@namzu/sdk 65.2.0 → 67.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (571) hide show
  1. package/CHANGELOG.md +161 -0
  2. package/dist/account/lock.d.ts +4 -12
  3. package/dist/account/lock.d.ts.map +1 -1
  4. package/dist/account/lock.js +5 -140
  5. package/dist/account/lock.js.map +1 -1
  6. package/dist/account/registry.d.ts.map +1 -1
  7. package/dist/account/registry.js +50 -6
  8. package/dist/account/registry.js.map +1 -1
  9. package/dist/account/types.d.ts +7 -5
  10. package/dist/account/types.d.ts.map +1 -1
  11. package/dist/account/types.js +6 -7
  12. package/dist/account/types.js.map +1 -1
  13. package/dist/authorization/dangerous-commands.d.ts +64 -0
  14. package/dist/authorization/dangerous-commands.d.ts.map +1 -0
  15. package/dist/authorization/dangerous-commands.js +479 -0
  16. package/dist/authorization/dangerous-commands.js.map +1 -0
  17. package/dist/authorization/gate.d.ts.map +1 -1
  18. package/dist/authorization/gate.js +19 -5
  19. package/dist/authorization/gate.js.map +1 -1
  20. package/dist/authorization/protected-paths.d.ts +11 -6
  21. package/dist/authorization/protected-paths.d.ts.map +1 -1
  22. package/dist/authorization/protected-paths.js +13 -8
  23. package/dist/authorization/protected-paths.js.map +1 -1
  24. package/dist/authorization/readonly-commands.d.ts +6 -1
  25. package/dist/authorization/readonly-commands.d.ts.map +1 -1
  26. package/dist/authorization/readonly-commands.js +35 -1
  27. package/dist/authorization/readonly-commands.js.map +1 -1
  28. package/dist/authorization/removal.d.ts +10 -0
  29. package/dist/authorization/removal.d.ts.map +1 -1
  30. package/dist/authorization/removal.js +7 -7
  31. package/dist/authorization/removal.js.map +1 -1
  32. package/dist/authorization/rules.d.ts +10 -0
  33. package/dist/authorization/rules.d.ts.map +1 -1
  34. package/dist/authorization/rules.js +60 -14
  35. package/dist/authorization/rules.js.map +1 -1
  36. package/dist/authorization/shell-lexer.d.ts +10 -0
  37. package/dist/authorization/shell-lexer.d.ts.map +1 -1
  38. package/dist/authorization/shell-lexer.js +15 -0
  39. package/dist/authorization/shell-lexer.js.map +1 -1
  40. package/dist/bridge/acp/permission.d.ts +5 -0
  41. package/dist/bridge/acp/permission.d.ts.map +1 -1
  42. package/dist/bridge/acp/permission.js.map +1 -1
  43. package/dist/bridge/acp/server.d.ts +8 -1
  44. package/dist/bridge/acp/server.d.ts.map +1 -1
  45. package/dist/bridge/acp/server.js +48 -6
  46. package/dist/bridge/acp/server.js.map +1 -1
  47. package/dist/compaction/context-breakdown.d.ts +25 -6
  48. package/dist/compaction/context-breakdown.d.ts.map +1 -1
  49. package/dist/compaction/context-breakdown.js +27 -7
  50. package/dist/compaction/context-breakdown.js.map +1 -1
  51. package/dist/compaction/dangling.d.ts.map +1 -1
  52. package/dist/compaction/dangling.js +2 -0
  53. package/dist/compaction/dangling.js.map +1 -1
  54. package/dist/compaction/extractor.d.ts +7 -1
  55. package/dist/compaction/extractor.d.ts.map +1 -1
  56. package/dist/compaction/extractor.js +8 -1
  57. package/dist/compaction/extractor.js.map +1 -1
  58. package/dist/compaction/index.d.ts +1 -1
  59. package/dist/compaction/index.d.ts.map +1 -1
  60. package/dist/compaction/index.js +1 -1
  61. package/dist/compaction/index.js.map +1 -1
  62. package/dist/compaction/managers/structured.js +2 -2
  63. package/dist/compaction/managers/structured.js.map +1 -1
  64. package/dist/compaction/manual.d.ts.map +1 -1
  65. package/dist/compaction/manual.js +11 -6
  66. package/dist/compaction/manual.js.map +1 -1
  67. package/dist/compaction/model-summary.d.ts.map +1 -1
  68. package/dist/compaction/model-summary.js +7 -1
  69. package/dist/compaction/model-summary.js.map +1 -1
  70. package/dist/compaction/summary.d.ts +13 -2
  71. package/dist/compaction/summary.d.ts.map +1 -1
  72. package/dist/compaction/summary.js +46 -3
  73. package/dist/compaction/summary.js.map +1 -1
  74. package/dist/constants/tools/index.d.ts +18 -1
  75. package/dist/constants/tools/index.d.ts.map +1 -1
  76. package/dist/constants/tools/index.js +28 -16
  77. package/dist/constants/tools/index.js.map +1 -1
  78. package/dist/manager/session/turn-recorder.d.ts +6 -0
  79. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  80. package/dist/manager/session/turn-recorder.js +29 -1
  81. package/dist/manager/session/turn-recorder.js.map +1 -1
  82. package/dist/network/audit.d.ts +49 -0
  83. package/dist/network/audit.d.ts.map +1 -0
  84. package/dist/network/audit.js +84 -0
  85. package/dist/network/audit.js.map +1 -0
  86. package/dist/network/clock.d.ts +21 -0
  87. package/dist/network/clock.d.ts.map +1 -0
  88. package/dist/network/clock.js +51 -0
  89. package/dist/network/clock.js.map +1 -0
  90. package/dist/network/discovery-mdns.d.ts +120 -0
  91. package/dist/network/discovery-mdns.d.ts.map +1 -0
  92. package/dist/network/discovery-mdns.js +442 -0
  93. package/dist/network/discovery-mdns.js.map +1 -0
  94. package/dist/network/discovery.d.ts +63 -0
  95. package/dist/network/discovery.d.ts.map +1 -0
  96. package/dist/network/discovery.js +163 -0
  97. package/dist/network/discovery.js.map +1 -0
  98. package/dist/network/fingerprint.d.ts +73 -0
  99. package/dist/network/fingerprint.d.ts.map +1 -0
  100. package/dist/network/fingerprint.js +208 -0
  101. package/dist/network/fingerprint.js.map +1 -0
  102. package/dist/network/identity.d.ts +38 -0
  103. package/dist/network/identity.d.ts.map +1 -0
  104. package/dist/network/identity.js +71 -0
  105. package/dist/network/identity.js.map +1 -0
  106. package/dist/network/index.d.ts +39 -0
  107. package/dist/network/index.d.ts.map +1 -0
  108. package/dist/network/index.js +25 -0
  109. package/dist/network/index.js.map +1 -0
  110. package/dist/network/join.d.ts +69 -0
  111. package/dist/network/join.d.ts.map +1 -0
  112. package/dist/network/join.js +136 -0
  113. package/dist/network/join.js.map +1 -0
  114. package/dist/network/mail-policy.d.ts +97 -0
  115. package/dist/network/mail-policy.d.ts.map +1 -0
  116. package/dist/network/mail-policy.js +147 -0
  117. package/dist/network/mail-policy.js.map +1 -0
  118. package/dist/network/membership.d.ts +76 -0
  119. package/dist/network/membership.d.ts.map +1 -0
  120. package/dist/network/membership.js +225 -0
  121. package/dist/network/membership.js.map +1 -0
  122. package/dist/network/roster.d.ts +59 -0
  123. package/dist/network/roster.d.ts.map +1 -0
  124. package/dist/network/roster.js +120 -0
  125. package/dist/network/roster.js.map +1 -0
  126. package/dist/network/service.d.ts +303 -0
  127. package/dist/network/service.d.ts.map +1 -0
  128. package/dist/network/service.js +1891 -0
  129. package/dist/network/service.js.map +1 -0
  130. package/dist/network/store.d.ts +141 -0
  131. package/dist/network/store.d.ts.map +1 -0
  132. package/dist/network/store.js +198 -0
  133. package/dist/network/store.js.map +1 -0
  134. package/dist/network/transport.d.ts +96 -0
  135. package/dist/network/transport.d.ts.map +1 -0
  136. package/dist/network/transport.js +342 -0
  137. package/dist/network/transport.js.map +1 -0
  138. package/dist/network/wire.d.ts +345 -0
  139. package/dist/network/wire.d.ts.map +1 -0
  140. package/dist/network/wire.js +212 -0
  141. package/dist/network/wire.js.map +1 -0
  142. package/dist/network/x509.d.ts +28 -0
  143. package/dist/network/x509.d.ts.map +1 -0
  144. package/dist/network/x509.js +84 -0
  145. package/dist/network/x509.js.map +1 -0
  146. package/dist/pals/activity/causality.d.ts.map +1 -1
  147. package/dist/pals/activity/causality.js +14 -2
  148. package/dist/pals/activity/causality.js.map +1 -1
  149. package/dist/peers/endpoint.d.ts.map +1 -1
  150. package/dist/peers/endpoint.js +6 -0
  151. package/dist/peers/endpoint.js.map +1 -1
  152. package/dist/peers/envelope.d.ts +18 -0
  153. package/dist/peers/envelope.d.ts.map +1 -1
  154. package/dist/peers/envelope.js +68 -5
  155. package/dist/peers/envelope.js.map +1 -1
  156. package/dist/peers/index.d.ts +5 -4
  157. package/dist/peers/index.d.ts.map +1 -1
  158. package/dist/peers/index.js +3 -2
  159. package/dist/peers/index.js.map +1 -1
  160. package/dist/peers/mode-word.d.ts +10 -0
  161. package/dist/peers/mode-word.d.ts.map +1 -0
  162. package/dist/peers/mode-word.js +19 -0
  163. package/dist/peers/mode-word.js.map +1 -0
  164. package/dist/peers/protocol.d.ts +42 -0
  165. package/dist/peers/protocol.d.ts.map +1 -1
  166. package/dist/peers/protocol.js +22 -1
  167. package/dist/peers/protocol.js.map +1 -1
  168. package/dist/peers/record.d.ts +8 -0
  169. package/dist/peers/record.d.ts.map +1 -1
  170. package/dist/peers/record.js +5 -0
  171. package/dist/peers/record.js.map +1 -1
  172. package/dist/plugin/session-hook-env.d.ts.map +1 -1
  173. package/dist/plugin/session-hook-env.js +22 -2
  174. package/dist/plugin/session-hook-env.js.map +1 -1
  175. package/dist/plugin/shell-hook.d.ts +16 -2
  176. package/dist/plugin/shell-hook.d.ts.map +1 -1
  177. package/dist/plugin/shell-hook.js +183 -14
  178. package/dist/plugin/shell-hook.js.map +1 -1
  179. package/dist/prompt/coding-agent-doctrine.d.ts +4 -2
  180. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  181. package/dist/prompt/coding-agent-doctrine.js +33 -38
  182. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  183. package/dist/public-runtime.d.ts +14 -6
  184. package/dist/public-runtime.d.ts.map +1 -1
  185. package/dist/public-runtime.js +22 -5
  186. package/dist/public-runtime.js.map +1 -1
  187. package/dist/public-tools.d.ts +3 -2
  188. package/dist/public-tools.d.ts.map +1 -1
  189. package/dist/public-tools.js +2 -2
  190. package/dist/public-tools.js.map +1 -1
  191. package/dist/public-types.d.ts +7 -2
  192. package/dist/public-types.d.ts.map +1 -1
  193. package/dist/runtime/jobs/registry.d.ts +29 -1
  194. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  195. package/dist/runtime/jobs/registry.js +64 -0
  196. package/dist/runtime/jobs/registry.js.map +1 -1
  197. package/dist/runtime/query/auto-review/classifier.d.ts +30 -6
  198. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  199. package/dist/runtime/query/auto-review/classifier.js +40 -12
  200. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  201. package/dist/runtime/query/auto-review/feedback.d.ts +37 -0
  202. package/dist/runtime/query/auto-review/feedback.d.ts.map +1 -0
  203. package/dist/runtime/query/auto-review/feedback.js +45 -0
  204. package/dist/runtime/query/auto-review/feedback.js.map +1 -0
  205. package/dist/runtime/query/auto-review/git-status.d.ts +59 -0
  206. package/dist/runtime/query/auto-review/git-status.d.ts.map +1 -0
  207. package/dist/runtime/query/auto-review/git-status.js +379 -0
  208. package/dist/runtime/query/auto-review/git-status.js.map +1 -0
  209. package/dist/runtime/query/auto-review/index.d.ts +3 -3
  210. package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
  211. package/dist/runtime/query/auto-review/index.js +2 -2
  212. package/dist/runtime/query/auto-review/index.js.map +1 -1
  213. package/dist/runtime/query/auto-review/prompt.d.ts.map +1 -1
  214. package/dist/runtime/query/auto-review/prompt.js +6 -1
  215. package/dist/runtime/query/auto-review/prompt.js.map +1 -1
  216. package/dist/runtime/query/auto-review/transcript.d.ts +14 -1
  217. package/dist/runtime/query/auto-review/transcript.d.ts.map +1 -1
  218. package/dist/runtime/query/auto-review/transcript.js +48 -2
  219. package/dist/runtime/query/auto-review/transcript.js.map +1 -1
  220. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  221. package/dist/runtime/query/executor/tool-call-admission.js +40 -3
  222. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  223. package/dist/runtime/query/executor.d.ts +32 -10
  224. package/dist/runtime/query/executor.d.ts.map +1 -1
  225. package/dist/runtime/query/executor.js +78 -17
  226. package/dist/runtime/query/executor.js.map +1 -1
  227. package/dist/runtime/query/index.d.ts +9 -0
  228. package/dist/runtime/query/index.d.ts.map +1 -1
  229. package/dist/runtime/query/index.js +54 -17
  230. package/dist/runtime/query/index.js.map +1 -1
  231. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  232. package/dist/runtime/query/iteration/index.js +17 -3
  233. package/dist/runtime/query/iteration/index.js.map +1 -1
  234. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  235. package/dist/runtime/query/iteration/phases/compaction.js +5 -2
  236. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  237. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  238. package/dist/runtime/query/iteration/phases/context.js +5 -0
  239. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  240. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +1 -2
  241. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  242. package/dist/runtime/query/iteration/phases/per-call-review.js +2 -5
  243. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  244. package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
  245. package/dist/runtime/query/iteration/phases/tool-review.js +6 -1
  246. package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
  247. package/dist/runtime/query/pasted-frames.d.ts +34 -0
  248. package/dist/runtime/query/pasted-frames.d.ts.map +1 -0
  249. package/dist/runtime/query/pasted-frames.js +108 -0
  250. package/dist/runtime/query/pasted-frames.js.map +1 -0
  251. package/dist/runtime/query/path-escalation.d.ts +6 -0
  252. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  253. package/dist/runtime/query/path-escalation.js +15 -3
  254. package/dist/runtime/query/path-escalation.js.map +1 -1
  255. package/dist/runtime/query/request-interrupted-turns.d.ts +20 -0
  256. package/dist/runtime/query/request-interrupted-turns.d.ts.map +1 -0
  257. package/dist/runtime/query/request-interrupted-turns.js +43 -0
  258. package/dist/runtime/query/request-interrupted-turns.js.map +1 -0
  259. package/dist/runtime/query/review-policy.d.ts +16 -6
  260. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  261. package/dist/runtime/query/review-policy.js +111 -15
  262. package/dist/runtime/query/review-policy.js.map +1 -1
  263. package/dist/runtime/query/turn/outcome-ledger.d.ts +9 -0
  264. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  265. package/dist/runtime/query/turn/outcome-ledger.js +94 -6
  266. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  267. package/dist/runtime/query/unanswered.d.ts +19 -0
  268. package/dist/runtime/query/unanswered.d.ts.map +1 -0
  269. package/dist/runtime/query/unanswered.js +25 -0
  270. package/dist/runtime/query/unanswered.js.map +1 -0
  271. package/dist/runtime/system-events.d.ts +4 -4
  272. package/dist/runtime/system-events.d.ts.map +1 -1
  273. package/dist/runtime/system-events.js +2 -0
  274. package/dist/runtime/system-events.js.map +1 -1
  275. package/dist/session/workspace/git-worktree.d.ts +8 -0
  276. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  277. package/dist/session/workspace/git-worktree.js +21 -3
  278. package/dist/session/workspace/git-worktree.js.map +1 -1
  279. package/dist/store/evidence/source-kind.d.ts +1 -1
  280. package/dist/store/evidence/source-kind.d.ts.map +1 -1
  281. package/dist/store/evidence/source-kind.js +1 -1
  282. package/dist/store/evidence/source-kind.js.map +1 -1
  283. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  284. package/dist/store/session-index/sqlite.js +42 -3
  285. package/dist/store/session-index/sqlite.js.map +1 -1
  286. package/dist/store/session-log/disk.js +1 -1
  287. package/dist/store/session-log/disk.js.map +1 -1
  288. package/dist/store/session-log/lease.d.ts.map +1 -1
  289. package/dist/store/session-log/lease.js +3 -2
  290. package/dist/store/session-log/lease.js.map +1 -1
  291. package/dist/tools/admit-facts.d.ts.map +1 -1
  292. package/dist/tools/admit-facts.js +2 -0
  293. package/dist/tools/admit-facts.js.map +1 -1
  294. package/dist/tools/builtins/bash.d.ts +10 -2
  295. package/dist/tools/builtins/bash.d.ts.map +1 -1
  296. package/dist/tools/builtins/bash.js +56 -17
  297. package/dist/tools/builtins/bash.js.map +1 -1
  298. package/dist/tools/builtins/browser-local.d.ts +117 -0
  299. package/dist/tools/builtins/browser-local.d.ts.map +1 -0
  300. package/dist/tools/builtins/browser-local.js +437 -0
  301. package/dist/tools/builtins/browser-local.js.map +1 -0
  302. package/dist/tools/builtins/browser.d.ts +18 -1
  303. package/dist/tools/builtins/browser.d.ts.map +1 -1
  304. package/dist/tools/builtins/browser.js +98 -8
  305. package/dist/tools/builtins/browser.js.map +1 -1
  306. package/dist/tools/builtins/computer-use-window-id.d.ts +16 -0
  307. package/dist/tools/builtins/computer-use-window-id.d.ts.map +1 -0
  308. package/dist/tools/builtins/computer-use-window-id.js +52 -0
  309. package/dist/tools/builtins/computer-use-window-id.js.map +1 -0
  310. package/dist/tools/builtins/computer-use.d.ts +65 -7
  311. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  312. package/dist/tools/builtins/computer-use.js +384 -71
  313. package/dist/tools/builtins/computer-use.js.map +1 -1
  314. package/dist/tools/builtins/content-fingerprint.d.ts +6 -0
  315. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  316. package/dist/tools/builtins/content-fingerprint.js +7 -1
  317. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  318. package/dist/tools/builtins/edit.d.ts.map +1 -1
  319. package/dist/tools/builtins/edit.js +89 -7
  320. package/dist/tools/builtins/edit.js.map +1 -1
  321. package/dist/tools/builtins/file-write-result.d.ts.map +1 -1
  322. package/dist/tools/builtins/file-write-result.js +2 -1
  323. package/dist/tools/builtins/file-write-result.js.map +1 -1
  324. package/dist/tools/builtins/grep.js +1 -1
  325. package/dist/tools/builtins/grep.js.map +1 -1
  326. package/dist/tools/builtins/job.d.ts.map +1 -1
  327. package/dist/tools/builtins/job.js +4 -2
  328. package/dist/tools/builtins/job.js.map +1 -1
  329. package/dist/tools/builtins/monitor.d.ts.map +1 -1
  330. package/dist/tools/builtins/monitor.js +6 -1
  331. package/dist/tools/builtins/monitor.js.map +1 -1
  332. package/dist/tools/builtins/search-tools.d.ts +12 -1
  333. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  334. package/dist/tools/builtins/search-tools.js +166 -20
  335. package/dist/tools/builtins/search-tools.js.map +1 -1
  336. package/dist/tools/builtins/shell-read-credit.d.ts +18 -6
  337. package/dist/tools/builtins/shell-read-credit.d.ts.map +1 -1
  338. package/dist/tools/builtins/shell-read-credit.js +95 -27
  339. package/dist/tools/builtins/shell-read-credit.js.map +1 -1
  340. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  341. package/dist/tools/builtins/wait-for-job.js +14 -3
  342. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  343. package/dist/tools/builtins/web-guidance.d.ts +6 -0
  344. package/dist/tools/builtins/web-guidance.d.ts.map +1 -1
  345. package/dist/tools/builtins/web-guidance.js +6 -0
  346. package/dist/tools/builtins/web-guidance.js.map +1 -1
  347. package/dist/tools/builtins/web.d.ts.map +1 -1
  348. package/dist/tools/builtins/web.js +2 -1
  349. package/dist/tools/builtins/web.js.map +1 -1
  350. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  351. package/dist/tools/builtins/write-file.js +32 -2
  352. package/dist/tools/builtins/write-file.js.map +1 -1
  353. package/dist/tools/command-shell.d.ts +1 -1
  354. package/dist/tools/command-shell.d.ts.map +1 -1
  355. package/dist/tools/command-shell.js +6 -8
  356. package/dist/tools/command-shell.js.map +1 -1
  357. package/dist/tools/defineTool.d.ts +2 -0
  358. package/dist/tools/defineTool.d.ts.map +1 -1
  359. package/dist/tools/defineTool.js +17 -1
  360. package/dist/tools/defineTool.js.map +1 -1
  361. package/dist/tools/schedules/index.d.ts +1 -0
  362. package/dist/tools/schedules/index.d.ts.map +1 -1
  363. package/dist/tools/schedules/index.js +1 -0
  364. package/dist/tools/schedules/index.js.map +1 -1
  365. package/dist/tools/schedules/loop-tool.d.ts.map +1 -1
  366. package/dist/tools/schedules/loop-tool.js +8 -6
  367. package/dist/tools/schedules/loop-tool.js.map +1 -1
  368. package/dist/tools/schedules/present.js +1 -1
  369. package/dist/tools/schedules/present.js.map +1 -1
  370. package/dist/tools/schedules/timer-tools.d.ts +36 -0
  371. package/dist/tools/schedules/timer-tools.d.ts.map +1 -0
  372. package/dist/tools/schedules/timer-tools.js +234 -0
  373. package/dist/tools/schedules/timer-tools.js.map +1 -0
  374. package/dist/tools/schedules/types.d.ts +68 -3
  375. package/dist/tools/schedules/types.d.ts.map +1 -1
  376. package/dist/tools/task/create.d.ts.map +1 -1
  377. package/dist/tools/task/create.js +2 -0
  378. package/dist/tools/task/create.js.map +1 -1
  379. package/dist/toolsets/manager.d.ts +49 -7
  380. package/dist/toolsets/manager.d.ts.map +1 -1
  381. package/dist/toolsets/manager.js +239 -40
  382. package/dist/toolsets/manager.js.map +1 -1
  383. package/dist/turn/evidence-query.d.ts +18 -1
  384. package/dist/turn/evidence-query.d.ts.map +1 -1
  385. package/dist/turn/evidence-query.js +177 -35
  386. package/dist/turn/evidence-query.js.map +1 -1
  387. package/dist/turn/evidence-recall.d.ts +8 -1
  388. package/dist/turn/evidence-recall.d.ts.map +1 -1
  389. package/dist/turn/evidence-recall.js +82 -22
  390. package/dist/turn/evidence-recall.js.map +1 -1
  391. package/dist/turn/history-shed.d.ts +15 -0
  392. package/dist/turn/history-shed.d.ts.map +1 -0
  393. package/dist/turn/history-shed.js +23 -0
  394. package/dist/turn/history-shed.js.map +1 -0
  395. package/dist/types/acp/index.d.ts +26 -0
  396. package/dist/types/acp/index.d.ts.map +1 -1
  397. package/dist/types/authorization/index.d.ts +9 -1
  398. package/dist/types/authorization/index.d.ts.map +1 -1
  399. package/dist/types/authorization/index.js +11 -2
  400. package/dist/types/authorization/index.js.map +1 -1
  401. package/dist/types/browser/index.d.ts +12 -0
  402. package/dist/types/browser/index.d.ts.map +1 -1
  403. package/dist/types/hitl/index.d.ts +10 -0
  404. package/dist/types/hitl/index.d.ts.map +1 -1
  405. package/dist/types/hitl/index.js.map +1 -1
  406. package/dist/types/message/index.d.ts +56 -1
  407. package/dist/types/message/index.d.ts.map +1 -1
  408. package/dist/types/message/index.js +2 -1
  409. package/dist/types/message/index.js.map +1 -1
  410. package/dist/types/permission/index.d.ts +14 -0
  411. package/dist/types/permission/index.d.ts.map +1 -1
  412. package/dist/types/permission/index.js +14 -0
  413. package/dist/types/permission/index.js.map +1 -1
  414. package/dist/types/plugin/index.d.ts +148 -1
  415. package/dist/types/plugin/index.d.ts.map +1 -1
  416. package/dist/types/plugin/index.js +9 -0
  417. package/dist/types/plugin/index.js.map +1 -1
  418. package/dist/types/provider/index.d.ts +1 -0
  419. package/dist/types/provider/index.d.ts.map +1 -1
  420. package/dist/types/provider/interface.d.ts +12 -0
  421. package/dist/types/provider/interface.d.ts.map +1 -1
  422. package/dist/types/provider/limits.d.ts +33 -0
  423. package/dist/types/provider/limits.d.ts.map +1 -0
  424. package/dist/types/provider/limits.js +7 -0
  425. package/dist/types/provider/limits.js.map +1 -0
  426. package/dist/types/tool/index.d.ts +30 -0
  427. package/dist/types/tool/index.d.ts.map +1 -1
  428. package/dist/types/tool/index.js.map +1 -1
  429. package/dist/types/tool/presentation.d.ts +4 -0
  430. package/dist/types/tool/presentation.d.ts.map +1 -1
  431. package/dist/utils/file-lock.d.ts +88 -0
  432. package/dist/utils/file-lock.d.ts.map +1 -0
  433. package/dist/utils/file-lock.js +281 -0
  434. package/dist/utils/file-lock.js.map +1 -0
  435. package/dist/utils/state-backup.d.ts +87 -0
  436. package/dist/utils/state-backup.d.ts.map +1 -0
  437. package/dist/utils/state-backup.js +272 -0
  438. package/dist/utils/state-backup.js.map +1 -0
  439. package/dist/utils/temp-sweep.d.ts +66 -0
  440. package/dist/utils/temp-sweep.d.ts.map +1 -0
  441. package/dist/utils/temp-sweep.js +311 -0
  442. package/dist/utils/temp-sweep.js.map +1 -0
  443. package/dist/utils/temp.d.ts +14 -0
  444. package/dist/utils/temp.d.ts.map +1 -1
  445. package/dist/utils/temp.js +70 -2
  446. package/dist/utils/temp.js.map +1 -1
  447. package/package.json +1 -1
  448. package/src/account/lock.ts +13 -133
  449. package/src/account/registry.ts +75 -21
  450. package/src/account/types.ts +8 -9
  451. package/src/authorization/dangerous-commands.ts +542 -0
  452. package/src/authorization/gate.ts +19 -5
  453. package/src/authorization/protected-paths.ts +13 -8
  454. package/src/authorization/readonly-commands.ts +35 -1
  455. package/src/authorization/removal.ts +7 -7
  456. package/src/authorization/rules.ts +75 -15
  457. package/src/authorization/shell-lexer.ts +19 -0
  458. package/src/bridge/acp/permission.ts +2 -0
  459. package/src/bridge/acp/server.ts +66 -6
  460. package/src/compaction/context-breakdown.ts +53 -11
  461. package/src/compaction/dangling.ts +2 -0
  462. package/src/compaction/extractor.ts +9 -1
  463. package/src/compaction/index.ts +1 -0
  464. package/src/compaction/managers/structured.ts +2 -2
  465. package/src/compaction/manual.ts +11 -3
  466. package/src/compaction/model-summary.ts +8 -1
  467. package/src/compaction/summary.ts +54 -7
  468. package/src/constants/tools/index.ts +30 -16
  469. package/src/manager/session/turn-recorder.ts +37 -1
  470. package/src/network/audit.ts +113 -0
  471. package/src/network/clock.ts +62 -0
  472. package/src/network/discovery-mdns.ts +485 -0
  473. package/src/network/discovery.ts +210 -0
  474. package/src/network/fingerprint.ts +241 -0
  475. package/src/network/identity.ts +98 -0
  476. package/src/network/index.ts +134 -0
  477. package/src/network/join.ts +177 -0
  478. package/src/network/mail-policy.ts +199 -0
  479. package/src/network/membership.ts +290 -0
  480. package/src/network/roster.ts +165 -0
  481. package/src/network/service.ts +2304 -0
  482. package/src/network/store.ts +261 -0
  483. package/src/network/transport.ts +445 -0
  484. package/src/network/wire.ts +250 -0
  485. package/src/network/x509.ts +114 -0
  486. package/src/pals/activity/causality.ts +16 -2
  487. package/src/peers/endpoint.ts +6 -0
  488. package/src/peers/envelope.ts +82 -5
  489. package/src/peers/index.ts +10 -2
  490. package/src/peers/mode-word.ts +18 -0
  491. package/src/peers/protocol.ts +24 -1
  492. package/src/peers/record.ts +5 -0
  493. package/src/plugin/session-hook-env.ts +25 -2
  494. package/src/plugin/shell-hook.ts +208 -14
  495. package/src/prompt/coding-agent-doctrine.ts +33 -38
  496. package/src/public-runtime.ts +107 -1
  497. package/src/public-tools.ts +11 -0
  498. package/src/public-types.ts +67 -1
  499. package/src/runtime/jobs/registry.ts +93 -3
  500. package/src/runtime/query/auto-review/classifier.ts +76 -14
  501. package/src/runtime/query/auto-review/feedback.ts +50 -0
  502. package/src/runtime/query/auto-review/git-status.ts +437 -0
  503. package/src/runtime/query/auto-review/index.ts +7 -2
  504. package/src/runtime/query/auto-review/prompt.ts +6 -1
  505. package/src/runtime/query/auto-review/transcript.ts +67 -4
  506. package/src/runtime/query/executor/tool-call-admission.ts +49 -3
  507. package/src/runtime/query/executor.ts +104 -21
  508. package/src/runtime/query/index.ts +66 -17
  509. package/src/runtime/query/iteration/index.ts +24 -3
  510. package/src/runtime/query/iteration/phases/compaction.ts +4 -0
  511. package/src/runtime/query/iteration/phases/context.ts +5 -0
  512. package/src/runtime/query/iteration/phases/per-call-review.ts +8 -13
  513. package/src/runtime/query/iteration/phases/tool-review.ts +7 -1
  514. package/src/runtime/query/pasted-frames.ts +119 -0
  515. package/src/runtime/query/path-escalation.ts +27 -3
  516. package/src/runtime/query/request-interrupted-turns.ts +47 -0
  517. package/src/runtime/query/review-policy.ts +125 -22
  518. package/src/runtime/query/turn/outcome-ledger.ts +99 -6
  519. package/src/runtime/query/unanswered.ts +35 -0
  520. package/src/runtime/system-events.ts +2 -0
  521. package/src/session/workspace/git-worktree.ts +34 -3
  522. package/src/store/evidence/source-kind.ts +1 -1
  523. package/src/store/session-index/sqlite.ts +40 -3
  524. package/src/store/session-log/disk.ts +1 -1
  525. package/src/store/session-log/lease.ts +3 -2
  526. package/src/tools/admit-facts.ts +2 -0
  527. package/src/tools/builtins/bash.ts +62 -19
  528. package/src/tools/builtins/browser-local.ts +504 -0
  529. package/src/tools/builtins/browser.ts +121 -8
  530. package/src/tools/builtins/computer-use-window-id.ts +50 -0
  531. package/src/tools/builtins/computer-use.ts +460 -68
  532. package/src/tools/builtins/content-fingerprint.ts +8 -1
  533. package/src/tools/builtins/edit.ts +93 -7
  534. package/src/tools/builtins/file-write-result.ts +2 -1
  535. package/src/tools/builtins/grep.ts +1 -1
  536. package/src/tools/builtins/job.ts +4 -2
  537. package/src/tools/builtins/monitor.ts +6 -1
  538. package/src/tools/builtins/search-tools.ts +196 -21
  539. package/src/tools/builtins/shell-read-credit.ts +97 -33
  540. package/src/tools/builtins/wait-for-job.ts +13 -3
  541. package/src/tools/builtins/web-guidance.ts +6 -0
  542. package/src/tools/builtins/web.ts +2 -1
  543. package/src/tools/builtins/write-file.ts +31 -3
  544. package/src/tools/command-shell.ts +6 -8
  545. package/src/tools/defineTool.ts +20 -1
  546. package/src/tools/schedules/index.ts +11 -0
  547. package/src/tools/schedules/loop-tool.ts +10 -6
  548. package/src/tools/schedules/present.ts +1 -1
  549. package/src/tools/schedules/timer-tools.ts +258 -0
  550. package/src/tools/schedules/types.ts +72 -3
  551. package/src/tools/task/create.ts +2 -0
  552. package/src/toolsets/manager.ts +262 -46
  553. package/src/turn/evidence-query.ts +183 -42
  554. package/src/turn/evidence-recall.ts +96 -19
  555. package/src/turn/history-shed.ts +30 -0
  556. package/src/types/acp/index.ts +24 -0
  557. package/src/types/authorization/index.ts +20 -3
  558. package/src/types/browser/index.ts +9 -0
  559. package/src/types/hitl/index.ts +10 -0
  560. package/src/types/message/index.ts +65 -0
  561. package/src/types/permission/index.ts +18 -0
  562. package/src/types/plugin/index.ts +205 -26
  563. package/src/types/provider/index.ts +1 -0
  564. package/src/types/provider/interface.ts +13 -0
  565. package/src/types/provider/limits.ts +35 -0
  566. package/src/types/tool/index.ts +30 -2
  567. package/src/types/tool/presentation.ts +4 -0
  568. package/src/utils/file-lock.ts +328 -0
  569. package/src/utils/state-backup.ts +318 -0
  570. package/src/utils/temp-sweep.ts +327 -0
  571. package/src/utils/temp.ts +73 -2
