# /aide:upgrade — Interactive Methodology Upgrade

> **Agent:** You are the orchestrator for this command. Do NOT delegate to a subagent.

> **CRITICAL — read this before doing anything:**
> This is a step-by-step wizard. You show ONE category at a time, ask ONE question using the `AskUserQuestion` tool with structured options, then STOP and wait.
>
> **Rules:**
> - Never show all drifted categories at once and ask "which do you want?"
> - Never offer "all" as an option
> - Every pause point MUST use `AskUserQuestion` with defined options
> - After every `AskUserQuestion`, STOP. Do not continue until the user responds.
> - The tool writes files to disk itself — you do NOT use the Write tool for file categories

Bring this project's AIDE methodology artifacts up to date with canonical by calling `aide_upgrade` and walking the user through each drifted category interactively.

## Two-call pattern

The tool uses a **two-call pattern**. The first call (no `category`) returns a lightweight summary. The second call (with `category`) writes files to disk and returns a manifest — no file content.

## Wizard flow

---

### Step 1: Call `aide_upgrade` (summary)

Call `aide_upgrade` with no arguments. The response is JSON with `framework` and `categories`. Each category has `files` (metadata only — no `canonicalContent`) and a `summary` with counts.

If all categories have `differs: 0` and `missing: 0`, and no file in any category has `status: "malformed"`, skip to **Project files** below — the project's own files can still be on an older format even when the package files are current.

Otherwise, proceed to walk through drifted categories one at a time.

---

### Step 2–N: Walk through drifted categories one at a time

For each category where `differs > 0` or `missing > 0`, or where any file's `status` is `"malformed"` (which doesn't increment `missing`; this happens in the `brain` and `hooks` categories), present ONLY that category:

- Name the category
- List which files differ or are missing (use `~` for differs, `+` for missing)
- Call `AskUserQuestion`:

```
question: "{Category} — {count} files need updating. Apply?"
header: "{Category}"
options:
  - label: "Yes, update" / description: "Write the canonical versions to disk"
  - label: "Skip" / description: "Keep current versions"
```

STOP. Wait for user response.

**If the user selects "Yes":**
1. Call `aide_upgrade` with `category` set to that category name
2. The tool writes all differs/missing files to disk itself and returns a manifest
3. Report what was updated (e.g., "Updated 2 files in .aide/docs/")

Then move to the NEXT drifted category. Present it the same way with `AskUserQuestion`.

**If the user selects "Skip":** Move to the next drifted category.

**Categories that are all `matches`:** Skip silently — don't ask about them.

---

### Special category handling

**pointer-stub:** The tool splices the canonical stub within marker boundaries, preserving user content outside the markers. This is handled by the tool during apply — just report the result.

**reference:** The tool and hook reference pages under `.aide/reference/` are their own category, separate from `methodology-docs`. Ask about them on their own; one yes writes every missing or changed page. Apply `version-metadata` too, or `aide_info` keeps listing the pages as outdated.

**mcp:** The manifest includes `prescription` data. Read the existing MCP config, show what would change, and call `AskUserQuestion`:

```
question: "MCP config — the aide server entry needs updating. Merge?"
header: "MCP"
options:
  - label: "Yes, merge" / description: "Update the aide entry in .mcp.json"
  - label: "Skip" / description: "Keep current MCP config"
```

On confirmation, read the config, merge the prescription, write with the Write tool. If `malformed`, tell the user and ask how to proceed.

