@xi4z/dsh-utils-utils-agents 0.10.0 → 0.11.0

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.
@@ -17,6 +17,14 @@
17
17
  * untouched afterwards, so downgrading still works. Deploy Keys stay under
18
18
  * `$DSH_HOME/storages`: they are secrets, not configuration.
19
19
  *
20
+ * A missing document with no legacy state, or a document that carries neither
21
+ * repositories nor settings (an empty `{}` left by an older install), is
22
+ * converted to the shipped default configuration — one shared Skill repository
23
+ * at the default URL/branch — and written back, so an upgraded profile starts
24
+ * from the same defaults as a fresh install. A document that already configures
25
+ * anything is never rewritten by a read; a malformed document is reported as
26
+ * defaults without touching the file (a hand edit stays repairable).
27
+ *
20
28
  * @module dsh-utils/utils-agents/utils-config
21
29
  */
22
30
  import { type Options, type SyncRecord } from './util.js';
@@ -28,6 +36,10 @@ export declare const DEFAULT_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES = 60;
28
36
  export declare const MIN_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES = 5;
29
37
  /** Largest accepted automatic refresh interval. */
30
38
  export declare const MAX_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES = 1440;
39
+ /** Shipped default URL of the shared Skill repository (same as the preset default). */
40
+ export declare const DEFAULT_SHARED_REPO_URL = "https://github.com/xi4z/skills";
41
+ /** Shipped default branch of the shared Skill repository. */
42
+ export declare const DEFAULT_SHARED_REPO_BRANCH = "Agent";
31
43
  /** One configured Skill repository checkout. */
