@octopi-agent/engine 0.102.10 → 0.121.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 (317) 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/discover.d.ts +33 -4
  5. package/dist/config-admin/discover.js +101 -6
  6. package/dist/config-admin/env.d.ts +11 -0
  7. package/dist/config-admin/env.js +41 -0
  8. package/dist/config-admin/error-copy.d.ts +106 -0
  9. package/dist/config-admin/error-copy.js +287 -0
  10. package/dist/config-admin/i18n.d.ts +21 -0
  11. package/dist/config-admin/i18n.js +19 -0
  12. package/dist/config-admin/index.d.ts +6 -2
  13. package/dist/config-admin/index.js +3 -1
  14. package/dist/config-admin/model-presets.d.ts +14 -0
  15. package/dist/config-admin/model-presets.js +595 -70
  16. package/dist/config-admin/onboarding-apply.d.ts +71 -0
  17. package/dist/config-admin/onboarding-apply.js +235 -0
  18. package/dist/config-admin/onboarding.d.ts +154 -0
  19. package/dist/config-admin/onboarding.js +270 -0
  20. package/dist/config-admin/redact.d.ts +42 -9
  21. package/dist/config-admin/redact.js +69 -5
  22. package/dist/config-schema/agent.d.ts +5 -1
  23. package/dist/config-schema/agent.js +20 -2
  24. package/dist/config-schema/browser.d.ts +62 -0
  25. package/dist/config-schema/browser.js +89 -0
  26. package/dist/config-schema/context.d.ts +7 -2
  27. package/dist/config-schema/context.js +6 -3
  28. package/dist/config-schema/engine.d.ts +86 -7
  29. package/dist/config-schema/engine.js +9 -2
  30. package/dist/config-schema/governance.d.ts +12 -1
  31. package/dist/config-schema/governance.js +10 -2
  32. package/dist/config-schema/models.d.ts +12 -8
  33. package/dist/config-schema/models.js +16 -1
  34. package/dist/config-schema/run.d.ts +4 -0
  35. package/dist/config-schema/run.js +10 -0
  36. package/dist/config-schema/shared.d.ts +1 -0
  37. package/dist/config-schema/shared.js +4 -2
  38. package/dist/config-schema/substrate.d.ts +5 -0
  39. package/dist/config-schema/substrate.js +8 -0
  40. package/dist/config.d.ts +116 -10
  41. package/dist/config.js +109 -13
  42. package/dist/file-mode.d.ts +67 -0
  43. package/dist/file-mode.js +182 -0
  44. package/dist/fork-child.d.ts +82 -0
  45. package/dist/fork-child.js +123 -0
  46. package/dist/harness/activation/delegated-run.d.ts +42 -0
  47. package/dist/harness/activation/delegated-run.js +71 -0
  48. package/dist/harness/activation/dispatcher.js +4 -0
  49. package/dist/harness/activation/index.d.ts +1 -0
  50. package/dist/harness/activation/run-backend.d.ts +92 -0
  51. package/dist/harness/activation/run-backend.js +16 -0
  52. package/dist/harness/activation/run-protocol.d.ts +392 -0
  53. package/dist/harness/activation/run-protocol.js +19 -0
  54. package/dist/harness/activation/runtime.d.ts +33 -0
  55. package/dist/harness/activation/runtime.js +119 -28
  56. package/dist/harness/activation/types.d.ts +19 -2
  57. package/dist/harness/agent/builder.d.ts +12 -0
  58. package/dist/harness/agent/builder.js +78 -22
  59. package/dist/harness/agent/config-bridge.d.ts +10 -1
  60. package/dist/harness/agent/config-bridge.js +15 -3
  61. package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
  62. package/dist/harness/agent/registered-tool-adapter.js +67 -0
  63. package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
  64. package/dist/harness/agent/wire-agent-builder.js +9 -2
  65. package/dist/harness/capabilities/document/backends/plain.js +2 -1
  66. package/dist/harness/capabilities/document/legacy/factory.js +3 -2
  67. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
  68. package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
  69. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
  70. package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
  71. package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
  72. package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
  73. package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
  74. package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
  75. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
  76. package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
  77. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
  78. package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
  79. package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
  80. package/dist/harness/collaboration/delegation/child-run.js +34 -2
  81. package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
  82. package/dist/harness/collaboration/delegation/service.d.ts +9 -4
  83. package/dist/harness/collaboration/delegation/service.js +33 -12
  84. package/dist/harness/collaboration/delegation/store.d.ts +2 -0
  85. package/dist/harness/collaboration/delegation/store.js +1 -0
  86. package/dist/harness/collaboration/delegation/types.d.ts +11 -0
  87. package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
  88. package/dist/harness/collaboration/delegation/wiring.js +1 -0
  89. package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
  90. package/dist/harness/context/capabilities/compact/engine.js +127 -39
  91. package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
  92. package/dist/harness/context/capabilities/compact/index.js +1 -1
  93. package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
  94. package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
  95. package/dist/harness/context/capabilities/summary/gate.js +53 -6
  96. package/dist/harness/context/capabilities/summary/registry.js +20 -0
  97. package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
  98. package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
  99. package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
  100. package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
  101. package/dist/harness/context/constitution/default-agents.md +85 -0
  102. package/dist/harness/context/context-size-ledger.js +8 -1
  103. package/dist/harness/context/default-context-engine.d.ts +100 -6
  104. package/dist/harness/context/default-context-engine.js +382 -89
  105. package/dist/harness/context/index.d.ts +2 -1
  106. package/dist/harness/context/index.js +1 -0
  107. package/dist/harness/context/layer-health.d.ts +4 -0
  108. package/dist/harness/context/layer-health.js +4 -0
  109. package/dist/harness/context/layer-types.d.ts +57 -0
  110. package/dist/harness/context/layer-types.js +73 -1
  111. package/dist/harness/context/layers.d.ts +3 -0
  112. package/dist/harness/context/layers.js +13 -6
  113. package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
  114. package/dist/harness/context/prefix-fingerprint.js +52 -0
  115. package/dist/harness/context/summarize.js +18 -0
  116. package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
  117. package/dist/harness/context/system-prompt-assembler.js +5 -2
  118. package/dist/harness/context/tool-result-aging.d.ts +104 -16
  119. package/dist/harness/context/tool-result-aging.js +211 -57
  120. package/dist/harness/context/types.d.ts +71 -4
  121. package/dist/harness/context/types.js +25 -1
  122. package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
  123. package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
  124. package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
  125. package/dist/harness/extension/execution-environment/workspace.js +1 -1
  126. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
  127. package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
  128. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
  129. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
  130. package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
  131. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  132. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  133. package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
  134. package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
  135. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
  136. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
  137. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
  138. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
  139. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
  140. package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
  141. package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
  142. package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
  143. package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
  144. package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
  145. package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
  146. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
  147. package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
  148. package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
  149. package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
  150. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
  151. package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
  152. package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
  153. package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
  154. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
  155. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
  156. package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
  157. package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
  158. package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
  159. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
  160. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
  161. package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
  162. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
  163. package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
  164. package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
  165. package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
  166. package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
  167. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
  168. package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
  169. package/dist/harness/governance/credentials/db.d.ts +9 -0
  170. package/dist/harness/governance/credentials/db.js +122 -31
  171. package/dist/harness/governance/credentials/store.d.ts +68 -7
  172. package/dist/harness/governance/credentials/store.js +177 -64
  173. package/dist/harness/governance/credentials/types.d.ts +13 -2
  174. package/dist/harness/governance/index.d.ts +1 -0
  175. package/dist/harness/governance/index.js +1 -0
  176. package/dist/harness/governance/registry/db.d.ts +32 -0
  177. package/dist/harness/governance/registry/db.js +142 -0
  178. package/dist/harness/governance/registry/index.d.ts +9 -0
  179. package/dist/harness/governance/registry/index.js +9 -0
  180. package/dist/harness/governance/registry/service.d.ts +381 -0
  181. package/dist/harness/governance/registry/service.js +825 -0
  182. package/dist/harness/governance/registry/types.d.ts +77 -0
  183. package/dist/harness/governance/registry/types.js +7 -0
  184. package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
  185. package/dist/harness/governance/security/default-security-guard.js +12 -1
  186. package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
  187. package/dist/harness/governance/security/risk-evaluator.js +307 -21
  188. package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
  189. package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
  190. package/dist/harness/index.d.ts +5 -3
  191. package/dist/harness/index.js +2 -2
  192. package/dist/harness/knowledge/boot-config.d.ts +2 -0
  193. package/dist/harness/knowledge/boot-config.js +2 -0
  194. package/dist/harness/knowledge/client.d.ts +53 -7
  195. package/dist/harness/knowledge/client.js +77 -20
  196. package/dist/harness/knowledge/db.d.ts +16 -0
  197. package/dist/harness/knowledge/db.js +107 -41
  198. package/dist/harness/knowledge/engine-thread.js +5 -7
  199. package/dist/harness/knowledge/grounding.js +4 -1
  200. package/dist/harness/knowledge/http-app.d.ts +15 -0
  201. package/dist/harness/knowledge/http-app.js +82 -21
  202. package/dist/harness/knowledge/http-bridge.d.ts +15 -0
  203. package/dist/harness/knowledge/http-bridge.js +19 -0
  204. package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
  205. package/dist/harness/knowledge/query-service.d.ts +12 -2
  206. package/dist/harness/knowledge/query-service.js +75 -41
  207. package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
  208. package/dist/harness/knowledge/query-worker-client.js +4 -1
  209. package/dist/harness/knowledge/query-worker.js +5 -3
  210. package/dist/harness/knowledge/read-http.d.ts +2 -0
  211. package/dist/harness/knowledge/read-http.js +9 -2
  212. package/dist/harness/knowledge/retriever.d.ts +1 -1
  213. package/dist/harness/knowledge/retriever.js +1 -2
  214. package/dist/harness/knowledge/serve.d.ts +6 -1
  215. package/dist/harness/knowledge/serve.js +5 -6
  216. package/dist/harness/knowledge/source-store.d.ts +101 -5
  217. package/dist/harness/knowledge/source-store.js +297 -71
  218. package/dist/harness/knowledge/start-service-process.d.ts +27 -8
  219. package/dist/harness/knowledge/start-service-process.js +49 -90
  220. package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
  221. package/dist/harness/knowledge/tenant-gate.js +167 -0
  222. package/dist/harness/knowledge/writer-service.d.ts +18 -2
  223. package/dist/harness/knowledge/writer-service.js +80 -16
  224. package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
  225. package/dist/harness/knowledge/writer-worker-client.js +20 -3
  226. package/dist/harness/knowledge/writer-worker.js +11 -4
  227. package/dist/harness/memory/backfill-trigger.d.ts +10 -3
  228. package/dist/harness/memory/backfill-trigger.js +19 -19
  229. package/dist/harness/memory/cognition-seeds.d.ts +45 -0
  230. package/dist/harness/memory/cognition-seeds.js +67 -0
  231. package/dist/harness/memory/cognition.d.ts +12 -3
  232. package/dist/harness/memory/cognition.js +55 -35
  233. package/dist/harness/memory/conceptualizer.d.ts +11 -1
  234. package/dist/harness/memory/conceptualizer.js +10 -1
  235. package/dist/harness/memory/context-slice.d.ts +42 -0
  236. package/dist/harness/memory/context-slice.js +197 -0
  237. package/dist/harness/memory/health-probe.d.ts +8 -2
  238. package/dist/harness/memory/health-probe.js +10 -13
  239. package/dist/harness/memory/index.d.ts +5 -1
  240. package/dist/harness/memory/index.js +3 -1
  241. package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
  242. package/dist/harness/memory/sqlite/agent-db.js +9 -8
  243. package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
  244. package/dist/harness/memory/sqlite/cognition-store.js +103 -45
  245. package/dist/harness/memory/sqlite/memory-store.js +4 -0
  246. package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
  247. package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
  248. package/dist/harness/memory/types.d.ts +18 -2
  249. package/dist/harness/observability/observer/hub.d.ts +10 -0
  250. package/dist/harness/observability/observer/hub.js +95 -2
  251. package/dist/harness/run/agent/agent.js +3 -2
  252. package/dist/harness/run/concurrency/tool-validator.js +4 -3
  253. package/dist/harness/run/reliability/run-agent.d.ts +22 -0
  254. package/dist/harness/run/reliability/run-agent.js +79 -10
  255. package/dist/harness/run/run-host.d.ts +302 -0
  256. package/dist/harness/run/run-host.js +978 -0
  257. package/dist/harness/run/run-scope.d.ts +11 -0
  258. package/dist/harness/run/run-scope.js +19 -1
  259. package/dist/harness/run/runner.d.ts +149 -22
  260. package/dist/harness/run/runner.js +352 -35
  261. package/dist/harness/session/in-memory-store.js +13 -1
  262. package/dist/harness/session/schedules/service.d.ts +10 -2
  263. package/dist/harness/session/schedules/service.js +13 -2
  264. package/dist/harness/session/tasks/tools.js +12 -0
  265. package/dist/harness/session/types.d.ts +10 -14
  266. package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
  267. package/dist/harness/shared/types/agent-definition.d.ts +6 -0
  268. package/dist/index.d.ts +3 -2
  269. package/dist/index.js +2 -1
  270. package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
  271. package/dist/integration/agent-runtime/channel-message-source.js +4 -3
  272. package/dist/integration/browser/camoufox.d.ts +40 -0
  273. package/dist/integration/browser/camoufox.js +80 -0
  274. package/dist/integration/browser/index.d.ts +91 -0
  275. package/dist/integration/browser/index.js +110 -0
  276. package/dist/integration/browser/install.d.ts +47 -0
  277. package/dist/integration/browser/install.js +214 -0
  278. package/dist/integration/browser/playwright.d.ts +224 -0
  279. package/dist/integration/browser/playwright.js +925 -0
  280. package/dist/integration/browser/service.d.ts +41 -0
  281. package/dist/integration/browser/service.js +181 -0
  282. package/dist/integration/browser/stealth.d.ts +42 -0
  283. package/dist/integration/browser/stealth.js +104 -0
  284. package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
  285. package/dist/integration/providers/anthropic-message-normalize.js +48 -0
  286. package/dist/integration/providers/anthropic.js +27 -2
  287. package/dist/integration/providers/fetch-timeout.d.ts +17 -0
  288. package/dist/integration/providers/fetch-timeout.js +24 -0
  289. package/dist/integration/providers/openai.d.ts +8 -0
  290. package/dist/integration/providers/openai.js +41 -1
  291. package/dist/integration/providers/wire-dump-diff.js +2 -1
  292. package/dist/integration/providers/wire-dump.d.ts +56 -2
  293. package/dist/integration/providers/wire-dump.js +119 -6
  294. package/dist/integration/storage/archive-manager.d.ts +14 -2
  295. package/dist/integration/storage/archive-manager.js +24 -8
  296. package/dist/integration/storage/atomic-tmp.d.ts +12 -0
  297. package/dist/integration/storage/atomic-tmp.js +36 -0
  298. package/dist/integration/storage/jsonl.d.ts +9 -0
  299. package/dist/integration/storage/jsonl.js +137 -38
  300. package/dist/integration/storage/session-index.d.ts +5 -0
  301. package/dist/integration/storage/session-index.js +25 -4
  302. package/dist/integration/tools/assemble.d.ts +50 -0
  303. package/dist/integration/tools/assemble.js +137 -0
  304. package/dist/paths.d.ts +18 -0
  305. package/dist/paths.js +36 -0
  306. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
  307. package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
  308. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
  309. package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
  310. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
  311. package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
  312. package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
  313. package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
  314. package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
  315. package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
  316. package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
  317. package/package.json +5 -3
