@namzu/sdk 68.0.1 → 69.1.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 (492) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/authorization/skill-grant.d.ts.map +1 -1
  6. package/dist/authorization/skill-grant.js +1 -0
  7. package/dist/authorization/skill-grant.js.map +1 -1
  8. package/dist/bridge/acp/permission.d.ts +10 -0
  9. package/dist/bridge/acp/permission.d.ts.map +1 -1
  10. package/dist/bridge/acp/permission.js.map +1 -1
  11. package/dist/bridge/acp/server.d.ts +12 -0
  12. package/dist/bridge/acp/server.d.ts.map +1 -1
  13. package/dist/bridge/acp/server.js +21 -0
  14. package/dist/bridge/acp/server.js.map +1 -1
  15. package/dist/compaction/context-window.d.ts +8 -0
  16. package/dist/compaction/context-window.d.ts.map +1 -1
  17. package/dist/compaction/context-window.js +14 -0
  18. package/dist/compaction/context-window.js.map +1 -1
  19. package/dist/compaction/loaded-skills.d.ts +10 -0
  20. package/dist/compaction/loaded-skills.d.ts.map +1 -1
  21. package/dist/compaction/loaded-skills.js +45 -1
  22. package/dist/compaction/loaded-skills.js.map +1 -1
  23. package/dist/compaction/manager.d.ts +8 -0
  24. package/dist/compaction/manager.d.ts.map +1 -1
  25. package/dist/compaction/manager.js +31 -0
  26. package/dist/compaction/manager.js.map +1 -1
  27. package/dist/compaction/manual.d.ts.map +1 -1
  28. package/dist/compaction/manual.js +7 -1
  29. package/dist/compaction/manual.js.map +1 -1
  30. package/dist/compaction/model-summary.js +2 -2
  31. package/dist/compaction/model-summary.js.map +1 -1
  32. package/dist/compaction/restore.d.ts +8 -0
  33. package/dist/compaction/restore.d.ts.map +1 -1
  34. package/dist/compaction/restore.js +65 -0
  35. package/dist/compaction/restore.js.map +1 -1
  36. package/dist/compaction/salience/working-set.d.ts.map +1 -1
  37. package/dist/compaction/salience/working-set.js +2 -2
  38. package/dist/compaction/salience/working-set.js.map +1 -1
  39. package/dist/compaction/tool-result-editing.d.ts +6 -0
  40. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  41. package/dist/compaction/tool-result-editing.js +7 -1
  42. package/dist/compaction/tool-result-editing.js.map +1 -1
  43. package/dist/compaction/types.d.ts +2 -0
  44. package/dist/compaction/types.d.ts.map +1 -1
  45. package/dist/compaction/wire.d.ts.map +1 -1
  46. package/dist/compaction/wire.js +4 -0
  47. package/dist/compaction/wire.js.map +1 -1
  48. package/dist/connector/index.d.ts +2 -2
  49. package/dist/connector/index.d.ts.map +1 -1
  50. package/dist/connector/index.js +1 -1
  51. package/dist/connector/index.js.map +1 -1
  52. package/dist/connector/mcp/client.d.ts +29 -0
  53. package/dist/connector/mcp/client.d.ts.map +1 -1
  54. package/dist/connector/mcp/client.js +59 -2
  55. package/dist/connector/mcp/client.js.map +1 -1
  56. package/dist/connector/mcp/errors.d.ts +7 -0
  57. package/dist/connector/mcp/errors.d.ts.map +1 -1
  58. package/dist/connector/mcp/errors.js +14 -0
  59. package/dist/connector/mcp/errors.js.map +1 -1
  60. package/dist/connector/mcp/index.d.ts +5 -1
  61. package/dist/connector/mcp/index.d.ts.map +1 -1
  62. package/dist/connector/mcp/index.js +3 -1
  63. package/dist/connector/mcp/index.js.map +1 -1
  64. package/dist/connector/mcp/skill-source.d.ts +144 -0
  65. package/dist/connector/mcp/skill-source.d.ts.map +1 -0
  66. package/dist/connector/mcp/skill-source.js +375 -0
  67. package/dist/connector/mcp/skill-source.js.map +1 -0
  68. package/dist/connector/mcp/skills.d.ts +137 -0
  69. package/dist/connector/mcp/skills.d.ts.map +1 -0
  70. package/dist/connector/mcp/skills.js +303 -0
  71. package/dist/connector/mcp/skills.js.map +1 -0
  72. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  73. package/dist/manager/session/turn-recorder.js +23 -1
  74. package/dist/manager/session/turn-recorder.js.map +1 -1
  75. package/dist/network/audit.d.ts +1 -1
  76. package/dist/network/audit.d.ts.map +1 -1
  77. package/dist/network/audit.js +2 -0
  78. package/dist/network/audit.js.map +1 -1
  79. package/dist/network/computer.d.ts +107 -0
  80. package/dist/network/computer.d.ts.map +1 -0
  81. package/dist/network/computer.js +250 -0
  82. package/dist/network/computer.js.map +1 -0
  83. package/dist/network/index.d.ts +2 -0
  84. package/dist/network/index.d.ts.map +1 -1
  85. package/dist/network/index.js +1 -0
  86. package/dist/network/index.js.map +1 -1
  87. package/dist/network/join.d.ts +13 -1
  88. package/dist/network/join.d.ts.map +1 -1
  89. package/dist/network/join.js +21 -3
  90. package/dist/network/join.js.map +1 -1
  91. package/dist/network/roster.d.ts +5 -0
  92. package/dist/network/roster.d.ts.map +1 -1
  93. package/dist/network/roster.js.map +1 -1
  94. package/dist/network/service.d.ts +12 -2
  95. package/dist/network/service.d.ts.map +1 -1
  96. package/dist/network/service.js +539 -60
  97. package/dist/network/service.js.map +1 -1
  98. package/dist/network/store.d.ts +33 -1
  99. package/dist/network/store.d.ts.map +1 -1
  100. package/dist/network/store.js +48 -4
  101. package/dist/network/store.js.map +1 -1
  102. package/dist/network/transport.d.ts +1 -1
  103. package/dist/network/transport.js +1 -1
  104. package/dist/network/wire.d.ts +14 -0
  105. package/dist/network/wire.d.ts.map +1 -1
  106. package/dist/network/wire.js +17 -1
  107. package/dist/network/wire.js.map +1 -1
  108. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  109. package/dist/plugin/shell-hook-tool-names.js +1 -0
  110. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  111. package/dist/plugin/shell-hook.d.ts +8 -3
  112. package/dist/plugin/shell-hook.d.ts.map +1 -1
  113. package/dist/plugin/shell-hook.js +132 -7
  114. package/dist/plugin/shell-hook.js.map +1 -1
  115. package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
  116. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  117. package/dist/prompt/coding-agent-doctrine.js +7 -2
  118. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  119. package/dist/provider/fallback.d.ts.map +1 -1
  120. package/dist/provider/fallback.js +9 -0
  121. package/dist/provider/fallback.js.map +1 -1
  122. package/dist/provider/idle-timeout.d.ts.map +1 -1
  123. package/dist/provider/idle-timeout.js +8 -0
  124. package/dist/provider/idle-timeout.js.map +1 -1
  125. package/dist/provider/instrumentation.d.ts.map +1 -1
  126. package/dist/provider/instrumentation.js +10 -0
  127. package/dist/provider/instrumentation.js.map +1 -1
  128. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  129. package/dist/provider/model-window-suffix.js +2 -0
  130. package/dist/provider/model-window-suffix.js.map +1 -1
  131. package/dist/provider/retry.d.ts.map +1 -1
  132. package/dist/provider/retry.js +8 -0
  133. package/dist/provider/retry.js.map +1 -1
  134. package/dist/public-runtime.d.ts +10 -7
  135. package/dist/public-runtime.d.ts.map +1 -1
  136. package/dist/public-runtime.js +12 -5
  137. package/dist/public-runtime.js.map +1 -1
  138. package/dist/public-tools.d.ts +7 -4
  139. package/dist/public-tools.d.ts.map +1 -1
  140. package/dist/public-tools.js +9 -3
  141. package/dist/public-tools.js.map +1 -1
  142. package/dist/public-types.d.ts +4 -1
  143. package/dist/public-types.d.ts.map +1 -1
  144. package/dist/registry/tool/presentation.d.ts +8 -1
  145. package/dist/registry/tool/presentation.d.ts.map +1 -1
  146. package/dist/registry/tool/presentation.js +14 -5
  147. package/dist/registry/tool/presentation.js.map +1 -1
  148. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  149. package/dist/runtime/jobs/registry.js +2 -1
  150. package/dist/runtime/jobs/registry.js.map +1 -1
  151. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  152. package/dist/runtime/query/auto-review/classifier.js +19 -3
  153. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  154. package/dist/runtime/query/auto-review/failure.d.ts +12 -0
  155. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
  156. package/dist/runtime/query/auto-review/failure.js +46 -0
  157. package/dist/runtime/query/auto-review/failure.js.map +1 -0
  158. package/dist/runtime/query/auto-review/index.d.ts +1 -0
  159. package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
  160. package/dist/runtime/query/auto-review/index.js +1 -0
  161. package/dist/runtime/query/auto-review/index.js.map +1 -1
  162. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  163. package/dist/runtime/query/executor/tool-call-admission.js +10 -1
  164. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  165. package/dist/runtime/query/executor.d.ts +12 -0
  166. package/dist/runtime/query/executor.d.ts.map +1 -1
  167. package/dist/runtime/query/executor.js +43 -9
  168. package/dist/runtime/query/executor.js.map +1 -1
  169. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  170. package/dist/runtime/query/file-evidence-replay.js +6 -6
  171. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  172. package/dist/runtime/query/index.d.ts +4 -0
  173. package/dist/runtime/query/index.d.ts.map +1 -1
  174. package/dist/runtime/query/index.js +40 -1
  175. package/dist/runtime/query/index.js.map +1 -1
  176. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  177. package/dist/runtime/query/iteration/index.js +2 -0
  178. package/dist/runtime/query/iteration/index.js.map +1 -1
  179. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  180. package/dist/runtime/query/iteration/phases/compaction.js +21 -3
  181. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  182. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  183. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  184. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  185. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -2
  186. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  187. package/dist/runtime/query/iteration/phases/per-call-review.js +24 -9
  188. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  189. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  190. package/dist/runtime/query/iteration/step-shaping.js +4 -0
  191. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  192. package/dist/runtime/query/prepare-turn.d.ts +5 -1
  193. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  194. package/dist/runtime/query/prepare-turn.js +13 -3
  195. package/dist/runtime/query/prepare-turn.js.map +1 -1
  196. package/dist/runtime/query/review-policy.d.ts +15 -4
  197. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  198. package/dist/runtime/query/review-policy.js +15 -4
  199. package/dist/runtime/query/review-policy.js.map +1 -1
  200. package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
  201. package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
  202. package/dist/runtime/query/shell-line-escalation.js +38 -0
  203. package/dist/runtime/query/shell-line-escalation.js.map +1 -0
  204. package/dist/runtime/query/tooling.d.ts +7 -0
  205. package/dist/runtime/query/tooling.d.ts.map +1 -1
  206. package/dist/runtime/query/tooling.js +2 -0
  207. package/dist/runtime/query/tooling.js.map +1 -1
  208. package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
  209. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  210. package/dist/runtime/query/turn/outcome-ledger.js +47 -1
  211. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  212. package/dist/sandbox/provider/local.d.ts.map +1 -1
  213. package/dist/sandbox/provider/local.js +3 -1
  214. package/dist/sandbox/provider/local.js.map +1 -1
  215. package/dist/scheduler/local.d.ts.map +1 -1
  216. package/dist/scheduler/local.js +3 -1
  217. package/dist/scheduler/local.js.map +1 -1
  218. package/dist/skills/index.d.ts +4 -0
  219. package/dist/skills/index.d.ts.map +1 -1
  220. package/dist/skills/index.js +2 -0
  221. package/dist/skills/index.js.map +1 -1
  222. package/dist/skills/inline-shell-host.d.ts +103 -0
  223. package/dist/skills/inline-shell-host.d.ts.map +1 -0
  224. package/dist/skills/inline-shell-host.js +238 -0
  225. package/dist/skills/inline-shell-host.js.map +1 -0
  226. package/dist/skills/inline-shell.d.ts +176 -0
  227. package/dist/skills/inline-shell.d.ts.map +1 -0
  228. package/dist/skills/inline-shell.js +646 -0
  229. package/dist/skills/inline-shell.js.map +1 -0
  230. package/dist/store/index.d.ts +2 -0
  231. package/dist/store/index.d.ts.map +1 -1
  232. package/dist/store/index.js +1 -0
  233. package/dist/store/index.js.map +1 -1
  234. package/dist/store/task/file.d.ts +124 -0
  235. package/dist/store/task/file.d.ts.map +1 -0
  236. package/dist/store/task/file.js +498 -0
  237. package/dist/store/task/file.js.map +1 -0
  238. package/dist/teams/backend.d.ts +28 -0
  239. package/dist/teams/backend.d.ts.map +1 -0
  240. package/dist/teams/backend.js +2 -0
  241. package/dist/teams/backend.js.map +1 -0
  242. package/dist/teams/fs-sync.d.ts +19 -0
  243. package/dist/teams/fs-sync.d.ts.map +1 -0
  244. package/dist/teams/fs-sync.js +81 -0
  245. package/dist/teams/fs-sync.js.map +1 -0
  246. package/dist/teams/index.d.ts +14 -0
  247. package/dist/teams/index.d.ts.map +1 -0
  248. package/dist/teams/index.js +11 -0
  249. package/dist/teams/index.js.map +1 -0
  250. package/dist/teams/names.d.ts +15 -0
  251. package/dist/teams/names.d.ts.map +1 -0
  252. package/dist/teams/names.js +43 -0
  253. package/dist/teams/names.js.map +1 -0
  254. package/dist/teams/store.d.ts +133 -0
  255. package/dist/teams/store.d.ts.map +1 -0
  256. package/dist/teams/store.js +536 -0
  257. package/dist/teams/store.js.map +1 -0
  258. package/dist/teams/types.d.ts +97 -0
  259. package/dist/teams/types.d.ts.map +1 -0
  260. package/dist/teams/types.js +70 -0
  261. package/dist/teams/types.js.map +1 -0
  262. package/dist/tools/admit-facts.d.ts.map +1 -1
  263. package/dist/tools/admit-facts.js +28 -0
  264. package/dist/tools/admit-facts.js.map +1 -1
  265. package/dist/tools/builtins/bash.d.ts.map +1 -1
  266. package/dist/tools/builtins/bash.js +5 -2
  267. package/dist/tools/builtins/bash.js.map +1 -1
  268. package/dist/tools/builtins/browser.js +1 -1
  269. package/dist/tools/builtins/browser.js.map +1 -1
  270. package/dist/tools/builtins/computer-use.d.ts +60 -2
  271. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  272. package/dist/tools/builtins/computer-use.js +695 -80
  273. package/dist/tools/builtins/computer-use.js.map +1 -1
  274. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  275. package/dist/tools/builtins/content-fingerprint.js +2 -1
  276. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  277. package/dist/tools/builtins/edit-apply.d.ts +1 -0
  278. package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
  279. package/dist/tools/builtins/edit-apply.js +108 -21
  280. package/dist/tools/builtins/edit-apply.js.map +1 -1
  281. package/dist/tools/builtins/edit-match.d.ts +37 -0
  282. package/dist/tools/builtins/edit-match.d.ts.map +1 -1
  283. package/dist/tools/builtins/edit-match.js +193 -0
  284. package/dist/tools/builtins/edit-match.js.map +1 -1
  285. package/dist/tools/builtins/edit.d.ts.map +1 -1
  286. package/dist/tools/builtins/edit.js +14 -7
  287. package/dist/tools/builtins/edit.js.map +1 -1
  288. package/dist/tools/builtins/exit-semantics.d.ts +8 -0
  289. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  290. package/dist/tools/builtins/exit-semantics.js +19 -0
  291. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  292. package/dist/tools/builtins/index.d.ts +3 -1
  293. package/dist/tools/builtins/index.d.ts.map +1 -1
  294. package/dist/tools/builtins/index.js +1 -0
  295. package/dist/tools/builtins/index.js.map +1 -1
  296. package/dist/tools/builtins/present-file.d.ts +24 -0
  297. package/dist/tools/builtins/present-file.d.ts.map +1 -0
  298. package/dist/tools/builtins/present-file.js +116 -0
  299. package/dist/tools/builtins/present-file.js.map +1 -0
  300. package/dist/tools/builtins/read-file.js +1 -1
  301. package/dist/tools/builtins/read-file.js.map +1 -1
  302. package/dist/tools/builtins/read-render.d.ts +12 -1
  303. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  304. package/dist/tools/builtins/read-render.js +16 -3
  305. package/dist/tools/builtins/read-render.js.map +1 -1
  306. package/dist/tools/builtins/search-tools.d.ts +10 -0
  307. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  308. package/dist/tools/builtins/search-tools.js +36 -2
  309. package/dist/tools/builtins/search-tools.js.map +1 -1
  310. package/dist/tools/builtins/skill.d.ts +31 -0
  311. package/dist/tools/builtins/skill.d.ts.map +1 -1
  312. package/dist/tools/builtins/skill.js +232 -88
  313. package/dist/tools/builtins/skill.js.map +1 -1
  314. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  315. package/dist/tools/builtins/wait-for-job.js +5 -0
  316. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  317. package/dist/tools/builtins/web.d.ts.map +1 -1
  318. package/dist/tools/builtins/web.js +13 -2
  319. package/dist/tools/builtins/web.js.map +1 -1
  320. package/dist/tools/task/create.d.ts.map +1 -1
  321. package/dist/tools/task/create.js +13 -4
  322. package/dist/tools/task/create.js.map +1 -1
  323. package/dist/tools/task/get.d.ts +8 -0
  324. package/dist/tools/task/get.d.ts.map +1 -0
  325. package/dist/tools/task/get.js +51 -0
  326. package/dist/tools/task/get.js.map +1 -0
  327. package/dist/tools/task/index.d.ts +7 -0
  328. package/dist/tools/task/index.d.ts.map +1 -1
  329. package/dist/tools/task/index.js +10 -2
  330. package/dist/tools/task/index.js.map +1 -1
  331. package/dist/tools/task/list.d.ts.map +1 -1
  332. package/dist/tools/task/list.js +10 -2
  333. package/dist/tools/task/list.js.map +1 -1
  334. package/dist/tools/task/number.d.ts +13 -0
  335. package/dist/tools/task/number.d.ts.map +1 -0
  336. package/dist/tools/task/number.js +30 -0
  337. package/dist/tools/task/number.js.map +1 -0
  338. package/dist/tools/task/present.d.ts.map +1 -1
  339. package/dist/tools/task/present.js +17 -3
  340. package/dist/tools/task/present.js.map +1 -1
  341. package/dist/tools/task/update.d.ts +2 -1
  342. package/dist/tools/task/update.d.ts.map +1 -1
  343. package/dist/tools/task/update.js +87 -20
  344. package/dist/tools/task/update.js.map +1 -1
  345. package/dist/types/acp/index.d.ts +10 -0
  346. package/dist/types/acp/index.d.ts.map +1 -1
  347. package/dist/types/agent/base.d.ts +4 -0
  348. package/dist/types/agent/base.d.ts.map +1 -1
  349. package/dist/types/agent/scheduler.d.ts +9 -0
  350. package/dist/types/agent/scheduler.d.ts.map +1 -1
  351. package/dist/types/computer-use/index.d.ts +7 -0
  352. package/dist/types/computer-use/index.d.ts.map +1 -1
  353. package/dist/types/computer-use/index.js.map +1 -1
  354. package/dist/types/connector/mcp.d.ts +10 -0
  355. package/dist/types/connector/mcp.d.ts.map +1 -1
  356. package/dist/types/permission/index.d.ts +20 -0
  357. package/dist/types/permission/index.d.ts.map +1 -1
  358. package/dist/types/permission/index.js +25 -0
  359. package/dist/types/permission/index.js.map +1 -1
  360. package/dist/types/plugin/index.d.ts +47 -3
  361. package/dist/types/plugin/index.d.ts.map +1 -1
  362. package/dist/types/plugin/index.js +4 -0
  363. package/dist/types/plugin/index.js.map +1 -1
  364. package/dist/types/provider/chat.d.ts +8 -0
  365. package/dist/types/provider/chat.d.ts.map +1 -1
  366. package/dist/types/provider/interface.d.ts +16 -0
  367. package/dist/types/provider/interface.d.ts.map +1 -1
  368. package/dist/types/provider/model.d.ts +6 -0
  369. package/dist/types/provider/model.d.ts.map +1 -1
  370. package/dist/types/provider/stream.d.ts +2 -0
  371. package/dist/types/provider/stream.d.ts.map +1 -1
  372. package/dist/types/tool/index.d.ts +28 -2
  373. package/dist/types/tool/index.d.ts.map +1 -1
  374. package/dist/types/tool/index.js.map +1 -1
  375. package/dist/types/tool/presentation.d.ts +15 -0
  376. package/dist/types/tool/presentation.d.ts.map +1 -1
  377. package/dist/utils/node-on-path.d.ts +27 -0
  378. package/dist/utils/node-on-path.d.ts.map +1 -0
  379. package/dist/utils/node-on-path.js +70 -0
  380. package/dist/utils/node-on-path.js.map +1 -0
  381. package/package.json +1 -1
  382. package/src/agents/QueryAgent.ts +2 -0
  383. package/src/authorization/skill-grant.ts +1 -0
  384. package/src/bridge/acp/permission.ts +11 -1
  385. package/src/bridge/acp/server.ts +26 -0
  386. package/src/compaction/context-window.ts +18 -0
  387. package/src/compaction/loaded-skills.ts +42 -1
  388. package/src/compaction/manager.ts +28 -0
  389. package/src/compaction/manual.ts +9 -1
  390. package/src/compaction/model-summary.ts +2 -2
  391. package/src/compaction/restore.ts +69 -0
  392. package/src/compaction/salience/working-set.ts +6 -2
  393. package/src/compaction/tool-result-editing.ts +8 -1
  394. package/src/compaction/types.ts +2 -0
  395. package/src/compaction/wire.ts +4 -0
  396. package/src/connector/index.ts +27 -0
  397. package/src/connector/mcp/client.ts +71 -2
  398. package/src/connector/mcp/errors.ts +14 -0
  399. package/src/connector/mcp/index.ts +36 -0
  400. package/src/connector/mcp/skill-source.ts +499 -0
  401. package/src/connector/mcp/skills.ts +367 -0
  402. package/src/manager/session/turn-recorder.ts +24 -1
  403. package/src/network/audit.ts +2 -0
  404. package/src/network/computer.ts +347 -0
  405. package/src/network/index.ts +20 -0
  406. package/src/network/join.ts +21 -2
  407. package/src/network/roster.ts +5 -0
  408. package/src/network/service.ts +674 -84
  409. package/src/network/store.ts +57 -4
  410. package/src/network/transport.ts +1 -1
  411. package/src/network/wire.ts +18 -1
  412. package/src/plugin/shell-hook-tool-names.ts +1 -0
  413. package/src/plugin/shell-hook.ts +144 -7
  414. package/src/prompt/coding-agent-doctrine.ts +7 -2
  415. package/src/provider/fallback.ts +10 -0
  416. package/src/provider/idle-timeout.ts +9 -0
  417. package/src/provider/instrumentation.ts +12 -0
  418. package/src/provider/model-window-suffix.ts +2 -0
  419. package/src/provider/retry.ts +9 -0
  420. package/src/public-runtime.ts +100 -0
  421. package/src/public-tools.ts +18 -0
  422. package/src/public-types.ts +29 -0
  423. package/src/registry/tool/presentation.ts +14 -4
  424. package/src/runtime/jobs/registry.ts +2 -1
  425. package/src/runtime/query/auto-review/classifier.ts +19 -3
  426. package/src/runtime/query/auto-review/failure.ts +50 -0
  427. package/src/runtime/query/auto-review/index.ts +1 -0
  428. package/src/runtime/query/executor/tool-call-admission.ts +10 -1
  429. package/src/runtime/query/executor.ts +57 -8
  430. package/src/runtime/query/file-evidence-replay.ts +6 -5
  431. package/src/runtime/query/index.ts +62 -0
  432. package/src/runtime/query/iteration/index.ts +2 -0
  433. package/src/runtime/query/iteration/phases/compaction.ts +25 -2
  434. package/src/runtime/query/iteration/phases/context.ts +4 -0
  435. package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
  436. package/src/runtime/query/iteration/step-shaping.ts +4 -0
  437. package/src/runtime/query/prepare-turn.ts +20 -2
  438. package/src/runtime/query/review-policy.ts +31 -5
  439. package/src/runtime/query/shell-line-escalation.ts +49 -0
  440. package/src/runtime/query/tooling.ts +6 -0
  441. package/src/runtime/query/turn/outcome-ledger.ts +56 -1
  442. package/src/sandbox/provider/local.ts +3 -1
  443. package/src/scheduler/local.ts +3 -1
  444. package/src/skills/index.ts +43 -0
  445. package/src/skills/inline-shell-host.ts +303 -0
  446. package/src/skills/inline-shell.ts +765 -0
  447. package/src/store/index.ts +8 -0
  448. package/src/store/task/file.ts +641 -0
  449. package/src/teams/backend.ts +29 -0
  450. package/src/teams/fs-sync.ts +91 -0
  451. package/src/teams/index.ts +47 -0
  452. package/src/teams/names.ts +49 -0
  453. package/src/teams/store.ts +607 -0
  454. package/src/teams/types.ts +102 -0
  455. package/src/tools/admit-facts.ts +26 -0
  456. package/src/tools/builtins/bash.ts +5 -2
  457. package/src/tools/builtins/browser.ts +1 -1
  458. package/src/tools/builtins/computer-use.ts +799 -86
  459. package/src/tools/builtins/content-fingerprint.ts +2 -1
  460. package/src/tools/builtins/edit-apply.ts +124 -24
  461. package/src/tools/builtins/edit-match.ts +200 -0
  462. package/src/tools/builtins/edit.ts +16 -7
  463. package/src/tools/builtins/exit-semantics.ts +23 -0
  464. package/src/tools/builtins/index.ts +3 -0
  465. package/src/tools/builtins/present-file.ts +127 -0
  466. package/src/tools/builtins/read-file.ts +1 -1
  467. package/src/tools/builtins/read-render.ts +18 -3
  468. package/src/tools/builtins/search-tools.ts +36 -2
  469. package/src/tools/builtins/skill.ts +291 -95
  470. package/src/tools/builtins/wait-for-job.ts +5 -0
  471. package/src/tools/builtins/web.ts +15 -2
  472. package/src/tools/task/create.ts +13 -4
  473. package/src/tools/task/get.ts +53 -0
  474. package/src/tools/task/index.ts +14 -2
  475. package/src/tools/task/list.ts +10 -2
  476. package/src/tools/task/number.ts +32 -0
  477. package/src/tools/task/present.ts +18 -3
  478. package/src/tools/task/update.ts +94 -20
  479. package/src/types/acp/index.ts +11 -1
  480. package/src/types/agent/base.ts +6 -0
  481. package/src/types/agent/scheduler.ts +9 -0
  482. package/src/types/computer-use/index.ts +7 -0
  483. package/src/types/connector/mcp.ts +10 -0
  484. package/src/types/permission/index.ts +29 -0
  485. package/src/types/plugin/index.ts +95 -39
  486. package/src/types/provider/chat.ts +9 -0
  487. package/src/types/provider/interface.ts +18 -0
  488. package/src/types/provider/model.ts +6 -0
  489. package/src/types/provider/stream.ts +2 -0
  490. package/src/types/tool/index.ts +23 -2
  491. package/src/types/tool/presentation.ts +14 -0
  492. package/src/utils/node-on-path.ts +81 -0
