@aiwayds/dsh-model-sync 0.8.0 → 0.10.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.
Files changed (68) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +9 -4
  3. package/README.zh-CN.md +9 -4
  4. package/lib/builtin-catalog-snapshot.d.ts +5 -1
  5. package/lib/builtin-catalog-snapshot.js +13 -10
  6. package/lib/builtin-catalog-snapshot.js.map +1 -1
  7. package/lib/index.d.ts +366 -0
  8. package/lib/index.js +729 -13
  9. package/lib/index.js.map +1 -1
  10. package/lib/opencode-go-diagnose.d.ts +74 -0
  11. package/lib/opencode-go-diagnose.js +146 -0
  12. package/lib/opencode-go-diagnose.js.map +1 -0
  13. package/lib/opencode-go-grouping.d.ts +29 -0
  14. package/lib/opencode-go-grouping.js +77 -0
  15. package/lib/opencode-go-grouping.js.map +1 -0
  16. package/lib/opencode-go-journal.d.ts +110 -0
  17. package/lib/opencode-go-journal.js +406 -0
  18. package/lib/opencode-go-journal.js.map +1 -0
  19. package/lib/opencode-go-migrate.d.ts +343 -0
  20. package/lib/opencode-go-migrate.js +1300 -0
  21. package/lib/opencode-go-migrate.js.map +1 -0
  22. package/lib/opencode-go-migration.d.ts +227 -0
  23. package/lib/opencode-go-migration.js +384 -0
  24. package/lib/opencode-go-migration.js.map +1 -0
  25. package/lib/opencode-go-planner.d.ts +153 -0
  26. package/lib/opencode-go-planner.js +339 -0
  27. package/lib/opencode-go-planner.js.map +1 -0
  28. package/lib/opencode-go-profile.d.ts +57 -0
  29. package/lib/opencode-go-profile.js +103 -0
  30. package/lib/opencode-go-profile.js.map +1 -0
  31. package/lib/opencode-go-scheduler.d.ts +128 -0
  32. package/lib/opencode-go-scheduler.js +241 -0
  33. package/lib/opencode-go-scheduler.js.map +1 -0
  34. package/lib/opencode-go-source.d.ts +117 -0
  35. package/lib/opencode-go-source.js +331 -0
  36. package/lib/opencode-go-source.js.map +1 -0
  37. package/lib/opencode-go-store.d.ts +18 -0
  38. package/lib/opencode-go-store.js +68 -0
  39. package/lib/opencode-go-store.js.map +1 -0
  40. package/lib/opencode-go-sync.d.ts +94 -0
  41. package/lib/opencode-go-sync.js +364 -0
  42. package/lib/opencode-go-sync.js.map +1 -0
  43. package/lib/opencode-go-writer.d.ts +132 -0
  44. package/lib/opencode-go-writer.js +966 -0
  45. package/lib/opencode-go-writer.js.map +1 -0
  46. package/lib/provider-native.d.ts +3 -1
  47. package/lib/provider-native.js +4 -2
  48. package/lib/provider-native.js.map +1 -1
  49. package/lib/remote-catalog.d.ts +37 -0
  50. package/lib/remote-catalog.js +261 -3
  51. package/lib/remote-catalog.js.map +1 -1
  52. package/package.json +18 -18
  53. package/src/builtin-catalog-snapshot.ts +18 -11
  54. package/src/index.ts +873 -12
  55. package/src/opencode-go-diagnose.ts +222 -0
  56. package/src/opencode-go-grouping.ts +97 -0
  57. package/src/opencode-go-journal.ts +458 -0
  58. package/src/opencode-go-migrate.ts +1694 -0
  59. package/src/opencode-go-migration.ts +552 -0
  60. package/src/opencode-go-planner.ts +505 -0
  61. package/src/opencode-go-profile.ts +114 -0
  62. package/src/opencode-go-scheduler.ts +315 -0
  63. package/src/opencode-go-source.ts +424 -0
  64. package/src/opencode-go-store.ts +73 -0
  65. package/src/opencode-go-sync.ts +503 -0
  66. package/src/opencode-go-writer.ts +1189 -0
  67. package/src/provider-native.ts +3 -1
  68. package/src/remote-catalog.ts +293 -3
