feat(goals): track native provider goals across clients #11516
github-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
- apps/server/src/provider/Layers/ClaudeProvider.ts line 579OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -576,3 +576,4 @@576576 slashCommands: dedupedSlashCommands,577577 skills,578578 probe: {579+ ...(dedupedSlashCommands.some((command) => command.name === "goal")
- @@ -277,0 +308,21 @@308+ }309+ };310+ return (311+ <View312+ className="mb-2 flex-row items-center gap-3 rounded-2xl px-3 py-2"313+ style={{ backgroundColor: "#7c3aed18", borderColor: "#8b5cf655", borderWidth: 1 }}314+ >315+ <View className="min-w-0 flex-1">316+ <Text numberOfLines={1} className="text-xs font-medium" style={{ color: "#8b5cf6" }}>317+ {goal.objective}318+ </Text>319+ <Text className="text-xs" style={{ color: "#8b5cf6" }}>320+ {[321+ goal.status,322+ elapsed,323+ goal.tokensUsed === null ? null : `${goal.tokensUsed.toLocaleString()} tokens`,324+ goal.rounds === undefined ? null : `${goal.rounds} rounds`,325+ ]326+ .filter(Boolean)327+ .join(" · ")}328+ </Text>@@ -3969,0 +4029,21 @@4029+ createdAt:4030+ previous?.objective === commandGoal.objective4031+ ? previous.createdAt4032+ : stamp.createdAt,4033+ updatedAt: stamp.createdAt,4034+ timeUsedSeconds: null,4035+ tokensUsed: null,4036+ tokenBudget: null,4037+ rounds: commandGoal.rounds,4038+ ...(commandGoal.lastReason ? { lastReason: commandGoal.lastReason } : {}),4039+ };4040+ yield* offerRuntimeEvent({4041+ type: "thread.goal.updated",4042+ ...stamp,4043+ provider: PROVIDER,4044+ threadId: context.session.threadId,4045+ payload: { goal: context.nativeGoal },4046+ providerRefs: nativeProviderRefs(context),4047+ raw: { source: "claude.sdk.message", method: "claude/assistant", payload: message },4048+ });4049+ }@@ -8892,3 +8894,19 @@88928894 <ComposerSurface.Host>88938895 <div ref={attachDraftHeroComposerAnchorRef} className="relative z-10">88948896 <ChatComposer8897+ onSetGoal={async (input) => {8898+ if (!activeThread) return false;8899+ const result = await setThreadGoal({8900+ environmentId,8901+ input: { threadId: activeThread.id, ...input },8902+ });8903+ return result._tag !== "Failure";8904+ }}8905+ onClearGoal={async () => {8906+ if (!activeThread) return false;8907+ const result = await clearThreadGoal({8908+ environmentId,8909+ input: { threadId: activeThread.id },8910+ });8911+ return result._tag !== "Failure";8912+ }}
- apps/server/src/provider/Layers/ClaudeAdapter.ts line 4211Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3969,0 +4044,21 @@4044+ compareSemverVersions(message.claude_code_version, "2.1.270") >= 0 &&4045+ message.slash_commands.includes("goal")4046+ )4047+ yield* enqueueGoalCommand(context, "/goal");4048+ }4049+4050+ if (4051+ message.type === "result" &&4052+ "local_command" in message &&4053+ message.local_command === "goal"4054+ ) {4055+ // A rejected new goal never starts model work. Settle only its exact4056+ // request; status, clear, and goal edits cannot close an existing turn.4057+ if (4058+ context.goalStartTurnId &&4059+ context.turnState?.turnId === context.goalStartTurnId &&4060+ "user_message_uuid" in message &&4061+ message.user_message_uuid === context.goalStartTurnId4062+ ) {4063+ delete context.goalStartTurnId;4064+ yield* completeTurn(
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 899OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -882,3 +891,9 @@882891 !shouldRestartForModelChange &&883892 !shouldRestartForModelSelectionChange884893 ) {894+ if (895+ options?.goalStartsWork === true &&896+ preferredProvider === "codex" &&897+ ((activeSession?.model !== undefined &&898+ activeSession.model !== desiredModelSelection.model) ||899+ (previousModelSelection?.options !== undefined &&
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts lines 1935 to 1941Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1864,0 +1974,21 @@1974+ createdAt: event.occurredAt,1975+ });1976+ }1977+ if (1978+ event.type === "thread.goal-set-requested" &&1979+ thread.interactionMode === "plan" &&1980+ (event.payload.objective !== undefined || event.payload.status === "active")1981+ ) {1982+ return yield* appendProviderFailureActivity({1983+ threadId: thread.id,1984+ kind: "provider.goal.failed",1985+ summary: "Goal update failed",1986+ detail: "Switch out of Plan mode before starting or editing a goal.",1987+ turnId: null,1988+ createdAt: event.occurredAt,1989+ });1990+ }1991+ yield* ensureThreadWorktree(thread);1992+ yield* ensureSessionForThread(event.payload.threadId, event.occurredAt);1993+ if (event.type === "thread.goal-set-requested")1994+ yield* providerService.setGoal(event.payload.threadId, event.payload);
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts line 1394Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1404,4 +1432,20 @@1432+ (message.attachments?.length ?? 0) === 01433+ ? /^\/goal(?:\s+([\s\S]*))?$/.exec(message.text.trim())1434+ : null;1435+ const goalArgument = goalCommand?.[1]?.trim() ?? "";1436+ const goalStartsWork =1437+ goalCommand !== null &&1438+ goalArgument !== "" &&1439+ goalArgument !== "clear" &&1440+ goalArgument !== "pause";1441+ if (goalStartsWork && (event.payload.interactionMode ?? thread.interactionMode) === "plan") {1442+ return yield* appendTurnStartFailure(1443+ "Goal update failed",1444+ "Switch out of Plan mode before starting or editing a goal.",1445+ );1446+ }1447+14041448 yield* ensureThreadWorktree(thread);1405144914061450 const isCompactCommand = isCompactCommandMessage(message);1407- if (!hasOtherUserMessages && !isCompactCommand) {1451+ if (!hasOtherUserMessages && !isCompactCommand && (!goalCommand || goalStartsWork)) {
- apps/server/src/orchestration/Layers/ProviderCommandReactor.ts lines 1367 to 1383Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1403,0 +1432,21 @@1432+ const goalCommand =1433+ (message.attachments?.length ?? 0) === 01434+ ? /^\/goal(?:\s+([\s\S]*))?$/.exec(message.text.trim())1435+ : null;1436+ const goalArgument = goalCommand?.[1]?.trim() ?? "";1437+ const goalStartsWork =1438+ goalCommand !== null &&1439+ goalArgument !== "" &&1440+ goalArgument !== "clear" &&1441+ goalArgument !== "pause";1442+ if (goalStartsWork && (event.payload.interactionMode ?? thread.interactionMode) === "plan") {1443+ return yield* appendTurnStartFailure(1444+ "Goal update failed",1445+ "Switch out of Plan mode before starting or editing a goal.",1446+ );1447+ }1448+ if (goalCommand) {1449+ const instanceId =1450+ event.payload.modelSelection?.instanceId ?? thread.modelSelection.instanceId;1451+ const providers = yield* providerRegistry.getProviders;1452+ if (!providers.find((provider) => provider.instanceId === instanceId)?.goal) {
- apps/web/src/components/chat/ChatComposer.tsx lines 5960 to 5960OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5944,3 +5952,9 @@59445952 : null}59455953 <ComposerBanner.Dock>59465954 <ComposerBanner.Column>5955+ {activeGoal ? (5956+ <GoalToolbar5957+ key={`goal:${activeThreadId}`}5958+ goal={activeGoal}5959+ capability={selectedProviderStatus?.goal}5960+ disabled={isConnecting || Boolean(props.environmentUnavailable)}apps/server/src/relay/AgentAwarenessRelay.ts line 469Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -406,3 +445,4 @@406445 });407446408447 const thread = yield* snapshotQuery.getThreadShellById(threadId);448+ if (Option.isNone(thread)) goalThreads.delete(threadId);
- @@ -985,3 +988,4 @@985988 };986989 }987990991+ if (thread.goal?.status === "active" && thread.session?.status !== "error") {
- apps/web/src/components/chat/GoalToolbar.tsx lines 94 to 94OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +74,21 @@74+ {goal.rounds !== undefined ? (75+ <span className="tabular-nums">76+ {goal.rounds} {goal.rounds === 1 ? "round" : "rounds"}77+ </span>78+ ) : null}79+ {goal.tokensUsed !== null ? (80+ <span className="ml-auto whitespace-nowrap text-purple-700 tabular-nums dark:text-purple-300">81+ {formatTokens(goal.tokensUsed).replace("K", "k")}82+ {goal.tokenBudget !== null83+ ? ` / ${formatTokens(goal.tokenBudget).replace("K", "k")}`84+ : ""}85+ <span className="sr-only"> tokens</span>86+ </span>87+ ) : null}88+ </ComposerBanner.Content>89+ <ComposerBanner.Actions>90+ <Button91+ type="button"92+ variant="ghost"93+ size="icon-xs"94+ className="text-purple-700 dark:text-purple-300 [--control-icon-color:currentColor]"
- packages/shared/src/agentAwareness.ts line 102Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -76,0 +82,21 @@82+ paused: { phase: "stale", headline: "Goal paused" },83+ complete: { phase: "completed", headline: "Goal completed" },84+ blocked: { phase: "waiting_for_input", headline: "Goal blocked" },85+ budgetLimited: { phase: "waiting_for_input", headline: "Goal budget reached" },86+ usageLimited: { phase: "waiting_for_input", headline: "Goal usage limit reached" },87+} as const;88+89+function resolveAwarenessGoal(thread: ProjectThreadAwarenessInput["thread"]) {90+ const goal = thread.goal;91+ if (92+ !goal ||93+ thread.hasPendingApprovals ||94+ thread.hasPendingUserInput ||95+ thread.session?.status === "error" ||96+ thread.latestTurn?.state === "error"97+ ) {98+ return null;99+ }100+ // A retained terminal goal must not hide a later, ordinary conversation turn.101+ if (102+ goal.status !== "active" &&apps/server/src/orchestration/decider.ts lines 1300 to 1300OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1294,3 +1294,7 @@12941294 };12951295 }129612961297+ case "thread.goal.set":1298+ case "thread.goal.clear":1299+ case "thread.goal.sync": {1300+ const thread = yield* requireThread({ readModel, command, threadId: command.threadId });apps/server/src/orchestration/Layers/ProviderCommandReactor.ts lines 1925 to 1925OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1793,0 +1905,21 @@1905+ case "thread.goal-set-requested":1906+ case "thread.goal-clear-requested":1907+ yield* Effect.gen(function* () {1908+ const thread = yield* resolveThreadShell(event.payload.threadId);1909+ if (!thread) return;1910+ const instanceId = thread.session?.providerInstanceId ?? thread.modelSelection.instanceId;1911+ const providers = yield* providerRegistry.getProviders;1912+ if (!providers.find((provider) => provider.instanceId === instanceId)?.goal) {1913+ return yield* appendProviderFailureActivity({1914+ threadId: thread.id,1915+ kind: "provider.goal.failed",1916+ summary: "Goal update failed",1917+ detail: "This provider does not advertise native goal support.",1918+ turnId: null,1919+ createdAt: event.occurredAt,1920+ });1921+ }1922+ if (1923+ event.type === "thread.goal-set-requested" &&1924+ thread.interactionMode === "plan" &&1925+ (event.payload.objective !== undefined || event.payload.status === "active")apps/server/src/provider/Layers/ClaudeAdapter.ts line 5315OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5065,3 +5312,4 @@50655312 });5066531350675314 if (steeringTurnState === null) context.turnStartMessageIds.push(turnId);5315+ if (isGoalStart && steeringTurnState === null) context.goalStartTurnId = turnId;apps/server/src/relay/AgentAwarenessRelay.ts line 374Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -340,3 +369,6 @@340369 // tombstone can never race an in-flight live update; a recovered state341370 // clears the deadline. Assigned after the worker exists.342371 const publishConfirmDeadlines = new Map<ThreadId, number>();372+ // Clearing a native goal must not reinterpret its last round as a new Done373+ // alert. A subsequent explicit turn restores ordinary completion behavior.374+ const goalThreads = new Map<
juliusmarminge closed this
Sign in to join this conversation.






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