@skrr-ai/cli 0.1.145 → 0.1.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/agenda/plan.d.ts +14 -0
- package/dist/commands/agenda/plan.js +29 -0
- package/dist/commands/agent/message/approve.js +5 -1
- package/dist/commands/agent/message/decline.js +5 -1
- package/dist/commands/agents/always-on/enable.js +1 -1
- package/dist/commands/agents/schedule-overview.js +9 -10
- package/dist/commands/agents/spawn.d.ts +38 -1
- package/dist/commands/agents/spawn.js +103 -3
- package/dist/commands/agents/triggers/fire.js +20 -0
- package/dist/commands/triggers/audit.js +1 -1
- package/dist/commands/triggers/fire.js +19 -0
- package/dist/lib/agentic-stream.d.ts +21 -0
- package/dist/lib/agentic-stream.js +67 -1
- package/dist/lib/format.d.ts +5 -0
- package/dist/lib/format.js +16 -0
- package/dist/lib/proactiveApi.d.ts +38 -1
- package/dist/lib/proactiveApi.js +17 -1
- package/dist/lib/schedule.d.ts +15 -0
- package/dist/lib/schedule.js +14 -0
- package/dist/lib/triggers.d.ts +129 -3
- package/dist/lib/triggers.js +248 -20
- package/dist/node_modules/@skrr-ai/auth-core/package.json +1 -1
- package/dist/node_modules/@skrr-ai/data-provider/index.js +984 -983
- package/oclif.manifest.json +8 -1
- package/package.json +1 -1
|
@@ -6,6 +6,20 @@ import { BaseCommand } from '../../base-command';
|
|
|
6
6
|
* (OSK-22554). Names the cloud worker when that is where the turn is queued.
|
|
7
7
|
*/
|
|
8
8
|
export declare function describeQueuedProgress(runtime: unknown): string;
|
|
9
|
+
/**
|
|
10
|
+
* Why a followed Agenda turn failed, in words.
|
|
11
|
+
*
|
|
12
|
+
* The stream's terminal event does not always carry the reason: a turn the platform refused (a
|
|
13
|
+
* workspace out of credit) or that lost a write wrote it on the response message only, and the
|
|
14
|
+
* command exited 1 with nothing printed (OSK-22639). The terminal event's own sentence wins; the
|
|
15
|
+
* stored message is the second witness; a failure with neither says so rather than staying silent.
|
|
16
|
+
*/
|
|
17
|
+
export declare function describeAgendaFailure(input: {
|
|
18
|
+
lastEvent: Record<string, unknown> | null | undefined;
|
|
19
|
+
readMessages: () => Promise<Array<Record<string, unknown>>>;
|
|
20
|
+
responseMessageId?: string;
|
|
21
|
+
conversationId: string;
|
|
22
|
+
}): Promise<string>;
|
|
9
23
|
/**
|
|
10
24
|
* `skrr agenda plan <agent-id>` — kick off a one-shot Agenda Planning turn
|
|
11
25
|
* for an agent. The server-side controller resolves the agent's persistent
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.describeQueuedProgress = describeQueuedProgress;
|
|
4
|
+
exports.describeAgendaFailure = describeAgendaFailure;
|
|
4
5
|
const core_1 = require("@oclif/core");
|
|
5
6
|
const data_provider_1 = require("@skrr-ai/data-provider");
|
|
6
7
|
const base_command_1 = require("../../base-command");
|
|
@@ -22,6 +23,28 @@ function describeQueuedProgress(runtime) {
|
|
|
22
23
|
? 'Queued on the cloud worker, starting…'
|
|
23
24
|
: 'Queued, waiting for the agent runtime to start…';
|
|
24
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Why a followed Agenda turn failed, in words.
|
|
28
|
+
*
|
|
29
|
+
* The stream's terminal event does not always carry the reason: a turn the platform refused (a
|
|
30
|
+
* workspace out of credit) or that lost a write wrote it on the response message only, and the
|
|
31
|
+
* command exited 1 with nothing printed (OSK-22639). The terminal event's own sentence wins; the
|
|
32
|
+
* stored message is the second witness; a failure with neither says so rather than staying silent.
|
|
33
|
+
*/
|
|
34
|
+
async function describeAgendaFailure(input) {
|
|
35
|
+
let reason = (0, agentic_stream_1.terminalFailureMessage)(input.lastEvent);
|
|
36
|
+
if (!reason) {
|
|
37
|
+
try {
|
|
38
|
+
const recorded = (0, chat_1.reconcileTerminalFromMessages)(await input.readMessages(), input.responseMessageId);
|
|
39
|
+
if (recorded?.status === 'failed' && recorded.error)
|
|
40
|
+
reason = recorded.error;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// The record could not be read; the line below still says the turn failed.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return `Agenda planning failed: ${reason ?? 'the run ended in failure and recorded no reason.'} Conversation ${input.conversationId}.`;
|
|
47
|
+
}
|
|
25
48
|
function describeRuntime(runtime) {
|
|
26
49
|
if (typeof runtime === 'string')
|
|
27
50
|
return runtime;
|
|
@@ -172,6 +195,12 @@ class AgendaPlan extends base_command_1.BaseCommand {
|
|
|
172
195
|
process.exitCode = interruptedBy === 'SIGTERM' ? 143 : interruptedBy === 'SIGHUP' ? 129 : interruptedBy ? 130 : 75;
|
|
173
196
|
}
|
|
174
197
|
else if (result.status === 'failed') {
|
|
198
|
+
process.stderr.write(`\n${await describeAgendaFailure({
|
|
199
|
+
lastEvent: result.lastEvent,
|
|
200
|
+
readMessages,
|
|
201
|
+
responseMessageId: response.responseMessageId,
|
|
202
|
+
conversationId: response.conversationId,
|
|
203
|
+
})}\n`);
|
|
175
204
|
process.exitCode = 1;
|
|
176
205
|
}
|
|
177
206
|
else if (result.status === 'aborted' && interruptedBy !== 'SIGHUP') {
|
|
@@ -16,7 +16,11 @@ class AgentMessageApprove extends base_command_1.BaseCommand {
|
|
|
16
16
|
'<%= config.bin %> agent message approve <intent-id> --agent <agent-id>',
|
|
17
17
|
];
|
|
18
18
|
static args = {
|
|
19
|
-
intent: core_1.Args.string({
|
|
19
|
+
intent: core_1.Args.string({
|
|
20
|
+
description: 'Intent ID from `agent message pending`',
|
|
21
|
+
required: true,
|
|
22
|
+
ignoreStdin: true,
|
|
23
|
+
}),
|
|
20
24
|
};
|
|
21
25
|
static flags = {
|
|
22
26
|
agent: core_1.Flags.string({ description: 'Agent ID', required: false }),
|
|
@@ -16,7 +16,11 @@ class AgentMessageDecline extends base_command_1.BaseCommand {
|
|
|
16
16
|
'<%= config.bin %> agent message decline <intent-id> --agent <agent-id>',
|
|
17
17
|
];
|
|
18
18
|
static args = {
|
|
19
|
-
intent: core_1.Args.string({
|
|
19
|
+
intent: core_1.Args.string({
|
|
20
|
+
description: 'Intent ID from `agent message pending`',
|
|
21
|
+
required: true,
|
|
22
|
+
ignoreStdin: true,
|
|
23
|
+
}),
|
|
20
24
|
};
|
|
21
25
|
static flags = {
|
|
22
26
|
agent: core_1.Flags.string({ description: 'Agent ID', required: false }),
|
|
@@ -66,7 +66,7 @@ class AgentsAlwaysOnEnable extends base_command_1.BaseCommand {
|
|
|
66
66
|
if (!result.matched)
|
|
67
67
|
this.exit(1);
|
|
68
68
|
if (status.operationalState === 'needs_setup') {
|
|
69
|
-
this.log('Note: no Commitment or managed producer lane exists yet. Create a Commitment (or convert a
|
|
69
|
+
this.log('Note: no Commitment or managed producer lane exists yet. Create a Commitment (or convert a standalone check-in) so the runtime has something to fire.');
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -109,19 +109,19 @@ class AgentsScheduleOverview extends base_command_1.BaseCommand {
|
|
|
109
109
|
if (note)
|
|
110
110
|
this.log(note);
|
|
111
111
|
}
|
|
112
|
-
// FUTURE.
|
|
112
|
+
// FUTURE. One named zone for every time below, as `agents upcoming` does (OSK-22643).
|
|
113
113
|
this.log('');
|
|
114
|
-
this.log(`■ Upcoming (next ${flags['horizon-days']}d)`);
|
|
114
|
+
this.log(`■ Upcoming (next ${flags['horizon-days']}d, times in ${(0, schedule_1.describeTimeZone)(todayZone)})`);
|
|
115
115
|
reportError(upcomingR, (line) => this.log(` ${line}`));
|
|
116
116
|
if (upcoming.length === 0) {
|
|
117
117
|
this.log(' Nothing upcoming.');
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
120
120
|
(0, format_1.renderTable)(upcoming.map((item) => ({
|
|
121
|
-
when: formatStamp(item.fireAt),
|
|
121
|
+
when: formatStamp(item.fireAt, todayZone),
|
|
122
122
|
kind: item.kind,
|
|
123
|
-
title: titleOf(item),
|
|
124
|
-
detail: detailOf(item),
|
|
123
|
+
title: (0, format_1.localizeIsoInstants)(titleOf(item), todayZone),
|
|
124
|
+
detail: (0, format_1.localizeIsoInstants)(detailOf(item), todayZone),
|
|
125
125
|
})), [
|
|
126
126
|
{ key: 'when', header: 'WHEN', maxWidth: 26 },
|
|
127
127
|
{ key: 'kind', header: 'KIND', maxWidth: 14 },
|
|
@@ -162,7 +162,7 @@ class AgentsScheduleOverview extends base_command_1.BaseCommand {
|
|
|
162
162
|
this.log('');
|
|
163
163
|
this.log('■ Recent fires');
|
|
164
164
|
reportError(firesR, (line) => this.log(` ${line}`));
|
|
165
|
-
(0, triggers_1.renderFireAudit)(fires, (line) => this.log(line));
|
|
165
|
+
(0, triggers_1.renderFireAudit)(fires, (line) => this.log(line), undefined, { timeZone: todayZone });
|
|
166
166
|
// Open tasks assigned to this agent.
|
|
167
167
|
this.log('');
|
|
168
168
|
this.log('■ Open tasks (assigned to this agent)');
|
|
@@ -175,7 +175,7 @@ class AgentsScheduleOverview extends base_command_1.BaseCommand {
|
|
|
175
175
|
ref: String(t.identifier ?? (t.taskNumber ? `#${t.taskNumber}` : '-')),
|
|
176
176
|
title: String(t.title ?? '-'),
|
|
177
177
|
status: String(t.status ?? '-'),
|
|
178
|
-
when: t.scheduledFor ? formatStamp(String(t.scheduledFor)) : '-',
|
|
178
|
+
when: t.scheduledFor ? formatStamp(String(t.scheduledFor), todayZone) : '-',
|
|
179
179
|
id: String(t.id ?? t._id ?? '-'),
|
|
180
180
|
})), [
|
|
181
181
|
{ key: 'ref', header: 'REF' },
|
|
@@ -289,11 +289,10 @@ function collectErrors(results) {
|
|
|
289
289
|
}
|
|
290
290
|
return Object.keys(errors).length > 0 ? errors : undefined;
|
|
291
291
|
}
|
|
292
|
-
function formatStamp(iso) {
|
|
292
|
+
function formatStamp(iso, zone) {
|
|
293
293
|
if (!iso)
|
|
294
294
|
return '-';
|
|
295
|
-
|
|
296
|
-
return Number.isNaN(d.getTime()) ? iso : d.toISOString();
|
|
295
|
+
return (0, format_1.zonedTime)(iso, zone, { seconds: false });
|
|
297
296
|
}
|
|
298
297
|
function titleOf(item) {
|
|
299
298
|
if (item.kind === 'message')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseCommand } from '../../base-command';
|
|
2
|
-
import { type InstallPlanItem, type ProactiveAgentSpec, type ApplyProactiveAgentResponse } from '../../lib/proactiveApi';
|
|
2
|
+
import { type InstallPlanItem, type SpawnOperation, type ProactiveAgentSpec, type ApplyProactiveAgentResponse } from '../../lib/proactiveApi';
|
|
3
3
|
export type ProactiveInstallReadiness = {
|
|
4
4
|
status: 'ready' | 'degraded';
|
|
5
5
|
message: string;
|
|
@@ -57,6 +57,35 @@ export declare const SPEC_FORMAT_HELP: string;
|
|
|
57
57
|
* visible as what is.
|
|
58
58
|
*/
|
|
59
59
|
export declare function installPlanLines(items: InstallPlanItem[], bin: string): string[];
|
|
60
|
+
export declare const SPAWN_FOLLOW_POLL_MS = 3000;
|
|
61
|
+
/** Longer than an install has taken; past it the CLI says where to read the receipt instead. */
|
|
62
|
+
export declare const SPAWN_FOLLOW_MAX_WAIT_MS: number;
|
|
63
|
+
export type SpawnFollowOutcome = {
|
|
64
|
+
kind: 'done';
|
|
65
|
+
result: NonNullable<SpawnOperation['result']>;
|
|
66
|
+
} | {
|
|
67
|
+
kind: 'failed';
|
|
68
|
+
message: string;
|
|
69
|
+
code?: string;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'quiet';
|
|
72
|
+
} | {
|
|
73
|
+
kind: 'timeout';
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Follow a spawn the server answered 202 for until it reports a receipt or a failure. The install is
|
|
77
|
+
* not cut short by the edge's 60 s any more, but its receipt used to be lost with the 504 (OSK-22623).
|
|
78
|
+
* A read that fails (a 5xx, the network) is waited through; a 4xx other than "not yet" is the answer.
|
|
79
|
+
*/
|
|
80
|
+
export declare function followSpawnOperation(options: {
|
|
81
|
+
operationId: string;
|
|
82
|
+
read?: (operationId: string) => Promise<SpawnOperation | undefined>;
|
|
83
|
+
sleep?: (ms: number) => Promise<void>;
|
|
84
|
+
now?: () => number;
|
|
85
|
+
pollMs?: number;
|
|
86
|
+
maxWaitMs?: number;
|
|
87
|
+
onWaiting?: (elapsedMs: number) => void;
|
|
88
|
+
}): Promise<SpawnFollowOutcome>;
|
|
60
89
|
/** What `--minimal` / `--without` say when the server cannot honour them. */
|
|
61
90
|
export declare const DECLINE_UNSUPPORTED_MESSAGE = "This server does not support --minimal/--without yet; nothing was opted out.";
|
|
62
91
|
/** A value as one POSIX shell word, so a printed command can be pasted as it is. */
|
|
@@ -104,6 +133,7 @@ export default class AgentsSpawn extends BaseCommand {
|
|
|
104
133
|
'apply-recommendation': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
105
134
|
'spec-hash': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
106
135
|
'from-spec': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
136
|
+
follow: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
107
137
|
'print-spec-template': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
108
138
|
minimal: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
109
139
|
without: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -122,6 +152,13 @@ export default class AgentsSpawn extends BaseCommand {
|
|
|
122
152
|
*/
|
|
123
153
|
private readInstallPlan;
|
|
124
154
|
private printInstallPlan;
|
|
155
|
+
/**
|
|
156
|
+
* An apply answer in hand: a receipt passes through; a `202` is followed to its receipt. An install
|
|
157
|
+
* takes longer than the edge allows, and the CLI used to print a 504 for one that completed with its
|
|
158
|
+
* receipt lost (OSK-22623).
|
|
159
|
+
*/
|
|
160
|
+
private resolveApplyAnswer;
|
|
161
|
+
private followToReceipt;
|
|
125
162
|
/**
|
|
126
163
|
* Refuse BEFORE creating anything when `--minimal` / `--without` were asked for and this server
|
|
127
164
|
* cannot honour them. A server that predates the options ignores them, applies every default and
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DECLINE_UNSUPPORTED_MESSAGE = exports.SPEC_FORMAT_HELP = exports.SPEC_TEMPLATE = void 0;
|
|
3
|
+
exports.DECLINE_UNSUPPORTED_MESSAGE = exports.SPAWN_FOLLOW_MAX_WAIT_MS = exports.SPAWN_FOLLOW_POLL_MS = exports.SPEC_FORMAT_HELP = exports.SPEC_TEMPLATE = void 0;
|
|
4
4
|
exports.workerPolicyWindowLines = workerPolicyWindowLines;
|
|
5
5
|
exports.specWithEffectiveWindowFlags = specWithEffectiveWindowFlags;
|
|
6
6
|
exports.installPlanLines = installPlanLines;
|
|
7
|
+
exports.followSpawnOperation = followSpawnOperation;
|
|
7
8
|
exports.shellQuote = shellQuote;
|
|
8
9
|
exports.initializeSummary = initializeSummary;
|
|
9
10
|
exports.proactiveInstallReadiness = proactiveInstallReadiness;
|
|
@@ -117,6 +118,47 @@ function installPlanLines(items, bin) {
|
|
|
117
118
|
}
|
|
118
119
|
return lines;
|
|
119
120
|
}
|
|
121
|
+
exports.SPAWN_FOLLOW_POLL_MS = 3_000;
|
|
122
|
+
/** Longer than an install has taken; past it the CLI says where to read the receipt instead. */
|
|
123
|
+
exports.SPAWN_FOLLOW_MAX_WAIT_MS = 10 * 60 * 1000;
|
|
124
|
+
/**
|
|
125
|
+
* Follow a spawn the server answered 202 for until it reports a receipt or a failure. The install is
|
|
126
|
+
* not cut short by the edge's 60 s any more, but its receipt used to be lost with the 504 (OSK-22623).
|
|
127
|
+
* A read that fails (a 5xx, the network) is waited through; a 4xx other than "not yet" is the answer.
|
|
128
|
+
*/
|
|
129
|
+
async function followSpawnOperation(options) {
|
|
130
|
+
const { operationId, read = async (id) => (await proactiveApi_1.proactiveApi.spawnOperation(id)).operation, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now = Date.now, pollMs = exports.SPAWN_FOLLOW_POLL_MS, maxWaitMs = exports.SPAWN_FOLLOW_MAX_WAIT_MS, onWaiting, } = options;
|
|
131
|
+
const startedAt = now();
|
|
132
|
+
for (;;) {
|
|
133
|
+
let operation;
|
|
134
|
+
try {
|
|
135
|
+
operation = await read(operationId);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
const status = (0, http_error_1.httpStatusOf)(error);
|
|
139
|
+
if (status !== undefined && status < 500)
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
if (operation?.state === 'succeeded' && operation.result) {
|
|
143
|
+
return { kind: 'done', result: operation.result };
|
|
144
|
+
}
|
|
145
|
+
if (operation?.state === 'failed') {
|
|
146
|
+
const body = operation.failure?.body;
|
|
147
|
+
return {
|
|
148
|
+
kind: 'failed',
|
|
149
|
+
message: body?.error || body?.message || 'The install failed.',
|
|
150
|
+
...(body?.code ? { code: body.code } : {}),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (operation?.state === 'unknown')
|
|
154
|
+
return { kind: 'quiet' };
|
|
155
|
+
const elapsed = now() - startedAt;
|
|
156
|
+
if (elapsed >= maxWaitMs)
|
|
157
|
+
return { kind: 'timeout' };
|
|
158
|
+
onWaiting?.(elapsed);
|
|
159
|
+
await sleep(pollMs);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
120
162
|
/** What `--minimal` / `--without` say when the server cannot honour them. */
|
|
121
163
|
exports.DECLINE_UNSUPPORTED_MESSAGE = 'This server does not support --minimal/--without yet; nothing was opted out.';
|
|
122
164
|
/** A value as one POSIX shell word, so a printed command can be pasted as it is. */
|
|
@@ -201,6 +243,21 @@ function proactiveInstallReadiness(result, bin) {
|
|
|
201
243
|
: `${bin} commitments list --agent ${safeAgentId ?? '<agent-id>'} --status draft`,
|
|
202
244
|
};
|
|
203
245
|
}
|
|
246
|
+
// A draft held only because Always-On is off names that gate in its `blockedBy` (no activation
|
|
247
|
+
// diagnostic exists, since nothing refused it). The repair is turning Always-On on, not a dry
|
|
248
|
+
// run; `commitments preflight` told the owner so one step later (OSK-22629).
|
|
249
|
+
const heldByAlwaysOff = affected.length > 0 &&
|
|
250
|
+
affected.every((commitment) => commitment.status === 'draft' &&
|
|
251
|
+
(commitment.blockedBy || []).some((entry) => entry.gate === 'always_on' && entry.reason === 'always_on_disabled'));
|
|
252
|
+
if (heldByAlwaysOff && safeAgentId && ids.length) {
|
|
253
|
+
return {
|
|
254
|
+
status: 'degraded',
|
|
255
|
+
message: `Always-On is off, so the Commitment${ids.length === 1 ? '' : 's'} ${ids.join(', ')} ` +
|
|
256
|
+
`${ids.length === 1 ? 'was' : 'were'} left as ${ids.length === 1 ? 'a draft' : 'drafts'}. ` +
|
|
257
|
+
'Turn Always-On on if you want it to run, then resume it.',
|
|
258
|
+
repairCommand: `${bin} agents always-on enable ${safeAgentId}`,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
204
261
|
return {
|
|
205
262
|
status: 'degraded',
|
|
206
263
|
message: ids.length
|
|
@@ -328,6 +385,9 @@ class AgentsSpawn extends base_command_1.BaseCommand {
|
|
|
328
385
|
'from-spec': core_1.Flags.string({
|
|
329
386
|
description: 'Path to a spec JSON (or "-" for stdin) to apply directly (requires --approve). Its shape is under SPEC FORMAT below; --print-spec-template prints a valid one. An explicit empty systems list skips implicit baseline watchers.',
|
|
330
387
|
}),
|
|
388
|
+
follow: core_1.Flags.string({
|
|
389
|
+
description: 'Read the receipt of an install that outlived its request, by the operation id the 202 named, and exit',
|
|
390
|
+
}),
|
|
331
391
|
'print-spec-template': core_1.Flags.boolean({
|
|
332
392
|
description: 'Print a valid spec JSON to edit and pass to --from-spec, and exit (creates nothing)',
|
|
333
393
|
}),
|
|
@@ -359,6 +419,16 @@ class AgentsSpawn extends base_command_1.BaseCommand {
|
|
|
359
419
|
return;
|
|
360
420
|
}
|
|
361
421
|
this.requireAuth();
|
|
422
|
+
if (flags.follow) {
|
|
423
|
+
try {
|
|
424
|
+
const result = await this.followToReceipt(flags.follow);
|
|
425
|
+
this.renderApplyResult(result, flags.json, false);
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
this.handleApiError(err);
|
|
429
|
+
}
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
362
432
|
// A recommendation is approved and applied as reviewed, with no way to decline a default;
|
|
363
433
|
// refusing here is better than a --minimal that silently installs everything.
|
|
364
434
|
if ((flags.minimal || (flags.without ?? []).length > 0) &&
|
|
@@ -427,6 +497,34 @@ class AgentsSpawn extends base_command_1.BaseCommand {
|
|
|
427
497
|
for (const line of installPlanLines(items, this.config.bin))
|
|
428
498
|
this.log(line);
|
|
429
499
|
}
|
|
500
|
+
/**
|
|
501
|
+
* An apply answer in hand: a receipt passes through; a `202` is followed to its receipt. An install
|
|
502
|
+
* takes longer than the edge allows, and the CLI used to print a 504 for one that completed with its
|
|
503
|
+
* receipt lost (OSK-22623).
|
|
504
|
+
*/
|
|
505
|
+
async resolveApplyAnswer(answer) {
|
|
506
|
+
if (!(0, proactiveApi_1.isSpawnAccepted)(answer))
|
|
507
|
+
return answer;
|
|
508
|
+
process.stderr.write(`The install is running on the server (operation ${answer.operation.id}); waiting for its receipt...\n`);
|
|
509
|
+
return this.followToReceipt(answer.operation.id);
|
|
510
|
+
}
|
|
511
|
+
async followToReceipt(operationId) {
|
|
512
|
+
const outcome = await followSpawnOperation({ operationId });
|
|
513
|
+
if (outcome.kind === 'done')
|
|
514
|
+
return outcome.result;
|
|
515
|
+
const again = `${this.config.bin} agents spawn --follow ${operationId}`;
|
|
516
|
+
if (outcome.kind === 'failed') {
|
|
517
|
+
return this.error(`The install failed: ${outcome.message}${outcome.code ? ` (${outcome.code})` : ''}`, {
|
|
518
|
+
exit: 1,
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
if (outcome.kind === 'quiet') {
|
|
522
|
+
return this.error(`The server no longer reports on this install (operation ${operationId}); it may have been interrupted. ` +
|
|
523
|
+
`Check what exists with \`${this.config.bin} agents list\`; applying the same spec with --agent-id converges it.`, { exit: 1 });
|
|
524
|
+
}
|
|
525
|
+
return this.error(`The install is still running after ${Math.round(exports.SPAWN_FOLLOW_MAX_WAIT_MS / 60000)} minutes. ` +
|
|
526
|
+
`It was not cut short; read its receipt with \`${again}\`.`, { exit: 1 });
|
|
527
|
+
}
|
|
430
528
|
/**
|
|
431
529
|
* Refuse BEFORE creating anything when `--minimal` / `--without` were asked for and this server
|
|
432
530
|
* cannot honour them. A server that predates the options ignores them, applies every default and
|
|
@@ -483,13 +581,14 @@ class AgentsSpawn extends base_command_1.BaseCommand {
|
|
|
483
581
|
return;
|
|
484
582
|
}
|
|
485
583
|
await this.assertServerDeclinesDefaults(spec, flags, true);
|
|
486
|
-
const
|
|
584
|
+
const applied = await proactiveApi_1.proactiveApi.applyProactiveAgentSpec({
|
|
487
585
|
spec,
|
|
488
586
|
...(flags['agent-id'] ? { agentId: flags['agent-id'] } : {}),
|
|
489
587
|
...(flags.timezone ? { timezone: flags.timezone } : {}),
|
|
490
588
|
fromReviewedSpec: true,
|
|
491
589
|
...this.declineOptions(flags),
|
|
492
590
|
});
|
|
591
|
+
const result = await this.resolveApplyAnswer(applied);
|
|
493
592
|
this.renderApplyResult(result, flags.json, Boolean(flags['agent-id']));
|
|
494
593
|
this.assertDeclinesApplied(result, flags);
|
|
495
594
|
}
|
|
@@ -574,13 +673,14 @@ class AgentsSpawn extends base_command_1.BaseCommand {
|
|
|
574
673
|
return;
|
|
575
674
|
}
|
|
576
675
|
await this.assertServerDeclinesDefaults(spec, flags, false);
|
|
577
|
-
const
|
|
676
|
+
const applied = await proactiveApi_1.proactiveApi.applyProactiveAgentSpec({
|
|
578
677
|
spec,
|
|
579
678
|
...(flags['agent-id'] ? { agentId: flags['agent-id'] } : {}),
|
|
580
679
|
...(flags.timezone ? { timezone: flags.timezone } : {}),
|
|
581
680
|
fromReviewedSpec: false,
|
|
582
681
|
...this.declineOptions(flags),
|
|
583
682
|
});
|
|
683
|
+
const result = await this.resolveApplyAnswer(applied);
|
|
584
684
|
this.renderApplyResult(result, flags.json, Boolean(flags['agent-id']));
|
|
585
685
|
this.assertDeclinesApplied(result, flags);
|
|
586
686
|
}
|
|
@@ -50,6 +50,26 @@ class AgentsTriggersFire extends base_command_1.BaseCommand {
|
|
|
50
50
|
this.error(err.message, { exit: 4 });
|
|
51
51
|
this.handleApiError(err);
|
|
52
52
|
}
|
|
53
|
+
// A watcher fire can run for minutes; the server answers 202 with the occurrence once it has
|
|
54
|
+
// outlived a short wait, and the result is followed here (OSK-22624).
|
|
55
|
+
const settled = await (0, triggers_1.settleFireAnswer)({
|
|
56
|
+
triggerId: args.triggerId,
|
|
57
|
+
agentId: args.agentId,
|
|
58
|
+
bin: this.config.bin,
|
|
59
|
+
answer: result,
|
|
60
|
+
note: (line) => process.stderr.write(`${line}\n`),
|
|
61
|
+
});
|
|
62
|
+
if (settled.running) {
|
|
63
|
+
if (flags.json) {
|
|
64
|
+
this.printJsonResult({ ...settled.answer, ok: true });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.log(`Fire accepted and still running (occurrence ${settled.answer.occurrenceId ?? '-'}).`);
|
|
68
|
+
this.log(`Read its result later: ${settled.command}`);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
result = settled.result;
|
|
53
73
|
const refused = flags.strict && !(0, triggers_1.fireWasAccepted)(result);
|
|
54
74
|
const refusal = refused ? (0, triggers_1.describeStrictFireRefusal)(result) : null;
|
|
55
75
|
if (flags.json) {
|
|
@@ -71,7 +71,7 @@ class TriggersAudit extends base_command_1.BaseCommand {
|
|
|
71
71
|
this.log(JSON.stringify(response, null, 2));
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
(0, triggers_1.renderFireAudit)(response.fires ?? [], (line) => this.log(line));
|
|
74
|
+
(0, triggers_1.renderFireAudit)(response.fires ?? [], (line) => this.log(line), response.waiting);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
exports.default = TriggersAudit;
|
|
@@ -44,6 +44,25 @@ class TriggersFire extends base_command_1.BaseCommand {
|
|
|
44
44
|
catch (err) {
|
|
45
45
|
this.handleApiError(err);
|
|
46
46
|
}
|
|
47
|
+
// A watcher fire can run for minutes; the server answers 202 with the occurrence once it has
|
|
48
|
+
// outlived a short wait, and the result is followed here (OSK-22624).
|
|
49
|
+
const settled = await (0, triggers_1.settleFireAnswer)({
|
|
50
|
+
triggerId: args.id,
|
|
51
|
+
bin: this.config.bin,
|
|
52
|
+
answer: result,
|
|
53
|
+
note: (line) => process.stderr.write(`${line}\n`),
|
|
54
|
+
});
|
|
55
|
+
if (settled.running) {
|
|
56
|
+
if (flags.json) {
|
|
57
|
+
this.printJsonResult({ ...settled.answer, ok: true });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.log(`Fire accepted and still running (occurrence ${settled.answer.occurrenceId ?? '-'}).`);
|
|
61
|
+
this.log(`Read its result later: ${settled.command}`);
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
result = settled.result;
|
|
47
66
|
const accepted = (0, triggers_1.fireWasAccepted)(result);
|
|
48
67
|
if (flags.json) {
|
|
49
68
|
// `ok` and the exit status are one answer: a strict refusal prints `ok: false` and why,
|
|
@@ -354,6 +354,20 @@ export declare function projectDaemonToolEvents(envelopes: unknown[], namesByCal
|
|
|
354
354
|
* fails here instead of silently reverting these calls to `[tool failed]`.
|
|
355
355
|
*/
|
|
356
356
|
export declare const CODEX_DECLINED_TOOL_OUTPUTS: readonly string[];
|
|
357
|
+
/**
|
|
358
|
+
* The `tool.completed` status a typed operation receipt earns, for an end that names none
|
|
359
|
+
* (OSK-22614).
|
|
360
|
+
*
|
|
361
|
+
* A cloud run's `tool:end` has no `status` field; the daemon-routed path always sets one. So a
|
|
362
|
+
* call that FAILED on the cloud ended as `[tool completed]` here, and `--jsonl` carried the
|
|
363
|
+
* failure only inside `operationOutcome`, where a consumer reading `status` never looked. The
|
|
364
|
+
* receipt is the server's own statement of how the operation ended, so it is read the same way
|
|
365
|
+
* the daemon's status is: failed is failed, and an operation that never ran did not run.
|
|
366
|
+
*
|
|
367
|
+
* `unknown` earns nothing, because nothing is known: that call keeps whatever the end said, which is
|
|
368
|
+
* the status quo, not a claim it succeeded.
|
|
369
|
+
*/
|
|
370
|
+
export declare function toolEndStatusFromOutcome(outcome: unknown): string | undefined;
|
|
357
371
|
/**
|
|
358
372
|
* The line printed when a tool call ends, in the words its status earns.
|
|
359
373
|
*
|
|
@@ -610,6 +624,8 @@ export declare class AgenticStreamClient {
|
|
|
610
624
|
* ran (OSK-22553).
|
|
611
625
|
*/
|
|
612
626
|
private readonly deniedToolUseIds;
|
|
627
|
+
/** Calls whose denial the terminal already labelled, so the run's own end does not say it twice. */
|
|
628
|
+
private readonly deniedLabelled;
|
|
613
629
|
private readonly permissionGenerations;
|
|
614
630
|
private readonly permissionEpochs;
|
|
615
631
|
/**
|
|
@@ -840,6 +856,11 @@ export declare class AgenticStreamClient {
|
|
|
840
856
|
*/
|
|
841
857
|
private jsonlView;
|
|
842
858
|
private emit;
|
|
859
|
+
/**
|
|
860
|
+
* `[tool denied] <tool> (it did not run)`, once per call (OSK-22553). The call's own end prints the
|
|
861
|
+
* same line when the run reports one; this is the line for the runs that never do.
|
|
862
|
+
*/
|
|
863
|
+
private writeRefusalLabel;
|
|
843
864
|
/**
|
|
844
865
|
* Human-mode lines for the hand-over wait. Returns true when the event is
|
|
845
866
|
* fully rendered here; false lets the ordinary rendering continue.
|
|
@@ -11,6 +11,7 @@ exports.envelopesText = envelopesText;
|
|
|
11
11
|
exports.envelopeKey = envelopeKey;
|
|
12
12
|
exports.unseenEnvelopes = unseenEnvelopes;
|
|
13
13
|
exports.projectDaemonToolEvents = projectDaemonToolEvents;
|
|
14
|
+
exports.toolEndStatusFromOutcome = toolEndStatusFromOutcome;
|
|
14
15
|
exports.describeToolEnd = describeToolEnd;
|
|
15
16
|
exports.describePermissionDecider = describePermissionDecider;
|
|
16
17
|
exports.projectPermissionResolutions = projectPermissionResolutions;
|
|
@@ -452,6 +453,30 @@ function daemonToolEndStatus(ev) {
|
|
|
452
453
|
}
|
|
453
454
|
return status;
|
|
454
455
|
}
|
|
456
|
+
/**
|
|
457
|
+
* The `tool.completed` status a typed operation receipt earns, for an end that names none
|
|
458
|
+
* (OSK-22614).
|
|
459
|
+
*
|
|
460
|
+
* A cloud run's `tool:end` has no `status` field; the daemon-routed path always sets one. So a
|
|
461
|
+
* call that FAILED on the cloud ended as `[tool completed]` here, and `--jsonl` carried the
|
|
462
|
+
* failure only inside `operationOutcome`, where a consumer reading `status` never looked. The
|
|
463
|
+
* receipt is the server's own statement of how the operation ended, so it is read the same way
|
|
464
|
+
* the daemon's status is: failed is failed, and an operation that never ran did not run.
|
|
465
|
+
*
|
|
466
|
+
* `unknown` earns nothing, because nothing is known: that call keeps whatever the end said, which is
|
|
467
|
+
* the status quo, not a claim it succeeded.
|
|
468
|
+
*/
|
|
469
|
+
function toolEndStatusFromOutcome(outcome) {
|
|
470
|
+
const receipt = (0, data_provider_1.readToolOperationOutcome)(outcome);
|
|
471
|
+
if (!receipt)
|
|
472
|
+
return undefined;
|
|
473
|
+
if (receipt.status === 'failed')
|
|
474
|
+
return 'failed';
|
|
475
|
+
if (receipt.status === 'not_run') {
|
|
476
|
+
return receipt.reason === 'permission_denied' ? 'denied' : 'not_run';
|
|
477
|
+
}
|
|
478
|
+
return undefined;
|
|
479
|
+
}
|
|
455
480
|
/**
|
|
456
481
|
* The line printed when a tool call ends, in the words its status earns.
|
|
457
482
|
*
|
|
@@ -855,6 +880,8 @@ class AgenticStreamClient {
|
|
|
855
880
|
* ran (OSK-22553).
|
|
856
881
|
*/
|
|
857
882
|
deniedToolUseIds = new Set();
|
|
883
|
+
/** Calls whose denial the terminal already labelled, so the run's own end does not say it twice. */
|
|
884
|
+
deniedLabelled = new Set();
|
|
858
885
|
permissionGenerations = new Map();
|
|
859
886
|
permissionEpochs = new Map();
|
|
860
887
|
/**
|
|
@@ -1082,6 +1109,7 @@ class AgenticStreamClient {
|
|
|
1082
1109
|
this.pendingEnvelopes.clear();
|
|
1083
1110
|
this.browserPermissionRequests.clear();
|
|
1084
1111
|
this.deniedToolUseIds.clear();
|
|
1112
|
+
this.deniedLabelled.clear();
|
|
1085
1113
|
this.permissionGenerations.clear();
|
|
1086
1114
|
this.permissionEpochs.clear();
|
|
1087
1115
|
this.abandonConnectWait?.();
|
|
@@ -2246,6 +2274,14 @@ class AgenticStreamClient {
|
|
|
2246
2274
|
this.emit({ ...event, status: 'denied' });
|
|
2247
2275
|
return;
|
|
2248
2276
|
}
|
|
2277
|
+
// An end that names no status, with a receipt that says how the operation ended (OSK-22614).
|
|
2278
|
+
if (event.type === 'tool.completed' && (event.status === undefined || event.status === null)) {
|
|
2279
|
+
const fromReceipt = toolEndStatusFromOutcome(event.operationOutcome);
|
|
2280
|
+
if (fromReceipt) {
|
|
2281
|
+
this.emit({ ...event, status: fromReceipt });
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2249
2285
|
this.emit(event);
|
|
2250
2286
|
}
|
|
2251
2287
|
/**
|
|
@@ -2372,7 +2408,13 @@ class AgenticStreamClient {
|
|
|
2372
2408
|
this.renderedText = this.answerText();
|
|
2373
2409
|
}
|
|
2374
2410
|
else if (event.type === 'tool.completed') {
|
|
2375
|
-
|
|
2411
|
+
const endedId = typeof event.toolUseId === 'string' ? event.toolUseId : undefined;
|
|
2412
|
+
// A refusal this terminal already labelled when it was given is not said a second time.
|
|
2413
|
+
if (!(event.status === 'denied' && endedId && this.deniedLabelled.has(endedId))) {
|
|
2414
|
+
output.write(`${describeToolEnd(event.toolName, event.status)}\n`);
|
|
2415
|
+
if (event.status === 'denied' && endedId)
|
|
2416
|
+
this.deniedLabelled.add(endedId);
|
|
2417
|
+
}
|
|
2376
2418
|
this.renderedText = this.answerText();
|
|
2377
2419
|
}
|
|
2378
2420
|
else if (event.type === 'stream.gap') {
|
|
@@ -2405,6 +2447,12 @@ class AgenticStreamClient {
|
|
|
2405
2447
|
'permission.response_refused',
|
|
2406
2448
|
].includes(event.type)) {
|
|
2407
2449
|
output.write(`\n[permission] ${String(event.message ?? '')}\n`);
|
|
2450
|
+
// A refusal the server recorded is this client's own fact, and the run does not always end
|
|
2451
|
+
// the call afterwards (a cloud run may carry on with its reply), so the label waited on an
|
|
2452
|
+
// event that never came and the denial went unlabelled in half the runs (OSK-22553).
|
|
2453
|
+
if (event.type === 'permission.response_recorded' && event.decision === 'deny') {
|
|
2454
|
+
this.writeRefusalLabel(event, output);
|
|
2455
|
+
}
|
|
2408
2456
|
this.renderedText = this.answerText();
|
|
2409
2457
|
}
|
|
2410
2458
|
else if (event.type === 'permission.cancelled') {
|
|
@@ -2435,6 +2483,12 @@ class AgenticStreamClient {
|
|
|
2435
2483
|
output.write(`\n[permission] ${describePermission(event)} denied: nobody could be asked, and this run was not started with --approve-tools\n`);
|
|
2436
2484
|
this.renderedText = this.answerText();
|
|
2437
2485
|
}
|
|
2486
|
+
else if (event.type === 'permission.denied' &&
|
|
2487
|
+
event.reason !== 'noninteractive_or_not_enabled') {
|
|
2488
|
+
// A person answered `n` and the decision went out the unbound way.
|
|
2489
|
+
this.writeRefusalLabel(event, output);
|
|
2490
|
+
this.renderedText = this.answerText();
|
|
2491
|
+
}
|
|
2438
2492
|
else if (event.type === 'permission.approved' && event.auto === true) {
|
|
2439
2493
|
// Said out loud, because nobody was asked: the flag approved it, and a
|
|
2440
2494
|
// reader of this log should see which tools that covered (OSK-10323).
|
|
@@ -2446,6 +2500,18 @@ class AgenticStreamClient {
|
|
|
2446
2500
|
this.renderedText = this.answerText();
|
|
2447
2501
|
}
|
|
2448
2502
|
}
|
|
2503
|
+
/**
|
|
2504
|
+
* `[tool denied] <tool> (it did not run)`, once per call (OSK-22553). The call's own end prints the
|
|
2505
|
+
* same line when the run reports one; this is the line for the runs that never do.
|
|
2506
|
+
*/
|
|
2507
|
+
writeRefusalLabel(event, output) {
|
|
2508
|
+
const id = typeof event.toolUseId === 'string' ? event.toolUseId : undefined;
|
|
2509
|
+
if (id && this.deniedLabelled.has(id))
|
|
2510
|
+
return;
|
|
2511
|
+
if (id)
|
|
2512
|
+
this.deniedLabelled.add(id);
|
|
2513
|
+
output.write(`\n${describeToolEnd(event.toolName, 'denied')}\n`);
|
|
2514
|
+
}
|
|
2449
2515
|
/**
|
|
2450
2516
|
* Human-mode lines for the hand-over wait. Returns true when the event is
|
|
2451
2517
|
* fully rendered here; false lets the ordinary rendering continue.
|
package/dist/lib/format.d.ts
CHANGED
|
@@ -169,3 +169,8 @@ export type WhenOptions = {
|
|
|
169
169
|
* the raw ISO string; this is for text only. Unparseable input is returned as is.
|
|
170
170
|
*/
|
|
171
171
|
export declare function formatWhen(value: unknown, options?: WhenOptions): string;
|
|
172
|
+
/**
|
|
173
|
+
* A span of seconds as people say it: "45s", "7m 36s", "1h 5m". Used for how far past its time a
|
|
174
|
+
* one-shot is, where a bare second count (456) hides that it is minutes.
|
|
175
|
+
*/
|
|
176
|
+
export declare function formatElapsed(seconds: number): string;
|