@droconnell/agent-inbox-cli 2.1.0 → 2.3.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.
Files changed (2) hide show
  1. package/agent-inbox.mjs +53 -3
  2. package/package.json +1 -1
package/agent-inbox.mjs CHANGED
@@ -34,7 +34,7 @@ import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
34
34
  import { spawn } from "node:child_process";
35
35
  import { fileURLToPath } from "node:url";
36
36
 
37
- export const VERSION = "2.1.0";
37
+ export const VERSION = "2.3.0";
38
38
  /** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
39
39
  export const PACKAGE = "@droconnell/agent-inbox-cli";
40
40
  const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
@@ -86,7 +86,7 @@ const urlArg = take("--url", true);
86
86
  const tokenArg = take("--token", true);
87
87
  /** The CLI's own commands. Anything else is a terminal command, sent as typed. */
88
88
  export const OWN = new Set(["login", "logout", "update", "export", "pull", "plan", "diff", "push", "propose", "run", "tail", "script", "check", "ci", "test", "rehearse", "commands", "help", "submit",
89
- "whoami", "policy", "mcp", "claude", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
89
+ "whoami", "policy", "audit", "mcp", "claude", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
90
90
  const first = args[0];
91
91
  // plan, diff and run are also terminal commands: the CLI's own only for a folder or file that is there (plan, diff) or
92
92
  // a quoted command (run "ls unassigned"); otherwise they go to the terminal as typed (diff 40 42, run onboarding).
@@ -572,7 +572,10 @@ const USAGE = [
572
572
  ["whoami", "the workspace, person and token this runs as"],
573
573
  ["policy pull [policy.yaml]", "write what every agent may do (apps, tools, limits, guards) to a file to keep in git"],
574
574
  ["policy check [policy.yaml]", "fail (exit 1) when the workspace no longer matches the file: for CI"],
575
+ ["policy plan [policy.yaml]", "what an edited policy file would change: agents on or off, at_most, model, daily limit, apps, limits, tools, inbox ceilings"],
576
+ ["policy push [policy.yaml]", "send those changes to Decisions, where an admin applies them (nothing changes from here)"],
575
577
  ["policy", "print what every agent may do"],
578
+ ["audit [--from 2026-11-01] [--to 2026-11-30] [--area access] [--csv] [--out file]", "the audit log and how much each token was used, for a date range (the last 30 days if none): admins only"],
576
579
  ["events [--only conversation,apps]", "changes as they happen, one per line (--json: one JSON object per line), until Ctrl+C"],
577
580
  ["listen --forward <address> [--events a,b]", "Next's webhooks, signed as usual, sent to a server on this computer while it runs"],
578
581
  ["mcp", "an MCP server over stdio for any AI tool, using this computer's sign-in"],
@@ -963,7 +966,54 @@ switch (cmd) {
963
966
  say(markdown && !ok ? `### What the agents may do has changed\n\n${(got.data?.differences ?? []).map((d) => `- ${d}`).join("\n")}\n\nIf it was meant, run \`${ME} policy pull\` and commit ${file}.` : got.text);
964
967
  process.exit(ok ? 0 : 1);
965
968
  }
966
- stop(`Say what to do: ${ME} policy, ${ME} policy pull [file] or ${ME} policy check [file].`);
969
+ if (sub === "plan" || sub === "push") {
970
+ // Edited by hand, the file becomes a plan to make the workspace match it (src/lib/policy.ts, policyToSetup); push
971
+ // sends it to Decisions, where an admin applies it. Nothing changes from here.
972
+ if (!existsSync(file)) stop(`There is no ${file} here. Make it with ${ME} policy pull${file === "policy.yaml" ? "" : ` ${file}`}, change it, then ${ME} policy ${sub}.`);
973
+ const got = await tool("plan_policy", { file: readFileSync(file, "utf8") });
974
+ const d = got.data ?? {};
975
+ const notes = (d.notes ?? []).length ? `\n\nNot changed by the file:\n${d.notes.map((n) => `- ${n}`).join("\n")}` : "";
976
+ if (!d.ok) { if (asJson) report("", { ok: false, problems: d.problems ?? [], notes: d.notes ?? [] }); else say(got.text); process.exit(1); }
977
+ if (!d.changes) { if (asJson) report("", { ok: true, changes: 0, plan: null, notes: d.notes ?? [] }); else say(`No changes: what the agents may do already matches ${file}.${notes}`); process.exit(0); }
978
+ if (sub === "plan") {
979
+ const body = got.text.replace(/\n*(Nothing has changed|This token can only look)[\s\S]*?(?=\n\nNot changed by the file|$)/, "").trim();
980
+ if (asJson) { report("", { ok: true, changes: d.changes, plan: d.plan, notes: d.notes ?? [], text: body }); process.exit(2); }
981
+ say(markdown ? `### ${d.changes === 1 ? "1 change" : `${d.changes} changes`} to what the agents may do\n\n${fence(body)}\n\nMerging proposes these; an admin applies them in Decisions.` : `${body}\n\n${ME} policy push${file === "policy.yaml" ? "" : ` ${file}`} sends this to Decisions, where an admin applies it.`);
982
+ process.exit(2);
983
+ }
984
+ const sent = await tool("submit_plan", { plan: d.plan });
985
+ if (sent.isError) stop(sent.text);
986
+ if (asJson) { report("", { proposed: true, changes: d.changes, plan: d.plan, notes: d.notes ?? [], text: sent.text }); break; }
987
+ say(`${sent.text}${notes}\nOnce it is applied, ${ME} policy pull${file === "policy.yaml" ? "" : ` ${file}`} brings the file in line, and ${ME} policy check passes.`);
988
+ break;
989
+ }
990
+ stop(`Say what to do: ${ME} policy, ${ME} policy pull [file], ${ME} policy check [file], ${ME} policy plan [file] or ${ME} policy push [file].`);
991
+ }
992
+ case "audit": {
993
+ // The audit log and token use for a date range (src/lib/audit-export.ts): a table here, or --csv / --json / --out.
994
+ const opt = (name) => { const i = rest.indexOf(`--${name}`); return i >= 0 && rest[i + 1] && !rest[i + 1].startsWith("--") ? rest[i + 1] : undefined; };
995
+ const out = opt("out");
996
+ const csv = rest.includes("--csv") || Boolean(out && /\.csv$/i.test(out));
997
+ const got = await tool("get_audit", { ...(opt("from") ? { from: opt("from") } : {}), ...(opt("to") ? { to: opt("to") } : {}), ...(opt("area") ? { area: opt("area") } : {}), format: csv ? "csv" : "json" });
998
+ if (got.isError) stop(got.text || "The server did not send the audit log. Try again.");
999
+ const d = got.data ?? {};
1000
+ if (out) {
1001
+ writeFileSync(out, csv ? d.csv : `${JSON.stringify({ ...d, summary: undefined }, null, 2)}\n`);
1002
+ report(`${d.summary} Wrote ${out}.`, { file: out, summary: d.summary });
1003
+ break;
1004
+ }
1005
+ if (csv) { process.stdout.write(d.csv ?? ""); break; }
1006
+ if (asJson) { report("", d); break; }
1007
+ const pad = (s, n) => (String(s).length > n ? `${String(s).slice(0, n - 1)}…` : String(s).padEnd(n));
1008
+ const lines = [`${d.workspace}: ${d.summary}`, ""];
1009
+ for (const e of d.entries ?? []) lines.push(`${e.at.slice(0, 16).replace("T", " ")} ${pad(e.via ? `${e.who} via ${e.via}` : e.who, 28)} ${pad(e.area, 22)} ${e.what}`);
1010
+ if ((d.tokens ?? []).length) {
1011
+ lines.push("", "Token use (calls a day):");
1012
+ for (const t of d.tokens) lines.push(`${t.day} ${pad(t.token, 24)} ${pad(t.owner, 20)} ${String(t.calls).padStart(6)}${t.revoked ? " (revoked)" : ""}`);
1013
+ }
1014
+ lines.push("", `Staff access: ${d.staff_access}`, `For a spreadsheet: ${ME} audit --csv --out audit.csv`);
1015
+ say(lines.join("\n"));
1016
+ break;
967
1017
  }
968
1018
  case "export": {
969
1019
  const { text, isError } = await tool("export_workspace");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droconnell/agent-inbox-cli",
3
- "version": "2.1.0",
3
+ "version": "2.3.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": {