@evomap/evolver-core 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/dist/algo/antiDistill.d.ts +35 -0
  2. package/dist/algo/antiDistill.js +167 -0
  3. package/dist/algo/bans.d.ts +6 -0
  4. package/dist/algo/bans.js +33 -0
  5. package/dist/algo/candidateAssembly.d.ts +65 -0
  6. package/dist/algo/candidateAssembly.js +196 -0
  7. package/dist/algo/capabilityCandidates.d.ts +38 -0
  8. package/dist/algo/capabilityCandidates.js +131 -0
  9. package/dist/algo/confidence.d.ts +106 -0
  10. package/dist/algo/confidence.js +196 -0
  11. package/dist/algo/cycleEngine.d.ts +143 -0
  12. package/dist/algo/cycleEngine.js +417 -0
  13. package/dist/algo/cycleFailureClassifier.d.ts +52 -0
  14. package/dist/algo/cycleFailureClassifier.js +104 -0
  15. package/dist/algo/epigenetics.d.ts +14 -0
  16. package/dist/algo/epigenetics.js +41 -0
  17. package/dist/algo/evolutionEvent.d.ts +23 -0
  18. package/dist/algo/evolutionEvent.js +24 -0
  19. package/dist/algo/exploration.d.ts +34 -0
  20. package/dist/algo/exploration.js +55 -0
  21. package/dist/algo/geneHealth.d.ts +24 -0
  22. package/dist/algo/geneHealth.js +16 -0
  23. package/dist/algo/geneIntake.d.ts +37 -0
  24. package/dist/algo/geneIntake.js +100 -0
  25. package/dist/algo/genePromotion.d.ts +48 -0
  26. package/dist/algo/genePromotion.js +53 -0
  27. package/dist/algo/geneSelection.d.ts +128 -0
  28. package/dist/algo/geneSelection.js +222 -0
  29. package/dist/algo/index.d.ts +18 -0
  30. package/dist/algo/index.js +18 -0
  31. package/dist/algo/mutation.d.ts +12 -0
  32. package/dist/algo/mutation.js +22 -0
  33. package/dist/algo/orchestrator.d.ts +65 -0
  34. package/dist/algo/orchestrator.js +63 -0
  35. package/dist/algo/solidify.d.ts +43 -0
  36. package/dist/algo/solidify.js +63 -0
  37. package/dist/algo/strategyPresets.d.ts +32 -0
  38. package/dist/algo/strategyPresets.js +61 -0
  39. package/dist/assetstore/index.d.ts +8 -0
  40. package/dist/assetstore/index.js +8 -0
  41. package/dist/assetstore/learningHistory.d.ts +25 -0
  42. package/dist/assetstore/learningHistory.js +38 -0
  43. package/dist/assetstore/localJsonl.d.ts +34 -0
  44. package/dist/assetstore/localJsonl.js +182 -0
  45. package/dist/assetstore/pendingSignals.d.ts +22 -0
  46. package/dist/assetstore/pendingSignals.js +171 -0
  47. package/dist/assetstore/provenance.d.ts +39 -0
  48. package/dist/assetstore/provenance.js +109 -0
  49. package/dist/assetstore/provider.d.ts +48 -0
  50. package/dist/assetstore/provider.js +36 -0
  51. package/dist/assetstore/remoteStub.d.ts +32 -0
  52. package/dist/assetstore/remoteStub.js +36 -0
  53. package/dist/assetstore/reviewFilter.d.ts +20 -0
  54. package/dist/assetstore/reviewFilter.js +44 -0
  55. package/dist/assetstore/reviewLedger.d.ts +55 -0
  56. package/dist/assetstore/reviewLedger.js +121 -0
  57. package/dist/benchmark/antiGeneBenchmark.d.ts +79 -0
  58. package/dist/benchmark/antiGeneBenchmark.js +241 -0
  59. package/dist/benchmark/antiGeneRollout.d.ts +80 -0
  60. package/dist/benchmark/antiGeneRollout.js +256 -0
  61. package/dist/benchmark/benchmark.d.ts +32 -0
  62. package/dist/benchmark/benchmark.js +26 -0
  63. package/dist/benchmark/evolutionThesisSolver.d.ts +25 -0
  64. package/dist/benchmark/evolutionThesisSolver.js +41 -0
  65. package/dist/benchmark/index.d.ts +5 -0
  66. package/dist/benchmark/index.js +5 -0
  67. package/dist/benchmark/thesis.d.ts +85 -0
  68. package/dist/benchmark/thesis.js +150 -0
  69. package/dist/bootstrap/envFingerprint.d.ts +45 -0
  70. package/dist/bootstrap/envFingerprint.js +72 -0
  71. package/dist/bootstrap/index.d.ts +2 -0
  72. package/dist/bootstrap/index.js +2 -0
  73. package/dist/bootstrap/selfEvolve.d.ts +36 -0
  74. package/dist/bootstrap/selfEvolve.js +26 -0
  75. package/dist/cycle/cycleTimeline.d.ts +35 -0
  76. package/dist/cycle/cycleTimeline.js +74 -0
  77. package/dist/cycle/index.d.ts +2 -0
  78. package/dist/cycle/index.js +2 -0
  79. package/dist/cycle/stateMachine.d.ts +6 -0
  80. package/dist/cycle/stateMachine.js +25 -0
  81. package/dist/daemon/cycleContext.d.ts +12 -0
  82. package/dist/daemon/cycleContext.js +13 -0
  83. package/dist/daemon/drain.d.ts +11 -0
  84. package/dist/daemon/drain.js +16 -0
  85. package/dist/daemon/guards.d.ts +87 -0
  86. package/dist/daemon/guards.js +142 -0
  87. package/dist/daemon/idempotency.d.ts +11 -0
  88. package/dist/daemon/idempotency.js +36 -0
  89. package/dist/daemon/idleScheduler.d.ts +55 -0
  90. package/dist/daemon/idleScheduler.js +181 -0
  91. package/dist/daemon/index.d.ts +8 -0
  92. package/dist/daemon/index.js +8 -0
  93. package/dist/daemon/stepRunner.d.ts +12 -0
  94. package/dist/daemon/stepRunner.js +31 -0
  95. package/dist/daemon/unhandledRejectionWindow.d.ts +21 -0
  96. package/dist/daemon/unhandledRejectionWindow.js +52 -0
  97. package/dist/daemon/watchdog.d.ts +11 -0
  98. package/dist/daemon/watchdog.js +14 -0
  99. package/dist/events/eventSchema.d.ts +132 -0
  100. package/dist/events/eventSchema.js +30 -0
  101. package/dist/events/eventStore.d.ts +32 -0
  102. package/dist/events/eventStore.js +137 -0
  103. package/dist/events/ingest.d.ts +34 -0
  104. package/dist/events/ingest.js +61 -0
  105. package/dist/events/paths.d.ts +22 -0
  106. package/dist/events/paths.js +44 -0
  107. package/dist/events/projectors.d.ts +9 -0
  108. package/dist/events/projectors.js +11 -0
  109. package/dist/events/public.d.ts +14 -0
  110. package/dist/events/public.js +8 -0
  111. package/dist/events/replayer.d.ts +26 -0
  112. package/dist/events/replayer.js +67 -0
  113. package/dist/events/reports.d.ts +90 -0
  114. package/dist/events/reports.js +244 -0
  115. package/dist/events/retention.d.ts +70 -0
  116. package/dist/events/retention.js +177 -0
  117. package/dist/events/sink.d.ts +5 -0
  118. package/dist/events/sink.js +1 -0
  119. package/dist/exec/autoExec.d.ts +137 -0
  120. package/dist/exec/autoExec.js +221 -0
  121. package/dist/exec/autonomousCycle.d.ts +48 -0
  122. package/dist/exec/autonomousCycle.js +78 -0
  123. package/dist/exec/claudeBridge.d.ts +112 -0
  124. package/dist/exec/claudeBridge.js +219 -0
  125. package/dist/exec/index.d.ts +9 -0
  126. package/dist/exec/index.js +11 -0
  127. package/dist/exec/openPrRegistry.d.ts +60 -0
  128. package/dist/exec/openPrRegistry.js +130 -0
  129. package/dist/exec/policy/blastRadius.d.ts +31 -0
  130. package/dist/exec/policy/blastRadius.js +67 -0
  131. package/dist/exec/policy/constraints.d.ts +26 -0
  132. package/dist/exec/policy/constraints.js +62 -0
  133. package/dist/exec/policy/destructive.d.ts +45 -0
  134. package/dist/exec/policy/destructive.js +108 -0
  135. package/dist/exec/policy/failureMode.d.ts +33 -0
  136. package/dist/exec/policy/failureMode.js +49 -0
  137. package/dist/exec/policy/index.d.ts +24 -0
  138. package/dist/exec/policy/index.js +30 -0
  139. package/dist/exec/policy/protectedPaths.d.ts +17 -0
  140. package/dist/exec/policy/protectedPaths.js +65 -0
  141. package/dist/exec/policyCheck.d.ts +2 -0
  142. package/dist/exec/policyCheck.js +7 -0
  143. package/dist/exec/prompt.d.ts +34 -0
  144. package/dist/exec/prompt.js +108 -0
  145. package/dist/exec/proofOfWork.d.ts +9 -0
  146. package/dist/exec/proofOfWork.js +11 -0
  147. package/dist/exec/runnerRegistry.d.ts +123 -0
  148. package/dist/exec/runnerRegistry.js +237 -0
  149. package/dist/exec/selfPr.d.ts +83 -0
  150. package/dist/exec/selfPr.js +104 -0
  151. package/dist/exec/selfPrObfuscation.d.ts +21 -0
  152. package/dist/exec/selfPrObfuscation.js +85 -0
  153. package/dist/hooks/hooks.d.ts +117 -0
  154. package/dist/hooks/hooks.js +89 -0
  155. package/dist/hooks/index.d.ts +1 -0
  156. package/dist/hooks/index.js +1 -0
  157. package/dist/hub/assetCallLog.d.ts +43 -0
  158. package/dist/hub/assetCallLog.js +72 -0
  159. package/dist/hub/bindings.d.ts +28 -0
  160. package/dist/hub/bindings.js +90 -0
  161. package/dist/hub/capability.d.ts +278 -0
  162. package/dist/hub/capability.js +1 -0
  163. package/dist/hub/conversationDistiller.d.ts +88 -0
  164. package/dist/hub/conversationDistiller.js +264 -0
  165. package/dist/hub/fake.d.ts +45 -0
  166. package/dist/hub/fake.js +69 -0
  167. package/dist/hub/hubReview.d.ts +91 -0
  168. package/dist/hub/hubReview.js +106 -0
  169. package/dist/hub/index.d.ts +10 -0
  170. package/dist/hub/index.js +10 -0
  171. package/dist/hub/ingest.d.ts +15 -0
  172. package/dist/hub/ingest.js +15 -0
  173. package/dist/hub/questionGenerator.d.ts +59 -0
  174. package/dist/hub/questionGenerator.js +406 -0
  175. package/dist/hub/reuseDecision.d.ts +87 -0
  176. package/dist/hub/reuseDecision.js +127 -0
  177. package/dist/hub/sanitize.d.ts +52 -0
  178. package/dist/hub/sanitize.js +321 -0
  179. package/dist/index.d.ts +27 -0
  180. package/dist/index.js +27 -0
  181. package/dist/mailbox/catalog.d.ts +17 -0
  182. package/dist/mailbox/catalog.js +53 -0
  183. package/dist/mailbox/daemon.d.ts +48 -0
  184. package/dist/mailbox/daemon.js +61 -0
  185. package/dist/mailbox/dispatch.d.ts +46 -0
  186. package/dist/mailbox/dispatch.js +62 -0
  187. package/dist/mailbox/envelope.d.ts +43 -0
  188. package/dist/mailbox/envelope.js +52 -0
  189. package/dist/mailbox/index.d.ts +8 -0
  190. package/dist/mailbox/index.js +8 -0
  191. package/dist/mailbox/ipcServer.d.ts +46 -0
  192. package/dist/mailbox/ipcServer.js +168 -0
  193. package/dist/mailbox/requestReply.d.ts +40 -0
  194. package/dist/mailbox/requestReply.js +77 -0
  195. package/dist/mailbox/store.d.ts +74 -0
  196. package/dist/mailbox/store.js +308 -0
  197. package/dist/mailbox/wake.d.ts +45 -0
  198. package/dist/mailbox/wake.js +60 -0
  199. package/dist/material/boundary.d.ts +7 -0
  200. package/dist/material/boundary.js +14 -0
  201. package/dist/material/consumer.d.ts +21 -0
  202. package/dist/material/consumer.js +52 -0
  203. package/dist/material/emit.d.ts +55 -0
  204. package/dist/material/emit.js +52 -0
  205. package/dist/material/factory.d.ts +27 -0
  206. package/dist/material/factory.js +25 -0
  207. package/dist/material/index.d.ts +8 -0
  208. package/dist/material/index.js +8 -0
  209. package/dist/material/materialStore.d.ts +24 -0
  210. package/dist/material/materialStore.js +76 -0
  211. package/dist/material/sampling.d.ts +21 -0
  212. package/dist/material/sampling.js +39 -0
  213. package/dist/material/sources.d.ts +25 -0
  214. package/dist/material/sources.js +33 -0
  215. package/dist/material/watermark.d.ts +21 -0
  216. package/dist/material/watermark.js +76 -0
  217. package/dist/observers/cursorRewriteObserver.d.ts +46 -0
  218. package/dist/observers/cursorRewriteObserver.js +103 -0
  219. package/dist/observers/distillObserver.d.ts +31 -0
  220. package/dist/observers/distillObserver.js +93 -0
  221. package/dist/observers/index.d.ts +5 -0
  222. package/dist/observers/index.js +5 -0
  223. package/dist/observers/observerBus.d.ts +44 -0
  224. package/dist/observers/observerBus.js +73 -0
  225. package/dist/observers/reflectionObserver.d.ts +31 -0
  226. package/dist/observers/reflectionObserver.js +124 -0
  227. package/dist/observers/valueDigestObserver.d.ts +50 -0
  228. package/dist/observers/valueDigestObserver.js +70 -0
  229. package/dist/ops/cleanup.d.ts +23 -0
  230. package/dist/ops/cleanup.js +68 -0
  231. package/dist/ops/health.d.ts +37 -0
  232. package/dist/ops/health.js +96 -0
  233. package/dist/ops/index.d.ts +7 -0
  234. package/dist/ops/index.js +7 -0
  235. package/dist/ops/recall.d.ts +65 -0
  236. package/dist/ops/recall.js +152 -0
  237. package/dist/ops/reuseOutcomes.d.ts +68 -0
  238. package/dist/ops/reuseOutcomes.js +126 -0
  239. package/dist/ops/savingsCore.d.ts +47 -0
  240. package/dist/ops/savingsCore.js +112 -0
  241. package/dist/ops/selfUpdate.d.ts +106 -0
  242. package/dist/ops/selfUpdate.js +294 -0
  243. package/dist/ops/valueLedger.d.ts +205 -0
  244. package/dist/ops/valueLedger.js +238 -0
  245. package/dist/ops/valueOutreach.d.ts +70 -0
  246. package/dist/ops/valueOutreach.js +244 -0
  247. package/dist/personality/drift.d.ts +45 -0
  248. package/dist/personality/drift.js +106 -0
  249. package/dist/personality/events.d.ts +25 -0
  250. package/dist/personality/events.js +37 -0
  251. package/dist/personality/evolveOps.d.ts +20 -0
  252. package/dist/personality/evolveOps.js +93 -0
  253. package/dist/personality/index.d.ts +11 -0
  254. package/dist/personality/index.js +11 -0
  255. package/dist/personality/mutate.d.ts +21 -0
  256. package/dist/personality/mutate.js +39 -0
  257. package/dist/personality/pivot.d.ts +23 -0
  258. package/dist/personality/pivot.js +22 -0
  259. package/dist/personality/prompt.d.ts +6 -0
  260. package/dist/personality/prompt.js +62 -0
  261. package/dist/personality/riskGate.d.ts +42 -0
  262. package/dist/personality/riskGate.js +80 -0
  263. package/dist/personality/schema.d.ts +255 -0
  264. package/dist/personality/schema.js +119 -0
  265. package/dist/personality/select.d.ts +46 -0
  266. package/dist/personality/select.js +71 -0
  267. package/dist/personality/stats.d.ts +46 -0
  268. package/dist/personality/stats.js +82 -0
  269. package/dist/personality/store.d.ts +35 -0
  270. package/dist/personality/store.js +92 -0
  271. package/dist/schema/common.d.ts +28 -0
  272. package/dist/schema/common.js +17 -0
  273. package/dist/schema/index.d.ts +5 -0
  274. package/dist/schema/index.js +5 -0
  275. package/dist/schema/material.d.ts +201 -0
  276. package/dist/schema/material.js +50 -0
  277. package/dist/schema/problem.d.ts +160 -0
  278. package/dist/schema/problem.js +45 -0
  279. package/dist/schema/proofOfWork.d.ts +97 -0
  280. package/dist/schema/proofOfWork.js +9 -0
  281. package/dist/schema/signal.d.ts +41 -0
  282. package/dist/schema/signal.js +19 -0
  283. package/dist/shadow/index.d.ts +6 -0
  284. package/dist/shadow/index.js +6 -0
  285. package/dist/shadow/jsonlSink.d.ts +17 -0
  286. package/dist/shadow/jsonlSink.js +27 -0
  287. package/dist/shadow/redact.d.ts +11 -0
  288. package/dist/shadow/redact.js +18 -0
  289. package/dist/shadow/shadowHub.d.ts +12 -0
  290. package/dist/shadow/shadowHub.js +42 -0
  291. package/dist/shadow/shadowMailbox.d.ts +17 -0
  292. package/dist/shadow/shadowMailbox.js +25 -0
  293. package/dist/shadow/shadowStore.d.ts +18 -0
  294. package/dist/shadow/shadowStore.js +55 -0
  295. package/dist/shadow/sink.d.ts +37 -0
  296. package/dist/shadow/sink.js +18 -0
  297. package/dist/signals/cycleHistoryFromEvents.d.ts +11 -0
  298. package/dist/signals/cycleHistoryFromEvents.js +96 -0
  299. package/dist/signals/expand.d.ts +34 -0
  300. package/dist/signals/expand.js +125 -0
  301. package/dist/signals/extractor.d.ts +25 -0
  302. package/dist/signals/extractor.js +57 -0
  303. package/dist/signals/index.d.ts +6 -0
  304. package/dist/signals/index.js +6 -0
  305. package/dist/signals/metaSignals.d.ts +57 -0
  306. package/dist/signals/metaSignals.js +158 -0
  307. package/dist/signals/signalGate.d.ts +15 -0
  308. package/dist/signals/signalGate.js +40 -0
  309. package/dist/signals/traceSignals.d.ts +44 -0
  310. package/dist/signals/traceSignals.js +123 -0
  311. package/dist/signatures/classifier.d.ts +16 -0
  312. package/dist/signatures/classifier.js +29 -0
  313. package/dist/signatures/index.d.ts +2 -0
  314. package/dist/signatures/index.js +2 -0
  315. package/dist/signatures/signatures.d.ts +22 -0
  316. package/dist/signatures/signatures.js +42 -0
  317. package/dist/strategy/experiment.d.ts +48 -0
  318. package/dist/strategy/experiment.js +63 -0
  319. package/dist/strategy/index.d.ts +2 -0
  320. package/dist/strategy/index.js +2 -0
  321. package/dist/strategy/strategyPoint.d.ts +30 -0
  322. package/dist/strategy/strategyPoint.js +23 -0
  323. package/dist/trace/index.d.ts +2 -0
  324. package/dist/trace/index.js +2 -0
  325. package/dist/trace/trajectory.d.ts +82 -0
  326. package/dist/trace/trajectory.js +117 -0
  327. package/dist/trace/trajectoryExport.d.ts +237 -0
  328. package/dist/trace/trajectoryExport.js +1818 -0
  329. package/dist/trigger/budget.d.ts +16 -0
  330. package/dist/trigger/budget.js +20 -0
  331. package/dist/trigger/engine.d.ts +12 -0
  332. package/dist/trigger/engine.js +23 -0
  333. package/dist/trigger/index.d.ts +6 -0
  334. package/dist/trigger/index.js +6 -0
  335. package/dist/trigger/problemBuilder.d.ts +24 -0
  336. package/dist/trigger/problemBuilder.js +32 -0
  337. package/dist/trigger/trigger.d.ts +22 -0
  338. package/dist/trigger/trigger.js +27 -0
  339. package/dist/trigger/valueModel.d.ts +26 -0
  340. package/dist/trigger/valueModel.js +25 -0
  341. package/dist/trigger/wfq.d.ts +13 -0
  342. package/dist/trigger/wfq.js +25 -0
  343. package/dist/util/fileLock.d.ts +24 -0
  344. package/dist/util/fileLock.js +227 -0
  345. package/dist/util/index.d.ts +2 -0
  346. package/dist/util/index.js +2 -0
  347. package/dist/util/version.d.ts +12 -0
  348. package/dist/util/version.js +51 -0
  349. package/dist/verify/index.d.ts +4 -0
  350. package/dist/verify/index.js +4 -0
  351. package/dist/verify/rollback.d.ts +22 -0
  352. package/dist/verify/rollback.js +33 -0
  353. package/dist/verify/sandboxRunner.d.ts +39 -0
  354. package/dist/verify/sandboxRunner.js +116 -0
  355. package/dist/verify/sandboxedValidation.d.ts +35 -0
  356. package/dist/verify/sandboxedValidation.js +56 -0
  357. package/dist/verify/validation.d.ts +41 -0
  358. package/dist/verify/validation.js +85 -0
  359. package/dist/wire/canonicalize.golden.d.ts +23 -0
  360. package/dist/wire/canonicalize.golden.js +46 -0
  361. package/dist/wire/geneHints.d.ts +64 -0
  362. package/dist/wire/geneHints.js +100 -0
  363. package/dist/wire/index.d.ts +91 -0
  364. package/dist/wire/index.js +3 -0
  365. package/dist/wire/schemaGate.d.ts +11 -0
  366. package/dist/wire/schemaGate.js +49 -0
  367. package/dist/workflow/dsl.d.ts +54 -0
  368. package/dist/workflow/dsl.js +15 -0
  369. package/dist/workflow/engine.d.ts +30 -0
  370. package/dist/workflow/engine.js +94 -0
  371. package/dist/workflow/index.d.ts +2 -0
  372. package/dist/workflow/index.js +2 -0
  373. package/package.json +29 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 选择性 Material 判定(M2-7). 默认遵目录 feedsMaterial; 两类在 dispatch 决定:
