@cnzgray/dsh-mattpocock-workflow 0.4.0 → 0.5.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/lib/client.js +238 -55
- package/lib/index.js +1099 -436
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -33,11 +33,12 @@ function isRecord(value) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// src/core/snapshot-store.ts
|
|
36
|
-
var SNAPSHOT_STORE_VERSION =
|
|
36
|
+
var SNAPSHOT_STORE_VERSION = 5;
|
|
37
37
|
var BACKENDS = ["github", "gitlab", "gitea", "markdown"];
|
|
38
38
|
function serializeSnapshotStoreEntry(entry) {
|
|
39
39
|
return JSON.stringify({
|
|
40
40
|
version: entry.version,
|
|
41
|
+
libraryVersion: entry.libraryVersion,
|
|
41
42
|
workspaceRoot: entry.workspaceRoot,
|
|
42
43
|
backend: entry.backend,
|
|
43
44
|
repository: entry.repository,
|
|
@@ -49,17 +50,21 @@ function serializeSnapshotStoreEntry(entry) {
|
|
|
49
50
|
total: entry.total,
|
|
50
51
|
...entry.windowLimit === void 0 ? {} : { windowLimit: entry.windowLimit },
|
|
51
52
|
hierarchy: entry.hierarchy,
|
|
53
|
+
metrics: entry.metrics,
|
|
52
54
|
tickets: entry.tickets
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
|
-
function
|
|
57
|
+
function parseSnapshotTicket(raw) {
|
|
56
58
|
let payload;
|
|
57
59
|
try {
|
|
58
60
|
payload = JSON.parse(raw);
|
|
59
61
|
} catch {
|
|
60
62
|
return void 0;
|
|
61
63
|
}
|
|
62
|
-
return
|
|
64
|
+
return readTicket(payload);
|
|
65
|
+
}
|
|
66
|
+
function readSnapshotStoreEntry(value) {
|
|
67
|
+
return readEntry(value);
|
|
63
68
|
}
|
|
64
69
|
function readEntry(value) {
|
|
65
70
|
if (!isRecord(value)) return void 0;
|
|
@@ -85,10 +90,17 @@ function readEntry(value) {
|
|
|
85
90
|
}
|
|
86
91
|
const hierarchy = readHierarchy(value.hierarchy);
|
|
87
92
|
if (hierarchy === void 0) return void 0;
|
|
93
|
+
const libraryVersion = value.libraryVersion;
|
|
94
|
+
if (typeof libraryVersion !== "number" || !Number.isInteger(libraryVersion) || libraryVersion < 0) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
const metrics = readMetrics(value.metrics);
|
|
98
|
+
if (metrics === void 0) return void 0;
|
|
88
99
|
const tickets = readTickets(value.tickets);
|
|
89
100
|
if (tickets === void 0) return void 0;
|
|
90
101
|
return {
|
|
91
102
|
version: SNAPSHOT_STORE_VERSION,
|
|
103
|
+
libraryVersion,
|
|
92
104
|
workspaceRoot,
|
|
93
105
|
backend,
|
|
94
106
|
repository,
|
|
@@ -100,6 +112,7 @@ function readEntry(value) {
|
|
|
100
112
|
total,
|
|
101
113
|
...windowLimit === void 0 ? {} : { windowLimit },
|
|
102
114
|
hierarchy,
|
|
115
|
+
metrics,
|
|
103
116
|
tickets
|
|
104
117
|
};
|
|
105
118
|
}
|
|
@@ -166,6 +179,38 @@ function readHierarchy(value) {
|
|
|
166
179
|
if (value === "native" || value === "convention" || value === "none") return value;
|
|
167
180
|
return void 0;
|
|
168
181
|
}
|
|
182
|
+
function readMetrics(value) {
|
|
183
|
+
if (!isRecord(value)) return void 0;
|
|
184
|
+
for (const key of ["openBacklog", "readyCapacity", "blockedRatio", "needsTriage", "stalled"]) {
|
|
185
|
+
if (typeof value[key] !== "number" || !Number.isFinite(value[key])) return void 0;
|
|
186
|
+
}
|
|
187
|
+
for (const key of [
|
|
188
|
+
"staleCount",
|
|
189
|
+
"staleRatio",
|
|
190
|
+
"oldestUpdateDays",
|
|
191
|
+
"longestBlockerChain",
|
|
192
|
+
"openedLast30Days",
|
|
193
|
+
"closedLast30Days",
|
|
194
|
+
"netFlow"
|
|
195
|
+
]) {
|
|
196
|
+
if (readMetricValue(value[key]) === void 0) return void 0;
|
|
197
|
+
}
|
|
198
|
+
const coverage = value.coverage;
|
|
199
|
+
if (!isRecord(coverage) || typeof coverage.truncated !== "boolean") return void 0;
|
|
200
|
+
const pressure = value.pressure;
|
|
201
|
+
if (!isRecord(pressure) || typeof pressure.tier !== "string") return void 0;
|
|
202
|
+
if (!Array.isArray(pressure.dimensions)) return void 0;
|
|
203
|
+
if (!Array.isArray(value.attention)) return void 0;
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
function readMetricValue(value) {
|
|
207
|
+
if (!isRecord(value)) return void 0;
|
|
208
|
+
if (value.value !== null && (typeof value.value !== "number" || !Number.isFinite(value.value))) {
|
|
209
|
+
return void 0;
|
|
210
|
+
}
|
|
211
|
+
if (value.gap !== null && typeof value.gap !== "string") return void 0;
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
169
214
|
function readAuthor(value) {
|
|
170
215
|
if (value === null || value === void 0) return null;
|
|
171
216
|
if (!isRecord(value)) return void 0;
|
|
@@ -206,123 +251,320 @@ function readStringArray(value) {
|
|
|
206
251
|
// src/adapters/fs/snapshot-store.ts
|
|
207
252
|
var SNAPSHOT_STORE_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
208
253
|
var SNAPSHOT_STORE_MAX_ENTRIES = 20;
|
|
254
|
+
var SNAPSHOT_CHANGELOG_LIMIT = 200;
|
|
209
255
|
var DIRECTORY_NAME = "dsh-mattpocock-workflow";
|
|
210
256
|
function createNodeSnapshotStore(deps = {}) {
|
|
211
257
|
const env = deps.env ?? process.env;
|
|
212
258
|
const root = resolveRoot(deps, env);
|
|
213
259
|
const display = resolveDisplay(deps, env);
|
|
214
|
-
return {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return [];
|
|
223
|
-
}
|
|
224
|
-
const entries = [];
|
|
225
|
-
for (const name2 of names) {
|
|
226
|
-
if (!name2.endsWith(".json")) continue;
|
|
227
|
-
try {
|
|
228
|
-
const entry = parseSnapshotStoreEntry(await readFile(join(root, name2), "utf8"));
|
|
260
|
+
return {
|
|
261
|
+
read: (workspaceRoot) => readWorkspace(dirFor(root, workspaceRoot)),
|
|
262
|
+
write: (entry) => commitEntry(dirFor(root, entry.workspaceRoot), entry),
|
|
263
|
+
remove: (workspaceRoot) => rm(dirFor(root, workspaceRoot), { recursive: true, force: true }).then(() => void 0),
|
|
264
|
+
async list() {
|
|
265
|
+
const entries = [];
|
|
266
|
+
for (const meta of await listMetas(root)) {
|
|
267
|
+
const entry = await readWorkspace(dirFor(root, meta.entry.workspaceRoot));
|
|
229
268
|
if (entry !== void 0) entries.push(entry);
|
|
230
|
-
} catch {
|
|
231
269
|
}
|
|
232
|
-
|
|
233
|
-
return entries;
|
|
234
|
-
};
|
|
235
|
-
return {
|
|
236
|
-
read: (workspaceRoot) => readEntryAt(root, workspaceRoot),
|
|
237
|
-
async write(entry) {
|
|
238
|
-
await writeEntryAt(root, entry);
|
|
270
|
+
return entries;
|
|
239
271
|
},
|
|
240
|
-
async remove(workspaceRoot) {
|
|
241
|
-
await rm(fileFor(root, workspaceRoot), { force: true });
|
|
242
|
-
},
|
|
243
|
-
list,
|
|
244
272
|
async clear() {
|
|
245
|
-
const
|
|
246
|
-
for (const
|
|
247
|
-
await rm(
|
|
273
|
+
const metas = await listMetas(root);
|
|
274
|
+
for (const meta of metas) {
|
|
275
|
+
await rm(dirFor(root, meta.entry.workspaceRoot), { recursive: true, force: true });
|
|
248
276
|
}
|
|
249
|
-
return
|
|
277
|
+
return metas.length + await sweepLegacyFiles(root);
|
|
250
278
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (gone === true) {
|
|
258
|
-
await rm(fileFor(root, entry.workspaceRoot), { force: true });
|
|
259
|
-
removed += 1;
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (gone === false && now - entry.fetchedAt > SNAPSHOT_STORE_TTL_MS) {
|
|
263
|
-
await rm(fileFor(root, entry.workspaceRoot), { force: true });
|
|
264
|
-
removed += 1;
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
kept.push(entry);
|
|
268
|
-
}
|
|
269
|
-
if (kept.length > SNAPSHOT_STORE_MAX_ENTRIES) {
|
|
270
|
-
kept.sort((left, right) => left.fetchedAt - right.fetchedAt);
|
|
271
|
-
for (const entry of kept.slice(0, kept.length - SNAPSHOT_STORE_MAX_ENTRIES)) {
|
|
272
|
-
await rm(fileFor(root, entry.workspaceRoot), { force: true });
|
|
273
|
-
removed += 1;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return removed;
|
|
277
|
-
}
|
|
279
|
+
prune: (now) => pruneDirs(root, now),
|
|
280
|
+
patchTicket: (workspaceRoot, ref, patch) => patchTicketAt(root, workspaceRoot, ref, patch),
|
|
281
|
+
removeTicket: (workspaceRoot, ref) => removeTicketAt(root, workspaceRoot, ref),
|
|
282
|
+
version: async (workspaceRoot) => (await readMetaAt(dirFor(root, workspaceRoot)))?.entry.libraryVersion ?? null,
|
|
283
|
+
changesSince: (workspaceRoot, afterVersion) => changesSinceAt(root, workspaceRoot, afterVersion),
|
|
284
|
+
location: () => display
|
|
278
285
|
};
|
|
279
286
|
}
|
|
280
|
-
function
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
287
|
+
async function listMetas(root) {
|
|
288
|
+
let names;
|
|
289
|
+
try {
|
|
290
|
+
names = await readdir(root);
|
|
291
|
+
} catch {
|
|
292
|
+
return [];
|
|
293
|
+
}
|
|
294
|
+
const metas = [];
|
|
295
|
+
for (const name2 of names) {
|
|
296
|
+
const meta = await readMetaAt(join(root, name2));
|
|
297
|
+
if (meta !== void 0) metas.push(meta);
|
|
298
|
+
}
|
|
299
|
+
return metas;
|
|
300
|
+
}
|
|
301
|
+
async function sweepLegacyFiles(root) {
|
|
302
|
+
let names;
|
|
303
|
+
try {
|
|
304
|
+
names = await readdir(root);
|
|
305
|
+
} catch {
|
|
306
|
+
return 0;
|
|
307
|
+
}
|
|
308
|
+
let removed = 0;
|
|
309
|
+
for (const name2 of names) {
|
|
310
|
+
if (!name2.endsWith(".json")) continue;
|
|
311
|
+
const path = join(root, name2);
|
|
312
|
+
if ((await stat2(path)).isDirectory()) continue;
|
|
313
|
+
await rm(path, { force: true });
|
|
314
|
+
removed += 1;
|
|
315
|
+
}
|
|
316
|
+
return removed;
|
|
317
|
+
}
|
|
318
|
+
async function pruneDirs(root, now) {
|
|
319
|
+
let removed = await sweepLegacyFiles(root);
|
|
320
|
+
for (const meta of await listMetas(root)) {
|
|
321
|
+
const workspaceRoot = meta.entry.workspaceRoot;
|
|
322
|
+
const gone = await isWorkspaceGone(workspaceRoot);
|
|
323
|
+
if (gone === true) {
|
|
324
|
+
await rm(dirFor(root, workspaceRoot), { recursive: true, force: true });
|
|
325
|
+
removed += 1;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (gone === false && now - meta.entry.fetchedAt > SNAPSHOT_STORE_TTL_MS) {
|
|
329
|
+
await rm(dirFor(root, workspaceRoot), { recursive: true, force: true });
|
|
330
|
+
removed += 1;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const kept = await listMetas(root);
|
|
334
|
+
if (kept.length > SNAPSHOT_STORE_MAX_ENTRIES) {
|
|
335
|
+
const sorted = [...kept].sort((left, right) => left.entry.fetchedAt - right.entry.fetchedAt);
|
|
336
|
+
for (const meta of sorted.slice(0, kept.length - SNAPSHOT_STORE_MAX_ENTRIES)) {
|
|
337
|
+
await rm(dirFor(root, meta.entry.workspaceRoot), { recursive: true, force: true });
|
|
338
|
+
removed += 1;
|
|
306
339
|
}
|
|
340
|
+
}
|
|
341
|
+
return removed;
|
|
342
|
+
}
|
|
343
|
+
async function patchTicketAt(root, workspaceRoot, ref, patch) {
|
|
344
|
+
const dir = dirFor(root, workspaceRoot);
|
|
345
|
+
const meta = await readMetaAt(dir);
|
|
346
|
+
if (meta === void 0) return false;
|
|
347
|
+
const item = meta.manifest.find((entry) => entry.ref === ref);
|
|
348
|
+
if (item === void 0) return false;
|
|
349
|
+
const ticket = await readTicketAt(dir, item);
|
|
350
|
+
if (ticket === void 0) return false;
|
|
351
|
+
const updated = {
|
|
352
|
+
...ticket,
|
|
353
|
+
...patch.labels === void 0 ? {} : { labels: patch.labels },
|
|
354
|
+
...patch.state === void 0 ? {} : { state: patch.state }
|
|
307
355
|
};
|
|
356
|
+
const sha = digest(JSON.stringify(updated));
|
|
357
|
+
await writeAtomic(join(ticketsDirOf(dir), item.file), JSON.stringify(updated));
|
|
358
|
+
await appendLog(dir, meta.entry.libraryVersion + 1, [ref], []);
|
|
359
|
+
await writeMeta(dir, { ...meta.entry, libraryVersion: meta.entry.libraryVersion + 1 }, [
|
|
360
|
+
...meta.manifest.filter((entry) => entry.ref !== ref),
|
|
361
|
+
{ ...item, sha }
|
|
362
|
+
]);
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
async function removeTicketAt(root, workspaceRoot, ref) {
|
|
366
|
+
const dir = dirFor(root, workspaceRoot);
|
|
367
|
+
const meta = await readMetaAt(dir);
|
|
368
|
+
if (meta === void 0) return false;
|
|
369
|
+
if (!meta.manifest.some((entry) => entry.ref === ref)) return false;
|
|
370
|
+
const newVersion = meta.entry.libraryVersion + 1;
|
|
371
|
+
await appendLog(dir, newVersion, [], [ref]);
|
|
372
|
+
await writeAtomic(tombstonesPathOf(dir), JSON.stringify([ref]));
|
|
373
|
+
await writeMeta(
|
|
374
|
+
dir,
|
|
375
|
+
{ ...meta.entry, libraryVersion: newVersion },
|
|
376
|
+
meta.manifest.filter((entry) => entry.ref !== ref)
|
|
377
|
+
);
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
async function changesSinceAt(root, workspaceRoot, afterVersion) {
|
|
381
|
+
const dir = dirFor(root, workspaceRoot);
|
|
382
|
+
const meta = await readMetaAt(dir);
|
|
383
|
+
if (meta === void 0) return void 0;
|
|
384
|
+
if (!Number.isInteger(afterVersion) || afterVersion < 0) return void 0;
|
|
385
|
+
const current = meta.entry.libraryVersion;
|
|
386
|
+
if (afterVersion > current) return void 0;
|
|
387
|
+
if (afterVersion === current) return { version: current, tickets: [], removed: [] };
|
|
388
|
+
const log = await readLogAt(dir);
|
|
389
|
+
if (log === null) return void 0;
|
|
390
|
+
const oldest = log.length === 0 ? current : log[0]?.version ?? current;
|
|
391
|
+
if (afterVersion < oldest - 1) return void 0;
|
|
392
|
+
const upserted = /* @__PURE__ */ new Set();
|
|
393
|
+
const removed = /* @__PURE__ */ new Set();
|
|
394
|
+
for (const entry of log) {
|
|
395
|
+
if (entry.version <= afterVersion) continue;
|
|
396
|
+
for (const ref of entry.upserted) {
|
|
397
|
+
upserted.add(ref);
|
|
398
|
+
removed.delete(ref);
|
|
399
|
+
}
|
|
400
|
+
for (const ref of entry.removed) {
|
|
401
|
+
removed.add(ref);
|
|
402
|
+
upserted.delete(ref);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const byRef = new Map(meta.manifest.map((item) => [item.ref, item]));
|
|
406
|
+
const tickets = [];
|
|
407
|
+
for (const ref of upserted) {
|
|
408
|
+
const item = byRef.get(ref);
|
|
409
|
+
if (item === void 0) return void 0;
|
|
410
|
+
const ticket = await readTicketAt(dir, item);
|
|
411
|
+
if (ticket === void 0) return void 0;
|
|
412
|
+
tickets.push(ticket);
|
|
413
|
+
}
|
|
414
|
+
return { version: current, tickets, removed: [...removed] };
|
|
415
|
+
}
|
|
416
|
+
async function readWorkspace(dir) {
|
|
417
|
+
const meta = await readMetaAt(dir);
|
|
418
|
+
if (meta === void 0) return void 0;
|
|
419
|
+
const tickets = [];
|
|
420
|
+
for (const item of meta.manifest) {
|
|
421
|
+
const ticket = await readTicketAt(dir, item);
|
|
422
|
+
if (ticket === void 0) return void 0;
|
|
423
|
+
tickets.push(ticket);
|
|
424
|
+
}
|
|
425
|
+
return { ...meta.entry, tickets };
|
|
426
|
+
}
|
|
427
|
+
async function commitEntry(dir, entry) {
|
|
428
|
+
const old = await readMetaAt(dir);
|
|
429
|
+
const newVersion = (old?.entry.libraryVersion ?? 0) + 1;
|
|
430
|
+
const previous = new Map((old?.manifest ?? []).map((item) => [item.ref, item]));
|
|
431
|
+
const nextRefs = /* @__PURE__ */ new Set();
|
|
432
|
+
const manifest = [];
|
|
433
|
+
const upserted = [];
|
|
434
|
+
for (const ticket of entry.tickets) {
|
|
435
|
+
const file = ticketFileFor(ticket.ref);
|
|
436
|
+
const sha = digest(JSON.stringify(ticket));
|
|
437
|
+
const prior = previous.get(ticket.ref);
|
|
438
|
+
const unchanged = prior?.sha === sha && prior.file === file && await ticketFileExists(dir, prior.file);
|
|
439
|
+
if (!unchanged) {
|
|
440
|
+
upserted.push({ ref: ticket.ref, file, sha });
|
|
441
|
+
}
|
|
442
|
+
nextRefs.add(ticket.ref);
|
|
443
|
+
manifest.push({ ref: ticket.ref, file, sha });
|
|
444
|
+
}
|
|
445
|
+
const removed = (old?.manifest ?? []).filter((item) => !nextRefs.has(item.ref)).map((item) => item.ref);
|
|
446
|
+
await mkdir(ticketsDirOf(dir), { recursive: true, mode: 448 });
|
|
447
|
+
for (const item of upserted) {
|
|
448
|
+
const ticket = entry.tickets.find((candidate) => candidate.ref === item.ref);
|
|
449
|
+
if (ticket === void 0) continue;
|
|
450
|
+
await writeAtomic(join(ticketsDirOf(dir), item.file), JSON.stringify(ticket));
|
|
451
|
+
}
|
|
452
|
+
if (upserted.length > 0 || removed.length > 0) {
|
|
453
|
+
const log = await readLogAt(dir) ?? [];
|
|
454
|
+
log.push({ version: newVersion, upserted: upserted.map((item) => item.ref), removed });
|
|
455
|
+
while (log.length > SNAPSHOT_CHANGELOG_LIMIT) log.shift();
|
|
456
|
+
await writeAtomic(logPathOf(dir), JSON.stringify(log));
|
|
457
|
+
}
|
|
458
|
+
await writeAtomic(tombstonesPathOf(dir), JSON.stringify(removed));
|
|
459
|
+
const live = new Set(manifest.map((item) => item.file));
|
|
460
|
+
for (const ref of removed) live.add(ticketFileFor(ref));
|
|
461
|
+
await sweepOrphans(dir, live);
|
|
462
|
+
const stored = { ...entry, libraryVersion: newVersion };
|
|
463
|
+
await writeMeta(dir, stored, manifest);
|
|
464
|
+
return newVersion;
|
|
465
|
+
}
|
|
466
|
+
async function readMetaAt(dir) {
|
|
467
|
+
let raw;
|
|
468
|
+
try {
|
|
469
|
+
raw = await readFile(metaPathOf(dir), "utf8");
|
|
470
|
+
} catch {
|
|
471
|
+
return void 0;
|
|
472
|
+
}
|
|
473
|
+
let payload;
|
|
474
|
+
try {
|
|
475
|
+
payload = JSON.parse(raw);
|
|
476
|
+
} catch {
|
|
477
|
+
return void 0;
|
|
478
|
+
}
|
|
479
|
+
if (!isRecord(payload)) return void 0;
|
|
480
|
+
const entry = readSnapshotStoreEntry(payload);
|
|
481
|
+
if (entry === void 0) return void 0;
|
|
482
|
+
const manifest = readManifest(payload.manifest);
|
|
483
|
+
if (manifest === void 0) return void 0;
|
|
484
|
+
return { entry, manifest };
|
|
308
485
|
}
|
|
309
|
-
function
|
|
310
|
-
|
|
486
|
+
function readManifest(value) {
|
|
487
|
+
if (!Array.isArray(value)) return void 0;
|
|
488
|
+
const manifest = [];
|
|
489
|
+
for (const item of value) {
|
|
490
|
+
if (!isRecord(item)) return void 0;
|
|
491
|
+
if (typeof item.ref !== "string" || item.ref.length === 0) return void 0;
|
|
492
|
+
if (typeof item.file !== "string" || item.file.length === 0) return void 0;
|
|
493
|
+
if (typeof item.sha !== "string" || item.sha.length === 0) return void 0;
|
|
494
|
+
manifest.push({ ref: item.ref, file: item.file, sha: item.sha });
|
|
495
|
+
}
|
|
496
|
+
return manifest;
|
|
311
497
|
}
|
|
312
|
-
async function
|
|
498
|
+
async function readTicketAt(dir, item) {
|
|
313
499
|
try {
|
|
314
|
-
|
|
315
|
-
return parseSnapshotStoreEntry(raw);
|
|
500
|
+
return parseSnapshotTicket(await readFile(join(ticketsDirOf(dir), item.file), "utf8"));
|
|
316
501
|
} catch {
|
|
317
502
|
return void 0;
|
|
318
503
|
}
|
|
319
504
|
}
|
|
320
|
-
async function
|
|
321
|
-
|
|
322
|
-
|
|
505
|
+
async function ticketFileExists(dir, file) {
|
|
506
|
+
try {
|
|
507
|
+
await stat2(join(ticketsDirOf(dir), file));
|
|
508
|
+
return true;
|
|
509
|
+
} catch {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async function readLogAt(dir) {
|
|
514
|
+
let raw;
|
|
515
|
+
try {
|
|
516
|
+
raw = await readFile(logPathOf(dir), "utf8");
|
|
517
|
+
} catch {
|
|
518
|
+
return [];
|
|
519
|
+
}
|
|
520
|
+
let payload;
|
|
521
|
+
try {
|
|
522
|
+
payload = JSON.parse(raw);
|
|
523
|
+
} catch {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
if (!Array.isArray(payload)) return null;
|
|
527
|
+
const log = [];
|
|
528
|
+
for (const item of payload) {
|
|
529
|
+
if (!isRecord(item)) return null;
|
|
530
|
+
if (typeof item.version !== "number" || !Number.isInteger(item.version)) return null;
|
|
531
|
+
if (!Array.isArray(item.upserted) || !item.upserted.every((ref) => typeof ref === "string")) {
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
if (!Array.isArray(item.removed) || !item.removed.every((ref) => typeof ref === "string")) {
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
log.push({ version: item.version, upserted: item.upserted, removed: item.removed });
|
|
538
|
+
}
|
|
539
|
+
return log;
|
|
540
|
+
}
|
|
541
|
+
async function appendLog(dir, version, upserted, removed) {
|
|
542
|
+
const log = await readLogAt(dir) ?? [];
|
|
543
|
+
log.push({ version, upserted, removed });
|
|
544
|
+
while (log.length > SNAPSHOT_CHANGELOG_LIMIT) log.shift();
|
|
545
|
+
await writeAtomic(logPathOf(dir), JSON.stringify(log));
|
|
546
|
+
}
|
|
547
|
+
async function writeMeta(dir, entry, manifest) {
|
|
548
|
+
const fields = JSON.parse(serializeSnapshotStoreEntry(entry));
|
|
549
|
+
const payload = { ...fields, manifest };
|
|
550
|
+
await writeAtomic(metaPathOf(dir), JSON.stringify(payload));
|
|
551
|
+
}
|
|
552
|
+
async function sweepOrphans(dir, live) {
|
|
553
|
+
let names;
|
|
554
|
+
try {
|
|
555
|
+
names = await readdir(ticketsDirOf(dir));
|
|
556
|
+
} catch {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
for (const name2 of names) {
|
|
560
|
+
if (!live.has(name2)) await rm(join(ticketsDirOf(dir), name2), { force: true });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
async function writeAtomic(target, content) {
|
|
564
|
+
await mkdir(join(target, ".."), { recursive: true, mode: 448 }).catch(() => void 0);
|
|
323
565
|
const temporary = `${target}.${String(process.pid)}.tmp`;
|
|
324
566
|
try {
|
|
325
|
-
await writeFile(temporary,
|
|
567
|
+
await writeFile(temporary, content, { mode: 384 });
|
|
326
568
|
await rename(temporary, target);
|
|
327
569
|
await chmod(target, 384);
|
|
328
570
|
} catch (error) {
|
|
@@ -330,6 +572,30 @@ async function writeEntryAt(root, entry) {
|
|
|
330
572
|
throw error;
|
|
331
573
|
}
|
|
332
574
|
}
|
|
575
|
+
function digest(content) {
|
|
576
|
+
return createHash("sha1").update(content).digest("hex");
|
|
577
|
+
}
|
|
578
|
+
function dirFor(root, workspaceRoot) {
|
|
579
|
+
return join(root, keyOf(workspaceRoot));
|
|
580
|
+
}
|
|
581
|
+
function keyOf(workspaceRoot) {
|
|
582
|
+
return createHash("sha256").update(workspaceRoot).digest("hex").slice(0, 16);
|
|
583
|
+
}
|
|
584
|
+
function ticketFileFor(ref) {
|
|
585
|
+
return `${createHash("sha256").update(ref).digest("hex").slice(0, 16)}.json`;
|
|
586
|
+
}
|
|
587
|
+
function metaPathOf(dir) {
|
|
588
|
+
return join(dir, "meta.json");
|
|
589
|
+
}
|
|
590
|
+
function ticketsDirOf(dir) {
|
|
591
|
+
return join(dir, "tickets");
|
|
592
|
+
}
|
|
593
|
+
function tombstonesPathOf(dir) {
|
|
594
|
+
return join(dir, "tombstones.json");
|
|
595
|
+
}
|
|
596
|
+
function logPathOf(dir) {
|
|
597
|
+
return join(dir, "log.json");
|
|
598
|
+
}
|
|
333
599
|
async function isWorkspaceGone(workspaceRoot) {
|
|
334
600
|
try {
|
|
335
601
|
await stat2(workspaceRoot);
|
|
@@ -340,9 +606,6 @@ async function isWorkspaceGone(workspaceRoot) {
|
|
|
340
606
|
return false;
|
|
341
607
|
}
|
|
342
608
|
}
|
|
343
|
-
function keyOf(workspaceRoot) {
|
|
344
|
-
return createHash("sha256").update(workspaceRoot).digest("hex").slice(0, 16);
|
|
345
|
-
}
|
|
346
609
|
function resolveRoot(deps, env) {
|
|
347
610
|
if (deps.root !== void 0 && deps.root.length > 0) return deps.root;
|
|
348
611
|
const home = resolveHome(deps, env);
|
|
@@ -517,15 +780,22 @@ function chooseBackend(address, glabHosts, teaHosts = []) {
|
|
|
517
780
|
// src/core/tracker-error.ts
|
|
518
781
|
var TrackerError = class extends Error {
|
|
519
782
|
code;
|
|
783
|
+
/**
|
|
784
|
+
* 服务端要求的重试等待(毫秒);限流类错误才有,
|
|
785
|
+
* 调用方据此决定冷却时长,缺省时按失败次数指数退避。
|
|
786
|
+
*/
|
|
787
|
+
retryAfterMs;
|
|
520
788
|
/**
|
|
521
789
|
* @param code - 客户端可据以给出操作提示的错误码。
|
|
522
790
|
* @param message - 面向用户的失败原因。
|
|
523
791
|
* @param options - 原始错误,保留调用链。
|
|
792
|
+
* @param retryAfterMs - 服务端要求的重试等待(毫秒)。
|
|
524
793
|
*/
|
|
525
|
-
constructor(code, message, options) {
|
|
794
|
+
constructor(code, message, options, retryAfterMs) {
|
|
526
795
|
super(message, options);
|
|
527
796
|
this.name = "TrackerError";
|
|
528
797
|
this.code = code;
|
|
798
|
+
this.retryAfterMs = retryAfterMs;
|
|
529
799
|
}
|
|
530
800
|
};
|
|
531
801
|
var NETWORK_FAILURE = /dial tcp|no such host|i\/o timeout|timeout|network is unreachable|connection refused|connection reset|TLS handshake|proxyconnect|unexpected EOF/i;
|
|
@@ -1614,6 +1884,7 @@ var TRIAGE_LABELS = [
|
|
|
1614
1884
|
var RPC_PATH = "/api/dsh-mattpocock-workflow";
|
|
1615
1885
|
var SNAPSHOT_PAGE_SIZE = 100;
|
|
1616
1886
|
var SNAPSHOT_MAX_WINDOW = 2e3;
|
|
1887
|
+
var SNAPSHOT_DELTA_MAX_ROWS = 1e3;
|
|
1617
1888
|
var RPC_METHODS = {
|
|
1618
1889
|
/** 读缓存;没有缓存时拉取一次。阻塞信息可能尚未定稿。 */
|
|
1619
1890
|
snapshotGet: "snapshot.get",
|
|
@@ -1655,6 +1926,8 @@ var ERROR_CODES = {
|
|
|
1655
1926
|
fetchFailed: "fetch-failed",
|
|
1656
1927
|
/** 编号不存在或工单已被删除。 */
|
|
1657
1928
|
ticketNotFound: "ticket-not-found",
|
|
1929
|
+
/** 后端拒绝了请求(限流);携带服务端要求的重试等待时按它退避。 */
|
|
1930
|
+
rateLimited: "rate-limited",
|
|
1658
1931
|
/** 当前后端不提供所请求的详情或写能力。 */
|
|
1659
1932
|
capabilityUnsupported: "capability-unsupported",
|
|
1660
1933
|
invalidParams: "invalid-params",
|
|
@@ -2159,7 +2432,7 @@ function invalidOptions(message) {
|
|
|
2159
2432
|
|
|
2160
2433
|
// src/adapters/gitea/tracker.ts
|
|
2161
2434
|
var DEFAULT_PAGE_SIZE = 50;
|
|
2162
|
-
var DEFAULT_CONCURRENCY =
|
|
2435
|
+
var DEFAULT_CONCURRENCY = 8;
|
|
2163
2436
|
var MAX_PAGES2 = 200;
|
|
2164
2437
|
function createGiteaTracker(deps) {
|
|
2165
2438
|
const pageSize = normalizePositive(deps.pageSize ?? DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE);
|
|
@@ -2175,23 +2448,12 @@ function createGiteaTracker(deps) {
|
|
|
2175
2448
|
const repository = await readRepository(deps.run, workspaceRoot);
|
|
2176
2449
|
const issues = await readIssues(deps, workspaceRoot, repository, pageSize, void 0, window);
|
|
2177
2450
|
const viewer = await viewerTask;
|
|
2178
|
-
const states =
|
|
2179
|
-
for (const issue of issues.items) {
|
|
2180
|
-
if (issue.ticket.number !== null) states.set(issue.ticket.number, issue.ticket.state);
|
|
2181
|
-
}
|
|
2182
|
-
const native = await readNativeBlockers(
|
|
2183
|
-
deps,
|
|
2184
|
-
workspaceRoot,
|
|
2185
|
-
repository,
|
|
2186
|
-
issues.items,
|
|
2187
|
-
pageSize,
|
|
2188
|
-
concurrency
|
|
2189
|
-
);
|
|
2451
|
+
const states = statesOf(issues.items);
|
|
2190
2452
|
const tickets = issues.items.map((issue) => ({
|
|
2191
2453
|
...issue.ticket,
|
|
2192
2454
|
...resolveOpenBlockers({
|
|
2193
2455
|
ticket: issue.ticket,
|
|
2194
|
-
nativeBlockers:
|
|
2456
|
+
nativeBlockers: void 0,
|
|
2195
2457
|
text: issue.body,
|
|
2196
2458
|
states
|
|
2197
2459
|
})
|
|
@@ -2209,7 +2471,10 @@ function createGiteaTracker(deps) {
|
|
|
2209
2471
|
};
|
|
2210
2472
|
},
|
|
2211
2473
|
async fetchChanges(workspaceRoot, since) {
|
|
2212
|
-
return readGiteaChanges(deps, workspaceRoot, pageSize, since
|
|
2474
|
+
return readGiteaChanges(deps, workspaceRoot, pageSize, since);
|
|
2475
|
+
},
|
|
2476
|
+
async resolveBlockers(workspaceRoot, targets) {
|
|
2477
|
+
return readNativeResolution(deps, workspaceRoot, targets, pageSize, concurrency);
|
|
2213
2478
|
},
|
|
2214
2479
|
fetchDetail: (workspaceRoot, reference) => readGiteaDetail(detailDeps, workspaceRoot, reference),
|
|
2215
2480
|
updateTicket: (workspaceRoot, reference, patch) => applyGiteaChanges(detailDeps, workspaceRoot, reference, patch),
|
|
@@ -2226,7 +2491,7 @@ async function readGiteaTotal(deps, workspaceRoot, repository) {
|
|
|
2226
2491
|
}
|
|
2227
2492
|
return response.total;
|
|
2228
2493
|
}
|
|
2229
|
-
async function readGiteaChanges(deps, workspaceRoot, pageSize, since
|
|
2494
|
+
async function readGiteaChanges(deps, workspaceRoot, pageSize, since) {
|
|
2230
2495
|
if (!Number.isFinite(since)) {
|
|
2231
2496
|
throw new TrackerError("fetch-failed", "\u589E\u91CF\u7A97\u53E3\u7684\u8D77\u70B9\u4E0D\u662F\u6709\u6548\u65F6\u95F4\u6233\u3002");
|
|
2232
2497
|
}
|
|
@@ -2238,23 +2503,12 @@ async function readGiteaChanges(deps, workspaceRoot, pageSize, since, concurrenc
|
|
|
2238
2503
|
const total = await readGiteaTotal(deps, workspaceRoot, repository);
|
|
2239
2504
|
const issues = await readIssues(deps, workspaceRoot, repository, pageSize, since);
|
|
2240
2505
|
const viewer = await viewerTask;
|
|
2241
|
-
const states =
|
|
2242
|
-
for (const issue of issues.items) {
|
|
2243
|
-
if (issue.ticket.number !== null) states.set(issue.ticket.number, issue.ticket.state);
|
|
2244
|
-
}
|
|
2245
|
-
const native = await readNativeBlockers(
|
|
2246
|
-
deps,
|
|
2247
|
-
workspaceRoot,
|
|
2248
|
-
repository,
|
|
2249
|
-
issues.items,
|
|
2250
|
-
pageSize,
|
|
2251
|
-
concurrency
|
|
2252
|
-
);
|
|
2506
|
+
const states = statesOf(issues.items);
|
|
2253
2507
|
const tickets = issues.items.map((issue) => ({
|
|
2254
2508
|
...issue.ticket,
|
|
2255
2509
|
...resolveOpenBlockers({
|
|
2256
2510
|
ticket: issue.ticket,
|
|
2257
|
-
nativeBlockers:
|
|
2511
|
+
nativeBlockers: void 0,
|
|
2258
2512
|
text: issue.body,
|
|
2259
2513
|
states
|
|
2260
2514
|
})
|
|
@@ -2297,27 +2551,44 @@ async function readIssues(deps, workspaceRoot, repository, pageSize, since, wind
|
|
|
2297
2551
|
truncated
|
|
2298
2552
|
};
|
|
2299
2553
|
}
|
|
2300
|
-
async function
|
|
2301
|
-
const open =
|
|
2302
|
-
(
|
|
2554
|
+
async function readNativeResolution(deps, workspaceRoot, targets, pageSize, concurrency) {
|
|
2555
|
+
const open = targets.filter(
|
|
2556
|
+
(target) => target.number !== null
|
|
2303
2557
|
);
|
|
2304
|
-
if (open.length === 0) return
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2558
|
+
if (open.length === 0) return emptyResolution();
|
|
2559
|
+
const repository = await readRepository(deps.run, workspaceRoot);
|
|
2560
|
+
const settled = await mapWithConcurrency(
|
|
2561
|
+
open,
|
|
2562
|
+
concurrency,
|
|
2563
|
+
async (target) => {
|
|
2564
|
+
try {
|
|
2565
|
+
const blocked2 = await readDependencies(
|
|
2566
|
+
deps,
|
|
2567
|
+
workspaceRoot,
|
|
2568
|
+
repository,
|
|
2569
|
+
target.number,
|
|
2570
|
+
pageSize
|
|
2571
|
+
);
|
|
2572
|
+
return { ref: target.ref, outcome: "ok", blocked: blocked2 };
|
|
2573
|
+
} catch (error) {
|
|
2574
|
+
if (error instanceof DependenciesUnavailable) {
|
|
2575
|
+
return { ref: target.ref, outcome: "unavailable" };
|
|
2576
|
+
}
|
|
2577
|
+
return { ref: target.ref, outcome: "failed" };
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
);
|
|
2581
|
+
if (settled.some((entry) => entry.outcome === "unavailable")) return emptyResolution();
|
|
2582
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2583
|
+
const blockedBy = /* @__PURE__ */ new Map();
|
|
2584
|
+
for (const entry of settled) {
|
|
2585
|
+
if (entry.outcome !== "ok") continue;
|
|
2586
|
+
counts.set(entry.ref, entry.blocked.open);
|
|
2587
|
+
if (entry.blocked.refs.length > 0) {
|
|
2588
|
+
blockedBy.set(entry.ref, remoteBlockerRefs(entry.blocked.refs));
|
|
2589
|
+
}
|
|
2320
2590
|
}
|
|
2591
|
+
return { open: counts, blockedBy };
|
|
2321
2592
|
}
|
|
2322
2593
|
async function readDependencies(deps, workspaceRoot, repository, index, pageSize) {
|
|
2323
2594
|
let open = 0;
|
|
@@ -2344,6 +2615,16 @@ async function readDependencies(deps, workspaceRoot, repository, index, pageSize
|
|
|
2344
2615
|
}
|
|
2345
2616
|
var DependenciesUnavailable = class extends Error {
|
|
2346
2617
|
};
|
|
2618
|
+
function emptyResolution() {
|
|
2619
|
+
return { open: /* @__PURE__ */ new Map(), blockedBy: /* @__PURE__ */ new Map() };
|
|
2620
|
+
}
|
|
2621
|
+
function statesOf(issues) {
|
|
2622
|
+
const states = /* @__PURE__ */ new Map();
|
|
2623
|
+
for (const issue of issues) {
|
|
2624
|
+
if (issue.ticket.number !== null) states.set(issue.ticket.number, issue.ticket.state);
|
|
2625
|
+
}
|
|
2626
|
+
return states;
|
|
2627
|
+
}
|
|
2347
2628
|
function issuesEndpoint(repository, pageSize, page, since) {
|
|
2348
2629
|
const window = since === void 0 ? "" : `&since=${new Date(since).toISOString()}`;
|
|
2349
2630
|
return `/repos/${repository.owner}/${repository.name}/issues?state=all&type=issues&sort=recentupdate&page=${String(page)}&limit=${String(pageSize)}${window}`;
|
|
@@ -2415,6 +2696,15 @@ function mapGhError(error) {
|
|
|
2415
2696
|
cause: error
|
|
2416
2697
|
});
|
|
2417
2698
|
}
|
|
2699
|
+
const rateLimit = rateLimitOf(error.stderr);
|
|
2700
|
+
if (rateLimit !== null) {
|
|
2701
|
+
return new TrackerError(
|
|
2702
|
+
"rate-limited",
|
|
2703
|
+
`GitHub \u9650\u6D41\u4E2D\uFF0C\u7A0D\u540E\u4F1A\u81EA\u52A8\u6062\u590D\uFF1A${rateLimit}`,
|
|
2704
|
+
{ cause: error },
|
|
2705
|
+
retryAfterMsOf(error.stderr)
|
|
2706
|
+
);
|
|
2707
|
+
}
|
|
2418
2708
|
return new TrackerError("fetch-failed", `\u8BFB\u53D6\u5DE5\u5355\u5931\u8D25\uFF1A${commandFailureDetail(error)}`, {
|
|
2419
2709
|
cause: error
|
|
2420
2710
|
});
|
|
@@ -2426,6 +2716,18 @@ function isAuthenticationFailure(stderr) {
|
|
|
2426
2716
|
stderr
|
|
2427
2717
|
);
|
|
2428
2718
|
}
|
|
2719
|
+
var RATE_LIMITED = /rate limit|too many requests|HTTP 429/i;
|
|
2720
|
+
function rateLimitOf(stderr) {
|
|
2721
|
+
if (!RATE_LIMITED.test(stderr)) return null;
|
|
2722
|
+
const firstLine = stderr.split("\n").map((line) => line.trim()).find((line) => line.length > 0);
|
|
2723
|
+
return firstLine ?? "\u5DF2\u89E6\u53D1\u9650\u6D41\u3002";
|
|
2724
|
+
}
|
|
2725
|
+
function retryAfterMsOf(stderr) {
|
|
2726
|
+
const match = /retry[ -]?after[^0-9]*(\d{1,4})\s*s?\b/i.exec(stderr);
|
|
2727
|
+
if (match === null) return void 0;
|
|
2728
|
+
const seconds = Number(match[1]);
|
|
2729
|
+
return Number.isFinite(seconds) && seconds > 0 ? seconds * 1e3 : void 0;
|
|
2730
|
+
}
|
|
2429
2731
|
|
|
2430
2732
|
// src/adapters/github/delete.ts
|
|
2431
2733
|
var NOT_FOUND4 = /Could not resolve to an Issue|HTTP 404|404 Not Found|Not Found/i;
|
|
@@ -2625,6 +2927,15 @@ function parseIssueGraphql(output, repository) {
|
|
|
2625
2927
|
}
|
|
2626
2928
|
return { total, tickets, viewer: readViewer2(payload), ...readPageCursor(issues) };
|
|
2627
2929
|
}
|
|
2930
|
+
function parseIssuesTotal(output) {
|
|
2931
|
+
const payload = parseJson6(output, "gh \u8FD4\u56DE\u7684\u4E0D\u662F\u6709\u6548 JSON");
|
|
2932
|
+
const issues = readIssues2(readRepository3(payload));
|
|
2933
|
+
const total = issues.totalCount;
|
|
2934
|
+
if (typeof total !== "number" || !Number.isInteger(total) || total < 0) {
|
|
2935
|
+
throw invalid3("\u4ED3\u5E93\u7684 issues.totalCount \u4E0D\u662F\u975E\u8D1F\u6574\u6570");
|
|
2936
|
+
}
|
|
2937
|
+
return total;
|
|
2938
|
+
}
|
|
2628
2939
|
function readViewer2(payload) {
|
|
2629
2940
|
if (!isRecord(payload)) return null;
|
|
2630
2941
|
const data = payload.data;
|
|
@@ -2844,6 +3155,7 @@ function invalidOptions2(message) {
|
|
|
2844
3155
|
|
|
2845
3156
|
// src/adapters/github/tracker.ts
|
|
2846
3157
|
var DEFAULT_LIMIT = 100;
|
|
3158
|
+
var DEFAULT_CHANGES_PAGE_LIMIT = 5;
|
|
2847
3159
|
var ISSUE_NODES = `nodes {
|
|
2848
3160
|
number
|
|
2849
3161
|
title
|
|
@@ -2869,6 +3181,22 @@ var ISSUE_QUERY = `query ($owner: String!, $name: String!, $limit: Int!, $after:
|
|
|
2869
3181
|
}
|
|
2870
3182
|
}
|
|
2871
3183
|
}`;
|
|
3184
|
+
var ISSUE_CHANGES_QUERY = `query ($owner: String!, $name: String!, $limit: Int!, $after: String, $since: DateTime!) {
|
|
3185
|
+
viewer { login }
|
|
3186
|
+
repository(owner: $owner, name: $name) {
|
|
3187
|
+
nameWithOwner
|
|
3188
|
+
issues(first: $limit, after: $after, orderBy: { field: UPDATED_AT, direction: DESC }, filterBy: { since: $since }) {
|
|
3189
|
+
totalCount
|
|
3190
|
+
pageInfo { hasNextPage endCursor }
|
|
3191
|
+
${ISSUE_NODES}
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
}`;
|
|
3195
|
+
var ISSUE_TOTAL_QUERY = `query ($owner: String!, $name: String!) {
|
|
3196
|
+
repository(owner: $owner, name: $name) {
|
|
3197
|
+
issues(first: 1) { totalCount }
|
|
3198
|
+
}
|
|
3199
|
+
}`;
|
|
2872
3200
|
function createGithubTracker(deps) {
|
|
2873
3201
|
const limit = normalizeLimit(deps.limit ?? DEFAULT_LIMIT);
|
|
2874
3202
|
return {
|
|
@@ -2889,6 +3217,21 @@ function createGithubTracker(deps) {
|
|
|
2889
3217
|
windowLimit: window
|
|
2890
3218
|
};
|
|
2891
3219
|
},
|
|
3220
|
+
async fetchChanges(workspaceRoot, since) {
|
|
3221
|
+
if (!Number.isFinite(since)) {
|
|
3222
|
+
throw new TrackerError("fetch-failed", "\u589E\u91CF\u7A97\u53E3\u7684\u8D77\u70B9\u4E0D\u662F\u6709\u6548\u65F6\u95F4\u6233\u3002");
|
|
3223
|
+
}
|
|
3224
|
+
const repository = await readRepository2(deps.run, workspaceRoot);
|
|
3225
|
+
const total = await readIssuesTotal(deps, workspaceRoot, repository);
|
|
3226
|
+
const changed = await readChangedTickets(deps, workspaceRoot, repository, limit, since);
|
|
3227
|
+
return {
|
|
3228
|
+
tickets: changed.tickets,
|
|
3229
|
+
hierarchy: "native",
|
|
3230
|
+
truncated: changed.truncated,
|
|
3231
|
+
total,
|
|
3232
|
+
viewer: changed.viewer
|
|
3233
|
+
};
|
|
3234
|
+
},
|
|
2892
3235
|
fetchDetail: (workspaceRoot, reference) => readGithubDetail(deps, workspaceRoot, reference),
|
|
2893
3236
|
updateTicket: (workspaceRoot, reference, patch) => applyGithubChanges(deps, workspaceRoot, reference, patch),
|
|
2894
3237
|
fetchOptions: (workspaceRoot) => readGithubOptions(deps, workspaceRoot),
|
|
@@ -2920,6 +3263,55 @@ async function readTickets2(deps, workspaceRoot, repository, pageSize, window) {
|
|
|
2920
3263
|
const windowed = tickets.slice(0, window);
|
|
2921
3264
|
return { total, tickets: windowed, viewer, hasNextPage: false, endCursor: null };
|
|
2922
3265
|
}
|
|
3266
|
+
async function readIssuesTotal(deps, workspaceRoot, repository) {
|
|
3267
|
+
const args = [
|
|
3268
|
+
"api",
|
|
3269
|
+
"graphql",
|
|
3270
|
+
"-f",
|
|
3271
|
+
`query=${ISSUE_TOTAL_QUERY}`,
|
|
3272
|
+
"-f",
|
|
3273
|
+
`owner=${repository.owner}`,
|
|
3274
|
+
"-f",
|
|
3275
|
+
`name=${repository.name}`
|
|
3276
|
+
];
|
|
3277
|
+
return parseIssuesTotal(await callGh(deps.run, workspaceRoot, args));
|
|
3278
|
+
}
|
|
3279
|
+
async function readChangedTickets(deps, workspaceRoot, repository, pageSize, since) {
|
|
3280
|
+
const tickets = [];
|
|
3281
|
+
let viewer = null;
|
|
3282
|
+
let cursor = null;
|
|
3283
|
+
for (let page = 1; page <= DEFAULT_CHANGES_PAGE_LIMIT; page += 1) {
|
|
3284
|
+
const parsed = await readChangesPage(deps, workspaceRoot, repository, pageSize, cursor, since);
|
|
3285
|
+
viewer = parsed.viewer ?? viewer;
|
|
3286
|
+
tickets.push(...parsed.tickets);
|
|
3287
|
+
if (!parsed.hasNextPage || parsed.endCursor === null || parsed.tickets.length === 0) {
|
|
3288
|
+
return { tickets, viewer, truncated: false };
|
|
3289
|
+
}
|
|
3290
|
+
cursor = parsed.endCursor;
|
|
3291
|
+
if (page === DEFAULT_CHANGES_PAGE_LIMIT) {
|
|
3292
|
+
return { tickets, viewer, truncated: true };
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
return { tickets, viewer, truncated: false };
|
|
3296
|
+
}
|
|
3297
|
+
async function readChangesPage(deps, workspaceRoot, repository, limit, after, since) {
|
|
3298
|
+
const args = [
|
|
3299
|
+
"api",
|
|
3300
|
+
"graphql",
|
|
3301
|
+
"-f",
|
|
3302
|
+
`query=${ISSUE_CHANGES_QUERY}`,
|
|
3303
|
+
"-f",
|
|
3304
|
+
`owner=${repository.owner}`,
|
|
3305
|
+
"-f",
|
|
3306
|
+
`name=${repository.name}`,
|
|
3307
|
+
"-F",
|
|
3308
|
+
`limit=${String(limit)}`,
|
|
3309
|
+
"-f",
|
|
3310
|
+
`since=${new Date(since).toISOString()}`,
|
|
3311
|
+
...after === null ? [] : ["-f", `after=${after}`]
|
|
3312
|
+
];
|
|
3313
|
+
return parseIssueGraphql(await callGh(deps.run, workspaceRoot, args), repositoryLabel(repository));
|
|
3314
|
+
}
|
|
2923
3315
|
async function readTicketsPage(deps, workspaceRoot, repository, limit, after) {
|
|
2924
3316
|
const args = [
|
|
2925
3317
|
"api",
|
|
@@ -3479,7 +3871,7 @@ function createGitlabTracker(deps) {
|
|
|
3479
3871
|
const open = targets.filter(
|
|
3480
3872
|
(target) => target.number !== null
|
|
3481
3873
|
);
|
|
3482
|
-
if (open.length === 0) return
|
|
3874
|
+
if (open.length === 0) return emptyResolution2();
|
|
3483
3875
|
const hint = hints.get(workspaceRoot) ?? {
|
|
3484
3876
|
project: await readProjectAddress(deps.run, workspaceRoot),
|
|
3485
3877
|
listSupportsNative: false,
|
|
@@ -3492,7 +3884,7 @@ function createGitlabTracker(deps) {
|
|
|
3492
3884
|
hint,
|
|
3493
3885
|
open
|
|
3494
3886
|
);
|
|
3495
|
-
if (!supported) return
|
|
3887
|
+
if (!supported) return emptyResolution2();
|
|
3496
3888
|
const counts = await readBlockedByCounts(deps, workspaceRoot, hint.project.path, open);
|
|
3497
3889
|
const native = /* @__PURE__ */ new Map();
|
|
3498
3890
|
for (const target of open) {
|
|
@@ -3517,7 +3909,7 @@ function createGitlabTracker(deps) {
|
|
|
3517
3909
|
fetchAttachment: (workspaceRoot, path) => readGitlabAttachment(deps, workspaceRoot, path)
|
|
3518
3910
|
};
|
|
3519
3911
|
}
|
|
3520
|
-
function
|
|
3912
|
+
function emptyResolution2() {
|
|
3521
3913
|
return { open: /* @__PURE__ */ new Map(), blockedBy: /* @__PURE__ */ new Map() };
|
|
3522
3914
|
}
|
|
3523
3915
|
async function readSnapshot(deps, hints, workspaceRoot, pageSize, windowLimit) {
|
|
@@ -4223,9 +4615,13 @@ var TICKET_ACTIONS = {
|
|
|
4223
4615
|
|
|
4224
4616
|
// src/host/env-check-service.ts
|
|
4225
4617
|
var TRACKER_DOC = "docs/agents/issue-tracker.md";
|
|
4618
|
+
var ENV_CHECK_CACHE_TTL_MS = 10 * 60 * 1e3;
|
|
4619
|
+
var ENV_CHECK_BACKOFF_START_MS = 8e3;
|
|
4620
|
+
var ENV_CHECK_BACKOFF_MAX_MS = 5 * 60 * 1e3;
|
|
4226
4621
|
var SKILL_DIRECTORIES = [".dsh/skills", ".agents/skills"];
|
|
4227
4622
|
function createEnvCheckService(deps) {
|
|
4228
4623
|
const pending = /* @__PURE__ */ new Map();
|
|
4624
|
+
const cache = /* @__PURE__ */ new Map();
|
|
4229
4625
|
return {
|
|
4230
4626
|
handle(method, params) {
|
|
4231
4627
|
if (method !== RPC_METHODS.envCheck) {
|
|
@@ -4239,7 +4635,38 @@ function createEnvCheckService(deps) {
|
|
|
4239
4635
|
}
|
|
4240
4636
|
const running = pending.get(workspaceRoot);
|
|
4241
4637
|
if (running !== void 0) return running;
|
|
4242
|
-
const
|
|
4638
|
+
const now = deps.now();
|
|
4639
|
+
const state = cache.get(workspaceRoot);
|
|
4640
|
+
const cached = state?.success;
|
|
4641
|
+
if (cached !== void 0 && cached !== null && now < cached.expiresAt) {
|
|
4642
|
+
const task2 = serveCached(deps, workspaceRoot, cached).then((outcome) => {
|
|
4643
|
+
cache.set(workspaceRoot, nextCacheState(state, outcome, deps.now()));
|
|
4644
|
+
return outcome.result;
|
|
4645
|
+
});
|
|
4646
|
+
pending.set(workspaceRoot, task2);
|
|
4647
|
+
void task2.then(
|
|
4648
|
+
() => {
|
|
4649
|
+
pending.delete(workspaceRoot);
|
|
4650
|
+
},
|
|
4651
|
+
() => {
|
|
4652
|
+
pending.delete(workspaceRoot);
|
|
4653
|
+
}
|
|
4654
|
+
);
|
|
4655
|
+
return task2;
|
|
4656
|
+
}
|
|
4657
|
+
if (state !== void 0 && state.failures > 0 && state.lastFailure !== null) {
|
|
4658
|
+
const backoff = Math.min(
|
|
4659
|
+
ENV_CHECK_BACKOFF_START_MS * 2 ** (state.failures - 1),
|
|
4660
|
+
ENV_CHECK_BACKOFF_MAX_MS
|
|
4661
|
+
);
|
|
4662
|
+
if (now - state.lastRunAt < backoff) {
|
|
4663
|
+
return Promise.resolve({ ok: true, result: state.lastFailure });
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
const task = runCheck(deps, workspaceRoot).then((outcome) => {
|
|
4667
|
+
cache.set(workspaceRoot, nextCacheState(state, outcome, deps.now()));
|
|
4668
|
+
return outcome.result;
|
|
4669
|
+
});
|
|
4243
4670
|
pending.set(workspaceRoot, task);
|
|
4244
4671
|
void task.then(
|
|
4245
4672
|
() => {
|
|
@@ -4253,6 +4680,41 @@ function createEnvCheckService(deps) {
|
|
|
4253
4680
|
}
|
|
4254
4681
|
};
|
|
4255
4682
|
}
|
|
4683
|
+
async function serveCached(deps, workspaceRoot, cached) {
|
|
4684
|
+
const probe = await probeBackend(deps, workspaceRoot);
|
|
4685
|
+
const identity = identityOf(probe);
|
|
4686
|
+
if (identity !== null && identity === cached.identity) {
|
|
4687
|
+
return { result: { ok: true, result: cached.report }, identity: cached.identity };
|
|
4688
|
+
}
|
|
4689
|
+
return runCheck(deps, workspaceRoot);
|
|
4690
|
+
}
|
|
4691
|
+
function nextCacheState(previous, outcome, now) {
|
|
4692
|
+
const report = outcome.result.ok ? outcome.result.result : null;
|
|
4693
|
+
if (report === null) return previous ?? emptyCache(now);
|
|
4694
|
+
const failed = report.items.some((item) => item.status === "fail");
|
|
4695
|
+
if (!failed) {
|
|
4696
|
+
return {
|
|
4697
|
+
success: outcome.identity === null ? null : { report, identity: outcome.identity, expiresAt: now + ENV_CHECK_CACHE_TTL_MS },
|
|
4698
|
+
failures: 0,
|
|
4699
|
+
lastRunAt: now,
|
|
4700
|
+
lastFailure: null
|
|
4701
|
+
};
|
|
4702
|
+
}
|
|
4703
|
+
return {
|
|
4704
|
+
success: previous?.success ?? null,
|
|
4705
|
+
failures: (previous?.failures ?? 0) + 1,
|
|
4706
|
+
lastRunAt: now,
|
|
4707
|
+
lastFailure: report
|
|
4708
|
+
};
|
|
4709
|
+
}
|
|
4710
|
+
function emptyCache(now) {
|
|
4711
|
+
return { success: null, failures: 0, lastRunAt: now, lastFailure: null };
|
|
4712
|
+
}
|
|
4713
|
+
function identityOf(probe) {
|
|
4714
|
+
if (probe.outcome.status !== "pass") return null;
|
|
4715
|
+
const kind = probe.outcome.choice.kind;
|
|
4716
|
+
return `${kind}@${kind === "markdown" ? "" : probe.remote?.path ?? ""}`;
|
|
4717
|
+
}
|
|
4256
4718
|
async function runCheck(deps, workspaceRoot) {
|
|
4257
4719
|
const startedAt = deps.now();
|
|
4258
4720
|
try {
|
|
@@ -4266,13 +4728,16 @@ async function runCheck(deps, workspaceRoot) {
|
|
|
4266
4728
|
capabilities: deps.capabilities()
|
|
4267
4729
|
};
|
|
4268
4730
|
logSummary(deps, report, startedAt);
|
|
4269
|
-
return { ok: true, result: report };
|
|
4731
|
+
return { result: { ok: true, result: report }, identity: collected.identity };
|
|
4270
4732
|
} catch {
|
|
4271
4733
|
deps.log("warn", LOG_EVENTS.envCheck, {
|
|
4272
4734
|
result: "error",
|
|
4273
4735
|
durationMs: Math.max(0, deps.now() - startedAt)
|
|
4274
4736
|
});
|
|
4275
|
-
return
|
|
4737
|
+
return {
|
|
4738
|
+
result: failure(ERROR_CODES.internal, "\u73AF\u5883\u68C0\u67E5\u65F6\u53D1\u751F\u672A\u9884\u671F\u7684\u9519\u8BEF\u3002"),
|
|
4739
|
+
identity: null
|
|
4740
|
+
};
|
|
4276
4741
|
}
|
|
4277
4742
|
}
|
|
4278
4743
|
async function collectFacts(deps, workspaceRoot) {
|
|
@@ -4300,7 +4765,8 @@ async function collectFacts(deps, workspaceRoot) {
|
|
|
4300
4765
|
skills,
|
|
4301
4766
|
setupSkill: PANEL_SKILLS.setup
|
|
4302
4767
|
},
|
|
4303
|
-
repository: decided === null || decided === "markdown" ? null : backend.remote?.path ?? null
|
|
4768
|
+
repository: decided === null || decided === "markdown" ? null : backend.remote?.path ?? null,
|
|
4769
|
+
identity: identityOf(backend)
|
|
4304
4770
|
};
|
|
4305
4771
|
}
|
|
4306
4772
|
async function probeLocalIssues(deps, workspaceRoot) {
|
|
@@ -4578,62 +5044,15 @@ function classifyTickets(tickets, names) {
|
|
|
4578
5044
|
}));
|
|
4579
5045
|
}
|
|
4580
5046
|
|
|
4581
|
-
// src/core/
|
|
4582
|
-
function
|
|
4583
|
-
const
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
const at = positions.get(change.ref);
|
|
4591
|
-
if (at === void 0) {
|
|
4592
|
-
positions.set(change.ref, merged.length);
|
|
4593
|
-
merged.push(change);
|
|
4594
|
-
continue;
|
|
4595
|
-
}
|
|
4596
|
-
const existing = merged[at];
|
|
4597
|
-
if (existing !== void 0 && isNewer(change, existing)) merged[at] = change;
|
|
4598
|
-
}
|
|
4599
|
-
if (windowLimit === void 0) return merged;
|
|
4600
|
-
return trimToWindow(merged, windowLimit);
|
|
4601
|
-
}
|
|
4602
|
-
function isNewer(candidate, current) {
|
|
4603
|
-
const left = timestamp(candidate.updatedAt);
|
|
4604
|
-
const right = timestamp(current.updatedAt);
|
|
4605
|
-
if (left === void 0 || right === void 0) return candidate.updatedAt >= current.updatedAt;
|
|
4606
|
-
return left >= right;
|
|
4607
|
-
}
|
|
4608
|
-
function timestamp(value) {
|
|
4609
|
-
const parsed = Date.parse(value);
|
|
4610
|
-
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
4611
|
-
}
|
|
4612
|
-
function trimToWindow(tickets, limit) {
|
|
4613
|
-
if (tickets.length <= limit) return [...tickets];
|
|
4614
|
-
const sorted = [...tickets].sort((left, right) => {
|
|
4615
|
-
const byTime = compareTime(left.updatedAt, right.updatedAt);
|
|
4616
|
-
if (byTime !== 0) return byTime;
|
|
4617
|
-
return left.ref.localeCompare(right.ref);
|
|
4618
|
-
});
|
|
4619
|
-
return sorted.slice(0, limit);
|
|
4620
|
-
}
|
|
4621
|
-
function compareTime(left, right) {
|
|
4622
|
-
const leftTime = timestamp(left);
|
|
4623
|
-
const rightTime = timestamp(right);
|
|
4624
|
-
if (leftTime === void 0 || rightTime === void 0) return right.localeCompare(left);
|
|
4625
|
-
return rightTime - leftTime;
|
|
4626
|
-
}
|
|
4627
|
-
|
|
4628
|
-
// src/core/skill-action.ts
|
|
4629
|
-
function decideSkillAction(ticket, names) {
|
|
4630
|
-
const status = classify(ticket, names);
|
|
4631
|
-
if (status === "closed") return blocked("closed");
|
|
4632
|
-
if (status === "blocked") return blocked("blocked");
|
|
4633
|
-
if (ticket.labels.includes(names.wontfix)) return blocked("wontfix");
|
|
4634
|
-
if (ticket.labels.includes(names.readyForHuman)) return blocked("ready-for-human");
|
|
4635
|
-
if (ticket.labels.includes(names.needsTriage)) {
|
|
4636
|
-
return { skillAction: "triage", skillActionReason: "needs-triage" };
|
|
5047
|
+
// src/core/skill-action.ts
|
|
5048
|
+
function decideSkillAction(ticket, names) {
|
|
5049
|
+
const status = classify(ticket, names);
|
|
5050
|
+
if (status === "closed") return blocked("closed");
|
|
5051
|
+
if (status === "blocked") return blocked("blocked");
|
|
5052
|
+
if (ticket.labels.includes(names.wontfix)) return blocked("wontfix");
|
|
5053
|
+
if (ticket.labels.includes(names.readyForHuman)) return blocked("ready-for-human");
|
|
5054
|
+
if (ticket.labels.includes(names.needsTriage)) {
|
|
5055
|
+
return { skillAction: "triage", skillActionReason: "needs-triage" };
|
|
4637
5056
|
}
|
|
4638
5057
|
if (ticket.labels.includes(names.needsInfo)) {
|
|
4639
5058
|
return { skillAction: "triage", skillActionReason: "needs-info" };
|
|
@@ -4650,6 +5069,45 @@ function blocked(reason) {
|
|
|
4650
5069
|
return { skillAction: "none", skillActionReason: reason };
|
|
4651
5070
|
}
|
|
4652
5071
|
|
|
5072
|
+
// src/host/refresh-guard.ts
|
|
5073
|
+
function createRefreshGuard(options = {}) {
|
|
5074
|
+
const baseMs = options.baseMs ?? 5e3;
|
|
5075
|
+
const maxMs = options.maxMs ?? 3e5;
|
|
5076
|
+
const states = /* @__PURE__ */ new Map();
|
|
5077
|
+
function stateOf(workspaceRoot) {
|
|
5078
|
+
let state = states.get(workspaceRoot);
|
|
5079
|
+
if (state === void 0) {
|
|
5080
|
+
state = { failuresSinceSuccess: 0, coolingUntil: 0 };
|
|
5081
|
+
states.set(workspaceRoot, state);
|
|
5082
|
+
}
|
|
5083
|
+
return state;
|
|
5084
|
+
}
|
|
5085
|
+
return {
|
|
5086
|
+
blockedUntil(workspaceRoot, at) {
|
|
5087
|
+
const state = states.get(workspaceRoot);
|
|
5088
|
+
if (state === void 0 || state.coolingUntil <= at) return null;
|
|
5089
|
+
return state.coolingUntil;
|
|
5090
|
+
},
|
|
5091
|
+
noteSuccess(workspaceRoot) {
|
|
5092
|
+
const state = stateOf(workspaceRoot);
|
|
5093
|
+
state.failuresSinceSuccess = 0;
|
|
5094
|
+
state.coolingUntil = 0;
|
|
5095
|
+
},
|
|
5096
|
+
noteFailure(workspaceRoot, at, retryAfterMs) {
|
|
5097
|
+
const state = stateOf(workspaceRoot);
|
|
5098
|
+
state.failuresSinceSuccess += 1;
|
|
5099
|
+
const backoffMs = Math.min(baseMs * 2 ** Math.min(state.failuresSinceSuccess - 1, 16), maxMs);
|
|
5100
|
+
const waitMs = retryAfterMs !== void 0 && retryAfterMs > 0 ? Math.min(retryAfterMs, maxMs) : backoffMs;
|
|
5101
|
+
state.coolingUntil = at + waitMs;
|
|
5102
|
+
return state.coolingUntil;
|
|
5103
|
+
},
|
|
5104
|
+
view(workspaceRoot) {
|
|
5105
|
+
const state = states.get(workspaceRoot);
|
|
5106
|
+
return state === void 0 ? { failuresSinceSuccess: 0, coolingUntil: 0 } : { ...state };
|
|
5107
|
+
}
|
|
5108
|
+
};
|
|
5109
|
+
}
|
|
5110
|
+
|
|
4653
5111
|
// src/host/rpc-params.ts
|
|
4654
5112
|
function readWorkspaceRoot2(params) {
|
|
4655
5113
|
if (typeof params !== "object" || params === null) return void 0;
|
|
@@ -4673,65 +5131,64 @@ function readTicketParams(params) {
|
|
|
4673
5131
|
|
|
4674
5132
|
// src/host/snapshot-error.ts
|
|
4675
5133
|
function mapSnapshotError(error) {
|
|
4676
|
-
if (error instanceof TrackerError)
|
|
5134
|
+
if (error instanceof TrackerError) {
|
|
5135
|
+
return {
|
|
5136
|
+
code: error.code,
|
|
5137
|
+
message: error.message,
|
|
5138
|
+
...error.retryAfterMs !== void 0 ? { retryAfterMs: error.retryAfterMs } : {}
|
|
5139
|
+
};
|
|
5140
|
+
}
|
|
4677
5141
|
return { code: ERROR_CODES.internal, message: "\u8BFB\u53D6\u5DE5\u5355\u65F6\u53D1\u751F\u672A\u9884\u671F\u7684\u9519\u8BEF\u3002" };
|
|
4678
5142
|
}
|
|
4679
5143
|
function snapshotFailure(code, message) {
|
|
4680
5144
|
return { ok: false, error: { code, message } };
|
|
4681
5145
|
}
|
|
4682
5146
|
|
|
4683
|
-
// src/
|
|
4684
|
-
function
|
|
4685
|
-
const
|
|
4686
|
-
const
|
|
4687
|
-
const
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
function mergePulled(current, raw) {
|
|
4691
|
-
if (current === void 0) return raw;
|
|
4692
|
-
if (current.raw.repository !== raw.repository) return raw;
|
|
4693
|
-
const existingWindow = current.raw.windowLimit ?? current.raw.tickets.length;
|
|
4694
|
-
const pulledWindow = raw.windowLimit ?? raw.tickets.length;
|
|
4695
|
-
const window = Math.max(existingWindow, pulledWindow);
|
|
4696
|
-
const shrunk = raw.tickets.length < current.raw.tickets.length;
|
|
4697
|
-
if (!shrunk && window <= pulledWindow) return raw;
|
|
4698
|
-
const tickets = mergeTickets(current.raw.tickets, raw.tickets, window);
|
|
4699
|
-
return { ...raw, loaded: tickets.length, tickets, windowLimit: window };
|
|
4700
|
-
}
|
|
4701
|
-
async function loadMore(host, workspaceRoot) {
|
|
4702
|
-
const initial = await host.getSnapshot(workspaceRoot);
|
|
4703
|
-
if (!initial.ok) return initial;
|
|
4704
|
-
const entry = host.cache.get(workspaceRoot);
|
|
4705
|
-
if (entry === void 0) return initial;
|
|
4706
|
-
const windowLimit = entry.raw.windowLimit ?? SNAPSHOT_PAGE_SIZE;
|
|
4707
|
-
if (entry.raw.tickets.length >= entry.raw.total || windowLimit >= SNAPSHOT_MAX_WINDOW) {
|
|
4708
|
-
return { ok: true, result: entry.snapshot };
|
|
5147
|
+
// src/core/merge.ts
|
|
5148
|
+
function mergeTickets(base, changes, windowLimit) {
|
|
5149
|
+
const positions = /* @__PURE__ */ new Map();
|
|
5150
|
+
const merged = [];
|
|
5151
|
+
for (const ticket of base) {
|
|
5152
|
+
if (!positions.has(ticket.ref)) positions.set(ticket.ref, merged.length);
|
|
5153
|
+
merged.push(ticket);
|
|
4709
5154
|
}
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
const
|
|
4718
|
-
|
|
4719
|
-
workspaceRoot,
|
|
4720
|
-
resolved,
|
|
4721
|
-
{ ...raw, viewer, windowLimit: nextWindow },
|
|
4722
|
-
startedAt
|
|
4723
|
-
);
|
|
4724
|
-
} catch (error) {
|
|
4725
|
-
const mapped = mapSnapshotError(error);
|
|
4726
|
-
host.log("warn", LOG_EVENTS.snapshot, {
|
|
4727
|
-
result: "error",
|
|
4728
|
-
...kind === void 0 ? {} : { backend: kind },
|
|
4729
|
-
stage: SNAPSHOT_STAGES.list,
|
|
4730
|
-
code: mapped.code,
|
|
4731
|
-
durationMs: Math.max(0, host.now() - startedAt)
|
|
4732
|
-
});
|
|
4733
|
-
return snapshotFailure(mapped.code, mapped.message);
|
|
5155
|
+
for (const change of changes) {
|
|
5156
|
+
const at = positions.get(change.ref);
|
|
5157
|
+
if (at === void 0) {
|
|
5158
|
+
positions.set(change.ref, merged.length);
|
|
5159
|
+
merged.push(change);
|
|
5160
|
+
continue;
|
|
5161
|
+
}
|
|
5162
|
+
const existing = merged[at];
|
|
5163
|
+
if (existing !== void 0 && isNewer(change, existing)) merged[at] = change;
|
|
4734
5164
|
}
|
|
5165
|
+
if (windowLimit === void 0) return merged;
|
|
5166
|
+
return trimToWindow(merged, windowLimit);
|
|
5167
|
+
}
|
|
5168
|
+
function isNewer(candidate, current) {
|
|
5169
|
+
const left = timestamp(candidate.updatedAt);
|
|
5170
|
+
const right = timestamp(current.updatedAt);
|
|
5171
|
+
if (left === void 0 || right === void 0) return candidate.updatedAt >= current.updatedAt;
|
|
5172
|
+
return left >= right;
|
|
5173
|
+
}
|
|
5174
|
+
function timestamp(value) {
|
|
5175
|
+
const parsed = Date.parse(value);
|
|
5176
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
5177
|
+
}
|
|
5178
|
+
function trimToWindow(tickets, limit) {
|
|
5179
|
+
if (tickets.length <= limit) return [...tickets];
|
|
5180
|
+
const sorted = [...tickets].sort((left, right) => {
|
|
5181
|
+
const byTime = compareTime(left.updatedAt, right.updatedAt);
|
|
5182
|
+
if (byTime !== 0) return byTime;
|
|
5183
|
+
return left.ref.localeCompare(right.ref);
|
|
5184
|
+
});
|
|
5185
|
+
return sorted.slice(0, limit);
|
|
5186
|
+
}
|
|
5187
|
+
function compareTime(left, right) {
|
|
5188
|
+
const leftTime = timestamp(left);
|
|
5189
|
+
const rightTime = timestamp(right);
|
|
5190
|
+
if (leftTime === void 0 || rightTime === void 0) return right.localeCompare(left);
|
|
5191
|
+
return rightTime - leftTime;
|
|
4735
5192
|
}
|
|
4736
5193
|
|
|
4737
5194
|
// src/core/metrics.ts
|
|
@@ -5055,11 +5512,13 @@ async function removeStored(deps, workspaceRoot) {
|
|
|
5055
5512
|
} catch {
|
|
5056
5513
|
}
|
|
5057
5514
|
}
|
|
5058
|
-
async function writeStored(deps, workspaceRoot, resolved, raw) {
|
|
5515
|
+
async function writeStored(deps, workspaceRoot, resolved, raw, metrics) {
|
|
5059
5516
|
const store = deps.store;
|
|
5060
|
-
if (store === void 0) return;
|
|
5517
|
+
if (store === void 0) return null;
|
|
5518
|
+
const coversAll = raw.tickets.length >= raw.total;
|
|
5061
5519
|
const entry = {
|
|
5062
5520
|
version: SNAPSHOT_STORE_VERSION,
|
|
5521
|
+
libraryVersion: 0,
|
|
5063
5522
|
workspaceRoot,
|
|
5064
5523
|
backend: resolved.kind,
|
|
5065
5524
|
repository: raw.repository,
|
|
@@ -5069,12 +5528,13 @@ async function writeStored(deps, workspaceRoot, resolved, raw) {
|
|
|
5069
5528
|
fetchedAt: raw.fetchedAt,
|
|
5070
5529
|
loaded: raw.tickets.length,
|
|
5071
5530
|
total: raw.total,
|
|
5072
|
-
...raw.windowLimit === void 0 ? {} : { windowLimit: raw.windowLimit },
|
|
5531
|
+
...coversAll || raw.windowLimit === void 0 ? {} : { windowLimit: raw.windowLimit },
|
|
5073
5532
|
hierarchy: raw.hierarchy,
|
|
5533
|
+
metrics,
|
|
5074
5534
|
tickets: raw.tickets
|
|
5075
5535
|
};
|
|
5076
5536
|
try {
|
|
5077
|
-
await store.write(entry);
|
|
5537
|
+
return await store.write(entry);
|
|
5078
5538
|
} catch (error) {
|
|
5079
5539
|
deps.log("warn", LOG_EVENTS.snapshot, {
|
|
5080
5540
|
result: "error",
|
|
@@ -5083,9 +5543,10 @@ async function writeStored(deps, workspaceRoot, resolved, raw) {
|
|
|
5083
5543
|
code: ERROR_CODES.internal,
|
|
5084
5544
|
...error instanceof Error ? { reason: error.message } : {}
|
|
5085
5545
|
});
|
|
5546
|
+
return null;
|
|
5086
5547
|
}
|
|
5087
5548
|
}
|
|
5088
|
-
function buildSnapshot(kind, repositoryHost, raw, tickets, blockersFinalized, metrics, source, stale, refreshError) {
|
|
5549
|
+
function buildSnapshot(kind, repositoryHost, raw, tickets, blockersFinalized, metrics, source, stale, refreshError, libraryVersion) {
|
|
5089
5550
|
return {
|
|
5090
5551
|
backend: kind,
|
|
5091
5552
|
repository: raw.repository,
|
|
@@ -5096,37 +5557,40 @@ function buildSnapshot(kind, repositoryHost, raw, tickets, blockersFinalized, me
|
|
|
5096
5557
|
total: raw.total,
|
|
5097
5558
|
windowLimit: raw.windowLimit ?? tickets.length,
|
|
5098
5559
|
hierarchy: raw.hierarchy,
|
|
5560
|
+
libraryVersion,
|
|
5099
5561
|
blockersFinalized,
|
|
5100
5562
|
metrics,
|
|
5101
5563
|
source,
|
|
5102
5564
|
stale,
|
|
5103
5565
|
refreshError,
|
|
5104
|
-
tickets: tickets.map(
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
}
|
|
5566
|
+
tickets: tickets.map(toTicketSnapshot)
|
|
5567
|
+
};
|
|
5568
|
+
}
|
|
5569
|
+
function toTicketSnapshot(ticket) {
|
|
5570
|
+
return {
|
|
5571
|
+
ref: ticket.ref,
|
|
5572
|
+
number: ticket.number,
|
|
5573
|
+
title: ticket.title,
|
|
5574
|
+
state: ticket.state,
|
|
5575
|
+
category: ticket.category,
|
|
5576
|
+
status: ticket.status,
|
|
5577
|
+
labels: ticket.labels,
|
|
5578
|
+
author: ticket.author,
|
|
5579
|
+
assignees: ticket.assignees,
|
|
5580
|
+
skillAction: ticket.skillAction,
|
|
5581
|
+
skillActionReason: ticket.skillActionReason,
|
|
5582
|
+
createdAt: ticket.createdAt,
|
|
5583
|
+
updatedAt: ticket.updatedAt,
|
|
5584
|
+
openBlockers: ticket.openBlockers,
|
|
5585
|
+
...ticket.closedAt === void 0 ? {} : { closedAt: ticket.closedAt },
|
|
5586
|
+
...ticket.url === void 0 ? {} : { url: ticket.url },
|
|
5587
|
+
...ticket.blockedBy === void 0 ? {} : { blockedBy: ticket.blockedBy },
|
|
5588
|
+
...ticket.parent === void 0 ? {} : { parent: ticket.parent }
|
|
5124
5589
|
};
|
|
5125
5590
|
}
|
|
5126
5591
|
function buildStoredSnapshot(deps, stored, state) {
|
|
5127
5592
|
const raw = rawOf(stored);
|
|
5128
5593
|
const tickets = withSkillActions(classifyTickets(raw.tickets, deps.labels), deps.labels);
|
|
5129
|
-
const metrics = metricsOf(deps, stored.backend, raw, tickets, false);
|
|
5130
5594
|
return {
|
|
5131
5595
|
backend: stored.backend,
|
|
5132
5596
|
repository: raw.repository,
|
|
@@ -5137,31 +5601,13 @@ function buildStoredSnapshot(deps, stored, state) {
|
|
|
5137
5601
|
total: raw.total,
|
|
5138
5602
|
windowLimit: raw.windowLimit ?? SNAPSHOT_PAGE_SIZE,
|
|
5139
5603
|
hierarchy: stored.hierarchy,
|
|
5604
|
+
libraryVersion: stored.libraryVersion,
|
|
5140
5605
|
blockersFinalized: false,
|
|
5141
|
-
metrics,
|
|
5606
|
+
metrics: stored.metrics,
|
|
5142
5607
|
source: "cache",
|
|
5143
5608
|
stale: state.stale,
|
|
5144
5609
|
refreshError: state.refreshError,
|
|
5145
|
-
tickets: tickets.map(
|
|
5146
|
-
ref: ticket.ref,
|
|
5147
|
-
number: ticket.number,
|
|
5148
|
-
title: ticket.title,
|
|
5149
|
-
state: ticket.state,
|
|
5150
|
-
category: ticket.category,
|
|
5151
|
-
status: ticket.status,
|
|
5152
|
-
labels: ticket.labels,
|
|
5153
|
-
author: ticket.author,
|
|
5154
|
-
assignees: ticket.assignees,
|
|
5155
|
-
skillAction: ticket.skillAction,
|
|
5156
|
-
skillActionReason: ticket.skillActionReason,
|
|
5157
|
-
createdAt: ticket.createdAt,
|
|
5158
|
-
updatedAt: ticket.updatedAt,
|
|
5159
|
-
openBlockers: ticket.openBlockers,
|
|
5160
|
-
...ticket.closedAt === void 0 ? {} : { closedAt: ticket.closedAt },
|
|
5161
|
-
...ticket.url === void 0 ? {} : { url: ticket.url },
|
|
5162
|
-
...ticket.blockedBy === void 0 ? {} : { blockedBy: ticket.blockedBy },
|
|
5163
|
-
...ticket.parent === void 0 ? {} : { parent: ticket.parent }
|
|
5164
|
-
}))
|
|
5610
|
+
tickets: tickets.map(toTicketSnapshot)
|
|
5165
5611
|
};
|
|
5166
5612
|
}
|
|
5167
5613
|
function storedEntry(stored, resolved, snapshot) {
|
|
@@ -5249,11 +5695,297 @@ function latestWrite(entries) {
|
|
|
5249
5695
|
return latest;
|
|
5250
5696
|
}
|
|
5251
5697
|
|
|
5252
|
-
// src/host/snapshot-
|
|
5698
|
+
// src/host/snapshot-window.ts
|
|
5699
|
+
function windowFor(current, base) {
|
|
5700
|
+
const cached = current?.raw.windowLimit ?? 0;
|
|
5701
|
+
const stored = base?.windowLimit ?? 0;
|
|
5702
|
+
const loaded = current?.raw.tickets.length ?? 0;
|
|
5703
|
+
return Math.min(SNAPSHOT_MAX_WINDOW, Math.max(cached, stored, loaded, SNAPSHOT_PAGE_SIZE));
|
|
5704
|
+
}
|
|
5705
|
+
function mergePulled(current, raw) {
|
|
5706
|
+
if (current === void 0) return raw;
|
|
5707
|
+
if (current.raw.repository !== raw.repository) return raw;
|
|
5708
|
+
const existingWindow = current.raw.windowLimit ?? current.raw.tickets.length;
|
|
5709
|
+
const pulledWindow = raw.windowLimit ?? raw.tickets.length;
|
|
5710
|
+
const window = Math.max(existingWindow, pulledWindow);
|
|
5711
|
+
const shrunk = raw.tickets.length < current.raw.tickets.length;
|
|
5712
|
+
if (!shrunk && window <= pulledWindow) return raw;
|
|
5713
|
+
const tickets = mergeTickets(current.raw.tickets, raw.tickets, window);
|
|
5714
|
+
return { ...raw, loaded: tickets.length, tickets, windowLimit: window };
|
|
5715
|
+
}
|
|
5716
|
+
async function loadMore(host, workspaceRoot) {
|
|
5717
|
+
const initial = await host.getSnapshot(workspaceRoot);
|
|
5718
|
+
if (!initial.ok) return initial;
|
|
5719
|
+
const entry = host.cache.get(workspaceRoot);
|
|
5720
|
+
if (entry === void 0) return initial;
|
|
5721
|
+
const windowLimit = entry.raw.windowLimit ?? SNAPSHOT_PAGE_SIZE;
|
|
5722
|
+
if (entry.raw.tickets.length >= entry.raw.total || windowLimit >= SNAPSHOT_MAX_WINDOW) {
|
|
5723
|
+
return { ok: true, result: entry.snapshot };
|
|
5724
|
+
}
|
|
5725
|
+
const nextWindow = Math.min(windowLimit + SNAPSHOT_PAGE_SIZE, SNAPSHOT_MAX_WINDOW);
|
|
5726
|
+
const startedAt = host.now();
|
|
5727
|
+
let kind;
|
|
5728
|
+
try {
|
|
5729
|
+
const resolved = await host.resolve(workspaceRoot);
|
|
5730
|
+
kind = resolved.kind;
|
|
5731
|
+
const raw = await resolved.tracker.fetchSnapshot(workspaceRoot, nextWindow);
|
|
5732
|
+
const viewer = raw.viewer ?? (entry.raw.repository === raw.repository ? entry.raw.viewer : null);
|
|
5733
|
+
return await host.publish(
|
|
5734
|
+
workspaceRoot,
|
|
5735
|
+
resolved,
|
|
5736
|
+
{ ...raw, viewer, windowLimit: nextWindow },
|
|
5737
|
+
startedAt
|
|
5738
|
+
);
|
|
5739
|
+
} catch (error) {
|
|
5740
|
+
const mapped = mapSnapshotError(error);
|
|
5741
|
+
host.log("warn", LOG_EVENTS.snapshot, {
|
|
5742
|
+
result: "error",
|
|
5743
|
+
...kind === void 0 ? {} : { backend: kind },
|
|
5744
|
+
stage: SNAPSHOT_STAGES.list,
|
|
5745
|
+
code: mapped.code,
|
|
5746
|
+
durationMs: Math.max(0, host.now() - startedAt)
|
|
5747
|
+
});
|
|
5748
|
+
return snapshotFailure(mapped.code, mapped.message);
|
|
5749
|
+
}
|
|
5750
|
+
}
|
|
5751
|
+
|
|
5752
|
+
// src/host/snapshot-refresh.ts
|
|
5253
5753
|
var INCREMENTAL_OVERLAP_MS = 6e4;
|
|
5754
|
+
async function refreshSnapshot(host, workspaceRoot, full, ifVersion) {
|
|
5755
|
+
const startedAt = host.now();
|
|
5756
|
+
if (!full) {
|
|
5757
|
+
const cooling = coolingReject(host, workspaceRoot, startedAt);
|
|
5758
|
+
if (cooling !== null) return cooling;
|
|
5759
|
+
}
|
|
5760
|
+
const failWith = (mapped) => {
|
|
5761
|
+
host.guard.noteFailure(workspaceRoot, startedAt, mapped.retryAfterMs);
|
|
5762
|
+
return keepOldSnapshot(host, workspaceRoot, mapped, startedAt);
|
|
5763
|
+
};
|
|
5764
|
+
let resolved;
|
|
5765
|
+
try {
|
|
5766
|
+
resolved = await host.resolve(workspaceRoot);
|
|
5767
|
+
} catch (error) {
|
|
5768
|
+
return failWith(mapSnapshotError(error));
|
|
5769
|
+
}
|
|
5770
|
+
const stored = await readStored(host, workspaceRoot);
|
|
5771
|
+
const base = stored?.repositoryKey === repositoryKey(resolved.kind, resolved.address) ? stored : void 0;
|
|
5772
|
+
const tracker = resolved.tracker;
|
|
5773
|
+
let raw;
|
|
5774
|
+
let mode = "full";
|
|
5775
|
+
if (base !== void 0 && !full && tracker.fetchChanges !== void 0 && // 对账以「全量覆盖」为前提:窗口截断的后端看不到窗口外的删除。
|
|
5776
|
+
base.windowLimit === void 0) {
|
|
5777
|
+
const outcome = await pullIncremental(host, workspaceRoot, resolved, base, startedAt);
|
|
5778
|
+
if (outcome.kind === "failure") {
|
|
5779
|
+
return failWith(outcome.error);
|
|
5780
|
+
}
|
|
5781
|
+
if (outcome.kind === "merged") {
|
|
5782
|
+
raw = outcome.raw;
|
|
5783
|
+
mode = "incremental";
|
|
5784
|
+
}
|
|
5785
|
+
}
|
|
5786
|
+
if (raw === void 0) {
|
|
5787
|
+
try {
|
|
5788
|
+
const fetched = await tracker.fetchSnapshot(
|
|
5789
|
+
workspaceRoot,
|
|
5790
|
+
windowFor(host.cache.get(workspaceRoot), base)
|
|
5791
|
+
);
|
|
5792
|
+
const current = host.cache.get(workspaceRoot);
|
|
5793
|
+
const hostName = resolved.kind === "markdown" ? null : resolved.address?.host ?? null;
|
|
5794
|
+
const sameRepository = current?.kind === resolved.kind && current.repositoryHost === hostName && current.raw.repository === fetched.repository;
|
|
5795
|
+
const previousViewer = (sameRepository ? current.raw.viewer : null) ?? base?.viewer ?? null;
|
|
5796
|
+
raw = fetched.viewer === null ? { ...fetched, viewer: previousViewer } : fetched;
|
|
5797
|
+
} catch (error) {
|
|
5798
|
+
return failWith(mapSnapshotError(error));
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
if (base !== void 0 && !ticketsDiffer(base, raw)) {
|
|
5802
|
+
return respondUnchanged(host, workspaceRoot, resolved, base, raw, ifVersion, startedAt);
|
|
5803
|
+
}
|
|
5804
|
+
const published = await host.publish(workspaceRoot, resolved, raw, startedAt, mode);
|
|
5805
|
+
if (!published.ok) {
|
|
5806
|
+
host.guard.noteFailure(workspaceRoot, host.now());
|
|
5807
|
+
return published;
|
|
5808
|
+
}
|
|
5809
|
+
host.guard.noteSuccess(workspaceRoot);
|
|
5810
|
+
return shapeDelta(host, workspaceRoot, published.result, ifVersion);
|
|
5811
|
+
}
|
|
5812
|
+
function coolingReject(host, workspaceRoot, startedAt) {
|
|
5813
|
+
const coolingUntil = host.guard.blockedUntil(workspaceRoot, startedAt);
|
|
5814
|
+
if (coolingUntil === null) return null;
|
|
5815
|
+
return keepOldSnapshot(
|
|
5816
|
+
host,
|
|
5817
|
+
workspaceRoot,
|
|
5818
|
+
{
|
|
5819
|
+
code: ERROR_CODES.fetchFailed,
|
|
5820
|
+
message: "\u5237\u65B0\u5DF2\u6682\u505C\uFF1A\u8FDE\u7EED\u5931\u8D25\u540E\u6B63\u5728\u9000\u907F\uFF0C\u7A0D\u540E\u4F1A\u81EA\u52A8\u6062\u590D\uFF0C\u663E\u793A\u7684\u662F\u672C\u5730\u7F13\u5B58\u3002"
|
|
5821
|
+
},
|
|
5822
|
+
startedAt
|
|
5823
|
+
);
|
|
5824
|
+
}
|
|
5825
|
+
async function pullIncremental(host, workspaceRoot, resolved, base, startedAt) {
|
|
5826
|
+
const tracker = resolved.tracker;
|
|
5827
|
+
if (tracker.fetchChanges === void 0) return { kind: "fallback" };
|
|
5828
|
+
let changes;
|
|
5829
|
+
try {
|
|
5830
|
+
changes = await tracker.fetchChanges(workspaceRoot, base.fetchedAt - INCREMENTAL_OVERLAP_MS);
|
|
5831
|
+
} catch (error) {
|
|
5832
|
+
const mapped = mapSnapshotError(error);
|
|
5833
|
+
return { kind: "failure", error: mapped };
|
|
5834
|
+
}
|
|
5835
|
+
if (changes.truncated) {
|
|
5836
|
+
logIncrementalFallback(host, resolved.kind, "truncated", startedAt);
|
|
5837
|
+
return { kind: "fallback" };
|
|
5838
|
+
}
|
|
5839
|
+
const total = changes.total;
|
|
5840
|
+
if (!Number.isInteger(total) || total < 0) {
|
|
5841
|
+
logIncrementalFallback(host, resolved.kind, "invalid-total", startedAt);
|
|
5842
|
+
return { kind: "fallback" };
|
|
5843
|
+
}
|
|
5844
|
+
if (changes.hierarchy !== base.hierarchy) {
|
|
5845
|
+
logIncrementalFallback(host, resolved.kind, "hierarchy", startedAt);
|
|
5846
|
+
return { kind: "fallback" };
|
|
5847
|
+
}
|
|
5848
|
+
const merged = mergeTickets(base.tickets, changes.tickets);
|
|
5849
|
+
if (merged.length > total) {
|
|
5850
|
+
logIncrementalFallback(host, resolved.kind, "drift", startedAt);
|
|
5851
|
+
return { kind: "fallback" };
|
|
5852
|
+
}
|
|
5853
|
+
return {
|
|
5854
|
+
kind: "merged",
|
|
5855
|
+
raw: {
|
|
5856
|
+
repository: base.repository,
|
|
5857
|
+
fetchedAt: host.now(),
|
|
5858
|
+
loaded: merged.length,
|
|
5859
|
+
total,
|
|
5860
|
+
hierarchy: base.hierarchy,
|
|
5861
|
+
tickets: merged,
|
|
5862
|
+
// 后端这次查了身份就用新值;没查(省略)时沿用基准数据里的身份。
|
|
5863
|
+
viewer: changes.viewer === void 0 ? base.viewer : changes.viewer,
|
|
5864
|
+
windowLimit: Math.max(base.tickets.length, SNAPSHOT_PAGE_SIZE)
|
|
5865
|
+
}
|
|
5866
|
+
};
|
|
5867
|
+
}
|
|
5868
|
+
function logIncrementalFallback(deps, backend, reason, startedAt) {
|
|
5869
|
+
deps.log("warn", LOG_EVENTS.snapshot, {
|
|
5870
|
+
result: "fallback",
|
|
5871
|
+
backend,
|
|
5872
|
+
stage: SNAPSHOT_STAGES.list,
|
|
5873
|
+
reason,
|
|
5874
|
+
durationMs: Math.max(0, deps.now() - startedAt)
|
|
5875
|
+
});
|
|
5876
|
+
}
|
|
5877
|
+
function ticketsDiffer(base, raw) {
|
|
5878
|
+
if (base.total !== raw.total || base.viewer !== raw.viewer) return true;
|
|
5879
|
+
return JSON.stringify(base.tickets) !== JSON.stringify(raw.tickets);
|
|
5880
|
+
}
|
|
5881
|
+
async function respondUnchanged(host, workspaceRoot, resolved, base, raw, ifVersion, startedAt) {
|
|
5882
|
+
if (ifVersion !== void 0 && ifVersion === base.libraryVersion) {
|
|
5883
|
+
host.guard.noteSuccess(workspaceRoot);
|
|
5884
|
+
return {
|
|
5885
|
+
ok: true,
|
|
5886
|
+
result: { kind: "not-modified", version: base.libraryVersion, checkedAt: host.now() }
|
|
5887
|
+
};
|
|
5888
|
+
}
|
|
5889
|
+
if (ifVersion !== void 0 && ifVersion < base.libraryVersion) {
|
|
5890
|
+
const changes = await host.store?.changesSince(workspaceRoot, ifVersion);
|
|
5891
|
+
if (changes !== void 0) {
|
|
5892
|
+
const delta = buildDelta(host, base.libraryVersion, raw.fetchedAt, changes, base);
|
|
5893
|
+
if (delta !== void 0) {
|
|
5894
|
+
host.guard.noteSuccess(workspaceRoot);
|
|
5895
|
+
return { ok: true, result: delta };
|
|
5896
|
+
}
|
|
5897
|
+
}
|
|
5898
|
+
}
|
|
5899
|
+
const published = await host.publish(workspaceRoot, resolved, raw, startedAt, "full", {
|
|
5900
|
+
skipWrite: true,
|
|
5901
|
+
versionFallback: base.libraryVersion
|
|
5902
|
+
});
|
|
5903
|
+
if (!published.ok) {
|
|
5904
|
+
host.guard.noteFailure(workspaceRoot, host.now());
|
|
5905
|
+
return published;
|
|
5906
|
+
}
|
|
5907
|
+
host.guard.noteSuccess(workspaceRoot);
|
|
5908
|
+
return { ok: true, result: { kind: "full", snapshot: published.result } };
|
|
5909
|
+
}
|
|
5910
|
+
async function shapeDelta(host, workspaceRoot, snapshot, ifVersion) {
|
|
5911
|
+
const full = { kind: "full", snapshot };
|
|
5912
|
+
if (ifVersion === void 0 || snapshot.libraryVersion === null) return { ok: true, result: full };
|
|
5913
|
+
if (ifVersion === snapshot.libraryVersion) return { ok: true, result: full };
|
|
5914
|
+
const changes = await host.store?.changesSince(workspaceRoot, ifVersion);
|
|
5915
|
+
if (changes === void 0) return { ok: true, result: full };
|
|
5916
|
+
const delta = buildDelta(
|
|
5917
|
+
host,
|
|
5918
|
+
snapshot.libraryVersion,
|
|
5919
|
+
snapshot.fetchedAt,
|
|
5920
|
+
changes,
|
|
5921
|
+
void 0,
|
|
5922
|
+
snapshot
|
|
5923
|
+
);
|
|
5924
|
+
if (delta === void 0) return { ok: true, result: full };
|
|
5925
|
+
return { ok: true, result: delta };
|
|
5926
|
+
}
|
|
5927
|
+
function buildDelta(host, version, fetchedAt, changes, base, snapshot) {
|
|
5928
|
+
if (changes.tickets.length + changes.removed.length > SNAPSHOT_DELTA_MAX_ROWS) return void 0;
|
|
5929
|
+
const metrics = snapshot?.metrics ?? base?.metrics;
|
|
5930
|
+
const viewer = snapshot?.viewer ?? base?.viewer ?? null;
|
|
5931
|
+
const total = snapshot?.total ?? base?.total ?? 0;
|
|
5932
|
+
const loaded = snapshot?.loaded ?? base?.tickets.length ?? 0;
|
|
5933
|
+
const windowLimit = snapshot?.windowLimit ?? base?.windowLimit ?? SNAPSHOT_PAGE_SIZE;
|
|
5934
|
+
if (metrics === void 0) return void 0;
|
|
5935
|
+
const rows = withSkillActions(classifyTickets(changes.tickets, host.labels), host.labels).map(
|
|
5936
|
+
toTicketSnapshot
|
|
5937
|
+
);
|
|
5938
|
+
const anyOpen = base?.tickets.some((ticket) => ticket.state === "open") ?? false;
|
|
5939
|
+
const blockersFinalized = snapshot?.blockersFinalized ?? !anyOpen;
|
|
5940
|
+
return {
|
|
5941
|
+
kind: "changes",
|
|
5942
|
+
version,
|
|
5943
|
+
fetchedAt,
|
|
5944
|
+
tickets: rows,
|
|
5945
|
+
removed: changes.removed,
|
|
5946
|
+
metrics,
|
|
5947
|
+
viewer,
|
|
5948
|
+
total,
|
|
5949
|
+
loaded,
|
|
5950
|
+
windowLimit,
|
|
5951
|
+
blockersFinalized
|
|
5952
|
+
};
|
|
5953
|
+
}
|
|
5954
|
+
async function keepOldSnapshot(host, workspaceRoot, mapped, startedAt) {
|
|
5955
|
+
const refreshError = { code: mapped.code, message: mapped.message };
|
|
5956
|
+
const cached = host.cache.get(workspaceRoot);
|
|
5957
|
+
if (cached !== void 0) {
|
|
5958
|
+
const snapshot2 = { ...cached.snapshot, stale: true, refreshError };
|
|
5959
|
+
cached.snapshot = snapshot2;
|
|
5960
|
+
host.log("warn", LOG_EVENTS.snapshot, {
|
|
5961
|
+
result: "error",
|
|
5962
|
+
backend: cached.kind,
|
|
5963
|
+
stage: SNAPSHOT_STAGES.list,
|
|
5964
|
+
code: mapped.code,
|
|
5965
|
+
durationMs: Math.max(0, host.now() - startedAt)
|
|
5966
|
+
});
|
|
5967
|
+
return { ok: true, result: { kind: "full", snapshot: snapshot2 } };
|
|
5968
|
+
}
|
|
5969
|
+
const stored = await readStored(host, workspaceRoot);
|
|
5970
|
+
if (stored === void 0) return { ok: false, error: refreshError };
|
|
5971
|
+
const snapshot = buildStoredSnapshot(host, stored, { stale: true, refreshError });
|
|
5972
|
+
host.cache.set(workspaceRoot, storedEntry(stored, null, snapshot));
|
|
5973
|
+
host.log("warn", LOG_EVENTS.snapshot, {
|
|
5974
|
+
result: "error",
|
|
5975
|
+
backend: stored.backend,
|
|
5976
|
+
stage: SNAPSHOT_STAGES.list,
|
|
5977
|
+
code: mapped.code,
|
|
5978
|
+
durationMs: Math.max(0, host.now() - startedAt)
|
|
5979
|
+
});
|
|
5980
|
+
return { ok: true, result: { kind: "full", snapshot } };
|
|
5981
|
+
}
|
|
5982
|
+
|
|
5983
|
+
// src/host/snapshot-service.ts
|
|
5254
5984
|
function createSnapshotService(deps) {
|
|
5255
5985
|
const cache = /* @__PURE__ */ new Map();
|
|
5256
5986
|
const loading = /* @__PURE__ */ new Map();
|
|
5987
|
+
const refreshing = /* @__PURE__ */ new Map();
|
|
5988
|
+
const guard = createRefreshGuard();
|
|
5257
5989
|
const more = {
|
|
5258
5990
|
resolve: deps.resolve,
|
|
5259
5991
|
now: deps.now,
|
|
@@ -5262,6 +5994,16 @@ function createSnapshotService(deps) {
|
|
|
5262
5994
|
getSnapshot: (workspaceRoot) => getSnapshot(deps, cache, loading, workspaceRoot),
|
|
5263
5995
|
publish: (workspaceRoot, resolved, raw, startedAt) => publish(deps, cache, workspaceRoot, resolved, raw, startedAt, "more")
|
|
5264
5996
|
};
|
|
5997
|
+
const refreshHost = {
|
|
5998
|
+
resolve: deps.resolve,
|
|
5999
|
+
now: deps.now,
|
|
6000
|
+
labels: deps.labels,
|
|
6001
|
+
log: deps.log,
|
|
6002
|
+
...deps.store === void 0 ? {} : { store: deps.store },
|
|
6003
|
+
cache,
|
|
6004
|
+
guard,
|
|
6005
|
+
publish: (workspaceRoot, resolved, raw, startedAt, mode, options) => publish(deps, cache, workspaceRoot, resolved, raw, startedAt, mode, options)
|
|
6006
|
+
};
|
|
5265
6007
|
return {
|
|
5266
6008
|
handle(method, params) {
|
|
5267
6009
|
if (!isSnapshotMethod(method)) {
|
|
@@ -5279,10 +6021,29 @@ function createSnapshotService(deps) {
|
|
|
5279
6021
|
if (method === RPC_METHODS.snapshotResolveBlockers) {
|
|
5280
6022
|
return resolveBlockers(deps, cache, loading, workspaceRoot);
|
|
5281
6023
|
}
|
|
5282
|
-
|
|
5283
|
-
|
|
6024
|
+
return loadMore(more, workspaceRoot);
|
|
6025
|
+
},
|
|
6026
|
+
refresh(params) {
|
|
6027
|
+
const workspaceRoot = readWorkspaceRoot2(params);
|
|
6028
|
+
if (workspaceRoot === void 0) {
|
|
6029
|
+
return Promise.resolve(
|
|
6030
|
+
snapshotFailure(ERROR_CODES.invalidParams, "\u7F3A\u5C11\u975E\u7A7A\u7684 workspaceRoot \u53C2\u6570\u3002")
|
|
6031
|
+
);
|
|
5284
6032
|
}
|
|
5285
|
-
|
|
6033
|
+
const inflight = refreshing.get(workspaceRoot);
|
|
6034
|
+
if (inflight !== void 0) return inflight;
|
|
6035
|
+
const task = refreshSnapshot(
|
|
6036
|
+
refreshHost,
|
|
6037
|
+
workspaceRoot,
|
|
6038
|
+
readFullFlag(params),
|
|
6039
|
+
readIfVersion(params)
|
|
6040
|
+
);
|
|
6041
|
+
refreshing.set(workspaceRoot, task);
|
|
6042
|
+
const clear = () => {
|
|
6043
|
+
if (refreshing.get(workspaceRoot) === task) refreshing.delete(workspaceRoot);
|
|
6044
|
+
};
|
|
6045
|
+
void task.then(clear, clear);
|
|
6046
|
+
return task;
|
|
5286
6047
|
},
|
|
5287
6048
|
cache(params) {
|
|
5288
6049
|
if (readWorkspaceRoot2(params) === void 0) {
|
|
@@ -5296,11 +6057,17 @@ function createSnapshotService(deps) {
|
|
|
5296
6057
|
};
|
|
5297
6058
|
}
|
|
5298
6059
|
function isSnapshotMethod(method) {
|
|
5299
|
-
return method === RPC_METHODS.snapshotGet || method === RPC_METHODS.
|
|
6060
|
+
return method === RPC_METHODS.snapshotGet || method === RPC_METHODS.snapshotResolveBlockers || method === RPC_METHODS.snapshotMore;
|
|
5300
6061
|
}
|
|
5301
6062
|
function readFullFlag(params) {
|
|
5302
6063
|
return isRecord(params) && params.full === true;
|
|
5303
6064
|
}
|
|
6065
|
+
function readIfVersion(params) {
|
|
6066
|
+
if (!isRecord(params)) return void 0;
|
|
6067
|
+
const value = params.ifVersion;
|
|
6068
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) return void 0;
|
|
6069
|
+
return value;
|
|
6070
|
+
}
|
|
5304
6071
|
function getSnapshot(deps, cache, loading, workspaceRoot) {
|
|
5305
6072
|
const cached = cache.get(workspaceRoot);
|
|
5306
6073
|
if (cached !== void 0) return Promise.resolve({ ok: true, result: cached.snapshot });
|
|
@@ -5309,7 +6076,7 @@ function getSnapshot(deps, cache, loading, workspaceRoot) {
|
|
|
5309
6076
|
function loadWorkspace(deps, cache, loading, workspaceRoot) {
|
|
5310
6077
|
const running = loading.get(workspaceRoot);
|
|
5311
6078
|
if (running !== void 0) return running;
|
|
5312
|
-
const task =
|
|
6079
|
+
const task = readWorkspace2(deps, cache, workspaceRoot);
|
|
5313
6080
|
loading.set(workspaceRoot, task);
|
|
5314
6081
|
void task.then(
|
|
5315
6082
|
() => {
|
|
@@ -5321,7 +6088,7 @@ function loadWorkspace(deps, cache, loading, workspaceRoot) {
|
|
|
5321
6088
|
);
|
|
5322
6089
|
return task;
|
|
5323
6090
|
}
|
|
5324
|
-
async function
|
|
6091
|
+
async function readWorkspace2(deps, cache, workspaceRoot) {
|
|
5325
6092
|
const stored = await readStored(deps, workspaceRoot);
|
|
5326
6093
|
if (stored !== void 0) {
|
|
5327
6094
|
const served = await serveStored(deps, cache, workspaceRoot, stored);
|
|
@@ -5354,87 +6121,6 @@ async function serveStored(deps, cache, workspaceRoot, stored) {
|
|
|
5354
6121
|
cache.set(workspaceRoot, storedEntry(stored, resolved, snapshot));
|
|
5355
6122
|
return { ok: true, result: snapshot };
|
|
5356
6123
|
}
|
|
5357
|
-
async function refreshSnapshot(deps, cache, workspaceRoot, full) {
|
|
5358
|
-
const startedAt = deps.now();
|
|
5359
|
-
let resolved;
|
|
5360
|
-
try {
|
|
5361
|
-
resolved = await deps.resolve(workspaceRoot);
|
|
5362
|
-
} catch (error) {
|
|
5363
|
-
return await keepOldSnapshot(deps, cache, workspaceRoot, mapSnapshotError(error), startedAt);
|
|
5364
|
-
}
|
|
5365
|
-
const stored = await readStored(deps, workspaceRoot);
|
|
5366
|
-
const base = stored?.repositoryKey === repositoryKey(resolved.kind, resolved.address) ? stored : void 0;
|
|
5367
|
-
const tracker = resolved.tracker;
|
|
5368
|
-
if (base !== void 0 && !full && tracker.fetchChanges !== void 0 && // 对账以「全量覆盖」为前提:窗口截断的后端看不到窗口外的删除。
|
|
5369
|
-
base.windowLimit === void 0) {
|
|
5370
|
-
const merged = await mergeIncremental(deps, cache, workspaceRoot, resolved, base, startedAt);
|
|
5371
|
-
if (merged !== void 0) return merged;
|
|
5372
|
-
}
|
|
5373
|
-
try {
|
|
5374
|
-
const raw = await tracker.fetchSnapshot(
|
|
5375
|
-
workspaceRoot,
|
|
5376
|
-
windowFor(cache.get(workspaceRoot), base)
|
|
5377
|
-
);
|
|
5378
|
-
const current = cache.get(workspaceRoot);
|
|
5379
|
-
const host = resolved.kind === "markdown" ? null : resolved.address?.host ?? null;
|
|
5380
|
-
const sameRepository = current?.kind === resolved.kind && current.repositoryHost === host && current.raw.repository === raw.repository;
|
|
5381
|
-
const previousViewer = (sameRepository ? current.raw.viewer : null) ?? base?.viewer ?? null;
|
|
5382
|
-
const withViewer = raw.viewer === null ? { ...raw, viewer: previousViewer } : raw;
|
|
5383
|
-
return await publish(deps, cache, workspaceRoot, resolved, withViewer, startedAt, "full");
|
|
5384
|
-
} catch (error) {
|
|
5385
|
-
return await keepOldSnapshot(deps, cache, workspaceRoot, mapSnapshotError(error), startedAt);
|
|
5386
|
-
}
|
|
5387
|
-
}
|
|
5388
|
-
async function mergeIncremental(deps, cache, workspaceRoot, resolved, base, startedAt) {
|
|
5389
|
-
const tracker = resolved.tracker;
|
|
5390
|
-
if (tracker.fetchChanges === void 0) return void 0;
|
|
5391
|
-
let changes;
|
|
5392
|
-
try {
|
|
5393
|
-
changes = await tracker.fetchChanges(workspaceRoot, base.fetchedAt - INCREMENTAL_OVERLAP_MS);
|
|
5394
|
-
} catch (error) {
|
|
5395
|
-
return await keepOldSnapshot(deps, cache, workspaceRoot, mapSnapshotError(error), startedAt);
|
|
5396
|
-
}
|
|
5397
|
-
if (changes.truncated) {
|
|
5398
|
-
logIncrementalFallback(deps, resolved.kind, "truncated", startedAt);
|
|
5399
|
-
return void 0;
|
|
5400
|
-
}
|
|
5401
|
-
const total = changes.total;
|
|
5402
|
-
if (!Number.isInteger(total) || total < 0) {
|
|
5403
|
-
logIncrementalFallback(deps, resolved.kind, "invalid-total", startedAt);
|
|
5404
|
-
return void 0;
|
|
5405
|
-
}
|
|
5406
|
-
if (changes.hierarchy !== base.hierarchy) {
|
|
5407
|
-
logIncrementalFallback(deps, resolved.kind, "hierarchy", startedAt);
|
|
5408
|
-
return void 0;
|
|
5409
|
-
}
|
|
5410
|
-
const windowLimit = base.windowLimit ?? SNAPSHOT_PAGE_SIZE;
|
|
5411
|
-
const merged = mergeTickets(base.tickets, changes.tickets, windowLimit);
|
|
5412
|
-
if (merged.length > total) {
|
|
5413
|
-
logIncrementalFallback(deps, resolved.kind, "drift", startedAt);
|
|
5414
|
-
return void 0;
|
|
5415
|
-
}
|
|
5416
|
-
const raw = {
|
|
5417
|
-
repository: base.repository,
|
|
5418
|
-
fetchedAt: deps.now(),
|
|
5419
|
-
loaded: merged.length,
|
|
5420
|
-
total,
|
|
5421
|
-
hierarchy: base.hierarchy,
|
|
5422
|
-
tickets: merged,
|
|
5423
|
-
// 后端这次查了身份就用新值;没查(省略)时沿用基准数据里的身份。
|
|
5424
|
-
viewer: changes.viewer === void 0 ? base.viewer : changes.viewer,
|
|
5425
|
-
windowLimit
|
|
5426
|
-
};
|
|
5427
|
-
return await publish(deps, cache, workspaceRoot, resolved, raw, startedAt, "incremental");
|
|
5428
|
-
}
|
|
5429
|
-
function logIncrementalFallback(deps, backend, reason, startedAt) {
|
|
5430
|
-
deps.log("warn", LOG_EVENTS.snapshot, {
|
|
5431
|
-
result: "fallback",
|
|
5432
|
-
backend,
|
|
5433
|
-
stage: SNAPSHOT_STAGES.list,
|
|
5434
|
-
reason,
|
|
5435
|
-
durationMs: Math.max(0, deps.now() - startedAt)
|
|
5436
|
-
});
|
|
5437
|
-
}
|
|
5438
6124
|
async function fetchAndCache(deps, cache, workspaceRoot) {
|
|
5439
6125
|
const startedAt = deps.now();
|
|
5440
6126
|
let kind;
|
|
@@ -5455,7 +6141,7 @@ async function fetchAndCache(deps, cache, workspaceRoot) {
|
|
|
5455
6141
|
return snapshotFailure(mapped.code, mapped.message);
|
|
5456
6142
|
}
|
|
5457
6143
|
}
|
|
5458
|
-
async function publish(deps, cache, workspaceRoot, resolved, raw, startedAt, mode) {
|
|
6144
|
+
async function publish(deps, cache, workspaceRoot, resolved, raw, startedAt, mode, options) {
|
|
5459
6145
|
const repositoryHost = resolved.kind === "markdown" ? null : resolved.address?.host ?? null;
|
|
5460
6146
|
const current = cache.get(workspaceRoot);
|
|
5461
6147
|
const merged = mergePulled(current, raw);
|
|
@@ -5463,6 +6149,7 @@ async function publish(deps, cache, workspaceRoot, resolved, raw, startedAt, mod
|
|
|
5463
6149
|
const resolver = resolved.tracker.resolveBlockers ?? null;
|
|
5464
6150
|
const finalized = resolver === null || !tickets.some((ticket) => ticket.state === "open");
|
|
5465
6151
|
const metrics = metricsOf(deps, resolved.kind, merged, tickets, finalized);
|
|
6152
|
+
const libraryVersion = options?.skipWrite ? options.versionFallback ?? null : await writeStored(deps, workspaceRoot, resolved, merged, metrics);
|
|
5466
6153
|
const snapshot = buildSnapshot(
|
|
5467
6154
|
resolved.kind,
|
|
5468
6155
|
repositoryHost,
|
|
@@ -5472,7 +6159,8 @@ async function publish(deps, cache, workspaceRoot, resolved, raw, startedAt, mod
|
|
|
5472
6159
|
metrics,
|
|
5473
6160
|
"live",
|
|
5474
6161
|
false,
|
|
5475
|
-
null
|
|
6162
|
+
null,
|
|
6163
|
+
libraryVersion
|
|
5476
6164
|
);
|
|
5477
6165
|
cache.set(workspaceRoot, {
|
|
5478
6166
|
kind: resolved.kind,
|
|
@@ -5482,45 +6170,18 @@ async function publish(deps, cache, workspaceRoot, resolved, raw, startedAt, mod
|
|
|
5482
6170
|
resolver,
|
|
5483
6171
|
pending: null
|
|
5484
6172
|
});
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
stage: SNAPSHOT_STAGES.list,
|
|
5490
|
-
durationMs: Math.max(0, deps.now() - startedAt),
|
|
5491
|
-
repository: snapshot.repository,
|
|
5492
|
-
loaded: snapshot.loaded,
|
|
5493
|
-
total: snapshot.total,
|
|
5494
|
-
mode
|
|
5495
|
-
});
|
|
5496
|
-
return { ok: true, result: snapshot };
|
|
5497
|
-
}
|
|
5498
|
-
async function keepOldSnapshot(deps, cache, workspaceRoot, mapped, startedAt) {
|
|
5499
|
-
const refreshError = { code: mapped.code, message: mapped.message };
|
|
5500
|
-
const cached = cache.get(workspaceRoot);
|
|
5501
|
-
if (cached !== void 0) {
|
|
5502
|
-
const snapshot2 = { ...cached.snapshot, stale: true, refreshError };
|
|
5503
|
-
cached.snapshot = snapshot2;
|
|
5504
|
-
deps.log("warn", LOG_EVENTS.snapshot, {
|
|
5505
|
-
result: "error",
|
|
5506
|
-
backend: cached.kind,
|
|
6173
|
+
if (!options?.skipWrite) {
|
|
6174
|
+
deps.log("info", LOG_EVENTS.snapshot, {
|
|
6175
|
+
result: "ok",
|
|
6176
|
+
backend: resolved.kind,
|
|
5507
6177
|
stage: SNAPSHOT_STAGES.list,
|
|
5508
|
-
|
|
5509
|
-
|
|
6178
|
+
durationMs: Math.max(0, deps.now() - startedAt),
|
|
6179
|
+
repository: snapshot.repository,
|
|
6180
|
+
loaded: snapshot.loaded,
|
|
6181
|
+
total: snapshot.total,
|
|
6182
|
+
mode
|
|
5510
6183
|
});
|
|
5511
|
-
return { ok: true, result: snapshot2 };
|
|
5512
6184
|
}
|
|
5513
|
-
const stored = await readStored(deps, workspaceRoot);
|
|
5514
|
-
if (stored === void 0) return snapshotFailure(mapped.code, mapped.message);
|
|
5515
|
-
const snapshot = buildStoredSnapshot(deps, stored, { stale: true, refreshError });
|
|
5516
|
-
cache.set(workspaceRoot, storedEntry(stored, null, snapshot));
|
|
5517
|
-
deps.log("warn", LOG_EVENTS.snapshot, {
|
|
5518
|
-
result: "error",
|
|
5519
|
-
backend: stored.backend,
|
|
5520
|
-
stage: SNAPSHOT_STAGES.list,
|
|
5521
|
-
code: mapped.code,
|
|
5522
|
-
durationMs: Math.max(0, deps.now() - startedAt)
|
|
5523
|
-
});
|
|
5524
6185
|
return { ok: true, result: snapshot };
|
|
5525
6186
|
}
|
|
5526
6187
|
function resolveBlockers(deps, cache, loading, workspaceRoot) {
|
|
@@ -5562,7 +6223,8 @@ async function finalize(deps, cache, workspaceRoot, entry, resolver) {
|
|
|
5562
6223
|
metrics,
|
|
5563
6224
|
entry.snapshot.source,
|
|
5564
6225
|
entry.snapshot.stale,
|
|
5565
|
-
entry.snapshot.refreshError
|
|
6226
|
+
entry.snapshot.refreshError,
|
|
6227
|
+
entry.snapshot.libraryVersion
|
|
5566
6228
|
);
|
|
5567
6229
|
} catch (error) {
|
|
5568
6230
|
failure4 = mapSnapshotError(error);
|
|
@@ -6220,6 +6882,7 @@ function createRpcHandler(scope, run, timer, log) {
|
|
|
6220
6882
|
handle: (method, params) => {
|
|
6221
6883
|
if (method === RPC_METHODS.envCheck) return envCheck.handle(method, params);
|
|
6222
6884
|
if (method === RPC_METHODS.snapshotCache) return snapshot.cache(params);
|
|
6885
|
+
if (method === RPC_METHODS.snapshotRefresh) return snapshot.refresh(params);
|
|
6223
6886
|
if (method === RPC_METHODS.ticketGet || method === RPC_METHODS.ticketUpdate || method === RPC_METHODS.ticketOptions || method === RPC_METHODS.ticketDelete || method === RPC_METHODS.ticketAttachment) {
|
|
6224
6887
|
return ticket.handle(method, params);
|
|
6225
6888
|
}
|