@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.
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 +116 -0
  10. package/lib/official-migrate.js +643 -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 +840 -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,241 +0,0 @@
1
- // P1c-2: async timer + scheduling layer for the opencode-go sync round.
2
- //
3
- // This module owns ONLY scheduling (design §6.3 / §14.6): startup delay +
4
- // jitter, the 60min (floor 15) interval with live re-arm, single-flight with
5
- // the manual /model-sync go command, failure backoff with caps, and timer
6
- // cleanup on plugin unload. It does NOT run the round itself — `runRound` is
7
- // injected and is normally index.ts's runGoRound (source → planner → writer).
8
- //
9
- // Every clock/random input is injected (GoSchedulerTimers / GoSchedulerRandom),
10
- // so the whole state machine runs deterministically under a fake timer: no
11
- // real sleep, no network. The production adapters live in index.ts.
12
- //
13
- // Last-good safety: scheduling never persists anything. Backoff state is an
14
- // in-memory streak only. A failed round returns before the writer, so settings
15
- // and the ownership ledger keep their last-good values (design §6.3 "离线:
16
- // settings 中 last-good 继续可用"). M-4 zero-write is enforced by routeWriter
17
- // inside the round (P1d-1); this layer only adds the M-5 `applying` drop.
18
- /** Cordis service seams used by index.ts to inject test doubles. */
19
- export const GO_SCHEDULER_TIMERS_SERVICE = 'goSchedulerTimers';
20
- export const GO_SCHEDULER_RANDOM_SERVICE = 'goSchedulerRandom';
21
- // Implementation constants. Design §6.3 / ADR-007 fix the interval floor and
22
- // the transport/auth caps; the backoff BASE and the startup jitter window are
23
- // not specified numerically by the design, so these are the documented
24
- // implementation choices (kept exported for tests).
25
- export const GO_INTERVAL_MIN_MINUTES = 15;
26
- export const GO_INTERVAL_DEFAULT_MINUTES = 60;
27
- export const GO_STARTUP_JITTER_MAX_MS = 5_000;
28
- export const GO_TRANSPORT_BACKOFF_BASE_MS = 60_000;
29
- export const GO_TRANSPORT_BACKOFF_CAP_MS = 30 * 60_000;
30
- export const GO_AUTH_BACKOFF_BASE_MS = 60 * 60_000;
31
- export const GO_AUTH_BACKOFF_CAP_MS = 6 * 60 * 60_000;
32
- /** Clamp an interval to the design floor; non-finite falls back to the default. */
33
- export function clampGoIntervalMinutes(value) {
34
- if (!Number.isFinite(value))
35
- return GO_INTERVAL_DEFAULT_MINUTES;
36
- return Math.max(GO_INTERVAL_MIN_MINUTES, Math.floor(value));
37
- }
38
- /** startupDelaySeconds*1000 plus bounded jitter (random is in [0,1)). */
39
- export function goStartupDelayMs(seconds, random) {
40
- const base = Number.isFinite(seconds) && seconds > 0 ? seconds * 1000 : 0;
41
- const r = Math.min(1, Math.max(0, Number.isFinite(random) ? random : 0));
42
- return base + Math.floor(r * GO_STARTUP_JITTER_MAX_MS);
43
- }
44
- /** Exponential backoff with per-class cap (design §6.3). */
45
- export function goBackoffDelayMs(streak, failureKind) {
46
- const n = Math.max(1, Math.floor(streak));
47
- const auth = failureKind === 'auth' || failureKind === 'entitlement';
48
- const base = auth ? GO_AUTH_BACKOFF_BASE_MS : GO_TRANSPORT_BACKOFF_BASE_MS;
49
- const cap = auth ? GO_AUTH_BACKOFF_CAP_MS : GO_TRANSPORT_BACKOFF_CAP_MS;
50
- return Math.min(cap, base * 2 ** (n - 1));
51
- }
52
- /** Report text for a skipped round — always states the reason explicitly. */
53
- export function goSchedulerSkipReport(reason, trigger) {
54
- const when = `opencode-go scheduler (${trigger})`;
55
- switch (reason) {
56
- case 'disabled':
57
- // Keep the legacy phrase "disabled — set opencode.go.enabled=true" so
58
- // manual /model-sync go reports stay byte-compatible with P1c-1.
59
- return `${when}: skipped — opencode.go sync is disabled — set opencode.go.enabled=true; no request, no settings write. (The migration gate is enforced separately by routeWriter on every write path.)`;
60
- case 'already-in-flight':
61
- return `${when}: skipped — a go round is already in flight (single-flight); no queue, no retry, no settings write (design §14.6).`;
62
- case 'migration-applying':
63
- return `${when}: skipped — migration apply in progress (M-5); no queue, no retry, no settings write (design §14.6).`;
64
- case 'disposed':
65
- return `${when}: skipped — scheduler disposed (plugin unload); no request, no settings write.`;
66
- default:
67
- return `${when}: skipped — ${reason}; no request, no settings write.`;
68
- }
69
- }
70
- function isBackoffFailure(outcome) {
71
- // Configuration/skip states (disabled, no-key, settings-unavailable) are not
72
- // failures — they keep the normal interval. Only source failures back off.
73
- return outcome.reason === 'source-failed' || outcome.failureKind !== undefined;
74
- }
75
- /**
76
- * The scheduler state machine. One instance per plugin activation; it owns a
77
- * single timer handle and a single in-flight flag shared by auto and manual
78
- * triggers (that is the single-flight lock).
79
- */
80
- export class GoScheduler {
81
- config;
82
- timers;
83
- random;
84
- runRound;
85
- report;
86
- isApplying;
87
- handle;
88
- started = false;
89
- inFlight = false;
90
- disposed = false;
91
- streak = 0;
92
- lastFailureKind;
93
- /** Single lifetime signal: dispose() aborts the round that is currently in flight. */
94
- abort = new AbortController();
95
- constructor(deps) {
96
- this.config = deps.config;
97
- this.timers = deps.timers;
98
- this.random = deps.random;
99
- this.runRound = deps.runRound;
100
- this.report = deps.report;
101
- this.isApplying = deps.isApplying;
102
- }
103
- /** Arm the startup timer. No-op when disabled — zero triggers at enabled=false. */
104
- start() {
105
- if (this.started || this.disposed)
106
- return;
107
- this.started = true;
108
- const cfg = this.config();
109
- if (!cfg.enabled)
110
- return;
111
- this.arm(goStartupDelayMs(cfg.startupDelaySeconds, this.random.next()), 'startup');
112
- }
113
- /**
114
- * Live re-arm after a settings edit. Cancels the pending timer and reads
115
- * fresh config; a round already in flight keeps its lock and picks up the
116
- * new config when it schedules its own successor.
117
- */
118
- rearm() {
119
- if (this.disposed || !this.started)
120
- return;
121
- this.cancel();
122
- if (this.inFlight)
123
- return;
124
- this.armFromConfig();
125
- }
126
- /**
127
- * Reset backoff after a credential change. Clears the in-memory streak and
128
- * re-arms at the normal interval instead of waiting out a capped (up to 6h)
129
- * backoff — a fixed key must not stay frozen for hours (design §6.3). The
130
- * caller's listener is disposed with the plugin; a disposed scheduler is a
131
- * no-op.
132
- */
133
- resetBackoff() {
134
- this.clearBackoff();
135
- if (this.disposed || !this.started || this.inFlight)
136
- return;
137
- this.armFromConfig();
138
- }
139
- /** Cancel every timer and abort a round already in flight (design §6.3 卸载). */
140
- dispose() {
141
- this.disposed = true;
142
- this.abort.abort();
143
- this.cancel();
144
- }
145
- get isInFlight() {
146
- return this.inFlight;
147
- }
148
- get failureStreak() {
149
- return this.streak;
150
- }
151
- /** Manual /model-sync go trigger — shares the single-flight lock with auto rounds. */
152
- triggerManual(options = {}) {
153
- return this.fire('manual', options.adopt === true);
154
- }
155
- arm(delayMs, trigger) {
156
- this.cancel();
157
- // Returning the promise is harmless to real setTimeout (return value is
158
- // ignored) and lets a fake timer await the whole round deterministically.
159
- this.handle = this.timers.setTimeout(() => this.fire(trigger), Math.max(0, delayMs));
160
- }
161
- cancel() {
162
- if (this.handle !== undefined) {
163
- this.timers.clearTimeout(this.handle);
164
- this.handle = undefined;
165
- }
166
- }
167
- armFromConfig() {
168
- const cfg = this.config();
169
- if (!cfg.enabled)
170
- return;
171
- if (this.streak > 0) {
172
- this.arm(goBackoffDelayMs(this.streak, this.lastFailureKind), 'backoff');
173
- }
174
- else {
175
- this.arm(clampGoIntervalMinutes(cfg.intervalMinutes) * 60_000, 'interval');
176
- }
177
- }
178
- /** Forget the entire backoff history (transport === auth) — used by reset paths. */
179
- clearBackoff() {
180
- this.streak = 0;
181
- this.lastFailureKind = undefined;
182
- }
183
- async fire(trigger, adopt = false) {
184
- if (this.disposed)
185
- return this.skip('disposed', trigger);
186
- if (!this.config().enabled)
187
- return this.skip('disabled', trigger);
188
- if (this.inFlight)
189
- return this.skip('already-in-flight', trigger);
190
- // M-5: an in-progress migration owns the routes; drop the round now rather
191
- // than racing a half-applied settings document. Same non-queueing rule as
192
- // the single-flight lock (§14.6).
193
- if (this.isApplying !== undefined && await this.isApplying() === true)
194
- return this.skip('migration-applying', trigger);
195
- // The timer that fired is now consumed; a new one is armed after the round.
196
- this.cancel();
197
- this.inFlight = true;
198
- // A manual round is an explicit force: forget any accumulated backoff
199
- // before it runs (design §6.3 "手动 force 必须重置退避").
200
- if (trigger === 'manual')
201
- this.clearBackoff();
202
- let result;
203
- try {
204
- const raw = await this.runRound({ trigger, adopt, signal: this.abort.signal });
205
- if (raw.ok) {
206
- this.streak = 0;
207
- this.lastFailureKind = undefined;
208
- }
209
- else if (isBackoffFailure(raw)) {
210
- this.streak += 1;
211
- this.lastFailureKind = raw.failureKind;
212
- }
213
- result = { ...raw, skipped: false };
214
- }
215
- catch (error) {
216
- const message = error instanceof Error ? error.message : String(error);
217
- this.streak += 1;
218
- this.lastFailureKind = 'transport';
219
- result = {
220
- ok: false,
221
- reason: 'scheduler-error',
222
- text: `opencode-go scheduler: round error — ${message}; kept last-good, no further settings write`,
223
- failureKind: 'transport',
224
- skipped: false,
225
- };
226
- }
227
- finally {
228
- this.inFlight = false;
229
- }
230
- this.report(result.text);
231
- if (!this.disposed)
232
- this.armFromConfig();
233
- return result;
234
- }
235
- skip(reason, trigger) {
236
- const text = goSchedulerSkipReport(reason, trigger);
237
- this.report(text);
238
- return { ok: false, reason, text, skipped: true };
239
- }
240
- }
241
- //# sourceMappingURL=opencode-go-scheduler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"opencode-go-scheduler.js","sourceRoot":"","sources":["../src/opencode-go-scheduler.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,EAAE;AACF,gFAAgF;AAChF,2EAA2E;AAC3E,oEAAoE;AACpE,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,yEAAyE;AACzE,yEAAyE;AACzE,0EAA0E;AAI1E,oEAAoE;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAAA;AAC9D,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CA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B,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,aAAa,EAAE,CAAA;QACxC,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,IAAI,CAAC,MAAc,EAAE,OAAkB;QAC7C,MAAM,IAAI,GAAG,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACjB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IACnD,CAAC;CACF"}
@@ -1,18 +0,0 @@
1
- import { type ModelsStoreAccessor } from './remote-catalog.ts';
2
- import type { GoOwnershipStore } from './opencode-go-writer.ts';
3
- /**
4
- * Build a `GoOwnershipStore` on top of an existing models-store accessor.
5
- *
6
- * `profileKey` prefixes every opaque key, turning `<route>#<keyFingerprint>`
7
- * into `<profileKey>#<route>#<keyFingerprint>` (B1). Two profiles using the
8
- * same Go key occupy disjoint slots in the shared document, and a rollback
9
- * deletes only the calling profile's slots. Omitting `profileKey` keeps the
10
- * pre-fix unscoped behavior for legacy callers/tests only.
11
- */
12
- export declare function createFileOwnershipStore(accessor: ModelsStoreAccessor, profileKey?: string): GoOwnershipStore;
13
- /**
14
- * Production factory: the ledger lives in ~/.dsh/models-store.json. Tests pass
15
- * `loadModelsStore(tempPath)` through `createFileOwnershipStore` instead, so no
16
- * test ever touches the real ~/.dsh.
17
- */
18
- export declare function createModelsStoreOwnershipStore(storePath?: string, profileKey?: string): GoOwnershipStore;
@@ -1,68 +0,0 @@
1
- // P1c file adapter: persist the opencode-go ownership ledger in the SAME file
2
- // and through the SAME serialized queue as the pi.dev fetch cache, so a ledger
3
- // write can never clobber a concurrent fetch/override stage (design §6.1,
4
- // ADR-004; verification 21 §9 concern ②).
5
- //
6
- // Wire format (design §6.1, B1): a top-level slot per ledger key,
7
- // <profileKey>#<route>#<keyFingerprint> -> GoOwnershipEntry
8
- // in ~/.dsh/models-store.json (unscoped callers still use <route>#<keyFingerprint>).
9
- // Keys containing `#` are never valid provider route ids, so the existing
10
- // `read(route)` / `update(route)` paths cannot see these entries. Atomic
11
- // temp+rename and the write queue come from `loadModelsStore()` — this module
12
- // adds no second persistence mechanism.
13
- //
14
- // Failure direction: a corrupt/unreadable document reads as "no ledger"
15
- // (`undefined`). The writer then does a conservative first-round claim — it
16
- // never deletes without a hash (ADR-004: store loss degrades to no-delete).
17
- // The next write replaces the bad file atomically and heals it.
18
- import { scopedStoreKey } from "./opencode-go-profile.js";
19
- import { loadModelsStore } from "./remote-catalog.js";
20
- /**
21
- * Build a `GoOwnershipStore` on top of an existing models-store accessor.
22
- *
23
- * `profileKey` prefixes every opaque key, turning `<route>#<keyFingerprint>`
24
- * into `<profileKey>#<route>#<keyFingerprint>` (B1). Two profiles using the
25
- * same Go key occupy disjoint slots in the shared document, and a rollback
26
- * deletes only the calling profile's slots. Omitting `profileKey` keeps the
27
- * pre-fix unscoped behavior for legacy callers/tests only.
28
- */
29
- export function createFileOwnershipStore(accessor, profileKey) {
30
- const slot = (key) => profileKey === undefined ? key : scopedStoreKey(profileKey, key);
31
- return {
32
- async read(key) {
33
- let raw;
34
- try {
35
- raw = await accessor.readRaw(slot(key));
36
- }
37
- catch {
38
- // Corrupt file / EACCES: no ledger. Never infer one, never delete.
39
- return undefined;
40
- }
41
- // readRaw now returns the slot verbatim; a present primitive/null slot is
42
- // NOT a ledger entry (same conservative "no ledger" direction as before).
43
- if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
44
- return undefined;
45
- const record = raw;
46
- if (typeof record.managed !== 'object' || record.managed === null
47
- || Array.isArray(record.managed)) {
48
- return undefined;
49
- }
50
- return record;
51
- },
52
- async write(key, entry) {
53
- await accessor.writeRaw(slot(key), entry);
54
- },
55
- async delete(key) {
56
- await accessor.deleteRaw(slot(key));
57
- },
58
- };
59
- }
60
- /**
61
- * Production factory: the ledger lives in ~/.dsh/models-store.json. Tests pass
62
- * `loadModelsStore(tempPath)` through `createFileOwnershipStore` instead, so no
63
- * test ever touches the real ~/.dsh.
64
- */
65
- export function createModelsStoreOwnershipStore(storePath, profileKey) {
66
- return createFileOwnershipStore(loadModelsStore(storePath), profileKey);
67
- }
68
- //# sourceMappingURL=opencode-go-store.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"opencode-go-store.js","sourceRoot":"","sources":["../src/opencode-go-store.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+EAA+E;AAC/E,0EAA0E;AAC1E,0CAA0C;AAC1C,EAAE;AACF,kEAAkE;AAClE,8DAA8D;AAC9D,qFAAqF;AACrF,0EAA0E;AAC1E,yEAAyE;AACzE,8EAA8E;AAC9E,wCAAwC;AACxC,EAAE;AACF,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,gEAAgE;AAGhE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,eAAe,EAA4B,MAAM,qBAAqB,CAAA;AAG/E;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA6B,EAC7B,UAAmB;IAEnB,MAAM,IAAI,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IACtG,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,GAAW;YACpB,IAAI,GAAY,CAAA;YAChB,IAAI,CAAC;gBACH,GAAG,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;YACzC,CAAC;YAAC,MAAM,CAAC;gBACP,mEAAmE;gBACnE,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,0EAA0E;YAC1E,0EAA0E;YAC1E,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;gBAAE,OAAO,SAAS,CAAA;YACnF,MAAM,MAAM,GAAG,GAA8B,CAAA;YAC7C,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI;mBAC5D,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBACnC,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,OAAO,MAAqC,CAAA;QAC9C,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAW,EAAE,KAAuB;YAC9C,MAAM,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAA2C,CAAC,CAAA;QACjF,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,GAAW;YACtB,MAAM,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACrC,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAAC,SAAkB,EAAE,UAAmB;IACrF,OAAO,wBAAwB,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,CAAA;AACzE,CAAC"}
@@ -1,107 +0,0 @@
1
- import { type GoRouteSlot } from './opencode-go-grouping.ts';
2
- import { type GoFetchLike, type GoSourceResult } from './opencode-go-source.ts';
3
- import { type GoOverrideStorer, type GoOwnershipStore, type GoWriteResult } from './opencode-go-writer.ts';
4
- import type { Logger, SettingsService } from './writer.ts';
5
- import { type MigrationStatus } from './opencode-go-migration.ts';
6
- import { type GoJournalStore, type ReconcileResult } from './opencode-go-journal.ts';
7
- /**
8
- * Cordis service names used only as injection seams. Both are optional:
9
- * production falls back to the real file store and the global fetch; tests
10
- * register a temp-dir store / stub fetch under these names to run a full round
11
- * with zero filesystem writes outside a temp dir and zero network.
12
- */
13
- export declare const GO_OWNERSHIP_STORE_SERVICE = "goOwnershipStore";
14
- export declare const GO_OVERRIDE_STORER_SERVICE = "goOverrideStorer";
15
- export declare const GO_FETCH_SERVICE = "goFetchImpl";
16
- /** The go subset of the published Config contract (design §6.2.6). */
17
- export interface GoSyncRuntimeConfig {
18
- /** Master switch (design §6.2.6: false = zero behavior change). */
19
- enabled: boolean;
20
- ref: string;
21
- modelsUrl: string;
22
- routes: Partial<Record<GoRouteSlot, string>>;
23
- pinnedModels: readonly string[];
24
- confirmRemovals: number;
25
- adoptExisting: boolean;
26
- }
27
- export interface GoRoundDeps {
28
- settings: SettingsService | undefined;
29
- ownershipStore: GoOwnershipStore;
30
- overrideStorer?: GoOverrideStorer;
31
- logger: Logger;
32
- config: GoSyncRuntimeConfig;
33
- /**
34
- * Host runtime catalog ids for opencode-go (0.12.1). An ARRAY intersects the
35
- * desired set with it (ids the host catalog does not know are reported as
36
- * `needs-host-catalog`, never written). `null` FAILS THE ROUND CLOSED —
37
- * zero writes — because writing the unverified full listing is exactly how
38
- * 0.12.0 got the whole mutate rejected by the host. `undefined` (pure unit
39
- * callers only; production always supplies one of the two) keeps the 0.12.0
40
- * behavior.
41
- */
42
- hostCatalogIds?: readonly string[] | null;
43
- /** Resolved credential VALUE; undefined/empty means no request and no write (V4). */
44
- apiKey?: string;
45
- /** Injectable network; production falls back to the global fetch in the source. */
46
- fetchImpl?: GoFetchLike;
47
- /** Deterministic clock for tests. */
48
- observedAt?: number;
49
- /** Plugin-lifetime signal; aborted mid-round stops the fetch and blocks the writer. */
50
- signal?: AbortSignal;
51
- /**
52
- * Current migration status (§14.1). Defaults to `absent` for direct unit
53
- * callers that only exercise writer mechanics; the production wiring in
54
- * index.ts always passes the real status read from the settings + record.
55
- */
56
- migration?: MigrationStatus;
57
- /**
58
- * §14.7.5: re-read the PERSISTED migration status for the second gate, called
59
- * before every mutate. Production passes `loadMigrationStatus`; without it
60
- * there is NO second gate (pure writer-mechanics callers) — the round-level
61
- * snapshot is never reused. A failed re-read is reported as
62
- * `canWrite-unavailable` and skips the route (fail closed).
63
- */
64
- reloadMigration?: () => Promise<MigrationStatus>;
65
- /** §14.7.4: forward the post-own-write managed ids to the record persister.
66
- * The third argument marks a whole-section unset (ledger key deleted). */
67
- onOwnWrite?: (route: string, managedIds: string[], info?: {
68
- unset: boolean;
69
- }) => Promise<void>;
70
- /**
71
- * O1/C2: file-backed write-ahead journal store. With `profileKey` and
72
- * `keyFingerprint`, the round reconciles surviving journals BEFORE the
73
- * migration gate (a closed gate must still self-heal). Omitted by pure unit
74
- * callers — no journal, no reconciliation, pre-C2 behavior.
75
- */
76
- journalStore?: GoJournalStore;
77
- /** O1/C2: stable profile key used to scope reconciliation. */
78
- profileKey?: string;
79
- /** O1/C2: current credential fingerprint; journals stamped with another key
80
- * are orphans and are discarded, never replayed. */
81
- keyFingerprint?: string;
82
- }
83
- export type GoRoundReason = 'disabled' | 'settings-unavailable' | 'no-key' | 'source-failed' | 'writer-error' | 'aborted' | 'migration-gate' | 'settings-changed-during-sync' | 'host-catalog-unavailable' | 'write-failed' | 'completed';
84
- export interface GoSyncRoundResult {
85
- ok: boolean;
86
- reason: GoRoundReason;
87
- source?: GoSourceResult;
88
- write?: GoWriteResult;
89
- /**
90
- * B4 (31, design §14.7.5): set only when the host settings document revision
91
- * moved while the official catalog request was in flight, i.e. the round was
92
- * abandoned before building a plan/writing anything. Machine-readable
93
- * companion to the user-visible `text` (no write, no ledger/fingerprint).
94
- */
95
- settingsChanged?: {
96
- beforeRevision: number;
97
- afterRevision: number;
98
- };
99
- /** O1/C2: outcome of the pre-gate journal reconciliation (when wired). */
100
- journal?: ReconcileResult;
101
- /** Human-readable lines for `/model-sync` and the auto-round logger. */
102
- text: string;
103
- }
104
- /** One complete go round. Never throws for expected source/store failures. */
105
- export declare function runGoSyncRound(deps: GoRoundDeps): Promise<GoSyncRoundResult>;
106
- /** Stable, testable report text: source summary, per-route outcome, plan notes. */
107
- export declare function formatGoRoundReport(source: GoSourceResult, write: GoWriteResult): string;