@droconnell/agent-inbox-cli 2.11.1 → 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/agent-inbox.mjs +89 -7
- package/package.json +1 -1
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");
|
|
@@ -1096,17 +1096,36 @@ async function update() {
|
|
|
1096
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)}`);
|
|
1097
1097
|
if (!latest) stop(`Could not ask ${url} for the newest version. Check your connection and try again. ${updateAdvice(how, url)}`);
|
|
1098
1098
|
if (!newer(latest, VERSION)) return;
|
|
1099
|
-
|
|
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) {
|
|
1100
1109
|
let body;
|
|
1101
1110
|
try {
|
|
1102
1111
|
const r = await fetch(`${url}/cli/agent-inbox.mjs`, { signal: AbortSignal.timeout(30_000) });
|
|
1103
1112
|
body = r.ok ? await r.text() : "";
|
|
1104
1113
|
} catch { body = ""; }
|
|
1105
|
-
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.`;
|
|
1106
1115
|
const next = `${SELF}.download`;
|
|
1107
|
-
try { writeFileSync(next, body, { mode: 0o755 }); renameSync(next, SELF); }
|
|
1108
|
-
catch { rmSync(next, { force: true });
|
|
1109
|
-
|
|
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: [] };
|
|
1110
1129
|
}
|
|
1111
1130
|
|
|
1112
1131
|
// ---- For agents: an MCP server on this computer, and Claude Code -----------------------------------------------------
|
|
@@ -1754,7 +1773,7 @@ async function connect(words) {
|
|
|
1754
1773
|
return { status: r.status, data: await r.json().catch(() => ({})) };
|
|
1755
1774
|
};
|
|
1756
1775
|
|
|
1757
|
-
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: [] });
|
|
1758
1777
|
if (!hello) stop(`Could not reach ${url}. Check your connection and try again.`);
|
|
1759
1778
|
if (hello.status !== 200 || !hello.data?.id) stop(hello.data?.error || "Next did not accept this computer. Try again.");
|
|
1760
1779
|
const { id, line: lineId } = hello.data;
|
|
@@ -1876,9 +1895,69 @@ async function connect(words) {
|
|
|
1876
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.`);
|
|
1877
1896
|
};
|
|
1878
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
|
+
|
|
1879
1957
|
/** One request: check it, show it, ask, then run this CLI with its words in this folder, and send back what it printed. */
|
|
1880
1958
|
const handle = async (run) => {
|
|
1881
1959
|
if (run.kind === "steps") return checkSteps(run);
|
|
1960
|
+
if (run.kind === "update") return updateSelf(run);
|
|
1882
1961
|
// Run all 3: two or three commands that may run without asking, shown together and asked about once.
|
|
1883
1962
|
const several = Array.isArray(run.steps);
|
|
1884
1963
|
const steps = several ? runnableSequence(run.steps) : (() => { const argv = runnable(run.sub, run.args); return argv ? [{ sub: run.sub, argv }] : null; })();
|
|
@@ -1948,7 +2027,10 @@ async function connect(words) {
|
|
|
1948
2027
|
};
|
|
1949
2028
|
let lostSince = 0;
|
|
1950
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(() => {});
|
|
1951
2032
|
const got = await line("GET", null, `?id=${id}&line=${lineId}&wait=25000&always=${encodeURIComponent([...always].join(","))}`);
|
|
2033
|
+
if (leaving) return new Promise(() => {});
|
|
1952
2034
|
if (!got || got.status !== 200) {
|
|
1953
2035
|
if (!lostSince) { lostSince = Date.now(); say(`${clock()} Lost the line to Next. Trying again…`); }
|
|
1954
2036
|
if (Date.now() - lostSince > 10 * 60_000) await leave("Could not reach Next for 10 minutes, so this computer disconnected. Run connect again.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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": {
|