@droconnell/agent-inbox-cli 2.6.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-inbox.mjs +471 -19
- package/package.json +1 -1
package/agent-inbox.mjs
CHANGED
|
@@ -13,9 +13,13 @@
|
|
|
13
13
|
// agent-inbox plan [folder] what the changed folder would change; changes nothing (exit 0 none, 2 some, 1 problems)
|
|
14
14
|
// agent-inbox push [folder] [--prune] send those changes to Approvals; --prune also removes articles and tests
|
|
15
15
|
// whose files you deleted
|
|
16
|
+
// agent-inbox dev [agent] in your support folder: talk to the agent as the folder's unpushed files have
|
|
17
|
+
// it; each save reloads it; --replay <ticket> answers a past conversation again
|
|
16
18
|
// agent-inbox check [folder] for a pull request: the plan and a rehearsal of it, as markdown (exit 1 needs a look)
|
|
17
19
|
// agent-inbox ci init [folder] write the GitHub workflow that checks pull requests, proposes on merge, and
|
|
18
20
|
// opens a pull request when someone changed the setup in the console
|
|
21
|
+
// agent-inbox ci comment [folder] in that workflow: one pull request comment with what the change does and the
|
|
22
|
+
// answers it changes on recent conversations, before and after (names taken out)
|
|
19
23
|
// agent-inbox diff <file|folder> what the file would change; changes nothing (exit 0 none, 2 some, 1 problems)
|
|
20
24
|
// agent-inbox propose <file|folder> send those changes to Approvals, where an admin applies or discards them
|
|
21
25
|
// (a folder: its Markdown, text and HTML documents, as knowledge articles)
|
|
@@ -38,7 +42,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
|
|
|
38
42
|
import { spawn, spawnSync } from "node:child_process";
|
|
39
43
|
import { fileURLToPath } from "node:url";
|
|
40
44
|
|
|
41
|
-
export const VERSION = "2.
|
|
45
|
+
export const VERSION = "2.9.0";
|
|
42
46
|
/** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
|
|
43
47
|
export const PACKAGE = "@droconnell/agent-inbox-cli";
|
|
44
48
|
const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
|
|
@@ -91,7 +95,7 @@ const fieldsArg = take("--fields", true);
|
|
|
91
95
|
const urlArg = take("--url", true);
|
|
92
96
|
const tokenArg = take("--token", true);
|
|
93
97
|
/** The CLI's own commands. Anything else is a terminal command, sent as typed. */
|
|
94
|
-
export const OWN = new Set(["login", "logout", "update", "export", "pull", "plan", "diff", "push", "propose", "run", "tail", "script", "check", "ci", "test", "rehearse", "commands", "help", "submit",
|
|
98
|
+
export const OWN = new Set(["login", "logout", "update", "export", "pull", "plan", "diff", "push", "propose", "run", "tail", "script", "check", "ci", "test", "rehearse", "commands", "help", "submit", "dev",
|
|
95
99
|
"whoami", "policy", "audit", "mcp", "claude", "init", "connect", "app", "events", "listen", "completion", "__complete", "--version", "-v", "--help", "-h"]);
|
|
96
100
|
const first = args[0];
|
|
97
101
|
// plan, diff and run are also terminal commands: the CLI's own only for a folder or file that is there (plan, diff) or
|
|
@@ -220,7 +224,7 @@ export function splitNext(text) {
|
|
|
220
224
|
|
|
221
225
|
/** Wait for test or rehearsal jobs, asking how each stands every few seconds (asking also moves it along). */
|
|
222
226
|
async function waitJobs(jobs) {
|
|
223
|
-
const lines = [];
|
|
227
|
+
const lines = [], data = [];
|
|
224
228
|
let ok = true;
|
|
225
229
|
for (const { job, agent } of jobs) {
|
|
226
230
|
// A whole day's replay can take a while (a few hundred conversations, twice each); the rest within minutes.
|
|
@@ -236,8 +240,255 @@ async function waitJobs(jobs) {
|
|
|
236
240
|
if (!markdown && process.stderr.isTTY) process.stderr.write("\r".padEnd(81) + "\r");
|
|
237
241
|
if (s.data?.passed === false) ok = false;
|
|
238
242
|
lines.push(`${agent}: ${s.text}`);
|
|
243
|
+
data.push(s.data ?? {});
|
|
239
244
|
}
|
|
240
|
-
return { ok, lines };
|
|
245
|
+
return { ok, lines, data };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ---- Talk to an agent as the folder has it: agent-inbox dev ---------------------------------------------------------
|
|
249
|
+
/**
|
|
250
|
+
* agent-inbox dev [agent] (prd/agent-dev.md): a chat in the terminal with the agent as this folder's unpushed files
|
|
251
|
+
* have it. Each turn sends the folder and the chat to Next (dev_answer), which answers in a throwaway test conversation;
|
|
252
|
+
* a save reloads the draft for the next answer. Each turn is charged as tests.
|
|
253
|
+
*/
|
|
254
|
+
export const DEV_COMMANDS = { reset: "start the chat again (the folder stays as it is)", why: "why the last answer said what it said (free)", "save-test": "keep the last question as a test in tests/ (add what it must do after it)", quit: "stop" };
|
|
255
|
+
|
|
256
|
+
/** A line typed in dev: a command (/why) or a message for the agent. "//" starts a message that begins with a slash. */
|
|
257
|
+
export function parseDevLine(line) {
|
|
258
|
+
const s = String(line ?? "").trim();
|
|
259
|
+
if (!s) return { kind: "empty" };
|
|
260
|
+
if (s.startsWith("//")) return { kind: "say", text: s.slice(1) };
|
|
261
|
+
const m = /^\/([a-z-]+)(?:\s+([\s\S]*))?$/i.exec(s);
|
|
262
|
+
if (!m) return { kind: "say", text: s };
|
|
263
|
+
const word = m[1].toLowerCase();
|
|
264
|
+
const name = word === "exit" || word === "q" ? "quit" : word === "savetest" || word === "save" ? "save-test" : word === "help" || word === "?" ? "help" : word;
|
|
265
|
+
if (name !== "help" && !(name in DEV_COMMANDS)) return { kind: "unknown", word: `/${word}` };
|
|
266
|
+
return { kind: "command", name, arg: (m[2] ?? "").trim() };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The most customer messages one replay answers: each one is a turn. */
|
|
270
|
+
export const REPLAY_MAX = 20;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* A past conversation (read_conversation) as turns to answer again: each customer message, the conversation as it was
|
|
274
|
+
* before it (customer and team lines; notes and system lines left out), and what was said back then, if anything.
|
|
275
|
+
*/
|
|
276
|
+
export function replayPairs(thread) {
|
|
277
|
+
const lines = (thread?.messages ?? []).filter((m) => !m.note && (m.role === "customer" || m.role === "agent" || m.role === "operator") && String(m.text ?? "").trim());
|
|
278
|
+
const pairs = [];
|
|
279
|
+
for (let i = 0; i < lines.length && pairs.length < REPLAY_MAX; i++) {
|
|
280
|
+
if (lines[i].role !== "customer") continue;
|
|
281
|
+
// Two customer messages in a row are answered together, as the agent would have met them.
|
|
282
|
+
let j = i;
|
|
283
|
+
while (lines[j + 1]?.role === "customer") j++;
|
|
284
|
+
const history = lines.slice(0, j + 1).map((m) => ({ role: m.role === "customer" ? "customer" : "agent", text: m.text }));
|
|
285
|
+
const back = lines[j + 1] && lines[j + 1].role !== "customer" ? lines[j + 1] : null;
|
|
286
|
+
// Went to a person: a teammate wrote before the customer's next message, even after the agent's reply.
|
|
287
|
+
let k = j + 1;
|
|
288
|
+
while (lines[k] && lines[k].role !== "customer" && lines[k].role !== "operator") k++;
|
|
289
|
+
const handed = Boolean(lines[k] && lines[k].role === "operator");
|
|
290
|
+
pairs.push({ customer: lines.slice(i, j + 1).map((m) => m.text).join("\n"), history, then: back ? { who: back.author || (back.role === "agent" ? "the agent" : "a teammate"), byAgent: back.role === "agent", handed, text: back.text } : null });
|
|
291
|
+
i = j;
|
|
292
|
+
}
|
|
293
|
+
return pairs;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** How the new answer differs from the old in kind: the only differences that count, as a rehearsal's. */
|
|
297
|
+
export function replayKind(then, now) {
|
|
298
|
+
if (!then) return "same";
|
|
299
|
+
const before = then.byAgent && !then.handed ? "answered" : "person";
|
|
300
|
+
if (now.handedOff && before === "answered") return "now handed to a person";
|
|
301
|
+
if (!now.handedOff && before === "person") return "now answered";
|
|
302
|
+
return "same";
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** A test file for the last question, as tests/<question>.yaml in the folder (the format pull writes). */
|
|
306
|
+
export function devTestFile(question, { handedOff = false, must = "" } = {}, exists = () => false) {
|
|
307
|
+
const slug = String(question).normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/, "") || "untitled";
|
|
308
|
+
let path = `tests/${slug}.yaml`;
|
|
309
|
+
for (let n = 2; exists(path); n++) path = `tests/${slug}-${n}.yaml`;
|
|
310
|
+
// JSON strings are YAML too: quotes, colons and new lines stay exactly as typed.
|
|
311
|
+
const text = `question: ${JSON.stringify(String(question).trim())}\nexpect: ${handedOff ? "escalate" : "answer"}\n${must.trim() ? `must: ${JSON.stringify(must.trim())}\n` : ""}`;
|
|
312
|
+
return { path, text };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const usd = (micros) => `$${(micros / 1e6).toFixed(micros < 100_000 ? 3 : 2)}`;
|
|
316
|
+
const SUPPORT = { strong: "strong support", partial: "partly supported", none: "not from the knowledge" };
|
|
317
|
+
|
|
318
|
+
/** The quiet lines under an answer: what it read, followed and would do, and what it cost. */
|
|
319
|
+
export function answerLines(a) {
|
|
320
|
+
const out = [];
|
|
321
|
+
for (const r of a.read ?? []) out.push(`read ${r.title}${r.quote ? `: “${r.quote}”` : ""}`);
|
|
322
|
+
if (!(a.read ?? []).length && (a.alsoSeen ?? []).length) out.push(`saw ${a.alsoSeen.join(", ")} (did not draw on them)`);
|
|
323
|
+
for (const p of a.followed ?? []) out.push(`followed ${p} (procedure)`);
|
|
324
|
+
for (const w of a.wouldDo ?? []) out.push(`would do ${w.replace(/^Would have (done|asked the team to approve): /, (m, k) => (k === "done" ? "" : "ask first: "))} (dry run)`);
|
|
325
|
+
out.push(`cost ${usd(a.micros ?? 0)} · ${a.handedOff ? `handed to a person${a.reason ? `: ${a.reason}` : ""}` : `answered${a.support ? `, ${SUPPORT[a.support] ?? a.support}` : ""}`}`);
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** /why: the last answer explained from what it recorded. No model is asked, so it is free and cannot make a reason up. */
|
|
330
|
+
export function whyText(a, setup) {
|
|
331
|
+
if (!a) return "Nothing to explain yet: ask something first.";
|
|
332
|
+
const lines = [`Why ${a.agent} said that:`];
|
|
333
|
+
if (setup && !setup.unchanged) lines.push(`- It answered with this folder's changes: ${setup.trying.join("; ")}.`);
|
|
334
|
+
else if (setup) lines.push("- The folder changes nothing it says, so it answered as things are in Next.");
|
|
335
|
+
lines.push(a.searches?.length ? `- It searched the knowledge for: ${a.searches.map((q) => `“${q}”`).join(", ")}.` : "- It did not search the knowledge.");
|
|
336
|
+
if (a.read?.length) lines.push(`- The answer rests on ${a.read.map((r) => r.title).join(", ")} (${SUPPORT[a.support] ?? "support unknown"}).`);
|
|
337
|
+
else if (a.support === "none" && !a.handedOff) lines.push("- Nothing it read supports the answer: it came from the instructions, or it is a guess. Add an article if it should know this.");
|
|
338
|
+
if (a.alsoSeen?.length) lines.push(`- It also saw ${a.alsoSeen.join(", ")}, and did not draw on ${a.alsoSeen.length === 1 ? "it" : "them"}.`);
|
|
339
|
+
if (a.followed?.length) lines.push(`- It followed the procedure ${a.followed.join(", ")}.`);
|
|
340
|
+
for (const w of a.wouldDo ?? []) lines.push(`- ${w}. Only recorded, nothing ran.`);
|
|
341
|
+
if (a.handedOff) lines.push(`- It handed the conversation to a person${a.reason ? `: ${a.reason}` : ""}.`);
|
|
342
|
+
if (a.steps?.length) lines.push(`- What it did, in order: ${a.steps.join("; ")}.`);
|
|
343
|
+
return lines.join("\n");
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Two texts side by side in columns, each wrapped to its width, for a wide terminal. */
|
|
347
|
+
export function sideBySide(left, right, width = 100) {
|
|
348
|
+
const col = Math.max(20, Math.floor((width - 3) / 2));
|
|
349
|
+
const wrap = (text) => {
|
|
350
|
+
const out = [];
|
|
351
|
+
for (const para of String(text).split("\n")) {
|
|
352
|
+
let line = "";
|
|
353
|
+
for (const word of para.split(/\s+/).filter(Boolean)) {
|
|
354
|
+
const w = word.length > col ? `${word.slice(0, col - 1)}…` : word;
|
|
355
|
+
if (line && line.length + 1 + w.length > col) { out.push(line); line = w; } else line = line ? `${line} ${w}` : w;
|
|
356
|
+
}
|
|
357
|
+
out.push(line);
|
|
358
|
+
}
|
|
359
|
+
return out;
|
|
360
|
+
};
|
|
361
|
+
const a = wrap(left), b = wrap(right);
|
|
362
|
+
return Array.from({ length: Math.max(a.length, b.length) }, (_, i) => `${(a[i] ?? "").padEnd(col)} │ ${b[i] ?? ""}`.trimEnd()).join("\n");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Watch the folder and call `changed` once a burst of saves has settled (editors write a file in several steps).
|
|
367
|
+
* Hidden files (.git, the pull's state file) and node_modules are left out. `watch` is node:fs's, or a stand-in in tests.
|
|
368
|
+
*/
|
|
369
|
+
export function watchFolder(dir, changed, { watch, wait = 400, timers = { setTimeout, clearTimeout } } = {}) {
|
|
370
|
+
let timer = null;
|
|
371
|
+
const seen = new Set();
|
|
372
|
+
const handle = (_event, name) => {
|
|
373
|
+
const file = name ? posix(String(name)) : "";
|
|
374
|
+
if (file && file.split("/").some((p) => p.startsWith(".") || p === "node_modules")) return;
|
|
375
|
+
if (file) seen.add(file);
|
|
376
|
+
timers.clearTimeout(timer);
|
|
377
|
+
timer = timers.setTimeout(() => { const files = [...seen]; seen.clear(); changed(files); }, wait);
|
|
378
|
+
};
|
|
379
|
+
let watcher;
|
|
380
|
+
try { watcher = watch(dir, { recursive: true }, handle); }
|
|
381
|
+
catch { watcher = watch(dir, handle); } // older systems without recursive watching: the top of the folder only
|
|
382
|
+
return { close: () => { timers.clearTimeout(timer); watcher?.close?.(); } };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
async function devCommand(words) {
|
|
386
|
+
const { createInterface } = await import("node:readline");
|
|
387
|
+
const folder = valueOf(words, "--folder") ?? ".";
|
|
388
|
+
const replayRef = valueOf(words, "--replay");
|
|
389
|
+
const yes = words.includes("--yes");
|
|
390
|
+
// A shell drops an unquoted #1042 as a comment: say so rather than start a chat.
|
|
391
|
+
if (words.includes("--replay") && (!replayRef || replayRef.startsWith("--"))) stop(`Name the conversation to replay: its ticket number (${ME} dev --replay 1042) or the 8 characters ls shows.`);
|
|
392
|
+
const skip = new Set(["--folder", "--replay"]);
|
|
393
|
+
const agent = words.filter((w, i) => !w.startsWith("--") && !skip.has(words[i - 1])).join(" ").trim() || undefined;
|
|
394
|
+
if (!existsSync(folder) || !statSync(folder).isDirectory() || !isPulled(folder)) stop(`${folder === "." ? "This folder" : folder} is not a folder from ${ME} pull (it has no workspace.yaml). Run it in your support folder, or name it with --folder.`);
|
|
395
|
+
const state = readState(folder);
|
|
396
|
+
if (state?.url) { const { url } = await access(); if (state.url !== url) stop(`${folder} was pulled from ${state.url}, but you are signed in to ${url}.`); }
|
|
397
|
+
const color = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
398
|
+
const dim = (s) => (color ? `\x1b[2m${s}\x1b[22m` : s);
|
|
399
|
+
const bold = (s) => (color ? `\x1b[1m${s}\x1b[22m` : s);
|
|
400
|
+
const folderNow = () => { const files = folderFiles(folder); const changed = edits(files, readState(folder)); return { files, ...(changed ? { changed } : {}) }; };
|
|
401
|
+
const ask = (args) => tool("dev_answer", { ...folderNow(), ...(agent ? { agent } : {}), ...args });
|
|
402
|
+
|
|
403
|
+
// Who answers, what it tries and the price of a turn: free, and the switch is checked before anything is charged.
|
|
404
|
+
const first = await ask({});
|
|
405
|
+
if (first.isError) stop(first.text);
|
|
406
|
+
let setup = first.data?.setup;
|
|
407
|
+
if (!setup) stop("Next did not answer as expected. Update the CLI or Next, and try again.");
|
|
408
|
+
const intro = () => `${setup.agent} answers ${setup.unchanged ? "as things are in Next: this folder changes nothing it says" : `as this folder has it, unpushed: ${setup.trying.join("; ")}`}.${setup.notTried.length ? ` Not tried: ${setup.notTried.join("; ")}.` : ""}`;
|
|
409
|
+
if (first.data.off) { say(`${intro()}\n\n${first.data.off}`); process.exit(1); }
|
|
410
|
+
const price = `About $${setup.usd.toFixed(2)} a turn, charged as tests.`;
|
|
411
|
+
|
|
412
|
+
if (replayRef) {
|
|
413
|
+
const got = await tool("read_conversation", { conversation: replayRef.replace(/^ticket\s*/i, "") });
|
|
414
|
+
if (got.isError || !got.data) stop(got.text || `There is no conversation ${replayRef} that you can open.`);
|
|
415
|
+
const pairs = replayPairs(got.data);
|
|
416
|
+
if (!pairs.length) stop(`${replayRef} has no customer messages to answer again.`);
|
|
417
|
+
const name = got.data.number ? `#${got.data.number}` : got.data.ref;
|
|
418
|
+
say(`${intro()}\nReplaying ${name}: ${pairs.length === 1 ? "1 customer message" : `${pairs.length} customer messages`}, about $${(setup.usd * pairs.length).toFixed(2)}, charged as tests.`);
|
|
419
|
+
if (!yes) {
|
|
420
|
+
if (!process.stdin.isTTY) stop("Add --yes to start it.");
|
|
421
|
+
const ok = await new Promise((done) => { const rl = createInterface({ input: process.stdin, output: process.stderr }); rl.question("Go ahead? (y/N) ", (a) => { rl.close(); done(/^y/i.test(a.trim())); }); });
|
|
422
|
+
if (!ok) { say("Not replayed."); return; }
|
|
423
|
+
}
|
|
424
|
+
const width = process.stdout.columns ?? 80;
|
|
425
|
+
const counts = { "now answered": 0, "now handed to a person": 0, same: 0 };
|
|
426
|
+
for (const [n, p] of pairs.entries()) {
|
|
427
|
+
const r = await ask({ messages: p.history });
|
|
428
|
+
if (r.isError) stop(r.text);
|
|
429
|
+
const a = r.data.answer;
|
|
430
|
+
const kind = replayKind(p.then, a);
|
|
431
|
+
counts[kind] = (counts[kind] ?? 0) + 1;
|
|
432
|
+
say(`\n${bold(`customer ${n + 1}/${pairs.length}`)} ${p.customer}`);
|
|
433
|
+
const then = p.then ? `then (${p.then.who}): ${p.then.text}` : "then: nobody answered";
|
|
434
|
+
const now = `now (${a.agent})${kind !== "same" ? `, ${kind}` : ""}: ${a.text || "(no answer)"}`;
|
|
435
|
+
say(width >= 100 ? sideBySide(then, now, Math.min(width, 160)) : `${then}\n\n${now}`);
|
|
436
|
+
say(dim(answerLines(a).map((l) => ` ${l}`).join("\n")));
|
|
437
|
+
}
|
|
438
|
+
say(`\n${pairs.length === 1 ? "1 answer" : `${pairs.length} answers`}: ${counts["now answered"]} now answered, ${counts["now handed to a person"]} now handed to a person, ${counts.same} the same kind as then. Nothing was sent or saved.`);
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
say(`${intro()}\n${price} Save a file and the next answer uses it. /why /reset /save-test /quit`);
|
|
443
|
+
const chat = [];
|
|
444
|
+
let last = null;
|
|
445
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, prompt: color ? "\x1b[36myou\x1b[39m " : "you ", terminal: process.stdin.isTTY });
|
|
446
|
+
const { watch } = await import("node:fs");
|
|
447
|
+
const watcher = watchFolder(folder, async (files) => {
|
|
448
|
+
const r = await ask({}).catch(() => null);
|
|
449
|
+
if (!r) return;
|
|
450
|
+
if (r.isError) { process.stdout.write(`\n${r.text}\nThe chat waits for the next save.\n`); return; }
|
|
451
|
+
setup = r.data.setup;
|
|
452
|
+
process.stdout.write(`\n↻ ${files.length ? `${files.slice(0, 3).join(", ")}${files.length > 3 ? ` and ${files.length - 3} more` : ""} saved` : "Saved"}: reloaded. ${intro()}\n`);
|
|
453
|
+
if (process.stdin.isTTY) rl.prompt(true);
|
|
454
|
+
}, { watch });
|
|
455
|
+
let busy = Promise.resolve();
|
|
456
|
+
const end = () => { watcher.close(); rl.close(); process.exit(0); };
|
|
457
|
+
// Ctrl+D, or the end of piped input: finish the turns already asked, then stop.
|
|
458
|
+
rl.on("SIGINT", end);
|
|
459
|
+
rl.on("close", () => { void busy.then(() => { watcher.close(); process.exit(0); }); });
|
|
460
|
+
const prompt = () => { if (process.stdin.isTTY) rl.prompt(); };
|
|
461
|
+
prompt();
|
|
462
|
+
rl.on("line", (line) => { busy = busy.then(() => onLine(line)).catch((e) => say(String(e?.message ?? e))).then(prompt); });
|
|
463
|
+
async function onLine(line) {
|
|
464
|
+
const said = parseDevLine(line);
|
|
465
|
+
if (said.kind === "empty") return;
|
|
466
|
+
if (said.kind === "unknown") { say(`${said.word} is not a command here. ${Object.keys(DEV_COMMANDS).map((c) => `/${c}`).join(" ")}`); return; }
|
|
467
|
+
if (said.kind === "command") {
|
|
468
|
+
if (said.name === "quit") end();
|
|
469
|
+
if (said.name === "help") { say(Object.entries(DEV_COMMANDS).map(([c, d]) => `/${c.padEnd(10)} ${d}`).join("\n") + "\n//text send a message that starts with a slash"); return; }
|
|
470
|
+
if (said.name === "reset") { chat.length = 0; last = null; say("Started again. The folder stays as it is."); return; }
|
|
471
|
+
if (said.name === "why") { say(whyText(last?.answer, setup)); return; }
|
|
472
|
+
if (said.name === "save-test") {
|
|
473
|
+
if (!last) { say("Ask something first: the test is the last thing you asked."); return; }
|
|
474
|
+
const must = said.arg.replace(/^must:?\s+/i, "");
|
|
475
|
+
const t = devTestFile(last.question, { handedOff: last.answer.handedOff, must }, (p) => existsSync(join(folder, ...p.split("/"))));
|
|
476
|
+
mkdirSync(join(folder, "tests"), { recursive: true });
|
|
477
|
+
writeFileSync(join(folder, ...t.path.split("/")), t.text);
|
|
478
|
+
say(`Wrote ${t.path} (expect: ${last.answer.handedOff ? "escalate" : "answer"}${must ? `, must: ${must}` : ""}). ${ME} push sends it with the rest.`);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
chat.push({ role: "customer", text: said.text });
|
|
483
|
+
const r = await ask({ messages: chat });
|
|
484
|
+
if (r.isError) { chat.pop(); say(r.text); return; }
|
|
485
|
+
const a = r.data.answer;
|
|
486
|
+
setup = r.data.setup ?? setup;
|
|
487
|
+
chat.push({ role: "agent", text: a.text || "(no answer)" });
|
|
488
|
+
last = { question: said.text, answer: a };
|
|
489
|
+
say(`${bold(a.agent)}${a.handedOff ? dim(" (handed to a person)") : ""}\n${a.text || "(no answer)"}\n${dim(answerLines(a).map((l) => ` ${l}`).join("\n"))}`);
|
|
490
|
+
}
|
|
491
|
+
await new Promise(() => {});
|
|
241
492
|
}
|
|
242
493
|
|
|
243
494
|
// ---- CI for a repository of support files --------------------------------------------------------------------------
|
|
@@ -273,7 +524,8 @@ export function ciWorkflow(url, folder) {
|
|
|
273
524
|
- run: ${cli}`;
|
|
274
525
|
const pr = "${{ github.event.pull_request.number }}";
|
|
275
526
|
return `# Next support, written by agent-inbox ci init. The support setup lives in ${dir === "." ? "this repository" : `${dir}/`} (agent-inbox pull).
|
|
276
|
-
# Pull requests: what the change
|
|
527
|
+
# Pull requests: what the change does, and the answers it changes on 10 recent conversations (each answered as things
|
|
528
|
+
# are and with the change), the saved tests and the cost, as one comment, edited on each push. Names are taken out.
|
|
277
529
|
# Merges to main: the changes are proposed in Next's Approvals, for an admin to apply.
|
|
278
530
|
# Nightly: changes someone made in Next's console come back as a pull request, so the two never drift apart. That
|
|
279
531
|
# includes policy.yaml, what every agent may do: a change to it (an agent now allowed to act alone) is a reviewed line.
|
|
@@ -300,18 +552,9 @@ jobs:
|
|
|
300
552
|
runs-on: ubuntu-latest
|
|
301
553
|
steps:
|
|
302
554
|
${setup}
|
|
303
|
-
- name:
|
|
304
|
-
|
|
305
|
-
run:
|
|
306
|
-
set +e
|
|
307
|
-
node agent-inbox.mjs check ${dir} > report.md
|
|
308
|
-
echo "code=$?" >> "$GITHUB_OUTPUT"
|
|
309
|
-
cat report.md >> "$GITHUB_STEP_SUMMARY"
|
|
310
|
-
- name: Comment on the pull request
|
|
311
|
-
env: { GH_TOKEN: "\${{ github.token }}" }
|
|
312
|
-
run: gh pr comment ${pr} --body-file report.md --edit-last || gh pr comment ${pr} --body-file report.md
|
|
313
|
-
- name: Pass or fail
|
|
314
|
-
run: exit \${{ steps.check.outputs.code }}
|
|
555
|
+
- name: How this changes answers
|
|
556
|
+
env: { GITHUB_TOKEN: "\${{ github.token }}" }
|
|
557
|
+
run: node agent-inbox.mjs ci comment ${dir} --on 10 --pr ${pr}
|
|
315
558
|
propose:
|
|
316
559
|
if: github.event_name == 'push'
|
|
317
560
|
runs-on: ubuntu-latest
|
|
@@ -340,6 +583,199 @@ ${setup}
|
|
|
340
583
|
`;
|
|
341
584
|
}
|
|
342
585
|
|
|
586
|
+
// ---- Answer changes on a pull request: agent-inbox ci comment ------------------------------------------------------
|
|
587
|
+
/** The marker the answer-changes comment starts with, so later pushes edit the same comment (found through the API). */
|
|
588
|
+
export const ANSWERS_MARK = "<!-- next-answer-changes -->";
|
|
589
|
+
/** GitHub refuses a comment over 65,536 characters; ours stays well under. */
|
|
590
|
+
const COMMENT_MAX = 60_000;
|
|
591
|
+
|
|
592
|
+
/** Words after "hi" or "I'm" that are not a name. */
|
|
593
|
+
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;
|
|
594
|
+
/**
|
|
595
|
+
* Text fit for a pull request, which more people may read than the console: emails, phone, card and order numbers,
|
|
596
|
+
* long tokens and names in greetings are taken out. Next has already taken out the customer's own name; this is the
|
|
597
|
+
* second look, on this computer, before anything is posted. Pure, so it can be tested.
|
|
598
|
+
*/
|
|
599
|
+
export function redact(text) {
|
|
600
|
+
return String(text ?? "")
|
|
601
|
+
.replace(/\b(bearer|basic)\s+\S+/gi, "$1 [hidden]")
|
|
602
|
+
.replace(/\b(password|passwd|passcode|pin|secret|token|api[_ -]?key|key|code)\b(\s*(?:is|:|=)\s*)\S+/gi, "$1$2[hidden]")
|
|
603
|
+
.replace(/[\w.+-]+@[\w-]+(\.[\w-]+)+/g, "[email]")
|
|
604
|
+
.replace(/\b(?:\d[ -]?){13,19}\b/g, "[card number]")
|
|
605
|
+
.replace(/(?:\+\d{1,3}[ .-]?)?(?:\(\d{2,4}\)[ .-]?)?\d{3,4}[ .-]\d{3,4}(?:[ .-]\d{2,4})?\b/g, "[phone]")
|
|
606
|
+
.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]")
|
|
607
|
+
.replace(/#\s?[A-Z]{0,3}-?\d{3,}\b/gi, "#[number]")
|
|
608
|
+
.replace(/\b\d{5,}\b/g, "[number]")
|
|
609
|
+
.replace(/\b(?=[A-Za-z0-9_\-]*\d)(?=[A-Za-z0-9_\-]*[A-Za-z])[A-Za-z0-9_\-]{24,}\b/g, "[hidden]")
|
|
610
|
+
// "my name is Ines Duarte", "I'm Sam", then greetings and sign-offs: "Hi Maya,", "Thanks, Leo Park".
|
|
611
|
+
.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]`))
|
|
612
|
+
.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]`));
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Text that can sit in a comment without becoming markup: no HTML (a </details> or the marker), no @mentions (GitHub
|
|
617
|
+
* would notify someone), no links or images, on one line. Applied after redact().
|
|
618
|
+
*/
|
|
619
|
+
export function mdSafe(text, max = 600) {
|
|
620
|
+
let s = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
621
|
+
if (s.length > max) s = `${s.slice(0, max).replace(/\s+\S*$/, "")}…`;
|
|
622
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/@/g, "@")
|
|
623
|
+
.replace(/\[/g, "[").replace(/\]/g, "]").replace(/!/g, "!").replace(/`/g, "`").replace(/\*/g, "*").replace(/_/g, "_").replace(/\|/g, "|");
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** A plan's text as plain lines for people: the table's rows as "section name: change", the notes kept, the hints dropped. */
|
|
627
|
+
export function planLines(plan) {
|
|
628
|
+
const out = [];
|
|
629
|
+
for (const raw of String(plan ?? "").split("\n")) {
|
|
630
|
+
const l = raw.replace(/^Plan [0-9a-f]{4,}: /, "").trim();
|
|
631
|
+
if (!l || /^name\s+change$/.test(l) || /rehearse|submit_plan|Approvals|apply /i.test(l)) continue;
|
|
632
|
+
const cells = l.split(/\s{2,}/);
|
|
633
|
+
out.push(cells.length >= 3 ? `${cells[0]} ${cells[1]}: ${cells.slice(2).join(", ")}` : cells.length === 2 ? `${cells[0]}: ${cells[1]}` : l);
|
|
634
|
+
}
|
|
635
|
+
return out;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
const KIND_SAID = { handed: "Now handed to a person", answered: "Now answered", acts: "Uses the apps differently", sources: "Answers from other articles" };
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* The one pull request comment: what the change does, how many answers change, each changed answer before and after
|
|
642
|
+
* (collapsed), the tests, the cost, and the link to the rehearsal in Next. Pure, so it can be tested; every text that
|
|
643
|
+
* came from a conversation goes through redact() and mdSafe(). `failed` is true when something needs a look.
|
|
644
|
+
*/
|
|
645
|
+
export function answerComment({ plan = "", changes = 0, policy = null, problems = null, rehearsal = null, passed = null, link = null, skipped = null, blocked = null, on = 10 }) {
|
|
646
|
+
const parts = [ANSWERS_MARK, "## Next: how this pull request changes answers"];
|
|
647
|
+
if (problems) {
|
|
648
|
+
parts.push("### The folder has problems", planLines(problems).map((l) => `- ${mdSafe(l, 400)}`).join("\n"), "**Needs a look before merging.**");
|
|
649
|
+
return { text: parts.join("\n\n") + "\n", failed: true };
|
|
650
|
+
}
|
|
651
|
+
const what = [...planLines(changes ? plan : ""), ...(policy?.changes ? planLines(policy.plan).map((l) => `What the agents may do: ${l}`) : [])];
|
|
652
|
+
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.");
|
|
653
|
+
if (skipped) parts.push(`> ${mdSafe(skipped, 500)}`);
|
|
654
|
+
if (blocked) parts.push("### Could not rehearse", mdSafe(blocked, 500));
|
|
655
|
+
const a = rehearsal?.answers;
|
|
656
|
+
if (rehearsal && a) {
|
|
657
|
+
parts.push(`### Answers that change: ${a.changed} of ${a.total}`,
|
|
658
|
+
`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.`);
|
|
659
|
+
for (const it of a.items) {
|
|
660
|
+
const ref = it.ref && /^#\d+$/.test(it.ref) ? `<b>${it.ref}</b> · ` : "";
|
|
661
|
+
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>`);
|
|
662
|
+
}
|
|
663
|
+
if (a.changed > a.items.length) parts.push(`…and ${a.changed - a.items.length} more, in Next.`);
|
|
664
|
+
} else if (rehearsal) {
|
|
665
|
+
parts.push(`### Answers: ${rehearsal.replay.answered} of ${rehearsal.replay.total} answered with the change (${rehearsal.replay.before} were answered at the time)`);
|
|
666
|
+
}
|
|
667
|
+
if (rehearsal?.tests) {
|
|
668
|
+
const tt = rehearsal.tests;
|
|
669
|
+
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"}` : ""}.`);
|
|
670
|
+
}
|
|
671
|
+
if (rehearsal) {
|
|
672
|
+
const where = link && /^https:\/\/[^\s<>()]+$/.test(link) ? ` [Open the rehearsal in Next](${link}) (for people in the workspace).` : "";
|
|
673
|
+
parts.push(`Cost: $${Number(rehearsal.usd ?? 0).toFixed(2)}, charged as tests.${where}`);
|
|
674
|
+
}
|
|
675
|
+
const failed = Boolean(blocked || (rehearsal && passed === false));
|
|
676
|
+
if (failed) parts.push("**Needs a look before merging.**");
|
|
677
|
+
else if (changes || policy?.changes) parts.push("Merging proposes these changes in Next's **Approvals**, where an admin applies them.");
|
|
678
|
+
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>`);
|
|
679
|
+
let text = parts.join("\n\n") + "\n";
|
|
680
|
+
if (text.length > COMMENT_MAX) text = `${text.slice(0, COMMENT_MAX - 200)}\n\n…cut short: the rest is in Next.\n`;
|
|
681
|
+
return { text, failed };
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/** The pull request's number in a GitHub Actions run: --pr, or the event that started it. */
|
|
685
|
+
export function prNumber(given, eventPath = process.env.GITHUB_EVENT_PATH, read = (p) => readFileSync(p, "utf8")) {
|
|
686
|
+
if (given && /^\d+$/.test(String(given))) return Number(given);
|
|
687
|
+
try { const n = JSON.parse(read(eventPath))?.pull_request?.number; return Number.isInteger(n) ? n : null; } catch { return null; }
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Post the comment, or edit the one already there: the pull request's comments are read a page at a time until one
|
|
692
|
+
* starts with the marker (this one, or check's older one), and that one is edited, so a pull request has one comment.
|
|
693
|
+
* `fetcher` is fetch, passed in so a test can stand in for GitHub.
|
|
694
|
+
*/
|
|
695
|
+
export async function postComment({ fetcher = fetch, token, repo, pr, body, api = "https://api.github.com", marks = [ANSWERS_MARK, CHECK_MARK] }) {
|
|
696
|
+
const headers = { authorization: `Bearer ${token}`, accept: "application/vnd.github+json", "x-github-api-version": "2022-11-28", "user-agent": UA, "content-type": "application/json" };
|
|
697
|
+
const base = `${api.replace(/\/+$/, "")}/repos/${repo}`;
|
|
698
|
+
let found = null;
|
|
699
|
+
for (let page = 1; page <= 30 && !found; page++) {
|
|
700
|
+
const r = await fetcher(`${base}/issues/${pr}/comments?per_page=100&page=${page}`, { headers });
|
|
701
|
+
if (!r.ok) return { ok: false, status: r.status };
|
|
702
|
+
const list = await r.json();
|
|
703
|
+
found = list.find((c) => marks.some((m) => String(c.body ?? "").startsWith(m))) ?? null;
|
|
704
|
+
if (list.length < 100) break;
|
|
705
|
+
}
|
|
706
|
+
const r = found
|
|
707
|
+
? await fetcher(`${base}/issues/comments/${found.id}`, { method: "PATCH", headers, body: JSON.stringify({ body }) })
|
|
708
|
+
: await fetcher(`${base}/issues/${pr}/comments`, { method: "POST", headers, body: JSON.stringify({ body }) });
|
|
709
|
+
if (!r.ok) return { ok: false, status: r.status };
|
|
710
|
+
const made = await r.json().catch(() => ({}));
|
|
711
|
+
return { ok: true, action: found ? "updated" : "created", url: made.html_url ?? null };
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* agent-inbox ci comment [folder] [--on 10] [--pr n] [--print]: in a pull request's workflow, plan the folder (and
|
|
716
|
+
* policy.yaml), rehearse the change on recent conversations with each answered as things are and with it, and post one
|
|
717
|
+
* comment on the pull request, edited on later pushes. Exit 1 when something needs a look; 0 otherwise, including when
|
|
718
|
+
* rehearsals are switched off (the comment says so).
|
|
719
|
+
*/
|
|
720
|
+
async function ciComment(words) {
|
|
721
|
+
const opt = (name) => { const i = words.indexOf(`--${name}`); return i >= 0 && words[i + 1] && !words[i + 1].startsWith("--") ? words[i + 1] : undefined; };
|
|
722
|
+
const dir = words.find((a, i) => !a.startsWith("--") && !(i > 0 && words[i - 1].startsWith("--") && words[i - 1] !== "--print")) || ".";
|
|
723
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory() || !isPulled(dir)) stop(`${dir} is not a folder from ${ME} pull (it has no workspace.yaml).`);
|
|
724
|
+
const asked = Number(opt("on") ?? 10);
|
|
725
|
+
const on = Number.isInteger(asked) && asked > 0 ? Math.min(asked, 30) : 10;
|
|
726
|
+
const progress = (s) => { if (process.stderr.isTTY || process.env.CI) process.stderr.write(`${s}\n`); };
|
|
727
|
+
|
|
728
|
+
progress("Planning the folder");
|
|
729
|
+
const { text, data } = await planFolder(dir);
|
|
730
|
+
const plan = text.replace(/\n*(Nothing has changed|This token can only look)[\s\S]*$/, "").replace(/\n+Before +rehearse [^\n]*/g, "").trim();
|
|
731
|
+
let comment;
|
|
732
|
+
let target = null, policy = null;
|
|
733
|
+
if (!data?.ok) comment = answerComment({ problems: plan });
|
|
734
|
+
else {
|
|
735
|
+
// policy.yaml, when the folder keeps one: a change to what the agents may do is part of the change too.
|
|
736
|
+
const policyFile = join(dir, POLICY_FILE);
|
|
737
|
+
if (existsSync(policyFile)) {
|
|
738
|
+
const got = await tool("plan_policy", { file: readFileSync(policyFile, "utf8") });
|
|
739
|
+
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 };
|
|
740
|
+
}
|
|
741
|
+
target = data.changes ? data.plan : policy?.ref ?? null;
|
|
742
|
+
let rehearsal = null, passed = null, link = null, skipped = null, blocked = null;
|
|
743
|
+
if (target) {
|
|
744
|
+
progress(`Rehearsing the change on ${on} recent conversations, each answered as things are and with it`);
|
|
745
|
+
const r = await tool("rehearse", { plan: target, conversations: on, compare: true });
|
|
746
|
+
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.`;
|
|
747
|
+
else if (r.isError && /nothing to rehearse|does not change what/i.test(r.text)) skipped = `Not rehearsed: ${r.text}`;
|
|
748
|
+
else if (r.isError) blocked = r.text;
|
|
749
|
+
else if (r.data?.job) {
|
|
750
|
+
const done = await waitJobs([{ job: r.data.job, agent: "This change" }]);
|
|
751
|
+
const last = done.data[0] ?? {};
|
|
752
|
+
rehearsal = last.rehearsal ?? null; passed = done.ok; link = last.link ?? r.data.link ?? null;
|
|
753
|
+
if (!rehearsal) blocked = done.lines.join("\n");
|
|
754
|
+
}
|
|
755
|
+
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.";
|
|
756
|
+
}
|
|
757
|
+
comment = answerComment({ plan, changes: data.changes, policy, rehearsal, passed, link, skipped, blocked, on });
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// Where it goes: the pull request (in GitHub Actions, with the workflow's token), the run's summary, or the screen.
|
|
761
|
+
if (process.env.GITHUB_STEP_SUMMARY) { try { writeFileSync(process.env.GITHUB_STEP_SUMMARY, comment.text, { flag: "a" }); } catch {} }
|
|
762
|
+
const pr = prNumber(opt("pr"));
|
|
763
|
+
const token = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
|
|
764
|
+
const repo = process.env.GITHUB_REPOSITORY;
|
|
765
|
+
if (words.includes("--print") || !token || !repo || !pr) {
|
|
766
|
+
say(comment.text);
|
|
767
|
+
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`);
|
|
768
|
+
} else {
|
|
769
|
+
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 }));
|
|
770
|
+
if (posted.ok) say(`${posted.action === "updated" ? "Updated" : "Posted"} the comment on pull request #${pr}${posted.url ? `: ${posted.url}` : ""}.`);
|
|
771
|
+
else {
|
|
772
|
+
say(comment.text);
|
|
773
|
+
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`);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
process.exit(comment.failed ? 1 : 0);
|
|
777
|
+
}
|
|
778
|
+
|
|
343
779
|
// ---- Knowledge from this computer ----------------------------------------------------------------------------------
|
|
344
780
|
const DOCS = [".md", ".markdown", ".txt", ".html", ".htm"];
|
|
345
781
|
const posix = (p) => p.split(sep).join("/");
|
|
@@ -568,8 +1004,11 @@ const USAGE = [
|
|
|
568
1004
|
["", "in a file, knowledge entries can name file: docs/a.md or files: docs/**/*.md"],
|
|
569
1005
|
["<terminal command>", "any console terminal command, such as ME ls unassigned"],
|
|
570
1006
|
['run "<command>"', 'the same, in quotes, such as "ls unassigned --inbox Billing"'],
|
|
1007
|
+
["dev [agent] [--folder support]", "talk to the agent as this folder's unpushed files have it; each save reloads it (each turn is charged as tests)"],
|
|
1008
|
+
["dev --replay <ticket|conversation> [--yes]", "answer a past conversation's customer messages again with the folder, beside what was said then"],
|
|
571
1009
|
["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)"],
|
|
572
1010
|
["ci init [folder] [--force]", "write a GitHub workflow: check pull requests, propose on merge, and open a pull request when the console changed"],
|
|
1011
|
+
["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)"],
|
|
573
1012
|
["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)"],
|
|
574
1013
|
["script <file> [--propose]", "commands, one per line, as one plan; --propose sends it to Approvals"],
|
|
575
1014
|
["submit <plan>", "send a plan a change printed to Approvals, for an admin to apply (the CLI never applies)"],
|
|
@@ -760,6 +1199,12 @@ export function initArgs(words, exists = existsSync) {
|
|
|
760
1199
|
return { address, folder: plain.find((w) => w !== address) ?? "support" };
|
|
761
1200
|
}
|
|
762
1201
|
|
|
1202
|
+
/**
|
|
1203
|
+
* Next as a Claude Code plugin: its tools and skills for a support lead, from the marketplace in this repository
|
|
1204
|
+
* (.claude-plugin/marketplace.json, plugins/next). init prints these two lines; typed in Claude Code, they install it.
|
|
1205
|
+
*/
|
|
1206
|
+
export const PLUGIN_LINES = ["/plugin marketplace add droconnell/agent-inbox", "/plugin install next@agent-inbox"];
|
|
1207
|
+
|
|
763
1208
|
/**
|
|
764
1209
|
* agent-inbox init <address> [folder]: everything the guide walks through, in one go. Each step says what it is doing,
|
|
765
1210
|
* skips what is already done, and never overwrites a file someone changed, so it is safe to run again. It only looks
|
|
@@ -834,6 +1279,10 @@ async function init(words) {
|
|
|
834
1279
|
step(6, "Claude Code");
|
|
835
1280
|
done.claude = Boolean(sh("claude", ["--version"])?.ok);
|
|
836
1281
|
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.");
|
|
1282
|
+
// Offered, never run: the person types these in Claude Code if they want the skills. The folder's .mcp.json already
|
|
1283
|
+
// gives Claude Code the tools without them.
|
|
1284
|
+
done.plugin = PLUGIN_LINES;
|
|
1285
|
+
if (!asJson) say(` For Next's skills too (why did the agent say this, what broke this week, ship a change), type these in Claude Code:\n${PLUGIN_LINES.map((l) => ` ${l}`).join("\n")}`);
|
|
837
1286
|
|
|
838
1287
|
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?"`);
|
|
839
1288
|
if (asJson) { report("", done); return; }
|
|
@@ -1318,6 +1767,7 @@ switch (cmd) {
|
|
|
1318
1767
|
case "claude": await claudeSetup(rest.includes("--project")); break;
|
|
1319
1768
|
case "init": await init(rest); break;
|
|
1320
1769
|
case "connect": await connect(rest); break;
|
|
1770
|
+
case "dev": await devCommand(rest); break;
|
|
1321
1771
|
case "app": await appCommand(rest); break;
|
|
1322
1772
|
case "events": { const only = (valueOf(rest, "--only") ?? "").split(",").filter(Boolean); await events(only.length ? only : null); break; }
|
|
1323
1773
|
case "listen": await listen(valueOf(rest, "--forward"), valueOf(rest, "--events")?.split(",").filter(Boolean)); break;
|
|
@@ -1519,8 +1969,10 @@ switch (cmd) {
|
|
|
1519
1969
|
process.exit(report.failed ? 1 : 0);
|
|
1520
1970
|
}
|
|
1521
1971
|
case "ci": {
|
|
1972
|
+
// ci comment [folder]: the pull request's comment on how the change moves answers (prd/answer-diffs.md).
|
|
1973
|
+
if (rest[0] === "comment") { await ciComment(rest.slice(1)); break; }
|
|
1522
1974
|
// ci init [folder]: write the GitHub workflow for a repository of support files.
|
|
1523
|
-
if (rest[0] !== "init") stop(`Use ${ME} ci init [folder], in the repository that holds the folder from ${ME} pull.`);
|
|
1975
|
+
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.`);
|
|
1524
1976
|
const dir = rest[1] || ".";
|
|
1525
1977
|
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.`);
|
|
1526
1978
|
const { url } = await access();
|
|
@@ -1533,7 +1985,7 @@ switch (cmd) {
|
|
|
1533
1985
|
Then:
|
|
1534
1986
|
1. In Next, an admin makes a personal access token set to Look and propose changes (Settings, Terminal, Plain English and AI tools).
|
|
1535
1987
|
2. In GitHub, add it as the repository secret AGENT_INBOX_TOKEN.
|
|
1536
|
-
3. Commit and push the workflow. Each pull request that changes ${dir === "." ? "the folder" : dir} gets
|
|
1988
|
+
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.
|
|
1537
1989
|
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.`);
|
|
1538
1990
|
break;
|
|
1539
1991
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@droconnell/agent-inbox-cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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": {
|