@yolo-labs/yolo-cli 0.39.0 → 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.
- package/dist/deploy-cli.js +150 -7
- package/dist/deploy-client.js +16 -0
- package/package.json +1 -1
package/dist/deploy-cli.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
1682
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
1691
|
-
|
|
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
|
}
|
package/dist/deploy-client.js
CHANGED
|
@@ -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.
|
|
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",
|