@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,117 @@
1
+ import { type ExtractedSignal, type SignalSourceTurn } from '../signals/extractor.js';
2
+ import { type ValueSummary } from '../ops/index.js';
3
+ export interface SessionStartConfig {
4
+ tokenBudgetHardCap: number;
5
+ injectGenes?: readonly string[];
6
+ preamble?: string;
7
+ /** Value-outreach recap line (#113): quiet metadata about injected memory/value context. Higher priority than
8
+ * the gene-list tail — when over budget the gene tail is cut FIRST and the recap is kept, so the agent keeps
9
+ * the context even in a tight budget. Empty/absent → no recap, no behavior change. */
10
+ recap?: string;
11
+ }
12
+ export interface SessionStartInjection {
13
+ systemPrompt: string;
14
+ tokenBudget: number;
15
+ genes: string[];
16
+ /** Whether the recap line survived into the prompt (false only if it was absent). */
17
+ recapIncluded: boolean;
18
+ }
19
+ /**
20
+ * 构造 SessionStart 注入. token 预算钉在 hard cap, 注入内容超额则截断 gene 列表(预算优先).
21
+ * Priority order (#113): preamble + recap are kept; only the GENE list is trimmed from its tail to fit the cap.
22
+ * The recap is a fixed quiet-context line, so it sits above every gene in priority — a tight budget drops genes,
23
+ * never the recap. The recap is assembled with the preamble (both retained as one head block).
24
+ */
25
+ export declare function buildSessionStartInjection(cfg: SessionStartConfig, estimateTokens?: (s: string) => number): SessionStartInjection;
26
+ /** Inputs the SessionStart recap (#113) needs from real run state: the genes being injected, the past successes
27
+ * they were learned from, and the value summary for the recap window. */
28
+ export interface SessionStartRecapContext {
29
+ /** Genes selected for this session's injection (N) — the rendered lines that go into the prompt. */
30
+ injectGenes: readonly string[];
31
+ /**
32
+ * Stable gene IDs aligned POSITIONALLY with `injectGenes` (line[i] ↔ id[i]), for inject attribution (#123).
33
+ * When present, the inject emission reports these IDs (mapped to the survivors of the budget trim) so the
34
+ * value ledger attributes by a stable id, not a rendered line. When absent, the emission falls back to the
35
+ * surviving line strings. Length should match `injectGenes`; a shorter array contributes no id past its end.
36
+ */
37
+ geneIds?: readonly string[];
38
+ /** Past successes the injected genes were distilled from (M) — e.g. distinct solidified cycles. */
39
+ successCount?: number;
40
+ /** Value summary for the recap window (its measured total is X). */
41
+ summary: ValueSummary;
42
+ }
43
+ /**
44
+ * What the SessionStart inject emission seam (#123) reports — the value-ledger attribution anchors for a
45
+ * `value.inject` root_event. This is an ATTRIBUTION-ONLY signal (the weakest in the ledger): it records WHICH
46
+ * genes were actually injected (and, when known, the session outcome) and carries NO savings number. The genes
47
+ * reported are the ones that survived the hard-cap budget trim — i.e. the genes the agent really saw, not the
48
+ * pre-trim candidate list.
49
+ */
50
+ export interface InjectInfo {
51
+ /** The gene ids actually injected into the prompt (post budget-trim). */
52
+ geneIds: readonly string[];
53
+ /** The cycle this injection feeds, when there is one. */
54
+ cycleId?: string;
55
+ /**
56
+ * The runtime's session id, when the hook delivers it (Claude Code passes it on SessionStart stdin). Recorded so
57
+ * a later attribution pass (recall) can tie THIS inject to the exact session transcript it produced (#205),
58
+ * instead of guessing "the most recent inject". Absent for runtimes that expose no per-session id (e.g. cursor).
59
+ */
60
+ sessionId?: string;
61
+ /**
62
+ * Session outcome, when observable. At SessionStart the session has not run yet, so this is normally absent;
63
+ * the field exists so a later attribution pass can carry it. Never scored into a number (attribution only).
64
+ */
65
+ outcome?: string;
66
+ }
67
+ /** Options for the recap-composing SessionStart injection (#123): the optional inject emission seam. */
68
+ export interface ComposeSessionStartOptions {
69
+ /** Token estimator (defaults to the char/4 heuristic inside buildSessionStartInjection). */
70
+ estimateTokens?: (s: string) => number;
71
+ /**
72
+ * Inject emission seam (#123). Fired exactly once with the genes that ACTUALLY made it into the prompt (after
73
+ * the hard-cap trim) so the value ledger can derive a source=inject record. Core stays sink-agnostic: the
74
+ * composition layer wires this to a `value.inject` root_event. Best-effort + MUST NOT throw — injection is the
75
+ * agent's critical path, so an emission error can never be allowed to break or delay it (fire-and-forget,
76
+ * mirroring the reuse-hit seam). Not fired when nothing was injected (no genes survived the budget).
77
+ */
78
+ onInject?: (info: InjectInfo) => void;
79
+ /** The cycle this injection feeds — carried into onInject so the event refs the SAME cycleId as the cycle. */
80
+ cycleId?: string;
81
+ /** The runtime session id — carried into onInject so the value.inject event can be tied back to its session (#205). */
82
+ sessionId?: string;
83
+ }
84
+ /**
85
+ * Compose a SessionStart injection WITH a value-outreach recap (#113), end to end. This is the real integration
86
+ * seam: it derives a quiet context line from live run state (N injected genes, M past successes, X measured
87
+ * tokens saved — all from the passed summary + counts, never invented) and threads it through the same hard-cap
88
+ * budget as `buildSessionStartInjection`, where the recap outranks the gene tail. The recap is omitted (no line
89
+ * added) when there is nothing honest to say. Pure given its inputs (+ the injected token estimator).
90
+ *
91
+ * Inject emission (#123): when an `onInject` seam is wired (via the options object form of the third argument),
92
+ * it fires ONCE with the genes that actually survived the budget trim (`inj.genes`) so the value ledger can feed
93
+ * its source=inject rail with REAL data. The emission is best-effort and fire-and-forget: a thrown error from the
94
+ * seam is swallowed and never propagates, so an attribution side-effect can never break the agent's injection.
95
+ *
96
+ * The third argument is overloaded for back-compat: a bare function is the token estimator (the original
97
+ * signature); an options object carries the estimator plus the optional inject seam.
98
+ */
99
+ export declare function composeSessionStartWithRecap(base: Omit<SessionStartConfig, 'recap'>, recapCtx: SessionStartRecapContext, estimateTokensOrOpts?: ((s: string) => number) | ComposeSessionStartOptions): SessionStartInjection;
100
+ export interface ToolUseEvent {
101
+ toolName: string;
102
+ toolResult?: string;
103
+ isError?: boolean;
104
+ text?: string;
105
+ }
106
+ /** PostToolUse 钩子: 把一次 tool 调用结果转成信号(复用三条腿提取). */
107
+ export declare function signalsFromToolUse(event: ToolUseEvent): ExtractedSignal[];
108
+ export interface StopMemoryEntry {
109
+ kind: 'session_summary';
110
+ summary: string;
111
+ signalCount: number;
112
+ signals: string[];
113
+ outcome: 'productive' | 'idle';
114
+ ts: number;
115
+ }
116
+ /** Stop 钩子: 把本 session 的信号沉淀成一条 memory(批注#6). idle(无信号)也记, 但标 idle. */
117
+ export declare function buildStopMemory(turns: readonly SignalSourceTurn[], now: number): StopMemoryEntry;
@@ -0,0 +1,89 @@
1
+ import { extractSignals } from '../signals/extractor.js';
2
+ import { buildValueRecap } from '../ops/index.js';
3
+ /**
4
+ * 构造 SessionStart 注入. token 预算钉在 hard cap, 注入内容超额则截断 gene 列表(预算优先).
5
+ * Priority order (#113): preamble + recap are kept; only the GENE list is trimmed from its tail to fit the cap.
6
+ * The recap is a fixed quiet-context line, so it sits above every gene in priority — a tight budget drops genes,
7
+ * never the recap. The recap is assembled with the preamble (both retained as one head block).
8
+ */
9
+ export function buildSessionStartInjection(cfg, estimateTokens = (s) => Math.ceil(s.length / 4)) {
10
+ const genes = [...(cfg.injectGenes ?? [])];
11
+ const recap = (cfg.recap ?? '').trim();
12
+ // The head block (preamble + recap) is never trimmed — only the gene tail is.
13
+ const head = [cfg.preamble ?? '', recap].filter(Boolean);
14
+ const compose = () => [...head, ...genes].filter(Boolean).join('\n');
15
+ let prompt = compose();
16
+ // hard cap: 注入超预算就从尾部砍 gene(保 preamble + recap, 预算优先且 recap 优先级高于 gene 尾部)
17
+ while (genes.length > 0 && estimateTokens(prompt) > cfg.tokenBudgetHardCap) {
18
+ genes.pop();
19
+ prompt = compose();
20
+ }
21
+ return { systemPrompt: prompt, tokenBudget: cfg.tokenBudgetHardCap, genes, recapIncluded: recap.length > 0 };
22
+ }
23
+ /**
24
+ * Compose a SessionStart injection WITH a value-outreach recap (#113), end to end. This is the real integration
25
+ * seam: it derives a quiet context line from live run state (N injected genes, M past successes, X measured
26
+ * tokens saved — all from the passed summary + counts, never invented) and threads it through the same hard-cap
27
+ * budget as `buildSessionStartInjection`, where the recap outranks the gene tail. The recap is omitted (no line
28
+ * added) when there is nothing honest to say. Pure given its inputs (+ the injected token estimator).
29
+ *
30
+ * Inject emission (#123): when an `onInject` seam is wired (via the options object form of the third argument),
31
+ * it fires ONCE with the genes that actually survived the budget trim (`inj.genes`) so the value ledger can feed
32
+ * its source=inject rail with REAL data. The emission is best-effort and fire-and-forget: a thrown error from the
33
+ * seam is swallowed and never propagates, so an attribution side-effect can never break the agent's injection.
34
+ *
35
+ * The third argument is overloaded for back-compat: a bare function is the token estimator (the original
36
+ * signature); an options object carries the estimator plus the optional inject seam.
37
+ */
38
+ export function composeSessionStartWithRecap(base, recapCtx, estimateTokensOrOpts) {
39
+ const opts = typeof estimateTokensOrOpts === 'function' ? { estimateTokens: estimateTokensOrOpts } : (estimateTokensOrOpts ?? {});
40
+ const recap = buildValueRecap({
41
+ injectedCount: recapCtx.injectGenes.length,
42
+ ...(recapCtx.successCount !== undefined ? { successCount: recapCtx.successCount } : {}),
43
+ summary: recapCtx.summary,
44
+ });
45
+ const inj = buildSessionStartInjection({ ...base, injectGenes: recapCtx.injectGenes, recap }, opts.estimateTokens);
46
+ // Inject emission (#123): record the genes that ACTUALLY landed in the prompt (post budget-trim), not the
47
+ // pre-trim candidate list — the ledger should attribute only what the agent really saw. The trim drops from the
48
+ // TAIL, so the survivors are the FIRST inj.genes.length entries; map them to the aligned stable gene ids (when
49
+ // provided) so attribution is by id, not by a rendered line. Fire-and-forget: skip when nothing was injected,
50
+ // and never let a seam error escape into the injection path.
51
+ if (opts.onInject && inj.genes.length > 0) {
52
+ const geneIds = recapCtx.geneIds
53
+ ? recapCtx.geneIds.slice(0, inj.genes.length).filter((id) => typeof id === 'string')
54
+ : inj.genes;
55
+ if (geneIds.length > 0) {
56
+ try {
57
+ opts.onInject({
58
+ geneIds,
59
+ ...(opts.cycleId ? { cycleId: opts.cycleId } : {}),
60
+ ...(opts.sessionId ? { sessionId: opts.sessionId } : {}),
61
+ });
62
+ }
63
+ catch { /* emission must never break the injection path */ }
64
+ }
65
+ }
66
+ return inj;
67
+ }
68
+ /** PostToolUse 钩子: 把一次 tool 调用结果转成信号(复用三条腿提取). */
69
+ export function signalsFromToolUse(event) {
70
+ const turn = {
71
+ toolName: event.toolName,
72
+ ...(event.isError && event.toolResult ? { errorMessage: event.toolResult } : {}),
73
+ ...(event.text ? { text: event.text } : {}),
74
+ isMeta: false,
75
+ };
76
+ return extractSignals([turn]);
77
+ }
78
+ /** Stop 钩子: 把本 session 的信号沉淀成一条 memory(批注#6). idle(无信号)也记, 但标 idle. */
79
+ export function buildStopMemory(turns, now) {
80
+ const signals = extractSignals(turns);
81
+ return {
82
+ kind: 'session_summary',
83
+ summary: signals.length > 0 ? `${signals.length} 个信号: ${signals.slice(0, 3).map((s) => s.kind).join(', ')}` : '无信号 session',
84
+ signalCount: signals.length,
85
+ signals: signals.slice(0, 20).map((s) => s.text.slice(0, 120)),
86
+ outcome: signals.length > 0 ? 'productive' : 'idle',
87
+ ts: now,
88
+ };
89
+ }
@@ -0,0 +1 @@
1
+ export * from './hooks.js';
@@ -0,0 +1 @@
1
+ export * from './hooks.js';
@@ -0,0 +1,43 @@
1
+ export type AssetCallAction = 'hub_search_hit' | 'hub_search_miss' | 'asset_reuse' | 'asset_reference' | 'asset_publish' | 'asset_publish_skip' | 'hub_review_submitted' | 'hub_review_rejected' | 'hub_review_failed';
2
+ export interface AssetCallEntry {
3
+ run_id?: string | null;
4
+ action: AssetCallAction;
5
+ asset_id?: string;
6
+ asset_type?: string;
7
+ source_node_id?: string;
8
+ chain_id?: string;
9
+ score?: number;
10
+ mode?: 'direct' | 'reference';
11
+ signals?: readonly string[];
12
+ reason?: string;
13
+ extra?: Record<string, unknown>;
14
+ }
15
+ export interface AssetCallRecord extends AssetCallEntry {
16
+ timestamp: string;
17
+ }
18
+ export interface ReadOpts {
19
+ run_id?: string;
20
+ action?: AssetCallAction;
21
+ /** Only entries at/after this ISO time. */
22
+ since?: string;
23
+ /** Only the last N entries (after the other filters). */
24
+ last?: number;
25
+ }
26
+ export interface CallLogSummary {
27
+ total_entries: number;
28
+ unique_assets: number;
29
+ unique_runs: number;
30
+ by_action: Record<string, number>;
31
+ entries: AssetCallRecord[];
32
+ }
33
+ export declare class AssetCallLog {
34
+ private readonly path;
35
+ private readonly now;
36
+ constructor(path: string, now?: () => Date);
37
+ /** Append one record (timestamped). Never throws — logging must not break evolution. */
38
+ append(entry: AssetCallEntry): void;
39
+ /** Read records with optional filters. Corrupt lines are skipped. */
40
+ read(opts?: ReadOpts): AssetCallRecord[];
41
+ /** Totals + per-action counts (for CLI / observability). */
42
+ summarize(opts?: ReadOpts): CallLogSummary;
43
+ }
@@ -0,0 +1,72 @@
1
+ // Append-only asset-call log (ported from v1 gep/assetCallLog.js). Records every hub-asset interaction across
2
+ // evolution runs — search hits/misses, reuse/reference, publish, and review outcomes — as one JSONL line each.
3
+ // This is the audit trail behind "which fetched assets actually got reused, and did the reuse pay off"; the
4
+ // reuse-reward / quality-feedback loops read it. Best-effort by construction: a logging failure NEVER blocks
5
+ // or fails an evolution. The log path is injected so it's testable without a real home dir.
6
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
7
+ import { dirname } from 'node:path';
8
+ export class AssetCallLog {
9
+ path;
10
+ now;
11
+ constructor(path, now = () => new Date()) {
12
+ this.path = path;
13
+ this.now = now;
14
+ }
15
+ /** Append one record (timestamped). Never throws — logging must not break evolution. */
16
+ append(entry) {
17
+ if (!entry || typeof entry !== 'object')
18
+ return;
19
+ try {
20
+ mkdirSync(dirname(this.path), { recursive: true });
21
+ const record = { timestamp: this.now().toISOString(), ...entry };
22
+ appendFileSync(this.path, `${JSON.stringify(record)}\n`, 'utf8');
23
+ }
24
+ catch { /* non-fatal */ }
25
+ }
26
+ /** Read records with optional filters. Corrupt lines are skipped. */
27
+ read(opts = {}) {
28
+ if (!existsSync(this.path))
29
+ return [];
30
+ let entries = [];
31
+ try {
32
+ for (const line of readFileSync(this.path, 'utf8').split('\n')) {
33
+ if (!line)
34
+ continue;
35
+ try {
36
+ entries.push(JSON.parse(line));
37
+ }
38
+ catch { /* skip corrupt */ }
39
+ }
40
+ }
41
+ catch {
42
+ return [];
43
+ }
44
+ if (opts.since) {
45
+ const sinceTs = new Date(opts.since).getTime();
46
+ if (Number.isFinite(sinceTs))
47
+ entries = entries.filter((e) => new Date(e.timestamp).getTime() >= sinceTs);
48
+ }
49
+ if (opts.run_id)
50
+ entries = entries.filter((e) => e.run_id === opts.run_id);
51
+ if (opts.action)
52
+ entries = entries.filter((e) => e.action === opts.action);
53
+ if (opts.last && Number.isFinite(opts.last) && opts.last > 0)
54
+ entries = entries.slice(-opts.last);
55
+ return entries;
56
+ }
57
+ /** Totals + per-action counts (for CLI / observability). */
58
+ summarize(opts = {}) {
59
+ const entries = this.read(opts);
60
+ const byAction = {};
61
+ const assets = new Set();
62
+ const runs = new Set();
63
+ for (const e of entries) {
64
+ byAction[e.action] = (byAction[e.action] ?? 0) + 1;
65
+ if (e.asset_id)
66
+ assets.add(e.asset_id);
67
+ if (e.run_id)
68
+ runs.add(e.run_id);
69
+ }
70
+ return { total_entries: entries.length, unique_assets: assets.size, unique_runs: runs.size, by_action: byAction, entries };
71
+ }
72
+ }
@@ -0,0 +1,28 @@
1
+ import type { HubCapability, HubBindings } from './capability.js';
2
+ import { type LeakCheckMode } from './sanitize.js';
3
+ /** publish 回执非 accepted → 抛此错; SyncEngine 据 terminal 决定是否重试. */
4
+ export declare class PublishRejectedError extends Error {
5
+ readonly status: string;
6
+ readonly terminal: boolean;
7
+ readonly retryAfterMs?: number | undefined;
8
+ readonly retryable?: boolean | undefined;
9
+ constructor(status: string, terminal: boolean, reason?: string, retryAfterMs?: number | undefined, retryable?: boolean | undefined);
10
+ }
11
+ /** makeHubBindings options. Pre-publish sanitize is on by default (both public + private adapters share this single chokepoint). */
12
+ export interface HubBindingsOptions {
13
+ sanitize?: {
14
+ /** Default true: deep-redact + leak-scan before egress. Off = raw publish (tests / special cases only). */
15
+ enabled?: boolean;
16
+ /** Source for the env reverse-scan + EVOLVER_LEAK_CHECK. Defaults to process.env. */
17
+ env?: Record<string, string | undefined>;
18
+ /** Override the leak-check mode (strict = refuse / warn = log only / off = skip scan). Defaults to reading env, which defaults to strict. */
19
+ mode?: LeakCheckMode;
20
+ };
21
+ }
22
+ /**
23
+ * 把 HubCapability 接到 core 两 seam(M6-1):
24
+ * - asProxyHandler: Dispatcher.handlers.proxy — 按 envelope.type 路由到 hub. 抛错→store.fail()重试;
25
+ * 但 publish 终态(reject/quarantine/402)抛 PublishRejectedError{terminal:true}, 调用方据此不重试(money-safety).
26
+ * - asAssetTransport: assetstore RemoteTransport — 落库前 core normalizeForPut, 不信任远端 asset_id.
27
+ */
28
+ export declare function makeHubBindings(cap: HubCapability, options?: HubBindingsOptions): HubBindings;
@@ -0,0 +1,90 @@
1
+ import { normalizeForPut } from '../assetstore/provider.js';
2
+ import { sanitizeBundle, summarizeLeaks } from './sanitize.js';
3
+ /** publish 回执非 accepted → 抛此错; SyncEngine 据 terminal 决定是否重试. */
4
+ export class PublishRejectedError extends Error {
5
+ status;
6
+ terminal;
7
+ retryAfterMs;
8
+ retryable;
9
+ constructor(status, terminal, reason, retryAfterMs, retryable) {
10
+ super(`publish ${status}${reason ? `: ${reason}` : ''}`);
11
+ this.status = status;
12
+ this.terminal = terminal;
13
+ this.retryAfterMs = retryAfterMs;
14
+ this.retryable = retryable;
15
+ this.name = 'PublishRejectedError';
16
+ }
17
+ }
18
+ function envelopeToAgentEvent(e) {
19
+ const stableId = e.type === 'proxy_trace' && e.idempotencyKey ? e.idempotencyKey : e.id;
20
+ return {
21
+ id: stableId,
22
+ type: e.type,
23
+ payload: e.payload,
24
+ priority: 'medium',
25
+ createdAt: e.createdAt,
26
+ ...(e.type === 'proxy_trace' && e.idempotencyKey ? { refId: e.idempotencyKey } : {}),
27
+ };
28
+ }
29
+ /**
30
+ * 把 HubCapability 接到 core 两 seam(M6-1):
31
+ * - asProxyHandler: Dispatcher.handlers.proxy — 按 envelope.type 路由到 hub. 抛错→store.fail()重试;
32
+ * 但 publish 终态(reject/quarantine/402)抛 PublishRejectedError{terminal:true}, 调用方据此不重试(money-safety).
33
+ * - asAssetTransport: assetstore RemoteTransport — 落库前 core normalizeForPut, 不信任远端 asset_id.
34
+ */
35
+ export function makeHubBindings(cap, options = {}) {
36
+ const sanCfg = options.sanitize ?? {};
37
+ const sanEnabled = sanCfg.enabled ?? true;
38
+ const sanEnv = sanCfg.env ?? (typeof process !== 'undefined' ? process.env : {});
39
+ /** Single publish chokepoint: sanitize (on by default) → strict + leak found → refuse (terminal, not retryable) → cap.publish the redacted bundle. */
40
+ const publishSanitized = (bundle) => {
41
+ if (!sanEnabled)
42
+ return cap.publish(bundle);
43
+ const r = sanitizeBundle(bundle, { env: sanEnv, ...(sanCfg.mode ? { mode: sanCfg.mode } : {}) });
44
+ if (r.blocked) {
45
+ throw new PublishRejectedError('leak_blocked', true, `sensitive data detected before publish, refused (not retryable): ${summarizeLeaks(r.leaks)}`);
46
+ }
47
+ return cap.publish(r.bundle);
48
+ };
49
+ return {
50
+ asProxyHandler() {
51
+ return async (e) => {
52
+ switch (e.type) {
53
+ case 'asset_submit': {
54
+ // payload 可为 bundle {assets:[...]} 或单资产; 统一成 bundle 数组发.
55
+ const p = e.payload;
56
+ const bundle = Array.isArray(p.assets) ? p.assets : [p];
57
+ const r = await publishSanitized(bundle);
58
+ if (r.status !== 'accepted')
59
+ throw new PublishRejectedError(r.status, r.terminal ?? true, r.reason);
60
+ return r;
61
+ }
62
+ case 'task_claim': return cap.task.claim(String(e.payload.taskId ?? ''));
63
+ case 'task_complete': {
64
+ const p = e.payload;
65
+ return cap.task.complete(String(p.claimId ?? ''), p.result);
66
+ }
67
+ default:
68
+ // 其余 outbound(atp_*/heartbeat/...) 走 mailbox.push
69
+ await cap.mailbox.push(envelopeToAgentEvent(e));
70
+ return { pushed: true };
71
+ }
72
+ };
73
+ },
74
+ asAssetTransport() {
75
+ return {
76
+ putRemote: async (record) => {
77
+ const { record: clean } = normalizeForPut(record); // 不信任远端 asset_id, core 侧重算
78
+ const r = await publishSanitized([clean]); // 单资产传输也走 bundle API([asset]) + 发布前脱敏
79
+ return { stored: r.status === 'accepted' };
80
+ },
81
+ getRemote: async (assetId) => {
82
+ const got = await cap.fetch({ limit: 10000 });
83
+ return got.find((a) => a.asset_id === assetId) ?? null;
84
+ },
85
+ searchRemote: (query) => cap.search(query),
86
+ listRemote: (kind, limit) => cap.fetch({ ...(kind ? { kind } : {}), limit }),
87
+ };
88
+ },
89
+ };
90
+ }