- **Global is the canonical launch.** The aide entry runs the bare `aidemd-mcp` command from a global install. An entry that launches through npx carries `globalSwitch: { key, name, installed, installCommand }` instead of a prescription. Ask the user, saying that npx launches time out at session start. On yes, run `installCommand` first unless `installed` is true; if the install fails, say so and leave the entry as it is. Then call `aide_upgrade({ category: "mcp" })`: the tool re-checks the install and rewrites only that entry's command and args, under the key it already uses, and refuses while the package is not installed globally. Never write the entry yourself. A missing aide entry carries the global prescription plus `globalPackage`: install first, then merge.
- **Moving a pin to a newer version goes through `targetVersion`, and the tool writes it.** This is the one-time path for an older project pinned to a version that cannot switch itself; the next upgrade, on the new server, offers the switch. When the caller knows the latest version (the `/aide` boot passes `aide_info`'s `behind.latest`), call `aide_upgrade` with `targetVersion`: the `mcp` result then carries `pinMove: { from, to }` instead of a `prescription`. Install that version first (`npx -y @aidemd-mcp/server@{to} sync --help`, which exits 2 by design: printed help starting `Usage:` means the version is installed; anything else means it failed, so stop and leave the entry as it is), then apply with `aide_upgrade({ category: "mcp", targetVersion: "{to}" })`. The tool changes only the version in the aide entry and returns `status: "updated"`; never merge a `pinMove` yourself. A result carrying `instructions` means the pin was not moved: relay it.
- **Custom entries are left alone.** A custom aide entry (neither npx nor `aidemd-mcp`, e.g. a dev `node ./dist/index.js`) reports `matches` and is never offered a change.
- **Tips are information.** If a file carries a `tip`, surface it once, as information. Never turn it into a merge question.
- **The brain's launcher is not part of this step.** A legacy brain launcher is changed through `/aide:brain config`, which previews and applies it with the brain category's `brainChange: "launcher"` call.

**brain:** `.aide/config/brain.aide` is user-owned, so this category is not applied like the others. `/aide:brain config` drives it: that flow inserts missing sections with `aide_upgrade({ category: "brain" })`, previews and applies each outdated section or legacy launcher one at a time (`brainChange`, then `beforeHash`), adapts sections for a non-template backend, and seeds the brain. Do NOT call `aide_upgrade` with `category: "brain"` from this command — without `brainChange` it inserts missing sections. Skip the generic "Yes, update" question for this category and use the case below that matches the file's `status`.

- **Behind** (`status` is `differs`, with `missingSections`): the config is missing required sections. Use `AskUserQuestion`:

  ```
  question: "Your brain config is missing required sections: {missingSections joined by ", "}. Repair now?"
  header: "Brain"
  options:
    - label: "Yes, repair" / description: "Invoke /aide:brain config to add only the missing sections"
    - label: "Skip" / description: "Leave brain.aide untouched"
  ```

- **Outdated** (`status` is `differs`, with `staleSections` and/or `legacyLauncher`, alone or alongside `missingSections`): sections still carry an earlier template's text, or the brain launcher is a legacy form (`legacyLauncher` lists why: `unpinned`, `unversioned`, `older-pin`, `missing-auto-confirm`). Sections the user edited and custom launchers are never reported. Fold every kind present into one `AskUserQuestion`:

  ```
  question: "Your brain config {is missing sections: … / has outdated sections: … / uses a legacy launcher (…)}. Review now?"
  header: "Brain"
  options:
    - label: "Yes, review" / description: "Invoke /aide:brain config — it shows each change as a before/after and changes nothing without your yes"
    - label: "Skip" / description: "Leave brain.aide untouched"
  ```

- **Missing or malformed** (`status` is `missing` or `malformed`): use `AskUserQuestion`:

  ```
  question: "Brain config — .aide/config/brain.aide is {missing|malformed}. Set it up now?"
  header: "Brain"
  options:
    - label: "Yes, set up brain" / description: "Invoke /aide:brain config to create or fix brain.aide"
    - label: "Skip" / description: "Leave brain.aide untouched"
  ```

On "Yes," invoke `Skill(skill="aide:brain", args="config")`. On "Skip," move to the next category.

**hooks:** AIDE's Claude Code hooks live only in each machine's uncommitted `.claude/settings.local.json`, calling this machine's installed server directly. The category can report up to three files: the local settings file, the shared `.claude/settings.json` (when it still holds AIDE's old entries, which the apply removes; every other entry stays), and `.gitignore` (when git doesn't yet ignore the local file). Before asking, check the results:
- **A file with `status: "malformed"`:** the category writes nothing. Tell the user which file can't be parsed, quoting its `instructions`, and that the hooks stay out of date until it's fixed. Don't offer to apply.
- **A `missing` result with `globalPackage` and `instructions` (no content):** AIDE isn't installed globally on this machine, so there is no server to point the hooks at. Tell the user, run the install command the `instructions` name via Bash only on their yes, then call `aide_upgrade` with no category again.
- **A result with a `tip`:** mention it once (for example, the local settings file is tracked by git and needs `git rm --cached .claude/settings.local.json`); it is never a reason to hold the apply.
Otherwise ask once for the whole category; one apply writes all its files.

**ide:** Use `AskUserQuestion` with multiSelect. VS Code steps return an `instructions` field — execute it if confirmed. Zed is written by the tool directly.

---

### Project files: run the upgrader — every time

The categories above refresh what the package ships. The project's own AIDE files — intent specs, plans, todo lists, briefs — may still be on an older format. Bringing them current is the `aide-upgrader` agent's job, and it runs at the end of **every** upgrade, with no condition to check first.

1. Delegate to `aide-upgrader` (via Agent tool, `subagent_type: aide-upgrader`) in **REPORT** mode. It reads the `[migration]` entries in `.aide/docs/changelog.md` (just refreshed by the docs category) and returns what is out of date, with a suggested value and evidence for each file that needs judgment.
2. **UP TO DATE** → say so in one line and go to the summary.
3. **MIGRATIONS FOUND** → walk the user through them with `AskUserQuestion`, one decision at a time:
   - **Batch entries** (`Confirm: once, as a batch`): one question per entry — name the change and the file count. Apply or skip.
   - **Per-file entries** (`Confirm: per file`): one question per file, offering the upgrader's suggested value first (with its evidence in the description) and the other allowed values as options.
   - Never apply anything the user did not choose.
4. Delegate the approved changes to `aide-upgrader` in **APPLY** mode, listing each one exactly.
5. Relay what it changed and anything a tool refused.

---

### Final step: Summary

Report what was done:
- Files updated per category
- Categories that were already current
- Categories the user skipped
- Project files migrated by the upgrader, and any the user left as they were

If anything changed — any file written, any pin moved, any project file migrated — tell the user to start a new session before doing more work. This session already loaded the old docs, skills and agents (and, after a pin move, the old server); a new session loads the new ones. If nothing changed, no restart is needed.
