@aiwayds/dsh-model-sync 0.11.1 → 0.12.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.
@@ -1,77 +1,21 @@
1
- // P0 protocol grouping: official api-dictionary keys → route slots.
1
+ // Route topology for the opencode-go single-route (catalog-reuse) write shape.
2
2
  //
3
- // Pure logic (07-design.md §6.2.3). P0 uses it for the diagnostic's protocol
4
- // ownership column; P1 will reuse it for route planning. No settings/IO here.
3
+ // 0.12.0 collapsed the four protocol routes into ONE managed route: the host
4
+ // (dsh-llm-pi-ai) only reuses pi-ai's builtin catalog provider when a route
5
+ // carries NO `api` field, and pi-ai 1.6.0's opencode-go catalog entries each
6
+ // carry their own per-protocol baseUrl — so any baseURL written on the single
7
+ // route would point at the wrong endpoint. The plugin therefore manages only
8
+ // the `chat` route and treats the three old protocol routes as legacy cleanup
9
+ // targets.
10
+ //
11
+ // Pure constants only (07-design.md §6.2.2 as revised). No settings/IO here.
5
12
  export const GO_ROUTE_SLOTS = ['chat', 'msg', 'resp', 'google'];
6
- /** Default route id per slot (design §6.2.6). */
13
+ /** Default route id per slot (design §6.2.6). The `chat` id names the single
14
+ * managed route; msg/resp/google name the legacy routes sync cleans up. */
7
15
  export const GO_SLOT_ROUTES = {
8
16
  chat: 'opencode-go',
9
17
  msg: 'opencode-go-msg',
10
18
  resp: 'opencode-go-resp',
11
19
  google: 'opencode-go-google',
12
20
  };
13
- /** Official protocol names this plugin knows how to place. */
14
- export const GO_KNOWN_PROTOCOLS = new Set([
15
- 'chat-completions',
16
- 'messages',
17
- 'responses',
18
- 'interactions',
19
- 'generate-content',
20
- ]);
21
- /** Map an official protocol key to a route slot. */
22
- export function slotForProtocol(protocol) {
23
- switch (protocol) {
24
- case 'chat-completions': return 'chat';
25
- case 'messages': return 'msg';
26
- case 'responses': return 'resp';
27
- case 'interactions':
28
- case 'generate-content': return 'google';
29
- default: return undefined;
30
- }
31
- }
32
- /**
33
- * Group official model ids by protocol (design §6.2.3):
34
- * - chat-completions present → chat (wins over any other protocol)
35
- * - exactly {messages} → msg; exactly {responses} → resp
36
- * - subset of {interactions, generate-content} → google
37
- * - multiple non-chat protocols → recommended_api breaks the tie
38
- * - empty / unknown / otherwise unsupported → unassigned (reported, never written)
39
- */
40
- export function groupGoModelsByProtocol(entries) {
41
- const slots = { chat: [], msg: [], resp: [], google: [] };
42
- const unassigned = [];
43
- for (const entry of entries) {
44
- const protocols = entry.protocols;
45
- const unknown = protocols.filter((protocol) => !GO_KNOWN_PROTOCOLS.has(protocol));
46
- if (unknown.length > 0) {
47
- unassigned.push({ id: entry.id, protocols: [...protocols], reason: 'unknown-protocol' });
48
- continue;
49
- }
50
- let slot;
51
- if (protocols.length === 0) {
52
- // no placement
53
- }
54
- else if (protocols.includes('chat-completions')) {
55
- slot = 'chat';
56
- }
57
- else if (protocols.length === 1 && protocols[0] === 'messages') {
58
- slot = 'msg';
59
- }
60
- else if (protocols.length === 1 && protocols[0] === 'responses') {
61
- slot = 'resp';
62
- }
63
- else if (protocols.every((p) => p === 'interactions' || p === 'generate-content')) {
64
- slot = 'google';
65
- }
66
- else if (protocols.length > 1 && entry.recommendedProtocol !== undefined) {
67
- slot = slotForProtocol(entry.recommendedProtocol);
68
- }
69
- if (slot === undefined) {
70
- unassigned.push({ id: entry.id, protocols: [...protocols], reason: 'unsupported-protocol' });
71
- continue;
72
- }
73
- slots[slot].push(entry.id);
74
- }
75
- return { slots, unassigned };
76
- }
77
21
  //# sourceMappingURL=opencode-go-grouping.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"opencode-go-grouping.js","sourceRoot":"","sources":["../src/opencode-go-grouping.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAO9E,MAAM,CAAC,MAAM,cAAc,GAA2B,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AAEvF,iDAAiD;AACjD,MAAM,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C,EAAE,CAAC,CAAA;IAC5B,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA;AAC9B,CAAC"}
