@coderook/cli 0.46.6 → 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.6",
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 });
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Uploader = exports.UploadCancelled = void 0;
7
+ exports.packsToFold = packsToFold;
7
8
  /**
8
9
  * Sending a version to CodeRook.
9
10
  *
@@ -158,6 +159,8 @@ class Uploader {
158
159
  deltaBatchSupported = null;
159
160
  /* Set once the service refuses a one-request delta save; later saves go the ordinary way. */
160
161
  deltaSaveRefused = false;
162
+ /** Files this save sends again only to gather them into one pack (see packsToFold). */
163
+ foldPaths = new Set();
161
164
  /* Digests the plan asked about and heard were not held; see storedInBulk. */
162
165
  plannedAbsent = new Set();
163
166
  /** Batch signatures fetched while pricing a save, used once by the pass that sends it. */
@@ -568,6 +571,22 @@ class Uploader {
568
571
  const prior = request.repositoryId
569
572
  ? await this.versionFiles(request.repositoryId, request.baseVersionId, request.listingRoot ?? request.localPath)
570
573
  : new Map();
574
+ /*
575
+ Small files gathered back together when the version has scattered them
576
+ (see packsToFold): the files on disk from those packs join this save,
577
+ and runPass sends them again as one pack.
578
+ */
579
+ const folded = (await this.packingAllowed()) ? packsToFold(prior) : new Set();
580
+ const foldIn = new Set();
581
+ if (folded.size) {
582
+ for (const file of everything) {
583
+ const held = prior.get(file.path);
584
+ if (!held || !folded.has(foldKey(held)) || ticked.has(file.path))
585
+ continue;
586
+ foldIn.add(file.path);
587
+ ticked.add(file.path);
588
+ }
589
+ }
571
590
  // Ticked files are sent; everything else the project still has keeps the
572
591
  // copy already stored, and a file that is new but unticked is left out.
573
592
  const sending = everything.filter((file) => ticked.has(file.path));
@@ -623,6 +642,8 @@ class Uploader {
623
642
  }
624
643
  return {
625
644
  rules,
645
+ folded,
646
+ foldIn,
626
647
  everything,
627
648
  unticked,
628
649
  ticked,
@@ -1575,7 +1596,9 @@ class Uploader {
1575
1596
  is left after this — the large files — is where bandwidth actually
1576
1597
  matters, and those still go one per request through the lanes below.
1577
1598
  */
1578
- const missing = declarations.filter((one) => !alreadyHeld.has(one.sha256));
1599
+ const missing = declarations.filter(
1600
+ /* Gathered files go into the new pack even though their bytes are held loose. */
1601
+ (one) => !alreadyHeld.has(one.sha256) || this.foldPaths.has(one.path));
1579
1602
  const smallOnes = missing.filter((one) => one.size <= BATCH_FILE_LIMIT);
1580
1603
  /* The first file with each digest is sent; the rest are counted when it lands. */
1581
1604
  const copiesOf = new Map();
@@ -1728,7 +1751,7 @@ class Uploader {
1728
1751
  })))
1729
1752
  : null;
1730
1753
  const packedBytes = built ? this.frameSolidPack(built).byteLength : 0;
1731
- const delta = built
1754
+ const delta = built && !this.foldPaths.size
1732
1755
  ? await (0, profile_js_1.timed)("price changed-file batch", () => this.putDeltaBatch(repositoryId, request.baseVersionId, taking, prior, packedBytes, request.localBase))
1733
1756
  : null;
