@melite/estate-queue 0.1.5-pre-alpha → 0.2.2-alpha

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 (82) hide show
  1. package/LICENSE +561 -457
  2. package/README.md +0 -5
  3. package/lib/cardsArmError.d.ts +52 -3
  4. package/lib/cardsArmError.js +7 -1
  5. package/lib/cardsCompose.d.ts +31 -0
  6. package/lib/cardsCompose.js +98 -7
  7. package/lib/cardsFacts.d.ts +16 -0
  8. package/lib/cardsFacts.js +25 -1
  9. package/lib/cardsLanes.d.ts +51 -3
  10. package/lib/cardsLanes.js +337 -13
  11. package/lib/cardsLanesCopy.d.ts +21 -0
  12. package/lib/cardsLanesCopy.js +22 -0
  13. package/lib/cardsRegistry.d.ts +105 -5
  14. package/lib/cardsRegistry.js +826 -46
  15. package/lib/cardsVariant.d.ts +12 -7
  16. package/lib/cardsVariant.js +196 -58
  17. package/lib/discloseRegistry.d.ts +41 -6
  18. package/lib/discloseRegistry.js +155 -17
  19. package/lib/filmLead.js +5 -3
  20. package/lib/flowsData.d.ts +77 -21
  21. package/lib/flowsData.js +159 -21
  22. package/lib/flowsFamilyCompose.js +12 -1
  23. package/lib/flowsRegistryRows.d.ts +0 -3
  24. package/lib/flowsRegistryRows.js +166 -222
  25. package/lib/index.d.ts +1 -1
  26. package/lib/index.js +6 -4
  27. package/lib/loadPlane.d.ts +46 -4
  28. package/lib/loadPlane.js +116 -7
  29. package/lib/loadRegistry.js +9 -2
  30. package/lib/manageOps.js +2 -1
  31. package/lib/managePlane.d.ts +16 -1
  32. package/lib/managePlane.js +955 -65
  33. package/lib/managePreflight.d.ts +26 -0
  34. package/lib/managePreflight.js +211 -0
  35. package/lib/manageProbe.d.ts +52 -0
  36. package/lib/manageProbe.js +171 -1
  37. package/lib/queueCore.d.ts +14 -1
  38. package/lib/queueCore.js +13 -0
  39. package/lib/queueLock.js +19 -10
  40. package/lib/queueResurrect.d.ts +7 -5
  41. package/lib/queueResurrect.js +25 -9
  42. package/lib/queueRetry.d.ts +12 -10
  43. package/lib/queueRetry.js +2 -4
  44. package/lib/queueSidecar.d.ts +122 -1
  45. package/lib/queueSidecar.js +192 -7
  46. package/lib/queueSubmit.d.ts +70 -4
  47. package/lib/queueSubmit.js +159 -7
  48. package/lib/runsErrorCodes.js +5 -3
  49. package/lib/runsExecute.d.ts +16 -1
  50. package/lib/runsExecute.js +97 -39
  51. package/lib/runsGates.d.ts +16 -4
  52. package/lib/runsGates.js +17 -5
  53. package/lib/runsList.d.ts +100 -4
  54. package/lib/runsList.js +364 -63
  55. package/lib/runsRefusalVoices.js +50 -1
  56. package/lib/runsRegistry.d.ts +142 -9
  57. package/lib/runsRegistry.js +960 -163
  58. package/lib/runsStart.d.ts +30 -7
  59. package/lib/runsStart.js +136 -14
  60. package/lib/runsTypes.d.ts +46 -3
  61. package/lib/runsTypes.js +63 -9
  62. package/lib/runsValidate.d.ts +1 -0
  63. package/lib/runsValidate.js +5 -0
  64. package/lib/runsValidateArms.js +25 -0
  65. package/lib/runsValidateServe.js +25 -12
  66. package/lib/runsValidateShared.d.ts +8 -1
  67. package/lib/runsValidateShared.js +44 -4
  68. package/lib/runsValidateStages.d.ts +1 -1
  69. package/lib/runsValidateStages.js +107 -55
  70. package/lib/runtimeProvision.d.ts +119 -0
  71. package/lib/runtimeProvision.js +243 -0
  72. package/lib/skillAuthored.d.ts +50 -0
  73. package/lib/skillAuthored.js +178 -0
  74. package/lib/skillPlane.d.ts +40 -2
  75. package/lib/skillPlane.js +63 -13
  76. package/lib/skillRegistry.d.ts +24 -1
  77. package/lib/skillRegistry.js +69 -5
  78. package/lib/skillRows.d.ts +13 -3
  79. package/lib/skillRows.js +49 -5
  80. package/package.json +33 -23
  81. package/lib/resurrect.d.ts +0 -6
  82. package/lib/resurrect.js +0 -18
