@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.
Files changed (88) hide show
  1. package/README.md +18 -17
  2. package/README.zh-CN.md +18 -17
  3. package/lib/index.d.ts +54 -384
  4. package/lib/index.js +306 -1107
  5. package/lib/index.js.map +1 -1
  6. package/lib/official-adapter.d.ts +80 -0
  7. package/lib/official-adapter.js +34 -0
  8. package/lib/official-adapter.js.map +1 -0
  9. package/lib/official-migrate.d.ts +122 -0
  10. package/lib/official-migrate.js +653 -0
  11. package/lib/official-migrate.js.map +1 -0
  12. package/lib/official-scheduler.d.ts +72 -0
  13. package/lib/official-scheduler.js +195 -0
  14. package/lib/official-scheduler.js.map +1 -0
  15. package/lib/official-store.d.ts +41 -0
  16. package/lib/official-store.js +84 -0
  17. package/lib/official-store.js.map +1 -0
  18. package/lib/official-sync.d.ts +68 -0
  19. package/lib/official-sync.js +274 -0
  20. package/lib/official-sync.js.map +1 -0
  21. package/lib/opencode-go-adapter.d.ts +56 -0
  22. package/lib/opencode-go-adapter.js +455 -0
  23. package/lib/opencode-go-adapter.js.map +1 -0
  24. package/lib/opencode-go-patch-file.d.ts +11 -0
  25. package/lib/opencode-go-patch-file.js +175 -11
  26. package/lib/opencode-go-patch-file.js.map +1 -1
  27. package/lib/opencode-go-source.d.ts +1 -1
  28. package/lib/opencode-go-source.js +1 -1
  29. package/locale/en.json +1 -1
  30. package/locale/zh.json +1 -1
  31. package/package.json +3 -3
  32. package/src/index.ts +352 -1281
  33. package/src/official-adapter.ts +111 -0
  34. package/src/official-migrate.ts +863 -0
  35. package/src/official-scheduler.ts +235 -0
  36. package/src/official-store.ts +122 -0
  37. package/src/official-sync.ts +371 -0
  38. package/src/opencode-go-adapter.ts +494 -0
  39. package/src/opencode-go-patch-file.ts +175 -9
  40. package/src/opencode-go-source.ts +1 -1
  41. package/lib/opencode-go-diagnose.d.ts +0 -96
  42. package/lib/opencode-go-diagnose.js +0 -177
  43. package/lib/opencode-go-diagnose.js.map +0 -1
  44. package/lib/opencode-go-grouping.d.ts +0 -7
  45. package/lib/opencode-go-grouping.js +0 -21
  46. package/lib/opencode-go-grouping.js.map +0 -1
  47. package/lib/opencode-go-host-catalog.d.ts +0 -42
  48. package/lib/opencode-go-host-catalog.js +0 -98
  49. package/lib/opencode-go-host-catalog.js.map +0 -1
  50. package/lib/opencode-go-journal.d.ts +0 -114
  51. package/lib/opencode-go-journal.js +0 -406
  52. package/lib/opencode-go-journal.js.map +0 -1
  53. package/lib/opencode-go-migrate.d.ts +0 -378
  54. package/lib/opencode-go-migrate.js +0 -1529
  55. package/lib/opencode-go-migrate.js.map +0 -1
  56. package/lib/opencode-go-migration.d.ts +0 -270
  57. package/lib/opencode-go-migration.js +0 -473
  58. package/lib/opencode-go-migration.js.map +0 -1
  59. package/lib/opencode-go-one-shot.d.ts +0 -282
  60. package/lib/opencode-go-one-shot.js +0 -1131
  61. package/lib/opencode-go-one-shot.js.map +0 -1
  62. package/lib/opencode-go-planner.d.ts +0 -168
  63. package/lib/opencode-go-planner.js +0 -407
  64. package/lib/opencode-go-planner.js.map +0 -1
  65. package/lib/opencode-go-scheduler.d.ts +0 -128
  66. package/lib/opencode-go-scheduler.js +0 -241
  67. package/lib/opencode-go-scheduler.js.map +0 -1
  68. package/lib/opencode-go-store.d.ts +0 -18
  69. package/lib/opencode-go-store.js +0 -68
  70. package/lib/opencode-go-store.js.map +0 -1
  71. package/lib/opencode-go-sync.d.ts +0 -107
  72. package/lib/opencode-go-sync.js +0 -388
  73. package/lib/opencode-go-sync.js.map +0 -1
  74. package/lib/opencode-go-writer.d.ts +0 -148
  75. package/lib/opencode-go-writer.js +0 -1061
  76. package/lib/opencode-go-writer.js.map +0 -1
  77. package/src/opencode-go-diagnose.ts +0 -276
  78. package/src/opencode-go-grouping.ts +0 -26
  79. package/src/opencode-go-host-catalog.ts +0 -125
  80. package/src/opencode-go-journal.ts +0 -460
  81. package/src/opencode-go-migrate.ts +0 -1951
  82. package/src/opencode-go-migration.ts +0 -666
  83. package/src/opencode-go-one-shot.ts +0 -1399
  84. package/src/opencode-go-planner.ts +0 -582
  85. package/src/opencode-go-scheduler.ts +0 -315
  86. package/src/opencode-go-store.ts +0 -73
  87. package/src/opencode-go-sync.ts +0 -541
  88. package/src/opencode-go-writer.ts +0 -1301
