@aiwayds/dsh-model-sync 0.12.0 → 0.13.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.
- package/README.md +18 -17
- package/README.zh-CN.md +18 -17
- package/lib/index.d.ts +54 -376
- package/lib/index.js +305 -1049
- 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 +116 -0
- package/lib/official-migrate.js +643 -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 +351 -1214
- package/src/official-adapter.ts +111 -0
- package/src/official-migrate.ts +840 -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 -75
- package/lib/opencode-go-diagnose.js +0 -146
- 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-journal.d.ts +0 -110
- 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 -345
- package/lib/opencode-go-migrate.js +0 -1371
- package/lib/opencode-go-migrate.js.map +0 -1
- package/lib/opencode-go-migration.d.ts +0 -227
- package/lib/opencode-go-migration.js +0 -384
- package/lib/opencode-go-migration.js.map +0 -1
- package/lib/opencode-go-one-shot.d.ts +0 -276
- package/lib/opencode-go-one-shot.js +0 -1096
- package/lib/opencode-go-one-shot.js.map +0 -1
- package/lib/opencode-go-planner.d.ts +0 -154
- package/lib/opencode-go-planner.js +0 -305
- 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 -94
- package/lib/opencode-go-sync.js +0 -364
- package/lib/opencode-go-sync.js.map +0 -1
- package/lib/opencode-go-writer.d.ts +0 -132
- package/lib/opencode-go-writer.js +0 -977
- package/lib/opencode-go-writer.js.map +0 -1
- package/src/opencode-go-diagnose.ts +0 -223
- package/src/opencode-go-grouping.ts +0 -26
- package/src/opencode-go-journal.ts +0 -458
- package/src/opencode-go-migrate.ts +0 -1764
- package/src/opencode-go-migration.ts +0 -552
- package/src/opencode-go-one-shot.ts +0 -1356
- package/src/opencode-go-planner.ts +0 -472
- package/src/opencode-go-scheduler.ts +0 -315
- package/src/opencode-go-store.ts +0 -73
- package/src/opencode-go-sync.ts +0 -503
- package/src/opencode-go-writer.ts +0 -1201
|
@@ -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.0'
|
|
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,75 +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
|
-
/** Legacy protocol route superseded by the single managed route. */
|
|
25
|
-
superseded?: boolean;
|
|
26
|
-
}
|
|
27
|
-
/** Structured diagnostic report emitted by P0. */
|
|
28
|
-
export interface GoDiagnosticReport {
|
|
29
|
-
source: 'opencode-go-official';
|
|
30
|
-
generatedAt: number;
|
|
31
|
-
authStatus: GoAuthStatus;
|
|
32
|
-
keyFingerprint: string;
|
|
33
|
-
payloadHash?: string;
|
|
34
|
-
error?: GoSourceError;
|
|
35
|
-
/** First entry = the managed route diff; remaining = legacy routes found. */
|
|
36
|
-
routes: GoRouteDiff[];
|
|
37
|
-
}
|
|
38
|
-
/** Inputs to buildGoDiagnosticReport — all already-resolved (pure). */
|
|
39
|
-
export interface BuildGoDiagnosticInput {
|
|
40
|
-
source: GoSourceResult;
|
|
41
|
-
routes: readonly GoRouteConfig[];
|
|
42
|
-
generatedAt?: number;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Read the profile's opencode-go route model ids from a settings descriptor.
|
|
46
|
-
* The single managed route (`chat` slot) is always present (possibly empty);
|
|
47
|
-
* the three legacy slot routes are listed only when they actually exist in
|
|
48
|
-
* the profile. This is a pure read — the descriptor is never modified.
|
|
49
|
-
*/
|
|
50
|
-
export declare function readGoRoutesFromDescriptor(desc: GoSettingsDescriptor | undefined): GoRouteConfig[];
|
|
51
|
-
/**
|
|
52
|
-
* Build the structured report. When the source read failed (no key, auth,
|
|
53
|
-
* entitlement, transport), the official side is empty and the diff is
|
|
54
|
-
* suppressed — reporting every configured model as "missing" from a failed
|
|
55
|
-
* read would be misleading. The failure is carried in authStatus / error
|
|
56
|
-
* instead.
|
|
57
|
-
*/
|
|
58
|
-
export declare function buildGoDiagnosticReport(input: BuildGoDiagnosticInput): GoDiagnosticReport;
|
|
59
|
-
/** Human-readable rendering of the structured report (command output). */
|
|
60
|
-
export declare function formatGoDiagnosticReport(report: GoDiagnosticReport): string;
|
|
61
|
-
/** Options for one diagnostic run. */
|
|
62
|
-
export interface RunGoDiagnosticOptions {
|
|
63
|
-
apiKey?: string;
|
|
64
|
-
descriptor?: GoSettingsDescriptor | undefined;
|
|
65
|
-
url?: string;
|
|
66
|
-
timeoutMs?: number;
|
|
67
|
-
fetchImpl?: GoFetchLike;
|
|
68
|
-
generatedAt?: number;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Run one read-only diagnostic: fetch official models, read the profile's
|
|
72
|
-
* route config, and return the structured report. Pass `fetchImpl` in tests
|
|
73
|
-
* so no network is ever touched.
|
|
74
|
-
*/
|
|
75
|
-
export declare function runGoDiagnostic(options?: RunGoDiagnosticOptions): Promise<GoDiagnosticReport>;
|
|
@@ -1,146 +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
|
-
export function readGoRoutesFromDescriptor(desc) {
|
|
41
|
-
const providers = desc?.user?.providers;
|
|
42
|
-
const table = isRecord(providers) ? providers : {};
|
|
43
|
-
const configs = [toRouteConfig(GO_SLOT_ROUTES.chat, true, table)];
|
|
44
|
-
for (const slot of ['msg', 'resp', 'google']) {
|
|
45
|
-
const route = GO_SLOT_ROUTES[slot];
|
|
46
|
-
if (!isRecord(table[route]))
|
|
47
|
-
continue;
|
|
48
|
-
configs.push(toRouteConfig(route, false, table));
|
|
49
|
-
}
|
|
50
|
-
return configs;
|
|
51
|
-
}
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
// Pure diff + report
|
|
54
|
-
// ---------------------------------------------------------------------------
|
|
55
|
-
function missingFrom(left, right) {
|
|
56
|
-
const rightSet = new Set(right);
|
|
57
|
-
return left.filter((id) => !rightSet.has(id));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Build the structured report. When the source read failed (no key, auth,
|
|
61
|
-
* entitlement, transport), the official side is empty and the diff is
|
|
62
|
-
* suppressed — reporting every configured model as "missing" from a failed
|
|
63
|
-
* read would be misleading. The failure is carried in authStatus / error
|
|
64
|
-
* instead.
|
|
65
|
-
*/
|
|
66
|
-
export function buildGoDiagnosticReport(input) {
|
|
67
|
-
const available = input.source.ok;
|
|
68
|
-
const officialIds = available ? input.source.entries.map((entry) => entry.id) : [];
|
|
69
|
-
const routes = input.routes.map((config) => {
|
|
70
|
-
if (config.managed) {
|
|
71
|
-
const configured = config.configuredIds;
|
|
72
|
-
return {
|
|
73
|
-
route: config.route,
|
|
74
|
-
official: [...officialIds],
|
|
75
|
-
configured,
|
|
76
|
-
added: available ? missingFrom(officialIds, configured) : [],
|
|
77
|
-
missing: available ? missingFrom(configured, officialIds) : [],
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
// Legacy protocol route: no official placement anymore; listed for the
|
|
81
|
-
// superseded hint only.
|
|
82
|
-
return {
|
|
83
|
-
route: config.route,
|
|
84
|
-
official: [],
|
|
85
|
-
configured: config.configuredIds,
|
|
86
|
-
added: [],
|
|
87
|
-
missing: [],
|
|
88
|
-
superseded: true,
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
const report = {
|
|
92
|
-
source: 'opencode-go-official',
|
|
93
|
-
generatedAt: input.generatedAt ?? Date.now(),
|
|
94
|
-
authStatus: input.source.authStatus,
|
|
95
|
-
keyFingerprint: input.source.keyFingerprint,
|
|
96
|
-
routes,
|
|
97
|
-
};
|
|
98
|
-
if (input.source.payloadHash !== undefined)
|
|
99
|
-
report.payloadHash = input.source.payloadHash;
|
|
100
|
-
if (input.source.error !== undefined)
|
|
101
|
-
report.error = input.source.error;
|
|
102
|
-
return report;
|
|
103
|
-
}
|
|
104
|
-
/** Human-readable rendering of the structured report (command output). */
|
|
105
|
-
export function formatGoDiagnosticReport(report) {
|
|
106
|
-
const lines = [
|
|
107
|
-
'opencode-go official /v1/models diagnostic (read-only; no settings written)',
|
|
108
|
-
` authStatus: ${report.authStatus}`,
|
|
109
|
-
` keyFingerprint: ${report.keyFingerprint}`,
|
|
110
|
-
];
|
|
111
|
-
if (report.payloadHash !== undefined)
|
|
112
|
-
lines.push(` payloadHash: ${report.payloadHash}`);
|
|
113
|
-
if (report.error !== undefined) {
|
|
114
|
-
lines.push(` status: ${report.error.kind}${report.error.status !== undefined ? ` (HTTP ${report.error.status})` : ''}`);
|
|
115
|
-
lines.push(` reason: ${report.error.message}`);
|
|
116
|
-
}
|
|
117
|
-
for (const route of report.routes) {
|
|
118
|
-
if (route.superseded === true) {
|
|
119
|
-
lines.push(` ${route.route} [legacy/superseded]: configured ${route.configured.length}`
|
|
120
|
-
+ ` (${route.configured.join(', ') || 'none'})`
|
|
121
|
-
+ ' — superseded by the single managed route; sync unsets it when fully plugin-managed');
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
lines.push(` ${route.route} [managed]: official ${route.official.length}, configured ${route.configured.length}`
|
|
125
|
-
+ `; +${route.added.join(', +') || 'none'}`
|
|
126
|
-
+ `; -${route.missing.join(', -') || 'none'}`);
|
|
127
|
-
}
|
|
128
|
-
return lines.join('\n');
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Run one read-only diagnostic: fetch official models, read the profile's
|
|
132
|
-
* route config, and return the structured report. Pass `fetchImpl` in tests
|
|
133
|
-
* so no network is ever touched.
|
|
134
|
-
*/
|
|
135
|
-
export async function runGoDiagnostic(options = {}) {
|
|
136
|
-
const source = await fetchGoOfficialModels({
|
|
137
|
-
apiKey: options.apiKey,
|
|
138
|
-
url: options.url,
|
|
139
|
-
timeoutMs: options.timeoutMs,
|
|
140
|
-
fetchImpl: options.fetchImpl,
|
|
141
|
-
observedAt: options.generatedAt,
|
|
142
|
-
});
|
|
143
|
-
const routes = readGoRoutesFromDescriptor(options.descriptor);
|
|
144
|
-
return buildGoDiagnosticReport({ source, routes, generatedAt: options.generatedAt });
|
|
145
|
-
}
|
|
146
|
-
//# 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,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAiD1D,8EAA8E;AAC9E,+BAA+B;AAC/B,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,SAAS,aAAa,CAAC,KAAa,EAAE,OAAgB,EAAE,SAAkC;IACxF,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;IAClC,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;IACjE,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACzC,CAAC,CAAC,MAAM;aACH,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;aACtF,MAAM,CAAC,CAAC,EAAE,EAAgB,EAAE,CAAC,EAAE,KAAK,SAAS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K,wBAAwB,KAAK,CAAC,QAAQ,CAAC,MAAM,gBAAgB,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE;cACpG,MAAM,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,EAAE;cACzC,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,EAAE,CAC9C,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAgBD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAAkC,EAAE;IACxE,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,OAAO,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,CAAC,CAAA;IAC7D,OAAO,uBAAuB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;AACtF,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,110 +0,0 @@
|
|
|
1
|
-
import { type GoOwnershipEntry } from './opencode-go-planner.ts';
|
|
2
|
-
import type { GoOwnershipStore } from './opencode-go-writer.ts';
|
|
3
|
-
import { type ModelsStoreAccessor } from './remote-catalog.ts';
|
|
4
|
-
import type { SettingsModelProfile } from './translate.ts';
|
|
5
|
-
import type { Logger, SettingsService } from './writer.ts';
|
|
6
|
-
declare const JOURNAL_VERSION = 1;
|
|
7
|
-
export interface GoWriteJournal {
|
|
8
|
-
version: typeof JOURNAL_VERSION;
|
|
9
|
-
/** Profile scope stamped at write time; must match the reconciling profile. */
|
|
10
|
-
profileKey: string;
|
|
11
|
-
route: string;
|
|
12
|
-
/** Credential fingerprint stamped at write time; must match the current key. */
|
|
13
|
-
keyFingerprint: string;
|
|
14
|
-
/** Ledger-managed ids this write was about to commit (sorted). */
|
|
15
|
-
modelIds: string[];
|
|
16
|
-
/** sha256 of the sorted models array we were about to write. */
|
|
17
|
-
contentHash: string;
|
|
18
|
-
/** Host settings revision the mutate was issued against (diagnostic only). */
|
|
19
|
-
expectedRevision?: number;
|
|
20
|
-
/** True for a whole-route unset (reconciliation deletes the ledger slot). */
|
|
21
|
-
unset: boolean;
|
|
22
|
-
/** Exact ledger entry to re-commit when not unset. */
|
|
23
|
-
entry?: GoOwnershipEntry;
|
|
24
|
-
/** Write timestamp (injected clock in tests). */
|
|
25
|
-
at: number;
|
|
26
|
-
}
|
|
27
|
-
export interface JournalReadResult {
|
|
28
|
-
journal?: GoWriteJournal;
|
|
29
|
-
/** Slot existed but could not be parsed — treat as "no journal" + warn. */
|
|
30
|
-
parseError?: string;
|
|
31
|
-
/**
|
|
32
|
-
* The slot held a primitive/null (not an object at all). Such a value can
|
|
33
|
-
* never carry a journal; reconciliation warns AND cleans it (after the
|
|
34
|
-
* key-shape/profile check), unlike a plain parse error on an object slot.
|
|
35
|
-
*/
|
|
36
|
-
rawTypeCorrupt?: boolean;
|
|
37
|
-
}
|
|
38
|
-
export interface GoJournalStore {
|
|
39
|
-
read(key: string): Promise<JournalReadResult>;
|
|
40
|
-
write(key: string, journal: GoWriteJournal): Promise<void>;
|
|
41
|
-
delete(key: string): Promise<void>;
|
|
42
|
-
/** All journal slots belonging to this profile (any key fingerprint). */
|
|
43
|
-
list(profileKey: string): Promise<string[]>;
|
|
44
|
-
/** Delete every journal slot of this profile; returns the number removed. */
|
|
45
|
-
clearProfile(profileKey: string): Promise<number>;
|
|
46
|
-
}
|
|
47
|
-
/** Four-part journal slot: `<profile>#<route>#<keyFingerprint>#journal`. */
|
|
48
|
-
export declare function goJournalKey(profileKey: string, route: string, keyFingerprint: string): string;
|
|
49
|
-
/**
|
|
50
|
-
* True for a syntactically journal-shaped slot of the given profile. We match
|
|
51
|
-
* the profile PREFIX and the `#journal` TAIL rather than a fixed part count: a
|
|
52
|
-
* profile name may itself contain '#', and the payload's profile/fingerprint
|
|
53
|
-
* stamps are validated independently on read.
|
|
54
|
-
*/
|
|
55
|
-
export declare function isJournalKey(key: string, profileKey: string): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Stable content hash of a route's models array. The writer calls this on the
|
|
58
|
-
* exact array it hands to settings.mutate; reconciliation calls it on the raw
|
|
59
|
-
* models read back from settings. Sorting by id + recursively canonical field
|
|
60
|
-
* order makes the two agree regardless of key insertion or array order.
|
|
61
|
-
*/
|
|
62
|
-
export declare function journalContentHash(models: readonly SettingsModelProfile[]): string;
|
|
63
|
-
/** Strict parse: any missing/mistyped field is a parse failure, never a journal. */
|
|
64
|
-
export declare function parseJournal(raw: unknown): {
|
|
65
|
-
journal?: GoWriteJournal;
|
|
66
|
-
error?: string;
|
|
67
|
-
};
|
|
68
|
-
/** File-backed journal store built on the same atomic queue as the ledger. */
|
|
69
|
-
export declare function createFileJournalStore(accessor: ModelsStoreAccessor): GoJournalStore;
|
|
70
|
-
export declare function createModelsStoreJournalStore(storePath?: string): GoJournalStore;
|
|
71
|
-
export interface JournalNotice {
|
|
72
|
-
code: 'journal-reconciled' | 'journal-stale' | 'journal-orphan' | 'journal-unparseable' | 'journal-reconcile-failed' | 'journal-list-failed' | 'journal-descriptor-unavailable';
|
|
73
|
-
level: 'info' | 'warn' | 'error';
|
|
74
|
-
key: string;
|
|
75
|
-
message: string;
|
|
76
|
-
/** True for a primitive/null slot (vs an object that merely failed parsing). */
|
|
77
|
-
rawTypeCorrupt?: boolean;
|
|
78
|
-
}
|
|
79
|
-
export interface ReconcileResult {
|
|
80
|
-
reconciled: string[];
|
|
81
|
-
discarded: string[];
|
|
82
|
-
notices: JournalNotice[];
|
|
83
|
-
lines: string[];
|
|
84
|
-
}
|
|
85
|
-
export interface ReconcileDeps {
|
|
86
|
-
journalStore: GoJournalStore;
|
|
87
|
-
ownershipStore: GoOwnershipStore;
|
|
88
|
-
settings: SettingsService | undefined;
|
|
89
|
-
profileKey: string;
|
|
90
|
-
keyFingerprint: string;
|
|
91
|
-
logger: Logger;
|
|
92
|
-
/** Same callback the writer uses after a healthy own-write: re-persist the
|
|
93
|
-
* migration record. Store/record only — never touches settings. */
|
|
94
|
-
onRecord?: (route: string, managedIds: string[]) => Promise<void> | void;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Reconcile every journal of this profile against the value actually present
|
|
98
|
-
* in settings. Outcomes:
|
|
99
|
-
* hash equal → re-commit ledger + migration record, delete journal;
|
|
100
|
-
* hash differs → the user edited the value: discard journal, keep their value;
|
|
101
|
-
* wrong scope → orphan (profile/key rotation): discard journal;
|
|
102
|
-
* parse fail → treat as no journal, warn, discard;
|
|
103
|
-
* raw-type slot → warn (journal-unparseable + rawTypeCorrupt flag) and clean
|
|
104
|
-
* it after a journal-key / profile safety check;
|
|
105
|
-
* store fail → keep journal for the next round, never block the round.
|
|
106
|
-
*/
|
|
107
|
-
export declare function reconcileJournals(deps: ReconcileDeps): Promise<ReconcileResult>;
|
|
108
|
-
/** One-line summary prepended to the round report when anything reconciled. */
|
|
109
|
-
export declare function formatReconcileSummary(result: ReconcileResult): string;
|
|
110
|
-
export {};
|