@gaunt-sloth/core 2.0.0-alpha.27 → 2.0.0-alpha.29

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 (45) hide show
  1. package/README.md +6 -0
  2. package/dist/config/filesystem-tools.d.ts +41 -0
  3. package/dist/config/filesystem-tools.js +56 -0
  4. package/dist/config/filesystem-tools.js.map +1 -0
  5. package/dist/config/loader.d.ts +30 -0
  6. package/dist/config/loader.js +101 -2
  7. package/dist/config/loader.js.map +1 -1
  8. package/dist/config/providerKeys.d.ts +69 -0
  9. package/dist/config/providerKeys.js +69 -0
  10. package/dist/config/providerKeys.js.map +1 -0
  11. package/dist/config/schema.d.ts +1 -0
  12. package/dist/config/schema.js +9 -0
  13. package/dist/config/schema.js.map +1 -1
  14. package/dist/config/types.d.ts +22 -5
  15. package/dist/config/types.js.map +1 -1
  16. package/dist/config.d.ts +6 -0
  17. package/dist/config.js +6 -0
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/GthAbstractAgent.d.ts +1 -19
  20. package/dist/core/GthAbstractAgent.js +13 -65
  21. package/dist/core/GthAbstractAgent.js.map +1 -1
  22. package/dist/core/GthLangChainAgent.js +12 -9
  23. package/dist/core/GthLangChainAgent.js.map +1 -1
  24. package/dist/core/shell/rater.d.ts +11 -1
  25. package/dist/core/shell/rater.js +27 -10
  26. package/dist/core/shell/rater.js.map +1 -1
  27. package/dist/providers/modelDiscovery.d.ts +25 -0
  28. package/dist/providers/modelDiscovery.js +48 -0
  29. package/dist/providers/modelDiscovery.js.map +1 -1
  30. package/dist/providers/openrouter.d.ts +3 -4
  31. package/dist/providers/openrouter.js +15 -30
  32. package/dist/providers/openrouter.js.map +1 -1
  33. package/dist/runtime/askStructured.js +7 -5
  34. package/dist/runtime/askStructured.js.map +1 -1
  35. package/dist/runtime/structuredOutput.d.ts +104 -0
  36. package/dist/runtime/structuredOutput.js +393 -0
  37. package/dist/runtime/structuredOutput.js.map +1 -0
  38. package/dist/utils/llmUtils.d.ts +17 -0
  39. package/dist/utils/llmUtils.js +28 -0
  40. package/dist/utils/llmUtils.js.map +1 -1
  41. package/dist/utils/systemPromptNotes.d.ts +14 -1
  42. package/dist/utils/systemPromptNotes.js +26 -4
  43. package/dist/utils/systemPromptNotes.js.map +1 -1
  44. package/package.json +5 -1
  45. package/schema/gsloth-config.schema.json +3 -0
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module runtime/structuredOutput
3
+ *
4
+ * EXT-88 — the **`withStructuredOutput` boundary**. Every `withStructuredOutput` call in this
5
+ * project goes through {@link structuredOutputBoundary}: `rateShellCommand` (the approvals rater),
6
+ * {@link askStructured} (arbitrary caller schemas, including `gth workflow` scripts) and
7
+ * `@gaunt-sloth/batch`'s eval judge. Review's rating step is deliberately not one of them — it
8
+ * reaches its schema through a bound TOOL, which is a different path with different rules.
9
+ *
10
+ * ## The problem it exists to solve
11
+ *
12
+ * A single Zod object normally does two jobs at once — it is converted into the JSON Schema the
13
+ * provider is sent, and it validates the answer that comes back. Those two jobs want **opposite**
14
+ * things from an optional field, and Zod has only one knob for both:
15
+ *
16
+ * - **On the wire**, OpenAI's strict `json_schema` rule is *"`required` must be supplied and must
17
+ * include every key in `properties`"*. A `.optional()` field is left out of `required`, and the
18
+ * OpenAI API rejects the whole request with `400 Invalid schema for response_format`. Optionality
19
+ * there is spelled as a **nullable type on a required key**, not as an absent key.
20
+ * - **On the way back**, providers do not agree. Some (ChatGroq) rewrite the schema themselves so
21
+ * every property is required-and-nullable, and their models answer `null`. Others (Anthropic,
22
+ * Google GenAI, Ollama) leave the field genuinely optional and their models may simply omit it.
23
+ * Zod's `.optional()` admits `undefined` and **not** `null`, so the first group's answer is
24
+ * rejected by the very schema that asked for it — and the caller sees a parse failure that looks
25
+ * like a bad model rather than a self-contradicting request.
26
+ *
27
+ * ## The shape that satisfies both
28
+ *
29
+ * For every field the caller declared `.optional()`, the boundary sends
30
+ * `inner.nullable().prefault(null)` instead. That one node is the wire/validation twin:
31
+ *
32
+ * - **Wire** — `prefault` does not change the parsed *output* type, so the key lands in `required`
33
+ * and its type is `["string","null"]` / `anyOf: [T, null]`. Strict mode is satisfied, and the
34
+ * model is given a legal way to say "nothing here". Unlike `.default()`, `prefault` emits **no
35
+ * `default` keyword** into the JSON Schema, so nothing extra is added to what the provider sees.
36
+ * - **Validation** — the same node accepts the value, accepts `null`, and accepts the key being
37
+ * **missing** (which is what `prefault` supplies the `null` for). All three arms are needed: the
38
+ * third is what keeps the providers that do *not* hoist working.
39
+ *
40
+ * The `null` never escapes: {@link StructuredOutputBoundary.safeParse} strips it back to the key
41
+ * being **absent** and then validates with the caller's **original** schema, so the parsed type is
42
+ * exactly what the caller declared — an optional string stays `string | undefined` and never
43
+ * becomes `string | null | undefined`.
44
+ *
45
+ * ## Two properties that must not be lost in a "simplification"
46
+ *
47
+ * - **Every `.describe()` survives into the emitted JSON Schema.** The descriptions are the only
48
+ * place the model is told what the fields mean. Expressing the null-to-absent step with
49
+ * `.transform()` on the field is the obvious-looking alternative and it costs the field its
50
+ * description — worse, the conversion OpenAI's path uses refuses to represent a transform at all.
51
+ * Normalization therefore happens in **code**, after the parse, never in the schema.
52
+ * - **A genuinely malformed answer still fails.** This boundary removes a *false* parse failure; it
53
+ * is not a blanket "accept anything". A wrong type in an optional field is still rejected, because
54
+ * the final validation is the caller's own untouched schema. In particular `.catch()` must not be
55
+ * used to express any of this — it would swallow real failures.
56
+ *
57
+ * ## Coverage, and the deliberate limits
58
+ *
59
+ * The rewrite descends through objects, arrays, tuples, records and the single-child wrappers
60
+ * (`nullable`, `readonly`, `default`, `prefault`, `nonoptional`), so an optional nested inside an
61
+ * object inside an array is handled.
62
+ *
63
+ * It deliberately stops at **unions** (including discriminated unions), **intersections**, `lazy`,
64
+ * `map`, `set`, `pipe`/`transform` and `custom`, leaving those subtrees exactly as the caller wrote
65
+ * them, and it leaves a **recursive** schema alone in its entirety. The reason is one rule: the
66
+ * rewrite and the normalization must cover **precisely the same set**. At a union the incoming value
67
+ * gives no reliable answer to *which branch was taken*, so a `null` could not be stripped back out;
68
+ * rewriting there while being unable to normalize would manufacture the very parse failure this
69
+ * module removes. Recursion is refused for the neighbouring reason — a rewrite that stopped at the
70
+ * cycle would make a key required at one depth and optional at the next, which satisfies no
71
+ * provider's strict rule and is harder to reason about than the caller's own schema.
72
+ *
73
+ * An optional inside one of those constructs keeps today's behaviour — correct everywhere it is
74
+ * correct today, and still rejected by OpenAI's strict rule, which is a visible error rather than a
75
+ * silent one.
76
+ */
77
+ import * as z from 'zod';
78
+ /**
79
+ * The two halves of one structured-output call: what to send, and how to read the answer.
80
+ *
81
+ * @typeParam T The caller's own parsed type — unchanged by the boundary.
82
+ */
83
+ export interface StructuredOutputBoundary<T> {
84
+ /**
85
+ * The schema to hand to `model.withStructuredOutput(...)`. Identical (by reference) to the
86
+ * caller's schema when it contains no optional field, so a schema that never had the problem is
87
+ * sent byte-for-byte as it is today.
88
+ */
89
+ wireSchema: z.ZodType<Record<string, unknown>>;
90
+ /**
91
+ * Validate a model answer: normalize every `null` that stands for "no value" back to the key being
92
+ * absent, then validate with the caller's **original** schema. Never throws — a malformed answer
93
+ * comes back as `success: false`, exactly as `schema.safeParse` would.
94
+ */
95
+ safeParse(raw: unknown): z.ZodSafeParseResult<T>;
96
+ }
97
+ /**
98
+ * Build the {@link StructuredOutputBoundary} for a schema — the one entry point every
99
+ * `withStructuredOutput` call in this project goes through. See the module doc for what it does and
100
+ * why.
101
+ *
102
+ * @param schema The caller's schema, used unchanged for the final validation.
103
+ */
104
+ export declare function structuredOutputBoundary<T>(schema: z.ZodType<T>): StructuredOutputBoundary<T>;
@@ -0,0 +1,393 @@
1
+ /**
2
+ * @module runtime/structuredOutput
3
+ *
4
+ * EXT-88 — the **`withStructuredOutput` boundary**. Every `withStructuredOutput` call in this
5
+ * project goes through {@link structuredOutputBoundary}: `rateShellCommand` (the approvals rater),
6
+ * {@link askStructured} (arbitrary caller schemas, including `gth workflow` scripts) and
7
+ * `@gaunt-sloth/batch`'s eval judge. Review's rating step is deliberately not one of them — it
8
+ * reaches its schema through a bound TOOL, which is a different path with different rules.
9
+ *
10
+ * ## The problem it exists to solve
11
+ *
12
+ * A single Zod object normally does two jobs at once — it is converted into the JSON Schema the
13
+ * provider is sent, and it validates the answer that comes back. Those two jobs want **opposite**
14
+ * things from an optional field, and Zod has only one knob for both:
15
+ *
16
+ * - **On the wire**, OpenAI's strict `json_schema` rule is *"`required` must be supplied and must
17
+ * include every key in `properties`"*. A `.optional()` field is left out of `required`, and the
18
+ * OpenAI API rejects the whole request with `400 Invalid schema for response_format`. Optionality
19
+ * there is spelled as a **nullable type on a required key**, not as an absent key.
20
+ * - **On the way back**, providers do not agree. Some (ChatGroq) rewrite the schema themselves so
21
+ * every property is required-and-nullable, and their models answer `null`. Others (Anthropic,
22
+ * Google GenAI, Ollama) leave the field genuinely optional and their models may simply omit it.
23
+ * Zod's `.optional()` admits `undefined` and **not** `null`, so the first group's answer is
24
+ * rejected by the very schema that asked for it — and the caller sees a parse failure that looks
25
+ * like a bad model rather than a self-contradicting request.
26
+ *
27
+ * ## The shape that satisfies both
28
+ *
29
+ * For every field the caller declared `.optional()`, the boundary sends
30
+ * `inner.nullable().prefault(null)` instead. That one node is the wire/validation twin:
31
+ *
32
+ * - **Wire** — `prefault` does not change the parsed *output* type, so the key lands in `required`
33
+ * and its type is `["string","null"]` / `anyOf: [T, null]`. Strict mode is satisfied, and the
34
+ * model is given a legal way to say "nothing here". Unlike `.default()`, `prefault` emits **no
35
+ * `default` keyword** into the JSON Schema, so nothing extra is added to what the provider sees.
36
+ * - **Validation** — the same node accepts the value, accepts `null`, and accepts the key being
37
+ * **missing** (which is what `prefault` supplies the `null` for). All three arms are needed: the
38
+ * third is what keeps the providers that do *not* hoist working.
39
+ *
40
+ * The `null` never escapes: {@link StructuredOutputBoundary.safeParse} strips it back to the key
41
+ * being **absent** and then validates with the caller's **original** schema, so the parsed type is
42
+ * exactly what the caller declared — an optional string stays `string | undefined` and never
43
+ * becomes `string | null | undefined`.
44
+ *
45
+ * ## Two properties that must not be lost in a "simplification"
46
+ *
47
+ * - **Every `.describe()` survives into the emitted JSON Schema.** The descriptions are the only
48
+ * place the model is told what the fields mean. Expressing the null-to-absent step with
49
+ * `.transform()` on the field is the obvious-looking alternative and it costs the field its
50
+ * description — worse, the conversion OpenAI's path uses refuses to represent a transform at all.
51
+ * Normalization therefore happens in **code**, after the parse, never in the schema.
52
+ * - **A genuinely malformed answer still fails.** This boundary removes a *false* parse failure; it
53
+ * is not a blanket "accept anything". A wrong type in an optional field is still rejected, because
54
+ * the final validation is the caller's own untouched schema. In particular `.catch()` must not be
55
+ * used to express any of this — it would swallow real failures.
56
+ *
57
+ * ## Coverage, and the deliberate limits
58
+ *
59
+ * The rewrite descends through objects, arrays, tuples, records and the single-child wrappers
60
+ * (`nullable`, `readonly`, `default`, `prefault`, `nonoptional`), so an optional nested inside an
61
+ * object inside an array is handled.
62
+ *
63
+ * It deliberately stops at **unions** (including discriminated unions), **intersections**, `lazy`,
64
+ * `map`, `set`, `pipe`/`transform` and `custom`, leaving those subtrees exactly as the caller wrote
65
+ * them, and it leaves a **recursive** schema alone in its entirety. The reason is one rule: the
66
+ * rewrite and the normalization must cover **precisely the same set**. At a union the incoming value
67
+ * gives no reliable answer to *which branch was taken*, so a `null` could not be stripped back out;
68
+ * rewriting there while being unable to normalize would manufacture the very parse failure this
69
+ * module removes. Recursion is refused for the neighbouring reason — a rewrite that stopped at the
70
+ * cycle would make a key required at one depth and optional at the next, which satisfies no
71
+ * provider's strict rule and is harder to reason about than the caller's own schema.
72
+ *
73
+ * An optional inside one of those constructs keeps today's behaviour — correct everywhere it is
74
+ * correct today, and still rejected by OpenAI's strict rule, which is a visible error rather than a
75
+ * silent one.
76
+ */
77
+ import * as z from 'zod';
78
+ /**
79
+ * A normalizer's answer for "this key must not be present at all" — distinct from `undefined`,
80
+ * because an object key explicitly set to `undefined` is still an own property and `Object.hasOwn`
81
+ * would report it. Callers must not have to learn a second spelling of "absent".
82
+ */
83
+ const ABSENT = Symbol('structured-output-absent');
84
+ function defOf(schema) {
85
+ return schema._zod.def;
86
+ }
87
+ /**
88
+ * Rebuild `schema` with part of its definition replaced, keeping everything else — the checks
89
+ * (`minItems`, `minimum`, …) and the registered `.describe()` metadata. Built from Zod's own clone
90
+ * rather than by calling `z.object(...)` / `z.array(...)` afresh, because re-constructing would
91
+ * silently drop those constraints from the schema the provider is sent.
92
+ *
93
+ * The metadata is copied through the registry rather than by cloning with Zod's `parent` option.
94
+ * A parent link is how Zod represents "the same schema, re-described", and its JSON-Schema emitter
95
+ * honours that by emitting a **`$ref` to the parent** with the differences as sibling keys. For a
96
+ * rewritten object that is actively wrong: the `$ref` would point at a definition still carrying the
97
+ * ORIGINAL `required` list — the one missing exactly the optional key this module exists to hoist —
98
+ * and `$ref`-with-siblings is not accepted by every provider's strict mode. Copying the metadata
99
+ * leaves the clone an independent schema, which is what it actually is.
100
+ */
101
+ function cloneWith(schema, patch) {
102
+ const next = { ...defOf(schema), ...patch };
103
+ const cloned = z.core.clone(schema, next);
104
+ const meta = z.globalRegistry.get(schema);
105
+ if (meta)
106
+ z.globalRegistry.add(cloned, meta);
107
+ return cloned;
108
+ }
109
+ function isRecord(value) {
110
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
111
+ }
112
+ /**
113
+ * `.optional()` → `inner.nullable().prefault(null)`, plus the normalizer that puts it back.
114
+ *
115
+ * The description is re-stated on the nullable wrapper so it lands at **field level** in the emitted
116
+ * JSON Schema whichever way the caller spelled it (`z.string().describe(D).optional()` carries it on
117
+ * the inner type, `z.string().optional().describe(D)` on the wrapper).
118
+ *
119
+ * `null` is only stripped where the caller's own declaration gives it no meaning. A field written
120
+ * `z.string().nullable().optional()` asked for `null` to be a value in its own right, so it keeps
121
+ * it; only a plain `.optional()`, for which `null` was never a legal answer and can only have come
122
+ * from the required-and-nullable rewrite, collapses to the key being absent.
123
+ */
124
+ function walkOptional(schema, def) {
125
+ const inner = def.innerType;
126
+ const innerWalk = walk(inner);
127
+ const description = schema.description ?? inner.description;
128
+ const nullIsMeaningful = inner.safeParse(null).success;
129
+ // A field that already admits `null` needs no second nullable wrapper — one would emit a nested
130
+ // `anyOf` inside an `anyOf` that says nothing the inner one does not.
131
+ let nullable = nullIsMeaningful ? innerWalk.schema : innerWalk.schema.nullable();
132
+ if (description !== undefined)
133
+ nullable = nullable.describe(description);
134
+ const wireSchema = nullable.prefault(null);
135
+ const innerNormalize = innerWalk.normalize;
136
+ const normalize = (value) => {
137
+ if (value === undefined)
138
+ return ABSENT;
139
+ if (value === null)
140
+ return nullIsMeaningful ? null : ABSENT;
141
+ return innerNormalize ? innerNormalize(value) : value;
142
+ };
143
+ return { schema: wireSchema, normalize };
144
+ }
145
+ function walkObject(schema, def) {
146
+ const shape = def.shape ?? {};
147
+ const nextShape = {};
148
+ const normalizers = [];
149
+ let changed = false;
150
+ for (const [key, field] of Object.entries(shape)) {
151
+ const result = walk(field);
152
+ nextShape[key] = result.schema;
153
+ if (result.schema !== field)
154
+ changed = true;
155
+ if (result.normalize)
156
+ normalizers.push([key, result.normalize]);
157
+ }
158
+ if (!changed && normalizers.length === 0)
159
+ return { schema };
160
+ const normalize = (value) => {
161
+ if (!isRecord(value))
162
+ return value;
163
+ const out = { ...value };
164
+ for (const [key, normalizeField] of normalizers) {
165
+ if (!Object.hasOwn(out, key))
166
+ continue;
167
+ const normalized = normalizeField(out[key]);
168
+ if (normalized === ABSENT)
169
+ delete out[key];
170
+ else
171
+ out[key] = normalized;
172
+ }
173
+ return out;
174
+ };
175
+ return { schema: changed ? cloneWith(schema, { shape: nextShape }) : schema, normalize };
176
+ }
177
+ function walkArray(schema, def) {
178
+ const element = def.element;
179
+ const result = walk(element);
180
+ if (result.schema === element && !result.normalize)
181
+ return { schema };
182
+ const normalizeElement = result.normalize;
183
+ const normalize = normalizeElement
184
+ ? (value) => {
185
+ if (!Array.isArray(value))
186
+ return value;
187
+ return value.map((item) => {
188
+ const normalized = normalizeElement(item);
189
+ // An element position has no key to remove, so "absent" degrades to `undefined` — which
190
+ // is what an optional element schema accepts anyway.
191
+ return normalized === ABSENT ? undefined : normalized;
192
+ });
193
+ }
194
+ : undefined;
195
+ return {
196
+ schema: result.schema === element ? schema : cloneWith(schema, { element: result.schema }),
197
+ normalize,
198
+ };
199
+ }
200
+ function walkTuple(schema, def) {
201
+ const items = def.items ?? [];
202
+ const rest = def.rest ?? null;
203
+ const itemResults = items.map((item) => walk(item));
204
+ const restResult = rest ? walk(rest) : undefined;
205
+ const changed = itemResults.some((result, index) => result.schema !== items[index]) ||
206
+ (restResult !== undefined && rest !== null && restResult.schema !== rest);
207
+ const needsNormalize = itemResults.some((result) => result.normalize) || restResult?.normalize !== undefined;
208
+ if (!changed && !needsNormalize)
209
+ return { schema };
210
+ const normalize = needsNormalize
211
+ ? (value) => {
212
+ if (!Array.isArray(value))
213
+ return value;
214
+ return value.map((item, index) => {
215
+ // Gate on POSITION: a prefix item is normalized by its own item schema and never by the
216
+ // rest schema, which describes a different position entirely.
217
+ const normalizeItem = index < items.length ? itemResults[index]?.normalize : restResult?.normalize;
218
+ if (!normalizeItem)
219
+ return item;
220
+ const normalized = normalizeItem(item);
221
+ return normalized === ABSENT ? undefined : normalized;
222
+ });
223
+ }
224
+ : undefined;
225
+ return {
226
+ schema: changed
227
+ ? cloneWith(schema, {
228
+ items: itemResults.map((result) => result.schema),
229
+ rest: restResult ? restResult.schema : rest,
230
+ })
231
+ : schema,
232
+ normalize,
233
+ };
234
+ }
235
+ function walkRecord(schema, def) {
236
+ const valueType = def.valueType;
237
+ const result = walk(valueType);
238
+ if (result.schema === valueType && !result.normalize)
239
+ return { schema };
240
+ const normalizeValue = result.normalize;
241
+ const normalize = normalizeValue
242
+ ? (value) => {
243
+ if (!isRecord(value))
244
+ return value;
245
+ const out = {};
246
+ for (const [key, item] of Object.entries(value)) {
247
+ const normalized = normalizeValue(item);
248
+ if (normalized !== ABSENT)
249
+ out[key] = normalized;
250
+ }
251
+ return out;
252
+ }
253
+ : undefined;
254
+ return {
255
+ schema: result.schema === valueType ? schema : cloneWith(schema, { valueType: result.schema }),
256
+ normalize,
257
+ };
258
+ }
259
+ /**
260
+ * The single-child wrappers: `nullable`, `readonly`, `default`, `prefault`, `nonoptional`.
261
+ *
262
+ * A wrapper is **transparent to optionality**. `z.string().optional().default('foo')` is still sent
263
+ * as a required key typed `anyOf: [T, null]`, so a `null` arriving here is the wire's "nothing here"
264
+ * and must reach the inner normalizer that knows how to remove it. Passing every `null` straight
265
+ * through instead would advertise `null` to the provider and then reject the one it sends — the same
266
+ * self-contradiction this module exists to remove, one wrapper deep. What "absent" then means is the
267
+ * caller's own business, because the final validation is the caller's untouched schema: under
268
+ * `.default('foo')` it resolves to `'foo'`, under `.readonly()` the key simply stays absent.
269
+ *
270
+ * The exception is a wrapper that makes `null` a value in its own right — the caller wrote
271
+ * `.nullable()` **outside** the optional. That is the question {@link walkOptional} asks of its own
272
+ * inner type, asked one level up, and it is what keeps the two spellings of nullable-and-optional
273
+ * from disagreeing about the same field.
274
+ *
275
+ * `undefined` is passed through rather than being given a second meaning here: the wire never
276
+ * produces one (`prefault` supplies `null` for a missing key), and a genuinely missing object key
277
+ * never reaches a field normalizer at all — {@link walkObject} skips it.
278
+ */
279
+ function walkWrapper(schema, def) {
280
+ const inner = def.innerType;
281
+ const result = walk(inner);
282
+ if (result.schema === inner && !result.normalize)
283
+ return { schema };
284
+ const innerNormalize = result.normalize;
285
+ const nullIsMeaningful = innerNormalize !== undefined && schema.safeParse(null).success;
286
+ const normalize = innerNormalize
287
+ ? (value) => {
288
+ if (value === undefined)
289
+ return value;
290
+ if (value === null && nullIsMeaningful)
291
+ return null;
292
+ return innerNormalize(value);
293
+ }
294
+ : undefined;
295
+ return {
296
+ schema: result.schema === inner ? schema : cloneWith(schema, { innerType: result.schema }),
297
+ normalize,
298
+ };
299
+ }
300
+ /**
301
+ * Thrown when the walk re-enters a schema it is already inside, i.e. the caller's schema is
302
+ * recursive. Caught in {@link structuredOutputBoundary}, which then leaves the whole schema alone —
303
+ * see the module doc's limits.
304
+ */
305
+ const CYCLIC = Symbol('structured-output-cyclic');
306
+ /** The schemas the current walk is inside. A node reached twice on one path is a cycle. */
307
+ const inProgress = new WeakSet();
308
+ /**
309
+ * Rewrite one node. Every branch here has a matching arm in the normalizer it returns — the two
310
+ * halves are produced by the **same** walk precisely so their coverage cannot drift apart. Anything
311
+ * not listed is returned untouched, with no normalizer.
312
+ *
313
+ * A **recursive** schema aborts the whole walk rather than being partly rewritten. Zod spells
314
+ * recursion as a getter in an object's shape, which reads as an ordinary `object` here and would
315
+ * otherwise descend for ever. Rewriting only the levels reached before the cycle would put an
316
+ * optional key in `required` at one depth and leave it out at the next — an inconsistency that
317
+ * satisfies no provider's strict rule while making the emitted schema harder to reason about than
318
+ * the caller's own.
319
+ */
320
+ function walk(schema) {
321
+ if (inProgress.has(schema))
322
+ throw CYCLIC;
323
+ inProgress.add(schema);
324
+ try {
325
+ return walkNode(schema);
326
+ }
327
+ finally {
328
+ inProgress.delete(schema);
329
+ }
330
+ }
331
+ function walkNode(schema) {
332
+ const def = defOf(schema);
333
+ switch (def.type) {
334
+ case 'optional':
335
+ return walkOptional(schema, def);
336
+ case 'object':
337
+ return walkObject(schema, def);
338
+ case 'array':
339
+ return walkArray(schema, def);
340
+ case 'tuple':
341
+ return walkTuple(schema, def);
342
+ case 'record':
343
+ return walkRecord(schema, def);
344
+ case 'nullable':
345
+ case 'readonly':
346
+ case 'default':
347
+ case 'prefault':
348
+ case 'nonoptional':
349
+ return walkWrapper(schema, def);
350
+ default:
351
+ return { schema };
352
+ }
353
+ }
354
+ /**
355
+ * Memoized per schema instance. Repeated calls with the same schema — the common case, since call
356
+ * sites hold a module-level schema constant — return the same `wireSchema` reference, which is what
357
+ * LangChain's own JSON-Schema conversion cache is keyed on.
358
+ */
359
+ const boundaries = new WeakMap();
360
+ /**
361
+ * Build the {@link StructuredOutputBoundary} for a schema — the one entry point every
362
+ * `withStructuredOutput` call in this project goes through. See the module doc for what it does and
363
+ * why.
364
+ *
365
+ * @param schema The caller's schema, used unchanged for the final validation.
366
+ */
367
+ export function structuredOutputBoundary(schema) {
368
+ const cached = boundaries.get(schema);
369
+ if (cached)
370
+ return cached;
371
+ let walked;
372
+ try {
373
+ walked = walk(schema);
374
+ }
375
+ catch (error) {
376
+ // A recursive schema is left exactly as the caller wrote it — the same answer this module gives
377
+ // for a union, and for the same reason: it will not rewrite what it cannot also normalize.
378
+ if (error !== CYCLIC)
379
+ throw error;
380
+ walked = { schema: schema };
381
+ }
382
+ const normalize = walked.normalize;
383
+ const boundary = {
384
+ wireSchema: walked.schema,
385
+ safeParse(raw) {
386
+ const normalized = normalize ? normalize(raw) : raw;
387
+ return schema.safeParse(normalized === ABSENT ? undefined : normalized);
388
+ },
389
+ };
390
+ boundaries.set(schema, boundary);
391
+ return boundary;
392
+ }
393
+ //# sourceMappingURL=structuredOutput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structuredOutput.js","sourceRoot":"","sources":["../../src/runtime/structuredOutput.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2EG;AAEH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAKzB;;;;GAIG;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AA0BlD,SAAS,KAAK,CAAC,MAAiB;IAC9B,OAAQ,MAAkD,CAAC,IAAI,CAAC,GAAG,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,SAAS,CAAC,MAAiB,EAAE,KAAyB;IAC7D,MAAM,IAAI,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK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,CAAC,CAAC;IACtE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { RunnableConfig } from '@langchain/core/runnables';
2
2
  import { GthConfig, PromptSegmentName } from '#src/config.js';
