Skip to content

fix: handle --agent-name flag by resolving and reviving target session - #17

Merged
elecnix merged 1 commit into
mainfrom
fix/handle-agent-name-flag
Jun 30, 2026
Merged

fix: handle --agent-name flag by resolving and reviving target session#17
elecnix merged 1 commit into
mainfrom
fix/handle-agent-name-flag

Conversation

@elecnix

@elecnix elecnix commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Problem

pi --agent-name solar-falcon-55 registered the flag but never acted on it. The --agent-name flag was registered via pi.registerFlag() but the extension never called pi.getFlag("agent-name") to process it. The flag was originally handled by a postinstall patch (patch-pi.mjs) that was later removed, leaving the flag orphaned.

This caused users to land in a new random agent instead of reviving the named one.

Fix

  • resolveTargetSession() (new in daemon-client.ts): resolves a flag value to a session file, guarding against re-entry (skips when flag matches current agent name).
  • session_start handler: checks pi.getFlag("agent-name"), and when it names a different agent registered in the daemon, spawns a new pi --session <file> process (mirroring the daemon's own resumeSession) and exits the current process.
  • 5 new tests cover all edge cases: undefined flag, boolean flag, self-match, found, not-found.

How it works

pi --agent-name solar-falcon-55
  → session_start: polar-lemur-69 (new random name)
  → pi.getFlag("agent-name") → "solar-falcon-55" ≠ polar-lemur-69
  → query daemon for solar-falcon-55 → /path/to/session.jsonl
  → spawn pi --session /path/to/session.jsonl (detached)
  → exit current process
  → new pi loads solar-falcon-55's session ✓

— swift-badger-66

The --agent-name flag was registered but never acted upon, since
the postinstall patch that handled it was removed. This fix makes
the extension itself resolve the flag value during session_start.

- Adds resolveTargetSession() to daemon-client.ts for flag-to-session
  resolution with guard against re-entry (skips when flag matches
  current agent name).
- In session_start, checks pi.getFlag("agent-name") and when the
  value names a different agent registered in the daemon, spawns a
  new pi --session <file> process (mirroring the daemon's own
  resumeSession) and exits the current process.
- Adds 5 tests for resolveTargetSession covering all edge cases
  (undefined, boolean, self-match, found, not-found).

Co-authored-by: swift-badger-66 <swift-badger-66@pi-agent.local>
@elecnix
elecnix marked this pull request as ready for review June 30, 2026 01:58
@elecnix
elecnix merged commit 3e13485 into main Jun 30, 2026
1 check passed
@elecnix
elecnix deleted the fix/handle-agent-name-flag branch June 30, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant