@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
@@ -4,6 +4,8 @@
4
4
  * 文件/Shell 工具统一走这里,避免在各工具内手写 `startsWith('/')`
5
5
  * 或硬编码 `/bin/bash` 导致 Windows 行为分裂。
6
6
  */
7
+ import { isPathUnderRoots } from '../../../shared/paths/index.js';
8
+ export { isPathUnderRoots };
7
9
  /** 平台 shell 方言 */
8
10
  export type ShellKind = 'bash' | 'powershell' | 'cmd';
9
11
  /** 已解析的平台 shell */
@@ -17,20 +19,34 @@ export interface PlatformShell {
17
19
  label: string;
18
20
  }
19
21
  /**
20
- * 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
22
+ * Build containment options from a tool context.
21
23
  *
22
- * 使用 `path.isAbsolute`,同时覆盖 POSIX `/foo`、Windows 盘符
23
- * `C:\` / `C:/` 与 UNC `\\server\share`。
24
+ * Every tool used to spell these fields out by hand, which is how a newly added
25
+ * policy field gets silently dropped (the same failure that hid
26
+ * `refuseFinalSymlink` from the tool surface). One constructor, one place to add
27
+ * the next field.
24
28
  *
25
- * @param rawPath - 工具入参路径
26
- * @param cwd - 工作目录;缺省为 `process.cwd()`
27
- * @returns 规范化后的绝对路径
29
+ * @param context - tool execution context
30
+ * @returns options for {@link resolveToolPath}
28
31
  */
32
+ export declare function containmentOptions(context?: {
33
+ pathRoots?: readonly string[];
34
+ pathContainment?: 'strict' | 'soft' | 'none';
35
+ pathDenylist?: readonly string[];
36
+ } | null): ResolveToolPathOptions;
37
+ /** L2 路径约束选项(由 {@link containmentOptions} 从工具上下文构造) */
29
38
  export interface ResolveToolPathOptions {
30
39
  /** L2 允许根;containment 非 none 时必须落在其下 */
31
- allowRoots?: string[];
40
+ allowRoots?: readonly string[];
32
41
  /** L2 级别;省略 = 不限制 */
33
42
  containment?: 'strict' | 'soft' | 'none';
43
+ /**
44
+ * L2 拒绝清单(glob,匹配允许根内相对路径与文件名)。
45
+ *
46
+ * 独立于 containment:声明即拒绝,任何级别都生效。默认空 = 不拒绝任何路径,
47
+ * 因为「agent 读写自己 workspace 里的 `.env`」是合法且常见的用法。
48
+ */
49
+ denyPatterns?: readonly string[];
34
50
  }
35
51
  /**
36
52
  * 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
@@ -38,13 +54,11 @@ export interface ResolveToolPathOptions {
38
54
  * 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
39
55
  *
40
56
  * @param rawPath - 工具入参路径
41
- * @param cwd - 工作目录;缺省为 process.cwd()
57
+ * @param cwd - 工具 cwd;缺省为 process.cwd()
42
58
  * @param options - L2 路径包含(ToolEffectPolicy)
43
- * @returns 规范化后的绝对路径
59
+ * @returns 规范化后的绝对路径;containment 生效时为符号链接解析后的真实路径
44
60
  */
45
61
  export declare function resolveToolPath(rawPath: string, cwd?: string, options?: ResolveToolPathOptions): string;
46
- /** 路径是否落在任一 root 之下(含 root 本身) */
47
- export declare function isPathUnderRoots(absPath: string, roots: string[]): boolean;
48
62
  /**
49
63
  * 只读附件根内解析(OP-15):相对名优先贴到 attachmentRoots
50
64
  *
@@ -5,50 +5,146 @@
5
5
  * 或硬编码 `/bin/bash` 导致 Windows 行为分裂。
6
6
  */
7
7
  import { accessSync, constants, existsSync, statSync } from 'node:fs';
