---
name: netsi-prompt-optimize
description: >
  Rewrites a weak prompt into a strong, precise one using only the techniques
  that empirically improve answers (specification, verification-with-signal,
  information grounding) — never persona/role-play, which measurably hurt. Use
  whenever the user writes /netsi-prompt-optimize, or asks to "optimize this
  prompt", "improve my prompt", "make this prompt better", "rewrite this prompt",
  "why is my prompt giving bad answers", or wants a prompt that works better on a
  small/local LLM. Also use when the user pastes a prompt and complains the output
  is vague, wrong, off-tone, too long, or ignores their constraints. Always run
  this skill for any /netsi-prompt-optimize command — produce the rewritten prompt,
  don't just answer the original.
metadata:
  tags:
    - prompt-engineering
    - prompt-optimization
    - specification
    - local-llm
  version: 1.0.0
---

# /netsi-prompt-optimize — Prompt Optimizer

Turn a weak prompt into a strong one. This skill applies **only** the levers that
were measured to actually improve LLM answers (especially on small local models):
**specification, verification-with-a-real-signal, and information grounding.** It
deliberately avoids persona / "imagine you are" / role-relay framing, which added
confident-sounding text and even new errors without improving correctness.
The reasoning and evidence live in `references/principles.md`.

## Trigger format

```
/netsi-prompt-optimize [the raw prompt to improve]
```

Examples:
- `/netsi-prompt-optimize explain spirituality to me simply`
- "Optimize this prompt: write a function that dedupes an array"
- "My local model gives rambling answers to this prompt — fix it"

If a prompt follows the command (or is pasted/attached), treat it as the input and
optimize it directly — don't ask "what's your prompt?" again.

## Language

Talk to the user in the language they write in. But note: for **small local
models**, English *instructions inside the prompt* were the single biggest quality
lever. So the optimized prompt itself may be written in English even when chatting
in Danish — tell the user why, and honour any explicit "keep it in Danish" request
(the output language is then stated as a constraint inside the prompt).

---

## TASK-000: Detect input and mode

1. **Get the raw prompt** from the command, pasted text, an attached file, or a
   `task.md`. If none is present, ask for it in one line.
2. **Decide whether verification applies.** Verification (a critic→revise pass)
   only helps when there is a *real* signal to check against — otherwise a
   self-judging critic invents "missing" requirements and makes the answer worse
   (this happened in testing). A real signal means one of:
   - **Reference material** the user supplied (facts, docs, a spec) → check the
     answer against it.
   - **A verifiable task** — code that can be run/tested, structured output that
     can be validated against a schema, a math result that can be checked.
   If neither is present, **do not run a critic loop.** Optimize the prompt, answer
   it, and stop.

---

## TASK-001: Optimize the prompt (always)

Rewrite the raw prompt into a precise, self-contained prompt that:

1. **States the task** unambiguously — one clear instruction, no vague verbs.
2. **Preserves the user's own constraints exactly.** If they said "3 short
   paragraphs", keep 3. Do **not** change their numbers and do **not** invent new
   constraints (length, format, sections) they never asked for. Adding a limit the
   user didn't request is only OK when the original had none *and* it clearly
   serves them — flag it if you do.
3. **Makes the implied audience and reading level explicit** and tells the model to
   match it (e.g. "for a total beginner; plain language, no jargon").
4. **Adds a short "Success criteria" checklist** derived *only* from what the task
   actually asks for.
5. **Forbids invented specifics** — no made-up names, citations, dates, or
   biography. If the model is unsure, it should say so plainly.
6. **Mentions code hygiene only if the task involves code** — then require valid,
   runnable code in a widely-known language (Python/JavaScript) unless another is
   specified, and make the task's language requirement override any default.
