@coderook/cli 0.46.5 → 0.46.7
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.
- package/.claude-plugin/plugin.json +19 -19
- package/dist/cbx/src/core/download.js +73 -6
- package/dist/cbx/src/core/upload.js +173 -10
- package/dist/cli/src/cli.js +48 -4
- package/package.json +1 -1
|
@@ -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.
|
|
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.7",
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
})
|
|
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
|
-
|
|
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 });
|
|
@@ -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(
|
|
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
|
-
|
|
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 =
|
|
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,8 @@ class Uploader {
|
|
|
2271
2331
|
})
|
|
2272
2332
|
: null;
|
|
2273
2333
|
quoting?.catch(() => undefined);
|
|
2274
|
-
|
|
2334
|
+
/* A save gathering scattered files has to store a new pack, which a patch cannot. */
|
|
2335
|
+
const oneRequest = this.deltaSaveRefused || this.foldPaths.size
|
|
2275
2336
|
? null
|
|
2276
2337
|
: await this.deltaSavePlan(request, repositoryId, declarations, prior);
|
|
2277
2338
|
if (oneRequest && this.planning && request.oneRoundTrip) {
|
|
@@ -2515,10 +2576,10 @@ class Uploader {
|
|
|
2515
2576
|
: null;
|
|
2516
2577
|
if (cached)
|
|
2517
2578
|
return cached;
|
|
2518
|
-
const
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2579
|
+
const rows = (localPath ? await this.patchedListing(repositoryId, versionId, localPath) : null) ??
|
|
2580
|
+
((await this.call(`/v1/repositories/${repositoryId}/versions/${versionId}/files`, {
|
|
2581
|
+
method: "GET",
|
|
2582
|
+
})).files ?? []);
|
|
2522
2583
|
if (localPath)
|
|
2523
2584
|
await writeListing(localPath, repositoryId, versionId, rows);
|
|
2524
2585
|
return rows;
|
|
@@ -2527,6 +2588,40 @@ class Uploader {
|
|
|
2527
2588
|
reading.catch(() => versionListings.delete(key));
|
|
2528
2589
|
return reading;
|
|
2529
2590
|
}
|
|
2591
|
+
/**
|
|
2592
|
+
* A version's listing made from the newest one this folder already keeps,
|
|
2593
|
+
* plus only what changed since it. Null when there is nothing kept to start
|
|
2594
|
+
* from, or the service answers in full (one that predates `since`), or the
|
|
2595
|
+
* result does not add up — the caller then asks for the whole listing.
|
|
2596
|
+
*
|
|
2597
|
+
* With several people or agents saving, the version a save starts from is
|
|
2598
|
+
* nearly always somebody else's, so the folder's kept listing was never the
|
|
2599
|
+
* one wanted and each save downloaded the whole listing again: 4.66 MB for
|
|
2600
|
+
* 14,125 files, on every save (2026-11-11).
|
|
2601
|
+
*/
|
|
2602
|
+
async patchedListing(repositoryId, versionId, localPath) {
|
|
2603
|
+
try {
|
|
2604
|
+
const base = await newestListing(localPath, repositoryId);
|
|
2605
|
+
if (!base || base.versionId === versionId)
|
|
2606
|
+
return null;
|
|
2607
|
+
const body = await this.call(`/v1/repositories/${repositoryId}/versions/${versionId}/files?since=${encodeURIComponent(base.versionId)}`, { method: "GET" });
|
|
2608
|
+
if (body.since !== base.versionId || !Array.isArray(body.changed) || !Array.isArray(body.removed)) {
|
|
2609
|
+
return body.files ?? null;
|
|
2610
|
+
}
|
|
2611
|
+
const byPath = new Map(base.files.map((row) => [String(row.path), row]));
|
|
2612
|
+
for (const gone of body.removed)
|
|
2613
|
+
byPath.delete(gone);
|
|
2614
|
+
for (const row of body.changed)
|
|
2615
|
+
byPath.set(String(row.path), row);
|
|
2616
|
+
if (byPath.size !== body.fileCount)
|
|
2617
|
+
return null;
|
|
2618
|
+
return [...byPath.values()];
|
|
2619
|
+
}
|
|
2620
|
+
catch {
|
|
2621
|
+
/* Anything unexpected costs one full listing, nothing more. */
|
|
2622
|
+
return null;
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2530
2625
|
/** The account's repository with this slug, if it has one. */
|
|
2531
2626
|
async findBySlug(slug) {
|
|
2532
2627
|
try {
|
|
@@ -3849,6 +3944,26 @@ async function readListing(localPath, repositoryId, versionId) {
|
|
|
3849
3944
|
return null;
|
|
3850
3945
|
}
|
|
3851
3946
|
}
|
|
3947
|
+
/** The most recently written listing this folder keeps for the project, or null. */
|
|
3948
|
+
async function newestListing(localPath, repositoryId) {
|
|
3949
|
+
const folder = node_path_1.default.join(localPath, ".coderook", "versions");
|
|
3950
|
+
try {
|
|
3951
|
+
const entries = await Promise.all((await (0, promises_1.readdir)(folder))
|
|
3952
|
+
.filter((name) => name.endsWith(".json"))
|
|
3953
|
+
.map(async (name) => ({ name, at: (await (0, promises_1.stat)(node_path_1.default.join(folder, name))).mtimeMs })));
|
|
3954
|
+
entries.sort((left, right) => right.at - left.at);
|
|
3955
|
+
for (const entry of entries) {
|
|
3956
|
+
const versionId = entry.name.slice(0, -".json".length);
|
|
3957
|
+
const files = await readListing(localPath, repositoryId, versionId);
|
|
3958
|
+
if (files)
|
|
3959
|
+
return { versionId, files };
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
catch {
|
|
3963
|
+
/* No kept listings yet. */
|
|
3964
|
+
}
|
|
3965
|
+
return null;
|
|
3966
|
+
}
|
|
3852
3967
|
async function writeListing(localPath, repositoryId, versionId, files) {
|
|
3853
3968
|
const folder = node_path_1.default.join(localPath, ".coderook", "versions");
|
|
3854
3969
|
try {
|
|
@@ -3870,6 +3985,54 @@ async function writeListing(localPath, repositoryId, versionId, files) {
|
|
|
3870
3985
|
/* A cache that cannot be written costs one download next time, nothing more. */
|
|
3871
3986
|
}
|
|
3872
3987
|
}
|
|
3988
|
+
/*
|
|
3989
|
+
When a version names this many small stored objects (a loose small file, or a
|
|
3990
|
+
pack holding only a few of the version's files), a save gathers their files
|
|
3991
|
+
into one pack. At most this many bytes are sent again in one save, smallest
|
|
3992
|
+
first.
|
|
3993
|
+
*/
|
|
3994
|
+
const FOLD_AT_OBJECTS = 64;
|
|
3995
|
+
const TINY_PACK_FILES = 8;
|
|
3996
|
+
const SMALL_OBJECT_BYTES = 256 * 1024;
|
|
3997
|
+
const MOST_BYTES_FOLDED = 32 * 1024 * 1024;
|
|
3998
|
+
/** Text, source and markup: what solid packs compress well. */
|
|
3999
|
+
function textLike(mediaType) {
|
|
4000
|
+
return /^text\/|json|javascript|typescript|xml|yaml|toml|csv|svg|x-sh|x-python|sql|markdown/i.test(mediaType);
|
|
4001
|
+
}
|
|
4002
|
+
/** Which stored object a file's bytes live in, for packsToFold; empty for a file in pieces. */
|
|
4003
|
+
function foldKey(held) {
|
|
4004
|
+
return held.pack?.objectId ?? (held.chunks?.length ? "" : held.objectId ?? "");
|
|
4005
|
+
}
|
|
4006
|
+
/** The stored objects whose files this save should send again together; empty almost always. */
|
|
4007
|
+
function packsToFold(prior) {
|
|
4008
|
+
const objects = new Map();
|
|
4009
|
+
/* Only what always packs well: text. Compressed media sent again would just land loose again. */
|
|
4010
|
+
const unpackable = new Set();
|
|
4011
|
+
for (const held of prior.values()) {
|
|
4012
|
+
const id = foldKey(held);
|
|
4013
|
+
if (!id)
|
|
4014
|
+
continue;
|
|
4015
|
+
if (held.mediaType !== undefined && !textLike(held.mediaType))
|
|
4016
|
+
unpackable.add(id);
|
|
4017
|
+
const one = objects.get(id) ?? { files: 0, bytes: 0 };
|
|
4018
|
+
one.files += 1;
|
|
4019
|
+
one.bytes += held.sourceSize;
|
|
4020
|
+
objects.set(id, one);
|
|
4021
|
+
}
|
|
4022
|
+
const small = [...objects].filter(([id, one]) => !unpackable.has(id) && one.files <= TINY_PACK_FILES && one.bytes <= SMALL_OBJECT_BYTES);
|
|
4023
|
+
if (small.length < FOLD_AT_OBJECTS)
|
|
4024
|
+
return new Set();
|
|
4025
|
+
small.sort((left, right) => left[1].bytes - right[1].bytes);
|
|
4026
|
+
const chosen = new Set();
|
|
4027
|
+
let bytes = 0;
|
|
4028
|
+
for (const [id, one] of small) {
|
|
4029
|
+
if (bytes + one.bytes > MOST_BYTES_FOLDED)
|
|
4030
|
+
break;
|
|
4031
|
+
bytes += one.bytes;
|
|
4032
|
+
chosen.add(id);
|
|
4033
|
+
}
|
|
4034
|
+
return chosen;
|
|
4035
|
+
}
|
|
3873
4036
|
/** A file the previous version holds, in the shape a save names it. */
|
|
3874
4037
|
function wireFromPrior(filePath, held) {
|
|
3875
4038
|
return {
|
package/dist/cli/src/cli.js
CHANGED
|
@@ -1742,7 +1742,25 @@ async function commandGet(parsed) {
|
|
|
1742
1742
|
}
|
|
1743
1743
|
if (link.local && !replacing) {
|
|
1744
1744
|
const rules = await (0, worktree_js_1.readRules)(folder);
|
|
1745
|
-
|
|
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
|
+
}
|
|
1746
1764
|
if (edited.length) {
|
|
1747
1765
|
const downloader = new download_js_1.Downloader(config_js_1.credentials);
|
|
1748
1766
|
const latest = (await downloader.versions(link.repositoryId))[0];
|
|
@@ -1900,7 +1918,7 @@ held, mode = "replace",
|
|
|
1900
1918
|
*/
|
|
1901
1919
|
trackName) {
|
|
1902
1920
|
const downloader = new download_js_1.Downloader(config_js_1.credentials);
|
|
1903
|
-
|
|
1921
|
+
let all = await downloader.versions(repositoryId);
|
|
1904
1922
|
/*
|
|
1905
1923
|
The head of this folder's line, not the newest version in the project.
|
|
1906
1924
|
|
|
@@ -1925,7 +1943,18 @@ trackName) {
|
|
|
1925
1943
|
console.error(red(`The line ${trackName} has nothing saved to it yet.`));
|
|
1926
1944
|
return 1;
|
|
1927
1945
|
}
|
|
1928
|
-
|
|
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
|
+
}
|
|
1929
1958
|
if (!head) {
|
|
1930
1959
|
console.error(red(`Could not read the current version of ${trackName}.`));
|
|
1931
1960
|
return 1;
|
|
@@ -2012,7 +2041,22 @@ trackName) {
|
|
|
2012
2041
|
});
|
|
2013
2042
|
// The record is written; the run has not reported success yet.
|
|
2014
2043
|
(0, faults_js_1.maybeFail)("get:after-record");
|
|
2015
|
-
|
|
2044
|
+
/*
|
|
2045
|
+
Nothing fetched reads as nothing fetched. It used to print the whole
|
|
2046
|
+
project's size "into" the folder, which looked like a 1.25 GB download
|
|
2047
|
+
when not a byte had moved.
|
|
2048
|
+
*/
|
|
2049
|
+
const unchanged = result.unchanged ?? 0;
|
|
2050
|
+
if (unchanged > 0 && unchanged >= result.files) {
|
|
2051
|
+
console.log(`Already up to date · ${accent(`v${latest.sequence}`)} · ${fileCount(result.files)}`);
|
|
2052
|
+
}
|
|
2053
|
+
else if (unchanged > 0) {
|
|
2054
|
+
const fetched = result.files - unchanged;
|
|
2055
|
+
console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(fetched)} updated, ${unchanged.toLocaleString("en-US")} already here · ${destination}`);
|
|
2056
|
+
}
|
|
2057
|
+
else {
|
|
2058
|
+
console.log(`${accent(`v${latest.sequence}`)} · ${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
|
|
2059
|
+
}
|
|
2016
2060
|
return 0;
|
|
2017
2061
|
}
|
|
2018
2062
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderook/cli",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.7",
|
|
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",
|