8
- import { delimiter, dirname, isAbsolute, join, resolve, sep } from 'node:path';
8
+ import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
9
+ import { isPathUnderRoots, lexicalUnderRoots, realpathAllowMissing, } from '../../../shared/paths/index.js';
10
+ import { matchesDenyPattern } from '../../../shared/paths/glob.js';
11
+ export { isPathUnderRoots };
12
+ /**
13
+ * Build containment options from a tool context.
14
+ *
15
+ * Every tool used to spell these fields out by hand, which is how a newly added
16
+ * policy field gets silently dropped (the same failure that hid
17
+ * `refuseFinalSymlink` from the tool surface). One constructor, one place to add
18
+ * the next field.
19
+ *
20
+ * @param context - tool execution context
21
+ * @returns options for {@link resolveToolPath}
22
+ */
23
+ export function containmentOptions(context) {
24
+ return {
25
+ allowRoots: context?.pathRoots,
26
+ containment: context?.pathContainment,
27
+ denyPatterns: context?.pathDenylist,
28
+ };
29
+ }
30
+ /**
31
+ * Apply L2 path containment against real (symlink-resolved) paths.
32
+ *
33
+ * Both sides are resolved: comparing a resolved target against an unresolved
34
+ * root would deny legitimate paths whenever the root is itself an alias
35
+ * (macOS `/var` → `/private/var`). The resolved target is returned so callers
36
+ * act on the same path that was checked; otherwise a link swapped between the
37
+ * check and the following fs call would still escape.
38
+ *
39
+ * @param absPath - absolute, lexically normalized candidate
40
+ * @param rawPath - original caller-supplied path, for error messages
41
+ * @param options - containment level and allowed roots
42
+ * @returns path to operate on
43
+ */
44
+ function containPath(absPath, rawPath, options) {
45
+ const containment = options?.containment ?? 'none';
46
+ const denyPatterns = options?.denyPatterns ?? [];
47
+ const roots = options?.allowRoots ?? [];
48
+ // The denylist is an independent deny layer: if a deployment declares these
49
+ // patterns forbidden, they are forbidden at every containment level. The
50
+ // lexical spelling is checked first because it needs no syscalls.
51
+ if (denyPatterns.length > 0) {
52
+ denyPath(absPath, rawPath, options, denyPatterns);
53
+ }
54
+ // `none` stays syscall-free unless a denylist is declared: then the resolved
55
+ // target must be checked too, or an innocuously named link reads a denied file.
56
+ if (containment === 'none') {
57
+ if (denyPatterns.length > 0)
58
+ denyResolvedTarget(absPath, rawPath, options, denyPatterns);
59
+ return absPath;
60
+ }
61
+ if (roots.length === 0) {
62
+ // strict 无 root = fail-closed(与 isPathAllowed 一致);soft 仅审计
63
+ if (containment === 'strict') {
64
+ throw new Error(`path_forbidden: "${rawPath}" effect roots not configured`);
65
+ }
66
+ if (denyPatterns.length > 0)
67
+ denyResolvedTarget(absPath, rawPath, options, denyPatterns);
68
+ return absPath;
69
+ }
70
+ const realRoots = roots
71
+ .map((root) => realpathAllowMissing(resolve(root)))
72
+ .filter((root) => root !== null);
73
+ const realTarget = realpathAllowMissing(absPath);
74
+ // Re-check the resolved path *before* the root verdict: the caller's spelling
75
+ // may be innocuous while the link target is denied, and that must also hold for
76
+ // paths that end up escaping the roots (soft mode passes those through).
77
+ if (denyPatterns.length > 0 && realTarget !== null && realTarget !== absPath) {
78
+ denyPath(realTarget, rawPath, options, denyPatterns);
79
+ }
80
+ // An unresolvable target or a set of vanished roots is a denial, not a pass.
81
+ // Both sides are already real here, so compare them lexically: re-resolving
82
+ // them would only repeat the syscalls.
83
+ if (realTarget === null || realRoots.length === 0 || !lexicalUnderRoots(realTarget, realRoots)) {
84
+ if (containment === 'strict') {
85
+ throw new Error(`path_forbidden: "${rawPath}" escapes effect roots`);
86
+ }
87
+ // soft:放行(审计由调用方/Observer 负责),保留词法答案以免改变既有语义
88
+ return absPath;
89
+ }
90
+ return realTarget;
91
+ }
92
+ /**
93
+ * Apply the denylist to the symlink-resolved target of a path.
94
+ *
95
+ * Only the resolved spelling is tested: the lexical one was already checked by
96
+ * the caller, and this exists for the "harmless name → denied target" case.
97
+ *
98
+ * @param absPath - absolute, lexically normalized candidate
99
+ * @param rawPath - caller spelling, for the error message
100
+ * @param options - containment options (roots)
101
+ * @param denyPatterns - denylist globs
102
+ */
103
+ function denyResolvedTarget(absPath, rawPath, options, denyPatterns) {
104
+ const realTarget = realpathAllowMissing(absPath);
105
+ if (realTarget !== null && realTarget !== absPath)
106
+ denyPath(realTarget, rawPath, options, denyPatterns);
107
+ }
108
+ /**
109
+ * Throw when the path matches the denylist.
110
+ *
111
+ * Matching happens against the path relative to the containing root, so a
112
+ * pattern like `.git/**` means "inside a root", not "anywhere on the host".
113
+ * When no root contains it the absolute path is used, which still catches
114
+ * name-based patterns such as `*.pem`.
115
+ *
116
+ * @param absPath - absolute path to test
117
+ * @param rawPath - caller spelling, for the error message
118
+ * @param options - containment options (roots)
119
+ * @param denyPatterns - denylist globs
120
+ */
121
+ function denyPath(absPath, rawPath, options, denyPatterns) {
122
+ const roots = options?.allowRoots ?? [];
123
+ const candidates = [];
124
+ for (const root of roots) {
125
+ const realRoot = realpathAllowMissing(resolve(root)) ?? resolve(root);
126
+ if (lexicalUnderRoots(absPath, [realRoot])) {
127
+ candidates.push(relative(realRoot, absPath).split(sep).join('/'));
128
+ }
129
+ }
130
+ candidates.push(absPath.split(sep).join('/'));
131
+ if (candidates.some((candidate) => matchesDenyPattern(candidate, denyPatterns))) {
132
+ throw new Error(`path_forbidden: "${rawPath}" matches pathDenylist`);
133
+ }
134
+ }
9
135
  /**
10
136
  * 解析工具入参路径:绝对路径原样返回,相对路径相对 cwd
11
137
  *
12
138
  * 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
13
139
  *
14
140
  * @param rawPath - 工具入参路径
15
- * @param cwd - 工作目录;缺省为 process.cwd()
141
+ * @param cwd - 工具 cwd;缺省为 process.cwd()
16
142
  * @param options - L2 路径包含(ToolEffectPolicy)
17
- * @returns 规范化后的绝对路径
143
+ * @returns 规范化后的绝对路径;containment 生效时为符号链接解析后的真实路径
18
144
  */
