@coderook/cli 0.46.7 → 0.46.9

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.
@@ -1575,7 +1575,11 @@ The connection failed: ${text}`));
1575
1575
  }
1576
1576
  console.log(`\nRun ${accent(`cbx merge ${result.mergeTrack.reference}`)} to decide,` +
1577
1577
  ` or ${accent("cbx merges")} to see everything waiting.`);
1578
- return 0;
1578
+ /*
1579
+ 3, not 0: the work is kept, but the line did not move. Scripts and agents
1580
+ read 0 as saved and carried on (2026-11-11 agent exercise).
1581
+ */
1582
+ return 3;
1579
1583
  }
1580
1584
  /*
1581
1585
  The version exists on the account. Stopping before the line below is the
@@ -1630,8 +1634,16 @@ The connection failed: ${text}`));
1630
1634
  ` nothing was sent again.`);
1631
1635
  return 0;
1632
1636
  }
1637
+ /*
1638
+ Files sent again only to be gathered into one pack are counted apart: "sent
1639
+ 64 files" for a one-line change read as 63 files nobody touched having
1640
+ changed (GrokBot3, 2026-11-11).
1641
+ */
1642
+ const repacked = Math.min(result.repackedFiles ?? 0, result.sentFiles);
1643
+ const changedSent = result.sentFiles - repacked;
1633
1644
  console.log(`Saved ${accent(`v${result.sequence}`)} · sent ${bytes(result.sentBytes)} in ` +
1634
- `${result.sentFiles} file${result.sentFiles === 1 ? "" : "s"}` +
1645
+ `${changedSent} file${changedSent === 1 ? "" : "s"}` +
1646
+ (repacked ? ` (and re-packed ${repacked} unchanged small file${repacked === 1 ? "" : "s"} together)` : "") +
1635
1647
  /*
1636
1648
  Three different things, kept apart. Sent is what crossed the wire.
1637
1649
  Already on the account is content the service turned out to have, which
@@ -1642,13 +1654,24 @@ The connection failed: ${text}`));
1642
1654
  ? `, ${result.alreadyStoredFiles} already on the account`
1643
1655
  : "") +
1644
1656
  (result.reusedFiles ? `, ${result.reusedFiles} unchanged` : "") +
1657
+ /* What --sync removed, which the line used not to mention at all (GrokBot3, v145). */
1658
+ (hasFlag(parsed, "sync") && files.some((file) => file.deleted)
1659
+ ? `, ${files.filter((file) => file.deleted).length} removed`
1660
+ : "") +
1645
1661
  /*
1646
1662
  "version holds" was the old fused vocabulary. `cbx submit` makes a
1647
1663
  save; a save becomes a version when somebody names it, which is what
1648
1664
  `cbx release` does. Saying "version" here promised something this
1649
1665
  command does not do.
1650
1666
  */
1651
- ` · the save holds ${bytes(result.sourceBytes)}`);
1667
+ /*
1668
+ Both sizes, named: "holds 2.9 MB" beside 858 KB in cbx versions read as
1669
+ a contradiction. One is the files' size, the other what storage keeps.
1670
+ */
1671
+ ` · the save holds ${bytes(result.sourceBytes)}` +
1672
+ (result.storedBytes && result.storedBytes < result.sourceBytes
1673
+ ? ` (${bytes(result.storedBytes)} stored)`
1674
+ : ""));
1652
1675
  noteKeptDeletions(folder, baseline, hasFlag(parsed, "sync"), seen);
1653
1676
  noteGitRoute(folder, link?.slug ?? adopt?.slug ?? (0, folder_match_js_1.slugFor)(flagText(parsed, "name") ?? node_path_1.default.basename(folder)));
1654
1677
  /*
@@ -1978,6 +2001,8 @@ trackName) {
1978
2001
  });
1979
2002
  }
1980
2003
  const line = progressLine();
2004
+ /* The folder's record of what each file was when last read; see Downloader.run. */
2005
+ const knownDigests = await (0, config_js_1.readDigests)(repositoryId, destination).catch(() => new Map());
1981
2006
  let result;
