@octopi-agent/engine 0.97.15 → 0.102.10

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 (369) hide show
  1. package/dist/config-schema/agent.d.ts +37 -5
  2. package/dist/config-schema/agent.js +24 -4
  3. package/dist/config-schema/context.d.ts +6 -36
  4. package/dist/config-schema/context.js +4 -28
  5. package/dist/config-schema/engine.d.ts +61 -160
  6. package/dist/config-schema/engine.js +1 -5
  7. package/dist/config-schema/governance.d.ts +10 -1
  8. package/dist/config-schema/governance.js +38 -1
  9. package/dist/config-schema/models.d.ts +2 -8
  10. package/dist/config-schema/models.js +0 -2
  11. package/dist/config-schema/run.d.ts +2 -2
  12. package/dist/config-schema/run.js +2 -2
  13. package/dist/config-schema/shared.d.ts +0 -3
  14. package/dist/config-schema/shared.js +0 -2
  15. package/dist/config-schema/substrate.d.ts +14 -88
  16. package/dist/config-schema/substrate.js +22 -107
  17. package/dist/config.d.ts +45 -113
  18. package/dist/config.js +8 -2
  19. package/dist/harness/activation/dispatcher.js +7 -0
  20. package/dist/harness/activation/inbox.d.ts +3 -3
  21. package/dist/harness/activation/inbox.js +3 -3
  22. package/dist/harness/activation/runtime.js +13 -5
  23. package/dist/harness/activation/types.d.ts +2 -2
  24. package/dist/harness/agent/builder.d.ts +34 -2
  25. package/dist/harness/agent/builder.js +189 -58
  26. package/dist/harness/agent/config-bridge.js +9 -2
  27. package/dist/harness/agent/config-integrity.d.ts +66 -0
  28. package/dist/harness/agent/config-integrity.js +108 -2
  29. package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
  30. package/dist/harness/agent/wire-agent-builder.js +31 -7
  31. package/dist/harness/capabilities/document/factory.d.ts +5 -0
  32. package/dist/harness/capabilities/document/factory.js +1 -0
  33. package/dist/harness/capabilities/document/port.js +6 -3
  34. package/dist/harness/capabilities/document/types.d.ts +5 -0
  35. package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
  36. package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
  37. package/dist/harness/collaboration/autonomous-subsystem/loader.js +4 -1
  38. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
  39. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +21 -4
  40. package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
  41. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
  42. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
  43. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
  44. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
  45. package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
  46. package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
  47. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
  48. package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
  49. package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
  50. package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
  51. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +12 -3
  52. package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
  53. package/dist/harness/collaboration/delegation/child-run.js +4 -4
  54. package/dist/harness/collaboration/delegation/index.d.ts +1 -1
  55. package/dist/harness/collaboration/delegation/index.js +1 -1
  56. package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
  57. package/dist/harness/collaboration/delegation/notifier.js +8 -1
  58. package/dist/harness/collaboration/delegation/service.d.ts +2 -0
  59. package/dist/harness/collaboration/delegation/service.js +2 -1
  60. package/dist/harness/collaboration/delegation/store.d.ts +2 -0
  61. package/dist/harness/collaboration/delegation/store.js +2 -1
  62. package/dist/harness/collaboration/delegation/types.d.ts +23 -2
  63. package/dist/harness/collaboration/delegation/types.js +22 -0
  64. package/dist/harness/collaboration/delegation/wiring.js +11 -1
  65. package/dist/harness/context/budget-allocator.d.ts +26 -18
  66. package/dist/harness/context/budget-allocator.js +67 -32
  67. package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
  68. package/dist/harness/context/capabilities/compact/engine.js +169 -121
  69. package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
  70. package/dist/harness/context/capabilities/compact/handover.js +7 -5
  71. package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
  72. package/dist/harness/context/capabilities/compact/index.js +4 -0
  73. package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
  74. package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
  75. package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
  76. package/dist/harness/context/capabilities/compact/messages.js +91 -0
  77. package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
  78. package/dist/harness/context/capabilities/compact/types.js +11 -1
  79. package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
  80. package/dist/harness/context/capabilities/compact/view-split.js +72 -0
  81. package/dist/harness/context/capabilities/summary/port.js +0 -1
  82. package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
  83. package/dist/harness/context/capabilities/summary/resolver.js +4 -9
  84. package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
  85. package/dist/harness/context/capabilities/summary/types.d.ts +4 -7
  86. package/dist/harness/context/context-size-ledger.d.ts +143 -0
  87. package/dist/harness/context/context-size-ledger.js +236 -0
  88. package/dist/harness/context/default-context-engine.d.ts +195 -119
  89. package/dist/harness/context/default-context-engine.js +1241 -743
  90. package/dist/harness/context/index.d.ts +2 -2
  91. package/dist/harness/context/index.js +1 -1
  92. package/dist/harness/context/layer-types.d.ts +15 -0
  93. package/dist/harness/context/layer-types.js +14 -1
  94. package/dist/harness/context/layers.d.ts +16 -19
  95. package/dist/harness/context/layers.js +42 -14
  96. package/dist/harness/context/message-selector.d.ts +10 -8
  97. package/dist/harness/context/message-selector.js +49 -27
  98. package/dist/harness/context/summarize.d.ts +3 -3
  99. package/dist/harness/context/summarize.js +11 -4
  100. package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
  101. package/dist/harness/context/system-prompt-assembler.js +3 -1
  102. package/dist/harness/context/token-constants.d.ts +8 -6
  103. package/dist/harness/context/token-constants.js +8 -7
  104. package/dist/harness/context/token-estimate-fns.d.ts +37 -27
  105. package/dist/harness/context/token-estimate-fns.js +85 -66
  106. package/dist/harness/context/token-estimator.d.ts +27 -12
  107. package/dist/harness/context/token-estimator.js +120 -66
  108. package/dist/harness/context/token-segments.d.ts +88 -0
  109. package/dist/harness/context/token-segments.js +103 -0
  110. package/dist/harness/context/tool-result-aging.d.ts +6 -1
  111. package/dist/harness/context/tool-result-aging.js +16 -5
  112. package/dist/harness/context/tool-result-body.js +2 -0
  113. package/dist/harness/context/transform/anchors.d.ts +66 -0
  114. package/dist/harness/context/transform/anchors.js +125 -0
  115. package/dist/harness/context/transform/fold.d.ts +56 -0
  116. package/dist/harness/context/transform/fold.js +135 -0
  117. package/dist/harness/context/transform/migrate.d.ts +41 -0
  118. package/dist/harness/context/transform/migrate.js +69 -0
  119. package/dist/harness/context/transform/types.d.ts +129 -0
  120. package/dist/harness/context/transform/types.js +19 -0
  121. package/dist/harness/context/turn-envelope.d.ts +6 -3
  122. package/dist/harness/context/types.d.ts +127 -117
  123. package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
  124. package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
  125. package/dist/harness/extension/execution-environment/ops-audit.d.ts +7 -3
  126. package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
  127. package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
  128. package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
  129. package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
  130. package/dist/harness/extension/execution-environment/undo-log.js +31 -10
  131. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
  132. package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
  133. package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
  134. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
  135. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
  136. package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
  137. package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
  138. package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
  139. package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
  140. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
  141. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
  142. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
  143. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
  144. package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
  145. package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
  146. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
  147. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
  148. package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
  149. package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
  150. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
  151. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
  152. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
  153. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
  154. package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
  155. package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
  156. package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
  157. package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
  158. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
  159. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
  160. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
  161. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
  162. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
  163. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
  164. package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
  165. package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
  166. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
  167. package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
  168. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
  169. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
  170. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
  171. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
  172. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
  173. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
  174. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
  175. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
  176. package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
  177. package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
  178. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
  179. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
  180. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +17 -24
  181. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
  182. package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
  183. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
  184. package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
  185. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
  186. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
  187. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
  188. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
  189. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
  190. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
  191. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
  192. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
  193. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
  194. package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
  195. package/dist/harness/governance/accounting/usage-ledger.js +23 -1
  196. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
  197. package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
  198. package/dist/harness/governance/security/capability-enforcer.js +1 -2
  199. package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
  200. package/dist/harness/governance/security/default-risk-policy.js +1 -0
  201. package/dist/harness/governance/security/default-security-guard.js +9 -0
  202. package/dist/harness/governance/security/index.d.ts +1 -0
  203. package/dist/harness/governance/security/index.js +2 -0
  204. package/dist/harness/governance/security/risk-evaluator.js +13 -0
  205. package/dist/harness/governance/security/risk-types.d.ts +12 -0
  206. package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
  207. package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
  208. package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
  209. package/dist/harness/governance/security/shell-parser-shared.js +188 -0
  210. package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
  211. package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
  212. package/dist/harness/governance/security/shell-parser.d.ts +23 -10
  213. package/dist/harness/governance/security/shell-parser.js +37 -496
  214. package/dist/harness/governance/security/vendor/README.md +24 -0
  215. package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
  216. package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
  217. package/dist/harness/index.d.ts +12 -12
  218. package/dist/harness/index.js +7 -7
  219. package/dist/harness/knowledge/boot-config.d.ts +55 -0
  220. package/dist/harness/knowledge/boot-config.js +50 -0
  221. package/dist/harness/knowledge/catalog-types.d.ts +2 -0
  222. package/dist/harness/knowledge/client.d.ts +24 -2
  223. package/dist/harness/knowledge/client.js +19 -5
  224. package/dist/harness/knowledge/db.js +5 -0
  225. package/dist/harness/knowledge/describe-sample.d.ts +23 -0
  226. package/dist/harness/knowledge/describe-sample.js +58 -0
  227. package/dist/harness/knowledge/describe.d.ts +8 -0
  228. package/dist/harness/knowledge/describe.js +18 -2
  229. package/dist/harness/knowledge/engine-thread.js +6 -0
  230. package/dist/harness/knowledge/grounding.js +3 -1
  231. package/dist/harness/knowledge/http-app.js +35 -4
  232. package/dist/harness/knowledge/http-params.d.ts +18 -0
  233. package/dist/harness/knowledge/http-params.js +24 -0
  234. package/dist/harness/knowledge/index.d.ts +2 -0
  235. package/dist/harness/knowledge/index.js +1 -0
  236. package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
  237. package/dist/harness/knowledge/purge.js +5 -2
  238. package/dist/harness/knowledge/query-service.d.ts +13 -2
  239. package/dist/harness/knowledge/query-service.js +4 -2
  240. package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
  241. package/dist/harness/knowledge/query-worker-client.js +4 -2
  242. package/dist/harness/knowledge/query-worker.js +4 -2
  243. package/dist/harness/knowledge/read-http.js +5 -1
  244. package/dist/harness/knowledge/serve.d.ts +8 -7
  245. package/dist/harness/knowledge/serve.js +9 -0
  246. package/dist/harness/knowledge/source-store.js +26 -3
  247. package/dist/harness/knowledge/start-service-process.d.ts +15 -7
  248. package/dist/harness/knowledge/start-service-process.js +21 -9
  249. package/dist/harness/knowledge/types.d.ts +7 -0
  250. package/dist/harness/knowledge/writer-service.d.ts +37 -9
  251. package/dist/harness/knowledge/writer-service.js +120 -14
  252. package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
  253. package/dist/harness/knowledge/writer-worker-client.js +20 -2
  254. package/dist/harness/knowledge/writer-worker.js +9 -1
  255. package/dist/harness/memory/index.d.ts +6 -2
  256. package/dist/harness/memory/index.js +4 -1
  257. package/dist/harness/memory/memory-events.d.ts +25 -0
  258. package/dist/harness/memory/memory-events.js +38 -0
  259. package/dist/harness/memory/sqlite/agent-db.js +15 -0
  260. package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
  261. package/dist/harness/memory/sqlite/wisdom-store.js +86 -12
  262. package/dist/harness/memory/steward-policy.d.ts +3 -0
  263. package/dist/harness/memory/steward-policy.js +1 -1
  264. package/dist/harness/memory/types.d.ts +47 -7
  265. package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
  266. package/dist/harness/memory/wisdom-attribution.js +287 -0
  267. package/dist/harness/memory/wisdom-events.d.ts +37 -0
  268. package/dist/harness/memory/wisdom-events.js +61 -0
  269. package/dist/harness/memory/wisdom-formation.d.ts +31 -1
  270. package/dist/harness/memory/wisdom-formation.js +130 -33
  271. package/dist/harness/memory/wisdom-gates.d.ts +14 -0
  272. package/dist/harness/memory/wisdom-gates.js +59 -19
  273. package/dist/harness/memory/wisdom.d.ts +7 -2
  274. package/dist/harness/memory/wisdom.js +49 -2
  275. package/dist/harness/observability/observer/hub.js +25 -15
  276. package/dist/harness/observability/observer/types.d.ts +10 -6
  277. package/dist/harness/run/agent/agent.d.ts +40 -21
  278. package/dist/harness/run/agent/agent.js +66 -13
  279. package/dist/harness/run/agent/index.d.ts +1 -1
  280. package/dist/harness/run/budget/budget.d.ts +28 -10
  281. package/dist/harness/run/budget/budget.js +38 -15
  282. package/dist/harness/run/model/index.d.ts +3 -1
  283. package/dist/harness/run/model/index.js +2 -1
  284. package/dist/harness/run/model/resolver.d.ts +4 -1
  285. package/dist/harness/run/model/resolver.js +36 -2
  286. package/dist/harness/run/model/run-scope.d.ts +2 -0
  287. package/dist/harness/run/model/run-scope.js +7 -0
  288. package/dist/harness/run/model/types.d.ts +22 -5
  289. package/dist/harness/run/model/types.js +3 -2
  290. package/dist/harness/run/model/window-truth.d.ts +37 -0
  291. package/dist/harness/run/model/window-truth.js +39 -0
  292. package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
  293. package/dist/harness/run/reliability/context-length-feedback.js +128 -0
  294. package/dist/harness/run/reliability/harness-events.d.ts +3 -3
  295. package/dist/harness/run/reliability/model-error-policy.js +4 -0
  296. package/dist/harness/run/reliability/run-agent.d.ts +10 -4
  297. package/dist/harness/run/reliability/run-agent.js +137 -53
  298. package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
  299. package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
  300. package/dist/harness/run/run-guard/default-run-guard.js +8 -8
  301. package/dist/harness/run/run-scope.d.ts +41 -4
  302. package/dist/harness/run/runner.d.ts +71 -31
  303. package/dist/harness/run/runner.js +368 -106
  304. package/dist/harness/session/attachments/index.d.ts +1 -0
  305. package/dist/harness/session/attachments/index.js +1 -0
  306. package/dist/harness/session/attachments/inject.d.ts +21 -10
  307. package/dist/harness/session/attachments/inject.js +76 -24
  308. package/dist/harness/session/attachments/recall-index.d.ts +70 -0
  309. package/dist/harness/session/attachments/recall-index.js +219 -0
  310. package/dist/harness/session/attachments/service.d.ts +21 -0
  311. package/dist/harness/session/attachments/service.js +258 -139
  312. package/dist/harness/session/attachments/types.d.ts +6 -0
  313. package/dist/harness/session/transform-store.d.ts +136 -0
  314. package/dist/harness/session/transform-store.js +302 -0
  315. package/dist/harness/session/types.d.ts +2 -2
  316. package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
  317. package/dist/harness/shared/events/agent-event-map.js +3 -2
  318. package/dist/harness/shared/events/scenario-events.d.ts +6 -6
  319. package/dist/harness/shared/paths/glob.d.ts +52 -0
  320. package/dist/harness/shared/paths/glob.js +218 -0
  321. package/dist/harness/shared/paths/index.d.ts +84 -0
  322. package/dist/harness/shared/paths/index.js +179 -0
  323. package/dist/harness/shared/types/agent-definition.d.ts +1 -2
  324. package/dist/index.d.ts +14 -17
  325. package/dist/index.js +7 -9
  326. package/dist/integration/observability/metrics.d.ts +6 -6
  327. package/dist/integration/observability/metrics.js +13 -13
  328. package/dist/integration/observability/observer-bridge.js +2 -2
  329. package/dist/integration/observability/trace-collector.d.ts +5 -5
  330. package/dist/integration/observability/trace-collector.js +34 -35
  331. package/dist/integration/observability/trace-events.d.ts +3 -3
  332. package/dist/integration/observability/trace-events.js +3 -3
  333. package/dist/integration/providers/anthropic.js +14 -1
  334. package/dist/integration/providers/openai.js +7 -1
  335. package/dist/integration/providers/usage.d.ts +1 -1
  336. package/dist/integration/providers/wire-dump.d.ts +1 -1
  337. package/dist/integration/storage/archive-manager.d.ts +6 -0
  338. package/dist/integration/storage/archive-manager.js +10 -0
  339. package/dist/integration/storage/jsonl.d.ts +1 -1
  340. package/dist/integration/storage/jsonl.js +18 -16
  341. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
  342. package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
  343. package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
  344. package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
  345. package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
  346. package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
  347. package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
  348. package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
  349. package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
  350. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
  351. package/dist/subsystems/wisdom-steward/formation/config.yaml +13 -5
  352. package/dist/subsystems/wisdom-steward/formation/handler.js +39 -23
  353. package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
  354. package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
  355. package/package.json +16 -14
  356. package/dist/harness/context/hybrid-compressor.d.ts +0 -41
  357. package/dist/harness/context/hybrid-compressor.js +0 -159
  358. package/dist/harness/context/llm-summarizer.d.ts +0 -46
  359. package/dist/harness/context/llm-summarizer.js +0 -249
  360. package/dist/harness/context/smart-router.d.ts +0 -75
  361. package/dist/harness/context/smart-router.js +0 -118
  362. package/dist/harness/context/truncate-compressor.d.ts +0 -28
  363. package/dist/harness/context/truncate-compressor.js +0 -107
  364. package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
  365. package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
  366. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
  367. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
  368. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
  369. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