1
+ {"version":3,"file":"opencode-go-grouping.js","sourceRoot":"","sources":["../src/opencode-go-grouping.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,8EAA8E;AAC9E,WAAW;AACX,EAAE;AACF,6EAA6E;AAM7E,MAAM,CAAC,MAAM,cAAc,GAA2B,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AAEvF;4EAC4E;AAC5E,MAAM,CAAC,MAAM,cAAc,GAA0C;IACnE,IAAI,EAAE,aAAa;IACnB,GAAG,EAAE,iBAAiB;IACtB,IAAI,EAAE,kBAAkB;IACxB,MAAM,EAAE,oBAAoB;CAC7B,CAAA"}
@@ -9,7 +9,9 @@ import type { Logger, SettingsDescriptor, SettingsService } from './writer.ts';
9
9
  /** What apply will do with one route. */
10
10
  export type MigrationAction = 'create' | 'update' | 'keep' | 'unset';
11
11
  /** Classification of one id that exists in the current route (design §14.2). */
12
- export type MigrationIdKind = 'desired-chat' | 'desired-msg' | 'desired-resp' | 'desired-google' | 'legacy-other-protocol' | 'unknown-retired' | 'user-extra'
12
+ export type MigrationIdKind =
13
+ /** Official desired id — always targets the single managed route (0.12.0). */
14
+ 'desired' | 'legacy-other-protocol' | 'unknown-retired' | 'user-extra'
13
15
  /** Public catalog unavailable (offline/401/403) — fail-closed, never deleted (§14.2). */
14
16
  | 'unclassified';
15
17
  export interface MigrationIdClass {
@@ -18,10 +18,14 @@
18
18
  // §14.5 (commands), §14.6 (order + single flight), §14.7 (write authority),
19
19
  // V16/V17/V19/V20/V22. No timer, no network, no real ~/.dsh lives here.
20
20
  import { createHash } from 'node:crypto';
21
- import { GO_SLOT_ROUTES, groupGoModelsByProtocol, } from "./opencode-go-grouping.js";
22
- import { goOwnershipKey, mapGoModelToProfile, planGoRouteFields, profileHash, } from "./opencode-go-planner.js";
21
+ import { GO_SLOT_ROUTES, } from "./opencode-go-grouping.js";
22
+ import { goOwnershipKey, mapGoModelToProfile, planGoRouteFields, profileHash, GO_LEGACY_ROUTE_FIELDS, } from "./opencode-go-planner.js";
23
23
  import { appliedFingerprintOf, fingerprintGoIdentity, fingerprintSection, readGoProviderSections, routeWriter, unclaimedRecordState, } from "./opencode-go-migration.js";
24
- const OWNED_FIELDS = ['api', 'baseURL', 'displayName', 'apiKeyEnv'];
24
+ // 0.12.0 catalog-reuse: the only route field migrate writes is `apiKeyEnv`.
25
+ // `api`/`baseURL` are stripped (they make the host leave pi-ai's builtin
26
+ // catalog provider — and its x-opencode-session wrapping — behind), and
27
+ // `displayName` is never rewritten so a user rename survives the migration.
28
+ const OWNED_FIELDS = ['apiKeyEnv'];
25
29
  const PLAN_VERSION = 1;
26
30
  // ---------------------------------------------------------------------------
27
31
  // Pure helpers: canonical hash + confirmation code (V16 / V17)
@@ -108,6 +112,13 @@ export function verifyConsent(plan, planHash, confirmCode, ackManaged) {
108
112
  // ---------------------------------------------------------------------------
109
113
  // Pure plan builder (V16: zero writes / zero external calls)
110
114
  // ---------------------------------------------------------------------------
115
+ /** Raw models array of one section from a readGoProviderSections result. */
116
+ function routeModels(sections, route) {
117
+ const section = sections?.[route];
118
+ return isRecord(section) && Array.isArray(section.models)
119
+ ? section.models
120
+ : [];
121
+ }
111
122
  /** Per-route state, refined from the full-set state (§14.1). */
112
123
  function detectRouteStates(sections, record, routeIds, overall) {
113
124
  const identityRoutes = record?.appliedIdentityRoutes ?? Object.keys(sections ?? {});
@@ -177,43 +188,42 @@ export function buildMigrationPlan(input) {
177
188
  const adoptDisabled = input.adoptDisabled === true;
178
189
  const adopt = input.adopt === true && !adoptDisabled;
179
190
  const rewriteRefs = input.rewriteRefs ?? 'none';
180
- const grouping = groupGoModelsByProtocol(input.entries);
181
- const entryById = new Map(input.entries.map((entry) => [entry.id, entry]));
182
- const desiredBySlot = new Map();
183
- for (const slot of ['chat', 'msg', 'resp', 'google']) {
184
- desiredBySlot.set(slot, grouping.slots[slot]
185
- .map((id) => entryById.get(id))
186
- .filter((entry) => entry !== undefined)
187
- .map(mapGoModelToProfile)
188
- .sort((a, b) => a.id.localeCompare(b.id)));
189
- }
190
- const desiredIds = new Set([...desiredBySlot.values()].flat().map((profile) => profile.id));
191
- // The two ids that move out of chat into dedicated protocol routes (§14.4).
192
- const targets = grouping.slots.msg.concat(grouping.slots.resp);
193
- const references = input.references ?? defaultReferences(targets, rewriteRefs);
194
- // Routes actually in scope for this plan (a conditional, empty google slot
195
- // with no pre-existing section is skipped — §9.4).
196
- const scopedRoutes = [];
197
- for (const slot of ['chat', 'msg', 'resp', 'google']) {
198
- if (slot === 'google' && desiredBySlot.get(slot).length === 0 && sections?.[routes[slot]] === undefined)
199
- continue;
191
+ // 0.12.0 desired collapse: EVERY official entry targets the single managed
192
+ // route (routes.chat). The three legacy protocol routes act only as move
193
+ // sources (adopt) / keep sources (conservative) for ids still sitting there.
194
+ const targetRoute = routes.chat;
195
+ const targetSlot = 'chat';
196
+ const fields = planGoRouteFields(input.entries, input.ref);
197
+ const desired = input.entries
198
+ .map(mapGoModelToProfile)
199
+ .sort((a, b) => a.id.localeCompare(b.id));
200
+ const desiredIds = new Set(desired.map((profile) => profile.id));
201
+ // Routes actually in scope for this plan: the managed route always; a legacy
202
+ // slot route only when its section exists (a never-created route has nothing
203
+ // to migrate).
204
+ const scopedRoutes = [{
205
+ slot: targetSlot,
206
+ route: targetRoute,
207
+ state: stateByRoute[targetRoute] ?? 'absent',
208
+ fields,
209
+ desired,
210
+ currentModels: routeModels(sections, targetRoute),
211
+ }];
212
+ for (const slot of ['msg', 'resp', 'google']) {
200
213
  const route = routes[slot];
201
- const section = sections?.[route];
202
- const routeState = stateByRoute[route] ?? 'absent';
203
- const fields = planGoRouteFields(slot, input.entries.filter((entry) => grouping.slots[slot].includes(entry.id)), input.ref);
204
- const desired = desiredBySlot.get(slot) ?? [];
205
- const currentModels = isRecord(section) && Array.isArray(section.models)
206
- ? section.models
207
- : [];
208
- scopedRoutes.push({ slot, route, state: routeState, fields, desired, currentModels });
209
- }
210
- // desired id → its official target route + exact profile.
211
- const desiredTarget = new Map();
212
- for (const scope of scopedRoutes) {
213
- for (const profile of scope.desired) {
214
- desiredTarget.set(profile.id, { slot: scope.slot, route: scope.route, profile });
215
- }
214
+ if (sections?.[route] === undefined)
215
+ continue;
216
+ scopedRoutes.push({
217
+ slot,
218
+ route,
219
+ state: stateByRoute[route] ?? 'absent',
220
+ fields,
221
+ desired: [],
222
+ currentModels: routeModels(sections, route),
223
+ });
216
224
  }
225
+ // desired id → its official target (always the single managed route).
226
+ const desiredTarget = new Map(desired.map((profile) => [profile.id, { slot: targetSlot, route: targetRoute, profile }]));
217
227
  // Every id currently in settings, with all the routes it occupies.
218
228
  const currentLocations = new Map();
219
229
  for (const scope of scopedRoutes) {
@@ -223,6 +233,12 @@ export function buildMigrationPlan(input) {
223
233
  currentLocations.set(profile.id, list);
224
234
  }
225
235
  }
236
+ // Ids whose references change under this plan: desired ids still sitting on
237
+ // a legacy protocol route (they end up on the managed route after apply).
238
+ const targets = desired
239
+ .filter((profile) => (currentLocations.get(profile.id) ?? []).some((loc) => loc.route !== targetRoute))
240
+ .map((profile) => profile.id);
241
+ const references = input.references ?? defaultReferences(targets, rewriteRefs);
226
242
  const pinnedIds = new Set(input.pinnedModels ?? []);
227
243
  // `undefined` is materially different from an empty list: empty means the
228
244
  // catalog was fetched and truly has no such id (→ user-extra); undefined means
@@ -231,9 +247,8 @@ export function buildMigrationPlan(input) {
231
247
  const publicIds = new Set(input.publicCatalogIds ?? []);
232
248
  const pruneUserExtra = input.pruneUserExtra === true;
233
249
  const kindOf = (id) => {
234
- const target = desiredTarget.get(id);
235
- if (target !== undefined)
236
- return `desired-${target.slot}`;
250
+ if (desiredTarget.has(id))
251
+ return 'desired';
237
252
  // Fail-closed (§14.2): no public catalog → never guess "user-written".
238
253
  if (!publicCatalogAvailable)
239
254
  return 'unclassified';
@@ -360,7 +375,7 @@ export function buildMigrationPlan(input) {
360
375
  willDelete: true,
361
376
  reason: action.reason,
362
377
  }));
363
- const plannedRoutes = scopedRoutes.map((scope) => {
378
+ const plannedRoutesDraft = scopedRoutes.map((scope) => {
364
379
  const seen = new Set();
365
380
  const existing = [];
366
381
  for (const profile of scope.currentModels) {
@@ -387,18 +402,36 @@ export function buildMigrationPlan(input) {
387
402
  action = 'update';
388
403
  return { slot: scope.slot, route: scope.route, state: scope.state, action, fields: scope.fields, desired: scope.desired, existing };
389
404
  });
405
+ // ONE plan-time simulation — the SAME function apply executes — decides both
406
+ // the informed-consent id set and which legacy routes end up emptied. A
407
+ // legacy protocol route whose post-apply models map is empty carries no
408
+ // user content anymore: apply will whole-section unset it (never a
409
+ // `models: []` write) and delete its ledger key.
410
+ const simulation = buildRouteWriteStates({ routes: plannedRoutesDraft, idActions }, input.descriptor);
411
+ const managedByRoute = {};
412
+ for (const [route, state] of simulation.byRoute) {
413
+ managedByRoute[route] = Object.keys(state.managed).sort((a, b) => a.localeCompare(b));
414
+ }
415
+ const plannedRoutes = plannedRoutesDraft.map((planned) => {
416
+ if (planned.slot === 'chat' || planned.state === 'absent')
417
+ return planned;
418
+ const postModels = simulation.byRoute.get(planned.route)?.models;
419
+ if (postModels !== undefined && postModels.size === 0) {
420
+ return { ...planned, action: 'unset' };
421
+ }
422
+ return planned;
423
+ });
390
424
  const pinnedSuggestions = new Set();
391
- const reversibleTargets = targets.filter((id) => !grouping.slots.chat.includes(id));
392
- for (const id of reversibleTargets)
425
+ // Reversible targets: desired ids still sitting on a legacy protocol route.
426
+ for (const id of targets)
393
427
  pinnedSuggestions.add(id);
394
428
  for (const id of pinnedIds)
395
429
  pinnedSuggestions.add(id);
396
430
  // B6 informed-consent text — part of the hashed body: any edit to this notice
397
431
  // changes planHash and invalidates the old confirmCode/ack. The id list comes
398
- // from `managedIdsAfterApply`, the SAME simulation apply uses for the ledger,
399
- // so a user-modified `update` row or a move onto a different-valued target is
400
- // never advertised as managed.
401
- const managedByRoute = managedIdsAfterApply({ routes: plannedRoutes, idActions }, input.descriptor);
432
+ // from the single `buildRouteWriteStates` simulation above — the SAME engine
433
+ // apply uses for the ledger — so a user-modified `update` row or a move onto
434
+ // a different-valued target is never advertised as managed.
402
435
  // N2: no row may claim management on paper if the simulation shows apply
403
436
  // will not actually write/adopt that id. Normalise the per-id `managed`
404
437
  // flags to the simulated set so even the printed `[managed]` marker cannot
@@ -446,10 +479,7 @@ export function buildMigrationPlan(input) {
446
479
  }
447
480
  function describeId(kind, adopt) {
448
481
  switch (kind) {
449
- case 'desired-chat': return 'official chat-completions target';
450
- case 'desired-msg': return 'official messages target (dedicated -msg route)';
451
- case 'desired-resp': return 'official responses target (dedicated -resp route)';
452
- case 'desired-google': return 'official google target';
482
+ case 'desired': return 'official desired id (single managed route)';
453
483
  case 'legacy-other-protocol': return adopt ? 'legacy id on the wrong protocol route' : 'legacy id kept in conservative mode';
454
484
  case 'unknown-retired': return adopt ? 'unknown/retired id, delete only if confirmed in plan' : 'unknown/retired id kept as user-owned';
455
485
  case 'user-extra': return 'user-written id, never auto-deleted';
@@ -499,7 +529,7 @@ export function formatMigrationPlan(plan) {
499
529
  for (const route of plan.routes) {
500
530
  const fields = route.fields;
501
531
  lines.push(` ${route.route} [${route.slot}/${route.state}] ${route.action.toUpperCase()}`);
502
- lines.push(` api=${fields.api} baseURL=${fields.baseURL} displayName=${fields.displayName} apiKeyEnv=${fields.apiKeyEnv}`);
532
+ lines.push(` displayName=${fields.displayName} apiKeyEnv=${fields.apiKeyEnv}${route.action === 'unset' ? ' (whole-route unset; fields not written)' : ''}`);
503
533
  lines.push(` desired (${route.desired.length}): ${route.desired.map((profile) => profile.id).join(', ') || '(none)'}`);
504
534
  if (route.existing.length > 0) {
505
535
  lines.push(` existing: ${route.existing.map((entry) => `${entry.id}=${entry.kind}/${entry.action}`).join(', ')}`);
@@ -623,6 +653,14 @@ function routeOps(desc, route, fields, models) {
623
653
  ops.push({ op: 'set', path: ['providers', route, field], value: fields[field] });
624
654
  }
625
655
  }
656
+ // Catalog-reuse: strip legacy `api`/`baseURL` so the host reuses pi-ai's
657
+ // builtin catalog provider for this route.
658
+ for (const field of GO_LEGACY_ROUTE_FIELDS) {
659
+ const value = data?.[field];
660
+ if (value !== undefined && value !== '') {
661
+ ops.push({ op: 'unset', path: ['providers', route, field] });
662
+ }
663
+ }
626
664
  const sorted = [...models].sort((a, b) => a.id.localeCompare(b.id));
627
665
  const current = [...rawModels(desc, route)].sort((a, b) => a.id.localeCompare(b.id));
628
666
  if (current.length !== sorted.length || current.some((profile, index) => profileHash(profile) !== profileHash(sorted[index]))) {
@@ -866,6 +904,39 @@ export async function applyMigration(args, deps) {
866
904
  continue;
867
905
  }
868
906
  const current = rawModels(desc, planned.route);
907
+ // Emptied legacy protocol route (plan action `unset`): whole-section
908
+ // unset + ledger key delete. Never a `models: []` write (§9.4), and no
909
+ // ledger entry survives it (no managedByRoute entry → appliedManagedIds
910
+ // mirrors only routes that still have a ledger, N3).
911
+ if (planned.action === 'unset') {
912
+ const section = rawRoute(desc, planned.route);
913
+ if (section !== undefined) {
914
+ try {
915
+ await mutateWithRetry(deps, [{ op: 'unset', path: ['providers', planned.route] }]);
916
+ writtenRoutes.push(planned.route);
917
+ }
918
+ catch (err) {
919
+ failure = `${planned.route}: settings mutate failed (${errorText(err)})`;
920
+ routesResult.push({ route: planned.route, status: 'failed', reason: errorText(err) });
921
+ break;
922
+ }
923
+ }
924
+ const legacyKey = goOwnershipKey(planned.route, deps.keyFingerprint);
925
+ try {
926
+ await deps.ownershipStore.delete(legacyKey);
927
+ }
928
+ catch (err) {
929
+ failure = `${planned.route}: ledger delete failed (${errorText(err)})`;
930
+ routesResult.push({ route: planned.route, status: 'failed', reason: errorText(err) });
931
+ break;
932
+ }
933
+ routesResult.push({
934
+ route: planned.route,
935
+ status: section !== undefined ? 'wrote' : 'skipped',
936
+ ...(section !== undefined ? {} : { reason: 'legacy route superseded; section already absent (no settings write)' }),
937
+ });
938
+ continue;
939
+ }
869
940
  // Write only ops that actually change fields/models. keep/update/delete-no
870
941
  // rows leave the section byte-identical, so no mutate happens for them.
871
942
  const ops = routeOps(desc, planned.route, planned.fields, [...state.models.values()]);