@aiwayds/dsh-model-sync 0.11.1 → 0.12.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/lib/index.d.ts +8 -0
- package/lib/index.js +90 -24
- package/lib/index.js.map +1 -1
- package/lib/opencode-go-diagnose.d.ts +43 -21
- package/lib/opencode-go-diagnose.js +87 -56
- package/lib/opencode-go-diagnose.js.map +1 -1
- package/lib/opencode-go-grouping.d.ts +4 -26
- package/lib/opencode-go-grouping.js +12 -68
- package/lib/opencode-go-grouping.js.map +1 -1
- package/lib/opencode-go-host-catalog.d.ts +42 -0
- package/lib/opencode-go-host-catalog.js +98 -0
- package/lib/opencode-go-host-catalog.js.map +1 -0
- package/lib/opencode-go-journal.d.ts +6 -2
- package/lib/opencode-go-journal.js +1 -1
- package/lib/opencode-go-journal.js.map +1 -1
- package/lib/opencode-go-migrate.d.ts +40 -5
- package/lib/opencode-go-migrate.js +313 -84
- package/lib/opencode-go-migrate.js.map +1 -1
- package/lib/opencode-go-migration.d.ts +43 -0
- package/lib/opencode-go-migration.js +91 -2
- package/lib/opencode-go-migration.js.map +1 -1
- package/lib/opencode-go-one-shot.d.ts +6 -0
- package/lib/opencode-go-one-shot.js +41 -4
- package/lib/opencode-go-one-shot.js.map +1 -1
- package/lib/opencode-go-planner.d.ts +39 -24
- package/lib/opencode-go-planner.js +275 -207
- package/lib/opencode-go-planner.js.map +1 -1
- package/lib/opencode-go-sync.d.ts +16 -3
- package/lib/opencode-go-sync.js +24 -0
- package/lib/opencode-go-sync.js.map +1 -1
- package/lib/opencode-go-writer.d.ts +17 -1
- package/lib/opencode-go-writer.js +111 -16
- package/lib/opencode-go-writer.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +100 -25
- package/src/opencode-go-diagnose.ts +124 -70
- package/src/opencode-go-grouping.ts +14 -85
- package/src/opencode-go-host-catalog.ts +125 -0
- package/src/opencode-go-journal.ts +5 -3
- package/src/opencode-go-migrate.ts +352 -95
- package/src/opencode-go-migration.ts +116 -2
- package/src/opencode-go-one-shot.ts +49 -4
- package/src/opencode-go-planner.ts +293 -216
- package/src/opencode-go-sync.ts +40 -2
- package/src/opencode-go-writer.ts +127 -15
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Host runtime catalog reader (0.12.1 catalog-intersection fix).
|
|
2
|
+
//
|
|
3
|
+
// 0.12.0 wrote the FULL official listing into the single managed route. The
|
|
4
|
+
// host validates every route model id against the pi-ai catalog snapshot its
|
|
5
|
+
// OWN process loaded (fail-closed: one unknown id rejects the whole mutate —
|
|
6
|
+
// incident migrate-go 20261129-114103: `beam-free` written from the official
|
|
7
|
+
// listing, rejected because the app's bundled pi-ai only knows 29 ids while
|
|
8
|
+
// the official listing carries it). The planner therefore needs the HOST's
|
|
9
|
+
// id universe, not a build-time snapshot and not a filesystem probe:
|
|
10
|
+
//
|
|
11
|
+
// - require.resolve('@earendil-works/pi-ai') is unusable here: this package
|
|
12
|
+
// is ESM (no bare require), pi-ai's exports map has no require condition
|
|
13
|
+
// (ERR_PACKAGE_PATH_NOT_EXPORTED), and even a resolvable path would walk
|
|
14
|
+
// up from the PROFILE node_modules to a DIFFERENT pi-ai copy than the one
|
|
15
|
+
// the running host loaded (measured 2026-11-29: profile closure pi-ai has
|
|
16
|
+
// 33 ids incl. beam-free, the running app asar has 29 without it — a
|
|
17
|
+
// false-positive intersection reintroduces the fault).
|
|
18
|
+
// - The correct source is the host llm adapter itself:
|
|
19
|
+
// `llm.discoverModels('llm-pi-ai', { provider })` answers from the
|
|
20
|
+
// adapter's in-memory installed catalog with no network, no apiKey and no
|
|
21
|
+
// baseURL (dsh-llm-pi-ai src/discovery.ts checks `catalogModels(provider)`
|
|
22
|
+
// first) — the exact whitelist the host's serviceability validation uses.
|
|
23
|
+
//
|
|
24
|
+
// Callers that WRITE treat `null` as fail-closed (abort, never write an
|
|
25
|
+
// unverified list); read-only callers (diagnose) may degrade to "catalog
|
|
26
|
+
// unknown". This module only resolves and normalizes ids — no settings write,
|
|
27
|
+
// no fetch of its own.
|
|
28
|
+
//
|
|
29
|
+
// @module dsh-model-sync/opencode-go-host-catalog
|
|
30
|
+
|
|
31
|
+
/** The pi-ai builtin catalog provider id backing the opencode-go route. */
|
|
32
|
+
export const HOST_CATALOG_PROVIDER = 'opencode-go'
|
|
33
|
+
|
|
34
|
+
/** The settings namespace whose registered discovery serves the request. */
|
|
35
|
+
export const HOST_CATALOG_SETTINGS_NS = 'llm-pi-ai'
|
|
36
|
+
|
|
37
|
+
/** One entry of the host llm adapter's discovery reply (structural subset). */
|
|
38
|
+
export interface HostDiscoveredModel {
|
|
39
|
+
id?: unknown
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The `llm` service subset this module consumes (see dsh-llm types). */
|
|
43
|
+
export interface HostCatalogLlmSeam {
|
|
44
|
+
discoverModels?(
|
|
45
|
+
settingsNs: string,
|
|
46
|
+
request: { provider?: string; baseURL?: string; api?: string; apiKey?: string },
|
|
47
|
+
signal?: AbortSignal,
|
|
48
|
+
): Promise<readonly HostDiscoveredModel[]>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Why the host catalog could not be read (carried verbatim in reports). */
|
|
52
|
+
export type HostCatalogUnavailable =
|
|
53
|
+
| 'llm-service-unavailable'
|
|
54
|
+
| 'discovery-failed'
|
|
55
|
+
| 'empty-catalog'
|
|
56
|
+
|
|
57
|
+
export type GoHostCatalogResult =
|
|
58
|
+
| { ok: true; ids: string[] }
|
|
59
|
+
| { ok: false; reason: HostCatalogUnavailable; message: string }
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalize a discovery reply into a sorted unique id list. Non-string/empty
|
|
63
|
+
* ids are dropped; the result is deterministic for report/plan hashing.
|
|
64
|
+
*/
|
|
65
|
+
export function parseGoHostCatalogModels(models: readonly HostDiscoveredModel[]): string[] {
|
|
66
|
+
// P1-2: the reply comes from a host seam whose shape we do not control — a
|
|
67
|
+
// non-array reply (a buggy adapter) must degrade to "no ids" here, never
|
|
68
|
+
// throw a TypeError out of the for-of. The caller maps [] to the structured
|
|
69
|
+
// `empty-catalog` result, keeping the never-throw contract.
|
|
70
|
+
if (!Array.isArray(models)) return []
|
|
71
|
+
const ids = new Set<string>()
|
|
72
|
+
for (const model of models) {
|
|
73
|
+
if (model === null || typeof model !== 'object') continue
|
|
74
|
+
const id = model.id
|
|
75
|
+
if (typeof id !== 'string' || id.length === 0) continue
|
|
76
|
+
ids.add(id)
|
|
77
|
+
}
|
|
78
|
+
return [...ids].sort((a, b) => a.localeCompare(b))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function errorText(err: unknown): string {
|
|
82
|
+
const message = (err as { message?: unknown } | null | undefined)?.message
|
|
83
|
+
return typeof message === 'string' ? message : String(err)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Read the host runtime catalog for opencode-go through the llm discovery
|
|
88
|
+
* seam. Never throws: every failure is a structured `{ ok: false }` result so
|
|
89
|
+
* callers decide between fail-closed (writes) and degrade (diagnostics).
|
|
90
|
+
*/
|
|
91
|
+
export async function loadHostGoCatalogIds(
|
|
92
|
+
llm: HostCatalogLlmSeam | undefined,
|
|
93
|
+
options: { provider?: string; settingsNs?: string; signal?: AbortSignal } = {},
|
|
94
|
+
): Promise<GoHostCatalogResult> {
|
|
95
|
+
const provider = options.provider ?? HOST_CATALOG_PROVIDER
|
|
96
|
+
const settingsNs = options.settingsNs ?? HOST_CATALOG_SETTINGS_NS
|
|
97
|
+
// P1-2: `== null` — an explicitly-injected null must take the structured
|
|
98
|
+
// unavailable path, not TypeError on member access.
|
|
99
|
+
if (llm == null || typeof llm.discoverModels !== 'function') {
|
|
100
|
+
return {
|
|
101
|
+
ok: false,
|
|
102
|
+
reason: 'llm-service-unavailable',
|
|
103
|
+
message: 'llm service has no discoverModels seam (host adapter missing or too old)',
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
let models: readonly HostDiscoveredModel[]
|
|
107
|
+
try {
|
|
108
|
+
models = await llm.discoverModels(settingsNs, { provider }, options.signal)
|
|
109
|
+
} catch (err) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
reason: 'discovery-failed',
|
|
113
|
+
message: `discoverModels(${settingsNs}, { provider: ${provider} }) failed: ${errorText(err)}`,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const ids = parseGoHostCatalogModels(models)
|
|
117
|
+
if (ids.length === 0) {
|
|
118
|
+
return {
|
|
119
|
+
ok: false,
|
|
120
|
+
reason: 'empty-catalog',
|
|
121
|
+
message: `host runtime catalog lists no model ids for provider ${provider}`,
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { ok: true, ids }
|
|
125
|
+
}
|
|
@@ -304,8 +304,10 @@ export interface ReconcileDeps {
|
|
|
304
304
|
keyFingerprint: string
|
|
305
305
|
logger: Logger
|
|
306
306
|
/** Same callback the writer uses after a healthy own-write: re-persist the
|
|
307
|
-
* migration record. Store/record only — never touches settings.
|
|
308
|
-
|
|
307
|
+
* migration record. Store/record only — never touches settings. The third
|
|
308
|
+
* argument marks a whole-section unset (ledger key deleted) so the record
|
|
309
|
+
* update drops the route's appliedManagedIds key, mirroring the writer. */
|
|
310
|
+
onRecord?: (route: string, managedIds: string[], info?: { unset: boolean }) => Promise<void> | void
|
|
309
311
|
}
|
|
310
312
|
|
|
311
313
|
function rawModels(desc: SettingsDescriptor | undefined, route: string): SettingsModelProfile[] {
|
|
@@ -429,7 +431,7 @@ export async function reconcileJournals(deps: ReconcileDeps): Promise<ReconcileR
|
|
|
429
431
|
await deps.ownershipStore.write(ledgerKey, journal.entry)
|
|
430
432
|
}
|
|
431
433
|
if (deps.onRecord !== undefined) {
|
|
432
|
-
await deps.onRecord(journal.route, [...journal.modelIds].sort())
|
|
434
|
+
await deps.onRecord(journal.route, [...journal.modelIds].sort(), { unset: journal.unset === true })
|
|
433
435
|
}
|
|
434
436
|
await deps.journalStore.delete(key)
|
|
435
437
|
result.reconciled.push(journal.route)
|