@namzu/sdk 51.1.0 → 52.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 (395) hide show
  1. package/CHANGELOG.md +119 -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/agents/SupervisorAgent.d.ts +1 -1
  6. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  7. package/dist/agents/SupervisorAgent.js.map +1 -1
  8. package/dist/agents/examples/SupervisorAgent.d.ts +42 -0
  9. package/dist/agents/examples/SupervisorAgent.d.ts.map +1 -1
  10. package/dist/agents/examples/SupervisorAgent.js +80 -4
  11. package/dist/agents/examples/SupervisorAgent.js.map +1 -1
  12. package/dist/agents/index.d.ts +1 -1
  13. package/dist/agents/index.d.ts.map +1 -1
  14. package/dist/agents/index.js.map +1 -1
  15. package/dist/authorization/protected-paths.d.ts +36 -0
  16. package/dist/authorization/protected-paths.d.ts.map +1 -0
  17. package/dist/authorization/protected-paths.js +107 -0
  18. package/dist/authorization/protected-paths.js.map +1 -0
  19. package/dist/authorization/readonly-commands.d.ts +39 -0
  20. package/dist/authorization/readonly-commands.d.ts.map +1 -0
  21. package/dist/authorization/readonly-commands.js +797 -0
  22. package/dist/authorization/readonly-commands.js.map +1 -0
  23. package/dist/authorization/readonly-flags.d.ts +19 -0
  24. package/dist/authorization/readonly-flags.d.ts.map +1 -0
  25. package/dist/authorization/readonly-flags.js +178 -0
  26. package/dist/authorization/readonly-flags.js.map +1 -0
  27. package/dist/authorization/removal.d.ts +52 -0
  28. package/dist/authorization/removal.d.ts.map +1 -0
  29. package/dist/authorization/removal.js +283 -0
  30. package/dist/authorization/removal.js.map +1 -0
  31. package/dist/authorization/shell-paths.d.ts +66 -0
  32. package/dist/authorization/shell-paths.d.ts.map +1 -0
  33. package/dist/authorization/shell-paths.js +697 -0
  34. package/dist/authorization/shell-paths.js.map +1 -0
  35. package/dist/bridge/acp/update.d.ts.map +1 -1
  36. package/dist/bridge/acp/update.js +1 -0
  37. package/dist/bridge/acp/update.js.map +1 -1
  38. package/dist/compaction/context-window.d.ts +24 -0
  39. package/dist/compaction/context-window.d.ts.map +1 -1
  40. package/dist/compaction/context-window.js +34 -0
  41. package/dist/compaction/context-window.js.map +1 -1
  42. package/dist/compaction/manual.d.ts.map +1 -1
  43. package/dist/compaction/manual.js +10 -2
  44. package/dist/compaction/manual.js.map +1 -1
  45. package/dist/compaction/plan.d.ts +4 -0
  46. package/dist/compaction/plan.d.ts.map +1 -1
  47. package/dist/compaction/plan.js +6 -2
  48. package/dist/compaction/plan.js.map +1 -1
  49. package/dist/compaction/verifier.d.ts +11 -1
  50. package/dist/compaction/verifier.d.ts.map +1 -1
  51. package/dist/compaction/verifier.js +75 -23
  52. package/dist/compaction/verifier.js.map +1 -1
  53. package/dist/config/runtime.d.ts +55 -7
  54. package/dist/config/runtime.d.ts.map +1 -1
  55. package/dist/config/runtime.js +23 -2
  56. package/dist/config/runtime.js.map +1 -1
  57. package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
  58. package/dist/connector/web/guarded-fetch.js +24 -0
  59. package/dist/connector/web/guarded-fetch.js.map +1 -1
  60. package/dist/connector/web/index.d.ts +1 -1
  61. package/dist/connector/web/index.d.ts.map +1 -1
  62. package/dist/connector/web/page.d.ts +59 -0
  63. package/dist/connector/web/page.d.ts.map +1 -0
  64. package/dist/connector/web/page.js +112 -0
  65. package/dist/connector/web/page.js.map +1 -0
  66. package/dist/connector/web/types.d.ts +47 -0
  67. package/dist/connector/web/types.d.ts.map +1 -1
  68. package/dist/connector/web/types.js.map +1 -1
  69. package/dist/constants/continuation.d.ts +8 -0
  70. package/dist/constants/continuation.d.ts.map +1 -1
  71. package/dist/constants/continuation.js +8 -0
  72. package/dist/constants/continuation.js.map +1 -1
  73. package/dist/constants/plugin/index.d.ts +1 -1
  74. package/dist/constants/plugin/index.d.ts.map +1 -1
  75. package/dist/constants/plugin/index.js +1 -1
  76. package/dist/constants/plugin/index.js.map +1 -1
  77. package/dist/contracts/a2a.d.ts +2 -2
  78. package/dist/manager/agent/lifecycle.d.ts +7 -0
  79. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  80. package/dist/manager/agent/lifecycle.js +11 -2
  81. package/dist/manager/agent/lifecycle.js.map +1 -1
  82. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  83. package/dist/manager/session/turn-recorder.js +4 -2
  84. package/dist/manager/session/turn-recorder.js.map +1 -1
  85. package/dist/plugin/index.d.ts +1 -1
  86. package/dist/plugin/index.d.ts.map +1 -1
  87. package/dist/plugin/index.js +1 -1
  88. package/dist/plugin/index.js.map +1 -1
  89. package/dist/plugin/lifecycle.d.ts +6 -0
  90. package/dist/plugin/lifecycle.d.ts.map +1 -1
  91. package/dist/plugin/lifecycle.js +98 -114
  92. package/dist/plugin/lifecycle.js.map +1 -1
  93. package/dist/plugin/shell-hook.d.ts +90 -22
  94. package/dist/plugin/shell-hook.d.ts.map +1 -1
  95. package/dist/plugin/shell-hook.js +434 -41
  96. package/dist/plugin/shell-hook.js.map +1 -1
  97. package/dist/provider/capabilities.d.ts +9 -0
  98. package/dist/provider/capabilities.d.ts.map +1 -1
  99. package/dist/provider/capabilities.js +15 -0
  100. package/dist/provider/capabilities.js.map +1 -1
  101. package/dist/provider/errors.d.ts.map +1 -1
  102. package/dist/provider/errors.js +13 -0
  103. package/dist/provider/errors.js.map +1 -1
  104. package/dist/provider/fallback.d.ts.map +1 -1
  105. package/dist/provider/fallback.js +10 -0
  106. package/dist/provider/fallback.js.map +1 -1
  107. package/dist/provider/idle-timeout.d.ts.map +1 -1
  108. package/dist/provider/idle-timeout.js +5 -0
  109. package/dist/provider/idle-timeout.js.map +1 -1
  110. package/dist/provider/image-input-refusal.d.ts +9 -0
  111. package/dist/provider/image-input-refusal.d.ts.map +1 -0
  112. package/dist/provider/image-input-refusal.js +54 -0
  113. package/dist/provider/image-input-refusal.js.map +1 -0
  114. package/dist/provider/index.d.ts +2 -1
  115. package/dist/provider/index.d.ts.map +1 -1
  116. package/dist/provider/index.js +2 -1
  117. package/dist/provider/index.js.map +1 -1
  118. package/dist/provider/retry.d.ts +7 -2
  119. package/dist/provider/retry.d.ts.map +1 -1
  120. package/dist/provider/retry.js +38 -4
  121. package/dist/provider/retry.js.map +1 -1
  122. package/dist/public-runtime.d.ts +5 -2
  123. package/dist/public-runtime.d.ts.map +1 -1
  124. package/dist/public-runtime.js +5 -2
  125. package/dist/public-runtime.js.map +1 -1
  126. package/dist/public-types.d.ts +2 -2
  127. package/dist/public-types.d.ts.map +1 -1
  128. package/dist/runtime/jobs/registry.d.ts +21 -0
  129. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  130. package/dist/runtime/jobs/registry.js +15 -2
  131. package/dist/runtime/jobs/registry.js.map +1 -1
  132. package/dist/runtime/query/deferred-sandbox.d.ts +54 -0
  133. package/dist/runtime/query/deferred-sandbox.d.ts.map +1 -0
  134. package/dist/runtime/query/deferred-sandbox.js +75 -0
  135. package/dist/runtime/query/deferred-sandbox.js.map +1 -0
  136. package/dist/runtime/query/executor/tool-call-admission.d.ts +10 -0
  137. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  138. package/dist/runtime/query/executor/tool-call-admission.js +74 -13
  139. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  140. package/dist/runtime/query/executor.d.ts +51 -2
  141. package/dist/runtime/query/executor.d.ts.map +1 -1
  142. package/dist/runtime/query/executor.js +214 -9
  143. package/dist/runtime/query/executor.js.map +1 -1
  144. package/dist/runtime/query/finalize-turn.d.ts +6 -0
  145. package/dist/runtime/query/finalize-turn.d.ts.map +1 -1
  146. package/dist/runtime/query/finalize-turn.js +1 -1
  147. package/dist/runtime/query/finalize-turn.js.map +1 -1
  148. package/dist/runtime/query/index.d.ts +29 -0
  149. package/dist/runtime/query/index.d.ts.map +1 -1
  150. package/dist/runtime/query/index.js +108 -28
  151. package/dist/runtime/query/index.js.map +1 -1
  152. package/dist/runtime/query/iteration/index.d.ts +57 -0
  153. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  154. package/dist/runtime/query/iteration/index.js +380 -28
  155. package/dist/runtime/query/iteration/index.js.map +1 -1
  156. package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts +61 -0
  157. package/dist/runtime/query/iteration/phases/compaction-breaker.d.ts.map +1 -0
  158. package/dist/runtime/query/iteration/phases/compaction-breaker.js +94 -0
  159. package/dist/runtime/query/iteration/phases/compaction-breaker.js.map +1 -0
  160. package/dist/runtime/query/iteration/phases/compaction.d.ts +42 -1
  161. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  162. package/dist/runtime/query/iteration/phases/compaction.js +203 -23
  163. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  164. package/dist/runtime/query/iteration/phases/context.d.ts +10 -0
  165. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  166. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  167. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  168. package/dist/runtime/query/iteration/phases/tool-review.js +165 -2
  169. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  170. package/dist/runtime/query/iteration/provider-rejected-image.d.ts +21 -1
  171. package/dist/runtime/query/iteration/provider-rejected-image.d.ts.map +1 -1
  172. package/dist/runtime/query/iteration/provider-rejected-image.js +53 -7
  173. package/dist/runtime/query/iteration/provider-rejected-image.js.map +1 -1
  174. package/dist/runtime/query/iteration/request-repair.d.ts +108 -0
  175. package/dist/runtime/query/iteration/request-repair.d.ts.map +1 -0
  176. package/dist/runtime/query/iteration/request-repair.js +593 -0
  177. package/dist/runtime/query/iteration/request-repair.js.map +1 -0
  178. package/dist/runtime/query/iteration/stream-turn.d.ts +6 -0
  179. package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
  180. package/dist/runtime/query/iteration/stream-turn.js +2 -2
  181. package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
  182. package/dist/runtime/query/path-escalation.d.ts +36 -0
  183. package/dist/runtime/query/path-escalation.d.ts.map +1 -0
  184. package/dist/runtime/query/path-escalation.js +184 -0
  185. package/dist/runtime/query/path-escalation.js.map +1 -0
  186. package/dist/runtime/query/plugin-hooks.d.ts.map +1 -1
  187. package/dist/runtime/query/plugin-hooks.js +8 -0
  188. package/dist/runtime/query/plugin-hooks.js.map +1 -1
  189. package/dist/runtime/query/reminders.d.ts +35 -0
  190. package/dist/runtime/query/reminders.d.ts.map +1 -0
  191. package/dist/runtime/query/reminders.js +7 -0
  192. package/dist/runtime/query/reminders.js.map +1 -0
  193. package/dist/runtime/query/request-rich-content.d.ts +5 -1
  194. package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
  195. package/dist/runtime/query/request-rich-content.js +67 -25
  196. package/dist/runtime/query/request-rich-content.js.map +1 -1
  197. package/dist/runtime/query/resume-pending.d.ts.map +1 -1
  198. package/dist/runtime/query/resume-pending.js +26 -0
  199. package/dist/runtime/query/resume-pending.js.map +1 -1
  200. package/dist/runtime/query/review-policy.d.ts +26 -0
  201. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  202. package/dist/runtime/query/review-policy.js +79 -5
  203. package/dist/runtime/query/review-policy.js.map +1 -1
  204. package/dist/runtime/query/tool-output-budget.d.ts +46 -0
  205. package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
  206. package/dist/runtime/query/tool-output-budget.js +85 -1
  207. package/dist/runtime/query/tool-output-budget.js.map +1 -1
  208. package/dist/runtime/query/tooling.d.ts +1 -0
  209. package/dist/runtime/query/tooling.d.ts.map +1 -1
  210. package/dist/runtime/query/tooling.js +5 -0
  211. package/dist/runtime/query/tooling.js.map +1 -1
  212. package/dist/session/paths.d.ts +5 -1
  213. package/dist/session/paths.d.ts.map +1 -1
  214. package/dist/session/paths.js +8 -0
  215. package/dist/session/paths.js.map +1 -1
  216. package/dist/store/memory/disk.d.ts.map +1 -1
  217. package/dist/store/memory/disk.js +2 -2
  218. package/dist/store/memory/disk.js.map +1 -1
  219. package/dist/store/memory/markdown.d.ts.map +1 -1
  220. package/dist/store/memory/markdown.js +2 -2
  221. package/dist/store/memory/markdown.js.map +1 -1
  222. package/dist/store/memory/naming.d.ts +9 -0
  223. package/dist/store/memory/naming.d.ts.map +1 -1
  224. package/dist/store/memory/naming.js +12 -0
  225. package/dist/store/memory/naming.js.map +1 -1
  226. package/dist/tools/builtins/bash.d.ts +30 -1
  227. package/dist/tools/builtins/bash.d.ts.map +1 -1
  228. package/dist/tools/builtins/bash.js +170 -26
  229. package/dist/tools/builtins/bash.js.map +1 -1
  230. package/dist/tools/builtins/computer-use.d.ts +1 -1
  231. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  232. package/dist/tools/builtins/computer-use.js +12 -5
  233. package/dist/tools/builtins/computer-use.js.map +1 -1
  234. package/dist/tools/builtins/content-fingerprint.d.ts +2 -0
  235. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  236. package/dist/tools/builtins/content-fingerprint.js +4 -0
  237. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  238. package/dist/tools/builtins/edit.d.ts.map +1 -1
  239. package/dist/tools/builtins/edit.js +60 -18
  240. package/dist/tools/builtins/edit.js.map +1 -1
  241. package/dist/tools/builtins/grep.d.ts +8 -1
  242. package/dist/tools/builtins/grep.d.ts.map +1 -1
  243. package/dist/tools/builtins/grep.js +152 -33
  244. package/dist/tools/builtins/grep.js.map +1 -1
  245. package/dist/tools/builtins/read-file.d.ts +1 -0
  246. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  247. package/dist/tools/builtins/read-file.js +44 -5
  248. package/dist/tools/builtins/read-file.js.map +1 -1
  249. package/dist/tools/builtins/read-render.d.ts +52 -0
  250. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  251. package/dist/tools/builtins/read-render.js +143 -0
  252. package/dist/tools/builtins/read-render.js.map +1 -1
  253. package/dist/tools/builtins/web.d.ts +13 -2
  254. package/dist/tools/builtins/web.d.ts.map +1 -1
  255. package/dist/tools/builtins/web.js +225 -32
  256. package/dist/tools/builtins/web.js.map +1 -1
  257. package/dist/tools/coordinator/ask-user-question.d.ts +2 -0
  258. package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
  259. package/dist/tools/coordinator/ask-user-question.js +256 -92
  260. package/dist/tools/coordinator/ask-user-question.js.map +1 -1
  261. package/dist/tools/coordinator/question-options.d.ts +1 -0
  262. package/dist/tools/coordinator/question-options.d.ts.map +1 -1
  263. package/dist/tools/coordinator/question-options.js +6 -1
  264. package/dist/tools/coordinator/question-options.js.map +1 -1
  265. package/dist/tools/defineTool.d.ts +4 -1
  266. package/dist/tools/defineTool.d.ts.map +1 -1
  267. package/dist/tools/defineTool.js +6 -1
  268. package/dist/tools/defineTool.js.map +1 -1
  269. package/dist/tools/paths.d.ts +6 -0
  270. package/dist/tools/paths.d.ts.map +1 -1
  271. package/dist/tools/paths.js +1 -1
  272. package/dist/tools/paths.js.map +1 -1
  273. package/dist/types/agent/query.d.ts +3 -0
  274. package/dist/types/agent/query.d.ts.map +1 -1
  275. package/dist/types/errors/catalog.js +1 -1
  276. package/dist/types/errors/catalog.js.map +1 -1
  277. package/dist/types/hitl/index.d.ts +104 -0
  278. package/dist/types/hitl/index.d.ts.map +1 -1
  279. package/dist/types/hitl/index.js.map +1 -1
  280. package/dist/types/message/index.d.ts +1 -1
  281. package/dist/types/message/index.d.ts.map +1 -1
  282. package/dist/types/message/index.js +2 -0
  283. package/dist/types/message/index.js.map +1 -1
  284. package/dist/types/plugin/index.d.ts +93 -19
  285. package/dist/types/plugin/index.d.ts.map +1 -1
  286. package/dist/types/plugin/index.js +3 -0
  287. package/dist/types/plugin/index.js.map +1 -1
  288. package/dist/types/provider/errors.d.ts +19 -0
  289. package/dist/types/provider/errors.d.ts.map +1 -1
  290. package/dist/types/provider/errors.js +54 -5
  291. package/dist/types/provider/errors.js.map +1 -1
  292. package/dist/types/provider/interface.d.ts +12 -0
  293. package/dist/types/provider/interface.d.ts.map +1 -1
  294. package/dist/types/provider/stream.d.ts +1 -1
  295. package/dist/types/session/config.d.ts +14 -0
  296. package/dist/types/session/config.d.ts.map +1 -1
  297. package/dist/types/session/events.d.ts +27 -4
  298. package/dist/types/session/events.d.ts.map +1 -1
  299. package/dist/types/session/events.js.map +1 -1
  300. package/dist/types/session/records.d.ts +9 -9
  301. package/dist/types/session/records.d.ts.map +1 -1
  302. package/dist/types/session/records.js +1 -0
  303. package/dist/types/session/records.js.map +1 -1
  304. package/dist/types/session/stop-reason.d.ts +5 -0
  305. package/dist/types/session/stop-reason.d.ts.map +1 -1
  306. package/dist/types/tool/index.d.ts +52 -0
  307. package/dist/types/tool/index.d.ts.map +1 -1
  308. package/dist/types/tool/index.js.map +1 -1
  309. package/package.json +4 -2
  310. package/src/agents/QueryAgent.ts +5 -1
  311. package/src/agents/SupervisorAgent.ts +1 -1
  312. package/src/agents/examples/SupervisorAgent.ts +217 -106
  313. package/src/agents/index.ts +1 -1
  314. package/src/authorization/protected-paths.ts +110 -0
  315. package/src/authorization/readonly-commands.ts +771 -0
  316. package/src/authorization/readonly-flags.ts +196 -0
  317. package/src/authorization/removal.ts +326 -0
  318. package/src/authorization/shell-paths.ts +927 -0
  319. package/src/bridge/acp/update.ts +1 -0
  320. package/src/compaction/context-window.ts +41 -0
  321. package/src/compaction/manual.ts +10 -2
  322. package/src/compaction/plan.ts +11 -2
  323. package/src/compaction/verifier.ts +84 -22
  324. package/src/config/runtime.ts +23 -2
  325. package/src/connector/web/guarded-fetch.ts +26 -0
  326. package/src/connector/web/index.ts +3 -0
  327. package/src/connector/web/page.ts +130 -0
  328. package/src/connector/web/types.ts +47 -0
  329. package/src/constants/continuation.ts +10 -0
  330. package/src/constants/plugin/index.ts +1 -1
  331. package/src/manager/agent/lifecycle.ts +12 -4
  332. package/src/manager/session/turn-recorder.ts +10 -2
  333. package/src/plugin/index.ts +1 -0
  334. package/src/plugin/lifecycle.ts +107 -119
  335. package/src/plugin/shell-hook.ts +477 -43
  336. package/src/provider/capabilities.ts +17 -0
  337. package/src/provider/errors.ts +13 -0
  338. package/src/provider/fallback.ts +10 -0
  339. package/src/provider/idle-timeout.ts +5 -0
  340. package/src/provider/image-input-refusal.ts +54 -0
  341. package/src/provider/index.ts +2 -0
  342. package/src/provider/retry.ts +42 -4
  343. package/src/public-runtime.ts +11 -0
  344. package/src/public-types.ts +4 -0
  345. package/src/runtime/jobs/registry.ts +39 -2
  346. package/src/runtime/query/deferred-sandbox.ts +110 -0
  347. package/src/runtime/query/executor/tool-call-admission.ts +79 -13
  348. package/src/runtime/query/executor.ts +267 -11
  349. package/src/runtime/query/finalize-turn.ts +7 -1
  350. package/src/runtime/query/index.ts +169 -52
  351. package/src/runtime/query/iteration/index.ts +439 -35
  352. package/src/runtime/query/iteration/phases/compaction-breaker.ts +108 -0
  353. package/src/runtime/query/iteration/phases/compaction.ts +241 -38
  354. package/src/runtime/query/iteration/phases/context.ts +11 -0
  355. package/src/runtime/query/iteration/phases/tool-review.ts +177 -2
  356. package/src/runtime/query/iteration/provider-rejected-image.ts +71 -5
  357. package/src/runtime/query/iteration/request-repair.ts +743 -0
  358. package/src/runtime/query/iteration/stream-turn.ts +11 -1
  359. package/src/runtime/query/path-escalation.ts +204 -0
  360. package/src/runtime/query/plugin-hooks.ts +8 -0
  361. package/src/runtime/query/reminders.ts +45 -0
  362. package/src/runtime/query/request-rich-content.ts +77 -27
  363. package/src/runtime/query/resume-pending.ts +27 -0
  364. package/src/runtime/query/review-policy.ts +106 -5
  365. package/src/runtime/query/tool-output-budget.ts +115 -1
  366. package/src/runtime/query/tooling.ts +6 -0
  367. package/src/session/paths.ts +11 -1
  368. package/src/store/memory/disk.ts +2 -1
  369. package/src/store/memory/markdown.ts +2 -1
  370. package/src/store/memory/naming.ts +13 -0
  371. package/src/tools/builtins/bash.ts +203 -34
  372. package/src/tools/builtins/computer-use.ts +13 -4
  373. package/src/tools/builtins/content-fingerprint.ts +5 -0
  374. package/src/tools/builtins/edit.ts +69 -19
  375. package/src/tools/builtins/grep.ts +159 -38
  376. package/src/tools/builtins/read-file.ts +48 -5
  377. package/src/tools/builtins/read-render.ts +193 -0
  378. package/src/tools/builtins/web.ts +258 -33
  379. package/src/tools/coordinator/ask-user-question.ts +309 -103
  380. package/src/tools/coordinator/question-options.ts +8 -1
  381. package/src/tools/defineTool.ts +11 -2
  382. package/src/tools/paths.ts +1 -1
  383. package/src/types/agent/query.ts +3 -0
  384. package/src/types/errors/catalog.ts +1 -1
  385. package/src/types/hitl/index.ts +104 -0
  386. package/src/types/message/index.ts +2 -0
  387. package/src/types/plugin/index.ts +101 -18
  388. package/src/types/provider/errors.ts +66 -5
  389. package/src/types/provider/interface.ts +13 -0
  390. package/src/types/provider/stream.ts +1 -1
  391. package/src/types/session/config.ts +14 -0
  392. package/src/types/session/events.ts +32 -4
  393. package/src/types/session/records.ts +1 -0
  394. package/src/types/session/stop-reason.ts +5 -0
  395. package/src/types/tool/index.ts +53 -2
