wave-agent-sdk 0.16.9 → 0.16.12

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 (85) hide show
  1. package/dist/agent.d.ts +5 -0
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +18 -0
  4. package/dist/constants/toolLimits.d.ts +2 -0
  5. package/dist/constants/toolLimits.d.ts.map +1 -1
  6. package/dist/constants/toolLimits.js +2 -0
  7. package/dist/managers/aiManager.d.ts +5 -0
  8. package/dist/managers/aiManager.d.ts.map +1 -1
  9. package/dist/managers/aiManager.js +21 -0
  10. package/dist/managers/hookManager.d.ts +6 -3
  11. package/dist/managers/hookManager.d.ts.map +1 -1
  12. package/dist/managers/hookManager.js +36 -13
  13. package/dist/managers/mcpManager.d.ts +4 -28
  14. package/dist/managers/mcpManager.d.ts.map +1 -1
  15. package/dist/managers/mcpManager.js +10 -127
  16. package/dist/services/authService.d.ts +33 -1
  17. package/dist/services/authService.d.ts.map +1 -1
  18. package/dist/services/authService.js +212 -11
  19. package/dist/services/configurationService.d.ts +1 -0
  20. package/dist/services/configurationService.d.ts.map +1 -1
  21. package/dist/services/configurationService.js +48 -6
  22. package/dist/services/hook.d.ts +4 -0
  23. package/dist/services/hook.d.ts.map +1 -1
  24. package/dist/services/hook.js +10 -0
  25. package/dist/services/initializationService.d.ts.map +1 -1
  26. package/dist/services/initializationService.js +11 -0
  27. package/dist/services/interactionService.d.ts.map +1 -1
  28. package/dist/services/interactionService.js +0 -12
  29. package/dist/services/remoteSettingsService.d.ts +21 -0
  30. package/dist/services/remoteSettingsService.d.ts.map +1 -0
  31. package/dist/services/remoteSettingsService.js +280 -0
  32. package/dist/tools/bashTool.d.ts.map +1 -1
  33. package/dist/tools/bashTool.js +58 -32
  34. package/dist/tools/types.d.ts +4 -0
  35. package/dist/tools/types.d.ts.map +1 -1
  36. package/dist/types/agent.d.ts +7 -0
  37. package/dist/types/agent.d.ts.map +1 -1
  38. package/dist/types/auth.d.ts +12 -0
  39. package/dist/types/auth.d.ts.map +1 -1
  40. package/dist/types/configuration.d.ts +20 -0
  41. package/dist/types/configuration.d.ts.map +1 -1
  42. package/dist/types/hooks.d.ts +5 -1
  43. package/dist/types/hooks.d.ts.map +1 -1
  44. package/dist/types/hooks.js +1 -0
  45. package/dist/types/mcp.d.ts +1 -1
  46. package/dist/types/mcp.d.ts.map +1 -1
  47. package/dist/utils/containerSetup.d.ts.map +1 -1
  48. package/dist/utils/containerSetup.js +9 -8
  49. package/dist/utils/gitUtils.d.ts +18 -1
  50. package/dist/utils/gitUtils.d.ts.map +1 -1
  51. package/dist/utils/gitUtils.js +120 -49
  52. package/dist/utils/mcpUtils.d.ts.map +1 -1
  53. package/dist/utils/mcpUtils.js +6 -1
  54. package/dist/utils/openaiClient.d.ts.map +1 -1
  55. package/dist/utils/openaiClient.js +4 -2
  56. package/dist/utils/toolResultStorage.d.ts +46 -0
  57. package/dist/utils/toolResultStorage.d.ts.map +1 -0
  58. package/dist/utils/toolResultStorage.js +90 -0
  59. package/dist/utils/worktreeUtils.d.ts.map +1 -1
  60. package/dist/utils/worktreeUtils.js +58 -0
  61. package/package.json +3 -3
  62. package/src/agent.ts +20 -0
  63. package/src/constants/toolLimits.ts +3 -0
  64. package/src/managers/aiManager.ts +37 -0
  65. package/src/managers/hookManager.ts +42 -17
  66. package/src/managers/mcpManager.ts +10 -178
  67. package/src/services/authService.ts +243 -16
  68. package/src/services/configurationService.ts +58 -6
  69. package/src/services/hook.ts +15 -0
  70. package/src/services/initializationService.ts +13 -0
  71. package/src/services/interactionService.ts +0 -18
  72. package/src/services/remoteSettingsService.ts +315 -0
  73. package/src/tools/bashTool.ts +70 -38
  74. package/src/tools/types.ts +4 -0
  75. package/src/types/agent.ts +7 -0
  76. package/src/types/auth.ts +10 -0
  77. package/src/types/configuration.ts +23 -0
  78. package/src/types/hooks.ts +7 -1
  79. package/src/types/mcp.ts +1 -1
  80. package/src/utils/containerSetup.ts +8 -8
  81. package/src/utils/gitUtils.ts +123 -48
  82. package/src/utils/mcpUtils.ts +12 -1
  83. package/src/utils/openaiClient.ts +5 -2
  84. package/src/utils/toolResultStorage.ts +117 -0
  85. package/src/utils/worktreeUtils.ts +63 -0
