@octopi-agent/engine 0.98.4 → 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 (301) hide show
  1. package/dist/config-schema/agent.d.ts +35 -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 +57 -160
  6. package/dist/config-schema/engine.js +1 -5
  7. package/dist/config-schema/governance.d.ts +8 -1
  8. package/dist/config-schema/governance.js +8 -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 +24 -3
  25. package/dist/harness/agent/builder.js +131 -27
  26. package/dist/harness/agent/config-bridge.js +9 -2
  27. package/dist/harness/agent/config-integrity.js +19 -2
  28. package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
  29. package/dist/harness/agent/wire-agent-builder.js +26 -7
  30. package/dist/harness/capabilities/document/factory.d.ts +5 -0
  31. package/dist/harness/capabilities/document/factory.js +1 -0
  32. package/dist/harness/capabilities/document/port.js +6 -3
  33. package/dist/harness/capabilities/document/types.d.ts +5 -0
  34. package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -1
  35. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
  36. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +2 -2
  37. package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
  38. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
  39. package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
  40. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
  41. package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
  42. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
  43. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +3 -3
  44. package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
  45. package/dist/harness/collaboration/delegation/child-run.js +4 -4
  46. package/dist/harness/collaboration/delegation/index.d.ts +1 -1
  47. package/dist/harness/collaboration/delegation/index.js +1 -1
  48. package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
  49. package/dist/harness/collaboration/delegation/notifier.js +8 -1
  50. package/dist/harness/collaboration/delegation/service.d.ts +2 -0
  51. package/dist/harness/collaboration/delegation/service.js +2 -1
  52. package/dist/harness/collaboration/delegation/store.d.ts +2 -0
  53. package/dist/harness/collaboration/delegation/store.js +2 -1
  54. package/dist/harness/collaboration/delegation/types.d.ts +23 -2
  55. package/dist/harness/collaboration/delegation/types.js +22 -0
  56. package/dist/harness/collaboration/delegation/wiring.js +11 -1
  57. package/dist/harness/context/budget-allocator.d.ts +26 -18
  58. package/dist/harness/context/budget-allocator.js +67 -32
  59. package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
  60. package/dist/harness/context/capabilities/compact/engine.js +169 -121
  61. package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
  62. package/dist/harness/context/capabilities/compact/handover.js +7 -5
  63. package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
  64. package/dist/harness/context/capabilities/compact/index.js +4 -0
  65. package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
  66. package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
  67. package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
  68. package/dist/harness/context/capabilities/compact/messages.js +91 -0
  69. package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
  70. package/dist/harness/context/capabilities/compact/types.js +11 -1
  71. package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
  72. package/dist/harness/context/capabilities/compact/view-split.js +72 -0
  73. package/dist/harness/context/capabilities/summary/port.js +0 -1
  74. package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
  75. package/dist/harness/context/capabilities/summary/resolver.js +1 -6
  76. package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
  77. package/dist/harness/context/capabilities/summary/types.d.ts +3 -6
  78. package/dist/harness/context/context-size-ledger.d.ts +143 -0
  79. package/dist/harness/context/context-size-ledger.js +236 -0
  80. package/dist/harness/context/default-context-engine.d.ts +195 -119
  81. package/dist/harness/context/default-context-engine.js +1241 -743
  82. package/dist/harness/context/index.d.ts +2 -2
  83. package/dist/harness/context/index.js +1 -1
  84. package/dist/harness/context/layer-types.d.ts +15 -0
  85. package/dist/harness/context/layer-types.js +14 -1
  86. package/dist/harness/context/layers.d.ts +14 -15
  87. package/dist/harness/context/layers.js +41 -11
  88. package/dist/harness/context/message-selector.d.ts +10 -8
  89. package/dist/harness/context/message-selector.js +49 -27
  90. package/dist/harness/context/summarize.d.ts +2 -2
  91. package/dist/harness/context/summarize.js +9 -2
  92. package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
  93. package/dist/harness/context/system-prompt-assembler.js +2 -1
  94. package/dist/harness/context/token-constants.d.ts +8 -6
  95. package/dist/harness/context/token-constants.js +8 -7
  96. package/dist/harness/context/token-estimate-fns.d.ts +37 -27
  97. package/dist/harness/context/token-estimate-fns.js +85 -66
  98. package/dist/harness/context/token-estimator.d.ts +27 -12
  99. package/dist/harness/context/token-estimator.js +120 -66
  100. package/dist/harness/context/token-segments.d.ts +88 -0
  101. package/dist/harness/context/token-segments.js +103 -0
  102. package/dist/harness/context/tool-result-aging.d.ts +6 -1
  103. package/dist/harness/context/tool-result-aging.js +16 -5
  104. package/dist/harness/context/tool-result-body.js +2 -0
  105. package/dist/harness/context/transform/anchors.d.ts +66 -0
  106. package/dist/harness/context/transform/anchors.js +125 -0
  107. package/dist/harness/context/transform/fold.d.ts +56 -0
  108. package/dist/harness/context/transform/fold.js +135 -0
  109. package/dist/harness/context/transform/migrate.d.ts +41 -0
  110. package/dist/harness/context/transform/migrate.js +69 -0
  111. package/dist/harness/context/transform/types.d.ts +129 -0
  112. package/dist/harness/context/transform/types.js +19 -0
  113. package/dist/harness/context/turn-envelope.d.ts +6 -3
  114. package/dist/harness/context/types.d.ts +127 -117
  115. package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
  116. package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
  117. package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
  118. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
  119. package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
  120. package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
  121. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
  122. package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
  123. package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
  124. package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
  125. package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
  126. package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
  127. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
  128. package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
  129. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
  130. package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
  131. package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
  132. package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
  133. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
  134. package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
  135. package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
  136. package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
  137. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
  138. package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
  139. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
  140. package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
  141. package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
  142. package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
  143. package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
  144. package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
  145. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
  146. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
  147. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
  148. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
  149. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
  150. package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
  151. package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
  152. package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
  153. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
  154. package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
  155. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
  156. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
  157. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
  158. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
  159. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
  160. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
  161. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
  162. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
  163. package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
  164. package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
  165. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
  166. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
  167. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
  168. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
  169. package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
  170. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
  171. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
  172. package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
  173. package/dist/harness/governance/accounting/usage-ledger.js +23 -1
  174. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
  175. package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
  176. package/dist/harness/governance/security/capability-enforcer.js +1 -2
  177. package/dist/harness/index.d.ts +12 -12
  178. package/dist/harness/index.js +7 -7
  179. package/dist/harness/knowledge/boot-config.d.ts +55 -0
  180. package/dist/harness/knowledge/boot-config.js +50 -0
  181. package/dist/harness/knowledge/catalog-types.d.ts +2 -0
  182. package/dist/harness/knowledge/client.d.ts +24 -2
  183. package/dist/harness/knowledge/client.js +19 -5
  184. package/dist/harness/knowledge/db.js +5 -0
  185. package/dist/harness/knowledge/describe-sample.d.ts +23 -0
  186. package/dist/harness/knowledge/describe-sample.js +58 -0
  187. package/dist/harness/knowledge/describe.d.ts +8 -0
  188. package/dist/harness/knowledge/describe.js +18 -2
  189. package/dist/harness/knowledge/engine-thread.js +6 -0
  190. package/dist/harness/knowledge/grounding.js +3 -1
  191. package/dist/harness/knowledge/http-app.js +35 -4
  192. package/dist/harness/knowledge/http-params.d.ts +18 -0
  193. package/dist/harness/knowledge/http-params.js +24 -0
  194. package/dist/harness/knowledge/index.d.ts +2 -0
  195. package/dist/harness/knowledge/index.js +1 -0
  196. package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
  197. package/dist/harness/knowledge/purge.js +5 -2
  198. package/dist/harness/knowledge/query-service.d.ts +13 -2
  199. package/dist/harness/knowledge/query-service.js +4 -2
  200. package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
  201. package/dist/harness/knowledge/query-worker-client.js +4 -2
  202. package/dist/harness/knowledge/query-worker.js +4 -2
  203. package/dist/harness/knowledge/read-http.js +5 -1
  204. package/dist/harness/knowledge/serve.d.ts +8 -7
  205. package/dist/harness/knowledge/serve.js +9 -0
  206. package/dist/harness/knowledge/source-store.js +26 -3
  207. package/dist/harness/knowledge/start-service-process.d.ts +15 -7
  208. package/dist/harness/knowledge/start-service-process.js +21 -9
  209. package/dist/harness/knowledge/types.d.ts +7 -0
  210. package/dist/harness/knowledge/writer-service.d.ts +37 -9
  211. package/dist/harness/knowledge/writer-service.js +120 -14
  212. package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
  213. package/dist/harness/knowledge/writer-worker-client.js +20 -2
  214. package/dist/harness/knowledge/writer-worker.js +9 -1
  215. package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
  216. package/dist/harness/memory/types.d.ts +6 -4
  217. package/dist/harness/memory/wisdom-formation.d.ts +14 -3
  218. package/dist/harness/memory/wisdom-formation.js +85 -22
  219. package/dist/harness/memory/wisdom-gates.d.ts +14 -0
  220. package/dist/harness/memory/wisdom-gates.js +59 -19
  221. package/dist/harness/memory/wisdom.js +9 -0
  222. package/dist/harness/observability/observer/hub.js +25 -15
  223. package/dist/harness/observability/observer/types.d.ts +10 -6
  224. package/dist/harness/run/agent/agent.d.ts +40 -21
  225. package/dist/harness/run/agent/agent.js +66 -13
  226. package/dist/harness/run/agent/index.d.ts +1 -1
  227. package/dist/harness/run/budget/budget.d.ts +28 -10
  228. package/dist/harness/run/budget/budget.js +38 -15
  229. package/dist/harness/run/model/index.d.ts +3 -1
  230. package/dist/harness/run/model/index.js +2 -1
  231. package/dist/harness/run/model/resolver.d.ts +4 -1
  232. package/dist/harness/run/model/resolver.js +36 -2
  233. package/dist/harness/run/model/run-scope.d.ts +2 -0
  234. package/dist/harness/run/model/run-scope.js +7 -0
  235. package/dist/harness/run/model/types.d.ts +22 -5
  236. package/dist/harness/run/model/types.js +3 -2
  237. package/dist/harness/run/model/window-truth.d.ts +37 -0
  238. package/dist/harness/run/model/window-truth.js +39 -0
  239. package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
  240. package/dist/harness/run/reliability/context-length-feedback.js +128 -0
  241. package/dist/harness/run/reliability/harness-events.d.ts +3 -3
  242. package/dist/harness/run/reliability/model-error-policy.js +4 -0
  243. package/dist/harness/run/reliability/run-agent.d.ts +10 -4
  244. package/dist/harness/run/reliability/run-agent.js +137 -53
  245. package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
  246. package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
  247. package/dist/harness/run/run-guard/default-run-guard.js +8 -8
  248. package/dist/harness/run/run-scope.d.ts +37 -4
  249. package/dist/harness/run/runner.d.ts +44 -29
  250. package/dist/harness/run/runner.js +320 -102
  251. package/dist/harness/session/attachments/index.d.ts +1 -0
  252. package/dist/harness/session/attachments/index.js +1 -0
  253. package/dist/harness/session/attachments/inject.d.ts +21 -10
  254. package/dist/harness/session/attachments/inject.js +76 -24
  255. package/dist/harness/session/attachments/recall-index.d.ts +70 -0
  256. package/dist/harness/session/attachments/recall-index.js +219 -0
  257. package/dist/harness/session/attachments/service.d.ts +21 -0
  258. package/dist/harness/session/attachments/service.js +258 -139
  259. package/dist/harness/session/attachments/types.d.ts +6 -0
  260. package/dist/harness/session/transform-store.d.ts +136 -0
  261. package/dist/harness/session/transform-store.js +302 -0
  262. package/dist/harness/session/types.d.ts +2 -2
  263. package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
  264. package/dist/harness/shared/events/agent-event-map.js +3 -2
  265. package/dist/harness/shared/events/scenario-events.d.ts +6 -6
  266. package/dist/harness/shared/types/agent-definition.d.ts +1 -2
  267. package/dist/index.d.ts +14 -17
  268. package/dist/index.js +7 -9
  269. package/dist/integration/observability/metrics.d.ts +6 -6
  270. package/dist/integration/observability/metrics.js +13 -13
  271. package/dist/integration/observability/observer-bridge.js +2 -2
  272. package/dist/integration/observability/trace-collector.d.ts +5 -5
  273. package/dist/integration/observability/trace-collector.js +34 -35
  274. package/dist/integration/observability/trace-events.d.ts +3 -3
  275. package/dist/integration/observability/trace-events.js +3 -3
  276. package/dist/integration/providers/anthropic.js +14 -1
  277. package/dist/integration/providers/openai.js +7 -1
  278. package/dist/integration/providers/usage.d.ts +1 -1
  279. package/dist/integration/providers/wire-dump.d.ts +1 -1
  280. package/dist/integration/storage/archive-manager.d.ts +6 -0
  281. package/dist/integration/storage/archive-manager.js +10 -0
  282. package/dist/integration/storage/jsonl.d.ts +1 -1
  283. package/dist/integration/storage/jsonl.js +18 -16
  284. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
  285. package/dist/subsystems/wisdom-steward/formation/config.yaml +1 -0
  286. package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
  287. package/package.json +11 -14
  288. package/dist/harness/context/hybrid-compressor.d.ts +0 -41
  289. package/dist/harness/context/hybrid-compressor.js +0 -159
  290. package/dist/harness/context/llm-summarizer.d.ts +0 -46
  291. package/dist/harness/context/llm-summarizer.js +0 -249
  292. package/dist/harness/context/smart-router.d.ts +0 -75
  293. package/dist/harness/context/smart-router.js +0 -118
  294. package/dist/harness/context/truncate-compressor.d.ts +0 -28
  295. package/dist/harness/context/truncate-compressor.js +0 -107
  296. package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
  297. package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
  298. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
  299. package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
  300. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
  301. package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Transform records — persistent compaction products.
