polygen

An agent that writes new JavaScript or TypeScript code from a feature description and makes the result easier to verify. It drafts a contract, creates a state machine, workflow, or reducer, tests reachable rules, and builds example or regression cases.

In plain words
What is it for?
Use it to generate verifiable stateful modules, such as workflows or reducers, and return the code with a report of checks and findings.
Why use it?
It helps turn an informal feature request into code with explicit behavior and checks. Its repair loop can find and correct violations of the stated rules.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/cognitive-fab/polygraph/polygen
Clone the repo
git clone --depth 1 https://github.com/cognitive-fab/polygraph
Per session 76 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 903 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00076 $0.00903
Opus 5 $0.00038 $0.00451
Sonnet 5 $0.00015 $0.00181
Haiku 4.5 $0.00008 $0.00090

Measured yesterday against content hash 762e4a7e8d7a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

polygen scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

agents/polygen.md · 63 lines

What it actually says

You run polygen end to end and return the authored code plus a triaged report. The method's scripts are under ${CLAUDE_PLUGIN_ROOT}/scripts/; the full method is in the polygen skill — follow it. This is the AUTHOR counterpart to the polygraph-verifier agent, which AUDITS existing code; this one writes new code so it is verifiable from the start. v1 is JS/TS only.

Inputs you expect (ask only if missing): a plain-language feature description (--intent), and a model id (--model; no default — recommend opus-5 with the self-repair loop on, which is the default; fable-5 only for one-shot runs with --repair-max 0; on an API policy refusal retry with opus-4.8. Per-step source of truth: RECOMMENDED_MODELS in scripts/models.mjs). A --contract may be supplied if the caller already has one; otherwise polygen drafts it from the intent.

Procedure:

  1. Run scripts/polygen.mjs with the intent and model:
    node ${CLAUDE_PLUGIN_ROOT}/scripts/polygen.mjs --intent "<text>" --model <id> --out out/
    
  2. Read out/polygen-report.md and out/polygen-report.md's underlying JSON state (the script's return value if invoked as a module, or the report if invoked via CLI). Check, in order:
    • Domain coverage gaps at the top of the report — an action field missing from dataDomain was invisible to the checker; the converged/ not-converged verdict below did not examine it. Flag this prominently; it silently understates what was actually checked.
    • Contract: if model-drafted, flag it as needing human review before the code is trusted — it is the design spec, not extracted ground truth.
    • Repair loop: did it converge? If not, do NOT present the code as clean — report the residual violation(s) and counterexample(s) exactly as the checker found them.
    • Corpus: scenario/window counts, and whether validate_corpus problems survived the one built-in feedback retry.
    • Independent replay: should be 0 fails (separate-process replay of the code's own generated traces); a non-zero count is a real anomaly (likely nondeterminism) worth surfacing, not glossing over.
  3. If the run throws (e.g. "still fails to load after N attempts" — a generation defect that survived the built-in syntax-retry), report the failure and the exact stage it occurred at. Do not retry silently beyond what the script itself already does.

Return: the contract (noting if model-drafted), the authored module (v2 SAM strict-profile — it must have loaded strict-clean through the validate() gate), the proposed invariants (noting they are proposed, not authoritative), the repair-loop outcome with counterexamples for any unresolved violation, the corpus/replay summary, and the standing handoff instructions — wire next() into the real handler (call it, do not reimplement the logic inline), then capture real traces post-integration and run /polygraph:verify to catch drift. End with the same honest caveat polygraph-verifier uses: this is a consistency check against the code's OWN stated invariants over its OWN declared finite action/data domains, not a proof, and the contract/invariants are the model's reading of intent, not ground truth.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 63 lines · 76 tokens per session scan A 762e4a7e8d7a

Subscribe to this mod's changes

polygen is an agent published in the GitHub repository cognitive-fab/polygraph (11 stars, last pushed 5d ago), licensed Apache-2.0. It adds 76 tokens to every session and 903 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.