1982
2007
  try {
1983
2008
  result = await downloader.run(repositoryId, latest.id, destination, (progress) => {
@@ -1987,7 +2012,7 @@ trackName) {
1987
2012
  },
1988
2013
  // What this folder received last time, so a file the project has since
1989
2014
  // dropped is removed while everything untracked is left alone.
1990
- held, mode);
2015
+ held, mode, knownDigests);
1991
2016
  }
1992
2017
  catch (error) {
1993
2018
  done(line);
@@ -2039,6 +2064,18 @@ trackName) {
2039
2064
  ...(trackName ? { track: trackName } : {}),
2040
2065
  // Reached the end, so there is no longer a fetch in flight.
2041
2066
  });
2067
+ /*
2068
+ What this fetch wrote is recorded as read: its size and time as placed,
2069
+ and the digest it was checked against on the way in. Without it the next
2070
+ status, fetch or save opened and hashed every file again — 20,000 small
2071
+ files took minutes after every clone (2026-11-11). Only files this run
2072
+ wrote: one it left alone may hold an edit the record must not hide.
2073
+ */
2074
+ if (result.placedFiles.size) {
2075
+ for (const [placed, record] of result.placedFiles)
2076
+ knownDigests.set(placed, record);
2077
+ await (0, config_js_1.writeDigests)(repositoryId, knownDigests, destination);
2078
+ }
2042
2079
  // The record is written; the run has not reported success yet.
2043
2080
  (0, faults_js_1.maybeFail)("get:after-record");
2044
2081
  /*
@@ -2047,16 +2084,24 @@ trackName) {
2047
2084
  when not a byte had moved.
2048
2085
  */
2049
2086
  const unchanged = result.unchanged ?? 0;
2050
- if (unchanged > 0 && unchanged >= result.files) {
2087
+ /* Removals count as change: "Already up to date" after deleting 1,997 files misled Opus55-3. */
2088
+ const removed = result.removed ?? 0;
2089
+ const gone = removed ? `, ${removed.toLocaleString("en-US")} removed` : "";
2090
+ if (unchanged > 0 && unchanged >= result.files && !removed) {
2051
2091
  console.log(`Already up to date · ${accent(`v${latest.sequence}`)} · ${fileCount(result.files)}`);
2052
2092
  }
2053
2093
  else if (unchanged > 0) {
2054
2094
  const fetched = result.files - unchanged;
2055
- console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(fetched)} updated, ${unchanged.toLocaleString("en-US")} already here · ${destination}`);
2095
+ console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(fetched)} updated${gone}, ${unchanged.toLocaleString("en-US")} already here · ${destination}`);
2056
2096
  }
2057
2097
  else {
2058
2098
  console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
2059
2099
  }
2100
+ const leftDeleted = result.leftDeleted ?? 0;
2101
+ if (leftDeleted) {
2102
+ console.log(dim(`${fileCount(leftDeleted)} you deleted here and have not saved ${leftDeleted === 1 ? "was" : "were"} left deleted; ` +
2103
+ `cbx submit --sync saves the deletion, cbx get --replace brings ${leftDeleted === 1 ? "it" : "them"} back.`));
2104
+ }
2060
2105
  return 0;
2061
2106
  }
