@skrr-ai/cli 0.1.144 → 0.1.146

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 (42) hide show
  1. package/README.md +5 -0
  2. package/dist/commands/agenda/plan.d.ts +21 -0
  3. package/dist/commands/agenda/plan.js +46 -0
  4. package/dist/commands/agent/message/approve.js +7 -5
  5. package/dist/commands/agent/message/decline.js +7 -5
  6. package/dist/commands/agent/message/pending.js +1 -1
  7. package/dist/commands/agents/always-on/enable.js +1 -1
  8. package/dist/commands/agents/plan-day.d.ts +11 -0
  9. package/dist/commands/agents/plan-day.js +41 -2
  10. package/dist/commands/agents/schedule-overview.js +15 -10
  11. package/dist/commands/agents/schedule-trace.js +12 -2
  12. package/dist/commands/agents/spawn.d.ts +73 -1
  13. package/dist/commands/agents/spawn.js +274 -5
  14. package/dist/commands/agents/triggers/fire.js +20 -0
  15. package/dist/commands/agents/upcoming.d.ts +1 -0
  16. package/dist/commands/agents/upcoming.js +18 -7
  17. package/dist/commands/commitments/create.js +1 -1
  18. package/dist/commands/commitments/update.js +1 -1
  19. package/dist/commands/spaces/workflow-templates/insert.js +4 -0
  20. package/dist/commands/store/show.js +22 -0
  21. package/dist/commands/triggers/audit.js +1 -1
  22. package/dist/commands/triggers/fire.js +19 -0
  23. package/dist/generated/agent-guides.json +19 -19
  24. package/dist/lib/agentic-stream.d.ts +28 -0
  25. package/dist/lib/agentic-stream.js +89 -1
  26. package/dist/lib/commitments.js +13 -1
  27. package/dist/lib/compasses.js +1 -1
  28. package/dist/lib/dedicated-power.js +10 -3
  29. package/dist/lib/format.d.ts +20 -0
  30. package/dist/lib/format.js +47 -0
  31. package/dist/lib/planOutcome.d.ts +51 -0
  32. package/dist/lib/planOutcome.js +88 -0
  33. package/dist/lib/proactiveApi.d.ts +100 -1
  34. package/dist/lib/proactiveApi.js +27 -2
  35. package/dist/lib/schedule.d.ts +40 -1
  36. package/dist/lib/schedule.js +51 -2
  37. package/dist/lib/triggers.d.ts +134 -3
  38. package/dist/lib/triggers.js +260 -21
  39. package/dist/node_modules/@skrr-ai/auth-core/package.json +1 -1
  40. package/dist/node_modules/@skrr-ai/data-provider/index.js +4677 -4673
  41. package/oclif.manifest.json +40 -4
  42. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.triggerApi = exports.TRIGGER_LIMIT_CEILING = exports.TRIGGER_MODE_FLAG_DESCRIPTION = exports.TRIGGER_WINDOW_FLAG_HELP = exports.AgentTriggerScopeError = exports.TRIGGER_MODE_REQUIRED_FLAGS = exports.TRIGGER_CREATE_FIELD_FLAGS = exports.FLAG_OWNER_KINDS = exports.SCOPE_IMPLIED_REF_KEY = exports.TRIGGER_EVENT_CATALOG = exports.TRIGGER_EVENT_ENTITY_TYPES = exports.TRIGGER_CHAT_AUTH_MODES = exports.TRIGGER_CHAT_RESPONSE_MODES = exports.TRIGGER_CHAT_MODES = exports.TRIGGER_FORM_RESPONSE_MODES = exports.TRIGGER_CONCURRENCY_POLICIES = exports.TRIGGER_EVENT_FILTER_MODES = exports.TRIGGER_EXECUTOR_MODES = exports.TRIGGER_SCOPE_KINDS = exports.TRIGGER_KINDS = void 0;
