feat: native /goal for Codex and Claude, with goal status in the UI #15592
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 7 commits into
main fromrefs/pull/15592/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge added labelsmacroscope-review
- apps/server/src/orchestration-v2/Orchestrator.ts lines 373 to 373OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -364,3 +365,9 @@364365 );365366 }366367368+/** A native `/goal` command. It changes the provider's goal, so it never steers a running turn. */369+function isGoalCommand(message: {370+ readonly text: string;371+ readonly attachments: ReadonlyArray<ChatAttachment>;372+}): boolean {373+ return message.attachments.length === 0 && /^\/goal(?:\s|$)/iu.test(message.text.trim());apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts line 854Resolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -846,8 +848,7 @@846848 };847849 }848850851+// Counts toward native rollback. `/goal` control turns never reach Codex and852+// carry no native ref, so they must not consume a native turn on revert.849853 const isTerminalProviderTurn = (turn: OrchestrationV2ProviderTurn): boolean =>850- turn.status === "completed" ||851- turn.status === "interrupted" ||852- turn.status === "failed" ||853- turn.status === "cancelled";854+ turn.nativeTurnRef !== null &&apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 4066 to 4081Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3904,0 +4058,21 @@4058+ rootProviderThreads.has(payload.threadId) &&4059+ (goalsByNativeThread.get(payload.threadId)?.status === "active" ||4060+ goalStops.has(payload.threadId))4061+ ) {4062+ yield* Effect.logWarning("orchestration-v2.codex-goal-turn-without-run", {4063+ nativeThreadId: payload.threadId,4064+ nativeTurnId: payload.turn.id,4065+ });4066+ yield* client4067+ .request("thread/goal/set", { threadId: payload.threadId, status: "paused" })4068+ .pipe(4069+ Effect.andThen(4070+ client.request("turn/interrupt", {4071+ threadId: payload.threadId,4072+ turnId: payload.turn.id,4073+ }),4074+ ),4075+ Effect.catch((cause) =>4076+ Effect.logWarning("orchestration-v2.codex-goal-turn-stop-failed", { cause }),4077+ ),4078+ Effect.forkIn(scope),
- apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts lines 1028 to 1031OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1014,3 +1015,17 @@10141015 return content.flatMap((part) => (part.type === "text" ? [part.text] : [])).join("");10151016 }101610171018+// In SDK mode Claude reports `/goal` only through the transcript (its1019+// `active_goal` event is remote-only): synthetic command output names the1020+// goal, and each unmet evaluator check returns as Stop hook feedback.1021+const CLAUDE_GOAL_SET_PREFIX = "Goal set: ";1022+const CLAUDE_GOAL_ACTIVE = /^Goal active: ([\s\S]+?) \((?:not yet evaluated|(\d+) turns?)\)/u;1023+1024+/**1025+ * The goal after one root SDK frame, or undefined when the frame says nothing1026+ * about it. Completion has no frame of its own; see finalizeActiveTurn.1027+ */1028+export function nextClaudeGoal(1029+ current: OrchestrationV2ProviderGoal | null,1030+ message: SDKMessage,1031+): OrchestrationV2ProviderGoal | null | undefined {apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 851 to 858Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -846,8 +848,11 @@846848 };847849 }848850851+// Counts toward native rollback. `/goal` control turns never reach Codex and852+// carry no native ref, so they must not consume a native turn on revert.849853 const isTerminalProviderTurn = (turn: OrchestrationV2ProviderTurn): boolean =>850- turn.status === "completed" ||851- turn.status === "interrupted" ||852- turn.status === "failed" ||853- turn.status === "cancelled";854+ turn.nativeTurnRef !== null &&855+ (turn.status === "completed" ||856+ turn.status === "interrupted" ||857+ turn.status === "failed" ||858+ turn.status === "cancelled");apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts lines 902 to 905OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -853,0 +885,21 @@885+ return { type: "resume" };886+ default:887+ return { type: "set", objective: argument };888+ }889+}890+891+type CodexThreadGoal = CodexSchema.V2ThreadGoalUpdatedNotification["goal"];892+893+const CODEX_GOAL_STATUSES = {894+ active: "active",895+ paused: "paused",896+ blocked: "blocked",897+ usageLimited: "usage_limited",898+ budgetLimited: "budget_limited",899+ complete: "complete",900+} as const satisfies Record<CodexThreadGoal["status"], OrchestrationV2ProviderGoal["status"]>;901+902+export function providerGoalFromCodex(goal: CodexThreadGoal): OrchestrationV2ProviderGoal | null {903+ const objective = goal.objective.trim();904+ if (objective.length === 0) return null;905+ return {
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.






macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed