strands-darwin 0.0.34 → 0.0.35

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.
Files changed (88) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/dist/patches/@strands-agents+sdk+1.16.0.patch +29 -15
  4. package/dist/patches/ink+7.1.1.patch +58 -0
  5. package/dist/src/agent/background-delegation.d.ts +3 -3
  6. package/dist/src/agent/background-delegation.js +2 -2
  7. package/dist/src/agent/background-delegation.js.map +1 -1
  8. package/dist/src/agent/context-breakdown.d.ts +2 -1
  9. package/dist/src/agent/context-breakdown.js +2 -1
  10. package/dist/src/agent/context-breakdown.js.map +1 -1
  11. package/dist/src/agent/instructions.d.ts +22 -3
  12. package/dist/src/agent/instructions.js +67 -34
  13. package/dist/src/agent/instructions.js.map +1 -1
  14. package/dist/src/agent/refusal.d.ts +44 -7
  15. package/dist/src/agent/refusal.js +54 -8
  16. package/dist/src/agent/refusal.js.map +1 -1
  17. package/dist/src/agent/runtime.d.ts +25 -6
  18. package/dist/src/agent/runtime.js +65 -17
  19. package/dist/src/agent/runtime.js.map +1 -1
  20. package/dist/src/agent/stream-resumption.d.ts +5 -2
  21. package/dist/src/agent/stream-resumption.js +5 -2
  22. package/dist/src/agent/stream-resumption.js.map +1 -1
  23. package/dist/src/agent/system-prompt.d.ts +1 -1
  24. package/dist/src/agent/system-prompt.js +4 -1
  25. package/dist/src/agent/system-prompt.js.map +1 -1
  26. package/dist/src/agent/thinking.js +4 -2
  27. package/dist/src/agent/thinking.js.map +1 -1
  28. package/dist/src/agents/subagent-tool.js +4 -3
  29. package/dist/src/agents/subagent-tool.js.map +1 -1
  30. package/dist/src/agents/workflow-tool.js +2 -2
  31. package/dist/src/agents/workflow-tool.js.map +1 -1
  32. package/dist/src/cli-doctor.js +7 -5
  33. package/dist/src/cli-doctor.js.map +1 -1
  34. package/dist/src/commands/custom-commands.d.ts +1 -1
  35. package/dist/src/commands/custom-commands.js +7 -1
  36. package/dist/src/commands/custom-commands.js.map +1 -1
  37. package/dist/src/commands/init-command.d.ts +47 -0
  38. package/dist/src/commands/init-command.js +110 -0
  39. package/dist/src/commands/init-command.js.map +1 -0
  40. package/dist/src/config.d.ts +35 -3
  41. package/dist/src/config.js +127 -4
  42. package/dist/src/config.js.map +1 -1
  43. package/dist/src/dev-repl.js +17 -2
  44. package/dist/src/dev-repl.js.map +1 -1
  45. package/dist/src/headless-protocol.js +6 -5
  46. package/dist/src/headless-protocol.js.map +1 -1
  47. package/dist/src/headless-runner.js +5 -1
  48. package/dist/src/headless-runner.js.map +1 -1
  49. package/dist/src/headless.d.ts +11 -0
  50. package/dist/src/headless.js +33 -7
  51. package/dist/src/headless.js.map +1 -1
  52. package/dist/src/pricing/model-prices.d.ts +3 -1
  53. package/dist/src/pricing/model-prices.js +7 -1
  54. package/dist/src/pricing/model-prices.js.map +1 -1
  55. package/dist/src/tools/background-bash.d.ts +15 -3
  56. package/dist/src/tools/background-bash.js +18 -8
  57. package/dist/src/tools/background-bash.js.map +1 -1
  58. package/dist/src/tools/file-editor-serial.d.ts +14 -0
  59. package/dist/src/tools/file-editor-serial.js +15 -0
  60. package/dist/src/tools/file-editor-serial.js.map +1 -1
  61. package/dist/src/tools/shell-env.d.ts +77 -0
  62. package/dist/src/tools/shell-env.js +139 -0
  63. package/dist/src/tools/shell-env.js.map +1 -0
  64. package/dist/src/trajectory/replay.js +23 -0
  65. package/dist/src/trajectory/replay.js.map +1 -1
  66. package/dist/src/trajectory/writer.d.ts +44 -3
  67. package/dist/src/trajectory/writer.js +80 -14
  68. package/dist/src/trajectory/writer.js.map +1 -1
  69. package/dist/src/tui/App.d.ts +4 -1
  70. package/dist/src/tui/App.js +181 -36
  71. package/dist/src/tui/App.js.map +1 -1
  72. package/dist/src/tui/InputBox.d.ts +1 -1
  73. package/dist/src/tui/InputBox.js +1 -1
  74. package/dist/src/tui/instructions-format.d.ts +14 -0
  75. package/dist/src/tui/instructions-format.js +24 -0
  76. package/dist/src/tui/instructions-format.js.map +1 -0
  77. package/dist/src/tui/prompt-queue.js +4 -2
  78. package/dist/src/tui/prompt-queue.js.map +1 -1
  79. package/dist/src/tui/status-format.d.ts +15 -0
  80. package/dist/src/tui/status-format.js +25 -0
  81. package/dist/src/tui/status-format.js.map +1 -1
  82. package/dist/src/tui/tangent.d.ts +122 -0
  83. package/dist/src/tui/tangent.js +153 -0
  84. package/dist/src/tui/tangent.js.map +1 -0
  85. package/dist/src/tui/turn-state.d.ts +12 -1
  86. package/dist/src/tui/turn-state.js +11 -0
  87. package/dist/src/tui/turn-state.js.map +1 -1
  88. package/package.json +3 -3
