@skrr-ai/cli 0.1.143 → 0.1.144
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 +8 -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 +72 -0
- package/dist/commands/agent/message/decline.d.ts +17 -0
- package/dist/commands/agent/message/decline.js +72 -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 +39 -7
- package/dist/commands/agents/plan-day.js +254 -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 +43 -5
- package/dist/commands/agents/schedule-trace.js +30 -19
- package/dist/commands/agents/spawn.d.ts +42 -0
- package/dist/commands/agents/spawn.js +91 -4
- 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/commitments/create.js +13 -3
- package/dist/commands/commitments/preflight.js +14 -3
- 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/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/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/commitments.d.ts +16 -9
- package/dist/lib/commitments.js +65 -4
- 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/format.d.ts +32 -0
- package/dist/lib/format.js +105 -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/proactive-audit.d.ts +52 -0
- package/dist/lib/proactive-audit.js +67 -0
- package/dist/lib/proactiveApi.d.ts +9 -0
- 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 +189 -9
- package/dist/lib/schedule.js +283 -22
- package/dist/lib/triggers.d.ts +134 -3
- package/dist/lib/triggers.js +370 -17
- 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 +4779 -4741
- package/oclif.manifest.json +494 -26
- package/package.json +1 -1
|
@@ -12,7 +12,13 @@ import { BaseCommand } from '../../base-command';
|
|
|
12
12
|
*
|
|
13
13
|
* A proposal is a DRAFT — nothing is scheduled until `--approve`. Re-running the
|
|
14
14
|
* bare command recovers the pending proposal rather than regenerating it (mirrors
|
|
15
|
-
* the board, which recovers a pending plan into the review modal).
|
|
15
|
+
* the board, which recovers a pending plan into the review modal). With NO
|
|
16
|
+
* pending plan the bare command starts a real planner run, and says so before it
|
|
17
|
+
* does; `--regenerate` is the explicit way to replace a pending plan.
|
|
18
|
+
*
|
|
19
|
+
* Times are shown in the plan's own timezone, named. A plan is proposed in
|
|
20
|
+
* `--timezone`, or this machine's zone: the same default `schedule-trace` and
|
|
21
|
+
* `todos list` use, so one agent-day is one zone across the commands.
|
|
16
22
|
*/
|
|
17
23
|
export default class AgentsPlanDay extends BaseCommand {
|
|
18
24
|
static description: string;
|
|
@@ -41,18 +47,44 @@ export default class AgentsPlanDay extends BaseCommand {
|
|
|
41
47
|
* --json` did when the transport handed back an unparseable body (OSK-2803).
|
|
42
48
|
*/
|
|
43
49
|
private requireProposal;
|
|
44
|
-
/**
|
|
45
|
-
|
|
50
|
+
/**
|
|
51
|
+
* `{proposal, planRequest}` envelope reader that survives a body-less response.
|
|
52
|
+
*
|
|
53
|
+
* `planRequest` is the server's own record of whether a plan is being
|
|
54
|
+
* generated, failed, or went quiet. It is what lets this command answer from
|
|
55
|
+
* the server's side instead of guessing from a timeout.
|
|
56
|
+
*/
|
|
57
|
+
private fetchPendingState;
|
|
58
|
+
/** Refuse an action on the draft while its replacement is being generated. */
|
|
59
|
+
private refuseWhileGenerating;
|
|
46
60
|
private workingHoursOverride;
|
|
47
61
|
/**
|
|
48
62
|
* Gateway failures can interrupt a response after the planner started.
|
|
49
|
-
* Check the
|
|
63
|
+
* Check the server's record before suggesting another billable request; a
|
|
50
64
|
* 502 can also mean the planner never started, so do not assert that it did.
|
|
51
65
|
*/
|
|
52
66
|
private static readonly TIMEOUT_STATUSES;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
private static readonly
|
|
67
|
+
private static readonly POLL_INTERVAL_MS;
|
|
68
|
+
/** Without a plan-request record (older server) the wait is the old, bounded guess. */
|
|
69
|
+
private static readonly LEGACY_POLL_ATTEMPTS;
|
|
70
|
+
/** The longest a planner may run is ~12 min; wait that plus a margin, never forever. */
|
|
71
|
+
private static readonly MAX_WAIT_MS;
|
|
72
|
+
/** A finished request's draft can lag a replica read; allow a few polls for it. */
|
|
73
|
+
private static readonly DRAFT_LAG_POLLS;
|
|
74
|
+
/**
|
|
75
|
+
* Wait for a plan request to settle, reading the server's record each time.
|
|
76
|
+
*
|
|
77
|
+
* `target` says which request matters:
|
|
78
|
+
* - `existing`: one we found running, and want the result of.
|
|
79
|
+
* - `ours`: the request our POST started, whose response was lost. We only
|
|
80
|
+
* know the id of whatever was on record BEFORE posting, so a record that is
|
|
81
|
+
* missing or unchanged means the server never saw our request start.
|
|
82
|
+
*
|
|
83
|
+
* Returns instead of throwing for the three "no draft" endings so the caller
|
|
84
|
+
* decides what each means; a request that FAILED throws with the reason,
|
|
85
|
+
* because that is the one answer the person has been missing.
|
|
86
|
+
*/
|
|
87
|
+
private awaitPlanRequest;
|
|
56
88
|
/**
|
|
57
89
|
* After a timed-out propose, collect the draft the server persisted anyway.
|
|
58
90
|
* Returns null when the failure was not a timeout, or when nothing landed —
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const core_1 = require("@oclif/core");
|
|
4
4
|
const base_command_1 = require("../../base-command");
|
|
5
|
+
const format_1 = require("../../lib/format");
|
|
5
6
|
const schedule_1 = require("../../lib/schedule");
|
|
6
7
|
/**
|
|
7
8
|
* `skrr agents plan-day <agent-id>` — Smart Schedule ("Plan my day").
|
|
@@ -16,7 +17,13 @@ const schedule_1 = require("../../lib/schedule");
|
|
|
16
17
|
*
|
|
17
18
|
* A proposal is a DRAFT — nothing is scheduled until `--approve`. Re-running the
|
|
18
19
|
* bare command recovers the pending proposal rather than regenerating it (mirrors
|
|
19
|
-
* the board, which recovers a pending plan into the review modal).
|
|
20
|
+
* the board, which recovers a pending plan into the review modal). With NO
|
|
21
|
+
* pending plan the bare command starts a real planner run, and says so before it
|
|
22
|
+
* does; `--regenerate` is the explicit way to replace a pending plan.
|
|
23
|
+
*
|
|
24
|
+
* Times are shown in the plan's own timezone, named. A plan is proposed in
|
|
25
|
+
* `--timezone`, or this machine's zone: the same default `schedule-trace` and
|
|
26
|
+
* `todos list` use, so one agent-day is one zone across the commands.
|
|
20
27
|
*/
|
|
21
28
|
class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
22
29
|
static description = "Smart Schedule an agent's day: propose a plan, then approve or dismiss it";
|
|
@@ -44,7 +51,9 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
44
51
|
}),
|
|
45
52
|
'hours-start': core_1.Flags.string({ description: 'Working-hours start (HH:MM) for the proposal' }),
|
|
46
53
|
'hours-end': core_1.Flags.string({ description: 'Working-hours end (HH:MM) for the proposal' }),
|
|
47
|
-
timezone: core_1.Flags.string({
|
|
54
|
+
timezone: core_1.Flags.string({
|
|
55
|
+
description: "IANA timezone for the plan day and its working hours (defaults to this machine's timezone, as in schedule-trace and todos list)",
|
|
56
|
+
}),
|
|
48
57
|
'approve-next-run': core_1.Flags.boolean({
|
|
49
58
|
description: 'With --approve, schedule the suggested next planning run',
|
|
50
59
|
dependsOn: ['approve'],
|
|
@@ -57,13 +66,8 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
57
66
|
this.requireAuth();
|
|
58
67
|
const { args, flags } = await this.parse(AgentsPlanDay);
|
|
59
68
|
const agentId = args.id;
|
|
60
|
-
if (!flags.dismiss && !flags.approve && flags.timezone) {
|
|
61
|
-
|
|
62
|
-
new Intl.DateTimeFormat('en', { timeZone: flags.timezone });
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
this.error(`Invalid IANA timezone: ${flags.timezone}`, { exit: 1 });
|
|
66
|
-
}
|
|
69
|
+
if (!flags.dismiss && !flags.approve && flags.timezone && !(0, schedule_1.isValidTimeZone)(flags.timezone)) {
|
|
70
|
+
this.error(`Invalid IANA timezone: ${flags.timezone}`, { exit: 1 });
|
|
67
71
|
}
|
|
68
72
|
try {
|
|
69
73
|
if (flags.dismiss) {
|
|
@@ -101,10 +105,20 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
101
105
|
details: { agentId, operation },
|
|
102
106
|
});
|
|
103
107
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
108
|
+
/**
|
|
109
|
+
* `{proposal, planRequest}` envelope reader that survives a body-less response.
|
|
110
|
+
*
|
|
111
|
+
* `planRequest` is the server's own record of whether a plan is being
|
|
112
|
+
* generated, failed, or went quiet. It is what lets this command answer from
|
|
113
|
+
* the server's side instead of guessing from a timeout.
|
|
114
|
+
*/
|
|
115
|
+
async fetchPendingState(agentId, { lenient = false } = {}) {
|
|
106
116
|
const pending = (await schedule_1.scheduleApi.pendingProposal(agentId));
|
|
107
117
|
if (pending == null || typeof pending !== 'object') {
|
|
118
|
+
// A caller that only wants context (and will carry on without it) must not
|
|
119
|
+
// have a broken body turned into a printed error envelope.
|
|
120
|
+
if (lenient)
|
|
121
|
+
return { proposal: null, planRequest: null, recorded: false };
|
|
108
122
|
this.failWithCliError({
|
|
109
123
|
message: `Could not read the pending Smart Schedule plan for agent ${agentId} ` +
|
|
110
124
|
`(${(0, schedule_1.describeNonProposal)(pending)}).`,
|
|
@@ -114,13 +128,28 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
114
128
|
details: { agentId },
|
|
115
129
|
});
|
|
116
130
|
}
|
|
131
|
+
const recorded = 'planRequest' in pending;
|
|
132
|
+
const planRequest = pending.planRequest ?? null;
|
|
117
133
|
const proposal = pending.proposal;
|
|
118
134
|
// An explicit `null` is a real answer — "no pending plan" — and every
|
|
119
135
|
// caller here already handles it. Anything else that is not a proposal is
|
|
120
136
|
// a broken response, not an empty one.
|
|
121
137
|
if (proposal == null)
|
|
122
|
-
return null;
|
|
123
|
-
return this.requireProposal(proposal, agentId, 'pending');
|
|
138
|
+
return { proposal: null, planRequest, recorded };
|
|
139
|
+
return { proposal: this.requireProposal(proposal, agentId, 'pending'), planRequest, recorded };
|
|
140
|
+
}
|
|
141
|
+
/** Refuse an action on the draft while its replacement is being generated. */
|
|
142
|
+
refuseWhileGenerating(agentId, state) {
|
|
143
|
+
if (!state.planRequest?.holds)
|
|
144
|
+
return;
|
|
145
|
+
this.failWithCliError({
|
|
146
|
+
message: `${(0, schedule_1.describePlanRequest)(state.planRequest)} ` +
|
|
147
|
+
`Run \`${this.config.bin} agents plan-day ${agentId}\` to wait for it.`,
|
|
148
|
+
code: 'SMART_SCHEDULE_PLAN_IN_PROGRESS',
|
|
149
|
+
exit: 1,
|
|
150
|
+
retryable: true,
|
|
151
|
+
details: { agentId, planRequest: state.planRequest },
|
|
152
|
+
});
|
|
124
153
|
}
|
|
125
154
|
workingHoursOverride(flags) {
|
|
126
155
|
if (!flags['hours-start'] || !flags['hours-end'])
|
|
@@ -133,65 +162,195 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
133
162
|
}
|
|
134
163
|
/**
|
|
135
164
|
* Gateway failures can interrupt a response after the planner started.
|
|
136
|
-
* Check the
|
|
165
|
+
* Check the server's record before suggesting another billable request; a
|
|
137
166
|
* 502 can also mean the planner never started, so do not assert that it did.
|
|
138
167
|
*/
|
|
139
168
|
static TIMEOUT_STATUSES = new Set([408, 502, 504, 524]);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
static
|
|
169
|
+
static POLL_INTERVAL_MS = 15_000;
|
|
170
|
+
/** Without a plan-request record (older server) the wait is the old, bounded guess. */
|
|
171
|
+
static LEGACY_POLL_ATTEMPTS = 12;
|
|
172
|
+
/** The longest a planner may run is ~12 min; wait that plus a margin, never forever. */
|
|
173
|
+
static MAX_WAIT_MS = 15 * 60_000;
|
|
174
|
+
/** A finished request's draft can lag a replica read; allow a few polls for it. */
|
|
175
|
+
static DRAFT_LAG_POLLS = 4;
|
|
176
|
+
/**
|
|
177
|
+
* Wait for a plan request to settle, reading the server's record each time.
|
|
178
|
+
*
|
|
179
|
+
* `target` says which request matters:
|
|
180
|
+
* - `existing`: one we found running, and want the result of.
|
|
181
|
+
* - `ours`: the request our POST started, whose response was lost. We only
|
|
182
|
+
* know the id of whatever was on record BEFORE posting, so a record that is
|
|
183
|
+
* missing or unchanged means the server never saw our request start.
|
|
184
|
+
*
|
|
185
|
+
* Returns instead of throwing for the three "no draft" endings so the caller
|
|
186
|
+
* decides what each means; a request that FAILED throws with the reason,
|
|
187
|
+
* because that is the one answer the person has been missing.
|
|
188
|
+
*/
|
|
189
|
+
async awaitPlanRequest(agentId, target, json) {
|
|
190
|
+
const startedAt = Date.now();
|
|
191
|
+
let legacyPolls = 0;
|
|
192
|
+
let lagPolls = 0;
|
|
193
|
+
while (Date.now() - startedAt < AgentsPlanDay.MAX_WAIT_MS) {
|
|
194
|
+
await new Promise((resolve) => setTimeout(resolve, AgentsPlanDay.POLL_INTERVAL_MS));
|
|
195
|
+
let state;
|
|
196
|
+
try {
|
|
197
|
+
state = await this.fetchPendingState(agentId);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// A read failing mid-wait is not itself the answer; keep waiting.
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const request = state.planRequest;
|
|
204
|
+
if (!state.recorded) {
|
|
205
|
+
// Older server: no record to read, so fall back to "a draft appeared".
|
|
206
|
+
legacyPolls += 1;
|
|
207
|
+
if (state.proposal)
|
|
208
|
+
return { outcome: 'proposal', proposal: state.proposal };
|
|
209
|
+
if (legacyPolls >= AgentsPlanDay.LEGACY_POLL_ATTEMPTS)
|
|
210
|
+
return { outcome: 'gave_up' };
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (request?.holds)
|
|
214
|
+
continue;
|
|
215
|
+
if (target.kind === 'ours' && (!request || request.requestId === target.baselineRequestId)) {
|
|
216
|
+
return { outcome: 'unrecorded' };
|
|
217
|
+
}
|
|
218
|
+
if (!request)
|
|
219
|
+
return { outcome: 'gave_up' };
|
|
220
|
+
if (request.state === 'failed') {
|
|
221
|
+
this.failWithCliError({
|
|
222
|
+
message: (0, schedule_1.describePlanRequest)(request) ?? 'The planning request failed.',
|
|
223
|
+
code: 'SMART_SCHEDULE_PLAN_FAILED',
|
|
224
|
+
exit: 1,
|
|
225
|
+
retryable: true,
|
|
226
|
+
details: { agentId, planRequest: request },
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (request.state === 'unknown')
|
|
230
|
+
return { outcome: 'unknown' };
|
|
231
|
+
// succeeded
|
|
232
|
+
if (state.proposal) {
|
|
233
|
+
if (!json) {
|
|
234
|
+
this.log(`The plan was ready ${Math.round((Date.now() - startedAt) / 1000)}s after waiting began.`);
|
|
235
|
+
}
|
|
236
|
+
return { outcome: 'proposal', proposal: state.proposal };
|
|
237
|
+
}
|
|
238
|
+
lagPolls += 1;
|
|
239
|
+
if (lagPolls >= AgentsPlanDay.DRAFT_LAG_POLLS)
|
|
240
|
+
return { outcome: 'gave_up' };
|
|
241
|
+
}
|
|
242
|
+
return { outcome: 'gave_up' };
|
|
243
|
+
}
|
|
143
244
|
/**
|
|
144
245
|
* After a timed-out propose, collect the draft the server persisted anyway.
|
|
145
246
|
* Returns null when the failure was not a timeout, or when nothing landed —
|
|
146
247
|
* in both cases the caller rethrows the original error rather than inventing
|
|
147
248
|
* a friendlier one.
|
|
148
249
|
*/
|
|
149
|
-
async recoverProposalAfterTimeout(agentId, err, json) {
|
|
250
|
+
async recoverProposalAfterTimeout(agentId, err, json, baselineRequestId) {
|
|
150
251
|
const status = err?.status;
|
|
151
252
|
if (typeof status !== 'number' || !AgentsPlanDay.TIMEOUT_STATUSES.has(status)) {
|
|
152
253
|
return null;
|
|
153
254
|
}
|
|
154
255
|
// stderr, so `--json` stdout stays a single parseable document.
|
|
155
256
|
this.warn(`The plan request for ${agentId} was interrupted (HTTP ${status}). ` +
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
return
|
|
174
|
-
}
|
|
257
|
+
"The run may still be finishing; checking the server's record of it before starting another.");
|
|
258
|
+
const waited = await this.awaitPlanRequest(agentId, { kind: 'ours', baselineRequestId }, json);
|
|
259
|
+
switch (waited.outcome) {
|
|
260
|
+
case 'proposal':
|
|
261
|
+
return waited.proposal;
|
|
262
|
+
case 'unrecorded':
|
|
263
|
+
this.warn(`The server has no record of this request starting, so nothing appears to be running for ${agentId}. ` +
|
|
264
|
+
'Run the command again.');
|
|
265
|
+
return null;
|
|
266
|
+
case 'unknown':
|
|
267
|
+
this.warn('The request stopped reporting and may have been interrupted. ' +
|
|
268
|
+
'Run the command again to plan; if it was still running, a second draft may appear.');
|
|
269
|
+
return null;
|
|
270
|
+
default:
|
|
271
|
+
this.warn(`No plan for ${agentId} became readable. ` +
|
|
272
|
+
`Check \`${this.config.bin} agents plan-day ${agentId}\` again before regenerating — ` +
|
|
273
|
+
'a second propose starts a second billable run.');
|
|
274
|
+
return null;
|
|
175
275
|
}
|
|
176
|
-
this.warn(`No plan for ${agentId} became readable within ` +
|
|
177
|
-
`${(AgentsPlanDay.RECOVERY_ATTEMPTS * AgentsPlanDay.RECOVERY_INTERVAL_MS) / 1000}s. ` +
|
|
178
|
-
'Check `skrr agents plan-day ' +
|
|
179
|
-
agentId +
|
|
180
|
-
'` again before regenerating — a second propose starts a second billable run.');
|
|
181
|
-
return null;
|
|
182
276
|
}
|
|
183
277
|
async runProposeOrShow(agentId, flags) {
|
|
184
278
|
let proposal = null;
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
279
|
+
// The zone the plan is proposed in. Sent explicitly: left to the server it
|
|
280
|
+
// falls back to the account's last-seen browser zone, which is not this
|
|
281
|
+
// machine's and shifted between runs (America/Los_Angeles, then
|
|
282
|
+
// America/Vancouver for the same agent and minute, OSK-22397).
|
|
283
|
+
const timezone = (0, schedule_1.resolveDayTimeZone)(flags.timezone) ?? 'UTC';
|
|
284
|
+
// Read the server's view first, whether or not a draft is wanted: whether a
|
|
285
|
+
// plan is already being generated decides everything that follows, and it
|
|
286
|
+
// is the baseline that tells a lost POST apart from one that never started.
|
|
287
|
+
let before = null;
|
|
288
|
+
try {
|
|
289
|
+
before = await this.fetchPendingState(agentId, { lenient: flags.regenerate !== undefined });
|
|
188
290
|
}
|
|
291
|
+
catch (readErr) {
|
|
292
|
+
// A fresh plan was never gated on this read; keep it that way.
|
|
293
|
+
if (flags.regenerate === undefined)
|
|
294
|
+
throw readErr;
|
|
295
|
+
}
|
|
296
|
+
if (before?.planRequest?.holds) {
|
|
297
|
+
if (flags.regenerate !== undefined)
|
|
298
|
+
this.refuseWhileGenerating(agentId, before);
|
|
299
|
+
// Someone (the web, another terminal, the agent) is already generating
|
|
300
|
+
// this plan. A second request would only be refused, and the answer the
|
|
301
|
+
// person wants is that plan.
|
|
302
|
+
this.warn((0, schedule_1.describePlanRequest)(before.planRequest) ?? 'A plan is being generated.');
|
|
303
|
+
this.warn('Waiting for it to finish.');
|
|
304
|
+
const waited = await this.awaitPlanRequest(agentId, { kind: 'existing' }, flags.json);
|
|
305
|
+
if (waited.outcome === 'proposal') {
|
|
306
|
+
proposal = waited.proposal;
|
|
307
|
+
}
|
|
308
|
+
else if (waited.outcome === 'unknown') {
|
|
309
|
+
this.warn('That request stopped reporting and may have been interrupted, so it no longer blocks planning.');
|
|
310
|
+
before = { ...before, planRequest: null };
|
|
311
|
+
proposal = before.proposal;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
this.failWithCliError({
|
|
315
|
+
message: `The plan for ${agentId} did not finish within the wait. ` +
|
|
316
|
+
`Check \`${this.config.bin} agents plan-day ${agentId}\` again.`,
|
|
317
|
+
code: 'SMART_SCHEDULE_PLAN_NOT_READY',
|
|
318
|
+
exit: 1,
|
|
319
|
+
retryable: true,
|
|
320
|
+
details: { agentId },
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else if (flags.regenerate === undefined) {
|
|
325
|
+
// Recover a pending draft unless the caller explicitly wants a fresh one.
|
|
326
|
+
proposal = before?.proposal ?? null;
|
|
327
|
+
}
|
|
328
|
+
// A planning attempt that FAILED is history the person should see, but not a
|
|
329
|
+
// reason to refuse: they asked to plan, and the next attempt may work.
|
|
330
|
+
let priorAttempt = null;
|
|
331
|
+
if (before?.planRequest?.state === 'failed' || before?.planRequest?.state === 'unknown') {
|
|
332
|
+
priorAttempt = before.planRequest;
|
|
333
|
+
this.warn((0, schedule_1.describePlanRequest)(priorAttempt) ?? '');
|
|
334
|
+
}
|
|
335
|
+
const showingPending = proposal !== null;
|
|
189
336
|
if (!proposal) {
|
|
337
|
+
// Planning is a real, billable agent run (~20s to a few minutes). Say so
|
|
338
|
+
// BEFORE starting it: a bare `plan-day` after an approval used to look
|
|
339
|
+
// like a status check and silently produced a second draft (OSK-22403).
|
|
340
|
+
if (!flags.json) {
|
|
341
|
+
this.log(flags.regenerate === undefined
|
|
342
|
+
? `No pending plan for ${agentId}; asking the planner for a new draft. This runs the agent and can take a minute or more.`
|
|
343
|
+
: `Asking the planner for a fresh plan for ${agentId}, replacing any pending one. This runs the agent and can take a minute or more.`);
|
|
344
|
+
if (flags.regenerate === undefined) {
|
|
345
|
+
this.log(`To look at what is already scheduled without planning: ${this.config.bin} agents todos list ${agentId}, ${this.config.bin} agents schedule-trace ${agentId}`);
|
|
346
|
+
}
|
|
347
|
+
this.log('');
|
|
348
|
+
}
|
|
190
349
|
let generated;
|
|
191
350
|
try {
|
|
192
351
|
generated = await schedule_1.scheduleApi.proposeSmartSchedule({
|
|
193
352
|
agentId,
|
|
194
|
-
|
|
353
|
+
timezone,
|
|
195
354
|
...(this.workingHoursOverride(flags)
|
|
196
355
|
? { workingHoursOverride: this.workingHoursOverride(flags) }
|
|
197
356
|
: {}),
|
|
@@ -210,7 +369,7 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
210
369
|
// Recovering the durable draft is also why this must never re-POST
|
|
211
370
|
// propose: a blind retry starts a SECOND run the user pays for while
|
|
212
371
|
// the first one is still finishing.
|
|
213
|
-
const recovered = await this.recoverProposalAfterTimeout(agentId, err, flags.json);
|
|
372
|
+
const recovered = await this.recoverProposalAfterTimeout(agentId, err, flags.json, before?.planRequest?.requestId ?? null);
|
|
214
373
|
if (!recovered)
|
|
215
374
|
throw err;
|
|
216
375
|
proposal = recovered;
|
|
@@ -220,20 +379,34 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
220
379
|
}
|
|
221
380
|
}
|
|
222
381
|
if (flags.json) {
|
|
223
|
-
|
|
382
|
+
// Additive: when the draft shown is an older one, the attempt after it that
|
|
383
|
+
// did not produce a newer. A freshly generated draft supersedes that history.
|
|
384
|
+
const showsOlderDraft = priorAttempt !== null && proposal === before?.proposal;
|
|
385
|
+
this.log(JSON.stringify(showsOlderDraft ? { ...proposal, planRequest: priorAttempt } : proposal, null, 2));
|
|
224
386
|
return;
|
|
225
387
|
}
|
|
388
|
+
if (showingPending) {
|
|
389
|
+
const zone = proposal.timezone || timezone;
|
|
390
|
+
const meta = [
|
|
391
|
+
proposal.version ? `v${proposal.version}` : null,
|
|
392
|
+
proposal.generatedAt ? `generated ${(0, format_1.zonedTime)(proposal.generatedAt, zone)}` : null,
|
|
393
|
+
]
|
|
394
|
+
.filter(Boolean)
|
|
395
|
+
.join(', ');
|
|
396
|
+
this.log(`Showing the pending plan${meta ? ` (${meta})` : ''}; pass --regenerate to replace it with a fresh one.`);
|
|
397
|
+
this.log('');
|
|
398
|
+
}
|
|
226
399
|
(0, schedule_1.renderProposal)(proposal, (line) => this.log(line));
|
|
227
400
|
this.log('');
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (proposal.nextRunSuggestion) {
|
|
231
|
-
this.log(` Include next run: ${this.config.bin} agents plan-day ${agentId} --approve --approve-next-run`);
|
|
232
|
-
}
|
|
233
|
-
this.log(` Discard: ${this.config.bin} agents plan-day ${agentId} --dismiss`);
|
|
401
|
+
for (const line of (0, schedule_1.proposalNextSteps)(proposal, this.config.bin, agentId))
|
|
402
|
+
this.log(line);
|
|
234
403
|
}
|
|
235
404
|
async runApprove(agentId, flags) {
|
|
236
|
-
const
|
|
405
|
+
const state = await this.fetchPendingState(agentId);
|
|
406
|
+
// The server refuses this too; saying so here names the request and the way
|
|
407
|
+
// to wait for it instead of surfacing a bare 409.
|
|
408
|
+
this.refuseWhileGenerating(agentId, state);
|
|
409
|
+
const proposal = state.proposal;
|
|
237
410
|
if (!proposal) {
|
|
238
411
|
this.error(`No pending plan for agent ${agentId}. Run \`${this.config.bin} agents plan-day ${agentId}\` first.`, { exit: 4 });
|
|
239
412
|
}
|
|
@@ -242,9 +415,10 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
242
415
|
this.error('The pending proposal has no suggested next run to approve.', { exit: 1 });
|
|
243
416
|
}
|
|
244
417
|
if (todos.length === 0 && !flags['approve-next-run']) {
|
|
418
|
+
const base = `${this.config.bin} agents plan-day ${agentId}`;
|
|
245
419
|
const next = proposal.nextRunSuggestion
|
|
246
|
-
? `
|
|
247
|
-
:
|
|
420
|
+
? ` To accept it and schedule its suggested next run, run \`${base} --approve --approve-next-run\` (two flags). To discard it, run \`${base} --dismiss\`.`
|
|
421
|
+
: ` There is nothing to approve; discard it with \`${base} --dismiss\`.`;
|
|
248
422
|
this.error(`The pending proposal has no schedulable to-dos.${next}`, { exit: 1 });
|
|
249
423
|
}
|
|
250
424
|
const result = await schedule_1.scheduleApi.approveSmartSchedule({
|
|
@@ -273,12 +447,20 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
273
447
|
this.log(JSON.stringify(result, null, 2));
|
|
274
448
|
return;
|
|
275
449
|
}
|
|
450
|
+
const zone = proposal.timezone || flags.timezone || 'UTC';
|
|
276
451
|
this.log(`Approved plan ${proposal.proposalId}: created ${result.created.length} to-do(s).`);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
452
|
+
if (result.replaced?.cancelled?.length) {
|
|
453
|
+
this.log(`Cancelled ${result.replaced.cancelled.length} earlier pending block(s) the plan replaced: ` +
|
|
454
|
+
result.replaced.cancelled.join(', '));
|
|
455
|
+
}
|
|
456
|
+
(0, schedule_1.renderCapacityWarning)(result.capacity, (line) => this.log(line), agentId, 'approved');
|
|
457
|
+
for (const line of (0, schedule_1.approvalEffectLines)(result, {
|
|
458
|
+
approvedNextRun: Boolean(flags['approve-next-run']),
|
|
459
|
+
timeZone: zone,
|
|
460
|
+
bin: this.config.bin,
|
|
461
|
+
agentId,
|
|
462
|
+
})) {
|
|
463
|
+
this.log(line);
|
|
282
464
|
}
|
|
283
465
|
if (result.failed.length > 0) {
|
|
284
466
|
this.log(`${result.failed.length} failed:`);
|
|
@@ -286,10 +468,15 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
286
468
|
this.log(` - ${f.tempId ?? '?'}: ${f.code} ${f.message}`);
|
|
287
469
|
}
|
|
288
470
|
}
|
|
289
|
-
|
|
471
|
+
// Name the day and zone the plan covers: a bare `todos list` shows today in
|
|
472
|
+
// the machine's zone, which is not the plan's day when they differ.
|
|
473
|
+
const dayFlags = `${proposal.planDate ? ` --date ${proposal.planDate}` : ''} --timezone ${zone}`;
|
|
474
|
+
this.log(`See them with: ${this.config.bin} agents todos list ${agentId}${dayFlags}`);
|
|
290
475
|
}
|
|
291
476
|
async runDismiss(agentId, json) {
|
|
292
|
-
const
|
|
477
|
+
const state = await this.fetchPendingState(agentId);
|
|
478
|
+
this.refuseWhileGenerating(agentId, state);
|
|
479
|
+
const proposal = state.proposal;
|
|
293
480
|
if (!proposal) {
|
|
294
481
|
this.log(`No pending plan for agent ${agentId}.`);
|
|
295
482
|
return;
|
|
@@ -300,6 +487,8 @@ class AgentsPlanDay extends base_command_1.BaseCommand {
|
|
|
300
487
|
return;
|
|
301
488
|
}
|
|
302
489
|
this.log(`Dismissed plan ${proposal.proposalId}.`);
|
|
490
|
+
for (const line of (0, schedule_1.dismissEffectLines)(result))
|
|
491
|
+
this.log(line);
|
|
303
492
|
}
|
|
304
493
|
}
|
|
305
494
|
exports.default = AgentsPlanDay;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base-command';
|
|
2
|
+
/**
|
|
3
|
+
* `skrr agents proactive-audit <agent-id>` — who changed this agent's proactivity boundary, when
|
|
4
|
+
* and why, across Compass, the worker (initiatives), Smart Schedule and the goal planner, plus the
|
|
5
|
+
* switches its task/goal watcher runs with and whether each is a setting or the platform default.
|
|
6
|
+
*
|
|
7
|
+
* `GET /api/todos/proactive-audit` had no CLI path; the only way to read it was devtools, and
|
|
8
|
+
* minting a token to curl it needs an authenticator code (OSK-22418).
|
|
9
|
+
*/
|
|
10
|
+
export default class AgentsProactiveAudit extends BaseCommand {
|
|
11
|
+
static description: string;
|
|
12
|
+
static examples: string[];
|
|
13
|
+
static args: {
|
|
14
|
+
agent: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
15
|
+
};
|
|
16
|
+
static flags: {
|
|
17
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
domain: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
20
|
+
};
|
|
21
|
+
run(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@oclif/core");
|
|
4
|
+
const base_command_1 = require("../../base-command");
|
|
5
|
+
const format_1 = require("../../lib/format");
|
|
6
|
+
const proactive_audit_1 = require("../../lib/proactive-audit");
|
|
7
|
+
const DOMAINS = [
|
|
8
|
+
'agent_compass',
|
|
9
|
+
'agent_initiatives',
|
|
10
|
+
'smart_schedule',
|
|
11
|
+
'goal_planner',
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* `skrr agents proactive-audit <agent-id>` — who changed this agent's proactivity boundary, when
|
|
15
|
+
* and why, across Compass, the worker (initiatives), Smart Schedule and the goal planner, plus the
|
|
16
|
+
* switches its task/goal watcher runs with and whether each is a setting or the platform default.
|
|
17
|
+
*
|
|
18
|
+
* `GET /api/todos/proactive-audit` had no CLI path; the only way to read it was devtools, and
|
|
19
|
+
* minting a token to curl it needs an authenticator code (OSK-22418).
|
|
20
|
+
*/
|
|
21
|
+
class AgentsProactiveAudit extends base_command_1.BaseCommand {
|
|
22
|
+
static description = "Who changed an agent's proactivity boundary (Compass, worker, Smart Schedule, goal planner), and the task/goal watcher's effective switches";
|
|
23
|
+
static examples = [
|
|
24
|
+
'<%= config.bin %> agents proactive-audit <agent-id>',
|
|
25
|
+
'<%= config.bin %> agents proactive-audit <agent-id> --domain smart_schedule --limit 20 --json',
|
|
26
|
+
];
|
|
27
|
+
static args = {
|
|
28
|
+
agent: core_1.Args.string({ ignoreStdin: true, description: 'Agent ID', required: true }),
|
|
29
|
+
};
|
|
30
|
+
static flags = {
|
|
31
|
+
json: core_1.Flags.boolean({ description: 'Output as JSON' }),
|
|
32
|
+
domain: core_1.Flags.string({
|
|
33
|
+
description: `Only one domain's changes (${DOMAINS.join(', ')})`,
|
|
34
|
+
options: DOMAINS,
|
|
35
|
+
}),
|
|
36
|
+
limit: core_1.Flags.integer({ description: 'Events to return (1-200, newest first)', min: 1, max: 200 }),
|
|
37
|
+
};
|
|
38
|
+
async run() {
|
|
39
|
+
this.requireAuth();
|
|
40
|
+
const { args, flags } = await this.parse(AgentsProactiveAudit);
|
|
41
|
+
let audit;
|
|
42
|
+
try {
|
|
43
|
+
audit = await proactive_audit_1.proactiveAuditApi.read({
|
|
44
|
+
agentId: args.agent,
|
|
45
|
+
domain: flags.domain,
|
|
46
|
+
limit: flags.limit,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
this.handleApiError(err);
|
|
51
|
+
}
|
|
52
|
+
if (flags.json) {
|
|
53
|
+
this.printJsonResult(audit);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!audit) {
|
|
57
|
+
this.error('No audit returned.', { exit: 1 });
|
|
58
|
+
}
|
|
59
|
+
const events = audit.events ?? [];
|
|
60
|
+
this.log(`Proactivity audit - ${args.agent}`);
|
|
61
|
+
this.log('');
|
|
62
|
+
if (events.length === 0) {
|
|
63
|
+
this.log(flags.domain
|
|
64
|
+
? `No boundary changes recorded for ${flags.domain}.`
|
|
65
|
+
: 'No boundary changes recorded: nobody has changed this agent\'s proactivity settings.');
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
(0, format_1.renderTable)(events.map((event) => ({
|
|
69
|
+
when: event.occurredAt ? String(event.occurredAt).slice(0, 19).replace('T', ' ') : '-',
|
|
70
|
+
domain: (0, format_1.formatCell)(event.domain),
|
|
71
|
+
change: (0, format_1.formatCell)(event.changeType),
|
|
72
|
+
by: (0, format_1.formatCell)(event.actorAgentId ?? event.actorUserId ?? event.actorType),
|
|
73
|
+
why: (0, format_1.formatCell)(event.summary ?? event.reason),
|
|
74
|
+
})), [
|
|
75
|
+
{ key: 'when', header: 'WHEN' },
|
|
76
|
+
{ key: 'domain', header: 'DOMAIN' },
|
|
77
|
+
{ key: 'change', header: 'CHANGE', maxWidth: 24 },
|
|
78
|
+
{ key: 'by', header: 'BY', maxWidth: 24 },
|
|
79
|
+
{ key: 'why', header: 'WHY', maxWidth: 56 },
|
|
80
|
+
], (line) => this.log(line));
|
|
81
|
+
}
|
|
82
|
+
this.log('');
|
|
83
|
+
(0, proactive_audit_1.renderTaskGoalWatcherSettings)(audit.taskGoalWatcher, (line) => this.log(line));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.default = AgentsProactiveAudit;
|
|
@@ -26,6 +26,13 @@ export default class AgentsScheduleOverview extends BaseCommand {
|
|
|
26
26
|
};
|
|
27
27
|
run(): Promise<void>;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Disabled triggers the person (or an agent on their behalf) authored. Not the reflection loop, which has
|
|
31
|
+
* its own section, and not a row a platform producer maintains, which nobody paused on purpose.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pausedTriggers(triggers: TriggerDefinition[], reflection?: TriggerDefinition): TriggerDefinition[];
|
|
34
|
+
/** The paused triggers as the text view prints them: newest first, capped, with where to see the rest. */
|
|
35
|
+
export declare function pausedTriggerLines(paused: TriggerDefinition[], agentId: string, bin: string): string[];
|
|
29
36
|
/** The reflection loop as `--json` reports it. A paused loop has no next run (`-`). */
|
|
30
37
|
export declare function reflectionSummary(reflection: TriggerDefinition): {
|
|
31
38
|
autonomy?: "runs" | "suggests_only";
|