@gaunt-sloth/core 2.0.0-alpha.9 → 2.0.0-beta.1

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 (275) hide show
  1. package/.gsloth.review.md +2 -0
  2. package/README.md +71 -20
  3. package/dist/config/colour.d.ts +38 -0
  4. package/dist/config/colour.js +36 -0
  5. package/dist/config/colour.js.map +1 -0
  6. package/dist/config/configDiscovery.d.ts +79 -0
  7. package/dist/config/configDiscovery.js +80 -0
  8. package/dist/config/configDiscovery.js.map +1 -0
  9. package/dist/config/defaults.d.ts +20 -20
  10. package/dist/config/defaults.js +10 -8
  11. package/dist/config/defaults.js.map +1 -1
  12. package/dist/config/filesystem-tools.d.ts +41 -0
  13. package/dist/config/filesystem-tools.js +56 -0
  14. package/dist/config/filesystem-tools.js.map +1 -0
  15. package/dist/config/loader.d.ts +171 -19
  16. package/dist/config/loader.js +1054 -144
  17. package/dist/config/loader.js.map +1 -1
  18. package/dist/config/mouse.d.ts +50 -0
  19. package/dist/config/mouse.js +44 -0
  20. package/dist/config/mouse.js.map +1 -0
  21. package/dist/config/profiles.d.ts +68 -0
  22. package/dist/config/profiles.js +93 -0
  23. package/dist/config/profiles.js.map +1 -0
  24. package/dist/config/providerKeys.d.ts +69 -0
  25. package/dist/config/providerKeys.js +69 -0
  26. package/dist/config/providerKeys.js.map +1 -0
  27. package/dist/config/schema.d.ts +2671 -138
  28. package/dist/config/schema.js +1361 -85
  29. package/dist/config/schema.js.map +1 -1
  30. package/dist/config/shell-policy.d.ts +899 -111
  31. package/dist/config/shell-policy.js +800 -70
  32. package/dist/config/shell-policy.js.map +1 -1
  33. package/dist/config/tool-descriptions.d.ts +211 -0
  34. package/dist/config/tool-descriptions.js +272 -0
  35. package/dist/config/tool-descriptions.js.map +1 -0
  36. package/dist/config/types.d.ts +352 -41
  37. package/dist/config/types.js +1 -0
  38. package/dist/config/types.js.map +1 -1
  39. package/dist/config.d.ts +35 -1
  40. package/dist/config.js +16 -1
  41. package/dist/config.js.map +1 -1
  42. package/dist/constants.d.ts +28 -1
  43. package/dist/constants.js +28 -1
  44. package/dist/constants.js.map +1 -1
  45. package/dist/core/GthAbstractAgent.d.ts +166 -11
  46. package/dist/core/GthAbstractAgent.js +484 -45
  47. package/dist/core/GthAbstractAgent.js.map +1 -1
  48. package/dist/core/GthAgentRunner.d.ts +543 -57
  49. package/dist/core/GthAgentRunner.js +1494 -140
  50. package/dist/core/GthAgentRunner.js.map +1 -1
  51. package/dist/core/GthLangChainAgent.d.ts +117 -2
  52. package/dist/core/GthLangChainAgent.js +602 -29
  53. package/dist/core/GthLangChainAgent.js.map +1 -1
  54. package/dist/core/approvals/annotations.d.ts +122 -0
  55. package/dist/core/approvals/annotations.js +137 -0
  56. package/dist/core/approvals/annotations.js.map +1 -0
  57. package/dist/core/approvals/grants.d.ts +216 -0
  58. package/dist/core/approvals/grants.js +469 -0
  59. package/dist/core/approvals/grants.js.map +1 -0
  60. package/dist/core/approvals/matcher.d.ts +202 -0
  61. package/dist/core/approvals/matcher.js +267 -0
  62. package/dist/core/approvals/matcher.js.map +1 -0
  63. package/dist/core/approvals/mcpSubjects.d.ts +40 -0
  64. package/dist/core/approvals/mcpSubjects.js +99 -0
  65. package/dist/core/approvals/mcpSubjects.js.map +1 -0
  66. package/dist/core/approvals/promptHeader.d.ts +28 -0
  67. package/dist/core/approvals/promptHeader.js +62 -0
  68. package/dist/core/approvals/promptHeader.js.map +1 -0
  69. package/dist/core/approvals/toolAnnotationSources.d.ts +105 -0
  70. package/dist/core/approvals/toolAnnotationSources.js +277 -0
  71. package/dist/core/approvals/toolAnnotationSources.js.map +1 -0
  72. package/dist/core/approvals/toolHost.d.ts +46 -0
  73. package/dist/core/approvals/toolHost.js +108 -0
  74. package/dist/core/approvals/toolHost.js.map +1 -0
  75. package/dist/core/debugCapture.d.ts +74 -0
  76. package/dist/core/debugCapture.js +100 -0
  77. package/dist/core/debugCapture.js.map +1 -0
  78. package/dist/core/gthLeanAgentFactory.d.ts +4 -4
  79. package/dist/core/gthLeanAgentFactory.js +4 -4
  80. package/dist/core/launchBanner.d.ts +127 -0
  81. package/dist/core/launchBanner.js +414 -0
  82. package/dist/core/launchBanner.js.map +1 -0
  83. package/dist/core/modelLabel.d.ts +19 -0
  84. package/dist/core/modelLabel.js +26 -0
  85. package/dist/core/modelLabel.js.map +1 -0
  86. package/dist/core/plainToolIndication.d.ts +15 -0
  87. package/dist/core/plainToolIndication.js +174 -0
  88. package/dist/core/plainToolIndication.js.map +1 -0
  89. package/dist/core/reasoningBlocks.d.ts +65 -0
  90. package/dist/core/reasoningBlocks.js +103 -0
  91. package/dist/core/reasoningBlocks.js.map +1 -0
  92. package/dist/core/refusal.d.ts +53 -0
  93. package/dist/core/refusal.js +133 -0
  94. package/dist/core/refusal.js.map +1 -0
  95. package/dist/core/runHeader.d.ts +38 -0
  96. package/dist/core/runHeader.js +42 -0
  97. package/dist/core/runHeader.js.map +1 -0
  98. package/dist/core/runStats.d.ts +14 -3
  99. package/dist/core/runStats.js +48 -3
  100. package/dist/core/runStats.js.map +1 -1
  101. package/dist/core/shell/ShellCommandFailedError.d.ts +3 -4
  102. package/dist/core/shell/ShellCommandFailedError.js +3 -4
  103. package/dist/core/shell/ShellCommandFailedError.js.map +1 -1
  104. package/dist/core/shell/abstention.d.ts +88 -0
  105. package/dist/core/shell/abstention.js +184 -0
  106. package/dist/core/shell/abstention.js.map +1 -0
  107. package/dist/core/shell/approvalCapture.d.ts +271 -0
  108. package/dist/core/shell/approvalCapture.js +108 -0
  109. package/dist/core/shell/approvalCapture.js.map +1 -0
  110. package/dist/core/shell/approvalStop.d.ts +123 -0
  111. package/dist/core/shell/approvalStop.js +269 -0
  112. package/dist/core/shell/approvalStop.js.map +1 -0
  113. package/dist/core/shell/arity.d.ts +6 -0
  114. package/dist/core/shell/arity.js +20 -6
  115. package/dist/core/shell/arity.js.map +1 -1
  116. package/dist/core/shell/denylist.d.ts +11 -0
  117. package/dist/core/shell/denylist.js +37 -0
  118. package/dist/core/shell/denylist.js.map +1 -0
  119. package/dist/core/shell/escalationSeverity.d.ts +141 -0
  120. package/dist/core/shell/escalationSeverity.js +89 -0
  121. package/dist/core/shell/escalationSeverity.js.map +1 -0
  122. package/dist/core/shell/framing.d.ts +190 -0
  123. package/dist/core/shell/framing.js +633 -0
  124. package/dist/core/shell/framing.js.map +1 -0
  125. package/dist/core/shell/hardline.d.ts +103 -0
  126. package/dist/core/shell/hardline.js +780 -0
  127. package/dist/core/shell/hardline.js.map +1 -0
  128. package/dist/core/shell/negotiation.d.ts +328 -0
  129. package/dist/core/shell/negotiation.js +488 -0
  130. package/dist/core/shell/negotiation.js.map +1 -0
  131. package/dist/core/shell/normalize.d.ts +44 -4
  132. package/dist/core/shell/normalize.js +61 -7
  133. package/dist/core/shell/normalize.js.map +1 -1
  134. package/dist/core/shell/openWorld.d.ts +263 -0
  135. package/dist/core/shell/openWorld.js +1188 -0
  136. package/dist/core/shell/openWorld.js.map +1 -0
  137. package/dist/core/shell/rater.d.ts +873 -0
  138. package/dist/core/shell/rater.js +1454 -0
  139. package/dist/core/shell/rater.js.map +1 -0
  140. package/dist/core/shell/raterModel.d.ts +41 -0
  141. package/dist/core/shell/raterModel.js +51 -0
  142. package/dist/core/shell/raterModel.js.map +1 -0
  143. package/dist/core/shell/raterVocabulary.d.ts +121 -0
  144. package/dist/core/shell/raterVocabulary.js +116 -0
  145. package/dist/core/shell/raterVocabulary.js.map +1 -0
  146. package/dist/core/shell/rejection.d.ts +69 -0
  147. package/dist/core/shell/rejection.js +38 -0
  148. package/dist/core/shell/rejection.js.map +1 -0
  149. package/dist/core/toolCallRepair/grammar.d.ts +41 -0
  150. package/dist/core/toolCallRepair/grammar.js +116 -0
  151. package/dist/core/toolCallRepair/grammar.js.map +1 -0
  152. package/dist/core/toolCallRepair/index.d.ts +2 -0
  153. package/dist/core/toolCallRepair/index.js +7 -0
  154. package/dist/core/toolCallRepair/index.js.map +1 -0
  155. package/dist/core/toolCallRepair/payload.d.ts +36 -0
  156. package/dist/core/toolCallRepair/payload.js +341 -0
  157. package/dist/core/toolCallRepair/payload.js.map +1 -0
  158. package/dist/core/toolCallRepair/promote.d.ts +45 -0
  159. package/dist/core/toolCallRepair/promote.js +90 -0
  160. package/dist/core/toolCallRepair/promote.js.map +1 -0
  161. package/dist/core/toolDisplay.d.ts +123 -0
  162. package/dist/core/toolDisplay.js +451 -0
  163. package/dist/core/toolDisplay.js.map +1 -0
  164. package/dist/core/toolOutputChannel.d.ts +95 -0
  165. package/dist/core/toolOutputChannel.js +165 -0
  166. package/dist/core/toolOutputChannel.js.map +1 -0
  167. package/dist/core/types.d.ts +349 -16
  168. package/dist/core/types.js.map +1 -1
  169. package/dist/history/historyFormat.d.ts +12 -3
  170. package/dist/history/historyFormat.js +50 -8
  171. package/dist/history/historyFormat.js.map +1 -1
  172. package/dist/history/historyStore.d.ts +77 -0
  173. package/dist/history/historyStore.js +173 -6
  174. package/dist/history/historyStore.js.map +1 -1
  175. package/dist/history/recordSession.d.ts +10 -1
  176. package/dist/history/recordSession.js +27 -0
  177. package/dist/history/recordSession.js.map +1 -1
  178. package/dist/providers/anthropic.js +12 -0
  179. package/dist/providers/anthropic.js.map +1 -1
  180. package/dist/providers/configurationPassthrough.d.ts +107 -0
  181. package/dist/providers/configurationPassthrough.js +148 -0
  182. package/dist/providers/configurationPassthrough.js.map +1 -0
  183. package/dist/providers/geminiSchemaSanitizer.d.ts +55 -0
  184. package/dist/providers/geminiSchemaSanitizer.js +347 -0
  185. package/dist/providers/geminiSchemaSanitizer.js.map +1 -0
  186. package/dist/providers/geminiThinking.d.ts +60 -0
  187. package/dist/providers/geminiThinking.js +92 -0
  188. package/dist/providers/geminiThinking.js.map +1 -0
  189. package/dist/providers/google-genai.js +18 -1
  190. package/dist/providers/google-genai.js.map +1 -1
  191. package/dist/providers/groq.js +12 -0
  192. package/dist/providers/groq.js.map +1 -1
  193. package/dist/providers/huggingface.d.ts +25 -0
  194. package/dist/providers/huggingface.js +69 -0
  195. package/dist/providers/huggingface.js.map +1 -0
  196. package/dist/providers/modelCatalog.d.ts +109 -0
  197. package/dist/providers/modelCatalog.js +245 -0
  198. package/dist/providers/modelCatalog.js.map +1 -0
  199. package/dist/providers/modelDiscovery.d.ts +99 -5
  200. package/dist/providers/modelDiscovery.js +191 -35
  201. package/dist/providers/modelDiscovery.js.map +1 -1
  202. package/dist/providers/ollama.d.ts +18 -4
  203. package/dist/providers/ollama.js +67 -37
  204. package/dist/providers/ollama.js.map +1 -1
  205. package/dist/providers/openai.js +34 -0
  206. package/dist/providers/openai.js.map +1 -1
  207. package/dist/providers/openrouter.d.ts +26 -4
  208. package/dist/providers/openrouter.js +83 -26
  209. package/dist/providers/openrouter.js.map +1 -1
  210. package/dist/providers/vertexai.js +19 -1
  211. package/dist/providers/vertexai.js.map +1 -1
  212. package/dist/providers/xai.js +20 -0
  213. package/dist/providers/xai.js.map +1 -1
  214. package/dist/runtime/askStructured.d.ts +105 -0
  215. package/dist/runtime/askStructured.js +120 -0
  216. package/dist/runtime/askStructured.js.map +1 -0
  217. package/dist/runtime/conversation.d.ts +64 -0
  218. package/dist/runtime/conversation.js +171 -0
  219. package/dist/runtime/conversation.js.map +1 -0
  220. package/dist/runtime/singleShot.d.ts +37 -6
  221. package/dist/runtime/singleShot.js +113 -67
  222. package/dist/runtime/singleShot.js.map +1 -1
  223. package/dist/runtime/structuredOutput.d.ts +104 -0
  224. package/dist/runtime/structuredOutput.js +393 -0
  225. package/dist/runtime/structuredOutput.js.map +1 -0
  226. package/dist/utils/ProgressIndicator.d.ts +21 -0
  227. package/dist/utils/ProgressIndicator.js +30 -3
  228. package/dist/utils/ProgressIndicator.js.map +1 -1
  229. package/dist/utils/aiignoreUtils.js.map +1 -1
  230. package/dist/utils/binaryOutputUtils.js.map +1 -1
  231. package/dist/utils/consoleUtils.d.ts +95 -0
  232. package/dist/utils/consoleUtils.js +112 -2
  233. package/dist/utils/consoleUtils.js.map +1 -1
  234. package/dist/utils/crashHandler.d.ts +87 -0
  235. package/dist/utils/crashHandler.js +128 -0
  236. package/dist/utils/crashHandler.js.map +1 -0
  237. package/dist/utils/debugDump.d.ts +134 -0
  238. package/dist/utils/debugDump.js +381 -0
  239. package/dist/utils/debugDump.js.map +1 -0
  240. package/dist/utils/debugUtils.d.ts +13 -4
  241. package/dist/utils/debugUtils.js +36 -13
  242. package/dist/utils/debugUtils.js.map +1 -1
  243. package/dist/utils/displayWidth.d.ts +53 -0
  244. package/dist/utils/displayWidth.js +195 -0
  245. package/dist/utils/displayWidth.js.map +1 -0
  246. package/dist/utils/fileUtils.js.map +1 -1
  247. package/dist/utils/globalConfigUtils.d.ts +14 -2
  248. package/dist/utils/globalConfigUtils.js +22 -4
  249. package/dist/utils/globalConfigUtils.js.map +1 -1
  250. package/dist/utils/llmUtils.d.ts +39 -8
  251. package/dist/utils/llmUtils.js +76 -8
  252. package/dist/utils/llmUtils.js.map +1 -1
  253. package/dist/utils/redactSecrets.d.ts +63 -0
  254. package/dist/utils/redactSecrets.js +286 -0
  255. package/dist/utils/redactSecrets.js.map +1 -0
  256. package/dist/utils/systemPromptNotes.d.ts +222 -0
  257. package/dist/utils/systemPromptNotes.js +338 -0
  258. package/dist/utils/systemPromptNotes.js.map +1 -0
  259. package/dist/utils/systemUtils.d.ts +18 -1
  260. package/dist/utils/systemUtils.js +38 -3
  261. package/dist/utils/systemUtils.js.map +1 -1
  262. package/dist/utils/toolMatching.d.ts +30 -0
  263. package/dist/utils/toolMatching.js +44 -0
  264. package/dist/utils/toolMatching.js.map +1 -0
  265. package/dist/utils/untrustedText.d.ts +86 -0
  266. package/dist/utils/untrustedText.js +101 -0
  267. package/dist/utils/untrustedText.js.map +1 -0
  268. package/package.json +21 -7
  269. package/schema/gsloth-config.schema.json +1921 -326
  270. package/dist/core/shell/allowlist.d.ts +0 -75
  271. package/dist/core/shell/allowlist.js +0 -187
  272. package/dist/core/shell/allowlist.js.map +0 -1
  273. package/dist/core/shell/judge.d.ts +0 -161
  274. package/dist/core/shell/judge.js +0 -261
  275. package/dist/core/shell/judge.js.map +0 -1
