strands-darwin 0.0.44 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/README.zh-CN.md +7 -2
- package/dist/patches/ink+7.1.1.patch +15 -0
- package/dist/src/agent/context-breakdown.d.ts +26 -3
- package/dist/src/agent/context-breakdown.js +27 -1
- package/dist/src/agent/context-breakdown.js.map +1 -1
- package/dist/src/agent/goal-check.d.ts +35 -0
- package/dist/src/agent/goal-check.js +132 -0
- package/dist/src/agent/goal-check.js.map +1 -0
- package/dist/src/agent/model-retry.d.ts +6 -1
- package/dist/src/agent/model-retry.js +45 -9
- package/dist/src/agent/model-retry.js.map +1 -1
- package/dist/src/agent/permission-rules.d.ts +31 -13
- package/dist/src/agent/permission-rules.js +180 -20
- package/dist/src/agent/permission-rules.js.map +1 -1
- package/dist/src/agent/permission.d.ts +0 -6
- package/dist/src/agent/permission.js +23 -5
- package/dist/src/agent/permission.js.map +1 -1
- package/dist/src/agent/runtime.d.ts +44 -1
- package/dist/src/agent/runtime.js +91 -6
- package/dist/src/agent/runtime.js.map +1 -1
- package/dist/src/agent/safety-classifier.d.ts +3 -1
- package/dist/src/agent/safety-classifier.js +0 -0
- package/dist/src/agent/safety-classifier.js.map +1 -1
- package/dist/src/agent/working-context.d.ts +16 -0
- package/dist/src/agent/working-context.js +20 -0
- package/dist/src/agent/working-context.js.map +1 -1
- package/dist/src/cli-completion.d.ts +13 -0
- package/dist/src/cli-completion.js +161 -0
- package/dist/src/cli-completion.js.map +1 -0
- package/dist/src/cli-main.js +3 -1
- package/dist/src/cli-main.js.map +1 -1
- package/dist/src/cli-mcp.d.ts +12 -0
- package/dist/src/cli-mcp.js +111 -0
- package/dist/src/cli-mcp.js.map +1 -0
- package/dist/src/cli-usage.d.ts +1 -1
- package/dist/src/cli-usage.js +3 -0
- package/dist/src/cli-usage.js.map +1 -1
- package/dist/src/cli.js +9 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/collaboration/command.js +1 -1
- package/dist/src/collaboration/command.js.map +1 -1
- package/dist/src/collaboration/local.d.ts +137 -6
- package/dist/src/collaboration/local.js +76 -19
- package/dist/src/collaboration/local.js.map +1 -1
- package/dist/src/collaboration/tools.js +1 -1
- package/dist/src/collaboration/tools.js.map +1 -1
- package/dist/src/commands/custom-commands.d.ts +8 -1
- package/dist/src/commands/custom-commands.js +23 -1
- package/dist/src/commands/custom-commands.js.map +1 -1
- package/dist/src/commands/goal-command.d.ts +26 -0
- package/dist/src/commands/goal-command.js +32 -0
- package/dist/src/commands/goal-command.js.map +1 -0
- package/dist/src/config.d.ts +3 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/dev-repl.js +4 -1
- package/dist/src/dev-repl.js.map +1 -1
- package/dist/src/headless-protocol.d.ts +1 -1
- package/dist/src/headless-protocol.js +5 -0
- package/dist/src/headless-protocol.js.map +1 -1
- package/dist/src/headless-runner.js +5 -0
- package/dist/src/headless-runner.js.map +1 -1
- package/dist/src/headless.js +5 -0
- package/dist/src/headless.js.map +1 -1
- package/dist/src/mcp/oauth-login.d.ts +37 -0
- package/dist/src/mcp/oauth-login.js +263 -0
- package/dist/src/mcp/oauth-login.js.map +1 -0
- package/dist/src/mcp/oauth-net.d.ts +50 -0
- package/dist/src/mcp/oauth-net.js +321 -0
- package/dist/src/mcp/oauth-net.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +89 -0
- package/dist/src/mcp/oauth-provider.js +398 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-store.d.ts +49 -0
- package/dist/src/mcp/oauth-store.js +176 -0
- package/dist/src/mcp/oauth-store.js.map +1 -0
- package/dist/src/mcp/prompts.d.ts +179 -0
- package/dist/src/mcp/prompts.js +349 -0
- package/dist/src/mcp/prompts.js.map +1 -0
- package/dist/src/mcp/registry.d.ts +14 -1
- package/dist/src/mcp/registry.js +86 -5
- package/dist/src/mcp/registry.js.map +1 -1
- package/dist/src/tools/shell-env.d.ts +27 -1
- package/dist/src/tools/shell-env.js +34 -5
- package/dist/src/tools/shell-env.js.map +1 -1
- package/dist/src/tui/App.d.ts +4 -1
- package/dist/src/tui/App.js +394 -20
- package/dist/src/tui/App.js.map +1 -1
- package/dist/src/tui/InputBox.d.ts +8 -2
- package/dist/src/tui/InputBox.js +6 -4
- package/dist/src/tui/InputBox.js.map +1 -1
- package/dist/src/tui/context-format.d.ts +7 -3
- package/dist/src/tui/context-format.js +28 -3
- package/dist/src/tui/context-format.js.map +1 -1
- package/dist/src/tui/external-editor.d.ts +143 -0
- package/dist/src/tui/external-editor.js +482 -0
- package/dist/src/tui/external-editor.js.map +1 -0
- package/dist/src/tui/goal.d.ts +123 -0
- package/dist/src/tui/goal.js +187 -0
- package/dist/src/tui/goal.js.map +1 -0
- package/dist/src/tui/help-format.d.ts +1 -1
- package/dist/src/tui/help-format.js +3 -3
- package/dist/src/tui/help-format.js.map +1 -1
- package/dist/src/tui/mcp-format.d.ts +2 -0
- package/dist/src/tui/mcp-format.js +27 -1
- package/dist/src/tui/mcp-format.js.map +1 -1
- package/dist/src/tui/prompt-editor.d.ts +10 -3
- package/dist/src/tui/prompt-editor.js +18 -3
- package/dist/src/tui/prompt-editor.js.map +1 -1
- package/package.json +1 -1
package/dist/src/tui/App.js
CHANGED
|
@@ -14,9 +14,10 @@ import { peerNotice, peerPrompt } from '../collaboration/protocol.js';
|
|
|
14
14
|
* unfinished answer; while idle the first press only arms. A second press within a
|
|
15
15
|
* short window exits, busy or idle. Ctrl+D always exits.
|
|
16
16
|
*/
|
|
17
|
+
import { open as openFile } from 'node:fs/promises';
|
|
17
18
|
import os from 'node:os';
|
|
18
19
|
import path from 'node:path';
|
|
19
|
-
import { Box, Text, useApp, useBoxMetrics, useInput, usePaste, useStdout, useWindowSize } from 'ink';
|
|
20
|
+
import { Box, Text, useApp, useBoxMetrics, useInput, usePaste, useStdin, useStdout, useWindowSize } from 'ink';
|
|
20
21
|
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from 'react';
|
|
21
22
|
import { AGENTS_FILENAME } from '../agent/instructions.js';
|
|
22
23
|
import { APPROVAL_MODES, describeApprovalMode, isApprovalMode, } from '../agent/permission.js';
|
|
@@ -39,6 +40,8 @@ import { BUILTIN_COMMAND_NAMES } from '../commands/custom-commands.js';
|
|
|
39
40
|
import { WORKFLOW_COMMAND_USAGE, parseWorkflowCommand } from '../commands/workflow-command.js';
|
|
40
41
|
import { parseReviewCommand, REVIEW_COMMIT_USAGE } from '../commands/review-command.js';
|
|
41
42
|
import { MCP_CONFIG_FILENAME, mcpConfigCandidates } from '../mcp/registry.js';
|
|
43
|
+
import { mcpPromptLoadedNotice, mcpPromptOmittedAnything } from '../mcp/prompts.js';
|
|
44
|
+
import { searchPreview } from './search-preview.js';
|
|
42
45
|
import { DARWIN_DIRNAME } from '../paths.js';
|
|
43
46
|
import { readBackgroundTail, readBackgroundTails } from '../tools/background-tail.js';
|
|
44
47
|
import { formatShellEnvNotice } from '../tools/shell-env.js';
|
|
@@ -57,7 +60,7 @@ import { PermissionRulePreview, ruleReviewClaim, ruleReviewLayout } from './perm
|
|
|
57
60
|
import { welcomeLayout } from './WelcomeHeader.js';
|
|
58
61
|
import { ActiveToolCalls } from './ToolCallPanel.js';
|
|
59
62
|
import { QueuedMessages } from './QueuedMessages.js';
|
|
60
|
-
import { backspaceAtCursor, deleteAtCursor, deleteWordAfter, deleteWordBefore, insertAtCursor, killToRowEdge, layoutEditor, moveHorizontal, moveToRowEdge, moveVertical, moveWordHorizontal, popUndo, pushUndo, updateLastCut, LAST_CUT_OVERFLOW_NOTICE, } from './prompt-editor.js';
|
|
63
|
+
import { backspaceAtCursor, deleteAtCursor, deleteWordAfter, deleteWordBefore, insertAtCursor, killToRowEdge, layoutEditor, moveHorizontal, moveToDraftEdge, moveToRowEdge, moveVertical, moveWordHorizontal, normalizeDraftText, popUndo, pushUndo, updateLastCut, LAST_CUT_OVERFLOW_NOTICE, } from './prompt-editor.js';
|
|
61
64
|
import { NO_WORKSPACE_PATHS, applyPathCompletion, scanWorkspacePaths, workspacePathsNote, } from './path-completion.js';
|
|
62
65
|
import { promptCompletionState, visiblePromptCompletions, } from './prompt-completion.js';
|
|
63
66
|
import { openPromptRecall, promptRecallIndicator, stepPromptRecall, } from './prompt-recall.js';
|
|
@@ -67,7 +70,12 @@ import { TANGENT_COMMAND_USAGE, armTangent, captureReturnPoint, discardedPromptC
|
|
|
67
70
|
import { clipboardImageFact, readClipboardImage } from './clipboard-image.js';
|
|
68
71
|
import { DRAFT_STASH_DROP_NOTICE, stashHint, toggleDraftStash } from './draft-stash.js';
|
|
69
72
|
import { delegationWakeEntries, hasQueuedImage, isTaskWake, partitionQueue, queuedCountHint, refusesToQueue, takeBackDraft, } from './prompt-queue.js';
|
|
73
|
+
import { GOAL_CONDITION_MAX_CODE_POINTS, parseGoalCommand } from '../commands/goal-command.js';
|
|
74
|
+
import { boundedReason } from '../agent/goal-check.js';
|
|
75
|
+
import { GOAL_SET_NOTICE, composeGoalEvidence, goalAction, goalAfterCheck, goalAfterTurn, goalBeforeTurn, goalContinuationPrompt, goalContinued, goalLiveSuffix, goalStatusText, newGoal, } from './goal.js';
|
|
70
76
|
import { composeShellReport, parseShellCommand, projectShellOutput, runShellCommand, } from './shell-command.js';
|
|
77
|
+
import { EXTERNAL_EDITOR_UNSET_NOTICE, canQuiesceTerminalInput, editorLabel, externalEditorRefusal, quiesceTerminalInput, resolveEditorCommand, runExternalEditor, } from './external-editor.js';
|
|
78
|
+
import { scrubShellEnv, withDarwinMarker } from '../tools/shell-env.js';
|
|
71
79
|
import { formatTaskCompletion, formatTasksReport, runningTasksHeader } from './task-format.js';
|
|
72
80
|
import { TASK_WAKE_TAIL_LINES, formatTaskNotification, formatTaskWakeUndelivered, taskNotificationFields, } from './task-wake.js';
|
|
73
81
|
import { formatDispatchCancellation, formatDispatchCompletion, formatDispatchesReport, } from './subagent-format.js';
|
|
@@ -103,8 +111,6 @@ const PATH_SCAN_TTL_MS = 5000;
|
|
|
103
111
|
* guessing low costs the scrollback.
|
|
104
112
|
*/
|
|
105
113
|
const ASSUMED_HEADER_ROWS = 14;
|
|
106
|
-
/** C0 controls except LF and tab, plus DEL: never treated as draft text. */
|
|
107
|
-
const NON_TEXT_CONTROLS = /[\u0000-\u0008\u000b-\u001f\u007f]/g;
|
|
108
114
|
/**
|
|
109
115
|
* Erase the screen, the scrollback and home the cursor — Ink's own `clearTerminal`,
|
|
110
116
|
* spelled out here because `ansi-escapes` is Ink's dependency and not darwin's.
|
|
@@ -115,12 +121,9 @@ const NON_TEXT_CONTROLS = /[\u0000-\u0008\u000b-\u001f\u007f]/g;
|
|
|
115
121
|
* different thing from one per text delta.
|
|
116
122
|
*/
|
|
117
123
|
const CLEAR_TERMINAL = '\u001B[2J\u001B[3J\u001B[H';
|
|
118
|
-
/** Canonicalizes terminal line endings and drops controls without losing layout. */
|
|
119
|
-
function normalizeDraftText(value) {
|
|
120
|
-
return value.replace(/\r+\n/g, '\n').replace(/\r/g, '\n').replace(NON_TEXT_CONTROLS, '');
|
|
121
|
-
}
|
|
122
124
|
export function App({ runtime: initialRuntime, permissions, initialHistory = [], startNewSession, startRewind, }) {
|
|
123
|
-
const { exit: inkExit, waitUntilRenderFlush } = useApp();
|
|
125
|
+
const { exit: inkExit, waitUntilRenderFlush, suspendTerminal } = useApp();
|
|
126
|
+
const { stdin } = useStdin();
|
|
124
127
|
const { columns, rows } = useWindowSize();
|
|
125
128
|
const { write: writeToTerminal } = useStdout();
|
|
126
129
|
// The live session. A prop at startup, state afterwards: `/clear` replaces the
|
|
@@ -152,7 +155,16 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
152
155
|
...BUILTIN_COMMAND_NAMES,
|
|
153
156
|
...runtime.info.commandNames,
|
|
154
157
|
...runtime.info.skillNames,
|
|
158
|
+
// SER-114: lowest precedence, after every existing entry. Names were already
|
|
159
|
+
// claimed against everything above, so none of these dedupes anything away.
|
|
160
|
+
...runtime.info.mcpPromptCommands.map((command) => command.name),
|
|
155
161
|
])], [runtime]);
|
|
162
|
+
// Completion-row descriptions for MCP prompt commands: the server's bounded
|
|
163
|
+
// description plus the argument hint; InputBox escapes controls when drawing.
|
|
164
|
+
const commandDescriptions = useMemo(() => new Map(runtime.info.mcpPromptCommands.map((command) => [
|
|
165
|
+
command.name,
|
|
166
|
+
[command.argumentHint, command.description ?? `MCP prompt`].filter((part) => part !== '').join(' · '),
|
|
167
|
+
])), [runtime]);
|
|
156
168
|
// Escape suppresses one computed query generation, not the draft. Mirrors are
|
|
157
169
|
// required for the same reason as the editor/selection mirrors: a second batched
|
|
158
170
|
// key must see the first Escape before React commits its render.
|
|
@@ -299,6 +311,24 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
299
311
|
queuedRef.current = next;
|
|
300
312
|
setQueuedState(next);
|
|
301
313
|
}, []);
|
|
314
|
+
/**
|
|
315
|
+
* The `/goal` loop's state (SER-108), with the same immediate-mirror ref the queue has:
|
|
316
|
+
* effects and the turn tail must read one generation. Live-session state only — never
|
|
317
|
+
* persisted, dropped by `/clear`.
|
|
318
|
+
*/
|
|
319
|
+
const [goal, setGoalState] = useState(undefined);
|
|
320
|
+
const goalRef = useRef(undefined);
|
|
321
|
+
const setGoal = useCallback((next) => {
|
|
322
|
+
goalRef.current = next;
|
|
323
|
+
setGoalState(next);
|
|
324
|
+
}, []);
|
|
325
|
+
/** Set while the goal's own continuation is being submitted; read once at the turn's start. */
|
|
326
|
+
const goalTurnPending = useRef(false);
|
|
327
|
+
/** The in-flight condition check's controller; Ctrl+C aborts only this, never the agent. */
|
|
328
|
+
const goalCheckAbort = useRef(undefined);
|
|
329
|
+
/** What the current turn showed the driver: the bounded record the check reads. */
|
|
330
|
+
const goalAnswers = useRef([]);
|
|
331
|
+
const goalTools = useRef([]);
|
|
302
332
|
/** True from a user Ctrl+C (or a turn failure) until the busy state it aborted ends. */
|
|
303
333
|
const turnAborted = useRef(false);
|
|
304
334
|
/** Latch: one queue entry in flight through submit(); see the drain effect. */
|
|
@@ -309,6 +339,16 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
309
339
|
const clipboardReadGeneration = useRef(0);
|
|
310
340
|
/** Image currently owned by one model-bound invocation, blocking reassociation. */
|
|
311
341
|
const imageTurnInFlight = useRef(false);
|
|
342
|
+
/**
|
|
343
|
+
* Ctrl+G external editing (SER-113). `editorActive` is the repeated-chord fence;
|
|
344
|
+
* the run handle is what unmount reaps. While the terminal is released the shared
|
|
345
|
+
* `draining` latch is held too, so queue, peer and goal drains wait, and the Static
|
|
346
|
+
* history is frozen at its released length: Ink discards renders while suspended,
|
|
347
|
+
* so a notice committed then would advance `<Static>` past an item never printed.
|
|
348
|
+
*/
|
|
349
|
+
const editorActive = useRef(false);
|
|
350
|
+
const editorRun = useRef(undefined);
|
|
351
|
+
const [heldHistory, setHeldHistory] = useState(undefined);
|
|
312
352
|
/**
|
|
313
353
|
* Terminal-only acknowledgement for the answer-close handoff. Dispatching a
|
|
314
354
|
* reducer action proves only that React accepted it; the layout effect below
|
|
@@ -598,7 +638,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
598
638
|
: undefined;
|
|
599
639
|
const busyRetryWait = busyElapsedMs === undefined ? undefined : liveRetryWait(runtime);
|
|
600
640
|
const queuedCounts = partitionQueue(queued);
|
|
601
|
-
const statusHint = hintForStatus(effectiveStatus, busyElapsedMs === undefined ? undefined : busySuffix(busyElapsedMs, liveSpend(runtime), busyRetryWait), queuedCounts.user.length, queuedCounts.wakes.length);
|
|
641
|
+
const statusHint = hintForStatus(effectiveStatus, busyElapsedMs === undefined ? undefined : busySuffix(busyElapsedMs, liveSpend(runtime), busyRetryWait), queuedCounts.user.length, queuedCounts.wakes.length, goalLiveSuffix(goal));
|
|
602
642
|
const streamingHint = statusHint === undefined ? undefined : stashHint(statusHint, draftStash !== undefined, columns);
|
|
603
643
|
const activeToolClaims = state.activeTools.map((tool) => ({
|
|
604
644
|
detailRows: toolDetailsVisible(tool.name, state.toolDetailsExpanded)
|
|
@@ -693,6 +733,9 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
693
733
|
// A `!` command must not outlive the TUI that ran it: on unmount (Ctrl+D, /exit,
|
|
694
734
|
// a second Ctrl+C) the group gets the same TERM→KILL reaping a cancel gives it.
|
|
695
735
|
useEffect(() => () => shellRun.current?.kill(), []);
|
|
736
|
+
// Same for an external editor (SER-113): darwin shutdown TERM→KILLs it and removes
|
|
737
|
+
// its private storage synchronously, since the exit path may not await settlement.
|
|
738
|
+
useEffect(() => () => editorRun.current?.kill(), []);
|
|
696
739
|
// Terminal window/tab title (SER-073): `darwin · <project> · <state>`, one OSC 2
|
|
697
740
|
// sequence straight to the real stdout — the seam the bell uses, never Ink's
|
|
698
741
|
// frame path — and only when the composed title changes, so this is a
|
|
@@ -864,15 +907,47 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
864
907
|
}
|
|
865
908
|
return true;
|
|
866
909
|
}, [dispatch, setAttachedImage, setEditor, setQueued]);
|
|
910
|
+
/** Applies a `/goal` transition: the new state, then its one transcript notice. */
|
|
911
|
+
const applyGoalTransition = useCallback((transition) => {
|
|
912
|
+
setGoal(transition.goal);
|
|
913
|
+
if (transition.notice !== undefined) {
|
|
914
|
+
dispatch({
|
|
915
|
+
type: 'notice',
|
|
916
|
+
text: transition.notice.text,
|
|
917
|
+
...(transition.notice.severity === undefined ? {} : { severity: transition.notice.severity }),
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
}, [dispatch, setGoal]);
|
|
867
921
|
const runTurn = useCallback(async (text, userInput = text, image, origin) => {
|
|
868
922
|
turnStartedAt.current = Date.now();
|
|
869
923
|
turnAborted.current = false;
|
|
924
|
+
// Who started this turn, decided once at its start (SER-108): the goal's own
|
|
925
|
+
// continuation, the session itself (task/delegation wake, peer), or the user.
|
|
926
|
+
const goalKind = origin !== undefined ? 'session' : goalTurnPending.current ? 'goal' : 'user';
|
|
927
|
+
goalTurnPending.current = false;
|
|
928
|
+
goalAnswers.current = [];
|
|
929
|
+
goalTools.current = [];
|
|
930
|
+
if (goalRef.current !== undefined)
|
|
931
|
+
setGoal(goalBeforeTurn(goalRef.current, goalKind));
|
|
870
932
|
let lifecycleOutcome = 'success';
|
|
871
933
|
setStatus('streaming');
|
|
872
934
|
try {
|
|
873
935
|
await runWithStreamResumption(text, async (turnInput) => {
|
|
874
936
|
let answerTailLive = false;
|
|
875
937
|
for await (const event of runtime.send(turnInput, userInput, turnInput === text ? image : undefined, origin)) {
|
|
938
|
+
// The bounded record a `/goal` check may read: observed, never re-read.
|
|
939
|
+
if (goalRef.current !== undefined) {
|
|
940
|
+
if (event.type === 'contentBlockEvent' && event.contentBlock.type === 'textBlock') {
|
|
941
|
+
goalAnswers.current.push(event.contentBlock.text);
|
|
942
|
+
if (goalAnswers.current.length > 64)
|
|
943
|
+
goalAnswers.current.shift();
|
|
944
|
+
}
|
|
945
|
+
else if (event.type === 'afterToolCallEvent') {
|
|
946
|
+
goalTools.current.push({ name: event.toolUse.name, status: event.result.status });
|
|
947
|
+
if (goalTools.current.length > 200)
|
|
948
|
+
goalTools.current.shift();
|
|
949
|
+
}
|
|
950
|
+
}
|
|
876
951
|
if (event.type === 'modelStreamUpdateEvent' &&
|
|
877
952
|
event.event.type === 'modelContentBlockDeltaEvent' &&
|
|
878
953
|
event.event.delta.type === 'textDelta' &&
|
|
@@ -1040,8 +1115,16 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1040
1115
|
for (const problem of runtime.takeHookProblems()) {
|
|
1041
1116
|
dispatch({ type: 'notice', text: `hook: ${problem}`, severity: 'warn' });
|
|
1042
1117
|
}
|
|
1118
|
+
// The `/goal` loop's turn tail (SER-108), last on purpose: every notice this turn
|
|
1119
|
+
// owes has been written before the goal may owe a check. Completed turns owe one
|
|
1120
|
+
// check at the next idle moment; a cancelled or failed one owes nothing, and
|
|
1121
|
+
// cancelled or failed goal-owned work clears the goal.
|
|
1122
|
+
const goalNow = goalRef.current;
|
|
1123
|
+
if (goalNow !== undefined) {
|
|
1124
|
+
applyGoalTransition(goalAfterTurn(goalNow, goalKind, !failed ? 'completed' : lifecycleOutcome === 'cancelled' ? 'cancelled' : 'failed'));
|
|
1125
|
+
}
|
|
1043
1126
|
return !failed;
|
|
1044
|
-
}, [prepareAnswerClose, returnQueuedToEditor, runtime, setTangent, waitUntilRenderFlush]);
|
|
1127
|
+
}, [applyGoalTransition, prepareAnswerClose, returnQueuedToEditor, runtime, setGoal, setTangent, waitUntilRenderFlush]);
|
|
1045
1128
|
const submit = useCallback(async (raw, queuedEntry) => {
|
|
1046
1129
|
const text = raw.trim();
|
|
1047
1130
|
if (clearing.current) {
|
|
@@ -1151,6 +1234,52 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1151
1234
|
applyModeCommand(runtime, text, dispatch);
|
|
1152
1235
|
return;
|
|
1153
1236
|
}
|
|
1237
|
+
// `/goal` (SER-108), before the busy check for the reason `/mode` is: mid-loop is
|
|
1238
|
+
// exactly when a goal needs replacing or switching off, and none of it sends
|
|
1239
|
+
// anything. Setting a goal spends nothing — the first check runs after the next
|
|
1240
|
+
// completed turn. `/goal off` never interrupts running work (Ctrl+C does that); it
|
|
1241
|
+
// withdraws the check in flight, if any, and stops every later continuation.
|
|
1242
|
+
const goalCommand = parseGoalCommand(text);
|
|
1243
|
+
if (goalCommand !== undefined) {
|
|
1244
|
+
setEditor({ text: '', cursor: { offset: 0, affinity: 'downstream' } });
|
|
1245
|
+
setSelectedCompletion(0);
|
|
1246
|
+
dispatch({ type: 'userInput', text });
|
|
1247
|
+
if (goalCommand.kind === 'status') {
|
|
1248
|
+
dispatch({ type: 'notice', text: goalStatusText(goalRef.current) });
|
|
1249
|
+
}
|
|
1250
|
+
else if (goalCommand.kind === 'too-long') {
|
|
1251
|
+
dispatch({
|
|
1252
|
+
type: 'notice',
|
|
1253
|
+
text: `goal condition is ${goalCommand.length} code points; the limit is ${GOAL_CONDITION_MAX_CODE_POINTS} — goal unchanged`,
|
|
1254
|
+
severity: 'warn',
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
else if (goalCommand.kind === 'off') {
|
|
1258
|
+
if (goalRef.current === undefined) {
|
|
1259
|
+
dispatch({ type: 'notice', text: 'no goal to clear' });
|
|
1260
|
+
}
|
|
1261
|
+
else {
|
|
1262
|
+
const checkInFlight = goalCheckAbort.current;
|
|
1263
|
+
checkInFlight?.abort();
|
|
1264
|
+
setGoal(undefined);
|
|
1265
|
+
dispatch({
|
|
1266
|
+
type: 'notice',
|
|
1267
|
+
text: checkInFlight !== undefined
|
|
1268
|
+
? 'goal cleared — the check in flight was cancelled'
|
|
1269
|
+
: status !== 'idle'
|
|
1270
|
+
? 'goal cleared — the running work is not interrupted (ctrl+c cancels it)'
|
|
1271
|
+
: 'goal cleared',
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
else {
|
|
1276
|
+
const replaced = goalRef.current !== undefined;
|
|
1277
|
+
goalCheckAbort.current?.abort();
|
|
1278
|
+
setGoal(newGoal(goalCommand.condition));
|
|
1279
|
+
dispatch({ type: 'notice', text: GOAL_SET_NOTICE(goalCommand.condition, replaced) });
|
|
1280
|
+
}
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1154
1283
|
// Before the busy check for the same reason as /mode: revocation only ever
|
|
1155
1284
|
// *narrows* what runs silently, and mid-turn is exactly when a rule that
|
|
1156
1285
|
// turned out too broad needs pulling — the gate stops honouring it before
|
|
@@ -1734,6 +1863,11 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1734
1863
|
setQueued([]);
|
|
1735
1864
|
clipboardReadGeneration.current += 1;
|
|
1736
1865
|
setAttachedImage(undefined);
|
|
1866
|
+
// The goal (SER-108) was about the conversation just set aside; it dies with it.
|
|
1867
|
+
// `/clear` is idle-only, so no check is in flight; a continuation owed is dropped.
|
|
1868
|
+
const droppedGoal = goalRef.current;
|
|
1869
|
+
setGoal(undefined);
|
|
1870
|
+
goalTurnPending.current = false;
|
|
1737
1871
|
// Mirrored to the *successor's* diagnostics log: the memoized `dispatch` still
|
|
1738
1872
|
// points at the predecessor's, which this switch has just closed.
|
|
1739
1873
|
withNoticeDiagnostics(recordAction, next.diagnostics)({
|
|
@@ -1741,6 +1875,12 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1741
1875
|
text: `cleared — new session ${next.info.sessionId}. Previous session ${previousSessionId} is saved and ` +
|
|
1742
1876
|
`resumable (darwin --session ${previousSessionId}); background jobs and MCP servers keep running.`,
|
|
1743
1877
|
});
|
|
1878
|
+
if (droppedGoal !== undefined) {
|
|
1879
|
+
withNoticeDiagnostics(recordAction, next.diagnostics)({
|
|
1880
|
+
type: 'notice',
|
|
1881
|
+
text: `goal dropped with the cleared conversation: ${droppedGoal.condition}`,
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1744
1884
|
// The tangent bookmarked a conversation this session no longer holds
|
|
1745
1885
|
// (SER-083): it ends with one notice, and no rewind is performed for it.
|
|
1746
1886
|
if (tangentRef.current !== undefined) {
|
|
@@ -1818,6 +1958,15 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1818
1958
|
// Skills and project commands send their expanded prompt instead of the
|
|
1819
1959
|
// literal command. Unknown slash input falls through as ordinary input.
|
|
1820
1960
|
let toSend = text;
|
|
1961
|
+
// SER-114: an MCP prompt is the one expansion that waits on a server. Hold the
|
|
1962
|
+
// session busy meanwhile — submissions queue, Ctrl+C reaches `runtime.cancel()`,
|
|
1963
|
+
// which aborts the `prompts/get` — exactly like the goal check's busy state.
|
|
1964
|
+
const fetchingMcpPrompt = runtime.isMcpPromptCommand(text);
|
|
1965
|
+
if (fetchingMcpPrompt) {
|
|
1966
|
+
turnAborted.current = false;
|
|
1967
|
+
turnStartedAt.current = Date.now();
|
|
1968
|
+
setStatus('streaming');
|
|
1969
|
+
}
|
|
1821
1970
|
try {
|
|
1822
1971
|
const expanded = await runtime.expandSlashCommand(text);
|
|
1823
1972
|
if (expanded !== null) {
|
|
@@ -1833,12 +1982,19 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1833
1982
|
? expanded.message.startsWith('Review commit ')
|
|
1834
1983
|
? 'reviewing commit with /review'
|
|
1835
1984
|
: 'reviewing current changes with /review'
|
|
1836
|
-
:
|
|
1985
|
+
: expanded.kind === 'mcp-prompt'
|
|
1986
|
+
? mcpPromptLoadedNotice(expanded)
|
|
1987
|
+
: `loaded command "/${expanded.command.name}"`,
|
|
1988
|
+
...(expanded.kind === 'mcp-prompt' && mcpPromptOmittedAnything(expanded.omitted) ? { severity: 'warn' } : {}),
|
|
1837
1989
|
});
|
|
1838
1990
|
toSend = expanded.message;
|
|
1839
1991
|
}
|
|
1840
1992
|
}
|
|
1841
1993
|
catch (error) {
|
|
1994
|
+
if (fetchingMcpPrompt) {
|
|
1995
|
+
turnStartedAt.current = undefined;
|
|
1996
|
+
setStatus('idle');
|
|
1997
|
+
}
|
|
1842
1998
|
dispatch({
|
|
1843
1999
|
type: 'notice',
|
|
1844
2000
|
text: `could not expand ${text}: ${error instanceof Error ? error.message : String(error)}; prompt not sent — restored to the editor`,
|
|
@@ -1877,7 +2033,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1877
2033
|
severity: 'warn',
|
|
1878
2034
|
});
|
|
1879
2035
|
}
|
|
1880
|
-
}, [adoptBranchSuccessor, dispatch, exit, openRewindChooser, recordAction, returnQueuedToEditor, runtime, runTurn, setAttachedImage, setDraftStash, setEditor, setQueued, setTangent, startNewSession, startRewind, status, writeToTerminal]);
|
|
2036
|
+
}, [adoptBranchSuccessor, dispatch, exit, openRewindChooser, recordAction, returnQueuedToEditor, runtime, runTurn, setAttachedImage, setDraftStash, setEditor, setGoal, setQueued, setTangent, startNewSession, startRewind, status, writeToTerminal]);
|
|
1881
2037
|
// The drain (SER-027): when the session is idle and nothing owns the keyboard,
|
|
1882
2038
|
// the oldest queued entry goes back through the ordinary submit path — its own
|
|
1883
2039
|
// turn for a prompt, its own run for a `!`, its own `userInput` recorded at
|
|
@@ -1950,6 +2106,77 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1950
2106
|
dispatch({ type: 'notice', severity: 'warn', text: `peer message ${peer.envelope.id} failed/cancelled; not re-sent` });
|
|
1951
2107
|
}).finally(() => { draining.current = false; setDrainCycle(cycle => cycle + 1); });
|
|
1952
2108
|
}, [peerCycle, drainCycle, pendingPermission, queued, runtime, runTurn, status, dispatch]);
|
|
2109
|
+
// The `/goal` loop (SER-108): the lowest-priority owner of an idle session. It is asked
|
|
2110
|
+
// in the same commits as the two effects above and declared after them, so anything
|
|
2111
|
+
// they take — a queued prompt, `!`, task/delegation wake, peer message — sets the
|
|
2112
|
+
// shared `draining` latch first and the goal simply waits for the next idle moment.
|
|
2113
|
+
// `goalAction` is the whole gate (idle, no permission decision, no `/clear`, empty queue,
|
|
2114
|
+
// empty peer inbox); a pending permission prompt therefore holds both the check and the
|
|
2115
|
+
// continuation exactly as it holds the queue.
|
|
2116
|
+
//
|
|
2117
|
+
// `check`: one bounded model call outside the agent loop, with the session held busy so
|
|
2118
|
+
// submissions queue behind it and Ctrl+C reaches it (`goalCheckAbort`). `continue`:
|
|
2119
|
+
// exactly one prompt through the ordinary `submit()`, as a drained entry — it never
|
|
2120
|
+
// touches the draft or an attached image, and it counts against the cap at dispatch.
|
|
2121
|
+
useEffect(() => {
|
|
2122
|
+
const current = goalRef.current;
|
|
2123
|
+
const action = goalAction(current, {
|
|
2124
|
+
idle: status === 'idle',
|
|
2125
|
+
permissionPending: pendingPermission !== undefined,
|
|
2126
|
+
clearing: clearing.current,
|
|
2127
|
+
draining: draining.current,
|
|
2128
|
+
queued: queuedRef.current.length,
|
|
2129
|
+
peerPending: runtime.collaboration?.pending ?? 0,
|
|
2130
|
+
});
|
|
2131
|
+
if (current === undefined || action === 'none')
|
|
2132
|
+
return;
|
|
2133
|
+
draining.current = true;
|
|
2134
|
+
if (action === 'continue') {
|
|
2135
|
+
const prompt = goalContinuationPrompt(current.condition, current.note ?? '(no note)');
|
|
2136
|
+
setGoal(goalContinued(current));
|
|
2137
|
+
goalTurnPending.current = true;
|
|
2138
|
+
void submit(prompt, { text: prompt }).finally(() => {
|
|
2139
|
+
goalTurnPending.current = false;
|
|
2140
|
+
draining.current = false;
|
|
2141
|
+
setDrainCycle((cycle) => cycle + 1);
|
|
2142
|
+
});
|
|
2143
|
+
return;
|
|
2144
|
+
}
|
|
2145
|
+
const checking = { ...current, phase: 'checking' };
|
|
2146
|
+
setGoal(checking);
|
|
2147
|
+
const controller = new AbortController();
|
|
2148
|
+
goalCheckAbort.current = controller;
|
|
2149
|
+
turnAborted.current = false;
|
|
2150
|
+
turnStartedAt.current = Date.now();
|
|
2151
|
+
setStatus('streaming');
|
|
2152
|
+
void (async () => {
|
|
2153
|
+
let result;
|
|
2154
|
+
try {
|
|
2155
|
+
const verdict = await runtime.checkGoal(current.condition, composeGoalEvidence(goalAnswers.current, goalTools.current), controller.signal);
|
|
2156
|
+
result = { kind: 'verdict', ...verdict };
|
|
2157
|
+
}
|
|
2158
|
+
catch (error) {
|
|
2159
|
+
result = controller.signal.aborted
|
|
2160
|
+
? { kind: 'cancelled' }
|
|
2161
|
+
: { kind: 'error', message: boundedReason(error instanceof Error ? error.message : String(error)) };
|
|
2162
|
+
}
|
|
2163
|
+
goalCheckAbort.current = undefined;
|
|
2164
|
+
turnStartedAt.current = undefined;
|
|
2165
|
+
setStatus('idle');
|
|
2166
|
+
// A goal replaced or switched off while the check ran already said so; its result
|
|
2167
|
+
// belongs to nothing now and is dropped. A user Ctrl+C left the state as it was.
|
|
2168
|
+
if (goalRef.current === checking)
|
|
2169
|
+
applyGoalTransition(goalAfterCheck(checking, result));
|
|
2170
|
+
// A cancelled check never silently sends the queue (SER-027), like a cancelled turn.
|
|
2171
|
+
if (turnAborted.current) {
|
|
2172
|
+
turnAborted.current = false;
|
|
2173
|
+
returnQueuedToEditor(true);
|
|
2174
|
+
}
|
|
2175
|
+
})().finally(() => {
|
|
2176
|
+
draining.current = false;
|
|
2177
|
+
setDrainCycle((cycle) => cycle + 1);
|
|
2178
|
+
});
|
|
2179
|
+
}, [applyGoalTransition, drainCycle, goal, peerCycle, pendingPermission, queued, returnQueuedToEditor, runtime, setGoal, status, submit]);
|
|
1953
2180
|
/**
|
|
1954
2181
|
* Answers the pending confirmation and, when the user picked an "always allow"
|
|
1955
2182
|
* option, remembers the rule.
|
|
@@ -2257,6 +2484,134 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
2257
2484
|
if (opened.text !== undefined)
|
|
2258
2485
|
applyRecalled(opened.text);
|
|
2259
2486
|
}, [applyRecalled, history, setRecall]);
|
|
2487
|
+
/**
|
|
2488
|
+
* Ctrl+G (SER-113): edit the exact unsent draft in the user's VISUAL/EDITOR. Eligible
|
|
2489
|
+
* only at idle with nothing about to claim the session; the editor gets the terminal
|
|
2490
|
+
* through Ink's `suspendTerminal`, darwin's own tty reads are paused for its lifetime
|
|
2491
|
+
* (see `quiesceTerminalInput`), and drains hold behind the shared `draining` latch.
|
|
2492
|
+
* A valid changed result replaces the draft, cursor at the end, and stays unsent.
|
|
2493
|
+
* Everything else — refusal, launch failure, nonzero/signal exit, invalid output or
|
|
2494
|
+
* no change — leaves the draft, cursor and image exactly as they were.
|
|
2495
|
+
*/
|
|
2496
|
+
const openExternalEditor = useCallback(() => {
|
|
2497
|
+
if (historySearchRef.current !== undefined || rewindSearchRef.current !== undefined)
|
|
2498
|
+
return;
|
|
2499
|
+
const goalOwed = goalAction(goalRef.current, {
|
|
2500
|
+
idle: true, permissionPending: false, clearing: false, draining: false, queued: 0, peerPending: 0,
|
|
2501
|
+
}) !== 'none';
|
|
2502
|
+
const refusal = externalEditorRefusal({
|
|
2503
|
+
editorActive: editorActive.current,
|
|
2504
|
+
idle: status === 'idle' && pendingPermission === undefined,
|
|
2505
|
+
queued: queuedRef.current.length,
|
|
2506
|
+
draining: draining.current,
|
|
2507
|
+
clearing: clearing.current,
|
|
2508
|
+
goalOwed,
|
|
2509
|
+
peerPending: runtime.collaboration?.pending ?? 0,
|
|
2510
|
+
liveDelegations: runtime.listBackgroundDelegations().length,
|
|
2511
|
+
});
|
|
2512
|
+
if (refusal === 'ignore')
|
|
2513
|
+
return;
|
|
2514
|
+
if (refusal !== undefined) {
|
|
2515
|
+
dispatch({ type: 'notice', text: refusal, severity: 'warn' });
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
const command = resolveEditorCommand(process.env);
|
|
2519
|
+
if (command.kind === 'unset') {
|
|
2520
|
+
dispatch({ type: 'notice', text: EXTERNAL_EDITOR_UNSET_NOTICE, severity: 'warn' });
|
|
2521
|
+
return;
|
|
2522
|
+
}
|
|
2523
|
+
if (command.kind === 'refused') {
|
|
2524
|
+
dispatch({ type: 'notice', text: `${command.source} not used: it ${command.reason} — draft unchanged`, severity: 'warn' });
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2527
|
+
if (!stdin.isTTY || !canQuiesceTerminalInput(stdin)) {
|
|
2528
|
+
dispatch({ type: 'notice', text: 'Ctrl+G needs an interactive terminal darwin can hand over safely — draft unchanged', severity: 'warn' });
|
|
2529
|
+
return;
|
|
2530
|
+
}
|
|
2531
|
+
const original = editorRef.current;
|
|
2532
|
+
const label = editorLabel(command.argv);
|
|
2533
|
+
// The same sanitized map the model's `bash` gets, plus `DARWIN=1` (SER-082/094).
|
|
2534
|
+
const env = withDarwinMarker(scrubShellEnv(process.env, runtime.info.shellEnv.passthrough).env);
|
|
2535
|
+
const cwd = runtime.info.projectRoot;
|
|
2536
|
+
editorActive.current = true;
|
|
2537
|
+
draining.current = true;
|
|
2538
|
+
// A clipboard read still pending must not attach while (or after) the draft is away.
|
|
2539
|
+
clipboardReadGeneration.current += 1;
|
|
2540
|
+
setHeldHistory(historyRef.current);
|
|
2541
|
+
void (async () => {
|
|
2542
|
+
let outcome;
|
|
2543
|
+
let failure;
|
|
2544
|
+
let restartInput = () => { };
|
|
2545
|
+
try {
|
|
2546
|
+
// Let Ink finish the input batch that carried Ctrl+G and commit the held history.
|
|
2547
|
+
await waitUntilRenderFlush();
|
|
2548
|
+
// A fresh description of the controlling terminal: whatever the editor does to
|
|
2549
|
+
// its file status flags (O_NONBLOCK) cannot leak into darwin's own stdin.
|
|
2550
|
+
const terminal = await openFile('/dev/tty', 'r+').catch(() => undefined);
|
|
2551
|
+
try {
|
|
2552
|
+
await suspendTerminal(async () => {
|
|
2553
|
+
restartInput = await quiesceTerminalInput(stdin);
|
|
2554
|
+
const run = runExternalEditor(original.text, {
|
|
2555
|
+
argv: command.argv,
|
|
2556
|
+
cwd,
|
|
2557
|
+
env,
|
|
2558
|
+
normalize: normalizeDraftText,
|
|
2559
|
+
projectRoot: cwd,
|
|
2560
|
+
...(terminal === undefined ? {} : { terminalFd: terminal.fd }),
|
|
2561
|
+
});
|
|
2562
|
+
editorRun.current = run;
|
|
2563
|
+
outcome = await run.done;
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
finally {
|
|
2567
|
+
editorRun.current = undefined;
|
|
2568
|
+
await terminal?.close().catch(() => undefined);
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
catch (error) {
|
|
2572
|
+
failure = error instanceof Error ? error.message : String(error);
|
|
2573
|
+
}
|
|
2574
|
+
finally {
|
|
2575
|
+
// Shutdown leaves darwin's terminal reads stopped on purpose.
|
|
2576
|
+
if (presentationMounted.current)
|
|
2577
|
+
restartInput();
|
|
2578
|
+
setHeldHistory(undefined);
|
|
2579
|
+
editorActive.current = false;
|
|
2580
|
+
draining.current = false;
|
|
2581
|
+
setDrainCycle((cycle) => cycle + 1);
|
|
2582
|
+
}
|
|
2583
|
+
if (!presentationMounted.current)
|
|
2584
|
+
return;
|
|
2585
|
+
if (outcome === undefined) {
|
|
2586
|
+
dispatch({ type: 'notice', text: `external editor failed: ${failure ?? 'no result'} — draft unchanged`, severity: 'warn' });
|
|
2587
|
+
}
|
|
2588
|
+
else if (outcome.kind === 'changed') {
|
|
2589
|
+
if (editorRef.current !== original) {
|
|
2590
|
+
dispatch({ type: 'notice', text: 'the draft changed while the editor was open; editor result discarded', severity: 'warn' });
|
|
2591
|
+
}
|
|
2592
|
+
else {
|
|
2593
|
+
// A different draft: undo/cut/recall/completion state belonged to the old one.
|
|
2594
|
+
undoStack.current = [];
|
|
2595
|
+
lastCut.current = '';
|
|
2596
|
+
preferredColumn.current = undefined;
|
|
2597
|
+
setRecall(undefined);
|
|
2598
|
+
setDismissedCompletion(undefined);
|
|
2599
|
+
setSelectedCompletion(0);
|
|
2600
|
+
setEditor({ text: outcome.text, cursor: moveToDraftEdge(outcome.text, 'end') });
|
|
2601
|
+
dispatch({ type: 'notice', text: `draft replaced from ${label} — not sent; Enter sends it` });
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
else if (outcome.kind === 'unchanged') {
|
|
2605
|
+
dispatch({ type: 'notice', text: `${label} closed without changes — draft unchanged` });
|
|
2606
|
+
}
|
|
2607
|
+
else {
|
|
2608
|
+
dispatch({ type: 'notice', text: `external editor: ${outcome.reason} — draft unchanged`, severity: 'warn' });
|
|
2609
|
+
}
|
|
2610
|
+
if (outcome?.cleanupProblem !== undefined) {
|
|
2611
|
+
dispatch({ type: 'notice', text: `external editor storage: ${outcome.cleanupProblem}`, severity: 'warn' });
|
|
2612
|
+
}
|
|
2613
|
+
})();
|
|
2614
|
+
}, [dispatch, pendingPermission, runtime, setDismissedCompletion, setEditor, setRecall, setSelectedCompletion, status, stdin, suspendTerminal, waitUntilRenderFlush]);
|
|
2260
2615
|
const handleInterrupt = useCallback(() => {
|
|
2261
2616
|
const now = Date.now();
|
|
2262
2617
|
const previous = interruptedAt.current;
|
|
@@ -2291,6 +2646,14 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
2291
2646
|
// be able to ask for approval. The abort mark is what keeps the queue from
|
|
2292
2647
|
// being silently sent when the cancelled turn winds down (SER-027).
|
|
2293
2648
|
turnAborted.current = true;
|
|
2649
|
+
// The goal's condition check (SER-108) is a busy state with no agent turn behind it:
|
|
2650
|
+
// Ctrl+C aborts exactly that call. The runtime's cancel would also close the peer
|
|
2651
|
+
// inbox for a turn that does not exist.
|
|
2652
|
+
if (goalCheckAbort.current !== undefined) {
|
|
2653
|
+
goalCheckAbort.current.abort();
|
|
2654
|
+
dispatch({ type: 'notice', text: 'interrupted — press ctrl+c again to exit' });
|
|
2655
|
+
return;
|
|
2656
|
+
}
|
|
2294
2657
|
permissions.denyPending();
|
|
2295
2658
|
runtime.cancel();
|
|
2296
2659
|
dispatch({ type: 'notice', text: 'interrupted — press ctrl+c again to exit' });
|
|
@@ -2428,6 +2791,13 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
2428
2791
|
}
|
|
2429
2792
|
return;
|
|
2430
2793
|
}
|
|
2794
|
+
// External editor (SER-113): composer ownership like Ctrl+S/Ctrl+O, below the
|
|
2795
|
+
// permission, compaction and search owners. Eligibility and the repeated-chord
|
|
2796
|
+
// fence live in `openExternalEditor`.
|
|
2797
|
+
if (key.ctrl && typed === 'g') {
|
|
2798
|
+
openExternalEditor();
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2431
2801
|
// Escape belongs to the highest transient prompt UI currently shown. A menu
|
|
2432
2802
|
// wins over recall just as it wins the arrow keys; neither branch touches the
|
|
2433
2803
|
// editor, submits, dispatches, or changes the queue/runtime. The dismissed query
|
|
@@ -2641,7 +3011,9 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
2641
3011
|
if (key.home || key.end) {
|
|
2642
3012
|
setEditor((current) => ({
|
|
2643
3013
|
...current,
|
|
2644
|
-
cursor:
|
|
3014
|
+
cursor: key.ctrl
|
|
3015
|
+
? moveToDraftEdge(current.text, key.home ? 'start' : 'end')
|
|
3016
|
+
: moveToRowEdge(layoutEditor(current.text, columns, current.cursor), key.home ? 'start' : 'end'),
|
|
2645
3017
|
}));
|
|
2646
3018
|
preferredColumn.current = undefined;
|
|
2647
3019
|
return;
|
|
@@ -2713,17 +3085,17 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
2713
3085
|
setSelectedCompletion(0);
|
|
2714
3086
|
endRecall();
|
|
2715
3087
|
});
|
|
2716
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(
|
|
3088
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(MessageList, { history: heldHistory ?? state.history, ...(state.staticEpoch === 0 ? { welcome: initialWelcome } : {}), liveText: state.liveText, liveCodeOpen: fenceOpenAfter(state.committedAnswer), columns: columns, maxLiveRows: grants.live, staticEpoch: state.staticEpoch }), _jsx(Box, { ref: headerRef, flexDirection: "column", children: _jsx(Header, { runtime: runtime, status: effectiveStatus, frame: frame, tangent: tangent, goal: goal, runningTaskCount: runningTaskCount, draftStashed: statusHint === undefined && draftStash !== undefined }) }), _jsxs(Box, { ref: chromeRef, flexDirection: "column", children: [state.thinking && effectiveStatus === 'streaming' && (_jsx(Text, { dimColor: true, wrap: "truncate-end", children: `thinking…${busyElapsedMs === undefined ? '' : busySuffix(busyElapsedMs, undefined, busyRetryWait)}` })), _jsx(ActiveToolCalls, { tools: state.activeTools, frame: frame, toolDetailsExpanded: state.toolDetailsExpanded, columns: columns, maxRows: grants.tools }), _jsx(PlanChecklist, { plan: state.livePlan, maxRows: grants.plan }), _jsx(QueuedMessages, { entries: queued, maxRows: grants.queued }), activeRuleReview !== undefined ? _jsx(PermissionRulePreview, { review: activeRuleReview }) : pendingPermission !== undefined ? (_jsx(PermissionPrompt, { request: pendingPermission, waiting: permissions.waiting, columns: columns, maxRows: grants.prompt })) : (_jsx(InputBox, { layout: layout, completions: completions, completionKind: completionKind, completionNote: completionNote, commandDescriptions: commandDescriptions, selectedCompletion: selectedCompletion, editable: effectiveStatus !== 'compacting', offset: { top: chrome.top, left: chrome.left }, maxRows: grants.prompt, hint: streamingHint, attachment: attachedImage === undefined ? undefined : clipboardImageFact(attachedImage), recallIndicator: recallIndicator, historySearch: historySearchProjection, rewindSearch: rewindSearchProjection }))] })] }));
|
|
2717
3089
|
}
|
|
2718
3090
|
/** The hint row under the draft, or nothing when the session is idle. */
|
|
2719
|
-
function hintForStatus(status, busyReadout, queuedCount = 0, queuedWakeCount = 0) {
|
|
3091
|
+
function hintForStatus(status, busyReadout, queuedCount = 0, queuedWakeCount = 0, goalSuffix = '') {
|
|
2720
3092
|
if (status === 'streaming') {
|
|
2721
3093
|
// The live readout rides directly behind `working…`, ahead of the static command
|
|
2722
3094
|
// hints: the row is one truncated <Text>, so on a narrow terminal the tail is what
|
|
2723
3095
|
// goes missing, and the tail should be the part that never changes. The queue
|
|
2724
3096
|
// count (SER-027) rides with it: even a listing cut to nothing stays counted here,
|
|
2725
3097
|
// typed entries and background-task wakes (SER-069) each under their own word.
|
|
2726
|
-
return `working…${busyReadout ?? ''}${queuedCountHint(queuedCount, queuedWakeCount)} /tasks lists jobs · /agents lists dispatches · /usage reports tokens · ctrl+c cancels this turn`;
|
|
3098
|
+
return `working…${busyReadout ?? ''}${goalSuffix}${queuedCountHint(queuedCount, queuedWakeCount)} /tasks lists jobs · /agents lists dispatches · /usage reports tokens · ctrl+c cancels this turn`;
|
|
2727
3099
|
}
|
|
2728
3100
|
// Elapsed lives on the command's own panel row, so this row can stay static.
|
|
2729
3101
|
if (status === 'shell')
|
|
@@ -2762,7 +3134,7 @@ function lastRetryOutcome(runtime) {
|
|
|
2762
3134
|
return undefined;
|
|
2763
3135
|
}
|
|
2764
3136
|
}
|
|
2765
|
-
export function Header({ runtime, status = 'idle', frame = 0, tangent, runningTaskCount = 0, draftStashed = false, }) {
|
|
3137
|
+
export function Header({ runtime, status = 'idle', frame = 0, tangent, goal, runningTaskCount = 0, draftStashed = false, }) {
|
|
2766
3138
|
const { columns } = useWindowSize();
|
|
2767
3139
|
const info = runtime.info;
|
|
2768
3140
|
const instructions = info.projectInstructions;
|
|
@@ -2771,12 +3143,14 @@ export function Header({ runtime, status = 'idle', frame = 0, tangent, runningTa
|
|
|
2771
3143
|
// place the effective mode is stated, and it must not gain a second one.
|
|
2772
3144
|
const mode = runtime.permissionMode;
|
|
2773
3145
|
const stateLabel = status === 'streaming' ? 'working' : headerStatus(status);
|
|
2774
|
-
const tangentSuffix = tangentHeaderSuffix(tangent);
|
|
3146
|
+
const tangentSuffix = tangentHeaderSuffix(tangent) + goalLiveSuffix(goal);
|
|
2775
3147
|
const activity = runningTasksHeader(runningTaskCount, columns - `◆ DARWIN · ${stateLabel}${tangentSuffix}`.length, frame);
|
|
2776
3148
|
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { wrap: "truncate-end", children: [_jsxs(Text, { color: visualColor.identity, bold: true, children: [visualMarker.identity, " DARWIN"] }), _jsxs(Text, { dimColor: true, children: [' · ', status === 'streaming' ? _jsx(WorkingStatus, { frame: frame }) : headerStatus(status), tangentSuffix] }), _jsx(Text, { color: visualColor.active, children: activity.label }), _jsx(Text, { dimColor: true, children: activity.hint })] }), _jsxs(Text, { dimColor: true, children: [runtime.config.provider, "/", runtime.config.model, " \u00B7 session ", info.sessionId, info.resumed ? ' (resumed)' : '', formatPromptCache(runtime.promptCache), formatThinking(runtime.thinking)] }), mode === 'yolo' ? (_jsxs(Text, { color: visualColor.warning, children: ["mode: ", describeMode(mode, runtime.allowRuleCount, runtime.denyRuleCount)] })) : mode === 'plan' ? (_jsxs(Text, { color: visualColor.warning, children: ["mode: ", describeMode(mode, runtime.allowRuleCount, runtime.denyRuleCount)] })) : (_jsxs(Text, { dimColor: true, children: ["mode: ", describeMode(mode, runtime.allowRuleCount, runtime.denyRuleCount)] })), instructions !== undefined &&
|
|
2777
|
-
(instructions.truncated ? (_jsx(Text, { color: visualColor.warning, children: formatInstructionsLoadedRow(instructions) })) : (_jsx(Text, { dimColor: true, children: formatInstructionsLoadedRow(instructions) }))), info.projectInstructionsProblem !== undefined && (_jsx(Text, { color: visualColor.warning, children: formatInstructionsProblemRow(info.projectInstructionsProblemFile ?? AGENTS_FILENAME, info.projectInstructionsProblem) })), info.systemPromptSource === 'config' && (_jsxs(Text, { dimColor: true, children: ["system prompt: overridden by ", DARWIN_DIRNAME, "/", CONFIG_FILENAME] })), info.systemPromptSource === 'file' && (_jsxs(Text, { dimColor: true, children: ["system prompt: ", DARWIN_DIRNAME, "/", SYSTEM_PROMPT_FILENAME] })), info.systemPromptProblem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["system prompt: using the default \u2014 ", info.systemPromptProblem] })), info.workingContextProblem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["working context: no directory listing \u2014 ", info.workingContextProblem] })), info.promptCache.problem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["prompt cache: off \u2014 ", info.promptCache.problem] })), runtime.thinking.problem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["thinking: ", runtime.thinking.problem] })), hasCapabilities(info) && (_jsxs(Text, { dimColor: true, children: ["loaded: ", formatCapabilities(info), " \u00B7 type / for commands"] })), info.mcpIgnoredConfigPath !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["mcp: using ", DARWIN_DIRNAME, "/", MCP_CONFIG_FILENAME, " \u2014 ", info.mcpIgnoredConfigPath, " ignored"] })), info.hookShadowNotices.map((notice) => (_jsxs(Text, { color: visualColor.warning, wrap: "truncate-end", children: ["hooks: ", notice.layer, " ", notice.directory, " shadows ", notice.shadowed.join(', ')] }, notice.directory))), info.skillProblems.map((problem) => (_jsxs(Text, { color: visualColor.warning, children: ["skill skipped: ", problem.directory, " \u2014 ", problem.reason] }, problem.directory))), info.commandProblems.map((problem) => (_jsxs(Text, { color: visualColor.warning, children: ["command skipped: ", problem.file, " \u2014 ", problem.reason] }, problem.file))), info.agentProblems.map((problem) => (_jsxs(Text, { color: visualColor.warning, children: ["agent skipped: ", problem.file, " \u2014 ", problem.reason] }, problem.file))), _jsx(Text, { dimColor: true, children: stashHint('/ for actions · @ for paths · ctrl+c cancels · /exit quits', draftStashed, columns) })] }));
|
|
3149
|
+
(instructions.truncated ? (_jsx(Text, { color: visualColor.warning, children: formatInstructionsLoadedRow(instructions) })) : (_jsx(Text, { dimColor: true, children: formatInstructionsLoadedRow(instructions) }))), info.projectInstructionsProblem !== undefined && (_jsx(Text, { color: visualColor.warning, children: formatInstructionsProblemRow(info.projectInstructionsProblemFile ?? AGENTS_FILENAME, info.projectInstructionsProblem) })), info.systemPromptSource === 'config' && (_jsxs(Text, { dimColor: true, children: ["system prompt: overridden by ", DARWIN_DIRNAME, "/", CONFIG_FILENAME] })), info.systemPromptSource === 'file' && (_jsxs(Text, { dimColor: true, children: ["system prompt: ", DARWIN_DIRNAME, "/", SYSTEM_PROMPT_FILENAME] })), info.systemPromptProblem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["system prompt: using the default \u2014 ", info.systemPromptProblem] })), info.workingContextProblem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["working context: no directory listing \u2014 ", info.workingContextProblem] })), info.promptCache.problem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["prompt cache: off \u2014 ", info.promptCache.problem] })), runtime.thinking.problem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["thinking: ", runtime.thinking.problem] })), hasCapabilities(info) && (_jsxs(Text, { dimColor: true, children: ["loaded: ", formatCapabilities(info), " \u00B7 type / for commands"] })), info.mcpIgnoredConfigPath !== undefined && (_jsxs(Text, { color: visualColor.warning, children: ["mcp: using ", DARWIN_DIRNAME, "/", MCP_CONFIG_FILENAME, " \u2014 ", info.mcpIgnoredConfigPath, " ignored"] })), info.hookShadowNotices.map((notice) => (_jsxs(Text, { color: visualColor.warning, wrap: "truncate-end", children: ["hooks: ", notice.layer, " ", notice.directory, " shadows ", notice.shadowed.join(', ')] }, notice.directory))), info.skillProblems.map((problem) => (_jsxs(Text, { color: visualColor.warning, children: ["skill skipped: ", problem.directory, " \u2014 ", problem.reason] }, problem.directory))), info.commandProblems.map((problem) => (_jsxs(Text, { color: visualColor.warning, children: ["command skipped: ", problem.file, " \u2014 ", problem.reason] }, problem.file))), info.mcpPromptProblems.slice(0, MAX_MCP_PROMPT_PROBLEM_ROWS).map((problem, index) => (_jsx(Text, { color: visualColor.warning, wrap: "truncate-end", children: searchPreview(problem) }, `mcp-prompt-${index}`))), info.mcpPromptProblems.length > MAX_MCP_PROMPT_PROBLEM_ROWS && (_jsxs(Text, { color: visualColor.warning, wrap: "truncate-end", children: ["\u2026 ", info.mcpPromptProblems.length - MAX_MCP_PROMPT_PROBLEM_ROWS, " more MCP prompt problems \u2014 /mcp shows per-server counts"] })), info.agentProblems.map((problem) => (_jsxs(Text, { color: visualColor.warning, children: ["agent skipped: ", problem.file, " \u2014 ", problem.reason] }, problem.file))), _jsx(Text, { dimColor: true, children: stashHint('/ for actions · @ for paths · ctrl+c cancels · /exit quits', draftStashed, columns) })] }));
|
|
2778
3150
|
}
|
|
2779
3151
|
const WORKING_LABEL = 'working';
|
|
3152
|
+
/** Startup header rows for MCP prompt problems before one `… N more` row (SER-114). */
|
|
3153
|
+
const MAX_MCP_PROMPT_PROBLEM_ROWS = 3;
|
|
2780
3154
|
/** Highlights one letter in place, preserving the header's exact width and row count. */
|
|
2781
3155
|
export function workingStatusIndex(frame) {
|
|
2782
3156
|
return frame % WORKING_LABEL.length;
|