@eyeauras/insight-cli 0.6.6 → 0.8.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 (122) hide show
  1. package/.cli-package-build.json +1 -1
  2. package/SKILL.md +1 -1
  3. package/dist/src/activity-audit.d.ts +130 -0
  4. package/dist/src/activity-audit.js +320 -0
  5. package/dist/src/analysis-storage.d.ts +5 -1
  6. package/dist/src/analysis-storage.js +9 -2
  7. package/dist/src/audit-commands.d.ts +10 -0
  8. package/dist/src/audit-commands.js +85 -0
  9. package/dist/src/audit-retention.d.ts +44 -0
  10. package/dist/src/audit-retention.js +167 -0
  11. package/dist/src/cli.js +28 -6
  12. package/dist/src/context-diagnostics.d.ts +1 -1
  13. package/dist/src/context-diagnostics.js +10 -2
  14. package/dist/src/contexts.d.ts +118 -10
  15. package/dist/src/contexts.js +851 -199
  16. package/dist/src/debugger.js +2 -1
  17. package/dist/src/diagnostic-error.d.ts +12 -0
  18. package/dist/src/diagnostic-error.js +82 -0
  19. package/dist/src/inline-script.js +3 -4
  20. package/dist/src/internal-timing.d.ts +8 -2
  21. package/dist/src/internal-timing.js +50 -7
  22. package/dist/src/lifecycle.d.ts +12 -1
  23. package/dist/src/lifecycle.js +34 -6
  24. package/dist/src/native-inputs.d.ts +6 -0
  25. package/dist/src/native-inputs.js +30 -6
  26. package/dist/src/native-queries.js +1 -6
  27. package/dist/src/native-service.d.ts +40 -0
  28. package/dist/src/native-service.js +406 -0
  29. package/dist/src/research.d.ts +30 -2
  30. package/dist/src/research.js +106 -27
  31. package/dist/src/server.d.ts +38 -1
  32. package/dist/src/server.js +160 -12
  33. package/dist/src/storage-gc.js +374 -341
  34. package/dist/src/sync-policy.js +2 -1
  35. package/dist/src/timed-backend.js +8 -0
  36. package/dist/src/timing-report.d.ts +32 -0
  37. package/dist/src/timing-report.js +74 -0
  38. package/dist/src/tool-runtime/identity.js +86 -1
  39. package/dist/src/tool-runtime/supervisor.js +6 -5
  40. package/dist/src/transport.d.ts +35 -0
  41. package/dist/src/transport.js +95 -16
  42. package/dist/src/unresolved-guidance.d.ts +46 -0
  43. package/dist/src/unresolved-guidance.js +55 -0
  44. package/dist/src/windbg.d.ts +1 -1
  45. package/dist/src/worker-lease.d.ts +17 -0
  46. package/dist/src/worker-lease.js +50 -0
  47. package/dist/src/workspace.d.ts +5 -9
  48. package/dist/src/workspace.js +34 -41
  49. package/package.json +1 -1
  50. package/references/native/InsightHeadlessMain.java +9 -2
  51. package/references/native/InsightNativeCheckout.java +113 -43
  52. package/references/native/InsightNativeFingerprint.java +28 -1
  53. package/references/native/InsightNativeRead.java +32 -9
  54. package/references/native/InsightNativeService.java +43 -0
  55. package/references/native/InsightNativeView.java +17 -6
  56. package/references/native/InsightOwnedScripts.java +170 -0
  57. package/references/native/InsightWorkerLease.java +132 -0
  58. package/references/recovery.md +68 -3
  59. package/references/research.md +71 -6
  60. package/references/setup.md +5 -1
  61. package/skill-bundle/insight-artifacts/SKILL.md +1 -1
  62. package/skill-bundle/insight-artifacts/references/recovery.md +68 -3
  63. package/skill-bundle/insight-binary/SKILL.md +1 -1
  64. package/skill-bundle/insight-capture/SKILL.md +1 -1
  65. package/skill-bundle/insight-cli/SKILL.md +1 -1
  66. package/skill-bundle/insight-cli/references/recovery.md +68 -3
  67. package/skill-bundle/insight-cli/references/setup.md +5 -1
  68. package/skill-bundle/insight-die/SKILL.md +1 -1
  69. package/skill-bundle/insight-dnspy/SKILL.md +1 -1
  70. package/skill-bundle/insight-dotnet-dump/SKILL.md +1 -1
  71. package/skill-bundle/insight-dotnet-stack/SKILL.md +1 -1
  72. package/skill-bundle/insight-dotnet-trace/SKILL.md +1 -1
  73. package/skill-bundle/insight-frida/SKILL.md +1 -1
  74. package/skill-bundle/insight-ghidra/SKILL.md +1 -1
  75. package/skill-bundle/insight-ghidra/references/recovery.md +68 -3
  76. package/skill-bundle/insight-ghidra/references/research.md +71 -6
  77. package/skill-bundle/insight-ghidra/references/setup.md +5 -1
  78. package/skill-bundle/insight-ilspy/SKILL.md +1 -1
  79. package/skill-bundle/insight-interop/SKILL.md +1 -1
  80. package/skill-bundle/insight-lldb/SKILL.md +1 -1
  81. package/skill-bundle/insight-llvm/SKILL.md +1 -1
  82. package/skill-bundle/insight-managed-heap/SKILL.md +1 -1
  83. package/skill-bundle/insight-managed-metadata/SKILL.md +1 -1
  84. package/skill-bundle/insight-mitmproxy/SKILL.md +1 -1
  85. package/skill-bundle/insight-overview/SKILL.md +1 -1
  86. package/skill-bundle/insight-procmon/SKILL.md +1 -1
  87. package/skill-bundle/insight-re/SKILL.md +7 -1
  88. package/skill-bundle/insight-re/references/recovery.md +68 -3
  89. package/skill-bundle/insight-sevenzip/SKILL.md +1 -1
  90. package/skill-bundle/insight-strace/SKILL.md +1 -1
  91. package/skill-bundle/insight-tshark/SKILL.md +1 -1
  92. package/skill-bundle/insight-windbg/SKILL.md +1 -1
  93. package/skill-bundle/manifest.json +1 -1
  94. package/skills/insight-artifacts/SKILL.md +1 -1
  95. package/skills/insight-artifacts/references/recovery.md +68 -3
  96. package/skills/insight-binary/SKILL.md +1 -1
  97. package/skills/insight-capture/SKILL.md +1 -1
  98. package/skills/insight-die/SKILL.md +1 -1
  99. package/skills/insight-dnspy/SKILL.md +1 -1
  100. package/skills/insight-dotnet-dump/SKILL.md +1 -1
  101. package/skills/insight-dotnet-stack/SKILL.md +1 -1
  102. package/skills/insight-dotnet-trace/SKILL.md +1 -1
  103. package/skills/insight-frida/SKILL.md +1 -1
  104. package/skills/insight-ghidra/SKILL.md +1 -1
  105. package/skills/insight-ghidra/references/recovery.md +68 -3
  106. package/skills/insight-ghidra/references/research.md +71 -6
  107. package/skills/insight-ghidra/references/setup.md +5 -1
  108. package/skills/insight-ilspy/SKILL.md +1 -1
  109. package/skills/insight-interop/SKILL.md +1 -1
  110. package/skills/insight-lldb/SKILL.md +1 -1
  111. package/skills/insight-llvm/SKILL.md +1 -1
  112. package/skills/insight-managed-heap/SKILL.md +1 -1
  113. package/skills/insight-managed-metadata/SKILL.md +1 -1
  114. package/skills/insight-mitmproxy/SKILL.md +1 -1
  115. package/skills/insight-overview/SKILL.md +1 -1
  116. package/skills/insight-procmon/SKILL.md +1 -1
  117. package/skills/insight-re/SKILL.md +7 -1
  118. package/skills/insight-re/references/recovery.md +68 -3
  119. package/skills/insight-sevenzip/SKILL.md +1 -1
  120. package/skills/insight-strace/SKILL.md +1 -1
  121. package/skills/insight-tshark/SKILL.md +1 -1
  122. package/skills/insight-windbg/SKILL.md +1 -1
