@gaunt-sloth/agent 2.0.0-alpha.2 → 2.0.0-alpha.21
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/README.md +10 -0
- package/dist/builtInToolsConfig.d.ts +17 -3
- package/dist/builtInToolsConfig.js +41 -14
- package/dist/builtInToolsConfig.js.map +1 -1
- package/dist/core/GthDeepAgent.d.ts +63 -13
- package/dist/core/GthDeepAgent.js +360 -130
- package/dist/core/GthDeepAgent.js.map +1 -1
- package/dist/core/debugCapture.d.ts +8 -49
- package/dist/core/debugCapture.js +1 -1
- package/dist/core/debugCapture.js.map +1 -1
- package/dist/core/deepAgentPermissions.d.ts +73 -13
- package/dist/core/deepAgentPermissions.js +191 -29
- package/dist/core/deepAgentPermissions.js.map +1 -1
- package/dist/core/gthAcpServer.js +11 -0
- package/dist/core/gthAcpServer.js.map +1 -1
- package/dist/core/gthDeepAgentFactory.d.ts +3 -0
- package/dist/core/gthDeepAgentFactory.js +9 -1
- package/dist/core/gthDeepAgentFactory.js.map +1 -1
- package/dist/core/resolveAgentFactory.d.ts +14 -0
- package/dist/core/resolveAgentFactory.js +18 -0
- package/dist/core/resolveAgentFactory.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/OAuthClientProviderImpl.js +2 -2
- package/dist/mcp/OAuthClientProviderImpl.js.map +1 -1
- package/dist/mcp/tlsTrust.d.ts +61 -0
- package/dist/mcp/tlsTrust.js +109 -0
- package/dist/mcp/tlsTrust.js.map +1 -0
- package/dist/middleware/registry.d.ts +1 -1
- package/dist/middleware/registry.js +1 -1
- package/dist/middleware/types.d.ts +1 -1
- package/dist/middleware/types.js +1 -1
- package/dist/modules/a2a/A2AClientWrapper.d.ts +46 -0
- package/dist/modules/a2a/A2AClientWrapper.js +71 -0
- package/dist/modules/a2a/A2AClientWrapper.js.map +1 -1
- package/dist/modules/acpModule.d.ts +5 -2
- package/dist/modules/acpModule.js +13 -2
- package/dist/modules/acpModule.js.map +1 -1
- package/dist/modules/apiAgUiModule.js +48 -16
- package/dist/modules/apiAgUiModule.js.map +1 -1
- package/dist/modules/interactiveSessionModule.js +140 -7
- package/dist/modules/interactiveSessionModule.js.map +1 -1
- package/dist/resolvers.js +104 -9
- package/dist/resolvers.js.map +1 -1
- package/dist/tools/GthCustomToolkit.js +24 -9
- package/dist/tools/GthCustomToolkit.js.map +1 -1
- package/dist/tools/GthDevToolkit.d.ts +45 -1
- package/dist/tools/GthDevToolkit.js +229 -31
- package/dist/tools/GthDevToolkit.js.map +1 -1
- package/dist/tools/GthFileSystemToolkit.d.ts +47 -0
- package/dist/tools/GthFileSystemToolkit.js +305 -18
- package/dist/tools/GthFileSystemToolkit.js.map +1 -1
- package/dist/tools/gthChecklistTool.d.ts +30 -0
- package/dist/tools/gthChecklistTool.js +81 -0
- package/dist/tools/gthChecklistTool.js.map +1 -0
- package/dist/tools/gthGrepTool.d.ts +54 -0
- package/dist/tools/gthGrepTool.js +482 -0
- package/dist/tools/gthGrepTool.js.map +1 -0
- package/dist/tools/shell/allowlist.d.ts +11 -0
- package/dist/tools/shell/allowlist.js +12 -0
- package/dist/tools/shell/allowlist.js.map +1 -0
- package/dist/tools/shell/arity.d.ts +11 -0
- package/dist/tools/shell/arity.js +12 -0
- package/dist/tools/shell/arity.js.map +1 -0
- package/dist/tools/shell/env.d.ts +22 -0
- package/dist/tools/shell/env.js +110 -0
- package/dist/tools/shell/env.js.map +1 -0
- package/dist/tools/shell/hardline.d.ts +15 -0
- package/dist/tools/shell/hardline.js +88 -0
- package/dist/tools/shell/hardline.js.map +1 -0
- package/dist/tools/shell/normalize.d.ts +10 -0
- package/dist/tools/shell/normalize.js +11 -0
- package/dist/tools/shell/normalize.js.map +1 -0
- package/dist/tools/shell/outputBuffer.d.ts +53 -0
- package/dist/tools/shell/outputBuffer.js +157 -0
- package/dist/tools/shell/outputBuffer.js.map +1 -0
- package/dist/tools/shell/workDir.d.ts +11 -0
- package/dist/tools/shell/workDir.js +45 -0
- package/dist/tools/shell/workDir.js.map +1 -0
- package/dist/utils/mcpAuthError.d.ts +36 -0
- package/dist/utils/mcpAuthError.js +89 -0
- package/dist/utils/mcpAuthError.js.map +1 -0
- package/dist/utils/mcpUtils.js +16 -0
- package/dist/utils/mcpUtils.js.map +1 -1
- package/package.json +14 -13
|
@@ -1,12 +1,40 @@
|
|
|
1
|
+
import { isShellToolEnabled, getEffectiveDevToolsConfig } from '@gaunt-sloth/core/config.js';
|
|
1
2
|
import { GthAbstractAgent } from '@gaunt-sloth/core/core/GthAbstractAgent.js';
|
|
2
3
|
import { StatusLevel } from '@gaunt-sloth/core/core/types.js';
|
|
3
4
|
import { debugLog, debugLogObject } from '@gaunt-sloth/core/utils/debugUtils.js';
|
|
4
5
|
import { buildSystemMessages, formatToolCalls, readChatPrompt, readCodePrompt, readExecPrompt, } from '@gaunt-sloth/core/utils/llmUtils.js';
|
|
5
6
|
import { getCurrentWorkDir } from '@gaunt-sloth/core/utils/systemUtils.js';
|
|
7
|
+
import { isToolAllowed } from '@gaunt-sloth/core/utils/toolMatching.js';
|
|
8
|
+
// GS2-27: the OS/shell-dialect and real-cwd notes are backend-agnostic (both backends expose
|
|
9
|
+
// run_shell_command and run on the real-fs cwd), so their canonical source moved to core so the
|
|
10
|
+
// lean backend composes them too. Imported here for GthDeepAgent.init()'s code-mode composition and
|
|
11
|
+
// re-exported so existing importers of this module keep working.
|
|
12
|
+
import { appendOsShellNote, appendCwdNote, appendCommitCoAuthorNote, appendModelContextNote, appendMcpServerInstructionsNote, resolveModelIdentity, } from '@gaunt-sloth/core/utils/systemPromptNotes.js';
|
|
13
|
+
export { appendOsShellNote, appendCwdNote, appendCommitCoAuthorNote, appendModelContextNote, resolveModelIdentity, OS_SHELL_GUIDANCE, } from '@gaunt-sloth/core/utils/systemPromptNotes.js';
|
|
6
14
|
import { AIMessage, ToolMessage } from '@langchain/core/messages';
|
|
15
|
+
import { GraphInterrupt } from '@langchain/langgraph';
|
|
7
16
|
import { createMiddleware } from 'langchain';
|
|
8
17
|
import { createDeepAgent, FilesystemBackend } from 'deepagents';
|
|
9
|
-
import { buildPermissions, FILESYSTEM_TOOL_NAMES, } from '#src/core/deepAgentPermissions.js';
|
|
18
|
+
import { buildPermissions, FILESYSTEM_TOOL_NAMES, guardFilesystemBackend, } from '#src/core/deepAgentPermissions.js';
|
|
19
|
+
import { extractDebugRequestExtras } from '#src/core/debugCapture.js';
|
|
20
|
+
// Re-export so existing importers of this module (extractDebugRequestExtras.spec) keep working
|
|
21
|
+
// now that the implementation lives in @gaunt-sloth/core.
|
|
22
|
+
export { extractDebugRequestExtras } from '#src/core/debugCapture.js';
|
|
23
|
+
import { ShellCommandFailedError } from '#src/tools/GthDevToolkit.js';
|
|
24
|
+
/**
|
|
25
|
+
* EXT-16: decide whether the deepagents filesystem backend must run in virtualMode.
|
|
26
|
+
*
|
|
27
|
+
* deepagents' permission layer (`validatePath`) requires POSIX `/`-rooted glob paths, and its
|
|
28
|
+
* fs tools hand the SAME model-supplied path string to both the permission check and the native
|
|
29
|
+
* `path.resolve`/`fs` backend. On Windows a real cwd is `D:\...`, which can satisfy neither side
|
|
30
|
+
* as one string, so the EXT-13 real-path sandbox throws `Error: path must be absolute` on every
|
|
31
|
+
* turn and the agent hangs. The precise trigger is "the real cwd is not POSIX-rooted", so we key
|
|
32
|
+
* off that directly (not just `win32`): when true, run virtualMode (cwd→`/`) with virtual
|
|
33
|
+
* permissions — the pre-EXT-13 known-good behavior. POSIX keeps the EXT-13 real-path namespace.
|
|
34
|
+
*/
|
|
35
|
+
function shouldUseVirtualFs() {
|
|
36
|
+
return !getCurrentWorkDir().startsWith('/');
|
|
37
|
+
}
|
|
10
38
|
/**
|
|
11
39
|
* Deep agent: builds a `createDeepAgent` graph (deepagents). All run/stream/event
|
|
12
40
|
* plumbing lives in {@link GthAbstractAgent}; this class only knows how to construct
|
|
@@ -18,7 +46,10 @@ import { buildPermissions, FILESYSTEM_TOOL_NAMES, } from '#src/core/deepAgentPer
|
|
|
18
46
|
* {@link FilesystemBackend}. gsloth's `.aiignore` + `filesystem` config are mapped
|
|
19
47
|
* onto deepagents `permissions` (see {@link buildPermissions}). Any resolved tool
|
|
20
48
|
* that reuses a deepagents filesystem-tool name is therefore superseded and dropped
|
|
21
|
-
* (`createDeepAgent` would otherwise throw on the collision).
|
|
49
|
+
* (`createDeepAgent` would otherwise throw on the collision). EXT-14: the
|
|
50
|
+
* `FilesystemBackend` itself is wrapped with {@link guardFilesystemBackend} before it
|
|
51
|
+
* reaches `createDeepAgent`, adding a realpath (symlink-resolved) containment check the
|
|
52
|
+
* permission globs alone can't provide.
|
|
22
53
|
* - todos / subagents / summarization come from deepagents' standard middleware.
|
|
23
54
|
*
|
|
24
55
|
* The transport-agnostic param assembly lives in {@link buildDeepAgentParams} so the ACP
|
|
@@ -26,13 +57,8 @@ import { buildPermissions, FILESYSTEM_TOOL_NAMES, } from '#src/core/deepAgentPer
|
|
|
26
57
|
* middleware hardening without re-running `createDeepAgent` locally.
|
|
27
58
|
*/
|
|
28
59
|
export class GthDeepAgent extends GthAbstractAgent {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* `runner.getAgent()`; read lazily inside the `wrapModelCall` middleware so that when it
|
|
32
|
-
* is `undefined` (the normal path) the middleware is a transparent pass-through. Never
|
|
33
|
-
* touched by the lean agent or the AG-UI server, so those contracts are unchanged.
|
|
34
|
-
*/
|
|
35
|
-
debugCapture;
|
|
60
|
+
// `debugCapture` (the opt-in TUI `/debug` sink) now lives on the shared GthAbstractAgent base
|
|
61
|
+
// so the lean backend supports it too; the wrapModelCall capture middleware below reads it.
|
|
36
62
|
async init(command, configIn, checkpointer) {
|
|
37
63
|
const params = await this.buildDeepAgentParams(command, configIn);
|
|
38
64
|
// Runner-path only: surface requested tool calls to the console. This is intentionally
|
|
@@ -83,32 +109,120 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
83
109
|
return response;
|
|
84
110
|
},
|
|
85
111
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
112
|
+
// EXT-16: whether the deepagents fs backend runs in virtualMode. deepagents' permission layer
|
|
113
|
+
// requires POSIX `/`-rooted paths, so a Windows real cwd (`D:\...`) can't be expressed as a
|
|
114
|
+
// permission glob and the EXT-13 real-path mode hangs there (`Error: path must be absolute`).
|
|
115
|
+
// When the real cwd isn't POSIX-rooted, fall back to virtualMode (cwd→`/`) with virtual
|
|
116
|
+
// permissions — the pre-EXT-13 known-good Windows behavior. Computed here because the EXT-22 S1
|
|
117
|
+
// middleware (below), the backend, and the systemPrompt gate (further down) all key off it.
|
|
118
|
+
const useVirtualFs = shouldUseVirtualFs();
|
|
119
|
+
// EXT-22 (S1): last-word path-namespace correction. Appends the shared guidance as a trailing
|
|
120
|
+
// system-message block ONLY in code + virtualMode (where the fs virtual `/` root and the
|
|
121
|
+
// shell's real-OS paths diverge); a transparent pass-through otherwise. Added LAST in the
|
|
122
|
+
// middleware array so, being the innermost wrapModelCall, its block lands AFTER deepagents'
|
|
123
|
+
// "All file paths must start with a /." line (see handoff/spike-systemmessage-ordering.md).
|
|
124
|
+
const pathNamespaceCorrectionMiddleware = createPathNamespaceCorrectionMiddleware(this.command === 'code' && useVirtualFs);
|
|
125
|
+
const middleware = [
|
|
126
|
+
...params.middleware,
|
|
127
|
+
toolCallStatusMiddleware,
|
|
128
|
+
debugCaptureMiddleware,
|
|
129
|
+
pathNamespaceCorrectionMiddleware,
|
|
130
|
+
];
|
|
131
|
+
this.headerStatus(`Loaded middleware: ${middleware.map((m) => m.name).join(', ')}`);
|
|
132
|
+
// EXT-13: the backend always runs in REAL-path mode (virtualMode off) so the deepagents fs
|
|
133
|
+
// tools and the EXT-9 run_shell_command tool share ONE path namespace — real absolute paths
|
|
134
|
+
// rooted at cwd. Containment is enforced by the permission allow/deny globs built in
|
|
135
|
+
// buildDeepAgentParams (default: allow cwd/**, deny /**), which match what virtualMode used to
|
|
136
|
+
// give for free (see deepAgentPermissions + the EXT-13 symlink/`..` parity tests), PLUS the
|
|
137
|
+
// EXT-14 realpath guard wrapped around the backend below (closes the intermediate-symlinked-
|
|
138
|
+
// directory gap those lexical globs alone can't catch).
|
|
139
|
+
// `--allow-dir` (config.allowDirs) further widens those allow-rules to reach extra real dirs;
|
|
140
|
+
// it removes a guardrail, so it is announced loudly by the exec command and surfaced here.
|
|
93
141
|
const allowDirs = this.config?.allowDirs;
|
|
94
142
|
const widenFs = Array.isArray(allowDirs) && allowDirs.length > 0;
|
|
95
143
|
if (widenFs) {
|
|
96
|
-
this.statusUpdate(StatusLevel.WARNING, `Filesystem sandbox widened beyond cwd (--allow-dir): ${allowDirs.join(', ')}`
|
|
144
|
+
this.statusUpdate(StatusLevel.WARNING, `Filesystem sandbox widened beyond cwd (--allow-dir): ${allowDirs.join(', ')}` +
|
|
145
|
+
(useVirtualFs
|
|
146
|
+
? ' — note: on this platform the sandbox runs in virtual mode, so widening beyond cwd is not applied.'
|
|
147
|
+
: ''));
|
|
97
148
|
}
|
|
98
|
-
|
|
149
|
+
// EXT-14: layer the realpath containment guard around the backend deepagents' fs middleware
|
|
150
|
+
// (main agent AND every subagent — they all share this one `backend` reference, see
|
|
151
|
+
// guardFilesystemBackend's doc comment) reads/writes through. Closes the intermediate-
|
|
152
|
+
// symlinked-directory escape that the lexical allow/deny globs alone cannot catch.
|
|
153
|
+
const backend = guardFilesystemBackend(new FilesystemBackend({
|
|
99
154
|
rootDir: getCurrentWorkDir(),
|
|
100
|
-
virtualMode:
|
|
155
|
+
virtualMode: useVirtualFs,
|
|
156
|
+
}), {
|
|
157
|
+
cwd: getCurrentWorkDir(),
|
|
158
|
+
virtual: useVirtualFs,
|
|
159
|
+
allowDirs: widenFs ? allowDirs : undefined,
|
|
101
160
|
});
|
|
161
|
+
// EXT-13 (part b): on the local-runner code path the model used to be told nothing about
|
|
162
|
+
// where it is, so it assumed `/` was cwd and fed `/`-rooted paths to the real-fs shell. Now
|
|
163
|
+
// the backend uses real absolute paths (above), so inject the dynamic real cwd + path model
|
|
164
|
+
// into the prompt the model actually receives. Code mode only — the surface with full fs +
|
|
165
|
+
// shell access; the ACP transport keeps virtualMode and re-roots per session, so this
|
|
166
|
+
// real-path note must NOT leak there (which is why it lives in init(), not the
|
|
167
|
+
// transport-agnostic buildDeepAgentParams).
|
|
168
|
+
// In virtualMode (EXT-16, Windows) the real-cwd note must NOT be injected — it would mislabel
|
|
169
|
+
// the namespace (the fs tools' `/` is the virtual root, not the real cwd). Instead, EXT-22 (S2)
|
|
170
|
+
// injects the virtualMode path-namespace note so the model is told EARLY that the fs virtual
|
|
171
|
+
// `/` root and run_shell_command's real-OS paths differ (the S1 middleware repeats it as the
|
|
172
|
+
// authoritative last word after deepagents' `/`-rooted line). Non-code paths get neither.
|
|
173
|
+
// EXT-26: after the cwd/virtual-cwd note, append the OS + shell-dialect note so the model is
|
|
174
|
+
// told its host OS and which shell run_shell_command spawns (cmd.exe on Windows, /bin/sh on
|
|
175
|
+
// POSIX). This is ORTHOGONAL to the path-namespace notes above (those say WHERE it is; this
|
|
176
|
+
// says WHAT shell it speaks) and applies in BOTH code-mode branches, independent of
|
|
177
|
+
// virtualMode — the shell dialect matters on every platform. Non-code paths get nothing new.
|
|
178
|
+
// GS2-35: append the commit co-authoring rule (config `commit.coAuthor`, defaulting to the Gaunt
|
|
179
|
+
// Sloth account) so agent-authored commits credit Gaunt Sloth in the `Co-Authored-By` trailer and
|
|
180
|
+
// never the underlying model name. Mirrors the lean backend seam so both compose the same shared
|
|
181
|
+
// note (GS2-27 parity); same code-mode gate as the shell/cwd notes and independent of virtualMode.
|
|
182
|
+
const codeNotesPrompt = this.command === 'code'
|
|
183
|
+
? appendCommitCoAuthorNote(appendOsShellNote(useVirtualFs
|
|
184
|
+
? appendVirtualCwdNote(params.systemPrompt)
|
|
185
|
+
: appendCwdNote(params.systemPrompt, getCurrentWorkDir())), this.config?.commit?.coAuthor)
|
|
186
|
+
: params.systemPrompt;
|
|
187
|
+
// GS2-34: inject the resolved provider:model identity (mirrors the lean GthLangChainAgent seam so
|
|
188
|
+
// both backends compose the same shared note — GS2-27 parity). Composed OUTSIDE the code-mode
|
|
189
|
+
// gate above: "which model are you?" can be asked in ANY mode (chat/ask/code/exec), so the
|
|
190
|
+
// identity is visible everywhere, unlike the code-only cwd/os-shell/commit notes. Config opt-out
|
|
191
|
+
// via `injectModelContext: false` (default ON, defaulted here at the read site); when off — or
|
|
192
|
+
// when no model resolves — nothing is appended and the prompt is exactly as before. Lives in
|
|
193
|
+
// init() like the cwd note (not buildDeepAgentParams), so the deepagents-acp transport is
|
|
194
|
+
// unaffected, consistent with every other init()-composed note. GS2-6 capability note deferred.
|
|
195
|
+
const modelContextPrompt = this.config?.injectModelContext !== false
|
|
196
|
+
? appendModelContextNote(codeNotesPrompt, resolveModelIdentity(this.config))
|
|
197
|
+
: codeNotesPrompt;
|
|
198
|
+
// EXT-32: inject the connected MCP servers' discovery `instructions` (captured by the resolver
|
|
199
|
+
// during buildDeepAgentParams' resolveTools call, above) into the prompt — fenced + per-server-
|
|
200
|
+
// labelled as untrusted server-provided context. Mode-independent (MCP tools load in every
|
|
201
|
+
// mode). This mirrors the lean backend's GthLangChainAgent seam so both backends compose the
|
|
202
|
+
// same shared note (GS2-27 shared-path parity). Lives in init() like the cwd note, so the ACP
|
|
203
|
+
// buildDeepAgentParams entry is intentionally unaffected. Empty capture adds nothing.
|
|
204
|
+
// When tools are disabled, buildDeepAgentParams skips resolveTools (no MCP contact), so a REUSED
|
|
205
|
+
// resolver could still hold a prior run's capture — gate on toolsDisabled (recomputed from the
|
|
206
|
+
// effective config buildDeepAgentParams set on `this.config`) so no stale instructions leak.
|
|
207
|
+
const deepToolsDisabled = Array.isArray(this.config?.allowedTools) && this.config.allowedTools.length === 0;
|
|
208
|
+
const mcpInstructions = deepToolsDisabled
|
|
209
|
+
? []
|
|
210
|
+
: (this.resolvers?.getMcpServerInstructions?.() ?? []);
|
|
211
|
+
const systemPrompt = appendMcpServerInstructionsNote(modelContextPrompt, mcpInstructions);
|
|
102
212
|
this.agent = createDeepAgent({
|
|
103
213
|
model: params.model,
|
|
104
214
|
tools: params.tools,
|
|
105
215
|
// gsloth's composed prompt, combined ADDITIVELY by deepagents with its base + fs prompts
|
|
106
216
|
// into a single system message (avoids the two-system-message Anthropic rejection).
|
|
107
|
-
systemPrompt
|
|
217
|
+
systemPrompt,
|
|
108
218
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
219
|
middleware: middleware,
|
|
110
220
|
backend,
|
|
111
221
|
permissions: params.permissions,
|
|
222
|
+
// Per-tool human-in-the-loop gating (e.g. run_shell_command confirmation). When set,
|
|
223
|
+
// deepagents installs humanInTheLoopMiddleware so a matching tool call suspends the graph
|
|
224
|
+
// for approval; `undefined` (the default, and under yolo) leaves every tool ungated.
|
|
225
|
+
interruptOn: params.interruptOn,
|
|
112
226
|
checkpointer,
|
|
113
227
|
});
|
|
114
228
|
debugLog('Deep agent created successfully');
|
|
@@ -131,16 +245,16 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
131
245
|
streamOutput: this.config.streamOutput,
|
|
132
246
|
debugLog: this.config.debugLog,
|
|
133
247
|
});
|
|
134
|
-
this.
|
|
248
|
+
this.headerStatus(`Workdir: ${getCurrentWorkDir()}`);
|
|
135
249
|
if (this.config.modelDisplayName) {
|
|
136
|
-
this.
|
|
250
|
+
this.headerStatus(`Model: ${this.config.modelDisplayName}`);
|
|
137
251
|
}
|
|
138
252
|
// An empty allowedTools allow-list disables every tool. Skip resolution entirely so we
|
|
139
253
|
// don't contact MCP servers (and trigger OAuth) just to discard the result.
|
|
140
254
|
const allowedTools = this.config.allowedTools;
|
|
141
255
|
const toolsDisabled = Array.isArray(allowedTools) && allowedTools.length === 0;
|
|
142
256
|
if (toolsDisabled) {
|
|
143
|
-
this.
|
|
257
|
+
this.headerStatus('Tool loading disabled by allowedTools: []; MCP/A2A servers will not be contacted. Omit allowedTools for no filtering.');
|
|
144
258
|
}
|
|
145
259
|
// Resolve tools with filesystem access disabled. deepagents OWNS the filesystem
|
|
146
260
|
// (its fs middleware + the `permissions` built below); gsloth's filesystem toolkit
|
|
@@ -158,11 +272,12 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
158
272
|
? []
|
|
159
273
|
: this.extractAndFlattenTools(this.config.tools || []);
|
|
160
274
|
debugLog(`User config tools loaded: ${flattenedConfigTools.length}`);
|
|
161
|
-
// Combine all tools, then apply the allowedTools name allow-list when configured.
|
|
275
|
+
// Combine all tools, then apply the allowedTools name allow-list when configured. Entries
|
|
276
|
+
// match by exact name, or glob-style when they contain `*` (e.g. `mcp__unimarket__*`) — see
|
|
277
|
+
// isToolAllowed. Nameless ServerTools are retained (they can't be named in the allow-list).
|
|
162
278
|
let tools = [...resolvedTools, ...flattenedConfigTools];
|
|
163
279
|
if (Array.isArray(allowedTools)) {
|
|
164
|
-
|
|
165
|
-
tools = tools.filter((tool) => !tool.name || allowed.has(tool.name));
|
|
280
|
+
tools = tools.filter((tool) => !tool.name || isToolAllowed(tool.name, allowedTools));
|
|
166
281
|
}
|
|
167
282
|
// Safety net: a custom/dev/MCP tool may still reuse a deepagents filesystem-tool
|
|
168
283
|
// name (createDeepAgent throws on such a collision). Drop the colliding tool — the
|
|
@@ -180,7 +295,7 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
180
295
|
.map((tool) => tool.name)
|
|
181
296
|
.filter((name) => name)
|
|
182
297
|
.join(', ');
|
|
183
|
-
this.
|
|
298
|
+
this.headerStatus(`Loaded tools: ${toolNames}`);
|
|
184
299
|
debugLog(`Total tools available: ${passThroughTools.length}`);
|
|
185
300
|
debugLogObject('All Tools', toolNames.split(', '));
|
|
186
301
|
}
|
|
@@ -202,11 +317,20 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
202
317
|
}
|
|
203
318
|
return true;
|
|
204
319
|
});
|
|
205
|
-
// Soften deepagents' fail-hard filesystem
|
|
206
|
-
// read/write
|
|
207
|
-
// a
|
|
208
|
-
//
|
|
209
|
-
//
|
|
320
|
+
// Soften deepagents' fail-hard filesystem tool throws. By default the permission layer
|
|
321
|
+
// THROWS on both a denied read/write AND on a malformed path the model supplied — a relative
|
|
322
|
+
// path, a `..`/`~` segment, or an empty string (deepagents' validatePath, run BEFORE the
|
|
323
|
+
// permission check in enforcePermission). Any of these aborts the WHOLE run. On the AG-UI
|
|
324
|
+
// transport that throw propagates out of streamWithEvents into the run handler's catch, which
|
|
325
|
+
// emits RUN_ERROR and ends the response WITHOUT a terminal RUN_FINISHED — and since AG-UI's
|
|
326
|
+
// protocol makes RUN_ERROR terminal ("no further events can be sent"), a consumer waiting for
|
|
327
|
+
// RUN_FINISHED hangs (EXT-24). Wrap tool calls so each of these becomes a recoverable error
|
|
328
|
+
// ToolMessage instead, letting the model observe the mistake, retry with a good path, and
|
|
329
|
+
// finish the run normally (reaching RUN_FINISHED). This preserves gsloth's recoverable-denial
|
|
330
|
+
// UX (the old GthFileSystemToolkit returned a message rather than throwing). Only these known
|
|
331
|
+
// fs path/permission messages are caught; every other throw (GraphInterrupt from a client-tool
|
|
332
|
+
// interrupt stub, AbortError on client disconnect, unexpected errors) is rethrown untouched so
|
|
333
|
+
// control-flow and genuine failures still surface.
|
|
210
334
|
const fsDenialSoftening = createMiddleware({
|
|
211
335
|
name: 'GthDeepFsDenialSoftening',
|
|
212
336
|
wrapToolCall: async (request, handler) => {
|
|
@@ -214,9 +338,24 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
214
338
|
return await handler(request);
|
|
215
339
|
}
|
|
216
340
|
catch (e) {
|
|
341
|
+
// EXT-25: rethrow control-flow throws BY TYPE, BEFORE the message regex below. A
|
|
342
|
+
// GraphInterrupt (a client-tool interrupt() suspending the graph for HITL tool
|
|
343
|
+
// approval) and an AbortError (caller cancellation) must ALWAYS propagate so the graph
|
|
344
|
+
// suspends / cancels — never be converted into a benign ToolMessage. Mirrors the guard
|
|
345
|
+
// in GthAbstractAgent (error.name checks + GraphInterrupt instanceof). Today these
|
|
346
|
+
// survive only because their messages happen not to match the regex; guarding by type
|
|
347
|
+
// stops a future regex broadening from silently swallowing the HITL suspend.
|
|
348
|
+
if (e instanceof GraphInterrupt ||
|
|
349
|
+
e?.name === 'GraphInterrupt' ||
|
|
350
|
+
e?.name === 'AbortError') {
|
|
351
|
+
throw e;
|
|
352
|
+
}
|
|
217
353
|
const message = e instanceof Error ? e.message : String(e);
|
|
218
|
-
|
|
219
|
-
|
|
354
|
+
// deepagents fs enforcement throws (middleware/fs.ts enforcePermission +
|
|
355
|
+
// permissions/enforce.ts validatePath): a permission denial, or a path that is
|
|
356
|
+
// relative / contains ".." or "~" / is empty. All are recoverable model-input errors.
|
|
357
|
+
if (/permission denied for (read|write)|path must (be absolute|not contain|be a non-empty string)/i.test(message)) {
|
|
358
|
+
debugLog(`Softened fs tool throw into a ToolMessage: ${message}`);
|
|
220
359
|
return new ToolMessage({
|
|
221
360
|
content: message,
|
|
222
361
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -228,10 +367,93 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
228
367
|
}
|
|
229
368
|
},
|
|
230
369
|
});
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
//
|
|
234
|
-
|
|
370
|
+
// EXT-20: sibling of fsDenialSoftening for the run_* (dev/shell) tools. GthDevToolkit's
|
|
371
|
+
// executeCommand now THROWS a ShellCommandFailedError on a non-zero exit or a timeout-kill
|
|
372
|
+
// (instead of resolving with the failure text), so the tool result no longer misreports
|
|
373
|
+
// status:'success' (✓). Catch it here and return an error ToolMessage that PRESERVES the full
|
|
374
|
+
// stdout/stderr body — the model's observation is unchanged except that status flips to
|
|
375
|
+
// 'error', which drives the ✗ (isError) glyph (GthAbstractAgent maps status==='error' →
|
|
376
|
+
// isError). Returning a ToolMessage (rather than rethrowing) also means the approved-then-failed
|
|
377
|
+
// command does NOT trigger a retry loop — it is a normal, observed tool result.
|
|
378
|
+
const shellExitSoftening = createMiddleware({
|
|
379
|
+
name: 'GthDeepShellExitSoftening',
|
|
380
|
+
wrapToolCall: async (request, handler) => {
|
|
381
|
+
try {
|
|
382
|
+
return await handler(request);
|
|
383
|
+
}
|
|
384
|
+
catch (e) {
|
|
385
|
+
if (e instanceof ShellCommandFailedError) {
|
|
386
|
+
debugLog(`Softened shell/dev command failure (exit ${e.exitCode ?? 'timeout'}) into an ` +
|
|
387
|
+
`error ToolMessage for '${e.command}'`);
|
|
388
|
+
return new ToolMessage({
|
|
389
|
+
content: e.output,
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
391
|
+
tool_call_id: request.toolCall?.id ?? '',
|
|
392
|
+
status: 'error',
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
throw e;
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
});
|
|
399
|
+
// MCP tool-execution errors are spec-compliant RESULTS, not fatal faults. Per the MCP spec
|
|
400
|
+
// (2025-11-25 & draft, "Server › Tools › Error Handling"), a tool that hits an API failure, an
|
|
401
|
+
// input-validation problem, or a business-logic error (e.g. a disabled capability) returns a
|
|
402
|
+
// normal tools/call result with `isError: true`, and the CLIENT *SHOULD* hand that error to the
|
|
403
|
+
// model so it can self-correct. `@langchain/mcp-adapters` instead surfaces such a result by
|
|
404
|
+
// THROWING a ToolException at call time (its `_convertCallToolResult`). Because we install a
|
|
405
|
+
// wrapToolCall middleware, langchain's ToolNode treats any error a middleware rethrows as a fatal
|
|
406
|
+
// "middleware error" (`errorFromMiddleware && handleToolErrors !== true` → throw) and aborts the
|
|
407
|
+
// whole turn instead of relaying the error to the model — the opposite of the spec's client
|
|
408
|
+
// SHOULD. This middleware closes that gap: it catches a thrown ToolException and RETURNS it as a
|
|
409
|
+
// status:'error' ToolMessage (→ isError → ✗), so the model observes the error and can retry or
|
|
410
|
+
// explain (matching the non-stream invoke path's ToolException handling). Scope & safety: matched
|
|
411
|
+
// by name === 'ToolException' (the adapter's marker), so GraphInterrupt and every non-MCP throw
|
|
412
|
+
// fall through the final rethrow untouched. The adapter ALSO wraps a call-time AbortError into a
|
|
413
|
+
// ToolException (its `_callTool` catch-all), so we RETHROW when the run's abort signal is set —
|
|
414
|
+
// otherwise softening here would swallow user cancellation that ToolNode's own `signal?.aborted`
|
|
415
|
+
// guard normally enforces (bypassed once we handle the error in middleware). MCP connect/auth
|
|
416
|
+
// (401/403) and load failures are handled at CONNECT time (resolvers.ts throwOnLoadError +
|
|
417
|
+
// onConnectionError), not here, so they stay fatal as intended.
|
|
418
|
+
const mcpToolErrorSoftening = createMiddleware({
|
|
419
|
+
name: 'GthMcpToolErrorSoftening',
|
|
420
|
+
wrapToolCall: async (request, handler) => {
|
|
421
|
+
try {
|
|
422
|
+
return await handler(request);
|
|
423
|
+
}
|
|
424
|
+
catch (e) {
|
|
425
|
+
if (e instanceof Error &&
|
|
426
|
+
e.name === 'ToolException' &&
|
|
427
|
+
!request.runtime?.signal?.aborted) {
|
|
428
|
+
debugLog(`Softened MCP tool error into an error ToolMessage: ${e.message}`);
|
|
429
|
+
return new ToolMessage({
|
|
430
|
+
content: e.message,
|
|
431
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
432
|
+
tool_call_id: request.toolCall?.id ?? '',
|
|
433
|
+
status: 'error',
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
throw e;
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
});
|
|
440
|
+
// fsDenialSoftening first so it is the outermost wrapToolCall — it must see the throw from
|
|
441
|
+
// deepagents' permission-enforcing fs tools. shellExitSoftening sits right after it (still
|
|
442
|
+
// outboard of any user-configured middleware, so it always sees the raw ShellCommandFailedError
|
|
443
|
+
// throw before a user wrapToolCall could transform it). Order between the two softeners is not
|
|
444
|
+
// load-bearing: they catch DISJOINT conditions (a permission-denied regex vs an
|
|
445
|
+
// `instanceof ShellCommandFailedError`) and each rethrows what it doesn't recognize, so neither
|
|
446
|
+
// can swallow the other. The console-bound tool-call-status middleware is NOT added here (see
|
|
447
|
+
// GthDeepAgentParams.middleware); the runner appends it. mcpToolErrorSoftening sits alongside the
|
|
448
|
+
// other two softeners (still outboard of user middleware); it catches a DISJOINT condition
|
|
449
|
+
// (name==='ToolException') and rethrows everything else, so ordering among the three is not
|
|
450
|
+
// load-bearing.
|
|
451
|
+
const middleware = [
|
|
452
|
+
fsDenialSoftening,
|
|
453
|
+
shellExitSoftening,
|
|
454
|
+
mcpToolErrorSoftening,
|
|
455
|
+
...configuredMiddleware,
|
|
456
|
+
];
|
|
235
457
|
// Map gsloth's .aiignore + filesystem mode onto deepagents permission rules. When
|
|
236
458
|
// `--allow-dir` widens the sandbox, the backend runs without virtualMode, so paths are REAL
|
|
237
459
|
// absolute paths: constrain read+write to cwd + the allowed dirs (everything else denied),
|
|
@@ -242,7 +464,10 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
242
464
|
allowDirs: Array.isArray(this.config.allowDirs) && this.config.allowDirs.length > 0
|
|
243
465
|
? this.config.allowDirs
|
|
244
466
|
: undefined,
|
|
245
|
-
}
|
|
467
|
+
},
|
|
468
|
+
// EXT-16: build virtual (`/`-rooted) permission rules when the backend will run in
|
|
469
|
+
// virtualMode (Windows), matching the FilesystemBackend created in init().
|
|
470
|
+
shouldUseVirtualFs());
|
|
246
471
|
debugLogObject('Filesystem permissions', permissions);
|
|
247
472
|
// Compose gsloth's system prompt (backstory + guidelines + per-command mode prompt +
|
|
248
473
|
// system prompt) so identity profiles (Gaunt Sloth, sorcerer, fisher-alt, …) and
|
|
@@ -258,111 +483,116 @@ export class GthDeepAgent extends GthAbstractAgent {
|
|
|
258
483
|
: readChatPrompt(this.config);
|
|
259
484
|
const systemMessages = buildSystemMessages(this.config, modePrompt);
|
|
260
485
|
const systemPrompt = typeof systemMessages[0]?.content === 'string' ? systemMessages[0].content : undefined;
|
|
486
|
+
// Gate the opt-in run_shell_command tool behind a per-command approval interrupt. The tool is
|
|
487
|
+
// only emitted (by GthDevToolkit, via builtInToolsConfig) when its `run_shell_command`
|
|
488
|
+
// builtInTools entry enables it; use the shared core resolver so the interrupt wiring stays in
|
|
489
|
+
// lockstep with where the tool is actually emitted (CFG-18: resolved from `builtInTools`).
|
|
490
|
+
const devTools = getEffectiveDevToolsConfig(this.config ?? undefined, this.command);
|
|
491
|
+
// EXT-12 — pass the active command so the absent-config default (shell ON in `code`)
|
|
492
|
+
// is applied consistently with where the tool is actually emitted (GthDevToolkit).
|
|
493
|
+
const shellEnabled = isShellToolEnabled(devTools, this.command);
|
|
494
|
+
// EXT-12 — auto-approve (shellYolo) interplay with gating:
|
|
495
|
+
// • In interactive `code` mode we KEEP the tool gated even when shellYolo pre-enables
|
|
496
|
+
// auto-approval, so the runner's session flag governs it and `/auto-approve off` can
|
|
497
|
+
// restore the per-command prompt mid-session. The runner seeds that flag ON from
|
|
498
|
+
// shellYolo (see GthAgentRunner.init), so the user still sees no prompt by default; the
|
|
499
|
+
// interactive event/stream path drains the interrupt and auto-approves silently.
|
|
500
|
+
// • In non-interactive modes (exec / ask --write) a single-shot run does NOT drain
|
|
501
|
+
// interrupts, so shellYolo keeps the tool UNGATED (runs inline without suspending),
|
|
502
|
+
// preserving prior behaviour. There is no slash-command surface there to toggle anyway.
|
|
503
|
+
const isInteractive = this.command === 'code';
|
|
504
|
+
const gateShell = shellEnabled && (devTools?.shellYolo !== true || isInteractive);
|
|
505
|
+
const interruptOn = gateShell
|
|
506
|
+
? { run_shell_command: { allowedDecisions: ['approve', 'reject'] } }
|
|
507
|
+
: undefined;
|
|
508
|
+
if (gateShell && devTools?.shellYolo === true) {
|
|
509
|
+
this.statusUpdate(StatusLevel.INFO, 'Shell tool (run_shell_command) auto-approved by config (shellYolo). Type /auto-approve off to require per-command approval.');
|
|
510
|
+
}
|
|
511
|
+
else if (interruptOn) {
|
|
512
|
+
this.statusUpdate(StatusLevel.INFO, 'Shell tool (run_shell_command) enabled with per-command approval (interruptOn).');
|
|
513
|
+
}
|
|
514
|
+
else if (shellEnabled) {
|
|
515
|
+
this.statusUpdate(StatusLevel.WARNING, 'Shell tool (run_shell_command) enabled in YOLO mode: commands run WITHOUT confirmation.');
|
|
516
|
+
}
|
|
261
517
|
return {
|
|
262
518
|
model: this.config.llm,
|
|
263
519
|
tools: passThroughTools,
|
|
264
520
|
permissions,
|
|
265
521
|
middleware,
|
|
266
522
|
systemPrompt,
|
|
523
|
+
interruptOn,
|
|
267
524
|
};
|
|
268
525
|
}
|
|
269
526
|
}
|
|
270
527
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
528
|
+
* EXT-22: shared virtualMode path-namespace guidance — ONE source of truth used by BOTH the S2
|
|
529
|
+
* early-framing note ({@link appendVirtualCwdNote}, injected into gsloth's composed systemPrompt =
|
|
530
|
+
* block 0) and the S1 last-word correction middleware
|
|
531
|
+
* ({@link createPathNamespaceCorrectionMiddleware}, appended after deepagents' `/`-rooted line).
|
|
532
|
+
*
|
|
533
|
+
* In a virtualMode `code` session (EXT-16, e.g. Windows) the deepagents filesystem tools use a
|
|
534
|
+
* VIRTUAL `/` root (= the working dir) while `run_shell_command` uses REAL native OS paths; the
|
|
535
|
+
* model conflates the two forms. This text draws the distinction and steers toward cwd-relative
|
|
536
|
+
* paths (the one form both tool families read alike).
|
|
274
537
|
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
538
|
+
* It deliberately does NOT equate the virtual root with a specific real path (no "`/` = D:\\work"):
|
|
539
|
+
* virtualMode withholds the real cwd on purpose (see the systemPrompt gate in {@link
|
|
540
|
+
* GthDeepAgent.init}), so the guidance is about the DISTINCTION between the two namespaces and the
|
|
541
|
+
* safety of relative paths, not a mapping between them.
|
|
278
542
|
*/
|
|
279
|
-
const
|
|
280
|
-
'
|
|
281
|
-
'
|
|
282
|
-
'
|
|
283
|
-
'
|
|
284
|
-
'
|
|
285
|
-
'
|
|
286
|
-
'
|
|
287
|
-
'
|
|
288
|
-
'
|
|
289
|
-
'
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (value === undefined || value === null)
|
|
304
|
-
continue;
|
|
305
|
-
// Only scalars / scalar arrays — never nested objects that could carry credentials.
|
|
306
|
-
if (typeof value === 'object' && !Array.isArray(value))
|
|
307
|
-
continue;
|
|
308
|
-
out[key] = value;
|
|
309
|
-
}
|
|
310
|
-
// `model` / `modelName` / `modelId` are langchain aliases for the same value; collapse the
|
|
311
|
-
// duplicates so the panel shows the model id once instead of two identical lines.
|
|
312
|
-
if (typeof out.model !== 'string' && typeof out.modelName === 'string') {
|
|
313
|
-
out.model = out.modelName;
|
|
314
|
-
}
|
|
315
|
-
if (out.modelName === out.model)
|
|
316
|
-
delete out.modelName;
|
|
317
|
-
if (out.modelId === out.model)
|
|
318
|
-
delete out.modelId;
|
|
319
|
-
return Object.keys(out).length > 0 ? out : undefined;
|
|
320
|
-
}
|
|
321
|
-
/** Best-effort tool definition (name + description + schema) for the debug view. */
|
|
322
|
-
function extractToolDefs(tools) {
|
|
323
|
-
if (!Array.isArray(tools) || tools.length === 0)
|
|
324
|
-
return undefined;
|
|
325
|
-
const defs = [];
|
|
326
|
-
for (const tool of tools) {
|
|
327
|
-
if (!tool || typeof tool !== 'object')
|
|
328
|
-
continue;
|
|
329
|
-
const t = tool;
|
|
330
|
-
const name = typeof t.name === 'string' ? t.name : undefined;
|
|
331
|
-
if (!name)
|
|
332
|
-
continue;
|
|
333
|
-
const description = typeof t.description === 'string' ? t.description : undefined;
|
|
334
|
-
// LangChain StructuredTools expose a Zod/JSON `schema`; some carry it on `lc_kwargs`.
|
|
335
|
-
const schema = t.schema ?? undefined;
|
|
336
|
-
defs.push({ name, description, schema });
|
|
337
|
-
}
|
|
338
|
-
return defs.length > 0 ? defs : undefined;
|
|
543
|
+
export const PATH_NAMESPACE_GUIDANCE = 'The filesystem tools (ls, read_file, write_file, edit_file, glob, grep) use a VIRTUAL root in ' +
|
|
544
|
+
'this session: a leading `/` means your working directory, and their paths are written ' +
|
|
545
|
+
'`/`-rooted relative to it (this is what "all file paths must start with a /" refers to). That ' +
|
|
546
|
+
'`/` is NOT the real operating-system filesystem root. run_shell_command is different: it runs ' +
|
|
547
|
+
'in the real operating system and uses real native paths (on Windows, e.g. ' +
|
|
548
|
+
'`C:\\Users\\...\\project`, with backslashes), never the virtual `/` root. A `/`-rooted path ' +
|
|
549
|
+
'from the filesystem tools is NOT a valid shell path and must never be passed to ' +
|
|
550
|
+
'run_shell_command. The one form that means the same thing to both tool families is a path ' +
|
|
551
|
+
'RELATIVE to the working directory (e.g. `src/index.ts`); prefer relative paths for both. When ' +
|
|
552
|
+
'you must be absolute, use `/`-rooted form ONLY for the filesystem tools and real native form ' +
|
|
553
|
+
'ONLY for run_shell_command.';
|
|
554
|
+
/**
|
|
555
|
+
* EXT-22 (S2): virtualMode variant of {@link appendCwdNote}. On the `code` path when the fs
|
|
556
|
+
* backend runs in virtualMode (EXT-16), inject the shared path-namespace guidance EARLY in
|
|
557
|
+
* gsloth's composed systemPrompt (block 0) so the model is framed before deepagents' own prompt.
|
|
558
|
+
*
|
|
559
|
+
* This is early framing only: deepagents' hardcoded `/`-rooted line lands in a LATER block and can
|
|
560
|
+
* partially override block 0, so the authoritative last word is delivered by the S1 middleware
|
|
561
|
+
* ({@link createPathNamespaceCorrectionMiddleware}); see handoff/spike-systemmessage-ordering.md.
|
|
562
|
+
* Returns the note alone when there is no base prompt.
|
|
563
|
+
*/
|
|
564
|
+
export function appendVirtualCwdNote(systemPrompt) {
|
|
565
|
+
const note = `Filesystem vs shell path namespaces: ${PATH_NAMESPACE_GUIDANCE}`;
|
|
566
|
+
return systemPrompt ? `${systemPrompt}\n\n${note}` : note;
|
|
339
567
|
}
|
|
340
568
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
569
|
+
* EXT-22 (S1): the load-bearing path-namespace correction. A gsloth `wrapModelCall` middleware
|
|
570
|
+
* runs INNERMOST (inside deepagents' filesystem middleware), so appending a trailing block to
|
|
571
|
+
* `request.systemMessage` lands AFTER deepagents' hardcoded "All file paths must start with a /."
|
|
572
|
+
* line — giving gsloth the last word on path semantics (empirically verified; see
|
|
573
|
+
* handoff/spike-systemmessage-ordering.md). It APPENDS via `request.systemMessage.concat(...)`
|
|
574
|
+
* (mirroring how deepagents appends its own fs prompt), never string-splices, and returns a NEW
|
|
575
|
+
* request so it never mutates persisted state (no compounding across turns).
|
|
576
|
+
*
|
|
577
|
+
* `appendCorrection` gates it to `code` + virtualMode: only there do the fs virtual `/` root and
|
|
578
|
+
* the shell's real-OS paths diverge. On POSIX real-path mode deepagents' "start with /" is
|
|
579
|
+
* literally true, so the middleware is a transparent pass-through (like the debug-capture
|
|
580
|
+
* middleware when no sink is attached).
|
|
344
581
|
*/
|
|
345
|
-
export function
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
tools: extractToolDefs(req.tools),
|
|
358
|
-
modelParams: extractModelParams(req.model),
|
|
359
|
-
toolChoice: req.toolChoice,
|
|
360
|
-
};
|
|
361
|
-
// Return undefined when nothing useful was captured so the renderer can show a clear empty state.
|
|
362
|
-
const hasAny = extras.systemPrompt !== undefined ||
|
|
363
|
-
extras.tools !== undefined ||
|
|
364
|
-
extras.modelParams !== undefined ||
|
|
365
|
-
extras.toolChoice !== undefined;
|
|
366
|
-
return hasAny ? extras : undefined;
|
|
582
|
+
export function createPathNamespaceCorrectionMiddleware(appendCorrection) {
|
|
583
|
+
return createMiddleware({
|
|
584
|
+
name: 'GthDeepPathNamespaceCorrection',
|
|
585
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
586
|
+
wrapModelCall: async (request, handler) => {
|
|
587
|
+
if (!appendCorrection || !request?.systemMessage)
|
|
588
|
+
return handler(request);
|
|
589
|
+
const correction = 'IMPORTANT — path namespaces (authoritative; this overrides any earlier instruction that ' +
|
|
590
|
+
`implies every path is a simple \`/\`-rooted filesystem path): ${PATH_NAMESPACE_GUIDANCE}`;
|
|
591
|
+
return handler({ ...request, systemMessage: request.systemMessage.concat(correction) });
|
|
592
|
+
},
|
|
593
|
+
});
|
|
367
594
|
}
|
|
595
|
+
// The `/debug` request-extras extraction (extractDebugRequestExtras + its model-param / tool-def
|
|
596
|
+
// allowlist helpers) now lives in @gaunt-sloth/core (`core/debugCapture.ts`) so the lean backend
|
|
597
|
+
// shares it. Imported at the top of this module and re-exported for back-compat.
|
|
368
598
|
//# sourceMappingURL=GthDeepAgent.js.map
|