---
description: "Update the pipeline to the latest published npm release: registry check, npm pack, install, migrate. Use when the installed pipeline is behind and should be brought to the latest version."
description-tr: "Pipeline'ı npm'deki son yayına günceller: registry kontrolü, npm pack, install, migrate."
allowed-tools: Bash, Read, Write, AskUserQuestion
parameters: []
gui: button
destructive: false
confirm: none
---

## After the install, check it

```bash
node "$HOME/.claude/scripts/doctor.mjs"
```

Report the result in `outputLanguage`.
Exit 2 means the update left the install in a state a run will fail from - say
that, do not report "updated" and stop.

# multi-agent update

Update the pipeline in one command. The npm registry is the single update channel: the latest published release is downloaded and installed. Existing preferences are preserved; only skill / script / schema files are refreshed.

Reasoning behind the steps, the step 6 summary format and a sample output:
`$HOME/.claude/multi-agent-refs/update/details.md`; read it before step 6.

A git clone of the pipeline repo is a maintainer workspace (`/multi-agent:sync`) and is never consulted here.

## Steps

Every fenced block below runs in a fresh shell, so no variable survives from one
block to the next. Step 1 writes the values the later steps need to a state file,
and every later block that needs them starts by sourcing it.

1. **Resolve the package and both versions**:
   ```bash
   STATE="${TMPDIR:-/tmp}/multi-agent-update.env"
   PKG="@{npm-scope}/multi-agent-pipeline"
   REG="https://registry.npmjs.org"
   UPD_DIR="${TMPDIR:-/tmp}/multi-agent-update"
   CUR=$(tr -d '[:space:]' < "$HOME/.claude/.pipeline-version" 2>/dev/null)
   [ -n "$CUR" ] || CUR="unknown"
   # Read the registry directly, never `npm view`.
   LATEST=$(curl -fsS "$REG/$(printf '%s' "$PKG" | sed 's|/|%2F|')/latest" \
     | node -pe 'JSON.parse(require("fs").readFileSync(0,"utf8")).version' 2>/dev/null)
   if [ -z "$LATEST" ]; then
     echo "Registry unreachable ($REG) - check your network and retry."
     exit 1
   fi
   # dist-tags.required is the supported-version floor (absent on most releases).
   REQUIRED=$(curl -fsS -H 'Accept: application/vnd.npm.install-v1+json' \
     "$REG/$(printf '%s' "$PKG" | sed 's|/|%2F|')" \
     | node -pe 'JSON.parse(require("fs").readFileSync(0,"utf8"))["dist-tags"].required || ""' 2>/dev/null)
   printf 'PKG=%q\nREG=%q\nUPD_DIR=%q\nCUR=%q\nLATEST=%q\n' \
     "$PKG" "$REG" "$UPD_DIR" "$CUR" "$LATEST" > "$STATE"
   echo "Current: v$CUR   Latest: v$LATEST${REQUIRED:+   Required floor: v$REQUIRED}"
   ```

   This command is never blocked by the floor  -  it is the remedy for it. The
   line above is where the floor is reported, so the user sees why a run halted.

2. **Stop early when already current.** When the line below prints, skip
   step 4 (no download, no reinstall) and still run step 3, so the stack
   plugins are refreshed either way:
   ```bash
   . "${TMPDIR:-/tmp}/multi-agent-update.env" || { echo "Run step 1 first."; exit 1; }
   [ "$CUR" = "$LATEST" ] && echo "✓ Already up to date: v$LATEST"
   ```

3. **Update the stack plugins first** (catalog refresh, then every installed plugin in its own scope):
   ```bash
   REFRESH_LOG="${TMPDIR:-/tmp}/multi-agent-plugin-refresh.log"
   bash "$HOME/.claude/scripts/plugin-refresh.sh" {owner} > "$REFRESH_LOG" 2>&1
   rc=$?
   cat "$REFRESH_LOG"
   echo "plugin-refresh exit: $rc"
   ```
   A non-zero exit means a step failed and the CLI's own error is already on screen. Report it to the user; do not retry silently. The log feeds step 6, which tells the user what each updated plugin brought.

   This runs **before** the install, not after: the installer delivers the
   knowledge skills from a copy of the marketplace, so refreshing it afterwards
   would leave every host on the copy the machine already had until the next
   update. The install's own fetch is a floor check against
   `schemas/plugins-pin.json`, not a refresh - a copy at the pinned version
   satisfies it, and this step is what moves the machine forward.

4. **Download the release and install**:
   ```bash
   . "${TMPDIR:-/tmp}/multi-agent-update.env" || { echo "Run step 1 first."; exit 1; }
   rm -rf "$UPD_DIR" && mkdir -p "$UPD_DIR"
   # Pin the SCOPE: `--registry` alone loses to an .npmrc scope mapping.
   SCOPE=$(printf '%s' "$PKG" | sed -n 's|^@\([^/]*\)/.*|\1|p')
   PACK_ERR="$UPD_DIR/npm-pack.log"
   PACK_OUT=$(npm pack "$PKG@$LATEST" ${SCOPE:+"--@${SCOPE}:registry=$REG"} \
     --registry "$REG" --pack-destination "$UPD_DIR" --json 2>"$PACK_ERR") || {
     echo "Download failed for $PKG@$LATEST:"; cat "$PACK_ERR"
     echo "If this says 'notarget', an .npmrc scope mapping is routing @${SCOPE} elsewhere:"
     echo "  npm config get @${SCOPE}:registry"
     exit 1
   }
   # Never glob into tar: take the file name from npm pack's JSON on stdout.
   # Notices go to stderr and can land mid-line, so they are kept out of it.
   TGZ="$UPD_DIR/$(printf '%s' "$PACK_OUT" | node -e 'let s="";process.stdin.on("data",(d)=>(s+=d)).on("end",()=>{try{process.stdout.write(String(JSON.parse(s)[0].filename||""))}catch{}})')"
   [ -f "$TGZ" ] || { echo "npm pack reported no tarball; aborting."; exit 1; }
   tar -xzf "$TGZ" -C "$UPD_DIR"
   node "$UPD_DIR/package/install.js" --installed
   ```

   `--installed` refreshes only the CLI targets that already carry a version
   stamp and adds none: an update never installs a CLI target the machine did
   not have.

