Skip to content

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

Closed

Description

@malibio

Overview

A session NodeSpace launches is meant to be the same in every harness that has a plugin. The Claude Code plugin opens such a session with the context of the task it was launched for, and reports the harness's own session id back to NodeSpace. The Pi extension and the OpenCode plugin do neither. This issue adds both to the module they share. It also moves the module's way of telling a session's own writes from someone else's onto the write journal the CLI keeps, as the Claude Code plugin now does.

Problem Statement

  • A session launched for a task in Pi or OpenCode starts with the orientation and the skill list only. The agent has to be told which task it is for, or find it, although the launch already named it in NODESPACE_LAUNCHED_FOR.
  • That task is not watched until the agent happens to read its context, so a change to it under the session is not noticed before then.
  • Neither plugin reports the harness's session id, so the session's ai-chat-pty node ends with an empty session_id and the conversation cannot be resumed from NodeSpace.
  • NODESPACE_SESSION and NODESPACE_LAUNCHED_FOR stay in the environment of every process the agent starts. A second harness started from the agent's shell would take itself for the launched session.
  • The shared module still reads the agent's shell lines to guess whether a command wrote (mayWrite, isRead, a count of writes in flight and of moves the session made). A write it cannot see, from a script or a command left running in the background, is read as someone else's change and stops the session, and in a session with nobody at the prompt that ends the work. A write made while a command runs is also absorbed into the baseline.
  • A context read of a deleted item fails like an unreachable daemon, so a deleted item never stops the session.

Proposed Solution

Do in packages/skill/plugins/shared/nodespace-session.ts what the Claude Code plugin does in plugins/claude-code/hooks/register.ts (readLaunch, takeOpening, dropLaunchVariables, and the session report-harness-session call), through the same harness-neutral interface the module already has:

  1. At session start read the launch from the environment. When there is one, report the harness's own session id with nodespace session report-harness-session <id>, and report it again when the harness starts a new conversation in the same process.
  2. When the launch named a task, read that task's context once and hand it to the agent with its first prompt, marked as graph data. The task becomes the item the session watches.
  3. A launch for the session's own chat node opens with nothing.
  4. Keep the launch variables out of what the agent starts, where the harness lets a plugin set the environment of the commands it runs.
  5. Attribute writes through the CLI's journal, as the Claude Code plugin does (Record a session's own writes in a CLI journal so the Claude Code plugin stops reading shell lines, and report a deleted item apart from a failed read #3642). Set NODESPACE_WRITE_JOURNAL to the harness's session id in the same command environment as step 4, and again when a new conversation starts. When the watched item's version differs from the one last seen, read <NodeSpace home>/.nodespace/journals/<session>.jsonl: a version it holds for the item is the session's own, any other is a change under the session, and a journal that cannot be read reports nothing. nodespace node context <id> --version-only --json printing {"error": "not_found", ...} is a deleted item and stops the session; any other failed read still says nothing. Run nodespace journal end <session> at session start and end. Delete mayWrite, isRead, the forced check before a write, the re-read after one, and the in-flight and moves counters; reading the shell line to learn which item is worked on stays.

Each harness file supplies what the module cannot know: the harness's session id, and how a first-prompt message and a command environment are set there.

Documentation

  • ADR-093 §8 - what a launched session gets: the database and launched-for values, and the plugin reporting the harness's session id; §5 - what every plugin does
  • Agent Session, How a Session Gets NodeSpace's Context - the opening context and the watch; Environment - the four variables; Session Resumption - the reported id
  • Prompt and Skill System, Harness plugins - the behaviour the plugins share
  • Updates: architecture/agent-session.md (the per-harness delivery table: which harness opens with the launched task and reports its session id), packages/skill/README.md (the Pi and OpenCode table)

Architecture Impact

Implements ADR-093 §8 for two more harnesses. No decision is reversed and no ADR change is needed.

