Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Filter for hooks

Jerome060367faf7af
diff --git a/.claude/hooks/cleanup-worktree.mjs b/.claude/hooks/cleanup-worktree.mjs
index 1a8d6e01..4369903f 100755
--- a/.claude/hooks/cleanup-worktree.mjs
+++ b/.claude/hooks/cleanup-worktree.mjs
@@ -28,7 +28,37 @@ import {
sessionBranch,
} from "./lib/topology.mjs";
-const ctx = createHookContext(readFileSync(0, "utf8"), "cleanup-worktree");
+const raw = readFileSync(0, "utf8");
+const ctx = createHookContext(raw, "cleanup-worktree");
+
+// SubagentStop fires this on EVERY subagent stop here (the matcher doesn't filter
+// and agent_type is empty in the payload). cleanup is the MERGER's post-merge step
+// — skip the worktree sweep when the sibling <agent>.meta.json shows the stopping
+// agent is clearly NOT a merger (developer / reviewer / planner / …). The sweep is
+// idempotent either way; this just avoids running it on every stop. Meta
+// missing/ambiguous → proceed with the normal cleanup.
+{
+ let payload = {};
+ try {
+ payload = JSON.parse(raw);
+ } catch {
+ /* proceed */
+ }
+ const tp = payload.agent_transcript_path || payload.transcript_path || "";
+ const metaPath = tp.replace(/\.jsonl$/, ".meta.json");
+ if (metaPath.endsWith(".meta.json") && existsSync(metaPath)) {
+ try {
+ const at = String(
+ JSON.parse(readFileSync(metaPath, "utf8")).agentType || "",
+ );
+ if (at && at !== "merger") {
+ ctx.accept(`skip — ${at} stop (cleanup runs on merger stops)`);
+ }
+ } catch {
+ // proceed with the normal cleanup
+ }
+ }
+}
if (!existsSync(ctx.worktreeBase)) {
ctx.accept(`${ctx.worktreeBase} not found`);
diff --git a/.claude/hooks/validate-on-stop.mjs b/.claude/hooks/validate-on-stop.mjs
index 8d32728c..613521ba 100755
--- a/.claude/hooks/validate-on-stop.mjs
+++ b/.claude/hooks/validate-on-stop.mjs
@@ -33,6 +33,25 @@ let taskId = ids.map(getFirstTaskId).find(Boolean) || "";
// name carries no TASK suffix, so it's recovered from the dispatch prompt below.
let isSimple = false;
+// Reliable identity at SubagentStop: the sibling <agent>.meta.json (written at
+// spawn, so it exists even when the big transcript JSONL hasn't been flushed yet —
+// a real race here). Its `description` carries the ticket (e.g. "Implement
+// TASK-002: …"). Use it to scope validation to THIS dev's worktree instead of
+// re-validating every session worktree (wt=all) on every stop.
+if (!taskId) {
+ const tp0 = payload.agent_transcript_path || payload.transcript_path || "";
+ const metaPath = tp0.replace(/\.jsonl$/, ".meta.json");
+ if (metaPath.endsWith(".meta.json") && existsSync(metaPath)) {
+ try {
+ const meta = JSON.parse(readFileSync(metaPath, "utf8"));
+ const m = String(meta.description || "").match(/TASK-\d+/);
+ if (m) taskId = m[0];
+ } catch {
+ // best-effort — fall through to transcript recovery below
+ }
+ }
+}
+
// No suffixed agent name in this harness → recover the TASK_ID (or the single-shot
// simple flow) from the dispatch prompt in the transcript, to scope validation to
// this dev's worktree (not wt=all).