@@ -1,5 +1,6 @@
1
1
  import { lstat, mkdir, open, readdir, readFile, realpath, rename, rm, unlink } from 'node:fs/promises';
2
- import { join } from 'node:path';
2
+ import { join, relative } from 'node:path';
3
+ import { auditEvent, auditHash } from './activity-audit.js';
3
4
  import { createHash, randomUUID } from 'node:crypto';
4
5
  import { createReadStream } from 'node:fs';
5
6
  import { stable } from './model.js';
@@ -172,396 +173,428 @@ export async function collectStorage(workspace, port, dryRun, progress = () => {
172
173
  const native = join(workspace.directory, 'ghidra-native'), retained = [];
173
174
  const reclaimed = new Reclaimed(), categories = {};
174
175
  const id = randomUUID(), receipt = join(workspace.directory, 'gc', id + '.json'), startedAt = new Date().toISOString();
175
- if (!dryRun) {
176
- await mkdir(join(workspace.directory, 'gc'), { recursive: true, mode: 0o700 });
177
- await durable(receipt, { schema: 1, id, state: 'started', startedAt });
178
- }
179
- const keep = (path, reason) => { retained.push({ path, reason }); };
180
- async function remove(path, category) {
181
- const st = await present(path);
182
- if (!st)
183
- return true;
184
- if (st.isSymbolicLink() || !st.isFile() && !st.isDirectory()) {
185
- keep(path, 'Links and special entries are never removed.');
186
- return false;
176
+ auditEvent('gc.started', { gcId: id, dryRun });
177
+ try {
178
+ if (!dryRun) {
179
+ await mkdir(join(workspace.directory, 'gc'), { recursive: true, mode: 0o700 });
180
+ await durable(receipt, { schema: 1, id, state: 'started', startedAt });
187
181
  }
188
- const sizes = new Reclaimed();
189
- await sizes.add(path, category);
190
- if (!dryRun)
182
+ const resource = (path) => {
191
183
  try {
192
- if (st.isDirectory())
193
- await rm(path, { recursive: true, maxRetries: 3 });
194
- else
195
- await unlink(path);
184
+ const locator = relative(workspace.directory, path).replaceAll('\\', '/'), artifact = /^artifacts\/([a-f0-9]{64})\.(gzf|json)$/.exec(locator), context = /^ghidra-native\/context\/(c_[a-f0-9-]{36})\//i.exec(locator);
185
+ return { gcId: id, dryRun, resourceHash: auditHash(locator), ...(context ? { context: context[1] } : {}), ...(artifact ? { artifact: (artifact[2] === 'gzf' ? 'snapshot:' : 'native:') + artifact[1], resourceType: artifact[2] === 'gzf' ? 'snapshot' : 'native-view' } : { resourceType: locator.endsWith('view.rep') || locator.endsWith('view.gpr') ? 'project' : locator.endsWith('.gzf') ? 'export' : locator.endsWith('.cache') ? 'cache' : 'other' }) };
196
186
  }
197
- catch (error) {
198
- keep(path, 'Removal failed: ' + String(error.code));
187
+ catch {
188
+ return { gcId: id, dryRun };
189
+ }
190
+ };
191
+ const keep = (path, reason) => {
192
+ retained.push({ path, reason });
193
+ const code = /[Pp]rivate|differs|additional files/.test(reason) ? 'private-work' : /[Ww]orker|opening|recovery|uncertain|unsettled|unresolved|debugger/.test(reason) ? 'live-or-uncertain' : /reference/.test(reason) ? 'referenced' : /ownership|owner|receipt|unverif/.test(reason) ? 'ownership-unproved' : /private|differs/.test(reason) ? 'private-work' : /capture/.test(reason) ? 'capture-unproved' : /Links/.test(reason) ? 'link-or-special' : /Removal/.test(reason) ? 'removal-failed' : 'other';
194
+ auditEvent('gc.retained', { ...resource(path), reason: code });
195
+ };
196
+ async function remove(path, category) {
197
+ const st = await present(path);
198
+ if (!st)
199
+ return true;
200
+ if (st.isSymbolicLink() || !st.isFile() && !st.isDirectory()) {
201
+ keep(path, 'Links and special entries are never removed.');
199
202
  return false;
200
203
  }
201
- reclaimed.include(sizes);
202
- (categories[category] ??= { items: 0, bytes: 0 }).items++;
203
- return true;
204
- }
205
- // A context participates only when nothing about its private state is uncertain.
206
- const contexts = workspace.allContexts(), safe = new Set(), blockedTargets = new Set(), unsettled = new Set();
207
- const nativeRoots = new Set(contexts.flatMap(c => c.nativeCheckout ? [c.nativeCheckout.root] : [])), artifacts = workspace.allArtifacts(), nativeEvidence = new Set(), nativeProjects = new Map();
208
- let unverifiedNativeReceipt = false;
209
- for (const artifact of artifacts)
210
- if (artifact.kind === 'native')
211
- try {
212
- const view = await json(await workspace.artifacts.verify(artifact));
213
- if (!view) {
214
- unverifiedNativeReceipt = true;
215
- nativeEvidence.add(artifact.id);
204
+ const sizes = new Reclaimed();
205
+ await sizes.add(path, category);
206
+ auditEvent(dryRun ? 'gc.remove.planned' : 'gc.remove.started', { ...resource(path), category });
207
+ if (!dryRun)
208
+ try {
209
+ if (st.isDirectory())
210
+ await rm(path, { recursive: true, maxRetries: 3 });
211
+ else
212
+ await unlink(path);
216
213
  }
217
- else if (view.source === 'checkout') {
218
- const checkout = view.checkout;
219
- if (typeof checkout?.root === 'string') {
220
- nativeRoots.add(checkout.root);
221
- nativeProjects.set(artifact.id, checkout.root);
222
- }
223
- else {
214
+ catch (error) {
215
+ auditEvent('gc.remove.failed', { ...resource(path), category, error, outcome: 'failure' });
216
+ keep(path, 'Removal failed: ' + String(error.code));
217
+ return false;
218
+ }
219
+ if (!dryRun)
220
+ auditEvent('gc.remove.succeeded', { ...resource(path), category, outcome: 'success' });
221
+ reclaimed.include(sizes);
222
+ (categories[category] ??= { items: 0, bytes: 0 }).items++;
223
+ return true;
224
+ }
225
+ // A context participates only when nothing about its private state is uncertain.
226
+ const contexts = workspace.allContexts(), safe = new Set(), blockedTargets = new Set(), unsettled = new Set();
227
+ const nativeRoots = new Set(contexts.flatMap(c => c.nativeCheckout ? [c.nativeCheckout.root] : [])), artifacts = workspace.allArtifacts(), nativeEvidence = new Set(), nativeProjects = new Map();
228
+ let unverifiedNativeReceipt = false;
229
+ for (const artifact of artifacts)
230
+ if (artifact.kind === 'native')
231
+ try {
232
+ const view = await json(await workspace.artifacts.verify(artifact));
233
+ if (!view) {
224
234
  unverifiedNativeReceipt = true;
225
235
  nativeEvidence.add(artifact.id);
226
236
  }
237
+ else if (view.source === 'checkout') {
238
+ const checkout = view.checkout;
239
+ if (typeof checkout?.root === 'string') {
240
+ nativeRoots.add(checkout.root);
241
+ nativeProjects.set(artifact.id, checkout.root);
242
+ }
243
+ else {
244
+ unverifiedNativeReceipt = true;
245
+ nativeEvidence.add(artifact.id);
246
+ }
247
+ }
227
248
  }
228
- }
229
- catch {
230
- unverifiedNativeReceipt = true;
231
- nativeEvidence.add(artifact.id);
232
- }
233
- for (const context of contexts) {
234
- const active = workspace.activePublication(context.target);
235
- let reason;
236
- if (active)
237
- blockedTargets.add(context.target);
238
- if (['opening', 'needs_recovery'].includes(context.state))
239
- reason = 'Context is still opening or requires recovery.';
240
- else if (workspace.unresolved(context).length || workspace.uncertainOutcome(context))
241
- reason = 'Context has an unresolved or uncertain operation.';
242
- else if (active?.session === context.session)
243
- reason = 'Context has an unresolved publication.';
244
- else if (context.debugger?.traces.length || context.debugger?.connected)
245
- reason = 'Context retains debugger state.';
246
- else {
247
- try {
248
- if (!await port.closed(context))
249
- reason = 'Context worker is not proved stopped.';
250
- }
251
- catch {
252
- reason = 'Context worker receipt could not be verified.';
253
- }
254
- if (!reason && context.workingSnapshot)
249
+ catch {
250
+ unverifiedNativeReceipt = true;
251
+ nativeEvidence.add(artifact.id);
252
+ }
253
+ for (const context of contexts) {
254
+ const active = workspace.activePublication(context.target);
255
+ let reason;
256
+ if (active)
257
+ blockedTargets.add(context.target);
258
+ if (['opening', 'needs_recovery'].includes(context.state))
259
+ reason = 'Context is still opening or requires recovery.';
260
+ else if (workspace.unresolved(context).length || workspace.uncertainOutcome(context))
261
+ reason = 'Context has an unresolved or uncertain operation.';
262
+ else if (active?.session === context.session)
263
+ reason = 'Context has an unresolved publication.';
264
+ else if (context.debugger?.traces.length || context.debugger?.connected)
265
+ reason = 'Context retains debugger state.';
266
+ else {
255
267
  try {
256
- await workspace.artifacts.verify(context.workingSnapshot);
268
+ if (!await port.closed(context))
269
+ reason = 'Context worker is not proved stopped.';
257
270
  }
258
271
  catch {
259
- reason = 'Saved private view could not be verified.';
272
+ reason = 'Context worker receipt could not be verified.';
260
273
  }
261
- }
262
- if (reason) {
263
- keep(join(native, 'context', context.id), reason);
264
- unsettled.add(context.target);
265
- }
266
- else
267
- safe.add(context.id);
268
- }
269
- // Ghidra releases clean checkouts itself; their projects are never deleted behind its back.
270
- for (const context of contexts) {
271
- const checkout = context.nativeCheckout, category = 'native-checkouts';
272
- if (!checkout || checkout.state === 'dropped' || !safe.has(context.id) || checkout.conflict || context.scalars.length || context.complexChanges.length)
273
- continue;
274
- if (checkout.state === 'active' && !await present(checkout.root)) {
275
- keep(checkout.root, 'Native checkout project is missing; its server checkout is retained.');
276
- continue;
277
- }
278
- try {
279
- const owner = join(checkout.root, 'native-owner.json');
280
- if (await linked(owner) || !await json(owner)) {
281
- keep(checkout.root, 'Native ownership receipt is missing or unverifiable; its checkout is retained.');
282
- continue;
274
+ if (!reason && context.workingSnapshot)
275
+ try {
276
+ await workspace.artifacts.verify(context.workingSnapshot);
277
+ }
278
+ catch {
279
+ reason = 'Saved private view could not be verified.';
280
+ }
283
281
  }
284
- }
285
- catch {
286
- keep(checkout.root, 'Native ownership receipt could not be verified; its checkout is retained.');
287
- continue;
288
- }
289
- if (workspace.checkoutReferenced(context)) {
290
- keep(checkout.root, 'An unresolved operation in another context references this checkout.');
291
- continue;
292
- }
293
- const project = join(checkout.root, 'view.rep');
294
- if (dryRun) {
295
- if (workspace.unchangedNative(context))
296
- await remove(project, category);
297
- else
298
- keep(checkout.root, 'Saved receipt differs from its shared base and from every recorded pristine open of that version; the checkout may hold private work.');
299
- continue;
300
- }
301
- const sizes = new Reclaimed();
302
- if (await present(project))
303
- await sizes.add(project, category);
304
- try {
305
- progress('Verifying native checkout ' + context.session + ' / ' + context.target);
306
- if (await port.release(context)) {
307
- const row = categories[category] ??= { items: 0, bytes: 0 };
308
- row.items++;
309
- row.bytes += sizes.bytes()[category] ?? 0;
282
+ if (reason) {
283
+ keep(join(native, 'context', context.id), reason);
284
+ unsettled.add(context.target);
310
285
  }
311
286
  else
312
- keep(checkout.root, 'Native checkout is not proved unchanged.');
313
- }
314
- catch (error) {
315
- keep(checkout.root, 'Native release was refused: ' + String(error.message).slice(0, 300));
287
+ safe.add(context.id);
316
288
  }
317
- }
318
- const known = new Set(contexts.map(c => c.id)), captured = new Map(), targetCaptures = new Map(), discarded = new Set(), disposedDetachedRoots = new Set();
319
- for (const context of contexts) {
320
- const snapshots = [];
321
- if (context.workingSnapshot?.kind === 'snapshot')
322
- snapshots.push(context.workingSnapshot);
323
- try {
324
- const migration = await json(join(workspace.directory, 'legacy-migrations', context.target, context.id + '-detached.json'));
325
- const original = migration?.original;
326
- if (migration?.schema === 1 && original?.id === context.id && original.target === context.target && !original.nativeCheckout && original.workingSnapshot?.kind === 'snapshot')
327
- snapshots.push(original.workingSnapshot);
328
- }
329
- catch { /* A damaged migration receipt does not prove a detached capture. */ }
330
- captured.set(context.id, snapshots);
331
- targetCaptures.set(context.target, [...(targetCaptures.get(context.target) ?? []), ...snapshots]);
332
- }
333
- // Only detached roots are reached by the project rule, and a discarded context holds no others.
334
- for (const context of contexts)
335
- if (workspace.legacyDiscarded(context))
336
- discarded.add(context.id);
337
- for (const kind of ['context', 'shared', 'candidate']) {
338
- const parent = join(native, kind);
339
- for (const owner of await directories(parent)) {
340
- if (kind === 'context' && !safe.has(owner)) {
341
- if (!known.has(owner))
342
- keep(join(parent, owner), 'Directory has no matching context.');
289
+ // Ghidra releases clean checkouts itself; their projects are never deleted behind its back.
290
+ for (const context of contexts) {
291
+ const checkout = context.nativeCheckout, category = 'native-checkouts';
292
+ if (!checkout || checkout.state === 'dropped' || !safe.has(context.id) || checkout.conflict || context.scalars.length || context.complexChanges.length)
293
+ continue;
294
+ if (checkout.state === 'active' && !await present(checkout.root)) {
295
+ keep(checkout.root, 'Native checkout project is missing; its server checkout is retained.');
343
296
  continue;
344
297
  }
345
- if (kind !== 'context' && blockedTargets.has(owner)) {
346
- keep(join(parent, owner), 'Target has an unresolved publication.');
298
+ try {
299
+ const owner = join(checkout.root, 'native-owner.json');
300
+ if (await linked(owner) || !await json(owner)) {
301
+ keep(checkout.root, 'Native ownership receipt is missing or unverifiable; its checkout is retained.');
302
+ continue;
303
+ }
304
+ }
305
+ catch {
306
+ keep(checkout.root, 'Native ownership receipt could not be verified; its checkout is retained.');
307
+ continue;
308
+ }
309
+ if (workspace.checkoutReferenced(context)) {
310
+ keep(checkout.root, 'An unresolved operation in another context references this checkout.');
347
311
  continue;
348
312
  }
349
- // A merge or refresh interrupted before its publication row still owns candidate evidence.
350
- if (kind === 'candidate' && unsettled.has(owner)) {
351
- keep(join(parent, owner), 'Target has an unsettled context.');
313
+ const project = join(checkout.root, 'view.rep');
314
+ if (dryRun) {
315
+ if (workspace.unchangedNative(context))
316
+ await remove(project, category);
317
+ else
318
+ keep(checkout.root, 'Ghidra did not report this checkout unmodified when it was last saved or observed; it may hold private work.');
352
319
  continue;
353
320
  }
354
- for (const name of await directories(join(parent, owner))) {
355
- const root = join(parent, owner, name);
356
- if (await realpath(root) !== join(await realpath(parent), owner, name)) {
357
- keep(root, 'Working root moved outside owned storage.');
321
+ const sizes = new Reclaimed();
322
+ if (await present(project))
323
+ await sizes.add(project, category);
324
+ try {
325
+ progress('Verifying native checkout ' + context.session + ' / ' + context.target);
326
+ auditEvent('gc.release.started', { ...resource(checkout.root), category, ...context, context: context.id });
327
+ if (await port.release(context)) {
328
+ const row = categories[category] ??= { items: 0, bytes: 0 };
329
+ row.items++;
330
+ row.bytes += sizes.bytes()[category] ?? 0;
331
+ auditEvent('gc.release.succeeded', { ...resource(checkout.root), category, outcome: 'success', ...context, context: context.id });
332
+ }
333
+ else {
334
+ auditEvent('gc.release.failed', { ...resource(checkout.root), category, reason: 'capture-unproved', outcome: 'failure', ...context, context: context.id });
335
+ keep(checkout.root, 'Native checkout is not proved unchanged.');
336
+ }
337
+ }
338
+ catch (error) {
339
+ auditEvent('gc.release.failed', { ...resource(checkout.root), category, error, outcome: 'failure', ...context, context: context.id });
340
+ keep(checkout.root, 'Native release was refused: ' + String(error.message).slice(0, 300));
341
+ }
342
+ }
343
+ const known = new Set(contexts.map(c => c.id)), captured = new Map(), targetCaptures = new Map(), discarded = new Set(), disposedDetachedRoots = new Set();
344
+ for (const context of contexts) {
345
+ const snapshots = [];
346
+ if (context.workingSnapshot?.kind === 'snapshot')
347
+ snapshots.push(context.workingSnapshot);
348
+ try {
349
+ const migration = await json(join(workspace.directory, 'legacy-migrations', context.target, context.id + '-detached.json'));
350
+ const original = migration?.original;
351
+ if (migration?.schema === 1 && original?.id === context.id && original.target === context.target && !original.nativeCheckout && original.workingSnapshot?.kind === 'snapshot')
352
+ snapshots.push(original.workingSnapshot);
353
+ }
354
+ catch { /* A damaged migration receipt does not prove a detached capture. */ }
355
+ captured.set(context.id, snapshots);
356
+ targetCaptures.set(context.target, [...(targetCaptures.get(context.target) ?? []), ...snapshots]);
357
+ }
358
+ // Only detached roots are reached by the project rule, and a discarded context holds no others.
359
+ for (const context of contexts)
360
+ if (workspace.legacyDiscarded(context))
361
+ discarded.add(context.id);
362
+ for (const kind of ['context', 'shared', 'candidate']) {
363
+ const parent = join(native, kind);
364
+ for (const owner of await directories(parent)) {
365
+ if (kind === 'context' && !safe.has(owner)) {
366
+ if (!known.has(owner))
367
+ keep(join(parent, owner), 'Directory has no matching context.');
358
368
  continue;
359
369
  }
360
- let worker, nativeRoot = false, projectOwnershipReason;
361
- try {
362
- const ownerPresent = Boolean(await present(join(root, 'native-owner.json')));
363
- const creationPath = join(parent, owner, 'checkout.json');
364
- if (kind === 'context' && await linked(creationPath)) {
365
- keep(root, 'Native creation receipt is linked; project ownership is unproved.');
370
+ if (kind !== 'context' && blockedTargets.has(owner)) {
371
+ keep(join(parent, owner), 'Target has an unresolved publication.');
372
+ continue;
373
+ }
374
+ // A merge or refresh interrupted before its publication row still owns candidate evidence.
375
+ if (kind === 'candidate' && unsettled.has(owner)) {
376
+ keep(join(parent, owner), 'Target has an unsettled context.');
377
+ continue;
378
+ }
379
+ for (const name of await directories(join(parent, owner))) {
380
+ const root = join(parent, owner, name);
381
+ if (await realpath(root) !== join(await realpath(parent), owner, name)) {
382
+ keep(root, 'Working root moved outside owned storage.');
366
383
  continue;
367
384
  }
368
- const creation = kind === 'context' ? await json(creationPath) : undefined;
369
- const creationPresent = kind === 'context' && Boolean(await present(creationPath));
370
- const creationRoot = creation?.root;
371
- let locatorUnverified = false;
372
- const locators = [...nativeRoots, ...(typeof creationRoot === 'string' ? [creationRoot] : [])];
373
- const recordedNative = !ownerPresent && locators.some(named => {
374
- if (named === root)
375
- return true;
376
- try {
377
- return sameDirectory(named, root);
385
+ let worker, nativeRoot = false, projectOwnershipReason;
386
+ try {
387
+ const ownerPresent = Boolean(await present(join(root, 'native-owner.json')));
388
+ const creationPath = join(parent, owner, 'checkout.json');
389
+ if (kind === 'context' && await linked(creationPath)) {
390
+ keep(root, 'Native creation receipt is linked; project ownership is unproved.');
391
+ continue;
378
392
  }
379
- catch (error) {
380
- if (!missing(error))
381
- locatorUnverified = true;
382
- return false;
393
+ const creation = kind === 'context' ? await json(creationPath) : undefined;
394
+ const creationPresent = kind === 'context' && Boolean(await present(creationPath));
395
+ const creationRoot = creation?.root;
396
+ let locatorUnverified = false;
397
+ const locators = [...nativeRoots, ...(typeof creationRoot === 'string' ? [creationRoot] : [])];
398
+ const recordedNative = !ownerPresent && locators.some(named => {
399
+ if (named === root)
400
+ return true;
401
+ try {
402
+ return sameDirectory(named, root);
403
+ }
404
+ catch (error) {
405
+ if (!missing(error))
406
+ locatorUnverified = true;
407
+ return false;
408
+ }
409
+ });
410
+ if (!ownerPresent && (recordedNative || locatorUnverified || (creationPresent && typeof creationRoot !== 'string') || unverifiedNativeReceipt)) {
411
+ projectOwnershipReason = 'Native checkout or creation ownership is missing or unverifiable; detached cleanup is not authorized.';
412
+ }
413
+ worker = await json(join(root, 'process.json'));
414
+ nativeRoot = ownerPresent;
415
+ if (!worker && !nativeRoot) {
416
+ keep(root, 'Working root has no worker receipt.');
417
+ continue;
418
+ }
419
+ if (worker && (worker.kind !== kind || (kind === 'context' ? worker.context : worker.target) !== owner)) {
420
+ keep(root, 'Worker receipt belongs to a different owner.');
421
+ continue;
422
+ }
423
+ if (worker && !await stopped(root, worker)) {
424
+ keep(root, 'Worker is not proved stopped.');
425
+ continue;
383
426
  }
384
- });
385
- if (!ownerPresent && (recordedNative || locatorUnverified || (creationPresent && typeof creationRoot !== 'string') || unverifiedNativeReceipt)) {
386
- projectOwnershipReason = 'Native checkout or creation ownership is missing or unverifiable; detached cleanup is not authorized.';
387
427
  }
388
- worker = await json(join(root, 'process.json'));
389
- nativeRoot = ownerPresent;
390
- if (!worker && !nativeRoot) {
391
- keep(root, 'Working root has no worker receipt.');
428
+ catch (error) {
429
+ keep(root, 'Working root worker proof could not be verified: ' + String(error.code ?? 'unavailable'));
392
430
  continue;
393
431
  }
394
- if (worker && (worker.kind !== kind || (kind === 'context' ? worker.context : worker.target) !== owner)) {
395
- keep(root, 'Worker receipt belongs to a different owner.');
396
- continue;
432
+ for (const name of ['ghidra', 'exports', 'explicit-exports'])
433
+ if (await linked(join(root, name)))
434
+ keep(join(root, name), 'Links and special entries are never removed.');
435
+ if (kind === 'context') {
436
+ const context = workspace.contextById(owner), stages = await peerStages(root, { context: owner, target: context.target });
437
+ let ownershipReason;
438
+ if (stages.length)
439
+ try {
440
+ const linkedOwner = await linked(join(root, 'process.json')) || await linked(join(root, 'native-owner.json'));
441
+ const nativeOwner = nativeRoot && !linkedOwner && (await lstat(join(root, 'native-owner.json'))).isFile() ? await json(join(root, 'native-owner.json')) : undefined;
442
+ if (!worker)
443
+ ownershipReason = 'Cross-target working root has no worker receipt that proves it stopped.';
444
+ else if (linkedOwner)
445
+ ownershipReason = 'Cross-target working root ownership receipt is a link.';
446
+ else if (worker && worker.target !== context.target || nativeRoot && (!nativeOwner || nativeOwner.context !== owner || nativeOwner.target !== context.target))
447
+ ownershipReason = 'Cross-target working root receipt belongs to a different owner.';
448
+ else if (typeof worker.root !== 'string' || !sameDirectory(worker.root, root))
449
+ ownershipReason = 'Cross-target worker receipt does not identify this working root.';
450
+ }
451
+ catch (error) {
452
+ ownershipReason = 'Cross-target working root ownership receipt could not be verified: ' + String(error.code ?? 'unavailable');
453
+ }
454
+ for (const stage of stages) {
455
+ if (ownershipReason)
456
+ keep(stage.folder, ownershipReason);
457
+ else if ('reason' in stage)
458
+ keep(stage.folder, stage.reason);
459
+ else if (stage.receipt.state !== 'closed')
460
+ keep(stage.folder, 'Cross-target cleanup is incomplete; its temporary program removal is unverified.');
461
+ else if (workspace.checkoutReferenced(context, root))
462
+ keep(stage.folder, 'An unresolved operation in another context references this checkout.');
463
+ else if (stage.input)
464
+ await remove(stage.input, 'duplicate-exports');
465
+ }
397
466
  }
398
- if (worker && !await stopped(root, worker)) {
399
- keep(root, 'Worker is not proved stopped.');
467
+ // Closed peer exports have their own complete ownership proof, independent of project disposal.
468
+ if (projectOwnershipReason) {
469
+ keep(root, projectOwnershipReason);
400
470
  continue;
401
471
  }
402
- }
403
- catch (error) {
404
- keep(root, 'Working root worker proof could not be verified: ' + String(error.code ?? 'unavailable'));
405
- continue;
406
- }
407
- for (const name of ['ghidra', 'exports', 'explicit-exports'])
408
- if (await linked(join(root, name)))
409
- keep(join(root, name), 'Links and special entries are never removed.');
410
- if (kind === 'context') {
411
- const context = workspace.contextById(owner), stages = await peerStages(root, { context: owner, target: context.target });
412
- let ownershipReason;
413
- if (stages.length)
472
+ const given = kind === 'context' && discarded.has(owner);
473
+ const candidates = kind === 'context' ? captured.get(owner) ?? [] : [...(targetCaptures.get(owner) ?? [])];
474
+ if (kind !== 'context')
414
475
  try {
415
- const linkedOwner = await linked(join(root, 'process.json')) || await linked(join(root, 'native-owner.json'));
416
- const nativeOwner = nativeRoot && !linkedOwner && (await lstat(join(root, 'native-owner.json'))).isFile() ? await json(join(root, 'native-owner.json')) : undefined;
417
- if (!worker)
418
- ownershipReason = 'Cross-target working root has no worker receipt that proves it stopped.';
419
- else if (linkedOwner)
420
- ownershipReason = 'Cross-target working root ownership receipt is a link.';
421
- else if (worker && worker.target !== context.target || nativeRoot && (!nativeOwner || nativeOwner.context !== owner || nativeOwner.target !== context.target))
422
- ownershipReason = 'Cross-target working root receipt belongs to a different owner.';
423
- else if (typeof worker.root !== 'string' || !sameDirectory(worker.root, root))
424
- ownershipReason = 'Cross-target worker receipt does not identify this working root.';
476
+ const shared = workspace.model(owner).sharedSnapshot;
477
+ if (shared?.kind === 'snapshot')
478
+ candidates.push(shared);
425
479
  }
426
- catch (error) {
427
- ownershipReason = 'Cross-target working root ownership receipt could not be verified: ' + String(error.code ?? 'unavailable');
428
- }
429
- for (const stage of stages) {
430
- if (ownershipReason)
431
- keep(stage.folder, ownershipReason);
432
- else if ('reason' in stage)
433
- keep(stage.folder, stage.reason);
434
- else if (stage.receipt.state !== 'closed')
435
- keep(stage.folder, 'Cross-target cleanup is incomplete; its temporary program removal is unverified.');
436
- else if (workspace.checkoutReferenced(context, root))
437
- keep(stage.folder, 'An unresolved operation in another context references this checkout.');
438
- else if (stage.input)
439
- await remove(stage.input, 'duplicate-exports');
480
+ catch { /* Unknown model roots cannot supply capture proof. */ }
481
+ if (!nativeRoot && ((worker?.program !== 'program' && worker?.program !== '/program') || typeof worker.root !== 'string' || !sameDirectory(worker.root, root) || !given && !await detachedCapture(workspace, root, candidates))) {
482
+ keep(root, 'Project has no verified full detached program capture; native JSON receipts do not contain program bytes.');
483
+ continue;
440
484
  }
441
- }
442
- // Closed peer exports have their own complete ownership proof, independent of project disposal.
443
- if (projectOwnershipReason) {
444
- keep(root, projectOwnershipReason);
445
- continue;
446
- }
447
- const given = kind === 'context' && discarded.has(owner);
448
- const candidates = kind === 'context' ? captured.get(owner) ?? [] : [...(targetCaptures.get(owner) ?? [])];
449
- if (kind !== 'context')
450
- try {
451
- const shared = workspace.model(owner).sharedSnapshot;
452
- if (shared?.kind === 'snapshot')
453
- candidates.push(shared);
485
+ let cleanupComplete = true;
486
+ for (const file of await files(join(root, 'ghidra')))
487
+ if (file.endsWith('.cache'))
488
+ cleanupComplete = await remove(join(root, 'ghidra', file), 'temporary-caches') && cleanupComplete;
489
+ if (nativeRoot) {
490
+ // The project itself belongs to its checkout lifecycle, including uncertain creations.
491
+ for (const run of await directories(join(root, 'explicit-exports')))
492
+ await remove(join(root, 'explicit-exports', run, 'program.gzf'), 'duplicate-exports');
493
+ continue;
454
494
  }
455
- catch { /* Unknown model roots cannot supply capture proof. */ }
456
- if (!nativeRoot && ((worker?.program !== 'program' && worker?.program !== '/program') || typeof worker.root !== 'string' || !sameDirectory(worker.root, root) || !given && !await detachedCapture(workspace, root, candidates))) {
457
- keep(root, 'Project has no verified full detached program capture; native JSON receipts do not contain program bytes.');
458
- continue;
459
- }
460
- let cleanupComplete = true;
461
- for (const file of await files(join(root, 'ghidra')))
462
- if (file.endsWith('.cache'))
463
- cleanupComplete = await remove(join(root, 'ghidra', file), 'temporary-caches') && cleanupComplete;
464
- if (nativeRoot) {
465
- // The project itself belongs to its checkout lifecycle, including uncertain creations.
466
- for (const run of await directories(join(root, 'explicit-exports')))
467
- await remove(join(root, 'explicit-exports', run, 'program.gzf'), 'duplicate-exports');
468
- continue;
469
- }
470
- for (const file of await files(join(root, 'exports')))
471
- if (exportName.test(file))
472
- cleanupComplete = await remove(join(root, 'exports', file), 'duplicate-exports') && cleanupComplete;
473
- // Facade edits are captured as they complete; a GUI save is captured only by an explicit close.
474
- const stop = worker && await stopReceipt(root, worker);
475
- if (!given && (!stop || worker?.mode !== 'headless' && stop.reason !== 'explicit_close')) {
476
- keep(join(root, 'view.rep'), 'Project has no clean stop receipt that proves capture.');
477
- continue;
478
- }
479
- if (!await soleProgram(root)) {
480
- keep(join(root, 'view.rep'), 'Project holds additional files.');
481
- continue;
495
+ for (const file of await files(join(root, 'exports')))
496
+ if (exportName.test(file))
497
+ cleanupComplete = await remove(join(root, 'exports', file), 'duplicate-exports') && cleanupComplete;
498
+ // Facade edits are captured as they complete; a GUI save is captured only by an explicit close.
499
+ const stop = worker && await stopReceipt(root, worker);
500
+ if (!given && (!stop || worker?.mode !== 'headless' && stop.reason !== 'explicit_close')) {
501
+ keep(join(root, 'view.rep'), 'Project has no clean stop receipt that proves capture.');
502
+ continue;
503
+ }
504
+ if (!await soleProgram(root)) {
505
+ keep(join(root, 'view.rep'), 'Project holds additional files.');
506
+ continue;
507
+ }
508
+ const projectFiles = ['view.rep', 'view.gpr', 'view.lock', 'view.lock~'];
509
+ for (const file of projectFiles)
510
+ cleanupComplete = await remove(join(root, file), 'detached-projects') && cleanupComplete;
511
+ // Every recognized removal must succeed before its full capture proof can be forgotten.
512
+ if (cleanupComplete && await remove(join(root, 'saved.gzf'), 'duplicate-exports'))
513
+ disposedDetachedRoots.add(root);
482
514
  }
483
- const projectFiles = ['view.rep', 'view.gpr', 'view.lock', 'view.lock~'];
484
- for (const file of projectFiles)
485
- cleanupComplete = await remove(join(root, file), 'detached-projects') && cleanupComplete;
486
- // Every recognized removal must succeed before its full capture proof can be forgotten.
487
- if (cleanupComplete && await remove(join(root, 'saved.gzf'), 'duplicate-exports'))
488
- disposedDetachedRoots.add(root);
489
515
  }
490
516
  }
491
- }
492
- for (const run of await directories(join(native, 'explicit-exports')))
493
- await remove(join(native, 'explicit-exports', run, 'program.gzf'), 'duplicate-exports');
494
- const calls = join(workspace.directory, 'server', 'calls');
495
- for (const call of await directories(calls))
496
- for (const file of await files(join(calls, call, 'ghidra')))
497
- if (file.endsWith('.cache'))
498
- await remove(join(calls, call, 'ghidra', file), 'temporary-caches');
499
- // Roots are live rows, unfinished or failed intents, every user-visible result and VT owners.
500
- const roots = workspace.artifactRoots();
501
- for (const id of nativeEvidence)
502
- roots.add(id);
503
- // Native release above can remove a project and its live context reference in this same pass.
504
- for (const [id, root] of nativeProjects)
505
- try {
506
- if (await present(join(root, 'view.rep')) || await present(join(root, 'view.gpr')))
507
- roots.add(id);
508
- }
509
- catch {
517
+ for (const run of await directories(join(native, 'explicit-exports')))
518
+ await remove(join(native, 'explicit-exports', run, 'program.gzf'), 'duplicate-exports');
519
+ const calls = join(workspace.directory, 'server', 'calls');
520
+ for (const call of await directories(calls))
521
+ for (const file of await files(join(calls, call, 'ghidra')))
522
+ if (file.endsWith('.cache'))
523
+ await remove(join(calls, call, 'ghidra', file), 'temporary-caches');
524
+ // Roots are live rows, unfinished or failed intents, every user-visible result and VT owners.
525
+ const roots = workspace.artifactRoots();
526
+ for (const id of nativeEvidence)
510
527
  roots.add(id);
511
- keep(root, 'Native project inventory could not be verified; its receipt is retained.');
512
- }
513
- // Migration journals keep identity, not artifact liveness. A retained saved.gzf still needs its
514
- // canonical verification copy for the next collection attempt, even after the context migrated.
515
- for (const kind of ['context', 'shared', 'candidate'])
516
- for (const owner of await directories(join(native, kind))) {
517
- const proofs = kind === 'context' ? (discarded.has(owner) ? [] : captured.get(owner) ?? []) : targetCaptures.get(owner) ?? [];
518
- if (!proofs.length)
519
- continue;
520
- for (const name of await directories(join(native, kind, owner))) {
521
- const root = join(native, kind, owner, name);
522
- if (disposedDetachedRoots.has(root))
528
+ // Native release above can remove a project and its live context reference in this same pass.
529
+ for (const [id, root] of nativeProjects)
530
+ try {
531
+ if (await present(join(root, 'view.rep')) || await present(join(root, 'view.gpr')))
532
+ roots.add(id);
533
+ }
534
+ catch {
535
+ roots.add(id);
536
+ keep(root, 'Native project inventory could not be verified; its receipt is retained.');
537
+ }
538
+ // Migration journals keep identity, not artifact liveness. A retained saved.gzf still needs its
539
+ // canonical verification copy for the next collection attempt, even after the context migrated.
540
+ for (const kind of ['context', 'shared', 'candidate'])
541
+ for (const owner of await directories(join(native, kind))) {
542
+ const proofs = kind === 'context' ? (discarded.has(owner) ? [] : captured.get(owner) ?? []) : targetCaptures.get(owner) ?? [];
543
+ if (!proofs.length)
523
544
  continue;
524
- try {
525
- if (!await present(join(root, 'saved.gzf')))
545
+ for (const name of await directories(join(native, kind, owner))) {
546
+ const root = join(native, kind, owner, name);
547
+ if (disposedDetachedRoots.has(root))
526
548
  continue;
549
+ try {
550
+ if (!await present(join(root, 'saved.gzf')))
551
+ continue;
552
+ }
553
+ catch {
554
+ keep(root, 'Retained capture metadata could not be verified; its snapshot proof is preserved.');
555
+ }
556
+ for (const artifact of proofs)
557
+ roots.add(artifact.id);
527
558
  }
528
- catch {
529
- keep(root, 'Retained capture metadata could not be verified; its snapshot proof is preserved.');
530
- }
531
- for (const artifact of proofs)
532
- roots.add(artifact.id);
533
559
  }
560
+ for (const tracking of await directories(join(workspace.directory, 'version-tracking'))) {
561
+ let owner = '';
562
+ try {
563
+ owner = await readFile(join(workspace.directory, 'version-tracking', tracking, 'owner.json'), 'utf8');
564
+ }
565
+ catch (error) {
566
+ if (!missing(error))
567
+ throw error;
568
+ }
569
+ for (const match of owner.matchAll(/(?:snapshot|native):[a-f0-9]{64}/g))
570
+ roots.add(match[0]);
534
571
  }
535
- for (const tracking of await directories(join(workspace.directory, 'version-tracking'))) {
536
- let owner = '';
537
- try {
538
- owner = await readFile(join(workspace.directory, 'version-tracking', tracking, 'owner.json'), 'utf8');
539
- }
540
- catch (error) {
541
- if (!missing(error))
542
- throw error;
572
+ const rows = new Set(workspace.allArtifacts().map(a => a.id));
573
+ if (!dryRun)
574
+ for (const artifact of workspace.allArtifacts())
575
+ if (artifact.kind !== 'input' && !roots.has(artifact.id))
576
+ workspace.forgetArtifact(artifact.id);
577
+ const directory = join(workspace.directory, 'artifacts');
578
+ for (const file of await files(directory)) {
579
+ const match = artifactName.exec(file);
580
+ const id = match && (match[2] === 'gzf' ? 'snapshot:' : 'native:') + match[1];
581
+ // A capture writes its file before its row, so unrowed files are stale only after a day.
582
+ if (id ? !roots.has(id) && (rows.has(id) || await older(join(directory, file), 86400000)) : pendingName.test(file) && await older(join(directory, file), 86400000))
583
+ await remove(join(directory, file), 'unreferenced-snapshots');
543
584
  }
544
- for (const match of owner.matchAll(/(?:snapshot|native):[a-f0-9]{64}/g))
545
- roots.add(match[0]);
585
+ for (const [category, bytes] of Object.entries(reclaimed.bytes()))
586
+ if (categories[category])
587
+ categories[category].bytes += bytes;
588
+ const result = { state: dryRun ? 'planned' : 'complete', dryRun, bytes: Object.values(categories).reduce((n, c) => n + c.bytes, 0), categories, retainedCount: retained.length };
589
+ if (!dryRun)
590
+ await durable(receipt, { schema: 1, id, startedAt, endedAt: new Date().toISOString(), ...result, retained });
591
+ for (const [category, value] of Object.entries(categories))
592
+ auditEvent('gc.category', { gcId: id, dryRun, category, ...value });
593
+ auditEvent('gc.finished', { gcId: id, ...result, outcome: 'success' });
594
+ return { ...result, ...(dryRun ? {} : { id }), retained: retained.slice(0, 200) };
546
595
  }
547
- const rows = new Set(workspace.allArtifacts().map(a => a.id));
548
- if (!dryRun)
549
- for (const artifact of workspace.allArtifacts())
550
- if (artifact.kind !== 'input' && !roots.has(artifact.id))
551
- workspace.forgetArtifact(artifact.id);
552
- const directory = join(workspace.directory, 'artifacts');
553
- for (const file of await files(directory)) {
554
- const match = artifactName.exec(file);
555
- const id = match && (match[2] === 'gzf' ? 'snapshot:' : 'native:') + match[1];
556
- // A capture writes its file before its row, so unrowed files are stale only after a day.
557
- if (id ? !roots.has(id) && (rows.has(id) || await older(join(directory, file), 86400000)) : pendingName.test(file) && await older(join(directory, file), 86400000))
558
- await remove(join(directory, file), 'unreferenced-snapshots');
596
+ catch (error) {
597
+ auditEvent('gc.failed', { gcId: id, dryRun, error, outcome: 'failure' });
598
+ throw error;
559
599
  }
560
- for (const [category, bytes] of Object.entries(reclaimed.bytes()))
561
- if (categories[category])
562
- categories[category].bytes += bytes;
563
- const result = { state: dryRun ? 'planned' : 'complete', dryRun, bytes: Object.values(categories).reduce((n, c) => n + c.bytes, 0), categories, retainedCount: retained.length };
564
- if (!dryRun)
565
- await durable(receipt, { schema: 1, id, startedAt, endedAt: new Date().toISOString(), ...result, retained });
566
- return { ...result, ...(dryRun ? {} : { id }), retained: retained.slice(0, 200) };
567
600
  }