@droconnell/agent-inbox-cli 2.5.0 → 2.7.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 +10 -0
- package/agent-inbox.mjs +443 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,6 +66,16 @@ agent-inbox ls unassigned # any console terminal command
|
|
|
66
66
|
agent-inbox help # every command
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
## Run commands from Next's answers
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
cd support && agent-inbox connect # keep it open; Ctrl+C disconnects
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
While `connect` runs, a command in the Assistant's answer in Next gets **Run on** your computer beside Copy. Your
|
|
76
|
+
computer shows what will run and asks `Run it? [y] yes [a] always [n] no` before each one; only `agent-inbox` commands
|
|
77
|
+
from a short list run, only in this folder, with no shell. Admins only.
|
|
78
|
+
|
|
69
79
|
## Update
|
|
70
80
|
|
|
71
81
|
```bash
|
package/agent-inbox.mjs
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
// agent-inbox check [folder] for a pull request: the plan and a rehearsal of it, as markdown (exit 1 needs a look)
|
|
17
17
|
// agent-inbox ci init [folder] write the GitHub workflow that checks pull requests, proposes on merge, and
|
|
18
18
|
// opens a pull request when someone changed the setup in the console
|
|
19
|
+
// agent-inbox ci comment [folder] in that workflow: one pull request comment with what the change does and the
|
|
20
|
+
// answers it changes on recent conversations, before and after (names taken out)
|
|
19
21
|
// agent-inbox diff <file|folder> what the file would change; changes nothing (exit 0 none, 2 some, 1 problems)
|
|
20
22
|
// agent-inbox propose <file|folder> send those changes to Approvals, where an admin applies or discards them
|
|
21
23
|
// (a folder: its Markdown, text and HTML documents, as knowledge articles)
|
|
@@ -24,6 +26,8 @@
|
|
|
24
26
|
// agent-inbox help <command> one terminal command with an example; agent-inbox commands lists them all
|
|
25
27
|
// agent-inbox script <file> [--propose] a file of terminal commands, one per line, as one plan; --propose sends
|
|
26
28
|
// it to Approvals (exit 0 nothing to change, 2 a plan, 1 problems)
|
|
29
|
+
// agent-inbox connect [--name "..."] in your support folder: Next's Assistant may offer to run agent-inbox commands
|
|
30
|
+
// here; each one runs only after you say yes on this computer (Ctrl+C stops it)
|
|
27
31
|
// agent-inbox logout forget the sign-in on this computer
|
|
28
32
|
// agent-inbox update how to update, for how it was installed (a downloaded file updates itself)
|
|
29
33
|
//
|
|
@@ -31,12 +35,12 @@
|
|
|
31
35
|
import { createHash, randomBytes } from "node:crypto";
|
|
32
36
|
import { createServer } from "node:http";
|
|
33
37
|
import { mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, existsSync } from "node:fs";
|
|
34
|
-
import { homedir } from "node:os";
|
|
38
|
+
import { homedir, hostname, platform, userInfo } from "node:os";
|
|
35
39
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
36
40
|
import { spawn, spawnSync } from "node:child_process";
|
|
37
41
|
import { fileURLToPath } from "node:url";
|
|
38
42
|
|
|
39
|
-
export const VERSION = "2.
|
|
43
|
+
export const VERSION = "2.7.0";
|
|
40
44
|
/** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
|
|
41
45
|
export const PACKAGE = "@droconnell/agent-inbox-cli";
|
|
42
46
|
const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
|
|
@@ -90,7 +94,7 @@ const urlArg = take("--url", true);
|
|
|
90
94
|
const tokenArg = take("--token", true);
|
|
91
95
|
/** The CLI's own commands. Anything else is a terminal command, sent as typed. */
|
|
92
96
|
export const OWN = new Set(["login", "logout", "update", "export", "pull", "plan", "diff", "push", "propose", "run", "tail", "script", "check", "ci", "test", "rehearse", "commands", "help", "submit",
|
|
93
|
-
"whoami", "policy", "audit", "mcp", "claude", "init", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
|
|
97
|
+
"whoami", "policy", "audit", "mcp", "claude", "init", "connect", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
|
|
94
98
|
const first = args[0];
|
|
95
99
|
// plan, diff and run are also terminal commands: the CLI's own only for a folder or file that is there (plan, diff) or
|
|
96
100
|
// a quoted command (run "ls unassigned"); otherwise they go to the terminal as typed (diff 40 42, run onboarding).
|
|
@@ -218,7 +222,7 @@ export function splitNext(text) {
|
|
|
218
222
|
|
|
219
223
|
/** Wait for test or rehearsal jobs, asking how each stands every few seconds (asking also moves it along). */
|
|
220
224
|
async function waitJobs(jobs) {
|
|
221
|
-
const lines = [];
|
|
225
|
+
const lines = [], data = [];
|
|
222
226
|
let ok = true;
|
|
223
227
|
for (const { job, agent } of jobs) {
|
|
224
228
|
// A whole day's replay can take a while (a few hundred conversations, twice each); the rest within minutes.
|
|
@@ -234,8 +238,9 @@ async function waitJobs(jobs) {
|
|
|
234
238
|
if (!markdown && process.stderr.isTTY) process.stderr.write("\r".padEnd(81) + "\r");
|
|
235
239
|
if (s.data?.passed === false) ok = false;
|
|
236
240
|
lines.push(`${agent}: ${s.text}`);
|
|
241
|
+
data.push(s.data ?? {});
|
|
237
242
|
}
|
|
238
|
-
return { ok, lines };
|
|
243
|
+
return { ok, lines, data };
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
// ---- CI for a repository of support files --------------------------------------------------------------------------
|
|
@@ -271,7 +276,8 @@ export function ciWorkflow(url, folder) {
|
|
|
271
276
|
- run: ${cli}`;
|
|
272
277
|
const pr = "${{ github.event.pull_request.number }}";
|
|
273
278
|
return `# Next support, written by agent-inbox ci init. The support setup lives in ${dir === "." ? "this repository" : `${dir}/`} (agent-inbox pull).
|
|
274
|
-
# Pull requests: what the change
|
|
279
|
+
# Pull requests: what the change does, and the answers it changes on 10 recent conversations (each answered as things
|
|
280
|
+
# are and with the change), the saved tests and the cost, as one comment, edited on each push. Names are taken out.
|
|
275
281
|
# Merges to main: the changes are proposed in Next's Approvals, for an admin to apply.
|
|
276
282
|
# Nightly: changes someone made in Next's console come back as a pull request, so the two never drift apart. That
|
|
277
283
|
# includes policy.yaml, what every agent may do: a change to it (an agent now allowed to act alone) is a reviewed line.
|
|
@@ -298,18 +304,9 @@ jobs:
|
|
|
298
304
|
runs-on: ubuntu-latest
|
|
299
305
|
steps:
|
|
300
306
|
${setup}
|
|
301
|
-
- name:
|
|
302
|
-
|
|
303
|
-
run:
|
|
304
|
-
set +e
|
|
305
|
-
node agent-inbox.mjs check ${dir} > report.md
|
|
306
|
-
echo "code=$?" >> "$GITHUB_OUTPUT"
|
|
307
|
-
cat report.md >> "$GITHUB_STEP_SUMMARY"
|
|
308
|
-
- name: Comment on the pull request
|
|
309
|
-
env: { GH_TOKEN: "\${{ github.token }}" }
|
|
310
|
-
run: gh pr comment ${pr} --body-file report.md --edit-last || gh pr comment ${pr} --body-file report.md
|
|
311
|
-
- name: Pass or fail
|
|
312
|
-
run: exit \${{ steps.check.outputs.code }}
|
|
307
|
+
- name: How this changes answers
|
|
308
|
+
env: { GITHUB_TOKEN: "\${{ github.token }}" }
|
|
309
|
+
run: node agent-inbox.mjs ci comment ${dir} --on 10 --pr ${pr}
|
|
313
310
|
propose:
|
|
314
311
|
if: github.event_name == 'push'
|
|
315
312
|
runs-on: ubuntu-latest
|
|
@@ -338,6 +335,199 @@ ${setup}
|
|
|
338
335
|
`;
|
|
339
336
|
}
|
|
340
337
|
|
|
338
|
+
// ---- Answer changes on a pull request: agent-inbox ci comment ------------------------------------------------------
|
|
339
|
+
/** The marker the answer-changes comment starts with, so later pushes edit the same comment (found through the API). */
|
|
340
|
+
export const ANSWERS_MARK = "<!-- next-answer-changes -->";
|
|
341
|
+
/** GitHub refuses a comment over 65,536 characters; ours stays well under. */
|
|
342
|
+
const COMMENT_MAX = 60_000;
|
|
343
|
+
|
|
344
|
+
/** Words after "hi" or "I'm" that are not a name. */
|
|
345
|
+
const NOT_A_NAME = /^(there|team|all|everyone|again|so|for|you|both|folks|support|the|next|i|i'm|i’m|a|an|not|very|just|here|sorry|glad|happy|looking|trying|writing|wondering)$/i;
|
|
346
|
+
/**
|
|
347
|
+
* Text fit for a pull request, which more people may read than the console: emails, phone, card and order numbers,
|
|
348
|
+
* long tokens and names in greetings are taken out. Next has already taken out the customer's own name; this is the
|
|
349
|
+
* second look, on this computer, before anything is posted. Pure, so it can be tested.
|
|
350
|
+
*/
|
|
351
|
+
export function redact(text) {
|
|
352
|
+
return String(text ?? "")
|
|
353
|
+
.replace(/\b(bearer|basic)\s+\S+/gi, "$1 [hidden]")
|
|
354
|
+
.replace(/\b(password|passwd|passcode|pin|secret|token|api[_ -]?key|key|code)\b(\s*(?:is|:|=)\s*)\S+/gi, "$1$2[hidden]")
|
|
355
|
+
.replace(/[\w.+-]+@[\w-]+(\.[\w-]+)+/g, "[email]")
|
|
356
|
+
.replace(/\b(?:\d[ -]?){13,19}\b/g, "[card number]")
|
|
357
|
+
.replace(/(?:\+\d{1,3}[ .-]?)?(?:\(\d{2,4}\)[ .-]?)?\d{3,4}[ .-]\d{3,4}(?:[ .-]\d{2,4})?\b/g, "[phone]")
|
|
358
|
+
.replace(/\b(order|invoice|booking|reservation|reference|ref|tracking|shipment|parcel|account|acct|customer)(\s*(?:no\.?|number|num|id|#)?\s*[:#]?\s*)(?=[A-Z0-9-]*\d)[A-Z0-9][A-Z0-9-]{2,}\b/gi, "$1$2[number]")
|
|
359
|
+
.replace(/#\s?[A-Z]{0,3}-?\d{3,}\b/gi, "#[number]")
|
|
360
|
+
.replace(/\b\d{5,}\b/g, "[number]")
|
|
361
|
+
.replace(/\b(?=[A-Za-z0-9_\-]*\d)(?=[A-Za-z0-9_\-]*[A-Za-z])[A-Za-z0-9_\-]{24,}\b/g, "[hidden]")
|
|
362
|
+
// "my name is Ines Duarte", "I'm Sam", then greetings and sign-offs: "Hi Maya,", "Thanks, Leo Park".
|
|
363
|
+
.replace(/\b(my name is|my name's|i am|i'm|i’m|this is)(\s+)(\p{Lu}[\p{L}'-]+)(\s+\p{Lu}[\p{L}'-]+)?/giu, (m, w, gap, first) => (NOT_A_NAME.test(first) ? m : `${w}${gap}[name]`))
|
|
364
|
+
.replace(/\b(hi|hello|hey|dear|thanks|thank you|cheers|regards|best)(,?\s+)(\p{Lu}[\p{L}'-]+)(\s+\p{Lu}[\p{L}'-]+)?/giu, (m, w, gap, first) => (NOT_A_NAME.test(first) ? m : `${w}${gap}[name]`));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Text that can sit in a comment without becoming markup: no HTML (a </details> or the marker), no @mentions (GitHub
|
|
369
|
+
* would notify someone), no links or images, on one line. Applied after redact().
|
|
370
|
+
*/
|
|
371
|
+
export function mdSafe(text, max = 600) {
|
|
372
|
+
let s = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
373
|
+
if (s.length > max) s = `${s.slice(0, max).replace(/\s+\S*$/, "")}…`;
|
|
374
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/@/g, "@")
|
|
375
|
+
.replace(/\[/g, "[").replace(/\]/g, "]").replace(/!/g, "!").replace(/`/g, "`").replace(/\*/g, "*").replace(/_/g, "_").replace(/\|/g, "|");
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** A plan's text as plain lines for people: the table's rows as "section name: change", the notes kept, the hints dropped. */
|
|
379
|
+
export function planLines(plan) {
|
|
380
|
+
const out = [];
|
|
381
|
+
for (const raw of String(plan ?? "").split("\n")) {
|
|
382
|
+
const l = raw.replace(/^Plan [0-9a-f]{4,}: /, "").trim();
|
|
383
|
+
if (!l || /^name\s+change$/.test(l) || /rehearse|submit_plan|Approvals|apply /i.test(l)) continue;
|
|
384
|
+
const cells = l.split(/\s{2,}/);
|
|
385
|
+
out.push(cells.length >= 3 ? `${cells[0]} ${cells[1]}: ${cells.slice(2).join(", ")}` : cells.length === 2 ? `${cells[0]}: ${cells[1]}` : l);
|
|
386
|
+
}
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const KIND_SAID = { handed: "Now handed to a person", answered: "Now answered", acts: "Uses the apps differently", sources: "Answers from other articles" };
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* The one pull request comment: what the change does, how many answers change, each changed answer before and after
|
|
394
|
+
* (collapsed), the tests, the cost, and the link to the rehearsal in Next. Pure, so it can be tested; every text that
|
|
395
|
+
* came from a conversation goes through redact() and mdSafe(). `failed` is true when something needs a look.
|
|
396
|
+
*/
|
|
397
|
+
export function answerComment({ plan = "", changes = 0, policy = null, problems = null, rehearsal = null, passed = null, link = null, skipped = null, blocked = null, on = 10 }) {
|
|
398
|
+
const parts = [ANSWERS_MARK, "## Next: how this pull request changes answers"];
|
|
399
|
+
if (problems) {
|
|
400
|
+
parts.push("### The folder has problems", planLines(problems).map((l) => `- ${mdSafe(l, 400)}`).join("\n"), "**Needs a look before merging.**");
|
|
401
|
+
return { text: parts.join("\n\n") + "\n", failed: true };
|
|
402
|
+
}
|
|
403
|
+
const what = [...planLines(changes ? plan : ""), ...(policy?.changes ? planLines(policy.plan).map((l) => `What the agents may do: ${l}`) : [])];
|
|
404
|
+
parts.push("### What the change does", what.length ? what.slice(0, 40).map((l) => `- ${mdSafe(l, 300)}`).join("\n") + (what.length > 40 ? `\n- …and ${what.length - 40} more` : "") : "Nothing in Next would change: the workspace already matches the folder.");
|
|
405
|
+
if (skipped) parts.push(`> ${mdSafe(skipped, 500)}`);
|
|
406
|
+
if (blocked) parts.push("### Could not rehearse", mdSafe(blocked, 500));
|
|
407
|
+
const a = rehearsal?.answers;
|
|
408
|
+
if (rehearsal && a) {
|
|
409
|
+
parts.push(`### Answers that change: ${a.changed} of ${a.total}`,
|
|
410
|
+
`Each of ${a.total} recent conversations was answered twice in test copies, as things are now and with this change, so what differs is the change's doing. Wording differs every time, so only these count: now handed to a person, now answered, apps used differently, or answered from other articles.`);
|
|
411
|
+
for (const it of a.items) {
|
|
412
|
+
const ref = it.ref && /^#\d+$/.test(it.ref) ? `<b>${it.ref}</b> · ` : "";
|
|
413
|
+
parts.push(`<details><summary>${ref}${KIND_SAID[it.kind] ?? "Changed"} · “${mdSafe(redact(it.question), 120)}”</summary>\n\n**As things are:** ${mdSafe(redact(it.before))}\n\n**With the change:** ${mdSafe(redact(it.after))}\n\n</details>`);
|
|
414
|
+
}
|
|
415
|
+
if (a.changed > a.items.length) parts.push(`…and ${a.changed - a.items.length} more, in Next.`);
|
|
416
|
+
} else if (rehearsal) {
|
|
417
|
+
parts.push(`### Answers: ${rehearsal.replay.answered} of ${rehearsal.replay.total} answered with the change (${rehearsal.replay.before} were answered at the time)`);
|
|
418
|
+
}
|
|
419
|
+
if (rehearsal?.tests) {
|
|
420
|
+
const tt = rehearsal.tests;
|
|
421
|
+
parts.push(`### Tests\n\n${tt.after} of ${tt.total} pass with the change (${tt.before} as things are now)${tt.worse ? `; ${tt.worse} now ${tt.worse === 1 ? "fails" : "fail"}` : ""}.`);
|
|
422
|
+
}
|
|
423
|
+
if (rehearsal) {
|
|
424
|
+
const where = link && /^https:\/\/[^\s<>()]+$/.test(link) ? ` [Open the rehearsal in Next](${link}) (for people in the workspace).` : "";
|
|
425
|
+
parts.push(`Cost: $${Number(rehearsal.usd ?? 0).toFixed(2)}, charged as tests.${where}`);
|
|
426
|
+
}
|
|
427
|
+
const failed = Boolean(blocked || (rehearsal && passed === false));
|
|
428
|
+
if (failed) parts.push("**Needs a look before merging.**");
|
|
429
|
+
else if (changes || policy?.changes) parts.push("Merging proposes these changes in Next's **Approvals**, where an admin applies them.");
|
|
430
|
+
parts.push(`<sub>Customer names, emails, phone and order numbers are taken out. This comment is updated on each push.${rehearsal ? "" : ` Rehearsed on ${on} conversations when there is something to rehearse.`}</sub>`);
|
|
431
|
+
let text = parts.join("\n\n") + "\n";
|
|
432
|
+
if (text.length > COMMENT_MAX) text = `${text.slice(0, COMMENT_MAX - 200)}\n\n…cut short: the rest is in Next.\n`;
|
|
433
|
+
return { text, failed };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** The pull request's number in a GitHub Actions run: --pr, or the event that started it. */
|
|
437
|
+
export function prNumber(given, eventPath = process.env.GITHUB_EVENT_PATH, read = (p) => readFileSync(p, "utf8")) {
|
|
438
|
+
if (given && /^\d+$/.test(String(given))) return Number(given);
|
|
439
|
+
try { const n = JSON.parse(read(eventPath))?.pull_request?.number; return Number.isInteger(n) ? n : null; } catch { return null; }
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Post the comment, or edit the one already there: the pull request's comments are read a page at a time until one
|
|
444
|
+
* starts with the marker (this one, or check's older one), and that one is edited, so a pull request has one comment.
|
|
445
|
+
* `fetcher` is fetch, passed in so a test can stand in for GitHub.
|
|
446
|
+
*/
|
|
447
|
+
export async function postComment({ fetcher = fetch, token, repo, pr, body, api = "https://api.github.com", marks = [ANSWERS_MARK, CHECK_MARK] }) {
|
|
448
|
+
const headers = { authorization: `Bearer ${token}`, accept: "application/vnd.github+json", "x-github-api-version": "2022-11-28", "user-agent": UA, "content-type": "application/json" };
|
|
449
|
+
const base = `${api.replace(/\/+$/, "")}/repos/${repo}`;
|
|
450
|
+
let found = null;
|
|
451
|
+
for (let page = 1; page <= 30 && !found; page++) {
|
|
452
|
+
const r = await fetcher(`${base}/issues/${pr}/comments?per_page=100&page=${page}`, { headers });
|
|
453
|
+
if (!r.ok) return { ok: false, status: r.status };
|
|
454
|
+
const list = await r.json();
|
|
455
|
+
found = list.find((c) => marks.some((m) => String(c.body ?? "").startsWith(m))) ?? null;
|
|
456
|
+
if (list.length < 100) break;
|
|
457
|
+
}
|
|
458
|
+
const r = found
|
|
459
|
+
? await fetcher(`${base}/issues/comments/${found.id}`, { method: "PATCH", headers, body: JSON.stringify({ body }) })
|
|
460
|
+
: await fetcher(`${base}/issues/${pr}/comments`, { method: "POST", headers, body: JSON.stringify({ body }) });
|
|
461
|
+
if (!r.ok) return { ok: false, status: r.status };
|
|
462
|
+
const made = await r.json().catch(() => ({}));
|
|
463
|
+
return { ok: true, action: found ? "updated" : "created", url: made.html_url ?? null };
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* agent-inbox ci comment [folder] [--on 10] [--pr n] [--print]: in a pull request's workflow, plan the folder (and
|
|
468
|
+
* policy.yaml), rehearse the change on recent conversations with each answered as things are and with it, and post one
|
|
469
|
+
* comment on the pull request, edited on later pushes. Exit 1 when something needs a look; 0 otherwise, including when
|
|
470
|
+
* rehearsals are switched off (the comment says so).
|
|
471
|
+
*/
|
|
472
|
+
async function ciComment(words) {
|
|
473
|
+
const opt = (name) => { const i = words.indexOf(`--${name}`); return i >= 0 && words[i + 1] && !words[i + 1].startsWith("--") ? words[i + 1] : undefined; };
|
|
474
|
+
const dir = words.find((a, i) => !a.startsWith("--") && !(i > 0 && words[i - 1].startsWith("--") && words[i - 1] !== "--print")) || ".";
|
|
475
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory() || !isPulled(dir)) stop(`${dir} is not a folder from ${ME} pull (it has no workspace.yaml).`);
|
|
476
|
+
const asked = Number(opt("on") ?? 10);
|
|
477
|
+
const on = Number.isInteger(asked) && asked > 0 ? Math.min(asked, 30) : 10;
|
|
478
|
+
const progress = (s) => { if (process.stderr.isTTY || process.env.CI) process.stderr.write(`${s}\n`); };
|
|
479
|
+
|
|
480
|
+
progress("Planning the folder");
|
|
481
|
+
const { text, data } = await planFolder(dir);
|
|
482
|
+
const plan = text.replace(/\n*(Nothing has changed|This token can only look)[\s\S]*$/, "").replace(/\n+Before +rehearse [^\n]*/g, "").trim();
|
|
483
|
+
let comment;
|
|
484
|
+
let target = null, policy = null;
|
|
485
|
+
if (!data?.ok) comment = answerComment({ problems: plan });
|
|
486
|
+
else {
|
|
487
|
+
// policy.yaml, when the folder keeps one: a change to what the agents may do is part of the change too.
|
|
488
|
+
const policyFile = join(dir, POLICY_FILE);
|
|
489
|
+
if (existsSync(policyFile)) {
|
|
490
|
+
const got = await tool("plan_policy", { file: readFileSync(policyFile, "utf8") });
|
|
491
|
+
if (got.data?.ok && got.data.changes) policy = { changes: got.data.changes, plan: got.text.replace(/\n*(Nothing has changed|This token can only look)[\s\S]*?(?=\n\nNot changed by the file|$)/, "").trim(), ref: got.data.plan };
|
|
492
|
+
}
|
|
493
|
+
target = data.changes ? data.plan : policy?.ref ?? null;
|
|
494
|
+
let rehearsal = null, passed = null, link = null, skipped = null, blocked = null;
|
|
495
|
+
if (target) {
|
|
496
|
+
progress(`Rehearsing the change on ${on} recent conversations, each answered as things are and with it`);
|
|
497
|
+
const r = await tool("rehearse", { plan: target, conversations: on, compare: true });
|
|
498
|
+
if (r.isError && /are off|look-only|can only look/i.test(r.text)) skipped = `Answers were not rehearsed: ${r.text.replace(/\.?$/, ".")} The setting is Tests and rehearsals from CI and AI tools, on Settings, AI features in Next.`;
|
|
499
|
+
else if (r.isError && /nothing to rehearse|does not change what/i.test(r.text)) skipped = `Not rehearsed: ${r.text}`;
|
|
500
|
+
else if (r.isError) blocked = r.text;
|
|
501
|
+
else if (r.data?.job) {
|
|
502
|
+
const done = await waitJobs([{ job: r.data.job, agent: "This change" }]);
|
|
503
|
+
const last = done.data[0] ?? {};
|
|
504
|
+
rehearsal = last.rehearsal ?? null; passed = done.ok; link = last.link ?? r.data.link ?? null;
|
|
505
|
+
if (!rehearsal) blocked = done.lines.join("\n");
|
|
506
|
+
}
|
|
507
|
+
if (data.changes && policy?.changes && !skipped && !blocked) skipped = "The change to policy.yaml is shown above but not rehearsed: one plan is rehearsed at a time, and this one is the folder's.";
|
|
508
|
+
}
|
|
509
|
+
comment = answerComment({ plan, changes: data.changes, policy, rehearsal, passed, link, skipped, blocked, on });
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// Where it goes: the pull request (in GitHub Actions, with the workflow's token), the run's summary, or the screen.
|
|
513
|
+
if (process.env.GITHUB_STEP_SUMMARY) { try { writeFileSync(process.env.GITHUB_STEP_SUMMARY, comment.text, { flag: "a" }); } catch {} }
|
|
514
|
+
const pr = prNumber(opt("pr"));
|
|
515
|
+
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
516
|
+
const repo = process.env.GITHUB_REPOSITORY;
|
|
517
|
+
if (words.includes("--print") || !token || !repo || !pr) {
|
|
518
|
+
say(comment.text);
|
|
519
|
+
if (!words.includes("--print")) process.stderr.write(`agent-inbox: printed the comment instead of posting it: ${!pr ? "no pull request number (run it on a pull_request event, or give --pr)" : "no GITHUB_TOKEN and GITHUB_REPOSITORY (the workflow gives both)"}.\n`);
|
|
520
|
+
} else {
|
|
521
|
+
const posted = await postComment({ token, repo, pr, body: comment.text, api: process.env.GITHUB_API_URL || "https://api.github.com" }).catch(() => ({ ok: false, status: 0 }));
|
|
522
|
+
if (posted.ok) say(`${posted.action === "updated" ? "Updated" : "Posted"} the comment on pull request #${pr}${posted.url ? `: ${posted.url}` : ""}.`);
|
|
523
|
+
else {
|
|
524
|
+
say(comment.text);
|
|
525
|
+
process.stderr.write(`agent-inbox: GitHub did not take the comment (${posted.status === 403 ? "the workflow needs pull-requests: write, and pull requests from forks get a read-only token" : posted.status ? `it answered ${posted.status}` : "no answer"}). It is in the run's summary instead.\n`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
process.exit(comment.failed ? 1 : 0);
|
|
529
|
+
}
|
|
530
|
+
|
|
341
531
|
// ---- Knowledge from this computer ----------------------------------------------------------------------------------
|
|
342
532
|
const DOCS = [".md", ".markdown", ".txt", ".html", ".htm"];
|
|
343
533
|
const posix = (p) => p.split(sep).join("/");
|
|
@@ -568,6 +758,7 @@ const USAGE = [
|
|
|
568
758
|
['run "<command>"', 'the same, in quotes, such as "ls unassigned --inbox Billing"'],
|
|
569
759
|
["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)"],
|
|
570
760
|
["ci init [folder] [--force]", "write a GitHub workflow: check pull requests, propose on merge, and open a pull request when the console changed"],
|
|
761
|
+
["ci comment [folder] [--on 10] [--pr n] [--print]", "in a pull request's workflow: one comment with what the change does and the answers it changes, before and after (costs money)"],
|
|
571
762
|
["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)"],
|
|
572
763
|
["script <file> [--propose]", "commands, one per line, as one plan; --propose sends it to Approvals"],
|
|
573
764
|
["submit <plan>", "send a plan a change printed to Approvals, for an admin to apply (the CLI never applies)"],
|
|
@@ -589,6 +780,7 @@ const USAGE = [
|
|
|
589
780
|
["listen --forward <address> [--events a,b]", "Next's webhooks, signed as usual, sent to a server on this computer while it runs"],
|
|
590
781
|
["mcp", "an MCP server over stdio for any AI tool, using this computer's sign-in"],
|
|
591
782
|
["claude [--project]", "add Next to Claude Code (or write .mcp.json for this project)"],
|
|
783
|
+
["connect [--name \"Maya's MacBook\"]", "in your support folder: the Assistant may offer to run agent-inbox commands here, each after you say yes (Ctrl+C stops)"],
|
|
592
784
|
["app ls | why <app> | logs <app> [--follow]", "apps: their health, and their runs as they happen"],
|
|
593
785
|
["app try <app> <tool> [--input JSON]", "run an app's tool that only reads, on its latest version"],
|
|
594
786
|
["app fix <app> [--claude]", "its recent failures as a request to fix (--claude hands it to Claude Code here)"],
|
|
@@ -1010,6 +1202,234 @@ async function appCommand(words) {
|
|
|
1010
1202
|
}
|
|
1011
1203
|
}
|
|
1012
1204
|
|
|
1205
|
+
// ---- Run on your computer: agent-inbox connect ----------------------------------------------------------------------
|
|
1206
|
+
/**
|
|
1207
|
+
* The commands Next may ask this computer to run, and whether the person may choose Always for one. The same list as
|
|
1208
|
+
* RUNNABLE in src/lib/computer-commands.ts on the server (src/lib/computer-commands.test.ts checks they agree), kept
|
|
1209
|
+
* here too so this computer checks every request itself: a server that was tricked still cannot widen it. Always is
|
|
1210
|
+
* only for commands that neither change Next nor cost money.
|
|
1211
|
+
*/
|
|
1212
|
+
export const RUNNABLE = {
|
|
1213
|
+
pull: { always: true, path: "optional" },
|
|
1214
|
+
plan: { always: true, path: "optional" },
|
|
1215
|
+
"policy check": { always: true, path: "optional" },
|
|
1216
|
+
"policy pull": { always: true, path: "optional" },
|
|
1217
|
+
"policy plan": { always: true, path: "optional" },
|
|
1218
|
+
whoami: { always: true },
|
|
1219
|
+
push: { always: false, path: "optional", flags: { "--prune": "flag" } },
|
|
1220
|
+
propose: { always: false, path: "required" },
|
|
1221
|
+
"policy push": { always: false, path: "optional" },
|
|
1222
|
+
check: { always: false, path: "optional", flags: { "--on": "count" } },
|
|
1223
|
+
test: { always: false },
|
|
1224
|
+
"ci init": { always: false, path: "optional" },
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1227
|
+
/** A folder or file inside the connected folder: `.`, or plain names that do not start with a dot. Never /, ~ or .. */
|
|
1228
|
+
export function insidePath(p) {
|
|
1229
|
+
if (typeof p !== "string" || p.length === 0 || p.length > 200) return false;
|
|
1230
|
+
return /^(\.|[A-Za-z0-9_][A-Za-z0-9._-]*)(\/[A-Za-z0-9_][A-Za-z0-9._-]*)*\/?$/.test(p);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* The CLI's own words to run for a request from Next (its command's name and words), checked against RUNNABLE: such
|
|
1235
|
+
* as ["pull", "."] or ["policy", "check"]. Null for anything else, which is refused without asking.
|
|
1236
|
+
*/
|
|
1237
|
+
export function runnable(sub, args) {
|
|
1238
|
+
if (typeof sub !== "string" || !Object.hasOwn(RUNNABLE, sub) || !Array.isArray(args) || args.length > 4) return null;
|
|
1239
|
+
if (!args.every((a) => typeof a === "string")) return null;
|
|
1240
|
+
const kind = RUNNABLE[sub];
|
|
1241
|
+
let path = null;
|
|
1242
|
+
const flags = [];
|
|
1243
|
+
for (let i = 0; i < args.length; i++) {
|
|
1244
|
+
const a = args[i];
|
|
1245
|
+
if (a.startsWith("-")) {
|
|
1246
|
+
const f = kind.flags?.[a];
|
|
1247
|
+
if (!f || flags.includes(a)) return null;
|
|
1248
|
+
if (f === "count") {
|
|
1249
|
+
const n = args[i + 1];
|
|
1250
|
+
if (!n || !/^[1-9]\d?$/.test(n) || Number(n) > 30) return null;
|
|
1251
|
+
flags.push(a, n); i++;
|
|
1252
|
+
} else flags.push(a);
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
if (!kind.path || path !== null || !insidePath(a)) return null;
|
|
1256
|
+
path = a;
|
|
1257
|
+
}
|
|
1258
|
+
if (kind.path === "required" && path === null) return null;
|
|
1259
|
+
return [...sub.split(" "), ...(path === null ? [] : [path]), ...flags];
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/** Text from Next shown in this terminal: no control characters, so nothing sent can move the cursor or recolour the screen. */
|
|
1263
|
+
export const plainText = (s, max = 120) => String(s ?? "").replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u2028-\u202e]/g, "").slice(0, max);
|
|
1264
|
+
|
|
1265
|
+
/** Whether a path the command names stays inside the folder, following any links on the way (a link out is refused). */
|
|
1266
|
+
export function staysInside(folder, p) {
|
|
1267
|
+
const root = real(folder);
|
|
1268
|
+
let at = resolve(root, p);
|
|
1269
|
+
// The part that exists, with its links followed; what is not there yet can only be made under it.
|
|
1270
|
+
const rest = [];
|
|
1271
|
+
while (!existsSync(at) && dirname(at) !== at) { rest.unshift(basename(at)); at = dirname(at); }
|
|
1272
|
+
const whole = join(real(at), ...rest);
|
|
1273
|
+
const rel = relative(root, whole);
|
|
1274
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/** What this computer calls itself in Next: Maya's MacBook Pro from Mayas-MacBook-Pro, or Maya's Mac when it has no useful name. */
|
|
1278
|
+
export function computerName(host = hostname(), user = (() => { try { return userInfo().username; } catch { return ""; } })(), os = platform()) {
|
|
1279
|
+
const h = String(host ?? "").replace(/\.(local|lan|home|localdomain)$/i, "").split(".")[0];
|
|
1280
|
+
const kind = os === "darwin" ? "Mac" : os === "win32" ? "PC" : "computer";
|
|
1281
|
+
const owner = user ? user.charAt(0).toUpperCase() + user.slice(1) : "";
|
|
1282
|
+
if (!h || /^(localhost|[0-9a-f]{8,})$/i.test(h)) return owner ? `${owner}'s ${kind}` : `This ${kind}`;
|
|
1283
|
+
const m = /^([A-Za-z]+?)s-(.+)$/.exec(h);
|
|
1284
|
+
if (m && /^(macbook|imac|mac|pc|laptop|desktop|surface|thinkpad)/i.test(m[2])) return `${m[1].charAt(0).toUpperCase() + m[1].slice(1)}'s ${m[2].replace(/-/g, " ")}`;
|
|
1285
|
+
return h.replace(/-/g, " ");
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/** A command's outcome from how the CLI ended: 0 is done, 2 is done with a plan or changes to show, anything else a problem. */
|
|
1289
|
+
export const runEnded = (code) => (code === 0 || code === 2 ? "done" : "failed");
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* agent-inbox connect: keep a line open from this computer to Next, so the Assistant can offer to run agent-inbox
|
|
1293
|
+
* commands in this support folder. Next only ever sends a command's name and words from the list above; this computer
|
|
1294
|
+
* checks them again, shows exactly what will run, where and who asked, and runs it only after you answer here (never in
|
|
1295
|
+
* the browser). It runs this CLI's own code, without a shell, in this folder only. Ctrl+C disconnects.
|
|
1296
|
+
*/
|
|
1297
|
+
async function connect(words) {
|
|
1298
|
+
const folder = real(process.cwd());
|
|
1299
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) stop("connect asks you before every command it runs, so it needs a terminal you can type in.");
|
|
1300
|
+
if (folder === real(homedir()) || dirname(folder) === folder) stop(`Run connect in your support folder (the one ${ME} init or pull made), not in your home folder.`);
|
|
1301
|
+
if (!isPulled(folder)) stop(`This is not a support folder: it has no workspace.yaml. Run connect in the folder ${ME} init or pull made, such as support.`);
|
|
1302
|
+
const me = await tool("whoami");
|
|
1303
|
+
if (me.isError || !me.data) stop(me.text || `The sign-in did not work. Run ${ME} login again.`);
|
|
1304
|
+
const { url } = await access();
|
|
1305
|
+
const name = plainText(valueOf(words, "--name") || computerName(), 80);
|
|
1306
|
+
const shown = folder.startsWith(homedir() + sep) ? `~${folder.slice(homedir().length)}` : folder;
|
|
1307
|
+
const always = new Set();
|
|
1308
|
+
|
|
1309
|
+
/** One call on the line. Network trouble comes back as null, so the loop can wait and try again. */
|
|
1310
|
+
const line = async (method, body, search = "") => {
|
|
1311
|
+
const { url: at, token } = await access();
|
|
1312
|
+
let r;
|
|
1313
|
+
try {
|
|
1314
|
+
r = await fetch(`${at}/api/cli/computer${search}`, { method, headers: { authorization: `Bearer ${token}`, "content-type": "application/json", "user-agent": UA }, ...(body ? { body: JSON.stringify(body) } : {}), signal: AbortSignal.timeout(45_000) });
|
|
1315
|
+
} catch { return null; }
|
|
1316
|
+
if (r.status === 401) stop(`Your sign-in was refused. Run ${ME} login again, then connect.`);
|
|
1317
|
+
if (r.status === 403) stop("Only an admin of the workspace can connect a computer.");
|
|
1318
|
+
if (r.status === 404) stop(`${at} does not have Run on your computer yet. It needs a newer Next.`);
|
|
1319
|
+
if (r.status >= 500) return null;
|
|
1320
|
+
return { status: r.status, data: await r.json().catch(() => ({})) };
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
const hello = await line("POST", { action: "connect", name, folder: shown, version: VERSION, always: [] });
|
|
1324
|
+
if (!hello) stop(`Could not reach ${url}. Check your connection and try again.`);
|
|
1325
|
+
if (hello.status !== 200 || !hello.data?.id) stop(hello.data?.error || "Next did not accept this computer. Try again.");
|
|
1326
|
+
const { id, line: lineId } = hello.data;
|
|
1327
|
+
const clock = () => new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
|
1328
|
+
say(`${clock()} Connected to ${new URL(url).host} as ${plainText(me.data.user)}`);
|
|
1329
|
+
say(`This computer shows in Next as "${name}", for ${folder}.\nWhen ${plainText(me.data.workspace)}'s Assistant offers to run an agent-inbox command, it asks you here first. Ctrl+C disconnects.`);
|
|
1330
|
+
|
|
1331
|
+
const rl = (await import("node:readline")).createInterface({ input: process.stdin, output: process.stdout });
|
|
1332
|
+
let child = null, leaving = false;
|
|
1333
|
+
const leave = async (why) => {
|
|
1334
|
+
if (leaving) return;
|
|
1335
|
+
leaving = true;
|
|
1336
|
+
if (child) child.kill();
|
|
1337
|
+
if (why) say(`\n${why}`);
|
|
1338
|
+
await line("POST", { action: "leave", id, line: lineId }).catch(() => {});
|
|
1339
|
+
rl.close();
|
|
1340
|
+
process.exit(0);
|
|
1341
|
+
};
|
|
1342
|
+
// Ctrl+C typed here reaches readline; a signal from elsewhere (kill, the window closing) reaches the process.
|
|
1343
|
+
rl.on("SIGINT", () => void leave("Disconnected. Next shows this computer as offline."));
|
|
1344
|
+
process.on("SIGINT", () => void leave("Disconnected. Next shows this computer as offline."));
|
|
1345
|
+
process.on("SIGTERM", () => void leave(""));
|
|
1346
|
+
process.on("SIGHUP", () => void leave(""));
|
|
1347
|
+
const question = (q) => new Promise((ok) => rl.question(q, (a) => ok(a.trim().toLowerCase())));
|
|
1348
|
+
|
|
1349
|
+
/** Tell Next how a run stands; tries a few times. False when Next refused it (the run ended there meanwhile). */
|
|
1350
|
+
const report = async (run, body) => {
|
|
1351
|
+
for (let i = 0; i < 5; i++) {
|
|
1352
|
+
const r = await line("POST", { action: "report", id, line: lineId, run: run.id, ...body });
|
|
1353
|
+
if (r) return r.status === 200;
|
|
1354
|
+
await new Promise((ok) => setTimeout(ok, 1000 * (i + 1)));
|
|
1355
|
+
}
|
|
1356
|
+
return false;
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
/** One request: check it, show it, ask, then run this CLI with its words in this folder, and send back what it printed. */
|
|
1360
|
+
const handle = async (run) => {
|
|
1361
|
+
const argv = runnable(run.sub, run.args);
|
|
1362
|
+
const command = `agent-inbox ${argv ? argv.join(" ") : plainText(run.sub, 40)}`;
|
|
1363
|
+
// A request from before this computer reconnected says how old it is, so an earlier ask is not mistaken for a new one.
|
|
1364
|
+
const ago = Math.floor((Date.now() - Date.parse(run.askedAt)) / 60_000);
|
|
1365
|
+
const when = ago >= 1 ? ` ${ago} minute${ago === 1 ? "" : "s"} ago` : "";
|
|
1366
|
+
say(`\n${clock()} ${plainText(run.from, 40)} wants to run, asked by ${plainText(run.askedBy, 60)}${when}:\n\n ${command}\n in ${folder}\n`);
|
|
1367
|
+
// The folder or file it names comes right after the command's own words (runnable puts it there), before any option.
|
|
1368
|
+
const named = argv?.[run.sub.split(" ").length];
|
|
1369
|
+
const path = named && !named.startsWith("-") ? named : ".";
|
|
1370
|
+
if (!argv || !staysInside(folder, path)) {
|
|
1371
|
+
say("Not run: this computer only runs agent-inbox commands from its list, in this folder.");
|
|
1372
|
+
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" });
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
let approved = always.has(run.sub) ? "always" : null;
|
|
1376
|
+
if (approved) say(`Running: you chose Always for ${run.sub} while connected.`);
|
|
1377
|
+
while (!approved) {
|
|
1378
|
+
const canAlways = RUNNABLE[run.sub].always;
|
|
1379
|
+
const a = await question(`Run it? [y] yes ${canAlways ? `[a] always for ${run.sub} ` : ""}[n] no › `);
|
|
1380
|
+
if (a === "y" || a === "yes") approved = "once";
|
|
1381
|
+
else if (canAlways && (a === "a" || a === "always")) { approved = "always"; always.add(run.sub); }
|
|
1382
|
+
else if (a === "n" || a === "no") break;
|
|
1383
|
+
else say(canAlways ? "Type y, a or n, then Enter." : "Type y or n, then Enter.");
|
|
1384
|
+
}
|
|
1385
|
+
if (!approved) { say("Not run."); await report(run, { status: "declined" }); return; }
|
|
1386
|
+
if (!(await report(run, { status: "running", approved }))) { say("Not run: the request ended in Next before you answered (after 10 minutes, or it was disconnected). Ask again from Next."); return; }
|
|
1387
|
+
const started = Date.now();
|
|
1388
|
+
let pending = "";
|
|
1389
|
+
const flush = async () => { if (!pending) return; const chunk = pending; pending = ""; await report(run, { status: "running", output: chunk }); };
|
|
1390
|
+
const timer = setInterval(() => void flush(), 1000);
|
|
1391
|
+
const code = await new Promise((done) => {
|
|
1392
|
+
// This CLI's own code with the checked words, in this folder, without a shell: nothing can be added to the line.
|
|
1393
|
+
child = spawn(process.execPath, [SELF, ...argv], { cwd: folder, shell: false, windowsHide: true, stdio: ["ignore", "pipe", "pipe"], env: { ...process.env, NO_COLOR: "1" } });
|
|
1394
|
+
const take = (b) => { const s = b.toString("utf8"); process.stdout.write(s); pending += s; };
|
|
1395
|
+
child.stdout.on("data", take); child.stderr.on("data", take);
|
|
1396
|
+
const limit = setTimeout(() => { pending += "\nStopped after 20 minutes.\n"; child?.kill(); }, 20 * 60_000);
|
|
1397
|
+
child.on("error", () => { clearTimeout(limit); done(-1); });
|
|
1398
|
+
child.on("close", (c) => { clearTimeout(limit); done(c ?? -1); });
|
|
1399
|
+
});
|
|
1400
|
+
child = null;
|
|
1401
|
+
clearInterval(timer);
|
|
1402
|
+
const ended = runEnded(code);
|
|
1403
|
+
const output = pending; pending = "";
|
|
1404
|
+
await report(run, { status: ended, exitCode: code, output });
|
|
1405
|
+
say(`${ended === "done" ? "Done" : "Stopped with a problem"} in ${Math.max(1, Math.round((Date.now() - started) / 1000))} s. Next shows the result.`);
|
|
1406
|
+
};
|
|
1407
|
+
|
|
1408
|
+
// The line: ask for work again and again (each ask waits up to 25 seconds). Requests are handled one at a time.
|
|
1409
|
+
const queue = [];
|
|
1410
|
+
let working = false;
|
|
1411
|
+
const work = async () => {
|
|
1412
|
+
if (working) return;
|
|
1413
|
+
working = true;
|
|
1414
|
+
while (queue.length) await handle(queue.shift()).catch(() => say("That run could not finish. Next shows it as stopped."));
|
|
1415
|
+
working = false;
|
|
1416
|
+
};
|
|
1417
|
+
let lostSince = 0;
|
|
1418
|
+
for (;;) {
|
|
1419
|
+
const got = await line("GET", null, `?id=${id}&line=${lineId}&wait=25000&always=${encodeURIComponent([...always].join(","))}`);
|
|
1420
|
+
if (!got || got.status !== 200) {
|
|
1421
|
+
if (!lostSince) { lostSince = Date.now(); say(`${clock()} Lost the line to Next. Trying again…`); }
|
|
1422
|
+
if (Date.now() - lostSince > 10 * 60_000) await leave("Could not reach Next for 10 minutes, so this computer disconnected. Run connect again.");
|
|
1423
|
+
await new Promise((ok) => setTimeout(ok, 5000));
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
if (lostSince) { lostSince = 0; say(`${clock()} Back in touch with Next.`); }
|
|
1427
|
+
if (got.data?.gone) await leave("Disconnected in Next (Settings, Terminal). Run connect again to reconnect.");
|
|
1428
|
+
if (got.data?.replaced) { leaving = true; say("\nconnect was started again for this folder, so this one stopped."); rl.close(); process.exit(0); }
|
|
1429
|
+
if (got.data?.run) { queue.push(got.data.run); void work(); }
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1013
1433
|
// ---- Shell completion ----------------------------------------------------------------------------------------------
|
|
1014
1434
|
export function completionScript(shell, me = "agent-inbox") {
|
|
1015
1435
|
if (shell === "bash") return `# ${me} completion for bash: add to ~/.bashrc: eval "$(${me} completion bash)"
|
|
@@ -1086,6 +1506,7 @@ switch (cmd) {
|
|
|
1086
1506
|
case "mcp": await mcpServer(); break;
|
|
1087
1507
|
case "claude": await claudeSetup(rest.includes("--project")); break;
|
|
1088
1508
|
case "init": await init(rest); break;
|
|
1509
|
+
case "connect": await connect(rest); break;
|
|
1089
1510
|
case "app": await appCommand(rest); break;
|
|
1090
1511
|
case "events": { const only = (valueOf(rest, "--only") ?? "").split(",").filter(Boolean); await events(only.length ? only : null); break; }
|
|
1091
1512
|
case "listen": await listen(valueOf(rest, "--forward"), valueOf(rest, "--events")?.split(",").filter(Boolean)); break;
|
|
@@ -1287,8 +1708,10 @@ switch (cmd) {
|
|
|
1287
1708
|
process.exit(report.failed ? 1 : 0);
|
|
1288
1709
|
}
|
|
1289
1710
|
case "ci": {
|
|
1711
|
+
// ci comment [folder]: the pull request's comment on how the change moves answers (prd/answer-diffs.md).
|
|
1712
|
+
if (rest[0] === "comment") { await ciComment(rest.slice(1)); break; }
|
|
1290
1713
|
// ci init [folder]: write the GitHub workflow for a repository of support files.
|
|
1291
|
-
if (rest[0] !== "init") stop(`Use ${ME} ci init [folder], in the repository that holds the folder from ${ME} pull.`);
|
|
1714
|
+
if (rest[0] !== "init") stop(`Use ${ME} ci init [folder], in the repository that holds the folder from ${ME} pull, or ${ME} ci comment [folder] in its pull request workflow.`);
|
|
1292
1715
|
const dir = rest[1] || ".";
|
|
1293
1716
|
if (!existsSync(dir) || !statSync(dir).isDirectory() || !isPulled(dir)) stop(`${dir} is not a folder from ${ME} pull (it has no workspace.yaml). Run ${ME} pull ${dir} first.`);
|
|
1294
1717
|
const { url } = await access();
|
|
@@ -1301,7 +1724,7 @@ switch (cmd) {
|
|
|
1301
1724
|
Then:
|
|
1302
1725
|
1. In Next, an admin makes a personal access token set to Look and propose changes (Settings, Terminal, Plain English and AI tools).
|
|
1303
1726
|
2. In GitHub, add it as the repository secret AGENT_INBOX_TOKEN.
|
|
1304
|
-
3. Commit and push the workflow. Each pull request that changes ${dir === "." ? "the folder" : dir} gets
|
|
1727
|
+
3. Commit and push the workflow. Each pull request that changes ${dir === "." ? "the folder" : dir} gets one comment: what it does and the answers it changes.
|
|
1305
1728
|
4. For rehearsals on pull requests, an admin turns on Tests and rehearsals from CI and AI tools (Settings, AI features). They are charged as tests.`);
|
|
1306
1729
|
break;
|
|
1307
1730
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@droconnell/agent-inbox-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.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": {
|