strands-darwin 0.0.32 → 0.0.34
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 +3 -1
- package/README.zh-CN.md +3 -1
- package/dist/src/agent/background-delegation.d.ts +69 -11
- package/dist/src/agent/background-delegation.js +156 -28
- package/dist/src/agent/background-delegation.js.map +1 -1
- package/dist/src/agent/cache-miss.d.ts +143 -0
- package/dist/src/agent/cache-miss.js +182 -0
- package/dist/src/agent/cache-miss.js.map +1 -0
- package/dist/src/agent/compact.d.ts +28 -0
- package/dist/src/agent/compact.js +34 -0
- package/dist/src/agent/compact.js.map +1 -1
- package/dist/src/agent/context-breakdown.d.ts +109 -0
- package/dist/src/agent/context-breakdown.js +116 -0
- package/dist/src/agent/context-breakdown.js.map +1 -0
- package/dist/src/agent/instructions.d.ts +1 -1
- package/dist/src/agent/instructions.js.map +1 -1
- package/dist/src/agent/permission-rules.d.ts +81 -2
- package/dist/src/agent/permission-rules.js +226 -6
- package/dist/src/agent/permission-rules.js.map +1 -1
- package/dist/src/agent/permission.d.ts +116 -2
- package/dist/src/agent/permission.js +201 -26
- package/dist/src/agent/permission.js.map +1 -1
- package/dist/src/agent/prompt-cache.d.ts +12 -3
- package/dist/src/agent/prompt-cache.js +12 -3
- package/dist/src/agent/prompt-cache.js.map +1 -1
- package/dist/src/agent/runtime.d.ts +141 -1
- package/dist/src/agent/runtime.js +259 -13
- package/dist/src/agent/runtime.js.map +1 -1
- package/dist/src/agent/task-terminal-delivery.d.ts +43 -0
- package/dist/src/agent/task-terminal-delivery.js +115 -0
- package/dist/src/agent/task-terminal-delivery.js.map +1 -0
- package/dist/src/agents/child-recipe.d.ts +9 -1
- package/dist/src/agents/child-recipe.js +2 -0
- package/dist/src/agents/child-recipe.js.map +1 -1
- package/dist/src/agents/dispatch-registry.d.ts +18 -0
- package/dist/src/agents/dispatch-registry.js +2 -0
- package/dist/src/agents/dispatch-registry.js.map +1 -1
- package/dist/src/agents/retained-children.d.ts +101 -0
- package/dist/src/agents/retained-children.js +101 -0
- package/dist/src/agents/retained-children.js.map +1 -0
- package/dist/src/agents/subagent-tool.d.ts +56 -1
- package/dist/src/agents/subagent-tool.js +148 -10
- package/dist/src/agents/subagent-tool.js.map +1 -1
- package/dist/src/agents/workflow-tool.d.ts +2 -0
- package/dist/src/agents/workflow-tool.js +1 -1
- package/dist/src/agents/workflow-tool.js.map +1 -1
- package/dist/src/cli-doctor.js +3 -1
- package/dist/src/cli-doctor.js.map +1 -1
- package/dist/src/cli-main.js +14 -3
- package/dist/src/cli-main.js.map +1 -1
- package/dist/src/commands/custom-commands.js +5 -4
- package/dist/src/commands/custom-commands.js.map +1 -1
- package/dist/src/config.d.ts +57 -6
- package/dist/src/config.js +43 -16
- package/dist/src/config.js.map +1 -1
- package/dist/src/headless-protocol.d.ts +1 -1
- package/dist/src/headless-runner.js +7 -2
- package/dist/src/headless-runner.js.map +1 -1
- package/dist/src/hooks/tool-hooks.js +10 -6
- package/dist/src/hooks/tool-hooks.js.map +1 -1
- package/dist/src/skills/builtin/self-evolution-research/SKILL.md +14 -1
- package/dist/src/skills/prompt.d.ts +17 -0
- package/dist/src/skills/prompt.js +20 -0
- package/dist/src/skills/prompt.js.map +1 -1
- package/dist/src/tools/background-bash.d.ts +11 -2
- package/dist/src/tools/background-bash.js +11 -5
- package/dist/src/tools/background-bash.js.map +1 -1
- package/dist/src/tools/background-tail.d.ts +1 -0
- package/dist/src/tools/background-tail.js +2 -1
- package/dist/src/tools/background-tail.js.map +1 -1
- package/dist/src/tools/background-wait-contract.d.ts +7 -0
- package/dist/src/tools/background-wait-contract.js +17 -0
- package/dist/src/tools/background-wait-contract.js.map +1 -1
- package/dist/src/trajectory/record.d.ts +212 -2
- package/dist/src/trajectory/record.js +138 -0
- package/dist/src/trajectory/record.js.map +1 -1
- package/dist/src/trajectory/replay.d.ts +34 -1
- package/dist/src/trajectory/replay.js +148 -4
- package/dist/src/trajectory/replay.js.map +1 -1
- package/dist/src/trajectory/resume-recap.js +10 -3
- package/dist/src/trajectory/resume-recap.js.map +1 -1
- package/dist/src/trajectory/spend.d.ts +14 -1
- package/dist/src/trajectory/spend.js +40 -6
- package/dist/src/trajectory/spend.js.map +1 -1
- package/dist/src/trajectory/writer.d.ts +57 -6
- package/dist/src/trajectory/writer.js +141 -9
- package/dist/src/trajectory/writer.js.map +1 -1
- package/dist/src/tui/App.d.ts +8 -4
- package/dist/src/tui/App.js +302 -55
- package/dist/src/tui/App.js.map +1 -1
- package/dist/src/tui/background-tool-presentation.js +2 -2
- package/dist/src/tui/background-tool-presentation.js.map +1 -1
- package/dist/src/tui/context-format.d.ts +16 -0
- package/dist/src/tui/context-format.js +41 -0
- package/dist/src/tui/context-format.js.map +1 -1
- package/dist/src/tui/prompt-queue.d.ts +52 -8
- package/dist/src/tui/prompt-queue.js +68 -8
- package/dist/src/tui/prompt-queue.js.map +1 -1
- package/dist/src/tui/status-format.d.ts +35 -16
- package/dist/src/tui/status-format.js +67 -8
- package/dist/src/tui/status-format.js.map +1 -1
- package/dist/src/tui/subagent-format.d.ts +8 -0
- package/dist/src/tui/subagent-format.js +24 -1
- package/dist/src/tui/subagent-format.js.map +1 -1
- package/dist/src/tui/task-wake.d.ts +75 -0
- package/dist/src/tui/task-wake.js +201 -0
- package/dist/src/tui/task-wake.js.map +1 -0
- package/dist/src/tui/terminal-notify.d.ts +40 -0
- package/dist/src/tui/terminal-notify.js +136 -0
- package/dist/src/tui/terminal-notify.js.map +1 -0
- package/dist/src/tui/terminal-title.d.ts +94 -0
- package/dist/src/tui/terminal-title.js +121 -0
- package/dist/src/tui/terminal-title.js.map +1 -0
- package/dist/src/tui/turn-state.d.ts +10 -1
- package/dist/src/tui/turn-state.js +17 -1
- package/dist/src/tui/turn-state.js.map +1 -1
- package/package.json +1 -1
package/dist/src/tui/App.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The TUI root and its state machine.
|
|
4
|
+
*
|
|
5
|
+
* Status transitions: `idle → streaming|compacting → idle`, with
|
|
6
|
+
* `awaiting-permission` entered from `streaming` whenever the gate asks a
|
|
7
|
+
* question and left when the user answers.
|
|
8
|
+
*
|
|
9
|
+
* Ctrl+C is handled here rather than by Ink (`exitOnCtrlC: false` at the render
|
|
10
|
+
* call): during a turn the first press cancels that turn but keeps the session,
|
|
11
|
+
* because losing a long conversation to a stray interrupt is worse than an
|
|
12
|
+
* unfinished answer; a second press within a short window, or any press while
|
|
13
|
+
* idle, exits. Ctrl+D always exits.
|
|
14
|
+
*/
|
|
15
|
+
import os from 'node:os';
|
|
16
|
+
import path from 'node:path';
|
|
2
17
|
import { Box, Text, useApp, useBoxMetrics, useInput, usePaste, useStdout, useWindowSize } from 'ink';
|
|
3
18
|
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from 'react';
|
|
4
19
|
import { AGENTS_FILENAME, MAX_INSTRUCTIONS_BYTES } from '../agent/instructions.js';
|
|
5
20
|
import { APPROVAL_MODES, describeApprovalMode, isApprovalMode, } from '../agent/permission.js';
|
|
6
|
-
import { compactFocusRefusal, normalizeCompactFocus } from '../agent/compact.js';
|
|
21
|
+
import { compactAndRecord, compactFocusRefusal, normalizeCompactFocus } from '../agent/compact.js';
|
|
7
22
|
import { formatUsageValue, sumUsage, usageBuckets, usageRows, cacheEffectivenessRows } from '../agent/usage.js';
|
|
8
23
|
import { describeModelCosts } from '../agent/cost.js';
|
|
9
24
|
import { averageRequestInputTokens } from '../agent/call-stats.js';
|
|
25
|
+
import { describeCacheMissCause, warmCacheSwitchNotice } from '../agent/cache-miss.js';
|
|
10
26
|
import { runWithStreamResumption, STREAM_CONTINUATION_NOTICE } from '../agent/stream-resumption.js';
|
|
11
27
|
import { retryFailureNotice } from '../agent/model-retry.js';
|
|
12
28
|
import { isRefusalStop, REFUSAL_NOTICE } from '../agent/refusal.js';
|
|
@@ -19,7 +35,7 @@ import { BUILTIN_COMMAND_NAMES } from '../commands/custom-commands.js';
|
|
|
19
35
|
import { WORKFLOW_COMMAND_USAGE, parseWorkflowCommand } from '../commands/workflow-command.js';
|
|
20
36
|
import { MCP_CONFIG_FILENAME, mcpConfigCandidates } from '../mcp/registry.js';
|
|
21
37
|
import { DARWIN_DIRNAME } from '../paths.js';
|
|
22
|
-
import { readBackgroundTails } from '../tools/background-tail.js';
|
|
38
|
+
import { readBackgroundTail, readBackgroundTails } from '../tools/background-tail.js';
|
|
23
39
|
import { exportTranscript } from '../trajectory/export.js';
|
|
24
40
|
import { readPromptHistory, } from '../trajectory/prompt-history.js';
|
|
25
41
|
import { InputBox, MAX_COMPLETIONS, completionSelection, moveCompletionSelection, } from './InputBox.js';
|
|
@@ -39,17 +55,21 @@ import { openPromptRecall, promptRecallIndicator, stepPromptRecall, } from './pr
|
|
|
39
55
|
import { acceptPromptHistorySearch, appendPromptHistorySearchQuery, backspacePromptHistorySearchQuery, cancelPromptHistorySearch, clearPromptHistorySearchQuery, movePromptHistorySearchSelection, openPromptHistorySearch, promptHistorySearchView, resolvePromptHistorySearch, } from './prompt-history-search.js';
|
|
40
56
|
import { ESCAPE_REWIND_CHORD_MS, acceptRewindSearch, appendRewindSearchQuery, backspaceRewindSearchQuery, cancelRewindSearch, clearRewindSearchQuery, moveRewindSearchSelection, openRewindSearch, rewindSearchView, } from './rewind-search.js';
|
|
41
57
|
import { clipboardImageFact, readClipboardImage } from './clipboard-image.js';
|
|
42
|
-
import { hasQueuedImage, queuedCountHint, refusesToQueue, takeBackDraft } from './prompt-queue.js';
|
|
58
|
+
import { delegationWakeEntries, hasQueuedImage, isTaskWake, partitionQueue, queuedCountHint, refusesToQueue, takeBackDraft, } from './prompt-queue.js';
|
|
43
59
|
import { composeShellReport, parseShellCommand, projectShellOutput, runShellCommand, } from './shell-command.js';
|
|
44
60
|
import { formatTaskCompletion, formatTasksReport } from './task-format.js';
|
|
61
|
+
import { TASK_WAKE_TAIL_LINES, formatTaskNotification, formatTaskWakeUndelivered, taskNotificationFields, } from './task-wake.js';
|
|
45
62
|
import { formatDispatchCancellation, formatDispatchCompletion, formatDispatchesReport, } from './subagent-format.js';
|
|
46
|
-
import {
|
|
63
|
+
import { liveBackgroundDelegationRefusal } from '../agent/background-delegation.js';
|
|
64
|
+
import { createContextWarnLatch, formatContextReport, formatContextReportWithBreakdown } from './context-format.js';
|
|
47
65
|
import { COPY_COMMAND_USAGE, runCopyCommand } from './copy-command.js';
|
|
48
66
|
import { formatHelpReport } from './help-format.js';
|
|
49
67
|
import { formatMcpReport } from './mcp-format.js';
|
|
50
|
-
import { formatPromptCache, formatPromptCacheState, formatStatusReport, formatThinking, } from './status-format.js';
|
|
68
|
+
import { describeMode, formatPromptCache, formatPromptCacheState, formatStatusReport, formatThinking, } from './status-format.js';
|
|
51
69
|
import { PlanChecklist } from './PlanChecklist.js';
|
|
52
70
|
import { ringTerminalBell } from './terminal-bell.js';
|
|
71
|
+
import { notifyTerminal } from './terminal-notify.js';
|
|
72
|
+
import { createTerminalTitleWriter, deriveTerminalTitleState } from './terminal-title.js';
|
|
53
73
|
import { initialTurnState, turnReducer } from './turn-state.js';
|
|
54
74
|
import { visualColor, visualMarker } from './visual-language.js';
|
|
55
75
|
/** Window in which a second Ctrl+C means "exit", not "cancel again". */
|
|
@@ -111,6 +131,10 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
111
131
|
const historyRef = useRef(state.history);
|
|
112
132
|
historyRef.current = state.history;
|
|
113
133
|
const [status, setStatus] = useState('idle');
|
|
134
|
+
// Mirror for subscription callbacks that must read the live status without being
|
|
135
|
+
// rebuilt per status change (the delegation-settlement listener, SER-070).
|
|
136
|
+
const statusRef = useRef(status);
|
|
137
|
+
statusRef.current = status;
|
|
114
138
|
const [workspacePaths, setWorkspacePaths] = useState(NO_WORKSPACE_PATHS);
|
|
115
139
|
const commandNames = useMemo(() => [
|
|
116
140
|
...BUILTIN_COMMAND_NAMES,
|
|
@@ -375,6 +399,14 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
375
399
|
dispatch({ type: 'notice', text: '/rewind is not available in this driver', severity: 'warn' });
|
|
376
400
|
return false;
|
|
377
401
|
}
|
|
402
|
+
// The SDK's `assertCanLoadSnapshot` throws while a background task is tracked, so a
|
|
403
|
+
// live delegation (SER-070) is refused here, before the chooser opens: no partial
|
|
404
|
+
// restore, no model call — the notice names the tasks and the two exits.
|
|
405
|
+
const liveDelegations = runtime.listBackgroundDelegations();
|
|
406
|
+
if (liveDelegations.length > 0) {
|
|
407
|
+
dispatch({ type: 'notice', text: liveBackgroundDelegationRefusal('/rewind', liveDelegations), severity: 'warn' });
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
378
410
|
const catalogue = await runtime.listRewindCheckpoints();
|
|
379
411
|
if (catalogue.problem !== undefined) {
|
|
380
412
|
dispatch({ type: 'notice', text: `rewind unavailable: ${catalogue.problem}`, severity: 'warn' });
|
|
@@ -469,7 +501,8 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
469
501
|
? Date.now() - turnStartedAt.current
|
|
470
502
|
: undefined;
|
|
471
503
|
const busyRetryWait = busyElapsedMs === undefined ? undefined : liveRetryWait(runtime);
|
|
472
|
-
const
|
|
504
|
+
const queuedCounts = partitionQueue(queued);
|
|
505
|
+
const streamingHint = hintForStatus(effectiveStatus, busyElapsedMs === undefined ? undefined : busySuffix(busyElapsedMs, liveSpend(runtime), busyRetryWait), queuedCounts.user.length, queuedCounts.wakes.length);
|
|
473
506
|
const activeToolClaims = state.activeTools.map((tool) => ({
|
|
474
507
|
detailRows: toolDetailsVisible(tool.name, state.toolDetailsExpanded)
|
|
475
508
|
? toolInputRows(tool.input, columns, tool.name).length
|
|
@@ -539,6 +572,26 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
539
572
|
// A `!` command must not outlive the TUI that ran it: on unmount (Ctrl+D, /exit,
|
|
540
573
|
// a second Ctrl+C) the group gets the same TERM→KILL reaping a cancel gives it.
|
|
541
574
|
useEffect(() => () => shellRun.current?.kill(), []);
|
|
575
|
+
// Terminal window/tab title (SER-073): `darwin · <project> · <state>`, one OSC 2
|
|
576
|
+
// sequence straight to the real stdout — the seam the bell uses, never Ink's
|
|
577
|
+
// frame path — and only when the composed title changes, so this is a
|
|
578
|
+
// transition write, not a tick. State is derived from what the App already owns:
|
|
579
|
+
// a published permission prompt outranks a running turn, which outranks idle, and
|
|
580
|
+
// a non-empty queue is a ` · N queued` suffix on whichever base holds. `/clear`
|
|
581
|
+
// hands over a runtime for the same tree, so the title
|
|
582
|
+
// simply continues; unmount (every exit path) restores the bare project name once.
|
|
583
|
+
const [terminalTitle] = useState(() => createTerminalTitleWriter({ isTTY: process.stdout.isTTY === true }));
|
|
584
|
+
useEffect(() => {
|
|
585
|
+
terminalTitle.show({
|
|
586
|
+
projectBasename: path.basename(runtime.info.projectRoot),
|
|
587
|
+
state: deriveTerminalTitleState({
|
|
588
|
+
permissionPending: pendingPermission !== undefined,
|
|
589
|
+
busy: status !== 'idle',
|
|
590
|
+
queued: queued.length,
|
|
591
|
+
}),
|
|
592
|
+
}, runtime.config.terminalTitle !== false);
|
|
593
|
+
}, [pendingPermission, queued.length, runtime, status, terminalTitle]);
|
|
594
|
+
useEffect(() => () => terminalTitle.restore(), [terminalTitle]);
|
|
542
595
|
// The SDK's default logger writes to the console, which tears this frame. It has
|
|
543
596
|
// something to say now that `/model` exists: switching away from Claude with a
|
|
544
597
|
// reasoning block in the history makes the OpenAI adapter warn, once per
|
|
@@ -558,9 +611,44 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
558
611
|
// Terminal task events are transcript-only observers: they never alter turn
|
|
559
612
|
// status, active tools, permissions, or the agent loop. React dispatch also
|
|
560
613
|
// causes an immediate idle render; cleanup prevents shutdown notices after exit.
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
614
|
+
//
|
|
615
|
+
// With `backgroundTaskWake` on (the default), the same terminal snapshot — and
|
|
616
|
+
// only that snapshot: never output activity, never a turn end — also leaves one
|
|
617
|
+
// wake entry in the prompt queue (SER-069), so the model learns of the completion
|
|
618
|
+
// as one ordinary drained turn instead of by polling `wait`. Exactly once per
|
|
619
|
+
// task: the manager publishes one snapshot, and a task already queued or already
|
|
620
|
+
// delivered to the model through a completed turn's `wait`/`status` result is not
|
|
621
|
+
// queued again. Independent of busy state: mid-turn it waits like any prompt
|
|
622
|
+
// (SER-027, next-turn-only). The tail read is the one async step; a subscription
|
|
623
|
+
// that ended before it resolved (`/clear` replaced the runtime) drops the wake
|
|
624
|
+
// rather than handing a predecessor's job to the successor's queue.
|
|
625
|
+
useEffect(() => {
|
|
626
|
+
let live = true;
|
|
627
|
+
const unsubscribe = runtime.subscribeToBackgroundTasks((task) => {
|
|
628
|
+
dispatch({ type: 'notice', text: formatTaskCompletion(task) });
|
|
629
|
+
if (runtime.config.backgroundTaskWake === false)
|
|
630
|
+
return;
|
|
631
|
+
const fields = taskNotificationFields(task);
|
|
632
|
+
if (fields === undefined)
|
|
633
|
+
return;
|
|
634
|
+
void readBackgroundTail(task.outputPath, { lines: TASK_WAKE_TAIL_LINES }).then((tail) => {
|
|
635
|
+
if (!live || runtime.terminalStateDelivered(task.taskId))
|
|
636
|
+
return;
|
|
637
|
+
if (queuedRef.current.some((entry) => isTaskWake(entry) && entry.taskId === task.taskId))
|
|
638
|
+
return;
|
|
639
|
+
const wake = {
|
|
640
|
+
kind: 'taskNotification',
|
|
641
|
+
...fields,
|
|
642
|
+
text: formatTaskNotification(task, tail),
|
|
643
|
+
};
|
|
644
|
+
setQueued([...queuedRef.current, wake]);
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
return () => {
|
|
648
|
+
live = false;
|
|
649
|
+
unsubscribe();
|
|
650
|
+
};
|
|
651
|
+
}, [dispatch, runtime, setQueued]);
|
|
564
652
|
// Same observer-only contract for finished delegations: a notice, never a status
|
|
565
653
|
// change. Concurrent children finish in an order nobody scripted, so a dispatch
|
|
566
654
|
// that ends mid-turn (or while a prompt is up) has to be able to say so without
|
|
@@ -568,25 +656,56 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
568
656
|
useEffect(() => runtime.subscribeToSubagentDispatches((dispatched) => {
|
|
569
657
|
dispatch({ type: 'notice', text: formatDispatchCompletion(dispatched) });
|
|
570
658
|
}), [runtime]);
|
|
659
|
+
// A background delegation's settlement (SER-070) wakes the agent through the same
|
|
660
|
+
// queue as a finished job — but only when nothing else would start a turn. Busy,
|
|
661
|
+
// the SDK itself attaches the result pair before the running turn's next model call
|
|
662
|
+
// (or at its end), so a wake would be a second turn about a delivered report; idle,
|
|
663
|
+
// one wake entry names the delegation (never its report — the SDK attaches that to
|
|
664
|
+
// the wake turn's own request). Exactly once per task: `delegationWakesSent`
|
|
665
|
+
// remembers every id ever queued, and the drain drops a wake whose task the SDK no
|
|
666
|
+
// longer tracks. The idle sweep below closes the one gap the settlement listener
|
|
667
|
+
// cannot see — a run that settled in the last microtasks of a turn, too late for
|
|
668
|
+
// the SDK's end-of-invocation delivery, is still tracked when the turn ends.
|
|
669
|
+
const delegationWakesSent = useRef(new Set());
|
|
670
|
+
const enqueueDelegationWakes = useCallback(() => {
|
|
671
|
+
if (runtime.config.backgroundTaskWake === false)
|
|
672
|
+
return;
|
|
673
|
+
const additions = delegationWakeEntries(runtime.listBackgroundDelegations(), delegationWakesSent.current);
|
|
674
|
+
if (additions.length === 0)
|
|
675
|
+
return;
|
|
676
|
+
for (const entry of additions)
|
|
677
|
+
delegationWakesSent.current.add(entry.taskId);
|
|
678
|
+
setQueued([...queuedRef.current, ...additions]);
|
|
679
|
+
}, [runtime, setQueued]);
|
|
680
|
+
useEffect(() => runtime.subscribeToBackgroundDelegations(() => {
|
|
681
|
+
if (statusRef.current === 'idle')
|
|
682
|
+
enqueueDelegationWakes();
|
|
683
|
+
}), [enqueueDelegationWakes, runtime]);
|
|
684
|
+
useEffect(() => {
|
|
685
|
+
if (status === 'idle')
|
|
686
|
+
enqueueDelegationWakes();
|
|
687
|
+
}, [enqueueDelegationWakes, status]);
|
|
571
688
|
// Safe phase changes and periodic heartbeats update only the existing live tool
|
|
572
689
|
// row. They never append transcript history or enter the model/trajectory.
|
|
573
690
|
useEffect(() => runtime.subscribeToSubagentProgress((progress) => {
|
|
574
691
|
dispatch({ type: 'subagentProgress', progress });
|
|
575
692
|
}), [runtime]);
|
|
576
693
|
/**
|
|
577
|
-
* Puts every queued entry back into the editor, unsent — ahead of any
|
|
578
|
-
* text, one per line, cursor at the end — and says so. The take-back gesture
|
|
694
|
+
* Puts every queued **user** entry back into the editor, unsent — ahead of any
|
|
695
|
+
* typed text, one per line, cursor at the end — and says so. The take-back gesture
|
|
579
696
|
* and the post-abort return share this so "what a cancel does to the queue"
|
|
580
697
|
* and "what `Up` does to the queue" cannot drift apart; `withNotice` is the
|
|
581
|
-
* only difference (the gesture explains itself).
|
|
698
|
+
* only difference (the gesture explains itself). Background-task wakes (SER-069)
|
|
699
|
+
* have nothing to edit and stay in the queue, in order: a cancel re-queues them
|
|
700
|
+
* rather than dropping them, and the drain sends them once the session is idle.
|
|
582
701
|
*/
|
|
583
702
|
const returnQueuedToEditor = useCallback((withNotice) => {
|
|
584
|
-
const entries = queuedRef.current;
|
|
703
|
+
const { user: entries, wakes } = partitionQueue(queuedRef.current);
|
|
585
704
|
if (entries.length === 0)
|
|
586
705
|
return false;
|
|
587
706
|
const text = takeBackDraft(entries, editorRef.current.text);
|
|
588
707
|
const returnedImage = entries.find((entry) => entry.image !== undefined)?.image;
|
|
589
|
-
setQueued(
|
|
708
|
+
setQueued(wakes);
|
|
590
709
|
if (returnedImage !== undefined)
|
|
591
710
|
setAttachedImage(returnedImage);
|
|
592
711
|
// The queue's entries replace the draft wholesale; the drafts destroyed by
|
|
@@ -603,7 +722,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
603
722
|
}
|
|
604
723
|
return true;
|
|
605
724
|
}, [dispatch, setAttachedImage, setEditor, setQueued]);
|
|
606
|
-
const runTurn = useCallback(async (text, userInput = text, image) => {
|
|
725
|
+
const runTurn = useCallback(async (text, userInput = text, image, origin) => {
|
|
607
726
|
turnStartedAt.current = Date.now();
|
|
608
727
|
turnAborted.current = false;
|
|
609
728
|
let lifecycleOutcome = 'success';
|
|
@@ -611,7 +730,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
611
730
|
try {
|
|
612
731
|
await runWithStreamResumption(text, async (turnInput) => {
|
|
613
732
|
let answerTailLive = false;
|
|
614
|
-
for await (const event of runtime.send(turnInput, userInput, turnInput === text ? image : undefined)) {
|
|
733
|
+
for await (const event of runtime.send(turnInput, userInput, turnInput === text ? image : undefined, origin)) {
|
|
615
734
|
if (event.type === 'modelStreamUpdateEvent' &&
|
|
616
735
|
event.event.type === 'modelContentBlockDeltaEvent' &&
|
|
617
736
|
event.event.delta.type === 'textDelta' &&
|
|
@@ -674,10 +793,15 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
674
793
|
if (turnAborted.current && lifecycleOutcome === 'success')
|
|
675
794
|
lifecycleOutcome = 'cancelled';
|
|
676
795
|
runtime.observeTurnComplete(lifecycleOutcome, 'interactive');
|
|
677
|
-
// The attention bell
|
|
678
|
-
// one raw BEL
|
|
679
|
-
//
|
|
796
|
+
// The attention bell and the terminal notification share the TurnComplete
|
|
797
|
+
// publication moment exactly: one raw BEL and/or one OSC 9 sequence to stdout
|
|
798
|
+
// per finished turn (any outcome), interactive only, and no-ops unless
|
|
799
|
+
// `terminalBell` / `terminalNotify` are configured on.
|
|
680
800
|
ringTerminalBell(runtime.config.terminalBell === true);
|
|
801
|
+
notifyTerminal(runtime.config.terminalNotify === true, {
|
|
802
|
+
projectBasename: path.basename(runtime.info.projectRoot),
|
|
803
|
+
moment: 'turn-complete',
|
|
804
|
+
});
|
|
681
805
|
dispatch({ type: 'turnEnded' });
|
|
682
806
|
setStatus('idle');
|
|
683
807
|
// Cleared with the status, so a cancelled or failed turn stops the busy
|
|
@@ -755,6 +879,28 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
755
879
|
// that retain the draft: clearing there only loses undo history — the
|
|
756
880
|
// failure mode this guards against is resurrecting a sent prompt.
|
|
757
881
|
undoStack.current = [];
|
|
882
|
+
// A drained background-task wake (SER-069): one ordinary turn through the
|
|
883
|
+
// same `runTurn` a prompt uses — hooks, permission gate, trajectory barrier
|
|
884
|
+
// and `TurnComplete` all fire — but nothing above the model applies: no
|
|
885
|
+
// slash expansion, no `!`, no local command, and no held `!` reports, so the
|
|
886
|
+
// `taskNotification` record's text is exactly what the model received. The
|
|
887
|
+
// drain only calls this at idle; a busy session re-queues defensively.
|
|
888
|
+
// The wake's own turn is final: cancelled or failed, it is not re-sent
|
|
889
|
+
// (auto-resending into an error is how retry loops start — the SER-027 rule),
|
|
890
|
+
// and one notice says the job's output is still readable.
|
|
891
|
+
if (queuedEntry !== undefined && isTaskWake(queuedEntry)) {
|
|
892
|
+
if (status !== 'idle') {
|
|
893
|
+
setQueued([...queuedRef.current, queuedEntry]);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
const { kind: _kind, text: _text, image: _image, ...fields } = queuedEntry;
|
|
897
|
+
dispatch({ type: 'taskNotification', ...fields });
|
|
898
|
+
const completed = await runTurn(text, text, undefined, fields);
|
|
899
|
+
if (!completed) {
|
|
900
|
+
dispatch({ type: 'notice', text: formatTaskWakeUndelivered(fields), severity: 'warn' });
|
|
901
|
+
}
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
758
904
|
// A bounded pure projection of canonical commands and fixed input controls.
|
|
759
905
|
// It owns every whitespace-separated /help form before the busy guard, so an
|
|
760
906
|
// argument is rejected locally and a valid report remains available while a
|
|
@@ -797,7 +943,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
797
943
|
dispatch({ type: 'userInput', text });
|
|
798
944
|
dispatch({
|
|
799
945
|
type: 'notice',
|
|
800
|
-
text: formatUsageReport(runtime.usage, runtime.config, runtime.info.resumed, status === 'streaming', runtime.lastTurnUsage, runtime.childUsage, runtime.callStats, runtime.modelShares),
|
|
946
|
+
text: formatUsageReport(runtime.usage, runtime.config, runtime.info.resumed, status === 'streaming', runtime.lastTurnUsage, runtime.childUsage, runtime.callStats, runtime.modelShares, runtime.cacheMissReport()),
|
|
801
947
|
});
|
|
802
948
|
return;
|
|
803
949
|
}
|
|
@@ -916,7 +1062,9 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
916
1062
|
}
|
|
917
1063
|
// Free like /usage: the count is the SDK's character heuristic, so asking
|
|
918
1064
|
// costs nothing, sends nothing, and can be answered mid-turn — the moment
|
|
919
|
-
// a long turn makes "how big has this grown" worth asking.
|
|
1065
|
+
// a long turn makes "how big has this grown" worth asking. The breakdown
|
|
1066
|
+
// (SER-077) is asked for here and nowhere else: it counts one component at a
|
|
1067
|
+
// time, so the post-turn advisory and /status keep the single-count estimate.
|
|
920
1068
|
if (/^\/context(?:\s|$)/.test(text)) {
|
|
921
1069
|
setEditor({ text: '', cursor: { offset: 0, affinity: 'downstream' } });
|
|
922
1070
|
setSelectedCompletion(0);
|
|
@@ -926,7 +1074,15 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
926
1074
|
return;
|
|
927
1075
|
}
|
|
928
1076
|
try {
|
|
929
|
-
|
|
1077
|
+
const estimate = await runtime.contextEstimate();
|
|
1078
|
+
try {
|
|
1079
|
+
dispatch({ type: 'notice', text: formatContextReportWithBreakdown(estimate, await runtime.contextBreakdown()) });
|
|
1080
|
+
}
|
|
1081
|
+
catch (error) {
|
|
1082
|
+
// The total line is the report; a failed breakdown costs the rows, never the line.
|
|
1083
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1084
|
+
dispatch({ type: 'notice', text: `${formatContextReport(estimate)}\n breakdown unavailable — ${reason}` });
|
|
1085
|
+
}
|
|
930
1086
|
}
|
|
931
1087
|
catch (error) {
|
|
932
1088
|
dispatch({
|
|
@@ -1033,8 +1189,13 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1033
1189
|
thinking: runtime.thinking,
|
|
1034
1190
|
mode: runtime.permissionMode,
|
|
1035
1191
|
allowRuleCount: runtime.allowRuleCount,
|
|
1192
|
+
denyRuleCount: runtime.denyRuleCount,
|
|
1036
1193
|
mcpServers: runtime.listMcpServers(),
|
|
1037
1194
|
skillNames: runtime.info.skillNames,
|
|
1195
|
+
hookSources: runtime.info.hookSources,
|
|
1196
|
+
hookShadowNotices: runtime.info.hookShadowNotices,
|
|
1197
|
+
projectRoot: runtime.info.projectRoot,
|
|
1198
|
+
homeDir: os.homedir(),
|
|
1038
1199
|
trajectory: runtime.trajectoryStatus,
|
|
1039
1200
|
diagnostics: runtime.diagnosticsStatus,
|
|
1040
1201
|
usage: runtime.usage,
|
|
@@ -1042,6 +1203,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1042
1203
|
modelShares: runtime.modelShares,
|
|
1043
1204
|
childUsage: runtime.childUsage,
|
|
1044
1205
|
callStats: runtime.callStats,
|
|
1206
|
+
cacheMisses: runtime.cacheMissReport(),
|
|
1045
1207
|
turnInFlight: status === 'streaming',
|
|
1046
1208
|
context,
|
|
1047
1209
|
...(contextProblem !== undefined && { contextProblem }),
|
|
@@ -1194,6 +1356,14 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1194
1356
|
dispatch({ type: 'notice', text: '/clear is not available in this driver', severity: 'warn' });
|
|
1195
1357
|
return;
|
|
1196
1358
|
}
|
|
1359
|
+
// A tracked background delegation (SER-070) makes `/clear` a local refusal: a
|
|
1360
|
+
// successor would cancel the children unasked and orphan the report the SDK
|
|
1361
|
+
// still owes. The notice names the tasks and the two exits; nothing is released.
|
|
1362
|
+
const liveDelegations = runtime.listBackgroundDelegations();
|
|
1363
|
+
if (liveDelegations.length > 0) {
|
|
1364
|
+
dispatch({ type: 'notice', text: liveBackgroundDelegationRefusal('/clear', liveDelegations), severity: 'warn' });
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1197
1367
|
// The switch awaits an assembly (skills, tools, a new Agent), and `status` stays
|
|
1198
1368
|
// idle throughout — so without this latch a second enter could start a second
|
|
1199
1369
|
// successor and leak the first.
|
|
@@ -1236,7 +1406,9 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1236
1406
|
// successor starts empty, and the old session's record still has them.
|
|
1237
1407
|
pendingShellReports.current = [];
|
|
1238
1408
|
// The queue dies with the conversation it was typed at (SER-027): nothing
|
|
1239
|
-
// was sent, so nothing is recorded — the entries simply never existed.
|
|
1409
|
+
// was sent, so nothing is recorded — the entries simply never existed. A
|
|
1410
|
+
// pending background-task wake (SER-069) dies with it too: the job it
|
|
1411
|
+
// names belongs to the conversation just set aside.
|
|
1240
1412
|
setQueued([]);
|
|
1241
1413
|
clipboardReadGeneration.current += 1;
|
|
1242
1414
|
setAttachedImage(undefined);
|
|
@@ -1263,7 +1435,10 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1263
1435
|
}
|
|
1264
1436
|
setStatus('compacting');
|
|
1265
1437
|
try {
|
|
1266
|
-
|
|
1438
|
+
// The one TUI compaction site: a shrinking pass also appends the
|
|
1439
|
+
// `contextCompacted` trajectory record (SRF-027); no-shrink and failure
|
|
1440
|
+
// paths leave the record file untouched.
|
|
1441
|
+
const result = await compactAndRecord(runtime, focus);
|
|
1267
1442
|
dispatch({ type: 'notice', text: formatCompactReport(result) });
|
|
1268
1443
|
}
|
|
1269
1444
|
catch (error) {
|
|
@@ -1366,19 +1541,36 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1366
1541
|
// effect after an entry — a local command, say — that left every other dep
|
|
1367
1542
|
// unchanged. Never while a permission decision is pending (the queue is held
|
|
1368
1543
|
// untouched under a prompt) and never while `/clear` is assembling a successor.
|
|
1544
|
+
//
|
|
1545
|
+
// Background-task wakes (SER-069) are entries of this same queue, so they are a
|
|
1546
|
+
// dependency of this effect through `queued`, never a side effect of a render: a
|
|
1547
|
+
// wake enqueued while a permission prompt is open is held here and sent once the
|
|
1548
|
+
// prompt resolves and the turn ends. Suppression is decided here, at drain time,
|
|
1549
|
+
// because only now is it known whether the turn that was running when the job
|
|
1550
|
+
// finished *completed* after carrying its terminal state to the model through
|
|
1551
|
+
// `wait`/`status`; such a wake is dropped silently — the conversation already
|
|
1552
|
+
// holds the fact — and the next entry drains in its place.
|
|
1369
1553
|
useEffect(() => {
|
|
1370
1554
|
if (draining.current || status !== 'idle' || pendingPermission !== undefined || clearing.current)
|
|
1371
1555
|
return;
|
|
1372
|
-
|
|
1373
|
-
|
|
1556
|
+
// A delegation wake (SER-070) is dropped once the SDK no longer tracks its task:
|
|
1557
|
+
// an intervening turn already carried the result pair, so the report is known.
|
|
1558
|
+
const entries = queuedRef.current.filter((entry) => !(isTaskWake(entry) && (entry.source === 'delegation'
|
|
1559
|
+
? !runtime.listBackgroundDelegations().some((delegation) => delegation.taskId === entry.taskId)
|
|
1560
|
+
: runtime.terminalStateDelivered(entry.taskId))));
|
|
1561
|
+
const next = entries[0];
|
|
1562
|
+
if (next === undefined) {
|
|
1563
|
+
if (entries.length !== queuedRef.current.length)
|
|
1564
|
+
setQueued(entries);
|
|
1374
1565
|
return;
|
|
1566
|
+
}
|
|
1375
1567
|
draining.current = true;
|
|
1376
|
-
setQueued(
|
|
1568
|
+
setQueued(entries.slice(1));
|
|
1377
1569
|
void submit(next.text, next).finally(() => {
|
|
1378
1570
|
draining.current = false;
|
|
1379
1571
|
setDrainCycle((cycle) => cycle + 1);
|
|
1380
1572
|
});
|
|
1381
|
-
}, [drainCycle, pendingPermission, queued, setQueued, status, submit]);
|
|
1573
|
+
}, [drainCycle, pendingPermission, queued, runtime, setQueued, status, submit]);
|
|
1382
1574
|
/**
|
|
1383
1575
|
* Answers the pending confirmation and, when the user picked an "always allow"
|
|
1384
1576
|
* option, remembers the rule.
|
|
@@ -1479,7 +1671,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
1479
1671
|
* takes the whole queue back — entries one per line, ahead of any typed text.
|
|
1480
1672
|
*/
|
|
1481
1673
|
const takeBackQueued = useCallback(() => {
|
|
1482
|
-
if (queuedRef.current.length === 0 || recallRef.current !== undefined)
|
|
1674
|
+
if (partitionQueue(queuedRef.current).user.length === 0 || recallRef.current !== undefined)
|
|
1483
1675
|
return false;
|
|
1484
1676
|
const value = editorRef.current;
|
|
1485
1677
|
const shape = layoutEditor(value.text, columns, value.cursor);
|
|
@@ -2077,17 +2269,18 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
|
|
|
2077
2269
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { ref: headerRef, flexDirection: "column", children: _jsx(Header, { runtime: runtime, status: effectiveStatus, frame: frame }) }), _jsx(MessageList, { history: state.history, ...(state.staticEpoch === 0 ? { welcome: initialWelcome } : {}), liveText: state.liveText, liveCodeOpen: fenceOpenAfter(state.committedAnswer), columns: columns, maxLiveRows: grants.live, staticEpoch: state.staticEpoch }), _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 }), pendingPermission !== undefined ? (_jsx(PermissionPrompt, { request: pendingPermission, waiting: permissions.waiting, columns: columns, maxRows: grants.prompt })) : (_jsx(InputBox, { layout: layout, completions: completions, completionKind: completionKind, completionNote: completionNote, 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 }))] })] }));
|
|
2078
2270
|
}
|
|
2079
2271
|
/** The hint row under the draft, or nothing when the session is idle. */
|
|
2080
|
-
function hintForStatus(status, busyReadout, queuedCount = 0) {
|
|
2272
|
+
function hintForStatus(status, busyReadout, queuedCount = 0, queuedWakeCount = 0) {
|
|
2081
2273
|
if (status === 'streaming') {
|
|
2082
2274
|
// The live readout rides directly behind `working…`, ahead of the static command
|
|
2083
2275
|
// hints: the row is one truncated <Text>, so on a narrow terminal the tail is what
|
|
2084
2276
|
// goes missing, and the tail should be the part that never changes. The queue
|
|
2085
|
-
// count (SER-027) rides with it: even a listing cut to nothing stays counted here
|
|
2086
|
-
|
|
2277
|
+
// count (SER-027) rides with it: even a listing cut to nothing stays counted here,
|
|
2278
|
+
// typed entries and background-task wakes (SER-069) each under their own word.
|
|
2279
|
+
return `working…${busyReadout ?? ''}${queuedCountHint(queuedCount, queuedWakeCount)} /tasks lists jobs · /agents lists dispatches · /usage reports tokens · ctrl+c cancels this turn`;
|
|
2087
2280
|
}
|
|
2088
2281
|
// Elapsed lives on the command's own panel row, so this row can stay static.
|
|
2089
2282
|
if (status === 'shell')
|
|
2090
|
-
return `running ! command…${queuedCountHint(queuedCount)} ctrl+c cancels it`;
|
|
2283
|
+
return `running ! command…${queuedCountHint(queuedCount, queuedWakeCount)} ctrl+c cancels it`;
|
|
2091
2284
|
return status === 'compacting' ? 'compacting conversation…' : undefined;
|
|
2092
2285
|
}
|
|
2093
2286
|
/**
|
|
@@ -2129,7 +2322,7 @@ export function Header({ runtime, status = 'idle', frame = 0, }) {
|
|
|
2129
2322
|
// naming the startup policy would be worse than no header — this row is the only
|
|
2130
2323
|
// place the effective mode is stated, and it must not gain a second one.
|
|
2131
2324
|
const mode = runtime.permissionMode;
|
|
2132
|
-
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { 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)] })] }), _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' ? (
|
|
2325
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsxs(Text, { 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)] })] }), _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 &&
|
|
2133
2326
|
(instructions.truncated ? (_jsxs(Text, { color: visualColor.warning, children: [AGENTS_FILENAME, ": loaded (", formatBytes(instructions.bytes), ", truncated to", ' ', MAX_INSTRUCTIONS_BYTES / 1024, " KB)"] })) : (_jsxs(Text, { dimColor: true, children: [AGENTS_FILENAME, ": loaded (", formatBytes(instructions.bytes), ")"] }))), info.projectInstructionsProblem !== undefined && (_jsxs(Text, { color: visualColor.warning, children: [AGENTS_FILENAME, ": skipped \u2014 ", 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: "/ for actions \u00B7 @ for paths \u00B7 ctrl+c cancels \u00B7 /exit quits" })] }));
|
|
2134
2327
|
}
|
|
2135
2328
|
const WORKING_LABEL = 'working';
|
|
@@ -2180,13 +2373,22 @@ function formatBytes(bytes) {
|
|
|
2180
2373
|
* working), and that comparison is what a column makes readable. An unavailable
|
|
2181
2374
|
* provider metric remains text rather than masquerading as numeric zero.
|
|
2182
2375
|
*/
|
|
2183
|
-
export function formatUsageReport(usage, config, resumed, turnInFlight = false, lastTurn, children, callStats, modelShares) {
|
|
2376
|
+
export function formatUsageReport(usage, config, resumed, turnInFlight = false, lastTurn, children, callStats, modelShares, cacheMisses) {
|
|
2184
2377
|
const rows = usageRows(usage, config);
|
|
2185
2378
|
const derived = cacheEffectivenessRows(usage, config);
|
|
2186
|
-
|
|
2379
|
+
// The miss count is a fact only once a miss was observed (SER-074): a session
|
|
2380
|
+
// without one renders byte-identically to before the tracker existed — the
|
|
2381
|
+
// additive convention every optional section here follows. `misses: 0` is that
|
|
2382
|
+
// absence, not a measured zero, because the tracker is silent when the cache
|
|
2383
|
+
// counters are unreported or caching is off.
|
|
2384
|
+
const missRows = cacheMisses !== undefined && cacheMisses.misses > 0
|
|
2385
|
+
? [{ label: 'cache misses', rendered: cacheMisses.misses.toLocaleString('en-US') }]
|
|
2386
|
+
: [];
|
|
2387
|
+
const labelWidth = Math.max(...rows.map(({ label }) => label.length), ...derived.map(({ label }) => label.length), ...missRows.map(({ label }) => label.length));
|
|
2187
2388
|
const lines = [
|
|
2188
2389
|
...rows.map(({ label, value }) => ({ label, rendered: formatUsageValue(value) })),
|
|
2189
2390
|
...derived.map(({ label, value }) => ({ label, rendered: value ?? 'not reported' })),
|
|
2391
|
+
...missRows,
|
|
2190
2392
|
].map(({ label, rendered }) => ` ${label.padEnd(labelWidth)} ${rendered.padStart(12)}`);
|
|
2191
2393
|
// The cost line closes the block — the same per-model projection `/status`
|
|
2192
2394
|
// prints, each model's share at its own rates, so the two cannot disagree.
|
|
@@ -2214,7 +2416,9 @@ export function formatUsageReport(usage, config, resumed, turnInFlight = false,
|
|
|
2214
2416
|
// Last-turn section: only when a turn has completed. Mid-turn, lastTurn is the
|
|
2215
2417
|
// previous completed turn, labelled clearly so it is not mistaken for the
|
|
2216
2418
|
// in-flight one.
|
|
2217
|
-
const lastTurnSection = lastTurn === undefined
|
|
2419
|
+
const lastTurnSection = lastTurn === undefined
|
|
2420
|
+
? []
|
|
2421
|
+
: formatLastTurnSection(lastTurn, config, labelWidth, cacheMisses?.lastMiss?.cause);
|
|
2218
2422
|
// Child sections: only when a dispatch reported spend (`runtime.childUsage`),
|
|
2219
2423
|
// so a session that never delegated renders byte-identical to before children
|
|
2220
2424
|
// were counted at all. The session total repeats the parent's projection rules
|
|
@@ -2267,9 +2471,11 @@ function usageSection(heading, usage, config, labelWidth) {
|
|
|
2267
2471
|
}
|
|
2268
2472
|
/**
|
|
2269
2473
|
* One-section "last turn (previous turn)" block, reusing the same label
|
|
2270
|
-
* width as the parent table for visual alignment.
|
|
2474
|
+
* width as the parent table for visual alignment. With a `lastMiss` (SER-074, only
|
|
2475
|
+
* once a miss was observed this session) one text row names its likely cause; the
|
|
2476
|
+
* value is left as text rather than right-aligned like a count.
|
|
2271
2477
|
*/
|
|
2272
|
-
function formatLastTurnSection(lastTurn, config, labelWidth) {
|
|
2478
|
+
function formatLastTurnSection(lastTurn, config, labelWidth, lastMiss) {
|
|
2273
2479
|
const lastRows = usageRows(lastTurn, config);
|
|
2274
2480
|
const lastDerived = cacheEffectivenessRows(lastTurn, config);
|
|
2275
2481
|
const allLastWidth = Math.max(labelWidth, ...lastRows.map(({ label }) => label.length), ...lastDerived.map(({ label }) => label.length));
|
|
@@ -2277,6 +2483,9 @@ function formatLastTurnSection(lastTurn, config, labelWidth) {
|
|
|
2277
2483
|
...lastRows.map(({ label, value }) => ({ label, rendered: formatUsageValue(value) })),
|
|
2278
2484
|
...lastDerived.map(({ label, value }) => ({ label, rendered: value ?? 'not reported' })),
|
|
2279
2485
|
].map(({ label, rendered }) => ` ${label.padEnd(allLastWidth)} ${rendered.padStart(12)}`);
|
|
2486
|
+
if (lastMiss !== undefined) {
|
|
2487
|
+
lastLines.push(` ${'last miss'.padEnd(allLastWidth)} ${describeCacheMissCause(lastMiss, config.promptCacheTtl)}`);
|
|
2488
|
+
}
|
|
2280
2489
|
return ['last turn (previous turn)', ...lastLines];
|
|
2281
2490
|
}
|
|
2282
2491
|
/**
|
|
@@ -2376,7 +2585,17 @@ function applyEffortCommand(runtime, text, dispatch) {
|
|
|
2376
2585
|
});
|
|
2377
2586
|
return;
|
|
2378
2587
|
}
|
|
2379
|
-
|
|
2588
|
+
// Read before the switch so the age is the cache's, not the switch's; dispatched
|
|
2589
|
+
// only when the level actually sent changes, because a clamped or repeated level
|
|
2590
|
+
// leaves the request — and the cache — exactly as it was (SER-074). The switch
|
|
2591
|
+
// is synchronous, so the notice still precedes every line the change earns.
|
|
2592
|
+
const warmth = runtime.cacheWarmth(Date.now());
|
|
2593
|
+
const { plan, saved, effectiveChanged } = runtime.changeThinkingEffort(argument);
|
|
2594
|
+
if (effectiveChanged) {
|
|
2595
|
+
const warmNotice = warmCacheSwitchNotice('effort', warmth);
|
|
2596
|
+
if (warmNotice !== undefined)
|
|
2597
|
+
dispatch({ type: 'notice', text: warmNotice });
|
|
2598
|
+
}
|
|
2380
2599
|
const applied = `thinking effort: ${describeThinking(plan)}`;
|
|
2381
2600
|
saved.then(() => {
|
|
2382
2601
|
dispatch({ type: 'notice', text: `${applied} — saved to ~/${DARWIN_DIRNAME}/${CONFIG_FILENAME}` });
|
|
@@ -2443,23 +2662,33 @@ function applyModeCommand(runtime, text, dispatch) {
|
|
|
2443
2662
|
});
|
|
2444
2663
|
}
|
|
2445
2664
|
/**
|
|
2446
|
-
* The `/permissions` listing: every live allow-rule, numbered, with its origin
|
|
2665
|
+
* The `/permissions` listing: every live allow-rule, numbered, with its origin,
|
|
2666
|
+
* then every configured deny-rule (SER-076), labelled as deny and unnumbered.
|
|
2447
2667
|
*
|
|
2448
2668
|
* Origin is stated per rule because the two kinds answer different questions —
|
|
2449
2669
|
* a `configured` rule was a deliberate entry in the project's permission-rules
|
|
2450
2670
|
* file, a `granted this session` rule is minutes old and the more likely
|
|
2451
|
-
* revocation target.
|
|
2671
|
+
* revocation target. Deny-rules carry no number on purpose: the numbers are
|
|
2672
|
+
* `revoke` targets, and a deny is never one. Exported for the free spike, like
|
|
2673
|
+
* `formatUsageReport`.
|
|
2452
2674
|
*/
|
|
2453
|
-
export function formatPermissionRulesReport(entries, rulesFile) {
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2675
|
+
export function formatPermissionRulesReport(entries, rulesFile, denyRules) {
|
|
2676
|
+
const allowSection = entries.length === 0
|
|
2677
|
+
? [
|
|
2678
|
+
'no allow-rules in effect — every non-safe call asks',
|
|
2679
|
+
` rules come from the permission prompt\u2019s "always allow" options, or from ${rulesFile}`,
|
|
2680
|
+
]
|
|
2681
|
+
: [
|
|
2682
|
+
`allow-rules in effect (${entries.length}) — configured rules load from ${rulesFile}`,
|
|
2683
|
+
...entries.map((entry, index) => ` ${index + 1}. ${entry.rule} — ${entry.origin === 'configured' ? 'configured' : 'granted this session'}`),
|
|
2684
|
+
' /permissions revoke <n|rule|all> revokes; new rules come only from the permission prompt',
|
|
2685
|
+
];
|
|
2686
|
+
if (denyRules.length === 0)
|
|
2687
|
+
return allowSection.join('\n');
|
|
2459
2688
|
return [
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2689
|
+
...allowSection,
|
|
2690
|
+
`deny-rules in effect (${denyRules.length}) — hold in every mode, for every agent; edit ${rulesFile} to change them`,
|
|
2691
|
+
...denyRules.map((rule) => ` - ${rule} — deny (configured)`),
|
|
2463
2692
|
].join('\n');
|
|
2464
2693
|
}
|
|
2465
2694
|
/**
|
|
@@ -2477,11 +2706,11 @@ export function formatPermissionRulesReport(entries, rulesFile) {
|
|
|
2477
2706
|
*/
|
|
2478
2707
|
export function applyPermissionsCommand(runtime, text, dispatch) {
|
|
2479
2708
|
const argument = text.slice('/permissions'.length).trim();
|
|
2480
|
-
const usage = 'usage: /permissions — list allow-rules · /permissions revoke <n|rule|all>';
|
|
2709
|
+
const usage = 'usage: /permissions — list allow- and deny-rules · /permissions revoke <n|rule|all> (allow-rules only)';
|
|
2481
2710
|
if (argument === '') {
|
|
2482
2711
|
dispatch({
|
|
2483
2712
|
type: 'notice',
|
|
2484
|
-
text: formatPermissionRulesReport(runtime.listAllowRules(), runtime.info.permissionRulesPath),
|
|
2713
|
+
text: formatPermissionRulesReport(runtime.listAllowRules(), runtime.info.permissionRulesPath, runtime.listDenyRules()),
|
|
2485
2714
|
});
|
|
2486
2715
|
return;
|
|
2487
2716
|
}
|
|
@@ -2508,6 +2737,17 @@ export function applyPermissionsCommand(runtime, text, dispatch) {
|
|
|
2508
2737
|
}
|
|
2509
2738
|
}
|
|
2510
2739
|
else {
|
|
2740
|
+
// A deny-rule (SER-076) is refused by name before the allow lookup: revoking
|
|
2741
|
+
// it would *widen* what runs, which this command can never do. The file is
|
|
2742
|
+
// the only way a deny changes, and the notice says so.
|
|
2743
|
+
if (runtime.listDenyRules().includes(target)) {
|
|
2744
|
+
dispatch({
|
|
2745
|
+
type: 'notice',
|
|
2746
|
+
text: `${target} is a deny-rule — /permissions never revokes deny-rules, because that would widen what runs\n` +
|
|
2747
|
+
` edit ${runtime.info.permissionRulesPath} and start a new session to change it`,
|
|
2748
|
+
});
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2511
2751
|
// An index from the listing, or the exact rule string. Index wins for a
|
|
2512
2752
|
// purely numeric target: rules carry a tool name, so none is all digits.
|
|
2513
2753
|
const index = /^\d+$/.test(target) ? Number(target) : undefined;
|
|
@@ -2522,9 +2762,10 @@ export function applyPermissionsCommand(runtime, text, dispatch) {
|
|
|
2522
2762
|
targets = [chosen.rule];
|
|
2523
2763
|
}
|
|
2524
2764
|
const { removed, saved } = runtime.revokeAllowRules(targets);
|
|
2765
|
+
const denyRulesStay = runtime.denyRuleCount === 0 ? '' : ' — deny-rules stay in force';
|
|
2525
2766
|
const headline = removed.length === 1
|
|
2526
|
-
? `revoked ${removed[0]} — the next matching call will ask again`
|
|
2527
|
-
: `revoked ${removed.length} allow-rules — the next matching calls will ask again`;
|
|
2767
|
+
? `revoked ${removed[0]} — the next matching call will ask again${denyRulesStay}`
|
|
2768
|
+
: `revoked ${removed.length} allow-rules — the next matching calls will ask again${denyRulesStay}`;
|
|
2528
2769
|
saved.then(() => {
|
|
2529
2770
|
dispatch({ type: 'notice', text: `${headline}\n removed from ${runtime.info.permissionRulesPath}` });
|
|
2530
2771
|
}, (error) => {
|
|
@@ -2583,6 +2824,12 @@ async function applyModelCommand(runtime, text, dispatch) {
|
|
|
2583
2824
|
dispatch({ type: 'notice', text: `already on ${target.name}\n${formatModelList(choices)}` });
|
|
2584
2825
|
return;
|
|
2585
2826
|
}
|
|
2827
|
+
// States the cost of leaving a warm cache and proceeds — a notice, never a
|
|
2828
|
+
// confirmation (SER-074). Before the switch, so it precedes the model line and
|
|
2829
|
+
// reads the cache's age rather than the switch's.
|
|
2830
|
+
const warmNotice = warmCacheSwitchNotice('model', runtime.cacheWarmth(Date.now()));
|
|
2831
|
+
if (warmNotice !== undefined)
|
|
2832
|
+
dispatch({ type: 'notice', text: warmNotice });
|
|
2586
2833
|
let result;
|
|
2587
2834
|
try {
|
|
2588
2835
|
result = await runtime.changeModel(target);
|