1734
1757
  if (delta) {
@@ -2040,7 +2063,7 @@ class Uploader {
2040
2063
  project held before it, and what a ticked path that is no longer on disk
2041
2064
  means. Nothing below changes any of it.
2042
2065
  */
2043
- const { everything, ticked, prior, sending, reused, deletions, readFailures, vanished, } = await this.selectFiles(request, report);
2066
+ const { folded, foldIn, everything, ticked, prior, sending, reused, deletions, readFailures, vanished, } = await this.selectFiles(request, report);
2044
2067
  /*
2045
2068
  Read once, here. Everything below works from the declarations rather
2046
2069
  than from the disk.
@@ -2089,7 +2112,25 @@ class Uploader {
2089
2112
  return was;
2090
2113
  return priorByDigest.get(declaration.sha256) ?? null;
2091
2114
  };
2092
- const keptAsItWas = (declaration) => storedAs(declaration) !== null;
2115
+ /*
2116
+ Small files gathered back together when the version has scattered them.
2117
+
2118
+ Each save packs only what it changed, so a project saved thousands of
2119
+ times ends up naming a separate tiny pack for nearly every file anybody
2120
+ touched: 47 stored objects at v36 and 1,038 at v1,136 in one 3,000-file
2121
+ project (2026-11-11). Every save, listing and restore then pays per
2122
+ object, which is why saves into a long-lived project slowed from 14 s
2123
+ to 26 s over 4,500 versions. Past a few dozen tiny packs, the unchanged
2124
+ files in them are sent again, together, as one pack. Same bytes, so the
2125
+ version is unchanged; only where it keeps them is.
2126
+ */
2127
+ const reuseOf = (declaration) => {
2128
+ const held = storedAs(declaration);
2129
+ if (held && folded.has(foldKey(held)))
2130
+ return null;
2131
+ return held;
2132
+ };
2133
+ const keptAsItWas = (declaration) => reuseOf(declaration) !== null;
2093
2134
  /*
2094
2135
  A copy left stale by somebody else's save is not an edit.
2095
2136
 
@@ -2119,7 +2160,24 @@ class Uploader {
2119
2160
  staleHere.add(one.path);
2120
2161
  }
2121
2162
  }
2163
+ /*
2164
+ A file joined only to be gathered into one pack is sent only if it is
2165
+ exactly what the version holds. Anything else here is not this save's
2166
+ to send — an edit somebody left unticked, or an old copy — so the
2167
+ version keeps its own.
2168
+ */
2169
+ for (const one of hashed.declarations) {
2170
+ if (foldIn.has(one.path) && prior.get(one.path)?.sha256 !== one.sha256)
2171
+ staleHere.add(one.path);
2172
+ }
2122
2173
  const declarations = hashed.declarations.filter((one) => !staleHere.has(one.path) && !keptAsItWas(one));
2174
+ /* The files sent again only to be gathered: same bytes as the version, held loose or in a tiny pack. */
2175
+ this.foldPaths = new Set(declarations
2176
+ .filter((one) => {
2177
+ const held = storedAs(one);
2178
+ return !!held && folded.has(foldKey(held));
2179
+ })
2180
+ .map((one) => one.path));
2123
2181
  let totalBytes = hashed.totalBytes;
2124
2182
  for (const one of hashed.declarations) {
2125
2183
  if (!staleHere.has(one.path))
@@ -2147,7 +2205,7 @@ class Uploader {
2147
2205
  for (const one of hashed.declarations) {
2148
2206
  if (staleHere.has(one.path))
2149
2207
  continue;
2150
- const held = storedAs(one);
2208
+ const held = reuseOf(one);
2151
2209
  if (!held)
2152
2210
  continue;
2153
2211
  totalBytes -= one.size;
@@ -2166,6 +2224,8 @@ class Uploader {
2166
2224
  });
2167
2225
  }
2168
2226
  (0, profile_js_1.counted)("files kept as they were", hashed.declarations.length - declarations.length);
2227
+ if (folded.size)
2228
+ (0, profile_js_1.counted)("tiny packs gathered into one", folded.size);
2169
2229
  // 2. The project needs somewhere on the account to live.
2170
2230
  const repositoryId = await this.ensureRepository(request);
2171
2231
  // Learn the wire contract once, before the two section pipelines begin.
@@ -2271,7 +2331,18 @@ class Uploader {
2271
2331
  })
2272
2332
  : null;
2273
2333
  quoting?.catch(() => undefined);
2274
- const oneRequest = this.deltaSaveRefused
2334
+ /* A save gathering scattered files has to store a new pack, which a patch cannot. */
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
2275
2346
  ? null
2276
2347
  : await this.deltaSavePlan(request, repositoryId, declarations, prior);
2277
2348
  if (oneRequest && this.planning && request.oneRoundTrip) {
@@ -2515,10 +2586,10 @@ class Uploader {
2515
2586
  : null;
2516
2587
  if (cached)
2517
2588
  return cached;
2518
- const body = await this.call(`/v1/repositories/${repositoryId}/versions/${versionId}/files`, {
2519
- method: "GET",
2520
- });
2521
- const rows = body.files ?? [];
2589
+ const rows = (localPath ? await this.patchedListing(repositoryId, versionId, localPath) : null) ??
2590
+ ((await this.call(`/v1/repositories/${repositoryId}/versions/${versionId}/files`, {
2591
+ method: "GET",
2592
+ })).files ?? []);
2522
2593
  if (localPath)
2523
2594
  await writeListing(localPath, repositoryId, versionId, rows);
2524
2595
  return rows;
@@ -2527,6 +2598,40 @@ class Uploader {
2527
2598
  reading.catch(() => versionListings.delete(key));
2528
2599
  return reading;
2529
2600
  }
2601
+ /**
2602
+ * A version's listing made from the newest one this folder already keeps,
2603
+ * plus only what changed since it. Null when there is nothing kept to start
2604
+ * from, or the service answers in full (one that predates `since`), or the
2605
+ * result does not add up — the caller then asks for the whole listing.
2606
+ *
2607
+ * With several people or agents saving, the version a save starts from is
2608
+ * nearly always somebody else's, so the folder's kept listing was never the
2609
+ * one wanted and each save downloaded the whole listing again: 4.66 MB for
2610
+ * 14,125 files, on every save (2026-11-11).
2611
+ */
2612
+ async patchedListing(repositoryId, versionId, localPath) {
2613
+ try {
2614
+ const base = await newestListing(localPath, repositoryId);
2615
+ if (!base || base.versionId === versionId)
2616
+ return null;
2617
+ const body = await this.call(`/v1/repositories/${repositoryId}/versions/${versionId}/files?since=${encodeURIComponent(base.versionId)}`, { method: "GET" });
2618
+ if (body.since !== base.versionId || !Array.isArray(body.changed) || !Array.isArray(body.removed)) {
2619
+ return body.files ?? null;
2620
+ }
2621
+ const byPath = new Map(base.files.map((row) => [String(row.path), row]));
2622
+ for (const gone of body.removed)
2623
+ byPath.delete(gone);
2624
+ for (const row of body.changed)
2625
+ byPath.set(String(row.path), row);
2626
+ if (byPath.size !== body.fileCount)
2627
+ return null;
2628
+ return [...byPath.values()];
2629
+ }
2630
+ catch {
2631
+ /* Anything unexpected costs one full listing, nothing more. */
2632
+ return null;
2633
+ }
2634
+ }
2530
2635
  /** The account's repository with this slug, if it has one. */
2531
2636
  async findBySlug(slug) {
2532
2637
  try {
@@ -3849,6 +3954,26 @@ async function readListing(localPath, repositoryId, versionId) {
3849
3954
  return null;
3850
3955
  }
3851
3956
  }
3957
+ /** The most recently written listing this folder keeps for the project, or null. */
3958
+ async function newestListing(localPath, repositoryId) {
3959
+ const folder = node_path_1.default.join(localPath, ".coderook", "versions");
3960
+ try {
3961
+ const entries = await Promise.all((await (0, promises_1.readdir)(folder))
3962
+ .filter((name) => name.endsWith(".json"))
3963
+ .map(async (name) => ({ name, at: (await (0, promises_1.stat)(node_path_1.default.join(folder, name))).mtimeMs })));
3964
+ entries.sort((left, right) => right.at - left.at);
3965
+ for (const entry of entries) {
3966
+ const versionId = entry.name.slice(0, -".json".length);
3967
+ const files = await readListing(localPath, repositoryId, versionId);
3968
+ if (files)
3969
+ return { versionId, files };
3970
+ }
3971
+ }
3972
+ catch {
3973
+ /* No kept listings yet. */
3974
+ }
3975
+ return null;
3976
+ }
3852
3977
  async function writeListing(localPath, repositoryId, versionId, files) {
3853
3978
  const folder = node_path_1.default.join(localPath, ".coderook", "versions");
3854
3979
  try {
@@ -3870,6 +3995,54 @@ async function writeListing(localPath, repositoryId, versionId, files) {
3870
3995
  /* A cache that cannot be written costs one download next time, nothing more. */
3871
3996
  }
3872
3997
  }
3998
+ /*
3999
+ When a version names this many small stored objects (a loose small file, or a
4000
+ pack holding only a few of the version's files), a save gathers their files
4001
+ into one pack. At most this many bytes are sent again in one save, smallest
4002
+ first.
4003
+ */
4004
+ const FOLD_AT_OBJECTS = 64;
4005
+ const TINY_PACK_FILES = 8;
4006
+ const SMALL_OBJECT_BYTES = 256 * 1024;
4007
+ const MOST_BYTES_FOLDED = 32 * 1024 * 1024;
4008
+ /** Text, source and markup: what solid packs compress well. */
4009
+ function textLike(mediaType) {
4010
+ return /^text\/|json|javascript|typescript|xml|yaml|toml|csv|svg|x-sh|x-python|sql|markdown/i.test(mediaType);
4011
+ }
4012
+ /** Which stored object a file's bytes live in, for packsToFold; empty for a file in pieces. */
4013
+ function foldKey(held) {
4014
+ return held.pack?.objectId ?? (held.chunks?.length ? "" : held.objectId ?? "");
4015
+ }
4016
+ /** The stored objects whose files this save should send again together; empty almost always. */
4017
+ function packsToFold(prior) {
4018
+ const objects = new Map();
4019
+ /* Only what always packs well: text. Compressed media sent again would just land loose again. */
4020
+ const unpackable = new Set();
4021
+ for (const held of prior.values()) {
4022
+ const id = foldKey(held);
4023
+ if (!id)
4024
+ continue;
4025
+ if (held.mediaType !== undefined && !textLike(held.mediaType))
4026
+ unpackable.add(id);
4027
+ const one = objects.get(id) ?? { files: 0, bytes: 0 };
4028
+ one.files += 1;
4029
+ one.bytes += held.sourceSize;
4030
+ objects.set(id, one);
4031
+ }
4032
+ const small = [...objects].filter(([id, one]) => !unpackable.has(id) && one.files <= TINY_PACK_FILES && one.bytes <= SMALL_OBJECT_BYTES);
4033
+ if (small.length < FOLD_AT_OBJECTS)
4034
+ return new Set();
4035
+ small.sort((left, right) => left[1].bytes - right[1].bytes);
4036
+ const chosen = new Set();
4037
+ let bytes = 0;
4038
+ for (const [id, one] of small) {
4039
+ if (bytes + one.bytes > MOST_BYTES_FOLDED)
4040
+ break;
4041
+ bytes += one.bytes;
4042
+ chosen.add(id);
4043
+ }
4044
+ return chosen;
4045
+ }
3873
4046
  /** A file the previous version holds, in the shape a save names it. */
3874
4047
  function wireFromPrior(filePath, held) {
3875
4048
  return {
@@ -1918,7 +1918,7 @@ held, mode = "replace",
1918
1918
  */
1919
1919
  trackName) {
1920
1920
  const downloader = new download_js_1.Downloader(config_js_1.credentials);
1921
- const all = await downloader.versions(repositoryId);
1921
+ let all = await downloader.versions(repositoryId);
1922
1922
  /*
1923
1923
  The head of this folder's line, not the newest version in the project.
1924
1924
 
@@ -1943,7 +1943,18 @@ trackName) {
1943
1943
  console.error(red(`The line ${trackName} has nothing saved to it yet.`));
1944
1944
  return 1;
1945
1945
  }
1946
- const head = all.find((version) => version.id === chosen.headVersionId);
1946
+ let head = all.find((version) => version.id === chosen.headVersionId);
1947
+ /*
1948
+ A save that lands between reading the versions and reading the line
1949
+ moves the head past the list just read. With several people or agents
1950
+ saving that is routine, and it ended clones with "Could not read the
1951
+ current version" (2026-11-11). Read both again, the line first.
1952
+ */
1953
+ for (let attempt = 0; !head && attempt < 3; attempt += 1) {
1954
+ const again = (await new tracks_js_1.Tracks(config_js_1.credentials).list(repositoryId)).find((candidate) => candidate.name === trackName && candidate.kind === "line");
1955
+ all = await downloader.versions(repositoryId);
1956
+ head = all.find((version) => version.id === again?.headVersionId);
1957
+ }
1947
1958
  if (!head) {
1948
1959
  console.error(red(`Could not read the current version of ${trackName}.`));
1949
1960
  return 1;
@@ -1967,6 +1978,8 @@ trackName) {
1967
1978
  });
1968
1979
  }
1969
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());
1970
1983
  let result;
1971
1984
  try {
1972
1985
  result = await downloader.run(repositoryId, latest.id, destination, (progress) => {
@@ -1976,7 +1989,7 @@ trackName) {
1976
1989
  },
1977
1990
  // What this folder received last time, so a file the project has since
1978
1991
  // dropped is removed while everything untracked is left alone.
1979
- held, mode);
1992
+ held, mode, knownDigests);
1980
1993
  }
1981
1994
  catch (error) {
1982
1995
  done(line);
@@ -2028,6 +2041,18 @@ trackName) {
2028
2041
  ...(trackName ? { track: trackName } : {}),
2029
2042
  // Reached the end, so there is no longer a fetch in flight.
2030
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
+ }
2031
2056
  // The record is written; the run has not reported success yet.
2032
2057
  (0, faults_js_1.maybeFail)("get:after-record");
2033
2058
  /*
@@ -2036,12 +2061,15 @@ trackName) {
2036
2061
  when not a byte had moved.
2037
2062
  */
2038
2063
  const unchanged = result.unchanged ?? 0;
2039
- 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) {
2040
2068
  console.log(`Already up to date · ${accent(`v${latest.sequence}`)} · ${fileCount(result.files)}`);
2041
2069
  }
2042
2070
  else if (unchanged > 0) {
2043
2071
  const fetched = result.files - unchanged;
2044
- 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}`);
2045
2073
  }
2046
2074
  else {
2047
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.6",
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",