Use before building a feature, refactoring, designing APIs or module boundaries, doing performance work, or reviewing a pull request or diff, in any repo. Covers plain data, call-site-first API design, simple control flow, boundary parsing, behavior-first tests, and lens-based code review. Skip it only for small bug fixes, one-line edits, and questions that change no code.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Metis?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/gitrasheed-metis-metis-skill)
---
name: metis
description: Use before building a feature, refactoring, designing APIs or module boundaries, doing performance work, or reviewing a pull request or diff, in any repo. Covers plain data, call-site-first API design, simple control flow, boundary parsing, behavior-first tests, and lens-based code review. Skip it only for small bug fixes, one-line edits, and questions that change no code.
---
# Metis
These are strong defaults, not laws.
The task's scope and the repo's conventions outrank every rule here. Restructuring and cleanup apply only to code the task already changes, and new types or files the change itself needs are in scope; put anything wider in your report as a proposal. Relax a default when a local convention, the framework, the language's idioms, an object-oriented integration boundary, or generated code imposes a different shape, and keep the intent: clear responsibilities, understandable state transitions, readable tests.
Apply these defaults quietly. Code, comments, commit messages, and written reports never cite these rules or justify routine choices.
## Design
### API shape
1. Start from the call site, by wishful thinking. Write the top-level code first as if the perfect helpers already existed, named the way you would want to call them. If that code reads awkwardly, the abstractions are wrong. For a hard subsystem, treat the sketch as a hypothesis; get the implementation right first, then fit the interface to it.
2. Prefer deep modules: a simple interface over substantial work. A helper earns its place by changing the interface, such as its units, errors, types, or a step name the caller needs. If its interface is nearly as complex as what it hides, deepen it or inline it, unless callers outside the codebase depend on it.
3. Add new behavior through a focused function, variant, adapter, or wrapper rather than edits spread across existing branches. Hide awkward external APIs behind an adapter, so the rest of the code speaks the interface you wish existed. Translate a new input form into existing operations when they already express it.
4. Keep interfaces narrow enough that callers don't depend on operations they never use. Expose finished data directly instead of hiding it behind accessors. Export only the intended public surface from a package's entry points.
### State and effects
5. Keep domain state as plain data and put behavior in focused functions or modules. Draw boundaries around what systems do, not what entities are. If one new feature means editing many classes in a hierarchy, the boundaries are around nouns.
6. Choose the simplest state model that matches reality: a tagged union for mutually exclusive states, composable fields for traits that mix freely, and a plain flat record when neither pressure exists. Core state gets a named, typed shape, and raw dicts and strings stay at the boundary. Store each fact once and derive what you can compute from it, across subsystems too, rather than keeping a copy that can drift. When a copy is unavoidable, such as an index kept for speed or logic two sides can't share, test it against a fresh derivation, after rollbacks as well as updates. Every variant and implementation of an interface, test fakes included, honors the advertised behavior and its cost.
7. Keep I/O and mutation in a thin outer layer that orchestrates, and keep the logic inside pure and testable on plain values. Keep I/O clients out of the inner logic, and pass the current time and changing config in as values. Use mutation inside when it clearly improves correctness, interoperability, or performance.
8. Give each piece of state one owner and route every write through it, so changes flow one way, from commands to state to views. Count readers that dependency tracking can't see, such as globals and caches. When two pieces of state write each other, each patch adds another edge, so redraw the flow.
### Control flow
9. Push ifs up, fors down. The parent partitions the input and decides the cases, and leaf functions loop over uniform work with little branching. Regroup work this way only when the items are independent.
10. When elements of a batch can invalidate each other through duplicates, conflicts, or cross-record constraints, classify the whole batch before applying any element, even when applying incrementally looks cleaner.
### Boundaries and invariants
11. Parse, don't validate. Where untrusted data enters (requests, files, databases, external APIs), convert it once into a typed shape that cannot represent invalid states, and report bad input as a normal error. Downstream code does not re-check what the type guarantees. Never stand in for "failed", "unknown", or "out of range" with zero, an empty list, or the largest number, which read as real answers. Enforce a declared schema before dispatch or any side effect, and carry every option you accept through to its effect.
12. Assert internal invariants on state transitions and cross-record contracts where a broken one would corrupt state, money, or stored data, including transitions that should be impossible. A failed assertion means a bug, not bad input; a case only a bug could produce gets an assertion, not a clamp. Most functions need none.
13. Re-check only what can change after parsing, at the point of use. On shared state, make check-then-act one atomic operation: a unique constraint, a conditional write, or a transaction. A separate existence query followed by an insert is a race.
14. Define errors out of existence when every caller would handle the case the same way: an idempotent operation, a delete that succeeds when the target is already gone, a range that clamps. Otherwise return or raise the error with context and its original cause. Never swallow one silently; skipping a bad record is a deliberate, counted decision.
15. A side effect that can be retried or replayed, such as a send, a charge, or a write across a boundary, carries a stable identity like an idempotency key, and its owner atomically deduplicates on it. When an irreversible action depends on an earlier step succeeding, pass it that step's result for this specific operation instead of trusting call order. When you replace persisted state, keep the last good version readable until the new one is durable, confirm nothing before then, and treat a failed flush as lost data to recover, never as a call to retry.
### Cost and change
16. Design for the hardest real requirement first, then simplify downward. A real requirement is stated or clearly imminent, never imagined. Add a layer, interface, or extension point only when such a requirement or a test fake calls for it.
17. Optimize for the next change. Once the change works, ask what the next known feature costs. If the structure makes it expensive, for example by touching many branches or classes, restructure it to data plus one system.
18. Before changing something that crosses a boundary, such as an API other services call, a persisted format, or config read by deployments, find its callers and its stored data. Prefer an additive change, such as an optional parameter or reading both the old and new field name, and say in your report what breaks when you cannot avoid a break. Inside one codebase, update the callers instead of keeping a compatibility shim.
19. Before freezing an API or shared format, check what it forces callers to read, copy, or wait for. Gather an operation's independent I/O up front instead of chaining request, wait, request, and keep long CPU work off an event loop serving deadlines. Without a stated budget or measured miss, write the plain version.
## Working process
1. Once the interface is stable and a test harness exists, write the check, see it fail, make it pass, and rerun it. For a bug fix, turn the repro into one focused regression test in the repo's style and ship it with the fix; with no harness, report how you reproduced it.
2. Reuse before you invent. Search the codebase for an existing helper or type before writing a new one, and call or extend it even when its name is not the one you would choose.
3. Existing workarounds are not patterns to copy unless they encode a real constraint, so find out what one protects before you replicate it.
4. Fix causes, not sites. When two symptoms share a root, fix the root. When a defect exists in one place, look for its siblings; fix every site of the same defect in scope, and report other siblings as proposals.
## Tests
1. Spend test effort where breakage is costly: parsers, state machines, business rules, transformations, integration seams, and failure paths. Skip trivial getters and passthroughs.
2. Prefer integration, contract, or acceptance tests over unit tests that mirror implementation details, so a refactor does not force a test rewrite. When a fast path or shortcut stands in for a plain path, compare their results and errors on hand-picked edge cases, including one where only data the plain path skips would fail, and fall back where they might differ.
3. Write each case directly, one behavior per test, with no loops or branching in the test body, so a failure shows what broke. Use a parameterized test only when many cases share one shape and it beats writing them out.
4. Tests encode the real contract; change a test only when the expected behavior really changed. When you write a verifier, lint, CI gate, or counter, plant one violation and confirm it fails for that reason.
5. Make async tests and races wait on an explicit signal, never a fixed sleep. Keep a timeout only as a failsafe.
6. Treat tests you wrote while exploring as scaffolding. Before committing, keep the ones that guard stable behavior or a real regression, in the repo's test style, and delete the rest. Don't re-test behavior the change didn't touch.
## Comments and slop
- Write no comments. The one exception is a line a careful reader would get wrong without one, such as a magic number: one line, saying why. Clear, short names do the rest.
- Remove slop from your own diff and flag it in review: duplicated null or defensive checks, tests that only prove the code you just wrote, speculative interfaces or factories, performance machinery (arenas, packed layouts, pools, caches) with no stated budget or measured miss, casts that dodge type errors, dead scaffolding, scratch scripts, untracked generated artifacts, and summary docs nobody asked for.
## Code review mode
Use this when reviewing a diff, a PR, or another agent's work. For a small diff, combine the lenses into one careful pass. For a large or complex diff, make one pass per lens.
Lens passes, in order:
1. Correctness and contracts. Does the change do what it claims, and do all variants honor the contract? Is untrusted data parsed at the trust boundary? Are failure paths handled? Can a failed read or a clamp pass as a real value? Is check-then-act atomic, and is a retried side effect deduplicated? Can a batch apply partly before a later item fails? Does a changed signature, config key, or persisted format break callers or stored data? Missing invariant protection on state transitions and cross-record contracts is report-worthy; validation that duplicates what a parser, type, or earlier boundary guarantees is noise.
2. Data and state. Check that state is plain data rather than behavior-heavy objects, that mutually exclusive states are unions, that mutation and I/O stay at the edges, that each fact has one owner, and that no two pieces of state write each other.
3. Control flow and API shape. Call sites read cleanly, ifs go up and fors go down, each module has one reason to change, interfaces are narrow, core logic does not depend on I/O clients, and nothing is speculative. Prescribe the structural remedy and name the new shape. A bloated signature wants a config object or a split of responsibilities, not keyword-only markers. A method that parses, shapes, sends, and decides error policy wants pure builders, an I/O port the caller can fake, and policy left with the caller. A hard-wired dependency wants a seam when many callers must test against it. Don't flag code for following an established repo convention; where the convention itself causes a defect, state the remedy in one sentence.
4. Tests and slop. Check the Tests rules and the slop list.
Findings:
- Trace each suspected defect upstream and downstream before reporting it.
- Report each finding as `file:line`, severity (blocking / should-fix / nit), and one sentence stating the problem and the fix.
- In your reply, tag each finding with its lens, e.g. `[lens 2: data and state]`, which forces a sweep of every lens. Drop the tags from anything posted to a PR or written to a file.
- Quality findings from lenses 2 to 4 are not padding. Report them at should-fix or nit severity even when blocking findings dominate, keeping only nits a teammate would act on. A lens may produce no findings; do not manufacture one.
## Hot paths
Use this section only when the task or repo states a latency, throughput, or memory budget, or a measurement shows a miss.
- On representative input, estimate the floor from the bytes that must move, the operations required, and the longest chain of dependent waits. Measure the plain path end to end and stop if it meets the budget. Otherwise explain the gap before tuning: a flat profile hides copies and waits paid in every stage. Choose an implementation once per batch, outside the loop.
- Multiply the bytes one record wastes by the peak number live. Count allocations per operation. Where spare capacity dominates, store finished data at its exact size; where a rare large variant does, move it out of line. Where building allocates repeatedly, build in caller-owned scratch and copy out once. Remeasure size and speed on the same input.
- Run both versions on the same workload and report any change in results, errors, or accepted inputs before the speedup.