@causyne/agent 1.20.124 → 1.20.128

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 (254) hide show
  1. package/bin/causyne.js +1 -1
  2. package/docs/THIRD_PARTY_NOTICES.md +36 -2
  3. package/package.json +6 -4
  4. package/src/acp/protocol.ts +19 -1
  5. package/src/acp/server.js +282 -8
  6. package/src/acp/server.ts +284 -8
  7. package/src/agent/abortableDelay.js +2 -2
  8. package/src/agent/abortableDelay.ts +2 -2
  9. package/src/agent/errorClassifier.js +9 -1
  10. package/src/agent/errorClassifier.ts +8 -1
  11. package/src/agentLoop.js +142 -53
  12. package/src/agentLoop.ts +151 -50
  13. package/src/approvalPolicy.js +34 -10
  14. package/src/approvalPolicy.ts +42 -11
  15. package/src/browser/causyneBrowser.js +61 -3
  16. package/src/browser/causyneBrowser.ts +65 -3
  17. package/src/browser/urlPolicy.js +14 -1
  18. package/src/browser/urlPolicy.ts +12 -1
  19. package/src/cliMode.js +21 -9
  20. package/src/cliMode.ts +20 -8
  21. package/src/commands.js +365 -45
  22. package/src/commands.ts +403 -45
  23. package/src/config.js +19 -4
  24. package/src/config.ts +18 -4
  25. package/src/core/contextCompactor.js +54 -7
  26. package/src/core/contextCompactor.ts +63 -7
  27. package/src/core/goalLoop.js +257 -0
  28. package/src/core/goalLoop.ts +310 -0
  29. package/src/entrypoint.js +135 -3
  30. package/src/entrypoint.ts +136 -3
  31. package/src/game/causyneCoreBridge.js +686 -0
  32. package/src/game/causyneCoreBridge.ts +702 -0
  33. package/src/game/gameLauncher.js +287 -0
  34. package/src/game/gameLauncher.ts +352 -0
  35. package/src/game/gameProvisioner.js +425 -0
  36. package/src/game/gameProvisioner.ts +488 -0
  37. package/src/headlessCli.js +19 -12
  38. package/src/headlessCli.ts +22 -8
  39. package/src/infra/atomicWriter.js +40 -4
  40. package/src/infra/atomicWriter.ts +36 -4
  41. package/src/launchIntent.js +73 -3
  42. package/src/launchIntent.ts +76 -3
  43. package/src/lsp/lspClient.js +83 -12
  44. package/src/lsp/lspClient.ts +75 -12
  45. package/src/mcp/mcpRegistry.js +75 -8
  46. package/src/mcp/mcpRegistry.ts +70 -7
  47. package/src/memory/contextBudget.js +2 -0
  48. package/src/memory/contextBudget.ts +1 -0
  49. package/src/memory/episodicStore.js +40 -0
  50. package/src/memory/episodicStore.ts +46 -0
  51. package/src/memory.js +67 -0
  52. package/src/memory.ts +65 -0
  53. package/src/modelVariants.js +45 -0
  54. package/src/modelVariants.ts +54 -0
  55. package/src/outputRecovery.js +3 -2
  56. package/src/outputRecovery.ts +4 -2
  57. package/src/permissionPresets.js +327 -0
  58. package/src/permissionPresets.ts +361 -0
  59. package/src/personalization.js +365 -0
  60. package/src/personalization.ts +471 -0
  61. package/src/projectInstructions.js +30 -10
  62. package/src/projectInstructions.ts +31 -12
  63. package/src/providers/acp.js +3 -2
  64. package/src/providers/acp.ts +3 -2
  65. package/src/providers/antigravity.js +64 -9
  66. package/src/providers/antigravity.ts +75 -9
  67. package/src/providers/byokHttp.js +7 -1
  68. package/src/providers/byokHttp.ts +6 -1
  69. package/src/providers/byokStream.js +21 -8
  70. package/src/providers/byokStream.ts +17 -7
  71. package/src/providers/dashscope-byok.js +21 -5
  72. package/src/providers/dashscope-byok.ts +29 -11
  73. package/src/providers/moonshot.js +26 -7
  74. package/src/providers/moonshot.ts +34 -13
  75. package/src/providers/muse.js +6 -0
  76. package/src/providers/muse.ts +8 -0
  77. package/src/providers/ollama.js +39 -7
  78. package/src/providers/ollama.ts +36 -7
  79. package/src/providers/openai-compatible.js +16 -3
  80. package/src/providers/openai-compatible.ts +13 -3
  81. package/src/providers/openai.js +62 -4
  82. package/src/providers/openai.ts +50 -4
  83. package/src/providers/openrouter.js +19 -4
  84. package/src/providers/openrouter.ts +21 -4
  85. package/src/providers/qwen-byok.js +21 -5
  86. package/src/providers/qwen-byok.ts +29 -11
  87. package/src/providers/xai.js +26 -10
  88. package/src/providers/xai.ts +34 -16
  89. package/src/reporting.js +4 -2
  90. package/src/reporting.ts +4 -2
  91. package/src/sandbox.js +34 -0
  92. package/src/sandbox.ts +43 -0
  93. package/src/scheduler/scheduler.js +372 -0
  94. package/src/scheduler/scheduler.ts +433 -0
  95. package/src/sessionSearchIndex.js +267 -0
  96. package/src/sessionSearchIndex.ts +311 -0
  97. package/src/skillsManager.js +2 -3
  98. package/src/skillsManager.ts +2 -3
  99. package/src/toolPacks.js +6 -0
  100. package/src/toolPacks.ts +6 -0
  101. package/src/tools/applyPatch.js +1 -1
  102. package/src/tools/applyPatch.ts +1 -1
  103. package/src/tools/generateMediaViaApi.js +4 -3
  104. package/src/tools/generateMediaViaApi.ts +4 -3
  105. package/src/tools/memoryWrite.js +15 -1
  106. package/src/tools/memoryWrite.ts +16 -1
  107. package/src/tools/nativeEngine.js +2 -2
  108. package/src/tools/nativeEngine.ts +2 -2
  109. package/src/tools/openSourceToolProvisioner.js +2 -2
  110. package/src/tools/openSourceToolProvisioner.ts +2 -2
  111. package/src/tools/osSandbox.js +1 -1
  112. package/src/tools/osSandbox.ts +1 -1
  113. package/src/tools/payloadSanitizer.js +0 -1
  114. package/src/tools/payloadSanitizer.ts +0 -1
  115. package/src/tools/pdfReader.js +122 -20
  116. package/src/tools/pdfReader.ts +111 -20
  117. package/src/tools/presentDeliverable.js +103 -0
  118. package/src/tools/presentDeliverable.ts +127 -0
  119. package/src/tools/ptcRuntime.js +444 -0
  120. package/src/tools/ptcRuntime.ts +490 -0
  121. package/src/tools/ptyTerminal.js +1108 -0
  122. package/src/tools/ptyTerminal.ts +1245 -0
  123. package/src/tools/registry.js +21 -12
  124. package/src/tools/registry.ts +21 -12
  125. package/src/tools/toolOutputStore.js +26 -4
  126. package/src/tools/toolOutputStore.ts +22 -4
  127. package/src/tools/webFetch.js +158 -11
  128. package/src/tools/webFetch.ts +145 -11
  129. package/src/tools/webSearch.js +123 -36
  130. package/src/tools/webSearch.ts +124 -33
  131. package/src/tui/banner.js +5 -1
  132. package/src/tui/banner.ts +6 -1
  133. package/src/tui/chatRenderer.js +1 -2
  134. package/src/tui/chatRenderer.ts +1 -2
  135. package/src/tui/completion.js +1 -0
  136. package/src/tui/completion.ts +1 -0
  137. package/src/tui/composerControls.js +111 -27
  138. package/src/tui/composerControls.ts +124 -28
  139. package/src/tui/dialogs.js +3 -16
  140. package/src/tui/dialogs.ts +3 -16
  141. package/src/tui/home.js +1 -0
  142. package/src/tui/home.ts +1 -0
  143. package/src/tui/invocation.js +1 -2
  144. package/src/tui/invocation.ts +1 -2
  145. package/src/tui/modelPicker.js +22 -12
  146. package/src/tui/modelPicker.ts +22 -12
  147. package/src/tui/overlay.js +2 -5
  148. package/src/tui/overlay.ts +2 -5
  149. package/src/tui/prompt.js +6 -4
  150. package/src/tui/prompt.ts +6 -4
  151. package/src/tui/selectList.js +4 -12
  152. package/src/tui/selectList.ts +4 -12
  153. package/src/tui/setup.js +22 -9
  154. package/src/tui/setup.ts +26 -9
  155. package/src/tui/statusLine.ts +2 -0
  156. package/src/web/client/browserPanel.js +905 -0
  157. package/src/web/client/browserPanel.ts +872 -0
  158. package/src/web/client/chatStream.js +321 -0
  159. package/src/web/client/chatStream.ts +297 -0
  160. package/src/web/client/cliPanel.js +165 -0
  161. package/src/web/client/cliPanel.ts +171 -0
  162. package/src/web/client/composer.js +204 -0
  163. package/src/web/client/composer.ts +209 -0
  164. package/src/web/client/diffPanel.js +176 -0
  165. package/src/web/client/diffPanel.ts +203 -0
  166. package/src/web/client/dom.js +271 -0
  167. package/src/web/client/dom.ts +272 -0
  168. package/src/web/client/filesAndCanvas.js +233 -0
  169. package/src/web/client/filesAndCanvas.ts +240 -0
  170. package/src/web/client/gameLauncherUi.js +78 -0
  171. package/src/web/client/gameLauncherUi.ts +78 -0
  172. package/src/web/client/main.js +316 -0
  173. package/src/web/client/main.ts +391 -0
  174. package/src/web/client/markdown.js +364 -0
  175. package/src/web/client/markdown.ts +373 -0
  176. package/src/web/client/modelPicker.js +455 -0
  177. package/src/web/client/modelPicker.ts +451 -0
  178. package/src/web/client/permissionPresetsUi.js +307 -0
  179. package/src/web/client/permissionPresetsUi.ts +333 -0
  180. package/src/web/client/sessions.js +353 -0
  181. package/src/web/client/sessions.ts +372 -0
  182. package/src/web/client/settingsModal.js +824 -0
  183. package/src/web/client/settingsModal.ts +959 -0
  184. package/src/web/client/state.js +280 -0
  185. package/src/web/client/state.ts +259 -0
  186. package/src/web/client/streamSmoother.js +127 -0
  187. package/src/web/client/streamSmoother.ts +119 -0
  188. package/src/web/client/studioLayout.js +89 -0
  189. package/src/web/client/studioLayout.ts +103 -0
  190. package/src/web/client/studioShell.js +660 -0
  191. package/src/web/client/studioShell.ts +672 -0
  192. package/src/web/client/studioStart.js +77 -0
  193. package/src/web/client/studioStart.ts +89 -0
  194. package/src/web/client/terminalPanel.js +606 -0
  195. package/src/web/client/terminalPanel.ts +632 -0
  196. package/src/web/client/terminalTheme.js +249 -0
  197. package/src/web/client/terminalTheme.ts +258 -0
  198. package/src/web/client/turnView.js +934 -0
  199. package/src/web/client/turnView.ts +981 -0
  200. package/src/web/client/types.js +1 -0
  201. package/src/web/client/types.ts +322 -0
  202. package/src/web/client/validators.js +147 -0
  203. package/src/web/client/validators.ts +140 -0
  204. package/src/web/server/activeRuns.js +152 -0
  205. package/src/web/server/activeRuns.ts +171 -0
  206. package/src/web/server/routesBrowser.js +409 -0
  207. package/src/web/server/routesBrowser.ts +435 -0
  208. package/src/web/server/routesChat.js +304 -0
  209. package/src/web/server/routesChat.ts +347 -0
  210. package/src/web/server/routesCore.js +472 -0
  211. package/src/web/server/routesCore.ts +522 -0
  212. package/src/web/server/routesSettings.js +344 -0
  213. package/src/web/server/routesSettings.ts +397 -0
  214. package/src/web/server/routesTerminal.js +162 -0
  215. package/src/web/server/routesTerminal.ts +182 -0
  216. package/src/web/server/routesWorkspace.js +510 -0
  217. package/src/web/server/routesWorkspace.ts +546 -0
  218. package/src/web/server/security.js +98 -0
  219. package/src/web/server/security.ts +108 -0
  220. package/src/web/server/sessionTranscript.js +586 -0
  221. package/src/web/server/sessionTranscript.ts +566 -0
  222. package/src/web/server/staticAssets.js +104 -0
  223. package/src/web/server/staticAssets.ts +116 -0
  224. package/src/web/server/types.js +1 -0
  225. package/src/web/server/types.ts +135 -0
  226. package/src/web/server/workspaceFiles.js +368 -0
  227. package/src/web/server/workspaceFiles.ts +363 -0
  228. package/src/web/skybridgeServer.js +78 -2448
  229. package/src/web/skybridgeServer.ts +120 -2600
  230. package/src/web/skybridgeUi.js +20 -450
  231. package/src/web/skybridgeUi.ts +24 -455
  232. package/src/web/styles/agent.css +380 -0
  233. package/src/web/styles/composer.css +193 -0
  234. package/src/web/styles/overlays.css +935 -0
  235. package/src/web/styles/shell.css +387 -0
  236. package/src/web/styles/studio.css +951 -0
  237. package/src/web/styles/thread.css +221 -0
  238. package/src/web/styles/tokens.css +94 -0
  239. package/src/web/ui/brandMark.js +73 -0
  240. package/src/web/ui/brandMark.ts +82 -0
  241. package/src/web/ui/modalsTemplate.js +388 -0
  242. package/src/web/ui/modalsTemplate.ts +388 -0
  243. package/src/web/ui/sidebarTemplate.js +63 -0
  244. package/src/web/ui/sidebarTemplate.ts +64 -0
  245. package/src/web/ui/studioTemplate.js +256 -0
  246. package/src/web/ui/studioTemplate.ts +256 -0
  247. package/src/web/ui/workspaceTemplate.js +72 -0
  248. package/src/web/ui/workspaceTemplate.ts +73 -0
  249. package/src/worktreeManager.js +16 -1
  250. package/src/worktreeManager.ts +22 -1
  251. package/src/web/skybridgeClientScript.js +0 -3951
  252. package/src/web/skybridgeClientScript.ts +0 -3952
  253. package/src/web/skybridgeStyles.js +0 -827
  254. package/src/web/skybridgeStyles.ts +0 -828
