# The TypeGlish Loop

> How a prompt lives in TypeGlish. Six stages; the compiler judges every one.
> Human version: https://typeglish.dev/loop · Docs: https://docs.typeglish.dev/llms.txt

The Loop keeps humans in control while agents write the prompts. Every draft lands in
readable TypeGlish, the compiler enforces the team's rules and proves every change,
and humans audit short readable diffs. The prompt never becomes a black box.

## The six stages

1. **CONVERT** - your agent writes its first TypeGlish: converting an existing prompt
   is one command (`tg convert my-prompt.md`), new ones read like plain English.
2. **UNDERSTAND** - understand the impact of every word (`tg explain prompt.tg`). Prose
   becomes legible logic: every sentence binds to a subject, a rule, or a test; any
   line can explain what it does and why it is there.
3. **RULES** - set custom compiler rules and linting practices (`team.rules.tg`):
   banned words, required terms, hard requirements. One file, enforced on every draft
   from every agent.
4. **OPTIMIZE** - clean up redundant words, inconsistent logic, and soft instructions
   (`tg optimize && tg score`). Contradictions proven absent, redundancy flagged,
   soft phrasing caught, the prompt graded.
5. **RUNTIME** - reduce error and cost by eliminating conditionals in prompts
   (`tg build --runtime`). IF/THEN branches leave the prompt and run as code; the
   model never reads a rule that doesn't apply right now. Fewer misreads, cheaper
   calls.
6. **ITERATE** - agentic iteration with the safety of your rules: each edit re-proven
   against rules and tests (`tg explain file.tg:LINE` for blast radius), production
   results point at the exact lines to revisit. Around again.

## Where TypeGlish fits an existing workflow

Intended change (human) -> coding agent drafts the .tg -> `tg check` + `tg score` return
findings -> agent patches -> repeat UNTIL pass (✓, score >= gate) -> compiled
artifact (byte-exact, never hand-edited) -> destination platform (Voiceflow, OpenAI,
Anthropic, or your own runtime).

Same repo, same PRs, same CI. TypeGlish sits between the coding agent and the
platform; only a proven prompt ever reaches the destination.

## If you are a coding agent

- You own drafting and fixing: author `.tg`, run `tg check` after every edit; findings
  are build breaks - fix the prompt, never override.
- You never touch the team's rules, the success criterion, or the measurements.
- Write `must` or `may`; `should`/`ideally`/`try to` are compile warnings (W-MODAL).
- One rule, one place: duplicates (W-DUPE) and contradictions (E-CONTRA) are flagged
  with line numbers.
- Report findings with file and line, and before/after scores in every PR.

## Reference deployment

Tico (Voiceflow's in-app support agent) runs the Loop on its Global Prompt + Triage
instructions: -40% global prompt size, -29% triage size, 0 compiler errors
(contradiction-free, Z3-proven), measured weekly against the pre-TypeGlish baseline.
