@droconnell/agent-inbox-cli 2.11.0 → 2.12.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/README.md +2 -2
- package/agent-inbox.mjs +92 -9
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -10,14 +10,14 @@ Needs Node 18 or later. No other dependencies.
|
|
|
10
10
|
npm i -g @droconnell/agent-inbox-cli
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
That installs the command `agent-inbox
|
|
13
|
+
That installs the command `agent-inbox` (`agent-inbox-cli` works too). On a Mac or Linux, if npm says `EACCES: permission denied`, give npm a folder of your own once, then install again without `sudo`:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global
|
|
17
17
|
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
You can also download the single file from your own Next address and run it with Node: `curl -fsSLO https://your-next-address/cli/agent-inbox.mjs
|
|
20
|
+
You can also download the single file from your own Next address and run it with Node: `curl -fsSLO https://your-next-address/cli/agent-inbox.mjs` (in Windows PowerShell, `curl.exe`), then `node agent-inbox.mjs ...`.
|
|
21
21
|
|
|
22
22
|
## Set everything up at once
|
|
23
23
|
|
package/agent-inbox.mjs
CHANGED
|
@@ -44,7 +44,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
44
44
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
45
45
|
import { createRequire } from "node:module";
|
|
46
46
|
|
|
47
|
-
export const VERSION = "2.
|
|
47
|
+
export const VERSION = "2.12.0";
|
|
48
48
|
/** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
|
|
49
49
|
export const PACKAGE = "@droconnell/agent-inbox-cli";
|
|
50
50
|
const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
|
|
@@ -98,7 +98,7 @@ const urlArg = take("--url", true);
|
|
|
98
98
|
const tokenArg = take("--token", true);
|
|
99
99
|
/** The CLI's own commands. Anything else is a terminal command, sent as typed. */
|
|
100
100
|
export const OWN = new Set(["login", "logout", "update", "export", "pull", "plan", "diff", "push", "propose", "run", "tail", "script", "check", "ci", "test", "rehearse", "commands", "help", "submit", "dev",
|
|
101
|
-
"whoami", "policy", "audit", "mcp", "claude", "init", "connect", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
|
|
101
|
+
"whoami", "policy", "audit", "mcp", "claude", "init", "connect", "app", "events", "listen", "completion", "__complete", "version", "--version", "-v", "--help", "-h"]);
|
|
102
102
|
const first = args[0];
|
|
103
103
|
// plan, diff and run are also terminal commands: the CLI's own only for a folder or file that is there (plan, diff) or
|
|
104
104
|
// a quoted command (run "ls unassigned"); otherwise they go to the terminal as typed (diff 40 42, run onboarding).
|
|
@@ -1040,6 +1040,7 @@ const USAGE = [
|
|
|
1040
1040
|
["completion bash|zsh|fish", "Tab completion of commands and real names for your shell"],
|
|
1041
1041
|
["logout", "forget this computer's sign-in (and revoke a browser sign-in in Next)"],
|
|
1042
1042
|
["update", "how to get the newest version (a downloaded file updates itself)"],
|
|
1043
|
+
["version", "which version you have (also --version)"],
|
|
1043
1044
|
["help <command>", "one terminal command with an example; ME commands lists them all"],
|
|
1044
1045
|
];
|
|
1045
1046
|
/** The usage, naming the command the way it was run, so each line can be copied as it is. */
|
|
@@ -1095,17 +1096,36 @@ async function update() {
|
|
|
1095
1096
|
if (!url) stop(`Sign in first with ${ME} login <your console's address>, so the CLI knows where to get the newest version. ${updateAdvice(how, url)}`);
|
|
1096
1097
|
if (!latest) stop(`Could not ask ${url} for the newest version. Check your connection and try again. ${updateAdvice(how, url)}`);
|
|
1097
1098
|
if (!newer(latest, VERSION)) return;
|
|
1098
|
-
|
|
1099
|
+
const problem = await replaceSelf(url, latest);
|
|
1100
|
+
if (problem) stop(`${problem} ${updateAdvice(how, url)}`);
|
|
1101
|
+
say(`Updated ${relative(process.cwd(), SELF) || SELF} to ${latest}.`);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
/**
|
|
1105
|
+
* Replace this downloaded file with the server's copy of `latest`: written beside it first, checked, then moved over it
|
|
1106
|
+
* in one step. Null when it worked, otherwise what went wrong (nothing was changed).
|
|
1107
|
+
*/
|
|
1108
|
+
async function replaceSelf(url, latest) {
|
|
1099
1109
|
let body;
|
|
1100
1110
|
try {
|
|
1101
1111
|
const r = await fetch(`${url}/cli/agent-inbox.mjs`, { signal: AbortSignal.timeout(30_000) });
|
|
1102
1112
|
body = r.ok ? await r.text() : "";
|
|
1103
1113
|
} catch { body = ""; }
|
|
1104
|
-
if (!body.startsWith("#!/usr/bin/env node") || !body.includes(`const VERSION = "${latest}"`))
|
|
1114
|
+
if (!body.startsWith("#!/usr/bin/env node") || !body.includes(`const VERSION = "${latest}"`)) return `The download from ${url} did not look right, so nothing was changed.`;
|
|
1105
1115
|
const next = `${SELF}.download`;
|
|
1106
|
-
try { writeFileSync(next, body, { mode: 0o755 }); renameSync(next, SELF); }
|
|
1107
|
-
catch { rmSync(next, { force: true });
|
|
1108
|
-
|
|
1116
|
+
try { writeFileSync(next, body, { mode: 0o755 }); renameSync(next, SELF); return null; }
|
|
1117
|
+
catch { rmSync(next, { force: true }); return `Could not replace ${SELF}: it may belong to another user.`; }
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* What updating to `version` runs on this computer, for how this copy was installed: npm or Homebrew (a fixed command
|
|
1122
|
+
* with fixed words, the version checked), or replacing the downloaded file. Shown to the person before they say yes.
|
|
1123
|
+
*/
|
|
1124
|
+
export function updateStep(how, version) {
|
|
1125
|
+
if (!/^\d+\.\d+\.\d+$/.test(String(version))) return null;
|
|
1126
|
+
if (how === "npm") return { shown: `npm i -g ${PACKAGE}@${version}`, command: "npm", args: ["i", "-g", `${PACKAGE}@${version}`] };
|
|
1127
|
+
if (how === "brew") return { shown: "brew upgrade agent-inbox", command: "brew", args: ["upgrade", "agent-inbox"] };
|
|
1128
|
+
return { shown: `download agent-inbox ${version} over ${SELF}`, command: null, args: [] };
|
|
1109
1129
|
}
|
|
1110
1130
|
|
|
1111
1131
|
// ---- For agents: an MCP server on this computer, and Claude Code -----------------------------------------------------
|
|
@@ -1753,7 +1773,7 @@ async function connect(words) {
|
|
|
1753
1773
|
return { status: r.status, data: await r.json().catch(() => ({})) };
|
|
1754
1774
|
};
|
|
1755
1775
|
|
|
1756
|
-
const hello = await line("POST", { action: "connect", name, folder: shown, version: VERSION, always: [] });
|
|
1776
|
+
const hello = await line("POST", { action: "connect", name, folder: shown, version: VERSION, installed: installedBy(real(SELF)), always: [] });
|
|
1757
1777
|
if (!hello) stop(`Could not reach ${url}. Check your connection and try again.`);
|
|
1758
1778
|
if (hello.status !== 200 || !hello.data?.id) stop(hello.data?.error || "Next did not accept this computer. Try again.");
|
|
1759
1779
|
const { id, line: lineId } = hello.data;
|
|
@@ -1875,9 +1895,69 @@ async function connect(words) {
|
|
|
1875
1895
|
: `Checked ${n} ${pagesWord} in ${secs} s: ${missing === 0 ? "every label was found" : `${missing} label${missing === 1 ? "" : "s"} not found`}. Next shows them on Knowledge.`);
|
|
1876
1896
|
};
|
|
1877
1897
|
|
|
1898
|
+
/**
|
|
1899
|
+
* Update this CLI (prd/run-on-my-computer.md, "Updates"): Next sends only the version it offers. This computer shows
|
|
1900
|
+
* exactly what it will run for how it was installed, asks (never Always), runs it, checks the newly installed CLI says
|
|
1901
|
+
* the new version, and then starts connect again with it, in this same window.
|
|
1902
|
+
*/
|
|
1903
|
+
const updateSelf = async (run) => {
|
|
1904
|
+
const how = installedBy(real(SELF));
|
|
1905
|
+
const step = updateStep(how, run.version);
|
|
1906
|
+
const ago = Math.floor((Date.now() - Date.parse(run.askedAt)) / 60_000);
|
|
1907
|
+
const when = ago >= 1 ? ` ${ago} minute${ago === 1 ? "" : "s"} ago` : "";
|
|
1908
|
+
if (!step || !newer(run.version, VERSION)) {
|
|
1909
|
+
say(`\n${clock()} Next asked to update agent-inbox, but this computer already has ${VERSION}. Not updated.`);
|
|
1910
|
+
await report(run, { status: "declined", output: `This computer already has agent-inbox ${VERSION}.\n` });
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
say(`\n${clock()} ${plainText(run.from, 40)} wants to update agent-inbox from ${VERSION} to ${run.version}, asked by ${plainText(run.askedBy, 60)}${when}:\n\n ${step.shown}\n\nThen connect starts again with the new version, here.\n`);
|
|
1914
|
+
let yes = null;
|
|
1915
|
+
while (yes === null) {
|
|
1916
|
+
const a = await question("Update it? [y] yes [n] no › ");
|
|
1917
|
+
if (a === "y" || a === "yes") yes = true;
|
|
1918
|
+
else if (a === "n" || a === "no") yes = false;
|
|
1919
|
+
else say("Type y or n, then Enter.");
|
|
1920
|
+
}
|
|
1921
|
+
if (!yes) { say("Not updated."); await report(run, { status: "declined" }); return; }
|
|
1922
|
+
if (!(await report(run, { status: "running", approved: "once" }))) { say("Not updated: the request ended in Next before you answered (after 10 minutes, or it was disconnected). Ask again from Next."); return; }
|
|
1923
|
+
let out = "";
|
|
1924
|
+
const take = (t) => { process.stdout.write(t); out += t; };
|
|
1925
|
+
let code = 0;
|
|
1926
|
+
if (step.command) {
|
|
1927
|
+
code = await new Promise((done) => {
|
|
1928
|
+
// A fixed command with fixed words. On Windows npm is npm.cmd, which Node only starts through the shell.
|
|
1929
|
+
child = spawn(step.command, step.args, { shell: process.platform === "win32", windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
1930
|
+
child.stdout.on("data", (b) => take(b.toString("utf8"))); child.stderr.on("data", (b) => take(b.toString("utf8")));
|
|
1931
|
+
const limit = setTimeout(() => { take("\nStopped after 10 minutes.\n"); child?.kill(); }, 10 * 60_000);
|
|
1932
|
+
child.on("error", () => { clearTimeout(limit); take(`Could not start ${step.command}: is it installed on this computer?\n`); done(-1); });
|
|
1933
|
+
child.on("close", (c) => { clearTimeout(limit); done(c ?? -1); });
|
|
1934
|
+
});
|
|
1935
|
+
child = null;
|
|
1936
|
+
} else {
|
|
1937
|
+
const problem = await replaceSelf(url, run.version);
|
|
1938
|
+
if (problem) { take(`${problem}\n`); code = 1; }
|
|
1939
|
+
}
|
|
1940
|
+
// The CLI now installed, asked for its version: the update counts only if it says the new one.
|
|
1941
|
+
const got = code === 0 ? spawnSync(process.execPath, [process.argv[1], "--version"], { encoding: "utf8", windowsHide: true, timeout: 30_000 }).stdout?.trim() : "";
|
|
1942
|
+
const ok = code === 0 && got && !newer(run.version, got);
|
|
1943
|
+
if (!ok && code === 0) take(how === "brew" ? `Homebrew has no newer agent-inbox yet (this computer has ${got || VERSION}). Try again later.\n` : `The update ran, but agent-inbox still says ${got || VERSION}.\n`);
|
|
1944
|
+
if (ok) take(`agent-inbox is now ${got}.\n`);
|
|
1945
|
+
await report(run, { status: ok ? "done" : "failed", exitCode: ok ? 0 : code || 1, output: out });
|
|
1946
|
+
if (!ok) { say("Not updated. Next shows what it printed."); return; }
|
|
1947
|
+
say(`${clock()} Updated. Starting connect again with ${got}…`);
|
|
1948
|
+
// The new version takes over this window: this process only waits for it and ends when it does.
|
|
1949
|
+
leaving = true;
|
|
1950
|
+
rl.close();
|
|
1951
|
+
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) { process.removeAllListeners(sig); process.on(sig, () => {}); }
|
|
1952
|
+
const again = spawn(process.execPath, process.argv.slice(1), { stdio: "inherit", shell: false });
|
|
1953
|
+
again.on("exit", (c) => process.exit(c ?? 0));
|
|
1954
|
+
again.on("error", () => { say(`Could not start connect again. Run ${ME} connect.`); process.exit(1); });
|
|
1955
|
+
};
|
|
1956
|
+
|
|
1878
1957
|
/** One request: check it, show it, ask, then run this CLI with its words in this folder, and send back what it printed. */
|
|
1879
1958
|
const handle = async (run) => {
|
|
1880
1959
|
if (run.kind === "steps") return checkSteps(run);
|
|
1960
|
+
if (run.kind === "update") return updateSelf(run);
|
|
1881
1961
|
// Run all 3: two or three commands that may run without asking, shown together and asked about once.
|
|
1882
1962
|
const several = Array.isArray(run.steps);
|
|
1883
1963
|
const steps = several ? runnableSequence(run.steps) : (() => { const argv = runnable(run.sub, run.args); return argv ? [{ sub: run.sub, argv }] : null; })();
|
|
@@ -1947,7 +2027,10 @@ async function connect(words) {
|
|
|
1947
2027
|
};
|
|
1948
2028
|
let lostSince = 0;
|
|
1949
2029
|
for (;;) {
|
|
2030
|
+
// Once leaving (an update started connect again, which now asks for work), this one asks no more.
|
|
2031
|
+
if (leaving) return new Promise(() => {});
|
|
1950
2032
|
const got = await line("GET", null, `?id=${id}&line=${lineId}&wait=25000&always=${encodeURIComponent([...always].join(","))}`);
|
|
2033
|
+
if (leaving) return new Promise(() => {});
|
|
1951
2034
|
if (!got || got.status !== 200) {
|
|
1952
2035
|
if (!lostSince) { lostSince = Date.now(); say(`${clock()} Lost the line to Next. Trying again…`); }
|
|
1953
2036
|
if (Date.now() - lostSince > 10 * 60_000) await leave("Could not reach Next for 10 minutes, so this computer disconnected. Run connect again.");
|
|
@@ -2217,7 +2300,7 @@ switch (cmd) {
|
|
|
2217
2300
|
say(markdown ? `### Proposed\n\n${fence(text)}\n\n${sent.text}` : `${text}\n\n${sent.text}`);
|
|
2218
2301
|
process.exit(2);
|
|
2219
2302
|
}
|
|
2220
|
-
case "--version": case "-v": say(VERSION); break;
|
|
2303
|
+
case "version": case "--version": case "-v": say(VERSION); break;
|
|
2221
2304
|
case "check": {
|
|
2222
2305
|
// A support folder's pull request: what it would change, and a rehearsal of the change.
|
|
2223
2306
|
const opt = (name) => { const i = rest.indexOf(`--${name}`); return i >= 0 ? rest[i + 1] : undefined; };
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@droconnell/agent-inbox-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "The Next CLI, built for agents: JSON on every command, an MCP server for any AI tool, live events, apps and webhooks from the terminal, and a support workspace's setup as files in git.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"agent-inbox": "agent-inbox.mjs"
|
|
7
|
+
"agent-inbox": "agent-inbox.mjs",
|
|
8
|
+
"agent-inbox-cli": "agent-inbox.mjs"
|
|
8
9
|
},
|
|
9
10
|
"files": [
|
|
10
11
|
"agent-inbox.mjs",
|