Community编程与开发github.com

implicit-to-explicit

Find the state machines hidden in a codebase, check the risky ones with a model checker, report in plain words the cases nobody decided, and, when asked, make each machine explicit in the code. Its ledger tool drives the run.

implicit-to-explicit 是什么?

implicit-to-explicit is a Claude Code agent skill that find the state machines hidden in a codebase, check the risky ones with a model checker, report in plain words the cases nobody decided, and, when asked, make each machine explicit in the code. Its ledger tool drives the run.

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/FasalZein/implicit-to-explicit/tree/HEAD/skills/implicit-to-explicit

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Implicit to explicit

A state machine is anything where the right answer to an event depends on a phase that persists: an order, a job, a session, a connection, a screen. In an implicit machine that phase is spread over flags, nullable fields, status strings and the order of calls, so the code can reach phases that nobody decided. An explicit machine has one type for its states and one place for its steps, and that place refuses every other step.

A lead is a suspected bug written in the ledger; it ends as a finding, a clear or a question.

The loop

The tool scripts/ledger in this skill's folder is the path through the run. It keeps one file, the ledger, checks it, and names the next thing to do.

L="<the folder of this SKILL.md>/scripts/ledger"
FILE="docs/state-machines.json"
"$L" init "$FILE" --scope "<what this run covers and leaves out>"   # once
"$L" next "$FILE"   # do what it says, then run it again
"$L" all "$FILE"    # at the finish line
  • The finish line. First finish the sweep: read every area in scope, record each machine you find, and write each bug you see as a lead of its machine before you write its test. The run ends when "$L" check "$FILE" --done exits 0, or exits 2 with only questions for the owner left. Before all, re-trace each finding with a fresh read, as "Finding or lead" says: next cannot see that step. Then run all on either ending, and see that the report and the page were written. End your final message with the last output of next.
  • Run next after each piece of work and do what it names, until it says that nothing is open, or names only questions that wait for the owner. The rules live in check, and next reads them for you.
  • When the user or the task sets a limit of time or size, the run covers fewer machines, each one in full: take the worst-ranked machine through its trace, its model and its attempts before the next machine starts, and leave the rest pending. A limit ends the run only when it is used up. The clock (date) is the only measure of time, and the count of your steps is not: note the time at the start, and while the clock shows time left and next names work that is not a question, go on. Your report then lists the machines finished, every open item and the areas not read.
  • Run check after each edit, and read the ledger in small parts, through show FILE <id> and list FILE --open.
  • Read references/ledger.md before you write the first field: the format, every command, the rules by number.
  • The --scope of init is the area the user named, or else the whole repository, and what the run leaves out, in plain words. Put the ledger in docs/, or where the project keeps its design documents.

Sweep

Read the code in scope with references/signals.md. Add a coverage entry for each area (then areas prints its file count) and a pending machine for each machine you find, with its loss and a why such as "found, not traced yet".

  • With helpers (you can start subagents): give each area to a read-only helper with references/signals.md and the machine fields of ledger.md. Re-read the cited lines of what it returns before you write it down; a claim you did not re-read keeps the mark read (helper). To hand out tracing, follow the helper paragraph of ledger.md ("Start here").
  • Alone: read every file of each area yourself, in full. A keyword search misses most machines. When the scope is too large, read fewer areas in full and mark the rest not read with a note; check keeps each such area open until you read it in full or take it out of the scope. Model only machines whose areas you read in full.

Values that track one entity under one owner are one machine; values that change independently are separate machines. A machine that a verify skill or a Verified code: line of the project already checks takes the treatment verify skill: run the project's check, bring it in line with /maintain-formal-verification-skill when it lags, and record what its model leaves out.

Keep the machines in rank order, the worst first: by harm, then by the points where other code can run between a read and the write that follows, then by combinations with no meaning, then by modules. Harm is the worst that a bad state does, not how likely it is: follow the stored values to what a user sees, pays or owns. The scale is under scores in ledger.md.

Trace a machine

For each machine that next names:

  1. Carriers and writers. Each value that carries the state (a field, a column, a variable, a handle, an order of calls), and each place that writes one, with who runs it.
  2. States. The states the code means, and each combination the values can hold that the code does not mean, as a no meaning state. Three booleans hold eight; when the code means four, the other four have no meaning.
  3. Events. Each thing that can happen to the entity, also the event that creates it.
  4. Cells. For each state and event, read the handler as it runs in that state: moves; refused at the check that rejects it; unspecified when no check in the handler reads this state, so the unguarded code decides (a lead); cannot happen when the event cannot arrive. A cell holds one event; orders of events are leads.
  5. Kinds. Run every kind and every parity of references/state-bugs.md over the machine. Each hit is a lead; a kind with none says why.
  6. Treatment. left as is, with its reason, only when all of this holds: two phases, one writer, no point where other code runs between a read and the write that follows, and every lead cleared. Its table and its kinds are filled as for a modelled machine. A machine the project already checks keeps verify skill. modelled for every other machine.

