@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.
- package/dist/config-admin/agent-presets.d.ts +70 -0
- package/dist/config-admin/agent-presets.js +243 -0
- package/dist/config-admin/discover.d.ts +30 -0
- package/dist/config-admin/discover.js +48 -0
- package/dist/config-admin/env.d.ts +22 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/index.d.ts +20 -0
- package/dist/config-admin/index.js +15 -0
- package/dist/config-admin/model-presets.d.ts +75 -0
- package/dist/config-admin/model-presets.js +249 -0
- package/dist/config-admin/name-guard.d.ts +14 -0
- package/dist/config-admin/name-guard.js +24 -0
- package/dist/config-admin/patch.d.ts +56 -0
- package/dist/config-admin/patch.js +201 -0
- package/dist/config-admin/port.d.ts +68 -0
- package/dist/config-admin/port.js +21 -0
- package/dist/config-admin/redact.d.ts +39 -0
- package/dist/config-admin/redact.js +42 -0
- package/dist/config-schema/agent.d.ts +43 -1
- package/dist/config-schema/agent.js +12 -5
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +110 -8
- package/dist/config-schema/governance.d.ts +43 -1
- package/dist/config-schema/governance.js +160 -2
- package/dist/config-schema/models.d.ts +7 -4
- package/dist/config-schema/models.js +4 -1
- package/dist/config-schema/observability.d.ts +9 -0
- package/dist/config-schema/observability.js +29 -0
- package/dist/config-schema/run.d.ts +3 -0
- package/dist/config-schema/run.js +14 -0
- package/dist/config-schema/shared.d.ts +3 -0
- package/dist/config-schema/shared.js +12 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config.d.ts +60 -13
- package/dist/config.js +81 -78
- package/dist/harness/activation/dispatcher.d.ts +8 -2
- package/dist/harness/activation/dispatcher.js +33 -5
- package/dist/harness/activation/inbox.d.ts +87 -0
- package/dist/harness/activation/inbox.js +169 -0
- package/dist/harness/activation/runtime.d.ts +9 -8
- package/dist/harness/activation/runtime.js +100 -8
- package/dist/harness/activation/types.d.ts +19 -0
- package/dist/harness/activation/types.js +2 -0
- package/dist/harness/agent/builder.d.ts +18 -3
- package/dist/harness/agent/builder.js +42 -17
- package/dist/harness/agent/config-bridge.d.ts +5 -0
- package/dist/harness/agent/config-bridge.js +7 -1
- package/dist/harness/agent/config-integrity.d.ts +72 -0
- package/dist/harness/agent/config-integrity.js +146 -0
- package/dist/harness/agent/tool-purpose.d.ts +9 -1
- package/dist/harness/agent/tool-purpose.js +11 -2
- package/dist/harness/agent/wire-agent-builder.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +3 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
- package/dist/harness/collaboration/delegation/child-run.js +21 -5
- package/dist/harness/collaboration/delegation/notifier.js +4 -3
- package/dist/harness/collaboration/delegation/service.js +2 -3
- package/dist/harness/collaboration/delegation/wiring.js +6 -5
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
- package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
- package/dist/harness/context/capabilities/compact/engine.js +198 -46
- package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
- package/dist/harness/context/capabilities/compact/handover.js +107 -0
- package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
- package/dist/harness/context/capabilities/compact/index.js +2 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
- package/dist/harness/context/capabilities/summary/executor.js +2 -1
- package/dist/harness/context/capabilities/summary/policies.js +8 -5
- package/dist/harness/context/constitution/default-agents.md +11 -10
- package/dist/harness/context/default-context-engine.d.ts +34 -4
- package/dist/harness/context/default-context-engine.js +198 -53
- package/dist/harness/context/hybrid-compressor.js +6 -0
- package/dist/harness/context/layer-types.d.ts +36 -0
- package/dist/harness/context/layer-types.js +38 -0
- package/dist/harness/context/llm-summarizer.d.ts +2 -8
- package/dist/harness/context/llm-summarizer.js +69 -91
- package/dist/harness/context/message-selector.js +4 -3
- package/dist/harness/context/root-instructions.js +1 -1
- package/dist/harness/context/summarize.d.ts +2 -0
- package/dist/harness/context/summarize.js +7 -2
- package/dist/harness/context/system-prompt-assembler.js +10 -4
- package/dist/harness/context/tool-result-aging.js +2 -2
- package/dist/harness/context/truncate-compressor.js +7 -0
- package/dist/harness/context/turn-envelope.d.ts +4 -3
- package/dist/harness/context/turn-envelope.js +4 -3
- package/dist/harness/context/types.d.ts +33 -1
- package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
- package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +133 -4
- package/dist/harness/extension/execution-environment/effect-policy.js +263 -14
- package/dist/harness/extension/execution-environment/index.d.ts +4 -2
- package/dist/harness/extension/execution-environment/index.js +2 -1
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
- package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +200 -0
- package/dist/harness/extension/execution-environment/ops-audit.js +338 -0
- package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
- package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
- package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
- package/dist/harness/extension/execution-environment/process-info.js +466 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
- package/dist/harness/extension/execution-environment/sandbox.js +264 -29
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
- package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
- package/dist/harness/extension/execution-environment/types.d.ts +19 -0
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +50 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +53 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +10 -17
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +8 -8
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +9 -100
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
- package/dist/harness/governance/security/temp-path.d.ts +9 -0
- package/dist/harness/governance/security/temp-path.js +13 -2
- package/dist/harness/governance/session-acl/seed-roles.js +14 -0
- package/dist/harness/index.d.ts +4 -0
- package/dist/harness/index.js +3 -0
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/fts.js +1 -2
- package/dist/harness/knowledge/grounding.js +5 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +180 -48
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +150 -150
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- package/dist/harness/observability/observer/hub.js +38 -1
- package/dist/harness/observability/observer/run-snapshot.js +1 -0
- package/dist/harness/observability/observer/types.d.ts +27 -0
- package/dist/harness/run/agent/agent.d.ts +7 -0
- package/dist/harness/run/agent/agent.js +23 -1
- package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
- package/dist/harness/run/reliability/fallback-provider.js +262 -22
- package/dist/harness/run/reliability/harness-events.d.ts +24 -1
- package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
- package/dist/harness/run/reliability/model-error-policy.js +42 -0
- package/dist/harness/run/reliability/provider-wrapper.js +29 -2
- package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
- package/dist/harness/run/reliability/refusal-guard.js +102 -0
- package/dist/harness/run/reliability/run-agent.js +231 -33
- package/dist/harness/run/run-guard/default-run-guard.js +1 -1
- package/dist/harness/run/run-scope.d.ts +31 -0
- package/dist/harness/run/runner.d.ts +132 -2
- package/dist/harness/run/runner.js +679 -60
- package/dist/harness/session/attachments/llm-intent.js +2 -1
- package/dist/harness/session/history/port.js +15 -5
- package/dist/harness/session/in-memory-store.d.ts +5 -0
- package/dist/harness/session/in-memory-store.js +33 -2
- package/dist/harness/session/tasks/render.d.ts +4 -1
- package/dist/harness/session/tasks/render.js +10 -7
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/shared/events/agent-event-map.d.ts +92 -0
- package/dist/harness/shared/events/agent-event-map.js +7 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -3
- package/dist/integration/agent-runtime/channel-message-source.js +19 -1
- package/dist/integration/index.d.ts +2 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/observability/loop-watchdog.d.ts +56 -0
- package/dist/integration/observability/loop-watchdog.js +177 -0
- package/dist/integration/observability/metrics.d.ts +3 -0
- package/dist/integration/observability/metrics.js +18 -7
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +23 -0
- package/dist/integration/providers/anthropic.js +97 -12
- package/dist/integration/providers/fetch-timeout.d.ts +42 -0
- package/dist/integration/providers/fetch-timeout.js +51 -0
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -11
- package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
- package/dist/integration/providers/provider-diagnostics.js +89 -0
- package/dist/integration/providers/timeout-coherence.d.ts +52 -0
- package/dist/integration/providers/timeout-coherence.js +68 -0
- package/dist/integration/providers/wire-dump.d.ts +62 -0
- package/dist/integration/providers/wire-dump.js +111 -2
- package/dist/integration/storage/jsonl.d.ts +19 -1
- package/dist/integration/storage/jsonl.js +100 -4
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +1 -1
- package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
- package/package.json +3 -2
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* 见 arch/tool-effect-policy.md §7。
|
|
6
6
|
*/
|
|
7
7
|
import { isAbsolute, resolve } from 'node:path';
|
|
8
|
+
import { expandHomePath } from '../../../paths.js';
|
|
9
|
+
import { checkEscalationBinary, escalationRuleTargets, escalationWritableRoots, } from './privileged-exec.js';
|
|
8
10
|
import { deniesReducedSurface, resolveToolCapabilities, } from './tool-capabilities.js';
|
|
9
11
|
import { assessL4ProcessMinimum, } from './process-isolation.js';
|
|
10
|
-
import {
|
|
12
|
+
import { resolveHitlOutcome } from '../../governance/human-in-the-loop/decision-cache.js';
|
|
11
13
|
import { getRunSessionId, getRunScope } from '../../run/run-scope.js';
|
|
12
14
|
/**
|
|
13
15
|
* Engine default when `effectPolicy.mode` is omitted (secure-by-default).
|
|
@@ -68,6 +70,69 @@ const MODE_DEFAULTS = {
|
|
|
68
70
|
shellJournal: 'snapshot',
|
|
69
71
|
},
|
|
70
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* Whether the resolved policy demands a process jail — fail-closed when the
|
|
75
|
+
* jail cannot be applied (ops P0: `jail: require`, `onJailUnavailable: refuse`,
|
|
76
|
+
* or untrusted that survived untrusted admission). Single predicate shared by
|
|
77
|
+
* the run path (runner) and host-side read surfaces (WebUI git status endpoint)
|
|
78
|
+
* so the isolation level never drifts between them.
|
|
79
|
+
*
|
|
80
|
+
* @param eff - resolved effective policy
|
|
81
|
+
* @returns true when a missing/broken jail must refuse execution
|
|
82
|
+
*/
|
|
83
|
+
export function requiresJail(eff) {
|
|
84
|
+
// jail=none 是授权无笼:onJailUnavailable 对它无意义,不得误报「要求笼」
|
|
85
|
+
if (eff.jail === 'none')
|
|
86
|
+
return false;
|
|
87
|
+
if (eff.jail === 'require' || eff.onJailUnavailable === 'refuse')
|
|
88
|
+
return true;
|
|
89
|
+
return eff.requestedMode === 'untrusted' && eff.mode === 'untrusted';
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 白名单提权全等匹配(§5 P3):`cmd` 绝对路径比对 + `args` 逐项全等。
|
|
93
|
+
* 不做前缀/正则/插值——任何「宽松匹配」都会把 allowlist 变成任意命令通道。
|
|
94
|
+
*
|
|
95
|
+
* @param escalation - resolved 提权策略
|
|
96
|
+
* @param cmd - 请求的可执行文件(必须与规则逐字相同)
|
|
97
|
+
* @param args - 请求的 argv 尾部
|
|
98
|
+
* @returns 命中的规则与稳定 ruleId;未命中 null
|
|
99
|
+
*/
|
|
100
|
+
export function matchEscalationRule(escalation, cmd, args) {
|
|
101
|
+
if (escalation.policy !== 'allowlist')
|
|
102
|
+
return null;
|
|
103
|
+
for (let i = 0; i < escalation.allow.length; i += 1) {
|
|
104
|
+
const rule = escalation.allow[i];
|
|
105
|
+
const ruleArgs = rule.args ?? [];
|
|
106
|
+
if (rule.cmd === cmd &&
|
|
107
|
+
ruleArgs.length === args.length &&
|
|
108
|
+
ruleArgs.every((a, idx) => a === args[idx])) {
|
|
109
|
+
// 显式 id 优先(下标 id 在规则重排后会断裂审计关联)
|
|
110
|
+
return { rule, ruleId: rule.id ?? `allow[${i}]` };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 构造 run 开始即记录的 `ops.jail.state`(意图 × 实测后端)。
|
|
117
|
+
* 「主动选择无约束」(authorized, intent=none)与「被动失去约束」
|
|
118
|
+
* (authorized=false, 缺笼降级)事后可分辨即靠这条记录。
|
|
119
|
+
*
|
|
120
|
+
* @param eff - 解析后的有效策略
|
|
121
|
+
* @param isolation - probe 到的隔离画像(缺省按「无笼」)
|
|
122
|
+
* @returns jail 状态记录
|
|
123
|
+
*/
|
|
124
|
+
export function buildOpsJailState(eff, isolation) {
|
|
125
|
+
const l4 = isolation ? assessL4ProcessMinimum(isolation) : { ok: false };
|
|
126
|
+
const jailAvailable = l4.ok;
|
|
127
|
+
return {
|
|
128
|
+
intent: eff.jail,
|
|
129
|
+
backend: isolation?.backend ?? 'unknown',
|
|
130
|
+
jailAvailable,
|
|
131
|
+
// none = 授权无笼;其余意图下只有笼按意图就位才是授权态
|
|
132
|
+
authorized: eff.jail === 'none' || jailAvailable,
|
|
133
|
+
degraded: [...eff.securityDegraded],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
71
136
|
/**
|
|
72
137
|
* 展开 effectPolicy 为有效策略
|
|
73
138
|
*
|
|
@@ -90,8 +155,60 @@ const MODE_DEFAULTS = {
|
|
|
90
155
|
* @throws Error when untrusted is refused
|
|
91
156
|
*/
|
|
92
157
|
export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
158
|
+
// `~` 前缀收口展开(Windows/Linux/macOS 通用):下游 allowRoots / tool cwd 只见
|
|
159
|
+
// 绝对路径;配置层(ConfigPathSchema)已先拒相对路径。顺序固定「trim → expand」,
|
|
160
|
+
// 库调用面传入带空白的 ` ~/x` 同样归一。
|
|
161
|
+
config = {
|
|
162
|
+
...config,
|
|
163
|
+
...(config.transactionRoots
|
|
164
|
+
? { transactionRoots: config.transactionRoots.map((r) => expandHomePath(r.trim())) }
|
|
165
|
+
: {}),
|
|
166
|
+
};
|
|
167
|
+
baseWorkspace =
|
|
168
|
+
baseWorkspace !== undefined ? expandHomePath(baseWorkspace.trim()) : baseWorkspace;
|
|
93
169
|
const requestedMode = config.mode ?? DEFAULT_EFFECT_RUN_MODE;
|
|
94
170
|
const untrustedAdmission = config.untrustedAdmission ?? 'refuse';
|
|
171
|
+
// ops P0:jail 意图先解析;**纯配置矛盾 fail-closed 先于任何探测分支**——
|
|
172
|
+
// 矛盾是配置事实,不该被「先撞上缺笼」抢先抛成另一种错误
|
|
173
|
+
const jail = config.jail ?? 'auto';
|
|
174
|
+
const onJailUnavailable = config.onJailUnavailable ?? 'degrade';
|
|
175
|
+
// ops P4 §4.1:full 档纯配置矛盾——同上原则,先于任何探测分支(矛盾是配置事实,
|
|
176
|
+
// 不该被「先撞上缺笼/缺 ack」抢先抛成另一种错误)
|
|
177
|
+
if (config.escalation?.policy === 'full') {
|
|
178
|
+
if (requestedMode !== 'host') {
|
|
179
|
+
throw new Error('effect_policy_invalid: escalation.policy=full requires mode=host (explicitly designated machine)');
|
|
180
|
+
}
|
|
181
|
+
if (jail !== 'none') {
|
|
182
|
+
throw new Error('effect_policy_invalid: escalation.policy=full requires jail=none (whole-shell freedom contradicts a jailed shell)');
|
|
183
|
+
}
|
|
184
|
+
if (!config.privilegedAck?.trim()) {
|
|
185
|
+
throw new Error('effect_policy_invalid: escalation.policy=full requires effectPolicy.privilegedAck (explicit privileged declaration)');
|
|
186
|
+
}
|
|
187
|
+
if ((config.escalation.allow ?? []).length > 0) {
|
|
188
|
+
// 死键 fail-loud:full 档没有 allowlist 面,静默忽略会误导配置读者
|
|
189
|
+
throw new Error('effect_policy_invalid: escalation.policy=full takes no escalation.allow rules (remove them, or use policy=allowlist)');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (jail === 'none') {
|
|
193
|
+
if (requestedMode === 'untrusted') {
|
|
194
|
+
throw new Error('effect_policy_invalid: jail=none cannot combine with mode=untrusted (untrusted promises a jail)');
|
|
195
|
+
}
|
|
196
|
+
if (!config.privilegedAck?.trim()) {
|
|
197
|
+
throw new Error('effect_policy_invalid: jail=none requires effectPolicy.privilegedAck (explicit unjailed choice)');
|
|
198
|
+
}
|
|
199
|
+
if (onJailUnavailable === 'refuse') {
|
|
200
|
+
// 死键 fail-loud:none 下该旋钮无指代,静默忽略会误导配置读者
|
|
201
|
+
throw new Error('effect_policy_invalid: onJailUnavailable=refuse has no meaning under jail=none (remove it, or use jail=auto/require)');
|
|
202
|
+
}
|
|
203
|
+
if (config.network === 'deny' || config.network === 'allowlist') {
|
|
204
|
+
// 网络限制只由 jail 实施:无笼时 deny/allowlist 是无法兑现的承诺,拒绝作假
|
|
205
|
+
throw new Error('effect_policy_invalid: network=deny/allowlist cannot be enforced under jail=none (network is jail-implemented only)');
|
|
206
|
+
}
|
|
207
|
+
// 授权无笼:不为 jail 记 securityDegraded(这是授权,不是降级)
|
|
208
|
+
}
|
|
209
|
+
else if ((jail === 'require' || onJailUnavailable === 'refuse') && untrustedAdmission === 'degrade') {
|
|
210
|
+
throw new Error('effect_policy_invalid: jail=require/onJailUnavailable=refuse contradicts untrustedAdmission=degrade (same condition, opposite outcomes)');
|
|
211
|
+
}
|
|
95
212
|
let mode = requestedMode;
|
|
96
213
|
let toolSurface = 'full';
|
|
97
214
|
const securityDegraded = [];
|
|
@@ -99,6 +216,13 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
99
216
|
const profile = isolation;
|
|
100
217
|
const l4 = profile ? assessL4ProcessMinimum(profile) : { ok: false, missing: ['processTree'] };
|
|
101
218
|
if (!l4.ok) {
|
|
219
|
+
if (config.jail === 'require' || config.onJailUnavailable === 'refuse') {
|
|
220
|
+
// jail 意图 fail-closed 优先且错误码/建议指向 jail 旋钮(untrustedAdmission=degrade
|
|
221
|
+
// 与该组合矛盾,配置校验已拒,不能在这里推荐它)
|
|
222
|
+
throw new Error(`jail_required_unavailable: effectPolicy.jail=${config.jail ?? 'auto'} ` +
|
|
223
|
+
`(onJailUnavailable=${config.onJailUnavailable ?? 'degrade'}) but no process jail ` +
|
|
224
|
+
`(missing: ${l4.missing.join(', ')}). Install bwrap/sandbox-exec, or set jail=none with privilegedAck.`);
|
|
225
|
+
}
|
|
102
226
|
if (untrustedAdmission === 'refuse') {
|
|
103
227
|
throw new Error(`untrusted_refused: L4 process jail unavailable (missing: ${l4.missing.join(', ')}). ` +
|
|
104
228
|
`Install bwrap/sandbox-exec or set effectPolicy.untrustedAdmission=degrade.`);
|
|
@@ -121,6 +245,62 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
121
245
|
securityDegraded.push('network_open');
|
|
122
246
|
}
|
|
123
247
|
}
|
|
248
|
+
// ops P0:jail 可用性申报(纯配置矛盾已在上方先拒)。授权(none)≠ 降级(缺笼)。
|
|
249
|
+
if (jail !== 'none') {
|
|
250
|
+
const l4 = isolation
|
|
251
|
+
? assessL4ProcessMinimum(isolation)
|
|
252
|
+
: { ok: false, missing: ['processTree'] };
|
|
253
|
+
if (!l4.ok) {
|
|
254
|
+
if (jail === 'require' || onJailUnavailable === 'refuse') {
|
|
255
|
+
throw new Error(`jail_required_unavailable: effectPolicy.jail=${jail} (onJailUnavailable=${onJailUnavailable}) ` +
|
|
256
|
+
`but no process jail (missing: ${l4.missing.join(', ')}). ` +
|
|
257
|
+
`Install bwrap/sandbox-exec, or set jail=none with privilegedAck.`);
|
|
258
|
+
}
|
|
259
|
+
// degrade:run 级如实申报(untrusted 降级路径可能已记,去重)
|
|
260
|
+
if (!securityDegraded.includes('no_process_jail'))
|
|
261
|
+
securityDegraded.push('no_process_jail');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// ops P3:提权策略(§4.1)。纯配置矛盾 fail-closed;allowlist 二进制 TOCTOU 护栏
|
|
265
|
+
// 同步兜底(库路径无 daemon 启动探测时也不能放行可换二进制)。
|
|
266
|
+
const escalation = {
|
|
267
|
+
policy: config.escalation?.policy ?? 'none',
|
|
268
|
+
via: config.escalation?.via ?? 'sudo',
|
|
269
|
+
allow: config.escalation?.allow ?? [],
|
|
270
|
+
};
|
|
271
|
+
if (escalation.policy !== 'none') {
|
|
272
|
+
if (requestedMode === 'untrusted') {
|
|
273
|
+
// untrusted 的产品承诺就是笼;「越笼」提权通道与之矛盾(§4.1 同类拒绝)
|
|
274
|
+
throw new Error('effect_policy_invalid: escalation cannot combine with mode=untrusted (untrusted promises a jail)');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// (full 档纯配置矛盾已在最前 fail-closed,此处只剩 allowlist 的 TOCTOU 护栏)
|
|
278
|
+
if (escalation.policy === 'allowlist') {
|
|
279
|
+
if (escalation.allow.length === 0) {
|
|
280
|
+
throw new Error('effect_policy_invalid: escalation.policy=allowlist requires escalation.allow rules');
|
|
281
|
+
}
|
|
282
|
+
// 可写根统一口径(与 daemon 启动探测共用 escalationWritableRoots,防两处漂移)
|
|
283
|
+
const writableRoots = escalationWritableRoots({
|
|
284
|
+
workspaces: baseWorkspace !== undefined ? [baseWorkspace] : [],
|
|
285
|
+
transactionRoots: (config.transactionRoots ?? []).map((r) => expandHomePath(r)),
|
|
286
|
+
});
|
|
287
|
+
for (const rule of escalation.allow) {
|
|
288
|
+
if (!isAbsolute(rule.cmd)) {
|
|
289
|
+
throw new Error(`effect_policy_invalid: escalation rule cmd must be absolute, got ${JSON.stringify(rule.cmd)}`);
|
|
290
|
+
}
|
|
291
|
+
// 有效目标逐个过 TOCTOU 护栏(via: sudo 形态含 sudo 之后的真实二进制)
|
|
292
|
+
const targets = escalationRuleTargets(rule, escalation.via);
|
|
293
|
+
if ('invalid' in targets) {
|
|
294
|
+
throw new Error(`effect_policy_invalid: escalation rule rejected (${targets.invalid})`);
|
|
295
|
+
}
|
|
296
|
+
for (const target of targets.targets) {
|
|
297
|
+
const bad = checkEscalationBinary(target, writableRoots);
|
|
298
|
+
if (bad) {
|
|
299
|
+
throw new Error(`effect_policy_invalid: escalation rule rejected (${bad})`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
124
304
|
// Path jail is part of the untrusted promise; never loosen it from config.
|
|
125
305
|
const d = MODE_DEFAULTS[mode];
|
|
126
306
|
const pathContainment = requestedMode === 'untrusted'
|
|
@@ -142,9 +322,13 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
142
322
|
// degraded untrusted must not leave shell allow as a hole
|
|
143
323
|
shellEscape: toolSurface === 'reduced' ? 'deny' : (config.shellEscape ?? d.shellEscape),
|
|
144
324
|
// untrusted product promise: egress deny is not a config knob (like pathContainment)
|
|
325
|
+
// jail=none:网络限制只由 jail 实施,无笼时 deny 是假承诺——显式配置已在上方拒绝,
|
|
326
|
+
// 未指定则如实取 open(§4.2 注记带 network=open)
|
|
145
327
|
network: requestedMode === 'untrusted' || toolSurface === 'reduced'
|
|
146
328
|
? 'deny'
|
|
147
|
-
:
|
|
329
|
+
: jail === 'none'
|
|
330
|
+
? 'open'
|
|
331
|
+
: (config.network ?? d.network),
|
|
148
332
|
processLimits: config.processLimits ?? d.processLimits,
|
|
149
333
|
commit: config.commit ?? d.commit,
|
|
150
334
|
onClose,
|
|
@@ -158,6 +342,18 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
158
342
|
undoLimit: config.undoLimit,
|
|
159
343
|
shellJournal: config.shellJournal ?? 'snapshot',
|
|
160
344
|
shellJournalLimit: config.shellJournalLimit,
|
|
345
|
+
jail,
|
|
346
|
+
onJailUnavailable,
|
|
347
|
+
escalation,
|
|
348
|
+
// 特权上下文(§5 P4/§8.1):授权态标记,不是降级;root/elevated 维度由启动期探测叠加
|
|
349
|
+
privileged: jail === 'none' || escalation.policy === 'full',
|
|
350
|
+
dangerousCommands: {
|
|
351
|
+
policy: config.dangerousCommands?.policy ?? 'confirm',
|
|
352
|
+
timeoutMs: config.dangerousCommands?.timeoutMs ?? 120_000,
|
|
353
|
+
},
|
|
354
|
+
opsAudit: config.opsAudit ?? 'on',
|
|
355
|
+
opsAuditPath: config.opsAuditPath,
|
|
356
|
+
opsAuditExportPath: config.opsAuditExportPath,
|
|
161
357
|
};
|
|
162
358
|
}
|
|
163
359
|
/**
|
|
@@ -198,19 +394,39 @@ export function isPathAllowed(resolved, allowRoots, containment) {
|
|
|
198
394
|
return target === r || target.startsWith(r + '/');
|
|
199
395
|
});
|
|
200
396
|
}
|
|
397
|
+
/** 效应确认缓存 key(含目标):一次点头只覆盖同一目标,不按 kind 一类放行 */
|
|
398
|
+
function effectCacheKey(intent) {
|
|
399
|
+
switch (intent.kind) {
|
|
400
|
+
case 'file.write':
|
|
401
|
+
return `file.write:${intent.path}`;
|
|
402
|
+
case 'shell':
|
|
403
|
+
return `shell:${intent.command}`;
|
|
404
|
+
case 'runner':
|
|
405
|
+
return `runner:${intent.command}`;
|
|
406
|
+
case 'vcs':
|
|
407
|
+
return `vcs:${intent.operation}:${intent.cwd ?? ''}`;
|
|
408
|
+
case 'memory.write':
|
|
409
|
+
return `memory.write:${intent.domain}`;
|
|
410
|
+
case 'other':
|
|
411
|
+
return `other:${intent.description}`;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
201
414
|
/**
|
|
202
415
|
* 效应闸(P4):事务内自动放行;host-gate 交给宿主;engine 通道按内置策略。
|
|
203
416
|
*
|
|
204
417
|
* @param intent - 效应意图
|
|
205
418
|
* @param options - 通道与回调
|
|
206
|
-
* @
|
|
419
|
+
* @returns 放行结论(confirmed/confirmSource + 确认人归因,审计用)
|
|
420
|
+
* @throws Error 当拒绝执行时(`effect_confirm_timeout` 超时 / `effect_denied` 拒绝,语义分家)
|
|
207
421
|
*/
|
|
208
422
|
export async function gateEffect(intent, options) {
|
|
209
423
|
// 可事务化(可 undo)→ 自动
|
|
210
|
-
if (intent.kind === 'memory.write' && intent.transactional)
|
|
211
|
-
return;
|
|
212
|
-
|
|
213
|
-
|
|
424
|
+
if (intent.kind === 'memory.write' && intent.transactional) {
|
|
425
|
+
return { confirmed: false, confirmSource: 'auto-transaction' };
|
|
426
|
+
}
|
|
427
|
+
if (intent.kind === 'file.write' && intent.transactional) {
|
|
428
|
+
return { confirmed: false, confirmSource: 'auto-transaction' };
|
|
429
|
+
}
|
|
214
430
|
if (intent.kind === 'shell') {
|
|
215
431
|
const esc = options.shellEscape ?? 'allow';
|
|
216
432
|
// deny:无 L4 无法只禁越界,必须拒绝 shell(fail-closed,保策略语义)
|
|
@@ -226,25 +442,58 @@ export async function gateEffect(intent, options) {
|
|
|
226
442
|
// shellEscape gates the shell tool only — workspace stays capable of git/project scripts.
|
|
227
443
|
if (options.effects !== 'host-gate') {
|
|
228
444
|
// engine 通道:路径牢笼由 L2 承担;shell 已在上方按 shellEscape 处理
|
|
229
|
-
return;
|
|
445
|
+
return { confirmed: false, confirmSource: 'auto-engine' };
|
|
230
446
|
}
|
|
231
447
|
// host-gate:非事务效应交给宿主(自动放行 / 宿主 UI / 策略引擎)
|
|
232
448
|
const decide = options.confirmEffect;
|
|
233
449
|
if (!decide) {
|
|
234
450
|
throw new Error('confirm_effect_missing: effectPolicy.effects=host-gate requires confirmEffect callback');
|
|
235
451
|
}
|
|
236
|
-
// SEC-7:HitlDecision + 引擎缓存;失败路径 fail-closed
|
|
237
|
-
|
|
452
|
+
// SEC-7:HitlDecision + 引擎缓存;失败路径 fail-closed。
|
|
453
|
+
// 缓存 key 含目标(B(c) 拍板 2026-10-26):一次 approve_session 只覆盖同一目标,
|
|
454
|
+
// 不再按 kind 一类放行(旧「有意粗粒度」已翻案,见 KNOWN-ISSUES)
|
|
455
|
+
const outcome = await resolveHitlOutcome({
|
|
238
456
|
cache: options.hitlCache,
|
|
239
457
|
channel: 'effect',
|
|
240
|
-
key: intent
|
|
458
|
+
key: effectCacheKey(intent),
|
|
241
459
|
sessionId: options.sessionId ?? getRunSessionId(),
|
|
242
460
|
agentId: options.agentId ?? getRunScope()?.agentId,
|
|
243
|
-
|
|
461
|
+
// 宿主可返回裸 HitlDecision 或 ConfirmOutcome(带归因/来源);归因随结果回传审计
|
|
462
|
+
ask: async () => {
|
|
463
|
+
const raw = await decide(intent);
|
|
464
|
+
const normalized = typeof raw === 'string' ? { decision: raw } : raw;
|
|
465
|
+
return {
|
|
466
|
+
decision: normalized.decision,
|
|
467
|
+
...(normalized.approver !== undefined ? { approver: normalized.approver } : {}),
|
|
468
|
+
...(normalized.channel !== undefined ? { channel: normalized.channel } : {}),
|
|
469
|
+
// 宿主标注的拒绝来源:timeout 归超时语义;其余归通道故障——不得冒充人工拒绝
|
|
470
|
+
...(normalized.decision === 'deny' && normalized.reason === 'timeout'
|
|
471
|
+
? { timedOut: true }
|
|
472
|
+
: {}),
|
|
473
|
+
...(normalized.decision === 'deny' &&
|
|
474
|
+
normalized.reason !== undefined &&
|
|
475
|
+
normalized.reason !== 'timeout'
|
|
476
|
+
? { denyReason: 'channel_error', denyDetail: normalized.reason }
|
|
477
|
+
: {}),
|
|
478
|
+
};
|
|
479
|
+
},
|
|
244
480
|
});
|
|
245
|
-
if (!allowed) {
|
|
246
|
-
|
|
481
|
+
if (!outcome.allowed) {
|
|
482
|
+
// 错误面分家(与审计 why 同一口径):超时 ≠ 人工拒绝 ≠ 通道故障,不得混为一谈
|
|
483
|
+
if (outcome.timedOut) {
|
|
484
|
+
throw new Error(`effect_confirm_timeout: no decision for ${effectCacheKey(intent)} — timeout is deny; do NOT retry this call until a human decides`);
|
|
485
|
+
}
|
|
486
|
+
const provenance = outcome.denyReason
|
|
487
|
+
? ` (${outcome.denyReason}${outcome.denyDetail ? `: ${outcome.denyDetail}` : ''})`
|
|
488
|
+
: '';
|
|
489
|
+
throw new Error(`effect_denied: ${intent.kind}${provenance} — ${outcome.denyReason ? 'no human decision was reached' : 'a human rejected this effect'}`);
|
|
247
490
|
}
|
|
491
|
+
return {
|
|
492
|
+
confirmed: true,
|
|
493
|
+
confirmSource: 'host-gate',
|
|
494
|
+
...(outcome.approver !== undefined ? { confirmedBy: outcome.approver } : {}),
|
|
495
|
+
...(outcome.channel !== undefined ? { confirmChannel: outcome.channel } : {}),
|
|
496
|
+
};
|
|
248
497
|
}
|
|
249
498
|
const EFFECT_OVERRIDES_META_KEY = 'effectOverrides';
|
|
250
499
|
/**
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, supervisedSpawnProfile, } from './sandbox.js';
|
|
8
8
|
export { probeProcessIsolation, scrubEnv, killProcessTree, L4_PROCESS_MINIMUM, } from './process-isolation.js';
|
|
9
9
|
export type { ProcessIsolationProfile, IsolationBackend, ProcessTreeIsolation, FilesystemIsolation, ResourceIsolation, NetworkIsolation, PrivilegeIsolation, EnvHygiene, L4ProcessAssessment, } from './process-isolation.js';
|
|
10
|
+
export { listProcesses, getAncestorPidChain, resolveProcessImage, buildAncestorChain, selectProcesses, parsePsProcessTable, parseCpuTimeToMs, parseProcPidEntry, parsePowerShellProcessTable, firstExecutableFromLsof, } from './process-info.js';
|
|
11
|
+
export type { ProcessInfoEntry, ProcessListResult, ListProcessesOptions, SelectedProcesses, AncestorChain, TableParseResult, } from './process-info.js';
|
|
10
12
|
export { FileWorkspace } from './workspace.js';
|
|
11
13
|
export type { FileWorkspaceConfig } from './workspace.js';
|
|
12
14
|
export { DEFAULT_TOOL_ISOLATION, resolveToolIsolationCwd, safeSessionDirSegment, looksLikeAbsoluteSessionPath, } from './isolation.js';
|
|
@@ -15,8 +17,8 @@ export { TurnFileUndoLog, commitSessionFileUndo, discardSessionFileUndo, resolve
|
|
|
15
17
|
export type { SessionUndoPaths, FileUndoEntry, DiscardFileEffectsResult, DiscardConflictReason, } from './undo-log.js';
|
|
16
18
|
export { isProbablyText, reverseAgentOverwrite, merge3Lines } from './undo-merge.js';
|
|
17
19
|
export { snapshotShellRoots, captureShellInventory, diffShellInventory, journalShellDiff, writeNotReversed, } from './shell-journal.js';
|
|
18
|
-
export { resolveEffectiveEffectPolicy, isPathAllowed, isToolAllowedOnSurface, gateEffect, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './effect-policy.js';
|
|
19
|
-
export type { UntrustedAdmission, ToolSurface, SecurityDegradation, EffectiveEffectPolicy, SessionEffectOverrides, } from './effect-policy.js';
|
|
20
|
+
export { resolveEffectiveEffectPolicy, requiresJail, buildOpsJailState, isPathAllowed, isToolAllowedOnSurface, gateEffect, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './effect-policy.js';
|
|
21
|
+
export type { UntrustedAdmission, JailIntent, OnJailUnavailable, OpsJailState, ToolSurface, SecurityDegradation, EffectiveEffectPolicy, SessionEffectOverrides, } from './effect-policy.js';
|
|
20
22
|
export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './resource-limits.js';
|
|
21
23
|
export type { ToolRunLimits } from './resource-limits.js';
|
|
22
24
|
export { TurnMemoryJournal, JournaledMemoryStore, createMemoryRestorer, discardMemoryUndo, } from './memory-undo.js';
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, supervisedSpawnProfile, } from './sandbox.js';
|
|
8
8
|
export { probeProcessIsolation, scrubEnv, killProcessTree, L4_PROCESS_MINIMUM, } from './process-isolation.js';
|
|
9
|
+
export { listProcesses, getAncestorPidChain, resolveProcessImage, buildAncestorChain, selectProcesses, parsePsProcessTable, parseCpuTimeToMs, parseProcPidEntry, parsePowerShellProcessTable, firstExecutableFromLsof, } from './process-info.js';
|
|
9
10
|
export { FileWorkspace } from './workspace.js';
|
|
10
11
|
export { DEFAULT_TOOL_ISOLATION, resolveToolIsolationCwd, safeSessionDirSegment, looksLikeAbsoluteSessionPath, } from './isolation.js';
|
|
11
12
|
export { TurnFileUndoLog, commitSessionFileUndo, discardSessionFileUndo, resolveSessionUndoPaths, resolveSessionUndoOnClose, } from './undo-log.js';
|
|
12
13
|
export { isProbablyText, reverseAgentOverwrite, merge3Lines } from './undo-merge.js';
|
|
13
14
|
export { snapshotShellRoots, captureShellInventory, diffShellInventory, journalShellDiff, writeNotReversed, } from './shell-journal.js';
|
|
14
|
-
export { resolveEffectiveEffectPolicy, isPathAllowed, isToolAllowedOnSurface, gateEffect, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './effect-policy.js';
|
|
15
|
+
export { resolveEffectiveEffectPolicy, requiresJail, buildOpsJailState, isPathAllowed, isToolAllowedOnSurface, gateEffect, DEFAULT_EFFECT_RUN_MODE, readSessionEffectOverrides, normalizeTransactionRoots, mergeTransactionRoots, SESSION_EFFECT_OVERRIDES_KEY, } from './effect-policy.js';
|
|
15
16
|
export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './resource-limits.js';
|
|
16
17
|
export { TurnMemoryJournal, JournaledMemoryStore, createMemoryRestorer, discardMemoryUndo, } from './memory-undo.js';
|
|
17
18
|
export { resolveToolCapabilities, deniesReducedSurface, BUILTIN_TOOL_CAPABILITIES, REDUCED_DENIED_CAPABILITIES, } from './tool-capabilities.js';
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* 本模块解析「本 Run 的 toolRuntime.cwd」,不引入分布式文件锁。
|
|
6
6
|
*/
|
|
7
7
|
import { isAbsolute, join, resolve, sep } from 'node:path';
|
|
8
|
+
import { expandHomePath } from '../../../paths.js';
|
|
8
9
|
import { toSessionFileName } from '@octopi-agent/core/session-filename.js';
|
|
9
10
|
/**
|
|
10
11
|
* 缺省隔离模式。
|
|
@@ -35,7 +36,10 @@ export function safeSessionDirSegment(sessionId) {
|
|
|
35
36
|
* @returns 工具 cwd 与生效模式
|
|
36
37
|
*/
|
|
37
38
|
export function resolveToolIsolationCwd(input) {
|
|
38
|
-
|
|
39
|
+
// `~` 形态在此展开(trim → expand):toolRuntime.cwd 必须与 eff.allowRoots
|
|
40
|
+
// (resolveEffectiveEffectPolicy 同源展开)一致,否则 strict 匹配失败、
|
|
41
|
+
// session-subdir 会 mkdir 出字面 `~` 目录(留观② P1-1)。
|
|
42
|
+
const base = input.baseCwd?.trim() ? expandHomePath(input.baseCwd.trim()) : undefined;
|
|
39
43
|
const mode = input.mode;
|
|
40
44
|
if (mode === 'session-subdir' && base) {
|
|
41
45
|
const segment = safeSessionDirSegment(input.sessionId);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kill switch(ops P5,`arch/ops-privileged-mode.md` §5 P5)——宿主侧急停
|
|
3
|
+
*
|
|
4
|
+
* 一条命令停掉 agent 的全部执行能力,**不依赖 LLM 判断与 agent 合作**:
|
|
5
|
+
* 宿主写一个哨兵文件(`octopi ops kill <agentId>`),引擎在 run 准入与每次工具
|
|
6
|
+
* 调用前检查——文件在 = 什么都不执行。删除文件(`octopi ops revive`)恢复。
|
|
7
|
+
*
|
|
8
|
+
* 设计约束:
|
|
9
|
+
* - **宿主侧信号**:不走 LLM、不走 agent 工具面(agent 无法自己解除;它甚至无法
|
|
10
|
+
* 阻止检查——检查点在 beforeToolCall,先于一切工具 handler)。
|
|
11
|
+
* - **每次实查,不缓存**:急停必须即时生效,也必须可即时恢复。
|
|
12
|
+
* - fail-closed:检查本身异常(stat 失败)按「未触发」处理不降级——哨兵缺失是
|
|
13
|
+
* 常态;但**路径未配置**时不得假装有急停(诚实:没有检查点 = 没有 kill switch)。
|
|
14
|
+
*/
|
|
15
|
+
/** 急停状态 */
|
|
16
|
+
export interface KillSwitchState {
|
|
17
|
+
engaged: boolean;
|
|
18
|
+
/** 触发的哨兵文件路径(engaged=true 时给出) */
|
|
19
|
+
path?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 默认哨兵路径(宿主布局):`<OCTOPI_HOME>/agents/<agentId>/KILL`。
|
|
23
|
+
*
|
|
24
|
+
* @param agentId - agent 标识
|
|
25
|
+
* @returns 哨兵文件绝对路径
|
|
26
|
+
*/
|
|
27
|
+
export declare function defaultKillSwitchPath(agentId: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* 检查急停哨兵(每次实查;文件存在 = engaged)。
|
|
30
|
+
*
|
|
31
|
+
* @param paths - 哨兵路径列表(任一存在即触发)
|
|
32
|
+
* @returns 急停状态
|
|
33
|
+
*/
|
|
34
|
+
export declare function checkKillSwitch(paths: readonly string[] | undefined): KillSwitchState;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kill switch(ops P5,`arch/ops-privileged-mode.md` §5 P5)——宿主侧急停
|
|
3
|
+
*
|
|
4
|
+
* 一条命令停掉 agent 的全部执行能力,**不依赖 LLM 判断与 agent 合作**:
|
|
5
|
+
* 宿主写一个哨兵文件(`octopi ops kill <agentId>`),引擎在 run 准入与每次工具
|
|
6
|
+
* 调用前检查——文件在 = 什么都不执行。删除文件(`octopi ops revive`)恢复。
|
|
7
|
+
*
|
|
8
|
+
* 设计约束:
|
|
9
|
+
* - **宿主侧信号**:不走 LLM、不走 agent 工具面(agent 无法自己解除;它甚至无法
|
|
10
|
+
* 阻止检查——检查点在 beforeToolCall,先于一切工具 handler)。
|
|
11
|
+
* - **每次实查,不缓存**:急停必须即时生效,也必须可即时恢复。
|
|
12
|
+
* - fail-closed:检查本身异常(stat 失败)按「未触发」处理不降级——哨兵缺失是
|
|
13
|
+
* 常态;但**路径未配置**时不得假装有急停(诚实:没有检查点 = 没有 kill switch)。
|
|
14
|
+
*/
|
|
15
|
+
import { statSync } from 'node:fs';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { getOctopiHome } from '../../../paths.js';
|
|
18
|
+
/**
|
|
19
|
+
* 默认哨兵路径(宿主布局):`<OCTOPI_HOME>/agents/<agentId>/KILL`。
|
|
20
|
+
*
|
|
21
|
+
* @param agentId - agent 标识
|
|
22
|
+
* @returns 哨兵文件绝对路径
|
|
23
|
+
*/
|
|
24
|
+
export function defaultKillSwitchPath(agentId) {
|
|
25
|
+
return join(getOctopiHome(), 'agents', agentId, 'KILL');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 检查急停哨兵(每次实查;文件存在 = engaged)。
|
|
29
|
+
*
|
|
30
|
+
* @param paths - 哨兵路径列表(任一存在即触发)
|
|
31
|
+
* @returns 急停状态
|
|
32
|
+
*/
|
|
33
|
+
export function checkKillSwitch(paths) {
|
|
34
|
+
if (!paths || paths.length === 0)
|
|
35
|
+
return { engaged: false };
|
|
36
|
+
for (const path of paths) {
|
|
37
|
+
try {
|
|
38
|
+
if (statSync(path).isFile())
|
|
39
|
+
return { engaged: true, path };
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// 哨兵缺失是常态(未急停);stat 失败同义,不制造假触发
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { engaged: false };
|
|
46
|
+
}
|