@droconnell/agent-inbox-cli 2.0.0 → 2.2.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 CHANGED
@@ -10,7 +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`. 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`, then `node agent-inbox.mjs ...`.
13
+ That installs the command `agent-inbox`. 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
+
15
+ ```bash
16
+ mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global
17
+ echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
18
+ ```
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`, then `node agent-inbox.mjs ...`.
14
21
 
15
22
  ## Sign in
16
23
 
@@ -45,6 +52,8 @@ agent-inbox push support # send the folder's changes to Decisions
45
52
  agent-inbox export agent-inbox.yaml # the setup as one YAML file
46
53
  agent-inbox diff agent-inbox.yaml # what the file would change; changes nothing
47
54
  agent-inbox propose agent-inbox.yaml # send the changes to Decisions
55
+ agent-inbox policy pull # what every agent may do, to policy.yaml, for git
56
+ agent-inbox policy check # exit 1 when the workspace no longer matches policy.yaml
48
57
  agent-inbox ls unassigned # any console terminal command
49
58
  agent-inbox help # every command
50
59
  ```
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.0.0";
37
+ export const VERSION = "2.2.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", "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).
@@ -268,7 +268,8 @@ export function ciWorkflow(url, folder) {
268
268
  return `# Next support, written by agent-inbox ci init. The support setup lives in ${dir === "." ? "this repository" : `${dir}/`} (agent-inbox pull).
269
269
  # Pull requests: what the change would do, and a rehearsal on past conversations and the saved tests, as one comment.
270
270
  # Merges to main: the changes are proposed in Next's Decisions, for an admin to apply.
271
- # Nightly: changes someone made in Next's console come back as a pull request, so the two never drift apart.
271
+ # Nightly: changes someone made in Next's console come back as a pull request, so the two never drift apart. That
272
+ # includes policy.yaml, what every agent may do: a change to it (an agent now allowed to act alone) is a reviewed line.
272
273
  # Needs the repository secret AGENT_INBOX_TOKEN: a Next personal access token set to Look and propose changes.
273
274
  name: Next support
274
275
  on:
@@ -316,6 +317,10 @@ ${setup}
316
317
  steps:
317
318
  ${setup}
318
319
  - run: node agent-inbox.mjs pull ${dir}
320
+ - name: What the agents may do
321
+ run: |
322
+ node agent-inbox.mjs policy check ${dir === "." ? "" : `${dir}/`}policy.yaml --markdown >> "$GITHUB_STEP_SUMMARY" || true
323
+ node agent-inbox.mjs policy pull ${dir === "." ? "" : `${dir}/`}policy.yaml
319
324
  - name: Open a pull request with what changed in Next
320
325
  env: { GH_TOKEN: "\${{ github.token }}" }
321
326
  run: |
@@ -324,7 +329,7 @@ ${setup}
324
329
  branch="next-changes-$(date +%Y-%m-%d)"
325
330
  git config user.name "Next" && git config user.email "next@users.noreply.github.com"
326
331
  git checkout -b "$branch" && git add -A && git commit -m "Changes made in Next" && git push -u origin "$branch"
327
- gh pr create --title "Changes made in Next" --body "Someone changed the support setup in Next's console. Merging brings this folder up to date; nothing in Next changes."
332
+ gh pr create --title "Changes made in Next" --body "Someone changed the support setup in Next's console. Merging brings this folder up to date; nothing in Next changes. A change to policy.yaml is a change to what the AI agents may do: check it before merging."
328
333
  `;
329
334
  }
330
335
 
@@ -384,12 +389,17 @@ const hash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 16);
384
389
  const readState = (dir) => { try { return JSON.parse(readFileSync(join(dir, STATE), "utf8")); } catch { return null; } };
385
390
  /** A folder pull made, or one laid out like one: workspace.yaml at the top. */
386
391
  export const isPulled = (dir) => existsSync(join(dir, STATE)) || existsSync(join(dir, "workspace.yaml"));
