@coderook/cli 0.44.0 → 0.46.0
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/dist/cbx/src/core/upload.js +40 -0
- package/dist/cbx/src/core/worktree.js +77 -10
- package/dist/cbx/src/local/history.js +6 -3
- package/dist/cbx/src/local/snapshot.js +99 -22
- package/dist/cbx/src/local/store.js +26 -0
- package/dist/cbx/src/shared/native_engine.js +267 -0
- package/dist/cli/src/api.js +2 -0
- package/dist/cli/src/bin.js +86 -0
- package/dist/cli/src/cli.js +40 -2
- package/dist/cli/src/local_commands.js +68 -116
- package/dist/cli/src/local_status.js +72 -0
- package/dist/cli/src/network.js +21 -7
- package/dist/cli/src/project_commands.js +10 -4
- package/dist/cli/src/registry.js +1 -1
- package/dist/cli/src/reminder_gate.js +37 -0
- package/dist/cli/src/update_command.js +160 -0
- package/dist/cli/src/workspace_threads.js +3 -13
- package/engine-bin/darwin-arm64/cbx-engine +0 -0
- package/engine-bin/darwin-x64/cbx-engine +0 -0
- package/engine-bin/linux-arm64/cbx-engine +0 -0
- package/engine-bin/linux-x64/cbx-engine +0 -0
- package/engine-bin/win32-x64/cbx-engine.exe +0 -0
- package/package.json +5 -4
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compareVersions = compareVersions;
|
|
7
|
+
exports.installKind = installKind;
|
|
8
|
+
exports.projectFolder = projectFolder;
|
|
9
|
+
exports.commandUpdate = commandUpdate;
|
|
10
|
+
/**
|
|
11
|
+
* `cbx update` — bring this copy of cbx itself up to the newest release.
|
|
12
|
+
*
|
|
13
|
+
* Not the folder: `cbx get` (and `cbx pull`) bring a project's files up to
|
|
14
|
+
* date. This asks the npm registry for the newest @coderook/cli and installs it
|
|
15
|
+
* the way this copy was installed, because the right command differs:
|
|
16
|
+
*
|
|
17
|
+
* global npm install npm install -g @coderook/cli@<newest>, run here
|
|
18
|
+
* npx nothing to install; npx fetches what it is told to
|
|
19
|
+
* a project's packages npm install @coderook/cli@<newest> in that project
|
|
20
|
+
* anything else the command to run, printed rather than guessed at
|
|
21
|
+
*
|
|
22
|
+
* Every outward call has a deadline, so a registry or npm that never answers
|
|
23
|
+
* ends in a message instead of a hang.
|
|
24
|
+
*/
|
|
25
|
+
const node_child_process_1 = require("node:child_process");
|
|
26
|
+
const node_fs_1 = require("node:fs");
|
|
27
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
28
|
+
const node_process_1 = __importDefault(require("node:process"));
|
|
29
|
+
const version_js_1 = require("./version.js");
|
|
30
|
+
const PACKAGE = "@coderook/cli";
|
|
31
|
+
/** A release number and nothing else: it is put on an npm command line. */
|
|
32
|
+
const RELEASE = /^\d{1,6}\.\d{1,6}\.\d{1,6}(?:-[0-9A-Za-z.]{1,40})?$/;
|
|
33
|
+
const REGISTRY = "https://registry.npmjs.org/" + PACKAGE.replace("/", "%2F") + "/latest";
|
|
34
|
+
const colour = node_process_1.default.stdout.isTTY && !node_process_1.default.env.NO_COLOR;
|
|
35
|
+
const paint = (code) => (text) => (colour ? `\x1b[${code}m${text}\x1b[0m` : text);
|
|
36
|
+
const dim = paint(2), accent = paint(33), red = paint(31), green = paint(32);
|
|
37
|
+
/** Compares two release numbers (1.2.3, pre-release tags rank below the release). Negative when a is older. */
|
|
38
|
+
function compareVersions(a, b) {
|
|
39
|
+
const parse = (v) => {
|
|
40
|
+
const [core = "", pre = ""] = v.trim().replace(/^v/, "").split("-", 2);
|
|
41
|
+
return { parts: core.split(".").map((n) => Number.parseInt(n, 10) || 0), pre };
|
|
42
|
+
};
|
|
43
|
+
const x = parse(a), y = parse(b);
|
|
44
|
+
for (let i = 0; i < 3; i += 1) {
|
|
45
|
+
const d = (x.parts[i] ?? 0) - (y.parts[i] ?? 0);
|
|
46
|
+
if (d)
|
|
47
|
+
return d;
|
|
48
|
+
}
|
|
49
|
+
if (x.pre === y.pre)
|
|
50
|
+
return 0;
|
|
51
|
+
if (!x.pre)
|
|
52
|
+
return 1;
|
|
53
|
+
if (!y.pre)
|
|
54
|
+
return -1;
|
|
55
|
+
return x.pre < y.pre ? -1 : 1;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* How the running copy was installed, from where its files are.
|
|
59
|
+
* `globalRoot` is `npm root -g` (null when npm could not say).
|
|
60
|
+
*/
|
|
61
|
+
function installKind(script, globalRoot, platform = node_process_1.default.platform) {
|
|
62
|
+
const norm = (p) => {
|
|
63
|
+
const s = p.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
64
|
+
return platform === "win32" ? s.toLowerCase() : s;
|
|
65
|
+
};
|
|
66
|
+
const here = norm(script);
|
|
67
|
+
if (!here.includes("/node_modules/@coderook/cli/"))
|
|
68
|
+
return "other";
|
|
69
|
+
if (/\/_npx\//.test(here))
|
|
70
|
+
return "npx";
|
|
71
|
+
if (globalRoot && here.startsWith(norm(globalRoot) + "/"))
|
|
72
|
+
return "global";
|
|
73
|
+
return "project";
|
|
74
|
+
}
|
|
75
|
+
/** The folder holding the node_modules this copy sits in (for a project install). */
|
|
76
|
+
function projectFolder(script) {
|
|
77
|
+
const s = script.replace(/\\/g, "/");
|
|
78
|
+
const at = s.lastIndexOf("/node_modules/@coderook/cli/");
|
|
79
|
+
return at < 0 ? node_path_1.default.dirname(script) : s.slice(0, at);
|
|
80
|
+
}
|
|
81
|
+
async function newestRelease() {
|
|
82
|
+
const response = await fetch(REGISTRY, { signal: AbortSignal.timeout(10_000), headers: { accept: "application/json" } });
|
|
83
|
+
if (!response.ok)
|
|
84
|
+
throw new Error(`the npm registry answered ${response.status}`);
|
|
85
|
+
const body = (await response.json());
|
|
86
|
+
if (typeof body.version !== "string" || !RELEASE.test(body.version))
|
|
87
|
+
throw new Error("the npm registry gave no usable version");
|
|
88
|
+
return body.version;
|
|
89
|
+
}
|
|
90
|
+
/** Runs npm with a deadline; output goes to this terminal when `show` is set. */
|
|
91
|
+
function npm(args, options) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
/*
|
|
94
|
+
npm is npm.cmd on Windows, which Node only starts through a shell, and a
|
|
95
|
+
shell takes one command line rather than an argument list. Every word
|
|
96
|
+
here is ours or a release number checked by RELEASE, so joining is safe.
|
|
97
|
+
*/
|
|
98
|
+
const stdio = options.show ? ["inherit", "inherit", "inherit"] : ["ignore", "pipe", "ignore"];
|
|
99
|
+
const child = node_process_1.default.platform === "win32"
|
|
100
|
+
? (0, node_child_process_1.spawn)(["npm", ...args].join(" "), { cwd: options.cwd, shell: true, stdio })
|
|
101
|
+
: (0, node_child_process_1.spawn)("npm", args, { cwd: options.cwd, stdio });
|
|
102
|
+
let out = "";
|
|
103
|
+
child.stdout?.on("data", (chunk) => { out += chunk.toString(); });
|
|
104
|
+
const timer = setTimeout(() => { child.kill(); resolve({ code: -1, out }); }, options.deadlineMs);
|
|
105
|
+
child.on("error", () => { clearTimeout(timer); resolve({ code: -2, out }); });
|
|
106
|
+
child.on("close", (code) => { clearTimeout(timer); resolve({ code: code ?? 1, out }); });
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async function commandUpdate(flags) {
|
|
110
|
+
const checkOnly = flags.has("check");
|
|
111
|
+
let newest;
|
|
112
|
+
try {
|
|
113
|
+
newest = await newestRelease();
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error(red("Could not find out the newest cbx: " + (error instanceof Error ? error.message : String(error)) + "."));
|
|
117
|
+
console.error(dim("Check the connection and try again. Nothing was changed."));
|
|
118
|
+
return 1;
|
|
119
|
+
}
|
|
120
|
+
const order = compareVersions(version_js_1.VERSION, newest);
|
|
121
|
+
if (order >= 0) {
|
|
122
|
+
console.log(green(`cbx ${version_js_1.VERSION} is the newest.`) + (order > 0 ? dim(` (the registry's newest is ${newest})`) : ""));
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
console.log(`cbx ${version_js_1.VERSION} is installed; ${accent(newest)} is out.`);
|
|
126
|
+
let script = node_process_1.default.argv[1] ?? "";
|
|
127
|
+
try {
|
|
128
|
+
script = (0, node_fs_1.realpathSync)(script);
|
|
129
|
+
}
|
|
130
|
+
catch { /* keep what we were given */ }
|
|
131
|
+
const root = await npm(["root", "-g"], { show: false, deadlineMs: 20_000 });
|
|
132
|
+
const kind = installKind(script, root.code === 0 ? root.out.trim() : null);
|
|
133
|
+
const target = `${PACKAGE}@${newest}`;
|
|
134
|
+
if (kind === "npx") {
|
|
135
|
+
/* The package has three commands (cbx, coderook, git-remote-coderook), so npx must be told which: -p names the package. */
|
|
136
|
+
console.log(`This copy runs through npx. Ask for the newest each time with ${accent(`npx -p ${PACKAGE}@latest cbx`)}.`);
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
if (kind === "other") {
|
|
140
|
+
console.log(`This copy was not installed by npm, so install the newest with ${accent(`npm install -g ${target}`)}.`);
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
const folder = kind === "project" ? projectFolder(script) : undefined;
|
|
144
|
+
const args = kind === "global" ? ["install", "-g", target] : ["install", target];
|
|
145
|
+
if (checkOnly) {
|
|
146
|
+
console.log(`Update with ${accent("cbx update")}, or ${accent("npm " + args.join(" "))}${folder ? dim(` in ${folder}`) : ""}.`);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
console.log(dim(`Running npm ${args.join(" ")}${folder ? ` in ${folder}` : ""}…`));
|
|
150
|
+
const result = await npm(args, { show: true, cwd: folder, deadlineMs: 5 * 60_000 });
|
|
151
|
+
if (result.code !== 0) {
|
|
152
|
+
console.error(red(result.code === -1 ? "npm did not finish within five minutes." : result.code === -2 ? "npm could not be started." : `npm stopped with code ${result.code}.`));
|
|
153
|
+
if (kind === "global")
|
|
154
|
+
console.error(dim("If it was refused for permissions, run the same command from a terminal that can install global packages."));
|
|
155
|
+
console.error(dim(`Your current cbx ${version_js_1.VERSION} is untouched.`));
|
|
156
|
+
return 1;
|
|
157
|
+
}
|
|
158
|
+
console.log(green(`cbx is now ${newest}.`) + dim(" Your folders, sign-in and settings are as they were."));
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
@@ -31,6 +31,7 @@ const node_readline_1 = __importDefault(require("node:readline"));
|
|
|
31
31
|
const api_js_1 = require("./api.js");
|
|
32
32
|
const colour_js_1 = require("./colour.js");
|
|
33
33
|
const config_js_1 = require("./config.js");
|
|
34
|
+
const reminder_gate_js_1 = require("./reminder_gate.js");
|
|
34
35
|
const workspace_watch_js_1 = require("./workspace_watch.js");
|
|
35
36
|
exports.THREAD_OPERATIONS = new Set(["say", "thread", "mute", "unmute"]);
|
|
36
37
|
/** The name this machine posts and reads as, if it gave one. */
|
|
@@ -70,7 +71,6 @@ async function commandWorkspaceThread(operation, root, workspaceId, parsed) {
|
|
|
70
71
|
return 0;
|
|
71
72
|
}
|
|
72
73
|
/* ----------------------------------------------------------- the reminder */
|
|
73
|
-
const REMIND_EVERY_MS = 5 * 60_000;
|
|
74
74
|
/**
|
|
75
75
|
* One line after a command when a workspace thread has unread messages. Only
|
|
76
76
|
* at a terminal, at most every five minutes, never slower than 1.5 s, and
|
|
@@ -78,19 +78,9 @@ const REMIND_EVERY_MS = 5 * 60_000;
|
|
|
78
78
|
* a script.
|
|
79
79
|
*/
|
|
80
80
|
async function unreadReminder(command, parsed) {
|
|
81
|
-
if (!
|
|
81
|
+
if (!(await (0, reminder_gate_js_1.reminderDue)(command)))
|
|
82
82
|
return;
|
|
83
|
-
|
|
84
|
-
return;
|
|
85
|
-
const stamp = node_path_1.default.join((0, config_js_1.configDirectory)(), "discussions-checked");
|
|
86
|
-
try {
|
|
87
|
-
const last = Number((await (0, promises_1.readFile)(stamp, "utf8")).trim());
|
|
88
|
-
if (Date.now() - last < REMIND_EVERY_MS)
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
catch {
|
|
92
|
-
/* Never checked on this machine. */
|
|
93
|
-
}
|
|
83
|
+
const stamp = (0, reminder_gate_js_1.reminderStamp)();
|
|
94
84
|
try {
|
|
95
85
|
await (0, promises_1.mkdir)(node_path_1.default.dirname(stamp), { recursive: true });
|
|
96
86
|
await (0, promises_1.writeFile)(stamp, String(Date.now()));
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderook/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
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",
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
"node": ">=22.15.0"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
|
-
"cbx": "dist/cli/src/
|
|
27
|
-
"coderook": "dist/cli/src/
|
|
26
|
+
"cbx": "dist/cli/src/bin.js",
|
|
27
|
+
"coderook": "dist/cli/src/bin.js",
|
|
28
28
|
"git-remote-coderook": "dist/cli/src/git_remote_bin.js"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
".claude-plugin",
|
|
31
|
+
".claude-plugin",
|
|
32
|
+
"engine-bin",
|
|
32
33
|
"dist",
|
|
33
34
|
"skills",
|
|
34
35
|
"NOTICE"
|