@yolo-labs/yolo-cli 0.43.0 → 0.44.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yolo Labs, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,57 +1,74 @@
1
- # @yololabs/yolo-cli — YOLO Studio substrate CLI
1
+ # @yolo-labs/yolo-cli
2
2
 
3
- The `yolo` binary owns substrate-tooling subcommands (Plan import/export,
4
- future workspace and artifact primitives). Distinct from:
3
+ The `yolo` CLI provides workspace context, artifact reads, personal app development
4
+ and publishing, and hosting commands. Run `yolo --help` for all commands.
5
5
 
6
- - **`yolo-code`** — YOLO Studio's built-in coding agent CLI (separate package).
7
- - **`yolo-router`** — the LLM gateway client (separate package).
6
+ ```sh
7
+ yolo context
8
+ yolo artifact list
9
+ yolo tileapp init my-app
10
+ yolo deploy --dry-run
11
+ ```
8
12
 
9
- ## Status
13
+ Authenticated commands require `SESSION_ID`, `YOLO_COMMON_API_URL` (or
14
+ `YOLO_API_URL`), and a user access JWT. The CLI reads the rotated token at
15
+ `~/.config/yolo/token`, falling back to `YOLO_API_TOKEN`. The session record
16
+ supplies the workspace identity.
10
17
 
11
- Phase 8a Group 9 scaffold. v1 ships only `yolo --version` and
12
- `yolo context` (resolves and prints the container ambient session
13
- context). Plan import/export lands in Phase 8c.
18
+ Artifact commands mint a scoped delegated token through
19
+ `POST /internal/mcp/tokens`; hosting commands authenticate with the user JWT.
20
+ Offline commands such as app scaffolding, validation, and local serving do not
21
+ require authentication.
14
22
 
15
- ## Usage (in-container)
23
+ Build and test locally:
16
24
 
17
25
  ```sh
18
- yolo --version
19
- yolo context
26
+ npm ci
27
+ npm test
28
+ node dist/cli.js --help
20
29
  ```
21
30
 
22
- Outside a Studio container the CLI exits with `session-required`. A future
23
- external-login flow is planned but out of scope for Phase 8.
31
+ This standalone package is installed in Studio containers through
32
+ `containers/sandboxes/yolo-main/Dockerfile`.
24
33
 
25
- ## Auth contract
34
+ ## Managed branch previews
26
35
 
27
- Requires:
36
+ Inside a Studio workspace, create a persistent preview of a repository branch:
28
37
 
29
- - `SESSION_ID` (load-bearing — workspace derives from the session record)
30
- - `YOLO_COMMON_API_URL` (or `YOLO_API_URL`)
31
- - A credential — resolved by precedence (AUTH_AND_ONBOARDING Slice 0):
32
- 1. `~/.config/yolo/token` — the rotated **user access JWT**, rewritten
33
- every ~10 min by container-api's token-refresh service. Preferred;
34
- reading the file (not the env var) avoids the stale-shell problem.
35
- 2. `YOLO_API_TOKEN` env — the pod-injected user JWT (≤24h).
36
- 3. `INTERNAL_API_KEY` env — service master-key fallback, kept for
37
- lane-runner / service callers. **No longer required in user shells**
38
- and intentionally excluded from the sandbox env.
38
+ ```sh
39
+ yolo preview create --name 'Latest main' --branch main --cwd web \
40
+ --setup 'npm ci' --build 'npm run build' \
41
+ --command 'npm start -- --hostname "$HOST" --port "$PORT"'
42
+ yolo preview status
43
+ yolo preview status <tile-id> --json
44
+ yolo preview logs <tile-id> --tail 100
45
+ yolo preview stop <tile-id>
46
+ ```
39
47
 
