@aiwayds/dsh-model-sync 0.9.0 → 0.11.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.
Files changed (74) hide show
  1. package/README.md +20 -3
  2. package/README.zh-CN.md +20 -3
  3. package/lib/builtin-catalog-snapshot.js +6 -3
  4. package/lib/builtin-catalog-snapshot.js.map +1 -1
  5. package/lib/index.d.ts +379 -0
  6. package/lib/index.js +897 -13
  7. package/lib/index.js.map +1 -1
  8. package/lib/opencode-go-diagnose.d.ts +74 -0
  9. package/lib/opencode-go-diagnose.js +146 -0
  10. package/lib/opencode-go-diagnose.js.map +1 -0
  11. package/lib/opencode-go-grouping.d.ts +29 -0
  12. package/lib/opencode-go-grouping.js +77 -0
  13. package/lib/opencode-go-grouping.js.map +1 -0
  14. package/lib/opencode-go-journal.d.ts +110 -0
  15. package/lib/opencode-go-journal.js +406 -0
  16. package/lib/opencode-go-journal.js.map +1 -0
  17. package/lib/opencode-go-migrate.d.ts +343 -0
  18. package/lib/opencode-go-migrate.js +1300 -0
  19. package/lib/opencode-go-migrate.js.map +1 -0
  20. package/lib/opencode-go-migration.d.ts +227 -0
  21. package/lib/opencode-go-migration.js +384 -0
  22. package/lib/opencode-go-migration.js.map +1 -0
  23. package/lib/opencode-go-one-shot.d.ts +276 -0
  24. package/lib/opencode-go-one-shot.js +1094 -0
  25. package/lib/opencode-go-one-shot.js.map +1 -0
  26. package/lib/opencode-go-patch-file.d.ts +123 -0
  27. package/lib/opencode-go-patch-file.js +1185 -0
  28. package/lib/opencode-go-patch-file.js.map +1 -0
  29. package/lib/opencode-go-planner.d.ts +153 -0
  30. package/lib/opencode-go-planner.js +339 -0
  31. package/lib/opencode-go-planner.js.map +1 -0
  32. package/lib/opencode-go-profile.d.ts +57 -0
  33. package/lib/opencode-go-profile.js +103 -0
  34. package/lib/opencode-go-profile.js.map +1 -0
  35. package/lib/opencode-go-scheduler.d.ts +128 -0
  36. package/lib/opencode-go-scheduler.js +241 -0
  37. package/lib/opencode-go-scheduler.js.map +1 -0
  38. package/lib/opencode-go-source.d.ts +117 -0
  39. package/lib/opencode-go-source.js +331 -0
  40. package/lib/opencode-go-source.js.map +1 -0
  41. package/lib/opencode-go-store.d.ts +18 -0
  42. package/lib/opencode-go-store.js +68 -0
  43. package/lib/opencode-go-store.js.map +1 -0
  44. package/lib/opencode-go-sync.d.ts +94 -0
  45. package/lib/opencode-go-sync.js +364 -0
  46. package/lib/opencode-go-sync.js.map +1 -0
  47. package/lib/opencode-go-writer.d.ts +132 -0
  48. package/lib/opencode-go-writer.js +966 -0
  49. package/lib/opencode-go-writer.js.map +1 -0
  50. package/lib/provider-native.d.ts +3 -1
  51. package/lib/provider-native.js +4 -2
  52. package/lib/provider-native.js.map +1 -1
  53. package/lib/remote-catalog.d.ts +61 -0
  54. package/lib/remote-catalog.js +307 -3
  55. package/lib/remote-catalog.js.map +1 -1
  56. package/package.json +15 -15
  57. package/src/builtin-catalog-snapshot.ts +6 -3
  58. package/src/index.ts +1060 -12
  59. package/src/opencode-go-diagnose.ts +222 -0
  60. package/src/opencode-go-grouping.ts +97 -0
  61. package/src/opencode-go-journal.ts +458 -0
  62. package/src/opencode-go-migrate.ts +1694 -0
  63. package/src/opencode-go-migration.ts +552 -0
  64. package/src/opencode-go-one-shot.ts +1354 -0
  65. package/src/opencode-go-patch-file.ts +1168 -0
  66. package/src/opencode-go-planner.ts +505 -0
  67. package/src/opencode-go-profile.ts +114 -0
  68. package/src/opencode-go-scheduler.ts +315 -0
  69. package/src/opencode-go-source.ts +424 -0
  70. package/src/opencode-go-store.ts +73 -0
  71. package/src/opencode-go-sync.ts +503 -0
  72. package/src/opencode-go-writer.ts +1189 -0
  73. package/src/provider-native.ts +3 -1
  74. package/src/remote-catalog.ts +359 -3
