@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
@@ -247,6 +247,50 @@ export function resolveAgyEffort(model) {
247
247
  return 'max';
248
248
  return 'low';
249
249
  }
250
+ const VALID_AGY_EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
251
+ function findRegisteredAgySlug(candidateLower) {
252
+ for (const slug of Object.values(ANTIGRAVITY_MODEL_IDS)) {
253
+ if (slug.toLowerCase() === candidateLower)
254
+ return slug;
255
+ }
256
+ return null;
257
+ }
258
+ /**
259
+ * Resolve the exact `--model` slug and optional `--effort` flag for `agy` CLI
260
+ * without ever emitting a conflicting pair (e.g. `--model gemini-4-neon-xhigh --effort max`)
261
+ * or passing `--effort` to unsuffixed orchestrator models that reject it.
262
+ */
263
+ export function resolveAgyCliModelAndEffort(model, rawReasoningEffort) {
264
+ const baseSlug = resolveAgyModelId(model);
265
+ if (!baseSlug)
266
+ return { modelSlug: '', effort: null };
267
+ const cleanedEffort = typeof rawReasoningEffort === 'string'
268
+ ? rawReasoningEffort.trim().toLowerCase()
269
+ : '';
270
+ const requestedEffort = VALID_AGY_EFFORTS.has(cleanedEffort) ? cleanedEffort : null;
271
+ const suffixMatch = /^(.+?)-(minimal|low|medium|high|xhigh|max)$/i.exec(baseSlug);
272
+ if (suffixMatch && suffixMatch[1] && suffixMatch[2]) {
273
+ const baseFamily = suffixMatch[1];
274
+ const slugEffort = suffixMatch[2].toLowerCase();
275
+ if (requestedEffort && requestedEffort !== slugEffort) {
276
+ const sibling = findRegisteredAgySlug(`${baseFamily.toLowerCase()}-${requestedEffort}`);
277
+ if (sibling) {
278
+ return { modelSlug: sibling, effort: null };
279
+ }
280
+ }
281
+ // Suffixed slugs already carry the exact effort tier; omitting `--effort`
282
+ // avoids redundant/conflicting flag rejection on every `agy` version.
283
+ return { modelSlug: baseSlug, effort: null };
284
+ }
285
+ if (requestedEffort) {
286
+ const sibling = findRegisteredAgySlug(`${baseSlug.toLowerCase()}-${requestedEffort}`);
287
+ if (sibling) {
288
+ return { modelSlug: sibling, effort: null };
289
+ }
290
+ }
291
+ // Unsuffixed models (such as orchestrators) reject `--effort`.
292
+ return { modelSlug: baseSlug, effort: null };
293
+ }
250
294
  export function isAntigravityProvider(provider) {
251
295
  if (!provider)
252
296
  return false;
@@ -1048,11 +1092,8 @@ export class AntigravityProvider extends LLMProvider {
1048
1092
  'Use <tool_call>{"name": "browser_act", "arguments": {"actions": [{"type": "preview", "filePath": "index.html"}, {"type": "snapshot"}]}}</tool_call> to verify rendered output directly. ' +
1049
1093
  'If you start a persistent local HTTP server, use `sysRunBg` or redirect stdio (`nohup ... </dev/null >/dev/null 2>&1 &`) so the server does not break with EIO when the turn pseudo-terminal closes.\n\n' + promptText;
1050
1094
  }
1051
- const modelSlug = resolveAgyModelId(this.model);
1052
- const explicitEffort = this.reasoningEffort && ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra'].includes(this.reasoningEffort)
1053
- ? this.reasoningEffort
1054
- : null;
1055
- const effort = explicitEffort || resolveAgyEffort(this.model);
1095
+ const { modelSlug, effort } = resolveAgyCliModelAndEffort(this.model, this.reasoningEffort);
1096
+ const workerEffortKey = effort || resolveAgyEffort(modelSlug);
1056
1097
  // Run the user's normal peer in the selected project. Do not substitute a
1057
1098
  // managed inference profile or hide project MCPs, skills, and instructions.
1058
1099
  const workspaceRoot = path.resolve(options.workspaceRoot || process.cwd());
@@ -1067,7 +1108,7 @@ export class AntigravityProvider extends LLMProvider {
1067
1108
  '--model',
1068
1109
  modelSlug
1069
1110
  ];
1070
- if (effort && (Boolean(explicitEffort) || modelSlug.endsWith(`-${effort}`) || /-(low|medium|high|xhigh|max|ultra)$/i.test(modelSlug))) {
1111
+ if (effort) {
1071
1112
  args.push('--effort', effort);
1072
1113
  }
1073
1114
  if (useConversation && this.currentConversationId) {
@@ -1080,7 +1121,7 @@ export class AntigravityProvider extends LLMProvider {
1080
1121
  const reuseExistingWorker = Boolean(existingWorker
1081
1122
  && existingWorker.workspaceRoot === workspaceRoot
1082
1123
  && existingWorker.modelSlug === modelSlug
1083
- && existingWorker.effort === effort
1124
+ && existingWorker.effort === workerEffortKey
1084
1125
  && existingWorker.child.exitCode === null
1085
1126
  && existingWorker.child.signalCode === null
1086
1127
  && !existingWorker.child.killed
@@ -1105,7 +1146,7 @@ export class AntigravityProvider extends LLMProvider {
1105
1146
  windowsHide: true
1106
1147
  });
1107
1148
  if (canUsePersistent) {
1108
- this.persistentWorker = { child, workspaceRoot, modelSlug, effort };
1149
+ this.persistentWorker = { child, workspaceRoot, modelSlug, effort: workerEffortKey };
1109
1150
  }
1110
1151
  }
1111
1152
  this.activeChild = child;
@@ -1663,7 +1704,9 @@ export class AntigravityProvider extends LLMProvider {
1663
1704
  this.currentConversationId = null;
1664
1705
  const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
1665
1706
  `terminal status ${finalResultObj?.status || 'unknown'}, exit code ${code}`;
1666
- safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
1707
+ const isInvalidSelection = /invalid model selection|conflicts with --effort|--effort is not supported/i.test(errDetail);
1708
+ const failure = Object.assign(new Error(`Antigravity Agent (agy) failed: ${errDetail}`), isInvalidSelection ? { code: 'AGY_INVALID_MODEL_SELECTION', status: 400 } : {});
1709
+ safeReject(failure);
1667
1710
  return;
1668
1711
  }
1669
1712
  let rawContent = (finalResultObj?.response || streamedResponse || '').trim();
@@ -1877,12 +1920,22 @@ export class AntigravityProvider extends LLMProvider {
1877
1920
  async chat(messages, options = {}) {
1878
1921
  const maxRetries = options.maxRetries ?? (options.taskIntent === 'launch' ? 1 : 2);
1879
1922
  let attempt = 0;
1923
+ let clearedEffortFallback = false;
1880
1924
  while (attempt <= maxRetries) {
1881
1925
  const hadConversation = Boolean(this.currentConversationId);
1882
1926
  try {
1883
1927
  return await this._executeOnce(messages, options);
1884
1928
  }
1885
1929
  catch (err) {
1930
+ if (err?.code === 'AGY_INVALID_MODEL_SELECTION') {
1931
+ if (!clearedEffortFallback && this.reasoningEffort) {
1932
+ clearedEffortFallback = true;
1933
+ this.reasoningEffort = null;
1934
+ this.currentConversationId = null;
1935
+ continue;
1936
+ }
1937
+ throw err;
1938
+ }
1886
1939
  if (!shouldRetryPeerError(err, options.signal?.aborted === true || err?.name === 'AbortError')
1887
1940
  || err?.code === 'AGY_NATIVE_ACTION_DENIED' || err?.code === 'PROVIDER_NO_PROGRESS') {
1888
1941
  throw err;
@@ -248,6 +248,58 @@ export function resolveAgyEffort(model?: string | null): string {
248
248
  return 'low';
249
249
  }
250
250
 
251
+ const VALID_AGY_EFFORTS = new Set(['low', 'medium', 'high', 'xhigh', 'max']);
252
+
253
+ function findRegisteredAgySlug(candidateLower: string): string | null {
254
+ for (const slug of Object.values(ANTIGRAVITY_MODEL_IDS)) {
255
+ if (slug.toLowerCase() === candidateLower) return slug;
256
+ }
257
+ return null;
258
+ }
259
+
260
+ /**
261
+ * Resolve the exact `--model` slug and optional `--effort` flag for `agy` CLI
262
+ * without ever emitting a conflicting pair (e.g. `--model gemini-4-neon-xhigh --effort max`)
263
+ * or passing `--effort` to unsuffixed orchestrator models that reject it.
264
+ */
265
+ export function resolveAgyCliModelAndEffort(
266
+ model?: string | null,
267
+ rawReasoningEffort?: string | null
268
+ ): { modelSlug: string; effort: string | null } {
269
+ const baseSlug = resolveAgyModelId(model);
270
+ if (!baseSlug) return { modelSlug: '', effort: null };
271
+
272
+ const cleanedEffort = typeof rawReasoningEffort === 'string'
273
+ ? rawReasoningEffort.trim().toLowerCase()
274
+ : '';
275
+ const requestedEffort = VALID_AGY_EFFORTS.has(cleanedEffort) ? cleanedEffort : null;
276
+
277
+ const suffixMatch = /^(.+?)-(minimal|low|medium|high|xhigh|max)$/i.exec(baseSlug);
278
+ if (suffixMatch && suffixMatch[1] && suffixMatch[2]) {
279
+ const baseFamily = suffixMatch[1];
280
+ const slugEffort = suffixMatch[2].toLowerCase();
281
+ if (requestedEffort && requestedEffort !== slugEffort) {
282
+ const sibling = findRegisteredAgySlug(`${baseFamily.toLowerCase()}-${requestedEffort}`);
283
+ if (sibling) {
284
+ return { modelSlug: sibling, effort: null };
285
+ }
286
+ }
287
+ // Suffixed slugs already carry the exact effort tier; omitting `--effort`
288
+ // avoids redundant/conflicting flag rejection on every `agy` version.
289
+ return { modelSlug: baseSlug, effort: null };
290
+ }
291
+
292
+ if (requestedEffort) {
293
+ const sibling = findRegisteredAgySlug(`${baseSlug.toLowerCase()}-${requestedEffort}`);
294
+ if (sibling) {
295
+ return { modelSlug: sibling, effort: null };
296
+ }
297
+ }
298
+
299
+ // Unsuffixed models (such as orchestrators) reject `--effort`.
300
+ return { modelSlug: baseSlug, effort: null };
301
+ }
302
+
251
303
  export function isAntigravityProvider(provider?: string | null): boolean {
252
304
  if (!provider) return false;
253
305
  const p = String(provider).toLowerCase();
@@ -1070,11 +1122,8 @@ export class AntigravityProvider extends LLMProvider {
1070
1122
  'If you start a persistent local HTTP server, use `sysRunBg` or redirect stdio (`nohup ... </dev/null >/dev/null 2>&1 &`) so the server does not break with EIO when the turn pseudo-terminal closes.\n\n' + promptText;
1071
1123
  }
1072
1124
 
1073
- const modelSlug = resolveAgyModelId(this.model);
1074
- const explicitEffort = this.reasoningEffort && ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra'].includes(this.reasoningEffort)
1075
- ? this.reasoningEffort
1076
- : null;
1077
- const effort = explicitEffort || resolveAgyEffort(this.model);
1125
+ const { modelSlug, effort } = resolveAgyCliModelAndEffort(this.model, this.reasoningEffort);
1126
+ const workerEffortKey = effort || resolveAgyEffort(modelSlug);
1078
1127
 
1079
1128
  // Run the user's normal peer in the selected project. Do not substitute a
1080
1129
  // managed inference profile or hide project MCPs, skills, and instructions.
@@ -1091,7 +1140,7 @@ export class AntigravityProvider extends LLMProvider {
1091
1140
  modelSlug
1092
1141
  ];
1093
1142
 
1094
- if (effort && (Boolean(explicitEffort) || modelSlug.endsWith(`-${effort}`) || /-(low|medium|high|xhigh|max|ultra)$/i.test(modelSlug))) {
1143
+ if (effort) {
1095
1144
  args.push('--effort', effort);
1096
1145
  }
1097
1146
 
@@ -1107,7 +1156,7 @@ export class AntigravityProvider extends LLMProvider {
1107
1156
  existingWorker
1108
1157
  && existingWorker.workspaceRoot === workspaceRoot
1109
1158
  && existingWorker.modelSlug === modelSlug
1110
- && existingWorker.effort === effort
1159
+ && existingWorker.effort === workerEffortKey
1111
1160
  && existingWorker.child.exitCode === null
1112
1161
  && existingWorker.child.signalCode === null
1113
1162
  && !existingWorker.child.killed
@@ -1133,7 +1182,7 @@ export class AntigravityProvider extends LLMProvider {
1133
1182
  windowsHide: true
1134
1183
  });
1135
1184
  if (canUsePersistent) {
1136
- this.persistentWorker = { child, workspaceRoot, modelSlug, effort };
1185
+ this.persistentWorker = { child, workspaceRoot, modelSlug, effort: workerEffortKey };
1137
1186
  }
1138
1187
  }
1139
1188
  this.activeChild = child;
@@ -1686,7 +1735,12 @@ export class AntigravityProvider extends LLMProvider {
1686
1735
  if (useConversation) this.currentConversationId = null;
1687
1736
  const errDetail = finalResultObj?.error || stderrBuffer.trim() ||
1688
1737
  `terminal status ${finalResultObj?.status || 'unknown'}, exit code ${code}`;
1689
- safeReject(new Error(`Antigravity Agent (agy) failed: ${errDetail}`));
1738
+ const isInvalidSelection = /invalid model selection|conflicts with --effort|--effort is not supported/i.test(errDetail);
1739
+ const failure = Object.assign(
1740
+ new Error(`Antigravity Agent (agy) failed: ${errDetail}`),
1741
+ isInvalidSelection ? { code: 'AGY_INVALID_MODEL_SELECTION', status: 400 } : {}
1742
+ );
1743
+ safeReject(failure);
1690
1744
  return;
1691
1745
  }
1692
1746
 
@@ -1924,11 +1978,21 @@ export class AntigravityProvider extends LLMProvider {
1924
1978
  override async chat(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
1925
1979
  const maxRetries = options.maxRetries ?? ((options as any).taskIntent === 'launch' ? 1 : 2);
1926
1980
  let attempt = 0;
1981
+ let clearedEffortFallback = false;
1927
1982
  while (attempt <= maxRetries) {
1928
1983
  const hadConversation = Boolean(this.currentConversationId);
1929
1984
  try {
1930
1985
  return await this._executeOnce(messages, options);
1931
1986
  } catch (err: any) {
1987
+ if (err?.code === 'AGY_INVALID_MODEL_SELECTION') {
1988
+ if (!clearedEffortFallback && this.reasoningEffort) {
1989
+ clearedEffortFallback = true;
1990
+ this.reasoningEffort = null;
1991
+ this.currentConversationId = null;
1992
+ continue;
1993
+ }
1994
+ throw err;
1995
+ }
1932
1996
  if (!shouldRetryPeerError(err, options.signal?.aborted === true || err?.name === 'AbortError')
1933
1997
  || err?.code === 'AGY_NATIVE_ACTION_DENIED' || err?.code === 'PROVIDER_NO_PROGRESS') {
1934
1998
  throw err;
@@ -220,7 +220,13 @@ export function redactTextSecrets(rawText, secrets = [], options = {}) {
220
220
  const trimmed = secret.trim();
221
221
  if (trimmed.length >= 6) {
222
222
  text = text.split(trimmed).join('[REDACTED]');
223
- const encoded = encodeURIComponent(trimmed);
223
+ let encoded = trimmed;
224
+ try {
225
+ encoded = encodeURIComponent(trimmed);
226
+ }
227
+ catch {
228
+ // The raw secret was already redacted; malformed UTF-16 has no URI encoding.
229
+ }
224
230
  if (encoded !== trimmed && encoded.length >= 6) {
225
231
  text = text.split(encoded).join('[REDACTED]');
226
232
  }
@@ -309,7 +309,12 @@ export function redactTextSecrets(
309
309
  const trimmed = secret.trim();
310
310
  if (trimmed.length >= 6) {
311
311
  text = text.split(trimmed).join('[REDACTED]');
312
- const encoded = encodeURIComponent(trimmed);
312
+ let encoded = trimmed;
313
+ try {
314
+ encoded = encodeURIComponent(trimmed);
315
+ } catch {
316
+ // The raw secret was already redacted; malformed UTF-16 has no URI encoding.
317
+ }
313
318
  if (encoded !== trimmed && encoded.length >= 6) {
314
319
  text = text.split(encoded).join('[REDACTED]');
315
320
  }
@@ -210,22 +210,30 @@ async function consumeSseStream(response, providerLabel, maxBytes, onEvent, sign
210
210
  await reader.cancel().catch(() => { });
211
211
  throw new Error(`${providerLabel} SSE event buffer exceeded safety limit (${MAX_SSE_BUFFER_BYTES} bytes).`);
212
212
  }
213
- let newlineIdx = buffer.indexOf('\n');
213
+ let newlineIdx = buffer.search(/[\r\n]/);
214
214
  while (newlineIdx !== -1) {
215
+ // Retain a trailing CR until the next chunk to distinguish CRLF.
216
+ if (buffer[newlineIdx] === '\r' && newlineIdx === buffer.length - 1)
217
+ break;
218
+ const delimiterLength = buffer.slice(newlineIdx, newlineIdx + 2) === '\r\n' ? 2 : 1;
215
219
  const line = buffer.slice(0, newlineIdx);
216
- buffer = buffer.slice(newlineIdx + 1);
220
+ buffer = buffer.slice(newlineIdx + delimiterLength);
217
221
  processLine(line);
218
- newlineIdx = buffer.indexOf('\n');
222
+ newlineIdx = buffer.search(/[\r\n]/);
219
223
  }
220
224
  }
221
225
  buffer += decoder.decode();
222
226
  if (buffer.length > 0) {
223
- for (const tailLine of buffer.split('\n')) {
227
+ for (const tailLine of buffer.split(/\r\n|\r|\n/)) {
224
228
  processLine(tailLine);
225
229
  }
226
230
  }
227
231
  flushEvent();
228
232
  }
233
+ catch (error) {
234
+ await reader.cancel().catch(() => { });
235
+ throw error;
236
+ }
229
237
  finally {
230
238
  reader.releaseLock();
231
239
  }
@@ -243,14 +251,15 @@ async function consumeNdjsonStream(response, providerLabel, maxBytes, onObject,
243
251
  const trimmed = stripped.trim();
244
252
  if (!trimmed)
245
253
  return;
254
+ let parsed;
246
255
  try {
247
- const parsed = JSON.parse(trimmed);
248
- if (isRecord(parsed))
249
- onObject(parsed);
256
+ parsed = JSON.parse(trimmed);
250
257
  }
251
258
  catch {
252
- // Ignore malformed trailing fragments
259
+ return;
253
260
  }
261
+ if (isRecord(parsed))
262
+ onObject(parsed);
254
263
  };
255
264
  try {
256
265
  while (true) {
@@ -287,6 +296,10 @@ async function consumeNdjsonStream(response, providerLabel, maxBytes, onObject,
287
296
  processLine(buffer);
288
297
  }
289
298
  }
299
+ catch (error) {
300
+ await reader.cancel().catch(() => { });
301
+ throw error;
302
+ }
290
303
  finally {
291
304
  reader.releaseLock();
292
305
  }
@@ -275,22 +275,28 @@ async function consumeSseStream(
275
275
  throw new Error(`${providerLabel} SSE event buffer exceeded safety limit (${MAX_SSE_BUFFER_BYTES} bytes).`);
276
276
  }
277
277
 
278
- let newlineIdx = buffer.indexOf('\n');
278
+ let newlineIdx = buffer.search(/[\r\n]/);
279
279
  while (newlineIdx !== -1) {
280
+ // Retain a trailing CR until the next chunk to distinguish CRLF.
281
+ if (buffer[newlineIdx] === '\r' && newlineIdx === buffer.length - 1) break;
282
+ const delimiterLength = buffer.slice(newlineIdx, newlineIdx + 2) === '\r\n' ? 2 : 1;
280
283
  const line = buffer.slice(0, newlineIdx);
281
- buffer = buffer.slice(newlineIdx + 1);
284
+ buffer = buffer.slice(newlineIdx + delimiterLength);
282
285
  processLine(line);
283
- newlineIdx = buffer.indexOf('\n');
286
+ newlineIdx = buffer.search(/[\r\n]/);
284
287
  }
285
288
  }
286
289
 
287
290
  buffer += decoder.decode();
288
291
  if (buffer.length > 0) {
289
- for (const tailLine of buffer.split('\n')) {
292
+ for (const tailLine of buffer.split(/\r\n|\r|\n/)) {
290
293
  processLine(tailLine);
291
294
  }
292
295
  }
293
296
  flushEvent();
297
+ } catch (error) {
298
+ await reader.cancel().catch(() => {});
299
+ throw error;
294
300
  } finally {
295
301
  reader.releaseLock();
296
302
  }
@@ -316,12 +322,13 @@ async function consumeNdjsonStream(
316
322
  const stripped = rawLine.charCodeAt(0) === 0xfeff ? rawLine.slice(1) : rawLine;
317
323
  const trimmed = stripped.trim();
318
324
  if (!trimmed) return;
325
+ let parsed: unknown;
319
326
  try {
320
- const parsed: unknown = JSON.parse(trimmed);
321
- if (isRecord(parsed)) onObject(parsed);
327
+ parsed = JSON.parse(trimmed);
322
328
  } catch {
323
- // Ignore malformed trailing fragments
329
+ return;
324
330
  }
331
+ if (isRecord(parsed)) onObject(parsed);
325
332
  };
326
333
 
327
334
  try {
@@ -360,6 +367,9 @@ async function consumeNdjsonStream(
360
367
  if (buffer.trim()) {
361
368
  processLine(buffer);
362
369
  }
370
+ } catch (error) {
371
+ await reader.cancel().catch(() => {});
372
+ throw error;
363
373
  } finally {
364
374
  reader.releaseLock();
365
375
  }
@@ -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
  import { resolveBudgetTokensForVariant } from '../modelVariants.js';
9
9
  export class DashscopeByokProvider extends LLMProvider {
@@ -109,17 +109,33 @@ export class DashscopeByokProvider extends LLMProvider {
109
109
  }
110
110
  }
111
111
  };
112
- const data = wantsStreaming(options)
112
+ const runDashscopeRequest = async (reqPayload) => (wantsStreaming(options)
113
113
  ? await streamOpenAICompatibleChat({
114
114
  ...requestOpts,
115
- payload,
115
+ payload: reqPayload,
116
116
  onChunk: options.onChunk,
117
117
  onReasoningChunk: options.onReasoningChunk
118
118
  })
119
119
  : await safeProviderFetchJson({
120
120
  ...requestOpts,
121
- body: JSON.stringify(payload)
122
- });
121
+ body: JSON.stringify(reqPayload)
122
+ }));
123
+ let data;
124
+ try {
125
+ data = await runDashscopeRequest(payload);
126
+ }
127
+ catch (err) {
128
+ const rejectedThinking = ('enable_thinking' in payload || 'thinking_budget' in payload)
129
+ && err instanceof ProviderHttpError
130
+ && err.status === 400
131
+ && /(?:enable_thinking|thinking_budget|thinking|unsupported|not supported|invalid|unknown)/i.test(err.message);
132
+ if (!rejectedThinking)
133
+ throw err;
134
+ const fallbackPayload = { ...payload };
135
+ delete fallbackPayload['enable_thinking'];
136
+ delete fallbackPayload['thinking_budget'];
137
+ data = await runDashscopeRequest(fallbackPayload);
138
+ }
123
139
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
124
140
  prefix: 'call_dashscope',
125
141
  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
@@ -116,17 +117,34 @@ export class DashscopeByokProvider extends LLMProvider {
116
117
  }
117
118
  };
118
119
 
119
- const data = wantsStreaming(options)
120
- ? await streamOpenAICompatibleChat({
121
- ...requestOpts,
122
- payload,
123
- onChunk: options.onChunk,
124
- onReasoningChunk: options.onReasoningChunk
125
- })
126
- : await safeProviderFetchJson({
127
- ...requestOpts,
128
- body: JSON.stringify(payload)
129
- });
120
+ const runDashscopeRequest = async (reqPayload: Record<string, any>) => (
121
+ wantsStreaming(options)
122
+ ? await streamOpenAICompatibleChat({
123
+ ...requestOpts,
124
+ payload: reqPayload,
125
+ onChunk: options.onChunk,
126
+ onReasoningChunk: options.onReasoningChunk
127
+ })
128
+ : await safeProviderFetchJson({
129
+ ...requestOpts,
130
+ body: JSON.stringify(reqPayload)
131
+ })
132
+ );
133
+
134
+ let data: Record<string, any>;
135
+ try {
136
+ data = await runDashscopeRequest(payload);
137
+ } catch (err: unknown) {
138
+ const rejectedThinking = ('enable_thinking' in payload || 'thinking_budget' in payload)
139
+ && err instanceof ProviderHttpError
140
+ && err.status === 400
141
+ && /(?:enable_thinking|thinking_budget|thinking|unsupported|not supported|invalid|unknown)/i.test(err.message);
142
+ if (!rejectedThinking) throw err;
143
+ const fallbackPayload = { ...payload };
144
+ delete fallbackPayload['enable_thinking'];
145
+ delete fallbackPayload['thinking_budget'];
146
+ data = await runDashscopeRequest(fallbackPayload);
147
+ }
130
148
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
131
149
  prefix: 'call_dashscope',
132
150
  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 MoonshotProvider extends LLMProvider {
9
9
  allowInsecureHttp;
@@ -38,8 +38,11 @@ export class MoonshotProvider extends LLMProvider {
38
38
  }
39
39
  else {
40
40
  payload['thinking'] = { type: 'enabled' };
41
- if (['low', 'medium', 'high'].includes(this.reasoningEffort)) {
42
- payload['reasoning_effort'] = this.reasoningEffort;
41
+ const mappedEffort = this.reasoningEffort === 'minimal'
42
+ ? 'low'
43
+ : (['xhigh', 'max', 'ultra'].includes(this.reasoningEffort) ? 'high' : this.reasoningEffort);
44
+ if (['low', 'medium', 'high'].includes(mappedEffort)) {
45
+ payload['reasoning_effort'] = mappedEffort;
43
46
  }
44
47
  }
45
48
  }
@@ -88,17 +91,33 @@ export class MoonshotProvider extends LLMProvider {
88
91
  }
89
92
  }
90
93
  };
91
- const data = wantsStreaming(options)
94
+ const runMoonshotRequest = async (reqPayload) => (wantsStreaming(options)
92
95
  ? await streamOpenAICompatibleChat({
93
96
  ...requestOpts,
94
- payload,
97
+ payload: reqPayload,
95
98
  onChunk: options.onChunk,
96
99
  onReasoningChunk: options.onReasoningChunk
97
100
  })
98
101
  : await safeProviderFetchJson({
99
102
  ...requestOpts,
100
- body: JSON.stringify(payload)
101
- });
103
+ body: JSON.stringify(reqPayload)
104
+ }));
105
+ let data;
106
+ try {
107
+ data = await runMoonshotRequest(payload);
108
+ }
109
+ catch (err) {
110
+ const rejectedReasoning = ('thinking' in payload || 'reasoning_effort' in payload)
111
+ && err instanceof ProviderHttpError
112
+ && err.status === 400
113
+ && /(?:thinking|reasoning_effort|effort|unsupported|not supported|invalid|unknown)/i.test(err.message);
114
+ if (!rejectedReasoning)
115
+ throw err;
116
+ const fallbackPayload = { ...payload };
117
+ delete fallbackPayload['thinking'];
118
+ delete fallbackPayload['reasoning_effort'];
119
+ data = await runMoonshotRequest(fallbackPayload);
120
+ }
102
121
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
103
122
  prefix: 'call_moonshot',
104
123
  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
@@ -45,8 +46,11 @@ export class MoonshotProvider extends LLMProvider {
45
46
  payload['thinking'] = { type: 'disabled' };
46
47
  } else {
47
48
  payload['thinking'] = { type: 'enabled' };
48
- if (['low', 'medium', 'high'].includes(this.reasoningEffort)) {
49
- payload['reasoning_effort'] = this.reasoningEffort;
49
+ const mappedEffort = this.reasoningEffort === 'minimal'
50
+ ? 'low'
51
+ : (['xhigh', 'max', 'ultra'].includes(this.reasoningEffort) ? 'high' : this.reasoningEffort);
52
+ if (['low', 'medium', 'high'].includes(mappedEffort)) {
53
+ payload['reasoning_effort'] = mappedEffort;
50
54
  }
51
55
  }
52
56
  }
@@ -96,17 +100,34 @@ export class MoonshotProvider extends LLMProvider {
96
100
  }
97
101
  };
98
102
 
99
- const data = wantsStreaming(options)
100
- ? await streamOpenAICompatibleChat({
101
- ...requestOpts,
102
- payload,
103
- onChunk: options.onChunk,
104
- onReasoningChunk: options.onReasoningChunk
105
- })
106
- : await safeProviderFetchJson({
107
- ...requestOpts,
108
- body: JSON.stringify(payload)
109
- });
103
+ const runMoonshotRequest = async (reqPayload: Record<string, any>) => (
104
+ wantsStreaming(options)
105
+ ? await streamOpenAICompatibleChat({
106
+ ...requestOpts,
107
+ payload: reqPayload,
108
+ onChunk: options.onChunk,
109
+ onReasoningChunk: options.onReasoningChunk
110
+ })
111
+ : await safeProviderFetchJson({
112
+ ...requestOpts,
113
+ body: JSON.stringify(reqPayload)
114
+ })
115
+ );
116
+
117
+ let data: Record<string, any>;
118
+ try {
119
+ data = await runMoonshotRequest(payload);
120
+ } catch (err: unknown) {
121
+ const rejectedReasoning = ('thinking' in payload || 'reasoning_effort' in payload)
122
+ && err instanceof ProviderHttpError
123
+ && err.status === 400
124
+ && /(?:thinking|reasoning_effort|effort|unsupported|not supported|invalid|unknown)/i.test(err.message);
125
+ if (!rejectedReasoning) throw err;
126
+ const fallbackPayload = { ...payload };
127
+ delete fallbackPayload['thinking'];
128
+ delete fallbackPayload['reasoning_effort'];
129
+ data = await runMoonshotRequest(fallbackPayload);
130
+ }
110
131
  const normalized = normalizeOpenAIChatChoiceResponse(data, {
111
132
  prefix: 'call_moonshot',
112
133
  freeFormPaths
@@ -45,6 +45,12 @@ export class MuseProvider extends OpenAICompatibleProvider {
45
45
  this.contextTokens = MUSE_CONTEXT_TOKENS;
46
46
  this.reasoningEffort = clampReasoningEffort(config.reasoningEffort, this.model);
47
47
  }
48
+ supportsReasoningEffort() {
49
+ return /^muse-spark/i.test((this.model || '').trim());
50
+ }
51
+ resolvePayloadReasoningEffort() {
52
+ return clampReasoningEffort(this.reasoningEffort, this.model);
53
+ }
48
54
  audioAlternative() {
49
55
  if (this.supportsAudio)
50
56
  return null;