@yolo-labs/yolo-cli 1.3.0 → 1.4.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.
@@ -20,6 +20,7 @@
20
20
  */
21
21
  import * as path from 'node:path';
22
22
  import * as fs from 'node:fs';
23
+ import * as os from 'node:os';
23
24
  import { spawn, execFileSync } from 'node:child_process';
24
25
  import { readDeployConfig } from './deploy-config.js';
25
26
  import { detectProjectShape, readWranglerCrons } from './deploy-detect.js';
@@ -44,6 +45,8 @@ export async function runDeployShip(options) {
44
45
  const runBuild = deps.runBuildImpl ?? defaultRunBuild;
45
46
  const readAssetFile = deps.readAssetFileImpl ?? defaultReadAssetFile;
46
47
  const resolveGitSha = deps.resolveGitShaImpl ?? defaultResolveGitSha;
48
+ const resolveGitTreeState = deps.resolveGitTreeStateImpl ?? defaultResolveGitTreeState;
49
+ const warn = options.warn ?? ((line) => process.stderr.write(`${line}\n`));
47
50
  const resolveRepoOrigin = deps.resolveRepoOriginImpl ?? defaultResolveRepoOrigin;
48
51
  // 1. Link — .yolo/deploy.json with a projectId is the durable bond.
49
52
  const readResult = readConfig(cwd);
@@ -238,6 +241,21 @@ export async function runDeployShip(options) {
238
241
  const gitSha = resolveGitSha(cwd);
239
242
  if (gitSha)
240
243
  request.gitSha = gitSha;
244
+ // gitSha names HEAD, which is NOT what was built when the tree is dirty. Say
245
+ // so on the release (gitDirty) and record the hash of the tree actually on
246
+ // disk (gitTreeHash), so a dirty release is never mistaken for HEAD. Both are
247
+ // sent whenever git could answer (gitDirty:false included, so "clean" is a
248
+ // recorded fact rather than an absence); a non-git dir omits both.
249
+ const treeState = resolveGitTreeState(cwd);
250
+ if (treeState) {
251
+ request.gitDirty = treeState.dirty;
252
+ request.gitTreeHash = treeState.treeHash;
253
+ if (treeState.dirty) {
254
+ warn(`Warning: deploying from a dirty working tree (${treeState.changedFiles} changed file${treeState.changedFiles === 1 ? '' : 's'}). ` +
255
+ `The release records gitSha ${gitSha ?? '(none)'} with dirty: true and treeHash ${treeState.treeHash}; ` +
256
+ 'commit first for a reproducible release.');
257
+ }
258
+ }
241
259
  // The source repo these exact bytes were built from. This is the only place
242
260
  // in the system that can know it — the server sees a bundle, and the owning
243
261
  // workspace may be gone by the time anyone asks. Best-effort in the same
@@ -340,6 +358,9 @@ export async function runDeployShip(options) {
340
358
  for (const line of pageCheckLines(pageCheck))
341
359
  progress(line);
342
360
  }
361
+ const sharedData = parseSharedData(finalized.value.sharedData);
362
+ if (sharedData)
363
+ progress(`deploy: warn — ${sharedData.notice}`);
343
364
  return {
344
365
  ok: true,
345
366
  dryRun: false,
@@ -349,6 +370,7 @@ export async function runDeployShip(options) {
349
370
  url: finalized.value.url,
350
371
  ...(bootCheck ? { bootCheck } : {}),
351
372
  ...(pageCheck ? { pageCheck } : {}),
373
+ ...(sharedData ? { sharedData } : {}),
352
374
  };
353
375
  }
354
376
  /**
@@ -378,6 +400,9 @@ async function resumeStagedShip(ctx, resume, io) {
378
400
  for (const line of pageCheckLines(pageCheck))
379
401
  progress(line);
380
402
  }
403
+ const sharedData = parseSharedData(finalized.value.sharedData);
404
+ if (sharedData)
405
+ progress(`deploy: warn — ${sharedData.notice}`);
381
406
  return {
382
407
  ok: true,
383
408
  dryRun: false,
@@ -397,6 +422,7 @@ async function resumeStagedShip(ctx, resume, io) {
397
422
  // warning goes to stderr and the structured verdict + samples would
398
423
  // otherwise be lost entirely for a resumed (approval-parked) ship.
399
424
  ...(pageCheck ? { pageCheck } : {}),
425
+ ...(sharedData ? { sharedData } : {}),
400
426
  };
401
427
  }
402
428
  // Still parked: the grant hasn't landed yet (approval-pending), or the
@@ -470,6 +496,22 @@ async function resumeStagedShip(ctx, resume, io) {
470
496
  function describeErrorMessage(err) {
471
497
  return err instanceof Error ? err.message : String(err);
472
498
  }
499
+ /** Narrow the backend's optional preview `sharedData` warning; ignore anything malformed. */
500
+ function parseSharedData(raw) {
501
+ if (!raw || typeof raw !== 'object')
502
+ return undefined;
503
+ const r = raw;
504
+ if (typeof r.notice !== 'string' || !r.notice)
505
+ return undefined;
506
+ const names = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
507
+ return {
508
+ d1: names(r.d1),
509
+ kv: names(r.kv),
510
+ r2: names(r.r2),
511
+ secretCount: typeof r.secretCount === 'number' ? r.secretCount : 0,
512
+ notice: r.notice,
513
+ };
514
+ }
473
515
  /** Narrow the backend's optional `bootCheck` envelope; ignore anything malformed. */
474
516
  function parseBootCheck(raw) {
475
517
  if (!raw || typeof raw !== 'object')
@@ -745,6 +787,77 @@ function defaultResolveGitSha(cwd) {
745
787
  return undefined;
746
788
  }
747
789
  }
790
+ const TREE_HASH_RE = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
791
+ /**
792
+ * `git status --porcelain` for dirtiness, then the tree hash of what is on
793
+ * disk. Clean ⇒ `HEAD^{tree}`. Dirty ⇒ a SCRATCH index (GIT_INDEX_FILE in
794
+ * os.tmpdir) seeded from HEAD, `add -A`, `write-tree` — the user's real index
795
+ * is never read or written, and .gitignore is honoured exactly as `git add`
796
+ * would. Side effect: `add -A` writes the dirty files' blobs into the object
797
+ * store as loose objects (unreferenced; a normal `git gc` reaps them).
798
+ *
799
+ * Best-effort: any failure (not a repo, no commits yet, git missing, timeout)
800
+ * ⇒ undefined, and the ship proceeds without the fields.
801
+ */
802
+ export function defaultResolveGitTreeState(cwd) {
803
+ const git = (args, env) => execFileSync('git', args, {
804
+ cwd,
805
+ stdio: ['ignore', 'pipe', 'ignore'],
806
+ timeout: 30000,
807
+ maxBuffer: 64 * 1024 * 1024,
808
+ ...(env ? { env } : {}),
809
+ }).toString();
810
+ let scratchDir;
811
+ try {
812
+ // -z: one NUL-terminated record per entry (renames carry a 2nd path field).
813
+ const status = git(['status', '--porcelain', '-z', '--untracked-files=all']);
814
+ const changedFiles = countPorcelainZEntries(status);
815
+ let treeHash;
816
+ if (changedFiles === 0) {
817
+ treeHash = git(['rev-parse', 'HEAD^{tree}']).trim();
818
+ }
819
+ else {
820
+ scratchDir = fs.mkdtempSync(path.join(os.tmpdir(), 'yolo-deploy-index-'));
821
+ const env = { ...process.env, GIT_INDEX_FILE: path.join(scratchDir, 'index') };
822
+ git(['read-tree', 'HEAD'], env);
823
+ // `:/` — the whole worktree even when cwd is a subdirectory, matching
824
+ // what status reported and what HEAD^{tree} describes when clean.
825
+ git(['add', '-A', '--', ':/'], env);
826
+ treeHash = git(['write-tree'], env).trim();
827
+ }
828
+ if (!TREE_HASH_RE.test(treeHash))
829
+ return undefined;
830
+ return { dirty: changedFiles > 0, changedFiles, treeHash };
831
+ }
832
+ catch {
833
+ return undefined;
834
+ }
835
+ finally {
836
+ if (scratchDir) {
837
+ try {
838
+ fs.rmSync(scratchDir, { recursive: true, force: true });
839
+ }
840
+ catch {
841
+ // best-effort cleanup of a tmp dir
842
+ }
843
+ }
844
+ }
845
+ }
846
+ /** Count entries in `git status --porcelain -z` output (renames/copies carry two fields). */
847
+ function countPorcelainZEntries(out) {
848
+ const fields = out.split('\0');
849
+ let count = 0;
850
+ for (let i = 0; i < fields.length; i++) {
851
+ const field = fields[i];
852
+ if (field.length < 4)
853
+ continue;
854
+ count++;
855
+ const x = field[0];
856
+ if (x === 'R' || x === 'C')
857
+ i++; // skip the original-path field
858
+ }
859
+ return count;
860
+ }
748
861
  const CONTENT_TYPES = {
749
862
  '.html': 'text/html',
750
863
  '.htm': 'text/html',
@@ -715,8 +715,9 @@ export async function runTileAppPublishPersonal(opts) {
715
715
  ].join('\n'),
716
716
  };
717
717
  }
718
+ const pinLines = portalPinLines(uploadJson.portalPins);
718
719
  if (!isWorker)
719
- return { ok: true, output: [summary, ...next].join('\n') };
720
+ return { ok: true, output: [summary, ...pinLines, ...next].join('\n') };
720
721
  // A worker app's bundle is stored either way; `publish` says whether its
721
722
  // backend made it, and `live` whether that backend runs on Dynamic Workers.
722
723
  // A version with no backend serves a UI whose /api/* is dead, so it is a failure.
@@ -738,7 +739,7 @@ export async function runTileAppPublishPersonal(opts) {
738
739
  else {
739
740
  lines.push(' backend: no worker placement report — the worker placement may be off on this deployment, so the backend was not published.');
740
741
  }
741
- lines.push(...next);
742
+ lines.push(...pinLines, ...next);
742
743
  return { ok: true, output: lines.join('\n') };
743
744
  }
744
745
  /** The refusal code (HTTP 409) for a live worker tile when Dynamic Workers is off on the deployment. */
@@ -790,6 +791,19 @@ export function installNextLines(appId, workspaceId, report) {
790
791
  return [` next: if it's already installed, ${install} moves the install to this version; if not, also run ${addTile}`];
791
792
  }
792
793
  }
