@coderook/cli 0.46.8 → 0.46.10

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.
@@ -58,6 +58,7 @@ const rules_js_1 = require("../../cbx/src/core/rules.js");
58
58
  const upload_js_1 = require("../../cbx/src/core/upload.js");
59
59
  const download_js_1 = require("../../cbx/src/core/download.js");
60
60
  const machine_js_1 = require("./machine.js");
61
+ const pending_merges_js_1 = require("./pending_merges.js");
61
62
  const workspace_machine_js_1 = require("./workspace_machine.js");
62
63
  const safe_path_js_1 = require("../../cbx/src/shared/safe_path.js");
63
64
  const faults_js_1 = require("../../cbx/src/core/faults.js");
@@ -561,6 +562,37 @@ function announcing(run, saved) {
561
562
  return code;
562
563
  };
563
564
  }
565
+ /*
566
+ Changes here that a save of this machine already kept as a merge, still
567
+ waiting for a decision. Asked of the service only when one was noted, so a
568
+ plain status costs nothing more; applied or cancelled ones are forgotten.
569
+ */
570
+ async function mergesWaiting(repositoryId, changed) {
571
+ if (!repositoryId)
572
+ return;
573
+ const noted = await (0, pending_merges_js_1.pendingMerges)(repositoryId);
574
+ if (!noted.length)
575
+ return;
576
+ const here = new Set(changed);
577
+ const settled = new Set();
578
+ for (const merge of noted.slice(-5)) {
579
+ const state = await (0, api_js_1.mergeTrack)(merge.id).then((detail) => detail.mergeTrack.state, () => null);
580
+ if (state === null)
581
+ continue;
582
+ if (state !== "open") {
583
+ settled.add(merge.id);
584
+ continue;
585
+ }
586
+ const overlap = merge.paths.filter((one) => here.has(one));
587
+ if (!overlap.length)
588
+ continue;
589
+ console.log(dim(`\n${overlap.length === 1 ? overlap[0] : `${overlap.length} of these`} ${overlap.length === 1 ? "is" : "are"} already kept as `) +
590
+ accent(merge.reference) +
591
+ dim(", waiting for a decision: ") + accent(`cbx merge ${merge.reference}`) +
592
+ dim(". Saving again keeps another copy beside it."));
593
+ }
594
+ await (0, pending_merges_js_1.forgetMerges)(repositoryId, settled).catch(() => undefined);
595
+ }
564
596
  async function commandStatus(parsed) {
565
597
  const folder = folderFor(parsed);
566
598
  let link;
@@ -659,16 +691,44 @@ async function commandStatus(parsed) {
659
691
  dropped it from this folder's record. Told plainly, since the one advice
660
692
  above would bring back a file the person meant to be rid of.
661
693
  */
694
+ /*
695
+ Told apart by this folder's own record: a file it never held is somebody
696
+ else's new file, which cbx get brings; one it held and no longer has was
697
+ deleted here. Both were told "if you deleted it yourself…", so a
698
+ teammate's new file read as a deletion (2026-11-11 exercise 2).
699
+ */
662
700
  const absent = stale.filter(([file]) => !(0, node_fs_1.existsSync)(node_path_1.default.join(folder, ...file.split("/"))));
663
- if (absent.length) {
664
- const one = absent.length === 1;
665
- const which = absent.length === stale.length
666
- ? one ? "It is not" : "They are not"
667
- : `${absent.length} of them ${one ? "is" : "are"} not`;
668
- console.log(dim(`${which} in this folder at all. If you deleted ${one ? "it" : "them"} yourself, ` +
669
- `run ${accent("cbx get")}, delete ${one ? "it" : "them"} again, and save with ${accent("--sync")}.`));
701
+ const newThere = absent.filter(([file]) => link.local[file] === undefined);
702
+ const goneHere = absent.filter(([file]) => link.local[file] !== undefined);
703
+ if (newThere.length) {
704
+ const one = newThere.length === 1;
705
+ console.log(dim(`${newThere.length} of them ${one ? "is a new file" : "are new files"} from the saved version, not here yet; `) +
706
+ accent("cbx get") + dim(` brings ${one ? "it" : "them"}.`));
707
+ }
708
+ if (goneHere.length) {
709
+ const one = goneHere.length === 1;
710
+ console.log(dim(`${goneHere.length} of them ${one ? "was" : "were"} deleted here and changed in the saved version since. ` +
711
+ `cbx get leaves ${one ? "it" : "them"} deleted; `) +
712
+ accent("cbx submit --sync") + dim(" saves the deletion, ") + accent("cbx get --replace") + dim(` brings ${one ? "it" : "them"} back.`));
670
713
  }
671
714
  }
715
+ /*
716
+ The other way round: files this folder holds that the saved version no
717
+ longer has, because somebody removed them. Status never said, and the next
718
+ cbx get removed eleven files nobody here had been told about (2026-11-11
719
+ exercise 2). Only files this folder wrote count; get leaves a file you
720
+ changed since alone.
721
+ */
722
+ const removedThere = link?.local
723
+ ? Object.keys(link.local).filter((file) => link.manifest[file] === undefined && (0, node_fs_1.existsSync)(node_path_1.default.join(folder, ...file.split("/"))))
724
+ : [];
725
+ if (removedThere.length) {
726
+ const one = removedThere.length === 1;
727
+ console.log(dim(`${removedThere.length} file${one ? "" : "s"} here ${one ? "was" : "were"} removed in the saved version; `) +
728
+ accent("cbx get") + dim(` removes ${one ? "it" : "them"} here too.`));
729
+ for (const file of removedThere.slice(0, 10))
730
+ console.log(dim(` removed ${file}`));
731
+ }
672
732
  /** The deletions, and what a plain save will do about them. */
673
733
  /*
674
734
  What this folder is, and what its own rules never heard about.
@@ -748,6 +808,7 @@ async function commandStatus(parsed) {
748
808
  }
749
809
  if (files.length > 50)
750
810
  console.log(dim(` …and ${files.length - 50} more`));
811
+ await mergesWaiting(link?.repositoryId, files.map((file) => file.path));
751
812
  deletions();
752
813
  await engine();
753
814
  return 0;
@@ -1360,6 +1421,22 @@ Pass ${accent("--allow-secrets")} if these are not real keys.`);
1360
1421
  presence: await (0, machine_js_1.checkInBody)({ kind: "folder", folder, track: link.track ?? null, changedFiles: 0 }),
1361
1422
  });
1362
1423
  }
1424
+ /*
1425
+ Where the save comes from, kept with the version for the project's people
1426
+ (cbx versions): this machine, unless check-ins are off, and the name an
1427
+ assistant or script gave itself. Eight assistants on one account could not
1428
+ be told apart in History (2026-11-11 agent exercise).
1429
+ */
1430
+ {
1431
+ const named = flagText(parsed, "as") ?? (node_process_1.default.env.CBX_NAME || undefined);
1432
+ const me = node_process_1.default.env.CODEROOK_NO_PRESENCE ? null : await (0, machine_js_1.machineIdentity)();
1433
+ const savedFrom = {
1434
+ ...(me ? { machineId: me.id, machine: me.name } : {}),
1435
+ ...(named?.trim() ? { as: named.trim().slice(0, 80) } : {}),
1436
+ };
1437
+ if (Object.keys(savedFrom).length)
1438
+ Object.assign(uploadRequest, { savedFrom });
1439
+ }
1363
1440
  /*
1364
1441
  Whether this is walking into a merge, asked before anything is sent.
1365
1442
 
@@ -1575,7 +1652,18 @@ The connection failed: ${text}`));
1575
1652
  }
1576
1653
  console.log(`\nRun ${accent(`cbx merge ${result.mergeTrack.reference}`)} to decide,` +
1577
1654
  ` or ${accent("cbx merges")} to see everything waiting.`);
1578
- return 0;
1655
+ /* So cbx status can say this change is already waiting, rather than invite saving it twice. */
1656
+ await (0, pending_merges_js_1.rememberMerge)(result.repositoryId, {
1657
+ id: result.mergeTrack.id,
1658
+ reference: result.mergeTrack.reference,
1659
+ paths: result.mergeTrack.conflicts.map((conflict) => conflict.path),
1660
+ at: new Date().toISOString(),
1661
+ }).catch(() => undefined);
1662
+ /*
1663
+ 3, not 0: the work is kept, but the line did not move. Scripts and agents
1664
+ read 0 as saved and carried on (2026-11-11 agent exercise).
1665
+ */
1666
+ return 3;
1579
1667
  }
1580
1668
  /*
1581
1669
  The version exists on the account. Stopping before the line below is the
@@ -1630,8 +1718,16 @@ The connection failed: ${text}`));
1630
1718
  ` nothing was sent again.`);
1631
1719
  return 0;
1632
1720
  }
1721
+ /*
1722
+ Files sent again only to be gathered into one pack are counted apart: "sent
1723
+ 64 files" for a one-line change read as 63 files nobody touched having
1724
+ changed (GrokBot3, 2026-11-11).
1725
+ */
1726
+ const repacked = Math.min(result.repackedFiles ?? 0, result.sentFiles);
1727
+ const changedSent = result.sentFiles - repacked;
1633
1728
  console.log(`Saved ${accent(`v${result.sequence}`)} · sent ${bytes(result.sentBytes)} in ` +
1634
- `${result.sentFiles} file${result.sentFiles === 1 ? "" : "s"}` +
1729
+ `${changedSent} file${changedSent === 1 ? "" : "s"}` +
1730
+ (repacked ? ` (and re-packed ${repacked} unchanged small file${repacked === 1 ? "" : "s"} together)` : "") +
1635
1731
  /*
1636
1732
  Three different things, kept apart. Sent is what crossed the wire.
1637
1733
  Already on the account is content the service turned out to have, which
@@ -1642,13 +1738,24 @@ The connection failed: ${text}`));
1642
1738
  ? `, ${result.alreadyStoredFiles} already on the account`
1643
1739
  : "") +
1644
1740
  (result.reusedFiles ? `, ${result.reusedFiles} unchanged` : "") +
1741
+ /* What --sync removed, which the line used not to mention at all (GrokBot3, v145). */
1742
+ (hasFlag(parsed, "sync") && files.some((file) => file.deleted)
1743
+ ? `, ${files.filter((file) => file.deleted).length} removed`
1744
+ : "") +
1645
1745
  /*
1646
1746
  "version holds" was the old fused vocabulary. `cbx submit` makes a
1647
1747
  save; a save becomes a version when somebody names it, which is what
1648
1748
  `cbx release` does. Saying "version" here promised something this
1649
1749
  command does not do.
1650
1750
  */
1651
- ` · the save holds ${bytes(result.sourceBytes)}`);
1751
+ /*
1752
+ Both sizes, named: "holds 2.9 MB" beside 858 KB in cbx versions read as
1753
+ a contradiction. One is the files' size, the other what storage keeps.
1754
+ */
1755
+ ` · the save holds ${bytes(result.sourceBytes)}` +
1756
+ (result.storedBytes && result.storedBytes < result.sourceBytes
1757
+ ? ` (${bytes(result.storedBytes)} stored)`
1758
+ : ""));
1652
1759
  noteKeptDeletions(folder, baseline, hasFlag(parsed, "sync"), seen);
1653
1760
  noteGitRoute(folder, link?.slug ?? adopt?.slug ?? (0, folder_match_js_1.slugFor)(flagText(parsed, "name") ?? node_path_1.default.basename(folder)));
1654
1761
  /*
@@ -2074,6 +2181,19 @@ trackName) {
2074
2181
  else {
2075
2182
  console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
2076
2183
  }
2184
+ /*
2185
+ A big file brought up to date by its changed pieces only. Without this, a
2186
+ 40 MiB file's update read like a 40 MiB download (2026-11-11 exercise 2).
2187
+ */
2188
+ const reused = result.piecesReused ?? 0;
2189
+ if (reused) {
2190
+ console.log(dim(`${reused.toLocaleString("en-US")} unchanged piece${reused === 1 ? "" : "s"} of large files came from the copies here; only the changed pieces were fetched.`));
2191
+ }
2192
+ const leftDeleted = result.leftDeleted ?? 0;
2193
+ if (leftDeleted) {
2194
+ console.log(dim(`${fileCount(leftDeleted)} you deleted here and have not saved ${leftDeleted === 1 ? "was" : "were"} left deleted; ` +
2195
+ `cbx submit --sync saves the deletion, cbx get --replace brings ${leftDeleted === 1 ? "it" : "them"} back.`));
2196
+ }
2077
2197
  return 0;