19
145
  export function resolveToolPath(rawPath, cwd, options) {
20
146
  const abs = isAbsolute(rawPath) ? resolve(rawPath) : resolve(cwd ?? process.cwd(), rawPath);
21
- const containment = options?.containment ?? 'none';
22
- if (containment !== 'none') {
23
- const roots = options?.allowRoots ?? [];
24
- if (roots.length === 0) {
25
- // strict 无 root = fail-closed(与 isPathAllowed 一致);soft 仅审计
26
- if (containment === 'strict') {
27
- throw new Error(`path_forbidden: "${rawPath}" effect roots not configured`);
28
- }
29
- return abs;
30
- }
31
- if (!isPathUnderRoots(abs, roots)) {
32
- if (containment === 'strict') {
33
- throw new Error(`path_forbidden: "${rawPath}" escapes effect roots`);
34
- }
35
- // soft:放行(审计由调用方/Observer 负责)
36
- }
37
- }
38
- return abs;
39
- }
40
- /** 路径是否落在任一 root 之下(含 root 本身) */
41
- export function isPathUnderRoots(absPath, roots) {
42
- const win = process.platform === 'win32';
43
- const norm = (s) => {
44
- const r = resolve(s);
45
- return win ? r.toLowerCase() : r;
46
- };
47
- const p = norm(absPath);
48
- return roots.some((root) => {
49
- const r = norm(root);
50
- return p === r || p.startsWith(r.endsWith(sep) ? r : r + sep);
51
- });
147
+ return containPath(abs, rawPath, options);
52
148
  }
