@gaunt-sloth/core 2.0.0-alpha.3 → 2.0.0-alpha.31

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 (271) hide show
  1. package/README.md +52 -20
  2. package/dist/config/colour.d.ts +38 -0
  3. package/dist/config/colour.js +36 -0
  4. package/dist/config/colour.js.map +1 -0
  5. package/dist/config/defaults.d.ts +84 -0
  6. package/dist/config/defaults.js +99 -0
  7. package/dist/config/defaults.js.map +1 -0
  8. package/dist/config/filesystem-tools.d.ts +41 -0
  9. package/dist/config/filesystem-tools.js +56 -0
  10. package/dist/config/filesystem-tools.js.map +1 -0
  11. package/dist/config/jsonc.d.ts +12 -0
  12. package/dist/config/jsonc.js +41 -0
  13. package/dist/config/jsonc.js.map +1 -0
  14. package/dist/config/loader.d.ts +246 -0
  15. package/dist/config/loader.js +1321 -0
  16. package/dist/config/loader.js.map +1 -0
  17. package/dist/config/mouse.d.ts +50 -0
  18. package/dist/config/mouse.js +44 -0
  19. package/dist/config/mouse.js.map +1 -0
  20. package/dist/config/profiles.d.ts +68 -0
  21. package/dist/config/profiles.js +93 -0
  22. package/dist/config/profiles.js.map +1 -0
  23. package/dist/config/providerKeys.d.ts +69 -0
  24. package/dist/config/providerKeys.js +69 -0
  25. package/dist/config/providerKeys.js.map +1 -0
  26. package/dist/config/schema.d.ts +2999 -0
  27. package/dist/config/schema.js +1519 -0
  28. package/dist/config/schema.js.map +1 -0
  29. package/dist/config/shell-policy.d.ts +896 -0
  30. package/dist/config/shell-policy.js +750 -0
  31. package/dist/config/shell-policy.js.map +1 -0
  32. package/dist/config/tool-descriptions.d.ts +211 -0
  33. package/dist/config/tool-descriptions.js +272 -0
  34. package/dist/config/tool-descriptions.js.map +1 -0
  35. package/dist/config/types.d.ts +760 -0
  36. package/dist/config/types.js +13 -0
  37. package/dist/config/types.js.map +1 -0
  38. package/dist/config.d.ts +34 -827
  39. package/dist/config.js +25 -657
  40. package/dist/config.js.map +1 -1
  41. package/dist/constants.d.ts +46 -0
  42. package/dist/constants.js +46 -0
  43. package/dist/constants.js.map +1 -1
  44. package/dist/core/GthAbstractAgent.d.ts +135 -2
  45. package/dist/core/GthAbstractAgent.js +496 -30
  46. package/dist/core/GthAbstractAgent.js.map +1 -1
  47. package/dist/core/GthAgentRunner.d.ts +568 -54
  48. package/dist/core/GthAgentRunner.js +1537 -136
  49. package/dist/core/GthAgentRunner.js.map +1 -1
  50. package/dist/core/GthLangChainAgent.d.ts +115 -0
  51. package/dist/core/GthLangChainAgent.js +644 -17
  52. package/dist/core/GthLangChainAgent.js.map +1 -1
  53. package/dist/core/approvals/annotations.d.ts +122 -0
  54. package/dist/core/approvals/annotations.js +137 -0
  55. package/dist/core/approvals/annotations.js.map +1 -0
  56. package/dist/core/approvals/grants.d.ts +216 -0
  57. package/dist/core/approvals/grants.js +469 -0
  58. package/dist/core/approvals/grants.js.map +1 -0
  59. package/dist/core/approvals/matcher.d.ts +202 -0
  60. package/dist/core/approvals/matcher.js +267 -0
  61. package/dist/core/approvals/matcher.js.map +1 -0
  62. package/dist/core/approvals/mcpSubjects.d.ts +40 -0
  63. package/dist/core/approvals/mcpSubjects.js +99 -0
  64. package/dist/core/approvals/mcpSubjects.js.map +1 -0
  65. package/dist/core/approvals/toolAnnotationSources.d.ts +105 -0
  66. package/dist/core/approvals/toolAnnotationSources.js +277 -0
  67. package/dist/core/approvals/toolAnnotationSources.js.map +1 -0
  68. package/dist/core/approvals/toolHost.d.ts +46 -0
  69. package/dist/core/approvals/toolHost.js +108 -0
  70. package/dist/core/approvals/toolHost.js.map +1 -0
  71. package/dist/core/debugCapture.d.ts +75 -0
  72. package/dist/core/debugCapture.js +101 -0
  73. package/dist/core/debugCapture.js.map +1 -0
  74. package/dist/core/gthLeanAgentFactory.d.ts +9 -0
  75. package/dist/core/gthLeanAgentFactory.js +10 -0
  76. package/dist/core/gthLeanAgentFactory.js.map +1 -0
  77. package/dist/core/launchBanner.d.ts +120 -0
  78. package/dist/core/launchBanner.js +418 -0
  79. package/dist/core/launchBanner.js.map +1 -0
  80. package/dist/core/plainToolIndication.d.ts +15 -0
  81. package/dist/core/plainToolIndication.js +174 -0
  82. package/dist/core/plainToolIndication.js.map +1 -0
  83. package/dist/core/reasoningBlocks.d.ts +60 -0
  84. package/dist/core/reasoningBlocks.js +98 -0
  85. package/dist/core/reasoningBlocks.js.map +1 -0
  86. package/dist/core/refusal.d.ts +53 -0
  87. package/dist/core/refusal.js +133 -0
  88. package/dist/core/refusal.js.map +1 -0
  89. package/dist/core/runStats.d.ts +52 -0
  90. package/dist/core/runStats.js +118 -0
  91. package/dist/core/runStats.js.map +1 -0
  92. package/dist/core/shell/ShellCommandFailedError.d.ts +54 -0
  93. package/dist/core/shell/ShellCommandFailedError.js +68 -0
  94. package/dist/core/shell/ShellCommandFailedError.js.map +1 -0
  95. package/dist/core/shell/abstention.d.ts +88 -0
  96. package/dist/core/shell/abstention.js +184 -0
  97. package/dist/core/shell/abstention.js.map +1 -0
  98. package/dist/core/shell/approvalCapture.d.ts +271 -0
  99. package/dist/core/shell/approvalCapture.js +108 -0
  100. package/dist/core/shell/approvalCapture.js.map +1 -0
  101. package/dist/core/shell/approvalStop.d.ts +84 -0
  102. package/dist/core/shell/approvalStop.js +119 -0
  103. package/dist/core/shell/approvalStop.js.map +1 -0
  104. package/dist/core/shell/arity.d.ts +6 -0
  105. package/dist/core/shell/arity.js +20 -6
  106. package/dist/core/shell/arity.js.map +1 -1
  107. package/dist/core/shell/denylist.d.ts +11 -0
  108. package/dist/core/shell/denylist.js +37 -0
  109. package/dist/core/shell/denylist.js.map +1 -0
  110. package/dist/core/shell/escalationSeverity.d.ts +141 -0
  111. package/dist/core/shell/escalationSeverity.js +89 -0
  112. package/dist/core/shell/escalationSeverity.js.map +1 -0
  113. package/dist/core/shell/framing.d.ts +190 -0
  114. package/dist/core/shell/framing.js +633 -0
  115. package/dist/core/shell/framing.js.map +1 -0
  116. package/dist/core/shell/hardline.d.ts +81 -0
  117. package/dist/core/shell/hardline.js +607 -0
  118. package/dist/core/shell/hardline.js.map +1 -0
  119. package/dist/core/shell/negotiation.d.ts +249 -0
  120. package/dist/core/shell/negotiation.js +355 -0
  121. package/dist/core/shell/negotiation.js.map +1 -0
  122. package/dist/core/shell/normalize.d.ts +44 -4
  123. package/dist/core/shell/normalize.js +61 -7
  124. package/dist/core/shell/normalize.js.map +1 -1
  125. package/dist/core/shell/openWorld.d.ts +263 -0
  126. package/dist/core/shell/openWorld.js +1188 -0
  127. package/dist/core/shell/openWorld.js.map +1 -0
  128. package/dist/core/shell/rater.d.ts +935 -0
  129. package/dist/core/shell/rater.js +1473 -0
  130. package/dist/core/shell/rater.js.map +1 -0
  131. package/dist/core/shell/raterModel.d.ts +41 -0
  132. package/dist/core/shell/raterModel.js +51 -0
  133. package/dist/core/shell/raterModel.js.map +1 -0
  134. package/dist/core/shell/rejection.d.ts +69 -0
  135. package/dist/core/shell/rejection.js +38 -0
  136. package/dist/core/shell/rejection.js.map +1 -0
  137. package/dist/core/toolCallRepair/grammar.d.ts +41 -0
  138. package/dist/core/toolCallRepair/grammar.js +116 -0
  139. package/dist/core/toolCallRepair/grammar.js.map +1 -0
  140. package/dist/core/toolCallRepair/index.d.ts +2 -0
  141. package/dist/core/toolCallRepair/index.js +7 -0
  142. package/dist/core/toolCallRepair/index.js.map +1 -0
  143. package/dist/core/toolCallRepair/payload.d.ts +36 -0
  144. package/dist/core/toolCallRepair/payload.js +341 -0
  145. package/dist/core/toolCallRepair/payload.js.map +1 -0
  146. package/dist/core/toolCallRepair/promote.d.ts +45 -0
  147. package/dist/core/toolCallRepair/promote.js +90 -0
  148. package/dist/core/toolCallRepair/promote.js.map +1 -0
  149. package/dist/core/toolDisplay.d.ts +123 -0
  150. package/dist/core/toolDisplay.js +451 -0
  151. package/dist/core/toolDisplay.js.map +1 -0
  152. package/dist/core/toolOutputChannel.d.ts +95 -0
  153. package/dist/core/toolOutputChannel.js +165 -0
  154. package/dist/core/toolOutputChannel.js.map +1 -0
  155. package/dist/core/types.d.ts +294 -12
  156. package/dist/core/types.js.map +1 -1
  157. package/dist/history/historyFormat.d.ts +28 -0
  158. package/dist/history/historyFormat.js +127 -0
  159. package/dist/history/historyFormat.js.map +1 -0
  160. package/dist/history/historyStore.d.ts +198 -0
  161. package/dist/history/historyStore.js +482 -0
  162. package/dist/history/historyStore.js.map +1 -0
  163. package/dist/history/recordSession.d.ts +37 -0
  164. package/dist/history/recordSession.js +56 -0
  165. package/dist/history/recordSession.js.map +1 -0
  166. package/dist/index.d.ts +4 -0
  167. package/dist/index.js +4 -0
  168. package/dist/index.js.map +1 -1
  169. package/dist/providers/anthropic.d.ts +1 -1
  170. package/dist/providers/anthropic.js +5 -10
  171. package/dist/providers/anthropic.js.map +1 -1
  172. package/dist/providers/deepseek.d.ts +1 -1
  173. package/dist/providers/deepseek.js +5 -10
  174. package/dist/providers/deepseek.js.map +1 -1
  175. package/dist/providers/geminiSchemaSanitizer.d.ts +55 -0
  176. package/dist/providers/geminiSchemaSanitizer.js +347 -0
  177. package/dist/providers/geminiSchemaSanitizer.js.map +1 -0
  178. package/dist/providers/geminiThinking.d.ts +52 -0
  179. package/dist/providers/geminiThinking.js +72 -0
  180. package/dist/providers/geminiThinking.js.map +1 -0
  181. package/dist/providers/google-genai.d.ts +1 -1
  182. package/dist/providers/google-genai.js +12 -11
  183. package/dist/providers/google-genai.js.map +1 -1
  184. package/dist/providers/groq.d.ts +1 -1
  185. package/dist/providers/groq.js +5 -10
  186. package/dist/providers/groq.js.map +1 -1
  187. package/dist/providers/huggingface.d.ts +25 -0
  188. package/dist/providers/huggingface.js +69 -0
  189. package/dist/providers/huggingface.js.map +1 -0
  190. package/dist/providers/modelCatalog.d.ts +109 -0
  191. package/dist/providers/modelCatalog.js +245 -0
  192. package/dist/providers/modelCatalog.js.map +1 -0
  193. package/dist/providers/modelDiscovery.d.ts +153 -6
  194. package/dist/providers/modelDiscovery.js +295 -41
  195. package/dist/providers/modelDiscovery.js.map +1 -1
  196. package/dist/providers/ollama.d.ts +19 -5
  197. package/dist/providers/ollama.js +60 -52
  198. package/dist/providers/ollama.js.map +1 -1
  199. package/dist/providers/openai.d.ts +1 -1
  200. package/dist/providers/openai.js +39 -10
  201. package/dist/providers/openai.js.map +1 -1
  202. package/dist/providers/openrouter.d.ts +4 -5
  203. package/dist/providers/openrouter.js +20 -35
  204. package/dist/providers/openrouter.js.map +1 -1
  205. package/dist/providers/vertexai.d.ts +1 -1
  206. package/dist/providers/vertexai.js +12 -11
  207. package/dist/providers/vertexai.js.map +1 -1
  208. package/dist/providers/xai.d.ts +1 -1
  209. package/dist/providers/xai.js +5 -10
  210. package/dist/providers/xai.js.map +1 -1
  211. package/dist/runtime/askStructured.d.ts +105 -0
  212. package/dist/runtime/askStructured.js +120 -0
  213. package/dist/runtime/askStructured.js.map +1 -0
  214. package/dist/runtime/conversation.d.ts +60 -0
  215. package/dist/runtime/conversation.js +151 -0
  216. package/dist/runtime/conversation.js.map +1 -0
  217. package/dist/runtime/singleShot.d.ts +25 -5
  218. package/dist/runtime/singleShot.js +95 -36
  219. package/dist/runtime/singleShot.js.map +1 -1
  220. package/dist/runtime/structuredOutput.d.ts +104 -0
  221. package/dist/runtime/structuredOutput.js +393 -0
  222. package/dist/runtime/structuredOutput.js.map +1 -0
  223. package/dist/utils/ProgressIndicator.d.ts +21 -0
  224. package/dist/utils/ProgressIndicator.js +30 -3
  225. package/dist/utils/ProgressIndicator.js.map +1 -1
  226. package/dist/utils/aiignoreUtils.js.map +1 -1
  227. package/dist/utils/binaryOutputUtils.js.map +1 -1
  228. package/dist/utils/consoleUtils.d.ts +52 -0
  229. package/dist/utils/consoleUtils.js +72 -2
  230. package/dist/utils/consoleUtils.js.map +1 -1
  231. package/dist/utils/crashHandler.d.ts +87 -0
  232. package/dist/utils/crashHandler.js +128 -0
  233. package/dist/utils/crashHandler.js.map +1 -0
  234. package/dist/utils/debugDump.d.ts +134 -0
  235. package/dist/utils/debugDump.js +381 -0
  236. package/dist/utils/debugDump.js.map +1 -0
  237. package/dist/utils/debugUtils.d.ts +13 -4
  238. package/dist/utils/debugUtils.js +36 -13
  239. package/dist/utils/debugUtils.js.map +1 -1
  240. package/dist/utils/displayWidth.d.ts +53 -0
  241. package/dist/utils/displayWidth.js +195 -0
  242. package/dist/utils/displayWidth.js.map +1 -0
  243. package/dist/utils/fileUtils.d.ts +24 -2
  244. package/dist/utils/fileUtils.js +54 -12
  245. package/dist/utils/fileUtils.js.map +1 -1
  246. package/dist/utils/llmUtils.d.ts +39 -8
  247. package/dist/utils/llmUtils.js +76 -8
  248. package/dist/utils/llmUtils.js.map +1 -1
  249. package/dist/utils/redactSecrets.d.ts +63 -0
  250. package/dist/utils/redactSecrets.js +286 -0
  251. package/dist/utils/redactSecrets.js.map +1 -0
  252. package/dist/utils/systemPromptNotes.d.ts +225 -0
  253. package/dist/utils/systemPromptNotes.js +340 -0
  254. package/dist/utils/systemPromptNotes.js.map +1 -0
  255. package/dist/utils/systemUtils.d.ts +49 -1
  256. package/dist/utils/systemUtils.js +67 -3
  257. package/dist/utils/systemUtils.js.map +1 -1
  258. package/dist/utils/toolMatching.d.ts +30 -0
  259. package/dist/utils/toolMatching.js +44 -0
  260. package/dist/utils/toolMatching.js.map +1 -0
  261. package/dist/utils/untrustedText.d.ts +66 -0
  262. package/dist/utils/untrustedText.js +80 -0
  263. package/dist/utils/untrustedText.js.map +1 -0
  264. package/package.json +22 -6
  265. package/schema/gsloth-config.schema.json +3134 -0
  266. package/dist/core/shell/allowlist.d.ts +0 -75
  267. package/dist/core/shell/allowlist.js +0 -187
  268. package/dist/core/shell/allowlist.js.map +0 -1
  269. package/dist/core/shell/judge.d.ts +0 -161
  270. package/dist/core/shell/judge.js +0 -261
  271. package/dist/core/shell/judge.js.map +0 -1
@@ -0,0 +1,935 @@
1
+ /**
2
+ * @module core/shell/rater
3
+ *
4
+ * CFG-27 (CFG-26 rework) — the **auto-rater**: the LLM that rates a pending `run_shell_command`
5
+ * before it executes, sitting *in front of* the human approval prompt (EXT-9). It is consulted at
6
+ * exactly two of the five rungs — `assisted` and `auto` (see `APPROVAL_RUNGS`); `manual`,
7
+ * `write` and `bypass` are fully deterministic and never pay for a model call.
8
+ *
9
+ * NOTE ON THE NAME: "judge" is reserved for the **eval grader** (`gth eval --judge <profile>`,
10
+ * `@gaunt-sloth/batch`) — a different concept. This module is the approvals rater.
11
+ *
12
+ * Validated prior art (both place the rater in front of the human prompt as an auto-approve
13
+ * fatigue-reducer): openclaw `exec-auto-reviewer.ts` and hermes-agent `approval.py` "smart" mode.
14
+ *
15
+ * Two hardening guarantees are baked in here:
16
+ *
17
+ * 1. **Prompt-injection defense.** The command is attacker-controlled text. It is normalized
18
+ * (reusing {@link normalizeCommand} + home-path folding) and embedded inside an XML
19
+ * `<command_to_evaluate>` tag, behind a preamble that states the tagged text is UNTRUSTED
20
+ * DATA to be analyzed, never instructions to follow. See {@link buildRaterPrompt}. §5.1's
21
+ * negotiation context ([[EXT-29]]) is admitted on exactly those terms — the justification, the
22
+ * prior rounds and the last user messages are each fenced in the user message, and
23
+ * {@link RATER_NEGOTIATION_GUIDANCE} extends the untrusted-data contract to their tags. Nothing
24
+ * else from the conversation is admitted at any round: no tool output, no file contents, no
25
+ * fetched pages (§4.3).
26
+ * 2. **Fail-closed on error.** If the LLM call throws, times out, or returns unparseable
27
+ * output, the verdict returned NEVER auto-approves — it is `destructive` with an honest
28
+ * "could not assess" reason. A rater failure can never silently green-light a command.
29
+ * See {@link FAIL_CLOSED_VERDICT}.
30
+ *
31
+ * A command whose target the gate cannot statically resolve is RATED like any other ([[EXT-81]]),
32
+ * carrying a neutral note about the shape the parser saw ({@link buildParserPreflightNote}). It is
33
+ * not an action, not a floor, and not a reason to skip the call.
34
+ *
35
+ * Mirrors the QA-3 rating substrate (`packages/review/src/middleware/reviewRateMiddleware.ts`):
36
+ * structured-output evaluation over `config.llm`, wrapped in try/catch.
37
+ */
38
+ import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
39
+ import * as z from 'zod';
40
+ import type { ApprovalRung, GrantedToolSummary, GthConfig } from '#src/config.js';
41
+ import type { EffectiveToolAnnotations } from '#src/core/approvals/matcher.js';
42
+ import { type RaterCallCapture } from '#src/core/shell/approvalCapture.js';
43
+ /**
44
+ * CFG-28 (spec §4.1) — the **four** outcomes the rater may return. The retired third outcome named
45
+ * the halt trigger by *mechanism* while positioning it as the top *severity*; the rescale (§11.1)
46
+ * splits that into two outcomes asking two different questions. There is no
47
+ * ordering knob and no threshold: each outcome's consequence is fixed by the rung
48
+ * ({@link mapVerdictToAction}).
49
+ *
50
+ * - `safe` — no harmful effect.
51
+ * - `destructive` — **the catch-all**: harmful, but recoverable from inside the session, and not
52
+ * an attack — **and anything the rater cannot assess**. The rating prompt defines it *by
53
+ * exclusion* ("not safe, not catastrophic and not an attack") precisely so no command can fall
54
+ * outside the four.
55
+ * - `catastrophic` — *can this be undone from inside the session?* Irreversible without something
56
+ * OUTSIDE the session: rescue media, a backup, a re-provision, a restore from a third party.
57
+ * Escalates at both rated rungs; never negotiable and never sticky (§4.2).
58
+ * - `attack` — *is something hostile acting here?* The command's own **structure** evidences
59
+ * compromise (§4.1.1: credential targeting, privilege escalation / permission weakening,
60
+ * persistence, deception, obfuscation). It is the only outcome that HALTS the run.
61
+ *
62
+ * **`catastrophic` and `attack` are not ranked against each other** — they ask different
63
+ * questions, and the spec says so explicitly. A command can be both; `attack` wins the
64
+ * *consequence* (a manipulated session cannot be trusted to continue) but MUST NOT swallow the
65
+ * finding — see the §6.1 clause in {@link buildRaterSystemPrompt}. Nothing here may be written as
66
+ * a severity comparison between the two.
67
+ */
68
+ export declare const RATER_OUTCOMES: readonly ['safe', 'destructive', 'catastrophic', 'attack'];
69
+ /** One outcome of {@link RATER_OUTCOMES}. */
70
+ export type RaterOutcome = (typeof RATER_OUTCOMES)[number];
71
+ /**
72
+ * Structured verdict the rater model must return: one outcome plus one short sentence. There is
73
+ * deliberately nothing else — no severity number, no booleans to recombine into a compound
74
+ * condition. The consequence is a property of the rung, not of a knob.
75
+ *
76
+ * **The schema is written plainly, as the verdict the rater's CALLERS want.** `suggestedTool` is a
77
+ * plain `.optional()` and the parsed verdict's `suggestedTool` is `string | undefined`. What a
78
+ * strict `json_schema` provider has to be sent instead — the key required and its type nullable —
79
+ * and the `null` that then comes back are entirely the business of
80
+ * {@link structuredOutputBoundary}, which {@link rateShellCommand} runs both halves of the call
81
+ * through. Nothing about the wire belongs in this object; putting it here is what made the schema we
82
+ * send contradict the schema we validate with.
83
+ */
84
+ export declare const ShellSafetyVerdictSchema: z.ZodObject<{
85
+ outcome: z.ZodEnum<{
86
+ attack: "attack";
87
+ catastrophic: "catastrophic";
88
+ destructive: "destructive";
89
+ safe: "safe";
90
+ }>;
91
+ reason: z.ZodString;
92
+ suggestedTool: z.ZodOptional<z.ZodString>;
93
+ }, z.core.$strip>;
94
+ /**
95
+ * The rater's structured verdict on a single shell command. `suggestedTool` is `string | undefined`
96
+ * and never `null` — the boundary the rating call goes through collapses a `null` to the key being
97
+ * absent before any consumer sees it, so "no suggestion" has exactly one spelling.
98
+ */
99
+ export type ShellSafetyVerdict = z.infer<typeof ShellSafetyVerdictSchema>;
100
+ /**
101
+ * The honest reason text used whenever the outcome was NOT assessed by the rater — a rater failure
102
+ * ({@link FAIL_CLOSED_VERDICT}) or the script-env-leak preflight. Spec rule (§4.1):
103
+ * *uncertainty is not an outcome*, so it maps to `destructive` while SAYING it could not be
104
+ * assessed rather than pretending the command was found harmful.
105
+ */
106
+ export declare const COULD_NOT_ASSESS_PREFIX = "Could not assess this command";
107
+ /**
108
+ * EXT-61 (§4.6) — the reason text prefix for the **open-world** preflight, and deliberately NOT
109
+ * {@link COULD_NOT_ASSESS_PREFIX}: this preflight *did* assess the command and found something
110
+ * specific. Saying "could not assess" here would be a lie, and the named host is the whole value of
111
+ * the escalation — "it downloads something, confirm" and "it fetches from registry.npmjs.ag" are
112
+ * different warnings, and only the second is worth reading.
113
+ */
114
+ export declare const NAMES_A_HOST_PREFIX = "This command names a host";
115
+ /**
116
+ * EXT-70 (§4.7.2, §4.7.3) — the reason text prefix for the **tool** arm of the open-world floor: a
117
+ * call whose EFFECTIVE `openWorldHint` is true. Like {@link NAMES_A_HOST_PREFIX} and unlike
118
+ * {@link COULD_NOT_ASSESS_PREFIX}, it states something the gate positively established.
119
+ *
120
+ * It names the hint rather than paraphrasing it, because the hint is also the thing the user can
121
+ * act on: trust it from that server (`approvals.mcp`), or declare the call in `approvals.allow`.
122
+ */
123
+ export declare const REACHES_OPEN_WORLD_PREFIX = "This tool reaches the open world";
124
+ /**
125
+ * The closing clause **shared by every open-world floor reason**, shell and tool alike.
126
+ *
127
+ * It is a constant rather than two copies of a sentence, and that is load-bearing rather than
128
+ * tidiness: the two arms are one rule (§4.6 for a shell fetch, §4.7.3 for the same fetch reached
129
+ * through a tool), so a reader who has seen one escalation reads the other as the same decision.
130
+ * It is also the one part of the floor a **second implementation** cannot reproduce by accident —
131
+ * an inline `{ outcome: 'destructive', reason: … }` written at some future call site would say
132
+ * something else, and the assertions that compare a floored reason against the exported reason
133
+ * builders are what turn that into a red test rather than a slow divergence.
134
+ */
135
+ export declare const NEVER_AUTO_APPROVED_CLAUSE = "so it is never auto-approved.";
136
+ /**
137
+ * The verdict returned whenever the rater cannot produce a trustworthy answer (LLM throws,
138
+ * times out, or returns unparseable output). Fail-closed: `destructive`, never auto-approved,
139
+ * and never `attack` or `catastrophic` either — a failure to assess must not manufacture a
140
+ * run-halting outcome any more than it may manufacture an approval.
141
+ */
142
+ export declare const FAIL_CLOSED_VERDICT: ShellSafetyVerdict;
143
+ /**
144
+ * EXT-66 — why the gate failed closed. **Every one of these is a fact about the GATE, not about the
145
+ * command**, which is the whole point of naming them: {@link FAIL_CLOSED_VERDICT} collapsed four
146
+ * different gate failures into one verdict that reads, downstream and in every eval report, exactly
147
+ * like a model that looked at the command and judged it `destructive`.
148
+ *
149
+ * That is not hypothetical. The EXT-62 anchoring sweep read its first `gemma4:12b` column as full
150
+ * coverage of the interpreter-wrapper misses; 3 of those escalations were the gate defaulting after
151
+ * 30 seconds, not the model judging, and only the reason string distinguished them.
152
+ *
153
+ * The outcome stays `destructive` for all four — failing closed is right and stays right, and a
154
+ * failure to assess must not manufacture `catastrophic`/`attack` any more than it may manufacture
155
+ * an approval. What changes is that the reason now says which failure happened, which is what lets a
156
+ * caller tell the gate defaulting from the model judging ({@link isFailClosed}).
157
+ */
158
+ export type FailClosedCause = 'no-model' | 'timeout' | 'unparseable' | 'threw';
159
+ /**
160
+ * The fail-closed verdict for a specific {@link FailClosedCause}. Keeps
161
+ * {@link COULD_NOT_ASSESS_PREFIX} — the statement "this was not assessed" is still true and is what
162
+ * downstream keys on — and appends what actually went wrong.
163
+ *
164
+ * The timeout arm names the budget, because "the rater timed out" is not actionable and "the rater
165
+ * did not answer within 30000ms" points straight at `approvals.raterTimeoutMs`.
166
+ */
167
+ export declare function failClosedVerdict(cause: FailClosedCause, timeoutMs?: number): ShellSafetyVerdict;
168
+ /**
169
+ * Whether a verdict is one this gate produced because it could not obtain a rating, as opposed to
170
+ * one a rater actually returned. Keys on {@link COULD_NOT_ASSESS_PREFIX} — the same
171
+ * reason-prefix-as-identity idiom {@link NAMES_A_HOST_PREFIX} already uses — so it covers the
172
+ * legacy {@link FAIL_CLOSED_VERDICT} as well as every {@link failClosedVerdict} cause.
173
+ *
174
+ * Exported so a caller can tell "the gate defaulted" from "the model judged" without string
175
+ * matching at the call site, which is the distinction an eval column and a session summary both
176
+ * need and neither could previously make.
177
+ */
178
+ export declare function isFailClosed(verdict: ShellSafetyVerdict | undefined): boolean;
179
+ /** Whether a verdict is specifically the {@link FailClosedCause} `timeout` arm. */
180
+ export declare function isRaterTimeout(verdict: ShellSafetyVerdict | undefined): boolean;
181
+ /**
182
+ * Default wall-clock budget (ms) for the rater LLM call. Kept low so a slow/hung rater can't
183
+ * wedge the approval flow — on timeout we fail closed. Mirrors openclaw's low exec-reviewer
184
+ * timeout minimum.
185
+ *
186
+ * **EXT-66 — this is a HOSTED-model number, and it is now a default rather than the only value.**
187
+ * `claude-haiku-4-5` and `gemini-3.6-flash` answered a 23-case corpus well inside it, 0 fail-closed.
188
+ * `gemma4:12b` over a local GPU took 6.0s–114.7s on the same corpus, and the harder the command the
189
+ * longer it thought — so the fixed limit preferentially clipped exactly the commands that most
190
+ * needed rating (3 of 18 calls in one run, 9 of 17 in the next; all of them returned real verdicts
191
+ * at 120s, including a correct `catastrophic` returned 85 seconds after the gate had given up).
192
+ * Override with `approvals.raterTimeoutMs`.
193
+ */
194
+ export declare const RATER_DEFAULT_TIMEOUT_MS = 30000;
195
+ /**
196
+ * The invariant half of the rater's system prompt: the role and the untrusted-input contract (the
197
+ * tagged command is DATA, not instructions). Patterned after openclaw's
198
+ * `DEFAULT_EXEC_REVIEWER_SYSTEM_PROMPT` and hermes' untrusted-input framing. Exported so tests can
199
+ * assert the injection-defense preamble survives.
200
+ */
201
+ export declare const RATER_SYSTEM_PREAMBLE: string;
202
+ /**
203
+ * The `catastrophic` half of the rating prompt (§4.1). The whole outcome is one question — *can
204
+ * this be undone from inside the session?* — and the prompt asks it that way rather than offering
205
+ * a severity scale, because a rater given "how bad is it" instead of "is it recoverable" produces a
206
+ * ranking rather than the classification §4.2 acts on.
207
+ *
208
+ * The examples deliberately include the members the §8 deterministic floor **cannot** reach
209
+ * (`DROP DATABASE`, `terraform destroy -auto-approve`, `kubectl delete namespace production`):
210
+ * §11.1 records that only a model recognises that class, which is the reason the outcome exists.
211
+ * The counter-examples matter just as much — `git reset --hard` is reflog-recoverable and therefore
212
+ * `destructive`, and that is precisely what lets §5's negotiation open on it at all (§11.1a).
213
+ */
214
+ export declare const RATER_CATASTROPHIC_GUIDANCE: string;
215
+ /**
216
+ * The `attack` half of the rating prompt, kept as its own export because **§4.1.1 requires the
217
+ * prompt to carry the structural test in its own words, not merely the one-line table
218
+ * definition.**
219
+ *
220
+ * The reason is worth restating where the prompt author will read it: `attack` is the only outcome
221
+ * that halts the run, the halt is not negotiable, and from `assisted` — the default rung for
222
+ * everyone — a non-interactive run has no key at all and the only ways through are an allow-list
223
+ * entry or dropping to `bypass`, i.e. one step from the default gate to no gate. An outcome that
224
+ * expensive MUST NOT fire on ordinary work, so the test is **what the command's own structure
225
+ * shows, not who it talks to**.
226
+ *
227
+ * Two clauses here are measurements rather than opinions, and neither may be quietly relaxed:
228
+ *
229
+ * - **Origin trust is not the rater's job** (§4.1.1's measured note). A cheap model rated
230
+ * `curl https://pypi.org.packages-cdn.io/simple/ -o index.html` as `safe` while *naming the
231
+ * deception in its own reasoning*, and split identically-shaped commands at random. A property
232
+ * that holds only on the good model is not a property, and `assisted` is the default for people
233
+ * pointed at small local models. `curl … | <shell>` is therefore `destructive` whatever the host.
234
+ * - **Clause (1) is narrowed** (§11.1b, 2026-07-28). A secret handed to a tool that is doing some
235
+ * other job is not credential targeting; a secret exposed for its own sake is. Read literally,
236
+ * the un-narrowed clause halted the run on `python deploy.py --key $AWS_SECRET_ACCESS_KEY` — one
237
+ * of the most ordinary shapes in deployment work, from a section that opens by saying an outcome
238
+ * this expensive must not fire on ordinary work. **Nothing is given up**: the deterministic
239
+ * {@link hasScriptEnvLeakRisk} preflight fires on exactly that shape, annotates this prompt, and
240
+ * forces the fail-closed `destructive` path in {@link mapVerdictToAction} — so a secret in an
241
+ * argument cannot reach `safe` however the rater rates it. The change trades a halt for a prompt
242
+ * on commands that were never going to auto-approve.
243
+ */
244
+ export declare const RATER_ATTACK_GUIDANCE: string;
245
+ /**
246
+ * EXT-61 (spec §4.6.1) — **deception becomes a REPORT and an upgrade, never a gate.**
247
+ *
248
+ * This is the rater-side half of the open-world preflight, and it exists because the preflight
249
+ * changed what the rater's hostname judgement is *for*. §4.6 floors every command that names a host
250
+ * at `destructive` before the rater is called, so that judgement no longer stands between a
251
+ * typosquat and execution. Its job is now to *tell the user what it sees*.
252
+ *
253
+ * **The error costs invert, and that is the point.** A missed deception costs a warning rather than
254
+ * a bypass; a wrongly-suspected one costs a sentence rather than a halted run. That is the correct
255
+ * place to put a judgement neither models nor humans perform reliably — §4.1.1's measurement is a
256
+ * cheap model rating a lookalike host `safe` *while naming the deception in its own reasoning*, and
257
+ * a working developer who did not discriminate hostnames in either direction.
258
+ *
259
+ * Both halves are normative and neither may be softened into the other:
260
+ *
261
+ * - **(1) Always report it**, naming the mechanism, **even when the outcome stays `destructive`**.
262
+ * The "even when" is the whole clause; a rater that only names a typosquat when it is halting the
263
+ * run reports nothing on the commands this preflight was built for, since they all land on
264
+ * `destructive`.
265
+ * - **(2) Upgrade to `attack` only when the deception is CLEAR**, resolving uncertainty *downward*
266
+ * to `destructive` with the doubt stated. §12.1 is the reason: a halt that fires is already more
267
+ * likely wrong than right, so it must be spent only where the structure is unambiguous.
268
+ *
269
+ * CFG-28 deliberately left (2) out of the prompt, on the reasoning that it presumes the §4.6 floor.
270
+ * The scoping call was right and the reasoning was not: at both rated rungs a `destructive` outcome
271
+ * escalates anyway, so the clause would have cost nothing had it landed early. **The floor is what
272
+ * makes the `destructive` half of §4.6.1 meaningful, not what gates the upgrade.**
273
+ */
274
+ export declare const RATER_DECEPTION_GUIDANCE: string;
275
+ /**
276
+ * [[EXT-29]] (spec §5.1) — how to WEIGH the negotiation context, added to the SYSTEM prompt for
277
+ * exactly the ratings that carry one ({@link buildNegotiationContextBlock}).
278
+ *
279
+ * **It is conditional on the CONTEXT, and that is the design rather than an optimisation.** Round 1
280
+ * is deliberately context-free (§5.1): there is no justification to weigh and no transcript to
281
+ * reason from, so a prompt explaining how a justification may lower an outcome has nothing to
282
+ * govern and everything to prime. Tying it to the block means the two can never disagree — the
283
+ * rules about weighing the extra context appear exactly when the extra context does.
284
+ *
285
+ * **§5.2's wording rules are NOT here, and the split is the point.** They are scoped by *whether
286
+ * the rejection is addressed to the agent at all* — which is what `auto` means — not by whether a
287
+ * transcript happens to exist yet; see {@link RATER_NEGOTIABLE_REJECTION_GUIDANCE}.
288
+ *
289
+ * Three rules are normative and none may be softened into another:
290
+ *
291
+ * - **A justification may only ever LOWER a rating** — *lower* meaning **less severe**. It may move
292
+ * `destructive` to `safe`; it may never move `safe` to `destructive`. That is the permissive
293
+ * direction on purpose: a negotiation the justification cannot win is not a negotiation.
294
+ * - **A stated intent that does not match what the command does is grounds for REJECTION, not for a
295
+ * discount.** This is the counterweight to the rule above and is not optional — the justification
296
+ * is the one place in the whole design where attacker-influenceable text can *reduce* an outcome.
297
+ * - **`attack` and `catastrophic` are exempt from the entire mechanism** (§4.2). No justification,
298
+ * no revision and no accumulated context moves either.
299
+ *
300
+ * The opening clause extends {@link RATER_SYSTEM_PREAMBLE}'s untrusted-data contract to the new
301
+ * tags. The preamble names `<command_to_evaluate>` alone and cannot be edited without breaking
302
+ * round-1 byte-identity, so the tags this block introduces are declared untrusted *here*, in the
303
+ * same prompt that introduces them.
304
+ */
305
+ export declare const RATER_NEGOTIATION_CONTEXT_GUIDANCE: string;
306
+ /**
307
+ * [[EXT-29]] (spec §5.2) — **how a rejection must be WORDED, added whenever the rejection will be
308
+ * read by the agent** rather than by a person.
309
+ *
310
+ * **This is scoped by MODE, not by round, and the distinction is the whole of §5.2.** §5.1 governs
311
+ * what *context* a rating is allowed to see, and round 1 sees the command alone; §5.2 governs how a
312
+ * rejection is *written*, and a rejection is written the same way in every round of a negotiation
313
+ * — including the first, which is the round §5.6's escalation example requires to name the fix
314
+ * (*"Name the commits to drop, or use `--soft`"*). What decides whether these rules apply at all is
315
+ * whether the rejection is *addressed to the agent*: at `auto` it is, at `assisted` a `destructive`
316
+ * outcome goes to the human instead, so *"MUST invite a response"* would be addressed to nobody.
317
+ *
318
+ * Turning it on therefore keys on {@link import('#src/config.js').isNegotiatingRung} and NOT on
319
+ * whether a negotiation block exists. The two are independent by construction: a cleared transcript
320
+ * (§5.3) produces a round-1 *context* that is still a round of a negotiation.
321
+ *
322
+ * It sits LAST in the system prompt, after {@link buildGrantedToolsGuidance}, because §5.2's list of
323
+ * things a rejection may name ends with *a granted built-in that does the job* — a clause that reads
324
+ * as an instruction only once that list is already on the page.
325
+ *
326
+ * The two named anti-patterns are stated as failures rather than merely left out: a bare *"Rejected.
327
+ * This is destructive."* leaves the agent nothing to act on, and a rejection that restates the danger
328
+ * and asks the agent to explain itself invites another justification rather than a better command.
329
+ */
330
+ export declare const RATER_NEGOTIABLE_REJECTION_GUIDANCE: string;
331
+ /**
332
+ * EXT-58 (spec §4.4) — the granted-alternative section of the rating prompt, built from the
333
+ * already-granted built-in tools of the current rung.
334
+ *
335
+ * Three properties are normative and each is spelled out to the rater:
336
+ *
337
+ * - It must name a granted tool **whenever** the outcome is not `safe` and one of them would do the
338
+ * job, because a free built-in call beats an interruption.
339
+ * - It must **not** name one when none can do the job — a path outside the working folder is the
340
+ * canonical case, where neither the read nor the edit tool can reach either. A facility that
341
+ * manufactures suggestions makes "a suggestion is never an approval" meaningless.
342
+ * - A suggestion is **never an approval**: it does not change the outcome, does not approve the
343
+ * original command, and does not pre-approve the suggested tool (which is gated normally when it
344
+ * arrives). The gate enforces this structurally — {@link mapVerdictToAction} never reads the
345
+ * field — but the rater is told so it does not soften an outcome because an alternative exists.
346
+ *
347
+ * The list is **trusted, locally-generated text** (§4.3) and therefore lives in the SYSTEM prompt,
348
+ * structurally outside the `<command_to_evaluate>` block that carries the untrusted command. Only
349
+ * tool names and one-line descriptions authored in `config/tool-descriptions.ts` ever appear here;
350
+ * no MCP/custom/A2A tool's own description can reach the rater.
351
+ *
352
+ * Returns `null` when nothing is granted (or the caller supplied no list), so the prompt is exactly
353
+ * the pre-EXT-58 text and the rater is never invited to invent a tool out of an empty list.
354
+ */
355
+ export declare function buildGrantedToolsGuidance(grantedTools: readonly GrantedToolSummary[] | undefined): string | null;
356
+ /**
357
+ * Build the rater's system prompt: the invariant {@link RATER_SYSTEM_PREAMBLE}, the four outcome
358
+ * definitions (with §4.1's recoverability question spelled out in
359
+ * {@link RATER_CATASTROPHIC_GUIDANCE} and §4.1.1's structural test in
360
+ * {@link RATER_ATTACK_GUIDANCE}), the rules that make `destructive` the catch-all and uncertainty a
361
+ * `destructive` rather than an outcome of its own, and — when the caller supplies them — the
362
+ * already-granted tools of §4.4 ({@link buildGrantedToolsGuidance}).
363
+ *
364
+ * `destructive` is defined **last and by exclusion** on purpose: the two severe outcomes have to be
365
+ * on the page before "everything else" can mean anything, and defining the catch-all in terms of
366
+ * the other three is what makes it structurally impossible for a command to fall outside the four.
367
+ *
368
+ * There is no strictness parameter: §1 removed strictness levels along with severity thresholds,
369
+ * so the rating criteria are the same at every rated rung. Two blocks are appended on top of them,
370
+ * and they key on **two independent things** ([[EXT-29]]):
371
+ *
372
+ * - `hasNegotiationContext` appends {@link RATER_NEGOTIATION_CONTEXT_GUIDANCE} — the rules for
373
+ * weighing a justification and a transcript, which have nothing to govern until one exists.
374
+ * - `negotiable` appends {@link RATER_NEGOTIABLE_REJECTION_GUIDANCE} — §5.2's rules for wording a
375
+ * rejection that the *agent* will read, which apply at every round of a negotiation including the
376
+ * first.
377
+ *
378
+ * **They are two parameters and not one because they are two questions.** Tying §5.2 to the context
379
+ * would silence it in exactly the two rounds §5.6 requires it in: round 1, and the round right after
380
+ * a §5.3 reset — both of which are round-1 *contexts* inside a live negotiation. Both blocks only
381
+ * ever APPEND, so a negotiated system prompt still has the plain one as its prefix.
382
+ *
383
+ * @param grantedTools §4.4's already-granted built-ins, or nothing.
384
+ * @param options `hasNegotiationContext` — whether this rating carries a §5.1 context; callers
385
+ * should not decide it for themselves, since {@link buildRaterPrompt} derives it from the one
386
+ * thing that decides it, namely whether {@link buildNegotiationContextBlock} produced a block.
387
+ * `negotiable` — whether a rejection will be handed back to the agent (§5.2), i.e. the rung
388
+ * negotiates ({@link import('#src/config.js').isNegotiatingRung}).
389
+ */
390
+ export declare function buildRaterSystemPrompt(grantedTools?: readonly GrantedToolSummary[], options?: {
391
+ hasNegotiationContext?: boolean;
392
+ negotiable?: boolean;
393
+ }): string;
394
+ /**
395
+ * Detect whether the command invokes an interpreter on a script target AND passes an
396
+ * `$ALL_CAPS` shell-variable expansion in its arguments — openclaw's "script preflight". Such a
397
+ * command can leak environment (often secrets) into the script, so it should bias toward
398
+ * escalation. Lightweight heuristic over the normalized command; a positive flag is fed to the
399
+ * rater prompt AND forces the fail-closed `destructive` path in the decision mapping.
400
+ *
401
+ * @returns true when an interpreter+script invocation also expands an ALL_CAPS env var.
402
+ */
403
+ export declare function hasScriptEnvLeakRisk(normalizedCommand: string): boolean;
404
+ /**
405
+ * Fold an absolute home path to `~` so the rater sees a stable, less-identifying form (mirrors
406
+ * hermes `_normalize_command_for_detection` path folding). Best-effort: only the literal home
407
+ * dir prefix is folded.
408
+ */
409
+ export declare function foldHomePath(command: string, home: string | undefined): string;
410
+ /**
411
+ * [[EXT-29]] (spec §5.1) — one COMPLETED round of a negotiation, as the next round's rater sees it.
412
+ *
413
+ * It carries exactly what §5.1's third bullet admits and nothing else: the command the agent
414
+ * proposed, the justification it attached (when it attached one), and **the rater's own outcome and
415
+ * explanation** for that round — *"the rater reasons from its earlier positions rather than
416
+ * re-deriving them."*
417
+ *
418
+ * **The rater's half is two flat fields rather than an embedded {@link ShellSafetyVerdict}**, and
419
+ * that is deliberate. A verdict also carries §4.4's `suggestedTool`, which is advice about the
420
+ * rating that produced it and not part of the history §5.1 admits; a renderer handed a three-field
421
+ * object that renders two of them is a silent drop waiting to be read as a bug. Flat fields mean the
422
+ * builder renders everything it is given, and the type states the admitted set by construction.
423
+ *
424
+ * `command` is the RAW command as the agent proposed it. The builder normalizes and home-folds it
425
+ * with the same functions the live command goes through, so the transcript shows a past round in the
426
+ * form that round was actually rated in, then renders it on one line — see
427
+ * {@link buildNegotiationContextBlock}.
428
+ */
429
+ export interface RaterNegotiationRound {
430
+ /**
431
+ * The command the agent proposed in that round, RAW. The builder normalizes, home-folds and
432
+ * one-lines it; a caller that pre-processes it is doing the work twice and differently.
433
+ */
434
+ command: string;
435
+ /** The justification the agent attached to it, if any. Omitted when it argued nothing. */
436
+ justification?: string;
437
+ /** The rater's own outcome for that round. */
438
+ outcome: RaterOutcome;
439
+ /** The rater's own one-sentence explanation for that round. */
440
+ reason: string;
441
+ }
442
+ /**
443
+ * [[EXT-29]] (spec §5.1) — the additional context a rating from **round 2 onward** carries. Absent,
444
+ * or present but carrying nothing, means a round-1 rating: the command alone, byte-for-byte the
445
+ * prompt this module built before the negotiation existed.
446
+ *
447
+ * "Carrying nothing" is defined so a caller never has to choose a spelling: `undefined`, `{}`, an
448
+ * empty or whitespace-only `justification`, and empty arrays are all the same round-1 context. §5.3
449
+ * clears the transcript with the counter, so the state the runner holds after a reset is exactly
450
+ * this, whichever way it spells it.
451
+ *
452
+ * Nothing here is bounded by the caller: the last-5 rule and the 1000-character truncation are
453
+ * applied by {@link buildNegotiationContextBlock}, so a caller that hands over an entire
454
+ * conversation still cannot put a pasted log into the rater's context.
455
+ */
456
+ export interface RaterNegotiationContext {
457
+ /** The main model's justification for **this** command. Untrusted; fenced like the command. */
458
+ justification?: string;
459
+ /**
460
+ * The conversation's user messages, oldest first. Only the last {@link NEGOTIATION_MAX_USER_MESSAGES}
461
+ * are admitted and each is truncated — hand over as many as are to hand.
462
+ */
463
+ userMessages?: readonly string[];
464
+ /** The negotiation so far, oldest round first. */
465
+ priorRounds?: readonly RaterNegotiationRound[];
466
+ }
467
+ /**
468
+ * Neutralise any sequence that would CLOSE the fence `tag`, so untrusted text cannot escape it.
469
+ *
470
+ * A fenced block is only a boundary if the fenced text cannot write the boundary itself. Untrusted
471
+ * content containing its own closing tag ends the fence early and everything after it reads as our
472
+ * own prose — and inside `<negotiation_so_far>` that is not merely confusing but *persuasive*: the
473
+ * block quotes the rater's own previous positions back to it, and {@link RATER_NEGOTIATION_GUIDANCE}
474
+ * tells it to reason from those positions. A forged prior `safe` therefore argues for approval in
475
+ * the rater's own voice.
476
+ *
477
+ * The replacement carries no angle brackets at all (a marker that spelled the tag out would be the
478
+ * very sequence being removed) and says what happened, because a rater that can see text was
479
+ * tampered with has been told something useful about the command it is rating.
480
+ *
481
+ * **Matching is deliberately loose, and the looseness is the mechanism.** The reader is a language
482
+ * model, not a parser, so a matcher that is stricter than the reader is not a filter — it is a list
483
+ * of spellings the attacker gets to choose from. Four kinds of slack are closed: case, the
484
+ * whitespace an XML parser would ignore (`</ justification >`), the compatibility glyphs NFKC folds
485
+ * (a fullwidth solidus is a solidus to a reader), and any invisible spliced into the tag
486
+ * ({@link INVISIBLE_FORMAT_CHARS}).
487
+ *
488
+ * **That is four kinds of slack, not all of them**, and the difference is worth keeping in view: the
489
+ * invisibles are covered by an enumeration of Unicode properties, so this is as tolerant as those
490
+ * properties are and no more. {@link INVISIBLE_FORMAT_CHARS} states that residual; a character
491
+ * measured to render as blank and walk through belongs in that class, not in a second matcher here.
492
+ *
493
+ * Self-reconstruction is impossible by construction: the replacement contains no angle bracket and
494
+ * no slash, so no arrangement of neutralised text can rebuild a closing tag.
495
+ *
496
+ * Parameterised by tag because it guards every fence in the rating prompt — the three §5.1 ones and
497
+ * `<command_to_evaluate>` — rather than each growing a mechanism that escapes differently. Exported
498
+ * so a test can drive the matcher directly.
499
+ *
500
+ * **THE RESIDUAL IS WIDER THAN A HOMOGLYPH LIST — measured, and do not size it from this comment.**
501
+ * This matcher catches the tag spelled essentially exactly. Four classes walk through, and the first
502
+ * needs no Unicode at all:
503
+ *
504
+ * 1. **Pure ASCII near-misses** — `</tag foo>` (a trailing attribute), `<//tag>`, `</tag/>`, and a
505
+ * plain space inside the name. Note the asymmetry that makes the last one easy to miss: a
506
+ * ZERO-WIDTH space between two letters of the name IS neutralised by the strip below, while an
507
+ * ordinary space in the identical position is not.
508
+ * 2. **Solidus homoglyphs** — NFKC folds the fullwidth solidus (U+FF0F) but not the fraction slash
509
+ * (U+2044), the division slash (U+2215) or the big solidus (U+29F8).
510
+ * 3. **Bracket homoglyphs** — U+2039, U+27E8, U+3008, U+2329, U+276C.
511
+ * 4. **Tag-name homoglyphs** — Cyrillic and Greek lookalikes inside the tag name.
512
+ *
513
+ * **The ASCII class is the serious one.** The reader this function defends against is a language
514
+ * model, and `</tag foo>` reads as a closing tag to a model more readily than any homoglyph does —
515
+ * it is what a closing tag with an attribute looks like in the XML-shaped prompt it sits in.
516
+ *
517
+ * **Nothing mechanical is fooled by any of it:** none produces the literal `</tag>`, so no boundary
518
+ * count is wrong and no test that counts fences can see it. That is precisely why it is written here.
519
+ *
520
+ * **Left open for SCOPE, not because it is mild** — the matcher guards all four fences, so widening
521
+ * it lands on every one at once. That decision, and the shape it should take (a tolerant matcher
522
+ * reaches class 1; a confusable skeleton answers 2-4), is [[EXT-111]].
523
+ */
524
+ export declare function neutralizeClosingTag(text: string, tag: string): string;
525
+ /**
526
+ * [[EXT-29]] (spec §5.1) — the negotiation context block appended to the rater's USER message, or
527
+ * `null` when there is no negotiation (a round-1 rating).
528
+ *
529
+ * **Everything here is attacker-influenceable and every part of it is fenced**, exactly as
530
+ * `<command_to_evaluate>` is: the justification is written by a main model that reads untrusted
531
+ * input, the user messages arrive through a channel an attacker can reach, and the prior rounds
532
+ * carry both. The system prompt's {@link RATER_NEGOTIATION_GUIDANCE} declares these tags untrusted
533
+ * and is emitted with this block for that reason. Only the rater's own past outcomes and our own
534
+ * headings are ours, and they are the block's structure rather than its contents.
535
+ *
536
+ * **The fences here are enforced, not merely drawn.** Two things could otherwise write the block's
537
+ * own structure from inside it, and both are neutralised at the point of rendering: a closing tag
538
+ * ({@link neutralizeClosingTag}) and a newline in any one-line slot ({@link oneLine}). The amplifier
539
+ * that makes this worth more than tidiness is what the block IS — it quotes the rater's previous
540
+ * outcomes back to it under guidance telling it to reason from them, so a forged prior `safe` argues
541
+ * for approval in the rater's own voice.
542
+ *
543
+ * **The order inside the block narrows outward from the command being rated**: the justification is
544
+ * about THIS command, the transcript is the exchange that produced it, and the user messages are the
545
+ * mandate around the whole thing. It also keeps the agent's argument for the pending command out of
546
+ * the final position, which is the one a model weighs hardest.
547
+ *
548
+ * **Prior commands are normalized here**, by the same function the live command goes through, so a
549
+ * past round appears in the form it was actually rated in. **Home-folding applies to every value the
550
+ * block renders** — the justification and the user messages as much as the commands — because
551
+ * {@link foldHomePath} exists to keep the identifying form out of the prompt, and a prose field is
552
+ * where an absolute home path is most likely to appear, not least.
553
+ *
554
+ * Bounds are applied here rather than trusted from the caller: at most
555
+ * {@link NEGOTIATION_MAX_USER_MESSAGES} messages (the LAST that many), each truncated to
556
+ * {@link NEGOTIATION_USER_MESSAGE_MAX_CHARS}. Blank entries are dropped before the last-5 window is
557
+ * taken, so a run of empty messages cannot spend the budget that carries the mandate — and "blank"
558
+ * counts the characters {@link INVISIBLE_FORMAT_CHARS} names as nothing ({@link isBlank}), so a
559
+ * value carrying only those cannot render a block that a plain rating would not have.
560
+ *
561
+ * @param negotiation The §5.1 context, or nothing.
562
+ * @param home The home directory to fold — the caller's own `home`, so the block folds exactly as
563
+ * the live command does.
564
+ * @returns The block, or `null` when nothing would be rendered. `null` is the single signal that
565
+ * this is a round-1 rating: {@link buildRaterPrompt} uses it for both halves of the prompt, so the
566
+ * guidance and the context can never appear without each other.
567
+ */
568
+ export declare function buildNegotiationContextBlock(negotiation: RaterNegotiationContext | undefined, home?: string): string | null;
569
+ /**
570
+ * Build the messages for the rater call: the system prompt ({@link buildRaterSystemPrompt}) plus a
571
+ * human message that embeds the NORMALIZED command inside an XML `<command_to_evaluate>` tag and
572
+ * (optionally) notes what a deterministic preflight already found — the script-env-leak flag,
573
+ * (§4.6) a host literal in a fetch position, and ([[EXT-81]]) the shape our own parser could not
574
+ * resolve. The command text is only ever DATA in the tag — the builder never executes or
575
+ * interpolates it as instructions, and the notes are our own trusted text beside it. That
576
+ * separation is ENFORCED rather than merely drawn: the command cannot close its own fence
577
+ * ({@link neutralizeClosingTag}), so no part of it can render where our notes render.
578
+ *
579
+ * The four preflight notes are worded differently on purpose, and the differences are the design:
580
+ *
581
+ * - The **script-env-leak** note caps nothing but says "treat this as at least destructive".
582
+ * - The **open-world floor** note must NOT, because §4.6.1 asks the rater to *upgrade* a clear
583
+ * typosquat to `attack` and a note that anchors on `destructive` would talk it out of the one
584
+ * judgement it is still being asked for. It may say the command is never auto-approved, because a
585
+ * floor really did fire on it.
586
+ * - The **parser** note ({@link buildParserPreflightNote}) is a third register again: those two
587
+ * describe findings that ARE hazards and are entitled to a floor, while this one reports that our
588
+ * parser could not read the command, which establishes nothing about it. So it states a mechanism
589
+ * and asks a question, carries no verdict and no severity, and — unlike the open-world note —
590
+ * never says the command has already been floored, because for these families none has.
591
+ * - The **composed open-world** note ({@link buildComposedOpenWorldNote}) shares that third register
592
+ * and must not borrow the floor note's wording, for the reason the floor note is entitled to it:
593
+ * no floor fired here. It names the DATA FLOW across the parts rather than restating the hostname,
594
+ * which is already in the command text — see that function for the measurement behind that
595
+ * distinction.
596
+ *
597
+ * **Order matters here and is the order of a reader's attention**: the two hazard notes come first
598
+ * because each names something positively established, then the parser note, then its open-world
599
+ * elaboration — general shape of what could not be resolved, then the specific flow inside it. Then,
600
+ * last, [[EXT-29]]'s negotiation context ({@link buildNegotiationContextBlock}) — the notes describe
601
+ * THIS command, the negotiation is the history around it.
602
+ *
603
+ * **Round 1 is the prompt this function built before the negotiation existed, character for
604
+ * character.** No negotiation, or one carrying nothing, adds no block and no guidance; a negotiated
605
+ * round only ever APPENDS to both halves. §5.3 clears the transcript with the counter, so the rating
606
+ * after a reset is a round-1 rating by construction rather than by the caller remembering to make
607
+ * one.
608
+ *
609
+ * §4.3 defines the rated unit tool-generally (tool name + JSON arguments); `run_shell_command` is
610
+ * the case whose argument is a command string, and it alone is additionally normalized and
611
+ * home-path-folded before fencing. The first implementation covers the shell only — every other
612
+ * tool is granted or escalated by the rung without a rating call until [[EXT-30]] widens the gate.
613
+ *
614
+ * Exposed (and returning plain strings) so tests can assert the structure: the tag is present,
615
+ * the untrusted-input preamble is present, and an injection string inside the command lands
616
+ * inside the tag rather than being acted on.
617
+ */
618
+ export declare function buildRaterPrompt(command: string, options?: {
619
+ home?: string;
620
+ grantedTools?: readonly GrantedToolSummary[];
621
+ /**
622
+ * [[EXT-29]] (§5.1) — the negotiation so far, from round 2 onward. Absent or empty builds
623
+ * exactly the round-1 prompt this function built before the negotiation existed, character for
624
+ * character, which is what makes §5.6's *"a cleared transcript means a round-1 context"* a
625
+ * property of this function rather than a discipline the caller has to keep.
626
+ */
627
+ negotiation?: RaterNegotiationContext;
628
+ /**
629
+ * [[EXT-29]] (§5.2) — whether a rejection will be handed back to the AGENT rather than to a
630
+ * person, i.e. the rung negotiates ({@link import('#src/config.js').isNegotiatingRung}).
631
+ *
632
+ * **Independent of `negotiation` on purpose.** §5.1 decides what the rating may SEE; this
633
+ * decides how a rejection must be WRITTEN, and the two diverge in exactly the round §5.6 cares
634
+ * most about — round 1 of a negotiation, and the round right after a §5.3 reset, where the
635
+ * context is empty and the rejection is still addressed to the agent.
636
+ *
637
+ * It changes the SYSTEM prompt only. The user message is a function of the command and the
638
+ * context alone, so a negotiation's round 1 has a byte-identical user prompt to an
639
+ * `assisted` rating of the same command.
640
+ */
641
+ negotiable?: boolean;
642
+ }): {
643
+ system: string;
644
+ user: string;
645
+ };
646
+ /**
647
+ * Rate a single shell command with the rater model and return a structured
648
+ * {@link ShellSafetyVerdict}.
649
+ *
650
+ * - Builds an injection-hardened, normalized prompt ({@link buildRaterPrompt}).
651
+ * - Calls the rater model (defaults to `config.llm`) via `withStructuredOutput(schema)`.
652
+ * - Races the call against {@link RATER_DEFAULT_TIMEOUT_MS}.
653
+ * - **Fail-closed:** any throw / timeout / parse failure returns {@link FAIL_CLOSED_VERDICT}
654
+ * (`destructive` + "could not assess"), never an approval.
655
+ *
656
+ * Note: this only produces a verdict; the approve / escalate / halt decision (including
657
+ * fail-closed-on-ambiguity) is made by {@link mapVerdictToAction} in the runner.
658
+ */
659
+ export declare function rateShellCommand(command: string, config: GthConfig, options?: {
660
+ model?: BaseChatModel;
661
+ home?: string;
662
+ timeoutMs?: number;
663
+ /**
664
+ * EXT-58 (§4.4) — the already-granted built-ins of the current rung. Supplied, the rater is
665
+ * asked to name one whenever it does not return `safe` and one would do the job; omitted, the
666
+ * prompt is exactly as before and no suggestion is ever produced.
667
+ */
668
+ grantedTools?: readonly GrantedToolSummary[];
669
+ /**
670
+ * [[EXT-29]] (§5.1) — the negotiation so far, for a rating from round 2 onward. Passed straight
671
+ * to {@link buildRaterPrompt}; absent or empty, this call is a round-1 rating and the prompt,
672
+ * the verdict and every decision made from it are exactly what they were before.
673
+ */
674
+ negotiation?: RaterNegotiationContext;
675
+ /**
676
+ * [[EXT-29]] (§5.2) — whether a rejection is addressed to the agent (the rung negotiates).
677
+ * Passed straight to {@link buildRaterPrompt}; see the option there for why it is independent
678
+ * of `negotiation`.
679
+ */
680
+ negotiable?: boolean;
681
+ /**
682
+ * [[TUI-C27]] — the sink for the diagnostic record of THIS call, handed over **at the send
683
+ * site**, carrying the prompt strings that are about to be sent.
684
+ *
685
+ * It is called once, BEFORE the model is invoked, with a record this function then fills in as
686
+ * the answer arrives. Two properties follow, and both are the point:
687
+ *
688
+ * - **The prompt is captured, never re-rendered.** The caller receives the very strings passed
689
+ * to `invoke`, so nothing downstream can rebuild a prompt that disagrees with the one that
690
+ * was actually sent — the one thing a diagnostic archive must never do.
691
+ * - **A rater that never answers still leaves a record of what it was asked.** The record is in
692
+ * the caller's hands before the call is made, so a hang, a timeout or a throw cannot take the
693
+ * question with it.
694
+ *
695
+ * Omitted (the eval target, and every caller that wants no diagnostics) costs nothing: no
696
+ * record is built.
697
+ */
698
+ onCapture?: (capture: RaterCallCapture) => void;
699
+ /** [[TUI-C27]] — `approvals.rater`, recorded on the capture so a dump names WHO rated. */
700
+ raterProfile?: string;
701
+ }): Promise<ShellSafetyVerdict>;
702
+ /**
703
+ * The action the approvals gate resolves to for a single gated call, BEFORE the human prompt.
704
+ *
705
+ * - `approve` — approve ONCE; do not touch the human or the allow-list.
706
+ * - `escalate` — fall through to the human approval callback, carrying the verdict when one
707
+ * exists. Where there is no human, §6.2 turns this into an immediate non-zero exit — that
708
+ * translation belongs to the runner, not here.
709
+ * - `halt` — **end the agent loop** (§4.2). Reserved for `attack`. It is not a rejection the
710
+ * model can respond to and offers it no moves; no rung except `bypass` can turn it into
711
+ * anything else.
712
+ * - `reject` — [[EXT-29]] (§5): hand the rater's explanation back to the **agent** as the refused
713
+ * call's tool result (§7), opening a round of the negotiation. Returned for `destructive` at
714
+ * `auto` and nowhere else.
715
+ *
716
+ * **`reject` says the outcome is negotiable, NOT that the negotiation may continue.** This mapping
717
+ * is keyed on the rung and knows nothing about how many rounds have been spent; §5.3's consecutive
718
+ * cap and the reachability bound live with the state they count, in the runner, which turns a
719
+ * `reject` into an escalation once either is spent. Putting the counters in here would make a pure
720
+ * rung-keyed table depend on session history, and would give the eval target
721
+ * (`@gaunt-sloth/batch`'s `raterTarget`) an action that varies with something it does not model.
722
+ *
723
+ * **[[EXT-81]] retired the fourth arm, `abstain`.** A command whose target the gate could not
724
+ * statically resolve used to skip the rating call entirely and return that action instead. Under
725
+ * §6.1's rule — *deterministic checks fire only where we are confident something is a threat; where
726
+ * we cannot tell, the model decides* — a parser reporting that it could not resolve a string is not
727
+ * a detection, so it no longer earns an action of its own. What it earns is a neutral note in the
728
+ * rating prompt ({@link buildParserPreflightNote}) and a real rating, which is also what restores
729
+ * the ceiling: `catastrophic` and `attack` were UNREACHABLE for that whole class while nobody rated
730
+ * it, so `pwd && rm -rf ~` could only ever be floored at `destructive`.
731
+ *
732
+ * There is deliberately **no `refuse` arm for `catastrophic`** (settled 2026-07-27c, §4.2). The
733
+ * deterministic members of that class — fork bomb, `mkfs`, `rm -rf /`, `dd` to a block device — are
734
+ * already refused unappealably by the §8 hardline floor under every rung including `bypass`, so a
735
+ * refusing `catastrophic` would add nothing for the commands that motivate the idea. What it would
736
+ * newly refuse is the remainder the floor cannot reach, every member of which has routine
737
+ * legitimate use (a staging database, an ephemeral `terraform destroy`, a preview namespace). An
738
+ * unmeasured classifier belongs behind a human who can correct it; a refusal has no correction
739
+ * path.
740
+ */
741
+ export type RaterAction = 'approve' | 'escalate' | 'halt' | 'reject';
742
+ /** Inputs to the decision mapping: just the rung. Each rung fully determines behaviour (§1). */
743
+ export interface RaterDecisionOptions {
744
+ /** The rung in force for this session. */
745
+ rung: ApprovalRung;
746
+ }
747
+ /**
748
+ * The verdict {@link mapVerdictToAction} acts on, after the gate's own fail-closed preflight has
749
+ * overridden the rater where it must. Returned alongside the action so the caller surfaces the
750
+ * HONEST reason (a "could not assess" note) rather than whatever the rater claimed about a
751
+ * command the gate could not statically vet. `undefined` at the unrated rungs, where no rating
752
+ * call was made at all.
753
+ */
754
+ export interface RaterDecision {
755
+ action: RaterAction;
756
+ /** The verdict actually used — the rater's, or the fail-closed `destructive` override. */
757
+ verdict?: ShellSafetyVerdict;
758
+ }
759
+ /**
760
+ * Is this outcome below the deterministic `destructive` floor — i.e. may a preflight rewrite it?
761
+ *
762
+ * See {@link BELOW_DESTRUCTIVE_FLOOR}. An outcome that is not in the table is treated as below the
763
+ * floor, so an out-of-band value is FLOORED to `destructive` rather than sailing past the preflight
764
+ * carrying the model's own unvalidated reason.
765
+ *
766
+ * The lookup is OWN-PROPERTY-ONLY, and the declared `boolean` return is the reason. `outcome` is
767
+ * only `RaterOutcome` as far as the compiler is concerned — this helper exists to be robust to a
768
+ * value that lied — and a `?? undefined` default would still hand back the *inherited* value for a
769
+ * prototype-chain key (`'toString'` → a function, `'constructor'` → `Object`). Those happen to be
770
+ * truthy, so today's single caller would still floor; but a caller written as `=== true`, which is
771
+ * how a predicate advertised as hardened invites being consumed, would fail OPEN on exactly the
772
+ * class of input this function is for. `Object.hasOwn` makes the advertised invariant true rather
773
+ * than incidentally true.
774
+ */
775
+ export declare function isBelowDestructiveFloor(outcome: RaterOutcome): boolean;
776
+ /**
777
+ * **THE deterministic floor — the one place an outcome is raised to `destructive`.**
778
+ *
779
+ * Every gated call reaches it: a shell command through {@link mapVerdictToAction}'s preflights
780
+ * ({@link preflightFloorReason}), a tool call through its effective `openWorldHint`
781
+ * ({@link openWorldToolFloorReason}, §4.7.3). They differ only in the *reason* they compute; what
782
+ * the reason then does to the outcome is decided here and nowhere else. A second implementation is
783
+ * how a gate and a display come to disagree about what a call is, and how one of them comes to
784
+ * *lower* an outcome the other raised.
785
+ *
786
+ * Two properties, both delegated to {@link isBelowDestructiveFloor} so they hold for every caller:
787
+ *
788
+ * - **It only ever RAISES.** A `destructive`, `catastrophic` or `attack` verdict passes through
789
+ * untouched, keeping its own explanation (and any §4.4 suggestion) — the floor is agreeing with
790
+ * it, not overriding it, and a floor that rewrote `catastrophic` would silently trade an
791
+ * unnegotiable escalation for a negotiable one.
792
+ * - **`undefined` is below the floor.** Nothing has assessed the call, so there is no outcome for
793
+ * the floor to defer to; a call nobody rated is exactly the call this rule exists to speak for.
794
+ * That is what lets a tool call — which no rater sees while §4.3's scope boundary stands — be
795
+ * floored by the same function that floors a rated shell command.
796
+ *
797
+ * @param verdict The outcome so far, or `undefined` when nothing has rated the call.
798
+ * @param reason The floor reason, or `null` when no preflight fired (the verdict is returned as-is).
799
+ */
800
+ export declare function applyDestructiveFloor(verdict: ShellSafetyVerdict, reason: string | null): ShellSafetyVerdict;
801
+ export declare function applyDestructiveFloor(verdict: ShellSafetyVerdict | undefined, reason: string | null): ShellSafetyVerdict | undefined;
802
+ /**
803
+ * EXT-70 (§4.7.2, §4.7.3) — the **tool** arm of the open-world floor: the reason a call whose
804
+ * EFFECTIVE `openWorldHint` is true is floored at `destructive`, or `null` when it is not.
805
+ *
806
+ * It sits beside {@link preflightFloorReason} because it is the same rule seen from the other side.
807
+ * §4.6 floors a shell fetch before any model call precisely so that no misreading of a hostname can
808
+ * auto-approve; *the same fetch reached through a tool instead of through `curl` must not be
809
+ * ungated*, or the preflight is a rule about spelling rather than about fetching. Both feed
810
+ * {@link applyDestructiveFloor}.
811
+ *
812
+ * **Independent of `readOnlyHint`, and that is the whole of §4.7.3.** A fetch tool is read-only in
813
+ * the local sense — it mutates nothing on this machine — while reaching the network; the two facts
814
+ * are unrelated, and `gth_web_fetch` (`readOnlyHint: true`, `openWorldHint: true`) is the case that
815
+ * proves it. `destructiveHint` is not consulted either: §4.7.2 lets it only ever RAISE, so a
816
+ * `destructiveHint: false` can never lower a floor this rule set. `idempotentHint` has no built-in
817
+ * consumer at all — do not invent one here.
818
+ *
819
+ * @param annotations The call's effective set (§4.7.1), never its declared one — trust has already
820
+ * been applied, so an untrusted server's `openWorldHint: false` has already collapsed to the
821
+ * fail-closed `true` by the time it arrives. `undefined` (a source that cannot decide) floors, in
822
+ * the same direction as the fail-closed default it would otherwise have returned.
823
+ */
824
+ export declare function openWorldToolFloorReason(annotations: EffectiveToolAnnotations | undefined): string | null;
825
+ /** Which of the two deterministic preflights fired. See {@link preflightFloorFinding}. */
826
+ export type PreflightFloorKind = 'script-env-leak' | 'open-world';
827
+ /** A preflight finding: which arm fired, and the reason it floors the command with. */
828
+ export interface PreflightFloorFinding {
829
+ kind: PreflightFloorKind;
830
+ reason: string;
831
+ }
832
+ /**
833
+ * [[TUI-C27]] — the same finding {@link preflightFloorReason} returns, with the ARM NAMED.
834
+ *
835
+ * The reason alone is what the decision needs; a diagnostic archive needs to say *which* stage
836
+ * decided, and "an environment variable was expanded into a script" and "a host literal sat in a
837
+ * fetch position" are two different findings a reader must be able to tell apart without matching
838
+ * prose prefixes. `preflightFloorReason` delegates here rather than the two existing side by side:
839
+ * a second copy of this ordering is how a gate and a dump come to disagree about what floored a
840
+ * command.
841
+ */
842
+ export declare function preflightFloorFinding(command: string): PreflightFloorFinding | null;
843
+ /**
844
+ * CFG-27 — pure, testable mapping from a {@link ShellSafetyVerdict} + the raw command to a
845
+ * {@link RaterAction}, keyed on the **rung** (spec §4.2, §8):
846
+ *
847
+ * | Outcome | `manual`/`write` | `assisted` | `auto` | `bypass` |
848
+ * |---|---|---|---|---|
849
+ * | — (no rating) | escalate | | | approve |
850
+ * | `safe` | — | approve | approve | — |
851
+ * | `destructive` | — | escalate | **reject** — §5's negotiation ([[EXT-29]]) | — |
852
+ * | `catastrophic` | — | escalate | escalate — **never negotiate** | — |
853
+ * | `attack` | — | **halt** | **halt** | — |
854
+ *
855
+ * **[[EXT-81]] — there is no longer a row cutting across that column.** A command whose target the
856
+ * gate cannot statically resolve used to return `abstain` here, before the `safe` check and after
857
+ * the two severe outcomes. It is now rated like any other command, carrying a neutral note about
858
+ * the shape the parser saw ({@link buildParserPreflightNote}), and this table is the whole mapping
859
+ * again. The table gained nothing it did not have: what it LOST is a branch that made
860
+ * `catastrophic` and `attack` unreachable for every composed, substituting or redirecting command.
861
+ *
862
+ * Order of precedence (fail-closed FIRST — **this ordering IS the safety property**):
863
+ *
864
+ * 1. `bypass` → `approve`. The gate is off. The declared deny list and the exec-time hardline
865
+ * floor still apply, but neither is decided here.
866
+ * 2. Unrated rungs (`manual`, `write`) → `escalate`. No model is consulted at all; the
867
+ * allow-list is checked by the caller BEFORE this function, so reaching here means the human
868
+ * decides. (The two rungs behave identically here, and that is not a missing branch: what
869
+ * separates them is which tools they auto-grant, decided once in `resolveGatedToolNames` when the
870
+ * gated set is built. A call that reaches this function is already one the rung did not grant,
871
+ * and the shell — this function's only subject — is granted by neither.)
872
+ * 3. **The deterministic preflight FINDINGS, which FLOOR the outcome at `destructive` and never
873
+ * lower one** ({@link preflightFloorReason}): the script-env-leak preflight
874
+ * ({@link hasScriptEnvLeakRisk}) and EXT-61's open-world preflight
875
+ * ({@link findOpenWorldHostLiterals} — a host literal in a fetch/transfer position, §4.6). Both
876
+ * are recomputed from the RAW command, independently of what the rater said. Either rewrites a
877
+ * verdict that sits BELOW the floor — i.e. `safe`, and only `safe`
878
+ * ({@link isBelowDestructiveFloor}) — to `destructive` with an honest reason, **before the `safe`
879
+ * check**, so a manipulated `safe` verdict can never slip one of them through. **A rater verdict
880
+ * may only ever make an outcome worse, never better**, and so may a preflight: `destructive`,
881
+ * `catastrophic` and `attack` all pass through UNCHANGED. (Before the rescale this branch
882
+ * excluded the single halting outcome BY NAME. Renamed in place it would have let a preflight hit
883
+ * *downgrade* a `catastrophic` verdict to `destructive` — the exact inverse of the invariant
884
+ * above, silently trading an unnegotiable escalation for a negotiable one at `auto`.)
885
+ * 4. `attack` → `halt`, at both rated rungs, never negotiable.
886
+ * 5. `catastrophic` → `escalate`, and MUST NOT enter §5's negotiation.
887
+ * 6. `safe` → `approve`; `destructive` → `escalate` at `assisted`, `reject` at `auto` (§5's
888
+ * negotiation, [[EXT-29]]).
889
+ *
890
+ * **EXT-58 (§4.4): the verdict's `suggestedTool` is not read here, and that is deliberate.** A
891
+ * suggestion is never an approval — it must not change the action, must not approve the original
892
+ * command, and must not pre-approve the suggested tool. The gate also never decides for itself that
893
+ * a shell command is "equivalent" to a built-in and substitutes it: any such equivalence test would
894
+ * be a second command parser, and a second command parser is a second place for the gate to be
895
+ * bypassed. The suggestion is carried, untouched, to the human (§6) and to the model (§7) — nothing
896
+ * else. Note that the fail-closed rewrite in (3) builds a FRESH verdict and therefore drops any
897
+ * suggestion along with the reason it belonged to: a verdict the gate has just declared
898
+ * untrustworthy must not keep recommending anything. A verdict the preflight leaves alone was never
899
+ * declared untrustworthy — the gate is agreeing with it, not overriding it — so it keeps both.
900
+ *
901
+ * @param command The raw command string (used to recompute ambiguity + preflight independently
902
+ * of the rater, so the gate is robust even if the rater is wrong or manipulated).
903
+ * @param verdict The rater's verdict (or {@link FAIL_CLOSED_VERDICT}); `undefined` at the unrated
904
+ * rungs. A missing verdict at a RATED rung is treated as {@link FAIL_CLOSED_VERDICT}.
905
+ * @param opts The rung in force.
906
+ */
907
+ export declare function mapVerdictToAction(command: string, verdict: ShellSafetyVerdict | undefined, opts: RaterDecisionOptions): RaterDecision;
908
+ /**
909
+ * EXT-71 §3.2 — the mapping for a call an **allow entry already matched** while keeping the rater
910
+ * involved (`rate: true`). This is a **TRIPWIRE, not a re-adjudication**, and the difference is the
911
+ * whole reason it is a separate function from {@link mapVerdictToAction}:
912
+ *
913
+ * | Outcome | Action | Why |
914
+ * |---|---|---|
915
+ * | `safe` | approve | nothing to say |
916
+ * | `destructive` | **approve** | the human already authorized this call; the rater does not overrule a standing human decision by disliking it |
917
+ * | `catastrophic` | escalate | a human decides, and per §4.2 that approval is never sticky |
918
+ * | `attack` | **halt** | exactly per §4.2 — the structure evidenced compromise, which no prior grant answers |
919
+ *
920
+ * The rater's job on an allow-listed call is to catch the tail where a broad entry matched
921
+ * something structurally hostile — not to re-ask a question the human answered.
922
+ *
923
+ * **The deterministic preflights are deliberately not consulted** ({@link preflightFloorReason} is
924
+ * not called). §4.6 states it directly for the open-world arm: *an allow match lifts this floor even
925
+ * when the entry keeps the rater involved — the tripwire still sees the call; the floor does not
926
+ * apply to it.* The script-env-leak arm is lifted with it, and doing so changes no outcome: a
927
+ * preflight only ever raises `safe` to `destructive`, and both of those run here. Applying the floor
928
+ * would therefore alter nothing except to replace an honest verdict with a note about a decision
929
+ * this mapping does not make.
930
+ *
931
+ * @param verdict The rater's verdict; `undefined` or a fail-closed verdict is `destructive` and so
932
+ * runs — the tripwire failing to answer does not revoke the human's standing decision, exactly as
933
+ * `rate: false` would not have asked in the first place.
934
+ */
935
+ export declare function mapAllowMatchedVerdictToAction(verdict: ShellSafetyVerdict | undefined): RaterDecision;