2078
2198
  }
2079
2199
  /**
@@ -2357,6 +2477,8 @@ async function findMerge(folder, reference) {
2357
2477
  * Deciding happens here rather than in a command of its own because the
2358
2478
  * decision only means anything next to the thing it is about.
2359
2479
  */
2480
+ /* A decision in the words the flags use; the service's own names (take_candidate) read as internals (exercise 2). */
2481
+ const resolutionWords = (resolution) => ({ take_candidate: "yours", take_target: "theirs", keep_both: "both", delete: "removed" }[resolution] ?? resolution);
2360
2482
  async function commandMerge(parsed) {
2361
2483
  const reference = parsed.positional[0];
2362
2484
  if (!reference) {
@@ -2450,7 +2572,7 @@ ${accent(now.mergeTrack.reference)} · ` +
2450
2572
  : `${now.provisional.unresolvedPaths.length} still to decide`));
2451
2573
  for (const conflict of now.conflicts) {
2452
2574
  console.log(` ${conflict.resolvedAt ? accent("decided") : red("waiting")} ${conflict.path}` +
2453
- ` ${dim(conflictWords(conflict.kind))}${conflict.resolution ? dim(` (${conflict.resolution})`) : ""}`);
2575
+ ` ${dim(conflictWords(conflict.kind))}${conflict.resolution ? dim(` (${resolutionWords(conflict.resolution)})`) : ""}`);
2454
2576
  }
2455
2577
  if (hasFlag(parsed, "apply")) {
2456
2578
  if (!now.provisional.ready) {
@@ -2661,7 +2783,10 @@ const SPECS = [
2661
2783
  "into it, --new starts a separate one.\n\n" +
2662
2784
  "A save is not a version. Nobody outside the project can see one until\n" +
2663
2785
  "it is named, which is what `cbx release` does — so submitting is as\n" +
2664
- "cheap and as private as you want it to be.",
2786
+ "cheap and as private as you want it to be.\n\n" +
2787
+ "Exits 0 when the save is on the line, 3 when it is kept as a merge\n" +
2788
+ "because somebody changed the same lines (cbx merges lists it), and\n" +
2789
+ "1 when it failed.",
2665
2790
  options: [
2666
2791
  { flags: "-m, --message <text>", description: "what changed, in a sentence" },
2667
2792
  { flags: "-n, --dry-run", description: "show what would be sent, send nothing" },
@@ -2693,6 +2818,10 @@ const SPECS = [
2693
2818
  flags: "--no-licence",
2694
2819
  description: "do not add a licence to a new project; nobody may reuse it",
2695
2820
  },
2821
+ {
2822
+ flags: "--as <name>",
2823
+ description: "the name an assistant or script saves under (or set CBX_NAME); the project's people see it in cbx versions",
2824
+ },
2696
2825
  ],
2697
2826
  examples: [
2698
2827
  'cbx submit -m "Fix the export dialog"',
@@ -3083,9 +3212,9 @@ const SPECS = [
3083
3212
  name: "workspace",
3084
3213
  group: "Workspaces",
3085
3214
  summary: "edit, save and run a private project remotely without a checkout",
3086
- usage: "workspace | workspace <usage|open|list|show|read|files|search|diff|patch|put|starter|review|reviewers|save|run|logs|cancel|deploy|preview|handoff|close|recipe|assign|assignments|unassign|checkout|say|thread|mute|unmute> <project> [workspace] [job] | workspace put <project> <workspace> <path…> | workspace push [folder] | workspace watch [project] [workspace]",
3215
+ usage: "workspace | workspace <usage|open|list|show|read|files|search|diff|patch|put|starter|review|reviewers|save|run|runs|logs|cancel|deploy|preview|handoff|close|reopen|recipe|assign|assignments|unassign|checkout|say|thread|mute|unmute> <project> [workspace] [job] | workspace put <project> <workspace> <path…> | workspace push [folder] | workspace watch [project] [workspace]",
3087
3216
  brief: "workspace <action> <project>",
3088
- detail: "Works on CodeRook's durable remote draft, never the current local folder. Use --data-file for structured edits or recipe configuration. Mutations need the reviewed --revision and a unique --key; reuse the same key and request when retrying. Recipes reference existing project workflows. Usage reads the shared workspace credits and separate PR allowance without a draft ID. put copies files from this folder into a draft: text as text, images, fonts and other binary files as bytes (up to 1 MiB each), a file that is gone here is removed there, and each file must still be the version the draft holds, so a teammate's edit is never overwritten. starter reads this folder (package.json scripts, Cargo.toml, go.mod, Python) and suggests one check recipe per package so drafts have something to run; --apply adds them, never replacing a recipe that exists. review shows who must OK a draft before it is saved or deployed; --ok or --changes -m gives your verdict on the current revision, and counts only from the reviewer's own sign-in or token, never a name given with --as. reviewers lists the project's rules, and an administrator sets them with --data-file. Saving and deploying are separate operations. Run on its own at a terminal, it lists your open workspaces with their unread messages: choose one to see its changes and what is being discussed, and reply, save, run checks, hand it over or close it with one key. say and thread post to and read a workspace's discussion as JSON; a machine signed in to your account can name itself with --as (or CBX_NAME) so its messages and unread count are its own. watch prints each new message, each message addressed to you (@your name, or the name given with --as) and each new saved version as it happens, until stopped; --json gives one JSON object per line for a program.",
3217
+ detail: "Works on CodeRook's durable remote draft, never the current local folder. Use --data-file for structured edits or recipe configuration. Mutations need the reviewed --revision and a unique --key; reuse the same key and request when retrying. Recipes reference existing project workflows. Usage reads the shared workspace credits and separate PR allowance without a draft ID. put copies files from this folder into a draft: text as text, images, fonts and other binary files as bytes (up to 1 MiB each), a file that is gone here is removed there, and each file must still be the version the draft holds, so a teammate's edit is never overwritten. starter reads this folder (package.json scripts, Cargo.toml, go.mod, Python) and suggests one check recipe per package so drafts have something to run; --apply adds them, never replacing a recipe that exists. review shows who must OK a draft before it is saved or deployed; --ok or --changes -m gives your verdict on the current revision, and counts only from the reviewer's own sign-in or token, never a name given with --as. reviewers lists the project's rules, and an administrator sets them with --data-file. Saving and deploying are separate operations. close refuses a draft with edits that were never saved unless --unsaved is given (the edits are kept, not thrown away); reopen opens a closed draft again, edits and all. Run on its own at a terminal, it lists your open workspaces with their unread messages: choose one to see its changes and what is being discussed, and reply, save, run checks, hand it over or close it with one key. say and thread post to and read a workspace's discussion as JSON; a machine signed in to your account can name itself with --as (or CBX_NAME) so its messages and unread count are its own. watch prints each new message, each message addressed to you (@your name, or the name given with --as) and each new saved version as it happens, until stopped; --json gives one JSON object per line for a program.",
3089
3218
  options: [
3090
3219
  { flags: "--data-file <path>", description: "read an operation's JSON from this local file" },
3091
3220
  { flags: "--name <name>", description: "name a new workspace" },
@@ -3103,6 +3232,7 @@ const SPECS = [
3103
3232
  { flags: "--version <id>", description: "saved workspace version to deploy" },
3104
3233
  { flags: "-m, --message <text>", description: "describe the version being saved" },
3105
3234
  { flags: "--note <text>", description: "task context for another computer/assistant" },
3235
+ { flags: "--unsaved", description: "close: close a draft whose edits were never saved; they are kept and come back with reopen" },
3106
3236
  { flags: "--days <number>", description: "assign: how long the handed-over token lasts (1-90, default 14)" },
3107
3237
  { flags: "--save", description: "push: save the draft after sending the changes" },
3108
3238
  { flags: "--dry-run", description: "push: list what would be sent, send nothing" },
@@ -3118,7 +3248,7 @@ const SPECS = [
3118
3248
  { flags: "--interval <seconds>", description: "watch: how often to look (default 20, at least 5)" },
3119
3249
  ],
3120
3250
  examples: ["cbx workspace open my-project --name \"Laptop work\" --key laptop-open-001", "cbx workspace list my-project", "cbx workspace assign my-project <draft> --name Laptop", "cbx workspace checkout my-project <draft>", "cbx workspace push --save -m \"Fix the export dialog\"", "cbx workspace", "cbx workspace say my-project <draft> -m \"Tests updated\" --as GrokBot", "cbx workspace thread my-project <draft> --unread", "cbx workspace watch my-project --as GrokBot --json", "cbx workspace put my-project <draft> website/app/page.tsx website/public/og.png", "cbx workspace starter my-project --apply", "cbx workspace review my-project <draft> --ok -m \"Matches the concept\""],
3121
- arguments: { "[job]": "a job's name inside a run, for logs and cancel" },
3251
+ arguments: { "[job]": "the run's id (cbx workspace run prints it), for logs and cancel" },
3122
3252
  run: workspace_command_js_1.commandWorkspace,
3123
3253
  },
3124
3254
  {
@@ -30,17 +30,11 @@ const project_commands_js_1 = require("./project_commands.js");
30
30
  const merge_diff_js_1 = require("../../cbx/src/shared/merge_diff.js");
31
31
  const worktree_js_1 = require("../../cbx/src/core/worktree.js");
32
32
  /*
33
- Built rather than typed, so the escape character never sits literally in the
34
- source. The other command files spell theirs out; this reads the same on a
35
- terminal and survives being copied through a tool that eats control bytes.
33
+ The shared colours: only at a terminal, never with NO_COLOR. This file had its
34
+ own always-on copy, so cbx diff piped or under NO_COLOR=1 came back full of
35
+ escape codes (2026-11-11 agent exercise).
36
36
  */
37
- const ESC = String.fromCharCode(27);
38
- const paint = (code) => (value) => `${ESC}[${code}m${value}${ESC}[0m`;
39
- const dim = paint("2");
40
- const bold = paint("1");
41
- const red = paint("31");
42
- const green = paint("32");
43
- const accent = paint("33");
37
+ const colour_js_1 = require("./colour.js");
44
38
  /*
45
39
  The line comparison builds a table of one side's lines against the other's,
46
40
  which is exact and quadratic. On a conflicted file — what it was written for
@@ -49,35 +43,39 @@ const accent = paint("33");
49
43
  changed without its lines. Saying so beats both wedging the terminal and
50
44
  printing a heuristic diff that quietly invents a change.
51
45
  */
52
- const MOST_LINES_COMPARED = 4_000;
46
+ /*
47
+ More changed lines than this in one file are summarised rather than listed.
48
+ Files of any length are compared: only the changed part costs anything
49
+ (diffLinesWithin). It refused any file over 4,000 lines before.
50
+ */
51
+ const MOST_LINES_SHOWN = 4_000;
53
52
  /** How a change reads at a glance. */
54
53
  const MARK = {
55
- added: green("+"),
56
- removed: red("-"),
57
- changed: accent("~"),
54
+ added: (0, colour_js_1.green)("+"),
55
+ removed: (0, colour_js_1.red)("-"),
56
+ changed: (0, colour_js_1.accent)("~"),
58
57
  };
59
58
  /** Print one file's lines, folded to the interesting parts. */
60
59
  function printHunks(before, after, context) {
61
- const left = (0, merge_diff_js_1.linesOf)(before);
62
- const right = (0, merge_diff_js_1.linesOf)(after);
63
- if (left.length > MOST_LINES_COMPARED || right.length > MOST_LINES_COMPARED) {
64
- console.log(dim(` ${Math.max(left.length, right.length).toLocaleString()} lines — ` +
65
- `too large to compare line by line`));
60
+ const compared = (0, merge_diff_js_1.diffLinesWithin)(before, after, MOST_LINES_SHOWN);
61
+ if (!compared) {
62
+ const longest = Math.max((0, merge_diff_js_1.linesOf)(before).length, (0, merge_diff_js_1.linesOf)(after).length);
63
+ console.log((0, colour_js_1.dim)(` more than ${MOST_LINES_SHOWN.toLocaleString()} lines changed in ${longest.toLocaleString()} — too many to list`));
66
64
  return;
67
65
  }
68
- for (const chunk of (0, merge_diff_js_1.foldUnchanged)((0, merge_diff_js_1.diffLines)(before, after), context)) {
66
+ for (const chunk of (0, merge_diff_js_1.foldUnchanged)(compared, context)) {
69
67
  if (chunk.kind === "gap") {
70
- console.log(dim(` ... ${chunk.skipped} unchanged`));
68
+ console.log((0, colour_js_1.dim)(` ... ${chunk.skipped} unchanged`));
71
69
  continue;
72
70
  }
73
71
  for (const line of chunk.lines) {
74
72
  const at = String(line.candidateLine ?? line.targetLine ?? "").padStart(5);
75
73
  if (line.side === "same")
76
- console.log(dim(`${at} ${line.text}`));
74
+ console.log((0, colour_js_1.dim)(`${at} ${line.text}`));
77
75
  else if (line.side === "candidate")
78
- console.log(`${dim(at)} ${green("+")} ${green(line.text)}`);
76
+ console.log(`${(0, colour_js_1.dim)(at)} ${(0, colour_js_1.green)("+")} ${(0, colour_js_1.green)(line.text)}`);
79
77
  else
80
- console.log(`${dim(at)} ${red("-")} ${red(line.text)}`);
78
+ console.log(`${(0, colour_js_1.dim)(at)} ${(0, colour_js_1.red)("-")} ${(0, colour_js_1.red)(line.text)}`);
81
79
  }
82
80
  }
83
81
  }
@@ -119,13 +117,13 @@ async function commandDiff(parsed) {
119
117
  const from = versionBy(list, first);
120
118
  const to = versionBy(list, second);
121
119
  if (!from || !to) {
122
- console.error(red(`No such version: ${from ? second : first}`));
120
+ console.error((0, colour_js_1.red)(`No such version: ${from ? second : first}`));
123
121
  return 1;
124
122
  }
125
123
  const changes = (await (0, api_js_1.compareVersions)(project.id, from.id, to.id))
126
124
  .filter((change) => !only || change.path.includes(String(only)))
127
125
  .sort((left, right) => left.path.localeCompare(right.path));
128
- console.log(`${bold(project.slug)} ${dim(`v${from.sequence} -> v${to.sequence}`)}`);
126
+ console.log(`${(0, colour_js_1.bold)(project.slug)} ${(0, colour_js_1.dim)(`v${from.sequence} -> v${to.sequence}`)}`);
129
127
  if (!changes.length) {
130
128
  console.log("Nothing differs between them.");
131
129
  return 0;
@@ -139,13 +137,13 @@ async function commandDiff(parsed) {
139
137
  (0, api_js_1.fileTextAt)(project.id, to.id, change.path),
140
138
  ]);
141
139
  if (before === null || after === null) {
142
- console.log(dim(" not text"));
140
+ console.log((0, colour_js_1.dim)(" not text"));
143
141
  continue;
144
142
  }
145
143
  printHunks(before, after, context);
146
144
  }
147
145
  const many = changes.length === 1 ? "" : "s";
148
- console.log(dim(`\n${changes.length} file${many} differ${many ? "" : "s"}`));
146
+ console.log((0, colour_js_1.dim)(`\n${changes.length} file${many} differ${many ? "" : "s"}`));
149
147
  return 0;
150
148
  }
151
149
  /*
@@ -155,14 +153,14 @@ async function commandDiff(parsed) {
155
153
  */
156
154
  const link = await (0, config_js_1.readLink)(node_process_1.default.cwd());
157
155
  if (!link) {
158
- console.error(red("This folder is not linked to a project, so there is no local side."));
156
+ console.error((0, colour_js_1.red)("This folder is not linked to a project, so there is no local side."));
159
157
  return 1;
160
158
  }
161
159
  const against = first
162
160
  ? versionBy(list, first)
163
161
  : { id: link.baseVersionId ?? list[0].id, sequence: link.sequence };
164
162
  if (!against) {
165
- console.error(red(`No such version: ${first}`));
163
+ console.error((0, colour_js_1.red)(`No such version: ${first}`));
166
164
  return 1;
167
165
  }
168
166
  const folder = node_process_1.default.cwd();
@@ -181,7 +179,7 @@ async function commandDiff(parsed) {
181
179
  const changed = (await (0, worktree_js_1.changedFiles)(folder, rules, new Map(Object.entries(saved)), "synchronize"))
182
180
  .filter((one) => !only || one.path.includes(String(only)))
183
181
  .sort((left, right) => left.path.localeCompare(right.path));
184
- console.log(`${bold(node_path_1.default.basename(folder))} ${dim(`this folder -> v${against.sequence}`)}`);
182
+ console.log(`${(0, colour_js_1.bold)(node_path_1.default.basename(folder))} ${(0, colour_js_1.dim)(`this folder -> v${against.sequence}`)}`);
185
183
  let differing = 0;
186
184
  for (const one of changed) {
187
185
  const wasSaved = Object.prototype.hasOwnProperty.call(saved, one.path);
@@ -195,7 +193,7 @@ async function commandDiff(parsed) {
195
193
  if (nameOnly || kind !== "changed")
196
194
  continue;
197
195
  if (one.binary) {
198
- console.log(dim(" not text"));
196
+ console.log((0, colour_js_1.dim)(" not text"));
199
197
  continue;
200
198
  }
201
199
  const [before, after] = await Promise.all([
@@ -203,7 +201,7 @@ async function commandDiff(parsed) {
203
201
  (0, promises_1.readFile)(node_path_1.default.join(folder, one.path), "utf8").catch(() => null),
204
202
  ]);
205
203
  if (before === null || after === null || !isText(after)) {
206
- console.log(dim(" not text"));
204
+ console.log((0, colour_js_1.dim)(" not text"));
207
205
  continue;
208
206
  }
209
207
  printHunks(before, after, context);
@@ -213,6 +211,6 @@ async function commandDiff(parsed) {
213
211
  return 0;
214
212
  }
215
213
  const many = differing === 1 ? "" : "s";
216
- console.log(dim(`\n${differing} file${many} differ${many ? "" : "s"}`));
214
+ console.log((0, colour_js_1.dim)(`\n${differing} file${many} differ${many ? "" : "s"}`));
217
215
  return 0;
218
216
  }
@@ -6,7 +6,9 @@ exports.short = exports.accent = exports.green = exports.red = exports.bold = ex
6
6
  * can print exactly what the full commands print without loading them.
7
7
  */
8
8
  const ESC = String.fromCharCode(27);
9
- const paint = (code) => (value) => `${ESC}[${code}m${value}${ESC}[0m`;
9
+ /* Only at a terminal and never with NO_COLOR, the same rule as colour.ts. */
10
+ const colour = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
11
+ const paint = (code) => (value) => (colour ? `${ESC}[${code}m${value}${ESC}[0m` : value);
10
12
  exports.dim = paint("2");
11
13
  exports.bold = paint("1");
12
14
  exports.red = paint("31");
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pendingMerges = pendingMerges;
7
+ exports.rememberMerge = rememberMerge;
8
+ exports.forgetMerges = forgetMerges;
9
+ /**
10
+ * Merges this machine's saves were kept as, per project.
11
+ *
12
+ * A save kept as a merge leaves the folder exactly as it was, so cbx status
13
+ * went on saying "1 file to submit" and nothing else, and the obvious next
14
+ * step was to save the same change again, keeping a second copy beside the
15
+ * first (2026-11-11 exercise 2). cbx submit notes each merge here; cbx status
16
+ * asks the service about the noted ones, says which are still waiting, and
17
+ * forgets the ones that were applied or cancelled.
18
+ *
19
+ * A note, not a record anybody depends on: a missing or unreadable file only
20
+ * means status says less.
21
+ */
22
+ const promises_1 = require("node:fs/promises");
23
+ const node_path_1 = __importDefault(require("node:path"));
24
+ const config_js_1 = require("./config.js");
25
+ const KEPT = 20;
26
+ function noteFile(repositoryId) {
27
+ /* Only an id the service gave names a file. */
28
+ return /^[0-9a-f-]{36}$/i.test(repositoryId)
29
+ ? node_path_1.default.join((0, config_js_1.configDirectory)(), "pending-merges", `${repositoryId.toLowerCase()}.json`)
30
+ : null;
31
+ }
32
+ async function pendingMerges(repositoryId) {
33
+ const file = noteFile(repositoryId);
34
+ if (!file)
35
+ return [];
36
+ try {
37
+ const parsed = JSON.parse(await (0, promises_1.readFile)(file, "utf8"));
38
+ return Array.isArray(parsed)
39
+ ? parsed.filter((one) => typeof one?.id === "string" && typeof one?.reference === "string" && Array.isArray(one?.paths))
40
+ : [];
41
+ }
42
+ catch {
43
+ return [];
44
+ }
45
+ }
46
+ async function write(repositoryId, merges) {
47
+ const file = noteFile(repositoryId);
48
+ if (!file)
49
+ return;
50
+ await (0, promises_1.mkdir)(node_path_1.default.dirname(file), { recursive: true });
51
+ await (0, promises_1.writeFile)(file, JSON.stringify(merges.slice(-KEPT), null, 2) + "\n");
52
+ }
53
+ async function rememberMerge(repositoryId, merge) {
54
+ const kept = (await pendingMerges(repositoryId)).filter((one) => one.id !== merge.id);
55
+ await write(repositoryId, [...kept, merge]);
56
+ }
57
+ async function forgetMerges(repositoryId, ids) {
58
+ if (!ids.size)
59
+ return;
60
+ const kept = await pendingMerges(repositoryId);
61
+ await write(repositoryId, kept.filter((one) => !ids.has(one.id)));
62
+ }
@@ -401,6 +401,23 @@ async function commandVersions(parsed) {
401
401
  (marks.length ? ` ${marks.join(" ")}` : ""));
402
402
  if (version.message)
403
403
  console.log(` ${(0, colour_js_1.dim)(version.message)}`);
404
+ /*
405
+ Where it came from, when the save said: "saved as Codex-2 on ALEX-PC from
406
+ draft 6f1c1a52 with cli/0.46.10". Eight assistants on one account read as
407
+ one author before this (2026-11-11 agent exercise). Only the project's
408
+ people are sent it, so a visitor's list has no such line.
409
+ */
410
+ const from = version.savedFrom;
411
+ const where = from
412
+ ? [
413
+ from.as ? `as ${from.as}` : "",
414
+ from.machine ? `on ${from.machine}` : "",
415
+ from.workspaceId ? `from draft ${from.workspaceId.slice(0, 8)}` : "",
416
+ from.client ? `with ${from.client}` : "",
417
+ ].filter(Boolean)
418
+ : [];
419
+ if (where.length)
420
+ console.log(` ${(0, colour_js_1.dim)(`saved ${where.join(" ")}`)}`);
404
421
  /*
405
422
  Indented under the save it belongs to rather than printed flat, so a
406
423
  note of several paragraphs still reads as part of one row.