@gaunt-sloth/core 2.0.0-beta.2 → 2.0.0-beta.3

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/dist/config/shell-policy.d.ts +2 -2
  2. package/dist/config/shell-policy.js +3 -3
  3. package/dist/config/tool-descriptions.d.ts +5 -5
  4. package/dist/config/tool-descriptions.js +3 -3
  5. package/dist/core/GthAbstractAgent.d.ts +1 -1
  6. package/dist/core/GthAbstractAgent.js +63 -3
  7. package/dist/core/GthAbstractAgent.js.map +1 -1
  8. package/dist/core/GthAgentRunner.d.ts +9 -9
  9. package/dist/core/GthAgentRunner.js +62 -13
  10. package/dist/core/GthAgentRunner.js.map +1 -1
  11. package/dist/core/GthLangChainAgent.js +1 -1
  12. package/dist/core/GthLangChainAgent.js.map +1 -1
  13. package/dist/core/reasoningBlocks.d.ts +4 -6
  14. package/dist/core/reasoningBlocks.js +4 -6
  15. package/dist/core/reasoningBlocks.js.map +1 -1
  16. package/dist/core/shell/ShellCommandFailedError.d.ts +4 -4
  17. package/dist/core/shell/ShellCommandFailedError.js +4 -4
  18. package/dist/core/shell/openWorld.d.ts +4 -3
  19. package/dist/core/shell/openWorld.js +4 -3
  20. package/dist/core/shell/openWorld.js.map +1 -1
  21. package/dist/core/toolDisplay.d.ts +49 -2
  22. package/dist/core/toolDisplay.js +137 -19
  23. package/dist/core/toolDisplay.js.map +1 -1
  24. package/dist/core/types.d.ts +6 -6
  25. package/dist/providers/geminiSchemaSanitizer.d.ts +2 -2
  26. package/dist/providers/geminiSchemaSanitizer.js +2 -2
  27. package/dist/providers/geminiThinking.d.ts +10 -5
  28. package/dist/providers/geminiThinking.js +10 -5
  29. package/dist/providers/geminiThinking.js.map +1 -1
  30. package/dist/runtime/askStructured.d.ts +22 -0
  31. package/dist/runtime/askStructured.js +53 -0
  32. package/dist/runtime/askStructured.js.map +1 -1
  33. package/dist/utils/aiignoreUtils.d.ts +6 -0
  34. package/dist/utils/aiignoreUtils.js +69 -1
  35. package/dist/utils/aiignoreUtils.js.map +1 -1
  36. package/dist/utils/displayWidth.d.ts +10 -5
  37. package/dist/utils/displayWidth.js +148 -54
  38. package/dist/utils/displayWidth.js.map +1 -1
  39. package/dist/utils/llmUtils.d.ts +1 -1
  40. package/dist/utils/llmUtils.js +1 -1
  41. package/dist/utils/systemPromptNotes.d.ts +3 -3
  42. package/dist/utils/systemPromptNotes.js +3 -3
  43. package/dist/utils/vertexaiUtils.js +100 -1
  44. package/dist/utils/vertexaiUtils.js.map +1 -1
  45. package/package.json +4 -3
@@ -65,6 +65,28 @@ export type StructuredFailureKind = 'timeout' | 'unparseable' | 'call-failed';
65
65
  * carries it, so a different value here reports a genuine timeout as `call-failed`.
66
66
  */
67
67
  export declare function classifyStructuredFailure(error: string, timeoutMs: number): StructuredFailureKind;
68
+ /**
69
+ * Say WHICH of {@link askStructured}'s three failures happened, in one sentence a reader can act on.
70
+ *
71
+ * The two a reader has to tell apart first are a provider that never answered and a provider that
72
+ * refused the request: they want opposite responses — re-run the one, investigate the other — and
73
+ * from the outside they arrive as the same red. Naming the class is what stops a real rejection
74
+ * being shrugged off as flakiness, which is how a guard stops guarding with nobody deciding to
75
+ * remove it.
76
+ *
77
+ * There is no `default` arm and no fallback sentence, deliberately. The module-internal
78
+ * `STRUCTURED_FAILURE_SENTENCES` map, declared above, is typed by the union, so an unhandled kind
79
+ * cannot reach here — the compiler rejects the map instead. A defensive arm would only catch a case
80
+ * the build already refuses, at the price of hiding the compile error that is the real signal.
81
+ * It is named here rather than linked because it is not exported, and a `{@link}` to an
82
+ * undocumented symbol renders as dead text in the API reference.
83
+ *
84
+ * @param error The `error` from a `{ ok: false }` {@link AskStructuredResult}.
85
+ * @param timeoutMs The budget passed to that same {@link askStructured} call — as for
86
+ * {@link classifyStructuredFailure}, a different value here reports a genuine timeout as
87
+ * `call-failed`.
88
+ */
89
+ export declare function describeStructuredFailure(error: string, timeoutMs: number): string;
68
90
  /** Inputs to {@link askStructured}. The caller supplies the model (via config), the two message
69
91
  * texts, and an optional timeout — the Zod schema is a separate positional argument so `<T>` can
70
92
  * be inferred from it. */
@@ -64,6 +64,59 @@ export function classifyStructuredFailure(error, timeoutMs) {
64
64
  return 'unparseable';
65
65
  return 'call-failed';
66
66
  }
67
+ /**
68
+ * The sentence each {@link StructuredFailureKind} is reported as — the wording a reader of a red run
69
+ * actually sees, and the half of {@link describeStructuredFailure} that can be wrong without any
70
+ * mechanism being wrong.
71
+ *
72
+ * It lives here, beside the classifier it is keyed on, for two reasons that are really one. The
73
+ * `Record` is annotated with the union, so the compiler checks the map is **total at its definition
74
+ * site**: adding a kind to {@link StructuredFailureKind} without giving it a sentence is a build
75
+ * error rather than a message that reads `undefined` at the moment someone needs it. And a sentence
76
+ * that sits beside the classifier is reachable by the unit suite, so each one is pinned to the class
77
+ * it names — a map the tests cannot see can have its bodies exchanged, and the failure that results
78
+ * is a stall announcing itself as a rejection, which is the exact confusion these sentences exist to
79
+ * end.
80
+ *
81
+ * Each entry receives the raw `error` and the budget the call was made with, so the sentence can
82
+ * quote both rather than describe them.
83
+ */
84
+ const STRUCTURED_FAILURE_SENTENCES = {
85
+ timeout: (error, timeoutMs) => `STALLED: the provider returned no response within the ${timeoutMs}ms call budget. ` +
86
+ 'Nothing was rejected and nothing was parsed, so this is NOT the schema guard firing — it ' +
87
+ 'is the provider failing to answer. ' +
88
+ `askStructured said: ${error}`,
89
+ unparseable: (error) => "REJECTED BY OUR OWN SCHEMA: the provider answered, and the answer failed this case's " +
90
+ 'schema. This IS the guard firing — the null-vs-absent half. ' +
91
+ `askStructured said: ${error}`,
92
+ 'call-failed': (error) => 'REJECTED BEFORE ANY ANSWER: the call failed outright. A 400 naming `required` IS the ' +
93
+ 'guard firing — the strict-schema half; anything else is auth, transport or configuration. ' +
94
+ `askStructured said: ${error}`,
95
+ };
96
+ /**
97
+ * Say WHICH of {@link askStructured}'s three failures happened, in one sentence a reader can act on.
98
+ *
99
+ * The two a reader has to tell apart first are a provider that never answered and a provider that
100
+ * refused the request: they want opposite responses — re-run the one, investigate the other — and
101
+ * from the outside they arrive as the same red. Naming the class is what stops a real rejection
102
+ * being shrugged off as flakiness, which is how a guard stops guarding with nobody deciding to
103
+ * remove it.
104
+ *
105
+ * There is no `default` arm and no fallback sentence, deliberately. The module-internal
106
+ * `STRUCTURED_FAILURE_SENTENCES` map, declared above, is typed by the union, so an unhandled kind
107
+ * cannot reach here — the compiler rejects the map instead. A defensive arm would only catch a case
108
+ * the build already refuses, at the price of hiding the compile error that is the real signal.
109
+ * It is named here rather than linked because it is not exported, and a `{@link}` to an
110
+ * undocumented symbol renders as dead text in the API reference.
111
+ *
112
+ * @param error The `error` from a `{ ok: false }` {@link AskStructuredResult}.
113
+ * @param timeoutMs The budget passed to that same {@link askStructured} call — as for
114
+ * {@link classifyStructuredFailure}, a different value here reports a genuine timeout as
115
+ * `call-failed`.
116
+ */
117
+ export function describeStructuredFailure(error, timeoutMs) {
118
+ return STRUCTURED_FAILURE_SENTENCES[classifyStructuredFailure(error, timeoutMs)](error, timeoutMs);
119
+ }
67
120
  /**
68
121
  * Ask the configured model for a single schema-validated object — a non-agentic structured-output
69
122
  * call that mirrors their mechanism (see the module doc) and never throws.
@@ -1 +1 @@
1
- {"version":3,"file":"askStructured.js","sourceRoot":"","sources":["../../src/runtime/askStructured.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAIvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,UAAU,2BAA2B,CAAC,SAAiB;IAC3D,OAAO,mCAAmC,SAAS,wCAAwC,CAAC;AAC9F,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM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E,EAAE,KAAK,EAAE,KAAK,EAAE,iCAAiC,EAAE,CAAC;QACjE,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACtF,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
@@ -11,6 +11,12 @@
11
11
  export declare function loadAiignorePatterns(rootDir: string): string[];
12
12
  /**
13
13
  * Check if a file path should be ignored based on aiignore patterns
14
+ *
15
+ * Matching follows `.gitignore` rules — a bare pattern applies at every depth, a pattern with a
16
+ * separator is anchored to `rootDir`, and either kind hides the subtree beneath whatever it
17
+ * matches. The module-private `expandPattern` above implements that mapping and documents the two
18
+ * deliberate departures from `.gitignore`.
19
+ *
14
20
  * @param filePath - The file path to check
15
21
  * @param rootDir - The root directory for relative pattern matching
16
22
  * @param customPatterns - Optional custom patterns to use instead of loading from file
@@ -32,8 +32,72 @@ export function loadAiignorePatterns(rootDir) {
32
32
  return [];
33
33
  }
34
34
  }
35
+ /**
36
+ * Expand one `.aiignore` line into the glob patterns that implement it.
37
+ *
38
+ * `.aiignore` is documented as using `.gitignore` rules, and that is the contract this function
39
+ * keeps. `path.matchesGlob` on its own does not: its `*` never crosses `/`, so a bare pattern is
40
+ * silently root-only, and a trailing slash matches nothing at all. Both failures are silent and
41
+ * both point the wrong way for a privacy boundary — the user writes a line, sees no error, and
42
+ * believes a file is hidden from the agent when it is not.
43
+ *
44
+ * The three rules, each mapping to one arm below:
45
+ *
46
+ * - **A pattern with no separator applies at every depth.** `*.log` hides `app.log` and
47
+ * `sub/app.log` alike, so it gains a globstar prefix. That prefixed form also matches at the
48
+ * root, so the one arm covers both depths.
49
+ * - **A pattern containing a separator is anchored to the root.** `build/out` hides
50
+ * `build/out`, never `src/build/out`. A leading `/` is an explicit spelling of the same thing and
51
+ * is stripped, since relative paths never carry one.
52
+ * - **Whatever a pattern hides, it hides the subtree beneath it.** This is the `/**` arm, and it is
53
+ * what makes a single line hide a directory's name *and* its contents. Without it the name is
54
+ * withheld from a listing while every file below it stays readable — the shape of the leak this
55
+ * boundary exists to prevent.
56
+ *
57
+ * DELIBERATE DEVIATION: a trailing slash is treated as an ordinary pattern rather than as
58
+ * "directories only", so `dist/` also hides a plain *file* named `dist`. Honouring the
59
+ * directory-only half needs the entry's type, which a path string does not carry and which the
60
+ * callers do not supply. Erring toward hiding costs a rare false positive the user can see and
61
+ * rename around; erring the other way silently exposes what someone asked to be hidden.
62
+ *
63
+ * NOT SUPPORTED: re-inclusion (`!pattern`). A leading `!` is matched literally, so such a line
64
+ * hides a file whose name really does start with `!` and un-hides nothing. That is the safe
65
+ * direction, and it is stated in the user documentation rather than left to be discovered.
66
+ *
67
+ * @param pattern - One non-empty, non-comment line from `.aiignore` or `aiignore.patterns`
68
+ * @returns Glob patterns to test the relative path against; empty when the line carries no pattern
69
+ */
70
+ function expandPattern(pattern) {
71
+ // A trailing slash is gitignore's directory marker; strip it (see DELIBERATE DEVIATION above).
72
+ let body = pattern.replace(/\/+$/, '');
73
+ // A leading slash anchors to the root. Relative paths never carry one, so it must come off or
74
+ // the pattern matches nothing.
75
+ let anchored = false;
76
+ if (body.startsWith('/')) {
77
+ body = body.replace(/^\/+/, '');
78
+ anchored = true;
79
+ }
80
+ // A line that was nothing but slashes carries no pattern. Returning no arms is what keeps it
81
+ // from collapsing into `**`, which would hide the entire tree.
82
+ if (body.length === 0) {
83
+ return [];
84
+ }
85
+ // An interior separator anchors the pattern; its absence lets it apply at any depth.
86
+ if (body.includes('/')) {
87
+ anchored = true;
88
+ }
89
+ const base = anchored ? body : `**/${body}`;
90
+ // The entry itself, then everything beneath it.
91
+ return [base, `${base}/**`];
92
+ }
35
93
  /**
36
94
  * Check if a file path should be ignored based on aiignore patterns
95
+ *
96
+ * Matching follows `.gitignore` rules — a bare pattern applies at every depth, a pattern with a
97
+ * separator is anchored to `rootDir`, and either kind hides the subtree beneath whatever it
98
+ * matches. The module-private `expandPattern` above implements that mapping and documents the two
99
+ * deliberate departures from `.gitignore`.
100
+ *
37
101
  * @param filePath - The file path to check
38
102
  * @param rootDir - The root directory for relative pattern matching
39
103
  * @param customPatterns - Optional custom patterns to use instead of loading from file
@@ -54,7 +118,11 @@ export function shouldIgnoreFile(filePath, rootDir, customPatterns = undefined,
54
118
  // Check if any pattern matches
55
119
  for (const pattern of patterns) {
56
120
  try {
57
- if (path.matchesGlob(relativePath, pattern)) {
121
+ // Globs are built with `/` separators regardless of platform: win32's matchesGlob resolves a
122
+ // backslash-separated path against them, so the relative path is passed through untouched
123
+ // rather than rewritten (a rewrite would split a POSIX filename that legitimately contains a
124
+ // backslash into two segments).
125
+ if (expandPattern(pattern).some((glob) => path.matchesGlob(relativePath, glob))) {
58
126
  debugLog(`File ignored by pattern '${pattern}': ${relativePath}`);
59
127
  return true;
60
128
  }
@@ -1 +1 @@
1
- {"version":3,"file":"aiignoreUtils.js","sourceRoot":"","sources":["../../src/utils/aiignoreUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAEvD,IAAI,C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AAa,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;gBAChF,QAAQ,CAAC,4BAA4B,OAAO,MAAM,YAAY,EAAE,CAAC,CAAC;gBAClE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,QAAQ,CACN,2BAA2B,OAAO,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACjG,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAmB,EACnB,OAAe,EACf,cAAc,GAAyB,SAAS,EAChD,OAAO,GAAY,IAAI;IAEvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,CAC5E,CAAC;AACJ,CAAC"}
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Terminal columns `text` occupies. Zero-width clusters (combining marks, default-ignorables)
3
3
  * count 0, wide clusters (CJK, emoji, fullwidth forms) count 2, everything else 1. ANSI escape
4
- * sequences are not counted, so a pre-coloured string measures as what the user sees — but the
5
- * slices below do not share that awareness, so do not read this as a licence to feed them one.
4
+ * sequences are not counted, so a pre-coloured string measures as what the user sees — and the
5
+ * slices below share that awareness, so a coloured string may be handed to either of them.
6
6
  */
