@skrr-ai/cli 0.1.145 → 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.
@@ -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,14 +65,18 @@ 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");
72
81
  const planOutcome_1 = require("./planOutcome");
73
82
  exports.TRIGGER_KINDS = [
@@ -904,6 +913,85 @@ function describeScheduledFire(result) {
904
913
  }
905
914
  return undefined;
906
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
+ }
907
995
  /**
908
996
  * Was the fire admitted? `in_progress` and `awaiting_runtime` are admissions whose terminal arrives
909
997
  * later (every agent-turn fire answers `in_progress`), and a repeat of a fire that was admitted is
@@ -948,6 +1036,11 @@ function describeFireDetail(result) {
948
1036
  else if (typeof result.retryAt === 'string' && result.retryAt) {
949
1037
  lines.push(`Try again after ${result.retryAt}.`);
950
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());
951
1044
  // A fire option the server does not read is named, because dropping it without a word left a caller
952
1045
  // unable to tell whether `--from-json` was honoured (OSK-15498).
953
1046
  if (Array.isArray(result.ignoredOptions) && result.ignoredOptions.length > 0) {
@@ -1341,20 +1434,46 @@ function schedulerLimitSentence(limits) {
1341
1434
  * trigger did not plainly confirm it is live.
1342
1435
  */
1343
1436
  function armedStateLabel(enabled, lastResult,
1344
- /** 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
+ */
1345
1441
  oneShot,
1346
1442
  /** The server's reading of the scheduler's run limits: a reached limit means no slot will run (OSK-22526). */
1347
- schedulerLimits) {
1443
+ schedulerLimits,
1444
+ /** The server's reading of what the trigger's window does to its next runs (OSK-22529). */
1445
+ windowVerdict) {
1348
1446
  if (enabled === false && oneShot && (oneShot.fires ?? 0) > 0) {
1349
1447
  return 'no — already fired (a one-shot trigger is spent once it fires)';
1350
1448
  }
1351
1449
  if (enabled === false && oneShot && (oneShot.failures ?? 0) > 0) {
1352
1450
  return 'no — its one fire already ran and did not succeed (a one-shot trigger is spent; see `skrr triggers audit`)';
1353
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
+ }
1354
1467
  if (enabled === false)
1355
1468
  return 'no — inert until enabled';
1356
1469
  if (schedulerLimits?.state === 'reached')
1357
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
+ }
1358
1477
  // "Will fire" is the row's intent. A platform-managed row whose owner is fenced (Always-On off) ticks on
1359
1478
  // schedule and is skipped every time, and the same screen's `Fires:` line says so; the first line a reader
1360
1479
  // meets must not say the opposite (dogfood df-261031-commitment-authoring, OSK-21103).