40
- The CLI mints a short-lived delegated MCP token via the session-bound
41
- endpoint (`POST /internal/mcp/tokens`) with `agentId: 'substrate-cli'`
42
- and a capped scope set, authenticating with the user JWT
43
- (`Authorization: Bearer`) when available, falling back to
44
- `X-Internal-Auth` otherwise. It then calls `/internal/work/*` REST
45
- routes with the delegated bearer (which is the capability — the
46
- service header is no longer required by `requireMcpAuth`).
48
+ Choose commands appropriate to your app; the example assumes its start script
49
+ accepts `--hostname` and `--port`. Single-quote commands to preserve `$PORT` and
50
+ `$HOST` for the service. It uses isolated checkouts, checks candidate health, and
51
+ switches the tile's stable port only after a successful build and start. Failed
52
+ updates keep the last working version. The required runtime must already be
53
+ installed; this service targets stateless HTTP apps, not database migrations.
47
54
 
48
- ## Local build
55
+ The session resolves the authoritative workspace. Preview operations use delegated
56
+ capabilities; no manual credentials or workspace ID are needed. `create` returns
57
+ the tile ID and starts asynchronously. Use `status` for progress, and reuse
58
+ `--request-id <stable-id>` if retrying creation after an uncertain response.
59
+ `status` without an ID lists managed branch previews only. `stop` retains the tile
60
+ and configuration in Studio, removes its running service, and prevents startup on
61
+ page reload. Click **Start** in the tile to resume. Logs are bounded and in-memory;
62
+ stopping the service discards them. All commands accept `--json`.
49
63
 
50
- ```sh
51
- npm install
52
- npm run build
53
- node dist/cli.js --version
54
- ```
64
+ `yolo preview --help` lists polling, timeout, port and health-check options. New CLI,
65
+ API, agent-registry scopes and container-api versions must be deployed together;
66
+ older deployments return an error rather than run a different preview mode.
67
+
68
+ ## Source & contributing
69
+
70
+ [github.com/yolo-labs-hq/yolo-cli](https://github.com/yolo-labs-hq/yolo-cli) is a public mirror of `packages/yolo-cli` in YOLO Labs' private monorepo, which stays the source of truth. The mirror is synced automatically on every change. Issues are welcome. Pull requests are welcome too: we apply them in the monorepo, keeping you as the author, and the change then syncs back here.
71
+
72
+ ## License
55
73
 
56
- Standalone package — not a workspace member. Container install is an
57
- explicit `COPY` + `npm install -g` block in `containers/sandboxes/yolo-main/Dockerfile`.
74
+ MIT. See [LICENSE](./LICENSE).
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Returns the latest version by default; `--version <n>` pins to a
5
5
  * specific version. Default summary renders metadata only (key,
6
- * version, type, producer, fingerprint, contentLength, createdAt).
6
+ * version, type, producer, contentLength, createdAt).
7
7
  * `--content` flag emits ONLY the artifact content body to stdout
8
8
  * (suitable for piping). `--json` emits the full record including
9
9
  * content.
