# Pipeline Repo Sync (Step 3)

Read by `/multi-agent:sync` before Step 3 (REPO), and before writing or reviewing
any synced shell script.

## Platform support (macOS only)

Only macOS is supported (ADR-0012). `package.json` declares `os: ["darwin"]`, which npm enforces on the root package, so this tree cannot be installed elsewhere, and a detection table for other hosts would describe a case that cannot occur.

**Contract for synced shell scripts.** The runtime is BSD userland and bash 3.2,
and that is a stricter constraint than "cross-platform", not a looser one:

1. Path handling: always quote (`"$f"`); use `$HOME`, never `/Users/...`.
2. `grep -P` is banned. BSD grep has no `-P`: it exits 2, and with `2>/dev/null`
   that reads as "found nothing". Use `-E`.
3. Timestamps: `stat -c %Y` FIRST, then `stat -f %m`. GNU-first ordering is
   required because `stat -f` is a valid GNU flag (`--file-system`) that
   succeeds and prints something that is not a timestamp.
4. Hashes: `sha256sum || shasum`, in that order. The gate fails a file that
   names either alone.
5. `find` traversal: `-prune` for `node_modules`, `Pods`, `.build`,
   `DerivedData`, `.next`.
6. Sed / awk: POSIX-portable. `-E`, never `-r`; `sed -i ''` on BSD.
7. Keychain I/O: always via `~/.claude/lib/credential-store.sh get|set`, never
   `security` directly - the wrapper is what keeps a secret off argv.
8. Verification: after Step 3 (REPO), `bash -n` every shell script in
   `pipeline/lib/` and `pipeline/scripts/`.

## Repo sync rules

1. **Source**: `~/.claude/commands/multi-agent/` + `~/.claude/multi-agent-refs/` + `~/.claude/agents/` + `~/.claude/lib/`
2. **Target**: `~/multi-agent-pipeline/pipeline/`
3. **Genericization** (must be applied BEFORE writing to the target):
   - Jira project key (`prefs.global.defaultJiraKey`) -> `{JIRA_KEY}`, `PROJ` in examples
   - Personal names/emails -> generic placeholder
   - Branch names -> `develop`
   - Project names -> `my-app`
   - `{JIRA_HOST}`, `{BITBUCKET_HOST}`, `{CONFLUENCE_HOST}`, `{CORP_DOMAIN}` stay as-is
   - **Verify**: `grep` scan for personal/corporate data inside pipeline/ -> 0 results
4. **File mapping**:
   ```
   ~/.claude/commands/multi-agent/        -> pipeline/commands/multi-agent/
   ~/.claude/multi-agent-refs/            -> pipeline/multi-agent-refs/   (refs + pickers, non-command)
   ~/.claude/commands/sim-test.md         -> pipeline/commands/sim-test.md
   ~/.claude/agents/*.md                  -> pipeline/agents/
   ```
5. **Files NOT synced** (local-only, may contain personal data):
   - `~/.claude/multi-agent-preferences.json`
   - `~/.claude/CLAUDE.md`, `~/.claude/rules/`, `~/.claude/knowledge/`
   - `~/.claude/scripts/`  -  EXCEPT `pre-commit-check.sh`, `agent-guard.sh`, `agent-guard.py`, and `build-stack-plugins.mjs` (generic, synced)
   - `~/.claude/settings.json`
   - `~/.claude/office/`  -  the office panel flows the other way: its source is the repo (`pipeline/office-src`, built by `office-build.mjs` into `pipeline/office`), and the installer copies it to each host. Never copy it from `~/.claude` into the repo; Step 3e checks it instead
   - `~/.claude/multi-agent-refs/registries/`  -  the installer copies gate registries there from the marketplace copy it delivers knowledge skills from; the repo holds their authoring source under `pipeline/skills/shared/external`
   - **Any `~/.claude/commands/multi-agent/*/SKILL.md` whose frontmatter has `local-only: true`** - these are user/repo-specific alias wrappers that delegate to a private marketplace plugin's skills exposed as `multi-agent:<name>`. Syncing them would leak the private plugin/skill names into the public pipeline. Skip them at copy time; the backstop below proves none reached `pipeline/commands/`.
     ```bash
     grep -rl "^local-only: true" ~/multi-agent-pipeline/pipeline/commands/ 2>/dev/null \
       && { echo "ABORT: local-only wrapper leaked into pipeline/commands"; exit 1; } || true
     # backstop: corporate refs only (generic ai-ios-toolkit is fine)
     grep -rniE "ai-(ios-engineering|mobile)-toolkit:(create-ui-component|evolve-ui-component|fix-bug|branch-and-pr|backlog|code-connect|figma-utility|resource-utility|component-wiki|component-docs|figma-setup)" \
       ~/multi-agent-pipeline/pipeline/commands/ 2>/dev/null \
       && { echo "ABORT: corporate reference leaked into pipeline/commands"; exit 1; } || true
     ```
   - **Installed-tree artifacts.** Picker descriptions are Turkish with a
     `description-en:` sidecar when `outputLanguage=tr`, and fable-tier agents
     carry `model: opus` while `fableEnabled` is off. The repo always gets the
     English form and `model: fable`, so normalize after copying:
     ```bash
     # normalize: restore English descriptions, strip description-en sidecars
     node ~/multi-agent-pipeline/pipeline/scripts/localize-commands.mjs restore \
       --dir ~/multi-agent-pipeline/pipeline/commands/multi-agent
     grep -rl "^description-en:" ~/multi-agent-pipeline/pipeline/commands/ 2>/dev/null \
       && { echo "ABORT: description-en sidecar leaked into pipeline/commands"; exit 1; } || true
     # backstop: repo description lines must be English (Turkish-diacritics proxy)
     grep -rn '^description:.*[çğıöşüÇĞİÖŞÜ]' ~/multi-agent-pipeline/pipeline/commands/ 2>/dev/null \
       && { echo "ABORT: localized description leaked into pipeline/commands"; exit 1; } || true
     node ~/multi-agent-pipeline/pipeline/lib/agent-model-sync.mjs --dir ~/multi-agent-pipeline/pipeline/agents --fable-on
     ```

6. **Cross-platform smoke gate** (final step of the REPO sync, before push):
   ```bash
   # bash -n: parse-level syntax check on every shell script
   find ~/multi-agent-pipeline/pipeline/lib ~/multi-agent-pipeline/pipeline/scripts \
        -name "*.sh" -type f -exec bash -n {} \;
   # Should print nothing  -  any output is a portability regression.

   # Portability grep: flag known non-portable constructs introduced post-sync.
   grep -rnE "stat -f[^[:space:]]+[^|]|sed -i[^[:space:]'\"]" \
        ~/multi-agent-pipeline/pipeline/lib ~/multi-agent-pipeline/pipeline/scripts || true
   # Each hit needs an explicit GNU/BSD fallback per the Platform Support contract.
   ```
   Gate failure -> abort push, surface the file + line, fix in the `~/.claude/` source first, re-sync.
