@octopi-agent/engine 0.86.38 → 0.97.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 (218) hide show
  1. package/dist/config-admin/agent-presets.d.ts +70 -0
  2. package/dist/config-admin/agent-presets.js +243 -0
  3. package/dist/config-admin/discover.d.ts +30 -0
  4. package/dist/config-admin/discover.js +48 -0
  5. package/dist/config-admin/env.d.ts +22 -0
  6. package/dist/config-admin/env.js +41 -0
  7. package/dist/config-admin/index.d.ts +20 -0
  8. package/dist/config-admin/index.js +15 -0
  9. package/dist/config-admin/model-presets.d.ts +75 -0
  10. package/dist/config-admin/model-presets.js +249 -0
  11. package/dist/config-admin/name-guard.d.ts +14 -0
  12. package/dist/config-admin/name-guard.js +24 -0
  13. package/dist/config-admin/patch.d.ts +56 -0
  14. package/dist/config-admin/patch.js +201 -0
  15. package/dist/config-admin/port.d.ts +68 -0
  16. package/dist/config-admin/port.js +21 -0
  17. package/dist/config-admin/redact.d.ts +39 -0
  18. package/dist/config-admin/redact.js +42 -0
  19. package/dist/config-schema/agent.d.ts +43 -1
  20. package/dist/config-schema/agent.js +12 -5
  21. package/dist/config-schema/context.d.ts +7 -2
  22. package/dist/config-schema/context.js +8 -0
  23. package/dist/config-schema/engine.d.ts +110 -8
  24. package/dist/config-schema/governance.d.ts +43 -1
  25. package/dist/config-schema/governance.js +160 -2
  26. package/dist/config-schema/models.d.ts +7 -4
  27. package/dist/config-schema/models.js +4 -1
  28. package/dist/config-schema/observability.d.ts +9 -0
  29. package/dist/config-schema/observability.js +29 -0
  30. package/dist/config-schema/run.d.ts +3 -0
  31. package/dist/config-schema/run.js +14 -0
  32. package/dist/config-schema/shared.d.ts +3 -0
  33. package/dist/config-schema/shared.js +12 -0
  34. package/dist/config-schema/substrate.d.ts +1 -1
  35. package/dist/config.d.ts +60 -13
  36. package/dist/config.js +81 -78
  37. package/dist/harness/activation/dispatcher.d.ts +8 -2
  38. package/dist/harness/activation/dispatcher.js +33 -5
  39. package/dist/harness/activation/inbox.d.ts +87 -0
  40. package/dist/harness/activation/inbox.js +169 -0
  41. package/dist/harness/activation/runtime.d.ts +9 -8
  42. package/dist/harness/activation/runtime.js +100 -8
  43. package/dist/harness/activation/types.d.ts +19 -0
  44. package/dist/harness/activation/types.js +2 -0
  45. package/dist/harness/agent/builder.d.ts +18 -3
  46. package/dist/harness/agent/builder.js +42 -17
  47. package/dist/harness/agent/config-bridge.d.ts +5 -0
  48. package/dist/harness/agent/config-bridge.js +7 -1
  49. package/dist/harness/agent/config-integrity.d.ts +72 -0
  50. package/dist/harness/agent/config-integrity.js +146 -0
  51. package/dist/harness/agent/tool-purpose.d.ts +9 -1
  52. package/dist/harness/agent/tool-purpose.js +11 -2
  53. package/dist/harness/agent/wire-agent-builder.js +11 -3
  54. package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
  55. package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
  56. package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
  57. package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
  58. package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -0
  59. package/dist/harness/collaboration/autonomous-subsystem/runtime.js +3 -1
  60. package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
  61. package/dist/harness/collaboration/delegation/child-run.js +21 -5
  62. package/dist/harness/collaboration/delegation/notifier.js +4 -3
  63. package/dist/harness/collaboration/delegation/service.js +2 -3
  64. package/dist/harness/collaboration/delegation/wiring.js +6 -5
  65. package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
  66. package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
  67. package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
  68. package/dist/harness/context/capabilities/compact/engine.js +198 -46
  69. package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
  70. package/dist/harness/context/capabilities/compact/handover.js +107 -0
  71. package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
  72. package/dist/harness/context/capabilities/compact/index.js +2 -1
  73. package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
  74. package/dist/harness/context/capabilities/summary/executor.js +2 -1
  75. package/dist/harness/context/capabilities/summary/policies.js +8 -5
  76. package/dist/harness/context/constitution/default-agents.md +11 -10
  77. package/dist/harness/context/default-context-engine.d.ts +34 -4
  78. package/dist/harness/context/default-context-engine.js +198 -53
  79. package/dist/harness/context/hybrid-compressor.js +6 -0
  80. package/dist/harness/context/layer-types.d.ts +36 -0
  81. package/dist/harness/context/layer-types.js +38 -0
  82. package/dist/harness/context/llm-summarizer.d.ts +2 -8
  83. package/dist/harness/context/llm-summarizer.js +69 -91
  84. package/dist/harness/context/message-selector.js +4 -3
  85. package/dist/harness/context/root-instructions.js +1 -1
  86. package/dist/harness/context/summarize.d.ts +2 -0
  87. package/dist/harness/context/summarize.js +7 -2
  88. package/dist/harness/context/system-prompt-assembler.js +10 -4
  89. package/dist/harness/context/tool-result-aging.js +2 -2
  90. package/dist/harness/context/truncate-compressor.js +7 -0
  91. package/dist/harness/context/turn-envelope.d.ts +4 -3
  92. package/dist/harness/context/turn-envelope.js +4 -3
  93. package/dist/harness/context/types.d.ts +33 -1
  94. package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
  95. package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
  96. package/dist/harness/extension/execution-environment/effect-policy.d.ts +133 -4
  97. package/dist/harness/extension/execution-environment/effect-policy.js +263 -14
  98. package/dist/harness/extension/execution-environment/index.d.ts +4 -2
  99. package/dist/harness/extension/execution-environment/index.js +2 -1
  100. package/dist/harness/extension/execution-environment/isolation.js +5 -1
  101. package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
  102. package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
  103. package/dist/harness/extension/execution-environment/ops-audit.d.ts +200 -0
  104. package/dist/harness/extension/execution-environment/ops-audit.js +338 -0
  105. package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
  106. package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
  107. package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
  108. package/dist/harness/extension/execution-environment/process-info.js +466 -0
  109. package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
  110. package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
  111. package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
  112. package/dist/harness/extension/execution-environment/sandbox.js +264 -29
  113. package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
  114. package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
  115. package/dist/harness/extension/execution-environment/types.d.ts +19 -0
  116. package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
  117. package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +6 -0
  118. package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +50 -0
  119. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
  120. package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
  121. package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
  122. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +53 -2
  123. package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +10 -17
  124. package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
  125. package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
  126. package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
  127. package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
  128. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +8 -8
  129. package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +9 -100
  130. package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
  131. package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
  132. package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
  133. package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
  134. package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
  135. package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
  136. package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
  137. package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
  138. package/dist/harness/governance/security/temp-path.d.ts +9 -0
  139. package/dist/harness/governance/security/temp-path.js +13 -2
  140. package/dist/harness/governance/session-acl/seed-roles.js +14 -0
  141. package/dist/harness/index.d.ts +4 -0
  142. package/dist/harness/index.js +3 -0
  143. package/dist/harness/knowledge/file-identity.d.ts +8 -0
  144. package/dist/harness/knowledge/file-identity.js +26 -1
  145. package/dist/harness/knowledge/fts.js +1 -2
  146. package/dist/harness/knowledge/grounding.js +5 -5
  147. package/dist/harness/knowledge/index-store.d.ts +31 -4
  148. package/dist/harness/knowledge/index-store.js +180 -48
  149. package/dist/harness/knowledge/ingest.d.ts +115 -115
  150. package/dist/harness/knowledge/ingest.js +150 -150
  151. package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
  152. package/dist/harness/knowledge/purge.js +4 -1
  153. package/dist/harness/memory/backfill-coverage.js +3 -1
  154. package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
  155. package/dist/harness/memory/sqlite/keyword-search.js +4 -3
  156. package/dist/harness/observability/observer/hub.js +38 -1
  157. package/dist/harness/observability/observer/run-snapshot.js +1 -0
  158. package/dist/harness/observability/observer/types.d.ts +27 -0
  159. package/dist/harness/run/agent/agent.d.ts +7 -0
  160. package/dist/harness/run/agent/agent.js +23 -1
  161. package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
  162. package/dist/harness/run/reliability/fallback-provider.js +262 -22
  163. package/dist/harness/run/reliability/harness-events.d.ts +24 -1
  164. package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
  165. package/dist/harness/run/reliability/model-error-policy.js +42 -0
  166. package/dist/harness/run/reliability/provider-wrapper.js +29 -2
  167. package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
  168. package/dist/harness/run/reliability/refusal-guard.js +102 -0
  169. package/dist/harness/run/reliability/run-agent.js +231 -33
  170. package/dist/harness/run/run-guard/default-run-guard.js +1 -1
  171. package/dist/harness/run/run-scope.d.ts +31 -0
  172. package/dist/harness/run/runner.d.ts +132 -2
  173. package/dist/harness/run/runner.js +679 -60
  174. package/dist/harness/session/attachments/llm-intent.js +2 -1
  175. package/dist/harness/session/history/port.js +15 -5
  176. package/dist/harness/session/in-memory-store.d.ts +5 -0
  177. package/dist/harness/session/in-memory-store.js +33 -2
  178. package/dist/harness/session/tasks/render.d.ts +4 -1
  179. package/dist/harness/session/tasks/render.js +10 -7
  180. package/dist/harness/session/title.js +25 -9
  181. package/dist/harness/shared/events/agent-event-map.d.ts +92 -0
  182. package/dist/harness/shared/events/agent-event-map.js +7 -0
  183. package/dist/index.d.ts +6 -4
  184. package/dist/index.js +4 -3
  185. package/dist/integration/agent-runtime/channel-message-source.js +19 -1
  186. package/dist/integration/index.d.ts +2 -0
  187. package/dist/integration/index.js +1 -0
  188. package/dist/integration/observability/loop-watchdog.d.ts +56 -0
  189. package/dist/integration/observability/loop-watchdog.js +177 -0
  190. package/dist/integration/observability/metrics.d.ts +3 -0
  191. package/dist/integration/observability/metrics.js +18 -7
  192. package/dist/integration/observability/run-telemetry.d.ts +8 -0
  193. package/dist/integration/observability/run-telemetry.js +31 -8
  194. package/dist/integration/observability/trace-collector.js +26 -4
  195. package/dist/integration/observability/trace-events.d.ts +1 -0
  196. package/dist/integration/observability/trace-events.js +2 -0
  197. package/dist/integration/observability/trace-logger.js +27 -17
  198. package/dist/integration/providers/anthropic.d.ts +23 -0
  199. package/dist/integration/providers/anthropic.js +97 -12
  200. package/dist/integration/providers/fetch-timeout.d.ts +42 -0
  201. package/dist/integration/providers/fetch-timeout.js +51 -0
  202. package/dist/integration/providers/openai.d.ts +10 -0
  203. package/dist/integration/providers/openai.js +58 -11
  204. package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
  205. package/dist/integration/providers/provider-diagnostics.js +89 -0
  206. package/dist/integration/providers/timeout-coherence.d.ts +52 -0
  207. package/dist/integration/providers/timeout-coherence.js +68 -0
  208. package/dist/integration/providers/wire-dump.d.ts +62 -0
  209. package/dist/integration/providers/wire-dump.js +111 -2
  210. package/dist/integration/storage/jsonl.d.ts +19 -1
  211. package/dist/integration/storage/jsonl.js +100 -4
  212. package/dist/paths.d.ts +19 -0
  213. package/dist/paths.js +38 -1
  214. package/dist/subsystems/cognition-steward/conceptualize/handler.js +1 -1
  215. package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
  216. package/dist/subsystems/safety-guard/config.yaml +3 -1
  217. package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
  218. package/package.json +3 -2
