@aiwayds/dsh-model-sync 0.6.0 → 0.6.1

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.
package/README.md CHANGED
@@ -67,7 +67,7 @@ The host auto-cleans: the bundles entry is spliced out of the profile and the pl
67
67
 
68
68
  ## Usage
69
69
 
70
- Configure the plugin under the `dsh-model-sync` settings entry — on dsh 0.1.7+ the entry id (the same stable id the bundle patch always mounted) is the settings namespace; edit it in the settings UI or your profile patch. Every key is optional, and every key is a volatile field, so edits apply without restarting the plugin:
70
+ Configure the plugin under the `dsh-model-sync` settings entry — on dsh 0.1.7+ the entry id (the same stable id the bundle patch always mounted) is the settings namespace; edit it in the settings UI or your profile patch. Every key is optional, and every key is a volatile field, so edits apply without restarting the plugin. Upgrading from a pre-0.1.7 install: a legacy top-level `model-sync:` section in the old `settings.yaml` is imported once into the new entry automatically at the next plugin boot (the audit record lands in `~/.dsh/storages/dsh-model-sync/legacy-import.json`):
71
71
 
72
72
  | Key | Default | Description |
73
73
  |---|---|---|
@@ -83,7 +83,7 @@ Configure the plugin under the `dsh-model-sync` settings entry — on dsh 0.1.7+
83
83
  | `providerNativeFetch` | `true` | Union each mapped provider's first-party `/models` listing into the pi.dev result (additions only) |
84
84
  | `keepDeprecatedBuiltin` | `false` | Opt back into emitting builtin ids the official default model list dropped (dsh 0.1.7 removed `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp`; the snapshot keeps the data but no longer syncs them by default) |
85
85
 
86
- Example (settings section `dsh-model-sync`; a legacy `settings.yaml` `model-sync:` section is **not** auto-imported by dsh 0.1.7 — re-declare your values once under the new entry):
86
+ Example (settings section `dsh-model-sync`; a legacy `settings.yaml` `model-sync:` section is not auto-imported by the dsh 0.1.7 host itself — the plugin recovers it once at boot, see above):
87
87
 
88
88
  ```yaml
89
89
  dsh-model-sync:
package/README.zh-CN.md CHANGED
@@ -67,7 +67,7 @@ dsh plugin remove @aiwayds/dsh-model-sync
67
67
 
68
68
  ## 用法
69
69
 
70
- 在 `dsh-model-sync` 设置条目下配置本插件——dsh 0.1.7+ 的 entry id(与 bundle patch 一直使用的稳定 id 相同)即 settings 命名空间,在设置 UI 或 profile patch 中编辑即可。每个键都是可选的,且全部是 volatile 字段,改动无需重启插件即可生效:
70
+ 在 `dsh-model-sync` 设置条目下配置本插件——dsh 0.1.7+ 的 entry id(与 bundle patch 一直使用的稳定 id 相同)即 settings 命名空间,在设置 UI 或 profile patch 中编辑即可。每个键都是可选的,且全部是 volatile 字段,改动无需重启插件即可生效。从 0.1.7 之前升级:旧 `settings.yaml` 里的 `model-sync:` 段会在下次插件 boot 时一次性自动迁入新条目(审计档在 `~/.dsh/storages/dsh-model-sync/legacy-import.json`):
71
71
 
72
72
  | 键 | 默认值 | 说明 |
73
73
  |---|---|---|
@@ -85,7 +85,7 @@ dsh plugin remove @aiwayds/dsh-model-sync
85
85
 
86
86
  示例:
87
87
 
88
- 示例(settings 段名 `dsh-model-sync`;dsh 0.1.7 不会自动导入旧 `settings.yaml` 里的 `model-sync:` 段——请把原值在新条目下重新声明一次):
88
+ 示例(settings 段名 `dsh-model-sync`;dsh 0.1.7 宿主本身不会自动导入旧 `settings.yaml` 里的 `model-sync:` 段——插件会在 boot 时一次性迁回,见上文):
89
89
 
90
90
  ```yaml
91
91
  dsh-model-sync:
