@octopi-agent/engine 0.102.10 → 0.121.15

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 (321) hide show
  1. package/dist/builtin-model-info.js +28 -7
  2. package/dist/config-admin/agent-presets.d.ts +32 -0
  3. package/dist/config-admin/agent-presets.js +133 -0
  4. package/dist/config-admin/console-access-key.d.ts +46 -0
  5. package/dist/config-admin/console-access-key.js +47 -0
  6. package/dist/config-admin/discover.d.ts +33 -4
  7. package/dist/config-admin/discover.js +101 -6
  8. package/dist/config-admin/env.d.ts +11 -0
  9. package/dist/config-admin/env.js +41 -0
  10. package/dist/config-admin/error-copy.d.ts +106 -0
  11. package/dist/config-admin/error-copy.js +287 -0
  12. package/dist/config-admin/i18n.d.ts +21 -0
  13. package/dist/config-admin/i18n.js +19 -0
  14. package/dist/config-admin/index.d.ts +8 -2
  15. package/dist/config-admin/index.js +4 -1
  16. package/dist/config-admin/model-presets.d.ts +14 -0
  17. package/dist/config-admin/model-presets.js +595 -70
  18. package/dist/config-admin/onboarding-apply.d.ts +83 -0
  19. package/dist/config-admin/onboarding-apply.js +259 -0
  20. package/dist/config-admin/onboarding.d.ts +160 -0
  21. package/dist/config-admin/onboarding.js +298 -0
  22. package/dist/config-admin/password-policy.d.ts +24 -0
  23. package/dist/config-admin/password-policy.js +31 -0
  24. package/dist/config-admin/redact.d.ts +42 -9
  25. package/dist/config-admin/redact.js +69 -5
  26. package/dist/config-schema/agent.d.ts +5 -1
  27. package/dist/config-schema/agent.js +20 -2
  28. package/dist/config-schema/browser.d.ts +62 -0
  29. package/dist/config-schema/browser.js +89 -0
  30. package/dist/config-schema/context.d.ts +7 -2
  31. package/dist/config-schema/context.js +6 -3
  32. package/dist/config-schema/engine.d.ts +86 -7
  33. package/dist/config-schema/engine.js +9 -2
  34. package/dist/config-schema/governance.d.ts +12 -1
  35. package/dist/config-schema/governance.js +10 -2
  36. package/dist/config-schema/models.d.ts +12 -8
  37. package/dist/config-schema/models.js +16 -1
  38. package/dist/config-schema/run.d.ts +4 -0
  39. package/dist/config-schema/run.js +10 -0
  40. package/dist/config-schema/shared.d.ts +1 -0
  41. package/dist/config-schema/shared.js +4 -2
  42. package/dist/config-schema/substrate.d.ts +5 -0
  43. package/dist/config-schema/substrate.js +8 -0
  44. package/dist/config.d.ts +116 -10
  45. package/dist/config.js +109 -13
  46. package/dist/file-mode.d.ts +67 -0
  47. package/dist/file-mode.js +182 -0
  48. package/dist/fork-child.d.ts +82 -0
  49. package/dist/fork-child.js +123 -0
  50. package/dist/harness/activation/delegated-run.d.ts +42 -0
  51. package/dist/harness/activation/delegated-run.js +71 -0
  52. package/dist/harness/activation/dispatcher.js +4 -0
  53. package/dist/harness/activation/index.d.ts +1 -0
  54. package/dist/harness/activation/run-backend.d.ts +92 -0
  55. package/dist/harness/activation/run-backend.js +16 -0
  56. package/dist/harness/activation/run-protocol.d.ts +392 -0
  57. package/dist/harness/activation/run-protocol.js +19 -0
  58. package/dist/harness/activation/runtime.d.ts +33 -0
  59. package/dist/harness/activation/runtime.js +119 -28
  60. package/dist/harness/activation/types.d.ts +19 -2
  61. package/dist/harness/agent/builder.d.ts +12 -0
  62. package/dist/harness/agent/builder.js +78 -22
  63. package/dist/harness/agent/config-bridge.d.ts +10 -1
  64. package/dist/harness/agent/config-bridge.js +15 -3
  65. package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
  66. package/dist/harness/agent/registered-tool-adapter.js +67 -0
  67. package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
  68. package/dist/harness/agent/wire-agent-builder.js +9 -2
  69. package/dist/harness/capabilities/document/backends/plain.js +2 -1
  70. package/dist/harness/capabilities/document/legacy/factory.js +3 -2
  71. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
  72. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
  73. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
  74. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
  75. package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
  76. package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
  77. package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
  78. package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
  79. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
  80. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
  81. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
  82. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
  83. package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
  84. package/dist/harness/collaboration/delegation/child-run.js +34 -2
  85. package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
  86. package/dist/harness/collaboration/delegation/service.d.ts +9 -4
  87. package/dist/harness/collaboration/delegation/service.js +33 -12
  88. package/dist/harness/collaboration/delegation/store.d.ts +2 -0
  89. package/dist/harness/collaboration/delegation/store.js +1 -0
  90. package/dist/harness/collaboration/delegation/types.d.ts +11 -0
  91. package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
  92. package/dist/harness/collaboration/delegation/wiring.js +1 -0
  93. package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
  94. package/dist/harness/context/capabilities/compact/engine.js +127 -39
  95. package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
  96. package/dist/harness/context/capabilities/compact/index.js +1 -1
  97. package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
  98. package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
  99. package/dist/harness/context/capabilities/summary/gate.js +53 -6
  100. package/dist/harness/context/capabilities/summary/registry.js +20 -0
  101. package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
  102. package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
  103. package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
  104. package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
  105. package/dist/harness/context/constitution/default-agents.md +85 -0
  106. package/dist/harness/context/context-size-ledger.js +8 -1
  107. package/dist/harness/context/default-context-engine.d.ts +100 -6
  108. package/dist/harness/context/default-context-engine.js +382 -89
  109. package/dist/harness/context/index.d.ts +2 -1
  110. package/dist/harness/context/index.js +1 -0
  111. package/dist/harness/context/layer-health.d.ts +4 -0
  112. package/dist/harness/context/layer-health.js +4 -0
  113. package/dist/harness/context/layer-types.d.ts +57 -0
  114. package/dist/harness/context/layer-types.js +73 -1
  115. package/dist/harness/context/layers.d.ts +3 -0
  116. package/dist/harness/context/layers.js +13 -6
  117. package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
  118. package/dist/harness/context/prefix-fingerprint.js +52 -0
  119. package/dist/harness/context/summarize.js +18 -0
  120. package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
  121. package/dist/harness/context/system-prompt-assembler.js +5 -2
  122. package/dist/harness/context/tool-result-aging.d.ts +104 -16
  123. package/dist/harness/context/tool-result-aging.js +211 -57
  124. package/dist/harness/context/types.d.ts +71 -4
  125. package/dist/harness/context/types.js +25 -1
  126. package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
  127. package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
  128. package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
  129. package/dist/harness/extension/execution-environment/workspace.js +1 -1
  130. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
  131. package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
  132. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
  133. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
  134. package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
  135. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  136. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  137. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
  138. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
  139. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
  140. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
  141. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
  142. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
  143. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
  144. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
  145. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
  146. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
  147. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
  148. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
  149. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
  150. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
  151. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
  152. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
  153. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
  154. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
  155. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
  156. package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
  157. package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
  158. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
  159. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
  160. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
  161. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
  162. package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
  163. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
  164. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
  165. package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
  166. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
  167. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
  168. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
  169. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
  170. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
  171. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
  172. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
  173. package/dist/harness/governance/credentials/db.d.ts +9 -0
  174. package/dist/harness/governance/credentials/db.js +122 -31
  175. package/dist/harness/governance/credentials/store.d.ts +68 -7
  176. package/dist/harness/governance/credentials/store.js +177 -64
  177. package/dist/harness/governance/credentials/types.d.ts +13 -2
  178. package/dist/harness/governance/index.d.ts +1 -0
  179. package/dist/harness/governance/index.js +1 -0
  180. package/dist/harness/governance/registry/db.d.ts +32 -0
  181. package/dist/harness/governance/registry/db.js +142 -0
  182. package/dist/harness/governance/registry/index.d.ts +9 -0
  183. package/dist/harness/governance/registry/index.js +9 -0
  184. package/dist/harness/governance/registry/service.d.ts +381 -0
  185. package/dist/harness/governance/registry/service.js +825 -0
  186. package/dist/harness/governance/registry/types.d.ts +77 -0
  187. package/dist/harness/governance/registry/types.js +7 -0
  188. package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
  189. package/dist/harness/governance/security/default-security-guard.js +12 -1
  190. package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
  191. package/dist/harness/governance/security/risk-evaluator.js +307 -21
  192. package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
  193. package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
  194. package/dist/harness/index.d.ts +5 -3
  195. package/dist/harness/index.js +2 -2
  196. package/dist/harness/knowledge/boot-config.d.ts +2 -0
  197. package/dist/harness/knowledge/boot-config.js +2 -0
  198. package/dist/harness/knowledge/client.d.ts +53 -7
  199. package/dist/harness/knowledge/client.js +77 -20
  200. package/dist/harness/knowledge/db.d.ts +16 -0
  201. package/dist/harness/knowledge/db.js +107 -41
  202. package/dist/harness/knowledge/engine-thread.js +5 -7
  203. package/dist/harness/knowledge/grounding.js +4 -1
  204. package/dist/harness/knowledge/http-app.d.ts +15 -0
  205. package/dist/harness/knowledge/http-app.js +82 -21
  206. package/dist/harness/knowledge/http-bridge.d.ts +15 -0
  207. package/dist/harness/knowledge/http-bridge.js +19 -0
  208. package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
  209. package/dist/harness/knowledge/query-service.d.ts +12 -2
  210. package/dist/harness/knowledge/query-service.js +75 -41
  211. package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
  212. package/dist/harness/knowledge/query-worker-client.js +4 -1
  213. package/dist/harness/knowledge/query-worker.js +5 -3
  214. package/dist/harness/knowledge/read-http.d.ts +2 -0
  215. package/dist/harness/knowledge/read-http.js +9 -2
  216. package/dist/harness/knowledge/retriever.d.ts +1 -1
  217. package/dist/harness/knowledge/retriever.js +1 -2
  218. package/dist/harness/knowledge/serve.d.ts +6 -1
  219. package/dist/harness/knowledge/serve.js +5 -6
  220. package/dist/harness/knowledge/source-store.d.ts +101 -5
  221. package/dist/harness/knowledge/source-store.js +297 -71
  222. package/dist/harness/knowledge/start-service-process.d.ts +27 -8
  223. package/dist/harness/knowledge/start-service-process.js +49 -90
  224. package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
  225. package/dist/harness/knowledge/tenant-gate.js +167 -0
  226. package/dist/harness/knowledge/writer-service.d.ts +18 -2
  227. package/dist/harness/knowledge/writer-service.js +80 -16
  228. package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
  229. package/dist/harness/knowledge/writer-worker-client.js +20 -3
  230. package/dist/harness/knowledge/writer-worker.js +11 -4
  231. package/dist/harness/memory/backfill-trigger.d.ts +10 -3
  232. package/dist/harness/memory/backfill-trigger.js +19 -19
  233. package/dist/harness/memory/cognition-seeds.d.ts +45 -0
  234. package/dist/harness/memory/cognition-seeds.js +67 -0
  235. package/dist/harness/memory/cognition.d.ts +12 -3
  236. package/dist/harness/memory/cognition.js +55 -35
  237. package/dist/harness/memory/conceptualizer.d.ts +11 -1
  238. package/dist/harness/memory/conceptualizer.js +10 -1
  239. package/dist/harness/memory/context-slice.d.ts +42 -0
  240. package/dist/harness/memory/context-slice.js +197 -0
  241. package/dist/harness/memory/health-probe.d.ts +8 -2
  242. package/dist/harness/memory/health-probe.js +10 -13
  243. package/dist/harness/memory/index.d.ts +5 -1
  244. package/dist/harness/memory/index.js +3 -1
  245. package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
  246. package/dist/harness/memory/sqlite/agent-db.js +9 -8
  247. package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
  248. package/dist/harness/memory/sqlite/cognition-store.js +103 -45
  249. package/dist/harness/memory/sqlite/memory-store.js +4 -0
  250. package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
  251. package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
  252. package/dist/harness/memory/types.d.ts +18 -2
  253. package/dist/harness/observability/observer/hub.d.ts +10 -0
  254. package/dist/harness/observability/observer/hub.js +95 -2
  255. package/dist/harness/run/agent/agent.js +3 -2
  256. package/dist/harness/run/concurrency/tool-validator.js +4 -3
  257. package/dist/harness/run/reliability/run-agent.d.ts +22 -0
  258. package/dist/harness/run/reliability/run-agent.js +79 -10
  259. package/dist/harness/run/run-host.d.ts +302 -0
  260. package/dist/harness/run/run-host.js +978 -0
  261. package/dist/harness/run/run-scope.d.ts +11 -0
  262. package/dist/harness/run/run-scope.js +19 -1
  263. package/dist/harness/run/runner.d.ts +149 -22
  264. package/dist/harness/run/runner.js +352 -35
  265. package/dist/harness/session/in-memory-store.js +13 -1
  266. package/dist/harness/session/schedules/service.d.ts +10 -2
  267. package/dist/harness/session/schedules/service.js +13 -2
  268. package/dist/harness/session/tasks/tools.js +12 -0
  269. package/dist/harness/session/types.d.ts +10 -14
  270. package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
  271. package/dist/harness/shared/types/agent-definition.d.ts +6 -0
  272. package/dist/index.d.ts +3 -2
  273. package/dist/index.js +2 -1
  274. package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
  275. package/dist/integration/agent-runtime/channel-message-source.js +4 -3
  276. package/dist/integration/browser/camoufox.d.ts +40 -0
  277. package/dist/integration/browser/camoufox.js +80 -0
  278. package/dist/integration/browser/index.d.ts +91 -0
  279. package/dist/integration/browser/index.js +110 -0
  280. package/dist/integration/browser/install.d.ts +47 -0
  281. package/dist/integration/browser/install.js +214 -0
  282. package/dist/integration/browser/playwright.d.ts +224 -0
  283. package/dist/integration/browser/playwright.js +925 -0
  284. package/dist/integration/browser/service.d.ts +41 -0
  285. package/dist/integration/browser/service.js +181 -0
  286. package/dist/integration/browser/stealth.d.ts +42 -0
  287. package/dist/integration/browser/stealth.js +104 -0
  288. package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
  289. package/dist/integration/providers/anthropic-message-normalize.js +48 -0
  290. package/dist/integration/providers/anthropic.js +27 -2
  291. package/dist/integration/providers/fetch-timeout.d.ts +17 -0
  292. package/dist/integration/providers/fetch-timeout.js +24 -0
  293. package/dist/integration/providers/openai.d.ts +8 -0
  294. package/dist/integration/providers/openai.js +41 -1
  295. package/dist/integration/providers/wire-dump-diff.js +2 -1
  296. package/dist/integration/providers/wire-dump.d.ts +56 -2
  297. package/dist/integration/providers/wire-dump.js +119 -6
  298. package/dist/integration/storage/archive-manager.d.ts +14 -2
  299. package/dist/integration/storage/archive-manager.js +24 -8
  300. package/dist/integration/storage/atomic-tmp.d.ts +12 -0
  301. package/dist/integration/storage/atomic-tmp.js +36 -0
  302. package/dist/integration/storage/jsonl.d.ts +9 -0
  303. package/dist/integration/storage/jsonl.js +137 -38
  304. package/dist/integration/storage/session-index.d.ts +5 -0
  305. package/dist/integration/storage/session-index.js +25 -4
  306. package/dist/integration/tools/assemble.d.ts +50 -0
  307. package/dist/integration/tools/assemble.js +137 -0
  308. package/dist/paths.d.ts +18 -0
  309. package/dist/paths.js +36 -0
  310. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
  311. package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
  312. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
  313. package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
  314. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
  315. package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
  316. package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
  317. package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
  318. package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
  319. package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
  320. package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
  321. package/package.json +5 -3
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Registry types — 租户与定义面实体模型(arch/multi-tenancy.md §3)。
3
+ *
4
+ * 所有权锚 = tenantId(隔离/审计/转移的钥匙);ownerUserId = 管理归属;
5
+ * visibility 决定租户内可见性。「一用户一租户」是策略默认,不是 schema 约束。
6
+ */
7
+ import type { Branded } from '../../knowledge/types.js';
8
+ export type TenantId = Branded<string, 'TenantId'>;
9
+ export type UserId = Branded<string, 'UserId'>;
10
+ export type AgentId = Branded<string, 'AgentId'>;
11
+ export type BindingId = Branded<string, 'BindingId'>;
12
+ export type MountId = Branded<string, 'MountId'>;
13
+ export type KnowledgeSourceId = Branded<string, 'KnowledgeSourceId'>;
14
+ export type AuthToken = Branded<string, 'AuthToken'>;
15
+ /** agent 在租户内的可见性:private=仅 owner;tenant=租户共享 */
16
+ export type AgentVisibility = 'private' | 'tenant';
17
+ /** 渠道会话策略:per-user 常驻 / per-chat 群会话 / per-message 单发 */
18
+ export type SessionPolicy = 'per-user' | 'per-chat' | 'per-message';
19
+ /** 挂载消费方:agent / project / session */
20
+ export type MountConsumerType = 'agent' | 'project' | 'session';
21
+ /** 挂载资产类型:knowledge 知识库 / project 项目 */
22
+ export type MountSourceType = 'knowledge' | 'project';
23
+ /** 资产所有权:platform 公共(跨租户共享唯一合法形态)/ tenant 私有 */
24
+ export type SourceScope = 'platform' | 'tenant';
25
+ export interface Tenant {
26
+ tenantId: TenantId;
27
+ name: string;
28
+ createdAt: number;
29
+ }
30
+ export interface User {
31
+ userId: UserId;
32
+ tenantId: TenantId;
33
+ name: string;
34
+ /** 平台 admin(Q13:首个注册用户;管理 platform 公共资产) */
35
+ isPlatformAdmin: boolean;
36
+ createdAt: number;
37
+ }
38
+ export interface AgentRecord {
39
+ agentId: AgentId;
40
+ tenantId: TenantId;
41
+ ownerUserId: UserId;
42
+ visibility: AgentVisibility;
43
+ name: string;
44
+ /** 定义权威在此(config/persona/skills 引用);机器上 agents/<id>/ 是物化态 */
45
+ definition: string;
46
+ homeRef: string | null;
47
+ createdAt: number;
48
+ updatedAt: number;
49
+ }
50
+ export interface Binding {
51
+ bindingId: BindingId;
52
+ tenantId: TenantId;
53
+ platform: string;
54
+ identity: string;
55
+ agentId: AgentId;
56
+ sessionPolicy: SessionPolicy;
57
+ createdAt: number;
58
+ }
59
+ export interface Mount {
60
+ mountId: MountId;
61
+ tenantId: TenantId;
62
+ consumerType: MountConsumerType;
63
+ consumerId: string;
64
+ sourceType: MountSourceType;
65
+ sourceId: KnowledgeSourceId | string;
66
+ /** session 挂载的反物化锚(消费会话所属 agent);agent/project 挂载为 null */
67
+ agentRef: string | null;
68
+ createdAt: number;
69
+ }
70
+ export interface KnowledgeSource {
71
+ sourceId: KnowledgeSourceId;
72
+ scope: SourceScope;
73
+ /** platform 库为 null */
74
+ tenantId: TenantId | null;
75
+ name: string;
76
+ createdAt: number;
77
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Registry types — 租户与定义面实体模型(arch/multi-tenancy.md §3)。
3
+ *
4
+ * 所有权锚 = tenantId(隔离/审计/转移的钥匙);ownerUserId = 管理归属;
5
+ * visibility 决定租户内可见性。「一用户一租户」是策略默认,不是 schema 约束。
6
+ */
7
+ export {};
@@ -56,6 +56,9 @@ export declare class DefaultSecurityGuard {
56
56
  checkModelOutput(output: string): SecurityCheckResult;
57
57
  /**
58
58
  * 检查工具输出(注入检测,始终开启)
59
+ *
60
+ * 默认档命中的处置是「标记放行」(severity medium → warn,调用方附不可信资料标记后放行),
61
+ * 不是销毁内容;只有 `injectionSensitivity: 'high'` 严格档升级为拦截。
59
62
  */
60
63
  checkToolOutput(output: string): SecurityCheckResult;
61
64
  /**
@@ -282,6 +282,9 @@ export class DefaultSecurityGuard {
282
282
  }
283
283
  /**
284
284
  * 检查工具输出(注入检测,始终开启)
285
+ *
286
+ * 默认档命中的处置是「标记放行」(severity medium → warn,调用方附不可信资料标记后放行),
287
+ * 不是销毁内容;只有 `injectionSensitivity: 'high'` 严格档升级为拦截。
285
288
  */
286
289
  checkToolOutput(output) {
287
290
  return this.checkInjection(output, 'tool_output');
@@ -566,7 +569,15 @@ export class DefaultSecurityGuard {
566
569
  if (match) {
567
570
  violations.push({
568
571
  type: 'injection',
569
- severity: this.config.injectionSensitivity === 'high' ? 'critical' : 'high',
572
+ // 注入命中的处置分通道:工具输出是「资料」——出现攻击形态文本 ≠ 攻击已生效,
573
+ // 默认档标记放行(medium→warn),内容不销毁(否则一切讨论注入的安全文档、
574
+ // 宪法、本守卫源码自身都被整份误杀);用户输入不适用「资料」语义,维持
575
+ // high(→confirm)。injectionSensitivity: 'high' 是严格档,两通道一律拦截。
576
+ severity: this.config.injectionSensitivity === 'high'
577
+ ? 'critical'
578
+ : source === 'tool_output'
579
+ ? 'medium'
580
+ : 'high',
570
581
  description: `检测到可能的 prompt injection: "${match[0].substring(0, 50)}..."`,
571
582
  range: { start: match.index, end: match.index + match[0].length },
572
583
  });
@@ -55,10 +55,20 @@ export declare function isProtectedPath(path: string, cwd?: string): boolean;
55
55
  */
56
56
  export declare function detectCatastrophicRecursiveDelete(command: string, cwd?: string): string | null;
57
57
  /**
58
- * 硬边界:下载并执行(管道链上同时出现下载源与解释器)
58
+ * 硬边界:下载并执行(下载内容真实流入解释器)
59
59
  *
60
- * 覆盖 `curl|bash`、`curl|/bin/bash`、`curl|env bash`、`curl|tee x|bash`。
61
- * 仅下载(`curl -o file`)或普通管道(`cat|grep`)不命中。
60
+ * 数据流判定(非共存判定),三条规则:
61
+ * 1. **管道链**:同一条 `|` 链上下载源在解释器上游 → 拦
62
+ * (`curl | sh`、`curl | /bin/bash`、`curl | env bash`、`curl | tee x | bash`)
63
+ * 2. **文件交接**:下载落盘(`curl -o f` / `curl -O` / `wget` 默认落盘 / `wget -O f` /
64
+ * `> f` 重定向 / 链下游 `tee f`)且同一命令串在下载之后执行同一文件(`bash f` /
65
+ * `python f` / `./f` / `source f` / `sh -c "./f"`)→ 拦(`curl -o s.sh … && bash s.sh`)
66
+ * 3. **嵌入注入**:下载源出现在解释器的内联载荷(`sh -c "$(curl …)"`)或进程替换
67
+ * (`bash <(curl …)`)里——下载文本直接进入解释器代码位 → 拦
68
+ *
69
+ * 仅共存不算数据流:`curl -o data.csv … && python analyze.py`、
70
+ * `bash build.sh && curl …`(解释器与下载无交接或顺序相反)不命中。
71
+ * 仅下载(`curl -o file` 无执行)或普通管道(`cat | grep`)不命中。
62
72
  */
63
73
  export declare function detectDownloadToInterpreter(command: string): string | null;
64
74
  /**
@@ -776,34 +776,320 @@ const INTERPRETER_BASES = new Set([
776
776
  /** 下载源命令 basename */
777
777
  const DOWNLOAD_BASES = new Set(['curl', 'wget', 'http', 'https']);
778
778
  /** 解释器前的合法 wrapper(不改变 RCE 语义) */
779
- const EXEC_WRAPPER_BASES = new Set(['sudo', 'env', 'nice', 'nohup', 'exec', 'xargs', 'time']);
779
+ const EXEC_WRAPPER_BASES = new Set(['sudo', 'env', 'nice', 'nohup', 'exec', 'xargs', 'time', 'timeout']);
780
780
  /**
781
- * 硬边界:下载并执行(管道链上同时出现下载源与解释器)
781
+ * 硬边界:下载并执行(下载内容真实流入解释器)
782
782
  *
783
- * 覆盖 `curl|bash`、`curl|/bin/bash`、`curl|env bash`、`curl|tee x|bash`。
784
- * 仅下载(`curl -o file`)或普通管道(`cat|grep`)不命中。
783
+ * 数据流判定(非共存判定),三条规则:
784
+ * 1. **管道链**:同一条 `|` 链上下载源在解释器上游 → 拦
785
+ * (`curl | sh`、`curl | /bin/bash`、`curl | env bash`、`curl | tee x | bash`)
786
+ * 2. **文件交接**:下载落盘(`curl -o f` / `curl -O` / `wget` 默认落盘 / `wget -O f` /
787
+ * `> f` 重定向 / 链下游 `tee f`)且同一命令串在下载之后执行同一文件(`bash f` /
788
+ * `python f` / `./f` / `source f` / `sh -c "./f"`)→ 拦(`curl -o s.sh … && bash s.sh`)
789
+ * 3. **嵌入注入**:下载源出现在解释器的内联载荷(`sh -c "$(curl …)"`)或进程替换
790
+ * (`bash <(curl …)`)里——下载文本直接进入解释器代码位 → 拦
791
+ *
792
+ * 仅共存不算数据流:`curl -o data.csv … && python analyze.py`、
793
+ * `bash build.sh && curl …`(解释器与下载无交接或顺序相反)不命中。
794
+ * 仅下载(`curl -o file` 无执行)或普通管道(`cat | grep`)不命中。
785
795
  */
786
796
  export function detectDownloadToInterpreter(command) {
787
797
  const parsed = parseShellCommand(command);
788
- if (!parsed.parsed || parsed.segments.length < 2)
798
+ if (!parsed.parsed || parsed.segments.length === 0)
799
+ return null;
800
+ const keys = parsed.segments.map((s) => resolveExecCommand(s).key);
801
+ // 单段命令无管道/交接形态,但内联载荷注入仍可能(`sh -c "curl x | sh"`)
802
+ const viaFlow = parsed.segments.length >= 2
803
+ ? detectDownloadPipeToInterpreter(parsed, keys) ?? detectDownloadFileHandoff(parsed)
804
+ : null;
805
+ return viaFlow ?? detectDownloadEmbeddedInjection(parsed);
806
+ }
807
+ /** 已知命令词(wrapper 剥离时优先认出真实命令,越过带值选项的值) */
808
+ const KNOWN_EXEC_BASES = new Set([...INTERPRETER_BASES, ...DOWNLOAD_BASES, 'tee', 'source', '.']);
809
+ /**
810
+ * 段的有效命令:剥 wrapper(sudo/env/nice/nohup/exec/xargs/time/timeout)。
811
+ * wrapper 后先找已知命令词(`sudo -u bob bash s.sh` 的 `bob` 是 -u 的值,不是命令),
812
+ * 找不到再退第一个非选项/非赋值/非纯数字参数。
813
+ */
814
+ function resolveExecCommand(seg) {
815
+ const key = cmdKey(seg.command);
816
+ if (!EXEC_WRAPPER_BASES.has(key))
817
+ return { key, args: seg.args, cmdArg: seg.command };
818
+ const knownIdx = seg.args.findIndex((a) => !a.includes('=') && KNOWN_EXEC_BASES.has(cmdKey(a)));
819
+ const nextIdx = knownIdx >= 0
820
+ ? knownIdx
821
+ : seg.args.findIndex((a) => !a.startsWith('-') && !a.includes('=') && !/^\d+$/.test(a));
822
+ if (nextIdx < 0)
823
+ return { key, args: seg.args, cmdArg: seg.command };
824
+ return {
825
+ key: cmdKey(seg.args[nextIdx]),
826
+ args: seg.args.slice(nextIdx + 1),
827
+ cmdArg: seg.args[nextIdx],
828
+ };
829
+ }
830
+ /** 规则 1:同管道链(连接符全为 `|` 的极大段组)内下载源在解释器上游 */
831
+ function detectDownloadPipeToInterpreter(parsed, keys) {
832
+ let start = 0;
833
+ for (let i = 0; i < parsed.segments.length; i++) {
834
+ const continues = i + 1 < parsed.segments.length && (parsed.connectors[i] ?? ';') === '|';
835
+ if (continues)
836
+ continue;
837
+ const dlIdx = keys.slice(start, i + 1).findIndex((k) => DOWNLOAD_BASES.has(k));
838
+ if (dlIdx >= 0) {
839
+ for (let j = start + dlIdx + 1; j <= i; j++) {
840
+ if (INTERPRETER_BASES.has(keys[j])) {
841
+ return 'download pipe to interpreter (remote code execution)';
842
+ }
843
+ }
844
+ }
845
+ start = i + 1;
846
+ }
847
+ return null;
848
+ }
849
+ /** URL basename(去 query/hash),`curl -O` 落盘名 */
850
+ function urlBasename(url) {
851
+ const path = url.replace(/[?#].*$/, '');
852
+ const base = path.split('/').pop() ?? '';
853
+ return base && base !== '/' ? base : null;
854
+ }
855
+ /**
856
+ * 同一文件判定:归一路径相等(大小写敏感)。
857
+ * 不做 basename 合并——跨目录/跨大小写是不同文件(`…/a/run.sh` 与 `…/b/run.sh`、
858
+ * `S.sh` 与 `s.sh` 在大小写敏感文件系统上不相交)。
859
+ */
860
+ function sameHandoffFile(a, b) {
861
+ return normalizeHandoffPath(a) === normalizeHandoffPath(b);
862
+ }
863
+ /** 归一路径(统一斜杠、剥 `./` 前缀;大小写保留) */
864
+ function normalizeHandoffPath(p) {
865
+ return p.replace(/\\/g, '/').replace(/^\.\//, '');
866
+ }
867
+ /** 直接执行脚本形态:`./s.sh` / `s.sh` / `/path/s.sh` */
868
+ function isScriptPath(cmd) {
869
+ return cmd.startsWith('./') || /\.(sh|bash|zsh|ksh|py|js|rb|pl|php|ps1|cmd|bat)$/i.test(cmd);
870
+ }
871
+ /**
872
+ * 规则 2:下载落盘文件(name = 落盘名;afterIdx = 落盘段索引,执行须在其后)。
873
+ * 选项解析覆盖短选项簇(`-sSLo f` / `-qO f` / `-of` 粘连值)与长选项别名
874
+ * (`--remote-name` / `--output=…`);wget 无输出选项时默认按 URL basename 落盘,
875
+ * wget 的 `-o` 是日志文件不算落盘,curl 的 `-O` 是无值选项(落盘名 = URL basename)。
876
+ */
877
+ function collectDownloadDrops(parsed) {
878
+ const drops = [];
879
+ for (let i = 0; i < parsed.segments.length; i++) {
880
+ const seg = parsed.segments[i];
881
+ const { key, args } = resolveExecCommand(seg);
882
+ if (!DOWNLOAD_BASES.has(key))
883
+ continue;
884
+ let outFileFlag = false; // 显式指定内容落盘文件(抑制 wget 默认落盘)
885
+ let remoteName = false; // curl -O / --remote-name:落盘名 = URL basename
886
+ let httpDownload = false; // httpie --download
887
+ for (let j = 0; j < args.length; j++) {
888
+ const a = args[j];
889
+ if (a === '--output' || a === '--output-document') {
890
+ const target = args[j + 1];
891
+ // `-O -` 是写 stdout,不落盘
892
+ if (target && target !== '-' && !target.startsWith('-')) {
893
+ drops.push({ name: target, afterIdx: i });
894
+ outFileFlag = true;
895
+ }
896
+ continue;
897
+ }
898
+ const eq = /^--output(?:-document)?=(.+)$/i.exec(a);
899
+ if (eq) {
900
+ if (eq[1] !== '-')
901
+ drops.push({ name: eq[1], afterIdx: i });
902
+ outFileFlag = true;
903
+ continue;
904
+ }
905
+ if (a === '--remote-name') {
906
+ remoteName = true;
907
+ continue;
908
+ }
909
+ if (a === '--download') {
910
+ httpDownload = true;
911
+ continue;
912
+ }
913
+ if (a.startsWith('--') || !a.startsWith('-') || a.length < 2 || a.includes('='))
914
+ continue;
915
+ // 短选项簇:`-sSLo f`(O 后取值)/ `-os.sh`(粘连值)/ `-OJ`(O 无值,J 另一选项)
916
+ for (let k = 1; k < a.length; k++) {
917
+ const c = a[k];
918
+ if (key === 'wget') {
919
+ if (c === 'O') {
920
+ // wget -O = 内容落盘文件(值可粘连/下一参数;`-O -` 写 stdout)
921
+ const value = a.slice(k + 1) || args[j + 1];
922
+ if (a.slice(k + 1))
923
+ k = a.length;
924
+ else
925
+ j += 1;
926
+ if (value && value !== '-' && !value.startsWith('-'))
927
+ drops.push({ name: value, afterIdx: i });
928
+ outFileFlag = true;
929
+ }
930
+ else if (c === 'o') {
931
+ // wget -o = 日志文件(不记内容落盘;消耗其值防止被误认)
932
+ if (a.slice(k + 1))
933
+ k = a.length;
934
+ else
935
+ j += 1;
936
+ }
937
+ }
938
+ else if (c === 'o') {
939
+ // curl/httpie -o = 内容落盘文件
940
+ const value = a.slice(k + 1) || args[j + 1];
941
+ if (a.slice(k + 1))
942
+ k = a.length;
943
+ else
944
+ j += 1;
945
+ if (value && value !== '-' && !value.startsWith('-'))
946
+ drops.push({ name: value, afterIdx: i });
947
+ outFileFlag = true;
948
+ }
949
+ else if (c === 'O') {
950
+ // curl -O = 无值选项,落盘名 = URL basename(下方统一记,多 -O 全记)
951
+ remoteName = true;
952
+ }
953
+ }
954
+ }
955
+ // URL basename 落盘:curl -O/--remote-name(段内全部 URL);httpie --download;
956
+ // wget 无输出选项时默认落盘(裸 `wget URL` 就是下载执行最常见写法)
957
+ const wantsUrlBasename = remoteName || httpDownload || (key === 'wget' && !outFileFlag);
958
+ if (wantsUrlBasename) {
959
+ for (const u of args) {
960
+ if (/^https?:\/\//i.test(u)) {
961
+ const base = urlBasename(u);
962
+ if (base)
963
+ drops.push({ name: base, afterIdx: i });
964
+ }
965
+ }
966
+ }
967
+ // 重定向落盘(`> f` / `>> f`)
968
+ for (const r of seg.redirects) {
969
+ if (r.type !== 'input')
970
+ drops.push({ name: r.target, afterIdx: i });
971
+ }
972
+ // 管道链下游 `tee f`:下载内容经 tee 落盘(`curl … | tee f | grep x && bash f`)
973
+ for (let j = i + 1; j < parsed.segments.length && (parsed.connectors[j - 1] ?? '|') === '|'; j++) {
974
+ const tee = resolveExecCommand(parsed.segments[j]);
975
+ if (tee.key === 'tee') {
976
+ for (const f of tee.args) {
977
+ if (!f.startsWith('-'))
978
+ drops.push({ name: f, afterIdx: j });
979
+ }
980
+ }
981
+ }
982
+ }
983
+ return drops;
984
+ }
985
+ /**
986
+ * 规则 2:脚本执行段。候选是解释器的**全部**非选项参数(带值选项的值多收,保守向:
987
+ * `bash -O extglob ./s.sh` 不漏 `./s.sh`);内联载荷(`sh -c "…"`)若是纯脚本路径
988
+ * (`sh -c "./s.sh"`、`cmd /c s.bat`)也算文件执行;`python -m mod` 是模块文件
989
+ * 执行(候选含 `mod` 与 `mod.py`);内联多词载荷不是文件执行(嵌入注入走规则 3)。
990
+ */
991
+ function collectScriptExecs(parsed) {
992
+ const execs = [];
993
+ for (let i = 0; i < parsed.segments.length; i++) {
994
+ const seg = parsed.segments[i];
995
+ const { key, args, cmdArg } = resolveExecCommand(seg);
996
+ if (key === 'source' || key === '.') {
997
+ const target = args[0];
998
+ if (target && !target.startsWith('-'))
999
+ execs.push({ name: target, idx: i });
1000
+ continue;
1001
+ }
1002
+ if (INTERPRETER_BASES.has(key)) {
1003
+ const inlineFlags = INTERPRETER_INLINE_FLAGS[key] ?? [];
1004
+ const firstArgIdx = args.findIndex((a) => !a.startsWith('-') && !a.includes('='));
1005
+ const preArgs = args.slice(0, firstArgIdx < 0 ? args.length : firstArgIdx);
1006
+ const inlineIdx = preArgs.findIndex((a) => inlineFlags.includes(a.toLowerCase()));
1007
+ if (inlineIdx >= 0) {
1008
+ const payload = args.slice(inlineIdx + 1).join(' ').trim();
1009
+ if (payload && (isScriptPath(payload) || payload.startsWith('./'))) {
1010
+ execs.push({ name: payload, idx: i });
1011
+ }
1012
+ continue;
1013
+ }
1014
+ for (const a of args) {
1015
+ if (!a.startsWith('-') && !a.includes('=') && !/^\d+$/.test(a)) {
1016
+ execs.push({ name: a, idx: i });
1017
+ }
1018
+ }
1019
+ // `python -m mod` 模块执行:模块主文件是 `mod.py`
1020
+ for (let j = 0; j < args.length - 1; j++) {
1021
+ if (args[j].toLowerCase() === '-m') {
1022
+ execs.push({ name: `${args[j + 1]}.py`, idx: i });
1023
+ }
1024
+ }
1025
+ // stdin 交接(`bash < s.sh`):输入重定向的文件也是执行对象
1026
+ for (const r of seg.redirects) {
1027
+ if (r.type === 'input')
1028
+ execs.push({ name: r.target, idx: i });
1029
+ }
1030
+ continue;
1031
+ }
1032
+ if (isScriptPath(cmdArg)) {
1033
+ execs.push({ name: cmdArg, idx: i });
1034
+ }
1035
+ }
1036
+ return execs;
1037
+ }
1038
+ /** 规则 2:下载落盘文件在下载之后被同一命令串执行 */
1039
+ function detectDownloadFileHandoff(parsed) {
1040
+ const drops = collectDownloadDrops(parsed);
1041
+ if (drops.length === 0)
1042
+ return null;
1043
+ for (const e of collectScriptExecs(parsed)) {
1044
+ for (const d of drops) {
1045
+ if (e.idx > d.afterIdx && sameHandoffFile(e.name, d.name)) {
1046
+ return 'downloaded file executed (remote code execution)';
1047
+ }
1048
+ }
1049
+ }
1050
+ return null;
1051
+ }
1052
+ /** 文本中出现下载源命令(词边界,防 `mycurl` 之类误报) */
1053
+ function hasDownloadSource(text) {
1054
+ return /(^|[\s|;&($<])((sudo|env|nice|nohup|exec|timeout)\s+)*(curl|wget|http|https)\b/i.test(text);
1055
+ }
1056
+ /**
1057
+ * 规则 3:下载源进入解释器代码位——内联载荷(`sh -c "$(curl …)"`)或进程替换
1058
+ * (`bash <(curl …)`)里的下载文本直接成为解释器的代码/输入文件。
1059
+ * 内联载荷内的 shell 文本另递归跑规则 1/2(`bash -c "curl x | sh"`)。
1060
+ */
1061
+ function detectDownloadEmbeddedInjection(parsed) {
1062
+ const hasDownload = parsed.segments.some((s) => DOWNLOAD_BASES.has(resolveExecCommand(s).key) || hasDownloadSource(s.raw));
1063
+ if (!hasDownload)
789
1064
  return null;
790
- let hasDownload = false;
791
- let hasInterpreter = false;
792
1065
  for (const seg of parsed.segments) {
793
- // 包装链:env / nice / xargs 后的真实命令
794
- let key = cmdKey(seg.command);
795
- if (EXEC_WRAPPER_BASES.has(key) && seg.args.length > 0) {
796
- const next = seg.args.find((a) => !a.startsWith('-') && !a.includes('='));
797
- if (next)
798
- key = cmdKey(next);
799
- }
800
- if (DOWNLOAD_BASES.has(key))
801
- hasDownload = true;
802
- if (INTERPRETER_BASES.has(key))
803
- hasInterpreter = true;
804
- }
805
- if (hasDownload && hasInterpreter) {
806
- return 'download pipe to interpreter (remote code execution)';
1066
+ const { key, args } = resolveExecCommand(seg);
1067
+ if (!INTERPRETER_BASES.has(key) && key !== 'source' && key !== '.')
1068
+ continue;
1069
+ const inlineFlags = INTERPRETER_INLINE_FLAGS[key] ?? [];
1070
+ const firstArgIdx = args.findIndex((a) => !a.startsWith('-') && !a.includes('='));
1071
+ const preArgs = args.slice(0, firstArgIdx < 0 ? args.length : firstArgIdx);
1072
+ const inlineIdx = preArgs.findIndex((a) => inlineFlags.includes(a.toLowerCase()));
1073
+ if (inlineIdx >= 0) {
1074
+ const payload = args.slice(inlineIdx + 1).join(' ').trim();
1075
+ if (!payload)
1076
+ continue;
1077
+ // 载荷是 shell 文本:内层 `curl x | sh` 走规则 1/2 递归
1078
+ const inner = detectDownloadToInterpreter(payload);
1079
+ if (inner)
1080
+ return inner;
1081
+ // 命令替换/进程替换把下载文本拼进代码位(`sh -c "$(curl x)"`)
1082
+ if (/\$\(|<\(|>\(/.test(payload) && hasDownloadSource(payload)) {
1083
+ return 'download injected into interpreter payload (remote code execution)';
1084
+ }
1085
+ continue;
1086
+ }
1087
+ // 进程替换参数(`bash <(curl …)`):下载文本成为解释器的输入文件
1088
+ for (const a of args) {
1089
+ if (/[<>]\(/.test(a) && hasDownloadSource(a)) {
1090
+ return 'download injected into interpreter process substitution (remote code execution)';
1091
+ }
1092
+ }
807
1093
  }
808
1094
  return null;
809
1095
  }
@@ -130,7 +130,7 @@ function extract(node, ctx, spanNode) {
130
130
  if (child.type === 'file_redirect') {
131
131
  const redirect = mapFileRedirect(child);
132
132
  if (redirect)
133
- redirects.push(redirect);
133
+ redirects.push({ redirect, start: child.startIndex });
134
134
  // 重定向目标里的命令替换仍会执行
135
135
  extract(child, ctx, null);
136
136
  }
@@ -149,12 +149,20 @@ function extract(node, ctx, spanNode) {
149
149
  extract(body, ctx, node);
150
150
  if (redirects.length > 0) {
151
151
  if (ctx.segments.length > before) {
152
- // 整句重定向挂在句内第一个命令段上(目标风险由重定向目标评估兜底)
153
- ctx.segments[before].seg.redirects.push(...redirects);
152
+ // 整句重定向按源位置归属:作用于其之前最近(end 最大)的命令段——
153
+ // `A && B < f` 归 B、`A < f && B` 归 A(tree-sitter 把链式重定向解析为
154
+ // 整句包装,源位置是唯一的作用域线索;嵌套命令替换段 end 更早,自然落选)
155
+ for (const entry of redirects) {
156
+ const candidates = ctx.segments.filter((s) => s.end <= entry.start);
157
+ const owner = candidates.length
158
+ ? candidates.reduce((a, b) => (a.end >= b.end ? a : b))
159
+ : ctx.segments[before];
160
+ owner.seg.redirects.push(entry.redirect);
161
+ }
154
162
  }
155
163
  else {
156
164
  // 句内无命令(`> file` 单独成句):目标仍可能是写入,不可丢
157
- ctx.orphans.push(...redirects);
165
+ ctx.orphans.push(...redirects.map((entry) => entry.redirect));
158
166
  }
159
167
  }
160
168
  return;
@@ -78,4 +78,5 @@ export declare function isToolAllowedByRights(toolName: string, capabilities: re
78
78
  export declare function isToolPermitted(toolName: string, capabilities: readonly string[] | null | undefined, layers: Array<ToolRights | {
79
79
  allow?: string[];
80
80
  deny?: string[];
81
+ denyCapabilities?: string[];
81
82
  } | undefined>): boolean;
@@ -33,7 +33,7 @@ export { JSON_CHARS_PER_TOKEN, TOOL_RESULT_CHARS_PER_TOKEN, CHARS_PER_TOKEN, } f
33
33
  export { DefaultMessageSelector } from './context/message-selector.js';
34
34
  export { DefaultBudgetAllocator } from './context/budget-allocator.js';
35
35
  export { LAYER_ORDER, LAYER_PRIORITY, LAYER_DEFAULT_SHARE, extractLayerQuery, hasLayerText, DefaultContextAssembler, truncateTextToTokens, ALL_LAYER_IDS, buildContextLayersSnapshot, deriveLayerStatus, emptyContextLayersSnapshot, probeContextLayerHealth, probeAgentHomeHealth, PersonaLayer, SkillLayer, RuntimeLayer, KnowledgeLayer, MemoryLayer, CognitionLayer, WisdomLayer, createDefaultLayers, createProviderSummarize, pickSummarizeProvider, createDefaultSystemPromptAssembler, } from './context/index.js';
36
- export type { ContextLayerId, LayerAssembleContext, LayerContent, ContextLayer, LayerManifestEntry, AssembleManifest, SystemAssembleResult, ContextAssembler, ContextAssembleParams, DefaultContextAssemblerConfig, CreateDefaultLayersOptions, CreateProviderSummarizeOptions, SystemPromptAssembleInput, SystemPromptAssembleOutput, ContextLayersSnapshot, LayerRuntimeView, LayerUiStatus, ContextLayerHealth, ContextLayerHealthEntry, ProbeContextHealthDeps, ContextCompactReason, ContextCompactEvent, ContextEmitFn, ContextCompactSnapshot, } from './context/index.js';
36
+ export type { ContextLayerId, LayerAssembleContext, LayerContent, ContextLayer, LayerManifestEntry, AssembleManifest, SystemAssembleResult, ContextAssembler, ContextAssembleParams, DefaultContextAssemblerConfig, CreateDefaultLayersOptions, CreateProviderSummarizeOptions, SystemPromptAssembleInput, SystemPromptAssembleOutput, ContextLayersSnapshot, LayerRuntimeView, LayerUiStatus, ContextLayerHealth, ContextLayerHealthEntry, ProbeContextHealthDeps, ContextCompactReason, ContextCompactEvent, ContextEmitFn, ContextSizeSnapshot, ContextCompactSnapshot, } from './context/index.js';
37
37
  export { CapabilityEnforcer, PluginTrustLevel } from './governance/security/capability-enforcer.js';
38
38
  export { runAgentWithReliability, DEFAULT_RELIABILITY_CONFIG } from './run/reliability/index.js';
39
39
  export type { ReliabilityConfig, ConcreteReliabilityHarness } from './run/reliability/index.js';
@@ -43,7 +43,8 @@ export { CircuitBreaker } from './run/reliability/circuit-breaker.js';
43
43
  export { wrapProviderWithCircuitBreaker } from './run/reliability/provider-wrapper.js';
44
44
  export { FallbackProvider } from './run/reliability/fallback-provider.js';
45
45
  export { guardRefusalProvider } from './run/reliability/refusal-guard.js';
46
- export { detectSummaryContamination } from './context/capabilities/compact/engine.js';
46
+ export { detectSummaryContamination, inspectSummaryOutput, evaluateEcho, } from './context/capabilities/compact/engine.js';
47
+ export type { ContaminationResult, EchoVerdict } from './context/capabilities/compact/engine.js';
47
48
  export { PluginManager } from './extension/plugin-ecosystem/plugins/manager.js';
48
49
  export { definePlugin } from './extension/plugin-ecosystem/plugins/entry.js';
49
50
  export type { OctopiPluginDefinition } from './extension/plugin-ecosystem/plugins/entry.js';
@@ -105,7 +106,8 @@ export { createEmbeddingProviderFromModels, resolveEmbeddingRuntime, isEmbedding
105
106
  export type { MemoryType, MemoryEntry, MemoryQuery, MemoryStats, MemoryStore } from './memory/types.js';
106
107
  export type { WisdomEntry, WisdomStore, WisdomStatus, WisdomOrigin, WisdomKind, WisdomScenario, WisdomEffect, WisdomDerivation, WisdomOutcomes, AdmitWisdomInput, AdmitWisdomResult, WisdomInjectQuery, WisdomInjectPick, WisdomStats, } from './memory/types.js';
107
108
  export type { ConceptKind, ConceptRelationType, ConceptStatus, EvidenceClass, EdgeBasis, ConceptNode, ConceptEdge, ConceptGraph, MergeCandidate, AdmitConceptInput, AdmitConceptResult, AdmitEdgeInput, AdmitEdgeResult, ConceptGateReason, SpreadingActivateOptions, ActivatedGraph, ConceptGraphStats, DecayResult, ConceptGraphStore, } from './memory/types.js';
108
- export { evaluateConceptGate, licenseEdge, conceptualizeAndAdmit, parseConceptualizerJson, DEFAULT_EDGE_DECAY_PER_DAY, hebbianStrengthen, nextEdgeStrength, } from './memory/index.js';
109
+ export { evaluateConceptGate, licenseEdge, conceptualizeAndAdmit, parseConceptualizerJson, DEFAULT_EDGE_DECAY_PER_DAY, hebbianStrengthen, nextEdgeStrength, normName, deriveQuerySeeds, createSeedMatcher, } from './memory/index.js';
110
+ export type { DeriveQuerySeedsOptions, SeedMatcher } from './memory/index.js';
109
111
  export type { Planner, Reflector, AgentState, AgentStats, Plan, PlanStep, StepResult, ExecutionRecord, Assessment, Pattern, } from './collaboration/orchestration/cognitive-loop.js';
110
112
  export type { SessionData, SessionLifecycleMeta, SessionLifecycleStatus, MemoryExtractionStatus } from './session/types.js';
111
113
  export { SessionAwareRunner } from './run/runner.js';
@@ -35,7 +35,7 @@ export { CircuitBreaker } from './run/reliability/circuit-breaker.js';
35
35
  export { wrapProviderWithCircuitBreaker } from './run/reliability/provider-wrapper.js';
36
36
  export { FallbackProvider } from './run/reliability/fallback-provider.js';
37
37
  export { guardRefusalProvider } from './run/reliability/refusal-guard.js';
38
- export { detectSummaryContamination } from './context/capabilities/compact/engine.js';
38
+ export { detectSummaryContamination, inspectSummaryOutput, evaluateEcho, } from './context/capabilities/compact/engine.js';
39
39
  // ── Plugin Ecosystem ──
40
40
  export { PluginManager } from './extension/plugin-ecosystem/plugins/manager.js';
41
41
  export { definePlugin } from './extension/plugin-ecosystem/plugins/entry.js';
@@ -79,7 +79,7 @@ export { KnowledgeDatabase, KnowledgeSourceStore, KnowledgeIndexStore, Knowledge
79
79
  // ── Memory ──
80
80
  export { InMemoryMemoryStore, InMemoryWisdomStore, InMemoryConceptGraph, AgentDatabase, SqliteMemoryStore, SqliteWisdomStore, SqliteConceptGraph, createEmbeddingProvider } from './memory/index.js';
81
81
  export { createEmbeddingProviderFromModels, resolveEmbeddingRuntime, isEmbeddingEnabled, tokenizeKeywordQuery, scoreKeywordFields, } from './memory/index.js';
82
- export { evaluateConceptGate, licenseEdge, conceptualizeAndAdmit, parseConceptualizerJson, DEFAULT_EDGE_DECAY_PER_DAY, hebbianStrengthen, nextEdgeStrength, } from './memory/index.js';
82
+ export { evaluateConceptGate, licenseEdge, conceptualizeAndAdmit, parseConceptualizerJson, DEFAULT_EDGE_DECAY_PER_DAY, hebbianStrengthen, nextEdgeStrength, normName, deriveQuerySeeds, createSeedMatcher, } from './memory/index.js';
83
83
  // ── Runner ──
84
84
  export { SessionAwareRunner } from './run/runner.js';
85
85
  // ── Tool effect isolation (I5) ──
@@ -40,6 +40,8 @@ export interface KnowledgeBootRetriever {
40
40
  }
41
41
  /** boot 文件里的调参块 */
42
42
  export interface KnowledgeBootTuning {
43
+ /** 跨租户共享闸(B-5):knowledge.projects.allowPublic,缺省 false=禁止创建 visibility='public' 项目 */
44
+ allowPublic?: boolean;
43
45
  embed?: KnowledgeBootEmbed;
44
46
  ingest?: KnowledgeBootIngest;
45
47
  retriever?: KnowledgeBootRetriever;
@@ -46,5 +46,7 @@ export function knowledgeTuningFromConfig(kn) {
46
46
  tuning.retriever = retriever;
47
47
  if (kn.catalog?.autoDescribe !== undefined)
48
48
  tuning.autoDescribe = kn.catalog.autoDescribe;
49
+ if (kn.projects?.allowPublic !== undefined)
50
+ tuning.allowPublic = kn.projects.allowPublic;
49
51
  return tuning;
50
52
  }