387
- /** Every file in the folder, by path relative to it, skipping hidden ones (.git, the state file) and node_modules. */
392
+ /**
393
+ * Every file in the folder, by path relative to it, skipping hidden ones (.git, the state file), node_modules, and
394
+ * policy.yaml at the top, which policy pull keeps and policy check reads: it records the setup, it does not change it.
395
+ */
396
+ export const POLICY_FILE = "policy.yaml";
388
397
  export function folderFiles(dir) {
389
398
  const out = {};
390
399
  const go = (d) => {
391
400
  for (const e of readdirSync(d, { withFileTypes: true })) {
392
401
  if (e.name.startsWith(".") || e.name === "node_modules") continue;
402
+ if (d === dir && e.name === POLICY_FILE) continue;
393
403
  const p = join(d, e.name);
394
404
  if (e.isDirectory()) go(p); else if (statSync(p).size <= 1_000_000) out[posix(relative(dir, p))] = readFileSync(p, "utf8");
395
405
  }
@@ -560,6 +570,10 @@ const USAGE = [
560
570
  ["login <address> --token", "sign in without a browser: paste a personal access token (or pipe it in, or --token <value>)"],
561
571
  ["login <address> --read", "sign in to look only"],
562
572
  ["whoami", "the workspace, person and token this runs as"],
573
+ ["policy pull [policy.yaml]", "write what every agent may do (apps, tools, limits, guards) to a file to keep in git"],
574
+ ["policy check [policy.yaml]", "fail (exit 1) when the workspace no longer matches the file: for CI"],
575
+ ["policy", "print what every agent may do"],
576
+ ["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"],
563
577
  ["events [--only conversation,apps]", "changes as they happen, one per line (--json: one JSON object per line), until Ctrl+C"],
564
578
  ["listen --forward <address> [--events a,b]", "Next's webhooks, signed as usual, sent to a server on this computer while it runs"],
565
579
  ["mcp", "an MCP server over stdio for any AI tool, using this computer's sign-in"],
@@ -928,6 +942,56 @@ switch (cmd) {
928
942
  emit(me);
929
943
  break;
930
944
  }
945
+ case "policy": {
946
+ // What every agent may do (src/lib/policy.ts): pull writes it, check fails when the workspace has moved on from it.
947
+ const sub = rest[0] && !rest[0].startsWith("--") ? rest[0] : "show";
948
+ const file = rest[1] && !rest[1].startsWith("--") ? rest[1] : "policy.yaml";
949
+ if (sub === "show" || sub === "pull") {
950
+ const got = await tool("get_policy");
951
+ if (got.isError || !got.data?.yaml) stop(got.text || "The server did not send the policy. Try again.");
952
+ if (sub === "show") { if (asJson) report("", { yaml: got.data.yaml }); else process.stdout.write(got.data.yaml); break; }
953
+ const before = existsSync(file) ? readFileSync(file, "utf8") : null;
954
+ if (before === got.data.yaml) { report(`${file} already matches the workspace.`, { file, changed: false }); break; }
955
+ writeFileSync(file, got.data.yaml);
956
+ report(`${before === null ? "Wrote" : "Updated"} ${file}. Commit it: a pull request shows exactly what changed in what the agents may do.`, { file, changed: true });
957
+ break;
958
+ }
959
+ if (sub === "check") {
960
+ if (!existsSync(file)) stop(`There is no ${file} here. Make it with ${ME} policy pull ${file === "policy.yaml" ? "" : file}`.trim());
961
+ const got = await tool("check_policy", { file: readFileSync(file, "utf8") });
962
+ const ok = Boolean(got.data?.ok);
963
+ if (asJson) { report("", { ok, differences: got.data?.differences ?? [], problems: got.data?.problems ?? [] }); process.exit(ok ? 0 : 1); }
964
+ 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);
965
+ process.exit(ok ? 0 : 1);
966
+ }
967
+ stop(`Say what to do: ${ME} policy, ${ME} policy pull [file] or ${ME} policy check [file].`);
968
+ }
969
+ case "audit": {
970
+ // The audit log and token use for a date range (src/lib/audit-export.ts): a table here, or --csv / --json / --out.
971
+ const opt = (name) => { const i = rest.indexOf(`--${name}`); return i >= 0 && rest[i + 1] && !rest[i + 1].startsWith("--") ? rest[i + 1] : undefined; };
972
+ const out = opt("out");
973
+ const csv = rest.includes("--csv") || Boolean(out && /\.csv$/i.test(out));
974
+ 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" });
975
+ if (got.isError) stop(got.text || "The server did not send the audit log. Try again.");
976
+ const d = got.data ?? {};
977
+ if (out) {
978
+ writeFileSync(out, csv ? d.csv : `${JSON.stringify({ ...d, summary: undefined }, null, 2)}\n`);
979
+ report(`${d.summary} Wrote ${out}.`, { file: out, summary: d.summary });
980
+ break;
981
+ }
982
+ if (csv) { process.stdout.write(d.csv ?? ""); break; }
983
+ if (asJson) { report("", d); break; }
984
+ const pad = (s, n) => (String(s).length > n ? `${String(s).slice(0, n - 1)}…` : String(s).padEnd(n));
985
+ const lines = [`${d.workspace}: ${d.summary}`, ""];
986
+ 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}`);
987
+ if ((d.tokens ?? []).length) {
988
+ lines.push("", "Token use (calls a day):");
989
+ 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)" : ""}`);
990
+ }
991
+ lines.push("", `Staff access: ${d.staff_access}`, `For a spreadsheet: ${ME} audit --csv --out audit.csv`);
992
+ say(lines.join("\n"));
993
+ break;
994
+ }
931
995
  case "export": {
932
996
  const { text, isError } = await tool("export_workspace");
933
997
  if (isError) stop(text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droconnell/agent-inbox-cli",
3
- "version": "2.0.0",
3
+ "version": "2.2.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": {