3
+ import type { GthCommand } from '#src/core/types.js';
3
4
  import { SystemMessage } from '@langchain/core/messages';
4
5
  /**
5
6
  * Creates new runnable config.
@@ -29,6 +30,22 @@ export declare function readChatPrompt(config: PromptReadConfig): string;
29
30
  export declare function buildSystemMessages(config: GthConfig, modePrompt?: string | null): SystemMessage[];
30
31
  export declare function readCodePrompt(config: PromptReadConfig): string;
31
32
  export declare function readExecPrompt(config: PromptReadConfig): string;
33
+ /**
34
+ * GS2-79 — the SINGLE place a command's mode prompt is chosen, for every site that composes a
35
+ * system prompt via {@link buildSystemMessages}: both agent backends and the subagent profiles.
36
+ *
37
+ * It exists because the selection used to be an inline three-branch ternary copied to each of
38
+ * those sites, and a command missing from one copy is silently served the CHAT prompt — the
39
+ * default branch — rather than failing. That is how `review`/`pr` came to compose the chat prompt
40
+ * while the review instructions were smuggled in as a caller-side leading `SystemMessage`, which
41
+ * Anthropic rejects outright ("System messages are only permitted as the first passed message").
42
+ * One function means a new command is wired once, and `review`/`pr` cannot silently fall back to
43
+ * chat again.
44
+ *
45
+ * `review`/`pr` resolve to the REVIEW INSTRUCTIONS (`.gsloth.review.md`), which is what makes a
46
+ * review a review; every command without a mode prompt of its own keeps the chat prompt.
47
+ */
48
+ export declare function readModePrompt(command: GthCommand | undefined, config: PromptReadConfig): string;
32
49
  /**
33
50
  * Read a prompt file from the project config dir (honouring identity profiles), falling back
34
51
  * to a packaged default unless `noDefaultPrompts` is set. Downstream packages owning their own
@@ -115,6 +115,34 @@ export function readCodePrompt(config) {
115
115
  export function readExecPrompt(config) {
116
116
  return readPromptSegment('exec', config);
117
117
  }
118
+ /**
119
+ * GS2-79 — the SINGLE place a command's mode prompt is chosen, for every site that composes a
120
+ * system prompt via {@link buildSystemMessages}: both agent backends and the subagent profiles.
121
+ *
122
+ * It exists because the selection used to be an inline three-branch ternary copied to each of
123
+ * those sites, and a command missing from one copy is silently served the CHAT prompt — the
124
+ * default branch — rather than failing. That is how `review`/`pr` came to compose the chat prompt
125
+ * while the review instructions were smuggled in as a caller-side leading `SystemMessage`, which
126
+ * Anthropic rejects outright ("System messages are only permitted as the first passed message").
127
+ * One function means a new command is wired once, and `review`/`pr` cannot silently fall back to
128
+ * chat again.
129
+ *
130
+ * `review`/`pr` resolve to the REVIEW INSTRUCTIONS (`.gsloth.review.md`), which is what makes a
131
+ * review a review; every command without a mode prompt of its own keeps the chat prompt.
132
+ */
133
+ export function readModePrompt(command, config) {
134
+ switch (command) {
135
+ case 'code':
136
+ return readCodePrompt(config);
137
+ case 'exec':
138
+ return readExecPrompt(config);
139
+ case 'review':
140
+ case 'pr':
141
+ return readReviewInstructions(config);
142
+ default:
143
+ return readChatPrompt(config);
144
+ }
145
+ }
118
146
  /**
119
147
  * Read a prompt file from the project config dir (honouring identity profiles), falling back
120
148
  * to a packaged default unless `noDefaultPrompts` is set. Downstream packages owning their own
@@ -1 +1 @@
1
- {"version":3,"file":"llmUtils.js","sourceRoot":"","sources":["../../src/utils/llmUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CA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esystemToolsConfig } from '#src/config/filesystem-tools.js';
18
19
  /**
19
20
  * EXT-26: the platform-agnostic tail shared by both {@link appendOsShellNote} branches.
20
21
  *
@@ -81,6 +82,18 @@ export interface CommitCoAuthor {
81
82
  * measured not to work. A file path carries no shell metacharacters, so the file form removes the
82
83
  * failure mode instead of asking the model to avoid it.
83
84
  *
85
+ * **The clause that names the writing tool is gated on `filesystem`** (EXT-84), through the one
86
+ * shared derivation {@link isWriteFileToolRegistered} — the same interpretation that decides which
87
+ * tools are actually registered. Naming an unregistered tool while forbidding both the shell
88
+ * fallback and the inline flag leaves the model NO compliant path, and its likeliest recovery is
89
+ * the inline form this note exists to prevent. So when the write tool is registered the note names
90
+ * it literally (the overwhelmingly common case, and a literal name is what makes the instruction
91
+ * actionable); when it is not, the note names no tool, keeps both prohibitions and the file form,
92
+ * and supplies the compliant path that remains: do not commit, and hand the message back to the
93
+ * user. That branch states no availability claim of its own — the backends read the same
94
+ * `filesystem` value but register filesystem tools differently, so a note asserting "you have no
95
+ * file-writing tool" could be flatly false on one of them.
96
+ *
84
97
  * The note's prose carries **no backtick and no other markup** — including no angle-bracket
85
98
  * placeholder: it is the one piece of guidance whose subject is how to write a commit message, so
86
99
  * quoting its own examples in backticks would demonstrate the exact style rule 2 exists to stop, and
@@ -100,7 +113,7 @@ export interface CommitCoAuthor {
100
113
  * the deep `GthDeepAgent` inject it (the git-commit capability rides on `run_shell_command`, which
101
114
  * both backends expose in code mode). Returns the note alone when there is no base prompt.
102
115
  */
103
- export declare function appendCommitCoAuthorNote(systemPrompt: string | undefined, coAuthor?: CommitCoAuthor, modelIdentity?: ResolvedModelIdentity): string;
116
+ export declare function appendCommitCoAuthorNote(systemPrompt: string | undefined, coAuthor?: CommitCoAuthor, modelIdentity?: ResolvedModelIdentity, filesystem?: FilesystemToolsConfig): string;
104
117
  /**
105
118
  * GS2-34/GS2-53 — the resolved active-model identity, as a STRUCTURED value.
106
119
  *