package/lib/index.d.ts CHANGED
@@ -143,7 +143,7 @@ export interface ModelSyncService {
143
143
  * the plugin syncs when `managedRoutes` is empty. Not part of the public
144
144
  * runtime surface; subject to change without notice. */
145
145
  export declare const DEFAULT_ROUTES_LIST: string[];
146
- export declare function apply(ctx: Context, config: ModelSyncConfigValue): void;
146
+ export declare function apply(ctx: Context, config: ModelSyncConfigValue): Promise<void>;
147
147
  /**
148
148
  * Get entries from builtin catalog that are not in pi.dev (for keepBuiltinOnly).
149
149
  * Returns minimal RemoteCatalogEntry-shaped objects — translateEntries only
package/lib/index.js CHANGED
@@ -21,6 +21,7 @@ import { BUILTIN_CATALOG_SNAPSHOT } from "./builtin-catalog-snapshot.js";
21
21
  import { refreshLiveCatalog, getLiveBuiltinCatalogForRoute } from "./live-catalog.js";
22
22
  import { checkRouteCredential } from "./route-credential.js";
23
23
  import { PROVIDER_NATIVE_ENDPOINTS, fetchProviderNativeModels, mergeProviderNativeEntries, resolveRouteCredentialValue, } from "./provider-native.js";
24
+ import { runLegacySettingsImport, resolveDshHome, } from "./legacy-import.js";
24
25
  export const name = 'dsh-model-sync';
25
26
  /** The settings seam this plugin consumes (its own config namespace). */
26
27
  export const inject = ['settings'];
@@ -100,7 +101,7 @@ const DEFAULT_ROUTES = [
100
101
  * the plugin syncs when `managedRoutes` is empty. Not part of the public
101
102
  * runtime surface; subject to change without notice. */
102
103
  export const DEFAULT_ROUTES_LIST = DEFAULT_ROUTES;
103
- export function apply(ctx, config) {
104
+ export async function apply(ctx, config) {
104
105
  // On dsh 0.1.7 the resolved Config arrives as apply()'s second argument:
105
106
  // every volatile field is a stable reference (see VolatileRef), so the
106
107
  // reads below are live views — no scope.get() and no scope.watch() (both
@@ -442,6 +443,31 @@ export function apply(ctx, config) {
442
443
  return commands.register(definition);
443
444
  }, 'dsh-model-sync: /model-sync');
444
445
  });
446
+ // One-time legacy settings import (0.1.5 → 0.1.7 upgrade path, see
447
+ // legacy-import.ts): recover the old `model-sync:` section for hosts where
448
+ // the 0.1.7 one-shot settings.yaml import never carried it over. Awaited
449
+ // as apply()'s LAST step — every registration above stays synchronous
450
+ // (fake-ctx tests keep working), while a real boot, whose loader awaits
451
+ // the fiber setup, settles the import before activation completes. Fully
452
+ // contained: any failure only warns and leaves the audit marker unwritten,
453
+ // so the next boot retries; activation never depends on this.
454
+ try {
455
+ await runLegacySettingsImport({
456
+ home: resolveDshHome(),
457
+ settings: ctx.settings,
458
+ logger: ctx.logger,
459
+ // The volatile refs read fresh, and the update itself fires
460
+ // settings/document-updated for this entry — the timers armed above
461
+ // with the pre-import value re-arm to it without a restart.
462
+ getCurrent: (key) => {
463
+ const slot = config[key];
464
+ return typeof slot?.get === 'function' ? slot.get() : slot;
465
+ },
466
+ });
467
+ }
468
+ catch (error) {
469
+ ctx.logger.warn('model-sync: legacy settings import failed (will retry next boot): %o', error);
470
+ }
445
471
  }
446
472
  // ---------------------------------------------------------------------------
