@coderook/cli 0.46.12 → 0.47.1

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.
Files changed (38) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/dist/cbx/src/core/cbx.js +110 -7
  3. package/dist/cbx/src/core/download.js +194 -27
  4. package/dist/cbx/src/core/tracks.js +4 -0
  5. package/dist/cbx/src/core/upload.js +2 -0
  6. package/dist/cbx/src/core/worktree.js +8 -1
  7. package/dist/cbx/src/local/durable.js +66 -0
  8. package/dist/cbx/src/local/repository.js +116 -11
  9. package/dist/cbx/src/local/store.js +84 -17
  10. package/dist/cbx/src/local/store_v2.js +7 -2
  11. package/dist/cbx/src/shared/native_engine.js +68 -12
  12. package/dist/cbx/src/shared/path_rules.js +231 -0
  13. package/dist/cbx/src/shared/safe_path.js +61 -24
  14. package/dist/cli/src/api.js +25 -2
  15. package/dist/cli/src/bin.js +2 -0
  16. package/dist/cli/src/build_command.js +48 -3
  17. package/dist/cli/src/build_pins.js +162 -0
  18. package/dist/cli/src/cli.js +65 -10
  19. package/dist/cli/src/config.js +47 -7
  20. package/dist/cli/src/import_command.js +24 -1
  21. package/dist/cli/src/mcp.js +12 -1
  22. package/dist/cli/src/mods_command.js +2 -0
  23. package/dist/cli/src/portable_python.js +29 -21
  24. package/dist/cli/src/runner.js +3 -1
  25. package/dist/cli/src/service_commands.js +4 -3
  26. package/dist/cli/src/settings_commands.js +1 -1
  27. package/dist/cli/src/terminal_guard.js +37 -0
  28. package/dist/cli/src/transfer_command.js +12 -2
  29. package/dist/cli/src/verify_command.js +14 -0
  30. package/dist/cli/src/workspace_machine.js +28 -4
  31. package/dist/cli/src/workspace_review.js +2 -0
  32. package/dist/cli.bundle.cjs +28322 -0
  33. package/engine-bin/darwin-arm64/cbx-engine +0 -0
  34. package/engine-bin/darwin-x64/cbx-engine +0 -0
  35. package/engine-bin/linux-arm64/cbx-engine +0 -0
  36. package/engine-bin/linux-x64/cbx-engine +0 -0
  37. package/engine-bin/win32-x64/cbx-engine.exe +0 -0
  38. package/package.json +1 -1
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UV_WHEEL_DIGESTS = exports.UV_VERSION = exports.PYTHON_VERSIONS = exports.PYTHON_RELEASE = void 0;
4
+ exports.pinnedPython = pinnedPython;
5
+ exports.uvRequirements = uvRequirements;
6
+ exports.npmSigned = npmSigned;
7
+ exports.buildEnvironment = buildEnvironment;
8
+ /**
9
+ * What `cbx build` downloads, pinned.
10
+ *
11
+ * The build fetches a CPython for the target, uv to resolve its wheels, and
12
+ * Bun's runtime for another system. Each used to be whatever its source
13
+ * called newest, checked only against a digest the same source published in
14
+ * the same answer, so a source that was wrong, compromised or impersonated
15
+ * could hand over any program and it would be built into somebody's release
16
+ * (audit, 16 November 2026). Now:
17
+ *
18
+ * - CPython is one python-build-standalone release, with each archive's
19
+ * SHA-256 written here.
20
+ * - uv, when pip installs it, is one version, with every wheel's SHA-256
21
+ * written here and pip told to accept nothing else (--require-hashes).
22
+ * - Bun's runtime has to match the Bun that builds, so its version cannot be
23
+ * fixed here; instead npm's own signature over the package's digest is
24
+ * checked against npm's public signing key, written here. A registry answer
25
+ * cannot be forged without npm's private key.
26
+ *
27
+ * Moving a pin is a code change: fetch the new release's published digests,
28
+ * check them, and replace the tables below.
29
+ */
30
+ const node_crypto_1 = require("node:crypto");
31
+ /* ------------------------------------------------------------- CPython */
32
+ /** python-build-standalone release 20261110 (published 11 November 2026). */
33
+ exports.PYTHON_RELEASE = "20261110";
34
+ /** The full CPython version each minor version is pinned to in that release. */
35
+ exports.PYTHON_VERSIONS = {
36
+ "3.11": "3.11.18",
37
+ "3.12": "3.12.16",
38
+ "3.13": "3.13.18",
39
+ "3.14": "3.14.10",
40
+ "3.15": "3.15.2",
41
+ };
42
+ const TRIPLES = ["macos-arm64", "windows-arm64", "linux-arm64", "macos-x64", "windows-x64", "linux-x64"];
43
+ /* SHA-256 of each install_only archive, in TRIPLES order, as the release publishes them. */
44
+ const PYTHON_DIGESTS = {
45
+ "3.11": [
46
+ "73f1ed14486aa278d331e95f7d6d452f5cfb69d90b418e26e62fd4846d53557d",
47
+ "2627dd511436b3f6e6db455907852dd260e62e6007dc43f9edfd967b2bf34a6b",
48
+ "623a370be4489d8c35c7a274be02f3007a030618cda29025780beb416c6c8861",
49
+ "9ff3ea8df9037e692939a3f2348f5fd760239ab8eb9d0d2d11d099457dda63a0",
50
+ "5ca7e23bbcc8933a75f4ae9c3a5e5d1ffae5fd143aec9a9d77cf5124cc6e0eef",
51
+ "ac0b758b6ae4ba1cb87f7091eb6bb17c9a383a9bcdb5c18493cdd4f34e35ae8c",
52
+ ],
53
+ "3.12": [
54
+ "e956e60bc9465d577ef8062059aa05cd3a2665b4b8678a2ed24e432368330b8f",
55
+ "7122bf62a0cf601527ba62e19ca715d64db86b269765da23937e9ac7f968f39c",
56
+ "4792f81750282597fb2a3389fe18b945ed2ba6aad5e45ad406d122c58cb33081",
57
+ "83f2922437e6d546d0fcdb8c11f150a8e52787e8d9ea8651b1974e20908eb1bc",
58
+ "e23fe5b16926de1d81661b1a97352e89fb167549c55a6825796ccd0f32ec7f1b",
59
+ "c2f87d4b4e8db3abddb0f116c6ccfc503d0cbdbb9ee8faacddad1b679ec12e99",
60
+ ],
61
+ "3.13": [
62
+ "1afd3983237c2a10277345f235be730e9cb49a123e0574ed252dbf3a841a24e4",
63
+ "f050f4df570616e75aac723a5d05319c0d69ea65243506071bcff162774050ca",
64
+ "d25a65036d5e149db902fa52ad65878d0c00e9301360ec197832f99063087e9e",
65
+ "a46bcdeecd28ba253522b321dcb3806da1b0ff581479fc1d27e9613e3ac44764",
66
+ "7e93813bd362c6413f30788b248590e2f169df2d17dcac81aafbcc7a6eeb542c",
67
+ "50c774f6674740739f791c05a9177ed03e2fe02abebda9bca3512eb7309b37cc",
68
+ ],
69
+ "3.14": [
70
+ "42031ed5f0d38777335252c8c77d64708c8010dd67c128246bdec25000672666",
71
+ "d1a855c3debb8c66e2ad684373f807d35ce9a2b5abf9241a846a8054d8ff2bdf",
72
+ "e59f83159984a55e719bb3805a0b2b5b281f645769222218084b78b92eedc07f",
73
+ "f6c82fcf867b4aaadd373ac97699ad95fbb9c96f9ecf9b25775943aa5458b87f",
74
+ "b9bee0a6f590914a495a8305701951e543b4475bb620d11661b49052b990456b",
75
+ "3fe0d7c0538eb5d190c34582992d26230532551355cbd789fabc6591621cfc07",
76
+ ],
77
+ "3.15": [
78
+ "6767ca67fdcfa3a966b6fb77fc3d4dd4020063fce27ac1e9425fab653195cbab",
79
+ "9f08b2ff987300f05aec566d1aad718036e5ce4eddbcf300ead1d8cab6242c5e",
80
+ "362378c07e01f1d7b18406760ace75e794c21dfff3693535b1bbffe88eec2e52",
81
+ "b9cff41dd36566bece864959f0104e6ddc233dfd4d92b3a9ccbb12d6eff38a7b",
82
+ "a0e4e14d152efbd2a66e4873efe0b4ab42e1ee759441dbc23af034236d7a09cd",
83
+ "182e7adf7e4f0e32dafac5143f00d466afd20eef45918ea170f78884e503ac18",
84
+ ],
85
+ };
86
+ /**
87
+ * The pinned CPython archive for a minor version ("3.12") and target, or an
88
+ * error naming the versions that are pinned.
89
+ */
90
+ function pinnedPython(minor, target, triple) {
91
+ const version = exports.PYTHON_VERSIONS[minor];
92
+ const digest = PYTHON_DIGESTS[minor]?.[TRIPLES.indexOf(target)];
93
+ if (!version || !digest) {
94
+ throw new Error(`no pinned CPython ${minor}; this cbx builds with ${Object.keys(exports.PYTHON_VERSIONS).join(", ")} ` +
95
+ `(set "python" in the build settings to one of them)`);
96
+ }
97
+ const name = `cpython-${version}+${exports.PYTHON_RELEASE}-${triple}-install_only.tar.gz`;
98
+ return {
99
+ name,
100
+ version,
101
+ sha256: digest,
102
+ url: `https://github.com/astral-sh/python-build-standalone/releases/download/${exports.PYTHON_RELEASE}/${encodeURIComponent(name)}`,
103
+ };
104
+ }
105
+ /* ------------------------------------------------------------------ uv */
106
+ /** uv 0.13.7 (3 November 2026): every wheel PyPI holds for it. */
107
+ exports.UV_VERSION = "0.13.7";
108
+ exports.UV_WHEEL_DIGESTS = [
109
+ "89df450624dec8c48b8b5a7adb654928cc50e95753f869c70cd65ef8333f2197",
110
+ "fd04bf01ba5f2829f4f94ca8f0c24a743f21e73d75045613ed6fc2fd66fc7bda",
111
+ "f91a229093163eefca89ea1b220a221d64c3beade05d03519a6584d1797a5a5f",
112
+ "a90f5d95716ab83091f0f73a8e7ec64e557abf2a28537fcd719b2ac88e6f725a",
113
+ "952dcae9b1a7742f2fab28e82391fbfabe8807e4e9363f674b0f6be1053b8dd4",
114
+ "94f65a8ac5826dff76a93cb3cafbaad15def1788c63da2ce5ce09e0bd1303e7a",
115
+ "57ff66891d9a738ec087c23fdde842ac8e5eb63189ffed6ee95caee1b82ceb54",
116
+ "917733990ebc178318af0321d6873823ed5da707e1c4b1e5060ac2065a81f1f3",
117
+ "1bc8543d930464bbb22ac01bb1a660a448235e558014914de1e1cd5b993361b8",
118
+ "2c9bdc4a872b60a93c5f26c0791089ea11585a4f9d3b3c017d78eb8487505e25",
119
+ "08f16fd463926786b702b497473511deae4b3e17a2fa6d22180950d6059a120d",
120
+ "d30cafb7070901ba35353ec64cf228ae46caf79ac0f6fae329f95468b1482531",
121
+ "158953b8669bee6f4bc2babdd997e34ff9f0d57170093cfe907f64448292b7c3",
122
+ "8fc6019740794df995085f7b278d99dc11ccacffad9c63957278d3a6e272280b",
123
+ "8b8ac028ae4ebb2a3f9d04907c61794f2cf8d7a7002bfbb4019a3dee28351fb2",
124
+ "5f37cc4d4660e4aee8a24d0dc179a0b0ce99506259c6796d37fa69bca9543a03",
125
+ "2835e2ab397d0db86323b9975dce75ecd76aa9cfa0d6a2aea84734aae7f8c9b3",
126
+ "55e741a380a98008fc4985cf069855f36bc50242ef438e21a466786f5bc84da8",
127
+ ];
128
+ /** A pip requirements file that accepts only the pinned uv wheels. */
129
+ function uvRequirements() {
130
+ return `uv==${exports.UV_VERSION} ${exports.UV_WHEEL_DIGESTS.map((digest) => `--hash=sha256:${digest}`).join(" ")}\n`;
131
+ }
132
+ /* ----------------------------------------------------------------- Bun */
133
+ /*
134
+ npm's registry signing key (keyid SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U),
135
+ from https://registry.npmjs.org/-/npm/v1/keys, with no expiry. npm signs
136
+ `<name>@<version>:<integrity>` for every package it serves.
137
+ */
138
+ const NPM_KEY_ID = "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U";
139
+ const NPM_KEY = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEY6Ya7W++7aUPzvMTrezH6Ycx3c+HOKYCcNGybJZSCJq/fd7Qa8uuAKtdIkUQtQiEKERhAmE5lMMJhP8OkDOa2g==";
140
+ /** Whether npm signed this package version's integrity digest. */
141
+ function npmSigned(name, version, integrity, signatures) {
142
+ const key = (0, node_crypto_1.createPublicKey)({ key: Buffer.from(NPM_KEY, "base64"), format: "der", type: "spki" });
143
+ const message = Buffer.from(`${name}@${version}:${integrity}`);
144
+ return (signatures ?? []).some((one) => one.keyid === NPM_KEY_ID &&
145
+ typeof one.sig === "string" &&
146
+ (0, node_crypto_1.verify)("sha256", message, key, Buffer.from(one.sig, "base64")));
147
+ }
148
+ /* --------------------------------------------------------------- children */
149
+ /**
150
+ * The environment a build's own commands run with: this one, without the
151
+ * CodeRook token. A project's build script, its `before` step and every
152
+ * dependency's setup code run here, and none of them needs the account's
153
+ * token; handing it over let any of them act as the person building.
154
+ */
155
+ function buildEnvironment(extra = {}) {
156
+ const env = { ...process.env, ...extra };
157
+ for (const name of Object.keys(env)) {
158
+ if (/^CODEROOK_(TOKEN|API_TOKEN|ACCESS_TOKEN)$/i.test(name))
159
+ delete env[name];
160
+ }
161
+ return env;
162
+ }
@@ -2326,10 +2326,23 @@ async function commandUnbundle(parsed) {
2326
2326
  }