53
149
  /**
54
150
  * 只读附件根内解析(OP-15):相对名优先贴到 attachmentRoots
@@ -64,13 +160,31 @@ export function resolveReadableToolPath(rawPath, cwd, attachmentRoots, options)
64
160
  if (!isAbsolute(rawPath) && roots.length > 0) {
65
161
  const cleaned = rawPath.replace(/^[/\\]+/, '');
66
162
  for (const root of roots) {
67
- const candidate = resolve(root, cleaned);
68
163
  const rootResolved = resolve(root);
69
- const prefix = rootResolved.endsWith(sep) ? rootResolved : rootResolved + sep;
70
- if (candidate === rootResolved || candidate.startsWith(prefix)) {
71
- if (existsSync(candidate))
72
- return candidate;
164
+ const candidate = resolve(rootResolved, cleaned);
165
+ // Lexical guard against `cleaned` climbing out of the root; shares the
166
+ // win32 case-folding rule with every other containment check.
167
+ if (candidate !== rootResolved && !lexicalUnderRoots(candidate, [rootResolved]))
168
+ continue;
169
+ if (!existsSync(candidate))
170
+ continue;
171
+ // Attachment roots sit outside the effect roots by design, so they carry
172
+ // their own containment: a link planted in the attachment tree would
173
+ // otherwise be a straight read out of the read-only sandbox.
174
+ // Both sides are resolved here, so compare lexically rather than making
175
+ // isPathUnderRoots resolve them a second time.
176
+ const realRoot = realpathAllowMissing(rootResolved);
177
+ const realCandidate = realpathAllowMissing(candidate);
178
+ if (realRoot === null || realCandidate === null)
179
+ continue;
180
+ if (!lexicalUnderRoots(realCandidate, [realRoot]))
181
+ continue;
182
+ // Attachment roots are outside the effect roots, so they would otherwise
183
+ // skip the denylist entirely: "read-only" is not "allowed to read".
184
+ if (options?.denyPatterns && options.denyPatterns.length > 0) {
185
+ denyPath(realCandidate, rawPath, options, options.denyPatterns);
73
186
  }
187
+ return realCandidate;
74
188
  }
75
189
  }
76
190
  // attachments 命中后返回;其余走 L2
@@ -85,17 +199,11 @@ export function resolveReadableToolPath(rawPath, cwd, attachmentRoots, options)
85
199
  export function isUnderAttachmentRoot(path, attachmentRoots) {
86
200
  if (!attachmentRoots?.length)
87
201
  return false;
88
- // Windows 路径比较须大小写不敏感,否则可绕过 startsWith 写保护
89
- const win = process.platform === 'win32';
90
- const norm = (s) => (win ? resolve(s).toLowerCase() : resolve(s));
91
- const p = norm(path);
92
- for (const root of attachmentRoots) {
93
- const r = norm(root);
94
- const prefix = r.endsWith(sep) ? r : r + sep;
95
- if (p === r || p.startsWith(prefix))
96
- return true;
97
- }
98
- return false;
202
+ // `path` now arrives resolved (`resolveToolPath` returns the real path), so a
203
+ // purely lexical comparison against a configured root would report false
204
+ // whenever the root is an alias (macOS /var, symlinked HOME) — turning a
205
+ // write-protection guard into a fail-open. Resolve both sides.
206
+ return isPathUnderRoots(path, attachmentRoots);
99
207
  }
100
208
  function isExecutableFile(filePath) {
101
209
  try {
@@ -374,17 +482,15 @@ export function defaultPathEnv() {
374
482
  * @returns whether the path is protected undo ledger
375
483
  */
376
484
  export function isUnderSessionUndoRoot(target, undoRoots) {
377
- const resolved = resolve(target);
378
485
  const roots = (undoRoots ?? []).map((r) => r?.trim()).filter(Boolean);
379
- const fold = (p) => process.platform === 'win32' ? p.toLowerCase() : p;
380
- if (roots.length > 0) {
381
- const norm = (p) => fold(resolve(p).replace(/\\/g, '/'));
382
- const tNorm = norm(resolved);
383
- return roots.some((root) => {
384
- const r = norm(root);
385
- return tNorm === r || tNorm.startsWith(r.endsWith('/') ? r : r + '/');
386
- });
387
- }
388
- const norm = fold(resolved.replace(/\\/g, '/'));
389
- return /\/sessions\/[^/]+\/undo(\/|$)/i.test(norm);
486
+ // Same coordinate problem as isUnderAttachmentRoot: the target arrives as a
487
+ // real path while the configured roots keep their lexical spelling.
488
+ if (roots.length > 0)
489
+ return isPathUnderRoots(target, roots);
490
+ // No configured roots: recognise the default layout instead. Resolve first so
491
+ // a symlinked sessions directory still matches the same rule.
492
+ const resolved = realpathAllowMissing(resolve(target)) ?? resolve(target);
493
+ const converted = resolved.replace(/\\/g, '/');
494
+ const folded = process.platform === 'win32' ? converted.toLowerCase() : converted;
495
+ return /\/sessions\/[^/]+\/undo(\/|$)/i.test(folded);
390
496
  }
