harnery 0.40.0 → 0.42.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 (595) hide show
  1. package/README.md +1 -1
  2. package/dist/commander.js +4 -0
  3. package/dist/commands/agents.d.ts.map +1 -1
  4. package/dist/commands/agents.js +34 -20
  5. package/dist/commands/artifacts.d.ts.map +1 -1
  6. package/dist/commands/artifacts.js +113 -12
  7. package/dist/commands/browse-ai.d.ts.map +1 -1
  8. package/dist/commands/browse-ai.js +4 -0
  9. package/dist/commands/browse.d.ts +164 -0
  10. package/dist/commands/browse.d.ts.map +1 -1
  11. package/dist/commands/browse.js +388 -45
  12. package/dist/commands/checkpoint.js +8 -12
  13. package/dist/commands/claude-desktop.d.ts.map +1 -1
  14. package/dist/commands/claude-desktop.js +52 -0
  15. package/dist/commands/deinit.d.ts +1 -1
  16. package/dist/commands/deinit.d.ts.map +1 -1
  17. package/dist/commands/deinit.js +8 -4
  18. package/dist/commands/disk.d.ts +6 -0
  19. package/dist/commands/disk.d.ts.map +1 -0
  20. package/dist/commands/disk.js +80 -0
  21. package/dist/commands/docs.d.ts.map +1 -1
  22. package/dist/commands/docs.js +2 -0
  23. package/dist/commands/doctor.d.ts +8 -0
  24. package/dist/commands/doctor.d.ts.map +1 -1
  25. package/dist/commands/doctor.js +58 -3
  26. package/dist/commands/fetch.d.ts.map +1 -1
  27. package/dist/commands/fetch.js +10 -0
  28. package/dist/commands/files.d.ts +16 -0
  29. package/dist/commands/files.d.ts.map +1 -1
  30. package/dist/commands/files.js +54 -2
  31. package/dist/commands/init.d.ts +21 -5
  32. package/dist/commands/init.d.ts.map +1 -1
  33. package/dist/commands/init.js +271 -109
  34. package/dist/commands/instructions.js +5 -4
  35. package/dist/commands/ledger-v3.d.ts.map +1 -1
  36. package/dist/commands/ledger-v3.js +2 -1
  37. package/dist/commands/rm.d.ts +4 -0
  38. package/dist/commands/rm.d.ts.map +1 -0
  39. package/dist/commands/rm.js +87 -0
  40. package/dist/commands/servers.d.ts +7 -0
  41. package/dist/commands/servers.d.ts.map +1 -0
  42. package/dist/commands/servers.js +394 -0
  43. package/dist/commands/tunnel.d.ts.map +1 -1
  44. package/dist/commands/tunnel.js +82 -2
  45. package/dist/commands/webview.d.ts +4 -0
  46. package/dist/commands/webview.d.ts.map +1 -0
  47. package/dist/commands/webview.js +94 -0
  48. package/dist/core/adapter.d.ts +50 -1
  49. package/dist/core/adapter.d.ts.map +1 -1
  50. package/dist/core/adapter.js +59 -1
  51. package/dist/core/adapters/attestation.d.ts.map +1 -1
  52. package/dist/core/adapters/attestation.js +3 -2
  53. package/dist/core/adapters/profiles.d.ts +29 -3
  54. package/dist/core/adapters/profiles.d.ts.map +1 -1
  55. package/dist/core/adapters/profiles.js +53 -1
  56. package/dist/core/adapters/registry.d.ts.map +1 -1
  57. package/dist/core/adapters/registry.js +33 -0
  58. package/dist/core/adapters/types.d.ts +9 -0
  59. package/dist/core/adapters/types.d.ts.map +1 -1
  60. package/dist/core/agents/canonical-emit.d.ts +1 -1
  61. package/dist/core/agents/canonical-emit.d.ts.map +1 -1
  62. package/dist/core/agents/canonical-emit.js +2 -7
  63. package/dist/core/agents/cli.js +25 -16
  64. package/dist/core/agents/coord-client.d.ts.map +1 -1
  65. package/dist/core/agents/coord-client.js +7 -2
  66. package/dist/core/agents/render/session-context.d.ts.map +1 -1
  67. package/dist/core/agents/render/session-context.js +2 -0
  68. package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -1
  69. package/dist/core/agents/rules/claim-conflict.js +3 -9
  70. package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -1
  71. package/dist/core/agents/rules/commit-conflict.js +2 -8
  72. package/dist/core/agents/rules/stop-hook.d.ts +2 -0
  73. package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
  74. package/dist/core/agents/rules/stop-hook.js +1 -1
  75. package/dist/core/agents/session-events.d.ts +6 -2
  76. package/dist/core/agents/session-events.d.ts.map +1 -1
  77. package/dist/core/agents/session-events.js +105 -26
  78. package/dist/core/agents/session-finalization-state-v3.d.ts.map +1 -1
  79. package/dist/core/agents/session-finalization-state-v3.js +2 -1
  80. package/dist/core/agents/session-finalizer-v3.d.ts.map +1 -1
  81. package/dist/core/agents/session-finalizer-v3.js +5 -4
  82. package/dist/core/agents/session-name-display.d.ts +28 -0
  83. package/dist/core/agents/session-name-display.d.ts.map +1 -1
  84. package/dist/core/agents/session-name-display.js +43 -0
  85. package/dist/core/agents/state/heartbeat-reader.d.ts +7 -0
  86. package/dist/core/agents/state/heartbeat-reader.d.ts.map +1 -1
  87. package/dist/core/agents/state/heartbeat-writer.d.ts +10 -0
  88. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  89. package/dist/core/agents/state/heartbeat-writer.js +21 -2
  90. package/dist/core/agents/state/live-coordination-view.d.ts +20 -0
  91. package/dist/core/agents/state/live-coordination-view.d.ts.map +1 -1
  92. package/dist/core/agents/state/live-coordination-view.js +61 -0
  93. package/dist/core/agents/state/live-coordination-writer.js +3 -0
  94. package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
  95. package/dist/core/agents/state/stale-sweep.js +2 -10
  96. package/dist/core/agents/turn-changes.d.ts +17 -0
  97. package/dist/core/agents/turn-changes.d.ts.map +1 -0
  98. package/dist/core/agents/turn-changes.js +76 -0
  99. package/dist/core/artifacts/delivery-card.d.ts.map +1 -1
  100. package/dist/core/artifacts/delivery-card.js +11 -3
  101. package/dist/core/artifacts/index.d.ts +140 -4
  102. package/dist/core/artifacts/index.d.ts.map +1 -1
  103. package/dist/core/artifacts/index.js +526 -52
  104. package/dist/core/config.d.ts +73 -11
  105. package/dist/core/config.d.ts.map +1 -1
  106. package/dist/core/config.js +142 -3
  107. package/dist/core/context/index.d.ts.map +1 -1
  108. package/dist/core/context/index.js +2 -1
  109. package/dist/core/conversations/archive.d.ts.map +1 -1
  110. package/dist/core/conversations/archive.js +4 -3
  111. package/dist/core/diagnostics/bundle.d.ts.map +1 -1
  112. package/dist/core/diagnostics/bundle.js +5 -4
  113. package/dist/core/events/legacy-storage/canary.d.ts.map +1 -1
  114. package/dist/core/events/legacy-storage/canary.js +5 -4
  115. package/dist/core/events/legacy-storage/compression.d.ts.map +1 -1
  116. package/dist/core/events/legacy-storage/compression.js +2 -1
  117. package/dist/core/events/v3/adapter-id.d.ts +10 -2
  118. package/dist/core/events/v3/adapter-id.d.ts.map +1 -1
  119. package/dist/core/events/v3/adapter-id.js +16 -0
  120. package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
  121. package/dist/core/events/v3/authority-outbox.js +2 -1
  122. package/dist/core/events/v3/bootstrap.d.ts.map +1 -1
  123. package/dist/core/events/v3/bootstrap.js +5 -4
  124. package/dist/core/events/v3/capabilities.d.ts.map +1 -1
  125. package/dist/core/events/v3/capabilities.js +17 -0
  126. package/dist/core/events/v3/contract.d.ts +5 -0
  127. package/dist/core/events/v3/contract.d.ts.map +1 -1
  128. package/dist/core/events/v3/contract.js +7 -1
  129. package/dist/core/events/v3/control-witness.d.ts.map +1 -1
  130. package/dist/core/events/v3/control-witness.js +3 -2
  131. package/dist/core/events/v3/coordination-transaction-recovery.d.ts.map +1 -1
  132. package/dist/core/events/v3/coordination-transaction-recovery.js +4 -3
  133. package/dist/core/events/v3/fingerprint-keys.d.ts.map +1 -1
  134. package/dist/core/events/v3/fingerprint-keys.js +7 -6
  135. package/dist/core/events/v3/generated.d.ts +1 -1
  136. package/dist/core/events/v3/generated.js +1 -1
  137. package/dist/core/events/v3/live-feed.d.ts.map +1 -1
  138. package/dist/core/events/v3/live-feed.js +5 -4
  139. package/dist/core/events/v3/producers/command-recorder.d.ts.map +1 -1
  140. package/dist/core/events/v3/producers/command-recorder.js +8 -7
  141. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
  142. package/dist/core/events/v3/producers/coordination-recorder.js +8 -7
  143. package/dist/core/events/v3/producers/diagnostic-summaries.d.ts.map +1 -1
  144. package/dist/core/events/v3/producers/diagnostic-summaries.js +5 -4
  145. package/dist/core/events/v3/producers/hook-base.d.ts +1 -0
  146. package/dist/core/events/v3/producers/hook-base.d.ts.map +1 -1
  147. package/dist/core/events/v3/producers/hook-base.js +10 -4
  148. package/dist/core/events/v3/producers/hook.d.ts +2 -0
  149. package/dist/core/events/v3/producers/hook.d.ts.map +1 -1
  150. package/dist/core/events/v3/producers/hook.js +16 -1
  151. package/dist/core/events/v3/producers/intake.d.ts.map +1 -1
  152. package/dist/core/events/v3/producers/intake.js +16 -6
  153. package/dist/core/events/v3/producers/recorder.d.ts +2 -4
  154. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  155. package/dist/core/events/v3/producers/recorder.js +125 -101
  156. package/dist/core/events/v3/projection.js +9 -1
  157. package/dist/core/events/v3/recovery.d.ts.map +1 -1
  158. package/dist/core/events/v3/recovery.js +4 -3
  159. package/dist/core/events/v3/support-storage/inventory.d.ts.map +1 -1
  160. package/dist/core/events/v3/support-storage/inventory.js +2 -1
  161. package/dist/core/events/v3/support-storage/maintenance.d.ts.map +1 -1
  162. package/dist/core/events/v3/support-storage/maintenance.js +4 -3
  163. package/dist/core/events/v3/support-storage/pack-reader.d.ts.map +1 -1
  164. package/dist/core/events/v3/support-storage/pack-reader.js +4 -3
  165. package/dist/core/events/v3/support-storage/pack-writer.d.ts.map +1 -1
  166. package/dist/core/events/v3/support-storage/pack-writer.js +6 -5
  167. package/dist/core/events/v3/tool-line-changes.d.ts +8 -0
  168. package/dist/core/events/v3/tool-line-changes.d.ts.map +1 -0
  169. package/dist/core/events/v3/tool-line-changes.js +135 -0
  170. package/dist/core/events/v3/writer.d.ts.map +1 -1
  171. package/dist/core/events/v3/writer.js +8 -7
  172. package/dist/core/governor/planning.d.ts.map +1 -1
  173. package/dist/core/governor/planning.js +6 -5
  174. package/dist/core/governor/service.d.ts.map +1 -1
  175. package/dist/core/governor/service.js +12 -11
  176. package/dist/core/governor/state.d.ts.map +1 -1
  177. package/dist/core/governor/state.js +7 -6
  178. package/dist/core/guard/evaluator.js +1 -0
  179. package/dist/core/guard/storage.d.ts.map +1 -1
  180. package/dist/core/guard/storage.js +3 -2
  181. package/dist/core/hooks/adapter/behaviors/claude-code.d.ts +4 -0
  182. package/dist/core/hooks/adapter/behaviors/claude-code.d.ts.map +1 -0
  183. package/dist/core/hooks/adapter/behaviors/claude-code.js +31 -0
  184. package/dist/core/hooks/adapter/behaviors/codex.d.ts +15 -0
  185. package/dist/core/hooks/adapter/behaviors/codex.d.ts.map +1 -0
  186. package/dist/core/hooks/adapter/behaviors/codex.js +82 -0
  187. package/dist/core/hooks/adapter/behaviors/cursor.d.ts +7 -0
  188. package/dist/core/hooks/adapter/behaviors/cursor.d.ts.map +1 -0
  189. package/dist/core/hooks/adapter/behaviors/cursor.js +35 -0
  190. package/dist/core/hooks/adapter/behaviors/index.d.ts +11 -0
  191. package/dist/core/hooks/adapter/behaviors/index.d.ts.map +1 -0
  192. package/dist/core/hooks/adapter/behaviors/index.js +20 -0
  193. package/dist/core/hooks/adapter/behaviors/openclaw.d.ts +7 -0
  194. package/dist/core/hooks/adapter/behaviors/openclaw.d.ts.map +1 -0
  195. package/dist/core/hooks/adapter/behaviors/openclaw.js +34 -0
  196. package/dist/core/hooks/adapter/behaviors/opencode.d.ts +7 -0
  197. package/dist/core/hooks/adapter/behaviors/opencode.d.ts.map +1 -0
  198. package/dist/core/hooks/adapter/behaviors/opencode.js +34 -0
  199. package/dist/core/hooks/adapter/behaviors/types.d.ts +89 -0
  200. package/dist/core/hooks/adapter/behaviors/types.d.ts.map +1 -0
  201. package/dist/core/hooks/adapter/behaviors/types.js +1 -0
  202. package/dist/core/hooks/adapter/detect.d.ts +1 -1
  203. package/dist/core/hooks/adapter/detect.d.ts.map +1 -1
  204. package/dist/core/hooks/adapter/detect.js +2 -3
  205. package/dist/core/hooks/adapter/events.d.ts +46 -1
  206. package/dist/core/hooks/adapter/events.d.ts.map +1 -1
  207. package/dist/core/hooks/adapter/events.js +36 -0
  208. package/dist/core/hooks/adapter/opencode-plugin.d.ts +60 -0
  209. package/dist/core/hooks/adapter/opencode-plugin.d.ts.map +1 -0
  210. package/dist/core/hooks/adapter/opencode-plugin.js +129 -0
  211. package/dist/core/hooks/adapter/output.d.ts +7 -0
  212. package/dist/core/hooks/adapter/output.d.ts.map +1 -1
  213. package/dist/core/hooks/adapter/output.js +8 -1
  214. package/dist/core/hooks/adapter/runtime-telemetry.js +3 -1
  215. package/dist/core/hooks/adapter/wiring.d.ts +52 -8
  216. package/dist/core/hooks/adapter/wiring.d.ts.map +1 -1
  217. package/dist/core/hooks/adapter/wiring.js +133 -12
  218. package/dist/core/hooks/cli.js +676 -531
  219. package/dist/core/hooks/effects/image-capture.d.ts.map +1 -1
  220. package/dist/core/hooks/effects/image-capture.js +2 -1
  221. package/dist/core/hooks/prompt-context/contract.d.ts.map +1 -1
  222. package/dist/core/hooks/prompt-context/contract.js +1 -0
  223. package/dist/core/hooks/resolve/transcript.d.ts +1 -1
  224. package/dist/core/hooks/resolve/transcript.d.ts.map +1 -1
  225. package/dist/core/hooks/resolve/transcript.js +35 -4
  226. package/dist/core/hooks/run-markers.d.ts +37 -0
  227. package/dist/core/hooks/run-markers.d.ts.map +1 -0
  228. package/dist/core/hooks/run-markers.js +109 -0
  229. package/dist/core/hooks/session-name-presence.d.ts +3 -1
  230. package/dist/core/hooks/session-name-presence.d.ts.map +1 -1
  231. package/dist/core/hooks/session-name-presence.js +7 -2
  232. package/dist/core/hooks/shell-waiter.d.ts +2 -0
  233. package/dist/core/hooks/shell-waiter.d.ts.map +1 -0
  234. package/dist/core/hooks/shell-waiter.js +173 -0
  235. package/dist/core/resources/service.d.ts.map +1 -1
  236. package/dist/core/resources/service.js +5 -4
  237. package/dist/core/semantic/review.d.ts.map +1 -1
  238. package/dist/core/semantic/review.js +5 -4
  239. package/dist/core/semantic/service.d.ts.map +1 -1
  240. package/dist/core/semantic/service.js +15 -14
  241. package/dist/core/semantic/storage.d.ts.map +1 -1
  242. package/dist/core/semantic/storage.js +5 -4
  243. package/dist/core/servers/index.d.ts +211 -0
  244. package/dist/core/servers/index.d.ts.map +1 -0
  245. package/dist/core/servers/index.js +560 -0
  246. package/dist/core/servers/net.d.ts +58 -0
  247. package/dist/core/servers/net.d.ts.map +1 -0
  248. package/dist/core/servers/net.js +270 -0
  249. package/dist/core/servers/tunnels.d.ts +14 -0
  250. package/dist/core/servers/tunnels.d.ts.map +1 -0
  251. package/dist/core/servers/tunnels.js +33 -0
  252. package/dist/core/storage/atomic-json.d.ts.map +1 -1
  253. package/dist/core/storage/atomic-json.js +7 -3
  254. package/dist/core/storage/builtins.js +1 -0
  255. package/dist/core/storage/durable-history.d.ts.map +1 -1
  256. package/dist/core/storage/durable-history.js +6 -5
  257. package/dist/core/storage/maintenance-providers.d.ts.map +1 -1
  258. package/dist/core/storage/maintenance-providers.js +2 -1
  259. package/dist/core/storage/maintenance.d.ts.map +1 -1
  260. package/dist/core/storage/maintenance.js +7 -6
  261. package/dist/core/storage/metrics.d.ts.map +1 -1
  262. package/dist/core/storage/metrics.js +5 -1
  263. package/dist/core/storage/modes.d.ts +17 -0
  264. package/dist/core/storage/modes.d.ts.map +1 -0
  265. package/dist/core/storage/modes.js +47 -0
  266. package/dist/core/storage/process-log.d.ts.map +1 -1
  267. package/dist/core/storage/process-log.js +3 -2
  268. package/dist/core/storage/receipts.d.ts.map +1 -1
  269. package/dist/core/storage/receipts.js +4 -3
  270. package/dist/core/storage/segments.d.ts.map +1 -1
  271. package/dist/core/storage/segments.js +7 -6
  272. package/dist/core/supervisor/hook-health.d.ts +2 -1
  273. package/dist/core/supervisor/hook-health.d.ts.map +1 -1
  274. package/dist/core/supervisor/hook-health.js +4 -3
  275. package/dist/core/supervisor/service.d.ts.map +1 -1
  276. package/dist/core/supervisor/service.js +7 -6
  277. package/dist/core/work/state.d.ts.map +1 -1
  278. package/dist/core/work/state.js +8 -7
  279. package/dist/core/workflow/adapters.d.ts +7 -0
  280. package/dist/core/workflow/adapters.d.ts.map +1 -1
  281. package/dist/core/workflow/adapters.js +9 -0
  282. package/dist/core/workflow/approvals.d.ts.map +1 -1
  283. package/dist/core/workflow/approvals.js +6 -5
  284. package/dist/core/workflow/billing.d.ts.map +1 -1
  285. package/dist/core/workflow/billing.js +33 -4
  286. package/dist/core/workflow/durable-record.d.ts.map +1 -1
  287. package/dist/core/workflow/durable-record.js +4 -3
  288. package/dist/core/workflow/engine.d.ts.map +1 -1
  289. package/dist/core/workflow/engine.js +30 -1
  290. package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
  291. package/dist/core/workflow/live-session-v3.js +2 -3
  292. package/dist/core/workflow/run-state.d.ts.map +1 -1
  293. package/dist/core/workflow/run-state.js +3 -2
  294. package/dist/core/workflow/sandbox-projection.d.ts +13 -2
  295. package/dist/core/workflow/sandbox-projection.d.ts.map +1 -1
  296. package/dist/core/workflow/sandbox-projection.js +23 -0
  297. package/dist/core/workflow/spawn-claude.d.ts.map +1 -1
  298. package/dist/core/workflow/spawn-claude.js +6 -1
  299. package/dist/core/workflow/spawn-codex.d.ts +2 -0
  300. package/dist/core/workflow/spawn-codex.d.ts.map +1 -1
  301. package/dist/core/workflow/spawn-codex.js +20 -1
  302. package/dist/core/workflow/spawn-cursor.d.ts.map +1 -1
  303. package/dist/core/workflow/spawn-cursor.js +6 -1
  304. package/dist/core/workflow/spawn-opencode.d.ts +36 -0
  305. package/dist/core/workflow/spawn-opencode.d.ts.map +1 -0
  306. package/dist/core/workflow/spawn-opencode.js +135 -0
  307. package/dist/core/workflow/transcript.d.ts.map +1 -1
  308. package/dist/core/workflow/transcript.js +3 -2
  309. package/dist/core/workflow/types.d.ts +47 -2
  310. package/dist/core/workflow/types.d.ts.map +1 -1
  311. package/dist/core/workflow/worker-access.d.ts +92 -0
  312. package/dist/core/workflow/worker-access.d.ts.map +1 -0
  313. package/dist/core/workflow/worker-access.js +450 -0
  314. package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
  315. package/dist/core/workflow/workspaces/leases.js +5 -4
  316. package/dist/core/workflow/workspaces/local-git.d.ts.map +1 -1
  317. package/dist/core/workflow/workspaces/local-git.js +3 -2
  318. package/dist/core/workflow/workspaces/paths.d.ts.map +1 -1
  319. package/dist/core/workflow/workspaces/paths.js +2 -1
  320. package/dist/core/workflow/workspaces/state.d.ts.map +1 -1
  321. package/dist/core/workflow/workspaces/state.js +10 -9
  322. package/dist/lazy-commands.js +8 -1
  323. package/dist/lib/agent-browser/client.d.ts +9 -0
  324. package/dist/lib/agent-browser/client.d.ts.map +1 -1
  325. package/dist/lib/agent-browser/client.js +13 -0
  326. package/dist/lib/browser/batch-steps.d.ts +18 -0
  327. package/dist/lib/browser/batch-steps.d.ts.map +1 -0
  328. package/dist/lib/browser/batch-steps.js +82 -0
  329. package/dist/lib/browser/client.d.ts +35 -1
  330. package/dist/lib/browser/client.d.ts.map +1 -1
  331. package/dist/lib/browser/client.js +117 -8
  332. package/dist/lib/browser/collect/collector.d.ts +99 -0
  333. package/dist/lib/browser/collect/collector.d.ts.map +1 -0
  334. package/dist/lib/browser/collect/collector.js +202 -0
  335. package/dist/lib/browser/collect/fields.d.ts +31 -0
  336. package/dist/lib/browser/collect/fields.d.ts.map +1 -0
  337. package/dist/lib/browser/collect/fields.js +75 -0
  338. package/dist/lib/browser/collect/index.d.ts +6 -0
  339. package/dist/lib/browser/collect/index.d.ts.map +1 -0
  340. package/dist/lib/browser/collect/index.js +5 -0
  341. package/dist/lib/browser/collect/page-driver.d.ts +14 -0
  342. package/dist/lib/browser/collect/page-driver.d.ts.map +1 -0
  343. package/dist/lib/browser/collect/page-driver.js +306 -0
  344. package/dist/lib/browser/collect/presets.d.ts +52 -0
  345. package/dist/lib/browser/collect/presets.d.ts.map +1 -0
  346. package/dist/lib/browser/collect/presets.js +176 -0
  347. package/dist/lib/browser/collect/scroll-plan.d.ts +85 -0
  348. package/dist/lib/browser/collect/scroll-plan.d.ts.map +1 -0
  349. package/dist/lib/browser/collect/scroll-plan.js +118 -0
  350. package/dist/lib/browser/identity.d.ts +25 -0
  351. package/dist/lib/browser/identity.d.ts.map +1 -0
  352. package/dist/lib/browser/identity.js +66 -0
  353. package/dist/lib/browser/index.d.ts +3 -2
  354. package/dist/lib/browser/index.d.ts.map +1 -1
  355. package/dist/lib/browser/index.js +2 -1
  356. package/dist/lib/browser/launch-args.d.ts +26 -0
  357. package/dist/lib/browser/launch-args.d.ts.map +1 -1
  358. package/dist/lib/browser/launch-args.js +41 -1
  359. package/dist/lib/browser/page-review-judge.d.ts +2 -0
  360. package/dist/lib/browser/page-review-judge.d.ts.map +1 -1
  361. package/dist/lib/browser/page-review-judge.js +13 -0
  362. package/dist/lib/browser/qa-run-contracts.d.ts +10 -0
  363. package/dist/lib/browser/qa-run-contracts.d.ts.map +1 -1
  364. package/dist/lib/browser/qa-run.d.ts.map +1 -1
  365. package/dist/lib/browser/qa-run.js +1 -0
  366. package/dist/lib/browser/user-agent.d.ts +53 -0
  367. package/dist/lib/browser/user-agent.d.ts.map +1 -0
  368. package/dist/lib/browser/user-agent.js +79 -0
  369. package/dist/lib/browser/windows-chrome.d.ts +59 -0
  370. package/dist/lib/browser/windows-chrome.d.ts.map +1 -0
  371. package/dist/lib/browser/windows-chrome.js +179 -0
  372. package/dist/lib/claude-desktop-share.d.ts +136 -0
  373. package/dist/lib/claude-desktop-share.d.ts.map +1 -0
  374. package/dist/lib/claude-desktop-share.js +394 -0
  375. package/dist/lib/disk-usage.d.ts +50 -0
  376. package/dist/lib/disk-usage.d.ts.map +1 -0
  377. package/dist/lib/disk-usage.js +303 -0
  378. package/dist/lib/docs-lint.d.ts +6 -0
  379. package/dist/lib/docs-lint.d.ts.map +1 -1
  380. package/dist/lib/docs-lint.js +8 -3
  381. package/dist/lib/docs-metadata-managed.d.ts +1 -0
  382. package/dist/lib/docs-metadata-managed.d.ts.map +1 -1
  383. package/dist/lib/docs-metadata-managed.js +17 -1
  384. package/dist/lib/guarded-remove.d.ts +34 -0
  385. package/dist/lib/guarded-remove.d.ts.map +1 -0
  386. package/dist/lib/guarded-remove.js +310 -0
  387. package/dist/lib/identities/assume.d.ts.map +1 -1
  388. package/dist/lib/identities/assume.js +4 -9
  389. package/dist/lib/instructions/apply.d.ts.map +1 -1
  390. package/dist/lib/instructions/apply.js +2 -0
  391. package/dist/lib/instructions/templates.js +8 -8
  392. package/dist/lib/pace/index.d.ts +2 -0
  393. package/dist/lib/pace/index.d.ts.map +1 -0
  394. package/dist/lib/pace/index.js +1 -0
  395. package/dist/lib/pace/pace.d.ts +95 -0
  396. package/dist/lib/pace/pace.d.ts.map +1 -0
  397. package/dist/lib/pace/pace.js +313 -0
  398. package/dist/lib/tunnel/error-page.d.ts +1 -1
  399. package/dist/lib/tunnel/error-page.d.ts.map +1 -1
  400. package/dist/lib/tunnel/error-page.js +19 -8
  401. package/dist/lib/tunnel/forward-headers.d.ts +11 -0
  402. package/dist/lib/tunnel/forward-headers.d.ts.map +1 -0
  403. package/dist/lib/tunnel/forward-headers.js +17 -0
  404. package/dist/lib/tunnel/gate.js +34 -10
  405. package/dist/lib/tunnel/path-scope.d.ts +22 -0
  406. package/dist/lib/tunnel/path-scope.d.ts.map +1 -0
  407. package/dist/lib/tunnel/path-scope.js +62 -0
  408. package/dist/lib/tunnel/state.d.ts +5 -0
  409. package/dist/lib/tunnel/state.d.ts.map +1 -1
  410. package/dist/lib/tunnel/state.js +17 -3
  411. package/dist/lib/webview/index.d.ts +2 -0
  412. package/dist/lib/webview/index.d.ts.map +1 -0
  413. package/dist/lib/webview/index.js +1 -0
  414. package/dist/lib/webview/webview.d.ts +116 -0
  415. package/dist/lib/webview/webview.d.ts.map +1 -0
  416. package/dist/lib/webview/webview.js +289 -0
  417. package/opencode-plugin/package.json +19 -0
  418. package/opencode-plugin/src/index.ts +791 -0
  419. package/package.json +16 -4
  420. package/schemas/config.schema.json +104 -0
  421. package/schemas/event-v3.schema.json +164 -0
  422. package/src/commander.ts +26 -0
  423. package/src/commands/agents.ts +47 -18
  424. package/src/commands/artifacts.ts +171 -19
  425. package/src/commands/browse-ai.ts +8 -0
  426. package/src/commands/browse.ts +570 -48
  427. package/src/commands/checkpoint.ts +7 -9
  428. package/src/commands/claude-desktop.ts +61 -0
  429. package/src/commands/deinit.ts +9 -4
  430. package/src/commands/disk.ts +114 -0
  431. package/src/commands/docs.ts +2 -0
  432. package/src/commands/doctor.ts +63 -3
  433. package/src/commands/fetch.ts +14 -0
  434. package/src/commands/files.ts +93 -2
  435. package/src/commands/init.ts +334 -122
  436. package/src/commands/instructions.ts +8 -4
  437. package/src/commands/ledger-v3.ts +2 -1
  438. package/src/commands/rm.ts +115 -0
  439. package/src/commands/servers.ts +506 -0
  440. package/src/commands/tunnel.ts +102 -2
  441. package/src/commands/webview.ts +159 -0
  442. package/src/core/adapter.ts +102 -1
  443. package/src/core/adapters/attestation.ts +3 -2
  444. package/src/core/adapters/profiles.ts +63 -1
  445. package/src/core/adapters/registry.ts +37 -0
  446. package/src/core/adapters/types.ts +10 -0
  447. package/src/core/agents/canonical-emit.ts +2 -5
  448. package/src/core/agents/cli.ts +26 -17
  449. package/src/core/agents/coord-client.ts +9 -3
  450. package/src/core/agents/render/session-context.ts +1 -0
  451. package/src/core/agents/rules/claim-conflict.ts +3 -8
  452. package/src/core/agents/rules/commit-conflict.ts +2 -7
  453. package/src/core/agents/rules/stop-hook.ts +3 -1
  454. package/src/core/agents/session-events.ts +120 -26
  455. package/src/core/agents/session-finalization-state-v3.ts +2 -1
  456. package/src/core/agents/session-finalizer-v3.ts +5 -4
  457. package/src/core/agents/session-name-display.ts +48 -0
  458. package/src/core/agents/state/heartbeat-reader.ts +7 -0
  459. package/src/core/agents/state/heartbeat-writer.ts +24 -2
  460. package/src/core/agents/state/live-coordination-view.ts +74 -0
  461. package/src/core/agents/state/live-coordination-writer.ts +3 -0
  462. package/src/core/agents/state/stale-sweep.ts +2 -9
  463. package/src/core/agents/turn-changes.ts +97 -0
  464. package/src/core/artifacts/delivery-card.ts +12 -3
  465. package/src/core/artifacts/index.ts +701 -47
  466. package/src/core/config.ts +206 -4
  467. package/src/core/context/index.ts +2 -1
  468. package/src/core/conversations/archive.ts +4 -3
  469. package/src/core/diagnostics/bundle.ts +5 -3
  470. package/src/core/events/legacy-storage/canary.ts +5 -4
  471. package/src/core/events/legacy-storage/compression.ts +2 -1
  472. package/src/core/events/v3/adapter-id.ts +29 -1
  473. package/src/core/events/v3/authority-outbox.ts +2 -1
  474. package/src/core/events/v3/bootstrap.ts +5 -4
  475. package/src/core/events/v3/capabilities.ts +17 -0
  476. package/src/core/events/v3/contract.ts +9 -1
  477. package/src/core/events/v3/control-witness.ts +3 -2
  478. package/src/core/events/v3/coordination-transaction-recovery.ts +4 -3
  479. package/src/core/events/v3/fingerprint-keys.ts +7 -6
  480. package/src/core/events/v3/generated.ts +1 -1
  481. package/src/core/events/v3/live-feed.ts +5 -4
  482. package/src/core/events/v3/producers/command-recorder.ts +8 -6
  483. package/src/core/events/v3/producers/coordination-recorder.ts +8 -7
  484. package/src/core/events/v3/producers/diagnostic-summaries.ts +5 -4
  485. package/src/core/events/v3/producers/hook-base.ts +11 -4
  486. package/src/core/events/v3/producers/hook.ts +19 -1
  487. package/src/core/events/v3/producers/intake.ts +18 -6
  488. package/src/core/events/v3/producers/recorder.ts +139 -114
  489. package/src/core/events/v3/projection.ts +11 -1
  490. package/src/core/events/v3/recovery.ts +4 -3
  491. package/src/core/events/v3/support-storage/inventory.ts +2 -1
  492. package/src/core/events/v3/support-storage/maintenance.ts +8 -3
  493. package/src/core/events/v3/support-storage/pack-reader.ts +4 -3
  494. package/src/core/events/v3/support-storage/pack-writer.ts +6 -5
  495. package/src/core/events/v3/tool-line-changes.ts +139 -0
  496. package/src/core/events/v3/writer.ts +8 -7
  497. package/src/core/governor/planning.ts +6 -5
  498. package/src/core/governor/service.ts +12 -11
  499. package/src/core/governor/state.ts +7 -6
  500. package/src/core/guard/evaluator.ts +1 -0
  501. package/src/core/guard/storage.ts +3 -2
  502. package/src/core/hooks/adapter/behaviors/claude-code.ts +33 -0
  503. package/src/core/hooks/adapter/behaviors/codex.ts +96 -0
  504. package/src/core/hooks/adapter/behaviors/cursor.ts +37 -0
  505. package/src/core/hooks/adapter/behaviors/index.ts +31 -0
  506. package/src/core/hooks/adapter/behaviors/openclaw.ts +36 -0
  507. package/src/core/hooks/adapter/behaviors/opencode.ts +36 -0
  508. package/src/core/hooks/adapter/behaviors/types.ts +110 -0
  509. package/src/core/hooks/adapter/detect.ts +2 -3
  510. package/src/core/hooks/adapter/events.ts +72 -1
  511. package/src/core/hooks/adapter/opencode-plugin.ts +177 -0
  512. package/src/core/hooks/adapter/output.ts +8 -1
  513. package/src/core/hooks/adapter/runtime-telemetry.ts +3 -1
  514. package/src/core/hooks/adapter/wiring.ts +198 -16
  515. package/src/core/hooks/cli.ts +776 -539
  516. package/src/core/hooks/effects/image-capture.ts +2 -1
  517. package/src/core/hooks/prompt-context/contract.ts +1 -0
  518. package/src/core/hooks/resolve/transcript.ts +42 -5
  519. package/src/core/hooks/run-markers.ts +132 -0
  520. package/src/core/hooks/session-name-presence.ts +10 -3
  521. package/src/core/hooks/shell-waiter.ts +166 -0
  522. package/src/core/resources/service.ts +5 -4
  523. package/src/core/semantic/review.ts +5 -4
  524. package/src/core/semantic/service.ts +15 -14
  525. package/src/core/semantic/storage.ts +5 -4
  526. package/src/core/servers/index.ts +712 -0
  527. package/src/core/servers/net.ts +283 -0
  528. package/src/core/servers/tunnels.ts +39 -0
  529. package/src/core/storage/atomic-json.ts +7 -3
  530. package/src/core/storage/builtins.ts +1 -0
  531. package/src/core/storage/durable-history.ts +6 -5
  532. package/src/core/storage/maintenance-providers.ts +2 -1
  533. package/src/core/storage/maintenance.ts +7 -6
  534. package/src/core/storage/metrics.ts +5 -1
  535. package/src/core/storage/modes.ts +53 -0
  536. package/src/core/storage/process-log.ts +3 -2
  537. package/src/core/storage/receipts.ts +4 -3
  538. package/src/core/storage/segments.ts +7 -6
  539. package/src/core/supervisor/hook-health.ts +4 -4
  540. package/src/core/supervisor/service.ts +7 -6
  541. package/src/core/work/state.ts +8 -7
  542. package/src/core/workflow/adapters.ts +15 -0
  543. package/src/core/workflow/approvals.ts +6 -5
  544. package/src/core/workflow/billing.ts +34 -4
  545. package/src/core/workflow/durable-record.ts +4 -3
  546. package/src/core/workflow/engine.ts +38 -1
  547. package/src/core/workflow/live-session-v3.ts +2 -3
  548. package/src/core/workflow/run-state.ts +3 -2
  549. package/src/core/workflow/sandbox-projection.ts +38 -2
  550. package/src/core/workflow/spawn-claude.ts +5 -1
  551. package/src/core/workflow/spawn-codex.ts +18 -1
  552. package/src/core/workflow/spawn-cursor.ts +5 -1
  553. package/src/core/workflow/spawn-opencode.ts +153 -0
  554. package/src/core/workflow/transcript.ts +3 -2
  555. package/src/core/workflow/types.ts +62 -2
  556. package/src/core/workflow/worker-access.ts +525 -0
  557. package/src/core/workflow/workspaces/leases.ts +5 -4
  558. package/src/core/workflow/workspaces/local-git.ts +3 -2
  559. package/src/core/workflow/workspaces/paths.ts +2 -1
  560. package/src/core/workflow/workspaces/state.ts +10 -9
  561. package/src/lazy-commands.ts +11 -1
  562. package/src/lib/agent-browser/client.ts +18 -0
  563. package/src/lib/browser/batch-steps.ts +79 -0
  564. package/src/lib/browser/client.ts +147 -9
  565. package/src/lib/browser/collect/collector.ts +306 -0
  566. package/src/lib/browser/collect/fields.ts +87 -0
  567. package/src/lib/browser/collect/index.ts +47 -0
  568. package/src/lib/browser/collect/page-driver.ts +327 -0
  569. package/src/lib/browser/collect/presets.ts +237 -0
  570. package/src/lib/browser/collect/scroll-plan.ts +179 -0
  571. package/src/lib/browser/identity.ts +64 -0
  572. package/src/lib/browser/index.ts +16 -1
  573. package/src/lib/browser/launch-args.ts +53 -1
  574. package/src/lib/browser/page-review-judge.ts +16 -0
  575. package/src/lib/browser/qa-run-contracts.ts +11 -0
  576. package/src/lib/browser/qa-run.ts +1 -0
  577. package/src/lib/browser/user-agent.ts +130 -0
  578. package/src/lib/browser/windows-chrome.ts +227 -0
  579. package/src/lib/claude-desktop-share.ts +511 -0
  580. package/src/lib/disk-usage.ts +347 -0
  581. package/src/lib/docs-lint.ts +8 -3
  582. package/src/lib/docs-metadata-managed.ts +21 -0
  583. package/src/lib/guarded-remove.ts +376 -0
  584. package/src/lib/identities/assume.ts +7 -7
  585. package/src/lib/instructions/apply.ts +2 -0
  586. package/src/lib/instructions/templates.ts +8 -8
  587. package/src/lib/pace/index.ts +14 -0
  588. package/src/lib/pace/pace.ts +370 -0
  589. package/src/lib/tunnel/error-page.ts +25 -9
  590. package/src/lib/tunnel/forward-headers.ts +16 -0
  591. package/src/lib/tunnel/gate.ts +39 -10
  592. package/src/lib/tunnel/path-scope.ts +73 -0
  593. package/src/lib/tunnel/state.ts +20 -3
  594. package/src/lib/webview/index.ts +13 -0
  595. package/src/lib/webview/webview.ts +457 -0
