@gaunt-sloth/core 2.0.0-alpha.3 → 2.0.0-alpha.30
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 +52 -20
- package/dist/config/colour.d.ts +38 -0
- package/dist/config/colour.js +36 -0
- package/dist/config/colour.js.map +1 -0
- package/dist/config/defaults.d.ts +84 -0
- package/dist/config/defaults.js +99 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/filesystem-tools.d.ts +41 -0
- package/dist/config/filesystem-tools.js +56 -0
- package/dist/config/filesystem-tools.js.map +1 -0
- package/dist/config/jsonc.d.ts +12 -0
- package/dist/config/jsonc.js +41 -0
- package/dist/config/jsonc.js.map +1 -0
- package/dist/config/loader.d.ts +246 -0
- package/dist/config/loader.js +1321 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/mouse.d.ts +50 -0
- package/dist/config/mouse.js +44 -0
- package/dist/config/mouse.js.map +1 -0
- package/dist/config/profiles.d.ts +68 -0
- package/dist/config/profiles.js +93 -0
- package/dist/config/profiles.js.map +1 -0
- package/dist/config/providerKeys.d.ts +69 -0
- package/dist/config/providerKeys.js +69 -0
- package/dist/config/providerKeys.js.map +1 -0
- package/dist/config/schema.d.ts +2999 -0
- package/dist/config/schema.js +1519 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/shell-policy.d.ts +896 -0
- package/dist/config/shell-policy.js +750 -0
- package/dist/config/shell-policy.js.map +1 -0
- package/dist/config/tool-descriptions.d.ts +211 -0
- package/dist/config/tool-descriptions.js +272 -0
- package/dist/config/tool-descriptions.js.map +1 -0
- package/dist/config/types.d.ts +760 -0
- package/dist/config/types.js +13 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +34 -827
- package/dist/config.js +25 -657
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +46 -0
- package/dist/constants.js +46 -0
- package/dist/constants.js.map +1 -1
- package/dist/core/GthAbstractAgent.d.ts +135 -2
- package/dist/core/GthAbstractAgent.js +496 -30
- package/dist/core/GthAbstractAgent.js.map +1 -1
- package/dist/core/GthAgentRunner.d.ts +568 -54
- package/dist/core/GthAgentRunner.js +1537 -136
- package/dist/core/GthAgentRunner.js.map +1 -1
- package/dist/core/GthLangChainAgent.d.ts +115 -0
- package/dist/core/GthLangChainAgent.js +644 -17
- package/dist/core/GthLangChainAgent.js.map +1 -1
- package/dist/core/approvals/annotations.d.ts +122 -0
- package/dist/core/approvals/annotations.js +137 -0
- package/dist/core/approvals/annotations.js.map +1 -0
- package/dist/core/approvals/grants.d.ts +216 -0
- package/dist/core/approvals/grants.js +469 -0
- package/dist/core/approvals/grants.js.map +1 -0
- package/dist/core/approvals/matcher.d.ts +202 -0
- package/dist/core/approvals/matcher.js +267 -0
- package/dist/core/approvals/matcher.js.map +1 -0
- package/dist/core/approvals/mcpSubjects.d.ts +40 -0
- package/dist/core/approvals/mcpSubjects.js +99 -0
- package/dist/core/approvals/mcpSubjects.js.map +1 -0
- package/dist/core/approvals/toolAnnotationSources.d.ts +105 -0
- package/dist/core/approvals/toolAnnotationSources.js +277 -0
- package/dist/core/approvals/toolAnnotationSources.js.map +1 -0
- package/dist/core/approvals/toolHost.d.ts +46 -0
- package/dist/core/approvals/toolHost.js +108 -0
- package/dist/core/approvals/toolHost.js.map +1 -0
- package/dist/core/debugCapture.d.ts +75 -0
- package/dist/core/debugCapture.js +101 -0
- package/dist/core/debugCapture.js.map +1 -0
- package/dist/core/gthLeanAgentFactory.d.ts +9 -0
- package/dist/core/gthLeanAgentFactory.js +10 -0
- package/dist/core/gthLeanAgentFactory.js.map +1 -0
- package/dist/core/launchBanner.d.ts +120 -0
- package/dist/core/launchBanner.js +418 -0
- package/dist/core/launchBanner.js.map +1 -0
- package/dist/core/plainToolIndication.d.ts +15 -0
- package/dist/core/plainToolIndication.js +174 -0
- package/dist/core/plainToolIndication.js.map +1 -0
- package/dist/core/reasoningBlocks.d.ts +60 -0
- package/dist/core/reasoningBlocks.js +98 -0
- package/dist/core/reasoningBlocks.js.map +1 -0
- package/dist/core/refusal.d.ts +53 -0
- package/dist/core/refusal.js +133 -0
- package/dist/core/refusal.js.map +1 -0
- package/dist/core/runStats.d.ts +52 -0
- package/dist/core/runStats.js +118 -0
- package/dist/core/runStats.js.map +1 -0
- package/dist/core/shell/ShellCommandFailedError.d.ts +54 -0
- package/dist/core/shell/ShellCommandFailedError.js +68 -0
- package/dist/core/shell/ShellCommandFailedError.js.map +1 -0
- package/dist/core/shell/abstention.d.ts +88 -0
- package/dist/core/shell/abstention.js +184 -0
- package/dist/core/shell/abstention.js.map +1 -0
- package/dist/core/shell/approvalCapture.d.ts +271 -0
- package/dist/core/shell/approvalCapture.js +108 -0
- package/dist/core/shell/approvalCapture.js.map +1 -0
- package/dist/core/shell/approvalStop.d.ts +84 -0
- package/dist/core/shell/approvalStop.js +119 -0
- package/dist/core/shell/approvalStop.js.map +1 -0
- package/dist/core/shell/arity.d.ts +6 -0
- package/dist/core/shell/arity.js +20 -6
- package/dist/core/shell/arity.js.map +1 -1
- package/dist/core/shell/denylist.d.ts +11 -0
- package/dist/core/shell/denylist.js +37 -0
- package/dist/core/shell/denylist.js.map +1 -0
- package/dist/core/shell/escalationSeverity.d.ts +141 -0
- package/dist/core/shell/escalationSeverity.js +89 -0
- package/dist/core/shell/escalationSeverity.js.map +1 -0
- package/dist/core/shell/framing.d.ts +190 -0
- package/dist/core/shell/framing.js +633 -0
- package/dist/core/shell/framing.js.map +1 -0
- package/dist/core/shell/hardline.d.ts +81 -0
- package/dist/core/shell/hardline.js +607 -0
- package/dist/core/shell/hardline.js.map +1 -0
- package/dist/core/shell/negotiation.d.ts +249 -0
- package/dist/core/shell/negotiation.js +355 -0
- package/dist/core/shell/negotiation.js.map +1 -0
- package/dist/core/shell/normalize.d.ts +44 -4
- package/dist/core/shell/normalize.js +61 -7
- package/dist/core/shell/normalize.js.map +1 -1
- package/dist/core/shell/openWorld.d.ts +263 -0
- package/dist/core/shell/openWorld.js +1188 -0
- package/dist/core/shell/openWorld.js.map +1 -0
- package/dist/core/shell/rater.d.ts +935 -0
- package/dist/core/shell/rater.js +1473 -0
- package/dist/core/shell/rater.js.map +1 -0
- package/dist/core/shell/raterModel.d.ts +41 -0
- package/dist/core/shell/raterModel.js +51 -0
- package/dist/core/shell/raterModel.js.map +1 -0
- package/dist/core/shell/rejection.d.ts +69 -0
- package/dist/core/shell/rejection.js +38 -0
- package/dist/core/shell/rejection.js.map +1 -0
- package/dist/core/toolCallRepair/grammar.d.ts +41 -0
- package/dist/core/toolCallRepair/grammar.js +116 -0
- package/dist/core/toolCallRepair/grammar.js.map +1 -0
- package/dist/core/toolCallRepair/index.d.ts +2 -0
- package/dist/core/toolCallRepair/index.js +7 -0
- package/dist/core/toolCallRepair/index.js.map +1 -0
- package/dist/core/toolCallRepair/payload.d.ts +36 -0
- package/dist/core/toolCallRepair/payload.js +341 -0
- package/dist/core/toolCallRepair/payload.js.map +1 -0
- package/dist/core/toolCallRepair/promote.d.ts +45 -0
- package/dist/core/toolCallRepair/promote.js +90 -0
- package/dist/core/toolCallRepair/promote.js.map +1 -0
- package/dist/core/toolDisplay.d.ts +123 -0
- package/dist/core/toolDisplay.js +451 -0
- package/dist/core/toolDisplay.js.map +1 -0
- package/dist/core/toolOutputChannel.d.ts +95 -0
- package/dist/core/toolOutputChannel.js +165 -0
- package/dist/core/toolOutputChannel.js.map +1 -0
- package/dist/core/types.d.ts +294 -12
- package/dist/core/types.js.map +1 -1
- package/dist/history/historyFormat.d.ts +28 -0
- package/dist/history/historyFormat.js +127 -0
- package/dist/history/historyFormat.js.map +1 -0
- package/dist/history/historyStore.d.ts +198 -0
- package/dist/history/historyStore.js +482 -0
- package/dist/history/historyStore.js.map +1 -0
- package/dist/history/recordSession.d.ts +37 -0
- package/dist/history/recordSession.js +56 -0
- package/dist/history/recordSession.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +5 -10
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/deepseek.d.ts +1 -1
- package/dist/providers/deepseek.js +5 -10
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/geminiSchemaSanitizer.d.ts +55 -0
- package/dist/providers/geminiSchemaSanitizer.js +347 -0
- package/dist/providers/geminiSchemaSanitizer.js.map +1 -0
- package/dist/providers/geminiThinking.d.ts +52 -0
- package/dist/providers/geminiThinking.js +72 -0
- package/dist/providers/geminiThinking.js.map +1 -0
- package/dist/providers/google-genai.d.ts +1 -1
- package/dist/providers/google-genai.js +12 -11
- package/dist/providers/google-genai.js.map +1 -1
- package/dist/providers/groq.d.ts +1 -1
- package/dist/providers/groq.js +5 -10
- package/dist/providers/groq.js.map +1 -1
- package/dist/providers/huggingface.d.ts +25 -0
- package/dist/providers/huggingface.js +69 -0
- package/dist/providers/huggingface.js.map +1 -0
- package/dist/providers/modelCatalog.d.ts +109 -0
- package/dist/providers/modelCatalog.js +245 -0
- package/dist/providers/modelCatalog.js.map +1 -0
- package/dist/providers/modelDiscovery.d.ts +153 -6
- package/dist/providers/modelDiscovery.js +295 -41
- package/dist/providers/modelDiscovery.js.map +1 -1
- package/dist/providers/ollama.d.ts +19 -5
- package/dist/providers/ollama.js +60 -52
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +39 -10
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter.d.ts +4 -5
- package/dist/providers/openrouter.js +20 -35
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/vertexai.d.ts +1 -1
- package/dist/providers/vertexai.js +12 -11
- package/dist/providers/vertexai.js.map +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +5 -10
- package/dist/providers/xai.js.map +1 -1
- package/dist/runtime/askStructured.d.ts +105 -0
- package/dist/runtime/askStructured.js +120 -0
- package/dist/runtime/askStructured.js.map +1 -0
- package/dist/runtime/conversation.d.ts +60 -0
- package/dist/runtime/conversation.js +151 -0
- package/dist/runtime/conversation.js.map +1 -0
- package/dist/runtime/singleShot.d.ts +25 -5
- package/dist/runtime/singleShot.js +95 -36
- package/dist/runtime/singleShot.js.map +1 -1
- package/dist/runtime/structuredOutput.d.ts +104 -0
- package/dist/runtime/structuredOutput.js +393 -0
- package/dist/runtime/structuredOutput.js.map +1 -0
- package/dist/utils/ProgressIndicator.d.ts +21 -0
- package/dist/utils/ProgressIndicator.js +30 -3
- package/dist/utils/ProgressIndicator.js.map +1 -1
- package/dist/utils/aiignoreUtils.js.map +1 -1
- package/dist/utils/binaryOutputUtils.js.map +1 -1
- package/dist/utils/consoleUtils.d.ts +52 -0
- package/dist/utils/consoleUtils.js +72 -2
- package/dist/utils/consoleUtils.js.map +1 -1
- package/dist/utils/crashHandler.d.ts +87 -0
- package/dist/utils/crashHandler.js +128 -0
- package/dist/utils/crashHandler.js.map +1 -0
- package/dist/utils/debugDump.d.ts +134 -0
- package/dist/utils/debugDump.js +381 -0
- package/dist/utils/debugDump.js.map +1 -0
- package/dist/utils/debugUtils.d.ts +13 -4
- package/dist/utils/debugUtils.js +36 -13
- package/dist/utils/debugUtils.js.map +1 -1
- package/dist/utils/displayWidth.d.ts +53 -0
- package/dist/utils/displayWidth.js +195 -0
- package/dist/utils/displayWidth.js.map +1 -0
- package/dist/utils/fileUtils.d.ts +24 -2
- package/dist/utils/fileUtils.js +54 -12
- package/dist/utils/fileUtils.js.map +1 -1
- package/dist/utils/llmUtils.d.ts +39 -8
- package/dist/utils/llmUtils.js +76 -8
- package/dist/utils/llmUtils.js.map +1 -1
- package/dist/utils/redactSecrets.d.ts +63 -0
- package/dist/utils/redactSecrets.js +286 -0
- package/dist/utils/redactSecrets.js.map +1 -0
- package/dist/utils/systemPromptNotes.d.ts +225 -0
- package/dist/utils/systemPromptNotes.js +340 -0
- package/dist/utils/systemPromptNotes.js.map +1 -0
- package/dist/utils/systemUtils.d.ts +49 -1
- package/dist/utils/systemUtils.js +67 -3
- package/dist/utils/systemUtils.js.map +1 -1
- package/dist/utils/toolMatching.d.ts +30 -0
- package/dist/utils/toolMatching.js +44 -0
- package/dist/utils/toolMatching.js.map +1 -0
- package/dist/utils/untrustedText.d.ts +66 -0
- package/dist/utils/untrustedText.js +80 -0
- package/dist/utils/untrustedText.js.map +1 -0
- package/package.json +22 -6
- package/schema/gsloth-config.schema.json +3134 -0
- package/dist/core/shell/allowlist.d.ts +0 -75
- package/dist/core/shell/allowlist.js +0 -187
- package/dist/core/shell/allowlist.js.map +0 -1
- package/dist/core/shell/judge.d.ts +0 -161
- package/dist/core/shell/judge.js +0 -261
- package/dist/core/shell/judge.js.map +0 -1
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Shell / dev-tools policy: the {@link GthDevToolsConfig} type plus all the resolvers
|
|
4
|
+
* that interpret it (shell enablement, timeouts, output budget, per-command dev-tools
|
|
5
|
+
* selection), and — since CFG-27 — the {@link ApprovalsConfig} value and its resolver
|
|
6
|
+
* {@link resolveApprovals} (the five-rung ladder, the rater's identity profile, and the declared
|
|
7
|
+
* allow/deny lists).
|
|
8
|
+
*
|
|
9
|
+
* CFG-18 — the dev/shell tools are now configured through the unified {@link GthConfig.builtInTools}
|
|
10
|
+
* registry (`string[] | Record<string, boolean | BuiltInToolConfig>`), NOT the removed per-command
|
|
11
|
+
* `commands.<mode>.devTools` key. {@link GthDevToolsConfig} is therefore no longer an on-disk shape:
|
|
12
|
+
* it is the internal, resolved view that {@link getEffectiveDevToolsConfig} builds from the effective
|
|
13
|
+
* `builtInTools` registry, and that {@link GthDevToolkit} + the shell accessors below consume. This
|
|
14
|
+
* keeps the toolkit/accessor surface stable while the single config surface is `builtInTools`.
|
|
15
|
+
*/
|
|
16
|
+
import { StatusLevel } from '#src/core/types.js';
|
|
17
|
+
import { isAccessClassGrantedAtRung } from '#src/config/tool-descriptions.js';
|
|
18
|
+
/**
|
|
19
|
+
* The fixed dev-command tools: each maps a `command` string (from its {@link BuiltInToolConfig})
|
|
20
|
+
* to a run_* tool emitted by {@link GthDevToolkit}.
|
|
21
|
+
*/
|
|
22
|
+
export const DEV_COMMAND_TOOL_NAMES = [
|
|
23
|
+
'run_tests',
|
|
24
|
+
'run_lint',
|
|
25
|
+
'run_build',
|
|
26
|
+
'run_single_test',
|
|
27
|
+
];
|
|
28
|
+
/** The opt-in general-purpose shell tool name. */
|
|
29
|
+
export const SHELL_TOOL_NAME = 'run_shell_command';
|
|
30
|
+
/**
|
|
31
|
+
* All dev/shell tool names carried in the {@link GthConfig.builtInTools} registry. These are emitted
|
|
32
|
+
* by {@link GthDevToolkit} via the dev-tools bucket, NOT loaded as plain built-in tools — so
|
|
33
|
+
* `getBuiltInTools` skips them (a `run_shell_command` entry in `builtInTools` is legitimate, not an
|
|
34
|
+
* "unknown built-in tool").
|
|
35
|
+
*/
|
|
36
|
+
export const DEV_TOOL_NAMES = [...DEV_COMMAND_TOOL_NAMES, SHELL_TOOL_NAME];
|
|
37
|
+
/**
|
|
38
|
+
* Normalize the widened {@link BuiltInToolsSetting} to a plain lookup keyed by tool name. The array
|
|
39
|
+
* form maps each name to `true`; the object form passes through unchanged; absent → `{}`.
|
|
40
|
+
*/
|
|
41
|
+
export function normalizeBuiltInTools(builtInTools) {
|
|
42
|
+
if (!builtInTools)
|
|
43
|
+
return {};
|
|
44
|
+
if (Array.isArray(builtInTools)) {
|
|
45
|
+
const out = {};
|
|
46
|
+
for (const name of builtInTools)
|
|
47
|
+
out[name] = true;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
return builtInTools;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether a plain built-in tool's registry entry is enabled: a bare `true`, or an object entry that
|
|
54
|
+
* is not `{ enabled: false }` (configuring a tool enables it). A bare `false` force-disables it.
|
|
55
|
+
* Dev/shell tools ({@link DEV_TOOL_NAMES}) are NOT resolved through this — they go through
|
|
56
|
+
* {@link getEffectiveDevToolsConfig} / {@link isShellToolEnabled}.
|
|
57
|
+
*/
|
|
58
|
+
export function isBuiltInToolEntryEnabled(value) {
|
|
59
|
+
if (value === undefined)
|
|
60
|
+
return false;
|
|
61
|
+
if (typeof value === 'boolean')
|
|
62
|
+
return value;
|
|
63
|
+
return value.enabled !== false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Default per-command shell timeout (ms) when {@link GthDevToolsConfig.shell}
|
|
67
|
+
* does not specify one. ~120s suits typical build/test/git steps without
|
|
68
|
+
* hanging the agent forever on a stuck command.
|
|
69
|
+
*/
|
|
70
|
+
export const SHELL_DEFAULT_TIMEOUT_MS = 120_000;
|
|
71
|
+
/**
|
|
72
|
+
* Default byte budget for shell output captured into the ToolMessage returned to
|
|
73
|
+
* the model (head + tail window). ~100KB keeps a noisy log from blowing the
|
|
74
|
+
* context window; the full output is spilled to a temp file when this is exceeded.
|
|
75
|
+
*/
|
|
76
|
+
export const SHELL_DEFAULT_MAX_OUTPUT_BYTES = 100_000;
|
|
77
|
+
/**
|
|
78
|
+
* Normalize the {@link GthDevToolsConfig.shell} opt-in (bare boolean or
|
|
79
|
+
* `{ enabled }`) to a plain boolean. Centralized so the toolkit (tool emission)
|
|
80
|
+
* and the deep agent (interrupt wiring) agree on what "shell enabled" means.
|
|
81
|
+
*
|
|
82
|
+
* EXT-12 / CFG-18 — default-resolution is `enabled ?? default`. An EXPLICIT `enabled` always wins
|
|
83
|
+
* (a bare boolean, or the object form's `enabled`), so `shell: false` / `{ enabled: false }` remains
|
|
84
|
+
* a hard escape hatch that fully disables the tool. When `enabled` is ABSENT — whether `shell` is
|
|
85
|
+
* undefined OR an object that omits `enabled` (e.g. `{ timeout: 300000 }`, i.e. a
|
|
86
|
+
* `{ "run_shell_command": { "timeout": 300000 } }` registry entry) — the per-mode default applies:
|
|
87
|
+
* ON in `code` mode (still gated — the per-command approval interrupt is wired separately and is NOT
|
|
88
|
+
* bypassed by this), OFF everywhere else (`exec`, `ask --write`, …). This is the CFG-18 change from
|
|
89
|
+
* the old `enabled === true` object semantics: configuring the shell no longer silently turns it off.
|
|
90
|
+
* The default is `code`-mode only because `code` is the interactive agentic-coding surface where a
|
|
91
|
+
* TTY can answer the approval prompt; the absent-config default never implies yolo.
|
|
92
|
+
*
|
|
93
|
+
* @param command The active command, so the absent-config default can be scoped to `code`.
|
|
94
|
+
* Omit (or pass a non-`code` command) to keep the historical OFF-by-default behaviour.
|
|
95
|
+
*/
|
|
96
|
+
export function isShellToolEnabled(devTools, command) {
|
|
97
|
+
const shell = devTools?.shell;
|
|
98
|
+
if (typeof shell === 'boolean')
|
|
99
|
+
return shell;
|
|
100
|
+
// Object form: `enabled ?? default` — an object without `enabled` still defaults ON in `code`.
|
|
101
|
+
if (shell && typeof shell === 'object')
|
|
102
|
+
return shell.enabled ?? command === 'code';
|
|
103
|
+
// Absent/undefined shell: ON by default for `code` mode (gated), OFF elsewhere.
|
|
104
|
+
return command === 'code';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Resolve the per-command shell timeout (ms) from config, falling back to
|
|
108
|
+
* {@link SHELL_DEFAULT_TIMEOUT_MS}. Only the object form can override it; a bare
|
|
109
|
+
* `shell: true` uses the default. Non-positive / non-finite values are ignored.
|
|
110
|
+
*/
|
|
111
|
+
export function getShellTimeoutMs(devTools) {
|
|
112
|
+
const shell = devTools?.shell;
|
|
113
|
+
if (shell && typeof shell === 'object' && typeof shell.timeout === 'number') {
|
|
114
|
+
if (Number.isFinite(shell.timeout) && shell.timeout > 0)
|
|
115
|
+
return shell.timeout;
|
|
116
|
+
}
|
|
117
|
+
return SHELL_DEFAULT_TIMEOUT_MS;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Resolve the captured-output byte budget from config, falling back to
|
|
121
|
+
* {@link SHELL_DEFAULT_MAX_OUTPUT_BYTES}. Only the object form can override it.
|
|
122
|
+
* Non-positive / non-finite values are ignored.
|
|
123
|
+
*/
|
|
124
|
+
export function getShellMaxOutputBytes(devTools) {
|
|
125
|
+
const shell = devTools?.shell;
|
|
126
|
+
if (shell && typeof shell === 'object' && typeof shell.maxOutputBytes === 'number') {
|
|
127
|
+
if (Number.isFinite(shell.maxOutputBytes) && shell.maxOutputBytes > 0) {
|
|
128
|
+
return shell.maxOutputBytes;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return SHELL_DEFAULT_MAX_OUTPUT_BYTES;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Build the internal, resolved {@link GthDevToolsConfig} from a normalized `builtInTools` registry:
|
|
135
|
+
* the fixed dev-command tools read their `command` string, and `run_shell_command` maps to the
|
|
136
|
+
* `shell` view the accessors below consume (CFG-26: the approval knobs are no longer here — they
|
|
137
|
+
* live in the top-level `approvals` block, resolved by {@link resolveApprovals}). Returns `undefined` when the registry
|
|
138
|
+
* carries no dev/shell entry at all, so callers treat it exactly like an unset `devTools` (the
|
|
139
|
+
* `code`-mode shell default still applies downstream via {@link isShellToolEnabled}).
|
|
140
|
+
*/
|
|
141
|
+
function devToolsConfigFromRegistry(registry) {
|
|
142
|
+
const resolved = {};
|
|
143
|
+
let hasAny = false;
|
|
144
|
+
for (const name of DEV_COMMAND_TOOL_NAMES) {
|
|
145
|
+
const entry = registry[name];
|
|
146
|
+
const cmd = entry && typeof entry === 'object' ? entry.command : undefined;
|
|
147
|
+
if (typeof cmd === 'string' && cmd.length > 0) {
|
|
148
|
+
resolved[name] = cmd;
|
|
149
|
+
hasAny = true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (Object.prototype.hasOwnProperty.call(registry, SHELL_TOOL_NAME)) {
|
|
153
|
+
const entry = registry[SHELL_TOOL_NAME];
|
|
154
|
+
if (typeof entry === 'boolean') {
|
|
155
|
+
resolved.shell = entry;
|
|
156
|
+
}
|
|
157
|
+
else if (entry && typeof entry === 'object') {
|
|
158
|
+
resolved.shell = {
|
|
159
|
+
enabled: entry.enabled,
|
|
160
|
+
timeout: entry.timeout,
|
|
161
|
+
maxOutputBytes: entry.maxOutputBytes,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
hasAny = true;
|
|
165
|
+
}
|
|
166
|
+
return hasAny ? resolved : undefined;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Resolve the {@link GthDevToolsConfig} that applies to the active command from the unified
|
|
170
|
+
* {@link GthConfig.builtInTools} registry (CFG-18 — replaces the removed per-command `devTools`).
|
|
171
|
+
* Mirrors the per-command selection used by `builtInToolsConfig.getDefaultTools`: `exec` →
|
|
172
|
+
* `commands.exec`, `ask --write` → `commands.ask`, `code` → `commands.code`; `undefined` elsewhere
|
|
173
|
+
* (the dev/shell tools are inert there). The effective registry for the scope is the per-command
|
|
174
|
+
* `builtInTools` if set, else the root `builtInTools` — matching `getEffectiveConfig`'s replace
|
|
175
|
+
* merge. Shared in core so the runner's allow-list/judge gates stay in lockstep with where the
|
|
176
|
+
* shell tool is actually emitted.
|
|
177
|
+
*/
|
|
178
|
+
export function getEffectiveDevToolsConfig(config, command) {
|
|
179
|
+
if (!config)
|
|
180
|
+
return undefined;
|
|
181
|
+
const askWrite = command === 'ask' && config.askWriteMode === true;
|
|
182
|
+
const cmdConfig = command === 'exec'
|
|
183
|
+
? config.commands?.exec
|
|
184
|
+
: askWrite
|
|
185
|
+
? config.commands?.ask
|
|
186
|
+
: command === 'code'
|
|
187
|
+
? config.commands?.code
|
|
188
|
+
: undefined;
|
|
189
|
+
// Only the do-the-job commands (code/exec/ask --write) carry dev/shell tools.
|
|
190
|
+
if (command !== 'exec' && command !== 'code' && !askWrite)
|
|
191
|
+
return undefined;
|
|
192
|
+
const effective = cmdConfig?.builtInTools ?? config.builtInTools;
|
|
193
|
+
return devToolsConfigFromRegistry(normalizeBuiltInTools(effective));
|
|
194
|
+
}
|
|
195
|
+
/* -------------------------------------------------------------------------------------------- *
|
|
196
|
+
* CFG-27 — the `approvals` ladder: one ordered set of five rungs, plus the declared lists.
|
|
197
|
+
* -------------------------------------------------------------------------------------------- */
|
|
198
|
+
/**
|
|
199
|
+
* CFG-27 (spec §1, §2) — **the ladder**. There is ONE approvals setting and it is a single ordered
|
|
200
|
+
* ladder; each rung fully determines behaviour. There are no severity thresholds, no strictness
|
|
201
|
+
* levels and no independent rater on/off switch.
|
|
202
|
+
*
|
|
203
|
+
* | # | Rung | Rater | LLM cost |
|
|
204
|
+
* |---|---|---|---|
|
|
205
|
+
* | 1 | `manual` | no | none |
|
|
206
|
+
* | 2 | `write` | no | none |
|
|
207
|
+
* | 3 | `assisted` | yes | 1 call per gated call |
|
|
208
|
+
* | 4 | `auto` | yes | 1–2 calls per gated call |
|
|
209
|
+
* | 5 | `bypass` | no | none |
|
|
210
|
+
*
|
|
211
|
+
* Rungs 1, 2 and 5 are fully deterministic: no model is consulted, so behaviour is reproducible
|
|
212
|
+
* and costs nothing.
|
|
213
|
+
*
|
|
214
|
+
* **CFG-39 — four postures plus one modifier, not five peers.** `write` is not a rung on a trust
|
|
215
|
+
* ladder: it is the same posture as `manual` with a different auto-granted set. The four postures
|
|
216
|
+
* a user chooses between are {@link APPROVAL_POSTURES} (`manual` → `assisted` → `auto`, plus
|
|
217
|
+
* `bypass`), and that ordering is legible in the names themselves. `write` remains fully settable
|
|
218
|
+
* — via `/approvals write` and via config — and simply does not occupy a row in quick access.
|
|
219
|
+
* This constant keeps ALL FIVE members: it is the type's domain, the set
|
|
220
|
+
* {@link resolveInterruptToolNames} unions over, and what makes `write` settable at all.
|
|
221
|
+
*
|
|
222
|
+
* **`bypass` is NOT a higher-autonomy rung than `auto`** (§2.5). Both let the agent act
|
|
223
|
+
* without asking; `bypass` is the same autonomy with the checks removed. The ordering below is the
|
|
224
|
+
* order the rungs are *offered* in, and must never be presented as though `auto` were an
|
|
225
|
+
* incomplete `bypass`.
|
|
226
|
+
*
|
|
227
|
+
* Identifiers are lower-case single words (§9.1) because the same token must work as a config
|
|
228
|
+
* value, a slash-command argument and a CLI flag — a space breaks the last two. Display names are
|
|
229
|
+
* capitalised; see {@link APPROVAL_RUNG_LABELS}.
|
|
230
|
+
*/
|
|
231
|
+
export const APPROVAL_RUNGS = ['manual', 'write', 'assisted', 'auto', 'bypass'];
|
|
232
|
+
/**
|
|
233
|
+
* §9.1 rule / §10 rule 4 — the display spelling of each rung, with spaces. An identifier and a
|
|
234
|
+
* label do not have to match and only one of them has to survive a shell, so user-facing prose
|
|
235
|
+
* uses these and never the kebab-case identifiers.
|
|
236
|
+
*/
|
|
237
|
+
export const APPROVAL_RUNG_LABELS = {
|
|
238
|
+
manual: 'Manual',
|
|
239
|
+
write: 'Write',
|
|
240
|
+
assisted: 'Assisted',
|
|
241
|
+
auto: 'Auto',
|
|
242
|
+
bypass: 'Bypass',
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* CFG-39 — **the four postures**, in the order they are offered: the rows `/approvals` presents
|
|
246
|
+
* when it asks the user to choose one.
|
|
247
|
+
*
|
|
248
|
+
* `write` is deliberately absent, and its absence is the whole point of the reframe. It is not a
|
|
249
|
+
* rung on a trust ladder — it is `manual`'s posture with a different auto-granted set, so listing
|
|
250
|
+
* it as a fifth peer is what made a four-point ladder read as five indistinguishable ones. It stays
|
|
251
|
+
* fully settable via `/approvals write` and via config; it simply leaves quick access.
|
|
252
|
+
*
|
|
253
|
+
* **This is a presentation list, never a policy one.** Every predicate, every `Record<ApprovalRung,
|
|
254
|
+
* …>` and the interrupt set are built from {@link APPROVAL_RUNGS}, which keeps all five. Using this
|
|
255
|
+
* constant to decide behaviour would silently un-settle `write`.
|
|
256
|
+
*/
|
|
257
|
+
export const APPROVAL_POSTURES = [
|
|
258
|
+
'manual',
|
|
259
|
+
'assisted',
|
|
260
|
+
'auto',
|
|
261
|
+
'bypass',
|
|
262
|
+
];
|
|
263
|
+
/**
|
|
264
|
+
* CFG-39 — the one-line note that `write` exists, shown as picker CHROME beside the `manual` row.
|
|
265
|
+
*
|
|
266
|
+
* It lives here rather than appended to {@link APPROVAL_RUNG_DESCRIPTIONS}`.manual` on purpose: the
|
|
267
|
+
* descriptions are one surface's copy shared by six, so a sentence about quick-access mechanics
|
|
268
|
+
* would follow the mode into the status display and the tool-description layer, where it means
|
|
269
|
+
* nothing.
|
|
270
|
+
*/
|
|
271
|
+
export const APPROVAL_WRITE_MODIFIER_HINT = 'Manual also has a Write variant that may edit files in your working folder without asking: ' +
|
|
272
|
+
'set it with /approvals write.';
|
|
273
|
+
/**
|
|
274
|
+
* §10 — what each mode is **for**, in at most two sentences, shown wherever a mode is chosen or
|
|
275
|
+
* displayed.
|
|
276
|
+
*
|
|
277
|
+
* **The first sentence is load-bearing and must stand alone.** The `/approvals` picker, the text
|
|
278
|
+
* fallback and the usage hint all render one line per mode through `firstSentence`, so sentence
|
|
279
|
+
* one has to answer "what is this mode for" on its own and sentence two carries the qualification.
|
|
280
|
+
* Keep it short enough to read as a menu row.
|
|
281
|
+
*
|
|
282
|
+
* **Say what the mode is for, not only what it permits.** A description that lists permissions
|
|
283
|
+
* invites the category error these modes actually suffer: Manual reads as "the safe one", so it
|
|
284
|
+
* gets picked for a long unattended run — where the deciding is done by a human, and a human is the
|
|
285
|
+
* fastest-degrading decider in the system. Manual and Write are bounded-volume tools and their copy
|
|
286
|
+
* says so.
|
|
287
|
+
*
|
|
288
|
+
* The wording is constrained by four normative rules (state what the mode PERMITS, state the
|
|
289
|
+
* allow-list carve-out, never claim safety this system cannot deliver, use the display spelling)
|
|
290
|
+
* plus §8.1 — the hardline floor is real but is NEVER advertised, so descriptions cite only
|
|
291
|
+
* protections the user can inspect and extend, i.e. the deny list. Five further constraints bind
|
|
292
|
+
* every edit here:
|
|
293
|
+
*
|
|
294
|
+
* 1. **No description may imply containment.** The gate protects against accidents, not intent, and
|
|
295
|
+
* a working-folder claim collapses the moment the agent has a shell — `write_file` refuses a
|
|
296
|
+
* path that `touch` then writes. The narrow true form (the built-in file *tools* are confined)
|
|
297
|
+
* is stated once, on `write`, alongside the fact that the shell is not confined that way.
|
|
298
|
+
* 2. **Claims are scoped to the session the user is in.** These strings render on terminal surfaces
|
|
299
|
+
* only; a sentence whose subject is "Gaunt Sloth" and whose claim is that it always asks would
|
|
300
|
+
* be false over the AG-UI and ACP servers, which never drain an approval interrupt ([[EXT-94]]).
|
|
301
|
+
* 3. **`assisted` MUST keep the sentence saying files are still rewritten and deleted without
|
|
302
|
+
* asking** — it sounds safer than it is, and that clause is the correction.
|
|
303
|
+
* 4. **A qualification may not live in the second sentence alone.** The picker, the text fallback
|
|
304
|
+
* and the usage hint all render `firstSentence` and nothing else, so the opener is the whole
|
|
305
|
+
* message on the three surfaces a user reads while *choosing* a mode. An opener that sells a
|
|
306
|
+
* behavioural difference the product does not have is not rescued by a sentence two those
|
|
307
|
+
* surfaces never print — check a wording by rendering it, not by reading the constant.
|
|
308
|
+
* 5. **`auto` is the mode a reader most wants to hear is quiet, and it is not.** It settles some
|
|
309
|
+
* risky commands with the rater instead of interrupting — that difference is real and may be
|
|
310
|
+
* stated — but the copy MUST also say that a bounded exchange ends at the user, and MUST NOT
|
|
311
|
+
* promise the user watches it happen. The rounds reach a person at the escalation, all of them
|
|
312
|
+
* at once, and nothing renders them before that ([[TUI-C26]]), so a sentence implying a live
|
|
313
|
+
* commentary would be describing a screen that does not exist.
|
|
314
|
+
*
|
|
315
|
+
* Everything these two sentences cannot hold lives at {@link APPROVAL_PROTECTION_DOCS_URL}, which
|
|
316
|
+
* the surfaces print beside the copy rather than each description repeating it.
|
|
317
|
+
*/
|
|
318
|
+
export const APPROVAL_RUNG_DESCRIPTIONS = {
|
|
319
|
+
manual: 'For a handful of commands you want to read yourself — not a mode to leave running. In this ' +
|
|
320
|
+
'session Gaunt Sloth reads and lists files in your working folder on its own; everything ' +
|
|
321
|
+
'else — shell, file changes, MCP and custom tools — comes to you, until you tell it to always ' +
|
|
322
|
+
'allow a command.',
|
|
323
|
+
write: 'Manual, for work that is mostly editing, and like Manual a bounded stretch: the built-in ' +
|
|
324
|
+
'file tools run free inside your working folder. The shell is not confined that way, so shell ' +
|
|
325
|
+
'commands, MCP calls and custom tools still come to you, until you tell it to always allow a ' +
|
|
326
|
+
'command.',
|
|
327
|
+
assisted: 'For everyday work: safe commands run, anything riskier comes to you — usually with a line ' +
|
|
328
|
+
'explaining what it does. Gaunt Sloth can still rewrite and delete files in your working ' +
|
|
329
|
+
'folder without asking — "safe" means each action is checked for reaching outside that folder ' +
|
|
330
|
+
'or harming your system, not that nothing changes.',
|
|
331
|
+
auto: 'For work you want to keep moving: Auto sends a risky command back to the agent to fix or ' +
|
|
332
|
+
'justify a few times, then stops and asks you. It is not safe — Gaunt Sloth will change and ' +
|
|
333
|
+
'delete things, your deny list still applies, and when it does ask, you are shown the whole ' +
|
|
334
|
+
'argument that led there.',
|
|
335
|
+
bypass: 'No gate, for a throwaway environment you would not mind losing. Whatever Gaunt Sloth decides ' +
|
|
336
|
+
'to run, runs — nothing is rated and nothing is asked; only the refusals in your config’s ' +
|
|
337
|
+
'deny list still apply.',
|
|
338
|
+
};
|
|
339
|
+
/**
|
|
340
|
+
* The page that carries what these modes do and do NOT protect you from — the reasoning the
|
|
341
|
+
* two-sentence descriptions deliberately do not hold.
|
|
342
|
+
*
|
|
343
|
+
* **A GitHub blob URL, matching the one other user-facing runtime doc link in this package** (the
|
|
344
|
+
* 2.0 migration pointer in `config/schema.ts`). The docs site publishes the same page at
|
|
345
|
+
* `https://gauntsloth.app/docs/guides/what-approvals-protect-you-from/`; move this constant there
|
|
346
|
+
* once that path serves the page, and nothing else changes.
|
|
347
|
+
*/
|
|
348
|
+
export const APPROVAL_PROTECTION_DOCS_URL = 'https://github.com/pukeko-robotics/gaunt-sloth/blob/main/docs/guides/what-approvals-protect-you-from.md';
|
|
349
|
+
/**
|
|
350
|
+
* The docs pointer as the surfaces print it: **label and URL as two separate lines**, never one
|
|
351
|
+
* joined string. Every notice surface takes `lines: string[]` and renders one line each, so a bare
|
|
352
|
+
* URL on its own line is the only form that survives a narrow pane without the break landing
|
|
353
|
+
* mid-path — and it is what lets a terminal that linkifies URLs pick the whole thing up.
|
|
354
|
+
*
|
|
355
|
+
* It lives beside the descriptions rather than inside them for {@link APPROVAL_WRITE_MODIFIER_HINT}'s
|
|
356
|
+
* reason: one line about where to read more, repeated into all five descriptions, would follow each
|
|
357
|
+
* mode into the tool-description layer and the status display, where it is noise.
|
|
358
|
+
*/
|
|
359
|
+
export const APPROVAL_PROTECTION_DOCS_LINES = [
|
|
360
|
+
'What these modes do and do not protect you from:',
|
|
361
|
+
APPROVAL_PROTECTION_DOCS_URL,
|
|
362
|
+
];
|
|
363
|
+
/** Narrowing type guard for a raw string that may name a rung. */
|
|
364
|
+
export function isApprovalRung(value) {
|
|
365
|
+
return typeof value === 'string' && APPROVAL_RUNGS.includes(value);
|
|
366
|
+
}
|
|
367
|
+
/** The rungs at which every gated call is rated by the model (§2.3, §2.4). */
|
|
368
|
+
export function isRatedRung(rung) {
|
|
369
|
+
return rung === 'assisted' || rung === 'auto';
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* [[EXT-29]] (§5) — the rung at which a `destructive` rating opens a **negotiation** with the rater
|
|
373
|
+
* instead of going to the human: the agent may revise the command or justify it, the rater re-rates
|
|
374
|
+
* with the exchange in view, and only a spent bound reaches a person.
|
|
375
|
+
*
|
|
376
|
+
* **This is the one predicate that separates `auto` from `assisted`, and it is deliberately ONE.**
|
|
377
|
+
* Three places have to agree about it — the decision mapping
|
|
378
|
+
* ({@link import('../core/shell/rater.js').mapVerdictToAction}, which returns `reject` here and
|
|
379
|
+
* `escalate` at `assisted`), the rating prompt (§5.2's wording rules are addressed to the agent, so
|
|
380
|
+
* they are turned on by this and not by whether a transcript happens to exist yet), and the runner
|
|
381
|
+
* that counts the rounds. Two of them agreeing and the third not is exactly how the two rated rungs
|
|
382
|
+
* would drift back into being the same posture with different names.
|
|
383
|
+
*
|
|
384
|
+
* Written as a `=== 'auto'` test rather than as "rated but not assisted" so that a sixth rung has to
|
|
385
|
+
* be classified deliberately rather than inheriting a negotiation by omission.
|
|
386
|
+
*/
|
|
387
|
+
export function isNegotiatingRung(rung) {
|
|
388
|
+
return rung === 'auto';
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* The rungs that decide a gated call **without a model** — `manual` and `write` (§2.1, §2.2).
|
|
392
|
+
* Everything they do not auto-grant goes to the human, so these are the two rungs a user picks in
|
|
393
|
+
* order to read and approve every tool call themselves.
|
|
394
|
+
*
|
|
395
|
+
* The complement of {@link isRatedRung} plus `bypass`; written out rather than negated so that a
|
|
396
|
+
* sixth rung would have to be classified deliberately instead of defaulting into this set.
|
|
397
|
+
*/
|
|
398
|
+
export function isDeterministicRung(rung) {
|
|
399
|
+
return rung === 'manual' || rung === 'write';
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* **The one rule: does `rung` gate this tool — i.e. must this call be decided rather than simply
|
|
403
|
+
* run?** Everything else in this area is a projection of this predicate over a set of names.
|
|
404
|
+
*
|
|
405
|
+
* - The shell is gated whenever the shell gate is on, at EVERY rung (`bypass` included, so §2.5's
|
|
406
|
+
* deny list can still fire — see the `bypass` arm of `GthAgentRunner.decideToolApproval`).
|
|
407
|
+
* - At the two **deterministic** rungs, a tool is gated when the rung's own grant does not cover its
|
|
408
|
+
* access class ({@link isAccessClassGrantedAtRung}). At `manual` that leaves only the built-in
|
|
409
|
+
* READ tools free; at `write`, the built-in read and write tools. The write built-ins, the shell,
|
|
410
|
+
* deepagents' `execute`, MCP tools and custom/agent-authored tools all escalate to the human.
|
|
411
|
+
* - At `assisted`, `auto` and `bypass` nothing but the shell is gated. **That split is
|
|
412
|
+
* deliberate and load-bearing, not tidiness.** At a rated rung a gated non-shell call reaches the
|
|
413
|
+
* `subject.kind !== 'shell'` arm of `GthAgentRunner.decideToolApproval`, which floors it at
|
|
414
|
+
* `destructive` and sends it to the human *with no rating call*, because §4.3 keeps the rater on
|
|
415
|
+
* the shell until [[EXT-30]]. Gating there would silently turn every MCP call at `assisted` into
|
|
416
|
+
* a human prompt — a UX change belonging to EXT-30, not to the two rungs whose published
|
|
417
|
+
* descriptions this predicate makes true.
|
|
418
|
+
*
|
|
419
|
+
* `gateShell` only ever WIDENS the result. At a deterministic rung the shell is gated by its own
|
|
420
|
+
* (absent) access class if it is bound at all, so `gateShell: false` does not exempt it — an
|
|
421
|
+
* exemption keyed to one tool NAME is the defect class this predicate exists to remove. In practice
|
|
422
|
+
* a disabled shell tool is never bound, so the two agree.
|
|
423
|
+
*
|
|
424
|
+
* **This takes no bound toolset**, which is what lets `GthAgentRunner` ask it about a single
|
|
425
|
+
* arriving call: the runner sees the names the graph registered, and on the deep backend that list
|
|
426
|
+
* omits tools deepagents registers itself. A decision that consulted a bound list would grant
|
|
427
|
+
* `execute` at `manual` purely because the runner could not see it.
|
|
428
|
+
*/
|
|
429
|
+
export function isToolGatedAtRung(options) {
|
|
430
|
+
const { toolName, rung, gateShell } = options;
|
|
431
|
+
if (gateShell && toolName === SHELL_TOOL_NAME)
|
|
432
|
+
return true;
|
|
433
|
+
if (!isDeterministicRung(rung))
|
|
434
|
+
return false;
|
|
435
|
+
return !isAccessClassGrantedAtRung(toolName, rung);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* **The LIVE gated set: which bound tools the rung in force actually gates.** What a decision is
|
|
439
|
+
* measured against — the tool descriptions the model reads (§4.5) and the rater's granted-tools
|
|
440
|
+
* summary (§4.4) are both built from this, so neither can tell the model a tool is free while the
|
|
441
|
+
* gate escalates it.
|
|
442
|
+
*
|
|
443
|
+
* **It is NOT what the backends wire into the interrupt.** That is
|
|
444
|
+
* {@link resolveInterruptToolNames}, and the two are different sets on purpose: the interrupt is
|
|
445
|
+
* installed once, at agent init, while `/approvals <rung>` moves the rung underneath it for the rest
|
|
446
|
+
* of the session. A set that carried the rung would be frozen at the rung the session started on —
|
|
447
|
+
* and since the default is `assisted`, typing `/approvals manual` would leave exactly the write
|
|
448
|
+
* tools this design escalates ungated. So the interrupt is wired rung-independently and
|
|
449
|
+
* `GthAgentRunner.decideToolApproval` consults {@link isToolGatedAtRung} against the LIVE rung.
|
|
450
|
+
*
|
|
451
|
+
* **Derived from the bound toolset, never a hand-written list.** A static list of built-ins would
|
|
452
|
+
* leave MCP, custom and agent-authored tools out — the exact tools with no access class and so the
|
|
453
|
+
* exact tools the deterministic rungs must escalate. `boundToolNames` must therefore be the FINAL
|
|
454
|
+
* toolset the graph is handed, including tools the graph builder registers itself (deepagents'
|
|
455
|
+
* filesystem tools, `execute`, `task` and `write_todos` never appear in the array gsloth passes it).
|
|
456
|
+
*
|
|
457
|
+
* Order is stable: the shell first, then bound order. Duplicates are collapsed, so a caller may pass
|
|
458
|
+
* overlapping name sources without deduplicating first.
|
|
459
|
+
*/
|
|
460
|
+
export function resolveGatedToolNames(options) {
|
|
461
|
+
const { rung, gateShell, boundToolNames } = options;
|
|
462
|
+
return collectToolNames(gateShell, boundToolNames, (name) => isToolGatedAtRung({ toolName: name, rung, gateShell }));
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* **Which commands have something that ANSWERS an approval interrupt.**
|
|
466
|
+
*
|
|
467
|
+
* `GthAgentRunner` is the one component that drains a suspended graph
|
|
468
|
+
* (`resolveToolInterrupts` → `decideToolApproval`) and the one that holds the session rung, so every
|
|
469
|
+
* command it drives answers approvals and can move the rung under a running session.
|
|
470
|
+
*
|
|
471
|
+
* **The AG-UI server (`api`) does not.** It drives the agent directly — `agent.init` +
|
|
472
|
+
* `streamWithEvents` — and its resume path serves its own frontend-tool `interrupt()` stubs, not
|
|
473
|
+
* approvals. An approval interrupt raised there suspends the graph with nobody to resume it: the
|
|
474
|
+
* tool never runs, the client is never asked, and the turn simply ends with that tool call
|
|
475
|
+
* unanswered. Measured, not inferred.
|
|
476
|
+
*
|
|
477
|
+
* So a command that answers nothing must be handed **no approval interrupt beyond what the shell
|
|
478
|
+
* gate itself requires** — see the `interruptTools` wiring in both backends. In particular it must
|
|
479
|
+
* NOT be handed the LIVE set for its configured rung: that set is non-empty at `manual` and
|
|
480
|
+
* `write`, so it carries exactly the same trap, and `commands.api.approvals` (plus a root-level
|
|
481
|
+
* `approvals`, which applies to every command) puts an ordinary config on those rungs.
|
|
482
|
+
*
|
|
483
|
+
* **Total over {@link GthCommand} on purpose.** An eighth command has to be classified here before
|
|
484
|
+
* it compiles, rather than defaulting silently into "answers approvals". The property is really
|
|
485
|
+
* about the DRIVER and not about the command — a second server built under an existing command that
|
|
486
|
+
* drives the agent without `GthAgentRunner` would inherit the trap with this record fully populated
|
|
487
|
+
* — so the shape that cannot rot at all is for the constructing surface to declare it at its own
|
|
488
|
+
* call site.
|
|
489
|
+
*
|
|
490
|
+
* Approvals for the AG-UI surface are [[EXT-30]]'s to build; until then this keeps a rung the server
|
|
491
|
+
* cannot serve from silently swallowing the tool calls it was asked to make.
|
|
492
|
+
*/
|
|
493
|
+
const COMMAND_ANSWERS_APPROVALS = {
|
|
494
|
+
ask: true,
|
|
495
|
+
chat: true,
|
|
496
|
+
code: true,
|
|
497
|
+
exec: true,
|
|
498
|
+
pr: true,
|
|
499
|
+
review: true,
|
|
500
|
+
/** The AG-UI server: it drives the agent itself and drains nothing. */
|
|
501
|
+
api: false,
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* {@link COMMAND_ANSWERS_APPROVALS} as a predicate. An unset command is a session driven by
|
|
505
|
+
* `GthAgentRunner` (nothing else leaves it unset), so it answers approvals.
|
|
506
|
+
*
|
|
507
|
+
* **`?? true` is the fail-safe default, not defensive noise.** The lookup yields `undefined` for a
|
|
508
|
+
* value outside {@link GthCommand}, and `undefined` is falsy — which would tell the caller to
|
|
509
|
+
* install NO approval interrupt, the one direction this predicate must never fail in. TypeScript
|
|
510
|
+
* makes that unreachable from inside this repo, but the function is re-exported from the public
|
|
511
|
+
* `@gaunt-sloth/core/config.js` barrel, so an untyped consumer can reach it. The coalesce restores
|
|
512
|
+
* runtime totality without weakening the compile-time totality the record already gives.
|
|
513
|
+
*/
|
|
514
|
+
export function commandAnswersApprovals(command) {
|
|
515
|
+
return command === undefined ? true : (COMMAND_ANSWERS_APPROVALS[command] ?? true);
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* **The interrupt set: which tool names the backends wire into the approval interrupt.** Every bound
|
|
519
|
+
* tool that ANY rung could gate — the union of {@link resolveGatedToolNames} over
|
|
520
|
+
* {@link APPROVAL_RUNGS}, which in practice is the shell plus every bound tool that is not a
|
|
521
|
+
* built-in READ tool.
|
|
522
|
+
*
|
|
523
|
+
* One derivation for both backends, for the same reason {@link resolveShellApprovalGate} is one: the
|
|
524
|
+
* lean backend installs `humanInTheLoopMiddleware` directly and the deep backend installs the very
|
|
525
|
+
* same middleware through deepagents' `interruptOn`, and a set computed twice is a set that drifts.
|
|
526
|
+
*
|
|
527
|
+
* **Deliberately rung-independent.** The interrupt is installed once, when the agent is built, and
|
|
528
|
+
* `/approvals <rung>` then moves the rung for the rest of the session without rebuilding it. Only a
|
|
529
|
+
* set that covers every rung can survive that: the interrupt fires and
|
|
530
|
+
* `GthAgentRunner.decideToolApproval` decides on the rung in force, which is where the rung has
|
|
531
|
+
* always been read. **Wiring wider does not gate wider** — a call the live rung does not gate is
|
|
532
|
+
* approved there with no rating call and no prompt, so `assisted`, `auto` and `bypass` behave
|
|
533
|
+
* exactly as they do when the interrupt holds the shell alone.
|
|
534
|
+
*
|
|
535
|
+
* **Only for a command that answers approvals** ({@link commandAnswersApprovals}). A surface that
|
|
536
|
+
* drains nothing gets the shell-gate set instead, because a rung-independent set there parks tool
|
|
537
|
+
* calls nobody can reach.
|
|
538
|
+
*/
|
|
539
|
+
export function resolveInterruptToolNames(options) {
|
|
540
|
+
const { gateShell, boundToolNames } = options;
|
|
541
|
+
return collectToolNames(gateShell, boundToolNames, (name) => APPROVAL_RUNGS.some((rung) => isToolGatedAtRung({ toolName: name, rung, gateShell })));
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Shared body of the two resolvers above: the shell first (when gated), then the bound names the
|
|
545
|
+
* caller's predicate selects, in bound order, deduplicated, with nameless entries dropped.
|
|
546
|
+
*/
|
|
547
|
+
function collectToolNames(gateShell, boundToolNames, include) {
|
|
548
|
+
const names = [];
|
|
549
|
+
const seen = new Set();
|
|
550
|
+
const add = (name) => {
|
|
551
|
+
if (typeof name !== 'string' || name.length === 0 || seen.has(name))
|
|
552
|
+
return;
|
|
553
|
+
seen.add(name);
|
|
554
|
+
names.push(name);
|
|
555
|
+
};
|
|
556
|
+
if (gateShell)
|
|
557
|
+
add(SHELL_TOOL_NAME);
|
|
558
|
+
for (const name of boundToolNames) {
|
|
559
|
+
if (typeof name === 'string' && name.length > 0 && include(name))
|
|
560
|
+
add(name);
|
|
561
|
+
}
|
|
562
|
+
return names;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* §4.7 — the four MCP `ToolAnnotations` hint names, and the whole vocabulary. It is the same list
|
|
566
|
+
* on both sides of the design: what a `hint` pattern may name ({@link ApprovalHintPattern}) and what
|
|
567
|
+
* a user may believe from a server ({@link McpServerApprovalsConfig.trustAnnotations}).
|
|
568
|
+
*
|
|
569
|
+
* **The schema twin `HINT_ANNOTATION_KEYS` in `config/schema.ts` is a deliberate duplicate, and the
|
|
570
|
+
* reason is layering, not oversight.** Neither file may import the other. `schema.ts` states in its
|
|
571
|
+
* own header that it must stay pure and cwd/fs-independent because it feeds `z.toJSONSchema()`, and
|
|
572
|
+
* importing this module would pull `core/types.js` and the whole runtime policy surface into it;
|
|
573
|
+
* importing `schema.ts` here would in turn pull zod into every module that only wanted a policy
|
|
574
|
+
* type. So the vocabulary is written once per layer on purpose — do not "simplify" it by making one
|
|
575
|
+
* import the other.
|
|
576
|
+
*
|
|
577
|
+
* What keeps the two honest instead is the equality assertion in `mcpApprovalsBlock.spec.ts`, which
|
|
578
|
+
* fails the moment they drift. Drift matters in one direction especially: a name the config accepts
|
|
579
|
+
* but the derivation never reads fails silently, and it fails toward trusting. Change one list,
|
|
580
|
+
* change the other.
|
|
581
|
+
*/
|
|
582
|
+
export const TOOL_ANNOTATION_HINTS = [
|
|
583
|
+
'readOnlyHint',
|
|
584
|
+
'destructiveHint',
|
|
585
|
+
'idempotentHint',
|
|
586
|
+
'openWorldHint',
|
|
587
|
+
];
|
|
588
|
+
/**
|
|
589
|
+
* §1.1 — **the default rung is `assisted`, everywhere.** It is the default in every interactive
|
|
590
|
+
* context, it does NOT vary with the configured model, and there is no separate non-interactive
|
|
591
|
+
* default. What changes without a human is what an escalation *does* (§6.2: an immediate non-zero
|
|
592
|
+
* exit, never an approval), not which rung the session starts on. A context-dependent default
|
|
593
|
+
* would reintroduce exactly the hidden branching this ladder exists to remove.
|
|
594
|
+
*/
|
|
595
|
+
export const DEFAULT_APPROVAL_RUNG = 'assisted';
|
|
596
|
+
/** Normalize the scalar/object union to the object form. The scalar is sugar for `{ mode }`. */
|
|
597
|
+
function toApprovalsObject(raw) {
|
|
598
|
+
if (raw === undefined)
|
|
599
|
+
return undefined;
|
|
600
|
+
if (typeof raw === 'string')
|
|
601
|
+
return { mode: raw };
|
|
602
|
+
return raw;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* CFG-27 — resolve the effective {@link ResolvedApprovals} for the active command.
|
|
606
|
+
*
|
|
607
|
+
* There is no defaults *matrix*: §1.1 makes `assisted` the default in every context, so this
|
|
608
|
+
* resolver neither detects nor accepts a "context". Precedence is the only thing it decides, and
|
|
609
|
+
* §9.1 splits it in two:
|
|
610
|
+
*
|
|
611
|
+
* - **The scalars — `mode`, `rater`, `raterTimeoutMs` — are replaced** when the per-command value
|
|
612
|
+
* states them and **inherited from the root when it does not**. So the scalar sugar
|
|
613
|
+
* `"code": { "approvals": "bypass" }` is exactly `{ mode: 'bypass' }` merged over the root: it
|
|
614
|
+
* sets the rung and nothing else.
|
|
615
|
+
* - **`deny` and `escalate` never replace: they CONCATENATE across every scope.** A
|
|
616
|
+
* command-specific `deny` *adds to* the root's. Removing an inherited prohibition for one command
|
|
617
|
+
* is deliberately not expressible.
|
|
618
|
+
* - **`allow` is REPLACED when the per-command value states its own, and inherited when it does
|
|
619
|
+
* not.** A per-command scope may therefore narrow what runs unprompted, and may never widen what
|
|
620
|
+
* is prohibited.
|
|
621
|
+
* - **`mcp` (EXT-70 §4.7) follows `allow`, not the restrictive lists**: replaced when the
|
|
622
|
+
* per-command value states it, inherited when it does not. Believing a hint is a PERMISSIVE act
|
|
623
|
+
* in both directions — it can make an `allow` hint entry fire and can make a `deny` hint entry
|
|
624
|
+
* stop firing — so it merges the way the permissive list does, and a per-command scope can
|
|
625
|
+
* narrow the session's trust (`"mcp": {}` believes nothing) but never inherits half of it by
|
|
626
|
+
* accident. Deep-merging the two scopes' `servers` maps was rejected for the same reason: it
|
|
627
|
+
* would leave a deliberately distrustful per-command block silently carrying the root's trust.
|
|
628
|
+
*
|
|
629
|
+
* **The two halves differ because the costs differ (§3.1), not for tidiness.** A missed allow entry
|
|
630
|
+
* escalates and a missed deny entry falls through to the rater — neither is an execution — while a
|
|
631
|
+
* too-broad allow entry *runs, unrated and unprompted*. Concatenating the restrictive lists fails
|
|
632
|
+
* toward a prompt; concatenating the permissive one fails toward an execution, and would leave a
|
|
633
|
+
* deliberately restrictive per-command rung with no way to shed the root's standing grants. Do not
|
|
634
|
+
* "regularize" these three into one policy: the direction each list fails in is the whole design.
|
|
635
|
+
*
|
|
636
|
+
* On the restrictive side the pressure runs the other way (§11.1f). Were the per-command value to
|
|
637
|
+
* replace the root wholesale, the friendliest spelling of "stop asking me about `code`" would also
|
|
638
|
+
* delete every `deny` entry — at the one rung where the deny list and the §8 floor are the only
|
|
639
|
+
* checks left. A prohibition a nested config key can quietly delete is not a hardline.
|
|
640
|
+
*
|
|
641
|
+
* Concatenation order cannot change any outcome (`resolveApprovalRules` consults every deny entry
|
|
642
|
+
* before any escalate entry and every escalate entry before any allow entry), so root-first is a
|
|
643
|
+
* convention for readability — matching `GthAgentRunner.approvalRuleLists`, where the declared
|
|
644
|
+
* entries precede the runtime grants — and never a precedence.
|
|
645
|
+
*
|
|
646
|
+
* Defaults are applied HERE, at the read site, rather than in `DEFAULT_CONFIG` — so the
|
|
647
|
+
* effective-config snapshot the `/config` panel renders never churns (à la GS2-34
|
|
648
|
+
* `injectModelContext` / GS2-63 `output.header`).
|
|
649
|
+
*
|
|
650
|
+
* This is the per-command half. The cross-LAYER half (a project config's lists adding to a global
|
|
651
|
+
* config's rather than replacing them) is the additive-array policy in `config/loader.ts`; both are
|
|
652
|
+
* needed, since either alone still loses a list silently.
|
|
653
|
+
*
|
|
654
|
+
* @param command The active command; selects the per-command block.
|
|
655
|
+
*/
|
|
656
|
+
export function resolveApprovals(config, command) {
|
|
657
|
+
const root = toApprovalsObject(config?.approvals);
|
|
658
|
+
const perCommand = toApprovalsObject(command
|
|
659
|
+
? config?.commands?.[command]
|
|
660
|
+
?.approvals
|
|
661
|
+
: undefined);
|
|
662
|
+
return {
|
|
663
|
+
rung: perCommand?.mode ?? root?.mode ?? DEFAULT_APPROVAL_RUNG,
|
|
664
|
+
rater: perCommand?.rater ?? root?.rater,
|
|
665
|
+
// `??`, so an EXPLICIT empty list is honoured: `allow: []` on a command states "nothing is
|
|
666
|
+
// pre-trusted here" and must not read as "said nothing, inherit the root's".
|
|
667
|
+
allow: perCommand?.allow ?? root?.allow ?? [],
|
|
668
|
+
deny: [...(root?.deny ?? []), ...(perCommand?.deny ?? [])],
|
|
669
|
+
escalate: [...(root?.escalate ?? []), ...(perCommand?.escalate ?? [])],
|
|
670
|
+
raterTimeoutMs: perCommand?.raterTimeoutMs ?? root?.raterTimeoutMs,
|
|
671
|
+
// `??`, so an EXPLICIT empty block is honoured exactly as an explicit empty `allow` is: it
|
|
672
|
+
// states "believe nothing external here" and must not read as "said nothing, inherit the root".
|
|
673
|
+
mcp: perCommand?.mcp ?? root?.mcp,
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* EXT-52 — the ONE shell approval-gate policy both agent backends resolve
|
|
678
|
+
* (`GthLangChainAgent` = lean/default, `GthDeepAgent` = deep). It decides whether the opt-in
|
|
679
|
+
* `run_shell_command` tool is gated behind the per-command approval interrupt, and which status
|
|
680
|
+
* notice (if any) the backend should surface. The backends differ only in HOW they install the
|
|
681
|
+
* interrupt; the policy and its user-facing copy live here so the two can never drift (and so a
|
|
682
|
+
* later rename of this config surface has one place to change).
|
|
683
|
+
*
|
|
684
|
+
* CFG-27 — **the tool is gated whenever it is enabled, at every rung including `bypass`.** CFG-26
|
|
685
|
+
* used to leave it UNGATED under `bypass` outside interactive `code`, which the ladder cannot
|
|
686
|
+
* afford: §2.5 makes the declared **deny list the one check `bypass` keeps**, and a deny entry can
|
|
687
|
+
* only fire if the call reaches `GthAgentRunner.decideToolApproval` — an ungated call never does.
|
|
688
|
+
* Gating unconditionally also keeps the rung switchable mid-session (`/approvals <rung>`), since a
|
|
689
|
+
* tool wired without the interrupt cannot be re-gated without rebuilding the agent.
|
|
690
|
+
*
|
|
691
|
+
* What each rung then does is decided in `decideToolApproval`, not here:
|
|
692
|
+
* • `bypass` — deny list, then approve without prompting or rating.
|
|
693
|
+
* • `manual`/`write` — deny list, allow-list, else escalate to the human.
|
|
694
|
+
* • `assisted`/`auto` — deny list, allow-list, then the rater.
|
|
695
|
+
*
|
|
696
|
+
* **This decides the SHELL's gating only, and it is not the whole gated set.** With the shell tool
|
|
697
|
+
* disabled — or on a non-dev-tools command (chat/api/…) — nothing about the shell is gated and
|
|
698
|
+
* nothing is announced, but at `manual` and `write` {@link resolveGatedToolNames} still gates
|
|
699
|
+
* every bound tool the rung does not auto-grant, so an MCP call in a plain `chat` session is
|
|
700
|
+
* escalated there. Read `gateShell` as "does the shell need the interrupt", never as "is the
|
|
701
|
+
* interrupt needed at all".
|
|
702
|
+
*
|
|
703
|
+
* Shell enablement itself is resolved through {@link getEffectiveDevToolsConfig} +
|
|
704
|
+
* {@link isShellToolEnabled}, so the gate stays in lockstep with where `GthDevToolkit` actually
|
|
705
|
+
* emits the tool; the posture comes from {@link resolveApprovals}, so this and the runner can
|
|
706
|
+
* never disagree about which rung is in force.
|
|
707
|
+
*/
|
|
708
|
+
export function resolveShellApprovalGate(config, command) {
|
|
709
|
+
const devTools = getEffectiveDevToolsConfig(config, command);
|
|
710
|
+
const gateShell = isShellToolEnabled(devTools, command);
|
|
711
|
+
if (!gateShell)
|
|
712
|
+
return { gateShell };
|
|
713
|
+
const { rung } = resolveApprovals(config, command);
|
|
714
|
+
if (rung === 'bypass') {
|
|
715
|
+
return {
|
|
716
|
+
gateShell,
|
|
717
|
+
notice: {
|
|
718
|
+
level: StatusLevel.WARNING,
|
|
719
|
+
message: 'Shell tool (run_shell_command): commands run without asking and without rating ' +
|
|
720
|
+
'(approvals: bypass). Only your deny list still applies — type /approvals assisted to ' +
|
|
721
|
+
'rate commands again.',
|
|
722
|
+
},
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
if (isRatedRung(rung)) {
|
|
726
|
+
// **Both rated modes get the SAME tail, because it is true of both and it is all this line
|
|
727
|
+
// promises**: nothing the rater does not clear simply runs. They reach it differently — at
|
|
728
|
+
// `assisted` an unsafe-looking command goes to the human, at `auto` ([[EXT-29]] §5) it is
|
|
729
|
+
// refused back to the agent first and reaches the human when a bound is spent — and at `auto`
|
|
730
|
+
// both halves happen within one session, so a per-mode tail could only pick one of them. This
|
|
731
|
+
// is the startup notice a user meets while working out what their config does; the mode's own
|
|
732
|
+
// description ({@link APPROVAL_RUNG_DESCRIPTIONS}) is where the difference is stated.
|
|
733
|
+
return {
|
|
734
|
+
gateShell,
|
|
735
|
+
notice: {
|
|
736
|
+
level: StatusLevel.INFO,
|
|
737
|
+
message: `Shell tool (run_shell_command) rated by the auto-rater (approvals: ${rung}); ` +
|
|
738
|
+
'anything it does not rate safe is still refused or escalated to you.',
|
|
739
|
+
},
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
return {
|
|
743
|
+
gateShell,
|
|
744
|
+
notice: {
|
|
745
|
+
level: StatusLevel.INFO,
|
|
746
|
+
message: `Shell tool (run_shell_command) enabled with per-command approval (approvals: ${rung}).`,
|
|
747
|
+
},
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
//# sourceMappingURL=shell-policy.js.map
|