@causyne/agent 1.20.124 → 1.20.127

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 (235) hide show
  1. package/bin/causyne.js +1 -1
  2. package/package.json +4 -4
  3. package/src/acp/protocol.ts +19 -1
  4. package/src/acp/server.js +282 -8
  5. package/src/acp/server.ts +284 -8
  6. package/src/agent/abortableDelay.js +2 -2
  7. package/src/agent/abortableDelay.ts +2 -2
  8. package/src/agent/errorClassifier.js +9 -1
  9. package/src/agent/errorClassifier.ts +8 -1
  10. package/src/agentLoop.js +83 -27
  11. package/src/agentLoop.ts +92 -26
  12. package/src/approvalPolicy.js +34 -10
  13. package/src/approvalPolicy.ts +42 -11
  14. package/src/browser/causyneBrowser.js +30 -3
  15. package/src/browser/causyneBrowser.ts +33 -3
  16. package/src/browser/urlPolicy.js +14 -1
  17. package/src/browser/urlPolicy.ts +12 -1
  18. package/src/cliMode.js +21 -9
  19. package/src/cliMode.ts +20 -8
  20. package/src/commands.js +188 -32
  21. package/src/commands.ts +209 -32
  22. package/src/config.js +19 -4
  23. package/src/config.ts +18 -4
  24. package/src/core/contextCompactor.js +54 -7
  25. package/src/core/contextCompactor.ts +63 -7
  26. package/src/core/goalLoop.js +257 -0
  27. package/src/core/goalLoop.ts +310 -0
  28. package/src/entrypoint.js +135 -3
  29. package/src/entrypoint.ts +136 -3
  30. package/src/game/causyneCoreBridge.js +686 -0
  31. package/src/game/causyneCoreBridge.ts +702 -0
  32. package/src/game/gameLauncher.js +287 -0
  33. package/src/game/gameLauncher.ts +352 -0
  34. package/src/game/gameProvisioner.js +425 -0
  35. package/src/game/gameProvisioner.ts +488 -0
  36. package/src/headlessCli.js +19 -12
  37. package/src/headlessCli.ts +22 -8
  38. package/src/infra/atomicWriter.js +40 -4
  39. package/src/infra/atomicWriter.ts +36 -4
  40. package/src/launchIntent.js +73 -3
  41. package/src/launchIntent.ts +76 -3
  42. package/src/lsp/lspClient.js +83 -12
  43. package/src/lsp/lspClient.ts +75 -12
  44. package/src/mcp/mcpRegistry.js +75 -8
  45. package/src/mcp/mcpRegistry.ts +70 -7
  46. package/src/memory/contextBudget.js +2 -0
  47. package/src/memory/contextBudget.ts +1 -0
  48. package/src/modelVariants.js +45 -0
  49. package/src/modelVariants.ts +54 -0
  50. package/src/outputRecovery.js +3 -2
  51. package/src/outputRecovery.ts +4 -2
  52. package/src/permissionPresets.js +327 -0
  53. package/src/permissionPresets.ts +361 -0
  54. package/src/providers/antigravity.js +62 -9
  55. package/src/providers/antigravity.ts +73 -9
  56. package/src/providers/byokHttp.js +7 -1
  57. package/src/providers/byokHttp.ts +6 -1
  58. package/src/providers/byokStream.js +21 -8
  59. package/src/providers/byokStream.ts +17 -7
  60. package/src/providers/dashscope-byok.js +21 -5
  61. package/src/providers/dashscope-byok.ts +29 -11
  62. package/src/providers/moonshot.js +26 -7
  63. package/src/providers/moonshot.ts +34 -13
  64. package/src/providers/muse.js +6 -0
  65. package/src/providers/muse.ts +8 -0
  66. package/src/providers/ollama.js +39 -7
  67. package/src/providers/ollama.ts +36 -7
  68. package/src/providers/openai-compatible.js +16 -3
  69. package/src/providers/openai-compatible.ts +13 -3
  70. package/src/providers/openai.js +62 -4
  71. package/src/providers/openai.ts +50 -4
  72. package/src/providers/openrouter.js +19 -4
  73. package/src/providers/openrouter.ts +21 -4
  74. package/src/providers/qwen-byok.js +21 -5
  75. package/src/providers/qwen-byok.ts +29 -11
  76. package/src/providers/xai.js +26 -10
  77. package/src/providers/xai.ts +34 -16
  78. package/src/reporting.js +4 -2
  79. package/src/reporting.ts +4 -2
  80. package/src/sandbox.js +34 -0
  81. package/src/sandbox.ts +43 -0
  82. package/src/scheduler/scheduler.js +372 -0
  83. package/src/scheduler/scheduler.ts +433 -0
  84. package/src/sessionSearchIndex.js +267 -0
  85. package/src/sessionSearchIndex.ts +311 -0
  86. package/src/skillsManager.js +2 -3
  87. package/src/skillsManager.ts +2 -3
  88. package/src/toolPacks.js +6 -0
  89. package/src/toolPacks.ts +6 -0
  90. package/src/tools/applyPatch.js +1 -1
  91. package/src/tools/applyPatch.ts +1 -1
  92. package/src/tools/generateMediaViaApi.js +4 -3
  93. package/src/tools/generateMediaViaApi.ts +4 -3
  94. package/src/tools/nativeEngine.js +2 -2
  95. package/src/tools/nativeEngine.ts +2 -2
  96. package/src/tools/openSourceToolProvisioner.js +2 -2
  97. package/src/tools/openSourceToolProvisioner.ts +2 -2
  98. package/src/tools/payloadSanitizer.js +0 -1
  99. package/src/tools/payloadSanitizer.ts +0 -1
  100. package/src/tools/pdfReader.js +122 -20
  101. package/src/tools/pdfReader.ts +111 -20
  102. package/src/tools/presentDeliverable.js +103 -0
  103. package/src/tools/presentDeliverable.ts +127 -0
  104. package/src/tools/ptcRuntime.js +444 -0
  105. package/src/tools/ptcRuntime.ts +490 -0
  106. package/src/tools/ptyTerminal.js +1096 -0
  107. package/src/tools/ptyTerminal.ts +1231 -0
  108. package/src/tools/registry.js +21 -12
  109. package/src/tools/registry.ts +21 -12
  110. package/src/tools/toolOutputStore.js +26 -4
  111. package/src/tools/toolOutputStore.ts +22 -4
  112. package/src/tools/webFetch.js +158 -11
  113. package/src/tools/webFetch.ts +145 -11
  114. package/src/tools/webSearch.js +123 -36
  115. package/src/tools/webSearch.ts +124 -33
  116. package/src/tui/banner.js +5 -1
  117. package/src/tui/banner.ts +6 -1
  118. package/src/tui/chatRenderer.js +1 -2
  119. package/src/tui/chatRenderer.ts +1 -2
  120. package/src/tui/completion.js +1 -0
  121. package/src/tui/completion.ts +1 -0
  122. package/src/tui/composerControls.js +111 -27
  123. package/src/tui/composerControls.ts +124 -28
  124. package/src/tui/dialogs.js +3 -16
  125. package/src/tui/dialogs.ts +3 -16
  126. package/src/tui/home.js +1 -0
  127. package/src/tui/home.ts +1 -0
  128. package/src/tui/invocation.js +1 -2
  129. package/src/tui/invocation.ts +1 -2
  130. package/src/tui/modelPicker.js +22 -12
  131. package/src/tui/modelPicker.ts +22 -12
  132. package/src/tui/overlay.js +2 -5
  133. package/src/tui/overlay.ts +2 -5
  134. package/src/tui/prompt.js +6 -4
  135. package/src/tui/prompt.ts +6 -4
  136. package/src/tui/selectList.js +4 -12
  137. package/src/tui/selectList.ts +4 -12
  138. package/src/tui/setup.js +22 -9
  139. package/src/tui/setup.ts +26 -9
  140. package/src/tui/statusLine.ts +2 -0
  141. package/src/web/client/browserPanel.js +702 -0
  142. package/src/web/client/browserPanel.ts +663 -0
  143. package/src/web/client/chatStream.js +309 -0
  144. package/src/web/client/chatStream.ts +289 -0
  145. package/src/web/client/cliPanel.js +165 -0
  146. package/src/web/client/cliPanel.ts +171 -0
  147. package/src/web/client/composer.js +204 -0
  148. package/src/web/client/composer.ts +209 -0
  149. package/src/web/client/diffPanel.js +176 -0
  150. package/src/web/client/diffPanel.ts +203 -0
  151. package/src/web/client/dom.js +220 -0
  152. package/src/web/client/dom.ts +221 -0
  153. package/src/web/client/filesAndCanvas.js +231 -0
  154. package/src/web/client/filesAndCanvas.ts +238 -0
  155. package/src/web/client/gameLauncherUi.js +78 -0
  156. package/src/web/client/gameLauncherUi.ts +78 -0
  157. package/src/web/client/main.js +301 -0
  158. package/src/web/client/main.ts +368 -0
  159. package/src/web/client/markdown.js +364 -0
  160. package/src/web/client/markdown.ts +373 -0
  161. package/src/web/client/modelPicker.js +455 -0
  162. package/src/web/client/modelPicker.ts +451 -0
  163. package/src/web/client/permissionPresetsUi.js +307 -0
  164. package/src/web/client/permissionPresetsUi.ts +333 -0
  165. package/src/web/client/sessions.js +353 -0
  166. package/src/web/client/sessions.ts +372 -0
  167. package/src/web/client/settingsModal.js +191 -0
  168. package/src/web/client/settingsModal.ts +176 -0
  169. package/src/web/client/state.js +250 -0
  170. package/src/web/client/state.ts +233 -0
  171. package/src/web/client/streamSmoother.js +127 -0
  172. package/src/web/client/streamSmoother.ts +119 -0
  173. package/src/web/client/studioLayout.js +54 -0
  174. package/src/web/client/studioLayout.ts +60 -0
  175. package/src/web/client/studioShell.js +327 -0
  176. package/src/web/client/studioShell.ts +340 -0
  177. package/src/web/client/studioStart.js +77 -0
  178. package/src/web/client/studioStart.ts +89 -0
  179. package/src/web/client/terminalPanel.js +357 -0
  180. package/src/web/client/terminalPanel.ts +345 -0
  181. package/src/web/client/turnView.js +934 -0
  182. package/src/web/client/turnView.ts +981 -0
  183. package/src/web/client/types.js +1 -0
  184. package/src/web/client/types.ts +319 -0
  185. package/src/web/client/validators.js +106 -0
  186. package/src/web/client/validators.ts +96 -0
  187. package/src/web/server/activeRuns.js +152 -0
  188. package/src/web/server/activeRuns.ts +171 -0
  189. package/src/web/server/routesBrowser.js +355 -0
  190. package/src/web/server/routesBrowser.ts +386 -0
  191. package/src/web/server/routesChat.js +304 -0
  192. package/src/web/server/routesChat.ts +347 -0
  193. package/src/web/server/routesCore.js +472 -0
  194. package/src/web/server/routesCore.ts +522 -0
  195. package/src/web/server/routesTerminal.js +162 -0
  196. package/src/web/server/routesTerminal.ts +182 -0
  197. package/src/web/server/routesWorkspace.js +510 -0
  198. package/src/web/server/routesWorkspace.ts +546 -0
  199. package/src/web/server/security.js +98 -0
  200. package/src/web/server/security.ts +108 -0
  201. package/src/web/server/sessionTranscript.js +586 -0
  202. package/src/web/server/sessionTranscript.ts +566 -0
  203. package/src/web/server/staticAssets.js +80 -0
  204. package/src/web/server/staticAssets.ts +91 -0
  205. package/src/web/server/types.js +1 -0
  206. package/src/web/server/types.ts +135 -0
  207. package/src/web/server/workspaceFiles.js +368 -0
  208. package/src/web/server/workspaceFiles.ts +363 -0
  209. package/src/web/skybridgeServer.js +76 -2449
  210. package/src/web/skybridgeServer.ts +118 -2600
  211. package/src/web/skybridgeUi.js +16 -450
  212. package/src/web/skybridgeUi.ts +16 -454
  213. package/src/web/styles/agent.css +380 -0
  214. package/src/web/styles/composer.css +193 -0
  215. package/src/web/styles/overlays.css +436 -0
  216. package/src/web/styles/shell.css +387 -0
  217. package/src/web/styles/studio.css +723 -0
  218. package/src/web/styles/thread.css +221 -0
  219. package/src/web/styles/tokens.css +94 -0
  220. package/src/web/ui/brandMark.js +73 -0
  221. package/src/web/ui/brandMark.ts +82 -0
  222. package/src/web/ui/modalsTemplate.js +139 -0
  223. package/src/web/ui/modalsTemplate.ts +139 -0
  224. package/src/web/ui/sidebarTemplate.js +63 -0
  225. package/src/web/ui/sidebarTemplate.ts +64 -0
  226. package/src/web/ui/studioTemplate.js +258 -0
  227. package/src/web/ui/studioTemplate.ts +258 -0
  228. package/src/web/ui/workspaceTemplate.js +72 -0
  229. package/src/web/ui/workspaceTemplate.ts +73 -0
  230. package/src/worktreeManager.js +16 -1
  231. package/src/worktreeManager.ts +22 -1
  232. package/src/web/skybridgeClientScript.js +0 -3951
  233. package/src/web/skybridgeClientScript.ts +0 -3952
  234. package/src/web/skybridgeStyles.js +0 -827
  235. package/src/web/skybridgeStyles.ts +0 -828
package/src/agentLoop.js CHANGED
@@ -83,6 +83,7 @@ import { StreamingCodePreview, NativeCodeObserver, codeProgressFromAction } from
83
83
  import { StallGuardController } from './stallGuard.js';
84
84
  import { buildRecoverableDroppedSummary, pruneStaleToolObservations, shortenOversizedToolObservations, pruneExecutedToolArguments } from './historyPruner.js';
85
85
  import { isOutputRecoveryRead } from './outputRecovery.js';
86
+ import { autonomyModeToPreset, getPermissionPresetDescriptor, normalizePermissionPreset, presetToAutonomyMode, renderPermissionPolicyContext, resolveConfigPermissionPreset } from './permissionPresets.js';
86
87
  import { isPlanReviewHandoff, isPlanningOnlyRequest } from './taskContinuation.js';
87
88
  export function noncachedTokens(usage) {
88
89
  if (!usage)
@@ -136,10 +137,10 @@ ${AGENT_USER_POLICY}
136
137
  - **Code Quality**: Write clear, runnable, idiomatic code following existing project conventions without trivial inline comments or TODO placeholders. Preserve unrelated behavior.
137
138
  - **Planning & Decisions**: Batch independent read-only calls together. Use \`update_plan\` only for genuinely complex multi-stage implementations (keep one step \`in_progress\`). Use \`request_decision\` only when a material architecture/product/security choice genuinely blocks progress.
138
139
  - **Git Commits**: Follow the target repository's commit message conventions and project instructions (such as \`AGENTS.md\` or \`git log\`) when committing changes.
139
- - **Autonomy & Safety Boundaries**:
140
- - **Mode A (Passive)**: Ask permission before mutating files, running shell commands, or installing dependencies.
141
- - **Mode B (Supervised)**: Ordinary dev dependencies allowed; ask before OS-level changes or \`sudo\`.
142
- - **Mode C (Autonomous)**: Execute ordinary in-scope work independently; whole-file/directory deletion, hard policy blocks, and workspace boundaries still require approval/compliance. Avoid interactive shell flags; use non-interactive flags (\`-y\`).
140
+ - **Permission Presets & Safety Boundaries**:
141
+ - **Read Only (\`read-only\`)**: Inspect files, search code, and read documentation only; file modifications and mutating shell commands are blocked.
142
+ - **Workspace Write (\`workspace-write\`)**: Read and edit files scoped to the active workspace; ask approval before dangerous operations, OS-level changes, or \`sudo\`.
143
+ - **Full access (\`danger-full-access\`)**: Execute ordinary in-scope workspace edits and commands directly; whole-file/directory deletion, credential safeguards, hard policy blocks, and workspace boundaries remain enforced. Avoid interactive shell flags; use non-interactive flags (\`-y\`).
143
144
  - **SSRF**: Never fetch cloud metadata (169.254.169.254, metadata.google.internal) or private LAN ranges. Loopback (\`localhost\`, \`127.0.0.1\`, \`::1\`) is permitted for local dev verification.
144
145
  - **Tool Schema Discipline**: Invoke only active Causyne or permitted peer tools using exact schema parameter names and valid JSON (no unescaped newlines or trailing commas). Respect BYOK token limits.
145
146
 
@@ -409,6 +410,9 @@ export class AgentLoop {
409
410
  this.peerMcpServers = Array.isArray(options.peerMcpServers)
410
411
  ? [...options.peerMcpServers]
411
412
  : [];
413
+ this.hostSystemInstructions = typeof options.hostSystemInstructions === 'string' && options.hostSystemInstructions.trim()
414
+ ? options.hostSystemInstructions.trim()
415
+ : null;
412
416
  this.config = loadConfig();
413
417
  applyProviderOverrides(this.config, this.providerOverride, this.modelOverride);
414
418
  if (this.variantOverride) {
@@ -909,13 +913,40 @@ export class AgentLoop {
909
913
  }
910
914
  }
911
915
  }
916
+ activePermissionPreset() {
917
+ const fromOverride = normalizePermissionPreset(this.autonomyOverride);
918
+ if (fromOverride)
919
+ return fromOverride;
920
+ return resolveConfigPermissionPreset(this.config, 'danger-full-access');
921
+ }
912
922
  setAutonomyMode(mode) {
913
- const normalized = String(mode || '').trim().toUpperCase();
914
- if (!['A', 'B', 'C'].includes(normalized)) {
915
- throw new Error('autonomy mode must be A, B, or C');
923
+ const preset = normalizePermissionPreset(mode);
924
+ if (!preset) {
925
+ throw new Error('permission preset must be read-only, workspace-write, or danger-full-access (or A, B, C)');
916
926
  }
927
+ const normalized = presetToAutonomyMode(preset);
917
928
  this.autonomyOverride = normalized;
918
929
  this.config.autonomyMode = normalized;
930
+ this.config.permissionPreset = preset;
931
+ if (this.sandbox) {
932
+ this.sandbox.autonomyMode = normalized;
933
+ this.sandbox.permissionPreset = preset;
934
+ }
935
+ }
936
+ setPermissionPreset(rawPreset) {
937
+ const preset = normalizePermissionPreset(rawPreset);
938
+ if (!preset) {
939
+ throw new Error('permission preset must be read-only, workspace-write, or danger-full-access');
940
+ }
941
+ const mode = presetToAutonomyMode(preset);
942
+ this.autonomyOverride = mode;
943
+ this.config.autonomyMode = mode;
944
+ this.config.permissionPreset = preset;
945
+ if (this.sandbox) {
946
+ this.sandbox.autonomyMode = mode;
947
+ this.sandbox.permissionPreset = preset;
948
+ }
949
+ return preset;
919
950
  }
920
951
  /**
921
952
  * A provider for UTILITY work — condensation, classification, filtering.
@@ -987,9 +1018,9 @@ export class AgentLoop {
987
1018
  const prefetched = new Map();
988
1019
  if (!Array.isArray(toolCalls) || toolCalls.length < 2)
989
1020
  return prefetched;
990
- // Mode A promises approval before every tool, including reads. Starting a
1021
+ // Read Only promises approval before every tool, including reads. Starting a
991
1022
  // read here would execute it before the serial approval and hook gates.
992
- if ((this.config.autonomyMode || 'C') === 'A')
1023
+ if (this.activePermissionPreset() === 'read-only')
993
1024
  return prefetched;
994
1025
  const eligible = [];
995
1026
  for (const toolCall of toolCalls) {
@@ -1142,11 +1173,13 @@ export class AgentLoop {
1142
1173
  const assessment = await coldObserver.evaluateMutation(tool, args, { workspaceRoot: this.workspaceRoot });
1143
1174
  if (assessment.veto)
1144
1175
  return false;
1145
- const isModeC = (this.config.autonomyMode || 'C') === 'C';
1176
+ const activePreset = this.activePermissionPreset();
1177
+ const isFullAccess = activePreset === 'danger-full-access';
1146
1178
  const needsApproval = enterpriseDecision.effect === 'ask'
1147
- || (!isModeC && uncertain)
1179
+ || (!isFullAccess && uncertain)
1148
1180
  || requiresToolApproval({
1149
- mode: this.config.autonomyMode || 'C', tool, args,
1181
+ permissionPreset: activePreset,
1182
+ mode: presetToAutonomyMode(activePreset), tool, args,
1150
1183
  risk: assessment.requiresConfirmation ? 'dangerous' : validation.risk,
1151
1184
  heavyDownload: false, standingApproval: this.isAlwaysAllowed(tool)
1152
1185
  });
@@ -1574,8 +1607,22 @@ export class AgentLoop {
1574
1607
  }
1575
1608
  updateTierLimits() {
1576
1609
  this.config = loadConfig();
1577
- if (this.autonomyOverride)
1578
- this.config.autonomyMode = this.autonomyOverride;
1610
+ if (this.autonomyOverride) {
1611
+ const overridePreset = normalizePermissionPreset(this.autonomyOverride);
1612
+ if (overridePreset) {
1613
+ this.config.permissionPreset = overridePreset;
1614
+ this.config.autonomyMode = presetToAutonomyMode(overridePreset);
1615
+ }
1616
+ else {
1617
+ this.config.autonomyMode = this.autonomyOverride;
1618
+ }
1619
+ }
1620
+ const syncedPreset = resolveConfigPermissionPreset(this.config, 'workspace-write');
1621
+ this.config.permissionPreset = syncedPreset;
1622
+ if (this.sandbox) {
1623
+ this.sandbox.permissionPreset = syncedPreset;
1624
+ this.sandbox.autonomyMode = presetToAutonomyMode(syncedPreset);
1625
+ }
1579
1626
  applyProviderOverrides(this.config, this.providerOverride, this.modelOverride);
1580
1627
  if (this.variantOverride) {
1581
1628
  this.config.reasoningEffort = this.variantOverride;
@@ -2100,7 +2147,7 @@ export class AgentLoop {
2100
2147
  if (!this.currentTaskPrompt && this.userPrompt) {
2101
2148
  this.currentTaskPrompt = this.userPrompt;
2102
2149
  }
2103
- const isAutonomousMode = (this.config.autonomyMode || 'C') === 'C';
2150
+ const isAutonomousMode = this.activePermissionPreset() === 'danger-full-access';
2104
2151
  const recoveryPaths = new Set();
2105
2152
  let modelCallIndex = 0;
2106
2153
  let softUsageNoticeIssued = false;
@@ -2264,7 +2311,8 @@ export class AgentLoop {
2264
2311
  // All transports receive the same compact catalog and selected host
2265
2312
  // schemas. Peer-native tools and native schema deferral remain provider
2266
2313
  // features; neither changes host authorization or schema selection.
2267
- const eligibleTools = await getDynamicTools(this.config.autonomyMode, this.llm.supportsVision, {
2314
+ const activePreset = this.activePermissionPreset();
2315
+ const eligibleTools = await getDynamicTools(activePreset, this.llm.supportsVision, {
2268
2316
  grantAllTools: true,
2269
2317
  allowedTools: this.sandbox.allowedTools,
2270
2318
  deniedTools: this.config.deniedTools
@@ -2297,7 +2345,8 @@ export class AgentLoop {
2297
2345
  }
2298
2346
  }
2299
2347
  // Dynamically inject the absolute latest System context
2300
- const autonomyMode = this.config.autonomyMode || 'C';
2348
+ const activePresetDesc = getPermissionPresetDescriptor(activePreset);
2349
+ const permissionPolicyLine = renderPermissionPolicyContext(activePreset, this.workspaceRoot);
2301
2350
  const allowedPaths = this.sandbox.grantAllAccess
2302
2351
  ? "/ (ALL ACCESS GRANTED - You can read/write anywhere EXCEPT system protected folders like /etc or /System)"
2303
2352
  : (this.sandbox.workspacePaths ? this.sandbox.workspacePaths.join(', ') : this.workspaceRoot);
@@ -2475,13 +2524,14 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
2475
2524
  // time a different skill is invoked. This one is stable for the task,
2476
2525
  // so it anchors too.
2477
2526
  ...(skillSystemMessage(this.activeSkill) || []),
2527
+ ...(this.hostSystemInstructions ? [{ role: 'system', content: this.hostSystemInstructions }] : []),
2478
2528
  // [5] VOLATILE tail — the only bytes that may differ between steps:
2479
2529
  // autonomy/workspace paths (change via config), live shared browser
2480
2530
  // state, and persistent memory (grows via memory_write mid-task).
2481
2531
  // Kept LAST and UNcached so a change here never invalidates [1]-[3].
2482
2532
  {
2483
2533
  role: 'system',
2484
- content: `${uncertaintyDirective ? uncertaintyDirective + '\n\n' : ''}${describeSession(this.taskId)}CURRENT AUTONOMY MODE: ${autonomyMode}\nALLOWED WORKSPACE PATHS: ${allowedPaths}\n(You MUST NOT write files outside these paths!)${sharedBrowserPrompt}${memoryContext ? `\n\n◆ PERSISTENT MEMORY (workspace-relevant notes — actual repository files and docs on disk always override memory if anything conflicts):\n${memoryContext}` : ''}`
2534
+ content: `${uncertaintyDirective ? uncertaintyDirective + '\n\n' : ''}${describeSession(this.taskId)}PERMISSION PRESET: ${activePresetDesc.label} (${activePreset})\n${permissionPolicyLine}\nALLOWED WORKSPACE PATHS: ${allowedPaths}\n(You MUST NOT write files outside these paths!)${sharedBrowserPrompt}${memoryContext ? `\n\n◆ PERSISTENT MEMORY (workspace-relevant notes — actual repository files and docs on disk always override memory if anything conflicts):\n${memoryContext}` : ''}`
2485
2535
  }
2486
2536
  ];
2487
2537
  // Dev-only visibility into what fills each step's prompt. Set
@@ -4185,8 +4235,9 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4185
4235
  // 4-Layer Security Sandbox Validation
4186
4236
  // 2. Sandbox Security Validation (CRITICAL FIX: Prevent Infinite Loop on Block)
4187
4237
  let validation = this.sandbox.validate(functionName, args);
4238
+ const recoveryCandidatePath = args.path ?? args.file_path ?? args.target ?? args.dir;
4188
4239
  if (!validation.allowed && /^Path outside allowed workspace:/.test(validation.reason || '')
4189
- && isOutputRecoveryRead(functionName, args.path, recoveryPaths)) {
4240
+ && isOutputRecoveryRead(functionName, recoveryCandidatePath, recoveryPaths)) {
4190
4241
  validation = { allowed: true, risk: 'safe', reason: 'Read exact tool output referenced by this session' };
4191
4242
  }
4192
4243
  if (!validation.allowed) {
@@ -4370,14 +4421,16 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4370
4421
  });
4371
4422
  continue;
4372
4423
  }
4373
- // A standing grant can avoid repeat prompts in supervised modes.
4374
- // Mode C is autonomous for in-scope work. Whole-file deletion asks
4424
+ // A standing grant can avoid repeat prompts in Workspace Write.
4425
+ // Full access runs in-scope work directly. Whole-file deletion asks
4375
4426
  // unless this session explicitly granted the fs_delete tool; a broad
4376
4427
  // shell grant cannot authorize deletion. Sandbox denials and observer
4377
4428
  // vetoes have already run and are never lifted by prompt policy.
4429
+ const stepPreset = this.activePermissionPreset();
4378
4430
  const standingApproval = this.isAlwaysAllowed(functionName);
4379
4431
  let needsToolApproval = requiresToolApproval({
4380
- mode: this.config.autonomyMode || 'C',
4432
+ permissionPreset: stepPreset,
4433
+ mode: presetToAutonomyMode(stepPreset),
4381
4434
  tool: functionName,
4382
4435
  args,
4383
4436
  risk: validation.risk,
@@ -4409,7 +4462,7 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4409
4462
  reason: enterpriseDecision.reason
4410
4463
  });
4411
4464
  }
4412
- if (standingApproval && !needsToolApproval && this.config.autonomyMode !== 'C' && enterpriseDecision.effect !== 'allow') {
4465
+ if (standingApproval && !needsToolApproval && stepPreset !== 'danger-full-access' && enterpriseDecision.effect !== 'allow') {
4413
4466
  auditLog.log({
4414
4467
  event: 'approval_auto_granted', taskId: this.taskId,
4415
4468
  tool: functionName, risk: validation.risk, reason: 'allow_always'
@@ -4706,7 +4759,7 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4706
4759
  }
4707
4760
  // Sovereign 100-Step Circuit Breaker Checkpoint Gate
4708
4761
  if (this.consecutiveCommands === 100 && !this.circuitBreakerUnlocked) {
4709
- if (this.config.autonomyMode === 'C') {
4762
+ if (this.activePermissionPreset() === 'danger-full-access') {
4710
4763
  this.circuitBreakerUnlocked = true;
4711
4764
  this.emitEvent({ type: 'status', message: `Continuing within the configured ${this.maxSteps}-step task limit.` });
4712
4765
  }
@@ -4737,7 +4790,7 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4737
4790
  }
4738
4791
  // Sovereign Tier Budget Extension Checkpoint Gate
4739
4792
  if (this.stepsCompleted >= this.maxSteps && !this.stopRequested) {
4740
- if (this.config.autonomyMode === 'C') {
4793
+ if (this.activePermissionPreset() === 'danger-full-access') {
4741
4794
  this.stopRequested = true;
4742
4795
  this.emitEvent({ type: 'error', message: `Task reached the configured ${this.maxSteps}-step limit without verified completion.` });
4743
4796
  }
@@ -4837,11 +4890,12 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4837
4890
  // Per tool, not one number for all of them. A build log and a
4838
4891
  // source file are not equally worth their space in the window.
4839
4892
  // Compatibility fallback preserves complete output when primary store is unavailable.
4893
+ const isRecoveryRead = functionName === 'fs_read' && isOutputRecoveryRead(functionName, args?.path ?? args?.file_path ?? args?.target, recoveryPaths);
4840
4894
  const MAX_RESULT_CHARS = resultCapFor(functionName);
4841
- const inlineLimit = Math.min(MAX_RESULT_CHARS, functionName === 'fs_read_skill' ? 16000 : functionName === 'tool_search' ? 8000 : 2500);
4895
+ const inlineLimit = Math.min(MAX_RESULT_CHARS, functionName === 'fs_read_skill' || functionName === 'fs_read' ? 16000 : functionName === 'tool_search' ? 8000 : 2500);
4842
4896
  const originalFingerprint = createHash('sha256').update(resultString).digest('hex');
4843
4897
  let spill = null;
4844
- if (resultString.length > inlineLimit) {
4898
+ if (!isRecoveryRead && resultString.length > inlineLimit) {
4845
4899
  const document = renderSpillDocument(result, { taskId: this.taskId, step: this.stepsCompleted, tool: functionName });
4846
4900
  const store = inlineLimit > 2500 ? new ToolOutputStore({ maxChars: inlineLimit, maxLines: 400, maxBytes: Math.max(50 * 1024, inlineLimit * 4) }) : defaultToolOutputStore;
4847
4901
  const stored = processToolOutputWithStore(this.taskId, toolCall.id, document, store);
@@ -5250,6 +5304,8 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
5250
5304
  apiKey: nextRoute.apiKey
5251
5305
  };
5252
5306
  delete this.config.baseUrl;
5307
+ delete this.config.reasoningEffort;
5308
+ delete this.config.reasoningBudgetTokens;
5253
5309
  this.llm = this.initializeProvider();
5254
5310
  this._utilityLlm = null;
5255
5311
  this.consecutiveFailures = 0;
package/src/agentLoop.ts CHANGED
@@ -139,6 +139,15 @@ import { StreamingCodePreview, NativeCodeObserver, codeProgressFromAction } from
139
139
  import { StallGuardController, type StallGuardDecision, type IdenticalCallObservation } from './stallGuard.js';
140
140
  import { buildRecoverableDroppedSummary, pruneStaleToolObservations, shortenOversizedToolObservations, pruneExecutedToolArguments } from './historyPruner.js';
141
141
  import { isOutputRecoveryRead } from './outputRecovery.js';
142
+ import {
143
+ autonomyModeToPreset,
144
+ getPermissionPresetDescriptor,
145
+ normalizePermissionPreset,
146
+ presetToAutonomyMode,
147
+ renderPermissionPolicyContext,
148
+ resolveConfigPermissionPreset,
149
+ type PermissionPresetId
150
+ } from './permissionPresets.js';
142
151
  import { isPlanReviewHandoff, isPlanningOnlyRequest } from './taskContinuation.js';
143
152
  export function noncachedTokens(usage: any): number {
144
153
  if (!usage) return 0;
@@ -207,6 +216,7 @@ export interface AgentLoopOptions {
207
216
  provider?: string;
208
217
  model?: string;
209
218
  variant?: string;
219
+ hostSystemInstructions?: string | undefined;
210
220
  peerMcpServers?: McpServer[] | undefined;
211
221
  }
212
222
 
@@ -246,10 +256,10 @@ ${AGENT_USER_POLICY}
246
256
  - **Code Quality**: Write clear, runnable, idiomatic code following existing project conventions without trivial inline comments or TODO placeholders. Preserve unrelated behavior.
247
257
  - **Planning & Decisions**: Batch independent read-only calls together. Use \`update_plan\` only for genuinely complex multi-stage implementations (keep one step \`in_progress\`). Use \`request_decision\` only when a material architecture/product/security choice genuinely blocks progress.
248
258
  - **Git Commits**: Follow the target repository's commit message conventions and project instructions (such as \`AGENTS.md\` or \`git log\`) when committing changes.
249
- - **Autonomy & Safety Boundaries**:
250
- - **Mode A (Passive)**: Ask permission before mutating files, running shell commands, or installing dependencies.
251
- - **Mode B (Supervised)**: Ordinary dev dependencies allowed; ask before OS-level changes or \`sudo\`.
252
- - **Mode C (Autonomous)**: Execute ordinary in-scope work independently; whole-file/directory deletion, hard policy blocks, and workspace boundaries still require approval/compliance. Avoid interactive shell flags; use non-interactive flags (\`-y\`).
259
+ - **Permission Presets & Safety Boundaries**:
260
+ - **Read Only (\`read-only\`)**: Inspect files, search code, and read documentation only; file modifications and mutating shell commands are blocked.
261
+ - **Workspace Write (\`workspace-write\`)**: Read and edit files scoped to the active workspace; ask approval before dangerous operations, OS-level changes, or \`sudo\`.
262
+ - **Full access (\`danger-full-access\`)**: Execute ordinary in-scope workspace edits and commands directly; whole-file/directory deletion, credential safeguards, hard policy blocks, and workspace boundaries remain enforced. Avoid interactive shell flags; use non-interactive flags (\`-y\`).
253
263
  - **SSRF**: Never fetch cloud metadata (169.254.169.254, metadata.google.internal) or private LAN ranges. Loopback (\`localhost\`, \`127.0.0.1\`, \`::1\`) is permitted for local dev verification.
254
264
  - **Tool Schema Discipline**: Invoke only active Causyne or permitted peer tools using exact schema parameter names and valid JSON (no unescaped newlines or trailing commas). Respect BYOK token limits.
255
265
 
@@ -556,6 +566,9 @@ export class AgentLoop {
556
566
  this.peerMcpServers = Array.isArray(options.peerMcpServers)
557
567
  ? [...options.peerMcpServers]
558
568
  : [];
569
+ this.hostSystemInstructions = typeof options.hostSystemInstructions === 'string' && options.hostSystemInstructions.trim()
570
+ ? options.hostSystemInstructions.trim()
571
+ : null;
559
572
 
560
573
  this.config = loadConfig();
561
574
  applyProviderOverrides(this.config, this.providerOverride, this.modelOverride);
@@ -1064,13 +1077,41 @@ export class AgentLoop {
1064
1077
  }
1065
1078
  }
1066
1079
 
1080
+ activePermissionPreset(): PermissionPresetId {
1081
+ const fromOverride = normalizePermissionPreset(this.autonomyOverride);
1082
+ if (fromOverride) return fromOverride;
1083
+ return resolveConfigPermissionPreset(this.config, 'danger-full-access');
1084
+ }
1085
+
1067
1086
  setAutonomyMode(mode: string) {
1068
- const normalized = String(mode || '').trim().toUpperCase();
1069
- if (!['A', 'B', 'C'].includes(normalized)) {
1070
- throw new Error('autonomy mode must be A, B, or C');
1087
+ const preset = normalizePermissionPreset(mode);
1088
+ if (!preset) {
1089
+ throw new Error('permission preset must be read-only, workspace-write, or danger-full-access (or A, B, C)');
1071
1090
  }
1091
+ const normalized = presetToAutonomyMode(preset);
1072
1092
  this.autonomyOverride = normalized;
1073
1093
  this.config.autonomyMode = normalized;
1094
+ this.config.permissionPreset = preset;
1095
+ if (this.sandbox) {
1096
+ this.sandbox.autonomyMode = normalized;
1097
+ this.sandbox.permissionPreset = preset;
1098
+ }
1099
+ }
1100
+
1101
+ setPermissionPreset(rawPreset: string): PermissionPresetId {
1102
+ const preset = normalizePermissionPreset(rawPreset);
1103
+ if (!preset) {
1104
+ throw new Error('permission preset must be read-only, workspace-write, or danger-full-access');
1105
+ }
1106
+ const mode = presetToAutonomyMode(preset);
1107
+ this.autonomyOverride = mode;
1108
+ this.config.autonomyMode = mode;
1109
+ this.config.permissionPreset = preset;
1110
+ if (this.sandbox) {
1111
+ this.sandbox.autonomyMode = mode;
1112
+ this.sandbox.permissionPreset = preset;
1113
+ }
1114
+ return preset;
1074
1115
  }
1075
1116
 
1076
1117
  /**
@@ -1143,9 +1184,9 @@ export class AgentLoop {
1143
1184
  const prefetched = new Map();
1144
1185
  if (!Array.isArray(toolCalls) || toolCalls.length < 2) return prefetched;
1145
1186
 
1146
- // Mode A promises approval before every tool, including reads. Starting a
1187
+ // Read Only promises approval before every tool, including reads. Starting a
1147
1188
  // read here would execute it before the serial approval and hook gates.
1148
- if ((this.config.autonomyMode || 'C') === 'A') return prefetched;
1189
+ if (this.activePermissionPreset() === 'read-only') return prefetched;
1149
1190
 
1150
1191
  const eligible: any[] = [];
1151
1192
  for (const toolCall of toolCalls) {
@@ -1282,11 +1323,13 @@ export class AgentLoop {
1282
1323
  if (hook?.denied) return false;
1283
1324
  const assessment = await coldObserver.evaluateMutation(tool, args, { workspaceRoot: this.workspaceRoot });
1284
1325
  if (assessment.veto) return false;
1285
- const isModeC = (this.config.autonomyMode || 'C') === 'C';
1326
+ const activePreset = this.activePermissionPreset();
1327
+ const isFullAccess = activePreset === 'danger-full-access';
1286
1328
  const needsApproval = enterpriseDecision.effect === 'ask'
1287
- || (!isModeC && uncertain)
1329
+ || (!isFullAccess && uncertain)
1288
1330
  || requiresToolApproval({
1289
- mode: this.config.autonomyMode || 'C', tool, args,
1331
+ permissionPreset: activePreset,
1332
+ mode: presetToAutonomyMode(activePreset), tool, args,
1290
1333
  risk: assessment.requiresConfirmation ? 'dangerous' : validation.risk,
1291
1334
  heavyDownload: false, standingApproval: this.isAlwaysAllowed(tool)
1292
1335
  });
@@ -1670,7 +1713,21 @@ export class AgentLoop {
1670
1713
 
1671
1714
  updateTierLimits() {
1672
1715
  this.config = loadConfig();
1673
- if (this.autonomyOverride) this.config.autonomyMode = this.autonomyOverride;
1716
+ if (this.autonomyOverride) {
1717
+ const overridePreset = normalizePermissionPreset(this.autonomyOverride);
1718
+ if (overridePreset) {
1719
+ this.config.permissionPreset = overridePreset;
1720
+ this.config.autonomyMode = presetToAutonomyMode(overridePreset);
1721
+ } else {
1722
+ this.config.autonomyMode = this.autonomyOverride;
1723
+ }
1724
+ }
1725
+ const syncedPreset = resolveConfigPermissionPreset(this.config, 'workspace-write');
1726
+ this.config.permissionPreset = syncedPreset;
1727
+ if (this.sandbox) {
1728
+ this.sandbox.permissionPreset = syncedPreset;
1729
+ this.sandbox.autonomyMode = presetToAutonomyMode(syncedPreset);
1730
+ }
1674
1731
  applyProviderOverrides(this.config, this.providerOverride, this.modelOverride);
1675
1732
  if (this.variantOverride) {
1676
1733
  this.config.reasoningEffort = this.variantOverride;
@@ -2202,7 +2259,7 @@ export class AgentLoop {
2202
2259
  if (!this.currentTaskPrompt && this.userPrompt) {
2203
2260
  this.currentTaskPrompt = this.userPrompt;
2204
2261
  }
2205
- const isAutonomousMode = (this.config.autonomyMode || 'C') === 'C';
2262
+ const isAutonomousMode = this.activePermissionPreset() === 'danger-full-access';
2206
2263
  const recoveryPaths = new Set<string>();
2207
2264
  let modelCallIndex = 0;
2208
2265
  let softUsageNoticeIssued = false;
@@ -2374,7 +2431,8 @@ export class AgentLoop {
2374
2431
  // All transports receive the same compact catalog and selected host
2375
2432
  // schemas. Peer-native tools and native schema deferral remain provider
2376
2433
  // features; neither changes host authorization or schema selection.
2377
- const eligibleTools = await getDynamicTools(this.config.autonomyMode, this.llm.supportsVision, {
2434
+ const activePreset = this.activePermissionPreset();
2435
+ const eligibleTools = await getDynamicTools(activePreset, this.llm.supportsVision, {
2378
2436
  grantAllTools: true,
2379
2437
  allowedTools: this.sandbox.allowedTools,
2380
2438
  deniedTools: this.config.deniedTools
@@ -2410,7 +2468,8 @@ export class AgentLoop {
2410
2468
  }
2411
2469
 
2412
2470
  // Dynamically inject the absolute latest System context
2413
- const autonomyMode = this.config.autonomyMode || 'C';
2471
+ const activePresetDesc = getPermissionPresetDescriptor(activePreset);
2472
+ const permissionPolicyLine = renderPermissionPolicyContext(activePreset, this.workspaceRoot);
2414
2473
  const allowedPaths = this.sandbox.grantAllAccess
2415
2474
  ? "/ (ALL ACCESS GRANTED - You can read/write anywhere EXCEPT system protected folders like /etc or /System)"
2416
2475
  : (this.sandbox.workspacePaths ? this.sandbox.workspacePaths.join(', ') : this.workspaceRoot);
@@ -2602,13 +2661,14 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
2602
2661
  // time a different skill is invoked. This one is stable for the task,
2603
2662
  // so it anchors too.
2604
2663
  ...(skillSystemMessage(this.activeSkill) || []),
2664
+ ...(this.hostSystemInstructions ? [{ role: 'system', content: this.hostSystemInstructions }] : []),
2605
2665
  // [5] VOLATILE tail — the only bytes that may differ between steps:
2606
2666
  // autonomy/workspace paths (change via config), live shared browser
2607
2667
  // state, and persistent memory (grows via memory_write mid-task).
2608
2668
  // Kept LAST and UNcached so a change here never invalidates [1]-[3].
2609
2669
  {
2610
2670
  role: 'system',
2611
- content: `${uncertaintyDirective ? uncertaintyDirective + '\n\n' : ''}${describeSession(this.taskId)}CURRENT AUTONOMY MODE: ${autonomyMode}\nALLOWED WORKSPACE PATHS: ${allowedPaths}\n(You MUST NOT write files outside these paths!)${sharedBrowserPrompt}${memoryContext ? `\n\n◆ PERSISTENT MEMORY (workspace-relevant notes — actual repository files and docs on disk always override memory if anything conflicts):\n${memoryContext}` : ''}`
2671
+ content: `${uncertaintyDirective ? uncertaintyDirective + '\n\n' : ''}${describeSession(this.taskId)}PERMISSION PRESET: ${activePresetDesc.label} (${activePreset})\n${permissionPolicyLine}\nALLOWED WORKSPACE PATHS: ${allowedPaths}\n(You MUST NOT write files outside these paths!)${sharedBrowserPrompt}${memoryContext ? `\n\n◆ PERSISTENT MEMORY (workspace-relevant notes — actual repository files and docs on disk always override memory if anything conflicts):\n${memoryContext}` : ''}`
2612
2672
  }
2613
2673
  ];
2614
2674
 
@@ -4398,8 +4458,9 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4398
4458
  // 4-Layer Security Sandbox Validation
4399
4459
  // 2. Sandbox Security Validation (CRITICAL FIX: Prevent Infinite Loop on Block)
4400
4460
  let validation = this.sandbox.validate(functionName, args);
4461
+ const recoveryCandidatePath = args.path ?? args.file_path ?? args.target ?? args.dir;
4401
4462
  if (!validation.allowed && /^Path outside allowed workspace:/.test(validation.reason || '')
4402
- && isOutputRecoveryRead(functionName, args.path, recoveryPaths)) {
4463
+ && isOutputRecoveryRead(functionName, recoveryCandidatePath, recoveryPaths)) {
4403
4464
  validation = { allowed: true, risk: 'safe', reason: 'Read exact tool output referenced by this session' };
4404
4465
  }
4405
4466
  if (!validation.allowed) {
@@ -4607,14 +4668,16 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4607
4668
  continue;
4608
4669
  }
4609
4670
 
4610
- // A standing grant can avoid repeat prompts in supervised modes.
4611
- // Mode C is autonomous for in-scope work. Whole-file deletion asks
4671
+ // A standing grant can avoid repeat prompts in Workspace Write.
4672
+ // Full access runs in-scope work directly. Whole-file deletion asks
4612
4673
  // unless this session explicitly granted the fs_delete tool; a broad
4613
4674
  // shell grant cannot authorize deletion. Sandbox denials and observer
4614
4675
  // vetoes have already run and are never lifted by prompt policy.
4676
+ const stepPreset = this.activePermissionPreset();
4615
4677
  const standingApproval = this.isAlwaysAllowed(functionName);
4616
4678
  let needsToolApproval = requiresToolApproval({
4617
- mode: this.config.autonomyMode || 'C',
4679
+ permissionPreset: stepPreset,
4680
+ mode: presetToAutonomyMode(stepPreset),
4618
4681
  tool: functionName,
4619
4682
  args,
4620
4683
  risk: validation.risk,
@@ -4647,7 +4710,7 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4647
4710
  reason: enterpriseDecision.reason
4648
4711
  });
4649
4712
  }
4650
- if (standingApproval && !needsToolApproval && this.config.autonomyMode !== 'C' && enterpriseDecision.effect !== 'allow') {
4713
+ if (standingApproval && !needsToolApproval && stepPreset !== 'danger-full-access' && enterpriseDecision.effect !== 'allow') {
4651
4714
  auditLog.log({
4652
4715
  event: 'approval_auto_granted', taskId: this.taskId,
4653
4716
  tool: functionName, risk: validation.risk, reason: 'allow_always'
@@ -4967,7 +5030,7 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4967
5030
 
4968
5031
  // Sovereign 100-Step Circuit Breaker Checkpoint Gate
4969
5032
  if (this.consecutiveCommands === 100 && !this.circuitBreakerUnlocked) {
4970
- if (this.config.autonomyMode === 'C') {
5033
+ if (this.activePermissionPreset() === 'danger-full-access') {
4971
5034
  this.circuitBreakerUnlocked = true;
4972
5035
  this.emitEvent({ type: 'status', message: `Continuing within the configured ${this.maxSteps}-step task limit.` });
4973
5036
  } else {
@@ -4998,7 +5061,7 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
4998
5061
 
4999
5062
  // Sovereign Tier Budget Extension Checkpoint Gate
5000
5063
  if (this.stepsCompleted >= this.maxSteps && !this.stopRequested) {
5001
- if (this.config.autonomyMode === 'C') {
5064
+ if (this.activePermissionPreset() === 'danger-full-access') {
5002
5065
  this.stopRequested = true;
5003
5066
  this.emitEvent({ type: 'error', message: `Task reached the configured ${this.maxSteps}-step limit without verified completion.` });
5004
5067
  } else {
@@ -5097,11 +5160,12 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
5097
5160
  // Per tool, not one number for all of them. A build log and a
5098
5161
  // source file are not equally worth their space in the window.
5099
5162
  // Compatibility fallback preserves complete output when primary store is unavailable.
5163
+ const isRecoveryRead = functionName === 'fs_read' && isOutputRecoveryRead(functionName, args?.path ?? args?.file_path ?? args?.target, recoveryPaths);
5100
5164
  const MAX_RESULT_CHARS = resultCapFor(functionName);
5101
- const inlineLimit = Math.min(MAX_RESULT_CHARS, functionName === 'fs_read_skill' ? 16000 : functionName === 'tool_search' ? 8000 : 2500);
5165
+ const inlineLimit = Math.min(MAX_RESULT_CHARS, functionName === 'fs_read_skill' || functionName === 'fs_read' ? 16000 : functionName === 'tool_search' ? 8000 : 2500);
5102
5166
  const originalFingerprint = createHash('sha256').update(resultString).digest('hex');
5103
5167
  let spill = null;
5104
- if (resultString.length > inlineLimit) {
5168
+ if (!isRecoveryRead && resultString.length > inlineLimit) {
5105
5169
  const document = renderSpillDocument(result, { taskId: this.taskId, step: this.stepsCompleted, tool: functionName });
5106
5170
  const store = inlineLimit > 2500 ? new ToolOutputStore({ maxChars: inlineLimit, maxLines: 400, maxBytes: Math.max(50 * 1024, inlineLimit * 4) }) : defaultToolOutputStore;
5107
5171
  const stored = processToolOutputWithStore(this.taskId, toolCall.id, document, store);
@@ -5543,6 +5607,8 @@ Verify Web/UI/3D work programmatically via browser_act (DOM snapshot + runtimeEr
5543
5607
  apiKey: nextRoute.apiKey
5544
5608
  };
5545
5609
  delete this.config.baseUrl;
5610
+ delete this.config.reasoningEffort;
5611
+ delete this.config.reasoningBudgetTokens;
5546
5612
  this.llm = this.initializeProvider();
5547
5613
  this._utilityLlm = null;
5548
5614
  this.consecutiveFailures = 0;
@@ -1,13 +1,35 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { normalizePermissionPreset, presetToAutonomyMode, resolveConfigPermissionPreset } from './permissionPresets.js';
2
3
  const toolAutonomy = new AsyncLocalStorage();
3
- /** Session-scoped context for legacy tools whose execute signature has no context parameter. */
4
+ const toolPreset = new AsyncLocalStorage();
5
+ /** Session-scoped context for tools whose execute signature has no context parameter. */
6
+ export function withToolPermissionPreset(preset, run) {
7
+ const mode = presetToAutonomyMode(preset);
8
+ return toolPreset.run(preset, () => toolAutonomy.run(mode, run));
9
+ }
10
+ export function currentToolPermissionPreset() {
11
+ const direct = toolPreset.getStore();
12
+ if (direct)
13
+ return direct;
14
+ const legacy = toolAutonomy.getStore();
15
+ return legacy ? (normalizePermissionPreset(legacy) ?? undefined) : undefined;
16
+ }
17
+ /** Legacy compatibility wrapper delegating to permission presets. */
4
18
  export function withToolAutonomyMode(mode, run) {
19
+ const preset = normalizePermissionPreset(mode);
20
+ if (preset) {
21
+ return toolPreset.run(preset, () => toolAutonomy.run(mode, run));
22
+ }
5
23
  return toolAutonomy.run(mode, run);
6
24
  }
7
25
  export function currentToolAutonomyMode() {
8
- return toolAutonomy.getStore();
26
+ const direct = toolAutonomy.getStore();
27
+ if (direct !== undefined)
28
+ return direct;
29
+ const preset = toolPreset.getStore();
30
+ return preset ? presetToAutonomyMode(preset) : undefined;
9
31
  }
10
- /** Read the live session mode from the tool context; never infer it from a tool argument. */
32
+ /** Read the live session permission preset from the tool context; never infer it from a tool argument. */
11
33
  export function isAutonomousToolContext(context) {
12
34
  if (!context || typeof context !== 'object' || Array.isArray(context))
13
35
  return false;
@@ -17,10 +39,9 @@ export function isAutonomousToolContext(context) {
17
39
  const config = parentLoop.config;
18
40
  if (!config || typeof config !== 'object' || Array.isArray(config))
19
41
  return false;
20
- const mode = config.autonomyMode;
21
- return mode === 'C' || mode === undefined;
42
+ return resolveConfigPermissionPreset(config, 'danger-full-access') === 'danger-full-access';
22
43
  }
23
- const SHELL_TOOLS = new Set(['sysRun', 'sysRunBg', 'terminal_persistent_shell', 'task_bg']);
44
+ const SHELL_TOOLS = new Set(['sysRun', 'sysRunBg', 'terminal_persistent_shell', 'terminal_pty', 'task_bg']);
24
45
  const WHOLE_FILE_DELETE = /(?:^|[;&|\n(]\s*)(?:(?:sudo|doas|pkexec|command|env)\s+)*(?:rm|unlink|rmdir|shred|srm|del|erase|Remove-Item)\b|\bgit\s+rm\b/i;
25
46
  const DELETE_API_CALL = /\b(?:os\.(?:remove|unlink)|shutil\.rmtree|fs\.(?:rm|unlink)(?:Sync)?|\.unlink|\.rmdir)\s*\(/i;
26
47
  const NESTED_SHELL_DELETE = /\b(?:bash|sh|zsh|dash)\s+-c\s+['"]\s*(?:rm|unlink|rmdir|shred|srm)\b|\b(?:powershell|pwsh)\s+(?:-Command|-c)\s+['"]?\s*Remove-Item\b/i;
@@ -71,7 +92,7 @@ export function isWholeFileDeletion(tool, args) {
71
92
  || DELETE_API_CALL.test(command)
72
93
  || NESTED_SHELL_DELETE.test(command));
73
94
  }
74
- /** Routine browser verification inside the isolated agent browser (preview, snapshot, click, fill, screenshot, etc.) does not require HITL in Mode B or C unless uploading or downloading files. */
95
+ /** Routine browser verification inside the isolated agent browser (preview, snapshot, click, fill, screenshot, etc.) does not require HITL in Workspace Write or Full access unless uploading or downloading files. */
75
96
  export function isRoutineBrowserVerification(tool, args) {
76
97
  if (canonicalPolicyTool(tool) !== 'browser_act')
77
98
  return false;
@@ -110,7 +131,10 @@ export function requiresToolApproval(input) {
110
131
  if (!input || typeof input !== 'object')
111
132
  return true;
112
133
  const canonical = canonicalPolicyTool(input.tool);
113
- if (input.mode === 'C') {
134
+ const preset = normalizePermissionPreset(input.permissionPreset)
135
+ ?? normalizePermissionPreset(input.mode)
136
+ ?? 'danger-full-access';
137
+ if (preset === 'danger-full-access') {
114
138
  if (touchesCredentialMaterial(input)) {
115
139
  return true;
116
140
  }
@@ -124,11 +148,11 @@ export function requiresToolApproval(input) {
124
148
  }
125
149
  if (input.standingApproval)
126
150
  return false;
127
- if (input.mode !== 'A' && isRoutineBrowserVerification(input.tool, input.args)) {
151
+ if (preset !== 'read-only' && isRoutineBrowserVerification(input.tool, input.args)) {
128
152
  return false;
129
153
  }
130
154
  return input.risk === 'extreme'
131
155
  || input.heavyDownload
132
156
  || input.risk === 'dangerous'
133
- || input.mode === 'A';
157
+ || preset === 'read-only';
134
158
  }