Skip to content

Commit e63071a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into claude/angry-driscoll-1d8336
2 parents 78ef882 + a3e8cf6 commit e63071a

16 files changed

Lines changed: 306 additions & 218 deletions

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"dependencies": {
4949
"@clerk/expo": "catalog:",
50-
"@clerk/expo-native-components": "0.1.1",
50+
"@clerk/expo-native-components": "0.2.0",
5151
"@effect/atom-react": "catalog:",
5252
"@expo-google-fonts/dm-sans": "^0.4.2",
5353
"@expo/metro-runtime": "~58.0.14",

‎apps/mobile/src/state/use-thread-composer-state.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ export function useThreadComposerState() {
307307
? EMPTY_QUEUE_WORKFLOW_ATOM
308308
: environmentThreadDetails.queueWorkflowAtom(selectedThreadDetailRef),
309309
);
310-
const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true;
311310
const queuedRunEdit = useQueuedRunEdit(selectedThreadKey);
312311
const composerDraftKey =
313312
selectedThreadKey === null
@@ -394,6 +393,8 @@ export function useThreadComposerState() {
394393
selectedThreadRuntime,
395394
selectedThreadVisibleTurnItems,
396395
]);
396+
// A compacting turn cannot take steering input, so follow-ups queue meanwhile.
397+
const canSteerActiveTurn = queueWorkflow?.canPromoteToSteer === true && !isCompacting;
397398

398399
const runlessWorkStartedAt = useMemo(
399400
() =>

‎apps/server/src/orchestration-v2/CommandPolicy.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assert, it } from "@effect/vitest";
22
import {
33
CommandId,
4+
MessageId,
45
type OrchestrationV2ProviderCapabilities,
56
type OrchestrationV2ThreadProjection,
67
ProviderInstanceId,
@@ -19,6 +20,7 @@ import * as CommandPolicy from "./CommandPolicy.ts";
1920
const commandId = CommandId.make("command-policy-test");
2021
const threadId = ThreadId.make("command-policy-thread");
2122
const activeRunId = RunId.make("command-policy-active-run");
23+
const userMessageId = MessageId.make("command-policy-user-message");
2224

2325
const baseCapabilities: OrchestrationV2ProviderCapabilities = CodexProviderCapabilitiesV2;
2426

@@ -37,7 +39,8 @@ function dispatchProjection(
3739
runs:
3840
sessionCapabilities === undefined
3941
? []
40-
: [{ id: activeRunId, status: "running", providerThreadId }],
42+
: [{ id: activeRunId, status: "running", providerThreadId, userMessageId }],
43+
messages: [{ id: userMessageId, text: "first", attachments: [] }],
4144
providerThreads:
4245
sessionCapabilities === undefined ? [] : [{ id: providerThreadId, providerSessionId }],
4346
providerSessions:
@@ -141,6 +144,39 @@ it("targets the latest active run for explicit steer and restart intent", () =>
141144
);
142145
});
143146

147+
it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) => {
148+
const projection = dispatchProjection(baseCapabilities);
149+
const maintenance = {
150+
...projection,
151+
messages: [{ id: userMessageId, text, attachments: [] }],
152+
} as unknown as OrchestrationV2ThreadProjection;
153+
for (const deliveryIntent of ["auto", "steer"] as const) {
154+
assert.deepEqual(
155+
CommandPolicy.resolveMessageDispatchIntent(
156+
maintenance,
157+
{ type: "start_immediately" },
158+
deliveryIntent,
159+
),
160+
{ type: "queue_after_active" },
161+
);
162+
}
163+
assert.deepEqual(
164+
CommandPolicy.resolveMessageDispatchIntent(maintenance, {
165+
type: "steer_active",
166+
targetRunId: activeRunId,
167+
}),
168+
{ type: "queue_after_active" },
169+
);
170+
assert.deepEqual(
171+
CommandPolicy.resolveMessageDispatchIntent(
172+
maintenance,
173+
{ type: "start_immediately" },
174+
"restart",
175+
),
176+
{ type: "restart_active", targetRunId: activeRunId },
177+
);
178+
});
179+
144180
const layer = it.layer(CommandPolicy.layer);
145181

