@stage5/lumine 0.2.66 → 0.2.67

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/admin.js CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  parseBuildReviewReceipt,
21
21
  runManagedBuildReview,
22
22
  } from "./build-review.js";
23
+ import { runAdminRuntimeLogWorkflow } from "./admin-runtime-logs.js";
23
24
 
24
25
  const MAX_EDITORIAL_FILE_BYTES = 256 * 1024;
25
26
  const MAX_COMPOSED_TEXT_FILE_BYTES = 64 * 1024;
@@ -242,7 +243,7 @@ export async function adminCommand(options) {
242
243
  options.idempotencyKey || (operation.mutates ? `cli:${randomUUID()}` : "");
243
244
  let result;
244
245
  try {
245
- const fetchOperation = async (requestPath = operation.path) =>
246
+ const fetchOperation = async (requestPath = operation.path, signal) =>
246
247
  requestJson({
247
248
  method: operation.method,
248
249
  url: `${options.apiUrl}${requestPath}`,
@@ -252,14 +253,14 @@ export async function adminCommand(options) {
252
253
  ...(runId ? { "x-lumine-admin-run-id": String(runId) } : {}),
253
254
  ...(correctionSessionId
254
255
  ? {
255
- "x-lumine-admin-correction-session-id": String(
256
- correctionSessionId,
257
- ),
256
+ "x-lumine-admin-correction-session-id":
257
+ String(correctionSessionId),
258
258
  }
259
259
  : {}),
260
260
  ...(requestId ? { "x-lumine-idempotency-key": requestId } : {}),
261
261
  },
262
262
  timeoutMs: options.timeoutMs,
263
+ signal,
263
264
  });
264
265
  const transformResult = (rawResult) =>
265
266
  transformAdminResult({
@@ -282,6 +283,13 @@ export async function adminCommand(options) {
282
283
  runId,
283
284
  parseTarget: parseRecommendationTarget,
284
285
  });
286
+ } else if (operation.name.startsWith("runtime-logs.")) {
287
+ result = await runAdminRuntimeLogWorkflow({
288
+ options,
289
+ operation,
290
+ authToken: auth.token,
291
+ requestId,
292
+ });
285
293
  } else if (options.adminAll) {
286
294
  if (options.adminCursor) {
287
295
  throw cliValidationError(
@@ -295,7 +303,7 @@ export async function adminCommand(options) {
295
303
  fetchPage: fetchOperation,
296
304
  transformPage: transformResult,
297
305
  recordCoverage: shouldRecordAdminQueueCoverage(runScope)
298
- ? async (coverage) =>
306
+ ? async (coverage, signal) =>
299
307
  requestJson({
300
308
  method: "POST",
301
309
  url: `${options.apiUrl}/cli/admin/daily-runs/coverage`,
@@ -306,6 +314,7 @@ export async function adminCommand(options) {
306
314
  "x-lumine-idempotency-key": `cli:queue-coverage:${runId}:${adminValueFingerprint(coverage).slice(0, 32)}`,
307
315
  },
308
316
  timeoutMs: options.timeoutMs,
317
+ signal,
309
318
  })
310
319
  : undefined,
311
320
  });
@@ -389,6 +398,9 @@ function transformAdminResult({
389
398
  if (operation.name === "recommendations.list") {
390
399
  assertRecommendationWindowResult({ operation, result: transformed });
391
400
  }
401
+ if (operation.name === "subjects.candidates") {
402
+ assertSubjectWindowResult({ operation, result: transformed });
403
+ }
392
404
  if (operation.name === "builds.candidates") {
393
405
  transformed = normalizeAdminBuildCandidatesResult({
394
406
  result: transformed,
@@ -438,6 +450,34 @@ export function assertRecommendationWindowResult({ operation, result }) {
438
450
  }
439
451
  }
440
452
 
453
+ export function assertSubjectWindowResult({ operation, result }) {
454
+ const mode = operation?.pagination?.coverageMode;
455
+ if (!mode || mode === "legacy") return;
456
+ const after = result?.data?.pagination?.after;
457
+ const snapshotTimeStamp = result?.data?.pagination?.snapshotTimeStamp;
458
+ if (
459
+ !Number.isSafeInteger(after) ||
460
+ after < 0 ||
461
+ !Number.isSafeInteger(snapshotTimeStamp) ||
462
+ snapshotTimeStamp < 0
463
+ ) {
464
+ const error = new Error(
465
+ "The deployed API did not confirm the bounded Subject window and snapshot. Deploy the matching API before using this CLI; use --include-legacy only for an intentional historical scan.",
466
+ );
467
+ error.code = "LUMINE_ADMIN_SUBJECT_WINDOW_UNSUPPORTED";
468
+ error.data = {
469
+ ok: false,
470
+ status: "validation_error",
471
+ error: {
472
+ code: error.code,
473
+ message: error.message,
474
+ details: { requestedMode: mode },
475
+ },
476
+ };
477
+ throw error;
478
+ }
479
+ }
480
+
441
481
  async function finishAdminOutput({ options, operation, result }) {
442
482
  const paginationStorage = getPaginatedResultStorage(result);
443
483
  if (options.json) {
@@ -717,7 +757,9 @@ export function canonicalAdminRunScope(run) {
717
757
  if (raw === undefined || raw === null || raw === "") return "full";
718
758
  const scope = String(raw);
719
759
  if (scope === "full" || scope === "featured") return scope;
720
- throw cliValidationError("The API returned an invalid administrator run scope.");
760
+ throw cliValidationError(
761
+ "The API returned an invalid administrator run scope.",
762
+ );
721
763
  }
722
764
 
723
765
  export function shouldRecordAdminQueueCoverage(runScope) {
@@ -757,6 +799,9 @@ export function assertAdminOperationAllowedForRunScope({
757
799
  }
758
800
 
759
801
  function adminOperationRequiresRun(operation) {
802
+ if (typeof operation.requiresRun === "boolean") {
803
+ return operation.requiresRun;
804
+ }
760
805
  return (
761
806
  ![
762
807
  "identity.list",
@@ -773,6 +818,14 @@ function adminOperationRequiresRun(operation) {
773
818
  "escalation.list",
774
819
  "escalation.set",
775
820
  "notable.add",
821
+ "notable.status",
822
+ "runtime-logs.start",
823
+ "runtime-logs.status",
824
+ "runtime-logs.capture",
825
+ "runtime-logs.complete",
826
+ "runtime-logs.resume",
827
+ "runtime-logs.abandon",
828
+ "energy-budget.report",
776
829
  ].includes(operation.name) &&
777
830
  !operation.name.startsWith("ai-bucket.") &&
778
831
  !operation.name.startsWith("ai-email-policy.") &&
@@ -803,7 +856,10 @@ export function parseAdminOperation(options) {
803
856
 
804
857
  if (namespace === "correction" || namespace === "corrections") {
805
858
  if (!action || action === "status") {
806
- return readOperation("correction.status", "/cli/admin/corrections/status");
859
+ return readOperation(
860
+ "correction.status",
861
+ "/cli/admin/corrections/status",
862
+ );
807
863
  }
808
864
  if (action === "start") {
809
865
  const commentId = parseRequiredInteger(target, "comment ID", 1);
@@ -1185,6 +1241,25 @@ export function parseAdminOperation(options) {
1185
1241
  return readOperation("daily-run.status", "/cli/admin/daily-runs/status");
1186
1242
  }
1187
1243
  if (action === "report") {
1244
+ const positionalRun = String(target || "").trim();
1245
+ const flaggedRun = String(options.adminRun || "").trim();
1246
+ if (
1247
+ extra ||
1248
+ (positionalRun && flaggedRun && positionalRun !== flaggedRun)
1249
+ ) {
1250
+ throw cliValidationError(
1251
+ "Usage: lumine admin daily-run report [--run <completed-run-id>] [--json].",
1252
+ );
1253
+ }
1254
+ const historicalRun = positionalRun || flaggedRun;
1255
+ if (historicalRun) {
1256
+ const runId = parseRequiredInteger(historicalRun, "run ID", 1);
1257
+ return readOperation(
1258
+ "daily-run.report",
1259
+ `/cli/admin/daily-runs/${runId}/report`,
1260
+ { requiresRun: false, historicalRunId: runId },
1261
+ );
1262
+ }
1188
1263
  return readOperation("daily-run.report", "/cli/admin/daily-runs/report");
1189
1264
  }
1190
1265
  if (action === "escalation" && target === "add") {
@@ -1630,6 +1705,23 @@ export function parseAdminOperation(options) {
1630
1705
  );
1631
1706
  }
1632
1707
 
1708
+ if (namespace === "notable" && action === "status" && !extra) {
1709
+ const rawTarget = String(target || "").trim();
1710
+ if (!rawTarget) {
1711
+ throw cliValidationError(
1712
+ "Usage: lumine admin notable status <userId|username>.",
1713
+ );
1714
+ }
1715
+ const query = /^\d+$/.test(rawTarget)
1716
+ ? { userId: parseRequiredInteger(rawTarget, "user ID", 1) }
1717
+ : { username: rawTarget };
1718
+ return readOperation(
1719
+ "notable.status",
1720
+ withQuery("/cli/admin/notable-users/status", query),
1721
+ { requiresRun: false },
1722
+ );
1723
+ }
1724
+
1633
1725
  if (namespace === "ai-costs") {
1634
1726
  if (action === "monthly" && !target && !extra) {
1635
1727
  if (options.adminDays) {
@@ -1639,7 +1731,105 @@ export function parseAdminOperation(options) {
1639
1731
  }
1640
1732
  return readOperation("ai-costs.monthly", "/cli/admin/ai-costs/monthly");
1641
1733
  }
1642
- throw cliValidationError("Usage: lumine admin ai-costs monthly [--json].");
1734
+ if (action === "day" && !extra) {
1735
+ if (options.adminDays) {
1736
+ throw cliValidationError(
1737
+ "ai-costs day reads one closed UTC day and does not accept --days.",
1738
+ );
1739
+ }
1740
+ const positionalDay = String(target || "").trim();
1741
+ const flaggedDay = String(options.adminDate || "").trim();
1742
+ if (positionalDay && flaggedDay && positionalDay !== flaggedDay) {
1743
+ throw cliValidationError(
1744
+ "Pass the same UTC day once, either positionally or with --date.",
1745
+ );
1746
+ }
1747
+ const dayKey = parseUtcDayKey(positionalDay || flaggedDay);
1748
+ return readOperation(
1749
+ "ai-costs.day",
1750
+ `/cli/admin/ai-costs/day/${dayKey}`,
1751
+ { requiresRun: false },
1752
+ );
1753
+ }
1754
+ throw cliValidationError(
1755
+ "Usage: lumine admin ai-costs monthly | ai-costs day <YYYY-MM-DD> [--json].",
1756
+ );
1757
+ }
1758
+
1759
+ if (namespace === "energy-budget" && !action) {
1760
+ if (options.adminDays) {
1761
+ const days = Number(options.adminDays);
1762
+ if (!Number.isInteger(days) || days < 1 || days > 31) {
1763
+ throw cliValidationError("--days must be an integer between 1 and 31.");
1764
+ }
1765
+ }
1766
+ return readOperation(
1767
+ "energy-budget.report",
1768
+ withQuery("/cli/admin/energy-budget/report", { days: options.adminDays }),
1769
+ { requiresRun: false },
1770
+ );
1771
+ }
1772
+
1773
+ if (namespace === "runtime-logs") {
1774
+ if (
1775
+ (action === "start" || action === "status" || action === "read") &&
1776
+ !target &&
1777
+ !extra
1778
+ ) {
1779
+ if (
1780
+ action !== "start" &&
1781
+ !String(options.adminReviewSession || "").trim()
1782
+ ) {
1783
+ throw cliValidationError(
1784
+ "Pass the production-log review session with --review-session <file>.",
1785
+ );
1786
+ }
1787
+ return {
1788
+ name:
1789
+ action === "read" ? "runtime-logs.capture" : `runtime-logs.${action}`,
1790
+ method: action === "status" ? "GET" : "POST",
1791
+ path: "",
1792
+ body: undefined,
1793
+ mutates: action !== "status",
1794
+ requiresRun: false,
1795
+ runtimeLogAction: action === "read" ? "capture" : action,
1796
+ };
1797
+ }
1798
+ if ((action === "resume" || action === "abandon") && !target && !extra) {
1799
+ return {
1800
+ name: `runtime-logs.${action}`,
1801
+ method: "POST",
1802
+ path: "",
1803
+ body: undefined,
1804
+ mutates: true,
1805
+ requiresRun: false,
1806
+ runtimeLogAction: action,
1807
+ };
1808
+ }
1809
+ if ((action === "finish" || action === "complete") && !target && !extra) {
1810
+ if (!String(options.adminReviewSession || "").trim()) {
1811
+ throw cliValidationError(
1812
+ "Pass the production-log review session with --review-session <file>.",
1813
+ );
1814
+ }
1815
+ if (!options.adminReviewed) {
1816
+ throw cliValidationError(
1817
+ "Inspect every downloaded runtime-log artifact, then confirm with --reviewed.",
1818
+ );
1819
+ }
1820
+ return {
1821
+ name: "runtime-logs.complete",
1822
+ method: "POST",
1823
+ path: "",
1824
+ body: undefined,
1825
+ mutates: true,
1826
+ requiresRun: false,
1827
+ runtimeLogAction: "complete",
1828
+ };
1829
+ }
1830
+ throw cliValidationError(
1831
+ "Usage: lumine admin runtime-logs start | status|read --review-session <file> | finish --review-session <file> --reviewed | resume | abandon [--review-session <file>].",
1832
+ );
1643
1833
  }
1644
1834
 
1645
1835
  if (namespace === "media-costs") {
@@ -1891,16 +2081,19 @@ export function parseAdminOperation(options) {
1891
2081
  }
1892
2082
 
1893
2083
  throw cliValidationError(
1894
- "Usage: lumine admin identity|economy|rescue|sponsor|daily-run|escalation|todo|recommendations|builds|post|subjects|subject|featured|comment|announcement|chat|news|audit|brief|ai-costs|media-costs|bot-output|notable ...",
2084
+ "Usage: lumine admin identity|economy|rescue|sponsor|daily-run|escalation|todo|recommendations|builds|post|subjects|subject|featured|comment|announcement|chat|news|audit|brief|ai-costs|media-costs|energy-budget|runtime-logs|bot-output|notable ...",
1895
2085
  );
1896
2086
  }
1897
2087
 
1898
2088
  function subjectsListOperation(options) {
1899
2089
  const operatorView = requestedOperatorViewFilter(options);
2090
+ const subjectWindow = parseSubjectWindow(options);
1900
2091
  return readOperation(
1901
2092
  "subjects.candidates",
1902
2093
  withQuery("/cli/admin/subjects", {
1903
- after: options.adminAfter,
2094
+ sinceRun: subjectWindow.mode === "since-run" ? "true" : "",
2095
+ after: subjectWindow.mode === "after" ? subjectWindow.after : "",
2096
+ includeLegacy: subjectWindow.mode === "legacy" ? "true" : "",
1904
2097
  cursor: options.adminCursor,
1905
2098
  effort: options.adminEffort,
1906
2099
  limit: options.limit,
@@ -1909,10 +2102,11 @@ function subjectsListOperation(options) {
1909
2102
  pagination: {
1910
2103
  collectionKey: "subjects",
1911
2104
  coverageQueue: "subjects",
1912
- coverageMode: options.adminAfter ? "after" : "all",
1913
- after: options.adminAfter
1914
- ? parseAfterForCoverage(options.adminAfter)
1915
- : null,
2105
+ coverageMode: subjectWindow.mode,
2106
+ after:
2107
+ subjectWindow.mode === "after"
2108
+ ? parseAfterForCoverage(subjectWindow.after)
2109
+ : null,
1916
2110
  filters: {
1917
2111
  effort: options.adminEffort || "all",
1918
2112
  ...(operatorView ? { operatorView } : {}),
@@ -2007,10 +2201,7 @@ function featuredReorderOperation(options) {
2007
2201
  }
2008
2202
 
2009
2203
  function featuredAddOperation(options) {
2010
- const addIds = parseFeaturedSubjectIds(
2011
- options.adminIds,
2012
- "--subject-ids",
2013
- );
2204
+ const addIds = parseFeaturedSubjectIds(options.adminIds, "--subject-ids");
2014
2205
  const postedAfter = String(options.adminPostedAfter || "").trim();
2015
2206
  if (!postedAfter) {
2016
2207
  throw cliValidationError(
@@ -2096,6 +2287,42 @@ export function parseRecommendationWindow(options) {
2096
2287
  return { mode, after: mode === "after" ? options.adminAfter : "" };
2097
2288
  }
2098
2289
 
2290
+ export function parseSubjectWindow(options) {
2291
+ const selected = [
2292
+ options.adminSinceRun ? "since-run" : "",
2293
+ options.adminAfter ? "after" : "",
2294
+ options.adminIncludeLegacy ? "legacy" : "",
2295
+ ].filter(Boolean);
2296
+ if (selected.length > 1) {
2297
+ throw cliValidationError(
2298
+ "Choose one Subject window: --since-run, --after, or --include-legacy.",
2299
+ );
2300
+ }
2301
+ const mode = selected[0] || "since-run";
2302
+ if (mode === "after") parseAfterForCoverage(options.adminAfter);
2303
+ return { mode, after: mode === "after" ? options.adminAfter : "" };
2304
+ }
2305
+
2306
+ function parseUtcDayKey(value) {
2307
+ const dayKey = String(value || "").trim();
2308
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(dayKey);
2309
+ if (!match) {
2310
+ throw cliValidationError(
2311
+ "Pass a real UTC calendar date in YYYY-MM-DD format.",
2312
+ );
2313
+ }
2314
+ const parsed = new Date(`${dayKey}T00:00:00.000Z`);
2315
+ if (
2316
+ !Number.isFinite(parsed.getTime()) ||
2317
+ parsed.toISOString().slice(0, 10) !== dayKey
2318
+ ) {
2319
+ throw cliValidationError(
2320
+ "Pass a real UTC calendar date in YYYY-MM-DD format.",
2321
+ );
2322
+ }
2323
+ return dayKey;
2324
+ }
2325
+
2099
2326
  function parseAfterForCoverage(value) {
2100
2327
  const raw = String(value || "").trim();
2101
2328
  if (/^\d+$/.test(raw)) {
@@ -2387,7 +2614,9 @@ function parseCommentMode(value) {
2387
2614
  }
2388
2615
 
2389
2616
  function parseDailyRunScope(value) {
2390
- const scope = String(value || "full").trim().toLowerCase();
2617
+ const scope = String(value || "full")
2618
+ .trim()
2619
+ .toLowerCase();
2391
2620
  if (!["full", "featured"].includes(scope)) {
2392
2621
  throw cliValidationError("--scope must be full or featured.");
2393
2622
  }
@@ -2698,6 +2927,48 @@ function printAdminMonthlyAiCosts(monthlyAiCosts) {
2698
2927
  }
2699
2928
  }
2700
2929
 
2930
+ function printAdminDailyAiCosts(dailyAiCosts) {
2931
+ console.log(
2932
+ `Application AI-cost ledger for ${dailyAiCosts.day.dayKey} (closed UTC day): ${formatAdminUsd(dailyAiCosts.summary?.estimatedCostUsd)} across ${Number(dailyAiCosts.summary?.requestCount || 0)} request(s).`,
2933
+ );
2934
+ for (const row of dailyAiCosts.byProviderModel || []) {
2935
+ console.log(
2936
+ ` ${row.provider || "unknown"}/${row.model || "unknown"}: ${formatAdminUsd(row.estimatedCostUsd)} · ${Number(row.totalTokens || 0)} token(s) · ${Number(row.requestCount || 0)} request(s).`,
2937
+ );
2938
+ }
2939
+ }
2940
+
2941
+ function printAdminEnergyBudget(energyBudget) {
2942
+ const headline = energyBudget.lastCompletedDay;
2943
+ if (headline) {
2944
+ console.log(
2945
+ `AI Energy budget health, last completed UTC day ${headline.dayKey}: ${formatAdminUsd(headline.chargedUsd)} charged, ${formatAdminUsd(headline.overflowUsd)} overflow, ${headline.users} user(s), ${headline.recharges} recharge(s), ${headline.runs.total.runs} run(s), ${headline.telemetry.metrics.busy_refusal.count} busy refusal(s).`,
2946
+ );
2947
+ } else {
2948
+ console.log("AI Energy budget health: no completed UTC day in the requested window.");
2949
+ }
2950
+ console.log(
2951
+ "day | charged | overflow | users | rechg | runs | calls/run avg/p90 | $/run avg/p90 | stops chg/unchg | busy | telemetry rows",
2952
+ );
2953
+ for (const day of energyBudget.byDay || []) {
2954
+ const m = day.telemetry.metrics;
2955
+ const runs = day.runs.total;
2956
+ console.log(
2957
+ `${day.dayKey}${day.inProgress ? "*" : " "}| ${formatAdminUsd(day.chargedUsd).padStart(7)} | ${formatAdminUsd(day.overflowUsd).padStart(8)} | ${String(day.users).padStart(5)} | ${String(day.recharges).padStart(5)} | ${String(runs.runs).padStart(4)} | ${String(runs.callsPerRun.avg).padStart(7)}/${String(runs.callsPerRun.p90).padEnd(9)} | ${formatAdminUsd(runs.usdPerRun.avg).padStart(6)}/${formatAdminUsd(runs.usdPerRun.p90).padEnd(6)} | ${String(m.budget_stop_changed.count).padStart(7)}/${String(m.budget_stop_unchanged.count).padEnd(7)} | ${String(m.busy_refusal.count).padStart(4)} | ${day.telemetry.rowCount}`,
2958
+ );
2959
+ }
2960
+ console.log("* = in-progress UTC day; never headline it.");
2961
+ const flags = energyBudget.flags || [];
2962
+ if (flags.length === 0) {
2963
+ console.log("Flags: none.");
2964
+ return;
2965
+ }
2966
+ console.log(`Flags (${flags.length}) — record each as a carry-over todo and escalate; never auto-enforce:`);
2967
+ for (const flag of flags) {
2968
+ console.log(` ${flag.dayKey} ${flag.code}: ${flag.message}`);
2969
+ }
2970
+ }
2971
+
2701
2972
  function formatAdminMediaUsd(value) {
2702
2973
  const amount = Number(value);
2703
2974
  if (!Number.isFinite(amount)) return "unavailable";
@@ -2959,6 +3230,28 @@ function printAdminResult({ operation, result }) {
2959
3230
  );
2960
3231
  return;
2961
3232
  }
3233
+ if (data.review && data.artifacts?.reviewSessionPath) {
3234
+ console.log(
3235
+ `Production-log review #${data.review.id}: ${data.completionStatus || data.review.status}.`,
3236
+ );
3237
+ console.log(`Review session: ${data.artifacts.reviewSessionPath}`);
3238
+ if (data.artifacts.latestSnapshot?.snapshotPath) {
3239
+ console.log(
3240
+ `Latest captured bytes: ${data.artifacts.latestSnapshot.snapshotPath}`,
3241
+ );
3242
+ }
3243
+ if (
3244
+ data.completionStatus === "needs_review" ||
3245
+ data.completionStatus === "post_clear_review_required"
3246
+ ) {
3247
+ console.log(
3248
+ data.completionStatus === "post_clear_review_required"
3249
+ ? "The API error log was cleared in place. Review the post-clear snapshot, then rerun finish with --reviewed to close the lease."
3250
+ : "New bytes arrived at the final boundary. Review the latest snapshot, then rerun finish with --reviewed.",
3251
+ );
3252
+ }
3253
+ return;
3254
+ }
2962
3255
  if (data.review) {
2963
3256
  console.log(
2964
3257
  `Confirmed Build #${data.review.buildId} runtime at published artifact #${data.review.publishedArtifactVersionId}.`,
@@ -2971,6 +3264,14 @@ function printAdminResult({ operation, result }) {
2971
3264
  printAdminMonthlyAiCosts(data.monthlyAiCosts);
2972
3265
  return;
2973
3266
  }
3267
+ if (data.dailyAiCosts) {
3268
+ printAdminDailyAiCosts(data.dailyAiCosts);
3269
+ return;
3270
+ }
3271
+ if (data.energyBudget) {
3272
+ printAdminEnergyBudget(data.energyBudget);
3273
+ return;
3274
+ }
2974
3275
  if (data.monthlyMediaCosts) {
2975
3276
  printAdminMonthlyMediaCosts(data.monthlyMediaCosts);
2976
3277
  return;
@@ -2990,8 +3291,9 @@ function printAdminResult({ operation, result }) {
2990
3291
  }
2991
3292
  if (data.report) {
2992
3293
  const report = data.report;
3294
+ const historical = report.basis?.kind === "historical_reconstruction";
2993
3295
  console.log(
2994
- `Run #${report.run.id}: ${report.mutations.successfulMutationCount} successful mutation(s), ${report.queueCoverage.length} queue coverage record(s), ${report.escalations.length} escalation(s), ${report.carryoverTodos?.count || 0} unfinished todo(s).`,
3296
+ `${historical ? "Historical reconstruction for run" : "Run"} #${report.run.id}: ${report.mutations.successfulMutationCount} successful mutation(s), ${report.queueCoverage.length} queue coverage record(s), ${report.escalations.length} escalation(s)${historical ? "." : `, ${report.carryoverTodos?.count || 0} unfinished todo(s).`}`,
2995
3297
  );
2996
3298
  for (const coverage of report.queueCoverage) {
2997
3299
  console.log(
@@ -3006,10 +3308,21 @@ function printAdminResult({ operation, result }) {
3006
3308
  ` ${String(escalation.severity || "attention").toUpperCase()} ${target} — ${escalation.summary}`,
3007
3309
  );
3008
3310
  }
3009
- printTodoItems(report.carryoverTodos?.items || [], "Unfinished work");
3311
+ if (historical) {
3312
+ console.log(
3313
+ "The live brief and carry-over todo state were not snapshotted for this completed run.",
3314
+ );
3315
+ } else {
3316
+ printTodoItems(report.carryoverTodos?.items || [], "Unfinished work");
3317
+ }
3010
3318
  if (report.sponsorIntegrity) {
3319
+ const pendingApplications = Number.isSafeInteger(
3320
+ report.sponsorIntegrity.pendingApplications,
3321
+ )
3322
+ ? `; ${report.sponsorIntegrity.pendingApplications} pending application(s)`
3323
+ : "; historical pending-application count unavailable";
3011
3324
  console.log(
3012
- `Sponsor integrity: ${report.sponsorIntegrity.scan?.status || "not started"}; ${report.sponsorIntegrity.cases?.open || 0} open case(s); ${report.sponsorIntegrity.pendingApplications || 0} pending application(s).`,
3325
+ `Sponsor integrity: ${report.sponsorIntegrity.scan?.status || "not started"}; ${report.sponsorIntegrity.cases?.open || 0} open case(s)${pendingApplications}.`,
3013
3326
  );
3014
3327
  }
3015
3328
  const surfaces = report.brief?.engagementPulse?.surfaces;
@@ -3029,10 +3342,12 @@ function printAdminResult({ operation, result }) {
3029
3342
  if (deltas.length)
3030
3343
  console.log(`Engagement deltas: ${deltas.join(", ")}.`);
3031
3344
  }
3032
- const notableCount = Array.isArray(report.brief?.notableCandidates)
3033
- ? report.brief.notableCandidates.length
3034
- : 0;
3035
- console.log(`Notable-user candidates in this brief: ${notableCount}.`);
3345
+ if (!historical) {
3346
+ const notableCount = Array.isArray(report.brief?.notableCandidates)
3347
+ ? report.brief.notableCandidates.length
3348
+ : 0;
3349
+ console.log(`Notable-user candidates in this brief: ${notableCount}.`);
3350
+ }
3036
3351
  return;
3037
3352
  }
3038
3353
  if (data.inspection) {
@@ -3096,6 +3411,15 @@ function printAdminResult({ operation, result }) {
3096
3411
  printTodoItems([data.todo], "Canonical todo");
3097
3412
  return;
3098
3413
  }
3414
+ if (Object.hasOwn(data, "isNotable") && data.user) {
3415
+ console.log(
3416
+ `${data.user.username} (user #${data.user.id}) is${data.isNotable ? "" : " not"} currently in Notable Users.`,
3417
+ );
3418
+ if (data.notableUser?.reason) {
3419
+ console.log(`Reason: ${data.notableUser.reason}`);
3420
+ }
3421
+ return;
3422
+ }
3099
3423
  if (data.bucket && Array.isArray(data.memberUserIds)) {
3100
3424
  const added = Array.isArray(data.accounts)
3101
3425
  ? `; added ${data.accounts.length} explicit account(s)`