diff --git a/apps/mobile/src/features/threads/ThreadQueueControl.tsx b/apps/mobile/src/features/threads/ThreadQueueControl.tsx index d3b3ba6006291..8541c639cd863 100644 --- a/apps/mobile/src/features/threads/ThreadQueueControl.tsx +++ b/apps/mobile/src/features/threads/ThreadQueueControl.tsx @@ -252,7 +252,8 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { No messages waiting in this queue. ) : null} - {queuedRuns.map(({ run, text, attachments, context, message }, index) => { + {queuedRuns.map((item, index) => { + const { run, text, attachments, context, message, steerRejectionReason } = item; const controls = resolveThreadQueueRowControls({ busy: busyRunId !== null, // A fresh message starts its own turn: it may skip compaction, but not steer into a turn. @@ -263,6 +264,8 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { editBlocked: editBlockedReason !== null, isEditing: editing?.runId === run.id, isGuestMessage: context?.guest !== undefined, + steerRejectionReason, + promoteSkipsCompaction: workflow?.promoteSkipsCompaction ?? false, text, }); const title = @@ -285,6 +288,11 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { { id: "steer", title: "Send now", + ...(!workflow?.canSendNow && + !workflow?.promoteSkipsCompaction && + steerRejectionReason + ? { subtitle: steerRejectionReason } + : {}), attributes: { disabled: !controls.canSend }, image: "arrow.up", }, @@ -354,6 +362,11 @@ export function ThreadQueueSheet({ route }: StaticScreenProps) { void act(run.id, "steer")} className="shrink-0 justify-center self-stretch pl-4 active:opacity-70 disabled:opacity-40" diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts index c29ef5eea7aa5..dd105e995aad7 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.test.ts @@ -16,13 +16,29 @@ describe("threadQueueControlPresentation", () => { isEditing, canPromoteToSteer: false, canSendNow: true, - text: "Queued message", + steerRejectionReason: "Context compaction must run as a separate turn.", + text: "/compact", }); expect(controls.canSend).toBe(expected); }, ); + it.each([false, true])( + "gates a queued /compact with compaction skip %s", + (promoteSkipsCompaction) => { + const controls = resolveThreadQueueRowControls({ + busy: false, + canPromoteToSteer: true, + canSendNow: false, + steerRejectionReason: "Context compaction must run as a separate turn.", + text: "/compact", + promoteSkipsCompaction, + }); + expect(controls.canSend).toBe(promoteSkipsCompaction); + }, + ); + it("shows an assistant quote as its quoted text", () => { const href = formatAssistantCitationHref({ version: 1, @@ -39,6 +55,7 @@ describe("threadQueueControlPresentation", () => { busy: false, canPromoteToSteer: true, canSendNow: false, + steerRejectionReason: null, text: `[Assistant quote](${href}) Can we add a backoff here?`, }); @@ -53,6 +70,7 @@ describe("threadQueueControlPresentation", () => { canPromoteToSteer: true, canSendNow: false, isEditing: true, + steerRejectionReason: null, text: "Being edited", }); @@ -68,6 +86,7 @@ describe("threadQueueControlPresentation", () => { canPromoteToSteer: true, canSendNow: false, isGuestMessage: true, + steerRejectionReason: null, text: "Why?", }); diff --git a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts index a62e29e14795d..e80b5a28e2163 100644 --- a/apps/mobile/src/features/threads/threadQueueControlPresentation.ts +++ b/apps/mobile/src/features/threads/threadQueueControlPresentation.ts @@ -17,11 +17,13 @@ export function resolveThreadQueueRowControls(input: { readonly busy: boolean; readonly canPromoteToSteer: boolean; readonly canSendNow: boolean; + readonly promoteSkipsCompaction?: boolean; /** Something else holds the composer, such as an open question. */ readonly editBlocked?: boolean; readonly isEditing?: boolean; /** A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. */ readonly isGuestMessage?: boolean; + readonly steerRejectionReason: string | null; readonly text: string; }): ThreadQueueRowControls { const mutationEnabled = !input.busy; @@ -33,7 +35,12 @@ export function resolveThreadQueueRowControls(input: { // away whatever has been typed since. canEdit: mutationEnabled && !isEditing && input.isGuestMessage !== true && input.editBlocked !== true, - canSend: mutationEnabled && (input.canPromoteToSteer || input.canSendNow) && !isEditing, + canSend: + mutationEnabled && + !isEditing && + (input.canSendNow || + (input.canPromoteToSteer && + (input.promoteSkipsCompaction === true || input.steerRejectionReason === null))), dismissAccessibilityLabel: REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL, // Editing and sending keep the original text so quoted citations stay linked. displayText: isAttachmentOnlyBootstrapPrompt(input.text) diff --git a/apps/server/src/orchestration-v2/CommandPolicy.ts b/apps/server/src/orchestration-v2/CommandPolicy.ts index cd56460369bd6..2e5ab8c6d0cf6 100644 --- a/apps/server/src/orchestration-v2/CommandPolicy.ts +++ b/apps/server/src/orchestration-v2/CommandPolicy.ts @@ -1,6 +1,6 @@ import { - type ChatAttachment, CommandId, + isNativeMaintenanceCommand, type OrchestrationV2Command, OrchestrationV2ProviderCapabilities, type OrchestrationV2GoalCommand, @@ -59,17 +59,6 @@ type MessageDispatchMode = Extract< { readonly type: "message.dispatch" } >["dispatchMode"]; -export function isNativeMaintenanceCommand(message: { - readonly text: string; - readonly attachments: ReadonlyArray; - readonly context?: import("@t3tools/contracts").OrchestrationMessageContext | undefined; -}): boolean { - return ( - message.attachments.length === 0 && - ["/compact", "/logout"].includes(message.text.trim().toLowerCase()) - ); -} - /** * A goal command sent into active work stops that work when it starts or * replaces goal work, or ends a goal that is driving the run. diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index c6d1ab4654110..31cc8fe5cbe10 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -26,6 +26,7 @@ import { type ChatAttachment, CommandId, type GuestMessageId, + isNativeMaintenanceCommand, isCompactionCommandMessage, isOrchestrationV2WorkActive, isProviderNativeSubagentThread, @@ -65,6 +66,7 @@ import { latestProviderTurnForAttempt, parseGoalCommand, orchestrationV2RunWorkStartedAt, + orchestrationV2SteerRejectionReason, ProviderInstanceId, ProviderInteractionMode, isRuntimeModeAbove, @@ -113,7 +115,6 @@ import { followUpOwnerRun, goalCommandStopsActiveRun, isActiveRun, - isNativeMaintenanceCommand, resolveMessageDispatchIntent, } from "./CommandPolicy.ts"; import { CommandReceiptStoreV2, type CommandReceiptV2 } from "./CommandReceiptStore.ts"; @@ -5811,14 +5812,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio >, message: Pick, ) { - if (isNativeMaintenanceCommand(message)) { + const rejectionReason = orchestrationV2SteerRejectionReason(message); + if (rejectionReason !== null) { return yield* new OrchestratorDispatchError({ commandId: command.commandId, commandType: command.type, - cause: - message.text.trim().toLowerCase() === "/compact" - ? "Context compaction must run as a separate turn. Queue it or wait for the active turn to finish." - : "Signing out must run as a separate turn. Queue it or wait for the active turn to finish.", + cause: `${rejectionReason} Queue it or wait for the active turn to finish.`, }); } if (parseGoalCommand(message) !== null) { diff --git a/apps/server/src/orchestration-v2/RestartContinuation.ts b/apps/server/src/orchestration-v2/RestartContinuation.ts index 242e366d4b605..4db2f7c79660d 100644 --- a/apps/server/src/orchestration-v2/RestartContinuation.ts +++ b/apps/server/src/orchestration-v2/RestartContinuation.ts @@ -2,6 +2,7 @@ import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError"; import { resolveProjectSettings } from "@t3tools/shared/projectSettings"; import { CommandId, + isNativeMaintenanceCommand, isOrchestrationV2WorkActive, latestProviderTurnForAttempt, MessageId, @@ -14,7 +15,6 @@ import * as Effect from "effect/Effect"; import type { ProjectionRuntimeRecoveryState } from "./ProjectionStore.ts"; import * as ServerSettings from "../serverSettings.ts"; -import { isNativeMaintenanceCommand } from "./CommandPolicy.ts"; import * as ThreadManagementService from "./ThreadManagementService.ts"; import { awaitingProviderThreadId, diff --git a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx index af20840837d47..7c8f684daffa9 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx @@ -9,13 +9,14 @@ import { import * as DateTime from "effect/DateTime"; import * as Option from "effect/Option"; import { AsyncResult, type Atom, AtomRegistry } from "effect/reactivity"; -import { Profiler, type ComponentProps } from "react"; +import { createRef, Profiler, type ComponentProps } from "react"; import { expect, it, vi } from "vite-plus/test"; import { page } from "vite-plus/test/browser"; const state = vi.hoisted(() => ({ threadState: null as unknown as Atom.Writable>, workflow: null as unknown, + runCommand: vi.fn(async (_input: unknown) => undefined), })); vi.mock(import("@t3tools/client-runtime/state/thread-workflows"), async (importOriginal) => ({ @@ -66,7 +67,7 @@ vi.mock(import("../../state/threads"), async (importOriginal) => { vi.mock(import("../../state/use-atom-command"), async (importOriginal) => ({ ...(await importOriginal()), - useAtomCommand: (() => async () => undefined) as never, + useAtomCommand: (() => state.runCommand) as never, })); vi.mock(import("../../assets/assetUrls"), async (importOriginal) => ({ @@ -80,10 +81,11 @@ import { EMPTY_ENVIRONMENT_THREAD_STATE } from "@t3tools/client-runtime/state/th import { act, render as renderUi } from "../../../test/render"; import { makeStreamingTimelineFixture, makeThreadProjectionFixture } from "../../test-fixtures"; -import { QueuedRunsControl } from "./QueuedRunsControl"; +import { QueuedRunsControl, type QueuedRunsControlHandle } from "./QueuedRunsControl"; function setup() { state.workflow = null; + state.runCommand.mockClear(); } const baseProps = { @@ -331,3 +333,56 @@ it("does not re-render while assistant text streams into the thread", async () = await act(() => registry.set(state.threadState, thread("Hello there", true))); expect(renders).toBeGreaterThan(settled); }); + +it.each([ + { canSendNow: false, promoteSkipsCompaction: false }, + { canSendNow: true, promoteSkipsCompaction: false }, + { canSendNow: false, promoteSkipsCompaction: true }, +])("gates queued command sending with %j", async ({ canSendNow, promoteSkipsCompaction }) => { + setup(); + state.workflow = { + activeRun: { id: "run:active" }, + canSendNow, + promoteSkipsCompaction, + canPromoteToSteer: !canSendNow, + canReorder: true, + queuedRuns: [ + { + run: { id: "run:compact", userMessageId: "message:compact" }, + text: "/compact", + attachments: [], + steerRejectionReason: "Context compaction must run as a separate turn.", + }, + { + run: { id: "run:plain", userMessageId: "message:plain" }, + text: "Also update the docs", + attachments: [], + steerRejectionReason: null, + }, + ], + }; + const ref = createRef(); + await using _screen = await renderQueue({ ref }); + + const steerButtons = page.getByRole("button", { + name: "Send now", + exact: true, + }); + if (canSendNow || promoteSkipsCompaction) await expect.element(steerButtons.nth(0)).toBeEnabled(); + else await expect.element(steerButtons.nth(0)).toBeDisabled(); + await expect.element(steerButtons.nth(1)).toBeEnabled(); + + expect(ref.current?.steerNext(false)).toBe(true); + expect(state.runCommand).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ + input: expect.objectContaining( + canSendNow + ? { runId: "run:compact" } + : { + queuedRunId: promoteSkipsCompaction ? "run:compact" : "run:plain", + targetRunId: "run:active", + }, + ), + }), + ); +}); diff --git a/apps/web/src/components/chat/QueuedRunsControl.tsx b/apps/web/src/components/chat/QueuedRunsControl.tsx index 68fcd504159c3..8c65ac6fb3983 100644 --- a/apps/web/src/components/chat/QueuedRunsControl.tsx +++ b/apps/web/src/components/chat/QueuedRunsControl.tsx @@ -119,6 +119,11 @@ export function QueuedRunsControl({ workflow?.canSendNow === true || (workflow?.canPromoteToSteer === true && (!freshContext || workflow.promoteSkipsCompaction === true)); + const nextSteerable = queued.find( + ({ run, steerRejectionReason }) => + canSendRun(run.freshContext === true) && + (workflow?.canSendNow || workflow?.promoteSkipsCompaction || steerRejectionReason === null), + ); const queuedImageUrlById = new Map( queuedImageAttachmentUrls.flatMap((url, index) => { const resource = queuedImageAttachmentResources[index]; @@ -129,28 +134,32 @@ export function QueuedRunsControl({ (message) => message.inputIntent === "queued_turn" && !acknowledgedMessageIds.has(message.id), ); const items = [ - ...queued.map(({ run, text, attachments, context, message }, serverIndex) => ({ - key: run.id, - message, - runId: run.id, - messageId: run.userMessageId, - freshContext: run.freshContext === true, - serverIndex, - text, - // A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. - editable: context?.guest === undefined, - attachments, - thumbnails: attachments - .filter((attachment) => attachment.type === "image") - .map((attachment) => ({ - key: attachment.id, - name: attachment.name, - url: queuedImageUrlById.get(attachment.id) ?? null, - })), - pending: false, - })), + ...queued.map( + ({ run, text, attachments, context, message, steerRejectionReason }, serverIndex) => ({ + key: run.id, + steerRejectionReason, + message, + runId: run.id, + messageId: run.userMessageId, + freshContext: run.freshContext === true, + serverIndex, + text, + // A guest's message keeps the guest's words; the owner can cancel it, not rewrite it. + editable: context?.guest === undefined, + attachments, + thumbnails: attachments + .filter((attachment) => attachment.type === "image") + .map((attachment) => ({ + key: attachment.id, + name: attachment.name, + url: queuedImageUrlById.get(attachment.id) ?? null, + })), + pending: false, + }), + ), ...optimisticQueued.map((message) => ({ key: message.id, + steerRejectionReason: null, message: undefined, runId: null, messageId: null, @@ -194,8 +203,8 @@ export function QueuedRunsControl({ useImperativeHandle(ref, () => ({ steerNext(repeat) { - const next = queued[0]; - if (!next || !canSendRun(next.run.freshContext === true)) return false; + const next = nextSteerable; + if (!next) return false; if (!repeat && busyRunId === null) void sendQueuedMessage(next.run.id); return true; }, @@ -281,7 +290,13 @@ export function QueuedRunsControl({ - {`${workflow?.canSendNow ? "Start a turn with this message" : workflow?.promoteSkipsCompaction ? "Skip compaction and send this message" : "Send into the current turn"}${item.serverIndex === 0 && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`} + {!workflow?.canSendNow && + !workflow?.promoteSkipsCompaction && + item.steerRejectionReason + ? item.steerRejectionReason + : `${workflow?.canSendNow ? "Start a turn with this message" : workflow?.promoteSkipsCompaction ? "Skip compaction and send this message" : "Send into the current turn"}${item.runId === nextSteerable?.run.id && props.steerShortcutLabel ? ` (${props.steerShortcutLabel})` : ""}`} diff --git a/packages/client-runtime/src/state/threadWorkflows.test.ts b/packages/client-runtime/src/state/threadWorkflows.test.ts index 3fe571e84b5bf..88250ccf30e8d 100644 --- a/packages/client-runtime/src/state/threadWorkflows.test.ts +++ b/packages/client-runtime/src/state/threadWorkflows.test.ts @@ -138,6 +138,73 @@ describe("thread workflows", () => { expect(state.canSendNow).toBe(false); }); + it("marks queued runs the server refuses to steer", () => { + const state = deriveThreadQueueWorkflowState({ + thread: { id: "thread", activeProviderThreadId: null }, + runs: [ + { id: "compact", status: "queued", userMessageId: "message-compact", ordinal: 1 }, + { id: "goal", status: "queued", userMessageId: "message-goal", ordinal: 2 }, + { id: "loading", status: "queued", userMessageId: "message-loading", ordinal: 3 }, + ], + messages: [ + { id: "message-compact", text: "/compact", attachments: [] }, + { id: "message-goal", text: "/goal finish the refactor", attachments: [] }, + ], + providerTurns: [], + providerThreads: [], + providerSessions: [], + } as never); + + expect( + state.queuedRuns.map(({ run, steerRejectionReason }) => [run.id, steerRejectionReason]), + ).toEqual([ + ["compact", "Context compaction must run as a separate turn."], + ["goal", null], + ["loading", "Queued message is still loading."], + ]); + }); + + it.each([ + ["codex", undefined, "codex", null], + ["opencode", true, "opencode", null], + ["opencode", false, "opencode", "Goal commands must run as a separate turn."], + ["pi", undefined, "pi", "Goal commands must run as a separate turn."], + ["pi", undefined, "codex", null], + ])( + "lets a queued goal steer a %s session (native goals %s) when queued for %s", + (driver, supportsNativeGoals, queuedInstanceId, reason) => { + const state = deriveThreadQueueWorkflowState({ + thread: { + id: "thread", + activeProviderThreadId: null, + modelSelection: { instanceId: queuedInstanceId }, + }, + runs: [ + { + id: "goal", + status: "queued", + userMessageId: "message-goal", + ordinal: 1, + modelSelection: { instanceId: queuedInstanceId }, + }, + ], + messages: [{ id: "message-goal", text: "/goal finish the refactor", attachments: [] }], + providerTurns: [], + providerThreads: [], + providerSessions: [ + { + id: "session", + driver, + providerInstanceId: driver, + status: "running", + capabilities: { turns: { supportsNativeGoals } }, + }, + ], + } as never); + + expect(state.queuedRuns[0]?.steerRejectionReason).toBe(reason); + }, + ); it.each(["completed", "interrupted", "cancelled", "failed"])( "allows sending a held message after a %s turn without a live session", (status) => { diff --git a/packages/client-runtime/src/state/threadWorkflows.ts b/packages/client-runtime/src/state/threadWorkflows.ts index 1f50bff8e2468..352fb1ea21a43 100644 --- a/packages/client-runtime/src/state/threadWorkflows.ts +++ b/packages/client-runtime/src/state/threadWorkflows.ts @@ -1,8 +1,10 @@ import { type ChatAttachment, - isCompactionCommandMessage, type OrchestrationV2ProjectedTurnItem, type OrchestrationV2ProviderCapabilities, + orchestrationV2SteerRejectionReason, + isCompactionCommandMessage, + parseGoalCommand, } from "@t3tools/contracts"; import { copySorted } from "@t3tools/shared/Array"; @@ -27,6 +29,8 @@ export interface QueuedThreadRun { readonly attachments: ReadonlyArray; readonly messageId: Message["id"]; readonly context?: Message["context"]; + /** Set when the server would reject promoting this run to a steer. */ + readonly steerRejectionReason: string | null; /** Carries the attribution a sent message shows: automation, agent sender, or guest. */ readonly message?: Message; } @@ -136,10 +140,31 @@ export function getUserQueuedThreadRuns( ); } +function steerRejectionReason( + message: { readonly text: string; readonly attachments: ReadonlyArray }, + runsNativeGoals: boolean, +): string | null { + const reason = orchestrationV2SteerRejectionReason(message); + if (reason !== null || runsNativeGoals || parseGoalCommand(message) === null) return reason; + return "Goal commands must run as a separate turn."; +} + export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQueueWorkflowState { const activeRun = resolveActiveThreadRun(projection); const session = resolveThreadProviderSession(projection); const capabilities = session?.capabilities.turns; + // Mirrors the server's goalDriverFor: elsewhere a goal cannot stop the turn, so it cannot steer. + const sessionRunsNativeGoals = + session === null || + session.driver === "codex" || + session.driver === "claudeAgent" || + ((session.driver === "opencode" || session.driver === "antigravity") && + capabilities?.supportsNativeGoals === true); + // The server checks the queued run's own provider; one the session does not show is left to it. + const runsNativeGoals = (run: Run) => + sessionRunsNativeGoals || + run.modelSelection?.instanceId !== session?.providerInstanceId || + projection.thread.modelSelection?.instanceId !== session?.providerInstanceId; const activeMessage = projection.messages.find( (message) => message.id === activeRun?.userMessageId, ); @@ -163,6 +188,13 @@ export function deriveThreadQueueWorkflowState(projection: Projection): ThreadQu // A queued guest message shows the guest's words; the agent still gets the attributed text. text: message?.context?.guest?.text ?? message?.text ?? "Queued message", attachments: message?.attachments ?? [], + steerRejectionReason: + message === undefined + ? "Queued message is still loading." + : steerRejectionReason( + { text: message.text, attachments: message.attachments ?? [] }, + runsNativeGoals(run), + ), messageId: run.userMessageId, ...(message?.context ? { context: message.context } : {}), ...(message ? { message } : {}), diff --git a/packages/contracts/src/orchestrationV2.test.ts b/packages/contracts/src/orchestrationV2.test.ts index 76f78f536d7c5..b415abcde1822 100644 --- a/packages/contracts/src/orchestrationV2.test.ts +++ b/packages/contracts/src/orchestrationV2.test.ts @@ -6,6 +6,7 @@ import { NodeId, RunAttemptId, TrimmedNonEmptyString } from "./index.ts"; import { latestProviderTurnForAttempt, OrchestrationV2CheckpointFileSummary, + orchestrationV2SteerRejectionReason, OrchestrationV2ProviderCapabilities, OrchestrationV2ProviderThread, OrchestrationV2ProviderThreadJson, @@ -650,3 +651,19 @@ describe("latestProviderTurnForAttempt", () => { expect(latestProviderTurnForAttempt(turns, null)).toBeUndefined(); }); }); + +describe("orchestrationV2SteerRejectionReason", () => { + const image = { type: "image", id: "image", name: "a.png", mimeType: "image/png", sizeBytes: 1 }; + + it.each([ + [" /COMPACT ", [], "Context compaction must run as a separate turn."], + ["/logout", [], "Signing out must run as a separate turn."], + ["/goal finish the refactor", [], null], + ["please /compact later", [], null], + ["/compact", [image], null], + ] as const)("%j with %j attachments", (text, attachments, reason) => { + expect(orchestrationV2SteerRejectionReason({ text, attachments: attachments as never })).toBe( + reason, + ); + }); +}); diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index e4a57262d12dc..8da364f230e33 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -1402,6 +1402,29 @@ export const OrchestrationV2ConversationMessage = Schema.Struct({ }); export type OrchestrationV2ConversationMessage = typeof OrchestrationV2ConversationMessage.Type; +type OrchestrationV2CommandMessage = Pick< + OrchestrationV2ConversationMessage, + "text" | "attachments" +>; + +/** A bare `/compact` or `/logout`: a provider maintenance turn, not conversation. */ +export function isNativeMaintenanceCommand(message: OrchestrationV2CommandMessage): boolean { + return ( + message.attachments.length === 0 && + ["/compact", "/logout"].includes(message.text.trim().toLowerCase()) + ); +} + +/** Why a message cannot steer an active turn. Queued goals promote through their own path. */ +export function orchestrationV2SteerRejectionReason( + message: OrchestrationV2CommandMessage, +): string | null { + if (!isNativeMaintenanceCommand(message)) return null; + return message.text.trim().toLowerCase() === "/compact" + ? "Context compaction must run as a separate turn." + : "Signing out must run as a separate turn."; +} + export const OrchestrationV2PlanStep = Schema.Struct({ id: TrimmedNonEmptyString, text: TrimmedNonEmptyString,