@@ -12,6 +12,7 @@ import {
12
12
  chmodSync,
13
13
  rmSync,
14
14
  mkdirSync,
15
+ statSync,
15
16
  } from "fs";
16
17
  import * as path from "path";
17
18
  import * as os from "os";
@@ -20,7 +21,8 @@ import { createServer, Server } from "http";
20
21
  import { URL } from "url";
21
22
  import { execFile } from "child_process";
22
23
  import { promisify } from "util";
23
- import type { AuthConfig, AuthUser } from "../types/auth.js";
24
+ import type { AuthConfig, AuthUser, TokenResponse } from "../types/auth.js";
25
+ import { logger } from "../utils/globalLogger.js";
24
26
 
25
27
  /** Persistent anonymous ID for telemetry fallback when SSO is not authenticated. */
26
28
  let _anonymousId: string | undefined;
@@ -32,6 +34,9 @@ export class AuthService {
32
34
  private _serverUrl: string | undefined;
33
35
  private onAuthChangeCallbacks: Array<(event: "login" | "logout") => void> =
34
36
  [];
37
+ private _refreshPromise: Promise<boolean> | null = null;
38
+ private _authFileMtime: number = 0;
39
+ private static readonly REFRESH_BUFFER_MS = 5 * 60 * 1000;
35
40
 
36
41
  static getInstance(): AuthService {
37
42
  if (!AuthService.instance) {
@@ -83,6 +88,12 @@ export class AuthService {
83
88
  }
84
89
  try {
85
90
  const content = readFileSync(authPath, "utf-8");
91
+ // Best-effort mtime tracking for multi-process detection
92
+ try {
93
+ this._authFileMtime = statSync(authPath).mtimeMs;
94
+ } catch {
95
+ // ignore stat errors
96
+ }
86
97
  return JSON.parse(content) as AuthConfig;
87
98
  } catch {
88
99
  return {};
@@ -97,11 +108,19 @@ export class AuthService {
97
108
  }
98
109
  writeFileSync(authPath, JSON.stringify(config, null, 2), "utf-8");
99
110
  chmodSync(authPath, 0o600);
111
+ // Update mtime after write
112
+ try {
113
+ this._authFileMtime = statSync(authPath).mtimeMs;
114
+ } catch {
115
+ // ignore stat errors
116
+ }
100
117
  }
101
118
 
102
119
  clearAuth(): void {
103
120
  const config = this.loadAuth();
104
121
  delete config.SSO_TOKEN;
122
+ delete config.SSO_REFRESH_TOKEN;
123
+ delete config.SSO_TOKEN_EXPIRES_AT;
105
124
  if (Object.keys(config).length === 0) {
106
125
  const authPath = this.getAuthPath();
107
126
  if (existsSync(authPath)) {
@@ -145,11 +164,22 @@ export class AuthService {
145
164
  });
146
165
 
147
166
  // Exchange authorization code for JWT (includes user info)
148
- const { token, user } = await this.exchangeCode(serverUrl, code);
167
+ const { token, refreshToken, expiresIn, user } = await this.exchangeCode(
168
+ serverUrl,
169
+ code,
170
+ );
149
171
 
150
172
  // Save the token and user info (preserve existing keys)
151
173
  const existing = this.loadAuth();
152
- this.saveAuth({ ...existing, SSO_TOKEN: token, user });
174
+ this.saveAuth({
175
+ ...existing,
176
+ SSO_TOKEN: token,
177
+ SSO_REFRESH_TOKEN: refreshToken,
178
+ SSO_TOKEN_EXPIRES_AT: expiresIn
179
+ ? Date.now() + expiresIn * 1000
180
+ : undefined,
181
+ user,
182
+ });
153
183
 
154
184
  this.notifyAuthChange("login");
155
185
 
@@ -158,32 +188,31 @@ export class AuthService {
158
188
 
159
189
  /**
160
190
  * Exchange a short-lived authorization code for a JWT token.
161
- * Returns both the token and user info.
191
+ * Returns token, optional refresh token, optional expiresIn, and user info.
162
192
  */
163
193
  private async exchangeCode(
164
194
  serverUrl: string,
165
195
  code: string,
166
- ): Promise<{ token: string; user: AuthUser }> {
167
- const exchangeUrl = `${serverUrl}/api/auth/exchange`;
196
+ ): Promise<TokenResponse> {
197
+ const exchangeUrl = `${serverUrl}/api/auth/token`;
198
+ logger.info(`[Auth] Exchanging authorization code at ${exchangeUrl}`);
168
199
  const response = await fetch(exchangeUrl, {
169
200
  method: "POST",
170
201
  headers: { "Content-Type": "application/json" },
171
- body: JSON.stringify({ code }),
202
+ body: JSON.stringify({ grant_type: "authorization_code", code }),
172
203
  });
173
204
 
174
205
  if (!response.ok) {
175
206
  const text = await response.text();
207
+ logger.info(
208
+ `[Auth] Authorization code exchange failed (${response.status}): ${text}`,
209
+ );
176
210
  throw new Error(`Token exchange failed (${response.status}): ${text}`);
177
211
  }
178
212
 
179
- const data = (await response.json()) as {
180
- token: string;
181
- user: { id: string; email?: string };
182
- };
183
- return {
184
- token: data.token,
185
- user: { id: data.user.id, email: data.user.email },
186
- };
213
+ const data = (await response.json()) as TokenResponse;
214
+ logger.info("[Auth] Authorization code exchanged successfully");
215
+ return data;
187
216
  }
188
217
 
189
218
  private startLocalAuthServer(
@@ -306,7 +335,149 @@ export class AuthService {
306
335
  }
307
336
 
308
337
  isSSOAuthenticated(): boolean {
309
- return this.getSSOToken() !== undefined;
338
+ const config = this.loadAuth();
339
+ if (!config.SSO_TOKEN) return false;
340
+ if (
341
+ config.SSO_TOKEN_EXPIRES_AT &&
342
+ Date.now() >= config.SSO_TOKEN_EXPIRES_AT
343
+ )
344
+ return false;
345
+ return true;
346
+ }
347
+
348
+ /**
349
+ * Check if the current token is expired or within the refresh buffer.
350
+ * Returns false if no expiry info (backward compat — treated as never-expiring).
351
+ */
352
+ isTokenExpired(): boolean {
353
+ const config = this.loadAuth();
354
+ if (!config.SSO_TOKEN_EXPIRES_AT) return false;
355
+ const expiresAt = config.SSO_TOKEN_EXPIRES_AT;
356
+ const bufferMs = AuthService.REFRESH_BUFFER_MS;
357
+ const now = Date.now();
358
+ const remaining = expiresAt - now;
359
+ const expired = now >= expiresAt - bufferMs;
360
+ if (expired) {
361
+ logger.info(
362
+ `[Auth] Token expired or within refresh buffer: remaining=${Math.round(remaining / 1000)}s, buffer=${bufferMs / 1000}s`,
363
+ );
364
+ }
365
+ return expired;
366
+ }
367
+
368
+ /**
369
+ * Check if the token needs refresh and refresh it if possible.
370
+ * Deduplicates concurrent refresh calls (401 dedup).
371
+ */
372
+ async checkAndRefreshTokenIfNeeded(): Promise<boolean> {
373
+ if (!this.isTokenExpired()) return true;
374
+ // Dedup: if a refresh is already in-flight, reuse the same promise
375
+ if (this._refreshPromise) {
376
+ logger.info(
377
+ "[Auth] Token refresh already in-flight, reusing existing promise",
378
+ );
379
+ return this._refreshPromise;
380
+ }
381
+ logger.info("[Auth] Starting token refresh");
382
+ this._refreshPromise = this.refreshToken();
383
+ try {
384
+ return await this._refreshPromise;
385
+ } finally {
386
+ this._refreshPromise = null;
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Refresh the access token using the stored refresh token.
392
+ * Returns true on success, false on failure.
393
+ */
394
+ private async refreshToken(): Promise<boolean> {
395
+ const config = this.loadAuth();
396
+ if (!config.SSO_REFRESH_TOKEN) {
397
+ logger.info("[Auth] No refresh token available, cannot refresh");
398
+ return false;
399
+ }
400
+
401
+ const serverUrl = this.getServerUrl();
402
+ try {
403
+ logger.info(`[Auth] Refreshing token via ${serverUrl}/api/auth/token`);
404
+ const response = await fetch(`${serverUrl}/api/auth/token`, {
405
+ method: "POST",
406
+ headers: { "Content-Type": "application/json" },
407
+ body: JSON.stringify({
408
+ grant_type: "refresh_token",
409
+ refresh_token: config.SSO_REFRESH_TOKEN,
410
+ }),
411
+ });
412
+
413
+ if (response.status === 400 || response.status === 401) {
414
+ // Refresh token revoked — clear auth
415
+ logger.info(
416
+ `[Auth] Refresh token rejected (${response.status}), clearing auth`,
417
+ );
418
+ this.clearAuth();
419
+ return false;
420
+ }
421
+
422
+ if (!response.ok) {
423
+ logger.info(
424
+ `[Auth] Token refresh failed with status ${response.status}`,
425
+ );
426
+ return false;
427
+ }
428
+
429
+ const data = (await response.json()) as TokenResponse;
430
+ const newExpiresAt = data.expiresIn
431
+ ? Date.now() + data.expiresIn * 1000
432
+ : undefined;
433
+ this.saveAuth({
434
+ ...config,
435
+ SSO_TOKEN: data.token,
436
+ SSO_REFRESH_TOKEN: data.refreshToken ?? config.SSO_REFRESH_TOKEN,
437
+ SSO_TOKEN_EXPIRES_AT: newExpiresAt,
438
+ user: data.user
439
+ ? { id: data.user.id, email: data.user.email }
440
+ : config.user,
441
+ });
442
+ logger.info(
443
+ `[Auth] Token refreshed successfully, new token expires at ${newExpiresAt ? new Date(newExpiresAt).toISOString() : "never"}`,
444
+ );
445
+ this.notifyAuthChange("login");
446
+ return true;
447
+ } catch (err) {
448
+ // Network error — don't clear auth (might be transient)
449
+ logger.info(`[Auth] Token refresh failed with network error: ${err}`);
450
+ return false;
451
+ }
452
+ }
453
+
454
+ /**
455
+ * Check if another process has refreshed the token on disk.
456
+ * Returns true if a fresh token was found and loaded.
457
+ */
458
+ /** @internal Check if another process has refreshed the token on disk */
459
+ tryReadRefreshedTokenFromDisk(): boolean {
460
+ try {
461
+ const authPath = this.getAuthPath();
462
+ if (!existsSync(authPath)) return false;
463
+ const stat = statSync(authPath);
464
+ if (stat.mtimeMs <= this._authFileMtime) return false;
465
+ // File was modified by another process — check if token is fresh
466
+ const config = this.loadAuth();
467
+ if (
468
+ config.SSO_TOKEN_EXPIRES_AT &&
469
+ Date.now() < config.SSO_TOKEN_EXPIRES_AT
470
+ ) {
471
+ logger.info(
472
+ `[Auth] Detected token refreshed by another process (auth.json mtime changed)`,
473
+ );
474
+ this._authFileMtime = stat.mtimeMs;
475
+ return true;
476
+ }
477
+ return false;
478
+ } catch {
479
+ return false;
480
+ }
310
481
  }
311
482
 
312
483
  getAuthUser(): AuthUser | undefined {
@@ -317,6 +488,62 @@ export class AuthService {
317
488
 
318
489
  export const authService = AuthService.getInstance();
319
490
 
491
+ /**
492
+ * Create a fetch wrapper that handles SSO token refresh transparently.
493
+ *
494
+ * 1. Proactive refresh: calls checkAndRefreshTokenIfNeeded() before each request
495
+ * 2. Updates Authorization header with fresh token
496
+ * 3. Reactive 401/403 recovery: tries disk refresh then force refresh, retries once
497
+ */
498
+ export function createAuthAwareFetch(innerFetch: typeof fetch): typeof fetch {
499
+ return async (input: RequestInfo | URL, init?: RequestInit) => {
500
+ // Proactive refresh
501
+ await authService.checkAndRefreshTokenIfNeeded();
502
+
503
+ // Update Authorization header with fresh token
504
+ const freshToken = authService.getSSOToken();
505
+ const headers = new Headers(init?.headers);
506
+ if (freshToken) {
507
+ headers.set("Authorization", `Bearer ${freshToken}`);
508
+ }
509
+ const modifiedInit = { ...init, headers };
510
+
511
+ const response = await innerFetch(input, modifiedInit);
512
+
513
+ // Reactive 401/403 recovery (single retry)
514
+ if (response.status === 401 || response.status === 403) {
515
+ logger.info(
516
+ `[Auth] Received ${response.status}, attempting token recovery`,
517
+ );
518
+ // Try disk refresh first (another process may have refreshed)
519
+ if (authService.tryReadRefreshedTokenFromDisk()) {
520
+ const retryToken = authService.getSSOToken();
521
+ const retryHeaders = new Headers(init?.headers);
522
+ if (retryToken) {
523
+ retryHeaders.set("Authorization", `Bearer ${retryToken}`);
524
+ }
525
+ logger.info("[Auth] Retrying request with disk-refreshed token");
526
+ return innerFetch(input, { ...init, headers: retryHeaders });
527
+ }
528
+
529
+ // Try force refresh
530
+ if (await authService.checkAndRefreshTokenIfNeeded()) {
531
+ const retryToken = authService.getSSOToken();
532
+ if (retryToken) {
533
+ const retryHeaders = new Headers(init?.headers);
534
+ retryHeaders.set("Authorization", `Bearer ${retryToken}`);
535
+ logger.info("[Auth] Retrying request with force-refreshed token");
536
+ return innerFetch(input, { ...init, headers: retryHeaders });
537
+ }
538
+ }
539
+
540
+ logger.info("[Auth] Token recovery failed, returning original response");
541
+ }
542
+
543
+ return response;
544
+ };
545
+ }
546
+
320
547
  /**
321
548
  * Get or create a persistent anonymous ID for telemetry.
322
549
  *
@@ -44,6 +44,11 @@ import {
44
44
  } from "../utils/constants.js";
45
45
  import { ClientOptions } from "openai";
46
46
  import { parseCustomHeaders } from "../utils/stringUtils.js";
47
+ import {
48
+ getRemoteSettingsSync,
49
+ mergeRemoteSettings,
50
+ } from "./remoteSettingsService.js";
51
+ import { createAuthAwareFetch } from "./authService.js";
47
52
 
48
53
  /**
49
54
  * Default ConfigurationService implementation
@@ -101,19 +106,25 @@ export class ConfigurationService {
101
106
  };
102
107
  }
103
108
 
109
+ // Merge remote settings (highest priority: Remote > Local > Project > User)
110
+ const remoteSettings = getRemoteSettingsSync();
111
+ const finalConfig = remoteSettings
112
+ ? mergeRemoteSettings(mergedConfig, remoteSettings)
113
+ : mergedConfig;
114
+
104
115
  // Success case
105
- this.currentConfiguration = mergedConfig;
116
+ this.currentConfiguration = finalConfig;
106
117
 
107
118
  // Set environment variables from merged config and inject system variables
108
119
  const env = {
109
- ...(mergedConfig.env || {}),
120
+ ...(finalConfig.env || {}),
110
121
  WAVE_PROJECT_DIR: workdir,
111
122
  };
112
123
  this.setEnvironmentVars(env);
113
- mergedConfig.env = env;
124
+ finalConfig.env = env;
114
125
 
115
126
  return {
116
- configuration: mergedConfig,
127
+ configuration: finalConfig,
117
128
  success: true,
118
129
  sourcePath: "merged configuration",
119
130
  warnings: validation.warnings,
@@ -413,6 +424,10 @@ export class ConfigurationService {
413
424
  const ssoToken = this.readSSOToken();
414
425
  const serverUrl = this.options.serverUrl || process.env.WAVE_SERVER_URL;
415
426
  if (ssoToken && serverUrl) {
427
+ const baseFetch = fetch ?? this.options.fetch ?? globalThis.fetch;
428
+ const authAwareFetch = createAuthAwareFetch(
429
+ baseFetch as typeof globalThis.fetch,
430
+ ) as ClientOptions["fetch"];
416
431
  return {
417
432
  apiKey: ssoToken,
418
433
  baseURL: `${serverUrl}/api/v1`,
@@ -421,7 +436,7 @@ export class ConfigurationService {
421
436
  ? defaultHeaders
422
437
  : undefined,
423
438
  fetchOptions: fetchOptions ?? this.options.fetchOptions,
424
- fetch: fetch ?? this.options.fetch,
439
+ fetch: authAwareFetch,
425
440
  };
426
441
  }
427
442
 
@@ -498,7 +513,10 @@ export class ConfigurationService {
498
513
  ): ModelConfig {
499
514
  // Resolve agent model: override > options > process.env (includes settings.json env)
500
515
  const resolvedAgentModel =
501
- model || this.options.model || process.env.WAVE_MODEL;
516
+ model ||
517
+ this.options.model ||
518
+ process.env.WAVE_MODEL ||
519
+ this.currentConfiguration?.model;
502
520
 
503
521
  // Resolve fast model: override > options > process.env (includes settings.json env)
504
522
  const resolvedFastModel =
@@ -686,6 +704,28 @@ export class ConfigurationService {
686
704
  */
687
705
  setModel(model: string): void {
688
706
  this.options.model = model;
707
+ this.persistModelToSettings(model);
708
+ }
709
+
710
+ private async persistModelToSettings(model: string): Promise<void> {
711
+ const configPath = getUserConfigPaths()[0]; // ~/.wave/settings.json
712
+ const configDir = path.dirname(configPath);
713
+ if (!existsSync(configDir)) {
714
+ await fs.mkdir(configDir, { recursive: true });
715
+ }
716
+
717
+ let config: WaveConfiguration = {};
718
+ if (existsSync(configPath)) {
719
+ try {
720
+ const content = await fs.readFile(configPath, "utf-8");
721
+ config = JSON.parse(content);
722
+ } catch {
723
+ // Start fresh if corrupted
724
+ }
725
+ }
726
+
727
+ config.model = model;
728
+ await fs.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
689
729
  }
690
730
 
691
731
  /**
@@ -700,6 +740,11 @@ export class ConfigurationService {
700
740
  models.add(currentModel);
701
741
  }
702
742
 
743
+ // Persisted model from settings (includes remote-merged)
744
+ if (this.currentConfiguration?.model) {
745
+ models.add(this.currentConfiguration.model);
746
+ }
747
+
703
748
  // Add models from merged configuration
704
749
  if (this.currentConfiguration?.models) {
705
750
  Object.keys(this.currentConfiguration.models).forEach((model) => {
@@ -1129,6 +1174,7 @@ export function loadWaveConfigFromFile(
1129
1174
  permissions: config.permissions || undefined,
1130
1175
  enabledPlugins: config.enabledPlugins || undefined,
1131
1176
  language: config.language || undefined,
1177
+ model: config.model || undefined,
1132
1178
  autoMemoryEnabled:
1133
1179
  config.autoMemoryEnabled !== undefined
1134
1180
  ? config.autoMemoryEnabled
@@ -1258,6 +1304,11 @@ export function loadMergedWaveConfig(
1258
1304
  mergedConfig.language = config.language;
1259
1305
  }
1260
1306
 
1307
+ // Merge model (last one wins)
1308
+ if (config.model !== undefined) {
1309
+ mergedConfig.model = config.model;
1310
+ }
1311
+
1261
1312
  // Merge autoMemoryEnabled (last one wins)
1262
1313
  if (config.autoMemoryEnabled !== undefined) {
1263
1314
  mergedConfig.autoMemoryEnabled = config.autoMemoryEnabled;
@@ -1306,6 +1357,7 @@ export function loadMergedWaveConfig(
1306
1357
  ? mergedConfig.enabledPlugins
1307
1358
  : undefined,
1308
1359
  language: mergedConfig.language,
1360
+ model: mergedConfig.model,
1309
1361
  autoMemoryEnabled: mergedConfig.autoMemoryEnabled,
1310
1362
  marketplaces:
1311
1363
  mergedConfig.marketplaces &&
@@ -277,6 +277,21 @@ export async function executeCommands(
277
277
  return results;
278
278
  }
279
279
 
280
+ /**
281
+ * Execute a CwdChanged hook
282
+ */
283
+ export async function executeCwdChangedHooks(
284
+ oldCwd: string,
285
+ newCwd: string,
286
+ context: ExtendedHookExecutionContext,
287
+ ): Promise<HookExecutionResult[]> {
288
+ // CwdChanged hooks are executed through HookManager.executeCwdChangedHooks()
289
+ void context;
290
+ void oldCwd;
291
+ void newCwd;
292
+ return [];
293
+ }
294
+
280
295
  /**
281
296
  * Validate command safety (basic checks)
282
297
  */
@@ -22,6 +22,7 @@ import type { MemoryRuleManager } from "../managers/MemoryRuleManager.js";
22
22
  import type { LiveConfigManager } from "../managers/liveConfigManager.js";
23
23
  import type { TaskManager } from "./taskManager.js";
24
24
  import type { PermissionManager } from "../managers/permissionManager.js";
25
+ import { remoteSettingsService } from "./remoteSettingsService.js";
25
26
 
26
27
  export interface InitializationContext {
27
28
  skillManager: SkillManager;
@@ -288,6 +289,18 @@ export class InitializationService {
288
289
  // Don't throw error to prevent app startup failure - continue without live reload
289
290
  }
290
291
 
292
+ // Initialize remote settings (fetch server-managed config)
293
+ try {
294
+ const phaseStart = performance.now();
295
+ await remoteSettingsService.initialize();
296
+ logger?.debug(
297
+ `Initialization Phase [Remote Settings] took ${(performance.now() - phaseStart).toFixed(2)}ms`,
298
+ );
299
+ } catch (error) {
300
+ logger?.error("Failed to initialize remote settings:", error);
301
+ // Don't throw error to prevent app startup failure - continue without remote settings
302
+ }
303
+
291
304
  // Memory is lazy-cached on first getCombinedMemoryContent call
292
305
  // No explicit loading needed during initialization
293
306
 
@@ -7,7 +7,6 @@ import type { ConfigurationService } from "./configurationService.js";
7
7
  import type { AIManager } from "../managers/aiManager.js";
8
8
  import type { SubagentManager } from "../managers/subagentManager.js";
9
9
  import type { TaskManager } from "./taskManager.js";
10
- import type { NotificationQueue } from "../managers/notificationQueue.js";
11
10
 
12
11
  export interface InteractionContext {
13
12
  messageManager: MessageManager;
@@ -62,23 +61,6 @@ export class InteractionService {
62
61
  // Don't add to history, let normal message processing logic below handle it
63
62
  }
64
63
 
65
- // Inject pending notifications from background tasks
66
- const notificationQueue = context.aiManager["container"].has(
67
- "NotificationQueue",
68
- )
69
- ? context.aiManager["container"].get<NotificationQueue>(
70
- "NotificationQueue",
71
- )
72
- : undefined;
73
- if (notificationQueue && notificationQueue.hasPending()) {
74
- const notifications = notificationQueue.dequeueAll();
75
- for (const notification of notifications) {
76
- messageManager.addUserMessage({
77
- content: notification,
78
- });
79
- }
80
- }
81
-
82
64
  // Handle normal AI message
83
65
  // Add user message first, will automatically sync to UI
84
66
  messageManager.addUserMessage({