@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
@@ -754,13 +754,40 @@ export class CausyneBrowser {
754
754
  getWorkspace() {
755
755
  return this.workspace;
756
756
  }
757
- async enqueueOperation(operation) {
757
+ async enqueueOperation(operation, signal) {
758
+ if (signal?.aborted) {
759
+ throw new Error('Browser operation aborted.');
760
+ }
758
761
  this.queuedOperations++;
759
762
  const previous = this.operationTail;
760
763
  let release;
761
764
  this.operationTail = new Promise(resolve => { release = resolve; });
762
- await previous;
763
765
  try {
766
+ if (signal) {
767
+ await new Promise((resolve, reject) => {
768
+ const onAbort = () => {
769
+ reject(new Error('Browser operation aborted while waiting in queue.'));
770
+ };
771
+ if (signal.aborted) {
772
+ onAbort();
773
+ return;
774
+ }
775
+ signal.addEventListener('abort', onAbort, { once: true });
776
+ previous.then(() => {
777
+ signal.removeEventListener('abort', onAbort);
778
+ resolve();
779
+ }, () => {
780
+ signal.removeEventListener('abort', onAbort);
781
+ resolve();
782
+ });
783
+ });
784
+ }
785
+ else {
786
+ await previous;
787
+ }
788
+ if (signal?.aborted) {
789
+ throw new Error('Browser operation aborted.');
790
+ }
764
791
  return await operation();
765
792
  }
766
793
  finally {
@@ -769,7 +796,7 @@ export class CausyneBrowser {
769
796
  }
770
797
  }
771
798
  async run(actions, options = {}) {
772
- return this.enqueueOperation(() => this.runUnlocked(actions, options));
799
+ return this.enqueueOperation(() => this.runUnlocked(actions, options), options.signal);
773
800
  }
774
801
  async runUnlocked(actions, options = {}) {
775
802
  if (!Array.isArray(actions) || actions.length === 0 || actions.length > 40) {
@@ -1461,6 +1488,37 @@ export class CausyneBrowser {
1461
1488
  async captureLiveFrame(options = {}) {
1462
1489
  return this.enqueueOperation(() => this.captureLiveFrameUnlocked(options));
1463
1490
  }
1491
+ async closeLiveSession() {
1492
+ return this.enqueueOperation(async () => {
1493
+ await this.close();
1494
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1495
+ });
1496
+ }
1497
+ async closeLiveTab(tabId) {
1498
+ return this.enqueueOperation(async () => {
1499
+ if (!this.isSessionHealthy()) {
1500
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1501
+ }
1502
+ const target = this.tabs.get(tabId);
1503
+ if (target) {
1504
+ if (!target.page.isClosed()) {
1505
+ await target.page.close().catch(() => { });
1506
+ }
1507
+ this.tabs.delete(tabId);
1508
+ if (this.activeTabId === tabId)
1509
+ this.activeTabId = null;
1510
+ }
1511
+ const liveTabs = [...this.tabs.values()].filter((t) => !t.page.isClosed() && !t.crashed);
1512
+ if (liveTabs.length === 0) {
1513
+ await this.close();
1514
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1515
+ }
1516
+ if (!this.activeTabId || !this.tabs.has(this.activeTabId)) {
1517
+ this.activeTabId = liveTabs[liveTabs.length - 1].id;
1518
+ }
1519
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1520
+ });
1521
+ }
1464
1522
  async captureLiveFrameUnlocked(options = {}) {
1465
1523
  const status = this.getRuntimeStatus();
1466
1524
  if (!this.isSessionHealthy()) {
@@ -644,6 +644,7 @@ export interface BrowserActionResult {
644
644
 
645
645
  export interface BrowserRunOptions {
646
646
  workspace?: string;
647
+ signal?: AbortSignal | undefined;
647
648
  }
648
649
 
649
650
  interface RuntimeOptions {
@@ -1166,13 +1167,42 @@ export class CausyneBrowser {
1166
1167
  return this.workspace;
1167
1168
  }
1168
1169
 
1169
- private async enqueueOperation<T>(operation: () => Promise<T>): Promise<T> {
1170
+ private async enqueueOperation<T>(operation: () => Promise<T>, signal?: AbortSignal): Promise<T> {
1171
+ if (signal?.aborted) {
1172
+ throw new Error('Browser operation aborted.');
1173
+ }
1170
1174
  this.queuedOperations++;
1171
1175
  const previous = this.operationTail;
1172
1176
  let release!: () => void;
1173
1177
  this.operationTail = new Promise<void>(resolve => { release = resolve; });
1174
- await previous;
1175
1178
  try {
1179
+ if (signal) {
1180
+ await new Promise<void>((resolve, reject) => {
1181
+ const onAbort = (): void => {
1182
+ reject(new Error('Browser operation aborted while waiting in queue.'));
1183
+ };
1184
+ if (signal.aborted) {
1185
+ onAbort();
1186
+ return;
1187
+ }
1188
+ signal.addEventListener('abort', onAbort, { once: true });
1189
+ previous.then(
1190
+ () => {
1191
+ signal.removeEventListener('abort', onAbort);
1192
+ resolve();
1193
+ },
1194
+ () => {
1195
+ signal.removeEventListener('abort', onAbort);
1196
+ resolve();
1197
+ }
1198
+ );
1199
+ });
1200
+ } else {
1201
+ await previous;
1202
+ }
1203
+ if (signal?.aborted) {
1204
+ throw new Error('Browser operation aborted.');
1205
+ }
1176
1206
  return await operation();
1177
1207
  } finally {
1178
1208
  this.queuedOperations--;
@@ -1181,7 +1211,7 @@ export class CausyneBrowser {
1181
1211
  }
1182
1212
 
1183
1213
  async run(actions: BrowserAction[], options: BrowserRunOptions = {}): Promise<BrowserActionResult[]> {
1184
- return this.enqueueOperation(() => this.runUnlocked(actions, options));
1214
+ return this.enqueueOperation(() => this.runUnlocked(actions, options), options.signal);
1185
1215
  }
1186
1216
 
1187
1217
  private async runUnlocked(actions: BrowserAction[], options: BrowserRunOptions = {}): Promise<BrowserActionResult[]> {
@@ -1883,6 +1913,38 @@ export class CausyneBrowser {
1883
1913
  return this.enqueueOperation(() => this.captureLiveFrameUnlocked(options));
1884
1914
  }
1885
1915
 
1916
+ async closeLiveSession(): Promise<LiveBrowserFrame> {
1917
+ return this.enqueueOperation(async () => {
1918
+ await this.close();
1919
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1920
+ });
1921
+ }
1922
+
1923
+ async closeLiveTab(tabId: string): Promise<LiveBrowserFrame> {
1924
+ return this.enqueueOperation(async () => {
1925
+ if (!this.isSessionHealthy()) {
1926
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1927
+ }
1928
+ const target = this.tabs.get(tabId);
1929
+ if (target) {
1930
+ if (!target.page.isClosed()) {
1931
+ await target.page.close().catch(() => {});
1932
+ }
1933
+ this.tabs.delete(tabId);
1934
+ if (this.activeTabId === tabId) this.activeTabId = null;
1935
+ }
1936
+ const liveTabs = [...this.tabs.values()].filter((t) => !t.page.isClosed() && !t.crashed);
1937
+ if (liveTabs.length === 0) {
1938
+ await this.close();
1939
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1940
+ }
1941
+ if (!this.activeTabId || !this.tabs.has(this.activeTabId)) {
1942
+ this.activeTabId = liveTabs[liveTabs.length - 1]!.id;
1943
+ }
1944
+ return this.captureLiveFrameUnlocked({ ensureStarted: false });
1945
+ });
1946
+ }
1947
+
1886
1948
  private async captureLiveFrameUnlocked(options: { ensureStarted?: boolean | undefined } = {}): Promise<LiveBrowserFrame> {
1887
1949
  const status = this.getRuntimeStatus();
1888
1950
  if (!this.isSessionHealthy()) {
@@ -1,6 +1,7 @@
1
1
  import { lookup } from 'node:dns/promises';
2
2
  import { isIP } from 'node:net';
3
3
  const DNS_CACHE_MS = 5 * 60_000;
4
+ const MAX_DNS_CACHE_ENTRIES = 512;
4
5
  const hostCache = new Map();
5
6
  function isPrivateIpv4(address) {
6
7
  const parts = address.split('.').map(Number);
@@ -75,7 +76,19 @@ async function resolvedAddresses(hostname) {
75
76
  return cached.addresses;
76
77
  const results = await lookup(hostname, { all: true, verbatim: true });
77
78
  const addresses = [...new Set(results.map(result => result.address))];
78
- hostCache.set(hostname, { expiresAt: Date.now() + DNS_CACHE_MS, addresses });
79
+ const now = Date.now();
80
+ for (const [key, value] of hostCache) {
81
+ if (value.expiresAt <= now)
82
+ hostCache.delete(key);
83
+ }
84
+ hostCache.delete(hostname);
85
+ while (hostCache.size >= MAX_DNS_CACHE_ENTRIES) {
86
+ const oldest = hostCache.keys().next();
87
+ if (oldest.done)
88
+ break;
89
+ hostCache.delete(oldest.value);
90
+ }
91
+ hostCache.set(hostname, { expiresAt: now + DNS_CACHE_MS, addresses });
79
92
  return addresses;
80
93
  }
81
94
  export function isLoopbackHost(hostname) {
@@ -2,6 +2,7 @@ import { lookup } from 'node:dns/promises';
2
2
  import { isIP } from 'node:net';
3
3
 
4
4
  const DNS_CACHE_MS = 5 * 60_000;
5
+ const MAX_DNS_CACHE_ENTRIES = 512;
5
6
  const hostCache = new Map<string, { expiresAt: number; addresses: string[] }>();
6
7
 
7
8
  function isPrivateIpv4(address: string): boolean {
@@ -72,7 +73,17 @@ async function resolvedAddresses(hostname: string): Promise<string[]> {
72
73
  if (cached && cached.expiresAt > Date.now()) return cached.addresses;
73
74
  const results = await lookup(hostname, { all: true, verbatim: true });
74
75
  const addresses = [...new Set(results.map(result => result.address))];
75
- hostCache.set(hostname, { expiresAt: Date.now() + DNS_CACHE_MS, addresses });
76
+ const now = Date.now();
77
+ for (const [key, value] of hostCache) {
78
+ if (value.expiresAt <= now) hostCache.delete(key);
79
+ }
80
+ hostCache.delete(hostname);
81
+ while (hostCache.size >= MAX_DNS_CACHE_ENTRIES) {
82
+ const oldest = hostCache.keys().next();
83
+ if (oldest.done) break;
84
+ hostCache.delete(oldest.value);
85
+ }
86
+ hostCache.set(hostname, { expiresAt: now + DNS_CACHE_MS, addresses });
76
87
  return addresses;
77
88
  }
78
89
 
package/src/cliMode.js CHANGED
@@ -25,7 +25,9 @@ import { auditLog } from './auditLog.js';
25
25
  import { isAcpProvider } from './providers/acp.js';
26
26
  import { isPiProvider } from './providers/pi.js';
27
27
  import { isAntigravityProvider } from './providers/antigravity.js';
28
- import { runHeadlessTask, parsePermissionMode, parseMaxTurns, parseVariantOption } from './headlessCli.js';
28
+ import { runHeadlessTask, parsePermissionPreset, parseMaxTurns, parseVariantOption } from './headlessCli.js';
29
+ import { resolveConfigPermissionPreset } from './permissionPresets.js';
30
+ import { reconcileConfigVariant } from './modelVariants.js';
29
31
  import { closeAll as closeAllMcpServers, setActiveWorkspace as setActiveMcpWorkspace } from './mcp/mcpRegistry.js';
30
32
  import { lspSessionManager } from './lsp/lspClient.js';
31
33
  import { backgroundTaskManager } from './backgroundTasks.js';
@@ -242,9 +244,9 @@ export async function runTask(task, options = {}) {
242
244
  if (parsedVariant)
243
245
  loopOptions.variant = parsedVariant;
244
246
  const loop = new AgentLoop(conn, taskId, task, loopOptions);
245
- const permMode = parsePermissionMode(options?.permissionMode);
246
- if (permMode)
247
- loop.autonomyOverride = permMode;
247
+ const permPreset = parsePermissionPreset(options?.permissionMode);
248
+ if (permPreset)
249
+ loop.setPermissionPreset(permPreset);
248
250
  const maxTurns = parseMaxTurns(options?.maxTurns);
249
251
  if (maxTurns !== undefined)
250
252
  loop.maxStepsCeiling = maxTurns;
@@ -301,17 +303,27 @@ export async function chatMode(options) {
301
303
  if (parsedVariant)
302
304
  loopOptions.variant = parsedVariant;
303
305
  let loop = new AgentLoop(conn, taskId, null, loopOptions);
304
- const permMode = parsePermissionMode(options?.permissionMode);
305
- if (permMode) {
306
- loop.autonomyOverride = permMode;
306
+ const permPreset = parsePermissionPreset(options?.permissionMode);
307
+ if (permPreset) {
308
+ loop.setPermissionPreset(permPreset);
307
309
  loop.updateTierLimits();
308
310
  }
309
311
  const config = loop.config || loadConfig();
312
+ const prevSavedEffort = typeof config.reasoningEffort === 'string' ? config.reasoningEffort : '';
313
+ const reconciledVariant = reconcileConfigVariant(config);
314
+ if (prevSavedEffort && reconciledVariant !== prevSavedEffort && !options?.variant) {
315
+ const persisted = loadConfig();
316
+ reconcileConfigVariant(persisted);
317
+ saveConfig(persisted);
318
+ loop.updateTierLimits?.();
319
+ }
320
+ const activePreset = resolveConfigPermissionPreset(config);
310
321
  const headerInfo = {
311
322
  version: `v${getPackageVersion()}`,
312
323
  provider: config.provider,
313
324
  model: config.model,
314
- variant: typeof config.reasoningEffort === 'string' ? config.reasoningEffort : '',
325
+ variant: reconciledVariant,
326
+ permissionPreset: activePreset,
315
327
  autonomyMode: config.autonomyMode,
316
328
  tier: config.tier,
317
329
  workspace: loop.sandbox && loop.sandbox.grantAllAccess
@@ -370,7 +382,7 @@ export async function chatMode(options) {
370
382
  surface,
371
383
  messageActionLoop: loop,
372
384
  onInterrupt: () => loop.abort(),
373
- getMode: () => loop.config?.autonomyMode || config.autonomyMode || 'B',
385
+ getMode: () => resolveConfigPermissionPreset(loop.config || config),
374
386
  onOpenMode: async () => {
375
387
  await openModeControl(prompt, loop);
376
388
  prompt?.refreshPinnedPanels?.(loop);
package/src/cliMode.ts CHANGED
@@ -25,7 +25,9 @@ import { auditLog } from './auditLog.js';
25
25
  import { isAcpProvider } from './providers/acp.js';
26
26
  import { isPiProvider } from './providers/pi.js';
27
27
  import { isAntigravityProvider } from './providers/antigravity.js';
28
- import { runHeadlessTask, parsePermissionMode, parseMaxTurns, parseVariantOption } from './headlessCli.js';
28
+ import { runHeadlessTask, parsePermissionPreset, parseMaxTurns, parseVariantOption } from './headlessCli.js';
29
+ import { resolveConfigPermissionPreset } from './permissionPresets.js';
30
+ import { reconcileConfigVariant } from './modelVariants.js';
29
31
  import { closeAll as closeAllMcpServers, setActiveWorkspace as setActiveMcpWorkspace } from './mcp/mcpRegistry.js';
30
32
  import { lspSessionManager } from './lsp/lspClient.js';
31
33
  import { backgroundTaskManager } from './backgroundTasks.js';
@@ -272,8 +274,8 @@ export async function runTask(task: string, options: RunTaskOptions = {}): Promi
272
274
  if (parsedVariant) loopOptions.variant = parsedVariant;
273
275
  const loop = new AgentLoop(conn, taskId, task, loopOptions);
274
276
 
275
- const permMode = parsePermissionMode(options?.permissionMode);
276
- if (permMode) loop.autonomyOverride = permMode;
277
+ const permPreset = parsePermissionPreset(options?.permissionMode);
278
+ if (permPreset) loop.setPermissionPreset(permPreset);
277
279
  const maxTurns = parseMaxTurns(options?.maxTurns);
278
280
  if (maxTurns !== undefined) loop.maxStepsCeiling = maxTurns;
279
281
 
@@ -329,18 +331,28 @@ export async function chatMode(options?: ChatModeOptions | null): Promise<void>
329
331
  const parsedVariant = parseVariantOption(options?.variant);
330
332
  if (parsedVariant) loopOptions.variant = parsedVariant;
331
333
  let loop: any = new AgentLoop(conn, taskId, null, loopOptions);
332
- const permMode = parsePermissionMode(options?.permissionMode);
333
- if (permMode) {
334
- loop.autonomyOverride = permMode;
334
+ const permPreset = parsePermissionPreset(options?.permissionMode);
335
+ if (permPreset) {
336
+ loop.setPermissionPreset(permPreset);
335
337
  loop.updateTierLimits();
336
338
  }
337
339
 
338
340
  const config = loop.config || loadConfig();
341
+ const prevSavedEffort = typeof config.reasoningEffort === 'string' ? config.reasoningEffort : '';
342
+ const reconciledVariant = reconcileConfigVariant(config);
343
+ if (prevSavedEffort && reconciledVariant !== prevSavedEffort && !options?.variant) {
344
+ const persisted = loadConfig();
345
+ reconcileConfigVariant(persisted);
346
+ saveConfig(persisted);
347
+ loop.updateTierLimits?.();
348
+ }
349
+ const activePreset = resolveConfigPermissionPreset(config);
339
350
  const headerInfo: Record<string, any> = {
340
351
  version: `v${getPackageVersion()}`,
341
352
  provider: config.provider,
342
353
  model: config.model,
343
- variant: typeof config.reasoningEffort === 'string' ? config.reasoningEffort : '',
354
+ variant: reconciledVariant,
355
+ permissionPreset: activePreset,
344
356
  autonomyMode: config.autonomyMode,
345
357
  tier: config.tier,
346
358
  workspace: loop.sandbox && loop.sandbox.grantAllAccess
@@ -401,7 +413,7 @@ export async function chatMode(options?: ChatModeOptions | null): Promise<void>
401
413
  surface,
402
414
  messageActionLoop: loop,
403
415
  onInterrupt: () => loop.abort(),
404
- getMode: () => loop.config?.autonomyMode || config.autonomyMode || 'B',
416
+ getMode: () => resolveConfigPermissionPreset(loop.config || config),
405
417
  onOpenMode: async () => {
406
418
  await openModeControl(prompt, loop);
407
419
  prompt?.refreshPinnedPanels?.(loop);