prompt-language
CLAUDE.md4 starsChanged 8 months agoMITView on GitHub
Quality gate: npm run ci then npm run eval:smoke (run both before claiming work complete). Run npm run test or npm run test:watch for feedback. Run npm run test:coverage before opening a PR. Domain-driven design with four layers: Dependency flow is strictly inward. Domain never imports from other layers. Current node kinds: prompt, run, while, until, retry, if, try, foreach, foreach_spawn, spawn, await, approve, review, race, remember, send, receive, break, continue, plus let/var for variable storage. let and var are…
- Reads credentials
- Deletes or force-pushes
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this CLAUDE.md into the rules it gives an agent
11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 9
Run npm run test or npm run test:watch for feedback.
- Very specific: line 27
Use type imports for type-only symbols.
- Distinctive: line 29
No weakening of ESLint, Prettier, TypeScript, Vitest, or dependency-cruiser rules.
- Distinctive: line 30
All node creation goes through factory functions in domain.
- Very specific: line 35
Use cases: verb-noun.ts (e.g., parse-flow.ts, advance-step.ts)
- Very specific: line 95
When enabled, snapshot "name" tar-gzips the stateDir (excluding .snapshots/) into <stateDir>/.snapshots/<sha256>.tar.gz and attaches the …
- Very specific: line 230
After any change to inject-context.ts, parse-flow.ts, evaluate-completion.ts, or hook files
- Distinctive: line 231
After any change to node advancement, state transitions, or gate evaluation
- Distinctive: line 232
After any new DSL primitive or syntax change
- Distinctive: line 233
Before any PR that touches application or presentation layers
- Very specific: line 234
After completing a feature or fix — run npm run eval:smoke before reporting done
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Project Rules
Quick reference
Quality gate: npm run ci then npm run eval:smoke (run both before claiming work complete).
Tests
Run npm run test or npm run test:watch for feedback. Run npm run test:coverage before opening a PR.
Architecture
Domain-driven design with four layers:
src/domain/ Pure types and functions. Zero external deps.
src/application/ Use cases, port interfaces.
src/infrastructure/ Adapters implementing ports.
src/presentation/ Hook entry points.Dependency flow is strictly inward. Domain never imports from other layers.
Rules
- Domain code must have zero external dependencies.
- Use
typeimports for type-only symbols. - No
eslint-disablecomments. - No weakening of ESLint, Prettier, TypeScript, Vitest, or dependency-cruiser rules.
- All node creation goes through factory functions in domain.
- SessionState is immutable; transitions return new objects.
Naming conventions
- Use cases:
verb-noun.ts(e.g.,parse-flow.ts,advance-step.ts) - Adapters:
noun-adapter.ts(e.g.,file-state-adapter.ts) - Ports:
noun-port.ts(e.g.,state-port.ts) - Tests:
*.test.tscolocated with source
DSL primitives
Current node kinds: prompt, run, while, until, retry, if, try, foreach, foreach_spawn, spawn, await, approve, review, race, remember, send, receive, break, continue, plus let/var for variable storage.
let/var nodes
let and var are aliases. Three source types:
let x = "literal"— stores a string valuelet x = prompt "text"— stores the prompt text as contextlet x = run "cmd"— executes command, stores stdout
List variables (stored as JSON array strings):
let x = []— initializes an empty listlet x += "val"— appends literal to list (auto-creates array if needed)let x += run "cmd"— appends command stdout to listlet x += prompt "text"— appends captured response to list
Auto-variable: ${x_length} is set on every list modification. Lists integrate with foreach via splitIterable() which parses JSON arrays as highest priority.
Variables are interpolated via ${varName} in prompt/run text. Unknown variables are left as-is. let/var, run (with command runner), and prompt nodes auto-advance (no agent interaction).
Built-in variables (auto-set after run: and let x = run)
last_exit_code— numeric exit codecommand_failed— boolean, true when exit code !== 0command_succeeded— boolean, true when exit code === 0last_stdout— stdout (truncated at 2000 chars)last_stderr— stderr (truncated at 2000 chars)
Control-flow evaluation
while/until: conditions resolve via variable lookup first, thenresolveBuiltinCommand()+ command executionretry: always enters body; re-loops whencommand_failed === trueand iteration < maxif/else: evaluates condition, enters then-branch or else-branch (or skips)try/catch: always enters body; onrunfailure, jumps to catch body if present
spawn/await nodes
spawn "name": Launches a childclaude -pprocess with its own state directory (.prompt-language-{name}/). Parent variables are copied to child asletdeclarations. Parent immediately advances past the spawn block.await "name"orawait all: Polls child state directories. Blocks until target children complete/fail. Imports child variables with name prefix (childName.varName).advanceSpawnNode()andadvanceAwaitNode()inadvance-flow.ts- Render:
renderSpawnNode()inrender-flow.tsshows[running]/[completed]/[failed]status tags - State:
spawnedChildrenrecord inSessionStatetracks name, status, pid, stateDir, and imported variables
Self-hosting primitives (PR1)
snapshot "name"captures a state-only checkpoint (variables, currentPath, iteration counters) intoSessionState.snapshots[name]. Duplicate names overwrite with a warning. No file capture in PR1.rollback to "name"restores only those three fields;spawnedChildren,completed/failedstatus,warnings, and the trace/transition sequence are preserved so the hash chain stays monotonic. A missing snapshot pauses the flow (notmarkFailed) so a surroundingtry/catchcan recover.
Self-hosting primitives (PR2 — optional file capture)
PR2 adds an opt-in file-capture path to snapshot "name" / rollback to "name". Off by default; enabled per-run via PL_SNAPSHOT_INCLUDE_FILES=1. With the flag unset, behavior is identical to PR1.
- When enabled,
snapshot "name"tar-gzips the stateDir (excluding.snapshots/) into<stateDir>/.snapshots/<sha256>.tar.gzand attaches the sha256 ref asfilesDigestRefon theStateSnapshot. Identical trees produce identical refs (content-addressed). rollback to "name"restores the file tree whenfilesDigestRefis present. On restore failure the flow is marked failed with reason prefixrollback files failed: ...; PR1 state-only restore has already applied, so the operator sees divergence rather than continuing on a half-restored workspace.- Size cap:
PL_SNAPSHOT_MAX_MB(default 10). Captures over-cap fail with an exactsnapshot capture exceeds PL_SNAPSHOT_MAX_MB cap of <N> MB; measured <M> MB under <stateDir>error. - Storage location override:
PL_SNAPSHOT_STORE_DIRredirects tarballs outside the stateDir (useful for CI scratch volumes). - Destructive restore caveat:
rollback towithPL_SNAPSHOT_INCLUDE_FILES=1deletes any modified files insidestateDirthat are not part of the captured tree before moving the extracted contents back in. You will lose uncommitted workspace edits understateDiron restore. The env flag plus the explicitrollback toDSL gesture both act as opt-in guards. - Windows: paths over 260 chars are rejected at capture time with the offending path in the error message rather than silently truncated.
Key implementation files (PR2):
src/application/ports/snapshot-store.ts—SnapshotStorePort,NullSnapshotStoredefaultsrc/application/ports/env-reader.ts—EnvReaderPortso advance-flow reads env flags through a testable port, notprocess.envdirectlysrc/infrastructure/adapters/file-snapshot-store.ts— tar-gzip adapter with sha256 refs, per-stateDir advisory lock, extract-then-swap restore, stale-marker recoverysrc/infrastructure/adapters/process-env-reader.ts—process.envwrapper
Security note
interpolate() performs raw substitution — use shellInterpolate() for run: commands. It wraps substituted values in single-quotes to prevent shell injection.
Key implementation files:
src/domain/flow-node.ts—LetNode,LetSource,createLetNode()src/domain/list-variable.ts— pureinitEmptyList(),appendToList(),listLength()for list variablessrc/domain/interpolate.ts— pureinterpolate(template, variables)+shellInterpolate()for commandssrc/domain/evaluate-condition.ts— pure condition evaluation against variable statesrc/domain/format-error.ts— safe error-to-string with stack trace preservationsrc/domain/render-flow.ts— renders let nodes with[= value]annotation (varrenders aslet— they are aliases)src/application/parse-flow.ts—parseLetLine()handles let/var parsingsrc/application/inject-context.ts—autoAdvanceNodes()+ control-flow + interpolationsrc/application/evaluate-completion.ts— gate evaluation withresolveBuiltinCommand()for builtin predicatessrc/application/ports/process-spawner.ts— ProcessSpawner port:spawn(input),poll(stateDir)src/infrastructure/adapters/claude-process-spawner.ts— Spawns childclaude -pprocesses, polls state files
Plugin installation
One-command install: npx @45ck/prompt-language
The CLI (bin/cli.mjs) copies plugin files to ~/.claude/plugins/local/prompt-language/, generates a marketplace catalog, registers it in extraKnownMarketplaces, and enables the plugin. No --plugin-dir flag needed after install.
Key constraints discovered during testing:
plugin.jsonauthorfield must be an object ({"name":"..."}) not a string.marketplace.jsonmust follow the catalog schema withowner(object) andplugins(array).- The marketplace directory must be the parent of the plugin directory (not the plugin dir itself). Source paths in the catalog use
"./prompt-language". - DSL regexes (
FLOW_BLOCK_RE,extractFlowBlock) must allow optional leading whitespace (^\s*flow:) since users may indent their input.
Smoke testing (mandatory — never skip)
Unit tests and CI are necessary but not sufficient. Smoke tests are required before claiming any work complete. Do not ask the user whether to run them — just run them. Unit tests use mocks and in-memory stores; smoke tests prove the plugin actually works end-to-end through Claude's real agent loop.
Automated smoke tests
npm run eval:smoke # full suite
npm run eval:smoke:quick # fast subset without gate/loop tests (~2 min)
npm run eval:smoke:codex
npm run eval:smoke:gemini
npm run eval:smoke:opencode
npm run eval:smoke:ollamaHarness-specific smoke commands are explicit entry points for the currently supported smoke adapters. Codex, OpenCode, and Ollama flow through prompt-language ci --runner ...; Gemini is supported as a first-class smoke harness, but today it uses the direct CLI prompt path rather than a dedicated ci --runner gemini flow runner.
The automated script (scripts/eval/smoke-test.mjs) builds, installs the plugin, and runs 52 live claude -p tests in temp directories:
- A: Context file relay — two prompts, second reads file created by first
- B: Context recall — second prompt recalls a code from the first
- C: Variable interpolation — let/var resolve and interpolate into prompt text
- D: Gate evaluation —
done when: tests_passblocks until app.js is fixed - E: Run auto-execution —
run:node auto-executes and creates a file - F: Foreach iteration —
foreach item in "a b c"creates per-item files - G: Let-prompt capture —
let x = promptcaptures Claude's response into a variable - H: If/else branching —
if command_succeededtakes the correct branch - I: Try/catch handling —
trybody failure triggerscatchbody execution - J: While loop —
while tests_fail max 3iterates until condition clears - K: Variable chain —
let x = run+if+${x}interpolation pipeline - L: Retry on failure —
retry max 3re-runs body on command failure - M: Gate-only mode —
done when: file_existswithout a flow block - N: Capture reliability —
let x = promptcaptures non-empty response with tag-based validation - O: Until loop —
until tests_pass max 3iterates until condition is true - P: Break exits loop —
breakinsidewhileexits the loop - Q: List append —
let x = []+let x += "val"builds a list - R: Custom gate —
gate check: node verify.jsruns custom command - S: Nested foreach —
foreachinsideforeachprocesses nested lists (flaky) - T: List accumulation —
let x += runinsideforeachbuilds list from command output (flaky) - U: And/or conditions —
if a and b,if a or bcompound conditions - V: Numeric comparison —
if ${count} > 0numeric condition evaluation - W: Try/finally —
trywithfinallyblock always executes cleanup - X: Break in nested —
breakinside nestedifwithin loop - Y: Until variable —
untilwith variable-based condition (flaky) - Z: Multi-var interpolation — multiple
${var}references in single prompt - AA: Approve timeout —
approve "msg" timeout Nauto-advances without human interaction - AB: Review block —
review max 1runs body then exits, flow advances - AC: Remember + memory: —
remember key/valuepersists;memory:prefetch loads into variables - AD: Race block — two spawns race;
race_winneris set to first completer (slow) - AE: foreach-spawn — parallel fan-out creates per-item files via spawned children (slow)
- AF: Send/receive — child sends message to parent via
send parent, parent captures viareceive(slow) - AG: Import anonymous flow — anonymous flow file import and execution
- AH: Import namespaced library —
import "lib.flow" as mylibanduse mylib.greet() - AI: Continue skips iteration —
continueinsideforeachskips to next iteration - AJ: Remember key-value storage —
remember key="x" value="y"persists in memory.json - AK: Grounded-by while —
while ask "..." grounded-by 'cmd'AI + command verification - AL: Continue in while —
continueresets loop iteration inuntil - AM: Spawn basic child —
spawn "name"launches child,await "name"blocks until completion - AN: Spawn inherits parent variables — spawned child inherits parent's variables, returns with prefix
- AO: Include file directive —
include "shared.prompt"inlines external prompt content - AP: Swarm manager-worker —
swarm delivery { role worker ... }pattern execution - AQ: Swarm reviewer-after-workers —
swarmwith multiple roles and sequenced await - AR: Retry with backoff —
retry max 3 backoff 1swaits >=900ms between attempts and completes (slow) - AS: Composite gate —
done when: all(file_exists a, file_exists b, file_exists c)completes after all files appear - AT: Spawn with modifiers — conditional
if ... spawn "worker" ... endlaunches child and registers inspawnedChildren - AU: Nested try/catch/finally — inner catch failure propagates to outer catch;
finallystill executes - AV: foreach in run —
foreach item in run "cmd"iterates over command stdout tokens - AW: Labeled break exits outer loop —
break outerunwinds nested loops and exits labeled ancestor - AX: Snapshot + rollback (state-only) —
snapshot "name"+rollback to "name"restores variables-only - BA: Snapshot file capture (PR2, gated) — with
PL_SNAPSHOT_INCLUDE_FILES=1,snapshottarballs the stateDir androllbackremoves drift files created after the snapshot; skipped when the env flag is unset - Z1: List-length drift —
let x = []+ foreach append writesitems_lengththrough each iteration - Z2: Nonce propagation — runtime UUID flows through multiple
run:nodes and matches state - Z3: Capture-gated branch —
if coin == "HEADS"branch selection depends on live prompt capture - Z4: Interleaved state probe — each iteration writes
${n}=${counter}using prior iteration's capture - Z5: Spawn PID fingerprint — foreach-spawn produces distinct child PIDs, none matching harness PID (slow)
- Z6: Race winner — race block populates
race_winnerconsistent with state (slow) - Z7: Send/receive hash — child's send appears in parent's receive with matching sha256 (slow)
Trace verification
The Z-series tests are differential: they are constructed so a stub harness that only replays recorded outputs cannot pass them. Each one depends on live runtime state (fresh UUIDs, real child PIDs, capture-gated branches, hash-matched send/receive payloads) that only the running PL runtime can produce.
Z-series runs are expected to be executed with PL_TRACE=1 and cross-checked with node scripts/eval/verify-trace.mjs --trace <path> --state <path> --json. See docs/tracing-and-provenance.md for setup and docs/thesis-verification.md for how this plugs into the E5 experiment.
If smoke fails fast with a harness auth or login blocker, that is a host limitation, not a plugin success signal. Use docs/troubleshooting.md for the recovery path and docs/eval-parity-matrix.md for the current parity bar. The history report command node scripts/eval/smoke-test.mjs --history is for local analysis only.
When to smoke test
Always. Specifically:
- After any change to
inject-context.ts,parse-flow.ts,evaluate-completion.ts, or hook files - After any change to node advancement, state transitions, or gate evaluation
- After any new DSL primitive or syntax change
- Before any PR that touches application or presentation layers
- After completing a feature or fix — run
npm run eval:smokebefore reporting done
Manual smoke tests
For one-off validation or debugging, run individual tests from a temp directory:
npm run build && node bin/cli.mjs install
mkdir -p /tmp/pl-test && cd /tmp/pl-test
rm -rf .prompt-language # clean state between testsVariable + prompt advancement
cd /tmp/pl-test && rm -rf .prompt-language
claude -p --dangerously-skip-permissions "Goal: test let/var
flow:
var greeting = \"hello world\"
let ver = run \"node -v\"
prompt: Say the greeting: \${greeting}. Node version is \${ver}."Gate evaluation (done when)
cd /tmp/pl-test && rm -rf .prompt-language
echo 'process.exit(1)' > app.js
claude -p --dangerously-skip-permissions "Goal: fix app
flow:
prompt: Fix app.js so it exits 0
run: node app.js
done when:
tests_pass"Control flow (retry, if)
cd /tmp/pl-test && rm -rf .prompt-language
claude -p --dangerously-skip-permissions "Goal: fix app.js
flow:
retry max 3
run: node app.js
if command_failed
prompt: Fix the error.
end
end
done when:
tests_pass"Note: command_succeeded/command_failed work as runtime variables (auto-set after each run: node) but are not yet implemented as gate predicates for done when:. Use tests_pass or file_exists <path> for gates.
Environment variables
PL_TRACE=1— Enable trace logging to.prompt-language/trace.jsonl.PL_COMPACT_RENDER=1— Experimental: switch the injected flow context from full mode (renderFlow) to compact mode (renderFlowCompact). Compact mode renders only the active execution path with abbreviated markers, reducing token usage. Automatic escalation to full mode triggers on recovery-sensitive conditions (errors, retries, try/catch, gate failures). Seesrc/domain/escalate-render-mode.ts.PL_GATE_TIMEOUT— Gate command timeout in milliseconds (default: 60000).
State file
Runtime state lives in .prompt-language/session-state.json. Never hard-code paths; use the infrastructure adapter.
CI
Full pipeline: npm run ci
This runs: typecheck, lint, format check, spell check, dependency cruiser, knip, build, test with coverage, e2e eval, and audit.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

