---
name: cpm-setup
description: Activate when the user wants to set up, render, or troubleshoot a CPM package (APM package + team-profile). Use for cpm init, cpm setup, cpm render, team-profile, model-mapping, oh-my-opencode-slim preset, missing model classes.
allowed-tools:
  - "Bash(python3 corentic-package-manager/cpm.py *)"
  - "Read"
  - "Write"
  - "Edit"
  - "Glob"
---

# CPM Setup Skill

Guides the user through: CPM package (APM manifest + team profile) → local model mapping → rendered harness preset (currently: oh-my-opencode-slim).

## The flow (Resolve–Validate–Render)

### 1. Find the team profile

Check whether a `team-profile.yaml` exists (package root or `corentic-package-manager/examples/package/team-profile.yaml`). Read it and summarize for the user:

```
Profile: acme.job-applications
Roles: orchestrator → strong-generalist, researcher → fast-research,
        writer → strong-writing, checker → high-reasoning, notifier → cheap-reliable
MCPs required: openviking, sharelatex (+ websearch/webfetch as OpenCode-native)
```

### 2. Check the mapping

Check `~/.config/cpm/model-mapping.yaml`. For **every** model class used in the profile an entry must exist.

If a model class is missing, offer the user concrete options (list available models from `~/.config/opencode/opencode.jsonc`):

```
No model assigned for 'high-reasoning'.
1. Pick an existing model (e.g. ollama/qwen3.6:35b-a3b-q4_K_M)
2. Configure a new provider/model in opencode.jsonc
3. Abort
```

After selection write the mapping and optionally mark `# selected_by: user`.

Alternatively use the interactive commands: `cpm init --fill` and `cpm setup`.

### 3. Check MCPs

Compare the MCPs named in the profile against the `mcp` section in `~/.config/opencode/opencode.jsonc`. Report missing ones to the user – never silently ignore. OpenCode-native tools (`websearch`, `webfetch`) are not MCPs and need no entry.

### 4. Render

```bash
python3 corentic-package-manager/cpm.py render --package <package-dir>
```

Show the output including warnings. The file `.opencode/oh-my-opencode-slim.json` is generated – never edit it manually.

### 5. Install package primitives

If the package declares an `apm.yml` with APM dependencies, the skills/instructions the roles reference are NOT deployed by cpm – APM does that:

```bash
cd <package-dir>
apm install        # requires the apm CLI (pip install apm-cli)
```

`cpm setup` offers this step automatically; when guiding manually, always run it before activation if dependencies exist.

### 6. Activate

Guide the user: `cd <package-dir>` (the generated config lives in its `.opencode/` directory!) → start `opencode` → `/preset <team-id>` → reload. Preset switches and skill loading both take effect only after a reload (by design). Activating writes the preset name to the global user config, so it persists across projects until switched again.

## Using the team

After activation the user works via the orchestrator in normal language ("Review X against our standards"). The orchestrator delegates per the generated routing prompts and consolidates results. Verify first with `/agents` and "ping all agents".

## Error handling

| Error | Fix |
|---|---|
| "Model class X is not mapped" | Step 2: add to mapping |
| "MCP ... not configured in opencode.json" | Step 3: set up the MCP or adjust the role |
| "No team profile found" | Check path, use `--team-file` |
| Invalid YAML | Follow the line number in the error message |

## Rules

- Never guess or assign models yourself – always let the user choose.
- Never edit the generated `.opencode/oh-my-opencode-slim.json` directly; sources are the team profile + mapping.
- Only ever tighten package security boundaries (MCP/skill allowlists), never widen them.
