@point-seven-studio/jq-deck 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/index.mjs +784 -123
- package/dist/jq-deck.mjs +855 -158
- package/dist/types/cli.d.ts +4 -0
- package/dist/types/page.d.ts +2 -1
- package/dist/types/presence.d.ts +38 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/deck.ts
|
|
2
2
|
import { createHash } from "crypto";
|
|
3
|
-
import { existsSync as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
4
|
+
import os4 from "os";
|
|
5
|
+
import path3 from "path";
|
|
6
6
|
|
|
7
7
|
// ../agents/dist/index.mjs
|
|
8
8
|
import { execFile as execFile2 } from "child_process";
|
|
@@ -14,6 +14,155 @@ import { promisify as promisify2 } from "util";
|
|
|
14
14
|
import { execFile } from "child_process";
|
|
15
15
|
import { promisify } from "util";
|
|
16
16
|
import os from "os";
|
|
17
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
18
|
+
import os3 from "os";
|
|
19
|
+
import path2 from "path";
|
|
20
|
+
var EDIT_TOOLS = /* @__PURE__ */ new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
|
|
21
|
+
function looksLikeACheck(command) {
|
|
22
|
+
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);
|
|
23
|
+
}
|
|
24
|
+
var CODE_FILE = /\.(ts|tsx|mts|cts|js|jsx|mjs|cjs|py|rb|go|rs|java|kt|swift|c|h|cc|cpp|hpp|cs|php|sql|sh|bash|zsh|json|ya?ml|toml|css|scss|less|html?|vue|svelte|tf|proto|gradle|xml|ini|cfg|conf|lock)$|(^|\/)(Dockerfile|Makefile|\.env[\w.]*)$/i;
|
|
25
|
+
var NOT_PROJECT = /^(\/tmp\/|\/private\/tmp\/|\/var\/folders\/|\/dev\/|\$)|(^|\/)\.claude\/|(^|\/)(node_modules|dist|build|out|coverage)\/|(^|\/)[._]?(tmp|temp|scratch)[\w.-]*(\/|$)|_tmp_|\.tmp\b/i;
|
|
26
|
+
function isCodePath(file) {
|
|
27
|
+
const clean = file.trim().replace(/^['"]|['"]$/g, "");
|
|
28
|
+
const name = clean.split("/").pop() || "";
|
|
29
|
+
if (/^[_.]/.test(name) && !/^\.env/.test(name)) return false;
|
|
30
|
+
return CODE_FILE.test(clean) && !NOT_PROJECT.test(clean);
|
|
31
|
+
}
|
|
32
|
+
function codePaths(text) {
|
|
33
|
+
return (text.match(/[~$\w@.{}\/-]+/g) || []).filter(isCodePath);
|
|
34
|
+
}
|
|
35
|
+
function maskQuotes(text) {
|
|
36
|
+
return text.replace(/'[^']*'|"(?:[^"\\]|\\.)*"/g, (quoted) => quoted[0] + "x".repeat(Math.max(0, quoted.length - 2)) + quoted[0]);
|
|
37
|
+
}
|
|
38
|
+
function splitHeredocs(command) {
|
|
39
|
+
const bodies = [];
|
|
40
|
+
const lines = command.split("\n");
|
|
41
|
+
const shell = [];
|
|
42
|
+
for (let i = 0; i < lines.length; i++) {
|
|
43
|
+
shell.push(lines[i]);
|
|
44
|
+
const tag = /<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/.exec(lines[i])?.[2];
|
|
45
|
+
if (!tag) continue;
|
|
46
|
+
const body = [];
|
|
47
|
+
i += 1;
|
|
48
|
+
while (i < lines.length && lines[i].trim() !== tag) body.push(lines[i++]);
|
|
49
|
+
bodies.push(body.join("\n"));
|
|
50
|
+
}
|
|
51
|
+
return { shell: shell.join("\n"), bodies };
|
|
52
|
+
}
|
|
53
|
+
function segments(shell) {
|
|
54
|
+
const masked = maskQuotes(shell);
|
|
55
|
+
const parts = [];
|
|
56
|
+
let from = 0;
|
|
57
|
+
for (const cut of [...masked.matchAll(/&&|\|\||;|\||\n/g), null]) {
|
|
58
|
+
const to = cut ? cut.index : masked.length;
|
|
59
|
+
const text = shell.slice(from, to).trim();
|
|
60
|
+
if (text) parts.push({ text, bare: masked.slice(from, to).trim() });
|
|
61
|
+
from = cut ? to + cut[0].length : to;
|
|
62
|
+
}
|
|
63
|
+
return parts;
|
|
64
|
+
}
|
|
65
|
+
function shellSegments(command) {
|
|
66
|
+
return segments(splitHeredocs(command).shell).map((part) => part.text);
|
|
67
|
+
}
|
|
68
|
+
var WRITES_A_FILE = /\bopen\([^)]*,\s*['"][wax]b?\+?['"]|\.write_text\(|\.write_bytes\(|\bwriteFile(Sync)?\(|\bappendFile(Sync)?\(|\bfs\.(rename|unlink|rm|cp|copyFile)(Sync)?\(|\bshutil\.(copy|move|rmtree)/;
|
|
69
|
+
function shellEdit(command) {
|
|
70
|
+
const { shell, bodies } = splitHeredocs(command);
|
|
71
|
+
const written = bodies.filter((body) => WRITES_A_FILE.test(body)).join("\n");
|
|
72
|
+
for (const { text, bare } of segments(shell)) {
|
|
73
|
+
const writer = /^(sudo\s+)?(sed|perl)\b.*\s-[a-zA-Z]*i/.test(bare) || /^(sudo\s+)?(mv|cp|rm|patch|tee)\s/.test(bare) || /^git\s+(apply|mv|rm)\b/.test(bare);
|
|
74
|
+
if (writer && codePaths(text).length) return text;
|
|
75
|
+
for (const hit of bare.matchAll(/(^|[^0-9&>=-])>>?\s*/g)) {
|
|
76
|
+
const target = /^\S+/.exec(text.slice(hit.index + hit[0].length))?.[0] ?? "";
|
|
77
|
+
if (isCodePath(target)) return text;
|
|
78
|
+
}
|
|
79
|
+
if (/^(python3?|node|ruby|perl|deno|bun)\b/.test(bare) && (written || WRITES_A_FILE.test(text)) && codePaths(`${written}
|
|
80
|
+
${text}`).length) return text;
|
|
81
|
+
}
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
function ruleText(command) {
|
|
85
|
+
const words = (shellSegments(command)[0] || command).trim().split(/\s+/);
|
|
86
|
+
const kept = [];
|
|
87
|
+
for (const word of words.slice(0, 3)) {
|
|
88
|
+
if (kept.length && /[\/$<>'"=]|^\d/.test(word)) break;
|
|
89
|
+
kept.push(word);
|
|
90
|
+
}
|
|
91
|
+
return kept.join(" ").slice(0, 60);
|
|
92
|
+
}
|
|
93
|
+
var MAX_RULES = 200;
|
|
94
|
+
var MAX_TEXT = 80;
|
|
95
|
+
function parseConfig(raw) {
|
|
96
|
+
const o = raw && typeof raw === "object" ? raw : {};
|
|
97
|
+
const rules = (Array.isArray(o.rules) ? o.rules : []).filter((r) => !!r && typeof r === "object" && typeof r.tree === "string" && typeof r.text === "string" && (r.kind === "check" || r.kind === "not-edit")).map((r) => ({ tree: r.tree, kind: r.kind, text: r.text.trim().slice(0, MAX_TEXT) })).filter((r) => r.text.length >= 2 && r.tree).slice(0, MAX_RULES);
|
|
98
|
+
const muted = (Array.isArray(o.muted) ? o.muted : []).filter((t) => typeof t === "string" && !!t).slice(0, MAX_RULES);
|
|
99
|
+
const dismissed = {};
|
|
100
|
+
if (o.dismissed && typeof o.dismissed === "object") {
|
|
101
|
+
for (const [id, at] of Object.entries(o.dismissed).slice(0, 500)) if (typeof at === "string") dismissed[id] = at;
|
|
102
|
+
}
|
|
103
|
+
return { rules, muted, dismissed };
|
|
104
|
+
}
|
|
105
|
+
function rulesFor(config, tree) {
|
|
106
|
+
const mine = config.rules.filter((r) => r.tree === "*" || r.tree === tree);
|
|
107
|
+
return { checks: mine.filter((r) => r.kind === "check").map((r) => r.text), notEdits: mine.filter((r) => r.kind === "not-edit").map((r) => r.text) };
|
|
108
|
+
}
|
|
109
|
+
var blocks = (rec) => Array.isArray(rec.message?.content) ? rec.message.content.filter((b) => !!b && typeof b === "object") : [];
|
|
110
|
+
function isPrompt(rec) {
|
|
111
|
+
if (rec.type !== "user" || rec.isSidechain) return false;
|
|
112
|
+
const content = rec.message?.content;
|
|
113
|
+
return typeof content === "string" ? content.trim() !== "" : blocks(rec).some((b) => b.type === "text" || b.type === "image");
|
|
114
|
+
}
|
|
115
|
+
var short = (command, max = 120) => {
|
|
116
|
+
const one = redactSecrets(command.replace(/\s+/g, " ").trim()).text;
|
|
117
|
+
return one.length > max ? one.slice(0, max).trimEnd() + "\u2026" : one;
|
|
118
|
+
};
|
|
119
|
+
function deriveTurnCheckDetail(records, rules = {}) {
|
|
120
|
+
const extraChecks = rules.checks ?? [];
|
|
121
|
+
const notEdits = rules.notEdits ?? [];
|
|
122
|
+
const isCheck = (command) => looksLikeACheck(command) || extraChecks.some((text) => command.includes(text));
|
|
123
|
+
let start = -1;
|
|
124
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
125
|
+
if (records[i] && isPrompt(records[i])) {
|
|
126
|
+
start = i;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let step = 0;
|
|
131
|
+
let lastEdit = -1;
|
|
132
|
+
let edit = null;
|
|
133
|
+
const shell = [];
|
|
134
|
+
const errored = /* @__PURE__ */ new Set();
|
|
135
|
+
for (const rec of records.slice(start + 1)) {
|
|
136
|
+
if (!rec || rec.isSidechain) continue;
|
|
137
|
+
for (const block of blocks(rec)) {
|
|
138
|
+
step += 1;
|
|
139
|
+
if (block.type === "tool_result" && block.is_error === true && block.tool_use_id) errored.add(block.tool_use_id);
|
|
140
|
+
if (block.type !== "tool_use" || !block.name) continue;
|
|
141
|
+
if (EDIT_TOOLS.has(block.name)) {
|
|
142
|
+
const file = block.input?.file_path ?? block.input?.notebook_path;
|
|
143
|
+
if (typeof file === "string" && !isCodePath(file)) continue;
|
|
144
|
+
lastEdit = step;
|
|
145
|
+
edit = { via: "tool", text: block.name };
|
|
146
|
+
} else if (block.name === "Bash" && typeof block.input?.command === "string") {
|
|
147
|
+
const command = block.input.command;
|
|
148
|
+
const check = isCheck(command);
|
|
149
|
+
shell.push({ step, id: block.id, command, check });
|
|
150
|
+
const changed = check || rules.shellEdits === false ? "" : shellEdit(command);
|
|
151
|
+
if (changed && !notEdits.some((text) => changed.includes(text) || command.includes(text))) {
|
|
152
|
+
lastEdit = step;
|
|
153
|
+
edit = { via: "shell", text: changed };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (lastEdit < 0 || !edit) return { result: start >= 0 ? "no-edits" : "unknown", via: null, evidence: null };
|
|
159
|
+
const after = shell.filter((c) => c.step > lastEdit);
|
|
160
|
+
const checks = after.filter((c) => c.check);
|
|
161
|
+
const last = checks[checks.length - 1];
|
|
162
|
+
const result = !last ? "unchecked" : last.id && errored.has(last.id) ? "failed" : "checked";
|
|
163
|
+
const evidence = result === "unchecked" || result === "failed" ? { via: edit.via, edit: edit.via === "shell" ? short(edit.text) : edit.text, after: [...new Set(after.filter((c) => !c.check).map((c) => short(c.command, 80)))].slice(-6) } : null;
|
|
164
|
+
return { result, via: edit.via, evidence };
|
|
165
|
+
}
|
|
17
166
|
var META_RECORD_TYPES = /* @__PURE__ */ new Set([
|
|
18
167
|
"last-prompt",
|
|
19
168
|
"pr-link",
|
|
@@ -97,16 +246,16 @@ function lastActivityAt(records) {
|
|
|
97
246
|
}
|
|
98
247
|
return null;
|
|
99
248
|
}
|
|
100
|
-
function deriveState(
|
|
101
|
-
if (!
|
|
249
|
+
function deriveState(alive2, lastActivityIso, now) {
|
|
250
|
+
if (!alive2) return "dead";
|
|
102
251
|
if (!lastActivityIso) return "stale";
|
|
103
252
|
const ageS = Math.max(0, (now - Date.parse(lastActivityIso)) / 1e3);
|
|
104
253
|
if (ageS <= LIVE_WITHIN_S) return "live";
|
|
105
254
|
if (ageS <= IDLE_WITHIN_S) return "idle";
|
|
106
255
|
return "stale";
|
|
107
256
|
}
|
|
108
|
-
function deriveWaiting(rec,
|
|
109
|
-
if (!
|
|
257
|
+
function deriveWaiting(rec, alive2) {
|
|
258
|
+
if (!alive2 || !rec || rec.type !== "assistant") return false;
|
|
110
259
|
return rec.message?.stop_reason === "end_turn";
|
|
111
260
|
}
|
|
112
261
|
function deriveAttention(state, waiting) {
|
|
@@ -120,7 +269,7 @@ function isTreeAllowed(workingTree, allowlist) {
|
|
|
120
269
|
return allowlist.some((t) => t && (workingTree === t || workingTree.startsWith(t.replace(/\/+$/, "") + "/")));
|
|
121
270
|
}
|
|
122
271
|
function buildStatusRow(opts) {
|
|
123
|
-
const { machine, records, sessionIdFallback, alive, pid, allowlist, now, workingTreeOverride } = opts;
|
|
272
|
+
const { machine, records, sessionIdFallback, alive: alive2, pid, allowlist, now, workingTreeOverride } = opts;
|
|
124
273
|
const withCwd = [...records].reverse().find((r) => r?.cwd);
|
|
125
274
|
const workingTree = workingTreeOverride || withCwd?.cwd || "";
|
|
126
275
|
if (!workingTree) return null;
|
|
@@ -130,8 +279,8 @@ function buildStatusRow(opts) {
|
|
|
130
279
|
const substantive = lastSubstantive(records);
|
|
131
280
|
const assistant = lastAssistant(records);
|
|
132
281
|
const activity = lastActivityAt(records);
|
|
133
|
-
const state = deriveState(
|
|
134
|
-
const waiting = deriveWaiting(substantive,
|
|
282
|
+
const state = deriveState(alive2, activity, now);
|
|
283
|
+
const waiting = deriveWaiting(substantive, alive2);
|
|
135
284
|
const rawText = assistant ? messageText(assistant) : "";
|
|
136
285
|
const allowed = isTreeAllowed(workingTree, allowlist);
|
|
137
286
|
let blocked_question = null;
|
|
@@ -141,6 +290,13 @@ function buildStatusRow(opts) {
|
|
|
141
290
|
question_redacted = redacted;
|
|
142
291
|
blocked_question = text.length > QUESTION_MAX_CHARS ? text.slice(0, QUESTION_MAX_CHARS).trimEnd() + "\u2026" : text;
|
|
143
292
|
}
|
|
293
|
+
const saidDone = substantive?.type === "assistant" && substantive.message?.stop_reason === "end_turn";
|
|
294
|
+
const detail = saidDone ? deriveTurnCheckDetail(records, opts.turnCheck) : null;
|
|
295
|
+
let turn_check = detail?.result ?? null;
|
|
296
|
+
if (turn_check === "unchecked" || turn_check === "failed") {
|
|
297
|
+
if (opts.turnCheck?.muted || opts.turnCheck?.dismissedAt && opts.turnCheck.dismissedAt === activity) turn_check = "dismissed";
|
|
298
|
+
}
|
|
299
|
+
if (detail && opts.onTurnDetail) opts.onTurnDetail(detail);
|
|
144
300
|
return {
|
|
145
301
|
machine,
|
|
146
302
|
product: workingTree.split("/").filter(Boolean).pop() || workingTree,
|
|
@@ -155,7 +311,9 @@ function buildStatusRow(opts) {
|
|
|
155
311
|
ends_with_question: rawText ? endsWithQuestion(rawText) : false,
|
|
156
312
|
blocked_question,
|
|
157
313
|
question_redacted,
|
|
158
|
-
question_allowed: allowed
|
|
314
|
+
question_allowed: allowed,
|
|
315
|
+
turn_check,
|
|
316
|
+
turn_check_via: detail?.via ?? null
|
|
159
317
|
};
|
|
160
318
|
}
|
|
161
319
|
function parsePs(stdout) {
|
|
@@ -347,7 +505,7 @@ var execFileAsync2 = promisify2(execFile2);
|
|
|
347
505
|
function defaultProjectsDir() {
|
|
348
506
|
return path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os2.homedir(), ".claude"), "projects");
|
|
349
507
|
}
|
|
350
|
-
var TAIL_RECORDS =
|
|
508
|
+
var TAIL_RECORDS = 200;
|
|
351
509
|
async function findTranscripts(dir, out = []) {
|
|
352
510
|
let entries;
|
|
353
511
|
try {
|
|
@@ -461,7 +619,11 @@ async function collectRows(opts = {}) {
|
|
|
461
619
|
const rawCwd = [...records].reverse().find((r) => r?.cwd)?.cwd || "";
|
|
462
620
|
const tree = rawCwd ? await repoRoot(rawCwd) : "";
|
|
463
621
|
const pid = tree ? cwdToPid.get(tree) ?? null : null;
|
|
622
|
+
const config = opts.turnCheck;
|
|
623
|
+
let evidence = null;
|
|
464
624
|
const row3 = buildStatusRow({
|
|
625
|
+
turnCheck: config ? { ...rulesFor(config, tree), muted: config.muted.includes(tree), dismissedAt: config.dismissed[path.basename(file, ".jsonl")] ?? null } : void 0,
|
|
626
|
+
onTurnDetail: (detail) => evidence = detail.evidence,
|
|
465
627
|
machine,
|
|
466
628
|
records,
|
|
467
629
|
workingTreeOverride: tree || void 0,
|
|
@@ -471,7 +633,11 @@ async function collectRows(opts = {}) {
|
|
|
471
633
|
allowlist: opts.questionTrees ?? [],
|
|
472
634
|
now
|
|
473
635
|
});
|
|
474
|
-
if (row3)
|
|
636
|
+
if (row3) {
|
|
637
|
+
if (config && row3.turn_check !== "dismissed" && (row3.turn_check === "unchecked" || row3.turn_check === "failed") && config.dismissed[row3.session_id] === row3.last_activity_at) row3.turn_check = "dismissed";
|
|
638
|
+
rows.push(row3);
|
|
639
|
+
if (evidence && opts.onEvidence) opts.onEvidence(row3.session_id, evidence);
|
|
640
|
+
}
|
|
475
641
|
} catch {
|
|
476
642
|
}
|
|
477
643
|
}
|
|
@@ -484,7 +650,8 @@ async function collectRows(opts = {}) {
|
|
|
484
650
|
}
|
|
485
651
|
var prevNet = /* @__PURE__ */ new Map();
|
|
486
652
|
async function snapshot(opts = {}) {
|
|
487
|
-
const
|
|
653
|
+
const turn_check = {};
|
|
654
|
+
const sessions = await collectRows(opts.evidence ? { ...opts, onEvidence: (id, e) => turn_check[id] = e } : opts);
|
|
488
655
|
let host = null;
|
|
489
656
|
let bottleneck = null;
|
|
490
657
|
if (opts.sample !== false) {
|
|
@@ -515,8 +682,27 @@ async function snapshot(opts = {}) {
|
|
|
515
682
|
bottleneck = null;
|
|
516
683
|
}
|
|
517
684
|
}
|
|
518
|
-
|
|
519
|
-
}
|
|
685
|
+
const snap = { machine: opts.machine ?? os2.hostname(), generated_at: new Date(opts.now ?? Date.now()).toISOString(), sessions, host, bottleneck };
|
|
686
|
+
if (opts.evidence) snap.local = { turn_check };
|
|
687
|
+
return snap;
|
|
688
|
+
}
|
|
689
|
+
var TOOLBAR_CSS = `
|
|
690
|
+
body{padding-bottom:64px}
|
|
691
|
+
.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)}
|
|
692
|
+
.jqbar a{color:var(--link,LinkText)}
|
|
693
|
+
.jqbar .here{font-weight:700}
|
|
694
|
+
.jqbar details[open]{order:-1;flex-basis:100%}
|
|
695
|
+
.jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
|
|
696
|
+
.jqbar summary::-webkit-details-marker{display:none}
|
|
697
|
+
.jqbar summary::after{content:" \u25B8"}
|
|
698
|
+
.jqbar details[open] summary::after{content:" \u25BE"}
|
|
699
|
+
.jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
|
|
700
|
+
.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)}
|
|
701
|
+
.jqbar details>div p{margin:0 0 4px}
|
|
702
|
+
.jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
|
|
703
|
+
.jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
|
|
704
|
+
@media print{.jqbar{display:none}body{padding-bottom:0}}
|
|
705
|
+
`;
|
|
520
706
|
var esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
521
707
|
function ago(iso, now) {
|
|
522
708
|
if (!iso) return "unknown";
|
|
@@ -549,18 +735,44 @@ function groupByTree(rows) {
|
|
|
549
735
|
rows: list2.sort((a, b) => (b.last_activity_at || "").localeCompare(a.last_activity_at || ""))
|
|
550
736
|
})).sort((a, b) => Number(needs(b.rows)) - Number(needs(a.rows)) || latest(b.rows).localeCompare(latest(a.rows)));
|
|
551
737
|
}
|
|
552
|
-
|
|
738
|
+
var hidden = (fields) => Object.entries(fields).map(([name, value]) => `<input type="hidden" name="${name}" value="${esc(value)}">`).join("");
|
|
739
|
+
var form = (m, fields, label) => `<form method="post" action="/turn-check">${hidden({ token: m.token, ...fields })}<button type="submit">${esc(label)}</button></form>`;
|
|
740
|
+
function whyPanel(r, evidence, m) {
|
|
741
|
+
const how = evidence.via === "shell" ? `<code>${esc(evidence.edit)}</code>, a shell command` : `the ${esc(evidence.edit)} tool`;
|
|
742
|
+
const verdict = r.turn_check === "failed" ? "The last check after it failed." : "No check ran after it.";
|
|
743
|
+
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) => {
|
|
744
|
+
const text = ruleText(command);
|
|
745
|
+
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>`;
|
|
746
|
+
}).join("")}</ul>` : "";
|
|
747
|
+
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`) : "";
|
|
748
|
+
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>";
|
|
749
|
+
}
|
|
750
|
+
function sessionRow(r, now, evidence, manage) {
|
|
553
751
|
const attention = deriveAttention(r.state, r.waiting);
|
|
554
752
|
const badge = attention === "needs-you" ? '<span class="b need">waiting on a person</span>' : attention === "abandoned" ? '<span class="b old">asked, then left</span>' : "";
|
|
753
|
+
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>' : "";
|
|
555
754
|
const res = r.cpu_pct != null || r.rss_mb != null ? `<span class="mut">${r.cpu_pct ?? "?"}% cpu \xB7 ${r.rss_mb ?? "?"} MB</span>` : "";
|
|
556
755
|
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>' : "";
|
|
557
|
-
|
|
756
|
+
const why = check && evidence && manage ? whyPanel(r, evidence, manage) : "";
|
|
757
|
+
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>`;
|
|
758
|
+
}
|
|
759
|
+
function correctionsPanel(snap, m) {
|
|
760
|
+
const { rules, muted, dismissed } = m.config;
|
|
761
|
+
const items = [
|
|
762
|
+
...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>`),
|
|
763
|
+
...muted.map((tree) => `<li><span>Never labelled: <span class="mut">${esc(tree)}</span></span>${form(m, { action: "unmute", tree }, "Label it again")}</li>`),
|
|
764
|
+
...Object.keys(dismissed).map((session) => {
|
|
765
|
+
const row3 = snap.sessions.find((r) => r.session_id === session);
|
|
766
|
+
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>`;
|
|
767
|
+
})
|
|
768
|
+
];
|
|
769
|
+
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>';
|
|
558
770
|
}
|
|
559
|
-
function renderPage(snap, now = Date.now()) {
|
|
771
|
+
function renderPage(snap, now = Date.now(), manage, bar = "") {
|
|
560
772
|
const t = totals(snap.sessions);
|
|
561
773
|
const b = snap.bottleneck;
|
|
562
774
|
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>`;
|
|
563
|
-
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)).join("")}</ul></section>`).join("");
|
|
775
|
+
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("");
|
|
564
776
|
return `<!doctype html>
|
|
565
777
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
566
778
|
<title>JQ Agents</title>
|
|
@@ -575,28 +787,51 @@ h1{font-size:24px;margin:0}h2{font-size:15px;margin:0;padding:10px 12px;word-bre
|
|
|
575
787
|
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;margin:10px 0;overflow:hidden}
|
|
576
788
|
ul{list-style:none;margin:0;padding:0}li{border-top:1px solid var(--line);padding:8px 12px}
|
|
577
789
|
.s{font-size:11px;font-weight:700;text-transform:uppercase;border-radius:4px;padding:1px 6px;border:1px solid var(--line)}.s.live{color:var(--ok)}.s.dead{color:var(--mut)}
|
|
578
|
-
.b{font-size:12px;font-weight:600}.b.need{color:var(--need)}.b.old{color:var(--mut)}
|
|
790
|
+
.b{font-size:12px;font-weight:600}.b.need{color:var(--need)}.b.old{color:var(--mut)}.b.bad{color:var(--bad)}
|
|
579
791
|
.chip{border:1px solid var(--line);border-radius:8px;padding:6px 10px;font-size:13px}
|
|
792
|
+
.why{margin:6px 0 2px;font-size:13px}.why summary{cursor:pointer;color:var(--mut);font-size:12px}.why p{margin:6px 0}
|
|
793
|
+
code{font:12px ui-monospace,Menlo,monospace;background:var(--well);border-radius:4px;padding:1px 4px;word-break:break-all}
|
|
794
|
+
.cmds{border:1px solid var(--line);border-radius:8px}.cmds li,.fix li{display:flex;flex-wrap:wrap;gap:6px 10px;align-items:center;justify-content:space-between}
|
|
795
|
+
.acts{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}form{margin:0}
|
|
796
|
+
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}
|
|
797
|
+
button:hover{border-color:var(--mut)}button:focus-visible{outline:2px solid var(--fg);outline-offset:2px}.pad{margin:0;padding:8px 12px}
|
|
580
798
|
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}
|
|
581
|
-
</style></head><body><main>
|
|
799
|
+
${bar ? TOOLBAR_CSS : ""}</style></head><body><main>
|
|
582
800
|
<h1>JQ Agents</h1>
|
|
583
801
|
<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>
|
|
584
802
|
<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>
|
|
585
803
|
${chip}
|
|
586
804
|
${trees || '<p class="mut">No session has been active in the window read.</p>'}
|
|
587
|
-
|
|
805
|
+
${manage ? correctionsPanel(snap, manage) : ""}
|
|
806
|
+
</main>${bar}</body></html>`;
|
|
807
|
+
}
|
|
808
|
+
function defaultConfigFile() {
|
|
809
|
+
return process.env.JQ_CONFIG || path2.join(os3.homedir(), ".jq", "config.json");
|
|
810
|
+
}
|
|
811
|
+
function readAll(file) {
|
|
812
|
+
if (!existsSync2(file)) return {};
|
|
813
|
+
const parsed = JSON.parse(readFileSync(file, "utf-8"));
|
|
814
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${file} does not hold a JSON object`);
|
|
815
|
+
return parsed;
|
|
816
|
+
}
|
|
817
|
+
function readTurnCheckConfig(file = defaultConfigFile()) {
|
|
818
|
+
try {
|
|
819
|
+
return parseConfig(readAll(file).turnCheck);
|
|
820
|
+
} catch {
|
|
821
|
+
return parseConfig(null);
|
|
822
|
+
}
|
|
588
823
|
}
|
|
589
824
|
|
|
590
825
|
// src/deck.ts
|
|
591
|
-
var expandHome = (p) => p === "~" || p.startsWith("~/") ?
|
|
592
|
-
function
|
|
593
|
-
return
|
|
826
|
+
var expandHome = (p) => p === "~" || p.startsWith("~/") ? path3.join(os4.homedir(), p.slice(1)) : p;
|
|
827
|
+
function defaultConfigFile2() {
|
|
828
|
+
return path3.join(os4.homedir(), ".jq", "config.json");
|
|
594
829
|
}
|
|
595
830
|
function loadConfig(file) {
|
|
596
|
-
if (!
|
|
831
|
+
if (!existsSync3(file)) return {};
|
|
597
832
|
let raw;
|
|
598
833
|
try {
|
|
599
|
-
raw = JSON.parse(
|
|
834
|
+
raw = JSON.parse(readFileSync2(file, "utf8"));
|
|
600
835
|
} catch (e) {
|
|
601
836
|
throw new Error(`cannot read ${file}: ${e?.message || e}`);
|
|
602
837
|
}
|
|
@@ -606,7 +841,7 @@ function loadConfig(file) {
|
|
|
606
841
|
if (typeof r.mailbox === "string") out.mailbox = expandHome(r.mailbox);
|
|
607
842
|
if (r.names && typeof r.names === "object" && !Array.isArray(r.names)) {
|
|
608
843
|
out.names = {};
|
|
609
|
-
for (const [k, v] of Object.entries(r.names)) if (typeof v === "string") out.names[k] =
|
|
844
|
+
for (const [k, v] of Object.entries(r.names)) if (typeof v === "string") out.names[k] = path3.resolve(expandHome(v));
|
|
610
845
|
}
|
|
611
846
|
if (Array.isArray(r.report)) out.report = r.report.filter((q) => typeof q === "string");
|
|
612
847
|
if (Array.isArray(r.sendQuestions)) out.sendQuestions = r.sendQuestions.filter((q) => typeof q === "string").map(expandHome);
|
|
@@ -615,11 +850,11 @@ function loadConfig(file) {
|
|
|
615
850
|
}
|
|
616
851
|
function findMailbox(opts) {
|
|
617
852
|
const named = opts.flag || opts.config || opts.env;
|
|
618
|
-
if (named) return
|
|
619
|
-
let dir =
|
|
853
|
+
if (named) return path3.resolve(expandHome(named));
|
|
854
|
+
let dir = path3.resolve(opts.cwd);
|
|
620
855
|
for (; ; ) {
|
|
621
|
-
if (
|
|
622
|
-
const up =
|
|
856
|
+
if (existsSync3(path3.join(dir, ".crosstalk"))) return dir;
|
|
857
|
+
const up = path3.dirname(dir);
|
|
623
858
|
if (up === dir) return null;
|
|
624
859
|
dir = up;
|
|
625
860
|
}
|
|
@@ -718,8 +953,8 @@ function originIn(config) {
|
|
|
718
953
|
}
|
|
719
954
|
function under(tree, folders) {
|
|
720
955
|
return folders.some((f) => {
|
|
721
|
-
const folder =
|
|
722
|
-
return tree === folder || tree.startsWith(folder +
|
|
956
|
+
const folder = path3.resolve(expandHome(f));
|
|
957
|
+
return tree === folder || tree.startsWith(folder + path3.sep);
|
|
723
958
|
});
|
|
724
959
|
}
|
|
725
960
|
function reportable(r, only) {
|
|
@@ -727,7 +962,7 @@ function reportable(r, only) {
|
|
|
727
962
|
const e = entry.trim();
|
|
728
963
|
if (!e) return false;
|
|
729
964
|
if (e.toLowerCase() === r.name.toLowerCase() || !!r.remote && e.toLowerCase() === r.remote.toLowerCase()) return true;
|
|
730
|
-
return /^[~/.]/.test(e) &&
|
|
965
|
+
return /^[~/.]/.test(e) && path3.resolve(expandHome(e)) === r.tree;
|
|
731
966
|
});
|
|
732
967
|
}
|
|
733
968
|
function teamReport(o, only = null, sendQuestions = []) {
|
|
@@ -751,12 +986,13 @@ function teamReport(o, only = null, sendQuestions = []) {
|
|
|
751
986
|
}
|
|
752
987
|
|
|
753
988
|
// src/collect.ts
|
|
754
|
-
import { existsSync as
|
|
755
|
-
import
|
|
989
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
|
|
990
|
+
import path6 from "path";
|
|
756
991
|
|
|
757
992
|
// ../crosstalk/dist/index.mjs
|
|
758
|
-
import { existsSync as
|
|
759
|
-
import
|
|
993
|
+
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync3, statSync } from "fs";
|
|
994
|
+
import path4 from "path";
|
|
995
|
+
import { createHash as createHash2, createPrivateKey, createPublicKey, generateKeyPairSync, sign, verify } from "crypto";
|
|
760
996
|
var BOARD = "board";
|
|
761
997
|
var DAY_MS = 864e5;
|
|
762
998
|
function ageDays(sentAt, now) {
|
|
@@ -775,7 +1011,9 @@ function summarize(m, now) {
|
|
|
775
1011
|
sent_at: m.sent_at,
|
|
776
1012
|
acked: m.acked,
|
|
777
1013
|
age_days: ageDays(m.sent_at, now),
|
|
778
|
-
kind: m.kind ?? null
|
|
1014
|
+
kind: m.kind ?? null,
|
|
1015
|
+
author: m.author ?? null,
|
|
1016
|
+
signature_state: m.signature_state ?? null
|
|
779
1017
|
};
|
|
780
1018
|
}
|
|
781
1019
|
var plural2 = (n, one, many) => n === 1 ? one : many;
|
|
@@ -944,6 +1182,7 @@ function parseMessage(filename, raw, recipient, acked) {
|
|
|
944
1182
|
let kind = null;
|
|
945
1183
|
let thread = null;
|
|
946
1184
|
let replyTo = null;
|
|
1185
|
+
let author = null;
|
|
947
1186
|
let from = "";
|
|
948
1187
|
let subject = null;
|
|
949
1188
|
let sent = null;
|
|
@@ -966,6 +1205,7 @@ function parseMessage(filename, raw, recipient, acked) {
|
|
|
966
1205
|
} else if (m[1] === "expires") expires = /^\d{4}-\d{2}-\d{2}$/.test(m[2].trim()) ? m[2].trim() : null;
|
|
967
1206
|
else if (m[1] === "evidence") evidence = m[2].trim() || null;
|
|
968
1207
|
else if (m[1] === "settled_by") settledBy = m[2].trim() || null;
|
|
1208
|
+
else if (m[1] === "author") author = m[2].trim() || null;
|
|
969
1209
|
}
|
|
970
1210
|
}
|
|
971
1211
|
if (!from) from = "unknown";
|
|
@@ -984,29 +1224,105 @@ function parseMessage(filename, raw, recipient, acked) {
|
|
|
984
1224
|
tags,
|
|
985
1225
|
expires_on: expires,
|
|
986
1226
|
evidence: evidence && ["verified", "assumed"].includes(evidence) ? evidence : null,
|
|
987
|
-
settled_by: settledBy && SETTLED_BY.includes(settledBy) ? settledBy : null
|
|
1227
|
+
settled_by: settledBy && SETTLED_BY.includes(settledBy) ? settledBy : null,
|
|
1228
|
+
author
|
|
988
1229
|
};
|
|
989
1230
|
}
|
|
1231
|
+
var VERSION = "jq-crosstalk-signed-v1";
|
|
1232
|
+
function signingPayload(f) {
|
|
1233
|
+
return Buffer.from(
|
|
1234
|
+
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()]),
|
|
1235
|
+
"utf8"
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
function fingerprint(publicKey) {
|
|
1239
|
+
return createHash2("sha256").update(Buffer.from(publicKey, "base64")).digest("hex").slice(0, 16);
|
|
1240
|
+
}
|
|
1241
|
+
function parseSigners(text) {
|
|
1242
|
+
const signers = /* @__PURE__ */ new Map();
|
|
1243
|
+
for (const line of text.split("\n")) {
|
|
1244
|
+
const m = line.match(/^([a-z0-9][a-z0-9-]*):\s*([A-Za-z0-9+/=]+)\s*$/);
|
|
1245
|
+
if (m) signers.set(m[1], m[2]);
|
|
1246
|
+
}
|
|
1247
|
+
return signers;
|
|
1248
|
+
}
|
|
1249
|
+
function splitMessage(filename, raw) {
|
|
1250
|
+
const fields = { filename, from: "", to: "", subject: "", sent: "", kind: "", thread: "", reply_to: "", author: "", body: raw };
|
|
1251
|
+
let signature = "";
|
|
1252
|
+
const fm = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
1253
|
+
if (!fm) return { fields, signature };
|
|
1254
|
+
fields.body = fm[2];
|
|
1255
|
+
for (const line of fm[1].split("\n")) {
|
|
1256
|
+
const m = line.match(/^(\w+):\s*(.*)$/);
|
|
1257
|
+
if (!m) continue;
|
|
1258
|
+
const value = m[2].trim();
|
|
1259
|
+
if (m[1] === "signature") signature = value;
|
|
1260
|
+
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") {
|
|
1261
|
+
fields[m[1]] = value;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return { fields, signature };
|
|
1265
|
+
}
|
|
1266
|
+
function checkSignature(filename, raw, signers) {
|
|
1267
|
+
const { fields, signature } = splitMessage(filename, raw);
|
|
1268
|
+
const publicKey = signers.get(fields.from);
|
|
1269
|
+
const base = { from: fields.from, author: fields.author };
|
|
1270
|
+
if (!publicKey) return { ...base, state: signature ? "unknown-signer" : "not-required", key: "" };
|
|
1271
|
+
const key = fingerprint(publicKey);
|
|
1272
|
+
if (!signature) return { ...base, state: "unsigned", key };
|
|
1273
|
+
try {
|
|
1274
|
+
const ok = verify(
|
|
1275
|
+
null,
|
|
1276
|
+
signingPayload(fields),
|
|
1277
|
+
createPublicKey({ key: Buffer.from(publicKey, "base64"), format: "der", type: "spki" }),
|
|
1278
|
+
Buffer.from(signature, "base64")
|
|
1279
|
+
);
|
|
1280
|
+
return { ...base, state: ok ? "verified" : "failed", key };
|
|
1281
|
+
} catch {
|
|
1282
|
+
return { ...base, state: "failed", key };
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
990
1285
|
function names(dir) {
|
|
991
|
-
if (!
|
|
992
|
-
return readdirSync(dir).filter((n) => statSync(
|
|
1286
|
+
if (!existsSync4(dir)) return [];
|
|
1287
|
+
return readdirSync(dir).filter((n) => statSync(path4.join(dir, n)).isDirectory());
|
|
993
1288
|
}
|
|
994
1289
|
function readMailbox(root) {
|
|
995
|
-
if (!
|
|
1290
|
+
if (!existsSync4(path4.join(root, "inbox"))) throw new Error(`not a crosstalk mailbox (no inbox/ folder): ${root}`);
|
|
1291
|
+
const signersFile = path4.join(root, "registry", "signers.txt");
|
|
1292
|
+
const signers = existsSync4(signersFile) ? parseSigners(readFileSync3(signersFile, "utf8")) : /* @__PURE__ */ new Map();
|
|
996
1293
|
const byKey = /* @__PURE__ */ new Map();
|
|
997
1294
|
for (const [base, acked] of [["inbox", false], ["archive", true]]) {
|
|
998
|
-
for (const name of names(
|
|
999
|
-
const dir =
|
|
1295
|
+
for (const name of names(path4.join(root, base))) {
|
|
1296
|
+
const dir = path4.join(root, base, name);
|
|
1000
1297
|
for (const file of readdirSync(dir).filter((f) => f.endsWith(".md"))) {
|
|
1001
|
-
const
|
|
1298
|
+
const raw = readFileSync3(path4.join(dir, file), "utf8");
|
|
1299
|
+
const row22 = parseMessage(file, raw, name, acked);
|
|
1300
|
+
const state = checkSignature(file, raw, signers).state;
|
|
1002
1301
|
const key = `${name}/${file}`;
|
|
1003
1302
|
const prev = byKey.get(key);
|
|
1004
|
-
if (!prev || acked && !prev.acked) byKey.set(key, { id: key, ...row22 });
|
|
1303
|
+
if (!prev || acked && !prev.acked) byKey.set(key, { id: key, ...row22, signature_state: state === "not-required" ? null : state });
|
|
1005
1304
|
}
|
|
1006
1305
|
}
|
|
1007
1306
|
}
|
|
1008
1307
|
return [...byKey.values()].sort((a, b) => a.id.localeCompare(b.id));
|
|
1009
1308
|
}
|
|
1309
|
+
var TOOLBAR_CSS2 = `
|
|
1310
|
+
body{padding-bottom:64px}
|
|
1311
|
+
.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)}
|
|
1312
|
+
.jqbar a{color:var(--link,LinkText)}
|
|
1313
|
+
.jqbar .here{font-weight:700}
|
|
1314
|
+
.jqbar details[open]{order:-1;flex-basis:100%}
|
|
1315
|
+
.jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
|
|
1316
|
+
.jqbar summary::-webkit-details-marker{display:none}
|
|
1317
|
+
.jqbar summary::after{content:" \u25B8"}
|
|
1318
|
+
.jqbar details[open] summary::after{content:" \u25BE"}
|
|
1319
|
+
.jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
|
|
1320
|
+
.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)}
|
|
1321
|
+
.jqbar details>div p{margin:0 0 4px}
|
|
1322
|
+
.jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
|
|
1323
|
+
.jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
|
|
1324
|
+
@media print{.jqbar{display:none}body{padding-bottom:0}}
|
|
1325
|
+
`;
|
|
1010
1326
|
var esc2 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
1011
1327
|
var age = (d) => d === null ? "no date" : d === 0 ? "today" : d === 1 ? "1 day" : `${d} days`;
|
|
1012
1328
|
var SETTLED = {
|
|
@@ -1019,14 +1335,16 @@ var SETTLED = {
|
|
|
1019
1335
|
function row(m, bodies, note, showTo = false) {
|
|
1020
1336
|
const kind = m.kind && m.kind !== "brief" ? `<span class="kind">${esc2(m.kind)}</span> ` : "";
|
|
1021
1337
|
const to = showTo ? ` <span class="mut">to</span> <span class="chip">${esc2(m.to_session)}</span>` : "";
|
|
1022
|
-
|
|
1338
|
+
const who = m.author ? ` <span class="mut">${esc2(m.author)}</span>` : "";
|
|
1339
|
+
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>` : "";
|
|
1340
|
+
return `<details><summary><span class="chip">${esc2(m.from_session)}</span>${who}${signed}${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>`;
|
|
1023
1341
|
}
|
|
1024
1342
|
function post(p, bodies) {
|
|
1025
1343
|
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"}`;
|
|
1026
1344
|
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("");
|
|
1027
1345
|
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>`;
|
|
1028
1346
|
}
|
|
1029
|
-
function renderPage2(r) {
|
|
1347
|
+
function renderPage2(r, bar = "") {
|
|
1030
1348
|
const waiting = r.waiting.inboxes.map(
|
|
1031
1349
|
(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>`
|
|
1032
1350
|
).join("");
|
|
@@ -1049,14 +1367,14 @@ details{border-top:1px solid var(--line)}summary{cursor:pointer;padding:8px 12px
|
|
|
1049
1367
|
.subj{font-weight:500}.file{font-family:ui-monospace,monospace;margin:0;padding:0 12px;word-break:break-all}
|
|
1050
1368
|
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}
|
|
1051
1369
|
.state{font-size:12px}.state.open{color:var(--ok)}.state.expired{color:var(--bad)}.state.closed{color:var(--mut)}
|
|
1052
|
-
</style></head><body><main>
|
|
1370
|
+
${bar ? TOOLBAR_CSS2 : ""}</style></head><body><main>
|
|
1053
1371
|
<h1>Crosstalk</h1>
|
|
1054
1372
|
<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>
|
|
1055
1373
|
<h2>Waiting</h2><p class="lead">${esc2(r.waiting.headline)}</p>${waiting}
|
|
1056
1374
|
<h2>Board</h2><p class="lead">${esc2(r.board.headline)}</p>${r.board.open.map((p) => post(p, r.bodies)).join("")}
|
|
1057
1375
|
${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>` : ""}
|
|
1058
1376
|
<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}
|
|
1059
|
-
</main
|
|
1377
|
+
</main>${bar}</body></html>`;
|
|
1060
1378
|
}
|
|
1061
1379
|
var THREADS_SHOWN = 60;
|
|
1062
1380
|
function buildReport(root, now = Date.now()) {
|
|
@@ -1078,9 +1396,9 @@ function buildReport(root, now = Date.now()) {
|
|
|
1078
1396
|
}
|
|
1079
1397
|
|
|
1080
1398
|
// ../groundcrew/dist/index.mjs
|
|
1081
|
-
import { existsSync as
|
|
1082
|
-
import
|
|
1083
|
-
import
|
|
1399
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
1400
|
+
import os5 from "os";
|
|
1401
|
+
import path5 from "path";
|
|
1084
1402
|
var DOCS = "https://code.claude.com/docs/en";
|
|
1085
1403
|
var MEMORY_LINE_TARGET = 200;
|
|
1086
1404
|
var MEMORY_LINE_FAIL = 400;
|
|
@@ -1092,6 +1410,136 @@ function deniesSecrets(rule) {
|
|
|
1092
1410
|
function allowsEveryCommand(rule) {
|
|
1093
1411
|
return /^Bash(\(\s*(\*|:\*|\*\*)?\s*\))?$/.test(rule.trim());
|
|
1094
1412
|
}
|
|
1413
|
+
var COMMAND_HEADS = new Set(
|
|
1414
|
+
"git gh npm npx pnpm yarn bun node deno python python3 pip pip3 uv poetry cargo go make docker kubectl helm terraform aws gcloud az psql mysql sqlite3 redis-cli curl wget ssh scp rsync rm mv cp chmod chown sudo kill pkill brew apt railway vercel netlify fly heroku firebase wrangler tsc eslint ruff prettier dprint jest vitest pytest nx turbo gradle mvn dotnet rails rake bundle composer php launchctl systemctl".split(" ")
|
|
1415
|
+
);
|
|
1416
|
+
var NEVER_WORDS = /\b(never|do not|don['’]t|must not|mustn['’]t|not allowed|forbidden|prohibited)\b/i;
|
|
1417
|
+
var ASK_WORDS = /\bask\b[^.]{0,40}\b(first|before)\b|\bgo-ahead\b|\bwithout (asking|approval|permission|confirmation)\b|\b(needs?|requires?|get|wait for) [^.]{0,30}\b(approval|confirmation|sign-off|say-so)\b|\bconfirm (first|before)\b/i;
|
|
1418
|
+
var BARE_COMMANDS = /\b(git (?:push|reset --hard|reset|rebase|merge|commit|clean|stash)|gh (?:pr|issue|release|repo) [a-z]+|npm publish|rm -rf)\b/g;
|
|
1419
|
+
var restrictionKind = (text) => ASK_WORDS.test(text) ? "ask" : NEVER_WORDS.test(text) ? "never" : null;
|
|
1420
|
+
function commandStart(span) {
|
|
1421
|
+
const words = span.trim().replace(/^\$\s+/, "").split(/\s+/);
|
|
1422
|
+
if (!COMMAND_HEADS.has(words[0])) return "";
|
|
1423
|
+
const kept = [words[0]];
|
|
1424
|
+
for (const word of words.slice(1, 3)) {
|
|
1425
|
+
if (!/^(--?[a-z][a-z-]*|[a-z0-9][a-z0-9:_-]*)$/i.test(word)) break;
|
|
1426
|
+
kept.push(word);
|
|
1427
|
+
}
|
|
1428
|
+
return kept.join(" ");
|
|
1429
|
+
}
|
|
1430
|
+
function findRestrictedCommands(text, file) {
|
|
1431
|
+
const found = [];
|
|
1432
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1433
|
+
const add = (kind, command, line) => {
|
|
1434
|
+
if (!command || seen.has(command)) return;
|
|
1435
|
+
seen.add(command);
|
|
1436
|
+
found.push({ file, line, kind, command });
|
|
1437
|
+
};
|
|
1438
|
+
const commandsIn = (part) => {
|
|
1439
|
+
const spans = [...part.matchAll(/`([^`]+)`/g)].flatMap((m) => m[1].split("/").map(commandStart));
|
|
1440
|
+
const bare = [...part.replace(/`[^`]*`/g, " ").matchAll(BARE_COMMANDS)].map((m) => m[1]);
|
|
1441
|
+
return [...spans, ...bare].filter(Boolean);
|
|
1442
|
+
};
|
|
1443
|
+
const readBlock = (block2, line, inherited) => {
|
|
1444
|
+
let matched = false;
|
|
1445
|
+
for (const sentence of block2.split(/(?<=[.!?:])\s+|\s[—–]\s|;\s/)) {
|
|
1446
|
+
const kind = restrictionKind(sentence);
|
|
1447
|
+
if (!kind) continue;
|
|
1448
|
+
matched = true;
|
|
1449
|
+
const at = sentence.search(kind === "ask" ? ASK_WORDS : NEVER_WORDS);
|
|
1450
|
+
for (const command of commandsIn(kind === "ask" ? sentence : sentence.slice(at))) add(kind, command, line);
|
|
1451
|
+
}
|
|
1452
|
+
if (!matched && inherited) for (const command of commandsIn(block2)) add(inherited, command, line);
|
|
1453
|
+
};
|
|
1454
|
+
let headingKind = null;
|
|
1455
|
+
let block = "";
|
|
1456
|
+
let blockLine = 0;
|
|
1457
|
+
let blockIsItem = false;
|
|
1458
|
+
let fenced = false;
|
|
1459
|
+
const flush = () => {
|
|
1460
|
+
if (block) readBlock(block, blockLine, blockIsItem ? headingKind : null);
|
|
1461
|
+
block = "";
|
|
1462
|
+
};
|
|
1463
|
+
text.split("\n").forEach((raw, index) => {
|
|
1464
|
+
if (/^\s*(```|~~~)/.test(raw)) {
|
|
1465
|
+
flush();
|
|
1466
|
+
fenced = !fenced;
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
if (fenced) return;
|
|
1470
|
+
if (/^#{1,6}\s/.test(raw)) {
|
|
1471
|
+
flush();
|
|
1472
|
+
headingKind = restrictionKind(raw);
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (!raw.trim()) return flush();
|
|
1476
|
+
const startsItem = /^\s*([-*+]|\d+[.)])\s/.test(raw) || /^\s*\|/.test(raw);
|
|
1477
|
+
if (startsItem) flush();
|
|
1478
|
+
if (!block) {
|
|
1479
|
+
blockLine = index + 1;
|
|
1480
|
+
blockIsItem = startsItem;
|
|
1481
|
+
}
|
|
1482
|
+
block += (block ? " " : "") + raw.trim();
|
|
1483
|
+
});
|
|
1484
|
+
flush();
|
|
1485
|
+
return found;
|
|
1486
|
+
}
|
|
1487
|
+
function ruleCovers(rule, command) {
|
|
1488
|
+
const trimmed = rule.trim();
|
|
1489
|
+
if (allowsEveryCommand(trimmed)) return true;
|
|
1490
|
+
const inner = /^Bash\((.*)\)$/.exec(trimmed)?.[1];
|
|
1491
|
+
if (inner === void 0) return false;
|
|
1492
|
+
const pattern = inner.replace(/:\*$/, " *").trim();
|
|
1493
|
+
const regex = new RegExp("^" + pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*") + "$");
|
|
1494
|
+
return regex.test(command) || regex.test(`${command} x`);
|
|
1495
|
+
}
|
|
1496
|
+
var NO_PROMPT_MODES = /* @__PURE__ */ new Set(["bypassPermissions", "auto"]);
|
|
1497
|
+
function proseFindings(facts) {
|
|
1498
|
+
const files = facts.settings;
|
|
1499
|
+
const covers = (rules, command) => rules.some((rule) => ruleCovers(rule, command));
|
|
1500
|
+
const [deny, ask, allow] = [all(files, (f) => f.deny), all(files, (f) => f.ask), all(files, (f) => f.allow)];
|
|
1501
|
+
const noPrompt = files.some((f) => f.defaultMode !== null && NO_PROMPT_MODES.has(f.defaultMode));
|
|
1502
|
+
return (facts.restricted ?? []).map((r) => {
|
|
1503
|
+
const enforced = covers(deny, r.command) || r.kind === "ask" && covers(ask, r.command);
|
|
1504
|
+
const state = enforced ? "enforced" : covers(allow, r.command) || noPrompt ? "allowed" : r.kind === "ask" ? "prompt" : "open";
|
|
1505
|
+
return { ...r, state };
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
var nameFinding = (f) => `"${f.command}" (${f.kind === "ask" ? "ask first" : "never"}, ${f.file} line ${f.line})`;
|
|
1509
|
+
var listFindings = (findings, limit = 4) => findings.slice(0, limit).map(nameFinding).join("; ") + (findings.length > limit ? `; and ${findings.length - limit} more` : "");
|
|
1510
|
+
function proseChecks(facts) {
|
|
1511
|
+
const source = `${DOCS}/permissions.md`;
|
|
1512
|
+
const base = { id: "prose-rules", group: "guardrails", title: "Rules in the instructions have a permission rule behind them", source };
|
|
1513
|
+
const findings = proseFindings(facts);
|
|
1514
|
+
if (!findings.length) {
|
|
1515
|
+
return [
|
|
1516
|
+
{
|
|
1517
|
+
...base,
|
|
1518
|
+
status: "info",
|
|
1519
|
+
detail: 'No instruction file names a command to never run, or to ask about first. Only a command written out, such as "git push", is found.',
|
|
1520
|
+
fix: ""
|
|
1521
|
+
}
|
|
1522
|
+
];
|
|
1523
|
+
}
|
|
1524
|
+
const allowed = findings.filter((f) => f.state === "allowed");
|
|
1525
|
+
const open2 = findings.filter((f) => f.state === "open");
|
|
1526
|
+
const prompt = findings.filter((f) => f.state === "prompt");
|
|
1527
|
+
const enforced = findings.filter((f) => f.state === "enforced");
|
|
1528
|
+
const parts = [];
|
|
1529
|
+
if (allowed.length) parts.push(`The instructions restrict ${plural3(allowed.length, "command")} that an allow rule or the permission mode lets run without asking: ${listFindings(allowed)}.`);
|
|
1530
|
+
if (open2.length) parts.push(`${plural3(open2.length, "command")} the instructions say never to run ${open2.length === 1 ? "has" : "have"} no deny rule: ${listFindings(open2)}.`);
|
|
1531
|
+
if (prompt.length) parts.push(`${plural3(prompt.length, "ask-first command")} ${prompt.length === 1 ? "is" : "are"} held only by the default prompt, which one "don't ask again" removes: ${listFindings(prompt, 3)}.`);
|
|
1532
|
+
if (enforced.length) parts.push(`${plural3(enforced.length, "restricted command")} ${enforced.length === 1 ? "has" : "have"} a rule behind ${enforced.length === 1 ? "it" : "them"}.`);
|
|
1533
|
+
const needsLook = allowed.length > 0 || open2.length > 0;
|
|
1534
|
+
return [
|
|
1535
|
+
{
|
|
1536
|
+
...base,
|
|
1537
|
+
status: needsLook ? "warn" : "pass",
|
|
1538
|
+
detail: parts.join(" ") + (needsLook ? " This check reads words, so confirm each line means what it found." : ""),
|
|
1539
|
+
fix: needsLook ? `The docs say "Permission rules are enforced by Claude Code, not by the model", and that instructions "shape what Claude tries to do, but they don't change these rules". Add a deny rule for a command the instructions forbid and an ask rule for one they say to ask about, and remove an allow rule that contradicts them.` : ""
|
|
1540
|
+
}
|
|
1541
|
+
];
|
|
1542
|
+
}
|
|
1095
1543
|
function memoryChecks(facts) {
|
|
1096
1544
|
const source = `${DOCS}/memory.md`;
|
|
1097
1545
|
if (!facts.memory.length) {
|
|
@@ -1270,13 +1718,13 @@ function guardrailChecks(facts) {
|
|
|
1270
1718
|
}
|
|
1271
1719
|
return checks;
|
|
1272
1720
|
}
|
|
1273
|
-
function
|
|
1721
|
+
function looksLikeACheck2(command) {
|
|
1274
1722
|
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);
|
|
1275
1723
|
}
|
|
1276
1724
|
function verificationChecks(facts) {
|
|
1277
1725
|
const files = facts.settings;
|
|
1278
|
-
const allowed = all(files, (f) => f.allow.filter((rule) => /^Bash\(/.test(rule) &&
|
|
1279
|
-
const hooked = all(files, (f) => f.hookCommands.filter((h) =>
|
|
1726
|
+
const allowed = all(files, (f) => f.allow.filter((rule) => /^Bash\(/.test(rule) && looksLikeACheck2(rule)));
|
|
1727
|
+
const hooked = all(files, (f) => f.hookCommands.filter((h) => looksLikeACheck2(h.command)));
|
|
1280
1728
|
const stopEvents = [...new Set(all(files, (f) => f.hookEvents.filter((event) => event === "Stop" || event === "SubagentStop")))].sort();
|
|
1281
1729
|
const unscoped = facts.subagentFiles.filter((agent) => !agent.limitsTools).map((agent) => agent.name);
|
|
1282
1730
|
const checks = [
|
|
@@ -1342,6 +1790,10 @@ function promptFor(check, facts) {
|
|
|
1342
1790
|
const rules = facts.secretFiles.length ? facts.secretFiles.map((file) => `Read(./${file})`).join(", ") : "Read(./.env), Read(./secrets/**)";
|
|
1343
1791
|
return `Add deny rules to the permissions.deny array in .claude/settings.json so that Claude Code cannot read secret files: ${rules}. Keep every rule that is already in the file. Show me the diff before you save it, and tell me how to confirm afterwards that a read of one of these files is refused.`;
|
|
1344
1792
|
}
|
|
1793
|
+
case "prose-rules": {
|
|
1794
|
+
const findings = proseFindings(facts).filter((f) => f.state === "allowed" || f.state === "open");
|
|
1795
|
+
return `My instruction files restrict these commands, and no permission rule enforces it: ${findings.map(nameFinding).join("; ")}. First read each line and tell me if it really restricts that command. For each one that does, propose a rule for the permissions in .claude/settings.json: a deny rule where the instructions say never, an ask rule where they say to ask first. If an allow rule in any settings file approves one of these commands, show me that rule and say whether to remove it. Keep every other rule. Show me the diff before you save it, and tell me how to confirm afterwards that each rule works.`;
|
|
1796
|
+
}
|
|
1345
1797
|
case "broad-allow":
|
|
1346
1798
|
return "My Claude Code settings hold an allow rule that approves every shell command. Find it in the settings files, then list the shell commands this project really needs, such as its test, lint and build commands. Propose scoped allow rules for those to replace the blanket rule. Show me the diff before you save it.";
|
|
1347
1799
|
case "sandbox":
|
|
@@ -1356,9 +1808,80 @@ function promptFor(check, facts) {
|
|
|
1356
1808
|
return "";
|
|
1357
1809
|
}
|
|
1358
1810
|
}
|
|
1811
|
+
var LAYER_OF = {
|
|
1812
|
+
"memory-exists": "guides",
|
|
1813
|
+
"memory-length": "guides",
|
|
1814
|
+
skills: "guides",
|
|
1815
|
+
"legacy-commands": "guides",
|
|
1816
|
+
hooks: "sensors",
|
|
1817
|
+
"verify-command": "sensors",
|
|
1818
|
+
"stop-check": "loop",
|
|
1819
|
+
"auto-memory-index": "memory",
|
|
1820
|
+
"allow-rules": "permissions",
|
|
1821
|
+
"subagents-and-mcp": "permissions",
|
|
1822
|
+
"deny-secrets": "permissions",
|
|
1823
|
+
"broad-allow": "permissions",
|
|
1824
|
+
"default-mode": "permissions",
|
|
1825
|
+
sandbox: "permissions",
|
|
1826
|
+
reach: "permissions",
|
|
1827
|
+
managed: "permissions",
|
|
1828
|
+
"prose-rules": "permissions",
|
|
1829
|
+
"subagent-scope": "permissions",
|
|
1830
|
+
retention: "observability"
|
|
1831
|
+
};
|
|
1832
|
+
function layerOf(id) {
|
|
1833
|
+
return LAYER_OF[id.split(":")[0]] ?? "guides";
|
|
1834
|
+
}
|
|
1835
|
+
var LAYERS = [
|
|
1836
|
+
{
|
|
1837
|
+
key: "guides",
|
|
1838
|
+
title: "Guides",
|
|
1839
|
+
what: "What steers the agent before it works: instructions, rules and skills.",
|
|
1840
|
+
unchecked: "It does not judge what the instructions say, only how long they are."
|
|
1841
|
+
},
|
|
1842
|
+
{
|
|
1843
|
+
key: "sensors",
|
|
1844
|
+
title: "Sensors",
|
|
1845
|
+
what: "What checks the work: tests, linters and hooks the agent can run.",
|
|
1846
|
+
unchecked: "It does not see your CI, so it cannot tell a check that always fails from one that works."
|
|
1847
|
+
},
|
|
1848
|
+
{
|
|
1849
|
+
key: "loop",
|
|
1850
|
+
title: "Loop",
|
|
1851
|
+
what: "What sends the agent back when the work is not done.",
|
|
1852
|
+
unchecked: "It does not look at retry or spending limits for runs with no person present."
|
|
1853
|
+
},
|
|
1854
|
+
{
|
|
1855
|
+
key: "memory",
|
|
1856
|
+
title: "Memory",
|
|
1857
|
+
what: "What carries over from one session to the next.",
|
|
1858
|
+
unchecked: "It does not look for handoff notes or a record of decisions."
|
|
1859
|
+
},
|
|
1860
|
+
{
|
|
1861
|
+
key: "permissions",
|
|
1862
|
+
title: "Permissions",
|
|
1863
|
+
what: "What the agent may do without asking, and what it may never do.",
|
|
1864
|
+
unchecked: "It finds a restricted command only when the instructions write it out, as in git push. It does not understand a rule in plain words."
|
|
1865
|
+
},
|
|
1866
|
+
{
|
|
1867
|
+
key: "observability",
|
|
1868
|
+
title: "Observability",
|
|
1869
|
+
what: "What a person can see of what the agent did.",
|
|
1870
|
+
unchecked: "It does not look for cost tracking or alerts."
|
|
1871
|
+
}
|
|
1872
|
+
];
|
|
1359
1873
|
function runChecks(facts) {
|
|
1360
|
-
const checks = [...memoryChecks(facts), ...automationChecks(facts), ...guardrailChecks(facts), ...verificationChecks(facts)];
|
|
1361
|
-
return checks.map((check) => ({ ...check, prompt: promptFor(check, facts) }));
|
|
1874
|
+
const checks = [...memoryChecks(facts), ...automationChecks(facts), ...guardrailChecks(facts), ...proseChecks(facts), ...verificationChecks(facts)];
|
|
1875
|
+
return checks.map((check) => ({ ...check, layer: layerOf(check.id), prompt: promptFor(check, facts) }));
|
|
1876
|
+
}
|
|
1877
|
+
function layerSummary(checks) {
|
|
1878
|
+
return LAYERS.map(({ key, title }) => {
|
|
1879
|
+
const mine = checks.filter((c) => c.layer === key);
|
|
1880
|
+
const count = (status) => mine.filter((c) => c.status === status).length;
|
|
1881
|
+
const [pass, warn, fail, info] = [count("pass"), count("warn"), count("fail"), count("info")];
|
|
1882
|
+
const state = fail ? "fix" : warn ? "look" : pass ? "good" : info ? "facts" : "none";
|
|
1883
|
+
return { layer: key, title, pass, warn, fail, info, state };
|
|
1884
|
+
});
|
|
1362
1885
|
}
|
|
1363
1886
|
function summarize2(checks) {
|
|
1364
1887
|
const count = (status) => checks.filter((c) => c.status === status).length;
|
|
@@ -1370,8 +1893,8 @@ var SECRET_NAMES = /^(\.env(\..+)?|secrets?(\..+)?|credentials(\..+)?|.*\.pem|id
|
|
|
1370
1893
|
var NOT_SECRET = /\.(example|sample|template)$/i;
|
|
1371
1894
|
var SECRET_DEPTH = 3;
|
|
1372
1895
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "vendor", "coverage"]);
|
|
1373
|
-
var home = () =>
|
|
1374
|
-
var configDir = () => process.env.CLAUDE_CONFIG_DIR ||
|
|
1896
|
+
var home = () => os5.homedir();
|
|
1897
|
+
var configDir = () => process.env.CLAUDE_CONFIG_DIR || path5.join(home(), ".claude");
|
|
1375
1898
|
var tilde = (file) => file.startsWith(home()) ? `~${file.slice(home().length)}` : file;
|
|
1376
1899
|
function canRead(project) {
|
|
1377
1900
|
try {
|
|
@@ -1383,23 +1906,29 @@ function canRead(project) {
|
|
|
1383
1906
|
}
|
|
1384
1907
|
function readJson(file) {
|
|
1385
1908
|
try {
|
|
1386
|
-
return JSON.parse(
|
|
1909
|
+
return JSON.parse(readFileSync4(file, "utf-8"));
|
|
1387
1910
|
} catch {
|
|
1388
1911
|
return null;
|
|
1389
1912
|
}
|
|
1390
1913
|
}
|
|
1391
1914
|
function countFiles(dir, test) {
|
|
1392
|
-
if (!
|
|
1915
|
+
if (!existsSync5(dir)) return 0;
|
|
1393
1916
|
let total = 0;
|
|
1394
1917
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1395
|
-
if (entry.isDirectory()) total += countFiles(
|
|
1918
|
+
if (entry.isDirectory()) total += countFiles(path5.join(dir, entry.name), test);
|
|
1396
1919
|
else if (test(entry.name)) total += 1;
|
|
1397
1920
|
}
|
|
1398
1921
|
return total;
|
|
1399
1922
|
}
|
|
1923
|
+
function markdownFiles(dir) {
|
|
1924
|
+
if (!existsSync5(dir)) return [];
|
|
1925
|
+
return readdirSync2(dir, { withFileTypes: true }).flatMap(
|
|
1926
|
+
(entry) => entry.isDirectory() ? markdownFiles(path5.join(dir, entry.name)) : entry.name.endsWith(".md") ? [path5.join(dir, entry.name)] : []
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1400
1929
|
function findSecretFiles(root, relative, depth) {
|
|
1401
|
-
const dir =
|
|
1402
|
-
if (depth > SECRET_DEPTH || !
|
|
1930
|
+
const dir = path5.join(root, relative);
|
|
1931
|
+
if (depth > SECRET_DEPTH || !existsSync5(dir)) return [];
|
|
1403
1932
|
const found = [];
|
|
1404
1933
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1405
1934
|
const here = relative ? `${relative}/${entry.name}` : entry.name;
|
|
@@ -1423,13 +1952,13 @@ function hookCommands(hooks) {
|
|
|
1423
1952
|
return found;
|
|
1424
1953
|
}
|
|
1425
1954
|
function subagentFiles(dir) {
|
|
1426
|
-
if (!
|
|
1955
|
+
if (!existsSync5(dir)) return [];
|
|
1427
1956
|
const found = [];
|
|
1428
1957
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1429
|
-
const file =
|
|
1958
|
+
const file = path5.join(dir, entry.name);
|
|
1430
1959
|
if (entry.isDirectory()) found.push(...subagentFiles(file));
|
|
1431
1960
|
else if (entry.name.endsWith(".md")) {
|
|
1432
|
-
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(
|
|
1961
|
+
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(readFileSync4(file, "utf-8"))?.[1] ?? "";
|
|
1433
1962
|
found.push({ name: entry.name.replace(/\.md$/, ""), limitsTools: /^(tools|disallowedTools)\s*:/m.test(frontmatter) });
|
|
1434
1963
|
}
|
|
1435
1964
|
}
|
|
@@ -1439,20 +1968,25 @@ var isMarkdown = (name) => name.endsWith(".md");
|
|
|
1439
1968
|
var strings = (value) => Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
1440
1969
|
function gather(project) {
|
|
1441
1970
|
const filesRead = [];
|
|
1442
|
-
const label = (file) => file.startsWith(project +
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1971
|
+
const label = (file) => file.startsWith(project + path5.sep) ? file.slice(project.length + 1) : tilde(file);
|
|
1972
|
+
const restricted = [];
|
|
1973
|
+
const memoryFile = (file, instructions = true) => {
|
|
1974
|
+
if (!existsSync5(file) || !statSync2(file).isFile()) return null;
|
|
1975
|
+
const text = readFileSync4(file, "utf-8");
|
|
1446
1976
|
filesRead.push(label(file));
|
|
1977
|
+
if (instructions) restricted.push(...findRestrictedCommands(text, label(file)));
|
|
1447
1978
|
return { label: label(file), lines: text.split("\n").length - (text.endsWith("\n") ? 1 : 0), bytes: Buffer.byteLength(text) };
|
|
1448
1979
|
};
|
|
1449
1980
|
const memory = [
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
].map(memoryFile).filter((file) => file !== null);
|
|
1981
|
+
path5.join(project, "CLAUDE.md"),
|
|
1982
|
+
path5.join(project, ".claude", "CLAUDE.md"),
|
|
1983
|
+
path5.join(project, "CLAUDE.local.md"),
|
|
1984
|
+
path5.join(project, "AGENTS.md"),
|
|
1985
|
+
path5.join(configDir(), "CLAUDE.md")
|
|
1986
|
+
].map((file) => memoryFile(file)).filter((file) => file !== null);
|
|
1987
|
+
for (const dir of [path5.join(project, ".claude", "rules"), path5.join(configDir(), "rules")]) {
|
|
1988
|
+
for (const file of markdownFiles(dir)) restricted.push(...findRestrictedCommands(readFileSync4(file, "utf-8"), label(file)));
|
|
1989
|
+
}
|
|
1456
1990
|
const settingsFile = (scope, file) => {
|
|
1457
1991
|
const json = readJson(file);
|
|
1458
1992
|
if (!json) return null;
|
|
@@ -1476,12 +2010,12 @@ function gather(project) {
|
|
|
1476
2010
|
const managed = process.platform === "darwin" ? "/Library/Application Support/ClaudeCode/managed-settings.json" : process.platform === "win32" ? "C:\\Program Files\\ClaudeCode\\managed-settings.json" : "/etc/claude-code/managed-settings.json";
|
|
1477
2011
|
const settings = [
|
|
1478
2012
|
settingsFile("managed", managed),
|
|
1479
|
-
settingsFile("local",
|
|
1480
|
-
settingsFile("project",
|
|
1481
|
-
settingsFile("user",
|
|
2013
|
+
settingsFile("local", path5.join(project, ".claude", "settings.local.json")),
|
|
2014
|
+
settingsFile("project", path5.join(project, ".claude", "settings.json")),
|
|
2015
|
+
settingsFile("user", path5.join(configDir(), "settings.json"))
|
|
1482
2016
|
].filter((file) => file !== null);
|
|
1483
|
-
const projectMcp = readJson(
|
|
1484
|
-
const userConfig = readJson(
|
|
2017
|
+
const projectMcp = readJson(path5.join(project, ".mcp.json"));
|
|
2018
|
+
const userConfig = readJson(path5.join(home(), ".claude.json"));
|
|
1485
2019
|
const userServers = Object.keys(userConfig?.mcpServers || {}).length + Object.keys(userConfig?.projects?.[project]?.mcpServers || {}).length;
|
|
1486
2020
|
if (projectMcp) filesRead.push(".mcp.json");
|
|
1487
2021
|
if (userConfig) filesRead.push("~/.claude.json (MCP server names only)");
|
|
@@ -1491,25 +2025,43 @@ function gather(project) {
|
|
|
1491
2025
|
facts: {
|
|
1492
2026
|
platform: process.platform,
|
|
1493
2027
|
memory,
|
|
1494
|
-
ruleFiles: countFiles(
|
|
1495
|
-
autoMemoryIndex: memoryFile(
|
|
2028
|
+
ruleFiles: countFiles(path5.join(project, ".claude", "rules"), isMarkdown) + countFiles(path5.join(configDir(), "rules"), isMarkdown),
|
|
2029
|
+
autoMemoryIndex: memoryFile(path5.join(configDir(), "projects", encoded, "memory", "MEMORY.md"), false),
|
|
1496
2030
|
settings,
|
|
1497
2031
|
skills: {
|
|
1498
|
-
project: countFiles(
|
|
1499
|
-
user: countFiles(
|
|
2032
|
+
project: countFiles(path5.join(project, ".claude", "skills"), (name) => name === "SKILL.md"),
|
|
2033
|
+
user: countFiles(path5.join(configDir(), "skills"), (name) => name === "SKILL.md")
|
|
1500
2034
|
},
|
|
1501
2035
|
subagents: {
|
|
1502
|
-
project: countFiles(
|
|
1503
|
-
user: countFiles(
|
|
2036
|
+
project: countFiles(path5.join(project, ".claude", "agents"), isMarkdown),
|
|
2037
|
+
user: countFiles(path5.join(configDir(), "agents"), isMarkdown)
|
|
1504
2038
|
},
|
|
1505
|
-
subagentFiles: [...subagentFiles(
|
|
1506
|
-
legacyCommands: countFiles(
|
|
2039
|
+
subagentFiles: [...subagentFiles(path5.join(project, ".claude", "agents")), ...subagentFiles(path5.join(configDir(), "agents"))],
|
|
2040
|
+
legacyCommands: countFiles(path5.join(project, ".claude", "commands"), isMarkdown),
|
|
1507
2041
|
mcpServers: { project: Object.keys(projectMcp?.mcpServers || {}).length, user: userServers },
|
|
1508
|
-
secretFiles: findSecretFiles(project, "", 0).sort()
|
|
2042
|
+
secretFiles: findSecretFiles(project, "", 0).sort(),
|
|
2043
|
+
restricted
|
|
1509
2044
|
}
|
|
1510
2045
|
};
|
|
1511
2046
|
}
|
|
1512
|
-
var
|
|
2047
|
+
var TOOLBAR_CSS3 = `
|
|
2048
|
+
body{padding-bottom:64px}
|
|
2049
|
+
.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)}
|
|
2050
|
+
.jqbar a{color:var(--link,LinkText)}
|
|
2051
|
+
.jqbar .here{font-weight:700}
|
|
2052
|
+
.jqbar details[open]{order:-1;flex-basis:100%}
|
|
2053
|
+
.jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
|
|
2054
|
+
.jqbar summary::-webkit-details-marker{display:none}
|
|
2055
|
+
.jqbar summary::after{content:" \u25B8"}
|
|
2056
|
+
.jqbar details[open] summary::after{content:" \u25BE"}
|
|
2057
|
+
.jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
|
|
2058
|
+
.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)}
|
|
2059
|
+
.jqbar details>div p{margin:0 0 4px}
|
|
2060
|
+
.jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
|
|
2061
|
+
.jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
|
|
2062
|
+
@media print{.jqbar{display:none}body{padding-bottom:0}}
|
|
2063
|
+
`;
|
|
2064
|
+
var esc22 = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
1513
2065
|
var STATUS = {
|
|
1514
2066
|
fail: { icon: "\u2715", word: "Fix" },
|
|
1515
2067
|
warn: { icon: "!", word: "Look" },
|
|
@@ -1558,42 +2110,55 @@ function done(){b.textContent='Copied';setTimeout(function(){b.textContent='Copy
|
|
|
1558
2110
|
function old(){var a=document.createElement('textarea');a.value=t;document.body.appendChild(a);a.select();document.execCommand('copy');a.remove();done()}
|
|
1559
2111
|
if(navigator.clipboard&&window.isSecureContext){navigator.clipboard.writeText(t).then(done,old)}else{old()}});`;
|
|
1560
2112
|
var dot = (status) => `<span class="dot s-${status}" aria-hidden="true">${STATUS[status].icon}</span>`;
|
|
1561
|
-
var sourceLink = (check) => `<a href="${
|
|
2113
|
+
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>`;
|
|
1562
2114
|
function fixCard(check) {
|
|
1563
2115
|
const status = STATUS[check.status];
|
|
1564
2116
|
const id = anchor(check);
|
|
1565
2117
|
const isCommand = check.prompt.startsWith("/");
|
|
1566
|
-
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">${
|
|
1567
|
-
return `<section class="check s-${check.status}" id="${id}"><h3>${dot(check.status)}${
|
|
2118
|
+
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>` : "";
|
|
2119
|
+
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>`;
|
|
2120
|
+
}
|
|
2121
|
+
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>`;
|
|
2122
|
+
var LAYER_DOT = { fix: "fail", look: "warn", good: "pass", facts: "info", none: "info" };
|
|
2123
|
+
function layerCount(row22) {
|
|
2124
|
+
const judged = row22.pass + row22.warn + row22.fail;
|
|
2125
|
+
if (judged) return `${row22.pass} of ${judged} good`;
|
|
2126
|
+
return row22.info ? "facts only" : "no check ran";
|
|
2127
|
+
}
|
|
2128
|
+
function layerPanel(checks) {
|
|
2129
|
+
const rows = layerSummary(checks).map((row22) => {
|
|
2130
|
+
const about = LAYERS.find((l) => l.key === row22.layer);
|
|
2131
|
+
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>`;
|
|
2132
|
+
});
|
|
2133
|
+
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>`;
|
|
1568
2134
|
}
|
|
1569
|
-
|
|
1570
|
-
function renderPage3(report2) {
|
|
2135
|
+
function renderPage3(report2, toolsBar = "") {
|
|
1571
2136
|
const { summary } = report2;
|
|
1572
2137
|
const judged = summary.pass + summary.warn + summary.fail;
|
|
1573
2138
|
const bar = ["fail", "warn", "pass"].filter((s) => summary[s] > 0).map((s) => `<i class="b-${s}" style="flex:${summary[s]}"></i>`).join("");
|
|
1574
2139
|
const sorted = [...report2.checks].sort((a, b) => ORDER.indexOf(a.status) - ORDER.indexOf(b.status));
|
|
1575
2140
|
const fixes = sorted.filter(needsFix);
|
|
1576
|
-
const todo = fixes.length ? `<h2>Do these first</h2><ul class="todo">${fixes.map((c) => `<li>${dot(c.status)}<a href="#${anchor(c)}">${
|
|
2141
|
+
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>';
|
|
1577
2142
|
const groups = GROUPS.map((group) => {
|
|
1578
2143
|
const mine = sorted.filter((c) => c.group === group.key);
|
|
1579
2144
|
const rest = mine.filter((c) => !needsFix(c));
|
|
1580
2145
|
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>` : "");
|
|
1581
2146
|
}).join("");
|
|
1582
|
-
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JQ Groundcrew: ${
|
|
2147
|
+
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_CSS3 : ""}</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>
|
|
1583
2148
|
`;
|
|
1584
2149
|
}
|
|
1585
2150
|
function report(project) {
|
|
1586
2151
|
const { facts, filesRead } = gather(project);
|
|
1587
2152
|
const checks = runChecks(facts);
|
|
1588
|
-
return { project: tilde(project), generatedAt: (/* @__PURE__ */ new Date()).toLocaleString("en-US"), filesRead, checks, summary: summarize2(checks) };
|
|
2153
|
+
return { project: tilde(project), generatedAt: (/* @__PURE__ */ new Date()).toLocaleString("en-US"), filesRead, checks, summary: summarize2(checks), layers: layerSummary(checks) };
|
|
1589
2154
|
}
|
|
1590
2155
|
|
|
1591
2156
|
// src/collect.ts
|
|
1592
2157
|
function looksLikeProject(dir) {
|
|
1593
|
-
return [".git", ".claude", "CLAUDE.md"].some((f) =>
|
|
2158
|
+
return [".git", ".claude", "CLAUDE.md"].some((f) => existsSync6(path6.join(dir, f)));
|
|
1594
2159
|
}
|
|
1595
2160
|
function checkSetup(tree) {
|
|
1596
|
-
if (!
|
|
2161
|
+
if (!existsSync6(tree)) return { error: "the folder is gone" };
|
|
1597
2162
|
if (!canRead(tree)) return { error: "the folder cannot be read" };
|
|
1598
2163
|
try {
|
|
1599
2164
|
return { summary: summarize2(runChecks(gather(tree).facts)) };
|
|
@@ -1603,15 +2168,15 @@ function checkSetup(tree) {
|
|
|
1603
2168
|
}
|
|
1604
2169
|
function remoteOf(tree) {
|
|
1605
2170
|
try {
|
|
1606
|
-
let gitDir =
|
|
2171
|
+
let gitDir = path6.join(tree, ".git");
|
|
1607
2172
|
if (statSync3(gitDir).isFile()) {
|
|
1608
|
-
const m = /^gitdir:\s*(.+)$/m.exec(
|
|
2173
|
+
const m = /^gitdir:\s*(.+)$/m.exec(readFileSync5(gitDir, "utf8"));
|
|
1609
2174
|
if (!m) return null;
|
|
1610
|
-
gitDir =
|
|
1611
|
-
const common =
|
|
1612
|
-
if (
|
|
2175
|
+
gitDir = path6.resolve(tree, m[1].trim());
|
|
2176
|
+
const common = path6.join(gitDir, "commondir");
|
|
2177
|
+
if (existsSync6(common)) gitDir = path6.resolve(gitDir, readFileSync5(common, "utf8").trim());
|
|
1613
2178
|
}
|
|
1614
|
-
return originIn(
|
|
2179
|
+
return originIn(readFileSync5(path6.join(gitDir, "config"), "utf8"));
|
|
1615
2180
|
} catch {
|
|
1616
2181
|
return null;
|
|
1617
2182
|
}
|
|
@@ -1631,7 +2196,7 @@ async function collectOverview(opts) {
|
|
|
1631
2196
|
if (opts.mailbox) {
|
|
1632
2197
|
try {
|
|
1633
2198
|
waiting = waitingBoard(readMailbox(opts.mailbox), opts.now ?? Date.now());
|
|
1634
|
-
inboxes = readdirSync3(
|
|
2199
|
+
inboxes = readdirSync3(path6.join(opts.mailbox, "inbox"), { withFileTypes: true }).filter((e) => e.isDirectory() && e.name !== BOARD).map((e) => e.name);
|
|
1635
2200
|
} catch (e) {
|
|
1636
2201
|
mailNote = String(e?.message || e);
|
|
1637
2202
|
}
|
|
@@ -1644,6 +2209,99 @@ async function collectOverview(opts) {
|
|
|
1644
2209
|
return buildOverview({ snapshot: snap, trees, setups, waiting, inboxes, mailbox: opts.mailbox, mailNote, names: opts.names, remotes });
|
|
1645
2210
|
}
|
|
1646
2211
|
|
|
2212
|
+
// src/presence.ts
|
|
2213
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync as readdirSync4, readFileSync as readFileSync6, unlinkSync, writeFileSync as writeFileSync2 } from "fs";
|
|
2214
|
+
import os6 from "os";
|
|
2215
|
+
import path7 from "path";
|
|
2216
|
+
var TOOLS = [
|
|
2217
|
+
{ id: "deck", name: "JQ Deck", what: "sessions, setup and mail on one page", port: 4316, run: "npx @point-seven-studio/jq-deck" },
|
|
2218
|
+
{ id: "agents", name: "JQ Agents", what: "every session, and which wait on a person", port: 4319, run: "npx @point-seven-studio/jq-agents" },
|
|
2219
|
+
{ id: "groundcrew", name: "JQ Groundcrew", what: "the setup check for one project", port: 4317, run: "npx @point-seven-studio/jq-groundcrew" },
|
|
2220
|
+
{ id: "crosstalk", name: "JQ Crosstalk", what: "the mailbox between sessions", port: 4318, run: "npx @point-seven-studio/jq-crosstalk view" }
|
|
2221
|
+
];
|
|
2222
|
+
var esc3 = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
2223
|
+
function runningDir(env = process.env) {
|
|
2224
|
+
return env.JQ_RUNNING_DIR || path7.join(os6.homedir(), ".jq", "running");
|
|
2225
|
+
}
|
|
2226
|
+
var isTool = (id) => TOOLS.some((t) => t.id === id);
|
|
2227
|
+
var validPort = (n) => typeof n === "number" && Number.isInteger(n) && n >= 1 && n <= 65535;
|
|
2228
|
+
function alive(pid) {
|
|
2229
|
+
try {
|
|
2230
|
+
process.kill(pid, 0);
|
|
2231
|
+
return true;
|
|
2232
|
+
} catch (e) {
|
|
2233
|
+
return e?.code === "EPERM";
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
function readRunning(dir = runningDir(), isAlive = alive) {
|
|
2237
|
+
const found = { deck: null, groundcrew: null, crosstalk: null, agents: null };
|
|
2238
|
+
if (!existsSync7(dir)) return found;
|
|
2239
|
+
let files;
|
|
2240
|
+
try {
|
|
2241
|
+
files = readdirSync4(dir).filter((f) => f.endsWith(".json"));
|
|
2242
|
+
} catch {
|
|
2243
|
+
return found;
|
|
2244
|
+
}
|
|
2245
|
+
for (const file of files) {
|
|
2246
|
+
try {
|
|
2247
|
+
const entry = JSON.parse(readFileSync6(path7.join(dir, file), "utf-8"));
|
|
2248
|
+
if (!isTool(entry?.tool) || !validPort(entry.port) || typeof entry.pid !== "number" || !isAlive(entry.pid)) continue;
|
|
2249
|
+
const usual = TOOLS.find((t) => t.id === entry.tool).port;
|
|
2250
|
+
if (found[entry.tool] === null || entry.port === usual) found[entry.tool] = entry.port;
|
|
2251
|
+
} catch {
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
return found;
|
|
2255
|
+
}
|
|
2256
|
+
function readTeamUrl(file = process.env.JQ_CONFIG || path7.join(os6.homedir(), ".jq", "config.json")) {
|
|
2257
|
+
try {
|
|
2258
|
+
const team = JSON.parse(readFileSync6(file, "utf-8"))?.team;
|
|
2259
|
+
if (typeof team !== "string") return null;
|
|
2260
|
+
const url = new URL(team);
|
|
2261
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") return null;
|
|
2262
|
+
if (url.username || url.password) return null;
|
|
2263
|
+
return url.href;
|
|
2264
|
+
} catch {
|
|
2265
|
+
return null;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
var TOOLBAR_CSS4 = `
|
|
2269
|
+
body{padding-bottom:64px}
|
|
2270
|
+
.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)}
|
|
2271
|
+
.jqbar a{color:var(--link,LinkText)}
|
|
2272
|
+
.jqbar .here{font-weight:700}
|
|
2273
|
+
.jqbar details[open]{order:-1;flex-basis:100%}
|
|
2274
|
+
.jqbar summary{cursor:pointer;color:var(--mut,GrayText);list-style:none;display:inline-block;padding:2px 0}
|
|
2275
|
+
.jqbar summary::-webkit-details-marker{display:none}
|
|
2276
|
+
.jqbar summary::after{content:" \u25B8"}
|
|
2277
|
+
.jqbar details[open] summary::after{content:" \u25BE"}
|
|
2278
|
+
.jqbar summary small,.jqbar a small{font-size:11px;font-weight:400}
|
|
2279
|
+
.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)}
|
|
2280
|
+
.jqbar details>div p{margin:0 0 4px}
|
|
2281
|
+
.jqbar code{font:12px ui-monospace,Menlo,monospace;word-break:break-all}
|
|
2282
|
+
.jqbar a:focus-visible,.jqbar summary:focus-visible{outline:2px solid var(--link,LinkText);outline-offset:2px}
|
|
2283
|
+
@media print{.jqbar{display:none}body{padding-bottom:0}}
|
|
2284
|
+
`;
|
|
2285
|
+
var local = (port) => `http://127.0.0.1:${port}`;
|
|
2286
|
+
function toolItem(t, o) {
|
|
2287
|
+
if (o.here === t.id) return `<span class="here" aria-current="page">${esc3(t.name)}</span>`;
|
|
2288
|
+
const start = `<p>To start it: <code>${esc3(t.run)}</code></p>`;
|
|
2289
|
+
if (o.running === null) {
|
|
2290
|
+
return `<details><summary>${esc3(t.name)} <small>on your computer</small></summary><div><p>${esc3(t.name)} shows ${esc3(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>`;
|
|
2291
|
+
}
|
|
2292
|
+
const port = o.running[t.id];
|
|
2293
|
+
if (port !== null) return `<a href="${local(port)}" title="${esc3(t.what)}">${esc3(t.name)}</a>`;
|
|
2294
|
+
return `<details><summary>${esc3(t.name)} <small>not running</small></summary><div><p>${esc3(t.name)} shows ${esc3(t.what)}. It is not running on this machine.</p>${start}<p>Then refresh this page.</p></div></details>`;
|
|
2295
|
+
}
|
|
2296
|
+
function teamItem(o) {
|
|
2297
|
+
if (o.here === "team") return '<span class="here" aria-current="page">Team board</span>';
|
|
2298
|
+
if (o.team) return `<a href="${esc3(o.team)}" title="every machine on the team, on one page">Team board</a>`;
|
|
2299
|
+
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>';
|
|
2300
|
+
}
|
|
2301
|
+
function toolbar(o) {
|
|
2302
|
+
return `<nav class="jqbar" aria-label="JQ tools">${TOOLS.map((t) => toolItem(t, o)).join("")}${teamItem(o)}</nav>`;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
1647
2305
|
// src/page.ts
|
|
1648
2306
|
var TABS = ["overview", "sessions", "setup", "mail"];
|
|
1649
2307
|
var TAB_TITLE = { overview: "Overview", sessions: "Sessions", setup: "Setup", mail: "Mail" };
|
|
@@ -1693,7 +2351,7 @@ function mailTab(o) {
|
|
|
1693
2351
|
}
|
|
1694
2352
|
return '<iframe title="Mailbox" src="/raw/mail"></iframe>';
|
|
1695
2353
|
}
|
|
1696
|
-
function renderShell(o, tab, repo, version) {
|
|
2354
|
+
function renderShell(o, tab, repo, version, bar = "") {
|
|
1697
2355
|
const body = tab === "overview" ? overview(o) : tab === "sessions" ? '<iframe title="Sessions" src="/raw/sessions"></iframe>' : tab === "setup" ? setupTab(o, repo) : mailTab(o);
|
|
1698
2356
|
const needs = o.repos.reduce((n, r) => n + r.needs_you, 0);
|
|
1699
2357
|
const failing = o.repos.filter((r) => r.setup && r.setup.fail > 0).length;
|
|
@@ -1729,7 +2387,7 @@ tbody th{font-weight:600}.path{display:block;font-weight:400;font-size:12px;colo
|
|
|
1729
2387
|
.chip.on{border-color:var(--fg);font-weight:600}
|
|
1730
2388
|
code,pre{font:12px ui-monospace,monospace;background:var(--well);border-radius:4px;padding:1px 4px}pre{padding:10px;overflow-x:auto}
|
|
1731
2389
|
@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}}
|
|
1732
|
-
</style></head><body>
|
|
2390
|
+
${bar ? TOOLBAR_CSS4 : ""}</style></head><body>
|
|
1733
2391
|
<header>
|
|
1734
2392
|
<h1>JQ Deck</h1>
|
|
1735
2393
|
<p class="head">${esc4(o.headline)}</p>
|
|
@@ -1738,11 +2396,11 @@ code,pre{font:12px ui-monospace,monospace;background:var(--well);border-radius:4
|
|
|
1738
2396
|
</header>
|
|
1739
2397
|
<main>${body}</main>
|
|
1740
2398
|
<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>
|
|
1741
|
-
</body></html>`;
|
|
2399
|
+
${bar}</body></html>`;
|
|
1742
2400
|
}
|
|
1743
2401
|
|
|
1744
2402
|
// src/cli.ts
|
|
1745
|
-
import
|
|
2403
|
+
import path8 from "path";
|
|
1746
2404
|
var DEFAULT_PORT = 4316;
|
|
1747
2405
|
var list = (s) => (s || "").split(",").map((x) => x.trim()).filter(Boolean);
|
|
1748
2406
|
function parseArgs(argv, env = {}) {
|
|
@@ -1756,7 +2414,7 @@ function parseArgs(argv, env = {}) {
|
|
|
1756
2414
|
sendQuestions: null,
|
|
1757
2415
|
port: DEFAULT_PORT,
|
|
1758
2416
|
mailbox: null,
|
|
1759
|
-
config: env.JQ_DECK_CONFIG ||
|
|
2417
|
+
config: env.JQ_DECK_CONFIG || defaultConfigFile2(),
|
|
1760
2418
|
questionTrees: env.JQ_AGENTS_QUESTION_TREES ? list(env.JQ_AGENTS_QUESTION_TREES) : null,
|
|
1761
2419
|
probe: false,
|
|
1762
2420
|
sample: true,
|
|
@@ -1803,17 +2461,19 @@ function reportList(a, fromConfig) {
|
|
|
1803
2461
|
function buildContext(a, env, cwd, version) {
|
|
1804
2462
|
const config = loadConfig(expandHome(a.config));
|
|
1805
2463
|
return {
|
|
2464
|
+
runningDir: runningDir(env),
|
|
2465
|
+
configFile: expandHome(a.config),
|
|
1806
2466
|
port: a.port,
|
|
1807
2467
|
version,
|
|
1808
2468
|
probe: a.probe,
|
|
1809
2469
|
sample: a.sample,
|
|
1810
2470
|
report: a.watch ? reportList(a, config.report) : null,
|
|
1811
|
-
sendQuestions: a.watch ? (a.sendQuestions ?? config.sendQuestions ?? []).map((t) =>
|
|
2471
|
+
sendQuestions: a.watch ? (a.sendQuestions ?? config.sendQuestions ?? []).map((t) => path8.resolve(expandHome(t))) : [],
|
|
1812
2472
|
deck: {
|
|
1813
2473
|
mailbox: findMailbox({ flag: a.mailbox, config: config.mailbox, env: env.CROSSTALK_DIR, cwd }),
|
|
1814
2474
|
names: config.names,
|
|
1815
2475
|
// Off unless asked for: question text is a session's own words.
|
|
1816
|
-
questionTrees: (a.questionTrees ?? config.questions ?? []).map((t) =>
|
|
2476
|
+
questionTrees: (a.questionTrees ?? config.questions ?? []).map((t) => path8.resolve(expandHome(t))),
|
|
1817
2477
|
maxAgeDays: a.maxAgeDays,
|
|
1818
2478
|
cwd
|
|
1819
2479
|
}
|
|
@@ -1830,10 +2490,11 @@ async function handle(url, host, ctx, overview2 = collectOverview) {
|
|
|
1830
2490
|
if (u.pathname === "/") {
|
|
1831
2491
|
const asked = u.searchParams.get("tab");
|
|
1832
2492
|
const tab = TABS.includes(asked ?? "") ? asked : "overview";
|
|
1833
|
-
|
|
2493
|
+
const bar = toolbar({ here: "deck", running: readRunning(ctx.runningDir), team: readTeamUrl(ctx.configFile) });
|
|
2494
|
+
return html(renderShell(await overview2(ctx.deck), tab, u.searchParams.get("repo"), ctx.version, bar));
|
|
1834
2495
|
}
|
|
1835
2496
|
if (u.pathname === "/raw/sessions") {
|
|
1836
|
-
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 })));
|
|
2497
|
+
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) })));
|
|
1837
2498
|
}
|
|
1838
2499
|
if (u.pathname === "/raw/setup") {
|
|
1839
2500
|
const row3 = (await overview2(ctx.deck)).repos.find((r) => r.id === u.searchParams.get("repo"));
|
|
@@ -1854,7 +2515,7 @@ export {
|
|
|
1854
2515
|
buildOverview,
|
|
1855
2516
|
checkSetup,
|
|
1856
2517
|
collectOverview,
|
|
1857
|
-
defaultConfigFile,
|
|
2518
|
+
defaultConfigFile2 as defaultConfigFile,
|
|
1858
2519
|
expandHome,
|
|
1859
2520
|
findMailbox,
|
|
1860
2521
|
handle,
|