Skip to content

feat(opencode-bridge): P4 close remaining data gaps — exitCode, reason, cwd, stdout#976

Merged
magicpro97 merged 2 commits into
mainfrom
feat/opencode-bridge-p4
Jun 9, 2026
Merged

feat(opencode-bridge): P4 close remaining data gaps — exitCode, reason, cwd, stdout#976
magicpro97 merged 2 commits into
mainfrom
feat/opencode-bridge-p4

Conversation

@magicpro97

Copy link
Copy Markdown
Owner

Summary

Closes all remaining data gaps between the opencode bridge and hook_runner rules.

Changes

  1. exitCode/exit_code in toolResult — reads from output.metadata.exitCode or metadata.exit_code, falls back to deriving from isError (1 error / 0 success). Unlocks SkillUsageRule, TokenTrackerRule, VerificationGateRule numeric exit code checks.

  2. stdout aliastoolResult.stdout = output.output for rules that check toolResult.stdout (VerificationGateRule).

  3. reason in sessionEndsession.idle events now pass reason: "idle" instead of reason: "unknown". SessionEndRule goal pause breadcrumb now shows accurate reason.

  4. cwd in userPromptSubmitted — UserPromptContextRule can locate project-local CONTEXT.md without falling back to os.getcwd().

Remaining Gaps

After P4, the data flow between bridge and hook_runner is complete for all 10 events. The remaining architectural gaps (agentStop, voting, shell.env, tool.definition) cannot be closed via data mapping — they would require feature additions to opencode's plugin API or fall under "deeply CLI-tied" rules.

Testing

  • 3 new source-level plugin checks (exitCode, reason, cwd)
  • 3 new hook runner integration tests (session end with reason, postToolUse with exitCode, userPromptSubmitted with cwd)
  • 38/38 bridge tests pass, 13/13 security tests pass

Part of Phase 2 opencode bridge (continuing from PR #973, #974, #975)

…n, cwd, stdout

- Add exitCode/exit_code to postToolUse toolResult (from metadata or derived
  from isError). Unlocks SkillUsageRule, TokenTrackerRule, VerificationGateRule
  numeric exit code checks.
- Add stdout alias for toolResult.output — rules that check toolResult.stdout
  now work (VerificationGateRule).
- Add reason field to sessionEnd payload. session.idle events pass reason=
  "idle" instead of "unknown". SessionEndRule goal pause breadcrumb
  now shows accurate reason.
- Add cwd to userPromptSubmitted — UserPromptContextRule can locate
  project-local CONTEXT.md without falling back to os.getcwd().

All 38 bridge tests + 13 security tests pass.
@magicpro97

Copy link
Copy Markdown
Owner Author

/copilot-review

…ION_ID

shell.env hook injects COPILOT_AGENT_SESSION_ID into all subprocess
environments (bash tool, shell mode, PTY terminals) when opencode's own
session ID is available and the env var isn't already set.

This enables get_session_id() and rules that read env vars directly
(RecurrenceDetectorRule, SessionCompilerRule, EpisodeBatcherRule) to
correctly identify the session without falling back to ppid-<PPID>.
@magicpro97 magicpro97 merged commit 5f6f7b8 into main Jun 9, 2026
34 checks passed
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