2327
2327
  const destination = node_path_1.default.resolve(parsed.positional[1] ?? suggested);
2328
2328
  const line = progressLine();
2329
- const result = await (0, cbx_js_1.unpackBundle)(node_path_1.default.resolve(source), destination, (progress) => {
2330
- line(` ${track(progress.percent)} ${String(progress.percent).padStart(3)}% ` +
2331
- dim(progress.path.slice(-40)));
2332
- });
2329
+ let result;
2330
+ try {
2331
+ result = await (0, cbx_js_1.unpackBundle)(node_path_1.default.resolve(source), destination, (progress) => {
2332
+ line(` ${track(progress.percent)} ${String(progress.percent).padStart(3)}% ` +
2333
+ dim(progress.path.slice(-40)));
2334
+ },
2335
+ /* The folder is replaced whole, so an existing one is kept unless asked. */
2336
+ { replace: hasFlag(parsed, "f", "force") });
2337
+ }
2338
+ catch (error) {
2339
+ if (!(error instanceof cbx_js_1.DestinationOccupied))
2340
+ throw error;
2341
+ done(line);
2342
+ console.error(red(`${destination} already has files in it, and unbundling replaces the whole folder.`));
2343
+ console.error("Name an empty or new folder: cbx unbundle <file.cbx> <folder>, or add --force to replace it.");
2344
+ return 1;
2345
+ }
2333
2346
  done(line);