@@ -1595,8 +1714,13 @@ function renderTriggerSummary(trigger, log, options = {}) {
1595
1714
  log(`ID: ${trigger.id ?? '-'}`);
1596
1715
  log(`Kind: ${trigger.kind ?? '-'}`);
1597
1716
  log(`Armed: ${armedStateLabel(trigger.enabled, trigger.audit?.lastResult, trigger.kind === 'once'
1598
- ? { fires: trigger.audit?.fireCount, failures: trigger.audit?.failureCount }
1599
- : 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)}`);
1600
1724
  log(`Scope: ${scopeLabel(trigger)}`);
1601
1725
  /*
1602
1726
  * Say when the row is not yours to change.
@@ -1631,6 +1755,8 @@ function renderTriggerSummary(trigger, log, options = {}) {
1631
1755
  const schedule = scheduleSummaryLine(trigger);
1632
1756
  if (schedule)
1633
1757
  log(`Schedule: ${schedule}`);
1758
+ for (const line of windowVerdictLines(trigger))
1759
+ log(line);
1634
1760
  const debounceText = debounceSummaryLine(trigger);
1635
1761
  if (debounceText)
1636
1762
  log(`Debounce: ${debounceText}`);
@@ -1691,8 +1817,18 @@ function renderTriggerSummary(trigger, log, options = {}) {
1691
1817
  const upcoming = Boolean(scheduledRunAt(trigger));
1692
1818
  // A slot the scheduler will drop is not a run to wait for (OSK-22526).
1693
1819
  const dropped = upcoming && trigger.schedulerLimits?.state === 'reached';
1694
- log(`${upcoming ? (dropped ? 'Next slot:' : 'Next run:') : 'Last run:'}${next.length > 0 ? ` ${next}` : ''}` +
1695
- `${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}`);
1696
1832
  }
1697
1833
  /*
1698
1834
  * What actually happened when it fired.
@@ -1717,8 +1853,9 @@ function renderTriggerSummary(trigger, log, options = {}) {
1717
1853
  const parts = [`${fires} succeeded`];
1718
1854
  if (failures !== undefined)
1719
1855
  parts.push(`${failures} failed`);
1720
- if (audit.lastResult)
1721
- parts.push(`last ${audit.lastResult}`);
1856
+ const last = lastResultLabel(trigger);
1857
+ if (last)
1858
+ parts.push(`last ${last}`);
1722
1859
  log(`Fires: ${parts.join(', ')}`);
1723
1860
  }
1724
1861
  // `last tools_refused:...` above is a success that held a refusal. Say what that means.
@@ -1775,15 +1912,60 @@ function skippedWindowClause(window, kind) {
1775
1912
  if (!window || window.kind !== kind || !window.start || !window.end)
1776
1913
  return null;
1777
1914
  const zone = window.timezone || 'UTC';
1778
- const label = kind === 'working_hours' ? 'working hours' : 'quiet hours';
1779
1915
  const judged = window.localTime
1780
1916
  ? `It was judged at ${window.localTime} ${zone}`
1781
1917
  : `It was judged at ${window.evaluatedAt ?? 'the time it came due'}`;
1782
1918
  const relation = kind === 'working_hours' ? 'outside' : 'inside';
1783
- const defaulted = window.timezoneDefaulted
1784
- ? ' The window sets no timezone, so it is read in UTC.'
1785
- : '';
1786
- 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;
1787
1969
  }
1788
1970
  /**
1789
1971
  * Why a fire was skipped by a working or quiet window, in words. Both trigger-level windows (Gate 5)
@@ -1829,13 +2011,31 @@ function clockSkipAuditExplanation(fire) {
1829
2011
  * (gate 7) finding an earlier fire still holding it: this occurrence was dropped, not queued, and an
1830
2012
  * occurrence that was dropped is consumed, so it is not retried (OSK-22509). The raw code alone read
1831
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.
1832
2019
  */
1833
2020
  function coalescedAuditExplanation(fire) {
1834
2021
  if (fire.outcome !== 'coalesced')
1835
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
+ : '';
1836
2032
  return {
1837
- summary: 'Not run: lane already busy',
1838
- 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.',
1839
2039
  };
1840
2040
  }
1841
2041
  /** Why no new inbox card was written, by the code the server records. Unknown codes are shown as they are. */
@@ -1894,14 +2094,35 @@ function policyAuditExplanation(fire) {
1894
2094
  detail: `The Agent policy prevented autonomous execution. Review the trigger preflight and Agent policy. ${card}`,
1895
2095
  };
1896
2096
  }
1897
- 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
+ }
1898
2119
  if (fires.length === 0) {
1899
2120
  log('No fire audit records.');
1900
2121
  return;
1901
2122
  }
1902
2123
  (0, format_1.renderTable)(fires.map((fire) => ({
1903
2124
  trigger: fire.triggerId ?? '',
1904
- firedAt: fire.firedAt ?? '-',
2125
+ firedAt: options.timeZone ? (0, format_1.zonedTime)(fire.firedAt, options.timeZone, { seconds: false }) : (fire.firedAt ?? '-'),
1905
2126
  outcome: fire.outcome ?? '-',
1906
2127
  source: fire.source ?? '-',
1907
2128
  reason: fire.metadata?.recordKind === 'schedule_end_marker'
@@ -1910,7 +2131,7 @@ function renderFireAudit(fires, log) {
1910
2131
  policyAuditExplanation(fire)?.summary ??
1911
2132
  coalescedAuditExplanation(fire)?.summary ??
1912
2133
  (0, planOutcome_1.fireAuditPlanOutcomeSummary)(fire) ??
1913
- fire.reason ??
2134
+ (fire.reason ? fireReasonText(fire.reason) : undefined) ??
1914
2135
  fire.errorMessage ??
1915
2136
  '',
1916
2137
  duration: fire.durationMs === undefined ? '-' : `${fire.durationMs}ms`,
@@ -1955,7 +2176,14 @@ exports.triggerApi = {
1955
2176
  }),
1956
2177
  setAuthorizationRevoked: (id, revoked) => data_provider_1.request.patch(`/api/triggers/${encodeURIComponent(id)}/authorization`, { revoked }),
1957
2178
  delete: (id) => data_provider_1.request.delete(`/api/triggers/${encodeURIComponent(id)}`),
1958
- 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
+ }),
1959
2187
  /**
1960
2188
  * Dry-run: per-gate verdicts, rendered prompt, resolved destination and the
1961
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": {