2062
2107
  /**
@@ -2644,7 +2689,10 @@ const SPECS = [
2644
2689
  "into it, --new starts a separate one.\n\n" +
2645
2690
  "A save is not a version. Nobody outside the project can see one until\n" +
2646
2691
  "it is named, which is what `cbx release` does — so submitting is as\n" +
2647
- "cheap and as private as you want it to be.",
2692
+ "cheap and as private as you want it to be.\n\n" +
2693
+ "Exits 0 when the save is on the line, 3 when it is kept as a merge\n" +
2694
+ "because somebody changed the same lines (cbx merges lists it), and\n" +
2695
+ "1 when it failed.",
2648
2696
  options: [
2649
2697
  { flags: "-m, --message <text>", description: "what changed, in a sentence" },
2650
2698
  { flags: "-n, --dry-run", description: "show what would be sent, send nothing" },
@@ -3066,9 +3114,9 @@ const SPECS = [
3066
3114
  name: "workspace",
3067
3115
  group: "Workspaces",
3068
3116
  summary: "edit, save and run a private project remotely without a checkout",
3069
- 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]",
3117
+ usage: "workspace | workspace <usage|open|list|show|read|files|search|diff|patch|put|starter|review|reviewers|save|run|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]",
3070
3118
  brief: "workspace <action> <project>",
3071
- 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.",
3119
+ 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.",
3072
3120
  options: [
3073
3121
  { flags: "--data-file <path>", description: "read an operation's JSON from this local file" },
3074
3122
  { flags: "--name <name>", description: "name a new workspace" },
@@ -3086,6 +3134,7 @@ const SPECS = [
3086
3134
  { flags: "--version <id>", description: "saved workspace version to deploy" },
3087
3135
  { flags: "-m, --message <text>", description: "describe the version being saved" },
3088
3136
  { flags: "--note <text>", description: "task context for another computer/assistant" },
3137
+ { flags: "--unsaved", description: "close: close a draft whose edits were never saved; they are kept and come back with reopen" },
3089
3138
  { flags: "--days <number>", description: "assign: how long the handed-over token lasts (1-90, default 14)" },
3090
3139
  { flags: "--save", description: "push: save the draft after sending the changes" },
3091
3140
  { flags: "--dry-run", description: "push: list what would be sent, send nothing" },
@@ -3101,7 +3150,7 @@ const SPECS = [
3101
3150
  { flags: "--interval <seconds>", description: "watch: how often to look (default 20, at least 5)" },
3102
3151
  ],
3103
3152
  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\""],
3104
- arguments: { "[job]": "a job's name inside a run, for logs and cancel" },
3153
+ arguments: { "[job]": "the run's id (cbx workspace run prints it), for logs and cancel" },
3105
3154
  run: workspace_command_js_1.commandWorkspace,
3106
3155
  },
3107
3156
  {
@@ -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");
@@ -394,8 +394,10 @@ async function commandVersions(parsed) {
394
394
  version.name && version.visibility === "private" ? (0, colour_js_1.dim)("hidden") : "",
395
395
  ...version.labels.map((label) => (0, colour_js_1.accent)(label.name)),
396
396
  ].filter(Boolean);
397
- console.log(` ${(0, colour_js_1.accent)(`v${version.sequence}`).padEnd(16)} ${when.padEnd(22)}` +
398
- `${String(version.fileCount).padStart(5)} ${version.fileCount === 1 ? "file " : "files"} ${bytes(version.storedSize)}` +
397
+ console.log(
398
+ /* A space is always kept: 5-digit counts ran into the time ("10:46:52 am20259 files"). */
399
+ ` ${(0, colour_js_1.accent)(`v${version.sequence}`).padEnd(16)} ${when.padEnd(22)} ` +
400
+ `${String(version.fileCount).padStart(6)} ${version.fileCount === 1 ? "file " : "files"} ${bytes(version.storedSize)}` +
399
401
  (marks.length ? ` ${marks.join(" ")}` : ""));
400
402
  if (version.message)
401
403
  console.log(` ${(0, colour_js_1.dim)(version.message)}`);
@@ -31,12 +31,8 @@ const node_process_1 = __importDefault(require("node:process"));
31
31
  const download_js_1 = require("../../cbx/src/core/download.js");
32
32
  const safe_path_js_1 = require("../../cbx/src/shared/safe_path.js");