7
7
  export declare function displayWidth(text: string): number;
8
8
  /**
@@ -46,8 +46,13 @@ export declare function sliceToMaxWidth(text: string, maxWidth: number): string;
46
46
  * the tail, lose the head. The mirror of {@link sliceToWidth}, for values whose end is the
47
47
  * informative part (a path's leaf directory).
48
48
  *
49
- * This one materialises the clusters: it walks backwards, and cluster boundaries are only
50
- * derivable from the front. Its callers pass a path or a model id, so the input is a line rather
51
- * than a file.
49
+ * This one materialises the pieces: it walks backwards, and both cluster and sequence boundaries
50
+ * are only derivable from the front. Its callers pass a path or a model id, so the input is a line
51
+ * rather than a file.
52
+ *
53
+ * Keeping the END means the escapes that OPENED a style sit in the discarded head and go with it,
54
+ * so a tail comes back in the terminal's default styling. Only the sequences inside the kept span
55
+ * are carried, which leaves the tail ending in whatever state the whole string ended in — the cut
56
+ * introduces no bleed of its own.
52
57
  */
53
58
  export declare function sliceEndToWidth(text: string, maxWidth: number): string;
@@ -23,24 +23,38 @@
23
23
  * rules below are defined over, so the two agree by construction and a sliced string's width is
