@namzu/sdk 65.3.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 (568) hide show
  1. package/CHANGELOG.md +153 -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 +84 -6
  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/hitl/index.d.ts +10 -0
  402. package/dist/types/hitl/index.d.ts.map +1 -1
  403. package/dist/types/hitl/index.js.map +1 -1
  404. package/dist/types/message/index.d.ts +56 -1
  405. package/dist/types/message/index.d.ts.map +1 -1
  406. package/dist/types/message/index.js +2 -1
  407. package/dist/types/message/index.js.map +1 -1
  408. package/dist/types/permission/index.d.ts +14 -0
  409. package/dist/types/permission/index.d.ts.map +1 -1
  410. package/dist/types/permission/index.js +14 -0
  411. package/dist/types/permission/index.js.map +1 -1
  412. package/dist/types/plugin/index.d.ts +148 -1
  413. package/dist/types/plugin/index.d.ts.map +1 -1
  414. package/dist/types/plugin/index.js +9 -0
  415. package/dist/types/plugin/index.js.map +1 -1
  416. package/dist/types/provider/index.d.ts +1 -0
  417. package/dist/types/provider/index.d.ts.map +1 -1
  418. package/dist/types/provider/interface.d.ts +12 -0
  419. package/dist/types/provider/interface.d.ts.map +1 -1
  420. package/dist/types/provider/limits.d.ts +33 -0
  421. package/dist/types/provider/limits.d.ts.map +1 -0
  422. package/dist/types/provider/limits.js +7 -0
  423. package/dist/types/provider/limits.js.map +1 -0
  424. package/dist/types/tool/index.d.ts +30 -0
  425. package/dist/types/tool/index.d.ts.map +1 -1
  426. package/dist/types/tool/index.js.map +1 -1
  427. package/dist/types/tool/presentation.d.ts +4 -0
  428. package/dist/types/tool/presentation.d.ts.map +1 -1
  429. package/dist/utils/file-lock.d.ts +88 -0
  430. package/dist/utils/file-lock.d.ts.map +1 -0
  431. package/dist/utils/file-lock.js +281 -0
  432. package/dist/utils/file-lock.js.map +1 -0
  433. package/dist/utils/state-backup.d.ts +87 -0
  434. package/dist/utils/state-backup.d.ts.map +1 -0
  435. package/dist/utils/state-backup.js +272 -0
  436. package/dist/utils/state-backup.js.map +1 -0
  437. package/dist/utils/temp-sweep.d.ts +66 -0
  438. package/dist/utils/temp-sweep.d.ts.map +1 -0
  439. package/dist/utils/temp-sweep.js +311 -0
  440. package/dist/utils/temp-sweep.js.map +1 -0
  441. package/dist/utils/temp.d.ts +14 -0
  442. package/dist/utils/temp.d.ts.map +1 -1
  443. package/dist/utils/temp.js +70 -2
  444. package/dist/utils/temp.js.map +1 -1
  445. package/package.json +1 -1
  446. package/src/account/lock.ts +13 -133
  447. package/src/account/registry.ts +75 -21
  448. package/src/account/types.ts +8 -9
  449. package/src/authorization/dangerous-commands.ts +542 -0
  450. package/src/authorization/gate.ts +19 -5
  451. package/src/authorization/protected-paths.ts +13 -8
  452. package/src/authorization/readonly-commands.ts +35 -1
  453. package/src/authorization/removal.ts +7 -7
  454. package/src/authorization/rules.ts +75 -15
  455. package/src/authorization/shell-lexer.ts +19 -0
  456. package/src/bridge/acp/permission.ts +2 -0
  457. package/src/bridge/acp/server.ts +66 -6
  458. package/src/compaction/context-breakdown.ts +53 -11
  459. package/src/compaction/dangling.ts +2 -0
  460. package/src/compaction/extractor.ts +9 -1
  461. package/src/compaction/index.ts +1 -0
  462. package/src/compaction/managers/structured.ts +2 -2
  463. package/src/compaction/manual.ts +11 -3
  464. package/src/compaction/model-summary.ts +8 -1
  465. package/src/compaction/summary.ts +54 -7
  466. package/src/constants/tools/index.ts +30 -16
  467. package/src/manager/session/turn-recorder.ts +37 -1
  468. package/src/network/audit.ts +113 -0
  469. package/src/network/clock.ts +62 -0
  470. package/src/network/discovery-mdns.ts +485 -0
  471. package/src/network/discovery.ts +210 -0
  472. package/src/network/fingerprint.ts +241 -0
  473. package/src/network/identity.ts +98 -0
  474. package/src/network/index.ts +134 -0
  475. package/src/network/join.ts +177 -0
  476. package/src/network/mail-policy.ts +199 -0
  477. package/src/network/membership.ts +290 -0
  478. package/src/network/roster.ts +165 -0
  479. package/src/network/service.ts +2304 -0
  480. package/src/network/store.ts +261 -0
  481. package/src/network/transport.ts +445 -0
  482. package/src/network/wire.ts +250 -0
  483. package/src/network/x509.ts +114 -0
  484. package/src/pals/activity/causality.ts +16 -2
  485. package/src/peers/endpoint.ts +6 -0
  486. package/src/peers/envelope.ts +82 -5
  487. package/src/peers/index.ts +10 -2
  488. package/src/peers/mode-word.ts +18 -0
  489. package/src/peers/protocol.ts +24 -1
  490. package/src/peers/record.ts +5 -0
  491. package/src/plugin/session-hook-env.ts +25 -2
  492. package/src/plugin/shell-hook.ts +208 -14
  493. package/src/prompt/coding-agent-doctrine.ts +33 -38
  494. package/src/public-runtime.ts +107 -1
  495. package/src/public-tools.ts +11 -0
  496. package/src/public-types.ts +67 -1
  497. package/src/runtime/jobs/registry.ts +93 -3
  498. package/src/runtime/query/auto-review/classifier.ts +76 -14
  499. package/src/runtime/query/auto-review/feedback.ts +50 -0
  500. package/src/runtime/query/auto-review/git-status.ts +437 -0
  501. package/src/runtime/query/auto-review/index.ts +7 -2
  502. package/src/runtime/query/auto-review/prompt.ts +6 -1
  503. package/src/runtime/query/auto-review/transcript.ts +67 -4
  504. package/src/runtime/query/executor/tool-call-admission.ts +49 -3
  505. package/src/runtime/query/executor.ts +104 -21
  506. package/src/runtime/query/index.ts +66 -17
  507. package/src/runtime/query/iteration/index.ts +24 -3
  508. package/src/runtime/query/iteration/phases/compaction.ts +4 -0
  509. package/src/runtime/query/iteration/phases/context.ts +5 -0
  510. package/src/runtime/query/iteration/phases/per-call-review.ts +8 -13
  511. package/src/runtime/query/iteration/phases/tool-review.ts +7 -1
  512. package/src/runtime/query/pasted-frames.ts +119 -0
  513. package/src/runtime/query/path-escalation.ts +27 -3
  514. package/src/runtime/query/request-interrupted-turns.ts +47 -0
  515. package/src/runtime/query/review-policy.ts +125 -22
  516. package/src/runtime/query/turn/outcome-ledger.ts +99 -6
  517. package/src/runtime/query/unanswered.ts +35 -0
  518. package/src/runtime/system-events.ts +2 -0
  519. package/src/session/workspace/git-worktree.ts +34 -3
  520. package/src/store/evidence/source-kind.ts +1 -1
  521. package/src/store/session-index/sqlite.ts +40 -3
  522. package/src/store/session-log/disk.ts +1 -1
  523. package/src/store/session-log/lease.ts +3 -2
  524. package/src/tools/admit-facts.ts +2 -0
  525. package/src/tools/builtins/bash.ts +62 -19
  526. package/src/tools/builtins/browser-local.ts +504 -0
  527. package/src/tools/builtins/browser.ts +108 -6
  528. package/src/tools/builtins/computer-use-window-id.ts +50 -0
  529. package/src/tools/builtins/computer-use.ts +460 -68
  530. package/src/tools/builtins/content-fingerprint.ts +8 -1
  531. package/src/tools/builtins/edit.ts +93 -7
  532. package/src/tools/builtins/file-write-result.ts +2 -1
  533. package/src/tools/builtins/grep.ts +1 -1
  534. package/src/tools/builtins/job.ts +4 -2
  535. package/src/tools/builtins/monitor.ts +6 -1
  536. package/src/tools/builtins/search-tools.ts +196 -21
  537. package/src/tools/builtins/shell-read-credit.ts +97 -33
  538. package/src/tools/builtins/wait-for-job.ts +13 -3
  539. package/src/tools/builtins/web-guidance.ts +6 -0
  540. package/src/tools/builtins/web.ts +2 -1
  541. package/src/tools/builtins/write-file.ts +31 -3
  542. package/src/tools/command-shell.ts +6 -8
  543. package/src/tools/defineTool.ts +20 -1
  544. package/src/tools/schedules/index.ts +11 -0
  545. package/src/tools/schedules/loop-tool.ts +10 -6
  546. package/src/tools/schedules/present.ts +1 -1
  547. package/src/tools/schedules/timer-tools.ts +258 -0
  548. package/src/tools/schedules/types.ts +72 -3
  549. package/src/tools/task/create.ts +2 -0
  550. package/src/toolsets/manager.ts +262 -46
  551. package/src/turn/evidence-query.ts +183 -42
  552. package/src/turn/evidence-recall.ts +96 -19
  553. package/src/turn/history-shed.ts +30 -0
  554. package/src/types/acp/index.ts +24 -0
  555. package/src/types/authorization/index.ts +20 -3
  556. package/src/types/hitl/index.ts +10 -0
  557. package/src/types/message/index.ts +65 -0
  558. package/src/types/permission/index.ts +18 -0
  559. package/src/types/plugin/index.ts +205 -26
  560. package/src/types/provider/index.ts +1 -0
  561. package/src/types/provider/interface.ts +13 -0
  562. package/src/types/provider/limits.ts +35 -0
  563. package/src/types/tool/index.ts +30 -2
  564. package/src/types/tool/presentation.ts +4 -0
  565. package/src/utils/file-lock.ts +328 -0
  566. package/src/utils/state-backup.ts +318 -0
  567. package/src/utils/temp-sweep.ts +327 -0
  568. package/src/utils/temp.ts +73 -2
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Which local network is this machine on? A fingerprint of the subnet an
3
+ * address belongs to plus the hardware address of that subnet's default
4
+ * gateway, hashed. It answers "is this the same Wi-Fi or wire as last time"
5
+ * well enough to remember that the person trusts it, and nothing more: it is
6
+ * not a secret and not proof of anything.
7
+ *
8
+ * The gateway's hardware address is read without privileges and without
9
+ * sending a packet of our own where the system keeps it already:
10
+ * - Linux: `/proc/net/route` for the default route, `/proc/net/arp` for the
11
+ * neighbour table.
12
+ * - macOS: `route -n get default`, then `arp -n <gateway>`.
13
+ * - Windows: `Get-NetRoute` and `Get-NetNeighbor` through PowerShell.
14
+ * None of them needs administrator rights. When the gateway or its hardware
15
+ * address cannot be read, the network is UNKNOWN: it has no fingerprint, so it
16
+ * is never trusted automatically. WSL2 in NAT mode sees only the Windows
17
+ * host's virtual adapter as its gateway, so every WSL2 machine fingerprints
18
+ * its own private network; mirrored networking removes that.
19
+ *
20
+ * Every reader is injected, so tests feed fixtures and never run a command.
21
+ *
22
+ * @experimental
23
+ */
24
+
25
+ import { createHash } from 'node:crypto'
26
+ import type { NetworkInterfaceInfo } from 'node:os'
27
+ import type { NetworkClock } from './clock.js'
28
+
29
+ export interface Gateway {
30
+ readonly ip: string
31
+ /** Lowercase `aa:bb:cc:dd:ee:ff`. */
32
+ readonly mac: string
33
+ }
34
+
35
+ export type GatewayReader = () => Promise<Gateway | undefined>
36
+
37
+ export type CommandRunner = (
38
+ command: string,
39
+ args: readonly string[],
40
+ ) => Promise<string | undefined>
41
+
42
+ const MAC = /^[0-9a-f]{2}(:[0-9a-f]{2}){5}$/
43
+
44
+ /** A hardware address worth hashing: six octets, not all zero, not broadcast. */
45
+ function usableMac(text: string): string | undefined {
46
+ const mac = text.trim().toLowerCase().replace(/-/g, ':')
47
+ if (!MAC.test(mac)) return undefined
48
+ if (mac === '00:00:00:00:00:00' || mac === 'ff:ff:ff:ff:ff:ff') return undefined
49
+ return mac
50
+ }
51
+
52
+ /** `0101A8C0` (little-endian hex as `/proc/net/route` writes it) to `192.168.1.1`. */
53
+ function hexToIPv4(hex: string): string | undefined {
54
+ if (!/^[0-9A-Fa-f]{8}$/.test(hex)) return undefined
55
+ const n = Number.parseInt(hex, 16)
56
+ return [n & 0xff, (n >>> 8) & 0xff, (n >>> 16) & 0xff, (n >>> 24) & 0xff].join('.')
57
+ }
58
+
59
+ /** The default route of `/proc/net/route`: the gateway of the up route to 0.0.0.0/0 with the lowest metric. */
60
+ export function parseLinuxDefaultRoute(
61
+ text: string,
62
+ ): { readonly ip: string; readonly iface: string } | undefined {
63
+ let best: { ip: string; iface: string; metric: number } | undefined
64
+ for (const line of text.split('\n').slice(1)) {
65
+ const cols = line.trim().split(/\s+/)
66
+ if (cols.length < 8) continue
67
+ const [iface, destination, gateway, flags, , , metric, mask] = cols as string[]
68
+ if (destination !== '00000000' || mask !== '00000000') continue
69
+ const f = Number.parseInt(flags ?? '0', 16)
70
+ // RTF_UP (1) and RTF_GATEWAY (2)
71
+ if ((f & 3) !== 3) continue
72
+ const ip = hexToIPv4(gateway ?? '')
73
+ if (!ip || ip === '0.0.0.0') continue
74
+ const m = Number(metric)
75
+ if (!best || m < best.metric) best = { ip, iface: iface ?? '', metric: m }
76
+ }
77
+ return best ? { ip: best.ip, iface: best.iface } : undefined
78
+ }
79
+
80
+ /** The hardware address of `ip` in `/proc/net/arp`; an entry that is not complete (flags 0x0) does not count. */
81
+ export function parseLinuxArp(text: string, ip: string): string | undefined {
82
+ for (const line of text.split('\n').slice(1)) {
83
+ const cols = line.trim().split(/\s+/)
84
+ if (cols.length < 6 || cols[0] !== ip) continue
85
+ if (Number.parseInt(cols[2] ?? '0', 16) === 0) continue
86
+ return usableMac(cols[3] ?? '')
87
+ }
88
+ return undefined
89
+ }
90
+
91
+ /** `route -n get default` on macOS: the `gateway:` line. */
92
+ export function parseMacDefaultRoute(text: string): string | undefined {
93
+ const match = /^\s*gateway:\s*(\d{1,3}(?:\.\d{1,3}){3})\s*$/m.exec(text)
94
+ return match?.[1]
95
+ }
96
+
97
+ /** `arp -n 192.168.1.1` on macOS: `? (192.168.1.1) at aa:bb:... on en0 ifscope [ethernet]`. Macs drop leading zeros. */
98
+ export function parseMacArp(text: string, ip: string): string | undefined {
99
+ const match = /\(([\d.]+)\) at ([0-9a-f]{1,2}(?::[0-9a-f]{1,2}){5})/i.exec(text)
100
+ if (!match || match[1] !== ip) return undefined
101
+ return usableMac(
102
+ (match[2] as string)
103
+ .split(':')
104
+ .map((o) => o.padStart(2, '0'))
105
+ .join(':'),
106
+ )
107
+ }
108
+
109
+ /** PowerShell output of the one-line script below: `192.168.1.1 AA-BB-CC-DD-EE-FF`. */
110
+ export const WINDOWS_GATEWAY_SCRIPT =
111
+ '$r = Get-NetRoute -DestinationPrefix \'0.0.0.0/0\' | Sort-Object RouteMetric | Select-Object -First 1; if ($r) { $n = Get-NetNeighbor -IPAddress $r.NextHop -ErrorAction SilentlyContinue | Where-Object { $_.LinkLayerAddress } | Select-Object -First 1; if ($n) { "$($r.NextHop) $($n.LinkLayerAddress)" } }'
112
+
113
+ export function parseWindowsGateway(text: string): Gateway | undefined {
114
+ const match =
115
+ /^\s*(\d{1,3}(?:\.\d{1,3}){3})\s+([0-9A-Fa-f]{2}(?:[-:][0-9A-Fa-f]{2}){5})\s*$/m.exec(text)
116
+ if (!match) return undefined
117
+ const mac = usableMac(match[2] as string)
118
+ return mac ? { ip: match[1] as string, mac } : undefined
119
+ }
120
+
121
+ export interface SystemGatewayOptions {
122
+ readonly platform?: NodeJS.Platform
123
+ /** Read a small text file; undefined when it cannot be read. */
124
+ readonly readText: (path: string) => Promise<string | undefined>
125
+ /** Run a command with no shell and a short timeout; undefined when it fails. */
126
+ readonly run: CommandRunner
127
+ }
128
+
129
+ /** The reader for this machine's system. Nothing here needs administrator rights. */
130
+ export function createSystemGatewayReader(options: SystemGatewayOptions): GatewayReader {
131
+ const platform = options.platform ?? process.platform
132
+ return async () => {
133
+ if (platform === 'linux') {
134
+ const route = await options.readText('/proc/net/route')
135
+ const found = route ? parseLinuxDefaultRoute(route) : undefined
136
+ if (!found) return undefined
137
+ const arp = await options.readText('/proc/net/arp')
138
+ const mac = arp ? parseLinuxArp(arp, found.ip) : undefined
139
+ return mac ? { ip: found.ip, mac } : undefined
140
+ }
141
+ if (platform === 'darwin') {
142
+ const route = await options.run('route', ['-n', 'get', 'default'])
143
+ const ip = route ? parseMacDefaultRoute(route) : undefined
144
+ if (!ip) return undefined
145
+ const arp = await options.run('arp', ['-n', ip])
146
+ const mac = arp ? parseMacArp(arp, ip) : undefined
147
+ return mac ? { ip, mac } : undefined
148
+ }
149
+ if (platform === 'win32') {
150
+ const out = await options.run('powershell.exe', [
151
+ '-NoProfile',
152
+ '-NonInteractive',
153
+ '-Command',
154
+ WINDOWS_GATEWAY_SCRIPT,
155
+ ])
156
+ return out ? parseWindowsGateway(out) : undefined
157
+ }
158
+ return undefined
159
+ }
160
+ }
161
+
162
+ function ipv4ToInt(address: string): number | undefined {
163
+ const parts = address.split('.')
164
+ if (parts.length !== 4) return undefined
165
+ let n = 0
166
+ for (const p of parts) {
167
+ if (!/^\d{1,3}$/.test(p) || Number(p) > 255) return undefined
168
+ n = n * 256 + Number(p)
169
+ }
170
+ return n
171
+ }
172
+
173
+ function prefixLength(netmask: string): number | undefined {
174
+ const n = ipv4ToInt(netmask)
175
+ if (n === undefined) return undefined
176
+ let bits = 0
177
+ for (let i = 31; i >= 0 && (n >>> i) & 1; i--) bits++
178
+ return bits
179
+ }
180
+
181
+ /** The IPv4 subnet (`192.168.1.0/24`) of the interface address that contains `address`, if any. */
182
+ export function subnetOf(
183
+ address: string,
184
+ interfaces: NodeJS.Dict<NetworkInterfaceInfo[]>,
185
+ ): string | undefined {
186
+ const target = ipv4ToInt(address)
187
+ if (target === undefined) return undefined
188
+ for (const list of Object.values(interfaces)) {
189
+ for (const info of list ?? []) {
190
+ if (info.family !== 'IPv4') continue
191
+ const bits = prefixLength(info.netmask)
192
+ const base = ipv4ToInt(info.address)
193
+ if (bits === undefined || base === undefined || bits === 0) continue
194
+ const mask = bits === 32 ? 0xffffffff : (~0 << (32 - bits)) >>> 0
195
+ if ((target & mask) >>> 0 === (base & mask) >>> 0)
196
+ return `${[24, 16, 8, 0].map((s) => ((base & mask) >>> s) & 0xff).join('.')}/${bits}`
197
+ }
198
+ }
199
+ return undefined
200
+ }
201
+
202
+ /** The network id: 16 hex of sha256 over the subnet and the gateway's hardware address. */
203
+ export function networkFingerprint(subnet: string, gatewayMac: string): string {
204
+ return createHash('sha256')
205
+ .update(`namzu-net/lan/1\n${subnet}\n${gatewayMac}`)
206
+ .digest('hex')
207
+ .slice(0, 16)
208
+ }
209
+
210
+ export interface NetworkIdentityOptions {
211
+ readonly interfaces: () => NodeJS.Dict<NetworkInterfaceInfo[]>
212
+ readonly gateway: GatewayReader
213
+ readonly clock: NetworkClock
214
+ /** How long a read of the gateway is reused. */
215
+ readonly cacheMs?: number
216
+ }
217
+
218
+ /**
219
+ * `identify(address)`: the fingerprint of the network `address` is on, or undefined when this machine is not
220
+ * on that subnet, the gateway cannot be read, or the gateway is not on that subnet (so it is not that network's
221
+ * gateway). Unknown means never trusted.
222
+ */
223
+ export function createNetworkIdentity(
224
+ options: NetworkIdentityOptions,
225
+ ): (address: string) => Promise<string | undefined> {
226
+ const cacheMs = options.cacheMs ?? 30_000
227
+ let cached: { at: number; gateway: Gateway | undefined } | undefined
228
+ return async (address) => {
229
+ const interfaces = options.interfaces()
230
+ const subnet = subnetOf(address, interfaces)
231
+ if (!subnet) return undefined
232
+ const now = options.clock.now()
233
+ if (!cached || now - cached.at >= cacheMs) {
234
+ cached = { at: now, gateway: await options.gateway().catch(() => undefined) }
235
+ }
236
+ const gateway = cached.gateway
237
+ if (!gateway) return undefined
238
+ if (subnetOf(gateway.ip, interfaces) !== subnet) return undefined
239
+ return networkFingerprint(subnet, gateway.mac)
240
+ }
241
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Machine identity: one Ed25519 key pair per machine, and the small helpers
3
+ * every other module of the Namzu network uses to name and sign with it.
4
+ *
5
+ * Nothing here implements a cryptographic primitive; it is `node:crypto`
6
+ * (`generateKeyPairSync`, `sign`, `verify`, `createHash`) with fixed
7
+ * encodings so that two machines always compute the same id from the same key.
8
+ *
9
+ * - `machineId`: lowercase hex sha256 of the public key's SPKI DER (64 hex).
10
+ * - `netId`: the first 16 hex of the same digest over the FOUNDER's key. It is
11
+ * not secret and not a name.
12
+ *
13
+ * @experimental
14
+ */
15
+
16
+ import {
17
+ type KeyObject,
18
+ createHash,
19
+ createPrivateKey,
20
+ createPublicKey,
21
+ generateKeyPairSync,
22
+ sign,
23
+ verify,
24
+ } from 'node:crypto'
25
+
26
+ export interface MachineKey {
27
+ readonly privateKey: KeyObject
28
+ readonly publicKey: KeyObject
29
+ /** SPKI DER of the public key. */
30
+ readonly publicKeyDer: Buffer
31
+ readonly machineId: string
32
+ }
33
+
34
+ const NET_ID_LENGTH = 16
35
+
36
+ export function sha256Hex(data: Buffer | string): string {
37
+ return createHash('sha256').update(data).digest('hex')
38
+ }
39
+
40
+ /** The id of a machine, from the SPKI DER of its public key. */
41
+ export function machineIdOf(publicKeyDer: Buffer): string {
42
+ return sha256Hex(publicKeyDer)
43
+ }
44
+
45
+ /** The id of a network, from the SPKI DER of its founder's public key. */
46
+ export function netIdOf(founderPublicKeyDer: Buffer): string {
47
+ return sha256Hex(founderPublicKeyDer).slice(0, NET_ID_LENGTH)
48
+ }
49
+
50
+ /** Short form of a machine id for a screen. */
51
+ export function shortMachineId(machineId: string): string {
52
+ return machineId.slice(0, 12)
53
+ }
54
+
55
+ function fromPrivateKey(privateKey: KeyObject): MachineKey {
56
+ const publicKey = createPublicKey(privateKey)
57
+ const publicKeyDer = publicKey.export({ type: 'spki', format: 'der' })
58
+ return {
59
+ privateKey,
60
+ publicKey,
61
+ publicKeyDer,
62
+ machineId: machineIdOf(publicKeyDer),
63
+ }
64
+ }
65
+
66
+ export function generateMachineKey(): MachineKey {
67
+ return fromPrivateKey(generateKeyPairSync('ed25519').privateKey)
68
+ }
69
+
70
+ /** PKCS#8 PEM of the private key. The only place a private key is serialised; callers write it 0600 and never log it. */
71
+ export function exportMachineKeyPem(key: MachineKey): string {
72
+ return key.privateKey.export({ type: 'pkcs8', format: 'pem' }).toString()
73
+ }
74
+
75
+ export function importMachineKeyPem(pem: string): MachineKey {
76
+ const privateKey = createPrivateKey(pem)
77
+ if (privateKey.asymmetricKeyType !== 'ed25519') {
78
+ throw new Error('The machine key is not an Ed25519 key.')
79
+ }
80
+ return fromPrivateKey(privateKey)
81
+ }
82
+
83
+ export function publicKeyFromDer(der: Buffer): KeyObject {
84
+ return createPublicKey({ key: der, type: 'spki', format: 'der' })
85
+ }
86
+
87
+ export function signBytes(key: MachineKey, data: Buffer): Buffer {
88
+ return sign(null, data, key.privateKey)
89
+ }
90
+
91
+ /** False for any malformed key or signature rather than throwing. */
92
+ export function verifyBytes(publicKeyDer: Buffer, data: Buffer, signature: Buffer): boolean {
93
+ try {
94
+ return verify(null, data, publicKeyFromDer(publicKeyDer), signature)
95
+ } catch {
96
+ return false
97
+ }
98
+ }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Your Namzu network: machines of one person find each other on the local
3
+ * network, show one roster of sessions, pass roles and messages, and keep the
4
+ * safety rules of local messaging across machines.
5
+ *
6
+ * Host-neutral. A host supplies a {@link NetworkHost} and a discovery; the
7
+ * terminal does so today and the desktop can later.
8
+ *
9
+ * @experimental
10
+ */
11
+
12
+ export { createManualClock, systemClock } from './clock.js'
13
+ export type { ManualClock, NetworkClock } from './clock.js'
14
+
15
+ export {
16
+ createDiscoveryHub,
17
+ createFakeDiscovery,
18
+ isPrivateNetworkAddress,
19
+ privateInterfaces,
20
+ } from './discovery.js'
21
+ export type {
22
+ Advertisement,
23
+ DiscoveredEndpoint,
24
+ DiscoveryHub,
25
+ FakeDiscovery,
26
+ ListenAddress,
27
+ NetworkDiscovery,
28
+ PrivateInterfaceOptions,
29
+ } from './discovery.js'
30
+
31
+ export { MDNS_GROUP, MDNS_PORT, SERVICE_NAME, createMdnsDiscovery } from './discovery-mdns.js'
32
+ export type { DgramLike, DgramSocketLike, MdnsOptions } from './discovery-mdns.js'
33
+
34
+ export {
35
+ AUDIT_EVENTS,
36
+ createFileAuditSink,
37
+ createMemoryAuditSink,
38
+ textHash,
39
+ } from './audit.js'
40
+ export type { AuditEntry, AuditEventName, AuditSink, FileAuditSinkOptions } from './audit.js'
41
+
42
+ export {
43
+ createNetworkIdentity,
44
+ createSystemGatewayReader,
45
+ networkFingerprint,
46
+ parseLinuxArp,
47
+ parseLinuxDefaultRoute,
48
+ parseMacArp,
49
+ parseMacDefaultRoute,
50
+ parseWindowsGateway,
51
+ subnetOf,
52
+ } from './fingerprint.js'
53
+ export type {
54
+ CommandRunner,
55
+ Gateway,
56
+ GatewayReader,
57
+ NetworkIdentityOptions,
58
+ SystemGatewayOptions,
59
+ } from './fingerprint.js'
60
+
61
+ export { createNetworkStore } from './store.js'
62
+ export type { NetworkStore, NetworkStoreOptions } from './store.js'
63
+
64
+ export { formatJoinCode, joinCode } from './join.js'
65
+ export type { PendingJoin } from './join.js'
66
+
67
+ export {
68
+ HOLD_EXPIRY_MS,
69
+ HoldQueue,
70
+ MAX_HELD_PER_TERMINAL,
71
+ SlidingCounter,
72
+ decideMail,
73
+ } from './mail-policy.js'
74
+ export type {
75
+ HeldEntry,
76
+ HoldQueueOptions,
77
+ MailDecision,
78
+ MailDecisionInput,
79
+ MailSetting,
80
+ } from './mail-policy.js'
81
+
82
+ export { generateMachineKey } from './identity.js'
83
+ export type { MachineKey } from './identity.js'
84
+
85
+ export { createFounding, evaluateMembership, mergeMembership } from './membership.js'
86
+ export type { Admission, MembershipState, MembershipView, Revocation } from './membership.js'
87
+
88
+ export {
89
+ generateSessionName,
90
+ machineLabel,
91
+ resolveSessionTarget,
92
+ sessionDisplayName,
93
+ sessionLabel,
94
+ } from './roster.js'
95
+ export type {
96
+ LocalSession,
97
+ RosterMachineView,
98
+ RosterView,
99
+ TargetResolution,
100
+ } from './roster.js'
101
+
102
+ export {
103
+ BROWSE_WINDOW_MS,
104
+ FRESH_NETWORK_MS,
105
+ DEFAULT_LISTEN_PORT,
106
+ createNamzuNetwork,
107
+ parseHostPort,
108
+ } from './service.js'
109
+ export type {
110
+ HeldMail,
111
+ AutoAdmitSetting,
112
+ NetworkEvent,
113
+ NetworkRef,
114
+ TrustedNetwork,
115
+ NetworkHost,
116
+ NetworkService,
117
+ NetworkServiceOptions,
118
+ NetworkState,
119
+ NetworkStatus,
120
+ RemoteMail,
121
+ } from './service.js'
122
+
123
+ export { NetworkError } from './transport.js'
124
+ export type { NetworkErrorCode } from './transport.js'
125
+
126
+ export {
127
+ MAX_NET_LINE_BYTES,
128
+ MAX_PREAUTH_LINE_BYTES,
129
+ MAX_ROLE_BYTES,
130
+ NET_PROTOCOL,
131
+ sanitizeName,
132
+ sanitizeRole,
133
+ } from './wire.js'
134
+ export type { HostPort, RosterSession } from './wire.js'
@@ -0,0 +1,177 @@
1
+ /**
2
+ * The join handshake's two small pieces: the short code both screens show,
3
+ * and the table of pending requests.
4
+ *
5
+ * The code is bound to the channel: it is computed from the two certificates'
6
+ * machine ids as each side saw them plus both nonces. A machine relaying
7
+ * between the joiner and a member presents different certificates on each leg,
8
+ * so the two screens differ. Skipping the glance is allowed; it is the
9
+ * documented residual risk.
10
+ *
11
+ * @experimental
12
+ */
13
+
14
+ import { createHash } from 'node:crypto'
15
+ import type { NetworkClock } from './clock.js'
16
+
17
+ const CODE_DOMAIN = 'namzu-net/join/1'
18
+
19
+ /** Six digits from the channel facts. Same inputs, same code; any swapped fingerprint, a different one. */
20
+ export function joinCode(
21
+ joinerMachineId: string,
22
+ memberMachineId: string,
23
+ joinerNonce: string,
24
+ memberNonce: string,
25
+ ): string {
26
+ const digest = createHash('sha256')
27
+ .update(
28
+ JSON.stringify([CODE_DOMAIN, joinerMachineId, memberMachineId, joinerNonce, memberNonce]),
29
+ 'utf8',
30
+ )
31
+ .digest()
32
+ return String(digest.readUInt32BE(0) % 1_000_000).padStart(6, '0')
33
+ }
34
+
35
+ /** `482913` as `482 913`. */
36
+ export function formatJoinCode(code: string): string {
37
+ return `${code.slice(0, 3)} ${code.slice(3)}`
38
+ }
39
+
40
+ export const JOIN_EXPIRY_MS = 10 * 60 * 1000
41
+ export const MAX_PENDING_JOINS = 8
42
+ export const JOIN_ADDRESS_WINDOW_MS = 60 * 1000
43
+
44
+ export interface PendingJoin {
45
+ readonly requestId: string
46
+ readonly name: string
47
+ readonly code: string
48
+ readonly sourceAddr: string
49
+ readonly createdAt: number
50
+ readonly expiresAt: number
51
+ /** The member the joiner is connected to. */
52
+ readonly viaMachineId: string
53
+ /** True on the member the joiner reached; only there is the joiner's connection held. */
54
+ readonly local: boolean
55
+ readonly joinerMachineId?: string
56
+ readonly joinerPublicKey?: string
57
+ }
58
+
59
+ export type JoinDecisionOutcome = 'ok' | 'already' | 'unknown'
60
+
61
+ const MAX_DECIDED = 512
62
+
63
+ export interface JoinTableOptions {
64
+ readonly clock: NetworkClock
65
+ readonly onExpire: (entry: PendingJoin) => void
66
+ }
67
+
68
+ export class JoinTable {
69
+ private readonly entries = new Map<string, PendingJoin & { cancel: () => void }>()
70
+ private readonly decided = new Map<string, 'allow' | 'deny' | 'expired'>()
71
+ private readonly lastByAddress = new Map<string, number>()
72
+ constructor(private readonly options: JoinTableOptions) {}
73
+
74
+ /** A request that arrived on this machine. Refused when the address asked too recently or the table is full. */
75
+ addLocal(
76
+ input: Omit<PendingJoin, 'local' | 'expiresAt' | 'createdAt'>,
77
+ ): { ok: true; entry: PendingJoin } | { ok: false; reason: 'rate' | 'full' } {
78
+ const now = this.options.clock.now()
79
+ const last = this.lastByAddress.get(input.sourceAddr)
80
+ if (last !== undefined && now - last < JOIN_ADDRESS_WINDOW_MS)
81
+ return { ok: false, reason: 'rate' }
82
+ if (this.localCount() >= MAX_PENDING_JOINS) return { ok: false, reason: 'full' }
83
+ this.lastByAddress.set(input.sourceAddr, now)
84
+ return {
85
+ ok: true,
86
+ entry: this.insert({
87
+ ...input,
88
+ local: true,
89
+ createdAt: now,
90
+ expiresAt: now + JOIN_EXPIRY_MS,
91
+ }),
92
+ }
93
+ }
94
+
95
+ /** A request another member told us about. */
96
+ addRemote(input: Omit<PendingJoin, 'local' | 'expiresAt'>): PendingJoin | undefined {
97
+ if (this.entries.has(input.requestId) || this.decided.has(input.requestId)) return undefined
98
+ if (this.entries.size >= MAX_PENDING_JOINS * 2) return undefined
99
+ const now = this.options.clock.now()
100
+ // A request is as old as it says only up to now: a member cannot make one outlive its ten minutes.
101
+ const createdAt = Math.min(input.createdAt, now)
102
+ const expiresAt = createdAt + JOIN_EXPIRY_MS
103
+ if (expiresAt <= now) return undefined
104
+ return this.insert({ ...input, createdAt, local: false, expiresAt }, expiresAt - now)
105
+ }
106
+
107
+ private insert(entry: PendingJoin, ttl = JOIN_EXPIRY_MS): PendingJoin {
108
+ const cancel = this.options.clock.setTimer(() => {
109
+ if (this.entries.delete(entry.requestId)) {
110
+ this.remember(entry.requestId, 'expired')
111
+ this.options.onExpire(entry)
112
+ }
113
+ }, ttl)
114
+ this.entries.set(entry.requestId, { ...entry, cancel })
115
+ return entry
116
+ }
117
+
118
+ private localCount(): number {
119
+ let n = 0
120
+ for (const e of this.entries.values()) if (e.local) n++
121
+ return n
122
+ }
123
+
124
+ get(requestId: string): PendingJoin | undefined {
125
+ return this.entries.get(requestId)
126
+ }
127
+
128
+ /** Find by request id, code (with or without the space) or the joiner's name. */
129
+ find(query: string): PendingJoin | undefined {
130
+ const q = query.trim()
131
+ const digits = q.replace(/\s+/g, '')
132
+ const all = this.list()
133
+ // A name is only an address while it is unique: two requests with one name (a stranger copying
134
+ // the real one) are told apart by their codes, never by whichever came first.
135
+ const byName = all.filter((e) => e.name.toLowerCase() === q.toLowerCase())
136
+ return (
137
+ all.find((e) => e.requestId === q) ??
138
+ all.find((e) => /^\d{6}$/.test(digits) && e.code === digits) ??
139
+ (byName.length === 1 ? byName[0] : undefined)
140
+ )
141
+ }
142
+
143
+ list(): readonly PendingJoin[] {
144
+ return [...this.entries.values()].map(({ cancel: _cancel, ...rest }) => rest)
145
+ }
146
+
147
+ /** The first decision wins; a later one is `already`. */
148
+ decide(requestId: string, decision: 'allow' | 'deny'): JoinDecisionOutcome {
149
+ const entry = this.entries.get(requestId)
150
+ if (!entry) return this.decided.has(requestId) ? 'already' : 'unknown'
151
+ entry.cancel()
152
+ this.entries.delete(requestId)
153
+ this.remember(requestId, decision)
154
+ return 'ok'
155
+ }
156
+
157
+ /** Record a decision made elsewhere (a gossiped `join_decision`). */
158
+ settle(requestId: string, decision: 'allow' | 'deny'): void {
159
+ const entry = this.entries.get(requestId)
160
+ if (entry) {
161
+ entry.cancel()
162
+ this.entries.delete(requestId)
163
+ }
164
+ this.remember(requestId, decision)
165
+ }
166
+
167
+ private remember(requestId: string, decision: 'allow' | 'deny' | 'expired'): void {
168
+ this.decided.set(requestId, decision)
169
+ if (this.decided.size > MAX_DECIDED)
170
+ this.decided.delete(this.decided.keys().next().value as string)
171
+ }
172
+
173
+ clear(): void {
174
+ for (const e of this.entries.values()) e.cancel()
175
+ this.entries.clear()
176
+ }
177
+ }