@@ -1,6 +1,7 @@
1
1
  import { EMPTY_TOKEN_USAGE } from '../../constants/limits.js'
2
2
  import { drainQuery } from '../../runtime/query/index.js'
3
3
  import { PendingAnswers, QuestionParkBinding } from '../../runtime/query/question-park.js'
4
+ import { resumeSession } from '../../runtime/query/resume-session.js'
4
5
  import { CompletionInbox } from '../../scheduler/completion-inbox.js'
5
6
  import { LocalTaskScheduler } from '../../scheduler/local.js'
6
7
  import {
@@ -18,10 +19,13 @@ import type {
18
19
  } from '../../types/agent/index.js'
19
20
  import type { TaskHandle, TaskScheduler } from '../../types/agent/scheduler.js'
20
21
  import type { AgentTaskContext } from '../../types/agent/task.js'
22
+ import { NamzuError } from '../../types/errors/index.js'
23
+ import { type HITLResumeDecision, autoApproveHandler } from '../../types/hitl/index.js'
21
24
  import type { SessionId, TurnId } from '../../types/ids/index.js'
22
25
  import { deriveChildState } from '../../types/invocation/index.js'
23
26
  import type { ActorRef } from '../../types/session/actor.js'
24
27
  import type { SessionEventListener } from '../../types/session/events.js'
28
+ import type { TurnState } from '../../types/session/index.js'
25
29
  import type { ToolDefinition } from '../../types/tool/index.js'
26
30
  import { ZERO_COST } from '../../utils/cost.js'
27
31
  import type { Logger } from '../../utils/logger.js'
@@ -71,6 +75,24 @@ export function countCompletedTasks(taskResults: readonly AgentTaskResult[]): nu
71
75
  return taskResults.filter((t) => t.result.status === 'completed').length
72
76
  }
