@coderook/cli 0.46.7 → 0.46.8

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.
@@ -2,7 +2,7 @@
2
2
  "name": "coderook",
3
3
  "displayName": "CodeRook",
4
4
  "description": "Save, browse and restore whole-snapshot versions of a project on CodeRook, with cbx or plain git, from Claude Code.",
5
- "version": "0.46.7",
5
+ "version": "0.46.8",
6
6
  "author": {
7
7
  "name": "ACCA Gaming Productions",
8
8
  "url": "https://coderook.com"
@@ -70,13 +70,40 @@ async function digestOf(target) {
70
70
  * a directory holding ignored files with them, so this stops at the first
71
71
  * one that still has something in it.
72
72
  */
73
+ /*
74
+ A file's digest, from the folder's record when its size and time still match
75
+ it, otherwise by reading it. Catching up past 20,000 deleted files read every
76
+ one of them first to make sure nobody had edited it: 752 s (2026-11-11).
77
+ */
78
+ async function currentDigest(target, recorded) {
79
+ if (recorded) {
80
+ try {
81
+ const now = await (0, promises_1.stat)(target);
82
+ if (now.size === recorded.size && now.mtimeMs === recorded.mtimeMs)
83
+ return recorded.sha256;
84
+ }
85
+ catch {
86
+ return null;
87
+ }
88
+ }
89
+ return digestOf(target);
90
+ }
73
91
  async function pruneEmpty(root, removed) {
74
- let directory = node_path_1.default.dirname(removed);
75
- while (directory.startsWith(root) && directory !== root) {
92
+ /*
93
+ Compared resolved, and without case on Windows. The two arrived spelled
94
+ differently (B:/x and B:\x, or b: and B:), so the check failed at once and
95
+ no folder was ever removed: catching up past 20,000 deleted files left 101
96
+ empty folders behind (2026-11-11).
97
+ */
98
+ const fold = (value) => (process.platform === "win32" ? value.toLowerCase() : value);
99
+ const top = fold(node_path_1.default.resolve(root));
100
+ let directory = node_path_1.default.resolve(node_path_1.default.dirname(removed));
101
+ while (fold(directory).startsWith(top + node_path_1.default.sep) && fold(directory) !== top) {
76
102
  try {
77
103
  if ((await (0, promises_1.readdir)(directory)).length)
78
104
  return;
79
- await (0, promises_1.rm)(directory, { recursive: false, force: true });
105
+ /* rmdir, not rm: rm refuses any directory unless told to recurse, so this never removed one. */
106
+ await (0, promises_1.rmdir)(directory);
80
107
  }
81
108
  catch {
82
109
  return;
@@ -866,7 +893,12 @@ class Downloader {
866
893
  version, which is what repairs a damaged one — and what discards
867
894
  anything unsaved.
868
895
  */
869
- mode = "replace") {
896
+ mode = "replace",
897
+ /*
898
+ What the folder's own record says each file was when last read: size,
899
+ time and digest. A file it still matches is known without opening it.
900
+ */
901
+ known) {
870
902
  const files = await this.files(repositoryId, versionId);
871
903
  if (!files.length)
872
904
  throw new Error("That version has no files");
@@ -886,6 +918,10 @@ class Downloader {
886
918
  try {
887
919
  let written = 0;
888
920
  let bytes = 0;
921
+ /* Each file this run put in place: its size and time as written, and its digest. */
922
+ const placedRecord = new Map();
923
+ /* Files the version dropped that this run removed from the folder. */
924
+ let removedHere = 0;
889
925
  /*
890
926
  Not fetched at all: a file the incoming version did not change, still
891
927
  here. Reconciling never writes one of these (see the placing loop
@@ -1140,31 +1176,68 @@ class Downloader {
1140
1176
  (0, faults_js_1.maybeFail)("get:after-staging");
1141
1177
  await (0, promises_1.mkdir)(destination, { recursive: true });
1142
1178
  let placed = 0;
1143
- for (const file of files) {
1144
- const target = (0, safe_path_js_1.inside)(destination, file.path);
1145
- /* Never fetched, because the folder already holds it unchanged. */
1146
- if (kept.has(file.path))
1147
- continue;
1148
- /*
1149
- Reconciling leaves alone whatever the incoming version did not
1150
- change. Writing it anyway would replace an edit in progress with a
1151
- copy of what the folder already had — destroying work to achieve
1152
- nothing, which is the least defensible way to lose someone's file.
1153
- */
1154
- if (mode === "reconcile" &&
1155
- held &&
1156
- held[file.path] === manifest[file.path] &&
1157
- (await exists(target))) {
1158
- continue;
1179
+ /*
1180
+ One at a time, each folder made once. Placing several at once was
1181
+ tried and measured: on Windows 18,000 small files took 106-114 s with
1182
+ 4 or 16 lanes against 24.5 s with one (2026-11-11), because renames
1183
+ into the same folders contend. The lane shape stays so the count is
1184
+ one place to change.
1185
+ */
1186
+ const PLACING_LANES = 1;
1187
+ const madeFolders = new Map();
1188
+ const folderFor = (target) => {
1189
+ const folder = node_path_1.default.dirname(target);
1190
+ let made = madeFolders.get(folder);
1191
+ if (!made) {
1192
+ made = (0, promises_1.mkdir)(folder, { recursive: true });
1193
+ madeFolders.set(folder, made);
1159
1194
  }
1160
- await (0, promises_1.mkdir)(node_path_1.default.dirname(target), { recursive: true });
1161
- await (0, promises_1.rm)(target, { recursive: true, force: true });
1162
- await (0, promises_1.rename)((0, safe_path_js_1.inside)(staging, file.path), target);
1163
- await applyMode(target, file.executable === true);
1164
- placed += 1;
1165
- if (placed === 1)
1166
- (0, faults_js_1.maybeFail)("get:after-first-file");
1167
- }
1195
+ return made;
1196
+ };
1197
+ let nextToPlace = 0;
1198
+ let placingFailed = false;
1199
+ const placeLane = async () => {
1200
+ while (!placingFailed) {
1201
+ const at = nextToPlace;
1202
+ nextToPlace += 1;
1203
+ if (at >= files.length)
1204
+ return;
1205
+ const file = files[at];
1206
+ const target = (0, safe_path_js_1.inside)(destination, file.path);
1207
+ /* Never fetched, because the folder already holds it unchanged. */
1208
+ if (kept.has(file.path))
1209
+ continue;
1210
+ /*
1211
+ Reconciling leaves alone whatever the incoming version did not
1212
+ change. Writing it anyway would replace an edit in progress with a
1213
+ copy of what the folder already had — destroying work to achieve
1214
+ nothing, which is the least defensible way to lose someone's file.
1215
+ */
1216
+ if (mode === "reconcile" &&
1217
+ held &&
1218
+ held[file.path] === manifest[file.path] &&
1219
+ (await exists(target))) {
1220
+ continue;
1221
+ }
1222
+ try {
1223
+ await folderFor(target);
1224
+ await (0, promises_1.rm)(target, { recursive: true, force: true });
1225
+ await (0, promises_1.rename)((0, safe_path_js_1.inside)(staging, file.path), target);
1226
+ await applyMode(target, file.executable === true);
1227
+ /* What was just written, so the next status need not read it again. */
1228
+ const now = await (0, promises_1.stat)(target);
1229
+ placedRecord.set(file.path, { size: now.size, mtimeMs: now.mtimeMs, sha256: manifest[file.path] });
1230
+ placed += 1;
1231
+ if (placed === 1)
1232
+ (0, faults_js_1.maybeFail)("get:after-first-file");
1233
+ }
1234
+ catch (error) {
1235
+ placingFailed = true;
1236
+ throw error;
1237
+ }
1238
+ }
1239
+ };
1240
+ await Promise.all(Array.from({ length: PLACING_LANES }, () => placeLane()));
1168
1241
  /*
1169
1242
  A file this folder received but the version no longer holds is gone
1170
1243
  deliberately, so it goes. One it never received is not this fetch's
@@ -1183,9 +1256,10 @@ class Downloader {
1183
1256
  ones this folder received, somebody has been working on it, and
1184
1257
  somebody else's deletion is not permission to throw that away.
1185
1258
  */
1186
- if (mode === "reconcile" && (await digestOf(target)) !== digest)
1259
+ if (mode === "reconcile" && (await currentDigest(target, known?.get(gone))) !== digest)
1187
1260
  continue;
1188
1261
  await (0, promises_1.rm)(target, { force: true });
1262
+ removedHere += 1;
1189
1263
  await pruneEmpty(destination, target);
1190
1264
  (0, faults_js_1.maybeFail)("get:after-delete");
1191
1265
  }
@@ -1201,7 +1275,7 @@ class Downloader {
1201
1275
  percent: 100,
1202
1276
  });
1203
1277
  /* How many were already here and left alone, so a caller can say nothing was fetched. */
1204
- return { files: written, bytes, manifest, unchanged: kept.size };
1278
+ return { files: written, bytes, manifest, unchanged: kept.size, placedFiles: placedRecord, removed: removedHere };
1205
1279
  }
1206
1280
  catch (error) {
1207
1281
  await (0, promises_1.rm)(staging, { recursive: true, force: true });
@@ -2332,7 +2332,17 @@ class Uploader {
2332
2332
  : null;
2333
2333
  quoting?.catch(() => undefined);
2334
2334
  /* A save gathering scattered files has to store a new pack, which a patch cannot. */
2335
- const oneRequest = this.deltaSaveRefused || this.foldPaths.size
2335
+ /*
2336
+ Nor can it name a file kept under a new path. A rename whose bytes are
2337
+ already stored is a reused entry, not a declaration, and the one-request
2338
+ save carries only patches and removals: the service filled in the rest
2339
+ from the base, which has no such path, so the renamed file vanished from
2340
+ the version while its old name was removed (2026-11-11, found by
2341
+ GrokBot2, confirmed by Opus55-1: rename + --sync from a folder behind the
2342
+ newest version lost both renamed files). The ordinary path names it.
2343
+ */
2344
+ const movesKeptBytes = reused.some((one) => !prior.has(one.path));
2345
+ const oneRequest = this.deltaSaveRefused || this.foldPaths.size || movesKeptBytes
2336
2346
  ? null
2337
2347
  : await this.deltaSavePlan(request, repositoryId, declarations, prior);
2338
2348
  if (oneRequest && this.planning && request.oneRoundTrip) {
@@ -1978,6 +1978,8 @@ trackName) {
1978
1978
  });
1979
1979
  }
1980
1980
  const line = progressLine();
1981
+ /* The folder's record of what each file was when last read; see Downloader.run. */
1982
+ const knownDigests = await (0, config_js_1.readDigests)(repositoryId, destination).catch(() => new Map());
1981
1983
  let result;
1982
1984
  try {
1983
1985
  result = await downloader.run(repositoryId, latest.id, destination, (progress) => {
@@ -1987,7 +1989,7 @@ trackName) {
1987
1989
  },
1988
1990
  // What this folder received last time, so a file the project has since
1989
1991
  // dropped is removed while everything untracked is left alone.
1990
- held, mode);
1992
+ held, mode, knownDigests);
1991
1993
  }
1992
1994
  catch (error) {
1993
1995
  done(line);
@@ -2039,6 +2041,18 @@ trackName) {
2039
2041
  ...(trackName ? { track: trackName } : {}),
2040
2042
  // Reached the end, so there is no longer a fetch in flight.
2041
2043
  });
2044
+ /*
2045
+ What this fetch wrote is recorded as read: its size and time as placed,
2046
+ and the digest it was checked against on the way in. Without it the next
2047
+ status, fetch or save opened and hashed every file again — 20,000 small
2048
+ files took minutes after every clone (2026-11-11). Only files this run
2049
+ wrote: one it left alone may hold an edit the record must not hide.
2050
+ */
2051
+ if (result.placedFiles.size) {
2052
+ for (const [placed, record] of result.placedFiles)
2053
+ knownDigests.set(placed, record);
2054
+ await (0, config_js_1.writeDigests)(repositoryId, knownDigests, destination);
2055
+ }
2042
2056
  // The record is written; the run has not reported success yet.
2043
2057
  (0, faults_js_1.maybeFail)("get:after-record");
2044
2058
  /*
@@ -2047,12 +2061,15 @@ trackName) {
2047
2061
  when not a byte had moved.
2048
2062
  */
2049
2063
  const unchanged = result.unchanged ?? 0;
2050
- if (unchanged > 0 && unchanged >= result.files) {
2064
+ /* Removals count as change: "Already up to date" after deleting 1,997 files misled Opus55-3. */
2065
+ const removed = result.removed ?? 0;
2066
+ const gone = removed ? `, ${removed.toLocaleString("en-US")} removed` : "";
2067
+ if (unchanged > 0 && unchanged >= result.files && !removed) {
2051
2068
  console.log(`Already up to date · ${accent(`v${latest.sequence}`)} · ${fileCount(result.files)}`);
2052
2069
  }
2053
2070
  else if (unchanged > 0) {
2054
2071
  const fetched = result.files - unchanged;
2055
- console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(fetched)} updated, ${unchanged.toLocaleString("en-US")} already here · ${destination}`);
2072
+ console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(fetched)} updated${gone}, ${unchanged.toLocaleString("en-US")} already here · ${destination}`);
2056
2073
  }
2057
2074
  else {
2058
2075
  console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
@@ -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)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderook/cli",
3
- "version": "0.46.7",
3
+ "version": "0.46.8",
4
4
  "description": "The command line for CodeRook (coderook.com): version control and project hosting for projects of any size. Every save is a compressed snapshot, private or public, never used to train AI.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://coderook.com",
@@ -44,7 +44,7 @@
44
44
  "test:matrix": "node test/state-matrix.mjs",
45
45
  "test:attempt": "node test/attempt-identity.mjs",
46
46
  "test:get": "node test/get-safety.mjs",
47
- "test:live": "node test/e2e.mjs --allow-production && node test/state-matrix.mjs --allow-production && node test/get-safety.mjs --allow-production && node test/get-track.mjs --allow-production && node test/get-protects-edits.mjs --allow-production && node test/upgrade-migration.mjs --allow-production && node test/fault-get.mjs --allow-production && node test/version-floor.mjs --allow-production && node test/fault-submit.mjs --allow-production && node test/race-attempts.mjs --allow-production && node test/attempt-identity.mjs --allow-production",
47
+ "test:live": "node test/e2e.mjs --allow-production && node test/state-matrix.mjs --allow-production && node test/get-safety.mjs --allow-production && node test/get-track.mjs --allow-production && node test/get-protects-edits.mjs --allow-production && node test/upgrade-migration.mjs --allow-production && node test/fault-get.mjs --allow-production && node test/rename-sync.mjs --allow-production && node test/version-floor.mjs --allow-production && node test/fault-submit.mjs --allow-production && node test/race-attempts.mjs --allow-production && node test/attempt-identity.mjs --allow-production",
48
48
  "test:getedits": "node test/get-protects-edits.mjs",
49
49
  "test:upgrade": "node test/upgrade-migration.mjs",
50
50
  "test:faultget": "node test/fault-get.mjs",