146182
layer("CommandPolicyV2", (it) => {

‎apps/server/src/orchestration-v2/CommandPolicy.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type ChatAttachment,
23
CommandId,
34
ModelSelection,
45
type OrchestrationV2Command,
@@ -116,10 +117,37 @@ type MessageDispatchMode = Extract<
116117
{ readonly type: "message.dispatch" }
117118
>["dispatchMode"];
118119

120+
export function isNativeMaintenanceCommand(message: {
121+
readonly text: string;
122+
readonly attachments: ReadonlyArray<ChatAttachment>;
123+
readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
124+
}): boolean {
125+
return (
126+
message.attachments.length === 0 &&
127+
["/compact", "/logout"].includes(message.text.trim().toLowerCase())
128+
);
129+
}
130+
119131
export function resolveMessageDispatchIntent(
120132
projection: OrchestrationV2ThreadProjection,
121133
requestedMode: MessageDispatchMode,
122134
deliveryIntent?: "auto" | "steer" | "restart",
135+
): MessageDispatchMode {
136+
const mode = resolveDeliveryIntent(projection, requestedMode, deliveryIntent);
137+
if (mode.type !== "steer_active") return mode;
138+
// Compaction and sign-out turns cannot take steering input. A message sent
139+
// while one runs waits in the queue like any other follow-up.
140+
const target = projection.runs.find((run) => run.id === mode.targetRunId);
141+
const targetMessage = projection.messages.find((message) => message.id === target?.userMessageId);
142+
return targetMessage !== undefined && isNativeMaintenanceCommand(targetMessage)
143+
? { type: "queue_after_active" }
144+
: mode;
145+
}
146+
147+
function resolveDeliveryIntent(
148+
projection: OrchestrationV2ThreadProjection,
149+
requestedMode: MessageDispatchMode,
150+
deliveryIntent?: "auto" | "steer" | "restart",
123151
): MessageDispatchMode {
124152
if (deliveryIntent === undefined) return requestedMode;
125153

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ import {
8484
SHARED_WORKSPACE_RESTORE_MESSAGE,
8585
} from "./CheckpointRestoreSafety.ts";
8686
import { CheckpointServiceV2 } from "./CheckpointService.ts";
87-
import { CommandPolicyV2, resolveMessageDispatchIntent } from "./CommandPolicy.ts";
87+
import {
88+
CommandPolicyV2,
89+
isNativeMaintenanceCommand,
90+
resolveMessageDispatchIntent,
91+
} from "./CommandPolicy.ts";
8892
import { CommandReceiptStoreV2 } from "./CommandReceiptStore.ts";
8993
import { ContextHandoffServiceV2 } from "./ContextHandoffService.ts";
9094
import { notificationTurnItem } from "@t3tools/provider-core/server/notification";
@@ -404,17 +408,6 @@ function wakeWorkStartedAt(
404408
return previous === undefined ? {} : { workStartedAt: orchestrationV2RunWorkStartedAt(previous) };
405409
}
406410

407-
export function isNativeMaintenanceCommand(message: {
408-
readonly text: string;
409-
readonly attachments: ReadonlyArray<ChatAttachment>;
410-
readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined;
411-
}): boolean {
412-
return (
413-
message.attachments.length === 0 &&
414-
["/compact", "/logout"].includes(message.text.trim().toLowerCase())
415-
);
416-
}
417-
418411
function isGoalCommand(message: {
419412
readonly text: string;
420413
readonly attachments: ReadonlyArray<ChatAttachment>;

‎apps/server/src/orchestration-v2/RestartContinuation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as Effect from "effect/Effect";
1313
import type { ProjectionRuntimeRecoveryState } from "./ProjectionStore.ts";
1414

1515
import * as ServerSettings from "../serverSettings.ts";
16-
import { isNativeMaintenanceCommand } from "./Orchestrator.ts";
16+
import { isNativeMaintenanceCommand } from "./CommandPolicy.ts";
1717
import * as ThreadManagementService from "./ThreadManagementService.ts";
1818
import {
1919
cancelledRosterTaskWork,

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -755,19 +755,26 @@ it.effect("keeps native maintenance commands out of steering and restart message
755755
const targetRun = before.runs[0];
756756
if (targetRun === undefined) return yield* Effect.die("Launch must create a run");
757757
const commandId = CommandId.make(`${scenario.name}:message`);
758-
const failure = yield* threads
759-
.dispatch({
760-
type: "message.dispatch",
761-
commandId,
762-
threadId: launched.threadId,
763-
messageId: MessageId.make(`${scenario.name}:message`),
764-
createdBy: "user",
765-
creationSource: "web",
766-
text: scenario.next,
767-
attachments: [],
768-
dispatchMode: { type: scenario.mode, targetRunId: targetRun.id },
769-
})
770-
.pipe(Effect.flip);
758+
const dispatch = threads.dispatch({
759+
type: "message.dispatch",
760+
commandId,
761+
threadId: launched.threadId,
762+
messageId: MessageId.make(`${scenario.name}:message`),
763+
createdBy: "user",
764+
creationSource: "web",
765+
text: scenario.next,
766+
attachments: [],
767+
dispatchMode: { type: scenario.mode, targetRunId: targetRun.id },
768+
});
769+
// A steer sent while a maintenance turn runs waits as a queued follow-up.
770+
if (scenario.name.startsWith("steer-")) {
771+
yield* dispatch;
772+
const queued = (yield* threads.getThreadProjection(launched.threadId)).runs[1];
773+
assert.equal(queued?.status, "queued");
774+
assert.equal(queued?.userMessageId, MessageId.make(`${scenario.name}:message`));
775+
continue;
776+
}
777+
const failure = yield* dispatch.pipe(Effect.flip);
771778
assert.include(
772779
String(failure.cause).toLowerCase(),
773780
scenario.name.includes("logout") ? "sign" : "context compaction",

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11192,6 +11192,7 @@ export default function ChatView(props: ChatViewProps) {
1119211192
isLocalDraftThread && activeProject === null
1119311193
}
1119411194
phase={phase}
11195+
isCompacting={isCompacting}
1119511196
canInterrupt={canInterruptRunningThread}
1119611197
isConnecting={isConnecting}
1119711198
isSendBusy={

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
13541354
isRunning: boolean;
13551355
canInterrupt: boolean;
13561356
followUpBehavior: "queue" | "steer";
1357+
canSteer: boolean;
13571358
alternateShortcutLabel: string | null;
13581359
showPlanFollowUpPrompt: boolean;
13591360
promptHasText: boolean;
@@ -1397,6 +1398,7 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
13971398
isRunning={props.isRunning}
13981399
canInterrupt={props.canInterrupt}
13991400
followUpBehavior={props.followUpBehavior}
1401+
canSteer={props.canSteer}
14001402
alternateShortcutLabel={props.alternateShortcutLabel}
14011403
showPlanFollowUpPrompt={props.showPlanFollowUpPrompt}
14021404
promptHasText={props.promptHasText}
@@ -1516,6 +1518,7 @@ export interface ChatComposerProps {
15161518
isRevertingCheckpoint?: boolean;
15171519
sendDisabledReason: string | null;
15181520
isPreparingWorktree: boolean;
1521+
isCompacting: boolean;
15191522
bannerItems: readonly ComposerBannerStackItem[];
15201523
resumeCompactionTokens: number | null;
15211524
keepFullHistory: boolean;
@@ -1676,6 +1679,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
16761679
isRevertingCheckpoint = false,
16771680
sendDisabledReason: externalSendDisabledReason,
16781681
isPreparingWorktree,
1682+
isCompacting,
16791683
environmentUnavailable,
16801684
activePendingApproval: incomingPendingApproval,
16811685
pendingApprovals,
@@ -4023,6 +4027,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
40234027
running: phase === "running",
40244028
alternateModifier: false,
40254029
activeTurnDefault: settings.followUpBehavior,
4030+
canSteer: !isCompacting,
40264031
}),
40274032
submissionIntent,
40284033
);
@@ -4045,6 +4050,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
40454050
running: phase === "running",
40464051
alternateModifier: event.metaKey || event.ctrlKey,
40474052
activeTurnDefault: settings.followUpBehavior,
4053+
canSteer: !isCompacting,
40484054
}),
40494055
);
40504056
};
@@ -4056,6 +4062,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
40564062
running: phase === "running",
40574063
alternateModifier: false,
40584064
activeTurnDefault: settings.followUpBehavior,
4065+
canSteer: !isCompacting,
40594066
}),
40604067
);
40614068
};
@@ -4216,6 +4223,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
42164223
running: phase === "running",
42174224
alternateModifier: submissionIntent === "alternate",
42184225
activeTurnDefault: settings.followUpBehavior,
4226+
canSteer: !isCompacting,
42194227
}),
42204228
submissionIntent,
42214229
);
@@ -7282,6 +7290,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
72827290
isRunning={phase === "running"}
72837291
canInterrupt={canInterrupt}
72847292
followUpBehavior={settings.followUpBehavior}
7293+
canSteer={!isCompacting}
72857294
alternateShortcutLabel={shortcutLabelForCommand(
72867295
keybindings,
72877296
"composer.sendAlternate",

‎apps/web/src/components/chat/ComposerPrimaryActions.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface ComposerPrimaryActionsProps {
3232
isRunning: boolean;
3333
canInterrupt: boolean;
3434
followUpBehavior?: "queue" | "steer";
35+
canSteer?: boolean;
3536
alternateShortcutLabel?: string | null;
3637
showPlanFollowUpPrompt: boolean;
3738
promptHasText: boolean;
@@ -86,6 +87,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
8687
isRunning,
8788
canInterrupt,
8889
followUpBehavior = "steer",
90+
canSteer = true,
8991
alternateShortcutLabel = null,
9092
showPlanFollowUpPrompt,
9193
promptHasText,
@@ -117,6 +119,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
117119
resolveComposerDispatchMode({
118120
running: isRunning,
119121
activeTurnDefault: followUpBehavior,
122+
canSteer,
120123
alternateModifier: shortcutModifiers.metaKey || shortcutModifiers.ctrlKey,
121124
}) === "queue";
122125
const alternateAction = alternateComposerDispatchAction(followUpBehavior);
@@ -297,7 +300,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
297300
submitStatus ??
298301
(compactsBeforeSend
299302
? `Summarize ${compactTokens} tokens of history, then send`
300-
: isRunning && !isEditingQueuedMessage
303+
: isRunning && !isEditingQueuedMessage && canSteer
301304
? `Click to ${followUpBehavior}, Ctrl/⌘-click${alternateShortcutLabel ? ` or ${alternateShortcutLabel}` : ""} to ${alternateAction}`
302305
: submitLabel);
303306

0 commit comments

Comments
 (0)