@yolo-labs/yolo-cli 0.39.0 → 0.41.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.
@@ -7,6 +7,8 @@
7
7
  * yolo deploy status [--json]
8
8
  * yolo deploy logs [--tail] [--since <dur>] [--json]
9
9
  * yolo deploy rollback [releaseId] [--json]
10
+ * yolo deploy set-parent <id|slug> [--json] ← re-parent the linked project
11
+ * yolo deploy set-parent --none [--json] ← detach it to a root
10
12
  * (yolo deploy db query — Phase 2, deliberately NOT wired)
11
13
  *
12
14
  * Output contract (spec §4/§5):
@@ -33,7 +35,7 @@ function defaultStatPath(p) {
33
35
  }
34
36
  }
35
37
  import { runDeployShip, exitCodeForFailure, formatShipSuccess, formatPending, formatFail, } from './deploy-ship.js';
36
- import { resolveDeployContext, createProject, getProjectStatus, listProjects, rollbackProject, unpublishProject, republishProject, renameProject, addAlias, removeAlias, setRedirect, deleteProject, cloneProject, getLogs, pollTail, queryD1, } from './deploy-client.js';
38
+ import { resolveDeployContext, createProject, getProjectStatus, listProjects, rollbackProject, unpublishProject, republishProject, renameProject, setProjectParent, addAlias, removeAlias, setRedirect, deleteProject, cloneProject, getLogs, pollTail, queryD1, } from './deploy-client.js';
37
39
  import { readDeployConfig, writeDeployConfig } from './deploy-config.js';
38
40
  import { adaptWrangler, detectProjectShape } from './deploy-detect.js';
39
41
  import { collectNodeBuiltinsFromText } from './deploy-bundle.js';
