loop-to-machine
БесплатноБез исполняемых скриптовНе проверенConvert existing agent code (a while-loop around a model, a tool loop, a tool-call scheduler, ad-hoc if/else control flow) into an XState v6 state machine…
от statelyai★ 86 звёзд на GitHubОб этом скилле
Convert agent code to a machine
Targets
@statelyai/agent2.0 alpha, as on thenextbranch. APIs change between alphas: when a call here does not match the installed package, checknode_modules/@statelyai/agent/CHANGELOG.md.
You replace the control flow of working agent code with a machine, and show where it behaves like the old code and where it differs on purpose. Model calls, tools, and retry code move across unchanged.
inventory → pin the baseline → environment → (policy) → runner → proofs → parity → hand back
Default track: wrap first, carve per commit
For an async workflow (not a hand-rolled loop you are asked to replace wholesale), start here, and use the sections below for each carved phase.
- Step 0: wrap and record. Move every side effect behind one
effectsobject of async functions. The old code allows two edits: that seam, and extract-method moves of a loop body or phase into its own method or function (no change in behavior, its own commit, gated by the old suite pluscheckParityagainst the code before the extract). ThenwrapWorkflow({ id, effects, run: (input, effects) => old(input, effects) })from@statelyai/agent. Pin the baseline withcheckParity(@statelyai/agent/testing):{ scenarios, effects: (s) => fakes, before: old, after: (input, fx) => step0.run(input, { effects: fx }) }; every rowequivalent. Ship it: inspection, traces, the event log,signal, a recorded baseline. - Carve one phase per commit. One phase becomes states (§3); the rest stays the old helper, invoked as a
createAsyncLogicactor built per run fromeffects. Keep the(input, effects)runner signature with a thirdoptionsargument passed through torunAgent(threadId,store,metadata,onTrace,inspect), so traces and inspection never need a copy of the runner. Move any prompt or warning text the carved phase sends into a versioned request config as you carve it: that file is whatimprove-machinemay later edit. RuncheckParityagainst the old code after each carve. Add the §6 proofs for the carved phase only.
A wrapped workflow is a black box: one state, no mid-function resume, no canReach about its inside. Do not report proofs before the phase is carved. Worked example: examples/strangler-fig. A class whose loop calls its own private model/tool methods: replace those methods on the instance inside run so they call effects (no edit to the class). Effect-TS generators, Redux thunks, LangGraph graphs, closures in DI factories, and step loops inside the model SDK have their own seams: docs/strangler-fig.md. Effects bound to one call's live objects: create the workflow once, pass run(input, { effects }) per call. For a class-shaped loop, pass the instance too: run(input, { effects, live: agent }), read as context.live in the workflow (alpha.40), so one wrapped workflow serves every instance. Scrub generated ids and timestamps: compare.normalize for effect arguments, normalizeOutput for the output, normalizeError for thrown errors.
A class that writes to its database inline (dozens of SQL, scheduler, and queue calls, so one effects object is impractical): skip wrapWorkflow. Gate each extract-method commit with the old suite plus compareRuns (@statelyai/agent/testing) over world-state snapshots of the code before that extract against the code after it (checkParity needs the effects seam these classes lack). Then compare the extracted class with the port the same way. Run the old code against itself first to find harness noise (same-millisecond ordering, schedule order, background writers).
A run that fails after the host's own writes committed leaves the saved snapshot behind the host's record. On error, read the host's record back and send a host event (RESYNC, with the status and every other host field the machine reads, such as the assignee) to the snapshot stored before the failed run (the errored snapshot stays in error), then store the result. Declare RESYNC with an event schema and a root-level transition that maps each host status to its machine state and copies those fields into context; an unhandled RESYNC is ignored and the snapshot stays stale. Bump the machine version. Without this, the next message can call the model on a case a person owns.
A phase in the middle of a private method: extract it at step 0 (a function, a protected method when the carve is a subclass that builds its actors in the class body, else a public @internal method), then the carved actor calls it on the live instance. Never copy a body you can edit. When a public per-turn hook exists, replace that method on the instance instead and let the machine decide at that boundary. Only for code you can't edit
Установить loop-to-machine в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл loop-to-machine?
Convert existing agent code (a while-loop around a model, a tool loop, a tool-call scheduler, ad-hoc if/else control flow) into an XState v6 state machine with @statelyai/agent, and prove with a parity report that it behaves like the code it replaces. Use when asked to "turn this agent into a state machine", "port my loop to xstate", "make this a statechart", "refactor this agent into a machine", or "split environment and policy" for code that already runs.
Как установить скилл loop-to-machine?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл loop-to-machine запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic