@coderook/cli 0.46.8 → 0.46.10
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 +1 -1
- package/README.md +4 -0
- package/dist/cbx/src/core/download.js +111 -5
- package/dist/cbx/src/core/upload.js +8 -0
- package/dist/cbx/src/shared/merge_diff.js +136 -0
- package/dist/cli/src/api.js +71 -5
- package/dist/cli/src/cli.js +145 -15
- package/dist/cli/src/diff_command.js +32 -34
- package/dist/cli/src/paint.js +3 -1
- package/dist/cli/src/pending_merges.js +62 -0
- package/dist/cli/src/project_commands.js +17 -0
- package/dist/cli/src/remote_restore.js +20 -24
- package/dist/cli/src/workspace_command.js +14 -1
- package/dist/cli/src/workspace_put.js +34 -6
- package/dist/cli/src/workspace_review.js +15 -7
- package/dist/cli/src/workspace_starter.js +61 -7
- package/package.json +2 -2
|
@@ -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.
|
|
5
|
+
"version": "0.46.10",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "ACCA Gaming Productions",
|
|
8
8
|
"url": "https://coderook.com"
|
package/README.md
CHANGED
|
@@ -784,6 +784,10 @@ is reachable, and who this machine is signed in as.
|
|
|
784
784
|
`0` on success, `1` on failure. Every command prints why it failed on standard
|
|
785
785
|
error, so a script can branch on the status and log the reason.
|
|
786
786
|
|
|
787
|
+
`cbx submit` and `cbx workspace save` exit `3` when the save was kept as a
|
|
788
|
+
merge (`M-n`) instead of landing on the line, because somebody changed the same
|
|
789
|
+
lines first. Nothing is lost: settle it with `cbx merge M-n`.
|
|
790
|
+
|
|
787
791
|
## Source and licence
|
|
788
792
|
|
|
789
793
|
The `cbx` command line and the CBX engine it is built on are open source under
|
|
@@ -23,6 +23,7 @@ const node_stream_1 = require("node:stream");
|
|
|
23
23
|
const node_zlib_1 = require("node:zlib");
|
|
24
24
|
const node_path_1 = __importDefault(require("node:path"));
|
|
25
25
|
const safe_path_js_1 = require("../shared/safe_path.js");
|
|
26
|
+
const chunking_js_1 = require("../shared/chunking.js");
|
|
26
27
|
const identify_js_1 = require("./identify.js");
|
|
27
28
|
const faults_js_1 = require("./faults.js");
|
|
28
29
|
const retry_js_1 = require("./retry.js");
|
|
@@ -692,7 +693,59 @@ class Downloader {
|
|
|
692
693
|
can say it happened.
|
|
693
694
|
*/
|
|
694
695
|
recoveredFromGzip = [];
|
|
695
|
-
|
|
696
|
+
/** Pieces of large files taken from the copy already in the folder rather than downloaded. */
|
|
697
|
+
piecesReused = 0;
|
|
698
|
+
/**
|
|
699
|
+
* Where each piece of `pieces` already sits in `localCopy`, by digest.
|
|
700
|
+
*
|
|
701
|
+
* Pieces are cut by content, so the parts of a large file a change did not
|
|
702
|
+
* touch cut into the same pieces again. Cutting the copy already in the
|
|
703
|
+
* folder the way the upload did finds them, and only the rest is fetched:
|
|
704
|
+
* a 1 MB edit inside a 1.2 GB file made every catch-up download all 1.2 GB
|
|
705
|
+
* again (2026-11-11 agent exercise, about 250 s each). Which profile the
|
|
706
|
+
* upload used is not in the listing, so the one whose target size is
|
|
707
|
+
* nearest the pieces' own median is taken; a wrong guess finds nothing and
|
|
708
|
+
* costs one read of the local file.
|
|
709
|
+
*/
|
|
710
|
+
async localPieces(localCopy, pieces) {
|
|
711
|
+
const found = await (0, promises_1.stat)(localCopy).catch(() => null);
|
|
712
|
+
if (!found?.isFile() || pieces.length < 2)
|
|
713
|
+
return null;
|
|
714
|
+
const total = pieces.reduce((sum, piece) => sum + piece.sourceSize, 0);
|
|
715
|
+
const sizes = pieces.map((piece) => piece.sourceSize).sort((left, right) => left - right);
|
|
716
|
+
const median = sizes[sizes.length >> 1] ?? 0;
|
|
717
|
+
const candidates = [(0, chunking_js_1.microchunkProfileForFileSize)(total), (0, chunking_js_1.profileForFileSize)(total)].filter((one) => one !== null);
|
|
718
|
+
if (!candidates.length)
|
|
719
|
+
return null;
|
|
720
|
+
const profile = candidates.reduce((best, one) => Math.abs(one.targetSize - median) < Math.abs(best.targetSize - median) ? one : best);
|
|
721
|
+
const wanted = new Set(pieces.map((piece) => piece.sha256).filter(Boolean));
|
|
722
|
+
const where = new Map();
|
|
723
|
+
const note = (bytes, offset) => {
|
|
724
|
+
const digest = (0, node_crypto_1.createHash)("sha256").update(bytes).digest("hex");
|
|
725
|
+
if (wanted.has(digest) && !where.has(digest))
|
|
726
|
+
where.set(digest, { offset, length: bytes.length });
|
|
727
|
+
};
|
|
728
|
+
let pending = Buffer.alloc(0);
|
|
729
|
+
let pendingAt = 0;
|
|
730
|
+
for await (const block of (0, node_fs_1.createReadStream)(localCopy, { highWaterMark: 8 * 1024 * 1024 })) {
|
|
731
|
+
this.check();
|
|
732
|
+
const incoming = Buffer.from(block);
|
|
733
|
+
pending = pending.length ? Buffer.concat([pending, incoming]) : incoming;
|
|
734
|
+
let from = 0;
|
|
735
|
+
for (const cut of (0, chunking_js_1.cutPoints)(pending, profile)) {
|
|
736
|
+
note(pending.subarray(from, cut), pendingAt + from);
|
|
737
|
+
from = cut;
|
|
738
|
+
}
|
|
739
|
+
pendingAt += from;
|
|
740
|
+
pending = Buffer.from(pending.subarray(from));
|
|
741
|
+
}
|
|
742
|
+
if (pending.length)
|
|
743
|
+
note(pending, pendingAt);
|
|
744
|
+
return where.size ? where : null;
|
|
745
|
+
}
|
|
746
|
+
async fetchInto(repositoryId, versionId, file, target, halt,
|
|
747
|
+
/* The copy of this file already in the folder, whose unchanged pieces need not be fetched. */
|
|
748
|
+
localCopy) {
|
|
696
749
|
/*
|
|
697
750
|
A sealed file is read whole, by path, whatever shape it is stored in.
|
|
698
751
|
|
|
@@ -731,11 +784,40 @@ class Downloader {
|
|
|
731
784
|
a 1.25 GB restore came down at 2.6 MB/s (2026-11-11).
|
|
732
785
|
*/
|
|
733
786
|
const AHEAD = 4;
|
|
787
|
+
const onDisk = localCopy ? await this.localPieces(localCopy, pieces).catch(() => null) : null;
|
|
788
|
+
const reuse = async (piece) => {
|
|
789
|
+
const place = onDisk?.get(piece.sha256);
|
|
790
|
+
if (!place || !localCopy)
|
|
791
|
+
return null;
|
|
792
|
+
const handle = await (0, promises_1.open)(localCopy, "r");
|
|
793
|
+
try {
|
|
794
|
+
const body = Buffer.alloc(place.length);
|
|
795
|
+
const { bytesRead } = await handle.read(body, 0, place.length, place.offset);
|
|
796
|
+
if (bytesRead !== place.length)
|
|
797
|
+
return null;
|
|
798
|
+
/* Checked like a download: a file changed since it was cut is fetched instead. */
|
|
799
|
+
if ((0, node_crypto_1.createHash)("sha256").update(body).digest("hex") !== piece.sha256)
|
|
800
|
+
return null;
|
|
801
|
+
return { body, headers: new Headers() };
|
|
802
|
+
}
|
|
803
|
+
finally {
|
|
804
|
+
await handle.close();
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
const counted = () => {
|
|
808
|
+
this.piecesReused += 1;
|
|
809
|
+
};
|
|
734
810
|
const source = (async function* () {
|
|
735
811
|
const asked = [];
|
|
736
812
|
const ask = (at) => {
|
|
737
813
|
const piece = pieces[at];
|
|
738
|
-
const reply =
|
|
814
|
+
const reply = reuse(piece).then((local) => {
|
|
815
|
+
if (local) {
|
|
816
|
+
counted();
|
|
817
|
+
return local;
|
|
818
|
+
}
|
|
819
|
+
return fetchPiece(`/v1/repositories/${repositoryId}/objects/${piece.objectId}`, `${file.path} (piece ${at + 1} of ${pieces.length})`);
|
|
820
|
+
});
|
|
739
821
|
/* Awaited in turn below; this only stops an early stop leaving it unhandled. */
|
|
740
822
|
reply.catch(() => undefined);
|
|
741
823
|
asked[at] = reply;
|
|
@@ -899,6 +981,7 @@ class Downloader {
|
|
|
899
981
|
time and digest. A file it still matches is known without opening it.
|
|
900
982
|
*/
|
|
901
983
|
known) {
|
|
984
|
+
const reusedBefore = this.piecesReused;
|
|
902
985
|
const files = await this.files(repositoryId, versionId);
|
|
903
986
|
if (!files.length)
|
|
904
987
|
throw new Error("That version has no files");
|
|
@@ -931,12 +1014,24 @@ class Downloader {
|
|
|
931
1014
|
14,125 files each spent twenty minutes re-downloading 306 MB apiece).
|
|
932
1015
|
*/
|
|
933
1016
|
const kept = new Set();
|
|
1017
|
+
/*
|
|
1018
|
+
Files the version left alone that are gone from the folder: deleted
|
|
1019
|
+
here and not saved yet. Catching up put them back, which turned an
|
|
1020
|
+
unsaved rename into a copy (Opus55-1, 2026-11-11). They stay deleted,
|
|
1021
|
+
and the record still names them, so status shows the deletion waiting
|
|
1022
|
+
to be saved.
|
|
1023
|
+
*/
|
|
1024
|
+
const deletedHere = new Set();
|
|
934
1025
|
if (mode === "reconcile" && held) {
|
|
935
1026
|
for (const file of files) {
|
|
936
1027
|
if (!file.sha256 || held[file.path] !== file.sha256)
|
|
937
1028
|
continue;
|
|
938
|
-
if (!(await exists((0, safe_path_js_1.inside)(destination, file.path))))
|
|
1029
|
+
if (!(await exists((0, safe_path_js_1.inside)(destination, file.path)))) {
|
|
1030
|
+
deletedHere.add(file.path);
|
|
1031
|
+
kept.add(file.path);
|
|
1032
|
+
manifest[file.path] = file.sha256;
|
|
939
1033
|
continue;
|
|
1034
|
+
}
|
|
940
1035
|
kept.add(file.path);
|
|
941
1036
|
manifest[file.path] = file.sha256;
|
|
942
1037
|
written += 1;
|
|
@@ -1056,7 +1151,9 @@ class Downloader {
|
|
|
1056
1151
|
const restoreFile = async (file) => {
|
|
1057
1152
|
const full = (0, safe_path_js_1.inside)(staging, file.path);
|
|
1058
1153
|
await (0, promises_1.mkdir)(node_path_1.default.dirname(full), { recursive: true });
|
|
1059
|
-
|
|
1154
|
+
/* A file in pieces can take its unchanged pieces from the copy already here. */
|
|
1155
|
+
const localCopy = file.chunks?.length ? (0, safe_path_js_1.inside)(destination, file.path) : undefined;
|
|
1156
|
+
const digest = await this.fetchInto(repositoryId, versionId, file, full, halt.signal, localCopy);
|
|
1060
1157
|
/*
|
|
1061
1158
|
The whole file's digest, checked after every piece has already been
|
|
1062
1159
|
checked individually. Both are needed: the pieces catch a corrupt or
|
|
@@ -1275,7 +1372,16 @@ class Downloader {
|
|
|
1275
1372
|
percent: 100,
|
|
1276
1373
|
});
|
|
1277
1374
|
/* How many were already here and left alone, so a caller can say nothing was fetched. */
|
|
1278
|
-
return {
|
|
1375
|
+
return {
|
|
1376
|
+
files: written,
|
|
1377
|
+
bytes,
|
|
1378
|
+
manifest,
|
|
1379
|
+
unchanged: kept.size - deletedHere.size,
|
|
1380
|
+
placedFiles: placedRecord,
|
|
1381
|
+
removed: removedHere,
|
|
1382
|
+
leftDeleted: deletedHere.size,
|
|
1383
|
+
piecesReused: this.piecesReused - reusedBefore,
|
|
1384
|
+
};
|
|
1279
1385
|
}
|
|
1280
1386
|
catch (error) {
|
|
1281
1387
|
await (0, promises_1.rm)(staging, { recursive: true, force: true });
|
|
@@ -1219,6 +1219,8 @@ class Uploader {
|
|
|
1219
1219
|
...(request.allowSecrets ? { allowSecrets: true } : {}),
|
|
1220
1220
|
...(linesAdded === undefined ? {} : { linesAdded }),
|
|
1221
1221
|
...(linesRemoved === undefined ? {} : { linesRemoved }),
|
|
1222
|
+
/* A service before saved-from-v1 drops it: this body is not strict. */
|
|
1223
|
+
...(request.savedFrom ? { savedFrom: request.savedFrom } : {}),
|
|
1222
1224
|
/*
|
|
1223
1225
|
Names this attempt so a retry after a lost connection is answered
|
|
1224
1226
|
with the version already made, rather than making a second one.
|
|
@@ -1241,6 +1243,10 @@ class Uploader {
|
|
|
1241
1243
|
paths repeat their folders.
|
|
1242
1244
|
*/
|
|
1243
1245
|
const sendDeltaSave = async (plan) => {
|
|
1246
|
+
/* The header refuses fields it does not know, so this goes only to a service that lists it. */
|
|
1247
|
+
const savedFrom = request.savedFrom && (await this.serviceFeatures()).includes("saved-from-v1")
|
|
1248
|
+
? request.savedFrom
|
|
1249
|
+
: undefined;
|
|
1244
1250
|
const sentHere = new Set(plan.entries.map((entry) => entry.declaration.path));
|
|
1245
1251
|
const removed = [...prior.keys()].filter((held) => !named.has(held));
|
|
1246
1252
|
const executable = contents
|
|
@@ -1262,6 +1268,7 @@ class Uploader {
|
|
|
1262
1268
|
...(removed.length ? { removed } : {}),
|
|
1263
1269
|
...(executable.length ? { executable } : {}),
|
|
1264
1270
|
...(request.presence ? { presence: request.presence } : {}),
|
|
1271
|
+
...(savedFrom ? { savedFrom } : {}),
|
|
1265
1272
|
}));
|
|
1266
1273
|
const rest = new Uint8Array(4 + header.byteLength + plan.envelope.byteLength);
|
|
1267
1274
|
new DataView(rest.buffer).setUint32(0, header.byteLength, false);
|
|
@@ -1433,6 +1440,7 @@ class Uploader {
|
|
|
1433
1440
|
storedBytes: completed.version.storedSize ?? storedBytes,
|
|
1434
1441
|
sentBytes: progress.transferred,
|
|
1435
1442
|
sentFiles: uploaded.length - progress.alreadyOnAccount,
|
|
1443
|
+
repackedFiles: this.foldPaths.size,
|
|
1436
1444
|
reusedFiles: reused.length,
|
|
1437
1445
|
/** Selected, but the service already held the content. */
|
|
1438
1446
|
alreadyStoredFiles: progress.alreadyOnAccount,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.linesOf = linesOf;
|
|
17
17
|
exports.diffLines = diffLines;
|
|
18
|
+
exports.diffLinesWithin = diffLinesWithin;
|
|
18
19
|
exports.foldUnchanged = foldUnchanged;
|
|
19
20
|
exports.conflictDraft = conflictDraft;
|
|
20
21
|
exports.hasConflictMarkers = hasConflictMarkers;
|
|
@@ -57,8 +58,67 @@ function linesOf(text) {
|
|
|
57
58
|
* make.
|
|
58
59
|
*/
|
|
59
60
|
function diffLines(target, candidate) {
|
|
61
|
+
return diffLinesWithin(target, candidate, Number.POSITIVE_INFINITY);
|
|
62
|
+
}
|
|
63
|
+
/*
|
|
64
|
+
Past this many cells the table is not built: the middle is compared by the
|
|
65
|
+
shortest edit instead, whose cost follows the number of changed lines.
|
|
66
|
+
*/
|
|
67
|
+
const MOST_TABLE_CELLS = 4_000_000;
|
|
68
|
+
/**
|
|
69
|
+
* `diffLines`, giving up (null) only when more than `maxEdits` lines differ.
|
|
70
|
+
*
|
|
71
|
+
* Lines both sides share at the start and the end are matched first: a longest
|
|
72
|
+
* common subsequence can always keep them, so the answer is the same and only
|
|
73
|
+
* the changed middle is compared. That middle goes through the exact table when
|
|
74
|
+
* it is small, and otherwise through the shortest edit (Myers), which is exact
|
|
75
|
+
* too and costs memory in the number of changes rather than in lines squared.
|
|
76
|
+
* `cbx diff` refused any file over 4,000 lines before, so a one-line change to
|
|
77
|
+
* the 4,937-line cli.ts could not be reviewed at all (2026-11-11).
|
|
78
|
+
*/
|
|
79
|
+
function diffLinesWithin(target, candidate, maxEdits) {
|
|
60
80
|
const left = linesOf(target);
|
|
61
81
|
const right = linesOf(candidate);
|
|
82
|
+
let head = 0;
|
|
83
|
+
while (head < left.length && head < right.length && left[head] === right[head])
|
|
84
|
+
head += 1;
|
|
85
|
+
let tail = 0;
|
|
86
|
+
while (tail < left.length - head &&
|
|
87
|
+
tail < right.length - head &&
|
|
88
|
+
left[left.length - 1 - tail] === right[right.length - 1 - tail])
|
|
89
|
+
tail += 1;
|
|
90
|
+
const middleLeft = left.slice(head, left.length - tail);
|
|
91
|
+
const middleRight = right.slice(head, right.length - tail);
|
|
92
|
+
const middle = (middleLeft.length + 1) * (middleRight.length + 1) <= MOST_TABLE_CELLS
|
|
93
|
+
? byTable(middleLeft, middleRight)
|
|
94
|
+
: shortestEdit(middleLeft, middleRight, maxEdits);
|
|
95
|
+
if (!middle)
|
|
96
|
+
return null;
|
|
97
|
+
if (middle.filter((line) => line.side !== "same").length > maxEdits)
|
|
98
|
+
return null;
|
|
99
|
+
const out = [];
|
|
100
|
+
for (let at = 0; at < head; at += 1) {
|
|
101
|
+
out.push({ side: "same", targetLine: at + 1, candidateLine: at + 1, text: left[at] });
|
|
102
|
+
}
|
|
103
|
+
for (const line of middle) {
|
|
104
|
+
out.push({
|
|
105
|
+
...line,
|
|
106
|
+
targetLine: line.targetLine === null ? null : line.targetLine + head,
|
|
107
|
+
candidateLine: line.candidateLine === null ? null : line.candidateLine + head,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
for (let at = tail; at > 0; at -= 1) {
|
|
111
|
+
out.push({
|
|
112
|
+
side: "same",
|
|
113
|
+
targetLine: left.length - at + 1,
|
|
114
|
+
candidateLine: right.length - at + 1,
|
|
115
|
+
text: left[left.length - at],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
/** The exact table walk, for a middle small enough to tabulate. */
|
|
121
|
+
function byTable(left, right) {
|
|
62
122
|
const table = commonRuns(left, right);
|
|
63
123
|
const out = [];
|
|
64
124
|
let a = 0;
|
|
@@ -103,6 +163,82 @@ function diffLines(target, candidate) {
|
|
|
103
163
|
}
|
|
104
164
|
return out;
|
|
105
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Myers' shortest edit between two line lists, or null past `maxEdits`.
|
|
168
|
+
*
|
|
169
|
+
* Each round d keeps only the furthest point reached on each diagonal, so the
|
|
170
|
+
* memory kept for walking back is about d squared over two entries rather than
|
|
171
|
+
* one per pair of lines.
|
|
172
|
+
*/
|
|
173
|
+
function shortestEdit(left, right, maxEdits) {
|
|
174
|
+
const n = left.length;
|
|
175
|
+
const m = right.length;
|
|
176
|
+
const limit = Math.min(n + m, Number.isFinite(maxEdits) ? maxEdits : n + m);
|
|
177
|
+
const trace = [];
|
|
178
|
+
const at = (row, d, k) => row[k + d];
|
|
179
|
+
let done = false;
|
|
180
|
+
for (let d = 0; d <= limit && !done; d += 1) {
|
|
181
|
+
const previous = trace[d - 1];
|
|
182
|
+
const row = new Int32Array(2 * d + 1);
|
|
183
|
+
for (let k = -d; k <= d; k += 2) {
|
|
184
|
+
let x;
|
|
185
|
+
if (d === 0)
|
|
186
|
+
x = 0;
|
|
187
|
+
else if (k === -d || (k !== d && at(previous, d - 1, k - 1) < at(previous, d - 1, k + 1))) {
|
|
188
|
+
x = at(previous, d - 1, k + 1);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
x = at(previous, d - 1, k - 1) + 1;
|
|
192
|
+
}
|
|
193
|
+
let y = x - k;
|
|
194
|
+
while (x < n && y < m && left[x] === right[y]) {
|
|
195
|
+
x += 1;
|
|
196
|
+
y += 1;
|
|
197
|
+
}
|
|
198
|
+
row[k + d] = x;
|
|
199
|
+
if (x >= n && y >= m) {
|
|
200
|
+
done = true;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
trace.push(row);
|
|
205
|
+
}
|
|
206
|
+
if (!done)
|
|
207
|
+
return null;
|
|
208
|
+
const out = [];
|
|
209
|
+
let x = n;
|
|
210
|
+
let y = m;
|
|
211
|
+
for (let d = trace.length - 1; d >= 0; d -= 1) {
|
|
212
|
+
const k = x - y;
|
|
213
|
+
if (d === 0) {
|
|
214
|
+
while (x > 0 && y > 0) {
|
|
215
|
+
out.push({ side: "same", targetLine: x, candidateLine: y, text: left[x - 1] });
|
|
216
|
+
x -= 1;
|
|
217
|
+
y -= 1;
|
|
218
|
+
}
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
const previous = trace[d - 1];
|
|
222
|
+
const down = k === -d || (k !== d && at(previous, d - 1, k - 1) < at(previous, d - 1, k + 1));
|
|
223
|
+
const fromK = down ? k + 1 : k - 1;
|
|
224
|
+
const fromX = at(previous, d - 1, fromK);
|
|
225
|
+
const fromY = fromX - fromK;
|
|
226
|
+
const startX = down ? fromX : fromX + 1;
|
|
227
|
+
const startY = down ? fromY + 1 : fromY;
|
|
228
|
+
while (x > startX && y > startY) {
|
|
229
|
+
out.push({ side: "same", targetLine: x, candidateLine: y, text: left[x - 1] });
|
|
230
|
+
x -= 1;
|
|
231
|
+
y -= 1;
|
|
232
|
+
}
|
|
233
|
+
if (down)
|
|
234
|
+
out.push({ side: "candidate", targetLine: null, candidateLine: fromY + 1, text: right[fromY] });
|
|
235
|
+
else
|
|
236
|
+
out.push({ side: "target", targetLine: fromX + 1, candidateLine: null, text: left[fromX] });
|
|
237
|
+
x = fromX;
|
|
238
|
+
y = fromY;
|
|
239
|
+
}
|
|
240
|
+
return out.reverse();
|
|
241
|
+
}
|
|
106
242
|
function foldUnchanged(lines, context = 3) {
|
|
107
243
|
const interesting = new Set();
|
|
108
244
|
lines.forEach((line, index) => {
|
package/dist/cli/src/api.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ServiceError = void 0;
|
|
7
|
+
exports.forgetFoundProjects = forgetFoundProjects;
|
|
4
8
|
exports.putObject = putObject;
|
|
5
9
|
exports.beginUpload = beginUpload;
|
|
6
10
|
exports.uploadPart = uploadPart;
|
|
@@ -74,7 +78,50 @@ exports.collisionCheck = collisionCheck;
|
|
|
74
78
|
/** The small part of the API the command-line tool needs directly. */
|
|
75
79
|
const network_js_1 = require("./network.js");
|
|
76
80
|
const identify_js_1 = require("../../cbx/src/core/identify.js");
|
|
81
|
+
const node_crypto_1 = require("node:crypto");
|
|
82
|
+
const promises_1 = require("node:fs/promises");
|
|
83
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
77
84
|
const config_js_1 = require("./config.js");
|
|
85
|
+
/*
|
|
86
|
+
The account's projects, remembered for a minute for finding one by name.
|
|
87
|
+
|
|
88
|
+
Every command naming a project listed them all first: one round trip, about
|
|
89
|
+
0.6 s from Australia, in every draft put an agent made (2026-11-11 exercise
|
|
90
|
+
2: puts took ~3 s, a fifth of it this). Only findProject reads it; cbx
|
|
91
|
+
projects and the other listings stay live. Keyed to the service and the
|
|
92
|
+
sign-in, so another account or a test bench never sees it, and dropped by
|
|
93
|
+
any request that creates, changes or deletes a project.
|
|
94
|
+
*/
|
|
95
|
+
const REMEMBER_PROJECTS_MS = 60_000;
|
|
96
|
+
const rememberedFile = () => node_path_1.default.join((0, config_js_1.configDirectory)(), "projects-found.json");
|
|
97
|
+
async function rememberedKey() {
|
|
98
|
+
return (0, node_crypto_1.createHash)("sha256").update(`${(0, config_js_1.apiOrigin)()} ${(await (0, config_js_1.loadToken)()) ?? ""}`).digest("hex").slice(0, 32);
|
|
99
|
+
}
|
|
100
|
+
async function rememberedProjects() {
|
|
101
|
+
try {
|
|
102
|
+
const saved = JSON.parse(await (0, promises_1.readFile)(rememberedFile(), "utf8"));
|
|
103
|
+
if (saved.key !== (await rememberedKey()) || !Array.isArray(saved.projects))
|
|
104
|
+
return [];
|
|
105
|
+
if (typeof saved.at !== "number" || saved.at > Date.now() || Date.now() - saved.at > REMEMBER_PROJECTS_MS)
|
|
106
|
+
return [];
|
|
107
|
+
return saved.projects;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function rememberProjects(list) {
|
|
114
|
+
try {
|
|
115
|
+
await (0, promises_1.mkdir)((0, config_js_1.configDirectory)(), { recursive: true });
|
|
116
|
+
await (0, promises_1.writeFile)(rememberedFile(), JSON.stringify({ key: await rememberedKey(), at: Date.now(), projects: list }));
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
/* Only a slower next lookup. */
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function forgetFoundProjects() {
|
|
123
|
+
await (0, promises_1.rm)(rememberedFile(), { force: true }).catch(() => undefined);
|
|
124
|
+
}
|
|
78
125
|
/**
|
|
79
126
|
* How long one request may go unanswered before it is treated as lost.
|
|
80
127
|
*
|
|
@@ -115,6 +162,9 @@ async function call(route, options = {}) {
|
|
|
115
162
|
throw new Error("Not signed in. Run: cbx sign-in");
|
|
116
163
|
}
|
|
117
164
|
const method = options.method ?? "GET";
|
|
165
|
+
/* Creating, changing or deleting a project makes the remembered list wrong (rememberedProjects). */
|
|
166
|
+
if (method !== "GET" && /^\/v1\/repositories(\/[^/?]+)?(\?|$)/.test(route))
|
|
167
|
+
await forgetFoundProjects();
|
|
118
168
|
/*
|
|
119
169
|
A read that failed before any answer is asked again, twice, with a pause.
|
|
120
170
|
Only reads: a write that may have landed is the caller's to retry, with
|
|
@@ -337,15 +387,24 @@ async function findProject(reference) {
|
|
|
337
387
|
missing sign-in is said as itself: swallowing it here turned a timeout
|
|
338
388
|
into "No project matching", which sent somebody looking for a typo.
|
|
339
389
|
*/
|
|
340
|
-
const all = await projects().catch((error) => {
|
|
341
|
-
if (error instanceof ServiceError)
|
|
342
|
-
return [];
|
|
343
|
-
throw error;
|
|
344
|
-
});
|
|
345
390
|
const ownersMatch = (project) => project.slug.toLowerCase() === bare ||
|
|
346
391
|
project.name.toLowerCase() === bare ||
|
|
347
392
|
/* By id too: a run is handed its project's id as CODEROOK_PROJECT. */
|
|
348
393
|
project.id.toLowerCase() === trimmed.toLowerCase();
|
|
394
|
+
/* The list this machine fetched in the last minute answers first; a miss asks again. */
|
|
395
|
+
if (!owner) {
|
|
396
|
+
const remembered = (await rememberedProjects()).find(ownersMatch);
|
|
397
|
+
if (remembered)
|
|
398
|
+
return remembered;
|
|
399
|
+
}
|
|
400
|
+
const all = await projects().then(async (fresh) => {
|
|
401
|
+
await rememberProjects(fresh);
|
|
402
|
+
return fresh;
|
|
403
|
+
}, (error) => {
|
|
404
|
+
if (error instanceof ServiceError)
|
|
405
|
+
return [];
|
|
406
|
+
throw error;
|
|
407
|
+
});
|
|
349
408
|
if (!owner) {
|
|
350
409
|
const mine = all.find(ownersMatch);
|
|
351
410
|
if (mine)
|
|
@@ -617,6 +676,13 @@ async function versions(repositoryId) {
|
|
|
617
676
|
: [],
|
|
618
677
|
removedAt: row.removedAt == null ? null : String(row.removedAt),
|
|
619
678
|
head: row.head === true,
|
|
679
|
+
savedFrom: (() => {
|
|
680
|
+
const from = row.savedFrom;
|
|
681
|
+
if (!from || typeof from !== "object")
|
|
682
|
+
return null;
|
|
683
|
+
const text = (value) => (typeof value === "string" && value ? value : undefined);
|
|
684
|
+
return { client: text(from.client), machine: text(from.machine), as: text(from.as), workspaceId: text(from.workspaceId) };
|
|
685
|
+
})(),
|
|
620
686
|
}));
|
|
621
687
|
}
|
|
622
688
|
/**
|