# Coding-Agent Prompt — Task Skeleton

Copy this to `/tmp/opencode_prompt.md`, fill in the placeholders, and feed to `opencode run`.

```markdown
# Task

[1-3 sentences: what to build/change and what the user is trying to achieve.]

## Context

[Optional. Anything the agent can't infer from `ls`/`cat` — domain rules, naming conventions, the project's existing patterns to mirror. Cite file paths so the agent can `Read` them.]

## Reference (if any)

If there's a reference repo or doc, name it and the specific file:

> Reference: https://github.com/foo/bar/blob/main/api/remains.ts
>
> Mirror its [field names / endpoint / auth scheme], but use the language of this project.

## Files to modify (be exhaustive)

- `/abs/path/to/a.py` — [what to change]
- `/abs/path/to/b.py` — [what to change]
- `/abs/path/to/c.yaml` — [what to change]

Files NOT to touch: [list any — explicit guidance helps the agent stay scoped.]

## API / schema details (verbatim)

```json
{
  "field_name_type": "endpoint_url",
  "response": { "shape": "..." },
  "status_codes": { "0": "success", "1004": "invalid api key" }
}
```

The agent often misses edge cases buried in the response schema. Reproduce them explicitly here.

## Constraints

- No new dependencies (use stdlib + existing project deps).
- Don't add a default secret value in any example.
- Match the existing module's error envelope: return `{success: false, error: str}` not exceptions.
- Use `from __future__ import annotations` at top of new Python files.

## Naming

Explicit, especially for non-standard choices:

> Naming: keep `MiniMax` non-standard casing (matches user's reference repo).
> File: `backend/app/MiniMax_quota.py`, endpoint `/api/MiniMax/quota`,
> config key `MiniMax_accounts`. Apply consistently across all files.

## Output (the agent MUST print these at the end)

1. Files modified (absolute paths) with `git diff --stat`-style counts.
2. Result of `python -m py_compile` for any modified Python files (must be exit 0).
3. Confirmation that no default secrets were added to example/sample files.

## Rules

- Use Bash freely. No need to ask confirmation.
- Don't add files I didn't list.
- Don't reformat code in files I didn't list.
- If you encounter a contradiction between this prompt and the codebase, STOP and report it.
```

# Coding-Agent Prompt — RESUME Skeleton

Use this when a previous `opencode run` was killed mid-task (model swap, timeout, error, manual kill) and you're launching a fresh agent to continue.

```markdown
# Task RESUME — earlier run did ~X0% before being killed

## Context: partial work ALREADY done

MUST list every file the previous run touched, with line counts / current state:

- ✅ `/abs/path/to/foo.py` — FULLY IMPLEMENTED (lines 1-NNN).
  Don't rewrite; keep intact.

- ⚠️ `/abs/path/to/config.py` — partial:
  - Added `BarConfig` dataclass at L28-33
  - Added `bar_accounts` field to `AppConfig` at L48
  - Added `_parse_bar_accounts()` helper function (NOT YET CALLED)
  - **NOT YET DONE:**
    - `parse_config` still uses inline parsing — make it call `_parse_bar_accounts(...)`
    - `AppConfig()` constructor at the bottom of `parse_config` is MISSING
      the `bar_accounts=` argument — add it.
    - The empty-check at L147 only checks opencode/ollama; update to also
      include bar_accounts.

- ❌ `/abs/path/to/main.py` — NOT YET TOUCHED. Add this endpoint here.

- ❌ `/abs/path/to/example.json` — NOT YET TOUCHED. Add `"bar_accounts": []`.

## What I need from you

1. [concrete step, file-scoped]
2. [concrete step, file-scoped]
3. [concrete step, file-scoped]

## Constraints

[Same as a fresh prompt — no new deps, no default secrets, etc.]

## Verification (you must run these yourself)

After edits, run:

```bash
python -m py_compile backend/app/foo.py backend/app/config.py backend/app/main.py
python -c "from app.config import parse_config; print(parse_config({'bar_accounts':[{'api_key':'sk-test12345'}]}).bar_accounts[0].name)"
```

Both must succeed. Then print `git diff --stat` summary.

## Output

1. Files modified (absolute paths) with diff stat.
2. Result of `python -m py_compile` (exit 0).
3. Confirmation that no default API key landed in the example.

## Rules

- Don't rewrite files I marked ✅.
- Don't add files I didn't list.
- If you find the previous run's code has a bug, fix it minimally and report it — don't rewrite the whole file.
```

# Python Smoke-Verification Skeleton

After any Python refactor done by an external agent, this 4-line block catches what `py_compile` misses:

```bash
cd /path/to/project
python -m py_compile backend/app/foo.py backend/app/bar.py backend/app/baz.py && echo "PY_COMPILE_OK"

cd backend && python -c "
from app.foo import fetch_all
from app.config import parse_config
# 1. Empty input — should not crash with import errors
parse_config({})
# 2. Minimal happy path — should expose the new API the spec required
cfg = parse_config({'new_accounts': [{'name': 'A', 'key': 'sk-test12345'}]})
assert cfg.new_accounts[0].name == 'A'
# 3. (Optional) Run the actual network call if a valid key is available
print('WIRING_OK')
"

git diff --stat
```

If `WIRING_OK` doesn't print, the agent's work isn't done — find the assertion that failed and figure out what wiring is missing.

# General Prompt-Crafting Rules (apply to both skeletons)

- **Exact paths, exact lines.** If you can cite `L28-33` or `line 47`, the agent finds it instantly. "around there" wastes turns.
- **Spec verbatim, not paraphrased.** When the user gave you API field names or schema, copy them verbatim. The agent will rewrite if your paraphrase differs.
- **Explicit "NOT to do"** beats implicit defaults. "Don't add a default API key" stops it; "be careful with secrets" doesn't.
- **One focused task beats one sprawling one.** If the spec is multi-domain, split into multiple `opencode run` calls, each scoped.
- **Always define the verification step inside the prompt** — agents that "self-verify" without an explicit recipe often skip the part where they'd have caught a bug.