@@ -1,98 +0,0 @@
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
- /** The pi-ai builtin catalog provider id backing the opencode-go route. */
31
- export const HOST_CATALOG_PROVIDER = 'opencode-go';
32
- /** The settings namespace whose registered discovery serves the request. */
33
- export const HOST_CATALOG_SETTINGS_NS = 'llm-pi-ai';
34
- /**
35
- * Normalize a discovery reply into a sorted unique id list. Non-string/empty
36
- * ids are dropped; the result is deterministic for report/plan hashing.
37
- */
38
- export function parseGoHostCatalogModels(models) {
39
- // P1-2: the reply comes from a host seam whose shape we do not control — a
40
- // non-array reply (a buggy adapter) must degrade to "no ids" here, never
41
- // throw a TypeError out of the for-of. The caller maps [] to the structured
42
- // `empty-catalog` result, keeping the never-throw contract.
43
- if (!Array.isArray(models))
44
- return [];
45
- const ids = new Set();
46
- for (const model of models) {
47
- if (model === null || typeof model !== 'object')
48
- continue;
49
- const id = model.id;
50
- if (typeof id !== 'string' || id.length === 0)
51
- continue;
52
- ids.add(id);
53
- }
54
- return [...ids].sort((a, b) => a.localeCompare(b));
55
- }
56
- function errorText(err) {
57
- const message = err?.message;
58
- return typeof message === 'string' ? message : String(err);
59
- }
60
- /**
61
- * Read the host runtime catalog for opencode-go through the llm discovery
62
- * seam. Never throws: every failure is a structured `{ ok: false }` result so
63
- * callers decide between fail-closed (writes) and degrade (diagnostics).
64
- */
65
- export async function loadHostGoCatalogIds(llm, options = {}) {
66
- const provider = options.provider ?? HOST_CATALOG_PROVIDER;
67
- const settingsNs = options.settingsNs ?? HOST_CATALOG_SETTINGS_NS;
68
- // P1-2: `== null` — an explicitly-injected null must take the structured
69
- // unavailable path, not TypeError on member access.
70
- if (llm == null || typeof llm.discoverModels !== 'function') {
71
- return {
72
- ok: false,
73
- reason: 'llm-service-unavailable',
74
- message: 'llm service has no discoverModels seam (host adapter missing or too old)',
75
- };
76
- }
77
- let models;
78
- try {
79
- models = await llm.discoverModels(settingsNs, { provider }, options.signal);
80
- }
81
- catch (err) {
82
- return {
83
- ok: false,
84
- reason: 'discovery-failed',
85
- message: `discoverModels(${settingsNs}, { provider: ${provider} }) failed: ${errorText(err)}`,
86
- };
87
- }
88
- const ids = parseGoHostCatalogModels(models);
89
- if (ids.length === 0) {
90
- return {
91
- ok: false,
92
- reason: 'empty-catalog',
93
- message: `host runtime catalog lists no model ids for provider ${provider}`,
94
- };
95
- }
96
- return { ok: true, ids };
97
- }
98
- //# sourceMappingURL=opencode-go-host-catalog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"opencode-go-host-catalog.js","sourceRoot":"","sources":["../src/opencode-go-host-catalog.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,2EAA2E;AAC3E,qEAAqE;AACrE,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,8EAA8E;AAC9E,yEAAyE;AACzE,2DAA2D;AAC3D,yDAAyD;AACzD,uEAAuE;AACvE,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,8EAA8E;AAC9E,uBAAuB;AACvB,EAAE;AACF,kDAAkD;AAElD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAA;AAElD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CAAA;AA0BnD;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAsC;IAC7E,2EAA2E;IAC3E,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAA;IACrC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAA;IAC7B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAQ;QACzD,MAAM,EAAE,GAAG,KAA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AO,EAAE,kBAAkB,UAAU,iBAAiB,QAAQ,eAAe,SAAS,CAAC,GAAG,CAAC,EAAE;SAC9F,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAA;IAC5C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,eAAe;YACvB,OAAO,EAAE,wDAAwD,QAAQ,EAAE;SAC5E,CAAA;IACH,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;AAC1B,CAAC"}
@@ -1,114 +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. The third
94
- * argument marks a whole-section unset (ledger key deleted) so the record
95
- * update drops the route's appliedManagedIds key, mirroring the writer. */
96
- onRecord?: (route: string, managedIds: string[], info?: {
97
- unset: boolean;
98
- }) => Promise<void> | void;
99
- }
100
- /**
101
- * Reconcile every journal of this profile against the value actually present
102
- * in settings. Outcomes:
103
- * hash equal → re-commit ledger + migration record, delete journal;
104
- * hash differs → the user edited the value: discard journal, keep their value;
105
- * wrong scope → orphan (profile/key rotation): discard journal;
106
- * parse fail → treat as no journal, warn, discard;
107
- * raw-type slot → warn (journal-unparseable + rawTypeCorrupt flag) and clean
108
- * it after a journal-key / profile safety check;
109
- * store fail → keep journal for the next round, never block the round.
110
- */
111
- export declare function reconcileJournals(deps: ReconcileDeps): Promise<ReconcileResult>;
112
- /** One-line summary prepended to the round report when anything reconciled. */
113
- export declare function formatReconcileSummary(result: ReconcileResult): string;
114
- export {};
@@ -1,406 +0,0 @@
1
- // O1/C2: write-ahead journal + next-round reconciliation. The go writer's real
2
- // order is `settings.mutate` → ownership ledger → migration record. A crash (or
3
- // a store write failure) between those steps leaves settings AHEAD of the two
4
- // store records: on the next round the route looks user-owned, the migration
5
- // gate can close forever (S1), a new model is never claimed (S2), and rollback
6
- // refuses with hash-mismatch (S3). No settings rollback is attempted (the
7
- // cross-process lock does not cover settings.mutate); instead this module
8
- // records the intended write BEFORE the mutate and reconciles it on the next
9
- // round, converging on the hash of the value actually present in settings.
10
- //
11
- // Wire format: one opaque slot per route in the SAME ~/.dsh/models-store.json
12
- // (same queue / atomic temp+rename as the ledger and migration record):
13
- // `<profileKey>#<route>#<keyFingerprint>#journal` -> GoWriteJournal
14
- // Four '#'-separated parts. `isUnscopedStoreKey` only classifies TWO-part keys
15
- // as unscoped legacy slots, so a journal key is never reported/claimed as a
16
- // foreign legacy record. The profile and fingerprint are BOTH stamped inside
17
- // the payload and validated on read, so a rotated key or another profile's
18
- // journal is discarded instead of being replayed onto the wrong ledger slot.
19
- //
20
- // Reconciliation is store/record-only: it NEVER calls settings.mutate. If the
21
- // present value's content hash equals the recorded post-write hash, our write
22
- // is intact and the ledger + migration record are re-committed; otherwise the
23
- // user changed the value and the journal is dropped (their value is kept).
24
- import { createHash } from 'node:crypto';
25
- import { goOwnershipKey } from "./opencode-go-planner.js";
26
- import { loadModelsStore } from "./remote-catalog.js";
27
- const JOURNAL_TAIL = 'journal';
28
- const JOURNAL_VERSION = 1;
29
- /** Four-part journal slot: `<profile>#<route>#<keyFingerprint>#journal`. */
30
- export function goJournalKey(profileKey, route, keyFingerprint) {
31
- return `${profileKey}#${goOwnershipKey(route, keyFingerprint)}#${JOURNAL_TAIL}`;
32
- }
33
- /**
34
- * True for a syntactically journal-shaped slot of the given profile. We match
35
- * the profile PREFIX and the `#journal` TAIL rather than a fixed part count: a
36
- * profile name may itself contain '#', and the payload's profile/fingerprint
37
- * stamps are validated independently on read.
38
- */
39
- export function isJournalKey(key, profileKey) {
40
- const prefix = `${profileKey}#`;
41
- const tail = `#${JOURNAL_TAIL}`;
42
- if (!key.startsWith(prefix) || !key.endsWith(tail))
43
- return false;
44
- const middle = key.slice(prefix.length, -tail.length);
45
- return middle.length > 0 && middle.includes('#');
46
- }
47
- function canonicalize(value) {
48
- if (Array.isArray(value))
49
- return value.map(canonicalize);
50
- if (isRecord(value)) {
51
- const out = {};
52
- for (const key of Object.keys(value).sort())
53
- out[key] = canonicalize(value[key]);
54
- return out;
55
- }
56
- return value;
57
- }
58
- /**
59
- * Stable content hash of a route's models array. The writer calls this on the
60
- * exact array it hands to settings.mutate; reconciliation calls it on the raw
61
- * models read back from settings. Sorting by id + recursively canonical field
62
- * order makes the two agree regardless of key insertion or array order.
63
- */
64
- export function journalContentHash(models) {
65
- // oldfox #5: localeCompare is host/locale-dependent, so the same models array
66
- // could hash differently on two machines sharing a store → `journal-stale`
67
- // false positives. JS string `<` compares UTF-16 code units (deterministic
68
- // byte/codepoint order for these ASCII ids), making the hash locale-proof.
69
- const stable = [...models]
70
- .sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
71
- .map((model) => canonicalize(model));
72
- return createHash('sha256').update(JSON.stringify(stable)).digest('hex');
73
- }
74
- function errorText(err) {
75
- const message = err?.message;
76
- return typeof message === 'string' ? message : String(err);
77
- }
78
- function isRecord(value) {
79
- return typeof value === 'object' && value !== null && !Array.isArray(value);
80
- }
81
- /**
82
- * Defensive bound against a corrupt/hostile journal carrying an oversized
83
- * entry. Legitimate ledgers are far smaller; this only rejects absurd arrays
84
- * before they are copied into an in-memory ledger.
85
- */
86
- const MAX_LEDGER_ENTRIES = 100_000;
87
- /**
88
- * oldfox #4: `entry` is the exact object reconciliation re-commits to the
89
- * ownership ledger, so a malformed one must never enter it. parseJournal used
90
- * to accept any object here; validate the real GoOwnershipEntry shape instead:
91
- * the required `managed` id→{hash} map plus every optional field's type. On
92
- * failure the whole slot is treated as an unparseable journal (warn + clean),
93
- * never reconciled.
94
- */
95
- function isValidOwnershipEntry(value) {
96
- if (!isRecord(value))
97
- return false;
98
- const managed = value.managed;
99
- if (!isRecord(managed))
100
- return false;
101
- const ids = Object.keys(managed);
102
- if (ids.length > MAX_LEDGER_ENTRIES)
103
- return false;
104
- for (const id of ids) {
105
- if (id.length === 0)
106
- return false;
107
- const owner = managed[id];
108
- if (!isRecord(owner) || typeof owner.hash !== 'string' || owner.hash.length === 0)
109
- return false;
110
- }
111
- if (value.routeFields !== undefined && !isRecord(value.routeFields))
112
- return false;
113
- if (value.preManagedSnapshot !== undefined) {
114
- if (!Array.isArray(value.preManagedSnapshot) || value.preManagedSnapshot.length > MAX_LEDGER_ENTRIES)
115
- return false;
116
- if (value.preManagedSnapshot.some((m) => !isRecord(m) || typeof m.id !== 'string'))
117
- return false;
118
- }
119
- if (value.preManagedSection !== undefined
120
- && value.preManagedSection !== null && !isRecord(value.preManagedSection))
121
- return false;
122
- if (value.appliedAddedIds !== undefined) {
123
- if (!Array.isArray(value.appliedAddedIds) || value.appliedAddedIds.length > MAX_LEDGER_ENTRIES)
124
- return false;
125
- if (value.appliedAddedIds.some((id) => typeof id !== 'string'))
126
- return false;
127
- }
128
- if (value.missing !== undefined) {
129
- if (!isRecord(value.missing))
130
- return false;
131
- const missingIds = Object.keys(value.missing);
132
- if (missingIds.length > MAX_LEDGER_ENTRIES)
133
- return false;
134
- for (const id of missingIds) {
135
- const count = value.missing[id];
136
- if (typeof count !== 'number' || !Number.isFinite(count))
137
- return false;
138
- }
139
- }
140
- return true;
141
- }
142
- /** Strict parse: any missing/mistyped field is a parse failure, never a journal. */
143
- export function parseJournal(raw) {
144
- if (!isRecord(raw))
145
- return { error: 'journal slot is not an object' };
146
- if (raw.version !== JOURNAL_VERSION)
147
- return { error: `unsupported journal version ${String(raw.version)}` };
148
- if (typeof raw.profileKey !== 'string' || raw.profileKey.length === 0)
149
- return { error: 'journal has no profileKey' };
150
- if (typeof raw.route !== 'string' || raw.route.length === 0)
151
- return { error: 'journal has no route' };
152
- if (typeof raw.keyFingerprint !== 'string' || raw.keyFingerprint.length === 0)
153
- return { error: 'journal has no keyFingerprint' };
154
- if (!Array.isArray(raw.modelIds) || raw.modelIds.some((id) => typeof id !== 'string')) {
155
- return { error: 'journal has invalid modelIds' };
156
- }
157
- if (typeof raw.contentHash !== 'string' || raw.contentHash.length === 0)
158
- return { error: 'journal has no contentHash' };
159
- if (typeof raw.unset !== 'boolean')
160
- return { error: 'journal has no unset flag' };
161
- if (!raw.unset && raw.entry === undefined)
162
- return { error: 'journal has no ledger entry' };
163
- if (typeof raw.at !== 'number' || !Number.isFinite(raw.at))
164
- return { error: 'journal has invalid timestamp' };
165
- const journal = {
166
- version: JOURNAL_VERSION,
167
- profileKey: raw.profileKey,
168
- route: raw.route,
169
- keyFingerprint: raw.keyFingerprint,
170
- modelIds: [...raw.modelIds],
171
- contentHash: raw.contentHash,
172
- unset: raw.unset,
173
- at: raw.at,
174
- };
175
- if (typeof raw.expectedRevision === 'number')
176
- journal.expectedRevision = raw.expectedRevision;
177
- // Validate whenever an entry is present (also on unset journals, where a
178
- // stale malformed entry must not survive into a later re-commit).
179
- if (raw.entry !== undefined) {
180
- if (!isValidOwnershipEntry(raw.entry))
181
- return { error: 'journal has invalid ledger entry' };
182
- journal.entry = raw.entry;
183
- }
184
- return { journal };
185
- }
186
- /** File-backed journal store built on the same atomic queue as the ledger. */
187
- export function createFileJournalStore(accessor) {
188
- return {
189
- async read(key) {
190
- let raw;
191
- try {
192
- raw = await accessor.readRaw(key);
193
- }
194
- catch (err) {
195
- return { parseError: `journal read failed: ${errorText(err)}` };
196
- }
197
- if (raw === undefined)
198
- return {};
199
- if (!isRecord(raw)) {
200
- // A primitive/null slot is not "no journal" — it is corruption that
201
- // can never carry a valid journal. Flag it so reconciliation warns and
202
- // cleans it under the key-shape/profile safety check.
203
- return {
204
- parseError: `journal slot held a non-object value (${raw === null ? 'null' : typeof raw})`,
205
- rawTypeCorrupt: true,
206
- };
207
- }
208
- const parsed = parseJournal(raw);
209
- return parsed.journal !== undefined
210
- ? { journal: parsed.journal }
211
- : { parseError: parsed.error ?? 'unknown journal parse failure' };
212
- },
213
- async write(key, journal) {
214
- await accessor.writeRaw(key, journal);
215
- },
216
- async delete(key) {
217
- await accessor.deleteRaw(key);
218
- },
219
- async list(profileKey) {
220
- // Do NOT swallow enumeration failures. An unreadable store must reach
221
- // reconcileJournals' try/catch and surface `journal-list-failed`, not be
222
- // mistaken for "no journals this round".
223
- return (await accessor.listRawKeys()).filter((key) => isJournalKey(key, profileKey));
224
- },
225
- async clearProfile(profileKey) {
226
- const keys = await this.list(profileKey);
227
- let deleted = 0;
228
- for (const key of keys) {
229
- try {
230
- await accessor.deleteRaw(key);
231
- deleted += 1;
232
- }
233
- catch {
234
- // Best effort: a surviving slot is re-validated (and discarded) by
235
- // the next reconciliation, never replayed blindly.
236
- }
237
- }
238
- return deleted;
239
- },
240
- };
241
- }
242
- export function createModelsStoreJournalStore(storePath) {
243
- return createFileJournalStore(loadModelsStore(storePath));
244
- }
245
- function rawModels(desc, route) {
246
- const providers = desc?.user?.providers;
247
- if (providers === undefined)
248
- return [];
249
- const data = providers[route];
250
- if (data === null || typeof data !== 'object' || Array.isArray(data))
251
- return [];
252
- const models = data.models;
253
- return Array.isArray(models) ? models : [];
254
- }
255
- /**
256
- * Reconcile every journal of this profile against the value actually present
257
- * in settings. Outcomes:
258
- * hash equal → re-commit ledger + migration record, delete journal;
259
- * hash differs → the user edited the value: discard journal, keep their value;
260
- * wrong scope → orphan (profile/key rotation): discard journal;
261
- * parse fail → treat as no journal, warn, discard;
262
- * raw-type slot → warn (journal-unparseable + rawTypeCorrupt flag) and clean
263
- * it after a journal-key / profile safety check;
264
- * store fail → keep journal for the next round, never block the round.
265
- */
266
- export async function reconcileJournals(deps) {
267
- const result = { reconciled: [], discarded: [], notices: [], lines: [] };
268
- const notice = (entry) => {
269
- result.notices.push(entry);
270
- result.lines.push(` [${entry.level}] ${entry.code} ${entry.key}: ${entry.message}`);
271
- };
272
- let keys;
273
- try {
274
- keys = await deps.journalStore.list(deps.profileKey);
275
- }
276
- catch (err) {
277
- const key = `profile:${deps.profileKey}`;
278
- deps.logger.warn('journal list failed for %s: %s', deps.profileKey, errorText(err));
279
- notice({
280
- code: 'journal-list-failed', level: 'warn', key,
281
- message: `could not list write-ahead journals (${errorText(err)}); reconciliation skipped this round`,
282
- });
283
- return result;
284
- }
285
- if (keys.length === 0)
286
- return result;
287
- const desc = deps.settings?.describe().find((entry) => entry.ns === 'llm-pi-ai');
288
- if (desc === undefined) {
289
- // Cannot verify the present hash — keep every journal, never guess.
290
- // This is NOT a list failure: enumeration succeeded. Use a dedicated code
291
- // so automation can tell the two apart (oldfox #2). Text stays accurate:
292
- // journals are kept, not discarded.
293
- notice({
294
- code: 'journal-descriptor-unavailable', level: 'warn', key: `profile:${deps.profileKey}`,
295
- message: 'llm-pi-ai descriptor unavailable; journals kept for a later round (reconciliation deferred, no list error)',
296
- });
297
- return result;
298
- }
299
- for (const key of keys) {
300
- let read;
301
- try {
302
- read = await deps.journalStore.read(key);
303
- }
304
- catch (err) {
305
- deps.logger.warn('journal read failed for %s: %s', key, errorText(err));
306
- notice({ code: 'journal-unparseable', level: 'warn', key, message: `read failed (${errorText(err)}); journal kept` });
307
- continue;
308
- }
309
- if (read.parseError !== undefined) {
310
- deps.logger.warn('unparseable journal %s: %s', key, read.parseError);
311
- if (read.rawTypeCorrupt === true) {
312
- // A primitive/null slot can never carry a valid journal. Same warn code
313
- // as an object-shape parse failure, but flagged and explicitly worded so
314
- // the raw-type case is recognizable. Clean it ONLY after re-confirming
315
- // the slot is a journal-shaped key of THIS profile — never touch a
316
- // foreign or non-journal key that happens to hold a primitive.
317
- notice({
318
- code: 'journal-unparseable', level: 'warn', key, rawTypeCorrupt: true,
319
- message: `${read.parseError}; raw-type corruption (cannot carry a journal) — slot discarded and cleaned`,
320
- });
321
- if (isJournalKey(key, deps.profileKey)) {
322
- try {
323
- await deps.journalStore.delete(key);
324
- }
325
- catch { /* best effort */ }
326
- }
327
- }
328
- else {
329
- notice({ code: 'journal-unparseable', level: 'warn', key, message: `${read.parseError}; journal discarded (treated as no journal)` });
330
- try {
331
- await deps.journalStore.delete(key);
332
- }
333
- catch { /* best effort */ }
334
- }
335
- result.discarded.push(key);
336
- continue;
337
- }
338
- const journal = read.journal;
339
- if (journal === undefined)
340
- continue;
341
- const expectedKey = goJournalKey(deps.profileKey, journal.route, journal.keyFingerprint);
342
- if (journal.profileKey !== deps.profileKey || journal.keyFingerprint !== deps.keyFingerprint
343
- || key !== expectedKey) {
344
- deps.logger.warn('orphan journal %s (profile=%s key=%s)', key, journal.profileKey, journal.keyFingerprint);
345
- notice({
346
- code: 'journal-orphan', level: 'warn', key,
347
- message: `profile/key fingerprint mismatch (profile=${journal.profileKey}, key=${journal.keyFingerprint}); discarded, never replayed`,
348
- });
349
- try {
350
- await deps.journalStore.delete(key);
351
- }
352
- catch { /* best effort */ }
353
- result.discarded.push(key);
354
- continue;
355
- }
356
- const currentHash = journalContentHash(rawModels(desc, journal.route));
357
- if (currentHash !== journal.contentHash) {
358
- deps.logger.warn('stale journal %s: current settings hash differs', key);
359
- notice({
360
- code: 'journal-stale', level: 'warn', key,
361
- message: `current settings differ from the recorded write hash; journal discarded and the user's value kept`,
362
- });
363
- try {
364
- await deps.journalStore.delete(key);
365
- }
366
- catch { /* best effort */ }
367
- result.discarded.push(key);
368
- continue;
369
- }
370
- try {
371
- const ledgerKey = goOwnershipKey(journal.route, deps.keyFingerprint);
372
- if (journal.unset || journal.entry === undefined) {
373
- await deps.ownershipStore.delete(ledgerKey);
374
- }
375
- else {
376
- await deps.ownershipStore.write(ledgerKey, journal.entry);
377
- }
378
- if (deps.onRecord !== undefined) {
379
- await deps.onRecord(journal.route, [...journal.modelIds].sort(), { unset: journal.unset === true });
380
- }
381
- await deps.journalStore.delete(key);
382
- result.reconciled.push(journal.route);
383
- notice({
384
- code: 'journal-reconciled', level: 'info', key,
385
- message: `present value matches the recorded write; ownership ledger + migration record re-committed`,
386
- });
387
- }
388
- catch (err) {
389
- // Keep the journal so a later round retries. Never block the round: the
390
- // user's settings are untouched by reconciliation by construction.
391
- deps.logger.warn('journal reconciliation failed for %s: %s', key, errorText(err));
392
- notice({
393
- code: 'journal-reconcile-failed', level: 'warn', key,
394
- message: `ledger/record re-commit failed (${errorText(err)}); journal kept for the next round`,
395
- });
396
- }
397
- }
398
- return result;
399
- }
400
- /** One-line summary prepended to the round report when anything reconciled. */
401
- export function formatReconcileSummary(result) {
402
- if (result.reconciled.length === 0 && result.discarded.length === 0 && result.notices.length === 0)
403
- return '';
404
- return `opencode-go: journal reconciliation: ${result.reconciled.length} re-committed, ${result.discarded.length} discarded`;
405
- }
406
- //# sourceMappingURL=opencode-go-journal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"opencode-go-journal.js","sourceRoot":"","sources":["../src/opencode-go-journal.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,6EAA6E;AAC7E,+EAA+E;AAC/E,0EAA0E;AAC1E,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,EAAE;AACF,8EAA8E;AAC9E,wEAAwE;AACxE,uEAAuE;AACvE,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,6EAA6E;AAC7E,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAE3E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,cAAc,EAAyB,MAAM,0BAA0B,CAAA;AAEhF,OAAO,EAAE,eAAe,EAA4B,MAAM,qBAAqB,CAAA;AAI/E,MAAM,YAAY,GAAG,SAAS,CAAA;AAC9B,MAAM,eAAe,GAAG,CAAC,CAAA;AA6CzB,4EAA4E;AAC5E,MAAM,UAAU,YAAY,CAAC,UAAkB,EAAE,KAAa,EAAE,cAAsB;IACpF,OAAO,GAAG,UAAU,IAAI,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC,IAAI,YAAY,EAAE,CAAA;AACjF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,UAAkB;IAC1D,MAAM,MAAM,GAAG,GAAG,UAAU,GAAG,CAAA;IAC/B,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAA;IAC/B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAA;IAChE,MA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