447
473
  // Builtin catalog helpers (uses shared snapshot)
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE;;;;;;;;;;;;GAYG;AAEH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAWxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EACL,kBAAkB,EAClB,eAAe,GAEhB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,gBAAgB,GAKjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,cAAc,GAIf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,EAAE,oBAAoB,EAA+B,MAAM,uBAAuB,CAAA;AACzF,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,GAE5B,MAAM,sBAAsB,CAAA;AAE7B,MAAM,CAAC,MAAM,IAAI,GAAG,gBAAgB,CAAA;AAEpC,yEAAyE;AACzE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAAU,CAAC,CAAA;AAElC,6EAA6E;AAC7E,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,2EAA2E;AAC3E,MAAM,YAAY,GAAG,gBAAgB,CAAA;AAErC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B;;;;OAIG;IACH,SAAS,EAAE,CAAC,C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wBAAwB,CAC/B,IAAoC,EACpC,KAAa;IAEb,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACxC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,SAAgD,CAAA;IAC7E,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAwC,CAAA;IACzE,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;IAC/B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAA;IAC5C,OAAO,MAAgC,CAAA;AACzC,CAAC"}
@@ -0,0 +1,72 @@
1
+ /** Profile entry id the recovered values are written to (index.ts OWN_ENTRY_ID). */
2
+ export declare const ENTRY_ID = "dsh-model-sync";
3
+ /** Legacy top-level section name in the old settings.yaml. */
4
+ export declare const LEGACY_SECTION = "model-sync";
5
+ /** Storage dir name for the audit marker (repo dir name, host convention). */
6
+ export declare const STORAGE_DIR_NAME = "dsh-model-sync";
7
+ /** Legacy keys worth recovering, mapped 1:1 onto Config keys of the same name. */
8
+ export declare const LEGACY_KEYS: readonly ["writeMode", "intervalMinutes"];
9
+ export type LegacyKey = (typeof LEGACY_KEYS)[number];
10
+ /** The settings seam the import writes through (`ctx.settings.update`). */
11
+ export interface SettingsUpdateSeam {
12
+ update(ns: string, patch: object): Promise<void>;
13
+ }
14
+ /** Minimal logger surface (both sinks optional — bare harnesses have none). */
15
+ export interface LegacyImportLogger {
16
+ info?(message: string): void;
17
+ warn?(message: string): void;
18
+ }
19
+ export interface LegacyImportInput {
20
+ /** Resolved dsh home (`resolveDshHome()` at the call site). */
21
+ home: string;
22
+ /** `ctx.settings` — absent/unusable seams skip the import without a marker. */
23
+ settings?: SettingsUpdateSeam | undefined;
24
+ /** Host logger (optional). */
25
+ logger?: LegacyImportLogger | undefined;
26
+ /** Current effective value for one legacy key (Volatile ref `.get()` at the call site). */
27
+ getCurrent(key: LegacyKey): unknown;
28
+ }
29
+ export type LegacyImportOutcome = 'imported' | 'no-op' | 'no-legacy' | 'no-section' | 'marker-exists' | 'no-settings' | 'update-failed';
30
+ export interface LegacyImportResult {
31
+ outcome: LegacyImportOutcome;
32
+ /** Keys written through settings.update (also in the marker). */
33
+ imported: Record<string, unknown>;
34
+ /** Keys not imported, with the reason (audit trail). */
35
+ skipped: Record<string, string>;
36
+ }
37
+ /** Dsh home resolution: `$DSH_HOME` when set, `~/.dsh` otherwise (the same
38
+ * shape remote-catalog.ts bakes in for the models-store path). */
39
+ export declare function resolveDshHome(): string;
40
+ /** Candidates in priority order: the host's renamed document first. */
41
+ export declare function legacySettingsCandidates(home: string): string[];
42
+ /** Audit marker path: `<home>/storages/<dir>/legacy-import.json`. */
43
+ export declare function legacyMarkerPath(home: string): string;
44
+ /**
45
+ * Scalar inference for one flat `key: value` value. Quoted values are
46
+ * unquoted; a single-line quoted flow-JSON value (`'["a","b"]'`) is
47
+ * JSON-parsed after unquoting — a malformed one stays a string. Unquoted
48
+ * flow collections are kept as strings (conservative: this is not a full
49
+ * YAML parser). Empty never reaches here (the line parser skips value-less
50
+ * keys — they open a nested block).
51
+ */
52
+ export declare function inferScalar(raw: string): unknown;
53
+ /**
54
+ * Flat section parser: locate the top-level `section:` line and collect its
55
+ * DIRECT children (`key: value` at one common indent) until the next
56
+ * top-level key. Deliberately conservative — NOT a YAML parser:
57
+ * - `key:` with an empty value (opens a nested map/sequence) is skipped, and
58
+ * the deeper lines under it never match the child indent, so folded values
59
+ * are skipped whole;
60
+ * - lines at any other indent are ignored;
61
+ * - an inline value on the header line itself (`section: x`) is not a flat
62
+ * map → `{}`.
63
+ * Pure function — tests run it against literal strings.
64
+ */
65
+ export declare function parseFlatSection(raw: string, section: string): Record<string, unknown>;
66
+ /**
67
+ * Run the one-time import. Resolves with the outcome; only throws on truly
68
+ * unexpected I/O errors (the apply()-side catch contains those). The marker
69
+ * is written for every settled outcome EXCEPT the retry-worthy failures
70
+ * (`no-settings`, `update-failed`) — those must re-run at the next boot.
71
+ */
72
+ export declare function runLegacySettingsImport(input: LegacyImportInput): Promise<LegacyImportResult>;
@@ -0,0 +1,241 @@
1
+ // Plan C (settings-seam): one-time legacy settings import for the 0.1.5 → 0.1.7 upgrade.
2
+ /**
3
+ * The dsh 0.1.7 host renames the old `~/.dsh/settings.yaml` to
4
+ * `settings.yaml.imported` and imports its sections into the active profile
5
+ * keyed by "section name = entry id". This plugin's old section was named
6
+ * `model-sync` — which HAPPENS to equal the entry id (`OWN_ENTRY_ID` in
7
+ * index.ts), so the host's one-shot import usually already carried the values
8
+ * over. But installs where the import never fired (host skipped the rename,
9
+ * a manually restored settings.yaml, plugin installed after the host
10
+ * upgrade) still hold their config in the legacy section. This module
11
+ * recovers it once:
12
+ *
13
+ * 1. read `<home>/settings.yaml.imported` (preferred) →
14
+ * `<home>/settings.yaml` (fallback);
15
+ * 2. flat-parse the `model-sync:` section (scalars only, conservative);
16
+ * 3. keep keys whose legacy value differs from the current effective value;
17
+ * 4. `settings.update('dsh-model-sync', patch)` → on success write the
18
+ * audit marker `<home>/storages/dsh-model-sync/legacy-import.json`;
19
+ * on failure warn and write nothing (the next boot retries);
20
+ * 5. marker present → the whole migration is skipped (idempotent — a
21
+ * later manual edit of the imported file must not resurrect old values).
22
+ *
23
+ * A marker is written for EVERY settled outcome (imported / no-op /
24
+ * no-legacy / no-section) so this runs at most once per home. Never throws
25
+ * into the caller beyond what the apply()-side catch contains: plugin
26
+ * activation must not depend on this.
27
+ *
28
+ * Deliberately a standalone copy of the same contract dsh-topics-memory
29
+ * implements: the two plugins share no runtime, only the convention.
30
+ *
31
+ * @module dsh-model-sync/legacy-import
32
+ */
33
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
34
+ import { homedir } from 'node:os';
35
+ import { join } from 'node:path';
36
+ /** Profile entry id the recovered values are written to (index.ts OWN_ENTRY_ID). */
37
+ export const ENTRY_ID = 'dsh-model-sync';
38
+ /** Legacy top-level section name in the old settings.yaml. */
39
+ export const LEGACY_SECTION = 'model-sync';
40
+ /** Storage dir name for the audit marker (repo dir name, host convention). */
41
+ export const STORAGE_DIR_NAME = 'dsh-model-sync';
42
+ /** Legacy keys worth recovering, mapped 1:1 onto Config keys of the same name. */
43
+ export const LEGACY_KEYS = ['writeMode', 'intervalMinutes'];
44
+ /** Dsh home resolution: `$DSH_HOME` when set, `~/.dsh` otherwise (the same
45
+ * shape remote-catalog.ts bakes in for the models-store path). */
46
+ export function resolveDshHome() {
47
+ const env = process.env.DSH_HOME?.trim();
48
+ if (env !== undefined && env !== '')
49
+ return env;
50
+ return join(homedir(), '.dsh');
51
+ }
52
+ /** Candidates in priority order: the host's renamed document first. */
53
+ export function legacySettingsCandidates(home) {
54
+ return [join(home, 'settings.yaml.imported'), join(home, 'settings.yaml')];
55
+ }
56
+ /** Audit marker path: `<home>/storages/<dir>/legacy-import.json`. */
57
+ export function legacyMarkerPath(home) {
58
+ return join(home, 'storages', STORAGE_DIR_NAME, 'legacy-import.json');
59
+ }
60
+ function escapeRegExp(s) {
61
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62
+ }
63
+ /** A fully quoted scalar: balanced matching quote pair. */
64
+ function isQuoted(s) {
65
+ return s.length >= 2 && ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'")));
66
+ }
67
+ function unquote(s) {
68
+ const inner = s.slice(1, -1);
69
+ // Double quotes: unescape \" and \\; single quotes: '' is a literal '.
70
+ if (s.startsWith('"'))
71
+ return inner.replaceAll('\\"', '"').replaceAll('\\\\', '\\');
72
+ return inner.replaceAll("''", "'");
73
+ }
74
+ /**
75
+ * Scalar inference for one flat `key: value` value. Quoted values are
76
+ * unquoted; a single-line quoted flow-JSON value (`'["a","b"]'`) is
77
+ * JSON-parsed after unquoting — a malformed one stays a string. Unquoted
78
+ * flow collections are kept as strings (conservative: this is not a full
79
+ * YAML parser). Empty never reaches here (the line parser skips value-less
80
+ * keys — they open a nested block).
81
+ */
82
+ export function inferScalar(raw) {
83
+ const s = raw.trim();
84
+ if (isQuoted(s)) {
85
+ const inner = unquote(s);
86
+ const t = inner.trim();
87
+ if (t.startsWith('[') || t.startsWith('{')) {
88
+ try {
89
+ return JSON.parse(t);
90
+ }
91
+ catch {
92
+ // not JSON after all — keep the unquoted string
93
+ }
94
+ }
95
+ return inner;
96
+ }
97
+ if (s === 'true' || s === 'True' || s === 'TRUE')
98
+ return true;
99
+ if (s === 'false' || s === 'False' || s === 'FALSE')
100
+ return false;
101
+ if (/^-?\d+$/.test(s) || /^-?\d+\.\d+$/.test(s))
102
+ return Number(s);
103
+ return s;
104
+ }
105
+ /**
106
+ * Flat section parser: locate the top-level `section:` line and collect its
107
+ * DIRECT children (`key: value` at one common indent) until the next
108
+ * top-level key. Deliberately conservative — NOT a YAML parser:
109
+ * - `key:` with an empty value (opens a nested map/sequence) is skipped, and
110
+ * the deeper lines under it never match the child indent, so folded values
111
+ * are skipped whole;
112
+ * - lines at any other indent are ignored;
113
+ * - an inline value on the header line itself (`section: x`) is not a flat
114
+ * map → `{}`.
115
+ * Pure function — tests run it against literal strings.
116
+ */
117
+ export function parseFlatSection(raw, section) {
118
+ const lines = raw.split('\n').map((l) => l.replace(/\r$/, ''));
119
+ const header = new RegExp(`^${escapeRegExp(section)}:(.*)$`);
120
+ const start = lines.findIndex((l) => header.test(l));
121
+ if (start < 0)
122
+ return {};
123
+ // An inline header value means the section is not a block map of children.
124
+ if (lines[start].replace(header, '$1').trim() !== '')
125
+ return {};
126
+ const out = {};
127
+ let childIndent;
128
+ for (let i = start + 1; i < lines.length; i++) {
129
+ const line = lines[i];
130
+ if (line.trim() === '' || line.trimStart().startsWith('#'))
131
+ continue;
132
+ const indent = line.length - line.trimStart().length;
133
+ if (indent === 0)
134
+ break; // next top-level key — section over
135
+ if (childIndent === undefined)
136
+ childIndent = indent;
137
+ if (indent !== childIndent)
138
+ continue; // nested block content — skipped
139
+ const match = /^([^\s:][^:]*):(?:[ \t]+(.*))?$/.exec(line.trim());
140
+ if (match === null)
141
+ continue; // not a `key: value` line — skipped
142
+ if (match[2] === undefined || match[2].trim() === '')
143
+ continue; // opens a nested block
144
+ out[match[1].trim()] = inferScalar(match[2]);
145
+ }
146
+ return out;
147
+ }
148
+ /**
149
+ * Run the one-time import. Resolves with the outcome; only throws on truly
150
+ * unexpected I/O errors (the apply()-side catch contains those). The marker
151
+ * is written for every settled outcome EXCEPT the retry-worthy failures
152
+ * (`no-settings`, `update-failed`) — those must re-run at the next boot.
153
+ */
154
+ export async function runLegacySettingsImport(input) {
155
+ const skipped = {};
156
+ const imported = {};
157
+ const warn = (message) => {
158
+ try {
159
+ input.logger?.warn?.(message);
160
+ }
161
+ catch {
162
+ // contained — a broken logger must not break the import
163
+ }
164
+ };
165
+ const info = (message) => {
166
+ try {
167
+ input.logger?.info?.(message);
168
+ }
169
+ catch {
170
+ // contained
171
+ }
172
+ };
173
+ const markerPath = legacyMarkerPath(input.home);
174
+ if (existsSync(markerPath))
175
+ return { outcome: 'marker-exists', imported, skipped };
176
+ // A settings seam that cannot accept the patch is a retry-worthy state:
177
+ // return WITHOUT reading/marking, so a host that mounts the service later
178
+ // (and a test harness pointing at a real home) neither imports nor writes.
179
+ const settings = input.settings;
180
+ if (settings === undefined || typeof settings.update !== 'function') {
181
+ return { outcome: 'no-settings', imported, skipped };
182
+ }
183
+ // Locate the legacy document.
184
+ const source = legacySettingsCandidates(input.home).find((p) => existsSync(p));
185
+ if (source === undefined) {
186
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'no-legacy', source: undefined, imported, skipped });
187
+ return { outcome: 'no-legacy', imported, skipped };
188
+ }
189
+ const section = parseFlatSection(readFileSync(source, 'utf8'), LEGACY_SECTION);
190
+ // The marker records the source BASENAME: the marker lives inside the same
191
+ // home, so the directory part is implied.
192
+ const sourceName = source.slice(source.lastIndexOf('/') + 1);
193
+ const present = Object.keys(section);
194
+ if (present.length === 0) {
195
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'no-section', source: sourceName, imported, skipped });
196
+ return { outcome: 'no-section', imported, skipped };
197
+ }
198
+ // Key-level rule: import only when the legacy value differs from the
199
+ // current effective value; keys this plugin does not know are recorded and
200
+ // left alone (an unknown key would be rejected by the host's schema).
201
+ for (const key of present) {
202
+ if (!LEGACY_KEYS.includes(key)) {
203
+ skipped[key] = 'unknown-key';
204
+ continue;
205
+ }
206
+ const legacyValue = section[key];
207
+ if (legacyValue === input.getCurrent(key))
208
+ skipped[key] = 'equal';
209
+ else
210
+ imported[key] = legacyValue;
211
+ }
212
+ if (Object.keys(imported).length === 0) {
213
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'no-op', source: sourceName, imported, skipped });
214
+ info(`${ENTRY_ID}: legacy settings import (${LEGACY_SECTION} → ${ENTRY_ID}): nothing to import (all values equal or unknown)`);
215
+ return { outcome: 'no-op', imported, skipped };
216
+ }
217
+ try {
218
+ await settings.update(ENTRY_ID, imported);
219
+ }
220
+ catch (error) {
221
+ // No marker: the next boot retries the import.
222
+ warn(`${ENTRY_ID}: legacy settings import failed (will retry next boot): ${error instanceof Error ? error.message : String(error)}`);
223
+ return { outcome: 'update-failed', imported, skipped };
224
+ }
225
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'imported', source: sourceName, imported, skipped });
226
+ info(`${ENTRY_ID}: legacy settings import (${LEGACY_SECTION} → ${ENTRY_ID}): ${Object.keys(imported).join(', ')}`);
227
+ return { outcome: 'imported', imported, skipped };
228
+ }
229
+ /** Persist the audit marker; a failed write leaves no marker (harmless — the
230
+ * next boot re-runs and converges, every step after the marker check is
231
+ * idempotent). */
232
+ function writeMarker(path, marker) {
233
+ try {
234
+ mkdirSync(join(path, '..'), { recursive: true });
235
+ writeFileSync(path, `${JSON.stringify(marker, null, 2)}\n`);
236
+ }
237
+ catch {
238
+ // contained — see above
239
+ }
240
+ }
241
+ //# sourceMappingURL=legacy-import.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-import.js","sourceRoot":"","sources":["../src/legacy-import.ts"],"names":[],"mappings":"AAAA,yFAAyF;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,oFAAoF;AACpF,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AAExC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAA;AAE1C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAA;AAEhD,kFAAkF;AAClF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,iBAAiB,CAAU,CAAA;AA2CpE;mEACmE;AACnE,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;IACxC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,GAAG,CAAA;IAC/C,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,MAAM,CAAC,CAAA;AAChC,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,wBAAwB,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAA;AAC5E,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,OAAO,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,gBAA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E,IAAI,EAAE,CAAC,CAAA;QAChD,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;IAC7D,CAAC;IAAC,MAAM,CAAC;QACP,wBAAwB;IAC1B,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwayds/dsh-model-sync",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "dsh plugin: keep llm-pi-ai provider routes' model lists in step with the pi.dev gateway, written through the official settings seam",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -34,7 +34,7 @@
34
34
  "build": "tsc -p tsconfig.json",