@@ -16,7 +16,7 @@ import os from 'node:os';
16
16
  import path from 'node:path';
17
17
  import { Box, Text, useApp, useBoxMetrics, useInput, usePaste, useStdout, useWindowSize } from 'ink';
18
18
  import React, { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore } from 'react';
19
- import { AGENTS_FILENAME, MAX_INSTRUCTIONS_BYTES } from '../agent/instructions.js';
19
+ import { AGENTS_FILENAME } from '../agent/instructions.js';
20
20
  import { APPROVAL_MODES, describeApprovalMode, isApprovalMode, } from '../agent/permission.js';
21
21
  import { compactAndRecord, compactFocusRefusal, normalizeCompactFocus } from '../agent/compact.js';
22
22
  import { formatUsageValue, sumUsage, usageBuckets, usageRows, cacheEffectivenessRows } from '../agent/usage.js';
@@ -25,7 +25,7 @@ import { averageRequestInputTokens } from '../agent/call-stats.js';
25
25
  import { describeCacheMissCause, warmCacheSwitchNotice } from '../agent/cache-miss.js';
26
26
  import { runWithStreamResumption, STREAM_CONTINUATION_NOTICE } from '../agent/stream-resumption.js';
27
27
  import { retryFailureNotice } from '../agent/model-retry.js';
28
- import { isRefusalStop, REFUSAL_NOTICE } from '../agent/refusal.js';
28
+ import { isRefusalStop, refusalNoticeWithRewind } from '../agent/refusal.js';
29
29
  import { contextOverflowErrorMessage } from '../context-overflow-error.js';
30
30
  import { routeSdkLogs } from '../agent/sdk-logging.js';
31
31
  import { SYSTEM_PROMPT_FILENAME } from '../agent/system-prompt.js';
@@ -36,10 +36,12 @@ import { WORKFLOW_COMMAND_USAGE, parseWorkflowCommand } from '../commands/workfl
36
36
  import { MCP_CONFIG_FILENAME, mcpConfigCandidates } from '../mcp/registry.js';
37
37
  import { DARWIN_DIRNAME } from '../paths.js';
38
38
  import { readBackgroundTail, readBackgroundTails } from '../tools/background-tail.js';
39
+ import { formatShellEnvNotice } from '../tools/shell-env.js';
39
40
  import { exportTranscript } from '../trajectory/export.js';
40
41
  import { readPromptHistory, } from '../trajectory/prompt-history.js';
41
42
  import { InputBox, MAX_COMPLETIONS, completionSelection, moveCompletionSelection, } from './InputBox.js';
42
43
  import { busySuffix } from './busy-suffix.js';
44
+ import { formatInstructionsLoadedRow, formatInstructionsProblemRow } from './instructions-format.js';
43
45
  import { LIVE_BLOCK_CHROME_ROWS, wrapToRows } from './live-text.js';
