@droconnell/agent-inbox-cli 2.4.0 → 2.5.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 +8 -0
- package/agent-inbox.mjs +178 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,14 @@ echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
|
|
|
19
19
|
|
|
20
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 ...`.
|
|
21
21
|
|
|
22
|
+
## Set everything up at once
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
agent-inbox init https://your-next-address
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Signs you in, writes your setup to a folder named `support`, adds a starter `CLAUDE.md`, `.mcp.json` (so AI tools opened there get Next's tools) and the GitHub workflow that checks pull requests, makes the folder a git repository, and offers to create a private GitHub repository when `gh` is signed in. It changes nothing in your workspace, and is safe to run again.
|
|
29
|
+
|
|
22
30
|
## Sign in
|
|
23
31
|
|
|
24
32
|
```bash
|
package/agent-inbox.mjs
CHANGED
|
@@ -4,43 +4,47 @@
|
|
|
4
4
|
// file from your workspace: curl -fsSLO <console>/cli/agent-inbox.mjs and run it as node agent-inbox.mjs.
|
|
5
5
|
// The npm package (cli/ in the repository) is a copy of this file made at release: this file is the only source.
|
|
6
6
|
//
|
|
7
|
+
// agent-inbox init <console address> everything at once: sign in, the setup as a folder in git, Claude Code and
|
|
8
|
+
// the pull request check, ready to use (run it again any time: it skips what is done)
|
|
7
9
|
// agent-inbox login <console address> sign in from the browser (or set AGENT_INBOX_URL and AGENT_INBOX_TOKEN)
|
|
8
10
|
// agent-inbox export [file] the setup as YAML (to the file, or printed)
|
|
9
11
|
// agent-inbox pull [folder] the setup as a folder of files: workspace.yaml, agents/, knowledge/, rules/,
|
|
10
12
|
// tests/ and apps/ (the same files Settings, Your support as files shows)
|
|
11
13
|
// agent-inbox plan [folder] what the changed folder would change; changes nothing (exit 0 none, 2 some, 1 problems)
|
|
12
|
-
// agent-inbox push [folder] [--prune] send those changes to
|
|
14
|
+
// agent-inbox push [folder] [--prune] send those changes to Approvals; --prune also removes articles and tests
|
|
13
15
|
// whose files you deleted
|
|
14
16
|
// agent-inbox check [folder] for a pull request: the plan and a rehearsal of it, as markdown (exit 1 needs a look)
|
|
15
17
|
// agent-inbox ci init [folder] write the GitHub workflow that checks pull requests, proposes on merge, and
|
|
16
18
|
// opens a pull request when someone changed the setup in the console
|
|
17
19
|
// agent-inbox diff <file|folder> what the file would change; changes nothing (exit 0 none, 2 some, 1 problems)
|
|
18
|
-
// agent-inbox propose <file|folder> send those changes to
|
|
20
|
+
// agent-inbox propose <file|folder> send those changes to Approvals, where an admin applies or discards them
|
|
19
21
|
// (a folder: its Markdown, text and HTML documents, as knowledge articles)
|
|
20
22
|
// agent-inbox <terminal command> any console terminal command, such as agent-inbox ls unassigned
|
|
21
23
|
// agent-inbox run "<command>" the same, in quotes, such as "ls unassigned" or "route test 'refund?'"
|
|
22
24
|
// agent-inbox help <command> one terminal command with an example; agent-inbox commands lists them all
|
|
23
25
|
// agent-inbox script <file> [--propose] a file of terminal commands, one per line, as one plan; --propose sends
|
|
24
|
-
// it to
|
|
26
|
+
// it to Approvals (exit 0 nothing to change, 2 a plan, 1 problems)
|
|
25
27
|
// agent-inbox logout forget the sign-in on this computer
|
|
26
28
|
// agent-inbox update how to update, for how it was installed (a downloaded file updates itself)
|
|
27
29
|
//
|
|
28
|
-
// Nothing the CLI does changes the workspace by itself: changes wait in
|
|
30
|
+
// Nothing the CLI does changes the workspace by itself: changes wait in Approvals for an admin's click.
|
|
29
31
|
import { createHash, randomBytes } from "node:crypto";
|
|
30
32
|
import { createServer } from "node:http";
|
|
31
33
|
import { mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, existsSync } from "node:fs";
|
|
32
34
|
import { homedir } from "node:os";
|
|
33
|
-
import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
|
|
34
|
-
import { spawn } from "node:child_process";
|
|
35
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
36
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
35
37
|
import { fileURLToPath } from "node:url";
|
|
36
38
|
|
|
37
|
-
export const VERSION = "2.
|
|
39
|
+
export const VERSION = "2.5.0";
|
|
38
40
|
/** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
|
|
39
41
|
export const PACKAGE = "@droconnell/agent-inbox-cli";
|
|
40
42
|
const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
|
|
41
43
|
const SAVED = join(DIR, "sign-in.json");
|
|
42
44
|
const CHECKED = join(DIR, "update-check.json");
|
|
43
45
|
const SELF = fileURLToPath(import.meta.url);
|
|
46
|
+
/** How the CLI names itself to Next. A run in CI says so, so Next can tell a pull request check from a person typing. */
|
|
47
|
+
const UA = `agent-inbox-cli/${VERSION}${process.env.CI || process.env.GITHUB_ACTIONS ? " ci" : ""}`;
|
|
44
48
|
const real = (p) => { try { return realpathSync(p); } catch { return p; } };
|
|
45
49
|
|
|
46
50
|
/** Whether version a is newer than version b ("1.10.0" is newer than "1.9.2"). Anything unreadable is not newer. */
|
|
@@ -86,7 +90,7 @@ const urlArg = take("--url", true);
|
|
|
86
90
|
const tokenArg = take("--token", true);
|
|
87
91
|
/** The CLI's own commands. Anything else is a terminal command, sent as typed. */
|
|
88
92
|
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", "audit", "mcp", "claude", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
|
|
93
|
+
"whoami", "policy", "audit", "mcp", "claude", "init", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
|
|
90
94
|
const first = args[0];
|
|
91
95
|
// 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
96
|
// a quoted command (run "ls unassigned"); otherwise they go to the terminal as typed (diff 40 42, run onboarding).
|
|
@@ -188,7 +192,7 @@ async function tool(name, args = {}, { soft = false } = {}) {
|
|
|
188
192
|
try {
|
|
189
193
|
r = await fetch(`${url}/api/mcp`, {
|
|
190
194
|
method: "POST",
|
|
191
|
-
headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json, text/event-stream", "user-agent":
|
|
195
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json, text/event-stream", "user-agent": UA },
|
|
192
196
|
body: JSON.stringify({ jsonrpc: "2.0", id: ++calls, method: "tools/call", params: { name, arguments: args } }),
|
|
193
197
|
});
|
|
194
198
|
} catch { if (soft) throw new Error("unreachable"); stop(`Could not reach ${url}. Check the address and your connection.`); }
|
|
@@ -252,7 +256,7 @@ export function checkReport({ plan, changes, rehearsal = null, skipped = null, b
|
|
|
252
256
|
if (blocked) parts.push(`### Could not rehearse\n\n${blocked}`);
|
|
253
257
|
const failed = Boolean(blocked || (rehearsal && !rehearsal.ok));
|
|
254
258
|
if (failed) parts.push("**Needs a look before merging.**");
|
|
255
|
-
else if (changes) parts.push("Merging proposes these changes in Next's **
|
|
259
|
+
else if (changes) parts.push("Merging proposes these changes in Next's **Approvals**, where an admin applies them.");
|
|
256
260
|
return { text: parts.join("\n\n") + "\n", failed };
|
|
257
261
|
}
|
|
258
262
|
|
|
@@ -268,7 +272,7 @@ export function ciWorkflow(url, folder) {
|
|
|
268
272
|
const pr = "${{ github.event.pull_request.number }}";
|
|
269
273
|
return `# Next support, written by agent-inbox ci init. The support setup lives in ${dir === "." ? "this repository" : `${dir}/`} (agent-inbox pull).
|
|
270
274
|
# Pull requests: what the change would do, and a rehearsal on past conversations and the saved tests, as one comment.
|
|
271
|
-
# Merges to main: the changes are proposed in Next's
|
|
275
|
+
# Merges to main: the changes are proposed in Next's Approvals, for an admin to apply.
|
|
272
276
|
# Nightly: changes someone made in Next's console come back as a pull request, so the two never drift apart. That
|
|
273
277
|
# includes policy.yaml, what every agent may do: a change to it (an agent now allowed to act alone) is a reviewed line.
|
|
274
278
|
# Needs the repository secret AGENT_INBOX_TOKEN: a Next personal access token set to Look and propose changes.
|
|
@@ -395,12 +399,14 @@ export const isPulled = (dir) => existsSync(join(dir, STATE)) || existsSync(join
|
|
|
395
399
|
* policy.yaml at the top, which policy pull keeps and policy check reads: it records the setup, it does not change it.
|
|
396
400
|
*/
|
|
397
401
|
export const POLICY_FILE = "policy.yaml";
|
|
402
|
+
/** Files at the top of the folder that are for the people and AI tools working in it, never part of the setup. */
|
|
403
|
+
export const HOUSE_FILES = ["CLAUDE.md", "AGENTS.md"];
|
|
398
404
|
export function folderFiles(dir) {
|
|
399
405
|
const out = {};
|
|
400
406
|
const go = (d) => {
|
|
401
407
|
for (const e of readdirSync(d, { withFileTypes: true })) {
|
|
402
408
|
if (e.name.startsWith(".") || e.name === "node_modules") continue;
|
|
403
|
-
if (d === dir && e.name === POLICY_FILE) continue;
|
|
409
|
+
if (d === dir && (e.name === POLICY_FILE || HOUSE_FILES.includes(e.name))) continue;
|
|
404
410
|
const p = join(d, e.name);
|
|
405
411
|
if (e.isDirectory()) go(p); else if (statSync(p).size <= 1_000_000) out[posix(relative(dir, p))] = readFileSync(p, "utf8");
|
|
406
412
|
}
|
|
@@ -469,7 +475,7 @@ async function pull(dir) {
|
|
|
469
475
|
}
|
|
470
476
|
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
471
477
|
say(before ? `Brought ${dir} up to date: ${count(wrote, "file", "files")} written${removed ? `, ${count(removed, "file", "files")} removed` : ""}, ${count(wanted.size, "file", "files")} in all.` : `Wrote ${count(wanted.size, "file", "files")} to ${dir}: workspace.yaml, agents/, knowledge/, rules/, tests/ and apps/.`);
|
|
472
|
-
if (!before) say(`Change any of them, then ${ME} plan ${dir} shows what would change and ${ME} push ${dir} sends it to
|
|
478
|
+
if (!before) say(`Change any of them, then ${ME} plan ${dir} shows what would change and ${ME} push ${dir} sends it to Approvals.`);
|
|
473
479
|
}
|
|
474
480
|
|
|
475
481
|
/** Plan a pulled folder, as the server reads it; the same answer import_workspace gives for one file. */
|
|
@@ -495,7 +501,7 @@ async function login(address) {
|
|
|
495
501
|
if (tokenGiven) {
|
|
496
502
|
const token = tokenArg || (process.stdin.isTTY ? await ask("Paste a personal access token from Settings, Terminal, AI tools: ") : (await stdinText()).trim());
|
|
497
503
|
if (!token) stop("No token was given.");
|
|
498
|
-
const r = await fetch(`${url}/api/mcp`, { method: "POST", headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json" },
|
|
504
|
+
const r = await fetch(`${url}/api/mcp`, { method: "POST", headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json", "user-agent": UA },
|
|
499
505
|
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "whoami", arguments: {} } }) }).catch(() => null);
|
|
500
506
|
if (!r) stop(`Could not reach ${url}. Check the address.`);
|
|
501
507
|
if (r.status === 401) stop("That token was refused: it is wrong, expired or revoked.");
|
|
@@ -548,13 +554,14 @@ async function login(address) {
|
|
|
548
554
|
}
|
|
549
555
|
|
|
550
556
|
const USAGE = [
|
|
557
|
+
["init <console address> [folder]", "set everything up at once: sign in, the setup as a folder in git, Claude Code and the pull request check"],
|
|
551
558
|
["login <console address>", "sign in from the browser"],
|
|
552
559
|
["export [file]", "the setup as YAML"],
|
|
553
560
|
["pull [folder]", "the setup as a folder of files (agents/, knowledge/, rules/, tests/, apps/)"],
|
|
554
561
|
["plan [folder]", "what the changed folder would change (exit 0 nothing, 2 changes, 1 problems)"],
|
|
555
|
-
["push [folder] [--prune]", "send the folder's changes to
|
|
562
|
+
["push [folder] [--prune]", "send the folder's changes to Approvals; --prune removes deleted articles and tests"],
|
|
556
563
|
["diff <file|folder>", "what the file would change (exit 0 nothing, 2 changes, 1 problems)"],
|
|
557
|
-
["propose <file|folder>", "send the changes to
|
|
564
|
+
["propose <file|folder>", "send the changes to Approvals for an admin to apply"],
|
|
558
565
|
["", "a folder's Markdown, text and HTML documents become knowledge articles;"],
|
|
559
566
|
["", "in a file, knowledge entries can name file: docs/a.md or files: docs/**/*.md"],
|
|
560
567
|
["<terminal command>", "any console terminal command, such as ME ls unassigned"],
|
|
@@ -562,8 +569,8 @@ const USAGE = [
|
|
|
562
569
|
["check [folder] [--on 20]", "for a pull request: what the folder would change and a rehearsal of it, as markdown (exit 1 when something needs a look)"],
|
|
563
570
|
["ci init [folder] [--force]", "write a GitHub workflow: check pull requests, propose on merge, and open a pull request when the console changed"],
|
|
564
571
|
["tail [--inbox name] [--tag name] [--since 15m]", "what is happening now, then keeps following until Ctrl+C (in CI: one page, then the line to continue)"],
|
|
565
|
-
["script <file> [--propose]", "commands, one per line, as one plan; --propose sends it to
|
|
566
|
-
["submit <plan>", "send a plan a change printed to
|
|
572
|
+
["script <file> [--propose]", "commands, one per line, as one plan; --propose sends it to Approvals"],
|
|
573
|
+
["submit <plan>", "send a plan a change printed to Approvals, for an admin to apply (the CLI never applies)"],
|
|
567
574
|
["test", "run the agents' tests and wait (exit 0 all pass, 1 some fail)"],
|
|
568
575
|
["rehearse <file>", "rehearse the agents the file adds or changes on past conversations and wait"],
|
|
569
576
|
["rehearse [plan] [--on 20] [--topic refund]", "show me before it goes live: past conversations and the tests, with a plan and without"],
|
|
@@ -575,7 +582,7 @@ const USAGE = [
|
|
|
575
582
|
["policy pull [policy.yaml]", "write what every agent may do (apps, tools, limits, guards) to a file to keep in git"],
|
|
576
583
|
["policy check [policy.yaml]", "fail (exit 1) when the workspace no longer matches the file: for CI"],
|
|
577
584
|
["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"],
|
|
578
|
-
["policy push [policy.yaml]", "send those changes to
|
|
585
|
+
["policy push [policy.yaml]", "send those changes to Approvals, where an admin applies them (nothing changes from here)"],
|
|
579
586
|
["policy", "print what every agent may do"],
|
|
580
587
|
["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"],
|
|
581
588
|
["events [--only conversation,apps]", "changes as they happen, one per line (--json: one JSON object per line), until Ctrl+C"],
|
|
@@ -602,7 +609,7 @@ ${lines.join("\n")}
|
|
|
602
609
|
Every command takes --json (data, not words: for scripts and agents) and --fields a,b (only those columns).
|
|
603
610
|
Pipe commands in with run - or script -. Exit codes: 0 done, 1 failed or refused, 2 a plan or changes to apply.
|
|
604
611
|
In CI, set AGENT_INBOX_URL and AGENT_INBOX_TOKEN (or --url and --token) instead of logging in.
|
|
605
|
-
--markdown gives plan, push, test and rehearse as a GitHub summary. Nothing changes until an admin applies it in
|
|
612
|
+
--markdown gives plan, push, test and rehearse as a GitHub summary. Nothing changes until an admin applies it in Approvals.`;
|
|
606
613
|
}
|
|
607
614
|
|
|
608
615
|
// ---- Updates -------------------------------------------------------------------------------------------------------
|
|
@@ -687,6 +694,149 @@ async function mcpServer() {
|
|
|
687
694
|
function selfCommand() { return ME === "agent-inbox" ? { command: "agent-inbox", args: ["mcp"] } : { command: process.execPath, args: [SELF, "mcp"] }; }
|
|
688
695
|
|
|
689
696
|
/** agent-inbox claude: add Next to Claude Code (claude mcp add), or write .mcp.json for this project with --project. */
|
|
697
|
+
/** Write (or add to) the folder's .mcp.json so AI tools opened there start Next's MCP server. True when it changed. */
|
|
698
|
+
function writeMcpJson(dir = ".") {
|
|
699
|
+
const c = selfCommand();
|
|
700
|
+
const file = join(dir, ".mcp.json");
|
|
701
|
+
let cfg = {}; try { cfg = JSON.parse(readFileSync(file, "utf8")); } catch {}
|
|
702
|
+
const next = { command: c.command, args: c.args };
|
|
703
|
+
if (JSON.stringify(cfg.mcpServers?.next) === JSON.stringify(next)) return false;
|
|
704
|
+
cfg.mcpServers = { ...(cfg.mcpServers ?? {}), next };
|
|
705
|
+
writeFileSync(file, JSON.stringify(cfg, null, 2) + "\n");
|
|
706
|
+
return true;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* The starter CLAUDE.md that init writes at the top of a support folder: what the folder is, how a change travels, and
|
|
711
|
+
* the house rules every AI tool working here should keep. People edit it afterwards; init never overwrites it.
|
|
712
|
+
*/
|
|
713
|
+
export function claudeMd({ workspace, url, agents = [], me = "agent-inbox" }) {
|
|
714
|
+
return `# ${workspace || "Our"} support
|
|
715
|
+
|
|
716
|
+
This folder is the setup of our support in Next (${url}): the agents, what they know, the rules and the tests.
|
|
717
|
+
It was written by \`${me} pull\`. Changing a file here changes nothing in Next until a person applies it.
|
|
718
|
+
|
|
719
|
+
## What is where
|
|
720
|
+
|
|
721
|
+
- \`workspace.yaml\`: inboxes, routing, hours and the other settings.
|
|
722
|
+
- \`agents/\`: one file per agent, with its job and instructions.${agents.length ? ` Ours: ${agents.join(", ")}.` : ""}
|
|
723
|
+
- \`knowledge/\`: one file per article the agents answer from. A new file is a new article.
|
|
724
|
+
- \`rules/\`: the rules every agent follows.
|
|
725
|
+
- \`tests/\`: questions with what a good answer must say. A new file is a new test.
|
|
726
|
+
- \`apps/\`: the small tools beside a conversation.
|
|
727
|
+
|
|
728
|
+
## How a change travels
|
|
729
|
+
|
|
730
|
+
1. Change the files.
|
|
731
|
+
2. \`${me} plan .\` shows what would change. It changes nothing.
|
|
732
|
+
3. \`${me} push .\` (or merging a pull request) sends it to Approvals in Next.
|
|
733
|
+
4. An admin presses Apply there. Nothing here can apply or undo a change.
|
|
734
|
+
|
|
735
|
+
You also have Next's tools (the MCP server named next): look things up with them instead of guessing.
|
|
736
|
+
|
|
737
|
+
## House rules
|
|
738
|
+
|
|
739
|
+
- Always show the plan before proposing anything, and say in one line why the change is worth making.
|
|
740
|
+
- Never propose a change that removes or turns something off without asking first.
|
|
741
|
+
- A change to an agent's instructions comes with a test in \`tests/\` that would have caught the problem.
|
|
742
|
+
- Write knowledge the way the other articles are written: plain words, short, one topic per article, no promises we cannot keep.
|
|
743
|
+
- Start from evidence: \`${me} gaps\` for what customers asked that the agents could not answer, and real conversations for why.
|
|
744
|
+
- Rehearsals and tests cost money. Ask before running one.
|
|
745
|
+
- Never put a customer's name, email or message into a file here.
|
|
746
|
+
`;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** Run a program and wait; null when it is not installed. */
|
|
750
|
+
const sh = (cmd, a, cwd) => { const r = spawnSync(cmd, a, { cwd, encoding: "utf8", windowsHide: true }); return r.error ? null : { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() }; };
|
|
751
|
+
/** A name GitHub accepts for the repository: the workspace's name, then -support. */
|
|
752
|
+
export const repoName = (workspace) => `${String(workspace || "next").toLowerCase().normalize("NFKD").replace(/\p{M}+/gu, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "next"}-support`;
|
|
753
|
+
/** init's words: the console's address (anything that reads as one) and the folder (anything else), in either order. */
|
|
754
|
+
export function initArgs(words, exists = existsSync) {
|
|
755
|
+
const plain = words.filter((w) => !w.startsWith("--"));
|
|
756
|
+
const address = plain.find((w) => /^https?:\/\//i.test(w) || (/^[a-z0-9.-]+\.[a-z]{2,}(:\d+)?$/i.test(w) && !exists(w)) || /^localhost(:\d+)?$/i.test(w));
|
|
757
|
+
return { address, folder: plain.find((w) => w !== address) ?? "support" };
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* agent-inbox init <address> [folder]: everything the guide walks through, in one go. Each step says what it is doing,
|
|
762
|
+
* skips what is already done, and never overwrites a file someone changed, so it is safe to run again. It only looks
|
|
763
|
+
* and writes files on this computer: nothing in the workspace changes.
|
|
764
|
+
*/
|
|
765
|
+
async function init(words) {
|
|
766
|
+
const { address, folder: dir } = initArgs(words);
|
|
767
|
+
const total = 6;
|
|
768
|
+
const step = (n, text) => { if (!asJson) say(`\n[${n}/${total}] ${text}`); };
|
|
769
|
+
const done = { signedIn: false, folder: dir, wrote: [], git: "skipped", github: "skipped", claude: false, next: [] };
|
|
770
|
+
|
|
771
|
+
step(1, "Signing in");
|
|
772
|
+
const saved = load();
|
|
773
|
+
const fromEnv = Boolean(process.env.AGENT_INBOX_TOKEN || tokenArg);
|
|
774
|
+
if (!fromEnv && address && saved?.url !== clean(address)) await login(address);
|
|
775
|
+
else if (!fromEnv && !saved) stop(`Give your Next address, for example ${ME} init https://inbox.example.com`);
|
|
776
|
+
const me = await tool("whoami");
|
|
777
|
+
if (me.isError || !me.data) stop(me.text || "The sign-in did not work. Run it again.");
|
|
778
|
+
done.signedIn = true;
|
|
779
|
+
const { url } = await access();
|
|
780
|
+
if (!asJson) say(` Signed in to ${me.data.workspace} as ${me.data.user}.`);
|
|
781
|
+
if (me.data.scope === "read" && !asJson) say(` This sign-in can only look. To propose changes later, run ${ME} login ${url} again.`);
|
|
782
|
+
|
|
783
|
+
step(2, `Your support as files, in ${dir}/`);
|
|
784
|
+
if (readState(dir)) { if (!asJson) say(` ${dir}/ is already here. ${ME} pull ${dir} brings it up to date.`); }
|
|
785
|
+
else await pull(dir);
|
|
786
|
+
|
|
787
|
+
step(3, "Files for Claude Code and for GitHub");
|
|
788
|
+
const wrote = (rel) => { done.wrote.push(rel); if (!asJson) say(` Wrote ${rel}`); };
|
|
789
|
+
const kept = (rel) => { if (!asJson) say(` Kept your ${rel}`); };
|
|
790
|
+
const files = folderFiles(dir);
|
|
791
|
+
const agents = [...new Set(Object.keys(files).filter((p) => p.startsWith("agents/")).map((p) => basename(p).replace(/\.[a-z]+$/i, "")))];
|
|
792
|
+
if (existsSync(join(dir, "CLAUDE.md"))) kept("CLAUDE.md"); else { writeFileSync(join(dir, "CLAUDE.md"), claudeMd({ workspace: me.data.workspace, url, agents, me: ME === "agent-inbox" ? ME : "agent-inbox" })); wrote("CLAUDE.md"); }
|
|
793
|
+
if (writeMcpJson(dir)) wrote(".mcp.json"); else kept(".mcp.json");
|
|
794
|
+
if (ME !== "agent-inbox" && !asJson) say(" (.mcp.json names this computer's copy of the CLI. Installed with npm, it works for teammates too.)");
|
|
795
|
+
const flow = join(dir, ".github", "workflows", "next-support.yml");
|
|
796
|
+
if (existsSync(flow)) kept(".github/workflows/next-support.yml"); else { mkdirSync(dirname(flow), { recursive: true }); writeFileSync(flow, ciWorkflow(url, ".")); wrote(".github/workflows/next-support.yml"); }
|
|
797
|
+
|
|
798
|
+
step(4, "Git");
|
|
799
|
+
const git = sh("git", ["--version"]);
|
|
800
|
+
if (!git?.ok) { done.git = "missing"; done.next.push("Install git (https://git-scm.com), then run this again."); if (!asJson) say(" Git is not installed here, so the folder is not a repository yet."); }
|
|
801
|
+
else if (existsSync(join(dir, ".git"))) { done.git = "there"; if (!asJson) say(" Already a repository. Commit the new files when you are ready."); }
|
|
802
|
+
else if (sh("git", ["rev-parse", "--is-inside-work-tree"], dir)?.ok) { done.git = "inside"; if (!asJson) say(` ${dir}/ is inside another repository, so it was left as it is. For the pull request check, give it a repository of its own.`); }
|
|
803
|
+
else {
|
|
804
|
+
sh("git", ["init", "-q", "-b", "main"], dir);
|
|
805
|
+
sh("git", ["add", "-A"], dir);
|
|
806
|
+
const c = sh("git", ["commit", "-q", "-m", "Our support setup, from Next"], dir);
|
|
807
|
+
done.git = c?.ok ? "committed" : "made";
|
|
808
|
+
if (!asJson) say(c?.ok ? " Made a repository and the first commit." : " Made a repository. Git needs your name before it can commit: git config --global user.name \"Your name\", and the same for user.email.");
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
step(5, "GitHub");
|
|
812
|
+
const hasGit = ["there", "committed", "made"].includes(done.git);
|
|
813
|
+
const remote = hasGit ? sh("git", ["remote", "get-url", "origin"], dir) : null;
|
|
814
|
+
const gh = sh("gh", ["auth", "status"]);
|
|
815
|
+
const secretLine = "gh secret set AGENT_INBOX_TOKEN";
|
|
816
|
+
if (remote?.ok) { done.github = "there"; if (!asJson) say(` Already on ${remote.out}.`); }
|
|
817
|
+
else if (!hasGit) { if (!asJson) say(" Skipped: there is no repository of its own to put there yet."); }
|
|
818
|
+
else if (gh?.ok && done.git === "committed" && process.stdin.isTTY && !asJson && !rest.includes("--no-github")) {
|
|
819
|
+
const name = repoName(me.data.workspace);
|
|
820
|
+
const yes = /^y(es)?$/i.test(await ask(` Create a private repository named ${name} on GitHub and push to it? (y/n) `));
|
|
821
|
+
if (yes) {
|
|
822
|
+
const made = sh("gh", ["repo", "create", name, "--private", "--source", ".", "--remote", "origin", "--push"], dir);
|
|
823
|
+
done.github = made?.ok ? "created" : "failed";
|
|
824
|
+
say(made?.ok ? ` Created ${name}, private, and pushed.` : ` GitHub did not create it: ${made?.out.split("\n").pop() ?? "no answer"}. Create it on github.com and push when you are ready.`);
|
|
825
|
+
} else say(" Left on this computer. Push it to a private repository when you are ready.");
|
|
826
|
+
} else {
|
|
827
|
+
if (!asJson) say(gh ? " Push this folder to a private repository on GitHub when you are ready." : " Push this folder to a private repository on GitHub when you are ready. (With GitHub's own tool, gh, installed and signed in, this step does it for you.)");
|
|
828
|
+
}
|
|
829
|
+
done.next.push(`For the pull request check: in Next, make a token set to Look and propose changes (Settings, Terminal, Plain English and AI tools), then in ${dir}/ run ${secretLine} and paste it${gh ? "" : " (or add it as a repository secret named AGENT_INBOX_TOKEN on github.com)"}. Paste it nowhere else.`);
|
|
830
|
+
|
|
831
|
+
step(6, "Claude Code");
|
|
832
|
+
done.claude = Boolean(sh("claude", ["--version"])?.ok);
|
|
833
|
+
if (!asJson) say(done.claude ? ` Claude Code is installed. Opened in ${dir}/, it has Next's tools and reads CLAUDE.md.` : " Claude Code is not installed here. Get it at https://claude.com/claude-code; this folder is ready for it.");
|
|
834
|
+
|
|
835
|
+
done.next.unshift(done.claude ? `cd ${dir}, run claude, and ask: "What needs a person in Next right now?"` : `Install Claude Code, then cd ${dir}, run claude, and ask: "What needs a person in Next right now?"`);
|
|
836
|
+
if (asJson) { report("", done); return; }
|
|
837
|
+
say(`\nDone. Nothing in ${me.data.workspace} was changed.\n\nNext:\n${done.next.map((n, i) => ` ${i + 1}. ${n}`).join("\n")}\n\n${url}/settings/terminal shows how far along you are.`);
|
|
838
|
+
}
|
|
839
|
+
|
|
690
840
|
async function claudeSetup(project) {
|
|
691
841
|
const c = selfCommand();
|
|
692
842
|
if (project) {
|
|
@@ -935,6 +1085,7 @@ switch (cmd) {
|
|
|
935
1085
|
}
|
|
936
1086
|
case "mcp": await mcpServer(); break;
|
|
937
1087
|
case "claude": await claudeSetup(rest.includes("--project")); break;
|
|
1088
|
+
case "init": await init(rest); break;
|
|
938
1089
|
case "app": await appCommand(rest); break;
|
|
939
1090
|
case "events": { const only = (valueOf(rest, "--only") ?? "").split(",").filter(Boolean); await events(only.length ? only : null); break; }
|
|
940
1091
|
case "listen": await listen(valueOf(rest, "--forward"), valueOf(rest, "--events")?.split(",").filter(Boolean)); break;
|
|
@@ -970,7 +1121,7 @@ switch (cmd) {
|
|
|
970
1121
|
}
|
|
971
1122
|
if (sub === "plan" || sub === "push") {
|
|
972
1123
|
// Edited by hand, the file becomes a plan to make the workspace match it (src/lib/policy.ts, policyToSetup); push
|
|
973
|
-
// sends it to
|
|
1124
|
+
// sends it to Approvals, where an admin applies it. Nothing changes from here.
|
|
974
1125
|
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}.`);
|
|
975
1126
|
const got = await tool("plan_policy", { file: readFileSync(file, "utf8") });
|
|
976
1127
|
const d = got.data ?? {};
|
|
@@ -980,7 +1131,7 @@ switch (cmd) {
|
|
|
980
1131
|
if (sub === "plan") {
|
|
981
1132
|
const body = got.text.replace(/\n*(Nothing has changed|This token can only look)[\s\S]*?(?=\n\nNot changed by the file|$)/, "").trim();
|
|
982
1133
|
if (asJson) { report("", { ok: true, changes: d.changes, plan: d.plan, notes: d.notes ?? [], text: body }); process.exit(2); }
|
|
983
|
-
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
|
|
1134
|
+
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 Approvals.` : `${body}\n\n${ME} policy push${file === "policy.yaml" ? "" : ` ${file}`} sends this to Approvals, where an admin applies it.`);
|
|
984
1135
|
process.exit(2);
|
|
985
1136
|
}
|
|
986
1137
|
const sent = await tool("submit_plan", { plan: d.plan });
|
|
@@ -1043,7 +1194,7 @@ switch (cmd) {
|
|
|
1043
1194
|
// A folder's notes (articles from a website, files with no match) are worth seeing even when nothing changes.
|
|
1044
1195
|
const notes = folder ? text.split("\n").filter((l) => l.trim() && !/^Nothing would change/.test(l)).join("\n") : "";
|
|
1045
1196
|
if (!data.changes) { say(markdown ? `### No changes\n\nThe workspace already matches the ${what}.${notes ? `\n\n${notes}` : ""}` : `No changes: the workspace already matches the ${what}.${notes ? `\n${notes}` : ""}`); process.exit(0); }
|
|
1046
|
-
say(markdown ? `### ${data.changes === 1 ? "1 change" : `${data.changes} changes`} to the workspace\n\n${fence(body)}\n\nMerging proposes these; an admin applies them in
|
|
1197
|
+
say(markdown ? `### ${data.changes === 1 ? "1 change" : `${data.changes} changes`} to the workspace\n\n${fence(body)}\n\nMerging proposes these; an admin applies them in Approvals.` : body);
|
|
1047
1198
|
process.exit(2);
|
|
1048
1199
|
}
|
|
1049
1200
|
case "push": case "propose": {
|
|
@@ -1060,7 +1211,7 @@ switch (cmd) {
|
|
|
1060
1211
|
if (sent.isError) stop(sent.text);
|
|
1061
1212
|
if (asJson) { report("", { proposed: true, changes: data.changes, plan: data.plan, apps: appsSent, text: sent.text }); break; }
|
|
1062
1213
|
say(markdown ? `### Proposed ${data.changes === 1 ? "1 change" : `${data.changes} changes`}\n\n${sent.text}` : `${folder ? `${text.replace(/\n*Nothing has changed\. An AI tool cannot apply[^\n]*/, "").trim()}\n\n` : ""}${sent.text}`);
|
|
1063
|
-
if (folder) say(`Once it is applied, ${ME} pull ${dir} brings the folder up to date. Undo it in the console (
|
|
1214
|
+
if (folder) say(`Once it is applied, ${ME} pull ${dir} brings the folder up to date. Undo it in the console (Approvals, or undo in the terminal).`);
|
|
1064
1215
|
break;
|
|
1065
1216
|
}
|
|
1066
1217
|
case "run": {
|
|
@@ -1107,7 +1258,7 @@ switch (cmd) {
|
|
|
1107
1258
|
if (isError) { say(text); process.exit(1); }
|
|
1108
1259
|
const planRef = (/Plan ([0-9a-f]{8})/.exec(text) ?? [])[1];
|
|
1109
1260
|
if (!planRef) { say(text); break; }
|
|
1110
|
-
if (!proposing) { say(markdown ? fence(text) : text); say("Nothing has changed. Run it again with --propose to send this plan to
|
|
1261
|
+
if (!proposing) { say(markdown ? fence(text) : text); say("Nothing has changed. Run it again with --propose to send this plan to Approvals."); process.exit(2); }
|
|
1111
1262
|
const sent = await tool("submit_plan", { plan: planRef });
|
|
1112
1263
|
if (sent.isError) stop(sent.text);
|
|
1113
1264
|
say(markdown ? `### Proposed\n\n${fence(text)}\n\n${sent.text}` : `${text}\n\n${sent.text}`);
|
|
@@ -1198,7 +1349,7 @@ Then:
|
|
|
1198
1349
|
break;
|
|
1199
1350
|
}
|
|
1200
1351
|
case "submit": {
|
|
1201
|
-
// A plan a change made here, sent to
|
|
1352
|
+
// A plan a change made here, sent to Approvals for an admin to apply.
|
|
1202
1353
|
if (!rest[0]) stop(`Give the plan to send, for example ${ME} submit 1a2b3c4d (the reference a change printed).`);
|
|
1203
1354
|
emit(await tool("submit_plan", { plan: rest[0] }));
|
|
1204
1355
|
break;
|
|
@@ -1209,7 +1360,7 @@ Then:
|
|
|
1209
1360
|
const got = await tool("terminal", { command: commandLine(cmd ? [cmd, ...rest] : rest) });
|
|
1210
1361
|
// A change is only a plan from here. The server's note is written for AI tools; the CLI says what a person can do.
|
|
1211
1362
|
const plan = (/Plan ([0-9a-f]{8})/.exec(got.text) ?? [])[1];
|
|
1212
|
-
emit(plan ? { ...got, text: got.text.replace(/Nothing has changed\. An AI tool cannot apply a change:[^\n]*/, `Nothing has changed. Apply it in the console's terminal (Ctrl+\` on any page, then apply ${plan}), or send it to
|
|
1363
|
+
emit(plan ? { ...got, text: got.text.replace(/Nothing has changed\. An AI tool cannot apply a change:[^\n]*/, `Nothing has changed. Apply it in the console's terminal (Ctrl+\` on any page, then apply ${plan}), or send it to Approvals for an admin with ${ME} submit ${plan}.`) } : got);
|
|
1213
1364
|
}
|
|
1214
1365
|
}
|
|
1215
1366
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@droconnell/agent-inbox-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.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": {
|