@librechat/agents 3.1.77-dev.1 → 3.1.78-dev.0
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/cjs/common/enum.cjs +54 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +148 -4
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +291 -0
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -0
- package/dist/cjs/llm/openai/index.cjs +317 -1
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +90 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/anthropicToolCache.cjs +102 -0
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -0
- package/dist/cjs/messages/prune.cjs +27 -0
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +99 -0
- package/dist/cjs/messages/recency.cjs.map +1 -0
- package/dist/cjs/run.cjs +30 -0
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +100 -6
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +635 -23
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +227 -0
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -0
- package/dist/cjs/tools/local/FileCheckpointer.cjs +90 -0
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalCodingTools.cjs +1098 -0
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +1042 -0
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalExecutionTools.cjs +122 -0
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +453 -0
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/local/attachments.cjs +183 -0
- package/dist/cjs/tools/local/attachments.cjs.map +1 -0
- package/dist/cjs/tools/local/bashAst.cjs +129 -0
- package/dist/cjs/tools/local/bashAst.cjs.map +1 -0
- package/dist/cjs/tools/local/editStrategies.cjs +188 -0
- package/dist/cjs/tools/local/editStrategies.cjs.map +1 -0
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +141 -0
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -0
- package/dist/cjs/tools/local/syntaxCheck.cjs +182 -0
- package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -0
- package/dist/cjs/tools/local/textEncoding.cjs +30 -0
- package/dist/cjs/tools/local/textEncoding.cjs.map +1 -0
- package/dist/cjs/tools/local/workspaceFS.cjs +51 -0
- package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +1 -0
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/esm/common/enum.mjs +53 -1
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +149 -5
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +289 -0
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -0
- package/dist/esm/llm/openai/index.mjs +318 -2
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +17 -2
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/anthropicToolCache.mjs +99 -0
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -0
- package/dist/esm/messages/prune.mjs +26 -1
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +97 -0
- package/dist/esm/messages/recency.mjs.map +1 -0
- package/dist/esm/run.mjs +30 -0
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +100 -6
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +635 -23
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +223 -0
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -0
- package/dist/esm/tools/local/FileCheckpointer.mjs +87 -0
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -0
- package/dist/esm/tools/local/LocalCodingTools.mjs +1075 -0
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -0
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +1022 -0
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -0
- package/dist/esm/tools/local/LocalExecutionTools.mjs +117 -0
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +448 -0
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/local/attachments.mjs +180 -0
- package/dist/esm/tools/local/attachments.mjs.map +1 -0
- package/dist/esm/tools/local/bashAst.mjs +126 -0
- package/dist/esm/tools/local/bashAst.mjs.map +1 -0
- package/dist/esm/tools/local/editStrategies.mjs +185 -0
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -0
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +137 -0
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -0
- package/dist/esm/tools/local/syntaxCheck.mjs +179 -0
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -0
- package/dist/esm/tools/local/textEncoding.mjs +27 -0
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -0
- package/dist/esm/tools/local/workspaceFS.mjs +49 -0
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +1 -0
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/types/common/enum.d.ts +39 -1
- package/dist/types/graphs/Graph.d.ts +34 -0
- package/dist/types/hooks/createWorkspacePolicyHook.d.ts +95 -0
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/llm/openai/index.d.ts +17 -0
- package/dist/types/messages/anthropicToolCache.d.ts +51 -0
- package/dist/types/messages/index.d.ts +2 -0
- package/dist/types/messages/prune.d.ts +11 -0
- package/dist/types/messages/recency.d.ts +64 -0
- package/dist/types/run.d.ts +21 -0
- package/dist/types/tools/ToolNode.d.ts +145 -2
- package/dist/types/tools/local/CompileCheckTool.d.ts +31 -0
- package/dist/types/tools/local/FileCheckpointer.d.ts +39 -0
- package/dist/types/tools/local/LocalCodingTools.d.ts +57 -0
- package/dist/types/tools/local/LocalExecutionEngine.d.ts +149 -0
- package/dist/types/tools/local/LocalExecutionTools.d.ts +9 -0
- package/dist/types/tools/local/LocalProgrammaticToolCalling.d.ts +21 -0
- package/dist/types/tools/local/attachments.d.ts +84 -0
- package/dist/types/tools/local/bashAst.d.ts +11 -0
- package/dist/types/tools/local/editStrategies.d.ts +28 -0
- package/dist/types/tools/local/index.d.ts +12 -0
- package/dist/types/tools/local/resolveLocalExecutionTools.d.ts +38 -0
- package/dist/types/tools/local/syntaxCheck.d.ts +42 -0
- package/dist/types/tools/local/textEncoding.d.ts +21 -0
- package/dist/types/tools/local/workspaceFS.d.ts +49 -0
- package/dist/types/types/hitl.d.ts +56 -27
- package/dist/types/types/run.d.ts +8 -1
- package/dist/types/types/summarize.d.ts +30 -0
- package/dist/types/types/tools.d.ts +341 -6
- package/package.json +21 -2
- package/src/common/enum.ts +54 -0
- package/src/graphs/Graph.ts +164 -6
- package/src/hooks/__tests__/compactHooks.test.ts +38 -2
- package/src/hooks/__tests__/createWorkspacePolicyHook.test.ts +393 -0
- package/src/hooks/createWorkspacePolicyHook.ts +355 -0
- package/src/hooks/index.ts +6 -0
- package/src/index.ts +1 -0
- package/src/llm/openai/deepseek.test.ts +479 -0
- package/src/llm/openai/index.ts +484 -1
- package/src/messages/__tests__/anthropicToolCache.test.ts +125 -0
- package/src/messages/__tests__/recency.test.ts +267 -0
- package/src/messages/anthropicToolCache.ts +116 -0
- package/src/messages/index.ts +2 -0
- package/src/messages/prune.ts +27 -1
- package/src/messages/recency.ts +155 -0
- package/src/run.ts +31 -0
- package/src/scripts/compare_pi_vs_ours.ts +840 -0
- package/src/scripts/local_engine.ts +166 -0
- package/src/scripts/local_engine_checkpointer.ts +205 -0
- package/src/scripts/local_engine_compile.ts +263 -0
- package/src/scripts/local_engine_hooks.ts +226 -0
- package/src/scripts/local_engine_image.ts +201 -0
- package/src/scripts/local_engine_ptc.ts +151 -0
- package/src/scripts/local_engine_workspace.ts +258 -0
- package/src/scripts/summarization-recency.ts +462 -0
- package/src/specs/prune.test.ts +39 -0
- package/src/summarization/__tests__/node.test.ts +499 -3
- package/src/summarization/node.ts +124 -7
- package/src/tools/ToolNode.ts +769 -20
- package/src/tools/__tests__/LocalExecutionTools.test.ts +2647 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +175 -0
- package/src/tools/__tests__/ToolNode.outputReferences.test.ts +114 -0
- package/src/tools/__tests__/ToolNode.session.test.ts +84 -0
- package/src/tools/__tests__/directToolHITLResumeScope.test.ts +467 -0
- package/src/tools/__tests__/directToolHooks.test.ts +411 -0
- package/src/tools/__tests__/localToolNames.test.ts +73 -0
- package/src/tools/__tests__/workspaceSeam.test.ts +134 -0
- package/src/tools/local/CompileCheckTool.ts +278 -0
- package/src/tools/local/FileCheckpointer.ts +93 -0
- package/src/tools/local/LocalCodingTools.ts +1342 -0
- package/src/tools/local/LocalExecutionEngine.ts +1329 -0
- package/src/tools/local/LocalExecutionTools.ts +167 -0
- package/src/tools/local/LocalProgrammaticToolCalling.ts +594 -0
- package/src/tools/local/__tests__/FileCheckpointer.test.ts +120 -0
- package/src/tools/local/__tests__/editStrategies.test.ts +134 -0
- package/src/tools/local/attachments.ts +251 -0
- package/src/tools/local/bashAst.ts +151 -0
- package/src/tools/local/editStrategies.ts +188 -0
- package/src/tools/local/index.ts +12 -0
- package/src/tools/local/resolveLocalExecutionTools.ts +208 -0
- package/src/tools/local/syntaxCheck.ts +243 -0
- package/src/tools/local/textEncoding.ts +37 -0
- package/src/tools/local/workspaceFS.ts +89 -0
- package/src/types/hitl.ts +56 -27
- package/src/types/run.ts +12 -1
- package/src/types/summarize.ts +31 -0
- package/src/types/tools.ts +359 -7
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { homedir } from 'os';
|
|
2
|
+
import { resolve, isAbsolute, relative } from 'path';
|
|
3
|
+
import { realpath } from 'fs/promises';
|
|
4
|
+
import { Constants } from '../common/enum.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Workspace boundary policy as a `PreToolUse` hook.
|
|
8
|
+
*
|
|
9
|
+
* Local-engine file tools enforce a hard workspace boundary at the
|
|
10
|
+
* tool implementation layer (`resolveWorkspacePathSafe`). This hook
|
|
11
|
+
* adds a complementary, host-controlled layer on top that uses the
|
|
12
|
+
* standard PreToolUse / HITL machinery to *negotiate* access to
|
|
13
|
+
* paths outside the workspace — instead of just throwing.
|
|
14
|
+
*
|
|
15
|
+
* The host opts in by registering this hook on a `HookRegistry`; the
|
|
16
|
+
* hook inspects each tool call's input, extracts the file paths it
|
|
17
|
+
* mentions via per-tool extractors, and returns:
|
|
18
|
+
*
|
|
19
|
+
* - `allow` — every path is inside `workspace.root`
|
|
20
|
+
* (or `additionalRoots`)
|
|
21
|
+
* - `deny` — at least one path is outside, and the
|
|
22
|
+
* configured outside-policy is `'deny'`
|
|
23
|
+
* - `ask` — at least one path is outside, and the
|
|
24
|
+
* outside-policy is `'ask'` (default).
|
|
25
|
+
* When `humanInTheLoop.enabled` is true,
|
|
26
|
+
* the existing PreToolUse `'ask'` flow
|
|
27
|
+
* raises a tool_approval interrupt the
|
|
28
|
+
* host UI can render. When HITL is off,
|
|
29
|
+
* `'ask'` collapses to `deny` (matches
|
|
30
|
+
* the rest of the SDK's default).
|
|
31
|
+
*
|
|
32
|
+
* Default per-tool path extractors cover the local-engine coding
|
|
33
|
+
* suite (`read_file`, `write_file`, `edit_file`, `grep_search`,
|
|
34
|
+
* `glob_search`, `list_directory`, `compile_check`). The host can
|
|
35
|
+
* override or extend via `pathExtractors`. Bash/code paths are not
|
|
36
|
+
* extracted by default — bash command parsing is its own concern, and
|
|
37
|
+
* the existing `bashAst` validator + sandbox-runtime fs allowlist are
|
|
38
|
+
* the right gates for those.
|
|
39
|
+
*
|
|
40
|
+
* Important: this hook does NOT replace `resolveWorkspacePathSafe`.
|
|
41
|
+
* Even if the hook returns `allow`, the file tool still enforces its
|
|
42
|
+
* own clamp unless `workspace.allowReadOutside` /
|
|
43
|
+
* `workspace.allowWriteOutside` (or the legacy
|
|
44
|
+
* `allowOutsideWorkspace`) is set. The recommended composition for
|
|
45
|
+
* "ask the user" semantics is:
|
|
46
|
+
*
|
|
47
|
+
* workspace: {
|
|
48
|
+
* root,
|
|
49
|
+
* allowReadOutside: true,
|
|
50
|
+
* allowWriteOutside: true,
|
|
51
|
+
* },
|
|
52
|
+
* // …with the hook installed and humanInTheLoop.enabled = true.
|
|
53
|
+
*/
|
|
54
|
+
const READ_TOOLS = new Set([
|
|
55
|
+
Constants.READ_FILE,
|
|
56
|
+
Constants.GREP_SEARCH,
|
|
57
|
+
Constants.GLOB_SEARCH,
|
|
58
|
+
Constants.LIST_DIRECTORY,
|
|
59
|
+
Constants.COMPILE_CHECK,
|
|
60
|
+
]);
|
|
61
|
+
const WRITE_TOOLS = new Set([
|
|
62
|
+
Constants.WRITE_FILE,
|
|
63
|
+
Constants.EDIT_FILE,
|
|
64
|
+
]);
|
|
65
|
+
/**
|
|
66
|
+
* Best-effort extractor for `compile_check` — pulls absolute and `~/`
|
|
67
|
+
* path tokens out of the `command` string so the workspace boundary
|
|
68
|
+
* sees them. Without this, a model could ship `command: 'cat
|
|
69
|
+
* /etc/passwd'` and the policy hook would short-circuit to `allow`
|
|
70
|
+
* (Codex P1 #26 — the prior `() => []` made the hook a no-op for
|
|
71
|
+
* compile_check). Conservative by design:
|
|
72
|
+
*
|
|
73
|
+
* - Matches `/foo`, `~/foo`, `$HOME/foo`, `${HOME}/foo` followed by
|
|
74
|
+
* non-shell-special chars. Stops at whitespace, quotes, redirect
|
|
75
|
+
* operators, pipes, semicolons.
|
|
76
|
+
* - Strips a leading `--flag=` so `--out=/etc/foo` extracts as
|
|
77
|
+
* `/etc/foo` (the path the agent's actually trying to write).
|
|
78
|
+
* - Misses relative paths (intended — those resolve under cwd
|
|
79
|
+
* anyway), and shell-substituted paths whose final form isn't
|
|
80
|
+
* visible at extract time. Hosts that need bulletproof gating
|
|
81
|
+
* should pair this with a `bash_tool`-level policy.
|
|
82
|
+
*/
|
|
83
|
+
// `["']?` slots before AND after the captured path cover quoted
|
|
84
|
+
// forms like `cat "/etc/passwd"` and `--out='/tmp/x'`. Codex P1 #31
|
|
85
|
+
// — the previous regex only matched unquoted tokens, so a model
|
|
86
|
+
// could trivially bypass the workspace policy by quoting any
|
|
87
|
+
// destination path. The path content character class still excludes
|
|
88
|
+
// quotes/whitespace/shell-specials so we don't over-extract; that's
|
|
89
|
+
// the defensive trade we want for fallback-grep style matching.
|
|
90
|
+
//
|
|
91
|
+
// The `\.\.(?:\/[^…]*)?` alternation covers parent-traversal forms
|
|
92
|
+
// (`..`, `../secrets.txt`, `../foo/bar`). Without it, a model could
|
|
93
|
+
// exfiltrate parent-directory files via `cat ../secrets` and the
|
|
94
|
+
// hook would short-circuit to `allow` because the extractor saw no
|
|
95
|
+
// "absolute" token. The boundary check at the call site resolves
|
|
96
|
+
// non-absolute extracted tokens against `root`, so `../secrets`
|
|
97
|
+
// becomes `<parent-of-workspace>/secrets` which the boundary then
|
|
98
|
+
// correctly flags as outside. Codex P2 #35.
|
|
99
|
+
const PATH_TOKEN = /(?:^|[\s=])(?:--[^\s=]+=)?["']?(\/[^\s'"|;&<>()`]+|~\/[^\s'"|;&<>()`]+|\$\{?HOME\}?\/[^\s'"|;&<>()`]+|\.\.(?:\/[^\s'"|;&<>()`]*)?)["']?/g;
|
|
100
|
+
// Back-compat alias kept for any downstream import.
|
|
101
|
+
const ABSOLUTE_PATH_TOKEN = PATH_TOKEN;
|
|
102
|
+
function expandHomeRelative(token) {
|
|
103
|
+
// Expand ~/foo and $HOME/foo and ${HOME}/foo to absolute. The
|
|
104
|
+
// workspace boundary check resolves non-absolute paths against the
|
|
105
|
+
// workspace root, which would silently treat `~/secret` as
|
|
106
|
+
// `<workspace>/~/secret` — exactly the bypass the codex flagged.
|
|
107
|
+
const home = homedir();
|
|
108
|
+
if (token.startsWith('~/'))
|
|
109
|
+
return `${home}/${token.slice(2)}`;
|
|
110
|
+
if (token.startsWith('${HOME}/'))
|
|
111
|
+
return `${home}/${token.slice(8)}`;
|
|
112
|
+
if (token.startsWith('$HOME/'))
|
|
113
|
+
return `${home}/${token.slice(6)}`;
|
|
114
|
+
return token;
|
|
115
|
+
}
|
|
116
|
+
function extractCompileCheckPaths(input) {
|
|
117
|
+
const command = typeof input.command === 'string' ? input.command : '';
|
|
118
|
+
if (command === '')
|
|
119
|
+
return [];
|
|
120
|
+
const out = [];
|
|
121
|
+
for (const match of command.matchAll(ABSOLUTE_PATH_TOKEN)) {
|
|
122
|
+
out.push(expandHomeRelative(match[1]));
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
const DEFAULT_EXTRACTORS = {
|
|
127
|
+
[Constants.READ_FILE]: (i) => typeof i.file_path === 'string' ? [i.file_path] : [],
|
|
128
|
+
[Constants.WRITE_FILE]: (i) => typeof i.file_path === 'string' ? [i.file_path] : [],
|
|
129
|
+
[Constants.EDIT_FILE]: (i) => typeof i.file_path === 'string' ? [i.file_path] : [],
|
|
130
|
+
[Constants.GREP_SEARCH]: (i) => typeof i.path === 'string' && i.path !== '' ? [i.path] : [],
|
|
131
|
+
[Constants.GLOB_SEARCH]: (i) => typeof i.path === 'string' && i.path !== '' ? [i.path] : [],
|
|
132
|
+
[Constants.LIST_DIRECTORY]: (i) => typeof i.path === 'string' && i.path !== '' ? [i.path] : [],
|
|
133
|
+
[Constants.COMPILE_CHECK]: extractCompileCheckPaths,
|
|
134
|
+
};
|
|
135
|
+
function isInsideAnyRoot(absolutePath, roots) {
|
|
136
|
+
for (const root of roots) {
|
|
137
|
+
if (absolutePath === root)
|
|
138
|
+
return true;
|
|
139
|
+
const rel = relative(root, absolutePath);
|
|
140
|
+
if (!rel.startsWith('..') && !isAbsolute(rel))
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Symlink-aware variant: realpaths the candidate AND the roots before
|
|
147
|
+
* comparing. Without this, a symlink inside the workspace pointing
|
|
148
|
+
* outside (e.g. `workspace/link → /etc/passwd`) compares as
|
|
149
|
+
* "in-workspace" lexically, but actually grants the agent reach
|
|
150
|
+
* outside the boundary. Critical when this hook is the primary gate
|
|
151
|
+
* (i.e. the host opted into `workspace.allowReadOutside: true` /
|
|
152
|
+
* `allowWriteOutside: true` so the file tools' own clamp is off).
|
|
153
|
+
*
|
|
154
|
+
* Handles paths that don't yet exist (e.g. `write_file` to a brand
|
|
155
|
+
* new path) by walking up to the nearest existing ancestor and
|
|
156
|
+
* realpathing that, then re-attaching the unresolved suffix. Mirrors
|
|
157
|
+
* `resolveWorkspacePathSafe`'s approach in LocalExecutionEngine.
|
|
158
|
+
*/
|
|
159
|
+
async function realpathOrSelf(absolutePath) {
|
|
160
|
+
try {
|
|
161
|
+
return await realpath(absolutePath);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return absolutePath;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async function realpathOfPathOrAncestor(absolutePath) {
|
|
168
|
+
let current = absolutePath;
|
|
169
|
+
let suffix = '';
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
171
|
+
while (true) {
|
|
172
|
+
try {
|
|
173
|
+
const real = await realpath(current);
|
|
174
|
+
return suffix === '' ? real : resolve(real, suffix);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
const parent = resolve(current, '..');
|
|
178
|
+
if (parent === current) {
|
|
179
|
+
return absolutePath;
|
|
180
|
+
}
|
|
181
|
+
const base = current.slice(parent.length + 1);
|
|
182
|
+
suffix = suffix === '' ? base : `${base}/${suffix}`;
|
|
183
|
+
current = parent;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function isInsideAnyRootRealpath(absolutePath, realRoots) {
|
|
188
|
+
const real = await realpathOfPathOrAncestor(absolutePath);
|
|
189
|
+
return isInsideAnyRoot(real, [...realRoots]);
|
|
190
|
+
}
|
|
191
|
+
function formatReason(template, toolName, outsidePaths) {
|
|
192
|
+
const fallback = `Tool "${toolName}" wants to touch ${outsidePaths.length} path(s) outside the workspace: ${outsidePaths.join(', ')}`;
|
|
193
|
+
if (template == null)
|
|
194
|
+
return fallback;
|
|
195
|
+
return template
|
|
196
|
+
.replace(/\{tool\}/g, toolName)
|
|
197
|
+
.replace(/\{paths\}/g, outsidePaths.join(', '));
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Build a `PreToolUse` callback that enforces the workspace policy.
|
|
201
|
+
* Register it on a `HookRegistry`:
|
|
202
|
+
*
|
|
203
|
+
* ```ts
|
|
204
|
+
* registry.register('PreToolUse', {
|
|
205
|
+
* hooks: [createWorkspacePolicyHook({ root, outsideWrite: 'ask' })],
|
|
206
|
+
* });
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* The hook is composable with `createToolPolicyHook` — register both;
|
|
210
|
+
* `executeHooks` precedence (`deny > ask > allow`) sorts out which
|
|
211
|
+
* decision wins per call.
|
|
212
|
+
*/
|
|
213
|
+
function createWorkspacePolicyHook(config) {
|
|
214
|
+
const root = resolve(config.root);
|
|
215
|
+
// Relative `additionalRoots` entries are anchored to `root` so a
|
|
216
|
+
// monorepo config like `additionalRoots: ['../shared']` resolves
|
|
217
|
+
// to a sibling of `root`, not of process.cwd. Matches
|
|
218
|
+
// `getWorkspaceRoots` in LocalExecutionEngine.
|
|
219
|
+
const additionalRoots = (config.additionalRoots ?? []).map((p) => isAbsolute(p) ? resolve(p) : resolve(root, p));
|
|
220
|
+
const allRoots = [root, ...additionalRoots];
|
|
221
|
+
// Pre-realpath the roots once at construction — these are stable
|
|
222
|
+
// per Run. The candidate paths get realpath'd lazily inside the
|
|
223
|
+
// hook callback. Cached so the per-call cost is just one realpath.
|
|
224
|
+
let realRootsPromise;
|
|
225
|
+
const getRealRoots = () => {
|
|
226
|
+
if (realRootsPromise == null) {
|
|
227
|
+
realRootsPromise = Promise.all(allRoots.map(realpathOrSelf));
|
|
228
|
+
}
|
|
229
|
+
return realRootsPromise;
|
|
230
|
+
};
|
|
231
|
+
const readPolicy = config.outsideRead ?? 'ask';
|
|
232
|
+
const writePolicy = config.outsideWrite ?? 'ask';
|
|
233
|
+
const extractors = {
|
|
234
|
+
...DEFAULT_EXTRACTORS,
|
|
235
|
+
...(config.pathExtractors ?? {}),
|
|
236
|
+
};
|
|
237
|
+
return async (input) => {
|
|
238
|
+
const extractor = extractors[input.toolName];
|
|
239
|
+
if (extractor == null)
|
|
240
|
+
return { decision: 'allow' };
|
|
241
|
+
const paths = extractor((input.toolInput ?? {}));
|
|
242
|
+
if (paths.length === 0)
|
|
243
|
+
return { decision: 'allow' };
|
|
244
|
+
// Two-stage check:
|
|
245
|
+
// 1. Lexical fast path — anything that's lexically inside the
|
|
246
|
+
// workspace AND doesn't get redirected by realpath stays
|
|
247
|
+
// allow-able without paying the realpath cost on every call.
|
|
248
|
+
// 2. For paths that look outside lexically OR look inside but
|
|
249
|
+
// may have been routed through a symlink, realpath both the
|
|
250
|
+
// candidate and the roots and compare. This catches the
|
|
251
|
+
// `workspace/link → /etc/passwd` escape that lexical-only
|
|
252
|
+
// checks miss.
|
|
253
|
+
const outside = [];
|
|
254
|
+
const realRoots = await getRealRoots();
|
|
255
|
+
for (const p of paths) {
|
|
256
|
+
const abs = isAbsolute(p) ? resolve(p) : resolve(root, p);
|
|
257
|
+
// Realpath is the source of truth — it catches both the
|
|
258
|
+
// symlink-escape case (lexically-inside path that resolves
|
|
259
|
+
// outside) and the alternate-mount case (lexically-outside
|
|
260
|
+
// path that resolves back inside the workspace). The lexical
|
|
261
|
+
// check alone gives the wrong answer for either, so we don't
|
|
262
|
+
// bother computing it.
|
|
263
|
+
const realInside = await isInsideAnyRootRealpath(abs, realRoots);
|
|
264
|
+
if (!realInside) {
|
|
265
|
+
outside.push(p);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (outside.length === 0)
|
|
269
|
+
return { decision: 'allow' };
|
|
270
|
+
const policy = WRITE_TOOLS.has(input.toolName)
|
|
271
|
+
? writePolicy
|
|
272
|
+
: READ_TOOLS.has(input.toolName)
|
|
273
|
+
? readPolicy
|
|
274
|
+
: writePolicy; // unknown tools — treat as write (stricter)
|
|
275
|
+
if (policy === 'allow')
|
|
276
|
+
return { decision: 'allow' };
|
|
277
|
+
const decision = policy === 'deny' ? 'deny' : 'ask';
|
|
278
|
+
return {
|
|
279
|
+
decision,
|
|
280
|
+
reason: formatReason(config.reason, input.toolName, outside),
|
|
281
|
+
...(decision === 'ask'
|
|
282
|
+
? { allowedDecisions: ['approve', 'reject'] }
|
|
283
|
+
: {}),
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { createWorkspacePolicyHook };
|
|
289
|
+
//# sourceMappingURL=createWorkspacePolicyHook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWorkspacePolicyHook.mjs","sources":["../../../src/hooks/createWorkspacePolicyHook.ts"],"sourcesContent":["/**\n * Workspace boundary policy as a `PreToolUse` hook.\n *\n * Local-engine file tools enforce a hard workspace boundary at the\n * tool implementation layer (`resolveWorkspacePathSafe`). This hook\n * adds a complementary, host-controlled layer on top that uses the\n * standard PreToolUse / HITL machinery to *negotiate* access to\n * paths outside the workspace — instead of just throwing.\n *\n * The host opts in by registering this hook on a `HookRegistry`; the\n * hook inspects each tool call's input, extracts the file paths it\n * mentions via per-tool extractors, and returns:\n *\n * - `allow` — every path is inside `workspace.root`\n * (or `additionalRoots`)\n * - `deny` — at least one path is outside, and the\n * configured outside-policy is `'deny'`\n * - `ask` — at least one path is outside, and the\n * outside-policy is `'ask'` (default).\n * When `humanInTheLoop.enabled` is true,\n * the existing PreToolUse `'ask'` flow\n * raises a tool_approval interrupt the\n * host UI can render. When HITL is off,\n * `'ask'` collapses to `deny` (matches\n * the rest of the SDK's default).\n *\n * Default per-tool path extractors cover the local-engine coding\n * suite (`read_file`, `write_file`, `edit_file`, `grep_search`,\n * `glob_search`, `list_directory`, `compile_check`). The host can\n * override or extend via `pathExtractors`. Bash/code paths are not\n * extracted by default — bash command parsing is its own concern, and\n * the existing `bashAst` validator + sandbox-runtime fs allowlist are\n * the right gates for those.\n *\n * Important: this hook does NOT replace `resolveWorkspacePathSafe`.\n * Even if the hook returns `allow`, the file tool still enforces its\n * own clamp unless `workspace.allowReadOutside` /\n * `workspace.allowWriteOutside` (or the legacy\n * `allowOutsideWorkspace`) is set. The recommended composition for\n * \"ask the user\" semantics is:\n *\n * workspace: {\n * root,\n * allowReadOutside: true,\n * allowWriteOutside: true,\n * },\n * // …with the hook installed and humanInTheLoop.enabled = true.\n */\n\nimport { homedir } from 'os';\nimport { isAbsolute, relative, resolve } from 'path';\nimport { realpath } from 'fs/promises';\nimport { Constants } from '@/common';\nimport type {\n HookCallback,\n PreToolUseHookInput,\n PreToolUseHookOutput,\n ToolDecision,\n} from './types';\n\n/**\n * What to do when a tool call references a path outside the workspace.\n *\n * - `'ask'` : default. Raise a PreToolUse `ask` (host UI prompts\n * via the HITL interrupt path).\n * - `'allow'` : let the call through (use the existing tool clamp\n * to actually enforce — the hook is purely advisory).\n * - `'deny'` : block the call with an error ToolMessage.\n */\nexport type OutsideAccessPolicy = 'ask' | 'allow' | 'deny';\n\nexport interface WorkspacePolicyConfig {\n /** Canonical workspace root. Required. */\n root: string;\n /** Sibling roots that count as inside-workspace. */\n additionalRoots?: readonly string[];\n /** Policy applied to read-only file tools. Defaults to `'ask'`. */\n outsideRead?: OutsideAccessPolicy;\n /** Policy applied to write-shaped file tools. Defaults to `'ask'`. */\n outsideWrite?: OutsideAccessPolicy;\n /**\n * Optional reason template surfaced in the `ask`/`deny` decision.\n * Supports `{tool}` and `{paths}` substitution.\n */\n reason?: string;\n /**\n * Per-tool path extractors. Defaults cover the local-engine coding\n * suite. Returning an empty array opts that tool out of policy.\n */\n pathExtractors?: Record<string, PathExtractor>;\n}\n\nexport type PathExtractor = (\n toolInput: Record<string, unknown>\n) => readonly string[];\n\nconst READ_TOOLS = new Set<string>([\n Constants.READ_FILE,\n Constants.GREP_SEARCH,\n Constants.GLOB_SEARCH,\n Constants.LIST_DIRECTORY,\n Constants.COMPILE_CHECK,\n]);\n\nconst WRITE_TOOLS = new Set<string>([\n Constants.WRITE_FILE,\n Constants.EDIT_FILE,\n]);\n\n/**\n * Best-effort extractor for `compile_check` — pulls absolute and `~/`\n * path tokens out of the `command` string so the workspace boundary\n * sees them. Without this, a model could ship `command: 'cat\n * /etc/passwd'` and the policy hook would short-circuit to `allow`\n * (Codex P1 #26 — the prior `() => []` made the hook a no-op for\n * compile_check). Conservative by design:\n *\n * - Matches `/foo`, `~/foo`, `$HOME/foo`, `${HOME}/foo` followed by\n * non-shell-special chars. Stops at whitespace, quotes, redirect\n * operators, pipes, semicolons.\n * - Strips a leading `--flag=` so `--out=/etc/foo` extracts as\n * `/etc/foo` (the path the agent's actually trying to write).\n * - Misses relative paths (intended — those resolve under cwd\n * anyway), and shell-substituted paths whose final form isn't\n * visible at extract time. Hosts that need bulletproof gating\n * should pair this with a `bash_tool`-level policy.\n */\n// `[\"']?` slots before AND after the captured path cover quoted\n// forms like `cat \"/etc/passwd\"` and `--out='/tmp/x'`. Codex P1 #31\n// — the previous regex only matched unquoted tokens, so a model\n// could trivially bypass the workspace policy by quoting any\n// destination path. The path content character class still excludes\n// quotes/whitespace/shell-specials so we don't over-extract; that's\n// the defensive trade we want for fallback-grep style matching.\n//\n// The `\\.\\.(?:\\/[^…]*)?` alternation covers parent-traversal forms\n// (`..`, `../secrets.txt`, `../foo/bar`). Without it, a model could\n// exfiltrate parent-directory files via `cat ../secrets` and the\n// hook would short-circuit to `allow` because the extractor saw no\n// \"absolute\" token. The boundary check at the call site resolves\n// non-absolute extracted tokens against `root`, so `../secrets`\n// becomes `<parent-of-workspace>/secrets` which the boundary then\n// correctly flags as outside. Codex P2 #35.\nconst PATH_TOKEN =\n /(?:^|[\\s=])(?:--[^\\s=]+=)?[\"']?(\\/[^\\s'\"|;&<>()`]+|~\\/[^\\s'\"|;&<>()`]+|\\$\\{?HOME\\}?\\/[^\\s'\"|;&<>()`]+|\\.\\.(?:\\/[^\\s'\"|;&<>()`]*)?)[\"']?/g;\n// Back-compat alias kept for any downstream import.\nconst ABSOLUTE_PATH_TOKEN = PATH_TOKEN;\nfunction expandHomeRelative(token: string): string {\n // Expand ~/foo and $HOME/foo and ${HOME}/foo to absolute. The\n // workspace boundary check resolves non-absolute paths against the\n // workspace root, which would silently treat `~/secret` as\n // `<workspace>/~/secret` — exactly the bypass the codex flagged.\n const home = homedir();\n if (token.startsWith('~/')) return `${home}/${token.slice(2)}`;\n if (token.startsWith('${HOME}/')) return `${home}/${token.slice(8)}`;\n if (token.startsWith('$HOME/')) return `${home}/${token.slice(6)}`;\n return token;\n}\nfunction extractCompileCheckPaths(input: Record<string, unknown>): string[] {\n const command = typeof input.command === 'string' ? input.command : '';\n if (command === '') return [];\n const out: string[] = [];\n for (const match of command.matchAll(ABSOLUTE_PATH_TOKEN)) {\n out.push(expandHomeRelative(match[1]));\n }\n return out;\n}\n\nconst DEFAULT_EXTRACTORS: Record<string, PathExtractor> = {\n [Constants.READ_FILE]: (i) =>\n typeof i.file_path === 'string' ? [i.file_path] : [],\n [Constants.WRITE_FILE]: (i) =>\n typeof i.file_path === 'string' ? [i.file_path] : [],\n [Constants.EDIT_FILE]: (i) =>\n typeof i.file_path === 'string' ? [i.file_path] : [],\n [Constants.GREP_SEARCH]: (i) =>\n typeof i.path === 'string' && i.path !== '' ? [i.path] : [],\n [Constants.GLOB_SEARCH]: (i) =>\n typeof i.path === 'string' && i.path !== '' ? [i.path] : [],\n [Constants.LIST_DIRECTORY]: (i) =>\n typeof i.path === 'string' && i.path !== '' ? [i.path] : [],\n [Constants.COMPILE_CHECK]: extractCompileCheckPaths,\n};\n\nfunction isInsideAnyRoot(absolutePath: string, roots: string[]): boolean {\n for (const root of roots) {\n if (absolutePath === root) return true;\n const rel = relative(root, absolutePath);\n if (!rel.startsWith('..') && !isAbsolute(rel)) return true;\n }\n return false;\n}\n\n/**\n * Symlink-aware variant: realpaths the candidate AND the roots before\n * comparing. Without this, a symlink inside the workspace pointing\n * outside (e.g. `workspace/link → /etc/passwd`) compares as\n * \"in-workspace\" lexically, but actually grants the agent reach\n * outside the boundary. Critical when this hook is the primary gate\n * (i.e. the host opted into `workspace.allowReadOutside: true` /\n * `allowWriteOutside: true` so the file tools' own clamp is off).\n *\n * Handles paths that don't yet exist (e.g. `write_file` to a brand\n * new path) by walking up to the nearest existing ancestor and\n * realpathing that, then re-attaching the unresolved suffix. Mirrors\n * `resolveWorkspacePathSafe`'s approach in LocalExecutionEngine.\n */\nasync function realpathOrSelf(absolutePath: string): Promise<string> {\n try {\n return await realpath(absolutePath);\n } catch {\n return absolutePath;\n }\n}\n\nasync function realpathOfPathOrAncestor(\n absolutePath: string\n): Promise<string> {\n let current = absolutePath;\n let suffix = '';\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n while (true) {\n try {\n const real = await realpath(current);\n return suffix === '' ? real : resolve(real, suffix);\n } catch {\n const parent = resolve(current, '..');\n if (parent === current) {\n return absolutePath;\n }\n const base = current.slice(parent.length + 1);\n suffix = suffix === '' ? base : `${base}/${suffix}`;\n current = parent;\n }\n }\n}\n\nasync function isInsideAnyRootRealpath(\n absolutePath: string,\n realRoots: readonly string[]\n): Promise<boolean> {\n const real = await realpathOfPathOrAncestor(absolutePath);\n return isInsideAnyRoot(real, [...realRoots]);\n}\n\nfunction formatReason(\n template: string | undefined,\n toolName: string,\n outsidePaths: readonly string[]\n): string {\n const fallback = `Tool \"${toolName}\" wants to touch ${outsidePaths.length} path(s) outside the workspace: ${outsidePaths.join(', ')}`;\n if (template == null) return fallback;\n return template\n .replace(/\\{tool\\}/g, toolName)\n .replace(/\\{paths\\}/g, outsidePaths.join(', '));\n}\n\n/**\n * Build a `PreToolUse` callback that enforces the workspace policy.\n * Register it on a `HookRegistry`:\n *\n * ```ts\n * registry.register('PreToolUse', {\n * hooks: [createWorkspacePolicyHook({ root, outsideWrite: 'ask' })],\n * });\n * ```\n *\n * The hook is composable with `createToolPolicyHook` — register both;\n * `executeHooks` precedence (`deny > ask > allow`) sorts out which\n * decision wins per call.\n */\nexport function createWorkspacePolicyHook(\n config: WorkspacePolicyConfig\n): HookCallback<'PreToolUse'> {\n const root = resolve(config.root);\n // Relative `additionalRoots` entries are anchored to `root` so a\n // monorepo config like `additionalRoots: ['../shared']` resolves\n // to a sibling of `root`, not of process.cwd. Matches\n // `getWorkspaceRoots` in LocalExecutionEngine.\n const additionalRoots = (config.additionalRoots ?? []).map((p) =>\n isAbsolute(p) ? resolve(p) : resolve(root, p)\n );\n const allRoots = [root, ...additionalRoots];\n\n // Pre-realpath the roots once at construction — these are stable\n // per Run. The candidate paths get realpath'd lazily inside the\n // hook callback. Cached so the per-call cost is just one realpath.\n let realRootsPromise: Promise<string[]> | undefined;\n const getRealRoots = (): Promise<string[]> => {\n if (realRootsPromise == null) {\n realRootsPromise = Promise.all(allRoots.map(realpathOrSelf));\n }\n return realRootsPromise;\n };\n\n const readPolicy: OutsideAccessPolicy = config.outsideRead ?? 'ask';\n const writePolicy: OutsideAccessPolicy = config.outsideWrite ?? 'ask';\n\n const extractors: Record<string, PathExtractor> = {\n ...DEFAULT_EXTRACTORS,\n ...(config.pathExtractors ?? {}),\n };\n\n return async (input: PreToolUseHookInput): Promise<PreToolUseHookOutput> => {\n const extractor = extractors[input.toolName];\n if (extractor == null) return { decision: 'allow' };\n\n const paths = extractor(\n (input.toolInput ?? {}) as Record<string, unknown>\n );\n if (paths.length === 0) return { decision: 'allow' };\n\n // Two-stage check:\n // 1. Lexical fast path — anything that's lexically inside the\n // workspace AND doesn't get redirected by realpath stays\n // allow-able without paying the realpath cost on every call.\n // 2. For paths that look outside lexically OR look inside but\n // may have been routed through a symlink, realpath both the\n // candidate and the roots and compare. This catches the\n // `workspace/link → /etc/passwd` escape that lexical-only\n // checks miss.\n const outside: string[] = [];\n const realRoots = await getRealRoots();\n for (const p of paths) {\n const abs = isAbsolute(p) ? resolve(p) : resolve(root, p);\n // Realpath is the source of truth — it catches both the\n // symlink-escape case (lexically-inside path that resolves\n // outside) and the alternate-mount case (lexically-outside\n // path that resolves back inside the workspace). The lexical\n // check alone gives the wrong answer for either, so we don't\n // bother computing it.\n const realInside = await isInsideAnyRootRealpath(abs, realRoots);\n if (!realInside) {\n outside.push(p);\n }\n }\n if (outside.length === 0) return { decision: 'allow' };\n\n const policy = WRITE_TOOLS.has(input.toolName)\n ? writePolicy\n : READ_TOOLS.has(input.toolName)\n ? readPolicy\n : writePolicy; // unknown tools — treat as write (stricter)\n if (policy === 'allow') return { decision: 'allow' };\n\n const decision: ToolDecision = policy === 'deny' ? 'deny' : 'ask';\n return {\n decision,\n reason: formatReason(config.reason, input.toolName, outside),\n ...(decision === 'ask'\n ? { allowedDecisions: ['approve', 'reject'] as const }\n : {}),\n };\n };\n}\n"],"names":[],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