Skip to content

Open launched Pi and OpenCode sessions with the task's context, report their session id, attribute writes through the journal - #3680

Merged
malibio merged 2 commits into
mainfrom
issue-3653-pi-opencode-launch
Oct 7, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3653-pi-opencode-launch

Conversation

@malibio

@malibio malibio commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Closes #3653.

What changed

  • plugins/shared/nodespace-session.ts: at start, reads the launch from the environment, reports the harness session id (session report-harness-session), and reads the launched task once, handing it over with the first prompt inside the graph-data marker; the task becomes the watched item. A launch for the chat node, an unanswered report or an unreadable task opens with nothing.
  • Writes are attributed through the CLI journal (NODESPACE_WRITE_JOURNAL, <home>/.nodespace/journals/<session>.jsonl), with journal end at start and end. mayWrite, isRead, the forced pre-write check, the post-write re-read and the in-flight and moves counters are deleted. A deleted item (not_found) stops the session; any other failed read says nothing.
  • Pi: session id from ctx.sessionManager; its own bash tool is re-registered with a spawnHook that sets the journal variable and drops the launch variables; session_shutdown ends the journal. The powershell tool is not covered (the README says so).
  • OpenCode: shell.env hook sets the journal variable per session; the launch variables are blanked, not removed, because shell.env is not documented to replace the environment. Only the first non-child session takes the launch.
  • README and architecture/agent-session.md (docs repo, pushed to main) updated.

Not done

  • Not run in Pi or OpenCode: neither harness is installed on this machine, so the acceptance item for running each plugin once in its harness is open. Everything else is covered by plugin-session.test.ts over the fake CLI, and quality:check type-checks both plugins against the published harness types.

Tests

Skill package: 264 passed; bun run --cwd packages/skill quality:check clean.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Verdict: APPROVE (with one Pi item I would fix or consciously accept before merge).

The change does what #3653 asks. The shared module now mirrors claude-code/hooks/register.ts: readLaunch, reportSession, launchedItem (including the "no report answer, or the chat node itself, opens nothing" rule), takeOpening semantics through prompt(), readJournal, endJournal, isDeleted and refuse. mayWrite, isRead, the forced pre-write check and the in-flight and moves counters are gone. The harness files stay thin. Ordering and gating match the Claude Code plugin where it matters: the report precedes the context read, the opening is cut at 16k chars and marker-neutralised, and a failed read returns null. Typecheck (quality:check) passes and the skill vitest suite passes (264 tests). The 82 tests in plugin-session.test.ts cover the criteria well, including the three write shapes (script, loop, background), the "other process during own write" case, and the OpenCode child-session case.

The one real concern is in the Pi bash re-registration, below.

Acceptance criteria

  • Report once at start and again on a new conversation (Pi new/resume/fork, OpenCode per session) - tests present for both harnesses
  • Terminal session reports nothing
  • Task context with first prompt only, inside the marker
  • Launched task watched from the first prompt, refuses the next tool call on change
  • Own chat node opens with nothing and watches nothing
  • Unreadable task adds nothing, blocks nothing
  • Launch variables kept from commands (Pi spawnHook, OpenCode shell.env blanking); the powershell and OpenCode-replace limits are stated in the README
  • Session-naming variable set where the harness allows; Pi powershell limitation stated
  • Script, loop, background write recognised through the journal, one test each; concurrent foreign write still reported
  • No read/write command list, no extra CLI call around the agent's commands (test asserts w.calls unchanged); journal failures never block
  • Deleted item refuses; other failed reads say nothing
  • Behaviour in the shared module, tests over the fake CLI
  • Type-checks against the published harness types (verified here)
  • Run once in each harness - open, stated in the PR (neither harness is installed on the review machine)
  • Docs: README updated in this diff; architecture/agent-session.md (per-harness delivery table) lives in nodespace-docs and is not in this diff - confirm it is pushed before merge
  • quality / tests: skill suite passes here; test:changed not re-run by me

Findings

Critical Issues

None.

