Skip to content

Commit a172e1c

Browse files
t3dotggclaude
andauthored
feat: native /goal for Codex and Claude, with goal status in the UI (pingdotgg#15592)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent f32c23c commit a172e1c

26 files changed

Lines changed: 2322 additions & 200 deletions

‎apps/mobile/src/components/AppSymbol.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import IconStar from "@tabler/icons-react-native/IconStar";
9898
import IconStarFilled from "@tabler/icons-react-native/IconStarFilled";
9999
import IconStethoscope from "@tabler/icons-react-native/IconStethoscope";
100100
import IconSun from "@tabler/icons-react-native/IconSun";
101+
import IconTarget from "@tabler/icons-react-native/IconTarget";
101102
import IconTerminal2 from "@tabler/icons-react-native/IconTerminal2";
102103
import IconTextDecrease from "@tabler/icons-react-native/IconTextDecrease";
103104
import IconTextIncrease from "@tabler/icons-react-native/IconTextIncrease";
@@ -216,6 +217,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
216217
"star.fill": IconStarFilled,
217218
"sun.max": IconSun,
218219
"stop.fill": IconPlayerStopFilled,
220+
target: IconTarget,
219221
terminal: IconTerminal2,
220222
"text.alignleft": IconAlignLeft,
221223
"text.bubble": IconMessage,

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import {
3131
type CodexArtifactTemplate,
3232
} from "@t3tools/client-runtime/codex-artifact-templates";
3333
import type { ThreadUserInputQuestion } from "@t3tools/client-runtime/state/thread-requests";
34-
import { presentPendingBackgroundWork } from "@t3tools/client-runtime/state/thread-execution";
34+
import {
35+
presentPendingBackgroundWork,
36+
presentProviderGoal,
37+
} from "@t3tools/client-runtime/state/thread-execution";
3538
import { resolveSubagentPillSegment } from "@t3tools/client-runtime/state/thread-subagents";
3639
import {
3740
formatModelSelectionEffort,
@@ -491,6 +494,14 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
491494
waiting: pendingBackgroundWork.waiting,
492495
};
493496
}
497+
if (props.selectedThread.goal !== null && contentPresentationKind === "ready") {
498+
const goal = presentProviderGoal(props.selectedThread.goal, false);
499+
return {
500+
kind: "goal",
501+
label: goal.title,
502+
accessibilityLabel: `${goal.title}: ${goal.objective}`,
503+
};
504+
}
494505
return null;
495506
})();
496507
const showWorkingControl = floatingStatus !== null;

