diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e82f4ac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: ci +on: + pull_request: + push: + branches: [main] +permissions: + contents: read +jobs: + install: + name: installer, ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # the upgrade cases install old commits with their own installer + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: install.sh, fresh, upgrade, edits, uninstall + if: runner.os != 'Windows' + run: bash scripts/test-install.sh + - name: install.ps1, the same cases + shell: bash + run: bash scripts/test-install.sh ps1 + check: + name: check and tool self tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + - run: bash scripts/check.sh # the private name scan is skipped here: its list is never committed + - run: npm ci + - run: npx playwright install --with-deps chromium + - run: sudo apt-get update && sudo apt-get install -y ffmpeg + - run: npm run test:tools diff --git a/AGENTS.md b/AGENTS.md index a701f5a..8ff1ef6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,7 +19,7 @@ git clone --depth 1 https://github.com/gntrs/workflow.git ~/.claude/workflow markdown skills, one rules file, two installers and six scripts (the size probe, its runner, the brand check, the ref reader, the ref check, the recorder). no build. - skills live in `skills//SKILL.md`, depth in `skills//references/`. frontmatter `name` matches the folder. -- `rules/RULES.md` is always on. a skill never contradicts it. +- `rules/RULES.md` is always on. a skill never contradicts it. nothing tells the reader to edit an installed file: what is personal goes in `~/.claude/RULES.local.md` (template in `setup/RULES.local.md`). - generic only. no names, emails, hosts, private projects or personal paths. - lowercase, direct prose. zero em dashes. - `bash scripts/check.sh` before you hand back. it must print `ok`. put your own private strings in `.claude/denylist.txt` (gitignored, one regex per line) and it scans for them too. @@ -27,7 +27,10 @@ markdown skills, one rules file, two installers and six scripts (the size probe, - after changing `tools/brand-check.mjs`, run `node tools/brand-check.mjs --self-test` and show every line passes. - after changing `tools/ref-read.mjs` or `tools/ref-check.mjs`, run their `--self-test` and show every line passes. ref-read's needs playwright like the probe runner. - after changing `tools/record.mjs`, run `node tools/record.mjs --self-test` and show every line passes. it needs playwright like the probe runner, and ffmpeg for the mp4 lines (without it, those check the webm fallback). -- after changing an installer, run it into a throwaway home: `HOME=$(mktemp -d) bash install.sh --yes --dry-run`, then without `--dry-run`, twice. +- after changing an installer, run `bash scripts/test-install.sh` (and `bash scripts/test-install.sh ps1` where `pwsh` exists). it installs into throwaway homes: fresh, an upgrade from old commits, with edits, uninstall. a new behavior gets a case there. keep `install.sh` and `install.ps1` doing the same thing. +- `npm ci && npm test` runs the check, the installer cases and every tool self test. playwright is pinned in `package.json`. +- a release: bump `VERSION` and `package.json`, add the `CHANGELOG.md` entry, tag `v`. +- `ln -sf ../../scripts/pre-commit .git/hooks/pre-commit` once per clone, so the check runs before every commit. ## the rules that hold here too diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d7a60ee --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,38 @@ +# changelog + +newest first. the installer prints the version it had and the one it wrote. + +## 1.1.0 + +updates work now. before this, running the installer again skipped every skill that differed from the new one, whether you had edited it or not. + +- **`/bbq`, the fast build.** for a hackathon, a prototype or a quick iteration: no questions, a time box, the demo path end to end first, fakes behind one seam, builders split by surface on a contract, one cold review of the demo, a debt list at the end. +- **big prs and single features are faster.** the build lane and the deep lane's phase builders no longer go through pstack's full feature playbook (a design panel on every job, a worktree per delegate, a commit per unit, its own pr flow). everything independent starts in one message, a ten line plan, builders split by files, high effort only on the plan and the final review, pstack tools by name. the deep lane keeps pstack for the long loop and its state. +- **it reviews itself.** on build and deep the cold review runs and its findings are fixed without being asked. +- **the installer tracks what it installed.** `~/.claude/workflow-manifest` holds a hash per file. on the next run a file you did not touch is replaced, a file you edited is kept and named. an install from before this version is recognised from the hashes of every file ever shipped, so it updates too. +- **backups leave `skills/`.** `--force` moves your copy to `~/.claude/workflow-backups//`. the `.bak-` folders older versions left inside `skills/` are moved there on the next run. +- **your settings have their own file.** `~/.claude/RULES.local.md` is created once and never written again. name, model names, voice, git changes and extra steps go there, and it wins over `RULES.md`. installed skills are no longer edited by setup. +- **`--with-permissions`.** merges an ask list into `~/.claude/settings.json`, so claude code stops and asks before a push, merge, pr, release or deploy command. the old file is backed up. +- **`--with-hooks`.** a hook that installs missing `node_modules` before a command that needs them. mac and linux, needs `jq`. +- **`--status`** says what you have, what main has, what is behind and what you edited. **`--uninstall`** moves what it installed to the backups folder and takes its lines out of `CLAUDE.md` and its hook out of `settings.json`. +- **merge.** the agent may merge, only on a yes that names the merge. a numbered chain printed in the `/ship` block can be approved with one yes, once. +- **models.** no model names in the skills. one strong model for every seat, a second family only for the major seats, names in `RULES.local.md`. +- **the size sweep** adds 2560 wide and a new fault, `off-center`: a tall column with a max width and no auto margins, glued to the left on a wide screen. +- **every recap and `/ship` block** says first whether a fresh review ran and what it said. +- **lighter.** `design/SKILL.md` went from 3,496 words to 1,718, the rest moved into its references. the skill descriptions that load on every turn went from 989 words to 504. +- **pstack** pin moved from v1.5.0 to v1.21.0, and an existing install moves with it. `skills/pstack/models.md` ships with every role on `inherit-parent` and is yours: created once, never written again. +- **a skill folder that is a link** to your own copy is left alone. +- **the installer pulls** when it runs from `~/.claude/workflow`, so running it again is the update. +- **ci.** the installer cases on linux, mac and windows, the repo check and the tool self tests. playwright is pinned in `package.json`. + +### if you edited your installed copy + +setup used to tailor `RULES.md` and the skills in place. those files count as edited, so the installer keeps them and names them. + +1. run `bash install.sh --status` to see which files you edited. +2. move what is yours (name, models, voice, git lines) into `~/.claude/RULES.local.md`. +3. run `bash install.sh --force`. your old copies are in `~/.claude/workflow-backups/`. + +## 1.0.0 + +the first public version: cook, deep, ship, review, status, initiate, design, write, playbook, the optional brain, the size probe, the brand check, the ref reader and the recorder. diff --git a/README.md b/README.md index 12f222a..3c53532 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ paste this into your agent: set up https://github.com/gntrs/workflow ``` -it reads [SETUP.md](SETUP.md), asks six things once and fits it to your machine. +it reads [SETUP.md](SETUP.md), asks seven things once and fits it to your machine. ### mac and linux @@ -35,6 +35,17 @@ powershell -ExecutionPolicy Bypass -File $HOME\.claude\workflow\install.ps1 -Yes then restart your agent and `/cook` something real. installer flags are at the top of [install.sh](install.sh). +### update + +run the installer again. it pulls the newest version first. what you did not touch is replaced, what you edited is kept and named, and nothing is deleted: old copies go to `~/.claude/workflow-backups/`. your own settings live in `~/.claude/RULES.local.md`, which it never writes twice. [what changed](CHANGELOG.md) + +```bash +bash ~/.claude/workflow/install.sh --status # what you have, what is behind, what you edited +bash ~/.claude/workflow/install.sh --yes # update +``` + +add `--with-permissions` and claude code itself asks before every push, merge, pr, release and deploy command. it matches how a command starts, so it is a second lock, not the only one. + ## how it runs @@ -49,10 +60,12 @@ it starts small and moves up a lane if the work fights back. | lane | looks like | runs | |---|---|---| | **microwave** (quick) | a typo, a color, a flag | main thread, no subagents | -| **stove** (build) | one feature or bug you know | up to 2 helpers, the plan read cold first | +| **stove** (build) | one feature or bug you know | helpers started together, split by files, reviewed as they land | | **slow cook** (/deep) | unfamiliar code, broke twice, "run till done" | research, a plan, your read, up to 4 agents | -stove and slow cook print a `/goal` with a finish line you can check, so the session can't stop short. +stove and slow cook print a `/goal` with a finish line you can check, so the session can't stop short. both review their own work with a fresh agent and fix what it finds. you never have to say "review it". + +not a lane, its own door: **the grill** (`/bbq`), for when it has to exist tonight. ## the commands @@ -66,13 +79,17 @@ the one door. it picks the lane, the models and how many agents. [skills/cook](s for work that fights back, or runs while you sleep. research first, then a plan in a file you read, then a long run that survives a compact. [skills/deep](skills/deep/SKILL.md) +### the grill (/bbq <time> <thing>) + +fast, hot, a bit burnt. for a hackathon, a prototype, a quick try. no questions, no plan to approve: it picks a time box, builds the demo path end to end first, fakes the slow parts behind one seam, splits builders by surface, reviews itself, and hands back what works, what is faked and the shortcuts it took. one yes at the end commits it and, if a host is logged in, puts up a preview link. nothing leaves before that. [skills/bbq](skills/bbq/SKILL.md) + ### the chef carrying a tray serve (/ship) prints the exact text that would go public, every file, the real test output and your hand tests. then it waits. nothing leaves without your yes, not even a commit. [skills/ship](skills/ship/SKILL.md) ### the chef tasting from a spoon taste test (/review) -a fresh agent reads the work, your exact words and your taste file, then says ship it, fix these, or bin it. [skills/review](skills/review/SKILL.md) +a fresh agent reads the work, your exact words and your taste file, then says ship it, fix these, or bin it. cook runs it on its own, you only call it for a second look. [skills/review](skills/review/SKILL.md) ### the chef giving a thumbs up /status @@ -110,7 +127,9 @@ these load on their own: ### why it's fast -- **review early.** the plan is read before anyone builds, and each lane the moment it lands. +- **no waiting in line.** everything independent starts in one message: explorers, builders, the plan's reviewer. +- **it reviews itself, early.** the plan is read before anyone builds, each piece the moment it lands, and the findings are fixed without you asking. +- **heavy tools by name only.** a design panel or a second review runs when the job calls for it, not on every feature and not on every phase of a big pr. - **parallel.** up to 4 agents, fewer on less ram. each owns its own files, so nothing collides. - **the coordinator doesn't build,** so its context stays small. - **a new ask gets its own lane,** never queued behind the batch. @@ -137,7 +156,7 @@ every reaction you give goes into a taste file, word for word, dated, with what ### the rules -always on in [rules/RULES.md](rules/RULES.md), and they beat every skill: nothing leaves without your yes, git only with a yes, no ai authorship, every job ends with a hand test. +always on in [rules/RULES.md](rules/RULES.md), and they beat every skill: nothing leaves without your yes, git only with a yes, no ai authorship, every job ends with a hand test. your own layer, `~/.claude/RULES.local.md`, beats them: your name, your models, your voice, your extra steps. ### the brain, optional diff --git a/SETUP.md b/SETUP.md index aa77c98..40a8854 100644 --- a/SETUP.md +++ b/SETUP.md @@ -1,6 +1,6 @@ # setup, for the agent -you were asked to set this workflow up for the person you are talking to. it is a set of markdown skills, one rules file and three small scripts (the size probe, its runner, the brand check) that go into `~/.claude/`. install it tailored to them, do not copy it blind. +you were asked to set this workflow up for the person you are talking to. it is a set of markdown skills, one rules file and six small scripts (the size probe, its runner, the brand check, the ref reader, the ref check, the recorder) that go into `~/.claude/`. install it, then write what is personal into their own file. do not copy it blind. works the same on macos, linux, wsl and windows. on windows use `$HOME\.claude` and powershell where this says bash. @@ -21,7 +21,8 @@ check these yourself and say what you found, in one short block. do not ask abou - os and shell, total ram, free disk. - whether `git`, `gh`, `node`, `docker` (and whether a docker vm is running), `python3`, `bun` and the `claude` cli exist. - `git config --global user.name` and `user.email`. none set: add a question for the name and email their commits go out as. -- what is already in `~/.claude/`: `CLAUDE.md`, `RULES.md`, any skill folder with the same name as one of ours (`cook`, `deep`, `ship`, `status`, `review`, `initiate`, `design`, `write`, `playbook`, `brain`, `dream`), and whether pstack is already installed (`claude plugin list`). +- what is already in `~/.claude/`: `CLAUDE.md`, `RULES.md`, `RULES.local.md`, `settings.json`, any skill folder with the same name as one of ours (`cook`, `bbq`, `deep`, `ship`, `status`, `review`, `initiate`, `design`, `write`, `playbook`, `brain`, `dream`), and whether pstack is already installed (`claude plugin list`). +- an earlier install: `bash ~/.claude/workflow/install.sh --status` says which version is there and which files they edited. then one message, numbered, each question with the default you will use if they say "you decide": @@ -30,49 +31,57 @@ then one message, numbered, each question with the default you will use if they 3. **the brain.** a notes vault at `~/vault` (Obsidian friendly) where every repo gets a hub, a log and an open items list, plus `/brain` and `/dream`? default: no. without it, notes live in each repo's gitignored `.claude/`. 4. **git strictness.** shipped: no commit, push, merge, pr or deploy without their yes that specific time, and one `feat/`, `fix/` or `chore/` branch per feature, which needs no ask. keep it, or allow local commits freely and gate only what leaves the machine? default: keep it. and: add the per repo notes files to the global gitignore, so they never get committed anywhere? default: yes. 5. **writing voice.** how text should sound (lowercase or not, formal or not), banned words. default: the plain style in `skills/write`. -6. **parallel agents.** default from what you measured (see the table below). ask only if they run several sessions at once or a heavy local stack. +6. **ask before anything leaves.** add an ask list to `~/.claude/settings.json`, so claude code itself stops before a push, merge, pr, release or deploy command, whatever a skill says? default: yes. without it, "nothing leaves without your yes" is a rule the agent follows, not one the app enforces. +7. **parallel agents.** default from what you measured (cook reads ram, a running docker vm and free disk every time). ask only if they run several sessions at once or a heavy local stack. ## 2. install run the installer with a flag for every answer. you have no terminal, so it asks nothing and anything you leave out is a no. ``` -bash ~/.claude/workflow/install.sh --dry-run --yes --with-pstack --with-brain --gitignore # mac, linux, wsl -powershell -ExecutionPolicy Bypass -File $HOME\.claude\workflow\install.ps1 -DryRun -Yes -WithPstack -WithBrain -Gitignore # windows +bash ~/.claude/workflow/install.sh --dry-run --yes --with-pstack --with-brain --with-permissions --gitignore # mac, linux, wsl +powershell -ExecutionPolicy Bypass -File $HOME\.claude\workflow\install.ps1 -DryRun -Yes -WithPstack -WithBrain -WithPermissions -Gitignore # windows ``` -- `--with-pstack` / `--no-pstack` per answer 2, `--with-brain` / `--no-brain` per answer 3. +- `--with-pstack` / `--no-pstack` per answer 2, `--with-brain` / `--no-brain` per answer 3, `--with-permissions` / `--no-permissions` per answer 6. - `--gitignore` adds the per repo notes files (`.claude/CLAUDE.md`, `log.md`, `tbd.md`, `plans/` and the rest, never all of `.claude/`) to their global gitignore. it touches git config, so ask. -- an existing skill with the same name is skipped and listed. `--force` replaces it and keeps the old one as `.bak-`. ask before `--force`. +- `--with-permissions` merges the ask list in `setup/permissions.json` into `~/.claude/settings.json`. everything already in that file stays, and the old file is copied to `~/.claude/workflow-backups/` first. the rules match how a command starts, so `git push` asks and `git -C push` or a push through `gh api` does not: it is a second lock, the first is still the rule in `RULES.md`. +- `--with-hooks` (mac and linux, needs `jq`) adds a hook that installs missing `node_modules` before a command that needs them, the fix for a fresh clone answering "command not found". offer it to anyone who works in node repos, and say what it does: it runs the project's own install, postinstall scripts included, in any repo the agent runs a node command in. +- a file they did not touch is updated. a file they edited is kept and named in the output. `--force` replaces it and moves their copy to `~/.claude/workflow-backups/`. ask before `--force`, and read what they changed first: it probably belongs in `RULES.local.md`. show them the `--dry-run` output, then run it without `--dry-run`. the installer is short and commented: read it if they want to know exactly what it does. ## 3. tailor -edit the installed copies in `~/.claude/`, never this repo's files. +one file: `~/.claude/RULES.local.md`. the installer created it, never writes it again, and it wins over `RULES.md`. fill its sections from the answers. never edit an installed skill or `RULES.md`: an edited file stops getting updates. -| in the files | becomes | +| section in `RULES.local.md` | gets | |---|---| -| "the user" | their name if they asked for it | -| the subagent cap in `cook` | nothing to edit: cook reads ram, a running docker vm and free disk every time. lower the ceiling of 4 only if they asked | -| the disk floor, 8 gb free before a worktree | keep it. already under it: tell them worktrees stay off until they free space | -| the model table in `cook`, and `pstack/models.md` | the current claude models their plan has. no access to one: the nearest one they do. a second model family is optional, never the only lane | -| git lines in `RULES.md` | per answer 4 | -| `skills/write` | per answer 5 | +| name | their name if they asked for it. empty keeps "the user" | +| models | the current models their plan has: one strong model for every seat, and a second model family for the major seats only if they have one | +| git | what differs from the shipped strictness, per answer 4. empty keeps it | +| voice | per answer 5 | +| parallel agents | a lower ceiling, only if they asked. the disk floor (8 gb free before a worktree) stays. already under it: tell them worktrees stay off until they free space | +| extra steps | anything they want run before a task, before `/ship` or after a push, and strings that must never leave the machine | -pstack off: remove the pstack section in `RULES.md`. cook's build lane already says what runs without it. +pstack on: `~/.claude/skills/pstack/models.md` is theirs too, created once and never written again. it ships with every role on `inherit-parent`. put the same model names there only if they want a role pinned. -keep the substance. do not soften "nothing leaves without your yes", "git is never touched without a yes that specific time", "hand tests always" or "a checkable finish line". those are the point. +keep the substance. do not write anything into `RULES.local.md` that softens "nothing leaves without your yes", "git is never touched without a yes that specific time", "hand tests always" or "a checkable finish line", unless they asked for exactly that in answer 4. those are the point. + +### they installed before 1.1.0 and tailored the old way + +the old setup edited `RULES.md` and the skills in place. `install.sh --status` lists those files as edited. move what is theirs into `RULES.local.md`, show them the result, then run the installer with `--force`. their old copies are in `~/.claude/workflow-backups/`. ## 4. prove it say what you ran, not what you read. 1. `ls ~/.claude/skills` lists every skill you installed. -2. `grep -n '@RULES.md' ~/.claude/CLAUDE.md` shows the import. +2. `grep -n '@RULES' ~/.claude/CLAUDE.md` shows both imports, `@RULES.md` then `@RULES.local.md`, and `bash ~/.claude/workflow/install.sh --status` says 0 behind. 3. `ls ~/.claude/tools/responsive-probe.js ~/.claude/tools/probe-test.mjs ~/.claude/tools/brand-check.mjs ~/.claude/tools/ref-read.mjs ~/.claude/tools/ref-check.mjs ~/.claude/tools/record.mjs` lists all six. 4. pstack yes: `claude plugin list` shows pstack. 5. brain yes: `ls ~/vault` shows `HOME.md`, `now.md`, `projects/`. +6. permissions yes: `grep -n 'git push' ~/.claude/settings.json` shows the ask rule. then hand them this, numbered: @@ -80,8 +89,8 @@ then hand them this, numbered: 2. make a throwaway repo: `mkdir t && cd t && git init && printf 'teh readme\n' > README.md && git add -A && git commit -qm init`. type `/initiate`. expect: the notes paths in `.git/info/exclude`, a `.claude/CLAUDE.md`, `.claude/tbd.md`, and `git status --short` showing none of them. broken if: a notes file shows as untracked, `.gitignore` changed, or it commits. 3. type `/cook fix a typo in the readme`. expect: one line naming the lane `quick`, a `fix/` branch, the fix in the main thread, no subagents, a numbered hand test, then the `/ship` block and a stop. broken if: it spawns agents, asks five questions, or commits. 4. type `/status`. expect: five lines or fewer, the first answering "done or not". -5. say yes to the `/ship` block. expect: one commit under their git identity, no co-authored-by line (`git log -1 --format='%an <%ae>%n%b'`), a push only if a remote exists. broken if: it opens a pr unasked, merges, or touches main. +5. say yes to the `/ship` block. expect: it runs the numbered chain the block printed and nothing else, one commit under their git identity, no co-authored-by line (`git log -1 --format='%an <%ae>%n%b'`), a push only if a remote exists. broken if: it opens a pr or merges without that step in the chain, or touches main. ## 5. finish -five lines: what was installed, what was skipped and why, where the source lives (`~/.claude/workflow`, update with `git pull` and the installer again), and the one thing to try first: `/cook` on a real task. +five lines: what was installed, what was skipped and why, where the source lives (`~/.claude/workflow`), how to update (`bash ~/.claude/workflow/install.sh --yes`: it pulls the newest version, replaces what they did not edit and names what it kept), where their own settings are (`~/.claude/RULES.local.md`), and the one thing to try first: `/cook` on a real task. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..9084fa2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.1.0 diff --git a/install.ps1 b/install.ps1 index 0a45c6d..9b62330 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,127 +1,382 @@ -# installs the workflow into $HOME\.claude on windows (powershell 5.1 or 7). +# installs the workflow into $HOME\.claude on windows (powershell 5.1 or 7), and updates it. # # powershell -ExecutionPolicy Bypass -File install.ps1 asks before anything optional -# -Yes defaults, no questions -# -WithPstack also install the pstack plugin (needs the claude cli) -# -WithBrain also install /brain, /dream and create ~\vault from brain-template -# -Gitignore also add the per repo notes files to your global gitignore +# -Yes defaults, no questions: rules, skills, the tools. nothing optional +# -WithPstack also install the pstack plugin (needs the claude cli) +# -WithBrain also install /brain, /dream and create ~\vault from brain-template +# -WithPermissions also make claude code ask before every push, merge, pr, release and deploy command +# -Gitignore also add the per repo notes files to your global gitignore # an agent (no console) gets no prompts: pass every switch you want. -# -Force replace skills that already exist (old copy kept as .bak-) -# -DryRun print what would happen, change nothing +# -Force replace files you edited too (your copy goes to ~\.claude\workflow-backups\) +# -DryRun print what would happen, change nothing +# -Status what is installed, what is behind, what you edited. changes nothing +# -Uninstall move every file it installed and you did not edit to workflow-backups\ # -# safe to run again. it never deletes, never touches git history, never pushes. -param([switch]$Yes, [switch]$Force, [switch]$DryRun, [switch]$WithPstack, [switch]$WithBrain, [switch]$Gitignore) +# run it again to update. a file you did not touch is replaced, a file you edited is kept and named. +# your own settings live in ~\.claude\RULES.local.md, which is created once and never written again. +# it never deletes (old copies are moved to workflow-backups\), never touches git history, never pushes. +[CmdletBinding()] +param([switch]$Yes, [switch]$Force, [switch]$DryRun, [switch]$Status, [switch]$Uninstall, + [switch]$WithPstack, [switch]$WithBrain, [switch]$WithPermissions, [switch]$WithHooks, [switch]$Gitignore) $ErrorActionPreference = 'Stop' $RepoUrl = if ($env:WORKFLOW_REPO) { $env:WORKFLOW_REPO } else { 'https://github.com/gntrs/workflow.git' } +# WORKFLOW_HOME is for the tests: it stands in for the home folder +$Root = if ($env:WORKFLOW_HOME) { $env:WORKFLOW_HOME } else { $HOME } $Src = $PSScriptRoot -if (-not $Src -or -not (Test-Path (Join-Path $Src 'rules\RULES.md')) -or -not (Test-Path (Join-Path $Src 'SETUP.md'))) { - $Src = Join-Path $HOME '.claude\workflow' - if (Test-Path (Join-Path $Src '.git')) { git -C $Src pull -q --ff-only } else { git clone -q --depth 1 $RepoUrl $Src } +if (-not $Src -or -not (Test-Path (Join-Path $Src 'rules/RULES.md')) -or -not (Test-Path (Join-Path $Src 'SETUP.md'))) { + $Src = Join-Path $Root '.claude/workflow' + if (Test-Path (Join-Path $Src '.git')) { + git -C $Src pull -q --ff-only + if ($LASTEXITCODE -ne 0) { Write-Host "could not update $Src (git pull failed), using the copy that is there" } + } else { git clone -q --depth 1 $RepoUrl $Src } } -$Claude = Join-Path $HOME '.claude' +# run from the clone the one line install made: get the newest version first, then start over from it. +# a clone anywhere else (a fork, a checkout you are working in) is used as it is +$MainVersion = '' +$Managed = Join-Path $Root '.claude/workflow' +if ((Test-Path (Join-Path $Src '.git')) -and -not $env:WORKFLOW_PULLED -and ((Resolve-Path $Src).Path -eq (Resolve-Path $Managed -ErrorAction SilentlyContinue).Path)) { + if (-not $Status -and -not $Uninstall -and -not $DryRun) { + git -C $Src pull -q --ff-only + if ($LASTEXITCODE -eq 0) { + $env:WORKFLOW_PULLED = '1' + & (Join-Path $Src 'install.ps1') @PSBoundParameters + exit $LASTEXITCODE + } + Write-Host "could not update $Src (git pull failed), using the copy that is there" + } else { + git -C $Src fetch -q 2>$null + if ($LASTEXITCODE -eq 0) { $MainVersion = (git -C $Src show '@{u}:VERSION' 2>$null | Out-String).Trim() } + } +} + +$Claude = Join-Path $Root '.claude' +$Manifest = Join-Path $Claude 'workflow-manifest' $Stamp = Get-Date -Format 'yyyyMMdd-HHmmss' -$Did = @(); $Skipped = @() +$Backup = Join-Path (Join-Path $Claude 'workflow-backups') $Stamp +$VersionFile = Join-Path $Src 'VERSION' +$Version = if (Test-Path $VersionFile) { (Get-Content $VersionFile -TotalCount 1 -Encoding UTF8).Trim() } else { 'unknown' } +$Ours = 'bbq','brain','cook','deep','design','dream','initiate','playbook','review','ship','status','write' +$script:Did = @(); $script:Skipped = @(); $script:Moved = @() +$script:NewMan = [ordered]@{} + +# the manifest and the known hashes, read once +$script:Recorded = [ordered]@{}; $script:Had = '' +if (Test-Path $Manifest) { + foreach ($line in Get-Content $Manifest -Encoding UTF8) { + if ($line -match '^# workflow (.+)$') { if (-not $script:Had) { $script:Had = $Matches[1].Trim() }; continue } + if ($line -match '^#' -or -not $line.Trim()) { continue } + $parts = $line -split '\s+', 2 + if ($parts.Count -eq 2) { $script:Recorded[$parts[1].Trim()] = $parts[0] } + } +} +$Known = @{} +$knownFile = Join-Path $Src 'setup/known-hashes.txt' +if (Test-Path $knownFile) { foreach ($k in Get-Content $knownFile) { if ($k.Trim()) { $Known[$k.Trim()] = $true } } } function Ask($q) { if ($Yes) { return $true } if ([Console]::IsInputRedirected) { return $false } $r = Read-Host "$q [y/N]"; return ($r -eq 'y' -or $r -eq 'Y') } -function Do-It($what, [scriptblock]$action) { - if ($DryRun) { Write-Host "would: $what" } else { & $action } +# -Yes never turns an optional part on +function Opt([bool]$flag, $q) { if ($flag) { return $true }; if ($Yes) { return $false }; return (Ask $q) } +function Sha($path) { return (Get-FileHash -Algorithm SHA256 -LiteralPath $path).Hash.ToLower() } +function Dest($rel) { return (Join-Path $Claude $rel) } +# new | same | clean (yours matches a copy we shipped) | edited +function State($srcFile, $rel) { + $dest = Dest $rel + if (-not (Test-Path -LiteralPath $dest)) { return 'new' } + $h = Sha $dest + if ($h -eq (Sha $srcFile)) { return 'same' } + if (($script:Recorded.Contains($rel) -and $script:Recorded[$rel] -eq $h) -or $Known.ContainsKey($h)) { return 'clean' } + return 'edited' +} +# true when REL or a folder above it inside ~\.claude is a link (your own copy, kept elsewhere) +function Linked($rel) { + $p = $Claude + foreach ($part in ($rel -split '/')) { + $p = Join-Path $p $part + $item = Get-Item -LiteralPath $p -Force -ErrorAction SilentlyContinue + if ($item -and ($item.Attributes -band [IO.FileAttributes]::ReparsePoint)) { return $true } + } + return $false +} +function Move-ToBackup($rel) { + if ($DryRun) { return } + $to = Join-Path $Backup $rel + New-Item -ItemType Directory -Force -Path (Split-Path $to -Parent) | Out-Null + Move-Item -LiteralPath (Dest $rel) -Destination $to -Force +} +# every file of a source file or folder as @{ Src; Rel }, rel always with forward slashes +function Pairs($src, $rel) { + if (Test-Path -LiteralPath $src -PathType Container) { + $base = (Resolve-Path -LiteralPath $src).Path.TrimEnd('\', '/') + return @(Get-ChildItem -LiteralPath $src -Recurse -File | Where-Object { $_.Name -ne '.DS_Store' } | Sort-Object FullName | ForEach-Object { + $sub = $_.FullName.Substring($base.Length + 1) -replace '\\', '/' + @{ Src = $_.FullName; Rel = "$rel/$sub" } + }) + } + return @(@{ Src = $src; Rel = $rel }) +} +# one skill folder or one file, all or nothing. a group with a file you edited is left alone and named, unless -Force or you say yes +function Install-Group($label, $src, $rel) { + if (Linked $rel) { $script:Skipped += "${label}: a link to your own copy, left alone"; return } + $pairs = Pairs $src $rel + $edited = @($pairs | Where-Object { (State $_.Src $_.Rel) -eq 'edited' } | ForEach-Object { if ($_.Rel -eq $rel) { $_.Rel } else { $_.Rel.Substring($rel.Length + 1) } }) + if ($edited.Count) { + $names = $edited -join ' ' + if (-not ($Force -or ((-not $Yes) -and (Ask "$label has your edits ($names). replace it? your copy goes to workflow-backups\")))) { + $script:Skipped += "${label}: you edited $names. kept yours. -Force replaces it, your copy goes to workflow-backups\" + return + } + } + $changed = $false + foreach ($p in $pairs) { + $st = State $p.Src $p.Rel + if ($st -eq 'edited') { Move-ToBackup $p.Rel; $script:Moved += $p.Rel } + if ($st -ne 'same') { + $changed = $true + if (-not $DryRun) { + $to = Dest $p.Rel + New-Item -ItemType Directory -Force -Path (Split-Path $to -Parent) | Out-Null + Copy-Item -LiteralPath $p.Src -Destination $to -Force + } + } + $script:NewMan[$p.Rel] = Sha $p.Src + } + # a file we installed before that is gone from the source: move it out if you did not edit it + if (Test-Path -LiteralPath $src -PathType Container) { + $have = @{}; foreach ($p in $pairs) { $have[$p.Rel] = $true } + foreach ($d in @($script:Recorded.Keys)) { + if (-not $d.StartsWith("$rel/") -or $have.ContainsKey($d)) { continue } + $f = Dest $d + if ((Test-Path -LiteralPath $f) -and (Sha $f) -eq $script:Recorded[$d]) { Move-ToBackup $d; $script:Moved += "$d (gone from the source)"; $changed = $true } + } + } + if ($changed) { $script:Did += $label } +} +function Write-Manifest { + if ($DryRun) { return } + $lines = @("# workflow $Version", '# files this installer put in ~/.claude and their sha256. it uses this to tell your edits from its own old copies. do not edit.') + foreach ($k in $script:NewMan.Keys) { $lines += "$($script:NewMan[$k]) $k" } + foreach ($k in $script:Recorded.Keys) { + if ($script:NewMan.Contains($k)) { continue } + if (Test-Path -LiteralPath (Dest $k)) { $lines += "$($script:Recorded[$k]) $k" } + } + [IO.File]::WriteAllText($Manifest, (($lines -join "`n") + "`n")) +} +# node writes a warning to stderr now and then. under Stop on powershell 5.1 that would end the script +function Run-Node { + $old = $ErrorActionPreference; $ErrorActionPreference = 'Continue' + try { $out = (& node @args 2>$null | Out-String).Trim() } finally { $ErrorActionPreference = $old } + return $out +} +function Settings-Merge($label, $frag) { + $settings = Join-Path $Claude 'settings.json' + if (-not (Get-Command node -ErrorAction SilentlyContinue)) { $script:Skipped += "${label}: needs node to merge settings.json. add the block in $frag by hand"; return } + $helper = Join-Path $Src 'setup/merge-settings.mjs' + $need = Run-Node $helper $settings $frag --check + if ($LASTEXITCODE -ne 0) { $script:Skipped += "${label}: $need"; return } + if ($need -eq 'same') { return } + if (-not $DryRun) { + if (Test-Path $settings) { New-Item -ItemType Directory -Force -Path $Backup | Out-Null; Copy-Item $settings (Join-Path $Backup 'settings.json') -Force } + Run-Node $helper $settings $frag | Out-Null + } + $script:Did += $label +} +# every @{ Src; Rel } the installer keeps up to date and that is installed here +function Groups { + $all = @(@{ Src = (Join-Path $Src 'rules/RULES.md'); Rel = 'RULES.md' }) + Get-ChildItem (Join-Path $Src 'skills') -Directory | Sort-Object Name | ForEach-Object { + if (Test-Path (Dest "skills/$($_.Name)")) { $all += Pairs $_.FullName "skills/$($_.Name)" } + } + foreach ($t in 'responsive-probe.js','probe-test.mjs','brand-check.mjs','ref-read.mjs','ref-check.mjs','record.mjs') { $all += @{ Src = (Join-Path $Src "tools/$t"); Rel = "tools/$t" } } + if (Test-Path (Dest 'skills/pstack')) { foreach ($f in 'install.sh','README.md') { $all += @{ Src = (Join-Path $Src "pstack/$f"); Rel = "skills/pstack/$f" } } } + return $all +} +function Read-Lines($path) { if (Test-Path $path) { return @(Get-Content $path -Encoding UTF8) } else { return @() } } + +# ---- status: read only +if ($Status) { + $haveText = if ($script:Had) { $script:Had } else { 'none recorded (never installed, or installed before updates were tracked)' } + Write-Host "installed: $haveText" + Write-Host "source: $Version, $Src" + if ($MainVersion) { Write-Host ("main: $MainVersion" + $(if ($MainVersion -ne $Version) { ', newer than the source here. the installer pulls it' } else { '' })) } + $behind = 0; $editedCount = 0 + if (Test-Path $Claude) { + foreach ($p in (Groups)) { + if (-not (Test-Path -LiteralPath (Dest $p.Rel))) { if ($p.Rel.StartsWith('skills/')) { $behind++ }; continue } + if (Linked $p.Rel) { continue } + switch (State $p.Src $p.Rel) { + 'clean' { $behind++ } + 'edited' { $editedCount++; Write-Host "edited: $($p.Rel)" } + } + } + } + Write-Host "$behind files behind the source, $editedCount edited by you. run the installer to update the ones you did not edit." + exit 0 } -function Same($a, $b) { - if (-not (Test-Path $b)) { return $false } - $ha = Get-ChildItem $a -Recurse -File | ForEach-Object { (Get-FileHash $_.FullName).Hash } | Sort-Object - $hb = Get-ChildItem $b -Recurse -File | ForEach-Object { (Get-FileHash $_.FullName).Hash } | Sort-Object - return (($ha -join ',') -eq ($hb -join ',')) + +# ---- uninstall: moves, never deletes +if ($Uninstall) { + if (-not (Test-Path $Manifest)) { Write-Host "nothing to uninstall: there is no $Manifest, so nothing here is tracked as installed."; exit 1 } + $kept = @(); $n = 0 + foreach ($d in @($script:Recorded.Keys)) { + $f = Dest $d + if (-not (Test-Path -LiteralPath $f)) { continue } + if (Linked $d) { $kept += "$d (a link to your own copy)" } + elseif ((Sha $f) -eq $script:Recorded[$d]) { $n++; Move-ToBackup $d } + else { $kept += $d } + } + if (-not $DryRun) { + foreach ($dir in 'skills','tools','hooks') { + $full = Join-Path $Claude $dir + if (-not (Test-Path $full)) { continue } + @(Get-ChildItem $full -Recurse -Directory) + @(Get-Item $full) | Sort-Object { $_.FullName.Length } -Descending | ForEach-Object { + if (-not (Get-ChildItem -LiteralPath $_.FullName -Force)) { Remove-Item -LiteralPath $_.FullName } + } + } + New-Item -ItemType Directory -Force -Path $Backup | Out-Null + $cm = Join-Path $Claude 'CLAUDE.md' + if (Test-Path $cm) { + Copy-Item $cm (Join-Path $Backup 'CLAUDE.md') -Force + $keep = @(Read-Lines $cm | Where-Object { $_ -ne '@RULES.md' -and $_ -ne '@RULES.local.md' }) + if (@($keep | Where-Object { $_.Trim() }).Count) { [IO.File]::WriteAllText($cm, (($keep -join "`n") + "`n")) } else { Remove-Item -LiteralPath $cm } + } + Move-Item -LiteralPath $Manifest -Destination (Join-Path $Backup 'workflow-manifest') -Force + } + Write-Host "" + if ($DryRun) { Write-Host "would move $n files to workflow-backups\ and take the two import lines out of CLAUDE.md. nothing changed." } + else { Write-Host "uninstalled. the $n files it moved are in $Backup" } + foreach ($k in $kept) { Write-Host "kept, you edited it: $k" } + Write-Host "left alone: RULES.local.md (yours), the ask list in settings.json, skills/pstack/models.md, ~\vault, the pstack plugin (claude plugin uninstall pstack@open-pstack)." + exit 0 } -$Pstack = $WithPstack -or ((-not $Yes) -and (Ask 'install pstack, the plugin cook runs on (recommended)?')) -$Brain = $WithBrain -or ((-not $Yes) -and (Ask 'install the brain (a notes vault at ~\vault, /brain and /dream)?')) -$Ignore = $Gitignore -or ((-not $Yes) -and (Ask 'add the per repo notes files (.claude/CLAUDE.md, log.md, tbd.md, plans/ ...) to your global gitignore?')) +# ---- install or update +$Pstack = Opt $WithPstack 'install pstack, the plugin cook runs on (recommended)?' +$Brain = Opt $WithBrain 'install the brain (a notes vault at ~\vault, /brain and /dream)?' +$Perms = Opt $WithPermissions 'make claude code ask before every push, merge, pr, release and deploy command (recommended)?' +$Ignore = Opt $Gitignore 'add the per repo notes files (.claude/CLAUDE.md, log.md, tbd.md, plans/ ...) to your global gitignore?' + +if (-not $DryRun) { New-Item -ItemType Directory -Force -Path (Join-Path $Claude 'skills'), (Join-Path $Claude 'tools') | Out-Null } -Do-It "create $Claude\skills and tools" { New-Item -ItemType Directory -Force -Path (Join-Path $Claude 'skills'), (Join-Path $Claude 'tools') | Out-Null } +# 0. older versions left .bak- copies inside skills\, where they can load as a second skill. move them out +foreach ($n in $Ours) { + Get-ChildItem (Join-Path $Claude 'skills') -Filter "$n.bak-*" -ErrorAction SilentlyContinue | ForEach-Object { + Move-ToBackup "skills/$($_.Name)"; $script:Moved += "skills/$($_.Name) (an old backup)" + } +} +Get-ChildItem $Claude -Filter 'RULES.md.bak-*' -File -ErrorAction SilentlyContinue | ForEach-Object { + Move-ToBackup $_.Name; $script:Moved += "$($_.Name) (an old backup)" +} -# 1. rules -$rules = Join-Path $Claude 'RULES.md' -if (-not (Same (Join-Path $Src 'rules\RULES.md') $rules)) { - if (Test-Path $rules) { Do-It "back up $rules" { Copy-Item $rules "$rules.bak-$Stamp" } } - Do-It "copy RULES.md to $rules" { Copy-Item (Join-Path $Src 'rules\RULES.md') $rules -Force } - $Did += 'RULES.md' +# 1. rules. yours to read, not to edit: what is personal goes in RULES.local.md +Install-Group 'RULES.md' (Join-Path $Src 'rules/RULES.md') 'RULES.md' +if (-not (Test-Path (Dest 'RULES.local.md'))) { + if ($DryRun) { Write-Host 'would: create RULES.local.md' } else { Copy-Item (Join-Path $Src 'setup/RULES.local.md') (Dest 'RULES.local.md') } + $script:Did += 'RULES.local.md (yours from now on)' } -# 2. the import line, appended +# 2. the import lines, appended, never replacing anything $cm = Join-Path $Claude 'CLAUDE.md' -if (-not (Test-Path $cm) -or -not (Select-String -Path $cm -SimpleMatch -Pattern '@RULES.md' -Quiet)) { - # a fresh file gets the line alone, an existing one gets it on a new line - $lead = if ((Test-Path $cm) -and (Get-Item $cm).Length -gt 0) { "`r`n" } else { '' } - Do-It "append @RULES.md to $cm" { Add-Content -Path $cm -Value "$lead@RULES.md" } - $Did += 'CLAUDE.md: @RULES.md' +foreach ($line in '@RULES.md', '@RULES.local.md') { + $has = @(Read-Lines $cm | Where-Object { $_ -eq $line }).Count -gt 0 + if ($has) { continue } + if ($DryRun) { Write-Host "would: append '$line' to $cm" } + else { + # a fresh file gets the line alone, an existing one gets it after a blank line + $old = if (Test-Path $cm) { [IO.File]::ReadAllText($cm) } else { '' } + if ($old.Length -gt 0 -and -not $old.EndsWith("`n")) { $old += "`n" } + $lead = if ($old.Length -gt 0) { "`n" } else { '' } + [IO.File]::WriteAllText($cm, "$old$lead$line`n") + } + $script:Did += "CLAUDE.md: $line" } # 3. skills -Get-ChildItem (Join-Path $Src 'skills') -Directory | ForEach-Object { +Get-ChildItem (Join-Path $Src 'skills') -Directory | Sort-Object Name | ForEach-Object { $name = $_.Name - if (($name -eq 'brain' -or $name -eq 'dream') -and -not $Brain) { return } - $dest = Join-Path $Claude "skills\$name" - if (Test-Path $dest) { - if (Same $_.FullName $dest) { return } - if ($Force -or ((-not $Yes) -and (Ask "skills\$name already exists and differs. replace it (old copy kept)?"))) { - Do-It "move $dest aside" { Move-Item $dest "$dest.bak-$Stamp" } - } else { $script:Skipped += "skills\$name (exists, use -Force)"; return } - } - $from = $_.FullName - Do-It "copy skills\$name to $dest" { Copy-Item $from $dest -Recurse } - $script:Did += "skills\$name" + if (($name -eq 'brain' -or $name -eq 'dream') -and -not $Brain -and -not (Test-Path (Dest "skills/$name"))) { return } + Install-Group "skills/$name" $_.FullName "skills/$name" } # 4. the size sweep probe, its runner, the brand check, the ref reader and its gate, and the recorder foreach ($t in 'responsive-probe.js','probe-test.mjs','brand-check.mjs','ref-read.mjs','ref-check.mjs','record.mjs') { - $to = Join-Path $Claude "tools\$t" - $from = Join-Path $Src "tools\$t" - if (-not (Same $from $to)) { - Do-It "copy $t to $to" { Copy-Item $from $to -Force } - $Did += "tools\$t" - } + Install-Group "tools/$t" (Join-Path $Src "tools/$t") "tools/$t" } # 5. optional: keep the per repo notes files out of every repo. exact paths, never all of .claude/ $Notes = '.claude/CLAUDE.md','.claude/log.md','.claude/tbd.md','.claude/taste.md','.claude/brand.md','.claude/plans/','.claude/research/','.claude/sql/','.claude/run/','.claude/videos/' if ($Ignore -and (Get-Command git -ErrorAction SilentlyContinue)) { $gi = git config --global core.excludesFile - if (-not $gi) { $gi = Join-Path $HOME '.gitignore_global'; Do-It "set core.excludesFile" { git config --global core.excludesFile $gi } } - $gi = $gi -replace '^~', $HOME - $have = if (Test-Path $gi) { Get-Content $gi } else { @() } - $missing = $Notes | Where-Object { $have -notcontains $_ } - if ($missing) { Do-It "append notes files to $gi" { Add-Content -Path $gi -Value $missing }; $Did += 'global gitignore: notes files' } + if (-not $gi) { + $gi = Join-Path $Root '.gitignore_global' + if ($DryRun) { Write-Host 'would: set core.excludesFile' } else { git config --global core.excludesFile $gi } + } + $gi = $gi -replace '^~', $Root + $have = Read-Lines $gi + $missing = @($Notes | Where-Object { $have -notcontains $_ }) + if ($missing.Count) { + if ($DryRun) { Write-Host "would: append notes files to $gi" } else { $old = if (Test-Path $gi) { [IO.File]::ReadAllText($gi) } else { '' }; $lead = if ($old.Length -gt 0 -and -not $old.EndsWith("`n")) { "`n" } else { '' }; [IO.File]::AppendAllText($gi, ($lead + ($missing -join "`n") + "`n")) } + $script:Did += 'global gitignore: notes files' + } } -# 6. pstack +# 6. optional: ask before anything leaves. merged into settings.json, the old file goes to workflow-backups\ +if ($Perms) { Settings-Merge 'settings.json: ask before push, merge, pr, release, deploy' (Join-Path $Src 'setup/permissions.json') } + +# 7. the node_modules hook is a bash script +if ($WithHooks) { $script:Skipped += 'the node_modules hook: a bash script, not installed on windows. use wsl and install.sh for it' } + +# 8. optional: pstack +if ($Pstack -or (Test-Path (Dest 'skills/pstack'))) { + foreach ($f in 'install.sh','README.md') { Install-Group "skills/pstack/$f" (Join-Path $Src "pstack/$f") "skills/pstack/$f" } + # models.md holds your model names: created once, never written again + if (-not (Test-Path (Dest 'skills/pstack/models.md'))) { + if (-not $DryRun) { + New-Item -ItemType Directory -Force -Path (Dest 'skills/pstack') | Out-Null + Copy-Item (Join-Path $Src 'pstack/models.md') (Dest 'skills/pstack/models.md') + } + $script:Did += 'skills/pstack/models.md (yours from now on)' + } +} if ($Pstack) { - Do-It "copy pstack" { Copy-Item (Join-Path $Src 'pstack') (Join-Path $Claude 'skills') -Recurse -Force } if (Get-Command claude -ErrorAction SilentlyContinue) { - Do-It "install the pstack plugin" { - $tag = (Select-String -Path (Join-Path $Src 'pstack\install.sh') -Pattern '^TAG="(.+)"').Matches[0].Groups[1].Value + if ($DryRun) { Write-Host 'would: install the pstack plugin' } + else { + $tag = (Select-String -Path (Join-Path $Src 'pstack/install.sh') -Pattern '^TAG="(.+)"').Matches[0].Groups[1].Value + # an install from an older pin keeps its marketplace entry: drop it, add it at this tag + if ((claude plugin marketplace list 2>$null | Out-String) -match 'open-pstack') { claude plugin marketplace remove open-pstack } claude plugin marketplace add "https://github.com/ericlitman/open-pstack.git#$tag" claude plugin install pstack@open-pstack - if (-not (Select-String -Path $cm -SimpleMatch -Pattern '@skills/pstack/models.md' -Quiet)) { Add-Content -Path $cm -Value "`r`n@skills/pstack/models.md" } + claude plugin update pstack@open-pstack + if (@(Read-Lines $cm | Where-Object { $_ -eq '@skills/pstack/models.md' }).Count -eq 0) { [IO.File]::AppendAllText($cm, "`n@skills/pstack/models.md`n") } } - $Did += 'pstack' - } else { $Skipped += 'pstack plugin: no claude cli on PATH' } + $script:Did += 'the pstack plugin' + } else { $script:Skipped += 'pstack plugin: no claude cli on PATH' } } -# 7. the brain +# 9. the brain if ($Brain) { - $vault = Join-Path $HOME 'vault' - if (Test-Path $vault) { $Skipped += '~\vault exists, left as is' } - else { Do-It "create ~\vault" { Copy-Item (Join-Path $Src 'brain-template') $vault -Recurse }; $Did += '~\vault' } + $vault = Join-Path $Root 'vault' + if (Test-Path $vault) { $script:Skipped += '~\vault exists, left as is' } + else { + if ($DryRun) { Write-Host 'would: create ~\vault' } else { Copy-Item (Join-Path $Src 'brain-template') $vault -Recurse } + $script:Did += '~\vault' + } } +Write-Manifest + Write-Host "" -$label = if ($DryRun) { 'would install: ' } else { 'installed: ' } -Write-Host ($label + $(if ($Did.Count) { $Did -join ', ' } else { 'nothing new' })) -if ($Skipped.Count) { Write-Host ("skipped: " + ($Skipped -join '; ')) } +$label = if ($DryRun) { 'would install or update: ' } else { 'installed or updated: ' } +Write-Host ($label + $(if ($script:Did.Count) { $script:Did -join ' ' } else { 'nothing, all up to date' })) +foreach ($s in $script:Skipped) { Write-Host "skipped: $s" } +if ($script:Moved.Count) { + if ($DryRun) { Write-Host ('would move to workflow-backups\: ' + ($script:Moved -join ' ')) } else { Write-Host ("moved to ${Backup}: " + ($script:Moved -join ' ')) } +} +if ($script:Had -and $script:Had -ne $Version) { Write-Host "version: $($script:Had) to $Version. what changed: $(Join-Path $Src 'CHANGELOG.md')" } else { Write-Host "version: $Version" } Write-Host "next: restart claude code, then type /cook ." diff --git a/install.sh b/install.sh index ab585f8..9bfd80c 100644 --- a/install.sh +++ b/install.sh @@ -1,32 +1,44 @@ #!/usr/bin/env bash -# installs the workflow into ~/.claude. mac and linux (and wsl). windows: install.ps1. +# installs the workflow into ~/.claude, and updates it. mac and linux (and wsl). windows: install.ps1. # # bash install.sh asks before anything optional -# bash install.sh --yes defaults, no questions: rules, skills, the probe and brand check. nothing optional +# bash install.sh --yes defaults, no questions: rules, skills, the tools. nothing optional # --with-pstack also install the pstack plugin (needs the claude cli) # --with-brain also install /brain, /dream and create ~/vault from brain-template/ +# --with-permissions also make claude code ask before every push, merge, pr, release and deploy command +# --with-hooks also add the hook that installs missing node_modules (needs jq) # --gitignore also add the notes files to your global gitignore # an agent (no terminal) gets no prompts: pass every --with-*/--no-* flag you want. -# --force replace skills that already exist (old copy kept as .bak-) +# --force replace files you edited too (your copy goes to ~/.claude/workflow-backups/) # --dry-run print what would happen, change nothing +# --status what is installed, what is behind, what you edited. changes nothing +# --uninstall move every file it installed and you did not edit to workflow-backups/ # -# safe to run again. it never deletes, never touches git history, never pushes. +# run it again to update. a file you did not touch is replaced, a file you edited is kept and named. +# your own settings live in ~/.claude/RULES.local.md, which is created once and never written again. +# it never deletes (old copies are moved to workflow-backups/), never touches git history, never pushes. set -euo pipefail REPO_URL="${WORKFLOW_REPO:-https://github.com/gntrs/workflow.git}" -YES=0 FORCE=0 DRY=0 PSTACK=ask BRAIN=ask GITIGNORE=ask +YES=0 FORCE=0 DRY=0 MODE=install PSTACK=ask BRAIN=ask GITIGNORE=ask PERMS=ask HOOKS=ask for a in "$@"; do case "$a" in --yes|-y) YES=1 ;; --force) FORCE=1 ;; --dry-run) DRY=1 ;; + --status) MODE=status ;; + --uninstall) MODE=uninstall ;; --with-pstack) PSTACK=1 ;; --no-pstack) PSTACK=0 ;; --with-brain) BRAIN=1 ;; --no-brain) BRAIN=0 ;; + --with-permissions) PERMS=1 ;; + --no-permissions) PERMS=0 ;; + --with-hooks) HOOKS=1 ;; + --no-hooks) HOOKS=0 ;; --gitignore) GITIGNORE=1 ;; --no-gitignore) GITIGNORE=0 ;; - -h|--help) sed -n 2,12p "$0"; exit 0 ;; + -h|--help) sed -n 2,20p "$0"; exit 0 ;; *) echo "unknown flag: $a"; exit 2 ;; esac done @@ -39,13 +51,30 @@ if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then fi if [ -z "$SRC" ] || [ ! -f "$SRC/rules/RULES.md" ] || [ ! -f "$SRC/SETUP.md" ]; then SRC="$HOME/.claude/workflow" - if [ -d "$SRC/.git" ]; then git -C "$SRC" pull -q --ff-only || true + if [ -d "$SRC/.git" ]; then git -C "$SRC" pull -q --ff-only || echo "could not update $SRC (git pull failed), using the copy that is there" else git clone -q --depth 1 "$REPO_URL" "$SRC"; fi fi +# run from the clone the one line install made: get the newest version first, then start over from it. +# a clone anywhere else (a fork, a checkout you are working in) is used as it is +MAIN_VERSION="" +if [ "$SRC" = "$HOME/.claude/workflow" ] && [ -d "$SRC/.git" ] && [ -z "${WORKFLOW_PULLED:-}" ]; then + if [ "$MODE" = install ] && [ $DRY -eq 0 ]; then + if git -C "$SRC" pull -q --ff-only; then WORKFLOW_PULLED=1 exec bash "$SRC/install.sh" "$@"; fi + echo "could not update $SRC (git pull failed), using the copy that is there" + elif git -C "$SRC" fetch -q 2>/dev/null; then + MAIN_VERSION="$(git -C "$SRC" show '@{u}:VERSION' 2>/dev/null || true)" + fi +fi + CLAUDE_DIR="$HOME/.claude" +MANIFEST="$CLAUDE_DIR/workflow-manifest" STAMP="$(date +%Y%m%d-%H%M%S)" -did=() skipped=() +BACKUP="$CLAUDE_DIR/workflow-backups/$STAMP" +VERSION="$(cat "$SRC/VERSION" 2>/dev/null || echo unknown)" +OURS="bbq brain cook deep design dream initiate playbook review ship status write" +did=() skipped=() moved=() +NEWMAN="$(mktemp)"; trap 'rm -f "$NEWMAN"' EXIT run() { if [ $DRY -eq 1 ]; then echo "would: $*"; else "$@"; fi; } ask() { # ask "question" -> 0 for yes @@ -53,48 +82,215 @@ ask() { # ask "question" -> 0 for yes [ -t 0 ] || return 1 read -r -p "$1 [y/N] " r; [ "$r" = y ] || [ "$r" = Y ] } -same() { diff -rq "$1" "$2" >/dev/null 2>&1; } +opt() { # opt CURRENT "question" -> 1 or 0. --yes never turns an optional part on + if [ "$1" != ask ]; then echo "$1"; elif [ $YES -eq 0 ] && ask "$2"; then echo 1; else echo 0; fi +} +sha() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d' ' -f1; } +recorded() { [ -f "$MANIFEST" ] || return 0; awk -v p="$1" '$2==p{print $1; exit}' "$MANIFEST"; } +known() { [ -f "$SRC/setup/known-hashes.txt" ] && grep -qxF "$1" "$SRC/setup/known-hashes.txt"; } +installed_version() { [ -f "$MANIFEST" ] && sed -n 's/^# workflow //p' "$MANIFEST" | head -1; } +# state SRCFILE DESTFILE REL -> new | same | clean (yours matches a copy we shipped) | edited +state() { + [ -e "$2" ] || { echo new; return; } + local h; h="$(sha "$2")" + if [ "$h" = "$(sha "$1")" ]; then echo same + elif [ "$h" = "$(recorded "$3")" ] || known "$h"; then echo clean + else echo edited; fi +} +linked() { # linked REL: true when REL or a folder above it inside ~/.claude is a symlink (your own copy, kept elsewhere) + local p="$CLAUDE_DIR" part rest="$1" + while [ -n "$rest" ]; do + part="${rest%%/*}"; p="$p/$part" + [ -L "$p" ] && return 0 + case "$rest" in */*) rest="${rest#*/}" ;; *) rest="" ;; esac + done + return 1 +} +backup() { # backup REL: move ~/.claude/REL into this run's backup folder + if [ $DRY -eq 1 ]; then return 0; fi + mkdir -p "$BACKUP/$(dirname "$1")"; mv "$CLAUDE_DIR/$1" "$BACKUP/$1" +} +pairs_of() { # pairs_of SRC REL -> lines of "srcfile|rel" for a file or every file in a folder + if [ -d "$1" ]; then (cd "$1" && find . -type f ! -name .DS_Store | sed 's|^\./||' | LC_ALL=C sort) | while IFS= read -r f; do echo "$1/$f|$2/$f"; done + else echo "$1|$2"; fi +} +# install_group LABEL SRC REL: one skill folder or one file, all or nothing. +# a group with a file you edited is left alone and named, unless --force or you say yes. +install_group() { + local label="$1" src="$2" rel="$3" pairs s d st edited="" changed=0 replace=0 + if linked "$rel"; then skipped+=("$label: a link to your own copy, left alone"); return 0; fi + pairs="$(pairs_of "$src" "$rel")" + while IFS='|' read -r s d; do + [ "$(state "$s" "$CLAUDE_DIR/$d" "$d")" = edited ] && edited="$edited ${d#"$rel"/}" + done <<< "$pairs" + if [ -n "$edited" ]; then + if [ $FORCE -eq 1 ] || { [ $YES -eq 0 ] && ask "$label has your edits (${edited# }). replace it? your copy goes to workflow-backups/"; }; then replace=1 + else skipped+=("$label: you edited${edited}. kept yours. --force replaces it, your copy goes to workflow-backups/"); return 0; fi + fi + while IFS='|' read -r s d; do + st="$(state "$s" "$CLAUDE_DIR/$d" "$d")" + case "$st" in + same) ;; + edited) backup "$d"; moved+=("$d"); changed=1 ;; + *) changed=1 ;; + esac + if [ "$st" != same ] && [ $DRY -eq 0 ]; then mkdir -p "$(dirname "$CLAUDE_DIR/$d")"; cp "$s" "$CLAUDE_DIR/$d"; fi + echo "$(sha "$s") $d" >> "$NEWMAN" + done <<< "$pairs" + # a file we installed before that is gone from the source: move it out if you did not edit it + if [ -d "$src" ] && [ -f "$MANIFEST" ]; then + while read -r h d; do + case "$d" in "$rel"/*) ;; *) continue ;; esac + grep -qF "|$d" <<< "$pairs" && continue + [ -f "$CLAUDE_DIR/$d" ] && [ "$(sha "$CLAUDE_DIR/$d")" = "$h" ] || continue + backup "$d"; moved+=("$d (gone from the source)"); changed=1 + done < <(grep -v '^#' "$MANIFEST") + fi + [ $changed -eq 1 ] && did+=("$label") + return 0 +} +write_manifest() { + [ $DRY -eq 1 ] && return 0 + local out="$MANIFEST.tmp" + echo "# workflow $VERSION" > "$out" + echo "# files this installer put in ~/.claude and their sha256. it uses this to tell your edits from its own old copies. do not edit." >> "$out" + cat "$NEWMAN" >> "$out" + if [ -f "$MANIFEST" ]; then + while read -r h d; do + awk -v p="$d" '$2==p{f=1} END{exit !f}' "$NEWMAN" && continue + [ -f "$CLAUDE_DIR/$d" ] && echo "$h $d" >> "$out" + done < <(grep -v '^#' "$MANIFEST") + fi + mv "$out" "$MANIFEST" +} +groups() { # every "src|rel" the installer keeps up to date and that is installed here + local dir name f + echo "$SRC/rules/RULES.md|RULES.md" + for dir in "$SRC"/skills/*/; do + name="$(basename "$dir")"; [ -d "$CLAUDE_DIR/skills/$name" ] && pairs_of "${dir%/}" "skills/$name" + done + for f in responsive-probe.js probe-test.mjs brand-check.mjs ref-read.mjs ref-check.mjs record.mjs; do echo "$SRC/tools/$f|tools/$f"; done + if [ -d "$CLAUDE_DIR/skills/pstack" ]; then for f in install.sh README.md; do echo "$SRC/pstack/$f|skills/pstack/$f"; done; fi + [ -e "$CLAUDE_DIR/hooks/ensure-node-modules.sh" ] && echo "$SRC/setup/hooks/ensure-node-modules.sh|hooks/ensure-node-modules.sh" + return 0 +} +settings_merge() { # settings_merge LABEL FRAGMENT [KEY=VALUE] + local label="$1" frag="$2" set="${3:-}" settings="$CLAUDE_DIR/settings.json" need + if ! command -v node >/dev/null 2>&1; then skipped+=("$label: needs node to merge settings.json. add the block in $frag by hand"); return 0; fi + need="$(node "$SRC/setup/merge-settings.mjs" "$settings" "$frag" --check ${set:+--set "$set"} 2>&1)" || { skipped+=("$label: $need"); return 0; } + [ "$need" = same ] && return 0 + if [ $DRY -eq 0 ]; then + if [ -f "$settings" ]; then mkdir -p "$BACKUP"; cp "$settings" "$BACKUP/settings.json"; fi + node "$SRC/setup/merge-settings.mjs" "$settings" "$frag" ${set:+--set "$set"} >/dev/null + fi + did+=("$label") +} + +# ---- status: read only +if [ "$MODE" = status ]; then + have="$(installed_version || true)" + echo "installed: ${have:-none recorded (never installed, or installed before updates were tracked)}" + echo "source: $VERSION, $SRC" + [ -n "$MAIN_VERSION" ] && echo "main: $MAIN_VERSION$([ "$MAIN_VERSION" = "$VERSION" ] || echo ", newer than the source here. the installer pulls it")" + behind=0 edited=0 + if [ -d "$CLAUDE_DIR" ]; then + while IFS='|' read -r s d; do + [ -e "$CLAUDE_DIR/$d" ] || { case "$d" in skills/*) behind=$((behind+1)) ;; esac; continue; } + linked "$d" && continue + case "$(state "$s" "$CLAUDE_DIR/$d" "$d")" in + clean) behind=$((behind+1)) ;; + edited) edited=$((edited+1)); echo "edited: $d" ;; + esac + done <<< "$(groups)" + fi + echo "$behind files behind the source, $edited edited by you. run the installer to update the ones you did not edit." + exit 0 +fi + +# ---- uninstall: moves, never deletes +if [ "$MODE" = uninstall ]; then + [ -f "$MANIFEST" ] || { echo "nothing to uninstall: there is no $MANIFEST, so nothing here is tracked as installed."; exit 1; } + kept=() n=0 + while read -r h d; do + [ -f "$CLAUDE_DIR/$d" ] || continue + if linked "$d"; then kept+=("$d (a link to your own copy)") + elif [ "$(sha "$CLAUDE_DIR/$d")" = "$h" ]; then n=$((n+1)); backup "$d" + else kept+=("$d"); fi + done < <(grep -v '^#' "$MANIFEST") + hook="$CLAUDE_DIR/hooks/ensure-node-modules.sh" + if [ $DRY -eq 0 ]; then + # the hook file is gone: take its entry out of settings.json too, or every command would call a missing file + if [ ! -e "$hook" ] && [ -f "$CLAUDE_DIR/settings.json" ] && command -v node >/dev/null 2>&1 \ + && [ "$(node "$SRC/setup/merge-settings.mjs" "$CLAUDE_DIR/settings.json" "$SRC/setup/hooks.json" --remove --check --set "__HOOK__=$hook" 2>/dev/null)" = changed ]; then + mkdir -p "$BACKUP"; cp "$CLAUDE_DIR/settings.json" "$BACKUP/settings.json" + node "$SRC/setup/merge-settings.mjs" "$CLAUDE_DIR/settings.json" "$SRC/setup/hooks.json" --remove --set "__HOOK__=$hook" >/dev/null + fi + for dir in skills tools hooks; do + [ -d "$CLAUDE_DIR/$dir" ] && find "$CLAUDE_DIR/$dir" -depth -type d -empty -exec rmdir {} \; 2>/dev/null || true + done + if [ -f "$CLAUDE_DIR/CLAUDE.md" ]; then + mkdir -p "$BACKUP"; cp "$CLAUDE_DIR/CLAUDE.md" "$BACKUP/CLAUDE.md" + grep -vxF -e "@RULES.md" -e "@RULES.local.md" "$BACKUP/CLAUDE.md" > "$CLAUDE_DIR/CLAUDE.md" || true + grep -q '[^[:space:]]' "$CLAUDE_DIR/CLAUDE.md" || rm "$CLAUDE_DIR/CLAUDE.md" + fi + mkdir -p "$BACKUP"; mv "$MANIFEST" "$BACKUP/workflow-manifest" + fi + echo + if [ $DRY -eq 1 ]; then echo "would move $n files to workflow-backups/ and take the two import lines out of CLAUDE.md. nothing changed." + else echo "uninstalled. the $n files it moved are in $BACKUP"; fi + [ ${#kept[@]} -gt 0 ] && printf 'kept, you edited it: %s\n' "${kept[@]}" + echo "left alone: RULES.local.md (yours), the ask list in settings.json, skills/pstack/models.md, ~/vault, the pstack plugin (claude plugin uninstall pstack@open-pstack)." + exit 0 +fi -[ "$PSTACK" = ask ] && { if [ $YES -eq 0 ] && ask "install pstack, the plugin cook runs on (recommended)?"; then PSTACK=1; else PSTACK=0; fi; } -[ "$BRAIN" = ask ] && { if [ $YES -eq 0 ] && ask "install the brain (a notes vault at ~/vault, /brain and /dream)?"; then BRAIN=1; else BRAIN=0; fi; } -[ "$GITIGNORE" = ask ] && { if [ $YES -eq 0 ] && ask "add the per repo notes files (.claude/CLAUDE.md, log.md, tbd.md, plans/ ...) to your global gitignore?"; then GITIGNORE=1; else GITIGNORE=0; fi; } +# ---- install or update +PSTACK="$(opt "$PSTACK" "install pstack, the plugin cook runs on (recommended)?")" +BRAIN="$(opt "$BRAIN" "install the brain (a notes vault at ~/vault, /brain and /dream)?")" +PERMS="$(opt "$PERMS" "make claude code ask before every push, merge, pr, release and deploy command (recommended)?")" +HOOKS="$(opt "$HOOKS" "add the hook that installs missing node_modules before a command needs them?")" +GITIGNORE="$(opt "$GITIGNORE" "add the per repo notes files (.claude/CLAUDE.md, log.md, tbd.md, plans/ ...) to your global gitignore?")" run mkdir -p "$CLAUDE_DIR/skills" "$CLAUDE_DIR/tools" -# 1. rules -if [ -f "$CLAUDE_DIR/RULES.md" ] && ! same "$SRC/rules/RULES.md" "$CLAUDE_DIR/RULES.md"; then - run cp "$CLAUDE_DIR/RULES.md" "$CLAUDE_DIR/RULES.md.bak-$STAMP" +# 0. older versions left .bak- copies inside skills/, where they can load as a second skill. move them out +for n in $OURS; do + for old in "$CLAUDE_DIR/skills/$n".bak-*; do + [ -e "$old" ] || continue + backup "skills/$(basename "$old")"; moved+=("skills/$(basename "$old") (an old backup)") + done +done +for old in "$CLAUDE_DIR"/RULES.md.bak-*; do + [ -e "$old" ] || continue + backup "$(basename "$old")"; moved+=("$(basename "$old") (an old backup)") +done + +# 1. rules. yours to read, not to edit: what is personal goes in RULES.local.md +install_group "RULES.md" "$SRC/rules/RULES.md" "RULES.md" +if [ ! -e "$CLAUDE_DIR/RULES.local.md" ]; then + run cp "$SRC/setup/RULES.local.md" "$CLAUDE_DIR/RULES.local.md"; did+=("RULES.local.md (yours from now on)") fi -same "$SRC/rules/RULES.md" "$CLAUDE_DIR/RULES.md" || { run cp "$SRC/rules/RULES.md" "$CLAUDE_DIR/RULES.md"; did+=("RULES.md"); } -# 2. the import line, appended, never replacing anything -touch_claude() { [ -f "$CLAUDE_DIR/CLAUDE.md" ] || run touch "$CLAUDE_DIR/CLAUDE.md"; } +# 2. the import lines, appended, never replacing anything add_line() { - touch_claude + [ -f "$CLAUDE_DIR/CLAUDE.md" ] || run touch "$CLAUDE_DIR/CLAUDE.md" if ! grep -qxF "$1" "$CLAUDE_DIR/CLAUDE.md" 2>/dev/null; then if [ $DRY -eq 1 ]; then echo "would: append '$1' to $CLAUDE_DIR/CLAUDE.md"; elif [ -s "$CLAUDE_DIR/CLAUDE.md" ]; then printf '\n%s\n' "$1" >> "$CLAUDE_DIR/CLAUDE.md"; else printf '%s\n' "$1" > "$CLAUDE_DIR/CLAUDE.md"; fi did+=("CLAUDE.md: $1") fi } add_line "@RULES.md" +add_line "@RULES.local.md" # 3. skills for dir in "$SRC"/skills/*/; do name="$(basename "$dir")" - case "$name" in brain|dream) [ "$BRAIN" = 1 ] || continue ;; esac - dest="$CLAUDE_DIR/skills/$name" - if [ -e "$dest" ]; then - if same "$dir" "$dest"; then continue; fi - if [ $FORCE -eq 1 ] || { [ $YES -eq 0 ] && ask "skills/$name already exists and differs. replace it (old copy kept)?"; }; then - run mv "$dest" "$dest.bak-$STAMP" - else skipped+=("skills/$name (exists, use --force)"); continue; fi - fi - run cp -R "$dir" "$dest"; did+=("skills/$name") + case "$name" in brain|dream) [ "$BRAIN" = 1 ] || [ -d "$CLAUDE_DIR/skills/$name" ] || continue ;; esac + install_group "skills/$name" "${dir%/}" "skills/$name" done # 4. the size sweep probe, its runner, the brand check, the ref reader and its gate, and the recorder for t in responsive-probe.js probe-test.mjs brand-check.mjs ref-read.mjs ref-check.mjs record.mjs; do - same "$SRC/tools/$t" "$CLAUDE_DIR/tools/$t" || { run cp "$SRC/tools/$t" "$CLAUDE_DIR/tools/"; did+=("tools/$t"); } + install_group "tools/$t" "$SRC/tools/$t" "tools/$t" done # 5. optional: keep the per repo notes files out of every repo. exact paths, never all of .claude/ @@ -112,20 +308,48 @@ if [ "$GITIGNORE" = 1 ] && command -v git >/dev/null; then [ "${added:-0}" = 1 ] && did+=("global gitignore: notes files") fi -# 6. optional: pstack +# 6. optional: ask before anything leaves. merged into settings.json, the old file goes to workflow-backups/ +[ "$PERMS" = 1 ] && settings_merge "settings.json: ask before push, merge, pr, release, deploy" "$SRC/setup/permissions.json" + +# 7. optional: the node_modules hook +if [ "$HOOKS" = 1 ]; then + if ! command -v jq >/dev/null 2>&1; then skipped+=("the node_modules hook: needs jq on PATH") + else + install_group "hooks/ensure-node-modules.sh" "$SRC/setup/hooks/ensure-node-modules.sh" "hooks/ensure-node-modules.sh" + [ $DRY -eq 1 ] || chmod +x "$CLAUDE_DIR/hooks/ensure-node-modules.sh" 2>/dev/null || true + settings_merge "settings.json: the node_modules hook" "$SRC/setup/hooks.json" "__HOOK__=$CLAUDE_DIR/hooks/ensure-node-modules.sh" + fi +fi + +# 8. optional: pstack +if [ "$PSTACK" = 1 ] || [ -d "$CLAUDE_DIR/skills/pstack" ]; then + for f in install.sh README.md; do + install_group "skills/pstack/$f" "$SRC/pstack/$f" "skills/pstack/$f" + done + # models.md holds your model names: created once, never written again + if [ ! -e "$CLAUDE_DIR/skills/pstack/models.md" ]; then + run cp "$SRC/pstack/models.md" "$CLAUDE_DIR/skills/pstack/models.md"; did+=("skills/pstack/models.md (yours from now on)") + fi +fi if [ "$PSTACK" = 1 ]; then - same "$SRC/pstack" "$CLAUDE_DIR/skills/pstack" || { run mkdir -p "$CLAUDE_DIR/skills/pstack"; run cp -R "$SRC/pstack/." "$CLAUDE_DIR/skills/pstack/"; did+=("skills/pstack"); } if command -v claude >/dev/null; then run bash "$CLAUDE_DIR/skills/pstack/install.sh" else skipped+=("pstack plugin: no claude cli on PATH, run ~/.claude/skills/pstack/install.sh later"); fi fi -# 7. optional: the brain +# 9. optional: the brain if [ "$BRAIN" = 1 ]; then if [ -e "$HOME/vault" ]; then skipped+=("~/vault exists, left as is") else run cp -R "$SRC/brain-template" "$HOME/vault"; did+=("~/vault"); fi fi +had="$(installed_version || true)" +write_manifest + echo -if [ $DRY -eq 1 ]; then echo "would install: ${did[*]:-nothing new}"; else echo "installed: ${did[*]:-nothing new}"; fi +if [ $DRY -eq 1 ]; then echo "would install or update: ${did[*]:-nothing, all up to date}"; else echo "installed or updated: ${did[*]:-nothing, all up to date}"; fi [ ${#skipped[@]} -gt 0 ] && printf 'skipped: %s\n' "${skipped[@]}" +if [ ${#moved[@]} -gt 0 ]; then + if [ $DRY -eq 1 ]; then printf 'would move to workflow-backups/: %s\n' "${moved[@]}"; else printf 'moved to %s: %s\n' "$BACKUP" "${moved[*]}"; fi +fi +if [ -n "$had" ] && [ "$had" != "$VERSION" ]; then echo "version: $had to $VERSION. what changed: $SRC/CHANGELOG.md"; else echo "version: $VERSION"; fi echo "next: restart claude code, then type /cook ." diff --git a/llms.txt b/llms.txt index 3bdf99b..1e74f40 100644 --- a/llms.txt +++ b/llms.txt @@ -1,6 +1,6 @@ # workflow -> a Claude Code workflow: always on rules, skills and an optional plugin layer. /cook sizes any task into quick, build or deep lanes, runs up to 4 agents in parallel, reviews each piece as it lands, and stops for the user's yes before anything leaves the machine. +> a Claude Code workflow: always on rules, skills and an optional plugin layer. /cook sizes any task into quick, build or deep lanes, runs up to 4 agents in parallel, reviews its own work as each piece lands, and stops for the user's yes before anything leaves the machine. to install it for someone: `git clone --depth 1 https://github.com/gntrs/workflow.git ~/.claude/workflow`, then follow SETUP.md. @@ -9,10 +9,13 @@ to install it for someone: `git clone --depth 1 https://github.com/gntrs/workflo - [SETUP.md](SETUP.md): the agent installer. look at the machine, ask once, install into ~/.claude, tailor, prove, hand test - [AGENTS.md](AGENTS.md): for any agent opening this repo - [rules/RULES.md](rules/RULES.md): always on, wins over every skill +- [setup/RULES.local.md](setup/RULES.local.md): the user's own layer, created once at `~/.claude/RULES.local.md`, wins over RULES.md +- [CHANGELOG.md](CHANGELOG.md): what changed per version, and how to move an old tailored install ## skills - [cook](skills/cook/SKILL.md): the entry point for every task, lanes, caps, models, the ending +- [bbq](skills/bbq/SKILL.md): the fast build for a prototype or a hackathon, no questions, a time box, a working demo, a debt list - [deep](skills/deep/SKILL.md): research, plan with an exit predicate, gate, autonomous run, proof - [ship](skills/ship/SKILL.md): pre-flight before anything leaves, commits and pushes only after a yes - [review](skills/review/SKILL.md): one cold reviewer, ship or fix these or redo @@ -33,3 +36,5 @@ to install it for someone: `git clone --depth 1 https://github.com/gntrs/workflo - [tools/ref-check.mjs](tools/ref-check.mjs): fails a brand.md with no read reference or a kit part with nothing behind it - [tools/record.mjs](tools/record.mjs): records a scroll, wheel or drag walk of a page to a video, and checks it moved - [brain-template/](brain-template/HOME.md): the vault skeleton +- [setup/permissions.json](setup/permissions.json): the ask list `--with-permissions` merges into settings.json +- [scripts/test-install.sh](scripts/test-install.sh): the installer's cases, fresh, upgrade, edits, uninstall diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..7e3931e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,63 @@ +{ + "name": "workflow", + "version": "1.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "workflow", + "version": "1.1.0", + "license": "MIT", + "devDependencies": { + "playwright": "1.62.1" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.62.1.tgz", + "integrity": "sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.62.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.62.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.62.1.tgz", + "integrity": "sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..9a9521a --- /dev/null +++ b/package.json @@ -0,0 +1,17 @@ +{ + "name": "workflow", + "version": "1.1.0", + "private": true, + "description": "let him /cook: agent skills, rules and tools for Claude Code", + "license": "MIT", + "type": "module", + "scripts": { + "check": "bash scripts/check.sh", + "test:install": "bash scripts/test-install.sh", + "test:tools": "node tools/brand-check.mjs --self-test && node tools/ref-check.mjs --self-test && node tools/probe-test.mjs --self-test && node tools/ref-read.mjs --self-test && node tools/record.mjs --self-test", + "test": "npm run check && npm run test:install && npm run test:tools" + }, + "devDependencies": { + "playwright": "1.62.1" + } +} diff --git a/pstack/README.md b/pstack/README.md index 6f78af9..d88bf1d 100644 --- a/pstack/README.md +++ b/pstack/README.md @@ -3,10 +3,10 @@ pstack is the engine cook can run on: open-pstack (MIT, `github.com/ericlitman/open-pstack`), a Claude Code plugin with playbooks for features, bug fixes, plans, reviews, arenas and long autonomous runs. it is installed as a plugin, pinned to one tag, never copied here, because a copy would load every skill twice. - `install.sh` installs the pinned plugin and adds `@skills/pstack/models.md` to `~/.claude/CLAUDE.md`. safe to run again. setup copies `models.md` to `~/.claude/skills/pstack/models.md` so that import resolves. -- `models.md` says which model and effort each pstack role uses. pstack's roles only; cook's own agents use cook's table. swap names for whatever your plan has. fable lanes are optional. +- `models.md` says which model and effort each pstack role uses. pstack's roles only; cook's own agents use cook's table. it is yours: the installer creates it once and never writes it again. it ships with every role on `inherit-parent`. a second model family is optional. the rules on top are in `RULES.md`, "pstack runs under these rules, not over them". where they disagree, RULES.md wins. without pstack: cook's build lane is a short plan in chat, the main thread builds, one reviewer subagent reads it. `/deep` runs the same research, plan and run loop by hand, with `/loop` to wake. nothing else changes. -moving the pin: read the new tag's changes, check the playbooks RULES.md overrides (opening-a-pr, shipping, babysit, autopilot), then change `TAG` and rerun. +moving the pin: read the new tag's changes, check the playbooks RULES.md overrides (opening-a-pr, shipping, babysit, autopilot), then change `TAG` and rerun. `install.sh` drops the old marketplace entry and adds it again at the new tag, so an existing install moves too. diff --git a/pstack/install.sh b/pstack/install.sh index c948dc8..a093be7 100755 --- a/pstack/install.sh +++ b/pstack/install.sh @@ -2,10 +2,15 @@ # installs open-pstack (MIT, github.com/ericlitman/open-pstack) as a claude code plugin, pinned to one tag. # optional: every skill in this repo says what it does without pstack. safe to run again. set -euo pipefail -TAG="v1.5.0" +TAG="v1.21.0" command -v claude >/dev/null 2>&1 || { echo "claude cli not found, install Claude Code first" >&2; exit 1; } -claude plugin marketplace add "https://github.com/ericlitman/open-pstack.git#${TAG}" || true +# an install from an older pin keeps its marketplace entry, and add alone would leave it there: drop the entry, add it at this tag +if claude plugin marketplace list 2>/dev/null | grep -q open-pstack; then + claude plugin marketplace remove open-pstack || true +fi +claude plugin marketplace add "https://github.com/ericlitman/open-pstack.git#${TAG}" claude plugin install pstack@open-pstack +claude plugin update pstack@open-pstack || true # setup copies models.md to ~/.claude/skills/pstack/models.md. CLAUDE.md imports it as @skills/pstack/models.md mkdir -p "$HOME/.claude" touch "$HOME/.claude/CLAUDE.md" diff --git a/pstack/models.md b/pstack/models.md index fa1fa2a..a5c102b 100644 --- a/pstack/models.md +++ b/pstack/models.md @@ -1,21 +1,21 @@ # pstack model configuration -provider qualified per role choices for pstack's own roles only. the agents cook spawns itself take their models from cook's table. read the installed pstack provider dispatch reference before dispatching a configured role. every documented role stays present. `inherit-parent` uses the parent model and still counts as one panel lane. +per role choices for pstack's own roles only. the agents cook spawns itself take their models from cook's table. read the installed pstack provider dispatch reference before dispatching a configured role. every documented role stays present. `inherit-parent` uses the parent model and still counts as one panel lane. -fable lanes are optional: a second model family when available, never the only one. on a plan without fable, delete `, claude:fable@max` from each line that has it, or swap in another model you have. never leave a panel with only one model that can run out of credits. setup swaps every name here for what the user's plan has. +this file is yours. the installer creates it once and never writes it again. it ships with every role on `inherit-parent`, which runs whatever model the session runs. to pin a role, write the provider, model and effort your plan has, the same names as `## models` in `~/.claude/RULES.local.md`, for example `claude:@xhigh`. a panel role takes a list, `claude:@xhigh, claude:@max`: a second model family is optional there and never the only lane, so a panel does not stop when one model runs out of credits. -feature, refactoring: claude:opus@xhigh -bug-fix: claude:opus@xhigh -perf-issue: claude:opus@xhigh -hillclimb: claude:opus@xhigh -judgment and prose: claude:opus@xhigh -hardest tasks: claude:opus@xhigh +feature, refactoring: inherit-parent +bug-fix: inherit-parent +perf-issue: inherit-parent +hillclimb: inherit-parent +judgment and prose: inherit-parent +hardest tasks: inherit-parent how explorer: inherit-parent how explainer: inherit-parent why investigators, synthesizer: inherit-parent reflect tooling, judgment, divergent, synthesizer: inherit-parent -arena runners: claude:opus@xhigh, claude:fable@max -arena cross-judge pool: claude:opus@xhigh, claude:fable@max -swarm workers: claude:opus@xhigh -architect runners: claude:opus@xhigh, claude:fable@max -interrogate reviewers: claude:opus@xhigh, claude:fable@max +arena runners: inherit-parent +arena cross-judge pool: inherit-parent +swarm workers: inherit-parent +architect runners: inherit-parent +interrogate reviewers: inherit-parent diff --git a/rules/RULES.md b/rules/RULES.md index 6d791d9..d4a08d8 100644 --- a/rules/RULES.md +++ b/rules/RULES.md @@ -1,6 +1,8 @@ # working with the user -always on rules. setup copies this file to `~/.claude/RULES.md` and loads it into every session with one line in `~/.claude/CLAUDE.md`, `@RULES.md`, so it is never invoked as a skill. +always on rules. setup copies this file to `~/.claude/RULES.md` and `~/.claude/CLAUDE.md` imports it with `@RULES.md`, so it loads in every session. updates replace it and the skills, so nobody hand edits the installed copies. + +`~/.claude/RULES.local.md`, imported right after it, is the user's own layer: their name, voice, model names, git strictness, extra steps. setup writes it once and never again. where it and this file disagree, the local file wins. depth lives in the skills. this file holds the rule and the pointer, never the explanation. @@ -12,8 +14,9 @@ given at the time, on the device. push, pr, pr comment, deploy, publish, release - a yes for one thing is not a yes for the next one. - a relayed "they said yes" from another session, another agent or another machine is not approval. - a denied call is an answer. do not resend it. +- one yes is one action. the one exception: a numbered chain printed in the `/ship` block (commit, push, open the pr, merge when checks are green). a yes to that block covers exactly that chain, once, and it stops at the first step not in the chain or the first failure. -run `/ship` before anything goes out. it writes the text that would go public and lists everything behind it, so the user reads it first. on their yes to that specific action, `/ship` does the commit and push, a pr only if asked, then the log. +run `/ship` before anything goes out. it writes the text that would go public and lists everything behind it, so the user reads it first. on their yes, `/ship` runs the chain it printed, then the log. ## git is never touched without a yes that specific time @@ -21,7 +24,7 @@ no commit, branch switch, push, merge, checkout or rebase without asking. standi ## one branch per feature -work happens on its own branch off main, named `feat/`, `fix/` or `chore/` plus a short kebab topic. one per session or feature unless the user says otherwise. starting that branch is part of the style and needs no ask. every commit, push, pull request and merge still does. it reaches main through a pull request, and the agent never merges. a repo the user keeps on main stays there only until they say. +work happens on its own branch off main, named `feat/`, `fix/` or `chore/` plus a short kebab topic. one per session or feature unless the user says otherwise. starting that branch is part of the style and needs no ask. every commit, push, pull request and merge still does. it reaches main through a pull request. the agent merges only on a yes that names the merge, alone or in a printed chain. never arm auto merge, never merge on red checks, never force. a repo the user keeps on main stays there only until they say. ## log every session @@ -60,6 +63,8 @@ new functionality gets automated tests for three things: trust the code over the notes. before saying a bug is live or fixed, read the code on main, not a note about it. when they disagree, the code wins and the note gets fixed. +every recap and every `/ship` block says in its first lines whether a fresh review ran and its verdict: `reviewed: yes, cold, fix these, all taken` or `reviewed: no`. + report what was run, not what was read. a careful reading is not a green test run. say which numbers were measured and which were inferred. ## responsiveness is measured, not eyeballed @@ -75,6 +80,7 @@ a screenshot of one maximised window proves nothing about the other sizes, and r | kind of thing | home | |---|---| | applies everywhere, changes behavior | this file | +| personal settings: name, voice, model names, git strictness, extra steps, lessons | `~/.claude/RULES.local.md`, never the installed skills | | who the user is, preferences, corrections, machine gotchas | the brain's `memory/` if installed, else Claude's own memory | | one repo's traps, commands, branches, standing exceptions | that repo's `.claude/CLAUDE.md`, gitignored | | one repo's log, open items, plans, research | the brain's `projects//` if installed, else that repo's `.claude/` | @@ -85,7 +91,7 @@ none of it gets committed to a project repo. ## every task goes through /cook -`/cook` sizes it (quick, build, deep), picks effort, models and the subagent cap, and ends every lane the same way: branch, real run, hand tests, the sweep for front end, log and tbd, `/ship`, then on the user's yes the commit and push. `/deep` is cook's deep lane. `/status` answers "all done?". `/review` is the fresh eyes. `/initiate` sets up a new repo. +`/cook` sizes it (quick, build, deep), picks effort, models and the subagent cap, and ends every lane the same way: branch, real run, hand tests, the sweep for front end, log and tbd, `/ship`, then on the user's yes the chain it printed. on build and deep it reviews its own work with a fresh agent and fixes what that finds, without being asked. `/deep` is cook's deep lane. `/bbq` is the fast build for a prototype or a hackathon: no questions, a time box, a working demo, what it faked listed. `/status` answers "all done?". `/review` is the fresh eyes. `/initiate` sets up a new repo. ## pstack runs under these rules, not over them @@ -94,13 +100,14 @@ pstack is optional. where it and this file disagree, this file wins. without it, - `opening-a-pr` stops at `/ship`. never `gh pr create` on its own. - "commit liberally" means stage and tell the user. - babysit and fix-ci: fix locally, run the tests, `/ship` the push. draft reviewer replies, never send them. -- shipping, autopilot-full, autopilot-stack: never merge, never arm auto merge. +- shipping, autopilot-full, autopilot-stack: merge only on a yes that names it, per `/ship`. never arm auto merge. - worktree-cleanup `--force` and `rm -rf`: list and ask. - multi-phase-plan and figure-it-out write plans to the brain's `projects//plans/` or the repo's `.claude/plans/`, never `docs/`. show-me-your-work writes its trail beside them, never a committed tsv. - `write` wins over unslop and technical-writing for anything the user reads. -- reflect writes lessons into your own skills, never the plugin cache. - +- reflect writes lessons into `~/.claude/RULES.local.md` or the repo's `.claude/CLAUDE.md`, never the installed skills or the plugin cache. ## writing zero em dashes, ever. lowercase and direct. answer first, no preamble, no hedging. if the plan is wrong, say so in the first sentence and give the better move. end with the user's move: the one thing only they can do. + +text the user will copy and paste (a draft, a command, a reply) goes as plain lines or a code block, never a blockquote: the quote bars come along with the copy. diff --git a/scripts/make-known-hashes.sh b/scripts/make-known-hashes.sh new file mode 100644 index 0000000..4dc93da --- /dev/null +++ b/scripts/make-known-hashes.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# writes setup/known-hashes.txt: the sha256 of every version of every installable file that was ever on main. +# the installer uses it to recognise a copy from before installs were tracked (no manifest) as one of its own, +# so an old untouched install updates instead of being skipped as "edited". run it before a release. +set -euo pipefail +cd "$(dirname "$0")/.." +ref="${1:-HEAD}" +sha() { if command -v sha256sum >/dev/null 2>&1; then sha256sum; else shasum -a 256; fi | cut -d' ' -f1; } +git rev-list "$ref" -- skills rules tools pstack | while read -r c; do + git ls-tree -r "$c" -- skills rules/RULES.md tools pstack | awk '$2=="blob"{print $3}' +done | LC_ALL=C sort -u | while read -r blob; do git cat-file blob "$blob" | sha; done | LC_ALL=C sort -u > setup/known-hashes.txt +wc -l < setup/known-hashes.txt diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 0000000..49a9289 --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# runs the repo's gate before every commit. install it once per clone: +# ln -sf ../../scripts/pre-commit .git/hooks/pre-commit +# with a private list in .claude/denylist.txt it also stops a commit that carries one of your private strings. +exec bash "$(git rev-parse --show-toplevel)/scripts/check.sh" diff --git a/scripts/test-install.sh b/scripts/test-install.sh new file mode 100644 index 0000000..e629f12 --- /dev/null +++ b/scripts/test-install.sh @@ -0,0 +1,248 @@ +#!/usr/bin/env bash +# the installer's own tests. every case runs in a throwaway home, nothing touches yours. +# bash scripts/test-install.sh tests install.sh +# bash scripts/test-install.sh ps1 tests install.ps1 (needs pwsh on PATH) +# the upgrade cases install an old commit with its own installer first, so they need the git history (not a shallow clone). +set -uo pipefail +ROOT="$(cd "$(dirname "$0")/.." && pwd)" +INSTALLER="${1:-sh}" +OLD_COMMITS="${OLD_COMMITS:-76f27ac e942460}" +WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT +pass=0 fail=0 +sha() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$@"; else shasum -a 256 "$@"; fi; } +native() { if command -v cygpath >/dev/null 2>&1; then cygpath -w "$1"; else echo "$1"; fi; } +ok() { # ok "what" command... + local what="$1"; shift + if "$@" >/dev/null 2>&1; then pass=$((pass+1)); echo "ok $what"; else fail=$((fail+1)); echo "FAIL $what"; fi +} +no() { local what="$1"; shift; if "$@" >/dev/null 2>&1; then fail=$((fail+1)); echo "FAIL $what"; else pass=$((pass+1)); echo "ok $what"; fi; } +newhome() { local h; h="$(mktemp -d "$WORK/home.XXXXXX")"; echo "$h"; } +tree() { (cd "$1" && find . -type f ! -path './.claude/workflow-backups/*' | LC_ALL=C sort | while IFS= read -r f; do echo "$f $(sha "$f" | cut -d' ' -f1)"; done | sha | cut -d' ' -f1); } +copy_source() { # a copy of the source we can change + local d; d="$(mktemp -d "$WORK/src.XXXXXX")" + (cd "$ROOT" && cp -R rules skills tools pstack setup brain-template install.sh install.ps1 SETUP.md VERSION "$d/") + echo "$d" +} +# inst SRC HOME flags...: run the installer under test from SRC into HOME +inst() { + local src="$1" h="$2"; shift 2 + if [ "$INSTALLER" = ps1 ]; then + local a=() f + for f in "$@"; do case "$f" in + --yes) a+=(-Yes) ;; --force) a+=(-Force) ;; --dry-run) a+=(-DryRun) ;; --status) a+=(-Status) ;; --uninstall) a+=(-Uninstall) ;; + --with-brain) a+=(-WithBrain) ;; --with-permissions) a+=(-WithPermissions) ;; --with-hooks) a+=(-WithHooks) ;; --with-pstack) a+=(-WithPstack) ;; + --no-*) ;; *) a+=("$f") ;; esac; done + WORKFLOW_HOME="$(native "$h")" pwsh -NoProfile -ExecutionPolicy Bypass -File "$(native "$src/install.ps1")" "${a[@]}" 2>&1 + else HOME="$h" bash "$src/install.sh" "$@" 2>&1 /dev/null 2>&1 /dev/null)" ]; } + +echo "# installer under test: install.$INSTALLER" + +echo "## fresh install" +h="$(newhome)"; out="$(inst "$ROOT" "$h" --yes --dry-run)" +ok "dry run on an empty home writes nothing" test ! -e "$h/.claude/skills/cook" +out="$(inst "$ROOT" "$h" --yes)" +ok "installs every core file" matches_source "$h" +ok "writes the manifest with the version" grep -q "^# workflow $(cat "$ROOT/VERSION")" "$h/.claude/workflow-manifest" +ok "creates RULES.local.md" test -f "$h/.claude/RULES.local.md" +ok "imports RULES.md" grep -qx '@RULES.md' "$h/.claude/CLAUDE.md" +ok "imports RULES.local.md after it" test "$(grep -n '@RULES' "$h/.claude/CLAUDE.md" | tr -d '\r' | tr '\n' ' ')" = "1:@RULES.md 3:@RULES.local.md " +no "does not install brain without the flag" test -e "$h/.claude/skills/brain" +no "does not write settings.json without the flag" test -e "$h/.claude/settings.json" +before="$(tree "$h")"; out="$(inst "$ROOT" "$h" --yes)" +ok "a second run changes nothing" test "$before" = "$(tree "$h")" +ok "a second run says so" grep -q "nothing, all up to date" <<< "$out" +no "a second run makes no backup folder" test -e "$h/.claude/workflow-backups" + +echo "## an existing CLAUDE.md is appended to, never replaced" +h="$(newhome)"; mkdir -p "$h/.claude"; printf 'my own line\n' > "$h/.claude/CLAUDE.md" +out="$(inst "$ROOT" "$h" --yes)" +ok "keeps the line that was there" grep -qx 'my own line' "$h/.claude/CLAUDE.md" +ok "adds both imports" test "$(grep -c '^@RULES' "$h/.claude/CLAUDE.md")" = 2 + +for c in $OLD_COMMITS; do + echo "## upgrade from $c, untouched" + h="$(newhome)" + if ! old_install "$c" "$h"; then echo "skip cannot build $c (shallow clone?)"; fail=$((fail+1)); continue; fi + no "the old install differs from the source (the test means something)" matches_source "$h" + before="$(tree "$h")"; out="$(inst "$ROOT" "$h" --yes --dry-run)" + ok "dry run changes nothing" test "$before" = "$(tree "$h")" + out="$(inst "$ROOT" "$h" --yes)" + ok "every file now equals the source" matches_source "$h" + no "nothing was skipped" grep -q '^skipped' <<< "$out" + ok "no backup copies inside skills/" no_baks_in_skills "$h" + ok "RULES.local.md created on upgrade" test -f "$h/.claude/RULES.local.md" + + echo "## upgrade from $c, with edits" + h="$(newhome)"; old_install "$c" "$h" + echo "my edit" >> "$h/.claude/skills/cook/SKILL.md"; echo "my rule" >> "$h/.claude/RULES.md" + out="$(inst "$ROOT" "$h" --yes)" + ok "the edited skill is kept" grep -qx 'my edit' "$h/.claude/skills/cook/SKILL.md" + ok "the edited RULES.md is kept" grep -qx 'my rule' "$h/.claude/RULES.md" + ok "both are named as skipped" test "$(grep -c '^skipped: \(skills.cook\|RULES.md\)' <<< "$out")" = 2 + ok "an untouched skill still updated" cmp -s "$ROOT/skills/ship/SKILL.md" "$h/.claude/skills/ship/SKILL.md" + out="$(inst "$ROOT" "$h" --yes --force)" + ok "--force replaces them" matches_source "$h" + ok "the edited skill went to workflow-backups" test -n "$(grep -rlx 'my edit' "$h/.claude/workflow-backups" 2>/dev/null)" + ok "the edited RULES.md went to workflow-backups" test -n "$(grep -rlx 'my rule' "$h/.claude/workflow-backups" 2>/dev/null)" + ok "no backup copies inside skills/" no_baks_in_skills "$h" +done + +echo "## update from this version to a later one" +h="$(newhome)"; out="$(inst "$ROOT" "$h" --yes)" +src="$(copy_source)" +echo "a later line" >> "$src/skills/cook/SKILL.md"; echo "a later line" >> "$src/skills/design/SKILL.md"; echo "a later rule" >> "$src/rules/RULES.md" +echo "new file" > "$src/skills/cook/new.md"; rm "$src/skills/playbook/SKILL.md"; echo "replaced" > "$src/skills/playbook/OTHER.md" +echo 9.9.9 > "$src/VERSION" +echo "my edit" >> "$h/.claude/skills/design/SKILL.md"; echo "mine" > "$h/.claude/skills/cook/my-notes.md"; echo "my settings" >> "$h/.claude/RULES.local.md" +out="$(inst "$src" "$h" --yes)" +ok "an untouched skill gets the new text" grep -qx 'a later line' "$h/.claude/skills/cook/SKILL.md" +ok "a new file in an existing skill arrives" test -f "$h/.claude/skills/cook/new.md" +ok "a file you added to a skill stays" grep -qx mine "$h/.claude/skills/cook/my-notes.md" +ok "the skill you edited is kept" grep -qx 'my edit' "$h/.claude/skills/design/SKILL.md" +no "the skill you edited did not get the new text" grep -qx 'a later line' "$h/.claude/skills/design/SKILL.md" +ok "it is named as skipped" grep -q '^skipped: skills.design' <<< "$out" +ok "untouched RULES.md updates" grep -qx 'a later rule' "$h/.claude/RULES.md" +ok "RULES.local.md is never written again" grep -qx 'my settings' "$h/.claude/RULES.local.md" +no "a file removed from the source leaves the skill" test -e "$h/.claude/skills/playbook/SKILL.md" +ok "and goes to workflow-backups" test -n "$(find "$h/.claude/workflow-backups" -path '*skills/playbook/SKILL.md')" +ok "the version change is printed" grep -q "version: $(cat "$ROOT/VERSION") to 9.9.9" <<< "$out" +out="$(inst "$src" "$h" --status)" +ok "--status names the edited file" grep -q 'edited: *skills.design.SKILL.md' <<< "$out" +out="$(inst "$src" "$h" --yes --force)" +ok "--force keeps RULES.local.md too" grep -qx 'my settings' "$h/.claude/RULES.local.md" +ok "--force replaces the edited skill" grep -qx 'a later line' "$h/.claude/skills/design/SKILL.md" + +echo "## old backup folders inside skills/ are moved out" +h="$(newhome)"; mkdir -p "$h/.claude/skills/cook.bak-20250101-000000" "$h/.claude/skills/mine.bak-1" +echo x > "$h/.claude/skills/cook.bak-20250101-000000/SKILL.md"; echo x > "$h/.claude/skills/mine.bak-1/SKILL.md"; echo x > "$h/.claude/RULES.md.bak-20250101-000000" +out="$(inst "$ROOT" "$h" --yes)" +no "cook.bak is gone from skills/" test -e "$h/.claude/skills/cook.bak-20250101-000000" +ok "it is in workflow-backups" test -n "$(find "$h/.claude/workflow-backups" -name 'cook.bak-20250101-000000')" +no "RULES.md.bak is gone from ~/.claude" test -e "$h/.claude/RULES.md.bak-20250101-000000" +ok "a folder that is not ours is left alone" test -e "$h/.claude/skills/mine.bak-1/SKILL.md" + +echo "## brain and pstack" +h="$(newhome)"; out="$(inst "$ROOT" "$h" --yes --with-brain)" +ok "--with-brain installs brain and dream" test -f "$h/.claude/skills/brain/SKILL.md" -a -f "$h/.claude/skills/dream/SKILL.md" +ok "--with-brain creates the vault" test -f "$h/vault/HOME.md" +echo "mine" > "$h/vault/HOME.md"; out="$(inst "$ROOT" "$h" --yes --with-brain)" +ok "an existing vault is left as is" grep -qx mine "$h/vault/HOME.md" +h="$(newhome)"; mkdir -p "$h/.claude/skills/pstack"; out="$(inst "$ROOT" "$h" --yes)" +ok "an installed pstack folder is kept up to date without the flag" cmp -s "$ROOT/pstack/README.md" "$h/.claude/skills/pstack/README.md" +ok "models.md is created" cmp -s "$ROOT/pstack/models.md" "$h/.claude/skills/pstack/models.md" +echo "my models" >> "$h/.claude/skills/pstack/models.md"; out="$(inst "$ROOT" "$h" --yes --force)" +ok "models.md is never written again, even with --force" grep -qx 'my models' "$h/.claude/skills/pstack/models.md" +no "and is not named as skipped" grep -q 'models.md' <<< "$out" + +if command -v node >/dev/null 2>&1; then + echo "## permissions" + h="$(newhome)"; out="$(inst "$ROOT" "$h" --yes --with-permissions)" + ok "creates settings.json with the ask list" grep -q '"Bash(git push:\*)"' "$h/.claude/settings.json" + before="$(sha "$h/.claude/settings.json")"; out="$(inst "$ROOT" "$h" --yes --with-permissions)" + ok "a second run leaves it byte for byte" test "$before" = "$(sha "$h/.claude/settings.json")" + h="$(newhome)"; mkdir -p "$h/.claude" + printf '{"model":"x","permissions":{"allow":["Bash(ls:*)"],"ask":["Bash(git push:*)","Bash(mine:*)"]},"hooks":{"Stop":[{"hooks":[{"type":"command","command":"mine.sh"}]}]}}' > "$h/.claude/settings.json" + out="$(inst "$ROOT" "$h" --yes --with-permissions)" + q() { node -e 'const s=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"));process.exit(eval(process.argv[2])?0:1)' "$h/.claude/settings.json" "$1"; } + ok "keeps the other keys" q 's.model==="x" && s.permissions.allow[0]==="Bash(ls:*)" && s.hooks.Stop[0].hooks[0].command==="mine.sh"' + ok "keeps the user's own ask rule" q 's.permissions.ask.includes("Bash(mine:*)")' + ok "adds ours once, no duplicate" q 's.permissions.ask.filter(r=>r==="Bash(git push:*)").length===1 && s.permissions.ask.includes("Bash(gh pr merge:*)")' + ok "the old settings.json is in workflow-backups" test -n "$(find "$h/.claude/workflow-backups" -name settings.json)" + h="$(newhome)"; mkdir -p "$h/.claude"; printf '{ not json' > "$h/.claude/settings.json" + out="$(inst "$ROOT" "$h" --yes --with-permissions)" + ok "a broken settings.json is left untouched" test "$(cat "$h/.claude/settings.json")" = '{ not json' + ok "and named as skipped" grep -q '^skipped: settings.json.*not valid json' <<< "$out" + ok "the rest of the install still ran" test -f "$h/.claude/skills/cook/SKILL.md" + + if [ "$INSTALLER" = sh ] && command -v jq >/dev/null 2>&1; then + echo "## the node_modules hook" + h="$(newhome)"; out="$(inst "$ROOT" "$h" --yes --with-hooks)" + q() { node -e 'const s=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"));process.exit(eval(process.argv[2])?0:1)' "$h/.claude/settings.json" "$1"; } + ok "installs the hook file, executable" test -x "$h/.claude/hooks/ensure-node-modules.sh" + ok "registers it with its full path" q "s.hooks.PreToolUse[0].hooks[0].command==='$h/.claude/hooks/ensure-node-modules.sh'" + out="$(inst "$ROOT" "$h" --yes --with-hooks --with-permissions)" + ok "a second run does not register it twice" q 's.hooks.PreToolUse.length===1 && s.permissions.ask.length>5' + p="$(mktemp -d "$WORK/proj.XXXXXX")"; printf '{"name":"t","version":"1.0.0"}' > "$p/package.json" + hook_out="$(printf '{"tool_input":{"command":"npx vite"},"cwd":"%s"}' "$p" | bash "$h/.claude/hooks/ensure-node-modules.sh")" + ok "the hook answers a command that needs node_modules" grep -q 'node_modules was missing' <<< "$hook_out" + hook_out="$(printf '{"tool_input":{"command":"ls"},"cwd":"%s"}' "$p" | bash "$h/.claude/hooks/ensure-node-modules.sh")" + ok "the hook stays silent for any other command" test -z "$hook_out" + out="$(inst "$ROOT" "$h" --uninstall)" + no "uninstall takes the hook file" test -e "$h/.claude/hooks/ensure-node-modules.sh" + ok "and its entry out of settings.json, the ask list stays" q '!s.hooks && s.permissions.ask.length>5' + fi +fi + +echo "## --status counts every kind of file" +h="$(newhome)"; out="$(inst "$ROOT" "$h" --yes)"; src="$(copy_source)" +echo "// later" >> "$src/tools/record.mjs"; echo "later" >> "$src/skills/ship/SKILL.md" +out="$(inst "$src" "$h" --status)" +ok "a newer tool and a newer skill are both behind" grep -q '^2 files behind' <<< "$out" +echo "// mine" >> "$h/.claude/tools/record.mjs"; out="$(inst "$src" "$h" --status)" +ok "an edited tool is named" grep -q 'edited: *tools.record.mjs' <<< "$out" + +if [ "$INSTALLER" = sh ]; then + echo "## a skill folder that is a link to your own copy" + h="$(newhome)"; mine="$(mktemp -d "$WORK/mine.XXXXXX")"; mkdir -p "$h/.claude/skills" + echo "my own cook" > "$mine/SKILL.md"; ln -s "$mine" "$h/.claude/skills/cook" + out="$(inst "$ROOT" "$h" --yes --force)" + ok "is left alone, even with --force" test "$(cat "$mine/SKILL.md")" = "my own cook" + ok "and named" grep -q '^skipped: skills/cook: a link' <<< "$out" + ok "the other skills still install" test -f "$h/.claude/skills/ship/SKILL.md" + cp "$ROOT/skills/cook/SKILL.md" "$mine/SKILL.md"; out="$(inst "$ROOT" "$h" --uninstall)" + ok "uninstall does not empty the linked folder" cmp -s "$ROOT/skills/cook/SKILL.md" "$mine/SKILL.md" +fi + +echo "## uninstall" +h="$(newhome)"; mkdir -p "$h/.claude"; printf 'my own line\n' > "$h/.claude/CLAUDE.md" +out="$(inst "$ROOT" "$h" --yes)" +echo "my edit" >> "$h/.claude/skills/ship/SKILL.md"; echo "my settings" >> "$h/.claude/RULES.local.md" +before="$(tree "$h")"; out="$(inst "$ROOT" "$h" --uninstall --dry-run)" +ok "uninstall dry run changes nothing" test "$before" = "$(tree "$h")" +ok "and says would, not uninstalled" grep -q '^would move [0-9]* files' <<< "$out" +no "and does not claim it uninstalled" grep -q '^uninstalled' <<< "$out" +out="$(inst "$ROOT" "$h" --uninstall)" +no "an untouched skill is gone" test -e "$h/.claude/skills/cook" +no "RULES.md is gone" test -e "$h/.claude/RULES.md" +ok "the skill you edited stays" grep -qx 'my edit' "$h/.claude/skills/ship/SKILL.md" +ok "and is named" grep -q 'kept, you edited it: skills.ship.SKILL.md' <<< "$out" +ok "RULES.local.md stays" grep -qx 'my settings' "$h/.claude/RULES.local.md" +ok "the imports are gone, your line stays" test "$(grep -v '^$' "$h/.claude/CLAUDE.md" | tr -d '\r')" = "my own line" +ok "everything it moved is in workflow-backups" test -n "$(find "$h/.claude/workflow-backups" -path '*skills/cook/SKILL.md')" +no "the manifest is gone" test -e "$h/.claude/workflow-manifest" +no "an emptied tools folder is gone" test -e "$h/.claude/tools" +out="$(inst "$ROOT" "$h" --uninstall)"; rc=$? +ok "a second uninstall says nothing is installed and fails" test "$rc" != 0 -a -n "$(grep 'nothing to uninstall' <<< "$out")" +out="$(inst "$ROOT" "$h" --yes)" +ok "installing again after an uninstall works" test -f "$h/.claude/skills/cook/SKILL.md" + +echo "## edges" +h="$WORK/a home with spaces"; mkdir -p "$h"; out="$(inst "$ROOT" "$h" --yes)" +ok "a home folder with spaces in its name" matches_source "$h" +h="$(newhome)"; out="$(inst "$ROOT" "$h" --nope)"; rc=$? +ok "an unknown flag is refused" test "$rc" != 0 +no "and installs nothing" test -e "$h/.claude/skills/cook" +h="$(newhome)"; out="$(inst "$ROOT" "$h" --status)" +ok "--status on an empty home says none recorded" grep -q 'installed: *none recorded' <<< "$out" +no "--status writes nothing" test -e "$h/.claude" + +echo +echo "$pass passed, $fail failed" +[ "$fail" -eq 0 ] diff --git a/setup/RULES.local.md b/setup/RULES.local.md new file mode 100644 index 0000000..e4cc9f0 --- /dev/null +++ b/setup/RULES.local.md @@ -0,0 +1,38 @@ +# my rules + +yours. the installer created this file once and never writes it again, so it survives every update. +it loads after `RULES.md`, and where the two disagree, this file wins. +write what is personal here instead of editing an installed skill: an edited skill stops getting updates. +a section left empty means the default. + +## name + +what to call you. empty: "the user". + +## models + +the model names your plan has, for the seats in cook's table. empty: the best model the plan has, for every seat. + +- every seat: +- major seats only (the deep lane planner, the final review), a second family if you have one: + +## git + +what differs from RULES.md. empty: no commit, push, pr or merge without your yes that specific time. + +## voice + +how text should sound, words you never want. empty: the plain style in `skills/write`. + +## parallel agents + +a lower ceiling than cook measures, if you run several sessions or a heavy local stack. empty: cook measures it. + +## extra steps + +things cook and /ship run on top of their own. empty: none. + +- before a task: +- before /ship: +- never send (strings that must not leave the machine, one per line): +- after a push: diff --git a/setup/hooks.json b/setup/hooks.json new file mode 100644 index 0000000..c8d0c10 --- /dev/null +++ b/setup/hooks.json @@ -0,0 +1,17 @@ +{ + "hooks": { + "PreToolUse": [ + { + "matcher": "Bash", + "hooks": [ + { + "type": "command", + "command": "__HOOK__", + "timeout": 300, + "statusMessage": "installing missing node_modules" + } + ] + } + ] + } +} diff --git a/setup/hooks/ensure-node-modules.sh b/setup/hooks/ensure-node-modules.sh new file mode 100755 index 0000000..8be69e0 --- /dev/null +++ b/setup/hooks/ensure-node-modules.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# a PreToolUse hook on Bash: install a project's dependencies before a command that needs +# them runs. it runs the project's own install (npm ci, pnpm install ...), postinstall scripts included. without this, a fresh clone answers "tsup: command not found", +# "vite: command not found", and so on, because the binary lives in +# node_modules/.bin and node_modules was never created. +# +# only fires when: the command looks like it needs a local js toolchain, the +# nearest package.json has no node_modules beside it, and a package manager is +# on PATH. otherwise it exits 0 and stays out of the way. + +set -uo pipefail + +input=$(cat) +cmd=$(printf '%s' "$input" | jq -r '.tool_input.command // ""') +dir=$(printf '%s' "$input" | jq -r '.cwd // ""') +[ -n "$dir" ] && [ -d "$dir" ] || dir=$PWD + +# the command has to be one that reaches for a locally installed binary. +printf '%s' "$cmd" | grep -Eq \ + '(^|[;&|(][[:space:]]*|[[:space:]])(npm|npx|pnpm|pnpx|yarn|tsc|tsup|tsx|vite|vitest|jest|eslint|prettier|next|astro|nest|storybook)([[:space:]]|$)' \ + || exit 0 + +# an install command is the thing we would run anyway. let it through. +printf '%s' "$cmd" | grep -Eq '(npm|pnpm|yarn|bun)[[:space:]]+(ci|i|install|add)([[:space:]]|$)' && exit 0 + +# walk up to the nearest package.json, stopping at home or root. +root=$dir +while [ ! -f "$root/package.json" ]; do + parent=$(dirname "$root") + [ "$parent" = "$root" ] && exit 0 + [ "$root" = "$HOME" ] && exit 0 + root=$parent +done + +[ -d "$root/node_modules" ] && exit 0 + +# match the package manager to the lockfile that is actually committed. +if [ -f "$root/pnpm-lock.yaml" ] && command -v pnpm >/dev/null 2>&1; then + install=(pnpm install --frozen-lockfile) +elif [ -f "$root/yarn.lock" ] && command -v yarn >/dev/null 2>&1; then + install=(yarn install --frozen-lockfile) +elif [ -f "$root/bun.lockb" ] && command -v bun >/dev/null 2>&1; then + install=(bun install --frozen-lockfile) +elif [ -f "$root/package-lock.json" ] && command -v npm >/dev/null 2>&1; then + install=(npm ci) +elif command -v npm >/dev/null 2>&1; then + install=(npm install) +else + exit 0 +fi + +log=$(cd "$root" && "${install[@]}" 2>&1) +status=$? + +# npm ci refuses when the lockfile drifted from package.json. a plain install +# fixes that and is still what a person would type next. +if [ $status -ne 0 ] && [ "${install[0]}" = "npm" ] && [ "${install[1]}" = "ci" ]; then + log=$(cd "$root" && npm install 2>&1) + status=$? +fi + +if [ $status -eq 0 ]; then + jq -n --arg r "$root" --arg c "${install[*]}" \ + '{systemMessage: ("node_modules was missing in " + $r + ", ran " + $c)}' +else + tail=$(printf '%s' "$log" | tail -5) + jq -n --arg r "$root" --arg t "$tail" \ + '{systemMessage: ("could not install dependencies in " + $r + "\n" + $t)}' +fi +exit 0 diff --git a/setup/known-hashes.txt b/setup/known-hashes.txt new file mode 100644 index 0000000..7eaf0a1 --- /dev/null +++ b/setup/known-hashes.txt @@ -0,0 +1,132 @@ +0036f042c4b22502de21a7fb51f9d7900884d29afd3dbe30b85a6bf2dfcf94d0 +013d7197676e2284f5be7141c4164ed0c6b5dfc0f9054220f93bc491b0efc5bc +02223a0b3e2ce6d0341eeec0d1087902c6ed81407924acf4a12bc9646ce887ff +07c228785b27004a9f8b9130277562a1aa3b0666030405e6649c909dd7f69165 +0db38a6ef220f600387ff847a5cbb1c183db9a7d2ceeb107e942981f55bfc0bc +12b506c32e19a4b3ff54d2bbba06b7334372045d5136cc43ea5c2a0e3cc3eece +18313ba8c8d0f9251a2e66684f6ec52649e7ba924fcd942e3151c5d6ceea9b53 +1a0e3250848264d70390c0e701cb2a79a9f13c3225fe2461c59bbd5b430ca177 +1ae8fc18cdc736969ed86dc72c7c0872a1b3122d7152801c7c77006900418521 +1d7f7ace36e32babaec9cef714c4f49bc8f9bae734e301a462112c3b2ed12c05 +1e9e85611c80a0526ee043404120e506c8b80bf87276cb9b706da5aa4e522912 +204a1f74fdff08166d9d023a5c111f656d5c60d5aae78ee81a159e2f48b7decb +23cd5e52dd6340faaeba7721d78f5dd1e63260a1694c46c98c7c077174745248 +2472d1580ca00d876b5b826b6d049edf829cdd6f9460c8db3ed0cc1410e6ce2b +24d3ea544ef9e414a260f99de8fefedb82eea076ccbc9b2ea281dbf61ce82d7b +268b63796a3c876a40f2c0c39c63c974177e506d41d23e059ba4ca47be5e5216 +29162a67bb9f0434948c9823599277ce9ceb38ab8b1420b48b6969f31c58474a +2a9bf3b6ed122d540b37328a3bca2ed67c632a9efd4dbfd9fb6f8770e5387073 +2b6812bde08f11e9800f5f98eb9c6dedb52c3c5c4b8c593a720652e190dc63c8 +2c3b0b92ec8ac60fb2a32749f36d6d46ad9f161798c971ff7438980096b7bd26 +2e191caab29570921628eaf026a7222105764c505abc123756bf873f9e234852 +2e2c5942fc16402104cf0e75df7c2916398b0e5e34477d4974f8d07e4aefdf60 +32168b4975ef20edaf075fa6ae580980414866d75166b87b160efddf2e44c47d +330f3ae27501a8996af9371ddaac8146bb6e602b917652828e59fd2e2677d43b +334f64bbbd9b4d31f33a4efbdca1e2a3ab661e9d47c956f1909bf291d09b7329 +33b96c1d5b4f267137e06be399a3f94465c26509c638f3eaf92db61364967222 +3b483b295cadbc87482180d2d22993c5edf65ae1fd02ae30796762263aa57fae +3e4b8dd4184a95bc7b5d6945796ade4325eaf3a05ece76305eaaad02bffbae81 +407c4a85796406a160ea84571c74fcabf7975aff1479698a620027b5888aec5c +4134bf6ecc99892c2e489a40963ba15bcb83ac7f3e785f73b4a51d87af52b558 +4375d43262e233e596e0d1bd75cdac9ba100c7d29341abb06eecc2db794c001c +439b1b0f155a4b041488102058438fdf7a8e1ef0d7292b88e3f26d93510bbb4a +4507502ce4138725438d5f0f66886b1fe87dc5e104b5b085057e70ad01130dd9 +4653fcf55c337f82706f51607b5d1b30efecc97787bb560fcd29c81b09284ad1 +46c9d7881d9e8626fd0c328f3e335cdd19fb7de09f190eac84202b7dac79abb2 +499153fa8fe1cb9d8be0b592874ee6d9669d51206fb21d2b78617bdbd6d179fa +49d991b8a37644ad13e8840465f642e6995989bff27117cef67e320f6b136f64 +4a49e9bb74198198c576d2a954bd06b83e5bcf349867c81928c7b6a20b507522 +4a58618a6091bdfed8bd58b227cbdbc14c301e83aff0fad2c4e25048c2979d6a +4cb30360ce4b263a07da95d31ec54ed361fa22915611dbbd4aaac850e92b4e2f +4fa616a7d7668a4ab572916e356a793146d14691e0583e3d96691e16931eb21d +508b3a7fec3529ecdf8b62917ee2f04b0748c6ace4548565fef064236e629101 +5c658cd3143ad6d4a16c295dbe00eda13ed6fdbc205b2274d0a3de2cbe8c61eb +5d402c3dc32a69716bbc40e528f65e31cb4e881c8a0af35df82028ca54edbb8b +60014972ef4eae8d98ca774f3d8a275cc3467f5475ce816d8601dc3f25e89233 +611417a3ae2719e8806bad0747ba545e985d3568dd0485ca1e5c503a526ae979 +6c9069bbe18e153043d88d11dfbe14d1b6d1a09e182819933e5e7c9724a5c1c9 +6d6ffa090b0cdf689771451e0e253836cf79df10812882d5c0362f70fad59e55 +6fa78667ae134ca15b0cebb44786a60db1b693c9a6ecdf05f14f82858dd2c59f +70712f77a6c243d3e4e2fc2f1131aca2dad0e3572a6b780b76f89bcb97de6b67 +719f4014876ebdffd41e4dcc346544c9d3c9d11e5698e9a75984ad6eca369103 +7286926ca379280e4ef137b104712c2bb253e95624f7f12a012e1009895cdabc +76493d256d08c855bee8bebab9f49b28bf42334bb442f4310b881cae533c7c24 +7807429b7274afe951e31b7494dada9349d2516e86a836c84a0d687cb6ff635d +78e97f8020f056420e64506ac79a7d6d0ebec65c3ed5588e7fe0ffd90139225d +790ebd2d64b60ceb9dff09defca954363568845a642310220ffc8a992742228c +81fb96d727999c5b640fcc79fbf29dc5b749606971f1e71f0b5949f80a212f75 +8271818426e70ad1095da7e5a5d1716497c201802997ba925c0791d13875a699 +827d7310cd9cc40b15c995458086beed4a9574fc054900dfa9f859afacaf1394 +854af28bc91a693c0448acad6e0d649309416d4493975dea3e41fa1cf3684fe5 +8664c68b0a16ba3cafa910fb999ff6ece3f3cb8bf0b3919b3722c1ae467ee42c +873077c43d2b9377c09a18d8d4d67d0409c7e0ec2f70d3fed3e736bf02244b21 +881f8039807a711e97d9f67b246c1d642b3c31012ecd7d32c0da2d6731f98a51 +89423d0a9c82e2f2c6bd5f670b32b04332cbb5dc32455f39a21dc780bc6967f9 +8a1257b7271d7b69c113d48d2cb9be0c6b7521c84bb12ace61e805a9f695cbca +92ea923ff019ee7726c9e6e403f8cf6dbab8abeff35495cbb820d4a9ac90390f +99625d58514cb517709407603e19d48a44051675633581ae40866254908fc58b +99f867a727dbe99aca8fb21bc9061d1488c7894023be0866d7c78a1ad18520cf +9a8d05029f218dd0009c98d215b200ad606d06ec84d7dd67ba3fa8837d1a0b40 +9ae029c5997bef7fdfc7395779ffac56957784d835b7505d987b9b8cc0123a56 +9b77325b5eec7ad0d50baa39b5bac9f48d7195612c0cecfc82883ee23973376d +9cf780fd6e2df1ba19bdaa23aa736cf8da5fc4ed64ec1299fd56b7fb0ec51ee5 +a0eb8385d15e65f7ecc8489a76d061a52066751a6b5dc7ebcedeceac931da1b9 +a374874bb5a9ffcfed9c91705c7fb3070a3ef3628da77f79b1863891e0a4d166 +a394d918ccbbe5c236be39b3b42f5db6b6c334979ae2d998edeb3ebc24d4a178 +a3a945adc4562dd2318f834687a5158d52ee6da569a890ee4ff3f16b5f2dd006 +a5839e7cc1b10ed33e8d6d49c86017c5cc0a163d23e29756c12b07f4b9b4bb51 +a6aaaab4aab355a96d907bd91666ddcde4336953a9082e1444eb67fc5f9a4c6b +a7b653b527d821b034ff511ec6250be5dc30e84b110fedad7601f4d1b6e8ed2a +aa5f8e1679519d7e9962ed521e7174a0b833de6ab5693e81e940cee9d25303a5 +ab871debe6c4181a1fc33346407362fc6cd576c6dd931ea0f3388324f6be6524 +af32a0632dff5ad2fc26e1ceca0ceeaae46ea69686315c4c961adbac3363db1e +b20b0db9415d77e51a87bd0233fad317ad16965ec7682363b3f3856a40f73493 +b2f31a6bcc69a7d3e67e252c4df64f17c53b6f10752afed5c2f0ceabc2b192c0 +b4bdbec9660b47d84f0d99bfc8e713d3254198cb43b6981ed5ed75fccf9f29a9 +b9e6d83da988af0c3dbfb386e8c959ca9de22e293320c436d5c6a2e13522c69e +baba0ff8c0b37c19d2d16a8230aa5e60779b4283bad7e161daff9d0c4fa6e180 +bd075f529469169e7182de116315d89b1ddcdb4da257cd515ca52ad04e6831ef +bddb0b2368dcdda8dc25ce905b5307ccf65f6607f28cc5e52bf2dd2db1536ab7 +bf711dd5a199c1a33de2f8efae122e6c845248c59ae361f1b9825ca56b0603dc +c00c80a3ce8448c4a6f9100d80c8051a8350c8a0b77294b7afe9152132c6d78e +c217a7b93bc8e70d461d50060ae541ee5923236aeb7cb2165cad89d62baad700 +c3083a7f22fdfd6bc7aef177eb8472474c17e9a553ca5855f15c9cbe787c56f2 +c35c5f8db4e2efddb3915e67cfa4bea2f6244b1e04c55bd27c3b26e6ff7794a7 +c639883054283aa9eea3acbe4f0db3af3121200bc620251582680b0212cd3a3f +c68c12067af19fb3a6b4e7688ea64ac9fcb4538cfcc8911d49fe3e0fb80047db +c714acaa772aa918de97d52755d59ee525d52121aca427a043000cf90cfb0433 +ca09fbade6eae4ad2b102c91ae28d898de8900ad718a2468220b5321699cb8e4 +caaa1ceaa63adeca65321dd4641d200f3947761271c04397845269885374d595 +cb81396b60fb824eeeb5e046f02fc01de321463e67b5b3679d15549c575b1668 +ce1a520fdf2bd0e927bb046a195764a557bccbe180a91c097b8ef69e51e229f5 +d24400f7adb7c4ed8b9059382250d00401a818d6c89692d46df6bf5d206579db +d6de8cd97653dbffb38d00334b4d545672f04cdd5fa50ad93ff65233bf19a61e +dca0cdca7ba4ce0f45e05516894d125eee69bd56cf58223fe9cfc60229d88e20 +dcfba522aa85eca85f2a07c825208d239085f5a8f9fbe871574707bac8a93a39 +df2f48a63cce253a6cd08806f3eb894d9a6d3e108e4633797c1411dde8ac7ca6 +e151160a30399308362fddad5966cb7a6787aeb19b71ad2ae2ac6113d0a0b7f9 +e26a6c27b5dbe0fc42af5f3e6e2314f200634b782e4049b369840a868b63ed48 +e4285526ca9643afda4a97dee31f47f7e223fbb012aa74196f5ce119aa054675 +e4be37baa657c000a94c8cb2f2069aef6cbfab32f2caae1a82c654edca648334 +e65aa86a2d8d0c0545b06261b7049d028951fafa3121efb80220e0c01a0ba7fe +e7da1f3ff17cd49844a47ca9e7d2b577896090f2d3a02c9f7edae5969102fa14 +e803537012b2fa343bd9d433aba2a2ec079fc4540ae3d00c1a386e52f78114f4 +e905c21c9ee7b7ab181e8a5a4a56372d18599496e200ed0aad39201ff908f3ce +eab4211ec1b43f67b2ae39f0e830502c396841b072bec99ca23e09aa3abcc01e +eb2fffd57d0f33a25f87c2ddfeea159260e69ad80b1abbe23c33e5e39e56a0a7 +ebbe275284a0ef6b068f0f98a0e8f162e2e052d364790e4a65f414993e58f86e +ee24938bac2cf110699b1ecb51f3ecc7ed0201252be098b4d0b441be10c53f6d +ee584fff13e162b084c5102b78d988b87829faa8fde35118c14ce53bd44fdc60 +f3778d49032a03d92be6bb4b3c72b37db756b18c57f5e658becf7ae4a6cf376a +f4e32e820f3bdeeb5b6455e0c5ea2adfb18b352c5466203e3a8da57e8ca3e57c +f63fc5032722516687a34b6d5419dbbdfd6d22395dbfbad3ff6562340a3bddc2 +f750bb3add421b16247bf40ac708655e5b701e19d949a1fbc9c166d79940baa0 +f7741bc9982aff71bf4ebf10a8f6ebca00e9c658f10350ed274292eeb0f3a05c +f817d66319230af75454094fe2e039bcbbd2032442e05a7eb67e3de479458477 +fa372fff602ce1b18fb7ff1bb6781ae78ff36dae3dcb09333575f941132d4918 +fab08db766157cc4c8303e3df8b9761578faac29ae68a0344b7d9f6cf53fff38 +fb8501f357f899eda186be4ca143ae326875e0b21b78df18755bac274995b769 +fc0ede82d9f7d3a8b8a160d299a08e07e21337e82fd2997dd76cdfef9d00dfa8 +fda8cebb02783d4f868f1515045dbe6dfe7181a3fd3a742d39200d0e99825383 +ff1133b2fb347f7569c3aa0b10984084dd907ae3daa137110c750dafbbe954e1 +fff2bf43f9e007281fbc7f42ea1e5fee0059ee0ba91af9c3c05b0c2b855e3209 diff --git a/setup/merge-settings.mjs b/setup/merge-settings.mjs new file mode 100644 index 0000000..1edc06c --- /dev/null +++ b/setup/merge-settings.mjs @@ -0,0 +1,80 @@ +#!/usr/bin/env node +// merges a fragment into a claude code settings.json without losing anything already there. +// node merge-settings.mjs [--check] [--set KEY=VALUE] +// permissions.allow, .ask and .deny are unioned. a hook entry is added only when none of its commands is already +// registered for that event. every other key in the settings file is left exactly as it was. +// --remove takes the fragment's hook entries back out (by command) and leaves permissions alone. +// --check writes nothing and prints "same" or "changed". exit 3: the settings file is not valid json, nothing written. +import { readFileSync, writeFileSync, renameSync, existsSync, mkdirSync } from 'node:fs'; +import { dirname } from 'node:path'; + +const paths = []; +let check = false; +let remove = false; +let set = null; +const args = process.argv.slice(2); +for (let i = 0; i < args.length; i++) { + if (args[i] === '--check') check = true; + else if (args[i] === '--remove') remove = true; + else if (args[i] === '--set') set = args[++i]; + else paths.push(args[i]); +} +const [settingsPath, fragmentPath] = paths; +if (!settingsPath || !fragmentPath) { console.error('usage: merge-settings.mjs [--check] [--set KEY=VALUE]'); process.exit(2); } + +let fragmentText = readFileSync(fragmentPath, 'utf8'); +if (set) { + const eq = set.indexOf('='); + fragmentText = fragmentText.split(set.slice(0, eq)).join(JSON.stringify(set.slice(eq + 1)).slice(1, -1)); +} +const fragment = JSON.parse(fragmentText); + +let settings = {}; +if (existsSync(settingsPath)) { + const raw = readFileSync(settingsPath, 'utf8'); + if (raw.trim()) { + try { settings = JSON.parse(raw); } catch (e) { console.log(`${settingsPath} is not valid json (${e.message}). left untouched`); process.exit(3); } + if (settings === null || typeof settings !== 'object' || Array.isArray(settings)) { console.log(`${settingsPath} is not a json object. left untouched`); process.exit(3); } + } +} +const before = JSON.stringify(settings); +const list = (v) => (Array.isArray(v) ? v : []); +const obj = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {}); + +if (remove) { + for (const [event, entries] of Object.entries(obj(fragment.hooks))) { + if (!Array.isArray(settings.hooks?.[event])) continue; + const gone = new Set(list(entries).flatMap((e) => list(e.hooks).map((h) => h.command))); + settings.hooks[event] = settings.hooks[event] + .map((e) => (Array.isArray(e?.hooks) ? { ...e, hooks: e.hooks.filter((h) => !gone.has(h?.command)) } : e)) + .filter((e) => !Array.isArray(e?.hooks) || e.hooks.length); + if (!settings.hooks[event].length) delete settings.hooks[event]; + } + if (settings.hooks && !Object.keys(settings.hooks).length) delete settings.hooks; +} else { + for (const kind of ['allow', 'ask', 'deny']) { + const add = list(fragment.permissions?.[kind]); + if (!add.length) continue; + settings.permissions = obj(settings.permissions); + const have = list(settings.permissions[kind]); + settings.permissions[kind] = [...have, ...add.filter((r) => !have.includes(r))]; + } + for (const [event, entries] of Object.entries(obj(fragment.hooks))) { + settings.hooks = obj(settings.hooks); + const have = list(settings.hooks[event]); + const commands = new Set(have.flatMap((e) => list(e?.hooks).map((h) => h?.command))); + const add = list(entries).filter((e) => !list(e.hooks).some((h) => commands.has(h.command))); + if (add.length) settings.hooks[event] = [...have, ...add]; + } + if (settings.hooks && !Object.keys(settings.hooks).length) delete settings.hooks; +} + +const changed = JSON.stringify(settings) !== before; +if (check) { console.log(changed ? 'changed' : 'same'); process.exit(0); } +if (changed) { + mkdirSync(dirname(settingsPath), { recursive: true }); + const tmp = `${settingsPath}.tmp-${process.pid}`; + writeFileSync(tmp, JSON.stringify(settings, null, 2) + '\n'); + renameSync(tmp, settingsPath); +} +console.log(changed ? 'changed' : 'same'); diff --git a/setup/permissions.json b/setup/permissions.json new file mode 100644 index 0000000..30dc4c5 --- /dev/null +++ b/setup/permissions.json @@ -0,0 +1,20 @@ +{ + "permissions": { + "ask": [ + "Bash(git push:*)", + "Bash(git merge:*)", + "Bash(gh pr create:*)", + "Bash(gh pr merge:*)", + "Bash(gh pr comment:*)", + "Bash(gh pr review:*)", + "Bash(gh release create:*)", + "Bash(npm publish:*)", + "Bash(vercel:*)", + "Bash(npx vercel:*)", + "Bash(netlify deploy:*)", + "Bash(fly deploy:*)", + "Bash(wrangler deploy:*)", + "Bash(supabase db push:*)" + ] + } +} diff --git a/skills/bbq/SKILL.md b/skills/bbq/SKILL.md new file mode 100644 index 0000000..b4fa31b --- /dev/null +++ b/skills/bbq/SKILL.md @@ -0,0 +1,99 @@ +--- +name: bbq +description: The fast build, for a hackathon, a prototype or a quick iteration. Takes what to build and a time box, asks nothing, runs on its own to a working demo, reviews itself, lists what it faked. Invoke on "/bbq ", "bbq this", "hack this together", "quick prototype", "build it fast". +--- + +# bbq + +the grill: fast, hot, a bit burnt. the user says what, this runs to a demo that works, on its own. `/cook` is for work that has to survive. this is for work that has to exist by tonight. + +`~/.claude/RULES.md` still holds. speed comes from cutting ceremony, never from cutting the user's yes or the truth about what works. + +## 0. start in one message + +no questions and no plan to approve. read the ask, then say all of this in one message and start: + +``` +bbq: ,