@droconnell/agent-inbox-cli 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/agent-inbox.mjs +46 -4
  2. package/package.json +1 -1
package/agent-inbox.mjs CHANGED
@@ -34,7 +34,7 @@ import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
34
34
  import { spawn } from "node:child_process";
35
35
  import { fileURLToPath } from "node:url";
36
36
 
37
- export const VERSION = "1.9.0";
37
+ export const VERSION = "1.10.0";
38
38
  /** The npm package; its command is agent-inbox. (The name agent-inbox itself belongs to someone else on npm.) */
39
39
  export const PACKAGE = "@droconnell/agent-inbox-cli";
40
40
  const DIR = join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agent-inbox");
@@ -324,6 +324,29 @@ export function folderFiles(dir) {
324
324
  go(dir);
325
325
  return out;
326
326
  }
327
+ /** The apps whose code or manifest changed since the pull (apps/<name>/app.html, manifest.yaml), by folder name. */
328
+ export function changedApps(files, state) {
329
+ const changed = edits(files, state);
330
+ const names = new Set();
331
+ for (const p of changed ?? []) { const m = /^apps\/([^/]+)\/(app\.html|manifest\.ya?ml)$/.exec(p); if (m) names.add(m[1]); }
332
+ return [...names].filter((n) => files[`apps/${n}/app.html`] !== undefined && (files[`apps/${n}/manifest.yaml`] ?? files[`apps/${n}/manifest.yml`]) !== undefined);
333
+ }
334
+
335
+ /** Send each changed app as a draft (propose_app), then remember them as sent, so pushing again does not send them twice. */
336
+ async function pushApps(dir, files) {
337
+ const state = readState(dir);
338
+ const names = changedApps(files, state);
339
+ for (const n of names) {
340
+ const manifestPath = files[`apps/${n}/manifest.yaml`] !== undefined ? `apps/${n}/manifest.yaml` : `apps/${n}/manifest.yml`;
341
+ const sent = await tool("propose_app", { source: files[`apps/${n}/app.html`], manifest: files[manifestPath], note: "Changed in the folder" });
342
+ if (sent.isError) { say(`apps/${n}: ${sent.text}`); process.exitCode = 1; continue; }
343
+ say(sent.text);
344
+ if (state?.files) { state.files[`apps/${n}/app.html`] = hash(files[`apps/${n}/app.html`]); state.files[manifestPath] = hash(files[manifestPath]); }
345
+ }
346
+ if (names.length && state?.files) writeFileSync(join(dir, STATE), JSON.stringify(state, null, 2) + "\n");
347
+ return names.length;
348
+ }
349
+
327
350
  /** Which files differ from the pull: changed or new. Without a record of the pull, it cannot say (null). */