@@ -81,8 +81,7 @@ export async function runArtifactGet(options) {
81
81
  // ─── Output formatting ────────────────────────────────────────────────────
82
82
  /**
83
83
  * Header with metadata — no content body. The producer block tells
84
- * the operator who emitted the artifact (agent + tile) and provenance
85
- * fingerprint for cross-run identity.
84
+ * the operator who emitted the artifact (agent + tile).
86
85
  */
87
86
  export function formatSummary(artifact, workspaceId) {
88
87
  const lines = [];
@@ -90,12 +89,6 @@ export function formatSummary(artifact, workspaceId) {
90
89
  lines.push(` type: ${artifact.artifactType}`);
91
90
  lines.push(` contentLength: ${artifact.contentLength}`);
92
91
  lines.push(` producedBy: ${artifact.producedByAgentId}${artifact.producedByTileId ? ` (tile ${artifact.producedByTileId})` : ''}`);
93
- if (artifact.producerType)
94
- lines.push(` producerType: ${artifact.producerType}`);
95
- if (artifact.producerId)
96
- lines.push(` producerId: ${artifact.producerId}`);
97
- if (artifact.fingerprint)
98
- lines.push(` fingerprint: ${artifact.fingerprint}`);
99
92
  if (artifact.refPath)
100
93
  lines.push(` refPath: ${artifact.refPath}`);
101
94
  lines.push(` createdAt: ${artifact.createdAt}`);
package/dist/cli.js CHANGED
@@ -1,13 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * `yolo` — YOLO Studio substrate CLI (Phase 8a Group 9 scaffold).
4
- *
5
- * Owns substrate-tooling subcommands (plan import/export/validate;
6
- * future: workspace, artifact). v1 ships only `yolo --version` and
7
- * `yolo context`; full plan import/export lands in Phase 8c.
8
- *
9
- * NOT the agent CLI. The agent CLI is `yolo-code`. NOT the LLM router
10
- * client. The LLM router client is `yolo-router`.
3
+ * `yolo` — YOLO Studio workspace, artifact, app and hosting CLI.
11
4
  *
12
5
  * Auth contract (AUTH_AND_ONBOARDING Slice 0 — user-JWT-only):
13
6
  * `SESSION_ID` + `YOLO_COMMON_API_URL` + a USER ACCESS JWT, resolved by
@@ -20,8 +13,6 @@
20
13
  * binding is derived from the session record, not from env or args.
21
14
  */
22
15
  import { readSessionContext, formatContext, ContextResolutionError } from './context.js';
23
- import { validatePlanFile, formatErrors } from './plan-validate.js';
24
- import { runRunList, exitCodeForFailure as runListExitCode, } from './run-list.js';
25
16
  import { runArtifactGet, exitCodeForFailure as artifactGetExitCode, } from './artifact-get.js';
26
17
  import { runArtifactList, exitCodeForFailure as artifactListExitCode, } from './artifact-list.js';
27
18
  import { runTileAppSign, runTileAppPublish, exitCodeForFailure as tileAppExitCode, } from './tileapp-publisher.js';
@@ -37,6 +28,7 @@ import { runTileAppSign, runTileAppPublish, exitCodeForFailure as tileAppExitCod
37
28
  // `../package.json` relative path resolves correctly both during
38
29
  // tests (src/) and in production (dist/).
39
30
  import { createRequire } from 'module';
31
+ import { exitAfterFlush } from './exit.js';
40
32
  const PKG_VERSION = createRequire(import.meta.url)('../package.json').version;
41
33
  /**
42
34
  * Serialize an orchestration result for `--json` output. Strips the
@@ -55,11 +47,6 @@ function printHelp() {
55
47
  '',
56
48
  'Commands:',
57
49
  ' context Print resolved session/workspace/API context.',
58
- ' plan validate <file> Validate a .yolo/plans/<slug>.md plan file (offline).',
59
- ' run list [opts] List Plan Runs in the current workspace (work.list_runs).',
60
- ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
61
- ' [--state <pending|running|paused|...>] Server-side executionState filter.',
62
- ' [--json] Pretty-print raw JSON instead of the table.',
63
50
  ' artifact get <key> [opts] Read a workspace artifact (work.get_artifact).',
64
51
  ' [--version <n>] Pin to a specific version. Default: latest.',
65
52
  ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
@@ -70,6 +57,14 @@ function printHelp() {
70
57
  ' [--limit <n>] Cap result count (1-500, default 100).',
71
58
  ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
72
59
  ' [--json] Pretty-print raw JSON instead of the table.',
60
+ ' kanban export <tileId> [opts] Read a board out as a seed document (operator-only REST route).',
61
+ ' [-o <file>] Write to <file>; refuses to overwrite. Default: stdout, for piping.',
62
+ ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
63
+ ' kanban import <boardId> <file> Rebuild a board from a seed document (additive; never overwrites).',
64
+ ' [--workspace <wsId>] Sanity-check the workspace bound to this session.',
65
+ ' git doctor [opts] Diagnose why git (not gh) can\'t authenticate to github.com.',
66
+ ' [--fix] Repair what is safe to (store file, helpers, remote URL), then re-check.',
67
+ ' [--offline] [--remote <name>] [--json] Skip network checks; remote to probe (default: origin); JSON output.',
73
68
  ' tileapp init <name> Scaffold a personal app (./<name>/tileapp.json + index.html).',
74
69
  ' tileapp validate <manifest> [opts] Offline lint: manifest schema + bundle layout (no auth).',
75
70
  ' tileapp media push <manifest> [--dir d] Upload store screenshots (additive — leaves the rest of the bundle alone).',
@@ -100,7 +95,8 @@ function printHelp() {
100
95
  ' mcp scopes [opts] Show mintable vs not-mintable MCP scopes for this session (pure read).',
101
96
  ' [--agent <agentId>] Agent identity to inspect (default: substrate-cli).',
102
97
  ' [--json] Emit {agentId, allowed, denied} as JSON.',
103
- ' serve <dir> [opts] Static file server (decision-preview / Gap 2a).',
98
+ ' preview <create|status|logs|stop> [opts] Manage branch-following previews.',
99
+ ' serve <dir> [opts] Static file server.',
104
100
  ' [--port <n>] Port (default: $PORT, else 3000).',
105
101
  ' [--host <h>] Bind host (default: 0.0.0.0).',
106
102
  ' [--spa] Serve index.html for unmatched routes (SPA mode).',
@@ -112,7 +108,7 @@ function printHelp() {
112
108
  ' deploy status [--json] Project + release status (incl. pending approvals).',
113
109
  ' deploy logs [--tail] [--since <dur>] Recent logs; --tail streams NDJSON.',
114
110
  ' deploy rollback [releaseId] [--json] Repoint the project to a previous release.',
115
- ' --version Print substrate CLI version.',
111
+ ' --version Print CLI version.',
116
112
  ' --help Print this help.',
117
113
  '',
118
114
  'Distinct from:',
@@ -121,30 +117,6 @@ function printHelp() {
121
117
  '',
122
118
  ].join('\n'));
123
119
  }
124
- function runPlanValidate(args) {
125
- const file = args[0];
126
- if (!file) {
127
- process.stderr.write('yolo: plan validate requires a file path\n');
128
- process.stderr.write('Usage: yolo plan validate <file>\n');
129
- return 64; // EX_USAGE
130
- }
131
- let result;
132
- try {
133
- result = validatePlanFile(file);
134
- }
135
- catch (err) {
136
- const msg = err instanceof Error ? err.message : String(err);
137
- process.stderr.write(`yolo: cannot read plan file '${file}': ${msg}\n`);
138
- return 64;
139
- }
140
- if (result.ok) {
141
- process.stdout.write(`OK: ${file} is canonical and schema-valid (planId=${result.planId}, ${result.bytes} bytes)\n`);
142
- return 0;
143
- }
144
- process.stderr.write(`FAIL: ${file}\n`);
145
- process.stderr.write(`${formatErrors(result.errors)}\n`);
146
- return 1;
147
- }
148
120
  function tileAppUsage(sub, message) {
149
121
  process.stderr.write(`yolo tileapp ${sub}: ${message}\n`);
150
122
  const usage = {
@@ -169,7 +141,7 @@ async function runTileAppInstallCmd(args) {
169
141
  const a = args[i];
170
142
  // A following flag must never be consumed as a value (`--workspace
171
143
  // --accept-optional=x`), so reject empty values and `--`-leading values —
172
- // same pattern as the run/plan parsers (codex gpt-5.6-sol P3, 2026-07-18).
144
+ // Reject flags in value positions.
173
145
  if (a === '--workspace') {
174
146
  const v = args[++i];
175
147
  if (!v || v.startsWith('--'))
@@ -540,61 +512,6 @@ async function runTileAppDevCmd(args) {
540
512
  }
541
513
  return runTileAppDev({ manifestPath, port, host, bundleDir, allow });
542
514
  }
543
- function parseRunListArgs(args) {
544
- let workspaceFlag;
545
- let stateFilter;
546
- let jsonOutput = false;
547
- for (let i = 0; i < args.length; i++) {
548
- const a = args[i];
549
- if (a === '--workspace') {
550
- const v = args[++i];
551
- if (!v || v.startsWith('--'))
552
- return { ok: false, message: '--workspace requires a value' };
553
- workspaceFlag = v;
554
- }
555
- else if (a.startsWith('--workspace=')) {
556
- workspaceFlag = a.slice('--workspace='.length);
557
- }
558
- else if (a === '--state') {
559
- const v = args[++i];
560
- if (!v || v.startsWith('--'))
561
- return { ok: false, message: '--state requires a value' };
562
- stateFilter = v;
563
- }
564
- else if (a.startsWith('--state=')) {
565
- stateFilter = a.slice('--state='.length);
566
- }
567
- else if (a === '--json') {
568
- jsonOutput = true;
569
- }
570
- else if (a.startsWith('--')) {
571
- return { ok: false, message: `unknown option: ${a}` };
572
- }
573
- else {
574
- return { ok: false, message: `unexpected positional argument: ${a}` };
575
- }
576
- }
577
- return { ok: true, workspaceFlag, stateFilter, jsonOutput };
578
- }
579
- async function runRunListCmd(args) {
580
- const parsed = parseRunListArgs(args);
581
- if (!parsed.ok) {
582
- process.stderr.write(`yolo: run list: ${parsed.message}\n`);
583
- process.stderr.write('Usage: yolo run list [--workspace <wsId>] [--state <pending|running|paused|succeeded|failed|cancelled|superseded>] [--json]\n');
584
- return 64;
585
- }
586
- const result = await runRunList({
587
- workspaceFlag: parsed.workspaceFlag,
588
- stateFilter: parsed.stateFilter,
589
- outputFormat: parsed.jsonOutput ? 'json' : 'summary',
590
- });
591
- if (result.ok) {
592
- process.stdout.write(`${result.output}\n`);
593
- return 0;
594
- }
595
- process.stderr.write(`FAIL [${result.kind}]: ${result.message}\n`);
596
- return runListExitCode(result.kind);
597
- }
598
515
  function parseArtifactGetArgs(args) {
599
516
  let key;
600
517
  let version;
@@ -781,32 +698,6 @@ async function main(argv) {
781
698
  throw err;
782
699
  }
783
700
  }
784
- if (cmd === 'plan') {
785
- const sub = args[1];
786
- if (sub === 'validate') {
787
- return runPlanValidate(args.slice(2));
788
- }
789
- if (!sub) {
790
- process.stderr.write('yolo: plan requires a subcommand (validate)\n');
791
- return 64;
792
- }
793
- process.stderr.write(`yolo: unknown plan subcommand '${sub}'\n`);
794
- process.stderr.write('Subcommands: validate\n');
795
- return 64;
796
- }
797
- if (cmd === 'run') {
798
- const sub = args[1];
799
- if (sub === 'list') {
800
- return runRunListCmd(args.slice(2));
801
- }
802
- if (!sub) {
803
- process.stderr.write('yolo: run requires a subcommand (list)\n');
804
- return 64;
805
- }
806
- process.stderr.write(`yolo: unknown run subcommand '${sub}'\n`);
807
- process.stderr.write('Subcommands: list\n');
808
- return 64;
809
- }
810
701
  if (cmd === 'artifact') {
811
702
  const sub = args[1];
812
703
  if (sub === 'get') {
@@ -849,6 +740,14 @@ async function main(argv) {
849
740
  process.stderr.write('Subcommands: init, validate, dev, sign, publish, media, install, add-tile\n');
850
741
  return 64;
851
742
  }
743
+ if (cmd === 'git') {
744
+ const { runGitCmd } = await import('./git-doctor.js');
745
+ return runGitCmd(args.slice(1));
746
+ }
747
+ if (cmd === 'kanban') {
748
+ const { runKanbanCmd } = await import('./kanban-cli.js');
749
+ return runKanbanCmd(args.slice(1));
750
+ }
852
751
  if (cmd === 'mcp') {
853
752
  const sub = args[1];
854
753
  if (sub === 'scopes')
@@ -861,13 +760,17 @@ async function main(argv) {
861
760
  process.stderr.write('Subcommands: scopes\n');
862
761
  return 64;
863
762
  }
763
+ if (cmd === 'preview') {
764
+ const { runPreviewCmd } = await import('./preview.js');
765
+ return runPreviewCmd(args.slice(1));
766
+ }
864
767
  if (cmd === 'serve') {
865
768
  const { runServeCmd } = await import('./serve.js');
866
769
  return runServeCmd(args.slice(1));
867
770
  }
868
771
  if (cmd === 'deploy') {
869
772
  // Lazy-load (serve precedent) so the deploy stack — incl. esbuild via
870
- // deploy-bundle — never taxes `yolo plan` startup.
773
+ // deploy-bundle is loaded only for hosting commands.
871
774
  const { runDeployCmd } = await import('./deploy-cli.js');
872
775
  return runDeployCmd(args.slice(1));
873
776
  }
@@ -875,7 +778,9 @@ async function main(argv) {
875
778
  printHelp();
876
779
  return 64; // EX_USAGE
877
780
  }
878
- main(process.argv).then((code) => process.exit(code), (err) => {
781
+ // Never `process.exit()` straight after writing: output to a pipe is async and
782
+ // would be cut at the 64 KiB pipe buffer (see ./exit.ts).
783
+ main(process.argv).then((code) => exitAfterFlush(code), (err) => {
879
784
  process.stderr.write(`yolo: unexpected error: ${err?.message ?? err}\n`);
880
- process.exit(1);
785
+ exitAfterFlush(1);
881
786
  });
@@ -93,21 +93,11 @@ export async function uploadAssetBucket(ctx, projectId, shipId, files) {
93
93
  * | 410 upload-expired (ship session lapsed → rerun)
94
94
  */
95
95
  /**
96
- * Best-effort substrate run-context headers for the finalize leg. When `yolo
97
- * deploy` runs inside a Plan-Run lane the pod env carries the run ids, so we
98
- * forward them and the server stamps release PROVENANCE — letting an auditor
99
- * walk a live URL back to the run that shipped it. These are CLIENT-ASSERTED
100
- * over the user JWT (NOT cryptographically bound like the MCP token path), so
101
- * the server records them as `source: 'cli-env'`: unverified audit metadata,
102
- * never authorizing. Omitted entirely for an interactive `yolo deploy` run
103
- * outside a lane (none of the vars set).
96
+ * Caller-reported session provenance for hosting audit metadata.
97
+ * This header never authorizes a deployment or rollback.
104
98
  */
105
- export function runContextHeaders(env) {
99
+ export function sessionContextHeaders(env) {
106
100
  const headers = {};
107
- if (env.YOLO_RUN_PLAN_ID)
108
- headers['X-Yolo-Run-Plan-Id'] = env.YOLO_RUN_PLAN_ID;
109
- if (env.YOLO_RUN_STEP_RUN_ID)
110
- headers['X-Yolo-Run-Step-Run-Id'] = env.YOLO_RUN_STEP_RUN_ID;
111
101
  if (env.SESSION_ID)
112
102
  headers['X-Yolo-Session-Id'] = env.SESSION_ID;
113
103
  return headers;
@@ -127,14 +117,14 @@ export async function finalizeShip(ctx, projectId, shipId, modules = [], sourceM
127
117
  if (!fetchImpl)
128
118
  return noFetchFailure();
129
119
  const url = `${stripTrailingSlash(ctx.commonApiUrl)}/v1/deploy/projects/${enc(projectId)}/ship/${enc(shipId)}/finalize`;
130
- // Substrate run-context provenance headers (best-effort; empty outside a lane).
131
- const runHeaders = runContextHeaders(ctx.env);
120
+ // Optional session provenance for the hosting audit record.
121
+ const requestHeaders = sessionContextHeaders(ctx.env);
132
122
  // Resume-after-grant: the pending-store rerun redeems the operator's grant
133
123
  // explicitly (x-approval-id → approvalNonce server-side), which yields crisp
134
124
  // approval-pending/-denied/-expired outcomes instead of the nonce-less
135
125
  // retry-redeem's blended ones.
136
126
  if (opts.approvalId)
137
- runHeaders['x-approval-id'] = opts.approvalId;
127
+ requestHeaders['x-approval-id'] = opts.approvalId;
138
128
  let response;
139
129
  try {
140
130
  if (modules.length > 0) {
@@ -150,14 +140,14 @@ export async function finalizeShip(ctx, projectId, shipId, modules = [], sourceM
150
140
  // No explicit Content-Type — fetch sets the multipart boundary itself.
151
141
  response = await fetchImpl(url, {
152
142
  method: 'POST',
153
- headers: { Authorization: `Bearer ${token}`, ...runHeaders },
143
+ headers: { Authorization: `Bearer ${token}`, ...requestHeaders },
154
144
  body: form,
155
145
  });
156
146
  }
157
147
  else {
158
148
  response = await fetchImpl(url, {
159
149
  method: 'POST',
160
- headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', ...runHeaders },
150
+ headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', ...requestHeaders },
161
151
  body: JSON.stringify({}),
162
152
  });
163
153
  }
@@ -238,12 +228,12 @@ export async function listProjects(ctx) {
238
228
  }
239
229
  /** POST /v1/deploy/projects/:id/rollback */
240
230
  export async function rollbackProject(ctx, projectId, request = {}) {
241
- // Rollback is a prod re-activation — forward run-context so the server can
231
+ // Rollback is a prod re-activation — forward session context so the server can
242
232
  // stamp `rollback.provenance` (same audit basis as a ship's finalize leg).
243
233
  return jsonLeg(ctx, `/deploy/projects/${enc(projectId)}/rollback`, {
244
234
  method: 'POST',
245
235
  jsonBody: request,
246
- headers: runContextHeaders(ctx.env),
236
+ headers: sessionContextHeaders(ctx.env),
247
237
  });
248
238
  }
249
239
  /** POST /v1/deploy/projects/:id/unpublish — take a live project offline (reversible). */
@@ -9,7 +9,7 @@
9
9
  * is the session JWT; `projectId` is non-secret and ownership-checked
10
10
  * server-side on every call.
11
11
  *
12
- * Canonical write shape (mirrors `lockfile.ts` write discipline):
12
+ * Canonical write shape:
13
13
  * - JSON, 2-space indent, single trailing `\n`.
14
14
  * - Fixed key order per the spec example: $version, projectId, slug,
15
15
  * type, build{command,outputDir}, worker{entry,assetsDir},
@@ -305,8 +305,7 @@ function collectUnknownKeyWarnings(obj) {
305
305
  /**
306
306
  * Reorder to the spec's fixed key order, omitting absent optionals.
307
307
  * Binding entries keep `kind`, `binding` first; extra hint keys follow
308
- * lex-sorted (same rule the plan-file canonicalizer applies to
309
- * free-form maps). Pure — does not mutate input.
308
+ * in lexicographic order. Pure — does not mutate input.
310
309
  */
311
310
  function canonicalize(config) {
312
311
  const out = { $version: 1 };
package/dist/exit.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Exit only after stdout and stderr have flushed.
3
+ *
4
+ * When stdout is a pipe (`yolo kanban export <tile> | jq`), Node writes to it
5
+ * asynchronously, and `process.exit()` drops whatever the kernel pipe buffer
6
+ * (64 KiB on Linux) has not accepted yet: a large export arrived as exactly
7
+ * 65,536 bytes of truncated JSON, with exit status 0. A file or TTY is written
8
+ * synchronously, which is why `-o <file>` was unaffected.
9
+ *
10
+ * A zero-length write's callback runs after every earlier write on that
11
+ * stream has been handed to the OS, so exiting from both callbacks loses
12
+ * nothing. The explicit exit is kept (rather than just setting exitCode)
13
+ * because some commands can leave handles open that would otherwise keep the
14
+ * process alive.
15
+ */
16
+ export function exitAfterFlush(code, streams = [process.stdout, process.stderr], exit = (c) => process.exit(c)) {
17
+ process.exitCode = code;
18
+ let pending = streams.length;
19
+ if (pending === 0) {
20
+ exit(code);
21
+ return;
22
+ }
23
+ const settle = () => { if (--pending === 0)
24
+ exit(code); };
25
+ for (const stream of streams) {
26
+ // A destroyed or errored stream (e.g. the reader closed the pipe) never
27
+ // calls back; treat it as flushed rather than hanging the process.
28
+ if (stream.destroyed || !stream.writable) {
29
+ settle();
30
+ continue;
31
+ }
32
+ stream.write('', settle);
33
+ }
34
+ }