package/lib/runsList.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { servableLeaf } from "@melite/contracts/mediaKinds";
2
+ import { ARCHIVED_DIR_NAME } from "@melite/contracts/mediaKinds";
3
+ import { draftIdOf } from "@melite/contracts/benchStage";
2
4
  // runsList.ts — the runs LIST surface (REBUILD-7, gateway kill):
3
5
  // the retired runs door's list arm (GET /v1/flows/runs, the restore port) re-homed verbatim into the queue package as the registry's `list` business arm.
4
6
  // The sidecar byte-surgery helpers are the door's own bodies, second move unchanged (the section notes below name the reader each helper implements).
@@ -34,6 +36,21 @@ export function sidecarNum(text, key, dflt) {
34
36
  return dflt;
35
37
  return parseLeadingInt(text.slice(i + needle.length));
36
38
  }
39
+ /** sidecar_bool: first `"key":`, skip spaces/tabs, expect the
40
+ * `true`/`false` literal — default when the key is absent or
41
+ * non-boolean (never guessed; a torn write reads the default). */
42
+ export function sidecarBool(text, key, dflt) {
43
+ const needle = '"' + key + '":';
44
+ const i = text.indexOf(needle);
45
+ if (i < 0)
46
+ return dflt;
47
+ const tail = text.slice(i + needle.length).replace(/^[ \t]+/, "");
48
+ if (tail.startsWith("true"))
49
+ return true;
50
+ if (tail.startsWith("false"))
51
+ return false;
52
+ return dflt;
53
+ }
37
54
  /** sidecar_str: BYTE-wise exact — first `"key":`, skip spaces/tabs, expect `"`, decode \\n \\r \\t \" \\ (any other escape lands literally — \u stays "u"), stop at cap-1 BYTES. Operates on the UTF-8 bytes (D5). */
