@yolo-labs/yolo-cli 0.42.1 → 0.44.0

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/revision.js DELETED
@@ -1,43 +0,0 @@
1
- /**
2
- * Plan-file revision hash (Phase 8c.2).
3
- *
4
- * The lockfile records a `lastImportedRevision` for each
5
- * `(workspaceId, planId)` so re-import can detect divergence: if the
6
- * file's current canonical bytes hash to the same revision as the
7
- * lockfile entry's `lastImportedRevision`, the file hasn't changed
8
- * since the last import (no-op or version bump only). If the hash
9
- * differs, the user actually edited the file — and `import` then
10
- * compares the lockfile's `lastImportedVersion` against the DB's
11
- * current `version` to decide whether to fast-forward
12
- * (`work.update_plan`) or refuse (without `--force`).
13
- *
14
- * Hash domain: the **canonical** bytes of the plan file
15
- * (frontmatter + body, post-`canonicalizePlanFile`). Hashing the raw
16
- * input bytes would mean cosmetic re-formatting (whitespace, key
17
- * order) shows up as drift; using the canonical form means only
18
- * semantic edits register.
19
- *
20
- * Format: `sha256:<hex>` per the design doc strawman
21
- * (`docs/_ORCHESTRATION_PHASE8_PLAN_FILES_DESIGN.md` §"Plan ID
22
- * identity"). The `sha256:` prefix is intentional: it leaves room for
23
- * a future algorithm bump (e.g., `blake3:…`) without re-keying old
24
- * entries.
25
- */
26
- import { createHash } from 'node:crypto';
27
- export const REVISION_PREFIX = 'sha256:';
28
- /**
29
- * Compute the lockfile revision hash for a canonical plan-file string.
30
- * Pure: same input → same output.
31
- */
32
- export function computeRevisionHash(canonicalText) {
33
- const digest = createHash('sha256').update(canonicalText, 'utf8').digest('hex');
34
- return `${REVISION_PREFIX}${digest}`;
35
- }
36
- /**
37
- * True if `revision` is well-formed (matches the `sha256:<64-hex>`
38
- * shape this version emits). Used by lockfile-read code to flag
39
- * malformed entries up front rather than letting them propagate.
40
- */
41
- export function isWellFormedRevision(revision) {
42
- return /^sha256:[0-9a-f]{64}$/.test(revision);
43
- }
package/dist/run-list.js DELETED
@@ -1,148 +0,0 @@
1
- /**
2
- * `yolo run list` — list Plan Runs in the current workspace.
3
- *
4
- * Read companion to the run lifecycle slice. After starting/transitioning
5
- * runs, an operator wants a "what runs are in this workspace?" view
6
- * without remembering planRunIds. Maps to `work.list_runs` (added on
7
- * the server side as part of this slice).
8
- *
9
- * Two output modes:
10
- * - default (`--summary`): one row per run with planRunId, planId,
11
- * run #, executionState, operator, startedAt.
12
- * - `--json`: pretty-printed raw `runs[]` for jq pipelines.
13
- *
14
- * Filter: `--state <pending|running|paused|succeeded|failed|cancelled|superseded>`
15
- * passed as `?executionState=` query string for server-side filtering.
16
- *
17
- * Exit codes:
18
- * - 0 = success (zero runs is also success — empty list, not an error)
19
- * - 1 = http (e.g., 401 from a revoked token)
20
- * - 64 = usage (bad --state, missing env, --workspace mismatch)
21
- */
22
- import { SUBSTRATE_CLI_RUN_SCOPES, WorkClientError, authenticatedRequest, mintSubstrateToken, } from './work-client.js';
23
- import { resolveSubstrateContext } from './auth-context.js';
24
- const ALLOWED_STATES = [
25
- 'pending',
26
- 'running',
27
- 'paused',
28
- 'succeeded',
29
- 'failed',
30
- 'cancelled',
31
- 'superseded',
32
- ];
33
- // ─── Public entry ─────────────────────────────────────────────────────────
34
- export async function runRunList(options) {
35
- const env = options.env ?? process.env;
36
- const format = options.outputFormat ?? 'summary';
37
- if (options.stateFilter !== undefined && !ALLOWED_STATES.includes(options.stateFilter)) {
38
- return fail('usage', `invalid --state '${options.stateFilter}': must be one of ${ALLOWED_STATES.join(', ')}`);
39
- }
40
- const auth = resolveSubstrateContext(env);
41
- if (!auth.ok)
42
- return fail('auth', auth.message);
43
- const { sessionId, commonApiUrl, userToken } = auth.context;
44
- let mint;
45
- try {
46
- mint = await mintSubstrateToken({
47
- commonApiUrl,
48
- userToken,
49
- sessionId,
50
- scopes: SUBSTRATE_CLI_RUN_SCOPES,
51
- fetchImpl: options.fetchImpl,
52
- });
53
- }
54
- catch (err) {
55
- if (err instanceof WorkClientError) {
56
- return fail('auth', `failed to mint substrate token: ${err.message}`, { status: err.status, code: err.code });
57
- }
58
- return fail('auth', `failed to mint substrate token: ${describeError(err)}`);
59
- }
60
- if (options.workspaceFlag && options.workspaceFlag !== mint.workspaceId) {
61
- return fail('workspace_mismatch', `--workspace ${options.workspaceFlag} does not match the workspace bound to this session (${mint.workspaceId}).`);
62
- }
63
- const ctx = {
64
- commonApiUrl,
65
- delegatedToken: mint.token,
66
- fetchImpl: options.fetchImpl,
67
- };
68
- const path = options.stateFilter
69
- ? `/workspaces/${mint.workspaceId}/runs?executionState=${options.stateFilter}`
70
- : `/workspaces/${mint.workspaceId}/runs`;
71
- const response = await authenticatedRequest(ctx, path, { method: 'GET' });
72
- if (!response.ok) {
73
- const text = await safeReadText(response);
74
- return fail('http', `work.list_runs failed: HTTP ${response.status} — ${text}`, {
75
- status: response.status,
76
- });
77
- }
78
- const json = (await response.json());
79
- if (!Array.isArray(json.runs)) {
80
- return fail('http', 'work.list_runs response missing `runs` array');
81
- }
82
- return {
83
- ok: true,
84
- output: format === 'json'
85
- ? formatJson(json.runs)
86
- : formatSummary(json.runs, mint.workspaceId, options.stateFilter),
87
- runs: json.runs,
88
- workspaceId: mint.workspaceId,
89
- };
90
- }
91
- // ─── Output formatting ────────────────────────────────────────────────────
92
- /**
93
- * Header + one row per run. Columns (auto-padded):
94
- * planRunId planId #N state operator startedAt
95
- * Empty list renders "(no runs)" instead of just a header.
96
- */
97
- export function formatSummary(runs, workspaceId, stateFilter) {
98
- const lines = [];
99
- const filterTag = stateFilter ? ` (filter: ${stateFilter})` : '';
100
- lines.push(`Plan Runs in workspace ${workspaceId}${filterTag}: ${runs.length}`);
101
- if (runs.length === 0) {
102
- lines.push(' (no runs)');
103
- return lines.join('\n');
104
- }
105
- const idCol = Math.max(9, ...runs.map((r) => r.planRunId.length));
106
- const planCol = Math.max(6, ...runs.map((r) => r.planId.length));
107
- const stateCol = Math.max(5, ...runs.map((r) => r.executionState.length));
108
- const operatorCol = Math.max(8, ...runs.map((r) => (r.operatorAgentId ?? '(unbound)').length));
109
- const header = ` ${'planRunId'.padEnd(idCol)} ${'planId'.padEnd(planCol)} run# ${'state'.padEnd(stateCol)} ${'operator'.padEnd(operatorCol)} startedAt`;
110
- lines.push(header);
111
- for (const r of runs) {
112
- const id = r.planRunId.padEnd(idCol);
113
- const plan = r.planId.padEnd(planCol);
114
- const runNum = `#${r.runNumber}`.padEnd(5);
115
- const state = r.executionState.padEnd(stateCol);
116
- const operator = (r.operatorAgentId ?? '(unbound)').padEnd(operatorCol);
117
- lines.push(` ${id} ${plan} ${runNum} ${state} ${operator} ${r.startedAt}`);
118
- }
119
- return lines.join('\n');
120
- }
121
- function formatJson(runs) {
122
- return JSON.stringify(runs, null, 2);
123
- }
124
- // ─── Helpers ──────────────────────────────────────────────────────────────
125
- function fail(kind, message, detail) {
126
- return { ok: false, kind, message, detail };
127
- }
128
- function describeError(err) {
129
- return err instanceof Error ? err.message : String(err);
130
- }
131
- async function safeReadText(response) {
132
- try {
133
- return await response.text();
134
- }
135
- catch {
136
- return '<no body>';
137
- }
138
- }
139
- export function exitCodeForFailure(kind) {
140
- switch (kind) {
141
- case 'usage':
142
- case 'auth':
143
- case 'workspace_mismatch':
144
- return 64;
145
- case 'http':
146
- return 1;
147
- }
148
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Webapp URL derivation for CLI link-print.
3
- *
4
- * The substrate CLI runs in a container that has `YOLO_COMMON_API_URL`
5
- * but no first-class webapp URL var. To keep `yolo plan import` / `yolo
6
- * plan get` able to print a clickable Plan-DAG link without requiring
7
- * operators to set a new env var, derive the webapp host from the
8
- * common-api host: prod is `api.yolo.studio` → `yolo.studio`, staging
9
- * is `api-staging.yolo.studio` → `staging.yolo.studio`. Operators can
10
- * override via `YOLO_WEBAPP_URL` for local dev / custom deployments.
11
- *
12
- * When derivation fails (an unrecognized API URL shape, e.g. a raw
13
- * localhost port), `deriveWebappUrl` returns null and the caller is
14
- * expected to skip the URL line — printing a bogus URL would be worse
15
- * than printing nothing.
16
- */
17
- export function deriveWebappUrl(input) {
18
- if (input.webappUrlOverride && input.webappUrlOverride.length > 0) {
19
- return stripTrailingSlash(input.webappUrlOverride);
20
- }
21
- let parsed;
22
- try {
23
- parsed = new URL(input.commonApiUrl);
24
- }
25
- catch {
26
- return null;
27
- }
28
- const host = parsed.hostname;
29
- // Recognized prod shape: api.<rest> → <rest>
30
- if (host.startsWith('api.')) {
31
- return `${parsed.protocol}//${host.slice('api.'.length)}`;
32
- }
33
- // Recognized env-suffixed shape: api-<env>.<rest> → <env>.<rest>
34
- const envMatch = /^api-([^.]+)\.(.+)$/.exec(host);
35
- if (envMatch) {
36
- return `${parsed.protocol}//${envMatch[1]}.${envMatch[2]}`;
37
- }
38
- // Unknown shape (raw localhost, IPs, custom hosts). Don't guess.
39
- return null;
40
- }
41
- /**
42
- * Convenience for the CLI flows: derive the webapp URL from
43
- * `process.env`-style inputs and format the Plan-DAG path. Returns
44
- * null when derivation fails so the caller can omit the URL line
45
- * entirely.
46
- */
47
- export function planDagUrl(env, workspaceId, planId) {
48
- const commonApiUrl = env.YOLO_COMMON_API_URL || env.YOLO_API_URL;
49
- if (!commonApiUrl)
50
- return null;
51
- const base = deriveWebappUrl({
52
- commonApiUrl,
53
- webappUrlOverride: env.YOLO_WEBAPP_URL,
54
- });
55
- if (!base)
56
- return null;
57
- return `${base}/workspaces/${workspaceId}/plans/${planId}`;
58
- }
59
- function stripTrailingSlash(s) {
60
- return s.endsWith('/') ? s.slice(0, -1) : s;
61
- }