Acceptance Criteria

  • In a Pi session and in an OpenCode session launched by NodeSpace, nodespace session report-harness-session is run once at session start with that harness's own session id, and again when a new conversation starts in the same process
  • A session started from a terminal (no NODESPACE_SESSION) reports nothing
  • A session launched for a task receives that task's context with its first prompt, once, inside the graph-data marker, and nothing on later prompts
  • The launched task is the watched item from the first prompt: a change to it under the session refuses the next tool call, with no context read by the agent in between
  • A session launched for its own chat node opens with nothing and watches nothing
  • A launched task that cannot be read adds nothing and blocks nothing
  • NODESPACE_SESSION and NODESPACE_LAUNCHED_FOR do not reach a command the agent runs, in each harness where a plugin can set that; where it cannot, the README says so
  • Each plugin sets the session-naming variable where the harness lets it set a command's environment; where it cannot, the README says that a write from a script is read as someone else's
  • A write made from a script, from a loop and from a command left running in the background is recognised as the session's own through the journal, with a test for each; a change made by another process while the session's own write is running is still reported
  • The shared module holds no list of read or write commands and makes no extra CLI call before or after the agent's own commands; a failed journal read or write never blocks a tool call
  • The watched item no longer existing refuses tool calls, and a read that failed for any other reason says nothing
  • The behaviour lives in the shared module, with tests in packages/skill/src/tests/plugin-session.test.ts over the fake CLI for each criterion above
  • Each plugin still type-checks against its harness's published types (bun run --cwd packages/skill quality:check)
  • Each plugin is run once in its harness with the launch variables set, and the PR says what was seen
  • Docs updated as listed under Documentation
  • Code passes bun run quality:fix
  • Tests pass (bun run test:changed)

Technical Specifications

Reference Files

  • packages/skill/plugins/claude-code/hooks/register.ts - readLaunch, dropLaunchVariables, takeOpening and the report-harness-session call: the behaviour to match
  • packages/skill/plugins/shared/nodespace-session.ts - createSession, its Host interface and start / prompt: where it goes; mayWrite, isRead and the write counters: what the journal replaces
  • packages/skill/plugins/claude-code/hooks/register.ts - nameSession, readJournal, endJournal, isDeleted, refuse: the journal behaviour to match
  • packages/cli/src/journal.rs - the journal's file format and the journal end command
  • packages/skill/plugins/pi/index.ts, packages/skill/plugins/opencode/nodespace.ts - the harness files
  • packages/skill/src/tests/plugin-session.test.ts - the fake CLI and the fake Pi and OpenCode inputs
  • packages/skill/README.md - "The Pi extension and the OpenCode plugin", including how to try one in its harness

Implementation Details

  • The harness's session id: Pi's ctx.sessionManager in session_start (which also fires with reason new, resume and fork); OpenCode's session.created event carries info.id, and a resumed session is first seen in another hook. Verify both against the current published types before writing.
  • The first-prompt hand-over can use what each file already uses for the skill-list note: the message returned from Pi's before_agent_start, and the text part pushed in OpenCode's chat.message.
  • OpenCode has a shell.env hook that sets the environment of the commands it runs. Check whether Pi offers the same before deciding how steps 4 and 5 are met there. Without a way to set it, a Pi session's writes cannot be journaled and the shell-line guess cannot be kept as a fallback (no dual mode): the plugin then reports no change as its own and the README says so.
  • The journal's path is <NodeSpace home>/.nodespace/journals/<session>.jsonl, with the home from NODESPACE_HOME, else the user's home. It holds ids and versions only. The session id must match [A-Za-z0-9_-]{1,128}, as the CLI refuses any other.
  • OpenCode serves several sessions from one plugin instance, child sessions among them. Only the session the launch started is the launched one.
  • The Claude Code plugin keeps the launch in session state so a /clear still knows it. The shared module keeps its state in the closure createSession returns; decide what survives Pi's session_start with reason new.

Dependencies

Related Issues

Non-Goals

  • Launched-session behaviour for Codex and Antigravity, which have no plugin
  • Changing what the Claude Code plugin does

Activity

  1. changed the title [-]Open launched Pi and OpenCode sessions with the launched task's context, and report their harness session id[/-] [+]Open launched Pi and OpenCode sessions with the launched task's context, report their harness session id, and attribute their writes through the CLI journal[/+] on Oct 6, 2026
  2. malibio commented on Oct 7, 2026

    @malibio
    CollaboratorAuthor

    Frontend: 5863 passed

  3. self-assigned this
    on Oct 7, 2026
  4. added a commit that references this issue on Oct 7, 2026
    9f971a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions