@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
package/src/commands.ts CHANGED
@@ -20,6 +20,12 @@ import {
20
20
  } from './userSkills.js';
21
21
  import { buildContextText, buildUsageText, buildCheckpointsText, buildUndoText, buildStatusText } from './reporting.js';
22
22
  import { loadConfig, saveConfig } from './config.js';
23
+ import {
24
+ getDefaultPermissionPreset,
25
+ getPermissionPresetDescriptor,
26
+ normalizePermissionPreset,
27
+ setDefaultPermissionPreset
28
+ } from './permissionPresets.js';
23
29
  import {
24
30
  resolveAvailableModels,
25
31
  getCuratedModels,
@@ -98,6 +104,12 @@ import { collectWorkingTreeDiff, renderDiffReview } from './diffReview.js';
98
104
  import { fetchFailedCiLogs, formatPrStatusReport, inspectPrStatus, preparePrDraft } from './prWorkflow.js';
99
105
  import { formatEvalScorecard, runCodingEvalSuite } from './benchmarks/codingEval.js';
100
106
  import { formatProjectRulesReport } from './projectInstructions.js';
107
+ import {
108
+ deleteCausyneMemories,
109
+ readPersonalizationOverview,
110
+ saveMemoryPreferences,
111
+ savePersonalizationInstructions
112
+ } from './personalization.js';
101
113
  import { buildRepoMap } from './codebase/repoMap.js';
102
114
  import { backgroundTaskManager } from './backgroundTasks.js';
103
115
  import {
@@ -111,6 +123,16 @@ import {
111
123
  getGuiServerStatus,
112
124
  stopGuiServer
113
125
  } from './web/guiLauncher.js';
126
+ import {
127
+ launchGameStudio,
128
+ getGameStudioStatus,
129
+ stopGameStudio
130
+ } from './game/gameLauncher.js';
131
+ import {
132
+ defaultGameManifestUrl,
133
+ installGameStudio,
134
+ locateGameStudio
135
+ } from './game/gameProvisioner.js';
114
136
 
115
137
  export interface CommandCompletionItem {
116
138
  value: string;
@@ -313,13 +335,20 @@ async function applySelectedVariant(
313
335
  );
314
336
  }
315
337
 
316
- config.reasoningEffort = matched.id;
317
338
  const modelChanged = Boolean(matched.targetModelId && matched.targetModelId !== config.model);
318
339
  if (matched.targetModelId) {
319
340
  config.model = matched.targetModelId;
320
341
  }
342
+ if (spec.source === 'agy_models') {
343
+ delete config.reasoningEffort;
344
+ delete config.reasoningBudgetTokens;
345
+ } else {
346
+ config.reasoningEffort = matched.id;
347
+ }
321
348
  saveConfig(config);
322
349
 
350
+ const displayedVariant = spec.source === 'agy_models' ? '' : matched.id;
351
+
323
352
  let liveSynced = false;
324
353
  if (typeof ctx.loop?.llm?.applyVariant === 'function' && !modelChanged) {
325
354
  liveSynced = Boolean(await ctx.loop.llm.applyVariant(matched.id, matched.acpConfigId));
@@ -335,17 +364,17 @@ async function applySelectedVariant(
335
364
 
336
365
  if (ctx.prompt) {
337
366
  if (typeof ctx.prompt.updateModel === 'function') {
338
- ctx.prompt.updateModel(config.provider || spec.provider, config.model || spec.model, matched.id);
367
+ ctx.prompt.updateModel(config.provider || spec.provider, config.model || spec.model, displayedVariant);
339
368
  } else if (ctx.prompt.renderer?.status) {
340
369
  ctx.prompt.renderer.status.setSession({
341
370
  provider: config.provider || spec.provider,
342
371
  model: config.model || spec.model,
343
- variant: matched.id
372
+ variant: displayedVariant
344
373
  });
345
374
  ctx.prompt.surface?.setSessionInfo?.({
346
375
  provider: config.provider || spec.provider,
347
376
  model: config.model || spec.model,
348
- variant: matched.id
377
+ variant: displayedVariant
349
378
  });
350
379
  if (typeof ctx.prompt.scheduleDraw === 'function') ctx.prompt.scheduleDraw();
351
380
  }
@@ -615,12 +644,10 @@ export const COMMANDS: SlashCommandDefinition[] = [
615
644
  /**
616
645
  * Argument suggestions, offered as the user types `/skills <prefix>`.
617
646
  *
618
- * openclaw's contract (src/tui/commands.ts getArgumentCompletions): the
619
- * command owns its argument vocabulary and the prompt asks for it. Ranking
620
- * and filtering are the prompt's job — this returns the whole vocabulary and
621
- * completion.js scores it with the same function it uses for commands and
622
- * filenames, so `/skills doc` reaches devops/docker-multi-stage-builds by a
623
- * basename-prefix match rather than needing the domain typed first.
647
+ * The command owns its argument vocabulary and the prompt ranks and filters
648
+ * candidates using the shared fuzzy scorer, so `/skills doc` reaches
649
+ * `devops/docker-multi-stage-builds` by a basename-prefix match rather than
650
+ * requiring the domain to be typed first.
624
651
  *
625
652
  * Domains are offered alongside skills because `/skills devops` is a valid
626
653
  * argument in its own right.
@@ -1379,38 +1406,79 @@ export const COMMANDS: SlashCommandDefinition[] = [
1379
1406
 
1380
1407
  {
1381
1408
  name: 'cortex',
1382
- aliases: ['memory'],
1409
+ aliases: ['memory', 'memories'],
1383
1410
  scope: 'local',
1384
- usage: '/cortex [status | list | search <query> | on | off | forget <id|--workspace>]',
1385
- description: 'Inspect, search, toggle, or clear persistent Cortex memory',
1411
+ usage: '/cortex [status | list | search <query> | on | off | tool-assisted on|off | forget <id|--workspace|all>]',
1412
+ description: 'Inspect, search, toggle, or clear Causyne & Cortex persistent memory',
1386
1413
  dialogTitle: 'Cortex Memory',
1387
1414
  complete: () => [
1388
- { value: 'status', label: 'status', description: 'show Cortex memory counts and engine status' },
1415
+ { value: 'status', label: 'status', description: 'show memory controls, counts, and Cortex engine status' },
1389
1416
  { value: 'list', label: 'list', description: 'list recent memories stored for this workspace' },
1390
1417
  { value: 'search', label: 'search', description: 'semantic search across stored memories' },
1391
- { value: 'on', label: 'on', description: 'enable persistent Cortex memory recall' },
1392
- { value: 'off', label: 'off', description: 'disable persistent Cortex memory recall' },
1393
- { value: 'forget --workspace', label: 'forget --workspace', description: 'clear memories for the current workspace' }
1418
+ { value: 'on', label: 'on', description: 'enable Causyne memories for this project (add "global" for all)' },
1419
+ { value: 'off', label: 'off', description: 'disable Causyne memories for this project (add "global" for all)' },
1420
+ { value: 'tool-assisted on', label: 'tool-assisted on', description: 'allow memories from MCP/web tool-assisted chats' },
1421
+ { value: 'tool-assisted off', label: 'tool-assisted off', description: 'block memories from MCP/web tool-assisted chats' },
1422
+ { value: 'forget --workspace', label: 'forget --workspace', description: 'clear memories for the current workspace' },
1423
+ { value: 'forget all', label: 'forget all', description: 'clear all stored Causyne memories on this device' }
1394
1424
  ],
1395
1425
  run: async (argv, ctx = {}) => {
1396
1426
  const sub = String(argv[0] || 'status').trim().toLowerCase();
1397
1427
  const workspace = ctx.loop?.workspaceRoot || process.cwd();
1428
+ const invalidateLoop = (): void => {
1429
+ if (ctx.loop && 'staticContext' in ctx.loop) {
1430
+ (ctx.loop as any).staticContext = null;
1431
+ }
1432
+ };
1398
1433
 
1399
1434
  if (sub === 'on' || sub === 'enable' || sub === 'off' || sub === 'disable') {
1400
1435
  const enabled = sub === 'on' || sub === 'enable';
1401
- const config = loadConfig();
1402
- const prev = config.cortex && typeof config.cortex === 'object' ? config.cortex : {};
1403
- config.cortex = { ...prev, enabled };
1404
- saveConfig(config);
1436
+ const explicitScope = String(argv[1] || '').trim().toLowerCase();
1437
+ const scopeArg: 'project' | 'global' = explicitScope === 'global'
1438
+ ? 'global'
1439
+ : explicitScope === 'project'
1440
+ ? 'project'
1441
+ : (ctx.loop?.workspaceRoot ? 'project' : 'global');
1442
+ const policy = saveMemoryPreferences(workspace, scopeArg, { enabled });
1443
+ if (scopeArg === 'global') {
1444
+ const config = loadConfig();
1445
+ const prev = config.cortex && typeof config.cortex === 'object' ? config.cortex : {};
1446
+ config.cortex = { ...prev, enabled };
1447
+ saveConfig(config);
1448
+ }
1405
1449
  if (ctx.loop) {
1406
1450
  ctx.loop.config = loadConfig();
1407
1451
  }
1452
+ invalidateLoop();
1453
+ return ok(
1454
+ `Causyne & Cortex memory (${scopeArg}) is now ${policy.enabled ? 'ENABLED' : 'DISABLED'}.`,
1455
+ { effect: 'inline' }
1456
+ );
1457
+ }
1458
+
1459
+ if (sub === 'tool-assisted' || sub === 'tool-memory') {
1460
+ const toggle = String(argv[1] || '').trim().toLowerCase();
1461
+ const scopeArg = String(argv[2] || 'project').trim().toLowerCase() === 'global' ? 'global' : 'project';
1462
+ if (toggle !== 'on' && toggle !== 'off') {
1463
+ return fail('Usage: /memory tool-assisted on|off [project|global]');
1464
+ }
1465
+ const policy = saveMemoryPreferences(workspace, scopeArg, { allowToolAssisted: toggle === 'on' });
1466
+ invalidateLoop();
1408
1467
  return ok(
1409
- `Cortex persistent memory is now ${enabled ? 'ENABLED' : 'DISABLED'}.`,
1468
+ `Tool-assisted chat memories (${scopeArg}) are now ${policy.allowToolAssisted ? 'ALLOWED' : 'BLOCKED'}.`,
1410
1469
  { effect: 'inline' }
1411
1470
  );
1412
1471
  }
1413
1472
 
1473
+ if (sub === 'forget' && (String(argv[1] || '').trim().toLowerCase() === 'all' || String(argv[1] || '').trim().toLowerCase() === 'project')) {
1474
+ const delScope = String(argv[1] || '').trim().toLowerCase() === 'all' ? 'all' : 'project';
1475
+ const deleted = deleteCausyneMemories(workspace, delScope);
1476
+ invalidateLoop();
1477
+ return ok(
1478
+ `Deleted Causyne memories (${delScope}): ${deleted.factsRemoved} facts, ${deleted.observationsRemoved} observations, ${deleted.summariesRemoved} summaries removed.`
1479
+ );
1480
+ }
1481
+
1414
1482
  const config = loadConfig();
1415
1483
  const enabled = config.cortex?.enabled !== false;
1416
1484
 
@@ -2316,6 +2384,149 @@ export const COMMANDS: SlashCommandDefinition[] = [
2316
2384
  }
2317
2385
  },
2318
2386
 
2387
+ {
2388
+ name: 'game',
2389
+ aliases: ['gamestudio', 'causyne-game'],
2390
+ scope: 'local',
2391
+ usage: '/game [open | status | stop | install [--yes] | --port <n> | --no-open]',
2392
+ description: 'Launch, inspect, stop, or install Causyne Game (official separate AI Game Studio)',
2393
+ complete: () => [
2394
+ { value: 'open', label: 'open', description: 'launch and open Causyne Game Studio in your browser' },
2395
+ { value: 'status', label: 'status', description: 'show Causyne Game installation and running server status' },
2396
+ { value: 'stop', label: 'stop', description: 'shut down the local Causyne Game server' },
2397
+ { value: 'install', label: 'install', description: 'check or download Causyne Game from the release manifest' },
2398
+ { value: '--no-open', label: '--no-open', description: 'start Causyne Game without automatically opening a browser tab' }
2399
+ ],
2400
+ run: async (argv, ctx = {}) => {
2401
+ const tokens = argv.map((t) => String(t || '').trim()).filter(Boolean);
2402
+ const first = (tokens[0] || 'open').toLowerCase();
2403
+
2404
+ if (first === 'status') {
2405
+ const located = locateGameStudio();
2406
+ const status = getGameStudioStatus();
2407
+ const lines = ['Causyne Game Studio'];
2408
+ if (located) {
2409
+ lines.push(` Installed : yes (${located.source}${located.version ? ` · v${located.version}` : ''})`);
2410
+ lines.push(` Location : ${safeDisplay(located.dir)}`);
2411
+ lines.push(` Build : ${located.hasNodeModules && located.hasStudioBuild ? 'ready' : 'incomplete (run npm ci && npm run build:studio)'}`);
2412
+ } else {
2413
+ lines.push(' Installed : no (run /game install --yes or set CAUSYNE_GAME_DIR)');
2414
+ }
2415
+ lines.push(` Manifest : ${defaultGameManifestUrl()}`);
2416
+ if (status.running) {
2417
+ lines.push(` Server : running at ${status.url} (127.0.0.1 loopback only)`);
2418
+ lines.push(' Control : /game stop (also stops automatically on CLI exit)');
2419
+ } else {
2420
+ lines.push(' Server : not running (run /game to launch)');
2421
+ }
2422
+ return ok(lines.join('\n'), { effect: 'inline' });
2423
+ }
2424
+
2425
+ if (first === 'stop' || first === 'close' || first === 'off') {
2426
+ const stopped = await stopGameStudio();
2427
+ if (ctx.prompt) {
2428
+ ctx.prompt.notice = stopped ? 'Causyne Game stopped' : 'Causyne Game was not running';
2429
+ ctx.prompt.scheduleDraw?.();
2430
+ }
2431
+ return ok(
2432
+ stopped ? 'Stopped local Causyne Game Studio server.' : 'Causyne Game Studio is not currently running.',
2433
+ { effect: 'inline' }
2434
+ );
2435
+ }
2436
+
2437
+ if (first === 'install') {
2438
+ const confirm = tokens.some((tok) => tok === '--yes' || tok === '-y' || tok === '--confirm');
2439
+ let manifestUrl: string | undefined;
2440
+ for (let i = 1; i < tokens.length; i++) {
2441
+ const tok = tokens[i]!;
2442
+ if (tok === '--manifest' && i + 1 < tokens.length) {
2443
+ manifestUrl = tokens[++i];
2444
+ } else if (tok.startsWith('--manifest=')) {
2445
+ manifestUrl = tok.slice('--manifest='.length);
2446
+ }
2447
+ }
2448
+ const res = await installGameStudio({ confirm, manifestUrl });
2449
+ if (res.requiresConsent) {
2450
+ const lines = [
2451
+ `Causyne Game v${res.version ?? 'latest'} is ready to install from ${safeDisplay(res.manifestUrl)}.`
2452
+ ];
2453
+ if (res.license) lines.push(` License : ${safeDisplay(res.license)}`);
2454
+ if (res.size) lines.push(` Size : ${(res.size / (1024 * 1024)).toFixed(1)} MB (SHA-256 verified)`);
2455
+ lines.push(' Confirm : run /game install --yes to download and install into ~/.causyne/game/');
2456
+ return ok(lines.join('\n'), { effect: 'inline' });
2457
+ }
2458
+ if (!res.success) {
2459
+ return fail(`Causyne Game install failed: ${safeDisplay(res.error || 'unknown error')}`);
2460
+ }
2461
+ return ok(
2462
+ res.alreadyInstalled
2463
+ ? `Causyne Game v${res.version ?? ''} is already installed at ${safeDisplay(res.path || '')}. Run /game to launch.`
2464
+ : `Installed Causyne Game v${res.version ?? ''} to ${safeDisplay(res.path || '')}. Run /game to launch.`,
2465
+ { effect: 'inline' }
2466
+ );
2467
+ }
2468
+
2469
+ let port = 0;
2470
+ let noOpen = false;
2471
+ for (let i = 0; i < tokens.length; i++) {
2472
+ const tok = tokens[i]!;
2473
+ const lower = tok.toLowerCase();
2474
+ if (lower === 'open' || lower === 'start') continue;
2475
+ if (lower === '--no-open' || lower === '--no-browser') {
2476
+ noOpen = true;
2477
+ continue;
2478
+ }
2479
+ if (lower === '--port' && i + 1 < tokens.length) {
2480
+ const parsed = Number.parseInt(tokens[++i]!, 10);
2481
+ if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
2482
+ return fail(`Invalid port "${safeDisplay(tokens[i]!)}". Expected 0-65535.`);
2483
+ }
2484
+ port = parsed;
2485
+ continue;
2486
+ }
2487
+ if (lower.startsWith('--port=')) {
2488
+ const rawPort = tok.slice('--port='.length);
2489
+ const parsed = Number.parseInt(rawPort, 10);
2490
+ if (!Number.isInteger(parsed) || parsed < 0 || parsed > 65535) {
2491
+ return fail(`Invalid port "${safeDisplay(rawPort)}". Expected 0-65535.`);
2492
+ }
2493
+ port = parsed;
2494
+ continue;
2495
+ }
2496
+ return fail(`Unknown /game option "${safeDisplay(tok)}". Usage: /game [open | status | stop | install [--yes] | --port <n> | --no-open]`);
2497
+ }
2498
+
2499
+ let launched;
2500
+ try {
2501
+ launched = await launchGameStudio({
2502
+ port,
2503
+ openBrowser: !noOpen
2504
+ });
2505
+ } catch (error) {
2506
+ return fail(error instanceof Error ? error.message : String(error));
2507
+ }
2508
+
2509
+ if (ctx.prompt) {
2510
+ ctx.prompt.notice = `Causyne Game live at ${launched.origin}`;
2511
+ ctx.prompt.scheduleDraw?.();
2512
+ }
2513
+
2514
+ const outLines = [
2515
+ launched.reused
2516
+ ? 'Causyne Game Studio is already running (127.0.0.1 loopback only):'
2517
+ : 'Causyne Game Studio started (127.0.0.1 loopback only · primary agent: Causyne Agent):',
2518
+ ` Open URL : ${launched.url}${launched.copiedToClipboard ? ' (copied to clipboard)' : ''}`,
2519
+ ` Source : ${launched.source}${launched.version ? ` (v${launched.version})` : ''} · ${safeDisplay(launched.dir)}`,
2520
+ ` Browser : ${launched.openedBrowser ? 'Opened in your default browser' : 'Open the URL above in your browser'}`
2521
+ ];
2522
+ if (launched.browserHint) {
2523
+ outLines.push(` Remote : ${safeDisplay(launched.browserHint)}`);
2524
+ }
2525
+ outLines.push(' Control : /game status | /game stop (auto-stops when CLI exits)');
2526
+ return ok(outLines.join('\n'), { effect: 'inline' });
2527
+ }
2528
+ },
2529
+
2319
2530
  {
2320
2531
  name: 'openrouter',
2321
2532
  aliases: ['free'],
@@ -3146,47 +3357,60 @@ export const COMMANDS: SlashCommandDefinition[] = [
3146
3357
 
3147
3358
  {
3148
3359
  name: 'mode',
3149
- aliases: ['autonomy'],
3360
+ aliases: ['autonomy', 'permissions', 'permission'],
3150
3361
  scope: 'local',
3151
- usage: '/mode [A | B | C]',
3152
- description: 'View or switch autonomy mode (A: Ask, B: Balanced, C: Autonomous)',
3153
- dialogTitle: 'Autonomy Mode',
3362
+ usage: '/mode [read-only | workspace-write | full-access]',
3363
+ description: 'View or switch permission preset (Read Only, Workspace Write, Full access)',
3364
+ dialogTitle: 'Permission Preset',
3154
3365
  complete: () => [
3155
- { value: 'A', label: 'A', description: 'Ask — review actions before execution' },
3156
- { value: 'B', label: 'B', description: 'Balanced — normal supervised autonomy' },
3157
- { value: 'C', label: 'C', description: 'Autonomous — maximum runway within policy' }
3366
+ { value: 'read-only', label: 'Read Only', description: 'Inspect files and search without modifying workspace files' },
3367
+ { value: 'workspace-write', label: 'Workspace Write', description: 'Edit files inside workspace with approval for risky actions' },
3368
+ { value: 'full-access', label: 'Full access', description: 'Direct workspace edits and commands within safety guardrails' }
3158
3369
  ],
3159
3370
  run: async (argv, ctx = {}) => {
3160
3371
  const config = loadConfig();
3161
- const target = (argv[0] || '').toUpperCase().trim();
3162
- if (!target) {
3372
+ const rawTarget = (argv[0] || '').trim();
3373
+ if (!rawTarget) {
3163
3374
  if (ctx.prompt) {
3164
3375
  const { openModeControl } = await import('./tui/composerControls.js');
3165
3376
  if (ctx.loop) {
3166
3377
  openModeControl(ctx.prompt, ctx.loop);
3167
- return ok('Opened mode selector.', { effect: 'silent' });
3378
+ return ok('Opened permission preset selector.', { effect: 'silent' });
3168
3379
  }
3169
3380
  }
3170
- return ok(`Current autonomy mode: ${config.autonomyMode || 'B'}\nModes:\n A: Ask (confirm gated actions)\n B: Balanced (supervised execution)\n C: Autonomous (independent execution)`);
3381
+ const curPreset = getDefaultPermissionPreset();
3382
+ const curDesc = getPermissionPresetDescriptor(curPreset);
3383
+ return ok(
3384
+ `Current permission preset: ${curDesc.label} (${curPreset})\n`
3385
+ + `Presets:\n`
3386
+ + ` read-only Read Only — inspect and search without workspace writes\n`
3387
+ + ` workspace-write Workspace Write — edits scoped to workspace with approval gates\n`
3388
+ + ` full-access Full access — direct execution within safety guardrails`
3389
+ );
3171
3390
  }
3172
3391
 
3173
- if (!['A', 'B', 'C'].includes(target)) {
3174
- return fail(`Invalid mode "${target}". Choose A, B, or C.`);
3392
+ const preset = normalizePermissionPreset(rawTarget);
3393
+ if (!preset) {
3394
+ return fail(`Invalid permission preset "${rawTarget}". Choose read-only, workspace-write, or full-access.`);
3175
3395
  }
3176
3396
 
3177
- config.autonomyMode = target;
3178
- saveConfig(config);
3179
- if (ctx.loop && typeof ctx.loop.setAutonomyMode === 'function') {
3180
- ctx.loop.setAutonomyMode(target);
3397
+ const desc = getPermissionPresetDescriptor(preset);
3398
+ setDefaultPermissionPreset(preset);
3399
+ config.permissionPreset = preset;
3400
+ config.autonomyMode = desc.autonomyMode;
3401
+ if (ctx.loop && typeof ctx.loop.setPermissionPreset === 'function') {
3402
+ ctx.loop.setPermissionPreset(preset);
3403
+ } else if (ctx.loop && typeof ctx.loop.setAutonomyMode === 'function') {
3404
+ ctx.loop.setAutonomyMode(desc.autonomyMode);
3181
3405
  }
3182
3406
  if (ctx.prompt) {
3183
- ctx.prompt.renderer?.status?.setSession?.({ autonomyMode: target });
3184
- ctx.prompt.surface?.setSessionInfo?.({ autonomyMode: target });
3185
- ctx.prompt.notice = `Mode ${target} active`;
3407
+ ctx.prompt.renderer?.status?.setSession?.({ permissionPreset: preset, autonomyMode: desc.autonomyMode });
3408
+ ctx.prompt.surface?.setSessionInfo?.({ permissionPreset: preset, autonomyMode: desc.autonomyMode });
3409
+ ctx.prompt.notice = `${desc.label} active`;
3186
3410
  if (ctx.prompt.scheduleDraw) ctx.prompt.scheduleDraw();
3187
- return ok(`Autonomy mode switched to ${target}.`, { effect: 'inline' });
3411
+ return ok(`Permission preset switched to ${desc.label} (${preset}).`, { effect: 'inline' });
3188
3412
  }
3189
- return ok(`Autonomy mode switched to ${target}.`);
3413
+ return ok(`Permission preset switched to ${desc.label} (${preset}).`);
3190
3414
  }
3191
3415
  },
3192
3416
 
@@ -3666,7 +3890,7 @@ export const COMMANDS: SlashCommandDefinition[] = [
3666
3890
  name: 'rules',
3667
3891
  scope: 'local',
3668
3892
  usage: '/rules',
3669
- description: 'Show hierarchical project instructions loaded from CAUSYNE.md, AGENTS.md, CLAUDE.md, and .causyne/rules/',
3893
+ description: 'Show hierarchical project instructions loaded from .causyne/personalization.md, CAUSYNE.md, AGENTS.md, CLAUDE.md, and .causyne/rules/',
3670
3894
  dialogTitle: 'Project Rules',
3671
3895
  run: async (_argv, ctx = {}) => {
3672
3896
  const ws = ctx.loop?.workspaceRoot || process.cwd();
@@ -3674,6 +3898,140 @@ export const COMMANDS: SlashCommandDefinition[] = [
3674
3898
  }
3675
3899
  },
3676
3900
 
3901
+ {
3902
+ name: 'personalization',
3903
+ aliases: ['persona', 'instructions'],
3904
+ scope: 'local',
3905
+ usage: '/personalization [show | set <text> | append <text> | global <text> | clear [project|global] | memory on|off [global] | tool-memory on|off [global] | forget [project|all]]',
3906
+ description: 'Manage per-project personalization instructions (.causyne/personalization.md), global instructions, and Causyne memory controls',
3907
+ dialogTitle: 'Personalization',
3908
+ complete: () => [
3909
+ { value: 'show', label: 'show', description: 'inspect project & global personalization and memory controls' },
3910
+ { value: 'set ', label: 'set <text>', description: 'save per-project personalization (.causyne/personalization.md)' },
3911
+ { value: 'append ', label: 'append <text>', description: 'append a directive to this project personalization' },
3912
+ { value: 'global ', label: 'global <text>', description: 'save global instructions (~/.causyne/CAUSYNE.md)' },
3913
+ { value: 'clear project', label: 'clear project', description: 'clear this project personalization' },
3914
+ { value: 'clear global', label: 'clear global', description: 'clear global instructions' },
3915
+ { value: 'memory on', label: 'memory on', description: 'enable Causyne memories for this project' },
3916
+ { value: 'memory off', label: 'memory off', description: 'disable Causyne memories for this project' },
3917
+ { value: 'tool-memory on', label: 'tool-memory on', description: 'allow memories from MCP/web tool-assisted chats' },
3918
+ { value: 'tool-memory off', label: 'tool-memory off', description: 'disable memories from MCP/web tool-assisted chats' },
3919
+ { value: 'forget project', label: 'forget project', description: 'delete stored memories for this project' },
3920
+ { value: 'forget all', label: 'forget all', description: 'delete all Causyne memories on this device' }
3921
+ ],
3922
+ run: async (argv, ctx = {}) => {
3923
+ const ws = ctx.loop?.workspaceRoot || process.cwd();
3924
+ const sub = String(argv[0] || 'show').toLowerCase();
3925
+
3926
+ const invalidateLoop = (): void => {
3927
+ if (ctx.loop && 'staticContext' in ctx.loop) {
3928
+ (ctx.loop as any).staticContext = null;
3929
+ }
3930
+ };
3931
+
3932
+ const renderOverview = (): string => {
3933
+ const info = readPersonalizationOverview(ws);
3934
+ const lines = [
3935
+ 'Causyne Personalization & Memory',
3936
+ ` Workspace : ${safeDisplay(info.workspaceRoot)}`,
3937
+ ` Project file : ${info.project.displayPath} (${info.project.exists ? `${info.project.bytes} bytes` : 'not set'})`,
3938
+ ` Global file : ${info.global.displayPath} (${info.global.exists ? `${info.global.bytes} bytes` : 'not set'})`,
3939
+ ` Memories : ${info.memory.enabled ? 'enabled' : 'disabled'} (source: ${info.memory.source})`,
3940
+ ` Tool-assisted mem : ${info.memory.allowToolAssisted ? 'allowed' : 'blocked'} (MCP/web chats)`,
3941
+ ` Stored memories : ${info.memoryStats.projectFacts} project facts (${info.memoryStats.totalFacts} total), ${info.memoryStats.projectObservations} project observations (${info.memoryStats.totalObservations} total)`
3942
+ ];
3943
+ if (info.project.content.trim()) {
3944
+ lines.push('', 'Project Personalization (.causyne/personalization.md):', info.project.content.trim());
3945
+ }
3946
+ if (info.global.content.trim()) {
3947
+ lines.push('', 'Global Instructions (~/.causyne/CAUSYNE.md):', info.global.content.trim());
3948
+ }
3949
+ if (info.activeRules.length > 0) {
3950
+ lines.push('', `Active Instruction Files (${info.activeRules.length}):`);
3951
+ for (const r of info.activeRules) {
3952
+ lines.push(` • [${r.scope}] ${safeDisplay(r.label)} (${r.bytes} bytes)`);
3953
+ }
3954
+ }
3955
+ lines.push(
3956
+ '',
3957
+ 'Usage: /personalization set <text> | append <text> | global <text> | clear [project|global] | memory on|off [global] | tool-memory on|off [global] | forget [project|all]'
3958
+ );
3959
+ return lines.join('\n');
3960
+ };
3961
+
3962
+ try {
3963
+ if (sub === 'show' || sub === 'status') {
3964
+ return ok(renderOverview());
3965
+ }
3966
+ if (sub === 'set') {
3967
+ const text = argv.slice(1).join(' ').trim();
3968
+ if (!text) return fail('Usage: /personalization set <project instructions>');
3969
+ const doc = savePersonalizationInstructions(ws, 'project', text);
3970
+ invalidateLoop();
3971
+ return ok(`Saved project personalization to ${doc.displayPath} (${doc.bytes} bytes). Active immediately for this workspace.`);
3972
+ }
3973
+ if (sub === 'append') {
3974
+ const text = argv.slice(1).join(' ').trim();
3975
+ if (!text) return fail('Usage: /personalization append <additional project instruction>');
3976
+ const existing = readPersonalizationOverview(ws).project.content.trim();
3977
+ const combined = existing ? `${existing}\n\n${text}` : text;
3978
+ const doc = savePersonalizationInstructions(ws, 'project', combined);
3979
+ invalidateLoop();
3980
+ return ok(`Updated project personalization at ${doc.displayPath} (${doc.bytes} bytes). Active immediately for this workspace.`);
3981
+ }
3982
+ if (sub === 'global') {
3983
+ const text = argv.slice(1).join(' ').trim();
3984
+ if (!text) return fail('Usage: /personalization global <global instructions>');
3985
+ const doc = savePersonalizationInstructions(ws, 'global', text);
3986
+ invalidateLoop();
3987
+ return ok(`Saved global instructions to ${doc.displayPath} (${doc.bytes} bytes).`);
3988
+ }
3989
+ if (sub === 'clear') {
3990
+ const scopeArg = String(argv[1] || 'project').toLowerCase();
3991
+ if (scopeArg !== 'project' && scopeArg !== 'global') {
3992
+ return fail('Usage: /personalization clear [project|global]');
3993
+ }
3994
+ savePersonalizationInstructions(ws, scopeArg, '');
3995
+ invalidateLoop();
3996
+ return ok(`Cleared ${scopeArg} personalization instructions.`);
3997
+ }
3998
+ if (sub === 'memory') {
3999
+ const toggle = String(argv[1] || '').toLowerCase();
4000
+ const scopeArg = String(argv[2] || 'project').toLowerCase() === 'global' ? 'global' : 'project';
4001
+ if (toggle !== 'on' && toggle !== 'off' && toggle !== 'inherit') {
4002
+ return fail('Usage: /personalization memory on|off|inherit [project|global]');
4003
+ }
4004
+ const value = toggle === 'inherit' ? null : toggle === 'on';
4005
+ const policy = saveMemoryPreferences(ws, scopeArg, { enabled: value });
4006
+ invalidateLoop();
4007
+ return ok(`Causyne memories (${scopeArg}): ${policy.enabled ? 'enabled' : 'disabled'} (effective source: ${policy.source}).`);
4008
+ }
4009
+ if (sub === 'tool-memory' || sub === 'tool-assisted') {
4010
+ const toggle = String(argv[1] || '').toLowerCase();
4011
+ const scopeArg = String(argv[2] || 'project').toLowerCase() === 'global' ? 'global' : 'project';
4012
+ if (toggle !== 'on' && toggle !== 'off' && toggle !== 'inherit') {
4013
+ return fail('Usage: /personalization tool-memory on|off|inherit [project|global]');
4014
+ }
4015
+ const value = toggle === 'inherit' ? null : toggle === 'on';
4016
+ const policy = saveMemoryPreferences(ws, scopeArg, { allowToolAssisted: value });
4017
+ invalidateLoop();
4018
+ return ok(`Tool-assisted chat memories (${scopeArg}): ${policy.allowToolAssisted ? 'allowed' : 'blocked'} (effective source: ${policy.source}).`);
4019
+ }
4020
+ if (sub === 'forget' || sub === 'delete') {
4021
+ const scopeArg = String(argv[1] || 'project').toLowerCase() === 'all' ? 'all' : 'project';
4022
+ const deleted = deleteCausyneMemories(ws, scopeArg);
4023
+ invalidateLoop();
4024
+ return ok(
4025
+ `Deleted Causyne memories (${scopeArg}): ${deleted.factsRemoved} facts, ${deleted.observationsRemoved} observations, ${deleted.summariesRemoved} summaries removed.`
4026
+ );
4027
+ }
4028
+ return fail(`Unknown /personalization action "${safeDisplay(sub)}". Try: show, set, append, global, clear, memory, tool-memory, forget.`);
4029
+ } catch (err) {
4030
+ return fail(safeDisplay(errMsg(err)));
4031
+ }
4032
+ }
4033
+ },
4034
+
3677
4035
  {
3678
4036
  name: 'map',
3679
4037
  aliases: ['repomap'],
package/src/config.js CHANGED
@@ -5,6 +5,7 @@ import { canonicalModelId } from './modelIds.js';
5
5
  import { DEFAULT_MODEL_BY_PROVIDER } from './modelCatalogue.js';
6
6
  import { causyneHome } from './utils/paths.js';
7
7
  import { listLocalOllamaDiskModels, pickPreferredLocalOllamaModel } from './zeroCostRouting.js';
8
+ import { autonomyModeToPreset, normalizePermissionPreset } from './permissionPresets.js';
8
9
  import { ensureVaultDir, atomicWriteSecretFileSync, encryptVaultSecret, decryptVaultSecret, isEncryptedVaultSecret } from './configVault.js';
9
10
  const MAX_CONFIG_BYTES = 2 * 1024 * 1024;
10
11
  const FORBIDDEN_CONFIG_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
@@ -56,15 +57,19 @@ export function resolveProviderApiKey(config, targetProvider) {
56
57
  return '';
57
58
  }
58
59
  export function applyProviderOverrides(config, providerOverride, modelOverride) {
60
+ const prevProvider = typeof config.provider === 'string' ? config.provider.trim().toLowerCase() : '';
61
+ const prevModel = typeof config.model === 'string' ? config.model.trim() : '';
59
62
  const nextProvider = typeof providerOverride === 'string' ? providerOverride.trim() : '';
60
63
  const nextModel = typeof modelOverride === 'string' ? modelOverride.trim() : '';
64
+ let changed = false;
61
65
  if (nextProvider) {
62
- const prevNorm = typeof config.provider === 'string' ? config.provider.trim().toLowerCase() : '';
63
66
  const nextNorm = nextProvider.toLowerCase();
64
- const prevAliases = prevNorm
65
- ? (Object.hasOwn(PROVIDER_KEY_ALIASES, prevNorm) ? PROVIDER_KEY_ALIASES[prevNorm] : [prevNorm])
67
+ const prevAliases = prevProvider
68
+ ? (Object.hasOwn(PROVIDER_KEY_ALIASES, prevProvider) ? PROVIDER_KEY_ALIASES[prevProvider] : [prevProvider])
66
69
  : [];
67
- const sameFamily = Boolean(prevNorm && (prevNorm === nextNorm || prevAliases.includes(nextNorm)));
70
+ const sameFamily = Boolean(prevProvider && (prevProvider === nextNorm || prevAliases.includes(nextNorm)));
71
+ if (prevProvider !== nextNorm)
72
+ changed = true;
68
73
  config.apiKey = resolveProviderApiKey(config, nextProvider);
69
74
  config.provider = nextProvider;
70
75
  if (!sameFamily && !nextModel) {
@@ -72,8 +77,14 @@ export function applyProviderOverrides(config, providerOverride, modelOverride)
72
77
  }
73
78
  }
74
79
  if (nextModel) {
80
+ if (prevModel !== nextModel)
81
+ changed = true;
75
82
  config.model = nextModel;
76
83
  }
84
+ if (changed) {
85
+ delete config.reasoningEffort;
86
+ delete config.reasoningBudgetTokens;
87
+ }
77
88
  return config;
78
89
  }
79
90
  function configDir() {
@@ -182,6 +193,9 @@ export function loadConfig() {
182
193
  saveConfig(parsed);
183
194
  }
184
195
  }
196
+ if (!normalizePermissionPreset(parsed.permissionPreset) && parsed.autonomyMode) {
197
+ parsed.permissionPreset = autonomyModeToPreset(parsed.autonomyMode);
198
+ }
185
199
  return parsed;
186
200
  }
187
201
  catch (e) {
@@ -193,6 +207,7 @@ export function loadConfig() {
193
207
  provider: envDetected ? envDetected.provider : '',
194
208
  model: envDetected ? envDetected.model : '',
195
209
  apiKey: envDetected ? envDetected.apiKey : '',
210
+ permissionPreset: 'workspace-write',
196
211
  autonomyMode: 'B',
197
212
  tokenBudget: {
198
213
  enabled: false,