@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
|
@@ -4,25 +4,23 @@
|
|
|
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
|
/** Gateway cancel 哨兵(与 gateway.ASK_USER_CANCELLED 同值,避免 harness→integration 依赖) */
|
|
10
12
|
export const ASK_USER_CANCELLED = '__ask_user_cancelled__';
|
|
11
|
-
/** 默认等待用户回答的上限(与 definition.timeoutMs 对齐) */
|
|
12
|
-
const DEFAULT_ASK_TIMEOUT_MS = 300_000;
|
|
13
13
|
/**
|
|
14
14
|
* 创建 ask_user 工具
|
|
15
15
|
*
|
|
16
16
|
* @param callback - 等待用户回答的回调(通常由 Gateway 挂 pending question)
|
|
17
|
-
* @param options.timeoutMs - 等待上限;超时返回错误而不是悬挂
|
|
18
17
|
*/
|
|
19
|
-
export function createAskUserTool(callback
|
|
20
|
-
const timeoutMs = options?.timeoutMs ?? DEFAULT_ASK_TIMEOUT_MS;
|
|
18
|
+
export function createAskUserTool(callback) {
|
|
21
19
|
return {
|
|
22
20
|
definition: {
|
|
23
21
|
name: 'ask_user',
|
|
24
22
|
capabilities: [],
|
|
25
|
-
description: 'Ask the user a question and wait for their response. Use when you need clarification, confirmation, or a choice from the user. Optionally provide a list of suggested options. Do not use for things you can look up yourself.',
|
|
23
|
+
description: 'Ask the user a question and wait for their response. Use when you need clarification, confirmation, or a choice from the user. Optionally provide a list of suggested options. Do not use for things you can look up yourself. There is no timeout — the question waits until the user answers, or the run is aborted.',
|
|
26
24
|
parameters: {
|
|
27
25
|
question: {
|
|
28
26
|
type: 'string',
|
|
@@ -35,7 +33,6 @@ export function createAskUserTool(callback, options) {
|
|
|
35
33
|
items: { type: 'string', description: 'An option' },
|
|
36
34
|
},
|
|
37
35
|
},
|
|
38
|
-
timeoutMs,
|
|
39
36
|
},
|
|
40
37
|
handler: async (args, context) => {
|
|
41
38
|
const question = String(args.question ?? '').trim();
|
|
@@ -54,11 +51,8 @@ export function createAskUserTool(callback, options) {
|
|
|
54
51
|
return { answer: null, error: 'aborted before asking user' };
|
|
55
52
|
}
|
|
56
53
|
const abortSignal = context?.abortSignal;
|
|
57
|
-
let timer;
|
|
58
54
|
const answer = await new Promise((resolve, reject) => {
|
|
59
55
|
const cleanup = () => {
|
|
60
|
-
if (timer !== undefined)
|
|
61
|
-
clearTimeout(timer);
|
|
62
56
|
abortSignal?.removeEventListener('abort', onAbort);
|
|
63
57
|
};
|
|
64
58
|
const onAbort = () => {
|
|
@@ -72,10 +66,6 @@ export function createAskUserTool(callback, options) {
|
|
|
72
66
|
return;
|
|
73
67
|
}
|
|
74
68
|
}
|
|
75
|
-
timer = setTimeout(() => {
|
|
76
|
-
cleanup();
|
|
77
|
-
reject(new Error(`ask_user timed out after ${timeoutMs}ms`));
|
|
78
|
-
}, timeoutMs);
|
|
79
69
|
callback(question, options, ctx).then((value) => {
|
|
80
70
|
cleanup();
|
|
81
71
|
resolve(value);
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* - file_search: 跨文件内容搜索
|
|
9
9
|
* - http_request: HTTP 请求
|
|
10
10
|
* - env_info: 运行环境信息
|
|
11
|
+
* - process_list: 只读进程诊断(进程表/资源/祖先链)
|
|
12
|
+
* - priv_exec: 白名单提权执行(ops P3,全等匹配 + 确认闸)
|
|
11
13
|
*
|
|
12
14
|
* 所有有状态工具(memory、task、ask_user)通过 extension-tools 按需注入。
|
|
13
15
|
*
|
|
@@ -32,6 +34,7 @@ import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
|
32
34
|
* - exitCode: 退出码
|
|
33
35
|
* - durationMs: 执行耗时
|
|
34
36
|
* - shell: 实际使用的 shell(kind/executable)
|
|
37
|
+
* - hints: 沙箱归因提示(仅当 jail 拒绝并已归因时出现,如 setuid exec)
|
|
35
38
|
*/
|
|
36
39
|
export declare function createShellTool(options?: {
|
|
37
40
|
summary?: import('../../../context/capabilities/summary/index.js').ToolSummarySupport;
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* - file_search: 跨文件内容搜索
|
|
9
9
|
* - http_request: HTTP 请求
|
|
10
10
|
* - env_info: 运行环境信息
|
|
11
|
+
* - process_list: 只读进程诊断(进程表/资源/祖先链)
|
|
12
|
+
* - priv_exec: 白名单提权执行(ops P3,全等匹配 + 确认闸)
|
|
11
13
|
*
|
|
12
14
|
* 所有有状态工具(memory、task、ask_user)通过 extension-tools 按需注入。
|
|
13
15
|
*
|
|
@@ -26,6 +28,8 @@ import { createGitTools } from './git-tools.js';
|
|
|
26
28
|
import { createPackageTools } from './package-tools.js';
|
|
27
29
|
import { createHttpRequestTool } from './http.js';
|
|
28
30
|
import { createEnvInfoTool } from './env-info.js';
|
|
31
|
+
import { createProcessListTool } from './process-tools.js';
|
|
32
|
+
import { createPrivExecTool } from './privileged-tool.js';
|
|
29
33
|
import { createDocumentProbeTool, createDocumentReadTool } from './document-tools.js';
|
|
30
34
|
import { isUnderSessionUndoRoot, defaultPathEnv, isPathUnderRoots, isUnderAttachmentRoot, resolvePlatformShell, resolveReadableToolPath, resolveToolPath, } from './platform.js';
|
|
31
35
|
/**
|
|
@@ -42,6 +46,7 @@ import { isUnderSessionUndoRoot, defaultPathEnv, isPathUnderRoots, isUnderAttach
|
|
|
42
46
|
* - exitCode: 退出码
|
|
43
47
|
* - durationMs: 执行耗时
|
|
44
48
|
* - shell: 实际使用的 shell(kind/executable)
|
|
49
|
+
* - hints: 沙箱归因提示(仅当 jail 拒绝并已归因时出现,如 setuid exec)
|
|
45
50
|
*/
|
|
46
51
|
export function createShellTool(options) {
|
|
47
52
|
const shell = resolvePlatformShell();
|
|
@@ -54,7 +59,7 @@ export function createShellTool(options) {
|
|
|
54
59
|
definition: {
|
|
55
60
|
name: 'shell',
|
|
56
61
|
capabilities: ['exec'],
|
|
57
|
-
description: `LAST RESORT shell. Prefer a dedicated tool when one covers the job (file_read/file_list/file_write/file_edit/file_delete/file_mkdir/file_rename/file_copy/file_stat/file_rmdir/file_search/env_info/git_status/git_diff/git_log/git_show/git_commit/git_branch/git_restore/package_edit/project_run/package_install and any task-specific tools). Use shell only when: no dedicated tool covers the operation, the dedicated tool is unavailable, or it still fails after a correct retry (wrong path/args → fix and retry the tool first). Never use shell instead of a working dedicated tool. Detected shell: ${shell.label}. ${syntaxHint}`,
|
|
62
|
+
description: `LAST RESORT shell. Prefer a dedicated tool when one covers the job (file_read/file_list/file_write/file_edit/file_delete/file_mkdir/file_rename/file_copy/file_stat/file_rmdir/file_search/env_info/process_list/git_status/git_diff/git_log/git_show/git_commit/git_branch/git_restore/package_edit/project_run/package_install and any task-specific tools). Use shell only when: no dedicated tool covers the operation, the dedicated tool is unavailable, or it still fails after a correct retry (wrong path/args → fix and retry the tool first). Never use shell instead of a working dedicated tool. Detected shell: ${shell.label}. ${syntaxHint}`,
|
|
58
63
|
parameters: {
|
|
59
64
|
command: {
|
|
60
65
|
type: 'string',
|
|
@@ -76,7 +81,7 @@ export function createShellTool(options) {
|
|
|
76
81
|
handler: async (args, context) => {
|
|
77
82
|
const command = args.command;
|
|
78
83
|
const cwd = args.cwd ?? context?.cwd ?? process.cwd();
|
|
79
|
-
await gateEffect({ kind: 'shell', command: args.command, cwd: typeof cwd === 'string' ? cwd : undefined }, {
|
|
84
|
+
const gateResult = await gateEffect({ kind: 'shell', command: args.command, cwd: typeof cwd === 'string' ? cwd : undefined }, {
|
|
80
85
|
effects: context?.effectChannel ?? 'engine',
|
|
81
86
|
confirmEffect: context?.confirmEffect,
|
|
82
87
|
shellEscape: context?.shellEscape,
|
|
@@ -122,6 +127,7 @@ export function createShellTool(options) {
|
|
|
122
127
|
allowRoots: [resolvedCwd, ...(context?.pathRoots ?? []).filter(Boolean)],
|
|
123
128
|
networkPolicy: context?.networkPolicy ?? 'deny',
|
|
124
129
|
requireJail: context?.requireJail,
|
|
130
|
+
disableJail: context?.disableJail,
|
|
125
131
|
homeWrite: context?.homeWrite,
|
|
126
132
|
noteSecurityDegraded: context?.noteSecurityDegraded,
|
|
127
133
|
signal: context?.abortSignal,
|
|
@@ -130,6 +136,43 @@ export function createShellTool(options) {
|
|
|
130
136
|
maxOutputBytes: 16 * 1024 * 1024,
|
|
131
137
|
},
|
|
132
138
|
});
|
|
139
|
+
// ops P2 §7:统一动作记录(argv/cwd/退出码/耗时/确认态/jail)——审计失败不阻断业务
|
|
140
|
+
try {
|
|
141
|
+
const { isJailBackend } = await import('../../execution-environment/process-isolation.js');
|
|
142
|
+
context?.recordOpsEvent?.({
|
|
143
|
+
event: 'ops.command.executed',
|
|
144
|
+
data: {
|
|
145
|
+
tool: 'shell',
|
|
146
|
+
argv: [resolvedShell.executable, ...resolvedShell.args, command],
|
|
147
|
+
cwd: resolvedCwd,
|
|
148
|
+
exitCode: sandboxResult.exitCode,
|
|
149
|
+
durationMs: sandboxResult.usage.elapsedMs,
|
|
150
|
+
escalated: false,
|
|
151
|
+
// 确认态取闸门实际放行结论(通道配置≠本次决策;自动放行如实记 false)
|
|
152
|
+
confirmed: gateResult.confirmed,
|
|
153
|
+
confirmSource: gateResult.confirmSource,
|
|
154
|
+
// ops P5:确认人归因(人工批准时随闸门回传;缓存命中/自动放行如实缺省)
|
|
155
|
+
...(gateResult.confirmedBy !== undefined ? { confirmedBy: gateResult.confirmedBy } : {}),
|
|
156
|
+
...(gateResult.confirmChannel !== undefined
|
|
157
|
+
? { confirmChannel: gateResult.confirmChannel }
|
|
158
|
+
: {}),
|
|
159
|
+
jail: {
|
|
160
|
+
backend: sandboxResult.isolation.backend,
|
|
161
|
+
unconfined: context?.disableJail === true || !isJailBackend(sandboxResult.isolation.backend),
|
|
162
|
+
},
|
|
163
|
+
// 注入源不明标记(§5 P2):工具调用带 session/run 归属 = 已归因
|
|
164
|
+
originAttributed: Boolean(context?.sessionId),
|
|
165
|
+
origin: {
|
|
166
|
+
sessionId: context?.sessionId,
|
|
167
|
+
agentId: context?.agentId,
|
|
168
|
+
runId: context?.runId ?? null,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// 审计回传失败不阻断 shell 业务结果(写失败的降级申报在 runner 侧)
|
|
175
|
+
}
|
|
133
176
|
try {
|
|
134
177
|
// §5.6:after diff 入账本 / 不可逆清单
|
|
135
178
|
try {
|
|
@@ -182,6 +225,9 @@ export function createShellTool(options) {
|
|
|
182
225
|
terminated: sandboxResult.terminated,
|
|
183
226
|
terminateReason: sandboxResult.terminateReason,
|
|
184
227
|
isolation: sandboxResult.isolation,
|
|
228
|
+
...(sandboxResult.diagnostics?.hints?.length
|
|
229
|
+
? { hints: sandboxResult.diagnostics.hints }
|
|
230
|
+
: {}),
|
|
185
231
|
shell: {
|
|
186
232
|
kind: resolvedShell.kind,
|
|
187
233
|
executable: resolvedShell.executable,
|
|
@@ -200,6 +246,9 @@ export function createShellTool(options) {
|
|
|
200
246
|
terminated: sandboxResult.terminated,
|
|
201
247
|
terminateReason: sandboxResult.terminateReason,
|
|
202
248
|
isolation: sandboxResult.isolation,
|
|
249
|
+
...(sandboxResult.diagnostics?.hints?.length
|
|
250
|
+
? { hints: sandboxResult.diagnostics.hints }
|
|
251
|
+
: {}),
|
|
203
252
|
shell: {
|
|
204
253
|
kind: resolvedShell.kind,
|
|
205
254
|
executable: resolvedShell.executable,
|
|
@@ -771,6 +820,8 @@ export function getBuiltinTools(options) {
|
|
|
771
820
|
requireBindings: options?.requireCredentialBindings,
|
|
772
821
|
}),
|
|
773
822
|
createEnvInfoTool(),
|
|
823
|
+
createProcessListTool(),
|
|
824
|
+
createPrivExecTool(),
|
|
774
825
|
createShellTool({ summary: options?.summary }),
|
|
775
826
|
];
|
|
776
827
|
}
|
|
@@ -10,6 +10,8 @@ export { createFileEditTool } from './file-edit.js';
|
|
|
10
10
|
export { createFileSearchTool } from './file-search.js';
|
|
11
11
|
export { createHttpRequestTool } from './http.js';
|
|
12
12
|
export { createEnvInfoTool } from './env-info.js';
|
|
13
|
+
export { createProcessListTool } from './process-tools.js';
|
|
14
|
+
export { createPrivExecTool } from './privileged-tool.js';
|
|
13
15
|
export { commandExists, defaultPathEnv, findExecutable, resetPlatformShellCache, resolvePlatformShell, resolveToolPath, type PlatformShell, type ShellKind, } from './platform.js';
|
|
14
16
|
export { createToolSet } from './tool-set.js';
|
|
15
17
|
export type { ToolSet, ToolSetConfig } from './tool-set.js';
|
|
@@ -8,6 +8,8 @@ export { createFileEditTool } from './file-edit.js';
|
|
|
8
8
|
export { createFileSearchTool } from './file-search.js';
|
|
9
9
|
export { createHttpRequestTool } from './http.js';
|
|
10
10
|
export { createEnvInfoTool } from './env-info.js';
|
|
11
|
+
export { createProcessListTool } from './process-tools.js';
|
|
12
|
+
export { createPrivExecTool } from './privileged-tool.js';
|
|
11
13
|
export { commandExists, defaultPathEnv, findExecutable, resetPlatformShellCache, resolvePlatformShell, resolveToolPath, } from './platform.js';
|
|
12
14
|
export { createToolSet } from './tool-set.js';
|
|
13
15
|
export { createAskUserTool } from './ask-user.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* priv_exec 工具 — 白名单提权执行(ops P3,§5 P3 / §8)
|
|
3
|
+
*
|
|
4
|
+
* 独立 privileged 通道:引擎侧 execFile 执行完整 argv,不经 shell、不包 jail、
|
|
5
|
+
* env 消毒、**cwd 钉住**(规则显式或 `/`,绝不取 agent 的 cwd)、超时真树杀。
|
|
6
|
+
* shell 工具保持原牢笼语义不动(原则 6:提权不与牢笼抢轴)。
|
|
7
|
+
*
|
|
8
|
+
* 安全闸门(全 fail-closed):
|
|
9
|
+
* 1. **匹配面**(effect-policy `matchEscalationRule`):`allowlist` 档 cmd 绝对路径 +
|
|
10
|
+
* args 逐项全等;`full` 档(P4,需 privilegedAck + jail=none + mode=host)无
|
|
11
|
+
* allowlist 面,但 `via: sudo` 仍必须显式 `sudo -n` 形态(裸跑 = 非特权通道假象)。
|
|
12
|
+
* 未命中/形态非法 → 拒绝 + `ops.escalation.denied` 留痕(不留痕的拒绝等于没拒)。
|
|
13
|
+
* 2. **确认闸门**:规则 `confirm: true`(allowlist)或 §6 危险分类命中(full 档)走
|
|
14
|
+
* HitlDecision 单模型(§8.2),缓存 key 含**完整 argv 全等**(§5 P3:防一次批准
|
|
15
|
+
* 放行整类);特权通道把 `approve_always` 降格为 `approve_session`。
|
|
16
|
+
* **确认超时一律 deny**(T1 硬约束,outcome 不可配)。
|
|
17
|
+
* 3. **请求者授权**(§8.6 拍板):由 SEC-2 `toolRights.deny('priv_exec')` 表达——
|
|
18
|
+
* 缺权参与者在 toolRights 层即拒,连确认闸都到不了。
|
|
19
|
+
* 4. **审计**(§7):`ops.escalation.requested` → `ops.privileged.exec` / `denied`。
|
|
20
|
+
*
|
|
21
|
+
* `full` 档的 §6 分类是**减速带不是安全边界**(只拦事故不拦攻击):未命中自动放行,
|
|
22
|
+
* 不做「未知即危险」;真正的边界是 privilegedAck + 常驻 PRIVILEGED 标记 + 审计。
|
|
23
|
+
*/
|
|
24
|
+
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
25
|
+
import { type HitlDecisionCache } from '../../../governance/human-in-the-loop/decision-cache.js';
|
|
26
|
+
/** 创建选项 */
|
|
27
|
+
export interface CreatePrivExecToolOptions {
|
|
28
|
+
/** HITL 决策缓存(缺省全局 defaultHitlCache;测试/宿主可注入独立实例) */
|
|
29
|
+
cache?: HitlDecisionCache;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 创建 priv_exec 工具
|
|
33
|
+
*
|
|
34
|
+
* 参数:
|
|
35
|
+
* - cmd (string, required):可执行文件**绝对路径**(与规则逐字相同)
|
|
36
|
+
* - args (string[], optional):argv 尾部(与规则逐项全等)
|
|
37
|
+
*
|
|
38
|
+
* 返回:ruleId / exitCode / stdout / stderr / durationMs / confirmDecision。
|
|
39
|
+
*
|
|
40
|
+
* @param options - 可注入 HITL 缓存
|
|
41
|
+
* @returns 注册好的提权工具
|
|
42
|
+
*/
|
|
43
|
+
export declare function createPrivExecTool(options?: CreatePrivExecToolOptions): RegisteredTool;
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* priv_exec 工具 — 白名单提权执行(ops P3,§5 P3 / §8)
|
|
3
|
+
*
|
|
4
|
+
* 独立 privileged 通道:引擎侧 execFile 执行完整 argv,不经 shell、不包 jail、
|
|
5
|
+
* env 消毒、**cwd 钉住**(规则显式或 `/`,绝不取 agent 的 cwd)、超时真树杀。
|
|
6
|
+
* shell 工具保持原牢笼语义不动(原则 6:提权不与牢笼抢轴)。
|
|
7
|
+
*
|
|
8
|
+
* 安全闸门(全 fail-closed):
|
|
9
|
+
* 1. **匹配面**(effect-policy `matchEscalationRule`):`allowlist` 档 cmd 绝对路径 +
|
|
10
|
+
* args 逐项全等;`full` 档(P4,需 privilegedAck + jail=none + mode=host)无
|
|
11
|
+
* allowlist 面,但 `via: sudo` 仍必须显式 `sudo -n` 形态(裸跑 = 非特权通道假象)。
|
|
12
|
+
* 未命中/形态非法 → 拒绝 + `ops.escalation.denied` 留痕(不留痕的拒绝等于没拒)。
|
|
13
|
+
* 2. **确认闸门**:规则 `confirm: true`(allowlist)或 §6 危险分类命中(full 档)走
|
|
14
|
+
* HitlDecision 单模型(§8.2),缓存 key 含**完整 argv 全等**(§5 P3:防一次批准
|
|
15
|
+
* 放行整类);特权通道把 `approve_always` 降格为 `approve_session`。
|
|
16
|
+
* **确认超时一律 deny**(T1 硬约束,outcome 不可配)。
|
|
17
|
+
* 3. **请求者授权**(§8.6 拍板):由 SEC-2 `toolRights.deny('priv_exec')` 表达——
|
|
18
|
+
* 缺权参与者在 toolRights 层即拒,连确认闸都到不了。
|
|
19
|
+
* 4. **审计**(§7):`ops.escalation.requested` → `ops.privileged.exec` / `denied`。
|
|
20
|
+
*
|
|
21
|
+
* `full` 档的 §6 分类是**减速带不是安全边界**(只拦事故不拦攻击):未命中自动放行,
|
|
22
|
+
* 不做「未知即危险」;真正的边界是 privilegedAck + 常驻 PRIVILEGED 标记 + 审计。
|
|
23
|
+
*/
|
|
24
|
+
import { isAbsolute } from 'node:path';
|
|
25
|
+
import { matchEscalationRule } from '../../execution-environment/effect-policy.js';
|
|
26
|
+
import { classifyDangerousArgv } from '../../execution-environment/dangerous-commands.js';
|
|
27
|
+
import { runPrivilegedExec, } from '../../execution-environment/privileged-exec.js';
|
|
28
|
+
import { resolveHitlOutcome, } from '../../../governance/human-in-the-loop/decision-cache.js';
|
|
29
|
+
/**
|
|
30
|
+
* 确认闸计时(T1 硬约束:超时 = 拒绝,outcome 不可配)。
|
|
31
|
+
* 超时后宿主再批也无效(decision 已按 deny 定案)——宁可重请求,不可放马后炮。
|
|
32
|
+
*
|
|
33
|
+
* @param ask - 宿主确认回调(可携带拒绝来源/归因标注)
|
|
34
|
+
* @param timeoutMs - 确认窗毫秒
|
|
35
|
+
* @param abortSignal - run 中止信号(中止即收闸,不再空等确认窗走完)
|
|
36
|
+
* @returns 决策 + 来源标注(审计 why: confirm_timeout / confirm_denied / channel_error / aborted 可分辨)
|
|
37
|
+
*/
|
|
38
|
+
async function askWithTimeout(ask, timeoutMs, abortSignal) {
|
|
39
|
+
let timer;
|
|
40
|
+
let onAbort;
|
|
41
|
+
const timeout = new Promise((res) => {
|
|
42
|
+
timer = setTimeout(() => res({ decision: 'deny', timedOut: true }), timeoutMs);
|
|
43
|
+
timer.unref?.();
|
|
44
|
+
});
|
|
45
|
+
const aborted = new Promise((res) => {
|
|
46
|
+
if (!abortSignal)
|
|
47
|
+
return;
|
|
48
|
+
onAbort = () => res({ decision: 'deny', denyReason: 'aborted' });
|
|
49
|
+
if (abortSignal.aborted)
|
|
50
|
+
onAbort();
|
|
51
|
+
else
|
|
52
|
+
abortSignal.addEventListener('abort', onAbort, { once: true });
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
return await Promise.race([
|
|
56
|
+
ask().then((result) => ({ ...result, timedOut: result.timedOut ?? false })),
|
|
57
|
+
timeout,
|
|
58
|
+
aborted,
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (timer)
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
if (onAbort)
|
|
65
|
+
abortSignal?.removeEventListener('abort', onAbort);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 创建 priv_exec 工具
|
|
70
|
+
*
|
|
71
|
+
* 参数:
|
|
72
|
+
* - cmd (string, required):可执行文件**绝对路径**(与规则逐字相同)
|
|
73
|
+
* - args (string[], optional):argv 尾部(与规则逐项全等)
|
|
74
|
+
*
|
|
75
|
+
* 返回:ruleId / exitCode / stdout / stderr / durationMs / confirmDecision。
|
|
76
|
+
*
|
|
77
|
+
* @param options - 可注入 HITL 缓存
|
|
78
|
+
* @returns 注册好的提权工具
|
|
79
|
+
*/
|
|
80
|
+
export function createPrivExecTool(options) {
|
|
81
|
+
return {
|
|
82
|
+
definition: {
|
|
83
|
+
name: 'priv_exec',
|
|
84
|
+
// exec 标签:reduced 工具面(untrusted 降级)剥掉提权通道(降能力不降墙)
|
|
85
|
+
capabilities: ['exec'],
|
|
86
|
+
description: 'Execute a privileged command through the engine-side privileged channel. ' +
|
|
87
|
+
'Under effectPolicy.escalation.policy=allowlist the argv must match an allow rule exactly (absolute cmd + identical args); ' +
|
|
88
|
+
'under policy=full any absolute argv is accepted (via:sudo must spell `sudo -n <target…>`). ' +
|
|
89
|
+
'Runs without a shell or jail; env scrubbed; cwd pinned by the rule (default /); timeout + tree-kill. ' +
|
|
90
|
+
'Refused argv is audited (ops.escalation.denied). Rules with confirm:true — and any argv hitting the ' +
|
|
91
|
+
'dangerous-command table under full — pass a HITL gate keyed on the full argv; confirm timeout is deny. ' +
|
|
92
|
+
'This is the only privilege-escalation channel.',
|
|
93
|
+
parameters: {
|
|
94
|
+
cmd: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
required: true,
|
|
97
|
+
description: 'Absolute path of the executable, exactly as configured in the allow rule',
|
|
98
|
+
},
|
|
99
|
+
args: {
|
|
100
|
+
type: 'array',
|
|
101
|
+
items: { type: 'string', description: 'argument' },
|
|
102
|
+
description: 'Arguments after cmd — must match the rule element-by-element (no prefix/regex matching)',
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
// 不设工具总线看门狗(同 ask_user 先例):真实时限全部内部强制——确认窗
|
|
106
|
+
// (dangerousCommands.timeoutMs,超时=拒绝)+ 执行超时(runPrivilegedExec 120s
|
|
107
|
+
// 树杀)。总线看门狗曾把 escalation_confirm_timeout 顶成 tool_timeout(错误语义
|
|
108
|
+
// 失真、诱导盲重试),且其阈值必须随配置漂移才成立——两处都错,故整块去掉。
|
|
109
|
+
},
|
|
110
|
+
handler: async (args, context) => {
|
|
111
|
+
const cmd = args.cmd;
|
|
112
|
+
const rawArgs = args.args;
|
|
113
|
+
const origin = {
|
|
114
|
+
sessionId: context?.sessionId,
|
|
115
|
+
agentId: context?.agentId,
|
|
116
|
+
runId: context?.runId ?? null,
|
|
117
|
+
// ops P5「参与者身份入账」:请求者是谁(SEC-2 角色绑定)——确认 ≠ 请求者可信
|
|
118
|
+
participants: context?.sessionParticipants ?? [],
|
|
119
|
+
};
|
|
120
|
+
// 参数形态非法也必须留痕(拒了没记 = 盲区)
|
|
121
|
+
const invalid = (() => {
|
|
122
|
+
if (typeof cmd !== 'string' || cmd === '')
|
|
123
|
+
return 'cmd must be a non-empty string';
|
|
124
|
+
if (rawArgs !== undefined && (!Array.isArray(rawArgs) || rawArgs.some((a) => typeof a !== 'string'))) {
|
|
125
|
+
return 'args must be an array of strings';
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
})();
|
|
129
|
+
if (invalid) {
|
|
130
|
+
context?.recordOpsEvent?.({
|
|
131
|
+
event: 'ops.escalation.denied',
|
|
132
|
+
data: { argv: [String(cmd), ...(Array.isArray(rawArgs) ? rawArgs.map(String) : [])], why: 'invalid_args', origin },
|
|
133
|
+
});
|
|
134
|
+
throw new Error(`priv_exec: ${invalid}`);
|
|
135
|
+
}
|
|
136
|
+
const argvTail = rawArgs ?? [];
|
|
137
|
+
// invalid 守卫已保证 cmd 为非空 string(TS 无法穿透闭包收窄,String() 为恒等转换)
|
|
138
|
+
const cmdStr = String(cmd);
|
|
139
|
+
const argv = [cmdStr, ...argvTail];
|
|
140
|
+
const escalation = context?.escalation;
|
|
141
|
+
if (!escalation || escalation.policy === 'none') {
|
|
142
|
+
context?.recordOpsEvent?.({
|
|
143
|
+
event: 'ops.escalation.denied',
|
|
144
|
+
data: { argv, why: 'policy_none', origin },
|
|
145
|
+
});
|
|
146
|
+
throw new Error('priv_exec disabled: effectPolicy.escalation.policy=none (enable allowlist/full to use priv_exec)');
|
|
147
|
+
}
|
|
148
|
+
// 匹配面:allowlist = cmd+args 全等;full(P4)= 全量档,仅校验形态(绝对路径 + sudo 显式形态)
|
|
149
|
+
let ruleId;
|
|
150
|
+
let ruleConfirm = false;
|
|
151
|
+
let ruleCwd;
|
|
152
|
+
if (escalation.policy === 'full') {
|
|
153
|
+
if (!isAbsolute(cmdStr)) {
|
|
154
|
+
context?.recordOpsEvent?.({
|
|
155
|
+
event: 'ops.escalation.denied',
|
|
156
|
+
data: { argv, why: 'invalid_args', origin },
|
|
157
|
+
});
|
|
158
|
+
throw new Error('priv_exec: cmd must be an absolute path (PATH resolution = replaceable binary)');
|
|
159
|
+
}
|
|
160
|
+
if (escalation.via === 'sudo') {
|
|
161
|
+
// full 档仍必须显式 `sudo -n <target…>` 形态:裸跑 = 非特权通道假象(与 allowlist 形态规则同构)
|
|
162
|
+
const base = cmdStr.replace(/\\/g, '/').split('/').pop()?.toLowerCase() ?? '';
|
|
163
|
+
const spellsSudo = base === 'sudo' || base === 'doas';
|
|
164
|
+
if (!spellsSudo || argvTail[0] !== '-n') {
|
|
165
|
+
context?.recordOpsEvent?.({
|
|
166
|
+
event: 'ops.escalation.denied',
|
|
167
|
+
data: { argv, why: 'invalid_args', origin },
|
|
168
|
+
});
|
|
169
|
+
throw new Error('priv_exec: full policy via=sudo must spell `sudo -n <target…>` explicitly (cmd = /usr/bin/sudo, args[0] = "-n")');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
ruleId = 'full';
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const match = matchEscalationRule(escalation, cmdStr, argvTail);
|
|
176
|
+
if (!match) {
|
|
177
|
+
// 未命中即拒绝并留痕:拒绝必须可查(§7),否则注入探测就成了盲区
|
|
178
|
+
context?.recordOpsEvent?.({
|
|
179
|
+
event: 'ops.escalation.denied',
|
|
180
|
+
data: { argv, why: 'not_allowlisted', origin },
|
|
181
|
+
});
|
|
182
|
+
throw new Error('escalation_not_allowlisted: no allow rule matches this argv exactly (cmd absolute path + args element-by-element)');
|
|
183
|
+
}
|
|
184
|
+
ruleId = match.ruleId;
|
|
185
|
+
ruleConfirm = match.rule.confirm === true;
|
|
186
|
+
ruleCwd = match.rule.cwd;
|
|
187
|
+
}
|
|
188
|
+
// §6 危险分类(full 档 pre-exec 闸):命中走确认/deny,未命中放行(不做「未知即危险」)。
|
|
189
|
+
// allowlist 档由规则 confirm 显式表态,不叠加分类——规则作者已逐条裁决。
|
|
190
|
+
let dangerousPattern;
|
|
191
|
+
let needsConfirm = ruleConfirm;
|
|
192
|
+
if (escalation.policy === 'full') {
|
|
193
|
+
const verdict = classifyDangerousArgv(argv);
|
|
194
|
+
if (verdict.dangerous) {
|
|
195
|
+
dangerousPattern = verdict.pattern;
|
|
196
|
+
const gatePolicy = context?.dangerousCommands?.policy ?? 'confirm';
|
|
197
|
+
if (gatePolicy === 'deny') {
|
|
198
|
+
context?.recordOpsEvent?.({
|
|
199
|
+
event: 'ops.escalation.denied',
|
|
200
|
+
data: { ruleId, argv, why: 'dangerous_denied', dangerous: dangerousPattern, origin },
|
|
201
|
+
});
|
|
202
|
+
throw new Error(`escalation_dangerous_denied: ${JSON.stringify(argv)} hit \`${dangerousPattern}\` (dangerousCommands.policy=deny)`);
|
|
203
|
+
}
|
|
204
|
+
if (gatePolicy === 'confirm')
|
|
205
|
+
needsConfirm = true;
|
|
206
|
+
// 'off':分类关闭——命中仍入审计(留痕不设闸),但不拦
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
context?.recordOpsEvent?.({
|
|
210
|
+
event: 'ops.escalation.requested',
|
|
211
|
+
data: {
|
|
212
|
+
ruleId,
|
|
213
|
+
argv,
|
|
214
|
+
via: escalation.via,
|
|
215
|
+
decision: 'pending',
|
|
216
|
+
requester: origin,
|
|
217
|
+
...(dangerousPattern !== undefined ? { dangerous: dangerousPattern } : {}),
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
let confirmDecision = 'auto';
|
|
221
|
+
// P5 确认人入账:谁批的、经哪条通道(宿主归因;未知如实缺省,不编造)
|
|
222
|
+
let confirmedBy;
|
|
223
|
+
let confirmChannel;
|
|
224
|
+
if (needsConfirm) {
|
|
225
|
+
// 确认超时一律 deny(T1 硬约束,outcome 不可配);超时/人工拒绝/通道故障在审计里可分辨
|
|
226
|
+
const confirmTimeoutMs = context?.dangerousCommands?.timeoutMs ?? 120_000;
|
|
227
|
+
const outcome = await resolveHitlOutcome({
|
|
228
|
+
// 缓存 key 含完整 argv 全等(§5 P3):一次 approve_session 只覆盖这一条命令
|
|
229
|
+
key: `priv:${JSON.stringify(argv)}`,
|
|
230
|
+
channel: 'effect',
|
|
231
|
+
// session/always 缓存需要归属(缺归属 = 退化 one-shot)
|
|
232
|
+
sessionId: context?.sessionId,
|
|
233
|
+
agentId: context?.agentId,
|
|
234
|
+
cache: options?.cache,
|
|
235
|
+
ask: () => askWithTimeout(async () => {
|
|
236
|
+
const confirmEffect = context?.confirmEffect;
|
|
237
|
+
// 无确认通道 ≠ 人工拒绝:如实标注来源,fail-closed
|
|
238
|
+
if (!confirmEffect) {
|
|
239
|
+
return {
|
|
240
|
+
decision: 'deny',
|
|
241
|
+
denyReason: 'no_channel',
|
|
242
|
+
denyDetail: 'confirmEffect hook absent',
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const raw = await confirmEffect({
|
|
246
|
+
kind: 'shell',
|
|
247
|
+
// 无歧义渲染:argv 数组的 JSON 形式(join(' ') 无法区分 args 边界与换行注入)
|
|
248
|
+
command: JSON.stringify(argv),
|
|
249
|
+
cwd: ruleCwd ?? '/',
|
|
250
|
+
// 宿主卡片生命周期据此排在确认窗之后(严格晚 settle,防误标 confirm_denied)
|
|
251
|
+
timeoutMs: confirmTimeoutMs,
|
|
252
|
+
});
|
|
253
|
+
// 裸 HitlDecision 或 ConfirmOutcome(带归因/来源)都合法
|
|
254
|
+
const normalized = typeof raw === 'string' ? { decision: raw } : raw;
|
|
255
|
+
// 特权通道保守语义:approve_always 永久放行特权 argv 过宽 → 降格 session 级
|
|
256
|
+
const decision = normalized.decision === 'approve_always' ? 'approve_session' : normalized.decision;
|
|
257
|
+
return {
|
|
258
|
+
decision,
|
|
259
|
+
...(normalized.approver !== undefined ? { approver: normalized.approver } : {}),
|
|
260
|
+
...(normalized.channel !== undefined ? { channel: normalized.channel } : {}),
|
|
261
|
+
// 宿主标注的拒绝来源:timeout 归超时语义;其余(如 no_session_scope)
|
|
262
|
+
// 归通道故障——任何非人工来源都不得冒充人工拒绝
|
|
263
|
+
...(decision === 'deny' && normalized.reason === 'timeout'
|
|
264
|
+
? { timedOut: true }
|
|
265
|
+
: {}),
|
|
266
|
+
...(decision === 'deny' &&
|
|
267
|
+
normalized.reason !== undefined &&
|
|
268
|
+
normalized.reason !== 'timeout'
|
|
269
|
+
? { denyReason: 'channel_error', denyDetail: normalized.reason }
|
|
270
|
+
: {}),
|
|
271
|
+
};
|
|
272
|
+
}, confirmTimeoutMs, context?.abortSignal),
|
|
273
|
+
});
|
|
274
|
+
if (outcome.approver !== undefined)
|
|
275
|
+
confirmedBy = outcome.approver;
|
|
276
|
+
if (outcome.channel !== undefined)
|
|
277
|
+
confirmChannel = outcome.channel;
|
|
278
|
+
if (!outcome.allowed) {
|
|
279
|
+
const why = outcome.timedOut
|
|
280
|
+
? 'confirm_timeout'
|
|
281
|
+
: outcome.denyReason === 'aborted' || outcome.denyReason === 'cancelled'
|
|
282
|
+
? 'aborted'
|
|
283
|
+
: outcome.denyReason !== undefined
|
|
284
|
+
? 'channel_error'
|
|
285
|
+
: 'confirm_denied';
|
|
286
|
+
context?.recordOpsEvent?.({
|
|
287
|
+
event: 'ops.escalation.denied',
|
|
288
|
+
data: {
|
|
289
|
+
ruleId,
|
|
290
|
+
argv,
|
|
291
|
+
why,
|
|
292
|
+
...(outcome.denyDetail !== undefined ? { reason: outcome.denyDetail } : {}),
|
|
293
|
+
...(dangerousPattern !== undefined ? { dangerous: dangerousPattern } : {}),
|
|
294
|
+
origin,
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
const argvText = JSON.stringify(argv);
|
|
298
|
+
throw new Error(outcome.timedOut
|
|
299
|
+
? `escalation_confirm_timeout: no decision within ${confirmTimeoutMs}ms — timeout is deny (not configurable). A human approval request is still pending on the confirm channel; do NOT retry this call until a human decides: ${argvText}`
|
|
300
|
+
: why === 'aborted'
|
|
301
|
+
? `priv_exec_aborted: run aborted while awaiting confirmation — nothing was executed: ${argvText}`
|
|
302
|
+
: why === 'channel_error'
|
|
303
|
+
? `escalation_confirm_unavailable: confirm channel unavailable (${outcome.denyReason}${outcome.denyDetail ? `: ${outcome.denyDetail}` : ''}) — fail-closed deny, no human decision was reached: ${argvText}`
|
|
304
|
+
: `escalation_confirm_denied: a human rejected this argv — do NOT retry this call on your own: ${argvText}`);
|
|
305
|
+
}
|
|
306
|
+
confirmDecision = 'approved';
|
|
307
|
+
}
|
|
308
|
+
const result = await runPrivilegedExec({
|
|
309
|
+
cmd: cmdStr,
|
|
310
|
+
args: argvTail,
|
|
311
|
+
via: escalation.via,
|
|
312
|
+
// cwd 钉住:规则显式或 `/`——agent 的 cwd 无权决定特权进程在哪解析相对路径
|
|
313
|
+
cwd: ruleCwd ?? '/',
|
|
314
|
+
timeoutMs: 120_000,
|
|
315
|
+
// run 中止即时树杀(不等执行超时兜底)
|
|
316
|
+
abortSignal: context?.abortSignal,
|
|
317
|
+
});
|
|
318
|
+
context?.recordOpsEvent?.({
|
|
319
|
+
event: 'ops.privileged.exec',
|
|
320
|
+
data: {
|
|
321
|
+
ruleId,
|
|
322
|
+
argv,
|
|
323
|
+
via: escalation.via,
|
|
324
|
+
confirmDecision,
|
|
325
|
+
executed: result.executed,
|
|
326
|
+
exitCode: result.exitCode,
|
|
327
|
+
durationMs: result.durationMs,
|
|
328
|
+
timedOut: result.timedOut,
|
|
329
|
+
...(dangerousPattern !== undefined ? { dangerous: dangerousPattern } : {}),
|
|
330
|
+
...(confirmedBy !== undefined ? { confirmedBy } : {}),
|
|
331
|
+
...(confirmChannel !== undefined ? { confirmChannel } : {}),
|
|
332
|
+
origin,
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
if (!result.executed) {
|
|
336
|
+
// 「未执行」≠「执行失败」:spawn 都没起来,业务结果不冒充执行
|
|
337
|
+
throw new Error(`priv_exec_spawn_failed: ${result.stderr}`);
|
|
338
|
+
}
|
|
339
|
+
return {
|
|
340
|
+
ruleId,
|
|
341
|
+
exitCode: result.exitCode,
|
|
342
|
+
stdout: result.stdout,
|
|
343
|
+
stderr: result.stderr,
|
|
344
|
+
durationMs: result.durationMs,
|
|
345
|
+
timedOut: result.timedOut,
|
|
346
|
+
confirmDecision,
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* process_list 工具 — 只读进程诊断(ops P1)
|
|
3
|
+
*
|
|
4
|
+
* 引擎侧枚举(procfs / ps / powershell),不经 shell 工具:
|
|
5
|
+
* macOS 牢笼拒 exec setuid 的 `ps`,Linux 牢笼在新 pidns 里看不到宿主进程,
|
|
6
|
+
* 「看进程」只能由牢笼外的引擎进程自己做。零权限放松——不杀进程、不改状态。
|
|
7
|
+
*
|
|
8
|
+
* 能力标签为 `host-read`(宿主内省,超出 workspace 信息面):
|
|
9
|
+
* reduced 工具面(untrusted 降级)**剥掉**本工具——argv 是凭证泄漏面
|
|
10
|
+
* (`--token=…`、内联脚本),且引擎侧数据源会绕过牢笼「看不到宿主进程」的边界。
|
|
11
|
+
*/
|
|
12
|
+
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
13
|
+
/**
|
|
14
|
+
* 创建 process_list 工具
|
|
15
|
+
*
|
|
16
|
+
* 参数:
|
|
17
|
+
* - pid (number, optional): 查单个 pid —— 返回该进程条目 + 祖先链(远祖在前,自身为链尾)+ 可执行映像;不可与其余参数同用
|
|
18
|
+
* - pids (number[], optional): 只列出这些 pid
|
|
19
|
+
* - nameContains (string, optional): 命令行子串过滤(大小写不敏感)
|
|
20
|
+
* - sort ('rss' | 'pid', optional): 排序键,缺省 'rss' 降序(重的在前)
|
|
21
|
+
* - limit (number, optional): 返回上限,缺省 200;截断时 `truncated` 为 true
|
|
22
|
+
*
|
|
23
|
+
* 返回:进程条目(pid/ppid/command/rssBytes/cpuTimeMs/threads)+ matched/total/truncated
|
|
24
|
+
* + source + complete + notes。complete=false 表示来源降级/不全(如牢笼内 ps 被拒、
|
|
25
|
+
* 表行被跳过),此时进程表不可当作「机器上只有这些」。
|
|
26
|
+
* pid 模式另有 chainComplete:祖先链是否每一环都解析到了(与 complete 相互独立)。
|
|
27
|
+
*
|
|
28
|
+
* @returns 注册好的只读工具
|
|
29
|
+
*/
|
|
30
|
+
export declare function createProcessListTool(): RegisteredTool;
|