@aiwayds/dsh-model-sync 0.12.1 → 0.13.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 +18 -17
- package/README.zh-CN.md +18 -17
- package/lib/index.d.ts +54 -384
- package/lib/index.js +306 -1107
- package/lib/index.js.map +1 -1
- package/lib/official-adapter.d.ts +80 -0
- package/lib/official-adapter.js +34 -0
- package/lib/official-adapter.js.map +1 -0
- package/lib/official-migrate.d.ts +122 -0
- package/lib/official-migrate.js +653 -0
- package/lib/official-migrate.js.map +1 -0
- package/lib/official-scheduler.d.ts +72 -0
- package/lib/official-scheduler.js +195 -0
- package/lib/official-scheduler.js.map +1 -0
- package/lib/official-store.d.ts +41 -0
- package/lib/official-store.js +84 -0
- package/lib/official-store.js.map +1 -0
- package/lib/official-sync.d.ts +68 -0
- package/lib/official-sync.js +274 -0
- package/lib/official-sync.js.map +1 -0
- package/lib/opencode-go-adapter.d.ts +56 -0
- package/lib/opencode-go-adapter.js +455 -0
- package/lib/opencode-go-adapter.js.map +1 -0
- package/lib/opencode-go-patch-file.d.ts +11 -0
- package/lib/opencode-go-patch-file.js +175 -11
- package/lib/opencode-go-patch-file.js.map +1 -1
- package/lib/opencode-go-source.d.ts +1 -1
- package/lib/opencode-go-source.js +1 -1
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +3 -3
- package/src/index.ts +352 -1281
- package/src/official-adapter.ts +111 -0
- package/src/official-migrate.ts +863 -0
- package/src/official-scheduler.ts +235 -0
- package/src/official-store.ts +122 -0
- package/src/official-sync.ts +371 -0
- package/src/opencode-go-adapter.ts +494 -0
- package/src/opencode-go-patch-file.ts +175 -9
- package/src/opencode-go-source.ts +1 -1
- package/lib/opencode-go-diagnose.d.ts +0 -96
- package/lib/opencode-go-diagnose.js +0 -177
- package/lib/opencode-go-diagnose.js.map +0 -1
- package/lib/opencode-go-grouping.d.ts +0 -7
- package/lib/opencode-go-grouping.js +0 -21
- package/lib/opencode-go-grouping.js.map +0 -1
- package/lib/opencode-go-host-catalog.d.ts +0 -42
- package/lib/opencode-go-host-catalog.js +0 -98
- package/lib/opencode-go-host-catalog.js.map +0 -1
- package/lib/opencode-go-journal.d.ts +0 -114
- package/lib/opencode-go-journal.js +0 -406
- package/lib/opencode-go-journal.js.map +0 -1
- package/lib/opencode-go-migrate.d.ts +0 -378
- package/lib/opencode-go-migrate.js +0 -1529
- package/lib/opencode-go-migrate.js.map +0 -1
- package/lib/opencode-go-migration.d.ts +0 -270
- package/lib/opencode-go-migration.js +0 -473
- package/lib/opencode-go-migration.js.map +0 -1
- package/lib/opencode-go-one-shot.d.ts +0 -282
- package/lib/opencode-go-one-shot.js +0 -1131
- package/lib/opencode-go-one-shot.js.map +0 -1
- package/lib/opencode-go-planner.d.ts +0 -168
- package/lib/opencode-go-planner.js +0 -407
- package/lib/opencode-go-planner.js.map +0 -1
- package/lib/opencode-go-scheduler.d.ts +0 -128
- package/lib/opencode-go-scheduler.js +0 -241
- package/lib/opencode-go-scheduler.js.map +0 -1
- package/lib/opencode-go-store.d.ts +0 -18
- package/lib/opencode-go-store.js +0 -68
- package/lib/opencode-go-store.js.map +0 -1
- package/lib/opencode-go-sync.d.ts +0 -107
- package/lib/opencode-go-sync.js +0 -388
- package/lib/opencode-go-sync.js.map +0 -1
- package/lib/opencode-go-writer.d.ts +0 -148
- package/lib/opencode-go-writer.js +0 -1061
- package/lib/opencode-go-writer.js.map +0 -1
- package/src/opencode-go-diagnose.ts +0 -276
- package/src/opencode-go-grouping.ts +0 -26
- package/src/opencode-go-host-catalog.ts +0 -125
- package/src/opencode-go-journal.ts +0 -460
- package/src/opencode-go-migrate.ts +0 -1951
- package/src/opencode-go-migration.ts +0 -666
- package/src/opencode-go-one-shot.ts +0 -1399
- package/src/opencode-go-planner.ts +0 -582
- package/src/opencode-go-scheduler.ts +0 -315
- package/src/opencode-go-store.ts +0 -73
- package/src/opencode-go-sync.ts +0 -541
- package/src/opencode-go-writer.ts +0 -1301
|
@@ -110,6 +110,7 @@ export type PatchParseResult =
|
|
|
110
110
|
| { ok: false; reason: string }
|
|
111
111
|
|
|
112
112
|
const LLM_PI_AI_ENTRY_ID = 'llm-pi-ai'
|
|
113
|
+
const AGENT_DEFAULT_MODEL_ENTRY_ID = 'agent-default-model'
|
|
113
114
|
|
|
114
115
|
/** The KEY regex every block-map row must match (keys are simple identifiers in practice). */
|
|
115
116
|
const KEY_ENTRY = /^(\S[^:]*?):(?:[ \t]+(.*))?$/
|
|
@@ -819,7 +820,7 @@ function containsOpaque(value: unknown): boolean {
|
|
|
819
820
|
return false
|
|
820
821
|
}
|
|
821
822
|
|
|
822
|
-
function
|
|
823
|
+
function findEntryById(root: PatchNode, targetId: string): (PatchNode & { kind: 'map' }) | { refusal: string } {
|
|
823
824
|
if (root.kind !== 'seq') return { refusal: 'profile patch must be a YAML sequence of entries' }
|
|
824
825
|
// The host edits the LAST non-insert row carrying the entry id.
|
|
825
826
|
for (let i = root.items.length - 1; i >= 0; i--) {
|
|
@@ -827,9 +828,93 @@ function findLlmPiAiEntry(root: PatchNode): (PatchNode & { kind: 'map' }) | { re
|
|
|
827
828
|
if (node.kind !== 'map') continue
|
|
828
829
|
if (node.entries.some((entry) => entry.key === 'insert')) continue
|
|
829
830
|
const idEntry = [...node.entries].reverse().find((entry) => entry.key === 'id')
|
|
830
|
-
if (idEntry !== undefined && idEntry.value.kind === 'scalar' && idEntry.value.value ===
|
|
831
|
+
if (idEntry !== undefined && idEntry.value.kind === 'scalar' && idEntry.value.value === targetId) return node
|
|
831
832
|
}
|
|
832
|
-
return { refusal: `no "${
|
|
833
|
+
return { refusal: `no "${targetId}" entry found in the profile patch` }
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
interface EntryConfigLocation {
|
|
837
|
+
configNode: PatchNode & { kind: 'map' }
|
|
838
|
+
configLine: number
|
|
839
|
+
before: Record<string, unknown>
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function locateEntryConfig(root: PatchNode, targetId: string): EntryConfigLocation | { refusal: string } {
|
|
843
|
+
const entry = findEntryById(root, targetId)
|
|
844
|
+
if ('refusal' in entry) return { refusal: entry.refusal }
|
|
845
|
+
const configEntry = [...entry.entries].reverse().find((item) => item.key === 'config')
|
|
846
|
+
if (configEntry === undefined || configEntry.value.kind !== 'map') {
|
|
847
|
+
return { refusal: `the ${targetId} entry has no config mapping` }
|
|
848
|
+
}
|
|
849
|
+
const plain = plainView(configEntry.value)
|
|
850
|
+
if (containsOpaque(plain)) {
|
|
851
|
+
return { refusal: `the ${targetId} config tree contains opaque values (tags / block scalars); refusing to edit` }
|
|
852
|
+
}
|
|
853
|
+
if (typeof plain !== 'object' || plain === null || Array.isArray(plain)) {
|
|
854
|
+
return { refusal: `the ${targetId} config section is not a mapping` }
|
|
855
|
+
}
|
|
856
|
+
return { configNode: configEntry.value, configLine: configEntry.startLine, before: plain as Record<string, unknown> }
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Scan all entries other than `llm-pi-ai` and `agent-default-model` for
|
|
861
|
+
* string values referencing `<providerPrefix>/...` (advisory warning only).
|
|
862
|
+
*/
|
|
863
|
+
export interface PatchReferenceHit {
|
|
864
|
+
entryId: string
|
|
865
|
+
path: string
|
|
866
|
+
value: string
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
export function scanPatchReferences(text: string, providerPrefix: string): PatchReferenceHit[] {
|
|
870
|
+
const parsed = parsePatchDocument(text)
|
|
871
|
+
if (!parsed.ok || parsed.root.kind !== 'seq') return []
|
|
872
|
+
const prefix = `${providerPrefix}/`
|
|
873
|
+
const hits: PatchReferenceHit[] = []
|
|
874
|
+
const seen = new Set<string>()
|
|
875
|
+
const walk = (node: PatchNode, entryId: string, path: string): void => {
|
|
876
|
+
switch (node.kind) {
|
|
877
|
+
case 'scalar': {
|
|
878
|
+
if (typeof node.value === 'string' && node.value.startsWith(prefix)) {
|
|
879
|
+
const key = `${entryId}\0${path}\0${node.value}`
|
|
880
|
+
if (!seen.has(key)) {
|
|
881
|
+
seen.add(key)
|
|
882
|
+
hits.push({ entryId, path, value: node.value })
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
break
|
|
886
|
+
}
|
|
887
|
+
case 'map':
|
|
888
|
+
for (const entry of node.entries) {
|
|
889
|
+
walk(entry.value, entryId, path ? `${path}.${entry.key}` : entry.key)
|
|
890
|
+
}
|
|
891
|
+
break
|
|
892
|
+
case 'seq':
|
|
893
|
+
node.items.forEach((item, index) => {
|
|
894
|
+
walk(item.node, entryId, `${path}[${index}]`)
|
|
895
|
+
})
|
|
896
|
+
break
|
|
897
|
+
case 'opaque':
|
|
898
|
+
break
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
const visitEntry = (node: PatchNode): void => {
|
|
902
|
+
if (node.kind !== 'map') return
|
|
903
|
+
const insertEntry = node.entries.find((e) => e.key === 'insert')
|
|
904
|
+
if (insertEntry !== undefined && insertEntry.value.kind === 'seq') {
|
|
905
|
+
for (const child of insertEntry.value.items) visitEntry(child.node)
|
|
906
|
+
return
|
|
907
|
+
}
|
|
908
|
+
const idEntry = [...node.entries].reverse().find((e) => e.key === 'id')
|
|
909
|
+
const entryId = idEntry !== undefined && idEntry.value.kind === 'scalar' && typeof idEntry.value.value === 'string'
|
|
910
|
+
? idEntry.value.value
|
|
911
|
+
: '(unknown)'
|
|
912
|
+
if (entryId === LLM_PI_AI_ENTRY_ID || entryId === AGENT_DEFAULT_MODEL_ENTRY_ID) return
|
|
913
|
+
const configEntry = [...node.entries].reverse().find((e) => e.key === 'config')
|
|
914
|
+
if (configEntry !== undefined) walk(configEntry.value, entryId, 'config')
|
|
915
|
+
}
|
|
916
|
+
for (const item of parsed.root.items) visitEntry(item.node)
|
|
917
|
+
return hits
|
|
833
918
|
}
|
|
834
919
|
|
|
835
920
|
interface ProvidersLocation {
|
|
@@ -843,7 +928,7 @@ interface ProvidersLocation {
|
|
|
843
928
|
* refusal reason. Shared by the op applier and the descriptor builder.
|
|
844
929
|
*/
|
|
845
930
|
function locateProviders(root: PatchNode): ProvidersLocation | { refusal: string } {
|
|
846
|
-
const entry =
|
|
931
|
+
const entry = findEntryById(root, LLM_PI_AI_ENTRY_ID)
|
|
847
932
|
if ('refusal' in entry) return { refusal: entry.refusal }
|
|
848
933
|
const configEntry = [...entry.entries].reverse().find((item) => item.key === 'config')
|
|
849
934
|
if (configEntry === undefined || configEntry.value.kind !== 'map') {
|
|
@@ -973,7 +1058,14 @@ function simulateOneOp(before: unknown, op: SettingsMutationOp): { ok: true; res
|
|
|
973
1058
|
const route = op.path[1]!
|
|
974
1059
|
if (op.path.length === 2) {
|
|
975
1060
|
if (op.op === 'unset') { delete root[route]; return { ok: true, result: root } }
|
|
976
|
-
|
|
1061
|
+
if (op.op === 'set') {
|
|
1062
|
+
if (op.value === null || typeof op.value !== 'object' || Array.isArray(op.value)) {
|
|
1063
|
+
return { ok: false, reason: `whole-provider set for ${route} requires an object value` }
|
|
1064
|
+
}
|
|
1065
|
+
root[route] = structuredClone(op.value)
|
|
1066
|
+
return { ok: true, result: root }
|
|
1067
|
+
}
|
|
1068
|
+
return { ok: false, reason: 'unsupported op on provider route' }
|
|
977
1069
|
}
|
|
978
1070
|
const field = op.path[2]!
|
|
979
1071
|
if (op.op === 'unset') {
|
|
@@ -990,6 +1082,17 @@ function simulateOneOp(before: unknown, op: SettingsMutationOp): { ok: true; res
|
|
|
990
1082
|
return { ok: true, result: root }
|
|
991
1083
|
}
|
|
992
1084
|
|
|
1085
|
+
function simulateConfigOp(before: unknown, op: SettingsMutationOp): { ok: true; result: Record<string, unknown> } | { ok: false; reason: string } {
|
|
1086
|
+
if (op.path.length !== 1) {
|
|
1087
|
+
return { ok: false, reason: `unsupported config mutation path '${op.path.join('.')}'` }
|
|
1088
|
+
}
|
|
1089
|
+
const root = plainTreeOf(before)
|
|
1090
|
+
const key = op.path[0]!
|
|
1091
|
+
if (op.op === 'unset') delete root[key]
|
|
1092
|
+
else root[key] = structuredClone(op.value)
|
|
1093
|
+
return { ok: true, result: root }
|
|
1094
|
+
}
|
|
1095
|
+
|
|
993
1096
|
function deepEqual(a: unknown, b: unknown): boolean {
|
|
994
1097
|
if (a === b) return true
|
|
995
1098
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
@@ -1042,6 +1145,17 @@ export function applyPatchOps(text: string, ops: readonly SettingsMutationOp[]):
|
|
|
1042
1145
|
} else if (entry !== undefined) {
|
|
1043
1146
|
return { ok: false, reason: `provider ${route} exists but is not a mapping` }
|
|
1044
1147
|
}
|
|
1148
|
+
} else if (op.path.length === 2 && op.op === 'set') {
|
|
1149
|
+
const route = op.path[1]!
|
|
1150
|
+
const entry = [...providersNode.entries].reverse().find((item) => item.key === route)
|
|
1151
|
+
if (entry !== undefined) {
|
|
1152
|
+
splice = { start: entry.startLine, end: entry.endLine, lines: renderEntryLines(route, op.value, providersNode.indent) }
|
|
1153
|
+
} else {
|
|
1154
|
+
const boundary = providersNode.entries.length === 0
|
|
1155
|
+
? providersLine + 1
|
|
1156
|
+
: providersNode.entries[providersNode.entries.length - 1]!.endLine + 1
|
|
1157
|
+
splice = { start: boundary, end: boundary - 1, lines: renderEntryLines(route, op.value, providersNode.indent) }
|
|
1158
|
+
}
|
|
1045
1159
|
} else {
|
|
1046
1160
|
const route = op.path[1]!
|
|
1047
1161
|
const field = op.path[2]!
|
|
@@ -1137,6 +1251,46 @@ const SETTINGS_CONFLICT = 'SETTINGS_CONFLICT'
|
|
|
1137
1251
|
* `mutate()` computes the candidate text in memory, validates it op by op,
|
|
1138
1252
|
* then writes atomically through the injected io.
|
|
1139
1253
|
*/
|
|
1254
|
+
export function applyEntryConfigOps(text: string, targetId: string, ops: readonly SettingsMutationOp[]): PatchOpResult {
|
|
1255
|
+
let current = text
|
|
1256
|
+
for (const op of ops) {
|
|
1257
|
+
const parsed = parsePatchDocument(current)
|
|
1258
|
+
if (!parsed.ok) return { ok: false, reason: `patch parse failed: ${parsed.reason}` }
|
|
1259
|
+
const located = locateEntryConfig(parsed.root, targetId)
|
|
1260
|
+
if ('refusal' in located) return { ok: false, reason: located.refusal }
|
|
1261
|
+
const simulated = simulateConfigOp(located.before, op)
|
|
1262
|
+
if (!simulated.ok) return { ok: false, reason: simulated.reason }
|
|
1263
|
+
const { configNode, configLine } = located
|
|
1264
|
+
const key = op.path[0]!
|
|
1265
|
+
const existing = [...configNode.entries].reverse().find((item) => item.key === key)
|
|
1266
|
+
let splice: Splice | undefined
|
|
1267
|
+
if (op.op === 'unset') {
|
|
1268
|
+
if (existing !== undefined) splice = { start: existing.startLine, end: existing.endLine, lines: [] }
|
|
1269
|
+
} else if (existing !== undefined) {
|
|
1270
|
+
splice = { start: existing.startLine, end: existing.endLine, lines: renderEntryLines(key, op.value, configNode.indent) }
|
|
1271
|
+
} else {
|
|
1272
|
+
const boundary = configNode.entries.length === 0
|
|
1273
|
+
? configLine + 1
|
|
1274
|
+
: configNode.entries[configNode.entries.length - 1]!.endLine + 1
|
|
1275
|
+
splice = { start: boundary, end: boundary - 1, lines: renderEntryLines(key, op.value, configNode.indent) }
|
|
1276
|
+
}
|
|
1277
|
+
if (splice === undefined) {
|
|
1278
|
+
if (!deepEqual(simulated.result, located.before)) return { ok: false, reason: 'no-op op changed simulated config; refusing' }
|
|
1279
|
+
continue
|
|
1280
|
+
}
|
|
1281
|
+
const candidate = spliceLines(current, splice.start, splice.end, splice.lines)
|
|
1282
|
+
const reparsed = parsePatchDocument(candidate)
|
|
1283
|
+
if (!reparsed.ok) return { ok: false, reason: `edited patch failed to re-parse: ${reparsed.reason}` }
|
|
1284
|
+
const after = locateEntryConfig(reparsed.root, targetId)
|
|
1285
|
+
if ('refusal' in after) return { ok: false, reason: `edited patch unusable: ${after.refusal}` }
|
|
1286
|
+
if (!deepEqual(after.before, simulated.result)) {
|
|
1287
|
+
return { ok: false, reason: 'edited patch does not match the simulated config result; refusing to write' }
|
|
1288
|
+
}
|
|
1289
|
+
current = candidate
|
|
1290
|
+
}
|
|
1291
|
+
return { ok: true, next: current }
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1140
1294
|
export function createFilePatchSettingsService(io: PatchFileIo): SettingsService {
|
|
1141
1295
|
return {
|
|
1142
1296
|
describe(): SettingsDescriptor[] {
|
|
@@ -1149,17 +1303,29 @@ export function createFilePatchSettingsService(io: PatchFileIo): SettingsService
|
|
|
1149
1303
|
if (text === undefined || text === '') return []
|
|
1150
1304
|
const parsed = parsePatchDocument(text)
|
|
1151
1305
|
if (!parsed.ok) return []
|
|
1306
|
+
const rev = revisionOf(text)
|
|
1307
|
+
const descriptors: SettingsDescriptor[] = []
|
|
1152
1308
|
const providers = patchLlmPiAiProviders(parsed.root)
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1309
|
+
if (providers.ok) {
|
|
1310
|
+
descriptors.push({ ns: LLM_PI_AI_ENTRY_ID, revision: rev, user: { providers: providers.providers } })
|
|
1311
|
+
}
|
|
1312
|
+
const defaultModel = locateEntryConfig(parsed.root, AGENT_DEFAULT_MODEL_ENTRY_ID)
|
|
1313
|
+
if (!('refusal' in defaultModel)) {
|
|
1314
|
+
descriptors.push({ ns: AGENT_DEFAULT_MODEL_ENTRY_ID, revision: rev, user: defaultModel.before })
|
|
1315
|
+
}
|
|
1316
|
+
return descriptors
|
|
1155
1317
|
},
|
|
1156
1318
|
async mutate(ns: string, ops: SettingsMutationOp[], expectedRevision?: number): Promise<void> {
|
|
1157
|
-
if (ns !== LLM_PI_AI_ENTRY_ID
|
|
1319
|
+
if (ns !== LLM_PI_AI_ENTRY_ID && ns !== AGENT_DEFAULT_MODEL_ENTRY_ID) {
|
|
1320
|
+
throw new Error(`file patch adapter only mutates ${LLM_PI_AI_ENTRY_ID} or ${AGENT_DEFAULT_MODEL_ENTRY_ID}`)
|
|
1321
|
+
}
|
|
1158
1322
|
const text = io.readText() ?? ''
|
|
1159
1323
|
if (expectedRevision !== undefined && expectedRevision !== revisionOf(text)) {
|
|
1160
1324
|
throw Object.assign(new Error('patch file changed since describe'), { code: SETTINGS_CONFLICT })
|
|
1161
1325
|
}
|
|
1162
|
-
const applied =
|
|
1326
|
+
const applied = ns === LLM_PI_AI_ENTRY_ID
|
|
1327
|
+
? applyPatchOps(text, ops)
|
|
1328
|
+
: applyEntryConfigOps(text, AGENT_DEFAULT_MODEL_ENTRY_ID, ops)
|
|
1163
1329
|
if (!applied.ok) throw new Error(applied.reason)
|
|
1164
1330
|
if (applied.next === text) return
|
|
1165
1331
|
await io.writeAtomic(applied.next)
|
|
@@ -19,7 +19,7 @@ export const OPENCODE_GO_MODELS_URL = 'https://opencode.ai/inference/go/v1/model
|
|
|
19
19
|
export const OPENCODE_GO_DEFAULT_INTERVAL_MINUTES = 60
|
|
20
20
|
|
|
21
21
|
/** Explicit UA — the gateway bans default library UAs with CF 1010 (05 §1). */
|
|
22
|
-
export const GO_USER_AGENT = 'dsh-model-sync/0.
|
|
22
|
+
export const GO_USER_AGENT = 'dsh-model-sync/0.13.1'
|
|
23
23
|
|
|
24
24
|
/** Auth states carried by the diagnostic report (design §6.1 SourceSnapshot). */
|
|
25
25
|
export type GoAuthStatus = 'unknown' | 'ok' | 'invalid' | 'not-entitled' | 'unreachable'
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { type GoFetchLike, type GoSourceResult, type GoAuthStatus, type GoSourceError } from './opencode-go-source.ts';
|
|
2
|
-
/** Minimal settings-descriptor shape the diagnostic reads (no writer import). */
|
|
3
|
-
export interface GoSettingsDescriptor {
|
|
4
|
-
user?: Record<string, unknown>;
|
|
5
|
-
}
|
|
6
|
-
/** One route's currently configured model ids, read from the profile. */
|
|
7
|
-
export interface GoRouteConfig {
|
|
8
|
-
route: string;
|
|
9
|
-
configuredIds: string[];
|
|
10
|
-
/** True for the single managed route (the official listing diffs against it). */
|
|
11
|
-
managed: boolean;
|
|
12
|
-
}
|
|
13
|
-
/** The comparison for one route in the report. */
|
|
14
|
-
export interface GoRouteDiff {
|
|
15
|
-
route: string;
|
|
16
|
-
/** Ids the official entitled source lists (managed route only; [] for legacy). */
|
|
17
|
-
official: string[];
|
|
18
|
-
/** Ids currently listed under this route in the profile. */
|
|
19
|
-
configured: string[];
|
|
20
|
-
/** Official ids absent from the profile (managed route only). */
|
|
21
|
-
added: string[];
|
|
22
|
-
/** Profile ids absent from the official entitled set (managed route only). */
|
|
23
|
-
missing: string[];
|
|
24
|
-
/**
|
|
25
|
-
* 0.12.1: official ids the HOST runtime catalog does not know (managed route
|
|
26
|
-
* only). These are host-side lag, not a plugin problem — sync never writes
|
|
27
|
-
* them (needs-host-catalog) and they auto-join after a host upgrade.
|
|
28
|
-
*/
|
|
29
|
-
hostCatalogLag: string[];
|
|
30
|
-
/** Legacy protocol route superseded by the single managed route. */
|
|
31
|
-
superseded?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/** Structured diagnostic report emitted by P0. */
|
|
34
|
-
export interface GoDiagnosticReport {
|
|
35
|
-
source: 'opencode-go-official';
|
|
36
|
-
generatedAt: number;
|
|
37
|
-
authStatus: GoAuthStatus;
|
|
38
|
-
keyFingerprint: string;
|
|
39
|
-
payloadHash?: string;
|
|
40
|
-
error?: GoSourceError;
|
|
41
|
-
/** True when host runtime catalog ids were supplied (hostCatalogLag is meaningful). */
|
|
42
|
-
hostCatalogAvailable: boolean;
|
|
43
|
-
/** First entry = the managed route diff; remaining = legacy routes found. */
|
|
44
|
-
routes: GoRouteDiff[];
|
|
45
|
-
}
|
|
46
|
-
/** Inputs to buildGoDiagnosticReport — all already-resolved (pure). */
|
|
47
|
-
export interface BuildGoDiagnosticInput {
|
|
48
|
-
source: GoSourceResult;
|
|
49
|
-
routes: readonly GoRouteConfig[];
|
|
50
|
-
/**
|
|
51
|
-
* Host runtime catalog ids for opencode-go. `undefined`/absent = unknown —
|
|
52
|
-
* no lag comparison is reported (the diagnostic is read-only, so unlike the
|
|
53
|
-
* write paths this degrades instead of failing closed).
|
|
54
|
-
*/
|
|
55
|
-
hostCatalogIds?: readonly string[] | null;
|
|
56
|
-
generatedAt?: number;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Read the profile's opencode-go route model ids from a settings descriptor.
|
|
60
|
-
* The single managed route (`chat` slot) is always present (possibly empty);
|
|
61
|
-
* the three legacy slot routes are listed only when they actually exist in
|
|
62
|
-
* the profile. This is a pure read — the descriptor is never modified.
|
|
63
|
-
*
|
|
64
|
-
* M2: `routes` accepts the resolved go.routes config so a custom chat route
|
|
65
|
-
* name is diagnosed correctly; defaults to the standard slot routes.
|
|
66
|
-
*/
|
|
67
|
-
export declare function readGoRoutesFromDescriptor(desc: GoSettingsDescriptor | undefined, routes?: Readonly<Record<string, string>>): GoRouteConfig[];
|
|
68
|
-
/**
|
|
69
|
-
* Build the structured report. When the source read failed (no key, auth,
|
|
70
|
-
* entitlement, transport), the official side is empty and the diff is
|
|
71
|
-
* suppressed — reporting every configured model as "missing" from a failed
|
|
72
|
-
* read would be misleading. The failure is carried in authStatus / error
|
|
73
|
-
* instead.
|
|
74
|
-
*/
|
|
75
|
-
export declare function buildGoDiagnosticReport(input: BuildGoDiagnosticInput): GoDiagnosticReport;
|
|
76
|
-
/** Human-readable rendering of the structured report (command output). */
|
|
77
|
-
export declare function formatGoDiagnosticReport(report: GoDiagnosticReport): string;
|
|
78
|
-
/** Options for one diagnostic run. */
|
|
79
|
-
export interface RunGoDiagnosticOptions {
|
|
80
|
-
apiKey?: string;
|
|
81
|
-
descriptor?: GoSettingsDescriptor | undefined;
|
|
82
|
-
/** M2: resolved go.routes config (custom chat route names diagnose correctly). */
|
|
83
|
-
routes?: Readonly<Record<string, string>>;
|
|
84
|
-
url?: string;
|
|
85
|
-
timeoutMs?: number;
|
|
86
|
-
fetchImpl?: GoFetchLike;
|
|
87
|
-
/** Host runtime catalog ids; absent/null = unknown (lag comparison skipped). */
|
|
88
|
-
hostCatalogIds?: readonly string[] | null;
|
|
89
|
-
generatedAt?: number;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Run one read-only diagnostic: fetch official models, read the profile's
|
|
93
|
-
* route config, and return the structured report. Pass `fetchImpl` in tests
|
|
94
|
-
* so no network is ever touched.
|
|
95
|
-
*/
|
|
96
|
-
export declare function runGoDiagnostic(options?: RunGoDiagnosticOptions): Promise<GoDiagnosticReport>;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
// P0 read-only diagnostic: compare the official opencode-go model set with
|
|
2
|
-
// the current profile's single managed opencode-go route and produce a
|
|
3
|
-
// structured report (added / missing / superseded legacy routes).
|
|
4
|
-
//
|
|
5
|
-
// 0.12.0 single-route shape: the official listing is diffed against ONE
|
|
6
|
-
// managed route (the `chat` slot route); the three legacy protocol routes are
|
|
7
|
-
// listed separately with a superseded hint (sync unsets them when fully
|
|
8
|
-
// plugin-managed). There is no per-protocol grouping anymore — unknown
|
|
9
|
-
// protocols can no longer fail anything closed.
|
|
10
|
-
//
|
|
11
|
-
// Hard boundary: this module only READS a settings descriptor. It never calls
|
|
12
|
-
// settings.mutate, never writes credentials, and never touches a profile file.
|
|
13
|
-
// Existing sync rounds and /model-sync are untouched by this code.
|
|
14
|
-
//
|
|
15
|
-
// Design: 07-design.md §6.3 (status), §16 P0, C7, final review §1.7.
|
|
16
|
-
import { fetchGoOfficialModels, } from "./opencode-go-source.js";
|
|
17
|
-
import { GO_SLOT_ROUTES } from "./opencode-go-grouping.js";
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
// Read-only profile extraction
|
|
20
|
-
// ---------------------------------------------------------------------------
|
|
21
|
-
function isRecord(value) {
|
|
22
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
23
|
-
}
|
|
24
|
-
function toRouteConfig(route, managed, providers) {
|
|
25
|
-
const routeData = providers[route];
|
|
26
|
-
const models = isRecord(routeData) ? routeData.models : undefined;
|
|
27
|
-
const configuredIds = Array.isArray(models)
|
|
28
|
-
? models
|
|
29
|
-
.map((entry) => isRecord(entry) && typeof entry.id === 'string' ? entry.id : undefined)
|
|
30
|
-
.filter((id) => id !== undefined)
|
|
31
|
-
: [];
|
|
32
|
-
return { route, configuredIds, managed };
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Read the profile's opencode-go route model ids from a settings descriptor.
|
|
36
|
-
* The single managed route (`chat` slot) is always present (possibly empty);
|
|
37
|
-
* the three legacy slot routes are listed only when they actually exist in
|
|
38
|
-
* the profile. This is a pure read — the descriptor is never modified.
|
|
39
|
-
*
|
|
40
|
-
* M2: `routes` accepts the resolved go.routes config so a custom chat route
|
|
41
|
-
* name is diagnosed correctly; defaults to the standard slot routes.
|
|
42
|
-
*/
|
|
43
|
-
export function readGoRoutesFromDescriptor(desc, routes = GO_SLOT_ROUTES) {
|
|
44
|
-
const providers = desc?.user?.providers;
|
|
45
|
-
const table = isRecord(providers) ? providers : {};
|
|
46
|
-
const chatRoute = routes.chat ?? GO_SLOT_ROUTES.chat;
|
|
47
|
-
const configs = [toRouteConfig(chatRoute, true, table)];
|
|
48
|
-
for (const slot of ['msg', 'resp', 'google']) {
|
|
49
|
-
const route = routes[slot];
|
|
50
|
-
if (route === undefined || route === chatRoute)
|
|
51
|
-
continue;
|
|
52
|
-
if (!isRecord(table[route]))
|
|
53
|
-
continue;
|
|
54
|
-
configs.push(toRouteConfig(route, false, table));
|
|
55
|
-
}
|
|
56
|
-
return configs;
|
|
57
|
-
}
|
|
58
|
-
// ---------------------------------------------------------------------------
|
|
59
|
-
// Pure diff + report
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
function missingFrom(left, right) {
|
|
62
|
-
const rightSet = new Set(right);
|
|
63
|
-
return left.filter((id) => !rightSet.has(id));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Build the structured report. When the source read failed (no key, auth,
|
|
67
|
-
* entitlement, transport), the official side is empty and the diff is
|
|
68
|
-
* suppressed — reporting every configured model as "missing" from a failed
|
|
69
|
-
* read would be misleading. The failure is carried in authStatus / error
|
|
70
|
-
* instead.
|
|
71
|
-
*/
|
|
72
|
-
export function buildGoDiagnosticReport(input) {
|
|
73
|
-
const available = input.source.ok;
|
|
74
|
-
const officialIds = available ? input.source.entries.map((entry) => entry.id) : [];
|
|
75
|
-
// 0.12.1: official ids the host runtime catalog does not know (read-only
|
|
76
|
-
// comparison; when the catalog is unknown the lag list stays empty and the
|
|
77
|
-
// report says the comparison was skipped).
|
|
78
|
-
const hostCatalogIds = input.hostCatalogIds;
|
|
79
|
-
const hostCatalogAvailable = Array.isArray(hostCatalogIds);
|
|
80
|
-
const hostSet = hostCatalogAvailable ? new Set(hostCatalogIds) : undefined;
|
|
81
|
-
const hostCatalogLag = available && hostSet !== undefined
|
|
82
|
-
? officialIds.filter((id) => !hostSet.has(id)).sort((a, b) => a.localeCompare(b))
|
|
83
|
-
: [];
|
|
84
|
-
const routes = input.routes.map((config) => {
|
|
85
|
-
if (config.managed) {
|
|
86
|
-
const configured = config.configuredIds;
|
|
87
|
-
return {
|
|
88
|
-
route: config.route,
|
|
89
|
-
official: [...officialIds],
|
|
90
|
-
configured,
|
|
91
|
-
added: available ? missingFrom(officialIds, configured) : [],
|
|
92
|
-
missing: available ? missingFrom(configured, officialIds) : [],
|
|
93
|
-
hostCatalogLag,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
// Legacy protocol route: no official placement anymore; listed for the
|
|
97
|
-
// superseded hint only.
|
|
98
|
-
return {
|
|
99
|
-
route: config.route,
|
|
100
|
-
official: [],
|
|
101
|
-
configured: config.configuredIds,
|
|
102
|
-
added: [],
|
|
103
|
-
missing: [],
|
|
104
|
-
hostCatalogLag: [],
|
|
105
|
-
superseded: true,
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
const report = {
|
|
109
|
-
source: 'opencode-go-official',
|
|
110
|
-
generatedAt: input.generatedAt ?? Date.now(),
|
|
111
|
-
authStatus: input.source.authStatus,
|
|
112
|
-
keyFingerprint: input.source.keyFingerprint,
|
|
113
|
-
hostCatalogAvailable,
|
|
114
|
-
routes,
|
|
115
|
-
};
|
|
116
|
-
if (input.source.payloadHash !== undefined)
|
|
117
|
-
report.payloadHash = input.source.payloadHash;
|
|
118
|
-
if (input.source.error !== undefined)
|
|
119
|
-
report.error = input.source.error;
|
|
120
|
-
return report;
|
|
121
|
-
}
|
|
122
|
-
/** Human-readable rendering of the structured report (command output). */
|
|
123
|
-
export function formatGoDiagnosticReport(report) {
|
|
124
|
-
const lines = [
|
|
125
|
-
'opencode-go official /v1/models diagnostic (read-only; no settings written)',
|
|
126
|
-
` authStatus: ${report.authStatus}`,
|
|
127
|
-
` keyFingerprint: ${report.keyFingerprint}`,
|
|
128
|
-
` host catalog: ${report.hostCatalogAvailable ? 'available (lag comparison done)' : 'UNAVAILABLE — 宿主运行时目录未知,未做滞后对比'}`,
|
|
129
|
-
];
|
|
130
|
-
if (report.payloadHash !== undefined)
|
|
131
|
-
lines.push(` payloadHash: ${report.payloadHash}`);
|
|
132
|
-
if (report.error !== undefined) {
|
|
133
|
-
lines.push(` status: ${report.error.kind}${report.error.status !== undefined ? ` (HTTP ${report.error.status})` : ''}`);
|
|
134
|
-
lines.push(` reason: ${report.error.message}`);
|
|
135
|
-
}
|
|
136
|
-
for (const route of report.routes) {
|
|
137
|
-
if (route.superseded === true) {
|
|
138
|
-
lines.push(` ${route.route} [legacy/superseded]: configured ${route.configured.length}`
|
|
139
|
-
+ ` (${route.configured.join(', ') || 'none'})`
|
|
140
|
-
+ ' — superseded by the single managed route; sync unsets it when fully plugin-managed');
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
lines.push(` ${route.route} [managed]: official ${route.official.length}, configured ${route.configured.length}`
|
|
144
|
-
+ `; +${route.added.join(', +') || 'none'}`
|
|
145
|
-
+ `; -${route.missing.join(', -') || 'none'}`);
|
|
146
|
-
// 0.12.1: official-but-not-in-host-catalog is HOST-SIDE lag, deliberately
|
|
147
|
-
// listed apart from the configured diff — sync keeps these out of the
|
|
148
|
-
// route (needs-host-catalog) and they auto-join after a host upgrade.
|
|
149
|
-
if (route.hostCatalogLag.length > 0) {
|
|
150
|
-
lines.push(` host-catalog lag: ${route.hostCatalogLag.join(', ')}`
|
|
151
|
-
+ ' — 官方 listing 有、宿主内置目录没有(宿主侧滞后,非本插件问题);sync 不会写入,宿主升级后自动纳入');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return lines.join('\n');
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Run one read-only diagnostic: fetch official models, read the profile's
|
|
158
|
-
* route config, and return the structured report. Pass `fetchImpl` in tests
|
|
159
|
-
* so no network is ever touched.
|
|
160
|
-
*/
|
|
161
|
-
export async function runGoDiagnostic(options = {}) {
|
|
162
|
-
const source = await fetchGoOfficialModels({
|
|
163
|
-
apiKey: options.apiKey,
|
|
164
|
-
url: options.url,
|
|
165
|
-
timeoutMs: options.timeoutMs,
|
|
166
|
-
fetchImpl: options.fetchImpl,
|
|
167
|
-
observedAt: options.generatedAt,
|
|
168
|
-
});
|
|
169
|
-
const routes = readGoRoutesFromDescriptor(options.descriptor, options.routes);
|
|
170
|
-
return buildGoDiagnosticReport({
|
|
171
|
-
source,
|
|
172
|
-
routes,
|
|
173
|
-
hostCatalogIds: options.hostCatalogIds,
|
|
174
|
-
generatedAt: options.generatedAt,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
//# sourceMappingURL=opencode-go-diagnose.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"opencode-go-diagnose.js","sourceRoot":"","sources":["../src/opencode-go-diagnose.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,uEAAuE;AACvE,kEAAkE;AAClE,EAAE;AACF,wEAAwE;AACxE,8EAA8E;AAC9E,wEAAwE;AACxE,uEAAuE;AACvE,gDAAgD;AAChD,EAAE;AACF,8EAA8E;AAC9E,+EAA+E;AAC/E,mEAAmE;AACnE,EAAE;AACF,qEAAqE;AAErE,OAAO,EACL,qBAAqB,GAKtB,MA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CAAC,GAAG;QAChB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,UAAU,EAAE,OAAO,CAAC,WAAW;KAChC,CAAC,CAAA;IACF,MAAM,MAAM,GAAG,0BAA0B,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7E,OAAO,uBAAuB,CAAC;QAC7B,MAAM;QACN,MAAM;QACN,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** The route slots of the go topology. `chat` is the only managed route; the
|
|
2
|
-
* other three are legacy cleanup targets kept for `go.routes` compat. */
|
|
3
|
-
export type GoRouteSlot = 'chat' | 'msg' | 'resp' | 'google';
|
|
4
|
-
export declare const GO_ROUTE_SLOTS: readonly GoRouteSlot[];
|
|
5
|
-
/** Default route id per slot (design §6.2.6). The `chat` id names the single
|
|
6
|
-
* managed route; msg/resp/google name the legacy routes sync cleans up. */
|
|
7
|
-
export declare const GO_SLOT_ROUTES: Readonly<Record<GoRouteSlot, string>>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Route topology for the opencode-go single-route (catalog-reuse) write shape.
|
|
2
|
-
//
|
|
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.
|
|
12
|
-
export const GO_ROUTE_SLOTS = ['chat', 'msg', 'resp', 'google'];
|
|
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. */
|
|
15
|
-
export const GO_SLOT_ROUTES = {
|
|
16
|
-
chat: 'opencode-go',
|
|
17
|
-
msg: 'opencode-go-msg',
|
|
18
|
-
resp: 'opencode-go-resp',
|
|
19
|
-
google: 'opencode-go-google',
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=opencode-go-grouping.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/** The pi-ai builtin catalog provider id backing the opencode-go route. */
|
|
2
|
-
export declare const HOST_CATALOG_PROVIDER = "opencode-go";
|
|
3
|
-
/** The settings namespace whose registered discovery serves the request. */
|
|
4
|
-
export declare const HOST_CATALOG_SETTINGS_NS = "llm-pi-ai";
|
|
5
|
-
/** One entry of the host llm adapter's discovery reply (structural subset). */
|
|
6
|
-
export interface HostDiscoveredModel {
|
|
7
|
-
id?: unknown;
|
|
8
|
-
}
|
|
9
|
-
/** The `llm` service subset this module consumes (see dsh-llm types). */
|
|
10
|
-
export interface HostCatalogLlmSeam {
|
|
11
|
-
discoverModels?(settingsNs: string, request: {
|
|
12
|
-
provider?: string;
|
|
13
|
-
baseURL?: string;
|
|
14
|
-
api?: string;
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
}, signal?: AbortSignal): Promise<readonly HostDiscoveredModel[]>;
|
|
17
|
-
}
|
|
18
|
-
/** Why the host catalog could not be read (carried verbatim in reports). */
|
|
19
|
-
export type HostCatalogUnavailable = 'llm-service-unavailable' | 'discovery-failed' | 'empty-catalog';
|
|
20
|
-
export type GoHostCatalogResult = {
|
|
21
|
-
ok: true;
|
|
22
|
-
ids: string[];
|
|
23
|
-
} | {
|
|
24
|
-
ok: false;
|
|
25
|
-
reason: HostCatalogUnavailable;
|
|
26
|
-
message: string;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Normalize a discovery reply into a sorted unique id list. Non-string/empty
|
|
30
|
-
* ids are dropped; the result is deterministic for report/plan hashing.
|
|
31
|
-
*/
|
|
32
|
-
export declare function parseGoHostCatalogModels(models: readonly HostDiscoveredModel[]): string[];
|
|
33
|
-
/**
|
|
34
|
-
* Read the host runtime catalog for opencode-go through the llm discovery
|
|
35
|
-
* seam. Never throws: every failure is a structured `{ ok: false }` result so
|
|
36
|
-
* callers decide between fail-closed (writes) and degrade (diagnostics).
|
|
37
|
-
*/
|
|
38
|
-
export declare function loadHostGoCatalogIds(llm: HostCatalogLlmSeam | undefined, options?: {
|
|
39
|
-
provider?: string;
|
|
40
|
-
settingsNs?: string;
|
|
41
|
-
signal?: AbortSignal;
|
|
42
|
-
}): Promise<GoHostCatalogResult>;
|