@@ -8,7 +8,9 @@ import { KnowledgeSourceStore } from './source-store.js';
8
8
  import { KnowledgeIndexStore } from './index-store.js';
9
9
  import { MembershipStore } from './membership-store.js';
10
10
  import { KnowledgeIngest } from './ingest.js';
11
- import { generateKnowledgeDescription } from './describe.js';
11
+ import { generateKnowledgeDescription, normalizeGeneratedDescription, } from './describe.js';
12
+ import { assembleDescribeSample, DESCRIBE_SAMPLE_MAX_CHARS } from './describe-sample.js';
13
+ import { scanSecretShapes } from './secret-scan.js';
12
14
  /** 进程内唯一写者(测试 / :memory:)。 */
13
15
  export class LocalKnowledgeWriteService {
14
16
  deps;
@@ -29,6 +31,7 @@ export class LocalKnowledgeWriteService {
29
31
  documentConfig: deps.documentConfig ?? null,
30
32
  embeddingProvider: embed?.enabled === false ? null : (deps.embeddingProvider ?? null),
31
33
  credentials: deps.credentials ?? null,
34
+ ...(deps.ingest ?? {}),
32
35
  ...(embed?.embedBatch != null ? { embedBatch: embed.embedBatch } : {}),
33
36
  ...(embed?.embedMinIntervalMs != null ? { embedMinIntervalMs: embed.embedMinIntervalMs } : {}),
34
37
  ...(embed?.embedConcurrency != null ? { embedConcurrency: embed.embedConcurrency } : {}),
@@ -185,19 +188,68 @@ export class LocalKnowledgeWriteService {
185
188
  this.sources.remove(sourceId);
186
189
  return { id: sourceId, purgedFiles: purged.length };
187
190
  }
188
- async describeSource(identity, sourceId) {
191
+ async describeSource(identity, sourceId, input) {
189
192
  await this.assertSourceOwner(identity, sourceId);
190
193
  const src = this.sources.get(sourceId);
191
194
  if (!src)
192
195
  return null;
193
- const paths = this.db.raw
194
- .prepare('SELECT logical_path FROM knowledge_memberships WHERE source_id = ? ORDER BY logical_path LIMIT 20')
195
- .all(sourceId);
196
- const sample = paths.map((p) => p.logical_path).join('\n') || src.location;
197
- const r = await generateKnowledgeDescription(src, sample, { enabled: true });
198
- this.sources.update(sourceId, { generatedDescription: r.description });
196
+ if (input?.description != null) {
197
+ // 写入口(B 方案回写):调用方是 gateway 的 LLM describe 流程;内容在出 Service 前过密钥扫描,
198
+ // 但描述会进系统提示 catalog 行——写入侧强制单行归一(防多行注入伪造 catalog 行)
199
+ const text = normalizeGeneratedDescription(input.description);
200
+ if (!text) {
201
+ throw Object.assign(new Error('description empty'), { code: 'bad_request' });
202
+ }
203
+ const source = input.source === 'heuristic' ? 'heuristic' : 'llm';
204
+ this.sources.update(sourceId, {
205
+ generatedDescription: text,
206
+ generatedDescriptionSource: source,
207
+ });
208
+ return { generatedDescription: text, source };
209
+ }
210
+ const r = await this.describeWithSample(src);
211
+ this.sources.update(sourceId, {
212
+ generatedDescription: r.description,
213
+ generatedDescriptionSource: r.source === 'disabled' ? 'heuristic' : r.source,
214
+ });
199
215
  return { generatedDescription: r.description, source: r.source };
200
216
  }
217
+ async describeSample(identity, sourceId) {
218
+ await this.assertSourceOwner(identity, sourceId);
219
+ const src = this.sources.get(sourceId);
220
+ if (!src)
221
+ return null;
222
+ const sample = assembleDescribeSample(this.db, sourceId);
223
+ // 密钥形态封锁:命中即不外发样本(fail-safe,同 generateKnowledgeDescription 口径)
224
+ const secretHits = scanSecretShapes(sample);
225
+ if (secretHits.length > 0)
226
+ return { blocked: true, secretHits };
227
+ return {
228
+ blocked: false,
229
+ meta: { displayName: src.displayName, kind: src.kind, location: src.location },
230
+ sample,
231
+ };
232
+ }
233
+ async listDescribePending(identity) {
234
+ // 待升级 = 有启发式/legacy 自动描述、无人工描述、归因非 llm(legacy NULL 视为 heuristic)
235
+ const rows = this.db.raw
236
+ .prepare(`SELECT id FROM knowledge_sources
237
+ WHERE generated_description IS NOT NULL
238
+ AND description IS NULL
239
+ AND (generated_description_source IS NULL OR generated_description_source = 'heuristic')
240
+ AND status NOT IN ('removed', 'disabled')
241
+ AND (registered_by IS NULL OR registered_by = '' OR registered_by = ?)`)
242
+ .all(identity.gatewayId);
243
+ return rows.map((r) => r.id);
244
+ }
245
+ /** 启发式/封锁描述生成(无 describePort:Service 侧永不含 LLM 出网,B 方案拍板) */
246
+ describeWithSample(src) {
247
+ const sample = assembleDescribeSample(this.db, src.id);
248
+ return generateKnowledgeDescription(src, sample, {
249
+ enabled: true,
250
+ sampleChars: DESCRIBE_SAMPLE_MAX_CHARS,
251
+ });
252
+ }
201
253
  async assertSourceOwner(identity, sourceId) {
202
254
  const row = this.db.raw
203
255
  .prepare('SELECT registered_by FROM knowledge_sources WHERE id = ?')
@@ -311,17 +363,41 @@ export class LocalKnowledgeWriteService {
311
363
  async startIngestRuntime() {
312
364
  const { sources, ingest } = this;
313
365
  ingest.onSourceSettled = (sourceId) => {
366
+ // catalog.autoDescribe=false:索引稳定后不自动生成 generatedDescription(v0.51.5 语义)
367
+ if (this.deps.autoDescribe === false)
368
+ return;
314
369
  void (async () => {
315
370
  try {
316
371
  const src = sources.get(sourceId);
317
372
  if (!src || src.description?.trim())
318
373
  return;
319
- const paths = this.db.raw
320
- .prepare('SELECT logical_path FROM knowledge_memberships WHERE source_id = ? ORDER BY logical_path LIMIT 20')
321
- .all(sourceId);
322
- const sample = paths.map((p) => p.logical_path).join('\n') || src.location;
323
- const r = await generateKnowledgeDescription(src, sample, { enabled: true });
324
- sources.update(sourceId, { generatedDescription: r.description });
374
+ // llm 归因是更高信任档:settle 不降级、不重发(B 方案 2026-11-02)
375
+ if (src.generatedDescriptionSource === 'llm')
376
+ return;
377
+ const r = await this.describeWithSample(src);
378
+ const source = r.source === 'disabled' ? 'heuristic' : r.source;
379
+ // startReconciler 每 15s 对稳态源反复触发本钩子(ingest.ts):文本与归因都
380
+ // 无变化则不写不发,掐断「每 tick 重发 describe-pending → gateway 每 tick
381
+ // LLM 升级」成本环。归因必须参与比较——blocked_secret 与 heuristic 共享同一
382
+ // 启发式文本,只比文本会让「封锁→清洁」的归因回退永远卡死(评审 P1-1)
383
+ if (src.generatedDescription === r.description &&
384
+ src.generatedDescriptionSource === source) {
385
+ return;
386
+ }
387
+ sources.update(sourceId, {
388
+ generatedDescription: r.description,
389
+ generatedDescriptionSource: source,
390
+ });
391
+ // B 方案(2026-11-02 拍板):LLM 描述由 gateway 代生成。
392
+ // 启发式落库即发升级信号;blocked_secret(抽样含密钥形态)不发——素材不得外发。
393
+ if (source === 'heuristic') {
394
+ this.emitProgress({
395
+ type: 'source',
396
+ sourceId,
397
+ status: 'describe-pending',
398
+ detail: 'llm upgrade eligible',
399
+ });
400
+ }
325
401
  }
326
402
  catch {
327
403
  /* describe 失败不影响索引 */
@@ -349,6 +425,36 @@ export class LocalKnowledgeWriteService {
349
425
  this.progressCbs.delete(cb);
350
426
  };
351
427
  }
428
+ /** Writer 自产事件(describe-pending 等);归属补齐口径与 IngestProgressEvent 一致 */
429
+ emitProgress(evt) {
430
+ let out = evt;
431
+ if (evt.sourceId && evt.registeredBy === undefined) {
432
+ try {
433
+ const row = this.db.raw
434
+ .prepare('SELECT tenant_id, registered_by, visibility FROM knowledge_sources WHERE id = ?')
435
+ .get(evt.sourceId);
436
+ if (row) {
437
+ out = {
438
+ ...evt,
439
+ tenantId: row.tenant_id,
440
+ registeredBy: row.registered_by,
441
+ visibility: row.visibility,
442
+ };
443
+ }
444
+ }
445
+ catch {
446
+ /* 源已删时保持原事件;SSE 侧按无归属放行到 fallback */
447
+ }
448
+ }
449
+ for (const cb of this.progressCbs) {
450
+ try {
451
+ cb(out);
452
+ }
453
+ catch {
454
+ /* SSE 订阅方异常不得打断 describe */
455
+ }
456
+ }
457
+ }
352
458
  async dispose() {
353
459
  this.progressCbs.clear();
354
460
  this.ingest.dispose();
@@ -1,8 +1,9 @@
1
- import type { KnowledgeWriteService, WriteIdentity, WriteAbortStats, WriteResumeStats, WriteRegisterResult, WriteDescribeResult, WriteReprocessResult } from './writer-service.js';
1
+ import type { KnowledgeWriteService, WriteIdentity, WriteAbortStats, WriteResumeStats, WriteRegisterResult, WriteDescribeResult, WriteDescribeInput, WriteDescribeSampleResult, WriteReprocessResult } from './writer-service.js';
2
2
  import type { KnowledgeSource } from './types.js';
3
3
  import type { KnowledgeJobControlState } from './job-control-state.js';
4
4
  import type { IngestProgressEvent } from './ingest.js';
5
5
  import type { DocumentCapabilityConfig } from '../capabilities/document/factory.js';
6
+ import type { KnowledgeBootEmbed, KnowledgeBootIngest } from './boot-config.js';
6
7
  export interface WorkerWriteStartOptions {
7
8
  dbPath: string;
8
9
  documentConfig?: DocumentCapabilityConfig | null;
@@ -11,13 +12,11 @@ export interface WorkerWriteStartOptions {
11
12
  providers?: Record<string, unknown>;
12
13
  embedding?: unknown;
13
14
  } | null;
14
- embed?: {
15
- enabled?: boolean;
16
- embedBatch?: number;
17
- embedMinIntervalMs?: number;
18
- embedConcurrency?: number;
19
- embedSecretPolicy?: 'allow' | 'redact' | 'skip';
20
- } | null;
15
+ embed?: KnowledgeBootEmbed | null;
16
+ /** Ingest 调参(knowledge.load / index.queue / index.files) */
17
+ ingest?: KnowledgeBootIngest | null;
18
+ /** false = 索引稳定后不自动生成 generatedDescription(knowledge.catalog.autoDescribe) */
19
+ autoDescribe?: boolean;
21
20
  testEmbeddingStub?: boolean;
22
21
  timeoutMs?: number;
23
22
  }
@@ -64,7 +63,9 @@ export declare class WorkerWriteService implements KnowledgeWriteService {
64
63
  id: string;
65
64
  purgedFiles: number;
66
65
  }>;
67
- describeSource(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeResult | null>;
66
+ describeSource(identity: WriteIdentity, sourceId: string, input?: WriteDescribeInput): Promise<WriteDescribeResult | null>;
67
+ describeSample(identity: WriteIdentity, sourceId: string): Promise<WriteDescribeSampleResult | null>;
68
+ listDescribePending(identity: WriteIdentity): Promise<string[]>;
68
69
  reindexSource(sourceId: string): Promise<void>;
69
70
  reprocessFiles(sourceId: string, paths: string[]): Promise<WriteReprocessResult>;
70
71
  reprocessByFilter(sourceId: string, filter?: {
@@ -93,6 +93,8 @@ export class WorkerWriteService {
93
93
  sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
94
94
  embeddingModels: opts.embeddingModels ?? null,
95
95
  embed: opts.embed ?? null,
96
+ ingest: opts.ingest ?? null,
97
+ autoDescribe: opts.autoDescribe,
96
98
  testEmbeddingStub: opts.testEmbeddingStub ?? false,
97
99
  },
98
100
  env: process.env,
@@ -225,9 +227,25 @@ export class WorkerWriteService {
225
227
  this.rethrow(e);
226
228
  }
227
229
  }
228
- async describeSource(identity, sourceId) {
230
+ async describeSource(identity, sourceId, input) {
229
231
  try {
230
- return (await this.call('describeSource', { identity, sourceId }));
232
+ return (await this.call('describeSource', { identity, sourceId, input }));
233
+ }
234
+ catch (e) {
235
+ this.rethrow(e);
236
+ }
237
+ }
238
+ async describeSample(identity, sourceId) {
239
+ try {
240
+ return (await this.call('describeSample', { identity, sourceId }));
241
+ }
242
+ catch (e) {
243
+ this.rethrow(e);
244
+ }
245
+ }
246
+ async listDescribePending(identity) {
247
+ try {
248
+ return (await this.call('listDescribePending', { identity }));
231
249
  }
232
250
  catch (e) {
233
251
  this.rethrow(e);
@@ -46,6 +46,8 @@ async function main() {
46
46
  documentConfig: boot.documentConfig ?? null,
47
47
  embeddingProvider: embeddingProvider,
48
48
  embed: boot.embed ?? null,
49
+ ingest: boot.ingest ?? null,
50
+ autoDescribe: boot.autoDescribe,
49
51
  });
50
52
  write.onProgress((evt) => {
51
53
  port.postMessage({ type: 'progress', evt });
@@ -105,7 +107,13 @@ async function main() {
105
107
  data = await write.removeSource(identity, String(args.sourceId));
106
108
  break;
107
109
  case 'describeSource':
108
- data = await write.describeSource(identity, String(args.sourceId));
110
+ data = await write.describeSource(identity, String(args.sourceId), args.input);
111
+ break;
112
+ case 'describeSample':
113
+ data = await write.describeSample(identity, String(args.sourceId));
114
+ break;
115
+ case 'listDescribePending':
116
+ data = await write.listDescribePending(identity);
109
117
  break;
110
118
  case 'reindexSource':
111
119
  await write.reindexSource(String(args.sourceId));
@@ -4,13 +4,17 @@
4
4
  * 价值模型:fact / method / norm(见 docs/memory.md、arch/memory-system-redesign.md)。
5
5
  * system prompt ContextLayer 契约在 harness/context/。
6
6
  */
7
- export type { MemoryType, MemoryChannel, MemoryStatus, SoftDeleteReason, MemoryEntry, MemoryQuery, MemoryStats, MemoryStore, MemoryWriteSlot, WisdomStatus, WisdomOrigin, WisdomKind, WisdomRetireReason, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomCounterevidence, WisdomOutcomes, WisdomEntry, WisdomGateReason, WisdomGateOutcome, AdmitWisdomInput, AdmitWisdomAction, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomOutcomeSignal, WisdomOutcomeEvent, WisdomStats, WisdomStore, ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, EdgeAux, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './types.js';
7
+ export type { MemoryType, MemoryChannel, MemoryStatus, SoftDeleteReason, MemoryEntry, MemoryQuery, MemoryStats, MemoryStore, MemoryWriteSlot, WisdomStatus, WisdomOrigin, WisdomKind, WisdomRetireReason, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomCounterevidence, WisdomOutcomes, WisdomEntry, WisdomGateReason, WisdomGateOutcome, AdmitWisdomInput, AdmitWisdomAction, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomOutcomeSignal, WisdomOutcomeEvent, WisdomAttributionCitation, WisdomAttributionWindowInput, WisdomAttributionWindow, WisdomStats, WisdomStore, ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, EdgeAux, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './types.js';
8
8
  export { MEMORY_TYPES, WISDOM_STATUSES, WISDOM_INJECTABLE_STATUSES, WISDOM_ORIGINS, WISDOM_KINDS, CONCEPT_KINDS, CONCEPT_RELATION_TYPES, STRONG_RELATION_TYPES, } from './types.js';
9
9
  export { evaluateWisdomGate, resolveInitialWisdomStatus, normalizeStatement, looksOpposed, WISDOM_DEFAULT_MIN_SUPPORT, } from './wisdom-gates.js';
10
10
  export { DEFAULT_WISDOM_EVALUATION, DEFAULT_WISDOM_GOVERN, foldOutcomeEvents, planConfidenceUpdate, planWisdomGovern, wisdomUtility, wisdomInjectScore, } from './wisdom-policy.js';
11
11
  export type { WisdomEvaluationConfig, WisdomGovernConfig, WisdomConfidenceUpdate, WisdomGoverPlanItem, } from './wisdom-policy.js';
12
- export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
12
+ export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, scenarioMatchDetail, isCoreEligible, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
13
13
  export type { RawWisdomFormationOutput, ParsedWisdomItem, ParsedWisdomFormation, } from './wisdom-formation.js';
14
+ export { extractCitations, collectRunAssistantTexts, recordWisdomRunWindow, selectAttributionCandidates, planAttributionBatch, buildAttributionDigest, parseAttributionVerdicts, verdictsToOutcomeEvents, } from './wisdom-attribution.js';
15
+ export type { WisdomRunWindowInfo, AttributionCandidate, AttributionBatch, AttributionVerdict, } from './wisdom-attribution.js';
16
+ export { emitWisdomEvaluateRequest, emitWisdomGoverned, WISDOM_EVALUATE_REQUEST_EVENT, WISDOM_GOVERNED_EVENT, } from './wisdom-events.js';
17
+ export type { WisdomEvaluateRequestPayload } from './wisdom-events.js';
14
18
  export { evaluateConceptGate, licenseEdge, edgeBasisFromLicense, normalizeForCue, } from './cognition-gates.js';
15
19
  export type { ConceptGateOutcome, EdgeLicenseInput, EdgeLicenseOutcome, } from './cognition-gates.js';
16
20
  export { DEFAULT_EDGE_DECAY_PER_DAY, DEFAULT_EDGE_DECAY_FLOOR, DEFAULT_RETRIEVE_STATUSES, decayMultiplier, nextEdgeStrength, hebbianStrengthen, counterEvidenceWeaken, } from './cognition-decay.js';
@@ -8,7 +8,10 @@ export { MEMORY_TYPES, WISDOM_STATUSES, WISDOM_INJECTABLE_STATUSES, WISDOM_ORIGI
8
8
  // ── Wisdom 门控 / 策略 / 形成 ──
9
9
  export { evaluateWisdomGate, resolveInitialWisdomStatus, normalizeStatement, looksOpposed, WISDOM_DEFAULT_MIN_SUPPORT, } from './wisdom-gates.js';
10
10
  export { DEFAULT_WISDOM_EVALUATION, DEFAULT_WISDOM_GOVERN, foldOutcomeEvents, planConfidenceUpdate, planWisdomGovern, wisdomUtility, wisdomInjectScore, } from './wisdom-policy.js';
11
- export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
11
+ export { parseWisdomFormationJson, normalizeWisdomFormation, toAdmitWisdomInput, formAndAdmit, scenarioMatchScore, scenarioMatchDetail, isCoreEligible, pickForInjection, formatWisdomBody, } from './wisdom-formation.js';
12
+ // ── Wisdom 归因窗口 / 判决事件 ──
13
+ export { extractCitations, collectRunAssistantTexts, recordWisdomRunWindow, selectAttributionCandidates, planAttributionBatch, buildAttributionDigest, parseAttributionVerdicts, verdictsToOutcomeEvents, } from './wisdom-attribution.js';
14
+ export { emitWisdomEvaluateRequest, emitWisdomGoverned, WISDOM_EVALUATE_REQUEST_EVENT, WISDOM_GOVERNED_EVENT, } from './wisdom-events.js';
12
15
  // ── Cognition 门控 / 可塑 / 概念化 ──
13
16
  export { evaluateConceptGate, licenseEdge, edgeBasisFromLicense, normalizeForCue, } from './cognition-gates.js';
14
17
  export { DEFAULT_EDGE_DECAY_PER_DAY, DEFAULT_EDGE_DECAY_FLOOR, DEFAULT_RETRIEVE_STATUSES, decayMultiplier, nextEdgeStrength, hebbianStrengthen, counterEvidenceWeaken, } from './cognition-decay.js';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Memory 存量变化信号 — 每条命题落库后 emit `memory.stored`
3
+ *
4
+ * 消费方(sense.filter.events 订阅):wisdom.steward.formation 等增量触发的子系统。
5
+ * 事件类型必须真实存在于 EventBus;发射失败静默(不得阻断 memory 写路径)。
6
+ *
7
+ * @module harness/memory/memory-events
8
+ */
9
+ import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
10
+ /** 命题落库信号(每条一发;消费方按 minEvents 累积节流) */
11
+ export declare const MEMORY_STORED_EVENT = "memory.stored";
12
+ export interface MemoryStoredPayload {
13
+ memoryId: string;
14
+ type?: string;
15
+ status?: string;
16
+ sessionId?: string;
17
+ agentId?: string;
18
+ }
19
+ /**
20
+ * 发射命题落库信号。失败静默(不得阻断 Memory 写入)。
21
+ *
22
+ * @param events - EventBus
23
+ * @param payload - 落库载荷
24
+ */
25
+ export declare function emitMemoryStored(events: EventBus | undefined, payload: MemoryStoredPayload): void;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Memory 存量变化信号 — 每条命题落库后 emit `memory.stored`
3
+ *
4
+ * 消费方(sense.filter.events 订阅):wisdom.steward.formation 等增量触发的子系统。
5
+ * 事件类型必须真实存在于 EventBus;发射失败静默(不得阻断 memory 写路径)。
6
+ *
7
+ * @module harness/memory/memory-events
8
+ */
9
+ /** 命题落库信号(每条一发;消费方按 minEvents 累积节流) */
10
+ export const MEMORY_STORED_EVENT = 'memory.stored';
11
+ /**
12
+ * 发射命题落库信号。失败静默(不得阻断 Memory 写入)。
13
+ *
14
+ * @param events - EventBus
15
+ * @param payload - 落库载荷
16
+ */
17
+ export function emitMemoryStored(events, payload) {
18
+ if (!events)
19
+ return;
20
+ try {
21
+ events.emit({
22
+ type: MEMORY_STORED_EVENT,
23
+ timestamp: Date.now(),
24
+ agentId: payload.agentId,
25
+ sessionId: payload.sessionId,
26
+ data: {
27
+ memoryId: payload.memoryId,
28
+ type: payload.type,
29
+ status: payload.status,
30
+ sessionId: payload.sessionId,
31
+ agentId: payload.agentId,
32
+ },
33
+ });
34
+ }
35
+ catch {
36
+ // 总线异常不得拖垮 Memory 写入
37
+ }
38
+ }
@@ -297,6 +297,21 @@ export class AgentDatabase {
297
297
  CREATE INDEX IF NOT EXISTS idx_wisdom_status ON wisdom(status);
298
298
  CREATE INDEX IF NOT EXISTS idx_wisdom_priority ON wisdom(priority);
299
299
 
300
+ -- ── Wisdom 归因窗口(弱归因验证:run 收尾记账,判官批量判决)──
301
+ CREATE TABLE IF NOT EXISTS wisdom_attribution_windows (
302
+ id TEXT PRIMARY KEY,
303
+ session_id TEXT NOT NULL,
304
+ agent_id TEXT,
305
+ query TEXT NOT NULL DEFAULT '',
306
+ outcome TEXT NOT NULL DEFAULT '',
307
+ injected_ids TEXT NOT NULL DEFAULT '[]',
308
+ citations TEXT NOT NULL DEFAULT '[]',
309
+ created_at INTEGER NOT NULL,
310
+ judged_at INTEGER
311
+ );
312
+ CREATE INDEX IF NOT EXISTS idx_wisdom_windows_judged ON wisdom_attribution_windows(judged_at);
313
+ CREATE INDEX IF NOT EXISTS idx_wisdom_windows_created ON wisdom_attribution_windows(created_at);
314
+
300
315
  -- ── Knowledge Sources 注册表 ──
301
316
  CREATE TABLE IF NOT EXISTS knowledge_sources (
302
317
  id TEXT PRIMARY KEY,
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @module
7
7
  */
8
- import type { AdmitWisdomInput, AdmitWisdomResult, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomOutcomeEvent, WisdomRetireReason, WisdomStats, WisdomStore } from '../types.js';
8
+ import type { AdmitWisdomInput, AdmitWisdomResult, WisdomAttributionWindow, WisdomAttributionWindowInput, WisdomEntry, WisdomInjectPick, WisdomInjectQuery, WisdomOutcomeEvent, WisdomRetireReason, WisdomStats, WisdomStore } from '../types.js';
9
9
  import { AgentDatabase } from './agent-db.js';
10
10
  export interface SqliteWisdomStoreOptions {
11
11
  /** admit 硬顶(存活面);默认 80 */
@@ -29,8 +29,13 @@ export declare class SqliteWisdomStore implements WisdomStore {
29
29
  by: string;
30
30
  reason: WisdomRetireReason | string;
31
31
  }): Promise<void>;
32
- recordOutcomes(events: WisdomOutcomeEvent[]): Promise<void>;
32
+ recordOutcomes(events: WisdomOutcomeEvent[], config?: import('../wisdom-policy.js').WisdomEvaluationConfig): Promise<void>;
33
33
  touchApplied(ids: string[]): Promise<void>;
34
+ recordAttributionWindow(input: WisdomAttributionWindowInput): Promise<string>;
35
+ listPendingWindows(limit?: number): Promise<WisdomAttributionWindow[]>;
36
+ markWindowsJudged(ids: string[], at?: number): Promise<string[]>;
37
+ pruneWindows(before: number): Promise<void>;
38
+ private rowToWindow;
34
39
  stats(): Promise<WisdomStats>;
35
40
  /** 存活面计数(candidate/trial/active/strengthened/contested) */
36
41
  countLive(): number;
@@ -31,6 +31,15 @@ export class SqliteWisdomStore {
31
31
  const now = Date.now();
32
32
  const status = resolveInitialWisdomStatus(input);
33
33
  const id = AgentDatabase.generateId('wis');
34
+ const insertRow = () => {
35
+ this.db.raw
36
+ .prepare(`INSERT INTO wisdom (
37
+ id, statement, rationale, scenario_json, effect_json, status, confidence, priority,
38
+ derived_from_json, exceptions_json, counterevidence_json, outcomes_json,
39
+ origin, kind, superseded_by, created_at, updated_at
40
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
41
+ .run(id, input.statement.trim(), input.rationale?.trim() || null, JSON.stringify(input.scenario), JSON.stringify(input.effect), status, clamp01(input.confidence ?? defaultConfidence(status, input.origin ?? 'distilled')), input.priority ?? defaultPriority(status, input.origin ?? 'distilled'), JSON.stringify(input.derivedFrom), JSON.stringify(input.exceptions ?? []), JSON.stringify([]), JSON.stringify(emptyOutcomes()), input.origin ?? 'distilled', input.kind, null, now, now);
42
+ };
34
43
  if (input.supersedesId) {
35
44
  const prev = this.getSync(input.supersedesId);
36
45
  if (!prev) {
@@ -40,17 +49,32 @@ export class SqliteWisdomStore {
40
49
  message: `supersedesId=${input.supersedesId}`,
41
50
  };
42
51
  }
43
- this.db.raw
44
- .prepare(`UPDATE wisdom SET status = 'superseded', superseded_by = ?, updated_at = ? WHERE id = ?`)
45
- .run(id, now, prev.id);
52
+ // 取代目标必须存活(retired/superseded 已退出主题);factory 是人格级预设,
53
+ // 只经人工通道更换,不许炼制回路静默取代(否则 govern 的出厂保护被绕过)
54
+ if (prev.status === 'retired' || prev.status === 'superseded' || prev.origin === 'factory') {
55
+ return {
56
+ action: 'rejected',
57
+ reason: 'supersedes_target_invalid',
58
+ message: `supersedes_target=${prev.status}/${prev.origin}`,
59
+ };
60
+ }
61
+ // 旧条目改写与新条目写入同事务:避免 INSERT 失败留下「已 superseded 但无继任者」悬挂链
62
+ this.db.raw.exec('BEGIN IMMEDIATE');
63
+ try {
64
+ this.db.raw
65
+ .prepare(`UPDATE wisdom SET status = 'superseded', superseded_by = ?, updated_at = ? WHERE id = ?`)
66
+ .run(id, now, prev.id);
67
+ insertRow();
68
+ this.db.raw.exec('COMMIT');
69
+ }
70
+ catch (err) {
71
+ this.db.raw.exec('ROLLBACK');
72
+ throw err;
73
+ }
74
+ }
75
+ else {
76
+ insertRow();
46
77
  }
47
- this.db.raw
48
- .prepare(`INSERT INTO wisdom (
49
- id, statement, rationale, scenario_json, effect_json, status, confidence, priority,
50
- derived_from_json, exceptions_json, counterevidence_json, outcomes_json,
51
- origin, kind, superseded_by, created_at, updated_at
52
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
53
- .run(id, input.statement.trim(), input.rationale?.trim() || null, JSON.stringify(input.scenario), JSON.stringify(input.effect), status, clamp01(input.confidence ?? defaultConfidence(status, input.origin ?? 'distilled')), input.priority ?? defaultPriority(status, input.origin ?? 'distilled'), JSON.stringify(input.derivedFrom), JSON.stringify(input.exceptions ?? []), JSON.stringify([]), JSON.stringify(emptyOutcomes()), input.origin ?? 'distilled', input.kind, null, now, now);
54
78
  return {
55
79
  action: input.supersedesId ? 'superseded' : 'created',
56
80
  id,
@@ -68,6 +92,7 @@ export class SqliteWisdomStore {
68
92
  return pickForInjection(entries, query.text ?? '', {
69
93
  coreMaxItems: query.coreMaxItems,
70
94
  scenarioMaxItems: query.scenarioMaxItems,
95
+ trialMaxItems: query.trialMaxItems,
71
96
  includeTrial: query.includeTrial,
72
97
  });
73
98
  }
@@ -112,7 +137,7 @@ export class SqliteWisdomStore {
112
137
  exceptions: [...(current.exceptions ?? []), `retired:${meta.reason}:${meta.by}`],
113
138
  });
114
139
  }
115
- async recordOutcomes(events) {
140
+ async recordOutcomes(events, config) {
116
141
  if (events.length === 0)
117
142
  return;
118
143
  const byId = new Map();
@@ -127,7 +152,7 @@ export class SqliteWisdomStore {
127
152
  continue;
128
153
  const folded = foldOutcomeEvents(current, evs);
129
154
  let next = { ...current, ...folded, updatedAt: Date.now() };
130
- const plan = planConfidenceUpdate(next);
155
+ const plan = planConfidenceUpdate(next, config);
131
156
  if (plan) {
132
157
  next = {
133
158
  ...next,
@@ -174,6 +199,55 @@ export class SqliteWisdomStore {
174
199
  .run(JSON.stringify(outcomes), now, id);
175
200
  }
176
201
  }
202
+ async recordAttributionWindow(input) {
203
+ const id = AgentDatabase.generateId('waw');
204
+ this.db.raw
205
+ .prepare(`INSERT INTO wisdom_attribution_windows
206
+ (id, session_id, agent_id, query, outcome, injected_ids, citations, created_at)
207
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
208
+ .run(id, input.sessionId, input.agentId ?? null, input.query, input.outcome, JSON.stringify(input.injectedIds), JSON.stringify(input.citations), Date.now());
209
+ return id;
210
+ }
211
+ async listPendingWindows(limit) {
212
+ const rows = this.db.raw
213
+ .prepare(`SELECT * FROM wisdom_attribution_windows WHERE judged_at IS NULL
214
+ ORDER BY created_at ASC LIMIT ?`)
215
+ .all(limit && limit > 0 ? limit : 500);
216
+ return rows.map((r) => this.rowToWindow(r));
217
+ }
218
+ async markWindowsJudged(ids, at) {
219
+ if (ids.length === 0)
220
+ return [];
221
+ const now = at ?? Date.now();
222
+ const stmt = this.db.raw.prepare(`UPDATE wisdom_attribution_windows SET judged_at = ? WHERE id = ? AND judged_at IS NULL`);
223
+ const newlyJudged = [];
224
+ for (const id of ids) {
225
+ // 只有真正置上的才算本次标记(跨进程幂等:他方先标则不发事件)
226
+ const res = stmt.run(now, id);
227
+ if (Number(res.changes ?? 0) > 0)
228
+ newlyJudged.push(id);
229
+ }
230
+ return newlyJudged;
231
+ }
232
+ async pruneWindows(before) {
233
+ this.db.raw
234
+ .prepare(`DELETE FROM wisdom_attribution_windows WHERE judged_at IS NOT NULL AND judged_at < ?`)
235
+ .run(before);
236
+ }
237
+ rowToWindow(r) {
238
+ return {
239
+ id: String(r.id),
240
+ sessionId: String(r.session_id),
241
+ agentId: r.agent_id == null ? undefined : String(r.agent_id),
242
+ query: String(r.query ?? ''),
243
+ outcome: String(r.outcome ?? ''),
244
+ // 坏行不得毒化整批(手工损坏/半写 JSON 跳过字段而非抛错)
245
+ injectedIds: safeParse(String(r.injected_ids ?? ''), []),
246
+ citations: safeParse(String(r.citations ?? ''), []),
247
+ createdAt: Number(r.created_at),
248
+ judgedAt: r.judged_at == null ? undefined : Number(r.judged_at),
249
+ };
250
+ }
177
251
  async stats() {
178
252
  const rows = this.db.raw.prepare(`SELECT * FROM wisdom`).all();
179
253
  const byStatus = Object.fromEntries(WISDOM_STATUSES.map((s) => [s, 0]));
@@ -76,6 +76,9 @@ export interface AdmitResult {
76
76
  id: string;
77
77
  type: MemoryType;
78
78
  status: string;
79
+ proposition: string;
80
+ channel: string;
81
+ evidence?: string;
79
82
  }>;
80
83
  rejected: Array<{
81
84
  reason: AdmitRejectReason;
@@ -275,7 +275,7 @@ export async function admitCandidates(store, candidates, source) {
275
275
  if (idx >= 0)
276
276
  live.splice(idx, 1);
277
277
  }
278
- accepted.push({ id, type, status });
278
+ accepted.push({ id, type, status, proposition: c.proposition, channel: c.channel ?? 'model_inference', evidence: c.evidence });
279
279
  sourceCount += 1;
280
280
  // 同批后续候选可对刚写入条目判重
281
281
  live.push({