7. **Sets the output language** as an explicit constraint when it matters.
8. Contains **no persona, no flattery, no grandiosity** ("you are a world-class
   expert" was measured to backfire). Keep it concise.

Present the result as a fenced, copy-pasteable block titled **Optimized prompt**,
followed by 2–4 bullets on *what changed and why* (anchored to the rules above).

---

## TASK-002: Answer only after the user confirms

The default deliverable is the **optimized prompt** — not the answer. After
presenting it (TASK-004), **stop and ask** whether the user wants you to:
- answer the optimized prompt here, or
- run it against a small/local model via the script (TASK-005), or
- nothing — they'll take the prompt and use it themselves.

Do **not** produce the answer until they choose. Only when they ask you to answer:

1. **Answer the optimized prompt.** Follow the same quality contract: match the
   audience, obey the constraints, invent nothing, keep code valid.
2. **If — and only if — TASK-000 found a real signal**, run one verification pass:
   - **Critic (hardened):** list only concrete, fixable problems: violations of
     constraints *explicitly stated* in the prompt; claims that contradict or are
     unsupported by the reference; invalid code; made-up specifics. **Never invent
     new requirements** (citations, academic rigor, extra sections) the prompt
     didn't ask for. Output problems, or exactly `NO ISSUES`.
   - **Revise:** fix only what the critic flagged; keep the rest. If `NO ISSUES`,
     leave the answer unchanged.
3. **No signal → no critic loop.** Deliver the answer from step 1 as final. Say why
   ("no reference to verify against, so a self-check would risk inventing
   problems").

---

## TASK-003: Never do (measured anti-patterns)

- **No persona / role framing.** No "act as / imagine you are / world-class expert".
- **No role-relay or multi-expert ensembles.** Same-model personas share the same
  blind spots → correlated errors, no gain.
- **No self-refine loop without a signal.** Extra self-judged passes add confidence,
  not correctness, and can degrade a correct answer.
- **No inventing constraints** in the optimized prompt that the user didn't state.

See `references/principles.md` for the experiments behind each of these.

---

## TASK-004: Output format

By default, deliver only:

1. **Optimized prompt** — a fenced block the user can copy and reuse. This is the
   primary artifact.
2. **What changed** — a few anchored bullets.
3. **One-line offer** — ask whether to answer it here, run it on a small/local
   model (TASK-005), or stop. Then wait.

Only *after* the user asks you to answer, append:

4. **Answer** — the response to the optimized prompt.
5. **Verification note** — either the critic/revise result (if a signal existed) or
   one line stating it was skipped and why.

Keep it tight. Never jump straight to the answer — the optimized prompt is what
this skill returns.

---

## TASK-005: Running it on a small / local model

For repeatable use against a local model (Ollama) or the Anthropic API, this skill
bundles a production script: `scripts/claude-optimize-prompt.ts`. It does exactly
TASK-001→TASK-002 as code (optimize always; critic→revise only when a
`reference.md`/`REFERENCE` is present) and writes `optimize-out.md`.

```bash
# Local small model
MODEL=llama3.2 deno run -A scripts/claude-optimize-prompt.ts "the raw prompt"

# Factual task with grounding — auto-enables the critic loop
REFERENCE="$(cat facts.md)" deno run -A scripts/claude-optimize-prompt.ts "the raw prompt"

# Anthropic instead of Ollama
PROVIDER=anthropic ANTHROPIC_API_KEY=sk-... deno run -A scripts/claude-optimize-prompt.ts
```

Env knobs: `PROVIDER` (ollama|anthropic), `MODEL`, `OLLAMA_URL`, `TEMPERATURE`,
`VERIFY` (auto|on|off), `REFERENCE` / `reference.md`.

Offer to run or adapt the script when the user's real target is a small model;
otherwise just apply TASK-001→TASK-004 inline yourself.

---

## TASK-006: Knowledge base priority

1. The user's own prompt and stated constraints come first — never override them.
2. Otherwise apply the principles in `references/principles.md`.
3. When the target is a small local model, weight **English instructions** and
   **information grounding** highly — they moved quality most in testing.