@@ -0,0 +1,384 @@
1
+ // P1d-1: migration gate + single-writer route authority (design §14.1 / §14.6 /
2
+ // §14.7, M-4 / M-5; ADR-008). Pure state/fingerprint/routeWriter functions plus
3
+ // an injected migration-record store seam. No timer, no network, no settings
4
+ // write lives here — the migrate *command* itself is P1d-2. Tests inject an
5
+ // `appliedFingerprint` record to exercise the applied state without apply().
6
+ //
7
+ // Priority (§14.7.1): ① migration gate (`none`) > ② single-writer ownership >
8
+ // ③ ordinary §6.2.4 write semantics. A skipped route must always produce a
9
+ // report line (never silent), which callers build from RouteWriterDecision.
10
+ import { createHash } from 'node:crypto';
11
+ import { GO_SLOT_ROUTES } from "./opencode-go-grouping.js";
12
+ import { GO_MIGRATION_STORE_KEY_BASE, isUnscopedStoreKey, scopedStoreKey } from "./opencode-go-profile.js";
13
+ import { loadModelsStore } from "./remote-catalog.js";
14
+ /** Cordis service seam: tests register a fake record store under this name. */
15
+ export const GO_MIGRATION_STORE_SERVICE = 'goMigrationStore';
16
+ /**
17
+ * Base name of the models-store raw slot holding the go migration record
18
+ * (P1d-1). B1: profile-scoped stores persist it as
19
+ * `<profileKey>#migration:opencode-go`; the unscoped name is kept only for
20
+ * legacy callers/tests and is never claimed by a scoped store. The literal is
21
+ * owned by opencode-go-profile.ts so `isUnscopedStoreKey` can distinguish a
22
+ * scoped migration record from a legacy key without guessing the key shape.
23
+ */
24
+ export const GO_MIGRATION_STORE_KEY = GO_MIGRATION_STORE_KEY_BASE;
25
+ /**
26
+ * D6: the ONE computation of the "unclaimable record" status label. Both
27
+ * `migrate status` (opencode-go-migrate.ts) and the go report's status refresh
28
+ * (index.ts `loadMigrationStatus`) use this helper, so the same store state
29
+ * yields the same label in both commands (W1). Call only when the profile's own
30
+ * scoped read() found no record — a foreign record must never relabel a profile
31
+ * that already has its own applied/drifted record (B1 isolation).
32
+ */
33
+ export function unclaimedRecordState(unclaimed) {
34
+ if (unclaimed.some((record) => record.kind === 'foreign-profile'))
35
+ return 'foreign-profile';
36
+ if (unclaimed.length > 0)
37
+ return 'legacy-store';
38
+ return undefined;
39
+ }
40
+ /** Fixed report line required by §14.6 for every migration-gate skip. */
41
+ export const MIGRATION_GATE_HINT = '检测到未迁移配置,已跳过写入;运行 /model-sync migrate plan';
42
+ // ---------------------------------------------------------------------------
43
+ // Fingerprint + state detection (pure)
44
+ // ---------------------------------------------------------------------------
45
+ function isRecord(value) {
46
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
47
+ }
48
+ /** Canonical JSON (recursive key sort) — the ownership-entry hash algorithm (§14.1). */
49
+ function canonicalize(value) {
50
+ if (Array.isArray(value))
51
+ return value.map(canonicalize);
52
+ if (!isRecord(value))
53
+ return value;
54
+ const out = {};
55
+ for (const key of Object.keys(value).sort())
56
+ out[key] = canonicalize(value[key]);
57
+ return out;
58
+ }
59
+ /** sha256 of canonical JSON — section fingerprint (§14.1). */
60
+ export function fingerprintSection(value) {
61
+ return createHash('sha256').update(JSON.stringify(canonicalize(value))).digest('hex');
62
+ }
63
+ /** Extract only the `opencode-go*` provider sections that currently exist. */
64
+ export function readGoProviderSections(source, routes = Object.values(GO_SLOT_ROUTES)) {
65
+ // A SettingsDescriptor carries `user.providers`; a raw providers object is
66
+ // itself the route→section map. Discriminate on `user` rather than `ns` so a
67
+ // partial descriptor fixture (no `ns`) still resolves correctly.
68
+ const providers = isRecord(source) && isRecord(source.user)
69
+ ? source.user.providers
70
+ : isRecord(source) ? source.providers : undefined;
71
+ if (!isRecord(providers))
72
+ return undefined;
73
+ const sections = {};
74
+ for (const route of routes) {
75
+ const data = providers[route];
76
+ if (isRecord(data))
77
+ sections[route] = data;
78
+ }
79
+ return sections;
80
+ }
81
+ /** Fingerprint of the current `opencode-go*` sections (empty object when absent). */
82
+ export function fingerprintGoRoutes(source, routes) {
83
+ return fingerprintSection(readGoProviderSections(source, routes) ?? {});
84
+ }
85
+ // --- Two-level applied fingerprint (§14.7.4) --------------------------------
86
+ //
87
+ // Only STABLE fields take part in drift detection:
88
+ // appliedIdentity = sha256(canonical({ <route>: {api, baseURL, displayName,
89
+ // apiKeyEnv} })) — from settings
90
+ // appliedManagedIds = { <route>: sorted ids in the ownership ledger } — from ledger
91
+ // appliedFingerprint = sha256(canonical({ appliedIdentity, appliedManagedIds }))
92
+ //
93
+ // Excluded on purpose: models[] capacity/capability fields (name,
94
+ // contextWindow, maxTokens, input, reasoningEfforts, compat — all rewritten
95
+ // every sync round), user-owned ids, model order, modelOverrides, and any
96
+ // time/usage field. Those are handled by the managed-vs-user-owned repair
97
+ // rules, never by closing the gate. Identity fields are never rewritten by a
98
+ // sync round, and the ledger ids change only through our own successful
99
+ // writes (which immediately re-persist the fingerprint), so a normal sync
100
+ // cannot create an identity-level mismatch. An external identity edit →
101
+ // `drifted`; an external models edit → still `applied`.
102
+ const IDENTITY_FIELDS = ['api', 'baseURL', 'displayName', 'apiKeyEnv'];
103
+ /** Identity map: only the four stable fields of each present go section. */
104
+ export function goIdentityOf(sections) {
105
+ const out = {};
106
+ for (const [route, section] of Object.entries(sections ?? {})) {
107
+ if (!isRecord(section))
108
+ continue;
109
+ const entry = {};
110
+ for (const field of IDENTITY_FIELDS) {
111
+ if (section[field] !== undefined)
112
+ entry[field] = section[field];
113
+ }
114
+ out[route] = entry;
115
+ }
116
+ return out;
117
+ }
118
+ /**
119
+ * Hash of the current route identities — stable across ordinary sync rounds.
120
+ * `routes` restricts the compared set: a record keeps the route set it was
121
+ * written with, so routes created later by a sync round never look like drift.
122
+ */
123
+ export function fingerprintGoIdentity(sections, routes) {
124
+ const all = goIdentityOf(sections);
125
+ if (routes === undefined)
126
+ return fingerprintSection(all);
127
+ return fingerprintSection(Object.fromEntries(routes.map((route) => [route, all[route] ?? {}])));
128
+ }
129
+ /** Full applied fingerprint = sha256(canonical({ identity, managedIds })). */
130
+ export function appliedFingerprintOf(identity, managedIds) {
131
+ return fingerprintSection({ identity, managedIds: managedIds ?? {} });
132
+ }
133
+ /**
134
+ * ONE route-set convention for the two-level applied fingerprint, shared by
135
+ * `migrationStatusOf` (loadMigrationStatus) and the writer's `onOwnWrite`:
136
+ * identity routes are the record's `appliedIdentityRoutes` (or the routes
137
+ * present in settings when the record has none); managed-id routes are exactly
138
+ * the entries present in the supplied map. A configured-but-absent route must
139
+ * NOT be fabricated as `<route>: []` — migrate/onOwnWrite persist only routes
140
+ * with a real ledger entry, and inventing empty ones here makes the first
141
+ * healthy round look like a fingerprint drift (`fingerprint-healed` noise).
142
+ */
143
+ export function appliedFingerprintFieldsOf(sections, record, managedIds) {
144
+ const identityRoutes = record?.appliedIdentityRoutes ?? Object.keys(sections ?? {});
145
+ const identity = fingerprintGoIdentity(sections, identityRoutes);
146
+ return { identity, appliedFingerprint: appliedFingerprintOf(identity, managedIds) };
147
+ }
148
+ /**
149
+ * Ledger ids for exactly the routes that HAVE a ledger entry. This is the
150
+ * managed-id half of the shared fingerprint convention above: no entry means
151
+ * no route in the map (never an empty array), so a normal first onboarding and
152
+ * a later own write hash identically. Unreadable entries are skipped too —
153
+ * the strict per-mutate gate already fails closed on a record read failure.
154
+ */
155
+ export async function goLedgerManagedIds(routes, readEntry) {
156
+ const managedIds = {};
157
+ for (const route of routes) {
158
+ let entry;
159
+ try {
160
+ entry = await readEntry(route);
161
+ }
162
+ catch {
163
+ continue; // unreadable ledger ⇒ no managed ids (never delete), no fabricated entry
164
+ }
165
+ if (entry !== undefined)
166
+ managedIds[route] = Object.keys(entry.managed ?? {}).sort();
167
+ }
168
+ return managedIds;
169
+ }
170
+ function hasInlineModels(sections, chatRoute) {
171
+ const chat = sections[chatRoute];
172
+ return isRecord(chat) && Array.isArray(chat.models);
173
+ }
174
+ /**
175
+ * Determine migration state (§14.1 / §14.7.4). Order matters: absent →
176
+ * identity-based applied/drifted (new records) → full-fingerprint match
177
+ * (legacy records written before the two-level split) → recorded legacy/drifted
178
+ * → unrecorded legacy form. Only an IDENTITY mismatch is `drifted`: a models
179
+ * edit (capacity fields, user-owned ids, order) leaves identity intact and is
180
+ * repaired by the writer instead of closing the gate.
181
+ */
182
+ export function migrationStateOf(sections, record, chatRoute = GO_SLOT_ROUTES.chat) {
183
+ if (sections === undefined || Object.keys(sections).length === 0)
184
+ return 'absent';
185
+ const fingerprint = fingerprintSection(sections);
186
+ if (record?.appliedIdentity !== undefined) {
187
+ return fingerprintGoIdentity(sections, record.appliedIdentityRoutes) === record.appliedIdentity
188
+ ? 'applied' : 'drifted';
189
+ }
190
+ // Backward compatibility with the pre-§14.7.4 full-section fingerprint.
191
+ if (record?.appliedFingerprint !== undefined && fingerprint === record.appliedFingerprint)
192
+ return 'applied';
193
+ if (record !== undefined && (record.appliedFingerprint !== undefined || record.legacyFingerprint !== undefined)) {
194
+ if (record.legacyFingerprint !== undefined && fingerprint === record.legacyFingerprint) {
195
+ return hasInlineModels(sections, chatRoute) ? 'legacy-inline' : 'legacy-inherit';
196
+ }
197
+ return 'drifted';
198
+ }
199
+ return hasInlineModels(sections, chatRoute) ? 'legacy-inline' : 'legacy-inherit';
200
+ }
201
+ /**
202
+ * Full status from a settings descriptor (or raw providers object) + record.
203
+ * `currentManagedIds`, when supplied, comes from the live ownership ledger and
204
+ * drives the §14.7.4 self-heal check (identity matches but the stored full
205
+ * fingerprint is stale because the fingerprint write failed after a commit).
206
+ */
207
+ export function migrationStatusOf(source, record, routes, currentManagedIds) {
208
+ const sections = readGoProviderSections(source, routes);
209
+ // Compare only the route set the record was written with — routes added by a
210
+ // later sync round must not invalidate an otherwise unchanged identity. The
211
+ // shared helper keeps this EXACT route set in sync with onOwnWrite, so a
212
+ // healthy round cannot emit a phantom `fingerprint-healed`.
213
+ const managedIds = currentManagedIds ?? record?.appliedManagedIds ?? {};
214
+ const { identity, appliedFingerprint: expectedFingerprint } = appliedFingerprintFieldsOf(sections, record, managedIds);
215
+ return {
216
+ state: migrationStateOf(sections, record, routes?.[0] ?? GO_SLOT_ROUTES.chat),
217
+ fingerprint: fingerprintSection(sections ?? {}),
218
+ identity,
219
+ appliedIdentity: record?.appliedIdentity,
220
+ appliedManagedIds: record?.appliedManagedIds,
221
+ appliedFingerprint: record?.appliedFingerprint,
222
+ legacyFingerprint: record?.legacyFingerprint,
223
+ applying: record?.applying === true,
224
+ fingerprintHealed: record?.appliedIdentity !== undefined
225
+ && identity === record.appliedIdentity
226
+ && record.appliedFingerprint !== expectedFingerprint,
227
+ expectedFingerprint,
228
+ };
229
+ }
230
+ // ---------------------------------------------------------------------------
231
+ // Single-writer route authority (pure)
232
+ // ---------------------------------------------------------------------------
233
+ /** True for any configured go route id or the `opencode-go*` prefix. */
234
+ export function isGoRoute(route, customRoutes) {
235
+ if (customRoutes?.includes(route) === true)
236
+ return true;
237
+ return Object.values(GO_SLOT_ROUTES).includes(route) || route.startsWith('opencode-go');
238
+ }
239
+ function isZenRoute(route, cfg) {
240
+ if (cfg.zenRoutes?.includes(route) === true)
241
+ return true;
242
+ return route.startsWith('opencode-zen');
243
+ }
244
+ /**
245
+ * The single decision point every write path must call before settings.mutate.
246
+ *
247
+ * Rules (§14.7.1, task P1d-1):
248
+ * - go.enabled=true + caller≠'go' on an `opencode-go*` route → always skip;
249
+ * the legacy pi.dev path may never take over, even if the gate returned none.
250
+ * - go.enabled=true + caller='go' + state=applied with a matching fingerprint,
251
+ * or state=absent → write. legacy-inherit / legacy-inline / drifted → skip
252
+ * (migration gate) and report MIGRATION_GATE_HINT.
253
+ * - `applying` → skip (M-5: auto rounds drop while apply is in progress).
254
+ * - go.enabled=false → v0.9.0 behavior restored for go routes (pi.dev owner).
255
+ * - zen routes mode: only the zen writer owns zen routes; other routes are
256
+ * unaffected (pi.dev owner) and keep their original behavior.
257
+ */
258
+ export function routeWriter(route, cfg, migration) {
259
+ const goRoute = isGoRoute(route, cfg.goRoutes);
260
+ if (goRoute && cfg.goEnabled) {
261
+ if (cfg.caller !== 'go') {
262
+ return {
263
+ decision: 'skip',
264
+ owner: 'go',
265
+ reason: 'skipped-route-owner: go (single-writer: opencode.go.enabled=true; legacy pi.dev path must never write opencode-go* routes)',
266
+ };
267
+ }
268
+ if (migration.applying) {
269
+ return {
270
+ decision: 'skip',
271
+ owner: 'none',
272
+ reason: `skipped-route-owner: none (migration applying; ${MIGRATION_GATE_HINT})`,
273
+ };
274
+ }
275
+ // §14.7.4: a record with `appliedIdentity` is judged applied by IDENTITY
276
+ // match alone — models edits must not close the gate. Legacy records fall
277
+ // back to the full-section fingerprint equality they were written with.
278
+ if (migration.state === 'applied'
279
+ && ((migration.appliedIdentity !== undefined && migration.identity === migration.appliedIdentity)
280
+ || (migration.appliedFingerprint !== undefined && migration.fingerprint === migration.appliedFingerprint))) {
281
+ return { decision: 'write', owner: 'go', reason: 'owner=go (migration applied; identity/fingerprint matched)' };
282
+ }
283
+ if (migration.state === 'absent') {
284
+ return { decision: 'write', owner: 'go', reason: 'owner=go (absent; no pre-existing section to migrate)' };
285
+ }
286
+ return {
287
+ decision: 'skip',
288
+ owner: 'none',
289
+ reason: `skipped-route-owner: none (migration gate: ${migration.state}; ${MIGRATION_GATE_HINT})`,
290
+ };
291
+ }
292
+ // go.enabled=false (or non-go route): zen routes still have a single owner.
293
+ if (cfg.zenMode === 'routes' && isZenRoute(route, cfg)) {
294
+ if (cfg.caller !== 'zen') {
295
+ return { decision: 'skip', owner: 'zen', reason: 'skipped-route-owner: zen (zen routes mode: only the zen writer owns zen routes)' };
296
+ }
297
+ return { decision: 'write', owner: 'zen', reason: 'owner=zen' };
298
+ }
299
+ // Everything else keeps the original pi.dev behavior. A go caller writing a
300
+ // non-go route is a no-op in practice; allow it so callers can pass a uniform
301
+ // decision function without changing other routes' semantics.
302
+ return { decision: 'write', owner: 'pi.dev', reason: 'owner=pi.dev' };
303
+ }
304
+ // ---------------------------------------------------------------------------
305
+ // Injected store (production adapter reads the same models-store JSON)
306
+ // ---------------------------------------------------------------------------
307
+ /**
308
+ * Build a migration store over the models-store raw-slot accessor.
309
+ *
310
+ * `profileKey` scopes the record slot to `<profileKey>#migration:opencode-go`
311
+ * and stamps the same identity into the record. Reads require the stamp to
312
+ * match — a record from another profile (or an unscoped legacy record with no
313
+ * stamp) is treated as "no record", so state detection falls back to
314
+ * legacy/absent and the migration gate stays closed. Omitting `profileKey`
315
+ * keeps the pre-fix unscoped behavior for legacy callers/tests only.
316
+ */
317
+ export function createFileMigrationStateStore(accessor, profileKey) {
318
+ const slot = profileKey === undefined
319
+ ? GO_MIGRATION_STORE_KEY
320
+ : scopedStoreKey(profileKey, GO_MIGRATION_STORE_KEY);
321
+ return {
322
+ async read() {
323
+ let raw;
324
+ try {
325
+ raw = await accessor.readRaw(slot);
326
+ }
327
+ catch {
328
+ return undefined; // unreadable ⇒ no record ⇒ conservative legacy detection
329
+ }
330
+ if (!isRecord(raw))
331
+ return undefined;
332
+ // Read-side ownership check (B1): never adopt a record stamped for a
333
+ // different profile, and never claim an unstamped legacy record.
334
+ if (profileKey !== undefined && raw.profileKey !== profileKey)
335
+ return undefined;
336
+ return raw;
337
+ },
338
+ async write(record) {
339
+ // writeRaw is queue-serialized atomic temp+rename, i.e. the SAME queue
340
+ // that persists the ownership ledger (§14.7.4: settings → ledger → fingerprint).
341
+ const stamped = profileKey === undefined ? record : { ...record, profileKey };
342
+ await accessor.writeRaw(slot, stamped);
343
+ },
344
+ async legacyKeys() {
345
+ const keys = await accessor.listRawKeys();
346
+ return keys.filter((key) => key === GO_MIGRATION_STORE_KEY || isUnscopedStoreKey(key));
347
+ },
348
+ async unclaimedRecords() {
349
+ // No resolved profile → no "foreign" notion; legacy callers keep their
350
+ // pre-fix read behavior. Status in production always has a profileKey.
351
+ if (profileKey === undefined)
352
+ return [];
353
+ const keys = await accessor.listRawKeys();
354
+ const out = [];
355
+ for (const key of keys) {
356
+ const isUnscopedSlot = key === GO_MIGRATION_STORE_KEY;
357
+ const isScopedSlot = !isUnscopedSlot && key.endsWith(`#${GO_MIGRATION_STORE_KEY}`);
358
+ if (!isUnscopedSlot && !isScopedSlot)
359
+ continue;
360
+ let raw;
361
+ try {
362
+ raw = await accessor.readRaw(key);
363
+ }
364
+ catch {
365
+ continue; // unreadable slot is advisory only; never changes the gate
366
+ }
367
+ if (!isRecord(raw))
368
+ continue;
369
+ const stamp = typeof raw.profileKey === 'string' && raw.profileKey.length > 0
370
+ ? raw.profileKey : undefined;
371
+ if (stamp === profileKey)
372
+ continue; // our own record — claimable as before
373
+ const kind = stamp === undefined ? 'legacy-store' : 'foreign-profile';
374
+ out.push(stamp === undefined ? { kind, key } : { kind, key, profileKey: stamp });
375
+ }
376
+ return out;
377
+ },
378
+ };
379
+ }
380
+ /** Production factory; tests pass a temp-file accessor or inject a fake store. */
381
+ export function createModelsStoreMigrationStateStore(storePath, profileKey) {
382
+ return createFileMigrationStateStore(loadModelsStore(storePath), profileKey);
383
+ }
384
+ //# sourceMappingURL=opencode-go-migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-go-migration.js","sourceRoot":"","sources":["../src/opencode-go-migration.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1D,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC1G,OAAO,EAAE,eAAe,EAA4B,MAAM,qBAAqB,CAAA;AAG/E,+EAA+E;AAC/E,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAA;AAC5D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,2BAA2B,CAAA;AA0FjE;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAA8C;IAE9C,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,CAAC;QAAE,OAAO,iBAAiB,CAAA;IAC3F,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,cAAc,CAAA;IAC/C,OAAO,SAAS,CAAA;AAClB,CAAC;AAsCD,yEAAyE;AACzE,MAAM,CAAC,MAAM,mBAAmB,GAAG,4CAA4C,CAAA;AAE/E,8EAA8E;AAC9E,uCAAuC;AACvC,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK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CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;YAClF,CAAC;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,oCAAoC,CAAC,SAAkB,EAAE,UAAmB;IAC1F,OAAO,6BAA6B,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAA;AAC9E,CAAC"}
@@ -0,0 +1,153 @@
1
+ import type { SettingsModelProfile } from './translate.ts';
2
+ import type { GoModelRecord } from './opencode-go-source.ts';
3
+ import { type GoRouteSlot } from './opencode-go-grouping.ts';
4
+ /** Host `api` value per slot (llm-pi-ai PROTOCOLS, report 19 §1). */
5
+ export declare const GO_API_BY_SLOT: Readonly<Record<GoRouteSlot, string>>;
6
+ /** The only display field the host uses to group providers (F22/13). */
7
+ export declare const GO_DISPLAY_NAME_BY_SLOT: Readonly<Record<GoRouteSlot, string>>;
8
+ /**
9
+ * Fallback host baseURLs — the values report 19 confirmed end-to-end. Normally
10
+ * the baseURL comes from the official payload (§6.2.2); these are used only
11
+ * when a record carries no per-protocol `base_url`.
12
+ */
13
+ export declare const GO_BASE_URL_BY_SLOT: Readonly<Record<GoRouteSlot, string>>;
14
+ /** Official protocol keys that back each slot (§6.2.2 table). */
15
+ export declare const GO_PROTOCOLS_BY_SLOT: Readonly<Record<GoRouteSlot, readonly string[]>>;
16
+ /**
17
+ * Normalize an official `base_url` for host use. Only `msg` changes: pi-ai
18
+ * calls `beta.messages.create` and appends `/v1/messages?beta=true`, so the
19
+ * trailing `/v1` must be stripped (ADR-003 / report 19 negative control).
20
+ */
21
+ export declare function normalizeGoBaseUrl(raw: string, slot: GoRouteSlot): string;
22
+ export interface GoPlannedRouteFields {
23
+ api: string;
24
+ baseURL: string;
25
+ displayName: string;
26
+ apiKeyEnv: string;
27
+ }
28
+ /**
29
+ * Build the route fields for a slot from the payload's per-protocol base_url.
30
+ * `ref` defaults to the P0-derived `OPENCODE_GO_API_KEY`.
31
+ */
32
+ export declare function planGoRouteFields(slot: GoRouteSlot, entries: readonly GoModelRecord[], ref?: string): GoPlannedRouteFields;
33
+ /** Official GoModelRecord → host SettingsModelProfile. `created` never enters. */
34
+ export declare function mapGoModelToProfile(entry: GoModelRecord): SettingsModelProfile;
35
+ export interface GoManagedModel {
36
+ /** Hash of the profile the plugin last wrote for this id. */
37
+ hash: string;
38
+ }
39
+ export interface GoOwnershipEntry {
40
+ /** Route fields the plugin last wrote (used to recognize a fully-owned route). */
41
+ routeFields?: Partial<GoPlannedRouteFields>;
42
+ /** Plugin-managed model ids and the hash of their last written profile. */
43
+ managed: Record<string, GoManagedModel>;
44
+ /**
45
+ * Raw models present in the route before the plugin first claimed it (design
46
+ * §6.1 / ADR-004). Audit-only: never used as a whole-route write-back.
47
+ * Rollback restores from `preManagedSection` (§14.3), not from this field.
48
+ */
49
+ preManagedSnapshot?: SettingsModelProfile[];
50
+ /**
51
+ * P1d-2: the COMPLETE raw provider section captured before `migrate apply`
52
+ * (all fields — api/baseURL/displayName/apiKeyEnv/models — exactly as found).
53
+ * `null` means the route did not exist before the migration. This is the
54
+ * authoritative rollback target (design §14.3 whole-section snapshot) and is
55
+ * persisted on the same models-store queue as the rest of the ledger entry;
56
+ * unlike the in-progress backup it is NOT released when apply succeeds.
57
+ */
58
+ preManagedSection?: Record<string, unknown> | null;
59
+ /**
60
+ * P1d-2: ids `migrate apply` newly introduced on this route (merged desired
61
+ * ids absent from the pre-apply section). Rollback removes these, while ids
62
+ * the user adds after apply are left untouched.
63
+ */
64
+ appliedAddedIds?: string[];
65
+ /**
66
+ * Consecutive successful rounds an id has been absent from the desired set.
67
+ * The planner only flags a deletion-candidate; the writer owns this counter
68
+ * and deletes only once it reaches `confirmRemovals` (design §6.2.4 / V5).
69
+ */
70
+ missing?: Record<string, number>;
71
+ }
72
+ export type GoOwnershipLedger = Readonly<Record<string, GoOwnershipEntry>>;
73
+ /** Ledger key: one route's ownership is invisible under a different key. */
74
+ export declare function goOwnershipKey(route: string, keyFingerprint: string): string;
75
+ /** The raw current state of one provider route in settings. */
76
+ export interface GoRouteState {
77
+ exists: boolean;
78
+ api?: string;
79
+ baseURL?: string;
80
+ displayName?: string;
81
+ apiKeyEnv?: string;
82
+ /** Raw models array (no schema defaults applied). */
83
+ models: readonly SettingsModelProfile[];
84
+ /** Ids covered by a non-empty modelOverrides key on this route. */
85
+ overrideIds?: readonly string[];
86
+ }
87
+ export interface GoRouteConflict {
88
+ slot: GoRouteSlot;
89
+ route: string;
90
+ field: 'api' | 'baseURL' | 'apiKeyEnv';
91
+ expected: string;
92
+ actual: string;
93
+ reason: string;
94
+ }
95
+ export type GoPlanReportLevel = 'info' | 'warn' | 'error';
96
+ export interface GoPlanReportEntry {
97
+ level: GoPlanReportLevel;
98
+ /** Stable machine code (e.g. route-conflict, kept-user-owned, unknown-protocol). */
99
+ code: string;
100
+ route?: string;
101
+ slot?: GoRouteSlot;
102
+ id?: string;
103
+ message: string;
104
+ }
105
+ export interface GoPlannedRoute {
106
+ slot: GoRouteSlot;
107
+ route: string;
108
+ fields: GoPlannedRouteFields;
109
+ /** Complete merged models array, sorted by id (never an empty write — see unset/skip). */
110
+ models: SettingsModelProfile[];
111
+ /** Empty and fully plugin-managed: caller should unset providers.<route>. */
112
+ unset: boolean;
113
+ /** Conflict, empty main route, or empty route with user content: write nothing. */
114
+ skip: boolean;
115
+ }
116
+ export interface GoPlanResult {
117
+ routes: GoPlannedRoute[];
118
+ /** Routes the caller should unset (never paired with `models: []`). */
119
+ unsetRoutes: string[];
120
+ conflicts: GoRouteConflict[];
121
+ report: GoPlanReportEntry[];
122
+ /** Shallow copy of the ledger updated only for this key's routes. */
123
+ nextOwnership: Record<string, GoOwnershipEntry>;
124
+ /**
125
+ * The mapped desired profiles per route BEFORE the merge with current
126
+ * settings. The writer needs this to do a first-round conservative claim
127
+ * (official desired ∩ current, never ids outside the desired set) — the
128
+ * merged `routes[].models` already contains kept user entries and cannot be
129
+ * used for that distinction.
130
+ */
131
+ desiredByRoute: Record<string, SettingsModelProfile[]>;
132
+ }
133
+ export interface GoPlannerOptions {
134
+ /** sha256(key) first 16 hex from the source result; '-' when no key. */
135
+ keyFingerprint: string;
136
+ entries: readonly GoModelRecord[];
137
+ /** Current state of the go routes, keyed by route id. */
138
+ currentRoutes: Readonly<Record<string, GoRouteState>>;
139
+ ownership: GoOwnershipLedger;
140
+ /** go.ref; defaults to P0's deriveKeyRef('opencode-go'). */
141
+ ref?: string;
142
+ /** go.routes overrides (default GO_SLOT_ROUTES). */
143
+ routes?: Partial<Record<GoRouteSlot, string>>;
144
+ /** go.pinnedModels — protected from deletion (design A4). */
145
+ pinnedModels?: readonly string[];
146
+ }
147
+ /** Stable hash of a settings profile — the "现值哈希" of the deletion gates. */
148
+ export declare function profileHash(profile: SettingsModelProfile): string;
149
+ /**
150
+ * Build the write plan. Pure: identical inputs always produce an identical
151
+ * plan (report/order included). No mutation of `options` or its nested values.
152
+ */
153
+ export declare function planGoRoutes(options: GoPlannerOptions): GoPlanResult;