35
35
  "check": "tsc --noEmit -p tsconfig.json",
36
36
  "pretest": "tsc -p tsconfig.json",
37
- "test": "node --test test/live-catalog.test.mjs test/diff.test.mjs test/translate.test.mjs test/writer.test.mjs test/writer-overrides.test.mjs test/remote-catalog.test.mjs test/provider-native.test.mjs test/serviceability.test.mjs test/command.test.mjs test/real-cordis.test.mjs test/route-credential.test.mjs",
37
+ "test": "node --test test/live-catalog.test.mjs test/diff.test.mjs test/translate.test.mjs test/writer.test.mjs test/writer-overrides.test.mjs test/remote-catalog.test.mjs test/provider-native.test.mjs test/serviceability.test.mjs test/command.test.mjs test/real-cordis.test.mjs test/route-credential.test.mjs test/legacy-import.test.mjs",
38
38
  "smoke": "node scripts/smoke-boot.mjs"
39
39
  },
40
40
  "dependencies": {},
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/node": "^24.0.0",
71
- "@deepseek-ai/cordis": "4.0.2",
71
+ "@deepseek-ai/cordis": "4.0.4",
72
72
  "@deepseek-ai/dsh-agent": "0.1.7-rc.1",
73
73
  "@deepseek-ai/dsh-attachment": "0.1.7-rc.1",