@@ -0,0 +1,281 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { closeSync, fstatSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeSync, } from 'node:fs';
3
+ import { dirname } from 'node:path';
4
+ import { isMainThread } from 'node:worker_threads';
5
+ /**
6
+ * A lock file beside a shared record, so two processes that read, change and
7
+ * write the same file never lose one another's change.
8
+ *
9
+ * The protocol, which any writer of the same files must follow (Desktop has
10
+ * its own copy because it cannot load this package at run time):
11
+ *
12
+ * - The lock is `<file>.lock`, created with `O_CREAT | O_EXCL` (`'wx'`) and
13
+ * mode 0600. Its whole body is `<pid>:<epoch ms>:<random hex>`. A creator
14
+ * whose body write fails removes the lock again before it reports the error.
15
+ * - A lock is stale, and is reclaimed, when its recorded pid no longer exists;
16
+ * when it records no pid (an empty or cut-off body) and its last change is
17
+ * more than {@link EMPTY_LOCK_GRACE_MS} away from now, so a creator that
18
+ * died between creating it and writing its body cannot block the file for
19
+ * good; or when it records this process's own pid while this process does
20
+ * not hold it, which is a lock left by an earlier process that had the same
21
+ * pid. Reclaimers are serialised by `<file>.lock.reclaim` (body: the
22
+ * reclaimer's pid), and the lock is checked again under that guard, so a
23
+ * lock that a live owner took in the meantime is never removed. There is no
24
+ * age timer for a lock with a live owner: a slow owner keeps its lock.
25
+ * - The owner removes the lock when done, and only while the lock still holds
26
+ * its own body.
27
+ *
28
+ * The lock is held across local read and write work, never across a prompt,
29
+ * and only from a process's main thread.
30
+ */
31
+ export class FileLockError extends Error {
32
+ lockPath;
33
+ name = 'FileLockError';
34
+ constructor(lockPath, message) {
35
+ super(message);
36
+ this.lockPath = lockPath;
37
+ }
38
+ }
39
+ /**
40
+ * How long a lock that records no owner is left alone. Its creator writes the
41
+ * body right after creating the file, so a lock still without one this long
42
+ * after its last change was left by a creator that failed or was killed.
43
+ */
44
+ export const EMPTY_LOCK_GRACE_MS = 10_000;
45
+ /** The lock file the protocol above uses for `file`. */
46
+ export function lockPathFor(file) {
47
+ return `${file}.lock`;
48
+ }
49
+ /**
50
+ * The bodies of the locks this process holds right now, shared by every copy
51
+ * of this module loaded in the same thread, so a lock with this process's pid
52
+ * that none of them holds is known to be left over.
53
+ */
54
+ const HELD_KEY = Symbol.for('namzu.file-lock.held');
55
+ function heldBodies() {
56
+ const scope = globalThis;
57
+ scope[HELD_KEY] ??= new Set();
58
+ return scope[HELD_KEY];
59
+ }
60
+ function writeBody(fd, body) {
61
+ const bytes = Buffer.from(body, 'utf8');
62
+ let written = 0;
63
+ while (written < bytes.length)
64
+ written += writeSync(fd, bytes, written);
65
+ }
66
+ function sameFile(a, b) {
67
+ return a.dev === b.dev && a.ino === b.ino;
68
+ }
69
+ function acquire(lockPath) {
70
+ const token = `${process.pid}:${Date.now()}:${randomBytes(12).toString('hex')}`;
71
+ mkdirSync(dirname(lockPath), { recursive: true, mode: 0o700 });
72
+ for (let pass = 0; pass < 2; pass++) {
73
+ let fd;
74
+ try {
75
+ fd = openSync(lockPath, 'wx', 0o600);
76
+ }
77
+ catch (error) {
78
+ if (error.code !== 'EEXIST')
79
+ throw error;
80
+ if (pass === 0 && reclaimIfStale(lockPath))
81
+ continue;
82
+ return undefined;
83
+ }
84
+ try {
85
+ writeBody(fd, token);
86
+ }
87
+ catch (error) {
88
+ // A full disk creates the file and then fails its body. An empty lock
89
+ // left behind would refuse every later change, so it goes now, while
90
+ // it is still the file this call created.
91
+ try {
92
+ if (sameFile(fstatSync(fd), statSync(lockPath)))
93
+ rmSync(lockPath, { force: true });
94
+ }
95
+ catch {
96
+ // Already gone, or replaced by someone else: not ours to remove.
97
+ }
98
+ closeSync(fd);
99
+ throw error;
100
+ }
101
+ closeSync(fd);
102
+ heldBodies().add(token);
103
+ return token;
104
+ }
105
+ return undefined;
106
+ }
107
+ function pidOf(token) {
108
+ const pid = Number.parseInt(token.split(':', 1)[0] ?? '', 10);
109
+ return Number.isInteger(pid) && pid > 0 ? pid : undefined;
110
+ }
111
+ function processIsDead(pid) {
112
+ try {
113
+ process.kill(pid, 0);
114
+ return false;
115
+ }
116
+ catch (error) {
117
+ // EPERM means the process exists but belongs to someone else: alive.
118
+ return error.code === 'ESRCH';
119
+ }
120
+ }
121
+ function sight(lockPath) {
122
+ try {
123
+ const stat = statSync(lockPath);
124
+ return { body: readFileSync(lockPath, 'utf8'), stat };
125
+ }
126
+ catch {
127
+ return undefined;
128
+ }
129
+ }
130
+ function isStale(seen, now) {
131
+ const pid = pidOf(seen.body);
132
+ if (pid === undefined)
133
+ return Math.abs(now - seen.stat.mtimeMs) > EMPTY_LOCK_GRACE_MS;
134
+ if (pid === process.pid)
135
+ return isMainThread && !heldBodies().has(seen.body);
136
+ return processIsDead(pid);
137
+ }
138
+ /** True when `again` is the very lock `seen` described: same file, same body, unchanged since. */
139
+ function unchanged(seen, again) {
140
+ return (again.body === seen.body &&
141
+ sameFile(again.stat, seen.stat) &&
142
+ again.stat.mtimeMs === seen.stat.mtimeMs &&
143
+ again.stat.size === seen.stat.size);
144
+ }
145
+ /**
146
+ * Remove a lock that is stale (see the protocol above). Reclaimers are
147
+ * serialised by a guard file, and the lock is re-read under the guard, so a
148
+ * lock that was replaced by a live owner in the meantime is never removed.
149
+ */
150
+ function reclaimIfStale(lockPath) {
151
+ const seen = sight(lockPath);
152
+ if (seen === undefined)
153
+ return true; // already gone; the caller may simply try again
154
+ if (!isStale(seen, Date.now()))
155
+ return false;
156
+ const guard = `${lockPath}.reclaim`;
157
+ let fd;
158
+ try {
159
+ fd = openSync(guard, 'wx', 0o600);
160
+ }
161
+ catch (error) {
162
+ if (error.code !== 'EEXIST')
163
+ throw error;
164
+ try {
165
+ const holder = sight(guard);
166
+ if (holder && isStale(holder, Date.now()))
167
+ rmSync(guard, { force: true });
168
+ }
169
+ catch {
170
+ // The guard vanished or is unreadable; the next attempt decides.
171
+ }
172
+ return false;
173
+ }
174
+ try {
175
+ try {
176
+ writeBody(fd, `${process.pid}`);
177
+ }
178
+ finally {
179
+ closeSync(fd);
180
+ }
181
+ const again = sight(lockPath);
182
+ if (again === undefined)
183
+ return true;
184
+ if (!unchanged(seen, again))
185
+ return false;
186
+ rmSync(lockPath, { force: true });
187
+ return true;
188
+ }
189
+ finally {
190
+ rmSync(guard, { force: true });
191
+ }
192
+ }
193
+ function release(lockPath, token) {
194
+ heldBodies().delete(token);
195
+ // Never remove a successor's lock if something else replaced the file.
196
+ try {
197
+ if (readFileSync(lockPath, 'utf8') === token)
198
+ rmSync(lockPath, { force: true });
199
+ }
200
+ catch {
201
+ // The work already has its result; a missing lock is not its failure.
202
+ }
203
+ }
204
+ /**
205
+ * Read who holds the lock at `lockPath` without taking or changing it. A stale
206
+ * lock is taken over by the next change that meets it, so this is for saying
207
+ * what is there (as `namzu doctor` does), not for deciding to write.
208
+ */
209
+ export function inspectFileLock(lockPath, now = Date.now()) {
210
+ let seen;
211
+ try {
212
+ seen = { stat: statSync(lockPath), body: readFileSync(lockPath, 'utf8') };
213
+ }
214
+ catch (error) {
215
+ const code = error.code;
216
+ if (code === 'ENOENT')
217
+ return { state: 'free' };
218
+ return { state: 'unreadable', reason: code ?? String(error) };
219
+ }
220
+ const pid = pidOf(seen.body);
221
+ if (isStale(seen, now))
222
+ return pid === undefined ? { state: 'stale' } : { state: 'stale', pid };
223
+ return pid === undefined ? { state: 'held' } : { state: 'held', pid };
224
+ }
225
+ function fileLockRefusal(lockPath) {
226
+ return new FileLockError(lockPath, `another process holds the lock ${lockPath}. The lock is reclaimed on its own when the process that recorded it has exited; if that process is still running, wait for it to finish.`);
227
+ }
228
+ /** The shared body of every async lock in this package; `refusal` names the error a caller sees. */
229
+ export async function runLocked(lockPath, operation, options, refusal) {
230
+ const attempts = Math.max(1, options.attempts ?? 1);
231
+ let token;
232
+ for (let attempt = 0; attempt < attempts; attempt++) {
233
+ token = acquire(lockPath);
234
+ if (token !== undefined)
235
+ break;
236
+ if (attempt + 1 < attempts && options.wait)
237
+ await options.wait(attempt);
238
+ }
239
+ if (token === undefined)
240
+ throw refusal(lockPath);
241
+ try {
242
+ return await operation();
243
+ }
244
+ finally {
245
+ release(lockPath, token);
246
+ }
247
+ }
248
+ /** The shared body of every sync lock in this package; `refusal` names the error a caller sees. */
249
+ export function runLockedSync(lockPath, operation, options, refusal) {
250
+ const attempts = Math.max(1, options.attempts ?? 1);
251
+ let token;
252
+ for (let attempt = 0; attempt < attempts; attempt++) {
253
+ token = acquire(lockPath);
254
+ if (token !== undefined)
255
+ break;
256
+ if (attempt + 1 < attempts && options.wait)
257
+ options.wait(attempt);
258
+ }
259
+ if (token === undefined)
260
+ throw refusal(lockPath);
261
+ try {
262
+ return operation();
263
+ }
264
+ finally {
265
+ release(lockPath, token);
266
+ }
267
+ }
268
+ /**
269
+ * Run `operation` while holding the lock file at `lockPath` (usually
270
+ * {@link lockPathFor} of the record it guards). A lock whose recorded process
271
+ * has exited is reclaimed; a lock held by a live process is a
272
+ * {@link FileLockError} (or a wait, when attempts and a wait function are given).
273
+ */
274
+ export function withFileLock(lockPath, operation, options = {}) {
275
+ return runLocked(lockPath, operation, options, fileLockRefusal);
276
+ }
277
+ /** Synchronous form of {@link withFileLock}, for short read-change-write work on a small file. */
278
+ export function withFileLockSync(lockPath, operation, options = {}) {
279
+ return runLockedSync(lockPath, operation, options, fileLockRefusal);
280
+ }
281
+ //# sourceMappingURL=file-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-lock.js","sourceRoot":"","sources":["../../src/utils/file-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAEN,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,SAAS,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAG7B;IAFQ,IAAI,GAAW,eAAe,CAAA;IAChD,YACU,QAAgB,EACzB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QAHL,aAAQ,GAAR,QAAQ,CAAQ;IAI1B,CAAC;CACD;AAgBD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAEzC,wDAAwD;AACx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AC;AACF,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,aAAa,CAC5B,QAAgB,EAChB,SAAkB,EAClB,OAA4B,EAC5B,OAAoC;IAEpC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAA;IACnD,IAAI,KAAyB,CAAA;IAC7B,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC;QACrD,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;QACzB,IAAI,KAAK,KAAK,SAAS;YAAE,MAAK;QAC9B,IAAI,OAAO,GAAG,CAAC,GAAG,QAAQ,IAAI,OAAO,CAAC,IAAI;YAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAClE,CAAC;IACD,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAA;IAChD,IAAI,CAAC;QACJ,OAAO,SAAS,EAAE,CAAA;IACnB,CAAC;YAAS,CAAC;QACV,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IACzB,CAAC;AACF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC3B,QAAgB,EAChB,SAA+B,EAC/B,UAA2B,EAAE;IAE7B,OAAO,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,CAAC,CAAA;AAChE,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,gBAAgB,CAC/B,QAAgB,EAChB,SAAkB,EAClB,UAA+B,EAAE;IAEjC,OAAO,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,CAAC,CAAA;AACpE,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Recovery copies of the small state files in the Namzu home whose loss hurts
3
+ * (settings, folder trust, server approvals, accounts, the provider chain).
4
+ *
5
+ * - `<home>/backups/<file>.backup.<epoch ms>`: the file as it was just before
6
+ * a write. At most one per {@link STATE_BACKUP_MIN_INTERVAL_MS} per file, the
7
+ * newest {@link STATE_BACKUP_KEEP} kept. A copy identical to the newest one is
8
+ * not taken again, so the kept copies are distinct states.
9
+ * - `<home>/backups/<file>.corrupted.<epoch ms>`: a file that could not be
10
+ * read, kept before anything is allowed to replace it.
11
+ *
12
+ * The number in a name only ever grows for a file: a copy is named at least
13
+ * one more than the newest of its kind, also when the clock went back, so the
14
+ * highest number is always the copy written last. The copy's modification
15
+ * time is set to when it was taken, and the one-a-minute limit is measured
16
+ * from that, not from the name.
17
+ *
18
+ * Every copy is written private (0600) whatever the source's mode, because
19
+ * some of these files hold keys. Nothing is restored automatically: restoring
20
+ * is copying one of these back over the file.
21
+ */
22
+ export declare const STATE_BACKUPS_DIR = "backups";
23
+ export declare const STATE_BACKUP_KEEP = 5;
24
+ export declare const STATE_BACKUP_MIN_INTERVAL_MS = 60000;
25
+ export interface StateBackupOptions {
26
+ /** The Namzu home; copies go to `<home>/backups/`. */
27
+ readonly home: string;
28
+ /** Epoch milliseconds; injected so a test never depends on the clock. */
29
+ readonly now?: () => number;
30
+ }
31
+ export interface StateBackupFileOptions extends StateBackupOptions {
32
+ /**
33
+ * Applied to the file's text before it is copied, for a secret the coming
34
+ * write removes and that must not reach a copy either.
35
+ */
36
+ readonly redact?: (text: string) => string;
37
+ }
38
+ export interface StateFileCopy {
39
+ readonly path: string;
40
+ /** The base name of the file this copies, such as `trust.json`. */
41
+ readonly file: string;
42
+ readonly kind: 'backup' | 'corrupted';
43
+ /** Epoch milliseconds from the copy's name; the highest is the copy written last. */
44
+ readonly at: number;
45
+ /** When the copy was taken (its modification time), for saying so to a person. */
46
+ readonly takenAt: number;
47
+ }
48
+ export declare function stateBackupsDir(home: string): string;
49
+ /** The copies in `<home>/backups/`, newest first; only those of `file` when it is given. */
50
+ export declare function listStateFileCopies(home: string, file?: string): StateFileCopy[];
51
+ /**
52
+ * Write `content` to `file` through a private temporary beside it: the body is
53
+ * flushed to disk before the rename, so a reader sees the old file or the
54
+ * whole new one, also after a power loss. The directory is flushed too where
55
+ * the platform allows it.
56
+ */
57
+ export declare function writeFileAtomicSync(file: string, content: string | Uint8Array, options?: {
58
+ readonly mode?: number;
59
+ }): void;
60
+ /**
61
+ * Take a recovery copy of `file` before it is replaced. Skipped when the file
62
+ * does not exist or is empty, when the newest copy was taken less than a minute ago, or
63
+ * when it is the same as the newest copy. A newest copy taken "later" than now
64
+ * (the clock went back) does not hold the next one off. Never throws: a copy
65
+ * that could not be taken must not stop the write it was protecting. Returns
66
+ * the copy written, if any.
67
+ */
68
+ export declare function backupStateFile(file: string, options: StateBackupFileOptions): string | undefined;
69
+ /**
70
+ * Keep the bytes of a file that could not be read as `<file>.corrupted.<ms>`
71
+ * before anything may replace it. A file already kept with the same bytes is
72
+ * not copied again, so a damaged file is reported once, not on every write.
73
+ * The copy is read back and compared before this returns. Throws when no copy
74
+ * can be made; the caller must then refuse its write.
75
+ */
76
+ export declare function preserveUnreadableStateFile(file: string, options: StateBackupOptions): {
77
+ readonly path: string;
78
+ readonly fresh: boolean;
79
+ };
80
+ /**
81
+ * Change every recovery copy of `file`, for a secret that must not outlive its
82
+ * removal in an old copy. `edit` gets a copy's text and returns its new text,
83
+ * or `undefined` to remove that copy. A copy that cannot be rewritten is
84
+ * removed rather than left holding what was asked to go.
85
+ */
86
+ export declare function rewriteStateFileBackups(home: string, file: string, edit: (text: string) => string | undefined): void;
87
+ //# sourceMappingURL=state-backup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-backup.d.ts","sourceRoot":"","sources":["../../src/utils/state-backup.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,YAAY,CAAA;AAC1C,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAClC,eAAO,MAAM,4BAA4B,QAAS,CAAA;AAKlD,MAA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AC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAepD;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GACxC,IAAI,CAYN"}
@@ -0,0 +1,272 @@
1
+ import { chmodSync, closeSync, fsyncSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, utimesSync, writeSync, } from 'node:fs';
2
+ import { basename, dirname, join } from 'node:path';
3
+ import { temporaryPathFor } from './atomic-write.js';
4
+ /**
5
+ * Recovery copies of the small state files in the Namzu home whose loss hurts
6
+ * (settings, folder trust, server approvals, accounts, the provider chain).
7
+ *
8
+ * - `<home>/backups/<file>.backup.<epoch ms>`: the file as it was just before
9
+ * a write. At most one per {@link STATE_BACKUP_MIN_INTERVAL_MS} per file, the
10
+ * newest {@link STATE_BACKUP_KEEP} kept. A copy identical to the newest one is
11
+ * not taken again, so the kept copies are distinct states.
12
+ * - `<home>/backups/<file>.corrupted.<epoch ms>`: a file that could not be
13
+ * read, kept before anything is allowed to replace it.
14
+ *
15
+ * The number in a name only ever grows for a file: a copy is named at least
16
+ * one more than the newest of its kind, also when the clock went back, so the
17
+ * highest number is always the copy written last. The copy's modification
18
+ * time is set to when it was taken, and the one-a-minute limit is measured
19
+ * from that, not from the name.
20
+ *
21
+ * Every copy is written private (0600) whatever the source's mode, because
22
+ * some of these files hold keys. Nothing is restored automatically: restoring
23
+ * is copying one of these back over the file.
24
+ */
25
+ export const STATE_BACKUPS_DIR = 'backups';
26
+ export const STATE_BACKUP_KEEP = 5;
27
+ export const STATE_BACKUP_MIN_INTERVAL_MS = 60_000;
28
+ const DIR_MODE = 0o700;
29
+ const FILE_MODE = 0o600;
30
+ export function stateBackupsDir(home) {
31
+ return join(home, STATE_BACKUPS_DIR);
32
+ }
33
+ const COPY_NAME = /^(.+?)\.(backup|corrupted)\.(\d{1,16})$/;
34
+ function parseCopy(dir, entry) {
35
+ const match = COPY_NAME.exec(entry);
36
+ if (!match)
37
+ return undefined;
38
+ const at = Number(match[3]);
39
+ if (!Number.isSafeInteger(at))
40
+ return undefined;
41
+ const path = join(dir, entry);
42
+ let takenAt = at;
43
+ try {
44
+ takenAt = statSync(path).mtimeMs;
45
+ }
46
+ catch {
47
+ // Listed a moment ago; the name's number is the best left.
48
+ }
49
+ const kind = match[2] === 'backup' ? 'backup' : 'corrupted';
50
+ return { path, file: match[1], kind, at, takenAt };
51
+ }
52
+ /** The copies in `<home>/backups/`, newest first; only those of `file` when it is given. */
53
+ export function listStateFileCopies(home, file) {
54
+ const dir = stateBackupsDir(home);
55
+ let entries;
56
+ try {
57
+ entries = readdirSync(dir);
58
+ }
59
+ catch {
60
+ return [];
61
+ }
62
+ const copies = [];
63
+ for (const entry of entries) {
64
+ const copy = parseCopy(dir, entry);
65
+ if (copy && (file === undefined || copy.file === file))
66
+ copies.push(copy);
67
+ }
68
+ return copies.sort((a, b) => b.at - a.at || (a.path < b.path ? 1 : -1));
69
+ }
70
+ /**
71
+ * Write `content` to `file` through a private temporary beside it: the body is
72
+ * flushed to disk before the rename, so a reader sees the old file or the
73
+ * whole new one, also after a power loss. The directory is flushed too where
74
+ * the platform allows it.
75
+ */
76
+ export function writeFileAtomicSync(file, content, options = {}) {
77
+ const temporary = temporaryPathFor(file);
78
+ let fd;
79
+ try {
80
+ fd = openSync(temporary, 'wx', options.mode ?? FILE_MODE);
81
+ const bytes = typeof content === 'string' ? Buffer.from(content, 'utf8') : content;
82
+ let written = 0;
83
+ while (written < bytes.length)
84
+ written += writeSync(fd, bytes, written);
85
+ fsyncSync(fd);
86
+ closeSync(fd);
87
+ fd = undefined;
88
+ renameSync(temporary, file);
89
+ }
90
+ catch (error) {
91
+ if (fd !== undefined) {
92
+ try {
93
+ closeSync(fd);
94
+ }
95
+ catch {
96
+ // The write already failed; that is the error to report.
97
+ }
98
+ }
99
+ rmSync(temporary, { force: true });
100
+ throw error;
101
+ }
102
+ syncDirectoryQuietly(dirname(file));
103
+ }
104
+ function syncDirectoryQuietly(directory) {
105
+ if (process.platform === 'win32')
106
+ return;
107
+ let fd;
108
+ try {
109
+ fd = openSync(directory, 'r');
110
+ fsyncSync(fd);
111
+ }
112
+ catch {
113
+ // The file itself is already flushed; the directory entry is the filesystem's.
114
+ }
115
+ finally {
116
+ if (fd !== undefined)
117
+ closeSync(fd);
118
+ }
119
+ }
120
+ /**
121
+ * Write a private copy and prove it: a copy that keeps a wide mode, or does not
122
+ * read back as `bytes`, is removed. `takenAt` becomes its modification time.
123
+ */
124
+ function writePrivateCopy(path, bytes, takenAt) {
125
+ writeFileAtomicSync(path, bytes, { mode: FILE_MODE });
126
+ try {
127
+ if (process.platform !== 'win32') {
128
+ if ((statSync(path).mode & 0o077) !== 0)
129
+ chmodSync(path, FILE_MODE);
130
+ if ((statSync(path).mode & 0o077) !== 0)
131
+ throw new Error(`${path} could not be made private`);
132
+ }
133
+ if (!sameBytes(path, bytes))
134
+ throw new Error(`${path} does not read back as what was written`);
135
+ const seconds = takenAt / 1000;
136
+ utimesSync(path, seconds, seconds);
137
+ }
138
+ catch (error) {
139
+ rmSync(path, { force: true });
140
+ throw error;
141
+ }
142
+ }
143
+ function sameBytes(path, bytes) {
144
+ try {
145
+ if (statSync(path).size !== bytes.length)
146
+ return false;
147
+ return Buffer.compare(readFileSync(path), bytes) === 0;
148
+ }
149
+ catch {
150
+ return false;
151
+ }
152
+ }
153
+ function prune(copies, keep) {
154
+ for (const old of copies.slice(keep))
155
+ rmSync(old.path, { force: true });
156
+ }
157
+ /**
158
+ * A name not yet taken, numbered at least one past the newest copy of its kind,
159
+ * so the order of the names is the order the copies were written in.
160
+ */
161
+ function freshName(dir, file, kind, at, newest) {
162
+ let stamp = newest ? Math.max(at, newest.at + 1) : at;
163
+ for (;;) {
164
+ const candidate = join(dir, `${file}.${kind}.${stamp}`);
165
+ try {
166
+ statSync(candidate);
167
+ stamp += 1;
168
+ }
169
+ catch {
170
+ return candidate;
171
+ }
172
+ }
173
+ }
174
+ function ensureDir(home) {
175
+ const dir = stateBackupsDir(home);
176
+ mkdirSync(dir, { recursive: true, mode: DIR_MODE });
177
+ if (process.platform !== 'win32') {
178
+ try {
179
+ if ((statSync(dir).mode & 0o077) !== 0)
180
+ chmodSync(dir, DIR_MODE);
181
+ }
182
+ catch {
183
+ // The copies themselves are private; a wide folder is reported by doctor.
184
+ }
185
+ }
186
+ return dir;
187
+ }
188
+ /**
189
+ * Take a recovery copy of `file` before it is replaced. Skipped when the file
190
+ * does not exist or is empty, when the newest copy was taken less than a minute ago, or
191
+ * when it is the same as the newest copy. A newest copy taken "later" than now
192
+ * (the clock went back) does not hold the next one off. Never throws: a copy
193
+ * that could not be taken must not stop the write it was protecting. Returns
194
+ * the copy written, if any.
195
+ */
196
+ export function backupStateFile(file, options) {
197
+ try {
198
+ const now = options.now?.() ?? Date.now();
199
+ const name = basename(file);
200
+ const existing = listStateFileCopies(options.home, name).filter((c) => c.kind === 'backup');
201
+ const newest = existing[0];
202
+ const since = newest ? now - newest.takenAt : Number.POSITIVE_INFINITY;
203
+ if (since >= 0 && since < STATE_BACKUP_MIN_INTERVAL_MS)
204
+ return undefined;
205
+ let bytes;
206
+ try {
207
+ bytes = readFileSync(file);
208
+ }
209
+ catch {
210
+ return undefined;
211
+ }
212
+ // An empty file holds nothing to go back to, and must not become "the newest copy".
213
+ if (bytes.toString('utf8').trim() === '')
214
+ return undefined;
215
+ if (options.redact)
216
+ bytes = Buffer.from(options.redact(bytes.toString('utf8')), 'utf8');
217
+ if (newest && sameBytes(newest.path, bytes))
218
+ return undefined;
219
+ const dir = ensureDir(options.home);
220
+ const path = freshName(dir, name, 'backup', now, newest);
221
+ writePrivateCopy(path, bytes, now);
222
+ prune(listStateFileCopies(options.home, name).filter((c) => c.kind === 'backup'), STATE_BACKUP_KEEP);
223
+ return path;
224
+ }
225
+ catch {
226
+ return undefined;
227
+ }
228
+ }
229
+ /**
230
+ * Keep the bytes of a file that could not be read as `<file>.corrupted.<ms>`
231
+ * before anything may replace it. A file already kept with the same bytes is
232
+ * not copied again, so a damaged file is reported once, not on every write.
233
+ * The copy is read back and compared before this returns. Throws when no copy
234
+ * can be made; the caller must then refuse its write.
235
+ */
236
+ export function preserveUnreadableStateFile(file, options) {
237
+ const bytes = readFileSync(file);
238
+ const name = basename(file);
239
+ const kept = listStateFileCopies(options.home, name).filter((c) => c.kind === 'corrupted');
240
+ const same = kept.find((copy) => sameBytes(copy.path, bytes));
241
+ if (same)
242
+ return { path: same.path, fresh: false };
243
+ const dir = ensureDir(options.home);
244
+ const now = options.now?.() ?? Date.now();
245
+ const path = freshName(dir, name, 'corrupted', now, kept[0]);
246
+ writePrivateCopy(path, bytes, now);
247
+ prune(listStateFileCopies(options.home, name).filter((c) => c.kind === 'corrupted'), STATE_BACKUP_KEEP);
248
+ return { path, fresh: true };
249
+ }
250
+ /**
251
+ * Change every recovery copy of `file`, for a secret that must not outlive its
252
+ * removal in an old copy. `edit` gets a copy's text and returns its new text,
253
+ * or `undefined` to remove that copy. A copy that cannot be rewritten is
254
+ * removed rather than left holding what was asked to go.
255
+ */
256
+ export function rewriteStateFileBackups(home, file, edit) {
257
+ for (const copy of listStateFileCopies(home, file)) {
258
+ try {
259
+ const text = readFileSync(copy.path, 'utf8');
260
+ const next = edit(text);
261
+ if (next === undefined)
262
+ rmSync(copy.path, { force: true });
263
+ // Rewritten in place, it keeps the time it was taken.
264
+ else if (next !== text)
265
+ writePrivateCopy(copy.path, Buffer.from(next, 'utf8'), copy.takenAt);
266
+ }
267
+ catch {
268
+ rmSync(copy.path, { force: true });
269
+ }
270
+ }
271
+ }
272
+ //# sourceMappingURL=state-backup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state-backup.js","sourceRoot":"","sources":["../../src/utils/state-backup.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,SAAS,EACT,SAAS,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