@codyswann/lisa 3.30.1 → 3.31.1

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 (81) hide show
  1. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  2. package/dist/core/upstream-evidence-manifest.js +12 -4
  3. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  4. package/package.json +1 -1
  5. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  6. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  7. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +17 -2
  8. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/surfaces.mjs +88 -5
  9. package/plugins/lisa/scripts/automation-status-claude-adapter.mjs +56 -6
  10. package/plugins/lisa/scripts/automation-status-codex-adapter.mjs +54 -4
  11. package/plugins/lisa/scripts/automation-status-unrecorded-runs.mjs +127 -0
  12. package/plugins/lisa/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +17 -2
  13. package/plugins/lisa/skills/lisa-secrets-access/scripts/surfaces.mjs +88 -5
  14. package/plugins/lisa-agy/plugin.json +1 -1
  15. package/plugins/lisa-agy/scripts/automation-status-claude-adapter.mjs +56 -6
  16. package/plugins/lisa-agy/scripts/automation-status-codex-adapter.mjs +54 -4
  17. package/plugins/lisa-agy/scripts/automation-status-unrecorded-runs.mjs +127 -0
  18. package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +17 -2
  19. package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/surfaces.mjs +88 -5
  20. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  22. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  23. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  24. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  25. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  26. package/plugins/lisa-copilot/scripts/automation-status-claude-adapter.mjs +56 -6
  27. package/plugins/lisa-copilot/scripts/automation-status-codex-adapter.mjs +54 -4
  28. package/plugins/lisa-copilot/scripts/automation-status-unrecorded-runs.mjs +127 -0
  29. package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +17 -2
  30. package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/surfaces.mjs +88 -5
  31. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  32. package/plugins/lisa-cursor/scripts/automation-status-claude-adapter.mjs +56 -6
  33. package/plugins/lisa-cursor/scripts/automation-status-codex-adapter.mjs +54 -4
  34. package/plugins/lisa-cursor/scripts/automation-status-unrecorded-runs.mjs +127 -0
  35. package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +17 -2
  36. package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/surfaces.mjs +88 -5
  37. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  39. package/plugins/lisa-expo-agy/plugin.json +1 -1
  40. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  49. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  50. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  54. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  55. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  60. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  64. package/plugins/lisa-rails-agy/plugin.json +1 -1
  65. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  69. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  70. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  73. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  74. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  75. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  77. package/plugins/src/base/scripts/automation-status-claude-adapter.mjs +56 -6
  78. package/plugins/src/base/scripts/automation-status-codex-adapter.mjs +54 -4
  79. package/plugins/src/base/scripts/automation-status-unrecorded-runs.mjs +127 -0
  80. package/plugins/src/base/skills/lisa-secrets-access/scripts/preflight-secrets.mjs +17 -2
  81. package/plugins/src/base/skills/lisa-secrets-access/scripts/surfaces.mjs +88 -5
package/package.json CHANGED
@@ -131,7 +131,7 @@
131
131
  "ws": ">=8.21.0"
132
132
  },
133
133
  "name": "@codyswann/lisa",
134
- "version": "3.30.1",
134
+ "version": "3.31.1",
135
135
  "description": "Claude Code governance framework that applies guardrails, guidance, and automated enforcement to projects",
136
136
  "main": "dist/index.js",
137
137
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa",
3
- "version": "3.30.1",
3
+ "version": "3.31.1",
4
4
  "description": "Universal governance — agents, skills, commands, hooks, and rules for all projects",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa",
3
- "version": "3.30.1",
3
+ "version": "3.31.1",
4
4
  "description": "Universal governance: agents, skills, commands, hooks, and rules for all projects.",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -189,11 +189,26 @@ export function report(result, cfg) {
189
189
  } else {
190
190
  lines.push(
191
191
  `Secrets preflight FAILED on surface "${cfg.surface}".`,
192
- `These credentials are required and resolve nowhere not in the`,
193
- `environment, not materialized, not in the "${cfg.provider}" grant.`,
192
+ `These credentials are required and were not found in the surfaces`,
193
+ `consulted — the environment, the materialized file, and the`,
194
+ `"${cfg.provider}" grant.`,
194
195
  `Extend the grant in the vault (or correct the routing that requires`,
195
196
  `them), then start a new session:`
196
197
  );
198
+ // A defaulted provider is the one case where the list above is not the
199
+ // whole story: no config was found, so the vault a project actually
200
+ // declares was never contacted. Saying "resolve nowhere" there sends the
201
+ // reader to grant a credential that was never absent.
202
+ if (!cfg.configPath) {
203
+ lines.push(
204
+ ``,
205
+ `NOTE: no .lisa.config.json was found at or above the working`,
206
+ `directory, so provider "${cfg.provider}" is a DEFAULT, not this`,
207
+ `project's setting. If this project uses a vault, the credential may`,
208
+ `resolve fine — start the session from the repository root, or check`,
209
+ `the config is present, before treating this as missing.`
210
+ );
211
+ }
197
212
  }