73
77
 
78
+ /**
79
+ * Which paused turn {@link SupervisorAgent.resume} continues.
80
+ */
81
+ export interface SupervisorResumeTarget {
82
+ /** The turn that ended in `turn_paused`. It keeps this id. */
83
+ readonly turnId: TurnId
84
+ /**
85
+ * A specific checkpoint of that turn. Absent means the one an open
86
+ * decision references, else the newest, as `resumeSession` chooses.
87
+ */
88
+ readonly checkpointId?: TurnState['checkpointId']
89
+ /**
90
+ * The answer to a park the checkpoint is waiting on. Without it a turn
91
+ * parked on a decision is refused rather than stepped past.
92
+ */
93
+ readonly pendingDecision?: HITLResumeDecision
94
+ }
95
+
74
96
  /** @deprecated Example of supervised delegation; hosts can compose their own agent. */
75
97
  export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, SupervisorAgentResult> {
76
98
  readonly type = 'supervisor' as const
@@ -110,10 +132,38 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
110
132
  )
111
133
  }
112
134
 
135
+ /**
136
+ * Continue a turn that ended in `turn_paused`: the SAME `turnId`, from the
137
+ * selected checkpoint, with the context folded from the session log.
138
+ *
139
+ * Takes what `run` takes and rebuilds the same delegation, budget and
140
+ * scheduler wiring for the turn, then hands the turn to `resumeSession`.
141
+ * `input.messages` is ignored: the transcript is the log's. `config` must
142
+ * carry the `sessionLog` (and `checkpointStore`, if it is not the one
143
+ * beside the log) the turn was written to.
144
+ *
145
+ * Emits the same `turn_paused` and terminal events as `run`, so a host
146
+ * bounds its resumes by counting `turn_paused`. Rejects with a
147
+ * `NamzuError` (`invalid_config`) when the turn is unknown, already
148
+ * ended, has no checkpoint, or waits on a decision `target` does not
149
+ * answer.
150
+ */
151
+ async resume(
152
+ input: AgentInput,
153
+ config: SupervisorAgentConfig,
154
+ target: SupervisorResumeTarget,
155
+ listener?: SessionEventListener,
156
+ ): Promise<SupervisorAgentResult> {
157
+ return await this.underIdempotencyKey(config.idempotencyKey, () =>
158
+ this.underInvocationLock(() => this.runExclusive(input, config, listener, target)),
159
+ )
160
+ }
161
+
113
162
  private async runExclusive(
114
163
  input: AgentInput,
115
164
  config: SupervisorAgentConfig,
116
165
  listener?: SessionEventListener,
166
+ resume?: SupervisorResumeTarget,
117
167
  ): Promise<SupervisorAgentResult> {
118
168
  const startTime = Date.now()
119
169
  if (!config.sessionId || !config.topicId || !config.projectId || !config.tenantId) {
@@ -122,7 +172,14 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
122
172
  )
123
173
  }