3
+ * - asset_publish_result: 仅 rejected 进(失败=养料 #40); 通过无需.
4
+ * - swarm.*: 仅带结论的进; 中间消息不进.
5
+ */
6
+ export function shouldFeedMaterial(e) {
7
+ if (e.type === 'asset_publish_result') {
8
+ return e.payload?.status === 'rejected';
9
+ }
10
+ if (e.type.startsWith('swarm.')) {
11
+ const p = e.payload;
12
+ return p?.conclusion !== undefined || p?.final === true;
13
+ }
14
+ return e.feedsMaterial;
15
+ }
16
+ /**
17
+ * 三-handler 分派器(M2-7). 谁 claim 谁 complete:
18
+ * - daemon 侧 pump core+proxy(确定性/hub 往返).
19
+ * - agent 类常由外部 runtime 经 IPC(M2-6) claim+complete; 嵌入式可显式 pump ['agent'].
20
+ */
21
+ export class Dispatcher {
22
+ deps;
23
+ constructor(deps) {
24
+ this.deps = deps;
25
+ }
26
+ async dispatchOne(e) {
27
+ const now = this.deps.now();
28
+ // 副作用幂等: 业务键(非默认=id)命中 → 跳过不二次执行, 直接 complete (money-safety A7/A13)
29
+ const sideEffecting = e.handler !== 'agent' && e.idempotencyKey !== e.id;
30
+ if (sideEffecting && this.deps.store.isProcessed(e.idempotencyKey)) {
31
+ this.deps.store.complete(e.id, now);
32
+ return { id: e.id, handler: e.handler, handled: true, fedMaterial: false, note: 'idempotent-skip' };
33
+ }
34
+ try {
35
+ const result = await this.deps.handlers[e.handler](e);
36
+ let fedMaterial = false;
37
+ if (this.deps.onMaterial && shouldFeedMaterial(e)) {
38
+ await this.deps.onMaterial(e);
39
+ fedMaterial = true;
40
+ }
41
+ if (sideEffecting)
42
+ this.deps.store.markProcessed(e.idempotencyKey, result ?? null, now);
43
+ this.deps.store.complete(e.id, now);
44
+ return { id: e.id, handler: e.handler, handled: true, fedMaterial };
45
+ }
46
+ catch (err) {
47
+ this.deps.store.fail(e.id, err instanceof Error ? err.message : String(err), now);
48
+ return { id: e.id, handler: e.handler, handled: false, fedMaterial: false, note: 'failed' };
49
+ }
50
+ }
51
+ /** 拉一批并分派. 默认 daemon 侧 core+proxy; agent 由 runtime 经 IPC 拉取. */
52
+ async pump(opts = {}) {
53
+ const kinds = opts.handlers ?? ['core', 'proxy'];
54
+ const out = [];
55
+ for (const k of kinds) {
56
+ const batch = this.deps.store.claim(k, opts.limit ?? 16, opts.leaseMs ?? 30_000, this.deps.now(), opts.runtimeNamespace);
57
+ for (const e of batch)
58
+ out.push(await this.dispatchOne(e));
59
+ }
60
+ return out;
61
+ }
62
+ }
@@ -0,0 +1,43 @@
1
+ import { specForType, type Direction, type Handler } from './catalog.js';
2
+ export type Status = 'pending' | 'in_flight' | 'done' | 'failed' | 'expired';
3
+ export declare const ENVELOPE_SCHEMA_VERSION = "1.0.0";
4
+ export interface Envelope {
5
+ id: string;
6
+ type: string;
7
+ direction: Direction;
8
+ status: Status;
9
+ handler: Handler;
10
+ payload: unknown;
11
+ correlationId: string;
12
+ replyTo: string | null;
13
+ receiptId: string;
14
+ idempotencyKey: string;
15
+ sourceAgent: string;
16
+ targetAgent: string;
17
+ runtimeNamespace: string;
18
+ attempts: number;
19
+ nextRetryAt: number | null;
20
+ ttlAt: number | null;
21
+ createdAt: number;
22
+ updatedAt: number;
23
+ schemaVersion: string;
24
+ feedsMaterial: boolean;
25
+ }
26
+ /** 固定 envelope 字段集 (schema-snapshot 锁; 增删字段必须改此处). */
27
+ export declare const ENVELOPE_FIELDS: readonly (keyof Envelope)[];
28
+ /** 防原型污染 (v1 GHSA). */
29
+ export declare function sanitizePayload(v: unknown): unknown;
30
+ export interface CreateEnvelopeInput {
31
+ id?: string;
32
+ type: string;
33
+ payload?: unknown;
34
+ correlationId?: string;
35
+ replyTo?: string | null;
36
+ idempotencyKey?: string;
37
+ sourceAgent?: string;
38
+ targetAgent?: string;
39
+ runtimeNamespace?: string;
40
+ now?: number;
41
+ }
42
+ export declare function createEnvelope(input: CreateEnvelopeInput): Envelope;
43
+ export { specForType };
@@ -0,0 +1,52 @@
1
+ import { ulid as makeUlid } from 'ulid';
2
+ import { specForType, assertKnownType } from './catalog.js';
3
+ export const ENVELOPE_SCHEMA_VERSION = '1.0.0';
4
+ /** 固定 envelope 字段集 (schema-snapshot 锁; 增删字段必须改此处). */
5
+ export const ENVELOPE_FIELDS = [
6
+ 'id', 'type', 'direction', 'status', 'handler', 'payload', 'correlationId', 'replyTo',
7
+ 'receiptId', 'idempotencyKey', 'sourceAgent', 'targetAgent', 'runtimeNamespace',
8
+ 'attempts', 'nextRetryAt', 'ttlAt', 'createdAt', 'updatedAt', 'schemaVersion', 'feedsMaterial',
9
+ ];
10
+ const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
11
+ /** 防原型污染 (v1 GHSA). */
12
+ export function sanitizePayload(v) {
13
+ if (Array.isArray(v))
14
+ return v.map(sanitizePayload);
15
+ if (v && typeof v === 'object') {
16
+ const out = {};
17
+ for (const [k, val] of Object.entries(v))
18
+ if (!FORBIDDEN_KEYS.has(k))
19
+ out[k] = sanitizePayload(val);
20
+ return out;
21
+ }
22
+ return v;
23
+ }
24
+ const TTL_MS = { control: 60 * 60 * 1000, default: 7 * 24 * 60 * 60 * 1000 };
25
+ export function createEnvelope(input) {
26
+ const spec = assertKnownType(input.type);
27
+ const id = input.id ?? makeUlid();
28
+ const now = input.now ?? Date.now();
29
+ return {
30
+ id,
31
+ type: input.type,
32
+ direction: spec.direction,
33
+ status: 'pending',
34
+ handler: spec.handler,
35
+ payload: sanitizePayload(input.payload ?? {}),
36
+ correlationId: input.correlationId ?? id,
37
+ replyTo: input.replyTo ?? null,
38
+ receiptId: id, // 投递即返(异步不变量)
39
+ idempotencyKey: input.idempotencyKey ?? id, // 副作用类型应传业务键(硬化 A13)
40
+ sourceAgent: input.sourceAgent ?? '',
41
+ targetAgent: input.targetAgent ?? '',
42
+ runtimeNamespace: input.runtimeNamespace ?? 'default',
43
+ attempts: 0,
44
+ nextRetryAt: null,
45
+ ttlAt: now + TTL_MS[spec.ttlClass],
46
+ createdAt: now,
47
+ updatedAt: now,
48
+ schemaVersion: ENVELOPE_SCHEMA_VERSION,
49
+ feedsMaterial: spec.feedsMaterial,
50
+ };
51
+ }
52
+ export { specForType };
@@ -0,0 +1,8 @@
1
+ export * from './catalog.js';
2
+ export * from './envelope.js';
3
+ export * from './store.js';
4
+ export * from './requestReply.js';
5
+ export * from './ipcServer.js';
6
+ export * from './dispatch.js';
7
+ export * from './wake.js';
8
+ export * from './daemon.js';
@@ -0,0 +1,8 @@
1
+ export * from './catalog.js';
2
+ export * from './envelope.js';
3
+ export * from './store.js';
4
+ export * from './requestReply.js';
5
+ export * from './ipcServer.js';
6
+ export * from './dispatch.js';
7
+ export * from './wake.js';
8
+ export * from './daemon.js';
@@ -0,0 +1,46 @@
1
+ import { type IncomingMessage, type ServerResponse } from 'node:http';
2
+ import { type Envelope } from './envelope.js';
3
+ import type { MailboxStore } from './store.js';
4
+ export interface IpcServerOptions {
5
+ store: MailboxStore;
6
+ token: string;
7
+ host?: string;
8
+ now?: () => number;
9
+ extraRoutes?: IpcRouteHandler[];
10
+ onSend?: (envelope: Envelope, result: {
11
+ receiptId: string;
12
+ stored: boolean;
13
+ }) => void;
14
+ onAuthFailure?: () => void;
15
+ }
16
+ export interface IpcRouteContext {
17
+ req: IncomingMessage;
18
+ res: ServerResponse;
19
+ url: URL;
20
+ route: string;
21
+ now: number;
22
+ store: MailboxStore;
23
+ readJson: () => Promise<unknown>;
24
+ json: (code: number, body: unknown) => void;
25
+ }
26
+ export type IpcRouteHandler = (ctx: IpcRouteContext) => boolean | void | Promise<boolean | void>;
27
+ /**
28
+ * 本地 HTTP IPC(M2-6): runtime adapter ↔ mailbox 的进程间通道.
29
+ * 仅绑 127.0.0.1 + Bearer token; runtimeNamespace 分区, 不同 runtime 实例互不串信箱.
30
+ */
31
+ export declare class MailboxIpcServer {
32
+ private readonly server;
33
+ private readonly store;
34
+ private readonly token;
35
+ private readonly host;
36
+ private readonly now;
37
+ private readonly extraRoutes;
38
+ private readonly onSend;
39
+ private readonly onAuthFailure;
40
+ constructor(opts: IpcServerOptions);
41
+ listen(port?: number): Promise<number>;
42
+ close(): Promise<void>;
43
+ private handle;
44
+ private readJson;
45
+ private json;
46
+ }
@@ -0,0 +1,168 @@
1
+ import { createServer } from 'node:http';
2
+ import { timingSafeEqual } from 'node:crypto';
3
+ import { createEnvelope } from './envelope.js';
4
+ const MAX_BODY = 256 * 1024; // 256KB 上限(防本机注入超大体)
5
+ const LOOPBACK = new Set(['127.0.0.1', '::1', '::ffff:127.0.0.1']);
6
+ /** 定长常量时间比较(防 token 计时侧信道). */
7
+ function tokenEq(a, b) {
8
+ const ba = Buffer.from(a), bb = Buffer.from(b);
9
+ if (ba.length !== bb.length)
10
+ return false;
11
+ return timingSafeEqual(ba, bb);
12
+ }
13
+ /**
14
+ * 本地 HTTP IPC(M2-6): runtime adapter ↔ mailbox 的进程间通道.
15
+ * 仅绑 127.0.0.1 + Bearer token; runtimeNamespace 分区, 不同 runtime 实例互不串信箱.
16
+ */
17
+ export class MailboxIpcServer {
18
+ server;
19
+ store;
20
+ token;
21
+ host;
22
+ now;
23
+ extraRoutes;
24
+ onSend;
25
+ onAuthFailure;
26
+ constructor(opts) {
27
+ this.store = opts.store;
28
+ this.token = opts.token;
29
+ this.host = opts.host ?? '127.0.0.1';
30
+ this.now = opts.now ?? (() => Date.now());
31
+ this.extraRoutes = opts.extraRoutes ?? [];
32
+ this.onSend = opts.onSend;
33
+ this.onAuthFailure = opts.onAuthFailure;
34
+ this.server = createServer((req, res) => { void this.handle(req, res); });
35
+ }
36
+ listen(port = 0) {
37
+ return new Promise((resolve, reject) => {
38
+ const cleanup = () => {
39
+ this.server.off('error', onError);
40
+ this.server.off('listening', onListening);
41
+ };
42
+ const onError = (err) => {
43
+ cleanup();
44
+ reject(err);
45
+ };
46
+ const onListening = () => {
47
+ cleanup();
48
+ const addr = this.server.address();
49
+ resolve(addr && typeof addr === 'object' ? addr.port : port);
50
+ };
51
+ this.server.once('error', onError);
52
+ this.server.once('listening', onListening);
53
+ this.server.listen(port, this.host);
54
+ });
55
+ }
56
+ close() {
57
+ return new Promise((resolve, reject) => this.server.close((e) => (e ? reject(e) : resolve())));
58
+ }
59
+ async handle(req, res) {
60
+ try {
61
+ const ra = req.socket.remoteAddress ?? '';
62
+ if (!LOOPBACK.has(ra))
63
+ return this.json(res, 403, { error: 'non-loopback' });
64
+ const auth = req.headers['authorization'] ?? '';
65
+ // Fail closed on an empty configured token: tokenEq('', '') is true, so without this guard a blank token
66
+ // would authenticate any `Authorization: Bearer ` request. An empty token never authenticates anyone.
67
+ if (!this.token || !auth.startsWith('Bearer ') || !tokenEq(auth.slice(7), this.token)) {
68
+ try {
69
+ this.onAuthFailure?.();
70
+ }
71
+ catch { /* auth failure handling must never weaken fail-closed IPC auth */ }
72
+ return this.json(res, 401, { error: 'bad token' });
73
+ }
74
+ const url = new URL(req.url ?? '/', 'http://localhost');
75
+ const route = `${req.method} ${url.pathname}`;
76
+ const now = this.now();
77
+ for (const extra of this.extraRoutes) {
78
+ const handled = await extra({
79
+ req,
80
+ res,
81
+ url,
82
+ route,
83
+ now,
84
+ store: this.store,
85
+ readJson: () => this.readJson(req),
86
+ json: (code, body) => this.json(res, code, body),
87
+ });
88
+ if (handled)
89
+ return;
90
+ }
91
+ if (route === 'POST /mailbox/send') {
92
+ const body = (await this.readJson(req));
93
+ const env = createEnvelope({ ...body, now });
94
+ const r = this.store.send(env);
95
+ if (r.stored)
96
+ this.onSend?.(env, r);
97
+ return this.json(res, 200, { id: env.id, receiptId: r.receiptId, stored: r.stored, correlationId: env.correlationId });
98
+ }
99
+ if (route === 'POST /mailbox/claim') {
100
+ const b = (await this.readJson(req));
101
+ const got = this.store.claim(b.handler, b.limit ?? 16, b.leaseMs ?? 30_000, now, b.runtimeNamespace);
102
+ return this.json(res, 200, { messages: got });
103
+ }
104
+ if (route === 'POST /mailbox/complete') {
105
+ const b = (await this.readJson(req));
106
+ this.store.complete(b.id, now);
107
+ return this.json(res, 200, { ok: true });
108
+ }
109
+ if (route === 'POST /mailbox/fail') {
110
+ const b = (await this.readJson(req));
111
+ this.store.fail(b.id, b.error ?? 'ipc fail', now);
112
+ return this.json(res, 200, { ok: true });
113
+ }
114
+ if (req.method === 'GET' && url.pathname === '/mailbox/status') {
115
+ const id = url.searchParams.get('id') ?? '';
116
+ const s = this.store.getStatus(id);
117
+ return s ? this.json(res, 200, s) : this.json(res, 404, { error: 'not found' });
118
+ }
119
+ if (req.method === 'GET' && url.pathname === '/mailbox/list') {
120
+ const status = url.searchParams.get('status') ?? undefined;
121
+ const got = this.store.list({
122
+ status: status,
123
+ handler: url.searchParams.get('handler') ?? undefined,
124
+ runtimeNamespace: url.searchParams.get('runtimeNamespace') ?? undefined,
125
+ limit: Number(url.searchParams.get('limit') ?? 200),
126
+ });
127
+ return this.json(res, 200, { messages: got });
128
+ }
129
+ return this.json(res, 404, { error: 'unknown route' });
130
+ }
131
+ catch (e) {
132
+ return this.json(res, 400, { error: e instanceof Error ? e.message : String(e) });
133
+ }
134
+ }
135
+ readJson(req) {
136
+ return new Promise((resolve, reject) => {
137
+ let size = 0;
138
+ let overflow = false;
139
+ const chunks = [];
140
+ req.on('data', (c) => {
141
+ size += c.length;
142
+ if (size > MAX_BODY) {
143
+ overflow = true;
144
+ return;
145
+ } // 不 destroy socket: 继续 drain 以保证能回 400
146
+ if (!overflow)
147
+ chunks.push(c);
148
+ });
149
+ req.on('end', () => {
150
+ if (overflow) {
151
+ reject(new Error('body too large'));
152
+ return;
153
+ }
154
+ try {
155
+ resolve(chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : {});
156
+ }
157
+ catch {
158
+ reject(new Error('invalid json'));
159
+ }
160
+ });
161
+ req.on('error', reject);
162
+ });
163
+ }
164
+ json(res, code, body) {
165
+ res.writeHead(code, { 'content-type': 'application/json' });
166
+ res.end(JSON.stringify(body));
167
+ }
168
+ }
@@ -0,0 +1,40 @@
1
+ import type { Envelope } from './envelope.js';
2
+ import type { MailboxStore } from './store.js';
3
+ /** 应答超时. correlationId 保留以便审计/重试. */
4
+ export declare class ReplyTimeoutError extends Error {
5
+ readonly correlationId: string;
6
+ constructor(correlationId: string, reason?: string);
7
+ }
8
+ /**
9
+ * 进程内应答等待器(M2-5). 一个 daemon 生命周期内: request 注册 waiter, dispatch 收到 inbound 即 notify 唤醒.
10
+ * 不持有定时器(由 sweep(now) 推进 deadline), 测试可确定性驱动; durable 兜底走 store.getReply.
11
+ */
12
+ export declare class ReplyRegistry {
13
+ private readonly waiters;
14
+ /** 注册等待 correlationId 的应答; 由 notify 解决, 由 sweep/expire 拒绝. */
15
+ await(correlationId: string, requestId: string, deadline: number): Promise<Envelope>;
16
+ /** 收到 envelope: 若是匹配关联的应答(非请求自身)则唤醒对应 waiter. */
17
+ notify(e: Envelope): boolean;
18
+ /** 推进时钟: deadline 已过的 waiter 全部超时拒绝. 返回过期数. */
19
+ sweep(now: number): number;
20
+ /** 显式过期单个关联(如收到 failed/expired 终态). */
21
+ expire(correlationId: string, reason?: string): boolean;
22
+ pending(): number;
23
+ }
24
+ /**
25
+ * 请求-应答门面: 绑定 store(durable) + registry(live).
26
+ * request 投递并注册 waiter; 应答既可经 notify 实时唤醒, 也可经 store.getReply durable 兜底.
27
+ */
28
+ export declare class RequestReply {
29
+ private readonly store;
30
+ readonly registry: ReplyRegistry;
31
+ constructor(store: MailboxStore, registry?: ReplyRegistry);
32
+ /** 投递请求, 返回 correlationId/requestId; 应答到达前先查 durable 已存(幂等重入). */
33
+ request(env: Envelope, timeoutMs: number, now: number): {
34
+ correlationId: string;
35
+ requestId: string;
36
+ reply: Promise<Envelope>;
37
+ };
38
+ /** dispatch 收到 inbound 时调用: 唤醒等待者. */
39
+ deliver(e: Envelope): boolean;
40
+ }
@@ -0,0 +1,77 @@
1
+ /** 应答超时. correlationId 保留以便审计/重试. */
2
+ export class ReplyTimeoutError extends Error {
3
+ correlationId;
4
+ constructor(correlationId, reason = 'reply timeout') {
5
+ super(`关联 ${correlationId} 应答超时: ${reason}`);
6
+ this.correlationId = correlationId;
7
+ this.name = 'ReplyTimeoutError';
8
+ }
9
+ }
10
+ /**
11
+ * 进程内应答等待器(M2-5). 一个 daemon 生命周期内: request 注册 waiter, dispatch 收到 inbound 即 notify 唤醒.
12
+ * 不持有定时器(由 sweep(now) 推进 deadline), 测试可确定性驱动; durable 兜底走 store.getReply.
13
+ */
14
+ export class ReplyRegistry {
15
+ waiters = new Map();
16
+ /** 注册等待 correlationId 的应答; 由 notify 解决, 由 sweep/expire 拒绝. */
17
+ await(correlationId, requestId, deadline) {
18
+ return new Promise((resolve, reject) => {
19
+ const prev = this.waiters.get(correlationId);
20
+ if (prev)
21
+ prev.reject(new ReplyTimeoutError(correlationId, '被同关联新等待覆盖'));
22
+ this.waiters.set(correlationId, { resolve, reject, requestId, deadline });
23
+ });
24
+ }
25
+ /** 收到 envelope: 若是匹配关联的应答(非请求自身)则唤醒对应 waiter. */
26
+ notify(e) {
27
+ const w = this.waiters.get(e.correlationId);
28
+ if (!w || e.id === w.requestId)
29
+ return false; // 没人等 / 是请求自身
30
+ this.waiters.delete(e.correlationId);
31
+ w.resolve(e);
32
+ return true;
33
+ }
34
+ /** 推进时钟: deadline 已过的 waiter 全部超时拒绝. 返回过期数. */
35
+ sweep(now) {
36
+ let n = 0;
37
+ for (const [cid, w] of this.waiters) {
38
+ if (w.deadline <= now) {
39
+ this.waiters.delete(cid);
40
+ w.reject(new ReplyTimeoutError(cid));
41
+ n += 1;
42
+ }
43
+ }
44
+ return n;
45
+ }
46
+ /** 显式过期单个关联(如收到 failed/expired 终态). */
47
+ expire(correlationId, reason) {
48
+ const w = this.waiters.get(correlationId);
49
+ if (!w)
50
+ return false;
51
+ this.waiters.delete(correlationId);
52
+ w.reject(new ReplyTimeoutError(correlationId, reason));
53
+ return true;
54
+ }
55
+ pending() { return this.waiters.size; }
56
+ }
57
+ /**
58
+ * 请求-应答门面: 绑定 store(durable) + registry(live).
59
+ * request 投递并注册 waiter; 应答既可经 notify 实时唤醒, 也可经 store.getReply durable 兜底.
60
+ */
61
+ export class RequestReply {
62
+ store;
63
+ registry;
64
+ constructor(store, registry = new ReplyRegistry()) {
65
+ this.store = store;
66
+ this.registry = registry;
67
+ }
68
+ /** 投递请求, 返回 correlationId/requestId; 应答到达前先查 durable 已存(幂等重入). */
69
+ request(env, timeoutMs, now) {
70
+ this.store.send(env);
71
+ const existing = this.store.getReply(env.correlationId, env.id);
72
+ const reply = existing ? Promise.resolve(existing) : this.registry.await(env.correlationId, env.id, now + timeoutMs);
73
+ return { correlationId: env.correlationId, requestId: env.id, reply };
74
+ }
75
+ /** dispatch 收到 inbound 时调用: 唤醒等待者. */
76
+ deliver(e) { return this.registry.notify(e); }
77
+ }
@@ -0,0 +1,74 @@
1
+ import { type Envelope, type Status, type CreateEnvelopeInput } from './envelope.js';
2
+ export declare const MAX_ATTEMPTS = 5;
3
+ export declare const DEFAULT_IMPORT_JSONL_MAX_LINE_BYTES: number;
4
+ export declare function expBackoffMs(attempt: number): number;
5
+ /** mailbox sqlite 引擎 (WAL + busy_timeout). 状态机 pending→in_flight→done/failed/expired + 租约 + 重试/DLQ. */
6
+ export declare class MailboxStore {
7
+ private readonly db;
8
+ constructor(opts: {
9
+ path: string;
10
+ busyTimeoutMs?: number;
11
+ });
12
+ /** 通用 KV 状态(M6: sync 游标 inbound_cursor / lifecycle reauth 退避 / node_id 等). */
13
+ getState(key: string): string | undefined;
14
+ setState(key: string, value: string): void;
15
+ /** 投递; 同 id 幂等(OR IGNORE). 返回 receiptId. */
16
+ send(e: Envelope): {
17
+ receiptId: string;
18
+ stored: boolean;
19
+ };
20
+ getById(id: string): Envelope | undefined;
21
+ list(opts?: {
22
+ status?: Status;
23
+ handler?: string;
24
+ runtimeNamespace?: string;
25
+ limit?: number;
26
+ }): Envelope[];
27
+ countByStatus(status: Status): number;
28
+ /** pending 计数(可按 handler/runtimeNamespace 分区), 用于 agent wake 去抖. */
29
+ countPending(handler?: string, runtimeNamespace?: string): number;
30
+ /** 只统计「现在就能 claim」的出站, 供 cadence 判定, 避免 deferred 拉低 idle 退避.
31
+ * 谓词须与 claim() 对齐: 到点 pending + 租约过期的 in_flight 孤儿; 否则孤儿出站(claim 能回收却不被计)会被误判 idle, 恢复最多慢一个 idle 周期. */
32
+ countClaimable(handler: string, now: number, runtimeNamespace?: string): number;
33
+ hasMessageWithIdempotencyKey(idempotencyKey: string): boolean;
34
+ hasMessageWithPayload(type: string, payload: unknown): boolean;
35
+ /** 原子 claim: pending(或租约过期的 in_flight) → in_flight + 租约. 可按 runtimeNamespace 分区. */
36
+ claim(handler: string, limit: number, leaseMs: number, now: number, runtimeNamespace?: string): Envelope[];
37
+ complete(id: string, now: number): void;
38
+ /** 失败: attempts<N→退避回 pending; ≥N→DLQ(不自动丢). */
39
+ fail(id: string, err: string, now: number, maxAttempts?: number): void;
40
+ /** 暂缓: transient upstream outage 不消耗 attempts, 仅设置下次可 claim 时间. */
41
+ defer(id: string, err: string, now: number, retryAfterMs: number): void;
42
+ /** DLQ 重放(人工/agent 显式, 不自动丢). */
43
+ replayDlq(id: string, now: number): void;
44
+ dlq(): Envelope[];
45
+ /** TTL 扫描: ttlAt 过期且未 done/dlq → expired. */
46
+ expireOld(now: number): number;
47
+ /** M2-5 关联线程: 同 correlationId 全部消息(请求+应答), 按 createdAt 排序. */
48
+ findByCorrelation(correlationId: string): Envelope[];
49
+ /** 关联线程中除 requestId 外最新一条 = 应答(durable, 跨重启/进程). */
50
+ getReply(correlationId: string, requestId: string): Envelope | undefined;
51
+ /** 构造并投递一条对 `to` 的应答(继承 correlationId, 收发方对调, replyTo 清空). */
52
+ reply(to: Envelope, replyType: string, payload: unknown, now: number, over?: Partial<CreateEnvelopeInput>): {
53
+ envelope: Envelope;
54
+ receiptId: string;
55
+ stored: boolean;
56
+ };
57
+ /** M2-5 轻量状态视图(运维/IPC 查询用). */
58
+ getStatus(id: string): {
59
+ id: string;
60
+ type: string;
61
+ status: Status;
62
+ attempts: number;
63
+ nextRetryAt: number | null;
64
+ ttlAt: number | null;
65
+ dlq: boolean;
66
+ } | undefined;
67
+ /** 幂等(A13): 副作用 handler 用 idempotencyKey 去重; 命中返缓存不重跑. */
68
+ isProcessed(key: string): boolean;
69
+ getProcessed(key: string): unknown;
70
+ markProcessed(key: string, result: unknown, now: number): void;
71
+ /** v1 messages.jsonl → sqlite 迁移(幂等可重入). */
72
+ importJsonl(path: string): number;
73
+ close(): void;
74
+ }