@@ -1,5 +1,6 @@
1
- import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';
1
+ import { readFileSync, existsSync, readdirSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
3
4
  export class AuditReader {
4
5
  auditDir;
5
6
  constructor(config) {
@@ -7,7 +8,7 @@ export class AuditReader {
7
8
  }
8
9
  query(filter) {
9
10
  const results = [];
10
- const searchDirs = this.getSearchDirs(filter?.agentId, filter?.subsystemId);
11
+ const searchDirs = this.getSearchDirs(filter?.tenantId, filter?.agentId, filter?.subsystemId);
11
12
  for (const dir of searchDirs) {
12
13
  if (!existsSync(dir))
13
14
  continue;
@@ -20,6 +21,9 @@ export class AuditReader {
20
21
  for (const line of lines) {
21
22
  try {
22
23
  const run = JSON.parse(line);
24
+ // 旧布局记录缺 tenantId 视作 DEFAULT(读端统一补齐查询语义)
25
+ if (filter?.tenantId && (run.tenantId ?? DEFAULT_TENANT_ID) !== filter.tenantId)
26
+ continue;
23
27
  if (filter?.status && run.status !== filter.status)
24
28
  continue;
25
29
  if (filter?.since && run.timestamp < filter.since)
@@ -42,42 +46,68 @@ export class AuditReader {
42
46
  }
43
47
  return results;
44
48
  }
45
- getSearchDirs(agentId, subsystemId) {
46
- if (agentId && subsystemId) {
47
- return [join(this.auditDir, agentId, subsystemId)];
48
- }
49
- if (agentId) {
50
- const agentDir = join(this.auditDir, agentId);
51
- if (!existsSync(agentDir))
52
- return [];
53
- return readdirSync(agentDir)
54
- .filter((d) => !d.startsWith('.'))
55
- .map((d) => join(agentDir, d));
56
- }
57
- if (subsystemId) {
58
- // 两种可能的路径:
59
- // 1. auditDir/subsystemId/(无 agentId 分区)
60
- // 2. auditDir/*/subsystemId/(有 agentId 分区)
61
- const dirs = [];
62
- const directDir = join(this.auditDir, subsystemId);
63
- if (existsSync(directDir) && statSync(directDir).isDirectory()) {
64
- dirs.push(directDir);
49
+ /**
50
+ * 检索目录解析:**双布局兼容**(MAJ-6,2026-11-13 评审)。
51
+ *
52
+ * - 新布局(三段式):`{tenantId}/[{agentId}/]{subsystemId}/`——writer 恒按记录租户分区;
53
+ * - legacy(旧两段):`[{agentId}/]{subsystemId}/`(升级前数据,租户视作 DEFAULT)。
54
+ *
55
+ * 叶子分类按段数 + 各解释逐一匹配查询(2 段同时尝试 (tenant,subsystem) 与
56
+ * (agent,subsystem) 两种解释,任一命中即收)。不做模糊 includes 匹配——租户名
57
+ * 与 agent 名可重合,位置语义才是准的。
58
+ */
59
+ getSearchDirs(tenantId, agentId, subsystemId) {
60
+ const out = [];
61
+ const walk = (dir, parts) => {
62
+ if (!existsSync(dir))
63
+ return;
64
+ const entries = readdirSync(dir, { withFileTypes: true });
65
+ const hasJsonl = entries.some((e) => e.isFile() && e.name.endsWith('.jsonl'));
66
+ if (hasJsonl && this.partsMatch(parts, tenantId, agentId, subsystemId)) {
67
+ out.push(dir);
65
68
  }
66
- if (existsSync(this.auditDir)) {
67
- for (const entry of readdirSync(this.auditDir, { withFileTypes: true })) {
68
- if (entry.isDirectory() && entry.name !== subsystemId) {
69
- const subDir = join(this.auditDir, entry.name, subsystemId);
70
- if (existsSync(subDir))
71
- dirs.push(subDir);
72
- }
73
- }
69
+ if (parts.length >= 3)
70
+ return;
71
+ for (const e of entries) {
72
+ if (e.isDirectory())
73
+ walk(join(dir, e.name), [...parts, e.name]);
74
74
  }
75
- return dirs;
75
+ };
76
+ walk(this.auditDir, []);
77
+ return out;
78
+ }
79
+ /** 叶子路径段对查询的双解释匹配(见 getSearchDirs) */
80
+ partsMatch(parts, tenantId, agentId, subsystemId) {
81
+ if (parts.length === 3) {
82
+ const [t, a, sub] = parts;
83
+ return matches(tenantId, t) && matches(agentId, a) && matches(subsystemId, sub);
84
+ }
85
+ if (parts.length === 2) {
86
+ const [x, sub] = parts;
87
+ // 解释 A:新布局无 agentId 段(tenant, subsystem);解释 B:legacy(agent, subsystem,
88
+ // 租户维视作 DEFAULT——不是「不存在」)
89
+ const asTenantSub = matches(tenantId, x) && matches(agentId, undefined) && matches(subsystemId, sub);
90
+ const asLegacy = matches(tenantId, DEFAULT_TENANT_ID) && matches(agentId, x) && matches(subsystemId, sub);
91
+ return asTenantSub || asLegacy;
76
92
  }
77
- if (!existsSync(this.auditDir))
78
- return [];
79
- return readdirSync(this.auditDir, { withFileTypes: true })
80
- .filter((d) => d.isDirectory())
81
- .map((d) => join(this.auditDir, d.name));
93
+ if (parts.length === 1) {
94
+ // legacy:仅 subsystem 段(租户维视作 DEFAULT,无 agent 维)
95
+ return (matches(tenantId, DEFAULT_TENANT_ID) &&
96
+ matches(agentId, undefined) &&
97
+ matches(subsystemId, parts[0]));
98
+ }
99
+ return false;
82
100
  }
83
101
  }
102
+ /**
103
+ * 查询值与路径段匹配:查询缺省(undefined)= 不限;段缺省(布局无该维)= 仅当查询未限该维才命中。
104
+ * legacy 布局的租户维按 DEFAULT 传入(视作 default,非缺维)。
105
+ *
106
+ * @param want - 查询值
107
+ * @param have - 路径段(undefined=该维度不存在)
108
+ */
109
+ function matches(want, have) {
110
+ if (want === undefined)
111
+ return true;
112
+ return have === want;
113
+ }
@@ -10,8 +10,10 @@ import type { SubsystemRun } from '../types.js';
10
10
  export interface AuditWriterConfig {
11
11
  /** 审计根目录(默认 ~/.octopi/audit) */
12
12
  auditDir: string;
13
- /** Agent ID(多租户时用于分区) */
13
+ /** Agent ID(分区) */
14
14
  agentId?: string;
15
+ /** 归属租户(arch/multi-tenancy.md §4:每条审计事件带租户);分区 + 记录代打 */
16
+ tenantId?: string;
15
17
  }
16
18
  /**
17
19
  * AuditWriter — 审计写入器
@@ -22,6 +24,7 @@ export interface AuditWriterConfig {
22
24
  export declare class AuditWriter {
23
25
  private auditDir;
24
26
  private agentId?;
27
+ private tenantId?;
25
28
  constructor(config: AuditWriterConfig);
26
29
  /**
27
30
  * 写入审计记录
@@ -30,7 +33,8 @@ export declare class AuditWriter {
30
33
  */
31
34
  write(run: SubsystemRun): void;
32
35
  /**
33
- * 获取审计文件路径
36
+ * 获取审计文件路径(三段式:{auditDir}/{tenantId}/[{agentId}/]{subsystemId}/{date}.jsonl)。
37
+ * 分区段 = 记录的生效租户(与记录恒一致)。
34
38
  */
35
39
  private getFilePath;
36
40
  }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { appendFileSync, mkdirSync, existsSync } from 'node:fs';
10
10
  import { join, dirname } from 'node:path';
11
+ import { DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
11
12
  /**
12
13
  * AuditWriter — 审计写入器
13
14
  *
@@ -17,9 +18,11 @@ import { join, dirname } from 'node:path';
17
18
  export class AuditWriter {
18
19
  auditDir;
19
20
  agentId;
21
+ tenantId;
20
22
  constructor(config) {
21
23
  this.auditDir = config.auditDir;
22
24
  this.agentId = config.agentId;
25
+ this.tenantId = config.tenantId;
23
26
  }
24
27
  /**
25
28
  * 写入审计记录
@@ -28,27 +31,44 @@ export class AuditWriter {
28
31
  */
29
32
  write(run) {
30
33
  try {
31
- const filePath = this.getFilePath(run.subsystemId, run.timestamp);
34
+ // 事件必带租户(§4 隔离矩阵):run 自带 > 写入器配置 > DEFAULT;
35
+ // **分区与记录用同一个租户**(MIN-3:分区≠记录会让按租户取证失去完整性)
36
+ const tenantId = run.tenantId ?? this.tenantId ?? DEFAULT_TENANT_ID;
37
+ const record = { ...run, tenantId };
38
+ const filePath = this.getFilePath(tenantId, run.subsystemId, run.timestamp);
32
39
  const dir = dirname(filePath);
33
40
  if (!existsSync(dir)) {
34
41
  mkdirSync(dir, { recursive: true });
35
42
  }
36
- appendFileSync(filePath, JSON.stringify(run) + '\n', 'utf-8');
43
+ appendFileSync(filePath, JSON.stringify(record) + '\n', 'utf-8');
37
44
  }
38
45
  catch {
39
46
  // 审计写入失败不阻塞主系统
40
47
  }
41
48
  }
42
49
  /**
43
- * 获取审计文件路径
50
+ * 获取审计文件路径(三段式:{auditDir}/{tenantId}/[{agentId}/]{subsystemId}/{date}.jsonl)。
51
+ * 分区段 = 记录的生效租户(与记录恒一致)。
44
52
  */
45
- getFilePath(subsystemId, timestamp) {
53
+ getFilePath(tenantId, subsystemId, timestamp) {
46
54
  const date = new Date(timestamp).toISOString().slice(0, 10); // YYYY-MM-DD
47
- const parts = [this.auditDir];
55
+ const parts = [this.auditDir, safeSegment(tenantId, 'tenantId')];
48
56
  if (this.agentId) {
49
- parts.push(this.agentId);
57
+ parts.push(safeSegment(this.agentId, 'agentId'));
50
58
  }
51
- parts.push(subsystemId, `${date}.jsonl`);
59
+ parts.push(safeSegment(subsystemId, 'subsystemId'), `${date}.jsonl`);
52
60
  return join(...parts);
53
61
  }
54
62
  }
63
+ /**
64
+ * 路径段安全断言:ID 进文件路径前拒分隔符与 `..`(路径穿越面;NIT 2026-11-13 评审)。
65
+ *
66
+ * @param value - 路径段
67
+ * @param label - 字段名(报错用)
68
+ */
69
+ function safeSegment(value, label) {
70
+ if (!value || /[/\\]/.test(value) || value.includes('..')) {
71
+ throw new Error(`audit_unsafe_path_segment: ${label}=${value}`);
72
+ }
73
+ return value;
74
+ }
@@ -64,6 +64,19 @@ export function validateSubsystemSpec(spec, enforcement) {
64
64
  message: 'sense.source "schedule" requires interval >= 1000ms',
65
65
  });
66
66
  }
67
+ const delay = spec.sense.startupDelayMs;
68
+ if (delay !== undefined && (!Number.isFinite(delay) || delay < 0)) {
69
+ errors.push({
70
+ field: 'sense.startupDelayMs',
71
+ message: 'sense.startupDelayMs must be a finite number >= 0',
72
+ });
73
+ }
74
+ if (delay !== undefined && interval !== undefined && Number.isFinite(delay) && delay > interval) {
75
+ errors.push({
76
+ field: 'sense.startupDelayMs',
77
+ message: 'sense.startupDelayMs must be <= interval(否则周期 tick 早于首跳,错峰语义失效)',
78
+ });
79
+ }
67
80
  }
68
81
  // ── act.mode 非 none 时,信号通道不能只有 escalate ──
69
82
  // (如果 act 已经直接行动了,escalate 应该配合其他通道一起用)
@@ -282,6 +282,7 @@ async function buildSpec(config, systemPrompt, source, dirPath) {
282
282
  } : undefined,
283
283
  interval: senseRaw.interval,
284
284
  runOnStart: senseRaw.runOnStart,
285
+ startupDelayMs: senseRaw.startupDelayMs,
285
286
  cooldownMs: senseRaw.cooldownMs,
286
287
  isolation: (senseRaw.isolation ?? 'structured'),
287
288
  fields: senseRaw.fields,
@@ -7,6 +7,7 @@
7
7
  * @module autonomous-subsystem/runtime
8
8
  */
9
9
  import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
10
+ import type { PulseSpec } from '../../activation/run-protocol.js';
10
11
  import type { Message } from '@octopi-agent/core/types.js';
11
12
  import type { ModelProvider } from '@octopi-agent/core/interfaces/model-provider.js';
12
13
  import type { ErrorStrategy } from '@octopi-agent/core/interfaces/error-strategy.js';
@@ -44,6 +45,8 @@ export interface SharedDeps {
44
45
  export interface SubsystemRuntimeConfig {
45
46
  deps: SharedDeps;
46
47
  auditDir?: string;
48
+ /** 归属租户(arch/multi-tenancy.md §4);透传 AuditWriter 分区/打标(生产装配接线随 T2) */
49
+ tenantId?: string;
47
50
  agentId?: string;
48
51
  /** SEC-6 宿主能力声明(必填):`sandboxed` 声明只有在 L4 可用时才放行 */
49
52
  securityEnforcement: SecurityEnforcementContext;
@@ -121,6 +124,14 @@ export declare class SubsystemRuntime {
121
124
  * 清理所有资源
122
125
  */
123
126
  dispose(): void;
127
+ /**
128
+ * 脉搏声明(P0c A′):schedule 型子系统的周期声明,供装配层聚合为实例级 PulseSpec。
129
+ */
130
+ pulseSpecs(): PulseSpec[];
131
+ /**
132
+ * 脉搏入口:gateway 单发驱动一次 schedule tick。key 形态 `subsystem.schedule:<id>`。
133
+ */
134
+ pulse(key: string): Promise<void>;
124
135
  /**
125
136
  * 触发回调(由 SenseEngine 调用)
126
137
  */
@@ -71,6 +71,7 @@ export class SubsystemRuntime {
71
71
  this.auditWriter = new AuditWriter({
72
72
  auditDir: config.auditDir,
73
73
  agentId: config.agentId,
74
+ tenantId: config.tenantId,
74
75
  });
75
76
  }
76
77
  }
@@ -269,6 +270,22 @@ export class SubsystemRuntime {
269
270
  this.sessionManager.dispose();
270
271
  this.signalBus.clear();
271
272
  }
273
+ /**
274
+ * 脉搏声明(P0c A′):schedule 型子系统的周期声明,供装配层聚合为实例级 PulseSpec。
275
+ */
276
+ pulseSpecs() {
277
+ return this.senseEngine.pulseSpecs();
278
+ }
279
+ /**
280
+ * 脉搏入口:gateway 单发驱动一次 schedule tick。key 形态 `subsystem.schedule:<id>`。
281
+ */
282
+ async pulse(key) {
283
+ const prefix = 'subsystem.schedule:';
284
+ if (!key.startsWith(prefix)) {
285
+ throw new Error(`subsystem-runtime: unknown pulse key "${key}"`);
286
+ }
287
+ await this.senseEngine.pulseSchedule(key.slice(prefix.length));
288
+ }
272
289
  // ── 内部方法 ──
273
290
  /**
274
291
  * 触发回调(由 SenseEngine 调用)
@@ -7,6 +7,7 @@
7
7
  * @module autonomous-subsystem/sense/engine
8
8
  */
9
9
  import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
10
+ import type { PulseSpec } from '../../../activation/run-protocol.js';
10
11
  import type { SenseContext, SubsystemSpec } from '../types.js';
11
12
  import { MetricsStore } from './metrics.js';
12
13
  export interface SenseEngineConfig {
@@ -41,9 +42,9 @@ export declare class SenseEngine {
41
42
  private subsystems;
42
43
  /** 全局传播深度追踪 */
43
44
  private depthTracker;
44
- /** 深度重置定时器 */
45
- private depthResetTimer?;
46
45
  constructor(config: SenseEngineConfig);
46
+ /** 惰性深度重置(P0c A′:替代原 depthResetTimer setInterval——零 self-arm 定时器) */
47
+ private depthExceeded;
47
48
  /** 获取指标存储(供主循环注入指标) */
48
49
  get metricsStore(): MetricsStore;
49
50
  /**
@@ -54,9 +55,18 @@ export declare class SenseEngine {
54
55
  */
55
56
  register(spec: SubsystemSpec, onTrigger: (ctx: SenseContext) => void): void;
56
57
  /**
57
- * 注销子系统:拆除其 EventBus 监听与 schedule 定时器
58
+ * 注销子系统:拆除其 EventBus 监听
58
59
  */
59
60
  unregister(subsystemId: string): void;
61
+ /**
62
+ * 脉搏声明(P0c A′):全部 schedule 型子系统的周期声明,供装配层聚合。
63
+ */
64
+ pulseSpecs(): PulseSpec[];
65
+ /**
66
+ * 脉搏入口:gateway 单发驱动一次 schedule tick(复用冷却/深度/condition)。
67
+ * 未注册或非 schedule 型 fail-loud。
68
+ */
69
+ pulseSchedule(subsystemId: string): Promise<void>;
60
70
  /**
61
71
  * 手动触发子系统(API 调用,可穿透冷却期)
62
72
  *
@@ -27,8 +27,6 @@ export class SenseEngine {
27
27
  subsystems = new Map();
28
28
  /** 全局传播深度追踪 */
29
29
  depthTracker = { depth: 0, chainStartTime: Date.now() };
30
- /** 深度重置定时器 */
31
- depthResetTimer;
32
30
  constructor(config) {
33
31
  this.events = config.events;
34
32
  this.metrics = new MetricsStore();
@@ -36,10 +34,13 @@ export class SenseEngine {
36
34
  this.maxDepth = config.maxDepth ?? 5;
37
35
  this.depthResetIntervalMs = config.depthResetIntervalMs ?? 60000;
38
36
  this.evaluatorTimeoutMs = config.evaluatorTimeoutMs ?? 30_000;
39
- // 定期重置深度计数器(防止长期运行后深度累积)
40
- this.depthResetTimer = setInterval(() => {
37
+ }
38
+ /** 惰性深度重置(P0c A′:替代原 depthResetTimer setInterval——零 self-arm 定时器) */
39
+ depthExceeded() {
40
+ if (Date.now() - this.depthTracker.chainStartTime >= this.depthResetIntervalMs) {
41
41
  this.depthTracker = { depth: 0, chainStartTime: Date.now() };
42
- }, this.depthResetIntervalMs);
42
+ }
43
+ return this.depthTracker.depth >= this.maxDepth;
43
44
  }
44
45
  // ── 公共 API ──
45
46
  /** 获取指标存储(供主循环注入指标) */
@@ -63,6 +64,7 @@ export class SenseEngine {
63
64
  minEvents: spec.sense.filter?.minEvents ?? 1,
64
65
  eventCount: 0,
65
66
  evaluator,
67
+ onTrigger,
66
68
  disposables: [],
67
69
  };
68
70
  this.subsystems.set(spec.id, entry);
@@ -75,7 +77,9 @@ export class SenseEngine {
75
77
  entry.disposables.push(disposable);
76
78
  }
77
79
  }
78
- // schedule:interval 轮询;复用冷却/深度/condition/onTrigger
80
+ // schedule:周期 tick 与首跳**不再 self-arm**(P0c A′ 零常驻触发器)——
81
+ // 改由 gateway 脉搏调度器经 `pulseSchedule()` 单发驱动;runOnStart 首跳随
82
+ // `pulseSpecs()` 的 `runOnStart` 标记由调度器发出。
79
83
  // 双脉搏:schedule 子系统也可监听 filter.events(如 memory.health.* / 手动 request)
80
84
  if (spec.sense.source === 'schedule') {
81
85
  if (spec.sense.filter?.events) {
@@ -86,27 +90,10 @@ export class SenseEngine {
86
90
  entry.disposables.push(disposable);
87
91
  }
88
92
  }
89
- const intervalMs = spec.sense.interval;
90
- if (intervalMs && intervalMs > 0) {
91
- entry.scheduleTimer = setInterval(() => {
92
- void this.onScheduleTick(spec.id, onTrigger);
93
- }, intervalMs);
94
- if (typeof entry.scheduleTimer === 'object' && entry.scheduleTimer !== null && 'unref' in entry.scheduleTimer) {
95
- entry.scheduleTimer.unref?.();
96
- }
97
- }
98
- // 启动首跳:注册完成后补一次 tick(长 interval 首跳跨不过进程生命周期时的保底脉搏;
99
- // setTimeout(0) 保证 builder 同步注册/依赖注入全部完成后才跑)
100
- if (spec.sense.runOnStart) {
101
- const starter = setTimeout(() => {
102
- void this.onScheduleTick(spec.id, onTrigger);
103
- }, 0);
104
- starter.unref?.();
105
- }
106
93
  }
107
94
  }
108
95
  /**
109
- * 注销子系统:拆除其 EventBus 监听与 schedule 定时器
96
+ * 注销子系统:拆除其 EventBus 监听
110
97
  */
111
98
  unregister(subsystemId) {
112
99
  const entry = this.subsystems.get(subsystemId);
@@ -116,12 +103,42 @@ export class SenseEngine {
116
103
  d.dispose();
117
104
  }
118
105
  entry.disposables = [];
119
- if (entry.scheduleTimer) {
120
- clearInterval(entry.scheduleTimer);
121
- entry.scheduleTimer = undefined;
122
- }
123
106
  this.subsystems.delete(subsystemId);
124
107
  }
108
+ /**
109
+ * 脉搏声明(P0c A′):全部 schedule 型子系统的周期声明,供装配层聚合。
110
+ */
111
+ pulseSpecs() {
112
+ const specs = [];
113
+ for (const [id, entry] of this.subsystems) {
114
+ if (entry.spec.sense.source !== 'schedule')
115
+ continue;
116
+ const intervalMs = entry.spec.sense.interval;
117
+ if (!intervalMs || intervalMs <= 0)
118
+ continue;
119
+ specs.push({
120
+ key: `subsystem.schedule:${id}`,
121
+ intervalMs,
122
+ runOnStart: entry.spec.sense.runOnStart,
123
+ startupDelayMs: entry.spec.sense.startupDelayMs,
124
+ });
125
+ }
126
+ return specs;
127
+ }
128
+ /**
129
+ * 脉搏入口:gateway 单发驱动一次 schedule tick(复用冷却/深度/condition)。
130
+ * 未注册或非 schedule 型 fail-loud。
131
+ */
132
+ async pulseSchedule(subsystemId) {
133
+ const entry = this.subsystems.get(subsystemId);
134
+ if (!entry) {
135
+ throw new Error(`sense-engine: unknown pulse subsystem "${subsystemId}"`);
136
+ }
137
+ if (entry.spec.sense.source !== 'schedule') {
138
+ throw new Error(`sense-engine: subsystem "${subsystemId}" is not schedule-sensed`);
139
+ }
140
+ await this.onScheduleTick(subsystemId, entry.onTrigger);
141
+ }
125
142
  /**
126
143
  * 手动触发子系统(API 调用,可穿透冷却期)
127
144
  *
@@ -134,7 +151,7 @@ export class SenseEngine {
134
151
  if (!entry)
135
152
  return false;
136
153
  // 检查并发深度
137
- if (this.depthTracker.depth >= this.maxDepth) {
154
+ if (this.depthExceeded()) {
138
155
  return false;
139
156
  }
140
157
  // API 触发穿透冷却期,但仍评估条件
@@ -256,14 +273,6 @@ export class SenseEngine {
256
273
  d.dispose();
257
274
  }
258
275
  entry.disposables = [];
259
- if (entry.scheduleTimer) {
260
- clearInterval(entry.scheduleTimer);
261
- entry.scheduleTimer = undefined;
262
- }
263
- }
264
- if (this.depthResetTimer) {
265
- clearInterval(this.depthResetTimer);
266
- this.depthResetTimer = undefined;
267
276
  }
268
277
  this.subsystems.clear();
269
278
  }
@@ -303,7 +312,7 @@ export class SenseEngine {
303
312
  if (now < entry.cooldown.until || entry.inFlight) {
304
313
  return;
305
314
  }
306
- if (this.depthTracker.depth >= this.maxDepth) {
315
+ if (this.depthExceeded()) {
307
316
  return;
308
317
  }
309
318
  const data = (event.data ?? {});
@@ -352,7 +361,7 @@ export class SenseEngine {
352
361
  if (now < entry.cooldown.until || entry.inFlight) {
353
362
  return;
354
363
  }
355
- if (this.depthTracker.depth >= this.maxDepth) {
364
+ if (this.depthExceeded()) {
356
365
  return;
357
366
  }
358
367
  const ctx = {
@@ -209,6 +209,9 @@ export class ThinkExecutor {
209
209
  name: t.definition.name,
210
210
  description: t.definition.description,
211
211
  executionMode: t.executionMode,
212
+ // 结果老化策略(同 executionMode:唯一声明源在 RegisteredTool)
213
+ ...(t.ageArgs ? { ageArgs: t.ageArgs } : {}),
214
+ ...(t.ageResult ? { ageResult: t.ageResult } : {}),
212
215
  parameters: {
213
216
  type: 'object',
214
217
  properties: Object.fromEntries(Object.entries(t.definition.parameters).map(([key, param]) => [
@@ -97,6 +97,8 @@ export interface SenseConfig {
97
97
  interval?: number;
98
98
  /** schedule 模式:注册后立即补一次首跳(长 interval 跨不过进程生命周期时的保底脉搏) */
99
99
  runOnStart?: boolean;
100
+ /** schedule 模式:首跳延迟(毫秒)——多子系统首跳按数据流依赖序错峰(如 govern 先于下游巩固/归因) */
101
+ startupDelayMs?: number;
100
102
  /** 本子系统的触发冷却(毫秒);缺省用 SenseEngine 全局 defaultCooldownMs */
101
103
  cooldownMs?: number;
102
104
  isolation: IsolationLevel;
@@ -378,6 +380,8 @@ export interface SubsystemRun {
378
380
  id: string;
379
381
  /** 子系统标识 */
380
382
  subsystemId: string;
383
+ /** 归属租户(arch/multi-tenancy.md §4;缺省 'default',AuditWriter.write 可代打) */
384
+ tenantId?: string;
381
385
  /** 触发原因 */
382
386
  trigger: {
383
387
  source: string;
@@ -24,10 +24,14 @@ import type { SessionData, SessionSpawnLink } from '../../session/types.js';
24
24
  import type { DelegationBudget, DelegationContextMode } from './types.js';
25
25
  /** 子 Run 入参 */
26
26
  export interface ChildRunInput {
27
+ /** 归属租户(继承父会话,arch/multi-tenancy.md §8);接线在 T4,缺省 DEFAULT_TENANT_ID */
28
+ tenantId?: import('@octopi-agent/core/types.js').TenantId;
27
29
  delegationId: string;
28
30
  /** 目标 agentId(已解析) */
29
31
  childAgentId: string;
30
32
  task: string;
33
+ /** 子会话显示标题(工具面必填;缺省时退任务派生标题,不产生「新会话」) */
34
+ title?: string;
31
35
  input: string;
32
36
  /** 上下文传递模式 */
33
37
  context: DelegationContextMode;
@@ -116,6 +120,11 @@ export declare class RunnerChildRunPort implements ChildRunPort {
116
120
  /** 构造带 `spawnBy` 的 child session 骨架 */
117
121
  private newChildSession;
118
122
  }
123
+ /** 委派 → 子会话标题(单一来源,委派单记录与子会话同用此值):显式 title 优先(压单行、截 120);缺省退任务派生(delegation: 前缀,兼容直连 API 老调用方) */
124
+ export declare function delegationSessionTitle(input: {
125
+ title?: string;
126
+ task: string;
127
+ }): string;
119
128
  /** 委派指令片段(§9.4:模板 persona + 编排指令) */
120
129
  export interface DelegationPromptOptions {
121
130
  /** 子 agent 的 persona(来自 `AgentConfig.persona`) */
@@ -18,6 +18,7 @@
18
18
  * 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
19
19
  */
20
20
  import { emptyTokenUsage } from '@octopi-agent/core/types/step.js';
21
+ import { DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
21
22
  /**
22
23
  * 累加 step 级 usage 到总账(决策 C2:归集到父的 run 账)
23
24
  *
@@ -83,6 +84,9 @@ export class RunnerChildRunPort {
83
84
  sessionId: childSessionId,
84
85
  // D3:委派权利天花板,Runner 会与模板天花板取交集
85
86
  rightsCeiling: input.rightsCeiling,
87
+ // §9.1-6:子 run principal 归属 = 父会话租户(mergePrincipal 与子 agent
88
+ // 归属冲突时 fail-loud——同租户闸已在 dispatch,这里是纵深防线)
89
+ ...(input.tenantId === undefined ? {} : { principal: { actorType: 'agent', tenantId: input.tenantId } }),
86
90
  };
87
91
  const usage = emptyTokenUsage();
88
92
  let output;
@@ -148,23 +152,46 @@ export class RunnerChildRunPort {
148
152
  /** 构造带 `spawnBy` 的 child session 骨架 */
149
153
  newChildSession(sessionId, input) {
150
154
  const timestamp = Date.now();
155
+ // 委派标题落三键:子会话不再一律「新会话」。
156
+ // 权威在 metadata 三键(写端恒打三键);meta.title 仅镜像——只写 meta.title
157
+ // 会被 readTitleState 投影覆盖为 undefined(曾是「新会话」的根因)。
158
+ // 显式标题按 user 语义保护(不被自动标题覆盖——"设了就是设了");
159
+ // 任务派生为临时(snippet,可被自动标题升级)——shouldUpdateTitle 既有仲裁
160
+ const title = delegationSessionTitle(input);
161
+ const titleSource = input.title?.trim() ? 'user' : 'snippet';
151
162
  return {
152
163
  id: sessionId,
153
164
  agentId: input.childAgentId,
165
+ tenantId: input.tenantId ?? DEFAULT_TENANT_ID,
154
166
  primaryAgentId: input.childAgentId,
155
167
  spawnBy: { ...input.spawnBy },
156
168
  meta: {
157
- title: `delegation: ${input.task}`.slice(0, 120),
169
+ tenantId: input.tenantId ?? DEFAULT_TENANT_ID,
170
+ title,
171
+ titleSource,
172
+ titleUpdatedAt: timestamp,
158
173
  createdAt: timestamp,
159
174
  updatedAt: timestamp,
160
175
  status: 'idle',
161
176
  },
162
177
  messages: [],
163
178
  steps: [],
164
- metadata: { delegationId: input.delegationId },
179
+ metadata: {
180
+ delegationId: input.delegationId,
181
+ title,
182
+ titleSource,
183
+ titleUpdatedAt: timestamp,
184
+ },
165
185
  };
166
186
  }
167
187
  }
188
+ /** 委派 → 子会话标题(单一来源,委派单记录与子会话同用此值):显式 title 优先(压单行、截 120);缺省退任务派生(delegation: 前缀,兼容直连 API 老调用方) */
189
+ export function delegationSessionTitle(input) {
190
+ const explicit = input.title?.replace(/\s+/g, ' ').trim();
191
+ if (explicit)
192
+ return explicit.slice(0, 120);
193
+ return `delegation: ${input.task.replace(/\s+/g, ' ').trim()}`.slice(0, 120);
194
+ }
168
195
  /**
169
196
  * 渲染 fork 模式的父历史前缀(§9.4:显式 `context: 'fork'` 才继承)
170
197
  *
@@ -224,10 +251,15 @@ export function createChildRunExecutor(port, options, resolvePersona) {
224
251
  const output = await port.run({
225
252
  delegationId: request.delegationId,
226
253
  childAgentId,
254
+ // §8 委派继承位:子 run 归属 = 父 run 归属(租户内委派闸在 dispatch)
255
+ ...(request.from.tenantId === undefined
256
+ ? {}
257
+ : { tenantId: request.from.tenantId }),
227
258
  // D7:id 由服务方在起 Run 前生成并落库,此处透传
228
259
  childSessionId: request.childSessionId,
229
260
  childRunId: request.childRunId,
230
261
  task: request.task,
262
+ title: request.title,
231
263
  input: request.input,
232
264
  context: request.context,
233
265
  parentMessages: request.parentMessages,