cataly 0.0.0-stage → 0.1.3

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 (1295) hide show
  1. package/.bun-test-timings.json +106 -0
  2. package/.dockerignore +48 -0
  3. package/.gitattributes +1 -0
  4. package/.github/actions/setup/action.yml +54 -0
  5. package/.github/pull_request_template.md +54 -0
  6. package/.github/social-preview.png +0 -0
  7. package/.github/workflows/ci.yml +86 -0
  8. package/.github/workflows/cla.yml +188 -0
  9. package/.github/workflows/cross-os.yml +95 -0
  10. package/.github/workflows/release.yml +39 -0
  11. package/.github/workflows/ulw-update.yml +72 -0
  12. package/.husky/pre-commit +2 -0
  13. package/.oxlintrc.json +47 -0
  14. package/.prettierignore +9 -0
  15. package/.prettierrc.json +11 -0
  16. package/CHANGELOG.md +343 -0
  17. package/CLA.md +58 -0
  18. package/CONTRIBUTING.md +283 -0
  19. package/LICENSE +102 -0
  20. package/LICENSE.omp-dori +23 -0
  21. package/LICENSING.md +61 -0
  22. package/NOTICE +113 -0
  23. package/README.de.md +197 -0
  24. package/README.it.md +197 -0
  25. package/README.ja.md +189 -0
  26. package/README.ko.md +196 -0
  27. package/README.md +208 -2
  28. package/README.zh.md +177 -0
  29. package/bun.lock +198 -0
  30. package/docs/architecture.png +0 -0
  31. package/docs/architecture.svg +2 -0
  32. package/docs/cataly-portrait.webp +0 -0
  33. package/docs/container.md +163 -0
  34. package/docs/discord-voice.md +174 -0
  35. package/docs/dori-vs-deepseek.en.png +0 -0
  36. package/docs/dori-vs-deepseek.ko.png +0 -0
  37. package/docs/hourly-loop.md +28 -0
  38. package/docs/how-it-works-dark.svg +68 -0
  39. package/docs/how-it-works-light.svg +68 -0
  40. package/docs/how-it-works.ko-dark.svg +67 -0
  41. package/docs/how-it-works.ko-light.svg +67 -0
  42. package/docs/lane-flow.png +0 -0
  43. package/docs/lane-flow.svg +1 -0
  44. package/docs/locks.md +47 -0
  45. package/docs/owner-profile.md +71 -0
  46. package/docs/platform-adapter.md +67 -0
  47. package/docs/releases.md +505 -0
  48. package/docs/runtime.md +262 -0
  49. package/examples/brief.md +13 -0
  50. package/examples/container/Dockerfile +119 -0
  51. package/examples/container/compose.yaml +35 -0
  52. package/examples/container/entrypoint.sh +16 -0
  53. package/examples/discord-voice.service +25 -0
  54. package/examples/update-supervisor.service +22 -0
  55. package/examples/update.config.json +54 -0
  56. package/extension/bootstrap.ts +68 -0
  57. package/extension/bun.lock +167 -0
  58. package/extension/deployment-health.ts +83 -0
  59. package/extension/discord-ask-auto.ts +93 -0
  60. package/extension/discord-ask-card.ts +70 -0
  61. package/extension/discord-ask-fields.ts +196 -0
  62. package/extension/discord-ask-form.ts +207 -0
  63. package/extension/discord-ask-html.ts +132 -0
  64. package/extension/discord-ask-interactions.ts +153 -0
  65. package/extension/discord-ask-remote.ts +183 -0
  66. package/extension/discord-ask.ts +175 -0
  67. package/extension/discord-lane-reply.ts +214 -0
  68. package/extension/discord-lane.ts +399 -0
  69. package/extension/head-admission.ts +154 -0
  70. package/extension/head-receipt.ts +88 -0
  71. package/extension/index.ts +1450 -0
  72. package/extension/lane-bookkeeping.ts +33 -0
  73. package/extension/lane-policy.ts +111 -0
  74. package/extension/monitor-output.ts +111 -0
  75. package/extension/monitor-state.ts +91 -0
  76. package/extension/monitor.ts +548 -0
  77. package/extension/native-remote-socket.ts +180 -0
  78. package/extension/native-remote-view.ts +58 -0
  79. package/extension/native-remote.ts +451 -0
  80. package/extension/package.json +20 -0
  81. package/extension/role-invariants.ts +24 -0
  82. package/extension/test/deployment-bootstrap.test.ts +289 -0
  83. package/extension/test/discord-ask-auto.test.ts +256 -0
  84. package/extension/test/discord-ask-buttons.test.ts +147 -0
  85. package/extension/test/discord-ask-card.test.ts +169 -0
  86. package/extension/test/discord-ask-form.test.ts +317 -0
  87. package/extension/test/discord-ask-mailbox.test.ts +159 -0
  88. package/extension/test/discord-ask-timeout.test.ts +89 -0
  89. package/extension/test/discord-ask.test.ts +114 -0
  90. package/extension/test/discord-lane-fence.test.ts +94 -0
  91. package/extension/test/discord-lane-reply.test.ts +151 -0
  92. package/extension/test/discord-lane-wake.test.ts +162 -0
  93. package/extension/test/fake-pi.ts +173 -0
  94. package/extension/test/fake-ulw.ts +38 -0
  95. package/extension/test/head-admission.test.ts +548 -0
  96. package/extension/test/head-receipt.test.ts +85 -0
  97. package/extension/test/index.test.ts +773 -0
  98. package/extension/test/lane-bookkeeping.test.ts +68 -0
  99. package/extension/test/lane-policy.test.ts +263 -0
  100. package/extension/test/launch-argv.test.ts +214 -0
  101. package/extension/test/launch-model.test.ts +192 -0
  102. package/extension/test/monitor-admission.test.ts +186 -0
  103. package/extension/test/monitor-bytes.test.ts +110 -0
  104. package/extension/test/monitor-once-admission.test.ts +133 -0
  105. package/extension/test/monitor-once-durability.test.ts +70 -0
  106. package/extension/test/monitor-once.test.ts +190 -0
  107. package/extension/test/monitor-output.test.ts +140 -0
  108. package/extension/test/monitor-replay.test.ts +69 -0
  109. package/extension/test/monitor-restart.test.ts +110 -0
  110. package/extension/test/monitor-state.test.ts +44 -0
  111. package/extension/test/monitor.test.ts +229 -0
  112. package/extension/test/native-prompt-matrix.test.ts +46 -0
  113. package/extension/test/native-remote.test.ts +357 -0
  114. package/extension/test/native-tool-completion.test.ts +483 -0
  115. package/extension/test/new-session.test.ts +251 -0
  116. package/extension/test/owes-gate.test.ts +141 -0
  117. package/extension/test/owes-monitor-lifecycle.test.ts +88 -0
  118. package/extension/test/record-head-inbound.ts +38 -0
  119. package/extension/test/report-generation.test.ts +210 -0
  120. package/extension/test/report-receipt-race.test.ts +193 -0
  121. package/extension/test/report-tool.test.ts +251 -0
  122. package/extension/test/role-invariants.test.ts +91 -0
  123. package/extension/test/source-bundle.test.ts +91 -0
  124. package/extension/test/status.test.ts +104 -0
  125. package/extension/tsconfig.json +23 -0
  126. package/install.sh +245 -0
  127. package/knip.json +48 -0
  128. package/native-addon/bun.lock +27 -0
  129. package/native-addon/package.json +8 -0
  130. package/native-omp.lock +186 -0
  131. package/native-omp.patch +5343 -0
  132. package/omp-ulw.lock +1 -0
  133. package/omp-ulw.overlay.lock +99 -0
  134. package/omp-ulw.patch +3225 -0
  135. package/package.json +36 -4
  136. package/prompts/duty.md +11 -0
  137. package/prompts/lane-footer.md +18 -0
  138. package/prompts/lead.md +21 -0
  139. package/prompts/nudge-waiting.md +11 -0
  140. package/prompts/nudge.md +10 -0
  141. package/prompts/owner-distill.md +18 -0
  142. package/prompts/review.md +15 -0
  143. package/release-capabilities.json +7 -0
  144. package/scripts/bench/fake-discord.ts +103 -0
  145. package/scripts/bench/variants.ts +142 -0
  146. package/scripts/bench-discord-intake.ts +236 -0
  147. package/scripts/check-loc.ts +47 -0
  148. package/scripts/check-test-fixtures.ts +30 -0
  149. package/scripts/ci-install-herdr.sh +26 -0
  150. package/scripts/consumer/omp +26 -0
  151. package/scripts/consumer-smoke-context.ts +241 -0
  152. package/scripts/consumer-smoke-harness.ts +213 -0
  153. package/scripts/consumer-smoke-inspect.ts +108 -0
  154. package/scripts/install-source.sh +464 -0
  155. package/scripts/release-build.ts +181 -0
  156. package/scripts/release-gate.ts +77 -0
  157. package/scripts/release-journal.ts +105 -0
  158. package/scripts/release-process.ts +135 -0
  159. package/scripts/release-publish.ts +129 -0
  160. package/scripts/release-remote.ts +112 -0
  161. package/scripts/release-source.ts +75 -0
  162. package/scripts/release.ts +60 -0
  163. package/scripts/source-configuration.ts +304 -0
  164. package/scripts/source-dependencies.ts +51 -0
  165. package/scripts/typecheck.ts +46 -0
  166. package/scripts/update-supervisor.ts +112 -0
  167. package/scripts/update-ulw-existing.ts +126 -0
  168. package/scripts/update-ulw-publish.ts +142 -0
  169. package/scripts/update-ulw.ts +25 -0
  170. package/scripts/verify-consumer-release.ts +243 -0
  171. package/skills/dori-mode/SKILL.md +156 -0
  172. package/skills/dori-mode/assets/dori-avatar.png +0 -0
  173. package/skills/dori-mode/references/config.example.json +51 -0
  174. package/skills/dori-mode/references/done-protocol.md +38 -0
  175. package/skills/dori-mode/references/onboarding.md +62 -0
  176. package/skills/dori-mode/references/scripts.md +895 -0
  177. package/skills/dori-mode/references/sessions.md +165 -0
  178. package/skills/dori-mode/references/setup.md +150 -0
  179. package/skills/dori-mode/references/writing.md +37 -0
  180. package/skills/dori-mode/scripts/bun.lock +203 -0
  181. package/skills/dori-mode/scripts/package.json +27 -0
  182. package/skills/dori-mode/scripts/src/artifact-config.ts +48 -0
  183. package/skills/dori-mode/scripts/src/artifact-files.ts +125 -0
  184. package/skills/dori-mode/scripts/src/artifact-records.ts +122 -0
  185. package/skills/dori-mode/scripts/src/artifact-report.ts +79 -0
  186. package/skills/dori-mode/scripts/src/artifacts.ts +235 -0
  187. package/skills/dori-mode/scripts/src/board.ts +160 -0
  188. package/skills/dori-mode/scripts/src/boot-checks.ts +69 -0
  189. package/skills/dori-mode/scripts/src/boot-monitors.ts +245 -0
  190. package/skills/dori-mode/scripts/src/boot.ts +250 -0
  191. package/skills/dori-mode/scripts/src/cgroup-memory.ts +117 -0
  192. package/skills/dori-mode/scripts/src/checkpoint-lock.ts +169 -0
  193. package/skills/dori-mode/scripts/src/checkpoints.ts +185 -0
  194. package/skills/dori-mode/scripts/src/cli-artifacts.ts +74 -0
  195. package/skills/dori-mode/scripts/src/cli-context.ts +161 -0
  196. package/skills/dori-mode/scripts/src/cli-decisions.ts +181 -0
  197. package/skills/dori-mode/scripts/src/cli-discord-gateway.ts +33 -0
  198. package/skills/dori-mode/scripts/src/cli-discord-ops.ts +157 -0
  199. package/skills/dori-mode/scripts/src/cli-discord-purpose.ts +103 -0
  200. package/skills/dori-mode/scripts/src/cli-discord-recovery.ts +22 -0
  201. package/skills/dori-mode/scripts/src/cli-discord.ts +248 -0
  202. package/skills/dori-mode/scripts/src/cli-errors.ts +24 -0
  203. package/skills/dori-mode/scripts/src/cli-harness.ts +26 -0
  204. package/skills/dori-mode/scripts/src/cli-headless.ts +96 -0
  205. package/skills/dori-mode/scripts/src/cli-inbound.ts +71 -0
  206. package/skills/dori-mode/scripts/src/cli-invoke.ts +29 -0
  207. package/skills/dori-mode/scripts/src/cli-journal.ts +234 -0
  208. package/skills/dori-mode/scripts/src/cli-lane-policy.ts +42 -0
  209. package/skills/dori-mode/scripts/src/cli-lanes.ts +243 -0
  210. package/skills/dori-mode/scripts/src/cli-messenger.ts +147 -0
  211. package/skills/dori-mode/scripts/src/cli-ops.ts +171 -0
  212. package/skills/dori-mode/scripts/src/cli-pr.ts +158 -0
  213. package/skills/dori-mode/scripts/src/cli-recall.ts +75 -0
  214. package/skills/dori-mode/scripts/src/cli-remote.ts +241 -0
  215. package/skills/dori-mode/scripts/src/cli-report.ts +41 -0
  216. package/skills/dori-mode/scripts/src/cli-schedule.ts +98 -0
  217. package/skills/dori-mode/scripts/src/cli-status.ts +111 -0
  218. package/skills/dori-mode/scripts/src/cli-telegram.ts +100 -0
  219. package/skills/dori-mode/scripts/src/cli-usage-report.ts +109 -0
  220. package/skills/dori-mode/scripts/src/cli-usage.ts +134 -0
  221. package/skills/dori-mode/scripts/src/cli-voice.ts +93 -0
  222. package/skills/dori-mode/scripts/src/cli.ts +250 -0
  223. package/skills/dori-mode/scripts/src/close-worktrees.ts +74 -0
  224. package/skills/dori-mode/scripts/src/config-identities.ts +23 -0
  225. package/skills/dori-mode/scripts/src/config.ts +222 -0
  226. package/skills/dori-mode/scripts/src/dead-panes.ts +62 -0
  227. package/skills/dori-mode/scripts/src/decisions-fold.ts +155 -0
  228. package/skills/dori-mode/scripts/src/decisions-record.ts +154 -0
  229. package/skills/dori-mode/scripts/src/decisions-render.ts +43 -0
  230. package/skills/dori-mode/scripts/src/decisions.ts +180 -0
  231. package/skills/dori-mode/scripts/src/delivery-lock.ts +87 -0
  232. package/skills/dori-mode/scripts/src/delivery-state.ts +85 -0
  233. package/skills/dori-mode/scripts/src/discord-lane-monitor.ts +98 -0
  234. package/skills/dori-mode/scripts/src/discord-lane-transcript.ts +143 -0
  235. package/skills/dori-mode/scripts/src/discord-lane-wake-command.ts +42 -0
  236. package/skills/dori-mode/scripts/src/discord-lane-wake-lease.ts +52 -0
  237. package/skills/dori-mode/scripts/src/discord-lane-wake-pending.ts +11 -0
  238. package/skills/dori-mode/scripts/src/discord-lane-wake.ts +245 -0
  239. package/skills/dori-mode/scripts/src/discord-lane-wake.yml +17 -0
  240. package/skills/dori-mode/scripts/src/doctor-config.ts +24 -0
  241. package/skills/dori-mode/scripts/src/doctor-monitors.ts +195 -0
  242. package/skills/dori-mode/scripts/src/doctor.ts +223 -0
  243. package/skills/dori-mode/scripts/src/done-flow.ts +238 -0
  244. package/skills/dori-mode/scripts/src/evidence-sequence.ts +38 -0
  245. package/skills/dori-mode/scripts/src/evidence-window.ts +132 -0
  246. package/skills/dori-mode/scripts/src/evidence.ts +231 -0
  247. package/skills/dori-mode/scripts/src/freshness-notify.ts +226 -0
  248. package/skills/dori-mode/scripts/src/freshness-policy.ts +27 -0
  249. package/skills/dori-mode/scripts/src/freshness-report.ts +65 -0
  250. package/skills/dori-mode/scripts/src/freshness.ts +220 -0
  251. package/skills/dori-mode/scripts/src/goal-record.ts +99 -0
  252. package/skills/dori-mode/scripts/src/heavy-slot.ts +70 -0
  253. package/skills/dori-mode/scripts/src/holds.ts +27 -0
  254. package/skills/dori-mode/scripts/src/host-guard.ts +117 -0
  255. package/skills/dori-mode/scripts/src/lane-policy-actions.ts +155 -0
  256. package/skills/dori-mode/scripts/src/lane-policy-launch.ts +64 -0
  257. package/skills/dori-mode/scripts/src/lane-policy-store.ts +126 -0
  258. package/skills/dori-mode/scripts/src/lane-policy.ts +46 -0
  259. package/skills/dori-mode/scripts/src/lane-run.ts +70 -0
  260. package/skills/dori-mode/scripts/src/lane-state.ts +69 -0
  261. package/skills/dori-mode/scripts/src/launch-errors.ts +3 -0
  262. package/skills/dori-mode/scripts/src/launch-finished.ts +217 -0
  263. package/skills/dori-mode/scripts/src/launch-footer.ts +127 -0
  264. package/skills/dori-mode/scripts/src/launch-generated.ts +46 -0
  265. package/skills/dori-mode/scripts/src/launch-headless.ts +114 -0
  266. package/skills/dori-mode/scripts/src/launch-input.ts +54 -0
  267. package/skills/dori-mode/scripts/src/launch-model.ts +156 -0
  268. package/skills/dori-mode/scripts/src/launch-queue-store.ts +90 -0
  269. package/skills/dori-mode/scripts/src/launch-queue.ts +237 -0
  270. package/skills/dori-mode/scripts/src/launch-selection.ts +34 -0
  271. package/skills/dori-mode/scripts/src/launch-session.ts +248 -0
  272. package/skills/dori-mode/scripts/src/launch-template.ts +41 -0
  273. package/skills/dori-mode/scripts/src/launch.ts +250 -0
  274. package/skills/dori-mode/scripts/src/lessons.ts +202 -0
  275. package/skills/dori-mode/scripts/src/lifecycle-session.ts +114 -0
  276. package/skills/dori-mode/scripts/src/messenger/discord-ask-mailbox.ts +250 -0
  277. package/skills/dori-mode/scripts/src/messenger/discord-ask-receiver.ts +242 -0
  278. package/skills/dori-mode/scripts/src/messenger/discord-channels.ts +200 -0
  279. package/skills/dori-mode/scripts/src/messenger/discord-gateway.ts +250 -0
  280. package/skills/dori-mode/scripts/src/messenger/discord-inbound-api.ts +235 -0
  281. package/skills/dori-mode/scripts/src/messenger/discord-inbound-context.ts +107 -0
  282. package/skills/dori-mode/scripts/src/messenger/discord-inbound-database.ts +43 -0
  283. package/skills/dori-mode/scripts/src/messenger/discord-inbound-env.ts +26 -0
  284. package/skills/dori-mode/scripts/src/messenger/discord-inbound-identity.ts +23 -0
  285. package/skills/dori-mode/scripts/src/messenger/discord-inbound-live.ts +187 -0
  286. package/skills/dori-mode/scripts/src/messenger/discord-inbound-queue.ts +235 -0
  287. package/skills/dori-mode/scripts/src/messenger/discord-inbound-state.ts +44 -0
  288. package/skills/dori-mode/scripts/src/messenger/discord-inbound-thread-admission.ts +155 -0
  289. package/skills/dori-mode/scripts/src/messenger/discord-inbound-thread-api.ts +57 -0
  290. package/skills/dori-mode/scripts/src/messenger/discord-inbound-thread-poll.ts +80 -0
  291. package/skills/dori-mode/scripts/src/messenger/discord-inbound-threads.ts +121 -0
  292. package/skills/dori-mode/scripts/src/messenger/discord-inbound.ts +220 -0
  293. package/skills/dori-mode/scripts/src/messenger/discord-lane-inbox.ts +237 -0
  294. package/skills/dori-mode/scripts/src/messenger/discord-markdown.ts +206 -0
  295. package/skills/dori-mode/scripts/src/messenger/discord-presence.ts +11 -0
  296. package/skills/dori-mode/scripts/src/messenger/discord-response.ts +68 -0
  297. package/skills/dori-mode/scripts/src/messenger/discord-source-fingerprint.ts +40 -0
  298. package/skills/dori-mode/scripts/src/messenger/discord.ts +247 -0
  299. package/skills/dori-mode/scripts/src/messenger/head-admission-state.ts +159 -0
  300. package/skills/dori-mode/scripts/src/messenger/head-admission.ts +145 -0
  301. package/skills/dori-mode/scripts/src/messenger/http.ts +174 -0
  302. package/skills/dori-mode/scripts/src/messenger/private-state-file.ts +103 -0
  303. package/skills/dori-mode/scripts/src/messenger/recall-discord.ts +62 -0
  304. package/skills/dori-mode/scripts/src/messenger/recall-ledger.ts +250 -0
  305. package/skills/dori-mode/scripts/src/messenger/recall-telegram.ts +53 -0
  306. package/skills/dori-mode/scripts/src/messenger/recall-text.ts +235 -0
  307. package/skills/dori-mode/scripts/src/messenger/slack-inbound.ts +140 -0
  308. package/skills/dori-mode/scripts/src/messenger/slack-presence.ts +56 -0
  309. package/skills/dori-mode/scripts/src/messenger/slack.ts +172 -0
  310. package/skills/dori-mode/scripts/src/messenger/split.ts +92 -0
  311. package/skills/dori-mode/scripts/src/messenger/telegram-cursor-error.ts +2 -0
  312. package/skills/dori-mode/scripts/src/messenger/telegram-inbound-state.ts +73 -0
  313. package/skills/dori-mode/scripts/src/messenger/telegram-inbound-update.ts +104 -0
  314. package/skills/dori-mode/scripts/src/messenger/telegram-inbound-win32-ffi.ts +89 -0
  315. package/skills/dori-mode/scripts/src/messenger/telegram-inbound-win32-native.ts +243 -0
  316. package/skills/dori-mode/scripts/src/messenger/telegram-inbound-win32-policy.ts +79 -0
  317. package/skills/dori-mode/scripts/src/messenger/telegram-inbound-win32-store.ts +247 -0
  318. package/skills/dori-mode/scripts/src/messenger/telegram-inbound.ts +204 -0
  319. package/skills/dori-mode/scripts/src/messenger/telegram-lag.ts +144 -0
  320. package/skills/dori-mode/scripts/src/messenger/telegram-line.ts +11 -0
  321. package/skills/dori-mode/scripts/src/messenger/telegram.ts +214 -0
  322. package/skills/dori-mode/scripts/src/messenger/thread-ledger.ts +211 -0
  323. package/skills/dori-mode/scripts/src/messenger/typing.ts +19 -0
  324. package/skills/dori-mode/scripts/src/messenger/voice.ts +247 -0
  325. package/skills/dori-mode/scripts/src/monitor-command.ts +241 -0
  326. package/skills/dori-mode/scripts/src/monitor-dori.ts +162 -0
  327. package/skills/dori-mode/scripts/src/monitor-launchers.ts +145 -0
  328. package/skills/dori-mode/scripts/src/monitor-presets.ts +100 -0
  329. package/skills/dori-mode/scripts/src/monitor-syntax.ts +188 -0
  330. package/skills/dori-mode/scripts/src/native-close-process.ts +43 -0
  331. package/skills/dori-mode/scripts/src/native-close.ts +221 -0
  332. package/skills/dori-mode/scripts/src/owes-file.ts +54 -0
  333. package/skills/dori-mode/scripts/src/owes-writer.ts +35 -0
  334. package/skills/dori-mode/scripts/src/owes.ts +243 -0
  335. package/skills/dori-mode/scripts/src/park.ts +136 -0
  336. package/skills/dori-mode/scripts/src/pause.ts +238 -0
  337. package/skills/dori-mode/scripts/src/pr-watch-fetch.ts +250 -0
  338. package/skills/dori-mode/scripts/src/pr-watch-tick.ts +184 -0
  339. package/skills/dori-mode/scripts/src/pr-watch.ts +225 -0
  340. package/skills/dori-mode/scripts/src/quota.ts +245 -0
  341. package/skills/dori-mode/scripts/src/reconcile.ts +26 -0
  342. package/skills/dori-mode/scripts/src/registry.ts +250 -0
  343. package/skills/dori-mode/scripts/src/remote-launch.ts +223 -0
  344. package/skills/dori-mode/scripts/src/remote-records.ts +73 -0
  345. package/skills/dori-mode/scripts/src/remote-worker.ts +200 -0
  346. package/skills/dori-mode/scripts/src/reopen.ts +240 -0
  347. package/skills/dori-mode/scripts/src/report-activity.ts +48 -0
  348. package/skills/dori-mode/scripts/src/report-delivery.ts +26 -0
  349. package/skills/dori-mode/scripts/src/report-events.ts +79 -0
  350. package/skills/dori-mode/scripts/src/reports.ts +246 -0
  351. package/skills/dori-mode/scripts/src/request-identity.ts +74 -0
  352. package/skills/dori-mode/scripts/src/routing.ts +17 -0
  353. package/skills/dori-mode/scripts/src/run.ts +198 -0
  354. package/skills/dori-mode/scripts/src/schedule-delivery.ts +79 -0
  355. package/skills/dori-mode/scripts/src/schedule-ownership.ts +27 -0
  356. package/skills/dori-mode/scripts/src/schedule-store.ts +139 -0
  357. package/skills/dori-mode/scripts/src/schedule-systemd.ts +71 -0
  358. package/skills/dori-mode/scripts/src/schedule-types.ts +204 -0
  359. package/skills/dori-mode/scripts/src/schedule-view.ts +53 -0
  360. package/skills/dori-mode/scripts/src/scheduler.ts +198 -0
  361. package/skills/dori-mode/scripts/src/session-id-headless.ts +44 -0
  362. package/skills/dori-mode/scripts/src/session-id.ts +243 -0
  363. package/skills/dori-mode/scripts/src/sessions.ts +176 -0
  364. package/skills/dori-mode/scripts/src/signals-parse.ts +170 -0
  365. package/skills/dori-mode/scripts/src/signals.ts +150 -0
  366. package/skills/dori-mode/scripts/src/slack-token.ts +226 -0
  367. package/skills/dori-mode/scripts/src/startup-screen.ts +108 -0
  368. package/skills/dori-mode/scripts/src/status-registry.ts +69 -0
  369. package/skills/dori-mode/scripts/src/status-render.ts +98 -0
  370. package/skills/dori-mode/scripts/src/status.ts +210 -0
  371. package/skills/dori-mode/scripts/src/supervision-activity.ts +3 -0
  372. package/skills/dori-mode/scripts/src/supervision-config.ts +55 -0
  373. package/skills/dori-mode/scripts/src/supervision-cost.ts +101 -0
  374. package/skills/dori-mode/scripts/src/supervision-evidence-state.ts +246 -0
  375. package/skills/dori-mode/scripts/src/supervision-git.ts +158 -0
  376. package/skills/dori-mode/scripts/src/supervision-observe.ts +208 -0
  377. package/skills/dori-mode/scripts/src/supervision-verdict.ts +243 -0
  378. package/skills/dori-mode/scripts/src/supervision.ts +163 -0
  379. package/skills/dori-mode/scripts/src/sync.ts +134 -0
  380. package/skills/dori-mode/scripts/src/tell.ts +158 -0
  381. package/skills/dori-mode/scripts/src/thread-groups.ts +117 -0
  382. package/skills/dori-mode/scripts/src/thread-status.ts +25 -0
  383. package/skills/dori-mode/scripts/src/tool-evidence.ts +230 -0
  384. package/skills/dori-mode/scripts/src/tool-fingerprint.ts +166 -0
  385. package/skills/dori-mode/scripts/src/usage-file.ts +59 -0
  386. package/skills/dori-mode/scripts/src/usage-index.ts +85 -0
  387. package/skills/dori-mode/scripts/src/usage-omp.ts +174 -0
  388. package/skills/dori-mode/scripts/src/usage-options.ts +28 -0
  389. package/skills/dori-mode/scripts/src/usage-session.ts +248 -0
  390. package/skills/dori-mode/scripts/src/usage-tree.ts +226 -0
  391. package/skills/dori-mode/scripts/src/verify-pr-check.ts +164 -0
  392. package/skills/dori-mode/scripts/src/verify-pr.ts +128 -0
  393. package/skills/dori-mode/scripts/src/voice/assistant.ts +129 -0
  394. package/skills/dori-mode/scripts/src/voice/audio.ts +184 -0
  395. package/skills/dori-mode/scripts/src/voice/backend.ts +230 -0
  396. package/skills/dori-mode/scripts/src/voice/commentary.ts +155 -0
  397. package/skills/dori-mode/scripts/src/voice/discord-events.ts +36 -0
  398. package/skills/dori-mode/scripts/src/voice/discord-link.ts +90 -0
  399. package/skills/dori-mode/scripts/src/voice/discord-receive.ts +178 -0
  400. package/skills/dori-mode/scripts/src/voice/discord-session.ts +249 -0
  401. package/skills/dori-mode/scripts/src/voice/discord.ts +152 -0
  402. package/skills/dori-mode/scripts/src/voice/facts.ts +27 -0
  403. package/skills/dori-mode/scripts/src/voice/prompts.ts +117 -0
  404. package/skills/dori-mode/scripts/src/voice/provider.ts +158 -0
  405. package/skills/dori-mode/scripts/src/voice/relay.ts +199 -0
  406. package/skills/dori-mode/scripts/src/voice/replies.ts +139 -0
  407. package/skills/dori-mode/scripts/src/voice/session.ts +249 -0
  408. package/skills/dori-mode/scripts/src/voice/settings.ts +72 -0
  409. package/skills/dori-mode/scripts/src/voice/status.ts +75 -0
  410. package/skills/dori-mode/scripts/src/voice/summary.ts +68 -0
  411. package/skills/dori-mode/scripts/src/voice/tools.ts +75 -0
  412. package/skills/dori-mode/scripts/src/voice/types.ts +116 -0
  413. package/skills/dori-mode/scripts/src/voice/usage.ts +156 -0
  414. package/skills/dori-mode/scripts/src/worklog-render.ts +53 -0
  415. package/skills/dori-mode/scripts/src/worklog.ts +250 -0
  416. package/skills/dori-mode/scripts/test/artifact-cli.test.ts +199 -0
  417. package/skills/dori-mode/scripts/test/artifact-close.test.ts +247 -0
  418. package/skills/dori-mode/scripts/test/artifact-config.test.ts +53 -0
  419. package/skills/dori-mode/scripts/test/artifact-files.test.ts +135 -0
  420. package/skills/dori-mode/scripts/test/artifact-fixture.ts +37 -0
  421. package/skills/dori-mode/scripts/test/artifacts.test.ts +180 -0
  422. package/skills/dori-mode/scripts/test/audio-samples.ts +93 -0
  423. package/skills/dori-mode/scripts/test/board.test.ts +233 -0
  424. package/skills/dori-mode/scripts/test/boot-checks.test.ts +148 -0
  425. package/skills/dori-mode/scripts/test/boot-decisions.test.ts +106 -0
  426. package/skills/dori-mode/scripts/test/boot-journals.test.ts +138 -0
  427. package/skills/dori-mode/scripts/test/boot-metadata.test.ts +193 -0
  428. package/skills/dori-mode/scripts/test/boot-monitor-matrix.test.ts +249 -0
  429. package/skills/dori-mode/scripts/test/boot-monitor-words.test.ts +202 -0
  430. package/skills/dori-mode/scripts/test/boot-monitors.test.ts +246 -0
  431. package/skills/dori-mode/scripts/test/boot-schedules.test.ts +161 -0
  432. package/skills/dori-mode/scripts/test/boot-slack.test.ts +159 -0
  433. package/skills/dori-mode/scripts/test/boot-worklog.test.ts +146 -0
  434. package/skills/dori-mode/scripts/test/boot.test.ts +233 -0
  435. package/skills/dori-mode/scripts/test/cgroup-memory.test.ts +189 -0
  436. package/skills/dori-mode/scripts/test/checkpoints-lock.test.ts +180 -0
  437. package/skills/dori-mode/scripts/test/checkpoints.test.ts +154 -0
  438. package/skills/dori-mode/scripts/test/cli-harness.test.ts +70 -0
  439. package/skills/dori-mode/scripts/test/cli-loading.test.ts +220 -0
  440. package/skills/dori-mode/scripts/test/config.test.ts +141 -0
  441. package/skills/dori-mode/scripts/test/dead-panes-retention.test.ts +188 -0
  442. package/skills/dori-mode/scripts/test/decisions-authority-cli.test.ts +250 -0
  443. package/skills/dori-mode/scripts/test/decisions-authority.test.ts +226 -0
  444. package/skills/dori-mode/scripts/test/decisions-flags.test.ts +128 -0
  445. package/skills/dori-mode/scripts/test/decisions-race.test.ts +159 -0
  446. package/skills/dori-mode/scripts/test/decisions.test.ts +246 -0
  447. package/skills/dori-mode/scripts/test/discord-api-base.test.ts +121 -0
  448. package/skills/dori-mode/scripts/test/discord-ask-receiver.test.ts +220 -0
  449. package/skills/dori-mode/scripts/test/discord-channels.test.ts +180 -0
  450. package/skills/dori-mode/scripts/test/discord-cli.test.ts +210 -0
  451. package/skills/dori-mode/scripts/test/discord-fakes.ts +191 -0
  452. package/skills/dori-mode/scripts/test/discord-head-admission.test.ts +111 -0
  453. package/skills/dori-mode/scripts/test/discord-head-cancel.test.ts +140 -0
  454. package/skills/dori-mode/scripts/test/discord-head-queued.test.ts +114 -0
  455. package/skills/dori-mode/scripts/test/discord-head-recovery.test.ts +237 -0
  456. package/skills/dori-mode/scripts/test/discord-head-thread-recovery.test.ts +95 -0
  457. package/skills/dori-mode/scripts/test/discord-inbound-ack-index.test.ts +61 -0
  458. package/skills/dori-mode/scripts/test/discord-inbound-activity-errors.test.ts +77 -0
  459. package/skills/dori-mode/scripts/test/discord-inbound-activity.test.ts +250 -0
  460. package/skills/dori-mode/scripts/test/discord-inbound-backlog-context.test.ts +188 -0
  461. package/skills/dori-mode/scripts/test/discord-inbound-backlog.test.ts +228 -0
  462. package/skills/dori-mode/scripts/test/discord-inbound-channels.test.ts +182 -0
  463. package/skills/dori-mode/scripts/test/discord-inbound-checkpoints.test.ts +208 -0
  464. package/skills/dori-mode/scripts/test/discord-inbound-cli.test.ts +189 -0
  465. package/skills/dori-mode/scripts/test/discord-inbound-close-route.test.ts +177 -0
  466. package/skills/dori-mode/scripts/test/discord-inbound-cursor-failures.test.ts +234 -0
  467. package/skills/dori-mode/scripts/test/discord-inbound-errors.test.ts +95 -0
  468. package/skills/dori-mode/scripts/test/discord-inbound-fakes.ts +161 -0
  469. package/skills/dori-mode/scripts/test/discord-inbound-ledger-close.test.ts +140 -0
  470. package/skills/dori-mode/scripts/test/discord-inbound-lifecycle.test.ts +112 -0
  471. package/skills/dori-mode/scripts/test/discord-inbound-live-async.test.ts +45 -0
  472. package/skills/dori-mode/scripts/test/discord-inbound-live-fakes.ts +206 -0
  473. package/skills/dori-mode/scripts/test/discord-inbound-live.test.ts +239 -0
  474. package/skills/dori-mode/scripts/test/discord-inbound-media.test.ts +173 -0
  475. package/skills/dori-mode/scripts/test/discord-inbound-memory-queue.ts +109 -0
  476. package/skills/dori-mode/scripts/test/discord-inbound-queue-cli.test.ts +200 -0
  477. package/skills/dori-mode/scripts/test/discord-inbound-queue.test.ts +207 -0
  478. package/skills/dori-mode/scripts/test/discord-inbound-queued-failures.test.ts +188 -0
  479. package/skills/dori-mode/scripts/test/discord-inbound-queued-receipts.test.ts +203 -0
  480. package/skills/dori-mode/scripts/test/discord-inbound-queued-recovery.test.ts +162 -0
  481. package/skills/dori-mode/scripts/test/discord-inbound-quiet-composition.test.ts +243 -0
  482. package/skills/dori-mode/scripts/test/discord-inbound-quiet.test.ts +173 -0
  483. package/skills/dori-mode/scripts/test/discord-inbound-state.test.ts +146 -0
  484. package/skills/dori-mode/scripts/test/discord-inbound-thread-admission.test.ts +161 -0
  485. package/skills/dori-mode/scripts/test/discord-inbound-thread-cancel.test.ts +225 -0
  486. package/skills/dori-mode/scripts/test/discord-inbound-thread-lifecycle.test.ts +156 -0
  487. package/skills/dori-mode/scripts/test/discord-inbound-thread-recovery.test.ts +241 -0
  488. package/skills/dori-mode/scripts/test/discord-inbound-threads.test.ts +212 -0
  489. package/skills/dori-mode/scripts/test/discord-inbound.test.ts +190 -0
  490. package/skills/dori-mode/scripts/test/discord-lane-inbox.test.ts +250 -0
  491. package/skills/dori-mode/scripts/test/discord-lane-monitor.test.ts +184 -0
  492. package/skills/dori-mode/scripts/test/discord-lane-wake-fixture.ts +178 -0
  493. package/skills/dori-mode/scripts/test/discord-lane-wake.test.ts +204 -0
  494. package/skills/dori-mode/scripts/test/discord-markdown.test.ts +225 -0
  495. package/skills/dori-mode/scripts/test/discord-presence-fakes.ts +97 -0
  496. package/skills/dori-mode/scripts/test/discord-presence-recovery.test.ts +218 -0
  497. package/skills/dori-mode/scripts/test/discord-presence.test.ts +174 -0
  498. package/skills/dori-mode/scripts/test/discord-purpose-receipts.test.ts +138 -0
  499. package/skills/dori-mode/scripts/test/discord-purpose-receiver.test.ts +102 -0
  500. package/skills/dori-mode/scripts/test/discord-purpose-source.test.ts +245 -0
  501. package/skills/dori-mode/scripts/test/discord-reply-binding.test.ts +156 -0
  502. package/skills/dori-mode/scripts/test/discord-send.test.ts +234 -0
  503. package/skills/dori-mode/scripts/test/discord-source-fingerprint.test.ts +66 -0
  504. package/skills/dori-mode/scripts/test/discord-split.test.ts +124 -0
  505. package/skills/dori-mode/scripts/test/discord-tables-cli.test.ts +173 -0
  506. package/skills/dori-mode/scripts/test/discord-transcribe-cli.test.ts +61 -0
  507. package/skills/dori-mode/scripts/test/doctor-cli.test.ts +205 -0
  508. package/skills/dori-mode/scripts/test/doctor-findings.test.ts +246 -0
  509. package/skills/dori-mode/scripts/test/doctor-metadata.test.ts +108 -0
  510. package/skills/dori-mode/scripts/test/doctor-runtime.test.ts +156 -0
  511. package/skills/dori-mode/scripts/test/doctor-supervision.test.ts +175 -0
  512. package/skills/dori-mode/scripts/test/doctor.test.ts +214 -0
  513. package/skills/dori-mode/scripts/test/done-flow.test.ts +247 -0
  514. package/skills/dori-mode/scripts/test/dori-monitor-vocabulary.test.ts +130 -0
  515. package/skills/dori-mode/scripts/test/eval-evidence.test.ts +164 -0
  516. package/skills/dori-mode/scripts/test/evidence-cli.test.ts +107 -0
  517. package/skills/dori-mode/scripts/test/evidence-order.test.ts +129 -0
  518. package/skills/dori-mode/scripts/test/evidence-sequence-fixture.ts +177 -0
  519. package/skills/dori-mode/scripts/test/evidence-sequence-race.test.ts +136 -0
  520. package/skills/dori-mode/scripts/test/evidence-sequence-scan.test.ts +42 -0
  521. package/skills/dori-mode/scripts/test/evidence-sequence.test.ts +221 -0
  522. package/skills/dori-mode/scripts/test/evidence.test.ts +235 -0
  523. package/skills/dori-mode/scripts/test/fakes.ts +228 -0
  524. package/skills/dori-mode/scripts/test/final-report.test.ts +63 -0
  525. package/skills/dori-mode/scripts/test/fixtures/verify-pr/browser-test-only.json +67 -0
  526. package/skills/dori-mode/scripts/test/fixtures/verify-pr/fix-then-untested-copy-fix.json +120 -0
  527. package/skills/dori-mode/scripts/test/fixtures/verify-pr/fix-with-own-ui-test.json +57 -0
  528. package/skills/dori-mode/scripts/test/fixtures/verify-pr/fixture-file-is-not-a-test.json +190 -0
  529. package/skills/dori-mode/scripts/test/fixtures/verify-pr/follow-up-fixes-without-tests.json +150 -0
  530. package/skills/dori-mode/scripts/test/fixtures/verify-pr/release-chore.json +83 -0
  531. package/skills/dori-mode/scripts/test/fixtures/verify-pr/source-fix-without-tests.json +39 -0
  532. package/skills/dori-mode/scripts/test/fixtures/verify-pr/tests-in-later-commits.json +274 -0
  533. package/skills/dori-mode/scripts/test/fixtures/verify-pr/wrong-commit-email.json +57 -0
  534. package/skills/dori-mode/scripts/test/freshness-git-timeout.fixture.ts +113 -0
  535. package/skills/dori-mode/scripts/test/freshness-git-timeout.test.ts +156 -0
  536. package/skills/dori-mode/scripts/test/freshness-policy.test.ts +250 -0
  537. package/skills/dori-mode/scripts/test/freshness-receipts.test.ts +222 -0
  538. package/skills/dori-mode/scripts/test/freshness.test.ts +167 -0
  539. package/skills/dori-mode/scripts/test/hardening-ceilings.test.ts +142 -0
  540. package/skills/dori-mode/scripts/test/hardening-cost.test.ts +134 -0
  541. package/skills/dori-mode/scripts/test/hardening.test.ts +120 -0
  542. package/skills/dori-mode/scripts/test/hc-runner.ts +86 -0
  543. package/skills/dori-mode/scripts/test/host-cgroup.test.ts +185 -0
  544. package/skills/dori-mode/scripts/test/host-sampling.test.ts +105 -0
  545. package/skills/dori-mode/scripts/test/inbound-activity-cli.test.ts +64 -0
  546. package/skills/dori-mode/scripts/test/lane-messenger-env.test.ts +98 -0
  547. package/skills/dori-mode/scripts/test/lane-policy-cli.test.ts +184 -0
  548. package/skills/dori-mode/scripts/test/lane-policy-launch.test.ts +168 -0
  549. package/skills/dori-mode/scripts/test/lane-policy.test.ts +197 -0
  550. package/skills/dori-mode/scripts/test/lane-race.test.ts +247 -0
  551. package/skills/dori-mode/scripts/test/launch-brief-restore.test.ts +94 -0
  552. package/skills/dori-mode/scripts/test/launch-brief.test.ts +234 -0
  553. package/skills/dori-mode/scripts/test/launch-context.test.ts +97 -0
  554. package/skills/dori-mode/scripts/test/launch-finished.test.ts +60 -0
  555. package/skills/dori-mode/scripts/test/launch-generated-recovery.test.ts +218 -0
  556. package/skills/dori-mode/scripts/test/launch-goal-proof.test.ts +69 -0
  557. package/skills/dori-mode/scripts/test/launch-goal.test.ts +89 -0
  558. package/skills/dori-mode/scripts/test/launch-model-compat.test.ts +111 -0
  559. package/skills/dori-mode/scripts/test/launch-model.test.ts +176 -0
  560. package/skills/dori-mode/scripts/test/launch-queue-cwd.test.ts +105 -0
  561. package/skills/dori-mode/scripts/test/launch-queue-fixture.ts +109 -0
  562. package/skills/dori-mode/scripts/test/launch-queue-races.test.ts +226 -0
  563. package/skills/dori-mode/scripts/test/launch-queue.test.ts +150 -0
  564. package/skills/dori-mode/scripts/test/launch-review.test.ts +240 -0
  565. package/skills/dori-mode/scripts/test/launch-selection.test.ts +202 -0
  566. package/skills/dori-mode/scripts/test/launch-serialization.test.ts +62 -0
  567. package/skills/dori-mode/scripts/test/launch-startup-wait.test.ts +220 -0
  568. package/skills/dori-mode/scripts/test/launch-template.test.ts +248 -0
  569. package/skills/dori-mode/scripts/test/lesson-cli-global.test.ts +214 -0
  570. package/skills/dori-mode/scripts/test/lesson-cli.test.ts +168 -0
  571. package/skills/dori-mode/scripts/test/lesson-flow.test.ts +226 -0
  572. package/skills/dori-mode/scripts/test/lessons.test.ts +249 -0
  573. package/skills/dori-mode/scripts/test/lifecycle-bound-readback.test.ts +144 -0
  574. package/skills/dori-mode/scripts/test/lifecycle-cli.test.ts +77 -0
  575. package/skills/dori-mode/scripts/test/lifecycle-close-hc-guard.test.ts +170 -0
  576. package/skills/dori-mode/scripts/test/lifecycle-close-legacy.test.ts +155 -0
  577. package/skills/dori-mode/scripts/test/lifecycle-close-readiness.test.ts +190 -0
  578. package/skills/dori-mode/scripts/test/lifecycle-close-recovery.test.ts +224 -0
  579. package/skills/dori-mode/scripts/test/lifecycle-close-retired.test.ts +93 -0
  580. package/skills/dori-mode/scripts/test/lifecycle-delivery-peer.test.ts +120 -0
  581. package/skills/dori-mode/scripts/test/lifecycle-fixture.ts +231 -0
  582. package/skills/dori-mode/scripts/test/lifecycle-generation-repair.test.ts +196 -0
  583. package/skills/dori-mode/scripts/test/lifecycle-process-guard.test.ts +128 -0
  584. package/skills/dori-mode/scripts/test/lifecycle-process-identity.test.ts +142 -0
  585. package/skills/dori-mode/scripts/test/lifecycle-quiescence-gap.test.ts +152 -0
  586. package/skills/dori-mode/scripts/test/lifecycle-recovery-repair.test.ts +249 -0
  587. package/skills/dori-mode/scripts/test/lifecycle-review.test.ts +189 -0
  588. package/skills/dori-mode/scripts/test/lifecycle-session-header.test.ts +79 -0
  589. package/skills/dori-mode/scripts/test/lifecycle-terminal-repair.test.ts +237 -0
  590. package/skills/dori-mode/scripts/test/lifecycle.test.ts +198 -0
  591. package/skills/dori-mode/scripts/test/loop-flag.test.ts +58 -0
  592. package/skills/dori-mode/scripts/test/messenger-certainty.test.ts +196 -0
  593. package/skills/dori-mode/scripts/test/messenger-local-receipt.test.ts +71 -0
  594. package/skills/dori-mode/scripts/test/messenger-presence.test.ts +129 -0
  595. package/skills/dori-mode/scripts/test/messenger-receipt-boundaries.test.ts +102 -0
  596. package/skills/dori-mode/scripts/test/messenger-reconnect.test.ts +96 -0
  597. package/skills/dori-mode/scripts/test/messenger.test.ts +220 -0
  598. package/skills/dori-mode/scripts/test/omp-launch-fixture.ts +163 -0
  599. package/skills/dori-mode/scripts/test/omp-launch.test.ts +123 -0
  600. package/skills/dori-mode/scripts/test/omp-pause.test.ts +139 -0
  601. package/skills/dori-mode/scripts/test/omp-session.test.ts +250 -0
  602. package/skills/dori-mode/scripts/test/omp-source-session.test.ts +243 -0
  603. package/skills/dori-mode/scripts/test/owes-concurrency.test.ts +178 -0
  604. package/skills/dori-mode/scripts/test/owes-recovery.test.ts +67 -0
  605. package/skills/dori-mode/scripts/test/owes-reminder-cli.test.ts +76 -0
  606. package/skills/dori-mode/scripts/test/owes-request.test.ts +246 -0
  607. package/skills/dori-mode/scripts/test/owes.test.ts +236 -0
  608. package/skills/dori-mode/scripts/test/pause.test.ts +204 -0
  609. package/skills/dori-mode/scripts/test/post-failed.test.ts +63 -0
  610. package/skills/dori-mode/scripts/test/pr-watch-fakes.ts +121 -0
  611. package/skills/dori-mode/scripts/test/pr-watch-lifecycle.test.ts +236 -0
  612. package/skills/dori-mode/scripts/test/pr-watch-track.test.ts +192 -0
  613. package/skills/dori-mode/scripts/test/pr-watch.test.ts +185 -0
  614. package/skills/dori-mode/scripts/test/quota.test.ts +250 -0
  615. package/skills/dori-mode/scripts/test/recall-cli.test.ts +157 -0
  616. package/skills/dori-mode/scripts/test/recall-ledger.test.ts +240 -0
  617. package/skills/dori-mode/scripts/test/recall-text.test.ts +129 -0
  618. package/skills/dori-mode/scripts/test/record-discord-gateway.ts +40 -0
  619. package/skills/dori-mode/scripts/test/record-discord-inbound.ts +83 -0
  620. package/skills/dori-mode/scripts/test/record-discord.ts +73 -0
  621. package/skills/dori-mode/scripts/test/record-fetch.ts +34 -0
  622. package/skills/dori-mode/scripts/test/record-gateway.ts +132 -0
  623. package/skills/dori-mode/scripts/test/record-inbound-activity-failure.ts +27 -0
  624. package/skills/dori-mode/scripts/test/record-slack-activity-backlog.ts +42 -0
  625. package/skills/dori-mode/scripts/test/record-telegram-epoch.ts +41 -0
  626. package/skills/dori-mode/scripts/test/record-telegram-startup.ts +49 -0
  627. package/skills/dori-mode/scripts/test/registry-read-removal.test.ts +60 -0
  628. package/skills/dori-mode/scripts/test/registry-transition.test.ts +55 -0
  629. package/skills/dori-mode/scripts/test/relayed-cli.test.ts +128 -0
  630. package/skills/dori-mode/scripts/test/reports-freshness.test.ts +206 -0
  631. package/skills/dori-mode/scripts/test/reports.test.ts +236 -0
  632. package/skills/dori-mode/scripts/test/repository-env.test.ts +250 -0
  633. package/skills/dori-mode/scripts/test/request-corruption.test.ts +183 -0
  634. package/skills/dori-mode/scripts/test/request-delivery.test.ts +230 -0
  635. package/skills/dori-mode/scripts/test/request-fixtures.ts +48 -0
  636. package/skills/dori-mode/scripts/test/request-journal.test.ts +208 -0
  637. package/skills/dori-mode/scripts/test/request-launch-env.test.ts +45 -0
  638. package/skills/dori-mode/scripts/test/request-launch-generation.test.ts +34 -0
  639. package/skills/dori-mode/scripts/test/request-launch-input.test.ts +111 -0
  640. package/skills/dori-mode/scripts/test/request-launch.test.ts +242 -0
  641. package/skills/dori-mode/scripts/test/request-lifecycle.test.ts +228 -0
  642. package/skills/dori-mode/scripts/test/request-origin-cli.test.ts +118 -0
  643. package/skills/dori-mode/scripts/test/reserved-key.test.ts +92 -0
  644. package/skills/dori-mode/scripts/test/routing.test.ts +48 -0
  645. package/skills/dori-mode/scripts/test/runtime-import.test.ts +17 -0
  646. package/skills/dori-mode/scripts/test/schedule-cli.test.ts +229 -0
  647. package/skills/dori-mode/scripts/test/schedule-delivery.test.ts +239 -0
  648. package/skills/dori-mode/scripts/test/schedule-post-budget.test.ts +78 -0
  649. package/skills/dori-mode/scripts/test/schedule-state.test.ts +125 -0
  650. package/skills/dori-mode/scripts/test/scheduler-delivery-state.test.ts +166 -0
  651. package/skills/dori-mode/scripts/test/scheduler.test.ts +234 -0
  652. package/skills/dori-mode/scripts/test/send-cli.test.ts +90 -0
  653. package/skills/dori-mode/scripts/test/session-id.test.ts +57 -0
  654. package/skills/dori-mode/scripts/test/session-observation-actions.test.ts +105 -0
  655. package/skills/dori-mode/scripts/test/session-observation.test.ts +129 -0
  656. package/skills/dori-mode/scripts/test/sessions.test.ts +163 -0
  657. package/skills/dori-mode/scripts/test/signals.test.ts +157 -0
  658. package/skills/dori-mode/scripts/test/slack-activity-backlog.test.ts +62 -0
  659. package/skills/dori-mode/scripts/test/slack-cli.test.ts +249 -0
  660. package/skills/dori-mode/scripts/test/slack-cursor-batch.test.ts +146 -0
  661. package/skills/dori-mode/scripts/test/slack-inbound.test.ts +226 -0
  662. package/skills/dori-mode/scripts/test/slack-route-fakes.ts +47 -0
  663. package/skills/dori-mode/scripts/test/slack-route-inbound.test.ts +127 -0
  664. package/skills/dori-mode/scripts/test/slack-route.test.ts +141 -0
  665. package/skills/dori-mode/scripts/test/slack-token-home.test.ts +87 -0
  666. package/skills/dori-mode/scripts/test/slack-token-read.test.ts +165 -0
  667. package/skills/dori-mode/scripts/test/slack-token.test.ts +226 -0
  668. package/skills/dori-mode/scripts/test/startup-screen.test.ts +182 -0
  669. package/skills/dori-mode/scripts/test/status-boundaries.test.ts +167 -0
  670. package/skills/dori-mode/scripts/test/status-cli.test.ts +207 -0
  671. package/skills/dori-mode/scripts/test/status-review.test.ts +168 -0
  672. package/skills/dori-mode/scripts/test/status.test.ts +248 -0
  673. package/skills/dori-mode/scripts/test/supervision-budget.test.ts +216 -0
  674. package/skills/dori-mode/scripts/test/supervision-confirmation.test.ts +199 -0
  675. package/skills/dori-mode/scripts/test/supervision-coverage.fixture.ts +92 -0
  676. package/skills/dori-mode/scripts/test/supervision-coverage.test.ts +193 -0
  677. package/skills/dori-mode/scripts/test/supervision-delivery.test.ts +144 -0
  678. package/skills/dori-mode/scripts/test/supervision-errors.test.ts +180 -0
  679. package/skills/dori-mode/scripts/test/supervision-evidence-boundary.test.ts +106 -0
  680. package/skills/dori-mode/scripts/test/supervision-evidence-review.test.ts +248 -0
  681. package/skills/dori-mode/scripts/test/supervision-explicit-activity.test.ts +217 -0
  682. package/skills/dori-mode/scripts/test/supervision-freshness-race.test.ts +105 -0
  683. package/skills/dori-mode/scripts/test/supervision-git-boundaries.test.ts +211 -0
  684. package/skills/dori-mode/scripts/test/supervision-git-fixtures.ts +128 -0
  685. package/skills/dori-mode/scripts/test/supervision-git.test.ts +161 -0
  686. package/skills/dori-mode/scripts/test/supervision-integration.fixture.ts +134 -0
  687. package/skills/dori-mode/scripts/test/supervision-integration.test.ts +178 -0
  688. package/skills/dori-mode/scripts/test/supervision-interruption.test.ts +96 -0
  689. package/skills/dori-mode/scripts/test/supervision-nested-git.test.ts +214 -0
  690. package/skills/dori-mode/scripts/test/supervision-overlap.test.ts +175 -0
  691. package/skills/dori-mode/scripts/test/supervision-path-identity.test.ts +154 -0
  692. package/skills/dori-mode/scripts/test/supervision-posting.test.ts +55 -0
  693. package/skills/dori-mode/scripts/test/supervision-recovery.test.ts +161 -0
  694. package/skills/dori-mode/scripts/test/supervision-resample-fixture.ts +60 -0
  695. package/skills/dori-mode/scripts/test/supervision-resample-repair.test.ts +229 -0
  696. package/skills/dori-mode/scripts/test/supervision-usage.test.ts +48 -0
  697. package/skills/dori-mode/scripts/test/supervision.test.ts +249 -0
  698. package/skills/dori-mode/scripts/test/sweeps-footer.test.ts +176 -0
  699. package/skills/dori-mode/scripts/test/sweeps-host.test.ts +122 -0
  700. package/skills/dori-mode/scripts/test/sweeps-launch.test.ts +226 -0
  701. package/skills/dori-mode/scripts/test/sweeps.test.ts +202 -0
  702. package/skills/dori-mode/scripts/test/sync-cache.test.ts +159 -0
  703. package/skills/dori-mode/scripts/test/sync-history.test.ts +51 -0
  704. package/skills/dori-mode/scripts/test/sync-observation.test.ts +191 -0
  705. package/skills/dori-mode/scripts/test/telegram-boundary-matrix.test.ts +97 -0
  706. package/skills/dori-mode/scripts/test/telegram-inbound-epoch-cli.test.ts +162 -0
  707. package/skills/dori-mode/scripts/test/telegram-inbound-epoch.test.ts +203 -0
  708. package/skills/dori-mode/scripts/test/telegram-inbound-fakes.ts +38 -0
  709. package/skills/dori-mode/scripts/test/telegram-inbound-loop.test.ts +235 -0
  710. package/skills/dori-mode/scripts/test/telegram-inbound-media.test.ts +195 -0
  711. package/skills/dori-mode/scripts/test/telegram-inbound-state.test.ts +61 -0
  712. package/skills/dori-mode/scripts/test/telegram-inbound-win32-token.test.ts +42 -0
  713. package/skills/dori-mode/scripts/test/telegram-inbound-win32.test.ts +228 -0
  714. package/skills/dori-mode/scripts/test/telegram-inbound.test.ts +216 -0
  715. package/skills/dori-mode/scripts/test/telegram-lag.test.ts +164 -0
  716. package/skills/dori-mode/scripts/test/telegram-line.test.ts +27 -0
  717. package/skills/dori-mode/scripts/test/telegram-send.test.ts +112 -0
  718. package/skills/dori-mode/scripts/test/telegram-startup.test.ts +240 -0
  719. package/skills/dori-mode/scripts/test/telegram-win32-fixtures.ts +51 -0
  720. package/skills/dori-mode/scripts/test/tell-fence-flow.test.ts +138 -0
  721. package/skills/dori-mode/scripts/test/tell-fence-lifecycle.test.ts +122 -0
  722. package/skills/dori-mode/scripts/test/tell-fence-monitor.test.ts +232 -0
  723. package/skills/dori-mode/scripts/test/tell-fence-process.test.ts +100 -0
  724. package/skills/dori-mode/scripts/test/tell-fence.test.ts +208 -0
  725. package/skills/dori-mode/scripts/test/tell-race.test.ts +187 -0
  726. package/skills/dori-mode/scripts/test/tell.test.ts +141 -0
  727. package/skills/dori-mode/scripts/test/thread-groups.test.ts +228 -0
  728. package/skills/dori-mode/scripts/test/thread-ledger-cli.test.ts +112 -0
  729. package/skills/dori-mode/scripts/test/thread-ledger-scope.test.ts +132 -0
  730. package/skills/dori-mode/scripts/test/thread-ledger.test.ts +102 -0
  731. package/skills/dori-mode/scripts/test/thread-status-cli.test.ts +129 -0
  732. package/skills/dori-mode/scripts/test/thread-watch.test.ts +184 -0
  733. package/skills/dori-mode/scripts/test/tool-completion.test.ts +172 -0
  734. package/skills/dori-mode/scripts/test/tool-evidence-cwd.test.ts +126 -0
  735. package/skills/dori-mode/scripts/test/tool-evidence.test.ts +209 -0
  736. package/skills/dori-mode/scripts/test/tool-fingerprint.test.ts +96 -0
  737. package/skills/dori-mode/scripts/test/transcribe-boundary.test.ts +237 -0
  738. package/skills/dori-mode/scripts/test/transcribe-stream.test.ts +66 -0
  739. package/skills/dori-mode/scripts/test/usage-cli.test.ts +154 -0
  740. package/skills/dori-mode/scripts/test/usage-close.test.ts +60 -0
  741. package/skills/dori-mode/scripts/test/usage-fakes.ts +71 -0
  742. package/skills/dori-mode/scripts/test/usage-file.test.ts +87 -0
  743. package/skills/dori-mode/scripts/test/usage-fork.test.ts +78 -0
  744. package/skills/dori-mode/scripts/test/usage-native.test.ts +178 -0
  745. package/skills/dori-mode/scripts/test/usage-omp.test.ts +142 -0
  746. package/skills/dori-mode/scripts/test/usage-provenance.test.ts +115 -0
  747. package/skills/dori-mode/scripts/test/usage-seance-history.test.ts +61 -0
  748. package/skills/dori-mode/scripts/test/usage-supervision.test.ts +75 -0
  749. package/skills/dori-mode/scripts/test/usage-tasks.test.ts +148 -0
  750. package/skills/dori-mode/scripts/test/verify-pr-github.test.ts +230 -0
  751. package/skills/dori-mode/scripts/test/verify-pr-setup.ts +95 -0
  752. package/skills/dori-mode/scripts/test/verify-pr.test.ts +216 -0
  753. package/skills/dori-mode/scripts/test/voice-audio.test.ts +101 -0
  754. package/skills/dori-mode/scripts/test/voice-backend-safety.test.ts +142 -0
  755. package/skills/dori-mode/scripts/test/voice-backend-usage.test.ts +124 -0
  756. package/skills/dori-mode/scripts/test/voice-backend.test.ts +134 -0
  757. package/skills/dori-mode/scripts/test/voice-boundaries.test.ts +119 -0
  758. package/skills/dori-mode/scripts/test/voice-commentary.test.ts +245 -0
  759. package/skills/dori-mode/scripts/test/voice-discord-contract.test.ts +85 -0
  760. package/skills/dori-mode/scripts/test/voice-discord-fakes.ts +248 -0
  761. package/skills/dori-mode/scripts/test/voice-discord-receive-library.test.ts +180 -0
  762. package/skills/dori-mode/scripts/test/voice-discord-receive.test.ts +201 -0
  763. package/skills/dori-mode/scripts/test/voice-discord-safety.test.ts +64 -0
  764. package/skills/dori-mode/scripts/test/voice-discord.test.ts +216 -0
  765. package/skills/dori-mode/scripts/test/voice-fixture.ts +81 -0
  766. package/skills/dori-mode/scripts/test/voice-gateway-resume.test.ts +193 -0
  767. package/skills/dori-mode/scripts/test/voice-live-contract.test.ts +240 -0
  768. package/skills/dori-mode/scripts/test/voice-live11.test.ts +237 -0
  769. package/skills/dori-mode/scripts/test/voice-native-output-fixture.ts +150 -0
  770. package/skills/dori-mode/scripts/test/voice-native-output.test.ts +121 -0
  771. package/skills/dori-mode/scripts/test/voice-provider.test.ts +197 -0
  772. package/skills/dori-mode/scripts/test/voice-relay.test.ts +248 -0
  773. package/skills/dori-mode/scripts/test/voice-replies-tail.test.ts +171 -0
  774. package/skills/dori-mode/scripts/test/voice-session-fixture.ts +77 -0
  775. package/skills/dori-mode/scripts/test/voice-session-safety.test.ts +171 -0
  776. package/skills/dori-mode/scripts/test/voice-session.test.ts +134 -0
  777. package/skills/dori-mode/scripts/test/voice-summary-admission.test.ts +80 -0
  778. package/skills/dori-mode/scripts/test/voice-summary-usage.test.ts +82 -0
  779. package/skills/dori-mode/scripts/test/voice-tools.test.ts +164 -0
  780. package/skills/dori-mode/scripts/test/worklog-records.test.ts +190 -0
  781. package/skills/dori-mode/scripts/test/worklog.test.ts +151 -0
  782. package/skills/dori-mode/scripts/tsconfig.json +8 -0
  783. package/src/backlog.ts +154 -0
  784. package/src/cli-args.ts +97 -0
  785. package/src/cli-lock.ts +40 -0
  786. package/src/cli-loops.ts +155 -0
  787. package/src/cli-owner.ts +79 -0
  788. package/src/cli-up.ts +88 -0
  789. package/src/cli.ts +188 -0
  790. package/src/delivery.ts +28 -0
  791. package/src/duty-inbox.ts +46 -0
  792. package/src/duty.ts +217 -0
  793. package/src/fit.ts +92 -0
  794. package/src/gate.ts +110 -0
  795. package/src/harness.ts +161 -0
  796. package/src/hooks.ts +133 -0
  797. package/src/inbox-files.ts +136 -0
  798. package/src/inbox-forward.ts +178 -0
  799. package/src/inbox-held.ts +91 -0
  800. package/src/inbox-lock.ts +79 -0
  801. package/src/inbox-spool.ts +167 -0
  802. package/src/inbox.ts +237 -0
  803. package/src/lanes.ts +181 -0
  804. package/src/lock-claim.ts +73 -0
  805. package/src/lock-list.ts +57 -0
  806. package/src/lock-owner.ts +159 -0
  807. package/src/lock-queue.ts +158 -0
  808. package/src/lock.ts +106 -0
  809. package/src/loop-audit.ts +44 -0
  810. package/src/loop-lock.ts +101 -0
  811. package/src/loop.ts +222 -0
  812. package/src/migrate-brief.ts +47 -0
  813. package/src/migrate-capture.ts +89 -0
  814. package/src/migrate-inbox.ts +111 -0
  815. package/src/migrate-swap.ts +101 -0
  816. package/src/migrate.ts +210 -0
  817. package/src/owner-check.ts +115 -0
  818. package/src/owner-distill.ts +62 -0
  819. package/src/owner.ts +235 -0
  820. package/src/platform/adapter.ts +132 -0
  821. package/src/platform/darwin.ts +206 -0
  822. package/src/platform/index.ts +69 -0
  823. package/src/platform/linux.ts +150 -0
  824. package/src/platform/shared.ts +31 -0
  825. package/src/platform/windows.ts +76 -0
  826. package/src/progress.ts +132 -0
  827. package/src/refs.ts +12 -0
  828. package/src/refusal.ts +2 -0
  829. package/src/release/archive.ts +110 -0
  830. package/src/release/automatic-cli.ts +42 -0
  831. package/src/release/automatic-policy.ts +96 -0
  832. package/src/release/automatic-state.ts +55 -0
  833. package/src/release/automatic.ts +189 -0
  834. package/src/release/bundle.ts +132 -0
  835. package/src/release/cli.ts +248 -0
  836. package/src/release/discovery.ts +110 -0
  837. package/src/release/files.ts +245 -0
  838. package/src/release/install.ts +204 -0
  839. package/src/release/launch-leases.ts +79 -0
  840. package/src/release/live.ts +76 -0
  841. package/src/release/manifest.ts +243 -0
  842. package/src/release/native-cache-cli.ts +75 -0
  843. package/src/release/native-cache-lease.ts +250 -0
  844. package/src/release/native-cache-prune.ts +206 -0
  845. package/src/release/native-cache-quarantine.ts +150 -0
  846. package/src/release/native-cache-refs.ts +161 -0
  847. package/src/release/native-cache-stage.ts +41 -0
  848. package/src/release/native-cache-uses.ts +172 -0
  849. package/src/release/native-cache.ts +132 -0
  850. package/src/release/native-export.ts +46 -0
  851. package/src/release/native.ts +245 -0
  852. package/src/release/process-cwd.ts +125 -0
  853. package/src/release/process-files.ts +86 -0
  854. package/src/release/provision.ts +191 -0
  855. package/src/release/references.ts +188 -0
  856. package/src/release/runtime.ts +208 -0
  857. package/src/release/setup.ts +77 -0
  858. package/src/release/source-bundle-update.ts +133 -0
  859. package/src/release/source-bundle.ts +241 -0
  860. package/src/release/source-checkout.ts +56 -0
  861. package/src/release/state.ts +219 -0
  862. package/src/release/types.ts +34 -0
  863. package/src/release/version.ts +7 -0
  864. package/src/remote/client.ts +138 -0
  865. package/src/remote/policy.ts +53 -0
  866. package/src/remote/socket-path.ts +38 -0
  867. package/src/remote/transport.ts +65 -0
  868. package/src/runtime/exec.ts +35 -0
  869. package/src/runtime/foreground.ts +50 -0
  870. package/src/runtime/group.ts +17 -0
  871. package/src/runtime/hc/deliver.ts +129 -0
  872. package/src/runtime/hc/exec.ts +79 -0
  873. package/src/runtime/hc/index.ts +102 -0
  874. package/src/runtime/hc/probe.ts +119 -0
  875. package/src/runtime/hc/sessions.ts +168 -0
  876. package/src/runtime/headless-broker.ts +250 -0
  877. package/src/runtime/headless-protocol.ts +238 -0
  878. package/src/runtime/headless-record.ts +241 -0
  879. package/src/runtime/headless-remote.ts +222 -0
  880. package/src/runtime/headless-rpc.ts +224 -0
  881. package/src/runtime/headless.ts +250 -0
  882. package/src/runtime/herdr/deliver.ts +172 -0
  883. package/src/runtime/herdr/exec.ts +46 -0
  884. package/src/runtime/herdr/index.ts +94 -0
  885. package/src/runtime/herdr/probe.ts +134 -0
  886. package/src/runtime/herdr/sessions.ts +126 -0
  887. package/src/runtime/omp-argv.ts +172 -0
  888. package/src/runtime/omp-options.ts +41 -0
  889. package/src/runtime/omp-prefixes.ts +122 -0
  890. package/src/runtime/omp.ts +170 -0
  891. package/src/runtime/registry.ts +60 -0
  892. package/src/runtime/select.ts +86 -0
  893. package/src/runtime/types.ts +156 -0
  894. package/src/setup-files.ts +131 -0
  895. package/src/setup-readback.ts +61 -0
  896. package/src/status-view.ts +74 -0
  897. package/src/store-journal.ts +68 -0
  898. package/src/store-types.ts +140 -0
  899. package/src/store.ts +249 -0
  900. package/src/target.ts +29 -0
  901. package/src/telemetry-otlp.ts +78 -0
  902. package/src/telemetry.ts +203 -0
  903. package/src/update/app-state.ts +107 -0
  904. package/src/update/cli.ts +133 -0
  905. package/src/update/command-output.ts +158 -0
  906. package/src/update/config.ts +31 -0
  907. package/src/update/controller.ts +241 -0
  908. package/src/update/deployment-active.ts +155 -0
  909. package/src/update/deployment-cli.ts +107 -0
  910. package/src/update/deployment-config.ts +178 -0
  911. package/src/update/deployment-files.ts +189 -0
  912. package/src/update/deployment-handoff.ts +122 -0
  913. package/src/update/deployment-health.ts +146 -0
  914. package/src/update/deployment-hold.ts +90 -0
  915. package/src/update/deployment-launch.ts +202 -0
  916. package/src/update/deployment-launcher.ts +23 -0
  917. package/src/update/deployment-legacy-monitors.ts +196 -0
  918. package/src/update/deployment-lock.ts +28 -0
  919. package/src/update/deployment-monitor-receipts.ts +197 -0
  920. package/src/update/deployment-monitors.ts +188 -0
  921. package/src/update/deployment-native-ui.ts +111 -0
  922. package/src/update/deployment-native.ts +250 -0
  923. package/src/update/deployment-prepare.ts +165 -0
  924. package/src/update/deployment-prior.ts +95 -0
  925. package/src/update/deployment-process.ts +202 -0
  926. package/src/update/deployment-quiesce.ts +71 -0
  927. package/src/update/deployment-restart-state.ts +107 -0
  928. package/src/update/deployment-restart.ts +137 -0
  929. package/src/update/deployment-rollback.ts +139 -0
  930. package/src/update/deployment-run.ts +242 -0
  931. package/src/update/deployment-shell.ts +62 -0
  932. package/src/update/deployment-signal.ts +32 -0
  933. package/src/update/deployment-toolchain.ts +133 -0
  934. package/src/update/deployment-types.ts +168 -0
  935. package/src/update/deployment.ts +4 -0
  936. package/src/update/detection-process.ts +198 -0
  937. package/src/update/environment.ts +140 -0
  938. package/src/update/github-ci.ts +115 -0
  939. package/src/update/load.ts +250 -0
  940. package/src/update/native-argv.ts +88 -0
  941. package/src/update/native-prompts.ts +58 -0
  942. package/src/update/pipeline.ts +86 -0
  943. package/src/update/pre-action-notice.ts +118 -0
  944. package/src/update/prepare.ts +164 -0
  945. package/src/update/proc.ts +62 -0
  946. package/src/update/process.ts +202 -0
  947. package/src/update/promotion.ts +145 -0
  948. package/src/update/publish-basis.ts +85 -0
  949. package/src/update/publish-config.ts +122 -0
  950. package/src/update/publish-export.ts +177 -0
  951. package/src/update/publish-github.ts +232 -0
  952. package/src/update/publish-lock.ts +66 -0
  953. package/src/update/publish-process.ts +149 -0
  954. package/src/update/publish-types.ts +65 -0
  955. package/src/update/publish.ts +250 -0
  956. package/src/update/recovery.ts +248 -0
  957. package/src/update/report.ts +207 -0
  958. package/src/update/response.ts +59 -0
  959. package/src/update/review.ts +124 -0
  960. package/src/update/reviewer-guard.ts +131 -0
  961. package/src/update/source-activity.ts +152 -0
  962. package/src/update/source-pin.ts +9 -0
  963. package/src/update/source-update-candidate.ts +54 -0
  964. package/src/update/source-update-cli.ts +156 -0
  965. package/src/update/source-update-config.ts +110 -0
  966. package/src/update/source-update-git.ts +92 -0
  967. package/src/update/source-update-idle.ts +89 -0
  968. package/src/update/source-update-run.ts +215 -0
  969. package/src/update/source-update-state.ts +159 -0
  970. package/src/update/source-update-target.ts +100 -0
  971. package/src/update/source.ts +246 -0
  972. package/src/update/state.ts +231 -0
  973. package/src/update/types.ts +170 -0
  974. package/src/update/worker-guard.ts +147 -0
  975. package/test/ambiguous-delivery.test.ts +234 -0
  976. package/test/backlog.test.ts +105 -0
  977. package/test/bin-mode.test.ts +27 -0
  978. package/test/ci-fixtures.test.ts +114 -0
  979. package/test/ci-install-herdr.test.ts +127 -0
  980. package/test/cla-precheck.test.ts +117 -0
  981. package/test/cli-args.test.ts +37 -0
  982. package/test/cli-native-admission.test.ts +131 -0
  983. package/test/duty-lock.test.ts +31 -0
  984. package/test/duty-notice-epoch.test.ts +169 -0
  985. package/test/duty-notice-lock.test.ts +107 -0
  986. package/test/duty-notice-once.test.ts +172 -0
  987. package/test/duty-progress-epochs.test.ts +124 -0
  988. package/test/duty-progress.test.ts +243 -0
  989. package/test/duty-prompts-access.test.ts +126 -0
  990. package/test/duty-reference-delivery.test.ts +241 -0
  991. package/test/duty-runtime.test.ts +61 -0
  992. package/test/duty-waiting-target.test.ts +238 -0
  993. package/test/duty-waiting-text.test.ts +104 -0
  994. package/test/duty-waiting-upgrade.test.ts +72 -0
  995. package/test/duty-waiting.test.ts +222 -0
  996. package/test/duty.test.ts +178 -0
  997. package/test/e2e-hc-deploy.test.ts +156 -0
  998. package/test/e2e-hc-setup.ts +123 -0
  999. package/test/e2e-hc.test.ts +138 -0
  1000. package/test/e2e-migrate.test.ts +146 -0
  1001. package/test/e2e.test.ts +144 -0
  1002. package/test/fake-hc.ts +185 -0
  1003. package/test/fake.ts +189 -0
  1004. package/test/fixtures/fake-agent-7501.sh +14 -0
  1005. package/test/fixtures/fake-agent.sh +8 -0
  1006. package/test/fixtures/headless-rpc.ts +86 -0
  1007. package/test/fixtures/inbox-lock-reclaimer.test.ts +22 -0
  1008. package/test/fixtures/lock-claim-reclaimer.test.ts +21 -0
  1009. package/test/fixtures/omp-native-host/bun.lock +151 -0
  1010. package/test/fixtures/omp-native-host/compose.ts +250 -0
  1011. package/test/fixtures/omp-native-host/head-admission.ts +128 -0
  1012. package/test/fixtures/omp-native-host/host.ts +20 -0
  1013. package/test/fixtures/omp-native-host/launch-model.ts +18 -0
  1014. package/test/fixtures/omp-native-host/native-message-head.ts +92 -0
  1015. package/test/fixtures/omp-native-host/package.json +8 -0
  1016. package/test/fixtures/omp-native-host/policy-host.ts +123 -0
  1017. package/test/fixtures/omp-native-host/policy-worker.ts +12 -0
  1018. package/test/fixtures/omp-native-host/prompt-matrix.ts +249 -0
  1019. package/test/fixtures/omp-native-host/request-run.ts +56 -0
  1020. package/test/fixtures/omp-native-host/required-source.ts +126 -0
  1021. package/test/fixtures/release-isolated-source-bundle.test.ts +111 -0
  1022. package/test/fixtures/remote-attach.ts +25 -0
  1023. package/test/fixtures/remote-endpoint.ts +67 -0
  1024. package/test/fixtures/remote-test-model.ts +44 -0
  1025. package/test/fixtures/runtime-headless.ts +77 -0
  1026. package/test/fixtures/screens/omo-dialog.txt +12 -0
  1027. package/test/fixtures/screens/omo-draft.txt +7 -0
  1028. package/test/fixtures/screens/omo-idle-live-monitors.txt +9 -0
  1029. package/test/fixtures/screens/omo-turn.txt +9 -0
  1030. package/test/gate.test.ts +94 -0
  1031. package/test/harness-lane-messenger-env.test.ts +62 -0
  1032. package/test/harness-omp.test.ts +124 -0
  1033. package/test/harness-setup.ts +36 -0
  1034. package/test/hc-rig.ts +28 -0
  1035. package/test/herdr-recorder.ts +32 -0
  1036. package/test/hooks.test.ts +228 -0
  1037. package/test/inbox-append-lock.test.ts +180 -0
  1038. package/test/inbox-commit-race.test.ts +101 -0
  1039. package/test/inbox-followups.test.ts +139 -0
  1040. package/test/inbox-forward.test.ts +161 -0
  1041. package/test/inbox-lead-intent.test.ts +145 -0
  1042. package/test/inbox-lock-crash-chain.test.ts +180 -0
  1043. package/test/inbox-lock-takeover.test.ts +76 -0
  1044. package/test/inbox-lock.test.ts +99 -0
  1045. package/test/inbox-owed-dup.test.ts +68 -0
  1046. package/test/inbox-reused-id.test.ts +119 -0
  1047. package/test/inbox-rollback-race.test.ts +94 -0
  1048. package/test/inbox-route-held.test.ts +112 -0
  1049. package/test/inbox-setup.ts +38 -0
  1050. package/test/inbox-spool-race.test.ts +213 -0
  1051. package/test/inbox-target-race.test.ts +51 -0
  1052. package/test/install-bun-path.test.ts +53 -0
  1053. package/test/install-command-collision.test.ts +171 -0
  1054. package/test/install-command-path.test.ts +66 -0
  1055. package/test/install-command-relink.test.ts +114 -0
  1056. package/test/install-configuration.test.ts +250 -0
  1057. package/test/install-consumer-pointer.test.ts +100 -0
  1058. package/test/install-consumer-setup.ts +40 -0
  1059. package/test/install-consumer.test.ts +174 -0
  1060. package/test/install-existing.test.ts +82 -0
  1061. package/test/install-selection.test.ts +124 -0
  1062. package/test/install-setup-safety.test.ts +175 -0
  1063. package/test/install-setup.ts +169 -0
  1064. package/test/install-side-omp-yml.test.ts +179 -0
  1065. package/test/install-side.test.ts +246 -0
  1066. package/test/install-ulw.test.ts +190 -0
  1067. package/test/install.test.ts +140 -0
  1068. package/test/lanes.test.ts +97 -0
  1069. package/test/lock-claim.test.ts +130 -0
  1070. package/test/lock-cli.test.ts +145 -0
  1071. package/test/lock-foreign.test.ts +124 -0
  1072. package/test/lock-queue.test.ts +132 -0
  1073. package/test/lock-race.test.ts +146 -0
  1074. package/test/lock-setup.ts +46 -0
  1075. package/test/lock.test.ts +128 -0
  1076. package/test/loop-lock.test.ts +110 -0
  1077. package/test/loop-setup.ts +21 -0
  1078. package/test/loop.test.ts +240 -0
  1079. package/test/managed-agent-command.test.ts +190 -0
  1080. package/test/managed-command-contract.test.ts +62 -0
  1081. package/test/managed-command-setup.ts +68 -0
  1082. package/test/managed-source-command.test.ts +133 -0
  1083. package/test/migrate-lock-release.test.ts +46 -0
  1084. package/test/migrate-roles.test.ts +139 -0
  1085. package/test/migrate-setup.ts +77 -0
  1086. package/test/migrate.test.ts +224 -0
  1087. package/test/module-graph.test.ts +51 -0
  1088. package/test/native-cache-prune-setup.ts +83 -0
  1089. package/test/native-export.test.ts +168 -0
  1090. package/test/native-file-digest.test.ts +127 -0
  1091. package/test/omp-setup.ts +61 -0
  1092. package/test/owner-distill.test.ts +89 -0
  1093. package/test/owner-recovery.test.ts +183 -0
  1094. package/test/owner.test.ts +186 -0
  1095. package/test/platform-adapter.test.ts +236 -0
  1096. package/test/proc-name.ts +9 -0
  1097. package/test/prompt-authority.test.ts +47 -0
  1098. package/test/prompt-goal-ownership.test.ts +90 -0
  1099. package/test/prompt-progress.test.ts +55 -0
  1100. package/test/prompt-routing.test.ts +40 -0
  1101. package/test/records-upgrade.test.ts +165 -0
  1102. package/test/release-automatic-bound-concurrency.test.ts +78 -0
  1103. package/test/release-automatic-concurrency.test.ts +223 -0
  1104. package/test/release-automatic-launch.test.ts +202 -0
  1105. package/test/release-automatic.test.ts +243 -0
  1106. package/test/release-bootstrap-runtime.test.ts +53 -0
  1107. package/test/release-bootstrap-setup.ts +120 -0
  1108. package/test/release-bootstrap.test.ts +214 -0
  1109. package/test/release-capabilities.test.ts +56 -0
  1110. package/test/release-consumer-discovery.test.ts +117 -0
  1111. package/test/release-consumer-liveness.test.ts +63 -0
  1112. package/test/release-consumer-lock.test.ts +68 -0
  1113. package/test/release-consumer-profile.test.ts +82 -0
  1114. package/test/release-consumer-runtime.test.ts +144 -0
  1115. package/test/release-consumer-security.test.ts +196 -0
  1116. package/test/release-consumer-selection.test.ts +91 -0
  1117. package/test/release-consumer-setup.ts +233 -0
  1118. package/test/release-consumer-side.test.ts +250 -0
  1119. package/test/release-consumer-state.test.ts +122 -0
  1120. package/test/release-consumer-toolchain.test.ts +145 -0
  1121. package/test/release-gate-parallel.test.ts +90 -0
  1122. package/test/release-gate.test.ts +132 -0
  1123. package/test/release-isolated-source-bundle.test.ts +63 -0
  1124. package/test/release-legacy-prerequisite.test.ts +121 -0
  1125. package/test/release-managed-command-env.test.ts +170 -0
  1126. package/test/release-manifest.test.ts +115 -0
  1127. package/test/release-native-cache-bytes.test.ts +35 -0
  1128. package/test/release-native-cache-cwd.test.ts +75 -0
  1129. package/test/release-native-cache-hold.test.ts +161 -0
  1130. package/test/release-native-cache-homes.test.ts +73 -0
  1131. package/test/release-native-cache-late.test.ts +225 -0
  1132. package/test/release-native-cache-lease.test.ts +184 -0
  1133. package/test/release-native-cache-prune-race.test.ts +200 -0
  1134. package/test/release-native-cache-prune-refs.test.ts +207 -0
  1135. package/test/release-native-cache-removal-recovery.test.ts +239 -0
  1136. package/test/release-native-cache-review.test.ts +245 -0
  1137. package/test/release-native-cache-threads.test.ts +218 -0
  1138. package/test/release-native-cache.test.ts +217 -0
  1139. package/test/release-native-recovery-setup.ts +120 -0
  1140. package/test/release-native-recovery.test.ts +213 -0
  1141. package/test/release-producer-setup.ts +120 -0
  1142. package/test/release-publication.test.ts +72 -0
  1143. package/test/release-publish-setup.ts +192 -0
  1144. package/test/release-publish.test.ts +106 -0
  1145. package/test/release-reference-renderer.test.ts +150 -0
  1146. package/test/release-setup-config.test.ts +250 -0
  1147. package/test/release-source-bundle.test.ts +161 -0
  1148. package/test/release-source.test.ts +54 -0
  1149. package/test/release-wrapper-command.test.ts +101 -0
  1150. package/test/remote-hc-native.test.ts +221 -0
  1151. package/test/remote-session.test.ts +208 -0
  1152. package/test/report-evidence-line.test.ts +45 -0
  1153. package/test/request-run-native.test.ts +66 -0
  1154. package/test/resolve-target.test.ts +60 -0
  1155. package/test/runtime-bound-delivery.test.ts +53 -0
  1156. package/test/runtime-core.test.ts +244 -0
  1157. package/test/runtime-exec.test.ts +45 -0
  1158. package/test/runtime-hc-argv.test.ts +32 -0
  1159. package/test/runtime-hc-deliver.test.ts +176 -0
  1160. package/test/runtime-hc-misc.test.ts +147 -0
  1161. package/test/runtime-hc-screen.test.ts +96 -0
  1162. package/test/runtime-hc.test.ts +234 -0
  1163. package/test/runtime-headless-native.test.ts +206 -0
  1164. package/test/runtime-headless-remote.test.ts +128 -0
  1165. package/test/runtime-headless-request.test.ts +74 -0
  1166. package/test/runtime-headless.test.ts +238 -0
  1167. package/test/runtime-herdr-deliver.test.ts +241 -0
  1168. package/test/runtime-herdr-groups.test.ts +39 -0
  1169. package/test/runtime-herdr-screen.test.ts +59 -0
  1170. package/test/runtime-herdr.test.ts +248 -0
  1171. package/test/runtime-omp-source.test.ts +100 -0
  1172. package/test/runtime-omp-timing.test.ts +163 -0
  1173. package/test/runtime-omp-typed.test.ts +74 -0
  1174. package/test/runtime-omp.test.ts +226 -0
  1175. package/test/runtime-select.test.ts +183 -0
  1176. package/test/screen.test.ts +44 -0
  1177. package/test/send-both.test.ts +78 -0
  1178. package/test/send.test.ts +96 -0
  1179. package/test/setup-files.test.ts +187 -0
  1180. package/test/shell-pane.test.ts +202 -0
  1181. package/test/shq.test.ts +11 -0
  1182. package/test/socket-budget.test.ts +20 -0
  1183. package/test/socket-budget.ts +13 -0
  1184. package/test/source-bundle-readonly.test.ts +28 -0
  1185. package/test/source-bundle-setup.ts +157 -0
  1186. package/test/source-bundle-update.test.ts +125 -0
  1187. package/test/source-bundle.test.ts +249 -0
  1188. package/test/status-view.test.ts +150 -0
  1189. package/test/telemetry-delivery.test.ts +141 -0
  1190. package/test/telemetry.test.ts +185 -0
  1191. package/test/terminal-context-migrate.test.ts +126 -0
  1192. package/test/terminal-context-setup.ts +121 -0
  1193. package/test/terminal-context-skill.test.ts +135 -0
  1194. package/test/terminal-context.test.ts +136 -0
  1195. package/test/terminal-managed-setup.ts +102 -0
  1196. package/test/ulw-canonical-repository.test.ts +43 -0
  1197. package/test/up.test.ts +98 -0
  1198. package/test/update-admission.test.ts +250 -0
  1199. package/test/update-app-state.test.ts +88 -0
  1200. package/test/update-boundaries.test.ts +248 -0
  1201. package/test/update-deploy-config.test.ts +172 -0
  1202. package/test/update-deploy-env.test.ts +87 -0
  1203. package/test/update-deploy-failure.test.ts +72 -0
  1204. package/test/update-deploy-files.test.ts +173 -0
  1205. package/test/update-deploy-foreground-cli.ts +39 -0
  1206. package/test/update-deploy-foreground-readiness.test.ts +29 -0
  1207. package/test/update-deploy-foreground-readiness.ts +248 -0
  1208. package/test/update-deploy-foreground-setup.ts +228 -0
  1209. package/test/update-deploy-foreground.test.ts +236 -0
  1210. package/test/update-deploy-hc.test.ts +85 -0
  1211. package/test/update-deploy-identity.test.ts +230 -0
  1212. package/test/update-deploy-launch.test.ts +194 -0
  1213. package/test/update-deploy-legacy-rollback.test.ts +235 -0
  1214. package/test/update-deploy-legacy-setup.ts +87 -0
  1215. package/test/update-deploy-lock.test.ts +123 -0
  1216. package/test/update-deploy-managed-bash.test.ts +159 -0
  1217. package/test/update-deploy-managed-setup.ts +102 -0
  1218. package/test/update-deploy-native-ui-consumer-setup.ts +126 -0
  1219. package/test/update-deploy-native-ui-consumers.test.ts +150 -0
  1220. package/test/update-deploy-native-ui-observed.test.ts +97 -0
  1221. package/test/update-deploy-native-ui.test.ts +157 -0
  1222. package/test/update-deploy-once.test.ts +96 -0
  1223. package/test/update-deploy-prepare-production.test.ts +89 -0
  1224. package/test/update-deploy-prepare-setup.ts +119 -0
  1225. package/test/update-deploy-prepare-umask.test.ts +92 -0
  1226. package/test/update-deploy-prepare.test.ts +180 -0
  1227. package/test/update-deploy-prior-source.test.ts +108 -0
  1228. package/test/update-deploy-rollback-presence.test.ts +115 -0
  1229. package/test/update-deploy-runtime.test.ts +195 -0
  1230. package/test/update-deploy-setup.ts +74 -0
  1231. package/test/update-deploy-shell-alias.test.ts +172 -0
  1232. package/test/update-deploy-shell-witness.test.ts +47 -0
  1233. package/test/update-deploy-source-launch.test.ts +161 -0
  1234. package/test/update-deploy-startup-stop.test.ts +127 -0
  1235. package/test/update-deploy-stop-recovery.test.ts +123 -0
  1236. package/test/update-detection-blackhole.test.ts +168 -0
  1237. package/test/update-detection-setup.ts +139 -0
  1238. package/test/update-detection.test.ts +138 -0
  1239. package/test/update-execution.test.ts +250 -0
  1240. package/test/update-monitor-lifecycle.test.ts +83 -0
  1241. package/test/update-native-bun-run.test.ts +133 -0
  1242. package/test/update-native-contract.test.ts +246 -0
  1243. package/test/update-native-launch-prefix.test.ts +152 -0
  1244. package/test/update-native-launchers.test.ts +235 -0
  1245. package/test/update-native-process-wrapper.test.ts +151 -0
  1246. package/test/update-native-source.test.ts +127 -0
  1247. package/test/update-pre-action-deployment.test.ts +208 -0
  1248. package/test/update-pre-action-notice.test.ts +147 -0
  1249. package/test/update-pre-action-setup.ts +67 -0
  1250. package/test/update-proc.test.ts +83 -0
  1251. package/test/update-promotion.test.ts +139 -0
  1252. package/test/update-publish-ancestor.test.ts +46 -0
  1253. package/test/update-publish-bootstrap.test.ts +238 -0
  1254. package/test/update-publish-deployment.test.ts +83 -0
  1255. package/test/update-publish-github.test.ts +144 -0
  1256. package/test/update-publish-recovery.test.ts +152 -0
  1257. package/test/update-publish-setup.ts +43 -0
  1258. package/test/update-publish-terminal.test.ts +231 -0
  1259. package/test/update-publish-wait.test.ts +213 -0
  1260. package/test/update-publish.test.ts +173 -0
  1261. package/test/update-report.test.ts +136 -0
  1262. package/test/update-response.test.ts +81 -0
  1263. package/test/update-review-scope.test.ts +184 -0
  1264. package/test/update-running-cancel.test.ts +78 -0
  1265. package/test/update-running-status.test.ts +153 -0
  1266. package/test/update-setup.ts +245 -0
  1267. package/test/update-source-activity.test.ts +149 -0
  1268. package/test/update-source-admission.test.ts +80 -0
  1269. package/test/update-source-ci.test.ts +77 -0
  1270. package/test/update-source-circuit.test.ts +147 -0
  1271. package/test/update-source-cli.test.ts +31 -0
  1272. package/test/update-source-config.test.ts +77 -0
  1273. package/test/update-source-git-setup.ts +151 -0
  1274. package/test/update-source-git.test.ts +95 -0
  1275. package/test/update-source-idle-setup.ts +146 -0
  1276. package/test/update-source-idle.test.ts +148 -0
  1277. package/test/update-source-intake-setup.ts +21 -0
  1278. package/test/update-source-journal-admission.test.ts +129 -0
  1279. package/test/update-source-pending-restart.test.ts +60 -0
  1280. package/test/update-source-rollout-setup.ts +111 -0
  1281. package/test/update-source-rollout.test.ts +164 -0
  1282. package/test/update-source-setup.ts +21 -0
  1283. package/test/update-source-state.test.ts +195 -0
  1284. package/test/update-source-supervisor.test.ts +128 -0
  1285. package/test/update-source-target.test.ts +152 -0
  1286. package/test/update-source-terminal-journal.test.ts +59 -0
  1287. package/test/update-source-toolchain.test.ts +109 -0
  1288. package/test/update-supervisor.test.ts +113 -0
  1289. package/test/update-ulw-publish-reuse.test.ts +94 -0
  1290. package/test/update-ulw-publish-setup.ts +131 -0
  1291. package/test/update-ulw-publish.test.ts +75 -0
  1292. package/test/update-verification.test.ts +109 -0
  1293. package/test/update.test.ts +236 -0
  1294. package/tsconfig.base.json +20 -0
  1295. package/tsconfig.json +7 -0