74
74
  "@deepseek-ai/dsh-brand": "0.1.7-rc.1",
package/src/index.ts CHANGED
@@ -54,6 +54,12 @@ import {
54
54
  resolveRouteCredentialValue,
55
55
  type NativeCredentialContext,
56
56
  } from './provider-native.ts'
57
+ import {
58
+ runLegacySettingsImport,
59
+ resolveDshHome,
60
+ type LegacyImportLogger,
61
+ type SettingsUpdateSeam,
62
+ } from './legacy-import.ts'
57
63
 
58
64
  export const name = 'dsh-model-sync'
59
65
 
@@ -182,7 +188,7 @@ const DEFAULT_ROUTES = [
182
188
  * runtime surface; subject to change without notice. */
183
189
  export const DEFAULT_ROUTES_LIST = DEFAULT_ROUTES
184
190
 
185
- export function apply(ctx: Context, config: ModelSyncConfigValue): void {
191
+ export async function apply(ctx: Context, config: ModelSyncConfigValue): Promise<void> {
186
192
  // On dsh 0.1.7 the resolved Config arrives as apply()'s second argument:
187
193
  // every volatile field is a stable reference (see VolatileRef), so the
188
194
  // reads below are live views — no scope.get() and no scope.watch() (both
@@ -565,6 +571,31 @@ export function apply(ctx: Context, config: ModelSyncConfigValue): void {
565
571
  return commands.register(definition)
566
572
  }, 'dsh-model-sync: /model-sync')
567
573
  })
