@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.
@@ -15,6 +15,7 @@ exports.zoneAbbreviation = zoneAbbreviation;
15
15
  exports.zonedTime = zonedTime;
16
16
  exports.localizeIsoInstants = localizeIsoInstants;
17
17
  exports.formatWhen = formatWhen;
18
+ exports.formatElapsed = formatElapsed;
18
19
  /**
19
20
  * Code points that occupy TWO terminal columns (Unicode East Asian Wide and
20
21
  * Fullwidth), plus the emoji blocks terminals render double-width.
@@ -474,3 +475,18 @@ function formatWhen(value, options = {}) {
474
475
  const relative = span === 'under a minute' ? 'just now' : delta >= 0 ? `in ${span}` : `${span} ago`;
475
476
  return `${stamp} (${relative})`;
476
477
  }
478
+ /**
479
+ * A span of seconds as people say it: "45s", "7m 36s", "1h 5m". Used for how far past its time a
480
+ * one-shot is, where a bare second count (456) hides that it is minutes.
481
+ */
482
+ function formatElapsed(seconds) {
483
+ const total = Math.max(0, Math.floor(seconds));
484
+ const h = Math.floor(total / 3600);
485
+ const m = Math.floor((total % 3600) / 60);
486
+ const sec = total % 60;
487
+ if (h > 0)
488
+ return m > 0 ? `${h}h ${m}m` : `${h}h`;
489
+ if (m > 0)
490
+ return sec > 0 ? `${m}m ${sec}s` : `${m}m`;
491
+ return `${sec}s`;
492
+ }
@@ -94,6 +94,39 @@ export interface PlanProactiveAgentResponse {
94
94
  outputTokens: number;
95
95
  };
96
96
  }
97
+ /**
98
+ * The `202` a `Prefer: respond-async` spawn apply answers when the install outlived the server's short
99
+ * wait: the install is running and was not cut short. NOT a receipt. The edge gives up at 60 s and an
100
+ * install takes longer, so a caller that asks this way follows the operation instead of reading a 504
101
+ * for an install that completed (OSK-22623).
102
+ */
103
+ export interface SpawnAccepted {
104
+ accepted: true;
105
+ operation: {
106
+ id: string;
107
+ state: 'running';
108
+ startedAt?: string;
109
+ };
110
+ message?: string;
111
+ }
112
+ export declare function isSpawnAccepted(value: unknown): value is SpawnAccepted;
113
+ /** A spawn operation as `GET /api/initiatives/spawn/operations/:id` reads it. */
114
+ export interface SpawnOperation {
115
+ id: string;
116
+ state: 'running' | 'succeeded' | 'failed' | 'unknown';
117
+ startedAt?: string;
118
+ finishedAt?: string;
119
+ agentId?: string;
120
+ result?: ApplyProactiveAgentResponse;
121
+ failure?: {
122
+ status?: number;
123
+ body?: {
124
+ error?: string;
125
+ message?: string;
126
+ code?: string;
127
+ };
128
+ };
129
+ }
97
130
  /** One object a spec will install (`POST /api/initiatives/spawn/preview`). */
98
131
  export interface InstallPlanItem {
99
132
  kind: string;
@@ -335,7 +368,11 @@ export declare const proactiveApi: {
335
368
  minimal?: boolean;
336
369
  /** Decline one default by name (see `DECLINABLE_DEFAULTS`). */
337
370
  without?: string[];
338
- }) => Promise<ApplyProactiveAgentResponse>;
371
+ }) => Promise<ApplyProactiveAgentResponse | SpawnAccepted>;
372
+ /** The receipt (or failure) of a spawn that answered 202. */
373
+ spawnOperation: (operationId: string) => Promise<{
374
+ operation: SpawnOperation;
375
+ }>;
339
376
  /** Read-only: every object a spec will install, marked requested or default. Never writes. */