198
213
  lines.push(``);
199
214
  for (const { name, reasons } of result.missing) {
@@ -15,7 +15,7 @@
15
15
 
16
16
  import { existsSync, readFileSync } from "node:fs";
17
17
  import { homedir } from "node:os";
18
- import { join } from "node:path";
18
+ import { dirname, join, resolve } from "node:path";
19
19
 
20
20
  import { bootstrapKeyFor } from "./providers.mjs";
21
21
  import { routingFloor } from "./routing-floor.mjs";
@@ -182,6 +182,64 @@ export function materializedPaths(namespace, env = process.env) {
182
182
  };
183
183
  }
184
184
 
185
+ /**
186
+ * Directories the harness claims are this session's project, best first.
187
+ *
188
+ * `CLAUDE_PROJECT_DIR` is set by Claude Code for hook commands, and Lisa's own
189
+ * hooks already invoke scripts through it. `LISA_PROJECT_DIR` lets a harness
190
+ * without that convention — or an operator debugging one — say the same thing.
191
+ *
192
+ * Blank values are dropped rather than resolved, because an unset variable
193
+ * expands to the empty string in a shell and `resolve("")` is the current
194
+ * directory, which would silently re-check a path already searched.
195
+ *
196
+ * @param {Record<string, string | undefined>} env - Environment to read.
197
+ * @returns {string[]} Candidate project roots, deduplicated, best first.
198
+ */
199
+ function projectAnchors(env) {
200
+ const raw = [env.LISA_PROJECT_DIR, env.CLAUDE_PROJECT_DIR];
201
+ return [...new Set(raw.map(value => (value ?? "").trim()).filter(Boolean))];
202
+ }
203
+
204
+ /**
205
+ * Find the nearest `.lisa.config.json` at or above `cwd`.
206
+ *
207
+ * Looking only in `cwd` made every session started anywhere but the repo root
208
+ * — a worktree subdirectory, a package folder, a parent wrapper directory —
209
+ * fall through to the environment defaults and resolve `provider: "env"`. The
210
+ * preflight then checked the environment, the materialized file, and the "env"
211
+ * grant, found nothing, and reported the credential as resolving NOWHERE,
212
+ * having never contacted the configured vault at all.
213
+ *
214
+ * That is a false negative wearing a definite answer's clothes, and the
215
+ * message it produces tells the reader to route the work to blocked. An
216
+ * obedient agent therefore abandons work over credentials it could have
217
+ * resolved, and nothing downstream ever re-derives that judgement.
218
+ *
219
+ * The walk stops at a repository boundary when it finds one, so a config
220
+ * belonging to an unrelated parent project is never adopted. If no boundary is
221
+ * found it stops at the filesystem root, which is what makes the bare-checkout
222
+ * and wrapper-directory layouts work.
223
+ *
224
+ * @param {string} cwd - Directory to start from.
225
+ * @returns {string | null} Absolute path to the config, or `null` if none.
226
+ */
227
+ function locateConfig(cwd) {
228
+ let dir = resolve(cwd);
229
+ for (;;) {
230
+ const candidate = join(dir, ".lisa.config.json");
231
+ if (existsSync(candidate)) return candidate;
232
+ // Checked AFTER the config, so a repo root carrying one still matches.
233
+ // Checked as a path rather than a directory because a worktree's `.git` is
234
+ // a file, and treating that as "not a boundary" would walk out of the
235
+ // worktree into whatever encloses it.
236
+ if (existsSync(join(dir, ".git"))) return null;
237
+ const parent = dirname(dir);
238
+ if (parent === dir) return null;
239
+ dir = parent;
240
+ }
241
+ }
242
+
185
243
  /**
186
244
  * Read the `secrets` block from `.lisa.config.json`.
187
245
  *
@@ -189,10 +247,28 @@ export function materializedPaths(namespace, env = process.env) {
189
247
  * provider means the environment *is* the provider. A credentials manager is
190
248
  * the preferred path, never a required one.
191
249
  * @param {string} [cwd] Directory to look in.
192
- * @returns {{provider: string, bootstrap: {sources: string[], key: string|null}, require: string[]|null, requiredFloor: readonly string[], rotating: string[], namespace: string, narrow: object, surface: string, routing: {tracker?: string, source?: string}, capabilities: object}} Resolved configuration with defaults applied.
250
+ * @returns {{provider: string, bootstrap: {sources: string[], key: string|null}, require: string[]|null, requiredFloor: readonly string[], rotating: string[], namespace: string, narrow: object, surface: string, routing: {tracker?: string, source?: string}, capabilities: object, configPath: string|null}} Resolved configuration with defaults applied. `configPath` is the file the values came from, or `null` when none was found and the defaults apply.
193
251
  */
