@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
@@ -6,7 +6,7 @@
6
6
  * 原则:原件 + .manifest.json 为权威;抽取/索引可重建。
7
7
  */
8
8
  import { createHash, randomUUID } from 'node:crypto';
9
- import { readFileSync } from 'node:fs';
9
+ import { readFileSync, statSync } from 'node:fs';
10
10
  import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
11
11
  import { join } from 'node:path';
12
12
  import { resolveSessionAttachmentsPaths } from './paths.js';
@@ -14,6 +14,20 @@ import { attachmentExtension, isPathInside, sanitizeAttachmentName } from './san
14
14
  import { classifyAttachmentKind, extractCompanionName, extractText, isPlainReadable, } from './extract.js';
15
15
  import { DEFAULT_ATTACHMENT_LIMITS, } from './types.js';
16
16
  import { isDocumentExtractError } from '../../capabilities/document/errors.js';
17
+ import { SessionAttachmentRecallIndex, attachmentExtractHash } from './recall-index.js';
18
+ /** 同一进程内跨 Service 实例的 Session 写临界区,避免多文件上传末写覆盖。 */
19
+ const sessionWriteTails = new Map();
20
+ function serializeSessionWrite(sessionId, operation) {
21
+ const previous = sessionWriteTails.get(sessionId) ?? Promise.resolve();
22
+ const current = previous.then(operation, operation);
23
+ const tail = current.then(() => undefined, () => undefined);
24
+ sessionWriteTails.set(sessionId, tail);
25
+ void tail.finally(() => {
26
+ if (sessionWriteTails.get(sessionId) === tail)
27
+ sessionWriteTails.delete(sessionId);
28
+ });
29
+ return current;
30
+ }
17
31
  export class SessionAttachmentService {
18
32
  sessionsDir;
19
33
  limits;
@@ -79,113 +93,195 @@ export class SessionAttachmentService {
79
93
  * @throws 超限 / 类型不允许
80
94
  */
81
95
  async save(sessionId, input) {
82
- const name = sanitizeAttachmentName(input.name);
83
- const ext = attachmentExtension(name);
84
- if (this.limits.allowedExtensions.length > 0 && ext && !this.limits.allowedExtensions.includes(ext)) {
85
- throw new Error(`file type not allowed: ${ext}`);
86
- }
87
- if (!ext && this.limits.allowedExtensions.length > 0) {
88
- throw new Error('file type not allowed: missing extension');
89
- }
90
- const data = Buffer.isBuffer(input.data)
91
- ? input.data
92
- : typeof input.data === 'string'
93
- ? Buffer.from(input.data, 'utf8')
94
- : Buffer.from(input.data);
95
- if (data.byteLength > this.limits.maxFileBytes) {
96
- throw new Error(`file exceeds maxFileBytes (${this.limits.maxFileBytes})`);
97
- }
98
- const manifest = this.readManifest(sessionId);
99
- const live = manifest.items.filter((i) => i.status !== 'promoted');
100
- if (live.length >= this.limits.maxFiles) {
101
- throw new Error(`too many attachments (max ${this.limits.maxFiles})`);
102
- }
103
- const total = live.reduce((s, i) => s + i.sizeBytes, 0) + data.byteLength;
104
- if (total > this.limits.maxTotalBytes) {
105
- throw new Error(`attachments exceed maxTotalBytes (${this.limits.maxTotalBytes})`);
106
- }
107
- const root = this.attachmentRoot(sessionId);
108
- await mkdir(root, { recursive: true });
109
- const uniqueName = this.uniqueName(live, name);
110
- const abs = join(root, uniqueName);
111
- if (!isPathInside(root, abs)) {
112
- throw new Error('invalid attachment path');
113
- }
114
- await writeFile(abs, data);
115
- const kind = classifyAttachmentKind(uniqueName);
116
- const contentHash = createHash('sha256').update(data).digest('hex');
117
- const item = {
118
- id: `att_${randomUUID().slice(0, 12)}`,
119
- name: uniqueName,
120
- mime: input.mime ?? guessMime(uniqueName),
121
- sizeBytes: data.byteLength,
122
- contentHash: `sha256:${contentHash}`,
123
- path: uniqueName,
124
- status: 'ready',
125
- kind,
126
- createdAt: Date.now(),
127
- };
128
- if (isPlainReadable(kind, uniqueName)) {
129
- item.extractPath = uniqueName;
130
- const extracted = extractText(data, uniqueName, kind);
131
- if (extracted) {
132
- item.status = 'parsed';
133
- item.parse = { ok: true, chars: extracted.chars };
96
+ return serializeSessionWrite(sessionId, async () => {
97
+ const name = sanitizeAttachmentName(input.name);
98
+ const ext = attachmentExtension(name);
99
+ if (this.limits.allowedExtensions.length > 0 && ext && !this.limits.allowedExtensions.includes(ext)) {
100
+ throw new Error(`file type not allowed: ${ext}`);
134
101
  }
135
- else {
136
- item.status = 'parse_failed';
137
- item.parse = { ok: false, error: 'binary content in text extension' };
102
+ if (!ext && this.limits.allowedExtensions.length > 0) {
103
+ throw new Error('file type not allowed: missing extension');
138
104
  }
139
- }
140
- else if (kind === 'document' && this.documentPort) {
141
- const companion = extractCompanionName(uniqueName);
142
- item.extractPath = companion;
143
- try {
144
- const result = await this.documentPort.extract({
145
- data: new Uint8Array(data),
146
- name: uniqueName,
147
- });
148
- const absExtract = join(root, companion);
149
- if (!isPathInside(root, absExtract)) {
150
- throw new Error('invalid extract path');
151
- }
152
- await writeFile(absExtract, result.markdown);
153
- item.status = 'parsed';
154
- item.parse = { ok: true, chars: result.markdown.length };
105
+ const data = Buffer.isBuffer(input.data)
106
+ ? input.data
107
+ : typeof input.data === 'string'
108
+ ? Buffer.from(input.data, 'utf8')
109
+ : Buffer.from(input.data);
110
+ if (data.byteLength > this.limits.maxFileBytes) {
111
+ throw new Error(`file exceeds maxFileBytes (${this.limits.maxFileBytes})`);
112
+ }
113
+ const manifest = this.readManifest(sessionId);
114
+ const live = manifest.items.filter((i) => i.status !== 'promoted');
115
+ if (live.length >= this.limits.maxFiles) {
116
+ throw new Error(`too many attachments (max ${this.limits.maxFiles})`);
117
+ }
118
+ const total = live.reduce((s, i) => s + i.sizeBytes, 0) + data.byteLength;
119
+ if (total > this.limits.maxTotalBytes) {
120
+ throw new Error(`attachments exceed maxTotalBytes (${this.limits.maxTotalBytes})`);
155
121
  }
156
- catch (err) {
157
- item.status = 'parse_failed';
158
- if (isDocumentExtractError(err)) {
159
- item.parse = {
160
- ok: false,
161
- error: `${err.code}${err.requires ? ` (requires: ${err.requires.join(',')})` : ''}`,
162
- };
122
+ const root = this.attachmentRoot(sessionId);
123
+ await mkdir(root, { recursive: true });
124
+ const uniqueName = this.uniqueName(live, name);
125
+ const abs = join(root, uniqueName);
126
+ if (!isPathInside(root, abs)) {
127
+ throw new Error('invalid attachment path');
128
+ }
129
+ await writeFile(abs, data);
130
+ const kind = classifyAttachmentKind(uniqueName);
131
+ const contentHash = createHash('sha256').update(data).digest('hex');
132
+ const item = {
133
+ id: `att_${randomUUID().slice(0, 12)}`,
134
+ name: uniqueName,
135
+ mime: input.mime ?? guessMime(uniqueName),
136
+ sizeBytes: data.byteLength,
137
+ contentHash: `sha256:${contentHash}`,
138
+ path: uniqueName,
139
+ status: 'ready',
140
+ kind,
141
+ createdAt: Date.now(),
142
+ };
143
+ if (isPlainReadable(kind, uniqueName)) {
144
+ item.extractPath = uniqueName;
145
+ const extracted = extractText(data, uniqueName, kind);
146
+ if (extracted) {
147
+ item.status = 'parsed';
148
+ item.parse = { ok: true, chars: extracted.chars };
163
149
  }
164
150
  else {
165
- item.parse = {
166
- ok: false,
167
- error: err instanceof Error ? err.message : String(err),
168
- };
151
+ item.status = 'parse_failed';
152
+ item.parse = { ok: false, error: 'binary content in text extension' };
153
+ }
154
+ }
155
+ else if (kind === 'document' && this.documentPort) {
156
+ const companion = extractCompanionName(uniqueName);
157
+ item.extractPath = companion;
158
+ try {
159
+ const result = await this.documentPort.extract({
160
+ data: new Uint8Array(data),
161
+ name: uniqueName,
162
+ });
163
+ const absExtract = join(root, companion);
164
+ if (!isPathInside(root, absExtract)) {
165
+ throw new Error('invalid extract path');
166
+ }
167
+ await writeFile(absExtract, result.markdown);
168
+ item.status = 'parsed';
169
+ item.parse = { ok: true, chars: result.markdown.length };
170
+ }
171
+ catch (err) {
172
+ item.status = 'parse_failed';
173
+ if (isDocumentExtractError(err)) {
174
+ item.parse = {
175
+ ok: false,
176
+ error: `${err.code}${err.requires ? ` (requires: ${err.requires.join(',')})` : ''}`,
177
+ };
178
+ }
179
+ else {
180
+ item.parse = {
181
+ ok: false,
182
+ error: err instanceof Error ? err.message : String(err),
183
+ };
184
+ }
169
185
  }
170
186
  }
187
+ else if (kind === 'image') {
188
+ item.status = 'ready';
189
+ }
190
+ else if (kind === 'document') {
191
+ item.status = 'ready';
192
+ item.parse = {
193
+ ok: false,
194
+ error: 'document extract disabled (no DocumentPort)',
195
+ };
196
+ }
197
+ else {
198
+ item.status = 'ready';
199
+ item.parse = { ok: false, error: 'no extractor for this type (see OP adapter)' };
200
+ }
201
+ manifest.items.push(item);
202
+ await this.indexSavedAttachment(sessionId, item);
203
+ await this.writeManifest(sessionId, manifest);
204
+ return item;
205
+ });
206
+ }
207
+ /**
208
+ * 上传解析成功后默认建立 Session 私有关键词投影,不注册 Knowledge source。
209
+ * 索引是可重建降级面:失败不影响原件与抽取文本的保存。
210
+ */
211
+ async indexSavedAttachment(sessionId, item) {
212
+ if (!item.extractPath || !item.parse?.ok)
213
+ return;
214
+ const root = this.attachmentRoot(sessionId);
215
+ const rel = item.extractPath;
216
+ const abs = join(root, rel);
217
+ if (!isPathInside(root, abs))
218
+ return;
219
+ try {
220
+ const text = readFileSync(abs, 'utf8');
221
+ await new SessionAttachmentRecallIndex(root).upsert(item, text, item.path);
222
+ const stat = statSync(abs);
223
+ Object.assign(item.parse, {
224
+ extractHash: attachmentExtractHash(item, text),
225
+ extractBytes: stat.size,
226
+ extractMtimeMs: stat.mtimeMs,
227
+ extractCtimeMs: stat.ctimeMs,
228
+ });
171
229
  }
172
- else if (kind === 'image') {
173
- item.status = 'ready';
230
+ catch {
231
+ // 投影失败仅使本轮召回走 structure_tools,不损失附件读取能力。
174
232
  }
175
- else if (kind === 'document') {
176
- item.status = 'ready';
177
- item.parse = {
178
- ok: false,
179
- error: 'document extract disabled (no DocumentPort)',
180
- };
233
+ }
234
+ /**
235
+ * 查询本轮附件的本地关键词召回;索引不可用由调用方回退 structure_tools。
236
+ *
237
+ * @param sessionId - 会话 id
238
+ * @param query - 局部检索焦点
239
+ * @param attachmentIds - 本轮已授权的附件范围
240
+ * @param limit - 全局 top-k
241
+ */
242
+ async recall(sessionId, query, attachmentIds, limit) {
243
+ const attachments = attachmentIds
244
+ .map((id) => this.get(sessionId, id))
245
+ .filter((a) => a != null && a.status !== 'promoted');
246
+ try {
247
+ return await new SessionAttachmentRecallIndex(this.attachmentRoot(sessionId))
248
+ .search(query, attachments, limit);
181
249
  }
182
- else {
183
- item.status = 'ready';
184
- item.parse = { ok: false, error: 'no extractor for this type (see OP adapter)' };
250
+ catch {
251
+ // 缺失/损坏/陈旧索引:与零命中区分,统一由注入层回退 structure_tools。
252
+ return null;
185
253
  }
186
- manifest.items.push(item);
187
- await this.writeManifest(sessionId, manifest);
188
- return item;
254
+ }
255
+ /**
256
+ * 从 manifest + 完整抽取文本重建本地投影;全部读取成功后才替换旧投影。
257
+ * 普通发送不调用此重路径,索引不可用时仍按 structure_tools 降级。
258
+ *
259
+ * @param sessionId - 会话 id
260
+ */
261
+ async rebuildRecall(sessionId) {
262
+ return serializeSessionWrite(sessionId, async () => {
263
+ const manifest = this.readManifest(sessionId);
264
+ const items = manifest.items
265
+ .filter((a) => a.status !== 'promoted' && a.extractPath && a.parse?.ok)
266
+ .map((attachment) => {
267
+ const text = this.readExtractedText(sessionId, attachment.id);
268
+ const stat = statSync(join(this.attachmentRoot(sessionId), attachment.extractPath));
269
+ return { attachment, text, stat, sourcePath: attachment.path };
270
+ });
271
+ if (items.some((item) => item.text == null)) {
272
+ throw new Error('attachment extract unavailable; recall index was not replaced');
273
+ }
274
+ await new SessionAttachmentRecallIndex(this.attachmentRoot(sessionId)).rebuild(items.map((item) => ({ ...item, text: item.text })));
275
+ for (const { attachment, text, stat } of items) {
276
+ Object.assign(attachment.parse, {
277
+ extractHash: attachmentExtractHash(attachment, text),
278
+ extractBytes: stat.size,
279
+ extractMtimeMs: stat.mtimeMs,
280
+ extractCtimeMs: stat.ctimeMs,
281
+ });
282
+ }
283
+ await this.writeManifest(sessionId, manifest);
284
+ });
189
285
  }
190
286
  /**
191
287
  * 删除附件(原件 + 伴生 + manifest 条目)
@@ -194,29 +290,37 @@ export class SessionAttachmentService {
194
290
  * @param attachmentId - 附件 id
195
291
  */
196
292
  async delete(sessionId, attachmentId) {
197
- const manifest = this.readManifest(sessionId);
198
- const idx = manifest.items.findIndex((i) => i.id === attachmentId);
199
- if (idx < 0)
200
- return false;
201
- const item = manifest.items[idx];
202
- if (item.status === 'promoted') {
203
- throw new Error('attachment already promoted; delete from project source');
204
- }
205
- const root = this.attachmentRoot(sessionId);
206
- const absFile = join(root, item.path);
207
- if (!isPathInside(root, absFile)) {
208
- throw new Error('invalid attachment path in manifest');
209
- }
210
- await safeUnlink(absFile);
211
- if (item.extractPath && item.extractPath !== item.path) {
212
- const absExtract = join(root, item.extractPath);
213
- if (isPathInside(root, absExtract)) {
214
- await safeUnlink(absExtract);
293
+ return serializeSessionWrite(sessionId, async () => {
294
+ const manifest = this.readManifest(sessionId);
295
+ const idx = manifest.items.findIndex((i) => i.id === attachmentId);
296
+ if (idx < 0)
297
+ return false;
298
+ const item = manifest.items[idx];
299
+ if (item.status === 'promoted') {
300
+ throw new Error('attachment already promoted; delete from project source');
215
301
  }
216
- }
217
- manifest.items.splice(idx, 1);
218
- await this.writeManifest(sessionId, manifest);
219
- return true;
302
+ const root = this.attachmentRoot(sessionId);
303
+ const absFile = join(root, item.path);
304
+ if (!isPathInside(root, absFile)) {
305
+ throw new Error('invalid attachment path in manifest');
306
+ }
307
+ await safeUnlink(absFile);
308
+ if (item.extractPath && item.extractPath !== item.path) {
309
+ const absExtract = join(root, item.extractPath);
310
+ if (isPathInside(root, absExtract)) {
311
+ await safeUnlink(absExtract);
312
+ }
313
+ }
314
+ manifest.items.splice(idx, 1);
315
+ try {
316
+ await new SessionAttachmentRecallIndex(root).remove(attachmentId);
317
+ }
318
+ catch {
319
+ // 索引缺失/损坏时已不可召回;原件与登记删除仍须完成。
320
+ }
321
+ await this.writeManifest(sessionId, manifest);
322
+ return true;
323
+ });
220
324
  }
221
325
  /**
222
326
  * 会话删除 / 归档清理:移除整个附件目录
@@ -224,8 +328,10 @@ export class SessionAttachmentService {
224
328
  * @param sessionId - 会话 id
225
329
  */
226
330
  async deleteAll(sessionId) {
227
- const root = this.attachmentRoot(sessionId);
228
- await rm(root, { recursive: true, force: true });
331
+ return serializeSessionWrite(sessionId, async () => {
332
+ const root = this.attachmentRoot(sessionId);
333
+ await rm(root, { recursive: true, force: true });
334
+ });
229
335
  }
230
336
  /**
231
337
  * 标记已绑定可检索 source
@@ -235,13 +341,15 @@ export class SessionAttachmentService {
235
341
  * @param sourceId - Knowledge source id
236
342
  */
237
343
  async markSearchable(sessionId, attachmentId, sourceId) {
238
- const manifest = this.readManifest(sessionId);
239
- const item = manifest.items.find((i) => i.id === attachmentId);
240
- if (!item)
241
- throw new Error(`attachment not found: ${attachmentId}`);
242
- item.searchableSourceId = sourceId;
243
- await this.writeManifest(sessionId, manifest);
244
- return item;
344
+ return serializeSessionWrite(sessionId, async () => {
345
+ const manifest = this.readManifest(sessionId);
346
+ const item = manifest.items.find((i) => i.id === attachmentId);
347
+ if (!item)
348
+ throw new Error(`attachment not found: ${attachmentId}`);
349
+ item.searchableSourceId = sourceId;
350
+ await this.writeManifest(sessionId, manifest);
351
+ return item;
352
+ });
245
353
  }
246
354
  /**
247
355
  * 标记已归入项目(文件移出后调用)
@@ -251,14 +359,22 @@ export class SessionAttachmentService {
251
359
  * @param info - 项目信息
252
360
  */
253
361
  async markPromoted(sessionId, attachmentId, info) {
254
- const manifest = this.readManifest(sessionId);
255
- const item = manifest.items.find((i) => i.id === attachmentId);
256
- if (!item)
257
- throw new Error(`attachment not found: ${attachmentId}`);
258
- item.status = 'promoted';
259
- item.promoted = { ...info, at: Date.now() };
260
- await this.writeManifest(sessionId, manifest);
261
- return item;
362
+ return serializeSessionWrite(sessionId, async () => {
363
+ const manifest = this.readManifest(sessionId);
364
+ const item = manifest.items.find((i) => i.id === attachmentId);
365
+ if (!item)
366
+ throw new Error(`attachment not found: ${attachmentId}`);
367
+ item.status = 'promoted';
368
+ item.promoted = { ...info, at: Date.now() };
369
+ try {
370
+ await new SessionAttachmentRecallIndex(this.attachmentRoot(sessionId)).remove(attachmentId);
371
+ }
372
+ catch {
373
+ // 可重建投影清理失败不阻断权威 promote 状态迁移。
374
+ }
375
+ await this.writeManifest(sessionId, manifest);
376
+ return item;
377
+ });
262
378
  }
263
379
  /**
264
380
  * 绝对路径(工具 / promote 用)
@@ -320,14 +436,17 @@ export class SessionAttachmentService {
320
436
  const parsed = JSON.parse(raw);
321
437
  return { sessionId, version: 1, items: parsed.items ?? [] };
322
438
  }
323
- catch {
324
- return { sessionId, version: 1, items: [] };
439
+ catch (err) {
440
+ if (err.code === 'ENOENT') {
441
+ return { sessionId, version: 1, items: [] };
442
+ }
443
+ throw err;
325
444
  }
326
445
  }
327
446
  async writeManifest(sessionId, manifest) {
328
447
  const { root, manifestPath } = resolveSessionAttachmentsPaths(this.sessionsDir, sessionId);
329
448
  await mkdir(root, { recursive: true });
330
- const tmp = `${manifestPath}.${process.pid}.tmp`;
449
+ const tmp = `${manifestPath}.${process.pid}.${randomUUID()}.tmp`;
331
450
  await writeFile(tmp, JSON.stringify(manifest, null, 2));
332
451
  await rename(tmp, manifestPath);
333
452
  }
@@ -9,6 +9,12 @@ export interface AttachmentParseInfo {
9
9
  ok: boolean;
10
10
  chars?: number;
11
11
  error?: string;
12
+ /** sha256(originalHash + NUL + fullExtractText),由解析/索引构建写入 */
13
+ extractHash?: string;
14
+ /** 抽取文件建索引时的大小与 mtime/ctime;代次变化才重读全文验 hash */
15
+ extractBytes?: number;
16
+ extractMtimeMs?: number;
17
+ extractCtimeMs?: number;
12
18
  }
13
19
  /** 单条会话附件(manifest 条目) */
14
20
  export interface SessionAttachment {
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Transform record store — durable ledger for compaction products.
3
+ *
4
+ * Layout (same base as turn-undo, sibling of `undo/` and `attachments/`):
5
+ *
6
+ * ```
7
+ * sessions/<sid>/transform/
8
+ * <agent-file>.jsonl # append-only entries: {kind:'record'|'revoke', ...}
9
+ * blobs/<sha256> # content-addressed replacement texts
10
+ * ```
11
+ *
12
+ * Durability contract: blobs are written (atomic tmp+rename, skip-if-exists)
13
+ * **before** their record line is appended — a line is never readable without
14
+ * its blob. Revocations are append-only lines; the ledger folds them at load.
15
+ * Appends are serialized per (sessionId, agentId) inside the store (review F5:
16
+ * seq assignment must not race), and load returns records sorted by seq.
17
+ *
18
+ * ⚠️ This must NOT live under `sessions/<sid>/undo/` — that directory is
19
+ * deleted wholesale on turn-undo commit/discard.
20
+ *
21
+ * @module harness/session/transform-store
22
+ */
23
+ import type { NewTransformRecord, TransformLedger, TransformRecord, TransformStore } from '../context/transform/types.js';
24
+ /** transform 目录布局 */
25
+ export interface SessionTransformPaths {
26
+ /** `sessions/<sid>/transform` */
27
+ root: string;
28
+ blobsDir: string;
29
+ }
30
+ /**
31
+ * 解析会话 transform 目录
32
+ *
33
+ * @param sessionsDir - 通常 `OCTOPI_HOME/sessions`
34
+ * @param sessionId - 会话 id
35
+ * @returns 路径
36
+ */
37
+ export declare function resolveSessionTransformPaths(sessionsDir: string, sessionId: string): SessionTransformPaths;
38
+ /**
39
+ * 复制会话 transform 账本(session fork 用)。
40
+ *
41
+ * 源缺失/复制失败返回 false——调用方降级路径是旧快照迁移(拷贝的 legacy 快照在
42
+ * 目标端一次性转换),不是静默成功。
43
+ *
44
+ * @param sessionsDir - `OCTOPI_HOME/sessions`
45
+ * @param fromSessionId - 源会话
46
+ * @param toSessionId - 目标会话
47
+ * @returns 是否完整复制
48
+ */
49
+ export declare function copySessionTransformDir(sessionsDir: string, fromSessionId: string, toSessionId: string): Promise<boolean>;
50
+ /**
51
+ * 删除会话 transform 账本(会话删除清理;摘要正文含用户内容,不得遗留)。
52
+ *
53
+ * @param sessionsDir - `OCTOPI_HOME/sessions`
54
+ * @param sessionId - 会话 id
55
+ * @returns void
56
+ */
57
+ export declare function removeSessionTransformDir(sessionsDir: string, sessionId: string): Promise<void>;
58
+ /** transform 孤儿目录(会话已删除/不在,账本残留) */
59
+ export interface OrphanTransformDir {
60
+ sessionDirName: string;
61
+ transformRoot: string;
62
+ ledgerFiles: number;
63
+ blobFiles: number;
64
+ }
65
+ /**
66
+ * 扫描 transform 孤儿目录(doctor 兜底)。
67
+ *
68
+ * 与 undo 不同:transform 账本**设计上常驻**(记录是持久事实),孤儿判据是
69
+ * 「会话 jsonl 已不存在而 transform/ 仍在」(删除清理之外的残留)。
70
+ *
71
+ * @param sessionsDir - `OCTOPI_HOME/sessions`
72
+ * @returns 孤儿列表
73
+ */
74
+ export declare function scanOrphanSessionTransform(sessionsDir: string): Promise<OrphanTransformDir[]>;
75
+ /**
76
+ * JSONL file-backed transform store (durable).
77
+ */
78
+ export declare class JsonlTransformStore implements TransformStore {
79
+ private readonly sessionsDir;
80
+ /** per (sessionId, agentId) append chain(F5:seq 分配互斥) */
81
+ private readonly appendChains;
82
+ /**
83
+ * @param options - sessionsDir (`OCTOPI_HOME/sessions`)
84
+ */
85
+ constructor(options: {
86
+ sessionsDir: string;
87
+ });
88
+ /**
89
+ * Load the ledger for (sessionId, agentId), blobs hydrated into `text`,
90
+ * records sorted by seq(fold 的 later-seq-wins 依赖序)。
91
+ *
92
+ * @param sessionId - session id
93
+ * @param agentId - agent id
94
+ * @returns ledger (empty when none)
95
+ */
96
+ load(sessionId: string, agentId: string): Promise<TransformLedger>;
97
+ /**
98
+ * Durably append records and/or revocations (serialized per key — seq safe).
99
+ *
100
+ * @param sessionId - session id
101
+ * @param agentId - agent id
102
+ * @param records - new records (seq assigned here)
103
+ * @param revokeSeqs - seqs to revoke
104
+ * @returns appended records with seq assigned
105
+ */
106
+ append(sessionId: string, agentId: string, records: NewTransformRecord[], revokeSeqs?: number[]): Promise<TransformRecord[]>;
107
+ private appendInternal;
108
+ }
109
+ /**
110
+ * In-memory transform store (standalone engines / tests). Same append semantics,
111
+ * no durability — permanence holds across assemblies within the process only.
112
+ * First append logs a one-time durability warning (review F4: degradation must
113
+ * not be silent).
114
+ */
115
+ export declare class InMemoryTransformStore implements TransformStore {
116
+ private readonly ledgers;
117
+ private key;
118
+ /**
119
+ * Load the ledger for (sessionId, agentId).
120
+ *
121
+ * @param sessionId - session id
122
+ * @param agentId - agent id
123
+ * @returns ledger
124
+ */
125
+ load(sessionId: string, agentId: string): Promise<TransformLedger>;
126
+ /**
127
+ * Append records and/or revocations in memory.
128
+ *
129
+ * @param sessionId - session id
130
+ * @param agentId - agent id
131
+ * @param records - new records
132
+ * @param revokeSeqs - seqs to revoke
133
+ * @returns appended records
134
+ */
135
+ append(sessionId: string, agentId: string, records: NewTransformRecord[], revokeSeqs?: number[]): Promise<TransformRecord[]>;
136
+ }