@@ -14,6 +14,7 @@
14
14
  * ```
15
15
  */
16
16
  import { DefaultToolBus } from '../extension/plugin-ecosystem/tools/tool-bus.js';
17
+ import { expandHomePath } from '../../paths.js';
17
18
  import { createUnconfiguredFileEffects, createUnconfiguredMemoryEffects, } from '../extension/execution-environment/undo-log.js';
18
19
  import { JournaledMemoryStore } from '../extension/execution-environment/memory-undo.js';
19
20
  import { buildToolLlmParameters, prepareHandlerArgs, resolveToolCallPurpose, sanitizeToolJsonSchema, } from './tool-purpose.js';
@@ -36,24 +37,30 @@ import { createProviderSummarize } from '../context/summarize.js';
36
37
  import { createDefaultSystemPromptAssembler } from '../context/system-prompt-assembler.js';
37
38
  import { SessionAwareRunner } from '../run/runner.js';
38
39
  import { DefaultMcpManager } from '../extension/plugin-ecosystem/mcp/manager.js';
40
+ import { maxAttemptsFor } from '../run/reliability/model-error-policy.js';
39
41
  // ── 默认实现 ──
40
- /** 默认错误策略(简单重试 + 中止) */
41
- class DefaultErrorStrategy {
42
+ /** 默认错误策略(按原因分级重试 + 中止;上限见 MODEL_ERROR_MAX_ATTEMPTS) */
43
+ export class DefaultErrorStrategy {
42
44
  onModelError(error, attempt) {
45
+ const maxAttempts = maxAttemptsFor(error.reason);
43
46
  // ── 可重试错误:限流、超时、网络、服务端 ──
44
- if (error.reason === 'rate_limit' && attempt < 3) {
47
+ if (error.reason === 'rate_limit' && attempt < maxAttempts) {
45
48
  const delayMs = error.retryAfterMs ?? (attempt + 1) * 1000;
46
49
  return { action: 'retry', delayMs };
47
50
  }
48
- if (error.reason === 'timeout' && attempt < 3) {
51
+ if (error.reason === 'timeout' && attempt < maxAttempts) {
49
52
  return { action: 'retry', delayMs: (attempt + 1) * 1000 };
50
53
  }
51
- if (error.reason === 'network' && attempt < 3) {
54
+ if (error.reason === 'network' && attempt < maxAttempts) {
52
55
  return { action: 'retry', delayMs: (attempt + 1) * 1500 };
53
56
  }
54
- if (error.reason === 'server' && attempt < 2) {
57
+ if (error.reason === 'server' && attempt < maxAttempts) {
55
58
  return { action: 'retry', delayMs: (attempt + 1) * 2000 };
56
59
  }
60
+ // ── content_filter:内容过滤拒答多为阈值型误杀,原样重试常过;不教模型换说法绕过 ──
61
+ if (error.reason === 'content_filter' && attempt < maxAttempts) {
62
+ return { action: 'retry', delayMs: (attempt + 1) * 1000 };
63
+ }
57
64
  // ── context_length:由引擎尝试 compact,这里返回 abort 让引擎决定 ──
58
65
  if (error.reason === 'context_length') {
59
66
  return { action: 'abort', reason: `Context length exceeded: ${error.message}` };
@@ -115,11 +122,16 @@ class RuntimeToolContextProvider {
115
122
  networkPolicy: scope.toolRuntime.networkPolicy,
116
123
  requireCredentialBindings: scope.toolRuntime.requireCredentialBindings,
117
124
  requireJail: scope.toolRuntime.requireJail,
125
+ disableJail: scope.toolRuntime.disableJail,
118
126
  homeWrite: scope.toolRuntime.homeWrite,
119
127
  noteSecurityDegraded: scope.toolRuntime.noteSecurityDegraded,
128
+ recordOpsEvent: scope.toolRuntime.recordOpsEvent,
120
129
  pathContainment: scope.toolRuntime.pathContainment,
121
130
  confirmEffect: scope.toolRuntime.confirmEffect,
122
131
  effectChannel: scope.toolRuntime.effectChannel,
132
+ escalation: scope.toolRuntime.escalation,
133
+ dangerousCommands: scope.toolRuntime.dangerousCommands,
134
+ sessionParticipants: scope.toolRuntime.sessionParticipants,
123
135
  processLimits: scope.toolRuntime.processLimits,
124
136
  shellEscape: scope.toolRuntime.shellEscape,
125
137
  shellJournal: scope.toolRuntime.shellJournal,
@@ -164,7 +176,7 @@ function convertToAgentTool(tool, contextProvider) {
164
176
  description: tool.definition.description,
165
177
  executionMode: tool.executionMode,
166
178
  parameters: buildToolLlmParameters(tool.definition.parameters),
167
- execute: async (toolCallId, args, signal) => {
179
+ execute: async (toolCallId, args, signal, onUpdate) => {
168
180
  const startTime = Date.now();
169
181
  try {
170
182
  const context = contextProvider.get();
@@ -175,7 +187,12 @@ function convertToAgentTool(tool, contextProvider) {
175
187
  const handlerArgs = prepareHandlerArgs(rawArgs, tool.definition);
176
188
  const { runWithToolLimits, resolveToolTimeoutMs } = await import('../extension/execution-environment/resource-limits.js');
177
189
  const processLimitsEnabled = context.processLimits !== false;
178
- const result = await runWithToolLimits((sig) => tool.handler(handlerArgs, { ...context, abortSignal: sig }), {
190
+ const result = await runWithToolLimits((sig) => tool.handler(handlerArgs, {
191
+ ...context,
192
+ abortSignal: sig,
193
+ // 工具部分输出通道(展示用途);无转发器时不给工具假通道
194
+ ...(onUpdate ? { onUpdate } : {}),
195
+ }), {
179
196
  timeoutMs: processLimitsEnabled
180
197
  ? resolveToolTimeoutMs(tool.definition)
181
198
  : undefined,
@@ -545,9 +562,10 @@ export class AgentBuilder {
545
562
  * 设置 Skill 目录(子目录内含 SKILL.md)
546
563
  *
547
564
  * build 时 discover,每轮以索引形式注入 system prompt(formatForPrompt)。
565
+ * `~` 形态在此展开(与 workspace / agentHome 同规,幂等)。
548
566
  */
549
567
  skillDirectory(dir) {
550
- this._skillDirectory = dir;
568
+ this._skillDirectory = expandHomePath(dir.trim());
551
569
  return this;
552
570
  }
553
571
  /** 直接注入 SkillManager(跳过目录 discover) */
@@ -762,14 +780,14 @@ export class AgentBuilder {
762
780
  this._personaWorkspaces.push(...workspaces);
763
781
  return this;
764
782
  }
765
- /** 设置 Agent 沙箱工作目录(注入到内置工具的 cwd) */
783
+ /** 设置 Agent 沙箱工作目录(注入到内置工具的 cwd);`~` 形态在此展开(trim → expand) */
766
784
  workspace(dir) {
767
- this._workspace = dir;
785
+ this._workspace = expandHomePath(dir.trim());
768
786
  return this;
769
787
  }
770
- /** agent 文件态 home:extract 落盘、与 persona 目录解耦 */
788
+ /** agent 文件态 home:extract 落盘、与 persona 目录解耦;`~` 形态在此展开(与 workspace 同规) */
771
789
  agentHome(dir) {
772
- this._agentHome = dir;
790
+ this._agentHome = expandHomePath(dir.trim());
773
791
  return this;
774
792
  }
775
793
  /** 逻辑 agentId(extract pending 扫描 / 观测) */
@@ -1062,6 +1080,9 @@ export class AgentBuilder {
1062
1080
  let subsystemRuntime;
1063
1081
  if (candidateSpecs.length > 0 || this._subsystemDir) {
1064
1082
  const { SubsystemRuntime } = await import('../collaboration/autonomous-subsystem/runtime.js');
1083
+ const { probeProcessIsolation, assessL4ProcessMinimum } = await import('../extension/execution-environment/process-isolation.js');
1084
+ const isolationProfile = await probeProcessIsolation();
1085
+ const securityEnforcement = { l4Available: assessL4ProcessMinimum(isolationProfile).ok };
1065
1086
  subsystemRuntime = new SubsystemRuntime({
1066
1087
  deps: {
1067
1088
  model: agent.model,
@@ -1073,6 +1094,7 @@ export class AgentBuilder {
1073
1094
  },
1074
1095
  auditDir: this._subsystemAuditDir,
1075
1096
  agentId: this._agentId,
1097
+ securityEnforcement,
1076
1098
  });
1077
1099
  const registeredIds = new Set();
1078
1100
  const tryRegister = (spec) => {
@@ -1328,7 +1350,11 @@ export class AgentBuilder {
1328
1350
  const snap = getResolvedModel();
1329
1351
  const provider = snap?.provider ?? this._model;
1330
1352
  const model = snap?.modelName;
1331
- return createProviderSummarize(provider, { model })(messages, opts);
1353
+ return createProviderSummarize(provider, {
1354
+ model,
1355
+ // F8R-04:源头钳制与 gateway 对齐——自动路径同样受模型输出上限约束
1356
+ maxOutputTokens: snap?.maxOutputTokens,
1357
+ })(messages, opts);
1332
1358
  }
1333
1359
  : undefined);
1334
1360
  agent.setConvertToLlm(async (messages) => {
@@ -1360,6 +1386,7 @@ export class AgentBuilder {
1360
1386
  tools,
1361
1387
  tokenBudget: contextWindow,
1362
1388
  contextWindow,
1389
+ maxOutputTokens: snapshot?.maxOutputTokens,
1363
1390
  compactTargetTokens: this._contextAssemblerConfig?.compactTargetTokens,
1364
1391
  summarize: summarizeFn,
1365
1392
  loadCompactState: () => agent.getSessionCompactState(sessionId, agentId),
@@ -1530,10 +1557,8 @@ export class AgentBuilder {
1530
1557
 
1531
1558
  ${toolList}
1532
1559
 
1533
- Every tool call must include a short honest purpose field (verb + object + goal, e.g. "read package.json to find test script") — humans and approvers see it as the call title.
1534
-
1535
1560
  Tool selection (strict):
1536
- 1. Prefer a dedicated tool when one covers the job (file_read / file_list / file_write / file_edit / file_delete / file_mkdir / file_rename / file_copy / file_stat / file_rmdir / file_search / env_info, and any task-specific tool).
1561
+ 1. Prefer a dedicated tool when one covers the job (file_read / file_list / file_write / file_edit / file_delete / file_mkdir / file_rename / file_copy / file_stat / file_rmdir / file_search / env_info / process_list, and any task-specific tool).
1537
1562
  2. If a dedicated-tool call fails because your arguments were wrong (bad path, bad params), fix the call and retry that tool — do not switch to shell for a call you can fix.
1538
1563
  3. Use shell only when: (a) no dedicated tool covers the operation, or (b) the dedicated tool is unavailable, or (c) it still fails after a correct retry and shell is the only remaining way to make progress.
1539
1564
  4. Do not prefer shell over a working dedicated tool for the same job.
@@ -85,4 +85,9 @@ export interface BuildFromConfigOptions {
85
85
  * 委派编排开关。缺省 = 只要有 agent 声明 `delegation` 策略就接线。
86
86
  */
87
87
  delegation?: boolean;
88
+ /**
89
+ * 宿主注入的 Runner 附加配置(浅合并进每个 agent)。
90
+ * ops P2:`securityIntegrity`(安全配置漂移守卫)与 `opsAuditPath` 走此通道。
91
+ */
92
+ runnerConfig?: import('../run/runner.js').SessionAwareRunnerConfig;
88
93
  }
@@ -13,7 +13,7 @@
13
13
  * // agents.get('assistant') → { engine, runner }
14
14
  * ```