@@ -4,6 +4,7 @@ import { LLMProvider, type ChatOptions, type ChatResponse, type ProviderConfig }
4
4
  import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
5
  import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
6
  import {
7
+ ProviderHttpError,
7
8
  requireApiKey,
8
9
  resolveTemperature,
9
10
  safeProviderFetchJson
@@ -115,17 +116,34 @@ export class QwenByokProvider extends LLMProvider {
115
116
  }
116
117
  };
117
118
 
118
- const data = wantsStreaming(options)
119
- ? await streamOpenAICompatibleChat({
120
- ...requestOpts,
121
- payload,
122
- onChunk: options.onChunk,
123
- onReasoningChunk: options.onReasoningChunk
124
- })
125
- : await safeProviderFetchJson({
126
- ...requestOpts,
127
- body: JSON.stringify(payload)
128
- });
119
+ const runQwenRequest = async (reqPayload: Record<string, any>) => (
120
+ wantsStreaming(options)
121
+ ? await streamOpenAICompatibleChat({
122
+ ...requestOpts,
123
+ payload: reqPayload,
124
+ onChunk: options.onChunk,
125
+ onReasoningChunk: options.onReasoningChunk
126
+ })
127
+ : await safeProviderFetchJson({
128
+ ...requestOpts,
129
+ body: JSON.stringify(reqPayload)
130
+ })
131
+ );
132
+
133
+ let data: Record<string, any>;
134
+ try {
135
+ data = await runQwenRequest(payload);
136
+ } catch (err: unknown) {
137
+ const rejectedThinking = ('enable_thinking' in payload || 'thinking_budget' in payload)
138
+ && err instanceof ProviderHttpError
139
+ && err.status === 400
140
+ && /(?:enable_thinking|thinking_budget|thinking|unsupported|not supported|invalid|unknown)/i.test(err.message);
141
+ if (!rejectedThinking) throw err;
142
+ const fallbackPayload = { ...payload };
143
+ delete fallbackPayload['enable_thinking'];
144
+ delete fallbackPayload['thinking_budget'];
145
+ data = await runQwenRequest(fallbackPayload);
146
+ }
129
147
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
130
148
  prefix: 'call_qwen',
131
149
  freeFormPaths
@@ -3,7 +3,7 @@ import { DEFAULT_MODEL_BY_PROVIDER } from '../modelCatalogue.js';
3
3
  import { LLMProvider } from './base.js';
4
4
  import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
5
  import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
- import { requireApiKey, resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
6
+ import { ProviderHttpError, requireApiKey, resolveTemperature, safeProviderFetchJson } from './byokHttp.js';
7
7
  import { streamOpenAICompatibleChat, wantsStreaming } from './byokStream.js';
8
8
  export class XAIProvider extends LLMProvider {
9
9
  allowInsecureHttp;
@@ -14,8 +14,9 @@ export class XAIProvider extends LLMProvider {
14
14
  this.baseUrl = customUrl || 'https://api.x.ai/v1/chat/completions';
15
15
  this.allowInsecureHttp = config.allowInsecureHttp === true;
16
16
  const rawEffort = typeof config.reasoningEffort === 'string' ? config.reasoningEffort.trim().toLowerCase() : '';
17
+ const clampedEffort = (rawEffort === 'max' || rawEffort === 'ultra') ? 'high' : (rawEffort === 'minimal' ? 'low' : rawEffort);
17
18
  const allowedEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
18
- this.reasoningEffort = allowedEfforts.has(rawEffort) ? rawEffort : null;
19
+ this.reasoningEffort = allowedEfforts.has(clampedEffort) ? clampedEffort : null;
19
20
  this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['xai']) || '');
20
21
  this.visionModels = ['grok-4', 'vision'];
21
22
  this.audioModels = [];
@@ -29,12 +30,12 @@ export class XAIProvider extends LLMProvider {
29
30
  temperature: resolveTemperature(options.temperature, 0.1)
30
31
  };
31
32
  const loweredModel = (this.model || '').toLowerCase();
32
- if (this.reasoningEffort) {
33
- if (loweredModel.includes('grok-420-reasoning')) {
33
+ if (this.reasoningEffort && !loweredModel.includes('non-reasoning')) {
34
+ if (loweredModel.includes('grok-420-reasoning') || (loweredModel.includes('grok-4') && loweredModel.includes('reasoning'))) {
34
35
  payload['reasoning_effort'] = this.reasoningEffort;
35
36
  }
36
- else if (loweredModel.includes('grok-3-mini') && (this.reasoningEffort === 'low' || this.reasoningEffort === 'high')) {
37
- payload['reasoning_effort'] = this.reasoningEffort;
37
+ else if (loweredModel.includes('grok-3-mini')) {
38
+ payload['reasoning_effort'] = this.reasoningEffort === 'low' ? 'low' : 'high';
38
39
  }
39
40
  }
40
41
  if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
@@ -65,17 +66,32 @@ export class XAIProvider extends LLMProvider {
65
66
  hasApiKey: true,
66
67
  allowInsecureHttp: this.allowInsecureHttp
67
68
  };
68
- const data = wantsStreaming(options)
69
+ const runXaiRequest = async (reqPayload) => (wantsStreaming(options)
69
70
  ? await streamOpenAICompatibleChat({
70
71
  ...requestOpts,
71
- payload,
72
+ payload: reqPayload,
72
73
  onChunk: options.onChunk,
73
74
  onReasoningChunk: options.onReasoningChunk
74
75
  })
75
76
  : await safeProviderFetchJson({
76
77
  ...requestOpts,
77
- body: JSON.stringify(payload)
78
- });
78
+ body: JSON.stringify(reqPayload)
79
+ }));
80
+ let data;
81
+ try {
82
+ data = await runXaiRequest(payload);
83
+ }
84
+ catch (err) {
85
+ const rejectedEffort = 'reasoning_effort' in payload
86
+ && err instanceof ProviderHttpError
87
+ && err.status === 400
88
+ && /(?:reasoning_effort|effort|unsupported|not supported|invalid|unknown)/i.test(err.message);
89
+ if (!rejectedEffort)
90
+ throw err;
91
+ const fallbackPayload = { ...payload };
92
+ delete fallbackPayload['reasoning_effort'];
93
+ data = await runXaiRequest(fallbackPayload);
94
+ }
79
95
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
80
96
  prefix: 'call_xai',
81
97
  freeFormPaths
@@ -4,6 +4,7 @@ import { LLMProvider, type ChatOptions, type ChatResponse, type ProviderConfig }
4
4
  import { scanAndAdaptToolsForProvider } from '../tools/toolScanner.js';
5
5
  import { normalizeOpenAIChatChoiceResponse } from './wireNormalizer.js';
6
6
  import {
7
+ ProviderHttpError,
7
8
  requireApiKey,
8
9
  resolveTemperature,
9
10
  safeProviderFetchJson
@@ -20,8 +21,9 @@ export class XAIProvider extends LLMProvider {
20
21
  this.baseUrl = customUrl || 'https://api.x.ai/v1/chat/completions';
21
22
  this.allowInsecureHttp = config.allowInsecureHttp === true;
22
23
  const rawEffort = typeof config.reasoningEffort === 'string' ? config.reasoningEffort.trim().toLowerCase() : '';
24
+ const clampedEffort = (rawEffort === 'max' || rawEffort === 'ultra') ? 'high' : (rawEffort === 'minimal' ? 'low' : rawEffort);
23
25
  const allowedEfforts = new Set(['low', 'medium', 'high', 'xhigh']);
24
- this.reasoningEffort = allowedEfforts.has(rawEffort) ? rawEffort : null;
26
+ this.reasoningEffort = allowedEfforts.has(clampedEffort) ? clampedEffort : null;
25
27
  this.model = String(canonicalModelId(config.model || DEFAULT_MODEL_BY_PROVIDER['xai']) || '');
26
28
  this.visionModels = ['grok-4', 'vision'];
27
29
  this.audioModels = [];
@@ -38,11 +40,11 @@ export class XAIProvider extends LLMProvider {
38
40
  };
39
41
 
40
42
  const loweredModel = (this.model || '').toLowerCase();
41
- if (this.reasoningEffort) {
42
- if (loweredModel.includes('grok-420-reasoning')) {
43
- payload['reasoning_effort'] = this.reasoningEffort;
44
- } else if (loweredModel.includes('grok-3-mini') && (this.reasoningEffort === 'low' || this.reasoningEffort === 'high')) {
43
+ if (this.reasoningEffort && !loweredModel.includes('non-reasoning')) {
44
+ if (loweredModel.includes('grok-420-reasoning') || (loweredModel.includes('grok-4') && loweredModel.includes('reasoning'))) {
45
45
  payload['reasoning_effort'] = this.reasoningEffort;
46
+ } else if (loweredModel.includes('grok-3-mini')) {
47
+ payload['reasoning_effort'] = this.reasoningEffort === 'low' ? 'low' : 'high';
46
48
  }
47
49
  }
48
50
  if (typeof options.maxTokens === 'number' && Number.isFinite(options.maxTokens) && options.maxTokens >= 1) {
@@ -77,17 +79,33 @@ export class XAIProvider extends LLMProvider {
77
79
  allowInsecureHttp: this.allowInsecureHttp
78
80
  };
79
81
 
80
- const data = wantsStreaming(options)
81
- ? await streamOpenAICompatibleChat({
82
- ...requestOpts,
83
- payload,
84
- onChunk: options.onChunk,
85
- onReasoningChunk: options.onReasoningChunk
86
- })
87
- : await safeProviderFetchJson({
88
- ...requestOpts,
89
- body: JSON.stringify(payload)
90
- });
82
+ const runXaiRequest = async (reqPayload: Record<string, any>) => (
83
+ wantsStreaming(options)
84
+ ? await streamOpenAICompatibleChat({
85
+ ...requestOpts,
86
+ payload: reqPayload,
87
+ onChunk: options.onChunk,
88
+ onReasoningChunk: options.onReasoningChunk
89
+ })
90
+ : await safeProviderFetchJson({
91
+ ...requestOpts,
92
+ body: JSON.stringify(reqPayload)
93
+ })
94
+ );
95
+
96
+ let data: Record<string, any>;
97
+ try {
98
+ data = await runXaiRequest(payload);
99
+ } catch (err: unknown) {
100
+ const rejectedEffort = 'reasoning_effort' in payload
101
+ && err instanceof ProviderHttpError
102
+ && err.status === 400
103
+ && /(?:reasoning_effort|effort|unsupported|not supported|invalid|unknown)/i.test(err.message);
104
+ if (!rejectedEffort) throw err;
105
+ const fallbackPayload = { ...payload };
106
+ delete fallbackPayload['reasoning_effort'];
107
+ data = await runXaiRequest(fallbackPayload);
108
+ }
91
109
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
92
110
  prefix: 'call_xai',
93
111
  freeFormPaths
package/src/reporting.js CHANGED
@@ -12,6 +12,7 @@ import { terminalWidth, readableWidth } from './tui/theme.js';
12
12
  import { isAcpProvider } from './providers/acp.js';
13
13
  import { isAntigravityProvider } from './providers/antigravity.js';
14
14
  import { LICENSE_ENFORCEMENT_ENABLED } from './licensing/policy.js';
15
+ import { getPermissionPresetDescriptor, resolveConfigPermissionPreset } from './permissionPresets.js';
15
16
  function resolveDisplayTier(liveConfig, savedConfig) {
16
17
  const configured = liveConfig?.tier ?? savedConfig?.tier;
17
18
  if (typeof configured === 'string' && configured.trim())
@@ -358,7 +359,8 @@ export function buildStatusText(options) {
358
359
  const liveConfig = loop?.config || {};
359
360
  const provider = String(liveConfig.provider || config.provider || 'default');
360
361
  const model = String(liveConfig.model || config.model || 'default');
361
- const autonomyMode = String(liveConfig.autonomyMode || config.autonomyMode || 'C');
362
+ const presetId = resolveConfigPermissionPreset(liveConfig, resolveConfigPermissionPreset(config, 'workspace-write'));
363
+ const presetDesc = getPermissionPresetDescriptor(presetId);
362
364
  const tier = resolveDisplayTier(liveConfig, config);
363
365
  const lines = ['Status'];
364
366
  lines.push(' Runtime : local desktop');
@@ -366,7 +368,7 @@ export function buildStatusText(options) {
366
368
  lines.push(` Session : ${safeDisplay(loop.memoryManager.sessionId)}`);
367
369
  }
368
370
  lines.push(` Provider / model : ${safeDisplay(provider)} / ${safeDisplay(model)}`);
369
- lines.push(` Autonomy mode : ${safeDisplay(autonomyMode)}`);
371
+ lines.push(` Permission : ${safeDisplay(presetDesc.label)} (${safeDisplay(presetDesc.id)})`);
370
372
  lines.push(` Tier : ${safeDisplay(tier)}`);
371
373
  if (loop && loop.sandbox) {
372
374
  const sandbox = loop.sandbox;
package/src/reporting.ts CHANGED
@@ -13,6 +13,7 @@ import { terminalWidth, readableWidth } from './tui/theme.js';
13
13
  import { isAcpProvider } from './providers/acp.js';
14
14
  import { isAntigravityProvider } from './providers/antigravity.js';
15
15
  import { LICENSE_ENFORCEMENT_ENABLED } from './licensing/policy.js';
16
+ import { getPermissionPresetDescriptor, resolveConfigPermissionPreset } from './permissionPresets.js';
16
17
 
17
18
  function resolveDisplayTier(liveConfig?: Record<string, unknown> | null, savedConfig?: Record<string, unknown> | null): string {
18
19
  const configured = liveConfig?.tier ?? savedConfig?.tier;
@@ -425,7 +426,8 @@ export function buildStatusText(options?: { loop?: any } | null): string {
425
426
  const liveConfig = loop?.config || {};
426
427
  const provider = String(liveConfig.provider || config.provider || 'default');
427
428
  const model = String(liveConfig.model || config.model || 'default');
428
- const autonomyMode = String(liveConfig.autonomyMode || config.autonomyMode || 'C');
429
+ const presetId = resolveConfigPermissionPreset(liveConfig, resolveConfigPermissionPreset(config, 'workspace-write'));
430
+ const presetDesc = getPermissionPresetDescriptor(presetId);
429
431
  const tier = resolveDisplayTier(liveConfig, config);
430
432
  const lines = ['Status'];
431
433
 
@@ -435,7 +437,7 @@ export function buildStatusText(options?: { loop?: any } | null): string {
435
437
  lines.push(` Session : ${safeDisplay(loop.memoryManager.sessionId)}`);
436
438
  }
437
439
  lines.push(` Provider / model : ${safeDisplay(provider)} / ${safeDisplay(model)}`);
438
- lines.push(` Autonomy mode : ${safeDisplay(autonomyMode)}`);
440
+ lines.push(` Permission : ${safeDisplay(presetDesc.label)} (${safeDisplay(presetDesc.id)})`);
439
441
  lines.push(` Tier : ${safeDisplay(tier)}`);
440
442
 
441
443
  if (loop && loop.sandbox) {
package/src/sandbox.js CHANGED
@@ -9,6 +9,7 @@ import { extractPatchTargetPaths } from './tools/applyPatch.js';
9
9
  import { getMcpToolAnnotations } from './mcp/mcpRegistry.js';
10
10
  import { isPhysicalPathAllowed, physicalPath } from './agent/workspaceBoundary.js';
11
11
  import { isBlockedWorkspaceRoot, isExtendedCredentialPath, isSensitiveWriteTarget, analyzeShellCommand, isExtremeRemovalSegment, isFetchAndExecPipeline } from './sandboxPolicy.js';
12
+ import { autonomyModeToPreset, normalizePermissionPreset, readOnlyPresetViolation } from './permissionPresets.js';
12
13
  const READ_ONLY_INVOCATIONS = {
13
14
  brew: /^brew\s+(--version|-v|list|info|search|config|outdated|deps|home|--prefix|--cellar)\b/,
14
15
  apt: /^apt\s+(--version|list|show|search|policy)\b/,
@@ -132,7 +133,14 @@ export class Sandbox {
132
133
  this.allowedTools = rawAllowed.map((name) => String(name).replace(/\./g, '_'));
133
134
  this.deniedTools = new Set((devMode ? [] : (this.config.deniedTools || []))
134
135
  .map((name) => String(name).replace(/\./g, '_')));
136
+ this.permissionPreset = normalizePermissionPreset(safeOptions.permissionPreset)
137
+ ?? (typeof safeOptions.autonomyMode === 'string' && safeOptions.autonomyMode.trim()
138
+ ? autonomyModeToPreset(safeOptions.autonomyMode)
139
+ : null)
140
+ ?? normalizePermissionPreset(this.config.permissionPreset)
141
+ ?? autonomyModeToPreset(this.config.autonomyMode);
135
142
  }
143
+ permissionPreset;
136
144
  updateWorkspacePaths(newPaths) {
137
145
  if (Array.isArray(newPaths) && newPaths.length > 0) {
138
146
  const seen = new Set();
@@ -172,6 +180,12 @@ export class Sandbox {
172
180
  return { allowed: false, reason: `Tool ${toolName} not allowed on current tier`, risk: 'forbidden' };
173
181
  }
174
182
  const safeArgs = args && typeof args === 'object' ? args : {};
183
+ if (this.permissionPreset === 'read-only') {
184
+ const readOnlyErr = readOnlyPresetViolation(canonicalToolName, safeArgs);
185
+ if (readOnlyErr) {
186
+ return { allowed: false, reason: readOnlyErr, risk: 'dangerous' };
187
+ }
188
+ }
175
189
  const pathsToCheck = [];
176
190
  if (canonicalToolName !== 'fs_read_skill') {
177
191
  const PATH_ARGUMENTS = [
@@ -255,6 +269,26 @@ export class Sandbox {
255
269
  }
256
270
  return withCredentialEscalation({ allowed: true, risk: 'safe' });
257
271
  }
272
+ if (canonicalToolName === 'present' || canonicalToolName === 'session_search' || canonicalToolName === 'run_code') {
273
+ return withCredentialEscalation({ allowed: true, risk: 'safe' });
274
+ }
275
+ if (canonicalToolName === 'goal' || canonicalToolName === 'schedule') {
276
+ return withCredentialEscalation({ allowed: true, risk: 'moderate' });
277
+ }
278
+ if (canonicalToolName === 'terminal_pty') {
279
+ const action = String(safeArgs.action || '').trim();
280
+ if (action === 'list' || action === 'read' || action === 'resize') {
281
+ return withCredentialEscalation({ allowed: true, risk: 'safe' });
282
+ }
283
+ if (action === 'send' && typeof safeArgs.input === 'string' && safeArgs.input.trim()) {
284
+ const risk = this.classifyCommandRisk(safeArgs.input);
285
+ if (risk === 'forbidden') {
286
+ return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
287
+ }
288
+ return withCredentialEscalation({ allowed: true, risk });
289
+ }
290
+ return withCredentialEscalation({ allowed: true, risk: 'moderate' });
291
+ }
258
292
  if (canonicalToolName === 'sysRun' || canonicalToolName === 'sysRunBg' || canonicalToolName === 'terminal_persistent_shell') {
259
293
  const command = safeArgs.command || safeArgs.input || safeArgs.cmd;
260
294
  if (command) {
package/src/sandbox.ts CHANGED
@@ -16,6 +16,12 @@ import {
16
16
  isExtremeRemovalSegment,
17
17
  isFetchAndExecPipeline
18
18
  } from './sandboxPolicy.js';
19
+ import {
20
+ autonomyModeToPreset,
21
+ normalizePermissionPreset,
22
+ readOnlyPresetViolation,
23
+ type PermissionPresetId
24
+ } from './permissionPresets.js';
19
25
 
20
26
  export type RiskLevel = 'safe' | 'moderate' | 'dangerous' | 'extreme' | 'forbidden';
21
27
 
@@ -158,8 +164,16 @@ export class Sandbox {
158
164
  (devMode ? [] : (this.config.deniedTools || []))
159
165
  .map((name: unknown) => String(name).replace(/\./g, '_'))
160
166
  );
167
+ this.permissionPreset = normalizePermissionPreset(safeOptions.permissionPreset)
168
+ ?? (typeof safeOptions.autonomyMode === 'string' && safeOptions.autonomyMode.trim()
169
+ ? autonomyModeToPreset(safeOptions.autonomyMode)
170
+ : null)
171
+ ?? normalizePermissionPreset((this.config as { permissionPreset?: unknown }).permissionPreset)
172
+ ?? autonomyModeToPreset(this.config.autonomyMode);
161
173
  }
162
174
 
175
+ permissionPreset: PermissionPresetId;
176
+
163
177
  updateWorkspacePaths(newPaths: unknown): { success: boolean; paths?: string[]; reason?: string } {
164
178
  if (Array.isArray(newPaths) && newPaths.length > 0) {
165
179
  const seen = new Set<string>();
@@ -202,6 +216,12 @@ export class Sandbox {
202
216
  }
203
217
 
204
218
  const safeArgs: Record<string, any> = args && typeof args === 'object' ? args : {};
219
+ if (this.permissionPreset === 'read-only') {
220
+ const readOnlyErr = readOnlyPresetViolation(canonicalToolName, safeArgs);
221
+ if (readOnlyErr) {
222
+ return { allowed: false, reason: readOnlyErr, risk: 'dangerous' };
223
+ }
224
+ }
205
225
  const pathsToCheck: unknown[] = [];
206
226
  if (canonicalToolName !== 'fs_read_skill') {
207
227
  const PATH_ARGUMENTS = [
@@ -285,6 +305,29 @@ export class Sandbox {
285
305
  return withCredentialEscalation({ allowed: true, risk: 'safe' });
286
306
  }
287
307
 
308
+ if (canonicalToolName === 'present' || canonicalToolName === 'session_search' || canonicalToolName === 'run_code') {
309
+ return withCredentialEscalation({ allowed: true, risk: 'safe' });
310
+ }
311
+
312
+ if (canonicalToolName === 'goal' || canonicalToolName === 'schedule') {
313
+ return withCredentialEscalation({ allowed: true, risk: 'moderate' });
314
+ }
315
+
316
+ if (canonicalToolName === 'terminal_pty') {
317
+ const action = String(safeArgs.action || '').trim();
318
+ if (action === 'list' || action === 'read' || action === 'resize') {
319
+ return withCredentialEscalation({ allowed: true, risk: 'safe' });
320
+ }
321
+ if (action === 'send' && typeof safeArgs.input === 'string' && safeArgs.input.trim()) {
322
+ const risk = this.classifyCommandRisk(safeArgs.input);
323
+ if (risk === 'forbidden') {
324
+ return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
325
+ }
326
+ return withCredentialEscalation({ allowed: true, risk });
327
+ }
328
+ return withCredentialEscalation({ allowed: true, risk: 'moderate' });
329
+ }
330
+
288
331
  if (canonicalToolName === 'sysRun' || canonicalToolName === 'sysRunBg' || canonicalToolName === 'terminal_persistent_shell') {
289
332
  const command = safeArgs.command || safeArgs.input || safeArgs.cmd;
290
333
  if (command) {