@@ -55,6 +57,8 @@ const USAGE = [
55
57
  ' yolo deploy alias <slug> [--json]',
56
58
  ' yolo deploy alias rm <slug> [--json]',
57
59
  ' yolo deploy redirect <slug> <url> [--json]',
60
+ ' yolo deploy set-parent <id|slug> [--json]',
61
+ ' yolo deploy set-parent --none [--json]',
58
62
  ' yolo deploy delete [--confirm <slug>] [--json]',
59
63
  ' yolo deploy clone [--name <name>] [--slug <slug>] [--json]',
60
64
  ' yolo deploy db query "<sql>" [--json]',
@@ -94,6 +98,8 @@ export async function runDeployCmd(args, deps = {}) {
94
98
  return runAliasCmd(args.slice(1), deps, io);
95
99
  if (sub === 'redirect')
96
100
  return runRedirectCmd(args.slice(1), deps, io);
101
+ if (sub === 'set-parent')
102
+ return runSetParentCmd(args.slice(1), deps, io);
97
103
  if (sub === 'delete')
98
104
  return runDeleteCmd(args.slice(1), deps, io);
99
105
  if (sub === 'clone')
@@ -1435,6 +1441,133 @@ async function runRedirectCmd(args, deps, io) {
1435
1441
  io.out(`OK: '${parsed.slug}' now 308 → ${parsed.url}\n`);
1436
1442
  return 0;
1437
1443
  }
1444
+ // ─── set-parent ─────────────────────────────────────────────────────────────
1445
+ //
1446
+ // Nesting S5 — re-parent the LINKED project (the rename/alias/redirect family:
1447
+ // restructure an existing project, never create one). `--none` detaches it back
1448
+ // to a root. The server owns every rule (ownership, depth, child count, project
1449
+ // state) and its refusal reason passes through verbatim as the failure kind.
1450
+ const SET_PARENT_USAGE = 'Usage: yolo deploy set-parent <id|slug> [--json]\n yolo deploy set-parent --none [--json]\n';
1451
+ export function parseSetParentArgs(args) {
1452
+ let parent;
1453
+ let detach = false;
1454
+ let jsonOutput = false;
1455
+ for (let i = 0; i < args.length; i++) {
1456
+ const a = args[i];
1457
+ if (a === '--json') {
1458
+ jsonOutput = true;
1459
+ }
1460
+ else if (a === '--none') {
1461
+ detach = true;
1462
+ }
1463
+ else if (a.startsWith('--')) {
1464
+ return { ok: false, message: `unknown option: ${a}` };
1465
+ }
1466
+ else if (parent === undefined) {
1467
+ parent = a;
1468
+ }
1469
+ else {
1470
+ return { ok: false, message: `unexpected positional argument: ${a}` };
1471
+ }
1472
+ }
1473
+ if (detach && parent !== undefined) {
1474
+ // Either/or: honoring one would silently discard the other, contradictory intent.
1475
+ return { ok: false, message: 'pass either a parent <id|slug> or --none, not both' };
1476
+ }
1477
+ if (!detach && (parent === undefined || parent.trim() === '')) {
1478
+ return {
1479
+ ok: false,
1480
+ message: 'a parent is required: yolo deploy set-parent <id|slug> (or --none to detach)',
1481
+ };
1482
+ }
1483
+ return { ok: true, parent, detach, jsonOutput };
1484
+ }
1485
+ async function runSetParentCmd(args, deps, io) {
1486
+ // `--json` must be honoured on EVERY failure path, not only the ones after a
1487
+ // successful parse — automation parses stdout and treats stderr as
1488
+ // diagnostics. Read the flag straight from argv here, because a parse
1489
+ // FAILURE has no parsed result to read it from.
1490
+ const wantsJson = args.includes('--json');
1491
+ const parsed = parseSetParentArgs(args);
1492
+ if (!parsed.ok) {
1493
+ if (wantsJson)
1494
+ io.out(`${formatJsonResult({ status: 'failed', message: parsed.message })}\n`);
1495
+ else
1496
+ io.err(`yolo deploy set-parent: ${parsed.message}\n${SET_PARENT_USAGE}`);
1497
+ return 64;
1498
+ }
1499
+ const linked = requireLink(deps, io, { silent: parsed.jsonOutput });
1500
+ if (!linked.ok) {
1501
+ if (parsed.jsonOutput)
1502
+ io.out(`${formatJsonResult(linked.failure)}\n`);
1503
+ return linked.exitCode;
1504
+ }
1505
+ const auth = resolveAuth(deps);
1506
+ if (!auth.ok) {
1507
+ const failure = { kind: 'auth', message: auth.message };
1508
+ if (parsed.jsonOutput)
1509
+ io.out(`${formatJsonResult(failure)}\n`);
1510
+ else
1511
+ io.err(`${formatFail(failure)}\n`);
1512
+ return 78;
1513
+ }
1514
+ // Resolve the new parent when given as a SLUG, exactly like `init --parent`:
1515
+ // SLUG FIRST, then id. A slug may legally be 24 hex characters, so a shape
1516
+ // test alone is ambiguous; the slug lookup resolves both forms with one call
1517
+ // and gives slugs precedence — the form a human typed on purpose.
1518
+ let resolvedParentId = null;
1519
+ if (!parsed.detach) {
1520
+ let target = parsed.parent;
1521
+ const lookup = await findOwnedProjectBySlug(deps, auth.context, target);
1522
+ if (!lookup.ok) {
1523
+ // A list failure (auth/network) is NOT "not found" — surface the real
1524
+ // error and its exit code, matching `init --parent`.
1525
+ if (parsed.jsonOutput)
1526
+ io.out(`${formatJsonResult(lookup)}\n`);
1527
+ else
1528
+ io.err(`${formatFail(lookup)}\n`);
1529
+ return exitCodeForFailure(lookup.kind);
1530
+ }
1531
+ const bySlug = lookup.project ? resolveProjectId(lookup.project) : undefined;
1532
+ if (bySlug) {
1533
+ target = bySlug;
1534
+ }
1535
+ else if (!/^[a-f0-9]{24}$/i.test(target)) {
1536
+ const message = `no project of yours matches parent '${target}' — pass its slug or 24-hex id`;
1537
+ if (parsed.jsonOutput)
1538
+ io.out(`${formatJsonResult({ status: 'failed', message })}\n`);
1539
+ else
1540
+ io.err(`FAIL: ${message}\n`);
1541
+ return 1;
1542
+ }
1543
+ // Else: not a slug of ours, but id-shaped — pass through and let the
1544
+ // server's ownership-asserted read be the authority.
1545
+ resolvedParentId = target;
1546
+ }
1547
+ const setParent = deps.setProjectParentImpl ?? setProjectParent;
1548
+ const result = await setParent(auth.context, linked.projectId, resolvedParentId);
1549
+ if (!result.ok) {
1550
+ // JSON mode keeps stderr EMPTY — automation treats it as diagnostics and
1551
+ // the machine-readable result is the single stdout object.
1552
+ if (parsed.jsonOutput)
1553
+ io.out(`${formatJsonResult(result)}\n`);
1554
+ else
1555
+ io.err(`${formatFail(result)}\n`);
1556
+ return exitCodeForFailure(result.kind);
1557
+ }
1558
+ if (parsed.jsonOutput) {
1559
+ io.out(`${JSON.stringify(result.value, null, 2)}\n`);
1560
+ return 0;
1561
+ }
1562
+ const name = linked.slug ?? linked.projectId;
1563
+ if (parsed.detach) {
1564
+ io.out(`OK: detached ${name} — it is now a root project\n`);
1565
+ }
1566
+ else {
1567
+ io.out(`OK: ${name} is now nested under ${parsed.parent}\n`);
1568
+ }
1569
+ return 0;
1570
+ }
1438
1571
  export function parseDeleteArgs(args) {
1439
1572
  let confirmSlug;
1440
1573
  let jsonOutput = false;
@@ -1673,22 +1806,32 @@ function parseFlagOnlyArgs(args, _name) {
1673
1806
  }
1674
1807
  return { ok: true, jsonOutput };
1675
1808
  }
1676
- function requireLink(deps, io) {
1809
+ /**
1810
+ * `opts.silent` suppresses the stderr write and hands the failure back instead,
1811
+ * so a `--json` caller can emit it on stdout and keep stderr EMPTY (the
1812
+ * stream-split contract). Defaults to the pre-existing write-to-stderr
1813
+ * behaviour, so every other subcommand is unchanged.
1814
+ */
1815
+ function requireLink(deps, io, opts = {}) {
1677
1816
  const cwd = deps.cwd ?? process.cwd();
1678
1817
  const readConfig = deps.readDeployConfigImpl ?? readDeployConfig;
1679
1818
  const readResult = readConfig(cwd);
1680
1819
  if (!readResult.ok) {
1681
- io.err(`${formatFail({ kind: readResult.kind, message: readResult.message })}\n`);
1682
- return { ok: false, exitCode: exitCodeForFailure(readResult.kind) };
1820
+ const failure = { kind: readResult.kind, message: readResult.message };
1821
+ if (!opts.silent)
1822
+ io.err(`${formatFail(failure)}\n`);
1823
+ return { ok: false, exitCode: exitCodeForFailure(readResult.kind), failure };
1683
1824
  }
1684
1825
  const config = readResult.config;
1685
1826
  if (!config?.projectId) {
1686
- io.err(`${formatFail({
1827
+ const failure = {
1687
1828
  kind: 'not-linked',
1688
1829
  message: 'this directory is not linked to a hosting project (.yolo/deploy.json missing or has no projectId)',
1689
1830
  hint: "run 'yolo deploy init' to create or link a hosting project",
1690
- })}\n`);
1691
- return { ok: false, exitCode: exitCodeForFailure('not-linked') };
1831
+ };
1832
+ if (!opts.silent)
1833
+ io.err(`${formatFail(failure)}\n`);
1834
+ return { ok: false, exitCode: exitCodeForFailure('not-linked'), failure };
1692
1835
  }
1693
1836
  return { ok: true, projectId: config.projectId, slug: config.slug };
1694
1837
  }
@@ -293,6 +293,22 @@ export async function queryD1(ctx, projectId, sql, options = {}) {
293
293
  export async function renameProject(ctx, projectId, request) {
294
294
  return jsonLeg(ctx, `/deploy/projects/${enc(projectId)}/slug`, { method: 'PUT', jsonBody: request });
295
295
  }
296
+ /**
297
+ * PUT /v1/deploy/projects/:id/parent — re-parent the project (nesting S5).
298
+ *
299
+ * `null` DETACHES it to a root. The CLI only passes the id through: the server
300
+ * resolves the parent via an ownership-asserted read and enforces depth,
301
+ * child-count and project-state, so its 4xx `reason` is the authority
302
+ * (`project-nesting-disabled`, `project-nesting-too-deep`,
303
+ * `project-has-children`, `project-not-active`, `not-published`,
304
+ * `project-busy`, `project-not-found`).
305
+ */
306
+ export async function setProjectParent(ctx, projectId, parentProjectId) {
307
+ return jsonLeg(ctx, `/deploy/projects/${enc(projectId)}/parent`, {
308
+ method: 'PUT',
309
+ jsonBody: { parentProjectId },
310
+ });
311
+ }
296
312
  /** POST /v1/deploy/projects/:id/aliases — add an alias hostname (slug). */
297
313
  export async function addAlias(ctx, projectId, slug) {
298
314
  return jsonLeg(ctx, `/deploy/projects/${enc(projectId)}/aliases`, { method: 'POST', jsonBody: { slug } });
@@ -296,6 +296,11 @@ export async function runDeployShip(options) {
296
296
  const bootCheck = parseBootCheck(finalized.value.bootCheck);
297
297
  if (bootCheck)
298
298
  progress(`deploy: warn — deployed Worker failed to boot (HTTP ${bootCheck.status})`);
299
+ const pageCheck = parsePageCheck(finalized.value.pageCheck);
300
+ if (pageCheckHasProblems(pageCheck)) {
301
+ for (const line of pageCheckLines(pageCheck))
302
+ progress(line);
303
+ }
299
304
  return {
300
305
  ok: true,
301
306
  dryRun: false,
@@ -304,6 +309,7 @@ export async function runDeployShip(options) {
304
309
  releaseId: finalized.value.releaseId,
305
310
  url: finalized.value.url,
306
311
  ...(bootCheck ? { bootCheck } : {}),
312
+ ...(pageCheck ? { pageCheck } : {}),
307
313
  };
308
314
  }
309
315
  /**
@@ -328,6 +334,11 @@ async function resumeStagedShip(ctx, resume, io) {
328
334
  const bootCheck = parseBootCheck(finalized.value.bootCheck);
329
335
  if (bootCheck)
330
336
  progress(`deploy: warn — deployed Worker failed to boot (HTTP ${bootCheck.status})`);
337
+ const pageCheck = parsePageCheck(finalized.value.pageCheck);
338
+ if (pageCheckHasProblems(pageCheck)) {
339
+ for (const line of pageCheckLines(pageCheck))
340
+ progress(line);
341
+ }
331
342
  return {
332
343
  ok: true,
333
344
  dryRun: false,
@@ -343,6 +354,10 @@ async function resumeStagedShip(ctx, resume, io) {
343
354
  releaseId: finalized.value.releaseId,
344
355
  url: finalized.value.url,
345
356
  ...(bootCheck ? { bootCheck } : {}),
357
+ // Must be on the RESULT, not only the progress line: under --json the
358
+ // warning goes to stderr and the structured verdict + samples would
359
+ // otherwise be lost entirely for a resumed (approval-parked) ship.
360
+ ...(pageCheck ? { pageCheck } : {}),
346
361
  };
347
362
  }
348
363
  // Still parked: the grant hasn't landed yet (approval-pending), or the
@@ -425,6 +440,71 @@ function parseBootCheck(raw) {
425
440
  return undefined;
426
441
  return { status: r.status, detail: r.detail };
427
442
  }
443
+ /**
444
+ * True when the page check found something worth a warning line. Mirrors
445
+ * `pageCheckHasProblems` in common-api — a 5xx document is a failure in its own
446
+ * right, not just a source of console noise.
447
+ *
448
+ * Takes `undefined` deliberately: absence means NOT CHECKED, so it returns
449
+ * false and the CLI stays silent rather than printing a reassuring line.
450
+ */
451
+ function pageCheckHasProblems(p) {
452
+ if (!p)
453
+ return false;
454
+ return p.consoleErrors > 0 || p.failedRequests > 0 || (!!p.httpStatus && p.httpStatus >= 500);
455
+ }
456
+ /**
457
+ * The warn line PLUS the captured samples.
458
+ *
459
+ * Counts alone are not actionable: "23 console errors" does not tell anyone the
460
+ * allow-list is missing `x-cart-token`, and finalize cannot be safely re-run
461
+ * just to get `--json`, so whatever the human path omits here is lost for good.
462
+ * The samples are already bounded and truncated server-side.
463
+ */
464
+ function pageCheckLines(p) {
465
+ const lines = [`deploy: warn — ${describeCliPageCheck(p)}`];
466
+ for (const sample of p.samples ?? [])
467
+ lines.push(`deploy: ${sample}`);
468
+ return lines;
469
+ }
470
+ /** One-line human summary for the warn output. */
471
+ function describeCliPageCheck(p) {
472
+ const parts = [];
473
+ if (p.httpStatus && p.httpStatus >= 500)
474
+ parts.push(`the page returned HTTP ${p.httpStatus}`);
475
+ if (p.consoleErrors > 0)
476
+ parts.push(`${p.consoleErrors} console error(s)`);
477
+ if (p.failedRequests > 0)
478
+ parts.push(`${p.failedRequests} failed request(s)`);
479
+ // Name the URL actually checked. A clean-or-dirty verdict about the PREVIEW
480
+ // origin must not be read as one about production — origin-exact CORS is
481
+ // exactly the failure class this check exists for.
482
+ const where = p.url ? ` on ${p.url}` : '';
483
+ return `page check${where}: ${parts.join(', ')}`;
484
+ }
485
+ /**
486
+ * Narrow the backend's optional `pageCheck` envelope; ignore anything malformed.
487
+ *
488
+ * A malformed payload narrows to `undefined`, which the caller renders as "not
489
+ * checked" — the safe direction. Inventing zeros instead would manufacture a
490
+ * clean bill of health out of a parse failure.
491
+ */
492
+ function parsePageCheck(raw) {
493
+ if (!raw || typeof raw !== 'object')
494
+ return undefined;
495
+ const r = raw;
496
+ if (typeof r.consoleErrors !== 'number' || typeof r.failedRequests !== 'number')
497
+ return undefined;
498
+ const samples = Array.isArray(r.samples) ? r.samples.filter((s) => typeof s === 'string') : [];
499
+ return {
500
+ consoleErrors: r.consoleErrors,
501
+ failedRequests: r.failedRequests,
502
+ samples,
503
+ url: typeof r.url === 'string' ? r.url : '',
504
+ ...(typeof r.httpStatus === 'number' ? { httpStatus: r.httpStatus } : {}),
505
+ ...(r.origin === 'preview' || r.origin === 'prod' ? { origin: r.origin } : {}),
506
+ };
507
+ }
428
508
  // ─── Exit codes (spec §5 — EXACT) ─────────────────────────────────────────
429
509
  /**
430
510
  * | Exit | Meaning |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-labs/yolo-cli",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "YOLO Studio substrate CLI \u2014 owns yolo plan/workspace/artifact substrate-tooling commands. Distinct from yolo-code (the agent CLI) and yolo-router (the LLM gateway client).",
5
5
  "license": "MIT",
6
6
  "type": "module",