3
+ exports.triggerApi = exports.TRIGGER_LIMIT_CEILING = exports.TRIGGER_MODE_FLAG_DESCRIPTION = exports.TRIGGER_WINDOW_FLAG_HELP = exports.AgentTriggerScopeError = exports.FIRE_FOLLOW_MAX_WAIT_MS = exports.FIRE_FOLLOW_POLL_MS = exports.TRIGGER_MODE_REQUIRED_FLAGS = exports.TRIGGER_CREATE_FIELD_FLAGS = exports.FLAG_OWNER_KINDS = exports.SCOPE_IMPLIED_REF_KEY = exports.TRIGGER_EVENT_CATALOG = exports.TRIGGER_EVENT_ENTITY_TYPES = exports.TRIGGER_CHAT_AUTH_MODES = exports.TRIGGER_CHAT_RESPONSE_MODES = exports.TRIGGER_CHAT_MODES = exports.TRIGGER_FORM_RESPONSE_MODES = exports.TRIGGER_CONCURRENCY_POLICIES = exports.TRIGGER_EVENT_FILTER_MODES = exports.TRIGGER_EXECUTOR_MODES = exports.TRIGGER_SCOPE_KINDS = exports.TRIGGER_KINDS = void 0;
4
4
  exports.validateEventReference = validateEventReference;
5
5
  exports.validateEventFilter = validateEventFilter;
6
6
  exports.serverEventCatalogIncludes = serverEventCatalogIncludes;
@@ -27,6 +27,11 @@ exports.mergeTriggerKindConfig = mergeTriggerKindConfig;
27
27
  exports.assertKindFlagsApply = assertKindFlagsApply;
28
28
  exports.assertModeRequiredFlags = assertModeRequiredFlags;
29
29
  exports.describeScheduledFire = describeScheduledFire;
30
+ exports.isFireAccepted = isFireAccepted;
31
+ exports.fireRecordIsSettled = fireRecordIsSettled;
32
+ exports.followAcceptedFire = followAcceptedFire;
33
+ exports.settleFireAnswer = settleFireAnswer;
34
+ exports.fireFollowCommand = fireFollowCommand;
30
35
  exports.fireWasAccepted = fireWasAccepted;
31
36
  exports.describeStrictFireRefusal = describeStrictFireRefusal;
32
37
  exports.describeFireDetail = describeFireDetail;
@@ -60,15 +65,20 @@ exports.scheduleSummaryLine = scheduleSummaryLine;
60
65
  exports.builtinActionLine = builtinActionLine;
61
66
  exports.renderTriggerSummary = renderTriggerSummary;
62
67
  exports.renderLegacyRuns = renderLegacyRuns;
68
+ exports.windowVerdictLines = windowVerdictLines;
69
+ exports.lastResultLabel = lastResultLabel;
63
70
  exports.clockSkipAuditExplanation = clockSkipAuditExplanation;
64
71
  exports.coalescedAuditExplanation = coalescedAuditExplanation;
65
72
  exports.policyCardSentence = policyCardSentence;
66
73
  exports.policyAuditExplanation = policyAuditExplanation;
74
+ exports.fireReasonText = fireReasonText;
67
75
  exports.renderFireAudit = renderFireAudit;
68
76
  exports.describeTriggerBudget = describeTriggerBudget;
69
77
  const data_provider_1 = require("@skrr-ai/data-provider");
70
78
  const node_fs_1 = require("node:fs");
79
+ const http_error_1 = require("./http-error");
71
80
  const format_1 = require("./format");
