fix: propagate OPENCODE_SESSION_ID to wiki tool in-process run (#399) - #400
Merged
Conversation
The session-tracker plugin's shell.env hook injects OPENCODE_SESSION_ID into every *shell* command's environment, but the wiki tool runs the enchiridion bundle in-process via run() — the hook never fires for it. Fix: in wiki-enchiridion.ts's execute(), inject context.sessionID into process.env.OPENCODE_SESSION_ID before calling run() and restore the prior value in a finally, so save-session (and any other subcommand that reads the session id) sees the correct value. Test: cli.run.test.ts adds a regression test that sets the env var directly (simulating what the plugin now does) and asserts that run(['save-session']) moves past the 'neither ID is set' check before failing on the tracker-state lookup — confirming the env var is read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #399.
The session-tracker plugin's
shell.envhook injectsOPENCODE_SESSION_IDinto every shell command's environment, but thewikitool runs the enchiridion bundle in-process viarun()— the hook never fires for tool calls, only for shell spawns.Root cause
When the agent calls
wiki(args=[save-session, --slug, ...]), the bundle'scaptureSession()readsprocess.env.OPENCODE_SESSION_IDviaprocessLookupEnv. Because the wiki tool is an in-process call (not a shell command), the tracker'sshell.envhook never sets the env var, socaptureSessionthrows the 'neither ID is set' error.Fix
In
wiki-enchiridion.ts'sexecute(), injectcontext.sessionID(which OpenCode supplies to every tool call) intoprocess.env.OPENCODE_SESSION_IDbefore callingrun()and restore the prior value in afinallyblock.Test
cli.run.test.tsgains a regression test that sets the env var directly (simulating what the plugin now does) and asserts thatrun(['save-session'])moves past the 'neither ID is set' check before failing on the tracker-state lookup — confirming the var is read by the in-process bundle.