@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
@@ -112,6 +112,23 @@ export interface EffectPolicyConfig {
112
112
  /** 额外事务 root(绝对路径或 ~ 形态,入口 trim → expand);并入 allowRoots */
113
113
  transactionRoots?: string[];
114
114
  pathContainment?: PathContainment;
115
+ /**
116
+ * 拒绝最终组件为符号链接的文件读写(缺省 `false`)。
117
+ *
118
+ * 包含判定已把路径解析为真实路径,正常情况下最终组件不是链接;若打开时它
119
+ * 仍是链接,说明检查与使用之间被替换。开启后以 `O_NOFOLLOW` / `lstat`
120
+ * 拒绝,而不是跟随。`untrusted` 模式强制开启,不受配置放松。
121
+ *
122
+ * 代价:`pathContainment: 'none'` 下根内合法链接的读写会被拒。
123
+ */
124
+ refuseFinalSymlink?: boolean;
125
+ /**
126
+ * 拒绝匹配这些 glob 的路径(相对允许根匹配,同时匹配文件名)。
127
+ *
128
+ * 默认空 = 不拒绝任何路径;「agent 读写自己 workspace 里的 `.env`」是合法
129
+ * 用法,本字段是部署策略而非引擎世界观。声明即拒绝,任何 containment 级别都生效。
130
+ */
131
+ pathDenylist?: string[];
115
132
  shellEscape?: ShellEscapePolicy;
116
133
  /**
117
134
  * Jail network posture (D4-c). Omitted = mode default:
@@ -142,8 +159,9 @@ export interface EffectPolicyConfig {
142
159
  jail?: JailIntent;
143
160
  /** jail≠none 且笼不可用时:`refuse` 拒绝执行 | `degrade`(缺省)记 securityDegraded + 告警 */
144
161
  onJailUnavailable?: OnJailUnavailable;
145
- /** `jail: "none"` 时必填的显式表态(缺省拒绝启动;§8.1 二级确认)。root/elevated
146
- * 部署同样要求此声明(§5 P4 root 部署语义,启动期断言)。 */
162
+ /** `jail: "none"` / `escalation: "full"` 时按块必填的显式表态(缺省拒绝启动;§8.1 二级确认)。
163
+ * root/elevated 部署声明是另一回事:只认**顶层** effectPolicy 的本字段(§5 P4,启动期断言);
164
+ * agent 块内的本字段只声明该块自己的 jail=none/full,不参与 elevated 启动声明。 */
147
165
  privilegedAck?: string;
148
166
  /** 提权策略(§4/§5 P3/P4):`allowlist` 按 cmd+args 全等放行;`full` 全量档
149
167
  * (需 `jail: "none"` + `privilegedAck` + `mode: "host"`);缺省 `none` */
@@ -188,6 +206,10 @@ export interface EffectiveEffectPolicy {
188
206
  securityDegraded: SecurityDegradation[];
189
207
  toolIsolation: ToolIsolationMode;
190
208
  pathContainment: PathContainment;
209
+ /** 拒绝最终组件为符号链接的文件读写(`untrusted` 强制 true) */
210
+ refuseFinalSymlink: boolean;
211
+ /** 拒绝清单(glob);空数组 = 不拒绝 */
212
+ pathDenylist: readonly string[];
191
213
  shellEscape: ShellEscapePolicy;
192
214
  /** Resolved jail network posture */
193
215
  network: 'open' | 'deny' | 'allowlist';
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { isAbsolute, resolve } from 'node:path';
8
8
  import { expandHomePath } from '../../../paths.js';
9
+ import { globToPathRegex, normalizeDenyPattern, validateDenyPattern } from '../../shared/paths/glob.js';
9
10
  import { checkEscalationBinary, escalationRuleTargets, escalationWritableRoots, } from './privileged-exec.js';
10
11
  import { deniesReducedSurface, resolveToolCapabilities, } from './tool-capabilities.js';
11
12
  import { assessL4ProcessMinimum, } from './process-isolation.js';
@@ -23,6 +24,10 @@ const MODE_DEFAULTS = {
23
24
  mode: 'workspace',
24
25
  toolIsolation: 'session-subdir',
25
26
  pathContainment: 'strict',
27
+ // containment 已把路径解析为真实路径,合法链接不受影响;需要闭合
28
+ // 「检查后、落盘前被换成链接」窗口的部署再显式开启。
29
+ refuseFinalSymlink: false,
30
+ pathDenylist: [],
26
31
  // 无 L4 时无法「只禁越界」:deny = 拒绝 shell 工具(fail-closed)
27
32
  shellEscape: 'deny',
28
33
  network: 'deny',
@@ -36,6 +41,8 @@ const MODE_DEFAULTS = {
36
41
  mode: 'project',
37
42
  toolIsolation: 'session-subdir',
38
43
  pathContainment: 'strict',
44
+ refuseFinalSymlink: false,
45
+ pathDenylist: [],
39
46
  // 编码 agent 必须有 shell;文件侧靠 L2,shell FS 越界待 L4
40
47
  shellEscape: 'allow',
41
48
  network: 'open',
@@ -49,6 +56,9 @@ const MODE_DEFAULTS = {
49
56
  mode: 'host',
50
57
  toolIsolation: 'none',
51
58
  pathContainment: 'none',
59
+ // containment 关闭时不做 realpath,开启会拒掉根内合法链接,故保持关闭
60
+ refuseFinalSymlink: false,
61
+ pathDenylist: [],
52
62
  shellEscape: 'allow',
53
63
  network: 'open',
54
64
  processLimits: true,
@@ -61,6 +71,9 @@ const MODE_DEFAULTS = {
61
71
  mode: 'untrusted',
62
72
  toolIsolation: 'session-subdir',
63
73
  pathContainment: 'strict',
74
+ // 不可信输入下强制开启:硬化为不可放松的产品承诺
75
+ refuseFinalSymlink: true,
76
+ pathDenylist: [],
64
77
  shellEscape: 'deny',
65
78
  network: 'deny',
66
79
  processLimits: true,
@@ -306,6 +319,21 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
306
319
  const pathContainment = requestedMode === 'untrusted'
307
320
  ? 'strict'
308
321
  : (config.pathContainment ?? d.pathContainment);
322
+ // Final-symlink refusal is a hardening, so the untrusted promise turns it on
323
+ // and config cannot loosen it back off. Elsewhere it stays opt-in: with
324
+ // containment off, in-root links are a legitimate workflow.
325
+ const refuseFinalSymlink = requestedMode === 'untrusted' ? true : (config.refuseFinalSymlink ?? d.refuseFinalSymlink);
326
+ // Union, not replace: a preset may only *add* denied patterns, so a deployment
327
+ // cannot loosen a built-in deny list by supplying its own.
328
+ const pathDenylist = [...new Set([...(d.pathDenylist ?? []), ...(config.pathDenylist ?? [])])]
329
+ .map(normalizeDenyPattern);
330
+ // Two gates, deliberately: the config schema rejects these shapes at load time
331
+ // (so a daemon never starts believing it is protected), and this loop covers
332
+ // callers that hand-build a config object instead of going through the schema.
333
+ for (const pattern of pathDenylist) {
334
+ validateDenyPattern(pattern);
335
+ globToPathRegex(pattern);
336
+ }
309
337
  // untrusted intent residue: keep discard-on-close even when effectiveMode renames
310
338
  const onClose = config.onClose ??
311
339
  (requestedMode === 'untrusted' ? MODE_DEFAULTS.untrusted.onClose : d.onClose);
@@ -319,6 +347,8 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
319
347
  securityDegraded,
320
348
  toolIsolation: config.toolIsolation ?? d.toolIsolation,
321
349
  pathContainment,
350
+ refuseFinalSymlink,
351
+ pathDenylist,
322
352
  // degraded untrusted must not leave shell allow as a hole
323
353
  shellEscape: toolSurface === 'reduced' ? 'deny' : (config.shellEscape ?? d.shellEscape),
324
354
  // untrusted product promise: egress deny is not a config knob (like pathContainment)
@@ -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 起单调递增 */
@@ -184,9 +184,13 @@ export declare class OpsAuditedFileEffects implements ToolFileEffects {
184
184
  private underRoots;
185
185
  private noteWrite;
186
186
  /** @inheritdoc */
187
- writeFile(path: string, data: string | Uint8Array): Promise<void>;
187
+ writeFile(path: string, data: string | Uint8Array, options?: {
188
+ refuseFinalSymlink?: boolean;
189
+ }): Promise<void>;
188
190
  /** @inheritdoc */
189
- appendFile(path: string, data: string | Uint8Array): Promise<void>;
191
+ appendFile(path: string, data: string | Uint8Array, options?: {
192
+ refuseFinalSymlink?: boolean;
193
+ }): Promise<void>;
190
194
  /** @inheritdoc */
191
195
  recordDelete(path: string, before: string | Uint8Array): Promise<void>;
192
196
  /** @inheritdoc */
@@ -18,7 +18,8 @@
18
18
  */
19
19
  import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, writeSync } from 'node:fs';
20
20
  import { createHash } from 'node:crypto';
21
- import { dirname, resolve, sep } from 'node:path';
21
+ import { dirname } from 'node:path';
22
+ import { isPathUnderRoots } from '../../shared/paths/index.js';
22
23
  /** 链首哨兵 */
23
24
  export const GENESIS_HASH = '0'.repeat(64);
24
25
  /**
@@ -279,13 +280,11 @@ export class OpsAuditedFileEffects {
279
280
  this.record = options.record;
280
281
  }
281
282
  underRoots(path) {
282
- // resolve + sep 感知;win32 大小写不敏感卷按 toLowerCase 口径(对齐 isPathAllowed)
283
- const norm = (p) => process.platform === 'win32' ? resolve(p).toLowerCase() : resolve(p);
284
- const target = norm(path);
285
- return this.roots.some((root) => {
286
- const base = norm(root);
287
- return target === base || target.startsWith(base.endsWith(sep) ? base : `${base}${sep}`);
288
- });
283
+ // Containment in real coordinates: tools now hand back symlink-resolved
284
+ // paths while `roots` keeps the configured spelling. A lexical-only check
285
+ // would audit every in-root write as an out-of-root write under alias roots
286
+ // (macOS /var → /private/var, a symlinked HOME).
287
+ return isPathUnderRoots(path, this.roots);
289
288
  }
290
289
  noteWrite(op, path, fromPath) {
291
290
  // 经 fileEffects 写口的写入本身是 undo 账在管(before/after 都在 TurnFileUndoLog,
@@ -301,13 +300,13 @@ export class OpsAuditedFileEffects {
301
300
  });
302
301
  }
303
302
  /** @inheritdoc */
304
- async writeFile(path, data) {
305
- await this.inner.writeFile(path, data);
303
+ async writeFile(path, data, options) {
304
+ await this.inner.writeFile(path, data, options);
306
305
  this.noteWrite('writeFile', path);
307
306
  }
308
307
  /** @inheritdoc */
309
- async appendFile(path, data) {
310
- await this.inner.appendFile(path, data);
308
+ async appendFile(path, data, options) {
309
+ await this.inner.appendFile(path, data, options);
311
310
  this.noteWrite('appendFile', path);
312
311
  }
313
312
  /** @inheritdoc */
@@ -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;
@@ -119,8 +119,12 @@ export declare class TurnFileUndoLog implements ToolFileEffects {
119
119
  }): Promise<TurnFileUndoLog>;
120
120
  get root(): string;
121
121
  get size(): number;
122
- writeFile(path: string, data: string | Uint8Array): Promise<void>;
123
- appendFile(path: string, data: string | Uint8Array): Promise<void>;
122
+ writeFile(path: string, data: string | Uint8Array, options?: {
123
+ refuseFinalSymlink?: boolean;
124
+ }): Promise<void>;
125
+ appendFile(path: string, data: string | Uint8Array, options?: {
126
+ refuseFinalSymlink?: boolean;
127
+ }): Promise<void>;
124
128
  /** 删除前调用:记 before,discard 时恢复 */
125
129
  recordDelete(path: string, before: string | Uint8Array): Promise<void>;
126
130
  /** 标记新建(零 before);已存在条目则不覆盖 first before */
@@ -9,7 +9,7 @@
9
9
  * 见 arch/tool-effect-policy.md §5.6。
10
10
  */
11
11
  import { createHash, randomBytes } from 'node:crypto';
12
- import { appendFile as fsAppendFile, chmod, mkdir, readFile, realpath, rename, rm, stat, writeFile, } from 'node:fs/promises';
12
+ import { appendFile as fsAppendFile, lstat, chmod, mkdir, readFile, realpath, rename, rm, stat, writeFile, } from 'node:fs/promises';
13
13
  import { join } from 'node:path';
14
14
  import { toSessionFileName } from '@octopi-agent/core/session-filename.js';
15
15
  import { isProbablyText, pathKey, reverseAgentOverwrite } from './undo-merge.js';
@@ -29,15 +29,35 @@ export function resolveSessionUndoPaths(sessionsDir, sessionId) {
29
29
  blobsDir: join(root, 'blobs'),
30
30
  };
31
31
  }
32
+ /**
33
+ * 最终组件为符号链接时拒绝(`refuseFinalSymlink` 开启时)。
34
+ *
35
+ * 检查与 fs 调用之间仍有极小窗口:本守卫的作用是把「包含检查 → 落盘」之间的
36
+ * 长窗口缩到两次相邻 syscall,而不是宣称彻底消除。中间路径段不在覆盖范围内。
37
+ */
38
+ async function assertFinalNotSymlink(path, options) {
39
+ if (options?.refuseFinalSymlink !== true)
40
+ return;
41
+ const entry = await lstat(path).catch(() => undefined);
42
+ if (entry?.isSymbolicLink()) {
43
+ throw new Error(`path_forbidden: "${path}" final component is a symlink (refuseFinalSymlink)`);
44
+ }
45
+ }
32
46
  /**
33
47
  * 原子覆写文件:tmp + rename,单次完整替换。
34
48
  * 防两类撕裂:同路径并发写交错字节、进程中途死掉留半截文件。
35
49
  * 语义差异(已接受):rename 以新 inode 替换目标,断开既有硬链接;
36
- * symlink 归一到实体(realpath)后落盘,保持 writeFile 穿透链接的语义;
50
+ * symlink 归一到实体(realpath)后落盘,保持 writeFile 穿透链接的语义
51
+ * (`refuseFinalSymlink` 开启时不再穿透,改为拒绝);
37
52
  * 既有文件的权限位经 chmod 保留;新建文件走默认 umask。
38
53
  */
39
- async function writeFileAtomic(path, data) {
40
- const target = await realpath(path).catch(() => path);
54
+ async function writeFileAtomic(path, data, options) {
55
+ // 守卫必须先于任何 realpath:realpath 会跟随链接,把「根内链接」解析成
56
+ // 「根外目标」,随后 rename 就落到根外去了。拒绝时直接以原路径为目标,
57
+ // rename 替换的是条目本身,不再穿过链接。
58
+ const refusing = options?.refuseFinalSymlink === true;
59
+ await assertFinalNotSymlink(path, options);
60
+ const target = refusing ? path : await realpath(path).catch(() => path);
41
61
  const mode = await stat(target).then((s) => s.mode & 0o7777).catch(() => undefined);
42
62
  const tmp = `${target}.octopi-tmp-${process.pid}-${randomBytes(6).toString('hex')}`;
43
63
  try {
@@ -153,11 +173,11 @@ export class TurnFileUndoLog {
153
173
  get size() {
154
174
  return this.entriesByPath.size;
155
175
  }
156
- async writeFile(path, data) {
157
- await this.recordWrite(path, data, 'overwrite');
176
+ async writeFile(path, data, options) {
177
+ await this.recordWrite(path, data, 'overwrite', options);
158
178
  }
159
- async appendFile(path, data) {
160
- await this.recordWrite(path, data, 'append');
179
+ async appendFile(path, data, options) {
180
+ await this.recordWrite(path, data, 'append', options);
161
181
  }
162
182
  /** 删除前调用:记 before,discard 时恢复 */
163
183
  async recordDelete(path, before) {
@@ -268,7 +288,7 @@ export class TurnFileUndoLog {
268
288
  }
269
289
  await this.flushLog();
270
290
  }
271
- async recordWrite(path, data, mode) {
291
+ async recordWrite(path, data, mode, options) {
272
292
  if (this.sealed) {
273
293
  throw new Error('turn file undo log already sealed');
274
294
  }
@@ -320,10 +340,11 @@ export class TurnFileUndoLog {
320
340
  }
321
341
  }
322
342
  if (mode === 'append') {
343
+ await assertFinalNotSymlink(path, options);
323
344
  await fsAppendFile(path, next);
324
345
  }
325
346
  else {
326
- await writeFileAtomic(path, next);
347
+ await writeFileAtomic(path, next, options);
327
348
  }
328
349
  await this.flushLog();
329
350
  }
@@ -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[];
@@ -1,17 +1,26 @@
1
1
  /**
2
2
  * Plugin registerCommand → CommandRouter 桥接
3
3
  */
4
+ /**
5
+ * Mount effective plugin contributions without replacing author-declared metadata.
6
+ * The ref is Host-assigned plugin identity; it is not supplied by the handler.
7
+ *
8
+ * @param pm - Manager whose effective contribution registry has been published
9
+ * @returns Command definitions and stable plugin registration references
10
+ */
4
11
  export function pluginCommandsFromManager(pm) {
5
12
  return pm.getCommands().map((cmd) => {
6
13
  const rawName = cmd.name.replace(/^\/+/, '');
7
- return {
14
+ const definition = {
8
15
  name: rawName,
9
16
  description: cmd.description ?? rawName,
10
17
  usage: `/${rawName}`,
11
- kind: 'control',
18
+ kind: cmd.kind ?? 'control',
12
19
  source: 'plugin',
13
- risk: 'low',
14
- invocableBy: ['principal', 'plugin'],
20
+ ...(cmd.risk === undefined ? {} : { risk: cmd.risk }),
21
+ ...(cmd.invocableBy === undefined ? {} : { invocableBy: cmd.invocableBy }),
22
+ ...(cmd.args === undefined ? {} : { args: cmd.args }),
23
+ ...(cmd.preempt === undefined ? {} : { preempt: cmd.preempt }),
15
24
  async execute(ctx) {
16
25
  try {
17
26
  const out = (await cmd.handler({
@@ -45,5 +54,6 @@ export function pluginCommandsFromManager(pm) {
45
54
  }
46
55
  },
47
56
  };
57
+ return { definition, ref: cmd.pluginId };
48
58
  });
49
59
  }
@@ -3,13 +3,13 @@
3
3
  *
4
4
  * 冲突策略(§6.0):
5
5
  * - 保留名:非 builtin 不得占用(可选 allowReservedOverride + prefer-source 显式胜出)
6
- * - 同 (source, ref) 重复注册 = upsert(skill 热重载安全)
6
+ * - 同 (source, ref, name) 重复注册 = upsert;ref 可同时承载一个插件的多个 Command
7
7
  * - 同名多候选(≥2)= reject-all:无一 active,候选保留至收敛到 1
8
8
  * - 永不因 reject-all 删除已注册 builtin
9
9
  * - Run 在途:仅 preempt 命令立即执行(默认仅 /stop)
10
10
  */
11
11
  import type { IssueRegistry } from '../../../observability/diagnostics/registry.js';
12
- import type { CommandCatalogItem, CommandConflict, CommandDefinition, CommandRegisterResult, CommandResult, CommandSource, ConflictPolicy, PrincipalRef, SessionOp, SessionReadView } from './types.js';
12
+ import type { CommandCatalogItem, CommandConflict, CommandDefinition, CommandExecutionSource, CommandRegisterResult, CommandResult, CommandSource, ConflictPolicy, PrincipalRef, SessionOp, SessionReadView } from './types.js';
13
13
  export interface CommandRouterOptions {
14
14
  issueRegistry?: IssueRegistry;
15
15
  conflictPolicy?: ConflictPolicy;
@@ -31,6 +31,7 @@ export type ExecuteCommandOutcome = {
31
31
  kind: 'command';
32
32
  result: CommandResult;
33
33
  definition?: CommandDefinition;
34
+ executionSource?: CommandExecutionSource;
34
35
  conflict?: CommandConflict;
35
36
  };
36
37
  export declare class CommandRouter {
@@ -46,10 +47,10 @@ export declare class CommandRouter {
46
47
  private sourcePriority;
47
48
  constructor(options?: CommandRouterOptions);
48
49
  /**
49
- * 注册命令。同 (source, ref) 为 upsert;按 name 候选数重算 active。
50
+ * 注册命令。同 (source, ref, name) 为 upsert;按 name 候选数重算 active。
50
51
  */
51
52
  register(definition: CommandDefinition, ref?: string): CommandRegisterResult;
52
- /** 按 (source, ref) 注销候选并重算 */
53
+ /** 按 (source, ref, name) 注销候选并重算 */
53
54
  unregister(source: CommandSource, ref: string, name: string): void;
54
55
  get(name: string): CommandDefinition | null;
55
56
  listDefinitions(): CommandDefinition[];
@@ -3,15 +3,15 @@
3
3
  *
4
4
  * 冲突策略(§6.0):
5
5
  * - 保留名:非 builtin 不得占用(可选 allowReservedOverride + prefer-source 显式胜出)
6
- * - 同 (source, ref) 重复注册 = upsert(skill 热重载安全)
6
+ * - 同 (source, ref, name) 重复注册 = upsert;ref 可同时承载一个插件的多个 Command
7
7
  * - 同名多候选(≥2)= reject-all:无一 active,候选保留至收敛到 1
8
8
  * - 永不因 reject-all 删除已注册 builtin
9
9
  * - Run 在途:仅 preempt 命令立即执行(默认仅 /stop)
10
10
  */
11
11
  import { parseCommand, normalizeCommandName, unescapeLiteralSlash } from './parse.js';
12
12
  const DEFAULT_PRIORITY = ['builtin', 'plugin', 'user', 'skill'];
13
- function candidateKey(source, ref) {
14
- return source + '\0' + ref;
13
+ function candidateKey(source, ref, name) {
14
+ return `${source}\0${ref}\0${name}`;
15
15
  }
16
16
  export class CommandRouter {
17
17
  /** 全部候选(含冲突中未激活的) */
@@ -31,7 +31,7 @@ export class CommandRouter {
31
31
  this.sourcePriority = options.sourcePriority ?? DEFAULT_PRIORITY;
32
32
  }
33
33
  /**
34
- * 注册命令。同 (source, ref) 为 upsert;按 name 候选数重算 active。
34
+ * 注册命令。同 (source, ref, name) 为 upsert;按 name 候选数重算 active。
35
35
  */
36
36
  register(definition, ref) {
37
37
  const name = normalizeCommandName(definition.name);
@@ -50,16 +50,16 @@ export class CommandRouter {
50
50
  this.rejectName(name, conflict, `命令 /${name} 未加载`, `保留名 /${name} 不可被 ${definition.source}(${sourceRef})占用。`, `commands:command.reserved_denied:${name}`);
51
51
  return { ok: false, reason: 'conflict', conflict };
52
52
  }
53
- this.candidates.set(candidateKey(definition.source, sourceRef), {
53
+ this.candidates.set(candidateKey(definition.source, sourceRef, name), {
54
54
  definition: normalized,
55
55
  ref: sourceRef,
56
56
  name,
57
57
  });
58
58
  return this.recompute(name);
59
59
  }
60
- /** 按 (source, ref) 注销候选并重算 */
60
+ /** 按 (source, ref, name) 注销候选并重算 */
61
61
  unregister(source, ref, name) {
62
- this.candidates.delete(candidateKey(source, ref));
62
+ this.candidates.delete(candidateKey(source, ref, normalizeCommandName(name) ?? name));
63
63
  this.recompute(normalizeCommandName(name) ?? name);
64
64
  }
65
65
  get(name) {
@@ -129,10 +129,12 @@ export class CommandRouter {
129
129
  };
130
130
  }
131
131
  const def = entry.definition;
132
+ const executionSource = { source: def.source, ref: entry.ref };
132
133
  if (!this.isInvokedBy(def, principal)) {
133
134
  return {
134
135
  kind: 'command',
135
136
  definition: def,
137
+ executionSource,
136
138
  result: {
137
139
  status: 'denied',
138
140
  display: textDisplay(`命令 /${def.name} 不允许当前调用方使用。`),
@@ -144,6 +146,7 @@ export class CommandRouter {
144
146
  return {
145
147
  kind: 'command',
146
148
  definition: def,
149
+ executionSource,
147
150
  result: {
148
151
  status: 'error',
149
152
  display: textDisplay('Agent 正在运行——可发送 /stop 中止后再试。'),
@@ -157,6 +160,7 @@ export class CommandRouter {
157
160
  return {
158
161
  kind: 'command',
159
162
  definition: def,
163
+ executionSource,
160
164
  result: {
161
165
  status: 'ok',
162
166
  display: textDisplay(`已展开 /${def.name}`),
@@ -167,12 +171,13 @@ export class CommandRouter {
167
171
  };
168
172
  }
169
173
  const result = await def.execute(ctx);
170
- return { kind: 'command', definition: def, result };
174
+ return { kind: 'command', definition: def, executionSource, result };
171
175
  }
172
176
  catch (err) {
173
177
  return {
174
178
  kind: 'command',
175
179
  definition: def,
180
+ executionSource,
176
181
  result: {
177
182
  status: 'error',
178
183
  display: textDisplay(`命令 /${def.name} 执行失败:${err instanceof Error ? err.message : String(err)}`),
@@ -262,13 +267,17 @@ export class CommandRouter {
262
267
  }
263
268
  isInvokedBy(def, principal) {
264
269
  const allowed = def.invocableBy ?? ['principal'];
265
- const actorType = principal.actorType ?? 'user';
266
- if (actorType === 'agent')
267
- return allowed.includes('agent');
268
- if (actorType === 'service' || actorType === 'subsystem') {
269
- return allowed.includes('plugin') || allowed.includes('principal');
270
+ switch (principal.actorType ?? 'user') {
271
+ case 'host':
272
+ case 'user':
273
+ case 'timer':
274
+ return allowed.includes('principal');
275
+ case 'agent':
276
+ return allowed.includes('agent');
277
+ case 'service':
278
+ case 'subsystem':
279
+ return allowed.includes('service');
270
280
  }
271
- return allowed.includes('principal');
272
281
  }
273
282
  higherSource(a, b) {
274
283
  return this.sourcePriority.indexOf(a) <= this.sourcePriority.indexOf(b);
@@ -7,7 +7,9 @@
7
7
  export type CommandKind = 'client' | 'control' | 'prompt';
8
8
  export type CommandSource = 'builtin' | 'plugin' | 'user' | 'skill';
9
9
  export type CommandRisk = 'low' | 'medium' | 'high';
10
- export type CommandInvoker = 'principal' | 'agent' | 'plugin';
10
+ /** Invoker categories expressible by PrincipalRef; source="plugin" is not caller identity. */
11
+ export declare const COMMAND_INVOKERS: readonly ["principal", "agent", "service"];
12
+ export type CommandInvoker = (typeof COMMAND_INVOKERS)[number];
11
13
  export type SessionOp = {
12
14
  op: 'abort_run';
13
15
  reason?: string;
@@ -111,6 +113,11 @@ export interface CommandConflictCandidate {
111
113
  ref: string;
112
114
  action: 'registered' | 'rejected' | 'shadowed';
113
115
  }
116
+ /** Host-assigned identity of the mounted definition; never accepted from a handler. */
117
+ export interface CommandExecutionSource {
118
+ source: CommandSource;
119
+ ref: string;
120
+ }
114
121
  export interface CommandConflict {
115
122
  name: string;
116
123
  candidates: CommandConflictCandidate[];
@@ -4,4 +4,5 @@
4
4
  * 归属:plugin-ecosystem/commands(调用面,与 tools/ 对偶)。
5
5
  * 效应经 sessionOps 由 Host 落地;handler 不直接改 session/model(I1/I6)。
6
6
  */
7
- export {};
7
+ /** Invoker categories expressible by PrincipalRef; source="plugin" is not caller identity. */
8
+ export const COMMAND_INVOKERS = ['principal', 'agent', 'service'];