--- name: semble-setup description: "Installs, audits, repairs, updates, enables, reindexes or removes the semble_code semantic code-search MCP for a project. Triggers: semble, semantic code search, semble status, настрой semble, статус semble, переиндексируй, удали semble." user-invocable: true disable-model-invocation: true argument-hint: "[prompt] [status|install|upgrade|enable|disable|uninstall|purge|reindex|optimize|resume] [--unattended]" allowed-tools: [Read, Bash, AskUserQuestion] model: opus license: MIT --- # Semble > Lifecycle router for `semble_code`, a semantic repository-search MCP server (pin, scope, corpus, cache: Constants). It resolves the mode, prints state before touching anything, and delegates every mutation to `scripts/`. Two tools, once wired (exact names, never a wildcard): | Tool | Purpose | |------|---------| | `mcp__semble_code__search` | find code by intent / behavior / name | | `mcp__semble_code__find_related` | neighbors of a KNOWN location, after a useful seed | Both require `repo` (absolute project root or explicit `https://`/`http://` git URL, never inferred) and accept optional `content=code|docs|config|all` (default: the registered `code docs config` corpus). Results carry `file_path`, `start_line`, `end_line`, `score`, optional `content`; no `line` field. Defaults `top_k=5`, `max_snippet_lines=10`. Routing, wherever this skill or its report states it: intent/behaviour -> semble; symbol definitions, references, call graphs -> LSP; literals, regexes, paths, exhaustive counts -> `rg`. Honest limits (state these to the user, never oversell): `references/output-contract.md`. ## Constants | Const | Value | |-------|-------| | MCP server name | `semble_code` | | Pin | `semble[mcp]==0.6.2` — always single-quoted (`zsh` globs `[ ]`); single source `scripts/lib/semble-common.sh` | | Scope | MCP registration: per Claude Code profile, `user` scope in that profile's config file (CLI default is `local`; `-s user` is mandatory). Hooks, rule and state: per project. The default profile's file is `~/.claude.json`, addressed only with `CLAUDE_CONFIG_DIR` unset: set to `~/.claude`, Claude Code reads `~/.claude/.claude.json` instead | | Corpus | `SEMBLE_CONTENT_ARGS` in `scripts/lib/semble-common.sh`: the server/CLI `--content` argv, passed verbatim so both select `index-code-config-docs`. Never copy the token list into a new invocation | | `alwaysLoad` | `true`, written by `add-json` only (`claude mcp add` has no flag); without it the tools stay deferred behind `ToolSearch` | | Shared cache root | macOS `$HOME/Library/Caches/semble-code` · Linux `${XDG_CACHE_HOME:-$HOME/.cache}/semble-code` — one root for every project and profile | | State file | `/.claude/semble/state.json` | References — read only the one you need: | File | When | |------|------| | `references/intent-routing.md` | **always** — normative routing table + 5-step resolution algorithm + mode -> script routing | | `references/output-contract.md` | **always** — report template, verbatim; honest limits; reading the Step 1 status JSON | | `references/mcp-and-cache.md` | MCP detection states, exact registration commands, cache layout | | `references/language-coverage.md` | suffix -> bucket, and what is uncovered | | `references/project-agent-migration.md` | how project agent frontmatter is patched | | `references/install-chain.md` | `install`, `upgrade`, `resume` — before Step 3 / Step 4: probe keys, script behaviour, guidance parts | | `references/removal.md` | `uninstall`, `purge` — before the flavour question: what each flavour deletes and keeps | --- ## Prompt contract `$ARGUMENTS` is one free-form RU/EN prompt; mode tokens may sit anywhere in it. The routing table, keyword scoring and resolution algorithm are not duplicated here: read `references/intent-routing.md` (already listed **always** above) and apply it literally in Step 2. `status` asks nothing. Before Step 0 executes, resolve the prompt against known context and print one PLAN. If checkpoint state is unknown, label the mode provisional and include the Step 1 status probe in DO. Step 2 refines from that probe with one short update, never a second PLAN. ``` PLAN — brewcode:semble-setup INPUT: MODE: — SCOPE: DO: <2-5 imperative bullets — the steps this mode actually runs> RESULT: ``` --- ## Step 0 — Resolve the skill directory Line 1 is the `CLAUDE_SKILL_DIR` token in its exact dollar-brace spelling, substituted into the skill text at load (not an environment variable); any other spelling, such as a `:-` modifier, is never substituted. Line 2 falls back to the newest plugin-cache copy (leaf `semble-setup` or pre-rename `semble`). Line 3 is substituted the same way, to the session's start dir that hooks also get (unset in the Bash tool); without it the scripts fall back to the git toplevel, whose `settings.json` a session started in a subdirectory never loads. Copy all three lines unchanged to the top of every later block: a new Bash call inherits nothing. **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" case "$SD" in "$HOME"/.claude/plugins/cache/*) echo "⚠️ SD came from the plugin CACHE, not \$CLAUDE_SKILL_DIR — assets may be older than the marketplace HEAD" ;; esac test -d "$SD/scripts" && test -f "$SD/scripts/semble-status.sh" && echo "SD=$SD" && echo "✅" || echo "❌ FAILED — skill dir unresolved: SD='$SD'" ``` > **STOP if ❌** — the plugin cache is incomplete. Run `/brewtools:plugin-update` (or `claude plugin update brewcode@claude-brewcode`) and retry. > > The ⚠️ line means no substitution happened (body run outside skill mode): the cache answers and can install older hook assets over newer ones. Print `SD` and its version directory in the report. `--plugin-dir` does not redirect this: the value is the directory the skill was loaded from. ## Step 1 — STATUS FIRST, in every mode, before any decision This block is read-only: `semble-status.sh` writes nothing under the project, the cache root or the profile's `settings.json`. Say once the side effects of the tools it calls: `claude mcp get semble_code` may touch the CLI's own `.claude.json` / statsig files; `uvx --from 'semble[mcp]==0.6.2' semble --version` is a network fetch on a cold uv cache (slow, fails offline, installs nothing). **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" bash "$SD/scripts/semble-status.sh" --section all --json; RC=$? echo "RC=$RC" [ "$RC" -eq 0 ] && echo "✅" || echo "❌ FAILED" ``` > **STOP if ❌** — no report = broken scripts or unsupported platform. Report the raw output; change nothing. Read `.verdict`, `.state.phase`, `.state.enabled`, `.mcp.state`, `.mcp.scopes`, `.cache.staleness`, `.guidance`, `.agents.summary`, `.prereq`, `.nextStep`. An `{"error": ...}` section is reported unknown; it never suppresses the rest. `.versions`, retired hooks, `.guidance.permissionsWired`, an errored `guidance` probe: `references/output-contract.md` (Reading the Step 1 status JSON). > `partial` -> `.nextStep`: only `warm`/`smoke` unrecorded and/or the index variant missing (`no current content variant in the shared cache`, e.g. index-only) -> `resume` (warm builds it); only absolute-path hook rows (`.guidance.absoluteCount`, `portable:` line), agents needing a patch and/or a stale rule stamp, with or without those -> `upgrade`; a hand-edited rule at an old or missing `content_version` (`.guidance.ruleStampStale`; unstamped counts as older) -> report it to the USER as Step 3.2b says, never plain `upgrade`; missing MCP, hooks, rule, permissions or install steps -> `install`. Keep this JSON as the immutable **Before** snapshot; never refresh it after a mutation. ## Step 2 — Resolve the mode Invariants of the `references/intent-routing.md` algorithm: empty / whitespace-only input -> `status`, read-only, no questions; `phase == "awaiting_reload"` and no mode named -> `resume` (before scoring); rule 5 bundles known choices into one `AskUserQuestion` (max 4 questions), and a later destructive or permission decision gets its own gate. A backup or `--yes` is never user consent. Print **Detection**/**Before** from the saved JSON before any mutation. Routine choices need no question. ### Early exit Mode `status`, or everything `ready` with a vague intent: print the report and **stop** — no re-install, no question chain. ### Mode -> script routing Each mode's script chain: `references/intent-routing.md` (Mode -> script routing). Exit codes: `0` ok · `1` hard failure (earlier writes may survive, no rollback) · `2` bad usage · `3` recoverable precondition/conflict/skipped verification · `4` confirmation required. Read each script's JSON and record the actual changed/failed/skipped surfaces. ## Step 3 — `install` chain (also the repair path) State exact commands and paths first, then run the blocks in order; stop at the first ❌. ### 3.1 Prerequisites — one hard gate (`uv`), one soft gate (`coreutils`) `semble-install.sh all` runs `check -> uv -> coreutils -> semble`. Two machine-level `brew install`s, gated differently: | Step | Gate | Exit code of `all` | |------|------|--------------------| | `brew install uv` | **hard**: exit `4`, nothing runs without explicit confirmation | `4` confirm · `3` no brew · `1` failed | | `brew install coreutils` -> `gtimeout` | **soft**: missing `--yes` or `brew`, a failed brew, `SEMBLE_NO_NETWORK`, `SEMBLE_DRY_RUN` stay a *note* | never non-zero | `uv` comes only from `brew`, the pin from `uvx`; narrating a plan is not a gate. Default is uvx-ephemeral (no `uv tool install`: a `semble` on `PATH` blocks on a bare call). With `uv` present `all` exits `0` and the coreutils note scrolls past, so decide from the probe JSON, never `RC` alone (keys: `references/install-chain.md`, 3.1). **3.1a — probe (no `--yes`, nothing installed).** **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" bash "$SD/scripts/semble-install.sh" all --json; RC=$? echo "RC=$RC # 0 = uv already present | 3 = precondition | 4 = confirmation required, nothing installed" { [ "$RC" -eq 0 ] || [ "$RC" -eq 3 ] || [ "$RC" -eq 4 ]; } && echo "✅" || echo "❌ FAILED" ``` > **STOP if ❌** — exit 1/2: nothing was installed; report the raw output. > `RC=3` (no `brew`): print the manual fallback `curl -LsSf https://astral.sh/uv/install.sh | sh` without running it, and stop. > `RC=0`: `uv`/`uvx` present and the pin resolved; skip 3.1b/3.1c, go to 3.1d. **3.1b — ask, only on `RC=4`.** Print the probe's `.commands` array verbatim (the coreutils line is absent when a binary already backs `sc_timeout`; example in `references/install-chain.md`, 3.1b). Then one `AskUserQuestion`, bundled with known MCP scope/repair choices: *"Run these Homebrew installs now?"* — `Install` (runs exactly those commands) / `Cancel` (nothing runs; print the 3.1a fallback, report `Actions -> skipped: brew install uv (declined)`, end). Say that `brew install` writes to the machine outside this project and that `coreutils` is optional (watchdog -> `gtimeout`). **3.1c — apply, only after an explicit `Install`.** **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" bash "$SD/scripts/semble-install.sh" all --yes --json; RC=$? echo "RC=$RC" { [ "$RC" -eq 0 ] || [ "$RC" -eq 3 ]; } && echo "✅" || echo "❌ FAILED" ``` > **STOP if ❌** — exit 1/2 = install failed; report the raw output. `RC=3` = no `brew`: print the 3.1a fallback, do not run it, stop. > Record `.timeout.coreutils.status` in `Actions` (`installed` -> changed, else skipped with its `reason`); it never changes the verdict. Go to 3.2; 3.1d is skipped. **3.1d — the coreutils offer, only when 3.1b did not fire (`RC=0`).** First matching row wins: | # | Condition (from the 3.1a JSON) | Action | |---|--------------------------------|--------| | 1 | `.timeout.backend != "none"` | Print `timeout: — sc_timeout is bound by a binary.` -> 3.2 | | 2 | `.timeout.backend == "none"` **and** `.timeout.coreutils.status == "needs_confirmation"` **and** `.brew.present == true` | Offer it in the bundled question -> 3.1e only if approved | | 3 | `.timeout.backend == "none"` **and** `.brew.present == false` | Print `no brew — gtimeout cannot be installed; sc_timeout keeps its bash watchdog (still bounded).` -> 3.2 | | 4 | anything else (`skipped` / `failed` / dry / no-network) | Print `.timeout.coreutils.reason` -> 3.2 | Row 2 prints the `brew install coreutils` line from `.commands` and asks: *"Install `coreutils` for `gtimeout`? Optional — `sc_timeout` is already bounded by a bash watchdog; `gtimeout` just makes the bound a real binary."* — `Install` / `Skip`; `Skip` records `Actions -> skipped: brew install coreutils (declined)`. **3.1e — apply coreutils, only after an explicit `Install`.** With `--yes` it exits `0` on every path, a failed `brew` included. **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" bash "$SD/scripts/semble-install.sh" coreutils --yes --json; RC=$? echo "RC=$RC" [ "$RC" -eq 0 ] && echo "✅" || echo "❌ FAILED" ``` > Not a stop: continue to 3.2, recording `.timeout.coreutils.status` as in 3.1c; a ❌ is only reported. ### 3.2 Register the MCP server `semble-mcp.sh detect` returns one state with a fixed response; read `references/mcp-and-cache.md` before acting on anything but `absent`. `add`/`repair` write the active profile's config file only (Constants, Scope). | State | Action | |-------|--------| | `absent` | `semble-mcp.sh add --scope user --yes` | | `correct` | `MCP_ACTION=add`: no MCP mutation, `add` only refreshes the project checkpoint (`references/install-chain.md`, 3.2) | | `stale_args` | show the before/after diff, confirm once, `semble-mcp.sh repair --yes` | | `wrong_scope` | use the bundled migrate-to-`user`/keep decision; repair only if approved | | `duplicate` | show every scope repair removes and its user-scoped replacement; migrate only if approved | | `upstream_unpinned` | never auto-remove the upstream `semble` server; report the conflict, removal is the user's choice | | `malformed` | **STOP**, never write; report the file and parser offset for a hand fix | **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" MCP_ACTION=skip # add for absent/correct; repair only for the approved concrete transition if [ "$MCP_ACTION" = add ]; then bash "$SD/scripts/semble-mcp.sh" add --scope user --yes --json; RC=$? elif [ "$MCP_ACTION" = repair ]; then bash "$SD/scripts/semble-mcp.sh" repair --yes --json; RC=$? else echo "skipped: MCP registration kept by user decision"; RC=0; fi echo "RC=$RC" [ "$RC" -eq 0 ] && echo "✅" || echo "❌ FAILED" ``` > **STOP if ❌** — report surviving state/config changes. `MCP_ACTION=skip` stops after the report: no wiring, no reload checkpoint. Backups, restore on failure, the `correct` checkpoint and no-project-root runs: `references/install-chain.md` (3.2). ### 3.2b Wire the guidance, permissions and agents — `install` does this itself All that needs no live server is wired now; the block equals Step 4.2's, so `resume` re-runs it idempotently and repairs drift. The smoke query (Step 4.1) and `phase ready` wait for the new session. Hook behaviour by phase and registration: `references/install-chain.md` (3.2b). **EXECUTE** using Bash tool: ```bash SD="${CLAUDE_SKILL_DIR}" [ -n "$SD" ] || SD="$(find "$HOME/.claude/plugins/cache/claude-brewcode/brewcode" -maxdepth 3 -type d -path '*/skills/*' \( -name semble-setup -o -name semble \) 2>/dev/null | sort -V | tail -1)" export CLAUDE_PROJECT_DIR="${CLAUDE_PROJECT_DIR}" RC=0 if bash "$SD/scripts/semble-guidance.sh" install --part all --json; then ARC=0; bash "$SD/scripts/semble-agents.sh" apply --scope project --yes --json || ARC=$? echo "agents apply RC=$ARC # 3 = reported conflict, not a failure" { [ "$ARC" -eq 0 ] || [ "$ARC" -eq 3 ]; } || RC=1 else RC=1; fi [ "$RC" -eq 0 ] && echo "✅" || echo "❌ FAILED" ``` > **STOP if ❌** — report which step failed and what it left behind; the 3.2 registration stands, no rollback. > Record `guidance` and `agents` in **Actions**; Step 4.3 marks them complete after `resume`. `skipped: rule: user_modified` is REPORT-ONLY, headless or not. **Never Write, Edit, `sed`, `cp` or hand-merge `.claude/rules/semble-first.md`, and never set its `content_version` yourself**: the user owns those edits. Record `rule: user_modified, kept`, then hand the USER three facts: the stale fact (`content_version` X or none vs the template's Y), the `diff -u