@yolo-labs/yolo-cli 0.38.1 → 0.40.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.
@@ -3,10 +3,12 @@
3
3
  * (docs/MANAGED_HOSTING_CLI_SPEC.md §1).
4
4
  *
5
5
  * yolo deploy [--env <staging|prod>] [--dry-run] [--json] ← bare = ship
6
- * yolo deploy init [--slug <slug>] [--type <static|worker>] [--json]
6
+ * yolo deploy init [--slug <slug>] [--type <static|worker>] [--parent <id|slug>] [--json]
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';
@@ -41,7 +43,7 @@ import { runDeployDev } from './deploy-dev.js';
41
43
  import { defaultReadFile } from './auth-context.js';
42
44
  const USAGE = [
43
45
  'Usage: yolo deploy [--env <staging|prod>] [--dry-run] [--json]',
44
- ' yolo deploy init [--slug <slug>] [--type <static|worker>] [--json]',
46
+ ' yolo deploy init [--slug <slug>] [--type <static|worker>] [--parent <id|slug>] [--json]',
45
47
  ' yolo deploy link (--project-id <id> | --slug <slug>) [--type <static|worker>]',
46
48
  ' yolo deploy validate [--json]',
47
49
  ' yolo deploy doctor [--json]',
@@ -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')
@@ -193,6 +199,7 @@ async function runShipCmd(args, deps, io) {
193
199
  export function parseInitArgs(args) {
194
200
  let slug;
195
201
  let type;
202
+ let parentProjectId;
196
203
  let jsonOutput = false;
197
204
  for (let i = 0; i < args.length; i++) {
198
205
  const a = args[i];
@@ -216,6 +223,15 @@ export function parseInitArgs(args) {
216
223
  return { ok: false, message: `--type must be 'static' or 'worker' (got '${v}')` };
217
224
  type = v;
218
225
  }
226
+ else if (a === '--parent') {
227
+ const v = args[++i];
228
+ if (!v || v.startsWith('--'))
229
+ return { ok: false, message: '--parent requires a project id' };
230
+ parentProjectId = v;
231
+ }
232
+ else if (a.startsWith('--parent=')) {
233
+ parentProjectId = a.slice('--parent='.length);
234
+ }
219
235
  else if (a.startsWith('--type=')) {
220
236
  const v = a.slice('--type='.length);
221
237
  if (v !== 'static' && v !== 'worker')
@@ -229,7 +245,10 @@ export function parseInitArgs(args) {
229
245
  return { ok: false, message: `unexpected positional argument: ${a}` };
230
246
  }
231
247
  }
232
- return { ok: true, slug, type, jsonOutput };
248
+ if (parentProjectId !== undefined && parentProjectId.length === 0) {
249
+ return { ok: false, message: '--parent requires a project id or slug' };
250
+ }
251
+ return { ok: true, slug, type, parentProjectId, jsonOutput };
233
252
  }
234
253
  async function runInitCmd(args, deps, io) {
235
254
  const parsed = parseInitArgs(args);
@@ -260,6 +279,27 @@ async function runInitCmd(args, deps, io) {
260
279
  return exitCodeForFailure(readResult.kind);
261
280
  }
262
281
  const existing = readResult.config;
282
+ if (existing?.projectId && parsed.parentProjectId) {
283
+ // 🚨 `--parent` on an ALREADY-LINKED directory would otherwise report
284
+ // `already-linked` and exit 0, having silently ignored the flag — the same
285
+ // false-success the slug-reconciliation guard below exists to prevent.
286
+ // Parent links are create-only, so there is nothing `init` can do here.
287
+ const message = 'this directory is already linked to a project; --parent only applies when creating one';
288
+ // JSON mode keeps stderr EMPTY — automation treats it as diagnostics, and
289
+ // the init contract is a clean stream split.
290
+ if (parsed.jsonOutput) {
291
+ io.out(`${formatJsonResult({ status: 'failed', message })}\n`);
292
+ }
293
+ else {
294
+ io.err(`FAIL: ${message}.\n`
295
+ // Only advice that actually works: parent links are create-only and
296
+ // there is no re-parent route or console control, so the recovery is
297
+ // to create the child as a NEW project.
298
+ + ' Nesting is set at creation. Create the child in its own directory with\n'
299
+ + ' `yolo deploy init --parent <id|slug>`, or from the Hosting console\'s New project dialog.\n');
300
+ }
301
+ return 1;
302
+ }
263
303
  if (existing?.projectId) {
264
304
  // Idempotent: a committed link means future sessions ship to the SAME
265
305
  // project instead of forking a new slug — never silently re-create.
@@ -282,6 +322,42 @@ async function runInitCmd(args, deps, io) {
282
322
  io.err(`${formatFail({ kind: 'auth', message: auth.message })}\n`);
283
323
  return 78;
284
324
  }
325
+ // Resolve `--parent` when given as a SLUG rather than an id. A CLI-only user
326
+ // has no way to discover an opaque 24-hex id (there is no `deploy list`
327
+ // subcommand), but slugs are the handle they already use everywhere else —
328
+ // so accept either and look the slug up through the same owned-projects
329
+ // helper `link` uses (codex P2).
330
+ let resolvedParentId = parsed.parentProjectId;
331
+ if (resolvedParentId) {
332
+ // SLUG FIRST, then id. A slug may legally be 24 hex characters, so a
333
+ // shape test alone is ambiguous; looking the slug up first resolves both
334
+ // forms with one call and gives slugs precedence — which is the form a
335
+ // human typed on purpose.
336
+ const parentLookup = await findOwnedProjectBySlug(deps, auth.context, resolvedParentId);
337
+ if (!parentLookup.ok) {
338
+ // A list failure (auth/network) is NOT "not found" — surface the real
339
+ // error and its exit code, matching how `link` treats the same helper.
340
+ if (parsed.jsonOutput)
341
+ io.out(`${formatJsonResult(parentLookup)}\n`);
342
+ else
343
+ io.err(`${formatFail(parentLookup)}\n`);
344
+ return exitCodeForFailure(parentLookup.kind);
345
+ }
346
+ const bySlug = parentLookup.project ? resolveProjectId(parentLookup.project) : undefined;
347
+ if (bySlug) {
348
+ resolvedParentId = bySlug;
349
+ }
350
+ else if (!/^[a-f0-9]{24}$/i.test(resolvedParentId)) {
351
+ const message = `no project of yours matches parent '${resolvedParentId}' — pass its slug or 24-hex id`;
352
+ if (parsed.jsonOutput)
353
+ io.out(`${formatJsonResult({ status: 'failed', message })}\n`);
354
+ else
355
+ io.err(`FAIL: ${message}\n`);
356
+ return 1;
357
+ }
358
+ // Else: not a slug of ours, but id-shaped — pass through and let the
359
+ // server's ownership-asserted read be the authority.
360
+ }
285
361
  const create = deps.createProjectImpl ?? createProject;
286
362
  const created = await create(auth.context, {
287
363
  name: parsed.slug ?? path.basename(cwd),
@@ -291,6 +367,9 @@ async function runInitCmd(args, deps, io) {
291
367
  // (and therefore to VibeAssist event watchers). Local CLI use remains
292
368
  // unchanged because the field is optional.
293
369
  ...(deps.env?.WORKSPACE_ID ? { workspaceId: deps.env.WORKSPACE_ID } : {}),
370
+ // Nesting S4 — passed straight through; the server verifies ownership,
371
+ // depth and parent state. Not written to `.yolo/deploy.json`.
372
+ ...(resolvedParentId ? { parentProjectId: resolvedParentId } : {}),
294
373
  });
295
374
  if (!created.ok) {
296
375
  // create-or-LINK: a `slug-taken` on a slug the caller ALREADY OWNS means a
@@ -308,7 +387,18 @@ async function runInitCmd(args, deps, io) {
308
387
  const lookup = await findOwnedProjectBySlug(deps, auth.context, takenSlug);
309
388
  const owned = lookup.ok ? lookup.project : undefined;
310
389
  const projectId = owned ? resolveProjectId(owned) : undefined;
311
- if (projectId) {
390
+ // 🚨 Do NOT reconcile into a project that is not already under the
391
+ // requested parent (codex P2). Parent links are CREATE-ONLY server
392
+ // side, so linking here would report a successful nesting that never
393
+ // happened — the caller believes the family exists and it does not.
394
+ // Fall through to the plain slug-taken refusal instead.
395
+ // Case-normalized: `--parent` accepts either case (the regex is /i) but
396
+ // the API serializes an ObjectId lowercase, so a raw compare would
397
+ // report a mismatch for the very same parent (codex P2).
398
+ const parentMismatch = parsed.parentProjectId !== undefined
399
+ && str(owned?.parentProjectId)?.toLowerCase()
400
+ !== resolvedParentId?.toLowerCase();
401
+ if (projectId && !parentMismatch) {
312
402
  return writeLinkFile(cwd, writeConfig, io, {
313
403
  projectId,
314
404
  slug: str(owned.slug) ?? takenSlug,
@@ -1351,6 +1441,133 @@ async function runRedirectCmd(args, deps, io) {
1351
1441
  io.out(`OK: '${parsed.slug}' now 308 → ${parsed.url}\n`);
1352
1442
  return 0;
1353
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
+ }
1354
1571
  export function parseDeleteArgs(args) {
1355
1572
  let confirmSlug;
1356
1573
  let jsonOutput = false;
@@ -1589,22 +1806,32 @@ function parseFlagOnlyArgs(args, _name) {
1589
1806
  }
1590
1807
  return { ok: true, jsonOutput };
1591
1808
  }
1592
- 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 = {}) {
1593
1816
  const cwd = deps.cwd ?? process.cwd();
1594
1817
  const readConfig = deps.readDeployConfigImpl ?? readDeployConfig;
1595
1818
  const readResult = readConfig(cwd);
1596
1819
  if (!readResult.ok) {
1597
- io.err(`${formatFail({ kind: readResult.kind, message: readResult.message })}\n`);
1598
- 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 };
1599
1824
  }
1600
1825
  const config = readResult.config;
1601
1826
  if (!config?.projectId) {
1602
- io.err(`${formatFail({
1827
+ const failure = {
1603
1828
  kind: 'not-linked',
1604
1829
  message: 'this directory is not linked to a hosting project (.yolo/deploy.json missing or has no projectId)',
1605
1830
  hint: "run 'yolo deploy init' to create or link a hosting project",
1606
- })}\n`);
1607
- 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 };
1608
1835
  }
1609
1836
  return { ok: true, projectId: config.projectId, slug: config.slug };
1610
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 } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-labs/yolo-cli",
3
- "version": "0.38.1",
3
+ "version": "0.40.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",