340
377
  previewProactiveAgentSpec: (body: {
341
378
  spec: ProactiveAgentSpec;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.proactiveApi = exports.DECLINABLE_DEFAULTS = void 0;
4
+ exports.isSpawnAccepted = isSpawnAccepted;
4
5
  /**
5
6
  * proactiveApi.ts — request-based client for the "spawn a proactive agent"
6
7
  * endpoints (`/api/initiatives/spawn/*`).
@@ -15,6 +16,13 @@ exports.proactiveApi = exports.DECLINABLE_DEFAULTS = void 0;
15
16
  * → review → `apply` (creates the agent + installs the chosen system[s]).
16
17
  */
17
18
  const data_provider_1 = require("@skrr-ai/data-provider");
19
+ function isSpawnAccepted(value) {
20
+ const candidate = value;
21
+ return (Boolean(candidate) &&
22
+ typeof candidate === 'object' &&
23
+ candidate.accepted === true &&
24
+ typeof candidate.operation?.id === 'string');
25
+ }
18
26
  /** The defaults `--without` can decline; the server refuses any other name. */
19
27
  exports.DECLINABLE_DEFAULTS = [
20
28
  'memory_watcher',
@@ -26,7 +34,15 @@ exports.proactiveApi = {
26
34
  /** Plan-only: turn a sentence into a spec draft. Never writes. */
27
35
  planProactiveAgent: (body) => data_provider_1.request.post('/api/initiatives/spawn/plan', body),
28
36
  /** Apply a (clamped, server-re-validated) spec: create + install. */
29
- applyProactiveAgentSpec: (body) => data_provider_1.request.post('/api/initiatives/spawn/apply', body),
37
+ applyProactiveAgentSpec: (body) =>
38
+ // `Prefer: respond-async` (RFC 7240): an install outlives the edge's 60 s, so once it has run a
39
+ // short while the server answers 202 with an operation to follow and keeps installing. A server
40
+ // that predates it ignores the header and answers as it always did.
41
+ data_provider_1.request.postWithOptions('/api/initiatives/spawn/apply', body, {
42
+ headers: { Prefer: 'respond-async' },
43
+ }),
44
+ /** The receipt (or failure) of a spawn that answered 202. */
45
+ spawnOperation: (operationId) => data_provider_1.request.get(`/api/initiatives/spawn/operations/${encodeURIComponent(operationId)}`),
30
46
  /** Read-only: every object a spec will install, marked requested or default. Never writes. */
31
47
  previewProactiveAgentSpec: (body) => data_provider_1.request.post('/api/initiatives/spawn/preview', body),
32
48
  /** Meta-agent path: plan and persist a reviewable recommendation. */
@@ -17,6 +17,10 @@ export interface TodoCommitmentRef {
17
17
  versionSnapshot: number;
18
18
  actionReason?: string;
19
19
  }
20
+ export interface TodoLateness {
21
+ bySeconds: number;
22
+ message: string;
23
+ }
20
24
  export interface Todo {
21
25
  id: string;
22
26
  agentId: string;
@@ -26,6 +30,11 @@ export interface Todo {
26
30
  timezone?: string;
27
31
  durationMinutes: number;
28
32
  status: TodoStatus;
33
+ /**
34
+ * Present only on a `pending` To-Do that is more than a minute past its `runAt`: it is armed
35
+ * and the scheduler has not fired it yet (OSK-22619). `status` stays `pending`.
36
+ */
37
+ late?: TodoLateness;
29
38
  source: TodoSource;
30
39
  rationale?: string;
31
40
  confidence?: TodoConfidence;
@@ -379,6 +388,12 @@ export declare function describeNonProposal(value: unknown): string;
379
388
  export declare function describePlanRequest(request: SmartSchedulePlanRequest | null | undefined, now?: Date): string | null;
380
389
  /** Explain terminal policy outcomes without changing the machine-readable status. */
381
390
  export declare function todoPolicyBlockMessage(reason?: string): string | undefined;
391
+ /**
392
+ * One line for a pending To-Do the scheduler has not fired though its time passed, or undefined.
393
+ * The STATUS column keeps saying `pending` (it is the machine-readable state); this is the part a
394
+ * person needs, which is that "pending" here no longer means "not yet".
395
+ */
396
+ export declare function todoLateMessage(todo: Pick<Todo, 'status' | 'late'>): string | undefined;
382
397
  /** Print explanations alongside the trace rows that recorded policy blocks. */
383
398
  export declare function renderTodoPolicyTraceDetails(events: ScheduleTraceEvent[], log: (line: string) => void): void;
384
399
  /**
@@ -13,6 +13,7 @@ exports.isSmartScheduleProposal = isSmartScheduleProposal;
13
13
  exports.describeNonProposal = describeNonProposal;
14
14
  exports.describePlanRequest = describePlanRequest;
15
15
  exports.todoPolicyBlockMessage = todoPolicyBlockMessage;
16
+ exports.todoLateMessage = todoLateMessage;
16
17
  exports.renderTodoPolicyTraceDetails = renderTodoPolicyTraceDetails;
17
18
  exports.renderTodoList = renderTodoList;
18
19
  exports.renderCapacityWarning = renderCapacityWarning;
@@ -243,6 +244,16 @@ function todoPolicyBlockMessage(reason) {
243
244
  return undefined;
244
245
  }
245
246
  }
247
+ /**
248
+ * One line for a pending To-Do the scheduler has not fired though its time passed, or undefined.
249
+ * The STATUS column keeps saying `pending` (it is the machine-readable state); this is the part a
250
+ * person needs, which is that "pending" here no longer means "not yet".
251
+ */
252
+ function todoLateMessage(todo) {
253
+ if (todo.status !== 'pending' || !todo.late)
254
+ return undefined;
255
+ return `${todo.late.message} (${(0, format_1.formatElapsed)(todo.late.bySeconds)} past its time)`;
256
+ }
246
257
  /** Print explanations alongside the trace rows that recorded policy blocks. */
247
258
  function renderTodoPolicyTraceDetails(events, log) {
248
259
  for (const event of events) {
@@ -282,6 +293,9 @@ function renderTodoList(todos, log, timeZone) {
282
293
  const message = todo.status === 'failed' ? todoPolicyBlockMessage(todo.result?.errorMessage) : undefined;
283
294
  if (message)
284
295
  log(` ${todo.id}: ${message}`);
296
+ const late = todoLateMessage(todo);
297
+ if (late)
298
+ log(` ${todo.id}: ${late}`);
285
299
  }
286
300
  }
287
301
  /**
@@ -82,6 +82,25 @@ export declare function validateEventFilter(input: {
82
82
  filterField?: string;
83
83
  filterValues?: string[];
84
84
  }): void;
85
+ /**
86
+ * What the trigger's own working / quiet window does to the occurrences it has coming (OSK-22529),
87
+ * the server's reading on `GET /api/triggers/:id` for a trigger that has a window. `windows` are in the
88
+ * shape a skipped fire's record keeps (`SkippedWindowRecord`). Absent means UNKNOWN, never "clear".
89
+ */
90
+ export interface WindowVerdict {
91
+ windows: Array<{
92
+ kind?: string;
93
+ start?: string;
94
+ end?: string;
95
+ timezone?: string;
96
+ timezoneDefaulted?: boolean;
97
+ }>;
98
+ state: 'clear' | 'blocks_next' | 'blocks_all' | 'no_next_run';
99
+ checked?: number;
100
+ next?: string;
101
+ reason?: string;
102
+ firstClear?: string | null;
103
+ }
85
104
  export interface SchedulerLimits {
86
105
  state: 'ok' | 'reached';
87
106
  reason?: string;
@@ -172,6 +191,8 @@ export interface TriggerDefinition {
172
191
  * limit, a read that failed), never "fine".
173
192
  */
174
193
  schedulerLimits?: SchedulerLimits;
194
+ /** The server's reading of what the trigger's window does to its next occurrences (OSK-22529). */
195
+ windowVerdict?: WindowVerdict;
175
196
  createdAt?: string;
176
197
  updatedAt?: string;
177
198
  }
@@ -247,6 +268,14 @@ export interface TriggerListResponse {
247
268
  export interface TriggerAuditResponse {
248
269
  fires: TriggerFireRecord[];
249
270
  nextCursor?: string | null;
271
+ /**
272
+ * Present on a per-trigger audit of a one-shot that is armed and more than a minute past its
273
+ * `runAt`: it has no fire record because the scheduler has not fired it yet (OSK-22619).
274
+ */
275
+ waiting?: {
276
+ bySeconds: number;
277
+ message: string;
278
+ };
250
279
  }
251
280
  export interface TriggerParseIntentResponse {
252
281
  message?: string;
@@ -423,6 +452,69 @@ export declare function assertModeRequiredFlags(mode: unknown, flags: Record<str
423
452
  * by itself (OSK-15492). Absent when the server reported nothing to say.
424
453
  */
425
454
  export declare function describeScheduledFire(result: Record<string, unknown>): string | undefined;
455
+ /**
456
+ * The `202` a `Prefer: respond-async` fire-now answers when the fire outlived the server's short wait:
457
+ * the fire is running and was not cut short. NOT a result.
458
+ */
459
+ export interface FireAccepted {
460
+ accepted: true;
461
+ outcome: 'running';
462
+ occurrenceId: string | null;
463
+ message?: string;
464
+ }
465
+ export declare function isFireAccepted(value: unknown): value is FireAccepted;
466
+ /** A fire record still being worked: `pending` is the claim before the outcome is written. */
467
+ export declare function fireRecordIsSettled(record: {
468
+ outcome?: unknown;
469
+ } | null | undefined): boolean;
470
+ export declare const FIRE_FOLLOW_POLL_MS = 3000;
471
+ /** Long enough for the slowest fire seen (215 s) with room; then the poll command is printed instead. */
472
+ export declare const FIRE_FOLLOW_MAX_WAIT_MS: number;
473
+ export type FollowedFire = {
474
+ settled: true;
475
+ result: Record<string, unknown>;
476
+ } | {
477
+ settled: false;
478
+ occurrenceId: string | null;
479
+ };
480
+ /**
481
+ * Follow a fire the server answered 202 for, by reading its record until the outcome is written.
482
+ * `result` is the record shaped like a synchronous fire answer (`outcome`, `reason`, ...), so the same
483
+ * strict check and detail lines apply. A record that does not exist yet is waited for: the claim is
484
+ * written a moment after the 202. Gives up after `maxWaitMs`, saying so rather than guessing.
485
+ */
486
+ export declare function followAcceptedFire(options: {
487
+ triggerId: string;
488
+ accepted: FireAccepted;
489
+ fetchFire?: (triggerId: string, fireId: string) => Promise<Record<string, unknown> | null>;
490
+ sleep?: (ms: number) => Promise<void>;
491
+ now?: () => number;
492
+ pollMs?: number;
493
+ maxWaitMs?: number;
494
+ onWaiting?: (elapsedMs: number) => void;
495
+ }): Promise<FollowedFire>;
496
+ /**
497
+ * A fire answer in hand: a result passes through; a `202` is followed until its record settles. Says
498
+ * (on stderr, once) that it is waiting, because a fire that took 215 s looks like a hang otherwise.
499
+ * `running` is a fire still going when the CLI stopped waiting, with the command that reads it later.
500
+ */
501
+ export declare function settleFireAnswer(options: {
502
+ triggerId: string;
503
+ agentId?: string;
504
+ bin: string;
505
+ answer: Record<string, unknown>;
506
+ follow?: typeof followAcceptedFire;
507
+ note?: (line: string) => void;
508
+ }): Promise<{
509
+ running: false;
510
+ result: Record<string, unknown>;
511
+ } | {
512
+ running: true;
513
+ answer: FireAccepted;
514
+ command: string;
515
+ }>;
516
+ /** The command that reads a fire later, for a fire still running when the CLI stopped waiting. */
517
+ export declare function fireFollowCommand(bin: string, agentId: string | undefined, triggerId: string, occurrenceId: string | null): string;
426
518
  /**
427
519
  * Was the fire admitted? `in_progress` and `awaiting_runtime` are admissions whose terminal arrives
428
520
  * later (every agent-turn fire answers `in_progress`), and a repeat of a fire that was admitted is
@@ -605,13 +697,20 @@ export declare function schedulerLimitSentence(limits: SchedulerLimits): string;
605
697
  * trigger did not plainly confirm it is live.
606
698
  */
607
699
  export declare function armedStateLabel(enabled: boolean | undefined, lastResult?: string | null,
608
- /** Pass for a `once` trigger: how often its single fire ran. A spent one-shot is not waiting to be enabled (OSK-21509). */
700
+ /**
701
+ * Pass for a `once` trigger: how often its single fire ran, whether it has been consumed (`firedAt`, which a
702
+ * skip sets too), and its id for the re-arm command. A spent one-shot is not waiting to be enabled (OSK-21509).
703
+ */
609
704
  oneShot?: {
610
705
  fires?: number;
611
706
  failures?: number;
707
+ firedAt?: unknown;
708
+ id?: string;
612
709
  } | null,
613
710
  /** The server's reading of the scheduler's run limits: a reached limit means no slot will run (OSK-22526). */
614
- schedulerLimits?: SchedulerLimits | null): string;
711
+ schedulerLimits?: SchedulerLimits | null,
712
+ /** The server's reading of what the trigger's window does to its next runs (OSK-22529). */
713
+ windowVerdict?: WindowVerdict | null): string;
615
714
  /**
616
715
  * Human phrasing for an effect trigger's write mode (OSK-4886).
617
716
  *
@@ -680,6 +779,18 @@ export declare function renderTriggerSummary(trigger: TriggerDefinition, log: (l
680
779
  baseURL?: string;
681
780
  }): void;
682
781
  export declare function renderLegacyRuns(runs: LegacyTriggerRun[], log: (line: string) => void): void;
782
+ /**
783
+ * The window lines `triggers show` prints (OSK-22529): each enabled window with its zone, then what it does
784
+ * to the next occurrences, in the server's reading. Empty for a trigger with no window, or when the server
785
+ * did not send one (an older server): unknown is not printed as clear.
786
+ */
787
+ export declare function windowVerdictLines(trigger: TriggerDefinition): string[];
788
+ /**
789
+ * `Fires: ..., last <this>`. A window skip is recorded as `outcome:reason` with the same code on both sides,
790
+ * so the line read `last outside_working_hours:outside_working_hours`; it says the sentence the audit says
791
+ * (`clockSkipAuditExplanation`), and any other result is printed as recorded.
792
+ */
793
+ export declare function lastResultLabel(trigger: TriggerDefinition): string | undefined;
683
794
  /**
684
795
  * Why a fire was skipped by a working or quiet window, in words. Both trigger-level windows (Gate 5)
685
796
  * consume the occurrence: a one-shot is spent, a recurring schedule carries on to its next slot, and
@@ -700,10 +811,16 @@ export declare function clockSkipAuditExplanation(fire: {
700
811
  * (gate 7) finding an earlier fire still holding it: this occurrence was dropped, not queued, and an
701
812
  * occurrence that was dropped is consumed, so it is not retried (OSK-22509). The raw code alone read
702
813
  * as a fire that was still in progress.
814
+ *
815
+ * The server records who held the lane and when its lease lapses (`metadata.lane`, OSK-22625). A lane
816
+ * is held by a lease its holder renews every minute, so `holdsUntil` is the latest the lane stays
817
+ * busy if the holder has died; a live holder keeps extending it. A fire from before the server wrote
818
+ * this keeps the general sentence.
703
819
  */
704
820
  export declare function coalescedAuditExplanation(fire: {
705
821
  outcome?: unknown;
706
822
  reason?: unknown;
823
+ metadata?: unknown;
707
824
  }): {
708
825
  summary: string;
709
826
  detail: string;
@@ -718,7 +835,16 @@ export declare function policyAuditExplanation(fire: {
718
835
  summary: string;
719
836
  detail: string;
720
837
  } | null;
721
- export declare function renderFireAudit(fires: TriggerFireRecord[], log: (line: string) => void): void;
838
+ /**
839
+ * The words for the few fire reasons that are only ever a code (OSK-22643). A reason a person can act on
840
+ * already has its own explanation above; these two are what the scheduler records when it finishes
841
+ * normally or runs out of runs, and read as an error when printed bare. Anything else is left as the
842
+ * server wrote it.
843
+ */
844
+ export declare function fireReasonText(reason: string): string;
845
+ export declare function renderFireAudit(fires: TriggerFireRecord[], log: (line: string) => void, waiting?: TriggerAuditResponse['waiting'], options?: {
846
+ timeZone?: string;
847
+ }): void;
722
848
  /**
723
849
  * Trigger budget for one scope. `active` counts only ENABLED rows — a disabled
724
850
  * trigger holds no scheduler resources — while `reclaimable` counts the