Skip to content

feat(opencode-bridge): P3 session lifecycle events — compact and subagent stop#975

Merged
magicpro97 merged 1 commit into
mainfrom
feat/opencode-bridge-p3
Jun 9, 2026
Merged

feat(opencode-bridge): P3 session lifecycle events — compact and subagent stop#975
magicpro97 merged 1 commit into
mainfrom
feat/opencode-bridge-p3

Conversation

@magicpro97

Copy link
Copy Markdown
Owner

Summary

Adds P3 session lifecycle events to the opencode bridge:

Changes

  1. experimental.session.compacting hook — fires preCompact to hook_runner before compaction. Injects any additionalContext from rules into output.context.

  2. session.compacted event — fires postCompact after compaction completes.

  3. Subagent tracking — uses session.created events to detect subagent sessions (those with parentID). Only fires sessionStart for main sessions.

  4. session.status(idle) handler — detects subagent idle → fires subagentStop with subagentId, subagentName, parentSessionId.

Rules Unlocked

Rule Before After
CompactLifecycleRule ░░░░ (0%) ████ (100%)
SubagentStopRule ░░░░ (0%) ████ (100%)
AutoBriefingRule (postCompact) ███░ (75%) ████ (100%)

Partial unlock for 6+ additional rules that benefit from lifecycle signals.

Testing

  • 4 new source-level plugin checks (lifecycle hooks, subagent tracking)
  • 3 new hook runner integration tests (preCompact, postCompact, subagentStop)
  • 32/32 bridge tests pass, 13/13 security tests pass

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

…gent stop

- Add experimental.session.compacting hook → fires preCompact to hook_runner,
  injects additionalContext into output.context
- Add session.compacted event → fires postCompact after compaction completes
- Track subagent sessions via session.created (parentID detection)
- Add session.status handler → detects subagent idle → fires subagentStop
  with subagentId, subagentName, parentSessionId
- Only fire sessionStart for main sessions (skip subagent created events)
- 4 new source-level checks + 3 new hook runner integration tests

Unlocks: CompactLifecycleRule, SubagentStopRule, AutoBriefingRule (postCompact)
Rules heatmap: 2 rules ░░░░→████, partial unlock for 6+ others
@magicpro97

Copy link
Copy Markdown
Owner Author

/copilot-review

@magicpro97 magicpro97 merged commit 68cf9be into main Jun 9, 2026
34 checks passed
magicpro97 added a commit that referenced this pull request Jun 9, 2026
…n, cwd, stdout, shell.env

## Summary

Closes all remaining data gaps between the opencode bridge and hook_runner rules.
Part of Phase 2 opencode bridge (continuing from PR #973, #974, #975).

### Changes

1. **exitCode/exit_code/stdout in toolResult** — unlocks SkillUsageRule, TokenTrackerRule, VerificationGateRule
2. **reason in sessionEnd** — idle events pass reason="idle" instead of "unknown"
3. **cwd in userPromptSubmitted** — UserPromptContextRule finds CONTEXT.md correctly
4. **shell.env hook** — injects COPILOT_AGENT_SESSION_ID into all subprocess environments

### Testing
39/39 bridge tests pass, 13/13 security tests pass.

### Phase 2 Complete Status
- ~90% rules compatible with opencode
- 12 bridge hooks covering all 10 hook_runner events
- Remaining gaps (agentStop, voting) are CLI-only or semantically inappropriate
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