24
24
  * exactly the sum of the widths of the clusters kept.
25
25
  *
26
- * ## What the slices expect: PLAIN text
27
- *
28
- * {@link displayWidth} is ANSI-aware and the slices are NOT, and that asymmetry is a contract
29
- * rather than an oversight. An escape sequence is not one cluster — the terminal swallows it
30
- * whole, but `ESC`, `[`, `3`, `5`, `m` segment as five, four of them printable so the two
31
- * disagree on an escape-bearing string and a slice can both under-fill its budget and cut inside
32
- * a sequence. Feed the slices the text a user will read, and colour it afterwards; that is what
33
- * every caller here does, since both render surfaces map a style tag to their own escapes at the
34
- * very end. Making the slices ANSI-aware would change what a coloured preview line renders as,
35
- * which is a decision for whoever needs it and not a silent detail of this module.
36
- *
37
- * That asymmetry is also why a slice decides "does the whole string fit?" two different ways. For
38
- * plain text the cluster walk decides it: the widths of the clusters sum to the width of the
39
- * string, so walking until the budget is blown answers the question and answers it WITHOUT
40
- * touching the rest of the input — which is what keeps a megabyte-long preview line from being
41
- * measured end to end before it is cut at column 200. Only escape-bearing text is measured whole
42
- * first, because there the two rulers disagree and a coloured string that MEASURES as fitting must
43
- * be handed back whole rather than cut short by the bytes of its own escapes.
26
+ * ## What the slices cut: text, with its escapes carried along
27
+ *
28
+ * The slices are ANSI-aware, and they agree with {@link displayWidth} by construction. An escape
29
+ * sequence is not one cluster — the terminal swallows it whole, but `ESC`, `[`, `3`, `5`, `m`
30
+ * segment as five, four of them printable. A walk that spent budget on those printable bytes
31
+ * would answer a different question from the ruler it is paired with, since `string-width` strips
32
+ * escapes before measuring; and at a budget narrower than the content it would cut INSIDE a
33
+ * sequence, handing the terminal a mutilated escape.
34
+ *
35
+ * So a sequence is an indivisible token costing zero columns. It is kept whole, and it is carried
36
+ * along with the text it introduces, so a truncated coloured string still renders coloured. A
37
+ * sequence whose text is entirely cut away is dropped with that text rather than left dangling at
38
+ * the end of the result, where it would style nothing and leak its colour into whatever the caller
39
+ * appends next an ellipsis, the next parameter, the status tag.
40
+ *
41
+ * **The result stays a genuine prefix (or suffix) of the input: no reset is appended.** Terminal
42
+ * state belongs to the surface that owns the line, and both render surfaces already open and close
43
+ * their own styling around each line they draw; an `ESC[0m` injected at the cut would close that
44
+ * wrapper early and un-style everything after it.
45
+ *
46
+ * Because escapes cost no budget, the clusters kept sum to the width of the string as
47
+ * {@link displayWidth} measures it, so the cluster walk decides "does the whole string fit?" on
48
+ * its own — incrementally, stopping at the budget, WITHOUT a pre-measurement of the input. That is
49
+ * what keeps a megabyte-long preview line from being measured end to end before it is cut at
50
+ * column 200, and it is why the escape-bearing case needs no separate ruler.
51
+ *
52
+ * The one input the two do not agree on is an escape sequence placed INSIDE a grapheme cluster,
53
+ * between a base character and its combining mark. The measurement strips the sequence and joins
54
+ * what is left into one cluster; the walk cannot, because the sequence has already broken the
55
+ * cluster in two. The walk then counts such a string WIDER than it renders, which spends budget
56
+ * that is not needed and can leave a slice short — never over its budget, which is the direction
57
+ * that matters.
44
58
  *