@@ -10,7 +10,14 @@
10
10
  * message chunks / `ToolMessage`s as they arrive), across providers whose message shapes vary.
11
11
  * Nothing here may throw into a run — a missing/odd field just means that datum is skipped.
12
12
  */
13
- import type { GthRunStats } from '#src/core/types.js';
13
+ import type { GthRunStats, GthToolResult } from '#src/core/types.js';
14
+ /**
15
+ * BATCH-21 — cap on a captured tool-result `content` (characters). Keeps a giant payload (a whole
16
+ * file read, a long shell log) from bloating run stats; anything longer is truncated to this
17
+ * length. Sized so realistic structured payloads (the `gth eval` tool-result-assertion use case)
18
+ * survive intact.
19
+ */
20
+ export declare const TOOL_RESULT_CONTENT_CAP = 8192;
14
21
  /** Mutable tally behind {@link finalizeRunStats}; see {@link createRunStatsAccumulator}. */
15
22
  export interface RunStatsAccumulator {
16
23
  /** Running sum of input/prompt tokens. */
@@ -21,15 +28,19 @@ export interface RunStatsAccumulator {
21
28
  sawUsage: boolean;
22
29
  /** Deduplicated set of invoked tool names. */
23
30
  tools: Set<string>;
31
+ /** BATCH-21 — one record per executed tool result (`ToolMessage`), in arrival order, un-deduped. */
32
+ toolResults: GthToolResult[];
24
33
  }
25
34
  /** A fresh, empty accumulator. */
26
35
  export declare function createRunStatsAccumulator(): RunStatsAccumulator;
27
36
  /**
28
37
  * Fold one LangChain message (or message chunk) into the accumulator. Fail-soft: any unexpected
29
38
  * shape is swallowed so a run is never affected. Harvests, when present:
30
- * - `usage_metadata.input_tokens` / `.output_tokens` (summed; marks `sawUsage`), and
39
+ * - `usage_metadata.input_tokens` / `.output_tokens` (summed; marks `sawUsage`),
31
40
  * - tool names from an AIMessage's requested `tool_calls[].name` AND from a `ToolMessage`'s own
32
- * `.name` (the executed tool), so both "requested" and "executed" tools are captured.
41
+ * `.name` (the executed tool), so both "requested" and "executed" tools are captured, and
42
+ * - (BATCH-21) a per-`ToolMessage` result record — `name` + `isError` (from `.status`) + capped
43
+ * `content` — into `acc.toolResults`, so tool-RESULT assertions can grade what a tool returned.
33
44
  */
34
45
  export declare function accumulateMessage(acc: RunStatsAccumulator, message: unknown): void;
35
46
  /** Freeze the accumulator into the public {@link GthRunStats}. Tokens omitted unless observed. */
@@ -1,13 +1,47 @@
1
+ /**
2
+ * BATCH-21 — cap on a captured tool-result `content` (characters). Keeps a giant payload (a whole
3
+ * file read, a long shell log) from bloating run stats; anything longer is truncated to this
4
+ * length. Sized so realistic structured payloads (the `gth eval` tool-result-assertion use case)
5
+ * survive intact.
6
+ */
7
+ export const TOOL_RESULT_CONTENT_CAP = 8192;
1
8
  /** A fresh, empty accumulator. */
2
9
  export function createRunStatsAccumulator() {
3
- return { input: 0, output: 0, sawUsage: false, tools: new Set() };
10
+ return { input: 0, output: 0, sawUsage: false, tools: new Set(), toolResults: [] };
11
+ }
12
+ /**
13
+ * BATCH-21 — derive a tool result's text payload from a `ToolMessage.content`, fail-soft. A string
14
+ * passes through; anything else non-`undefined` is JSON-stringified (the same derivation the
15
+ * `tool_result` stream event uses in `GthAbstractAgent`); the result is capped at
16
+ * {@link TOOL_RESULT_CONTENT_CAP}. Returns `undefined` (payload omitted) when nothing textual can
17
+ * be derived — never throws.
18
+ */
19
+ function toolResultContentText(content) {
20
+ try {
21
+ let text;
22
+ if (typeof content === 'string') {
23
+ text = content;
24
+ }
25
+ else if (content !== undefined) {
26
+ text = JSON.stringify(content);
27
+ }
28
+ if (text === undefined)
29
+ return undefined;
30
+ return text.length > TOOL_RESULT_CONTENT_CAP ? text.slice(0, TOOL_RESULT_CONTENT_CAP) : text;
31
+ }
32
+ catch {
33
+ /* fail-soft: an unstringifiable payload just means no content is recorded */
34
+ return undefined;
35
+ }
4
36
  }
5
37
  /**
6
38
  * Fold one LangChain message (or message chunk) into the accumulator. Fail-soft: any unexpected
7
39
  * shape is swallowed so a run is never affected. Harvests, when present:
8
- * - `usage_metadata.input_tokens` / `.output_tokens` (summed; marks `sawUsage`), and
40
+ * - `usage_metadata.input_tokens` / `.output_tokens` (summed; marks `sawUsage`),
9
41
  * - tool names from an AIMessage's requested `tool_calls[].name` AND from a `ToolMessage`'s own
10
- * `.name` (the executed tool), so both "requested" and "executed" tools are captured.
42
+ * `.name` (the executed tool), so both "requested" and "executed" tools are captured, and
43
+ * - (BATCH-21) a per-`ToolMessage` result record — `name` + `isError` (from `.status`) + capped
44
+ * `content` — into `acc.toolResults`, so tool-RESULT assertions can grade what a tool returned.
11
45
  */
12
46
  export function accumulateMessage(acc, message) {
13
47
  try {
@@ -39,6 +73,16 @@ export function accumulateMessage(acc, message) {
39
73
  const type = typeof m.getType === 'function' ? m.getType() : m._getType?.();
40
74
  if (type === 'tool' && typeof m.name === 'string' && m.name.length > 0) {
41
75
  acc.tools.add(m.name);
76
+ // BATCH-21 — capture the RESULT record too (same capture site, same fail-soft discipline):
77
+ // `.status === 'error'` is LangChain's real tool-error signal, `.content` the returned
78
+ // payload (capped; omitted when no text can be derived). One record per ToolMessage, in
79
+ // arrival order — deliberately NOT deduplicated, unlike the name set above.
80
+ const content = toolResultContentText(m.content);
81
+ acc.toolResults.push({
82
+ name: m.name,
83
+ isError: m.status === 'error',
84
+ ...(content !== undefined ? { content } : {}),
85
+ });
42
86
  }
43
87
  }
44
88
  catch {
@@ -51,6 +95,7 @@ export function finalizeRunStats(acc) {
51
95
  tokensInput: acc.sawUsage ? acc.input : undefined,
52
96
  tokensOutput: acc.sawUsage ? acc.output : undefined,
53
97
  tools: [...acc.tools],
98
+ toolResults: [...acc.toolResults],
54
99
  };
55
100
  }
56
101
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"runStats.js","sourceRoot":"","sources":["../../src/core/runStats.ts"],"names":[],"mappings":"AA0BA,kCAAkC;AAClC,MAAM,UAAU,yBAAyB;IACvC,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,GAAG,EAAU,EAAE,CAAC;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,CAAC,IAAI,CAAC;gBACnB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,OAAO,EAAE,CAAC,CAAC,MAAM,KAAK,OAAO;gBAC7B,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,qDAAqD;IACvD,CAAC;AACH,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,gBAAgB,CAAC,GAAwB;IACvD,OAAO;QACL,WAAW,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;QACjD,YAAY,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QACnD,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC;QACrB,WAAW,EAAE,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC;KAClC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,QAAiB;IAC/C,MAAM,GAAG,GAAG,yBAAyB,EAAE,CAAC;IACxC,IAAI,CAAC;QACH,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,KAAK,MAAM,CAAC,IAAI,QAAQ;gBAAE,iBAAiB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,eAAe;IACjB,CAAC;IACD,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC"}
@@ -6,10 +6,9 @@
6
6
  * body so a softening middleware can hand the model the exact observation it saw before — the
7
7
  * only change being that the tool result's status flips to `'error'` (→ `isError` → the ✗ glyph).
8
8
  *
9
- * Canonical home is **core** so BOTH agents can recognise a shell failure without violating the
10
- * `agent → core` dependency direction:
11
- * - the deep agent (`code` mode, `@gaunt-sloth/agent` `GthDeepShellExitSoftening`) and
12
- * - the lean agent (`exec` / `ask --write`, core `GthLangChainAgent` `GthLeanShellExitSoftening`).
9
+ * Canonical home is **core** so any agent can recognise a shell failure without violating the
10
+ * `agent → core` dependency direction — today the lean agent (`exec` / `ask --write`, core
11
+ * `GthLangChainAgent` `GthLeanShellExitSoftening`).
13
12
  *
14
13
  * The throw site (`GthDevToolkit.executeCommand`) lives in the `agent` package and re-exports this
15
14
  * class, so its `throw new ShellCommandFailedError(...)` is one and the same type both agents catch.
@@ -6,10 +6,9 @@
6
6
  * body so a softening middleware can hand the model the exact observation it saw before — the
7
7
  * only change being that the tool result's status flips to `'error'` (→ `isError` → the ✗ glyph).
8
8
  *
9
- * Canonical home is **core** so BOTH agents can recognise a shell failure without violating the
10
- * `agent → core` dependency direction:
11
- * - the deep agent (`code` mode, `@gaunt-sloth/agent` `GthDeepShellExitSoftening`) and
12
- * - the lean agent (`exec` / `ask --write`, core `GthLangChainAgent` `GthLeanShellExitSoftening`).
9
+ * Canonical home is **core** so any agent can recognise a shell failure without violating the
10
+ * `agent → core` dependency direction — today the lean agent (`exec` / `ask --write`, core
11
+ * `GthLangChainAgent` `GthLeanShellExitSoftening`).
13
12
  *
14
13
  * The throw site (`GthDevToolkit.executeCommand`) lives in the `agent` package and re-exports this
15
14
  * class, so its `throw new ShellCommandFailedError(...)` is one and the same type both agents catch.
@@ -1 +1 @@
1
- {"version":3,"file":"ShellCommandFailedError.js","sourceRoot":"","sources":["../../../src/core/shell/ShellCommandFailedError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,iGAAiG;IACxF,MAAM,CAAS;IACxB,oGAAoG;IAC3F,QAAQ,CAAgB;IACjC,kDAAkD;IACzC,OAAO,CAAS;IACzB,4FAA4F;IACnF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,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAClC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CAAC,CAAU;IAClD,IAAI,CAAC,YAAY,uBAAuB;QAAE,OAAO,IAAI,CAAC;IACtD,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACT,CAAwB,CAAC,IAAI,KAAK,yBAAyB;QAC5D,OAAQ,CAA0B,CAAC,MAAM,KAAK,QAAQ;QACtD,OAAQ,CAA2B,CAAC,OAAO,KAAK,QAAQ;QACxD,OAAQ,CAA4B,CAAC,QAAQ,KAAK,QAAQ,CAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The shape in the command that the gate's parser could not resolve.
3
+ *
4
+ * These are FORMS, not judgements — nothing here says a command is dangerous, and nothing here is a
5
+ * rating. They exist to select the sentence the rater is shown.
6
+ */
7
+ export type AbstentionMechanism =
8
+ /** A git commit whose message contains a substitution the SHELL runs before git sees it. */
9
+ 'commit-message-substitution'
10
+ /** More than one command: `;`, `&`, `&&`, `|`, `||`, or a line break. */
11
+ | 'composition'
12
+ /** Command / variable / process substitution: `$(…)`, backticks, `${…}`, `<(…)`. */
13
+ | 'substitution'
14
+ /** A stream redirect: `>`, `>>`, `<`, `2>`, `&>`. */
15
+ | 'redirect'
16
+ /** None of the above — an unbalanced quote, an empty command, or no resolvable program name. */
17
+ | 'unparseable';
18
+ /** What the parser saw in a command it could not resolve: the shapes, and the note for each. */
19
+ export interface AbstentionDefect {
20
+ /** The most specific mechanism found — what the note leads with. */
21
+ mechanism: AbstentionMechanism;
22
+ /** Every mechanism found, in note order. A command may carry more than one. */
23
+ mechanisms: AbstentionMechanism[];
24
+ /** One note per mechanism, in the same order. Never empty. */
25
+ notes: string[];
26
+ }
27
+ /**
28
+ * **The per-family note text — one distinct string per {@link AbstentionMechanism}.**
29
+ *
30
+ * Typed as a total `Record`, so adding a mechanism is a COMPILE ERROR until someone writes its
31
+ * sentence. A family that silently fell back to another family's note would be the failure this
32
+ * table exists to prevent: [[QA-17]] measured that the note's effect is family-specific, and
33
+ * `docs/test-sessions/qa-17-substitution-note-2026-08-03/` records a narrowing by family name that
34
+ * was FALSIFIED — `gh pr comment 42 --body "…"` carrying an executing substitution classifies as
35
+ * generic `substitution`, and three of three hosted raters called it safe unassisted.
36
+ *
37
+ * Every entry states a fact about what THE SHELL does, and then asks a question. Neither is a
38
+ * verdict about the command in front of the rater, which is what keeps the note neutral while still
39
+ * carrying the mechanism that the measurement showed is load-bearing.
40
+ */
41
+ export declare const MECHANISM_NOTES: Readonly<Record<AbstentionMechanism, string>>;
42
+ /**
43
+ * Classify a command the gate's parser could not resolve, or return `null` when it resolves.
44
+ *
45
+ * **The `null` arm is the guard, and it is structural on purpose.** Every mechanism below is a
46
+ * regex, and `unparseable` is the fallback — so without this gate the function would classify `ls
47
+ * -la` as `unparseable` and a note would be attached to every command in the session. The predicate
48
+ * is {@link classifyCommand}'s own, not a second reading of it, so the note appears on exactly the
49
+ * set of commands the gate could not resolve and on no others.
50
+ *
51
+ * Detection runs on the NORMALIZED command (the same form `classifyCommand` refused), so obfuscation
52
+ * that the normalizer collapses cannot hide a mechanism from the note — while the command shown to
53
+ * the rater stays the one the rater is being asked about, fenced by its own caller.
54
+ *
55
+ * The line-break check reads the RAW command, exactly as `classifyCommand` does: the normalizer is
56
+ * not required to preserve that separator, and EXT-55 is the node about what happens when a caller
57
+ * assumes it did.
58
+ *
59
+ * **Order is note order, most specific first**, and `commit-message-substitution` SUPPRESSES the
60
+ * generic substitution note it is a special case of — telling the rater the same thing twice about
61
+ * one `$(…)` spends attention on a repetition.
62
+ *
63
+ * @param command The raw command string as the model proposed it.
64
+ * @returns What the parser saw, or `null` when the command's target statically resolves.
65
+ */
66
+ export declare function describeAbstention(command: string): AbstentionDefect | null;
67
+ /**
68
+ * The opening line of the preflight note: **what this is, and what it is not.**
69
+ *
70
+ * It says the finding is about OUR PARSER rather than about the command, and that nothing has been
71
+ * judged. Both halves are load-bearing. The first stops the rater reading the note as a report of
72
+ * something found — the failure mode a bare observation produced, where a rater treats our
73
+ * uncertainty as evidence and either inflates or explains it away. The second is what keeps this
74
+ * note out of the open-world note's register: that one may say the command *"has ALREADY been
75
+ * floored deterministically and will be shown to the user whatever you return"*, and here that
76
+ * sentence would simply be false.
77
+ */
78
+ export declare const PARSER_NOTE_PREAMBLE: string;
79
+ /**
80
+ * Build the neutral preflight note for a command, or `null` when the gate resolved it.
81
+ *
82
+ * One note per mechanism the command carries, most specific first, bulleted when there is more than
83
+ * one — a command can compose AND substitute AND redirect, and a note that mentioned only the first
84
+ * would leave the rater reasoning about a fragment of the shape.
85
+ *
86
+ * @param command The raw command string as the model proposed it.
87
+ */
88
+ export declare function buildParserPreflightNote(command: string): string | null;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * @module core/shell/abstention
3
+ *
4
+ * EXT-81 — **what the RATER is told about a command our parser could not resolve.**
5
+ *
6
+ * `classifyCommand` resolves a command's target, or returns `null` when it cannot. That `null` used
7
+ * to be an ACTION: the gate refused the call before any rating, on the theory that a reading of a
8
+ * command it could not parse was not worth buying. §6.1's rule reverses that — *deterministic checks
9
+ * fire only where we are confident something is a threat; where we cannot tell, the model decides* —
10
+ * and a parser reporting that it could not resolve a string is not a detection of anything. So the
11
+ * finding is now **neutral context handed to the rater**, and the flow is one path: preflight → note
12
+ * → rate → approve / escalate / halt.
13
+ *
14
+ * This module turns the `null` into that note: **which shape the parser saw, and the mechanism that
15
+ * makes the shape worth a second look.** Two properties are the whole design, and each has a
16
+ * measurement behind it ([[QA-17]], `docs/test-sessions/qa-17-substitution-note-2026-08-03/`):
17
+ *
18
+ * - **The note carries the MECHANISM, not just the construct's name.** A bare *"the parser saw a
19
+ * substitution"* observation was measured NEGATIVE on two raters — one became more confidently
20
+ * wrong than with no note at all (*"not executed since it's within double quotes"*), another lost
21
+ * severity against the control. Adding one sentence of mechanism — that a double-quoted argument
22
+ * is not inert prose, because the shell expands it before the outer program runs — is what moved
23
+ * every deployment-class rater to the correct verdict. A bare observation from a component that
24
+ * has just announced it could not read the command reads as DOUBT, and doubt is not information.
25
+ * - **The note is ASSISTANCE, never an accusation.** *"Hey rater, here is a command, please pay
26
+ * attention it includes composition."* No verdict, no severity, no *suspicious*, no *careful*, no
27
+ * *treat this as at least X*, and nothing that caps the outcome — `catastrophic` and `attack` stay
28
+ * reachable. A question is allowed; a question is not a lean. A composition is not a hazard:
29
+ * `cd build && ls`, `npm test && npm run build` and `git add -A && git status` are the
30
+ * overwhelming majority of what this fires on, and a leading note would re-create the very
31
+ * escalation this design removes — laundered through the model instead of the parser, and now
32
+ * unfalsifiable because a model said it.
33
+ *
34
+ * It also states nothing about what the gate will DO with the verdict. The open-world note's shape
35
+ * (*"has ALREADY been floored deterministically and will be shown to the user whatever you
36
+ * return"*) is honest only where a floor exists, and for these families none does.
37
+ *
38
+ * **Scope, deliberately narrow.** Flag what the parser saw and stop. Extracting spans, naming which
39
+ * segment is unresolvable, and drawing on surrounding context all wait for real user trial — the
40
+ * elaborate note is the one most likely to acquire connotation by accident.
41
+ */
42
+ import { classifyCommand } from '#src/core/shell/arity.js';
43
+ import { COMMAND_SEPARATOR_RE, LINE_BREAK_RE, normalizeCommand, } from '#src/core/shell/normalize.js';
44
+ /**
45
+ * **The per-family note text — one distinct string per {@link AbstentionMechanism}.**
46
+ *
47
+ * Typed as a total `Record`, so adding a mechanism is a COMPILE ERROR until someone writes its
48
+ * sentence. A family that silently fell back to another family's note would be the failure this
49
+ * table exists to prevent: [[QA-17]] measured that the note's effect is family-specific, and
50
+ * `docs/test-sessions/qa-17-substitution-note-2026-08-03/` records a narrowing by family name that
51
+ * was FALSIFIED — `gh pr comment 42 --body "…"` carrying an executing substitution classifies as
52
+ * generic `substitution`, and three of three hosted raters called it safe unassisted.
53
+ *
54
+ * Every entry states a fact about what THE SHELL does, and then asks a question. Neither is a
55
+ * verdict about the command in front of the rater, which is what keeps the note neutral while still
56
+ * carrying the mechanism that the measurement showed is load-bearing.
57
+ */
58
+ export const MECHANISM_NOTES = {
59
+ 'commit-message-substitution': 'This is a git commit carrying its message inline, and the message contains a ' +
60
+ 'dollar-parenthesis or a backtick. The SHELL expands that before git ever sees the message, ' +
61
+ 'so the text inside the quotes is not inert prose: double quotes do not stop `$(…)` or a ' +
62
+ 'backtick from running, and git receives whatever it produced. What does the shell run when ' +
63
+ 'it expands that message?',
64
+ composition: 'This command line runs MORE THAN ONE command — a `;`, `&&`, `||`, `|` or a line break ' +
65
+ 'separates them — and the shell runs each part in turn, feeding one into the next where the ' +
66
+ 'separator is a pipe. What does the whole line do once every part has run?',
67
+ substitution: 'This command line contains a substitution — `$(…)`, a backtick, `${…}` or `<(…)`. The SHELL ' +
68
+ 'expands it BEFORE the outer program runs, and hands that program the result. A ' +
69
+ 'double-quoted argument is therefore not inert prose: double quotes do not stop `$(…)` or a ' +
70
+ 'backtick from being run, so a substitution inside what reads as ordinary text is still ' +
71
+ 'executed. What does the shell run when it expands this one?',
72
+ redirect: 'This command line redirects a stream — `>`, `>>`, `<`, `2>` or `&>`. The shell attaches a ' +
73
+ 'file to the program before the program starts, so its output lands in that file rather than ' +
74
+ 'on the terminal, and a `>` truncates the file it names first. Which file is being read or ' +
75
+ 'written here?',
76
+ unparseable: 'The gate could not tokenize this command line at all — most often an unbalanced quote, or no ' +
77
+ 'program name it could identify. So we cannot tell you which program this runs; what is ' +
78
+ 'quoted above is exactly the text that would be handed to the shell. What does it do?',
79
+ };
80
+ /** Process substitution `<(…)` / `>(…)`, which is a SUBSTITUTION and must not also read as a redirect. */
81
+ const PROCESS_SUBSTITUTION_RE = /[<>]\(/g;
82
+ /**
83
+ * Does this look like a `git commit` carrying an inline message?
84
+ *
85
+ * Deliberately a heuristic and not a parser: the command has already defeated the gate's tokenizer,
86
+ * so there is nothing precise left to parse. It is safe to be approximate here because a wrong
87
+ * answer costs at most a less specific note — the rating is bought either way.
88
+ */
89
+ const GIT_COMMIT_RE = /\bgit\b[^\n]*\bcommit\b/i;
90
+ const INLINE_MESSAGE_FLAG_RE = /(^|\s)(-m\b|--message\b|-\w*m\b)/;
91
+ /** Command substitution `$(…)` or a backtick — the two the shell EXECUTES. */
92
+ const EXECUTING_SUBSTITUTION_RE = /\$\(|`/;
93
+ /** Every substitution/expansion form, including the non-executing ones. */
94
+ const ANY_SUBSTITUTION_RE = /\$\(|`|\$\{|[<>]\(/;
95
+ /**
96
+ * Classify a command the gate's parser could not resolve, or return `null` when it resolves.
97
+ *
98
+ * **The `null` arm is the guard, and it is structural on purpose.** Every mechanism below is a
99
+ * regex, and `unparseable` is the fallback — so without this gate the function would classify `ls
100
+ * -la` as `unparseable` and a note would be attached to every command in the session. The predicate
101
+ * is {@link classifyCommand}'s own, not a second reading of it, so the note appears on exactly the
102
+ * set of commands the gate could not resolve and on no others.
103
+ *
104
+ * Detection runs on the NORMALIZED command (the same form `classifyCommand` refused), so obfuscation
105
+ * that the normalizer collapses cannot hide a mechanism from the note — while the command shown to
106
+ * the rater stays the one the rater is being asked about, fenced by its own caller.
107
+ *
108
+ * The line-break check reads the RAW command, exactly as `classifyCommand` does: the normalizer is
109
+ * not required to preserve that separator, and EXT-55 is the node about what happens when a caller
110
+ * assumes it did.
111
+ *
112
+ * **Order is note order, most specific first**, and `commit-message-substitution` SUPPRESSES the
113
+ * generic substitution note it is a special case of — telling the rater the same thing twice about
114
+ * one `$(…)` spends attention on a repetition.
115
+ *
116
+ * @param command The raw command string as the model proposed it.
117
+ * @returns What the parser saw, or `null` when the command's target statically resolves.
118
+ */
119
+ export function describeAbstention(command) {
120
+ if (classifyCommand(command, normalizeCommand) !== null)
121
+ return null;
122
+ const normalized = normalizeCommand(command);
123
+ const composes = COMMAND_SEPARATOR_RE.test(normalized) || LINE_BREAK_RE.test(command.trim());
124
+ const substitutes = ANY_SUBSTITUTION_RE.test(normalized);
125
+ const commitSubstitution = GIT_COMMIT_RE.test(normalized) &&
126
+ INLINE_MESSAGE_FLAG_RE.test(normalized) &&
127
+ EXECUTING_SUBSTITUTION_RE.test(normalized);
128
+ // A redirect is any `<`/`>` that is NOT the opening of a process substitution — that form is
129
+ // already reported as a substitution, and reporting it twice would describe one piece of syntax
130
+ // with two different mechanisms.
131
+ const redirects = /[<>]/.test(normalized.replace(PROCESS_SUBSTITUTION_RE, ''));
132
+ const mechanisms = [];
133
+ if (commitSubstitution)
134
+ mechanisms.push('commit-message-substitution');
135
+ if (composes)
136
+ mechanisms.push('composition');
137
+ if (substitutes && !commitSubstitution)
138
+ mechanisms.push('substitution');
139
+ if (redirects)
140
+ mechanisms.push('redirect');
141
+ // The fallback for the causes that are not a shape at all — an unbalanced quote, an empty
142
+ // command, a command with no resolvable program name — so a note is never empty.
143
+ if (mechanisms.length === 0)
144
+ mechanisms.push('unparseable');
145
+ return {
146
+ mechanism: mechanisms[0],
147
+ mechanisms,
148
+ notes: mechanisms.map((mechanism) => MECHANISM_NOTES[mechanism]),
149
+ };
150
+ }
151
+ /**
152
+ * The opening line of the preflight note: **what this is, and what it is not.**
153
+ *
154
+ * It says the finding is about OUR PARSER rather than about the command, and that nothing has been
155
+ * judged. Both halves are load-bearing. The first stops the rater reading the note as a report of
156
+ * something found — the failure mode a bare observation produced, where a rater treats our
157
+ * uncertainty as evidence and either inflates or explains it away. The second is what keeps this
158
+ * note out of the open-world note's register: that one may say the command *"has ALREADY been
159
+ * floored deterministically and will be shown to the user whatever you return"*, and here that
160
+ * sentence would simply be false.
161
+ */
162
+ export const PARSER_NOTE_PREAMBLE = 'PREFLIGHT NOTE: our command parser could not resolve what this command line runs, so here is ' +
163
+ 'what it did see. This is a fact about OUR PARSER and not a finding about the command — nothing ' +
164
+ 'has been judged, nothing has been floored, and none of this is a verdict or a severity. Rate ' +
165
+ 'the command on its own merits.';
166
+ /**
167
+ * Build the neutral preflight note for a command, or `null` when the gate resolved it.
168
+ *
169
+ * One note per mechanism the command carries, most specific first, bulleted when there is more than
170
+ * one — a command can compose AND substitute AND redirect, and a note that mentioned only the first
171
+ * would leave the rater reasoning about a fragment of the shape.
172
+ *
173
+ * @param command The raw command string as the model proposed it.
174
+ */
175
+ export function buildParserPreflightNote(command) {
176
+ const defect = describeAbstention(command);
177
+ if (defect === null)
178
+ return null;
179
+ const body = defect.notes.length === 1
180
+ ? defect.notes[0]
181
+ : defect.notes.map((note) => `- ${note}`).join('\n');
182
+ return `${PARSER_NOTE_PREAMBLE}\n${body}`;
183
+ }
184
+ //# sourceMappingURL=abstention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstention.js","sourceRoot":"","sources":["../../../src/core/shell/abstention.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AA8BtC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,eAAe,GAAkD;IAC5E,6BAA6B,EAC3B,+EAA+E;QAC/E,6FAA6F;QAC7F,0FAA0F;QAC1F,6FAA6F;QAC7F,0BAA0B;IAC5B,WAAW,EACT,wFAAwF;QACxF,6FAA6F;QAC7F,2EAA2E;IAC7E,YAAY,EACV,8FAA8F;QAC9F,iFAAiF;QACjF,6FAA6F;QAC7F,yFAAyF;QACzF,6DAA6D;IAC/D,QAAQ,EACN,4FAA4F;QAC5F,8FAA8F;QAC9F,4FAA4F;QAC5F,eAAe;IACjB,WAAW,EACT,+FAA+F;QAC/F,yFAAyF;QACzF,sFAAsF;CACzF,CAAC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