Skip to content

Commit 2715ef8

Browse files
committed
refactor(settings): route diagnostics through emitDiagnostic
SettingsDefaultsManager used raw console.warn for its [SETTINGS] diagnostics. Replace with emitDiagnostic (hook-io) so the lines survive the Phase 2 hook stderr buffer (#2292) — the same channel logger uses — instead of being swallowed by raw console. Keeps the deliberate stderr-not-stdout behavior that protects the machine-readable JSON contract on stdout. emitDiagnostic is chosen over logger because logger transitively depends on this module via shared/paths, so importing logger here would invert layering and risk a circular dependency at bootstrap. hook-io is a leaf module (type-only import), so no cycle.
1 parent b7479f8 commit 2715ef8

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/shared/SettingsDefaultsManager.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
33
import { join, dirname } from 'path';
44
import { homedir } from 'os';
55
import { HOOK_TIMEOUTS, getTimeout } from './hook-constants.js';
6+
import { emitDiagnostic } from './hook-io.js';
67

78
export interface SettingsDefaults {
89
CLAUDE_MEM_MODEL: string;
@@ -205,10 +206,12 @@ export class SettingsDefaultsManager {
205206
writeFileSync(settingsPath, JSON.stringify(defaults, null, 2), 'utf-8');
206207
// stderr, never stdout: this fires on the first boot in a fresh data
207208
// dir, and CLI commands like `start` promise machine-readable JSON
208-
// on stdout to the hook framework.
209-
console.warn('[SETTINGS] Created settings file with defaults:', settingsPath);
209+
// on stdout to the hook framework. emitDiagnostic routes through the
210+
// same channel logger uses so the line survives the Phase 2 hook
211+
// stderr buffer (#2292) instead of being swallowed by raw console.
212+
emitDiagnostic(`[SETTINGS] Created settings file with defaults: ${settingsPath}\n`);
210213
} catch (error: unknown) {
211-
console.warn('[SETTINGS] Failed to create settings file, using in-memory defaults:', settingsPath, error instanceof Error ? error.message : String(error));
214+
emitDiagnostic(`[SETTINGS] Failed to create settings file, using in-memory defaults: ${settingsPath} ${error instanceof Error ? error.message : String(error)}\n`);
212215
}
213216
return applyEnvOverrides ? this.applyEnvOverrides(defaults) : defaults;
214217
}
@@ -226,9 +229,9 @@ export class SettingsDefaultsManager {
226229
try {
227230
writeFileSync(settingsPath, JSON.stringify(flatSettings, null, 2), 'utf-8');
228231
// stderr, never stdout — same JSON-on-stdout contract as above.
229-
console.warn('[SETTINGS] Migrated settings file from nested to flat schema:', settingsPath);
232+
emitDiagnostic(`[SETTINGS] Migrated settings file from nested to flat schema: ${settingsPath}\n`);
230233
} catch (error: unknown) {
231-
console.warn('[SETTINGS] Failed to auto-migrate settings file:', settingsPath, error instanceof Error ? error.message : String(error));
234+
emitDiagnostic(`[SETTINGS] Failed to auto-migrate settings file: ${settingsPath} ${error instanceof Error ? error.message : String(error)}\n`);
232235
// Continue with in-memory migration even if write fails
233236
}
234237
}
@@ -242,7 +245,7 @@ export class SettingsDefaultsManager {
242245

243246
return applyEnvOverrides ? this.applyEnvOverrides(result) : result;
244247
} catch (error: unknown) {
245-
console.warn('[SETTINGS] Failed to load settings, using defaults:', settingsPath, error instanceof Error ? error.message : String(error));
248+
emitDiagnostic(`[SETTINGS] Failed to load settings, using defaults: ${settingsPath} ${error instanceof Error ? error.message : String(error)}\n`);
246249
const defaults = this.getAllDefaults();
247250
return applyEnvOverrides ? this.applyEnvOverrides(defaults) : defaults;
248251
}

0 commit comments

Comments
 (0)