45
59
  * ## Why ambiguous-width characters stay NARROW — and the one place they must not
46
60
  *
@@ -75,8 +89,8 @@ const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: 'graphem
75
89
  /**
76
90
  * Terminal columns `text` occupies. Zero-width clusters (combining marks, default-ignorables)
77
91
  * count 0, wide clusters (CJK, emoji, fullwidth forms) count 2, everything else 1. ANSI escape
78
- * sequences are not counted, so a pre-coloured string measures as what the user sees — but the
79
- * slices below do not share that awareness, so do not read this as a licence to feed them one.
92
+ * sequences are not counted, so a pre-coloured string measures as what the user sees — and the
93
+ * slices below share that awareness, so a coloured string may be handed to either of them.
80
94
  */
81
95
  export function displayWidth(text) {
82
96
  return stringWidth(text);
@@ -104,22 +118,78 @@ export function firstCluster(text) {
104
118
  return segment;
105
119
  return '';
106
120
  }
107
- /** The clusters of `text`, in order — the only unit either slice is allowed to cut between. */
108
- function clusters(text) {
109
- const out = [];
110
- for (const { segment } of GRAPHEME_SEGMENTER.segment(text))
111
- out.push(segment);
112
- return out;
113
- }
114
121
  /**
115
- * Whether the whole-string measurement is the only ruler that can answer "does this fit" for
116
- * `text` true exactly when it carries an escape introducer (`ESC`, or the one-byte `CSI`), the
117
- * two characters `string-width` itself strips on. On anything else the cluster widths sum to the
118
- * whole-string width, so the walk decides the same question incrementally and a pre-measurement
119
- * would be a second full pass over the input for nothing.
122
+ * The code points a sequence can begin with: `ESC` (U+001B) and the one-byte `CSI` (U+009B) — the
123
+ * same two characters `string-width` itself tests for before it strips.
124
+ */
125
+ const ESCAPE_INTRODUCER_CODES = new Set([0x00_1b, 0x00_9b]);
126
+ /**
127
+ * One ANSI escape sequence — an OSC string, or a CSI/two-character sequence — as a source pattern.
128
+ *
129
+ * This is the grammar of `ansi-regex`, which is what `strip-ansi` matches with and therefore what
130
+ * `string-width` removes before it measures. It is reproduced here rather than imported so the walk
131
+ * can never end up on a DIFFERENT copy of that package from the one `string-width` resolves: two
132
+ * versions in one tree would let the ruler and the walk disagree about where a sequence ends, which
133
+ * is the exact defect this module's ANSI-awareness exists to prevent. The spec cross-checks this
134
+ * pattern against `strip-ansi` itself, so a divergence fails loudly rather than silently.
135
+ *
136
+ * The OSC payload stops at the first terminator character instead of scanning ahead for one, so an
137
+ * unterminated OSC introducer cannot rescan the rest of the input — which is what keeps the walk
138
+ * linear on a long line full of half-written escapes rather than quadratic.
139
+ */
140
+ const ANSI_SEQUENCE_SOURCE = [
141
+ '(?:\\u001B\\][^\\u0007\\u001B\\u009C]*(?:\\u0007|\\u001B\\u005C|\\u009C))',
142
+ '[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]',
143
+ ].join('|');
144
+ /**
145
+ * The same grammar anchored with the sticky flag, so it answers "does a sequence START here?" in
146
+ * one step at a known index rather than searching forward for the next one anywhere in the string.
147
+ *
148
+ * Module-level, because compiling it per slice would tax the common case that never uses it. Its
149
+ * `lastIndex` is written immediately before every `exec`, with nothing in between, so a second walk
150
+ * that begins while the first is suspended cannot observe a stale position.
120
151
  */
121
- function needsWholeStringMeasure(text) {
122
- return text.includes('\u001B') || text.includes('\u009B');
152
+ const ANSI_SEQUENCE_AT_INDEX = new RegExp(ANSI_SEQUENCE_SOURCE, 'y');
153
+ /**
154
+ * The pieces of `text` in order — whole escape sequences and whole grapheme clusters, the only
155
+ * units either slice is allowed to cut between.
156
+ *
157
+ * Lazy, and that is the point: the head slice stops pulling at its budget, so a megabyte-long line
158
+ * costs the length of the RESULT rather than the length of the input.
159
+ *
160
+ * An escape introducer is always its own cluster, because the segmentation rules break on both
161
+ * sides of a control character — so a sequence can only ever begin where a cluster begins, and one
162
+ * anchored match there settles how far it runs. The clusters it spans are then skipped. A cluster
163
+ * that STRADDLES the end of a sequence (a combining mark binding to the sequence's final byte)
164
+ * yields only the part beyond it, so the pieces always reassemble into the input exactly.
165
+ */
166
+ function* widthTokens(text) {
167
+ let index = 0;
168
+ for (const { segment, index: at } of GRAPHEME_SEGMENTER.segment(text)) {
169
+ const end = at + segment.length;
170
+ if (end <= index)
171
+ continue; // wholly inside a sequence already yielded
172
+ if (at < index) {
173
+ // Straddles the end of that sequence: only what lies beyond it is still unyielded.
174
+ const rest = text.slice(index, end);
175
+ index = end;
176
+ yield { text: rest, escape: false };
177
+ continue;
178
+ }
179
+ if (segment.length === 1 && ESCAPE_INTRODUCER_CODES.has(segment.charCodeAt(0))) {
180
+ ANSI_SEQUENCE_AT_INDEX.lastIndex = at;
181
+ const match = ANSI_SEQUENCE_AT_INDEX.exec(text);
182
+ if (match !== null) {
183
+ index = at + match[0].length;
184
+ yield { text: match[0], escape: true };
185
+ continue;
186
+ }
187
+ // An introducer that begins no sequence falls through as an ordinary cluster. It is a
188
+ // control character, so it measures zero and costs no budget either way.
189
+ }
190
+ index = end;
191
+ yield { text: segment, escape: false };
192
+ }
123
193
  }
124
194
  /**
125
195
  * The longest LEADING run of whole clusters whose total width is at most `maxWidth` — i.e. keep
@@ -146,50 +216,74 @@ export function sliceToMaxWidth(text, maxWidth) {
146
216
  }
147
217
  /**
148
218
  * The head-slice both public cuts are made of, given the ruler to measure with. The ruler is passed
149
- * rather than chosen here so the whole-string shortcut and the cluster walk can never end up on
150
- * different ones — measuring the shortcut narrow and the walk wide would hand back a string that
151
- * overruns the very budget the caller asked to be held to.
219
+ * rather than chosen here so a caller cannot end up measured by one and cut by the other — reading
220
+ * the budget narrow and spending it wide would hand back a string that overruns the very budget the
221
+ * caller asked to be held to.
222
+ *
223
+ * The input is measured ONCE, incrementally, by the walk itself: escapes cost nothing, so the
224
+ * clusters kept sum to what {@link displayWidth} would report for them, and "does the whole string
225
+ * fit?" is answered by reaching the end rather than by a separate pass over the input first.
226
+ *
227
+ * Escapes are held back until a cluster is actually kept, so a sequence whose text all falls
228
+ * outside the budget is dropped with it instead of trailing the result and colouring whatever the
229
+ * caller appends next.
152
230
  */
153
231
  function sliceHeadToWidth(text, maxWidth, measure) {
154
232
  if (maxWidth <= 0)
155
233
  return '';
156
- if (needsWholeStringMeasure(text) && measure(text) <= maxWidth)
157
- return text;
158
234
  let width = 0;
159
235
  let kept = '';
160
- for (const { segment } of GRAPHEME_SEGMENTER.segment(text)) {
161
- const clusterWidth = measure(segment);
236
+ let pendingEscapes = '';
237
+ for (const token of widthTokens(text)) {
238
+ if (token.escape) {
239
+ pendingEscapes += token.text;
240
+ continue;
241
+ }
242
+ const clusterWidth = measure(token.text);
162
243
  if (width + clusterWidth > maxWidth)
163
- break;
244
+ return kept;
164
245
  width += clusterWidth;
165
- kept += segment;
246
+ kept += pendingEscapes + token.text;
247
+ pendingEscapes = '';
166
248
  }
167
- return kept;
249
+ // Every token fitted, so the answer is the input itself — returned rather than reassembled, so
250
+ // a caller comparing the result with what it passed in gets the identity it is testing for.
251
+ return text;
168
252
  }
169
253
  /**
170
254
  * The longest TRAILING run of whole clusters whose total width is at most `maxWidth` — i.e. keep
171
255
  * the tail, lose the head. The mirror of {@link sliceToWidth}, for values whose end is the
172
256
  * informative part (a path's leaf directory).
173
257
  *
174
- * This one materialises the clusters: it walks backwards, and cluster boundaries are only
175
- * derivable from the front. Its callers pass a path or a model id, so the input is a line rather
176
- * than a file.
258
+ * This one materialises the pieces: it walks backwards, and both cluster and sequence boundaries
259
+ * are only derivable from the front. Its callers pass a path or a model id, so the input is a line
260
+ * rather than a file.
261
+ *
262
+ * Keeping the END means the escapes that OPENED a style sit in the discarded head and go with it,
263
+ * so a tail comes back in the terminal's default styling. Only the sequences inside the kept span
264
+ * are carried, which leaves the tail ending in whatever state the whole string ended in — the cut
265
+ * introduces no bleed of its own.
177
266
  */
178
267
  export function sliceEndToWidth(text, maxWidth) {
179
268
  if (maxWidth <= 0)
180
269
  return '';
181
- if (needsWholeStringMeasure(text) && displayWidth(text) <= maxWidth)
182
- return text;
183
- const all = clusters(text);
270
+ const all = [...widthTokens(text)];
184
271
  let width = 0;
185
272
  let kept = '';
273
+ let pendingEscapes = '';
186
274
  for (let index = all.length - 1; index >= 0; index--) {
187
- const clusterWidth = displayWidth(all[index]);
275
+ const token = all[index];
276
+ if (token.escape) {
277
+ pendingEscapes = token.text + pendingEscapes;
278
+ continue;
279
+ }
280
+ const clusterWidth = displayWidth(token.text);
188
281
  if (width + clusterWidth > maxWidth)
189
- break;
282
+ return kept;
190
283
  width += clusterWidth;
191
- kept = all[index] + kept;
284
+ kept = token.text + pendingEscapes + kept;
285
+ pendingEscapes = '';
192
286
  }
193
- return kept;
287
+ return text;
194
288
  }
195
289
  //# sourceMappingURL=displayWidth.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"displayWidth.js","sourceRoot":"","sources":["../../src/utils/displayWidth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,kBAAkB,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;AAEtF;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,WAAW,CAAC,IAAI,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,OAAO,CAAC;IAC3E,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,+FAA+F;AAC/F,SAAS,QAAQ,CAAC,IAAY;IAC5B,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9E,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;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;
32
32
  export declare function readExecPrompt(config: PromptReadConfig): string;
33
33
  /**
34
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.
35
+ * system prompt via {@link buildSystemMessages}: the agent and the subagent profiles.
36
36
  *
37
37
  * It exists because the selection used to be an inline three-branch ternary copied to each of
38
38
  * those sites, and a command missing from one copy is silently served the CHAT prompt — the
@@ -117,7 +117,7 @@ export function readExecPrompt(config) {
117
117
  }
118
118
  /**
119
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.
120
+ * system prompt via {@link buildSystemMessages}: the agent and the subagent profiles.
121
121
  *
122
122
  * It exists because the selection used to be an inline three-branch ternary copied to each of
123
123
  * those sites, and a command missing from one copy is silently served the CHAT prompt — the
@@ -93,9 +93,9 @@ export interface CommitCoAuthor {
93
93
  * it literally (the overwhelmingly common case, and a literal name is what makes the instruction
94
94
  * actionable); when it is not, the note names no tool, keeps both prohibitions and the file form,
95
95
  * and supplies the compliant path that remains: do not commit, and hand the message back to the
96
- * user. That branch states no availability claim of its own — the backends read the same
97
- * `filesystem` value but register filesystem tools differently, so a note asserting "you have no
98
- * file-writing tool" could be flatly false on one of them.
96
+ * user. That branch states no availability claim of its own — registering filesystem tools is the
97
+ * agent's decision, made from the same `filesystem` value, so a note asserting "you have no
98
+ * file-writing tool" could be flatly false.
99
99
  *
100
100
  * The note's prose carries **no backtick and no other markup** — including no angle-bracket
101
101
  * placeholder: it is the one piece of guidance whose subject is how to write a commit message, so
@@ -117,9 +117,9 @@ export function appendCwdNote(systemPrompt, cwd) {
117
117
  * it literally (the overwhelmingly common case, and a literal name is what makes the instruction
118
118
  * actionable); when it is not, the note names no tool, keeps both prohibitions and the file form,
119
119
  * and supplies the compliant path that remains: do not commit, and hand the message back to the
120
- * user. That branch states no availability claim of its own — the backends read the same
121
- * `filesystem` value but register filesystem tools differently, so a note asserting "you have no
122
- * file-writing tool" could be flatly false on one of them.
120
+ * user. That branch states no availability claim of its own — registering filesystem tools is the
121
+ * agent's decision, made from the same `filesystem` value, so a note asserting "you have no
122
+ * file-writing tool" could be flatly false.
123
123
  *
124
124
  * The note's prose carries **no backtick and no other markup** — including no angle-bracket
125
125
  * placeholder: it is the one piece of guidance whose subject is how to write a commit message, so