@aiwayds/dsh-model-sync 0.12.1 → 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 -384
- package/lib/index.js +306 -1107
- package/lib/index.js.map +1 -1
- package/lib/official-adapter.d.ts +80 -0
- package/lib/official-adapter.js +34 -0
- package/lib/official-adapter.js.map +1 -0
- package/lib/official-migrate.d.ts +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 +352 -1281
- 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 -96
- package/lib/opencode-go-diagnose.js +0 -177
- package/lib/opencode-go-diagnose.js.map +0 -1
- package/lib/opencode-go-grouping.d.ts +0 -7
- package/lib/opencode-go-grouping.js +0 -21
- package/lib/opencode-go-grouping.js.map +0 -1
- package/lib/opencode-go-host-catalog.d.ts +0 -42
- package/lib/opencode-go-host-catalog.js +0 -98
- package/lib/opencode-go-host-catalog.js.map +0 -1
- package/lib/opencode-go-journal.d.ts +0 -114
- package/lib/opencode-go-journal.js +0 -406
- package/lib/opencode-go-journal.js.map +0 -1
- package/lib/opencode-go-migrate.d.ts +0 -378
- package/lib/opencode-go-migrate.js +0 -1529
- package/lib/opencode-go-migrate.js.map +0 -1
- package/lib/opencode-go-migration.d.ts +0 -270
- package/lib/opencode-go-migration.js +0 -473
- package/lib/opencode-go-migration.js.map +0 -1
- package/lib/opencode-go-one-shot.d.ts +0 -282
- package/lib/opencode-go-one-shot.js +0 -1131
- package/lib/opencode-go-one-shot.js.map +0 -1
- package/lib/opencode-go-planner.d.ts +0 -168
- package/lib/opencode-go-planner.js +0 -407
- package/lib/opencode-go-planner.js.map +0 -1
- package/lib/opencode-go-scheduler.d.ts +0 -128
- package/lib/opencode-go-scheduler.js +0 -241
- package/lib/opencode-go-scheduler.js.map +0 -1
- package/lib/opencode-go-store.d.ts +0 -18
- package/lib/opencode-go-store.js +0 -68
- package/lib/opencode-go-store.js.map +0 -1
- package/lib/opencode-go-sync.d.ts +0 -107
- package/lib/opencode-go-sync.js +0 -388
- package/lib/opencode-go-sync.js.map +0 -1
- package/lib/opencode-go-writer.d.ts +0 -148
- package/lib/opencode-go-writer.js +0 -1061
- package/lib/opencode-go-writer.js.map +0 -1
- package/src/opencode-go-diagnose.ts +0 -276
- package/src/opencode-go-grouping.ts +0 -26
- package/src/opencode-go-host-catalog.ts +0 -125
- package/src/opencode-go-journal.ts +0 -460
- package/src/opencode-go-migrate.ts +0 -1951
- package/src/opencode-go-migration.ts +0 -666
- package/src/opencode-go-one-shot.ts +0 -1399
- package/src/opencode-go-planner.ts +0 -582
- package/src/opencode-go-scheduler.ts +0 -315
- package/src/opencode-go-store.ts +0 -73
- package/src/opencode-go-sync.ts +0 -541
- package/src/opencode-go-writer.ts +0 -1301
package/lib/opencode-go-sync.js
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
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
|
-
// M1: keys outside the plugin's known field set are user content (headers,
|
|
49
|
-
// custom config) — a whole-route unset would destroy them, so the planner's
|
|
50
|
-
// fully-managed verdict never fires while any exist.
|
|
51
|
-
const knownFields = new Set(['api', 'baseURL', 'displayName', 'apiKeyEnv', 'models', 'modelOverrides']);
|
|
52
|
-
const unknownKeys = Object.keys(data).filter((key) => !knownFields.has(key));
|
|
53
|
-
if (unknownKeys.length > 0)
|
|
54
|
-
state.unknownKeys = unknownKeys;
|
|
55
|
-
return state;
|
|
56
|
-
}
|
|
57
|
-
/** Round stopped by a plugin-unload abort: last-good settings are untouched. */
|
|
58
|
-
function abortedResult(source) {
|
|
59
|
-
return {
|
|
60
|
-
ok: false,
|
|
61
|
-
reason: 'aborted',
|
|
62
|
-
source,
|
|
63
|
-
text: 'opencode-go: round aborted (plugin unload); kept last-good, no settings write',
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* B4: the user edited settings while the /v1/models request was in flight.
|
|
68
|
-
* The pre-fetch descriptor is stale, so the round is discarded in full — no
|
|
69
|
-
* settings mutate, no ledger commit, no fingerprint update — and a later round
|
|
70
|
-
* re-reads current settings and retries. Never reuse the stale plan here.
|
|
71
|
-
*/
|
|
72
|
-
function settingsChangedResult(source, beforeRevision, afterRevision) {
|
|
73
|
-
return {
|
|
74
|
-
ok: false,
|
|
75
|
-
reason: 'settings-changed-during-sync',
|
|
76
|
-
source,
|
|
77
|
-
settingsChanged: { beforeRevision, afterRevision },
|
|
78
|
-
text: [
|
|
79
|
-
`opencode-go: settings changed during the /v1/models fetch (llm-pi-ai revision ${beforeRevision} -> ${afterRevision}); discarding this round`,
|
|
80
|
-
' user edits were kept as-is: no settings write, no ownership ledger change, no fingerprint update',
|
|
81
|
-
' the next round re-reads the current settings and retries normally',
|
|
82
|
-
].join('\n'),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* B4/N1: the writer detected a settings revision change after the round was
|
|
87
|
-
* validated — the plan went stale. Usually no mutate landed, but a mid-loop
|
|
88
|
-
* race can leave earlier routes already written (S7); in that case report the
|
|
89
|
-
* written and discarded routes explicitly instead of claiming "no settings
|
|
90
|
-
* write". The zero-write wording is kept byte-identical when nothing landed.
|
|
91
|
-
*/
|
|
92
|
-
function writerSettingsChangedResult(source, beforeRevision, afterRevision, write) {
|
|
93
|
-
const landed = write.settingsLandedRoutes;
|
|
94
|
-
const discarded = write.routes
|
|
95
|
-
.filter((r) => r.status === 'skipped' && r.reason === 'settings-changed-during-sync')
|
|
96
|
-
.map((r) => r.route);
|
|
97
|
-
const honesty = landed.length === 0
|
|
98
|
-
? ' user edits were kept as-is: no settings write, no ownership ledger change, no fingerprint update'
|
|
99
|
-
: ` 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`;
|
|
100
|
-
return {
|
|
101
|
-
ok: false,
|
|
102
|
-
reason: 'settings-changed-during-sync',
|
|
103
|
-
source,
|
|
104
|
-
settingsChanged: { beforeRevision: beforeRevision ?? -1, afterRevision },
|
|
105
|
-
text: [
|
|
106
|
-
`opencode-go: settings changed during this sync round (llm-pi-ai revision ${String(beforeRevision)} -> ${afterRevision}); discarding the stale plan`,
|
|
107
|
-
honesty,
|
|
108
|
-
' the next round re-reads the current settings and retries normally',
|
|
109
|
-
].join('\n'),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Read only this key's ledger slots. A slot that cannot be read is treated as
|
|
114
|
-
* absent — the writer then refuses to delete (no hash), the safe direction.
|
|
115
|
-
*/
|
|
116
|
-
async function readOwnership(store, fingerprint, routes) {
|
|
117
|
-
const ledger = {};
|
|
118
|
-
for (const route of new Set(routes)) {
|
|
119
|
-
const key = goOwnershipKey(route, fingerprint);
|
|
120
|
-
try {
|
|
121
|
-
const entry = await store.read(key);
|
|
122
|
-
if (entry !== undefined)
|
|
123
|
-
ledger[key] = entry;
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
// No ledger for this route this round → never delete.
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return ledger;
|
|
130
|
-
}
|
|
131
|
-
/** One complete go round. Never throws for expected source/store failures. */
|
|
132
|
-
export async function runGoSyncRound(deps) {
|
|
133
|
-
const { settings, ownershipStore, logger, config } = deps;
|
|
134
|
-
const routes = { ...GO_SLOT_ROUTES, ...(config.routes ?? {}) };
|
|
135
|
-
const desc = llmDescriptor(settings);
|
|
136
|
-
if (!config.enabled) {
|
|
137
|
-
return {
|
|
138
|
-
ok: false,
|
|
139
|
-
reason: 'disabled',
|
|
140
|
-
text: 'opencode-go sync is disabled — set opencode.go.enabled=true to write its routes (design §6.2.6: zero behavior change by default)',
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
if (settings === undefined || desc === undefined) {
|
|
144
|
-
return {
|
|
145
|
-
ok: false,
|
|
146
|
-
reason: 'settings-unavailable',
|
|
147
|
-
text: 'opencode-go: skipped — settings service / llm-pi-ai namespace unavailable; no request, no write',
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
const apiKey = typeof deps.apiKey === 'string' ? deps.apiKey.trim() : '';
|
|
151
|
-
if (apiKey === '') {
|
|
152
|
-
return {
|
|
153
|
-
ok: false,
|
|
154
|
-
reason: 'no-key',
|
|
155
|
-
text: `opencode-go: skipped — no credential value for ${config.ref}; no /v1/models request sent, no settings write (design V4)`,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
// O1/C2: reconcile BEFORE the migration gate. A crashed first write leaves
|
|
159
|
-
// sections present but no migration record → `legacy-inline` closes the gate
|
|
160
|
-
// forever; reconciliation runs even on that closed-gate round so the record
|
|
161
|
-
// can be re-committed and the gate reopened. It writes only the store/record
|
|
162
|
-
// (never settings) and validates profile scope + key fingerprint per slot.
|
|
163
|
-
let journalResult;
|
|
164
|
-
let journalPrefix = '';
|
|
165
|
-
if (deps.journalStore !== undefined && deps.profileKey !== undefined && deps.keyFingerprint !== undefined) {
|
|
166
|
-
journalResult = await reconcileJournals({
|
|
167
|
-
journalStore: deps.journalStore,
|
|
168
|
-
ownershipStore,
|
|
169
|
-
settings,
|
|
170
|
-
profileKey: deps.profileKey,
|
|
171
|
-
keyFingerprint: deps.keyFingerprint,
|
|
172
|
-
logger,
|
|
173
|
-
onRecord: deps.onOwnWrite,
|
|
174
|
-
});
|
|
175
|
-
const summary = formatReconcileSummary(journalResult);
|
|
176
|
-
journalPrefix = [summary, ...journalResult.lines].filter((line) => line.length > 0).join('\n') + '\n';
|
|
177
|
-
}
|
|
178
|
-
const withJournal = (round) => journalPrefix === '' ? round : { ...round, journal: journalResult, text: journalPrefix + round.text };
|
|
179
|
-
// M-4 migration gate + single writer (§14.6 / §14.7, ADR-008). All go routes
|
|
180
|
-
// share one authority decision; when none of them may be written the round
|
|
181
|
-
// short-circuits BEFORE the source fetch (zero side effects, explicit report).
|
|
182
|
-
let migration = deps.migration ?? {
|
|
183
|
-
state: 'absent', fingerprint: '', identity: '', applying: false,
|
|
184
|
-
fingerprintHealed: false, expectedFingerprint: '',
|
|
185
|
-
};
|
|
186
|
-
// Reconciliation may have just re-persisted the migration record that was
|
|
187
|
-
// missing when this round's snapshot was taken. Re-read it so a reconciled
|
|
188
|
-
// S1 can reopen the gate in THIS round instead of waiting for another one.
|
|
189
|
-
if ((journalResult?.reconciled.length ?? 0) > 0 && deps.reloadMigration !== undefined) {
|
|
190
|
-
try {
|
|
191
|
-
migration = await deps.reloadMigration();
|
|
192
|
-
}
|
|
193
|
-
catch {
|
|
194
|
-
// Keep the original snapshot; the next round re-reads it anyway.
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
const authority = { caller: 'go', goEnabled: config.enabled, goRoutes: Object.values(routes) };
|
|
198
|
-
const decisions = Object.values(routes).map((route) => ({ route, decision: routeWriter(route, authority, migration) }));
|
|
199
|
-
const blocked = decisions.filter((entry) => entry.decision.decision === 'skip');
|
|
200
|
-
if (blocked.length === decisions.length) {
|
|
201
|
-
return withJournal({
|
|
202
|
-
ok: false,
|
|
203
|
-
reason: 'migration-gate',
|
|
204
|
-
text: [
|
|
205
|
-
'opencode-go: migration gate — zero settings writes, no /v1/models request',
|
|
206
|
-
...blocked.map(({ route, decision }) => ` [info] ${decision.reason}; route=${route}`),
|
|
207
|
-
].join('\n'),
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
// 0.12.1: fail-closed BEFORE the source fetch (zero side effects, same spirit
|
|
211
|
-
// as the migration gate short-circuit above). Without the host runtime
|
|
212
|
-
// catalog there is no servable write: the 0.12.0 full-listing write is what
|
|
213
|
-
// got rejected by the host in the first place.
|
|
214
|
-
if (deps.hostCatalogIds === null) {
|
|
215
|
-
return withJournal({
|
|
216
|
-
ok: false,
|
|
217
|
-
reason: 'host-catalog-unavailable',
|
|
218
|
-
text: [
|
|
219
|
-
'opencode-go: host runtime catalog unavailable — 本轮 fail-closed 中止,零写入、零请求。',
|
|
220
|
-
' 宿主 llm 服务的 discoverModels 未返回目录(服务缺失/未注册/无 opencode-go catalog)。',
|
|
221
|
-
' 为避免再次写入宿主不认识的模型 id(宿主对整条 mutate fail-closed 拒绝),未做任何写入;目录可用后自动恢复。',
|
|
222
|
-
].join('\n'),
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
// B4 (31, design §14.7.5): snapshot the host settings document revision
|
|
226
|
-
// BEFORE the network wait. This is only a baseline for the post-fetch
|
|
227
|
-
// freshness check below — never a source for the write plan itself.
|
|
228
|
-
const preFetchRevision = desc.revision;
|
|
229
|
-
let source;
|
|
230
|
-
try {
|
|
231
|
-
source = await fetchGoOfficialModels({
|
|
232
|
-
url: config.modelsUrl,
|
|
233
|
-
apiKey,
|
|
234
|
-
fetchImpl: deps.fetchImpl,
|
|
235
|
-
observedAt: deps.observedAt,
|
|
236
|
-
signal: deps.signal,
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
catch (err) {
|
|
240
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
241
|
-
return withJournal({ ok: false, reason: 'source-failed', text: `opencode-go: source error — ${message}; no settings write` });
|
|
242
|
-
}
|
|
243
|
-
if (!source.ok) {
|
|
244
|
-
const error = source.error;
|
|
245
|
-
return withJournal({
|
|
246
|
-
ok: false,
|
|
247
|
-
reason: 'source-failed',
|
|
248
|
-
source,
|
|
249
|
-
text: `opencode-go: source failed (${error?.kind ?? 'unknown'}${error?.status !== undefined ? ` HTTP ${error.status}` : ''}) — ${error?.message ?? 'unknown error'}; kept last-good, no settings write`,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
// The plugin may be disposed while the source request (or the ownership
|
|
253
|
-
// reads below) is in flight. Never reach the writer after unload (§6.3 卸载).
|
|
254
|
-
if (deps.signal?.aborted)
|
|
255
|
-
return withJournal(abortedResult(source));
|
|
256
|
-
// B4: re-read the descriptor AFTER the fetch. The plan must describe the
|
|
257
|
-
// settings we are about to write, not the snapshot used to build the
|
|
258
|
-
// request. If the host revision moved during the request window a user edit
|
|
259
|
-
// landed here; writing the pre-fetch plan would silently drop it (no even
|
|
260
|
-
// SETTINGS_CONFLICT, because the writer's own re-read only sees the new
|
|
261
|
-
// revision, not the stale merged models). Discard the whole round instead.
|
|
262
|
-
const freshDesc = llmDescriptor(settings);
|
|
263
|
-
if (freshDesc === undefined) {
|
|
264
|
-
return withJournal({
|
|
265
|
-
ok: false,
|
|
266
|
-
reason: 'settings-unavailable',
|
|
267
|
-
source,
|
|
268
|
-
text: 'opencode-go: llm-pi-ai descriptor disappeared during the fetch; no settings write',
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
if (freshDesc.revision !== preFetchRevision) {
|
|
272
|
-
return withJournal(settingsChangedResult(source, preFetchRevision, freshDesc.revision));
|
|
273
|
-
}
|
|
274
|
-
// Plan from the post-fetch descriptor so the write target and the plan are
|
|
275
|
-
// the same object (design §14.7.5). No revision bump → no user edit in the
|
|
276
|
-
// window → the freshly read state is the correct planning input.
|
|
277
|
-
const currentRoutes = Object.fromEntries(Object.values(routes).map((route) => [route, readRouteState(freshDesc, route)]));
|
|
278
|
-
const ownership = await readOwnership(ownershipStore, source.keyFingerprint, Object.values(routes));
|
|
279
|
-
const plan = planGoRoutes({
|
|
280
|
-
keyFingerprint: source.keyFingerprint,
|
|
281
|
-
entries: source.entries,
|
|
282
|
-
hostCatalogIds: deps.hostCatalogIds,
|
|
283
|
-
currentRoutes,
|
|
284
|
-
ownership,
|
|
285
|
-
ref: config.ref,
|
|
286
|
-
routes: config.routes,
|
|
287
|
-
pinnedModels: config.pinnedModels,
|
|
288
|
-
});
|
|
289
|
-
// Re-check immediately before the only settings mutation: a dispose that
|
|
290
|
-
// lands during readOwnership/planning must still produce a zero-write round.
|
|
291
|
-
if (deps.signal?.aborted)
|
|
292
|
-
return withJournal(abortedResult(source));
|
|
293
|
-
// §14.7.5: the second gate ALWAYS re-reads the persisted status on every
|
|
294
|
-
// call — the round-level `migration` snapshot is never reused here. Without
|
|
295
|
-
// a live reader there is no second gate (pure writer-mechanics callers); a
|
|
296
|
-
// failed re-read is fail-closed with a `canWrite-unavailable` report line.
|
|
297
|
-
const reloadMigration = deps.reloadMigration;
|
|
298
|
-
const canWrite = reloadMigration === undefined
|
|
299
|
-
? undefined
|
|
300
|
-
: async (route) => {
|
|
301
|
-
try {
|
|
302
|
-
const current = await reloadMigration();
|
|
303
|
-
const decision = routeWriter(route, authority, current);
|
|
304
|
-
// O1-minimal: pass the routeWriter reason through to the writer's skip
|
|
305
|
-
// record/report. Previously every skip collapsed to `route-authority`,
|
|
306
|
-
// hiding the real gate/applying/owner decision that revoked authority.
|
|
307
|
-
return {
|
|
308
|
-
allow: decision.decision === 'write',
|
|
309
|
-
reason: decision.decision === 'skip' ? decision.reason : undefined,
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
return { allow: false, reason: 'canWrite-unavailable' };
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
let write;
|
|
317
|
-
try {
|
|
318
|
-
write = await writeGoPlan(plan, {
|
|
319
|
-
settings,
|
|
320
|
-
ownershipStore,
|
|
321
|
-
overrideStorer: deps.overrideStorer,
|
|
322
|
-
logger,
|
|
323
|
-
keyFingerprint: source.keyFingerprint,
|
|
324
|
-
hostCatalogIds: deps.hostCatalogIds,
|
|
325
|
-
confirmRemovals: config.confirmRemovals,
|
|
326
|
-
adoptExisting: config.adoptExisting,
|
|
327
|
-
// B4/N1: the revision this round validated (post-fetch == pre-fetch).
|
|
328
|
-
// The writer re-checks it before every mutate and abandons the whole
|
|
329
|
-
// round if a user edit landed in the gap between here and the write.
|
|
330
|
-
expectedRevision: preFetchRevision,
|
|
331
|
-
canWrite,
|
|
332
|
-
onOwnWrite: deps.onOwnWrite,
|
|
333
|
-
// O1/C2: same journal store + profile scope used by the pre-gate
|
|
334
|
-
// reconciliation, so a surviving slot is written under the key the next
|
|
335
|
-
// round will look for.
|
|
336
|
-
journalStore: deps.journalStore,
|
|
337
|
-
profileKey: deps.profileKey,
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
catch (err) {
|
|
341
|
-
// The source already succeeded above; this is an unexpected writer throw.
|
|
342
|
-
// Keep the truthful text and give it a matching reason instead of lying
|
|
343
|
-
// with `source-failed` (oldfox #3). No failureKind is attached by the
|
|
344
|
-
// scheduler adapter (it is source-only), so no transport/auth backoff is
|
|
345
|
-
// scheduled for a writer exception — the normal interval still retries.
|
|
346
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
347
|
-
return withJournal({
|
|
348
|
-
ok: false,
|
|
349
|
-
reason: 'writer-error',
|
|
350
|
-
source,
|
|
351
|
-
text: `opencode-go: writer error — ${message}; settings state is whatever landed before the error`,
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
// B4/N1: the writer abandoned the round because settings changed after
|
|
355
|
-
// validation. Do NOT expose a `completed` write or a half-plan here — report
|
|
356
|
-
// the same zero-write reason as the fetch-window guard.
|
|
357
|
-
if (write.settingsChanged !== undefined) {
|
|
358
|
-
return withJournal(writerSettingsChangedResult(source, write.settingsChanged.expectedRevision, write.settingsChanged.actualRevision, write));
|
|
359
|
-
}
|
|
360
|
-
// O1-minimal: a round with failedRoutes is never a clean `completed` success,
|
|
361
|
-
// even though some routes may have written settings. The command surface maps
|
|
362
|
-
// this reason to kind:'error'. (Only source failures back off — see scheduler.)
|
|
363
|
-
const hasFailedRoutes = write.failedRoutes.length > 0;
|
|
364
|
-
return withJournal({
|
|
365
|
-
ok: !hasFailedRoutes,
|
|
366
|
-
reason: hasFailedRoutes ? 'write-failed' : 'completed',
|
|
367
|
-
source,
|
|
368
|
-
write,
|
|
369
|
-
text: formatGoRoundReport(source, write),
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
/** Stable, testable report text: source summary, per-route outcome, plan notes. */
|
|
373
|
-
export function formatGoRoundReport(source, write) {
|
|
374
|
-
const lines = [
|
|
375
|
-
`opencode-go: source ok (${source.entries.length} models, key=${source.keyFingerprint}, hash=${(source.payloadHash ?? '').slice(0, 12)})`,
|
|
376
|
-
];
|
|
377
|
-
for (const status of write.routes) {
|
|
378
|
-
lines.push(` ${status.route}: ${status.status}${status.reason !== undefined ? ` (${status.reason})` : ''}`);
|
|
379
|
-
}
|
|
380
|
-
for (const entry of write.report) {
|
|
381
|
-
lines.push(` [${entry.level}] ${entry.code}${entry.route !== undefined ? ` ${entry.route}` : ''}${entry.id !== undefined ? `/${entry.id}` : ''}: ${entry.message}`);
|
|
382
|
-
}
|
|
383
|
-
if (write.writtenRoutes.length === 0 && write.failedRoutes.length === 0) {
|
|
384
|
-
lines.push(' no settings changes');
|
|
385
|
-
}
|
|
386
|
-
return lines.join('\n');
|
|
387
|
-
}
|
|
388
|
-
//# sourceMappingURL=opencode-go-sync.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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,IAAI,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -1,148 +0,0 @@
|
|
|
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
|
-
/**
|
|
30
|
-
* Host runtime catalog ids for opencode-go (0.12.1). `undefined` keeps the
|
|
31
|
-
* 0.12.0 writer behavior. With an array the writer (H5): removes
|
|
32
|
-
* deletion-candidates the host catalog does not know IMMEDIATELY (the
|
|
33
|
-
* double-round confirmation deadlocks when round 1's write-back is rejected
|
|
34
|
-
* wholesale and the counter can never persist), and refuses to write any
|
|
35
|
-
* route whose final models array still carries ids outside the catalog
|
|
36
|
-
* (fail-closed with an actionable message instead of a raw host rejection).
|
|
37
|
-
*/
|
|
38
|
-
hostCatalogIds?: readonly string[];
|
|
39
|
-
/** go.confirmRemovals; default 2 (schema min 2, design §6.2.6). */
|
|
40
|
-
confirmRemovals?: number;
|
|
41
|
-
/**
|
|
42
|
-
* go.adoptExisting / `/model-sync adopt go` (design §14.1). With no prior
|
|
43
|
-
* ledger the writer claims only desired∩current by default; adopt also
|
|
44
|
-
* claims the route's pre-existing models so they become deletion candidates
|
|
45
|
-
* on later rounds (still subject to the two-round confirmation + 3 gates).
|
|
46
|
-
*/
|
|
47
|
-
adoptExisting?: boolean;
|
|
48
|
-
/** Optional models-store seam for override fold + unset (store-first). */
|
|
49
|
-
overrideStorer?: GoOverrideStorer;
|
|
50
|
-
/**
|
|
51
|
-
* B4/N1 fail-closed guard: the llm-pi-ai revision the plan was built against
|
|
52
|
-
* (the fetch-time / post-validation revision). The writer re-reads the
|
|
53
|
-
* descriptor before ANY settings mutate or ledger commit; if the revision
|
|
54
|
-
* moved since the round was validated, the plan is stale and the WHOLE round
|
|
55
|
-
* is abandoned (zero writes, no ledger/fingerprint). Omitted only by pure
|
|
56
|
-
* unit writers that do not have a round-level revision to validate.
|
|
57
|
-
*/
|
|
58
|
-
expectedRevision?: number;
|
|
59
|
-
/**
|
|
60
|
-
* §14.7.5 second gate: called immediately before EACH mutate (and again on a
|
|
61
|
-
* SETTINGS_CONFLICT retry). Must re-read the persisted migration status —
|
|
62
|
-
* never reuse the round-level snapshot. A false result leaves the route
|
|
63
|
-
* untouched (including the ledger); `reason: 'canWrite-unavailable'` is
|
|
64
|
-
* reported when the status re-read itself failed (fail closed). Absent means
|
|
65
|
-
* no second gate (pure unit writers). A plain boolean is accepted for tests.
|
|
66
|
-
*/
|
|
67
|
-
canWrite?: (route: string) => boolean | GoCanWriteDecision | Promise<boolean> | Promise<GoCanWriteDecision>;
|
|
68
|
-
/**
|
|
69
|
-
* §14.7.4: called ONLY after a route's settings.mutate AND its ledger commit
|
|
70
|
-
* both succeeded, with the ledger-managed ids just committed. The callback
|
|
71
|
-
* re-persists `appliedFingerprint` through the same store queue. Never called
|
|
72
|
-
* for a failed write, a no-change round, or another writer's no-op success.
|
|
73
|
-
* H4/M2: the third argument marks a whole-section unset (the ledger key was
|
|
74
|
-
* deleted, not written) so the record update can DROP the route's
|
|
75
|
-
* `appliedManagedIds` key instead of persisting a phantom `[]` entry no
|
|
76
|
-
* ledger backs.
|
|
77
|
-
*/
|
|
78
|
-
onOwnWrite?: (route: string, managedIds: string[], info?: {
|
|
79
|
-
unset: boolean;
|
|
80
|
-
}) => Promise<void> | void;
|
|
81
|
-
/**
|
|
82
|
-
* O1/C2: write-ahead journal store. When present together with `profileKey`,
|
|
83
|
-
* each settings mutate is preceded by a journal slot recording the intended
|
|
84
|
-
* ledger entry + the post-write content hash; it is removed only after the
|
|
85
|
-
* ledger AND migration record both landed. The next round reconciles any
|
|
86
|
-
* surviving journal before the migration gate. Omitted by pure unit writers
|
|
87
|
-
* (no file-backed store) — those keep the pre-C2 behavior.
|
|
88
|
-
*/
|
|
89
|
-
journalStore?: GoJournalStore;
|
|
90
|
-
/** O1/C2: stable profile key for the journal slot (must match reconciliation). */
|
|
91
|
-
profileKey?: string;
|
|
92
|
-
/** O1/C2: injectable clock for the journal timestamp; defaults to Date.now. */
|
|
93
|
-
now?: () => number;
|
|
94
|
-
}
|
|
95
|
-
export interface GoCanWriteDecision {
|
|
96
|
-
allow: boolean;
|
|
97
|
-
/** `canWrite-unavailable` when the live status re-read failed. */
|
|
98
|
-
reason?: string;
|
|
99
|
-
}
|
|
100
|
-
export type GoRouteStatus = 'wrote' | 'no-change' | 'unset' | 'skipped' | 'conflict' | 'failed';
|
|
101
|
-
export interface GoRouteWriteStatus {
|
|
102
|
-
route: string;
|
|
103
|
-
slot?: GoRouteSlot;
|
|
104
|
-
status: GoRouteStatus;
|
|
105
|
-
reason?: string;
|
|
106
|
-
}
|
|
107
|
-
export interface GoWriteResult {
|
|
108
|
-
/** One entry per planned route, plus one per conflicted route. */
|
|
109
|
-
routes: GoRouteWriteStatus[];
|
|
110
|
-
/** Routes whose settings.mutate resolved (wrote or unset). */
|
|
111
|
-
writtenRoutes: string[];
|
|
112
|
-
/** Routes whose mutate failed, with an honest reason. */
|
|
113
|
-
failedRoutes: {
|
|
114
|
-
route: string;
|
|
115
|
-
reason: string;
|
|
116
|
-
}[];
|
|
117
|
-
/**
|
|
118
|
-
* O1-minimal: routes whose settings.mutate landed this round, whether or not
|
|
119
|
-
* the ledger commit after it succeeded. Used for an honest N1-abandon report
|
|
120
|
-
* (a route may have been written before the round was abandoned).
|
|
121
|
-
*/
|
|
122
|
-
settingsLandedRoutes: string[];
|
|
123
|
-
/**
|
|
124
|
-
* B4/N1: set when the round was abandoned because the host settings revision
|
|
125
|
-
* moved mid-round. The caller must report this as
|
|
126
|
-
* `settings-changed-during-sync` and treat the round as a zero-write no-op.
|
|
127
|
-
*/
|
|
128
|
-
settingsChanged?: {
|
|
129
|
-
expectedRevision: number | undefined;
|
|
130
|
-
actualRevision: number;
|
|
131
|
-
};
|
|
132
|
-
/** Planner report adjusted by writer decisions + `moved` association. */
|
|
133
|
-
report: GoPlanReportEntry[];
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Apply a planner result to the injected settings service and persist the
|
|
137
|
-
* updated ownership ledger. Multi-route writes are isolated per route: one
|
|
138
|
-
* route's failure never poisons the others, and the result names both the
|
|
139
|
-
* routes written and the routes failed (§19 single-point-failure guidance).
|
|
140
|
-
*/
|
|
141
|
-
export declare function writeGoPlan(plan: GoPlanResult, deps: GoWriterDeps): Promise<GoWriteResult>;
|
|
142
|
-
/**
|
|
143
|
-
* Pair a removal on route A with an add of the same id on route B into one
|
|
144
|
-
* human-readable `moved` entry, so a consumer never reads a cross-slot move as
|
|
145
|
-
* an unrelated delete + add. A still-pending source removal is labelled as
|
|
146
|
-
* such (double confirmation), so the report stays honest.
|
|
147
|
-
*/
|
|
148
|
-
export declare function associateGoMoves(report: readonly GoPlanReportEntry[]): GoPlanReportEntry[];
|