44
46
  import { fenceOpenAfter } from './markdown.js';
45
47
  import { PERMISSION_BOX_FIXED_ROWS, frameBudget, promptBoxWanted, queueListWanted, toolDetailsVisible, toolInputRows, toolPanelWanted, } from './frame-budget.js';
@@ -54,6 +56,7 @@ import { promptCompletionState, visiblePromptCompletions, } from './prompt-compl
54
56
  import { openPromptRecall, promptRecallIndicator, stepPromptRecall, } from './prompt-recall.js';
55
57
  import { acceptPromptHistorySearch, appendPromptHistorySearchQuery, backspacePromptHistorySearchQuery, cancelPromptHistorySearch, clearPromptHistorySearchQuery, movePromptHistorySearchSelection, openPromptHistorySearch, promptHistorySearchView, resolvePromptHistorySearch, } from './prompt-history-search.js';
56
58
  import { ESCAPE_REWIND_CHORD_MS, acceptRewindSearch, appendRewindSearchQuery, backspaceRewindSearchQuery, cancelRewindSearch, clearRewindSearchQuery, moveRewindSearchSelection, openRewindSearch, rewindSearchView, } from './rewind-search.js';
59
+ import { TANGENT_COMMAND_USAGE, armTangent, captureReturnPoint, discardedPromptCount, parseTangentCommand, rewindDraftAfterBranch, tangentCommandOutcome, tangentEndedByNotice, tangentHeaderSuffix, tangentReturnNotice, tangentStatusFact, } from './tangent.js';
57
60
  import { clipboardImageFact, readClipboardImage } from './clipboard-image.js';
58
61
  import { delegationWakeEntries, hasQueuedImage, isTaskWake, partitionQueue, queuedCountHint, refusesToQueue, takeBackDraft, } from './prompt-queue.js';
59
62
  import { composeShellReport, parseShellCommand, projectShellOutput, runShellCommand, } from './shell-command.js';
@@ -384,6 +387,16 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
384
387
  rewindSearchRef.current = next;
385
388
  setRewindSearchState(next);
386
389
  }, []);
390
+ // `/tangent` (SER-083): live TUI session state like the permission mode — never
391
+ // persisted or recorded, dropped by `/clear`, absent in a resumed session. In
392
+ // state for the header/status projections and mirrored in a ref for the
393
+ // callbacks that read it after an await.
394
+ const [tangent, setTangentState] = useState(undefined);
395
+ const tangentRef = useRef(tangent);
396
+ const setTangent = useCallback((next) => {
397
+ tangentRef.current = next;
398
+ setTangentState(next);
399
+ }, []);
387
400
  const updateRewindSearch = useCallback((update) => {
388
401
  const current = rewindSearchRef.current;
389
402
  if (current !== undefined)
@@ -436,6 +449,34 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
436
449
  setRewindSearch(openRewindSearch(opening, runtime.info.sessionId, catalogue.checkpoints));
437
450
  return true;
438
451
  }, [dispatch, runtime, setEditor, setHistorySearch, setRecall, setRewindSearch, startRewind]);
452
+ // The one way a rewind successor takes over the screen — `/rewind` acceptance and
453
+ // a `/tangent` return (SER-083) both land here, so the terminal clear, the editor
454
+ // hand-back rule, the per-session latches and the omission notice cannot drift.
455
+ // The only difference between the two is the draft: `rewindDraftAfterBranch`.
456
+ const adoptBranchSuccessor = useCallback((next, kind, selectedPrompt, sourceSessionId) => {
457
+ writeToTerminal(CLEAR_TERMINAL);
458
+ recordAction({ type: 'clear' });
459
+ setRuntime(next);
460
+ setRewindSearch(undefined);
461
+ // The restored session replaces the whole editor state; the selected prompt
462
+ // returns unsent (a tangent return hands back nothing — the user asked to
463
+ // return, not to resend), and undo must not reach across the session boundary.
464
+ undoStack.current = [];
465
+ const draft = rewindDraftAfterBranch(kind, selectedPrompt);
466
+ setEditor({ text: draft, cursor: { offset: draft.length, affinity: 'upstream' } });
467
+ setSelectedCompletion(0);
468
+ contextWarnLatch.current = createContextWarnLatch();
469
+ trajectoryWarned.current = false;
470
+ diagnosticsWarned.current = false;
471
+ pendingShellReports.current = [];
472
+ setQueued([]);
473
+ withNoticeDiagnostics(recordAction, next.diagnostics)({
474
+ type: 'notice',
475
+ severity: 'warn',
476
+ text: `rewound conversation into new session ${next.info.sessionId}; source ${sourceSessionId} remains saved and resumable. ` +
477
+ 'Workspace unchanged: workspace files, shell and ! effects, hooks, MCP writes, subagents, background jobs, and learned-memory files were not rewound.',
478
+ });
479
+ }, [recordAction, setEditor, setQueued, setRewindSearch, setSelectedCompletion, writeToTerminal]);
439
480
  // When the first no-op Escape landed on an empty idle composer; a second one
440
481
  // within ESCAPE_REWIND_CHORD_MS opens the chooser. Cleared by any other key or
441
482
  // owner, so the chord can never straddle a draft, a turn or a menu.
@@ -608,6 +649,16 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
608
649
  return;
609
650
  dispatch({ type: 'notice', text: `diagnostics: recording SDK debug/info to ${file}` });
610
651
  }, [dispatch, runtime]);
652
+ // SER-082: what model-spawned shells did not inherit, said once in the transcript
653
+ // on the same terms as the diagnostics line above — a frame row is not an option,
654
+ // and a clean environment adds no line. Names only, a few of them; `/status` has
655
+ // the bounded full list. Per runtime, so a `/clear` successor states it again.
656
+ useEffect(() => {
657
+ const notice = formatShellEnvNotice(runtime.info.shellEnv.withheld);
658
+ if (notice === undefined)
659
+ return;
660
+ dispatch({ type: 'notice', text: `shell env: ${notice} — see /status` });
661
+ }, [dispatch, runtime]);
611
662
  // Terminal task events are transcript-only observers: they never alter turn
612
663
  // status, active tools, permissions, or the agent loop. React dispatch also
613
664
  // causes an immediate idle render; cleanup prevents shutdown notices after exit.
@@ -757,9 +808,12 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
757
808
  answerTailLive = false;
758
809
  }
759
810
  // The SDK ends a refused turn normally, so the transcript would show an
760
- // empty (or cut-short) answer with no reason. Name it once, as a notice.
811
+ // empty (or cut-short) answer with no reason. Name it once, as a notice,
812
+ // with the stop reason actually received (SRF-029) and the remedy only
813
+ // this driver has: the runtime catalogued the prompt, so `/rewind` to it
814
+ // removes the declined exchange (SRF-030).
761
815
  if (event.type === 'agentResultEvent' && isRefusalStop(event.result.stopReason)) {
762
- dispatch({ type: 'notice', text: REFUSAL_NOTICE, severity: 'warn' });
816
+ dispatch({ type: 'notice', text: refusalNoticeWithRewind(event.result.stopReason), severity: 'warn' });
763
817
  }
764
818
  }
765
819
  }, (error) => {
@@ -822,6 +876,24 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
822
876
  turnAborted.current = false;
823
877
  returnQueuedToEditor(true);
824
878
  }
879
+ // An armed `/tangent` (SER-083) resolves on the first prompt after it: the
880
+ // checkpoint `send()` captured before this prompt is the return point, read
881
+ // back from the catalogue the runtime already keeps — no snapshot of our own,
882
+ // no second listing shape. No growth means the tangent ends here, saying why.
883
+ const armed = tangentRef.current;
884
+ if (armed?.phase === 'armed') {
885
+ const facts = { image: image !== undefined, sessionOriginated: origin !== undefined, completed: !failed };
886
+ let catalogue;
887
+ try {
888
+ catalogue = await runtime.listRewindCheckpoints();
889
+ }
890
+ catch (error) {
891
+ catalogue = { checkpoints: [], capped: false, problem: error instanceof Error ? error.message : String(error) };
892
+ }
893
+ const outcome = captureReturnPoint(armed, catalogue, facts);
894
+ setTangent(outcome.kind === 'started' ? outcome.state : undefined);
895
+ dispatch({ type: 'notice', text: outcome.notice, ...(outcome.kind === 'ended' && { severity: 'warn' }) });
896
+ }
825
897
  // Post-turn context-pressure check: reuse the configurable warning latch
826
898
  // and existing Static transcript notice — no second threshold or live row.
827
899
  // Compaction remains an explicit user command. A failed estimate is silently
@@ -866,7 +938,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
866
938
  dispatch({ type: 'notice', text: `hook: ${problem}`, severity: 'warn' });
867
939
  }
868
940
  return !failed;
869
- }, [prepareAnswerClose, returnQueuedToEditor, runtime, waitUntilRenderFlush]);
941
+ }, [prepareAnswerClose, returnQueuedToEditor, runtime, setTangent, waitUntilRenderFlush]);
870
942
  const submit = useCallback(async (raw, queuedEntry) => {
871
943
  const text = raw.trim();
872
944
  // A drained entry owns its optional image, including explicit absence. It
@@ -1190,10 +1262,12 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
1190
1262
  mode: runtime.permissionMode,
1191
1263
  allowRuleCount: runtime.allowRuleCount,
1192
1264
  denyRuleCount: runtime.denyRuleCount,
1265
+ tangent: tangentStatusFact(tangentRef.current),
1193
1266
  mcpServers: runtime.listMcpServers(),
1194
1267
  skillNames: runtime.info.skillNames,
1195
1268
  hookSources: runtime.info.hookSources,
1196
1269
  hookShadowNotices: runtime.info.hookShadowNotices,
1270
+ shellEnv: runtime.info.shellEnv,
1197
1271
  projectRoot: runtime.info.projectRoot,
1198
1272
  homeDir: os.homedir(),
1199
1273
  trajectory: runtime.trajectoryStatus,
@@ -1340,6 +1414,86 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
1340
1414
  }
1341
1415
  return;
1342
1416
  }
1417
+ // `/tangent` (SER-083): a bookmark over the rewind path. Below the busy check
1418
+ // like `/rewind` (it refuses to queue: arming is a statement about "the next
1419
+ // prompt", and the return replaces the runtime). Arming only reads the
1420
+ // catalogue; the return is `startRewind` on the captured row, adopted through
1421
+ // the same successor path as `/rewind` — minus the draft hand-back.
1422
+ const tangentCommand = parseTangentCommand(text);
1423
+ if (tangentCommand !== undefined) {
1424
+ setEditor({ text: '', cursor: { offset: 0, affinity: 'downstream' } });
1425
+ setSelectedCompletion(0);
1426
+ dispatch({ type: 'userInput', text });
1427
+ if (tangentCommand === 'usage') {
1428
+ dispatch({ type: 'notice', text: TANGENT_COMMAND_USAGE });
1429
+ return;
1430
+ }
1431
+ if (startRewind === undefined) {
1432
+ dispatch({ type: 'notice', text: '/tangent is not available in this driver', severity: 'warn' });
1433
+ return;
1434
+ }
1435
+ const outcome = tangentCommandOutcome(tangentRef.current, tangentCommand);
1436
+ if (outcome.action === 'notice' || outcome.action === 'disarm') {
1437
+ if (outcome.action === 'disarm')
1438
+ setTangent(undefined);
1439
+ dispatch({ type: 'notice', text: outcome.notice });
1440
+ return;
1441
+ }
1442
+ if (outcome.action === 'arm') {
1443
+ const armed = armTangent(await runtime.listRewindCheckpoints());
1444
+ if (armed.kind === 'refused') {
1445
+ dispatch({ type: 'notice', text: armed.notice, severity: 'warn' });
1446
+ return;
1447
+ }
1448
+ setTangent(armed.state);
1449
+ dispatch({ type: 'notice', text: armed.notice });
1450
+ return;
1451
+ }
1452
+ // Return: the same refusals `/rewind` acceptance has, in the same order.
1453
+ const liveDelegations = runtime.listBackgroundDelegations();
1454
+ if (liveDelegations.length > 0) {
1455
+ dispatch({ type: 'notice', text: liveBackgroundDelegationRefusal('/tangent', liveDelegations), severity: 'warn' });
1456
+ return;
1457
+ }
1458
+ if (clearing.current) {
1459
+ dispatch({ type: 'notice', text: 'still starting the new session — press enter again once it appears' });
1460
+ return;
1461
+ }
1462
+ const sourceSessionId = runtime.info.sessionId;
1463
+ clearing.current = true;
1464
+ let next;
1465
+ let discarded;
1466
+ try {
1467
+ // Counted before the branch, from the source's own catalogue; a listing
1468
+ // failure costs precision, never the return.
1469
+ let catalogue;
1470
+ try {
1471
+ catalogue = await runtime.listRewindCheckpoints();
1472
+ }
1473
+ catch {
1474
+ catalogue = undefined;
1475
+ }
1476
+ discarded = discardedPromptCount(outcome.state, catalogue);
1477
+ next = await startRewind(outcome.state.returnPoint);
1478
+ }
1479
+ catch (error) {
1480
+ // Stale or unmapped row: the rewind path's own error, and the tangent stays
1481
+ // armed — nothing was released, the user can still /rewind by hand.
1482
+ dispatch({
1483
+ type: 'notice',
1484
+ text: `could not rewind; still in ${sourceSessionId}: ${error instanceof Error ? error.message : String(error)}`,
1485
+ severity: 'error',
1486
+ });
1487
+ return;
1488
+ }
1489
+ finally {
1490
+ clearing.current = false;
1491
+ }
1492
+ adoptBranchSuccessor(next, 'tangent', outcome.state.returnPoint.prompt, sourceSessionId);
1493
+ setTangent(undefined);
1494
+ withNoticeDiagnostics(recordAction, next.diagnostics)({ type: 'notice', text: tangentReturnNotice(discarded) });
1495
+ return;
1496
+ }
1343
1497
  // the local reports above it: this replaces the conversation the running turn is
1344
1498
  // streaming into, and the SDK's session snapshot is written when that turn ends —
1345
1499
  // so a mid-turn switch would hand the old session's manager a conversation it no
@@ -1419,6 +1573,12 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
1419
1573
  text: `cleared — new session ${next.info.sessionId}. Previous session ${previousSessionId} is saved and ` +
1420
1574
  `resumable (darwin --session ${previousSessionId}); background jobs and MCP servers keep running.`,
1421
1575
  });
1576
+ // The tangent bookmarked a conversation this session no longer holds
1577
+ // (SER-083): it ends with one notice, and no rewind is performed for it.
1578
+ if (tangentRef.current !== undefined) {
1579
+ setTangent(undefined);
1580
+ withNoticeDiagnostics(recordAction, next.diagnostics)({ type: 'notice', text: tangentEndedByNotice('/clear') });
1581
+ }
1422
1582
  return;
1423
1583
  }
1424
1584
  if (text === '/compact' || text.startsWith('/compact ')) {
@@ -1489,7 +1649,9 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
1489
1649
  ? `loaded skill "${expanded.skill.name}"`
1490
1650
  : expanded.kind === 'workflow'
1491
1651
  ? 'delegating via the workflow tool'
1492
- : `loaded command "/${expanded.command.name}"`,
1652
+ : expanded.kind === 'init'
1653
+ ? 'writing project instructions with /init'
1654
+ : `loaded command "/${expanded.command.name}"`,
1493
1655
  });
1494
1656
  toSend = expanded.message;
1495
1657
  }
@@ -1531,7 +1693,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
1531
1693
  severity: 'warn',
1532
1694
  });
1533
1695
  }
1534
- }, [dispatch, exit, openRewindChooser, recordAction, returnQueuedToEditor, runtime, runTurn, setAttachedImage, setEditor, setQueued, startNewSession, status, writeToTerminal]);
1696
+ }, [adoptBranchSuccessor, dispatch, exit, openRewindChooser, recordAction, returnQueuedToEditor, runtime, runTurn, setAttachedImage, setEditor, setQueued, setTangent, startNewSession, startRewind, status, writeToTerminal]);
1535
1697
  // The drain (SER-027): when the session is idle and nothing owns the keyboard,
1536
1698
  // the oldest queued entry goes back through the ordinary submit path — its own
1537
1699
  // turn for a prompt, its own run for a `!`, its own `userInput` recorded at
@@ -1819,27 +1981,14 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
1819
1981
  finally {
1820
1982
  clearing.current = false;
1821
1983
  }
1822
- writeToTerminal(CLEAR_TERMINAL);
1823
- recordAction({ type: 'clear' });
1824
- setRuntime(next);
1825
- setRewindSearch(undefined);
1826
- // The restored session replaces the whole editor state; the selected prompt
1827
- // returns unsent, and undo must not reach across the session boundary.
1828
- undoStack.current = [];
1829
- setEditor({ text: selected.prompt, cursor: { offset: selected.prompt.length, affinity: 'upstream' } });
1830
- setSelectedCompletion(0);
1831
- contextWarnLatch.current = createContextWarnLatch();
1832
- trajectoryWarned.current = false;
1833
- diagnosticsWarned.current = false;
1834
- pendingShellReports.current = [];
1835
- setQueued([]);
1836
- withNoticeDiagnostics(recordAction, next.diagnostics)({
1837
- type: 'notice',
1838
- severity: 'warn',
1839
- text: `rewound conversation into new session ${next.info.sessionId}; source ${search.sourceSessionId} remains saved and resumable. ` +
1840
- 'Workspace unchanged: workspace files, shell and ! effects, hooks, MCP writes, subagents, background jobs, and learned-memory files were not rewound.',
1841
- });
1842
- }, [dispatch, recordAction, runtime, setEditor, setQueued, setRewindSearch, startRewind, writeToTerminal]);
1984
+ adoptBranchSuccessor(next, 'rewind', selected.prompt, search.sourceSessionId);
1985
+ // A tangent bookmarked the conversation just left behind (SER-083): it ends
1986
+ // with one notice, and the rewind the user chose is the only rewind performed.
1987
+ if (tangentRef.current !== undefined) {
1988
+ setTangent(undefined);
1989
+ withNoticeDiagnostics(recordAction, next.diagnostics)({ type: 'notice', text: tangentEndedByNotice('/rewind') });
1990
+ }
1991
+ }, [adoptBranchSuccessor, dispatch, recordAction, runtime, setRewindSearch, setTangent, startRewind]);
1843
1992
  const handleRewindSearchKey = useCallback((typed, key) => {
1844
1993
  const current = rewindSearchRef.current;
1845
1994
  if (current === undefined)
@@ -2266,7 +2415,7 @@ export function App({ runtime: initialRuntime, permissions, initialHistory = [],
2266
2415
  setSelectedCompletion(0);
2267
2416
  endRecall();
2268
2417
  });
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 }))] })] }));
2418
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { ref: headerRef, flexDirection: "column", children: _jsx(Header, { runtime: runtime, status: effectiveStatus, frame: frame, tangent: tangent }) }), _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 }))] })] }));
2270
2419
  }
2271
2420
  /** The hint row under the draft, or nothing when the session is idle. */
2272
2421
  function hintForStatus(status, busyReadout, queuedCount = 0, queuedWakeCount = 0) {
@@ -2315,15 +2464,15 @@ function lastRetryOutcome(runtime) {
2315
2464
  return undefined;
2316
2465
  }
2317
2466
  }
2318
- export function Header({ runtime, status = 'idle', frame = 0, }) {
2467
+ export function Header({ runtime, status = 'idle', frame = 0, tangent, }) {
2319
2468
  const info = runtime.info;
2320
2469
  const instructions = info.projectInstructions;
2321
2470
  // Live, not info.permissionMode: /mode moves it mid-session, and a header still
2322
2471
  // naming the startup policy would be worse than no header — this row is the only
2323
2472
  // place the effective mode is stated, and it must not gain a second one.
2324
2473
  const mode = runtime.permissionMode;
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 &&
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" })] }));
2474
+ 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), tangentHeaderSuffix(tangent)] })] }), _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 &&
2475
+ (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: "/ for actions \u00B7 @ for paths \u00B7 ctrl+c cancels \u00B7 /exit quits" })] }));
2327
2476
  }
2328
2477
  const WORKING_LABEL = 'working';
2329
2478
  /** Highlights one letter in place, preserving the header's exact width and row count. */
@@ -2361,10 +2510,6 @@ function formatCapabilities(info) {
2361
2510
  function capabilityCount(count, label) {
2362
2511
  return count > 0 ? `${count} ${label}${count === 1 ? '' : 's'}` : undefined;
2363
2512
  }
2364
- /** Sizes are shown so an accidentally huge AGENTS.md is visible at a glance. */
2365
- function formatBytes(bytes) {
2366
- return bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`;
2367
- }
2368
2513
  /**
2369
2514
  * Provider-aware token counters as a labelled block.
2370
2515
  *