4c. **Prune retired adapter files** (per-project adapter files are left untouched; see `details.md`):
   ```bash
   echo "  -> no global adapter files to prune"
   ```

   > **Do NOT delete `$HOME/.codex/prompts/multi-agent.md`.** The Codex installer
   > writes it and it backs the `/multi-agent` slash command on Codex CLI.

5. **Migrate preferences** (if there is an old schema):
   ```bash
   if [ -f "$HOME/.claude/scripts/migrate-prefs.mjs" ]; then
     node "$HOME/.claude/scripts/migrate-prefs.mjs"
   fi
   ```

5b. **Auto-configure operational reporting.** One call, the same one
   `/multi-agent:setup` and a first run make, so a machine is registered by
   whichever of the three runs first.

   ```bash
   node "$HOME/.claude/scripts/usage-register.mjs" --json
   ```

   It requests a per-machine **write-only** token when none resolves, stores it
   only in the credential store, and flips `usageLog.enabled` on. A stored token
   is checked with the server first; one the server rejects is replaced by
   registering again (a proof first, else the stored `usageLog.declaredLogin` or
   `registeredAs`, with no question), and a check that cannot reach the server
   keeps the token. `usageLog.optOut: true` blocks it permanently. Offline,
   endpoint down or ingest disabled leaves reporting off with one status line -
   never an error. Contract and the data it sends:
   `$HOME/.claude/multi-agent-refs/features/usage-reporting.md`.

   Ask a question only when the JSON line carries `"needsPersonalAccount":true`,
   and ask nothing else. Then ask once for the person's GitHub username (free
   text; Skip leaves reporting off) and run
   `node "$HOME/.claude/scripts/usage-register.mjs" --login <name> --json`,
   then say in one line that the site owner approves the name and that logs
   start after approval. Under `MULTI_AGENT_UNATTENDED=1` never ask (the flag
   is false there; a `deferred` status means the accounts were not visible
   and the next normal run registers). The flag is false whenever the account is already known (a provable gh,
   credential-helper or SSH account, a stored `declaredLogin`, or a pinned
   `registeredAs`), so a known account is never asked for. A `refusal`
   (`not_collaborator` or `proof_required`) only prints its status line: the
   site answers a declared name the same way whether or not it is a
   collaborator, so typing the name again would change nothing.
   Show `account.temporaryPassword` exactly once (with username, `loginUrl`,
   change at first login), then never repeat, store or pass it on.
   `failingSince`: one line, usage registration failing since <date>: <detail>;
   `pendingApproval` one line: the site holds records until its owner approves.

6. **Tell the user what the update brought.** Read the notes, then write the summary yourself:
   ```bash
   . "${TMPDIR:-/tmp}/multi-agent-update.env" || { echo "Run step 1 first."; exit 1; }
   NEW=$(tr -d '[:space:]' < "$HOME/.claude/.pipeline-version" 2>/dev/null)
   NOTES="$UPD_DIR/package/pipeline/scripts/release-notes.mjs"
   [ -f "$NOTES" ] || NOTES="$HOME/.claude/scripts/release-notes.mjs"
   LOG="$UPD_DIR/package/CHANGELOG.md"
   [ -f "$LOG" ] || LOG=/nonexistent
   node "$NOTES" --changelog "$LOG" --from "$CUR" --to "$NEW" \
     --plugins-dir "$HOME/.claude/plugins/marketplaces/multi-agent-plugins/plugins" \
     --plugin-refresh-log "${TMPDIR:-/tmp}/multi-agent-plugin-refresh.log"
   ```

   Turn the JSON into a short note in `outputLanguage` for the person using the
   pipeline, in the format of `details.md`, "Writing the step 6 summary" (version
   line, plugin lines, New / Fixed / Changed / Removed groups). Use only what the
   JSON says. Never invent a feature or a fix, and never guess why something
   changed. With empty notes and no plugin updates, print only the version line.

7. **Smoke test (optional)** - the release tarball ships exactly two smokes for this purpose:
   ```bash
   . "${TMPDIR:-/tmp}/multi-agent-update.env" || { echo "Run step 1 first."; exit 1; }
   echo ""
   echo "Verification:"
   bash "$UPD_DIR/package/pipeline/scripts/smoke-schema-validation.sh" 2>&1 | tail -1
   bash "$UPD_DIR/package/pipeline/scripts/smoke-cross-cli-behavior.sh" 2>&1 | tail -1
   rm -rf "$UPD_DIR" "${TMPDIR:-/tmp}/multi-agent-update.env"
   ```

## Output

See the sample in `details.md`.
