@namzu/sdk 68.0.0 → 69.0.0

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 (281) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/bridge/acp/server.d.ts +12 -0
  3. package/dist/bridge/acp/server.d.ts.map +1 -1
  4. package/dist/bridge/acp/server.js +20 -0
  5. package/dist/bridge/acp/server.js.map +1 -1
  6. package/dist/compaction/context-window.d.ts +8 -0
  7. package/dist/compaction/context-window.d.ts.map +1 -1
  8. package/dist/compaction/context-window.js +14 -0
  9. package/dist/compaction/context-window.js.map +1 -1
  10. package/dist/compaction/loaded-skills.d.ts +10 -0
  11. package/dist/compaction/loaded-skills.d.ts.map +1 -1
  12. package/dist/compaction/loaded-skills.js +45 -1
  13. package/dist/compaction/loaded-skills.js.map +1 -1
  14. package/dist/compaction/manager.d.ts +8 -0
  15. package/dist/compaction/manager.d.ts.map +1 -1
  16. package/dist/compaction/manager.js +31 -0
  17. package/dist/compaction/manager.js.map +1 -1
  18. package/dist/compaction/manual.d.ts.map +1 -1
  19. package/dist/compaction/manual.js +7 -1
  20. package/dist/compaction/manual.js.map +1 -1
  21. package/dist/compaction/model-summary.js +2 -2
  22. package/dist/compaction/model-summary.js.map +1 -1
  23. package/dist/compaction/restore.d.ts +8 -0
  24. package/dist/compaction/restore.d.ts.map +1 -1
  25. package/dist/compaction/restore.js +65 -0
  26. package/dist/compaction/restore.js.map +1 -1
  27. package/dist/compaction/salience/working-set.d.ts.map +1 -1
  28. package/dist/compaction/salience/working-set.js +2 -2
  29. package/dist/compaction/salience/working-set.js.map +1 -1
  30. package/dist/compaction/tool-result-editing.d.ts +6 -0
  31. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  32. package/dist/compaction/tool-result-editing.js +7 -1
  33. package/dist/compaction/tool-result-editing.js.map +1 -1
  34. package/dist/compaction/types.d.ts +2 -0
  35. package/dist/compaction/types.d.ts.map +1 -1
  36. package/dist/compaction/wire.d.ts.map +1 -1
  37. package/dist/compaction/wire.js +4 -0
  38. package/dist/compaction/wire.js.map +1 -1
  39. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  40. package/dist/manager/session/turn-recorder.js +23 -1
  41. package/dist/manager/session/turn-recorder.js.map +1 -1
  42. package/dist/network/join.d.ts +10 -0
  43. package/dist/network/join.d.ts.map +1 -1
  44. package/dist/network/join.js +15 -0
  45. package/dist/network/join.js.map +1 -1
  46. package/dist/network/service.d.ts.map +1 -1
  47. package/dist/network/service.js +166 -12
  48. package/dist/network/service.js.map +1 -1
  49. package/dist/network/store.d.ts +23 -1
  50. package/dist/network/store.d.ts.map +1 -1
  51. package/dist/network/store.js +23 -1
  52. package/dist/network/store.js.map +1 -1
  53. package/dist/network/transport.d.ts +1 -1
  54. package/dist/network/transport.js +1 -1
  55. package/dist/network/wire.d.ts +12 -0
  56. package/dist/network/wire.d.ts.map +1 -1
  57. package/dist/network/wire.js +12 -1
  58. package/dist/network/wire.js.map +1 -1
  59. package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
  60. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  61. package/dist/prompt/coding-agent-doctrine.js +7 -2
  62. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  63. package/dist/provider/fallback.d.ts.map +1 -1
  64. package/dist/provider/fallback.js +5 -0
  65. package/dist/provider/fallback.js.map +1 -1
  66. package/dist/provider/idle-timeout.d.ts.map +1 -1
  67. package/dist/provider/idle-timeout.js +5 -0
  68. package/dist/provider/idle-timeout.js.map +1 -1
  69. package/dist/provider/instrumentation.d.ts.map +1 -1
  70. package/dist/provider/instrumentation.js +10 -0
  71. package/dist/provider/instrumentation.js.map +1 -1
  72. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  73. package/dist/provider/model-window-suffix.js +1 -0
  74. package/dist/provider/model-window-suffix.js.map +1 -1
  75. package/dist/provider/retry.d.ts.map +1 -1
  76. package/dist/provider/retry.js +5 -0
  77. package/dist/provider/retry.js.map +1 -1
  78. package/dist/public-runtime.d.ts +1 -1
  79. package/dist/public-runtime.d.ts.map +1 -1
  80. package/dist/public-runtime.js +1 -1
  81. package/dist/public-runtime.js.map +1 -1
  82. package/dist/public-tools.d.ts +2 -0
  83. package/dist/public-tools.d.ts.map +1 -1
  84. package/dist/public-tools.js +4 -0
  85. package/dist/public-tools.js.map +1 -1
  86. package/dist/public-types.d.ts +1 -0
  87. package/dist/public-types.d.ts.map +1 -1
  88. package/dist/registry/tool/presentation.d.ts +8 -1
  89. package/dist/registry/tool/presentation.d.ts.map +1 -1
  90. package/dist/registry/tool/presentation.js +14 -5
  91. package/dist/registry/tool/presentation.js.map +1 -1
  92. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  93. package/dist/runtime/jobs/registry.js +2 -1
  94. package/dist/runtime/jobs/registry.js.map +1 -1
  95. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  96. package/dist/runtime/query/auto-review/classifier.js +19 -3
  97. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  98. package/dist/runtime/query/auto-review/failure.d.ts +12 -0
  99. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
  100. package/dist/runtime/query/auto-review/failure.js +46 -0
  101. package/dist/runtime/query/auto-review/failure.js.map +1 -0
  102. package/dist/runtime/query/auto-review/index.d.ts +1 -0
  103. package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
  104. package/dist/runtime/query/auto-review/index.js +1 -0
  105. package/dist/runtime/query/auto-review/index.js.map +1 -1
  106. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  107. package/dist/runtime/query/file-evidence-replay.js +6 -6
  108. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  109. package/dist/runtime/query/index.d.ts.map +1 -1
  110. package/dist/runtime/query/index.js +8 -1
  111. package/dist/runtime/query/index.js.map +1 -1
  112. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  113. package/dist/runtime/query/iteration/index.js +2 -0
  114. package/dist/runtime/query/iteration/index.js.map +1 -1
  115. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  116. package/dist/runtime/query/iteration/phases/compaction.js +21 -3
  117. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  118. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  119. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  120. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  121. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -2
  122. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  123. package/dist/runtime/query/iteration/phases/per-call-review.js +24 -9
  124. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  125. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  126. package/dist/runtime/query/iteration/step-shaping.js +4 -0
  127. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  128. package/dist/runtime/query/prepare-turn.d.ts +5 -1
  129. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  130. package/dist/runtime/query/prepare-turn.js +13 -3
  131. package/dist/runtime/query/prepare-turn.js.map +1 -1
  132. package/dist/runtime/query/review-policy.d.ts +13 -2
  133. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  134. package/dist/runtime/query/review-policy.js +13 -2
  135. package/dist/runtime/query/review-policy.js.map +1 -1
  136. package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
  137. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  138. package/dist/runtime/query/turn/outcome-ledger.js +36 -1
  139. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  140. package/dist/sandbox/provider/local.d.ts.map +1 -1
  141. package/dist/sandbox/provider/local.js +3 -1
  142. package/dist/sandbox/provider/local.js.map +1 -1
  143. package/dist/tools/admit-facts.d.ts.map +1 -1
  144. package/dist/tools/admit-facts.js +20 -0
  145. package/dist/tools/admit-facts.js.map +1 -1
  146. package/dist/tools/builtins/bash.d.ts.map +1 -1
  147. package/dist/tools/builtins/bash.js +5 -2
  148. package/dist/tools/builtins/bash.js.map +1 -1
  149. package/dist/tools/builtins/browser.js +2 -2
  150. package/dist/tools/builtins/browser.js.map +1 -1
  151. package/dist/tools/builtins/computer-use.d.ts +4 -0
  152. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  153. package/dist/tools/builtins/computer-use.js +106 -5
  154. package/dist/tools/builtins/computer-use.js.map +1 -1
  155. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  156. package/dist/tools/builtins/content-fingerprint.js +2 -1
  157. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  158. package/dist/tools/builtins/edit-apply.d.ts +1 -0
  159. package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
  160. package/dist/tools/builtins/edit-apply.js +108 -21
  161. package/dist/tools/builtins/edit-apply.js.map +1 -1
  162. package/dist/tools/builtins/edit-match.d.ts +37 -0
  163. package/dist/tools/builtins/edit-match.d.ts.map +1 -1
  164. package/dist/tools/builtins/edit-match.js +193 -0
  165. package/dist/tools/builtins/edit-match.js.map +1 -1
  166. package/dist/tools/builtins/edit.d.ts.map +1 -1
  167. package/dist/tools/builtins/edit.js +14 -7
  168. package/dist/tools/builtins/edit.js.map +1 -1
  169. package/dist/tools/builtins/exit-semantics.d.ts +8 -0
  170. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  171. package/dist/tools/builtins/exit-semantics.js +19 -0
  172. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  173. package/dist/tools/builtins/index.d.ts +2 -0
  174. package/dist/tools/builtins/index.d.ts.map +1 -1
  175. package/dist/tools/builtins/index.js +1 -0
  176. package/dist/tools/builtins/index.js.map +1 -1
  177. package/dist/tools/builtins/present-file.d.ts +24 -0
  178. package/dist/tools/builtins/present-file.d.ts.map +1 -0
  179. package/dist/tools/builtins/present-file.js +116 -0
  180. package/dist/tools/builtins/present-file.js.map +1 -0
  181. package/dist/tools/builtins/read-file.js +1 -1
  182. package/dist/tools/builtins/read-file.js.map +1 -1
  183. package/dist/tools/builtins/read-render.d.ts +12 -1
  184. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  185. package/dist/tools/builtins/read-render.js +16 -3
  186. package/dist/tools/builtins/read-render.js.map +1 -1
  187. package/dist/tools/builtins/search-tools.d.ts +10 -0
  188. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  189. package/dist/tools/builtins/search-tools.js +36 -2
  190. package/dist/tools/builtins/search-tools.js.map +1 -1
  191. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  192. package/dist/tools/builtins/wait-for-job.js +5 -0
  193. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  194. package/dist/tools/builtins/web.d.ts.map +1 -1
  195. package/dist/tools/builtins/web.js +13 -2
  196. package/dist/tools/builtins/web.js.map +1 -1
  197. package/dist/tools/task/create.js +2 -2
  198. package/dist/tools/task/create.js.map +1 -1
  199. package/dist/tools/task/update.js +1 -1
  200. package/dist/tools/task/update.js.map +1 -1
  201. package/dist/types/provider/chat.d.ts +8 -0
  202. package/dist/types/provider/chat.d.ts.map +1 -1
  203. package/dist/types/provider/interface.d.ts +10 -0
  204. package/dist/types/provider/interface.d.ts.map +1 -1
  205. package/dist/types/provider/model.d.ts +6 -0
  206. package/dist/types/provider/model.d.ts.map +1 -1
  207. package/dist/types/provider/stream.d.ts +2 -0
  208. package/dist/types/provider/stream.d.ts.map +1 -1
  209. package/dist/types/tool/presentation.d.ts +11 -0
  210. package/dist/types/tool/presentation.d.ts.map +1 -1
  211. package/dist/utils/node-on-path.d.ts +27 -0
  212. package/dist/utils/node-on-path.d.ts.map +1 -0
  213. package/dist/utils/node-on-path.js +70 -0
  214. package/dist/utils/node-on-path.js.map +1 -0
  215. package/package.json +1 -1
  216. package/src/bridge/acp/server.ts +25 -0
  217. package/src/compaction/context-window.ts +18 -0
  218. package/src/compaction/loaded-skills.ts +42 -1
  219. package/src/compaction/manager.ts +28 -0
  220. package/src/compaction/manual.ts +9 -1
  221. package/src/compaction/model-summary.ts +2 -2
  222. package/src/compaction/restore.ts +69 -0
  223. package/src/compaction/salience/working-set.ts +6 -2
  224. package/src/compaction/tool-result-editing.ts +8 -1
  225. package/src/compaction/types.ts +2 -0
  226. package/src/compaction/wire.ts +4 -0
  227. package/src/manager/session/turn-recorder.ts +24 -1
  228. package/src/network/join.ts +17 -0
  229. package/src/network/service.ts +185 -12
  230. package/src/network/store.ts +28 -1
  231. package/src/network/transport.ts +1 -1
  232. package/src/network/wire.ts +13 -1
  233. package/src/prompt/coding-agent-doctrine.ts +7 -2
  234. package/src/provider/fallback.ts +6 -0
  235. package/src/provider/idle-timeout.ts +6 -0
  236. package/src/provider/instrumentation.ts +12 -0
  237. package/src/provider/model-window-suffix.ts +1 -0
  238. package/src/provider/retry.ts +6 -0
  239. package/src/public-runtime.ts +1 -0
  240. package/src/public-tools.ts +9 -0
  241. package/src/public-types.ts +1 -0
  242. package/src/registry/tool/presentation.ts +14 -4
  243. package/src/runtime/jobs/registry.ts +2 -1
  244. package/src/runtime/query/auto-review/classifier.ts +19 -3
  245. package/src/runtime/query/auto-review/failure.ts +50 -0
  246. package/src/runtime/query/auto-review/index.ts +1 -0
  247. package/src/runtime/query/file-evidence-replay.ts +6 -5
  248. package/src/runtime/query/index.ts +19 -0
  249. package/src/runtime/query/iteration/index.ts +2 -0
  250. package/src/runtime/query/iteration/phases/compaction.ts +25 -2
  251. package/src/runtime/query/iteration/phases/context.ts +4 -0
  252. package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
  253. package/src/runtime/query/iteration/step-shaping.ts +4 -0
  254. package/src/runtime/query/prepare-turn.ts +20 -2
  255. package/src/runtime/query/review-policy.ts +24 -4
  256. package/src/runtime/query/turn/outcome-ledger.ts +45 -1
  257. package/src/sandbox/provider/local.ts +3 -1
  258. package/src/tools/admit-facts.ts +18 -0
  259. package/src/tools/builtins/bash.ts +5 -2
  260. package/src/tools/builtins/browser.ts +2 -2
  261. package/src/tools/builtins/computer-use.ts +123 -4
  262. package/src/tools/builtins/content-fingerprint.ts +2 -1
  263. package/src/tools/builtins/edit-apply.ts +124 -24
  264. package/src/tools/builtins/edit-match.ts +200 -0
  265. package/src/tools/builtins/edit.ts +16 -7
  266. package/src/tools/builtins/exit-semantics.ts +23 -0
  267. package/src/tools/builtins/index.ts +2 -0
  268. package/src/tools/builtins/present-file.ts +127 -0
  269. package/src/tools/builtins/read-file.ts +1 -1
  270. package/src/tools/builtins/read-render.ts +18 -3
  271. package/src/tools/builtins/search-tools.ts +36 -2
  272. package/src/tools/builtins/wait-for-job.ts +5 -0
  273. package/src/tools/builtins/web.ts +15 -2
  274. package/src/tools/task/create.ts +2 -2
  275. package/src/tools/task/update.ts +1 -1
  276. package/src/types/provider/chat.ts +9 -0
  277. package/src/types/provider/interface.ts +11 -0
  278. package/src/types/provider/model.ts +6 -0
  279. package/src/types/provider/stream.ts +2 -0
  280. package/src/types/tool/presentation.ts +12 -0
  281. package/src/utils/node-on-path.ts +81 -0
