Skip to content

Commit 9bc1ba9

Browse files
feat: detect OpenCode origin + activate PLANNOTATOR_ORIGIN override (#590)
* feat: detect OpenCode origin + activate PLANNOTATOR_ORIGIN override 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)". * fix: remove stray project argument from getServerConfig calls 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. --------- Co-authored-by: Michael Ramos <mdramos8@gmail.com>
1 parent 104be99 commit 9bc1ba9

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

apps/hook/server/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import { detectProjectName } from "@plannotator/server/project";
8080
import { hostnameOrFallback } from "@plannotator/shared/project";
8181
import { planDenyFeedback } from "@plannotator/shared/feedback-templates";
8282
import { readImprovementHook } from "@plannotator/shared/improvement-hooks";
83-
import type { Origin } from "@plannotator/shared/agents";
83+
import { AGENT_CONFIG, type Origin } from "@plannotator/shared/agents";
8484
import { findSessionLogsForCwd, resolveSessionLogByPpid, findSessionLogsByAncestorWalk, getLastRenderedMessage, type RenderedMessage } from "./session-log";
8585
import { findCodexRolloutByThreadId, getLastCodexMessage } from "./codex-session";
8686
import { findCopilotPlanContent, findCopilotSessionForCwd, getLastCopilotMessage } from "./copilot-session";
@@ -140,10 +140,21 @@ const shareBaseUrl = process.env.PLANNOTATOR_SHARE_URL || undefined;
140140
const pasteApiUrl = process.env.PLANNOTATOR_PASTE_URL || undefined;
141141

142142
// Detect calling agent from environment variables set by agent runtimes.
143-
// Priority: Codex > Copilot CLI > Claude Code (default fallback)
143+
// Priority:
144+
// PLANNOTATOR_ORIGIN (explicit override, validated against AGENT_CONFIG)
145+
// > Codex (CODEX_THREAD_ID)
146+
// > Copilot CLI (COPILOT_CLI)
147+
// > OpenCode (OPENCODE)
148+
// > Claude Code (default fallback)
149+
//
150+
// To add a new agent, also add an entry to AGENT_CONFIG in
151+
// packages/shared/agents.ts (see header comment there).
152+
const originOverride = process.env.PLANNOTATOR_ORIGIN as Origin | undefined;
144153
const detectedOrigin: Origin =
154+
(originOverride && originOverride in AGENT_CONFIG) ? originOverride :
145155
process.env.CODEX_THREAD_ID ? "codex" :
146156
process.env.COPILOT_CLI ? "copilot-cli" :
157+
process.env.OPENCODE ? "opencode" :
147158
"claude-code";
148159

149160
if (args[0] === "sessions") {

packages/server/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
* Environment variables:
77
* PLANNOTATOR_REMOTE - Set to "1"/"true" for remote, "0"/"false" for local
88
* PLANNOTATOR_PORT - Fixed port to use (default: random locally, 19432 for remote)
9-
* PLANNOTATOR_ORIGIN - Origin identifier ("claude-code" or "opencode")
9+
* PLANNOTATOR_ORIGIN - Explicit origin override; validated against AGENT_CONFIG
10+
* in packages/shared/agents.ts. Supported values:
11+
* "claude-code", "opencode", "codex", "copilot-cli",
12+
* "gemini-cli", "pi".
1013
*/
1114

1215
import type { Origin } from "@plannotator/shared/agents";

0 commit comments

Comments
 (0)