@point-seven-studio/jq-deck 0.3.2 → 0.4.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/dist/jq-deck.mjs CHANGED
@@ -3,21 +3,149 @@
3
3
  // src/cli.ts
4
4
  import { spawn } from "child_process";
5
5
  import { createServer } from "http";
6
+
7
+ // src/presence.ts
8
+ import { existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
9
+ import os from "os";
10
+ import path from "path";
11
+ var TOOLS = [
12
+ { id: "deck", name: "JQ Deck", what: "sessions, setup and mail on one page", port: 4316, run: "npx @point-seven-studio/jq-deck" },
13
+ { id: "agents", name: "JQ Agents", what: "every session, and which wait on a person", port: 4319, run: "npx @point-seven-studio/jq-agents" },
14
+ { id: "groundcrew", name: "JQ Groundcrew", what: "the setup check for one project", port: 4317, run: "npx @point-seven-studio/jq-groundcrew" },
15
+ { id: "crosstalk", name: "JQ Crosstalk", what: "the mailbox between sessions", port: 4318, run: "npx @point-seven-studio/jq-crosstalk view" }
16
+ ];
17
+ var esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
18
+ function runningDir(env = process.env) {
19
+ return env.JQ_RUNNING_DIR || path.join(os.homedir(), ".jq", "running");
20
+ }
21
+ var isTool = (id) => TOOLS.some((t) => t.id === id);
22
+ var validPort = (n) => typeof n === "number" && Number.isInteger(n) && n >= 1 && n <= 65535;
23
+ function alive(pid) {
24
+ try {
25
+ process.kill(pid, 0);
26
+ return true;
27
+ } catch (e) {
28
+ return e?.code === "EPERM";
29
+ }
30
+ }
31
+ function readRunning(dir = runningDir(), isAlive = alive) {
32
+ const found = { deck: null, groundcrew: null, crosstalk: null, agents: null };
33
+ if (!existsSync(dir)) return found;
34
+ let files;
35
+ try {
36
+ files = readdirSync(dir).filter((f) => f.endsWith(".json"));
37
+ } catch {
38
+ return found;
39
+ }
40
+ for (const file of files) {
41
+ try {
42
+ const entry = JSON.parse(readFileSync(path.join(dir, file), "utf-8"));
43
+ if (!isTool(entry?.tool) || !validPort(entry.port) || typeof entry.pid !== "number" || !isAlive(entry.pid)) continue;
44
+ const usual = TOOLS.find((t) => t.id === entry.tool).port;
45
+ if (found[entry.tool] === null || entry.port === usual) found[entry.tool] = entry.port;
46
+ } catch {
47
+ }
48
+ }
49
+ return found;
50
+ }
51
+ function announce(tool, port, dir = runningDir()) {
52
+ const file = path.join(dir, `${tool}.${process.pid}.json`);
53
+ let removed = false;
54
+ const remove = () => {
55
+ if (removed) return;
56
+ removed = true;
57
+ try {
58
+ unlinkSync(file);
59
+ } catch {
60
+ }
61
+ };
62
+ try {
63
+ mkdirSync(dir, { recursive: true });
64
+ for (const f of readdirSync(dir).filter((n) => n.endsWith(".json"))) {
65
+ try {
66
+ const pid = JSON.parse(readFileSync(path.join(dir, f), "utf-8"))?.pid;
67
+ if (typeof pid !== "number" || !alive(pid)) unlinkSync(path.join(dir, f));
68
+ } catch {
69
+ }
70
+ }
71
+ writeFileSync(file, JSON.stringify({ tool, port, pid: process.pid, started_at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n", { mode: 384 });
72
+ } catch {
73
+ return remove;
74
+ }
75
+ process.once("exit", remove);
76
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
77
+ process.once(signal, () => {
78
+ remove();
79
+ process.exit(signal === "SIGINT" ? 130 : 143);
80
+ });
81
+ }
82
+ return remove;
83
+ }
84
+ function readTeamUrl(file = process.env.JQ_CONFIG || path.join(os.homedir(), ".jq", "config.json")) {
85
+ try {
86
+ const team = JSON.parse(readFileSync(file, "utf-8"))?.team;
87
+ if (typeof team !== "string") return null;
88
+ const url = new URL(team);
89
+ if (url.protocol !== "https:" && url.protocol !== "http:") return null;
90
+ if (url.username || url.password) return null;
91
+ return url.href;
92
+ } catch {
93
+ return null;
94
+ }
95
+ }
96
+ var TOOLBAR_CSS = `
97
+ body{padding-bottom:64px}
98
+ .jqbar{position:fixed;left:0;right:0;bottom:0;z-index:5;display:flex;flex-wrap:wrap;align-items:center;gap:4px 14px;padding:8px 16px;font:13px/1.4 system-ui,sans-serif;background:var(--card,Canvas);color:var(--fg,CanvasText);border-top:1px solid var(--line,GrayText)}
99
+ .jqbar a{color:var(--link,LinkText)}
100
+ .jqbar .here{font-weight:700}
101
+ .jqbar details[open]{order:-1;flex-basis:100%}
102
+ .jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
103
+ .jqbar summary::-webkit-details-marker{display:none}
104
+ .jqbar summary::after{content:" \u25B8"}
105
+ .jqbar details[open] summary::after{content:" \u25BE"}
106
+ .jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
107
+ .jqbar details>div{margin:4px 0 6px;padding:8px 10px;max-width:640px;border:1px solid var(--line,GrayText);border-radius:8px;background:var(--well,Canvas)}
108
+ .jqbar details>div p{margin:0 0 4px}
109
+ .jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
110
+ .jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
111
+ @media print{.jqbar{display:none}body{padding-bottom:0}}
112
+ `;
113
+ var local = (port) => `http://127.0.0.1:${port}`;
114
+ function toolItem(t, o) {
115
+ if (o.here === t.id) return `<span class="here" aria-current="page">${esc(t.name)}</span>`;
116
+ const start = `<p>To start it: <code>${esc(t.run)}</code></p>`;
117
+ if (o.running === null) {
118
+ return `<details><summary>${esc(t.name)} <small>on your computer</small></summary><div><p>${esc(t.name)} shows ${esc(t.what)}. It runs on your own computer, and this page cannot see whether it is running there.</p><p>If it is, it is at <a href="${local(t.port)}">${local(t.port)}</a>.</p>${start}</div></details>`;
119
+ }
120
+ const port = o.running[t.id];
121
+ if (port !== null) return `<a href="${local(port)}" title="${esc(t.what)}">${esc(t.name)}</a>`;
122
+ return `<details><summary>${esc(t.name)} <small>not running</small></summary><div><p>${esc(t.name)} shows ${esc(t.what)}. It is not running on this machine.</p>${start}<p>Then refresh this page.</p></div></details>`;
123
+ }
124
+ function teamItem(o) {
125
+ if (o.here === "team") return '<span class="here" aria-current="page">Team board</span>';
126
+ if (o.team) return `<a href="${esc(o.team)}" title="every machine on the team, on one page">Team board</a>`;
127
+ return '<details><summary>Team board <small>not set up</small></summary><div><p>A team board shows every machine on a team on one page. This machine has no address for one.</p><p>If your team has one, add a <code>"team"</code> line holding its address to <code>~/.jq/config.json</code>.</p><p>To host one: <code>npx @point-seven-studio/jq-deck-server</code></p></div></details>';
128
+ }
129
+ function toolbar(o) {
130
+ return `<nav class="jqbar" aria-label="JQ tools">${TOOLS.map((t) => toolItem(t, o)).join("")}${teamItem(o)}</nav>`;
131
+ }
132
+
133
+ // src/cli.ts
6
134
  import path7 from "path";
7
135
 
8
136
  // ../agents/dist/index.mjs
9
137
  import { execFile as execFile2 } from "child_process";
10
- import { existsSync } from "fs";
138
+ import { existsSync as existsSync2 } from "fs";
11
139
  import { open, readdir, stat } from "fs/promises";
12
140
  import os2 from "os";
13
- import path from "path";
141
+ import path2 from "path";
14
142
  import { promisify as promisify2 } from "util";
15
143
  import { execFile } from "child_process";
16
144
  import { promisify } from "util";
17
- import os from "os";
18
- import { existsSync as existsSync2, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
19
145
  import os3 from "os";
20
- import path2 from "path";
146
+ import { existsSync as existsSync22, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "fs";
147
+ import os32 from "os";
148
+ import path22 from "path";
21
149
  var EDIT_TOOLS = /* @__PURE__ */ new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
22
150
  function looksLikeACheck(command) {
23
151
  return /\b(test|tests|jest|vitest|pytest|mocha|lint|eslint|ruff|tsc|typecheck|type-check|mypy|pyright|check|build|cargo (test|check|clippy)|go (test|vet))\b/i.test(command);
@@ -247,16 +375,16 @@ function lastActivityAt(records) {
247
375
  }
248
376
  return null;
249
377
  }
250
- function deriveState(alive, lastActivityIso, now) {
251
- if (!alive) return "dead";
378
+ function deriveState(alive2, lastActivityIso, now) {
379
+ if (!alive2) return "dead";
252
380
  if (!lastActivityIso) return "stale";
253
381
  const ageS = Math.max(0, (now - Date.parse(lastActivityIso)) / 1e3);
254
382
  if (ageS <= LIVE_WITHIN_S) return "live";
255
383
  if (ageS <= IDLE_WITHIN_S) return "idle";
256
384
  return "stale";
257
385
  }
258
- function deriveWaiting(rec, alive) {
259
- if (!alive || !rec || rec.type !== "assistant") return false;
386
+ function deriveWaiting(rec, alive2) {
387
+ if (!alive2 || !rec || rec.type !== "assistant") return false;
260
388
  return rec.message?.stop_reason === "end_turn";
261
389
  }
262
390
  function deriveAttention(state, waiting) {
@@ -270,7 +398,7 @@ function isTreeAllowed(workingTree, allowlist) {
270
398
  return allowlist.some((t) => t && (workingTree === t || workingTree.startsWith(t.replace(/\/+$/, "") + "/")));
271
399
  }
272
400
  function buildStatusRow(opts) {
273
- const { machine, records, sessionIdFallback, alive, pid, allowlist, now, workingTreeOverride } = opts;
401
+ const { machine, records, sessionIdFallback, alive: alive2, pid, allowlist, now, workingTreeOverride } = opts;
274
402
  const withCwd = [...records].reverse().find((r) => r?.cwd);
275
403
  const workingTree = workingTreeOverride || withCwd?.cwd || "";
276
404
  if (!workingTree) return null;
@@ -280,8 +408,8 @@ function buildStatusRow(opts) {
280
408
  const substantive = lastSubstantive(records);
281
409
  const assistant = lastAssistant(records);
282
410
  const activity = lastActivityAt(records);
283
- const state = deriveState(alive, activity, now);
284
- const waiting = deriveWaiting(substantive, alive);
411
+ const state = deriveState(alive2, activity, now);
412
+ const waiting = deriveWaiting(substantive, alive2);
285
413
  const rawText = assistant ? messageText(assistant) : "";
286
414
  const allowed = isTreeAllowed(workingTree, allowlist);
287
415
  let blocked_question = null;
@@ -478,9 +606,9 @@ async function sampleHost(probe = false) {
478
606
  ]);
479
607
  const disk = parseIostat(iostat);
480
608
  return {
481
- cpuCount: os.cpus()?.length || 0,
482
- load1: parseLoadAvg(load) || os.loadavg()[0] || 0,
483
- memUsedPct: parseVmStat(vmstat, os.totalmem()),
609
+ cpuCount: os3.cpus()?.length || 0,
610
+ load1: parseLoadAvg(load) || os3.loadavg()[0] || 0,
611
+ memUsedPct: parseVmStat(vmstat, os3.totalmem()),
484
612
  swapUsedMb: parseSwapUsedMb(swap),
485
613
  diskReadMbs: disk?.readMbs ?? null,
486
614
  diskWriteMbs: disk?.writeMbs ?? null,
@@ -504,7 +632,7 @@ async function sampleProcs(pids) {
504
632
  }
505
633
  var execFileAsync2 = promisify2(execFile2);
506
634
  function defaultProjectsDir() {
507
- return path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os2.homedir(), ".claude"), "projects");
635
+ return path2.join(process.env.CLAUDE_CONFIG_DIR || path2.join(os2.homedir(), ".claude"), "projects");
508
636
  }
509
637
  var TAIL_RECORDS = 200;
510
638
  async function findTranscripts(dir, out = []) {
@@ -515,7 +643,7 @@ async function findTranscripts(dir, out = []) {
515
643
  return out;
516
644
  }
517
645
  for (const e of entries) {
518
- const full = path.join(dir, e.name);
646
+ const full = path2.join(dir, e.name);
519
647
  if (e.isDirectory()) await findTranscripts(full, out);
520
648
  else if (e.isFile() && e.name.endsWith(".jsonl")) out.push(full);
521
649
  }
@@ -529,10 +657,10 @@ async function repoRoot(dir) {
529
657
  let cur = dir;
530
658
  for (let i = 0; i < 12; i++) {
531
659
  try {
532
- await stat(path.join(cur, ".git"));
660
+ await stat(path2.join(cur, ".git"));
533
661
  break;
534
662
  } catch {
535
- const parent = path.dirname(cur);
663
+ const parent = path2.dirname(cur);
536
664
  if (parent === cur) {
537
665
  cur = dir;
538
666
  break;
@@ -591,7 +719,7 @@ async function pidCwds(pids) {
591
719
  const byCwd = /* @__PURE__ */ new Map();
592
720
  if (pids.length === 0) return byCwd;
593
721
  try {
594
- const lsof = existsSync("/usr/sbin/lsof") ? "/usr/sbin/lsof" : "lsof";
722
+ const lsof = existsSync2("/usr/sbin/lsof") ? "/usr/sbin/lsof" : "lsof";
595
723
  const { stdout } = await execFileAsync2(lsof, ["-a", "-p", pids.join(","), "-d", "cwd", "-Fn"], { maxBuffer: 4 * 1024 * 1024 });
596
724
  let current = null;
597
725
  for (const line of stdout.split("\n")) {
@@ -623,12 +751,12 @@ async function collectRows(opts = {}) {
623
751
  const config = opts.turnCheck;
624
752
  let evidence = null;
625
753
  const row3 = buildStatusRow({
626
- turnCheck: config ? { ...rulesFor(config, tree), muted: config.muted.includes(tree), dismissedAt: config.dismissed[path.basename(file, ".jsonl")] ?? null } : void 0,
754
+ turnCheck: config ? { ...rulesFor(config, tree), muted: config.muted.includes(tree), dismissedAt: config.dismissed[path2.basename(file, ".jsonl")] ?? null } : void 0,
627
755
  onTurnDetail: (detail) => evidence = detail.evidence,
628
756
  machine,
629
757
  records,
630
758
  workingTreeOverride: tree || void 0,
631
- sessionIdFallback: path.basename(file, ".jsonl"),
759
+ sessionIdFallback: path2.basename(file, ".jsonl"),
632
760
  alive: pid !== null,
633
761
  pid,
634
762
  allowlist: opts.questionTrees ?? [],
@@ -687,7 +815,24 @@ async function snapshot(opts = {}) {
687
815
  if (opts.evidence) snap.local = { turn_check };
688
816
  return snap;
689
817
  }
690
- var esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
818
+ var TOOLBAR_CSS2 = `
819
+ body{padding-bottom:64px}
820
+ .jqbar{position:fixed;left:0;right:0;bottom:0;z-index:5;display:flex;flex-wrap:wrap;align-items:center;gap:4px 14px;padding:8px 16px;font:13px/1.4 system-ui,sans-serif;background:var(--card,Canvas);color:var(--fg,CanvasText);border-top:1px solid var(--line,GrayText)}
821
+ .jqbar a{color:var(--link,LinkText)}
822
+ .jqbar .here{font-weight:700}
823
+ .jqbar details[open]{order:-1;flex-basis:100%}
824
+ .jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
825
+ .jqbar summary::-webkit-details-marker{display:none}
826
+ .jqbar summary::after{content:" \u25B8"}
827
+ .jqbar details[open] summary::after{content:" \u25BE"}
828
+ .jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
829
+ .jqbar details>div{margin:4px 0 6px;padding:8px 10px;max-width:640px;border:1px solid var(--line,GrayText);border-radius:8px;background:var(--well,Canvas)}
830
+ .jqbar details>div p{margin:0 0 4px}
831
+ .jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
832
+ .jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
833
+ @media print{.jqbar{display:none}body{padding-bottom:0}}
834
+ `;
835
+ var esc2 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
691
836
  function ago(iso, now) {
692
837
  if (!iso) return "unknown";
693
838
  const s = Math.max(0, Math.floor((now - Date.parse(iso)) / 1e3));
@@ -711,22 +856,22 @@ function totals(rows) {
711
856
  function groupByTree(rows) {
712
857
  const by = /* @__PURE__ */ new Map();
713
858
  for (const r of rows) by.set(r.working_tree, [...by.get(r.working_tree) ?? [], r]);
714
- const needs = (list2) => list2.some((r) => deriveAttention(r.state, r.waiting) === "needs-you");
715
- const latest = (list2) => list2.map((r) => r.last_activity_at || "").sort().pop() || "";
716
- return [...by.entries()].map(([tree, list2]) => ({
859
+ const needs = (list3) => list3.some((r) => deriveAttention(r.state, r.waiting) === "needs-you");
860
+ const latest = (list3) => list3.map((r) => r.last_activity_at || "").sort().pop() || "";
861
+ return [...by.entries()].map(([tree, list3]) => ({
717
862
  tree,
718
- product: list2[0].product,
719
- rows: list2.sort((a, b) => (b.last_activity_at || "").localeCompare(a.last_activity_at || ""))
863
+ product: list3[0].product,
864
+ rows: list3.sort((a, b) => (b.last_activity_at || "").localeCompare(a.last_activity_at || ""))
720
865
  })).sort((a, b) => Number(needs(b.rows)) - Number(needs(a.rows)) || latest(b.rows).localeCompare(latest(a.rows)));
721
866
  }
722
- var hidden = (fields) => Object.entries(fields).map(([name, value]) => `<input type="hidden" name="${name}" value="${esc(value)}">`).join("");
723
- var form = (m, fields, label) => `<form method="post" action="/turn-check">${hidden({ token: m.token, ...fields })}<button type="submit">${esc(label)}</button></form>`;
867
+ var hidden = (fields) => Object.entries(fields).map(([name, value]) => `<input type="hidden" name="${name}" value="${esc2(value)}">`).join("");
868
+ var form = (m, fields, label) => `<form method="post" action="/turn-check">${hidden({ token: m.token, ...fields })}<button type="submit">${esc2(label)}</button></form>`;
724
869
  function whyPanel(r, evidence, m) {
725
- const how = evidence.via === "shell" ? `<code>${esc(evidence.edit)}</code>, a shell command` : `the ${esc(evidence.edit)} tool`;
870
+ const how = evidence.via === "shell" ? `<code>${esc2(evidence.edit)}</code>, a shell command` : `the ${esc2(evidence.edit)} tool`;
726
871
  const verdict = r.turn_check === "failed" ? "The last check after it failed." : "No check ran after it.";
727
872
  const after = evidence.after.length ? `<p>It ran these afterwards. If one of them is how this project checks its work, say so:</p><ul class="cmds">${evidence.after.map((command) => {
728
873
  const text = ruleText(command);
729
- return `<li><code>${esc(command)}</code>${text.length >= 2 ? form(m, { action: "add-rule", kind: "check", tree: r.working_tree, text }, `Count "${text}" as a check here`) : ""}</li>`;
874
+ return `<li><code>${esc2(command)}</code>${text.length >= 2 ? form(m, { action: "add-rule", kind: "check", tree: r.working_tree, text }, `Count "${text}" as a check here`) : ""}</li>`;
730
875
  }).join("")}</ul>` : "";
731
876
  const notEdit = evidence.via === "shell" && ruleText(evidence.edit).length >= 2 ? form(m, { action: "add-rule", kind: "not-edit", tree: r.working_tree, text: ruleText(evidence.edit) }, `"${ruleText(evidence.edit)}" does not edit code here`) : "";
732
877
  return `<details class="why"><summary>Why, and is it wrong?</summary><p>The last edit was ${how}. ${verdict}</p>${after}<div class="acts">${notEdit}` + form(m, { action: "dismiss", session: r.session_id }, "Dismiss this one") + form(m, { action: "mute", tree: r.working_tree }, "Never label this tree") + "</div></details>";
@@ -736,27 +881,27 @@ function sessionRow(r, now, evidence, manage) {
736
881
  const badge = attention === "needs-you" ? '<span class="b need">waiting on a person</span>' : attention === "abandoned" ? '<span class="b old">asked, then left</span>' : "";
737
882
  const check = r.turn_check === "unchecked" ? '<span class="b need">stopped without running a check</span>' : r.turn_check === "failed" ? '<span class="b bad">stopped after a failed check</span>' : "";
738
883
  const res = r.cpu_pct != null || r.rss_mb != null ? `<span class="mut">${r.cpu_pct ?? "?"}% cpu \xB7 ${r.rss_mb ?? "?"} MB</span>` : "";
739
- const question = r.blocked_question ? `<pre>${esc(r.blocked_question)}${r.question_redacted ? "\n[a secret-shaped string was removed]" : ""}</pre>` : attention !== "none" && !r.question_allowed ? '<p class="mut q">Question text is off for this tree.</p>' : "";
884
+ const question = r.blocked_question ? `<pre>${esc2(r.blocked_question)}${r.question_redacted ? "\n[a secret-shaped string was removed]" : ""}</pre>` : attention !== "none" && !r.question_allowed ? '<p class="mut q">Question text is off for this tree.</p>' : "";
740
885
  const why = check && evidence && manage ? whyPanel(r, evidence, manage) : "";
741
- return `<li><span class="s ${r.state}">${r.state}</span> <span class="mut">${esc(r.branch || "no branch")} \xB7 active ${ago(r.last_activity_at, now)} ago</span> ${[badge, check].filter(Boolean).join('<span class="mut"> \xB7 </span>')} ${res}${question}${why}</li>`;
886
+ return `<li><span class="s ${r.state}">${r.state}</span> <span class="mut">${esc2(r.branch || "no branch")} \xB7 active ${ago(r.last_activity_at, now)} ago</span> ${[badge, check].filter(Boolean).join('<span class="mut"> \xB7 </span>')} ${res}${question}${why}</li>`;
742
887
  }
743
888
  function correctionsPanel(snap, m) {
744
889
  const { rules, muted, dismissed } = m.config;
745
890
  const items = [
746
- ...rules.map((rule, index) => `<li><span>${rule.kind === "check" ? "Counts as a check" : "Does not edit code"}: <code>${esc(rule.text)}</code> <span class="mut">in ${esc(rule.tree === "*" ? "every tree" : rule.tree)}</span></span>${form(m, { action: "remove-rule", index: String(index) }, "Remove")}</li>`),
747
- ...muted.map((tree) => `<li><span>Never labelled: <span class="mut">${esc(tree)}</span></span>${form(m, { action: "unmute", tree }, "Label it again")}</li>`),
891
+ ...rules.map((rule, index) => `<li><span>${rule.kind === "check" ? "Counts as a check" : "Does not edit code"}: <code>${esc2(rule.text)}</code> <span class="mut">in ${esc2(rule.tree === "*" ? "every tree" : rule.tree)}</span></span>${form(m, { action: "remove-rule", index: String(index) }, "Remove")}</li>`),
892
+ ...muted.map((tree) => `<li><span>Never labelled: <span class="mut">${esc2(tree)}</span></span>${form(m, { action: "unmute", tree }, "Label it again")}</li>`),
748
893
  ...Object.keys(dismissed).map((session) => {
749
894
  const row3 = snap.sessions.find((r) => r.session_id === session);
750
- return `<li><span>Dismissed: <span class="mut">${esc(row3 ? `${row3.product} \xB7 ${row3.branch || "no branch"}` : `session ${session.slice(0, 8)}`)}</span></span>${form(m, { action: "undismiss", session }, "Undo")}</li>`;
895
+ return `<li><span>Dismissed: <span class="mut">${esc2(row3 ? `${row3.product} \xB7 ${row3.branch || "no branch"}` : `session ${session.slice(0, 8)}`)}</span></span>${form(m, { action: "undismiss", session }, "Undo")}</li>`;
751
896
  })
752
897
  ];
753
- return '<section class="card fix"><h2>Your corrections to the check label</h2>' + (items.length ? `<ul>${items.join("")}</ul>` : '<p class="mut pad">None yet. A label you think is wrong has a "Why, and is it wrong?" link under it.</p>') + '<p class="mut pad">Saved in <code>~/.jq/config.json</code> on this machine. This is the only file JQ Agents writes.</p></section>';
898
+ return '<section class="card fix"><h2>Your corrections to the check label</h2>' + (items.length ? `<ul>${items.join("")}</ul>` : '<p class="mut pad">None yet. A label you think is wrong has a "Why, and is it wrong?" link under it.</p>') + '<p class="mut pad">Saved in <code>~/.jq/config.json</code> on this machine. Apart from its own running note in <code>~/.jq/running/</code>, this is the only file JQ Agents writes.</p></section>';
754
899
  }
755
- function renderPage(snap, now = Date.now(), manage) {
900
+ function renderPage(snap, now = Date.now(), manage, bar = "") {
756
901
  const t = totals(snap.sessions);
757
902
  const b = snap.bottleneck;
758
- const chip = !b ? '<p class="mut">Host not sampled.</p>' : b.kind === "none" ? "" : `<p class="chip">${b.kind === "unknown" ? "Could not tell what this machine is short of." : `Bottleneck: ${esc(b.kind)}${b.reason ? ` (${esc(b.reason)})` : ""}`}</p>`;
759
- const trees = groupByTree(snap.sessions).map((g) => `<section class="card"><h2>${esc(g.product)} <span class="mut">${esc(g.tree)}</span></h2><ul>${g.rows.map((r) => sessionRow(r, now, snap.local?.turn_check[r.session_id], manage)).join("")}</ul></section>`).join("");
903
+ const chip = !b ? '<p class="mut">Host not sampled.</p>' : b.kind === "none" ? "" : `<p class="chip">${b.kind === "unknown" ? "Could not tell what this machine is short of." : `Bottleneck: ${esc2(b.kind)}${b.reason ? ` (${esc2(b.reason)})` : ""}`}</p>`;
904
+ const trees = groupByTree(snap.sessions).map((g) => `<section class="card"><h2>${esc2(g.product)} <span class="mut">${esc2(g.tree)}</span></h2><ul>${g.rows.map((r) => sessionRow(r, now, snap.local?.turn_check[r.session_id], manage)).join("")}</ul></section>`).join("");
760
905
  return `<!doctype html>
761
906
  <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
762
907
  <title>JQ Agents</title>
@@ -780,21 +925,21 @@ code{font:12px ui-monospace,Menlo,monospace;background:var(--well);border-radius
780
925
  button{font:600 12px system-ui,sans-serif;color:var(--fg);background:var(--card);border:1px solid var(--line);border-radius:6px;padding:5px 10px;min-height:30px;cursor:pointer}
781
926
  button:hover{border-color:var(--mut)}button:focus-visible{outline:2px solid var(--fg);outline-offset:2px}.pad{margin:0;padding:8px 12px}
782
927
  pre{white-space:pre-wrap;word-break:break-word;background:var(--well);margin:8px 0 2px;padding:10px;border-radius:8px;font-size:12px}.q{margin:6px 0 0}
783
- </style></head><body><main>
928
+ ${bar ? TOOLBAR_CSS2 : ""}</style></head><body><main>
784
929
  <h1>JQ Agents</h1>
785
- <p class="mut">${esc(snap.machine)} \xB7 read ${esc(snap.generated_at)}. Refresh to read again. Read-only: answer a session where it is running.</p>
930
+ <p class="mut">${esc2(snap.machine)} \xB7 read ${esc2(snap.generated_at)}. Refresh to read again. Read-only: answer a session where it is running.</p>
786
931
  <div class="tot"><div><b>${t.needs_you}</b><span class="mut">waiting on a person</span></div><div><b>${t.abandoned}</b><span class="mut">asked, then left</span></div><div><b>${t.live}</b><span class="mut">live</span></div><div><b>${t.sessions}</b><span class="mut">sessions in ${t.trees} ${t.trees === 1 ? "tree" : "trees"}</span></div></div>
787
932
  ${chip}
788
933
  ${trees || '<p class="mut">No session has been active in the window read.</p>'}
789
934
  ${manage ? correctionsPanel(snap, manage) : ""}
790
- </main></body></html>`;
935
+ </main>${bar}</body></html>`;
791
936
  }
792
937
  function defaultConfigFile() {
793
- return process.env.JQ_CONFIG || path2.join(os3.homedir(), ".jq", "config.json");
938
+ return process.env.JQ_CONFIG || path22.join(os32.homedir(), ".jq", "config.json");
794
939
  }
795
940
  function readAll(file) {
796
- if (!existsSync2(file)) return {};
797
- const parsed = JSON.parse(readFileSync(file, "utf-8"));
941
+ if (!existsSync22(file)) return {};
942
+ const parsed = JSON.parse(readFileSync2(file, "utf-8"));
798
943
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${file} does not hold a JSON object`);
799
944
  return parsed;
800
945
  }
@@ -807,8 +952,9 @@ function readTurnCheckConfig(file = defaultConfigFile()) {
807
952
  }
808
953
 
809
954
  // ../crosstalk/dist/index.mjs
810
- import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, statSync } from "fs";
955
+ import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync3, statSync } from "fs";
811
956
  import path3 from "path";
957
+ import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from "crypto";
812
958
  var BOARD = "board";
813
959
  var DAY_MS = 864e5;
814
960
  function ageDays(sentAt, now) {
@@ -827,7 +973,9 @@ function summarize(m, now) {
827
973
  sent_at: m.sent_at,
828
974
  acked: m.acked,
829
975
  age_days: ageDays(m.sent_at, now),
830
- kind: m.kind ?? null
976
+ kind: m.kind ?? null,
977
+ author: m.author ?? null,
978
+ signature_state: m.signature_state ?? null
831
979
  };
832
980
  }
833
981
  var plural = (n, one, many) => n === 1 ? one : many;
@@ -835,20 +983,20 @@ function waitingBoard(messages, now) {
835
983
  const byInbox = /* @__PURE__ */ new Map();
836
984
  for (const m of messages) {
837
985
  if (m.acked || m.to_session === BOARD) continue;
838
- const list2 = byInbox.get(m.to_session) ?? [];
839
- list2.push(m);
840
- byInbox.set(m.to_session, list2);
986
+ const list3 = byInbox.get(m.to_session) ?? [];
987
+ list3.push(m);
988
+ byInbox.set(m.to_session, list3);
841
989
  }
842
990
  const time = (m) => m.sent_at ? Date.parse(m.sent_at) || Infinity : Infinity;
843
- const inboxes = [...byInbox.entries()].map(([product, list2]) => {
844
- list2.sort((a, b) => time(a) - time(b));
845
- const oldest = list2.find((m) => ageDays(m.sent_at, now) !== null) ?? null;
991
+ const inboxes = [...byInbox.entries()].map(([product, list3]) => {
992
+ list3.sort((a, b) => time(a) - time(b));
993
+ const oldest = list3.find((m) => ageDays(m.sent_at, now) !== null) ?? null;
846
994
  return {
847
995
  product,
848
- unread: list2.length,
996
+ unread: list3.length,
849
997
  oldest_sent_at: oldest?.sent_at ?? null,
850
998
  oldest_age_days: oldest ? ageDays(oldest.sent_at, now) : null,
851
- items: list2.map((m) => summarize(m, now))
999
+ items: list3.map((m) => summarize(m, now))
852
1000
  };
853
1001
  });
854
1002
  inboxes.sort(
@@ -930,19 +1078,19 @@ function deriveThreads(messages, now) {
930
1078
  groups.set(root, [...groups.get(root) ?? [], m]);
931
1079
  }
932
1080
  const time = (m) => m.sent_at ? Date.parse(m.sent_at) || 0 : 0;
933
- const threads = [...groups.values()].map((list2) => {
934
- list2.sort((a, b) => time(a) - time(b) || a.filename.localeCompare(b.filename));
935
- const first = list2[0];
936
- const last = list2[list2.length - 1];
1081
+ const threads = [...groups.values()].map((list3) => {
1082
+ list3.sort((a, b) => time(a) - time(b) || a.filename.localeCompare(b.filename));
1083
+ const first = list3[0];
1084
+ const last = list3[list3.length - 1];
937
1085
  return {
938
1086
  id: first.filename,
939
1087
  subject: first.subject,
940
- participants: [...new Set(list2.flatMap((m) => [m.from_session, m.to_session]))].sort(),
941
- count: list2.length,
942
- unread: list2.filter((m) => !m.acked).length,
1088
+ participants: [...new Set(list3.flatMap((m) => [m.from_session, m.to_session]))].sort(),
1089
+ count: list3.length,
1090
+ unread: list3.filter((m) => !m.acked).length,
943
1091
  first_at: first.sent_at,
944
1092
  last_at: last.sent_at,
945
- messages: list2.map((m) => summarize(m, now))
1093
+ messages: list3.map((m) => summarize(m, now))
946
1094
  };
947
1095
  });
948
1096
  threads.sort((a, b) => (Date.parse(b.last_at ?? "") || 0) - (Date.parse(a.last_at ?? "") || 0) || a.id.localeCompare(b.id));
@@ -996,6 +1144,7 @@ function parseMessage(filename, raw, recipient, acked) {
996
1144
  let kind = null;
997
1145
  let thread = null;
998
1146
  let replyTo = null;
1147
+ let author = null;
999
1148
  let from = "";
1000
1149
  let subject = null;
1001
1150
  let sent = null;
@@ -1013,11 +1162,12 @@ function parseMessage(filename, raw, recipient, acked) {
1013
1162
  else if (m[1] === "thread") thread = m[2].trim() || null;
1014
1163
  else if (m[1] === "reply_to") replyTo = m[2].trim() || null;
1015
1164
  else if (m[1] === "tags") {
1016
- const list2 = m[2].split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
1017
- tags = list2.length ? [...new Set(list2)] : null;
1165
+ const list3 = m[2].split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
1166
+ tags = list3.length ? [...new Set(list3)] : null;
1018
1167
  } else if (m[1] === "expires") expires = /^\d{4}-\d{2}-\d{2}$/.test(m[2].trim()) ? m[2].trim() : null;
1019
1168
  else if (m[1] === "evidence") evidence = m[2].trim() || null;
1020
1169
  else if (m[1] === "settled_by") settledBy = m[2].trim() || null;
1170
+ else if (m[1] === "author") author = m[2].trim() || null;
1021
1171
  }
1022
1172
  }
1023
1173
  if (!from) from = "unknown";
@@ -1036,30 +1186,106 @@ function parseMessage(filename, raw, recipient, acked) {
1036
1186
  tags,
1037
1187
  expires_on: expires,
1038
1188
  evidence: evidence && ["verified", "assumed"].includes(evidence) ? evidence : null,
1039
- settled_by: settledBy && SETTLED_BY.includes(settledBy) ? settledBy : null
1189
+ settled_by: settledBy && SETTLED_BY.includes(settledBy) ? settledBy : null,
1190
+ author
1040
1191
  };
1041
1192
  }
1193
+ var VERSION = "jq-crosstalk-signed-v1";
1194
+ function signingPayload(f) {
1195
+ return Buffer.from(
1196
+ JSON.stringify([VERSION, f.filename, f.from, f.to, f.subject, f.sent, f.kind, f.thread, f.reply_to, f.author, f.body.trim()]),
1197
+ "utf8"
1198
+ );
1199
+ }
1200
+ function fingerprint(publicKey) {
1201
+ return createHash("sha256").update(Buffer.from(publicKey, "base64")).digest("hex").slice(0, 16);
1202
+ }
1203
+ function parseSigners(text) {
1204
+ const signers = /* @__PURE__ */ new Map();
1205
+ for (const line of text.split("\n")) {
1206
+ const m = line.match(/^([a-z0-9][a-z0-9-]*):\s*([A-Za-z0-9+/=]+)\s*$/);
1207
+ if (m) signers.set(m[1], m[2]);
1208
+ }
1209
+ return signers;
1210
+ }
1211
+ function splitMessage(filename, raw) {
1212
+ const fields = { filename, from: "", to: "", subject: "", sent: "", kind: "", thread: "", reply_to: "", author: "", body: raw };
1213
+ let signature = "";
1214
+ const fm = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
1215
+ if (!fm) return { fields, signature };
1216
+ fields.body = fm[2];
1217
+ for (const line of fm[1].split("\n")) {
1218
+ const m = line.match(/^(\w+):\s*(.*)$/);
1219
+ if (!m) continue;
1220
+ const value = m[2].trim();
1221
+ if (m[1] === "signature") signature = value;
1222
+ else if (m[1] === "from" || m[1] === "to" || m[1] === "subject" || m[1] === "sent" || m[1] === "kind" || m[1] === "thread" || m[1] === "reply_to" || m[1] === "author") {
1223
+ fields[m[1]] = value;
1224
+ }
1225
+ }
1226
+ return { fields, signature };
1227
+ }
1228
+ function checkSignature(filename, raw, signers) {
1229
+ const { fields, signature } = splitMessage(filename, raw);
1230
+ const publicKey = signers.get(fields.from);
1231
+ const base = { from: fields.from, author: fields.author };
1232
+ if (!publicKey) return { ...base, state: signature ? "unknown-signer" : "not-required", key: "" };
1233
+ const key = fingerprint(publicKey);
1234
+ if (!signature) return { ...base, state: "unsigned", key };
1235
+ try {
1236
+ const ok = verify(
1237
+ null,
1238
+ signingPayload(fields),
1239
+ createPublicKey({ key: Buffer.from(publicKey, "base64"), format: "der", type: "spki" }),
1240
+ Buffer.from(signature, "base64")
1241
+ );
1242
+ return { ...base, state: ok ? "verified" : "failed", key };
1243
+ } catch {
1244
+ return { ...base, state: "failed", key };
1245
+ }
1246
+ }
1042
1247
  function names(dir) {
1043
1248
  if (!existsSync3(dir)) return [];
1044
- return readdirSync(dir).filter((n) => statSync(path3.join(dir, n)).isDirectory());
1249
+ return readdirSync2(dir).filter((n) => statSync(path3.join(dir, n)).isDirectory());
1045
1250
  }
1046
1251
  function readMailbox(root) {
1047
1252
  if (!existsSync3(path3.join(root, "inbox"))) throw new Error(`not a crosstalk mailbox (no inbox/ folder): ${root}`);
1253
+ const signersFile = path3.join(root, "registry", "signers.txt");
1254
+ const signers = existsSync3(signersFile) ? parseSigners(readFileSync3(signersFile, "utf8")) : /* @__PURE__ */ new Map();
1048
1255
  const byKey = /* @__PURE__ */ new Map();
1049
1256
  for (const [base, acked] of [["inbox", false], ["archive", true]]) {
1050
1257
  for (const name of names(path3.join(root, base))) {
1051
1258
  const dir = path3.join(root, base, name);
1052
- for (const file of readdirSync(dir).filter((f) => f.endsWith(".md"))) {
1053
- const row22 = parseMessage(file, readFileSync2(path3.join(dir, file), "utf8"), name, acked);
1259
+ for (const file of readdirSync2(dir).filter((f) => f.endsWith(".md"))) {
1260
+ const raw = readFileSync3(path3.join(dir, file), "utf8");
1261
+ const row22 = parseMessage(file, raw, name, acked);
1262
+ const state = checkSignature(file, raw, signers).state;
1054
1263
  const key = `${name}/${file}`;
1055
1264
  const prev = byKey.get(key);
1056
- if (!prev || acked && !prev.acked) byKey.set(key, { id: key, ...row22 });
1265
+ if (!prev || acked && !prev.acked) byKey.set(key, { id: key, ...row22, signature_state: state === "not-required" ? null : state });
1057
1266
  }
1058
1267
  }
1059
1268
  }
1060
1269
  return [...byKey.values()].sort((a, b) => a.id.localeCompare(b.id));
1061
1270
  }
1062
- var esc2 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
1271
+ var TOOLBAR_CSS3 = `
1272
+ body{padding-bottom:64px}
1273
+ .jqbar{position:fixed;left:0;right:0;bottom:0;z-index:5;display:flex;flex-wrap:wrap;align-items:center;gap:4px 14px;padding:8px 16px;font:13px/1.4 system-ui,sans-serif;background:var(--card,Canvas);color:var(--fg,CanvasText);border-top:1px solid var(--line,GrayText)}
1274
+ .jqbar a{color:var(--link,LinkText)}
1275
+ .jqbar .here{font-weight:700}
1276
+ .jqbar details[open]{order:-1;flex-basis:100%}
1277
+ .jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
1278
+ .jqbar summary::-webkit-details-marker{display:none}
1279
+ .jqbar summary::after{content:" \u25B8"}
1280
+ .jqbar details[open] summary::after{content:" \u25BE"}
1281
+ .jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
1282
+ .jqbar details>div{margin:4px 0 6px;padding:8px 10px;max-width:640px;border:1px solid var(--line,GrayText);border-radius:8px;background:var(--well,Canvas)}
1283
+ .jqbar details>div p{margin:0 0 4px}
1284
+ .jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
1285
+ .jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
1286
+ @media print{.jqbar{display:none}body{padding-bottom:0}}
1287
+ `;
1288
+ var esc3 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
1063
1289
  var age = (d) => d === null ? "no date" : d === 0 ? "today" : d === 1 ? "1 day" : `${d} days`;
1064
1290
  var SETTLED = {
1065
1291
  source: "settled by checking the source",
@@ -1069,21 +1295,23 @@ var SETTLED = {
1069
1295
  nobody: "no one answered"
1070
1296
  };
1071
1297
  function row(m, bodies, note, showTo = false) {
1072
- const kind = m.kind && m.kind !== "brief" ? `<span class="kind">${esc2(m.kind)}</span> ` : "";
1073
- const to = showTo ? ` <span class="mut">to</span> <span class="chip">${esc2(m.to_session)}</span>` : "";
1074
- return `<details><summary><span class="chip">${esc2(m.from_session)}</span>${to} ${kind}<span class="subj">${esc2(m.subject || "(no subject)")}</span> <span class="note">${esc2(note)}</span></summary><p class="file">${esc2(m.filename)}</p><pre>${esc2(bodies[m.id] ?? "")}</pre></details>`;
1298
+ const kind = m.kind && m.kind !== "brief" ? `<span class="kind">${esc3(m.kind)}</span> ` : "";
1299
+ const to = showTo ? ` <span class="mut">to</span> <span class="chip">${esc3(m.to_session)}</span>` : "";
1300
+ const who = m.author ? ` <span class="mut">${esc3(m.author)}</span>` : "";
1301
+ const signed = m.signature_state === "verified" ? ' <span class="kind">signed</span>' : m.signature_state ? ` <span class="kind">${m.signature_state === "unknown-signer" ? "signature not checked" : "NOT VERIFIED"}</span>` : "";
1302
+ return `<details><summary><span class="chip">${esc3(m.from_session)}</span>${who}${signed}${to} ${kind}<span class="subj">${esc3(m.subject || "(no subject)")}</span> <span class="note">${esc3(note)}</span></summary><p class="file">${esc3(m.filename)}</p><pre>${esc3(bodies[m.id] ?? "")}</pre></details>`;
1075
1303
  }
1076
1304
  function post(p, bodies) {
1077
1305
  const state = p.state === "closed" ? SETTLED[p.settled_by ?? ""] ?? "closed" : p.state === "expired" ? `past its date (${p.expires_on})` : `open until ${p.expires_on ?? "closed"}`;
1078
1306
  const replies = p.replies.map((r) => row(r, bodies, r.evidence === "verified" ? "checked" : r.evidence === "assumed" ? "from memory, not checked" : "did not say how they know")).join("");
1079
- return `<section class="card"><h3>${esc2(p.title || "(no title)")} ${p.tags.map((t) => `<span class="tag">${esc2(t)}</span>`).join(" ")} <span class="state ${p.state}">${esc2(state)}</span></h3>${row(p.post, bodies, p.post.age_days ? `asked ${age(p.post.age_days)} ago` : "asked today")}${replies}${p.closing ? row(p.closing, bodies, "closing note") : ""}${p.replies.length === 0 && p.state !== "closed" ? '<p class="mut">No replies yet.</p>' : ""}</section>`;
1307
+ return `<section class="card"><h3>${esc3(p.title || "(no title)")} ${p.tags.map((t) => `<span class="tag">${esc3(t)}</span>`).join(" ")} <span class="state ${p.state}">${esc3(state)}</span></h3>${row(p.post, bodies, p.post.age_days ? `asked ${age(p.post.age_days)} ago` : "asked today")}${replies}${p.closing ? row(p.closing, bodies, "closing note") : ""}${p.replies.length === 0 && p.state !== "closed" ? '<p class="mut">No replies yet.</p>' : ""}</section>`;
1080
1308
  }
1081
- function renderPage2(r) {
1309
+ function renderPage2(r, bar = "") {
1082
1310
  const waiting = r.waiting.inboxes.map(
1083
- (i) => `<section class="card"><h3>${esc2(i.product)} inbox <span class="note">${i.unread} unread, oldest ${age(i.oldest_age_days)}</span></h3>${i.items.map((m) => row(m, r.bodies, `unread, ${age(m.age_days)}`)).join("")}</section>`
1311
+ (i) => `<section class="card"><h3>${esc3(i.product)} inbox <span class="note">${i.unread} unread, oldest ${age(i.oldest_age_days)}</span></h3>${i.items.map((m) => row(m, r.bodies, `unread, ${age(m.age_days)}`)).join("")}</section>`
1084
1312
  ).join("");
1085
1313
  const threads = r.threads.map(
1086
- (t) => `<section class="card"><h3>${esc2(t.subject || "(no subject)")} <span class="note">${t.count} ${t.count === 1 ? "message" : "messages"}${t.unread ? `, ${t.unread} unread` : ""} \xB7 ${t.participants.map(esc2).join(", ")}</span></h3>${t.messages.map((m) => row(m, r.bodies, m.acked ? age(m.age_days) : `unread, ${age(m.age_days)}`, true)).join("")}</section>`
1314
+ (t) => `<section class="card"><h3>${esc3(t.subject || "(no subject)")} <span class="note">${t.count} ${t.count === 1 ? "message" : "messages"}${t.unread ? `, ${t.unread} unread` : ""} \xB7 ${t.participants.map(esc3).join(", ")}</span></h3>${t.messages.map((m) => row(m, r.bodies, m.acked ? age(m.age_days) : `unread, ${age(m.age_days)}`, true)).join("")}</section>`
1087
1315
  ).join("");
1088
1316
  return `<!doctype html>
1089
1317
  <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
@@ -1101,14 +1329,14 @@ details{border-top:1px solid var(--line)}summary{cursor:pointer;padding:8px 12px
1101
1329
  .subj{font-weight:500}.file{font-family:ui-monospace,monospace;margin:0;padding:0 12px;word-break:break-all}
1102
1330
  pre{white-space:pre-wrap;word-break:break-word;background:var(--well);margin:8px 12px 12px;padding:10px;border-radius:8px;font-size:12px;max-height:420px;overflow:auto}
1103
1331
  .state{font-size:12px}.state.open{color:var(--ok)}.state.expired{color:var(--bad)}.state.closed{color:var(--mut)}
1104
- </style></head><body><main>
1332
+ ${bar ? TOOLBAR_CSS3 : ""}</style></head><body><main>
1105
1333
  <h1>Crosstalk</h1>
1106
- <p class="note">${esc2(r.mailbox)} \xB7 ${r.total} messages \xB7 read ${esc2(r.generated_at)}. Refresh to read again. This page is read-only.</p>
1107
- <h2>Waiting</h2><p class="lead">${esc2(r.waiting.headline)}</p>${waiting}
1108
- <h2>Board</h2><p class="lead">${esc2(r.board.headline)}</p>${r.board.open.map((p) => post(p, r.bodies)).join("")}
1334
+ <p class="note">${esc3(r.mailbox)} \xB7 ${r.total} messages \xB7 read ${esc3(r.generated_at)}. Refresh to read again. This page is read-only.</p>
1335
+ <h2>Waiting</h2><p class="lead">${esc3(r.waiting.headline)}</p>${waiting}
1336
+ <h2>Board</h2><p class="lead">${esc3(r.board.headline)}</p>${r.board.open.map((p) => post(p, r.bodies)).join("")}
1109
1337
  ${r.board.closed.length ? `<details class="card"><summary>${r.board.closed.length} closed</summary>${r.board.closed.map((p) => post(p, r.bodies)).join("")}</details>` : ""}
1110
1338
  <h2>Threads</h2><p class="note">The ${r.threads.length} with the newest activity. Where a message carries no thread id, threads are worked out from replies that cite a message or reuse its subject, so some related mail shows as separate.</p>${threads}
1111
- </main></body></html>`;
1339
+ </main>${bar}</body></html>`;
1112
1340
  }
1113
1341
  var THREADS_SHOWN = 60;
1114
1342
  function buildReport(root, now = Date.now()) {
@@ -1130,7 +1358,7 @@ function buildReport(root, now = Date.now()) {
1130
1358
  }
1131
1359
 
1132
1360
  // ../groundcrew/dist/index.mjs
1133
- import { existsSync as existsSync4, readFileSync as readFileSync3, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
1361
+ import { existsSync as existsSync4, readFileSync as readFileSync4, readdirSync as readdirSync3, statSync as statSync2 } from "fs";
1134
1362
  import os4 from "os";
1135
1363
  import path4 from "path";
1136
1364
  var DOCS = "https://code.claude.com/docs/en";
@@ -1231,10 +1459,10 @@ var NO_PROMPT_MODES = /* @__PURE__ */ new Set(["bypassPermissions", "auto"]);
1231
1459
  function proseFindings(facts) {
1232
1460
  const files = facts.settings;
1233
1461
  const covers = (rules, command) => rules.some((rule) => ruleCovers(rule, command));
1234
- const [deny, ask, allow] = [all(files, (f) => f.deny), all(files, (f) => f.ask), all(files, (f) => f.allow)];
1462
+ const [deny, ask2, allow] = [all(files, (f) => f.deny), all(files, (f) => f.ask), all(files, (f) => f.allow)];
1235
1463
  const noPrompt = files.some((f) => f.defaultMode !== null && NO_PROMPT_MODES.has(f.defaultMode));
1236
1464
  return (facts.restricted ?? []).map((r) => {
1237
- const enforced = covers(deny, r.command) || r.kind === "ask" && covers(ask, r.command);
1465
+ const enforced = covers(deny, r.command) || r.kind === "ask" && covers(ask2, r.command);
1238
1466
  const state = enforced ? "enforced" : covers(allow, r.command) || noPrompt ? "allowed" : r.kind === "ask" ? "prompt" : "open";
1239
1467
  return { ...r, state };
1240
1468
  });
@@ -1632,7 +1860,7 @@ var configDir = () => process.env.CLAUDE_CONFIG_DIR || path4.join(home(), ".clau
1632
1860
  var tilde = (file) => file.startsWith(home()) ? `~${file.slice(home().length)}` : file;
1633
1861
  function canRead(project) {
1634
1862
  try {
1635
- readdirSync2(project);
1863
+ readdirSync3(project);
1636
1864
  return true;
1637
1865
  } catch {
1638
1866
  return false;
@@ -1640,7 +1868,7 @@ function canRead(project) {
1640
1868
  }
1641
1869
  function readJson(file) {
1642
1870
  try {
1643
- return JSON.parse(readFileSync3(file, "utf-8"));
1871
+ return JSON.parse(readFileSync4(file, "utf-8"));
1644
1872
  } catch {
1645
1873
  return null;
1646
1874
  }
@@ -1648,7 +1876,7 @@ function readJson(file) {
1648
1876
  function countFiles(dir, test) {
1649
1877
  if (!existsSync4(dir)) return 0;
1650
1878
  let total = 0;
1651
- for (const entry of readdirSync2(dir, { withFileTypes: true })) {
1879
+ for (const entry of readdirSync3(dir, { withFileTypes: true })) {
1652
1880
  if (entry.isDirectory()) total += countFiles(path4.join(dir, entry.name), test);
1653
1881
  else if (test(entry.name)) total += 1;
1654
1882
  }
@@ -1656,7 +1884,7 @@ function countFiles(dir, test) {
1656
1884
  }
1657
1885
  function markdownFiles(dir) {
1658
1886
  if (!existsSync4(dir)) return [];
1659
- return readdirSync2(dir, { withFileTypes: true }).flatMap(
1887
+ return readdirSync3(dir, { withFileTypes: true }).flatMap(
1660
1888
  (entry) => entry.isDirectory() ? markdownFiles(path4.join(dir, entry.name)) : entry.name.endsWith(".md") ? [path4.join(dir, entry.name)] : []
1661
1889
  );
1662
1890
  }
@@ -1664,7 +1892,7 @@ function findSecretFiles(root, relative, depth) {
1664
1892
  const dir = path4.join(root, relative);
1665
1893
  if (depth > SECRET_DEPTH || !existsSync4(dir)) return [];
1666
1894
  const found = [];
1667
- for (const entry of readdirSync2(dir, { withFileTypes: true })) {
1895
+ for (const entry of readdirSync3(dir, { withFileTypes: true })) {
1668
1896
  const here = relative ? `${relative}/${entry.name}` : entry.name;
1669
1897
  if (entry.isDirectory()) {
1670
1898
  if (!SKIP_DIRS.has(entry.name) && !entry.name.startsWith(".")) found.push(...findSecretFiles(root, here, depth + 1));
@@ -1688,11 +1916,11 @@ function hookCommands(hooks) {
1688
1916
  function subagentFiles(dir) {
1689
1917
  if (!existsSync4(dir)) return [];
1690
1918
  const found = [];
1691
- for (const entry of readdirSync2(dir, { withFileTypes: true })) {
1919
+ for (const entry of readdirSync3(dir, { withFileTypes: true })) {
1692
1920
  const file = path4.join(dir, entry.name);
1693
1921
  if (entry.isDirectory()) found.push(...subagentFiles(file));
1694
1922
  else if (entry.name.endsWith(".md")) {
1695
- const frontmatter = /^---\n([\s\S]*?)\n---/.exec(readFileSync3(file, "utf-8"))?.[1] ?? "";
1923
+ const frontmatter = /^---\n([\s\S]*?)\n---/.exec(readFileSync4(file, "utf-8"))?.[1] ?? "";
1696
1924
  found.push({ name: entry.name.replace(/\.md$/, ""), limitsTools: /^(tools|disallowedTools)\s*:/m.test(frontmatter) });
1697
1925
  }
1698
1926
  }
@@ -1706,7 +1934,7 @@ function gather(project) {
1706
1934
  const restricted = [];
1707
1935
  const memoryFile = (file, instructions = true) => {
1708
1936
  if (!existsSync4(file) || !statSync2(file).isFile()) return null;
1709
- const text = readFileSync3(file, "utf-8");
1937
+ const text = readFileSync4(file, "utf-8");
1710
1938
  filesRead.push(label(file));
1711
1939
  if (instructions) restricted.push(...findRestrictedCommands(text, label(file)));
1712
1940
  return { label: label(file), lines: text.split("\n").length - (text.endsWith("\n") ? 1 : 0), bytes: Buffer.byteLength(text) };
@@ -1719,7 +1947,7 @@ function gather(project) {
1719
1947
  path4.join(configDir(), "CLAUDE.md")
1720
1948
  ].map((file) => memoryFile(file)).filter((file) => file !== null);
1721
1949
  for (const dir of [path4.join(project, ".claude", "rules"), path4.join(configDir(), "rules")]) {
1722
- for (const file of markdownFiles(dir)) restricted.push(...findRestrictedCommands(readFileSync3(file, "utf-8"), label(file)));
1950
+ for (const file of markdownFiles(dir)) restricted.push(...findRestrictedCommands(readFileSync4(file, "utf-8"), label(file)));
1723
1951
  }
1724
1952
  const settingsFile = (scope, file) => {
1725
1953
  const json = readJson(file);
@@ -1778,7 +2006,24 @@ function gather(project) {
1778
2006
  }
1779
2007
  };
1780
2008
  }
1781
- var esc3 = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2009
+ var TOOLBAR_CSS4 = `
2010
+ body{padding-bottom:64px}
2011
+ .jqbar{position:fixed;left:0;right:0;bottom:0;z-index:5;display:flex;flex-wrap:wrap;align-items:center;gap:4px 14px;padding:8px 16px;font:13px/1.4 system-ui,sans-serif;background:var(--card,Canvas);color:var(--fg,CanvasText);border-top:1px solid var(--line,GrayText)}
2012
+ .jqbar a{color:var(--link,LinkText)}
2013
+ .jqbar .here{font-weight:700}
2014
+ .jqbar details[open]{order:-1;flex-basis:100%}
2015
+ .jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
2016
+ .jqbar summary::-webkit-details-marker{display:none}
2017
+ .jqbar summary::after{content:" \u25B8"}
2018
+ .jqbar details[open] summary::after{content:" \u25BE"}
2019
+ .jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
2020
+ .jqbar details>div{margin:4px 0 6px;padding:8px 10px;max-width:640px;border:1px solid var(--line,GrayText);border-radius:8px;background:var(--well,Canvas)}
2021
+ .jqbar details>div p{margin:0 0 4px}
2022
+ .jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
2023
+ .jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
2024
+ @media print{.jqbar{display:none}body{padding-bottom:0}}
2025
+ `;
2026
+ var esc22 = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1782
2027
  var STATUS = {
1783
2028
  fail: { icon: "\u2715", word: "Fix" },
1784
2029
  warn: { icon: "!", word: "Look" },
@@ -1827,15 +2072,15 @@ function done(){b.textContent='Copied';setTimeout(function(){b.textContent='Copy
1827
2072
  function old(){var a=document.createElement('textarea');a.value=t;document.body.appendChild(a);a.select();document.execCommand('copy');a.remove();done()}
1828
2073
  if(navigator.clipboard&&window.isSecureContext){navigator.clipboard.writeText(t).then(done,old)}else{old()}});`;
1829
2074
  var dot = (status) => `<span class="dot s-${status}" aria-hidden="true">${STATUS[status].icon}</span>`;
1830
- var sourceLink = (check) => `<a href="${esc3(check.source)}" target="_blank" rel="noopener noreferrer">${esc3(check.source.replace(/^https:\/\/code\.claude\.com\/docs\/en\//, "docs: ").replace(/\.md$/, ""))}</a>`;
2075
+ var sourceLink = (check) => `<a href="${esc22(check.source)}" target="_blank" rel="noopener noreferrer">${esc22(check.source.replace(/^https:\/\/code\.claude\.com\/docs\/en\//, "docs: ").replace(/\.md$/, ""))}</a>`;
1831
2076
  function fixCard(check) {
1832
2077
  const status = STATUS[check.status];
1833
2078
  const id = anchor(check);
1834
2079
  const isCommand = check.prompt.startsWith("/");
1835
- const prompt = check.prompt ? `<div class="prompt"><header>${isCommand ? "Type this command in Claude Code" : "Paste this into Claude Code"}<button type="button" data-copy="${id}-prompt">Copy</button></header><pre id="${id}-prompt">${esc3(check.prompt)}</pre></div>` : "";
1836
- return `<section class="check s-${check.status}" id="${id}"><h3>${dot(check.status)}${esc3(check.title)}<span class="word">${status.word}</span></h3><p>${esc3(check.detail)}</p>${check.fix ? `<p class="fix"><b>What to change:</b> ${esc3(check.fix)}</p>` : ""}${prompt}<p class="src mut">Rests on ${sourceLink(check)}</p></section>`;
2080
+ const prompt = check.prompt ? `<div class="prompt"><header>${isCommand ? "Type this command in Claude Code" : "Paste this into Claude Code"}<button type="button" data-copy="${id}-prompt">Copy</button></header><pre id="${id}-prompt">${esc22(check.prompt)}</pre></div>` : "";
2081
+ return `<section class="check s-${check.status}" id="${id}"><h3>${dot(check.status)}${esc22(check.title)}<span class="word">${status.word}</span></h3><p>${esc22(check.detail)}</p>${check.fix ? `<p class="fix"><b>What to change:</b> ${esc22(check.fix)}</p>` : ""}${prompt}<p class="src mut">Rests on ${sourceLink(check)}</p></section>`;
1837
2082
  }
1838
- var row2 = (check) => `<li>${dot(check.status)}<b>${esc3(check.title)}<span class="mut"> \xB7 ${STATUS[check.status].word}</span></b><span class="d">${esc3(check.detail)}</span><span class="src mut">${sourceLink(check)}</span></li>`;
2083
+ var row2 = (check) => `<li>${dot(check.status)}<b>${esc22(check.title)}<span class="mut"> \xB7 ${STATUS[check.status].word}</span></b><span class="d">${esc22(check.detail)}</span><span class="src mut">${sourceLink(check)}</span></li>`;
1839
2084
  var LAYER_DOT = { fix: "fail", look: "warn", good: "pass", facts: "info", none: "info" };
1840
2085
  function layerCount(row22) {
1841
2086
  const judged = row22.pass + row22.warn + row22.fail;
@@ -1845,23 +2090,23 @@ function layerCount(row22) {
1845
2090
  function layerPanel(checks) {
1846
2091
  const rows = layerSummary(checks).map((row22) => {
1847
2092
  const about = LAYERS.find((l) => l.key === row22.layer);
1848
- return `<li>${dot(LAYER_DOT[row22.state])}<b>${about.title}<span class="mut"> \xB7 ${layerCount(row22)}</span></b><span class="d">${esc3(about.what)} <span class="mut">${esc3(about.unchecked)}</span></span></li>`;
2093
+ return `<li>${dot(LAYER_DOT[row22.state])}<b>${about.title}<span class="mut"> \xB7 ${layerCount(row22)}</span></b><span class="d">${esc22(about.what)} <span class="mut">${esc22(about.unchecked)}</span></span></li>`;
1849
2094
  });
1850
2095
  return `<h2>Your harness, layer by layer</h2><p class="mut">An agent is a model and what surrounds it. These are six parts of what surrounds it, with what the checks below found in each.</p><ul class="rows">${rows.join("")}</ul>`;
1851
2096
  }
1852
- function renderPage3(report2) {
2097
+ function renderPage3(report2, toolsBar = "") {
1853
2098
  const { summary } = report2;
1854
2099
  const judged = summary.pass + summary.warn + summary.fail;
1855
2100
  const bar = ["fail", "warn", "pass"].filter((s) => summary[s] > 0).map((s) => `<i class="b-${s}" style="flex:${summary[s]}"></i>`).join("");
1856
2101
  const sorted = [...report2.checks].sort((a, b) => ORDER.indexOf(a.status) - ORDER.indexOf(b.status));
1857
2102
  const fixes = sorted.filter(needsFix);
1858
- const todo = fixes.length ? `<h2>Do these first</h2><ul class="todo">${fixes.map((c) => `<li>${dot(c.status)}<a href="#${anchor(c)}">${esc3(c.title)}</a><span class="mut">${GROUP_TITLE[c.group]}</span></li>`).join("")}</ul>` : '<h2>Nothing to fix</h2><p class="mut">Every check that can fail passes.</p>';
2103
+ const todo = fixes.length ? `<h2>Do these first</h2><ul class="todo">${fixes.map((c) => `<li>${dot(c.status)}<a href="#${anchor(c)}">${esc22(c.title)}</a><span class="mut">${GROUP_TITLE[c.group]}</span></li>`).join("")}</ul>` : '<h2>Nothing to fix</h2><p class="mut">Every check that can fail passes.</p>';
1859
2104
  const groups = GROUPS.map((group) => {
1860
2105
  const mine = sorted.filter((c) => c.group === group.key);
1861
2106
  const rest = mine.filter((c) => !needsFix(c));
1862
2107
  return `<h2>${GROUP_TITLE[group.key]}</h2><p class="mut">${group.intro}</p>${mine.filter(needsFix).map(fixCard).join("")}` + (rest.length ? `<ul class="rows">${rest.map(row2).join("")}</ul>` : "");
1863
2108
  }).join("");
1864
- return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JQ Groundcrew: ${esc3(report2.project)}</title><style>${CSS}</style></head><body><main><h1>JQ Groundcrew</h1><p class="mut">The setup check for Claude Code. How it is set up for <code>${esc3(report2.project)}</code>. Read ${esc3(report2.generatedAt)}. Refresh to read again.</p><div class="score"><div class="tile"><b>${summary.fail}</b><span>to fix</span></div><div class="tile"><b>${summary.warn}</b><span>to look at</span></div><div class="tile"><b>${summary.pass}</b><span>good</span></div><div class="tile"><b>${summary.score}%</b><span>of ${judged} checks pass</span></div></div><div class="bar" role="img" aria-label="${summary.fail} to fix, ${summary.warn} to look at, ${summary.pass} good">${bar}</div>` + todo + layerPanel(report2.checks) + groups + `<footer><p>This page was made on your machine from the files below, and it loads nothing, so nothing left the machine. Its one script copies a prompt to your clipboard when you press Copy. It read settings and your instruction files, and counted the rest. It did not read the contents of any secret file, and it read no session transcript.</p><p>A suggested prompt asks Claude Code to show its plan or its diff first. Read that before you approve it.</p><ul>${report2.filesRead.map((file) => `<li><code>${esc3(file)}</code></li>`).join("")}</ul><p>Each check names the page of Anthropic\u2019s Claude Code documentation it rests on. The documentation was checked on 2026-11-14 and can change.</p></footer></main><script>${COPY_SCRIPT}</script></body></html>
2109
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JQ Groundcrew: ${esc22(report2.project)}</title><style>${CSS}${toolsBar ? TOOLBAR_CSS4 : ""}</style></head><body><main><h1>JQ Groundcrew</h1><p class="mut">The setup check for Claude Code. How it is set up for <code>${esc22(report2.project)}</code>. Read ${esc22(report2.generatedAt)}. Refresh to read again.</p><div class="score"><div class="tile"><b>${summary.fail}</b><span>to fix</span></div><div class="tile"><b>${summary.warn}</b><span>to look at</span></div><div class="tile"><b>${summary.pass}</b><span>good</span></div><div class="tile"><b>${summary.score}%</b><span>of ${judged} checks pass</span></div></div><div class="bar" role="img" aria-label="${summary.fail} to fix, ${summary.warn} to look at, ${summary.pass} good">${bar}</div>` + todo + layerPanel(report2.checks) + groups + `<footer><p>This page was made on your machine from the files below, and it loads nothing, so nothing left the machine. Its one script copies a prompt to your clipboard when you press Copy. It read settings and your instruction files, and counted the rest. It did not read the contents of any secret file, and it read no session transcript.</p><p>A suggested prompt asks Claude Code to show its plan or its diff first. Read that before you approve it.</p><ul>${report2.filesRead.map((file) => `<li><code>${esc22(file)}</code></li>`).join("")}</ul><p>Each check names the page of Anthropic\u2019s Claude Code documentation it rests on. The documentation was checked on 2026-11-14 and can change.</p></footer></main>${toolsBar}<script>${COPY_SCRIPT}</script></body></html>
1865
2110
  `;
1866
2111
  }
1867
2112
  function report(project) {
@@ -1871,12 +2116,12 @@ function report(project) {
1871
2116
  }
1872
2117
 
1873
2118
  // src/collect.ts
1874
- import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
2119
+ import { existsSync as existsSync6, readdirSync as readdirSync4, readFileSync as readFileSync6, statSync as statSync3 } from "fs";
1875
2120
  import path6 from "path";
1876
2121
 
1877
2122
  // src/deck.ts
1878
- import { createHash } from "crypto";
1879
- import { existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
2123
+ import { createHash as createHash2 } from "crypto";
2124
+ import { existsSync as existsSync5, readFileSync as readFileSync5 } from "fs";
1880
2125
  import os5 from "os";
1881
2126
  import path5 from "path";
1882
2127
  var expandHome = (p) => p === "~" || p.startsWith("~/") ? path5.join(os5.homedir(), p.slice(1)) : p;
@@ -1887,7 +2132,7 @@ function loadConfig(file) {
1887
2132
  if (!existsSync5(file)) return {};
1888
2133
  let raw;
1889
2134
  try {
1890
- raw = JSON.parse(readFileSync4(file, "utf8"));
2135
+ raw = JSON.parse(readFileSync5(file, "utf8"));
1891
2136
  } catch (e) {
1892
2137
  throw new Error(`cannot read ${file}: ${e?.message || e}`);
1893
2138
  }
@@ -1915,7 +2160,7 @@ function findMailbox(opts) {
1915
2160
  dir = up;
1916
2161
  }
1917
2162
  }
1918
- var repoId = (tree) => createHash("sha1").update(tree).digest("hex").slice(0, 10);
2163
+ var repoId = (tree) => createHash2("sha1").update(tree).digest("hex").slice(0, 10);
1919
2164
  function matchInbox(folder, inboxes) {
1920
2165
  const f = folder.toLowerCase();
1921
2166
  const exact = inboxes.find((i) => i.toLowerCase() === f);
@@ -2058,13 +2303,13 @@ function remoteOf(tree) {
2058
2303
  try {
2059
2304
  let gitDir = path6.join(tree, ".git");
2060
2305
  if (statSync3(gitDir).isFile()) {
2061
- const m = /^gitdir:\s*(.+)$/m.exec(readFileSync5(gitDir, "utf8"));
2306
+ const m = /^gitdir:\s*(.+)$/m.exec(readFileSync6(gitDir, "utf8"));
2062
2307
  if (!m) return null;
2063
2308
  gitDir = path6.resolve(tree, m[1].trim());
2064
2309
  const common = path6.join(gitDir, "commondir");
2065
- if (existsSync6(common)) gitDir = path6.resolve(gitDir, readFileSync5(common, "utf8").trim());
2310
+ if (existsSync6(common)) gitDir = path6.resolve(gitDir, readFileSync6(common, "utf8").trim());
2066
2311
  }
2067
- return originIn(readFileSync5(path6.join(gitDir, "config"), "utf8"));
2312
+ return originIn(readFileSync6(path6.join(gitDir, "config"), "utf8"));
2068
2313
  } catch {
2069
2314
  return null;
2070
2315
  }
@@ -2084,7 +2329,7 @@ async function collectOverview(opts) {
2084
2329
  if (opts.mailbox) {
2085
2330
  try {
2086
2331
  waiting = waitingBoard(readMailbox(opts.mailbox), opts.now ?? Date.now());
2087
- inboxes = readdirSync3(path6.join(opts.mailbox, "inbox"), { withFileTypes: true }).filter((e) => e.isDirectory() && e.name !== BOARD).map((e) => e.name);
2332
+ inboxes = readdirSync4(path6.join(opts.mailbox, "inbox"), { withFileTypes: true }).filter((e) => e.isDirectory() && e.name !== BOARD).map((e) => e.name);
2088
2333
  } catch (e) {
2089
2334
  mailNote = String(e?.message || e);
2090
2335
  }
@@ -2130,8 +2375,8 @@ function overview(o) {
2130
2375
  const rows = o.repos.map(
2131
2376
  (r) => `<tr><th scope="row">${esc4(r.name)}<span class="path">${esc4(r.tree)}</span></th><td data-l="Sessions">${sessionsCell(r)}</td><td data-l="Setup">${setupCell(r)}</td><td data-l="Mail">${mailCell(r)}</td></tr>`
2132
2377
  ).join("");
2133
- const unmatched = o.mail?.unmatched.length ? `<p class="mut note">Unread mail for an inbox with no repository on this page: ${o.mail.unmatched.map((u) => `${esc4(u.inbox)} (${u.unread})`).join(", ")}. <a href="/?tab=mail">Open Mail</a>. To tie an inbox to a folder, add it under <code>names</code> in the config file.</p>` : "";
2134
- return `<div class="card"><table><thead><tr><th scope="col">Repository</th><th scope="col">Sessions</th><th scope="col">Setup</th><th scope="col">Mail</th></tr></thead><tbody>${rows}</tbody></table></div>${unmatched}`;
2378
+ const unmatched2 = o.mail?.unmatched.length ? `<p class="mut note">Unread mail for an inbox with no repository on this page: ${o.mail.unmatched.map((u) => `${esc4(u.inbox)} (${u.unread})`).join(", ")}. <a href="/?tab=mail">Open Mail</a>. To tie an inbox to a folder, add it under <code>names</code> in the config file.</p>` : "";
2379
+ return `<div class="card"><table><thead><tr><th scope="col">Repository</th><th scope="col">Sessions</th><th scope="col">Setup</th><th scope="col">Mail</th></tr></thead><tbody>${rows}</tbody></table></div>${unmatched2}`;
2135
2380
  }
2136
2381
  function setupTab(o, asked) {
2137
2382
  const chosen = pickRepo(o.repos, asked);
@@ -2146,7 +2391,7 @@ function mailTab(o) {
2146
2391
  }
2147
2392
  return '<iframe title="Mailbox" src="/raw/mail"></iframe>';
2148
2393
  }
2149
- function renderShell(o, tab, repo, version) {
2394
+ function renderShell(o, tab, repo, version, bar = "") {
2150
2395
  const body = tab === "overview" ? overview(o) : tab === "sessions" ? '<iframe title="Sessions" src="/raw/sessions"></iframe>' : tab === "setup" ? setupTab(o, repo) : mailTab(o);
2151
2396
  const needs = o.repos.reduce((n, r) => n + r.needs_you, 0);
2152
2397
  const failing = o.repos.filter((r) => r.setup && r.setup.fail > 0).length;
@@ -2182,7 +2427,7 @@ tbody th{font-weight:600}.path{display:block;font-weight:400;font-size:12px;colo
2182
2427
  .chip.on{border-color:var(--fg);font-weight:600}
2183
2428
  code,pre{font:12px ui-monospace,monospace;background:var(--well);border-radius:4px;padding:1px 4px}pre{padding:10px;overflow-x:auto}
2184
2429
  @media (max-width:640px){thead{display:none}tr{display:block;border-top:1px solid var(--line);padding:8px 0}th,td{display:block;border:0;padding:3px 12px}td::before{content:attr(data-l) ": ";color:var(--mut);font-size:12px}}
2185
- </style></head><body>
2430
+ ${bar ? TOOLBAR_CSS : ""}</style></head><body>
2186
2431
  <header>
2187
2432
  <h1>JQ Deck</h1>
2188
2433
  <p class="head">${esc4(o.headline)}</p>
@@ -2191,7 +2436,7 @@ code,pre{font:12px ui-monospace,monospace;background:var(--well);border-radius:4
2191
2436
  </header>
2192
2437
  <main>${body}</main>
2193
2438
  <footer class="mut" style="max-width:1000px;width:100%;margin:0 auto;padding:0 16px 16px">JQ Deck ${esc4(version)} \xB7 this machine only</footer>
2194
- </body></html>`;
2439
+ ${bar}</body></html>`;
2195
2440
  }
2196
2441
 
2197
2442
  // src/cli.ts
@@ -2201,6 +2446,7 @@ function parseArgs(argv, env = {}) {
2201
2446
  const a = {
2202
2447
  json: false,
2203
2448
  watch: false,
2449
+ quiet: false,
2204
2450
  exec: null,
2205
2451
  intervalS: Number(env.JQ_DECK_INTERVAL_S) || 60,
2206
2452
  repos: null,
@@ -2223,6 +2469,7 @@ function parseArgs(argv, env = {}) {
2223
2469
  const f = argv[i];
2224
2470
  if (f === "--json") a.json = true;
2225
2471
  else if (f === "--watch") a.watch = true;
2472
+ else if (f === "--quiet") a.quiet = true;
2226
2473
  else if (f === "--exec") a.exec = value(i++, f);
2227
2474
  else if (f === "--repos") a.repos = list(value(i++, f));
2228
2475
  else if (f === "--all-repos") a.allRepos = true;
@@ -2255,6 +2502,7 @@ function reportList(a, fromConfig) {
2255
2502
  function buildContext(a, env, cwd, version) {
2256
2503
  const config = loadConfig(expandHome(a.config));
2257
2504
  return {
2505
+ runningDir: runningDir(env),
2258
2506
  configFile: expandHome(a.config),
2259
2507
  port: a.port,
2260
2508
  version,
@@ -2283,7 +2531,8 @@ async function handle(url, host, ctx, overview2 = collectOverview) {
2283
2531
  if (u.pathname === "/") {
2284
2532
  const asked = u.searchParams.get("tab");
2285
2533
  const tab = TABS.includes(asked ?? "") ? asked : "overview";
2286
- return html(renderShell(await overview2(ctx.deck), tab, u.searchParams.get("repo"), ctx.version));
2534
+ const bar = toolbar({ here: "deck", running: readRunning(ctx.runningDir), team: readTeamUrl(ctx.configFile) });
2535
+ return html(renderShell(await overview2(ctx.deck), tab, u.searchParams.get("repo"), ctx.version, bar));
2287
2536
  }
2288
2537
  if (u.pathname === "/raw/sessions") {
2289
2538
  return html(renderPage(await snapshot({ questionTrees: ctx.deck.questionTrees, maxAgeDays: ctx.deck.maxAgeDays, projectsDir: ctx.deck.projectsDir, sockDir: ctx.deck.sockDir, probe: ctx.probe, sample: ctx.sample, turnCheck: readTurnCheckConfig(ctx.configFile) })));
@@ -2318,8 +2567,9 @@ async function run2(argv, version) {
2318
2567
  const report2 = teamReport(await collectOverview({ ...ctx.deck, questionTrees: ctx.sendQuestions }), ctx.report, ctx.sendQuestions);
2319
2568
  const code = await hand(a.exec, report2);
2320
2569
  const line = `jq-deck: ${report2.repos.length} ${report2.repos.length === 1 ? "repository" : "repositories"} reported to your command`;
2321
- if (code === 0) console.log(line);
2322
- else console.error(`${line}, which FAILED (exit ${code})`);
2570
+ if (code === 0) {
2571
+ if (!a.quiet) console.log(line);
2572
+ } else console.error(`${(/* @__PURE__ */ new Date()).toISOString()} ${line}, which FAILED (exit ${code})`);
2323
2573
  } catch (e) {
2324
2574
  console.error("jq-deck: report failed:", e?.message || e);
2325
2575
  }
@@ -2349,14 +2599,257 @@ async function run2(argv, version) {
2349
2599
  });
2350
2600
  res.end(reply.body);
2351
2601
  }).listen(a.port, "127.0.0.1", () => {
2602
+ announce("deck", a.port, ctx.runningDir);
2352
2603
  console.log(`jq-deck: http://127.0.0.1:${a.port} (Ctrl-C to stop)`);
2353
2604
  console.log(ctx.deck.mailbox ? `jq-deck: mailbox ${ctx.deck.mailbox}` : "jq-deck: no mailbox found (pass --mailbox DIR to show mail)");
2354
2605
  });
2355
2606
  }
2356
2607
 
2608
+ // src/join.ts
2609
+ import { spawn as spawn2 } from "child_process";
2610
+ import { chmodSync, existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync7, realpathSync, rmSync, statSync as statSync4, writeFileSync as writeFileSync3 } from "fs";
2611
+ import os6 from "os";
2612
+ import path8 from "path";
2613
+ import { createInterface } from "readline";
2614
+ var JOB_LABEL = "studio.pointseven.jq-deck-report";
2615
+ var UNIT_NAME = "jq-deck-report.service";
2616
+ var list2 = (s) => s.split(",").map((x) => x.trim()).filter(Boolean);
2617
+ function parseJoin(argv, env = {}) {
2618
+ const a = { url: "", repos: null, sendQuestions: null, intervalS: 60, board: null, service: true, config: env.JQ_DECK_CONFIG || defaultConfigFile2() };
2619
+ const value = (i, flag) => {
2620
+ const v = argv[i + 1];
2621
+ if (v === void 0 || v.startsWith("--")) throw new Error(`${flag} needs a value`);
2622
+ return v;
2623
+ };
2624
+ for (let i = 0; i < argv.length; i++) {
2625
+ const f = argv[i];
2626
+ if (f === "--url") a.url = value(i++, f);
2627
+ else if (f === "--repos") a.repos = list2(value(i++, f));
2628
+ else if (f === "--send-questions") a.sendQuestions = list2(value(i++, f));
2629
+ else if (f === "--interval") a.intervalS = Number(value(i++, f));
2630
+ else if (f === "--board") a.board = value(i++, f);
2631
+ else if (f === "--no-service") a.service = false;
2632
+ else if (f === "--config") a.config = value(i++, f);
2633
+ else if (f === "--all-repos") throw new Error("join does not take --all-repos: name the repositories this machine may report, with --repos");
2634
+ else throw new Error(`unknown option: ${f}`);
2635
+ }
2636
+ if (!a.url) throw new Error("join needs --url: the address the board gave you for reports");
2637
+ if (!(a.intervalS >= 15)) throw new Error("--interval needs 15 seconds or more");
2638
+ for (const [flag, v] of [["--url", a.url], ["--board", a.board]]) {
2639
+ if (v === null) continue;
2640
+ let u;
2641
+ try {
2642
+ u = new URL(v);
2643
+ } catch {
2644
+ throw new Error(`${flag} is not an address: ${v}`);
2645
+ }
2646
+ if (u.protocol !== "https:" && u.protocol !== "http:") throw new Error(`${flag} must be an http or https address`);
2647
+ if (u.username || u.password) throw new Error(`${flag} must not hold a user name or password`);
2648
+ }
2649
+ return a;
2650
+ }
2651
+ function joinPaths(home2, platform = process.platform) {
2652
+ const jq = path8.join(home2, ".jq");
2653
+ return {
2654
+ dir: jq,
2655
+ token: path8.join(jq, "deck-token"),
2656
+ script: path8.join(jq, "deck-report.sh"),
2657
+ log: path8.join(jq, "deck-report.log"),
2658
+ job: platform === "darwin" ? path8.join(home2, "Library", "LaunchAgents", `${JOB_LABEL}.plist`) : platform === "linux" ? path8.join(home2, ".config", "systemd", "user", UNIT_NAME) : null
2659
+ };
2660
+ }
2661
+ function safeForScript(what, value) {
2662
+ if (/['"$`\\\r\n]/.test(value)) throw new Error(`${what} holds a character that cannot go in the report script (a quote, $, backtick, backslash or line break): ${value}`);
2663
+ return value;
2664
+ }
2665
+ function reportScript(p) {
2666
+ const q = (what, v) => `'${safeForScript(what, v)}'`;
2667
+ const send = `${q("the path to node", p.node)} ${q("the path to jq-deck-server", p.server)} send --url ${q("--url", p.url)}`;
2668
+ return `#!/bin/sh
2669
+ # Written by \`jq-deck join\`. Reports this machine's listed repositories to the address below.
2670
+ # The repositories are the "report" list in ${safeForScript("the config file path", p.configFile)}.
2671
+ # To stop and remove this: jq-deck leave
2672
+ export PATH="${safeForScript("the path to node", path8.dirname(p.node))}:/usr/local/bin:/usr/bin:/bin"
2673
+ JQ_DECK_TOKEN="$(cat ${q("the token file path", p.tokenFile)})"
2674
+ export JQ_DECK_TOKEN
2675
+ exec ${q("the path to node", p.node)} ${q("the path to jq-deck", p.deck)} --watch --quiet --interval ${Math.floor(p.intervalS)} --config ${q("the config file path", p.configFile)} --exec "${send}"
2676
+ `;
2677
+ }
2678
+ var xml = (s) => s.replace(/[&<>]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;" })[c]);
2679
+ function launchdPlist(o) {
2680
+ return `<?xml version="1.0" encoding="UTF-8"?>
2681
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2682
+ <plist version="1.0"><dict>
2683
+ <key>Label</key><string>${JOB_LABEL}</string>
2684
+ <key>ProgramArguments</key><array><string>/bin/sh</string><string>${xml(o.script)}</string></array>
2685
+ <key>WorkingDirectory</key><string>${xml(o.home)}</string>
2686
+ <key>RunAtLoad</key><true/>
2687
+ <key>KeepAlive</key><true/>
2688
+ <key>ThrottleInterval</key><integer>60</integer>
2689
+ <key>StandardOutPath</key><string>${xml(o.log)}</string>
2690
+ <key>StandardErrorPath</key><string>${xml(o.log)}</string>
2691
+ </dict></plist>
2692
+ `;
2693
+ }
2694
+ function systemdUnit(o) {
2695
+ return `[Unit]
2696
+ Description=JQ Deck: report this machine's listed repositories to a board
2697
+ After=network-online.target
2698
+
2699
+ [Service]
2700
+ ExecStart=/bin/sh "${o.script}"
2701
+ WorkingDirectory=${o.home}
2702
+ Restart=always
2703
+ RestartSec=60
2704
+ StandardOutput=append:${o.log}
2705
+ StandardError=append:${o.log}
2706
+
2707
+ [Install]
2708
+ WantedBy=default.target
2709
+ `;
2710
+ }
2711
+ function protectedFolder(tree, home2, platform = process.platform) {
2712
+ if (platform !== "darwin") return null;
2713
+ for (const name of ["Desktop", "Documents", "Downloads"]) {
2714
+ const dir = path8.join(home2, name);
2715
+ if (tree === dir || tree.startsWith(dir + path8.sep)) return name;
2716
+ }
2717
+ return null;
2718
+ }
2719
+ function unmatched(listed, repos) {
2720
+ return listed.filter((name) => !repos.some((r) => reportable(r, [name])));
2721
+ }
2722
+ function mergeConfig(file, set) {
2723
+ let current = {};
2724
+ if (existsSync7(file)) {
2725
+ const raw = JSON.parse(readFileSync7(file, "utf8"));
2726
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error(`${file} must hold a JSON object`);
2727
+ current = raw;
2728
+ }
2729
+ mkdirSync3(path8.dirname(file), { recursive: true });
2730
+ writeFileSync3(file, JSON.stringify({ ...current, ...set }, null, 2) + "\n", { mode: 384 });
2731
+ }
2732
+ function findOnPath(name, envPath) {
2733
+ for (const dir of (envPath || "").split(path8.delimiter).filter(Boolean)) {
2734
+ const file = path8.join(dir, name);
2735
+ try {
2736
+ if (statSync4(file).isFile()) return realpathSync(file);
2737
+ } catch {
2738
+ }
2739
+ }
2740
+ return null;
2741
+ }
2742
+ function runQuiet(cmd, args2, input, env) {
2743
+ return new Promise((resolve) => {
2744
+ const child = spawn2(cmd, args2, { stdio: ["pipe", "ignore", "pipe"], env: env ?? process.env });
2745
+ let err = "";
2746
+ child.stderr.on("data", (d) => err += d);
2747
+ child.on("error", (e) => resolve({ code: 127, err: e.message }));
2748
+ child.on("close", (code) => resolve({ code: code ?? 1, err: err.trim() }));
2749
+ child.stdin.on("error", () => {
2750
+ });
2751
+ child.stdin.end(input ?? "");
2752
+ });
2753
+ }
2754
+ function ask(question) {
2755
+ const rl = createInterface({ input: process.stdin, output: process.stderr });
2756
+ return new Promise((resolve) => rl.question(question, (answer) => (rl.close(), resolve(answer.trim()))));
2757
+ }
2758
+ async function startJob(platform, job) {
2759
+ if (platform === "darwin") {
2760
+ const domain = `gui/${process.getuid?.() ?? 501}`;
2761
+ await runQuiet("launchctl", ["bootout", `${domain}/${JOB_LABEL}`]);
2762
+ const r2 = await runQuiet("launchctl", ["bootstrap", domain, job]);
2763
+ return r2.code === 0 ? null : `launchctl could not start the job (${r2.err || `exit ${r2.code}`})`;
2764
+ }
2765
+ await runQuiet("systemctl", ["--user", "daemon-reload"]);
2766
+ const r = await runQuiet("systemctl", ["--user", "enable", "--now", UNIT_NAME]);
2767
+ return r.code === 0 ? null : `systemctl could not start the job (${r.err || `exit ${r.code}`})`;
2768
+ }
2769
+ async function stopJob(platform) {
2770
+ if (platform === "darwin") await runQuiet("launchctl", ["bootout", `gui/${process.getuid?.() ?? 501}/${JOB_LABEL}`]);
2771
+ else if (platform === "linux") await runQuiet("systemctl", ["--user", "disable", "--now", UNIT_NAME]);
2772
+ }
2773
+ async function join(argv, env = process.env, home2 = os6.homedir()) {
2774
+ const a = parseJoin(argv, env);
2775
+ const platform = process.platform;
2776
+ const paths = joinPaths(home2, platform);
2777
+ const configFile = path8.resolve(expandHome(a.config));
2778
+ const config = loadConfig(configFile);
2779
+ const repos = a.repos ?? config.report ?? [];
2780
+ if (repos.length === 0) throw new Error("join needs to know which repositories this machine may report: --repos name,name");
2781
+ const sendQuestions = (a.sendQuestions ?? config.sendQuestions ?? []).map((t) => path8.resolve(expandHome(t)));
2782
+ const node = process.execPath;
2783
+ const deck = realpathSync(process.argv[1]);
2784
+ if (/[\\/]_npx[\\/]/.test(deck)) throw new Error("join needs jq-deck installed, not run through npx: the login job must find it after a restart.\n npm install -g @point-seven-studio/jq-deck @point-seven-studio/jq-deck-server");
2785
+ const server = findOnPath("jq-deck-server", env.PATH);
2786
+ if (!server) throw new Error("join sends reports with jq-deck-server, which is not installed:\n npm install -g @point-seven-studio/jq-deck-server");
2787
+ const token = env.JQ_DECK_TOKEN || (process.stdin.isTTY ? await ask("This machine's token (it starts with jqm_): ") : "");
2788
+ if (!token) throw new Error("join needs this machine's token: set $JQ_DECK_TOKEN, or run join in a terminal and paste it when asked");
2789
+ if (/\s/.test(token)) throw new Error("that does not look like a token: it has a space in it");
2790
+ const overview2 = await collectOverview({ mailbox: findMailbox({ config: config.mailbox, env: env.CROSSTALK_DIR, cwd: home2 }), names: config.names, questionTrees: sendQuestions, maxAgeDays: 3, cwd: home2 });
2791
+ const report2 = teamReport(overview2, repos, sendQuestions);
2792
+ const sent = await runQuiet(node, [server, "send", "--url", a.url], JSON.stringify(report2), { ...env, JQ_DECK_TOKEN: token });
2793
+ if (sent.code !== 0) throw new Error(`the board did not accept a report, so nothing was set up.
2794
+ ${sent.err || `jq-deck-server send exited ${sent.code}`}`);
2795
+ console.log(`jq-deck: the board accepted a report of ${report2.repos.length} ${report2.repos.length === 1 ? "repository" : "repositories"}`);
2796
+ const missing = unmatched(repos, overview2.repos);
2797
+ if (missing.length) console.log(`jq-deck: no Claude Code session was found for: ${missing.join(", ")}. A repository is reported once it has a session; check the spelling if you expected one.`);
2798
+ mkdirSync3(paths.dir, { recursive: true, mode: 448 });
2799
+ writeFileSync3(paths.token, token + "\n", { mode: 384 });
2800
+ chmodSync(paths.token, 384);
2801
+ mergeConfig(configFile, { report: repos, ...a.sendQuestions ? { sendQuestions: a.sendQuestions } : {}, ...a.board ? { team: a.board } : {} });
2802
+ writeFileSync3(paths.script, reportScript({ node, deck, server, url: a.url, tokenFile: paths.token, configFile, intervalS: a.intervalS }), { mode: 448 });
2803
+ chmodSync(paths.script, 448);
2804
+ console.log(`jq-deck: token saved to ${paths.token} (readable by you only)`);
2805
+ console.log(`jq-deck: reporting ${repos.join(", ")}; question text ${sendQuestions.length ? `IS sent for sessions under ${sendQuestions.join(", ")}` : "is not sent"}`);
2806
+ const byHand = ` sh ${paths.script}`;
2807
+ if (!a.service || !paths.job) {
2808
+ console.log(a.service ? `jq-deck: no login job is set up on this system. To report, keep this running:
2809
+ ${byHand}` : `jq-deck: no login job installed (--no-service). To report, keep this running:
2810
+ ${byHand}`);
2811
+ return;
2812
+ }
2813
+ mkdirSync3(path8.dirname(paths.job), { recursive: true });
2814
+ const jobParts = { script: paths.script, log: paths.log, home: home2 };
2815
+ writeFileSync3(paths.job, platform === "darwin" ? launchdPlist(jobParts) : systemdUnit(jobParts));
2816
+ const failed = await startJob(platform, paths.job);
2817
+ if (failed) {
2818
+ console.log(`jq-deck: ${failed}. The job file is at ${paths.job}. Until that is sorted, keep this running:
2819
+ ${byHand}`);
2820
+ return;
2821
+ }
2822
+ console.log(`jq-deck: a login job now reports every ${a.intervalS}s and starts again after a restart. Its log: ${paths.log}`);
2823
+ console.log("jq-deck: to stop and remove all of this: jq-deck leave");
2824
+ const blocked = [...new Set(overview2.repos.filter((r) => reportable(r, repos)).map((r) => protectedFolder(r.tree, home2, platform)).filter(Boolean))];
2825
+ if (blocked.length) {
2826
+ console.log(`
2827
+ jq-deck: NOTE. Some of these repositories are under ${blocked.join(" and ")}. macOS does not let a login job read those folders,`);
2828
+ console.log("so their rows may show no git remote and no setup score. Either:");
2829
+ console.log(` - give this program Full Disk Access (System Settings, Privacy & Security, Full Disk Access, add ${node}), then run: jq-deck join again`);
2830
+ console.log(` - or run: jq-deck leave, and keep the reporter in a terminal instead:
2831
+ ${byHand}`);
2832
+ }
2833
+ }
2834
+ async function leave(home2 = os6.homedir()) {
2835
+ const platform = process.platform;
2836
+ const paths = joinPaths(home2, platform);
2837
+ await stopJob(platform);
2838
+ const removed = [];
2839
+ for (const file of [paths.job, paths.script, paths.token]) {
2840
+ if (file && existsSync7(file)) {
2841
+ rmSync(file);
2842
+ removed.push(file);
2843
+ }
2844
+ }
2845
+ console.log(removed.length ? `jq-deck: stopped reporting and removed:
2846
+ ${removed.map((f) => ` ${f}`).join("\n")}` : "jq-deck: nothing to remove; this machine was not set up with join");
2847
+ console.log(`jq-deck: the log (${paths.log}) and your config file are left as they are. The token still works until you remove this machine on the board.`);
2848
+ }
2849
+
2357
2850
  // src/main.ts
2358
- var VERSION = true ? "0.3.2" : "dev";
2359
- var HELP = `JQ Deck ${VERSION}: one page for your Claude Code sessions, their setup and their mail.
2851
+ var VERSION2 = true ? "0.4.0" : "dev";
2852
+ var HELP = `JQ Deck ${VERSION2}: one page for your Claude Code sessions, their setup and their mail.
2360
2853
 
2361
2854
  jq-deck open the page at http://127.0.0.1:${DEFAULT_PORT}
2362
2855
  jq-deck --json print the overview
@@ -2368,6 +2861,17 @@ var HELP = `JQ Deck ${VERSION}: one page for your Claude Code sessions, their se
2368
2861
  --send-questions DIR,DIR also send what a waiting session asked, for sessions
2369
2862
  under these folders (default: none)
2370
2863
  --interval SECONDS for --watch (default 60)
2864
+ --quiet say nothing when a report goes through
2865
+ jq-deck join --url ADDRESS --repos NAME,NAME
2866
+ set this machine up to report to a board: sends one
2867
+ report to check the address and the token, saves the
2868
+ token ($JQ_DECK_TOKEN, or pasted when asked) where only
2869
+ you can read it, and installs a login job that keeps
2870
+ reporting after a restart. Needs jq-deck-server installed.
2871
+ --board ADDRESS the board's own page, for the links on the local pages
2872
+ --send-questions DIR,DIR as for --watch (default: none)
2873
+ --no-service write the files, install no login job
2874
+ jq-deck leave stop reporting and remove what join wrote
2371
2875
  jq-deck --mailbox DIR the crosstalk mailbox to show (default: $CROSSTALK_DIR,
2372
2876
  or the nearest folder above you holding .crosstalk)
2373
2877
  jq-deck --questions DIR,DIR show the question a waiting session asked, for
@@ -2378,16 +2882,22 @@ var HELP = `JQ Deck ${VERSION}: one page for your Claude Code sessions, their se
2378
2882
  jq-deck --config FILE default ~/.jq/config.json
2379
2883
  jq-deck --port NUMBER
2380
2884
 
2381
- It reads what jq-agents, jq-groundcrew and jq-crosstalk read, and writes nothing.
2885
+ It reads what jq-agents, jq-groundcrew and jq-crosstalk read. It writes a small note
2886
+ while its page runs, and nothing else unless you run join.
2382
2887
  The page is served to this machine only. Nothing leaves it unless you pass --exec
2383
2888
  (your command gets the report) or --probe (one timed connection).
2384
2889
 
2385
2890
  Unofficial. Not affiliated with or endorsed by Anthropic.`;
2386
2891
  var args = process.argv.slice(2);
2387
2892
  if (args.includes("--help") || args.includes("-h")) console.log(HELP);
2388
- else if (args.includes("--version") || args.includes("-v")) console.log(VERSION);
2893
+ else if (args.includes("--version") || args.includes("-v")) console.log(VERSION2);
2894
+ else if (args[0] === "join" || args[0] === "leave")
2895
+ (args[0] === "join" ? join(args.slice(1)) : leave()).catch((error) => {
2896
+ console.error(`jq-deck: ${error.message || error}`);
2897
+ process.exit(1);
2898
+ });
2389
2899
  else
2390
- run2(args, VERSION).catch((error) => {
2900
+ run2(args, VERSION2).catch((error) => {
2391
2901
  console.error(error.message || error);
2392
2902
  process.exit(1);
2393
2903
  });