@@ -0,0 +1,370 @@
1
+ import {
2
+ closeSync,
3
+ mkdirSync,
4
+ openSync,
5
+ readFileSync,
6
+ renameSync,
7
+ rmSync,
8
+ statSync,
9
+ writeFileSync,
10
+ } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { dirname, resolve } from "node:path";
13
+
14
+ /**
15
+ * Human-pace gate for page loads.
16
+ *
17
+ * Every Harnery surface that loads a web page (`browse`, `browse-ai`, `fetch`,
18
+ * and the headed browse-session verbs) reserves a slot here before the request
19
+ * goes out. Consecutive loads against the same registrable site are spaced by
20
+ * a random gap inside `[minMs, maxMs]`, the way a person reads one page before
21
+ * opening the next. Loads against different sites do not wait on each other.
22
+ * Loopback, private-network, single-label, and reserved-suffix hosts are exempt
23
+ * so local development and page QA keep running at machine speed.
24
+ *
25
+ * The ledger is a small machine-local JSON file (`~/.cache/harnery/pace.json`)
26
+ * shared by every process, so separate `harn fetch` calls in a shell loop are
27
+ * paced the same as one long `harn browse` session. A caller reserves the next
28
+ * slot before it sleeps, so concurrent processes queue behind each other
29
+ * instead of all firing at once.
30
+ *
31
+ * The gate is on by default. `HARNERY_PACE=off` disables it machine-wide and
32
+ * each command carries `--no-pace` for a single run.
33
+ */
34
+
35
+ export const DEFAULT_PACE_MIN_MS = 3_000;
36
+ export const DEFAULT_PACE_MAX_MS = 9_000;
37
+ export const DEFAULT_PACE_LEDGER = resolve(homedir(), ".cache", "harnery", "pace.json");
38
+
39
+ /** Entries idle this long drop out of the ledger on the next write. */
40
+ const LEDGER_RETENTION_MS = 60 * 60 * 1_000;
41
+ /** A lock older than this belongs to a dead process and is reclaimed. */
42
+ const LOCK_STALE_MS = 5_000;
43
+ /** Total time a reservation waits for the ledger lock before proceeding anyway. */
44
+ const LOCK_WAIT_MS = 500;
45
+ const LOCK_POLL_MS = 5;
46
+
47
+ export interface PacePolicy {
48
+ /** False turns the gate into a no-op. Default true. */
49
+ enabled: boolean;
50
+ /** Shortest gap between two loads of the same site, in ms. */
51
+ minMs: number;
52
+ /** Longest gap between two loads of the same site, in ms. */
53
+ maxMs: number;
54
+ /** Extra exempt host suffixes (`example.test` matches itself and `*.example.test`). */
55
+ exemptSuffixes: string[];
56
+ /** Path of the shared reservation ledger. */
57
+ ledgerPath: string;
58
+ }
59
+
60
+ export interface PaceWait {
61
+ /** Registrable site the reservation was made against. */
62
+ site: string;
63
+ /** Milliseconds the caller waited (0 when the slot was free). */
64
+ waitMs: number;
65
+ }
66
+
67
+ export interface PaceGateDeps {
68
+ now?: () => number;
69
+ random?: () => number;
70
+ /** Called after a reservation, whether or not it waited. */
71
+ onWait?: (wait: PaceWait) => void;
72
+ }
73
+
74
+ interface LedgerEntry {
75
+ /** Epoch ms before which the next load of this site must not start. */
76
+ nextAllowedAt: number;
77
+ /** Epoch ms the most recent reservation was granted for. */
78
+ lastAt: number;
79
+ }
80
+
81
+ interface Ledger {
82
+ version: 1;
83
+ sites: Record<string, LedgerEntry>;
84
+ }
85
+
86
+ const OFF_VALUES = new Set(["off", "0", "false", "no", "none"]);
87
+
88
+ /**
89
+ * Resolve the pace policy from the environment.
90
+ *
91
+ * - `HARNERY_PACE`: `off` (or `0`, `false`, `no`) disables the gate. Unset or
92
+ * `human` keeps the default.
93
+ * - `HARNERY_PACE_MIN_MS` / `HARNERY_PACE_MAX_MS`: gap bounds in ms. Both must
94
+ * be non-negative integers with min <= max.
95
+ * - `HARNERY_PACE_EXEMPT`: comma-separated host suffixes that never wait.
96
+ * - `HARNERY_PACE_LEDGER`: ledger path override.
97
+ */
98
+ export function pacePolicyFromEnv(env: NodeJS.ProcessEnv = process.env): PacePolicy {
99
+ const mode = env.HARNERY_PACE?.trim().toLowerCase();
100
+ if (mode && mode !== "human" && !OFF_VALUES.has(mode)) {
101
+ throw new Error(`HARNERY_PACE must be "human" or "off" (got "${env.HARNERY_PACE}").`);
102
+ }
103
+ const minMs = readMs(env, "HARNERY_PACE_MIN_MS", DEFAULT_PACE_MIN_MS);
104
+ const maxMs = readMs(env, "HARNERY_PACE_MAX_MS", DEFAULT_PACE_MAX_MS);
105
+ if (minMs > maxMs) {
106
+ throw new Error(
107
+ `HARNERY_PACE_MIN_MS (${minMs}) must not exceed HARNERY_PACE_MAX_MS (${maxMs}).`,
108
+ );
109
+ }
110
+ const exemptSuffixes = (env.HARNERY_PACE_EXEMPT ?? "")
111
+ .split(",")
112
+ .map((s) => normalizeHost(s))
113
+ .filter((s): s is string => s !== null);
114
+ return {
115
+ enabled: !(mode && OFF_VALUES.has(mode)),
116
+ minMs,
117
+ maxMs,
118
+ exemptSuffixes,
119
+ ledgerPath: env.HARNERY_PACE_LEDGER?.trim() || DEFAULT_PACE_LEDGER,
120
+ };
121
+ }
122
+
123
+ function readMs(env: NodeJS.ProcessEnv, name: string, fallback: number): number {
124
+ const raw = env[name]?.trim();
125
+ if (!raw) return fallback;
126
+ if (!/^\d+$/.test(raw)) {
127
+ throw new Error(
128
+ `${name} must be a non-negative integer number of milliseconds (got "${raw}").`,
129
+ );
130
+ }
131
+ return Number.parseInt(raw, 10);
132
+ }
133
+
134
+ /**
135
+ * Public suffixes that take two labels, so the registrable site is three
136
+ * labels deep (`news.bbc.co.uk` -> `bbc.co.uk`). A short curated list is
137
+ * enough here: the gate only needs sibling hosts of one site to share a key,
138
+ * and a miss degrades to per-hostname pacing, never to no pacing.
139
+ */
140
+ const TWO_LABEL_SUFFIXES = new Set([
141
+ "co.uk",
142
+ "org.uk",
143
+ "ac.uk",
144
+ "gov.uk",
145
+ "com.au",
146
+ "net.au",
147
+ "org.au",
148
+ "co.nz",
149
+ "co.jp",
150
+ "co.kr",
151
+ "co.in",
152
+ "co.za",
153
+ "com.br",
154
+ "com.mx",
155
+ "com.ar",
156
+ "com.cn",
157
+ "com.tw",
158
+ "com.sg",
159
+ "com.tr",
160
+ ]);
161
+
162
+ /** Reserved or local-only suffixes that are never paced. */
163
+ const EXEMPT_SUFFIXES = ["localhost", "local", "test", "internal", "example", "invalid"];
164
+
165
+ function normalizeHost(raw: string): string | null {
166
+ const host = raw.trim().toLowerCase().replace(/\.+$/, "");
167
+ return host ? host : null;
168
+ }
169
+
170
+ function hasSuffix(host: string, suffix: string): boolean {
171
+ return host === suffix || host.endsWith(`.${suffix}`);
172
+ }
173
+
174
+ function isExemptIpv4(host: string): boolean {
175
+ const m = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
176
+ if (!m) return false;
177
+ const [a, b] = [Number(m[1]), Number(m[2])];
178
+ return (
179
+ a === 127 ||
180
+ a === 10 ||
181
+ a === 0 ||
182
+ (a === 172 && b >= 16 && b <= 31) ||
183
+ (a === 192 && b === 168) ||
184
+ (a === 169 && b === 254)
185
+ );
186
+ }
187
+
188
+ function isExemptIpv6(host: string): boolean {
189
+ const h = host.replace(/^\[|\]$/g, "");
190
+ return h === "::1" || h === "::" || /^f[cd]/.test(h) || /^fe[89ab]/.test(h);
191
+ }
192
+
193
+ /**
194
+ * Registrable site a URL belongs to for pacing purposes, or `null` when the
195
+ * URL is exempt: a non-HTTP scheme, a loopback or private address, a
196
+ * single-label or reserved-suffix host, or a configured exemption.
197
+ */
198
+ export function paceSiteKey(url: string, exemptSuffixes: readonly string[] = []): string | null {
199
+ let parsed: URL;
200
+ try {
201
+ parsed = new URL(url);
202
+ } catch {
203
+ return null;
204
+ }
205
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
206
+ const host = normalizeHost(parsed.hostname);
207
+ if (!host) return null;
208
+ if (host.startsWith("[") || host.includes(":")) return isExemptIpv6(host) ? null : host;
209
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(host)) return isExemptIpv4(host) ? null : host;
210
+ for (const suffix of EXEMPT_SUFFIXES) if (hasSuffix(host, suffix)) return null;
211
+ for (const suffix of exemptSuffixes) if (hasSuffix(host, suffix)) return null;
212
+ const labels = host.split(".");
213
+ if (labels.length < 2) return null;
214
+ const lastTwo = labels.slice(-2).join(".");
215
+ if (labels.length >= 3 && TWO_LABEL_SUFFIXES.has(lastTwo)) return labels.slice(-3).join(".");
216
+ return lastTwo;
217
+ }
218
+
219
+ /** Block the current thread for `ms`. Used by clients that drive a child process synchronously. */
220
+ export function sleepSync(ms: number): void {
221
+ if (ms <= 0) return;
222
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
223
+ }
224
+
225
+ export class PaceGate {
226
+ private readonly now: () => number;
227
+ private readonly random: () => number;
228
+ private readonly onWait: ((wait: PaceWait) => void) | undefined;
229
+
230
+ constructor(
231
+ readonly policy: PacePolicy,
232
+ deps: PaceGateDeps = {},
233
+ ) {
234
+ this.now = deps.now ?? Date.now;
235
+ this.random = deps.random ?? Math.random;
236
+ this.onWait = deps.onWait;
237
+ }
238
+
239
+ /** A gate that never waits, for callers that opted out. */
240
+ static disabled(): PaceGate {
241
+ return new PaceGate({ ...pacePolicyFromEnv({}), enabled: false });
242
+ }
243
+
244
+ /**
245
+ * Reserve the next slot for `url` without sleeping. Returns how long the
246
+ * caller should wait before loading, or `null` when the URL is exempt or the
247
+ * gate is disabled. The reservation is recorded even when the wait is zero,
248
+ * so the next load of the same site owes a gap.
249
+ */
250
+ reserve(url: string): PaceWait | null {
251
+ if (!this.policy.enabled) return null;
252
+ const site = paceSiteKey(url, this.policy.exemptSuffixes);
253
+ if (!site) return null;
254
+ const now = this.now();
255
+ const gap = this.policy.minMs + this.random() * (this.policy.maxMs - this.policy.minMs);
256
+ let readyAt = now;
257
+ withLedgerLock(this.policy.ledgerPath, this.now, () => {
258
+ const ledger = readLedger(this.policy.ledgerPath);
259
+ readyAt = Math.max(now, ledger.sites[site]?.nextAllowedAt ?? 0);
260
+ for (const [key, entry] of Object.entries(ledger.sites)) {
261
+ if (entry.nextAllowedAt < now - LEDGER_RETENTION_MS) delete ledger.sites[key];
262
+ }
263
+ ledger.sites[site] = { nextAllowedAt: Math.round(readyAt + gap), lastAt: readyAt };
264
+ writeLedger(this.policy.ledgerPath, ledger);
265
+ });
266
+ const wait = { site, waitMs: Math.max(0, Math.round(readyAt - now)) };
267
+ this.onWait?.(wait);
268
+ return wait;
269
+ }
270
+
271
+ /** Reserve a slot and wait it out asynchronously. */
272
+ async before(url: string): Promise<PaceWait | null> {
273
+ const wait = this.reserve(url);
274
+ if (wait && wait.waitMs > 0) {
275
+ await new Promise<void>((done) => setTimeout(done, wait.waitMs));
276
+ }
277
+ return wait;
278
+ }
279
+
280
+ /** Reserve a slot and block the thread for it. For `spawnSync`-driven clients. */
281
+ beforeSync(url: string): PaceWait | null {
282
+ const wait = this.reserve(url);
283
+ if (wait && wait.waitMs > 0) sleepSync(wait.waitMs);
284
+ return wait;
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Gate for a CLI command run. `null` when the run passed `--no-pace`;
290
+ * otherwise the environment policy, with every non-zero wait reported through
291
+ * `log` so the operator can see why a load took longer.
292
+ */
293
+ export function commandPaceGate(optedIn: boolean, log: (message: string) => void): PaceGate | null {
294
+ if (!optedIn) return null;
295
+ return new PaceGate(pacePolicyFromEnv(), {
296
+ onWait: (wait) => {
297
+ if (wait.waitMs > 0) log(describePaceWait(wait));
298
+ },
299
+ });
300
+ }
301
+
302
+ /** Describe a wait for a human-facing log line. */
303
+ export function describePaceWait(wait: PaceWait): string {
304
+ const seconds = (wait.waitMs / 1_000).toFixed(1);
305
+ return `paced ${seconds}s before ${wait.site} (human pace; --no-pace or HARNERY_PACE=off skips)`;
306
+ }
307
+
308
+ function readLedger(path: string): Ledger {
309
+ try {
310
+ const parsed = JSON.parse(readFileSync(path, "utf8")) as Partial<Ledger>;
311
+ if (parsed && parsed.version === 1 && parsed.sites && typeof parsed.sites === "object") {
312
+ const sites: Record<string, LedgerEntry> = {};
313
+ for (const [key, entry] of Object.entries(parsed.sites)) {
314
+ if (
315
+ entry &&
316
+ typeof entry.nextAllowedAt === "number" &&
317
+ Number.isFinite(entry.nextAllowedAt) &&
318
+ typeof entry.lastAt === "number" &&
319
+ Number.isFinite(entry.lastAt)
320
+ ) {
321
+ sites[key] = { nextAllowedAt: entry.nextAllowedAt, lastAt: entry.lastAt };
322
+ }
323
+ }
324
+ return { version: 1, sites };
325
+ }
326
+ } catch {
327
+ // Missing or corrupt ledger: start fresh. A lost ledger costs one unpaced
328
+ // load per site, never a crash.
329
+ }
330
+ return { version: 1, sites: {} };
331
+ }
332
+
333
+ function writeLedger(path: string, ledger: Ledger): void {
334
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
335
+ const tmp = `${path}.${process.pid}.tmp`;
336
+ writeFileSync(tmp, `${JSON.stringify(ledger)}\n`, { mode: 0o600 });
337
+ renameSync(tmp, path);
338
+ }
339
+
340
+ /**
341
+ * Serialize ledger read-modify-write across processes with an exclusive lock
342
+ * file. The lock is best-effort: a stale lock from a dead process is reclaimed,
343
+ * and a caller that cannot get the lock within `LOCK_WAIT_MS` proceeds without
344
+ * it rather than blocking a page load on a bookkeeping file.
345
+ */
346
+ function withLedgerLock(path: string, now: () => number, fn: () => void): void {
347
+ const lockPath = `${path}.lock`;
348
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
349
+ const start = now();
350
+ let held = false;
351
+ while (!held && now() - start < LOCK_WAIT_MS) {
352
+ try {
353
+ closeSync(openSync(lockPath, "wx", 0o600));
354
+ held = true;
355
+ } catch {
356
+ try {
357
+ if (Date.now() - statSync(lockPath).mtimeMs > LOCK_STALE_MS)
358
+ rmSync(lockPath, { force: true });
359
+ } catch {
360
+ // Lock vanished between the failed open and the stat; retry.
361
+ }
362
+ sleepSync(LOCK_POLL_MS);
363
+ }
364
+ }
365
+ try {
366
+ fn();
367
+ } finally {
368
+ if (held) rmSync(lockPath, { force: true });
369
+ }
370
+ }
@@ -1,5 +1,5 @@
1
1
  export interface TunnelErrorPageOptions {
2
- kind: "access-denied" | "upstream-unavailable";
2
+ kind: "access-denied" | "path-denied" | "upstream-unavailable";
3
3
  incidentId: string;
4
4
  timestamp: string;
5
5
  tunnelName: string;
@@ -40,14 +40,30 @@ function diagnosticText(options: TunnelErrorPageOptions): string {
40
40
  }
41
41
 
42
42
  export function renderTunnelErrorPage(options: TunnelErrorPageOptions): string {
43
- const denied = options.kind === "access-denied";
44
- const title = denied ? "This device is not allowed yet" : "The preview is temporarily offline";
45
- const summary = denied
46
- ? "The tunnel is running, but this device's public IP is not on its access list."
47
- : "The public tunnel and access check are working, but the local preview server is not responding.";
48
- const nextStep = denied
49
- ? "Copy the diagnostic below and send it to the person running the tunnel. It includes the public IP that needs to be allowed."
50
- : "Copy the diagnostic below and send it to the person running the tunnel. The incident ID can be matched to the server log.";
43
+ const copy = {
44
+ "access-denied": {
45
+ title: "This device is not allowed yet",
46
+ summary: "The tunnel is running, but this device's public IP is not on its access list.",
47
+ nextStep:
48
+ "Copy the diagnostic below and send it to the person running the tunnel. It includes the public IP that needs to be allowed.",
49
+ },
50
+ "path-denied": {
51
+ title: "This page is not shared",
52
+ summary:
53
+ "The tunnel is running, but it shares only part of the site, and this address is outside it.",
54
+ nextStep:
55
+ "If you expected to see this page, copy the diagnostic below and send it to the person running the tunnel.",
56
+ },
57
+ "upstream-unavailable": {
58
+ title: "The preview is temporarily offline",
59
+ summary:
60
+ "The public tunnel and access check are working, but the local preview server is not responding.",
61
+ nextStep:
62
+ "Copy the diagnostic below and send it to the person running the tunnel. The incident ID can be matched to the server log.",
63
+ },
64
+ }[options.kind];
65
+ const { title, summary, nextStep } = copy;
66
+ const denied = options.kind !== "upstream-unavailable";
51
67
  const diagnostic = diagnosticText(options);
52
68
  const safeDiagnosticForScript = JSON.stringify(diagnostic).replaceAll("<", "\\u003c");
53
69
 
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Headers the tunnel gate sends to the upstream after the Host rewrite.
3
+ *
4
+ * The gate replaces Host so PHP (and other vhost-routed servers) see the
5
+ * configured review host. Callers that compare Origin to Host then fail,
6
+ * because the browser still sends the public tunnel hostname. Copy that
7
+ * original Host into X-Forwarded-Host, overwriting any client-supplied
8
+ * value, so the upstream can recover the hostname the browser used.
9
+ */
10
+ export function applyUpstreamHeaders(headers: Headers, vhost: string): void {
11
+ const originalHost = headers.get("host") ?? "";
12
+ headers.set("host", vhost);
13
+ if (originalHost) headers.set("x-forwarded-host", originalHost);
14
+ headers.set("accept-encoding", "identity");
15
+ headers.delete("connection");
16
+ }
@@ -1,15 +1,20 @@
1
1
  // Reverse-proxy worker spawned by `tunnel up`. Listens on 127.0.0.1:<port>
2
2
  // and forwards HTTP + WebSocket requests to an upstream with a Host header
3
- // rewrite and Content-Encoding stripped (Bun's fetch auto-decompresses the
4
- // body but retains the encoding header, which breaks browser decoding
5
- // downstream). Cloudflare provider mode checks CF-Connecting-IP against an
6
- // allowlist; trusted local proxy mode lets the local exposer own access.
3
+ // rewrite, the original Host copied to X-Forwarded-Host, and Content-Encoding
4
+ // stripped (Bun's fetch auto-decompresses the body but retains the encoding
5
+ // header, which breaks browser decoding downstream). Cloudflare provider mode
6
+ // checks CF-Connecting-IP against an allowlist; trusted local proxy mode lets
7
+ // the local exposer own access. In every mode the gate then refuses any path
8
+ // outside the tunnel's path scope (see path-scope.ts); an empty scope refuses
9
+ // everything.
7
10
  //
8
11
  // Runs detached, outside the CLI command framework; no command context is
9
12
  // available; stdout/stderr is captured into .cache/tunnel/gate.log by the
10
13
  // spawner.
11
14
 
12
15
  import { renderTunnelErrorPage } from "./error-page";
16
+ import { applyUpstreamHeaders } from "./forward-headers";
17
+ import { ALLOW_PATHS_ENV, isPathAllowed, parseAllowPathsEnv } from "./path-scope.ts";
13
18
 
14
19
  // `--port`/`--name` are also passed on argv (not just env) so the gate's port
15
20
  // and instance name show up in its process command line. That's what lets
@@ -32,6 +37,7 @@ const TARGET = process.env.HARNERY_TUNNEL_TARGET ?? "127.0.0.1:8001";
32
37
  const VHOST = process.env.HARNERY_TUNNEL_VHOST ?? "localhost";
33
38
  const PORT = Number(process.env.HARNERY_TUNNEL_PORT ?? argvFlag("--port") ?? "9001");
34
39
  const ACCESS = process.env.HARNERY_TUNNEL_ACCESS ?? "cloudflare-allowlist";
40
+ const ALLOW_PATHS = parseAllowPathsEnv(process.env[ALLOW_PATHS_ENV]);
35
41
  const NAME = argvFlag("--name") ?? "default";
36
42
 
37
43
  const UPSTREAM_HTTP = `http://${TARGET}`;
@@ -39,6 +45,7 @@ const UPSTREAM_WS = `ws://${TARGET}`;
39
45
 
40
46
  interface WsData {
41
47
  path: string;
48
+ originalHost: string;
42
49
  }
43
50
 
44
51
  function requestDetails(req: Request, url: URL) {
@@ -93,17 +100,35 @@ const server = Bun.serve<WsData, never>({
93
100
  }
94
101
  }
95
102
 
103
+ if (!isPathAllowed(url.pathname, ALLOW_PATHS)) {
104
+ const details = requestDetails(req, url);
105
+ console.log(
106
+ // lint-ok-emission: detached worker, see file note above
107
+ `path-deny: incident=${details.incidentId} ip=${details.clientIp || "(missing-cf-connecting-ip)"} ray=${details.cloudflareRay || "(missing)"} ${req.method} ${details.path}`,
108
+ );
109
+ return new Response(renderTunnelErrorPage({ ...details, kind: "path-denied" }), {
110
+ status: 403,
111
+ headers: {
112
+ "cache-control": "no-store",
113
+ "content-type": "text/html; charset=utf-8",
114
+ "x-harnery-tunnel-incident": details.incidentId,
115
+ },
116
+ });
117
+ }
118
+
96
119
  if (req.headers.get("upgrade")?.toLowerCase() === "websocket") {
97
- if (server.upgrade(req, { data: { path: url.pathname + url.search } })) {
120
+ if (
121
+ server.upgrade(req, {
122
+ data: { path: url.pathname + url.search, originalHost: req.headers.get("host") ?? "" },
123
+ })
124
+ ) {
98
125
  return undefined;
99
126
  }
100
127
  return new Response("WS upgrade failed\n", { status: 500 });
101
128
  }
102
129
 
103
130
  const headers = new Headers(req.headers);
104
- headers.set("host", VHOST);
105
- headers.set("accept-encoding", "identity");
106
- headers.delete("connection");
131
+ applyUpstreamHeaders(headers, VHOST);
107
132
 
108
133
  const init: RequestInit = {
109
134
  method: req.method,
@@ -156,11 +181,14 @@ const server = Bun.serve<WsData, never>({
156
181
  },
157
182
  websocket: {
158
183
  open(ws) {
159
- const { path } = ws.data;
184
+ const { path, originalHost } = ws.data;
160
185
  // Bun's WebSocket constructor accepts a `headers` option at runtime
161
186
  // even though the standard lib.dom.d.ts WebSocket type doesn't.
162
187
  const upstream = new WebSocket(UPSTREAM_WS + path, {
163
- headers: { host: VHOST },
188
+ headers: {
189
+ host: VHOST,
190
+ ...(originalHost ? { "x-forwarded-host": originalHost } : {}),
191
+ },
164
192
  } as unknown as undefined);
165
193
  upstream.binaryType = "arraybuffer";
166
194
  (ws as unknown as { upstream?: WebSocket }).upstream = upstream;
@@ -184,4 +212,5 @@ const server = Bun.serve<WsData, never>({
184
212
  // captured into .cache/tunnel/gate.log by the spawning command.
185
213
  console.log(`harn-tunnel-gate :${server.port} -> ${UPSTREAM_HTTP} (Host: ${VHOST})`); // lint-ok-emission: detached worker, see file note above
186
214
  console.log(`access: ${ACCESS}`); // lint-ok-emission: detached worker, see file note above
215
+ console.log(`paths: ${ALLOW_PATHS.join(", ") || "(empty, every path refused)"}`); // lint-ok-emission: detached worker, see file note above
187
216
  console.log(`allow: ${[...ALLOW].join(", ") || "(empty, not used outside allowlist mode)"}`); // lint-ok-emission: detached worker, see file note above
@@ -0,0 +1,73 @@
1
+ // Path scope for the tunnel gate: the URL path prefixes a tunnel publishes.
2
+ //
3
+ // A tunnel forwards to a whole local app, but the person starting it usually
4
+ // means to share one surface of that app. The gate therefore refuses every
5
+ // request whose path is outside the scope the operator named at `tunnel up`,
6
+ // and an empty scope refuses everything. `/` is the explicit way to publish
7
+ // the whole upstream.
8
+
9
+ /** Env var that carries the scope from `tunnel up` to the detached gate. */
10
+ export const ALLOW_PATHS_ENV = "HARNERY_TUNNEL_ALLOW_PATHS";
11
+
12
+ /**
13
+ * Normalize one `--allow-path` value to a canonical prefix: a leading slash,
14
+ * no trailing slash (except `/` itself), no query or fragment, and no dot,
15
+ * empty, or percent-encoded segment. Throws on anything the gate could not
16
+ * match unambiguously, so a typo fails at `tunnel up` instead of publishing
17
+ * more or less than intended.
18
+ */
19
+ export function normalizeAllowPath(raw: string): string {
20
+ const value = raw.trim();
21
+ if (!value.startsWith("/")) {
22
+ throw new Error(`allow-path must start with "/": ${JSON.stringify(raw)}`);
23
+ }
24
+ if (/[?#%\\]/.test(value)) {
25
+ throw new Error(
26
+ `allow-path must be a plain path prefix without ?, #, %, or \\: ${JSON.stringify(raw)}`,
27
+ );
28
+ }
29
+ if (value === "/") return "/";
30
+ const trimmed = value.replace(/\/+$/, "");
31
+ const segments = trimmed.slice(1).split("/");
32
+ if (segments.some((s) => s === "" || s === "." || s === "..")) {
33
+ throw new Error(
34
+ `allow-path must not contain empty, "." or ".." segments: ${JSON.stringify(raw)}`,
35
+ );
36
+ }
37
+ return trimmed;
38
+ }
39
+
40
+ /** Normalize and de-duplicate a list of `--allow-path` values. */
41
+ export function normalizeAllowPaths(raw: readonly string[]): string[] {
42
+ return [...new Set(raw.map(normalizeAllowPath))];
43
+ }
44
+
45
+ /** Parse the gate's env value (comma-separated, already normalized by `up`). */
46
+ export function parseAllowPathsEnv(value: string | undefined): string[] {
47
+ return normalizeAllowPaths(
48
+ (value ?? "")
49
+ .split(",")
50
+ .map((s) => s.trim())
51
+ .filter(Boolean),
52
+ );
53
+ }
54
+
55
+ // Encoded slash, backslash, dot, or percent. A request path carrying one of
56
+ // these can be decoded differently by the gate and the upstream router (for
57
+ // example `/share%2F..%2Fprivate`), so the gate refuses it outright rather than
58
+ // guess which reading the upstream will use.
59
+ const AMBIGUOUS_PATH = /%(2f|5c|2e|25)|\\/i;
60
+
61
+ /**
62
+ * True when `pathname` (a WHATWG-parsed URL pathname, so `.` and `..` segments
63
+ * are already resolved) falls inside one of the allowed prefixes. A prefix
64
+ * matches itself and anything below it on a segment boundary: `/share` allows
65
+ * `/share` and `/share/x`, never `/shared`.
66
+ */
67
+ export function isPathAllowed(pathname: string, allowPaths: readonly string[]): boolean {
68
+ if (allowPaths.length === 0) return false;
69
+ if (!pathname.startsWith("/") || AMBIGUOUS_PATH.test(pathname)) return false;
70
+ return allowPaths.some(
71
+ (prefix) => prefix === "/" || pathname === prefix || pathname.startsWith(`${prefix}/`),
72
+ );
73
+ }
@@ -11,6 +11,7 @@ import {
11
11
  writeFileSync,
12
12
  } from "node:fs";
13
13
  import { resolve } from "node:path";
14
+ import { isPathAllowed } from "./path-scope.ts";
14
15
 
15
16
  // Tunnel state lives under <root>/.cache/tunnel/. Root defaults to cwd for the
16
17
  // command surface and can be supplied by callers that already resolved a repo.
@@ -81,14 +82,25 @@ export interface TunnelState {
81
82
  target: string;
82
83
  vhost: string;
83
84
  gate_port: number;
85
+ /** URL path prefixes the gate forwards; every other path is refused. */
86
+ allow_paths: string[];
84
87
  tailscale_mode?: TailscaleMode;
85
88
  tailscale_path?: string;
86
89
  tailscale_https_port?: number;
87
90
  }
88
91
 
89
- /** Normalize a parsed state blob; supply `name` for pre-multi-instance files. */
92
+ /**
93
+ * Normalize a parsed state blob; supply `name` for pre-multi-instance files.
94
+ * A state written before path scopes existed reads as an empty scope, which
95
+ * the gate treats as "refuse every path".
96
+ */
90
97
  function normalizeState(raw: TunnelState, fallbackName: string): TunnelState {
91
- return { ...raw, name: raw.name ?? fallbackName, provider: raw.provider ?? "cloudflare" };
98
+ return {
99
+ ...raw,
100
+ name: raw.name ?? fallbackName,
101
+ provider: raw.provider ?? "cloudflare",
102
+ allow_paths: Array.isArray(raw.allow_paths) ? raw.allow_paths : [],
103
+ };
92
104
  }
93
105
 
94
106
  export function readConfig(): TunnelConfig {
@@ -169,7 +181,7 @@ export function isTunnelStateLive(
169
181
  return typeof providerPid === "number" && processAlive(providerPid);
170
182
  }
171
183
 
172
- function tunnelTargetPort(state: TunnelState): number | null {
184
+ export function tunnelTargetPort(state: TunnelState): number | null {
173
185
  const value = /^[a-z][a-z\d+.-]*:\/\//i.test(state.target)
174
186
  ? state.target
175
187
  : `http://${state.target}`;
@@ -209,6 +221,11 @@ export function findLiveTunnelForOrigin(
209
221
  );
210
222
  }
211
223
 
224
+ /** True when the tunnel's path scope forwards every one of `paths`. */
225
+ export function tunnelServesPaths(state: TunnelState, paths: readonly string[]): boolean {
226
+ return paths.every((path) => isPathAllowed(path, state.allow_paths));
227
+ }
228
+
212
229
  /**
213
230
  * Ensure cloudflared is on PATH or installed at ~/.local/bin/cloudflared.
214
231
  * Auto-downloads on Linux; throws on other platforms with brew hint.
@@ -0,0 +1,13 @@
1
+ export {
2
+ type BunWebViewRuntime,
3
+ buildWebViewBackend,
4
+ parseWebViewTypeStep,
5
+ parseWebViewViewport,
6
+ type RunWebViewOptions,
7
+ runWebView,
8
+ type WebViewBackend,
9
+ type WebViewConsoleEvent,
10
+ type WebViewResult,
11
+ type WebViewTypeStep,
12
+ WebViewUnavailableError,
13
+ } from "./webview.ts";