emdash icon indicating copy to clipboard operation
emdash copied to clipboard

fix(pi): pi cli resume specific sessions not just last

Open janburzinski opened this issue 5 months ago • 2 comments

Description

  • add pi plugin support for passing a resume session id
  • fix pi to resume specific sessions

Screenshot/Recording (if applicable)

( after restarting the correct sessions resumed )

Checklist
  • [X] I kept this PR small and focused
  • [X] I ran a self-review before opening this PR
  • [X] I ran the relevant local checks or explained why not
  • [X] I updated docs when behavior or setup changed
  • [X] I added or updated tests when behavior changed, or explained why not
  • [X] I only added comments where the logic is not obvious
  • [X] I used Conventional Commits for commit messages and, when possible, the PR title

janburzinski avatar Jun 16 '26 13:06 janburzinski

Greptile Summary

This PR fixes Pi session resumption so that specific sessions are resumed by their provider-native ID instead of always continuing the most recent session. It adds a session_start hook to the Pi extension that forwards the Pi-generated session ID to Emdash on every session start, then threads that stored ID through resolveAgentSessionCommandArgs and buildStandardCommand as --session <id> on resume.

  • Plugin extension (plugin-file.ts): adds session_start listener that calls notifyEmdash('session', { session_id }) so Emdash can persist the Pi-native ID; updates the notifyEmdash type union and adds ExtensionContext.
  • Command building (pi/index.ts, agent-provider-registry.ts): replaces the old -c (continue-last) flag with --session <id>, marking it sessionIdOnResumeOnly: true so the flag is only emitted when a stored session ID exists.
  • Session resolver (resolve-agent-session-command.ts): adds 'pi' to the provider-native-ID branch alongside codex and droid, falling back to isResuming: false when no session ID is stored.

Confidence Score: 5/5

Safe to merge — changes are well-scoped to the Pi provider and follow the same pattern already used by codex and droid.

All five files touch only the Pi provider path. The session-capture and resume logic mirrors the existing codex/droid pattern exactly, the new flags are handled correctly by the shared buildStandardCommand utility (sessionIdOnResumeOnly ensures --session is only emitted when a stored ID exists), and end-to-end tests verify both the fresh-start fallback and the resume command output.

No files require special attention.

Important Files Changed

Filename Overview
packages/plugins/src/agents/impl/pi/plugin-file.ts Adds session_start handler that emits the Pi-native session ID to Emdash via the hook; adds 'session' to the notifyEmdash event type union and adds the ExtensionContext type carrying sessionManager.
packages/plugins/src/agents/impl/pi/index.ts Switches resumeFlag from '-c' to '--session', adds sessionIdFlag and sessionIdOnResumeOnly, and adds 'session' to supportedEvents — addressing both prior review comments.
apps/emdash-desktop/src/shared/core/agents/agent-provider-registry.ts Updates the Pi provider's static registry entry to match the plugin: resumeFlag '-c' → '--session', adds sessionIdFlag and sessionIdOnResumeOnly.
apps/emdash-desktop/src/main/core/conversations/resolve-agent-session-command.ts Adds 'pi' to the provider-native session-ID branch alongside 'codex' and 'droid', so Pi resumes fall back to isResuming:false when no providerSessionId is stored.
apps/emdash-desktop/src/main/core/conversations/resolve-agent-session-command.test.ts Adds four new tests covering Pi-specific resume paths: stored ID used, fresh fallback, and end-to-end buildCommand output verification.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant U as User
    participant E as Emdash
    participant P as Pi Process
    participant H as Hook (session_start)

    Note over U,H: First Launch (fresh session)
    U->>E: Start Pi conversation
    E->>P: pi (no --session flag)
    P->>H: session_start fires
    H->>E: "notifyEmdash('session', { session_id: 'pi-abc' })"
    E->>E: "store providerSessionId = 'pi-abc'"

    Note over U,H: Subsequent Resume
    U->>E: Resume Pi conversation
    E->>E: "resolveAgentSessionCommandArgs → { sessionId:'pi-abc', isResuming:true }"
    E->>P: pi --session pi-abc
    P->>H: session_start fires
    H->>E: "notifyEmdash('session', { session_id: 'pi-abc' })"
    E->>E: providerSessionId confirmed/updated
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant U as User
    participant E as Emdash
    participant P as Pi Process
    participant H as Hook (session_start)

    Note over U,H: First Launch (fresh session)
    U->>E: Start Pi conversation
    E->>P: pi (no --session flag)
    P->>H: session_start fires
    H->>E: "notifyEmdash('session', { session_id: 'pi-abc' })"
    E->>E: "store providerSessionId = 'pi-abc'"

    Note over U,H: Subsequent Resume
    U->>E: Resume Pi conversation
    E->>E: "resolveAgentSessionCommandArgs → { sessionId:'pi-abc', isResuming:true }"
    E->>P: pi --session pi-abc
    P->>H: session_start fires
    H->>E: "notifyEmdash('session', { session_id: 'pi-abc' })"
    E->>E: providerSessionId confirmed/updated

Reviews (2): Last reviewed commit: "fix(pi): declare session hook support" | Re-trigger Greptile

greptile-apps avatar Jun 16 '26 13:06 greptile-apps

@greptileai

janburzinski avatar Jun 16 '26 13:06 janburzinski