2334
2347
  console.log(`${fileCount(result.files)} · ${bytes(result.bytes)} into ${destination}`);
2335
2348
  return 0;
@@ -2357,7 +2370,7 @@ async function commandDoctor() {
2357
2370
  console.log(`cbx ${version_js_1.VERSION} · Node ${node_process_1.default.versions.node} · ${node_process_1.default.platform}`);
2358
2371
  console.log(`Config: ${(0, config_js_1.configDirectory)()}`);
2359
2372
  console.log(service
2360
- ? `Service: ${service.status} · schema ${service.schemaVersion}` +
2373
+ ? `Service: ${service.status}` +
2361
2374
  (service.contentEncodings ? ` · accepts ${service.contentEncodings.join(", ")}` : "")
2362
2375
  : red("Service: unreachable"));
2363
2376
  const token = await (0, config_js_1.loadToken)();
@@ -3235,7 +3248,7 @@ const SPECS = [
3235
3248
  summary: "edit, save and run a private project remotely without a checkout",
3236
3249
  usage: "workspace | workspace <usage|open|list|show|read|files|search|diff|patch|put|starter|review|reviewers|save|run|runs|logs|cancel|deploy|preview|handoff|close|reopen|recipe|assign|assignments|unassign|checkout|say|thread|mute|unmute> <project> [workspace] [job] | workspace put <project> <workspace> <path…> | workspace push [folder] | workspace watch [project] [workspace]",
3237
3250
  brief: "workspace <action> <project>",
3238
- detail: "Works on CodeRook's durable remote draft, never the current local folder. Use --data-file for structured edits or recipe configuration. Mutations need the reviewed --revision and a unique --key; reuse the same key and request when retrying. Recipes reference existing project workflows. Usage reads the shared workspace credits and separate PR allowance without a draft ID. put copies files from this folder into a draft: text as text, images, fonts and other binary files as bytes (up to 1 MiB each), a file that is gone here is removed there, and each file must still be the version the draft holds, so a teammate's edit is never overwritten. starter reads this folder (package.json scripts, Cargo.toml, go.mod, Python) and suggests one check recipe per package so drafts have something to run; --apply adds them, never replacing a recipe that exists. review shows who must OK a draft before it is saved or deployed; --ok or --changes -m gives your verdict on the current revision, and counts only from the reviewer's own sign-in or token, never a name given with --as. reviewers lists the project's rules, and an administrator sets them with --data-file. Saving and deploying are separate operations. close refuses a draft with edits that were never saved unless --unsaved is given (the edits are kept, not thrown away); reopen opens a closed draft again, edits and all. Run on its own at a terminal, it lists your open workspaces with their unread messages: choose one to see its changes and what is being discussed, and reply, save, run checks, hand it over or close it with one key. say and thread post to and read a workspace's discussion as JSON; a machine signed in to your account can name itself with --as (or CBX_NAME) so its messages and unread count are its own. watch prints each new message, each message addressed to you (@your name, or the name given with --as) and each new saved version as it happens, until stopped; --json gives one JSON object per line for a program.",
3251
+ detail: "Works on CodeRook's durable remote draft, never the current local folder. Use --data-file for structured edits or recipe configuration. Mutations need the reviewed --revision and a unique --key; reuse the same key and request when retrying. Recipes reference existing project workflows. Usage reads the shared workspace credits and separate PR allowance without a draft ID. put copies files from this folder into a draft: text as text, images, fonts and other binary files as bytes (up to 1 MiB each), a file that is gone here is removed there, and each file must still be the version the draft holds, so a teammate's edit is never overwritten. starter reads this folder (package.json scripts, Cargo.toml, go.mod, Python) and suggests one check recipe per package so drafts have something to run; --apply adds them, never replacing a recipe that exists. review shows who must OK a draft before it is saved or deployed (the rules hold drafts only, not saves made outside a draft); --ok or --changes -m gives your verdict on the current revision, and counts only from the reviewer's own sign-in or token, never a name given with --as. reviewers lists the project's rules, and an administrator sets them with --data-file. Saving and deploying are separate operations. close refuses a draft with edits that were never saved unless --unsaved is given (the edits are kept, not thrown away); reopen opens a closed draft again, edits and all. Run on its own at a terminal, it lists your open workspaces with their unread messages: choose one to see its changes and what is being discussed, and reply, save, run checks, hand it over or close it with one key. say and thread post to and read a workspace's discussion as JSON; a machine signed in to your account can name itself with --as (or CBX_NAME) so its messages and unread count are its own. watch prints each new message, each message addressed to you (@your name, or the name given with --as) and each new saved version as it happens, until stopped; --json gives one JSON object per line for a program.",
3239
3252
  options: [
3240
3253
  { flags: "--data-file <path>", description: "read an operation's JSON from this local file" },
3241
3254
  { flags: "--name <name>", description: "name a new workspace" },
@@ -3481,7 +3494,7 @@ const SPECS = [
3481
3494
  name: "hand-over",
3482
3495
  group: "Project settings",
3483
3496
  summary: "offer a project to another owner, or answer an offer",
3484
- usage: "hand-over <username|email> [project] [--drop-access] [--yes] | hand-over offers | hand-over accept|decline|cancel <project>",
3497
+ usage: "hand-over <username> [project] [--drop-access] [--yes] | hand-over offers | hand-over accept|decline|cancel <project>",
3485
3498
  brief: "hand-over <user> [project]",
3486
3499
  detail: "Offers the project to another account, as the website's Settings →\n" +
3487
3500
  "Danger zone does. Nothing moves until they accept, and the offer lapses\n" +
@@ -3498,7 +3511,7 @@ const SPECS = [
3498
3511
  ],
3499
3512
  examples: [
3500
3513
  "cbx hand-over sam my-project",
3501
- "cbx hand-over sam@example.com --drop-access",
3514
+ "cbx hand-over @sam --drop-access",
3502
3515
  "cbx hand-over offers",
3503
3516
  "cbx hand-over accept night-owl-diner",
3504
3517
  ],
@@ -4428,8 +4441,8 @@ const SPECS = [
4428
4441
  name: "unbundle",
4429
4442
  group: "Mods and bundles",
4430
4443
  summary: "extract a .cbx",
4431
- usage: "unbundle <file> [dir]",
4432
- detail: "Unpacks a .cbx made by cbx bundle into a new folder, named after the folder it was made from unless you give one.",
4444
+ usage: "unbundle <file> [dir] [--force]",
4445
+ detail: "Unpacks a .cbx made by cbx bundle into a new folder, named after the folder it was made from unless you give one. A folder that already has files in it is left alone unless you add --force, which replaces it.",
4433
4446
  examples: ["cbx unbundle my-game.cbx", "cbx unbundle my-game.cbx restored-game"],
4434
4447
  run: commandUnbundle,
4435
4448
  },
@@ -4702,6 +4715,47 @@ async function main(argv) {
4702
4715
  */
4703
4716
  function leave(code) {
4704
4717
  node_process_1.default.exitCode = code;
4718
+ /*
4719
+ The belt, as git_remote_bin.ts has: only fires if something is still
4720
+ holding the loop open five seconds after the command finished (a socket
4721
+ a fetch left behind, a stray timer), and being unreferenced it cannot be
4722
+ that thing itself. Without it such a command printed its answer and then
4723
+ never returned to the prompt.
4724
+ */
4725
+ setTimeout(() => node_process_1.default.exit(code), 5000).unref();
4726
+ }
4727
+ /*
4728
+ Before a folder's own `.coderook/link.json` is taken up on a machine that
4729
+ never linked it, the person is asked, with the project and its owner named
4730
+ as the service knows them rather than as the file says (config.ts). With
4731
+ nobody at a terminal to ask, it is not taken up, and one line says how to.
4732
+ */
4733
+ async function askAboutFolderLink({ folder, link }) {
4734
+ const project = await (0, api_js_2.projectById)(link.repositoryId).catch(() => null);
4735
+ if (!project) {
4736
+ console.error(dim(`${folder} carries a link to a project (${link.slug}) this account cannot open; it was not used.`));
4737
+ return false;
4738
+ }
4739
+ const name = project.ownerHandle ? `${project.ownerHandle}/${project.slug}` : project.slug;
4740
+ console.log(`This folder says it belongs to ${accent(name)}` +
4741
+ (project.member ? "" : dim(" (a project you are not a member of)")) +
4742
+ `, but this machine has never linked it.`);
4743
+ if (project.slug !== link.slug) {
4744
+ console.log(dim(` The folder's own file calls it "${link.slug}".`));
4745
+ }
4746
+ const reader = (0, promises_1.createInterface)({ input: node_process_1.default.stdin, output: node_process_1.default.stdout });
4747
+ try {
4748
+ const answer = (await reader.question(`Save and fetch this folder as ${name}? [y/N] `)).trim().toLowerCase();
4749
+ return answer === "y" || answer === "yes";
4750
+ }
4751
+ finally {
4752
+ reader.close();
4753
+ }
4754
+ }
4755
+ async function tellAboutFolderLink({ folder, link }) {
4756
+ console.error(dim(`${folder} carries a link to ${link.slug} that this machine never made, so it was not used. `) +
4757
+ dim("Link it with ") + accent(`cbx link ${link.slug}`) + dim(" if that is right."));
4758
+ return false;
4705
4759
  }
4706
4760
  /*
4707
4761
  Run only when started as the program. A test loads this file to read the
@@ -4711,6 +4765,7 @@ function leave(code) {
4711
4765
  /** Run the command line with this process's arguments. bin.ts calls this for everything it does not answer itself. */
4712
4766
  function start() {
4713
4767
  (0, network_js_1.tuneNetwork)();
4768
+ (0, config_js_1.judgeFolderLinks)(node_process_1.default.stdin.isTTY && node_process_1.default.stdout.isTTY ? askAboutFolderLink : tellAboutFolderLink);
4714
4769
  main(node_process_1.default.argv.slice(2))
4715
4770
  .then(leave)
4716
4771
  .catch((error) => {
@@ -12,6 +12,8 @@ exports.loadToken = loadToken;
12
12
  exports.clearToken = clearToken;
13
13
  exports.keyFor = keyFor;
14
14
  exports.linkFileFor = linkFileFor;
15
+ exports.judgeFolderLinks = judgeFolderLinks;
16
+ exports.folderLinkOf = folderLinkOf;
15
17
  exports.readLink = readLink;
16
18
  exports.forgetLink = forgetLink;
17
19
  exports.writeLink = writeLink;
@@ -33,7 +35,19 @@ const node_path_1 = __importDefault(require("node:path"));
33
35
  exports.DEFAULT_API = "https://api.coderook.com";
34
36
  function apiOrigin() {
35
37
  /* CODEROOK_API is what a run is handed (with CODEROOK_TOKEN), so cbx inside a run needs no setup. */
36
- return (process.env.CODEROOK_API_URL || process.env.CODEROOK_API || exports.DEFAULT_API).replace(/\/+$/, "");
38
+ const origin = (process.env.CODEROOK_API_URL || process.env.CODEROOK_API || exports.DEFAULT_API).replace(/\/+$/, "");
39
+ /*
40
+ The sign-in token goes with every request to it, so never over plain
41
+ http to another machine (audit, 16 November 2026). This machine's own
42
+ addresses stay allowed for a local service or test bench.
43
+ */
44
+ if (/^http:\/\//i.test(origin)) {
45
+ const host = origin.replace(/^http:\/\//i, "").split(/[/:]/)[0].toLowerCase();
46
+ if (!["localhost", "127.0.0.1", "[::1]"].includes(host) && !host.endsWith(".localhost")) {
47
+ throw new Error(`CODEROOK_API must use https (${origin}); the sign-in token is sent with every request.`);
48
+ }
49
+ }
50
+ return origin;
37
51
  }
38
52
  /**
39
53
  * The website that goes with the service, for a link somebody can open.
@@ -96,9 +110,14 @@ const legacyLinksFile = () => node_path_1.default.join(configDirectory(), "links
96
110
  * rather than exceptional.
97
111
  */
98
112
  async function writePrivate(target, body) {
99
- await (0, promises_1.mkdir)(node_path_1.default.dirname(target), { recursive: true });
113
+ /*
114
+ Private from the moment it exists: made with the mode rather than tightened
115
+ after, which left it readable by other accounts for a moment, and the
116
+ folder kept to its owner (audit, 16 November 2026).
117
+ */
118
+ await (0, promises_1.mkdir)(node_path_1.default.dirname(target), { recursive: true, mode: 0o700 });
100
119
  const temporary = `${target}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
101
- await (0, promises_1.writeFile)(temporary, body, "utf8");
120
+ await (0, promises_1.writeFile)(temporary, body, { encoding: "utf8", mode: 0o600 });
102
121
  // Windows ignores the mode; on everything else this is what keeps the
103
122
  // token out of other accounts' reach.
104
123
  await (0, promises_1.chmod)(temporary, 0o600).catch(() => undefined);
@@ -363,6 +382,17 @@ async function writeFolderLink(localPath, link) {
363
382
  /* A folder that cannot hold the copy still has the machine's record. */
364
383
  }
365
384
  }
385
+ let folderLinkJudge = null;
386
+ /** Set (or clear, with null) who is asked before a folder's own link is adopted. */
387
+ function judgeFolderLinks(judge) {
388
+ folderLinkJudge = judge;
389
+ }
390
+ /** A folder's own copy of its link, without adopting it. */
391
+ async function folderLinkOf(localPath) {
392
+ return readFolderLink(localPath);
393
+ }
394
+ /* Asked once per folder per run, however many times the link is read. */
395
+ const folderLinkAnswers = new Map();
366
396
  async function readLink(localPath) {
367
397
  let found = await lookUp(localPath);
368
398
  if (!found &&
@@ -376,10 +406,20 @@ async function readLink(localPath) {
376
406
  return null;
377
407
  let link = found;
378
408
  if (!link) {
379
- link = await readFolderLink(localPath);
380
- /* Adopted, so this machine knows the folder from now on. */
381
- if (link)
382
- await writeLink(localPath, link);
409
+ const offered = await readFolderLink(localPath);
410
+ if (offered && folderLinkJudge) {
411
+ const folder = node_path_1.default.resolve(localPath);
412
+ let answer = folderLinkAnswers.get(folder);
413
+ if (!answer) {
414
+ answer = folderLinkJudge({ folder, link: offered }).catch(() => false);
415
+ folderLinkAnswers.set(folder, answer);
416
+ }
417
+ /* Adopted, so this machine knows the folder from now on. */
418
+ if (await answer) {
419
+ await writeLink(localPath, offered);
420
+ link = offered;
421
+ }
422
+ }
383
423
  }
384
424
  if (!link)
385
425
  return null;
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.projectNameFromUrl = projectNameFromUrl;
7
+ exports.gitOperand = gitOperand;
8
+ exports.safeBranchName = safeBranchName;
7
9
  exports.looksLikeRepositoryUrl = looksLikeRepositoryUrl;
8
10
  exports.gitAvailable = gitAvailable;
9
11
  exports.fetchSnapshot = fetchSnapshot;
@@ -37,6 +39,25 @@ function projectNameFromUrl(url) {
37
39
  const name = tail.replace(/\.git$/i, "").trim();
38
40
  return name || "imported-project";
39
41
  }
42
+ /**
43
+ * Values handed to git that git must never read as options.
44
+ *
45
+ * A repository address or branch name arrives from somebody else: typed from
46
+ * a page, or listed by the forge being transferred from. Git reads anything
47
+ * starting with "-" as an option, and `--upload-pack=<command>` as a program
48
+ * to run, so such a value is refused here, and every value is also placed
49
+ * after "--" so git stops reading options before it (audit, 16 November 2026).
50
+ */
51
+ function gitOperand(value, what) {
52
+ if (!value || value.startsWith("-")) {
53
+ throw new Error(`Refusing ${what} "${value}": git would read it as an option.`);
54
+ }
55
+ return value;
56
+ }
57
+ /** Whether a branch name may be handed to git: not empty, and not an option. */
58
+ function safeBranchName(name) {
59
+ return Boolean(name) && !name.startsWith("-");
60
+ }
40
61
  /**
41
62
  * Refuse anything that is not a repository location.
42
63
  *
@@ -111,7 +132,9 @@ async function fetchSnapshot(url, into, log = () => { }) {
111
132
  fetching every branch's tip would cost time to produce content this
112
133
  command then discards.
113
134
  */
114
- await run("git", ["clone", "--depth", "1", "--single-branch", url, folder], { windowsHide: true, maxBuffer: 32 * 1024 * 1024 });
135
+ await run("git",
136
+ /* After "--": an address is never read as an option (gitOperand, above). */
137
+ ["clone", "--depth", "1", "--single-branch", "--", gitOperand(url, "the address"), folder], { windowsHide: true, maxBuffer: 32 * 1024 * 1024 });
115
138
  const gitDirectory = node_path_1.default.join(folder, ".git");
116
139
  if (await exists(gitDirectory)) {
117
140
  await (0, promises_1.rm)(gitDirectory, { recursive: true, force: true });
@@ -384,6 +384,13 @@ async function commandMcp(version) {
384
384
  serverVersion = version;
385
385
  node_process_1.default.stdin.setEncoding("utf8");
386
386
  let buffer = "";
387
+ /*
388
+ Requests still being answered when the assistant closes its end. They
389
+ are finished before this returns: the command line exits a few seconds
390
+ after a command returns (cli.ts leave), and an answer cut off there is
391
+ one the assistant waited for and never got.
392
+ */
393
+ const answering = new Set();
387
394
  await new Promise((done) => {
388
395
  node_process_1.default.stdin.on("data", (piece) => {
389
396
  buffer += piece;
@@ -395,7 +402,9 @@ async function commandMcp(version) {
395
402
  if (!line)
396
403
  continue;
397
404
  try {
398
- void handle(JSON.parse(line));
405
+ const work = handle(JSON.parse(line)).catch(() => undefined);
406
+ answering.add(work);
407
+ void work.finally(() => answering.delete(work));
399
408
  }
400
409
  catch {
401
410
  /* Not JSON. Nothing to answer, and nobody to answer to. */
@@ -405,5 +414,7 @@ async function commandMcp(version) {
405
414
  node_process_1.default.stdin.on("end", () => done());
406
415
  node_process_1.default.stdin.on("close", () => done());
407
416
  });
417
+ while (answering.size)
418
+ await Promise.allSettled([...answering]);
408
419
  return 0;
409
420
  }
@@ -53,6 +53,8 @@ async function call(route, method = "GET", body, raw, auth = true) {
53
53
  method,
54
54
  headers,
55
55
  body: raw ?? (body === undefined ? undefined : JSON.stringify(body)),
56
+ /* Every outward request has a deadline; an upload gets a long one (audit, 16 November 2026). */
57
+ signal: AbortSignal.timeout(raw ? 30 * 60_000 : 60_000),
56
58
  });
57
59
  const text = await response.text();
58
60
  let parsed = {};
@@ -43,6 +43,7 @@ const node_process_1 = __importDefault(require("node:process"));
43
43
  const node_zlib_1 = require("node:zlib");
44
44
  const rules_js_1 = require("../../cbx/src/core/rules.js");
45
45
  const worktree_js_1 = require("../../cbx/src/core/worktree.js");
46
+ const build_pins_js_1 = require("./build_pins.js");
46
47
  /** python-build-standalone's name for each system. */
47
48
  exports.PYTHON_TRIPLE = {
48
49
  "windows-x64": "x86_64-pc-windows-msvc",
@@ -173,7 +174,8 @@ const isProgram = (body) => (body[0] === 0x7f && body.toString("latin1", 1, 4) =
173
174
  function run(program, args, options = {}) {
174
175
  return new Promise((done) => {
175
176
  let out = "";
176
- const child = (0, node_child_process_1.spawn)(program, args, { windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
177
+ /* Without the CodeRook token: dependencies' own setup code runs here (build_pins.ts). */
178
+ const child = (0, node_child_process_1.spawn)(program, args, { windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: (0, build_pins_js_1.buildEnvironment)() });
177
179
  child.stdout.on("data", (chunk) => {
178
180
  out += chunk;
179
181
  if (!options.quiet)
@@ -195,35 +197,41 @@ async function findUv(cache) {
195
197
  const local = node_path_1.default.join(cache, "uv", "bin", node_process_1.default.platform === "win32" ? "uv.exe" : "uv");
196
198
  if ((0, node_fs_1.existsSync)(local))
197
199
  return local;
200
+ /* One uv, and only the wheels whose digests are pinned (build_pins.ts). */
201
+ await (0, promises_1.mkdir)(cache, { recursive: true });
202
+ const requirements = node_path_1.default.join(cache, `uv-${build_pins_js_1.UV_VERSION}-requirements.txt`);
203
+ await (0, promises_1.writeFile)(requirements, (0, build_pins_js_1.uvRequirements)());
198
204
  for (const python of ["python3", "python"]) {
199
- const installed = await run(python, ["-m", "pip", "install", "--quiet", "--disable-pip-version-check", "--target", node_path_1.default.join(cache, "uv"), "uv"], { quiet: true });
205
+ const installed = await run(python, [
206
+ "-m", "pip", "install", "--quiet", "--disable-pip-version-check", "--no-deps", "--only-binary", ":all:",
207
+ "--require-hashes", "--target", node_path_1.default.join(cache, "uv"), "-r", requirements,
208
+ ], { quiet: true });
200
209
  if (installed.code === 0 && (0, node_fs_1.existsSync)(local))
201
210
  return local;
202
211
  }
203
212
  throw new Error("needs uv (https://docs.astral.sh/uv) or Python with pip to fetch it");
204
213
  }
205
- /** The target's CPython, downloaded once, checked against its published digest. */
214
+ /**
215
+ * The target's CPython, downloaded once and checked against the digest
216
+ * pinned in build_pins.ts. A copy already in the cache is checked again
217
+ * before use: the cache is a folder anything on the machine can write to.
218
+ */
206
219
  async function pythonRuntime(cache, version, target, say) {
207
220
  const folder = node_path_1.default.join(cache, "python");
208
221
  await (0, promises_1.mkdir)(folder, { recursive: true });
209
- const wanted = new RegExp(`^cpython-${version.replace(".", "\\.")}\\.\\d+\\+\\d+-${exports.PYTHON_TRIPLE[target]}-install_only\\.tar\\.gz$`);
210
- const cached = (await (0, promises_1.readdir)(folder)).find((name) => wanted.test(name));
211
- if (cached)
212
- return (0, promises_1.readFile)(node_path_1.default.join(folder, cached));
213
- const release = (await (await fetch("https://api.github.com/repos/astral-sh/python-build-standalone/releases/latest", {
214
- headers: { accept: "application/vnd.github+json", "user-agent": "coderook-cli" },
215
- })).json());
216
- const asset = (release.assets ?? []).find((one) => wanted.test(one.name));
217
- if (!asset)
218
- throw new Error(`no CPython ${version} build for ${target} in the latest python-build-standalone release`);
219
- if (!asset.digest?.startsWith("sha256:"))
220
- throw new Error("the release does not publish a digest for it");
221
- say(`Fetching ${asset.name}…`);
222
- const body = Buffer.from(await (await fetch(asset.browser_download_url)).arrayBuffer());
223
- if ((0, node_crypto_1.createHash)("sha256").update(body).digest("hex") !== asset.digest.slice("sha256:".length)) {
224
- throw new Error("the download does not match its published digest");
225
- }
226
- await (0, promises_1.writeFile)(node_path_1.default.join(folder, asset.name), body);
222
+ const pinned = (0, build_pins_js_1.pinnedPython)(version, target, exports.PYTHON_TRIPLE[target]);
223
+ const sha = (bytes) => (0, node_crypto_1.createHash)("sha256").update(bytes).digest("hex");
224
+ const cached = await (0, promises_1.readFile)(node_path_1.default.join(folder, pinned.name)).catch(() => null);
225
+ if (cached && sha(cached) === pinned.sha256)
226
+ return cached;
227
+ say(`Fetching ${pinned.name}…`);
228
+ const reply = await fetch(pinned.url, { signal: AbortSignal.timeout(15 * 60_000) });
229
+ if (!reply.ok)
230
+ throw new Error(`could not fetch ${pinned.name} (${reply.status})`);
231
+ const body = Buffer.from(await reply.arrayBuffer());
232
+ if (sha(body) !== pinned.sha256)
233
+ throw new Error(`${pinned.name} does not match its pinned digest`);
234
+ await (0, promises_1.writeFile)(node_path_1.default.join(folder, pinned.name), body);
227
235
  return body;
228
236
  }
229
237
  /* ------------------------------------------------------------- project */
@@ -43,6 +43,7 @@ const node_path_1 = __importDefault(require("node:path"));
43
43
  const download_js_1 = require("../../cbx/src/core/download.js");
44
44
  const identify_js_1 = require("../../cbx/src/core/identify.js");
45
45
  const config_js_1 = require("./config.js");
46
+ const api_js_1 = require("./api.js");
46
47
  const progress_js_1 = require("./progress.js");
47
48
  /** Replace each secret's value with ***, longest first. */
48
49
  function maskSecrets(text, secrets) {
@@ -73,7 +74,8 @@ async function call(route, options = {}) {
73
74
  signal: AbortSignal.timeout(REQUEST_DEADLINE_MS),
74
75
  });
75
76
  const text = await response.text();
76
- const body = text ? JSON.parse(text) : {};
77
+ /* Status first: a gateway's HTML page is not a reason to lose the status (api.ts replyBody). */
78
+ const body = (0, api_js_1.replyBody)(text, route, response.status, response.ok);
77
79
  if (!response.ok) {
78
80
  const error = new Error(body?.error?.message ?? `${route} failed (${response.status})`);
79
81
  error.code = body?.error?.code;
@@ -319,7 +319,7 @@ async function commandCollaborators(parsed) {
319
319
  if (changing !== undefined || removing !== undefined || cancelling !== undefined) {
320
320
  const wanted = changing ?? removing ?? cancelling;
321
321
  if (typeof wanted !== "string" || !wanted.trim()) {
322
- console.error((0, colour_js_1.red)("Who? Name them by email address or display name."));
322
+ console.error((0, colour_js_1.red)("Who? Name them by @username, display name, or their invite's email address."));
323
323
  return 1;
324
324
  }
325
325
  const who = wanted.trim().toLowerCase();
@@ -334,7 +334,8 @@ async function commandCollaborators(parsed) {
334
334
  console.log((0, colour_js_1.green)(`Withdrew the invite to ${pending.email}. Its link no longer works.`));
335
335
  return 0;
336
336
  }
337
- const person = people.collaborators.find((one) => one.email.toLowerCase() === who ||
337
+ const person = people.collaborators.find((one) => (one.email && one.email.toLowerCase() === who) ||
338
+ (one.username && one.username.toLowerCase() === who.replace(/^@/, "")) ||
338
339
  one.displayName.toLowerCase() === who ||
339
340
  one.userId === wanted.trim());
340
341
  if (!person) {
@@ -392,7 +393,7 @@ async function commandCollaborators(parsed) {
392
393
  console.log((0, colour_js_1.dim)(" Nobody else has access."));
393
394
  }
394
395
  for (const person of people.collaborators) {
395
- console.log(` ${(person.displayName || person.email).padEnd(28)} ${(0, colour_js_1.dim)(person.role)}`);
396
+ console.log(` ${(person.displayName || (person.username ? `@${person.username}` : person.email)).padEnd(28)} ${(0, colour_js_1.dim)(person.role)}`);
396
397
  }
397
398
  if (people.invites.length) {
398
399
  console.log("");
@@ -510,7 +510,7 @@ async function typed(question) {
510
510
  async function commandHandOver(parsed) {
511
511
  const first = parsed.positional[0];
512
512
  if (!first) {
513
- console.error((0, colour_js_1.red)("To whom? cbx hand-over <username or email> [project]") + (0, colour_js_1.dim)(" (or: cbx hand-over offers)"));
513
+ console.error((0, colour_js_1.red)("To whom? cbx hand-over <username> [project]") + (0, colour_js_1.dim)(" (or: cbx hand-over offers)"));
514
514
  return 1;
515
515
  }
516
516
  if (first === "offers") {