32
44
  export interface SkillRepositoryConfig {
33
45
  repoUrl: string;
@@ -58,16 +70,31 @@ export declare function utilsConfigDir(): string;
58
70
  export declare function utilsConfigPath(): string;
59
71
  /** The legacy single-repository document `global-repo` used to write. */
60
72
  export declare function legacyUtilsStatePath(): string;
61
- /** A fresh document with the shipped defaults. */
73
+ /** The shipped settings with no repository; normalize starts from this baseline. */
62
74
  export declare function emptyUtilsConfig(): UtilsConfig;
63
- /** The fallback repository the panel shows before anything is saved. */
64
- export declare function defaultSkillRepository(options: Pick<Options, 'defaultRepoUrl' | 'defaultBranch'>): SkillRepositoryConfig;
75
+ /**
76
+ * The fallback repository the panel shows before anything is saved, and the
77
+ * repository an empty document is bootstrapped with.
78
+ * @param options - row settings supplying the default URL/branch; omitted uses the shipped constants.
79
+ * @returns the default shared repository entry.
80
+ */
81
+ export declare function defaultSkillRepository(options?: Pick<Options, 'defaultRepoUrl' | 'defaultBranch'>): SkillRepositoryConfig;
82
+ /**
83
+ * The shipped default configuration: the same settings as an empty document
84
+ * plus the default shared Skill repository. This is what a missing or empty
85
+ * `utils.json` turns into, so a fresh install and an upgraded one start equal.
86
+ * @returns a document to persist as-is.
87
+ */
88
+ export declare function defaultUtilsConfig(): UtilsConfig;
65
89
  /**
66
90
  * Read the consolidated configuration.
67
91
  *
68
- * A missing file is migrated from the legacy state document (and written back
69
- * when that document exists); a malformed document yields the defaults without
70
- * destroying the file, so a hand-edit can be repaired.
92
+ * A missing file is migrated from the legacy state document when that document
93
+ * carries a repository, and otherwise becomes the shipped default
94
+ * configuration; an empty document is converted to the default and written
95
+ * back, so an upgraded profile ends up with the same document a fresh install
96
+ * gets. A malformed document yields the defaults without destroying the file,
97
+ * so a hand edit can be repaired.
71
98
  * @returns the normalized document, whether it existed, and its path.
72
99
  */
73
100
  export declare function readUtilsConfig(): Promise<UtilsConfigSnapshot>;
@@ -17,6 +17,14 @@
17
17
  * untouched afterwards, so downgrading still works. Deploy Keys stay under
18
18
  * `$DSH_HOME/storages`: they are secrets, not configuration.
19
19
  *
20
+ * A missing document with no legacy state, or a document that carries neither
21
+ * repositories nor settings (an empty `{}` left by an older install), is
22
+ * converted to the shipped default configuration — one shared Skill repository
23
+ * at the default URL/branch — and written back, so an upgraded profile starts
24
+ * from the same defaults as a fresh install. A document that already configures
25
+ * anything is never rewritten by a read; a malformed document is reported as
26
+ * defaults without touching the file (a hand edit stays repairable).
27
+ *
20
28
  * @module dsh-utils/utils-agents/utils-config
21
29
  */
22
30
  import { randomBytes } from 'node:crypto';
@@ -33,6 +41,15 @@ export const MIN_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES = 5;
33
41
  export const MAX_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES = 1440;
34
42
  /** Branch used for a migrated repository that never recorded one. */
35
43
  const FALLBACK_BRANCH = 'Agent';
44
+ /** Shipped default URL of the shared Skill repository (same as the preset default). */
45
+ export const DEFAULT_SHARED_REPO_URL = 'https://github.com/xi4z/skills';
46
+ /** Shipped default branch of the shared Skill repository. */
47
+ export const DEFAULT_SHARED_REPO_BRANCH = 'Agent';
48
+ /**
49
+ * Document keys that carry settings of their own. A document with none of
50
+ * these and no repository is treated as empty (see {@link isEmptyDocument}).
51
+ */
52
+ const SETTING_KEYS = ['autoUpdate', 'autoSyncPresets', 'updateIntervalMinutes'];
36
53
  /** `$DSH_HOME/utils`. */
37
54
  export function utilsConfigDir() {
38
55
  return join(dshHome(), 'utils');
@@ -45,7 +62,7 @@ export function utilsConfigPath() {
45
62
  export function legacyUtilsStatePath() {
46
63
  return join(dshHome(), 'storages', 'dsh-utils-ui.json');
47
64
  }
48
- /** A fresh document with the shipped defaults. */
65
+ /** The shipped settings with no repository; normalize starts from this baseline. */
49
66
  export function emptyUtilsConfig() {
50
67
  return {
51
68
  version: UTILS_CONFIG_VERSION,
@@ -55,23 +72,40 @@ export function emptyUtilsConfig() {
55
72
  updateIntervalMinutes: DEFAULT_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES,
56
73
  };
57
74
  }
58
- /** The fallback repository the panel shows before anything is saved. */
75
+ /**
76
+ * The fallback repository the panel shows before anything is saved, and the
77
+ * repository an empty document is bootstrapped with.
78
+ * @param options - row settings supplying the default URL/branch; omitted uses the shipped constants.
79
+ * @returns the default shared repository entry.
80
+ */
59
81
  export function defaultSkillRepository(options) {
60
82
  return {
61
- repoUrl: options.defaultRepoUrl,
62
- branch: options.defaultBranch,
83
+ repoUrl: options === undefined ? DEFAULT_SHARED_REPO_URL : options.defaultRepoUrl,
84
+ branch: options === undefined ? DEFAULT_SHARED_REPO_BRANCH : options.defaultBranch,
63
85
  targetDir: join(dshHome(), 'skills', 'utils-skill'),
64
86
  keyPath: '',
65
87
  recurseSubmodules: true,
66
88
  lastSync: null,
67
89
  };
68
90
  }
91
+ /**
92
+ * The shipped default configuration: the same settings as an empty document
93
+ * plus the default shared Skill repository. This is what a missing or empty
94
+ * `utils.json` turns into, so a fresh install and an upgraded one start equal.
95
+ * @returns a document to persist as-is.
96
+ */
97
+ export function defaultUtilsConfig() {
98
+ return { ...emptyUtilsConfig(), skillRepositories: [defaultSkillRepository()] };
99
+ }
69
100
  /**
70
101
  * Read the consolidated configuration.
71
102
  *
72
- * A missing file is migrated from the legacy state document (and written back
73
- * when that document exists); a malformed document yields the defaults without
74
- * destroying the file, so a hand-edit can be repaired.
103
+ * A missing file is migrated from the legacy state document when that document
104
+ * carries a repository, and otherwise becomes the shipped default
105
+ * configuration; an empty document is converted to the default and written
106
+ * back, so an upgraded profile ends up with the same document a fresh install
107
+ * gets. A malformed document yields the defaults without destroying the file,
108
+ * so a hand edit can be repaired.
75
109
  * @returns the normalized document, whether it existed, and its path.
76
110
  */
77
111
  export async function readUtilsConfig() {
@@ -83,9 +117,43 @@ export async function readUtilsConfig() {
83
117
  catch (error) {
84
118
  if (isAbsent(error))
85
119
  return migrateLegacyConfig(path);
120
+ // Unparsable: report defaults but never overwrite what may be a hand edit.
86
121
  return { config: emptyUtilsConfig(), existed: true, path };
87
122
  }
88
- return { config: normalizeUtilsConfig(raw), existed: true, path };
123
+ if (!isEmptyDocument(raw))
124
+ return { config: normalizeUtilsConfig(raw), existed: true, path };
125
+ const config = defaultUtilsConfig();
126
+ await persistQuietly(config);
127
+ return { config, existed: true, path };
128
+ }
129
+ /**
130
+ * Whether a parsed document carries nothing worth keeping: no repository and
131
+ * no setting. The empty `{}` an older install left behind, and a
132
+ * `{"version": 1}` skeleton, both qualify; an explicit setting such as
133
+ * `autoUpdate: false` or `skillRepositories: []` does not.
134
+ * @param raw - parsed JSON value.
135
+ * @returns true when the default configuration should replace it.
136
+ */
137
+ function isEmptyDocument(raw) {
138
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
139
+ return true;
140
+ const record = raw;
141
+ const repositories = record.skillRepositories;
142
+ const hasRepository = Array.isArray(repositories)
143
+ ? repositories.length > 0
144
+ : record.repoUrl !== undefined || record.targetDir !== undefined;
145
+ if (hasRepository)
146
+ return false;
147
+ return !SETTING_KEYS.some((key) => record[key] !== undefined);
148
+ }
149
+ /** Write the document, ignoring a read-only home so a read never fails on it. */
150
+ async function persistQuietly(config) {
151
+ try {
152
+ await writeUtilsConfig(config);
153
+ }
154
+ catch {
155
+ // A read-only home must not turn configuration reads into a failure.
156
+ }
89
157
  }
90
158
  /** Replace the document atomically with mode 0600. */
91
159
  export async function writeUtilsConfig(config) {
@@ -164,29 +232,27 @@ function normalizeSkillRepository(raw) {
164
232
  };
165
233
  }
166
234
  /**
167
- * Migrate the legacy single-repository document exactly once.
235
+ * Materialize the document a profile without one starts from.
236
+ *
237
+ * A legacy single-repository document wins when it names a repository;
238
+ * otherwise the shipped default configuration is used, so an upgraded profile
239
+ * ends up with defaults instead of an empty document. The result is always
240
+ * written back (best effort), and the legacy file is never modified.
168
241
  * @param path - the consolidated config path.
169
- * @returns the migrated snapshot; the legacy file is never modified.
242
+ * @returns the migrated snapshot.
170
243
  */
171
244
  async function migrateLegacyConfig(path) {
172
- const config = emptyUtilsConfig();
245
+ const config = defaultUtilsConfig();
173
246
  try {
174
247
  const raw = JSON.parse(await readFile(legacyUtilsStatePath(), 'utf8'));
175
248
  const repository = normalizeSkillRepository(raw);
176
249
  if (repository !== undefined)
177
- config.skillRepositories.push(repository);
250
+ config.skillRepositories = [repository];
178
251
  }
179
252
  catch {
180
- // No legacy document, or it is unreadable: start empty.
181
- }
182
- if (config.skillRepositories.length > 0) {
183
- try {
184
- await writeUtilsConfig(config);
185
- }
186
- catch {
187
- // A read-only home must not turn discovery into a failure.
188
- }
253
+ // No legacy document, or it is unreadable: keep the shipped default.
189
254
  }
255
+ await persistQuietly(config);
190
256
  return { config, existed: false, path };
191
257
  }
192
258
  /** Clamp one refresh interval to the accepted range. */
@@ -1 +1 @@
1
- {"version":3,"file":"utils-config.js","sourceRoot":"","sources":["../src/utils-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,OAAO,EACP,cAAc,GAGf,MAAM,WAAW,CAAA;AAElB,uCAAuC;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAErC,gEAAgE;AAChE,MAAM,CAAC,MAAM,gDAAgD,GAAG,EAAE,CAAA;AAElE,oDAAoD;AACpD,MAAM,CAAC,MAAM,4CAA4C,GAAG,CAAC,CAAA;AAE7D,mDAAmD;AACnD,MAAM,CAAC,MAAM,4CAA4C,GAAG,IAAI,CAAA;AAEhE,qEAAqE;AACrE,MAAM,eAAe,GAAG,OAAO,CAAA;AA6B/B,yBAAyB;AACzB,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAA;AACjC,CAAC;AAED,oCAAoC;AACpC,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,cAAc,EAAE,EAAE,YAAY,CAAC,CAAA;AAC7C,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,oBAAoB;IAClC,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,mBAAmB,CAAC,CAAA;AACzD,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU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AAE,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;KAClE,CAAA;AACH,CAAC;AAED,2DAA2D;AAC3D,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK;WAChE,CAAE,KAA4B,CAAC,IAAI,KAAK,QAAQ,IAAK,KAA4B,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;AAC5G,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xi4z/dsh-utils-utils-agents",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "dsh-utils component: the utils-agents panel that manages presets, skills, skill repositories and AGENTS.md; it also owns nested SKILL.md discovery and the model-facing skill visibility switches, merged from the former main and skill-panel components.",
5
5
  "license": "MIT",
6
6
  "author": "xi4z",
@@ -17,6 +17,14 @@
17
17
  * untouched afterwards, so downgrading still works. Deploy Keys stay under
18
18
  * `$DSH_HOME/storages`: they are secrets, not configuration.
19
19
  *
20
+ * A missing document with no legacy state, or a document that carries neither
21
+ * repositories nor settings (an empty `{}` left by an older install), is
22
+ * converted to the shipped default configuration — one shared Skill repository
23
+ * at the default URL/branch — and written back, so an upgraded profile starts
24
+ * from the same defaults as a fresh install. A document that already configures
25
+ * anything is never rewritten by a read; a malformed document is reported as
26
+ * defaults without touching the file (a hand edit stays repairable).
27
+ *
20
28
  * @module dsh-utils/utils-agents/utils-config
21
29
  */
22
30
 
@@ -45,6 +53,18 @@ export const MAX_SKILL_REPOSITORY_UPDATE_INTERVAL_MINUTES = 1440
45
53
  /** Branch used for a migrated repository that never recorded one. */
46
54
  const FALLBACK_BRANCH = 'Agent'
47
55
 
56
+ /** Shipped default URL of the shared Skill repository (same as the preset default). */
57
+ export const DEFAULT_SHARED_REPO_URL = 'https://github.com/xi4z/skills'
58
+
59
+ /** Shipped default branch of the shared Skill repository. */
60
+ export const DEFAULT_SHARED_REPO_BRANCH = 'Agent'
61
+
62
+ /**
63
+ * Document keys that carry settings of their own. A document with none of
64
+ * these and no repository is treated as empty (see {@link isEmptyDocument}).
65
+ */
66
+ const SETTING_KEYS = ['autoUpdate', 'autoSyncPresets', 'updateIntervalMinutes'] as const
67
+
48
68
  /** One configured Skill repository checkout. */
49
69
  export interface SkillRepositoryConfig {
50
70
  repoUrl: string
@@ -87,7 +107,7 @@ export function legacyUtilsStatePath(): string {
87
107
  return join(dshHome(), 'storages', 'dsh-utils-ui.json')
88
108
  }
89
109
 
90
- /** A fresh document with the shipped defaults. */
110
+ /** The shipped settings with no repository; normalize starts from this baseline. */
91
111
  export function emptyUtilsConfig(): UtilsConfig {
92
112
  return {
93
113
  version: UTILS_CONFIG_VERSION,
@@ -98,11 +118,16 @@ export function emptyUtilsConfig(): UtilsConfig {
98
118
  }
99
119
  }
100
120
 
101
- /** The fallback repository the panel shows before anything is saved. */
102
- export function defaultSkillRepository(options: Pick<Options, 'defaultRepoUrl' | 'defaultBranch'>): SkillRepositoryConfig {
121
+ /**
122
+ * The fallback repository the panel shows before anything is saved, and the
123
+ * repository an empty document is bootstrapped with.
124
+ * @param options - row settings supplying the default URL/branch; omitted uses the shipped constants.
125
+ * @returns the default shared repository entry.
126
+ */
127
+ export function defaultSkillRepository(options?: Pick<Options, 'defaultRepoUrl' | 'defaultBranch'>): SkillRepositoryConfig {
103
128
  return {
104
- repoUrl: options.defaultRepoUrl,
105
- branch: options.defaultBranch,
129
+ repoUrl: options === undefined ? DEFAULT_SHARED_REPO_URL : options.defaultRepoUrl,
130
+ branch: options === undefined ? DEFAULT_SHARED_REPO_BRANCH : options.defaultBranch,
106
131
  targetDir: join(dshHome(), 'skills', 'utils-skill'),
107
132
  keyPath: '',
108
133
  recurseSubmodules: true,
@@ -110,12 +135,25 @@ export function defaultSkillRepository(options: Pick<Options, 'defaultRepoUrl' |
110
135
  }
111
136
  }
112
137
 
138
+ /**
139
+ * The shipped default configuration: the same settings as an empty document
140
+ * plus the default shared Skill repository. This is what a missing or empty
141
+ * `utils.json` turns into, so a fresh install and an upgraded one start equal.
142
+ * @returns a document to persist as-is.
143
+ */
144
+ export function defaultUtilsConfig(): UtilsConfig {
145
+ return { ...emptyUtilsConfig(), skillRepositories: [defaultSkillRepository()] }
146
+ }
147
+
113
148
  /**
114
149
  * Read the consolidated configuration.
115
150
  *
116
- * A missing file is migrated from the legacy state document (and written back
117
- * when that document exists); a malformed document yields the defaults without
118
- * destroying the file, so a hand-edit can be repaired.
151
+ * A missing file is migrated from the legacy state document when that document
152
+ * carries a repository, and otherwise becomes the shipped default
153
+ * configuration; an empty document is converted to the default and written
154
+ * back, so an upgraded profile ends up with the same document a fresh install
155
+ * gets. A malformed document yields the defaults without destroying the file,
156
+ * so a hand edit can be repaired.
119
157
  * @returns the normalized document, whether it existed, and its path.
120
158
  */
121
159
  export async function readUtilsConfig(): Promise<UtilsConfigSnapshot> {
@@ -125,9 +163,41 @@ export async function readUtilsConfig(): Promise<UtilsConfigSnapshot> {
125
163
  raw = JSON.parse(await readFile(path, 'utf8')) as unknown
126
164
  } catch (error) {
127
165
  if (isAbsent(error)) return migrateLegacyConfig(path)
166
+ // Unparsable: report defaults but never overwrite what may be a hand edit.
128
167
  return { config: emptyUtilsConfig(), existed: true, path }
129
168
  }
130
- return { config: normalizeUtilsConfig(raw), existed: true, path }
169
+ if (!isEmptyDocument(raw)) return { config: normalizeUtilsConfig(raw), existed: true, path }
170
+ const config = defaultUtilsConfig()
171
+ await persistQuietly(config)
172
+ return { config, existed: true, path }
173
+ }
174
+
175
+ /**
176
+ * Whether a parsed document carries nothing worth keeping: no repository and
177
+ * no setting. The empty `{}` an older install left behind, and a
178
+ * `{"version": 1}` skeleton, both qualify; an explicit setting such as
179
+ * `autoUpdate: false` or `skillRepositories: []` does not.
180
+ * @param raw - parsed JSON value.
181
+ * @returns true when the default configuration should replace it.
182
+ */
183
+ function isEmptyDocument(raw: unknown): boolean {
184
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return true
185
+ const record = raw as Record<string, unknown>
186
+ const repositories = record.skillRepositories
187
+ const hasRepository = Array.isArray(repositories)
188
+ ? repositories.length > 0
189
+ : record.repoUrl !== undefined || record.targetDir !== undefined
190
+ if (hasRepository) return false
191
+ return !SETTING_KEYS.some((key) => record[key] !== undefined)
192
+ }
193
+
194
+ /** Write the document, ignoring a read-only home so a read never fails on it. */
195
+ async function persistQuietly(config: UtilsConfig): Promise<void> {
196
+ try {
197
+ await writeUtilsConfig(config)
198
+ } catch {
199
+ // A read-only home must not turn configuration reads into a failure.
200
+ }
131
201
  }
132
202
 
133
203
  /** Replace the document atomically with mode 0600. */
@@ -205,26 +275,25 @@ function normalizeSkillRepository(raw: unknown): SkillRepositoryConfig | undefin
205
275
  }
206
276
 
207
277
  /**
208
- * Migrate the legacy single-repository document exactly once.
278
+ * Materialize the document a profile without one starts from.
279
+ *
280
+ * A legacy single-repository document wins when it names a repository;
281
+ * otherwise the shipped default configuration is used, so an upgraded profile
282
+ * ends up with defaults instead of an empty document. The result is always
283
+ * written back (best effort), and the legacy file is never modified.
209
284
  * @param path - the consolidated config path.
210
- * @returns the migrated snapshot; the legacy file is never modified.
285
+ * @returns the migrated snapshot.
211
286
  */
212
287
  async function migrateLegacyConfig(path: string): Promise<UtilsConfigSnapshot> {
213
- const config = emptyUtilsConfig()
288
+ const config = defaultUtilsConfig()
214
289
  try {
215
290
  const raw = JSON.parse(await readFile(legacyUtilsStatePath(), 'utf8')) as unknown
216
291
  const repository = normalizeSkillRepository(raw)
217
- if (repository !== undefined) config.skillRepositories.push(repository)
292
+ if (repository !== undefined) config.skillRepositories = [repository]
218
293
  } catch {
219
- // No legacy document, or it is unreadable: start empty.
220
- }
221
- if (config.skillRepositories.length > 0) {
222
- try {
223
- await writeUtilsConfig(config)
224
- } catch {
225
- // A read-only home must not turn discovery into a failure.
226
- }
294
+ // No legacy document, or it is unreadable: keep the shipped default.
227
295
  }
296
+ await persistQuietly(config)
228
297
  return { config, existed: false, path }
229
298
  }
230
299