@coderook/cli 0.46.4 → 0.46.6

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.
@@ -1,19 +1,19 @@
1
- {
2
- "name": "coderook",
3
- "displayName": "CodeRook",
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.3",
6
- "author": {
7
- "name": "ACCA Gaming Productions",
8
- "url": "https://coderook.com"
9
- },
10
- "homepage": "https://coderook.com/docs#assistants",
11
- "license": "Apache-2.0",
12
- "keywords": [
13
- "coderook",
14
- "versioning",
15
- "snapshots",
16
- "backup",
17
- "git"
18
- ]
19
- }
1
+ {
2
+ "name": "coderook",
3
+ "displayName": "CodeRook",
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",
6
+ "author": {
7
+ "name": "ACCA Gaming Productions",
8
+ "url": "https://coderook.com"
9
+ },
10
+ "homepage": "https://coderook.com/docs#assistants",
11
+ "license": "Apache-2.0",
12
+ "keywords": [
13
+ "coderook",
14
+ "versioning",
15
+ "snapshots",
16
+ "backup",
17
+ "git"
18
+ ]
19
+ }
@@ -285,7 +285,10 @@ class Downloader {
285
285
  async bytes(route, what, halt) {
286
286
  return this.repeat(async () => {
287
287
  const reply = await this.attempt(route, REQUEST_DEADLINE_MS, halt);
288
- return { body: Buffer.from(await reply.arrayBuffer()), headers: reply.headers };
288
+ const raw = Buffer.from(await reply.arrayBuffer());
289
+ /* Sent as stored (see attempt): unpacked here instead of in the service. */
290
+ const body = reply.headers.get("x-coderook-encoding") === "gzip" ? (0, node_zlib_1.gunzipSync)(raw) : raw;
291
+ return { body, headers: reply.headers };
289
292
  }, { what, halt });
290
293
  }
291
294
  async attempt(route,
@@ -310,6 +313,11 @@ class Downloader {
310
313
  authorization: `Bearer ${token}`,
311
314
  "user-agent": "CodeRook/0.1",
312
315
  ...(0, identify_js_1.clientHeaders)(),
316
+ /*
317
+ An object kept compressed may be sent exactly as stored, and is
318
+ unpacked here. A service that predates this ignores the header.
319
+ */
320
+ ...(route.includes("/objects/") ? { "x-coderook-accept-stored": "gzip" } : {}),
313
321
  ...extra,
314
322
  },
315
323
  /*
@@ -689,11 +697,31 @@ class Downloader {
689
697
  through a large file costs the piece that was arriving and no more: the
690
698
  ones already written stay written, and the file carries on from there.
691
699
  */
700
+ /*
701
+ A few pieces are asked for ahead of the one being written, and written
702
+ strictly in order. One at a time, a single large file ran at one
703
+ request's speed whatever the line could carry: the last 360 MB file of
704
+ a 1.25 GB restore came down at 2.6 MB/s (2026-11-11).
705
+ */
706
+ const AHEAD = 4;
692
707
  const source = (async function* () {
708
+ const asked = [];
709
+ const ask = (at) => {
710
+ const piece = pieces[at];
711
+ const reply = fetchPiece(`/v1/repositories/${repositoryId}/objects/${piece.objectId}`, `${file.path} (piece ${at + 1} of ${pieces.length})`);
712
+ /* Awaited in turn below; this only stops an early stop leaving it unhandled. */
713
+ reply.catch(() => undefined);
714
+ asked[at] = reply;
715
+ };
693
716
  for (let at = 0; at < pieces.length; at += 1) {
694
717
  check();
718
+ for (let ahead = at; ahead < Math.min(pieces.length, at + AHEAD); ahead += 1) {
719
+ if (!asked[ahead])
720
+ ask(ahead);
721
+ }
695
722
  const piece = pieces[at];
696
- const reply = await fetchPiece(`/v1/repositories/${repositoryId}/objects/${piece.objectId}`, `${file.path} (piece ${at + 1} of ${pieces.length})`);
723
+ const reply = await asked[at];
724
+ delete asked[at];
697
725
  let body = reply.body;
698
726
  /*
699
727
  Checked against what the upload recorded for this piece, before
@@ -781,7 +809,8 @@ class Downloader {
781
809
  });
782
810
  }
783
811
  else {
784
- await (0, promises_2.pipeline)(node_stream_1.Readable.fromWeb(reply.body), new node_stream_1.Transform({
812
+ const source = node_stream_1.Readable.fromWeb(reply.body);
813
+ const hashing = new node_stream_1.Transform({
785
814
  transform(block, _encoding, done) {
786
815
  try {
787
816
  check();
@@ -794,7 +823,14 @@ class Downloader {
794
823
  hash.update(buffer);
795
824
  done(null, buffer);
796
825
  },
797
- }), sink);
826
+ });
827
+ /* Sent as stored (see attempt): unpacked on the way to the disk. */
828
+ if (reply.headers.get("x-coderook-encoding") === "gzip") {
829
+ await (0, promises_2.pipeline)(source, (0, node_zlib_1.createGunzip)(), hashing, sink);
830
+ }
831
+ else {
832
+ await (0, promises_2.pipeline)(source, hashing, sink);
833
+ }
798
834
  }
799
835
  return hash.digest("hex");
800
836
  }, {
@@ -850,6 +886,27 @@ class Downloader {
850
886
  try {
851
887
  let written = 0;
852
888
  let bytes = 0;
889
+ /*
890
+ Not fetched at all: a file the incoming version did not change, still
891
+ here. Reconciling never writes one of these (see the placing loop
892
+ below), so downloading it only to throw it away made every catch-up
893
+ cost a full restore — a folder already on the newest version fetched
894
+ the whole project again (2026-11-11 soak: eight current folders of
895
+ 14,125 files each spent twenty minutes re-downloading 306 MB apiece).
896
+ */
897
+ const kept = new Set();
898
+ if (mode === "reconcile" && held) {
899
+ for (const file of files) {
900
+ if (!file.sha256 || held[file.path] !== file.sha256)
901
+ continue;
902
+ if (!(await exists((0, safe_path_js_1.inside)(destination, file.path))))
903
+ continue;
904
+ kept.add(file.path);
905
+ manifest[file.path] = file.sha256;
906
+ written += 1;
907
+ bytes += file.sourceSize;
908
+ }
909
+ }
853
910
  const packed = new Map();
854
911
  for (const file of files) {
855
912
  /* Sealed members never come out of the pack — see `sealed` above. */
@@ -883,9 +940,12 @@ class Downloader {
883
940
  if (restoredPacks.has(id))
884
941
  continue;
885
942
  restoredPacks.add(id);
943
+ /* A pack is fetched only when something in it is needed. */
944
+ if ((packed.get(id) ?? []).every((member) => kept.has(member.path)))
945
+ continue;
886
946
  jobs.push({ kind: "pack", id });
887
947
  }
888
- else {
948
+ else if (!kept.has(file.path)) {
889
949
  jobs.push({ kind: "file", file });
890
950
  }
891
951
  }
@@ -935,6 +995,9 @@ class Downloader {
935
995
  }
936
996
  for (const member of packed.get(packId) ?? []) {
937
997
  this.check();
998
+ /* Already here and unchanged: counted and recorded when the work was planned. */
999
+ if (kept.has(member.path))
1000
+ continue;
938
1001
  const offset = member.pack.offset;
939
1002
  const length = member.pack.length;
940
1003
  if (offset < 0 || length < 0 || offset + length > body.byteLength) {
@@ -1079,6 +1142,9 @@ class Downloader {
1079
1142
  let placed = 0;
1080
1143
  for (const file of files) {
1081
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;
1082
1148
  /*
1083
1149
  Reconciling leaves alone whatever the incoming version did not
1084
1150
  change. Writing it anyway would replace an edit in progress with a
@@ -1134,7 +1200,8 @@ class Downloader {
1134
1200
  path: "Done",
1135
1201
  percent: 100,
1136
1202
  });
1137
- return { files: written, bytes, manifest };
1203
+ /* 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 };
1138
1205
  }
1139
1206
  catch (error) {
1140
1207
  await (0, promises_1.rm)(staging, { recursive: true, force: true });
@@ -136,6 +136,9 @@ const signatures = new Map();
136
136
  const KEPT_LISTINGS = 3;
137
137
  /* The largest new file a one-request delta save carries as its own bytes. */
138
138
  const DELTA_SAVE_NEW_FILE_BYTES = 1024 * 1024;
139
+ /* With oneRoundTrip: an edit this small goes whole, up to this much in one save. */
140
+ const WHOLE_EDIT_BYTES = 256 * 1024;
141
+ const WHOLE_EDITS_BUDGET = 1024 * 1024;
139
142
  /** A delta save the service would not take; the save is sent the ordinary way. */
140
143
  class DeltaSaveRefused extends Error {
141
144
  }
@@ -521,27 +524,29 @@ class Uploader {
521
524
  truncated version of it would propose deleting everything the walk did
522
525
  not reach.
523
526
  */
524
- const everything = await (0, profile_js_1.timed)("survey the project", () => (0, worktree_js_1.surveyFiles)(request.localPath, rules, (found) =>
525
- /*
526
- The walk is the first minute of a large save and said nothing at
527
- all, so the panel could only show 0%. A running count of what has
528
- been seen is not a fraction of anything — it is the evidence that
529
- the thing is working.
530
- */
531
- report({
532
- stage: "plan",
533
- files: found,
534
- totalFiles: 0,
535
- bytes: 0,
536
- totalBytes: 0,
537
- path: "Looking through the folder",
527
+ const everything = request.survey
528
+ ? [...request.survey].sort((left, right) => left.path.localeCompare(right.path))
529
+ : await (0, profile_js_1.timed)("survey the project", () => (0, worktree_js_1.surveyFiles)(request.localPath, rules, (found) =>
538
530
  /*
539
- Between the key check and the reading, and it holds its own place
540
- on the bar rather than dropping back to nought between them.
531
+ The walk is the first minute of a large save and said nothing at
532
+ all, so the panel could only show 0%. A running count of what has
533
+ been seen is not a fraction of anything — it is the evidence that
534
+ the thing is working.
541
535
  */
542
- percent: 6,
543
- bytesPerSecond: 0,
544
- })));
536
+ report({
537
+ stage: "plan",
538
+ files: found,
539
+ totalFiles: 0,
540
+ bytes: 0,
541
+ totalBytes: 0,
542
+ path: "Looking through the folder",
543
+ /*
544
+ Between the key check and the reading, and it holds its own place
545
+ on the bar rather than dropping back to nought between them.
546
+ */
547
+ percent: 6,
548
+ bytesPerSecond: 0,
549
+ })));
545
550
  if (tracked) {
546
551
  const layers = await (0, worktree_js_1.collectLayers)(request.localPath, rules);
547
552
  this.trackedByGit = everything
@@ -719,6 +724,11 @@ class Uploader {
719
724
  Anything it does not answer is hashed here as before.
720
725
  */
721
726
  const ahead = new Map();
727
+ const surveyedTimes = new Map();
728
+ for (const one of request.survey ?? []) {
729
+ if (typeof one.mtimeMs === "number")
730
+ surveyedTimes.set(one.path, one.mtimeMs);
731
+ }
722
732
  {
723
733
  const unknown = sending.filter((file) => {
724
734
  const remembered = this.plannedDigests.get(file.path) ?? request.knownDigests?.get(file.path);
@@ -749,20 +759,32 @@ class Uploader {
749
759
  const full = node_path_1.default.join(request.localPath, file.path);
750
760
  let size;
751
761
  let mtimeMs;
752
- try {
753
- const info = await (0, promises_1.stat)(full);
754
- size = info.size;
755
- mtimeMs = info.mtimeMs;
756
- }
757
- catch (error) {
758
- // Unreadable now, though it was listed a moment ago. Skipping it
759
- // would publish a version quietly missing a file the person chose.
760
- vanished.push(file.path);
761
- readFailures.set(file.path, error instanceof Error ? error.message : String(error));
762
- hashed += 1;
763
- readDone += file.size;
764
- continue;
762
+ /*
763
+ The caller's walk of this folder (UploadRequest.survey) stated every
764
+ file a moment ago; statting all of them again here cost 0.4 s per
765
+ pass on a 14,000-file folder, twice a save. A file that moved since
766
+ is still caught: its bytes are hashed before they are sent.
767
+ */
768
+ const surveyed = surveyedTimes.get(file.path);
769
+ if (surveyed !== undefined) {
770
+ size = file.size;
771
+ mtimeMs = surveyed;
765
772
  }
773
+ else
774
+ try {
775
+ const info = await (0, promises_1.stat)(full);
776
+ size = info.size;
777
+ mtimeMs = info.mtimeMs;
778
+ }
779
+ catch (error) {
780
+ // Unreadable now, though it was listed a moment ago. Skipping it
781
+ // would publish a version quietly missing a file the person chose.
782
+ vanished.push(file.path);
783
+ readFailures.set(file.path, error instanceof Error ? error.message : String(error));
784
+ hashed += 1;
785
+ readDone += file.size;
786
+ continue;
787
+ }
766
788
  /*
767
789
  Hashing is the first thing that opens the file, and opening is what
768
790
  fails on a file another program holds — a database in use, a browser
@@ -2230,6 +2252,7 @@ class Uploader {
2230
2252
  has, and this answer is simply not used.
2231
2253
  */
2232
2254
  const quoting = this.planning &&
2255
+ !request.oneRoundTrip &&
2233
2256
  !this.deltaSaveRefused &&
2234
2257
  typeof request.baseVersionId === "string" &&
2235
2258
  prior.size > 0 &&
@@ -2251,7 +2274,27 @@ class Uploader {
2251
2274
  const oneRequest = this.deltaSaveRefused
2252
2275
  ? null
2253
2276
  : await this.deltaSavePlan(request, repositoryId, declarations, prior);
2254
- if (oneRequest && this.planning) {
2277
+ if (oneRequest && this.planning && request.oneRoundTrip) {
2278
+ /* Priced from its own numbers: the service checks storage when the save arrives. */
2279
+ this.plannedQuote = {
2280
+ quoteId: "",
2281
+ repositoryId,
2282
+ sourceBytes: totalBytes,
2283
+ excludedBytes: 0,
2284
+ compactedBytes: oneRequest.patchBytes,
2285
+ reusableBytes: 0,
2286
+ chargeableBytes: oneRequest.patchBytes,
2287
+ storage: { usedBytes: 0, quotaBytes: 0, remainingBytes: 0 },
2288
+ allowance: {
2289
+ exempt: true, stage: 0, unlockedPercent: 0, unlockedBytes: 0, chargedBytes: 0,
2290
+ reservedBytes: 0, remainingBytes: 0, periodStart: "", periodEnd: "", nextUnlockAt: null,
2291
+ },
2292
+ expiresAt: "",
2293
+ objects: {},
2294
+ estimated: true,
2295
+ };
2296
+ }
2297
+ else if (oneRequest && this.planning) {
2255
2298
  report({
2256
2299
  stage: "publish",
2257
2300
  files: declarations.length,
@@ -2272,6 +2315,8 @@ class Uploader {
2272
2315
  track: request.track ?? "main",
2273
2316
  }),
2274
2317
  }));
2318
+ }
2319
+ if (oneRequest && this.planning && this.plannedQuote) {
2275
2320
  return {
2276
2321
  repositoryId,
2277
2322
  versionId: "",
@@ -2846,6 +2891,13 @@ class Uploader {
2846
2891
  const targets = [];
2847
2892
  const held = [];
2848
2893
  const signed = [];
2894
+ /*
2895
+ For a client waiting on the save, a small edit goes whole: asking for
2896
+ its base's signatures is a round trip (0.4 s from Australia to the
2897
+ service), and a 20 KB source file compressed in the envelope costs far
2898
+ less than that to send. Bounded, so a save of many edits still asks.
2899
+ */
2900
+ let wholeBudget = request.oneRoundTrip ? WHOLE_EDITS_BUDGET : 0;
2849
2901
  for (const [index, declaration] of declarations.entries()) {
2850
2902
  let target;
2851
2903
  try {
@@ -2862,6 +2914,10 @@ class Uploader {
2862
2914
  held.push(base);
2863
2915
  if (base)
2864
2916
  continue;
2917
+ if (was && declaration.size <= WHOLE_EDIT_BYTES && declaration.size <= wholeBudget) {
2918
+ wholeBudget -= declaration.size;
2919
+ continue;
2920
+ }
2865
2921
  if (was && (0, delta_js_1.estimateDeltaSignatureBytes)(was.sourceSize, 2) < declaration.size * 0.8) {
2866
2922
  signed.push(index);
2867
2923
  }
@@ -938,7 +938,14 @@ exact = true,
938
938
  not. A caller asking which saved files are gone from the folder needs only
939
939
  stat the ones missing from it, rather than every file the save holds.
940
940
  */
941
- seen) {
941
+ seen,
942
+ /*
943
+ Told how many files have been read so far and how many need reading: the
944
+ ones whose size or time no longer match what was recorded. A folder with
945
+ no usable record reads everything, which on a large project is minutes,
946
+ and said nothing while it did.
947
+ */
948
+ onReading) {
942
949
  /* What git already tracks goes up whatever a rule says; see gitTracked. */
943
950
  const tracked = await gitTracked(root);
944
951
  /*
@@ -970,7 +977,7 @@ seen) {
970
977
  */
971
978
  for (const one of native ?? []) {
972
979
  present.add(one.path);
973
- outcome?.sizes.push({ path: one.path, size: one.size });
980
+ outcome?.sizes.push({ path: one.path, size: one.size, mtimeMs: one.mtimeMs });
974
981
  found.push({ full: node_path_1.default.join(root, ...one.path.split("/")), relative: one.path, size: one.size, mtimeMs: one.mtimeMs });
975
982
  }
976
983
  for (let next = 0; !native && next < pending.length; next++) {
@@ -1035,7 +1042,7 @@ seen) {
1035
1042
  kept out — files sitting right there on disk.
1036
1043
  */
1037
1044
  present.add(one.relative);
1038
- outcome?.sizes.push({ path: one.relative, size: one.size });
1045
+ outcome?.sizes.push({ path: one.relative, size: one.size, mtimeMs: one.mtimeMs });
1039
1046
  found.push(one);
1040
1047
  }
1041
1048
  }
@@ -1062,6 +1069,8 @@ seen) {
1062
1069
  return one.size <= LINE_COUNT_LIMIT || (baseline?.has(one.relative) ?? false);
1063
1070
  };
1064
1071
  let readAheadTo = 0;
1072
+ const toRead = onReading ? order.filter(needsReading).length : 0;
1073
+ let read = 0;
1065
1074
  for (let at = 0; at < order.length; at += 1) {
1066
1075
  if (files.length >= limit)
1067
1076
  break;
@@ -1091,6 +1100,11 @@ seen) {
1091
1100
  }
1092
1101
  const one = order[at];
1093
1102
  const { full, relative, size, mtimeMs } = one;
1103
+ if (onReading && toRead && needsReading(one)) {
1104
+ read += 1;
1105
+ if (read === 1 || read % 25 === 0 || read === toRead)
1106
+ onReading(read, toRead);
1107
+ }
1094
1108
  const measured = readAhead.get(relative) ??
1095
1109
  (await measure(full, size, {
1096
1110
  mtimeMs,
@@ -135,6 +135,40 @@ function progressLine() {
135
135
  }
136
136
  /** The shared bar, drawn from a percentage and this session's colour setting. */
137
137
  const track = (percent) => (0, progress_js_1.bar)(percent / 100, 18, dim);
138
+ /*
139
+ A line that counts files read while changes are worked out, shown only when
140
+ there are enough to take a while. A folder whose record of its files did not
141
+ match read every file in silence, and a save looked as if it had stopped.
142
+ */
143
+ function readingProgress() {
144
+ let line = null;
145
+ let shown = false;
146
+ let latest = null;
147
+ const draw = (read, toRead) => {
148
+ if (toRead < 200)
149
+ return;
150
+ line ??= progressLine();
151
+ line(` Reading files to find what changed · ${read.toLocaleString()} of ${toRead.toLocaleString()}` +
152
+ dim(" (once; later saves only read what changes)"));
153
+ };
154
+ return {
155
+ report: (read, toRead) => {
156
+ latest = [read, toRead];
157
+ if (shown)
158
+ draw(read, toRead);
159
+ },
160
+ show: () => {
161
+ shown = true;
162
+ if (latest && latest[0] < latest[1])
163
+ draw(latest[0], latest[1]);
164
+ },
165
+ done: () => {
166
+ if (line)
167
+ done(line);
168
+ line = null;
169
+ },
170
+ };
171
+ }
138
172
  const done = (line) => {
139
173
  if (node_process_1.default.stdout.isTTY) {
140
174
  line("");
@@ -561,7 +595,7 @@ async function commandStatus(parsed) {
561
595
  the folder each time it ran. What it learns is kept for the next run.
562
596
  */
563
597
  const knownDigests = link?.repositoryId
564
- ? await (0, config_js_1.readDigests)(link.repositoryId)
598
+ ? await (0, config_js_1.readDigests)(link.repositoryId, folder)
565
599
  : new Map();
566
600
  let learned = 0;
567
601
  const remember = knownDigests.set.bind(knownDigests);
@@ -569,9 +603,12 @@ async function commandStatus(parsed) {
569
603
  learned += 1;
570
604
  return remember(key, value);
571
605
  };
572
- const found = await (0, worktree_js_1.changedFiles)(folder, rules, baseline, "synchronize", knownDigests, undefined, false);
606
+ const reading = readingProgress();
607
+ reading.show();
608
+ const found = await (0, worktree_js_1.changedFiles)(folder, rules, baseline, "synchronize", knownDigests, undefined, false, undefined, reading.report);
609
+ reading.done();
573
610
  if (learned && link?.repositoryId)
574
- await (0, config_js_1.writeDigests)(link.repositoryId, knownDigests);
611
+ await (0, config_js_1.writeDigests)(link.repositoryId, knownDigests, folder);
575
612
  const gone = found.filter((file) => file.deleted);
576
613
  const files = found.filter((file) => !file.deleted);
577
614
  // Tells the project's Actions page what this machine's folder holds; never delays or fails status.
@@ -849,6 +886,15 @@ async function digestOfFile(full) {
849
886
  return null;
850
887
  }
851
888
  }
889
+ /** Whether two path-to-digest maps say the same thing (the early scan's baseline and reconcile's). */
890
+ function sameEntries(left, right) {
891
+ if (!right || left.size !== right.size)
892
+ return false;
893
+ for (const [file, digest] of left)
894
+ if (right.get(file) !== digest)
895
+ return false;
896
+ return true;
897
+ }
852
898
  /**
853
899
  * Say so when files deleted here are still in the saved version.
854
900
  *
@@ -934,10 +980,34 @@ async function commandSubmit(parsed) {
934
980
  /* Made before the scan so its capability check overlaps it (prefetchCapabilities). */
935
981
  const firstUploader = new upload_js_1.Uploader(config_js_1.credentials);
936
982
  firstUploader.prefetchCapabilities();
983
+ /*
984
+ A linked folder's scan, started while the service is asked about the
985
+ project rather than after. The baseline it compares against is this
986
+ folder's own record, which is what reconcile answers with when the folder
987
+ is level; when it answers otherwise, or with another project, this is
988
+ dropped and the scan below runs as it always has. Nothing is written into
989
+ a linked folder before that scan (only a first save adds a LICENSE), so
990
+ starting early changes what it sees by nothing but the moment.
991
+ */
992
+ /* Shown only when a folder has to read a lot to find its changes (readingProgress). */
993
+ const reading = readingProgress();
994
+ const linkedNow = adopt || hasFlag(parsed, "allow-ignored") ? null : await (0, config_js_1.readLink)(folder).catch(() => null);
995
+ const earlyScan = linkedNow?.repositoryId && linkedNow.manifest
996
+ ? (async () => {
997
+ const rules = await (0, worktree_js_1.readRules)(folder);
998
+ const knownDigests = await (0, config_js_1.readDigests)(linkedNow.repositoryId, folder);
999
+ const baseline = new Map(Object.entries(linkedNow.local ?? linkedNow.manifest));
1000
+ const seen = new Set();
1001
+ const listing = { listed: 0, total: 0, sizes: [] };
1002
+ const files = await (0, worktree_js_1.changedFiles)(folder, rules, baseline, hasFlag(parsed, "sync") ? "synchronize" : "add-and-update", knownDigests, listing, true, seen, reading.report);
1003
+ return { repositoryId: linkedNow.repositoryId, rules, knownDigests, baseline, seen, listing, files };
1004
+ })().catch(() => null)
1005
+ : null;
937
1006
  const { link, baseline, behind, member } = await reconcile(folder, {
938
1007
  ...(adopt ? { adopt } : {}),
939
1008
  persist: !dryRun,
940
1009
  });
1010
+ reading.show();
941
1011
  /*
942
1012
  Somebody else's project, cloned from its public page. Reading and
943
1013
  fetching are fine; saving into it is not this account's to do, and the
@@ -1021,11 +1091,35 @@ async function commandSubmit(parsed) {
1021
1091
  same map serves both — `changedFiles` fills it in place, so what the scan
1022
1092
  learns is what the upload is handed.
1023
1093
  */
1024
- const knownDigests = link?.repositoryId
1025
- ? await (0, config_js_1.readDigests)(link.repositoryId)
1026
- : new Map();
1027
- const seen = new Set();
1028
- const files = await (0, worktree_js_1.changedFiles)(folder, rules, baseline, hasFlag(parsed, "sync") ? "synchronize" : "add-and-update", knownDigests, undefined, true, seen);
1094
+ const early = earlyScan ? await earlyScan : null;
1095
+ const reuse = early &&
1096
+ !importing &&
1097
+ link?.repositoryId === early.repositoryId &&
1098
+ early.rules.shared === rules.shared &&
1099
+ early.rules.local === rules.local &&
1100
+ sameEntries(early.baseline, baseline)
1101
+ ? early
1102
+ : null;
1103
+ const knownDigests = reuse
1104
+ ? reuse.knownDigests
1105
+ : link?.repositoryId
1106
+ ? await (0, config_js_1.readDigests)(link.repositoryId, folder)
1107
+ : new Map();
1108
+ const seen = reuse ? reuse.seen : new Set();
1109
+ const listing = reuse ? reuse.listing : { listed: 0, total: 0, sizes: [] };
1110
+ const recordedBefore = new Map(knownDigests);
1111
+ const files = reuse
1112
+ ? reuse.files
1113
+ : await (0, worktree_js_1.changedFiles)(folder, rules, baseline, hasFlag(parsed, "sync") ? "synchronize" : "add-and-update", knownDigests, listing, true, seen, reading.report);
1114
+ reading.done();
1115
+ /*
1116
+ What the scan read, kept now rather than after the save. A save that ends
1117
+ on a merge, a refusal or an error returned before the record was written,
1118
+ so a folder behind its project read every file again on every attempt.
1119
+ */
1120
+ if (link?.repositoryId && [...knownDigests].some(([file, known]) => recordedBefore.get(file)?.sha256 !== known.sha256 || recordedBefore.get(file)?.mtimeMs !== known.mtimeMs)) {
1121
+ await (0, config_js_1.writeDigests)(link.repositoryId, knownDigests, folder);
1122
+ }
1029
1123
  /*
1030
1124
  An upgraded folder with no materialisation record and something that
1031
1125
  differs from its recorded version is ambiguous in the one way that
@@ -1356,6 +1450,17 @@ Pass ${accent("--allow-secrets")} if these are not real keys.`);
1356
1450
  if (createdRepositoryId && !uploadRequest.repositoryId) {
1357
1451
  Object.assign(uploadRequest, { repositoryId: createdRepositoryId });
1358
1452
  }
1453
+ /*
1454
+ The upload uses this command's own walk of the folder rather than
1455
+ walking it again in each of its two passes (UploadRequest.survey), and a
1456
+ save that goes as one request does not wait on a separate price check
1457
+ first (oneRoundTrip). A dry run still asks the service, so what it shows
1458
+ is the service's answer.
1459
+ */
1460
+ if (!importing)
1461
+ uploadRequest.survey = listing.sizes;
1462
+ if (!dryRun)
1463
+ uploadRequest.oneRoundTrip = true;
1359
1464
  const plan = await uploader.plan(uploadRequest, (progress) => {
1360
1465
  line(` ${track(progress.percent)} ${String(progress.percent).padStart(3)}% ` +
1361
1466
  `${"plan".padEnd(7)} ${progress.files}/${progress.totalFiles} ` +
@@ -1364,12 +1469,16 @@ Pass ${accent("--allow-secrets")} if these are not real keys.`);
1364
1469
  done(line);
1365
1470
  if (plan.repositoryCreated)
1366
1471
  createdRepositoryId = plan.repositoryId;
1367
- console.log(`${accent("Upload plan")} ${bytes(plan.sourceBytes)} selected → ` +
1368
- `${bytes(plan.compactedBytes)} compacted; ${bytes(plan.chargeableBytes)} new storage.`);
1369
- console.log(plan.allowance.exempt
1370
- ? dim("No monthly upload steps on this plan; the storage limit is the only one.")
1371
- : dim(`Monthly stage ${plan.allowance.stage}: ${plan.allowance.unlockedPercent}% unlocked, ` +
1372
- `${bytes(plan.allowance.remainingBytes)} remains after this reservation.`));
1472
+ console.log(plan.estimated
1473
+ ? `${accent("Upload plan")} ${bytes(plan.sourceBytes)} selected; ${bytes(plan.chargeableBytes)} of changes to send.`
1474
+ : `${accent("Upload plan")} ${bytes(plan.sourceBytes)} selected → ` +
1475
+ `${bytes(plan.compactedBytes)} compacted; ${bytes(plan.chargeableBytes)} new storage.`);
1476
+ console.log(plan.estimated
1477
+ ? dim("Storage and the monthly allowance are checked as the save arrives.")
1478
+ : plan.allowance.exempt
1479
+ ? dim("No monthly upload steps on this plan; the storage limit is the only one.")
1480
+ : dim(`Monthly stage ${plan.allowance.stage}: ${plan.allowance.unlockedPercent}% unlocked, ` +
1481
+ `${bytes(plan.allowance.remainingBytes)} remains after this reservation.`));
1373
1482
  await sayAhead();
1374
1483
  if (dryRun) {
1375
1484
  await uploader.cancelPlan(plan, true);
@@ -1441,6 +1550,16 @@ The connection failed: ${text}`));
1441
1550
  }
1442
1551
  }
1443
1552
  done(line);
1553
+ /*
1554
+ What this save hashed, kept for the next one, before anything below can
1555
+ return (a save kept on a merge track used to skip it).
1556
+
1557
+ Merged rather than replaced: `digestsTaken` holds only the files actually
1558
+ read this time, and everything served from the existing record has to
1559
+ survive or the next save reads it all again — which is precisely the cost
1560
+ this exists to avoid.
1561
+ */
1562
+ await (0, config_js_1.writeDigests)(result.repositoryId, new Map([...knownDigests, ...uploader.digestsTaken()]), folder);
1444
1563
  if (result.mergeTrack) {
1445
1564
  /*
1446
1565
  The upload is complete and kept, but the project has not changed —
@@ -1506,15 +1625,6 @@ The connection failed: ${text}`));
1506
1625
  */
1507
1626
  ...(link?.track ? { track: link.track } : {}),
1508
1627
  });
1509
- /*
1510
- What this save hashed, kept for the next one.
1511
-
1512
- Merged rather than replaced: `digestsTaken` holds only the files actually
1513
- read this time, and everything served from the existing record has to
1514
- survive or the next save reads it all again — which is precisely the cost
1515
- this exists to avoid.
1516
- */
1517
- await (0, config_js_1.writeDigests)(result.repositoryId, new Map([...knownDigests, ...uploader.digestsTaken()]));
1518
1628
  if (result.repeated) {
1519
1629
  console.log(`Already saved as ${accent(`v${result.sequence}`)} by an earlier attempt;` +
1520
1630
  ` nothing was sent again.`);
@@ -1632,7 +1742,25 @@ async function commandGet(parsed) {
1632
1742
  }
1633
1743
  if (link.local && !replacing) {
1634
1744
  const rules = await (0, worktree_js_1.readRules)(folder);
1635
- const edited = await (0, worktree_js_1.changedFiles)(folder, rules, new Map(Object.entries(link.local)));
1745
+ /*
1746
+ The digests status and submit keep, so a file whose size and time are
1747
+ unchanged is not opened again. Without them every catch-up read and
1748
+ hashed the whole folder first: 14,125 files took 100–140 s on Windows
1749
+ before the first request, for a folder one version behind (2026-11-11).
1750
+ */
1751
+ const knownDigests = link.repositoryId
1752
+ ? await (0, config_js_1.readDigests)(link.repositoryId, folder)
1753
+ : new Map();
1754
+ let learned = 0;
1755
+ const remember = knownDigests.set.bind(knownDigests);
1756
+ knownDigests.set = (key, value) => {
1757
+ learned += 1;
1758
+ return remember(key, value);
1759
+ };
1760
+ const edited = await (0, worktree_js_1.changedFiles)(folder, rules, new Map(Object.entries(link.local)), "add-and-update", knownDigests);
1761
+ if (link.repositoryId && learned) {
1762
+ await (0, config_js_1.writeDigests)(link.repositoryId, knownDigests, folder);
1763
+ }
1636
1764
  if (edited.length) {
1637
1765
  const downloader = new download_js_1.Downloader(config_js_1.credentials);
1638
1766
  const latest = (await downloader.versions(link.repositoryId))[0];
@@ -1902,7 +2030,22 @@ trackName) {
1902
2030
  });
1903
2031
  // The record is written; the run has not reported success yet.
1904
2032
  (0, faults_js_1.maybeFail)("get:after-record");
1905
- console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
2033
+ /*
2034
+ Nothing fetched reads as nothing fetched. It used to print the whole
2035
+ project's size "into" the folder, which looked like a 1.25 GB download
2036
+ when not a byte had moved.
2037
+ */
2038
+ const unchanged = result.unchanged ?? 0;
2039
+ if (unchanged > 0 && unchanged >= result.files) {
2040
+ console.log(`Already up to date · ${accent(`v${latest.sequence}`)} · ${fileCount(result.files)}`);
2041
+ }
2042
+ else if (unchanged > 0) {
2043
+ const fetched = result.files - unchanged;
2044
+ console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(fetched)} updated, ${unchanged.toLocaleString("en-US")} already here · ${destination}`);
2045
+ }
2046
+ else {
2047
+ console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
2048
+ }
1906
2049
  return 0;
1907
2050
  }
1908
2051
  /**
@@ -429,22 +429,36 @@ async function writeLink(localPath, link) {
429
429
  if (legacy !== key)
430
430
  await (0, promises_1.rm)(storedFileFor(legacy), { force: true });
431
431
  }
432
- const digestsFile = (projectId) => node_path_1.default.join(configDirectory(), "digests", `${projectId}.json`);
433
- async function readDigests(projectId) {
432
+ const digestsFile = (projectId, folder) => {
433
+ if (!folder)
434
+ return node_path_1.default.join(configDirectory(), "digests", `${projectId}.json`);
435
+ const where = node_path_1.default.resolve(folder);
436
+ const key = (0, node_crypto_1.createHash)("sha256")
437
+ .update(process.platform === "win32" ? where.toLowerCase() : where)
438
+ .digest("hex")
439
+ .slice(0, 16);
440
+ return node_path_1.default.join(configDirectory(), "digests", `${projectId}-${key}.json`);
441
+ };
442
+ async function readDigestFile(file) {
434
443
  try {
435
- const raw = await (0, promises_1.readFile)(digestsFile(projectId), "utf8");
444
+ const raw = await (0, promises_1.readFile)(file, "utf8");
436
445
  return new Map(Object.entries(JSON.parse(raw)));
437
446
  }
438
447
  catch {
439
- /* No record yet, or one this build cannot read: hash everything. */
440
- return new Map();
448
+ return null;
441
449
  }
442
450
  }
443
- async function writeDigests(projectId, digests) {
451
+ async function readDigests(projectId, folder) {
452
+ /* No record yet, or one this build cannot read: hash everything. */
453
+ return ((folder ? await readDigestFile(digestsFile(projectId, folder)) : null) ??
454
+ (await readDigestFile(digestsFile(projectId))) ??
455
+ new Map());
456
+ }
457
+ async function writeDigests(projectId, digests, folder) {
444
458
  if (!digests.size)
445
459
  return;
446
460
  try {
447
- await writePrivate(digestsFile(projectId), JSON.stringify(Object.fromEntries(digests)));
461
+ await writePrivate(digestsFile(projectId, folder), JSON.stringify(Object.fromEntries(digests)));
448
462
  }
449
463
  catch {
450
464
  /* The next save hashes again, which is where this started. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coderook/cli",
3
- "version": "0.46.4",
3
+ "version": "0.46.6",
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",