@@ -9,6 +9,7 @@ import { cancelCauseOf } from '../../types/session/cancel-cause.js'
9
9
  import type { ToolFacts } from '../../types/tool/presentation.js'
10
10
  import { subscribeToAbort } from '../../utils/abort.js'
11
11
  import { readPositiveIntEnv } from '../../utils/env.js'
12
+ import { withNodeOnPath } from '../../utils/node-on-path.js'
12
13
  import {
13
14
  type CommandShell,
14
15
  WINDOWS_BASH_GUIDANCE,
@@ -31,7 +32,7 @@ import {
31
32
  recordDirectory,
32
33
  withCwdCapture,
33
34
  } from './bash-cwd.js'
34
- import { judgeExit } from './exit-semantics.js'
35
+ import { commandNotFoundHint, judgeExit } from './exit-semantics.js'
35
36
  import { jsonStringEscapes } from './json-string-hint.js'
36
37
  import { creditShellReads } from './shell-read-credit.js'
37
38
  import { leadingLongSleep, longSleepRefusal } from './sleep-guard.js'
@@ -812,6 +813,7 @@ const BashToolBase = defineTool({
812
813
  ? `[${clipped.join(' and ')} was truncated by the sandbox output cap. The omitted output is unavailable in this result. Use a saved artifact or a read-only observation; do not repeat a state-changing action to recover its output.]`
813
814
  : '',
814
815
  result.attribution ? `[${result.attribution.message}]` : '',
816
+ commandNotFoundHint(result.exitCode, result.stderr) ?? '',
815
817
  ]
816
818
  .filter(Boolean)
817
819
  .join('\n\n')
@@ -909,7 +911,7 @@ const BashToolBase = defineTool({
909
911
  {
910
912
  cwd: startDirectory,
911
913
  timeout: input.timeout,
912
- env: { ...inherited.env, ...context.env },
914
+ env: withNodeOnPath({ ...inherited.env, ...context.env }),
913
915
  maxBuffer: DEFAULT_BASH_MAX_BUFFER_BYTES,
914
916
  signal: context.abortSignal,
915
917
  onOutput,
@@ -1024,6 +1026,7 @@ const BashToolBase = defineTool({
1024
1026
  clipped.length > 0
1025
1027
  ? `[${clipped.join(' and ')} ${clipped.length === 1 ? 'was' : 'were'} truncated by the host output cap. The omitted output is unavailable in this result.]`
1026
1028
  : '',
1029
+ commandNotFoundHint(exitCode, failure.stderr ?? '') ?? '',
1027
1030
  ]
1028
1031
  .filter(Boolean)
1029
1032
  .join('\n\n')
@@ -835,7 +835,7 @@ function hostErrorToResult(tool: string, error: BrowserHostError): ToolResult {
835
835
  }
836
836
  return {
837
837
  ...refusal(
838
- `${tool}: ${error.origin || 'the page'} is showing ${what}. Stop here and tell the user; do not sign in, solve it or type a password or code.${how}`,
838
+ `${tool}: ${error.origin || 'the page'} is showing ${what}. Stop here and tell the user; do not sign in, solve it or type a password or code.${how} This browser uses its own Namzu profile, not the user's everyday browser (Brave, Chrome or Edge), so a sign-in they made there is not visible to you; if they ask, say so and that signing in once in the Namzu window is remembered for next time.`,
839
839
  {
840
840
  code: error.code,
841
841
  handoff: { kind: 'human-required', reason: error.reason, detail },
@@ -1039,7 +1039,7 @@ function unavailableLine(caps: BrowserCapabilities): string[] {
1039
1039
 
1040
1040
  function observeDescription(caps: BrowserCapabilities): string {
1041
1041
  return [
1042
- `Drives a web browser${caps.headless ? ' with no visible window' : ''}: open pages and read them. Change pages with browser_act.`,
1042
+ `Drives a web browser${caps.headless ? ' with no visible window' : ''}: open pages that need a real browser (a sign-in, a page drawn by script, a page you must click through) and read them. To read what a public page says, such as an article or documentation, try web_fetch first when you have it. Change pages with browser_act.`,
1043
1043
  'navigate, back, forward and reload return a snapshot of the page when it has something to read, so do not snapshot again straight after. Work from snapshots: "snapshot" returns the page as an accessibility tree, each element with [ref=eN] and, for a control, what it holds (a field\'s text, a select\'s chosen option), under a header "Page: <origin> — <title> (tab tN)". Refs belong to the latest snapshot only; take a new one after the page changes.',
1044
1044
  'A full snapshot of a big page is costly, so read less when you can: snapshot with view "delta" (what changed since the last one), view "interactive" (only what can be clicked or typed into), view "reading" (the page text, for an article), or query and role to find an element by name or text (also reaches content a menu or long page hides). "value" with a ref reads one control\'s current value without a snapshot; "wait_for" with stable waits for a page that is still loading.',
1045
1045
  'A page you wrote inside the work folder opens by its path (navigate url); to check how it looks, open it and take a screenshot.',
@@ -530,6 +530,50 @@ const SCREEN_OBSERVATIONS = new Set<string>([
530
530
  const TERMINAL_APPS =
531
531
  /^(WindowsTerminal|OpenConsole|conhost|cmd|powershell|pwsh|wsl|mintty|wezterm(-gui)?|alacritty|Hyper|Tabby|kitty|ConEmu(64)?|putty|Terminal|iTerm2?|gnome-terminal(-server)?|konsole|xterm|xfce4-terminal|tilix|terminator|foot|ghostty|Warp)$/i
532
532
 
533
+ /**
534
+ * Browser windows, by the process name a host reports in `WindowInfo.app` (on
535
+ * Windows without `.exe`). The tool only looks at these: a page is worked
536
+ * through the browser tool.
537
+ */
538
+ const BROWSER_APPS =
539
+ /^(chrome|google-chrome(-stable|-beta|-unstable)?|chromium(-browser)?|msedge|microsoft-edge(-stable|-beta|-dev)?|firefox(-esr|-bin)?|brave(-browser)?|opera|vivaldi(-stable)?|arc-browser|safari|librewolf|waterfox|zen-browser|navigator|tor browser|iexplore|duckduckgo|yandex-?browser|thorium)$/i
540
+
541
+ /**
542
+ * Editors and development environments, by process name. Like a terminal,
543
+ * the tool may click in these but does not type or press keys in them: the
544
+ * shell and the edit tools do that work without a screen.
545
+ */
546
+ const IDE_APPS =
547
+ /^(code(-insiders|-oss)?|cursor|windsurf|zed|devenv|idea(64)?|pycharm(64)?|webstorm(64)?|goland(64)?|clion(64)?|rider(64)?|phpstorm(64)?|rubymine(64)?|datagrip(64)?|studio64|android-studio|jetbrains-[a-z-]+|sublime_text|subl|atom-editor|eclipse|netbeans(64)?|xcode|nova-editor|vscodium|codium|kate|gedit|vim|gvim|nvim-qt|emacs|lapce|jetbrains-fleet)$/i
548
+
549
+ /** How far the tool works in an application: only looks, looks and clicks, or everything. */
550
+ export type AppTier = 'view' | 'click' | 'full'
551
+
552
+ /** The tier of an application by the name a host reports for its window. */
553
+ export function appTier(app: string): AppTier {
554
+ const name = app
555
+ .trim()
556
+ .replace(/\.exe$/i, '')
557
+ .replace(/^.*[\\/]/, '')
558
+ if (BROWSER_APPS.test(name)) return 'view'
559
+ if (TERMINAL_APPS.test(name) || IDE_APPS.test(name)) return 'click'
560
+ return 'full'
561
+ }
562
+
563
+ /** Keys that only move a page: allowed in a view-only application. */
564
+ const SCROLL_KEYS = /^(page_?up|page_?down|home|end|arrow_?(up|down|left|right)|up|down|space)$/i
565
+
566
+ function onlyScrollKeys(keys: unknown): boolean {
567
+ if (typeof keys !== 'string') return false
568
+ const parts = keys.split(/[\s+]+/).filter(Boolean)
569
+ return parts.length > 0 && parts.every((part) => SCROLL_KEYS.test(part))
570
+ }
571
+
572
+ /** Actions that type: refused in a click-only application. */
573
+ const TYPING_ACTIONS = new Set<string>(['type_text', 'key'])
574
+ /** Actions that press or drive a control: refused in a view-only application too. */
575
+ const POINTING_ACTIONS = new Set<string>(['mouse_click', 'mouse_drag', 'ui_act', 'ui_do'])
576
+
533
577
  /** Actions a batch cannot carry: the ones that return an image or a tree, and batch itself. */
534
578
  const OUTSIDE_BATCH = new Set<string>(['screenshot', 'zoom', 'ui_snapshot', 'wait_for', 'batch'])
535
579
 
@@ -724,6 +768,7 @@ function buildDescription(
724
768
  lines.push(
725
769
  'Coordinates: every x/y you send is a pixel of the most recent screenshot this tool returned — origin at its top-left, x to the right, y down — never a screen pixel. Each screenshot states its id and size (for example "s3: 1456x819"); stay inside it. Display screenshots map onto the display. To aim at an earlier display screenshot, pass its id as screenshot_id.',
726
770
  'Take a screenshot before your first click on pixels.',
771
+ "Look at the screen before you say what state an application is in. Never click links with computer use: a page is the browser tool's. Prefer a connected tool or a command line to the screen when one does the job.",
727
772
  )
728
773
  if (settings.screenshotAfterActions)
729
774
  lines.push(
@@ -755,7 +800,7 @@ function buildDescription(
755
800
  )
756
801
  if (windowCaptureAvailable(host, caps))
757
802
  lines.push(
758
- `When the user names an application or window, ${available.includes('list_windows') ? 'use list_windows then screenshot {window_id}' : 'use screenshot {window_id} with a host-provided window id'} to capture pixels for that window. Its x/y are pixels of that window image; clicks, drags, typing and keys target that window. Window pointer input is sent in the background first. If a click or drag is refused, inspect a fresh image before any other action; where the host can use the screen it may repeat a refused click once on the screen, and the result says so. ${caps.windowScroll === false ? `Window pixel scrolling is unavailable on this host; for a browser page use key PAGE_DOWN or ARROW_DOWN with delivery_mode:"foreground"${hostActionAvailable(caps, 'screenshot') ? ', or deliberately take a display screenshot for display scrolling' : ''}. ` : ''}To type into a browser field, first mouse_click its point in the window image, then type_text with delivery_mode:"foreground" if background text is unavailable. This may briefly bring the verified window to the front: the host waits until the user has been still for a moment, puts their window back afterwards, and reports it as not delivered (safe to try again later) when the screen stays busy. ${host.beginTurn ? 'A result that says the user pressed Escape means stop: end your turn and say what is left undone. ' : ''}For browser shortcuts such as CTRL+L, use key with delivery_mode:"foreground". A stale or moved window is refused; take a fresh window screenshot. ${hostActionAvailable(caps, 'screenshot') ? 'Plain screenshot still shows the display. ' : 'screenshot requires window_id on this host. '}Browser permission bubbles outside the window may be absent. If the window image is blank or shows another window, do not click it; focus the target and capture it again.`,
803
+ `When the user names an application or window, ${available.includes('list_windows') ? 'use list_windows then screenshot {window_id}' : 'use screenshot {window_id} with a host-provided window id'} to capture pixels for that window. Its x/y are pixels of that window image; clicks, drags, typing and keys target that window. Window pointer input is sent in the background first. If a click or drag is refused, inspect a fresh image before any other action; where the host can use the screen it may repeat a refused click once on the screen, and the result says so. ${caps.windowScroll === false ? `Window pixel scrolling is unavailable on this host; ${hostActionAvailable(caps, 'screenshot') ? 'deliberately take a display screenshot for display scrolling' : 'scroll by another means'}. ` : ''}Foreground text may briefly bring the verified window to the front: the host waits until the user has been still for a moment, puts their window back afterwards, and reports it as not delivered (safe to try again later) when the screen stays busy. ${host.beginTurn ? 'A result that says the user pressed Escape means stop: end your turn and say what is left undone. ' : ''}A browser window is only looked at: act on a page with the browser tool. A stale or moved window is refused; take a fresh window screenshot. ${hostActionAvailable(caps, 'screenshot') ? 'Plain screenshot still shows the display. ' : 'screenshot requires window_id on this host. '}Browser permission bubbles outside the window may be absent. If the window image is blank or shows another window, do not click it; focus the target and capture it again.`,
759
804
  )
760
805
  if (available.includes('ui_snapshot'))
761
806
  lines.push(
@@ -1858,7 +1903,7 @@ export function createComputerUseTool(
1858
1903
  )
1859
1904
  if (frame.window && caps.windowScroll === false)
1860
1905
  throw new StepFailure(
1861
- 'window pixel scrolling is unavailable on this host; use foreground PAGE_DOWN or ARROW_DOWN in this window, or take a deliberate display screenshot before display scrolling',
1906
+ 'window pixel scrolling is unavailable on this host; take a deliberate display screenshot before display scrolling, or use the browser tool for a page',
1862
1907
  )
1863
1908
  const at = mapPoint(frame, item.at, 'at')
1864
1909
  return step(() =>
@@ -1883,7 +1928,9 @@ export function createComputerUseTool(
1883
1928
  if (item.delivery_mode && !frame.window)
1884
1929
  throw new StepFailure('type_text delivery_mode requires a window screenshot')
1885
1930
  if (frame.window && TERMINAL_APPS.test(frame.window.window.app))
1886
- throw new StepFailure('computer_use never types into a terminal window')
1931
+ throw new StepFailure(
1932
+ 'computer_use never types into a terminal window; use the shell tool for a command',
1933
+ )
1887
1934
  return step(() =>
1888
1935
  runHost(
1889
1936
  {
@@ -1907,7 +1954,9 @@ export function createComputerUseTool(
1907
1954
  'key delivery_mode requires a window screenshot; take one with screenshot {window_id}',
1908
1955
  )
1909
1956
  if (frame.window && TERMINAL_APPS.test(frame.window.window.app))
1910
- throw new StepFailure('computer_use never sends keys to a terminal window')
1957
+ throw new StepFailure(
1958
+ 'computer_use never sends keys to a terminal window; use the shell tool for a command',
1959
+ )
1911
1960
  return step(() =>
1912
1961
  runHost(
1913
1962
  {
@@ -2390,6 +2439,14 @@ export function createComputerUseTool(
2390
2439
  )
2391
2440
  }
2392
2441
  const front = windows.find((window) => window.focused)
2442
+ if (front && appTier(front.app) === 'view')
2443
+ throw new StepFailure(
2444
+ `a browser is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use only looks at a browser. Use the browser tool to act on a page, or bring the window you mean to the front (focus_window, or click it) and try again`,
2445
+ )
2446
+ if (front && IDE_APPS.test(front.app.trim().replace(/\.exe$/i, '')))
2447
+ throw new StepFailure(
2448
+ `an editor is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use clicks in an editor but does not type there. Use the edit tools for a file and the shell tool for a command, or bring the window you mean to the front (focus_window, or click it) and try again`,
2449
+ )
2393
2450
  if (front && TERMINAL_APPS.test(front.app))
2394
2451
  throw new StepFailure(
2395
2452
  `a terminal is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use never sends keys or text to a terminal. Bring the window you mean to the front (focus_window, or click it) and try again; for a command, use a shell tool instead`,
@@ -3106,6 +3163,66 @@ export function createComputerUseTool(
3106
3163
  return `computer_use does not act in ${applicationName(app)}: the person put it off limits. Nothing was done. Use another application, or tell the person you need it and let them change the list.`
3107
3164
  }
3108
3165
 
3166
+ /**
3167
+ * Why this call may not run because of the kind of application it would act in, or undefined:
3168
+ * a browser window is only looked at, a terminal or an editor is clicked but not typed into.
3169
+ * It places the call from what the tool already knows (a window screenshot, the last window list)
3170
+ * and never reads the host for it: acting must not cost a call it would not make. A call it
3171
+ * cannot place is left to the checks that follow, and a terminal's typing is refused by them.
3172
+ * The person's denied list is checked first and stands on top of this.
3173
+ */
3174
+ const appTierRefusal = async (
3175
+ input: ActionInput,
3176
+ context: ToolContext,
3177
+ ): Promise<string | undefined> => {
3178
+ if (isReadOnlyInput(input)) return undefined
3179
+ // A call with no window of its own is placed by the focused window or by bounds: read a fresh list.
3180
+ const loose0: unknown = input
3181
+ const shot0 =
3182
+ isRecord(loose0) && typeof loose0.screenshot_id === 'string'
3183
+ ? loose0.screenshot_id
3184
+ : undefined
3185
+ const unbound = (batchActions(input) ?? [input]).some((item) => {
3186
+ if (!isRecord(item) || boundWindowId(item) !== undefined) return false
3187
+ if (!TYPING_ACTIONS.has(String(item.type)) && !POINTING_ACTIONS.has(String(item.type)))
3188
+ return false
3189
+ const id = typeof item.screenshot_id === 'string' ? item.screenshot_id : shot0
3190
+ const frame = id ? frames.get(id) : frames.latest()
3191
+ return !frame?.window
3192
+ })
3193
+ if (unbound && typeof host.listWindows === 'function') {
3194
+ try {
3195
+ rememberWindows(await host.listWindows(context.abortSignal))
3196
+ } catch {
3197
+ // The checks that follow read the front window before typing.
3198
+ }
3199
+ }
3200
+ const loose: unknown = input
3201
+ const shotId =
3202
+ isRecord(loose) && typeof loose.screenshot_id === 'string' ? loose.screenshot_id : undefined
3203
+ const withShot = (item: Record<string, unknown>): Record<string, unknown> =>
3204
+ shotId && item.screenshot_id === undefined ? { ...item, screenshot_id: shotId } : item
3205
+ for (const item of batchActions(input) ?? [input]) {
3206
+ if (!isRecord(item)) continue
3207
+ const type = String(item.type)
3208
+ const setsValue =
3209
+ (type === 'ui_act' || type === 'ui_do') &&
3210
+ (item.action === 'set_value' || typeof item.value === 'string')
3211
+ if (!TYPING_ACTIONS.has(type) && !POINTING_ACTIONS.has(type)) continue
3212
+ const placed = appsKnown(withShot(item))
3213
+ for (const app of placed) {
3214
+ const tier = appTier(app)
3215
+ const name = applicationName(app)
3216
+ if (tier === 'view' && type === 'key' && onlyScrollKeys(item.keys)) continue
3217
+ if (tier === 'view')
3218
+ return `computer_use only looks at ${name}, a browser: it does not click, type or press keys there. Use the browser tool to act on a page; take a screenshot to see what the window shows. Nothing was done.`
3219
+ if (tier === 'click' && !TERMINAL_APPS.test(app) && (TYPING_ACTIONS.has(type) || setsValue))
3220
+ return `computer_use clicks in ${name} but does not type or press keys there. Use the shell tool for a command and the edit tools for a file. Nothing was done.`
3221
+ }
3222
+ }
3223
+ return undefined
3224
+ }
3225
+
3109
3226
  const runAction = async (input: ActionInput, context: ToolContext): Promise<ToolResult> => {
3110
3227
  const denied = refusal(input.type)
3111
3228
  if (denied) return { success: false, output: '', error: denied }
@@ -3190,6 +3307,8 @@ export function createComputerUseTool(
3190
3307
  async execute(input, context): Promise<ToolResult> {
3191
3308
  const keptOut = await deniedAppRefusal(input, context)
3192
3309
  if (keptOut) return { success: false, output: '', error: keptOut }
3310
+ const tiered = await appTierRefusal(input, context)
3311
+ if (tiered) return { success: false, output: '', error: tiered }
3193
3312
  const shotId = 'screenshot_id' in input ? input.screenshot_id : undefined
3194
3313
  const before = shotId ? frames.get(shotId) : frames.latest()
3195
3314
  // Only what is already known: acting must not cost the host a call it would not make.
@@ -1,4 +1,5 @@
1
1
  import { createHash } from 'node:crypto'
2
+ import { linePrefix } from './read-render.js'
2
3
 
3
4
  /**
4
5
  * A short, stable fingerprint of a file body.
@@ -50,7 +51,7 @@ export function unreadEditShownError(path: string, content: string): string | un
50
51
  const lines = content.split('\n')
51
52
  if (lines.length > 1 && lines[lines.length - 1] === '') lines.pop()
52
53
  if (lines.length > UNREAD_EDIT_SHOWN_MAX_LINES) return undefined
53
- const numbered = lines.map((line, i) => `${i + 1}\t${line}`).join('\n')
54
+ const numbered = lines.map((line, i) => `${linePrefix(i + 1)}${line}`).join('\n')
54
55
  return `${path} had not been read in this session, so this edit was not applied. It has now been read for you; its current contents follow. Repeat the edit against them, without reading the file again. Nothing was written.\n\n${numbered}`
55
56
  }
56
57
 
@@ -1,4 +1,11 @@
1
- import { reconcileNewString, resolveOldString } from './edit-match.js'
1
+ import {
2
+ describeIndent,
3
+ indentedMatchStarts,
4
+ reconcileNewString,
5
+ resolveIndentedMatch,
6
+ resolveOldString,
7
+ showWhitespace,
8
+ } from './edit-match.js'
2
9
  import type { EditInput } from './edit.js'
3
10
 
4
11
  /**
@@ -156,30 +163,50 @@ export type EditApplyFailure = {
156
163
  export function applyEdit(
157
164
  content: string,
158
165
  operations: readonly NormalizedEditInput[],
159
- ): { success: true; content: string; replacements: number } | EditApplyFailure {
166
+ ): { success: true; content: string; replacements: number; notes: string[] } | EditApplyFailure {
160
167
  let current = content
161
168
  let replacements = 0
162
-
169
+ const notes: string[] = []
170
+ const failures: string[] = []
171
+ let reason: EditApplyFailure['reason']
172
+
173
+ // Every hunk is tried, so one reply names every one that does not apply
174
+ // rather than the first. A failed hunk leaves the content as it was, so
175
+ // the ones after it are judged against the file without it; the write
176
+ // stays all-or-nothing either way.
163
177
  for (const [index, operation] of operations.entries()) {
164
- const result = applyOne(current, operation)
178
+ const result = applyOne(current, operation, index < FULL_EXCERPT_HUNKS)
165
179
  if (!result.success) {
166
- return {
167
- success: false,
168
- error: framedError(result.error, index, operations.length),
169
- ...(result.reason ? { reason: result.reason } : {}),
170
- }
180
+ failures.push(framedFailure(result.error, index, operations.length))
181
+ reason ??= result.reason
182
+ continue
171
183
  }
172
184
  current = result.content
173
185
  replacements += result.replacements
186
+ if (result.note !== undefined) {
187
+ notes.push(operations.length === 1 ? result.note : `edits[${index}]: ${result.note}`)
188
+ }
189
+ }
190
+
191
+ if (failures.length > 0) {
192
+ return {
193
+ success: false,
194
+ error:
195
+ operations.length === 1
196
+ ? (failures[0] as string)
197
+ : `${capBatchError(failures.join('\n'))}\nNothing was written — the whole batch is refused, so the file is exactly as it was.`,
198
+ ...(reason ? { reason } : {}),
199
+ }
174
200
  }
175
201
 
176
- return { success: true, content: current, replacements }
202
+ return { success: true, content: current, replacements, notes }
177
203
  }
178
204
 
179
205
  function applyOne(
180
206
  content: string,
181
207
  input: NormalizedEditInput,
182
- ): { success: true; content: string; replacements: number } | EditApplyFailure {
208
+ fullExcerpt = true,
209
+ ): { success: true; content: string; replacements: number; note?: string } | EditApplyFailure {
183
210
  if (input.operation === 'insert') {
184
211
  return applyLineInsert(content, input)
185
212
  }
@@ -194,22 +221,30 @@ function applyOne(
194
221
  // replacement so it fits where it lands. See `edit-match.ts`.
195
222
  let oldString = replacement.oldString
196
223
  let newString = replacement.newString
224
+ let note: string | undefined
197
225
  if (!content.includes(oldString)) {
198
226
  const resolved = resolveOldString(content, oldString)
199
- if (resolved === null) {
200
- const near = nearLine(content, oldString)
201
- return {
202
- success: false,
203
- reason: 'text_not_found',
204
- error: `old_string/oldStr not found in file. Make sure the string matches exactly, including whitespace and indentation. ${
205
- near === undefined
206
- ? 'Read the lines you mean to change again and copy them as they are.'
207
- : `A line that matches its first line apart from spacing is at line ${near}; read around it again and copy it as it is.`
208
- }`,
227
+ if (resolved !== null) {
228
+ newString = reconcileNewString(oldString, resolved, newString)
229
+ oldString = resolved
230
+ } else {
231
+ // Last resort, and only for one place: the same lines with different
232
+ // leading whitespace. `replace_all` names no single place, so it never
233
+ // takes this road.
234
+ const indented = replacement.replace_all
235
+ ? null
236
+ : resolveIndentedMatch(content, oldString, newString)
237
+ if (indented === null) {
238
+ return {
239
+ success: false,
240
+ reason: 'text_not_found',
241
+ error: notFoundError(content, oldString, fullExcerpt),
242
+ }
209
243
  }
244
+ oldString = indented.span
245
+ newString = indented.newString
246
+ note = INDENT_NOTE
210
247
  }
211
- newString = reconcileNewString(oldString, resolved, newString)
212
- oldString = resolved
213
248
  }
214
249
 
215
250
  // A deletion takes the line's trailing newline with it, so removing a whole
@@ -248,9 +283,68 @@ function applyOne(
248
283
  content:
249
284
  content.slice(0, firstIndex) + newString + content.slice(firstIndex + oldString.length),
250
285
  replacements: 1,
286
+ ...(note === undefined ? {} : { note }),
251
287
  }
252
288
  }
253
289
 
290
+ /** Said once when an edit applied although the indentation of old_string was not the file's. */
291
+ const INDENT_NOTE =
292
+ 'matched with adjusted indentation (old_string was indented differently from the file; new_string was re-indented to fit). Copy leading whitespace as it is after the arrow in read output.'
293
+
294
+ const CONTEXT_LINES = 12
295
+ /** Failing hunks of one batch that get the file's lines; the rest get index, reason and line number. */
296
+ const FULL_EXCERPT_HUNKS = 3
297
+ /** The most characters one batch's failure text may run to. */
298
+ const BATCH_ERROR_MAX_CHARS = 6000
299
+
300
+ function capBatchError(text: string): string {
301
+ if (text.length <= BATCH_ERROR_MAX_CHARS) return text
302
+ return `${text.slice(0, BATCH_ERROR_MAX_CHARS)}…\n(more failing hunks follow; fix these and run again)`
303
+ }
304
+ const CONTEXT_LINE_MAX_CHARS = 160
305
+
306
+ /**
307
+ * The not-found refusal. When a line of the file matches the first line of
308
+ * old_string apart from spacing, the file's own lines there are shown with
309
+ * their whitespace made visible, so the model can copy them without a read.
310
+ */
311
+ function notFoundError(content: string, oldString: string, fullExcerpt = true): string {
312
+ const head =
313
+ 'old_string/oldStr not found in file. Make sure the string matches exactly, including whitespace and indentation.'
314
+ const near = nearLine(content, oldString)
315
+ const starts = indentedMatchStarts(content, oldString)
316
+ if (starts.length > 1) {
317
+ const where = starts
318
+ .slice(0, 5)
319
+ .map((at) => at + 1)
320
+ .join(', ')
321
+ return `${head} Its lines appear in ${starts.length} places once indentation is ignored (starting at lines ${where}), so none was chosen; include more surrounding lines, or copy the indentation of the one you mean exactly.`
322
+ }
323
+ if (near === undefined) {
324
+ return `${head} Read the lines you mean to change again and copy them as they are.`
325
+ }
326
+ if (!fullExcerpt) {
327
+ return `${head} A line that matches its first line apart from spacing is at line ${near}; read around it and copy it as it is.`
328
+ }
329
+ const lines = content.split('\n')
330
+ const wanted = oldString.split('\n')
331
+ const firstWanted = wanted.find((line) => line.trim() !== '') ?? ''
332
+ const count = Math.min(Math.max(wanted.length, 3) + 1, CONTEXT_LINES)
333
+ const from = Math.max(1, near - 1)
334
+ const to = Math.min(lines.length, near - 1 + count)
335
+ const shown: string[] = []
336
+ for (let n = from; n <= to; n++) {
337
+ // The empty piece after a final newline is not a line of the file.
338
+ if (n === lines.length && lines[n - 1] === '') break
339
+ const raw = (lines[n - 1] ?? '').replace(/\r$/, '')
340
+ const visible = showWhitespace(raw)
341
+ shown.push(
342
+ `${String(n).padStart(6)}| ${visible.length > CONTEXT_LINE_MAX_CHARS ? `${visible.slice(0, CONTEXT_LINE_MAX_CHARS)}…` : visible}`,
343
+ )
344
+ }
345
+ return `${head} A line that matches its first line apart from spacing is at line ${near}: the file has ${describeIndent(lines[near - 1] ?? '')} there, your old_string has ${describeIndent(firstWanted)}. The file's lines, with → for a tab and · for a space (the numbers and | are not part of the file):\n${shown.join('\n')}\nCopy the text after the | exactly, turning → back into a tab and · into a space.`
346
+ }
347
+
254
348
  const NEAR_LINE_MIN_CHARS = 8
255
349
 
256
350
  /** The line of `content` that matches the first non-blank line of `needle` apart from spacing, 1-based. */
@@ -336,7 +430,13 @@ function normalizeLineEndings(
336
430
  /** The batch framing an operation's own error is reported under. */
337
431
  function framedError(error: string, index: number, total: number): string {
338
432
  if (total === 1) return error
339
- return `edits[${index}] of ${total}: ${error} Nothing was written — the whole batch is refused, so the file is exactly as it was.`
433
+ return `${framedFailure(error, index, total)} Nothing was written — the whole batch is refused, so the file is exactly as it was.`
434
+ }
435
+
436
+ /** One failing hunk of a batch, named by its index. */
437
+ function framedFailure(error: string, index: number, total: number): string {
438
+ if (total === 1) return error
439
+ return `edits[${index}] of ${total}: ${error}`
340
440
  }
341
441
 
342
442
  /**