574
+
575
+ // One-time legacy settings import (0.1.5 → 0.1.7 upgrade path, see
576
+ // legacy-import.ts): recover the old `model-sync:` section for hosts where
577
+ // the 0.1.7 one-shot settings.yaml import never carried it over. Awaited
578
+ // as apply()'s LAST step — every registration above stays synchronous
579
+ // (fake-ctx tests keep working), while a real boot, whose loader awaits
580
+ // the fiber setup, settles the import before activation completes. Fully
581
+ // contained: any failure only warns and leaves the audit marker unwritten,
582
+ // so the next boot retries; activation never depends on this.
583
+ try {
584
+ await runLegacySettingsImport({
585
+ home: resolveDshHome(),
586
+ settings: ctx.settings as SettingsUpdateSeam,
587
+ logger: (ctx as unknown as { logger?: LegacyImportLogger }).logger,
588
+ // The volatile refs read fresh, and the update itself fires
589
+ // settings/document-updated for this entry — the timers armed above
590
+ // with the pre-import value re-arm to it without a restart.
591
+ getCurrent: (key) => {
592
+ const slot = (config as unknown as Record<string, unknown>)[key] as { get?: unknown } | undefined
593
+ return typeof slot?.get === 'function' ? slot.get() : slot
594
+ },
595
+ })
596
+ } catch (error) {
597
+ ctx.logger.warn('model-sync: legacy settings import failed (will retry next boot): %o', error)
598
+ }
568
599
  }
569
600
 
570
601
  // ---------------------------------------------------------------------------
