@yolo-labs/yolo-cli 0.42.1 → 0.43.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,7 +3,7 @@
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>] [--parent <id|slug>] [--json]
6
+ * yolo deploy init [--slug <slug>] [--type <static|worker>] [--parent <id|slug> | --no-parent] [--json]
7
7
  * yolo deploy status [--json]
8
8
  * yolo deploy logs [--tail] [--since <dur>] [--json]
9
9
  * yolo deploy rollback [releaseId] [--json]
@@ -36,14 +36,14 @@ function defaultStatPath(p) {
36
36
  }
37
37
  import { runDeployShip, exitCodeForFailure, formatShipSuccess, formatPending, formatFail, } from './deploy-ship.js';
38
38
  import { resolveDeployContext, createProject, getProjectStatus, listProjects, rollbackProject, unpublishProject, republishProject, renameProject, setProjectParent, addAlias, removeAlias, setRedirect, deleteProject, cloneProject, getLogs, pollTail, queryD1, } from './deploy-client.js';
39
- import { readDeployConfig, writeDeployConfig } from './deploy-config.js';
39
+ import { readDeployConfig, writeDeployConfig, findAncestorDeployLink as findAncestorLink, } from './deploy-config.js';
40
40
  import { adaptWrangler, detectProjectShape } from './deploy-detect.js';
41
41
  import { collectNodeBuiltinsFromText } from './deploy-bundle.js';
42
42
  import { runDeployDev } from './deploy-dev.js';
43
43
  import { defaultReadFile } from './auth-context.js';
