feat: detect OpenCode origin + activate PLANNOTATOR_ORIGIN override#590
Open
HeikoAtGitHub wants to merge 2 commits intobacknotprop:mainfrom
Open
feat: detect OpenCode origin + activate PLANNOTATOR_ORIGIN override#590HeikoAtGitHub wants to merge 2 commits intobacknotprop:mainfrom
HeikoAtGitHub wants to merge 2 commits intobacknotprop:mainfrom
Conversation
Extend the origin detection chain in apps/hook/server/index.ts to recognize OpenCode via `process.env.OPENCODE`, the stable runtime flag set by the OpenCode binary (also sets OPENCODE_RUN_ID, OPENCODE_PID, OPENCODE_PROCESS_ROLE, but OPENCODE=1 is the canonical detection flag). Additionally, activate `PLANNOTATOR_ORIGIN` as an explicit override. The comment in packages/server/index.ts already documented this variable, but it was never actually read. It is now honored at the top of the detection chain and validated against AGENT_CONFIG so only known origins take effect — invalid values fall through to env-based detection. Priority order after this change: PLANNOTATOR_ORIGIN > Codex > Copilot CLI > OpenCode > Claude Code (default) Single-point fix: all five existing `detectedOrigin` usages (lines 405, 568, 694, 741, 999) pick up the new chain automatically. The `'opencode'` origin key is already defined in packages/shared/agents.ts (AGENT_CONFIG), complete with a UI badge — the detection chain was the last missing piece. Closes the gap noted in packages/shared/agents.ts header comment: "If detection is via environment variable, add it to the detection chain in apps/hook/server/index.ts (detectedOrigin constant)".
getServerConfig only accepts gitUser — the project argument was silently ignored at runtime but fails the typecheck. Reverts the two call sites to their correct single-argument form. For provenance purposes, this commit was AI assisted.
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
process.env.OPENCODE) to the origin detection chain inapps/hook/server/index.ts. Without this, every OpenCode invocation defaults to"claude-code"and loads the wrong UI variant (missing agent-switch toggle, wrong badge).PLANNOTATOR_ORIGINas an explicit override. The comment inpackages/server/index.tsalready documented this variable, but it was never read. It is now honored at the top of the detection chain and validated againstAGENT_CONFIGso invalid values fall through to env-based detection.Context
The
'opencode'origin key is already defined inpackages/shared/agents.ts(AGENT_CONFIG), complete with a UI badge class — the detection chain was the last missing piece. The header comment of that file explicitly calls out the extension point:This PR closes that gap. It also turns the
PLANNOTATOR_ORIGINcomment inpackages/server/index.tsfrom a dead symbol into a live override (useful for testing and edge-case forcing).Detection priority after this change
Why
OPENCODE=1specificallyAmong OpenCode's runtime env vars (
OPENCODE,OPENCODE_RUN_ID,OPENCODE_PID,OPENCODE_PROCESS_ROLE,OPENCODE_DISABLE_CLAUDE_CODE_PROMPT),OPENCODE=1is the canonical runtime flag — set unconditionally by the OpenCode binary, not session- or role-specific. Matches the existing pattern (CODEX_THREAD_ID,COPILOT_CLI).Scope
Single-point fix — all five existing
detectedOriginconsumers (lines 405, 568, 694, 741, 999) pick up the new chain automatically. No changes to UI components, theOrigintype,AGENT_CONFIG, or any other agent-specific code paths.Test Plan
Headless detection tests (7/7 pass locally):
OPENCODE=1opencodeclaude-codeCODEX_THREAD_ID=... OPENCODE=1codexCOPILOT_CLI=1 OPENCODE=1copilot-cliPLANNOTATOR_ORIGIN=claude-code OPENCODE=1claude-codePLANNOTATOR_ORIGIN=fake OPENCODE=1opencode(falls through)PLANNOTATOR_ORIGIN=gemini-cligemini-cliDocs
Comment block at
apps/hook/server/index.ts:142-151updated with the full priority order and cross-reference toAGENT_CONFIG. Comment atpackages/server/index.ts:9updated from "(claude-code or opencode)" to the full supported-values list.