194
252
  export function readConfig(cwd = process.cwd(), env = process.env) {
195
- const path = join(cwd, ".lisa.config.json");
253
+ // Walk from `cwd` first, then from whatever the harness says the project is.
254
+ //
255
+ // A walk from `cwd` alone does not close this. The SessionStart hook that
256
+ // runs the preflight never changes directory, so its cwd is wherever the
257
+ // harness happened to spawn it — `$HOME`, a plugin cache — and a walk from
258
+ // there terminates without finding anything, exactly as a walk from `cwd`
259
+ // inside the project succeeds. Measured on a session whose credential
260
+ // resolved fine from its own worktree while the preflight called it
261
+ // unreachable: every directory from that worktree upward carried a config,
262
+ // so the hook cannot have been running anywhere in that tree.
263
+ //
264
+ // cwd wins when it finds something, because an explicit working directory is
265
+ // intent and the project variable is only ever a hint about the session.
266
+ const path =
267
+ locateConfig(cwd) ??
268
+ projectAnchors(env)
269
+ .map(anchor => locateConfig(anchor))
270
+ .find(found => found !== null) ??
271
+ null;
196
272
  // No repository is a real, supported state — not just a missing file.
197
273
  //
198
274
  // A Claude Tag channel session runs as the organization with no user account,
@@ -203,7 +279,13 @@ export function readConfig(cwd = process.cwd(), env = process.env) {
203
279
  // The only values a config would supply here are the namespace and provider,
204
280
  // so they can come from the environment instead. Everything else keeps its
205
281
  // default, and an environment that sets neither still gets the old behaviour.
206
- if (!existsSync(path)) return withSurface(fromEnvironment(env));
282
+ //
283
+ // It stays supported, but it no longer stays SILENT: `configPath: null` lets
284
+ // a caller say "no config found, assuming provider=env" instead of printing
285
+ // a defaulted provider that is indistinguishable from a declared one.
286
+ if (!path) {
287
+ return withSurface({ ...fromEnvironment(env), configPath: null });
288
+ }
207
289
  let root;
208
290
  try {
209
291
  root = JSON.parse(readFileSync(path, "utf8"));
@@ -216,7 +298,7 @@ export function readConfig(cwd = process.cwd(), env = process.env) {
216
298
  // `secrets` would be a second copy free to disagree with the one every other
217
299
  // skill dispatches on.
218
300
  const routing = { tracker: root.tracker, source: root.source };
219
- if (!cfg) return withSurface({ ...DEFAULTS, routing });
301
+ if (!cfg) return withSurface({ ...DEFAULTS, routing, configPath: path });
220
302
  const provider = cfg.provider ?? DEFAULTS.provider;
221
303
  const namespace = assertNamespace(cfg.namespace ?? DEFAULTS.namespace);
222
304
  return withSurface({
@@ -229,6 +311,7 @@ export function readConfig(cwd = process.cwd(), env = process.env) {
229
311
  narrow: { ...DEFAULTS.narrow, ...(cfg.narrow ?? {}) },
230
312
  surface: cfg.surface ?? null,
231
313
  routing,
314
+ configPath: path,
232
315
  });
233
316
  }
234
317
 
@@ -16,9 +16,11 @@ import {
16
16
  renderAutomationGroups,
17
17
  } from "./automation-status-expected-fleet.mjs";
18
18
  import {
19
+ RUNBOOK_NOT_SCAFFOLDED_LINE,
19
20
  resolveAutomationRunDisplay,
20
21
  resolveRecoveryEscalation,
21
22
  } from "./automation-status-run-history.mjs";
23
+ import { resolveUnrecordedRunFinding } from "./automation-status-unrecorded-runs.mjs";
22
24
 
23
25
  const CLAUDE_RUNTIME_LABEL = "Claude /schedule";
24
26
  const CLAUDE_ACTIVE_STATUSES = new Set([
@@ -241,7 +243,7 @@ function createObservedStatusItem(input) {
241
243
  const comparison = input.comparison;
242
244
  const observed = comparison.observedAutomation;
243
245
  const runDisplay = input.runDisplay;
244
- const runSignal = classifyAutomationRunSignal({
246
+ const primaryRunSignal = classifyAutomationRunSignal({
245
247
  expected,
246
248
  observedAutomation: observed,
247
249
  now: input.now,
@@ -251,6 +253,27 @@ function createObservedStatusItem(input) {
251
253
  // the scheduler surface cannot see. It wins over the scheduler run-signal.
252
254
  const escalation = resolveRecoveryEscalation(runDisplay);
253
255
 
256
+ // A run the scheduler saw but the ledger did not. Ranked below `runSignal`
257
+ // on purpose: a disabled or failing scheduler entry EXPLAINS the missing
258
+ // rows, so reporting the silence over the cause would bury the cause.
259
+ const unrecorded = resolveUnrecordedRunFinding({
260
+ schedulerLastRunAt: observed?.lastRunAt,
261
+ ledgerLastRecordAt: runDisplay?.lastOutcome?.ts ?? null,
262
+ hasRunbook: runDisplay
263
+ ? runDisplay.runbook !== RUNBOOK_NOT_SCAFFOLDED_LINE
264
+ : undefined,
265
+ cadenceMs: observed
266
+ ? resolveObservedCadenceMs({ observed, expected })
267
+ : null,
268
+ });
269
+ const runSignal =
270
+ primaryRunSignal ??
271
+ (unrecorded && {
272
+ status: /** @type {const} */ ("DRIFTED"),
273
+ summary: unrecorded.summary,
274
+ remediation: unrecorded.remediation,
275
+ });
276
+
254
277
  const observedDetails = [comparison.observed];
255
278
  if (observed?.status) {
256
279
  observedDetails.push(`Scheduler status: ${observed.status}`);
@@ -262,6 +285,9 @@ function createObservedStatusItem(input) {
262
285
  "Last-run metadata unavailable from Claude /schedule."
263
286
  );
264
287
  }
288
+ if (runDisplay?.lastOutcome?.ts) {
289
+ observedDetails.push(`Newest run record: ${runDisplay.lastOutcome.ts}`);
290
+ }
265
291
  if (observed?.lastRunSummary) {
266
292
  observedDetails.push(`Latest summary: ${observed.lastRunSummary}`);
267
293
  } else if (observed?.lastRunFailed == null) {
@@ -337,11 +363,10 @@ function classifyAutomationRunSignal(input) {
337
363
  return null;
338
364
  }
339
365
 
340
- const cadenceMs =
341
- rruleToIntervalMs(observed.observedRRule) ??
342
- cadenceLabelToIntervalMs(
343
- observed.observedCadence ?? input.expected.expectedCadence
344
- );
366
+ const cadenceMs = resolveObservedCadenceMs({
367
+ observed,
368
+ expected: input.expected,
369
+ });
345
370
  if (!cadenceMs) {
346
371
  return null;
347
372
  }
@@ -364,6 +389,31 @@ function classifyAutomationRunSignal(input) {
364
389
  return null;
365
390
  }
366
391
 
392
+ /**
393
+ * Milliseconds between scheduled runs, preferring what the scheduler actually
394
+ * reports over what the fleet expects.
395
+ *
396
+ * The observed RRULE wins because a loop re-cadenced on the scheduler is still
397
+ * a correctly running loop; measuring it against the expected cadence would
398
+ * manufacture findings out of an intentional change.
399
+ *
400
+ * @param {{
401
+ * readonly observed: ObservedClaudeAutomation
402
+ * readonly expected: { readonly expectedCadence?: string }
403
+ * }} input - Observed scheduler entry and its expected-fleet counterpart.
404
+ * @returns {number | null} Interval in milliseconds, or `null` when neither
405
+ * side expresses a parseable cadence.
406
+ */
407
+ function resolveObservedCadenceMs(input) {
408
+ return (
409
+ rruleToIntervalMs(input.observed.observedRRule) ??
410
+ cadenceLabelToIntervalMs(
411
+ input.observed.observedCadence ?? input.expected.expectedCadence
412
+ ) ??
413
+ null
414
+ );
415
+ }
416
+
367
417
  function coerceClaudeScheduleEntries(scheduleListing) {
368
418
  if (!scheduleListing) {
369
419
  return [];
@@ -25,9 +25,11 @@ import {
25
25
  renderAutomationGroups,
26
26
  } from "./automation-status-expected-fleet.mjs";
27
27
  import {
28
+ RUNBOOK_NOT_SCAFFOLDED_LINE,
28
29
  resolveAutomationRunDisplay,
29
30
  resolveRecoveryEscalation,
30
31
  } from "./automation-status-run-history.mjs";
32
+ import { resolveUnrecordedRunFinding } from "./automation-status-unrecorded-runs.mjs";
31
33
 
32
34
  const CODEx_RUNTIME_LABEL = "Codex automations";
33
35
  const RUN_TIMESTAMP_PATTERN = /20\d{2}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z/;
@@ -664,7 +666,7 @@ function createObservedStatusItem(input) {
664
666
  const comparison = input.comparison;
665
667
  const observed = comparison.observedAutomation;
666
668
  const runDisplay = input.runDisplay;
667
- const runSignal = classifyAutomationRunSignal({
669
+ const primaryRunSignal = classifyAutomationRunSignal({
668
670
  expected,
669
671
  observedAutomation: observed,
670
672
  now: input.now,
@@ -674,6 +676,27 @@ function createObservedStatusItem(input) {
674
676
  // the raw backing store cannot see. It wins over the scheduler run-signal.
675
677
  const escalation = resolveRecoveryEscalation(runDisplay);
676
678
 
679
+ // A run the scheduler saw but the ledger did not. Ranked below
680
+ // `primaryRunSignal` on purpose: a suspended entry or a broken cwd EXPLAINS
681
+ // the missing rows, so reporting the silence over the cause would bury it.
682
+ const unrecorded = resolveUnrecordedRunFinding({
683
+ schedulerLastRunAt: observed?.lastRunAt,
684
+ ledgerLastRecordAt: runDisplay?.lastOutcome?.ts ?? null,
685
+ hasRunbook: runDisplay
686
+ ? runDisplay.runbook !== RUNBOOK_NOT_SCAFFOLDED_LINE
687
+ : undefined,
688
+ cadenceMs: observed
689
+ ? resolveObservedCadenceMs({ observed, expected })
690
+ : null,
691
+ });
692
+ const runSignal =
693
+ primaryRunSignal ??
694
+ (unrecorded && {
695
+ status: /** @type {const} */ ("DRIFTED"),
696
+ summary: unrecorded.summary,
697
+ remediation: unrecorded.remediation,
698
+ });
699
+
677
700
  const observedDetails = [comparison.observed];
678
701
  if (observed?.status) {
679
702
  observedDetails.push(`Scheduler status: ${observed.status}`);
@@ -686,6 +709,9 @@ function createObservedStatusItem(input) {
686
709
  } else if (observed) {
687
710
  observedDetails.push("Last run metadata unavailable.");
688
711
  }
712
+ if (runDisplay?.lastOutcome?.ts) {
713
+ observedDetails.push(`Newest run record: ${runDisplay.lastOutcome.ts}`);
714
+ }
689
715
  if (observed?.lastRunSummary) {
690
716
  observedDetails.push(`Latest summary: ${observed.lastRunSummary}`);
691
717
  }
@@ -729,6 +755,29 @@ function composeAutomationSummary(input) {
729
755
  return `${input.runSignal.summary}; ${comparisonSummary}`;
730
756
  }
731
757
 
758
+ /**
759
+ * Milliseconds between scheduled runs, preferring what the scheduler actually
760
+ * reports over what the fleet expects.
761
+ *
762
+ * The observed RRULE wins because an automation re-cadenced in Codex is still
763
+ * a correctly running automation; measuring it against the expected cadence
764
+ * would manufacture findings out of an intentional change.
765
+ *
766
+ * @param {{
767
+ * readonly observed: { readonly observedRRule?: string | null }
768
+ * readonly expected: { readonly expectedCadence?: string }
769
+ * }} input - Observed automation entry and its expected-fleet counterpart.
770
+ * @returns {number | null} Interval in milliseconds, or `null` when neither
771
+ * side expresses a parseable cadence.
772
+ */
773
+ function resolveObservedCadenceMs(input) {
774
+ return (
775
+ rruleToIntervalMs(input.observed.observedRRule) ??
776
+ cadenceLabelToIntervalMs(input.expected.expectedCadence) ??
777
+ null
778
+ );
779
+ }
780
+
732
781
  function classifyAutomationRunSignal(input) {
733
782
  const observed = input.observedAutomation;
734
783
  if (!observed) {
@@ -765,9 +814,10 @@ function classifyAutomationRunSignal(input) {
765
814
  return null;
766
815
  }
767
816
 
768
- const cadenceMs =
769
- rruleToIntervalMs(observed.observedRRule) ??
770
- cadenceLabelToIntervalMs(input.expected.expectedCadence);
817
+ const cadenceMs = resolveObservedCadenceMs({
818
+ observed,
819
+ expected: input.expected,
820
+ });
771
821
  if (!cadenceMs) {
772
822
  return null;
773
823
  }
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Detect registered-loop cycles that ran and recorded nothing.
4
+ *
5
+ * The Automation Runbook Contract requires every run of a registered loop to
6
+ * end in exactly one of six recorded outcomes, but the recorder is invoked only
7
+ * by prose instruction inside each loop's `SKILL.md`. A cycle that finishes
8
+ * without running it appends no row, and an absent row is ambiguous in the one
9
+ * way that matters: it looks identical to a cycle that never ran.
10
+ *
11
+ * That ambiguity is not merely an audit gap. Cycles read the ledger tail to
12
+ * decide whether the lane was already worked, so a missing row feeds back into
13
+ * selection — the next cycle sees stale activity, concludes the lane is
14
+ * unworked, and re-picks the rung a peer is already holding.
15
+ *
16
+ * This module resolves the ambiguity with a signal the loop does not control:
17
+ * the scheduler's own last-run time. A row written by a cycle necessarily
18
+ * postdates that cycle's start, so a newest row older than the last scheduler
19
+ * run means the run in between recorded nothing. Neither side can fake it —
20
+ * the scheduler timestamp is written by the runtime, and the ledger timestamp
21
+ * by the recorder.
22
+ *
23
+ * Reporting only, never blocking, per the contract's own escape: "If recording
24
+ * still fails, degrade, never abort." Every unreadable input degrades to `null`
25
+ * rather than to a finding, because a detector that guesses would poison the
26
+ * same selection loop it exists to protect.
27
+ */
28
+
29
+ /**
30
+ * @typedef {{
31
+ * readonly missedCycles: number
32
+ * readonly schedulerLastRunAt: string
33
+ * readonly ledgerLastRecordAt: string | null
34
+ * readonly summary: string
35
+ * readonly remediation: string
36
+ * }} UnrecordedRunFinding
37
+ */
38
+
39
+ /**
40
+ * Remediation text shared by both finding shapes.
41
+ *
42
+ * It names the contract rather than the script because the omission is a
43
+ * skipped step in the loop, not a broken recorder — a broken recorder reports
44
+ * itself through the degradation path this module deliberately leaves alone.
45
+ */
46
+ const UNRECORDED_RUN_REMEDIATION =
47
+ "The loop ran without recording an outcome. Confirm the loop's SKILL.md " +
48
+ "still ends every path by invoking `automation-run-record.mjs`, including " +
49
+ "the paths that find no work, per the automation-runbook-contract rule.";
50
+
51
+ /**
52
+ * Whether a scheduled run finished without appending a run record.
53
+ *
54
+ * Tolerance is one full cadence, not a fixed grace period. The scheduler's
55
+ * `lastRunAt` may be stamped at either end of a cycle depending on runtime, and
56
+ * a cycle can legitimately run for many minutes, so anything tighter would
57
+ * report a slow-but-honest loop as a silent one. A full cadence cannot be
58
+ * crossed by a single well-behaved run: it means an entire scheduled cycle came
59
+ * and went between the newest row and the newest run.
60
+ *
61
+ * @param {{
62
+ * readonly schedulerLastRunAt?: string | null
63
+ * readonly ledgerLastRecordAt?: string | null
64
+ * readonly hasRunbook?: boolean
65
+ * readonly cadenceMs?: number | null
66
+ * }} input - Scheduler-side run time, ledger-side newest record, and cadence.
67
+ * @returns {UnrecordedRunFinding | null} The finding, or `null` when the
68
+ * comparison cannot be made from trustworthy inputs.
69
+ */
70
+ export function resolveUnrecordedRunFinding(input) {
71
+ const cadenceMs = input.cadenceMs;
72
+ if (!cadenceMs || !Number.isFinite(cadenceMs) || cadenceMs <= 0) {
73
+ return null;
74
+ }
75
+
76
+ // No scheduler timestamp means the runtime never reported a run, which is
77
+ // indistinguishable from a loop registered moments ago. Silence here is the
78
+ // honest answer, and `classifyAutomationRunSignal` already reports the
79
+ // missing metadata separately.
80
+ if (!input.schedulerLastRunAt) {
81
+ return null;
82
+ }
83
+ const schedulerLastRun = Date.parse(input.schedulerLastRunAt);
84
+ if (Number.isNaN(schedulerLastRun)) {
85
+ return null;
86
+ }
87
+
88
+ // A loop with no runbook is not yet under the contract; `automation-status`
89
+ // reports the un-scaffolded runbook itself, and stacking a second finding on
90
+ // it would blame the loop for a setup step it never took.
91
+ if (input.hasRunbook === false) {
92
+ return null;
93
+ }
94
+
95
+ if (!input.ledgerLastRecordAt) {
96
+ return {
97
+ missedCycles: 1,
98
+ schedulerLastRunAt: input.schedulerLastRunAt,
99
+ ledgerLastRecordAt: null,
100
+ summary: `scheduler reports a run at ${input.schedulerLastRunAt} but the ledger holds no record at all`,
101
+ remediation: UNRECORDED_RUN_REMEDIATION,
102
+ };
103
+ }
104
+
105
+ const ledgerLastRecord = Date.parse(input.ledgerLastRecordAt);
106
+ if (Number.isNaN(ledgerLastRecord)) {
107
+ return null;
108
+ }
109
+
110
+ const gapMs = schedulerLastRun - ledgerLastRecord;
111
+ if (gapMs <= cadenceMs) {
112
+ return null;
113
+ }
114
+
115
+ const missedCycles = Math.floor(gapMs / cadenceMs);
116
+ return {
117
+ missedCycles,
118
+ schedulerLastRunAt: input.schedulerLastRunAt,
119
+ ledgerLastRecordAt: input.ledgerLastRecordAt,
120
+ summary: `${missedCycles} scheduled ${
121
+ missedCycles === 1 ? "run" : "runs"
122
+ } recorded no outcome (newest record ${input.ledgerLastRecordAt}, last run ${input.schedulerLastRunAt})`,
123
+ remediation: UNRECORDED_RUN_REMEDIATION,
124
+ };
125
+ }
126
+
127
+ export { UNRECORDED_RUN_REMEDIATION };
@@ -189,11 +189,26 @@ export function report(result, cfg) {
189
189
  } else {
190
190
  lines.push(
191
191
  `Secrets preflight FAILED on surface "${cfg.surface}".`,
192
- `These credentials are required and resolve nowhere not in the`,
193
- `environment, not materialized, not in the "${cfg.provider}" grant.`,
192
+ `These credentials are required and were not found in the surfaces`,
193
+ `consulted — the environment, the materialized file, and the`,
194
+ `"${cfg.provider}" grant.`,
194
195
  `Extend the grant in the vault (or correct the routing that requires`,
195
196
  `them), then start a new session:`
196
197
  );
198
+ // A defaulted provider is the one case where the list above is not the
199
+ // whole story: no config was found, so the vault a project actually
200
+ // declares was never contacted. Saying "resolve nowhere" there sends the
201
+ // reader to grant a credential that was never absent.
202
+ if (!cfg.configPath) {
203
+ lines.push(
204
+ ``,
205
+ `NOTE: no .lisa.config.json was found at or above the working`,
206
+ `directory, so provider "${cfg.provider}" is a DEFAULT, not this`,
207
+ `project's setting. If this project uses a vault, the credential may`,
208
+ `resolve fine — start the session from the repository root, or check`,
209
+ `the config is present, before treating this as missing.`
210
+ );
211
+ }
197
212
  }
198
213
  lines.push(``);
199
214
  for (const { name, reasons } of result.missing) {