@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.
- package/README.md +5 -0
- package/dist/commands/agenda/plan.d.ts +21 -0
- package/dist/commands/agenda/plan.js +46 -0
- package/dist/commands/agent/message/approve.js +7 -5
- package/dist/commands/agent/message/decline.js +7 -5
- package/dist/commands/agent/message/pending.js +1 -1
- package/dist/commands/agents/always-on/enable.js +1 -1
- package/dist/commands/agents/plan-day.d.ts +11 -0
- package/dist/commands/agents/plan-day.js +41 -2
- package/dist/commands/agents/schedule-overview.js +15 -10
- package/dist/commands/agents/schedule-trace.js +12 -2
- package/dist/commands/agents/spawn.d.ts +73 -1
- package/dist/commands/agents/spawn.js +274 -5
- package/dist/commands/agents/triggers/fire.js +20 -0
- package/dist/commands/agents/upcoming.d.ts +1 -0
- package/dist/commands/agents/upcoming.js +18 -7
- package/dist/commands/commitments/create.js +1 -1
- package/dist/commands/commitments/update.js +1 -1
- package/dist/commands/spaces/workflow-templates/insert.js +4 -0
- package/dist/commands/store/show.js +22 -0
- package/dist/commands/triggers/audit.js +1 -1
- package/dist/commands/triggers/fire.js +19 -0
- package/dist/generated/agent-guides.json +19 -19
- package/dist/lib/agentic-stream.d.ts +28 -0
- package/dist/lib/agentic-stream.js +89 -1
- package/dist/lib/commitments.js +13 -1
- package/dist/lib/compasses.js +1 -1
- package/dist/lib/dedicated-power.js +10 -3
- package/dist/lib/format.d.ts +20 -0
- package/dist/lib/format.js +47 -0
- package/dist/lib/planOutcome.d.ts +51 -0
- package/dist/lib/planOutcome.js +88 -0
- package/dist/lib/proactiveApi.d.ts +100 -1
- package/dist/lib/proactiveApi.js +27 -2
- package/dist/lib/schedule.d.ts +40 -1
- package/dist/lib/schedule.js +51 -2
- package/dist/lib/triggers.d.ts +134 -3
- package/dist/lib/triggers.js +260 -21
- package/dist/node_modules/@skrr-ai/auth-core/package.json +1 -1
- package/dist/node_modules/@skrr-ai/data-provider/index.js +4677 -4673
- package/oclif.manifest.json +40 -4
- package/package.json +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPlanOutcome = readPlanOutcome;
|
|
4
|
+
exports.renderPlanOutcomeTraceDetails = renderPlanOutcomeTraceDetails;
|
|
5
|
+
exports.latestPlanOutcomeLine = latestPlanOutcomeLine;
|
|
6
|
+
exports.fireAuditPlanOutcomeSummary = fireAuditPlanOutcomeSummary;
|
|
7
|
+
exports.alwaysOnUpcomingNote = alwaysOnUpcomingNote;
|
|
8
|
+
/**
|
|
9
|
+
* planOutcome.ts — read a Smart Schedule planning fire's recorded outcome.
|
|
10
|
+
*
|
|
11
|
+
* A watcher or planning-run fire that "completed" may have drafted nothing: it was watch-only,
|
|
12
|
+
* nothing changed, One Voice held it, quiet hours lowered auto to review, the planner proposed no
|
|
13
|
+
* blocks or failed. The API records which one on the fire (`metadata.builtinAction.planOutcome`) and
|
|
14
|
+
* the schedule trace carries it on the event (`detail.planOutcome`). These helpers only read and
|
|
15
|
+
* word that record; the vocabulary is owned by `@skrr-ai/data-provider` and the sentence by the API.
|
|
16
|
+
*/
|
|
17
|
+
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
18
|
+
/** The recorded outcome in `value`, or null when it is absent or not a known outcome. */
|
|
19
|
+
function readPlanOutcome(value) {
|
|
20
|
+
if (!value || typeof value !== 'object')
|
|
21
|
+
return null;
|
|
22
|
+
const candidate = value;
|
|
23
|
+
if (!(0, data_provider_1.isSmartSchedulePlanOutcomeCode)(candidate.outcome))
|
|
24
|
+
return null;
|
|
25
|
+
if (typeof candidate.reason !== 'string' || !candidate.reason)
|
|
26
|
+
return null;
|
|
27
|
+
return candidate;
|
|
28
|
+
}
|
|
29
|
+
function eventOutcome(event) {
|
|
30
|
+
const detail = event.detail;
|
|
31
|
+
if (!detail || typeof detail !== 'object')
|
|
32
|
+
return null;
|
|
33
|
+
return readPlanOutcome(detail.planOutcome);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Under the trace table: for every planning fire, WHY it did or did not leave a plan. The table's
|
|
37
|
+
* summary column says what ran; this says what it decided.
|
|
38
|
+
*/
|
|
39
|
+
function renderPlanOutcomeTraceDetails(events, log,
|
|
40
|
+
// The caller's own clock, so these lines agree with the table above them.
|
|
41
|
+
formatWhen = (at) => at.slice(0, 19).replace('T', ' ')) {
|
|
42
|
+
const rows = events
|
|
43
|
+
.map((event) => ({ event, outcome: eventOutcome(event) }))
|
|
44
|
+
.filter((row) => Boolean(row.outcome));
|
|
45
|
+
if (rows.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
log('');
|
|
48
|
+
log('Planning outcomes:');
|
|
49
|
+
for (const { event, outcome } of rows) {
|
|
50
|
+
const when = event.occurredAt ? formatWhen(String(event.occurredAt)) : '-';
|
|
51
|
+
log(` ${when} ${outcome.outcome}${outcome.reasonCode ? ` (${outcome.reasonCode})` : ''}`);
|
|
52
|
+
log(` ${outcome.reason}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The answer to "why no plan today?" from the newest planning fire in this trace, or null when no
|
|
57
|
+
* fire in it recorded an outcome. Events arrive newest first.
|
|
58
|
+
*/
|
|
59
|
+
function latestPlanOutcomeLine(events) {
|
|
60
|
+
for (const event of events) {
|
|
61
|
+
const outcome = eventOutcome(event);
|
|
62
|
+
if (outcome)
|
|
63
|
+
return outcome.reason;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The REASON column of a fire-audit row: the planning outcome's sentence when the fire recorded
|
|
69
|
+
* one, else undefined so the caller falls back to the fire's own reason.
|
|
70
|
+
*/
|
|
71
|
+
function fireAuditPlanOutcomeSummary(fire) {
|
|
72
|
+
return readPlanOutcome(fire.metadata?.builtinAction?.planOutcome)?.reason;
|
|
73
|
+
}
|
|
74
|
+
const ALWAYS_ON_REASONS = new Set(['disabled', 'always_on_disabled']);
|
|
75
|
+
/**
|
|
76
|
+
* The line under "withheld" in the upcoming view when the cause is Always-On. A trigger that is
|
|
77
|
+
* listed under Upcoming has passed the same fence the withheld ones failed, so it is not gated by
|
|
78
|
+
* Always-On: it still fires. Without this the two lists sit side by side and read as one rule
|
|
79
|
+
* (OSK-22406). Null when nothing is withheld for Always-On or nothing is listed.
|
|
80
|
+
*/
|
|
81
|
+
function alwaysOnUpcomingNote(withheld, listedCount) {
|
|
82
|
+
if (listedCount === 0)
|
|
83
|
+
return null;
|
|
84
|
+
if (!withheld.some((trigger) => ALWAYS_ON_REASONS.has(String(trigger.reason ?? ''))))
|
|
85
|
+
return null;
|
|
86
|
+
return ('Always-On is off for this agent. The withheld triggers wait for it; the triggers listed under ' +
|
|
87
|
+
'Upcoming are not gated by Always-On, so they still fire.');
|
|
88
|
+
}
|
|
@@ -94,6 +94,63 @@ 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
|
+
}
|
|
130
|
+
/** One object a spec will install (`POST /api/initiatives/spawn/preview`). */
|
|
131
|
+
export interface InstallPlanItem {
|
|
132
|
+
kind: string;
|
|
133
|
+
name: string;
|
|
134
|
+
label: string;
|
|
135
|
+
/** `requested` = the spec names it; `default` = the platform adds it, and `why` says why. */
|
|
136
|
+
origin: 'requested' | 'default';
|
|
137
|
+
why: string;
|
|
138
|
+
status: 'install' | 'declined' | 'will_be_blocked';
|
|
139
|
+
reason?: string;
|
|
140
|
+
detail?: string;
|
|
141
|
+
}
|
|
142
|
+
export interface InstallPreviewResponse {
|
|
143
|
+
items: InstallPlanItem[];
|
|
144
|
+
options: {
|
|
145
|
+
minimal: boolean;
|
|
146
|
+
without: string[];
|
|
147
|
+
};
|
|
148
|
+
runtime: {
|
|
149
|
+
commitments: 'can_run' | 'cannot_run' | 'unknown';
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** The defaults `--without` can decline; the server refuses any other name. */
|
|
153
|
+
export declare const DECLINABLE_DEFAULTS: readonly ["memory_watcher", "task_goal_watcher", "initiative_follow_through", "relationship_loops"];
|
|
97
154
|
export interface ApplyWarning {
|
|
98
155
|
step: string;
|
|
99
156
|
code: string;
|
|
@@ -172,6 +229,22 @@ export interface ApplyProactiveAgentResponse {
|
|
|
172
229
|
/** The first attempt made this one; a retry reported it instead of creating it again. */
|
|
173
230
|
existing?: boolean;
|
|
174
231
|
}>;
|
|
232
|
+
/** Everything that exists on the Agent after the apply, read back; a list is null when unreadable. */
|
|
233
|
+
inventory?: {
|
|
234
|
+
triggers: Array<{
|
|
235
|
+
id: string;
|
|
236
|
+
label: string | null;
|
|
237
|
+
source: string | null;
|
|
238
|
+
enabled: boolean;
|
|
239
|
+
origin: 'requested' | 'default';
|
|
240
|
+
}> | null;
|
|
241
|
+
commitments: Array<{
|
|
242
|
+
id: string;
|
|
243
|
+
title: string | null;
|
|
244
|
+
status: string | null;
|
|
245
|
+
systemRole: string | null;
|
|
246
|
+
}> | null;
|
|
247
|
+
};
|
|
175
248
|
initialize?: {
|
|
176
249
|
goals: Array<{
|
|
177
250
|
id?: string;
|
|
@@ -195,6 +268,15 @@ export interface ApplyProactiveAgentResponse {
|
|
|
195
268
|
};
|
|
196
269
|
};
|
|
197
270
|
warnings: ApplyWarning[];
|
|
271
|
+
/**
|
|
272
|
+
* Present only when `--minimal` / `--without` were requested: the defaults the server declined.
|
|
273
|
+
* Its absence after such a request means the server ignored the options.
|
|
274
|
+
*/
|
|
275
|
+
installOptions?: {
|
|
276
|
+
minimal: boolean;
|
|
277
|
+
without: string[];
|
|
278
|
+
declined: string[];
|
|
279
|
+
};
|
|
198
280
|
}
|
|
199
281
|
export type ProactiveAgentRecommendationStatus = 'proposed' | 'approved' | 'applied' | 'dismissed' | 'expired' | 'failed' | 'superseded';
|
|
200
282
|
export type ProactiveAgentRecommendationSource = 'meta_agent' | 'onboarding' | 'manual' | 'system';
|
|
@@ -282,7 +364,24 @@ export declare const proactiveApi: {
|
|
|
282
364
|
fromReviewedSpec?: boolean;
|
|
283
365
|
recommendationId?: string;
|
|
284
366
|
approvedSpecHash?: string;
|
|
285
|
-
|
|
367
|
+
/** Decline every default the platform would add beyond what the spec asks for. */
|
|
368
|
+
minimal?: boolean;
|
|
369
|
+
/** Decline one default by name (see `DECLINABLE_DEFAULTS`). */
|
|
370
|
+
without?: string[];
|
|
371
|
+
}) => Promise<ApplyProactiveAgentResponse | SpawnAccepted>;
|
|
372
|
+
/** The receipt (or failure) of a spawn that answered 202. */
|
|
373
|
+
spawnOperation: (operationId: string) => Promise<{
|
|
374
|
+
operation: SpawnOperation;
|
|
375
|
+
}>;
|
|
376
|
+
/** Read-only: every object a spec will install, marked requested or default. Never writes. */
|
|
377
|
+
previewProactiveAgentSpec: (body: {
|
|
378
|
+
spec: ProactiveAgentSpec;
|
|
379
|
+
agentId?: string;
|
|
380
|
+
timezone?: string;
|
|
381
|
+
fromReviewedSpec?: boolean;
|
|
382
|
+
minimal?: boolean;
|
|
383
|
+
without?: string[];
|
|
384
|
+
}) => Promise<InstallPreviewResponse>;
|
|
286
385
|
/** Meta-agent path: plan and persist a reviewable recommendation. */
|
|
287
386
|
planProactiveAgentRecommendation: (body: {
|
|
288
387
|
name?: string;
|
package/dist/lib/proactiveApi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.proactiveApi = void 0;
|
|
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,11 +16,35 @@ exports.proactiveApi = 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
|
+
}
|
|
26
|
+
/** The defaults `--without` can decline; the server refuses any other name. */
|
|
27
|
+
exports.DECLINABLE_DEFAULTS = [
|
|
28
|
+
'memory_watcher',
|
|
29
|
+
'task_goal_watcher',
|
|
30
|
+
'initiative_follow_through',
|
|
31
|
+
'relationship_loops',
|
|
32
|
+
];
|
|
18
33
|
exports.proactiveApi = {
|
|
19
34
|
/** Plan-only: turn a sentence into a spec draft. Never writes. */
|
|
20
35
|
planProactiveAgent: (body) => data_provider_1.request.post('/api/initiatives/spawn/plan', body),
|
|
21
36
|
/** Apply a (clamped, server-re-validated) spec: create + install. */
|
|
22
|
-
applyProactiveAgentSpec: (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)}`),
|
|
46
|
+
/** Read-only: every object a spec will install, marked requested or default. Never writes. */
|
|
47
|
+
previewProactiveAgentSpec: (body) => data_provider_1.request.post('/api/initiatives/spawn/preview', body),
|
|
23
48
|
/** Meta-agent path: plan and persist a reviewable recommendation. */
|
|
24
49
|
planProactiveAgentRecommendation: (body) => data_provider_1.request.post('/api/initiatives/recommendations/plan', body),
|
|
25
50
|
listProactiveAgentRecommendations: (params) => {
|
package/dist/lib/schedule.d.ts
CHANGED
|
@@ -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;
|
|
@@ -152,6 +161,26 @@ export interface SmartSchedulePlanRequest {
|
|
|
152
161
|
message: string;
|
|
153
162
|
};
|
|
154
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* The `202` answer to a propose that sent `Prefer: respond-async`: the plan day was
|
|
166
|
+
* claimed and the planner keeps running on the server. NOT a plan. A plan takes
|
|
167
|
+
* 35-66 s and the edge gives up at 60 s, so a command that asks this way is handed
|
|
168
|
+
* the request to follow instead of a 502/504 for a plan that is still running.
|
|
169
|
+
*/
|
|
170
|
+
export interface SmartSchedulePlanAccepted {
|
|
171
|
+
accepted: true;
|
|
172
|
+
planRequest: SmartSchedulePlanRequest | null;
|
|
173
|
+
message?: string;
|
|
174
|
+
}
|
|
175
|
+
export declare function isPlanAccepted(value: unknown): value is SmartSchedulePlanAccepted;
|
|
176
|
+
/**
|
|
177
|
+
* Has the request a `202` named finished, judged from a read of the day's record?
|
|
178
|
+
*
|
|
179
|
+
* A read with no record, or with an older request than ours, predates the claim (a
|
|
180
|
+
* poll already in flight when the 202 arrived), so it settles nothing. The same id
|
|
181
|
+
* settles when it is no longer holding; a NEWER request means ours is over.
|
|
182
|
+
*/
|
|
183
|
+
export declare function acceptedPlanVerdict(record: SmartSchedulePlanRequest | null | undefined, accepted: SmartSchedulePlanRequest | null | undefined): 'waiting' | 'settled';
|
|
155
184
|
export interface ApproveTodoInput {
|
|
156
185
|
tempId?: string;
|
|
157
186
|
name: string;
|
|
@@ -235,7 +264,11 @@ export interface ScheduleTraceEvent {
|
|
|
235
264
|
status?: string;
|
|
236
265
|
summary?: string;
|
|
237
266
|
source?: string;
|
|
267
|
+
/** A sentence for a person. The machine code behind it is `detail.reasonCode` (OSK-22558). */
|
|
238
268
|
reason?: string;
|
|
269
|
+
detail?: {
|
|
270
|
+
reasonCode?: string;
|
|
271
|
+
};
|
|
239
272
|
}
|
|
240
273
|
export interface ScheduleTrace {
|
|
241
274
|
object?: string;
|
|
@@ -309,7 +342,7 @@ export declare const scheduleApi: {
|
|
|
309
342
|
workingHoursOverride?: WorkingHoursWindow;
|
|
310
343
|
timezone?: string;
|
|
311
344
|
regenerateHint?: string;
|
|
312
|
-
}) => Promise<SmartScheduleProposal>;
|
|
345
|
+
}) => Promise<SmartScheduleProposal | SmartSchedulePlanAccepted>;
|
|
313
346
|
pendingProposal: (agentId: string) => Promise<{
|
|
314
347
|
proposal: SmartScheduleProposal | null;
|
|
315
348
|
/** Absent from older servers; null when no request is on record. */
|
|
@@ -355,6 +388,12 @@ export declare function describeNonProposal(value: unknown): string;
|
|
|
355
388
|
export declare function describePlanRequest(request: SmartSchedulePlanRequest | null | undefined, now?: Date): string | null;
|
|
356
389
|
/** Explain terminal policy outcomes without changing the machine-readable status. */
|
|
357
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;
|
|
358
397
|
/** Print explanations alongside the trace rows that recorded policy blocks. */
|
|
359
398
|
export declare function renderTodoPolicyTraceDetails(events: ScheduleTraceEvent[], log: (line: string) => void): void;
|
|
360
399
|
/**
|
package/dist/lib/schedule.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scheduleApi = void 0;
|
|
4
|
+
exports.isPlanAccepted = isPlanAccepted;
|
|
5
|
+
exports.acceptedPlanVerdict = acceptedPlanVerdict;
|
|
4
6
|
exports.scheduleTraceToday = scheduleTraceToday;
|
|
5
7
|
exports.machineTimeZone = machineTimeZone;
|
|
6
8
|
exports.isValidTimeZone = isValidTimeZone;
|
|
@@ -11,6 +13,7 @@ exports.isSmartScheduleProposal = isSmartScheduleProposal;
|
|
|
11
13
|
exports.describeNonProposal = describeNonProposal;
|
|
12
14
|
exports.describePlanRequest = describePlanRequest;
|
|
13
15
|
exports.todoPolicyBlockMessage = todoPolicyBlockMessage;
|
|
16
|
+
exports.todoLateMessage = todoLateMessage;
|
|
14
17
|
exports.renderTodoPolicyTraceDetails = renderTodoPolicyTraceDetails;
|
|
15
18
|
exports.renderTodoList = renderTodoList;
|
|
16
19
|
exports.renderCapacityWarning = renderCapacityWarning;
|
|
@@ -43,6 +46,31 @@ exports.formatStamp = formatStamp;
|
|
|
43
46
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
44
47
|
const format_1 = require("./format");
|
|
45
48
|
const triggers_1 = require("./triggers");
|
|
49
|
+
function isPlanAccepted(value) {
|
|
50
|
+
return (Boolean(value) &&
|
|
51
|
+
typeof value === 'object' &&
|
|
52
|
+
value.accepted === true);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Has the request a `202` named finished, judged from a read of the day's record?
|
|
56
|
+
*
|
|
57
|
+
* A read with no record, or with an older request than ours, predates the claim (a
|
|
58
|
+
* poll already in flight when the 202 arrived), so it settles nothing. The same id
|
|
59
|
+
* settles when it is no longer holding; a NEWER request means ours is over.
|
|
60
|
+
*/
|
|
61
|
+
function acceptedPlanVerdict(record, accepted) {
|
|
62
|
+
if (!record)
|
|
63
|
+
return 'waiting';
|
|
64
|
+
if (!accepted)
|
|
65
|
+
return record.holds ? 'waiting' : 'settled';
|
|
66
|
+
if (record.requestId === accepted.requestId)
|
|
67
|
+
return record.holds ? 'waiting' : 'settled';
|
|
68
|
+
const mine = Date.parse(accepted.startedAt ?? '');
|
|
69
|
+
const theirs = Date.parse(record.startedAt ?? '');
|
|
70
|
+
if (Number.isFinite(mine) && Number.isFinite(theirs) && theirs < mine)
|
|
71
|
+
return 'waiting';
|
|
72
|
+
return record.holds ? 'waiting' : 'settled';
|
|
73
|
+
}
|
|
46
74
|
/** Calendar day at an instant in the zone used for the schedule query. */
|
|
47
75
|
function scheduleTraceToday(now, timezone) {
|
|
48
76
|
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
@@ -117,7 +145,13 @@ exports.scheduleApi = {
|
|
|
117
145
|
updateTodo: (todoId, patch) => data_provider_1.request.patch(`/api/todos/${encodeURIComponent(todoId)}`, patch),
|
|
118
146
|
/** Cancel a To-Do (DELETE soft-cancels pending; see todos.js). */
|
|
119
147
|
cancelTodo: (todoId) => data_provider_1.request.delete(`/api/todos/${encodeURIComponent(todoId)}`),
|
|
120
|
-
proposeSmartSchedule: (input) =>
|
|
148
|
+
proposeSmartSchedule: (input) =>
|
|
149
|
+
// `Prefer: respond-async` (RFC 7240): once the server has claimed the day it answers
|
|
150
|
+
// 202 with the request to follow and keeps planning, instead of holding the
|
|
151
|
+
// connection past the edge's 60 s. A server that predates it ignores the header.
|
|
152
|
+
data_provider_1.request.postWithOptions('/api/todos/smart-schedule/propose', input, {
|
|
153
|
+
headers: { Prefer: 'respond-async' },
|
|
154
|
+
}),
|
|
121
155
|
pendingProposal: (agentId) => data_provider_1.request.get(`/api/todos/smart-schedule/pending?agentId=${encodeURIComponent(agentId)}`),
|
|
122
156
|
approveSmartSchedule: (input) => data_provider_1.request.post('/api/todos/smart-schedule/approve', input),
|
|
123
157
|
dismissProposal: (proposalId, agentId) => data_provider_1.request.post(`/api/todos/smart-schedule/${encodeURIComponent(proposalId)}/dismiss`, {
|
|
@@ -210,10 +244,22 @@ function todoPolicyBlockMessage(reason) {
|
|
|
210
244
|
return undefined;
|
|
211
245
|
}
|
|
212
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
|
+
}
|
|
213
257
|
/** Print explanations alongside the trace rows that recorded policy blocks. */
|
|
214
258
|
function renderTodoPolicyTraceDetails(events, log) {
|
|
215
259
|
for (const event of events) {
|
|
216
|
-
const message = event.type === 'todo_execution_failed'
|
|
260
|
+
const message = event.type === 'todo_execution_failed'
|
|
261
|
+
? todoPolicyBlockMessage(event.detail?.reasonCode ?? event.reason)
|
|
262
|
+
: undefined;
|
|
217
263
|
if (message)
|
|
218
264
|
log(` ${event.id ?? event.summary ?? 'To-Do'}: ${message}`);
|
|
219
265
|
}
|
|
@@ -247,6 +293,9 @@ function renderTodoList(todos, log, timeZone) {
|
|
|
247
293
|
const message = todo.status === 'failed' ? todoPolicyBlockMessage(todo.result?.errorMessage) : undefined;
|
|
248
294
|
if (message)
|
|
249
295
|
log(` ${todo.id}: ${message}`);
|
|
296
|
+
const late = todoLateMessage(todo);
|
|
297
|
+
if (late)
|
|
298
|
+
log(` ${todo.id}: ${late}`);
|
|
250
299
|
}
|
|
251
300
|
}
|
|
252
301
|
/**
|
package/dist/lib/triggers.d.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -206,6 +227,11 @@ export interface TriggerFireRecord {
|
|
|
206
227
|
permissionRefusalsUnread?: boolean;
|
|
207
228
|
/** What became of the inbox card a policy-skipped fire was supposed to leave (OSK-21911). */
|
|
208
229
|
policyCard?: TriggerPolicyCard;
|
|
230
|
+
/** A built-in action's result; Smart Schedule's carries why it did or did not leave a plan. */
|
|
231
|
+
builtinAction?: {
|
|
232
|
+
builtinType?: string;
|
|
233
|
+
planOutcome?: unknown;
|
|
234
|
+
};
|
|
209
235
|
/** The working / quiet window that skipped this fire, as the server judged it (OSK-22528). */
|
|
210
236
|
window?: SkippedWindowRecord;
|
|
211
237
|
};
|
|
@@ -242,6 +268,14 @@ export interface TriggerListResponse {
|
|
|
242
268
|
export interface TriggerAuditResponse {
|
|
243
269
|
fires: TriggerFireRecord[];
|
|
244
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
|
+
};
|
|
245
279
|
}
|
|
246
280
|
export interface TriggerParseIntentResponse {
|
|
247
281
|
message?: string;
|
|
@@ -418,6 +452,69 @@ export declare function assertModeRequiredFlags(mode: unknown, flags: Record<str
|
|
|
418
452
|
* by itself (OSK-15492). Absent when the server reported nothing to say.
|
|
419
453
|
*/
|
|
420
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;
|
|
421
518
|
/**
|
|
422
519
|
* Was the fire admitted? `in_progress` and `awaiting_runtime` are admissions whose terminal arrives
|
|
423
520
|
* later (every agent-turn fire answers `in_progress`), and a repeat of a fire that was admitted is
|
|
@@ -600,13 +697,20 @@ export declare function schedulerLimitSentence(limits: SchedulerLimits): string;
|
|
|
600
697
|
* trigger did not plainly confirm it is live.
|
|
601
698
|
*/
|
|
602
699
|
export declare function armedStateLabel(enabled: boolean | undefined, lastResult?: string | null,
|
|
603
|
-
/**
|
|
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
|
+
*/
|
|
604
704
|
oneShot?: {
|
|
605
705
|
fires?: number;
|
|
606
706
|
failures?: number;
|
|
707
|
+
firedAt?: unknown;
|
|
708
|
+
id?: string;
|
|
607
709
|
} | null,
|
|
608
710
|
/** The server's reading of the scheduler's run limits: a reached limit means no slot will run (OSK-22526). */
|
|
609
|
-
schedulerLimits?: SchedulerLimits | null
|
|
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;
|
|
610
714
|
/**
|
|
611
715
|
* Human phrasing for an effect trigger's write mode (OSK-4886).
|
|
612
716
|
*
|
|
@@ -675,6 +779,18 @@ export declare function renderTriggerSummary(trigger: TriggerDefinition, log: (l
|
|
|
675
779
|
baseURL?: string;
|
|
676
780
|
}): void;
|
|
677
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;
|
|
678
794
|
/**
|
|
679
795
|
* Why a fire was skipped by a working or quiet window, in words. Both trigger-level windows (Gate 5)
|
|
680
796
|
* consume the occurrence: a one-shot is spent, a recurring schedule carries on to its next slot, and
|
|
@@ -695,10 +811,16 @@ export declare function clockSkipAuditExplanation(fire: {
|
|
|
695
811
|
* (gate 7) finding an earlier fire still holding it: this occurrence was dropped, not queued, and an
|
|
696
812
|
* occurrence that was dropped is consumed, so it is not retried (OSK-22509). The raw code alone read
|
|
697
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.
|
|
698
819
|
*/
|
|
699
820
|
export declare function coalescedAuditExplanation(fire: {
|
|
700
821
|
outcome?: unknown;
|
|
701
822
|
reason?: unknown;
|
|
823
|
+
metadata?: unknown;
|
|
702
824
|
}): {
|
|
703
825
|
summary: string;
|
|
704
826
|
detail: string;
|
|
@@ -713,7 +835,16 @@ export declare function policyAuditExplanation(fire: {
|
|
|
713
835
|
summary: string;
|
|
714
836
|
detail: string;
|
|
715
837
|
} | null;
|
|
716
|
-
|
|
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;
|
|
717
848
|
/**
|
|
718
849
|
* Trigger budget for one scope. `active` counts only ENABLED rows — a disabled
|
|
719
850
|
* trigger holds no scheduler resources — while `reclaimable` counts the
|