Model

Every modelled machine gets a model, generated and then extended:

  • scaffold FILE MACHINE writes the model from the table: module, configs, view, rules and runs.
  • Outside its markers, add what a table cannot hold, by "The hand part of a model" in state-bugs.md: stored values, write sites, a second actor, a crash.
  • try FILE --machine ID while you edit: random runs.
  • runs FILE --machine ID for the record: the full check, written into the ledger.

A rule counts only when a run has shown that it can fail: a copy of the config with one guard switched off, as "Start here" in ledger.md says.

A lead about two actors overlapping, a stale read, or a failure between two writes names its gap: the line where one actor waits (an await, the end of a transaction, a separate request, an outside call) and what the other does meanwhile. When you find no gap after following every call between the read and the write, the code runs in one piece: clear the lead with the line that shows it.

Finding or lead

A finding is a lead that the real code did, in a test. Everything else stays a lead, however sure the model is. When the checker breaks a rule only because the model assumes a step that the code may not take, mark the lead checked under an assumption; it ends as a question.

  • In a machine with harm "high", every lead marked checked (cleared ones too) and every question lead is owed an attempt: the test shows what the code does today and what the user loses, and the owner still decides what it should do. A test that shows both makes the lead a finding that keeps its question: a finding says what the code does, not that the owner must change it. Record could not build only when the test cannot run here, or when it ran and shows no loss, and keep a test that ran. outline FILE MACHINE/LEAD prints the test to write; --fast-check prints it in TypeScript. Ask the owner before you add a test library to the project.
  • Replay the cheap half first: the server's half of a screen lead before the screen.
  • Enter where a user, a client or a job enters, and assert on the machine's loss, beyond the broken rule. When the sequence needs a crash, an outage or a slow write, inject it at the store or the network and mark the lead replayed (fault). A reproduced attempt goes with either mark, replayed or replayed (fault).
  • Keep each replay in the project's suite as an expected failure (test.failing, xfail) that names its lead, so a fix shows as an unexpected pass. When the task asks for plain failing tests, write them so. When the project's rules admit no such file, ask the owner where it goes.
  • When the code makes the sequence impossible, the clear cites the lines that block it on every path. When the order can occur, only a checked run that covers that order clears the lead. state-bugs.md says which reasons clear a lead.
  • Before all, re-trace each finding, and each clear whose line is in another module, with a fresh read: a helper gets only the finding, without your reasoning; with no helpers, start again from the entry point yourself. A step that fails makes the finding a question.

Questions for the owner

A question is a product decision that the code cannot answer. Write one for each finding and each unspecified cell (what should happen there?) and for each state with no meaning (can stored data hold it today?); one question may cover several leads. Ask the questions that next names, in the session, in rounds. With the grilling skill installed, run them through it. Without it:

  1. Ask only ready questions.
  2. Give each one recommendation, with its reason: the answer the code or its tests point to.
  3. Find facts yourself instead of asking for them.
  4. Stop when no question is ready.

Write each answer with answer. Answers come only from the owner: with nobody there, leave them unwritten and go on with work that hangs on no question.

What the reader gets

all writes the report state-machines.md and the page state-machines/index.html beside the ledger, with a picture of each machine that has a table, and the paths and charts the checker produced, all drawn by the tool from the ledger. Their reader reads no code:

  • Plain words. Every name, meaning, loss, harm, lead text and question uses the product's nouns and the words its screens show, and no name from the code or the model. check catches code tokens, not jargon.
  • Every chart needs a view. runs gives /statechart the model's view as --view; its state and step turn model values into plain words. When the hand part adds a variable or an action, extend them. Run /statechart by hand only to debug, and then with --view set to the model's view.

Afterwards (when the owner asks for it, after the report)

  • Make each machine explicit, in rank order, by references/make-explicit.md. It changes only cells that have an answer.
  • changed FILE is the gate for later edits: after you edit code, it names each machine whose cited code changed since the ledger's commit. Trace those again and run their checks before you move the ledger's commit. runs is the check for modelled machines; a verify skill machine is checked by its own recorded command. This skill writes no verify skill for a machine.
  • note FILE prints one line for the project's AGENTS.md. Add it only when the owner says yes.
  • Keep the project's formatter off the generated files (the ledger, state-machines.md, state-machines/): the tool writes them byte for byte. An ignore list is a check of the project, so ask the owner before you change one.

Requirements

Node 22.18 or later (on Node 23: 23.6 or later). The statechart skill in the folder beside this one, with the checker it pins (everystate): runs needs both, try the checker. The renderer is downloaded once, the first time anything is drawn; after that every command works offline. Run the command: when something is missing, it says what in one line.

相关技能