38
55
  export function sidecarStr(raw, key, cap) {
39
56
  const pat = Buffer.from('"' + key + '":', "utf8");
@@ -237,19 +254,122 @@ export function runArtifacts(runDir, outDirLiteral) {
237
254
  : [named.find((art) => art['name'] === film), ...named.filter((art) => art['name'] !== film)];
238
255
  return marker === undefined ? ordered : [...ordered, marker];
239
256
  }
240
- /** _run_thumbnail: cached poster wins, else the first image candidate (same one-level rule, so nested-only runs still get a poster). */
257
+
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+ export function runArchivedArtifacts(runDir, outDirLiteral) {
270
+ const runBase = (() => {
271
+ const stripped = outDirLiteral.replace(/\/+$/, "");
272
+ const slash = stripped.lastIndexOf("/");
273
+ return slash >= 0 ? stripped.slice(slash + 1) : stripped;
274
+ })();
275
+ const out = [];
276
+ const push = (rel, full) => {
277
+ const base = rel.includes("/")
278
+ ? rel.slice(rel.lastIndexOf("/") + 1)
279
+ : rel;
280
+ const t = artifactType(base);
281
+ if (t !== "image" && t !== "video" && t !== "audio" && t !== "model" && t !== "text")
282
+ return;
283
+ const size = fileSize(full);
284
+ if (size < 0)
285
+ return;
286
+ out.push({
287
+ name: base,
288
+ path: outDirLiteral + "/" + ARCHIVED_DIR_NAME + "/" + rel,
289
+ bytes: size,
290
+ url: runBase + "/" + ARCHIVED_DIR_NAME + "/" + rel,
291
+ type: t,
292
+ size,
293
+ });
294
+ };
295
+ let tops;
296
+ try {
297
+ tops = readdirSync(join(runDir, ARCHIVED_DIR_NAME));
298
+ }
299
+ catch {
300
+ return [];
301
+ }
302
+ tops.sort(byteLess);
303
+ const subs = [];
304
+ for (const name of tops) {
305
+ if (!servableLeaf(name))
306
+ continue;
307
+ const full = join(runDir, ARCHIVED_DIR_NAME, name);
308
+ if (isDir(full))
309
+ subs.push(name);
310
+ else
311
+ push(name, full);
312
+ }
313
+ subs.sort(byteLess);
314
+ for (const sub of subs) {
315
+ let inner;
316
+ try {
317
+ inner = readdirSync(join(runDir, ARCHIVED_DIR_NAME, sub));
318
+ }
319
+ catch {
320
+ continue;
321
+ }
322
+ inner.sort(byteLess);
323
+ for (const name of inner) {
324
+ if (!servableLeaf(name))
325
+ continue;
326
+ const full = join(runDir, ARCHIVED_DIR_NAME, sub, name);
327
+ if (isDir(full))
328
+ continue;
329
+ push(sub + "/" + name, full);
330
+ }
331
+ }
332
+ return out;
333
+ }
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
241
347
  export function runThumbnail(runDir, runId) {
242
348
  try {
243
349
  statSync(join(runDir, "_poster.jpg"));
244
350
  return runId + "/_poster.jpg";
245
351
  }
246
352
  catch {
247
- /* no poster — fall through to first image */
353
+ /* no poster — fall through to the deliverable law */
354
+ }
355
+ const cands = mediaCandidates(runDir);
356
+ const baseOf = (rel) => (rel.includes("/")
357
+ ? rel.slice(rel.lastIndexOf("/") + 1)
358
+ : rel);
359
+ for (const cand of cands) {
360
+ const base = baseOf(cand.rel);
361
+ if (artifactType(base) === "video" && engineFilmName([base]) !== null) {
362
+ return runId + "/" + cand.rel;
363
+ }
248
364
  }
249
- for (const cand of mediaCandidates(runDir)) {
250
- const base = cand.rel.includes("/")
251
- ? cand.rel.slice(cand.rel.lastIndexOf("/") + 1)
252
- : cand.rel;
365
+ for (const cand of cands) {
366
+ const base = baseOf(cand.rel);
367
+ if (artifactType(base) === "video") {
368
+ return runId + "/" + cand.rel;
369
+ }
370
+ }
371
+ for (const cand of cands) {
372
+ const base = baseOf(cand.rel);
253
373
  if (artifactType(base) === "image") {
254
374
  return runId + "/" + cand.rel;
255
375
  }
@@ -305,8 +425,14 @@ export function runDirHasMedia(runDir) {
305
425
  // The estate's own emitter half (runArtifacts in this file) counts "model" rows as listable media, mediaKinds.ts carries the galleryModel set, and the img-to-mesh lane is the first producer of model-only runs.
306
426
  // Keeping the image-era refusal would drop every completed model run from the restore port (runs/list) — and with it runs/list adoption (fetchLatestRunForDraft) — so the row gate admits "model" alongside the triple.
307
427
  const RUN_ID_RE = /^run-[A-Za-z0-9_.@-]+$/;
308
- // NOT runsTypes.ts's exported RUN_STATUSES: this set is the list-side vocabulary (adds success/unknown, drops queued/stopping — the C-contract fold runsRegistry owns).
428
+ // NOT runsTypes.ts's exported RUN_STATUSES: this set is the list-side
429
+ // vocabulary (adds success/unknown, drops stopping — the C-contract fold
430
+
431
+ // sidecar word serves VERBATIM on the row (the read never folds queued
432
+ // into a terminal word, and refusing the row would vanish a queued run
433
+ // from the very face that must show it — the burn's neighbor defect).
309
434
  const RUN_STATUS = new Set([
435
+ "queued",
310
436
  "running",
311
437
  "completed",
312
438
  "failed",
@@ -361,6 +487,15 @@ export function runRowOrNull(row) {
361
487
  if (!artifactRowOk(a))
362
488
  return null;
363
489
  }
490
+ for (const a of row.archived ?? []) {
491
+ if (!artifactRowOk(a))
492
+ return null;
493
+ }
494
+ // a half-shaped truncation verdict refuses the row whole (the
495
+ // gate's own law: never serve a shape it cannot vouch for)
496
+ if (row.truncated !== undefined
497
+ && !(isIntGe0(row.truncated.listed) && isIntGe0(row.truncated.total)))
498
+ return null;
364
499
  return {
365
500
  run_id: row.run_id,
366
501
  name: row.name,
@@ -374,8 +509,18 @@ export function runRowOrNull(row) {
374
509
  params: row.params,
375
510
  draft_id: row.draft_id,
376
511
  ...(row.stage_ids !== undefined && row.stage_ids.length > 0 ? { stage_ids: [...row.stage_ids] } : {}),
512
+ // THE BENCH INCARNATION rides beside the digest it joins with
513
+ // (W-3 / F3-11); absent stamps stay absent.
514
+ ...(typeof row.bench_epoch === "string" && row.bench_epoch !== "" ? { bench_epoch: row.bench_epoch } : {}),
377
515
  ...(typeof row.export_name === "string" && row.export_name !== "" ? { export_name: row.export_name } : {}),
378
516
  ...(typeof row.export_path === "string" && row.export_path !== "" ? { export_path: row.export_path } : {}),
517
+ ...(row.truncated !== undefined && isIntGe0(row.truncated.listed) && isIntGe0(row.truncated.total)
518
+ ? { truncated: { listed: row.truncated.listed, total: row.truncated.total } }
519
+ : {}),
520
+ ...(row.archived !== undefined && row.archived.length > 0 ? { archived: row.archived } : {}),
521
+ // the TEST STAMP rides ALWAYS (the live face's law — a missing
522
+ // key would read as "unstamped", never as production).
523
+ test: row.test === true,
379
524
  };
380
525
  }
381
526
  /** Strict int parse: surrounding whitespace stripped, one optional
@@ -401,59 +546,110 @@ export function firstQuery(qs, name, dflt) {
401
546
  }
402
547
  return dflt;
403
548
  }
404
- /** The single-root scan (the file-era walk, intact): PROD output
405
- * root only (test runs never listed — kept 1:1). */
406
- function scanRunsRoot(stateRoot) {
407
- // The PROD output root only (the door's list scanned
408
- // roots.runsRoot; test runs never listed — kept 1:1).
409
- const outputRoot = join(stateRoot, "output");
410
- let names;
549
+ /** The filter's row law: every STATED key must hold on the served
550
+ * row (AND, never OR). Absent filter serves every row. */
551
+ function runsFilterServes(row, filter) {
552
+ if (filter.draftId !== undefined && row["draft_id"] !== filter.draftId)
553
+ return false;
554
+ if (filter.benchStageId !== undefined) {
555
+ const ids = row["stage_ids"];
556
+
557
+ // Array.isArray narrows unknown to any[] — the membership test
558
+ // needs no cast, and a cast here would mint a new as-unknown
559
+ // site the census refuses.
560
+ if (!Array.isArray(ids) || !ids.includes(filter.benchStageId))
561
+ return false;
562
+ }
563
+ return true;
564
+ }
565
+ const scanCache = new Map();
566
+ function mtimeMsOf(path) {
411
567
  try {
412
- names = readdirSync(outputRoot);
568
+ return statSync(path).mtimeMs;
569
+ }
570
+ catch {
571
+ return -1;
572
+ }
573
+ }
574
+ function scanRunEnt(runDir) {
575
+ // TWO KEYS, one convergence law: the DIR mtime bumps when a file
576
+ // lands at the top level, but a run that writes its artifacts one
577
+ // level down never bumps it. The SIDECAR mtime closes that hole —
578
+ // the registry rewrites _flow.json on every status transition, so
579
+ // the final write (completed) lands AFTER the last artifact
580
+ // wherever it went, and any sidecar rewrite re-opens the dir for
581
+ // one fresh scan. Warm cost per run: two stats, zero reads.
582
+ const dirMtime = mtimeMsOf(runDir);
583
+ const flowMtime = mtimeMsOf(join(runDir, "_flow.json"));
584
+ if (dirMtime < 0 && flowMtime < 0)
585
+ return undefined;
586
+ const hit = scanCache.get(runDir);
587
+ if (hit !== undefined && hit.dirMtime === dirMtime && hit.flowMtime === flowMtime)
588
+ return hit;
589
+ let created = 0;
590
+ let buf = "";
591
+ try {
592
+ buf = readFileSync(join(runDir, "_flow.json"), "utf8").slice(0, 8191);
413
593
  }
414
594
  catch {
415
- names = [];
595
+ buf = "";
416
596
  }
597
+ if (buf) {
598
+ // created_at (sidecar) first, "created" (C fossil) fallback.
599
+ created = sidecarNum(buf, "created", 0);
600
+ const at = buf.indexOf('"created_at":');
601
+ if (at >= 0)
602
+ created = parseLeadingInt(buf.slice(at + 13));
603
+ }
604
+ const ent = { dirMtime, flowMtime, created, media: runDirHasMedia(runDir) };
605
+ scanCache.set(runDir, ent);
606
+ return ent;
607
+ }
608
+ function scanRunsRoot(stateRoot) {
609
+ // BOTH out seats (the visible-bench law): production first, then
610
+ // test — a same-id collision serves production.
417
611
  const ents = [];
418
- for (const name of names) {
419
- if (ents.length >= 8192)
420
- break; // the C's 8192 collected cap
421
- if (!name.startsWith("run-"))
422
- continue;
423
- const runDir = join(outputRoot, name);
424
- let created = 0;
425
- let buf = "";
612
+ const seen = new Set();
613
+ for (const seat of ["output", "test-output"]) {
614
+ const seatRoot = join(stateRoot, seat);
615
+ let names;
426
616
  try {
427
- buf = readFileSync(join(runDir, "_flow.json"), "utf8").slice(0, 8191);
617
+ names = readdirSync(seatRoot);
428
618
  }
429
619
  catch {
430
- buf = "";
620
+ continue;
431
621
  }
432
- if (buf) {
433
- // created_at (sidecar) first, "created" (C fossil) fallback.
434
- created = sidecarNum(buf, "created", 0);
435
- const at = buf.indexOf('"created_at":');
436
- if (at >= 0)
437
- created = parseLeadingInt(buf.slice(at + 13));
622
+ for (const name of names) {
623
+ if (ents.length >= 8192)
624
+ break; // the C's 8192 collected cap
625
+ if (!name.startsWith("run-"))
626
+ continue;
627
+ if (seen.has(name))
628
+ continue;
629
+ seen.add(name);
630
+ const ent = scanRunEnt(join(seatRoot, name));
631
+ if (ent === undefined)
632
+ continue;
633
+ ents.push({
634
+ dir: name,
635
+ created: ent.created,
636
+ media: ent.media,
637
+ root: stateRoot,
638
+ seat,
639
+ });
438
640
  }
439
- ents.push({
440
- dir: name,
441
- created,
442
- media: runDirHasMedia(runDir),
443
- root: stateRoot,
444
- });
445
641
  }
446
642
  return ents;
447
643
  }
448
- /** The per-run card build (the file-era row law, intact): sidecar
449
- * byte-scan → zombie override → user-surface skip → orphan-draft
450
- * clearing → runRowOrNull. Null = skipped (never stored, never
451
- * served — the count still counts the dir). The drafts probe is
452
- * ASYNC (the drafts remote's birth-certificate face — the legacy
453
- * drafts/<id>.json stat died with the drafts-door migration;
454
- * orphans lose their draft link, never the row). */
644
+ const rowCache = new Map();
455
645
  async function buildRunCard(outputRoot, ent, hasDraft) {
456
646
  const runDir = join(outputRoot, ent.dir);
647
+ const dirMtime = mtimeMsOf(runDir);
648
+ const flowMtime = mtimeMsOf(join(runDir, "_flow.json"));
649
+ const cached = rowCache.get(runDir);
650
+ if (cached !== undefined && cached.dirMtime === dirMtime && cached.flowMtime === flowMtime) {
651
+ return applyDraftOverlay(cached.row, hasDraft);
652
+ }
457
653
  let buf = null;
458
654
  // NO sidecar (ENOENT) is the file-era completed-run law: it reads
459
655
  // the "success" default, pinned by runs-list.spec. A sidecar that
@@ -472,19 +668,33 @@ async function buildRunCard(outputRoot, ent, hasDraft) {
472
668
  let prompt = "";
473
669
  let draft = "";
474
670
  let stageIdsRaw = "";
671
+ // THE BENCH INCARNATION (W-3 / F3-11): "" = the sidecar named no
672
+ // epoch (pre-cure run) — the row key stays absent, never guessed.
673
+ let benchEpoch = "";
475
674
  let exported = "";
476
675
  let exportedPath = "";
477
676
  let seed = -1;
677
+ // THE TEST FLAG, READ (visible-bench law): the row's own
678
+ // sidecar names the seat it rode — the writer persists `test`
679
+ // (queueSidecar's IDENTITY KEYS); absent reads production for
680
+ // pre-cure trees, and NO sidecar (ENOENT) is production, same
681
+ // as the completed-run default above.
682
+ let testFlag = false;
478
683
  let created = ent.created;
479
684
  const rawBytes = buf === null ? Buffer.alloc(0) : Buffer.from(buf, "utf8");
480
685
  if (buf !== null) {
481
686
  // found-ness matters: absent key -> "unknown" (served); present-but-empty -> "" (gate-skipped).
482
687
  const [foundStatus, rawStatus] = sidecarStrFound(rawBytes, "status", 16);
483
688
  if (foundStatus) {
689
+
690
+ // word (queued/running) carries VERBATIM until the settle
691
+ // rewrites the sidecar — the read never stamps a terminal word
692
+ // on a non-terminal run. The burn: a queue-window read served
693
+ // "failed" (the old disk-only zombie override) while run_status
694
+ // said "completed" — the artifact was real. Zombies are the
695
+ // boot sweep's (queueSweep.bootSweep), not a read-time guess.
696
+ // "error" stays the one lawful normalization (terminal word).
484
697
  status = rawStatus === "error" ? "failed" : rawStatus;
485
- // read-time zombie override (sweep=False: report only, D1).
486
- if (status === "running")
487
- status = "failed";
488
698
  }
489
699
  else {
490
700
  status = "unknown";
@@ -496,6 +706,14 @@ async function buildRunCard(outputRoot, ent, hasDraft) {
496
706
  // absent on pre-digest sidecars (the export_name precedent:
497
707
  // optional key, never guessed).
498
708
  stageIdsRaw = sidecarStr(rawBytes, "stage_ids", 512);
709
+
710
+ // draft doc's `epoch` at press rides the identity prefix — the
711
+ // bench read's join requires equality alongside draft_id, so a
712
+ // post-clear read binds only post-clear runs. Additive optional
713
+ // key (the export_path law): absent on pre-cure sidecars, never
714
+ // guessed.
715
+ const [foundEpoch, rawEpoch] = sidecarStrFound(rawBytes, "bench_epoch", 96);
716
+ benchEpoch = foundEpoch ? rawEpoch : "";
499
717
  // THE EXPORT NAME, LISTED (023's self-critique #4/#6): the
500
718
  // design lane's mint rides the list row too — additive, same
501
719
  // spelling as the sidecar; absent on non-export runs.
@@ -505,17 +723,27 @@ async function buildRunCard(outputRoot, ent, hasDraft) {
505
723
  // root is long, so the slice budget doubles the name's.
506
724
  exportedPath = sidecarStr(rawBytes, "export_path", 256);
507
725
  seed = sidecarNum(buf, "seed", -1);
726
+ testFlag = sidecarBool(buf, "test", false);
508
727
  const at = buf.indexOf('"created_at":');
509
728
  if (at >= 0)
510
729
  created = parseLeadingInt(buf.slice(at + 13));
511
730
  }
512
731
  if (pipeline.startsWith("_"))
513
732
  return null; // user-surface law
514
- if (draft && !(await hasDraft(draft))) {
515
- draft = "";
516
- }
517
- const literal = "./output/" + ent.dir;
518
- const row = runRowOrNull({
733
+ const literal = "./" + ent.seat + "/" + ent.dir;
734
+ const arts = runArtifacts(runDir, literal);
735
+
736
+ // rides the artifact list's tail, but the panel's capped counter
737
+ // reads the run row's `truncated` FIELD — stamp it beside the list
738
+ // so a 3-of-6 listing never reads as complete (the grid says a
739
+ // product is missing).
740
+ const truncMarker = arts.find((a) => a["truncated"] === true);
741
+ // THE ARCHIVED FACE (mass-archive law): the tuck's rows ride the
742
+ // row beside the live list — the live walk never sees them (the
743
+ // `_archived/` dir fails the servable law at the top level), so
744
+ // this second sweep is the only reader that opens that dir.
745
+ const archivedArts = runArchivedArtifacts(runDir, literal);
746
+ const built = runRowOrNull({
519
747
  run_id: ent.dir,
520
748
  name: pipeline,
521
749
  flow: pipeline,
@@ -524,19 +752,78 @@ async function buildRunCard(outputRoot, ent, hasDraft) {
524
752
  prompt,
525
753
  seed,
526
754
  thumbnail: runThumbnail(runDir, ent.dir),
527
- artifacts: runArtifacts(runDir, literal),
755
+ artifacts: arts,
756
+ ...(truncMarker !== undefined
757
+ ? { truncated: { listed: truncMarker["listed"], total: truncMarker["total"] } }
758
+ : {}),
759
+ ...(archivedArts.length > 0 ? { archived: archivedArts } : {}),
528
760
  params: { seed },
529
761
  draft_id: draft,
530
762
  ...(stageIdsRaw !== "" ? { stage_ids: stageIdsRaw.split(",") } : {}),
763
+ // THE BENCH INCARNATION, LISTED (W-3 / F3-11): beside the digest
764
+ // it stamps — the bench read's join half. Absent stamps stay
765
+ // absent (the export_name law).
766
+ ...(benchEpoch !== "" ? { bench_epoch: benchEpoch } : {}),
531
767
  ...(exported !== "" ? { export_name: exported } : {}),
532
768
  ...(exportedPath !== "" ? { export_path: exportedPath } : {}),
769
+ test: testFlag,
533
770
  });
534
- return row; // null = RESILIENCE LAW loud skip
771
+ if (built === null)
772
+ return null; // user-surface / RESILIENCE LAW loud skip — never cached
773
+ // TORN reads are transient (permissions, torn mid-write): caching
774
+ // one would freeze "unknown" while the mtimes hold. Clean reads
775
+ // (and absent sidecars — their APPEARANCE moves the flow key)
776
+ // cache.
777
+ if (!torn)
778
+ rowCache.set(runDir, { dirMtime, flowMtime, row: built });
779
+ return applyDraftOverlay(built, hasDraft);
780
+ }
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+ export function noteRunTreeChanged(mutatedPath) {
800
+ const seg = mutatedPath.split(/[/\\]+/).find((s) => RUN_ID_RE.test(s));
801
+ if (seg === undefined)
802
+ return;
803
+ for (const key of [...rowCache.keys()]) {
804
+ if (key.replace(/[/\\]+$/, "").split(/[/\\]/).pop() === seg)
805
+ rowCache.delete(key);
806
+ }
807
+ for (const key of [...scanCache.keys()]) {
808
+ if (key.replace(/[/\\]+$/, "").split(/[/\\]/).pop() === seg)
809
+ scanCache.delete(key);
810
+ }
811
+ }
812
+ /** The FRESH overlay on a served row: the draft probe is registry
813
+ * state, never disk truth — it re-runs on every serve, mutating a
814
+ * CLONE so the cache never learns the probe's answer. */
815
+ async function applyDraftOverlay(row, hasDraft) {
816
+ const served = structuredClone(row);
817
+ const draft = served["draft_id"];
818
+ if (typeof draft === "string" && draft !== "" && !(await hasDraft(draftIdOf(draft)))) {
819
+ served["draft_id"] = "";
820
+ }
821
+ return served;
535
822
  }
536
- /** The runs-list envelope (the restore port): the output-root scan, media-first + newest sort, the limit parse (raw STRING — the lane/remote pass the raw text; underscores parse, non-ints refuse), refused cards SKIPPED but counted. */
823
+ /** The runs-list envelope (the restore port): the BOTH-SEATS scan per root (visible-bench law), media-first + newest sort, the limit sliced off the merged order, the limit parsed (raw STRING — the lane/remote pass the raw text; underscores parse, non-ints refuse), refused cards SKIPPED but counted. */
537
824
  /** url/thumbnail are run-RELATIVE (the /v1/assets prefix died with the app — the header's law). */
538
- export async function listRuns(stateRoot, limit, hasDraft) {
539
- return listRunsAcross([stateRoot], limit, hasDraft);
825
+ export async function listRuns(stateRoot, limit, hasDraft, filter) {
826
+ return listRunsAcross([stateRoot], limit, hasDraft, filter);
540
827
  }
541
828
 
542
829
 
@@ -545,7 +832,12 @@ export async function listRuns(stateRoot, limit, hasDraft) {
545
832
 
546
833
 
547
834
 
548
- export async function listRunsAcross(roots, limit, hasDraft) {
835
+
836
+
837
+
838
+
839
+
840
+ export async function listRunsAcross(roots, limit, hasDraft, filter) {
549
841
  const ents = [];
550
842
  for (const root of roots)
551
843
  ents.push(...scanRunsRoot(root));
@@ -557,18 +849,27 @@ export async function listRunsAcross(roots, limit, hasDraft) {
557
849
  return am - bm;
558
850
  return b.created - a.created; // newest-first; stable
559
851
  });
560
- const sliced = ents.slice(0, limit);
852
+ // THE RUNS-PER-DRAFT DOOR (the stale-two-run chat audit's cure 3,
853
+
854
+ // first-root-wins dedup intact) and slices AFTER the filter — the
855
+ // window is the draft's own tail, never the global limit's (a
856
+ // draft's older takes survive a foreign newer run). Absent filter:
857
+ // the restore port's path unchanged — sliced before build.
858
+ const filtered = filter !== undefined && (filter.draftId !== undefined || filter.benchStageId !== undefined);
859
+ const scanned = filtered ? ents : ents.slice(0, limit);
561
860
  const seen = new Set();
562
861
  const rows = [];
563
- for (const ent of sliced) {
862
+ for (const ent of scanned) {
564
863
  if (seen.has(ent.dir))
565
864
  continue; // first manifest root wins
566
865
  seen.add(ent.dir);
567
- const row = await buildRunCard(join(ent.root, "output"), ent, hasDraft);
866
+ const row = await buildRunCard(join(ent.root, ent.seat), ent, hasDraft);
568
867
  if (row === null)
569
868
  continue; // RESILIENCE LAW: loud skip
869
+ if (filtered && !runsFilterServes(row, filter))
870
+ continue;
570
871
  rows.push({ ...row, served_from: ent.root });
571
872
  }
572
- return { count, runs: rows };
873
+ return { count, runs: filtered ? rows.slice(0, limit) : rows };
573
874
  }
574
875
  //# sourceMappingURL=runsList.js.map
@@ -19,6 +19,18 @@ function refusalEnvelopeOf(err) {
19
19
  p["folders"] = [...lane.folders];
20
20
  if (lane.fetchUrl !== undefined)
21
21
  p["fetch_url"] = lane.fetchUrl;
22
+
23
+ // spelling is snake; every row carries the popup's download
24
+ // facts (slot, name, folders, declared size, fetch address).
25
+ if (lane.missingAll !== undefined) {
26
+ p["missing_all"] = lane.missingAll.map((r) => ({
27
+ slot: r.slot,
28
+ name: r.name,
29
+ folders: [...r.folders],
30
+ ...(r.sizeBytes !== undefined ? { size_bytes: r.sizeBytes } : {}),
31
+ ...(r.fetchUrl !== undefined ? { fetch_url: r.fetchUrl } : {}),
32
+ }));
33
+ }
22
34
  p["kind"] = lane.kind;
23
35
  }
24
36
  return p;
@@ -36,13 +48,49 @@ function laneDetailsOf(p) {
36
48
  const kind = p["kind"];
37
49
  if (typeof family !== "string" || typeof slot !== "string"
38
50
  || typeof missing !== "string" || !Array.isArray(folders)
39
- || (kind !== "model" && kind !== "extension")) {
51
+ // "runtime" rides the tool-runtime leg (E2-2 Piece A): the
52
+ // popup's runtime banner keys on the parsed prose, and the
53
+ // fold carries the row through like every other refusal's.
54
+ || (kind !== "model" && kind !== "extension" && kind !== "runtime")) {
40
55
  throw new Error("runs remote: lane_input_missing refusal lacks its structured artifact (family/slot/missing/folders/kind)");
41
56
  }
42
57
  const fetchUrl = p["fetch_url"];
43
58
  const loc = p["loc"];
44
59
  const expected = p["expected"];
45
60
  const got = p["got"];
61
+
62
+ // malformed rows throw loud — the popup's download list keys on
63
+ // these fields, never on prose. Optional: the runtime leg and the
64
+ // in-flight arm carry no list.
65
+ const rawMissingAll = p["missing_all"];
66
+ let missingAll;
67
+ if (rawMissingAll !== undefined) {
68
+ if (!Array.isArray(rawMissingAll)) {
69
+ throw new Error("runs remote: lane_input_missing missing_all is not a list");
70
+ }
71
+ missingAll = rawMissingAll.map((row) => {
72
+ const r = row;
73
+ const slot = r["slot"];
74
+ const name = r["name"];
75
+ const folders = r["folders"];
76
+ const size = r["size_bytes"];
77
+ const fetch = r["fetch_url"];
78
+ if (typeof slot !== "string" || slot === "" || typeof name !== "string" || name === ""
79
+ || !Array.isArray(folders)) {
80
+ throw new Error("runs remote: lane_input_missing missing_all row lacks slot/name/folders");
81
+ }
82
+ if (size !== undefined && typeof size !== "number") {
83
+ throw new Error("runs remote: lane_input_missing missing_all row size_bytes is not a number");
84
+ }
85
+ return {
86
+ slot,
87
+ name,
88
+ folders: folders.filter((f) => typeof f === "string"),
89
+ ...(typeof size === "number" ? { size_bytes: size } : {}),
90
+ ...(typeof fetch === "string" && fetch !== "" ? { fetch_url: fetch } : {}),
91
+ };
92
+ });
93
+ }
46
94
  return {
47
95
  // THE ROW EXTENDS RunsRefusalDetails: the bench arm's loc-carry
48
96
  // reads these three off the mapped details — a lane refusal that
@@ -55,6 +103,7 @@ function laneDetailsOf(p) {
55
103
  missing,
56
104
  folders: folders.filter((f) => typeof f === "string"),
57
105
  ...(typeof fetchUrl === "string" && fetchUrl !== "" ? { fetch_url: fetchUrl } : {}),
106
+ ...(missingAll !== undefined ? { missing_all: missingAll } : {}),
58
107
  kind,
59
108
  };
60
109
  }