@gaunt-sloth/core 2.0.0-alpha.24 → 2.0.0-alpha.26

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.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/dist/config/colour.d.ts +38 -0
  3. package/dist/config/colour.js +36 -0
  4. package/dist/config/colour.js.map +1 -0
  5. package/dist/config/defaults.d.ts +1 -0
  6. package/dist/config/defaults.js +1 -0
  7. package/dist/config/defaults.js.map +1 -1
  8. package/dist/config/loader.d.ts +13 -6
  9. package/dist/config/loader.js +171 -28
  10. package/dist/config/loader.js.map +1 -1
  11. package/dist/config/mouse.d.ts +50 -0
  12. package/dist/config/mouse.js +44 -0
  13. package/dist/config/mouse.js.map +1 -0
  14. package/dist/config/schema.d.ts +2372 -114
  15. package/dist/config/schema.js +845 -16
  16. package/dist/config/schema.js.map +1 -1
  17. package/dist/config/shell-policy.d.ts +466 -116
  18. package/dist/config/shell-policy.js +273 -62
  19. package/dist/config/shell-policy.js.map +1 -1
  20. package/dist/config/tool-descriptions.d.ts +165 -0
  21. package/dist/config/tool-descriptions.js +229 -0
  22. package/dist/config/tool-descriptions.js.map +1 -0
  23. package/dist/config/types.d.ts +36 -1
  24. package/dist/config/types.js.map +1 -1
  25. package/dist/config.d.ts +3 -0
  26. package/dist/config.js +3 -0
  27. package/dist/config.js.map +1 -1
  28. package/dist/core/GthAbstractAgent.d.ts +59 -1
  29. package/dist/core/GthAbstractAgent.js +72 -0
  30. package/dist/core/GthAbstractAgent.js.map +1 -1
  31. package/dist/core/GthAgentRunner.d.ts +341 -58
  32. package/dist/core/GthAgentRunner.js +817 -149
  33. package/dist/core/GthAgentRunner.js.map +1 -1
  34. package/dist/core/GthLangChainAgent.d.ts +16 -0
  35. package/dist/core/GthLangChainAgent.js +72 -2
  36. package/dist/core/GthLangChainAgent.js.map +1 -1
  37. package/dist/core/approvals/annotations.d.ts +122 -0
  38. package/dist/core/approvals/annotations.js +137 -0
  39. package/dist/core/approvals/annotations.js.map +1 -0
  40. package/dist/core/approvals/grants.d.ts +216 -0
  41. package/dist/core/approvals/grants.js +469 -0
  42. package/dist/core/approvals/grants.js.map +1 -0
  43. package/dist/core/approvals/matcher.d.ts +202 -0
  44. package/dist/core/approvals/matcher.js +267 -0
  45. package/dist/core/approvals/matcher.js.map +1 -0
  46. package/dist/core/approvals/mcpSubjects.d.ts +40 -0
  47. package/dist/core/approvals/mcpSubjects.js +99 -0
  48. package/dist/core/approvals/mcpSubjects.js.map +1 -0
  49. package/dist/core/approvals/toolAnnotationSources.d.ts +105 -0
  50. package/dist/core/approvals/toolAnnotationSources.js +277 -0
  51. package/dist/core/approvals/toolAnnotationSources.js.map +1 -0
  52. package/dist/core/approvals/toolHost.d.ts +46 -0
  53. package/dist/core/approvals/toolHost.js +108 -0
  54. package/dist/core/approvals/toolHost.js.map +1 -0
  55. package/dist/core/launchBanner.d.ts +120 -0
  56. package/dist/core/launchBanner.js +399 -0
  57. package/dist/core/launchBanner.js.map +1 -0
  58. package/dist/core/plainToolIndication.js +13 -7
  59. package/dist/core/plainToolIndication.js.map +1 -1
  60. package/dist/core/shell/approvalStop.d.ts +75 -0
  61. package/dist/core/shell/approvalStop.js +108 -0
  62. package/dist/core/shell/approvalStop.js.map +1 -0
  63. package/dist/core/shell/arity.d.ts +6 -0
  64. package/dist/core/shell/arity.js +20 -6
  65. package/dist/core/shell/arity.js.map +1 -1
  66. package/dist/core/shell/denylist.d.ts +11 -0
  67. package/dist/core/shell/denylist.js +37 -0
  68. package/dist/core/shell/denylist.js.map +1 -0
  69. package/dist/core/shell/normalize.d.ts +41 -1
  70. package/dist/core/shell/normalize.js +58 -4
  71. package/dist/core/shell/normalize.js.map +1 -1
  72. package/dist/core/shell/openWorld.d.ts +138 -0
  73. package/dist/core/shell/openWorld.js +523 -0
  74. package/dist/core/shell/openWorld.js.map +1 -0
  75. package/dist/core/shell/rater.d.ts +560 -0
  76. package/dist/core/shell/rater.js +895 -0
  77. package/dist/core/shell/rater.js.map +1 -0
  78. package/dist/core/shell/raterModel.d.ts +41 -0
  79. package/dist/core/shell/raterModel.js +51 -0
  80. package/dist/core/shell/raterModel.js.map +1 -0
  81. package/dist/core/shell/rejection.d.ts +66 -0
  82. package/dist/core/shell/rejection.js +38 -0
  83. package/dist/core/shell/rejection.js.map +1 -0
  84. package/dist/core/types.d.ts +71 -9
  85. package/dist/core/types.js.map +1 -1
  86. package/dist/runtime/askStructured.d.ts +8 -7
  87. package/dist/runtime/askStructured.js +8 -7
  88. package/dist/runtime/askStructured.js.map +1 -1
  89. package/dist/runtime/conversation.js +89 -76
  90. package/dist/runtime/conversation.js.map +1 -1
  91. package/dist/runtime/singleShot.js +71 -60
  92. package/dist/runtime/singleShot.js.map +1 -1
  93. package/dist/utils/ProgressIndicator.d.ts +21 -0
  94. package/dist/utils/ProgressIndicator.js +30 -3
  95. package/dist/utils/ProgressIndicator.js.map +1 -1
  96. package/dist/utils/consoleUtils.d.ts +30 -0
  97. package/dist/utils/consoleUtils.js +27 -2
  98. package/dist/utils/consoleUtils.js.map +1 -1
  99. package/dist/utils/systemUtils.d.ts +17 -0
  100. package/dist/utils/systemUtils.js +17 -0
  101. package/dist/utils/systemUtils.js.map +1 -1
  102. package/package.json +5 -2
  103. package/schema/gsloth-config.schema.json +1216 -417
  104. package/dist/core/shell/allowlist.d.ts +0 -75
  105. package/dist/core/shell/allowlist.js +0 -187
  106. package/dist/core/shell/allowlist.js.map +0 -1
  107. package/dist/core/shell/judge.d.ts +0 -161
  108. package/dist/core/shell/judge.js +0 -261
  109. package/dist/core/shell/judge.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rater.js","sourceRoot":"","sources":["../../../src/core/shell/rater.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,CAAC,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,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IACpD,CAAC;IAED,6FAA6F;IAC7F,2FAA2F;IAC3F,4FAA4F;IAC5F,yFAAyF;IACzF,6FAA6F;IAC7F,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAAuC;IAEvC,MAAM,SAAS,GAAuB,OAAO,IAAI,mBAAmB,CAAC;IACrE,IAAI,SAAS,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAClF,IAAI,SAAS,CAAC,OAAO,KAAK,cAAc;QAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAC5F,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @module core/shell/raterModel