3
+ *
4
+ * Model (arch/context-size-accounting.md §10.18「持久转换记录」拍板):
5
+ * a compaction product is a **fact**, not a temporary view. Once a record is
6
+ * appended it is permanently effective; the original text only returns to the
7
+ * view on an explicit revocation entry. Assembly = deterministic application
8
+ * of effective records over the append-only original messages (fold).
9
+ *
10
+ * - Per-agent ledger: records are keyed (sessionId, agentId) (E4 shape); agents
11
+ * never see each other's compaction views.
12
+ * - Coordinates are message content anchors (hash + occurrence), never array
13
+ * indices — indices survive neither fork/copy nor re-indexing.
14
+ * - `type` is honest: `summary` only for fresh semantic summaries (the fresh
15
+ * gate's sole remaining job); mechanical products are `degrade`.
16
+ *
17
+ * @module harness/context/transform/types
18
+ */
19
+ /**
20
+ * Stable coordinate of one original message.
21
+ *
22
+ * `hash` is the canonical identity hash of the persisted message; `occurrence`
23
+ * disambiguates byte-identical duplicates in stream order; `indexHint` is the
24
+ * raw index at creation time (fast path only — never authoritative).
25
+ */
26
+ export interface MessageAnchor {
27
+ /** sha256 hex of the canonical message identity */
28
+ hash: string;
29
+ /** 0-based occurrence of this hash in the message stream at creation */
30
+ occurrence: number;
31
+ /** raw index at creation (resolution fast path) */
32
+ indexHint: number;
33
+ }
34
+ /** One covered run: inclusive original-message range `[from, to]`. */
35
+ export interface TransformRun {
36
+ from: MessageAnchor;
37
+ to: MessageAnchor;
38
+ }
39
+ export type TransformRecordType = 'summary' | 'degrade';
40
+ /** Rendering shape of the replacement placeholder message. */
41
+ export interface TransformPlaceholder {
42
+ role: 'user' | 'system' | 'assistant';
43
+ /** Message.metadata.source marker (e.g. 'contextSummary' / 'contextLedger') */
44
+ source?: string;
45
+ }
46
+ /**
47
+ * One compaction product. Created only by compaction paths (proactive /
48
+ * overflow / manual); appended durably before the compacted view is returned.
49
+ *
50
+ * `covers` may be empty: a pure growth-gate anchor (a completed compaction
51
+ * round that produced no durable coverage — legacy migrate / counters-only).
52
+ */
53
+ export interface TransformRecord {
54
+ /** per-(sessionId, agentId) monotonic sequence, assigned by the store */
55
+ seq: number;
56
+ sessionId: string;
57
+ agentId: string;
58
+ type: TransformRecordType;
59
+ createdAt: number;
60
+ /** covered original-message runs (inclusive; usually exactly one run) */
61
+ covers: TransformRun[];
62
+ /** content-addressed replacement text ref (`sha256:<hex>`); undefined iff covers is empty */
63
+ blobRef?: string;
64
+ /** replacement text (hydrated at load / consumed at append; persisted via blobRef) */
65
+ text?: string;
66
+ /** replacement message shape (text comes from the blob) */
67
+ placeholder: TransformPlaceholder;
68
+ /** appended revocation entry flipped this flag at load (append-only ledger) */
69
+ revoked: boolean;
70
+ meta: TransformRecordMeta;
71
+ }
72
+ export interface TransformRecordMeta {
73
+ reason: 'proactive' | 'overflow' | 'manual';
74
+ /** fresh semantic summary at creation (record type gate) */
75
+ fresh: boolean;
76
+ /** a summarize LLM call was actually issued (success or failure) */
77
+ summarizeAttempted: boolean;
78
+ /** messages.length at creation (growth-gate base) */
79
+ messageCount: number;
80
+ /** raw-history token estimate at creation — 仅诊断口径(有多段历史时远大于实际请求)
81
+ * :**不作增长门基数**(2026-11-07 起,改用 viewTokens) */
82
+ fullTokens?: number;
83
+ /** post-compaction view token estimate = 实际请求口径(fold + 老化);单位 raw(M-3) */
84
+ viewTokens?: number;
85
+ /** viewTokens 的计量口径版本:缺省 = 旧口径(fold 视图未老化、且非请求形状)。
86
+ * 增长门只认 'request-raw'(请求形状 + raw 单位);'request' 是历史存量(校准单位、
87
+ * 缺写入时 ratio 无法换算)只读不写,与更旧记录一律视为无基数(允许一次压缩自愈),
88
+ * 否则两种口径/单位互比会永久压制压缩。 */
89
+ viewTokensSource?: 'request' | 'request-raw';
90
+ }
91
+ /** Record as handed to the store (seq assigned by the store; text goes to a blob). */
92
+ export type NewTransformRecord = Omit<TransformRecord, 'seq' | 'blobRef' | 'revoked'>;
93
+ export interface TransformLedger {
94
+ /** ordered by seq;`revoked` 已折叠 */
95
+ records: TransformRecord[];
96
+ /**
97
+ * 账本文件曾有任何条目(含损坏行 / blob 丢失被丢弃的)。
98
+ * 迁移幂等门用它而不是 records.length——「行在 blob 全丢」不得被当成空账本
99
+ * 而重放旧快照迁移(评审 F7)。
100
+ */
101
+ hadEntries?: boolean;
102
+ }
103
+ /**
104
+ * Persistence port for transform records.
105
+ *
106
+ * Appends are durable-before-return: a compaction product must hit the store
107
+ * before the compacted view is sent (otherwise a crash refills the raw text —
108
+ * exactly the defect this model exists to remove).
109
+ */
110
+ export interface TransformStore {
111
+ /**
112
+ * Load the ledger for (sessionId, agentId).
113
+ *
114
+ * @param sessionId - session id
115
+ * @param agentId - agent id ("" for legacy single-agent)
116
+ * @returns ledger (empty when none)
117
+ */
118
+ load(sessionId: string, agentId: string): Promise<TransformLedger>;
119
+ /**
120
+ * Durably append records (and optional revocations).
121
+ *
122
+ * @param sessionId - session id
123
+ * @param agentId - agent id
124
+ * @param records - new records (seq assigned by the store)
125
+ * @param revokeSeqs - seqs of existing records to revoke (explicit revocation)
126
+ * @returns the appended records with seq assigned
127
+ */
128
+ append(sessionId: string, agentId: string, records: NewTransformRecord[], revokeSeqs?: number[]): Promise<TransformRecord[]>;
129
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Transform records — persistent compaction products.
3
+ *
4
+ * Model (arch/context-size-accounting.md §10.18「持久转换记录」拍板):
5
+ * a compaction product is a **fact**, not a temporary view. Once a record is
6
+ * appended it is permanently effective; the original text only returns to the
7
+ * view on an explicit revocation entry. Assembly = deterministic application
8
+ * of effective records over the append-only original messages (fold).
9
+ *
10
+ * - Per-agent ledger: records are keyed (sessionId, agentId) (E4 shape); agents
11
+ * never see each other's compaction views.
12
+ * - Coordinates are message content anchors (hash + occurrence), never array
13
+ * indices — indices survive neither fork/copy nor re-indexing.
14
+ * - `type` is honest: `summary` only for fresh semantic summaries (the fresh
15
+ * gate's sole remaining job); mechanical products are `degrade`.
16
+ *
17
+ * @module harness/context/transform/types
18
+ */
19
+ export {};
@@ -10,10 +10,12 @@
10
10
  * 定形后字节冻结。正文经 XML 转义嵌入,用户原文不得截断信封。
11
11
  */
12
12
  import type { Message } from '@octopi-agent/core/types.js';
13
+ import type { LLMMessage } from '@octopi-agent/core/interfaces/model-provider.js';
14
+ type EnvelopeContent = Message['content'] | LLMMessage['content'];
13
15
  /** turn_start 元素的 id 形态(会话内单调 t1,t2,…) */
14
16
  export declare function formatTurnId(seq: number): string;
15
17
  /** 归一化 Message.content → 纯文本(多模态取 text 块拼接;空 content → '') */
16
- export declare function messageText(content: Message['content'] | undefined | null): string;
18
+ export declare function messageText(content: EnvelopeContent | undefined): string;
17
19
  /** user 原文嵌入 XML 前的最小转义(防伪影标签截断信封) */
18
20
  export declare function escapeUserMessageText(text: string): string;
19
21
  /** 解转义(extractUserMessageText 出口) */
@@ -44,7 +46,7 @@ export declare function formatTurnContextXml(params: {
44
46
  * 非 turn_start 正文原样返回。
45
47
  * 取**最后一个** user_message 块(boilerplate 禁止再写该标签字面量)。
46
48
  */
47
- export declare function extractUserMessageText(content: string | Message['content'] | undefined | null): string;
49
+ export declare function extractUserMessageText(content: EnvelopeContent | undefined): string;
48
50
  /**
49
51
  * 剥掉 `<turn_context>…</turn_context>`(摘要语义输入 / UI)。
50
52
  * 保留 `<user_message>` 与 turn_start/turn_end 骨架(或在 UI 场景配合 extractUserMessageText)。
@@ -109,7 +111,7 @@ export declare function escapeSlotBody(tag: string, body: string): string;
109
111
  * @param content - 消息正文(string 或 Message.content)
110
112
  * @returns 信封解析结果;非 turn_start 正文返回 null
111
113
  */
112
- export declare function parseTurnEnvelope(content: string | Message['content'] | undefined | null): TurnEnvelopeParts | null;
114
+ export declare function parseTurnEnvelope(content: EnvelopeContent | undefined): TurnEnvelopeParts | null;
113
115
  /**
114
116
  * 拼 turn_context 内的槽位 XML(runner 注入)。
115
117
  * 正文经 escapeSlotBody 定向转义(D7 A′):语料同名字面量不得产出解析器眼里的标签,
@@ -122,3 +124,4 @@ export declare function joinSlotXml(parts: Array<{
122
124
  }>): string;
123
125
  /** 任意 content 归一化后的用户正文(UI / 载体扫描共用) */
124
126
  export declare function unwrapUserText(content: string | Message['content'] | undefined | null): string;
127
+ export {};
@@ -8,7 +8,10 @@
8
8
  */
9
9
  import type { Message } from '@octopi-agent/core/types.js';
10
10
  import type { LLMMessage, LLMToolDefinition } from '@octopi-agent/core/interfaces/model-provider.js';
11
+ import type { SummarizeFunction } from './capabilities/compact/types.js';
11
12
  export type { LLMMessage, LLMToolDefinition };
13
+ /** 族 A 摘要执行契约:单源定义在 capabilities/compact/types.ts(此处再导出保持域内引用面稳定)。 */
14
+ export type { SummarizeFunction };
12
15
  export interface ContextEngineInfo {
13
16
  /** 引擎唯一标识 */
14
17
  id: string;
@@ -39,8 +42,8 @@ export interface TokenEstimator {
39
42
  /** 估算工具定义的 token 数 */
40
43
  estimateTools(tools: LLMToolDefinition[]): number;
41
44
  }
42
- /** 压缩原因:主动摘要 vs 硬溢出 */
43
- export type ContextCompactReason = 'proactive' | 'overflow';
45
+ /** 压缩原因:主动摘要 vs 硬溢出 vs 手动(m-2:manual 事件显式带 reason,防 store 沿用旧标签) */
46
+ export type ContextCompactReason = 'proactive' | 'overflow' | 'manual';
44
47
  /**
45
48
  * 上下文压缩可观测事件
46
49
  *
@@ -48,7 +51,7 @@ export type ContextCompactReason = 'proactive' | 'overflow';
48
51
  * 避免 LLM 摘要耗时被误判为会话卡死。失败不中断本轮(引擎回退截断)。
49
52
  */
50
53
  export interface ContextCompactEvent {
51
- type: 'context.compact.start' | 'context.compact.end' | 'context.compact.error' | 'context.compact.summarize_fallback';
54
+ type: 'context.compact.start' | 'context.compact.progress' | 'context.compact.end' | 'context.compact.error' | 'context.compact.summarize_fallback';
52
55
  sessionId: string;
53
56
  reason?: ContextCompactReason;
54
57
  /** 压缩前估算 token */
@@ -61,17 +64,54 @@ export interface ContextCompactEvent {
61
64
  durationMs?: number;
62
65
  /** 走缓存摘要重建,未调 LLM */
63
66
  cached?: boolean;
67
+ /** 中止收尾(本轮作废、零写入)——不是「压缩完成」,UI 不得显示 compacted */
68
+ cancelled?: boolean;
64
69
  /** summarize_fallback:cache-miss 旁路原因(no_prefix | window_guard | window_exhausted,F22) */
65
70
  fallback?: string;
66
71
  error?: string;
72
+ /** error 的性质:denied = before_compaction 策略拒绝(不是故障);failed = 压缩失败 */
73
+ kind?: 'denied' | 'failed';
74
+ /** progress:当前阶段(summarize = 摘要请求已发出、等 provider 返回) */
75
+ phase?: 'summarize';
76
+ /** progress:摘要请求体量(JSON 字符数) */
77
+ requestChars?: number;
78
+ /** progress:摘要请求消息条数 */
79
+ requestMessages?: number;
80
+ /** progress:本次摘要调用预算(ms);缺失 = 不设预算 */
81
+ timeoutMs?: number;
67
82
  }
68
83
  /** 事件回调(Builder 注入 → EventBus) */
69
- export type ContextEmitFn = (event: ContextCompactEvent) => void;
84
+ export type ContextEmitFn = (event: ContextCompactEvent | OverflowAlertEvent) => void;
85
+ /**
86
+ * overflow 症状告警(P3,arch/overflow-redesign.md §2.3 + 红线 7)
87
+ *
88
+ * 守门人触发 = 罕见异常信号,每次触发打告警(不当日常):
89
+ * - `proactive_failed`(A 类症状):前馈溢出——proactive 本该在到达窗口前压缩
90
+ * - `config_drift` / `config_missing`(F 类,有实证):contextWindow 配置漂移/缺失
91
+ * - `structural_over_budget`(D 类):保护段超限——窗口连固定面都放不下
92
+ * - `window_mismatch`(F 类,归因未定):请求超真窗口但未提取到数字,配置或尺子偏差待查
93
+ */
94
+ export interface OverflowAlertEvent {
95
+ type: 'context.overflow.alert';
96
+ sessionId: string;
97
+ /** 症状语义(红线 7:前馈溢出必须含 proactive 失效语义) */
98
+ symptom: 'proactive_failed' | 'config_drift' | 'config_missing' | 'structural_over_budget' | 'window_mismatch';
99
+ /** 人类可读告警(含症状语义关键词,UI/日志直接展示) */
100
+ message: string;
101
+ /** 触发时的估算 token(可选) */
102
+ estimatedTokens?: number;
103
+ /** 窗口值(配置或真值,可选) */
104
+ contextWindow?: number;
105
+ /** 触发入口:T1 前馈溢出 / T2 反馈溢出(F 类回填)/ T3 保护段超限 */
106
+ trigger?: 'T1' | 'T2' | 'T3';
107
+ }
70
108
  export interface AssembleParams {
71
109
  /** Session ID */
72
110
  sessionId: string;
73
111
  /** Agent ID(E4 compact 键分量;缺省时引擎状态退化为纯 sessionId) */
74
112
  agentId?: string;
113
+ /** provider/model 标识(P1-a 校准 ratio 分键,如 `mock/m`;缺省时校准归入 'unknown') */
114
+ modelKey?: string;
75
115
  /** 当前消息历史 */
76
116
  messages: Message[];
77
117
  /** 系统提示词 */
@@ -92,17 +132,25 @@ export interface AssembleParams {
92
132
  * 与 contextWindow 无关;未知窗口时仍可作手动/结构压缩的目标。
93
133
  */
94
134
  compactTargetTokens?: number;
95
- /** 中止信号 */
135
+ /** 中止信号(run 中止 → 取消在飞摘要;P3 起由 Loop 经 convertToLlm 透传) */
96
136
  signal?: AbortSignal;
97
- /** Token 估算器(可选,未提供时使用默认实现) */
137
+ /** Token 估算器(可选,未提供时使用默认实现)。**必须是未校准的原始估算器**——
138
+ * 校准由引擎 ContextSizeLedger 统一施加,传入已校准包装会造成双重校准 */
98
139
  tokenEstimator?: TokenEstimator;
99
140
  /** LLM 摘要调用函数(可选,用于压缩阶段) */
100
141
  summarize?: SummarizeFunction;
142
+ /**
143
+ * 交接式摘要素材:当前会话 task 快照(B0:易变块走 content 尾部指令)。
144
+ * 手动/自动(proactive/overflow)压缩路径统一透传给摘要请求(F8R-05),
145
+ * 使自动路径不再依赖注入历史里的旧快照副本。
146
+ */
147
+ taskSnapshot?: string;
101
148
  /** 压缩进度回调(可选;UI / 可观测) */
102
149
  emit?: ContextEmitFn;
103
150
  /**
104
- * 从持久层加载压缩状态快照(进程重启恢复)。
105
- * 引擎内存态为空时调用一次。
151
+ /**
152
+ * 旧压缩快照读口(ContextCompactSnapshot,迁移输入):转换记录账本为空且快照
153
+ * 存在时一次性迁移为初始记录(幂等)。迁移后快照不再更新。
106
154
  */
107
155
  loadCompactState?: (sessionId: string) => Promise<ContextCompactSnapshot | undefined> | ContextCompactSnapshot | undefined;
108
156
  }
@@ -125,28 +173,6 @@ export interface ContextCompactSnapshot {
125
173
  /** 上次主动压缩后的视图 token 估算 */
126
174
  lastProactiveTokens?: number;
127
175
  }
128
- /**
129
- * 摘要调用函数
130
- *
131
- * 由 Harness 层注入,ContextEngine 用它调用 LLM 生成摘要。
132
- * 这样 ContextEngine 不直接依赖 ModelProvider,保持解耦。
133
- *
134
- * 契约(迭代式更新):`options.previousSummary` 已按约定嵌入 `messages` 正文
135
- * ("Previous summary: …" 段),实现方无需再读 opts 拼 prompt;**返回值即完整
136
- * 更新后的摘要**,调用方不得再与旧摘要拼接。
137
- *
138
- * @param messages - 摘要请求消息(system 指令 + 用户正文;非原始对话序列)
139
- * @param options - 摘要选项
140
- * @returns 完整更新后的摘要文本
141
- */
142
- export type SummarizeFunction = (messages: LLMMessage[], options?: {
143
- /** 上次摘要(已嵌入 messages 正文;仅作元信息回传) */
144
- previousSummary?: string;
145
- /** 摘要 token 预算 */
146
- maxTokens?: number;
147
- /** 自定义指令 */
148
- instructions?: string;
149
- }) => Promise<string>;
150
176
  export interface AssembleResult {
151
177
  /** 组装好的 LLM 消息 */
152
178
  messages: LLMMessage[];
@@ -157,12 +183,12 @@ export interface AssembleResult {
157
183
  /** 被丢弃/压缩的信息摘要(告诉模型"你失去了什么") */
158
184
  droppedSummary?: string;
159
185
  /**
160
- * 当前会话压缩摘要正文(previousSummary)。
161
- * 供调用方写回 Session 持久化;无摘要时为 undefined。
186
+ * 当前会话压缩摘要正文(最新 summary 型转换记录的文本)。
187
+ * 供调用方展示;无摘要时为 undefined。
162
188
  */
163
189
  summary?: string;
164
- /** 可持久化压缩状态快照(含 lastProactiveMessageCount 等) */
165
- compactState?: ContextCompactSnapshot;
190
+ /** estimatedTokens 的读数来源(pressure 快照可观测,评审 F5):calibrated/anchored/raw */
191
+ readingSource?: 'calibrated' | 'anchored' | 'raw';
166
192
  /** 不可信内容范围 */
167
193
  untrustedRanges?: Array<{
168
194
  start: number;
@@ -174,27 +200,14 @@ export interface IngestParams {
174
200
  sessionId: string;
175
201
  message: Message;
176
202
  }
177
- export interface CompactResult {
178
- ok: boolean;
179
- compacted: boolean;
180
- reason?: string;
181
- tokensBefore: number;
182
- tokensAfter?: number;
183
- summary?: string;
184
- /**
185
- * 摘要覆盖终点(下标,**不含**)= tailStart。
186
- * sticky 重建的增量起点;写 `messages.length` 会把 tail 误算进覆盖 → 滑出后丢消息。
187
- */
188
- coveredMessageCount?: number;
189
- }
190
- export interface AfterTurnParams {
203
+ export interface AfterStepParams {
191
204
  sessionId: string;
192
205
  /** E4: compact key component; engine state key falls back to sessionId when omitted */
193
206
  agentId?: string;
194
207
  /** 本轮消息 */
195
- turn: Message[];
208
+ step: Message[];
196
209
  /** 本轮 token 使用(cache-aware) */
197
- usage?: import('@octopi-agent/core/types/turn.js').TokenUsage;
210
+ usage?: import('@octopi-agent/core/types/step.js').TokenUsage;
198
211
  }
199
212
  /**
200
213
  * ContextEngine — 上下文管理引擎
@@ -206,11 +219,36 @@ export interface AfterTurnParams {
206
219
  *
207
220
  * 可选方法:
208
221
  * - ingest(): 存储消息
209
- * - afterTurn(): 更新状态(turn 为**本轮增量**消息)
222
+ * - afterStep(): 更新状态(step 为**本轮增量**消息)
210
223
  *
211
224
  * 本域契约(@layer harness/context);Harness 提供 DefaultContextEngine。
212
225
  */
213
226
  export interface ContextEngine {
227
+ /**
228
+ * 校准状态快照(可选,持久化配套):锚+样本计数导出——restore 后回填消除冷启动。
229
+ * @returns per-key 样本计数与锚
230
+ */
231
+ exportCalibration?(): {
232
+ samples: Record<string, {
233
+ samples: number;
234
+ }>;
235
+ anchors: Record<string, {
236
+ actual: number;
237
+ raw: number;
238
+ modelKey: string;
239
+ }>;
240
+ };
241
+ /** 校准状态恢复(可选):importCalibration 配对使用 */
242
+ importCalibration?(data: {
243
+ samples?: Record<string, {
244
+ samples: number;
245
+ }>;
246
+ anchors?: Record<string, {
247
+ actual: number;
248
+ raw: number;
249
+ modelKey: string;
250
+ }>;
251
+ }): void;
214
252
  readonly info: ContextEngineInfo;
215
253
  /**
216
254
  * 组装上下文
@@ -233,14 +271,15 @@ export interface ContextEngine {
233
271
  *
234
272
  * 用于更新内部统计、触发异步压缩等。
235
273
  */
236
- afterTurn?(params: AfterTurnParams): Promise<void>;
274
+ afterStep?(params: AfterStepParams): Promise<void>;
237
275
  }
238
276
  export interface SelectResult {
239
- /** 要保留的消息 */
277
+ /** 要保留的消息。**身份契约**:必须是入参数组的同引用对象(转换记录按对象身份
278
+ * 把产物翻译回原始区间;返回拷贝会让翻译失锚) */
240
279
  kept: Message[];
241
- /** 溢出的消息(需要压缩) */
280
+ /** 溢出的消息(需要压缩)。同上:同引用 */
242
281
  overflow: Message[];
243
- /** 尾部保护的消息 */
282
+ /** 尾部保护的消息。同上:同引用 */
244
283
  tail: Message[];
245
284
  /** 尾部 token 数 */
246
285
  tailTokens: number;
@@ -253,83 +292,54 @@ export interface SelectOptions {
253
292
  maxTokens: number;
254
293
  protectFirstN: number;
255
294
  protectLastN: number;
256
- }
257
- export interface MessageSelector {
258
- select(messages: Message[], options: SelectOptions, tokenEstimator?: TokenEstimator): SelectResult;
259
- }
260
- export interface CompressParams {
261
- messages: Message[];
262
- targetTokens: number;
263
- previousSummary?: string;
264
- summarize?: SummarizeFunction;
265
- tokenEstimator?: TokenEstimator;
266
295
  /**
267
- * 要求产出语义摘要:设置后,机械截断(旧工具输出截断/兜底截断)即使已达标
268
- * 也不得就此短路返回——必须尝试摘要级。主动摘要路径(applyProactiveCompact)使用:
269
- * 否则压缩成功但永不产摘要,状态机的复用分支永远无法启用。
296
+ * 度量视图(可选):与 `messages` **等长同序**,只用于 token 估算。
270
297
  *
271
- * 实现约定:仅约束「可摘要时不得走机械短路」;无摘要能力(如无 summarize)时
272
- * 的机械降级结果是允许的,调用方以「结果中无语义摘要」识别降级
273
- * (见 DefaultContextEngine.extractSummaryText)。
298
+ * 存在的理由(尺子与作用域同源):实际请求发的是**老化视图**,而压缩必须吃
299
+ * **原文**(F-b)。若用原文估算,老化越有效误判越大——原文 middle 797k /
300
+ * 视图 76k 时会每请求判溢出、每请求触发一次摘要,把前缀缓存整段烧掉。
301
+ * 切分仍按 `messages`(原文),仅估算看这里。
274
302
  */
275
- requireSummary?: boolean;
276
- /**
277
- * 缓存前缀:与会话 LLM 请求**同形**的 system+history(buildLlmMessages 产物)。
278
- * 摘要请求只许在其**尾部**追加指令;禁止改 system / 历史字节——否则打穿 provider 前缀缓存。
279
- */
280
- llmPrefix?: LLMMessage[];
281
- /** 摘要软目标预算(P1c clamp(2%, 2k, 8k) 的可配置 ratio/min/max) */
282
- summaryBudget?: {
283
- ratioPct?: number;
284
- minTokens?: number;
285
- maxTokens?: number;
286
- };
287
- /** 折叠区间(评审 F7):交接书替换范围与原样保留尾部——计数语义 */
288
- foldRange?: {
289
- replacedCount: number;
290
- total: number;
291
- preservedTail: number;
292
- };
293
- /** task 快照(B0:易变块走 content 尾部,不进 system) */
294
- taskSnapshot?: string;
295
- /** 会话模型窗口/输出上限(评审 F5):摘要硬顶按窗口钳制 */
296
- contextWindow?: number;
297
- maxOutputTokens?: number;
298
- /** 事件回调(F22:cache-miss 旁路可观测) */
299
- emit?: (e: {
300
- type: 'compact.summarize_fallback';
301
- reason?: string;
302
- cached?: boolean;
303
- }) => void;
303
+ measureMessages?: Message[];
304
304
  }
305
- export interface CompressResult {
306
- /** 压缩后的消息/摘要 */
307
- result: Message[];
308
- /** 估算 token 数 */
309
- estimatedTokens: number;
310
- /** 本次产出**新的**语义摘要(评审 F8-F1):仅 true 时调用方才可推进覆盖点/previousSummary。
311
- * 机械降级(截断/兜底/占位说明)必须显式 false——占位说明不得冒充语义摘要(fail-closed,F8R-01)。 */
312
- fresh: boolean;
313
- /** LLM 摘要调用是否真正发起过(成功/失败均算):只在 true 时推进冷却时间戳(F8R-01)。 */
314
- summarizeAttempted: boolean;
315
- /** 被丢弃的信息摘要 */
316
- droppedSummary?: string;
317
- }
318
- export interface Compressor {
319
- compress(params: CompressParams): Promise<CompressResult>;
305
+ export interface MessageSelector {
306
+ select(messages: Message[], options: SelectOptions, tokenEstimator?: TokenEstimator): SelectResult;
320
307
  }
321
308
  export interface BudgetAllocateParams {
322
309
  /** 可用 token 预算;未知窗口时可省略(见 budget-allocator) */
323
310
  tokenBudget?: number;
324
311
  contextWindow?: number;
312
+ /**
313
+ * 模型单次输出上限(= 请求实际携带的 max_tokens 上界)。
314
+ * 提供且物理窗口已知时,按硬预留计入 `outputReserve`——这是
315
+ * `input + max_tokens ≤ contextWindow` 不变量的唯一保证。
316
+ * 窗口未知(仅有 compactTargetTokens 等策略目标)时忽略:目标不是物理边界。
317
+ */
318
+ maxOutputTokens?: number;
325
319
  systemPromptTokens: number;
326
320
  toolTokens: number;
327
321
  }
328
322
  export interface BudgetAllocateResult {
329
- /** 消息可用的 token 预算 */
323
+ /**
324
+ * 输入侧硬上限(不变量):`system + tools + messages ≤ inputLimit`。
325
+ * 恒有 `inputLimit + outputReserve ≤ effectiveLimit`。
326
+ */
327
+ inputLimit: number;
328
+ /**
329
+ * 消息侧硬上限 = `inputLimit − system − tools − 请求信封`。
330
+ * `MessageSelector` / overflow 目标等**强制点**必须用这个值。
331
+ */
332
+ messagesLimit: number;
333
+ /**
334
+ * 消息侧软目标(压缩策略提示值,≤ messagesLimit)。
335
+ * 触发压缩的阈值挂这里;它允许小于 messagesLimit(提前压缩),
336
+ * 但任何强制点不得用它当作边界。
337
+ */
330
338
  messagesBudget: number;
331
- /** 预留给模型输出的 token */
339
+ /** 预留给模型输出的 token(有 maxOutputTokens 时即其值) */
332
340
  outputReserve: number;
341
+ /** 预算不可行:固定开销 + 输出预留已吃掉窗口(messagesLimit ≤ 0) */
342
+ infeasible?: boolean;
333
343
  }
334
344
  export interface BudgetAllocator {
335
345
  allocate(params: BudgetAllocateParams): BudgetAllocateResult;
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import type { ToolFileEffects } from '@octopi-agent/core/types/tools.js';
20
20
  /** 审计事件词表(§7) */
21
- export type OpsAuditEvent = 'ops.jail.state' | 'ops.command.executed' | 'ops.system_path.write' | 'ops.policy.degraded' | 'ops.config.security_changed' | 'ops.escalation.requested' | 'ops.escalation.denied' | 'ops.privileged.exec' | 'ops.kill_switch.tripped';
21
+ export type OpsAuditEvent = 'ops.jail.state' | 'ops.command.executed' | 'ops.system_path.write' | 'ops.policy.degraded' | 'ops.config.security_changed' | 'ops.knowledge.run_refused' | 'ops.escalation.requested' | 'ops.escalation.denied' | 'ops.privileged.exec' | 'ops.kill_switch.tripped';
22
22
  /** 账本条目(hash 链节点) */
23
23
  export interface OpsAuditEntry {
24
24
  /** 从 1 起单调递增 */
@@ -2,7 +2,7 @@
2
2
  * L1 资源限制 — 工具执行看门狗(ToolEffectPolicy / OP-17)
3
3
  *
4
4
  * 统一强制 `definition.timeoutMs`;与 abortSignal 联动。
5
- * run 级硬停(token/iteration)仍归 Budget/Run,不在此域。
5
+ * run 级硬停(token/step)仍归 Budget/Run,不在此域。
6
6
  */
7
7
  export declare class ToolTimeoutError extends Error {
8
8
  readonly timedOut = true;
@@ -2,7 +2,7 @@
2
2
  * L1 资源限制 — 工具执行看门狗(ToolEffectPolicy / OP-17)
3
3
  *
4
4
  * 统一强制 `definition.timeoutMs`;与 abortSignal 联动。
5
- * run 级硬停(token/iteration)仍归 Budget/Run,不在此域。
5
+ * run 级硬停(token/step)仍归 Budget/Run,不在此域。
6
6
  */
7
7
  export class ToolTimeoutError extends Error {
8
8
  timedOut = true;
@@ -9,7 +9,7 @@
9
9
  * - Plugin 通过 registerChannel(adapter) 注册实现
10
10
  * - Gateway / Integration 按部署形态挂载具体 adapter
11
11
  */
12
- export type ChannelMessageDelivery = 'steered' | 'followup' | 'run';
12
+ export type ChannelMessageDelivery = 'continued' | 'followup' | 'run';
13
13
  export interface ChannelMessage {
14
14
  id: string;
15
15
  channel: string;
@@ -3,9 +3,10 @@
3
3
  *
4
4
  * 保留导出面:CommandRouter / parse / builtin / skill-bridge。
5
5
  */
6
- export type { ArgSpec, CommandCatalogItem, CommandConflict, CommandConflictCandidate, CommandContext, CommandDefinition, CommandEffect, CommandInvoker, CommandKind, CommandRegisterResult, CommandResult, CommandRisk, CommandSource, ConflictPolicy, DisplayPayload, ExpandedMessages, PrincipalRef, SessionOp, SessionReadView, } from './types.js';
6
+ export type { ArgSpec, CommandCatalogItem, CommandConflict, CommandConflictCandidate, CommandContext, CommandDefinition, CommandEffect, CommandExecutionSource, CommandInvoker, CommandKind, CommandRegisterResult, CommandResult, CommandRisk, CommandSource, ConflictPolicy, DisplayPayload, ExpandedMessages, PrincipalRef, SessionOp, SessionReadView, } from './types.js';
7
7
  export { normalizeCommandName, parseCommand, unescapeLiteralSlash, } from './parse.js';
8
8
  export type { ParsedCommand } from './parse.js';
9
+ export { COMMAND_INVOKERS } from './types.js';
9
10
  export { CommandRouter } from './router.js';
10
11
  export type { CommandRouterOptions, ExecuteCommandInput, ExecuteCommandOutcome, } from './router.js';
11
12
  export { createBuiltinCommands, createClientCatalogCommand, issuesFromRegistry, } from './builtin.js';
@@ -13,3 +14,4 @@ export type { BuiltinHost } from './builtin.js';
13
14
  export { isValidCommandFieldName, skillCommandsFromManager, } from './skill-bridge.js';
14
15
  export { loadUserCommandDefs } from './user-source.js';
15
16
  export { pluginCommandsFromManager } from './plugin-bridge.js';
17
+ export type { PluginCommandBridge } from './plugin-bridge.js';
@@ -4,6 +4,7 @@
4
4
  * 保留导出面:CommandRouter / parse / builtin / skill-bridge。
5
5
  */
6
6
  export { normalizeCommandName, parseCommand, unescapeLiteralSlash, } from './parse.js';
7
+ export { COMMAND_INVOKERS } from './types.js';
7
8
  export { CommandRouter } from './router.js';
8
9
  export { createBuiltinCommands, createClientCatalogCommand, issuesFromRegistry, } from './builtin.js';
9
10
  export { isValidCommandFieldName, skillCommandsFromManager, } from './skill-bridge.js';
@@ -3,4 +3,15 @@
3
3
  */
4
4
  import type { PluginManager } from '../plugins/manager.js';
5
5
  import type { CommandDefinition } from './types.js';
6
- export declare function pluginCommandsFromManager(pm: PluginManager): CommandDefinition[];
6
+ export interface PluginCommandBridge {
7
+ definition: CommandDefinition;
8
+ ref: string;
9
+ }
10
+ /**
11
+ * Mount effective plugin contributions without replacing author-declared metadata.
12
+ * The ref is Host-assigned plugin identity; it is not supplied by the handler.
13
+ *
14
+ * @param pm - Manager whose effective contribution registry has been published
15
+ * @returns Command definitions and stable plugin registration references
16
+ */
17
+ export declare function pluginCommandsFromManager(pm: PluginManager): PluginCommandBridge[];