81
+ const planOutcome_1 = require("./planOutcome");
72
82
  exports.TRIGGER_KINDS = [
73
83
  'schedule',
74
84
  'once',
@@ -883,8 +893,9 @@ function describeScheduledFire(result) {
883
893
  const report = result.scheduledFire;
884
894
  if (typeof report !== 'object' || report === null)
885
895
  return undefined;
886
- const { wouldRun, reason, bypassed } = report;
896
+ const { wouldRun, reason, reasonText, bypassed } = report;
887
897
  const why = typeof reason === 'string' && reason ? ` (${reason})` : '';
898
+ const sentence = typeof reasonText === 'string' && reasonText.trim() ? reasonText.trim() : null;
888
899
  if (Array.isArray(bypassed) && bypassed.length > 0) {
889
900
  const gates = bypassed
890
901
  .map((entry) => `${String(entry.gate)}${entry.reason ? ` (${String(entry.reason)})` : ''}`)
@@ -892,6 +903,9 @@ function describeScheduledFire(result) {
892
903
  return `Note: this manual fire bypassed ${gates}; a scheduled fire would not run.`;
893
904
  }
894
905
  if (wouldRun === false) {
906
+ if (sentence) {
907
+ return `Note: a scheduled fire would not run. ${sentence} A manual fire is exempt from that check.`;
908
+ }
895
909
  return `Note: a scheduled fire would not run${why}; a manual fire is exempt from that check.`;
896
910
  }
897
911
  if (wouldRun === null) {
@@ -899,6 +913,85 @@ function describeScheduledFire(result) {
899
913
  }
900
914
  return undefined;
901
915
  }
916
+ function isFireAccepted(value) {
917
+ return (Boolean(value) &&
918
+ typeof value === 'object' &&
919
+ value.accepted === true &&
920
+ value.outcome === 'running');
921
+ }
922
+ /** A fire record still being worked: `pending` is the claim before the outcome is written. */
923
+ function fireRecordIsSettled(record) {
924
+ return Boolean(record) && typeof record.outcome === 'string' && record.outcome !== 'pending';
925
+ }
926
+ exports.FIRE_FOLLOW_POLL_MS = 3_000;
927
+ /** Long enough for the slowest fire seen (215 s) with room; then the poll command is printed instead. */
928
+ exports.FIRE_FOLLOW_MAX_WAIT_MS = 6 * 60 * 1000;
929
+ /**
930
+ * Follow a fire the server answered 202 for, by reading its record until the outcome is written.
931
+ * `result` is the record shaped like a synchronous fire answer (`outcome`, `reason`, ...), so the same
932
+ * strict check and detail lines apply. A record that does not exist yet is waited for: the claim is
933
+ * written a moment after the 202. Gives up after `maxWaitMs`, saying so rather than guessing.
934
+ */
935
+ async function followAcceptedFire(options) {
936
+ const { triggerId, accepted, fetchFire = async (id, fireId) => (await exports.triggerApi.fireDetail(id, fireId)), sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now = Date.now, pollMs = exports.FIRE_FOLLOW_POLL_MS, maxWaitMs = exports.FIRE_FOLLOW_MAX_WAIT_MS, onWaiting, } = options;
937
+ const occurrenceId = accepted.occurrenceId;
938
+ if (!occurrenceId)
939
+ return { settled: false, occurrenceId: null };
940
+ const startedAt = now();
941
+ for (;;) {
942
+ let record = null;
943
+ try {
944
+ record = await fetchFire(triggerId, occurrenceId);
945
+ }
946
+ catch (error) {
947
+ // Not written yet (404) or a read that failed: keep waiting; the budget below bounds it.
948
+ const status = (0, http_error_1.httpStatusOf)(error);
949
+ if (status !== undefined && status !== 404 && status < 500)
950
+ throw error;
951
+ }
952
+ if (fireRecordIsSettled(record)) {
953
+ return { settled: true, result: { ...record, ok: true, occurrenceId } };
954
+ }
955
+ const elapsed = now() - startedAt;
956
+ if (elapsed >= maxWaitMs)
957
+ return { settled: false, occurrenceId };
958
+ onWaiting?.(elapsed);
959
+ await sleep(pollMs);
960
+ }
961
+ }
962
+ /**
963
+ * A fire answer in hand: a result passes through; a `202` is followed until its record settles. Says
964
+ * (on stderr, once) that it is waiting, because a fire that took 215 s looks like a hang otherwise.
965
+ * `running` is a fire still going when the CLI stopped waiting, with the command that reads it later.
966
+ */
967
+ async function settleFireAnswer(options) {
968
+ const { triggerId, agentId, bin, answer, follow = followAcceptedFire, note = () => { } } = options;
969
+ if (!isFireAccepted(answer))
970
+ return { running: false, result: answer };
971
+ let noted = false;
972
+ const followed = await follow({
973
+ triggerId,
974
+ accepted: answer,
975
+ onWaiting: () => {
976
+ if (noted)
977
+ return;
978
+ noted = true;
979
+ note(`The fire is still running on the server (occurrence ${answer.occurrenceId}); waiting for its result...`);
980
+ },
981
+ });
982
+ if (followed.settled)
983
+ return { running: false, result: followed.result };
984
+ return {
985
+ running: true,
986
+ answer,
987
+ command: fireFollowCommand(bin, agentId, triggerId, answer.occurrenceId),
988
+ };
989
+ }
990
+ /** The command that reads a fire later, for a fire still running when the CLI stopped waiting. */
991
+ function fireFollowCommand(bin, agentId, triggerId, occurrenceId) {
992
+ const target = agentId ? `agents triggers runs ${agentId} ${triggerId}` : `triggers runs ${triggerId}`;
993
+ return `${bin} ${target}${occurrenceId ? ` --fire ${occurrenceId}` : ''}`;
994
+ }
902
995
  /**
903
996
  * Was the fire admitted? `in_progress` and `awaiting_runtime` are admissions whose terminal arrives
904
997
  * later (every agent-turn fire answers `in_progress`), and a repeat of a fire that was admitted is
@@ -943,6 +1036,11 @@ function describeFireDetail(result) {
943
1036
  else if (typeof result.retryAt === 'string' && result.retryAt) {
944
1037
  lines.push(`Try again after ${result.retryAt}.`);
945
1038
  }
1039
+ // What a watcher said about itself (what it looked at, whether a cap cut the read, why each thing it
1040
+ // found was or was not surfaced), when the fire's record carries it (OSK-22414).
1041
+ const recordSummary = result.metadata?.summary;
1042
+ if (typeof recordSummary === 'string' && recordSummary.trim())
1043
+ lines.push(recordSummary.trim());
946
1044
  // A fire option the server does not read is named, because dropping it without a word left a caller
947
1045
  // unable to tell whether `--from-json` was honoured (OSK-15498).
948
1046
  if (Array.isArray(result.ignoredOptions) && result.ignoredOptions.length > 0) {
@@ -1336,20 +1434,46 @@ function schedulerLimitSentence(limits) {
1336
1434
  * trigger did not plainly confirm it is live.
1337
1435
  */
1338
1436
  function armedStateLabel(enabled, lastResult,
1339
- /** Pass for a `once` trigger: how often its single fire ran. A spent one-shot is not waiting to be enabled (OSK-21509). */
1437
+ /**
1438
+ * Pass for a `once` trigger: how often its single fire ran, whether it has been consumed (`firedAt`, which a
1439
+ * skip sets too), and its id for the re-arm command. A spent one-shot is not waiting to be enabled (OSK-21509).
1440
+ */
1340
1441
  oneShot,
1341
1442
  /** The server's reading of the scheduler's run limits: a reached limit means no slot will run (OSK-22526). */
1342
- schedulerLimits) {
1443
+ schedulerLimits,
1444
+ /** The server's reading of what the trigger's window does to its next runs (OSK-22529). */
1445
+ windowVerdict) {
1343
1446
  if (enabled === false && oneShot && (oneShot.fires ?? 0) > 0) {
1344
1447
  return 'no — already fired (a one-shot trigger is spent once it fires)';
1345
1448
  }
1346
1449
  if (enabled === false && oneShot && (oneShot.failures ?? 0) > 0) {
1347
1450
  return 'no — its one fire already ran and did not succeed (a one-shot trigger is spent; see `skrr triggers audit`)';
1348
1451
  }
1452
+ // A one-shot has one occurrence, and a skip consumes it as a fire does: it is spent whether or not it is
1453
+ // enabled, and enabling it again re-arms nothing (OSK-22529).
1454
+ if (oneShot?.firedAt) {
1455
+ if ((oneShot.fires ?? 0) > 0)
1456
+ return 'no — already fired (a one-shot trigger is spent once it fires)';
1457
+ if ((oneShot.failures ?? 0) > 0) {
1458
+ return 'no — its one fire already ran and did not succeed (a one-shot trigger is spent; see `skrr triggers audit`)';
1459
+ }
1460
+ const id = oneShot.id ?? '<id>';
1461
+ const code = typeof lastResult === 'string' ? lastResult.split(':')[0] : '';
1462
+ const why = clockSkipAuditExplanation({ reason: code, outcome: code, source: 'once' })?.summary ??
1463
+ (lastResult ? `its one occurrence ended ${lastResult}` : 'its one occurrence is used up');
1464
+ return (`no — spent: ${why.charAt(0).toLowerCase()}${why.slice(1)}, and a one-shot does not retry. ` +
1465
+ `Re-arm it with \`skrr triggers update ${id} --at <time>\`${enabled === false ? ` and then \`skrr triggers enable ${id}\`` : ''}`);
1466
+ }
1349
1467
  if (enabled === false)
1350
1468
  return 'no — inert until enabled';
1351
1469
  if (schedulerLimits?.state === 'reached')
1352
1470
  return `no — ${schedulerLimitSentence(schedulerLimits)}`;
1471
+ if (windowVerdict?.state === 'blocks_all') {
1472
+ return `no — its ${windowVerdict.windows.map(windowSpan).join(' and ')} block every projected run, so nothing will fire (see \`skrr triggers preflight\`)`;
1473
+ }
1474
+ if (windowVerdict?.state === 'blocks_next') {
1475
+ return `yes — but its next run falls ${windowVerdict.reason === 'outside_working_hours' ? 'outside its working hours' : 'inside its quiet hours'} and will be skipped`;
1476
+ }
1353
1477
  // "Will fire" is the row's intent. A platform-managed row whose owner is fenced (Always-On off) ticks on
1354
1478
  // schedule and is skipped every time, and the same screen's `Fires:` line says so; the first line a reader
1355
1479
  // meets must not say the opposite (dogfood df-261031-commitment-authoring, OSK-21103).
@@ -1590,8 +1714,13 @@ function renderTriggerSummary(trigger, log, options = {}) {
1590
1714
  log(`ID: ${trigger.id ?? '-'}`);
1591
1715
  log(`Kind: ${trigger.kind ?? '-'}`);
1592
1716
  log(`Armed: ${armedStateLabel(trigger.enabled, trigger.audit?.lastResult, trigger.kind === 'once'
1593
- ? { fires: trigger.audit?.fireCount, failures: trigger.audit?.failureCount }
1594
- : undefined, trigger.schedulerLimits)}`);
1717
+ ? {
1718
+ fires: trigger.audit?.fireCount,
1719
+ failures: trigger.audit?.failureCount,
1720
+ firedAt: trigger.once?.firedAt,
1721
+ id: trigger.id,
1722
+ }
1723
+ : undefined, trigger.schedulerLimits, trigger.windowVerdict)}`);
1595
1724
  log(`Scope: ${scopeLabel(trigger)}`);
1596
1725
  /*
1597
1726
  * Say when the row is not yours to change.
@@ -1626,6 +1755,8 @@ function renderTriggerSummary(trigger, log, options = {}) {
1626
1755
  const schedule = scheduleSummaryLine(trigger);
1627
1756
  if (schedule)
1628
1757
  log(`Schedule: ${schedule}`);
1758
+ for (const line of windowVerdictLines(trigger))
1759
+ log(line);
1629
1760
  const debounceText = debounceSummaryLine(trigger);
1630
1761
  if (debounceText)
1631
1762
  log(`Debounce: ${debounceText}`);
@@ -1686,8 +1817,18 @@ function renderTriggerSummary(trigger, log, options = {}) {
1686
1817
  const upcoming = Boolean(scheduledRunAt(trigger));
1687
1818
  // A slot the scheduler will drop is not a run to wait for (OSK-22526).
1688
1819
  const dropped = upcoming && trigger.schedulerLimits?.state === 'reached';
1689
- log(`${upcoming ? (dropped ? 'Next slot:' : 'Next run:') : 'Last run:'}${next.length > 0 ? ` ${next}` : ''}` +
1690
- `${dropped ? ' (will be skipped: the scheduler\'s run limit is reached)' : ''}`);
1820
+ // The same for a slot the trigger's own window will skip (OSK-22529).
1821
+ const verdict = trigger.windowVerdict;
1822
+ const windowed = upcoming &&
1823
+ !dropped &&
1824
+ verdict !== undefined &&
1825
+ (verdict.state === 'blocks_all' || verdict.state === 'blocks_next') &&
1826
+ Date.parse(String(verdict.next)) === Date.parse(next);
1827
+ const windowNote = windowed
1828
+ ? ` (will be skipped: ${verdict?.reason === 'outside_working_hours' ? 'outside the working hours' : 'inside the quiet hours'})`
1829
+ : '';
1830
+ log(`${upcoming ? (dropped || windowed ? 'Next slot:' : 'Next run:') : 'Last run:'}${next.length > 0 ? ` ${next}` : ''}` +
1831
+ `${dropped ? ' (will be skipped: the scheduler\'s run limit is reached)' : windowNote}`);
1691
1832
  }
1692
1833
  /*
1693
1834
  * What actually happened when it fired.
@@ -1712,8 +1853,9 @@ function renderTriggerSummary(trigger, log, options = {}) {
1712
1853
  const parts = [`${fires} succeeded`];
1713
1854
  if (failures !== undefined)
1714
1855
  parts.push(`${failures} failed`);
1715
- if (audit.lastResult)
1716
- parts.push(`last ${audit.lastResult}`);
1856
+ const last = lastResultLabel(trigger);
1857
+ if (last)
1858
+ parts.push(`last ${last}`);
1717
1859
  log(`Fires: ${parts.join(', ')}`);
1718
1860
  }
1719
1861
  // `last tools_refused:...` above is a success that held a refusal. Say what that means.
@@ -1770,15 +1912,60 @@ function skippedWindowClause(window, kind) {
1770
1912
  if (!window || window.kind !== kind || !window.start || !window.end)
1771
1913
  return null;
1772
1914
  const zone = window.timezone || 'UTC';
1773
- const label = kind === 'working_hours' ? 'working hours' : 'quiet hours';
1774
1915
  const judged = window.localTime
1775
1916
  ? `It was judged at ${window.localTime} ${zone}`
1776
1917
  : `It was judged at ${window.evaluatedAt ?? 'the time it came due'}`;
1777
1918
  const relation = kind === 'working_hours' ? 'outside' : 'inside';
1778
- const defaulted = window.timezoneDefaulted
1779
- ? ' The window sets no timezone, so it is read in UTC.'
1780
- : '';
1781
- return `${judged}, ${relation} the trigger's ${label} ${window.start}-${window.end} ${zone}.${defaulted}`;
1919
+ return `${judged}, ${relation} the trigger's ${windowSpan(window)}.${windowZoneNote(window)}`;
1920
+ }
1921
+ /** `working hours 09:00-17:00 UTC`: the window as the audit and `show` both name it. */
1922
+ function windowSpan(window) {
1923
+ const label = window.kind === 'working_hours' ? 'working hours' : 'quiet hours';
1924
+ return `${label} ${window.start}-${window.end} ${window.timezone || 'UTC'}`;
1925
+ }
1926
+ /** The sentence that says a window chose no zone, or nothing. */
1927
+ function windowZoneNote(window) {
1928
+ return window.timezoneDefaulted ? ' The window sets no timezone, so it is read in UTC.' : '';
1929
+ }
1930
+ /**
1931
+ * The window lines `triggers show` prints (OSK-22529): each enabled window with its zone, then what it does
1932
+ * to the next occurrences, in the server's reading. Empty for a trigger with no window, or when the server
1933
+ * did not send one (an older server): unknown is not printed as clear.
1934
+ */
1935
+ function windowVerdictLines(trigger) {
1936
+ const verdict = trigger.windowVerdict;
1937
+ if (!verdict?.windows?.length)
1938
+ return [];
1939
+ const lines = verdict.windows.map((window) => `Window: ${windowSpan(window)}.${windowZoneNote(window)}`);
1940
+ const relation = verdict.reason === 'outside_working_hours' ? 'outside the working hours' : 'inside the quiet hours';
1941
+ if (verdict.state === 'blocks_all') {
1942
+ lines.push(verdict.checked === 1
1943
+ ? ` The next run, ${verdict.next}, falls ${relation}: it will be skipped and nothing else is scheduled.`
1944
+ : ` Blocks every projected run (the next ${verdict.checked}, from ${verdict.next}, all ${relation}): none will run until the window or the schedule changes.`);
1945
+ }
1946
+ else if (verdict.state === 'blocks_next') {
1947
+ lines.push(` The next run, ${verdict.next}, falls ${relation} and will be skipped; ${verdict.firstClear} is the first that runs.`);
1948
+ }
1949
+ return lines;
1950
+ }
1951
+ /**
1952
+ * `Fires: ..., last <this>`. A window skip is recorded as `outcome:reason` with the same code on both sides,
1953
+ * so the line read `last outside_working_hours:outside_working_hours`; it says the sentence the audit says
1954
+ * (`clockSkipAuditExplanation`), and any other result is printed as recorded.
1955
+ */
1956
+ function lastResultLabel(trigger) {
1957
+ const last = trigger.audit?.lastResult;
1958
+ if (typeof last !== 'string' || !last)
1959
+ return undefined;
1960
+ const code = /^(outside_working_hours|inside_quiet_hours)(?::\1)?$/.exec(last)?.[1];
1961
+ if (!code)
1962
+ return last;
1963
+ const summary = clockSkipAuditExplanation({
1964
+ reason: code,
1965
+ outcome: code,
1966
+ source: trigger.kind === 'once' ? 'once' : 'schedule',
1967
+ })?.summary;
1968
+ return summary ? summary.charAt(0).toLowerCase() + summary.slice(1) : last;
1782
1969
  }
1783
1970
  /**
1784
1971
  * Why a fire was skipped by a working or quiet window, in words. Both trigger-level windows (Gate 5)
@@ -1824,13 +2011,31 @@ function clockSkipAuditExplanation(fire) {
1824
2011
  * (gate 7) finding an earlier fire still holding it: this occurrence was dropped, not queued, and an
1825
2012
  * occurrence that was dropped is consumed, so it is not retried (OSK-22509). The raw code alone read
1826
2013
  * as a fire that was still in progress.
2014
+ *
2015
+ * The server records who held the lane and when its lease lapses (`metadata.lane`, OSK-22625). A lane
2016
+ * is held by a lease its holder renews every minute, so `holdsUntil` is the latest the lane stays
2017
+ * busy if the holder has died; a live holder keeps extending it. A fire from before the server wrote
2018
+ * this keeps the general sentence.
1827
2019
  */
1828
2020
  function coalescedAuditExplanation(fire) {
1829
2021
  if (fire.outcome !== 'coalesced')
1830
2022
  return null;
2023
+ const lane = fire.metadata
2024
+ ?.lane;
2025
+ const holdsUntil = typeof lane?.holdsUntil === 'string' && Number.isFinite(Date.parse(lane.holdsUntil))
2026
+ ? lane.holdsUntil
2027
+ : null;
2028
+ const heldBy = typeof lane?.heldBy?.occurrenceId === 'string' ? lane.heldBy.occurrenceId : null;
2029
+ const holder = holdsUntil
2030
+ ? ` The lane was held${heldBy ? ` by occurrence ${heldBy}` : ' by an earlier fire'} and stays busy until ${holdsUntil} at the latest: its holder renews the lease every minute, so a run that is still alive keeps it and one that died (for example when the server task running it was replaced) releases it at that time.`
2031
+ : '';
1831
2032
  return {
1832
- summary: 'Not run: lane already busy',
1833
- detail: 'An earlier fire under the same concurrency lane was still running when this occurrence came due, so it was dropped, not queued, and will not retry automatically. `skrr triggers preflight <id> --json` shows the lane (concurrencyKey); a trigger that stores no key coalesces only against itself.',
2033
+ summary: holdsUntil
2034
+ ? `Not run: lane busy until ${holdsUntil.slice(11, 19)}Z`
2035
+ : 'Not run: lane already busy',
2036
+ detail: 'An earlier fire under the same concurrency lane was still running when this occurrence came due, so it was dropped, not queued, and will not retry automatically.' +
2037
+ holder +
2038
+ ' `skrr triggers preflight <id> --json` shows the lane (concurrencyKey); a trigger that stores no key coalesces only against itself.',
1834
2039
  };
1835
2040
  }
1836
2041
  /** Why no new inbox card was written, by the code the server records. Unknown codes are shown as they are. */
@@ -1889,19 +2094,46 @@ function policyAuditExplanation(fire) {
1889
2094
  detail: `The Agent policy prevented autonomous execution. Review the trigger preflight and Agent policy. ${card}`,
1890
2095
  };
1891
2096
  }
1892
- function renderFireAudit(fires, log) {
2097
+ /**
2098
+ * The words for the few fire reasons that are only ever a code (OSK-22643). A reason a person can act on
2099
+ * already has its own explanation above; these two are what the scheduler records when it finishes
2100
+ * normally or runs out of runs, and read as an error when printed bare. Anything else is left as the
2101
+ * server wrote it.
2102
+ */
2103
+ function fireReasonText(reason) {
2104
+ switch (reason) {
2105
+ case 'durable_execution_completed':
2106
+ return 'Completed';
2107
+ case 'max_runs_reached':
2108
+ return 'The maximum number of runs was reached';
2109
+ default:
2110
+ return reason;
2111
+ }
2112
+ }
2113
+ function renderFireAudit(fires, log, waiting, options = {}) {
2114
+ // An armed one-shot whose time passed has no fire record yet. "No records" alone reads as
2115
+ // "not yet", so say that it is late and what it is waiting for.
2116
+ if (waiting) {
2117
+ log(`This one-shot is ${waiting.message} (${(0, format_1.formatElapsed)(waiting.bySeconds)} past its time). It has not fired, so there is no fire record yet; one appears when the scheduler picks it up.`);
2118
+ }
1893
2119
  if (fires.length === 0) {
1894
2120
  log('No fire audit records.');
1895
2121
  return;
1896
2122
  }
1897
2123
  (0, format_1.renderTable)(fires.map((fire) => ({
1898
2124
  trigger: fire.triggerId ?? '',
1899
- firedAt: fire.firedAt ?? '-',
2125
+ firedAt: options.timeZone ? (0, format_1.zonedTime)(fire.firedAt, options.timeZone, { seconds: false }) : (fire.firedAt ?? '-'),
1900
2126
  outcome: fire.outcome ?? '-',
1901
2127
  source: fire.source ?? '-',
1902
2128
  reason: fire.metadata?.recordKind === 'schedule_end_marker'
1903
2129
  ? 'Schedule ended after prior fire'
1904
- : clockSkipAuditExplanation(fire)?.summary ?? policyAuditExplanation(fire)?.summary ?? coalescedAuditExplanation(fire)?.summary ?? fire.reason ?? fire.errorMessage ?? '',
2130
+ : clockSkipAuditExplanation(fire)?.summary ??
2131
+ policyAuditExplanation(fire)?.summary ??
2132
+ coalescedAuditExplanation(fire)?.summary ??
2133
+ (0, planOutcome_1.fireAuditPlanOutcomeSummary)(fire) ??
2134
+ (fire.reason ? fireReasonText(fire.reason) : undefined) ??
2135
+ fire.errorMessage ??
2136
+ '',
1905
2137
  duration: fire.durationMs === undefined ? '-' : `${fire.durationMs}ms`,
1906
2138
  replay: fire.metadata?.replayable === true || fire.metadata?.replayContext
1907
2139
  ? 'yes'
@@ -1944,7 +2176,14 @@ exports.triggerApi = {
1944
2176
  }),
1945
2177
  setAuthorizationRevoked: (id, revoked) => data_provider_1.request.patch(`/api/triggers/${encodeURIComponent(id)}/authorization`, { revoked }),
1946
2178
  delete: (id) => data_provider_1.request.delete(`/api/triggers/${encodeURIComponent(id)}`),
1947
- fire: (id, body) => data_provider_1.request.post(`/api/triggers/${encodeURIComponent(id)}/fire-now`, body),
2179
+ fire: (id, body) =>
2180
+ // `Prefer: respond-async` (RFC 7240): a watcher fire can run for minutes and the edge gives up at
2181
+ // 60 s, so the server answers 202 with the occurrence to follow once the fire has outlived a short
2182
+ // wait, and the fast fires still answer with their result. A server that predates it ignores the
2183
+ // header and answers as it always did (OSK-22624).
2184
+ data_provider_1.request.postWithOptions(`/api/triggers/${encodeURIComponent(id)}/fire-now`, body, {
2185
+ headers: { Prefer: 'respond-async' },
2186
+ }),
1948
2187
  /**
1949
2188
  * Dry-run: per-gate verdicts, rendered prompt, resolved destination and the
1950
2189
  * next projected fires — without firing (gap analysis §A3).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skrr-ai/auth-core",
3
- "version": "0.4.35",
3
+ "version": "0.4.36",
4
4
  "main": "dist/cjs/index.js",
5
5
  "types": "dist/esm/index.d.ts",
6
6
  "exports": {