15
15
  */
16
- import { createProviderFromConfig, createWireDumpSinkFromConfig, resolveModelConfig } from '../../config.js';
16
+ import { createProviderFromConfig, createWireDumpSinkFromConfig, resolveModelConfig, wireObservability } from '../../config.js';
17
17
  import { SubsystemLoader } from '../collaboration/autonomous-subsystem/loader.js';
18
18
  import { homedir } from 'node:os';
19
19
  import { resolve, join } from 'node:path';
@@ -130,6 +130,8 @@ export async function buildFromConfig(config, options) {
130
130
  sessionIdleExpiryMs: config.session?.idleExpiryMs,
131
131
  modelCallConfig: config.modelCall,
132
132
  concurrencyConfig: config.concurrency,
133
+ observabilityConfig: config.observability,
134
+ runnerConfig: options?.runnerConfig,
133
135
  });
134
136
  agents.set(agentConfig.id, built);
135
137
  }
@@ -170,6 +172,8 @@ export async function buildFromConfig(config, options) {
170
172
  */
171
173
  async function buildAgent(agentConfig, shared) {
172
174
  const builder = new AgentBuilder();
175
+ if (shared.runnerConfig)
176
+ builder.runnerConfig(shared.runnerConfig);
173
177
  // 解析主模型 provider(宿主可在此包装 circuit breaker;config-bridge 用原始 provider)
174
178
  const resolvedModel = resolveModelConfig(agentConfig.model, shared.flatModels);
175
179
  const provider = shared.providers.get(resolvedModel.provider);
@@ -210,6 +214,8 @@ async function buildAgent(agentConfig, shared) {
210
214
  subsystemDenylist: shared.subsystemDenylist,
211
215
  concurrencyConfig: shared.concurrencyConfig,
212
216
  });
217
+ // ── 观测装配(F3/D5):observability 配置 → trace 落盘 + 采集意图 ──
218
+ await wireObservability(builder, shared.observabilityConfig, { filePrefix: agentConfig.id });
213
219
  // ── Build ──
214
220
  const built = await builder.build({
215
221
  autoLoadSubsystems: shouldAutoLoadSubsystems(shared),
@@ -0,0 +1,72 @@
1
+ /**
2
+ * 安全配置指纹与漂移守卫(ops P2,`arch/ops-privileged-mode.md` §4.3 / §8.4 拍板)
3
+ *
4
+ * 「agent 可写自身配置」是自提权面:host 模式下 agent 改写 `octopi.json` 的安全字段
5
+ * 等于自我升档。边界(§8.4):安全字段**重启才生效**,运行中检测到漂移 → **拒新 run**
6
+ * + `ops.config.security_changed`,直至宿主(重启 / WebUI 署名通道)确认。
7
+ *
8
+ * 本模块只做「指纹 + 对比」;重读配置文件由宿主注入(引擎不越界做 IO 策略)。
9
+ */
10
+ /** 安全字段指纹(锚定值 + 字段摘要) */
11
+ export interface SecurityConfigFingerprint {
12
+ /** sha256(canonicalJson(fields)) */
13
+ fingerprint: string;
14
+ /** 扁平字段摘要(`effectPolicy.jail` → 值),审计记录与 diff 用 */
15
+ fields: Record<string, unknown>;
16
+ }
17
+ /** 指纹对比结果 */
18
+ export interface SecurityConfigDrift {
19
+ ok: boolean;
20
+ /** 发生变化的字段名(指纹不同则至少一项) */
21
+ changed: string[];
22
+ /** 当前指纹(审计记录的「新摘要」) */
23
+ currentFingerprint: string;
24
+ }
25
+ /**
26
+ * 计算安全配置指纹(启动期锚定)。
27
+ *
28
+ * @param config - 已解析配置的安全相关切面(effectPolicy + security)
29
+ * @returns 指纹 + 字段摘要
30
+ */
31
+ export declare function computeSecurityConfigFingerprint(config: {
32
+ effectPolicy?: Record<string, unknown>;
33
+ security?: Record<string, unknown>;
34
+ agents?: Array<Record<string, unknown>>;
35
+ plugins?: Record<string, unknown>;
36
+ }): SecurityConfigFingerprint;
37
+ /**
38
+ * 从原始 JSON 文本提取安全字段切面(漂移复核用;不走完整 schema 解析——
39
+ * 被篡改的配置可能根本过不了 schema,指纹对比必须先于校验)。
40
+ *
41
+ * 覆盖面(§8.4 + 评审补洞):顶层 effectPolicy / security、**agents[].effectPolicy**
42
+ * (每 agent 覆盖顶层,改单个 agent 的 jail 也必须算漂移)、**agents[].tools**(工具
43
+ * allow/deny)、**plugins.loadPaths**(插件加载路径)。
44
+ *
45
+ * @param jsonText - 配置文件全文
46
+ * @returns 安全字段切面
47
+ */
48
+ export declare function extractSecurityConfigSlice(jsonText: string): {
49
+ effectPolicy: Record<string, unknown>;
50
+ security: Record<string, unknown>;
51
+ agents: Array<Record<string, unknown>>;
52
+ plugins: Record<string, unknown>;
53
+ };
54
+ /**
55
+ * 对比锚定指纹与当前指纹。
56
+ *
57
+ * @param anchor - 启动期指纹
58
+ * @param current - 当前指纹
59
+ * @returns 漂移结论(changed 为字段名列表)
60
+ */
61
+ export declare function diffSecurityConfigFingerprint(anchor: SecurityConfigFingerprint, current: SecurityConfigFingerprint): SecurityConfigDrift;
62
+ /**
63
+ * 基于配置文件的漂移复核器(宿主注入 Runner 的 `securityIntegrity.recheck`)。
64
+ *
65
+ * @param options.configPath - 配置文件绝对路径
66
+ * @param options.anchor - 启动期锚定指纹
67
+ * @returns 复核函数:ok=false 时 changed 非空
68
+ */
69
+ export declare function createFileSecurityIntegrity(options: {
70
+ configPath: string;
71
+ anchor: SecurityConfigFingerprint;
72
+ }): () => SecurityConfigDrift;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * 安全配置指纹与漂移守卫(ops P2,`arch/ops-privileged-mode.md` §4.3 / §8.4 拍板)
3
+ *
4
+ * 「agent 可写自身配置」是自提权面:host 模式下 agent 改写 `octopi.json` 的安全字段
5
+ * 等于自我升档。边界(§8.4):安全字段**重启才生效**,运行中检测到漂移 → **拒新 run**
6
+ * + `ops.config.security_changed`,直至宿主(重启 / WebUI 署名通道)确认。
7
+ *
8
+ * 本模块只做「指纹 + 对比」;重读配置文件由宿主注入(引擎不越界做 IO 策略)。
9
+ */
10
+ import { readFileSync } from 'node:fs';
11
+ import { createHash } from 'node:crypto';
12
+ /**
13
+ * 参与指纹的安全字段(§8.4:jail / escalation / effects / 审计开关 + 作用域面)。
14
+ * 键序无关;值走稳定序列化。
15
+ */
16
+ const EFFECT_POLICY_SECURITY_KEYS = [
17
+ 'mode',
18
+ 'untrustedAdmission',
19
+ 'pathContainment',
20
+ 'shellEscape',
21
+ 'jail',
22
+ 'onJailUnavailable',
23
+ 'privilegedAck',
24
+ 'effects',
25
+ 'toolIsolation',
26
+ 'opsAudit',
27
+ 'opsAuditPath',
28
+ // P5 审计外送也是安全面(换收口 = 换见证人)
29
+ 'opsAuditExportPath',
30
+ 'network',
31
+ 'escalation',
32
+ // ops P4:危险命令减速带也是安全闸(改档 = 放松/收紧确认闸,须重启 + 宿主署名)
33
+ 'dangerousCommands',
34
+ ];
35
+ const SECURITY_CONFIG_SECURITY_KEYS = ['enforce', 'injectionSensitivity', 'allowedPaths'];
36
+ function pickFields(source, keys, prefix) {
37
+ const out = {};
38
+ for (const key of keys) {
39
+ if (source[key] !== undefined)
40
+ out[`${prefix}${key}`] = source[key];
41
+ }
42
+ return out;
43
+ }
44
+ function stableStringify(value) {
45
+ if (value === null || typeof value !== 'object')
46
+ return JSON.stringify(value) ?? 'null';
47
+ if (Array.isArray(value))
48
+ return `[${value.map((v) => stableStringify(v)).join(',')}]`;
49
+ const entries = Object.entries(value)
50
+ .filter(([, v]) => v !== undefined)
51
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
52
+ return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(',')}}`;
53
+ }
54
+ /**
55
+ * 计算安全配置指纹(启动期锚定)。
56
+ *
57
+ * @param config - 已解析配置的安全相关切面(effectPolicy + security)
58
+ * @returns 指纹 + 字段摘要
59
+ */
60
+ export function computeSecurityConfigFingerprint(config) {
61
+ const fields = {
62
+ ...pickFields(config.effectPolicy ?? {}, EFFECT_POLICY_SECURITY_KEYS, 'effectPolicy.'),
63
+ ...pickFields(config.security ?? {}, SECURITY_CONFIG_SECURITY_KEYS, 'security.'),
64
+ };
65
+ // per-agent 覆盖与工具面/插件加载路径都是安全面(§8.4 补洞)
66
+ if (config.agents !== undefined)
67
+ fields['agents'] = config.agents;
68
+ if (config.plugins !== undefined && Object.keys(config.plugins).length > 0) {
69
+ fields['plugins'] = pickFields(config.plugins, ['loadPaths'], 'plugins.');
70
+ }
71
+ return {
72
+ fingerprint: createHash('sha256').update(stableStringify(fields)).digest('hex'),
73
+ fields,
74
+ };
75
+ }
76
+ /**
77
+ * 从原始 JSON 文本提取安全字段切面(漂移复核用;不走完整 schema 解析——
78
+ * 被篡改的配置可能根本过不了 schema,指纹对比必须先于校验)。
79
+ *
80
+ * 覆盖面(§8.4 + 评审补洞):顶层 effectPolicy / security、**agents[].effectPolicy**
81
+ * (每 agent 覆盖顶层,改单个 agent 的 jail 也必须算漂移)、**agents[].tools**(工具
82
+ * allow/deny)、**plugins.loadPaths**(插件加载路径)。
83
+ *
84
+ * @param jsonText - 配置文件全文
85
+ * @returns 安全字段切面
86
+ */
87
+ export function extractSecurityConfigSlice(jsonText) {
88
+ const parsed = JSON.parse(jsonText);
89
+ const rawAgents = Array.isArray(parsed.agents) ? parsed.agents : [];
90
+ const agents = rawAgents.map((a) => {
91
+ const agent = (a ?? {});
92
+ return {
93
+ id: agent.id,
94
+ tools: agent.tools,
95
+ ...pickFields((agent.effectPolicy ?? {}), EFFECT_POLICY_SECURITY_KEYS, 'effectPolicy.'),
96
+ };
97
+ });
98
+ return {
99
+ effectPolicy: (parsed.effectPolicy ?? {}),
100
+ security: (parsed.security ?? {}),
101
+ agents,
102
+ plugins: (parsed.plugins ?? {}),
103
+ };
104
+ }
105
+ /**
106
+ * 对比锚定指纹与当前指纹。
107
+ *
108
+ * @param anchor - 启动期指纹
109
+ * @param current - 当前指纹
110
+ * @returns 漂移结论(changed 为字段名列表)
111
+ */
112
+ export function diffSecurityConfigFingerprint(anchor, current) {
113
+ if (anchor.fingerprint === current.fingerprint) {
114
+ return { ok: true, changed: [], currentFingerprint: current.fingerprint };
115
+ }
116
+ const changed = new Set();
117
+ for (const key of new Set([...Object.keys(anchor.fields), ...Object.keys(current.fields)])) {
118
+ if (stableStringify(anchor.fields[key]) !== stableStringify(current.fields[key]))
119
+ changed.add(key);
120
+ }
121
+ return { ok: false, changed: [...changed].sort(), currentFingerprint: current.fingerprint };
122
+ }
123
+ /**
124
+ * 基于配置文件的漂移复核器(宿主注入 Runner 的 `securityIntegrity.recheck`)。
125
+ *
126
+ * @param options.configPath - 配置文件绝对路径
127
+ * @param options.anchor - 启动期锚定指纹
128
+ * @returns 复核函数:ok=false 时 changed 非空
129
+ */
130
+ export function createFileSecurityIntegrity(options) {
131
+ return () => {
132
+ let slice;
133
+ try {
134
+ slice = extractSecurityConfigSlice(readFileSync(options.configPath, 'utf8'));
135
+ }
136
+ catch (err) {
137
+ // 读不到/解析不了 = 无法证明未被篡改,按漂移对待(fail-closed)
138
+ return {
139
+ ok: false,
140
+ changed: [`<config unreadable: ${err instanceof Error ? err.message : String(err)}>`],
141
+ currentFingerprint: '<unreadable>',
142
+ };
143
+ }
144
+ return diffSecurityConfigFingerprint(options.anchor, computeSecurityConfigFingerprint(slice));
145
+ };
146
+ }
@@ -5,11 +5,19 @@
5
5
  * 禁止 builder / gateway / tool-bus 各自拼一套(否则模型看到的 required 不一致)。
6
6
  */
7
7
  import type { ToolDefinition, ToolParameter } from '@octopi-agent/core/types.js';
8
- /** 统一注入的行动简述参数 */
8
+ /**
9
+ * 统一注入的行动简述参数。
10
+ *
11
+ * description 只留极短 stub(schema 自解释兜底);详版+示例在 TOOL_PURPOSE_SYSTEM_NOTE
12
+ * 全局说明(system prompt 稳定块)只写一次——55 个工具不再重复同一段 157 字符文案
13
+ * (方案 S,arch/tool-call-purpose.md「演进」)。
14
+ */
9
15
  export declare const TOOL_PURPOSE_PARAM: {
10
16
  type: "string";
11
17
  description: string;
12
18
  };
19
+ /** purpose 填法的全局说明(详版与示例唯一来源;system prompt 稳定块,缓存无损) */
20
+ export declare const TOOL_PURPOSE_SYSTEM_NOTE = "### Tool call purpose\nEvery tool call MUST include a `purpose` argument: one short honest line for humans and approvers \u2014 what the call does and why (verb + object + goal, max 120 chars). Example: \"overwrite src/a.ts to fix timeout\". Never leave it empty.";
13
21
  /** 仅保留 OpenAI function calling 可识别的 JSON Schema 关键字 */
14
22
  export declare function sanitizeToolJsonSchema(node: unknown): unknown;
15
23
  /**
@@ -1,8 +1,17 @@
1
- /** 统一注入的行动简述参数 */
1
+ /**
2
+ * 统一注入的行动简述参数。
3
+ *
4
+ * description 只留极短 stub(schema 自解释兜底);详版+示例在 TOOL_PURPOSE_SYSTEM_NOTE
5
+ * 全局说明(system prompt 稳定块)只写一次——55 个工具不再重复同一段 157 字符文案
6
+ * (方案 S,arch/tool-call-purpose.md「演进」)。
7
+ */
2
8
  export const TOOL_PURPOSE_PARAM = {
3
9
  type: 'string',
4
- description: 'One short honest line for humans and approvers: what this call does and why (verb + object + goal, max 120 chars). Example: "overwrite src/a.ts to fix timeout".',
10
+ description: 'Call purpose: what + why, ≤120 chars',
5
11
  };
12
+ /** purpose 填法的全局说明(详版与示例唯一来源;system prompt 稳定块,缓存无损) */
13
+ export const TOOL_PURPOSE_SYSTEM_NOTE = `### Tool call purpose
14
+ Every tool call MUST include a \`purpose\` argument: one short honest line for humans and approvers — what the call does and why (verb + object + goal, max 120 chars). Example: "overwrite src/a.ts to fix timeout". Never leave it empty.`;
6
15
  /** 仅保留 OpenAI function calling 可识别的 JSON Schema 关键字 */
7
16
  export function sanitizeToolJsonSchema(node) {
8
17
  if (Array.isArray(node))
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import { existsSync } from 'node:fs';
15
15
  import { join } from 'node:path';
16
+ import { expandHomePath } from '../../paths.js';
16
17
  import { getOctopiHome } from '../../paths.js';
17
18
  import { DefaultRunGuard, } from '../run/run-guard/default-run-guard.js';
18
19
  import { DefaultContextEngine } from '../context/default-context-engine.js';
@@ -60,8 +61,9 @@ export function resolveContextEngine(config) {
60
61
  // 缺省 type = default:只给旋钮(如 proactiveCompactRatio)也必须落到默认引擎
61
62
  if (!config || config.type == null || config.type === 'default') {
62
63
  return new DefaultContextEngine({
63
- protectFirstN: config?.protectFirstN ?? 3,
64
+ protectFirstN: config?.protectFirstN ?? 5,
64
65
  protectLastN: config?.protectLastN ?? 20,
66
+ summaryBudget: config?.summaryBudget,
65
67
  proactiveCompactRatio: config?.proactiveCompactRatio ?? 0.6,
66
68
  proactiveCooldownMs: config?.proactiveCooldownMs ?? 30_000,
67
69
  historyAging: config?.historyAging,
@@ -166,7 +168,9 @@ export async function wireAgentBuilder(builder, spec) {
166
168
  // ── Home / Persona / Skills ──
167
169
  // stores 只跟显式 home 走;string persona 只作 prompt 目录,不隐式开 agent.db
168
170
  //(config-bridge 需要 legacy persona-as-home 时应显式传 home)。
169
- const agentHome = spec.home;
171
+ // home/skillDirectory 在库边界展开 `~`(幂等):`join()` 与 agent.db 路径都以它为基,
172
+ // 留一个未展开的 `~` 就会在进程 cwd 下建出字面 `~/…` 目录。
173
+ const agentHome = spec.home ? expandHomePath(spec.home.trim()) : undefined;
170
174
  // agentId 无条件接线(审计分区 / 工具域对称);home 只决定 agent 文件态目录
171
175
  builder.agentId(spec.agentId);
172
176
  if (spec.home) {
@@ -181,7 +185,11 @@ export async function wireAgentBuilder(builder, spec) {
181
185
  else if (agentHome) {
182
186
  builder.persona(agentHome);
183
187
  }
184
- const skillDir = spec.skillDirectory ?? (agentHome ? join(agentHome, 'skills') : undefined);
188
+ const skillDir = spec.skillDirectory
189
+ ? expandHomePath(spec.skillDirectory.trim())
190
+ : agentHome
191
+ ? join(agentHome, 'skills')
192
+ : undefined;
185
193
  let skillManager;
186
194
  if (skillDir && existsSync(skillDir)) {
187
195
  try {
@@ -6,6 +6,15 @@
6
6
  * @module autonomous-subsystem/boundary/validator
7
7
  */
8
8
  import type { SubsystemSpec } from '../types.js';
9
+ /**
10
+ * SEC-6 执行上下文:声明必须可兑现。
11
+ * `sandboxed` 是加载器的硬承诺(环境须满足 L4 process 最低线);
12
+ * `trusted | privileged` 是作者承诺(advisory,见 docs/autonomous-subsystem.md)。
13
+ */
14
+ export interface SecurityEnforcementContext {
15
+ /** 环境是否满足 L4 process 最低线(`assessL4ProcessMinimum`) */
16
+ l4Available: boolean;
17
+ }
9
18
  /**
10
19
  * 校验错误
11
20
  */
@@ -19,6 +28,7 @@ export interface ValidationError {
19
28
  * 校验 SubsystemSpec 的内部一致性
20
29
  *
21
30
  * @param spec - 子系统规格
31
+ * @param enforcement - SEC-6 执行上下文(宿主能力声明,必填:校验器不替调用方猜环境)
22
32
  * @returns 校验错误数组,空数组表示通过
23
33
  */
24
- export declare function validateSubsystemSpec(spec: SubsystemSpec): ValidationError[];
34
+ export declare function validateSubsystemSpec(spec: SubsystemSpec, enforcement: SecurityEnforcementContext): ValidationError[];
@@ -18,9 +18,10 @@ const AUTHORITY_ACT_MAP = {
18
18
  * 校验 SubsystemSpec 的内部一致性
19
19
  *
20
20
  * @param spec - 子系统规格
21
+ * @param enforcement - SEC-6 执行上下文(宿主能力声明,必填:校验器不替调用方猜环境)
21
22
  * @returns 校验错误数组,空数组表示通过
22
23
  */
23
- export function validateSubsystemSpec(spec) {
24
+ export function validateSubsystemSpec(spec, enforcement) {
24
25
  const errors = [];
25
26
  if (!spec.boundary)
26
27
  errors.push({ field: 'boundary', message: 'boundary is required' });
@@ -30,6 +31,15 @@ export function validateSubsystemSpec(spec) {
30
31
  errors.push({ field: 'act', message: 'act is required' });
31
32
  if (!spec.boundary || !spec.signal || !spec.act)
32
33
  return errors;
34
+ // ── SEC-6:`sandboxed` 声明必须可兑现(fail-closed)──
35
+ // `sandboxed` 是加载器的硬承诺:环境达不到 L4 process 最低线就拒绝加载,
36
+ // 绝不允许「看起来已沙箱」。`trusted | privileged` 是作者承诺(advisory),不在此拦截。
37
+ if (spec.boundary.security === 'sandboxed' && !enforcement.l4Available) {
38
+ errors.push({
39
+ field: 'boundary.security',
40
+ message: 'security "sandboxed" requires L4 process isolation (bwrap/Seatbelt/Job) in this environment; declare trusted/privileged explicitly or run where L4 exists',
41
+ });
42
+ }
33
43
  // ── act.mode 与 boundary.authority 交叉校验 ──
34
44
  const allowedModes = AUTHORITY_ACT_MAP[spec.boundary.authority];
35
45
  if (!allowedModes.has(spec.act.mode)) {
@@ -1,10 +1,16 @@
1
1
  import type { SubsystemSpec } from './types.js';
2
+ import { type SecurityEnforcementContext } from './boundary/validator.js';
2
3
  export interface SubsystemLoaderConfig {
3
4
  builtinDir?: string;
4
5
  userDir?: string;
5
6
  projectDir?: string;
6
7
  /** node_modules 目录(用于 npm 子系统发现) */
7
8
  npmDir?: string;
9
+ /**
10
+ * SEC-6 能力注入(测试/确定性场景)。缺省实测环境:
11
+ * `probeProcessIsolation()` + L4 process 最低线评估。
12
+ */
13
+ securityEnforcement?: SecurityEnforcementContext;
8
14
  }
9
15
  export interface LoadResult {
10
16
  specs: SubsystemSpec[];
@@ -18,7 +24,14 @@ export declare class SubsystemLoader {
18
24
  private userDir?;
19
25
  private projectDir?;
20
26
  private npmDir?;
27
+ private securityEnforcement?;
21
28
  constructor(config: SubsystemLoaderConfig);
29
+ /**
30
+ * SEC-6 能力解析:注入优先;缺省实测环境(L4 process 最低线评估)。
31
+ *
32
+ * @returns 宿主能力声明
33
+ */
34
+ private resolveSecurityEnforcement;
22
35
  loadAll(): Promise<LoadResult>;
23
36
  /**
24
37
  * 加载一级目录:单 spec 包,或多 spec 包(子目录含 config/SUBSYSTEM.md + shared 静默跳过)
@@ -2,6 +2,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { basename, join } from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
4
  import { validateSubsystemSpec } from './boundary/validator.js';
5
+ import { probeProcessIsolation, assessL4ProcessMinimum } from '../../extension/execution-environment/process-isolation.js';
5
6
  // js-yaml 自身未附带 d.ts;仅使用 load,避免为类型强装 @types(与当前 TS 版本 peer 冲突)
6
7
  // 惰性 require:包缺失时只在真正解析 YAML 时失败,不阻断模块 import
7
8
  let loadYamlFn;
@@ -17,11 +18,24 @@ export class SubsystemLoader {
17
18
  userDir;
18
19
  projectDir;
19
20
  npmDir;
21
+ securityEnforcement;
20
22
  constructor(config) {
21
23
  this.builtinDir = config.builtinDir;
22
24
  this.userDir = config.userDir;
23
25
  this.projectDir = config.projectDir;
24
26
  this.npmDir = config.npmDir;
27
+ this.securityEnforcement = config.securityEnforcement;
28
+ }
29
+ /**
30
+ * SEC-6 能力解析:注入优先;缺省实测环境(L4 process 最低线评估)。
31
+ *
32
+ * @returns 宿主能力声明
33
+ */
34
+ async resolveSecurityEnforcement() {
35
+ if (this.securityEnforcement)
36
+ return this.securityEnforcement;
37
+ const profile = await probeProcessIsolation();
38
+ return { l4Available: assessL4ProcessMinimum(profile).ok };
25
39
  }
26
40
  async loadAll() {
27
41
  const specs = new Map();
@@ -188,7 +202,8 @@ export class SubsystemLoader {
188
202
  if (missingExplicitFields.length > 0) {
189
203
  return { error: `Missing required explicit fields: ${missingExplicitFields.join(', ')}` };
190
204
  }
191
- const errors = validateSubsystemSpec(spec);
205
+ const enforcement = await this.resolveSecurityEnforcement();
206
+ const errors = validateSubsystemSpec(spec, enforcement);
192
207
  if (errors.length > 0) {
193
208
  return { error: `Validation failed: ${errors.map((e) => `${e.field}: ${e.message}`).join('; ')}` };
194
209
  }