@@ -0,0 +1,364 @@
1
+ // P1c orchestration: one opencode-go sync round = source → planner → writer.
2
+ //
3
+ // The three layers stay separate (design §6.2.1): the source owns the network
4
+ // read, the planner is pure, the writer owns the only settings write path.
5
+ // This module adds only glue + report formatting. Every I/O dependency
6
+ // (settings, ledger store, override store, fetch, logger) is injected, so the
7
+ // whole round can be exercised offline with mocks and a temp-dir store.
8
+ //
9
+ // No timer lives here (P1c-2 owns scheduling). No command registration lives
10
+ // here either (index.ts owns the cordis/command surface). No credentials are
11
+ // read here — the caller resolves the key value through the existing cordis
12
+ // credential seam and passes it in.
13
+ import { GO_SLOT_ROUTES } from "./opencode-go-grouping.js";
14
+ import { goOwnershipKey, planGoRoutes } from "./opencode-go-planner.js";
15
+ import { fetchGoOfficialModels } from "./opencode-go-source.js";
16
+ import { writeGoPlan, } from "./opencode-go-writer.js";
17
+ import { routeWriter } from "./opencode-go-migration.js";
18
+ import { formatReconcileSummary, reconcileJournals, } from "./opencode-go-journal.js";
19
+ /**
20
+ * Cordis service names used only as injection seams. Both are optional:
21
+ * production falls back to the real file store and the global fetch; tests
22
+ * register a temp-dir store / stub fetch under these names to run a full round
23
+ * with zero filesystem writes outside a temp dir and zero network.
24
+ */
25
+ export const GO_OWNERSHIP_STORE_SERVICE = 'goOwnershipStore';
26
+ export const GO_OVERRIDE_STORER_SERVICE = 'goOverrideStorer';
27
+ export const GO_FETCH_SERVICE = 'goFetchImpl';
28
+ function llmDescriptor(settings) {
29
+ return settings?.describe().find((desc) => desc.ns === 'llm-pi-ai');
30
+ }
31
+ function isRecord(value) {
32
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
33
+ }
34
+ /** Raw current state of one route (no schema defaults — hashes must match the writer's). */
35
+ function readRouteState(desc, route) {
36
+ const providers = desc?.user?.providers;
37
+ const data = isRecord(providers) ? providers[route] : undefined;
38
+ if (!isRecord(data))
39
+ return { exists: false, models: [] };
40
+ const models = Array.isArray(data.models) ? data.models : [];
41
+ const overrideIds = isRecord(data.modelOverrides) ? Object.keys(data.modelOverrides) : [];
42
+ const state = { exists: true, models, overrideIds };
43
+ for (const field of ['api', 'baseURL', 'displayName', 'apiKeyEnv']) {
44
+ const value = data[field];
45
+ if (typeof value === 'string')
46
+ state[field] = value;
47
+ }
48
+ return state;
49
+ }
50
+ /** Round stopped by a plugin-unload abort: last-good settings are untouched. */
51
+ function abortedResult(source) {
52
+ return {
53
+ ok: false,
54
+ reason: 'aborted',
55
+ source,
56
+ text: 'opencode-go: round aborted (plugin unload); kept last-good, no settings write',
57
+ };
58
+ }
59
+ /**
60
+ * B4: the user edited settings while the /v1/models request was in flight.
61
+ * The pre-fetch descriptor is stale, so the round is discarded in full — no
62
+ * settings mutate, no ledger commit, no fingerprint update — and a later round
63
+ * re-reads current settings and retries. Never reuse the stale plan here.
64
+ */
65
+ function settingsChangedResult(source, beforeRevision, afterRevision) {
66
+ return {
67
+ ok: false,
68
+ reason: 'settings-changed-during-sync',
69
+ source,
70
+ settingsChanged: { beforeRevision, afterRevision },
71
+ text: [
72
+ `opencode-go: settings changed during the /v1/models fetch (llm-pi-ai revision ${beforeRevision} -> ${afterRevision}); discarding this round`,
73
+ ' user edits were kept as-is: no settings write, no ownership ledger change, no fingerprint update',
74
+ ' the next round re-reads the current settings and retries normally',
75
+ ].join('\n'),
76
+ };
77
+ }
78
+ /**
79
+ * B4/N1: the writer detected a settings revision change after the round was
80
+ * validated — the plan went stale. Usually no mutate landed, but a mid-loop
81
+ * race can leave earlier routes already written (S7); in that case report the
82
+ * written and discarded routes explicitly instead of claiming "no settings
83
+ * write". The zero-write wording is kept byte-identical when nothing landed.
84
+ */
85
+ function writerSettingsChangedResult(source, beforeRevision, afterRevision, write) {
86
+ const landed = write.settingsLandedRoutes;
87
+ const discarded = write.routes
88
+ .filter((r) => r.status === 'skipped' && r.reason === 'settings-changed-during-sync')
89
+ .map((r) => r.route);
90
+ const honesty = landed.length === 0
91
+ ? ' user edits were kept as-is: no settings write, no ownership ledger change, no fingerprint update'
92
+ : ` already written this round: [${landed.join(', ')}]; discarded with no settings write: [${discarded.length === 0 ? 'none' : discarded.join(', ')}]; no ownership ledger/fingerprint update for the discarded routes`;
93
+ return {
94
+ ok: false,
95
+ reason: 'settings-changed-during-sync',
96
+ source,
97
+ settingsChanged: { beforeRevision: beforeRevision ?? -1, afterRevision },
98
+ text: [
99
+ `opencode-go: settings changed during this sync round (llm-pi-ai revision ${String(beforeRevision)} -> ${afterRevision}); discarding the stale plan`,
100
+ honesty,
101
+ ' the next round re-reads the current settings and retries normally',
102
+ ].join('\n'),
103
+ };
104
+ }
105
+ /**
106
+ * Read only this key's ledger slots. A slot that cannot be read is treated as
107
+ * absent — the writer then refuses to delete (no hash), the safe direction.
108
+ */
109
+ async function readOwnership(store, fingerprint, routes) {
110
+ const ledger = {};
111
+ for (const route of new Set(routes)) {
112
+ const key = goOwnershipKey(route, fingerprint);
113
+ try {
114
+ const entry = await store.read(key);
115
+ if (entry !== undefined)
116
+ ledger[key] = entry;
117
+ }
118
+ catch {
119
+ // No ledger for this route this round → never delete.
120
+ }
121
+ }
122
+ return ledger;
123
+ }
124
+ /** One complete go round. Never throws for expected source/store failures. */
125
+ export async function runGoSyncRound(deps) {
126
+ const { settings, ownershipStore, logger, config } = deps;
127
+ const routes = { ...GO_SLOT_ROUTES, ...(config.routes ?? {}) };
128
+ const desc = llmDescriptor(settings);
129
+ if (!config.enabled) {
130
+ return {
131
+ ok: false,
132
+ reason: 'disabled',
133
+ text: 'opencode-go sync is disabled — set opencode.go.enabled=true to write its routes (design §6.2.6: zero behavior change by default)',
134
+ };
135
+ }
136
+ if (settings === undefined || desc === undefined) {
137
+ return {
138
+ ok: false,
139
+ reason: 'settings-unavailable',
140
+ text: 'opencode-go: skipped — settings service / llm-pi-ai namespace unavailable; no request, no write',
141
+ };
142
+ }
143
+ const apiKey = typeof deps.apiKey === 'string' ? deps.apiKey.trim() : '';
144
+ if (apiKey === '') {
145
+ return {
146
+ ok: false,
147
+ reason: 'no-key',
148
+ text: `opencode-go: skipped — no credential value for ${config.ref}; no /v1/models request sent, no settings write (design V4)`,
149
+ };
150
+ }
151
+ // O1/C2: reconcile BEFORE the migration gate. A crashed first write leaves
152
+ // sections present but no migration record → `legacy-inline` closes the gate
153
+ // forever; reconciliation runs even on that closed-gate round so the record
154
+ // can be re-committed and the gate reopened. It writes only the store/record
155
+ // (never settings) and validates profile scope + key fingerprint per slot.
156
+ let journalResult;
157
+ let journalPrefix = '';
158
+ if (deps.journalStore !== undefined && deps.profileKey !== undefined && deps.keyFingerprint !== undefined) {
159
+ journalResult = await reconcileJournals({
160
+ journalStore: deps.journalStore,
161
+ ownershipStore,
162
+ settings,
163
+ profileKey: deps.profileKey,
164
+ keyFingerprint: deps.keyFingerprint,
165
+ logger,
166
+ onRecord: deps.onOwnWrite,
167
+ });
168
+ const summary = formatReconcileSummary(journalResult);
169
+ journalPrefix = [summary, ...journalResult.lines].filter((line) => line.length > 0).join('\n') + '\n';
170
+ }
171
+ const withJournal = (round) => journalPrefix === '' ? round : { ...round, journal: journalResult, text: journalPrefix + round.text };
172
+ // M-4 migration gate + single writer (§14.6 / §14.7, ADR-008). All go routes
173
+ // share one authority decision; when none of them may be written the round
174
+ // short-circuits BEFORE the source fetch (zero side effects, explicit report).
175
+ let migration = deps.migration ?? {
176
+ state: 'absent', fingerprint: '', identity: '', applying: false,
177
+ fingerprintHealed: false, expectedFingerprint: '',
178
+ };
179
+ // Reconciliation may have just re-persisted the migration record that was
180
+ // missing when this round's snapshot was taken. Re-read it so a reconciled
181
+ // S1 can reopen the gate in THIS round instead of waiting for another one.
182
+ if ((journalResult?.reconciled.length ?? 0) > 0 && deps.reloadMigration !== undefined) {
183
+ try {
184
+ migration = await deps.reloadMigration();
185
+ }
186
+ catch {
187
+ // Keep the original snapshot; the next round re-reads it anyway.
188
+ }
189
+ }
190
+ const authority = { caller: 'go', goEnabled: config.enabled, goRoutes: Object.values(routes) };
191
+ const decisions = Object.values(routes).map((route) => ({ route, decision: routeWriter(route, authority, migration) }));
192
+ const blocked = decisions.filter((entry) => entry.decision.decision === 'skip');
193
+ if (blocked.length === decisions.length) {
194
+ return withJournal({
195
+ ok: false,
196
+ reason: 'migration-gate',
197
+ text: [
198
+ 'opencode-go: migration gate — zero settings writes, no /v1/models request',
199
+ ...blocked.map(({ route, decision }) => ` [info] ${decision.reason}; route=${route}`),
200
+ ].join('\n'),
201
+ });
202
+ }
203
+ // B4 (31, design §14.7.5): snapshot the host settings document revision
204
+ // BEFORE the network wait. This is only a baseline for the post-fetch
205
+ // freshness check below — never a source for the write plan itself.
206
+ const preFetchRevision = desc.revision;
207
+ let source;
208
+ try {
209
+ source = await fetchGoOfficialModels({
210
+ url: config.modelsUrl,
211
+ apiKey,
212
+ fetchImpl: deps.fetchImpl,
213
+ observedAt: deps.observedAt,
214
+ signal: deps.signal,
215
+ });
216
+ }
217
+ catch (err) {
218
+ const message = err instanceof Error ? err.message : String(err);
219
+ return withJournal({ ok: false, reason: 'source-failed', text: `opencode-go: source error — ${message}; no settings write` });
220
+ }
221
+ if (!source.ok) {
222
+ const error = source.error;
223
+ return withJournal({
224
+ ok: false,
225
+ reason: 'source-failed',
226
+ source,
227
+ text: `opencode-go: source failed (${error?.kind ?? 'unknown'}${error?.status !== undefined ? ` HTTP ${error.status}` : ''}) — ${error?.message ?? 'unknown error'}; kept last-good, no settings write`,
228
+ });
229
+ }
230
+ // The plugin may be disposed while the source request (or the ownership
231
+ // reads below) is in flight. Never reach the writer after unload (§6.3 卸载).
232
+ if (deps.signal?.aborted)
233
+ return withJournal(abortedResult(source));
234
+ // B4: re-read the descriptor AFTER the fetch. The plan must describe the
235
+ // settings we are about to write, not the snapshot used to build the
236
+ // request. If the host revision moved during the request window a user edit
237
+ // landed here; writing the pre-fetch plan would silently drop it (no even
238
+ // SETTINGS_CONFLICT, because the writer's own re-read only sees the new
239
+ // revision, not the stale merged models). Discard the whole round instead.
240
+ const freshDesc = llmDescriptor(settings);
241
+ if (freshDesc === undefined) {
242
+ return withJournal({
243
+ ok: false,
244
+ reason: 'settings-unavailable',
245
+ source,
246
+ text: 'opencode-go: llm-pi-ai descriptor disappeared during the fetch; no settings write',
247
+ });
248
+ }
249
+ if (freshDesc.revision !== preFetchRevision) {
250
+ return withJournal(settingsChangedResult(source, preFetchRevision, freshDesc.revision));
251
+ }
252
+ // Plan from the post-fetch descriptor so the write target and the plan are
253
+ // the same object (design §14.7.5). No revision bump → no user edit in the
254
+ // window → the freshly read state is the correct planning input.
255
+ const currentRoutes = Object.fromEntries(Object.values(routes).map((route) => [route, readRouteState(freshDesc, route)]));
256
+ const ownership = await readOwnership(ownershipStore, source.keyFingerprint, Object.values(routes));
257
+ const plan = planGoRoutes({
258
+ keyFingerprint: source.keyFingerprint,
259
+ entries: source.entries,
260
+ currentRoutes,
261
+ ownership,
262
+ ref: config.ref,
263
+ routes: config.routes,
264
+ pinnedModels: config.pinnedModels,
265
+ });
266
+ // Re-check immediately before the only settings mutation: a dispose that
267
+ // lands during readOwnership/planning must still produce a zero-write round.
268
+ if (deps.signal?.aborted)
269
+ return withJournal(abortedResult(source));
270
+ // §14.7.5: the second gate ALWAYS re-reads the persisted status on every
271
+ // call — the round-level `migration` snapshot is never reused here. Without
272
+ // a live reader there is no second gate (pure writer-mechanics callers); a
273
+ // failed re-read is fail-closed with a `canWrite-unavailable` report line.
274
+ const reloadMigration = deps.reloadMigration;
275
+ const canWrite = reloadMigration === undefined
276
+ ? undefined
277
+ : async (route) => {
278
+ try {
279
+ const current = await reloadMigration();
280
+ const decision = routeWriter(route, authority, current);
281
+ // O1-minimal: pass the routeWriter reason through to the writer's skip
282
+ // record/report. Previously every skip collapsed to `route-authority`,
283
+ // hiding the real gate/applying/owner decision that revoked authority.
284
+ return {
285
+ allow: decision.decision === 'write',
286
+ reason: decision.decision === 'skip' ? decision.reason : undefined,
287
+ };
288
+ }
289
+ catch {
290
+ return { allow: false, reason: 'canWrite-unavailable' };
291
+ }
292
+ };
293
+ let write;
294
+ try {
295
+ write = await writeGoPlan(plan, {
296
+ settings,
297
+ ownershipStore,
298
+ overrideStorer: deps.overrideStorer,
299
+ logger,
300
+ keyFingerprint: source.keyFingerprint,
301
+ confirmRemovals: config.confirmRemovals,
302
+ adoptExisting: config.adoptExisting,
303
+ // B4/N1: the revision this round validated (post-fetch == pre-fetch).
304
+ // The writer re-checks it before every mutate and abandons the whole
305
+ // round if a user edit landed in the gap between here and the write.
306
+ expectedRevision: preFetchRevision,
307
+ canWrite,
308
+ onOwnWrite: deps.onOwnWrite,
309
+ // O1/C2: same journal store + profile scope used by the pre-gate
310
+ // reconciliation, so a surviving slot is written under the key the next
311
+ // round will look for.
312
+ journalStore: deps.journalStore,
313
+ profileKey: deps.profileKey,
314
+ });
315
+ }
316
+ catch (err) {
317
+ // The source already succeeded above; this is an unexpected writer throw.
318
+ // Keep the truthful text and give it a matching reason instead of lying
319
+ // with `source-failed` (oldfox #3). No failureKind is attached by the
320
+ // scheduler adapter (it is source-only), so no transport/auth backoff is
321
+ // scheduled for a writer exception — the normal interval still retries.
322
+ const message = err instanceof Error ? err.message : String(err);
323
+ return withJournal({
324
+ ok: false,
325
+ reason: 'writer-error',
326
+ source,
327
+ text: `opencode-go: writer error — ${message}; settings state is whatever landed before the error`,
328
+ });
329
+ }
330
+ // B4/N1: the writer abandoned the round because settings changed after
331
+ // validation. Do NOT expose a `completed` write or a half-plan here — report
332
+ // the same zero-write reason as the fetch-window guard.
333
+ if (write.settingsChanged !== undefined) {
334
+ return withJournal(writerSettingsChangedResult(source, write.settingsChanged.expectedRevision, write.settingsChanged.actualRevision, write));
335
+ }
336
+ // O1-minimal: a round with failedRoutes is never a clean `completed` success,
337
+ // even though some routes may have written settings. The command surface maps
338
+ // this reason to kind:'error'. (Only source failures back off — see scheduler.)
339
+ const hasFailedRoutes = write.failedRoutes.length > 0;
340
+ return withJournal({
341
+ ok: !hasFailedRoutes,
342
+ reason: hasFailedRoutes ? 'write-failed' : 'completed',
343
+ source,
344
+ write,
345
+ text: formatGoRoundReport(source, write),
346
+ });
347
+ }
348
+ /** Stable, testable report text: source summary, per-route outcome, plan notes. */
349
+ export function formatGoRoundReport(source, write) {
350
+ const lines = [
351
+ `opencode-go: source ok (${source.entries.length} models, key=${source.keyFingerprint}, hash=${(source.payloadHash ?? '').slice(0, 12)})`,
352
+ ];
353
+ for (const status of write.routes) {
354
+ lines.push(` ${status.route}: ${status.status}${status.reason !== undefined ? ` (${status.reason})` : ''}`);
355
+ }
356
+ for (const entry of write.report) {
357
+ lines.push(` [${entry.level}] ${entry.code}${entry.route !== undefined ? ` ${entry.route}` : ''}${entry.id !== undefined ? `/${entry.id}` : ''}: ${entry.message}`);
358
+ }
359
+ if (write.writtenRoutes.length === 0 && write.failedRoutes.length === 0) {
360
+ lines.push(' no settings changes');
361
+ }
362
+ return lines.join('\n');
363
+ }
364
+ //# sourceMappingURL=opencode-go-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-go-sync.js","sourceRoot":"","sources":["../src/opencode-go-sync.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,uEAAuE;AACvE,8EAA8E;AAC9E,wEAAwE;AACxE,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,4EAA4E;AAC5E,oCAAoC;AAEpC,OAAO,EAAE,cAAc,EAAoB,MAAM,2BAA2B,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAoE,MAAM,0BAA0B,CAAA;AACzI,OAAO,EAAE,qBAAqB,EAAyC,MAAM,yBAAyB,CAAA;AACtG,OAAO,EACL,WAAW,GAKZ,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAAE,WAAW,EAAwB,MAAM,4BAA4B,CAAA;AAC9E,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAGlB,MAAM,0BAA0B,CAAA;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAA;AAC5D,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAA;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAA;AA+F7C,SAAS,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AK,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IACtK,CAAC;IACD,IAAI,KAAK,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxE,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
@@ -0,0 +1,132 @@
1
+ import type { GoRouteSlot } from './opencode-go-grouping.ts';
2
+ import { type GoOwnershipEntry, type GoPlanReportEntry, type GoPlanResult } from './opencode-go-planner.ts';
3
+ import { type Logger, type SettingsService } from './writer.ts';
4
+ import { type GoJournalStore } from './opencode-go-journal.ts';
5
+ /**
6
+ * Ownership ledger store (store v2 in design §6.1). Entries are keyed by
7
+ * `<route>#<keyFingerprint>`, so one route's ledger is invisible under a
8
+ * different key. All methods are async so a file-backed adapter can be used
9
+ * in production while tests stay in memory.
10
+ */
11
+ export interface GoOwnershipStore {
12
+ read(key: string): Promise<GoOwnershipEntry | undefined>;
13
+ write(key: string, entry: GoOwnershipEntry): Promise<void>;
14
+ delete(key: string): Promise<void>;
15
+ }
16
+ /** Minimal models-store seam for store-first `modelOverrides` staging (§6.2.4). */
17
+ export interface GoOverrideStorer {
18
+ read?(route: string): Promise<{
19
+ overrides?: Record<string, Record<string, unknown>>;
20
+ } | undefined>;
21
+ updateOverrides(route: string, overrides: Record<string, Record<string, unknown>>): Promise<void>;
22
+ }
23
+ export interface GoWriterDeps {
24
+ settings: SettingsService | undefined;
25
+ ownershipStore: GoOwnershipStore;
26
+ logger: Logger;
27
+ /** sha256(key) prefix from the source result; `-` when no key. */
28
+ keyFingerprint: string;
29
+ /** go.confirmRemovals; default 2 (schema min 2, design §6.2.6). */
30
+ confirmRemovals?: number;
31
+ /**
32
+ * go.adoptExisting / `/model-sync adopt go` (design §14.1). With no prior
33
+ * ledger the writer claims only desired∩current by default; adopt also
34
+ * claims the route's pre-existing models so they become deletion candidates
35
+ * on later rounds (still subject to the two-round confirmation + 3 gates).
36
+ */
37
+ adoptExisting?: boolean;
38
+ /** Optional models-store seam for override fold + unset (store-first). */
39
+ overrideStorer?: GoOverrideStorer;
40
+ /**
41
+ * B4/N1 fail-closed guard: the llm-pi-ai revision the plan was built against
42
+ * (the fetch-time / post-validation revision). The writer re-reads the
43
+ * descriptor before ANY settings mutate or ledger commit; if the revision
44
+ * moved since the round was validated, the plan is stale and the WHOLE round
45
+ * is abandoned (zero writes, no ledger/fingerprint). Omitted only by pure
46
+ * unit writers that do not have a round-level revision to validate.
47
+ */
48
+ expectedRevision?: number;
49
+ /**
50
+ * §14.7.5 second gate: called immediately before EACH mutate (and again on a
51
+ * SETTINGS_CONFLICT retry). Must re-read the persisted migration status —
52
+ * never reuse the round-level snapshot. A false result leaves the route
53
+ * untouched (including the ledger); `reason: 'canWrite-unavailable'` is
54
+ * reported when the status re-read itself failed (fail closed). Absent means
55
+ * no second gate (pure unit writers). A plain boolean is accepted for tests.
56
+ */
57
+ canWrite?: (route: string) => boolean | GoCanWriteDecision | Promise<boolean> | Promise<GoCanWriteDecision>;
58
+ /**
59
+ * §14.7.4: called ONLY after a route's settings.mutate AND its ledger commit
60
+ * both succeeded, with the ledger-managed ids just committed. The callback
61
+ * re-persists `appliedFingerprint` through the same store queue. Never called
62
+ * for a failed write, a no-change round, or another writer's no-op success.
63
+ */
64
+ onOwnWrite?: (route: string, managedIds: string[]) => Promise<void> | void;
65
+ /**
66
+ * O1/C2: write-ahead journal store. When present together with `profileKey`,
67
+ * each settings mutate is preceded by a journal slot recording the intended
68
+ * ledger entry + the post-write content hash; it is removed only after the
69
+ * ledger AND migration record both landed. The next round reconciles any
70
+ * surviving journal before the migration gate. Omitted by pure unit writers
71
+ * (no file-backed store) — those keep the pre-C2 behavior.
72
+ */
73
+ journalStore?: GoJournalStore;
74
+ /** O1/C2: stable profile key for the journal slot (must match reconciliation). */
75
+ profileKey?: string;
76
+ /** O1/C2: injectable clock for the journal timestamp; defaults to Date.now. */
77
+ now?: () => number;
78
+ }
79
+ export interface GoCanWriteDecision {
80
+ allow: boolean;
81
+ /** `canWrite-unavailable` when the live status re-read failed. */
82
+ reason?: string;
83
+ }
84
+ export type GoRouteStatus = 'wrote' | 'no-change' | 'unset' | 'skipped' | 'conflict' | 'failed';
85
+ export interface GoRouteWriteStatus {
86
+ route: string;
87
+ slot?: GoRouteSlot;
88
+ status: GoRouteStatus;
89
+ reason?: string;
90
+ }
91
+ export interface GoWriteResult {
92
+ /** One entry per planned route, plus one per conflicted route. */
93
+ routes: GoRouteWriteStatus[];
94
+ /** Routes whose settings.mutate resolved (wrote or unset). */
95
+ writtenRoutes: string[];
96
+ /** Routes whose mutate failed, with an honest reason. */
97
+ failedRoutes: {
98
+ route: string;
99
+ reason: string;
100
+ }[];
101
+ /**
102
+ * O1-minimal: routes whose settings.mutate landed this round, whether or not
103
+ * the ledger commit after it succeeded. Used for an honest N1-abandon report
104
+ * (a route may have been written before the round was abandoned).
105
+ */
106
+ settingsLandedRoutes: string[];
107
+ /**
108
+ * B4/N1: set when the round was abandoned because the host settings revision
109
+ * moved mid-round. The caller must report this as
110
+ * `settings-changed-during-sync` and treat the round as a zero-write no-op.
111
+ */
112
+ settingsChanged?: {
113
+ expectedRevision: number | undefined;
114
+ actualRevision: number;
115
+ };
116
+ /** Planner report adjusted by writer decisions + `moved` association. */
117
+ report: GoPlanReportEntry[];
118
+ }
119
+ /**
120
+ * Apply a planner result to the injected settings service and persist the
121
+ * updated ownership ledger. Multi-route writes are isolated per route: one
122
+ * route's failure never poisons the others, and the result names both the
123
+ * routes written and the routes failed (§19 single-point-failure guidance).
124
+ */
125
+ export declare function writeGoPlan(plan: GoPlanResult, deps: GoWriterDeps): Promise<GoWriteResult>;
126
+ /**
127
+ * Pair a removal on route A with an add of the same id on route B into one
128
+ * human-readable `moved` entry, so a consumer never reads a cross-slot move as
129
+ * an unrelated delete + add. A still-pending source removal is labelled as
130
+ * such (double confirmation), so the report stays honest.
131
+ */
132
+ export declare function associateGoMoves(report: readonly GoPlanReportEntry[]): GoPlanReportEntry[];