@@ -1,3 +1,4 @@
1
+ import { createHash } from 'node:crypto'
1
2
  import { z } from 'zod'
2
3
  import { modelReadsImages, resolveProviderCapabilities } from '../../provider/capabilities.js'
3
4
  import type {
@@ -38,6 +39,7 @@ import {
38
39
  } from './computer-use-coordinates.js'
39
40
  import {
40
41
  type FittedImage,
42
+ HIGH_RES_SCREENSHOT_LIMITS,
41
43
  STANDARD_SCREENSHOT_LIMITS,
42
44
  type ScreenshotLimits,
43
45
  cropAndFitPng,
@@ -53,6 +55,26 @@ export {
53
55
  } from './computer-use-image.js'
54
56
  export type { ImageSize, ScreenshotLimits } from './computer-use-image.js'
55
57
 
58
+ /**
59
+ * The limits to fit a screenshot to for `model`: the high-resolution tier for
60
+ * a model known to read it (the 4.7 and later models of the vendor behind that
61
+ * tier, with or without a vendor prefix or a dated suffix), the standard tier for every
62
+ * other model, including one the table does not know. A wrong "high" costs a
63
+ * rejected tool result; a wrong "standard" only costs detail, so an unknown
64
+ * model gets the standard tier.
65
+ */
66
+ export function screenshotLimitsForModel(model: string | undefined): ScreenshotLimits {
67
+ if (model === undefined) return STANDARD_SCREENSHOT_LIMITS
68
+ const match = /claude-(?:opus|sonnet|haiku|fable)-(\d+)(?:[-.](\d{1,2})(?!\d))?/i.exec(model)
69
+ if (!match) return STANDARD_SCREENSHOT_LIMITS
70
+ const major = Number(match[1])
71
+ const minor = match[2] === undefined ? 0 : Number(match[2])
72
+ // A dated id such as `claude-sonnet-4-20250514` has no minor: the date is not one.
73
+ return major > 4 || (major === 4 && minor >= 7)
74
+ ? HIGH_RES_SCREENSHOT_LIMITS
75
+ : STANDARD_SCREENSHOT_LIMITS
76
+ }
77
+
56
78
  export const COMPUTER_USE_TOOL_NAME = 'computer_use' as const
57
79
 
58
80
  const DEFAULT_SETTLE_MS = 500
@@ -87,8 +109,12 @@ async function settleAfterActions(
87
109
  await sleep(settleMs, signal)
88
110
  }
89
111
  const MAX_LISTED_WINDOWS = 50
90
- /** The most of a ui_snapshot the model is shown, in characters (about 4 000 tokens). */
91
- const MAX_UI_SNAPSHOT_CHARS = 14_000
112
+ /** Steps after which a batch may end with the window's controls instead of a picture. */
113
+ const TREE_ENDING_STEPS: ReadonlySet<string> = new Set(['ui_act', 'ui_do', 'type_text', 'key'])
114
+ /** Steps that aim at a pixel of a screenshot. */
115
+ const PIXEL_STEPS: ReadonlySet<string> = new Set(['mouse_click', 'mouse_drag', 'scroll'])
116
+ /** The most of a ui_snapshot the model is shown, in characters (about 7 000 tokens). */
117
+ const MAX_UI_SNAPSHOT_CHARS = 24_000
92
118
  /** The refs of earlier snapshots the tool still resolves for the host. */
93
119
  const MAX_HELD_UI_REFS = 4_000
94
120
 
@@ -162,9 +188,11 @@ export interface ComputerUseToolOptions {
162
188
  * What every screenshot and zoom image is fitted to before the model sees
163
189
  * it. Default {@link STANDARD_SCREENSHOT_LIMITS}, which every current vision
164
190
  * model takes without a further resize; {@link HIGH_RES_SCREENSHOT_LIMITS}
165
- * only when every model the session can reach is on that tier.
191
+ * only when every model the session can reach is on that tier. A function
192
+ * is asked before every capture, for a session whose model changes between
193
+ * turns; see {@link screenshotLimitsForModel}.
166
194
  */
167
- readonly screenshotLimits?: ScreenshotLimits
195
+ readonly screenshotLimits?: ScreenshotLimits | (() => ScreenshotLimits)
168
196
  /**
169
197
  * Milliseconds to wait after an action before the screenshot it returns,
170
198
  * so a menu has opened or a page has started to paint. Default 500.
@@ -207,6 +235,62 @@ export interface ComputerUseToolOptions {
207
235
  * tell where it would land. Absent or empty: no application is off limits.
208
236
  */
209
237
  readonly deniedApps?: readonly string[]
238
+ /**
239
+ * What the tool does in a browser window (`computerUse.browserWindows`). `look`, the default
240
+ * here, only looks: a page is the browser tool's. `act` clicks and types there like in any other
241
+ * application. `ask` looks until a person allows it: the first action aimed at a browser window
242
+ * puts {@link askBrowserWindow} to them, and only their answer grants it, for that browser and
243
+ * for the life of this tool (one conversation). Nothing else grants it, no permission mode
244
+ * included; a function is read at every call, and a switch to `look` takes every grant back; without `askBrowserWindow` (a scheduled or unattended run) `ask` stays `look`.
245
+ */
246
+ readonly browserWindows?: BrowserWindowsSetting | (() => BrowserWindowsSetting)
247
+ /**
248
+ * Puts the question "may Namzu click and type in this browser in this conversation?" to a
249
+ * person. `allow` grants it, `deny` is "not now", `unavailable` means nobody can answer.
250
+ */
251
+ readonly askBrowserWindow?: (
252
+ question: BrowserWindowQuestion,
253
+ signal?: AbortSignal,
254
+ ) => Promise<BrowserWindowAnswer>
255
+ }
256
+
257
+ /** `computerUse.browserWindows`: how far the tool works in a browser window. */
258
+ export type BrowserWindowsSetting = 'look' | 'ask' | 'act'
259
+ /** The person's answer to {@link ComputerUseToolOptions.askBrowserWindow}. */
260
+ export type BrowserWindowAnswer = 'allow' | 'deny' | 'unavailable'
261
+ /** The browser the question is about: the host's name for it and how a person reads it. */
262
+ export interface BrowserWindowQuestion {
263
+ readonly app: string
264
+ readonly name: string
265
+ }
266
+
267
+ /** How a browser is told apart in a grant: trimmed, lower case, spaces joined, without `.exe`. */
268
+ function browserKey(app: string): string {
269
+ return deniedAppKey(app).replace(/\s+/g, '-')
270
+ }
271
+
272
+ /**
273
+ * The three ways forward after a browser window was not acted in, in the words the model offers
274
+ * the person. `own` names the first: the setting to change when it is `look`, the question when
275
+ * it is `ask`.
276
+ */
277
+ function browserWaysForward(name: string, setting: BrowserWindowsSetting): string {
278
+ const first =
279
+ setting === 'look'
280
+ ? `change Browser windows in Settings (computerUse.browserWindows) to Ask, so Namzu may click and type in ${name} once they allow it`
281
+ : `allow Namzu to click and type in ${name} for this conversation`
282
+ return `Ways forward to offer the person, in plain words: ${first}; or continue in Namzu's own browser (the browser tool), where they sign in once; or they click in ${name} themselves while you guide them from screenshots.`
283
+ }
284
+
285
+ /** What the tool says about browser windows, one paragraph, for its description. */
286
+ export function browserWindowsGuidance(setting: BrowserWindowsSetting): string {
287
+ const care =
288
+ 'Even where it is allowed, stop and ask the person before you type into a password field, submit payment or personal data, send or post something, delete, accept terms, or change organisation-wide admin settings.'
289
+ if (setting === 'act')
290
+ return `Browser windows are worked like any other application. The browser tool is Namzu's own browser, where the person signs in once; the person's own open browser is here. ${care}`
291
+ if (setting === 'ask')
292
+ return `A browser window is only looked at until the person allows more: the first action aimed at one asks them whether Namzu may click and type in that browser for this conversation, and only their answer allows it. If it is refused or not asked yet, offer the person the ways forward in plain words: allow it for this conversation; continue in Namzu's own browser (the browser tool), where they sign in once; or they click while you guide them from screenshots. ${care}`
293
+ return "A browser window is only looked at: act on a page with the browser tool, which is Namzu's own browser, where the person signs in once. To work in the browser window the person already has open, they can allow it in Settings (Browser windows), or click there themselves while you guide them from screenshots."
210
294
  }
211
295
 
212
296
  /** How an application name is compared: trimmed, lower case, without a trailing `.exe`. */
@@ -357,6 +441,10 @@ const uiSnapshotSchema = z.object({
357
441
  offset: z.number().int().min(0).max(1_000_000).optional(),
358
442
  /** Only controls whose text contains this, with the elements above them. */
359
443
  query: z.string().min(1).max(200).optional(),
444
+ /** Only controls of this role (comma-separated for several), with the elements above them. */
445
+ role: z.string().min(1).max(120).optional(),
446
+ /** Show the whole tree even where the window was read before (the default shows what changed). */
447
+ full: z.boolean().optional(),
360
448
  })
361
449
  const WAIT_FOR_CONDITIONS = [
362
450
  'element_appears',
@@ -530,6 +618,65 @@ const SCREEN_OBSERVATIONS = new Set<string>([
530
618
  const TERMINAL_APPS =
531
619
  /^(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
620
 
621
+ /**
622
+ * Browser windows, by the process name a host reports in `WindowInfo.app` (on
623
+ * Windows without `.exe`). The tool only looks at these: a page is worked
624
+ * through the browser tool.
625
+ */
626
+ const BROWSER_APPS =
627
+ /^(chrome|google-chrome(-stable|-beta|-unstable|-canary|-dev)?|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
628
+
629
+ /**
630
+ * Editors and development environments, by process name. Like a terminal,
631
+ * the tool may click in these but does not type or press keys in them: the
632
+ * shell and the edit tools do that work without a screen.
633
+ */
634
+ const IDE_APPS =
635
+ /^(code(-insiders|-oss)?|visual-studio-code(-insiders)?|intellij-idea(-ce)?|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
636
+
637
+ /** How far the tool works in an application: only looks, looks and clicks, or everything. */
638
+ export type AppTier = 'view' | 'click' | 'full'
639
+
640
+ /** The tier of an application by the name a host reports for its window. */
641
+ export function appTier(app: string): AppTier {
642
+ // Arc's macOS display name is the bare word; as a lower-case process name it is too generic.
643
+ if (appIs(BROWSER_APPS, app) || app.trim() === 'Arc') return 'view'
644
+ if (appIs(TERMINAL_APPS, app) || appIs(IDE_APPS, app)) return 'click'
645
+ return 'full'
646
+ }
647
+
648
+ /**
649
+ * Whether an application name matches a family pattern. Hosts name a window's
650
+ * application differently: a process name on Windows and Linux (`msedge`,
651
+ * `sublime_text`), the display name on macOS (`Microsoft Edge`, `Sublime Text`).
652
+ * The name is tried as given and with its spaces joined by `-` and by `_`.
653
+ */
654
+ function appIs(pattern: RegExp, app: string): boolean {
655
+ const name = app
656
+ .trim()
657
+ .replace(/\.exe$/i, '')
658
+ .replace(/^.*[\\/]/, '')
659
+ return (
660
+ pattern.test(name) ||
661
+ pattern.test(name.replace(/\s+/g, '-')) ||
662
+ pattern.test(name.replace(/\s+/g, '_'))
663
+ )
664
+ }
665
+
666
+ /** Keys that only move a page: allowed in a view-only application. */
667
+ const SCROLL_KEYS = /^(page_?up|page_?down|home|end|arrow_?(up|down|left|right)|up|down|space)$/i
668
+
669
+ function onlyScrollKeys(keys: unknown): boolean {
670
+ if (typeof keys !== 'string') return false
671
+ const parts = keys.split(/[\s+]+/).filter(Boolean)
672
+ return parts.length > 0 && parts.every((part) => SCROLL_KEYS.test(part))
673
+ }
674
+
675
+ /** Actions that type: refused in a click-only application. */
676
+ const TYPING_ACTIONS = new Set<string>(['type_text', 'key'])
677
+ /** Actions that press or drive a control: refused in a view-only application too. */
678
+ const POINTING_ACTIONS = new Set<string>(['mouse_click', 'mouse_drag', 'ui_act', 'ui_do'])
679
+
533
680
  /** Actions a batch cannot carry: the ones that return an image or a tree, and batch itself. */
534
681
  const OUTSIDE_BATCH = new Set<string>(['screenshot', 'zoom', 'ui_snapshot', 'wait_for', 'batch'])
535
682
 
@@ -694,6 +841,7 @@ function buildDescription(
694
841
  caps: ComputerUseCapabilities,
695
842
  settings: ResolvedSettings,
696
843
  advisor?: ComputerUseAdvisor,
844
+ browser: BrowserWindowsSetting = 'look',
697
845
  ): string {
698
846
  const available = availableActions(host, caps, advisor)
699
847
  const unavailable = unavailableHostActions(host, caps)
@@ -723,19 +871,20 @@ function buildDescription(
723
871
  )
724
872
  lines.push(
725
873
  '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
- 'Take a screenshot before your first click on pixels.',
874
+ 'Click coordinates need a screenshot to refer to; any action that changes something already returns one, so take one yourself only when none has been shown yet.',
875
+ `Look at the screen before you say what state an application is in. ${browser === 'look' ? "Never click links with computer use: a page is the browser tool's." : 'Prefer the browser tool for a page; click in a browser window with computer use only where the browser rule allows it.'} Prefer a connected tool or a command line to the screen when one does the job.`,
727
876
  )
728
877
  if (settings.screenshotAfterActions)
729
878
  lines.push(
730
- `After any action that changes something, the tool waits ${settings.settleMs} ms and returns a new screenshot — do not call screenshot again after acting.`,
879
+ `After any action that changes something, the tool itself waits for the window to stop changing (at most ${settings.settleMs} ms) and then returns the result — do not add a wait or call screenshot after acting.`,
731
880
  )
732
881
  lines.push(
733
- 'zoom returns a closer, sharper view of region {x, y, width, height} of the screenshot; your coordinates still refer to the screenshot, not to the zoomed image.',
882
+ `zoom returns a closer, sharper view of region {x, y, width, height} of the screenshot; your coordinates still refer to the screenshot, not to the zoomed image. It is for reading small text that ${available.includes('ui_snapshot') ? "the window's controls do not name" : 'the screenshot shows too small'}, not a step to take before acting: act on what you can already see.`,
734
883
  `wait pauses for ms milliseconds (at most ${settings.maxWaitMs} per call, a batch's waits together) and then shows the screen.${available.includes('wait_for') ? ' Prefer wait_for to a fixed wait whenever you know what you are waiting for.' : ''}`,
735
884
  )
736
885
  if (available.includes('batch'))
737
886
  lines.push(
738
- `batch: {"type":"batch","actions":[...]} runs up to ${settings.maxBatchActions} actions in order, stops at the first one that fails, and returns one screenshot at the end. Every call costs a model round trip of several seconds, so put the steps you can already predict into one batch (click a field, type, press ENTER) rather than one call each — but end the batch at any step that should bring up a new window, and look before typing into it. A batch cannot contain screenshot${available.includes('ui_snapshot') ? ', zoom or ui_snapshot' : ' or zoom'}.`,
887
+ `batch: {"type":"batch","actions":[...]} runs up to ${settings.maxBatchActions} actions in order, stops at the first one that fails (a ref that cannot be found or is ambiguous included, so nothing after it runs), and ends with what changed in the window's controls when you have read that window, or else one screenshot. The tool settles after each action, so a batch needs no wait between steps. Every call costs a model round trip of several seconds, so put the steps you can already predict into one batch (click a field, type, press ENTER) rather than one call each — but end the batch at any step that should bring up a new window, and look before typing into it. A batch cannot contain screenshot${available.includes('ui_snapshot') ? ', zoom or ui_snapshot' : ' or zoom'}.`,
739
888
  )
740
889
  if (
741
890
  caps.displayServer === 'win32' &&
@@ -755,11 +904,11 @@ function buildDescription(
755
904
  )
756
905
  if (windowCaptureAvailable(host, caps))
757
906
  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.`,
907
+ `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. ' : ''}${browserWindowsGuidance(browser)} 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
908
  )
760
909
  if (available.includes('ui_snapshot'))
761
910
  lines.push(
762
- `ui_snapshot {window_id} reads a window's controls (its accessibility tree) as text, each control you can act on with a ref such as e12; without window_id it reads the window in front. A large window comes back as an outline: a region ends with "(+N more inside)" and has a ref; ui_snapshot {root: <that ref>} reads that region alone (a long one in pages: offset) and keeps every other ref usable, and ui_snapshot {query: <text>} lists only the controls whose text matches. ui_act {ref, action, value} acts on one control: invoke (press a button, open a menu item), set_value (replace a field's text with value), toggle, select, expand, collapse. A batch of ui_act steps (for example pressing several buttons) runs in one call. A ref names its control and stays usable after later snapshots and after you act: the control is found again by its id, its place and its name before anything is sent. If it cannot be found the step fails with STALE_REF, and if several controls fit it fails with AMBIGUOUS_TARGET; in both nothing was sent, so take a ui_snapshot and choose again.`,
911
+ `ui_snapshot {window_id} reads a window's controls (its accessibility tree) as text, each control you can act on with a ref such as e12; without window_id it reads the window in front. A large window comes back as an outline: a region ends with "(+N more inside)" and has a ref; ui_snapshot {root: <that ref>} reads that region alone (a long one in pages: offset) and keeps every other ref usable, and ui_snapshot {query: <text>} lists only the controls whose text matches, and ui_snapshot {role: "Button"} only those of that type (both keep the elements above them). A window you have read before comes back as what changed since (+ added, ~ changed, - gone, or "no change"), with every earlier ref still usable; ui_snapshot {full: true} lists the whole tree. The result ends with the focused control and any selected text. A window screenshot of a window not yet read comes with its controls. ui_act {ref, action, value} acts on one control: invoke (press a button, open a menu item), set_value (replace a field's text with value), toggle, select, expand, collapse. A batch of ui_act steps (for example pressing several buttons) runs in one call. A ref names its control and stays usable after later snapshots and after you act: the control is found again by its id, its place and its name before anything is sent. If it cannot be found the step fails with STALE_REF, and if several controls fit it fails with AMBIGUOUS_TARGET; in both nothing was sent, so take a ui_snapshot and choose again.`,
763
912
  'Each ui_act says what is known. "done, verified" means the control was read back and matches. "sent, not confirmed" means the input went out and nothing could check it: look (ui_snapshot, or a window screenshot) before repeating it, because repeating can act twice. A failure that says "not delivered" means nothing reached the control, so trying again, or another way, is safe. set_value on a control that does not take the value fails with that reason instead of being typed in; select on a list row selects it without opening it (invoke opens it).',
764
913
  ...(available.includes('wait_for')
765
914
  ? [
@@ -844,7 +993,7 @@ const ACTION_REQUIREMENTS: Readonly<Record<ToolActionType, string>> = {
844
993
  list_windows: 'list_windows needs no other fields',
845
994
  focus_window: 'focus_window needs window_id',
846
995
  ui_snapshot:
847
- 'ui_snapshot takes an optional window_id, root (a ref to open) and query (text to find)',
996
+ 'ui_snapshot takes an optional window_id, root (a ref to open), query (text to find), role (a control type to list) and full (the whole tree instead of what changed)',
848
997
  wait_for: 'wait_for needs until and match; role, window_id and timeout_ms are optional',
849
998
  ui_act: 'ui_act needs ref and action, and value for set_value',
850
999
  ui_do: 'ui_do needs target (the control, in words) and action, and value for set_value',
@@ -959,6 +1108,16 @@ function hostModelSchema(
959
1108
  description:
960
1109
  'For ui_snapshot: list only the controls whose text contains this (case-insensitive), with the elements above them.',
961
1110
  }
1111
+ fields.role = {
1112
+ type: 'string',
1113
+ description:
1114
+ 'For ui_snapshot: list only controls of this role, such as Button or Edit (comma-separated for several), with the elements above them. Combines with query.',
1115
+ }
1116
+ fields.full = {
1117
+ type: 'boolean',
1118
+ description:
1119
+ 'For ui_snapshot: true shows the whole tree. By default a window read before shows only what changed since that read.',
1120
+ }
962
1121
  }
963
1122
  if (!forItems && present.includes('wait_for')) {
964
1123
  fields.until = {
@@ -1235,7 +1394,7 @@ function batchLabel(
1235
1394
  // ---------------------------------------------------------------------------
1236
1395
 
1237
1396
  interface ResolvedSettings {
1238
- readonly limits: ScreenshotLimits
1397
+ readonly limits: () => ScreenshotLimits
1239
1398
  readonly settleMs: number
1240
1399
  readonly screenshotAfterActions: boolean
1241
1400
  readonly maxBatchActions: number
@@ -1249,18 +1408,22 @@ function resolveSettings(options: ComputerUseToolOptions): ResolvedSettings {
1249
1408
  throw new RangeError(`createComputerUseTool: ${name} must be an integer ≥ ${min}`)
1250
1409
  return value
1251
1410
  }
1252
- const limits = options.screenshotLimits ?? STANDARD_SCREENSHOT_LIMITS
1253
- if (
1254
- !Number.isSafeInteger(limits.maxLongEdge) ||
1255
- !Number.isSafeInteger(limits.maxTiles) ||
1256
- limits.maxLongEdge < 28 ||
1257
- limits.maxTiles < 1
1258
- )
1259
- throw new RangeError(
1260
- 'createComputerUseTool: screenshotLimits needs an integer maxLongEdge ≥ 28 and maxTiles ≥ 1',
1411
+ const source = options.screenshotLimits ?? STANDARD_SCREENSHOT_LIMITS
1412
+ const check = (limits: ScreenshotLimits): ScreenshotLimits => {
1413
+ if (
1414
+ !Number.isSafeInteger(limits.maxLongEdge) ||
1415
+ !Number.isSafeInteger(limits.maxTiles) ||
1416
+ limits.maxLongEdge < 28 ||
1417
+ limits.maxTiles < 1
1261
1418
  )
1419
+ throw new RangeError(
1420
+ 'createComputerUseTool: screenshotLimits needs an integer maxLongEdge ≥ 28 and maxTiles ≥ 1',
1421
+ )
1422
+ return limits
1423
+ }
1424
+ check(typeof source === 'function' ? source() : source)
1262
1425
  return {
1263
- limits,
1426
+ limits: () => check(typeof source === 'function' ? source() : source),
1264
1427
  settleMs: count(options.settleMs, DEFAULT_SETTLE_MS, 0, 'settleMs'),
1265
1428
  screenshotAfterActions: options.screenshotAfterActions ?? true,
1266
1429
  maxBatchActions: count(
@@ -1469,21 +1632,58 @@ export interface ComputerUseTool extends ToolDefinition<ActionInput> {
1469
1632
  * ordinary action. A reading of the call's own words, not of the screen.
1470
1633
  */
1471
1634
  consequence(input: unknown): string | undefined
1635
+ /** The browsers a person allowed Namzu to click and type in during this conversation, as named. */
1636
+ browserGrants(): string[]
1637
+ /** Takes a browser back (by any name the host gives it). Returns whether it was allowed. */
1638
+ revokeBrowserGrant(app: string): boolean
1639
+ /**
1640
+ * Whether an action in this application would put the browser question to a person: it is a
1641
+ * browser, the setting is `ask`, somebody can be asked, and nobody has allowed it yet. A host
1642
+ * that draws its own application card uses it to ask once, in the browser's words, not twice.
1643
+ */
1644
+ browserQuestionPending(app: string): boolean
1645
+ /**
1646
+ * Of the applications a call works on, the browsers the engine will put its question about for
1647
+ * THIS call. A call that only looks (a picture, a list of windows) puts no question, so it names
1648
+ * none: its card would grant click-and-type, and a no would refuse a harmless look.
1649
+ */
1650
+ browserAsk(input: unknown, apps: readonly string[]): string[]
1472
1651
  }
1473
1652
 
1474
1653
  const CONSEQUENTIAL_KEYS =
1475
1654
  /(^|\+)(alt\+f4|ctrl\+q|cmd\+q|super\+q|ctrl\+w|ctrl\+shift\+delete|shift\+delete|ctrl\+enter|cmd\+enter|delete)$/i
1476
1655
  const CONSEQUENTIAL_WORDS =
1477
- /(?<!\p{L})(delete|remove|erase|discard|don'?t save|do not save|close|quit|exit|send|submit|pay|purchase|buy|order|sign out|log ?out|empty|format|uninstall|kaydetme|sil|gönder|kapat|çık|çıkış|satın al|öde)(?!\p{L})/iu
1656
+ /(?<!\p{L})(delete|remove|erase|discard|don'?t save|do not save|close|quit|exit|send|submit|pay|purchase|buy|order|sign out|log ?out|empty|format|uninstall|accept|agree|post|publish|confirm|password|passcode|card number|cvv|iban|kaydetme|sil|gönder|kapat|çık|çıkış|satın al|öde)(?!\p{L})/iu
1657
+
1658
+ /** Browsers whose process name is not how a person says it. */
1659
+ const KNOWN_BROWSER_NAMES: Record<string, string> = {
1660
+ 'brave-browser': 'Brave',
1661
+ brave: 'Brave',
1662
+ 'google-chrome': 'Chrome',
1663
+ chrome: 'Chrome',
1664
+ msedge: 'Microsoft Edge',
1665
+ 'microsoft-edge': 'Microsoft Edge',
1666
+ firefox: 'Firefox',
1667
+ }
1478
1668
 
1479
1669
  /** An application as a person reads it: no `.exe`, and a lowercase process name starts with a capital. */
1480
1670
  function applicationName(name: string): string {
1481
1671
  const bare = name.trim().replace(/\.exe$/i, '')
1672
+ const known = KNOWN_BROWSER_NAMES[bare.toLowerCase()]
1673
+ if (known) return known
1482
1674
  return bare && bare === bare.toLowerCase()
1483
1675
  ? `${bare.charAt(0).toUpperCase()}${bare.slice(1)}`
1484
1676
  : bare
1485
1677
  }
1486
1678
 
1679
+ /** A control that takes a secret: a password field, by its state, role or name. */
1680
+ function isSecretElement(element: UiElement): boolean {
1681
+ const states = (element.states ?? []).map((state) => state.toLowerCase())
1682
+ if (states.some((state) => state === 'password' || state === 'protected' || state === 'secure'))
1683
+ return true
1684
+ return /password|passcode|passwort|parola|şifre|sifre/i.test(`${element.role} ${element.name}`)
1685
+ }
1686
+
1487
1687
  /** Words that make a control's name or an intent one a person should answer for. */
1488
1688
  function consequentialWords(text: string | undefined): boolean {
1489
1689
  return text !== undefined && CONSEQUENTIAL_WORDS.test(text)
@@ -1593,6 +1793,22 @@ export function createComputerUseTool(
1593
1793
  const frames = new ScreenshotFrames()
1594
1794
  const available = new Set<string>(availableActions(host, caps, options.advisor))
1595
1795
  const advisor = options.advisor
1796
+ // Browser windows: the setting, and the browsers a person allowed in this conversation. Only the
1797
+ // person's answer to `askBrowserWindow` adds one; `ask` with nobody to ask is `look`.
1798
+ const readBrowserSetting = (): BrowserWindowsSetting =>
1799
+ typeof options.browserWindows === 'function'
1800
+ ? options.browserWindows()
1801
+ : (options.browserWindows ?? 'look')
1802
+ const browserSetting: BrowserWindowsSetting = readBrowserSetting()
1803
+ const browserGranted = new Map<string, string>()
1804
+ const browserDeclined = new Map<string, string>()
1805
+ const browserActionsAllowed = (app: string): boolean => {
1806
+ const setting = readBrowserSetting()
1807
+ if (setting === 'look') browserGranted.clear()
1808
+ return setting === 'act' || (setting === 'ask' && browserGranted.has(browserKey(app)))
1809
+ }
1810
+ // Whether the control in focus in the latest ui_snapshot is a secret field (a password).
1811
+ let focusedSecret = false
1596
1812
 
1597
1813
  // The controls of the latest ui_snapshot, by the ref the model was shown.
1598
1814
  // A ref names a control, not one reading of it: the same host ref keeps the
@@ -1602,6 +1818,19 @@ export function createComputerUseTool(
1602
1818
  const uiRefByHost = new Map<string, string>()
1603
1819
  // The refs the latest reading of each window showed, so an advisor is asked about what is there now.
1604
1820
  const shownRefs = new Map<string, Set<string>>()
1821
+ // The last whole-window read of each window, for showing only what changed next time.
1822
+ const uiSnapshotMemory = new Map<
1823
+ string,
1824
+ {
1825
+ readonly id: string
1826
+ readonly entries:
1827
+ | readonly {
1828
+ readonly hostRef: string | undefined
1829
+ readonly text: string
1830
+ }[]
1831
+ | undefined
1832
+ }
1833
+ >()
1605
1834
  let uiSnapshots = 0
1606
1835
  let uiRefCount = 0
1607
1836
  let uiSnapshotWindowId: string | undefined
@@ -1669,12 +1898,14 @@ export function createComputerUseTool(
1669
1898
  windowId,
1670
1899
  callSignal,
1671
1900
  )
1672
- const image = await fitPng(shot.data, settings.limits)
1901
+ const image = await fitPng(shot.data, settings.limits())
1673
1902
  if (image.sourceWidth !== shot.width || image.sourceHeight !== shot.height)
1674
1903
  throw new StepFailure(
1675
1904
  'the window PNG dimensions changed during capture; take a new screenshot',
1676
1905
  )
1677
- return { frame: frames.recordWindow(image, shot), image }
1906
+ const frame = frames.recordWindow(image, shot)
1907
+ noteDigest(frame, image)
1908
+ return { frame, image }
1678
1909
  }
1679
1910
  if (!hostActionAvailable(caps, 'screenshot'))
1680
1911
  throw new StepFailure(
@@ -1684,9 +1915,57 @@ export function createComputerUseTool(
1684
1915
  if (result.type !== 'screenshot')
1685
1916
  throw new Error(`computer_use: the host answered a screenshot with "${result.type}"`)
1686
1917
  const shot = result.result
1687
- const image = await fitPng(shot.data, settings.limits)
1918
+ const image = await fitPng(shot.data, settings.limits())
1688
1919
  const display = shot.display ?? assumedDisplay(image.sourceWidth, image.sourceHeight)
1689
- return { frame: frames.record(image, display), image }
1920
+ const frame = frames.record(image, display)
1921
+ noteDigest(frame, image)
1922
+ return { frame, image }
1923
+ }
1924
+
1925
+ /**
1926
+ * Before a click, drag or scroll on a window screenshot: the window must still be where that
1927
+ * picture was taken. A moved or resized window turns every coordinate into a different control,
1928
+ * and a closed one has nothing left to click. Nothing is sent. A host that cannot list windows
1929
+ * leaves the check to its own.
1930
+ */
1931
+ const refuseMovedWindow = async (frame: ScreenshotFrame): Promise<void> => {
1932
+ const shown = frame.window?.window
1933
+ if (!shown || typeof host.listWindows !== 'function') return
1934
+ let windows: readonly WindowInfo[]
1935
+ try {
1936
+ windows = rememberWindows(await host.listWindows(callSignal))
1937
+ } catch {
1938
+ if (callSignal?.aborted) throw new StepFailure('cancelled')
1939
+ return
1940
+ }
1941
+ const now = windows.find((window) => window.id === shown.id)
1942
+ const where = `window ${visibleWindowId(shown.id)}`
1943
+ let why: string | undefined
1944
+ if (!now) why = `${where} is no longer open`
1945
+ else if (now.minimized) why = `${where} is minimized now`
1946
+ else if (
1947
+ now.bounds.x !== shown.bounds.x ||
1948
+ now.bounds.y !== shown.bounds.y ||
1949
+ now.bounds.width !== shown.bounds.width ||
1950
+ now.bounds.height !== shown.bounds.height
1951
+ )
1952
+ why = `${where} moved or was resized since ${frame.id} was taken (${shown.bounds.width}x${shown.bounds.height} at ${shown.bounds.x},${shown.bounds.y}, now ${now.bounds.width}x${now.bounds.height} at ${now.bounds.x},${now.bounds.y})`
1953
+ if (why)
1954
+ throw deliveryFailure({
1955
+ delivery: 'not_delivered',
1956
+ retrySafety: 'safe',
1957
+ detail: `${why}, so nothing was clicked: the coordinates of ${frame.id} no longer point at what they did. Take a new window screenshot (or read its controls with ui_snapshot) and choose the target again.`,
1958
+ })
1959
+ }
1960
+
1961
+ /** A fingerprint of each frame's picture, to tell a click that changed nothing from one that did. */
1962
+ const frameDigest = new Map<string, string>()
1963
+ const noteDigest = (frame: ScreenshotFrame, image: FittedImage): void => {
1964
+ frameDigest.set(frame.id, createHash('sha1').update(image.data).digest('hex'))
1965
+ // Only the few newest are ever compared.
1966
+ if (frameDigest.size > 16)
1967
+ for (const key of [...frameDigest.keys()].slice(0, frameDigest.size - 16))
1968
+ frameDigest.delete(key)
1690
1969
  }
1691
1970
 
1692
1971
  const frameFor = (id: string | undefined): ScreenshotFrame => {
@@ -1819,6 +2098,7 @@ export function createComputerUseTool(
1819
2098
  const frame = frameFor(frameId)
1820
2099
  const at = mapPoint(frame, item.at, 'at')
1821
2100
  return step(async () => {
2101
+ await refuseMovedWindow(frame)
1822
2102
  const outcome = await runHost(
1823
2103
  {
1824
2104
  type: 'mouse_click',
@@ -1848,7 +2128,10 @@ export function createComputerUseTool(
1848
2128
  const frame = frameFor(frameId)
1849
2129
  const from = mapPoint(frame, item.from, 'from')
1850
2130
  const to = mapPoint(frame, item.to, 'to')
1851
- return step(() => runHost({ type: 'mouse_drag', from, to, button: item.button }, frame))
2131
+ return step(async () => {
2132
+ await refuseMovedWindow(frame)
2133
+ return runHost({ type: 'mouse_drag', from, to, button: item.button }, frame)
2134
+ })
1852
2135
  }
1853
2136
  case 'scroll': {
1854
2137
  const frame = frameFor(frameId)
@@ -1858,11 +2141,12 @@ export function createComputerUseTool(
1858
2141
  )
1859
2142
  if (frame.window && caps.windowScroll === false)
1860
2143
  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',
2144
+ '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
2145
  )
1863
2146
  const at = mapPoint(frame, item.at, 'at')
1864
- return step(() =>
1865
- runHost(
2147
+ return step(async () => {
2148
+ await refuseMovedWindow(frame)
2149
+ return runHost(
1866
2150
  {
1867
2151
  type: 'scroll',
1868
2152
  at,
@@ -1870,8 +2154,8 @@ export function createComputerUseTool(
1870
2154
  amount: item.amount,
1871
2155
  },
1872
2156
  frame,
1873
- ),
1874
- )
2157
+ )
2158
+ })
1875
2159
  }
1876
2160
  case 'type_text': {
1877
2161
  if (item.at)
@@ -1882,8 +2166,10 @@ export function createComputerUseTool(
1882
2166
  const frame = frameFor(frameId)
1883
2167
  if (item.delivery_mode && !frame.window)
1884
2168
  throw new StepFailure('type_text delivery_mode requires a window screenshot')
1885
- if (frame.window && TERMINAL_APPS.test(frame.window.window.app))
1886
- throw new StepFailure('computer_use never types into a terminal window')
2169
+ if (frame.window && appIs(TERMINAL_APPS, frame.window.window.app))
2170
+ throw new StepFailure(
2171
+ 'computer_use never types into a terminal window; use the shell tool for a command',
2172
+ )
1887
2173
  return step(() =>
1888
2174
  runHost(
1889
2175
  {
@@ -1906,8 +2192,10 @@ export function createComputerUseTool(
1906
2192
  throw new StepFailure(
1907
2193
  'key delivery_mode requires a window screenshot; take one with screenshot {window_id}',
1908
2194
  )
1909
- if (frame.window && TERMINAL_APPS.test(frame.window.window.app))
1910
- throw new StepFailure('computer_use never sends keys to a terminal window')
2195
+ if (frame.window && appIs(TERMINAL_APPS, frame.window.window.app))
2196
+ throw new StepFailure(
2197
+ 'computer_use never sends keys to a terminal window; use the shell tool for a command',
2198
+ )
1911
2199
  return step(() =>
1912
2200
  runHost(
1913
2201
  {
@@ -2082,6 +2370,7 @@ export function createComputerUseTool(
2082
2370
  ...(rootRef ? { root: rootRef.hostRef } : {}),
2083
2371
  ...(rootRef && input.offset !== undefined ? { offset: input.offset } : {}),
2084
2372
  ...(input.query !== undefined ? { query: input.query } : {}),
2373
+ ...(input.role !== undefined ? { role: input.role } : {}),
2085
2374
  }
2086
2375
  try {
2087
2376
  snapshot = await (host.uiSnapshot as NonNullable<ComputerUseHost['uiSnapshot']>)(
@@ -2092,7 +2381,17 @@ export function createComputerUseTool(
2092
2381
  } catch (error) {
2093
2382
  throw new StepFailure(errorText(error))
2094
2383
  }
2095
- return showUiSnapshot(snapshot, windowId, [], input.root)
2384
+ return showUiSnapshot(snapshot, windowId, [], input.root, {
2385
+ ...(input.full === true ? { full: true } : {}),
2386
+ ...(input.query !== undefined || input.role !== undefined
2387
+ ? {
2388
+ filter: [
2389
+ ...(input.role !== undefined ? [`role ${quotedText(input.role)}`] : []),
2390
+ ...(input.query !== undefined ? [`text ${quotedText(input.query)}`] : []),
2391
+ ].join(' and '),
2392
+ }
2393
+ : {}),
2394
+ })
2096
2395
  }
2097
2396
 
2098
2397
  /** Number a read tree's controls and show it; this snapshot's refs replace the last one's. */
@@ -2101,6 +2400,7 @@ export function createComputerUseTool(
2101
2400
  requestedWindowId: string | undefined,
2102
2401
  preface: readonly string[] = [],
2103
2402
  openedRef?: string,
2403
+ mode: { readonly full?: boolean; readonly filter?: string } = {},
2104
2404
  ): ToolResult => {
2105
2405
  uiSnapshots += 1
2106
2406
  const id = `u${uiSnapshots}`
@@ -2113,6 +2413,13 @@ export function createComputerUseTool(
2113
2413
  let shown = 0
2114
2414
  let total = 0
2115
2415
  let cut = false
2416
+ // What was listed, for the diff against the next read of this window.
2417
+ const entries: {
2418
+ readonly hostRef: string | undefined
2419
+ readonly text: string
2420
+ }[] = []
2421
+ let focusedLine: string | undefined
2422
+ let focusedSecretNow = false
2116
2423
  const visit = (element: UiElement, depth: number): void => {
2117
2424
  total += 1
2118
2425
  const actionable = element.ref.length > 0
@@ -2130,6 +2437,14 @@ export function createComputerUseTool(
2130
2437
  cut = true
2131
2438
  } else {
2132
2439
  lines.push(line)
2440
+ entries.push({
2441
+ hostRef: actionable ? element.ref : undefined,
2442
+ text: line.trim(),
2443
+ })
2444
+ if (focusedLine === undefined && element.states?.includes('focused') === true) {
2445
+ focusedLine = line.trim()
2446
+ focusedSecretNow = isSecretElement(element)
2447
+ }
2133
2448
  chars += line.length + 1
2134
2449
  shown += 1
2135
2450
  if (ref) {
@@ -2147,6 +2462,7 @@ export function createComputerUseTool(
2147
2462
  // Refs shown now replace what they name; the rest stay as they were, so a
2148
2463
  // region opened by itself leaves the refs outside it usable.
2149
2464
  for (const [ref, entry] of refs) uiRefs.set(ref, entry)
2465
+ focusedSecret = focusedSecretNow
2150
2466
  if (uiRefs.size > MAX_HELD_UI_REFS) {
2151
2467
  for (const ref of [...uiRefs.keys()].slice(0, uiRefs.size - MAX_HELD_UI_REFS)) {
2152
2468
  const gone = uiRefs.get(ref)
@@ -2166,16 +2482,6 @@ export function createComputerUseTool(
2166
2482
  const window =
2167
2483
  snapshot.windowId && /^[\w.:-]{1,64}$/.test(snapshot.windowId) ? snapshot.windowId : undefined
2168
2484
  const opened = openedRef !== undefined && /^e\d{1,6}$/.test(openedRef) ? openedRef : undefined
2169
- const summaryLine = `UI snapshot ${id}${window ? ` of window ${window}` : ''}${snapshot.region ? `${opened ? `, region ${opened}` : ', one region'}` : ''}: ${shown} controls shown${snapshot.total !== undefined && snapshot.total > shown ? ` of ${snapshot.total}` : ''}, ${refs.size} with a ref you can pass to ui_act. A ref names its control and stays usable after later snapshots; if the control has gone or several fit, ui_act says so (STALE_REF, AMBIGUOUS_TARGET) and nothing is sent.`
2170
- const header = [
2171
- ...preface,
2172
- summaryLine,
2173
- ...(frame && !frame.window
2174
- ? [
2175
- `@(x, y) is a control's centre on screenshot ${frame.id}, for a click when ui_act cannot reach it.`,
2176
- ]
2177
- : []),
2178
- ]
2179
2485
  // The window's title and application, when the tree's own root does not
2180
2486
  // already say them; inside the frame, since an application sets both.
2181
2487
  const about = [
@@ -2184,42 +2490,120 @@ export function createComputerUseTool(
2184
2490
  ? [`Window title ${quotedText(snapshot.title)}`]
2185
2491
  : []),
2186
2492
  ]
2187
- const body = [...about, ...lines].join('\n')
2188
- const drill =
2189
- 'Open a region with ui_snapshot {root: <its ref>}, or find a control by its text with ui_snapshot {query}.'
2190
- const footer = [
2191
- ...(snapshot.next !== undefined && opened
2192
- ? [
2193
- `This is one page of a long region. Next page: ui_snapshot {root: "${opened}", offset: ${snapshot.next}}.`,
2194
- ]
2195
- : []),
2196
- ...(snapshot.outline
2197
- ? [
2198
- `This is an outline: regions marked "(+N more inside)" hold controls that are not listed. ${drill}`,
2199
- ]
2200
- : []),
2201
- ...(cut
2493
+ // A window read before shows what changed since, unless the whole tree is
2494
+ // asked for, the read is a region or a filtered one, or either read was cut.
2495
+ const whole = !snapshot.region && mode.filter === undefined
2496
+ const key = windowKey(uiSnapshotWindowId)
2497
+ const before = whole ? uiSnapshotMemory.get(key) : undefined
2498
+ if (whole) uiSnapshotMemory.set(key, { id, entries: cut ? undefined : entries })
2499
+ let changes: { added: string[]; changed: string[]; removed: string[] } | undefined
2500
+ if (before?.entries && !cut && mode.full !== true) {
2501
+ const prevByRef = new Map<string, string>()
2502
+ const prevCounts = new Map<string, number>()
2503
+ for (const entry of before.entries) {
2504
+ if (entry.hostRef) prevByRef.set(entry.hostRef, entry.text)
2505
+ else prevCounts.set(entry.text, (prevCounts.get(entry.text) ?? 0) + 1)
2506
+ }
2507
+ const added: string[] = []
2508
+ const changed: string[] = []
2509
+ const seenRefs = new Set<string>()
2510
+ const left = new Map(prevCounts)
2511
+ for (const entry of entries) {
2512
+ if (entry.hostRef) {
2513
+ seenRefs.add(entry.hostRef)
2514
+ const was = prevByRef.get(entry.hostRef)
2515
+ if (was === undefined) added.push(entry.text)
2516
+ else if (was !== entry.text) changed.push(entry.text)
2517
+ } else {
2518
+ const count = left.get(entry.text) ?? 0
2519
+ if (count > 0) left.set(entry.text, count - 1)
2520
+ else added.push(entry.text)
2521
+ }
2522
+ }
2523
+ const removed: string[] = []
2524
+ for (const [hostRef, text] of prevByRef) if (!seenRefs.has(hostRef)) removed.push(text)
2525
+ for (const [text, count] of left) for (let i = 0; i < count; i++) removed.push(text)
2526
+ // A window that mostly changed is shorter, and clearer, read whole.
2527
+ if (added.length + changed.length + removed.length < entries.length)
2528
+ changes = { added, changed, removed }
2529
+ }
2530
+ const trailer = [
2531
+ ...(focusedLine !== undefined ? [`Focused: ${focusedLine}`] : []),
2532
+ ...(snapshot.selectedText !== undefined
2202
2533
  ? [
2203
- `The listing was cut at ${MAX_UI_SNAPSHOT_CHARS} characters after ${shown} of ${total} controls. Drill into the region you need: ${drill}`,
2534
+ `Selected text: ${neutralizeEnvelopeDelimiter(JSON.stringify(snapshot.selectedText.slice(0, 500)))}`,
2204
2535
  ]
2205
2536
  : []),
2206
- ...(snapshot.truncated
2537
+ ]
2538
+ const body = changes
2539
+ ? [
2540
+ ...about,
2541
+ ...changes.added.map((line) => `+ ${line}`),
2542
+ ...changes.changed.map((line) => `~ ${line}`),
2543
+ ...changes.removed.map((line) => `- ${line}`),
2544
+ ...trailer,
2545
+ ].join('\n')
2546
+ : [...about, ...lines, ...trailer].join('\n')
2547
+ const noChange =
2548
+ changes !== undefined &&
2549
+ changes.added.length + changes.changed.length + changes.removed.length === 0
2550
+ const where = `${window ? ` of window ${window}` : ''}${snapshot.region ? `${opened ? `, region ${opened}` : ', one region'}` : ''}${mode.filter ? `, only ${mode.filter}` : ''}`
2551
+ const counts = `${shown} controls shown${snapshot.total !== undefined ? ` of the ${snapshot.total} the window holds` : ''}, ${refs.size} with a ref you can pass to ui_act`
2552
+ const summaryLine = changes
2553
+ ? noChange
2554
+ ? `UI snapshot ${id}${where}: no change since ${before ? before.id : 'the last read'} (${counts}). Refs from that read are used while the host still has them.`
2555
+ : `UI snapshot ${id}${where}: ${changes.added.length} added (+), ${changes.changed.length} changed (~), ${changes.removed.length} gone (-) since ${before ? before.id : 'the last read'}; ${counts}. Refs from that read are used while the host still has them. ui_snapshot {full: true} lists the whole tree.`
2556
+ : `UI snapshot ${id}${where}: ${counts}. A ref names its control and stays usable after later snapshots; if the control has gone or several fit, ui_act says so (STALE_REF, AMBIGUOUS_TARGET) and nothing is sent.${mode.filter && shown <= 1 ? ' Nothing matched the filter.' : ''}`
2557
+ const header = [
2558
+ ...preface,
2559
+ summaryLine,
2560
+ ...(frame && !frame.window
2207
2561
  ? [
2208
- `The host stopped reading the tree before it ended, so some controls are missing. Drill into the region you need: ${drill} A window screenshot shows the rest.`,
2562
+ `@(x, y) is a control's centre on screenshot ${frame.id}, for a click when ui_act cannot reach it.`,
2209
2563
  ]
2210
2564
  : []),
2211
2565
  ]
2566
+ const drill =
2567
+ 'Open a region with ui_snapshot {root: <its ref>}, or find a control by its text with ui_snapshot {query}.'
2568
+ const footer = changes
2569
+ ? []
2570
+ : [
2571
+ ...(snapshot.next !== undefined && opened
2572
+ ? [
2573
+ `This is one page of a long region. Next page: ui_snapshot {root: "${opened}", offset: ${snapshot.next}}.`,
2574
+ ]
2575
+ : []),
2576
+ ...(snapshot.outline
2577
+ ? [
2578
+ `This is an outline: regions marked "(+N more inside)" hold controls that are not listed. ${drill}`,
2579
+ ]
2580
+ : []),
2581
+ ...(cut
2582
+ ? [
2583
+ `The listing was cut at ${MAX_UI_SNAPSHOT_CHARS} characters after ${shown} of ${total} controls. Drill into the region you need: ${drill}`,
2584
+ ]
2585
+ : []),
2586
+ ...(snapshot.truncated
2587
+ ? [
2588
+ `The host stopped reading the tree before it ended, so some controls are missing. Drill into the region you need: ${drill} A window screenshot shows the rest.`,
2589
+ ]
2590
+ : []),
2591
+ ]
2212
2592
  const text = [
2213
2593
  ...header,
2214
- wrapUntrusted(
2215
- {
2216
- kind: 'desktop-ui',
2217
- ...(window ? { attributes: { window } } : {}),
2218
- provenance:
2219
- "The accessibility tree of a window on the user's desktop, as the host read it. Names and values are whatever the application shows, which can include text anyone wrote.",
2220
- },
2221
- body,
2222
- ),
2594
+ ...(noChange && body.length === 0
2595
+ ? []
2596
+ : [
2597
+ wrapUntrusted(
2598
+ {
2599
+ kind: 'desktop-ui',
2600
+ ...(window ? { attributes: { window } } : {}),
2601
+ provenance:
2602
+ "The accessibility tree of a window on the user's desktop, as the host read it. Names and values are whatever the application shows, which can include text anyone wrote.",
2603
+ },
2604
+ body,
2605
+ ),
2606
+ ]),
2223
2607
  ...footer,
2224
2608
  ].join('\n')
2225
2609
  return {
@@ -2234,6 +2618,7 @@ export function createComputerUseTool(
2234
2618
  refs: refs.size,
2235
2619
  truncated: cut || snapshot.truncated === true,
2236
2620
  ...(snapshot.outline ? { outline: true } : {}),
2621
+ ...(changes ? { diff: noChange ? ('none' as const) : ('changes' as const) } : {}),
2237
2622
  ...(snapshot.total !== undefined ? { total: snapshot.total } : {}),
2238
2623
  },
2239
2624
  },
@@ -2390,7 +2775,15 @@ export function createComputerUseTool(
2390
2775
  )
2391
2776
  }
2392
2777
  const front = windows.find((window) => window.focused)
2393
- if (front && TERMINAL_APPS.test(front.app))
2778
+ if (front && appTier(front.app) === 'view' && !browserActionsAllowed(front.app))
2779
+ throw new StepFailure(
2780
+ `a browser is in front (${front.app}, window ${front.id}), so nothing was typed: computer_use does not type in a browser unless the person allowed it. 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. ${browserWaysForward(applicationName(front.app), readBrowserSetting())}`,
2781
+ )
2782
+ if (front && appIs(IDE_APPS, front.app))
2783
+ throw new StepFailure(
2784
+ `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`,
2785
+ )
2786
+ if (front && appIs(TERMINAL_APPS, front.app))
2394
2787
  throw new StepFailure(
2395
2788
  `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`,
2396
2789
  )
@@ -2464,7 +2857,11 @@ export function createComputerUseTool(
2464
2857
  const shrink = display.width / frame.imageWidth
2465
2858
  const shrunkNote =
2466
2859
  shrink >= 2
2467
- ? ` The display is ${Math.round(shrink * 10) / 10} times larger than this image, so small text is hard to read here: use zoom on the area to read it at full detail.`
2860
+ ? ` The display is ${Math.round(shrink * 10) / 10} times larger than this image, so small text is hard to read here.${
2861
+ windowCaptureAvailable(host, caps)
2862
+ ? ' For the application you are working in, take a window screenshot (list_windows, then screenshot with its window_id): it is close to full size.'
2863
+ : ''
2864
+ }`
2468
2865
  : ''
2469
2866
  return scaled
2470
2867
  ? `Screenshot ${frame.id}: ${frame.imageWidth}x${frame.imageHeight} pixels, showing the ${display.width}x${display.height} display. Send coordinates in this image's pixels (x 0–${frame.imageWidth - 1}, y 0–${frame.imageHeight - 1}); the tool maps them onto the display.${shrunkNote}`
@@ -2528,6 +2925,53 @@ export function createComputerUseTool(
2528
2925
  workingState: pin(shot.frame),
2529
2926
  })
2530
2927
 
2928
+ /**
2929
+ * The first look at a window carries its controls with the picture, so the
2930
+ * model starts from names, not pixels. Later looks are the picture alone
2931
+ * (ui_snapshot shows what changed). A host that cannot read the tree, or a
2932
+ * read that fails, leaves the screenshot as it was.
2933
+ */
2934
+ const firstLookWithTree = async (
2935
+ shot: Capture,
2936
+ windowId: string | undefined,
2937
+ ): Promise<ToolResult> => {
2938
+ const result = screenshotResult(shot)
2939
+ if (
2940
+ !shot.frame.window ||
2941
+ windowId === undefined ||
2942
+ !available.has('ui_snapshot') ||
2943
+ uiSnapshotMemory.has(windowKey(windowId))
2944
+ )
2945
+ return result
2946
+ try {
2947
+ const snapshot = await (host.uiSnapshot as NonNullable<ComputerUseHost['uiSnapshot']>)(
2948
+ windowId,
2949
+ undefined,
2950
+ callSignal,
2951
+ )
2952
+ const tree = showUiSnapshot(snapshot, windowId)
2953
+ const treeBlocks = Array.isArray(tree.content) ? tree.content : []
2954
+ const treeText = treeBlocks.find((block) => block.type === 'text')
2955
+ if (!treeText || treeText.type !== 'text') return result
2956
+ const [head, ...rest] = Array.isArray(result.content) ? result.content : []
2957
+ return {
2958
+ ...result,
2959
+ content: [
2960
+ ...(head ? [head] : []),
2961
+ {
2962
+ type: 'text',
2963
+ text: `The window's controls, read with this screenshot (ui_act on a ref; pixels only for what the controls do not name):\n${treeText.text}`,
2964
+ },
2965
+ ...rest,
2966
+ ],
2967
+ data: { ...(result.data as object), ...(tree.data as object) },
2968
+ }
2969
+ } catch (error) {
2970
+ if (callSignal?.aborted) throw error
2971
+ return result
2972
+ }
2973
+ }
2974
+
2531
2975
  const zoom = async (input: Extract<ActionInput, { type: 'zoom' }>): Promise<ToolResult> => {
2532
2976
  const frame = frameFor(input.screenshot_id)
2533
2977
  const { region } = input
@@ -2546,10 +2990,10 @@ export function createComputerUseTool(
2546
2990
  if (frame.window) {
2547
2991
  if (!frame.window.data)
2548
2992
  throw new StepFailure(`window screenshot ${frame.id} is stale; capture the window again`)
2549
- fitted = await cropAndFitPng(frame.window.data, rect, settings.limits)
2993
+ fitted = await cropAndFitPng(frame.window.data, rect, settings.limits())
2550
2994
  } else if (caps.regionCapture === true && typeof host.captureRegion === 'function') {
2551
2995
  const piece = await host.captureRegion(rect, callSignal)
2552
- fitted = await fitPng(piece.data, settings.limits)
2996
+ fitted = await fitPng(piece.data, settings.limits())
2553
2997
  } else {
2554
2998
  const result = await host.execute({ type: 'screenshot' }, callSignal)
2555
2999
  if (result.type !== 'screenshot')
@@ -2574,7 +3018,7 @@ export function createComputerUseTool(
2574
3018
  width: Math.max(1, Math.min(size.width, Math.ceil((rect.x + rect.width) * sx)) - left),
2575
3019
  height: Math.max(1, Math.min(size.height, Math.ceil((rect.y + rect.height) * sy)) - top),
2576
3020
  },
2577
- settings.limits,
3021
+ settings.limits(),
2578
3022
  )
2579
3023
  }
2580
3024
  const detail = fitted.width / onImage.width
@@ -2635,6 +3079,24 @@ export function createComputerUseTool(
2635
3079
  const unsent: readonly BatchItem[] = blockedAt >= 0 ? items.slice(blockedAt) : []
2636
3080
  const toPlan: readonly BatchItem[] = blockedAt >= 0 ? items.slice(0, blockedAt) : items
2637
3081
  const actionFrame = frameId ? frames.get(frameId) : frames.latest()
3082
+ // What the model last saw, to tell afterwards whether a pixel action changed it.
3083
+ const frameBefore = frames.latest()
3084
+ // The baseline for "a new window opened" is the host's list right now, never the last list the
3085
+ // model asked for, which may be old. A list that fails leaves no baseline, so no note.
3086
+ let windowsBefore: readonly WindowInfo[] = []
3087
+ if (
3088
+ typeof host.listWindows === 'function' &&
3089
+ typeof host.uiSnapshot === 'function' &&
3090
+ toPlan.length > 0 &&
3091
+ toPlan.every((item) => TREE_ENDING_STEPS.has(item.type)) &&
3092
+ [...treeUsable.values()].includes(true)
3093
+ ) {
3094
+ try {
3095
+ windowsBefore = rememberWindows(await host.listWindows(callSignal))
3096
+ } catch {
3097
+ if (callSignal?.aborted) throw new Error('cancelled')
3098
+ }
3099
+ }
2638
3100
  const explicitDisplayFrame =
2639
3101
  frameId !== undefined && actionFrame !== undefined && !actionFrame.window
2640
3102
  if (
@@ -2785,14 +3247,108 @@ export function createComputerUseTool(
2785
3247
  !signal?.aborted
2786
3248
  let shot: Capture | undefined = frameShot
2787
3249
  let shotError: string | undefined
2788
- if (looks) {
3250
+ // A batch of element and keyboard steps on a window whose controls were read ends with what
3251
+ // changed there, not a picture: the model acts on the next refs, and the text is far cheaper.
3252
+ const executed = planned.filter((_, index) => records[index]?.status === 'done')
3253
+ let treeText: string | undefined
3254
+ let treeData: unknown
3255
+ let windowClosed: string | undefined
3256
+ let newWindows: readonly WindowInfo[] = []
3257
+ const treeEnding =
3258
+ looks &&
3259
+ !failure &&
3260
+ frameShot === undefined &&
3261
+ frameId === undefined &&
3262
+ postWindowId !== undefined &&
3263
+ available.has('ui_snapshot') &&
3264
+ typeof host.uiSnapshot === 'function' &&
3265
+ treeUsable.get(windowKey(postWindowId)) === true &&
3266
+ executed.length > 0 &&
3267
+ executed.every((step) => TREE_ENDING_STEPS.has(step.item.type))
3268
+ /** Whether a window is gone from the host's list: the action closed it. */
3269
+ const isGone = async (id: string): Promise<boolean> => {
3270
+ if (typeof host.listWindows !== 'function') return false
3271
+ try {
3272
+ const listed = rememberWindows(await host.listWindows(callSignal))
3273
+ return !listed.some((window) => window.id === id)
3274
+ } catch {
3275
+ return false
3276
+ }
3277
+ }
3278
+ if (treeEnding && postWindowId !== undefined) {
3279
+ try {
3280
+ await settleAfterActions(host, postWindowId, settings.settleMs, signal)
3281
+ const read = await uiSnapshot({
3282
+ type: 'ui_snapshot',
3283
+ window_id: postWindowId,
3284
+ } as Extract<ActionInput, { type: 'ui_snapshot' }>)
3285
+ const block = Array.isArray(read.content)
3286
+ ? read.content.find((entry) => entry.type === 'text')
3287
+ : undefined
3288
+ treeText = block?.type === 'text' ? block.text : read.output
3289
+ treeData = read.data
3290
+ if (windowsBefore.length > 0 && typeof host.listWindows === 'function') {
3291
+ try {
3292
+ const listed = rememberWindows(await host.listWindows(callSignal))
3293
+ newWindows = listed.filter(
3294
+ (window) =>
3295
+ !windowsBefore.some((old) => old.id === window.id) &&
3296
+ !deniedKeys.has(deniedAppKey(window.app)),
3297
+ )
3298
+ } catch {
3299
+ // A list that fails says nothing; the tree above stands.
3300
+ }
3301
+ }
3302
+ } catch {
3303
+ // Fall back to the picture below; a cancelled call stops there too.
3304
+ if (signal?.aborted) shotError = 'cancelled'
3305
+ else if (await isGone(postWindowId)) windowClosed = postWindowId
3306
+ }
3307
+ }
3308
+ if (looks && treeText === undefined && windowClosed === undefined) {
2789
3309
  try {
2790
3310
  await settleAfterActions(host, postWindowId, settings.settleMs, signal)
2791
3311
  shot = await capture(postWindowId)
2792
3312
  } catch (error) {
2793
3313
  shotError = signal?.aborted ? 'cancelled' : errorText(error)
3314
+ if (!signal?.aborted && postWindowId !== undefined && (await isGone(postWindowId)))
3315
+ windowClosed = postWindowId
3316
+ }
3317
+ }
3318
+ // The window is gone: show what is left of the screen, when the host can.
3319
+ if (
3320
+ windowClosed !== undefined &&
3321
+ shot === undefined &&
3322
+ !signal?.aborted &&
3323
+ hostActionAvailable(caps, 'screenshot')
3324
+ ) {
3325
+ try {
3326
+ shot = await capture()
3327
+ shotError = undefined
3328
+ } catch (error) {
3329
+ shotError = errorText(error)
2794
3330
  }
2795
3331
  }
3332
+ const closedLine =
3333
+ windowClosed !== undefined
3334
+ ? `Window ${visibleWindowId(windowClosed)} is no longer open: the action closed it (or the application did). This is a result, not a failure of the tool; list_windows shows what is open now.${shot ? ' The display screenshot follows.' : ''}`
3335
+ : undefined
3336
+ // A pixel action after which the picture is identical to the one before it did nothing visible.
3337
+ const pixelActed = executed.some((step) => PIXEL_STEPS.has(step.item.type))
3338
+ const noVisibleChange =
3339
+ pixelActed &&
3340
+ shot !== undefined &&
3341
+ frameShot === undefined &&
3342
+ frameBefore !== undefined &&
3343
+ shot.frame !== frameBefore &&
3344
+ (frameBefore.window?.window.id ?? null) === (shot.frame.window?.window.id ?? null) &&
3345
+ frameBefore.imageWidth === shot.frame.imageWidth &&
3346
+ frameBefore.imageHeight === shot.frame.imageHeight &&
3347
+ frameDigest.get(frameBefore.id) !== undefined &&
3348
+ frameDigest.get(frameBefore.id) === frameDigest.get(shot.frame.id)
3349
+ const noChangeLine = noVisibleChange
3350
+ ? `No visible change: the screen looks the same after the settle wait as in ${frameBefore?.id}. The click may have landed without showing it, or it may have missed; check with a fresh look or a control by ref.`
3351
+ : undefined
2796
3352
 
2797
3353
  const summary = (record: StepRecord, index: number): string => {
2798
3354
  const n = single ? '' : `${index + 1}. `
@@ -2824,10 +3380,33 @@ export function createComputerUseTool(
2824
3380
  ? [`The screenshot after acting failed: ${shotError}. Take one before acting again.`]
2825
3381
  : []
2826
3382
  const unknownLines = failure?.unknown ? [failure.unknown.message] : []
2827
- const text = [...header, ...stepLines, ...unknownLines, ...shotLines].join('\n')
3383
+ const afterLines = [
3384
+ ...(closedLine ? [closedLine] : []),
3385
+ ...(noChangeLine ? [noChangeLine] : []),
3386
+ ...(treeText !== undefined ? [treeText] : []),
3387
+ ...(newWindows.length > 0
3388
+ ? [
3389
+ `A new window opened during the batch; read it with ui_snapshot {window_id}:\n${wrapUntrusted(
3390
+ {
3391
+ kind: 'desktop-windows',
3392
+ provenance:
3393
+ "Windows that opened on the user's desktop during the batch, as the host listed them. Titles are whatever each application shows, which can include text anyone wrote.",
3394
+ },
3395
+ newWindows
3396
+ .slice(0, 5)
3397
+ .map((window) => `- ${window.id} · ${JSON.stringify(window.title)} · ${window.app}`)
3398
+ .join('\n'),
3399
+ )}`,
3400
+ ]
3401
+ : []),
3402
+ ]
3403
+ const text = [...header, ...stepLines, ...unknownLines, ...afterLines, ...shotLines].join('\n')
2828
3404
  const output = [
2829
3405
  ...header,
2830
3406
  ...stepLines,
3407
+ ...(closedLine ? [closedLine] : []),
3408
+ ...(noChangeLine ? [noChangeLine] : []),
3409
+ ...(treeText !== undefined ? ['Window controls after the batch follow.'] : []),
2831
3410
  ...(shot
2832
3411
  ? [`Screenshot ${shot.frame.id} (${shot.frame.imageWidth}x${shot.frame.imageHeight}).`]
2833
3412
  : []),
@@ -2853,6 +3432,9 @@ export function createComputerUseTool(
2853
3432
  : { label: record.label, status: record.status },
2854
3433
  ),
2855
3434
  ...(shot ? { screenshot: frameData(shot.frame) } : {}),
3435
+ ...(treeData && typeof treeData === 'object' ? treeData : {}),
3436
+ ...(windowClosed !== undefined ? { windowClosed } : {}),
3437
+ ...(noVisibleChange ? { noVisibleChange: true } : {}),
2856
3438
  ...(failure?.unknown
2857
3439
  ? {
2858
3440
  code: failure.unknown.code,
@@ -3106,6 +3688,117 @@ export function createComputerUseTool(
3106
3688
  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
3689
  }
3108
3690
 
3691
+ /**
3692
+ * Why an action aimed at a browser window may not run, or undefined when it may. `act` allows
3693
+ * it; `ask` allows it once a person has said yes for this browser in this conversation, asking
3694
+ * them the first time. Nobody to ask, or a no, leaves the window look-only and says what the
3695
+ * person can do instead. A no holds for the rest of the turn so one turn does not ask twice.
3696
+ */
3697
+ const browserWindowRefusal = async (
3698
+ app: string,
3699
+ name: string,
3700
+ context: ToolContext,
3701
+ ): Promise<string | undefined> => {
3702
+ if (browserActionsAllowed(app)) return undefined
3703
+ const key = browserKey(app)
3704
+ const ways = (setting: BrowserWindowsSetting) => browserWaysForward(name, setting)
3705
+ if (readBrowserSetting() === 'look')
3706
+ 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. ${ways('look')}`
3707
+ if (!options.askBrowserWindow)
3708
+ return `computer_use only looks at ${name}, a browser, in this session: acting there needs a person's yes and nobody can be asked here. Nothing was done. Use the browser tool, or tell the person what is left for them. ${ways('ask')}`
3709
+ if (browserDeclined.get(key) === String(context.turnId))
3710
+ return `The person said not now to clicking and typing in ${name} in this turn. Nothing was done. Do not ask again this turn. ${ways('ask')}`
3711
+ let answer: BrowserWindowAnswer
3712
+ try {
3713
+ answer = await options.askBrowserWindow({ app, name }, context.abortSignal)
3714
+ } catch {
3715
+ answer = 'unavailable'
3716
+ }
3717
+ if (answer === 'allow') {
3718
+ browserGranted.set(key, name)
3719
+ browserDeclined.delete(key)
3720
+ return undefined
3721
+ }
3722
+ if (answer === 'deny') {
3723
+ browserDeclined.set(key, String(context.turnId))
3724
+ return `The person said not now to clicking and typing in ${name}. Nothing was done. ${ways('ask')}`
3725
+ }
3726
+ return `computer_use only looks at ${name}, a browser: the question whether Namzu may act there was not answered. Nothing was done. ${ways('ask')}`
3727
+ }
3728
+
3729
+ /**
3730
+ * Why this call may not run because of the kind of application it would act in, or undefined:
3731
+ * a browser window is only looked at, a terminal or an editor is clicked but not typed into.
3732
+ * It places the call from what the tool already knows (a window screenshot, the last window list)
3733
+ * and never reads the host for it: acting must not cost a call it would not make. A call it
3734
+ * cannot place is left to the checks that follow, and a terminal's typing is refused by them.
3735
+ * The person's denied list is checked first and stands on top of this.
3736
+ */
3737
+ const appTierRefusal = async (
3738
+ input: ActionInput,
3739
+ context: ToolContext,
3740
+ ): Promise<string | undefined> => {
3741
+ if (isReadOnlyInput(input)) return undefined
3742
+ // A call with no window of its own is placed by the focused window or by bounds: read a fresh list.
3743
+ const loose0: unknown = input
3744
+ const shot0 =
3745
+ isRecord(loose0) && typeof loose0.screenshot_id === 'string'
3746
+ ? loose0.screenshot_id
3747
+ : undefined
3748
+ const unbound = (batchActions(input) ?? [input]).some((item) => {
3749
+ if (!isRecord(item) || boundWindowId(item) !== undefined) return false
3750
+ if (!TYPING_ACTIONS.has(String(item.type)) && !POINTING_ACTIONS.has(String(item.type)))
3751
+ return false
3752
+ const id = typeof item.screenshot_id === 'string' ? item.screenshot_id : shot0
3753
+ const frame = id ? frames.get(id) : frames.latest()
3754
+ return !frame?.window
3755
+ })
3756
+ if (unbound && typeof host.listWindows === 'function') {
3757
+ try {
3758
+ rememberWindows(await host.listWindows(context.abortSignal))
3759
+ } catch {
3760
+ // The checks that follow read the front window before typing.
3761
+ }
3762
+ }
3763
+ const loose: unknown = input
3764
+ const shotId =
3765
+ isRecord(loose) && typeof loose.screenshot_id === 'string' ? loose.screenshot_id : undefined
3766
+ const withShot = (item: Record<string, unknown>): Record<string, unknown> =>
3767
+ shotId && item.screenshot_id === undefined ? { ...item, screenshot_id: shotId } : item
3768
+ for (const item of batchActions(input) ?? [input]) {
3769
+ if (!isRecord(item)) continue
3770
+ const type = String(item.type)
3771
+ const setsValue =
3772
+ (type === 'ui_act' || type === 'ui_do') &&
3773
+ (item.action === 'set_value' || typeof item.value === 'string')
3774
+ if (!TYPING_ACTIONS.has(type) && !POINTING_ACTIONS.has(type)) continue
3775
+ const placed = appsKnown(withShot(item))
3776
+ for (const app of placed) {
3777
+ const tier = appTier(app)
3778
+ const name = applicationName(app)
3779
+ if (tier === 'view' && type === 'key' && onlyScrollKeys(item.keys)) continue
3780
+ if (tier === 'view') {
3781
+ const refused = await browserWindowRefusal(app, name, context)
3782
+ if (refused) return refused
3783
+ // A granted browser still never gets a secret typed by the tool: the person types it.
3784
+ const ref = typeof item.ref === 'string' ? uiRefs.get(item.ref) : undefined
3785
+ if (
3786
+ (type === 'type_text' && focusedSecret) ||
3787
+ (setsValue && ref !== undefined && isSecretElement(ref.element))
3788
+ )
3789
+ return `computer_use does not type into a password field in ${name}. Nothing was done. Ask the person to type it themselves, then continue.`
3790
+ }
3791
+ if (
3792
+ tier === 'click' &&
3793
+ !appIs(TERMINAL_APPS, app) &&
3794
+ (TYPING_ACTIONS.has(type) || setsValue)
3795
+ )
3796
+ 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.`
3797
+ }
3798
+ }
3799
+ return undefined
3800
+ }
3801
+
3109
3802
  const runAction = async (input: ActionInput, context: ToolContext): Promise<ToolResult> => {
3110
3803
  const denied = refusal(input.type)
3111
3804
  if (denied) return { success: false, output: '', error: denied }
@@ -3124,7 +3817,7 @@ export function createComputerUseTool(
3124
3817
  try {
3125
3818
  switch (input.type) {
3126
3819
  case 'screenshot':
3127
- return screenshotResult(await capture(input.window_id))
3820
+ return await firstLookWithTree(await capture(input.window_id), input.window_id)
3128
3821
  case 'zoom':
3129
3822
  return await zoom(input)
3130
3823
  case 'ui_snapshot':
@@ -3153,7 +3846,7 @@ export function createComputerUseTool(
3153
3846
 
3154
3847
  const tool = defineTool({
3155
3848
  name: COMPUTER_USE_TOOL_NAME,
3156
- description: buildDescription(host, caps, settings, options.advisor),
3849
+ description: buildDescription(host, caps, settings, options.advisor, browserSetting),
3157
3850
  inputSchema: actionSchema,
3158
3851
  modelInputSchema: hostModelSchema(host, caps, settings, options.advisor),
3159
3852
  validationErrorHint: `Action requirements: ${ALL_ACTIONS.map((action) => actionRequirement(action, host, caps)).join('; ')}. A batch is {"type":"batch","actions":[...]} with at most ${settings.maxBatchActions} actions and no screenshot, zoom, ui_snapshot or batch inside.`,
@@ -3190,6 +3883,8 @@ export function createComputerUseTool(
3190
3883
  async execute(input, context): Promise<ToolResult> {
3191
3884
  const keptOut = await deniedAppRefusal(input, context)
3192
3885
  if (keptOut) return { success: false, output: '', error: keptOut }
3886
+ const tiered = await appTierRefusal(input, context)
3887
+ if (tiered) return { success: false, output: '', error: tiered }
3193
3888
  const shotId = 'screenshot_id' in input ? input.screenshot_id : undefined
3194
3889
  const before = shotId ? frames.get(shotId) : frames.latest()
3195
3890
  // Only what is already known: acting must not cost the host a call it would not make.
@@ -3197,11 +3892,29 @@ export function createComputerUseTool(
3197
3892
  const result = await runAction(input, context)
3198
3893
  if (app && result.success !== false && !appsUsed.has(app) && !isReadOnlyInput(input)) {
3199
3894
  appsUsed.add(app)
3200
- result.data = { ...(isRecord(result.data) ? result.data : {}), firstUseOf: app }
3895
+ result.data = {
3896
+ ...(isRecord(result.data) ? result.data : {}),
3897
+ firstUseOf: app,
3898
+ }
3201
3899
  }
3202
3900
  await observe(input, before, result, context.toolUseId, app)
3203
3901
  return result
3204
3902
  },
3205
3903
  })
3206
- return Object.assign(tool, { describeUiRef, appOf, appsOf, consequence })
3904
+ const browserQuestionPending = (app: string): boolean =>
3905
+ appTier(app) === 'view' &&
3906
+ readBrowserSetting() === 'ask' &&
3907
+ options.askBrowserWindow !== undefined &&
3908
+ !browserGranted.has(browserKey(app))
3909
+ return Object.assign(tool, {
3910
+ describeUiRef,
3911
+ appOf,
3912
+ appsOf,
3913
+ consequence,
3914
+ browserGrants: (): string[] => [...browserGranted.values()],
3915
+ revokeBrowserGrant: (app: string): boolean => browserGranted.delete(browserKey(app)),
3916
+ browserQuestionPending,
3917
+ browserAsk: (input: unknown, apps: readonly string[]): string[] =>
3918
+ isReadOnlyInput(input) ? [] : apps.filter((app) => browserQuestionPending(app)),
3919
+ })
3207
3920
  }