---
name: multi-agent-update
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."
user-invocable: true
argument-hint: ""
metadata:
  language: en
---

## After the install, check it

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

An update is the moment the layout changes, so it is the moment a layout check is
worth most: a script that moved, a host tree that did not get the copy, a version
stamp that disagrees with the package. 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.

A git clone of the pipeline repo is a maintainer workspace, kept in sync by `/multi-agent:sync` - it is never consulted here. A fix that only exists on `main` reaches users when a release is published, not before.

## Steps

Every fenced block runs in a fresh shell; step 1 writes the values later steps
need to a state file, and each later block sources it. Detail and the step 6
summary format: `$HOME/.claude/multi-agent-refs/update/details.md`, or on
GitHub https://github.com/multi-agent-ecosystem/multi-agent-pipeline/blob/main/pipeline/multi-agent-refs/update/details.md

1. **Resolve the package and both versions** (read the registry directly,
   never `npm view`):
   ```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/.copilot/.pipeline-version" 2>/dev/null)
   [ -n "$CUR" ] || CUR="unknown"
   LATEST=$(curl -fsS "$REG/$(printf '%s' "$PKG" | sed 's|/|%2F|')/latest" \
     | node -pe 'JSON.parse(require("fs").readFileSync(0,"utf8")).version' 2>/dev/null)
   [ -n "$LATEST" ] || { echo "Registry unreachable ($REG) - check your network and retry."; exit 1; }
   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"
   ```
2. **Stop early when already current**: when
   `[ "$CUR" = "$LATEST" ]` (after sourcing the state file), skip step 3 and
   continue at step 4b.
3. **Download the release and install** (pin the scope: `--registry` alone
   loses to an `.npmrc` scope mapping; never glob into tar; the file name comes
   from the JSON on stdout, with npm's notices kept apart on stderr):
   ```bash
   . "${TMPDIR:-/tmp}/multi-agent-update.env" || { echo "Run step 1 first."; exit 1; }
   rm -rf "$UPD_DIR" && mkdir -p "$UPD_DIR"
   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"; exit 1; }
   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.
4b. **Update the stack plugins**:
   `bash "$HOME/.copilot/scripts/plugin-refresh.sh" {owner} > "${TMPDIR:-/tmp}/multi-agent-plugin-refresh.log" 2>&1`,
   then show the log; a non-zero exit is reported, never retried silently.
5. **Migrate preferences**:
   `[ -f "$HOME/.copilot/scripts/migrate-prefs.mjs" ] && node "$HOME/.copilot/scripts/migrate-prefs.mjs"`
5b. `node "$HOME/.copilot/scripts/usage-register.mjs" --json` - operational reporting.
   It requests a per-machine **write-only** token when none resolves, stores it in
   the credential store only, and switches reporting on. A no-op when a token is
   already onboarded and the server still accepts it (a rejected token is
   replaced with no question; an unreachable check keeps it), and permanently
   blocked by `usageLog.optOut: true`. Offline or endpoint down leaves reporting
   off with one line, never an error. Contract:
   `$HOME/.claude/multi-agent-refs/features/usage-reporting.md`.
   Ask only when the JSON line carries `"needsPersonalAccount":true` (false
   whenever the account is already known), and nothing else. Then ask once for
   the GitHub username (Skip leaves reporting off) and run
   `node "$HOME/.copilot/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; `deferred` means the accounts were not visible). 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. Show `account.temporaryPassword` exactly once (username,
   password, `account.loginUrl`, changed at first login), then never repeat,
   store or pass it on. `failingSince` gets 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**: source the state file, then
   ```bash
   NEW=$(tr -d '[:space:]' < "$HOME/.copilot/.pipeline-version" 2>/dev/null)
   NOTES="$UPD_DIR/package/pipeline/scripts/release-notes.mjs"
   [ -f "$NOTES" ] || NOTES="$HOME/.copilot/scripts/release-notes.mjs"
   LOG="$UPD_DIR/package/CHANGELOG.md"; [ -f "$LOG" ] || LOG=/nonexistent
   node "$NOTES" --changelog "$LOG" --from "$CUR" --to "$NEW" \
     --plugin-refresh-log "${TMPDIR:-/tmp}/multi-agent-plugin-refresh.log"
   ```
   Summarise the JSON in `outputLanguage` (version line, plugin lines, New /
   Fixed / Changed / Removed). Use only what it says; never invent a change.
7. **Smoke test (optional)**: `bash "$UPD_DIR/package/pipeline/scripts/smoke-schema-validation.sh"`
   and `smoke-cross-cli-behavior.sh` from the same directory, each `| tail -1`,
   then `rm -rf "$UPD_DIR" "${TMPDIR:-/tmp}/multi-agent-update.env"`.

## Usage

```
/multi-agent-update
```

Output:
```
v14.2.2 → v15.0.0 updated
  5 commits, 25 files changed
  schema-validation: 27/27 pass
```
