@namzu/sdk 68.0.1 → 69.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (492) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/dist/agents/QueryAgent.d.ts.map +1 -1
  3. package/dist/agents/QueryAgent.js +2 -0
  4. package/dist/agents/QueryAgent.js.map +1 -1
  5. package/dist/authorization/skill-grant.d.ts.map +1 -1
  6. package/dist/authorization/skill-grant.js +1 -0
  7. package/dist/authorization/skill-grant.js.map +1 -1
  8. package/dist/bridge/acp/permission.d.ts +10 -0
  9. package/dist/bridge/acp/permission.d.ts.map +1 -1
  10. package/dist/bridge/acp/permission.js.map +1 -1
  11. package/dist/bridge/acp/server.d.ts +12 -0
  12. package/dist/bridge/acp/server.d.ts.map +1 -1
  13. package/dist/bridge/acp/server.js +21 -0
  14. package/dist/bridge/acp/server.js.map +1 -1
  15. package/dist/compaction/context-window.d.ts +8 -0
  16. package/dist/compaction/context-window.d.ts.map +1 -1
  17. package/dist/compaction/context-window.js +14 -0
  18. package/dist/compaction/context-window.js.map +1 -1
  19. package/dist/compaction/loaded-skills.d.ts +10 -0
  20. package/dist/compaction/loaded-skills.d.ts.map +1 -1
  21. package/dist/compaction/loaded-skills.js +45 -1
  22. package/dist/compaction/loaded-skills.js.map +1 -1
  23. package/dist/compaction/manager.d.ts +8 -0
  24. package/dist/compaction/manager.d.ts.map +1 -1
  25. package/dist/compaction/manager.js +31 -0
  26. package/dist/compaction/manager.js.map +1 -1
  27. package/dist/compaction/manual.d.ts.map +1 -1
  28. package/dist/compaction/manual.js +7 -1
  29. package/dist/compaction/manual.js.map +1 -1
  30. package/dist/compaction/model-summary.js +2 -2
  31. package/dist/compaction/model-summary.js.map +1 -1
  32. package/dist/compaction/restore.d.ts +8 -0
  33. package/dist/compaction/restore.d.ts.map +1 -1
  34. package/dist/compaction/restore.js +65 -0
  35. package/dist/compaction/restore.js.map +1 -1
  36. package/dist/compaction/salience/working-set.d.ts.map +1 -1
  37. package/dist/compaction/salience/working-set.js +2 -2
  38. package/dist/compaction/salience/working-set.js.map +1 -1
  39. package/dist/compaction/tool-result-editing.d.ts +6 -0
  40. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  41. package/dist/compaction/tool-result-editing.js +7 -1
  42. package/dist/compaction/tool-result-editing.js.map +1 -1
  43. package/dist/compaction/types.d.ts +2 -0
  44. package/dist/compaction/types.d.ts.map +1 -1
  45. package/dist/compaction/wire.d.ts.map +1 -1
  46. package/dist/compaction/wire.js +4 -0
  47. package/dist/compaction/wire.js.map +1 -1
  48. package/dist/connector/index.d.ts +2 -2
  49. package/dist/connector/index.d.ts.map +1 -1
  50. package/dist/connector/index.js +1 -1
  51. package/dist/connector/index.js.map +1 -1
  52. package/dist/connector/mcp/client.d.ts +29 -0
  53. package/dist/connector/mcp/client.d.ts.map +1 -1
  54. package/dist/connector/mcp/client.js +59 -2
  55. package/dist/connector/mcp/client.js.map +1 -1
  56. package/dist/connector/mcp/errors.d.ts +7 -0
  57. package/dist/connector/mcp/errors.d.ts.map +1 -1
  58. package/dist/connector/mcp/errors.js +14 -0
  59. package/dist/connector/mcp/errors.js.map +1 -1
  60. package/dist/connector/mcp/index.d.ts +5 -1
  61. package/dist/connector/mcp/index.d.ts.map +1 -1
  62. package/dist/connector/mcp/index.js +3 -1
  63. package/dist/connector/mcp/index.js.map +1 -1
  64. package/dist/connector/mcp/skill-source.d.ts +144 -0
  65. package/dist/connector/mcp/skill-source.d.ts.map +1 -0
  66. package/dist/connector/mcp/skill-source.js +375 -0
  67. package/dist/connector/mcp/skill-source.js.map +1 -0
  68. package/dist/connector/mcp/skills.d.ts +137 -0
  69. package/dist/connector/mcp/skills.d.ts.map +1 -0
  70. package/dist/connector/mcp/skills.js +303 -0
  71. package/dist/connector/mcp/skills.js.map +1 -0
  72. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  73. package/dist/manager/session/turn-recorder.js +23 -1
  74. package/dist/manager/session/turn-recorder.js.map +1 -1
  75. package/dist/network/audit.d.ts +1 -1
  76. package/dist/network/audit.d.ts.map +1 -1
  77. package/dist/network/audit.js +2 -0
  78. package/dist/network/audit.js.map +1 -1
  79. package/dist/network/computer.d.ts +107 -0
  80. package/dist/network/computer.d.ts.map +1 -0
  81. package/dist/network/computer.js +250 -0
  82. package/dist/network/computer.js.map +1 -0
  83. package/dist/network/index.d.ts +2 -0
  84. package/dist/network/index.d.ts.map +1 -1
  85. package/dist/network/index.js +1 -0
  86. package/dist/network/index.js.map +1 -1
  87. package/dist/network/join.d.ts +13 -1
  88. package/dist/network/join.d.ts.map +1 -1
  89. package/dist/network/join.js +21 -3
  90. package/dist/network/join.js.map +1 -1
  91. package/dist/network/roster.d.ts +5 -0
  92. package/dist/network/roster.d.ts.map +1 -1
  93. package/dist/network/roster.js.map +1 -1
  94. package/dist/network/service.d.ts +12 -2
  95. package/dist/network/service.d.ts.map +1 -1
  96. package/dist/network/service.js +539 -60
  97. package/dist/network/service.js.map +1 -1
  98. package/dist/network/store.d.ts +33 -1
  99. package/dist/network/store.d.ts.map +1 -1
  100. package/dist/network/store.js +48 -4
  101. package/dist/network/store.js.map +1 -1
  102. package/dist/network/transport.d.ts +1 -1
  103. package/dist/network/transport.js +1 -1
  104. package/dist/network/wire.d.ts +14 -0
  105. package/dist/network/wire.d.ts.map +1 -1
  106. package/dist/network/wire.js +17 -1
  107. package/dist/network/wire.js.map +1 -1
  108. package/dist/plugin/shell-hook-tool-names.d.ts.map +1 -1
  109. package/dist/plugin/shell-hook-tool-names.js +1 -0
  110. package/dist/plugin/shell-hook-tool-names.js.map +1 -1
  111. package/dist/plugin/shell-hook.d.ts +8 -3
  112. package/dist/plugin/shell-hook.d.ts.map +1 -1
  113. package/dist/plugin/shell-hook.js +132 -7
  114. package/dist/plugin/shell-hook.js.map +1 -1
  115. package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
  116. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  117. package/dist/prompt/coding-agent-doctrine.js +7 -2
  118. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  119. package/dist/provider/fallback.d.ts.map +1 -1
  120. package/dist/provider/fallback.js +9 -0
  121. package/dist/provider/fallback.js.map +1 -1
  122. package/dist/provider/idle-timeout.d.ts.map +1 -1
  123. package/dist/provider/idle-timeout.js +8 -0
  124. package/dist/provider/idle-timeout.js.map +1 -1
  125. package/dist/provider/instrumentation.d.ts.map +1 -1
  126. package/dist/provider/instrumentation.js +10 -0
  127. package/dist/provider/instrumentation.js.map +1 -1
  128. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  129. package/dist/provider/model-window-suffix.js +2 -0
  130. package/dist/provider/model-window-suffix.js.map +1 -1
  131. package/dist/provider/retry.d.ts.map +1 -1
  132. package/dist/provider/retry.js +8 -0
  133. package/dist/provider/retry.js.map +1 -1
  134. package/dist/public-runtime.d.ts +10 -7
  135. package/dist/public-runtime.d.ts.map +1 -1
  136. package/dist/public-runtime.js +12 -5
  137. package/dist/public-runtime.js.map +1 -1
  138. package/dist/public-tools.d.ts +7 -4
  139. package/dist/public-tools.d.ts.map +1 -1
  140. package/dist/public-tools.js +9 -3
  141. package/dist/public-tools.js.map +1 -1
  142. package/dist/public-types.d.ts +4 -1
  143. package/dist/public-types.d.ts.map +1 -1
  144. package/dist/registry/tool/presentation.d.ts +8 -1
  145. package/dist/registry/tool/presentation.d.ts.map +1 -1
  146. package/dist/registry/tool/presentation.js +14 -5
  147. package/dist/registry/tool/presentation.js.map +1 -1
  148. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  149. package/dist/runtime/jobs/registry.js +2 -1
  150. package/dist/runtime/jobs/registry.js.map +1 -1
  151. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  152. package/dist/runtime/query/auto-review/classifier.js +19 -3
  153. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  154. package/dist/runtime/query/auto-review/failure.d.ts +12 -0
  155. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
  156. package/dist/runtime/query/auto-review/failure.js +46 -0
  157. package/dist/runtime/query/auto-review/failure.js.map +1 -0
  158. package/dist/runtime/query/auto-review/index.d.ts +1 -0
  159. package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
  160. package/dist/runtime/query/auto-review/index.js +1 -0
  161. package/dist/runtime/query/auto-review/index.js.map +1 -1
  162. package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
  163. package/dist/runtime/query/executor/tool-call-admission.js +10 -1
  164. package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
  165. package/dist/runtime/query/executor.d.ts +12 -0
  166. package/dist/runtime/query/executor.d.ts.map +1 -1
  167. package/dist/runtime/query/executor.js +43 -9
  168. package/dist/runtime/query/executor.js.map +1 -1
  169. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  170. package/dist/runtime/query/file-evidence-replay.js +6 -6
  171. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  172. package/dist/runtime/query/index.d.ts +4 -0
  173. package/dist/runtime/query/index.d.ts.map +1 -1
  174. package/dist/runtime/query/index.js +40 -1
  175. package/dist/runtime/query/index.js.map +1 -1
  176. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  177. package/dist/runtime/query/iteration/index.js +2 -0
  178. package/dist/runtime/query/iteration/index.js.map +1 -1
  179. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  180. package/dist/runtime/query/iteration/phases/compaction.js +21 -3
  181. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  182. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  183. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  184. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  185. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -2
  186. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  187. package/dist/runtime/query/iteration/phases/per-call-review.js +24 -9
  188. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  189. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  190. package/dist/runtime/query/iteration/step-shaping.js +4 -0
  191. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  192. package/dist/runtime/query/prepare-turn.d.ts +5 -1
  193. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  194. package/dist/runtime/query/prepare-turn.js +13 -3
  195. package/dist/runtime/query/prepare-turn.js.map +1 -1
  196. package/dist/runtime/query/review-policy.d.ts +15 -4
  197. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  198. package/dist/runtime/query/review-policy.js +15 -4
  199. package/dist/runtime/query/review-policy.js.map +1 -1
  200. package/dist/runtime/query/shell-line-escalation.d.ts +24 -0
  201. package/dist/runtime/query/shell-line-escalation.d.ts.map +1 -0
  202. package/dist/runtime/query/shell-line-escalation.js +38 -0
  203. package/dist/runtime/query/shell-line-escalation.js.map +1 -0
  204. package/dist/runtime/query/tooling.d.ts +7 -0
  205. package/dist/runtime/query/tooling.d.ts.map +1 -1
  206. package/dist/runtime/query/tooling.js +2 -0
  207. package/dist/runtime/query/tooling.js.map +1 -1
  208. package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
  209. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  210. package/dist/runtime/query/turn/outcome-ledger.js +47 -1
  211. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  212. package/dist/sandbox/provider/local.d.ts.map +1 -1
  213. package/dist/sandbox/provider/local.js +3 -1
  214. package/dist/sandbox/provider/local.js.map +1 -1
  215. package/dist/scheduler/local.d.ts.map +1 -1
  216. package/dist/scheduler/local.js +3 -1
  217. package/dist/scheduler/local.js.map +1 -1
  218. package/dist/skills/index.d.ts +4 -0
  219. package/dist/skills/index.d.ts.map +1 -1
  220. package/dist/skills/index.js +2 -0
  221. package/dist/skills/index.js.map +1 -1
  222. package/dist/skills/inline-shell-host.d.ts +103 -0
  223. package/dist/skills/inline-shell-host.d.ts.map +1 -0
  224. package/dist/skills/inline-shell-host.js +238 -0
  225. package/dist/skills/inline-shell-host.js.map +1 -0
  226. package/dist/skills/inline-shell.d.ts +176 -0
  227. package/dist/skills/inline-shell.d.ts.map +1 -0
  228. package/dist/skills/inline-shell.js +646 -0
  229. package/dist/skills/inline-shell.js.map +1 -0
  230. package/dist/store/index.d.ts +2 -0
  231. package/dist/store/index.d.ts.map +1 -1
  232. package/dist/store/index.js +1 -0
  233. package/dist/store/index.js.map +1 -1
  234. package/dist/store/task/file.d.ts +124 -0
  235. package/dist/store/task/file.d.ts.map +1 -0
  236. package/dist/store/task/file.js +498 -0
  237. package/dist/store/task/file.js.map +1 -0
  238. package/dist/teams/backend.d.ts +28 -0
  239. package/dist/teams/backend.d.ts.map +1 -0
  240. package/dist/teams/backend.js +2 -0
  241. package/dist/teams/backend.js.map +1 -0
  242. package/dist/teams/fs-sync.d.ts +19 -0
  243. package/dist/teams/fs-sync.d.ts.map +1 -0
  244. package/dist/teams/fs-sync.js +81 -0
  245. package/dist/teams/fs-sync.js.map +1 -0
  246. package/dist/teams/index.d.ts +14 -0
  247. package/dist/teams/index.d.ts.map +1 -0
  248. package/dist/teams/index.js +11 -0
  249. package/dist/teams/index.js.map +1 -0
  250. package/dist/teams/names.d.ts +15 -0
  251. package/dist/teams/names.d.ts.map +1 -0
  252. package/dist/teams/names.js +43 -0
  253. package/dist/teams/names.js.map +1 -0
  254. package/dist/teams/store.d.ts +133 -0
  255. package/dist/teams/store.d.ts.map +1 -0
  256. package/dist/teams/store.js +536 -0
  257. package/dist/teams/store.js.map +1 -0
  258. package/dist/teams/types.d.ts +97 -0
  259. package/dist/teams/types.d.ts.map +1 -0
  260. package/dist/teams/types.js +70 -0
  261. package/dist/teams/types.js.map +1 -0
  262. package/dist/tools/admit-facts.d.ts.map +1 -1
  263. package/dist/tools/admit-facts.js +28 -0
  264. package/dist/tools/admit-facts.js.map +1 -1
  265. package/dist/tools/builtins/bash.d.ts.map +1 -1
  266. package/dist/tools/builtins/bash.js +5 -2
  267. package/dist/tools/builtins/bash.js.map +1 -1
  268. package/dist/tools/builtins/browser.js +1 -1
  269. package/dist/tools/builtins/browser.js.map +1 -1
  270. package/dist/tools/builtins/computer-use.d.ts +60 -2
  271. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  272. package/dist/tools/builtins/computer-use.js +695 -80
  273. package/dist/tools/builtins/computer-use.js.map +1 -1
  274. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  275. package/dist/tools/builtins/content-fingerprint.js +2 -1
  276. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  277. package/dist/tools/builtins/edit-apply.d.ts +1 -0
  278. package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
  279. package/dist/tools/builtins/edit-apply.js +108 -21
  280. package/dist/tools/builtins/edit-apply.js.map +1 -1
  281. package/dist/tools/builtins/edit-match.d.ts +37 -0
  282. package/dist/tools/builtins/edit-match.d.ts.map +1 -1
  283. package/dist/tools/builtins/edit-match.js +193 -0
  284. package/dist/tools/builtins/edit-match.js.map +1 -1
  285. package/dist/tools/builtins/edit.d.ts.map +1 -1
  286. package/dist/tools/builtins/edit.js +14 -7
  287. package/dist/tools/builtins/edit.js.map +1 -1
  288. package/dist/tools/builtins/exit-semantics.d.ts +8 -0
  289. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  290. package/dist/tools/builtins/exit-semantics.js +19 -0
  291. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  292. package/dist/tools/builtins/index.d.ts +3 -1
  293. package/dist/tools/builtins/index.d.ts.map +1 -1
  294. package/dist/tools/builtins/index.js +1 -0
  295. package/dist/tools/builtins/index.js.map +1 -1
  296. package/dist/tools/builtins/present-file.d.ts +24 -0
  297. package/dist/tools/builtins/present-file.d.ts.map +1 -0
  298. package/dist/tools/builtins/present-file.js +116 -0
  299. package/dist/tools/builtins/present-file.js.map +1 -0
  300. package/dist/tools/builtins/read-file.js +1 -1
  301. package/dist/tools/builtins/read-file.js.map +1 -1
  302. package/dist/tools/builtins/read-render.d.ts +12 -1
  303. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  304. package/dist/tools/builtins/read-render.js +16 -3
  305. package/dist/tools/builtins/read-render.js.map +1 -1
  306. package/dist/tools/builtins/search-tools.d.ts +10 -0
  307. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  308. package/dist/tools/builtins/search-tools.js +36 -2
  309. package/dist/tools/builtins/search-tools.js.map +1 -1
  310. package/dist/tools/builtins/skill.d.ts +31 -0
  311. package/dist/tools/builtins/skill.d.ts.map +1 -1
  312. package/dist/tools/builtins/skill.js +232 -88
  313. package/dist/tools/builtins/skill.js.map +1 -1
  314. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  315. package/dist/tools/builtins/wait-for-job.js +5 -0
  316. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  317. package/dist/tools/builtins/web.d.ts.map +1 -1
  318. package/dist/tools/builtins/web.js +13 -2
  319. package/dist/tools/builtins/web.js.map +1 -1
  320. package/dist/tools/task/create.d.ts.map +1 -1
  321. package/dist/tools/task/create.js +13 -4
  322. package/dist/tools/task/create.js.map +1 -1
  323. package/dist/tools/task/get.d.ts +8 -0
  324. package/dist/tools/task/get.d.ts.map +1 -0
  325. package/dist/tools/task/get.js +51 -0
  326. package/dist/tools/task/get.js.map +1 -0
  327. package/dist/tools/task/index.d.ts +7 -0
  328. package/dist/tools/task/index.d.ts.map +1 -1
  329. package/dist/tools/task/index.js +10 -2
  330. package/dist/tools/task/index.js.map +1 -1
  331. package/dist/tools/task/list.d.ts.map +1 -1
  332. package/dist/tools/task/list.js +10 -2
  333. package/dist/tools/task/list.js.map +1 -1
  334. package/dist/tools/task/number.d.ts +13 -0
  335. package/dist/tools/task/number.d.ts.map +1 -0
  336. package/dist/tools/task/number.js +30 -0
  337. package/dist/tools/task/number.js.map +1 -0
  338. package/dist/tools/task/present.d.ts.map +1 -1
  339. package/dist/tools/task/present.js +17 -3
  340. package/dist/tools/task/present.js.map +1 -1
  341. package/dist/tools/task/update.d.ts +2 -1
  342. package/dist/tools/task/update.d.ts.map +1 -1
  343. package/dist/tools/task/update.js +87 -20
  344. package/dist/tools/task/update.js.map +1 -1
  345. package/dist/types/acp/index.d.ts +10 -0
  346. package/dist/types/acp/index.d.ts.map +1 -1
  347. package/dist/types/agent/base.d.ts +4 -0
  348. package/dist/types/agent/base.d.ts.map +1 -1
  349. package/dist/types/agent/scheduler.d.ts +9 -0
  350. package/dist/types/agent/scheduler.d.ts.map +1 -1
  351. package/dist/types/computer-use/index.d.ts +7 -0
  352. package/dist/types/computer-use/index.d.ts.map +1 -1
  353. package/dist/types/computer-use/index.js.map +1 -1
  354. package/dist/types/connector/mcp.d.ts +10 -0
  355. package/dist/types/connector/mcp.d.ts.map +1 -1
  356. package/dist/types/permission/index.d.ts +20 -0
  357. package/dist/types/permission/index.d.ts.map +1 -1
  358. package/dist/types/permission/index.js +25 -0
  359. package/dist/types/permission/index.js.map +1 -1
  360. package/dist/types/plugin/index.d.ts +47 -3
  361. package/dist/types/plugin/index.d.ts.map +1 -1
  362. package/dist/types/plugin/index.js +4 -0
  363. package/dist/types/plugin/index.js.map +1 -1
  364. package/dist/types/provider/chat.d.ts +8 -0
  365. package/dist/types/provider/chat.d.ts.map +1 -1
  366. package/dist/types/provider/interface.d.ts +16 -0
  367. package/dist/types/provider/interface.d.ts.map +1 -1
  368. package/dist/types/provider/model.d.ts +6 -0
  369. package/dist/types/provider/model.d.ts.map +1 -1
  370. package/dist/types/provider/stream.d.ts +2 -0
  371. package/dist/types/provider/stream.d.ts.map +1 -1
  372. package/dist/types/tool/index.d.ts +28 -2
  373. package/dist/types/tool/index.d.ts.map +1 -1
  374. package/dist/types/tool/index.js.map +1 -1
  375. package/dist/types/tool/presentation.d.ts +15 -0
  376. package/dist/types/tool/presentation.d.ts.map +1 -1
  377. package/dist/utils/node-on-path.d.ts +27 -0
  378. package/dist/utils/node-on-path.d.ts.map +1 -0
  379. package/dist/utils/node-on-path.js +70 -0
  380. package/dist/utils/node-on-path.js.map +1 -0
  381. package/package.json +1 -1
  382. package/src/agents/QueryAgent.ts +2 -0
  383. package/src/authorization/skill-grant.ts +1 -0
  384. package/src/bridge/acp/permission.ts +11 -1
  385. package/src/bridge/acp/server.ts +26 -0
  386. package/src/compaction/context-window.ts +18 -0
  387. package/src/compaction/loaded-skills.ts +42 -1
  388. package/src/compaction/manager.ts +28 -0
  389. package/src/compaction/manual.ts +9 -1
  390. package/src/compaction/model-summary.ts +2 -2
  391. package/src/compaction/restore.ts +69 -0
  392. package/src/compaction/salience/working-set.ts +6 -2
  393. package/src/compaction/tool-result-editing.ts +8 -1
  394. package/src/compaction/types.ts +2 -0
  395. package/src/compaction/wire.ts +4 -0
  396. package/src/connector/index.ts +27 -0
  397. package/src/connector/mcp/client.ts +71 -2
  398. package/src/connector/mcp/errors.ts +14 -0
  399. package/src/connector/mcp/index.ts +36 -0
  400. package/src/connector/mcp/skill-source.ts +499 -0
  401. package/src/connector/mcp/skills.ts +367 -0
  402. package/src/manager/session/turn-recorder.ts +24 -1
  403. package/src/network/audit.ts +2 -0
  404. package/src/network/computer.ts +347 -0
  405. package/src/network/index.ts +20 -0
  406. package/src/network/join.ts +21 -2
  407. package/src/network/roster.ts +5 -0
  408. package/src/network/service.ts +674 -84
  409. package/src/network/store.ts +57 -4
  410. package/src/network/transport.ts +1 -1
  411. package/src/network/wire.ts +18 -1
  412. package/src/plugin/shell-hook-tool-names.ts +1 -0
  413. package/src/plugin/shell-hook.ts +144 -7
  414. package/src/prompt/coding-agent-doctrine.ts +7 -2
  415. package/src/provider/fallback.ts +10 -0
  416. package/src/provider/idle-timeout.ts +9 -0
  417. package/src/provider/instrumentation.ts +12 -0
  418. package/src/provider/model-window-suffix.ts +2 -0
  419. package/src/provider/retry.ts +9 -0
  420. package/src/public-runtime.ts +100 -0
  421. package/src/public-tools.ts +18 -0
  422. package/src/public-types.ts +29 -0
  423. package/src/registry/tool/presentation.ts +14 -4
  424. package/src/runtime/jobs/registry.ts +2 -1
  425. package/src/runtime/query/auto-review/classifier.ts +19 -3
  426. package/src/runtime/query/auto-review/failure.ts +50 -0
  427. package/src/runtime/query/auto-review/index.ts +1 -0
  428. package/src/runtime/query/executor/tool-call-admission.ts +10 -1
  429. package/src/runtime/query/executor.ts +57 -8
  430. package/src/runtime/query/file-evidence-replay.ts +6 -5
  431. package/src/runtime/query/index.ts +62 -0
  432. package/src/runtime/query/iteration/index.ts +2 -0
  433. package/src/runtime/query/iteration/phases/compaction.ts +25 -2
  434. package/src/runtime/query/iteration/phases/context.ts +4 -0
  435. package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
  436. package/src/runtime/query/iteration/step-shaping.ts +4 -0
  437. package/src/runtime/query/prepare-turn.ts +20 -2
  438. package/src/runtime/query/review-policy.ts +31 -5
  439. package/src/runtime/query/shell-line-escalation.ts +49 -0
  440. package/src/runtime/query/tooling.ts +6 -0
  441. package/src/runtime/query/turn/outcome-ledger.ts +56 -1
  442. package/src/sandbox/provider/local.ts +3 -1
  443. package/src/scheduler/local.ts +3 -1
  444. package/src/skills/index.ts +43 -0
  445. package/src/skills/inline-shell-host.ts +303 -0
  446. package/src/skills/inline-shell.ts +765 -0
  447. package/src/store/index.ts +8 -0
  448. package/src/store/task/file.ts +641 -0
  449. package/src/teams/backend.ts +29 -0
  450. package/src/teams/fs-sync.ts +91 -0
  451. package/src/teams/index.ts +47 -0
  452. package/src/teams/names.ts +49 -0
  453. package/src/teams/store.ts +607 -0
  454. package/src/teams/types.ts +102 -0
  455. package/src/tools/admit-facts.ts +26 -0
  456. package/src/tools/builtins/bash.ts +5 -2
  457. package/src/tools/builtins/browser.ts +1 -1
  458. package/src/tools/builtins/computer-use.ts +799 -86
  459. package/src/tools/builtins/content-fingerprint.ts +2 -1
  460. package/src/tools/builtins/edit-apply.ts +124 -24
  461. package/src/tools/builtins/edit-match.ts +200 -0
  462. package/src/tools/builtins/edit.ts +16 -7
  463. package/src/tools/builtins/exit-semantics.ts +23 -0
  464. package/src/tools/builtins/index.ts +3 -0
  465. package/src/tools/builtins/present-file.ts +127 -0
  466. package/src/tools/builtins/read-file.ts +1 -1
  467. package/src/tools/builtins/read-render.ts +18 -3
  468. package/src/tools/builtins/search-tools.ts +36 -2
  469. package/src/tools/builtins/skill.ts +291 -95
  470. package/src/tools/builtins/wait-for-job.ts +5 -0
  471. package/src/tools/builtins/web.ts +15 -2
  472. package/src/tools/task/create.ts +13 -4
  473. package/src/tools/task/get.ts +53 -0
  474. package/src/tools/task/index.ts +14 -2
  475. package/src/tools/task/list.ts +10 -2
  476. package/src/tools/task/number.ts +32 -0
  477. package/src/tools/task/present.ts +18 -3
  478. package/src/tools/task/update.ts +94 -20
  479. package/src/types/acp/index.ts +11 -1
  480. package/src/types/agent/base.ts +6 -0
  481. package/src/types/agent/scheduler.ts +9 -0
  482. package/src/types/computer-use/index.ts +7 -0
  483. package/src/types/connector/mcp.ts +10 -0
  484. package/src/types/permission/index.ts +29 -0
  485. package/src/types/plugin/index.ts +95 -39
  486. package/src/types/provider/chat.ts +9 -0
  487. package/src/types/provider/interface.ts +18 -0
  488. package/src/types/provider/model.ts +6 -0
  489. package/src/types/provider/stream.ts +2 -0
  490. package/src/types/tool/index.ts +23 -2
  491. package/src/types/tool/presentation.ts +14 -0
  492. package/src/utils/node-on-path.ts +81 -0