3
+ *
4
+ * CFG-26 — resolve the model the AI rater rates with when `approvals.rater.profile` names an
5
+ * identity profile. Without this the profile is validated and then IGNORED: the config parses,
6
+ * `gth config validate` passes, CFG-24's first-run dialog promises "set a stronger model as the
7
+ * rater later via approvals.rater.profile" — and the runtime quietly rates with the main model.
8
+ *
9
+ * Why it matters concretely (QA-5 rater baseline, 2026-07-26): rating quality varies enormously by
10
+ * model. A local `gemma4:12b` scored 61.7% tier accuracy; `llama3.2:1b` scored 25.5% and rated
11
+ * EVERY safe command `danger`. Pointing the rater at a competent model is the difference between
12
+ * `auto` being useful and being `ask` with a bill attached — so the knob has to actually work.
13
+ *
14
+ * Kept in its own module (rather than inline in {@link GthAgentRunner}) for two reasons: the
15
+ * runner's specs can mock THIS seam instead of the whole `#src/config.js` barrel, and the
16
+ * global-state discipline below lives in exactly one place.
17
+ */
18
+ import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
19
+ /**
20
+ * Load the identity profile named by `approvals.rater.profile` and return ITS model.
21
+ *
22
+ * Strict, per [[GS2-62]]: a profile that cannot be loaded, or that resolves to a config with no
23
+ * usable model, is an ERROR — never a silent fallback to the session's main model. A silent
24
+ * fallback is precisely the failure this function exists to remove (the user asked for a stronger
25
+ * rater and would have been given the weak one, with nothing said). The profile's EXISTENCE is
26
+ * already validated at config-load time by the loader (and by `gth config validate`); this is the
27
+ * later, separate question of whether it yields a usable model.
28
+ *
29
+ * **Global-state discipline.** `initConfig` re-runs project discovery and calls
30
+ * `setProjectDir(discovered?.dir)` as a side effect. That is correct for the SESSION's config load
31
+ * but wrong for this subsidiary one: a rater sub-config must never re-root the session. Because
32
+ * this call passes no `customConfigPath`, discovery re-walks from cwd and can legitimately land on
33
+ * a different dir than the session did (e.g. a session started with `-c <path>`), which would then
34
+ * silently repoint every `getProjectDir()` consumer — prompt files, output paths, the shell
35
+ * allow-list file, debug dumps. So the project dir is snapshotted and restored in a `finally`.
36
+ *
37
+ * @param profile The identity profile name from `approvals.rater.profile`.
38
+ * @returns The profile's chat model, ready to be handed to `rateShellCommand`'s `model` option.
39
+ * @throws When the profile's config cannot be loaded or carries no usable model.
40
+ */
41
+ export declare function resolveRaterModel(profile: string): Promise<BaseChatModel>;
@@ -0,0 +1,51 @@
1
+ import { initConfig } from '#src/config/loader.js';
2
+ import { peekProjectDir, setProjectDir } from '#src/utils/systemUtils.js';
3
+ /**
4
+ * Load the identity profile named by `approvals.rater.profile` and return ITS model.
5
+ *
6
+ * Strict, per [[GS2-62]]: a profile that cannot be loaded, or that resolves to a config with no
7
+ * usable model, is an ERROR — never a silent fallback to the session's main model. A silent
8
+ * fallback is precisely the failure this function exists to remove (the user asked for a stronger
9
+ * rater and would have been given the weak one, with nothing said). The profile's EXISTENCE is
10
+ * already validated at config-load time by the loader (and by `gth config validate`); this is the
11
+ * later, separate question of whether it yields a usable model.
12
+ *
13
+ * **Global-state discipline.** `initConfig` re-runs project discovery and calls
14
+ * `setProjectDir(discovered?.dir)` as a side effect. That is correct for the SESSION's config load
15
+ * but wrong for this subsidiary one: a rater sub-config must never re-root the session. Because
16
+ * this call passes no `customConfigPath`, discovery re-walks from cwd and can legitimately land on
17
+ * a different dir than the session did (e.g. a session started with `-c <path>`), which would then
18
+ * silently repoint every `getProjectDir()` consumer — prompt files, output paths, the shell
19
+ * allow-list file, debug dumps. So the project dir is snapshotted and restored in a `finally`.
20
+ *
21
+ * @param profile The identity profile name from `approvals.rater.profile`.
22
+ * @returns The profile's chat model, ready to be handed to `rateShellCommand`'s `model` option.
23
+ * @throws When the profile's config cannot be loaded or carries no usable model.
24
+ */
25
+ export async function resolveRaterModel(profile) {
26
+ // Snapshot BEFORE initConfig's discovery mutates it (see the note above). `peekProjectDir`
27
+ // rather than `getProjectDir` so an UNSET dir is restored as unset, not pinned to today's cwd.
28
+ const projectDirBefore = peekProjectDir();
29
+ let raterConfig;
30
+ try {
31
+ raterConfig = await initConfig({ identityProfile: profile });
32
+ }
33
+ catch (error) {
34
+ throw new Error(`Could not load the AI rater profile "${profile}" named by approvals.rater.profile: ` +
35
+ `${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? { cause: error } : undefined);
36
+ }
37
+ finally {
38
+ setProjectDir(projectDirBefore);
39
+ }
40
+ const model = raterConfig?.llm;
41
+ // Guard explicitly rather than returning `undefined`: `rateShellCommand` falls back to
42
+ // `config.llm` when its `model` option is undefined, so handing it undefined here would
43
+ // reintroduce the very silent fallback this module removes.
44
+ if (!model || typeof model.withStructuredOutput !== 'function') {
45
+ throw new Error(`The AI rater profile "${profile}" resolved to a config with no usable model. ` +
46
+ 'Give that profile a valid `llm`, or remove approvals.rater.profile to rate with the ' +
47
+ 'session model.');
48
+ }
49
+ return model;
50
+ }
51
+ //# sourceMappingURL=raterModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raterModel.js","source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the model is told when a gated tool call is refused.**
5
+ *
6
+ * A rejection returned to the model MUST name the moves available to it, not merely the refusal.
7
+ * The pre-EXT-58 message was the bare string *"User rejected the shell command."*, which tells the
8
+ * model it failed and nothing about what to do instead — so it either re-runs the identical call or
9
+ * abandons a legitimate task silently. §7 fixes both ends: state the refusal, carry the explanation
10
+ * when one exists, and name the three moves (re-call with a justification, call a different
11
+ * command, ask the user).
12
+ *
13
+ * When the rater named an already-granted alternative (§4.4), the message MUST carry it **and** say
14
+ * that the alternative needs no approval. That last clause is the sentence that actually redirects
15
+ * behaviour: without it the model reads a tool name and still has no reason to believe calling it
16
+ * is cheaper than arguing about the command it already chose.
17
+ *
18
+ * What this module deliberately does NOT do:
19
+ *
20
+ * - It does not decide anything. It renders a refusal that has already been decided elsewhere; a
21
+ * suggestion it carries is never an approval and changes no outcome (§4.4).
22
+ * - It does not serve a **halt** (§4.2). A halt is not a rejection and offers the model no moves,
23
+ * so it is an error (`AttackHaltError`) rather than a message — see `approvalStop.ts`.
24
+ * - It does not serve a **deny-list** refusal. A deny entry is the user's own hardline, and
25
+ * "re-call the same command with a justification" is not a move the model has there; that message
26
+ * stays as it is, in `GthAgentRunner.decideToolApproval`.
27
+ */
28
+ import type { ShellSafetyVerdict } from '#src/core/shell/rater.js';
29
+ /** Who refused the call — the opening sentence differs, the moves do not. */
30
+ export type RejectionSource =
31
+ /** The human answered "no" at the escalation prompt (§6). */
32
+ 'user'
33
+ /** The auto-rater refused during a negotiation (§5 / [[EXT-29]]). */
34
+ | 'rater';
35
+ /** The three moves §7 requires every rejection to name. */
36
+ export declare const REJECTION_MOVES: string;
37
+ /**
38
+ * §7 — the clause that makes a suggestion actionable. Verbatim in substance from the spec:
39
+ * *"`gth_edit_file` does this and is already approved at this level, so it will not interrupt the
40
+ * user."*
41
+ */
42
+ export declare function buildGrantedAlternativeClause(toolName: string): string;
43
+ /** Inputs to {@link buildRejectionMessage}. */
44
+ export interface RejectionMessageOptions {
45
+ /** Who refused. */
46
+ source: RejectionSource;
47
+ /** The tool that was refused; defaults to a generic phrasing when absent. */
48
+ toolName?: string;
49
+ /**
50
+ * The rating that accompanied the escalation, when one exists. Carries both the explanation the
51
+ * model is owed and — when the rater named one — the granted alternative (§4.4). Absent at the
52
+ * unrated rungs (`read-only`, `write`), where there is no rating at all and the descriptions of
53
+ * §4.5 are the only mechanism in play.
54
+ */
55
+ verdict?: ShellSafetyVerdict;
56
+ }
57
+ /**
58
+ * Build the §7 rejection message handed back to the model as the refused call's tool result.
59
+ *
60
+ * Shape (each part omitted when it does not apply):
61
+ * 1. who refused what;
62
+ * 2. the rater's explanation, when a rating exists;
63
+ * 3. the three moves — always;
64
+ * 4. the granted alternative plus the no-approval-needed clause, when the rater named one.
65
+ */
66
+ export declare function buildRejectionMessage(options: RejectionMessageOptions): string;
@@ -0,0 +1,38 @@
1
+ /** The three moves §7 requires every rejection to name. */
2
+ export const REJECTION_MOVES = 'You may call the same command with a justification, call a different command, or ask the user ' +
3
+ 'if there is no way around it.';
4
+ /**
5
+ * §7 — the clause that makes a suggestion actionable. Verbatim in substance from the spec:
6
+ * *"`gth_edit_file` does this and is already approved at this level, so it will not interrupt the
7
+ * user."*
8
+ */
9
+ export function buildGrantedAlternativeClause(toolName) {
10
+ return `\`${toolName}\` does this and is already approved at this level, so it will not interrupt the user.`;
11
+ }
12
+ /**
13
+ * Build the §7 rejection message handed back to the model as the refused call's tool result.
14
+ *
15
+ * Shape (each part omitted when it does not apply):
16
+ * 1. who refused what;
17
+ * 2. the rater's explanation, when a rating exists;
18
+ * 3. the three moves — always;
19
+ * 4. the granted alternative plus the no-approval-needed clause, when the rater named one.
20
+ */
21
+ export function buildRejectionMessage(options) {
22
+ const target = options.toolName ? `your call to ${options.toolName}` : 'your command';
23
+ const opener = options.source === 'rater'
24
+ ? `The auto-rater rejected ${target}.`
25
+ : `The user rejected ${target}.`;
26
+ const parts = [opener];
27
+ const reason = options.verdict?.reason?.trim();
28
+ if (reason) {
29
+ parts.push(`Explanation: ${reason}`);
30
+ }
31
+ parts.push(REJECTION_MOVES);
32
+ const suggested = options.verdict?.suggestedTool?.trim();
33
+ if (suggested) {
34
+ parts.push(buildGrantedAlternativeClause(suggested));
35
+ }
36
+ return parts.join(' ');
37
+ }
38
+ //# sourceMappingURL=rejection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rejection.js","sourceRoot":"","sources":["../../../src/core/shell/rejection.ts"],"names":[],"mappings":"AAoCA,2DAA2D;AAC3D,MAAM,CAAC,MAAM,eAAe,GAC1B,gGAAgG;IAChG,+BAA+B,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,6BAA6B,CAAC,QAAgB;IAC5D,OAAO,KAAK,QAAQ,wFAAwF,CAAC;AAC/G,CAAC;AAiBD;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgC;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;IACtF,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,KAAK,OAAO;QACxB,CAAC,CAAC,2BAA2B,MAAM,GAAG;QACtC,CAAC,CAAC,qBAAqB,MAAM,GAAG,CAAC;IAErC,MAAM,KAAK,GAAa,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC/C,IAAI,MAAM,EAAE,CAAC;QACX,KAAK,CAAC,IAAI,CAAC,gBAAgB,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IACzD,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,SAAS,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type { GthConfig } from '#src/config.js';
2
- import type { ShellSafetyVerdict } from '#src/core/shell/judge.js';
2
+ import type { DeclaredToolAnnotations } from '#src/core/approvals/annotations.js';
3
+ import type { ShellSafetyVerdict } from '#src/core/shell/rater.js';
3
4
  import type { BaseMessage } from '@langchain/core/messages';
4
5
  import type { RunnableConfig } from '@langchain/core/runnables';
5
6
  import type { StructuredToolInterface } from '@langchain/core/tools';
@@ -158,19 +159,60 @@ export interface PendingToolInterrupt {
158
159
  name: string;
159
160
  args: Record<string, unknown>;
160
161
  /**
161
- * EXT-10 — when the LLM-as-judge safety gate escalated this `run_shell_command` to the human
162
- * (rather than auto-approving it), the judge's verdict is attached here so the approval surface
163
- * can show a "safety judge flagged: <reason>" notice. Absent when the judge is disabled (the
164
- * default) or when the command reached the human without going through the judge.
162
+ * CFG-26 — when the AI rater escalated this `run_shell_command` to the human (rather than
163
+ * approving it or bouncing it back to the model), the rater's verdict is attached here so the
164
+ * approval surface can show an "AI rater (<tier>): <reason>" notice. Absent when the rater is
165
+ * off, or when the command reached the human without being rated.
165
166
  */
166
167
  safetyVerdict?: ShellSafetyVerdict;
168
+ /**
169
+ * EXT-71 §3.2 — when this call reached the human because a declared `approvals.escalate` entry
170
+ * matched it, the entry that fired, rendered for display. It is the provenance the prompt shows:
171
+ * an escalation the user cannot trace to the line they wrote reads as the gate malfunctioning.
172
+ * Absent whenever the escalation came from the rung or the rater instead.
173
+ */
174
+ escalatedBy?: string;
175
+ /**
176
+ * EXT-71 §6 — **what a sticky choice will store**, rendered in the object form the user would
177
+ * write in a config file, e.g. `{ "type": "shell", "matcher": "exact", "pattern": "npm test" }`.
178
+ * The menu MUST show this at the moment of the choice, on every surface: the user is shown the
179
+ * thing they are agreeing to rather than a generalization of it, which is what makes the display
180
+ * honest and cheap at once.
181
+ *
182
+ * **For a tool call the stored thing is the tool, not the arguments** (§4.7.4), so this reads
183
+ * e.g. `{ "type": "mcpTool", "server": "fetcher", "matcher": "exact", "pattern": "fetch_url",
184
+ * "host": "docs.internal.example" }`. That is the one place a grant is deliberately broader than
185
+ * what the human was shown, which is why the display carries the most weight there.
186
+ *
187
+ * Absent exactly where no sticky grant is on offer — a `catastrophic` outcome (§4.2 withdraws
188
+ * the persistent grants), a rung that remembers nothing, a command that does not statically
189
+ * resolve, or a tool call naming more than one host (which has no honest single-host entry) — so
190
+ * a prompt never advertises a control that has already been withdrawn.
191
+ */
192
+ grantPreview?: string;
193
+ /**
194
+ * §6 — **the same grant in the words a menu control is written in**: `npm test` for a shell
195
+ * command, `tool gth_web_fetch (host docs.internal.example)` or `mcpTool jira/create_issue` for a
196
+ * tool call. It is what the *always approve* control names, so the control reads as
197
+ * *always approve this tool for this host* rather than as a bare key.
198
+ *
199
+ * It is rendered by `describeApprovalEntry` — the one-liner every other provenance message uses,
200
+ * including the §4.7.4 notice that later withdraws the grant. Sharing the renderer is the point:
201
+ * a menu that describes a grant differently from the notice that withdraws it is how a user stops
202
+ * trusting either.
203
+ *
204
+ * Present exactly when {@link grantPreview} is, since both are rendered from the one entry
205
+ * `recordApproval` would write.
206
+ */
207
+ grantSummary?: string;
167
208
  }
168
209
  /**
169
- * Persistence scope for an `approve` decision (EXT-9 Tier-2 allow-list ergonomics):
210
+ * Persistence scope for an `approve` decision (spec §6):
170
211
  * - `once` — run this single invocation only; remember nothing (the default).
171
- * - `session` — remember the command's classified prefix for the life of this runner
172
- * instance, so flag-variants of the same operation auto-approve without re-prompting.
173
- * - `always` — additionally persist the prefix to the project allow-list
212
+ * - `session` — remember **this command**, as an `exact` entry (§3.1), for the life of this runner
213
+ * instance, so the same command stops re-prompting. A longer variant of it still asks: the menu
214
+ * never widens, and breadth is something a human writes in a config file.
215
+ * - `always` — additionally persist that entry to the project store
174
216
  * (`.gsloth/.gsloth-settings/shell-allowlist.json`) so it survives across runs.
175
217
  */
176
218
  export type ToolApprovalScope = 'once' | 'session' | 'always';
@@ -222,6 +264,26 @@ export interface GthAgentInterface {
222
264
  * approve/reject confirmation loop.
223
265
  */
224
266
  getPendingToolInterrupts?(runConfig: RunnableConfig): Promise<PendingToolInterrupt[]>;
267
+ /**
268
+ * EXT-58 (spec §4.4) — the names of the tools registered with the graph at `init`. The runner
269
+ * intersects them with the built-in summaries table to tell the rater which already-granted
270
+ * built-ins it may offer as an alternative, so a suggestion can never name a tool the model does
271
+ * not have. Optional: an agent that does not track its tools simply omits it, and the rater then
272
+ * receives no granted list (and so suggests nothing).
273
+ */
274
+ getRegisteredToolNames?(): string[];
275
+ /**
276
+ * EXT-70 (spec §4.7.1) — what the connected MCP servers declared about their own tools in their
277
+ * `tools/list` responses, keyed by the REGISTERED tool name (`mcp__<server>__<tool>`). The runner
278
+ * reads it as the `mcp` half of a declared-annotation lookup when it computes a call's effective
279
+ * annotation set.
280
+ *
281
+ * These are **claims, not credentials**: nothing here has been trusted, and an entry only becomes
282
+ * load-bearing where the user's `approvals.mcp` block believes that hint from that server.
283
+ * Optional — an agent that tracks no tools omits it, and every tool is then fail-closed, which is
284
+ * exactly what a fully distrustful configuration computes anyway.
285
+ */
286
+ getDeclaredMcpToolAnnotations?(): ReadonlyMap<string, DeclaredToolAnnotations>;
225
287
  /**
226
288
  * GS2-16 — reset the per-run analytics accumulator so the NEXT turn's token/tool totals start
227
289
  * from zero. Called by {@link GthAgentRunner} at each turn boundary (the runner is reused across
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAYA;;;;GAIG;AACH,MAAM,CAAN,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,+CAAS,CAAA;IACT,6CAAQ,CAAA;IACR,mDAAW,CAAA;IACX,mDAAW,CAAA;IACX,mDAAW,CAAA;IACX,+CAAS,CAAA;IACT,iDAAU,CAAA;AACZ,CAAC,EARW,WAAW,KAAX,WAAW,QAQtB"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAaA;;;;GAIG;AACH,MAAM,CAAN,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,+CAAS,CAAA;IACT,6CAAQ,CAAA;IACR,mDAAW,CAAA;IACX,mDAAW,CAAA;IACX,mDAAW,CAAA;IACX,+CAAS,CAAA;IACT,iDAAU,CAAA;AACZ,CAAC,EARW,WAAW,KAAX,WAAW,QAQtB"}
@@ -3,23 +3,24 @@
3
3
  *
4
4
  * A reusable, non-agentic "ask the LLM and get a schema-validated object back" primitive — the
5
5
  * structured-output half the (later) `gth workflow` host calls. Deliberately mirrors the
6
- * *mechanism* of the LLM-as-judge calls ({@link judgeEvalCase} in `@gaunt-sloth/batch`'s
7
- * `judge.ts`, and its in-core ancestor {@link judgeShellCommand} in `core/shell/judge.ts`):
6
+ * *mechanism* of the structured-evaluation calls ({@link judgeEvalCase} — the EVAL GRADER in
7
+ * `@gaunt-sloth/batch`'s `judge.ts` and its in-core sibling {@link rateShellCommand}, the
8
+ * approvals AI rater in `core/shell/rater.ts`):
8
9
  * `model.withStructuredOutput(schema)` for a single structured call, `.invoke([SystemMessage,
9
10
  * HumanMessage])` raced against a wall-clock timeout via `Promise.race`, a defensive `safeParse`
10
11
  * re-validation, `clearTimeout` in `finally`, and — crucially — it **never throws**, returning a
11
12
  * failure object instead.
12
13
  *
13
- * Differences from the judges: this one is **generic** over the Zod schema and takes the
14
- * system/user strings from the caller (the judges hard-code a schema and build a rubric/safety
15
- * prompt), and it reads the model from `config.llm` (like `runSingleShot`/`judgeShellCommand`),
14
+ * Differences from those two: this one is **generic** over the Zod schema and takes the
15
+ * system/user strings from the caller (they hard-code a schema and build a rubric/safety
16
+ * prompt), and it reads the model from `config.llm` (like `runSingleShot`/`rateShellCommand`),
16
17
  * so the workflow host can hand it the resolved {@link GthConfig} directly. `judgeEvalCase` could
17
18
  * later be refactored to delegate to this primitive — out of scope here.
18
19
  */
19
20
  import * as z from 'zod';
20
21
  import type { GthConfig } from '#src/config.js';
21
22
  /**
22
- * Default wall-clock budget (ms) for the structured LLM call — same value as the judges'
23
+ * Default wall-clock budget (ms) for the structured LLM call — same value as their
23
24
  * `EVAL_JUDGE_DEFAULT_TIMEOUT_MS` / `JUDGE_DEFAULT_TIMEOUT_MS`, kept as this module's own constant
24
25
  * since the primitive is conceptually independent of them.
25
26
  */
@@ -47,7 +48,7 @@ export type AskStructuredResult<T> = {
47
48
  };
48
49
  /**
49
50
  * Ask the configured model for a single schema-validated object — a non-agentic structured-output
50
- * call that mirrors the judges' mechanism (see the module doc) and never throws.
51
+ * call that mirrors their mechanism (see the module doc) and never throws.
51
52
  *
52
53
  * - No usable model (`config.llm` missing or lacking `withStructuredOutput`) →
53
54
  * `{ ok: false, error: 'No usable model configured.' }`.
@@ -3,29 +3,30 @@
3
3
  *
4
4
  * A reusable, non-agentic "ask the LLM and get a schema-validated object back" primitive — the
5
5
  * structured-output half the (later) `gth workflow` host calls. Deliberately mirrors the
6
- * *mechanism* of the LLM-as-judge calls ({@link judgeEvalCase} in `@gaunt-sloth/batch`'s
7
- * `judge.ts`, and its in-core ancestor {@link judgeShellCommand} in `core/shell/judge.ts`):
6
+ * *mechanism* of the structured-evaluation calls ({@link judgeEvalCase} — the EVAL GRADER in
7
+ * `@gaunt-sloth/batch`'s `judge.ts` and its in-core sibling {@link rateShellCommand}, the
8
+ * approvals AI rater in `core/shell/rater.ts`):
8
9
  * `model.withStructuredOutput(schema)` for a single structured call, `.invoke([SystemMessage,
9
10
  * HumanMessage])` raced against a wall-clock timeout via `Promise.race`, a defensive `safeParse`
10
11
  * re-validation, `clearTimeout` in `finally`, and — crucially — it **never throws**, returning a
11
12
  * failure object instead.
12
13
  *
13
- * Differences from the judges: this one is **generic** over the Zod schema and takes the
14
- * system/user strings from the caller (the judges hard-code a schema and build a rubric/safety
15
- * prompt), and it reads the model from `config.llm` (like `runSingleShot`/`judgeShellCommand`),
14
+ * Differences from those two: this one is **generic** over the Zod schema and takes the
15
+ * system/user strings from the caller (they hard-code a schema and build a rubric/safety
16
+ * prompt), and it reads the model from `config.llm` (like `runSingleShot`/`rateShellCommand`),
16
17
  * so the workflow host can hand it the resolved {@link GthConfig} directly. `judgeEvalCase` could
17
18
  * later be refactored to delegate to this primitive — out of scope here.
18
19
  */
19
20
  import { HumanMessage, SystemMessage } from '@langchain/core/messages';
20
21
  /**
21
- * Default wall-clock budget (ms) for the structured LLM call — same value as the judges'
22
+ * Default wall-clock budget (ms) for the structured LLM call — same value as their
22
23
  * `EVAL_JUDGE_DEFAULT_TIMEOUT_MS` / `JUDGE_DEFAULT_TIMEOUT_MS`, kept as this module's own constant
23
24
  * since the primitive is conceptually independent of them.
24
25
  */
25
26
  export const ASK_STRUCTURED_DEFAULT_TIMEOUT_MS = 30_000;
26
27
  /**
27
28
  * Ask the configured model for a single schema-validated object — a non-agentic structured-output
28
- * call that mirrors the judges' mechanism (see the module doc) and never throws.
29
+ * call that mirrors their mechanism (see the module doc) and never throws.
29
30
  *
30
31
  * - No usable model (`config.llm` missing or lacking `withStructuredOutput`) →
31
32
  * `{ ok: false, error: 'No usable model configured.' }`.
@@ -1 +1 @@
1
- {"version":3,"file":"askStructured.js","sourceRoot":"","sources":["../../src/runtime/askStructured.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AAmBxD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAoB,EACpB,IAA0B;IAE1B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,iCAAiC,CAAC;IAEtE,MAAM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runConversation(source, _preamble, userMessages, config, resolvers, command = 'ask', agentFactory) {
50
50
  const progressIndicator = config.streamOutput ? undefined : new ProgressIndicator('Thinking.');
51
- // Resolve output path and initialize session logging if enabled (same discipline as runSingleShot;
52
- // a no-op when `writeOutputToFile` is off, as `gth eval` forces it — getCommandOutputFilePath null).
53
- const filePath = getCommandOutputFilePath(config, source);
54
- if (filePath) {
55
- initSessionLogging(filePath, config.streamSessionInferenceLog);
56
- }
57
- // Build the agent + resolve tools ONCE for the whole conversation (the MCP connection / any OAuth /
58
- // the toolset must persist across turns so cross-turn memory is real). Cleaned up once, in finally.
59
- const runner = new GthAgentRunner(defaultStatusCallback, resolvers, agentFactory);
60
- const results = [];
61
- // The accumulated conversation: [user1, ai1, user2, ai2, …]. Each turn replays the whole array
62
- // against a freshly-rotated thread (see the doc block). BATCH-13: NO leading SystemMessage — the
63
- // agent composes the system prompt via `createAgent({ systemPrompt })` (same as runSingleShot);
64
- // seeding a preamble SystemMessage here too made two system messages, which Anthropic rejects.
65
- const messages = [];
66
51
  try {
67
- await runner.init(command, config, new MemorySaver());
68
- for (const userMessage of userMessages) {
69
- // Rotate to a fresh (empty) checkpointer thread so this turn's replay of the full `messages`
70
- // array is the sole history the agent sees — no double-append from a prior turn's checkpoint.
71
- runner.resetThread();
72
- messages.push(new HumanMessage(userMessage));
73
- const startedAt = Date.now();
74
- let answer = '';
75
- let ok = true;
76
- let error;
77
- try {
78
- answer = await runner.processMessages(messages);
79
- // Append this turn's answer so the NEXT turn's replay includes it (cross-turn memory).
80
- messages.push(new AIMessage(answer));
81
- }
82
- catch (err) {
83
- ok = false;
84
- error = err instanceof Error ? err.message : String(err);
85
- displayError(`Failed to get answer: ${error}`);
52
+ // Resolve output path and initialize session logging if enabled (same discipline as
53
+ // runSingleShot; a no-op when `writeOutputToFile` is off, as `gth eval` forces it —
54
+ // getCommandOutputFilePath null).
55
+ const filePath = getCommandOutputFilePath(config, source);
56
+ if (filePath) {
57
+ initSessionLogging(filePath, config.streamSessionInferenceLog);
58
+ }
59
+ // Build the agent + resolve tools ONCE for the whole conversation (the MCP connection / any
60
+ // OAuth / the toolset must persist across turns so cross-turn memory is real). Cleaned up once,
61
+ // in finally.
62
+ const runner = new GthAgentRunner(defaultStatusCallback, resolvers, agentFactory);
63
+ const results = [];
64
+ // The accumulated conversation: [user1, ai1, user2, ai2, …]. Each turn replays the whole array
65
+ // against a freshly-rotated thread (see the doc block). BATCH-13: NO leading SystemMessage — the
66
+ // agent composes the system prompt via `createAgent({ systemPrompt })` (same as runSingleShot);
67
+ // seeding a preamble SystemMessage here too made two system messages, which Anthropic rejects.
68
+ const messages = [];
69
+ try {
70
+ await runner.init(command, config, new MemorySaver());
71
+ for (const userMessage of userMessages) {
72
+ // Rotate to a fresh (empty) checkpointer thread so this turn's replay of the full `messages`
73
+ // array is the sole history the agent sees — no double-append from a prior checkpoint.
74
+ runner.resetThread();
75
+ messages.push(new HumanMessage(userMessage));
76
+ const startedAt = Date.now();
77
+ let answer = '';
78
+ let ok = true;
79
+ let error;
80
+ try {
81
+ answer = await runner.processMessages(messages);
82
+ // Append this turn's answer so the NEXT turn's replay includes it (cross-turn memory).
83
+ messages.push(new AIMessage(answer));
84
+ }
85
+ catch (err) {
86
+ ok = false;
87
+ error = err instanceof Error ? err.message : String(err);
88
+ displayError(`Failed to get answer: ${error}`);
89
+ }
90
+ // GS2-16: read this turn's token/tool delta from the live agent (before cleanup). Fail-soft
91
+ // — analytics must never affect the run. `processMessages` reset the tally at its top, so
92
+ // this is THIS turn's usage, not the conversation's cumulative total.
93
+ let runStats = { tools: [] };
94
+ try {
95
+ const s = runner.getRunStats?.();
96
+ if (s)
97
+ runStats = s;
98
+ }
99
+ catch {
100
+ /* fail-soft */
101
+ }
102
+ // GS2-7 (B20): opt-in, fail-soft per-turn session history. A no-op unless `history.enabled`.
103
+ recordSessionSafe(config, {
104
+ command,
105
+ project: getProjectDir(),
106
+ model: config.modelDisplayName,
107
+ prompt: userMessage,
108
+ response: answer,
109
+ tokensInput: runStats.tokensInput,
110
+ tokensOutput: runStats.tokensOutput,
111
+ tools: runStats.tools.length > 0 ? runStats.tools : undefined,
112
+ durationMs: Date.now() - startedAt,
113
+ });
114
+ results.push({ ok, answer, error, ...runStats });
115
+ // A failed turn breaks the conversation's context — stop rather than run later turns on it.
116
+ if (!ok)
117
+ break;
86
118
  }
87
- // GS2-16: read this turn's token/tool delta from the live agent (before cleanup). Fail-soft —
88
- // analytics must never affect the run. `processMessages` reset the tally at its top, so this is
89
- // THIS turn's usage, not the conversation's cumulative total.
90
- let runStats = { tools: [] };
119
+ }
120
+ finally {
121
+ await runner.cleanup();
122
+ }
123
+ progressIndicator?.stop();
124
+ if (config.writeOutputToFile === false) {
125
+ display('\n'); // something going on in some terminals, they swallow last line of output
126
+ }
127
+ if (filePath) {
91
128
  try {
92
- const s = runner.getRunStats?.();
93
- if (s)
94
- runStats = s;
129
+ flushSessionLog();
130
+ stopSessionLogging();
131
+ displaySuccess(`\n\nThis report can be found in ${filePath}`);
95
132
  }
96
- catch {
97
- /* fail-soft */
133
+ catch (err) {
134
+ displayError(`Failed to write answer to file: ${filePath}`);
135
+ displayError(err instanceof Error ? err.message : String(err));
98
136
  }
99
- // GS2-7 (B20): opt-in, fail-soft per-turn session history. A no-op unless `history.enabled`.
100
- recordSessionSafe(config, {
101
- command,
102
- project: getProjectDir(),
103
- model: config.modelDisplayName,
104
- prompt: userMessage,
105
- response: answer,
106
- tokensInput: runStats.tokensInput,
107
- tokensOutput: runStats.tokensOutput,
108
- tools: runStats.tools.length > 0 ? runStats.tools : undefined,
109
- durationMs: Date.now() - startedAt,
110
- });
111
- results.push({ ok, answer, error, ...runStats });
112
- // A failed turn breaks the conversation's context — stop rather than run later turns on it.
113
- if (!ok)
114
- break;
115
137
  }
138
+ return results;
116
139
  }
117
140
  finally {
118
- await runner.cleanup();
119
- }
120
- progressIndicator?.stop();
121
- if (config.writeOutputToFile === false) {
122
- display('\n'); // something going on in some terminals, they swallow last line of output
123
- }
124
- if (filePath) {
125
- try {
126
- flushSessionLog();
127
- stopSessionLogging();
128
- displaySuccess(`\n\nThis report can be found in ${filePath}`);
129
- }
130
- catch (err) {
131
- displayError(`Failed to write answer to file: ${filePath}`);
132
- displayError(err instanceof Error ? err.message : String(err));
133
- }
141
+ // EXT-53: the indicator owns a 1s setInterval — an active libuv handle that keeps Node's event
142
+ // loop from ever draining, so leaking it hangs the CLI forever after the work is done. The
143
+ // `stop()` above sits where it does for output ordering (before the trailing newline / the
144
+ // "report can be found in …" line); this `finally` guarantees the handle is also released when
145
+ // anything above throws notably `runner.init()`, which has no catch, and `runner.cleanup()`.
146
+ // `stop()` is idempotent, so the normal path's second call is a no-op.
147
+ progressIndicator?.stop();
134
148
  }
135
- return results;
136
149
  }
137
150
  //# sourceMappingURL=conversation.js.map