Suggested Improvements

  • packages/skill/plugins/pi/index.ts (the createBashToolDefinition(process.cwd(), { spawnHook }) + pi.registerTool(bash) block) [Improvement, strongest of the set]: Pi builds its own bash tool in agent-session.js with createAllToolDefinitions(this._cwd, { bash: { commandPrefix: settings.shellCommandPrefix, shellPath: settings.shellPath } }). The replacement drops both settings and substitutes process.cwd() for the session's cwd. A Pi user with shellCommandPrefix (for example an env setup line) or a custom shellPath silently loses it once this extension loads, and bash behaves differently only in sessions where NodeSpace is installed. Options: read the same two values from Pi's settings if the extension API exposes them and pass them through; otherwise state the limitation in the README Pi bullet (next to the powershell one) so it is a known trade-off, not a surprise. The "no way to set the env" fallback in the issue was meant to be the alternative to this, so documenting it is a legitimate resolution.

  • packages/skill/plugins/shared/nodespace-session.ts start() and packages/skill/plugins/pi/index.ts (opens: event.reason !== 'reload'): the comment says "A reload keeps the one it had", but start() unconditionally resets item, blocked, fetched, skills, opening and lastCheckedAt, and calls endJournal() (deleting the session's own journal). After a Pi /reload mid-session the launched task's watch is dropped until the agent next reads its context, and a reload before the first prompt loses the opening. The Claude Code plugin deliberately keeps state across a module reload. Either keep item/opening when opens === false and the session id is unchanged, or correct the comment and README so they do not promise a kept conversation. The existing "does not open again when Pi reloads" test only asserts the absence of an opening, so it passes either way.

  • packages/skill/plugins/opencode/nodespace.ts session.deleted: this is the only place the journal is ended, and OpenCode does not delete a session when it exits, so journal files accumulate in <home>/.nodespace/journals/ (ids and versions only, small, but never swept because each OpenCode session id is new). Claude Code ends them on session.end. If OpenCode has a process-exit or server.instance.disposed-style event, use it; otherwise add one sentence to the README so the leak is a known property.

  • packages/skill/plugins/opencode/nodespace.ts sessionFor (child detection): isChild is only known when session.created carries parentID. A session first seen from shell.env or another hook (the "resumed" path) is assumed to be non-child, and takes the launch if it is unclaimed. Reasonable, but it means a child session whose session.created is missed could steal the launch from the real one. Low probability; a one-line note near hasClaimedLaunch would record the assumption.

Nitpicks

  • Nit: packages/skill/README.md (OpenCode bullet): "set to empty there, which the CLI and the plugin read as no launch". The plugin does (|| ''). The CLI's session report-harness-session takes --session from NODESPACE_SESSION through clap env, and clap keeps an empty env value as a value, so a nested nodespace session report-harness-session would send an empty session id to the daemon instead of failing at argument parsing. Say "the plugin reads as no launch" or drop the CLI.
  • Nit: plugins/shared/nodespace-session.ts header comment still lists "a way to run a command, the environment and a clock"; readFile is the fourth.
  • Nit: Pi before_agent_start returns the opening with display: true, so up to 16k chars of task context is printed into the user's transcript. Consistent with the skill-list note, but the opening is far larger; display: false may be kinder if Pi still passes the content to the model.
  • Nit: commandEnv sets NODESPACE_WRITE_JOURNAL even when the CLI was not found at start (the early no-cli return). Harmless.

Notes

  • Positives: the attribution logic is shared rather than copied per harness; the Pi and OpenCode files each reduce to host adaptation; refuse and the concurrent-check guard (blocked re-read after the awaits) are preserved; and the journal-id regex check matches the CLI's.
  • Differences from the Claude Code plugin that I judge acceptable: beforeTool here does not require a resolved project (the launched task is watched even where the checkout has no project, and there is a test for that), and start() skips the report when the harness gives an empty session id.
  • Remaining before merge: the in-harness run for Pi and OpenCode (stated in the PR) and the docs-repo table update.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

Addressed (docs and comment only, no logic change):

  • README: Pi's re-registered bash tool drops the user's shellPath / shellCommandPrefix settings; a Pi reload starts with no item watched.
  • README: the CLI may take an empty NODESPACE_SESSION as a value, so the OpenCode "blanked" variables are not guaranteed to read as no launch outside the plugin.
  • README: OpenCode journal cleanup (session.deleted, or the next session's start after an hour idle).
  • Shared module header comment now names readFile.

Skipped:

  • Passing Pi's settings into the bash tool: the extension API gives no settings accessor; documented instead. Revisit if Pi exposes one.
  • Keeping state across a Pi reload: Pi replaces the extension runtime on reload, so closure state cannot survive; documented.
  • OpenCode exit event and child-detection hardening: no such event exists, and the missed-session.created case is low probability; documented.
  • display: true on the Pi opening and commandEnv when the CLI is missing: both match the Claude Code plugin's intent and are harmless.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Only a README paragraph and a comment changed; no code or tests.

🤖 Generated with Claude Code

malibio and others added 2 commits October 7, 2026 10:57
…t their session id, attribute writes through the journal (closes #3653)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3653-pi-opencode-launch branch from aa01bc8 to e41fec0 Compare October 7, 2026 08:57
@malibio
malibio merged commit ad73e60 into main Oct 7, 2026
@malibio
malibio deleted the issue-3653-pi-opencode-launch branch October 7, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant