strands-darwin 0.0.33 → 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 (142) hide show
  1. package/README.md +5 -1
  2. package/README.zh-CN.md +5 -1
  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/cache-miss.d.ts +143 -0
  9. package/dist/src/agent/cache-miss.js +182 -0
  10. package/dist/src/agent/cache-miss.js.map +1 -0
  11. package/dist/src/agent/compact.d.ts +28 -0
  12. package/dist/src/agent/compact.js +34 -0
  13. package/dist/src/agent/compact.js.map +1 -1
  14. package/dist/src/agent/context-breakdown.d.ts +110 -0
  15. package/dist/src/agent/context-breakdown.js +117 -0
  16. package/dist/src/agent/context-breakdown.js.map +1 -0
  17. package/dist/src/agent/instructions.d.ts +23 -4
  18. package/dist/src/agent/instructions.js +67 -34
  19. package/dist/src/agent/instructions.js.map +1 -1
  20. package/dist/src/agent/permission-rules.d.ts +81 -2
  21. package/dist/src/agent/permission-rules.js +226 -6
  22. package/dist/src/agent/permission-rules.js.map +1 -1
  23. package/dist/src/agent/permission.d.ts +116 -2
  24. package/dist/src/agent/permission.js +201 -26
  25. package/dist/src/agent/permission.js.map +1 -1
  26. package/dist/src/agent/prompt-cache.d.ts +12 -3
  27. package/dist/src/agent/prompt-cache.js +12 -3
  28. package/dist/src/agent/prompt-cache.js.map +1 -1
  29. package/dist/src/agent/refusal.d.ts +44 -7
  30. package/dist/src/agent/refusal.js +54 -8
  31. package/dist/src/agent/refusal.js.map +1 -1
  32. package/dist/src/agent/runtime.d.ts +112 -7
  33. package/dist/src/agent/runtime.js +240 -19
  34. package/dist/src/agent/runtime.js.map +1 -1
  35. package/dist/src/agent/stream-resumption.d.ts +5 -2
  36. package/dist/src/agent/stream-resumption.js +5 -2
  37. package/dist/src/agent/stream-resumption.js.map +1 -1
  38. package/dist/src/agent/system-prompt.d.ts +1 -1
  39. package/dist/src/agent/system-prompt.js +4 -1
  40. package/dist/src/agent/system-prompt.js.map +1 -1
  41. package/dist/src/agent/thinking.js +4 -2
  42. package/dist/src/agent/thinking.js.map +1 -1
  43. package/dist/src/agents/child-recipe.d.ts +9 -1
  44. package/dist/src/agents/child-recipe.js +2 -0
  45. package/dist/src/agents/child-recipe.js.map +1 -1
  46. package/dist/src/agents/dispatch-registry.d.ts +18 -0
  47. package/dist/src/agents/dispatch-registry.js +2 -0
  48. package/dist/src/agents/dispatch-registry.js.map +1 -1
  49. package/dist/src/agents/retained-children.d.ts +101 -0
  50. package/dist/src/agents/retained-children.js +101 -0
  51. package/dist/src/agents/retained-children.js.map +1 -0
  52. package/dist/src/agents/subagent-tool.d.ts +50 -1
  53. package/dist/src/agents/subagent-tool.js +151 -12
  54. package/dist/src/agents/subagent-tool.js.map +1 -1
  55. package/dist/src/agents/workflow-tool.js +2 -2
  56. package/dist/src/agents/workflow-tool.js.map +1 -1
  57. package/dist/src/cli-doctor.js +10 -6
  58. package/dist/src/cli-doctor.js.map +1 -1
  59. package/dist/src/cli-main.js +9 -3
  60. package/dist/src/cli-main.js.map +1 -1
  61. package/dist/src/commands/custom-commands.d.ts +1 -1
  62. package/dist/src/commands/custom-commands.js +12 -5
  63. package/dist/src/commands/custom-commands.js.map +1 -1
  64. package/dist/src/commands/init-command.d.ts +47 -0
  65. package/dist/src/commands/init-command.js +110 -0
  66. package/dist/src/commands/init-command.js.map +1 -0
  67. package/dist/src/config.d.ts +78 -8
  68. package/dist/src/config.js +167 -20
  69. package/dist/src/config.js.map +1 -1
  70. package/dist/src/dev-repl.js +17 -2
  71. package/dist/src/dev-repl.js.map +1 -1
  72. package/dist/src/headless-protocol.d.ts +1 -1
  73. package/dist/src/headless-protocol.js +6 -5
  74. package/dist/src/headless-protocol.js.map +1 -1
  75. package/dist/src/headless-runner.js +12 -3
  76. package/dist/src/headless-runner.js.map +1 -1
  77. package/dist/src/headless.d.ts +11 -0
  78. package/dist/src/headless.js +33 -7
  79. package/dist/src/headless.js.map +1 -1
  80. package/dist/src/hooks/tool-hooks.js +10 -6
  81. package/dist/src/hooks/tool-hooks.js.map +1 -1
  82. package/dist/src/pricing/model-prices.d.ts +3 -1
  83. package/dist/src/pricing/model-prices.js +7 -1
  84. package/dist/src/pricing/model-prices.js.map +1 -1
  85. package/dist/src/skills/builtin/self-evolution-research/SKILL.md +14 -1
  86. package/dist/src/skills/prompt.d.ts +17 -0
  87. package/dist/src/skills/prompt.js +20 -0
  88. package/dist/src/skills/prompt.js.map +1 -1
  89. package/dist/src/tools/background-bash.d.ts +15 -3
  90. package/dist/src/tools/background-bash.js +18 -8
  91. package/dist/src/tools/background-bash.js.map +1 -1
  92. package/dist/src/tools/file-editor-serial.d.ts +14 -0
  93. package/dist/src/tools/file-editor-serial.js +15 -0
  94. package/dist/src/tools/file-editor-serial.js.map +1 -1
  95. package/dist/src/tools/shell-env.d.ts +77 -0
  96. package/dist/src/tools/shell-env.js +139 -0
  97. package/dist/src/tools/shell-env.js.map +1 -0
  98. package/dist/src/trajectory/record.d.ts +169 -2
  99. package/dist/src/trajectory/record.js +135 -0
  100. package/dist/src/trajectory/record.js.map +1 -1
  101. package/dist/src/trajectory/replay.d.ts +34 -1
  102. package/dist/src/trajectory/replay.js +157 -4
  103. package/dist/src/trajectory/replay.js.map +1 -1
  104. package/dist/src/trajectory/resume-recap.js +10 -3
  105. package/dist/src/trajectory/resume-recap.js.map +1 -1
  106. package/dist/src/trajectory/spend.d.ts +14 -1
  107. package/dist/src/trajectory/spend.js +40 -6
  108. package/dist/src/trajectory/spend.js.map +1 -1
  109. package/dist/src/trajectory/writer.d.ts +89 -4
  110. package/dist/src/trajectory/writer.js +191 -17
  111. package/dist/src/trajectory/writer.js.map +1 -1
  112. package/dist/src/tui/App.d.ts +12 -5
  113. package/dist/src/tui/App.js +328 -67
  114. package/dist/src/tui/App.js.map +1 -1
  115. package/dist/src/tui/InputBox.d.ts +1 -1
  116. package/dist/src/tui/InputBox.js +1 -1
  117. package/dist/src/tui/context-format.d.ts +16 -0
  118. package/dist/src/tui/context-format.js +41 -0
  119. package/dist/src/tui/context-format.js.map +1 -1
  120. package/dist/src/tui/instructions-format.d.ts +14 -0
  121. package/dist/src/tui/instructions-format.js +24 -0
  122. package/dist/src/tui/instructions-format.js.map +1 -0
  123. package/dist/src/tui/prompt-queue.js +4 -2
  124. package/dist/src/tui/prompt-queue.js.map +1 -1
  125. package/dist/src/tui/status-format.d.ts +50 -16
  126. package/dist/src/tui/status-format.js +92 -8
  127. package/dist/src/tui/status-format.js.map +1 -1
  128. package/dist/src/tui/subagent-format.js +13 -1
  129. package/dist/src/tui/subagent-format.js.map +1 -1
  130. package/dist/src/tui/tangent.d.ts +122 -0
  131. package/dist/src/tui/tangent.js +153 -0
  132. package/dist/src/tui/tangent.js.map +1 -0
  133. package/dist/src/tui/terminal-notify.d.ts +40 -0
  134. package/dist/src/tui/terminal-notify.js +136 -0
  135. package/dist/src/tui/terminal-notify.js.map +1 -0
  136. package/dist/src/tui/terminal-title.d.ts +94 -0
  137. package/dist/src/tui/terminal-title.js +121 -0
  138. package/dist/src/tui/terminal-title.js.map +1 -0
  139. package/dist/src/tui/turn-state.d.ts +12 -1
  140. package/dist/src/tui/turn-state.js +11 -0
  141. package/dist/src/tui/turn-state.js.map +1 -1
  142. package/package.json +3 -3
package/README.md CHANGED
@@ -37,7 +37,7 @@ This is a bounded workflow, not autonomous product authority. A dirty or unverif
37
37
  ## What it gives you
38
38
 
39
39
  - **A readable Ink TUI:** streaming Markdown answers, proposed file-edit diffs, elapsed time and token spend, slash/path completion, prompt recall and queueing, local `!` commands, and bounded reports.
40
- - **Safe approval modes:** `default`, classifier-assisted `auto`, read-only `plan`, and explicit `yolo`, with narrow project-scoped allow rules that can be revoked in-session.
40
+ - **Safe approval modes:** `default`, classifier-assisted `auto`, read-only `plan`, and explicit `yolo`, with narrow project-scoped allow rules that can be revoked in-session and deny rules that hold in every mode, `yolo` included.
41
41
  - **Durable work:** resumable project-scoped sessions, append-only trajectories, replay/search/fork/export, cost records, optional diagnostics, background jobs, and parent-managed on-demand project memory with exact evidence and durable-turn commit.
42
42
  - **Extension layers:** built-in and project/global skills, custom commands, child agents with workflow-DAG delegation, tool hooks, and stdio/HTTP MCP servers, with portable `.agents/` discovery.
43
43
  - **Automation:** one-shot text output or versioned JSON/JSONL, strict session selection, bounded model-call and context-offload controls, and nonzero cancellation/failure exits.
@@ -107,12 +107,16 @@ For multiple switchable models, provider-specific fields, Bedrock Mantle, cachin
107
107
  /developer <requirement>
108
108
  /self-evolution-research
109
109
  /help local command, prompt, and key reference
110
+ /init ask the model to create or improve this project's AGENTS.md
110
111
  /copy copy the last completed answer to the clipboard (OSC 52, works over SSH)
111
112
  /rewind branch conversation from a completed prompt (workspace unchanged)
113
+ /tangent bookmark the conversation for a side question; /tangent again returns
112
114
  ```
113
115
 
114
116
  Use `Ctrl+R` to search this project's prompt history (type to filter, `Ctrl+R`/`Up`/`Down` to navigate, `Enter`/`Tab` to accept, `Escape` to cancel), `Ctrl+C` to cancel busy work, `Ctrl+B` to expand or compact tool details, and `/exit` or `Ctrl+D` to quit. In the composer, `Alt/Ctrl+Left/Right` or `Alt+B`/`Alt+F` moves by word, `Alt+Backspace`/`Alt+D` deletes the word before/after the cursor, and `Ctrl+_` (or `Ctrl+-`) undoes the last `Ctrl+K`/`Ctrl+U`, `Ctrl+W` or `Alt` word deletion. On an empty idle composer, `Esc` `Esc` (the second within 500 ms) opens the `/rewind` chooser — the same thing typing `/rewind` does; a single `Esc` there does nothing. Model tool calls still pass through the active permission mode; `!` commands are commands you authorize by typing them yourself.
115
117
 
118
+ To be called back when you have switched away, set `"terminalBell": true` (one BEL) and/or `"terminalNotify": true` (one OSC 9 desktop-notification sequence, shown by iTerm2, kitty, Ghostty, WezTerm and foot, silently ignored elsewhere) in `~/.darwin/config.json`; both fire when a permission prompt waits and when a turn completes, and both are off by default. iTerm2 needs "Send escape sequence-generated alerts" enabled; tmux needs `set -g allow-passthrough on`. Details in [Configuration and context](docs/user-guide/configuration.md).
119
+
116
120
  For non-interactive use:
117
121
 
118
122
  ```bash
package/README.zh-CN.md CHANGED
@@ -37,7 +37,7 @@ darwin 是一项自托管 AI 开发实验。[v0.0.1 基线版本](https://github
37
37
  ## 主要能力
38
38
 
39
39
  - **清晰的 Ink TUI:**流式 Markdown 回复、文件修改 diff、耗时与 token 消耗、斜杠命令与路径补全、提示词回看和排队、本地 `!` 命令,以及有长度上限的状态报告。
40
- - **安全审批模式:**`default`、带分类器的 `auto`、只读 `plan` 和显式开启的 `yolo`;项目级放行规则尽量收窄,并可在会话内撤销。
40
+ - **安全审批模式:**`default`、带分类器的 `auto`、只读 `plan` 和显式开启的 `yolo`;项目级放行规则尽量收窄,并可在会话内撤销;拒绝规则在所有模式下生效,包括 `yolo`。
41
41
  - **可持续的工作状态:**按项目保存的可恢复会话、只追加轨迹、回放/搜索/分叉/导出、费用记录、可选诊断日志、后台任务,以及由父 agent 按需管理、带精确证据并在回合持久化后提交的项目记忆。
42
42
  - **扩展机制:**内置及项目/全局 skills、自定义命令、子代理与 workflow DAG 委派、工具 hooks、stdio/HTTP MCP 服务器,并兼容 `.agents/` 目录。
43
43
  - **自动化接口:**单次文本输出或带版本的 JSON/JSONL;严格选择会话;可限制模型调用次数和上下文卸载;取消或失败时返回非零状态码。
@@ -107,12 +107,16 @@ Bedrock 使用标准 AWS 凭证链。模型 ID 必须是 `us.`、`eu.`、`apac.`
107
107
  /developer <requirement>
108
108
  /self-evolution-research
109
109
  /help 查看本地命令、输入语法和按键说明
110
+ /init 请模型为当前项目创建或改进 AGENTS.md
110
111
  /copy 把最近一条已完成回答复制到剪贴板(OSC 52,SSH 下可用)
111
112
  /rewind 从已完成提示词分支对话(工作区不变)
113
+ /tangent 为一次旁支提问给对话加书签;再输入 /tangent 即返回
112
114
  ```
113
115
 
114
116
  按 `Ctrl+R` 可搜索当前项目的提示历史(输入文字筛选,按 `Ctrl+R`/`Up`/`Down` 切换结果,按 `Enter`/`Tab` 接受,按 `Escape` 取消);忙碌时按 `Ctrl+C` 取消,按 `Ctrl+B` 展开或收起工具详情,使用 `/exit` 或 `Ctrl+D` 退出。编辑输入时,`Alt/Ctrl+Left/Right` 或 `Alt+B`/`Alt+F` 按词移动光标,`Alt+Backspace`/`Alt+D` 删除光标前/后的一个词,`Ctrl+_`(或 `Ctrl+-`)可撤销最近一次 `Ctrl+K`/`Ctrl+U`、`Ctrl+W` 或 `Alt` 系列的删词操作。输入框为空且空闲时,连按两次 `Esc`(第二次在 500 ms 内)会打开 `/rewind` 选择器,效果与输入 `/rewind` 完全相同;此时单按一次 `Esc` 不做任何事。模型发起的工具调用仍会经过当前审批模式;`!` 命令由你亲自输入,因此不走模型工具审批。
115
117
 
118
+ 想在切到别处时被叫回来,可在 `~/.darwin/config.json` 中设置 `"terminalBell": true`(响一次终端铃)和/或 `"terminalNotify": true`(写一条 OSC 9 桌面通知序列,iTerm2、kitty、Ghostty、WezTerm 和 foot 会弹出通知,其他终端静默忽略);二者都在权限提示等待时和回合结束时触发,默认均为关闭。iTerm2 需开启 "Send escape sequence-generated alerts";tmux 需要 `set -g allow-passthrough on`。详见[配置与上下文](docs/user-guide/configuration.zh-CN.md)。
119
+
116
120
  无交互运行方式如下:
117
121
 
118
122
  ```bash
@@ -528,10 +528,10 @@ index 69b6549df8bf55b39e34aaf2940cac2a7fbf0714..440965bdc2879f7c2755ace3cda9ab70
528
528
  //# sourceMappingURL=plugin.js.map
529
529
 
530
530
  diff --git a/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.d.ts b/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.d.ts
531
- index a0a5b0e40e22e6108df5d832e9b1ba051e2f99cd..8907d109ce2866e376df312ebc0bae1a68acec3d 100644
531
+ index a0a5b0e40e22e6108df5d832e9b1ba051e2f99cd..aeef5bc02bb459333de75e2c93d97a4bf92ebdf7 100644
532
532
  --- a/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.d.ts
533
533
  +++ b/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.d.ts
534
- @@ -1,12 +1,19 @@
534
+ @@ -1,12 +1,25 @@
535
535
  -import type { BashOutput } from './types.js';
536
536
  +import type { InvokableTool } from '../../index.js';
537
537
  +import type { BashInput, BashOutput } from './types.js';
@@ -540,6 +540,12 @@ index a0a5b0e40e22e6108df5d832e9b1ba051e2f99cd..8907d109ce2866e376df312ebc0bae1a
540
540
  + cwd?: string;
541
541
  + /** Session project root used only for conservative wrong-root path preflight. */
542
542
  + projectRoot?: string;
543
+ + /**
544
+ + * Environment for every persistent shell this tool starts (replacements after
545
+ + * restart/exit included); `PS1`/`PS2` are still cleared on top. Absent means
546
+ + * `process.env`, byte-identical to the behaviour without the option.
547
+ + */
548
+ + env?: Record<string, string>;
543
549
  +}
544
550
  +/**
545
551
  + * Create a host-only bash tool with configured persistent-shell path context.
@@ -559,7 +565,7 @@ index a0a5b0e40e22e6108df5d832e9b1ba051e2f99cd..8907d109ce2866e376df312ebc0bae1a
559
565
  //# sourceMappingURL=bash.d.ts.map
560
566
 
561
567
  diff --git a/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.js b/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.js
562
- index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fac7a100e9 100644
568
+ index 44fb775853169dab0fde7aee5e7cc275a060de9c..7f3389ddd3e39704bb0ba5728dcf2c113b66efdf 100644
563
569
  --- a/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.js
564
570
  +++ b/node_modules/@strands-agents/sdk/dist/src/vended-tools/bash/bash.js
565
571
  @@ -1,8 +1,64 @@
@@ -685,7 +691,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
685
691
  /**
686
692
  * Internal class for managing a bash session.
687
693
  */
688
- @@ -18,9 +125,21 @@ class BashSession {
694
+ @@ -18,9 +125,25 @@ class BashSession {
689
695
  _started = false;
690
696
  _timeout;
691
697
  _sentinel;
@@ -696,8 +702,12 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
696
702
  + _initialCwd;
697
703
  + _projectRoot;
698
704
  + _cwd;
699
- + constructor(timeout = 120, initialCwd = process.cwd(), projectRoot = null) {
705
+ + _env;
706
+ + constructor(timeout = 120, initialCwd = process.cwd(), projectRoot = null, env = null) {
700
707
  this._timeout = timeout;
708
+ + // The environment every shell this session starts inherits; null keeps the
709
+ + // process's own, exactly as before the option existed.
710
+ + this._env = env;
701
711
  this._sentinel = `__BASH_DONE_${Date.now()}_${Math.random().toString(36).slice(2)}__`;
702
712
  + this._stderrSentinel = `${this._sentinel}_STDERR`;
703
713
  + this._exitCodeSentinel = `${this._sentinel}_EXIT`;
@@ -708,7 +718,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
708
718
  }
709
719
  /**
710
720
  * Starts the bash process if not already started.
711
- @@ -30,17 +149,28 @@ class BashSession {
721
+ @@ -30,17 +153,28 @@ class BashSession {
712
722
  return;
713
723
  }
714
724
  try {
@@ -716,8 +726,9 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
716
726
  + // timed-out foreground child down with it instead of orphaning it to pid 1.
717
727
  this._process = spawn('bash', [], {
718
728
  - cwd: process.cwd(),
729
+ - env: { ...process.env, PS1: '', PS2: '' },
719
730
  + cwd: this._initialCwd,
720
- env: { ...process.env, PS1: '', PS2: '' },
731
+ + env: { ...(this._env ?? process.env), PS1: '', PS2: '' },
721
732
  + detached: true,
722
733
  });
723
734
  if (!this._process.stdin || !this._process.stdout || !this._process.stderr) {
@@ -740,7 +751,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
740
751
  this._process = null;
741
752
  this._started = false;
742
753
  });
743
- @@ -54,16 +184,43 @@ class BashSession {
754
+ @@ -54,16 +188,43 @@ class BashSession {
744
755
  */
745
756
  stop() {
746
757
  if (this._process) {
@@ -787,7 +798,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
787
798
  this.start();
788
799
  if (!this._process || !this._process.stdin || !this._process.stdout || !this._process.stderr) {
789
800
  throw new BashSessionError('Bash session not properly initialized');
790
- @@ -72,33 +229,90 @@ class BashSession {
801
+ @@ -72,33 +233,90 @@ class BashSession {
791
802
  let stdoutData = '';
792
803
  let stderrData = '';
793
804
  let timeoutHandle = null;
@@ -888,7 +899,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
888
899
  }
889
900
  };
890
901
  // Handler for process errors
891
- @@ -107,13 +321,14 @@ class BashSession {
902
+ @@ -107,13 +325,14 @@ class BashSession {
892
903
  this.stop();
893
904
  reject(new BashSessionError(`Bash process error: ${err.message}`));
894
905
  };
@@ -905,7 +916,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
905
916
  stdout.off('data', onStdoutData);
906
917
  stderr.off('data', onStderrData);
907
918
  // Check if process still exists before removing listeners
908
- @@ -122,27 +337,77 @@ class BashSession {
919
+ @@ -122,27 +341,77 @@ class BashSession {
909
920
  this._process.off('error', onError);
910
921
  }
911
922
  };
@@ -987,7 +998,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
987
998
  });
988
999
  }
989
1000
  }
990
- @@ -151,6 +416,16 @@ class BashSession {
1001
+ @@ -151,6 +420,16 @@ class BashSession {
991
1002
  */
992
1003
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
993
1004
  const sessions = new WeakMap();
@@ -1004,7 +1015,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
1004
1015
  /**
1005
1016
  * Track all active sessions for cleanup on process exit.
1006
1017
  */
1007
- @@ -221,42 +496,50 @@ const DEFAULT_DESCRIPTION = 'Executes bash shell commands in a persistent sessio
1018
+ @@ -221,42 +500,53 @@ const DEFAULT_DESCRIPTION = 'Executes bash shell commands in a persistent sessio
1008
1019
  * State (variables, working directory) persists within the session.
1009
1020
  * Node.js only.
1010
1021
  */
@@ -1031,6 +1042,9 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
1031
1042
  + const initialCwd = path.resolve(options.cwd ?? process.cwd());
1032
1043
  + const projectRoot = options.projectRoot === undefined ? null : path.resolve(options.projectRoot);
1033
1044
  + const reportRestartCwd = options.cwd !== undefined || options.projectRoot !== undefined;
1045
+ + // Copied once: the caller's map is the environment for every shell this tool
1046
+ + // starts, including replacements after restart/exit; absent means process.env.
1047
+ + const env = options.env === undefined ? null : { ...options.env };
1034
1048
  + return tool({
1035
1049
  + name: 'bash',
1036
1050
  + description: DEFAULT_DESCRIPTION,
@@ -1071,7 +1085,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
1071
1085
  + sessions.delete(agent);
1072
1086
  + }
1073
1087
  + // Create new session (will be added to activeSessions when started)
1074
- + const newSession = new BashSession(120, initialCwd, projectRoot);
1088
+ + const newSession = new BashSession(120, initialCwd, projectRoot, env);
1075
1089
  + sessions.set(agent, newSession);
1076
1090
  + sessionFinalizer.register(agent, newSession);
1077
1091
  + return reportRestartCwd ? `Bash session restarted\ncwd: ${initialCwd}` : 'Bash session restarted';
@@ -1080,7 +1094,7 @@ index 44fb775853169dab0fde7aee5e7cc275a060de9c..b8b3a1f3f9541de7d671e0a5df9261fa
1080
1094
  + // Get or create session
1081
1095
  + let session = sessions.get(agent);
1082
1096
  + if (!session) {
1083
- + session = new BashSession(input.timeout ?? 120, initialCwd, projectRoot);
1097
+ + session = new BashSession(input.timeout ?? 120, initialCwd, projectRoot, env);
1084
1098
  + sessions.set(agent, session);
1085
1099
  + sessionFinalizer.register(agent, session);
1086
1100
  + }
@@ -0,0 +1,58 @@
1
+ diff --git a/node_modules/ink/build/ink.js b/node_modules/ink/build/ink.js
2
+ index 0082666b281ec2db77b875d6b8460bcc19a59ce7..dd772c834f77096cd3621f83bfa7d0fc0137ea47 100644
3
+ --- a/node_modules/ink/build/ink.js
4
+ +++ b/node_modules/ink/build/ink.js
5
+ @@ -155,6 +155,9 @@ export default class Ink {
6
+ lastOutputToRender;
7
+ lastOutputHeight;
8
+ lastTerminalWidth;
9
+ + // Set by `resized` when the terminal got narrower: the next interactive frame
10
+ + // redraws from a cleared screen instead of erasing by the stale line count.
11
+ + redrawAfterNarrowing;
12
+ container;
13
+ rootNode;
14
+ // This variable is used only in debug mode to store full static output
15
+ @@ -279,8 +282,17 @@ export default class Ink {
16
+ resized = () => {
17
+ const currentWidth = getWindowSize(this.options.stdout).columns;
18
+ if (currentWidth < this.lastTerminalWidth) {
19
+ - // We clear the screen when decreasing terminal width to prevent duplicate overlapping re-renders.
20
+ - this.log.clear();
21
+ + // A narrower terminal reflows the rows of the previous frame that no
22
+ + // longer fit, so the frame now occupies more rows than the line count
23
+ + // `log.clear()` would erase, and the top rows survive as stale copies
24
+ + // (one per resize event). Redraw the next frame from a cleared screen
25
+ + // with the full static output, the way overflowing frames already do,
26
+ + // and drop any throttled write of the pre-resize frame that would
27
+ + // otherwise land after the redraw.
28
+ + if (typeof this.throttledLog.cancel === 'function') {
29
+ + this.throttledLog.cancel();
30
+ + }
31
+ + this.redrawAfterNarrowing = true;
32
+ this.lastOutput = '';
33
+ this.lastOutputToRender = '';
34
+ }
35
+ @@ -753,13 +765,16 @@ export default class Ink {
36
+ const viewportRows = isTty ? getWindowSize(this.options.stdout).rows : 24;
37
+ const isFullscreen = isTty && outputHeight >= viewportRows;
38
+ const outputToRender = isFullscreen ? output : output + '\n';
39
+ - const shouldClearTerminal = shouldClearTerminalForFrame({
40
+ - isTty,
41
+ - viewportRows,
42
+ - previousOutputHeight: this.lastOutputHeight,
43
+ - nextOutputHeight: outputHeight,
44
+ - isUnmounting: this.isUnmounting,
45
+ - });
46
+ + const redrawAfterNarrowing = this.redrawAfterNarrowing === true;
47
+ + this.redrawAfterNarrowing = false;
48
+ + const shouldClearTerminal = (isTty && redrawAfterNarrowing) ||
49
+ + shouldClearTerminalForFrame({
50
+ + isTty,
51
+ + viewportRows,
52
+ + previousOutputHeight: this.lastOutputHeight,
53
+ + nextOutputHeight: outputHeight,
54
+ + isUnmounting: this.isUnmounting,
55
+ + });
56
+ if (shouldClearTerminal) {
57
+ const sync = this.shouldSync();
58
+ if (sync) {
@@ -77,13 +77,13 @@ export type BackgroundDelegationListener = (status: BackgroundDelegationStatus)
77
77
  /** The first eight characters of an SDK task id (a UUID) — enough to tell tasks apart in a row. */
78
78
  export declare function shortBackgroundTaskId(taskId: string): string;
79
79
  /**
80
- * The one refusal `/clear` and `/rewind` give while a background delegation is
81
- * tracked (SER-070): the live task ids and the two ways out. Never a partial restore,
80
+ * The one refusal `/clear`, `/rewind` and a `/tangent` return give while a background
81
+ * delegation is tracked (SER-070): the live task ids and the two ways out. Never a partial restore,
82
82
  * never a silent cancel of minutes of child work — the same rule as the SER-027 busy
83
83
  * refusal. Shared by the TUI's local check and the runtime's own guard, so the two
84
84
  * cannot word it differently.
85
85
  */
86
- export declare function liveBackgroundDelegationRefusal(command: '/clear' | '/rewind', tasks: readonly BackgroundDelegationStatus[]): string;
86
+ export declare function liveBackgroundDelegationRefusal(command: '/clear' | '/rewind' | '/tangent', tasks: readonly BackgroundDelegationStatus[]): string;
87
87
  /**
88
88
  * Forwards background runs' `AfterToolCallEvent`s into the parent's stream and keeps
89
89
  * the parent-side ledger of tracked delegations (SER-064, SER-070).
@@ -127,8 +127,8 @@ export function shortBackgroundTaskId(taskId) {
127
127
  return taskId.length > 8 ? taskId.slice(0, 8) : taskId;
128
128
  }
129
129
  /**
130
- * The one refusal `/clear` and `/rewind` give while a background delegation is
131
- * tracked (SER-070): the live task ids and the two ways out. Never a partial restore,
130
+ * The one refusal `/clear`, `/rewind` and a `/tangent` return give while a background
131
+ * delegation is tracked (SER-070): the live task ids and the two ways out. Never a partial restore,
132
132
  * never a silent cancel of minutes of child work — the same rule as the SER-027 busy
133
133
  * refusal. Shared by the TUI's local check and the runtime's own guard, so the two
134
134
  * cannot word it differently.
@@ -1 +1 @@
1
- {"version":3,"file":"background-delegation.js","sourceRoot":"","sources":["../../../src/agent/background-delegation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,uBAAuB,CAAC;AAEjE,iFAAiF;AACjF,MAAM,CAAC,MAAM,gCAAgC,GAAG,gCAAgC,CAAC;AAEjF,iFAAiF;AACjF,MAAM,CAAC,MAAM,gCAAgC,GAAG,gCAAgC,CAAC;AAEjF,2EAA2E;AAC3E,MAAM,cAAc,GAAG,6BAA6B,CAAC;AACrD,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAqBzC;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAsC;IAC/E,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE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AAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAEO,CAAC,KAAK;QACZ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,CAAC,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Why the prompt cache missed (SER-074): a derivation over facts darwin already
3
+ * holds, never a new measurement.
4
+ *
5
+ * `/usage` and `/status` have always shown cache read/write counts and a hit ratio,
6
+ * but a number alone does not say why a call re-read the conversation uncached.
7
+ * Every input needed to name a likely cause is already in the runtime: the per-call
8
+ * provider counters `observeCallStats` folds (`afterModelCallEvent`
9
+ * `stopData.message.metadata.usage`), the cache-invalidating events the session
10
+ * itself performed (`/model`, `/effort`, `/compact`), the configured TTL
11
+ * (`promptCacheTtl`: `1h` default, `5m`), the wall clock, and whether the session
12
+ * was resumed. This module is the pure arithmetic over those facts; the runtime
13
+ * feeds it through {@link CacheMissTracker} with the same synchronous,
14
+ * non-throwing, latch-on-failure discipline the call stats observe under.
15
+ *
16
+ * Advisory only, on the context-pressure row's terms: the verdict is printed on
17
+ * existing reports (`/usage`, `/status`) and as one transcript notice before a
18
+ * `/model` or `/effort` switch on a warm cache. Nothing is compacted, no second
19
+ * threshold exists, no frame row, tick or channel is added, nothing is persisted or
20
+ * recorded in the trajectory.
21
+ *
22
+ * Invalidators, and one deliberate non-invalidator. A model switch, an effective
23
+ * effort change and a compaction each change the request prefix (a different model
24
+ * keys a different cache; `output_config.effort` is part of the request; compaction
25
+ * rewrites the messages), and idling past the TTL lets the entries expire. `/rewind`
26
+ * is not marked: it restores an earlier prefix of the same conversation, whose cache
27
+ * entries are still valid if they have not expired — the same rule Claude Code's
28
+ * prompt-caching documentation states. File edits, permission-mode changes and skill
29
+ * loads change no cached section either.
30
+ *
31
+ * Claude-only by the gate `prompt-cache.ts` explains: OpenAI caches automatically
32
+ * at the provider with no darwin-placed cache points, so its counters describe a
33
+ * cache darwin did not configure — the tracker stays silent unless the live plan
34
+ * has Darwin-managed cache points.
35
+ */
36
+ import { type PromptCacheTtl } from './prompt-cache.js';
37
+ /** The one bounded verdict per missed call, in precedence order. */
38
+ export type CacheMissCause = 'model switched' | 'effort changed' | 'compacted' | 'idle past cache TTL' | 'first request of a resumed session' | 'unknown';
39
+ /** Session events that invalidate the prefix a cache read depends on. */
40
+ export type CacheInvalidatingEvent = 'model' | 'effort' | 'compact';
41
+ /**
42
+ * A call reading less than this share of its own request total from the cache is a
43
+ * miss. A warm call on a long conversation reads nearly all of it (the last user
44
+ * message is the only uncached part); one fifth leaves room for a large tool result
45
+ * or user message without calling an ordinary turn a miss.
46
+ */
47
+ export declare const CACHE_MISS_READ_FRACTION = 0.2;
48
+ /** One completed call's cache facts, as the tracker needs them. */
49
+ export interface CacheCallFacts {
50
+ /** When the call completed (epoch ms). */
51
+ at: number;
52
+ /** Tokens read from the cache, or undefined when the provider did not report it. */
53
+ cacheRead: number | undefined;
54
+ /** The request total (`requestInputTokens`: input + cache read + cache write), or undefined. */
55
+ requestInput: number | undefined;
56
+ }
57
+ export interface CacheMissInput {
58
+ /** The previous completed call, or undefined when this is the session's first. */
59
+ previous: CacheCallFacts | undefined;
60
+ current: CacheCallFacts;
61
+ /** Invalidating events the session performed since {@link previous} completed. */
62
+ events: ReadonlySet<CacheInvalidatingEvent>;
63
+ ttlMs: number;
64
+ /** True for the first call of a resumed session, whose cache the previous run wrote. */
65
+ firstCallAfterResume: boolean;
66
+ }
67
+ /** The TTL in milliseconds; an unset TTL is darwin's {@link DEFAULT_PROMPT_CACHE_TTL}. */
68
+ export declare function promptCacheTtlMs(ttl: PromptCacheTtl | undefined): number;
69
+ /**
70
+ * True when a call read less than {@link CACHE_MISS_READ_FRACTION} of its request
71
+ * from the cache. Unreported counters and an empty request are not misses: they are
72
+ * unknown, and unknown is never a verdict.
73
+ */
74
+ export declare function isCacheMiss(call: CacheCallFacts): boolean;
75
+ /**
76
+ * The likely cause of the current call's cache miss, or `undefined` for no verdict.
77
+ *
78
+ * No verdict when the current call's counters are unreported, when it is not a miss,
79
+ * when it is a fresh session's first call (expected cold: nothing has been written
80
+ * yet), or when the previous call was itself cold — a miss is only a miss relative
81
+ * to a cache that was demonstrably warm. When several causes apply, the one that
82
+ * certainly invalidated the prefix wins over the one that merely could have:
83
+ * `model switched` > `effort changed` > `compacted` > `idle past cache TTL` >
84
+ * `first request of a resumed session` > `unknown`.
85
+ */
86
+ export declare function cacheMissCause(input: CacheMissInput): CacheMissCause | undefined;
87
+ /** The cause as `/usage` and `/status` print it; the TTL cause names the configured TTL. */
88
+ export declare function describeCacheMissCause(cause: CacheMissCause, ttl: PromptCacheTtl | undefined): string;
89
+ /** What the reports read: the last observed miss, and how many there were. */
90
+ export interface CacheMissReport {
91
+ lastMiss: {
92
+ cause: CacheMissCause;
93
+ at: number;
94
+ cacheRead: number;
95
+ requestInput: number;
96
+ } | undefined;
97
+ misses: number;
98
+ }
99
+ /** Whether the last completed call's cache entries are still readable. */
100
+ export interface CacheWarmth {
101
+ /** True iff the last completed call read from the cache and finished less than the TTL ago. */
102
+ warm: boolean;
103
+ /** Milliseconds since the last completed call. */
104
+ ageMs: number;
105
+ /** What that call read from the cache. */
106
+ lastCacheRead: number;
107
+ }
108
+ /**
109
+ * The one bounded notice `/model <target>` and `/effort <level>` print before a
110
+ * switch on a warm cache — `undefined` when the cache is cold or nothing is known,
111
+ * so a cold switch prints nothing new. States the cost and lets the switch proceed;
112
+ * deliberately not a confirmation dialog.
113
+ */
114
+ export declare function warmCacheSwitchNotice(kind: 'model' | 'effort', warmth: CacheWarmth | undefined): string | undefined;
115
+ /**
116
+ * The per-runtime state behind {@link CacheMissReport} and {@link CacheWarmth}.
117
+ *
118
+ * Pure over what it is handed: the runtime passes each completed call's facts and
119
+ * the clock, marks the events it performed, and reads the two projections. Nothing
120
+ * here throws on ordinary data; the runtime wraps the calls in the observer latch
121
+ * anyway, so a surprise degrades to absence rather than to a dead turn. `/clear`'s
122
+ * successor runtime builds a new tracker, which is how the state stays session-scoped.
123
+ */
124
+ export declare class CacheMissTracker {
125
+ private readonly ttlMs;
126
+ private previous;
127
+ private readonly events;
128
+ private lastMiss;
129
+ private misses;
130
+ private firstCallAfterResume;
131
+ /**
132
+ * @param ttlMs the live TTL, read per call because `promptCacheTtl` is a model
133
+ * field and `/model` can change it mid-session.
134
+ */
135
+ constructor(ttlMs: () => number, resumed: boolean);
136
+ /** Records that the session performed one invalidating event since the last call. */
137
+ mark(event: CacheInvalidatingEvent): void;
138
+ /** Folds one completed call in; returns the verdict for that call, if any. */
139
+ observe(call: CacheCallFacts): CacheMissCause | undefined;
140
+ report(): CacheMissReport;
141
+ /** `undefined` until a call has completed. */
142
+ warmth(now: number): CacheWarmth | undefined;
143
+ }