@point-seven-studio/jq-deck 0.3.0 → 0.3.2
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 +15 -4
- package/dist/index.mjs +544 -95
- package/dist/jq-deck.mjs +544 -95
- package/dist/types/cli.d.ts +2 -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",
|
|
@@ -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,7 +682,9 @@ async function snapshot(opts = {}) {
|
|
|
515
682
|
bottleneck = null;
|
|
516
683
|
}
|
|
517
684
|
}
|
|
518
|
-
|
|
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;
|
|
519
688
|
}
|
|
520
689
|
var esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
521
690
|
function ago(iso, now) {
|
|
@@ -549,18 +718,44 @@ function groupByTree(rows) {
|
|
|
549
718
|
rows: list2.sort((a, b) => (b.last_activity_at || "").localeCompare(a.last_activity_at || ""))
|
|
550
719
|
})).sort((a, b) => Number(needs(b.rows)) - Number(needs(a.rows)) || latest(b.rows).localeCompare(latest(a.rows)));
|
|
551
720
|
}
|
|
552
|
-
|
|
721
|
+
var hidden = (fields) => Object.entries(fields).map(([name, value]) => `<input type="hidden" name="${name}" value="${esc(value)}">`).join("");
|
|
722
|
+
var form = (m, fields, label) => `<form method="post" action="/turn-check">${hidden({ token: m.token, ...fields })}<button type="submit">${esc(label)}</button></form>`;
|
|
723
|
+
function whyPanel(r, evidence, m) {
|
|
724
|
+
const how = evidence.via === "shell" ? `<code>${esc(evidence.edit)}</code>, a shell command` : `the ${esc(evidence.edit)} tool`;
|
|
725
|
+
const verdict = r.turn_check === "failed" ? "The last check after it failed." : "No check ran after it.";
|
|
726
|
+
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) => {
|
|
727
|
+
const text = ruleText(command);
|
|
728
|
+
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>`;
|
|
729
|
+
}).join("")}</ul>` : "";
|
|
730
|
+
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`) : "";
|
|
731
|
+
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>";
|
|
732
|
+
}
|
|
733
|
+
function sessionRow(r, now, evidence, manage) {
|
|
553
734
|
const attention = deriveAttention(r.state, r.waiting);
|
|
554
735
|
const badge = attention === "needs-you" ? '<span class="b need">waiting on a person</span>' : attention === "abandoned" ? '<span class="b old">asked, then left</span>' : "";
|
|
736
|
+
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
737
|
const res = r.cpu_pct != null || r.rss_mb != null ? `<span class="mut">${r.cpu_pct ?? "?"}% cpu \xB7 ${r.rss_mb ?? "?"} MB</span>` : "";
|
|
556
738
|
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
|
-
|
|
739
|
+
const why = check && evidence && manage ? whyPanel(r, evidence, manage) : "";
|
|
740
|
+
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>`;
|
|
741
|
+
}
|
|
742
|
+
function correctionsPanel(snap, m) {
|
|
743
|
+
const { rules, muted, dismissed } = m.config;
|
|
744
|
+
const items = [
|
|
745
|
+
...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>`),
|
|
746
|
+
...muted.map((tree) => `<li><span>Never labelled: <span class="mut">${esc(tree)}</span></span>${form(m, { action: "unmute", tree }, "Label it again")}</li>`),
|
|
747
|
+
...Object.keys(dismissed).map((session) => {
|
|
748
|
+
const row3 = snap.sessions.find((r) => r.session_id === session);
|
|
749
|
+
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>`;
|
|
750
|
+
})
|
|
751
|
+
];
|
|
752
|
+
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>';
|
|
558
753
|
}
|
|
559
|
-
function renderPage(snap, now = Date.now()) {
|
|
754
|
+
function renderPage(snap, now = Date.now(), manage) {
|
|
560
755
|
const t = totals(snap.sessions);
|
|
561
756
|
const b = snap.bottleneck;
|
|
562
757
|
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("");
|
|
758
|
+
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
759
|
return `<!doctype html>
|
|
565
760
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
566
761
|
<title>JQ Agents</title>
|
|
@@ -575,8 +770,14 @@ h1{font-size:24px;margin:0}h2{font-size:15px;margin:0;padding:10px 12px;word-bre
|
|
|
575
770
|
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;margin:10px 0;overflow:hidden}
|
|
576
771
|
ul{list-style:none;margin:0;padding:0}li{border-top:1px solid var(--line);padding:8px 12px}
|
|
577
772
|
.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)}
|
|
773
|
+
.b{font-size:12px;font-weight:600}.b.need{color:var(--need)}.b.old{color:var(--mut)}.b.bad{color:var(--bad)}
|
|
579
774
|
.chip{border:1px solid var(--line);border-radius:8px;padding:6px 10px;font-size:13px}
|
|
775
|
+
.why{margin:6px 0 2px;font-size:13px}.why summary{cursor:pointer;color:var(--mut);font-size:12px}.why p{margin:6px 0}
|
|
776
|
+
code{font:12px ui-monospace,Menlo,monospace;background:var(--well);border-radius:4px;padding:1px 4px;word-break:break-all}
|
|
777
|
+
.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}
|
|
778
|
+
.acts{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}form{margin:0}
|
|
779
|
+
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}
|
|
780
|
+
button:hover{border-color:var(--mut)}button:focus-visible{outline:2px solid var(--fg);outline-offset:2px}.pad{margin:0;padding:8px 12px}
|
|
580
781
|
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
782
|
</style></head><body><main>
|
|
582
783
|
<h1>JQ Agents</h1>
|
|
@@ -584,19 +785,36 @@ pre{white-space:pre-wrap;word-break:break-word;background:var(--well);margin:8px
|
|
|
584
785
|
<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
786
|
${chip}
|
|
586
787
|
${trees || '<p class="mut">No session has been active in the window read.</p>'}
|
|
788
|
+
${manage ? correctionsPanel(snap, manage) : ""}
|
|
587
789
|
</main></body></html>`;
|
|
588
790
|
}
|
|
791
|
+
function defaultConfigFile() {
|
|
792
|
+
return process.env.JQ_CONFIG || path2.join(os3.homedir(), ".jq", "config.json");
|
|
793
|
+
}
|
|
794
|
+
function readAll(file) {
|
|
795
|
+
if (!existsSync2(file)) return {};
|
|
796
|
+
const parsed = JSON.parse(readFileSync(file, "utf-8"));
|
|
797
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error(`${file} does not hold a JSON object`);
|
|
798
|
+
return parsed;
|
|
799
|
+
}
|
|
800
|
+
function readTurnCheckConfig(file = defaultConfigFile()) {
|
|
801
|
+
try {
|
|
802
|
+
return parseConfig(readAll(file).turnCheck);
|
|
803
|
+
} catch {
|
|
804
|
+
return parseConfig(null);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
589
807
|
|
|
590
808
|
// src/deck.ts
|
|
591
|
-
var expandHome = (p) => p === "~" || p.startsWith("~/") ?
|
|
592
|
-
function
|
|
593
|
-
return
|
|
809
|
+
var expandHome = (p) => p === "~" || p.startsWith("~/") ? path3.join(os4.homedir(), p.slice(1)) : p;
|
|
810
|
+
function defaultConfigFile2() {
|
|
811
|
+
return path3.join(os4.homedir(), ".jq", "config.json");
|
|
594
812
|
}
|
|
595
813
|
function loadConfig(file) {
|
|
596
|
-
if (!
|
|
814
|
+
if (!existsSync3(file)) return {};
|
|
597
815
|
let raw;
|
|
598
816
|
try {
|
|
599
|
-
raw = JSON.parse(
|
|
817
|
+
raw = JSON.parse(readFileSync2(file, "utf8"));
|
|
600
818
|
} catch (e) {
|
|
601
819
|
throw new Error(`cannot read ${file}: ${e?.message || e}`);
|
|
602
820
|
}
|
|
@@ -606,7 +824,7 @@ function loadConfig(file) {
|
|
|
606
824
|
if (typeof r.mailbox === "string") out.mailbox = expandHome(r.mailbox);
|
|
607
825
|
if (r.names && typeof r.names === "object" && !Array.isArray(r.names)) {
|
|
608
826
|
out.names = {};
|
|
609
|
-
for (const [k, v] of Object.entries(r.names)) if (typeof v === "string") out.names[k] =
|
|
827
|
+
for (const [k, v] of Object.entries(r.names)) if (typeof v === "string") out.names[k] = path3.resolve(expandHome(v));
|
|
610
828
|
}
|
|
611
829
|
if (Array.isArray(r.report)) out.report = r.report.filter((q) => typeof q === "string");
|
|
612
830
|
if (Array.isArray(r.sendQuestions)) out.sendQuestions = r.sendQuestions.filter((q) => typeof q === "string").map(expandHome);
|
|
@@ -615,11 +833,11 @@ function loadConfig(file) {
|
|
|
615
833
|
}
|
|
616
834
|
function findMailbox(opts) {
|
|
617
835
|
const named = opts.flag || opts.config || opts.env;
|
|
618
|
-
if (named) return
|
|
619
|
-
let dir =
|
|
836
|
+
if (named) return path3.resolve(expandHome(named));
|
|
837
|
+
let dir = path3.resolve(opts.cwd);
|
|
620
838
|
for (; ; ) {
|
|
621
|
-
if (
|
|
622
|
-
const up =
|
|
839
|
+
if (existsSync3(path3.join(dir, ".crosstalk"))) return dir;
|
|
840
|
+
const up = path3.dirname(dir);
|
|
623
841
|
if (up === dir) return null;
|
|
624
842
|
dir = up;
|
|
625
843
|
}
|
|
@@ -718,8 +936,8 @@ function originIn(config) {
|
|
|
718
936
|
}
|
|
719
937
|
function under(tree, folders) {
|
|
720
938
|
return folders.some((f) => {
|
|
721
|
-
const folder =
|
|
722
|
-
return tree === folder || tree.startsWith(folder +
|
|
939
|
+
const folder = path3.resolve(expandHome(f));
|
|
940
|
+
return tree === folder || tree.startsWith(folder + path3.sep);
|
|
723
941
|
});
|
|
724
942
|
}
|
|
725
943
|
function reportable(r, only) {
|
|
@@ -727,7 +945,7 @@ function reportable(r, only) {
|
|
|
727
945
|
const e = entry.trim();
|
|
728
946
|
if (!e) return false;
|
|
729
947
|
if (e.toLowerCase() === r.name.toLowerCase() || !!r.remote && e.toLowerCase() === r.remote.toLowerCase()) return true;
|
|
730
|
-
return /^[~/.]/.test(e) &&
|
|
948
|
+
return /^[~/.]/.test(e) && path3.resolve(expandHome(e)) === r.tree;
|
|
731
949
|
});
|
|
732
950
|
}
|
|
733
951
|
function teamReport(o, only = null, sendQuestions = []) {
|
|
@@ -751,12 +969,12 @@ function teamReport(o, only = null, sendQuestions = []) {
|
|
|
751
969
|
}
|
|
752
970
|
|
|
753
971
|
// src/collect.ts
|
|
754
|
-
import { existsSync as
|
|
755
|
-
import
|
|
972
|
+
import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "fs";
|
|
973
|
+
import path6 from "path";
|
|
756
974
|
|
|
757
975
|
// ../crosstalk/dist/index.mjs
|
|
758
|
-
import { existsSync as
|
|
759
|
-
import
|
|
976
|
+
import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync3, statSync } from "fs";
|
|
977
|
+
import path4 from "path";
|
|
760
978
|
var BOARD = "board";
|
|
761
979
|
var DAY_MS = 864e5;
|
|
762
980
|
function ageDays(sentAt, now) {
|
|
@@ -988,17 +1206,17 @@ function parseMessage(filename, raw, recipient, acked) {
|
|
|
988
1206
|
};
|
|
989
1207
|
}
|
|
990
1208
|
function names(dir) {
|
|
991
|
-
if (!
|
|
992
|
-
return readdirSync(dir).filter((n) => statSync(
|
|
1209
|
+
if (!existsSync4(dir)) return [];
|
|
1210
|
+
return readdirSync(dir).filter((n) => statSync(path4.join(dir, n)).isDirectory());
|
|
993
1211
|
}
|
|
994
1212
|
function readMailbox(root) {
|
|
995
|
-
if (!
|
|
1213
|
+
if (!existsSync4(path4.join(root, "inbox"))) throw new Error(`not a crosstalk mailbox (no inbox/ folder): ${root}`);
|
|
996
1214
|
const byKey = /* @__PURE__ */ new Map();
|
|
997
1215
|
for (const [base, acked] of [["inbox", false], ["archive", true]]) {
|
|
998
|
-
for (const name of names(
|
|
999
|
-
const dir =
|
|
1216
|
+
for (const name of names(path4.join(root, base))) {
|
|
1217
|
+
const dir = path4.join(root, base, name);
|
|
1000
1218
|
for (const file of readdirSync(dir).filter((f) => f.endsWith(".md"))) {
|
|
1001
|
-
const row22 = parseMessage(file,
|
|
1219
|
+
const row22 = parseMessage(file, readFileSync3(path4.join(dir, file), "utf8"), name, acked);
|
|
1002
1220
|
const key = `${name}/${file}`;
|
|
1003
1221
|
const prev = byKey.get(key);
|
|
1004
1222
|
if (!prev || acked && !prev.acked) byKey.set(key, { id: key, ...row22 });
|
|
@@ -1078,9 +1296,9 @@ function buildReport(root, now = Date.now()) {
|
|
|
1078
1296
|
}
|
|
1079
1297
|
|
|
1080
1298
|
// ../groundcrew/dist/index.mjs
|
|
1081
|
-
import { existsSync as
|
|
1082
|
-
import
|
|
1083
|
-
import
|
|
1299
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
|
|
1300
|
+
import os5 from "os";
|
|
1301
|
+
import path5 from "path";
|
|
1084
1302
|
var DOCS = "https://code.claude.com/docs/en";
|
|
1085
1303
|
var MEMORY_LINE_TARGET = 200;
|
|
1086
1304
|
var MEMORY_LINE_FAIL = 400;
|
|
@@ -1092,6 +1310,136 @@ function deniesSecrets(rule) {
|
|
|
1092
1310
|
function allowsEveryCommand(rule) {
|
|
1093
1311
|
return /^Bash(\(\s*(\*|:\*|\*\*)?\s*\))?$/.test(rule.trim());
|
|
1094
1312
|
}
|
|
1313
|
+
var COMMAND_HEADS = new Set(
|
|
1314
|
+
"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(" ")
|
|
1315
|
+
);
|
|
1316
|
+
var NEVER_WORDS = /\b(never|do not|don['’]t|must not|mustn['’]t|not allowed|forbidden|prohibited)\b/i;
|
|
1317
|
+
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;
|
|
1318
|
+
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;
|
|
1319
|
+
var restrictionKind = (text) => ASK_WORDS.test(text) ? "ask" : NEVER_WORDS.test(text) ? "never" : null;
|
|
1320
|
+
function commandStart(span) {
|
|
1321
|
+
const words = span.trim().replace(/^\$\s+/, "").split(/\s+/);
|
|
1322
|
+
if (!COMMAND_HEADS.has(words[0])) return "";
|
|
1323
|
+
const kept = [words[0]];
|
|
1324
|
+
for (const word of words.slice(1, 3)) {
|
|
1325
|
+
if (!/^(--?[a-z][a-z-]*|[a-z0-9][a-z0-9:_-]*)$/i.test(word)) break;
|
|
1326
|
+
kept.push(word);
|
|
1327
|
+
}
|
|
1328
|
+
return kept.join(" ");
|
|
1329
|
+
}
|
|
1330
|
+
function findRestrictedCommands(text, file) {
|
|
1331
|
+
const found = [];
|
|
1332
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1333
|
+
const add = (kind, command, line) => {
|
|
1334
|
+
if (!command || seen.has(command)) return;
|
|
1335
|
+
seen.add(command);
|
|
1336
|
+
found.push({ file, line, kind, command });
|
|
1337
|
+
};
|
|
1338
|
+
const commandsIn = (part) => {
|
|
1339
|
+
const spans = [...part.matchAll(/`([^`]+)`/g)].flatMap((m) => m[1].split("/").map(commandStart));
|
|
1340
|
+
const bare = [...part.replace(/`[^`]*`/g, " ").matchAll(BARE_COMMANDS)].map((m) => m[1]);
|
|
1341
|
+
return [...spans, ...bare].filter(Boolean);
|
|
1342
|
+
};
|
|
1343
|
+
const readBlock = (block2, line, inherited) => {
|
|
1344
|
+
let matched = false;
|
|
1345
|
+
for (const sentence of block2.split(/(?<=[.!?:])\s+|\s[—–]\s|;\s/)) {
|
|
1346
|
+
const kind = restrictionKind(sentence);
|
|
1347
|
+
if (!kind) continue;
|
|
1348
|
+
matched = true;
|
|
1349
|
+
const at = sentence.search(kind === "ask" ? ASK_WORDS : NEVER_WORDS);
|
|
1350
|
+
for (const command of commandsIn(kind === "ask" ? sentence : sentence.slice(at))) add(kind, command, line);
|
|
1351
|
+
}
|
|
1352
|
+
if (!matched && inherited) for (const command of commandsIn(block2)) add(inherited, command, line);
|
|
1353
|
+
};
|
|
1354
|
+
let headingKind = null;
|
|
1355
|
+
let block = "";
|
|
1356
|
+
let blockLine = 0;
|
|
1357
|
+
let blockIsItem = false;
|
|
1358
|
+
let fenced = false;
|
|
1359
|
+
const flush = () => {
|
|
1360
|
+
if (block) readBlock(block, blockLine, blockIsItem ? headingKind : null);
|
|
1361
|
+
block = "";
|
|
1362
|
+
};
|
|
1363
|
+
text.split("\n").forEach((raw, index) => {
|
|
1364
|
+
if (/^\s*(```|~~~)/.test(raw)) {
|
|
1365
|
+
flush();
|
|
1366
|
+
fenced = !fenced;
|
|
1367
|
+
return;
|
|
1368
|
+
}
|
|
1369
|
+
if (fenced) return;
|
|
1370
|
+
if (/^#{1,6}\s/.test(raw)) {
|
|
1371
|
+
flush();
|
|
1372
|
+
headingKind = restrictionKind(raw);
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
if (!raw.trim()) return flush();
|
|
1376
|
+
const startsItem = /^\s*([-*+]|\d+[.)])\s/.test(raw) || /^\s*\|/.test(raw);
|
|
1377
|
+
if (startsItem) flush();
|
|
1378
|
+
if (!block) {
|
|
1379
|
+
blockLine = index + 1;
|
|
1380
|
+
blockIsItem = startsItem;
|
|
1381
|
+
}
|
|
1382
|
+
block += (block ? " " : "") + raw.trim();
|
|
1383
|
+
});
|
|
1384
|
+
flush();
|
|
1385
|
+
return found;
|
|
1386
|
+
}
|
|
1387
|
+
function ruleCovers(rule, command) {
|
|
1388
|
+
const trimmed = rule.trim();
|
|
1389
|
+
if (allowsEveryCommand(trimmed)) return true;
|
|
1390
|
+
const inner = /^Bash\((.*)\)$/.exec(trimmed)?.[1];
|
|
1391
|
+
if (inner === void 0) return false;
|
|
1392
|
+
const pattern = inner.replace(/:\*$/, " *").trim();
|
|
1393
|
+
const regex = new RegExp("^" + pattern.split("*").map((part) => part.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*") + "$");
|
|
1394
|
+
return regex.test(command) || regex.test(`${command} x`);
|
|
1395
|
+
}
|
|
1396
|
+
var NO_PROMPT_MODES = /* @__PURE__ */ new Set(["bypassPermissions", "auto"]);
|
|
1397
|
+
function proseFindings(facts) {
|
|
1398
|
+
const files = facts.settings;
|
|
1399
|
+
const covers = (rules, command) => rules.some((rule) => ruleCovers(rule, command));
|
|
1400
|
+
const [deny, ask, allow] = [all(files, (f) => f.deny), all(files, (f) => f.ask), all(files, (f) => f.allow)];
|
|
1401
|
+
const noPrompt = files.some((f) => f.defaultMode !== null && NO_PROMPT_MODES.has(f.defaultMode));
|
|
1402
|
+
return (facts.restricted ?? []).map((r) => {
|
|
1403
|
+
const enforced = covers(deny, r.command) || r.kind === "ask" && covers(ask, r.command);
|
|
1404
|
+
const state = enforced ? "enforced" : covers(allow, r.command) || noPrompt ? "allowed" : r.kind === "ask" ? "prompt" : "open";
|
|
1405
|
+
return { ...r, state };
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
var nameFinding = (f) => `"${f.command}" (${f.kind === "ask" ? "ask first" : "never"}, ${f.file} line ${f.line})`;
|
|
1409
|
+
var listFindings = (findings, limit = 4) => findings.slice(0, limit).map(nameFinding).join("; ") + (findings.length > limit ? `; and ${findings.length - limit} more` : "");
|
|
1410
|
+
function proseChecks(facts) {
|
|
1411
|
+
const source = `${DOCS}/permissions.md`;
|
|
1412
|
+
const base = { id: "prose-rules", group: "guardrails", title: "Rules in the instructions have a permission rule behind them", source };
|
|
1413
|
+
const findings = proseFindings(facts);
|
|
1414
|
+
if (!findings.length) {
|
|
1415
|
+
return [
|
|
1416
|
+
{
|
|
1417
|
+
...base,
|
|
1418
|
+
status: "info",
|
|
1419
|
+
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.',
|
|
1420
|
+
fix: ""
|
|
1421
|
+
}
|
|
1422
|
+
];
|
|
1423
|
+
}
|
|
1424
|
+
const allowed = findings.filter((f) => f.state === "allowed");
|
|
1425
|
+
const open2 = findings.filter((f) => f.state === "open");
|
|
1426
|
+
const prompt = findings.filter((f) => f.state === "prompt");
|
|
1427
|
+
const enforced = findings.filter((f) => f.state === "enforced");
|
|
1428
|
+
const parts = [];
|
|
1429
|
+
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)}.`);
|
|
1430
|
+
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)}.`);
|
|
1431
|
+
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)}.`);
|
|
1432
|
+
if (enforced.length) parts.push(`${plural3(enforced.length, "restricted command")} ${enforced.length === 1 ? "has" : "have"} a rule behind ${enforced.length === 1 ? "it" : "them"}.`);
|
|
1433
|
+
const needsLook = allowed.length > 0 || open2.length > 0;
|
|
1434
|
+
return [
|
|
1435
|
+
{
|
|
1436
|
+
...base,
|
|
1437
|
+
status: needsLook ? "warn" : "pass",
|
|
1438
|
+
detail: parts.join(" ") + (needsLook ? " This check reads words, so confirm each line means what it found." : ""),
|
|
1439
|
+
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.` : ""
|
|
1440
|
+
}
|
|
1441
|
+
];
|
|
1442
|
+
}
|
|
1095
1443
|
function memoryChecks(facts) {
|
|
1096
1444
|
const source = `${DOCS}/memory.md`;
|
|
1097
1445
|
if (!facts.memory.length) {
|
|
@@ -1270,13 +1618,13 @@ function guardrailChecks(facts) {
|
|
|
1270
1618
|
}
|
|
1271
1619
|
return checks;
|
|
1272
1620
|
}
|
|
1273
|
-
function
|
|
1621
|
+
function looksLikeACheck2(command) {
|
|
1274
1622
|
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
1623
|
}
|
|
1276
1624
|
function verificationChecks(facts) {
|
|
1277
1625
|
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) =>
|
|
1626
|
+
const allowed = all(files, (f) => f.allow.filter((rule) => /^Bash\(/.test(rule) && looksLikeACheck2(rule)));
|
|
1627
|
+
const hooked = all(files, (f) => f.hookCommands.filter((h) => looksLikeACheck2(h.command)));
|
|
1280
1628
|
const stopEvents = [...new Set(all(files, (f) => f.hookEvents.filter((event) => event === "Stop" || event === "SubagentStop")))].sort();
|
|
1281
1629
|
const unscoped = facts.subagentFiles.filter((agent) => !agent.limitsTools).map((agent) => agent.name);
|
|
1282
1630
|
const checks = [
|
|
@@ -1342,6 +1690,10 @@ function promptFor(check, facts) {
|
|
|
1342
1690
|
const rules = facts.secretFiles.length ? facts.secretFiles.map((file) => `Read(./${file})`).join(", ") : "Read(./.env), Read(./secrets/**)";
|
|
1343
1691
|
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
1692
|
}
|
|
1693
|
+
case "prose-rules": {
|
|
1694
|
+
const findings = proseFindings(facts).filter((f) => f.state === "allowed" || f.state === "open");
|
|
1695
|
+
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.`;
|
|
1696
|
+
}
|
|
1345
1697
|
case "broad-allow":
|
|
1346
1698
|
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
1699
|
case "sandbox":
|
|
@@ -1356,9 +1708,80 @@ function promptFor(check, facts) {
|
|
|
1356
1708
|
return "";
|
|
1357
1709
|
}
|
|
1358
1710
|
}
|
|
1711
|
+
var LAYER_OF = {
|
|
1712
|
+
"memory-exists": "guides",
|
|
1713
|
+
"memory-length": "guides",
|
|
1714
|
+
skills: "guides",
|
|
1715
|
+
"legacy-commands": "guides",
|
|
1716
|
+
hooks: "sensors",
|
|
1717
|
+
"verify-command": "sensors",
|
|
1718
|
+
"stop-check": "loop",
|
|
1719
|
+
"auto-memory-index": "memory",
|
|
1720
|
+
"allow-rules": "permissions",
|
|
1721
|
+
"subagents-and-mcp": "permissions",
|
|
1722
|
+
"deny-secrets": "permissions",
|
|
1723
|
+
"broad-allow": "permissions",
|
|
1724
|
+
"default-mode": "permissions",
|
|
1725
|
+
sandbox: "permissions",
|
|
1726
|
+
reach: "permissions",
|
|
1727
|
+
managed: "permissions",
|
|
1728
|
+
"prose-rules": "permissions",
|
|
1729
|
+
"subagent-scope": "permissions",
|
|
1730
|
+
retention: "observability"
|
|
1731
|
+
};
|
|
1732
|
+
function layerOf(id) {
|
|
1733
|
+
return LAYER_OF[id.split(":")[0]] ?? "guides";
|
|
1734
|
+
}
|
|
1735
|
+
var LAYERS = [
|
|
1736
|
+
{
|
|
1737
|
+
key: "guides",
|
|
1738
|
+
title: "Guides",
|
|
1739
|
+
what: "What steers the agent before it works: instructions, rules and skills.",
|
|
1740
|
+
unchecked: "It does not judge what the instructions say, only how long they are."
|
|
1741
|
+
},
|
|
1742
|
+
{
|
|
1743
|
+
key: "sensors",
|
|
1744
|
+
title: "Sensors",
|
|
1745
|
+
what: "What checks the work: tests, linters and hooks the agent can run.",
|
|
1746
|
+
unchecked: "It does not see your CI, so it cannot tell a check that always fails from one that works."
|
|
1747
|
+
},
|
|
1748
|
+
{
|
|
1749
|
+
key: "loop",
|
|
1750
|
+
title: "Loop",
|
|
1751
|
+
what: "What sends the agent back when the work is not done.",
|
|
1752
|
+
unchecked: "It does not look at retry or spending limits for runs with no person present."
|
|
1753
|
+
},
|
|
1754
|
+
{
|
|
1755
|
+
key: "memory",
|
|
1756
|
+
title: "Memory",
|
|
1757
|
+
what: "What carries over from one session to the next.",
|
|
1758
|
+
unchecked: "It does not look for handoff notes or a record of decisions."
|
|
1759
|
+
},
|
|
1760
|
+
{
|
|
1761
|
+
key: "permissions",
|
|
1762
|
+
title: "Permissions",
|
|
1763
|
+
what: "What the agent may do without asking, and what it may never do.",
|
|
1764
|
+
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."
|
|
1765
|
+
},
|
|
1766
|
+
{
|
|
1767
|
+
key: "observability",
|
|
1768
|
+
title: "Observability",
|
|
1769
|
+
what: "What a person can see of what the agent did.",
|
|
1770
|
+
unchecked: "It does not look for cost tracking or alerts."
|
|
1771
|
+
}
|
|
1772
|
+
];
|
|
1359
1773
|
function runChecks(facts) {
|
|
1360
|
-
const checks = [...memoryChecks(facts), ...automationChecks(facts), ...guardrailChecks(facts), ...verificationChecks(facts)];
|
|
1361
|
-
return checks.map((check) => ({ ...check, prompt: promptFor(check, facts) }));
|
|
1774
|
+
const checks = [...memoryChecks(facts), ...automationChecks(facts), ...guardrailChecks(facts), ...proseChecks(facts), ...verificationChecks(facts)];
|
|
1775
|
+
return checks.map((check) => ({ ...check, layer: layerOf(check.id), prompt: promptFor(check, facts) }));
|
|
1776
|
+
}
|
|
1777
|
+
function layerSummary(checks) {
|
|
1778
|
+
return LAYERS.map(({ key, title }) => {
|
|
1779
|
+
const mine = checks.filter((c) => c.layer === key);
|
|
1780
|
+
const count = (status) => mine.filter((c) => c.status === status).length;
|
|
1781
|
+
const [pass, warn, fail, info] = [count("pass"), count("warn"), count("fail"), count("info")];
|
|
1782
|
+
const state = fail ? "fix" : warn ? "look" : pass ? "good" : info ? "facts" : "none";
|
|
1783
|
+
return { layer: key, title, pass, warn, fail, info, state };
|
|
1784
|
+
});
|
|
1362
1785
|
}
|
|
1363
1786
|
function summarize2(checks) {
|
|
1364
1787
|
const count = (status) => checks.filter((c) => c.status === status).length;
|
|
@@ -1370,8 +1793,8 @@ var SECRET_NAMES = /^(\.env(\..+)?|secrets?(\..+)?|credentials(\..+)?|.*\.pem|id
|
|
|
1370
1793
|
var NOT_SECRET = /\.(example|sample|template)$/i;
|
|
1371
1794
|
var SECRET_DEPTH = 3;
|
|
1372
1795
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "vendor", "coverage"]);
|
|
1373
|
-
var home = () =>
|
|
1374
|
-
var configDir = () => process.env.CLAUDE_CONFIG_DIR ||
|
|
1796
|
+
var home = () => os5.homedir();
|
|
1797
|
+
var configDir = () => process.env.CLAUDE_CONFIG_DIR || path5.join(home(), ".claude");
|
|
1375
1798
|
var tilde = (file) => file.startsWith(home()) ? `~${file.slice(home().length)}` : file;
|
|
1376
1799
|
function canRead(project) {
|
|
1377
1800
|
try {
|
|
@@ -1383,23 +1806,29 @@ function canRead(project) {
|
|
|
1383
1806
|
}
|
|
1384
1807
|
function readJson(file) {
|
|
1385
1808
|
try {
|
|
1386
|
-
return JSON.parse(
|
|
1809
|
+
return JSON.parse(readFileSync4(file, "utf-8"));
|
|
1387
1810
|
} catch {
|
|
1388
1811
|
return null;
|
|
1389
1812
|
}
|
|
1390
1813
|
}
|
|
1391
1814
|
function countFiles(dir, test) {
|
|
1392
|
-
if (!
|
|
1815
|
+
if (!existsSync5(dir)) return 0;
|
|
1393
1816
|
let total = 0;
|
|
1394
1817
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1395
|
-
if (entry.isDirectory()) total += countFiles(
|
|
1818
|
+
if (entry.isDirectory()) total += countFiles(path5.join(dir, entry.name), test);
|
|
1396
1819
|
else if (test(entry.name)) total += 1;
|
|
1397
1820
|
}
|
|
1398
1821
|
return total;
|
|
1399
1822
|
}
|
|
1823
|
+
function markdownFiles(dir) {
|
|
1824
|
+
if (!existsSync5(dir)) return [];
|
|
1825
|
+
return readdirSync2(dir, { withFileTypes: true }).flatMap(
|
|
1826
|
+
(entry) => entry.isDirectory() ? markdownFiles(path5.join(dir, entry.name)) : entry.name.endsWith(".md") ? [path5.join(dir, entry.name)] : []
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1400
1829
|
function findSecretFiles(root, relative, depth) {
|
|
1401
|
-
const dir =
|
|
1402
|
-
if (depth > SECRET_DEPTH || !
|
|
1830
|
+
const dir = path5.join(root, relative);
|
|
1831
|
+
if (depth > SECRET_DEPTH || !existsSync5(dir)) return [];
|
|
1403
1832
|
const found = [];
|
|
1404
1833
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1405
1834
|
const here = relative ? `${relative}/${entry.name}` : entry.name;
|
|
@@ -1423,13 +1852,13 @@ function hookCommands(hooks) {
|
|
|
1423
1852
|
return found;
|
|
1424
1853
|
}
|
|
1425
1854
|
function subagentFiles(dir) {
|
|
1426
|
-
if (!
|
|
1855
|
+
if (!existsSync5(dir)) return [];
|
|
1427
1856
|
const found = [];
|
|
1428
1857
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1429
|
-
const file =
|
|
1858
|
+
const file = path5.join(dir, entry.name);
|
|
1430
1859
|
if (entry.isDirectory()) found.push(...subagentFiles(file));
|
|
1431
1860
|
else if (entry.name.endsWith(".md")) {
|
|
1432
|
-
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(
|
|
1861
|
+
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(readFileSync4(file, "utf-8"))?.[1] ?? "";
|
|
1433
1862
|
found.push({ name: entry.name.replace(/\.md$/, ""), limitsTools: /^(tools|disallowedTools)\s*:/m.test(frontmatter) });
|
|
1434
1863
|
}
|
|
1435
1864
|
}
|
|
@@ -1439,20 +1868,25 @@ var isMarkdown = (name) => name.endsWith(".md");
|
|
|
1439
1868
|
var strings = (value) => Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
1440
1869
|
function gather(project) {
|
|
1441
1870
|
const filesRead = [];
|
|
1442
|
-
const label = (file) => file.startsWith(project +
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1871
|
+
const label = (file) => file.startsWith(project + path5.sep) ? file.slice(project.length + 1) : tilde(file);
|
|
1872
|
+
const restricted = [];
|
|
1873
|
+
const memoryFile = (file, instructions = true) => {
|
|
1874
|
+
if (!existsSync5(file) || !statSync2(file).isFile()) return null;
|
|
1875
|
+
const text = readFileSync4(file, "utf-8");
|
|
1446
1876
|
filesRead.push(label(file));
|
|
1877
|
+
if (instructions) restricted.push(...findRestrictedCommands(text, label(file)));
|
|
1447
1878
|
return { label: label(file), lines: text.split("\n").length - (text.endsWith("\n") ? 1 : 0), bytes: Buffer.byteLength(text) };
|
|
1448
1879
|
};
|
|
1449
1880
|
const memory = [
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
].map(memoryFile).filter((file) => file !== null);
|
|
1881
|
+
path5.join(project, "CLAUDE.md"),
|
|
1882
|
+
path5.join(project, ".claude", "CLAUDE.md"),
|
|
1883
|
+
path5.join(project, "CLAUDE.local.md"),
|
|
1884
|
+
path5.join(project, "AGENTS.md"),
|
|
1885
|
+
path5.join(configDir(), "CLAUDE.md")
|
|
1886
|
+
].map((file) => memoryFile(file)).filter((file) => file !== null);
|
|
1887
|
+
for (const dir of [path5.join(project, ".claude", "rules"), path5.join(configDir(), "rules")]) {
|
|
1888
|
+
for (const file of markdownFiles(dir)) restricted.push(...findRestrictedCommands(readFileSync4(file, "utf-8"), label(file)));
|
|
1889
|
+
}
|
|
1456
1890
|
const settingsFile = (scope, file) => {
|
|
1457
1891
|
const json = readJson(file);
|
|
1458
1892
|
if (!json) return null;
|
|
@@ -1476,12 +1910,12 @@ function gather(project) {
|
|
|
1476
1910
|
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
1911
|
const settings = [
|
|
1478
1912
|
settingsFile("managed", managed),
|
|
1479
|
-
settingsFile("local",
|
|
1480
|
-
settingsFile("project",
|
|
1481
|
-
settingsFile("user",
|
|
1913
|
+
settingsFile("local", path5.join(project, ".claude", "settings.local.json")),
|
|
1914
|
+
settingsFile("project", path5.join(project, ".claude", "settings.json")),
|
|
1915
|
+
settingsFile("user", path5.join(configDir(), "settings.json"))
|
|
1482
1916
|
].filter((file) => file !== null);
|
|
1483
|
-
const projectMcp = readJson(
|
|
1484
|
-
const userConfig = readJson(
|
|
1917
|
+
const projectMcp = readJson(path5.join(project, ".mcp.json"));
|
|
1918
|
+
const userConfig = readJson(path5.join(home(), ".claude.json"));
|
|
1485
1919
|
const userServers = Object.keys(userConfig?.mcpServers || {}).length + Object.keys(userConfig?.projects?.[project]?.mcpServers || {}).length;
|
|
1486
1920
|
if (projectMcp) filesRead.push(".mcp.json");
|
|
1487
1921
|
if (userConfig) filesRead.push("~/.claude.json (MCP server names only)");
|
|
@@ -1491,21 +1925,22 @@ function gather(project) {
|
|
|
1491
1925
|
facts: {
|
|
1492
1926
|
platform: process.platform,
|
|
1493
1927
|
memory,
|
|
1494
|
-
ruleFiles: countFiles(
|
|
1495
|
-
autoMemoryIndex: memoryFile(
|
|
1928
|
+
ruleFiles: countFiles(path5.join(project, ".claude", "rules"), isMarkdown) + countFiles(path5.join(configDir(), "rules"), isMarkdown),
|
|
1929
|
+
autoMemoryIndex: memoryFile(path5.join(configDir(), "projects", encoded, "memory", "MEMORY.md"), false),
|
|
1496
1930
|
settings,
|
|
1497
1931
|
skills: {
|
|
1498
|
-
project: countFiles(
|
|
1499
|
-
user: countFiles(
|
|
1932
|
+
project: countFiles(path5.join(project, ".claude", "skills"), (name) => name === "SKILL.md"),
|
|
1933
|
+
user: countFiles(path5.join(configDir(), "skills"), (name) => name === "SKILL.md")
|
|
1500
1934
|
},
|
|
1501
1935
|
subagents: {
|
|
1502
|
-
project: countFiles(
|
|
1503
|
-
user: countFiles(
|
|
1936
|
+
project: countFiles(path5.join(project, ".claude", "agents"), isMarkdown),
|
|
1937
|
+
user: countFiles(path5.join(configDir(), "agents"), isMarkdown)
|
|
1504
1938
|
},
|
|
1505
|
-
subagentFiles: [...subagentFiles(
|
|
1506
|
-
legacyCommands: countFiles(
|
|
1939
|
+
subagentFiles: [...subagentFiles(path5.join(project, ".claude", "agents")), ...subagentFiles(path5.join(configDir(), "agents"))],
|
|
1940
|
+
legacyCommands: countFiles(path5.join(project, ".claude", "commands"), isMarkdown),
|
|
1507
1941
|
mcpServers: { project: Object.keys(projectMcp?.mcpServers || {}).length, user: userServers },
|
|
1508
|
-
secretFiles: findSecretFiles(project, "", 0).sort()
|
|
1942
|
+
secretFiles: findSecretFiles(project, "", 0).sort(),
|
|
1943
|
+
restricted
|
|
1509
1944
|
}
|
|
1510
1945
|
};
|
|
1511
1946
|
}
|
|
@@ -1567,6 +2002,19 @@ function fixCard(check) {
|
|
|
1567
2002
|
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>`;
|
|
1568
2003
|
}
|
|
1569
2004
|
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>`;
|
|
2005
|
+
var LAYER_DOT = { fix: "fail", look: "warn", good: "pass", facts: "info", none: "info" };
|
|
2006
|
+
function layerCount(row22) {
|
|
2007
|
+
const judged = row22.pass + row22.warn + row22.fail;
|
|
2008
|
+
if (judged) return `${row22.pass} of ${judged} good`;
|
|
2009
|
+
return row22.info ? "facts only" : "no check ran";
|
|
2010
|
+
}
|
|
2011
|
+
function layerPanel(checks) {
|
|
2012
|
+
const rows = layerSummary(checks).map((row22) => {
|
|
2013
|
+
const about = LAYERS.find((l) => l.key === row22.layer);
|
|
2014
|
+
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>`;
|
|
2015
|
+
});
|
|
2016
|
+
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>`;
|
|
2017
|
+
}
|
|
1570
2018
|
function renderPage3(report2) {
|
|
1571
2019
|
const { summary } = report2;
|
|
1572
2020
|
const judged = summary.pass + summary.warn + summary.fail;
|
|
@@ -1579,21 +2027,21 @@ function renderPage3(report2) {
|
|
|
1579
2027
|
const rest = mine.filter((c) => !needsFix(c));
|
|
1580
2028
|
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
2029
|
}).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: ${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 + 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 counted
|
|
2030
|
+
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>
|
|
1583
2031
|
`;
|
|
1584
2032
|
}
|
|
1585
2033
|
function report(project) {
|
|
1586
2034
|
const { facts, filesRead } = gather(project);
|
|
1587
2035
|
const checks = runChecks(facts);
|
|
1588
|
-
return { project: tilde(project), generatedAt: (/* @__PURE__ */ new Date()).toLocaleString("en-US"), filesRead, checks, summary: summarize2(checks) };
|
|
2036
|
+
return { project: tilde(project), generatedAt: (/* @__PURE__ */ new Date()).toLocaleString("en-US"), filesRead, checks, summary: summarize2(checks), layers: layerSummary(checks) };
|
|
1589
2037
|
}
|
|
1590
2038
|
|
|
1591
2039
|
// src/collect.ts
|
|
1592
2040
|
function looksLikeProject(dir) {
|
|
1593
|
-
return [".git", ".claude", "CLAUDE.md"].some((f) =>
|
|
2041
|
+
return [".git", ".claude", "CLAUDE.md"].some((f) => existsSync6(path6.join(dir, f)));
|
|
1594
2042
|
}
|
|
1595
2043
|
function checkSetup(tree) {
|
|
1596
|
-
if (!
|
|
2044
|
+
if (!existsSync6(tree)) return { error: "the folder is gone" };
|
|
1597
2045
|
if (!canRead(tree)) return { error: "the folder cannot be read" };
|
|
1598
2046
|
try {
|
|
1599
2047
|
return { summary: summarize2(runChecks(gather(tree).facts)) };
|
|
@@ -1603,15 +2051,15 @@ function checkSetup(tree) {
|
|
|
1603
2051
|
}
|
|
1604
2052
|
function remoteOf(tree) {
|
|
1605
2053
|
try {
|
|
1606
|
-
let gitDir =
|
|
2054
|
+
let gitDir = path6.join(tree, ".git");
|
|
1607
2055
|
if (statSync3(gitDir).isFile()) {
|
|
1608
|
-
const m = /^gitdir:\s*(.+)$/m.exec(
|
|
2056
|
+
const m = /^gitdir:\s*(.+)$/m.exec(readFileSync5(gitDir, "utf8"));
|
|
1609
2057
|
if (!m) return null;
|
|
1610
|
-
gitDir =
|
|
1611
|
-
const common =
|
|
1612
|
-
if (
|
|
2058
|
+
gitDir = path6.resolve(tree, m[1].trim());
|
|
2059
|
+
const common = path6.join(gitDir, "commondir");
|
|
2060
|
+
if (existsSync6(common)) gitDir = path6.resolve(gitDir, readFileSync5(common, "utf8").trim());
|
|
1613
2061
|
}
|
|
1614
|
-
return originIn(
|
|
2062
|
+
return originIn(readFileSync5(path6.join(gitDir, "config"), "utf8"));
|
|
1615
2063
|
} catch {
|
|
1616
2064
|
return null;
|
|
1617
2065
|
}
|
|
@@ -1631,7 +2079,7 @@ async function collectOverview(opts) {
|
|
|
1631
2079
|
if (opts.mailbox) {
|
|
1632
2080
|
try {
|
|
1633
2081
|
waiting = waitingBoard(readMailbox(opts.mailbox), opts.now ?? Date.now());
|
|
1634
|
-
inboxes = readdirSync3(
|
|
2082
|
+
inboxes = readdirSync3(path6.join(opts.mailbox, "inbox"), { withFileTypes: true }).filter((e) => e.isDirectory() && e.name !== BOARD).map((e) => e.name);
|
|
1635
2083
|
} catch (e) {
|
|
1636
2084
|
mailNote = String(e?.message || e);
|
|
1637
2085
|
}
|
|
@@ -1742,7 +2190,7 @@ code,pre{font:12px ui-monospace,monospace;background:var(--well);border-radius:4
|
|
|
1742
2190
|
}
|
|
1743
2191
|
|
|
1744
2192
|
// src/cli.ts
|
|
1745
|
-
import
|
|
2193
|
+
import path7 from "path";
|
|
1746
2194
|
var DEFAULT_PORT = 4316;
|
|
1747
2195
|
var list = (s) => (s || "").split(",").map((x) => x.trim()).filter(Boolean);
|
|
1748
2196
|
function parseArgs(argv, env = {}) {
|
|
@@ -1756,7 +2204,7 @@ function parseArgs(argv, env = {}) {
|
|
|
1756
2204
|
sendQuestions: null,
|
|
1757
2205
|
port: DEFAULT_PORT,
|
|
1758
2206
|
mailbox: null,
|
|
1759
|
-
config: env.JQ_DECK_CONFIG ||
|
|
2207
|
+
config: env.JQ_DECK_CONFIG || defaultConfigFile2(),
|
|
1760
2208
|
questionTrees: env.JQ_AGENTS_QUESTION_TREES ? list(env.JQ_AGENTS_QUESTION_TREES) : null,
|
|
1761
2209
|
probe: false,
|
|
1762
2210
|
sample: true,
|
|
@@ -1803,17 +2251,18 @@ function reportList(a, fromConfig) {
|
|
|
1803
2251
|
function buildContext(a, env, cwd, version) {
|
|
1804
2252
|
const config = loadConfig(expandHome(a.config));
|
|
1805
2253
|
return {
|
|
2254
|
+
configFile: expandHome(a.config),
|
|
1806
2255
|
port: a.port,
|
|
1807
2256
|
version,
|
|
1808
2257
|
probe: a.probe,
|
|
1809
2258
|
sample: a.sample,
|
|
1810
2259
|
report: a.watch ? reportList(a, config.report) : null,
|
|
1811
|
-
sendQuestions: a.watch ? (a.sendQuestions ?? config.sendQuestions ?? []).map((t) =>
|
|
2260
|
+
sendQuestions: a.watch ? (a.sendQuestions ?? config.sendQuestions ?? []).map((t) => path7.resolve(expandHome(t))) : [],
|
|
1812
2261
|
deck: {
|
|
1813
2262
|
mailbox: findMailbox({ flag: a.mailbox, config: config.mailbox, env: env.CROSSTALK_DIR, cwd }),
|
|
1814
2263
|
names: config.names,
|
|
1815
2264
|
// Off unless asked for: question text is a session's own words.
|
|
1816
|
-
questionTrees: (a.questionTrees ?? config.questions ?? []).map((t) =>
|
|
2265
|
+
questionTrees: (a.questionTrees ?? config.questions ?? []).map((t) => path7.resolve(expandHome(t))),
|
|
1817
2266
|
maxAgeDays: a.maxAgeDays,
|
|
1818
2267
|
cwd
|
|
1819
2268
|
}
|
|
@@ -1833,7 +2282,7 @@ async function handle(url, host, ctx, overview2 = collectOverview) {
|
|
|
1833
2282
|
return html(renderShell(await overview2(ctx.deck), tab, u.searchParams.get("repo"), ctx.version));
|
|
1834
2283
|
}
|
|
1835
2284
|
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 })));
|
|
2285
|
+
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
2286
|
}
|
|
1838
2287
|
if (u.pathname === "/raw/setup") {
|
|
1839
2288
|
const row3 = (await overview2(ctx.deck)).repos.find((r) => r.id === u.searchParams.get("repo"));
|
|
@@ -1854,7 +2303,7 @@ export {
|
|
|
1854
2303
|
buildOverview,
|
|
1855
2304
|
checkSetup,
|
|
1856
2305
|
collectOverview,
|
|
1857
|
-
defaultConfigFile,
|
|
2306
|
+
defaultConfigFile2 as defaultConfigFile,
|
|
1858
2307
|
expandHome,
|
|
1859
2308
|
findMailbox,
|
|
1860
2309
|
handle,
|