794
+ /** The publish report's lines for portal pins: a pin that stopped serving says so, with the fix. */
795
+ export function portalPinLines(pins) {
796
+ if (!Array.isArray(pins) || pins.length === 0)
797
+ return [];
798
+ return pins.slice(0, 20).map((p) => {
799
+ const where = p.scope === 'project' ? `pinned as project default on ${p.projectId}` : `pinned for customer ${p.relationshipId} (project ${p.projectId})`;
800
+ if (p.follow === 'latest-published')
801
+ return ` portal: ${where}, follows latest published — customers now get ${p.servingVersion ?? 'this version'}`;
802
+ if (p.serving)
803
+ return ` portal: ${where} — serving ${p.servingVersion ?? 'the pinned version'}`;
804
+ return ` portal: ${where} — not serving until re-pinned (mogul.portal_app_set; add follow: "latest-published" to skip this next time)`;
805
+ });
806
+ }
793
807
  /**
794
808
  * Build the app image in-pod with podman, `save` it to an OCI archive in the
795
809
  * workspace, and hand it to common-api's MEDIATED push endpoint — common-api
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yolo-labs/yolo-cli",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "YOLO Studio CLI for workspace context, artifacts, personal apps and hosting.",
5
5
  "license": "MIT",
6
6
  "repository": {