@octopi-agent/engine 0.90.11 → 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/context.d.ts +6 -1
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +106 -4
- package/dist/config-schema/governance.d.ts +43 -1
- package/dist/config-schema/governance.js +157 -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 +15 -1
- package/dist/harness/agent/builder.js +31 -10
- 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 +72 -0
- package/dist/harness/agent/config-integrity.js +146 -0
- package/dist/harness/agent/wire-agent-builder.js +2 -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 +194 -49
- package/dist/harness/context/hybrid-compressor.js +6 -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/summarize.d.ts +2 -0
- package/dist/harness/context/summarize.js +7 -2
- 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 +127 -8
- package/dist/harness/extension/execution-environment/effect-policy.js +244 -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 +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 +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/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 +53 -2
- 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/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 +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/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- 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 +31 -0
- package/dist/harness/run/runner.d.ts +116 -2
- package/dist/harness/run/runner.js +547 -41
- 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/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/handler.js +1 -1
- package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
- package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
- package/package.json +3 -2
|
@@ -7,6 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { SandboxProvider, SandboxConfig, SandboxResult, IsolationLevel } from './types.js';
|
|
9
9
|
import { assessL4ProcessMinimum, supervisedSpawnProfile, type ProcessIsolationProfile } from './process-isolation.js';
|
|
10
|
+
/**
|
|
11
|
+
* Run 级失笼降级的归一码前缀(ops P0):probe 缺笼与运行时失笼共用 `no_process_jail`
|
|
12
|
+
* 前缀,消费面按前缀匹配即可覆盖全部失笼路径。
|
|
13
|
+
*
|
|
14
|
+
* @param detail - 失笼细节(jail_setup_failed / jail_spawn_failed / …)
|
|
15
|
+
* @returns 归一后的 securityDegraded 代码
|
|
16
|
+
*/
|
|
17
|
+
export declare function jailDegradationCode(detail: string): string;
|
|
10
18
|
export interface ProcessSandboxOptions {
|
|
11
19
|
/** Force a profile (tests). Otherwise probes on construct. */
|
|
12
20
|
profile?: ProcessIsolationProfile;
|
|
@@ -41,6 +49,20 @@ export declare class ProcessSandbox implements SandboxProvider {
|
|
|
41
49
|
*/
|
|
42
50
|
executeArgv(argv: string[], config?: SandboxConfig): Promise<SandboxResult>;
|
|
43
51
|
private run;
|
|
52
|
+
/**
|
|
53
|
+
* Attribute a setuid/privilege exec denial on the caller's channels.
|
|
54
|
+
*
|
|
55
|
+
* A jail that does not apply (nested sandbox, wrapper missing) still refuses
|
|
56
|
+
* setuid exec when an **enclosing** jail is in force, so attribution cannot
|
|
57
|
+
* live only in `runSeatbelt`. `denyExec` stays empty there: without proof we
|
|
58
|
+
* own the profile, claiming a specific deny-list entry would be a guess.
|
|
59
|
+
*
|
|
60
|
+
* @param pending - result promise from whichever backend ran
|
|
61
|
+
* @param cwd - run cwd, used to resolve bare command names
|
|
62
|
+
* @param denyExec - deny list we know is in force (empty when unknown)
|
|
63
|
+
* @returns result, with one explanation attached when stderr was attributable
|
|
64
|
+
*/
|
|
65
|
+
private withExecDiagnostics;
|
|
44
66
|
private runSupervised;
|
|
45
67
|
private runBwrap;
|
|
46
68
|
private runSeatbelt;
|
|
@@ -117,6 +139,93 @@ export declare function buildSeatbeltProfile(roots: string[], network: 'open' |
|
|
|
117
139
|
* bwrap supplies its own /dev). Character sinks cannot escape the jail.
|
|
118
140
|
*/
|
|
119
141
|
export declare const SEATBELT_DEVICE_WRITE_ALLOW: readonly ["/dev/null", "/dev/zero", "/dev/tty", "/dev/stdin", "/dev/stdout", "/dev/stderr"];
|
|
142
|
+
/**
|
|
143
|
+
* Privilege-gaining binaries, grouped by the capability they grant.
|
|
144
|
+
*
|
|
145
|
+
* This is a **cross-platform superset on purpose**, not a survey of the host
|
|
146
|
+
* running it. Two reasons:
|
|
147
|
+
* - Seatbelt's `(literal ...)` matches a path string exactly; it does not
|
|
148
|
+
* normalise `/bin` vs `/usr/bin` or `sbin` vs `bin`. Distributions disagree
|
|
149
|
+
* on all of them (`su` is `/bin/su` on Debian, `/usr/bin/su` on macOS;
|
|
150
|
+
* `chroot` lives under `/usr/sbin` on macOS and additionally under
|
|
151
|
+
* `/usr/bin` / `/sbin` elsewhere). A missing spelling is an open door.
|
|
152
|
+
* - A deny line for a path that does not exist on this host never matches and
|
|
153
|
+
* costs nothing: no error, no runtime penalty. So the asymmetry is one-way —
|
|
154
|
+
* dead entries are free, missing entries are a hole.
|
|
155
|
+
*
|
|
156
|
+
* **Do not trim this list by inspecting one machine.** Every entry that looks
|
|
157
|
+
* dead on macOS is live on some Linux distribution. New privilege-gaining
|
|
158
|
+
* helpers (`pkexec`, `doas`, `run0`, `sudoedit`) are inherited by every jail
|
|
159
|
+
* backend that shares this table, so the risk of a stale entry is the cheaper
|
|
160
|
+
* side of the trade.
|
|
161
|
+
*/
|
|
162
|
+
export declare const PRIVILEGE_DENY_EXEC_GROUPS: {
|
|
163
|
+
/** Full privilege switch to any user. */
|
|
164
|
+
readonly su: readonly ["/bin/su", "/usr/bin/su", "/sbin/su"];
|
|
165
|
+
/** Run a command as another user (sudo family). */
|
|
166
|
+
readonly sudo: readonly ["/usr/bin/sudo", "/bin/sudo", "/usr/local/bin/sudo"];
|
|
167
|
+
/** Edit a file as root through sudo. */
|
|
168
|
+
readonly sudoedit: readonly ["/usr/bin/sudoedit", "/bin/sudoedit"];
|
|
169
|
+
/** Polkit-mediated privilege escalation (desktop Linux). */
|
|
170
|
+
readonly pkexec: readonly ["/usr/bin/pkexec", "/usr/local/bin/pkexec"];
|
|
171
|
+
/** Minimal sudo replacement (OpenBSD, Alpine, some Linux). */
|
|
172
|
+
readonly doas: readonly ["/usr/bin/doas", "/usr/local/bin/doas", "/usr/local/sbin/doas"];
|
|
173
|
+
/** systemd-run privilege escalation (systemd >= 256). */
|
|
174
|
+
readonly run0: readonly ["/usr/bin/run0"];
|
|
175
|
+
/** Replace the session, bypassing the caller's credentials. */
|
|
176
|
+
readonly login: readonly ["/usr/bin/login", "/bin/login"];
|
|
177
|
+
/** Change the process group ID without a password. */
|
|
178
|
+
readonly newgrp: readonly ["/usr/bin/newgrp", "/bin/newgrp", "/usr/bin/sg", "/bin/sg"];
|
|
179
|
+
/** Start a process in a different root / namespace. */
|
|
180
|
+
readonly chroot: readonly ["/usr/sbin/chroot", "/usr/bin/chroot", "/sbin/chroot", "/bin/chroot"];
|
|
181
|
+
/** Read or modify the local directory service (macOS account DB). */
|
|
182
|
+
readonly dscl: readonly ["/usr/bin/dscl", "/usr/sbin/dscl"];
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Flat deny list in force unless the host overrides it.
|
|
186
|
+
*
|
|
187
|
+
* Derived from {@link PRIVILEGE_DENY_EXEC_GROUPS} so the grouped table stays
|
|
188
|
+
* the single source of truth.
|
|
189
|
+
*/
|
|
190
|
+
export declare const DEFAULT_PRIVILEGE_DENY_EXEC: readonly string[];
|
|
191
|
+
/**
|
|
192
|
+
* One denial the jail produced, attributed to the mechanism that caused it.
|
|
193
|
+
*
|
|
194
|
+
* Two mechanisms print `Operation not permitted`, and they need **different**
|
|
195
|
+
* advice:
|
|
196
|
+
* - `setuid-exec` — the OS refuses `execve` of a setuid binary inside
|
|
197
|
+
* Seatbelt. This is a kernel invariant: no profile edit can allow it. `ps`
|
|
198
|
+
* and `top` are setuid on macOS, which is why process listing dies there.
|
|
199
|
+
* - `privilege-deny` — an explicit `(deny process-exec ...)` line written by
|
|
200
|
+
* `buildSeatbeltProfile` for privileged helpers that are **not** setuid
|
|
201
|
+
* (`chroot`, `dscl`); the implicit setuid rule does not cover them.
|
|
202
|
+
*
|
|
203
|
+
* Write and network denials print the same EPERM wording but are left
|
|
204
|
+
* unattributed on purpose — blaming them on exec would misdirect the caller.
|
|
205
|
+
*/
|
|
206
|
+
export interface SeatbeltExecDenial {
|
|
207
|
+
/** Absolute path of the denied binary (PATH-resolved when reported bare). */
|
|
208
|
+
target: string;
|
|
209
|
+
/** Which mechanism refused the exec. */
|
|
210
|
+
kind: 'setuid-exec' | 'privilege-deny';
|
|
211
|
+
/** Factual one-liner for the isolation notes (what the jail did). */
|
|
212
|
+
note: string;
|
|
213
|
+
/** Actionable one-liner for the caller (what to do instead). */
|
|
214
|
+
hint: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Attribute an exec denial inside the macOS jail so the caller can correct
|
|
218
|
+
* itself without re-discovering the sandbox's invariants by trial and error.
|
|
219
|
+
*
|
|
220
|
+
* @param args - captured stderr, run cwd, and the deny list written into the profile
|
|
221
|
+
* @returns the first attributable denial, or null when EPERM had another cause
|
|
222
|
+
*/
|
|
223
|
+
export declare function explainSeatbeltExecDenial(args: {
|
|
224
|
+
stderr: string;
|
|
225
|
+
cwd: string;
|
|
226
|
+
/** Deny list actually emitted into the profile; defaults to the built-in one. */
|
|
227
|
+
denyExec?: readonly string[];
|
|
228
|
+
}): Promise<SeatbeltExecDenial | null>;
|
|
120
229
|
/**
|
|
121
230
|
* Create the best process sandbox this host can offer.
|
|
122
231
|
*
|
|
@@ -6,11 +6,21 @@
|
|
|
6
6
|
* Public contract: `docs/process-isolation.md`.
|
|
7
7
|
*/
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
|
-
import { realpath, unlink, writeFile } from 'node:fs/promises';
|
|
9
|
+
import { realpath, stat, unlink, writeFile } from 'node:fs/promises';
|
|
10
10
|
import { homedir, tmpdir } from 'node:os';
|
|
11
11
|
import { join, resolve } from 'node:path';
|
|
12
12
|
import { StringDecoder } from 'node:string_decoder';
|
|
13
13
|
import { assessL4ProcessMinimum, killProcessTree, probeProcessIsolation, scrubEnv, supervisedSpawnProfile, } from './process-isolation.js';
|
|
14
|
+
/**
|
|
15
|
+
* Run 级失笼降级的归一码前缀(ops P0):probe 缺笼与运行时失笼共用 `no_process_jail`
|
|
16
|
+
* 前缀,消费面按前缀匹配即可覆盖全部失笼路径。
|
|
17
|
+
*
|
|
18
|
+
* @param detail - 失笼细节(jail_setup_failed / jail_spawn_failed / …)
|
|
19
|
+
* @returns 归一后的 securityDegraded 代码
|
|
20
|
+
*/
|
|
21
|
+
export function jailDegradationCode(detail) {
|
|
22
|
+
return `no_process_jail: ${detail}`;
|
|
23
|
+
}
|
|
14
24
|
/**
|
|
15
25
|
* Supervised process runner: tree-killable spawn with scrubbed env.
|
|
16
26
|
* This is NOT a filesystem jail — `isolation.filesystem` stays `cwd-pin`.
|
|
@@ -63,6 +73,22 @@ export class ProcessSandbox {
|
|
|
63
73
|
const env = scrubEnv(config?.env, { forceKeys: this.forceEnvKeys });
|
|
64
74
|
const timeoutMs = config?.limits?.timeoutMs ?? 60_000;
|
|
65
75
|
const maxOutputBytes = config?.limits?.maxOutputBytes ?? 10 * 1024 * 1024;
|
|
76
|
+
if (config?.disableJail && config?.requireJail) {
|
|
77
|
+
// 库契约守卫:两个都设 = 配置矛盾,绝不静默取舍
|
|
78
|
+
return Promise.reject(new Error('sandbox_config_conflict: disableJail and requireJail are mutually exclusive'));
|
|
79
|
+
}
|
|
80
|
+
// 授权无笼(ops P0:jail=none + privilegedAck 已过配置闸):显式注记,不是降级
|
|
81
|
+
if (config?.disableJail) {
|
|
82
|
+
return this.withExecDiagnostics(this.runSupervised(file, args, config, {
|
|
83
|
+
...profile,
|
|
84
|
+
backend: 'supervised-spawn',
|
|
85
|
+
processTree: 'killable',
|
|
86
|
+
filesystem: 'cwd-pin',
|
|
87
|
+
privilege: 'same',
|
|
88
|
+
network: 'open',
|
|
89
|
+
notes: [...(profile.notes ?? []), 'jail=disabled_by_config (privileged)'],
|
|
90
|
+
}, { cwd, env, timeoutMs, maxOutputBytes }), cwd, []);
|
|
91
|
+
}
|
|
66
92
|
// Jail backends wrap the spawn; fall back to supervised spawn.
|
|
67
93
|
if (profile.backend === 'linux-bwrap' && process.platform === 'linux') {
|
|
68
94
|
return this.runBwrap(file, args, config, profile, { cwd, env, timeoutMs, maxOutputBytes });
|
|
@@ -71,9 +97,44 @@ export class ProcessSandbox {
|
|
|
71
97
|
return this.runSeatbelt(file, args, config, profile, { cwd, env, timeoutMs, maxOutputBytes });
|
|
72
98
|
}
|
|
73
99
|
if (config?.requireJail) {
|
|
74
|
-
return Promise.reject(new Error(`
|
|
100
|
+
return Promise.reject(new Error(`jail_required_unavailable: no process jail backend (probe=${profile.backend}); refuse unsandboxed execute`));
|
|
75
101
|
}
|
|
76
|
-
|
|
102
|
+
// jail 意图落空(auto+degrade):逐条命令如实注记;run 级 securityDegraded
|
|
103
|
+
// 已由 resolveEffectiveEffectPolicy 记 `no_process_jail`(probe 期缺笼)
|
|
104
|
+
return this.withExecDiagnostics(this.runSupervised(file, args, config, {
|
|
105
|
+
...profile,
|
|
106
|
+
notes: [...(profile.notes ?? []), 'jail=unavailable (supervised-spawn); running unsandboxed'],
|
|
107
|
+
}, { cwd, env, timeoutMs, maxOutputBytes }), cwd, []);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Attribute a setuid/privilege exec denial on the caller's channels.
|
|
111
|
+
*
|
|
112
|
+
* A jail that does not apply (nested sandbox, wrapper missing) still refuses
|
|
113
|
+
* setuid exec when an **enclosing** jail is in force, so attribution cannot
|
|
114
|
+
* live only in `runSeatbelt`. `denyExec` stays empty there: without proof we
|
|
115
|
+
* own the profile, claiming a specific deny-list entry would be a guess.
|
|
116
|
+
*
|
|
117
|
+
* @param pending - result promise from whichever backend ran
|
|
118
|
+
* @param cwd - run cwd, used to resolve bare command names
|
|
119
|
+
* @param denyExec - deny list we know is in force (empty when unknown)
|
|
120
|
+
* @returns result, with one explanation attached when stderr was attributable
|
|
121
|
+
*/
|
|
122
|
+
withExecDiagnostics(pending, cwd, denyExec) {
|
|
123
|
+
if (process.platform !== 'darwin')
|
|
124
|
+
return Promise.resolve(pending);
|
|
125
|
+
return Promise.resolve(pending).then(async (result) => {
|
|
126
|
+
const denial = await explainSeatbeltExecDenial({ stderr: result.stderr, cwd, denyExec });
|
|
127
|
+
if (!denial)
|
|
128
|
+
return result;
|
|
129
|
+
return {
|
|
130
|
+
...result,
|
|
131
|
+
isolation: {
|
|
132
|
+
...result.isolation,
|
|
133
|
+
notes: [...(result.isolation.notes ?? []), denial.note],
|
|
134
|
+
},
|
|
135
|
+
diagnostics: { hints: [denial.hint] },
|
|
136
|
+
};
|
|
137
|
+
});
|
|
77
138
|
}
|
|
78
139
|
runSupervised(file, args, config, profile, opts) {
|
|
79
140
|
return new Promise((resolve, reject) => {
|
|
@@ -182,7 +243,7 @@ export class ProcessSandbox {
|
|
|
182
243
|
const usage = this.usage(start, stdoutCaptured, stderrCaptured);
|
|
183
244
|
const isJailWrapper = profile.backend === 'linux-bwrap' || profile.backend === 'mac-seatbelt';
|
|
184
245
|
if (config?.requireJail && isJailWrapper) {
|
|
185
|
-
fail(new Error(`
|
|
246
|
+
fail(new Error(`jail_required_unavailable: jail spawn failed: ${err.message} (requireJail=true; refuse unsandboxed execute)`));
|
|
186
247
|
return;
|
|
187
248
|
}
|
|
188
249
|
const honest = isJailWrapper
|
|
@@ -193,8 +254,10 @@ export class ProcessSandbox {
|
|
|
193
254
|
notes: [...(profile.notes ?? []), `jail spawn failed: ${err.message}`],
|
|
194
255
|
}
|
|
195
256
|
: profile;
|
|
196
|
-
|
|
197
|
-
|
|
257
|
+
// 归一码 no_process_jail(与 jailSetupFailed/jailWrapperRuntimeFailure 同前缀)
|
|
258
|
+
if (isJailWrapper) {
|
|
259
|
+
config?.noteSecurityDegraded?.(jailDegradationCode(`jail_spawn_failed: ${err.message}`));
|
|
260
|
+
}
|
|
198
261
|
finish({
|
|
199
262
|
exitCode: -1,
|
|
200
263
|
stdout,
|
|
@@ -263,11 +326,14 @@ export class ProcessSandbox {
|
|
|
263
326
|
// Host override wins; otherwise generate a profile covering allowRoots (D3-b+).
|
|
264
327
|
let profilePath = process.env.OCTOPI_SB_PROFILE;
|
|
265
328
|
let generatedPath;
|
|
329
|
+
/** Deny list in force, or null when an external profile owns it (unknown). */
|
|
330
|
+
let denyExec = null;
|
|
266
331
|
if (!profilePath) {
|
|
267
332
|
generatedPath = join(tmpdir(), `octopi-sb-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.sb`);
|
|
268
333
|
try {
|
|
269
334
|
await writeFile(generatedPath, buildSeatbeltProfile(roots, network), { encoding: 'utf8', mode: 0o600 });
|
|
270
335
|
profilePath = generatedPath;
|
|
336
|
+
denyExec = DEFAULT_PRIVILEGE_DENY_EXEC;
|
|
271
337
|
}
|
|
272
338
|
catch (err) {
|
|
273
339
|
return this.jailSetupFailed(file, args, config, profile, opts, `seatbelt profile generation failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -294,7 +360,11 @@ export class ProcessSandbox {
|
|
|
294
360
|
if (isJailWrapperSetupFailure(result, 'sandbox-exec')) {
|
|
295
361
|
return await this.jailWrapperRuntimeFailure(result, config, profile, `seatbelt apply failed (exit=${result.exitCode}): ${result.stderr.slice(0, 200)}`);
|
|
296
362
|
}
|
|
297
|
-
|
|
363
|
+
// A real command may have printed EPERM for reasons the caller cannot see
|
|
364
|
+
// from inside the jail (setuid exec is an OS invariant; privileged
|
|
365
|
+
// helpers are denied by the profile). Attribute it once, on the honest
|
|
366
|
+
// channels: isolation notes (what the jail did) + diagnostics (next step).
|
|
367
|
+
return this.withExecDiagnostics(result, opts.cwd, denyExec ?? []);
|
|
298
368
|
}
|
|
299
369
|
finally {
|
|
300
370
|
if (generatedPath) {
|
|
@@ -308,7 +378,7 @@ export class ProcessSandbox {
|
|
|
308
378
|
*/
|
|
309
379
|
jailSetupFailed(file, args, config, profile, opts, reason) {
|
|
310
380
|
if (config?.requireJail) {
|
|
311
|
-
return Promise.reject(new Error(`
|
|
381
|
+
return Promise.reject(new Error(`jail_required_unavailable: ${reason} (requireJail=true; refuse unsandboxed execute)`));
|
|
312
382
|
}
|
|
313
383
|
const degraded = {
|
|
314
384
|
...profile,
|
|
@@ -319,7 +389,8 @@ export class ProcessSandbox {
|
|
|
319
389
|
network: 'open',
|
|
320
390
|
notes: [...(profile.notes ?? []), `jail_setup_failed: ${reason}; supervised fallback`],
|
|
321
391
|
};
|
|
322
|
-
|
|
392
|
+
// 归一码 no_process_jail:消费面按前缀匹配即可覆盖 probe 缺笼与运行时建笼失败两类路径
|
|
393
|
+
config?.noteSecurityDegraded?.(jailDegradationCode(`jail_setup_failed: ${reason}`));
|
|
323
394
|
return this.runSupervised(file, args, config, degraded, opts);
|
|
324
395
|
}
|
|
325
396
|
/**
|
|
@@ -337,9 +408,10 @@ export class ProcessSandbox {
|
|
|
337
408
|
*/
|
|
338
409
|
jailWrapperRuntimeFailure(result, config, profile, reason) {
|
|
339
410
|
if (config?.requireJail) {
|
|
340
|
-
return Promise.reject(new Error(`
|
|
411
|
+
return Promise.reject(new Error(`jail_required_unavailable: ${reason} (requireJail=true; refuse unsandboxed execute)`));
|
|
341
412
|
}
|
|
342
|
-
|
|
413
|
+
// 归一码 no_process_jail(同 jailSetupFailed)
|
|
414
|
+
config?.noteSecurityDegraded?.(jailDegradationCode(`jail_setup_failed: ${reason}`));
|
|
343
415
|
return Promise.resolve({
|
|
344
416
|
...result,
|
|
345
417
|
isolation: {
|
|
@@ -520,16 +592,151 @@ export const SEATBELT_DEVICE_WRITE_ALLOW = [
|
|
|
520
592
|
'/dev/stdout',
|
|
521
593
|
'/dev/stderr',
|
|
522
594
|
];
|
|
523
|
-
/**
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
595
|
+
/**
|
|
596
|
+
* Privilege-gaining binaries, grouped by the capability they grant.
|
|
597
|
+
*
|
|
598
|
+
* This is a **cross-platform superset on purpose**, not a survey of the host
|
|
599
|
+
* running it. Two reasons:
|
|
600
|
+
* - Seatbelt's `(literal ...)` matches a path string exactly; it does not
|
|
601
|
+
* normalise `/bin` vs `/usr/bin` or `sbin` vs `bin`. Distributions disagree
|
|
602
|
+
* on all of them (`su` is `/bin/su` on Debian, `/usr/bin/su` on macOS;
|
|
603
|
+
* `chroot` lives under `/usr/sbin` on macOS and additionally under
|
|
604
|
+
* `/usr/bin` / `/sbin` elsewhere). A missing spelling is an open door.
|
|
605
|
+
* - A deny line for a path that does not exist on this host never matches and
|
|
606
|
+
* costs nothing: no error, no runtime penalty. So the asymmetry is one-way —
|
|
607
|
+
* dead entries are free, missing entries are a hole.
|
|
608
|
+
*
|
|
609
|
+
* **Do not trim this list by inspecting one machine.** Every entry that looks
|
|
610
|
+
* dead on macOS is live on some Linux distribution. New privilege-gaining
|
|
611
|
+
* helpers (`pkexec`, `doas`, `run0`, `sudoedit`) are inherited by every jail
|
|
612
|
+
* backend that shares this table, so the risk of a stale entry is the cheaper
|
|
613
|
+
* side of the trade.
|
|
614
|
+
*/
|
|
615
|
+
export const PRIVILEGE_DENY_EXEC_GROUPS = {
|
|
616
|
+
/** Full privilege switch to any user. */
|
|
617
|
+
su: ['/bin/su', '/usr/bin/su', '/sbin/su'],
|
|
618
|
+
/** Run a command as another user (sudo family). */
|
|
619
|
+
sudo: ['/usr/bin/sudo', '/bin/sudo', '/usr/local/bin/sudo'],
|
|
620
|
+
/** Edit a file as root through sudo. */
|
|
621
|
+
sudoedit: ['/usr/bin/sudoedit', '/bin/sudoedit'],
|
|
622
|
+
/** Polkit-mediated privilege escalation (desktop Linux). */
|
|
623
|
+
pkexec: ['/usr/bin/pkexec', '/usr/local/bin/pkexec'],
|
|
624
|
+
/** Minimal sudo replacement (OpenBSD, Alpine, some Linux). */
|
|
625
|
+
doas: ['/usr/bin/doas', '/usr/local/bin/doas', '/usr/local/sbin/doas'],
|
|
626
|
+
/** systemd-run privilege escalation (systemd >= 256). */
|
|
627
|
+
run0: ['/usr/bin/run0'],
|
|
628
|
+
/** Replace the session, bypassing the caller's credentials. */
|
|
629
|
+
login: ['/usr/bin/login', '/bin/login'],
|
|
630
|
+
/** Change the process group ID without a password. */
|
|
631
|
+
newgrp: ['/usr/bin/newgrp', '/bin/newgrp', '/usr/bin/sg', '/bin/sg'],
|
|
632
|
+
/** Start a process in a different root / namespace. */
|
|
633
|
+
chroot: ['/usr/sbin/chroot', '/usr/bin/chroot', '/sbin/chroot', '/bin/chroot'],
|
|
634
|
+
/** Read or modify the local directory service (macOS account DB). */
|
|
635
|
+
dscl: ['/usr/bin/dscl', '/usr/sbin/dscl'],
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Flat deny list in force unless the host overrides it.
|
|
639
|
+
*
|
|
640
|
+
* Derived from {@link PRIVILEGE_DENY_EXEC_GROUPS} so the grouped table stays
|
|
641
|
+
* the single source of truth.
|
|
642
|
+
*/
|
|
643
|
+
export const DEFAULT_PRIVILEGE_DENY_EXEC = Object.values(PRIVILEGE_DENY_EXEC_GROUPS).flat();
|
|
644
|
+
/** POSIX binary directories searched for a bare command name. */
|
|
645
|
+
const EXEC_LOOKUP_DIRS = ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'];
|
|
646
|
+
/** Setuid file mode bit. */
|
|
647
|
+
const SETUID_BIT = 0o4000;
|
|
648
|
+
/** Cap on distinct paths probed from one stderr, to bound `stat` cost. */
|
|
649
|
+
const EXEC_DENIAL_PROBE_LIMIT = 8;
|
|
650
|
+
/**
|
|
651
|
+
* Locate a binary the shell named in an EPERM line.
|
|
652
|
+
*
|
|
653
|
+
* @param token - absolute path or bare command name from stderr
|
|
654
|
+
* @param cwd - base for relative paths
|
|
655
|
+
* @returns resolved absolute path with its mode, or null when nothing exists
|
|
656
|
+
*/
|
|
657
|
+
async function resolveExecutable(token, cwd) {
|
|
658
|
+
const candidates = token.includes('/')
|
|
659
|
+
? [resolve(cwd, token)]
|
|
660
|
+
: EXEC_LOOKUP_DIRS.map((dir) => join(dir, token));
|
|
661
|
+
for (const candidate of candidates) {
|
|
662
|
+
try {
|
|
663
|
+
const info = await stat(candidate);
|
|
664
|
+
if (info.isFile())
|
|
665
|
+
return { path: candidate, mode: info.mode };
|
|
666
|
+
}
|
|
667
|
+
catch {
|
|
668
|
+
// Not in this directory — try the next candidate.
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Extract the subject of each EPERM line.
|
|
675
|
+
*
|
|
676
|
+
* Shells disagree on where the path sits:
|
|
677
|
+
* - bash/sh: `bash: line 1: /usr/bin/top: Operation not permitted`
|
|
678
|
+
* - zsh: `zsh:1: operation not permitted: /usr/bin/top`
|
|
679
|
+
*
|
|
680
|
+
* Deduped and capped: a pathological command can emit thousands of EPERM lines
|
|
681
|
+
* and each candidate costs up to one `stat` per lookup dir.
|
|
682
|
+
*
|
|
683
|
+
* @param stderr - captured stderr
|
|
684
|
+
* @returns distinct paths in emission order
|
|
685
|
+
*/
|
|
686
|
+
function extractDeniedTargets(stderr) {
|
|
687
|
+
const targets = new Set();
|
|
688
|
+
for (const raw of stderr.split('\n')) {
|
|
689
|
+
if (targets.size >= EXEC_DENIAL_PROBE_LIMIT)
|
|
690
|
+
break;
|
|
691
|
+
const line = raw.trim();
|
|
692
|
+
if (!/operation not permitted/i.test(line))
|
|
693
|
+
continue;
|
|
694
|
+
const trailing = /(?:^|:)\s*([^\s:][^:\n]*?):\s*operation not permitted$/i.exec(line);
|
|
695
|
+
if (trailing?.[1]) {
|
|
696
|
+
targets.add(trailing[1].trim());
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const leading = /operation not permitted:\s*(\S.*)$/i.exec(line);
|
|
700
|
+
if (leading?.[1])
|
|
701
|
+
targets.add(leading[1].trim());
|
|
702
|
+
}
|
|
703
|
+
return [...targets];
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Attribute an exec denial inside the macOS jail so the caller can correct
|
|
707
|
+
* itself without re-discovering the sandbox's invariants by trial and error.
|
|
708
|
+
*
|
|
709
|
+
* @param args - captured stderr, run cwd, and the deny list written into the profile
|
|
710
|
+
* @returns the first attributable denial, or null when EPERM had another cause
|
|
711
|
+
*/
|
|
712
|
+
export async function explainSeatbeltExecDenial(args) {
|
|
713
|
+
const deny = new Set(args.denyExec ?? DEFAULT_PRIVILEGE_DENY_EXEC);
|
|
714
|
+
for (const token of extractDeniedTargets(args.stderr)) {
|
|
715
|
+
const found = await resolveExecutable(token, args.cwd);
|
|
716
|
+
if (!found)
|
|
717
|
+
continue;
|
|
718
|
+
if (deny.has(found.path)) {
|
|
719
|
+
return {
|
|
720
|
+
target: found.path,
|
|
721
|
+
kind: 'privilege-deny',
|
|
722
|
+
note: `exec_denied: ${found.path} is on the jail privilege deny list`,
|
|
723
|
+
hint: `exec_denied: ${found.path} is on the sandbox privilege deny list (buildSeatbeltProfile) — ` +
|
|
724
|
+
`privileged helpers are blocked by design inside the jail; do not retry, find an unprivileged route.`,
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
if ((found.mode & SETUID_BIT) !== 0) {
|
|
728
|
+
return {
|
|
729
|
+
target: found.path,
|
|
730
|
+
kind: 'setuid-exec',
|
|
731
|
+
note: `exec_denied: ${found.path} is setuid; seatbelt refuses setuid exec (macOS invariant)`,
|
|
732
|
+
hint: `exec_denied: ${found.path} is setuid and seatbelt refuses setuid exec — a macOS invariant, ` +
|
|
733
|
+
`not configurable by the profile. Do not retry it; read the same state without exec'ing a ` +
|
|
734
|
+
`setuid binary (e.g. pgrep -fl, lsof, vm_stat, or libproc proc_pidinfo).`,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return null;
|
|
739
|
+
}
|
|
533
740
|
function resolveShell() {
|
|
534
741
|
if (process.platform === 'win32') {
|
|
535
742
|
const comspec = process.env.COMSPEC || 'cmd.exe';
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import type { ToolCapability } from '@octopi-agent/core/types.js';
|
|
11
11
|
export type { ToolCapability };
|
|
12
12
|
/** Capabilities that are denied on the reduced tool surface. */
|
|
13
|
-
export declare const REDUCED_DENIED_CAPABILITIES: readonly ["exec", "egress", "send", "dynamic-code", "runner"];
|
|
13
|
+
export declare const REDUCED_DENIED_CAPABILITIES: readonly ["exec", "egress", "send", "dynamic-code", "runner", "host-read"];
|
|
14
14
|
/**
|
|
15
15
|
* Builtin name → capability tags. Keep in sync with each tool definition's
|
|
16
16
|
* `capabilities` field (backfilled for every builtin).
|
|
@@ -15,6 +15,8 @@ export const REDUCED_DENIED_CAPABILITIES = [
|
|
|
15
15
|
'dynamic-code',
|
|
16
16
|
/** project_run executes workspace-defined scripts (code execution) */
|
|
17
17
|
'runner',
|
|
18
|
+
/** host introspection (process table/argv) — engine-side data bypasses the jail's "cannot see host processes" boundary */
|
|
19
|
+
'host-read',
|
|
18
20
|
];
|
|
19
21
|
/**
|
|
20
22
|
* Builtin name → capability tags. Keep in sync with each tool definition's
|
|
@@ -48,6 +50,10 @@ export const BUILTIN_TOOL_CAPABILITIES = {
|
|
|
48
50
|
document_read: ['fs-read'],
|
|
49
51
|
document_probe: ['fs-read'],
|
|
50
52
|
env_info: ['fs-read'],
|
|
53
|
+
// 只读进程诊断(ops P1):宿主内省(进程表/argv),reduced 面剥掉(host-read)
|
|
54
|
+
process_list: ['host-read'],
|
|
55
|
+
// exec 标签:reduced 面剥掉提权通道(降能力不降墙)
|
|
56
|
+
priv_exec: ['exec'],
|
|
51
57
|
http_request: ['egress'],
|
|
52
58
|
web_search: ['egress'],
|
|
53
59
|
ask_user: [],
|
|
@@ -35,6 +35,13 @@ export interface SandboxConfig {
|
|
|
35
35
|
* Setup failure throws instead of falling back to supervised spawn.
|
|
36
36
|
*/
|
|
37
37
|
requireJail?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* ops P0: authorized no-jail (`effectPolicy.jail: "none"`, privilegedAck
|
|
40
|
+
* already enforced at config resolution). Skips jail wrapping even when a
|
|
41
|
+
* backend is present and notes `jail=disabled_by_config (privileged)` —
|
|
42
|
+
* this is an authorization, never a degradation.
|
|
43
|
+
*/
|
|
44
|
+
disableJail?: boolean;
|
|
38
45
|
/**
|
|
39
46
|
* Allow `$HOME` writes inside the jail (project/host only per 2b).
|
|
40
47
|
* tmpdir and, on POSIX, shared `/tmp` + `/var/tmp` are always writable (2a);
|
|
@@ -84,6 +91,18 @@ export interface SandboxResult {
|
|
|
84
91
|
usage: ResourceUsage;
|
|
85
92
|
/** Honest isolation actually applied for this run */
|
|
86
93
|
isolation: ProcessIsolationProfile;
|
|
94
|
+
/** Structured diagnostics; absent when the run explained itself */
|
|
95
|
+
diagnostics?: SandboxDiagnostics;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Structured, machine-readable diagnostics for a sandboxed run.
|
|
99
|
+
*
|
|
100
|
+
* Hints exist so a caller can self-correct on the next attempt instead of
|
|
101
|
+
* re-discovering a sandbox invariant (mirrors `file_search` diagnostics).
|
|
102
|
+
*/
|
|
103
|
+
export interface SandboxDiagnostics {
|
|
104
|
+
/** Actionable self-correction hints, one line each */
|
|
105
|
+
hints?: string[];
|
|
87
106
|
}
|
|
88
107
|
/**
|
|
89
108
|
* SandboxProvider — execute commands under an isolation profile.
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* - Plugin 通过 registerChannel(adapter) 注册实现
|
|
10
10
|
* - Gateway / Integration 按部署形态挂载具体 adapter
|
|
11
11
|
*/
|
|
12
|
+
export type ChannelMessageDelivery = 'steered' | 'followup' | 'run';
|
|
12
13
|
export interface ChannelMessage {
|
|
13
14
|
id: string;
|
|
14
15
|
channel: string;
|
|
@@ -18,6 +19,10 @@ export interface ChannelMessage {
|
|
|
18
19
|
conversationId: string;
|
|
19
20
|
timestamp: number;
|
|
20
21
|
metadata?: Record<string, unknown>;
|
|
22
|
+
/** Runtime 受理后的真实去向;宿主回执用,不进入模型。 */
|
|
23
|
+
delivery?: ChannelMessageDelivery;
|
|
24
|
+
/** 宿主传入;Runtime 实际受理后由 Gateway 调用。 */
|
|
25
|
+
onDelivery?: (delivery: ChannelMessageDelivery) => void;
|
|
21
26
|
}
|
|
22
27
|
export interface ChannelReply {
|
|
23
28
|
channel: string;
|
|
@@ -51,6 +51,7 @@ export async function runAllowlistedArgv(options) {
|
|
|
51
51
|
allowRoots: [cwd, ...journalRoots],
|
|
52
52
|
networkPolicy: context?.networkPolicy ?? 'deny',
|
|
53
53
|
requireJail: context?.requireJail,
|
|
54
|
+
disableJail: context?.disableJail,
|
|
54
55
|
homeWrite: context?.homeWrite,
|
|
55
56
|
noteSecurityDegraded: context?.noteSecurityDegraded,
|
|
56
57
|
signal: context?.abortSignal,
|
|
@@ -59,6 +60,38 @@ export async function runAllowlistedArgv(options) {
|
|
|
59
60
|
maxOutputBytes: 16 * 1024 * 1024,
|
|
60
61
|
},
|
|
61
62
|
});
|
|
63
|
+
// ops P2 §7:统一动作记录(allowlisted exec 同契约;P3 提权通道复用此形态)
|
|
64
|
+
try {
|
|
65
|
+
const { isJailBackend } = await import('../../execution-environment/process-isolation.js');
|
|
66
|
+
context?.recordOpsEvent?.({
|
|
67
|
+
event: 'ops.command.executed',
|
|
68
|
+
data: {
|
|
69
|
+
tool: 'allowlisted_run',
|
|
70
|
+
argv: [executable, ...args],
|
|
71
|
+
cwd,
|
|
72
|
+
exitCode: sandboxResult.exitCode,
|
|
73
|
+
durationMs: sandboxResult.usage.elapsedMs,
|
|
74
|
+
escalated: false,
|
|
75
|
+
// 子步执行的确认态由所属工具的效应闸门承担,本层无从得知——记 null(未知),
|
|
76
|
+
// 不用 false/true 冒充
|
|
77
|
+
confirmed: null,
|
|
78
|
+
confirmSource: 'not-gated-here',
|
|
79
|
+
jail: {
|
|
80
|
+
backend: sandboxResult.isolation.backend,
|
|
81
|
+
unconfined: context?.disableJail === true || !isJailBackend(sandboxResult.isolation.backend),
|
|
82
|
+
},
|
|
83
|
+
originAttributed: Boolean(context?.sessionId),
|
|
84
|
+
origin: {
|
|
85
|
+
sessionId: context?.sessionId,
|
|
86
|
+
agentId: context?.agentId,
|
|
87
|
+
runId: context?.runId ?? null,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// 审计回传失败不阻断业务结果(与下方 journal 同策略)
|
|
94
|
+
}
|
|
62
95
|
// Journal after-diff (same contract as shell tool §5.6)
|
|
63
96
|
try {
|
|
64
97
|
const sj = await import('../../execution-environment/shell-journal.js');
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* 通过工厂函数接收 AskUserCallback(闭包注入),与 UI 层解耦。
|
|
5
5
|
* 回调持有「等回答」的 Promise;Gateway/UI 提供答案后工具才返回。
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* 无超时(2026-10-26 拍板):需要用户确认的问题不能被时间自动跳过。
|
|
8
|
+
* 退出只有两路:会话中止(abortSignal)或 Gateway 取消(ASK_USER_CANCELLED 哨兵)。
|
|
9
|
+
* definition 不声明 timeoutMs,工具总线(runWithToolLimits)因此不设看门狗。
|
|
8
10
|
*/
|
|
9
11
|
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
10
12
|
/** askUser 回调上下文(绑定到具体会话) */
|
|
@@ -27,8 +29,5 @@ export declare const ASK_USER_CANCELLED = "__ask_user_cancelled__";
|
|
|
27
29
|
* 创建 ask_user 工具
|
|
28
30
|
*
|
|
29
31
|
* @param callback - 等待用户回答的回调(通常由 Gateway 挂 pending question)
|
|
30
|
-
* @param options.timeoutMs - 等待上限;超时返回错误而不是悬挂
|
|
31
32
|
*/
|
|
32
|
-
export declare function createAskUserTool(callback: AskUserCallback
|
|
33
|
-
timeoutMs?: number;
|
|
34
|
-
}): RegisteredTool;
|
|
33
|
+
export declare function createAskUserTool(callback: AskUserCallback): RegisteredTool;
|