Skip to content

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

Fix regressions from moving harness. Chat-orchestrator : spawning documentator and asking question Developer : missing skill branding Bash-guard : for developer not writting migration with bash

Jerome4e7aff6fbf72
diff --git a/.claude/agents/chat-orchestrator.md b/.claude/agents/chat-orchestrator.md
index f7809965..febea0a0 100644
--- a/.claude/agents/chat-orchestrator.md
+++ b/.claude/agents/chat-orchestrator.md
@@ -494,9 +494,10 @@ never triggers a forward migration, so POST-DEV is always skipped:
3. Build the reply in user's language, plain words — e.g. *"Done — take a look in the demo."*
4. Branch on the detection output:
- Empty → send the reply, enter STATE DONE.
- - Non-empty (one or more schema-relevant file paths) → append the PD-ASK satisfaction
- question to the reply (do NOT send a separate PD-ASK turn — the question is already
- embedded here), end this turn, and enter STATE PD-RESPOND.
+ - Non-empty (one or more schema-relevant file paths) → on a new line after the reply,
+ append the `%%ASK_SATISFACTION%%` marker (exact format and HARD REQUIREMENT per
+ STATE PD-ASK) — do NOT send a separate PD-ASK turn, and do NOT ask in plain prose.
+ End this turn and enter STATE PD-RESPOND.
From PD-RESPOND onward, the existing POST-DEV state machine (PD-MIG-DEV →
PD-MIG-REVIEW → PD-MIG-MERGE → PD-DEPLOY → PD-LIVE-ASK → PD-LIVE-SWITCH → PD-DONE)
@@ -717,8 +718,8 @@ tickets on `session/<SESSION_SHORT_ID>`; nothing has reached `main` yet.
- **Every ticket FAILED** (nothing merged) → skip promotion. SETUP path → STATE
SETUP-DONE; COMPLEX path → reply per-ticket and STATE DONE.
-Session-end memory synthesis (documentator Mode 2) is spawned automatically by
-chat-service after your final turn — do not dispatch it yourself.
+Business-knowledge capture (documentator Mode 2) is spawned at STATE PD-RESPOND when the user confirms satisfaction
+(see that state). It runs in the background and its output never shows in the chat.
#### Interruption & recovery
@@ -791,19 +792,56 @@ conditional on the session-branch diff touching schema-relevant files). It does
**SIMPLE flows skip this state** — the satisfaction question is embedded in the S-DONE reply and the orchestrator enters STATE PD-RESPOND directly on the next user turn.
-Always ask, in the user's language, plain words only — never mention database,
-migration, deploy, Supabase:
+Write ONE short line recapping **only what was built** (past tense, plain words,
+in the user's language, no tech terms — never mention database, migration, deploy,
+Supabase). Do NOT ask anything in prose. Then, on a **new line**, append the
+satisfaction marker, all four fields translated into the user's language:
-> *"Here are your changes — does everything look the way you want, or should I adjust something?"*
+```
+%%ASK_SATISFACTION|<header>|<body_text>|<yes_label>|<no_label>%%
+```
+
+- `header`: very short status label (≤ 30 chars), e.g. "Preview ready".
+- `body_text`: one sentence, plain words, asking whether they're happy (the demo
+ preview isn't saved to their data yet).
+- `yes_label`: short confirm label, e.g. "Yes, save the changes".
+- `no_label`: short decline label, e.g. "No, I want to adjust something".
+
+Good example (recap states the feature, widget asks to save — no overlap):
+
+```
+I built the equipment, rentals and maintenance sections you asked for.
+%%ASK_SATISFACTION|Preview ready|Everything is visible in the demo but hasn't been saved to your database yet. Happy with the result?|Yes, save the changes|No, I want to adjust something%%
+```
**End this turn.** → STATE PD-RESPOND on the next user turn.
### STATE PD-RESPOND
+The user's reply is either the satisfaction widget **button label** (the full text,
+e.g. "Yes, save the changes" / "No, I want to adjust something") or free text typed
+directly — treat the button label as the corresponding answer.
+
+**On satisfaction — capture business knowledge (once, fire-and-forget):** when the
+user confirms the work is good, dispatch ONE Mode-2 documentator in the background
+(no `team_name`, no worktree; do NOT wait for it — it runs while migration/wrap-up
+proceeds and its output never shows in the chat):
+
+```
+Agent({
+ subagent_type: "documentator",
+ description: "Capture business knowledge",
+ prompt: "ROLE: documentator (Mode 2)\nSESSION_LOG: <session_dir>/log.jsonl\nSESSION_DIFF_BASE: origin/main\nreason: business-knowledge\n\nFollow your Mode 2 instructions: read the session diff vs origin/main and append business-knowledge bullets to $CLAUDE_PROJECT_DIR/MEMORY.md (silently do nothing if there is nothing concrete to capture).",
+ run_in_background: true
+})
+```
+
+Then proceed per the table:
+
| Meaning | Next |
|---|---|
-| Wants to adjust / new request | Re-enter CLASSIFICATION (new request, accumulates on session/<SESSION_SHORT_ID>); ask PD-ASK again after. |
-| Satisfied (yes, perfect, looks good…) | Run `Bash("pending-deploys --app $CLAUDE_PROJECT_DIR --session <SESSION_SHORT_ID>")`. Empty output → reply "Great, everything's set." and STATE DONE. Non-empty → emit "Saving your changes — this can take a moment." and enter STATE PD-MIG-DEV. |
+| Satisfied (button label or free text: "yes", "perfect", "looks good"…) | (Dispatch the Mode-2 documentator above first.) Run `Bash("pending-deploys --app $CLAUDE_PROJECT_DIR --session <SESSION_SHORT_ID>")`. Empty output → reply "Great, everything's set." and STATE DONE. Non-empty → emit "Saving your changes — this can take a moment." and enter STATE PD-MIG-DEV. |
+| Wants to adjust / new request (button label or free text: "no", "change something"…) | Re-enter CLASSIFICATION (new request, accumulates on session/<SESSION_SHORT_ID>); ask PD-ASK again after. |
| Ambiguous | Re-ask the open question once; stay in PD-RESPOND. |
### STATE PD-MIG-DEV — write the migration
@@ -849,9 +887,15 @@ One line: *"Applying your changes — this can take a moment on first run."*
### STATE PD-LIVE-ASK — offer to switch the app to real data
-Demo mode only. Reply in the user's language, plain words:
+Demo mode only. Write a one-line confirmation that the data is saved, then on a new
+line append the satisfaction marker (same format and HARD REQUIREMENT as STATE PD-ASK)
+offering the switch, translated into the user's language:
+
+```
+%%ASK_SATISFACTION|Changes saved|Your changes have been saved. Want to switch the app to your real data now, or keep using sample data?|Yes, switch to real data|No, keep sample data%%
+```
-> *"Your data is saved. Want to switch the app over to your real data now? You can keep using sample data otherwise."*
+Do NOT ask in plain prose — the widget IS the question. The marker is required.
**End this turn.**
@@ -899,7 +943,7 @@ Already wraps every successful PD branch with the user-facing reply. After reply
- ❌ Dispatch more than 5 tickets in a single STATE B pass — cap at 5, loop through the remainder.
- ❌ Write or Edit any file **except** `$CLAUDE_PROJECT_DIR/docs/project-context.json` during SETUP-INTERVIEW. The `Write` / `Edit` tools are only for that one file in that one state.
- ❌ Dispatch `project-manager` agent during SETUP-INTERVIEW — you conduct the interview directly using the `setup-interview` skill.
-- ❌ `Write` / `Edit` `$CLAUDE_PROJECT_DIR/MEMORY.md` or any `$CLAUDE_PROJECT_DIR/adr/*` yourself. Documentator owns MEMORY.md (auto-spawned by chat-service at session end); developer owns adr/ via worktree merges as part of a COMPLEX wave. Read for context, never write.
+- ❌ `Write` / `Edit` `$CLAUDE_PROJECT_DIR/MEMORY.md` or any `$CLAUDE_PROJECT_DIR/adr/*` yourself. Documentator owns MEMORY.md (dispatched by the orchestrator at STATE PD-RESPOND on user satisfaction); developer owns adr/ via worktree merges as part of a COMPLEX wave. Read for context, never write.
---
diff --git a/.claude/agents/developer.md b/.claude/agents/developer.md
index d37a04d5..23032cd0 100644
--- a/.claude/agents/developer.md
+++ b/.claude/agents/developer.md
@@ -100,6 +100,7 @@ Domain skills — load on demand with `Skill({skill: "..."})` when your task nee
- `Skill({skill: "playwright-testing"})` — Playwright API and selector patterns
- `Skill({skill: "shadcn-customization"})` — CSS variables, OKLCH colors, theme presets (load if `"visual_customization": true`)
- `Skill({skill: "delete-initial-resource"})` — remove an initial CRM resource (contacts, companies, deals, tags, tasks) and every reference to it
+- `Skill({skill: "update-branding"})` — change the CRM logo and/or title
---
diff --git a/.claude/hooks/bash-guard.mjs b/.claude/hooks/bash-guard.mjs
index f9c868d5..df2ab718 100755
--- a/.claude/hooks/bash-guard.mjs
+++ b/.claude/hooks/bash-guard.mjs
@@ -101,4 +101,37 @@ if (violation) {
});
}
+// File-write rules — gated subagents only: code-writing agents must use the
+// Write/Edit tools, never Bash redirection/in-place edits. Bash writes bypass the
+// Write|Edit-only block-migration-writes guard (a developer could otherwise write a migration in
+// bash).
+const writesRedirect = (c) =>
+ /(^|[^0-9&])>>?\s*(\/|\.\.?\/|~\/|[a-zA-Z0-9._-]+\/|[a-zA-Z0-9._-]+\.[a-zA-Z0-9]+)/.test(
+ c,
+ ) && !/>>?\s*(\/dev\/null|\/chat-service\/logs\/)/.test(c);
+const writesSedInPlace = (c) => /sed\s+(-[a-zA-Z]*i\b|--in-place)/.test(c);
+const writesAwkInPlace = (c) => /awk\s+-i\s+inplace/.test(c);
+const writesTee = (c) =>
+ /\|\s*tee\s+[^-]/.test(c) && !/\|\s*tee\s+(-a\s+)?\/dev\/null/.test(c);
+const writesScript = (c) =>
+ /(node|python3?)\s+-[ecp].*(writeFileSync|writeFile|write_text|os\.write|fs\.write)/.test(
+ c,
+ );
+
+const FILE_WRITE_RULES = [
+ [writesRedirect, "bash redirection to a file (> or >>)"],
+ [writesSedInPlace, "sed -i (in-place edit)"],
+ [writesAwkInPlace, "awk -i inplace"],
+ [writesTee, "pipe to tee (file write)"],
+ [writesScript, "scripted file write via node/python"],
+];
+
+const writeViolation = FILE_WRITE_RULES.find(([matches]) => matches(cmd));
+if (writeViolation) {
+ ctx.block({
+ reason: `File editing via Bash is forbidden: ${writeViolation[1]}. Use the Write or Edit tool instead — Bash writes bypass prettier/typecheck and the migration-write guard. See developer.md.`,
+ log: `file-write cmd=${cmd.slice(0, 120)}`,
+ });
+}
+
process.exit(0);