diff --git a/.ai-superpower b/.ai-superpower new file mode 100644 index 0000000..9d785d6 --- /dev/null +++ b/.ai-superpower @@ -0,0 +1,12 @@ +ai-superpower + +# This file exists so that apply.sh can identify this repo as itself. +# +# apply.sh scans all directories that contain a .git folder and creates a +# .ai symlink in each one. Without this file, apply.sh would also symlink +# this repo into itself, producing .ai/.ai → .ai/ (infinite loop). +# +# WARNING — do not delete this file: +# - apply.sh will create a .ai/.ai symlink inside this repo pointing to itself +# - the next apply.sh run will loop or crash +# - fix: restore this file and remove the .ai/.ai symlink that was created diff --git a/.ai/instructions/behavior/docs.instructions.md b/.ai/instructions/behavior/docs.instructions.md index 5155818..aaf109a 100644 --- a/.ai/instructions/behavior/docs.instructions.md +++ b/.ai/instructions/behavior/docs.instructions.md @@ -27,6 +27,25 @@ Keep under 200 lines. Link to `architecture.md` for diagrams. --- +## Factory template marker + +`docs/ai-context.md` and `docs/architecture.md` may start with this block: + +``` + +``` + +**When you first touch a file that has this marker — even just to read it before writing — remove the marker line as the very first edit:** +1. Remove the line `` +2. Then write the actual content + +The marker's presence tells `apply.sh` the file has not been edited yet and will be overwritten on the next run. Once removed, the file is owned by the project and will never be overwritten. + +--- + ## Rules - Docs are **not** a changelog — no "updated X on date Y" diff --git a/.ai/instructions/skills/git.instructions.md b/.ai/instructions/skills/git.instructions.md index 78ae15f..d34871e 100644 --- a/.ai/instructions/skills/git.instructions.md +++ b/.ai/instructions/skills/git.instructions.md @@ -46,8 +46,7 @@ When the user asks for a commit message: 1. **Run `git diff --staged` or `git diff`** — read what actually changed 2. **Documentation check** — scan the changed files and ask: does any `docs/` or `README.md` need updating based on these changes? If yes, flag it clearly before writing the message. Do not block the commit — just surface it. -3. **Write the commit message** — one short subject line, optionally a blank line and brief body if the change needs context -4. **Show the command** — display the full `git commit -m "..."` for the user to run themselves +3. **Write the commit message only** — one short subject line, optionally a blank line and brief body if the change needs context. Output just the message text in a code block. Do NOT wrap it in a `git commit` command. Format: ``` diff --git a/.ai/instructions/skills/mermaid.instructions.md b/.ai/instructions/skills/mermaid.instructions.md index c7611d3..dafc7a0 100644 --- a/.ai/instructions/skills/mermaid.instructions.md +++ b/.ai/instructions/skills/mermaid.instructions.md @@ -1,5 +1,20 @@ # Mermaid Diagram Instructions +--- + +## Edge Labels + +Use `-- "text" -->` syntax, **not** `-->|text|` syntax. + +`|` inside `-->|label|` breaks parsing if the label contains a pipe character (e.g. `curl | bash`). Quoted syntax always works: + +``` +✅ A -- "curl | bash" --> B +❌ A -->|curl | bash| B +``` + +--- + ## Color Contrast — CRITICAL All Mermaid diagrams MUST have sufficient color contrast. AI-generated diagrams often fail this. diff --git a/.gitignore b/.gitignore index 23fe5e8..de3a5f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.ai-instructions.conf +.ai-superpower.version tmp/ +.ai diff --git a/README.md b/README.md index cfe0285..2998283 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ai-superpower AI instructions scatter across a large number of projects. Maintaining them inside each project individually is not practical — a single change requires manual updates everywhere. -This repo solves that: instructions live in one place and are distributed to all projects from here. +This repo solves that: a central `.ai/` folder is installed in your dev root, and every project gets a symlink to it. A `git pull` + re-run of `apply.sh` updates all projects instantly. AI requires strong guidance to support human workflows rather than override them. Treat its outputs as zero-trust: the human reviews everything and must be willing to put their name on what the AI produced. @@ -10,35 +10,45 @@ Good instructions are what make that possible — they allow AI to produce outpu ## Principles - **Generic vs. project-specific** — `.ai/` instructions know nothing about individual projects. Project knowledge lives in each project's own `docs/ai-context.md`. -- **Sync writes only to `.ai/`** — never touches project code or `docs/`. +- **Single install, real folder** — `apply.sh` copies `.ai/` into your dev root. Every project symlinks there. One source of truth, zero drift. - **Modular loading** — AI loads only the relevant instruction files per task, not everything at once. -- **One change, all projects** — edit here, run sync, done. +- **One change, all projects** — re-run `apply.sh`, done. `.ai/` is refreshed and all symlinks already point to it. - **Version controlled** — instructions are managed in git. Changes are tracked, history is preserved, and rolling back is straightforward. -## Usage +## Install -Clone this repo directly into your dev root — the folder where all your projects live. The dev root can be anything (`~/koodi`, `~/projects`, `C:\dev`), but `ai-superpower` must be an immediate child of it. The script uses its own location to determine where to look for projects. - -``` -dev_root/ ← can be anywhere -├── ai-superpower/ ← must be here, at this level -├── project-a/ -├── project-b/ -└── some-folder/ - └── project-c/ ← nested projects are found automatically -``` +Run this from your dev root — the folder where all your projects live: ```bash -cd ~/koodi -git clone https://gitea.nikos-dev.keskikuja.site/niko/ai-superpower.git +curl -fsSL https://gitea.nikos-dev.keskikuja.site/niko/ai-superpower/raw/branch/main/apply.sh | bash ``` -From there, run the appropriate script depending on how you use your editor: +This script **must be run via `curl | bash`** from your dev root. Running it directly will fail with instructions to use the curl command. -- **One project per editor window** — run `apply.sh`. It copies `.ai/` into each project and sets up context files. -- **Dev root as single workspace** — run `apply.sh`. Skips `.ai/` distribution (not needed), only sets up per-project context files. +What it does: +1. Clones (or updates) this repo into `dev_root/ai-superpower/` +2. Copies `.ai/` into your dev root as a real folder +3. Scans for all projects (up to 4 levels deep) and creates a `.ai` symlink in each +4. Adds `.ai` to each project's `.gitignore` +5. Creates `docs/ai-context.md` and `docs/architecture.md` templates in projects that have a `docs/` folder but no such files yet +6. Writes a `.ai-superpower.version` file to your dev root with the run timestamp and commit hash -See [apply.md](apply.md) for the full mechanism and [docs/architecture.md](docs/architecture.md) for the design. +``` +dev_root/ ← run curl from here +├── .ai/ ← installed here as a real folder (refreshed on every run) +├── ai-superpower/ ← cloned here automatically +├── project-a/ +│ └── .ai → dev_root/.ai/ ← symlink +├── project-b/ +│ └── .ai → dev_root/.ai/ ← symlink +└── some-folder/ + └── project-c/ ← nested projects found automatically (maxdepth 4) + └── .ai → dev_root/.ai/ +``` + +See [docs/apply-requirements.md](docs/apply-requirements.md) for the full requirements and [docs/apply-usecases.md](docs/apply-usecases.md) for a detailed flow diagram. + +## AI setup The AI must be instructed to always read `.ai/ai-root-instructions.md` at the start of every session. In your AI assistant's system prompt or custom instructions, add: @@ -52,19 +62,20 @@ Verify that every AI response begins with this confirmation. If it does not, the ``` ai-superpower/ -└── .ai/ ← synced to all projects +└── .ai/ ← source, copied to dev_root/.ai/ on every run ├── ai-root-instructions.md ← entry point, read first └── instructions/ - ├── behavior/ ← how AI approaches its work - ├── skills/ ← task-specific guides (git, docs, diagrams) - └── constraints/ ← what AI must not do + ├── behavior/ ← how AI approaches its work + ├── skills/ ← task-specific guides (git, docs, diagrams) + └── constraints/ ← what AI must not do -project-x/ -├── .ai/ ← written by sync -└── docs/ - └── ai-context.md ← project-specific, never synced +dev_root/ +├── .ai/ ← real folder (copy of above) +└── project-x/ + ├── .ai → dev_root/.ai/ ← symlink + └── docs/ + ├── ai-context.md ← project-specific context, never overwritten once customised + └── architecture.md ← project architecture, never overwritten once customised ``` -Clear architecture documentation — written following the instructions in this project — matters for both human and AI work. There must be a plan before building. The AI will consistently push for this, because without context it cannot work well. The vision always comes from the human; the AI helps carry it out under human supervision. - - +Templates for `ai-context.md` and `architecture.md` are deployed automatically to any project that has a `docs/` folder. They contain a factory-reset marker on line 1 — as long as that marker is present, `apply.sh` will refresh the file on every run. Once you (or the AI) edits the file and removes the marker, the file is yours and will never be touched again. diff --git a/apply.sh b/apply.sh index 65ea96e..aa16dd7 100755 --- a/apply.sh +++ b/apply.sh @@ -1,4 +1,142 @@ #!/usr/bin/env bash set -euo pipefail -echo "jee" +REPO_URL="https://gitea.nikos-dev.keskikuja.site/niko/ai-superpower.git" +REPO_NAME="ai-superpower" +RAW_URL="https://gitea.nikos-dev.keskikuja.site/niko/ai-superpower/raw/branch/main/apply.sh" + +# ── Bootstrap mode (curl | bash) ───────────────────────────────────────────── +# BASH_SOURCE[0] is empty when piped through bash +if [[ -z "${BASH_SOURCE[0]:-}" ]]; then + DEV_ROOT="$PWD" # capture before exec replaces the process + TARGET="$DEV_ROOT/$REPO_NAME" + if [[ -d "$TARGET" ]]; then + echo "→ updating $REPO_NAME ..." + git -C "$TARGET" pull || { echo "✗ git pull failed"; exit 1; } + else + echo "→ cloning $REPO_NAME into $TARGET ..." + git clone "$REPO_URL" "$TARGET" || { echo "✗ git clone failed"; exit 1; } + fi + # Pass DEV_ROOT explicitly — local mode must not guess it from script location + exec bash "$TARGET/apply.sh" --bootstrapped "$DEV_ROOT" +fi + +# ── Guard — block direct invocation ────────────────────────────────────────── +if [[ "${1:-}" != "--bootstrapped" ]]; then + echo "✗ do not run this script directly." + echo " run from your dev root folder:" + echo "" + echo " curl -fsSL $RAW_URL | bash" + echo "" + exit 1 +fi + +# ── Local mode ──────────────────────────────────────────────────────────────── +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +DEV_ROOT="${2:?DEV_ROOT not passed — re-run via curl}" +AI_TARGET="$DEV_ROOT/.ai" +TEMPLATE_MARKER=" B[Bootstrap: clone or pull ai-superpower] + B -- "exec apply.sh --bootstrapped" --> C[Copy .ai/ into DEV_ROOT] + + A -- "bash apply.sh" --> ERR[✗ Error: must run via curl] + + C --> D[Scan dev root for .git projects] + + D --> E{Projects found?} + E -- "No" --> NP[Print: no projects found] + E -- "Yes" --> G[Per-project setup] + + G --> H{.ai symlink → DEV_ROOT/.ai ok?} + H -- "Missing or broken" --> I[Create symlink] + H -- "Ok" --> J[Skip] + + I --> K + J --> K + + K{.ai in .gitignore?} + K -- "No" --> L[Add .ai to .gitignore] + K -- "Yes" --> M[Skip] + + L --> N + M --> N + + N{docs/ exists?} + N -- "No" --> O[⚠ Warning: no docs/ folder] + N -- "Yes" --> P{ai-context.md exists?} + + O --> S + P -- "No" --> Q[Create from template] + P -- "Yes, marker present" --> QR[Refresh from template] + P -- "Yes, no marker" --> R[Skip — developer owns file] + + Q --> S + QR --> S + R --> S + + S{architecture.md exists?} + S -- "No" --> T[Create from template] + S -- "Yes, marker present" --> TR[Refresh from template] + S -- "Yes, no marker" --> U[Skip — developer owns file] + + T --> V + TR --> V + U --> V + + V{More projects?} + V -- "Yes" --> G + V -- "No" --> W[Write .ai-superpower.version] + W --> X([✅ Done]) diff --git a/templates/ai-context.md b/templates/ai-context.md new file mode 100644 index 0000000..2e5c63b --- /dev/null +++ b/templates/ai-context.md @@ -0,0 +1,44 @@ + + +> **AI: remove the marker line above (``) immediately — in the same edit where you first touch this file, before anything else.** +> As long as that line exists, `apply.sh` will overwrite this file on every run. + +# — AI context + +> **Quickstart:** let the AI write this for you. Open the project in your editor and prompt: +> +> *"Read the codebase and write docs/ai-context.md for this project. Cover: what it does, the tech stack, architecture, key decisions, conventions, and anything else an AI needs to work here effectively."* +> +> Review, correct, and commit. You own this file — the AI drafts it. + +## What this project does + +> 2-4 sentences. What problem does this solve, who uses it, and what does it NOT do? + +## Stack + +> Languages, frameworks, key libraries, infrastructure — include versions where they matter. + +## Architecture overview + +> Link to docs/architecture.md. Do not duplicate content from there. +> Example: _See [docs/architecture.md](architecture.md)._ +> +> **Monorepo — AI:** scan the repo structure. If you find multiple services, apps, or components under separate subdirectories, tell the developer: +> - which subdirectories you identified as separate components +> - that each one should have its own `docs/ai-context.md` and `docs/architecture.md` +> - offer to create them one by one +> +> **Monorepo — developer:** if this repo contains multiple services or components, create a `docs/` folder in each one and ask the AI to write `ai-context.md` and `architecture.md` there. Link to them from this file. + +## Key decisions + +> Decisions that affect how the code is written and why. Especially anything that would surprise a new team member. + +## Conventions + +> How is code organised? What patterns are used consistently? What would a new developer get wrong on their first PR? + +## What AI should know + +> Context that affects how the AI should work here: frozen modules, deployment constraints, external dependencies, things to avoid. diff --git a/templates/architecture.md b/templates/architecture.md new file mode 100644 index 0000000..a2d8377 --- /dev/null +++ b/templates/architecture.md @@ -0,0 +1,46 @@ + + +> **AI: remove the marker line above (``) immediately — in the same edit where you first touch this file, before anything else.** +> As long as that line exists, `apply.sh` will overwrite this file on every run. + +# Architecture + +> **Quickstart:** let the AI write this for you. Open the project in your editor and prompt: +> +> *"Read the codebase and write docs/architecture.md for this project. Cover: what the system does, main components, data flow, infrastructure, key architectural decisions, and known constraints."* +> +> Review, correct, and commit. You own this file — the AI drafts it. + +## Overview + +> One paragraph: what is this system and what problem does it solve? +> Include a simple diagram or ASCII tree if it helps clarify structure. +> +> **Monorepo — AI:** scan the repo structure. If you find multiple services, apps, or components, tell the developer: +> - which subdirectories you identified as separate components +> - that each one benefits from its own `docs/architecture.md` +> - offer to create them one by one +> +> **Monorepo — developer:** if this repo contains multiple components, create a `docs/` folder in each and ask the AI to write `architecture.md` there. Link to them from this file. + +## Components + +> Each major component in 2-4 sentences: what it does, what it depends on, what depends on it. + +## Data flow + +> How does data move through the system? What enters, what is transformed, what is stored, what is returned? + +## Infrastructure + +> Where does this run and how is it deployed? Link to IaC files if they exist. + +## Key decisions + +> Architectural decisions that are not obvious from the code. +> For each: what was chosen, what was the alternative, why this one. + +## Constraints and limitations + +> What does this system not do well? Known bottlenecks, scaling limits, or technical debt areas. +