@octopi-agent/engine 0.90.11 → 0.98.4
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 +45 -1
- package/dist/config-schema/context.d.ts +6 -1
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +110 -4
- package/dist/config-schema/governance.d.ts +45 -1
- package/dist/config-schema/governance.js +187 -0
- package/dist/config-schema/models.d.ts +5 -2
- 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.d.ts +29 -4
- package/dist/config.js +15 -4
- 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 +26 -1
- package/dist/harness/agent/builder.js +85 -37
- package/dist/harness/agent/config-bridge.d.ts +5 -0
- package/dist/harness/agent/config-bridge.js +3 -0
- package/dist/harness/agent/config-integrity.d.ts +138 -0
- package/dist/harness/agent/config-integrity.js +235 -0
- package/dist/harness/agent/wire-agent-builder.js +7 -1
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +19 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +9 -0
- 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/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -4
- package/dist/harness/context/capabilities/summary/types.d.ts +2 -2
- 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 +194 -49
- package/dist/harness/context/hybrid-compressor.js +6 -0
- package/dist/harness/context/layers.d.ts +2 -4
- package/dist/harness/context/layers.js +9 -11
- 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/summarize.d.ts +3 -1
- package/dist/harness/context/summarize.js +9 -4
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +1 -0
- package/dist/harness/context/truncate-compressor.js +7 -0
- package/dist/harness/context/turn-envelope.d.ts +3 -2
- package/dist/harness/context/turn-envelope.js +3 -2
- 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 +149 -8
- package/dist/harness/extension/execution-environment/effect-policy.js +274 -19
- 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/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 +204 -0
- package/dist/harness/extension/execution-environment/ops-audit.js +337 -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 +228 -21
- 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/execution-environment/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +33 -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 +70 -26
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- 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/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- 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/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/governance/session-acl/seed-roles.js +14 -0
- package/dist/harness/index.d.ts +2 -0
- package/dist/harness/index.js +2 -0
- package/dist/harness/knowledge/fts.js +1 -2
- package/dist/harness/knowledge/index-store.js +59 -9
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +51 -2
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +41 -3
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +20 -1
- package/dist/harness/memory/wisdom-formation.js +55 -21
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +40 -2
- package/dist/harness/observability/observer/hub.js +8 -0
- package/dist/harness/observability/observer/run-snapshot.js +1 -0
- package/dist/harness/observability/observer/types.d.ts +4 -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 +35 -0
- package/dist/harness/run/runner.d.ts +141 -2
- package/dist/harness/run/runner.js +592 -42
- package/dist/harness/session/attachments/llm-intent.js +2 -1
- package/dist/harness/session/tasks/render.d.ts +4 -1
- package/dist/harness/session/tasks/render.js +10 -7
- package/dist/harness/shared/events/agent-event-map.d.ts +66 -0
- package/dist/harness/shared/events/agent-event-map.js +5 -0
- package/dist/harness/shared/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- 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/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.js +4 -1
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +12 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +12 -18
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +8 -2
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { HitlDecision } from '@octopi-agent/core/types/tools.js';
|
|
8
8
|
import type { ToolIsolationMode } from './isolation.js';
|
|
9
|
+
import type { EscalationPolicy, EscalationRule } from './privileged-exec.js';
|
|
9
10
|
import { type ProcessIsolationProfile } from './process-isolation.js';
|
|
10
11
|
/** 命名运行模式 */
|
|
11
12
|
export type EffectRunMode = 'workspace' | 'project' | 'host' | 'untrusted';
|
|
@@ -24,7 +25,11 @@ export type ShellEscapePolicy = 'deny' | 'confirm' | 'allow';
|
|
|
24
25
|
export type EffectCommitPolicy = 'auto' | 'manual';
|
|
25
26
|
/** 效应确认通道 */
|
|
26
27
|
/** 效应意图(host-gate confirmEffect 入参) */
|
|
27
|
-
export type EffectIntent = {
|
|
28
|
+
export type EffectIntent = EffectIntentPayload & {
|
|
29
|
+
/** 引擎侧确认窗(毫秒):宿主卡片生命周期须严格晚于它结束(见 core confirmEffect 契约) */
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
};
|
|
32
|
+
type EffectIntentPayload = {
|
|
28
33
|
kind: 'file.write';
|
|
29
34
|
path: string;
|
|
30
35
|
mode: 'create' | 'overwrite' | 'append' | 'edit';
|
|
@@ -66,6 +71,28 @@ export type EffectConfirmChannel = 'engine' | 'host-gate';
|
|
|
66
71
|
export type ShellJournalMode = 'snapshot' | 'off';
|
|
67
72
|
/** How to admit `untrusted` when L4 process jail is missing */
|
|
68
73
|
export type UntrustedAdmission = 'refuse' | 'degrade';
|
|
74
|
+
/**
|
|
75
|
+
* 进程牢笼意图(ops P0,`arch/ops-privileged-mode.md` §4):
|
|
76
|
+
* `auto` = 按模式派生(缺笼如实降级)| `require` = 拿不到即拒 | `none` = 显式无笼(需 privilegedAck)。
|
|
77
|
+
* 「主动选择无约束」与「被动失去约束」必须可区分——授权 ≠ 降级。
|
|
78
|
+
*/
|
|
79
|
+
export type JailIntent = 'auto' | 'require' | 'none';
|
|
80
|
+
/** jail 意图落空时的行为:`refuse` 拒绝执行 | `degrade` 记 securityDegraded + 告警(禁止静默) */
|
|
81
|
+
export type OnJailUnavailable = 'refuse' | 'degrade';
|
|
82
|
+
export type { EscalationPolicy, EscalationRule };
|
|
83
|
+
/** run 开始即记录的 jail 状态(意图 × 实测后端)——「授权」与「故障」的事后判据 */
|
|
84
|
+
export interface OpsJailState {
|
|
85
|
+
/** 配置意图 */
|
|
86
|
+
intent: JailIntent;
|
|
87
|
+
/** 实测 ProcessIsolationProfile.backend */
|
|
88
|
+
backend: import('./process-isolation.js').IsolationBackend | 'unknown';
|
|
89
|
+
/** L4 最小判据是否成立(intent=none 时仅作事实上报) */
|
|
90
|
+
jailAvailable: boolean;
|
|
91
|
+
/** true = 授权态(显式 none / 笼按意图就位);false = 故障或缺失(降级路径) */
|
|
92
|
+
authorized: boolean;
|
|
93
|
+
/** 本 run 的 securityDegraded 代码 */
|
|
94
|
+
degraded: string[];
|
|
95
|
+
}
|
|
69
96
|
/** Effective tool surface after isolation admission */
|
|
70
97
|
export type ToolSurface = 'full' | 'reduced';
|
|
71
98
|
/** Machine-readable degradations (never silent) */
|
|
@@ -85,6 +112,23 @@ export interface EffectPolicyConfig {
|
|
|
85
112
|
/** 额外事务 root(绝对路径或 ~ 形态,入口 trim → expand);并入 allowRoots */
|
|
86
113
|
transactionRoots?: string[];
|
|
87
114
|
pathContainment?: PathContainment;
|
|
115
|
+
/**
|
|
116
|
+
* 拒绝最终组件为符号链接的文件读写(缺省 `false`)。
|
|
117
|
+
*
|
|
118
|
+
* 包含判定已把路径解析为真实路径,正常情况下最终组件不是链接;若打开时它
|
|
119
|
+
* 仍是链接,说明检查与使用之间被替换。开启后以 `O_NOFOLLOW` / `lstat`
|
|
120
|
+
* 拒绝,而不是跟随。`untrusted` 模式强制开启,不受配置放松。
|
|
121
|
+
*
|
|
122
|
+
* 代价:`pathContainment: 'none'` 下根内合法链接的读写会被拒。
|
|
123
|
+
*/
|
|
124
|
+
refuseFinalSymlink?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* 拒绝匹配这些 glob 的路径(相对允许根匹配,同时匹配文件名)。
|
|
127
|
+
*
|
|
128
|
+
* 默认空 = 不拒绝任何路径;「agent 读写自己 workspace 里的 `.env`」是合法
|
|
129
|
+
* 用法,本字段是部署策略而非引擎世界观。声明即拒绝,任何 containment 级别都生效。
|
|
130
|
+
*/
|
|
131
|
+
pathDenylist?: string[];
|
|
88
132
|
shellEscape?: ShellEscapePolicy;
|
|
89
133
|
/**
|
|
90
134
|
* Jail network posture (D4-c). Omitted = mode default:
|
|
@@ -111,6 +155,40 @@ export interface EffectPolicyConfig {
|
|
|
111
155
|
maxBytes?: number;
|
|
112
156
|
maxFileSize?: number;
|
|
113
157
|
};
|
|
158
|
+
/** 进程牢笼意图;缺省 `auto`(按模式派生,缺笼如实降级 + 告警) */
|
|
159
|
+
jail?: JailIntent;
|
|
160
|
+
/** jail≠none 且笼不可用时:`refuse` 拒绝执行 | `degrade`(缺省)记 securityDegraded + 告警 */
|
|
161
|
+
onJailUnavailable?: OnJailUnavailable;
|
|
162
|
+
/** `jail: "none"` / `escalation: "full"` 时按块必填的显式表态(缺省拒绝启动;§8.1 二级确认)。
|
|
163
|
+
* root/elevated 部署声明是另一回事:只认**顶层** effectPolicy 的本字段(§5 P4,启动期断言);
|
|
164
|
+
* agent 块内的本字段只声明该块自己的 jail=none/full,不参与 elevated 启动声明。 */
|
|
165
|
+
privilegedAck?: string;
|
|
166
|
+
/** 提权策略(§4/§5 P3/P4):`allowlist` 按 cmd+args 全等放行;`full` 全量档
|
|
167
|
+
* (需 `jail: "none"` + `privilegedAck` + `mode: "host"`);缺省 `none` */
|
|
168
|
+
escalation?: {
|
|
169
|
+
policy?: 'none' | 'allowlist' | 'full';
|
|
170
|
+
via?: 'sudo' | 'direct';
|
|
171
|
+
allow?: EscalationRule[];
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* 危险命令确认(§6:减速带而非安全边界):命中保守分类表的 argv 要求确认。
|
|
175
|
+
* `policy`:`confirm`(缺省,走 HitlDecision)| `deny`(直接拒绝)| `off`(关闭分类)。
|
|
176
|
+
* `timeoutMs`:确认超时(超时一律 deny,不可配 outcome);缺省 120000。
|
|
177
|
+
*/
|
|
178
|
+
dangerousCommands?: {
|
|
179
|
+
policy?: 'confirm' | 'deny' | 'off';
|
|
180
|
+
timeoutMs?: number;
|
|
181
|
+
};
|
|
182
|
+
/** ops 审计账本开关(安全字段:重启生效 + 宿主署名,§4.3);缺省 `on` */
|
|
183
|
+
opsAudit?: 'on' | 'off';
|
|
184
|
+
/** ops 审计账本路径(缺省 `<OCTOPI_HOME>/audit/ops.<agentId>.jsonl`) */
|
|
185
|
+
opsAuditPath?: string;
|
|
186
|
+
/**
|
|
187
|
+
* 审计外送收口路径(P5 唯一不可抵赖档,原则 8);缺省不外送。
|
|
188
|
+
* **必须放在 agent 可写面之外**(`~/.octopi` 在 host 模式可写面内——放那里等于没外送)。
|
|
189
|
+
* 每条账目以信封(count=seq + tailHash 锚点 + entry 原样)append-only 外送,宿主可重验链。
|
|
190
|
+
*/
|
|
191
|
+
opsAuditExportPath?: string;
|
|
114
192
|
}
|
|
115
193
|
/** 展开后的有效策略 */
|
|
116
194
|
export interface EffectiveEffectPolicy {
|
|
@@ -128,6 +206,10 @@ export interface EffectiveEffectPolicy {
|
|
|
128
206
|
securityDegraded: SecurityDegradation[];
|
|
129
207
|
toolIsolation: ToolIsolationMode;
|
|
130
208
|
pathContainment: PathContainment;
|
|
209
|
+
/** 拒绝最终组件为符号链接的文件读写(`untrusted` 强制 true) */
|
|
210
|
+
refuseFinalSymlink: boolean;
|
|
211
|
+
/** 拒绝清单(glob);空数组 = 不拒绝 */
|
|
212
|
+
pathDenylist: readonly string[];
|
|
131
213
|
shellEscape: ShellEscapePolicy;
|
|
132
214
|
/** Resolved jail network posture */
|
|
133
215
|
network: 'open' | 'deny' | 'allowlist';
|
|
@@ -149,17 +231,64 @@ export interface EffectiveEffectPolicy {
|
|
|
149
231
|
maxBytes?: number;
|
|
150
232
|
maxFileSize?: number;
|
|
151
233
|
};
|
|
234
|
+
/** 进程牢笼意图(auto/require/none) */
|
|
235
|
+
jail: JailIntent;
|
|
236
|
+
/** jail 意图落空时的行为(refuse/degrade) */
|
|
237
|
+
onJailUnavailable: OnJailUnavailable;
|
|
238
|
+
/** 提权策略(ops P3/P4,resolved) */
|
|
239
|
+
escalation: EscalationPolicy;
|
|
240
|
+
/**
|
|
241
|
+
* 特权部署标记(§5 P4 / §8.1):`jail: "none"`(授权无笼)或 `escalation.policy: "full"`
|
|
242
|
+
* (全量提权)即为特权上下文。root/elevated 进程维度由启动期探测叠加(UI 常驻
|
|
243
|
+
* `PRIVILEGED` 标记的数据源)。**授权态 ≠ 降级**:此标记不进 securityDegraded。
|
|
244
|
+
*/
|
|
245
|
+
privileged: boolean;
|
|
246
|
+
/** 危险命令减速带(§6)resolved:分类策略 + 确认超时(超时一律 deny) */
|
|
247
|
+
dangerousCommands: {
|
|
248
|
+
policy: 'confirm' | 'deny' | 'off';
|
|
249
|
+
timeoutMs: number;
|
|
250
|
+
};
|
|
251
|
+
/** ops 审计账本开关(ops P2) */
|
|
252
|
+
opsAudit: 'on' | 'off';
|
|
253
|
+
/** ops 审计账本路径覆盖 */
|
|
254
|
+
opsAuditPath?: string;
|
|
255
|
+
/** 审计外送收口路径(P5;缺省不外送) */
|
|
256
|
+
opsAuditExportPath?: string;
|
|
152
257
|
}
|
|
153
258
|
/**
|
|
154
|
-
* Whether the resolved policy demands a process jail
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
259
|
+
* Whether the resolved policy demands a process jail — fail-closed when the
|
|
260
|
+
* jail cannot be applied (ops P0: `jail: require`, `onJailUnavailable: refuse`,
|
|
261
|
+
* or untrusted that survived untrusted admission). Single predicate shared by
|
|
262
|
+
* the run path (runner) and host-side read surfaces (WebUI git status endpoint)
|
|
263
|
+
* so the isolation level never drifts between them.
|
|
158
264
|
*
|
|
159
265
|
* @param eff - resolved effective policy
|
|
160
|
-
* @returns true when
|
|
266
|
+
* @returns true when a missing/broken jail must refuse execution
|
|
161
267
|
*/
|
|
162
268
|
export declare function requiresJail(eff: EffectiveEffectPolicy): boolean;
|
|
269
|
+
/**
|
|
270
|
+
* 白名单提权全等匹配(§5 P3):`cmd` 绝对路径比对 + `args` 逐项全等。
|
|
271
|
+
* 不做前缀/正则/插值——任何「宽松匹配」都会把 allowlist 变成任意命令通道。
|
|
272
|
+
*
|
|
273
|
+
* @param escalation - resolved 提权策略
|
|
274
|
+
* @param cmd - 请求的可执行文件(必须与规则逐字相同)
|
|
275
|
+
* @param args - 请求的 argv 尾部
|
|
276
|
+
* @returns 命中的规则与稳定 ruleId;未命中 null
|
|
277
|
+
*/
|
|
278
|
+
export declare function matchEscalationRule(escalation: EscalationPolicy, cmd: string, args: readonly string[]): {
|
|
279
|
+
rule: EscalationRule;
|
|
280
|
+
ruleId: string;
|
|
281
|
+
} | null;
|
|
282
|
+
/**
|
|
283
|
+
* 构造 run 开始即记录的 `ops.jail.state`(意图 × 实测后端)。
|
|
284
|
+
* 「主动选择无约束」(authorized, intent=none)与「被动失去约束」
|
|
285
|
+
* (authorized=false, 缺笼降级)事后可分辨即靠这条记录。
|
|
286
|
+
*
|
|
287
|
+
* @param eff - 解析后的有效策略
|
|
288
|
+
* @param isolation - probe 到的隔离画像(缺省按「无笼」)
|
|
289
|
+
* @returns jail 状态记录
|
|
290
|
+
*/
|
|
291
|
+
export declare function buildOpsJailState(eff: EffectiveEffectPolicy, isolation?: ProcessIsolationProfile): OpsJailState;
|
|
163
292
|
/**
|
|
164
293
|
* 展开 effectPolicy 为有效策略
|
|
165
294
|
*
|
|
@@ -200,12 +329,24 @@ export declare function isToolAllowedOnSurface(toolName: string, surface: ToolSu
|
|
|
200
329
|
* @returns 是否允许
|
|
201
330
|
*/
|
|
202
331
|
export declare function isPathAllowed(resolved: string, allowRoots: string[], containment: PathContainment): boolean;
|
|
332
|
+
/** 闸门放行结论(ops P2:审计要「是否经确认」的事实,不是通道配置) */
|
|
333
|
+
export interface GateEffectResult {
|
|
334
|
+
/** 是否经宿主确认(自动放行 = false;未过闸 = 不返回本值而是 throw) */
|
|
335
|
+
confirmed: boolean;
|
|
336
|
+
/** 放行来源:确认过 / 事务自动 / engine 内置策略 */
|
|
337
|
+
confirmSource: 'host-gate' | 'auto-transaction' | 'auto-engine';
|
|
338
|
+
/** ops P5 确认人署名(仅 host-gate 经人工批准时;缓存命中/自动放行如实缺省) */
|
|
339
|
+
confirmedBy?: string;
|
|
340
|
+
/** ops P5 确认通道(gateway | webhook | …) */
|
|
341
|
+
confirmChannel?: string;
|
|
342
|
+
}
|
|
203
343
|
/**
|
|
204
344
|
* 效应闸(P4):事务内自动放行;host-gate 交给宿主;engine 通道按内置策略。
|
|
205
345
|
*
|
|
206
346
|
* @param intent - 效应意图
|
|
207
347
|
* @param options - 通道与回调
|
|
208
|
-
* @
|
|
348
|
+
* @returns 放行结论(confirmed/confirmSource + 确认人归因,审计用)
|
|
349
|
+
* @throws Error 当拒绝执行时(`effect_confirm_timeout` 超时 / `effect_denied` 拒绝,语义分家)
|
|
209
350
|
*/
|
|
210
351
|
export declare function gateEffect(intent: EffectIntent, options: {
|
|
211
352
|
effects: EffectConfirmChannel;
|
|
@@ -216,7 +357,7 @@ export declare function gateEffect(intent: EffectIntent, options: {
|
|
|
216
357
|
/** SEC-7:always-scope 缓存键(agent 分桶);缺省尝试 RunScope */
|
|
217
358
|
agentId?: string;
|
|
218
359
|
hitlCache?: import('../../governance/human-in-the-loop/decision-cache.js').HitlDecisionCache;
|
|
219
|
-
}): Promise<
|
|
360
|
+
}): Promise<GateEffectResult>;
|
|
220
361
|
/**
|
|
221
362
|
* Session-only effect overrides. Append-only: may add allow roots for this
|
|
222
363
|
* session; must never loosen pathContainment / shellEscape.
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { isAbsolute, resolve } from 'node:path';
|
|
8
8
|
import { expandHomePath } from '../../../paths.js';
|
|
9
|
+
import { globToPathRegex, normalizeDenyPattern, validateDenyPattern } from '../../shared/paths/glob.js';
|
|
10
|
+
import { checkEscalationBinary, escalationRuleTargets, escalationWritableRoots, } from './privileged-exec.js';
|
|
9
11
|
import { deniesReducedSurface, resolveToolCapabilities, } from './tool-capabilities.js';
|
|
10
12
|
import { assessL4ProcessMinimum, } from './process-isolation.js';
|
|
11
|
-
import {
|
|
13
|
+
import { resolveHitlOutcome } from '../../governance/human-in-the-loop/decision-cache.js';
|
|
12
14
|
import { getRunSessionId, getRunScope } from '../../run/run-scope.js';
|
|
13
15
|
/**
|
|
14
16
|
* Engine default when `effectPolicy.mode` is omitted (secure-by-default).
|
|
@@ -22,6 +24,10 @@ const MODE_DEFAULTS = {
|
|
|
22
24
|
mode: 'workspace',
|
|
23
25
|
toolIsolation: 'session-subdir',
|
|
24
26
|
pathContainment: 'strict',
|
|
27
|
+
// containment 已把路径解析为真实路径,合法链接不受影响;需要闭合
|
|
28
|
+
// 「检查后、落盘前被换成链接」窗口的部署再显式开启。
|
|
29
|
+
refuseFinalSymlink: false,
|
|
30
|
+
pathDenylist: [],
|
|
25
31
|
// 无 L4 时无法「只禁越界」:deny = 拒绝 shell 工具(fail-closed)
|
|
26
32
|
shellEscape: 'deny',
|
|
27
33
|
network: 'deny',
|
|
@@ -35,6 +41,8 @@ const MODE_DEFAULTS = {
|
|
|
35
41
|
mode: 'project',
|
|
36
42
|
toolIsolation: 'session-subdir',
|
|
37
43
|
pathContainment: 'strict',
|
|
44
|
+
refuseFinalSymlink: false,
|
|
45
|
+
pathDenylist: [],
|
|
38
46
|
// 编码 agent 必须有 shell;文件侧靠 L2,shell FS 越界待 L4
|
|
39
47
|
shellEscape: 'allow',
|
|
40
48
|
network: 'open',
|
|
@@ -48,6 +56,9 @@ const MODE_DEFAULTS = {
|
|
|
48
56
|
mode: 'host',
|
|
49
57
|
toolIsolation: 'none',
|
|
50
58
|
pathContainment: 'none',
|
|
59
|
+
// containment 关闭时不做 realpath,开启会拒掉根内合法链接,故保持关闭
|
|
60
|
+
refuseFinalSymlink: false,
|
|
61
|
+
pathDenylist: [],
|
|
51
62
|
shellEscape: 'allow',
|
|
52
63
|
network: 'open',
|
|
53
64
|
processLimits: true,
|
|
@@ -60,6 +71,9 @@ const MODE_DEFAULTS = {
|
|
|
60
71
|
mode: 'untrusted',
|
|
61
72
|
toolIsolation: 'session-subdir',
|
|
62
73
|
pathContainment: 'strict',
|
|
74
|
+
// 不可信输入下强制开启:硬化为不可放松的产品承诺
|
|
75
|
+
refuseFinalSymlink: true,
|
|
76
|
+
pathDenylist: [],
|
|
63
77
|
shellEscape: 'deny',
|
|
64
78
|
network: 'deny',
|
|
65
79
|
processLimits: true,
|
|
@@ -70,17 +84,68 @@ const MODE_DEFAULTS = {
|
|
|
70
84
|
},
|
|
71
85
|
};
|
|
72
86
|
/**
|
|
73
|
-
* Whether the resolved policy demands a process jail
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
87
|
+
* Whether the resolved policy demands a process jail — fail-closed when the
|
|
88
|
+
* jail cannot be applied (ops P0: `jail: require`, `onJailUnavailable: refuse`,
|
|
89
|
+
* or untrusted that survived untrusted admission). Single predicate shared by
|
|
90
|
+
* the run path (runner) and host-side read surfaces (WebUI git status endpoint)
|
|
91
|
+
* so the isolation level never drifts between them.
|
|
77
92
|
*
|
|
78
93
|
* @param eff - resolved effective policy
|
|
79
|
-
* @returns true when
|
|
94
|
+
* @returns true when a missing/broken jail must refuse execution
|
|
80
95
|
*/
|
|
81
96
|
export function requiresJail(eff) {
|
|
97
|
+
// jail=none 是授权无笼:onJailUnavailable 对它无意义,不得误报「要求笼」
|
|
98
|
+
if (eff.jail === 'none')
|
|
99
|
+
return false;
|
|
100
|
+
if (eff.jail === 'require' || eff.onJailUnavailable === 'refuse')
|
|
101
|
+
return true;
|
|
82
102
|
return eff.requestedMode === 'untrusted' && eff.mode === 'untrusted';
|
|
83
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* 白名单提权全等匹配(§5 P3):`cmd` 绝对路径比对 + `args` 逐项全等。
|
|
106
|
+
* 不做前缀/正则/插值——任何「宽松匹配」都会把 allowlist 变成任意命令通道。
|
|
107
|
+
*
|
|
108
|
+
* @param escalation - resolved 提权策略
|
|
109
|
+
* @param cmd - 请求的可执行文件(必须与规则逐字相同)
|
|
110
|
+
* @param args - 请求的 argv 尾部
|
|
111
|
+
* @returns 命中的规则与稳定 ruleId;未命中 null
|
|
112
|
+
*/
|
|
113
|
+
export function matchEscalationRule(escalation, cmd, args) {
|
|
114
|
+
if (escalation.policy !== 'allowlist')
|
|
115
|
+
return null;
|
|
116
|
+
for (let i = 0; i < escalation.allow.length; i += 1) {
|
|
117
|
+
const rule = escalation.allow[i];
|
|
118
|
+
const ruleArgs = rule.args ?? [];
|
|
119
|
+
if (rule.cmd === cmd &&
|
|
120
|
+
ruleArgs.length === args.length &&
|
|
121
|
+
ruleArgs.every((a, idx) => a === args[idx])) {
|
|
122
|
+
// 显式 id 优先(下标 id 在规则重排后会断裂审计关联)
|
|
123
|
+
return { rule, ruleId: rule.id ?? `allow[${i}]` };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 构造 run 开始即记录的 `ops.jail.state`(意图 × 实测后端)。
|
|
130
|
+
* 「主动选择无约束」(authorized, intent=none)与「被动失去约束」
|
|
131
|
+
* (authorized=false, 缺笼降级)事后可分辨即靠这条记录。
|
|
132
|
+
*
|
|
133
|
+
* @param eff - 解析后的有效策略
|
|
134
|
+
* @param isolation - probe 到的隔离画像(缺省按「无笼」)
|
|
135
|
+
* @returns jail 状态记录
|
|
136
|
+
*/
|
|
137
|
+
export function buildOpsJailState(eff, isolation) {
|
|
138
|
+
const l4 = isolation ? assessL4ProcessMinimum(isolation) : { ok: false };
|
|
139
|
+
const jailAvailable = l4.ok;
|
|
140
|
+
return {
|
|
141
|
+
intent: eff.jail,
|
|
142
|
+
backend: isolation?.backend ?? 'unknown',
|
|
143
|
+
jailAvailable,
|
|
144
|
+
// none = 授权无笼;其余意图下只有笼按意图就位才是授权态
|
|
145
|
+
authorized: eff.jail === 'none' || jailAvailable,
|
|
146
|
+
degraded: [...eff.securityDegraded],
|
|
147
|
+
};
|
|
148
|
+
}
|
|
84
149
|
/**
|
|
85
150
|
* 展开 effectPolicy 为有效策略
|
|
86
151
|
*
|
|
@@ -116,6 +181,47 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
116
181
|
baseWorkspace !== undefined ? expandHomePath(baseWorkspace.trim()) : baseWorkspace;
|
|
117
182
|
const requestedMode = config.mode ?? DEFAULT_EFFECT_RUN_MODE;
|
|
118
183
|
const untrustedAdmission = config.untrustedAdmission ?? 'refuse';
|
|
184
|
+
// ops P0:jail 意图先解析;**纯配置矛盾 fail-closed 先于任何探测分支**——
|
|
185
|
+
// 矛盾是配置事实,不该被「先撞上缺笼」抢先抛成另一种错误
|
|
186
|
+
const jail = config.jail ?? 'auto';
|
|
187
|
+
const onJailUnavailable = config.onJailUnavailable ?? 'degrade';
|
|
188
|
+
// ops P4 §4.1:full 档纯配置矛盾——同上原则,先于任何探测分支(矛盾是配置事实,
|
|
189
|
+
// 不该被「先撞上缺笼/缺 ack」抢先抛成另一种错误)
|
|
190
|
+
if (config.escalation?.policy === 'full') {
|
|
191
|
+
if (requestedMode !== 'host') {
|
|
192
|
+
throw new Error('effect_policy_invalid: escalation.policy=full requires mode=host (explicitly designated machine)');
|
|
193
|
+
}
|
|
194
|
+
if (jail !== 'none') {
|
|
195
|
+
throw new Error('effect_policy_invalid: escalation.policy=full requires jail=none (whole-shell freedom contradicts a jailed shell)');
|
|
196
|
+
}
|
|
197
|
+
if (!config.privilegedAck?.trim()) {
|
|
198
|
+
throw new Error('effect_policy_invalid: escalation.policy=full requires effectPolicy.privilegedAck (explicit privileged declaration)');
|
|
199
|
+
}
|
|
200
|
+
if ((config.escalation.allow ?? []).length > 0) {
|
|
201
|
+
// 死键 fail-loud:full 档没有 allowlist 面,静默忽略会误导配置读者
|
|
202
|
+
throw new Error('effect_policy_invalid: escalation.policy=full takes no escalation.allow rules (remove them, or use policy=allowlist)');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (jail === 'none') {
|
|
206
|
+
if (requestedMode === 'untrusted') {
|
|
207
|
+
throw new Error('effect_policy_invalid: jail=none cannot combine with mode=untrusted (untrusted promises a jail)');
|
|
208
|
+
}
|
|
209
|
+
if (!config.privilegedAck?.trim()) {
|
|
210
|
+
throw new Error('effect_policy_invalid: jail=none requires effectPolicy.privilegedAck (explicit unjailed choice)');
|
|
211
|
+
}
|
|
212
|
+
if (onJailUnavailable === 'refuse') {
|
|
213
|
+
// 死键 fail-loud:none 下该旋钮无指代,静默忽略会误导配置读者
|
|
214
|
+
throw new Error('effect_policy_invalid: onJailUnavailable=refuse has no meaning under jail=none (remove it, or use jail=auto/require)');
|
|
215
|
+
}
|
|
216
|
+
if (config.network === 'deny' || config.network === 'allowlist') {
|
|
217
|
+
// 网络限制只由 jail 实施:无笼时 deny/allowlist 是无法兑现的承诺,拒绝作假
|
|
218
|
+
throw new Error('effect_policy_invalid: network=deny/allowlist cannot be enforced under jail=none (network is jail-implemented only)');
|
|
219
|
+
}
|
|
220
|
+
// 授权无笼:不为 jail 记 securityDegraded(这是授权,不是降级)
|
|
221
|
+
}
|
|
222
|
+
else if ((jail === 'require' || onJailUnavailable === 'refuse') && untrustedAdmission === 'degrade') {
|
|
223
|
+
throw new Error('effect_policy_invalid: jail=require/onJailUnavailable=refuse contradicts untrustedAdmission=degrade (same condition, opposite outcomes)');
|
|
224
|
+
}
|
|
119
225
|
let mode = requestedMode;
|
|
120
226
|
let toolSurface = 'full';
|
|
121
227
|
const securityDegraded = [];
|
|
@@ -123,6 +229,13 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
123
229
|
const profile = isolation;
|
|
124
230
|
const l4 = profile ? assessL4ProcessMinimum(profile) : { ok: false, missing: ['processTree'] };
|
|
125
231
|
if (!l4.ok) {
|
|
232
|
+
if (config.jail === 'require' || config.onJailUnavailable === 'refuse') {
|
|
233
|
+
// jail 意图 fail-closed 优先且错误码/建议指向 jail 旋钮(untrustedAdmission=degrade
|
|
234
|
+
// 与该组合矛盾,配置校验已拒,不能在这里推荐它)
|
|
235
|
+
throw new Error(`jail_required_unavailable: effectPolicy.jail=${config.jail ?? 'auto'} ` +
|
|
236
|
+
`(onJailUnavailable=${config.onJailUnavailable ?? 'degrade'}) but no process jail ` +
|
|
237
|
+
`(missing: ${l4.missing.join(', ')}). Install bwrap/sandbox-exec, or set jail=none with privilegedAck.`);
|
|
238
|
+
}
|
|
126
239
|
if (untrustedAdmission === 'refuse') {
|
|
127
240
|
throw new Error(`untrusted_refused: L4 process jail unavailable (missing: ${l4.missing.join(', ')}). ` +
|
|
128
241
|
`Install bwrap/sandbox-exec or set effectPolicy.untrustedAdmission=degrade.`);
|
|
@@ -145,11 +258,82 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
145
258
|
securityDegraded.push('network_open');
|
|
146
259
|
}
|
|
147
260
|
}
|
|
261
|
+
// ops P0:jail 可用性申报(纯配置矛盾已在上方先拒)。授权(none)≠ 降级(缺笼)。
|
|
262
|
+
if (jail !== 'none') {
|
|
263
|
+
const l4 = isolation
|
|
264
|
+
? assessL4ProcessMinimum(isolation)
|
|
265
|
+
: { ok: false, missing: ['processTree'] };
|
|
266
|
+
if (!l4.ok) {
|
|
267
|
+
if (jail === 'require' || onJailUnavailable === 'refuse') {
|
|
268
|
+
throw new Error(`jail_required_unavailable: effectPolicy.jail=${jail} (onJailUnavailable=${onJailUnavailable}) ` +
|
|
269
|
+
`but no process jail (missing: ${l4.missing.join(', ')}). ` +
|
|
270
|
+
`Install bwrap/sandbox-exec, or set jail=none with privilegedAck.`);
|
|
271
|
+
}
|
|
272
|
+
// degrade:run 级如实申报(untrusted 降级路径可能已记,去重)
|
|
273
|
+
if (!securityDegraded.includes('no_process_jail'))
|
|
274
|
+
securityDegraded.push('no_process_jail');
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// ops P3:提权策略(§4.1)。纯配置矛盾 fail-closed;allowlist 二进制 TOCTOU 护栏
|
|
278
|
+
// 同步兜底(库路径无 daemon 启动探测时也不能放行可换二进制)。
|
|
279
|
+
const escalation = {
|
|
280
|
+
policy: config.escalation?.policy ?? 'none',
|
|
281
|
+
via: config.escalation?.via ?? 'sudo',
|
|
282
|
+
allow: config.escalation?.allow ?? [],
|
|
283
|
+
};
|
|
284
|
+
if (escalation.policy !== 'none') {
|
|
285
|
+
if (requestedMode === 'untrusted') {
|
|
286
|
+
// untrusted 的产品承诺就是笼;「越笼」提权通道与之矛盾(§4.1 同类拒绝)
|
|
287
|
+
throw new Error('effect_policy_invalid: escalation cannot combine with mode=untrusted (untrusted promises a jail)');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// (full 档纯配置矛盾已在最前 fail-closed,此处只剩 allowlist 的 TOCTOU 护栏)
|
|
291
|
+
if (escalation.policy === 'allowlist') {
|
|
292
|
+
if (escalation.allow.length === 0) {
|
|
293
|
+
throw new Error('effect_policy_invalid: escalation.policy=allowlist requires escalation.allow rules');
|
|
294
|
+
}
|
|
295
|
+
// 可写根统一口径(与 daemon 启动探测共用 escalationWritableRoots,防两处漂移)
|
|
296
|
+
const writableRoots = escalationWritableRoots({
|
|
297
|
+
workspaces: baseWorkspace !== undefined ? [baseWorkspace] : [],
|
|
298
|
+
transactionRoots: (config.transactionRoots ?? []).map((r) => expandHomePath(r)),
|
|
299
|
+
});
|
|
300
|
+
for (const rule of escalation.allow) {
|
|
301
|
+
if (!isAbsolute(rule.cmd)) {
|
|
302
|
+
throw new Error(`effect_policy_invalid: escalation rule cmd must be absolute, got ${JSON.stringify(rule.cmd)}`);
|
|
303
|
+
}
|
|
304
|
+
// 有效目标逐个过 TOCTOU 护栏(via: sudo 形态含 sudo 之后的真实二进制)
|
|
305
|
+
const targets = escalationRuleTargets(rule, escalation.via);
|
|
306
|
+
if ('invalid' in targets) {
|
|
307
|
+
throw new Error(`effect_policy_invalid: escalation rule rejected (${targets.invalid})`);
|
|
308
|
+
}
|
|
309
|
+
for (const target of targets.targets) {
|
|
310
|
+
const bad = checkEscalationBinary(target, writableRoots);
|
|
311
|
+
if (bad) {
|
|
312
|
+
throw new Error(`effect_policy_invalid: escalation rule rejected (${bad})`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
148
317
|
// Path jail is part of the untrusted promise; never loosen it from config.
|
|
149
318
|
const d = MODE_DEFAULTS[mode];
|
|
150
319
|
const pathContainment = requestedMode === 'untrusted'
|
|
151
320
|
? 'strict'
|
|
152
321
|
: (config.pathContainment ?? d.pathContainment);
|
|
322
|
+
// Final-symlink refusal is a hardening, so the untrusted promise turns it on
|
|
323
|
+
// and config cannot loosen it back off. Elsewhere it stays opt-in: with
|
|
324
|
+
// containment off, in-root links are a legitimate workflow.
|
|
325
|
+
const refuseFinalSymlink = requestedMode === 'untrusted' ? true : (config.refuseFinalSymlink ?? d.refuseFinalSymlink);
|
|
326
|
+
// Union, not replace: a preset may only *add* denied patterns, so a deployment
|
|
327
|
+
// cannot loosen a built-in deny list by supplying its own.
|
|
328
|
+
const pathDenylist = [...new Set([...(d.pathDenylist ?? []), ...(config.pathDenylist ?? [])])]
|
|
329
|
+
.map(normalizeDenyPattern);
|
|
330
|
+
// Two gates, deliberately: the config schema rejects these shapes at load time
|
|
331
|
+
// (so a daemon never starts believing it is protected), and this loop covers
|
|
332
|
+
// callers that hand-build a config object instead of going through the schema.
|
|
333
|
+
for (const pattern of pathDenylist) {
|
|
334
|
+
validateDenyPattern(pattern);
|
|
335
|
+
globToPathRegex(pattern);
|
|
336
|
+
}
|
|
153
337
|
// untrusted intent residue: keep discard-on-close even when effectiveMode renames
|
|
154
338
|
const onClose = config.onClose ??
|
|
155
339
|
(requestedMode === 'untrusted' ? MODE_DEFAULTS.untrusted.onClose : d.onClose);
|
|
@@ -163,12 +347,18 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
163
347
|
securityDegraded,
|
|
164
348
|
toolIsolation: config.toolIsolation ?? d.toolIsolation,
|
|
165
349
|
pathContainment,
|
|
350
|
+
refuseFinalSymlink,
|
|
351
|
+
pathDenylist,
|
|
166
352
|
// degraded untrusted must not leave shell allow as a hole
|
|
167
353
|
shellEscape: toolSurface === 'reduced' ? 'deny' : (config.shellEscape ?? d.shellEscape),
|
|
168
354
|
// untrusted product promise: egress deny is not a config knob (like pathContainment)
|
|
355
|
+
// jail=none:网络限制只由 jail 实施,无笼时 deny 是假承诺——显式配置已在上方拒绝,
|
|
356
|
+
// 未指定则如实取 open(§4.2 注记带 network=open)
|
|
169
357
|
network: requestedMode === 'untrusted' || toolSurface === 'reduced'
|
|
170
358
|
? 'deny'
|
|
171
|
-
:
|
|
359
|
+
: jail === 'none'
|
|
360
|
+
? 'open'
|
|
361
|
+
: (config.network ?? d.network),
|
|
172
362
|
processLimits: config.processLimits ?? d.processLimits,
|
|
173
363
|
commit: config.commit ?? d.commit,
|
|
174
364
|
onClose,
|
|
@@ -182,6 +372,18 @@ export function resolveEffectiveEffectPolicy(config, baseWorkspace, isolation) {
|
|
|
182
372
|
undoLimit: config.undoLimit,
|
|
183
373
|
shellJournal: config.shellJournal ?? 'snapshot',
|
|
184
374
|
shellJournalLimit: config.shellJournalLimit,
|
|
375
|
+
jail,
|
|
376
|
+
onJailUnavailable,
|
|
377
|
+
escalation,
|
|
378
|
+
// 特权上下文(§5 P4/§8.1):授权态标记,不是降级;root/elevated 维度由启动期探测叠加
|
|
379
|
+
privileged: jail === 'none' || escalation.policy === 'full',
|
|
380
|
+
dangerousCommands: {
|
|
381
|
+
policy: config.dangerousCommands?.policy ?? 'confirm',
|
|
382
|
+
timeoutMs: config.dangerousCommands?.timeoutMs ?? 120_000,
|
|
383
|
+
},
|
|
384
|
+
opsAudit: config.opsAudit ?? 'on',
|
|
385
|
+
opsAuditPath: config.opsAuditPath,
|
|
386
|
+
opsAuditExportPath: config.opsAuditExportPath,
|
|
185
387
|
};
|
|
186
388
|
}
|
|
187
389
|
/**
|
|
@@ -222,19 +424,39 @@ export function isPathAllowed(resolved, allowRoots, containment) {
|
|
|
222
424
|
return target === r || target.startsWith(r + '/');
|
|
223
425
|
});
|
|
224
426
|
}
|
|
427
|
+
/** 效应确认缓存 key(含目标):一次点头只覆盖同一目标,不按 kind 一类放行 */
|
|
428
|
+
function effectCacheKey(intent) {
|
|
429
|
+
switch (intent.kind) {
|
|
430
|
+
case 'file.write':
|
|
431
|
+
return `file.write:${intent.path}`;
|
|
432
|
+
case 'shell':
|
|
433
|
+
return `shell:${intent.command}`;
|
|
434
|
+
case 'runner':
|
|
435
|
+
return `runner:${intent.command}`;
|
|
436
|
+
case 'vcs':
|
|
437
|
+
return `vcs:${intent.operation}:${intent.cwd ?? ''}`;
|
|
438
|
+
case 'memory.write':
|
|
439
|
+
return `memory.write:${intent.domain}`;
|
|
440
|
+
case 'other':
|
|
441
|
+
return `other:${intent.description}`;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
225
444
|
/**
|
|
226
445
|
* 效应闸(P4):事务内自动放行;host-gate 交给宿主;engine 通道按内置策略。
|
|
227
446
|
*
|
|
228
447
|
* @param intent - 效应意图
|
|
229
448
|
* @param options - 通道与回调
|
|
230
|
-
* @
|
|
449
|
+
* @returns 放行结论(confirmed/confirmSource + 确认人归因,审计用)
|
|
450
|
+
* @throws Error 当拒绝执行时(`effect_confirm_timeout` 超时 / `effect_denied` 拒绝,语义分家)
|
|
231
451
|
*/
|
|
232
452
|
export async function gateEffect(intent, options) {
|
|
233
453
|
// 可事务化(可 undo)→ 自动
|
|
234
|
-
if (intent.kind === 'memory.write' && intent.transactional)
|
|
235
|
-
return;
|
|
236
|
-
|
|
237
|
-
|
|
454
|
+
if (intent.kind === 'memory.write' && intent.transactional) {
|
|
455
|
+
return { confirmed: false, confirmSource: 'auto-transaction' };
|
|
456
|
+
}
|
|
457
|
+
if (intent.kind === 'file.write' && intent.transactional) {
|
|
458
|
+
return { confirmed: false, confirmSource: 'auto-transaction' };
|
|
459
|
+
}
|
|
238
460
|
if (intent.kind === 'shell') {
|
|
239
461
|
const esc = options.shellEscape ?? 'allow';
|
|
240
462
|
// deny:无 L4 无法只禁越界,必须拒绝 shell(fail-closed,保策略语义)
|
|
@@ -250,25 +472,58 @@ export async function gateEffect(intent, options) {
|
|
|
250
472
|
// shellEscape gates the shell tool only — workspace stays capable of git/project scripts.
|
|
251
473
|
if (options.effects !== 'host-gate') {
|
|
252
474
|
// engine 通道:路径牢笼由 L2 承担;shell 已在上方按 shellEscape 处理
|
|
253
|
-
return;
|
|
475
|
+
return { confirmed: false, confirmSource: 'auto-engine' };
|
|
254
476
|
}
|
|
255
477
|
// host-gate:非事务效应交给宿主(自动放行 / 宿主 UI / 策略引擎)
|
|
256
478
|
const decide = options.confirmEffect;
|
|
257
479
|
if (!decide) {
|
|
258
480
|
throw new Error('confirm_effect_missing: effectPolicy.effects=host-gate requires confirmEffect callback');
|
|
259
481
|
}
|
|
260
|
-
// SEC-7:HitlDecision + 引擎缓存;失败路径 fail-closed
|
|
261
|
-
|
|
482
|
+
// SEC-7:HitlDecision + 引擎缓存;失败路径 fail-closed。
|
|
483
|
+
// 缓存 key 含目标(B(c) 拍板 2026-10-26):一次 approve_session 只覆盖同一目标,
|
|
484
|
+
// 不再按 kind 一类放行(旧「有意粗粒度」已翻案,见 KNOWN-ISSUES)
|
|
485
|
+
const outcome = await resolveHitlOutcome({
|
|
262
486
|
cache: options.hitlCache,
|
|
263
487
|
channel: 'effect',
|
|
264
|
-
key: intent
|
|
488
|
+
key: effectCacheKey(intent),
|
|
265
489
|
sessionId: options.sessionId ?? getRunSessionId(),
|
|
266
490
|
agentId: options.agentId ?? getRunScope()?.agentId,
|
|
267
|
-
|
|
491
|
+
// 宿主可返回裸 HitlDecision 或 ConfirmOutcome(带归因/来源);归因随结果回传审计
|
|
492
|
+
ask: async () => {
|
|
493
|
+
const raw = await decide(intent);
|
|
494
|
+
const normalized = typeof raw === 'string' ? { decision: raw } : raw;
|
|
495
|
+
return {
|
|
496
|
+
decision: normalized.decision,
|
|
497
|
+
...(normalized.approver !== undefined ? { approver: normalized.approver } : {}),
|
|
498
|
+
...(normalized.channel !== undefined ? { channel: normalized.channel } : {}),
|
|
499
|
+
// 宿主标注的拒绝来源:timeout 归超时语义;其余归通道故障——不得冒充人工拒绝
|
|
500
|
+
...(normalized.decision === 'deny' && normalized.reason === 'timeout'
|
|
501
|
+
? { timedOut: true }
|
|
502
|
+
: {}),
|
|
503
|
+
...(normalized.decision === 'deny' &&
|
|
504
|
+
normalized.reason !== undefined &&
|
|
505
|
+
normalized.reason !== 'timeout'
|
|
506
|
+
? { denyReason: 'channel_error', denyDetail: normalized.reason }
|
|
507
|
+
: {}),
|
|
508
|
+
};
|
|
509
|
+
},
|
|
268
510
|
});
|
|
269
|
-
if (!allowed) {
|
|
270
|
-
|
|
511
|
+
if (!outcome.allowed) {
|
|
512
|
+
// 错误面分家(与审计 why 同一口径):超时 ≠ 人工拒绝 ≠ 通道故障,不得混为一谈
|
|
513
|
+
if (outcome.timedOut) {
|
|
514
|
+
throw new Error(`effect_confirm_timeout: no decision for ${effectCacheKey(intent)} — timeout is deny; do NOT retry this call until a human decides`);
|
|
515
|
+
}
|
|
516
|
+
const provenance = outcome.denyReason
|
|
517
|
+
? ` (${outcome.denyReason}${outcome.denyDetail ? `: ${outcome.denyDetail}` : ''})`
|
|
518
|
+
: '';
|
|
519
|
+
throw new Error(`effect_denied: ${intent.kind}${provenance} — ${outcome.denyReason ? 'no human decision was reached' : 'a human rejected this effect'}`);
|
|
271
520
|
}
|
|
521
|
+
return {
|
|
522
|
+
confirmed: true,
|
|
523
|
+
confirmSource: 'host-gate',
|
|
524
|
+
...(outcome.approver !== undefined ? { confirmedBy: outcome.approver } : {}),
|
|
525
|
+
...(outcome.channel !== undefined ? { confirmChannel: outcome.channel } : {}),
|
|
526
|
+
};
|
|
272
527
|
}
|
|
273
528
|
const EFFECT_OVERRIDES_META_KEY = 'effectOverrides';
|
|
274
529
|
/**
|