@skrr-ai/cli 0.1.143 → 0.1.145
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 +13 -0
- package/dist/commands/agenda/plan.d.ts +7 -0
- package/dist/commands/agenda/plan.js +17 -0
- package/dist/commands/agenda/trigger/create.js +4 -2
- package/dist/commands/agenda/trigger/list.js +7 -7
- package/dist/commands/agent/message/approve.d.ts +17 -0
- package/dist/commands/agent/message/approve.js +70 -0
- package/dist/commands/agent/message/decline.d.ts +17 -0
- package/dist/commands/agent/message/decline.js +70 -0
- package/dist/commands/agent/message/pending.d.ts +18 -0
- package/dist/commands/agent/message/pending.js +79 -0
- package/dist/commands/agents/delete.d.ts +45 -0
- package/dist/commands/agents/delete.js +139 -2
- package/dist/commands/agents/plan-day.d.ts +50 -7
- package/dist/commands/agents/plan-day.js +293 -65
- package/dist/commands/agents/proactive-audit.d.ts +22 -0
- package/dist/commands/agents/proactive-audit.js +86 -0
- package/dist/commands/agents/schedule-overview.d.ts +7 -0
- package/dist/commands/agents/schedule-overview.js +49 -5
- package/dist/commands/agents/schedule-trace.js +42 -21
- package/dist/commands/agents/spawn.d.ts +78 -1
- package/dist/commands/agents/spawn.js +262 -6
- package/dist/commands/agents/todos/list.d.ts +5 -0
- package/dist/commands/agents/todos/list.js +19 -5
- package/dist/commands/agents/triggers/create.js +1 -1
- package/dist/commands/agents/triggers/update.js +1 -1
- package/dist/commands/agents/upcoming.d.ts +1 -0
- package/dist/commands/agents/upcoming.js +18 -7
- package/dist/commands/commitments/create.js +14 -4
- package/dist/commands/commitments/preflight.js +14 -3
- package/dist/commands/commitments/update.js +1 -1
- package/dist/commands/initiatives/worker/deactivate.d.ts +23 -0
- package/dist/commands/initiatives/worker/deactivate.js +78 -0
- package/dist/commands/login.js +8 -2
- package/dist/commands/logout.d.ts +20 -0
- package/dist/commands/logout.js +110 -5
- package/dist/commands/memory/maintain.js +16 -2
- package/dist/commands/spaces/delete.js +6 -1
- package/dist/commands/spaces/workflow-templates/insert.js +4 -0
- package/dist/commands/spaces/workflows/archive.js +6 -1
- package/dist/commands/spaces/workflows/publish.js +3 -1
- package/dist/commands/spaces/workflows/run.d.ts +1 -0
- package/dist/commands/spaces/workflows/run.js +17 -1
- package/dist/commands/spaces/workflows/triggers/create.js +3 -1
- package/dist/commands/store/show.js +22 -0
- package/dist/commands/tasks/workflow-context.js +3 -1
- package/dist/commands/triggers/capabilities.js +17 -1
- package/dist/commands/triggers/create.d.ts +2 -0
- package/dist/commands/triggers/create.js +23 -7
- package/dist/commands/triggers/fire-detail.js +12 -3
- package/dist/commands/triggers/list.d.ts +1 -0
- package/dist/commands/triggers/list.js +13 -1
- package/dist/commands/triggers/preflight.js +18 -0
- package/dist/commands/triggers/prune.js +9 -5
- package/dist/commands/triggers/update.js +13 -4
- package/dist/generated/agent-guides.json +35 -35
- package/dist/lib/agent-proactive-baseline.js +7 -1
- package/dist/lib/agentic-stream.d.ts +7 -0
- package/dist/lib/agentic-stream.js +22 -0
- package/dist/lib/commitments.d.ts +16 -9
- package/dist/lib/commitments.js +78 -5
- package/dist/lib/compasses.js +1 -1
- package/dist/lib/daemon-setup.js +9 -3
- package/dist/lib/daemonBroker.d.ts +7 -0
- package/dist/lib/daemonBroker.js +5 -0
- package/dist/lib/daemonHandoff.d.ts +2 -0
- package/dist/lib/daemonHandoff.js +10 -1
- package/dist/lib/daemonIslandProfile.d.ts +19 -0
- package/dist/lib/daemonIslandProfile.js +41 -0
- package/dist/lib/dedicated-power.js +10 -3
- package/dist/lib/format.d.ts +47 -0
- package/dist/lib/format.js +136 -1
- package/dist/lib/initiatives-worker.d.ts +25 -0
- package/dist/lib/initiatives-worker.js +13 -0
- package/dist/lib/login.d.ts +7 -0
- package/dist/lib/login.js +5 -0
- package/dist/lib/planOutcome.d.ts +51 -0
- package/dist/lib/planOutcome.js +88 -0
- package/dist/lib/proactive-audit.d.ts +52 -0
- package/dist/lib/proactive-audit.js +67 -0
- package/dist/lib/proactiveApi.d.ts +71 -0
- package/dist/lib/proactiveApi.js +10 -1
- package/dist/lib/refresh.d.ts +20 -6
- package/dist/lib/refresh.js +27 -9
- package/dist/lib/roles.d.ts +1 -1
- package/dist/lib/schedule.d.ts +214 -10
- package/dist/lib/schedule.js +317 -21
- package/dist/lib/triggers.d.ts +139 -3
- package/dist/lib/triggers.js +382 -18
- package/dist/lib/workflow-node-control.js +8 -0
- package/dist/lib/workflow-run-view.js +9 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.d.ts +1 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/index.js +2 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.d.ts +22 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/cjs/refresh.js +15 -4
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.d.ts +1 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/index.js +1 -1
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.d.ts +22 -0
- package/dist/node_modules/@skrr-ai/auth-core/dist/esm/refresh.js +22 -4
- package/dist/node_modules/@skrr-ai/data-provider/index.js +5252 -5211
- package/oclif.manifest.json +526 -29
- package/package.json +1 -1
package/dist/lib/schedule.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
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;
|
|
7
|
+
exports.machineTimeZone = machineTimeZone;
|
|
8
|
+
exports.isValidTimeZone = isValidTimeZone;
|
|
9
|
+
exports.describeTimeZone = describeTimeZone;
|
|
10
|
+
exports.resolveDayTimeZone = resolveDayTimeZone;
|
|
5
11
|
exports.scheduleTracePath = scheduleTracePath;
|
|
6
12
|
exports.isSmartScheduleProposal = isSmartScheduleProposal;
|
|
7
13
|
exports.describeNonProposal = describeNonProposal;
|
|
14
|
+
exports.describePlanRequest = describePlanRequest;
|
|
8
15
|
exports.todoPolicyBlockMessage = todoPolicyBlockMessage;
|
|
9
16
|
exports.renderTodoPolicyTraceDetails = renderTodoPolicyTraceDetails;
|
|
10
17
|
exports.renderTodoList = renderTodoList;
|
|
11
18
|
exports.renderCapacityWarning = renderCapacityWarning;
|
|
19
|
+
exports.renderReplacementPreview = renderReplacementPreview;
|
|
20
|
+
exports.liveProposedTodos = liveProposedTodos;
|
|
12
21
|
exports.renderProposal = renderProposal;
|
|
22
|
+
exports.proposalNextSteps = proposalNextSteps;
|
|
23
|
+
exports.approvalEffectLines = approvalEffectLines;
|
|
24
|
+
exports.dismissEffectLines = dismissEffectLines;
|
|
13
25
|
exports.proposalToApproveTodos = proposalToApproveTodos;
|
|
26
|
+
exports.formatStamp = formatStamp;
|
|
14
27
|
/**
|
|
15
28
|
* schedule.ts — request-based client for the agent To-Do + Smart Schedule
|
|
16
29
|
* subsystem (`/api/todos/*`).
|
|
@@ -32,6 +45,31 @@ exports.proposalToApproveTodos = proposalToApproveTodos;
|
|
|
32
45
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
33
46
|
const format_1 = require("./format");
|
|
34
47
|
const triggers_1 = require("./triggers");
|
|
48
|
+
function isPlanAccepted(value) {
|
|
49
|
+
return (Boolean(value) &&
|
|
50
|
+
typeof value === 'object' &&
|
|
51
|
+
value.accepted === true);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Has the request a `202` named finished, judged from a read of the day's record?
|
|
55
|
+
*
|
|
56
|
+
* A read with no record, or with an older request than ours, predates the claim (a
|
|
57
|
+
* poll already in flight when the 202 arrived), so it settles nothing. The same id
|
|
58
|
+
* settles when it is no longer holding; a NEWER request means ours is over.
|
|
59
|
+
*/
|
|
60
|
+
function acceptedPlanVerdict(record, accepted) {
|
|
61
|
+
if (!record)
|
|
62
|
+
return 'waiting';
|
|
63
|
+
if (!accepted)
|
|
64
|
+
return record.holds ? 'waiting' : 'settled';
|
|
65
|
+
if (record.requestId === accepted.requestId)
|
|
66
|
+
return record.holds ? 'waiting' : 'settled';
|
|
67
|
+
const mine = Date.parse(accepted.startedAt ?? '');
|
|
68
|
+
const theirs = Date.parse(record.startedAt ?? '');
|
|
69
|
+
if (Number.isFinite(mine) && Number.isFinite(theirs) && theirs < mine)
|
|
70
|
+
return 'waiting';
|
|
71
|
+
return record.holds ? 'waiting' : 'settled';
|
|
72
|
+
}
|
|
35
73
|
/** Calendar day at an instant in the zone used for the schedule query. */
|
|
36
74
|
function scheduleTraceToday(now, timezone) {
|
|
37
75
|
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
@@ -43,6 +81,46 @@ function scheduleTraceToday(now, timezone) {
|
|
|
43
81
|
const part = (type) => parts.find((item) => item.type === type)?.value;
|
|
44
82
|
return `${part('year')}-${part('month')}-${part('day')}`;
|
|
45
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* This machine's IANA zone — the "viewer" zone the web client also sends
|
|
86
|
+
* (`browserTimeZone()` on propose, list and trace). `UTC` only when the runtime
|
|
87
|
+
* cannot say.
|
|
88
|
+
*/
|
|
89
|
+
function machineTimeZone() {
|
|
90
|
+
try {
|
|
91
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return 'UTC';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isValidTimeZone(timeZone) {
|
|
98
|
+
try {
|
|
99
|
+
new Intl.DateTimeFormat('en-US', { timeZone });
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** `America/Vancouver (PST)` — a zone name plus what it is called right now. */
|
|
107
|
+
function describeTimeZone(timeZone, at = new Date()) {
|
|
108
|
+
const abbreviation = (0, format_1.zoneAbbreviation)(timeZone, at);
|
|
109
|
+
return abbreviation && abbreviation !== timeZone ? `${timeZone} (${abbreviation})` : timeZone;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* One zone for one agent-day, for every Smart Schedule command that names a
|
|
113
|
+
* "today": `--timezone` when given, otherwise this machine's. `plan-day`,
|
|
114
|
+
* `schedule-trace`, `schedule-overview` and `todos list` used to default to
|
|
115
|
+
* three different zones (the server's last-seen browser zone, this machine, and
|
|
116
|
+
* UTC), so the same minute was a different day depending on the command
|
|
117
|
+
* (OSK-22397, OSK-22398). Returns `null` for an invalid explicit zone so the
|
|
118
|
+
* caller can fail with its own message.
|
|
119
|
+
*/
|
|
120
|
+
function resolveDayTimeZone(flag) {
|
|
121
|
+
const zone = flag?.trim() || machineTimeZone();
|
|
122
|
+
return isValidTimeZone(zone) ? zone : null;
|
|
123
|
+
}
|
|
46
124
|
function scheduleTracePath(params) {
|
|
47
125
|
return (0, triggers_1.withQuery)('/api/todos/smart-schedule/trace', {
|
|
48
126
|
agentId: params.agentId,
|
|
@@ -66,7 +144,13 @@ exports.scheduleApi = {
|
|
|
66
144
|
updateTodo: (todoId, patch) => data_provider_1.request.patch(`/api/todos/${encodeURIComponent(todoId)}`, patch),
|
|
67
145
|
/** Cancel a To-Do (DELETE soft-cancels pending; see todos.js). */
|
|
68
146
|
cancelTodo: (todoId) => data_provider_1.request.delete(`/api/todos/${encodeURIComponent(todoId)}`),
|
|
69
|
-
proposeSmartSchedule: (input) =>
|
|
147
|
+
proposeSmartSchedule: (input) =>
|
|
148
|
+
// `Prefer: respond-async` (RFC 7240): once the server has claimed the day it answers
|
|
149
|
+
// 202 with the request to follow and keeps planning, instead of holding the
|
|
150
|
+
// connection past the edge's 60 s. A server that predates it ignores the header.
|
|
151
|
+
data_provider_1.request.postWithOptions('/api/todos/smart-schedule/propose', input, {
|
|
152
|
+
headers: { Prefer: 'respond-async' },
|
|
153
|
+
}),
|
|
70
154
|
pendingProposal: (agentId) => data_provider_1.request.get(`/api/todos/smart-schedule/pending?agentId=${encodeURIComponent(agentId)}`),
|
|
71
155
|
approveSmartSchedule: (input) => data_provider_1.request.post('/api/todos/smart-schedule/approve', input),
|
|
72
156
|
dismissProposal: (proposalId, agentId) => data_provider_1.request.post(`/api/todos/smart-schedule/${encodeURIComponent(proposalId)}/dismiss`, {
|
|
@@ -108,6 +192,46 @@ function describeNonProposal(value) {
|
|
|
108
192
|
const keys = Object.keys(value);
|
|
109
193
|
return keys.length === 0 ? 'empty object' : `object with keys: ${keys.slice(0, 8).join(', ')}`;
|
|
110
194
|
}
|
|
195
|
+
function clockTime(iso) {
|
|
196
|
+
const parsed = iso ? new Date(iso) : null;
|
|
197
|
+
if (!parsed || Number.isNaN(parsed.getTime()))
|
|
198
|
+
return 'an unknown time';
|
|
199
|
+
return parsed.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
200
|
+
}
|
|
201
|
+
function minutesSince(iso, now) {
|
|
202
|
+
const parsed = iso ? new Date(iso) : null;
|
|
203
|
+
if (!parsed || Number.isNaN(parsed.getTime()))
|
|
204
|
+
return '';
|
|
205
|
+
const minutes = Math.max(0, Math.round((now.getTime() - parsed.getTime()) / 60_000));
|
|
206
|
+
return minutes < 1 ? ', under a minute ago' : `, ${minutes} min ago`;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* One sentence for a plan request a person should know about, or null when
|
|
210
|
+
* there is nothing to say (no record, or a plan that simply succeeded).
|
|
211
|
+
*
|
|
212
|
+
* The same four states the web panel shows, worded for a terminal. `unknown`
|
|
213
|
+
* says what is true — the request stopped reporting — and does not claim the
|
|
214
|
+
* planner stopped.
|
|
215
|
+
*/
|
|
216
|
+
function describePlanRequest(request, now = new Date()) {
|
|
217
|
+
if (!request)
|
|
218
|
+
return null;
|
|
219
|
+
const kind = request.origin === 'automatic' ? 'automatic planning run' : 'planning request';
|
|
220
|
+
switch (request.state) {
|
|
221
|
+
case 'running':
|
|
222
|
+
return (`A plan for ${request.planDate} is being generated (started ${clockTime(request.startedAt)}` +
|
|
223
|
+
`${minutesSince(request.startedAt, now)}). Approve, dismiss and regenerate are paused until it finishes.`);
|
|
224
|
+
case 'unknown':
|
|
225
|
+
return (`The last ${kind} for ${request.planDate} (started ${clockTime(request.startedAt)}) never reported a result ` +
|
|
226
|
+
'and may have been interrupted. You can plan again; if it was still running, a second draft may appear.');
|
|
227
|
+
case 'failed':
|
|
228
|
+
return (`The last ${kind} for ${request.planDate} failed` +
|
|
229
|
+
`${request.finishedAt ? ` at ${clockTime(request.finishedAt)}` : ''}: ` +
|
|
230
|
+
`${request.failure?.message ?? 'no reason was recorded'}`);
|
|
231
|
+
default:
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
111
235
|
/** Explain terminal policy outcomes without changing the machine-readable status. */
|
|
112
236
|
function todoPolicyBlockMessage(reason) {
|
|
113
237
|
switch (reason) {
|
|
@@ -123,27 +247,31 @@ function todoPolicyBlockMessage(reason) {
|
|
|
123
247
|
function renderTodoPolicyTraceDetails(events, log) {
|
|
124
248
|
for (const event of events) {
|
|
125
249
|
const message = event.type === 'todo_execution_failed'
|
|
126
|
-
? todoPolicyBlockMessage(event.reason)
|
|
250
|
+
? todoPolicyBlockMessage(event.detail?.reasonCode ?? event.reason)
|
|
127
251
|
: undefined;
|
|
128
252
|
if (message)
|
|
129
253
|
log(` ${event.id ?? event.summary ?? 'To-Do'}: ${message}`);
|
|
130
254
|
}
|
|
131
255
|
}
|
|
132
|
-
/**
|
|
133
|
-
|
|
256
|
+
/**
|
|
257
|
+
* Render a To-Do list as a table. `timeZone` names the zone the WHEN column is
|
|
258
|
+
* shown in (and is labelled on every row); omitted, rows keep the raw UTC
|
|
259
|
+
* instant the older output printed.
|
|
260
|
+
*/
|
|
261
|
+
function renderTodoList(todos, log, timeZone) {
|
|
134
262
|
if (todos.length === 0) {
|
|
135
263
|
log('No to-dos.');
|
|
136
264
|
return;
|
|
137
265
|
}
|
|
138
266
|
(0, format_1.renderTable)(todos.map((t) => ({
|
|
139
|
-
when: formatStamp(t.runAt),
|
|
267
|
+
when: formatStamp(t.runAt, timeZone, { seconds: false }),
|
|
140
268
|
status: t.status,
|
|
141
269
|
name: t.name,
|
|
142
270
|
mins: String(t.durationMinutes ?? '-'),
|
|
143
271
|
source: t.source === 'smart_schedule' ? 'smart' : 'manual',
|
|
144
272
|
id: t.id,
|
|
145
273
|
})), [
|
|
146
|
-
{ key: 'when', header: 'WHEN', maxWidth:
|
|
274
|
+
{ key: 'when', header: 'WHEN', maxWidth: 28 },
|
|
147
275
|
{ key: 'status', header: 'STATUS', maxWidth: 10 },
|
|
148
276
|
{ key: 'name', header: 'NAME', maxWidth: 36 },
|
|
149
277
|
{ key: 'mins', header: 'MINS' },
|
|
@@ -162,28 +290,71 @@ function renderTodoList(todos, log) {
|
|
|
162
290
|
* Silent when there is comfortable headroom — a budget line on every plan is
|
|
163
291
|
* noise, and noise is how a real warning gets ignored. It speaks up only when
|
|
164
292
|
* the budget is exhausted or nearly so, and always names the remediation
|
|
165
|
-
* rather than just the number.
|
|
293
|
+
* rather than just the number. An owner with no cap of their own never sees it.
|
|
294
|
+
*
|
|
295
|
+
* `agentId` makes the remedy a command that can be pasted; without it the
|
|
296
|
+
* command keeps a placeholder, which is only right when the caller cannot know.
|
|
166
297
|
*/
|
|
167
|
-
function renderCapacityWarning(capacity, log) {
|
|
168
|
-
if (!capacity || capacity.remaining > 3)
|
|
298
|
+
function renderCapacityWarning(capacity, log, agentId, phase = 'review') {
|
|
299
|
+
if (!capacity || capacity.unlimited === true || capacity.remaining > 3)
|
|
169
300
|
return;
|
|
170
301
|
if (capacity.remaining === 0) {
|
|
171
302
|
log(`Capacity: FULL — ${capacity.active} of ${capacity.limit} agent triggers in use.`);
|
|
172
|
-
log(' Approving this plan will be refused until you free a slot.');
|
|
173
303
|
}
|
|
174
304
|
else {
|
|
175
305
|
log(`Capacity: ${capacity.remaining} of ${capacity.limit} agent trigger slot(s) left.`);
|
|
176
306
|
}
|
|
307
|
+
if (phase === 'review') {
|
|
308
|
+
log(' To-dos use no trigger slot. Approval registers the schedule-check watcher' +
|
|
309
|
+
`${capacity.deltaWatcherInstalled === true ? ' (already installed)' : ' (if none exists)'}` +
|
|
310
|
+
' and, if you approve it, the next planning run; those need free slots, and approval is' +
|
|
311
|
+
' refused before anything is created when they do not fit.');
|
|
312
|
+
}
|
|
177
313
|
if (capacity.reclaimable > 0) {
|
|
178
|
-
log(` ${capacity.reclaimable} disabled trigger(s) can be
|
|
314
|
+
log(` ${capacity.reclaimable} disabled trigger(s) can be removed: preview with \`skrr triggers prune --agent ${agentId ?? '<agent-id>'} --dry-run\``);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Name the earlier blocks approval will cancel BEFORE the reviewer approves.
|
|
319
|
+
* The draft lists only what it adds, so without this the cancellation is only
|
|
320
|
+
* discoverable afterwards in the schedule trace (OSK-22419).
|
|
321
|
+
*/
|
|
322
|
+
function renderReplacementPreview(preview, zone, log) {
|
|
323
|
+
if (!preview || preview.blocks.length === 0)
|
|
324
|
+
return;
|
|
325
|
+
const from = preview.fromVersion ? ` from the approved plan v${preview.fromVersion}` : '';
|
|
326
|
+
log(`Approving this plan will CANCEL ${preview.blocks.length} earlier pending block(s)${from} ` +
|
|
327
|
+
'that this draft does not list:');
|
|
328
|
+
for (const block of preview.blocks) {
|
|
329
|
+
const tasks = (block.taskRefs ?? []).map((ref) => ref.titleSnapshot || ref.taskId).join('; ');
|
|
330
|
+
log(` - ${(0, format_1.zonedTime)(block.runAt, zone, { seconds: false })} ${block.name}${tasks ? ` [${tasks}]` : ''} (${block.todoId})`);
|
|
179
331
|
}
|
|
332
|
+
log('To keep them untouched, dismiss this plan (--dismiss) instead of approving it.');
|
|
333
|
+
log('');
|
|
334
|
+
}
|
|
335
|
+
/** The zone a proposal is about: the one it was planned in. */
|
|
336
|
+
function proposalZone(proposal) {
|
|
337
|
+
return proposal.timezone || proposal.workingHours?.timezone || 'UTC';
|
|
180
338
|
}
|
|
181
|
-
/**
|
|
339
|
+
/** The proposed to-dos a person would be approving (dropped ones are not). */
|
|
340
|
+
function liveProposedTodos(proposal) {
|
|
341
|
+
return proposal.todos.filter((t) => !t.dropped);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Render a Smart Schedule proposal: header + the proposed (non-dropped) to-dos.
|
|
345
|
+
*
|
|
346
|
+
* Every instant is shown in the PLAN's zone and says which: a draft that "stays
|
|
347
|
+
* until midnight" is only readable as `00:00 PST`, not as `08:00Z` (OSK-22397).
|
|
348
|
+
* `--json` keeps the raw UTC instants.
|
|
349
|
+
*/
|
|
182
350
|
function renderProposal(proposal, log) {
|
|
183
351
|
const wh = proposal.workingHours;
|
|
352
|
+
const zone = proposalZone(proposal);
|
|
184
353
|
log(`Proposal: ${proposal.proposalId}`);
|
|
185
354
|
log(`Status: ${proposal.status ?? 'pending'}`);
|
|
186
|
-
log(`Timezone: ${proposal.
|
|
355
|
+
log(`Timezone: ${describeTimeZone(zone, proposal.generatedAt ? new Date(proposal.generatedAt) : new Date())}`);
|
|
356
|
+
if (proposal.planDate)
|
|
357
|
+
log(`Plan day: ${proposal.planDate}`);
|
|
187
358
|
log(`Hours: ${wh?.start ?? '?'}–${wh?.end ?? '?'}`);
|
|
188
359
|
const ctx = proposal.contextSummary;
|
|
189
360
|
log(`Context: ${ctx.openTaskCount} open task(s), ${ctx.goalCount} goal(s)` +
|
|
@@ -196,32 +367,150 @@ function renderProposal(proposal, log) {
|
|
|
196
367
|
? 'Task context was unavailable; the count may be incomplete.'
|
|
197
368
|
: 'Task search scope was not recorded for this proposal.';
|
|
198
369
|
log(`Task scope: ${taskScope}`);
|
|
199
|
-
if (proposal.expiresAt)
|
|
200
|
-
|
|
201
|
-
|
|
370
|
+
if (proposal.expiresAt) {
|
|
371
|
+
const expires = (0, format_1.zonedTime)(proposal.expiresAt, zone);
|
|
372
|
+
log(`Expires: ${expires}${/ 00:00:00 /.test(expires) ? ' (midnight at the end of the plan day)' : ''}`);
|
|
373
|
+
}
|
|
374
|
+
renderCapacityWarning(proposal.capacity, log, proposal.agentId);
|
|
202
375
|
if (proposal.nextRunSuggestion) {
|
|
203
|
-
log(`Next run: ${
|
|
376
|
+
log(`Next run: ${(0, format_1.zonedTime)(proposal.nextRunSuggestion.runAt, zone)}${proposal.nextRunSuggestion.reason ? ` · ${proposal.nextRunSuggestion.reason}` : ''}`);
|
|
204
377
|
}
|
|
205
378
|
log('');
|
|
206
|
-
const live = proposal
|
|
379
|
+
const live = liveProposedTodos(proposal);
|
|
207
380
|
if (live.length === 0) {
|
|
208
381
|
log('No proposed to-dos.');
|
|
209
382
|
return;
|
|
210
383
|
}
|
|
384
|
+
renderReplacementPreview(proposal.replacementPreview, zone, log);
|
|
211
385
|
(0, format_1.renderTable)(live.map((t) => ({
|
|
212
|
-
when:
|
|
386
|
+
when: (0, format_1.zonedTime)(t.runAt, zone, { seconds: false }),
|
|
213
387
|
mins: String(t.durationMinutes ?? '-'),
|
|
214
388
|
conf: t.confidence ?? '-',
|
|
215
389
|
name: t.name,
|
|
216
390
|
why: t.rationale ?? '',
|
|
217
391
|
})), [
|
|
218
|
-
{ key: 'when', header: 'WHEN', maxWidth:
|
|
392
|
+
{ key: 'when', header: 'WHEN', maxWidth: 28 },
|
|
219
393
|
{ key: 'mins', header: 'MINS' },
|
|
220
394
|
{ key: 'conf', header: 'CONF' },
|
|
221
395
|
{ key: 'name', header: 'NAME', maxWidth: 32 },
|
|
222
396
|
{ key: 'why', header: 'RATIONALE', maxWidth: 40 },
|
|
223
397
|
], log);
|
|
224
398
|
}
|
|
399
|
+
/**
|
|
400
|
+
* The commands that can succeed for THIS draft, in the order a person would
|
|
401
|
+
* reach for them.
|
|
402
|
+
*
|
|
403
|
+
* The footer used to be one generic three-line block, so an EMPTY draft led with
|
|
404
|
+
* `--approve`, which the same command refuses ("no schedulable to-dos"): the
|
|
405
|
+
* very first suggestion failed (OSK-22396). An empty draft can only be accepted
|
|
406
|
+
* together with its suggested next run, so that is the one accept command it
|
|
407
|
+
* prints; with no next run to schedule there is nothing to accept and the only
|
|
408
|
+
* move left is to discard it.
|
|
409
|
+
*/
|
|
410
|
+
function proposalNextSteps(proposal, bin, agentId) {
|
|
411
|
+
const base = `${bin} agents plan-day ${agentId}`;
|
|
412
|
+
const empty = liveProposedTodos(proposal).length === 0;
|
|
413
|
+
const lines = [];
|
|
414
|
+
if (empty) {
|
|
415
|
+
lines.push('Nothing to schedule: the planner proposed no to-dos. This is a draft; nothing has changed yet.');
|
|
416
|
+
if (proposal.nextRunSuggestion) {
|
|
417
|
+
lines.push(` Accept, and schedule the suggested next run: ${base} --approve --approve-next-run`);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
lines.push(' There is nothing to approve: no to-dos and no next run to schedule.');
|
|
421
|
+
}
|
|
422
|
+
lines.push(` Discard: ${base} --dismiss`);
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
lines.push('This is a draft — nothing is scheduled yet.');
|
|
426
|
+
lines.push(` Approve: ${base} --approve`);
|
|
427
|
+
if (proposal.nextRunSuggestion) {
|
|
428
|
+
lines.push(` Include next run: ${base} --approve --approve-next-run`);
|
|
429
|
+
}
|
|
430
|
+
lines.push(` Discard: ${base} --dismiss`);
|
|
431
|
+
}
|
|
432
|
+
if (!empty || proposal.nextRunSuggestion) {
|
|
433
|
+
lines.push('Approving also keeps the recurring schedule watcher on (it re-checks the plan a few times a day), unless you switched it off.');
|
|
434
|
+
}
|
|
435
|
+
return lines;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* What an approval left behind besides To-Dos: the next planning run and the
|
|
439
|
+
* recurring watcher. The server always did both; only the next run was ever
|
|
440
|
+
* printed, so `upcoming` was the one place a person found the watcher
|
|
441
|
+
* (OSK-22403). Wording follows the web's approval notice.
|
|
442
|
+
*/
|
|
443
|
+
function approvalEffectLines(result, options) {
|
|
444
|
+
const lines = [];
|
|
445
|
+
if (options.approvedNextRun) {
|
|
446
|
+
const next = result.scheduledNextRun;
|
|
447
|
+
if (next?.created) {
|
|
448
|
+
lines.push(`Next planning run scheduled${next.runAt ? ` for ${(0, format_1.zonedTime)(next.runAt, options.timeZone)}` : ''}` +
|
|
449
|
+
`${next.triggerId ? ` (${next.triggerId})` : ''}.`);
|
|
450
|
+
}
|
|
451
|
+
else if (next?.skippedReason === 'existing_future_next_run') {
|
|
452
|
+
lines.push(`A next planning run is already scheduled${next.runAt ? ` for ${(0, format_1.zonedTime)(next.runAt, options.timeZone)}` : ''}` +
|
|
453
|
+
`${next.triggerId ? ` (${next.triggerId})` : ''}; none was added.`);
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
lines.push(`Next planning run was not created${next?.message || next?.skippedReason ? `: ${next.message || next.skippedReason}` : '.'}`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
const watcher = result.scheduledDeltaWatcher;
|
|
460
|
+
if (watcher) {
|
|
461
|
+
const times = watcher.times?.length
|
|
462
|
+
? ` (${watcher.times.length}x/day: ${watcher.times.join(', ')}${watcher.timezone ? ` ${watcher.timezone}` : ''})`
|
|
463
|
+
: '';
|
|
464
|
+
const manage = `Manage it with \`${options.bin} agents triggers list ${options.agentId}\`.`;
|
|
465
|
+
if (watcher.created) {
|
|
466
|
+
lines.push(`Recurring schedule watcher armed${times}. ${manage}`);
|
|
467
|
+
}
|
|
468
|
+
else if (watcher.skippedReason === 'existing_delta_watcher') {
|
|
469
|
+
lines.push(watcher.cadenceUpdated
|
|
470
|
+
? `Recurring schedule watcher is on and its check times were moved by this approval${times}. ${manage}`
|
|
471
|
+
: `Recurring schedule watcher is on and was not changed${times}. ${manage}`);
|
|
472
|
+
}
|
|
473
|
+
else if (watcher.skippedReason === 'disabled_delta_watcher') {
|
|
474
|
+
lines.push(`Recurring schedule watcher is off and was left off${times}. ${manage}`);
|
|
475
|
+
}
|
|
476
|
+
else if (watcher.skippedReason === 'delta_watcher_workspace_mismatch') {
|
|
477
|
+
// The watcher exists, in a different workspace from the one this request
|
|
478
|
+
// was made in (the CLI sends none unless told). Approval neither
|
|
479
|
+
// confirmed nor changed it, which is not the same as "not enabled".
|
|
480
|
+
lines.push(`Recurring schedule watcher was left untouched: the existing one is in a different workspace than this request, so this approval could not confirm or change it. ${manage}`);
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
lines.push(`Recurring schedule watcher was not confirmed${watcher.message ? `: ${watcher.message}` : ''}. ${manage}`);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return lines;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Dismissing is plan feedback, and feedback may move the watcher's check times.
|
|
490
|
+
* Say which happened, so "why did the watcher fire at 11:00 and not 02:00" is
|
|
491
|
+
* never answerable only by diffing triggers before and after (OSK-22407).
|
|
492
|
+
*/
|
|
493
|
+
function dismissEffectLines(result) {
|
|
494
|
+
const watcher = result.deltaWatcher;
|
|
495
|
+
if (!watcher)
|
|
496
|
+
return [];
|
|
497
|
+
if (watcher.updated && watcher.times?.length) {
|
|
498
|
+
const before = watcher.previousTimes?.length
|
|
499
|
+
? watcher.previousTimes.join(', ')
|
|
500
|
+
: 'earlier times';
|
|
501
|
+
return [
|
|
502
|
+
`Recurring schedule watcher re-timed because of this feedback: ${before} -> ${watcher.times.join(', ')}` +
|
|
503
|
+
`${watcher.timezone ? ` ${watcher.timezone}` : ''}.`,
|
|
504
|
+
];
|
|
505
|
+
}
|
|
506
|
+
// No watcher at all is not worth a line.
|
|
507
|
+
if (watcher.skippedReason === 'delta_watcher_missing')
|
|
508
|
+
return [];
|
|
509
|
+
const times = watcher.times?.length
|
|
510
|
+
? ` (${watcher.times.join(', ')}${watcher.timezone ? ` ${watcher.timezone}` : ''})`
|
|
511
|
+
: '';
|
|
512
|
+
return [`Recurring schedule watcher was not changed${times}.`];
|
|
513
|
+
}
|
|
225
514
|
/** Map a proposal's live todos into the approve-payload shape (approve all). */
|
|
226
515
|
function proposalToApproveTodos(proposal) {
|
|
227
516
|
return proposal.todos
|
|
@@ -233,13 +522,20 @@ function proposalToApproveTodos(proposal) {
|
|
|
233
522
|
runAt: t.runAt,
|
|
234
523
|
timezone: proposal.timezone,
|
|
235
524
|
durationMinutes: t.durationMinutes,
|
|
525
|
+
// The draft's references are part of what the reviewer approved. Leaving
|
|
526
|
+
// them out makes the server create an unlinked To-Do (OSK-22413).
|
|
527
|
+
...(t.taskRefs ? { taskRefs: t.taskRefs } : {}),
|
|
528
|
+
...(t.commitmentRefs ? { commitmentRefs: t.commitmentRefs } : {}),
|
|
236
529
|
rationale: t.rationale,
|
|
237
530
|
confidence: t.confidence,
|
|
238
531
|
}));
|
|
239
532
|
}
|
|
240
|
-
|
|
533
|
+
/** An instant for a person: in `timeZone` with the zone named; raw UTC when none is given. */
|
|
534
|
+
function formatStamp(value, timeZone, options = {}) {
|
|
241
535
|
if (!value)
|
|
242
536
|
return '-';
|
|
537
|
+
if (timeZone)
|
|
538
|
+
return (0, format_1.zonedTime)(value, timeZone, options);
|
|
243
539
|
const d = new Date(value);
|
|
244
540
|
return Number.isNaN(d.getTime()) ? value : d.toISOString();
|
|
245
541
|
}
|