@@ -0,0 +1,284 @@
1
+ // Plan C (settings-seam): one-time legacy settings import for the 0.1.5 → 0.1.7 upgrade.
2
+
3
+ /**
4
+ * The dsh 0.1.7 host renames the old `~/.dsh/settings.yaml` to
5
+ * `settings.yaml.imported` and imports its sections into the active profile
6
+ * keyed by "section name = entry id". This plugin's old section was named
7
+ * `model-sync` — which HAPPENS to equal the entry id (`OWN_ENTRY_ID` in
8
+ * index.ts), so the host's one-shot import usually already carried the values
9
+ * over. But installs where the import never fired (host skipped the rename,
10
+ * a manually restored settings.yaml, plugin installed after the host
11
+ * upgrade) still hold their config in the legacy section. This module
12
+ * recovers it once:
13
+ *
14
+ * 1. read `<home>/settings.yaml.imported` (preferred) →
15
+ * `<home>/settings.yaml` (fallback);
16
+ * 2. flat-parse the `model-sync:` section (scalars only, conservative);
17
+ * 3. keep keys whose legacy value differs from the current effective value;
18
+ * 4. `settings.update('dsh-model-sync', patch)` → on success write the
19
+ * audit marker `<home>/storages/dsh-model-sync/legacy-import.json`;
20
+ * on failure warn and write nothing (the next boot retries);
21
+ * 5. marker present → the whole migration is skipped (idempotent — a
22
+ * later manual edit of the imported file must not resurrect old values).
23
+ *
24
+ * A marker is written for EVERY settled outcome (imported / no-op /
25
+ * no-legacy / no-section) so this runs at most once per home. Never throws
26
+ * into the caller beyond what the apply()-side catch contains: plugin
27
+ * activation must not depend on this.
28
+ *
29
+ * Deliberately a standalone copy of the same contract dsh-topics-memory
30
+ * implements: the two plugins share no runtime, only the convention.
31
+ *
32
+ * @module dsh-model-sync/legacy-import
33
+ */
34
+
35
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
36
+ import { homedir } from 'node:os'
37
+ import { join } from 'node:path'
38
+
39
+ /** Profile entry id the recovered values are written to (index.ts OWN_ENTRY_ID). */
40
+ export const ENTRY_ID = 'dsh-model-sync'
41
+
42
+ /** Legacy top-level section name in the old settings.yaml. */
43
+ export const LEGACY_SECTION = 'model-sync'
44
+
45
+ /** Storage dir name for the audit marker (repo dir name, host convention). */
46
+ export const STORAGE_DIR_NAME = 'dsh-model-sync'
47
+
48
+ /** Legacy keys worth recovering, mapped 1:1 onto Config keys of the same name. */
49
+ export const LEGACY_KEYS = ['writeMode', 'intervalMinutes'] as const
50
+
51
+ export type LegacyKey = (typeof LEGACY_KEYS)[number]
52
+
53
+ /** The settings seam the import writes through (`ctx.settings.update`). */
54
+ export interface SettingsUpdateSeam {
55
+ update(ns: string, patch: object): Promise<void>
56
+ }
57
+
58
+ /** Minimal logger surface (both sinks optional — bare harnesses have none). */
59
+ export interface LegacyImportLogger {
60
+ info?(message: string): void
61
+ warn?(message: string): void
62
+ }
63
+
64
+ export interface LegacyImportInput {
65
+ /** Resolved dsh home (`resolveDshHome()` at the call site). */
66
+ home: string
67
+ /** `ctx.settings` — absent/unusable seams skip the import without a marker. */
68
+ settings?: SettingsUpdateSeam | undefined
69
+ /** Host logger (optional). */
70
+ logger?: LegacyImportLogger | undefined
71
+ /** Current effective value for one legacy key (Volatile ref `.get()` at the call site). */
72
+ getCurrent(key: LegacyKey): unknown
73
+ }
74
+
75
+ export type LegacyImportOutcome =
76
+ | 'imported' // ≥1 key written through settings.update, marker written
77
+ | 'no-op' // section found but every key equal/unknown, marker written
78
+ | 'no-legacy' // neither legacy file exists, marker written
79
+ | 'no-section' // legacy file exists without a `model-sync:` section, marker written
80
+ | 'marker-exists' // already migrated before — nothing touched
81
+ | 'no-settings' // settings seam unusable — no marker, retried next boot
82
+ | 'update-failed' // settings.update rejected — no marker, retried next boot
83
+
84
+ export interface LegacyImportResult {
85
+ outcome: LegacyImportOutcome
86
+ /** Keys written through settings.update (also in the marker). */
87
+ imported: Record<string, unknown>
88
+ /** Keys not imported, with the reason (audit trail). */
89
+ skipped: Record<string, string>
90
+ }
91
+
92
+ /** Dsh home resolution: `$DSH_HOME` when set, `~/.dsh` otherwise (the same
93
+ * shape remote-catalog.ts bakes in for the models-store path). */
94
+ export function resolveDshHome(): string {
95
+ const env = process.env.DSH_HOME?.trim()
96
+ if (env !== undefined && env !== '') return env
97
+ return join(homedir(), '.dsh')
98
+ }
99
+
100
+ /** Candidates in priority order: the host's renamed document first. */
101
+ export function legacySettingsCandidates(home: string): string[] {
102
+ return [join(home, 'settings.yaml.imported'), join(home, 'settings.yaml')]
103
+ }
104
+
105
+ /** Audit marker path: `<home>/storages/<dir>/legacy-import.json`. */
106
+ export function legacyMarkerPath(home: string): string {
107
+ return join(home, 'storages', STORAGE_DIR_NAME, 'legacy-import.json')
108
+ }
109
+
110
+ function escapeRegExp(s: string): string {
111
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
112
+ }
113
+
114
+ /** A fully quoted scalar: balanced matching quote pair. */
115
+ function isQuoted(s: string): boolean {
116
+ return s.length >= 2 && ((s.startsWith('"') && s.endsWith('"')) || (s.startsWith("'") && s.endsWith("'")))
117
+ }
118
+
119
+ function unquote(s: string): string {
120
+ const inner = s.slice(1, -1)
121
+ // Double quotes: unescape \" and \\; single quotes: '' is a literal '.
122
+ if (s.startsWith('"')) return inner.replaceAll('\\"', '"').replaceAll('\\\\', '\\')
123
+ return inner.replaceAll("''", "'")
124
+ }
125
+
126
+ /**
127
+ * Scalar inference for one flat `key: value` value. Quoted values are
128
+ * unquoted; a single-line quoted flow-JSON value (`'["a","b"]'`) is
129
+ * JSON-parsed after unquoting — a malformed one stays a string. Unquoted
130
+ * flow collections are kept as strings (conservative: this is not a full
131
+ * YAML parser). Empty never reaches here (the line parser skips value-less
132
+ * keys — they open a nested block).
133
+ */
134
+ export function inferScalar(raw: string): unknown {
135
+ const s = raw.trim()
136
+ if (isQuoted(s)) {
137
+ const inner = unquote(s)
138
+ const t = inner.trim()
139
+ if (t.startsWith('[') || t.startsWith('{')) {
140
+ try {
141
+ return JSON.parse(t)
142
+ } catch {
143
+ // not JSON after all — keep the unquoted string
144
+ }
145
+ }
146
+ return inner
147
+ }
148
+ if (s === 'true' || s === 'True' || s === 'TRUE') return true
149
+ if (s === 'false' || s === 'False' || s === 'FALSE') return false
150
+ if (/^-?\d+$/.test(s) || /^-?\d+\.\d+$/.test(s)) return Number(s)
151
+ return s
152
+ }
153
+
154
+ /**
155
+ * Flat section parser: locate the top-level `section:` line and collect its
156
+ * DIRECT children (`key: value` at one common indent) until the next
157
+ * top-level key. Deliberately conservative — NOT a YAML parser:
158
+ * - `key:` with an empty value (opens a nested map/sequence) is skipped, and
159
+ * the deeper lines under it never match the child indent, so folded values
160
+ * are skipped whole;
161
+ * - lines at any other indent are ignored;
162
+ * - an inline value on the header line itself (`section: x`) is not a flat
163
+ * map → `{}`.
164
+ * Pure function — tests run it against literal strings.
165
+ */
166
+ export function parseFlatSection(raw: string, section: string): Record<string, unknown> {
167
+ const lines = raw.split('\n').map((l) => l.replace(/\r$/, ''))
168
+ const header = new RegExp(`^${escapeRegExp(section)}:(.*)$`)
169
+ const start = lines.findIndex((l) => header.test(l))
170
+ if (start < 0) return {}
171
+ // An inline header value means the section is not a block map of children.
172
+ if (lines[start].replace(header, '$1').trim() !== '') return {}
173
+ const out: Record<string, unknown> = {}
174
+ let childIndent: number | undefined
175
+ for (let i = start + 1; i < lines.length; i++) {
176
+ const line = lines[i]
177
+ if (line.trim() === '' || line.trimStart().startsWith('#')) continue
178
+ const indent = line.length - line.trimStart().length
179
+ if (indent === 0) break // next top-level key — section over
180
+ if (childIndent === undefined) childIndent = indent
181
+ if (indent !== childIndent) continue // nested block content — skipped
182
+ const match = /^([^\s:][^:]*):(?:[ \t]+(.*))?$/.exec(line.trim())
183
+ if (match === null) continue // not a `key: value` line — skipped
184
+ if (match[2] === undefined || match[2].trim() === '') continue // opens a nested block
185
+ out[match[1].trim()] = inferScalar(match[2])
186
+ }
187
+ return out
188
+ }
189
+
190
+ /**
191
+ * Run the one-time import. Resolves with the outcome; only throws on truly
192
+ * unexpected I/O errors (the apply()-side catch contains those). The marker
193
+ * is written for every settled outcome EXCEPT the retry-worthy failures
194
+ * (`no-settings`, `update-failed`) — those must re-run at the next boot.
195
+ */
196
+ export async function runLegacySettingsImport(input: LegacyImportInput): Promise<LegacyImportResult> {
197
+ const skipped: Record<string, string> = {}
198
+ const imported: Record<string, unknown> = {}
199
+ const warn = (message: string): void => {
200
+ try {
201
+ input.logger?.warn?.(message)
202
+ } catch {
203
+ // contained — a broken logger must not break the import
204
+ }
205
+ }
206
+ const info = (message: string): void => {
207
+ try {
208
+ input.logger?.info?.(message)
209
+ } catch {
210
+ // contained
211
+ }
212
+ }
213
+
214
+ const markerPath = legacyMarkerPath(input.home)
215
+ if (existsSync(markerPath)) return { outcome: 'marker-exists', imported, skipped }
216
+
217
+ // A settings seam that cannot accept the patch is a retry-worthy state:
218
+ // return WITHOUT reading/marking, so a host that mounts the service later
219
+ // (and a test harness pointing at a real home) neither imports nor writes.
220
+ const settings = input.settings
221
+ if (settings === undefined || typeof settings.update !== 'function') {
222
+ return { outcome: 'no-settings', imported, skipped }
223
+ }
224
+
225
+ // Locate the legacy document.
226
+ const source = legacySettingsCandidates(input.home).find((p) => existsSync(p))
227
+ if (source === undefined) {
228
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'no-legacy', source: undefined, imported, skipped })
229
+ return { outcome: 'no-legacy', imported, skipped }
230
+ }
231
+
232
+ const section = parseFlatSection(readFileSync(source, 'utf8'), LEGACY_SECTION)
233
+ // The marker records the source BASENAME: the marker lives inside the same
234
+ // home, so the directory part is implied.
235
+ const sourceName = source.slice(source.lastIndexOf('/') + 1)
236
+ const present = Object.keys(section)
237
+ if (present.length === 0) {
238
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'no-section', source: sourceName, imported, skipped })
239
+ return { outcome: 'no-section', imported, skipped }
240
+ }
241
+
242
+ // Key-level rule: import only when the legacy value differs from the
243
+ // current effective value; keys this plugin does not know are recorded and
244
+ // left alone (an unknown key would be rejected by the host's schema).
245
+ for (const key of present) {
246
+ if (!(LEGACY_KEYS as readonly string[]).includes(key)) {
247
+ skipped[key] = 'unknown-key'
248
+ continue
249
+ }
250
+ const legacyValue = section[key]
251
+ if (legacyValue === input.getCurrent(key as LegacyKey)) skipped[key] = 'equal'
252
+ else imported[key] = legacyValue
253
+ }
254
+
255
+ if (Object.keys(imported).length === 0) {
256
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'no-op', source: sourceName, imported, skipped })
257
+ info(`${ENTRY_ID}: legacy settings import (${LEGACY_SECTION} → ${ENTRY_ID}): nothing to import (all values equal or unknown)`)
258
+ return { outcome: 'no-op', imported, skipped }
259
+ }
260
+
261
+ try {
262
+ await settings.update(ENTRY_ID, imported)
263
+ } catch (error) {
264
+ // No marker: the next boot retries the import.
265
+ warn(`${ENTRY_ID}: legacy settings import failed (will retry next boot): ${error instanceof Error ? error.message : String(error)}`)
266
+ return { outcome: 'update-failed', imported, skipped }
267
+ }
268
+
269
+ writeMarker(markerPath, { at: new Date().toISOString(), outcome: 'imported', source: sourceName, imported, skipped })
270
+ info(`${ENTRY_ID}: legacy settings import (${LEGACY_SECTION} → ${ENTRY_ID}): ${Object.keys(imported).join(', ')}`)
271
+ return { outcome: 'imported', imported, skipped }
272
+ }
273
+
274
+ /** Persist the audit marker; a failed write leaves no marker (harmless — the
275
+ * next boot re-runs and converges, every step after the marker check is
276
+ * idempotent). */
277
+ function writeMarker(path: string, marker: Record<string, unknown>): void {
278
+ try {
279
+ mkdirSync(join(path, '..'), { recursive: true })
280
+ writeFileSync(path, `${JSON.stringify(marker, null, 2)}\n`)
281
+ } catch {
282
+ // contained — see above
283
+ }
284
+ }