@@ -0,0 +1,11 @@
1
+ /** Plugin Tool mounting and authorization shared by ToolBus, Agent, and Gateway. */
2
+ import type { RegisteredTool, ToolPolicy, ToolSource } from '@octopi-agent/core/types.js';
3
+ import type { PluginToolRecord } from '../plugins/contribution-registry.js';
4
+ /** Plugin Tools never inherit builtin's empty-allow visibility. */
5
+ export declare function isPluginToolPermitted(tool: RegisteredTool, policy?: ToolPolicy): boolean;
6
+ /** AgentTool/Runner projection variant: no handler is needed for policy evaluation. */
7
+ export declare function isPluginToolCallPermitted(name: string, source: ToolSource | undefined, policy?: ToolPolicy): boolean;
8
+ /** Adapter boundary: the host, not the plugin, assigns the contribution identity. */
9
+ export declare function pluginToolToRegisteredTool(record: PluginToolRecord): RegisteredTool;
10
+ /** Mount only explicitly permitted contributions into an Agent's local ToolBus. */
11
+ export declare function mountPluginTools(records: readonly PluginToolRecord[], agentId: string, policy: ToolPolicy | undefined, registerForAgent: (agentId: string, tool: RegisteredTool) => void): RegisteredTool[];
@@ -0,0 +1,39 @@
1
+ /** Plugin Tool mounting and authorization shared by ToolBus, Agent, and Gateway. */
2
+ /** Plugin Tools never inherit builtin's empty-allow visibility. */
3
+ export function isPluginToolPermitted(tool, policy) {
4
+ return isPluginToolCallPermitted(tool.definition.name, tool.source, policy);
5
+ }
6
+ /** AgentTool/Runner projection variant: no handler is needed for policy evaluation. */
7
+ export function isPluginToolCallPermitted(name, source, policy) {
8
+ if (source?.kind !== 'plugin')
9
+ return true;
10
+ const allow = policy?.allow ?? [];
11
+ if (!(allow.includes('*') || allow.includes(name)))
12
+ return false;
13
+ if (policy?.deny?.includes('*') || policy?.deny?.includes(name))
14
+ return false;
15
+ return true;
16
+ }
17
+ /** Adapter boundary: the host, not the plugin, assigns the contribution identity. */
18
+ export function pluginToolToRegisteredTool(record) {
19
+ const source = { kind: 'plugin', origin: record.pluginId, trustLevel: 'third-party' };
20
+ return {
21
+ definition: record.definition,
22
+ handler: record.handler,
23
+ source,
24
+ executionMode: record.executionMode ??
25
+ (record.definition.capabilities?.includes('fs-write') ? 'sequential' : undefined),
26
+ };
27
+ }
28
+ /** Mount only explicitly permitted contributions into an Agent's local ToolBus. */
29
+ export function mountPluginTools(records, agentId, policy, registerForAgent) {
30
+ const mounted = [];
31
+ for (const record of records) {
32
+ const tool = pluginToolToRegisteredTool(record);
33
+ if (!isPluginToolPermitted(tool, policy))
34
+ continue;
35
+ registerForAgent(agentId, tool);
36
+ mounted.push(tool);
37
+ }
38
+ return mounted;
39
+ }
@@ -59,7 +59,7 @@ export declare class DefaultToolBus implements ToolBus {
59
59
  * 查找工具 → 参数校验 → 调用 handler。
60
60
  * 适用于在 agentLoop 外部直接调用工具的场景。
61
61
  */
62
- execute(name: string, args: Record<string, unknown>, context: import('@octopi-agent/core/types.js').ToolExecutionContext): Promise<unknown>;
62
+ execute(name: string, args: Record<string, unknown>, context: import('@octopi-agent/core/types.js').ToolExecutionContext, policy?: ToolPolicy): Promise<unknown>;
63
63
  /**
64
64
  * 获取全局注册的工具名集合(用于 SecurityGuard 的 registeredTools 校验)
65
65
  */
@@ -18,6 +18,7 @@
18
18
  */
19
19
  import { registerToolCapabilities } from '../../execution-environment/tool-capabilities.js';
20
20
  import { buildToolLlmParameters } from '../../../agent/tool-purpose.js';
21
+ import { isPluginToolPermitted } from './plugin-tool.js';
21
22
  /**
22
23
  * DefaultToolBus — 工具总线实现
23
24
  *
@@ -54,6 +55,9 @@ export class DefaultToolBus {
54
55
  }
55
56
  }
56
57
  registerForAgent(agentId, tool) {
58
+ if (this.getTool(tool.definition.name, agentId)) {
59
+ throw new Error(`Agent tool "${tool.definition.name}" already registered for "${agentId}"`);
60
+ }
57
61
  if (!this.agentTools.has(agentId)) {
58
62
  this.agentTools.set(agentId, new Map());
59
63
  }
@@ -90,7 +94,7 @@ export class DefaultToolBus {
90
94
  }
91
95
  // ── 解析 ──
92
96
  resolve(agentId, policy) {
93
- let tools = this.listForAgent(agentId);
97
+ let tools = this.listForAgent(agentId).filter((tool) => isPluginToolPermitted(tool, policy));
94
98
  if (policy) {
95
99
  if (policy.allow && policy.allow.length > 0) {
96
100
  const allowSet = new Set(policy.allow);
@@ -154,11 +158,16 @@ export class DefaultToolBus {
154
158
  * 查找工具 → 参数校验 → 调用 handler。
155
159
  * 适用于在 agentLoop 外部直接调用工具的场景。
156
160
  */
157
- async execute(name, args, context) {
161
+ async execute(name, args, context, policy) {
158
162
  const tool = this.getTool(name, context.agentId);
159
163
  if (!tool) {
160
164
  throw new Error(`Tool "${name}" not found`);
161
165
  }
166
+ const { getRunScope } = await import('../../../run/run-scope.js');
167
+ const effectivePolicy = getRunScope()?.toolRuntime?.agentToolPolicy ?? policy;
168
+ if (!isPluginToolPermitted(tool, effectivePolicy)) {
169
+ throw new Error(`Plugin tool "${name}" is not allowed for agent "${context.agentId}"`);
170
+ }
162
171
  this.validateArgs(name, args, tool.definition);
163
172
  const { runWithToolLimits, resolveToolTimeoutMs } = await import('../../execution-environment/resource-limits.js');
164
173
  return runWithToolLimits((signal) => tool.handler(args, { ...context, abortSignal: signal }), {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 见 arch/budget-redesign.md:只记录,不 kill。Policy 另层(P3+)。
5
5
  */
6
- import type { TokenUsage } from '@octopi-agent/core/types/turn.js';
6
+ import type { TokenUsage } from '@octopi-agent/core/types/step.js';
7
7
  /** 账本快照(Observer + Policy 只读输入) */
8
8
  export interface UsageLedgerSnapshot {
9
9
  scope: 'run' | 'session';
@@ -24,6 +24,8 @@ export interface UsageLedgerSnapshot {
24
24
  elapsedMs: number;
25
25
  /** P5: context 估算 tokens(最新值) */
26
26
  contextEstTokens?: number;
27
+ /** context 实测 tokens(最近一次非摘要 LLM 调用的 prompt 实测;wrap-up 压力轴优先用它) */
28
+ contextActualTokens?: number;
27
29
  /** P5: context 窗口大小(模型能力) */
28
30
  contextWindowTokens?: number;
29
31
  /** P5: 估算花费(币种由 pricing 决定) */
@@ -53,6 +55,7 @@ export declare class UsageLedger {
53
55
  private summaryOutputTokens;
54
56
  private toolCalls;
55
57
  private contextEstTokens?;
58
+ private contextActualTokens?;
56
59
  private contextWindowTokens?;
57
60
  private toolSummaryApplied;
58
61
  private toolOutputRawChars;
@@ -105,3 +108,12 @@ export declare class UsageLedger {
105
108
  agentId?: string;
106
109
  }): UsageLedgerSnapshot;
107
110
  }
111
+ /**
112
+ * wrap-up 压力轴的 context 体量口径(单一实现):实测优先,估算只做前瞻补充。
113
+ * 毒估算/锚外推可把估算放大数倍(2026-11-07 实测 5.4× 虚高误杀 run),
114
+ * 压力裁决必须锚在 provider 实测上;无实测(首步前)才回落估算。
115
+ *
116
+ * @param snapshot - 用量账本快照
117
+ * @returns 压力裁决用的 context 体量(tokens),两者皆缺返回 undefined
118
+ */
119
+ export declare function contextPressureTokens(snapshot: Pick<UsageLedgerSnapshot, 'contextActualTokens' | 'contextEstTokens'>): number | undefined;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 见 arch/budget-redesign.md:只记录,不 kill。Policy 另层(P3+)。
5
5
  */
6
- import { nominalTotalTokens } from '@octopi-agent/core/types/turn.js';
6
+ import { nominalTotalTokens } from '@octopi-agent/core/types/step.js';
7
7
  /**
8
8
  * UsageLedger
9
9
  */
@@ -20,6 +20,7 @@ export class UsageLedger {
20
20
  summaryOutputTokens = 0;
21
21
  toolCalls = 0;
22
22
  contextEstTokens;
23
+ contextActualTokens;
23
24
  contextWindowTokens;
24
25
  toolSummaryApplied = 0;
25
26
  toolOutputRawChars = 0;
@@ -46,6 +47,14 @@ export class UsageLedger {
46
47
  this.summaryLlmCalls++;
47
48
  this.summaryOutputTokens += usage.outputTokens;
48
49
  }
50
+ else {
51
+ // context 实测:只认对话请求的 prompt 实测(摘要请求的 usage 是另一个请求的体量,
52
+ // 混入会污染压力轴);provider 报告优先,分项和兜底——与展示口径同源
53
+ const promptActual = usage.inputReportedTokens ??
54
+ usage.inputUncachedTokens + usage.inputCachedTokens + usage.inputCacheWriteTokens;
55
+ if (promptActual > 0)
56
+ this.contextActualTokens = promptActual;
57
+ }
49
58
  }
50
59
  /** @param n - 工具调用次数 */
51
60
  recordToolCall(n = 1) {
@@ -98,6 +107,7 @@ export class UsageLedger {
98
107
  this.summaryOutputTokens = 0;
99
108
  this.toolCalls = 0;
100
109
  this.contextEstTokens = undefined;
110
+ this.contextActualTokens = undefined;
101
111
  this.contextWindowTokens = undefined;
102
112
  this.toolSummaryApplied = 0;
103
113
  this.toolOutputRawChars = 0;
@@ -127,6 +137,7 @@ export class UsageLedger {
127
137
  toolCalls: this.toolCalls,
128
138
  elapsedMs: Date.now() - this.startTime,
129
139
  contextEstTokens: this.contextEstTokens,
140
+ contextActualTokens: this.contextActualTokens,
130
141
  contextWindowTokens: this.contextWindowTokens,
131
142
  toolSummaryApplied: this.toolSummaryApplied,
132
143
  toolOutputRawChars: this.toolOutputRawChars,
@@ -135,3 +146,14 @@ export class UsageLedger {
135
146
  };
136
147
  }
137
148
  }
149
+ /**
150
+ * wrap-up 压力轴的 context 体量口径(单一实现):实测优先,估算只做前瞻补充。
151
+ * 毒估算/锚外推可把估算放大数倍(2026-11-07 实测 5.4× 虚高误杀 run),
152
+ * 压力裁决必须锚在 provider 实测上;无实测(首步前)才回落估算。
153
+ *
154
+ * @param snapshot - 用量账本快照
155
+ * @returns 压力裁决用的 context 体量(tokens),两者皆缺返回 undefined
156
+ */
157
+ export function contextPressureTokens(snapshot) {
158
+ return snapshot.contextActualTokens ?? snapshot.contextEstTokens;
159
+ }
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import type { HitlDecision } from '@octopi-agent/core/types/tools.js';
14
14
  /** Which confirm surface produced the decision */
15
- export type HitlChannel = 'high_risk' | 'effect';
15
+ export type HitlChannel = 'high_risk' | 'effect' | 'plugin_hook';
16
16
  /** Cached scope of a remembered approval */
17
17
  export type HitlCacheScope = 'session' | 'always';
18
18
  /** 非人工拒绝来源(人工决策不带此标注);用于错误面与审计如实归因 */
@@ -62,7 +62,7 @@ export declare class HitlDecisionCache {
62
62
  /**
63
63
  * Look up a remembered approval.
64
64
  *
65
- * @param channel - high_risk | effect
65
+ * @param channel - high_risk | effect | plugin_hook
66
66
  * @param key - tool name or effect kind
67
67
  * @param options - sessionId (session scope) and/or agentId (always scope)
68
68
  * @returns `'approve'` if cached, otherwise `null`
@@ -79,7 +79,7 @@ export declare class HitlDecisionCache {
79
79
  * Missing scope id → silently one-shot (fail-safe, never over-grant).
80
80
  *
81
81
  * @param decision - host decision
82
- * @param channel - high_risk | effect
82
+ * @param channel - high_risk | effect | plugin_hook
83
83
  * @param key - tool name or effect kind
84
84
  * @param options - sessionId and/or agentId
85
85
  */
@@ -43,7 +43,7 @@ export class HitlDecisionCache {
43
43
  /**
44
44
  * Look up a remembered approval.
45
45
  *
46
- * @param channel - high_risk | effect
46
+ * @param channel - high_risk | effect | plugin_hook
47
47
  * @param key - tool name or effect kind
48
48
  * @param options - sessionId (session scope) and/or agentId (always scope)
49
49
  * @returns `'approve'` if cached, otherwise `null`
@@ -74,7 +74,7 @@ export class HitlDecisionCache {
74
74
  * Missing scope id → silently one-shot (fail-safe, never over-grant).
75
75
  *
76
76
  * @param decision - host decision
77
- * @param channel - high_risk | effect
77
+ * @param channel - high_risk | effect | plugin_hook
78
78
  * @param key - tool name or effect kind
79
79
  * @param options - sessionId and/or agentId
80
80
  */
@@ -138,8 +138,7 @@ export class CapabilityEnforcer {
138
138
  case '*':
139
139
  return { allowed: true };
140
140
  case 'allowed-list':
141
- // 可以配置白名单
142
- return { allowed: true };
141
+ return { allowed: false, reason: `Plugin "${pluginId}" network allow-list is not implemented for host "${host}"` };
143
142
  case 'none':
144
143
  return { allowed: false, reason: `Plugin "${pluginId}" has no network access` };
145
144
  default:
@@ -62,5 +62,6 @@ export declare class DefaultToolCallRiskPolicy implements ToolCallRiskPolicy {
62
62
  steps?: string[];
63
63
  };
64
64
  reason: string;
65
+ uncertain?: boolean;
65
66
  };
66
67
  }
@@ -60,6 +60,7 @@ export class DefaultToolCallRiskPolicy {
60
60
  })),
61
61
  alternative,
62
62
  reason: decision.reason,
63
+ uncertain: decision.uncertain,
63
64
  };
64
65
  }
65
66
  }
@@ -423,6 +423,15 @@ export class DefaultSecurityGuard {
423
423
  });
424
424
  return { isClean: hardViolations.length === 0, violations: hardViolations, riskUnknown: true };
425
425
  }
426
+ // 强不确定(解析结构性不确定):正交通知安全智能体过目,
427
+ // 等级判定与拦截行为照常(不因不确定放行,也不因不确定加拦)
428
+ if (decision.uncertain) {
429
+ this.emitRunEvent({
430
+ type: 'tool_call.risk_unknown',
431
+ timestamp: Date.now(),
432
+ data: { toolCall: call, decision },
433
+ });
434
+ }
426
435
  const riskViolations = [];
427
436
  if (decision.level !== 'low') {
428
437
  const severityMap = {
@@ -5,6 +5,7 @@
5
5
  * SecurityGuard 接口定义在 Core 层。
6
6
  */
7
7
  export { DefaultSecurityGuard } from './default-security-guard.js';
8
+ export { initShellParser, isShellParserReady, getShellParserEngine, } from './shell-parser.js';
8
9
  export { isValidSecurityGuard, severityToAction } from '@octopi-agent/core/security-guard.js';
9
10
  export type { SecurityGuard, SecurityCheckResult, SecurityViolation, SecurityViolationType, SecurityAction, BehaviorContext, SecurityGuardConfig, } from '@octopi-agent/core/interfaces/security-guard.js';
10
11
  export type { ToolCallRiskPolicy } from '@octopi-agent/core/interfaces/security-guard.js';
@@ -6,5 +6,7 @@
6
6
  */
7
7
  // ── DefaultSecurityGuard 实现(canonical 位置) ──
8
8
  export { DefaultSecurityGuard } from './default-security-guard.js';
9
+ // ── Shell 解析引擎(自装配方需自行 await initShellParser) ──
10
+ export { initShellParser, isShellParserReady, getShellParserEngine, } from './shell-parser.js';
9
11
  // ── Core 接口 re-export(方便 harness 消费者) ──
10
12
  export { isValidSecurityGuard, severityToAction } from '@octopi-agent/core/security-guard.js';