@yolo-labs/yolo-cli 0.41.0 → 0.42.1

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.
@@ -1,133 +0,0 @@
1
- /**
2
- * `yolo run pause / resume / cancel <runId>` — lifecycle transitions.
3
- *
4
- * The three verbs share a single runner because the routes share a
5
- * single transition handler on the server (common-api/src/routes/
6
- * workspaces.ts:transitionPlanRunForUser). They differ only in
7
- * target state, valid source states, and whether they accept a
8
- * `--reason`.
9
- *
10
- * Auth model: hits the user-facing route at
11
- * `/v1/workspaces/:id/runs/:planRunId/{verb}` via X-Internal-Auth +
12
- * X-User-Id (the substrate CLI is by definition invoked by the
13
- * workspace owner — operating as them is the right default). The
14
- * user route checks workspace ownership only and skips R4 operator
15
- * binding, so this works regardless of which agent (if any) is
16
- * bound to the run.
17
- *
18
- * Why not the MCP path: that path's R4 binding makes sense for
19
- * agent-to-agent calls (claude pausing its own run) but produces
20
- * 403 NOT_AUTHORIZED whenever the user wants to cancel a run owned
21
- * by a different agent or by the webapp launcher. Forcing the user
22
- * to know which side of that fence they're on is bad UX. The CLI
23
- * decides automatically.
24
- *
25
- * Errors map to exit codes via the CLI wrapper:
26
- * - 0 = success
27
- * - 1 = http (404, 409 INVALID_STATE, 5xx)
28
- * - 64 = usage (bad runId, missing env trio, --workspace mismatch,
29
- * reason too long pre-network, bad target verb)
30
- */
31
- import { SUBSTRATE_CLI_RUN_SCOPES, WorkClientError, mintSubstrateToken, userRouteRequest, } from './work-client.js';
32
- import { resolveSubstrateContext } from './auth-context.js';
33
- // ─── Public entry ─────────────────────────────────────────────────────────
34
- const PLAN_RUN_ID_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,191}$/;
35
- const REASON_MAX_LEN = 1024;
36
- export async function runRunLifecycle(options) {
37
- const env = options.env ?? process.env;
38
- const format = options.outputFormat ?? 'summary';
39
- if (options.verb !== 'pause' && options.verb !== 'resume' && options.verb !== 'cancel') {
40
- return fail('usage', `unknown verb '${options.verb}': must be pause, resume, or cancel`);
41
- }
42
- if (!PLAN_RUN_ID_REGEX.test(options.planRunId)) {
43
- return fail('usage', `invalid planRunId '${options.planRunId}': must match /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,191}$/`);
44
- }
45
- if (options.reason !== undefined) {
46
- if (typeof options.reason !== 'string' || options.reason.length > REASON_MAX_LEN) {
47
- return fail('usage', `--reason must be a string of at most ${REASON_MAX_LEN} chars`);
48
- }
49
- if (options.verb === 'resume') {
50
- return fail('usage', '--reason is not accepted by `run resume`');
51
- }
52
- }
53
- const auth = resolveSubstrateContext(env);
54
- if (!auth.ok)
55
- return fail('auth', auth.message);
56
- const { sessionId, commonApiUrl, userToken } = auth.context;
57
- let mint;
58
- try {
59
- mint = await mintSubstrateToken({
60
- commonApiUrl,
61
- userToken,
62
- sessionId,
63
- scopes: SUBSTRATE_CLI_RUN_SCOPES,
64
- fetchImpl: options.fetchImpl,
65
- });
66
- }
67
- catch (err) {
68
- if (err instanceof WorkClientError) {
69
- return fail('auth', `failed to mint substrate token: ${err.message}`, { status: err.status, code: err.code });
70
- }
71
- return fail('auth', `failed to mint substrate token: ${describeError(err)}`);
72
- }
73
- if (options.workspaceFlag && options.workspaceFlag !== mint.workspaceId) {
74
- return fail('workspace_mismatch', `--workspace ${options.workspaceFlag} does not match the workspace bound to this session (${mint.workspaceId}).`);
75
- }
76
- const body = {};
77
- if (options.reason !== undefined && options.verb !== 'resume') {
78
- body.reason = options.reason;
79
- }
80
- const path = `/workspaces/${mint.workspaceId}/runs/${options.planRunId}/${options.verb}`;
81
- const response = await userRouteRequest({
82
- commonApiUrl,
83
- userToken,
84
- fetchImpl: options.fetchImpl,
85
- }, path, { method: 'POST', jsonBody: body });
86
- if (!response.ok) {
87
- const text = await safeReadText(response);
88
- return fail('http', `work.${options.verb}_run failed: HTTP ${response.status} — ${text}`, { status: response.status });
89
- }
90
- const json = (await response.json());
91
- if (typeof json.planRunId !== 'string' || typeof json.executionState !== 'string') {
92
- return fail('http', `work.${options.verb}_run response missing planRunId or executionState`);
93
- }
94
- return {
95
- ok: true,
96
- output: format === 'json' ? formatJson(json) : formatSummary(options.verb, json),
97
- response: json,
98
- workspaceId: mint.workspaceId,
99
- };
100
- }
101
- // ─── Output formatting ────────────────────────────────────────────────────
102
- export function formatSummary(verb, response) {
103
- const past = verb === 'pause' ? 'paused' : verb === 'resume' ? 'resumed' : 'cancelled';
104
- return `OK: ${past} run ${response.planRunId} (executionState=${response.executionState})`;
105
- }
106
- function formatJson(response) {
107
- return JSON.stringify(response, null, 2);
108
- }
109
- // ─── Helpers ──────────────────────────────────────────────────────────────
110
- function fail(kind, message, detail) {
111
- return { ok: false, kind, message, detail };
112
- }
113
- function describeError(err) {
114
- return err instanceof Error ? err.message : String(err);
115
- }
116
- async function safeReadText(response) {
117
- try {
118
- return await response.text();
119
- }
120
- catch {
121
- return '<no body>';
122
- }
123
- }
124
- export function exitCodeForFailure(kind) {
125
- switch (kind) {
126
- case 'usage':
127
- case 'auth':
128
- case 'workspace_mismatch':
129
- return 64;
130
- case 'http':
131
- return 1;
132
- }
133
- }
package/dist/run-start.js DELETED
@@ -1,110 +0,0 @@
1
- /**
2
- * `yolo run start <planId>` — bootstrap a Plan Run via work.start_run.
3
- *
4
- * Mints a session-bound delegated token (work.start_run scope) and
5
- * POSTs to `/internal/work/workspaces/<wsId>/runs` with the planId
6
- * and (optional) inputs. The route handler (common-api/src/routes/
7
- * work.ts) binds `operatorAgentId: ctx.agentId` — so a Run started
8
- * via this verb has `operatorAgentId === 'substrate-cli'` and only
9
- * the substrate CLI can pause/resume/cancel it via MCP.
10
- *
11
- * Inputs: passed as a JSON object literal via `--inputs '<json>'`.
12
- * If absent, defaults to `{}` (the route accepts that and lets Plan
13
- * input validation reject if any inputs were declared as required).
14
- *
15
- * Errors map to exit codes via the CLI wrapper:
16
- * - 0 = success
17
- * - 1 = http (plan not found, plan not active, validation failure)
18
- * - 64 = usage (bad planId, malformed --inputs JSON, missing env
19
- * trio, --workspace mismatch)
20
- */
21
- import { SUBSTRATE_CLI_RUN_SCOPES, WorkClientError, authenticatedRequest, mintSubstrateToken, } from './work-client.js';
22
- import { resolveSubstrateContext } from './auth-context.js';
23
- // ─── Public entry ─────────────────────────────────────────────────────────
24
- const PLAN_ID_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/;
25
- export async function runRunStart(options) {
26
- const env = options.env ?? process.env;
27
- const format = options.outputFormat ?? 'summary';
28
- if (!PLAN_ID_REGEX.test(options.planId)) {
29
- return fail('usage', `invalid planId '${options.planId}': must match /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/`);
30
- }
31
- const auth = resolveSubstrateContext(env);
32
- if (!auth.ok)
33
- return fail('auth', auth.message);
34
- const { sessionId, commonApiUrl, userToken } = auth.context;
35
- let mint;
36
- try {
37
- mint = await mintSubstrateToken({
38
- commonApiUrl,
39
- userToken,
40
- sessionId,
41
- scopes: SUBSTRATE_CLI_RUN_SCOPES,
42
- fetchImpl: options.fetchImpl,
43
- });
44
- }
45
- catch (err) {
46
- if (err instanceof WorkClientError) {
47
- return fail('auth', `failed to mint substrate token: ${err.message}`, { status: err.status, code: err.code });
48
- }
49
- return fail('auth', `failed to mint substrate token: ${describeError(err)}`);
50
- }
51
- if (options.workspaceFlag && options.workspaceFlag !== mint.workspaceId) {
52
- return fail('workspace_mismatch', `--workspace ${options.workspaceFlag} does not match the workspace bound to this session (${mint.workspaceId}).`);
53
- }
54
- const ctx = {
55
- commonApiUrl,
56
- delegatedToken: mint.token,
57
- fetchImpl: options.fetchImpl,
58
- };
59
- const body = { planId: options.planId };
60
- if (options.inputs !== undefined)
61
- body.inputs = options.inputs;
62
- const response = await authenticatedRequest(ctx, `/workspaces/${mint.workspaceId}/runs`, { method: 'POST', jsonBody: body });
63
- if (!response.ok) {
64
- const text = await safeReadText(response);
65
- return fail('http', `work.start_run failed: HTTP ${response.status} — ${text}`, { status: response.status });
66
- }
67
- const json = (await response.json());
68
- if (typeof json.planRunId !== 'string' || !json.planRunId) {
69
- return fail('http', 'work.start_run response missing planRunId');
70
- }
71
- return {
72
- ok: true,
73
- output: format === 'json' ? formatJson(json) : formatSummary(json, options.planId),
74
- response: json,
75
- workspaceId: mint.workspaceId,
76
- };
77
- }
78
- // ─── Output formatting ────────────────────────────────────────────────────
79
- export function formatSummary(response, planId) {
80
- const operatorTag = response.operatorAgentId ? `operator=${response.operatorAgentId}` : 'operator=(unbound)';
81
- return `OK: started run ${response.planRunId} for plan ${planId} (run #${response.runNumber}, executionState=${response.executionState}, ${operatorTag})`;
82
- }
83
- function formatJson(response) {
84
- return JSON.stringify(response, null, 2);
85
- }
86
- // ─── Helpers ──────────────────────────────────────────────────────────────
87
- function fail(kind, message, detail) {
88
- return { ok: false, kind, message, detail };
89
- }
90
- function describeError(err) {
91
- return err instanceof Error ? err.message : String(err);
92
- }
93
- async function safeReadText(response) {
94
- try {
95
- return await response.text();
96
- }
97
- catch {
98
- return '<no body>';
99
- }
100
- }
101
- export function exitCodeForFailure(kind) {
102
- switch (kind) {
103
- case 'usage':
104
- case 'auth':
105
- case 'workspace_mismatch':
106
- return 64;
107
- case 'http':
108
- return 1;
109
- }
110
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * `yolo run transfer <runId> --to <agentId>` — change a Run's bound
3
- * Operator. The handoff verb that closes the loop on the lifecycle
4
- * slice's operator-binding implication.
5
- *
6
- * Natural use case: `yolo run start <planId>` makes substrate-cli
7
- * the Operator; `yolo run transfer <runId> --to claude` hands the
8
- * Run off to claude/codex for actual execution. The route's R4
9
- * matrix permits self-transfer (current Operator → new agent),
10
- * claim-user-driven (taking over a Run with operatorAgentId=null),
11
- * and force-transfer of an unresponsive Operator.
12
- *
13
- * Target validation: the route enforces `isValidOperatorTarget` —
14
- * target must be in OPERATOR_TIER_AGENT_IDS (claude, codex) or
15
- * null (user-driven). Substrate-cli is NOT Operator-tier, so
16
- * `--to substrate-cli` always fails at the route layer with 403
17
- * NOT_AUTHORIZED + reason=invalid_transfer_target.
18
- *
19
- * Errors map to exit codes via the CLI wrapper:
20
- * - 0 = success
21
- * - 1 = http (404, 403 NOT_AUTHORIZED, 409 INVALID_STATE, 5xx)
22
- * - 64 = usage (bad runId, missing env trio, --workspace mismatch,
23
- * --to + --user-driven mutex violation, missing target)
24
- */
25
- import { SUBSTRATE_CLI_RUN_SCOPES, WorkClientError, authenticatedRequest, mintSubstrateToken, } from './work-client.js';
26
- import { resolveSubstrateContext } from './auth-context.js';
27
- // ─── Public entry ─────────────────────────────────────────────────────────
28
- const PLAN_RUN_ID_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,191}$/;
29
- const AGENT_ID_MAX_LEN = 128;
30
- export async function runRunTransfer(options) {
31
- const env = options.env ?? process.env;
32
- const format = options.outputFormat ?? 'summary';
33
- if (!PLAN_RUN_ID_REGEX.test(options.planRunId)) {
34
- return fail('usage', `invalid planRunId '${options.planRunId}': must match /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,191}$/`);
35
- }
36
- // Target must be a non-empty string ≤128 chars or explicit null.
37
- // Mirrors the route's pre-store check so we fail fast without a
38
- // network round-trip.
39
- if (options.newOperatorAgentId !== null &&
40
- (typeof options.newOperatorAgentId !== 'string' ||
41
- options.newOperatorAgentId.length === 0 ||
42
- options.newOperatorAgentId.length > AGENT_ID_MAX_LEN)) {
43
- return fail('usage', `newOperatorAgentId must be a non-empty string ≤${AGENT_ID_MAX_LEN} chars or null`);
44
- }
45
- const auth = resolveSubstrateContext(env);
46
- if (!auth.ok)
47
- return fail('auth', auth.message);
48
- const { sessionId, commonApiUrl, userToken } = auth.context;
49
- let mint;
50
- try {
51
- mint = await mintSubstrateToken({
52
- commonApiUrl,
53
- userToken,
54
- sessionId,
55
- scopes: SUBSTRATE_CLI_RUN_SCOPES,
56
- fetchImpl: options.fetchImpl,
57
- });
58
- }
59
- catch (err) {
60
- if (err instanceof WorkClientError) {
61
- return fail('auth', `failed to mint substrate token: ${err.message}`, { status: err.status, code: err.code });
62
- }
63
- return fail('auth', `failed to mint substrate token: ${describeError(err)}`);
64
- }
65
- if (options.workspaceFlag && options.workspaceFlag !== mint.workspaceId) {
66
- return fail('workspace_mismatch', `--workspace ${options.workspaceFlag} does not match the workspace bound to this session (${mint.workspaceId}).`);
67
- }
68
- const ctx = {
69
- commonApiUrl,
70
- delegatedToken: mint.token,
71
- fetchImpl: options.fetchImpl,
72
- };
73
- const response = await authenticatedRequest(ctx, `/workspaces/${mint.workspaceId}/runs/${options.planRunId}/operator/transfer`, { method: 'POST', jsonBody: { newOperatorAgentId: options.newOperatorAgentId } });
74
- if (!response.ok) {
75
- const text = await safeReadText(response);
76
- return fail('http', `work.transfer_run_operator failed: HTTP ${response.status} — ${text}`, {
77
- status: response.status,
78
- });
79
- }
80
- const json = (await response.json());
81
- if (typeof json.planRunId !== 'string') {
82
- return fail('http', 'work.transfer_run_operator response missing planRunId');
83
- }
84
- return {
85
- ok: true,
86
- output: format === 'json' ? formatJson(json) : formatSummary(json),
87
- response: json,
88
- workspaceId: mint.workspaceId,
89
- };
90
- }
91
- // ─── Output formatting ────────────────────────────────────────────────────
92
- export function formatSummary(response) {
93
- const target = response.operatorAgentId === null
94
- ? 'user-driven (primaryOperator=null)'
95
- : response.operatorAgentId;
96
- // operatorCount surfaces the size of the additive operators[];
97
- // the legacy operatorHistoryLength was removed in item 16.
98
- const count = response.operatorCount ?? 0;
99
- return `OK: transferred run ${response.planRunId} primary to ${target} (operatorCount=${count})`;
100
- }
101
- function formatJson(response) {
102
- return JSON.stringify(response, null, 2);
103
- }
104
- // ─── Helpers ──────────────────────────────────────────────────────────────
105
- function fail(kind, message, detail) {
106
- return { ok: false, kind, message, detail };
107
- }
108
- function describeError(err) {
109
- return err instanceof Error ? err.message : String(err);
110
- }
111
- async function safeReadText(response) {
112
- try {
113
- return await response.text();
114
- }
115
- catch {
116
- return '<no body>';
117
- }
118
- }
119
- export function exitCodeForFailure(kind) {
120
- switch (kind) {
121
- case 'usage':
122
- case 'auth':
123
- case 'workspace_mismatch':
124
- return 64;
125
- case 'http':
126
- return 1;
127
- }
128
- }