@@ -0,0 +1,347 @@
1
+ /**
2
+ * The computer secret: how two Namzu homes of one person on one computer prove they share a computer.
3
+ *
4
+ * A "machine" on the Namzu network is a key, one per home, so the default home, a scheduler service home,
5
+ * Desktop and a WSL terminal are each another machine. They may join without a person's Allow only when
6
+ * the joiner shows it holds the same secret as the member it reached. That is the whole evidence: a source
7
+ * address, a machine name, a hostname or a flag in the request prove nothing and are never consulted.
8
+ *
9
+ * One 32-byte secret per OS user lives at `<default home>/network/machine-secret` (mode 0600 in a 0700
10
+ * directory). It is never sent: a proof is an HMAC over both ends of the TLS leg and the joiner's nonce.
11
+ *
12
+ * @experimental
13
+ */
14
+
15
+ import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto'
16
+ import { link, lstat, mkdir, open, readFile, unlink, writeFile } from 'node:fs/promises'
17
+ import { basename, dirname, join, posix, resolve } from 'node:path'
18
+ import { hardenPeerRuntimeDir } from '../peers/dir.js'
19
+
20
+ export const COMPUTER_SECRET_FILE = 'machine-secret'
21
+ /** Beside the native secret on WSL: where the Windows profile's copy was found, so a service without interop finds it too. */
22
+ export const COMPUTER_SECRET_WINDOWS_PATH_FILE = 'machine-secret.windows-path'
23
+
24
+ const SECRET_BYTES = 32
25
+ const SECRET_HEX_LENGTH = SECRET_BYTES * 2
26
+ const KEY_DOMAIN = 'namzu-net/computer/key/1'
27
+ const JOIN_DOMAIN = 'namzu-net/computer/join/1'
28
+ const MEMBER_DOMAIN = 'namzu-net/computer/member/1'
29
+ const FINGERPRINT_DOMAIN = 'namzu-net/computer/fp/1'
30
+
31
+ /** How a secret file is trusted: by inspecting it (POSIX), or by where it lives (a Windows profile seen from WSL). */
32
+ export type ComputerSecretCheck = 'posix' | 'path-only'
33
+
34
+ export interface ComputerSecretSource {
35
+ readonly path: string
36
+ readonly check: ComputerSecretCheck
37
+ /** True when this home may create the file when it is absent. */
38
+ readonly create: boolean
39
+ }
40
+
41
+ export type ComputerSecretRead =
42
+ | { readonly status: 'ok'; readonly secret: Buffer }
43
+ | { readonly status: 'absent' }
44
+ | { readonly status: 'unsafe'; readonly reason: string }
45
+
46
+ export interface ReadSecretOptions {
47
+ readonly uid?: number | undefined
48
+ /** Tests: pretend to be this platform. */
49
+ readonly platform?: string
50
+ }
51
+
52
+ const currentUid = () => (typeof process.getuid === 'function' ? process.getuid() : undefined)
53
+
54
+ /**
55
+ * Read the secret, refusing anything that could be someone else's or could have been read by someone else:
56
+ * a symbolic link, a file that is not regular, one owned by another user, one readable or writable by
57
+ * group or others, a directory others can write, or a file of the wrong size. A refusal is reported, never
58
+ * repaired, and never replaced (a new secret would split the homes).
59
+ */
60
+ export async function readComputerSecret(
61
+ source: Pick<ComputerSecretSource, 'path' | 'check'>,
62
+ options: ReadSecretOptions = {},
63
+ ): Promise<ComputerSecretRead> {
64
+ let info: Awaited<ReturnType<typeof lstat>>
65
+ try {
66
+ info = await lstat(source.path)
67
+ } catch {
68
+ return { status: 'absent' }
69
+ }
70
+ if (info.isSymbolicLink()) return { status: 'unsafe', reason: 'the secret is a symbolic link' }
71
+ if (!info.isFile()) return { status: 'unsafe', reason: 'the secret is not a regular file' }
72
+ const platform = options.platform ?? process.platform
73
+ if (source.check === 'posix' && platform !== 'win32') {
74
+ const uid = 'uid' in options ? options.uid : currentUid()
75
+ if (uid !== undefined && info.uid !== uid)
76
+ return { status: 'unsafe', reason: 'the secret belongs to another user' }
77
+ if ((info.mode & 0o077) !== 0)
78
+ return {
79
+ status: 'unsafe',
80
+ reason: 'the secret can be read by others (mode is not 0600)',
81
+ }
82
+ let parent: Awaited<ReturnType<typeof lstat>>
83
+ try {
84
+ parent = await lstat(dirname(source.path))
85
+ } catch {
86
+ return {
87
+ status: 'unsafe',
88
+ reason: 'the folder of the secret cannot be read',
89
+ }
90
+ }
91
+ if (uid !== undefined && parent.uid !== uid)
92
+ return {
93
+ status: 'unsafe',
94
+ reason: 'the folder of the secret belongs to another user',
95
+ }
96
+ if ((parent.mode & 0o022) !== 0)
97
+ return {
98
+ status: 'unsafe',
99
+ reason: 'the folder of the secret can be written by others',
100
+ }
101
+ }
102
+ let text: string
103
+ try {
104
+ text = (await readFile(source.path, 'utf8')).trim()
105
+ } catch {
106
+ return { status: 'unsafe', reason: 'the secret cannot be read' }
107
+ }
108
+ if (!/^[0-9a-f]+$/.test(text) || text.length !== SECRET_HEX_LENGTH)
109
+ return { status: 'unsafe', reason: 'the secret is not the expected size' }
110
+ return { status: 'ok', secret: Buffer.from(text, 'hex') }
111
+ }
112
+
113
+ /**
114
+ * Create the secret when no file is there. Two homes starting together race: the file is written whole to a
115
+ * private name and then linked into place, which fails for the loser, who reads the winner's. An existing
116
+ * file (good or bad) is never overwritten.
117
+ */
118
+ export async function ensureComputerSecret(
119
+ source: ComputerSecretSource,
120
+ harden: (dir: string) => void = (dir) => hardenPeerRuntimeDir(dir, currentUid()),
121
+ ): Promise<'created' | 'exists'> {
122
+ if (!source.create) return 'exists'
123
+ try {
124
+ await lstat(source.path)
125
+ return 'exists'
126
+ } catch {
127
+ // absent: create below
128
+ }
129
+ const dir = dirname(source.path)
130
+ harden(dir)
131
+ await mkdir(dir, { recursive: true, mode: 0o700 })
132
+ const staging = join(
133
+ dir,
134
+ `.${COMPUTER_SECRET_FILE}.${process.pid}.${randomBytes(6).toString('hex')}`,
135
+ )
136
+ const body = `${randomBytes(SECRET_BYTES).toString('hex')}\n`
137
+ try {
138
+ const handle = await open(staging, 'wx', 0o600)
139
+ try {
140
+ await handle.writeFile(body)
141
+ } finally {
142
+ await handle.close()
143
+ }
144
+ try {
145
+ await link(staging, source.path)
146
+ return 'created'
147
+ } catch (error) {
148
+ if ((error as NodeJS.ErrnoException).code === 'EEXIST') return 'exists'
149
+ // A filesystem without hard links: create exclusively instead.
150
+ try {
151
+ await writeFile(source.path, body, { flag: 'wx', mode: 0o600 })
152
+ return 'created'
153
+ } catch (inner) {
154
+ if ((inner as NodeJS.ErrnoException).code === 'EEXIST') return 'exists'
155
+ throw inner
156
+ }
157
+ }
158
+ } finally {
159
+ await unlink(staging).catch(() => undefined)
160
+ }
161
+ }
162
+
163
+ const computerKey = (secret: Buffer): Buffer =>
164
+ createHmac('sha256', secret).update(KEY_DOMAIN).digest()
165
+
166
+ /**
167
+ * The proof a joiner attaches to its join request. It names both ends of the TLS leg as each side sees them
168
+ * and the joiner's nonce, so a machine relaying between the two cannot reuse it and a copy of it from
169
+ * another key does not verify.
170
+ */
171
+ export function computerJoinProof(
172
+ secret: Buffer,
173
+ joinerMachineId: string,
174
+ memberMachineId: string,
175
+ joinerNonce: string,
176
+ ): string {
177
+ return createHmac('sha256', computerKey(secret))
178
+ .update(JSON.stringify([JOIN_DOMAIN, joinerMachineId, memberMachineId, joinerNonce]), 'utf8')
179
+ .digest('base64')
180
+ }
181
+
182
+ export function verifyComputerJoinProof(
183
+ secret: Buffer,
184
+ proof: string,
185
+ joinerMachineId: string,
186
+ memberMachineId: string,
187
+ joinerNonce: string,
188
+ ): boolean {
189
+ const expected = Buffer.from(
190
+ computerJoinProof(secret, joinerMachineId, memberMachineId, joinerNonce),
191
+ 'utf8',
192
+ )
193
+ const given = Buffer.from(proof, 'utf8')
194
+ return given.length === expected.length && timingSafeEqual(given, expected)
195
+ }
196
+
197
+ /**
198
+ * The member's counter-proof in the `admitted` frame, under its own domain string so a join proof can never
199
+ * stand in for it. It names both ends and both nonces: the joiner records "this computer" only when it
200
+ * verifies, so a member that merely claims the flag is not marked.
201
+ */
202
+ export function computerMemberProof(
203
+ secret: Buffer,
204
+ memberMachineId: string,
205
+ joinerMachineId: string,
206
+ joinerNonce: string,
207
+ memberNonce: string,
208
+ ): string {
209
+ return createHmac('sha256', computerKey(secret))
210
+ .update(
211
+ JSON.stringify([MEMBER_DOMAIN, memberMachineId, joinerMachineId, joinerNonce, memberNonce]),
212
+ 'utf8',
213
+ )
214
+ .digest('base64')
215
+ }
216
+
217
+ export function verifyComputerMemberProof(
218
+ secret: Buffer,
219
+ proof: string,
220
+ memberMachineId: string,
221
+ joinerMachineId: string,
222
+ joinerNonce: string,
223
+ memberNonce: string,
224
+ ): boolean {
225
+ const expected = Buffer.from(
226
+ computerMemberProof(secret, memberMachineId, joinerMachineId, joinerNonce, memberNonce),
227
+ 'utf8',
228
+ )
229
+ const given = Buffer.from(proof, 'utf8')
230
+ return given.length === expected.length && timingSafeEqual(given, expected)
231
+ }
232
+
233
+ /** A short public tag of a secret (not reversible), kept beside the remembered machines so a reset secret drops the marks. */
234
+ export function computerSecretFingerprint(secret: Buffer): string {
235
+ return createHmac('sha256', computerKey(secret))
236
+ .update(FINGERPRINT_DOMAIN)
237
+ .digest()
238
+ .subarray(0, 8)
239
+ .toString('hex')
240
+ }
241
+
242
+ // ─── which secret a home may use ─────────────────────────────────────────
243
+
244
+ export interface ResolveSecretDeps {
245
+ readonly realpath: (path: string) => Promise<string>
246
+ readonly exists: (path: string) => Promise<boolean>
247
+ readonly readText: (path: string) => Promise<string | undefined>
248
+ readonly writeText: (path: string, text: string) => Promise<void>
249
+ /** Run a program and return its trimmed standard output, or undefined when it cannot run. */
250
+ readonly exec: (command: string, args: readonly string[]) => Promise<string | undefined>
251
+ /**
252
+ * The user id the file system reports as owning a file (undefined when it cannot be read). On WSL a
253
+ * Windows drive is mounted as one Linux user, so this is how a Windows file is tied to a Linux user.
254
+ * Without it the Windows copy is never trusted.
255
+ */
256
+ readonly fileOwner?: (path: string) => Promise<number | undefined>
257
+ /** The user id of this process (undefined where there is none); the Windows copy is trusted only for the user that owns it. */
258
+ readonly uid?: number | undefined
259
+ }
260
+
261
+ export interface ResolveSecretInput {
262
+ /** This home (`NAMZU_HOME` or the default). */
263
+ readonly home: string
264
+ /** The OS user's home directory; the default Namzu home is `<osHome>/.namzu`. */
265
+ readonly osHome: string
266
+ readonly platform: string
267
+ readonly env: NodeJS.ProcessEnv
268
+ readonly deps: ResolveSecretDeps
269
+ }
270
+
271
+ /** Where a Windows profile seen from WSL may live: `/mnt/<drive>/Users/<name>`. Anything else is refused. */
272
+ const WINDOWS_PROFILE_FROM_WSL = /^\/mnt\/[a-z]\/Users\/[^/\0]+$/
273
+
274
+ export const windowsProfilePathOk = (path: string): boolean =>
275
+ WINDOWS_PROFILE_FROM_WSL.test(path) && posix.normalize(path) === path
276
+
277
+ /** Whether `home` is the default home or a scheduler service home directly under it. */
278
+ export async function homeQualifies(
279
+ home: string,
280
+ osHome: string,
281
+ realpath: (path: string) => Promise<string>,
282
+ ): Promise<boolean> {
283
+ const real = async (p: string) => realpath(p).catch(() => resolve(p))
284
+ const defaultHome = await real(join(osHome, '.namzu'))
285
+ const mine = await real(home)
286
+ if (mine === defaultHome) return true
287
+ const parent = dirname(mine)
288
+ return basename(parent) === 'services' && dirname(parent) === defaultHome && mine !== parent
289
+ }
290
+
291
+ const isWsl = (platform: string, env: NodeJS.ProcessEnv) =>
292
+ platform === 'linux' &&
293
+ (typeof env.WSL_DISTRO_NAME === 'string' || typeof env.WSL_INTEROP === 'string')
294
+
295
+ /**
296
+ * Which secret this home uses, or undefined when it uses none (it then asks a person like any other machine).
297
+ *
298
+ * Only the default home and a service home directly under it qualify; any other `NAMZU_HOME` (a scratch or
299
+ * sandboxed home) never joins the person's network by itself. On Windows, Linux and macOS the native copy
300
+ * is the secret. On WSL the Windows profile's copy is the source of truth when it can be read (so Desktop
301
+ * and the WSL terminal agree) and the Linux user that the Windows drive mount maps the file to is the
302
+ * current one, else the native WSL copy in this user's own home; Windows never reaches into WSL, whose distro may
303
+ * not be running.
304
+ */
305
+ export async function resolveComputerSecret(
306
+ input: ResolveSecretInput,
307
+ ): Promise<ComputerSecretSource | undefined> {
308
+ const { home, osHome, platform, env, deps } = input
309
+ if (!(await homeQualifies(home, osHome, deps.realpath))) return undefined
310
+ const nativeDir = join(osHome, '.namzu', 'network')
311
+ const native: ComputerSecretSource = {
312
+ path: join(nativeDir, COMPUTER_SECRET_FILE),
313
+ check: platform === 'win32' ? 'path-only' : 'posix',
314
+ create: true,
315
+ }
316
+ if (!isWsl(platform, env)) return native
317
+
318
+ const cachePath = join(nativeDir, COMPUTER_SECRET_WINDOWS_PATH_FILE)
319
+ let profile: string | undefined
320
+ // With interop the Windows profile of the account running this very process is asked for afresh and
321
+ // wins over the cache, so a stale or planted cache cannot point at another Windows account's folder.
322
+ // The cache serves only a home that has no interop (a service).
323
+ if (typeof env.WSL_INTEROP === 'string') {
324
+ const raw = await deps.exec('cmd.exe', ['/c', 'echo %USERPROFILE%'])
325
+ const win = raw?.replace(/\r/g, '').trim()
326
+ if (win && !win.includes('%')) {
327
+ const unix = (await deps.exec('wslpath', ['-u', win]))?.trim()
328
+ if (unix !== undefined && windowsProfilePathOk(unix)) {
329
+ profile = unix
330
+ await deps.writeText(cachePath, `${unix}\n`).catch(() => undefined)
331
+ }
332
+ }
333
+ } else {
334
+ const cached = (await deps.readText(cachePath))?.trim()
335
+ if (cached !== undefined && windowsProfilePathOk(cached)) profile = cached
336
+ }
337
+ if (profile === undefined) return native
338
+ const windowsPath = join(profile, '.namzu', 'network', COMPUTER_SECRET_FILE)
339
+ // Only a copy Windows made: from here nothing is ever created in the Windows profile.
340
+ if (!(await deps.exists(windowsPath))) return native
341
+ // A Windows drive is mounted into the distro as one Linux user, so every other Linux user of the
342
+ // distro would reach the same file. Only the user the mount maps the file to may trust it; any
343
+ // other uses the copy in its own home, and a file whose owner cannot be seen is not trusted.
344
+ const owner = await deps.fileOwner?.(windowsPath).catch(() => undefined)
345
+ if (owner === undefined || deps.uid === undefined || owner !== deps.uid) return native
346
+ return { path: windowsPath, check: 'path-only', create: false }
347
+ }
@@ -61,6 +61,26 @@ export type {
61
61
  export { createNetworkStore } from './store.js'
62
62
  export type { NetworkStore, NetworkStoreOptions } from './store.js'
63
63
 
64
+ export {
65
+ COMPUTER_SECRET_FILE,
66
+ COMPUTER_SECRET_WINDOWS_PATH_FILE,
67
+ computerJoinProof,
68
+ ensureComputerSecret,
69
+ homeQualifies,
70
+ readComputerSecret,
71
+ resolveComputerSecret,
72
+ verifyComputerJoinProof,
73
+ windowsProfilePathOk,
74
+ } from './computer.js'
75
+ export type {
76
+ ComputerSecretCheck,
77
+ ComputerSecretRead,
78
+ ComputerSecretSource,
79
+ ReadSecretOptions,
80
+ ResolveSecretDeps,
81
+ ResolveSecretInput,
82
+ } from './computer.js'
83
+
64
84
  export { formatJoinCode, joinCode } from './join.js'
65
85
  export type { PendingJoin } from './join.js'
66
86
 
@@ -39,7 +39,13 @@ export function formatJoinCode(code: string): string {
39
39
 
40
40
  export const JOIN_EXPIRY_MS = 10 * 60 * 1000
41
41
  export const MAX_PENDING_JOINS = 8
42
+ /** A request whose connection is gone is kept this long for another terminal of the machine to take over. */
43
+ export const JOIN_ORPHAN_MS = 60 * 1000
42
44
  export const JOIN_ADDRESS_WINDOW_MS = 60 * 1000
45
+ /** After a person denied the ask, this machine does not ask that network again on its own for this long. */
46
+ export const JOIN_BACKOFF_DENIED_MS = 60 * 60 * 1000
47
+ /** After the ask expired unanswered or was refused: shorter, because nobody said no. */
48
+ export const JOIN_BACKOFF_OTHER_MS = 10 * 60 * 1000
43
49
 
44
50
  export interface PendingJoin {
45
51
  readonly requestId: string
@@ -71,16 +77,24 @@ export class JoinTable {
71
77
  private readonly lastByAddress = new Map<string, number>()
72
78
  constructor(private readonly options: JoinTableOptions) {}
73
79
 
80
+ /** Whether this address asked less than a minute ago. */
81
+ tooSoon(sourceAddr: string): boolean {
82
+ const last = this.lastByAddress.get(sourceAddr)
83
+ return last !== undefined && this.options.clock.now() - last < JOIN_ADDRESS_WINDOW_MS
84
+ }
85
+
74
86
  /** A request that arrived on this machine. Refused when the address asked too recently or the table is full. */
75
87
  addLocal(
76
88
  input: Omit<PendingJoin, 'local' | 'expiresAt' | 'createdAt'>,
89
+ /** A joiner that proved it holds this computer's secret does not meet the per-address limit. */
90
+ exemptFromRate = false,
77
91
  ): { ok: true; entry: PendingJoin } | { ok: false; reason: 'rate' | 'full' } {
78
92
  const now = this.options.clock.now()
79
93
  const last = this.lastByAddress.get(input.sourceAddr)
80
- if (last !== undefined && now - last < JOIN_ADDRESS_WINDOW_MS)
94
+ if (!exemptFromRate && last !== undefined && now - last < JOIN_ADDRESS_WINDOW_MS)
81
95
  return { ok: false, reason: 'rate' }
82
96
  if (this.localCount() >= MAX_PENDING_JOINS) return { ok: false, reason: 'full' }
83
- this.lastByAddress.set(input.sourceAddr, now)
97
+ if (!exemptFromRate) this.lastByAddress.set(input.sourceAddr, now)
84
98
  return {
85
99
  ok: true,
86
100
  entry: this.insert({
@@ -121,6 +135,11 @@ export class JoinTable {
121
135
  return n
122
136
  }
123
137
 
138
+ /** The request waiting from this machine, if any: a machine has at most one. */
139
+ findByJoiner(joinerMachineId: string): PendingJoin | undefined {
140
+ return this.list().find((e) => e.joinerMachineId === joinerMachineId)
141
+ }
142
+
124
143
  get(requestId: string): PendingJoin | undefined {
125
144
  return this.entries.get(requestId)
126
145
  }
@@ -79,6 +79,11 @@ export interface RosterMachineView {
79
79
  /** Epoch ms of the last answer; absent for this machine. */
80
80
  readonly seenAt?: number
81
81
  readonly role?: string
82
+ /**
83
+ * True when this machine is another home of the same person on this computer: it joined, or let this one
84
+ * in, by proving the computer secret, and the secret still reads. A live fact, not part of any signed record.
85
+ */
86
+ readonly sameComputer?: boolean
82
87
  readonly sessions: readonly RosterSession[]
83
88
  }
84
89