Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от statelyai★ 86 звёзд на GitHub

Об этом скилле

Convert agent code to a machine

Targets @statelyai/agent 2.0 alpha, as on the next branch. APIs change between alphas: when a call here does not match the installed package, check node_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.

  1. Step 0: wrap and record. Move every side effect behind one effects object 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 plus checkParity against the code before the extract). Then wrapWorkflow({ id, effects, run: (input, effects) => old(input, effects) }) from @statelyai/agent. Pin the baseline with checkParity (@statelyai/agent/testing): { scenarios, effects: (s) => fakes, before: old, after: (input, fx) => step0.run(input, { effects: fx }) }; every row equivalent. Ship it: inspection, traces, the event log, signal, a recorded baseline.
  2. Carve one phase per commit. One phase becomes states (§3); the rest stays the old helper, invoked as a createAsyncLogic actor built per run from effects. Keep the (input, effects) runner signature with a third options argument passed through to runAgent (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 what improve-machine may later edit. Run checkParity against 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

Полный SKILL.md на GitHub

Установить loop-to-machine в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

policy.mdreference.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить loop-to-machine с