124
174
  const sessionId = config.sessionId
125
- const turnId = this.createTurnId()
175
+ if (resume && !config.sessionLog) {
176
+ throw new NamzuError({
177
+ code: 'invalid_config',
178
+ message:
179
+ 'SupervisorAgent.resume requires config.sessionLog: the log the paused turn was written to.',
180
+ })
181
+ }
182
+ const turnId = resume?.turnId ?? this.createTurnId()
126
183
  this.bindTurn(sessionId, turnId, config.logger)
127
184
  const topicId = config.topicId
128
185
  const projectId = config.projectId
@@ -325,114 +382,115 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
325
382
  this.metadata.id,
326
383
  )
327
384
 
328
- const turn = await drainQuery(
329
- {
330
- systemPrompt: config.systemPrompt,
331
- skills: config.skills,
332
- provider: config.provider,
333
- toolsets,
334
- ...(config.toolResultGuardrails !== undefined
335
- ? { toolResultGuardrails: config.toolResultGuardrails }
336
- : {}),
337
- ...(input.attachmentStore ? { attachmentStore: input.attachmentStore } : {}),
338
- ...(config.attachmentResolveTimeoutMs !== undefined
339
- ? { attachmentResolveTimeoutMs: config.attachmentResolveTimeoutMs }
340
- : {}),
341
- turnConfig: {
342
- model: config.model,
343
- tokenBudget: config.tokenBudget,
344
- timeoutMs: config.timeoutMs,
345
- ...(config.sandbox ? { sandbox: config.sandbox } : {}),
346
- ...(config.streamIdleTimeoutMs !== undefined
347
- ? { streamIdleTimeoutMs: config.streamIdleTimeoutMs }
348
- : {}),
349
- ...(config.maxRequestRichContentBytes !== undefined
350
- ? {
351
- maxRequestRichContentBytes: config.maxRequestRichContentBytes,
352
- }
353
- : {}),
354
- maxIterations: config.maxIterations,
355
- temperature: config.temperature,
356
- env: config.env,
357
- ...(config.pruneKeepLast !== undefined ? { pruneKeepLast: config.pruneKeepLast } : {}),
358
- logger: this.log,
359
- // See ReactiveAgent: a hand-listed literal drops what nobody
360
- // remembered to add, and reports nothing when it does.
361
- ...(config.thinking ? { thinking: config.thinking } : {}),
362
- ...(config.effort ? { effort: config.effort } : {}),
363
- },
364
- questionParks,
365
- pendingAnswers,
366
- // How wide a fan-out actually runs. Absent leaves the kernel
367
- // default — the same forwarding ReactiveAgent has always done,
368
- // missing from the one agent whose job is delegation.
369
- ...(config.maxToolConcurrency !== undefined
370
- ? { maxToolConcurrency: config.maxToolConcurrency }
371
- : {}),
372
- agentId: this.metadata.id,
373
- agentName: this.metadata.name,
374
- workingDirectory: input.workingDirectory,
375
- messages: input.messages,
376
- signal: input.signal,
377
- sessionId,
378
- topicId,
379
- projectId,
380
- tenantId,
381
- turnId,
382
- ...(config.parentSessionId ? { parentSessionId: config.parentSessionId } : {}),
383
- ...(config.parentTurnId ? { parentTurnId: config.parentTurnId } : {}),
384
- depth: config.depth,
385
- contextLevel: 'full',
386
- onContextCreated: ({ planManager }) => {
387
- planManagerRef = planManager
388
- },
389
- taskStore: input.taskStore,
390
- runtimeToolOverrides: input.runtimeToolOverrides,
391
- runtimeContext: input.runtimeContext,
392
- taskScheduler: gateway,
393
- budget,
394
- completionInbox,
395
- advisory: config.advisory,
396
- invocationState: childInvocationState,
397
- // HITL surface: forward optional review-time hooks so hosts can
398
- // run "Ask before acting" supervisors instead of the default
399
- // auto-approve. drainQuery falls back to autoApproveHandler
400
- // when resumeHandler is omitted (= same behaviour as before).
401
- ...(config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
402
- ...(config.reviewAllowedCalls ? { reviewAllowedCalls: config.reviewAllowedCalls } : {}),
403
- // Forwarded for the same reason the handler is. A capability the
404
- // kernel honours in `drainQuery` but that never reaches the
405
- // surface a host actually constructs is a capability nobody can
406
- // use — which is the shape of defect this file has already been
407
- // corrected for twice.
408
- ...(config.steering ? { steering: config.steering } : {}),
409
- ...(config.inboundMessages ? { inboundMessages: config.inboundMessages } : {}),
410
- ...(config.durableInbound ? { durableInbound: config.durableInbound } : {}),
411
- ...(config.projectInstructionContext
412
- ? { projectInstructionContext: config.projectInstructionContext }
413
- : {}),
414
- ...(config.authorizationGate ? { authorizationGate: config.authorizationGate } : {}),
415
- // The one hop between the config and the tool. `drainQuery`
416
- // registers `structured_output` from this and the loop
417
- // captures it, so the kernel never cared which archetype it
418
- // came from — only `ReactiveAgent` was passing it.
419
- ...(config.structuredOutput ? { structuredOutput: config.structuredOutput } : {}),
420
- ...(config.sandboxProvider ? { sandboxProvider: config.sandboxProvider } : {}),
421
- ...(config.sandboxTeardownTimeoutMs !== undefined
422
- ? { sandboxTeardownTimeoutMs: config.sandboxTeardownTimeoutMs }
385
+ const queryParams: Parameters<typeof drainQuery>[0] = {
386
+ systemPrompt: config.systemPrompt,
387
+ skills: config.skills,
388
+ provider: config.provider,
389
+ toolsets,
390
+ ...(config.toolResultGuardrails !== undefined
391
+ ? { toolResultGuardrails: config.toolResultGuardrails }
392
+ : {}),
393
+ ...(input.attachmentStore ? { attachmentStore: input.attachmentStore } : {}),
394
+ ...(config.attachmentResolveTimeoutMs !== undefined
395
+ ? { attachmentResolveTimeoutMs: config.attachmentResolveTimeoutMs }
396
+ : {}),
397
+ turnConfig: {
398
+ model: config.model,
399
+ tokenBudget: config.tokenBudget,
400
+ timeoutMs: config.timeoutMs,
401
+ ...(config.sandbox ? { sandbox: config.sandbox } : {}),
402
+ ...(config.streamIdleTimeoutMs !== undefined
403
+ ? { streamIdleTimeoutMs: config.streamIdleTimeoutMs }
423
404
  : {}),
424
- // Working-memory / compaction seam (optional; absent => unchanged
425
- // run path, byte-identical for every existing consumer).
426
- ...(config.compactionConfig ? { compactionConfig: config.compactionConfig } : {}),
427
- ...(config.workingMemoryProvider
428
- ? { workingMemoryProvider: config.workingMemoryProvider }
405
+ ...(config.maxRequestRichContentBytes !== undefined
406
+ ? {
407
+ maxRequestRichContentBytes: config.maxRequestRichContentBytes,
408
+ }
429
409
  : {}),
430
- ...(config.paths ? { paths: config.paths } : {}),
431
- ...(config.sessionLog ? { sessionLog: config.sessionLog } : {}),
432
- ...(config.checkpointStore ? { checkpointStore: config.checkpointStore } : {}),
410
+ maxIterations: config.maxIterations,
411
+ temperature: config.temperature,
412
+ env: config.env,
413
+ ...(config.pruneKeepLast !== undefined ? { pruneKeepLast: config.pruneKeepLast } : {}),
414
+ logger: this.log,
415
+ // See ReactiveAgent: a hand-listed literal drops what nobody
416
+ // remembered to add, and reports nothing when it does.
417
+ ...(config.thinking ? { thinking: config.thinking } : {}),
418
+ ...(config.effort ? { effort: config.effort } : {}),
433
419
  },
434
- listener,
435
- )
420
+ questionParks,
421
+ pendingAnswers,
422
+ // How wide a fan-out actually runs. Absent leaves the kernel
423
+ // default — the same forwarding ReactiveAgent has always done,
424
+ // missing from the one agent whose job is delegation.
425
+ ...(config.maxToolConcurrency !== undefined
426
+ ? { maxToolConcurrency: config.maxToolConcurrency }
427
+ : {}),
428
+ agentId: this.metadata.id,
429
+ agentName: this.metadata.name,
430
+ workingDirectory: input.workingDirectory,
431
+ messages: input.messages,
432
+ signal: input.signal,
433
+ sessionId,
434
+ topicId,
435
+ projectId,
436
+ tenantId,
437
+ turnId,
438
+ ...(config.parentSessionId ? { parentSessionId: config.parentSessionId } : {}),
439
+ ...(config.parentTurnId ? { parentTurnId: config.parentTurnId } : {}),
440
+ depth: config.depth,
441
+ contextLevel: 'full',
442
+ onContextCreated: ({ planManager }) => {
443
+ planManagerRef = planManager
444
+ },
445
+ taskStore: input.taskStore,
446
+ runtimeToolOverrides: input.runtimeToolOverrides,
447
+ runtimeContext: input.runtimeContext,
448
+ taskScheduler: gateway,
449
+ budget,
450
+ completionInbox,
451
+ advisory: config.advisory,
452
+ invocationState: childInvocationState,
453
+ // HITL surface: forward optional review-time hooks so hosts can
454
+ // run "Ask before acting" supervisors instead of the default
455
+ // auto-approve. drainQuery falls back to autoApproveHandler
456
+ // when resumeHandler is omitted (= same behaviour as before).
457
+ ...(config.resumeHandler ? { resumeHandler: config.resumeHandler } : {}),
458
+ ...(config.reviewAllowedCalls ? { reviewAllowedCalls: config.reviewAllowedCalls } : {}),
459
+ // Forwarded for the same reason the handler is. A capability the
460
+ // kernel honours in `drainQuery` but that never reaches the
461
+ // surface a host actually constructs is a capability nobody can
462
+ // use — which is the shape of defect this file has already been
463
+ // corrected for twice.
464
+ ...(config.steering ? { steering: config.steering } : {}),
465
+ ...(config.inboundMessages ? { inboundMessages: config.inboundMessages } : {}),
466
+ ...(config.durableInbound ? { durableInbound: config.durableInbound } : {}),
467
+ ...(config.projectInstructionContext
468
+ ? { projectInstructionContext: config.projectInstructionContext }
469
+ : {}),
470
+ ...(config.authorizationGate ? { authorizationGate: config.authorizationGate } : {}),
471
+ // The one hop between the config and the tool. `drainQuery`
472
+ // registers `structured_output` from this and the loop
473
+ // captures it, so the kernel never cared which archetype it
474
+ // came from — only `ReactiveAgent` was passing it.
475
+ ...(config.structuredOutput ? { structuredOutput: config.structuredOutput } : {}),
476
+ ...(config.sandboxProvider ? { sandboxProvider: config.sandboxProvider } : {}),
477
+ ...(config.sandboxTeardownTimeoutMs !== undefined
478
+ ? { sandboxTeardownTimeoutMs: config.sandboxTeardownTimeoutMs }
479
+ : {}),
480
+ // Working-memory / compaction seam (optional; absent => unchanged
481
+ // run path, byte-identical for every existing consumer).
482
+ ...(config.compactionConfig ? { compactionConfig: config.compactionConfig } : {}),
483
+ ...(config.workingMemoryProvider
484
+ ? { workingMemoryProvider: config.workingMemoryProvider }
485
+ : {}),
486
+ ...(config.paths ? { paths: config.paths } : {}),
487
+ ...(config.sessionLog ? { sessionLog: config.sessionLog } : {}),
488
+ ...(config.checkpointStore ? { checkpointStore: config.checkpointStore } : {}),
489
+ }
490
+
491
+ const turn = resume
492
+ ? await this.resumeTurn(queryParams, config, resume, listener)
493
+ : await drainQuery(queryParams, listener)
436
494
 
437
495
  const taskHandles = gateway.listTasks()
438
496
  const taskResults = synthesizeTaskResults(taskHandles, {
@@ -470,4 +528,57 @@ export class SupervisorAgent extends AbstractAgent<SupervisorAgentConfig, Superv
470
528
  completionInbox.close()
471
529
  }
472
530
  }
531
+
532
+ /**
533
+ * The resumed counterpart of `drainQuery`: same params, so the wiring is
534
+ * the one a fresh turn gets, handed to `resumeSession` rather than a
535
+ * second copy of its machinery.
536
+ */
537
+ private async resumeTurn(
538
+ queryParams: Parameters<typeof drainQuery>[0],
539
+ config: SupervisorAgentConfig,
540
+ resume: SupervisorResumeTarget,
541
+ listener?: SessionEventListener,
542
+ ) {
543
+ const { messages: _messages, turnId: _turnId, ...rest } = queryParams
544
+ const sessionLog = config.sessionLog
545
+ if (
546
+ !sessionLog ||
547
+ !config.sessionId ||
548
+ !config.topicId ||
549
+ !config.projectId ||
550
+ !config.tenantId
551
+ ) {
552
+ throw new NamzuError({
553
+ code: 'invalid_config',
554
+ message: 'SupervisorAgent.resume requires config.sessionLog.',
555
+ })
556
+ }
557
+ const outcome = await resumeSession({
558
+ ...rest,
559
+ resumeHandler: rest.resumeHandler ?? autoApproveHandler,
560
+ scope: {
561
+ tenantId: config.tenantId,
562
+ projectId: config.projectId,
563
+ topicId: config.topicId,
564
+ sessionId: config.sessionId,
565
+ turnId: resume.turnId,
566
+ ...(config.parentSessionId ? { parentSessionId: config.parentSessionId } : {}),
567
+ ...(config.parentTurnId ? { parentTurnId: config.parentTurnId } : {}),
568
+ },
569
+ sessionLog,
570
+ ...(resume.checkpointId ? { checkpointId: resume.checkpointId } : {}),
571
+ ...(resume.pendingDecision ? { pendingDecision: resume.pendingDecision } : {}),
572
+ ...(listener ? { listener } : {}),
573
+ })
574
+ if (outcome.resumed) return outcome.turn
575
+ throw new NamzuError({
576
+ code: 'invalid_config',
577
+ message:
578
+ outcome.reason === 'no-checkpoint'
579
+ ? `Turn ${resume.turnId} has no checkpoint${resume.checkpointId ? ` ${resume.checkpointId}` : ''} to resume.`
580
+ : `Turn ${resume.turnId} is waiting on a decision; pass resume.pendingDecision.`,
581
+ details: { turnId: resume.turnId, reason: outcome.reason },
582
+ })
583
+ }
473
584
  }
@@ -4,7 +4,7 @@ export { QueryAgent } from './QueryAgent.js'
4
4
  export { ReactiveAgent } from './ReactiveAgent.js'
5
5
  export { PipelineAgent } from './PipelineAgent.js'
6
6
  export { RouterAgent } from './RouterAgent.js'
7
- export { SupervisorAgent } from './SupervisorAgent.js'
7
+ export { SupervisorAgent, type SupervisorResumeTarget } from './SupervisorAgent.js'
8
8
  export { defineAgent } from './defineAgent.js'
9
9
  export type { DefineAgentOptions } from './defineAgent.js'
10
10
  export { InvocationLock, ConcurrentInvocationError } from './lock.js'
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Paths a write is always asked about, in every mode.
3
+ *
4
+ * A repository carries files that are not data but triggers: a git hook runs
5
+ * on the next commit, a shell rc file on the next terminal, `.vscode/tasks.json`
6
+ * when a folder opens, `.envrc` on the next `cd`. A model that can write them
7
+ * does not need to run anything now; it plants code that runs later, outside
8
+ * the turn, with the operator's own rights. So a write to one of them is a
9
+ * question for a person, whatever the mode and whatever a rule or an earlier
10
+ * "approve all" said. That is what a mode is, an answer given before the call
11
+ * existed, and none of them saw this path.
12
+ *
13
+ * The lists are the reference terminal's protected-directory and
14
+ * protected-file tables (version 2.1.302), with its own configuration
15
+ * directory and file mapped to Namzu's: the project directory is `.namzu` and
16
+ * the project file is `namzu.config.json`.
17
+ *
18
+ * Matching is by name, on every segment of the path. `.git` anywhere above a
19
+ * file protects it, and `.config/git` counts as one two-segment unit. Names
20
+ * are case-folded, including the dotless `ı` and long `ſ` that fold to `i`
21
+ * and `s`, so `.GIT` and `.gıt` on a case-insensitive file system are the
22
+ * same directory.
23
+ */
24
+
25
+ /** Directory names; a path with one of these as any segment is protected. */
26
+ export const PROTECTED_DIRECTORIES: readonly string[] = [
27
+ '.git',
28
+ '.vscode',
29
+ '.idea',
30
+ '.namzu',
31
+ '.husky',
32
+ '.cargo',
33
+ '.devcontainer',
34
+ '.yarn',
35
+ '.mvn',
36
+ ]
37
+
38
+ /** Directory sequences; the segments must be adjacent. */
39
+ export const PROTECTED_NESTED_DIRECTORIES: readonly (readonly string[])[] = [['.config', 'git']]
40
+
41
+ /** File names; a path whose last segment is one of these is protected. */
42
+ export const PROTECTED_FILE_NAMES: readonly string[] = [
43
+ '.gitconfig',
44
+ '.gitmodules',
45
+ '.bashrc',
46
+ '.bash_profile',
47
+ '.zshrc',
48
+ '.zprofile',
49
+ '.profile',
50
+ '.zshenv',
51
+ '.zlogin',
52
+ '.zlogout',
53
+ '.bash_login',
54
+ '.bash_aliases',
55
+ '.bash_logout',
56
+ '.envrc',
57
+ '.ripgreprc',
58
+ '.mcp.json',
59
+ 'namzu.config.json',
60
+ // The project's local config, where "don't ask again" answers are written.
61
+ 'namzu.config.local.json',
62
+ '.npmrc',
63
+ '.yarnrc',
64
+ '.yarnrc.yml',
65
+ '.pnp.cjs',
66
+ '.pnp.loader.mjs',
67
+ '.pnpmfile.cjs',
68
+ 'bunfig.toml',
69
+ '.bunfig.toml',
70
+ '.bazelrc',
71
+ '.bazelversion',
72
+ '.bazeliskrc',
73
+ '.pre-commit-config.yaml',
74
+ 'lefthook.yml',
75
+ '.lefthook.yml',
76
+ 'lefthook.yaml',
77
+ '.lefthook.yaml',
78
+ 'gradle-wrapper.properties',
79
+ 'maven-wrapper.properties',
80
+ '.devcontainer.json',
81
+ 'pyrightconfig.json',
82
+ ]
83
+
84
+ /** Lower case, with the two letters that fold into ASCII on some file systems. */
85
+ function fold(name: string): string {
86
+ return name.toLowerCase().replace(/ı/g, 'i').replace(/ſ/g, 's')
87
+ }
88
+
89
+ const DIRECTORIES = new Set(PROTECTED_DIRECTORIES.map(fold))
90
+ const FILE_NAMES = new Set(PROTECTED_FILE_NAMES.map(fold))
91
+ const NESTED = PROTECTED_NESTED_DIRECTORIES.map((sequence) => sequence.map(fold))
92
+
93
+ /**
94
+ * Whether a write to `path` is one of the protected kinds. Pure: it reads the
95
+ * spelling it is given, so a caller that wants a symlink's target covered
96
+ * passes the canonical path as well.
97
+ */
98
+ export function isProtectedPath(path: string): boolean {
99
+ const segments = path.split(/[\\/]+/).map(fold)
100
+ for (const segment of segments) {
101
+ if (DIRECTORIES.has(segment)) return true
102
+ }
103
+ for (const sequence of NESTED) {
104
+ for (let start = 0; start + sequence.length <= segments.length; start += 1) {
105
+ if (sequence.every((name, offset) => segments[start + offset] === name)) return true
106
+ }
107
+ }
108
+ const last = segments[segments.length - 1]
109
+ return last !== undefined && last !== '' && FILE_NAMES.has(last)
110
+ }