‎apps/mobile/src/features/threads/floating-working-control.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,21 @@ function FloatingStatusLabel(props: {
407407
</StatusLabelRow>
408408
);
409409
}
410+
if (props.status.kind === "goal") {
411+
return (
412+
<StatusLabelRow
413+
key="goal"
414+
accessibilityLabel={props.status.accessibilityLabel}
415+
className="gap-2"
416+
onLayout={props.onLayout}
417+
>
418+
<SymbolView name="target" size={13} tintColorClassName="foreground" type="monochrome" />
419+
<Text className="shrink font-t3-medium text-xs text-foreground" numberOfLines={1}>
420+
{props.status.label}
421+
</Text>
422+
</StatusLabelRow>
423+
);
424+
}
410425
if (props.status.kind === "preparing") {
411426
return (
412427
<StatusLabelRow

‎apps/mobile/src/features/threads/floating-working-status.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export type FloatingWorkingStatus =
1717
readonly accessibilityLabel: string;
1818
readonly waiting: boolean;
1919
}
20+
// A native /goal on an idle thread: paused, blocked, complete, or set.
21+
| { readonly kind: "goal"; readonly label: string; readonly accessibilityLabel: string }
2022
// A task whose thread the server has not created yet: the worktree may
2123
// still be checking out, so there is no turn to time.
2224
| { readonly kind: "preparing"; readonly label: string }

‎apps/mobile/src/features/threads/thread-list-v2-items.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,12 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
587587
// label as the web sidebar, sourced from the server-side visited watermark
588588
// so checking a thread on any device clears it everywhere.
589589
const isUnread = status === "ready" && threadHasUnseenCompletion(thread);
590+
const workingLabel = STATUS_LABEL_BY_STATUS[status];
590591
const statusLabel =
591-
STATUS_LABEL_BY_STATUS[status] ??
592+
// A native /goal keeps the agent going across turns until it is met.
593+
(status === "working" && workingLabel !== undefined && thread.goal?.status === "active"
594+
? { ...workingLabel, label: "Goal" }
595+
: workingLabel) ??
592596
(isUnread ? { label: "Done", className: "text-adaptive-emerald-700-300" } : undefined);
593597
// The timestamp is precomputed on the list item (same stamps the settled
594598
// tail sorts by) so a minute tick only re-renders rows that draw it.

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8172,6 +8172,155 @@ describe("ClaudeAdapterV2 background wake turns", () => {
81728172
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
81738173
),
81748174
);
8175+
8176+
describe("native goals", () => {
8177+
const syntheticFrame = (uuid: string, text: string) =>
8178+
claudeSdkFrame({
8179+
type: "assistant",
8180+
message: {
8181+
model: "<synthetic>",
8182+
id: uuid,
8183+
type: "message",
8184+
role: "assistant",
8185+
content: [{ type: "text", text }],
8186+
stop_reason: "end_turn",
8187+
stop_sequence: null,
8188+
usage: {
8189+
input_tokens: 0,
8190+
output_tokens: 0,
8191+
cache_creation_input_tokens: 0,
8192+
cache_read_input_tokens: 0,
8193+
},
8194+
},
8195+
parent_tool_use_id: null,
8196+
uuid,
8197+
session_id: WAKE_NATIVE_SESSION,
8198+
});
8199+
const stopHookFeedback = (uuid: string, condition: string, reason: string) =>
8200+
claudeSdkFrame({
8201+
type: "user",
8202+
message: {
8203+
role: "user",
8204+
content: [{ type: "text", text: `Stop hook feedback:\n[${condition}]: ${reason}` }],
8205+
},
8206+
parent_tool_use_id: null,
8207+
isSynthetic: true,
8208+
uuid,
8209+
session_id: WAKE_NATIVE_SESSION,
8210+
});
8211+
const goalStatuses = (events: ReadonlyArray<ProviderAdapterV2Event>) =>
8212+
events.flatMap((event) =>
8213+
event.type === "provider_thread.updated" && event.providerThread.goal != null
8214+
? [event.providerThread.goal]
8215+
: [],
8216+
);
8217+
8218+
it.effect("tracks a /goal through unmet checks until Claude stops on its own", () =>
8219+
Effect.gen(function* () {
8220+
const harness = yield* makeWakeHarness;
8221+
const condition = "all tests pass";
8222+
yield* harness.runtime.startTurn(
8223+
makeClaudeTestTurnInput({
8224+
threadId: harness.threadId,
8225+
providerThread: harness.providerThread,
8226+
now: yield* DateTime.now,
8227+
attemptId: RunAttemptId.make("goal-attempt"),
8228+
text: `/goal ${condition}`,
8229+
attachments: [],
8230+
}),
8231+
);
8232+
for (const frame of [
8233+
syntheticFrame("goal-set", `Goal set: ${condition}`),
8234+
makeAssistantTextFrame({ uuid: "goal-work-1", text: "Fixing the first test." }),
8235+
stopHookFeedback("goal-check-1", condition, "One test still fails."),
8236+
makeAssistantTextFrame({ uuid: "goal-work-2", text: "All tests pass now." }),
8237+
makeResultFrame({ uuid: "goal-result", result: "All tests pass now." }),
8238+
]) {
8239+
yield* Queue.offer(harness.sdkMessages, frame);
8240+
}
8241+
const terminal = yield* Queue.take(harness.terminalReceipts);
8242+
assert.equal(terminal.status, "completed");
8243+
assert.deepEqual(goalStatuses(harness.events), [
8244+
{ objective: condition, status: "active", checks: 0 },
8245+
{
8246+
objective: condition,
8247+
status: "active",
8248+
checks: 1,
8249+
lastCheck: "One test still fails.",
8250+
},
8251+
{ objective: condition, status: "complete", checks: 1 },
8252+
]);
8253+
}).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
8254+
);
8255+
8256+
it.effect("keeps a goal active when a hook stops the turn before the goal passes", () =>
8257+
Effect.gen(function* () {
8258+
const harness = yield* makeWakeHarness;
8259+
const condition = "the deploy succeeds";
8260+
yield* harness.runtime.startTurn(
8261+
makeClaudeTestTurnInput({
8262+
threadId: harness.threadId,
8263+
providerThread: harness.providerThread,
8264+
now: yield* DateTime.now,
8265+
attemptId: RunAttemptId.make("goal-hook-stop-attempt"),
8266+
text: `/goal ${condition}`,
8267+
attachments: [],
8268+
}),
8269+
);
8270+
for (const frame of [
8271+
syntheticFrame("goal-hook-set", `Goal set: ${condition}`),
8272+
makeAssistantTextFrame({ uuid: "goal-hook-work", text: "Deploying." }),
8273+
makeResultFrame({
8274+
uuid: "goal-hook-result",
8275+
result: "Deploying.",
8276+
terminalReason: "hook_stopped",
8277+
}),
8278+
]) {
8279+
yield* Queue.offer(harness.sdkMessages, frame);
8280+
}
8281+
yield* Queue.take(harness.terminalReceipts);
8282+
assert.deepEqual(goalStatuses(harness.events).at(-1), {
8283+
objective: condition,
8284+
status: "active",
8285+
checks: 0,
8286+
});
8287+
}).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
8288+
);
8289+
8290+
it.effect("keeps a goal active after a command turn with no model output", () =>
8291+
Effect.gen(function* () {
8292+
const harness = yield* makeWakeHarness;
8293+
const condition = "the build is green";
8294+
yield* harness.runtime.startTurn(
8295+
makeClaudeTestTurnInput({
8296+
threadId: harness.threadId,
8297+
providerThread: {
8298+
...harness.providerThread,
8299+
goal: { objective: condition, status: "active", checks: 2 },
8300+
},
8301+
now: yield* DateTime.now,
8302+
attemptId: RunAttemptId.make("goal-show-attempt"),
8303+
text: "/goal",
8304+
attachments: [],
8305+
}),
8306+
);
8307+
yield* Queue.offer(
8308+
harness.sdkMessages,
8309+
syntheticFrame("goal-show", `Goal active: ${condition} (2 turns)`),
8310+
);
8311+
yield* Queue.offer(
8312+
harness.sdkMessages,
8313+
makeResultFrame({ uuid: "goal-show-result", result: "", numTurns: 0 }),
8314+
);
8315+
yield* Queue.take(harness.terminalReceipts);
8316+
assert.deepEqual(goalStatuses(harness.events).at(-1), {
8317+
objective: condition,
8318+
status: "active",
8319+
checks: 2,
8320+
});
8321+
}).pipe(Effect.scoped, Effect.provide(Layer.merge(IdAllocator.layer, NodeServices.layer))),
8322+
);
8323+
});
81758324
});
81768325

81778326
describe("ClaudeAdapterV2 query message stream", () => {

0 commit comments

Comments
 (0)