33
33
  const config_js_1 = require("./config.js");
34
- const ESC = String.fromCharCode(27);
35
- const paint = (code) => (value) => `${ESC}[${code}m${value}${ESC}[0m`;
36
- const dim = paint("2");
37
- const red = paint("31");
38
- const green = paint("32");
39
- const accent = paint("33");
34
+ /* The shared colours: only at a terminal, never with NO_COLOR. */
35
+ const colour_js_1 = require("./colour.js");
40
36
  const plural = (count, one, many = `${one}s`) => `${count} ${count === 1 ? one : many}`;
41
37
  async function digestOfFile(full) {
42
38
  try {
@@ -78,10 +74,10 @@ function projectPath(root, cwd, typed) {
78
74
  async function commandRemoteRestore(parsed) {
79
75
  const found = await linkedRoot(node_process_1.default.cwd());
80
76
  if (!found) {
81
- console.error(red("No history here."));
82
- console.error(dim(" This folder is not linked to a CodeRook project and has no local history. ") +
83
- accent("cbx link <project>") + dim(" connects it; ") + accent("cbx init") +
84
- dim(" starts a history on this machine."));
77
+ console.error((0, colour_js_1.red)("No history here."));
78
+ console.error((0, colour_js_1.dim)(" This folder is not linked to a CodeRook project and has no local history. ") +
79
+ (0, colour_js_1.accent)("cbx link <project>") + (0, colour_js_1.dim)(" connects it; ") + (0, colour_js_1.accent)("cbx init") +
80
+ (0, colour_js_1.dim)(" starts a history on this machine."));
85
81
  return 1;
86
82
  }
87
83
  const { root, link } = found;
@@ -90,7 +86,7 @@ async function commandRemoteRestore(parsed) {
90
86
  for (const typed of parsed.positional) {
91
87
  const one = projectPath(root, node_process_1.default.cwd(), typed);
92
88
  if (one === null) {
93
- console.error(red(`${typed} is outside the project folder (${root}).`));
89
+ console.error((0, colour_js_1.red)(`${typed} is outside the project folder (${root}).`));
94
90
  return 1;
95
91
  }
96
92
  wanted.push(one);
@@ -105,7 +101,7 @@ async function commandRemoteRestore(parsed) {
105
101
  ? versions.find((one) => one.sequence === Number(sequence[1]))
106
102
  : versions.find((one) => one.id.startsWith(from.trim()));
107
103
  if (!version) {
108
- console.error(red(`No version ${from} in ${link.slug}.`) + dim(" cbx versions lists them."));
104
+ console.error((0, colour_js_1.red)(`No version ${from} in ${link.slug}.`) + (0, colour_js_1.dim)(" cbx versions lists them."));
109
105
  return 1;
110
106
  }
111
107
  }
@@ -115,14 +111,14 @@ async function commandRemoteRestore(parsed) {
115
111
  versions.find((one) => one.id === base) ??
116
112
  versions.find((one) => one.sequence === link.sequence);
117
113
  if (!version) {
118
- console.error(red("This folder's saved version could not be found.") +
119
- dim(" Name one with --from vN."));
114
+ console.error((0, colour_js_1.red)("This folder's saved version could not be found.") +
115
+ (0, colour_js_1.dim)(" Name one with --from vN."));
120
116
  return 1;
121
117
  }
122
118
  }
123
119
  const files = selectFiles(await downloader.files(link.repositoryId, version.id), wanted);
124
120
  if (!files.length) {
125
- console.error(red(`v${version.sequence} holds nothing at ${wanted.join(", ") || "the project root"}.`));
121
+ console.error((0, colour_js_1.red)(`v${version.sequence} holds nothing at ${wanted.join(", ") || "the project root"}.`));
126
122
  return 1;
127
123
  }
128
124
  const toWrite = [];
@@ -130,7 +126,7 @@ async function commandRemoteRestore(parsed) {
130
126
  for (const file of files) {
131
127
  const unsafe = (0, safe_path_js_1.whyUnsafe)(file.path);
132
128
  if (unsafe) {
133
- console.error(red(`Skipped ${JSON.stringify(file.path)}: ${unsafe}.`));
129
+ console.error((0, colour_js_1.red)(`Skipped ${JSON.stringify(file.path)}: ${unsafe}.`));
134
130
  continue;
135
131
  }
136
132
  const here = await digestOfFile(node_path_1.default.join(root, ...file.path.split("/")));
@@ -147,28 +143,28 @@ async function commandRemoteRestore(parsed) {
147
143
  toWrite.push(file);
148
144
  }
149
145
  if (edited.length) {
150
- console.error(red(`${plural(edited.length, "file")} here ${edited.length === 1 ? "has" : "have"} ` +
146
+ console.error((0, colour_js_1.red)(`${plural(edited.length, "file")} here ${edited.length === 1 ? "has" : "have"} ` +
151
147
  `unsaved changes that restoring would overwrite:`));
152
148
  for (const one of edited.slice(0, 20))
153
149
  console.error(` ${one}`);
154
150
  if (edited.length > 20)
155
- console.error(dim(` …and ${edited.length - 20} more`));
156
- console.error(`\nAdd ${accent("--force")} to discard them, or save them first with ${accent("cbx submit")}.`);
151
+ console.error((0, colour_js_1.dim)(` …and ${edited.length - 20} more`));
152
+ console.error(`\nAdd ${(0, colour_js_1.accent)("--force")} to discard them, or save them first with ${(0, colour_js_1.accent)("cbx submit")}.`);
157
153
  return 1;
158
154
  }
159
155
  if (!toWrite.length) {
160
- console.log(`Already matches ${accent(`v${version.sequence}`)}; nothing to put back.`);
156
+ console.log(`Already matches ${(0, colour_js_1.accent)(`v${version.sequence}`)}; nothing to put back.`);
161
157
  return 0;
162
158
  }
163
159
  for (const file of toWrite) {
164
160
  await downloader.fileTo(link.repositoryId, version.id, file, node_path_1.default.join(root, ...file.path.split("/")));
165
161
  }
166
- console.log(`Put back ${plural(toWrite.length, "file")} from ${accent(`v${version.sequence}`)}: ` +
162
+ console.log(`Put back ${plural(toWrite.length, "file")} from ${(0, colour_js_1.accent)(`v${version.sequence}`)}: ` +
167
163
  `${version.message.split("\n")[0]}`);
168
164
  for (const file of toWrite.slice(0, 20))
169
- console.log(` ${green("restored")} ${file.path}`);
165
+ console.log(` ${(0, colour_js_1.green)("restored")} ${file.path}`);
170
166
  if (toWrite.length > 20)
171
- console.log(dim(` …and ${toWrite.length - 20} more`));
172
- console.log(dim("The folder's link has not moved. cbx submit saves the folder as it is now."));
167
+ console.log((0, colour_js_1.dim)(` …and ${toWrite.length - 20} more`));
168
+ console.log((0, colour_js_1.dim)("The folder's link has not moved. cbx submit saves the folder as it is now."));
173
169
  return 0;
174
170
  }
@@ -164,13 +164,16 @@ async function commandWorkspace(parsed) {
164
164
  body = {};
165
165
  }
166
166
  }
167
- else if (operation === "handoff" || operation === "close") {
167
+ else if (operation === "handoff" || operation === "close" || operation === "reopen") {
168
168
  method = "PATCH";
169
169
  body = {
170
170
  ...data,
171
171
  expectedRevision: revision,
172
172
  note: flag("note") ?? data.note,
173
173
  ...(operation === "close" ? { archived: true } : {}),
174
+ /* Closing a draft with unsaved edits needs this: the service refuses otherwise. The edits are kept for reopen. */
175
+ ...(operation === "close" && parsed.flags.has("unsaved") ? { unsaved: true } : {}),
176
+ ...(operation === "reopen" ? { archived: false } : {}),
174
177
  };
175
178
  }
176
179
  else if (operation !== "show")
@@ -197,6 +200,16 @@ async function commandWorkspace(parsed) {
197
200
  throw error;
198
201
  }
199
202
  console.log(JSON.stringify(result, null, 2));
203
+ /*
204
+ A save kept as a merge did not reach the line. It exited 0 with only JSON
205
+ to say otherwise, so a script or agent read it as saved (2026-11-11, M-1).
206
+ Exit 3 means exactly that, the same as cbx submit.
207
+ */
208
+ const kept = operation === "save" ? result?.mergeTrack : null;
209
+ if (kept?.reference) {
210
+ say(`Kept as ${kept.reference}, not saved to the line: somebody changed the same lines. Run cbx merge ${kept.reference} to decide.`);
211
+ return 3;
212
+ }
200
213
  return 0;
201
214
  }
202
215
  const say = (line) => process.stderr.write(line + "\n");
@@ -88,13 +88,41 @@ async function commandWorkspacePut(parsed, root, workspace) {
88
88
  const draft = `${root}/workspaces/${encodeURIComponent(workspace)}`;
89
89
  const wanted = [...new Set(paths.map((p) => projectPath(folder, p)))];
90
90
  /* The hashes the draft holds now; the listing pages 500 at a time, so stop once every wanted path is found. */
91
+ /*
92
+ Asked path by path first. Paging never stopped early for a new file, which
93
+ no page names: a put into a 20,000-file draft made about 41 requests and
94
+ took 22-24 s (2026-11-11 agent exercise). The listing is still the way for
95
+ many paths, and for a service that does not answer meta=1.
96
+ */
91
97
  const held = new Map();
92
- for (let offset = 0; offset !== null && held.size < wanted.length;) {
93
- const page = await (0, api_js_1.callApi)(`${draft}/files?offset=${offset}`);
94
- for (const f of page.files)
95
- if (wanted.includes(f.path))
96
- held.set(f.path, f.sha256);
97
- offset = page.nextOffset;
98
+ let pageThrough = wanted.length > 32;
99
+ if (!pageThrough) {
100
+ for (const path of wanted) {
101
+ try {
102
+ const one = await (0, api_js_1.callApi)(`${draft}/files?path=${encodeURIComponent(path)}&meta=1`);
103
+ if (typeof one.sha256 !== "string") {
104
+ pageThrough = true;
105
+ break;
106
+ }
107
+ held.set(path, one.sha256);
108
+ }
109
+ catch (error) {
110
+ if (error instanceof api_js_1.ServiceError && error.code === "workspace_file_missing")
111
+ continue;
112
+ pageThrough = true;
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ if (pageThrough) {
118
+ held.clear();
119
+ for (let offset = 0; offset !== null && held.size < wanted.length;) {
120
+ const page = await (0, api_js_1.callApi)(`${draft}/files?offset=${offset}`);
121
+ for (const f of page.files)
122
+ if (wanted.includes(f.path))
123
+ held.set(f.path, f.sha256);
124
+ offset = page.nextOffset;
125
+ }
98
126
  }
99
127
  const changes = [];
100
128
  const unchanged = [];
@@ -7,9 +7,11 @@ exports.commandWorkspaceReviewers = commandWorkspaceReviewers;
7
7
  * cbx workspace review <project> <workspace> --ok [-m "…"] | --changes -m "…"
8
8
  * cbx workspace reviewers <project> [--data-file rules.json]
9
9
  *
10
- * The CLI side of the review gate (backend workspace_reviews.ts). A review
11
- * counts only from the reviewer's own sign-in or token, so --as is refused
12
- * here before the service refuses it, with the reason.
10
+ * The CLI side of the review gate (backend workspace_reviews.ts). Where the
11
+ * project names reviewers, a review counts only from the reviewer's own
12
+ * sign-in or token, and the service refuses a name given with --as. Where it
13
+ * names none, any member's review, a named machine's included, is kept as
14
+ * advisory: shown, and waited on by nobody.
13
15
  */
14
16
  const promises_1 = require("node:fs/promises");
15
17
  const api_js_1 = require("./api.js");
@@ -25,6 +27,11 @@ const flag = (parsed, ...names) => {
25
27
  /** One line per reviewer: a word for where it stands, never only a colour. */
26
28
  function describeReviewer(s, revision) {
27
29
  const when = [s.beforeSave && "save", s.beforeDeploy && "deploy"].filter(Boolean).join(" + ");
30
+ if (s.advisory) {
31
+ const said = s.state === "ok" ? (0, colour_js_1.green)("OK ") : s.state === "changes" ? (0, colour_js_1.red)("changes ") : "outdated ";
32
+ const on = s.state === "outdated" ? `on revision ${s.revision}, draft is at ${revision}` : `on revision ${s.revision}`;
33
+ return `${said}${(0, colour_js_1.bold)(s.label)} ${(0, colour_js_1.dim)(`advisory, ${on}`)}${s.note ? ` ${s.note}` : ""}`;
34
+ }
28
35
  if (!s.applies)
29
36
  return `${(0, colour_js_1.dim)("not needed")} ${s.label} ${(0, colour_js_1.dim)(`(no changes in its paths)`)}`;
30
37
  const word = s.state === "ok"
@@ -42,8 +49,9 @@ function describeReviewer(s, revision) {
42
49
  return `${word}${(0, colour_js_1.bold)(s.label)} ${(0, colour_js_1.dim)(`before ${when}`)}${detail ? ` ${detail}` : ""}`;
43
50
  }
44
51
  async function commandWorkspaceReview(parsed, root, workspace) {
45
- if (parsed.flags.has("as") || process.env.CBX_NAME)
46
- throw new Error("A review counts only from the reviewer's own sign-in or token; run it without --as or CBX_NAME.");
52
+ /* Passed on: the service keeps it as advisory where no reviewers are named, and refuses it where they are. */
53
+ const asValue = parsed.flags.get("as");
54
+ const named = typeof asValue === "string" ? asValue : process.env.CBX_NAME || undefined;
47
55
  const ok = parsed.flags.has("ok");
48
56
  const changes = parsed.flags.has("changes");
49
57
  const draft = `${root}/workspaces/${encodeURIComponent(workspace)}`;
@@ -54,7 +62,7 @@ async function commandWorkspaceReview(parsed, root, workspace) {
54
62
  if (parsed.flags.has("json"))
55
63
  console.log(JSON.stringify({ revision: shown.workspace.revision, review }, null, 2));
56
64
  else if (!review.length)
57
- console.log("This project names no reviewers. An administrator sets them with cbx workspace reviewers.");
65
+ console.log("This project names no reviewers, so nothing waits on a review; any review given is kept as advisory. An administrator names reviewers with cbx workspace reviewers.");
58
66
  else
59
67
  for (const s of review)
60
68
  console.log(describeReviewer(s, shown.workspace.revision));
@@ -68,7 +76,7 @@ async function commandWorkspaceReview(parsed, root, workspace) {
68
76
  : (await (0, api_js_1.callApi)(draft)).workspace.revision;
69
77
  const out = await (0, api_js_1.callApi)(`${draft}/reviews`, {
70
78
  method: "POST",
71
- body: { verdict: ok ? "ok" : "changes", note, expectedRevision: revision },
79
+ body: { verdict: ok ? "ok" : "changes", note, expectedRevision: revision, ...(named ? { as: named } : {}) },
72
80
  });
73
81
  if (parsed.flags.has("json"))
74
82
  console.log(JSON.stringify(out, null, 2));