feat(onboard): split mode classifies CLAUDE.md sections, onboarder MODE: split executes (RED: current skill ran archetype detection on split)

This commit is contained in:
bchanot committed 2026-10-26 17:51:20 +01:00
1 parent b4131666af
commit 041e04b1d6
2 files changed
+186 -6

No files matched your search

+83 -1
View File
@@ -11,6 +11,9 @@ effort: medium
## ROLE
Generate the baseline claude-config files in a project directory. No interview, no audit, no analysis — the orchestrator `/onboard` handles those upstream. This agent only writes config files given a prepared brief.
Two modes. No `MODE:` line in the brief → the generator below (PHASES 1-6).
`MODE: split` → only § MODE: split at the end of this file runs.
---
## INPUTS (passed by orchestrator)
@@ -167,6 +170,85 @@ PLACEHOLDERS : <null enrichment keys left as TODO(/onboard STEP 3), or none>
- A command the permission rules refuse is reported in your final message with the rule that stopped it, never rerun through a wrapper script, alias, env file, `make` target or another shell (a brief that orders the refused form is wrong: report it, do not comply).
- NO interview (handled upstream).
- NO audit (handled downstream by orchestrator).
- NO destructive writes: never overwrite CLAUDE.md if it exists without asking (print path + STOP, let orchestrator decide).
- NO destructive writes: never overwrite CLAUDE.md if it exists without asking (print path + STOP, let orchestrator decide). MODE: split edits it by design, row by row, on the approved TABLE.
- Respect monorepo mode: path resolution depends on `monorepo_mode` in BRIEF.
- If a REQUIRED BRIEF key is missing (or monorepo unresolved), STOP and report — do not guess. Null OPTIONAL keys are normal on first dispatch: placeholder, don't stop.
---
## MODE: split (dispatched by `/onboard split`)
INPUTS: `PROJECT_ROOT` (absolute; written as a literal path in every
command below, never through a variable), `TABLE` = the approved rows, one
per line, `<heading> | <name> | <globs-json>` (heading without `## `). No
BRIEF; PHASES 1-6 do not run. `PR` below stands for
`bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT>`.
S0 — PREFLIGHT (no write before every row passes):
- `git -C <PROJECT_ROOT> status --porcelain` is empty, else STOP.
- gitignore: `git -C <PROJECT_ROOT> check-ignore -q .claude/rules/probe.md`
rc 0 means the rules would be ignored → append the negation (portable,
lands after any `.claude/*` line):
`printf '!.claude/rules/\n' >> <PROJECT_ROOT>/.gitignore`
then re-run `check-ignore`; still rc 0 → STOP: "ignore form cannot be
negated (BDR-003: use the `.claude/*` file form)", and `git -C
<PROJECT_ROOT> checkout -- .gitignore`. Remember whether this step
appended (`GITIGNORE_TOUCHED`): `.gitignore` enters the later `add`,
`checkout` and `commit` only then (a repo with no `.gitignore` is rc 1
here and never names it: a missing pathspec is a fatal git error).
- per row: `PR sections CLAUDE.md` lists `## <heading>` exactly once;
`<PROJECT_ROOT>/.claude/rules/<name>.md` does not exist; every glob of
`<globs-json>` passes `PR matches '<glob>'` (rc 0). Any failure → STOP
with the row and the reason (nothing written yet besides the gitignore
line, which the STOP reverts).
S1 — EXTRACT, per row (single quotes around the heading):
```bash
bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT> extract CLAUDE.md '<heading>' .claude/rules/<name>.md '<globs-json>'
```
rc ≠ 0 (should not happen after S0) → ROLLBACK: `git -C <PROJECT_ROOT>
reset -q`, `git -C <PROJECT_ROOT> checkout -- CLAUDE.md` (plus
`.gitignore` when S0 appended to it), delete every
`.claude/rules/<name>.md` this run wrote (literal paths, one `rm` per
row), then STOP with the row and the lib's message.
S2 — POINTER. If CLAUDE.md has no `## Path-scoped rules` section, append:
```markdown
## Path-scoped rules
Project rules live in `.claude/rules/<name>.md` and load on Read of a file
matching their `paths:` (never at session start): <name>, <name>.
```
Else add the new names to its list. Collapse runs of blank lines left by
the extraction (never more than one).
S3 — CHECK, COMMIT, VERIFY TRACKED.
```bash
bash ~/.claude/lib/project-rules.sh -C <PROJECT_ROOT> check
```
rc ≠ 0 → ROLLBACK as in S1, STOP with the culprit lines. rc 0 →
```bash
git -C <PROJECT_ROOT> add CLAUDE.md .claude/rules # + .gitignore when S0 appended
git -C <PROJECT_ROOT> commit -m "<message>"
```
`<message>` follows the project's commit convention (its CLAUDE.md commit
rules: allowed types and scopes); with none, `chore: split <k> CLAUDE.md
section(s) into .claude/rules/`. Commit rc ≠ 0 (a hook refused it, e.g.
the gitflow pre-commit on a protected branch, or gitleaks) → ROLLBACK as
in S1, STOP with the hook's output verbatim. rc 0 → verify each row in
the commit, not in the index:
```bash
git -C <PROJECT_ROOT> cat-file -e HEAD:.claude/rules/<name>.md # per row
```
A row `cat-file` cannot find → `STOP: <name> not in HEAD after commit
<hash> (commit kept)`; the orchestrator never re-dispatches on it.
OUTPUT:
```
SPLIT DONE: <k> rule(s) — <name>.md (<globs>), …
CLAUDE.md: <lines before> → <lines after> lines
CHECK : project-rules: <k> rule(s) ok
COMMIT : <hash> — all rules in HEAD
```
or `STOP: <row> — <reason> (rollback done, nothing committed)`, or
`STOP: <name> not in HEAD after commit <hash> (commit kept)`.