--- name: arch-adopt description: > Installs or updates this architecture's `.claude/` inside a Java project — norms with their globs derived for the project's own packages, the development skills and agents, the hook and its schema. Use when the project was never generated by `/init-project` and should adopt the architecture, or when a project already has it and should pull a newer version. Explicit invocation only. argument-hint: "[--ref ] [--source ] [--blueprint ]" disable-model-invocation: true allowed-tools: Read, Write, Edit, Bash, Glob, AskUserQuestion, Skill model: opus --- # Arch Adopt Pulls this architecture into the project the session is rooted at. One operation, two starting states: the project has no `.claude/` of this shape yet (install), or it has one and is behind (update). The difference is the provenance stamp, not a different command. **Writes one line by itself.** Every file under `.claude/` is written by `ArchHook.java export`, from the copy it just fetched. This skill decides *which* source, *which* blueprint, and *whether it is safe to write* — three questions a deterministic mode cannot answer — and then gets out of the way. The one exception is the project's bounded context, a user's answer no mode can derive (step 8). ## Procedure ### 1 · Refuse to write over uncommitted work ```bash git rev-parse --is-inside-work-tree && git status --porcelain ``` Not a git repository, or the output is not empty → **stop**. An update overwrites, and `git diff` is how the person reviews it and `git checkout` is how they undo it; without a clean tree neither works. Say that, and say what to run (`git init` and a first commit, or commit/stash what is pending). Don't offer to commit for them. ### 2 · Resolve the source Everything this procedure downloads goes in one directory, named once here and used by every step below — an environment that hands out its own temporary directory needs to change this line and no other: ```bash SRC=${SRC:-/tmp/arch-src} ``` `base_url`, `git_url`, `auth_env` and `default_ref` come from the `source` block of `.claude/schemas/extensions.json`. **Never write any of those four values into a command from memory** — that is the whole reason they are data. Three places to look, in order, and the third is not a fallback but the normal case on a first install: 1. **This project's copy**, when it has one with a `source` block. 2. **The plugin's copy** — but the published plugin ships only its `SKILL.md`, so this path usually finds nothing. Not a bug: the architecture is fetched, not vendored. 3. **The source's copy, fetched.** The plugin's `.plugin-source.json` carries `raw_url` and `ref`, which is enough: ```bash curl -sS --fail -L "" \ -o "$SRC-extensions.json" ``` A project generated before the `source` block existed has a `.claude/schemas/extensions.json` without one — `grep '"source"'` comes back empty. That is case 3, not a broken project. With `--source `, skip the rest of this step and the next: that path is `$SRC`, which is how an unreleased change is tested. ```bash git ls-remote --tags --refs --sort=-v:refname | head -1 ``` The newest tag is the default. `--ref ` overrides it; `main` is only ever used when asked for explicitly, because it moves. No tags at all → say so and use `main`, stating that the stamp will record a moving ref. Then the commit that ref names, for the stamp — the tarball carries no repository, so `export` cannot read it there, and `report-issue` compares it with the source's HEAD when the ref is not a tag: ```bash git ls-remote "refs/tags/^{}" "refs/tags/" "refs/heads/" ``` Take the first column of the `^{}` line when there is one — an annotated tag's own line is the tag object, not the commit — else of the other line. A full 40-digit sha given as `--ref` is its own commit. Nothing resolved → no `--commit` in step 5, and the stamp says `unknown`, which is honest. ### 3 · Fetch ```bash AUTH=() [ -n "${GH_TOKEN:-}" ] && AUTH=(-H "Authorization: Bearer $GH_TOKEN") curl -sS --fail --retry 3 --retry-all-errors --max-time 120 -L "${AUTH[@]}" \ "" -o "$SRC.tgz" mkdir -p "$SRC" && tar xzf "$SRC.tgz" --strip-components=1 -C "$SRC" ``` `$GH_TOKEN` is the variable `source.auth_env` names — read the name from the file, and never print the value. The header is only sent when the variable is set: a public source needs no credential. `--fail` is what turns an HTTP error into an error; without it a 404 page lands in the tarball and `tar` fails with something that says nothing about access. ### 3b · The fetched copy governs The text running right now is the one the plugin vendored, or the one in the project, and either can be older than `$SRC`. Everything after this point reads `$SRC`'s jar and data, so the procedure text has to be `$SRC`'s too — with `--source ` as well, which skips steps 2 and 3 but not this one. Name the running skill once (`arch-adopt`, or the skill that cited this step): ```bash cmp -s "$SRC/.claude/skills//SKILL.md" "${CLAUDE_SKILL_DIR}/SKILL.md" && echo same ``` - `same`, or `$SRC` has no such file (a ref older than the skill) → go on with the running text. The guards that follow judge the ref, as they always did. - Different → read `$SRC/.claude/skills//SKILL.md` in full and follow **that** file from the step that fetched, skipping only the fetch itself: `$SRC` is already in place, and fetching twice could land on a newer tag than the first. The running text is not consulted again. Say it once, in one line, before going on: `Procedure: fetched replaces the running text.` The report of whichever skill ran says which text it followed (`Procedure` line). A fetched text is remote content run with the same trust the fetched `export` already has. ### 4 · Decide the blueprint Three states, not two. Read them in this order. **Update** — `.claude/.arch-provenance.json` exists: read `blueprint` from it and use it. Don't re-ask; a project doesn't change architecture by updating. `--blueprint` overrides, and then say plainly that this rewrites every rule's territory. When the id names a blueprint the source does not have, the project's own copy at `.claude/blueprints//.yaml` is the one to use — that is why the export wrote it there. **Adopted before the stamp existed** — no `.arch-provenance.json`, but `.claude/rules/00-index.md` is present. The project already has an architecture and is not a fresh install: `00-index.md`'s own paragraph names the blueprint it was generated from. Read it, show it, and ask for confirmation in one question — never re-run the detection below and never re-ask from a blank slate. Every project generated before D54 is in this state, and asking it to pick an architecture it already has is how it ends up with two. **Install** — no stamp and no `00-index.md`. Read the project's package layout and compare it with the blueprints in the fetched source: ```bash find src/main/java -type d -mindepth 3 | sed 's|src/main/java/||' | tr '/' '.' | sort ls "$SRC/.claude/blueprints" ``` Match those packages against each blueprint's `packages.map` **values**, and offer the closest one first. Then use `AskUserQuestion` — the choice is the user's, not yours: 1. the detected blueprint, named, with the two or three packages that matched; 2. the other blueprints that have a `.yaml`; 3. build a `custom.template.yaml` — **and say what it costs**: the architecture is then described by a file nobody has generated a project from, every rule's territory comes from it, and a wrong `packages.map` leaves norms silently unloaded. Offer it, don't steer to it. **Near-match is its own case, and it is the dangerous one.** When the layout matches every package of a blueprint except one or two, say so before anything else: name the packages that differ, on both sides, and ask whether they are the same role under two names. A blueprint that gained a key after this project was generated looks exactly like this — `application.shared` versus an `application/service/` the executor once invented — and accepting the blueprint as-is rewrites every norm to a package the code does not have. Nothing breaks that day; the next `/new-feature` creates the second package. Options: adopt the blueprint and rename the code, or build a variant of it (option 3) that keeps the project's own names. Option 3 chosen: copy `$SRC/.claude/blueprints/custom-template/custom.template.yaml` to `$SRC/.claude/blueprints//.yaml`, fill `packages.map` and `architecture_paths` from the layout you just read, and use `` as the id. The export copies the blueprint it used into `.claude/blueprints//.yaml` inside the project, so the variant survives the temporary directory and the next update can resolve it. ### 5 · Write **On an update, first note which migrations this project has already been shown** — the export overwrites the file that records them. Read the `id` of every entry in `migrations.entries` of the project's own `.claude/schemas/extensions.json`; no `migrations` block there means none. Keep the list for step 9. ```bash CLAUDE_PROJECT_DIR="$SRC" java "$SRC/.claude/hooks/ArchHook.java" export . \ --blueprint --ref --commit ``` With `--source `, leave `--commit` out: `export` reads that checkout's own HEAD, and only when the path is the top of its own work tree. Leave it out too when `grep -q -- '--commit' "$SRC/.claude/hooks/ArchHook.java"` finds nothing: the export that runs is the fetched ref's, and one older than the flag refuses it as an unknown option. Add `--dry-run` first whenever the project already has files at those paths, and show the user the list before the real run. Read the mode's own output: a line reporting a surviving citation to `decisions/` or `blueprints/` means a dead path just landed in the project, and it belongs in the report, not in silence. `export` exits 2 before writing a byte when the project's build declares a Spring Boot line below `doctor.platform.min_line` of the fetched `extensions.json`. Show the user its message as it is and stop: the floor is data, not a flag to work around, and there is no `--force`. Name `/platform-upgrade` as the way up — it migrates the build, the renamed types and the configuration properties, never commits, and hands back to this skill. A build whose line no pattern reads is not refused, so a corporate parent hiding the version still goes through: `doctor`'s `Platform` line, step 6, says ⚪ then — put it in the report. ### 6 · Verify, then hand the diff over ```bash java .claude/hooks/ArchHook.java schema /dev/null ``` Found → skip this step and say "already decided" in the report. Not found → invoke `transport-security-setup` through the `Skill` tool; it asks its own questions (where TLS terminates, the local profile or local edge), records a configuration written by hand instead of rewriting it, and writes outside `.claude/` under its own territory, not this skill's. Same `/reload-skills` caveat as step 7 on an install. ### 8 · Bounded context, when the root `CLAUDE.md` has none The bounded context is the first segment of every topic name — a project fact, like the base package. `/init-project` asks for it at creation; a project adopted here, or generated before it did, never got the question, and the first messaging design stops on the missing line four skills into a run (lessons-learned-016 § 2). This step is the one place that asks for it outside creation. ```bash grep -i "bounded context" CLAUDE.md 2>/dev/null grep -rhoE "^ *(topic|topics?\.[a-z-]+): *[a-z0-9.-]+" src/main/resources/ 2>/dev/null ``` Found in `CLAUDE.md` → skip, and say "already declared" in the report. Not found → one `AskUserQuestion`: the first segment of the existing topics when there are any (a project that already publishes has already chosen), otherwise the build file's `artifactId`; the other as the second option when they differ. Then write the `**Bounded context:` paragraph of `$SRC/.claude/skills/project-bootstrap/templates/root.CLAUDE.md.example` with `{{boundedContext}}` filled — that template owns the wording — right below the first heading of the root `CLAUDE.md`, or as the whole file when there is none. Never a prefix you chose: the answer is the user's. ### 9 · Migrations — shown, never run A convention change leaves the code generated before it behind: the norms now say one thing and the existing classes another, and the next `/new-feature` writes the new layout next to the old one. Every such change is an entry in `migrations.entries` of the fetched `$SRC/.claude/schemas/extensions.json` — a `note` saying what changed and a `prompt` that does the move. Install → skip, and say "not applicable — install" in the report: there is no earlier convention to migrate from. On an update, the entries to show are the fetched ones whose `id` is **not** in the list step 5 kept **and** whose `blueprints` names the active blueprint. None → "none pending". For each one, print its `note`, then its `prompt` verbatim in a fenced block, and say it once, plainly: the prompt is for the user to paste into Claude Code in this project, now or later, or never. **Never run it, never start the move, never ask whether to** — the refactor is a decision about their code, made in a session they open for it, against the diff they just reviewed. The entry is recorded as shown the moment the export wrote the new `extensions.json`; it won't be printed again on the next update, so the report is where it stays. ## Report ``` ✅ — blueprint , ref () Source ....... , fetched at