328
351
  export function edits(files, state) {
329
352
  if (!state?.files) return null;
@@ -388,8 +411,10 @@ async function login(address) {
388
411
  const go = new URL(`${url}/oauth/authorize`);
389
412
  for (const [k, v] of Object.entries({ response_type: "code", client_id: client.client_id, redirect_uri: redirect, code_challenge: createHash("sha256").update(verifier).digest("base64url"), code_challenge_method: "S256", state, scope: "propose" })) go.searchParams.set(k, v);
390
413
  say(`Opening your browser to sign in and approve the CLI. If it does not open, go to:\n${go}`);
391
- const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "explorer" : "xdg-open";
392
- try { spawn(opener, [go.toString()], { stdio: "ignore", detached: true }).on("error", () => {}).unref(); } catch {}
414
+ // On Windows, explorer drops long addresses like this one; rundll32's URL handler opens the default browser with
415
+ // the whole address, & and all, without a shell in between.
416
+ const [opener, ...how] = process.platform === "darwin" ? ["open"] : process.platform === "win32" ? ["rundll32", "url.dll,FileProtocolHandler"] : ["xdg-open"];
417
+ try { spawn(opener, [...how, go.toString()], { stdio: "ignore", detached: true, windowsHide: true }).on("error", () => {}).unref(); } catch {}
393
418
  const back = await new Promise((ok) => {
394
419
  const timer = setTimeout(() => ok(null), 5 * 60_000);
395
420
  server.on("request", (req, res) => {
@@ -424,6 +449,7 @@ const USAGE = [
424
449
  ["ci init [folder] [--force]", "write a GitHub workflow: check pull requests, propose on merge, and open a pull request when the console changed"],
425
450
  ["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)"],
426
451
  ["script <file> [--propose]", "commands, one per line, as one plan; --propose sends it to Decisions"],
452
+ ["submit <plan>", "send a plan a change printed to Decisions, for an admin to apply (the CLI never applies)"],
427
453
  ["test", "run the agents' tests and wait (exit 0 all pass, 1 some fail)"],
428
454
  ["rehearse <file>", "rehearse the agents the file adds or changes on past conversations and wait"],
429
455
  ["rehearse [plan] [--on 20] [--topic refund]", "show me before it goes live: past conversations and the tests, with a plan and without"],
@@ -516,6 +542,9 @@ switch (cmd) {
516
542
  const body = text.replace(/^Plan \w+: /, "").replace(/\n*(Nothing has changed|This token can only look)[\s\S]*$/, "").trim();
517
543
  if (!data?.ok) { say(markdown ? `### The workspace file has problems\n\n${fence(body)}` : body); process.exit(1); }
518
544
  const what = folder ? "folder" : "file";
545
+ // Changed apps are not in the plan: push sends each as a draft.
546
+ const apps = folder ? changedApps(folderFiles(dir), readState(dir)) : [];
547
+ if (apps.length) say(`${apps.length === 1 ? "1 app" : `${apps.length} apps`} changed (${apps.map((n) => `apps/${n}`).join(", ")}): ${ME} push sends ${apps.length === 1 ? "it" : "each"} as a draft for an admin to publish.`);
519
548
  // A folder's notes (articles from a website, files with no match) are worth seeing even when nothing changes.
520
549
  const notes = folder ? text.split("\n").filter((l) => l.trim() && !/^Nothing would change/.test(l)).join("\n") : "";
521
550
  if (!data.changes) { say(markdown ? `### No changes\n\nThe workspace already matches the ${what}.${notes ? `\n\n${notes}` : ""}` : `No changes: the workspace already matches the ${what}.${notes ? `\n${notes}` : ""}`); process.exit(0); }
@@ -526,8 +555,11 @@ switch (cmd) {
526
555
  const dir = cmd === "push" ? rest[0] || "." : rest[0];
527
556
  const folder = dir && existsSync(dir) && statSync(dir).isDirectory() && isPulled(dir);
528
557
  if (cmd === "push" && !folder) stop(`${dir} is not a folder from ${ME} pull (it has no workspace.yaml). Run ${ME} pull first, or ${ME} propose <file> for one workspace file.`);
558
+ // Apps whose code or manifest changed go first, each as a draft for an admin to publish.
559
+ const appsSent = folder ? await pushApps(dir, folderFiles(dir)) : 0;
529
560
  const { text, data } = folder ? await planFolder(dir) : await tool("import_workspace", read(rest[0]));
530
561
  if (!data?.ok) { say(text); process.exit(1); }
562
+ if (!data.changes && appsSent) break;
531
563
  if (!data.changes) { say(folder ? "Nothing to push: the workspace already matches the folder." : "Nothing to propose: the workspace already matches the file."); if (folder) say(text.split("\n").filter((l) => !/^Nothing would change/.test(l) && l.trim()).join("\n")); break; }
532
564
  const sent = await tool("submit_plan", { plan: data.plan });
533
565
  if (sent.isError) stop(sent.text);
@@ -659,10 +691,20 @@ Then:
659
691
  say(text); if (isError) process.exit(1);
660
692
  break;
661
693
  }
694
+ case "submit": {
695
+ // A plan a change made here, sent to Decisions for an admin to apply.
696
+ if (!rest[0]) stop(`Give the plan to send, for example ${ME} submit 1a2b3c4d (the reference a change printed).`);
697
+ const sent = await tool("submit_plan", { plan: rest[0] });
698
+ say(sent.text); if (sent.isError) process.exit(1);
699
+ break;
700
+ }
662
701
  default: {
663
702
  // Anything else is a terminal command, as typed in the console: agent-inbox ls unassigned, agent-inbox agents.
664
703
  const { text, isError } = await tool("terminal", { command: [cmd, ...rest].join(" ") });
665
- say(text); if (isError) process.exit(1);
704
+ // A change is only a plan from here. The server's note is written for AI tools; the CLI says what a person can do.
705
+ const plan = (/Plan ([0-9a-f]{8})/.exec(text) ?? [])[1];
706
+ say(plan ? text.replace(/Nothing has changed\. An AI tool cannot apply a change:[^\n]*/, `Nothing has changed. Apply it in the console's terminal (Ctrl+\` on any page, then apply ${plan}), or send it to Decisions for an admin with ${ME} submit ${plan}.`) : text);
707
+ if (isError) process.exit(1);
666
708
  }
667
709
  }
668
710
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droconnell/agent-inbox-cli",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "The Next CLI: a support workspace's setup as a file in git, and the console terminal from your own computer.",
5
5
  "type": "module",
6
6
  "bin": {