44
44
  const USAGE = [
45
45
  'Usage: yolo deploy [--env <staging|prod>] [--dry-run] [--json]',
46
- ' yolo deploy init [--slug <slug>] [--type <static|worker>] [--parent <id|slug>] [--json]',
46
+ ' yolo deploy init [--slug <slug>] [--type <static|worker>] [--parent <id|slug> | --no-parent] [--json]',
47
47
  ' yolo deploy link (--project-id <id> | --slug <slug>) [--type <static|worker>]',
48
48
  ' yolo deploy validate [--json]',
49
49
  ' yolo deploy doctor [--json]',
@@ -200,6 +200,7 @@ export function parseInitArgs(args) {
200
200
  let slug;
201
201
  let type;
202
202
  let parentProjectId;
203
+ let noParent = false;
203
204
  let jsonOutput = false;
204
205
  for (let i = 0; i < args.length; i++) {
205
206
  const a = args[i];
@@ -229,6 +230,9 @@ export function parseInitArgs(args) {
229
230
  return { ok: false, message: '--parent requires a project id' };
230
231
  parentProjectId = v;
231
232
  }
233
+ else if (a === '--no-parent') {
234
+ noParent = true;
235
+ }
232
236
  else if (a.startsWith('--parent=')) {
233
237
  parentProjectId = a.slice('--parent='.length);
234
238
  }
@@ -248,7 +252,12 @@ export function parseInitArgs(args) {
248
252
  if (parentProjectId !== undefined && parentProjectId.length === 0) {
249
253
  return { ok: false, message: '--parent requires a project id or slug' };
250
254
  }
251
- return { ok: true, slug, type, parentProjectId, jsonOutput };
255
+ // Refuse rather than pick a winner: the two flags express opposite intents,
256
+ // and silently honouring one would create a project the caller did not ask for.
257
+ if (noParent && parentProjectId !== undefined) {
258
+ return { ok: false, message: '--parent and --no-parent are mutually exclusive' };
259
+ }
260
+ return { ok: true, slug, type, parentProjectId, noParent, jsonOutput };
252
261
  }
253
262
  async function runInitCmd(args, deps, io) {
254
263
  const parsed = parseInitArgs(args);
@@ -268,6 +277,19 @@ async function runInitCmd(args, deps, io) {
268
277
  const cwd = deps.cwd ?? process.cwd();
269
278
  const readConfig = deps.readDeployConfigImpl ?? readDeployConfig;
270
279
  const writeConfig = deps.writeDeployConfigImpl ?? writeDeployConfig;
280
+ // 🚨 `deps.env` is a TEST SEAM, not the environment. The real CLI reaches here
281
+ // as `runDeployCmd(args)` with no deps at all (`cli.ts:739`), so `deps.env?.X`
282
+ // is always undefined in production — a shape that reads like an env lookup and
283
+ // silently is not one. `resolveDeployContext` already uses the `?? process.env`
284
+ // form; these two had not. Behind it were:
285
+ // - the ancestor walk's `$HOME` floor, which would have been DISABLED in
286
+ // production, permitting exactly the machine-wide capture it exists to stop;
287
+ // - `WORKSPACE_ID` on create, so a hosting project made by `yolo deploy init`
288
+ // inside a session pod has NEVER carried the `workspaceId` that routes deploy
289
+ // lifecycle events back to the workspace (and to VibeAssist watchers).
290
+ // Pre-existing, and dead since it shipped.
291
+ // Injection still wins, so tests are unaffected.
292
+ const env = deps.env ?? process.env;
271
293
  const readResult = readConfig(cwd);
272
294
  if (!readResult.ok) {
273
295
  // Never silently clobber a malformed/invalid link file.
@@ -283,7 +305,10 @@ async function runInitCmd(args, deps, io) {
283
305
  // 🚨 `--parent` on an ALREADY-LINKED directory would otherwise report
284
306
  // `already-linked` and exit 0, having silently ignored the flag — the same
285
307
  // false-success the slug-reconciliation guard below exists to prevent.
286
- // Parent links are create-only, so there is nothing `init` can do here.
308
+ // `init` itself can do nothing here — its parent link is create-only — but
309
+ // re-parenting IS possible since S5 (2026-08-09): `yolo deploy set-parent`.
310
+ // The advice below used to say there was no re-parent route at all, which
311
+ // sent people to recreate a project when one command would have done.
287
312
  const message = 'this directory is already linked to a project; --parent only applies when creating one';
288
313
  // JSON mode keeps stderr EMPTY — automation treats it as diagnostics, and
289
314
  // the init contract is a clean stream split.
@@ -295,8 +320,8 @@ async function runInitCmd(args, deps, io) {
295
320
  // Only advice that actually works: parent links are create-only and
296
321
  // there is no re-parent route or console control, so the recovery is
297
322
  // 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');
323
+ + ' To re-parent THIS project: `yolo deploy set-parent <id|slug>`.\n'
324
+ + ' To create a NEW child: `yolo deploy init --parent <id|slug>` in its own directory.\n');
300
325
  }
301
326
  return 1;
302
327
  }
@@ -358,6 +383,44 @@ async function runInitCmd(args, deps, io) {
358
383
  // Else: not a slug of ours, but id-shaped — pass through and let the
359
384
  // server's ownership-asserted read be the authority.
360
385
  }
386
+ // ── Inferred parent (nesting §10 S4) ────────────────────────────────────
387
+ // No `--parent` given: look UP for an ancestor that is already a hosting
388
+ // project. `yolo deploy init` inside `apps/api` otherwise mints a fully
389
+ // independent project named after the directory — which is exactly how
390
+ // `El Paso Ballroom API` came to sit as an unrelated top-level card beside the
391
+ // site it serves. The relationship already exists in the filesystem; this
392
+ // records it.
393
+ //
394
+ // 🚨 INFERRED IS BEST-EFFORT; EXPLICIT IS AUTHORITATIVE. An inference must
395
+ // never fail an `init` that would otherwise succeed, so the candidate is
396
+ // VALIDATED against the caller's own projects before use and simply dropped if
397
+ // it does not qualify. A bad `--parent`, by contrast, still fails loudly above
398
+ // — the user asked for that specific parent and did not get it.
399
+ let inferredParent;
400
+ if (!resolvedParentId && !parsed.noParent) {
401
+ const ancestor = findAncestorLink(cwd, deps.readFileImpl, { ...(env.HOME ? { home: env.HOME } : {}) });
402
+ if (ancestor) {
403
+ const listImpl = deps.listProjectsImpl ?? listProjects;
404
+ const listed = await listImpl(auth.context);
405
+ // A list failure is NOT a reason to fail: we are only looking for a
406
+ // default. Fall through and create a root.
407
+ if (listed.ok) {
408
+ const match = listed.value.find((p) => resolveProjectId(p) === ancestor.projectId);
409
+ // Roots only, and only a project in a state the server will accept as a
410
+ // parent — the same rule the console's picker applies. Anything else is
411
+ // dropped silently: it is a suggestion, not an instruction.
412
+ const parentOfParent = match ? match.parentProjectId : undefined;
413
+ const status = match ? str(match.status) : undefined;
414
+ const eligible = !!match
415
+ && (parentOfParent === null || parentOfParent === undefined)
416
+ && (status === undefined || status === 'active' || status === 'published');
417
+ if (eligible) {
418
+ resolvedParentId = ancestor.projectId;
419
+ inferredParent = { link: ancestor, ...(str(match.slug) ? { slug: str(match.slug) } : {}) };
420
+ }
421
+ }
422
+ }
423
+ }
361
424
  const create = deps.createProjectImpl ?? createProject;
362
425
  const created = await create(auth.context, {
363
426
  name: parsed.slug ?? path.basename(cwd),
@@ -366,7 +429,7 @@ async function runInitCmd(args, deps, io) {
366
429
  // lets server-side deploy lifecycle events route back to the workspace
367
430
  // (and therefore to VibeAssist event watchers). Local CLI use remains
368
431
  // unchanged because the field is optional.
369
- ...(deps.env?.WORKSPACE_ID ? { workspaceId: deps.env.WORKSPACE_ID } : {}),
432
+ ...(env.WORKSPACE_ID ? { workspaceId: env.WORKSPACE_ID } : {}),
370
433
  // Nesting S4 — passed straight through; the server verifies ownership,
371
434
  // depth and parent state. Not written to `.yolo/deploy.json`.
372
435
  ...(resolvedParentId ? { parentProjectId: resolvedParentId } : {}),
@@ -399,6 +462,21 @@ async function runInitCmd(args, deps, io) {
399
462
  && str(owned?.parentProjectId)?.toLowerCase()
400
463
  !== resolvedParentId?.toLowerCase();
401
464
  if (projectId && !parentMismatch) {
465
+ // 🚨 An INFERRED parent must not silently evaporate here (codex P2).
466
+ // Reconciliation is still right — refusing would strand a project the
467
+ // caller already owns, which `init` must never do, and parent links
468
+ // are create-only so this path cannot apply one. But the caller was
469
+ // about to get a nested project and is instead getting a link to an
470
+ // existing one that may sit elsewhere in the tree. Say so, and name
471
+ // the command that closes the gap.
472
+ const existingParent = str(owned?.parentProjectId);
473
+ const inferenceLost = !!inferredParent
474
+ && existingParent?.toLowerCase() !== resolvedParentId?.toLowerCase();
475
+ if (inferenceLost && !parsed.jsonOutput) {
476
+ io.out(`note: this project already existed and is NOT under ${inferredParent.slug ?? resolvedParentId}.\n`
477
+ + ` Nesting was inferred from ${inferredParent.link.path} but only applies when creating.\n`
478
+ + ` Run \`yolo deploy set-parent ${inferredParent.slug ?? resolvedParentId}\` to nest it.\n`);
479
+ }
402
480
  return writeLinkFile(cwd, writeConfig, io, {
403
481
  projectId,
404
482
  slug: str(owned.slug) ?? takenSlug,
@@ -407,6 +485,9 @@ async function runInitCmd(args, deps, io) {
407
485
  adapted,
408
486
  jsonOutput: parsed.jsonOutput,
409
487
  jsonStatus: 'linked-existing',
488
+ // Machine callers get the same fact as a field, never a claim
489
+ // that the nesting happened.
490
+ ...(inferenceLost ? { parentNotApplied: resolvedParentId } : {}),
410
491
  }, `OK: slug '${takenSlug}' was already yours — linked existing project ${projectId} — wrote .yolo/deploy.json`);
411
492
  }
412
493
  }
@@ -429,7 +510,29 @@ async function runInitCmd(args, deps, io) {
429
510
  io.err(`${formatFail(failure)}\n`);
430
511
  return 2;
431
512
  }
432
- return writeLinkFile(cwd, writeConfig, io, { projectId, slug, type: parsed.type, existing, adapted, jsonOutput: parsed.jsonOutput, jsonStatus: 'created' }, `OK: linked project ${projectId}${slug ? ` (slug ${slug})` : ''} — wrote .yolo/deploy.json`);
513
+ // 🚨 SAY SO. A parent nobody asked for, applied silently, is the worst
514
+ // outcome available here — the caller would only discover the nesting from
515
+ // the console. Human mode names the ancestor file it came from and the exact
516
+ // command to undo it; JSON mode carries the same facts as fields.
517
+ if (inferredParent && !parsed.jsonOutput) {
518
+ const label = inferredParent.slug ? `${inferredParent.slug} (${resolvedParentId})` : resolvedParentId;
519
+ io.out(`note: nested under ${label}, inferred from ${inferredParent.link.path}\n`
520
+ + ' Use --no-parent to create a top-level project instead,\n'
521
+ + ' or `yolo deploy set-parent --none` to detach this one.\n');
522
+ }
523
+ return writeLinkFile(cwd, writeConfig, io, {
524
+ projectId,
525
+ slug,
526
+ type: parsed.type,
527
+ existing,
528
+ adapted,
529
+ jsonOutput: parsed.jsonOutput,
530
+ jsonStatus: 'created',
531
+ ...(resolvedParentId ? { parentProjectId: resolvedParentId } : {}),
532
+ ...(inferredParent
533
+ ? { parentInferredFrom: inferredParent.link.path }
534
+ : {}),
535
+ }, `OK: linked project ${projectId}${slug ? ` (slug ${slug})` : ''} — wrote .yolo/deploy.json`);
433
536
  }
434
537
  export function parseLinkArgs(args) {
435
538
  let projectId;
@@ -1889,6 +1992,13 @@ function writeLinkFile(cwd, writeConfig, io, params, message) {
1889
1992
  ...(params.slug ? { slug: params.slug } : {}),
1890
1993
  ...(params.type ? { type: params.type } : {}),
1891
1994
  configPath: '.yolo/deploy.json',
1995
+ // Nesting is invisible in `.yolo/deploy.json` by design (the link lives
1996
+ // on the project document), so JSON callers would have no way to see it
1997
+ // happened. `parentInferredFrom` is present ONLY when the CLI chose the
1998
+ // parent — its absence means the caller asked for it or there is none.
1999
+ ...(params.parentProjectId ? { parentProjectId: params.parentProjectId } : {}),
2000
+ ...(params.parentInferredFrom ? { parentInferredFrom: params.parentInferredFrom } : {}),
2001
+ ...(params.parentNotApplied ? { parentNotApplied: params.parentNotApplied } : {}),
1892
2002
  ...(params.adapted
1893
2003
  ? { adapted: { sourceFile: params.adapted.sourceFile, migrated: params.adapted.migrated, warnings: params.adapted.warnings } }
1894
2004
  : {}),
@@ -26,7 +26,7 @@
26
26
  * (e.g. `compatibilityDate`, which the platform fixes and does not read)
27
27
  * surfaces in `yolo deploy validate` instead of misleading the author.
28
28
  */
29
- import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
29
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
30
30
  import path from 'node:path';
31
31
  export class DeployConfigError extends Error {
32
32
  code;
@@ -43,6 +43,85 @@ export class DeployConfigError extends Error {
43
43
  export function deployConfigPath(cwd) {
44
44
  return path.join(cwd, '.yolo', 'deploy.json');
45
45
  }
46
+ /** How far up to look before giving up. A backstop against a pathological tree. */
47
+ const ANCESTOR_WALK_MAX_DEPTH = 24;
48
+ /**
49
+ * Walk UP from `cwd` looking for an ancestor already linked to a hosting project.
50
+ *
51
+ * WHY: `yolo deploy init` inside `apps/api` mints a fully independent project
52
+ * named after the directory — which is exactly how `El Paso Ballroom API` came
53
+ * to exist as an unrelated top-level card next to the site it serves. The
54
+ * relationship already exists in the filesystem; nothing recorded it. This finds
55
+ * it so `init` can offer it (nesting plan §10 S4).
56
+ *
57
+ * 🚨 THE STOP CONDITIONS ARE THE DESIGN. An unbounded walk is actively harmful:
58
+ *
59
+ * - **Never `cwd` itself.** That is the already-linked case, which `init`
60
+ * handles separately; treating it as an ancestor would make every project
61
+ * its own parent.
62
+ * - **Stop at a `.git` directory.** That is the repo boundary and therefore
63
+ * the monorepo boundary. The repo root is CHECKED first and only then
64
+ * becomes a stopping point, so a deployed monorepo root is still found.
65
+ * - **Stop BEFORE `$HOME`, and never inspect it.** Someone who once ran
66
+ * `yolo deploy init` in their home directory would otherwise have every
67
+ * future project on the machine silently adopted by that one — a
68
+ * machine-wide capture from a single stray file.
69
+ * - **Depth cap** as a backstop, and the filesystem root always terminates.
70
+ *
71
+ * Pure and injectable so the walk is testable without touching a real tree.
72
+ */
73
+ export function findAncestorDeployLink(cwd, readFileImpl = defaultReadFile, opts = {}) {
74
+ const exists = opts.existsImpl ?? ((p) => existsSync(p));
75
+ const maxDepth = opts.maxDepth ?? ANCESTOR_WALK_MAX_DEPTH;
76
+ const home = opts.home ? path.resolve(opts.home) : undefined;
77
+ const start = path.resolve(cwd);
78
+ // The repo boundary applies to `cwd` ITSELF (codex P2). Running `init` at the
79
+ // root of a nested repository would otherwise begin the walk one level ABOVE
80
+ // it and adopt a parent from the enclosing tree — crossing exactly the
81
+ // boundary the ancestor-level check below exists to hold.
82
+ if (exists(path.join(start, '.git')))
83
+ return null;
84
+ let dir = path.dirname(start);
85
+ for (let depth = 0; depth < maxDepth; depth += 1) {
86
+ // Home is a hard FLOOR: reaching it ends the walk, and it is never
87
+ // inspected. Walking upward from anywhere inside home always arrives here
88
+ // before `/`, so this one check covers the whole case — an earlier version
89
+ // tried to test "is dir inside home" and had the sense inverted, which
90
+ // refused every directory UNDER home and quietly disabled the feature for
91
+ // every user whose repos live there (i.e. almost all of them).
92
+ if (home && dir === home)
93
+ return null;
94
+ const filePath = deployConfigPath(dir);
95
+ const text = readFileImpl(filePath);
96
+ if (text !== undefined && text.trim() !== '') {
97
+ try {
98
+ const parsed = JSON.parse(text);
99
+ if (typeof parsed.projectId === 'string' && parsed.projectId.length > 0) {
100
+ return {
101
+ projectId: parsed.projectId,
102
+ ...(typeof parsed.slug === 'string' && parsed.slug ? { slug: parsed.slug } : {}),
103
+ dir,
104
+ path: filePath,
105
+ };
106
+ }
107
+ }
108
+ catch {
109
+ // A malformed ancestor link is not this command's problem to report —
110
+ // it belongs to that directory, and failing `init` here would block a
111
+ // child on a file the user may not even know exists. Keep walking.
112
+ }
113
+ }
114
+ // Repo boundary. Checked AFTER the link above so a deployed monorepo root
115
+ // still counts as an ancestor.
116
+ if (exists(path.join(dir, '.git')))
117
+ return null;
118
+ const parent = path.dirname(dir);
119
+ if (parent === dir)
120
+ return null; // filesystem root
121
+ dir = parent;
122
+ }
123
+ return null;
124
+ }
46
125
  /**
47
126
  * Read `.yolo/deploy.json` from a project root. Absent file is the
48
127
  * non-error `{ ok: true, config: null }` case (detection falls through
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-labs/yolo-cli",
3
- "version": "0.42.1",
3
+ "version": "0.43.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",