@droconnell/agent-inbox-cli 2.9.0 → 2.10.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 +54 -22
- package/package.json +1 -1
package/agent-inbox.mjs
CHANGED
|
@@ -42,7 +42,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
|
|
|
42
42
|
import { spawn, spawnSync } from "node:child_process";
|
|
43
43
|
import { fileURLToPath } from "node:url";
|
|
44
44
|
|
|
45
|
-
export const VERSION = "2.
|
|
45
|
+
export const VERSION = "2.10.0";
|
|
46
46
|
/** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
|
|
47
47
|
export const PACKAGE = "@droconnell/agent-inbox-cli";
|
|
48
48
|
const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
|
|
@@ -1519,6 +1519,24 @@ export function runnable(sub, args) {
|
|
|
1519
1519
|
return [...sub.split(" "), ...(path === null ? [] : [path]), ...flags];
|
|
1520
1520
|
}
|
|
1521
1521
|
|
|
1522
|
+
/**
|
|
1523
|
+
* A sequence from Next (Run all 3): two or three commands, each checked by runnable and each one that may run without
|
|
1524
|
+
* asking (only those go together; anything that changes Next or costs money is asked about on its own). The CLI's own
|
|
1525
|
+
* words for each, in order, or null for anything else, which is refused without asking. The same rule as
|
|
1526
|
+
* validSequence in src/lib/computer-commands.ts (src/lib/computer-commands.test.ts checks they agree).
|
|
1527
|
+
*/
|
|
1528
|
+
export const MAX_SEQUENCE = 3;
|
|
1529
|
+
export function runnableSequence(steps) {
|
|
1530
|
+
if (!Array.isArray(steps) || steps.length < 2 || steps.length > MAX_SEQUENCE) return null;
|
|
1531
|
+
const out = [];
|
|
1532
|
+
for (const s of steps) {
|
|
1533
|
+
const argv = s && typeof s === "object" ? runnable(s.sub, s.args) : null;
|
|
1534
|
+
if (!argv || !RUNNABLE[s.sub].always) return null;
|
|
1535
|
+
out.push({ sub: s.sub, argv });
|
|
1536
|
+
}
|
|
1537
|
+
return out;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1522
1540
|
/** Text from Next shown in this terminal: no control characters, so nothing sent can move the cursor or recolour the screen. */
|
|
1523
1541
|
export const plainText = (s, max = 120) => String(s ?? "").replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028-\u202e]/g, "").slice(0, max);
|
|
1524
1542
|
|
|
@@ -1616,27 +1634,31 @@ async function connect(words) {
|
|
|
1616
1634
|
return false;
|
|
1617
1635
|
};
|
|
1618
1636
|
|
|
1637
|
+
/** The folder or file a command's words name (it comes right after the command's own words, before any option), or "." */
|
|
1638
|
+
const namedPath = (sub, argv) => { const named = argv[sub.split(" ").length]; return named && !named.startsWith("-") ? named : "."; };
|
|
1639
|
+
|
|
1619
1640
|
/** One request: check it, show it, ask, then run this CLI with its words in this folder, and send back what it printed. */
|
|
1620
1641
|
const handle = async (run) => {
|
|
1621
|
-
|
|
1622
|
-
const
|
|
1642
|
+
// Run all 3: two or three commands that may run without asking, shown together and asked about once.
|
|
1643
|
+
const several = Array.isArray(run.steps);
|
|
1644
|
+
const steps = several ? runnableSequence(run.steps) : (() => { const argv = runnable(run.sub, run.args); return argv ? [{ sub: run.sub, argv }] : null; })();
|
|
1645
|
+
const lines = steps ? steps.map((s) => `agent-inbox ${s.argv.join(" ")}`) : [`agent-inbox ${plainText(run.sub, 40)}`];
|
|
1623
1646
|
// A request from before this computer reconnected says how old it is, so an earlier ask is not mistaken for a new one.
|
|
1624
1647
|
const ago = Math.floor((Date.now() - Date.parse(run.askedAt)) / 60_000);
|
|
1625
1648
|
const when = ago >= 1 ? ` ${ago} minute${ago === 1 ? "" : "s"} ago` : "";
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
const path = named && !named.startsWith("-") ? named : ".";
|
|
1630
|
-
if (!argv || !staysInside(folder, path)) {
|
|
1649
|
+
const shownLines = several && steps ? lines.map((l, i) => ` ${i + 1}. ${l}`).join("\n") : ` ${lines[0]}`;
|
|
1650
|
+
say(`\n${clock()} ${plainText(run.from, 40)} wants to run, asked by ${plainText(run.askedBy, 60)}${when}:\n\n${shownLines}\n in ${folder}${several && steps ? ", one after the other" : ""}\n`);
|
|
1651
|
+
if (!steps || !steps.every((s) => staysInside(folder, namedPath(s.sub, s.argv)))) {
|
|
1631
1652
|
say("Not run: this computer only runs agent-inbox commands from its list, in this folder.");
|
|
1632
1653
|
await report(run, { status: "declined", output: "This computer refused it: it only runs agent-inbox commands from its list, in the folder it connected.\n" });
|
|
1633
1654
|
return;
|
|
1634
1655
|
}
|
|
1635
|
-
let approved = always.has(
|
|
1636
|
-
if (approved) say(`Running: you chose Always for ${run.sub} while connected.`);
|
|
1656
|
+
let approved = steps.every((s) => always.has(s.sub)) ? "always" : null;
|
|
1657
|
+
if (approved) say(several ? "Running: you chose Always for each of these while connected." : `Running: you chose Always for ${run.sub} while connected.`);
|
|
1637
1658
|
while (!approved) {
|
|
1638
|
-
|
|
1639
|
-
const
|
|
1659
|
+
// Always is offered for one command that may have it, never for a sequence as a whole.
|
|
1660
|
+
const canAlways = !several && RUNNABLE[run.sub].always;
|
|
1661
|
+
const a = await question(several ? `Run all ${steps.length}? [y] yes [n] no › ` : `Run it? [y] yes ${canAlways ? `[a] always for ${run.sub} ` : ""}[n] no › `);
|
|
1640
1662
|
if (a === "y" || a === "yes") approved = "once";
|
|
1641
1663
|
else if (canAlways && (a === "a" || a === "always")) { approved = "always"; always.add(run.sub); }
|
|
1642
1664
|
else if (a === "n" || a === "no") break;
|
|
@@ -1648,16 +1670,26 @@ async function connect(words) {
|
|
|
1648
1670
|
let pending = "";
|
|
1649
1671
|
const flush = async () => { if (!pending) return; const chunk = pending; pending = ""; await report(run, { status: "running", output: chunk }); };
|
|
1650
1672
|
const timer = setInterval(() => void flush(), 1000);
|
|
1651
|
-
const
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1673
|
+
const take = (s) => { process.stdout.write(s); pending += s; };
|
|
1674
|
+
let code = 0;
|
|
1675
|
+
for (let i = 0; i < steps.length; i++) {
|
|
1676
|
+
// In a sequence, each command's output starts with the command, so Next (and the Assistant) can tell them apart.
|
|
1677
|
+
if (several) take(`$ ${lines[i]}\n`);
|
|
1678
|
+
code = await new Promise((done) => {
|
|
1679
|
+
// This CLI's own code with the checked words, in this folder, without a shell: nothing can be added to the line.
|
|
1680
|
+
child = spawn(process.execPath, [SELF, ...steps[i].argv], { cwd: folder, shell: false, windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
1681
|
+
const got = (b) => take(b.toString("utf8"));
|
|
1682
|
+
child.stdout.on("data", got); child.stderr.on("data", got);
|
|
1683
|
+
const limit = setTimeout(() => { take("\nStopped after 20 minutes.\n"); child?.kill(); }, 20 * 60_000);
|
|
1684
|
+
child.on("error", () => { clearTimeout(limit); done(-1); });
|
|
1685
|
+
child.on("close", (c) => { clearTimeout(limit); done(c ?? -1); });
|
|
1686
|
+
});
|
|
1687
|
+
child = null;
|
|
1688
|
+
if (runEnded(code) !== "done") {
|
|
1689
|
+
if (several && i < steps.length - 1) take(`Stopped: ${lines[i]} did not finish, so the rest did not run.\n`);
|
|
1690
|
+
break;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1661
1693
|
clearInterval(timer);
|
|
1662
1694
|
const ended = runEnded(code);
|
|
1663
1695
|
const output = pending; pending = "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@droconnell/agent-inbox-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.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": {
|