@@ -0,0 +1,242 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { lstatSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { processStart } from "../../../../../src/release/process-cwd.ts";
5
+ import { discordApiBase } from "./discord.ts";
6
+ import { readPrivateAskFile } from "./discord-ask-mailbox.ts";
7
+ import { isDiscordSnowflake } from "./discord-inbound-state.ts";
8
+
9
+ const TTL_MS = 30_000;
10
+ const REFRESH_MS = 5_000;
11
+ const MAX_BYTES = 65_536;
12
+ const MAX_CHANNELS = 1_024;
13
+ const RECEIPT_NAME = /^(\d{1,10})-[0-9a-f-]{36}\.json$/;
14
+ type Route = { owner: string; explicit: readonly string[]; watched: readonly string[] };
15
+ type Receipt = Route & {
16
+ version: 1;
17
+ pid: number;
18
+ start: string;
19
+ tokenDigest: string;
20
+ apiBase: string;
21
+ expiresAt: number;
22
+ };
23
+ export type DiscordAskReceiverPublication = { refresh(): void; suspend(): void; close(): void };
24
+ const owned = (uid: number) => process.getuid === undefined || uid === process.getuid();
25
+ const digest = (token: string) => createHash("sha256").update(token).digest("hex");
26
+ const channelList = (value: unknown): value is string[] =>
27
+ Array.isArray(value) && value.length <= MAX_CHANNELS && value.every(isDiscordSnowflake);
28
+
29
+ function privateDirectory(path: string): void {
30
+ const stat = lstatSync(path);
31
+ if (!stat.isDirectory() || !owned(stat.uid) || (stat.mode & 0o077) !== 0)
32
+ throw new Error("Discord ASK receiver directory is not private");
33
+ }
34
+
35
+ /** A reused PID, zombie, or a receipt from a previous Linux boot is not a receiver. */
36
+ function identity(pid: number): string | undefined {
37
+ try {
38
+ process.kill(pid, 0);
39
+ if (process.platform !== "linux") return processStart(String(pid));
40
+ const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
41
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
42
+ const start = fields[19];
43
+ if (fields[0] === "Z" || fields[0] === "X" || !start || !/^\d+$/.test(start)) return undefined;
44
+ return `${readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim()}:${start}`;
45
+ } catch {
46
+ return undefined;
47
+ }
48
+ }
49
+
50
+ function receipt(value: unknown, pid: number): Receipt | undefined {
51
+ if (value === null || typeof value !== "object") return undefined;
52
+ const item = value as Partial<Receipt>;
53
+ if (
54
+ item.version !== 1 ||
55
+ item.pid !== pid ||
56
+ !Number.isSafeInteger(pid) ||
57
+ pid <= 0 ||
58
+ typeof item.start !== "string" ||
59
+ item.start.length > 256 ||
60
+ typeof item.apiBase !== "string" ||
61
+ typeof item.tokenDigest !== "string" ||
62
+ !/^[0-9a-f]{64}$/.test(item.tokenDigest) ||
63
+ !isDiscordSnowflake(item.owner) ||
64
+ !channelList(item.explicit) ||
65
+ !channelList(item.watched) ||
66
+ !item.explicit.every((channel) => item.watched!.includes(channel)) ||
67
+ !Number.isSafeInteger(item.expiresAt)
68
+ )
69
+ return undefined;
70
+ return item as Receipt;
71
+ }
72
+
73
+ /**
74
+ * Local discovery only: exact token digest, private file, unexpired heartbeat, live process/start identity.
75
+ * `watched` includes discovered scope-all channels and followed threads, NOT automatic Dori destinations.
76
+ * Consumers may use those only for a registered lane thread; automatic Dori needs exactly one `explicit` ID.
77
+ * Malformed, unavailable, insecure and stale receipts never turn discovery into a command failure.
78
+ */
79
+ export function discordAskReceivers(
80
+ stateDir: string,
81
+ token: string,
82
+ ): Array<{
83
+ owner: string;
84
+ explicit: readonly string[];
85
+ watched: readonly string[];
86
+ }> {
87
+ if (!token) return [];
88
+ const root = join(stateDir, "discord-ask-receivers");
89
+ const routes: Route[] = [];
90
+ const tokenDigest = digest(token);
91
+ try {
92
+ const apiBase = discordApiBase(process.env["DORI_DISCORD_API_BASE"]);
93
+ privateDirectory(root);
94
+ for (const name of readdirSync(root)) {
95
+ const match = RECEIPT_NAME.exec(name);
96
+ if (!match) continue;
97
+ const path = join(root, name);
98
+ try {
99
+ const raw = readPrivateAskFile(path, MAX_BYTES);
100
+ if (raw === undefined) continue;
101
+ const item = receipt(JSON.parse(raw), Number(match[1]));
102
+ if (!item) continue;
103
+ const now = Date.now();
104
+ if (identity(item.pid) !== item.start) {
105
+ unlinkSync(path);
106
+ continue;
107
+ }
108
+ // A heartbeat may replace this pathname after the read; never unlink a merely expired snapshot.
109
+ if (item.expiresAt <= now || item.expiresAt > now + TTL_MS) continue;
110
+ if (item.tokenDigest === tokenDigest && item.apiBase === apiBase)
111
+ routes.push({ owner: item.owner, explicit: item.explicit, watched: item.watched });
112
+ } catch {
113
+ // An absent, concurrently refreshed or untrusted receipt is not a working route.
114
+ }
115
+ }
116
+ } catch {
117
+ // Discovery must not require a state directory or rewrite persistent user settings.
118
+ }
119
+ return routes;
120
+ }
121
+
122
+ /** Call only after intake authenticates the bot and validates its owner/channel scope. All publication is best-effort. */
123
+ export function openDiscordAskReceiver(
124
+ stateDir: string,
125
+ token: string,
126
+ owner: string,
127
+ explicit: readonly string[],
128
+ watched: () => readonly string[],
129
+ progressWindowMs = Infinity,
130
+ ): DiscordAskReceiverPublication {
131
+ const root = join(stateDir, "discord-ask-receivers");
132
+ const name = `${process.pid}-${randomUUID()}.json`;
133
+ const path = join(root, name);
134
+ const start = identity(process.pid);
135
+ const tokenDigest = digest(token);
136
+ let apiBase: string | undefined;
137
+ try {
138
+ apiBase = discordApiBase(process.env["DORI_DISCORD_API_BASE"]);
139
+ } catch {
140
+ /* Fail closed below. */
141
+ }
142
+ const configured = [...new Set(explicit)];
143
+ let timer: NodeJS.Timeout | undefined;
144
+ let active = false;
145
+ let lastChannels: readonly string[] = [];
146
+ let verifiedUntil = 0;
147
+ let renewAt = 0;
148
+ let closed = false;
149
+ const remove = () => {
150
+ try {
151
+ privateDirectory(root);
152
+ unlinkSync(path);
153
+ } catch {
154
+ // Process death and the short expiry remain authoritative if cleanup fails.
155
+ }
156
+ };
157
+ const publish = () => {
158
+ if (!active || closed || !start) return;
159
+ let temp: string | undefined;
160
+ try {
161
+ const now = Date.now();
162
+ if (now >= verifiedUntil) {
163
+ suspend();
164
+ return;
165
+ }
166
+ const current = watched();
167
+ if (now < renewAt && current.length === lastChannels.length && current.every((id, i) => id === lastChannels[i]))
168
+ return;
169
+ const channels = [...new Set(current)];
170
+ if (
171
+ !token ||
172
+ !apiBase ||
173
+ !isDiscordSnowflake(owner) ||
174
+ !channelList(configured) ||
175
+ !channelList(channels) ||
176
+ !configured.every((channel) => channels.includes(channel))
177
+ )
178
+ throw new Error("Invalid Discord ASK receiver route");
179
+ const body: Receipt = {
180
+ version: 1,
181
+ pid: process.pid,
182
+ start,
183
+ tokenDigest,
184
+ apiBase,
185
+ owner,
186
+ explicit: configured,
187
+ watched: channels,
188
+ expiresAt: Math.floor(Math.min(now + TTL_MS, verifiedUntil)),
189
+ };
190
+ const text = JSON.stringify(body);
191
+ if (Buffer.byteLength(text) > MAX_BYTES) throw new Error("Discord ASK receiver route exceeds size limit");
192
+ mkdirSync(root, { recursive: true, mode: 0o700 });
193
+ privateDirectory(root);
194
+ temp = join(root, `.${name}-${randomUUID()}`);
195
+ writeFileSync(temp, text, { flag: "wx", mode: 0o600 });
196
+ renameSync(temp, path);
197
+ lastChannels = [...current];
198
+ renewAt = now + REFRESH_MS;
199
+ } catch {
200
+ renewAt = 0;
201
+ remove();
202
+ } finally {
203
+ if (temp !== undefined) {
204
+ try {
205
+ unlinkSync(temp);
206
+ } catch {
207
+ /* Renamed or already removed. */
208
+ }
209
+ }
210
+ }
211
+ };
212
+ const suspend = () => {
213
+ active = false;
214
+ verifiedUntil = 0;
215
+ renewAt = 0;
216
+ clearInterval(timer);
217
+ timer = undefined;
218
+ remove();
219
+ };
220
+ const close = () => {
221
+ if (closed) return;
222
+ closed = true;
223
+ suspend();
224
+ process.removeListener("exit", close);
225
+ };
226
+ process.once("exit", close);
227
+ return {
228
+ /** Renew on schedule or immediately if the receiver's observed channel set changed. */
229
+ refresh(): void {
230
+ if (closed || !start) return;
231
+ verifiedUntil = Date.now() + progressWindowMs;
232
+ active = true;
233
+ publish();
234
+ if (timer === undefined) {
235
+ timer = setInterval(publish, REFRESH_MS);
236
+ timer.unref();
237
+ }
238
+ },
239
+ suspend,
240
+ close,
241
+ };
242
+ }
@@ -0,0 +1,200 @@
1
+ /** Private purpose notes and their source-bound receipts. A purpose is metadata, never an owner instruction. */
2
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { takeLock } from "../checkpoint-lock.ts";
5
+ import { isDiscordSnowflake } from "./discord-inbound-state.ts";
6
+
7
+ export class ChannelPurposeError extends Error {}
8
+
9
+ export type ChannelPurpose = { readonly purpose: string; readonly name?: string; readonly updatedAt: string };
10
+ type Purposes = Readonly<Record<string, ChannelPurpose>>;
11
+
12
+ export type PurposeSource = {
13
+ readonly botId: string;
14
+ readonly ownerId: string;
15
+ readonly channelId: string;
16
+ readonly messageId: string;
17
+ };
18
+
19
+ type PurposeReceipt = {
20
+ readonly source: PurposeSource;
21
+ readonly channel: string;
22
+ readonly purpose: string | null;
23
+ readonly result: ChannelPurpose | boolean;
24
+ };
25
+
26
+ type PurposeState = {
27
+ readonly version: 1;
28
+ readonly notes: Purposes;
29
+ readonly receipts: Readonly<Record<string, PurposeReceipt>>;
30
+ };
31
+
32
+ const MAX_PURPOSE = 500;
33
+ const LOCK_WAIT_MS = 5_000;
34
+ // C0 and C1 controls, DEL, the Unicode line and paragraph separators and bidirectional overrides and isolates: a
35
+ // purpose is one line of text that reads as it is stored.
36
+ // oxlint-disable-next-line no-control-regex -- the pattern deliberately matches control characters to reject them
37
+ const NOT_ONE_LINE = /[\x00-\x1f\x7f-\x9f\u2028\u2029\u202a-\u202e\u2066-\u2069]/;
38
+
39
+ /** A purpose is one line of 1 to 500 characters after trimming; anything else is refused before it is stored. */
40
+ export const purposeText = (purpose: string): string => {
41
+ const text = purpose.trim();
42
+ if (!oneLine(text)) throw new ChannelPurposeError(`--purpose must be one line of 1 to ${MAX_PURPOSE} characters`);
43
+ return text;
44
+ };
45
+
46
+ /** The stored form `purposeText` writes: trimmed, 1 to 500 characters, one line. */
47
+ const oneLine = (text: string): boolean =>
48
+ text !== "" && text === text.trim() && text.length <= MAX_PURPOSE && !NOT_ONE_LINE.test(text);
49
+
50
+ /** A stored entry is read only in the form `set` writes, so a hand-edited bad purpose counts as damage. */
51
+ const isPurpose = (value: unknown): value is ChannelPurpose => {
52
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
53
+ const { purpose, name, updatedAt } = value as Record<string, unknown>;
54
+ return (
55
+ typeof purpose === "string" &&
56
+ oneLine(purpose) &&
57
+ typeof updatedAt === "string" &&
58
+ (name === undefined || typeof name === "string")
59
+ );
60
+ };
61
+
62
+ const isSource = (value: unknown): value is PurposeSource => {
63
+ if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).length !== 4)
64
+ return false;
65
+ const { botId, ownerId, channelId, messageId } = value as Record<string, unknown>;
66
+ return [botId, ownerId, channelId, messageId].every(isDiscordSnowflake) && botId !== ownerId;
67
+ };
68
+
69
+ const receiptKey = (source: PurposeSource, channel: string): string =>
70
+ JSON.stringify([source.botId, source.ownerId, source.channelId, source.messageId, channel]);
71
+
72
+ const isReceipt = (value: unknown): value is PurposeReceipt => {
73
+ if (typeof value !== "object" || value === null || Array.isArray(value) || Object.keys(value).length !== 4)
74
+ return false;
75
+ const { source, channel, purpose, result } = value as Record<string, unknown>;
76
+ if (!isSource(source) || !isDiscordSnowflake(channel)) return false;
77
+ return purpose === null
78
+ ? typeof result === "boolean"
79
+ : typeof purpose === "string" && oneLine(purpose) && isPurpose(result) && result.purpose === purpose;
80
+ };
81
+
82
+ /** Legacy maps are read; writes atomically preserve notes and receipts in the same private file. */
83
+ export class DiscordChannels {
84
+ readonly path: string;
85
+ constructor(readonly stateDir: string) {
86
+ this.path = join(stateDir, "discord-channels.json");
87
+ }
88
+
89
+ /** Existing readers see only notes, never the internal source receipts. */
90
+ read(): Purposes {
91
+ return this.readState().notes;
92
+ }
93
+
94
+ private readState(): PurposeState {
95
+ if (!existsSync(this.path)) return { version: 1, notes: {}, receipts: {} };
96
+ let parsed: unknown;
97
+ try {
98
+ parsed = JSON.parse(readFileSync(this.path, "utf8"));
99
+ } catch {
100
+ throw new ChannelPurposeError(`${this.path} is not valid JSON; repair it before retrying`);
101
+ }
102
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
103
+ throw new ChannelPurposeError(`${this.path} must hold one JSON object`);
104
+ const record = parsed as Record<string, unknown>;
105
+ let notes: Record<string, unknown>;
106
+ let receipts: Record<string, unknown>;
107
+ if (Object.hasOwn(record, "version")) {
108
+ const { version, notes: savedNotes, receipts: savedReceipts } = record;
109
+ if (
110
+ version !== 1 ||
111
+ Object.keys(record).length !== 3 ||
112
+ typeof savedNotes !== "object" ||
113
+ savedNotes === null ||
114
+ Array.isArray(savedNotes) ||
115
+ typeof savedReceipts !== "object" ||
116
+ savedReceipts === null ||
117
+ Array.isArray(savedReceipts)
118
+ )
119
+ throw new ChannelPurposeError(`${this.path} has an invalid purpose state; repair it before retrying`);
120
+ notes = savedNotes as Record<string, unknown>;
121
+ receipts = savedReceipts as Record<string, unknown>;
122
+ } else {
123
+ notes = record;
124
+ receipts = {};
125
+ }
126
+ for (const [id, entry] of Object.entries(notes))
127
+ if (!isDiscordSnowflake(id) || !isPurpose(entry))
128
+ throw new ChannelPurposeError(`${this.path}: entry ${JSON.stringify(id)} is not a channel purpose`);
129
+ for (const [key, receipt] of Object.entries(receipts))
130
+ if (!isReceipt(receipt) || key !== receiptKey(receipt.source, receipt.channel))
131
+ throw new ChannelPurposeError(`${this.path} has an invalid source receipt; repair it before retrying`);
132
+ return { version: 1, notes: notes as Purposes, receipts: receipts as PurposeState["receipts"] };
133
+ }
134
+
135
+ /** Manual edits remain unrestricted by source, but retain every earlier receipt. */
136
+ async set(
137
+ id: string,
138
+ purpose: string,
139
+ name: string | undefined,
140
+ now: number,
141
+ source?: PurposeSource,
142
+ ): Promise<ChannelPurpose> {
143
+ const entry: ChannelPurpose = {
144
+ purpose: purposeText(purpose),
145
+ ...(name === undefined ? {} : { name }),
146
+ updatedAt: new Date(now).toISOString(),
147
+ };
148
+ return await this.change(id, entry, source);
149
+ }
150
+
151
+ /** A bound retry returns the first clear result without removing a later note. */
152
+ async clear(id: string, source?: PurposeSource): Promise<boolean> {
153
+ return await this.change(id, null, source);
154
+ }
155
+
156
+ private change(id: string, entry: ChannelPurpose, source?: PurposeSource): Promise<ChannelPurpose>;
157
+ private change(id: string, entry: null, source?: PurposeSource): Promise<boolean>;
158
+ private async change(
159
+ id: string,
160
+ entry: ChannelPurpose | null,
161
+ source?: PurposeSource,
162
+ ): Promise<ChannelPurpose | boolean> {
163
+ if (!isDiscordSnowflake(id)) throw new ChannelPurposeError(`${JSON.stringify(id)} is not a Discord ID`);
164
+ if (source !== undefined && !isSource(source)) throw new ChannelPurposeError("invalid purpose source identity");
165
+ mkdirSync(this.stateDir, { recursive: true });
166
+ const fail = (m: string) => new ChannelPurposeError(`channel purpose lock ${m}`);
167
+ const deadline = Date.now() + LOCK_WAIT_MS;
168
+ for (;;) {
169
+ const held = takeLock(`${this.path}.lock`, Date.now(), fail);
170
+ if (typeof held !== "string") {
171
+ try {
172
+ const all = this.readState();
173
+ const purpose = entry?.purpose ?? null;
174
+ const previous = source === undefined ? undefined : all.receipts[receiptKey(source, id)];
175
+ if (previous !== undefined) {
176
+ if (previous.purpose !== purpose) throw new ChannelPurposeError("channel purpose source identity conflict");
177
+ return previous.result;
178
+ }
179
+ const result = entry ?? Object.hasOwn(all.notes, id);
180
+ const notes =
181
+ entry === null
182
+ ? Object.fromEntries(Object.entries(all.notes).filter(([key]) => key !== id))
183
+ : { ...all.notes, [id]: entry };
184
+ const receipts = { ...all.receipts };
185
+ if (source !== undefined) receipts[receiptKey(source, id)] = { source, channel: id, purpose, result };
186
+ const next: PurposeState = { version: 1, notes, receipts };
187
+ const tmp = `${this.path}.${process.pid}.tmp`;
188
+ writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
189
+ chmodSync(tmp, 0o600);
190
+ renameSync(tmp, this.path);
191
+ return result;
192
+ } finally {
193
+ held();
194
+ }
195
+ }
196
+ if (Date.now() >= deadline) throw new ChannelPurposeError(`channel purposes are locked (${held})`);
197
+ await Bun.sleep(50);
198
+ }
199
+ }
200
+ }
@@ -0,0 +1,250 @@
1
+ import type { Clock } from "../run.ts";
2
+ import { MessengerError } from "./http.ts";
3
+
4
+ export type GatewaySocket = {
5
+ send(data: string): void;
6
+ close(code: number): void;
7
+ onMessage(cb: (data: string) => void): void;
8
+ onClose(cb: (code: number) => void): void;
9
+ onError(cb: () => void): void;
10
+ };
11
+ export type GatewayClock = Pick<Clock, "now"> & {
12
+ random(): number;
13
+ setTimeout(cb: () => void, ms: number): unknown;
14
+ clearTimeout(handle: unknown): void;
15
+ };
16
+ type Payload = {
17
+ op: number;
18
+ s?: number | null;
19
+ t?: string;
20
+ d?: boolean | { heartbeat_interval?: number; session_id?: string; resume_gateway_url?: string };
21
+ };
22
+ export type GatewayOptions = {
23
+ /** Prefix of the READY/RECONNECT/ACK/STOPPED report lines, e.g. PRESENCE. */
24
+ label: string;
25
+ intents: number;
26
+ /** Identify and resume as online; off leaves the account's presence to whoever else holds a connection. */
27
+ online: boolean;
28
+ onReady?: (event: "READY" | "RESUMED") => void;
29
+ /** Opt in to ordered dispatch replay after RESUME is sent, before RESUMED confirms completion. */
30
+ replayDispatches?: boolean;
31
+ /** The current socket has been retired; cached admission must wait for READY/RESUMED. */
32
+ onDisconnect?: () => void;
33
+ onHealth?: (available: boolean) => void;
34
+ /** Dispatches after establishment, plus authenticated resume replay only when explicitly opted in. */
35
+ onDispatch?: (type: string, data: unknown) => void;
36
+ };
37
+ const GATEWAY = "wss://gateway.discord.gg/?v=10&encoding=json";
38
+ const ONLINE = { status: "online", since: null, activities: [], afk: false };
39
+ const TERMINAL: Readonly<Record<number, string>> = {
40
+ 4004: "authentication failed",
41
+ 4010: "invalid shard",
42
+ 4011: "sharding required",
43
+ 4012: "invalid API version",
44
+ 4013: "invalid intents",
45
+ 4014: "disallowed intents",
46
+ };
47
+
48
+ export const discordGateway = (
49
+ open: (url: string) => GatewaySocket,
50
+ token: string,
51
+ clock: GatewayClock,
52
+ report: (line: string) => void,
53
+ options: GatewayOptions,
54
+ ) => {
55
+ const done = Promise.withResolvers<void>();
56
+ let socket: GatewaySocket | undefined;
57
+ let session: { id: string; url: string } | undefined;
58
+ let seq: number | null = null;
59
+ let stopped = false;
60
+ let heartbeat: unknown;
61
+ let handshake: unknown;
62
+ let retry: unknown;
63
+ let readyAt: number | undefined;
64
+ let acknowledged = false;
65
+ let lastIdentify = -Infinity;
66
+ let backoff = 5_000;
67
+ /** The established connection's sender: set on READY/RESUMED, cleared whenever that socket is retired. */
68
+ let deliver: ((frame: unknown) => boolean) | undefined;
69
+ const dispose = (code: number) => {
70
+ const previous = socket;
71
+ socket = undefined;
72
+ deliver = undefined;
73
+ if (heartbeat !== undefined) clock.clearTimeout(heartbeat);
74
+ if (handshake !== undefined) clock.clearTimeout(handshake);
75
+ heartbeat = handshake = undefined;
76
+ previous?.close(code);
77
+ if (previous) options.onDisconnect?.();
78
+ options.onHealth?.(false);
79
+ };
80
+ const finish = (error?: MessengerError) => {
81
+ stopped = true;
82
+ if (retry !== undefined) clock.clearTimeout(retry);
83
+ retry = undefined;
84
+ dispose(1000);
85
+ if (error) done.reject(error);
86
+ else done.resolve();
87
+ };
88
+ const forget = () => {
89
+ session = undefined;
90
+ seq = null;
91
+ };
92
+ const reconnect = (reason: string, code = 0, requested?: number) => {
93
+ if (stopped || retry !== undefined) return;
94
+ if (acknowledged && readyAt !== undefined && clock.now() - readyAt >= 60_000) {
95
+ backoff = 5_000;
96
+ }
97
+ readyAt = undefined;
98
+ acknowledged = false;
99
+ dispose(4000);
100
+ let delay = requested ?? backoff;
101
+ if (code === 4008) delay = Math.max(delay, 60_000);
102
+ if (!session) delay = Math.max(delay, 5_000 - (clock.now() - lastIdentify));
103
+ backoff = Math.min(backoff * 2, 300_000);
104
+ report(`${options.label}_RECONNECT discord reason=${reason} code=${code} retry_in=${delay / 1000}s`);
105
+ retry = clock.setTimeout(() => {
106
+ retry = undefined;
107
+ connect();
108
+ }, delay);
109
+ };
110
+ const connect = () => {
111
+ if (stopped) return;
112
+ let ws: GatewaySocket;
113
+ try {
114
+ ws = open(session?.url ?? GATEWAY);
115
+ } catch {
116
+ reconnect("connect_error");
117
+ return;
118
+ }
119
+ socket = ws;
120
+ let hello = false;
121
+ let authenticated = false;
122
+ let awaitingAck = false;
123
+ let heartbeatSeq: number | null = null;
124
+ let established = false;
125
+ let resuming = false;
126
+ const current = () => !stopped && socket === ws;
127
+ const send = (frame: unknown) => {
128
+ try {
129
+ ws.send(JSON.stringify(frame));
130
+ return current();
131
+ } catch {
132
+ reconnect("socket_error");
133
+ return false;
134
+ }
135
+ };
136
+ const beat = () => {
137
+ heartbeatSeq = seq;
138
+ if (send({ op: 1, d: heartbeatSeq })) awaitingAck = true;
139
+ };
140
+ const tick = (interval: number) => {
141
+ if (!current()) return;
142
+ if (awaitingAck) return reconnect("heartbeat_timeout");
143
+ beat();
144
+ if (current()) heartbeat = clock.setTimeout(() => tick(interval), interval);
145
+ };
146
+ handshake = clock.setTimeout(() => reconnect("handshake_timeout"), 30_000);
147
+ ws.onClose((code) => {
148
+ if (!current()) return;
149
+ const terminal = TERMINAL[code];
150
+ if (terminal) return finish(new MessengerError(`Discord gateway closed code=${code} (${terminal})`, code));
151
+ if (code === 1000 || code === 1001 || code === 4007 || code === 4009) forget();
152
+ reconnect("closed", code);
153
+ });
154
+ ws.onError(() => {
155
+ if (current()) reconnect("socket_error");
156
+ });
157
+ ws.onMessage((raw) => {
158
+ if (!current()) return;
159
+ let m: Payload;
160
+ try {
161
+ m = JSON.parse(raw) as Payload;
162
+ if (!m || typeof m !== "object" || typeof m.op !== "number") throw new Error();
163
+ } catch {
164
+ reconnect("invalid_payload");
165
+ return;
166
+ }
167
+ if (m.op === 0 && typeof m.s === "number") seq = m.s;
168
+ if (m.op === 10) {
169
+ const interval = m.d && typeof m.d === "object" ? m.d.heartbeat_interval : undefined;
170
+ if (hello || typeof interval !== "number" || !Number.isFinite(interval) || interval <= 0) {
171
+ reconnect("invalid_hello");
172
+ return;
173
+ }
174
+ hello = true;
175
+ heartbeat = clock.setTimeout(() => tick(interval), clock.random() * interval);
176
+ resuming = session !== undefined && seq !== null;
177
+ authenticated = send(
178
+ session && seq !== null
179
+ ? { op: 6, d: { token, session_id: session.id, seq } }
180
+ : {
181
+ op: 2,
182
+ d: {
183
+ token,
184
+ intents: options.intents,
185
+ properties: { os: process.platform, browser: "dori", device: "dori" },
186
+ ...(options.online ? { presence: ONLINE } : {}),
187
+ },
188
+ },
189
+ );
190
+ if (!session && authenticated) lastIdentify = clock.now();
191
+ } else if (m.op === 11 && awaitingAck) {
192
+ awaitingAck = false;
193
+ if (deliver) options.onHealth?.(true);
194
+ if (!acknowledged) {
195
+ acknowledged = true;
196
+ report(`${options.label}_ACK discord seq=${heartbeatSeq ?? "-"}`);
197
+ }
198
+ } else if (m.op === 1 && hello) {
199
+ beat();
200
+ } else if (m.op === 7) {
201
+ reconnect("server_reconnect", 0, 0);
202
+ } else if (m.op === 9) {
203
+ if (m.d !== true) forget();
204
+ reconnect("invalid_session", 0, 1_000 + Math.floor(clock.random() * 4_000));
205
+ } else if (m.op === 0 && (m.t === "READY" || m.t === "RESUMED")) {
206
+ if (!hello || !authenticated || seq === null) return reconnect("invalid_session_dispatch");
207
+ if (m.t === "READY") {
208
+ try {
209
+ if (!m.d || typeof m.d !== "object" || !m.d.session_id || !m.d.resume_gateway_url) throw new Error();
210
+ const url = new URL(m.d.resume_gateway_url);
211
+ if (url.protocol !== "wss:" || !url.hostname.endsWith(".discord.gg") || url.username || url.password) {
212
+ throw new Error();
213
+ }
214
+ url.search = "?v=10&encoding=json";
215
+ session = { id: m.d.session_id, url: url.href };
216
+ } catch {
217
+ reconnect("invalid_session_dispatch");
218
+ return;
219
+ }
220
+ } else if (!session || (options.online && !send({ op: 3, d: ONLINE }))) {
221
+ return;
222
+ }
223
+ if (handshake !== undefined) clock.clearTimeout(handshake);
224
+ handshake = undefined;
225
+ readyAt = clock.now();
226
+ report(`${options.label}_READY discord event=${m.t}`);
227
+ established = true;
228
+ deliver = send;
229
+ options.onReady?.(m.t);
230
+ } else if (
231
+ m.op === 0 &&
232
+ (established || (options.replayDispatches && authenticated && resuming)) &&
233
+ typeof m.t === "string"
234
+ ) {
235
+ options.onDispatch?.(m.t, m.d);
236
+ }
237
+ });
238
+ };
239
+ connect();
240
+ return {
241
+ done: done.promise,
242
+ /** Sends one frame on the current authenticated connection; false before READY/RESUMED, reconnecting or closed. */
243
+ send: (payload: unknown): boolean => deliver?.(payload) ?? false,
244
+ close() {
245
+ if (stopped) return;
246
+ finish();
247
+ report(`${options.label}_STOPPED discord`);
248
+ },
249
+ };
250
+ };