¿Qué hace skill2cli?
Convert one skill directory into one standalone TypeScript CLI project. The
output copies the pipeline-template architecture: src/pipeline/core (types,
registry, runner), src/lib (errors, config, storage, logging), one pipeline per
skill, a strict JSON config, run.json + events.jsonl per run, stable error
codes and exit codes 0/1/2.
Two scripts do the deterministic work (inspect-skill.mjs, scaffold-cli.mjs),
one checks the result (validate-cli.mjs). You decide what the stages are and
write their bodies. Scripts are relative to this skill's directory; resolve it
to an absolute path first, for example:
SKILL2CLI=/absolute/path/to/skills/skill2cli
Preconditions
- The source directory contains
SKILL.mdwithnameanddescription. - The generated CLI runs on Node 22.19 or newer (a
@earendil-works/pi-airequirement);npm installneeds network once. - If the skill is only open-ended conversation with no verifiable output, stop
and say so. A CLI whose every stage throws is not a deliverable. A single
model judgement step is fine: it becomes a stage that calls
ctx.deps.llm.completeand writes its reply as an artifact.
Step 0 — Choose the target (ask the user)
A new skill does not automatically get a new CLI. Look for existing ones first:
node "$SKILL2CLI/scripts/find-cli.mjs" <workspace-root>
It scans for .skill2cli.json markers and prints each CLI with its pipelines.
One CLI hosts several pipelines, so adding a pipeline usually beats creating a
second project.
- No CLI found: create a new one (
--out). Say so, then continue. - One or more found: ask the user with AskUserQuestion which target to use —
add the new skill as another pipeline to
<dir>(--into, recommended when the CLIs already exist in that workspace), or create a separate CLI (--out). Never decide this silently. - If the pipeline id already exists in the chosen CLI, ask whether to replace
just that pipeline (
--force) or to pick another id.--forceon--intonever touches the other pipelines or the sharedcli.ts/lib.
Step 1 — Inspect
node "$SKILL2CLI/scripts/inspect-skill.mjs" <skill-dir> --out <work-dir>/skill-ir.json
Then read the source SKILL.md yourself, plus every file in scripts/,
references/ and assets/ that the body relies on. The IR is a draft: it
holds frontmatter, headings, steps, resources, referenced commands, detected
flags and a first guess at stages. It does not understand the skill.
Step 2 — Curate the mapping
Edit skill-ir.json before scaffolding. scaffold-cli.mjs reads exactly two
fields: suggestedStages and suggestedInputs (plus provenance).
Rules:
- One stage = one verifiable action with a checkable output. Not a paragraph.
- Keep
preflightfirst; it is already implemented and validates placeholders. - Aim for 3 to 8 stages. Merge steps that only make sense together, drop advisory steps ("ask the user", "choose a tone", "consider alternatives").
- Stage ids are kebab-case and verb-first:
collect-inputs,score-sources,render-report. file,id,path,limit,languageand similar becomeinputs. One input per value that legitimately changes between runs. Types arestring,number,boolean,array(array of strings).- AI access is a user decision, never a default. If any stage may call a model,
or you cannot rule that out, ask the user with AskUserQuestion before
scaffolding: (a) their own endpoint and key, (b) pi-ai login, which may open a
browser or print a device code to get credentials, (c) no AI at all. Record
the answer as
llm: { mode, provider?, model? }in the IR. If you scaffold without an answer the config keepsllm.mode: "unset"and every model call fails on purpose. llm.provider/llm.modelmust be ids that exist in the pi-ai catalog when mode ispi; ask the user which provider they use rather than inventing one.- Anything that is judgement stays in the source skill and out of the CLI.
- Keep the source section and line in each stage so the mapping file can point
back (
MAPPING.mdfor the first pipeline,MAPPING-<id>.mdfor added ones). - A pipeline id must be unique inside the target CLI. Renaming the pipeline
means editing
pipelineIdin the IR before scaffolding, not renaming files afterwards.
See references/mapping-rules.md for the construct-by-construct table and
worked examples.
Step 3 — Scaffold
# new CLI
node "$SKILL2CLI/scripts/scaffold-cli.mjs" <work-dir>/skill-ir.json --out <cli-dir>
# add a pipeline to an existing CLI (the target the user picked in Step 0)
node "$SKILL2CLI/scripts/scaffold-cli.mjs" <work-dir>/skill-ir.json --into <cli-dir>
cd <cli-dir> && npm install # only needed once per CLI
--out --force replaces only a directory that still has its .skill2cli.json
marker, so it never deletes unrelated work. --into writes only the new
pipeline module, its config and MAPPING-<id>.md, appends one import to
src/pipeline/index.ts, and refreshes .skill2cli.json plus PIPELINES.md; the
shared src/lib, src/pipeline/core and src/cli.ts are left untouched.
--out writes 37 files: the skeleton (src/lib, src/module, src/lib/llm,
src/pipeline/core, src/cli.ts, tests, tsconfig), the pipeline module
(config.ts, deps.ts, stages.ts, index.ts), src/pipeline/index.ts,
config/<id>.json, README.md, MAPPING.md, PIPELINES.md and the provenance
marker. --into adds 8 files: the four pipeline module files,
config/<id>.json, MAPPING-<id>.md, plus the updated marker and
PIPELINES.md (9 on first use, when it also creates src/module/inputs/).
AI access
src/lib/llm/ is the only place that talks to a model provider. It wraps
@earendil-works/pi-ai, so a stage never imports a provider SDK and the backend
stays replaceable.
Backends, decided by resolveLlmBackend and printed by plan:
llm.mode | Behaviour |
|---|---|
unset (scaffolded value) | model calls fail with LLM_MODE_UNSET until a human chooses |
custom | your own OpenAI-compatible endpoint; missing llm.baseUrlEnv / llm.apiKeyEnv fails with ENV_MISSING |
pi | pi-ai, no endpoint or key needed |
off | model calls fail with LLM_DISABLED |
There is no auto and no silent fallback: a CLI must not quietly pick a
provider or bill someone's account. unset exists precisely so the choice is
visible in plan, in MAPPING.md and in code review.
With mode pi, pi-ai resolves credentials itself, in this order: the credential
file named by llm.authFile (written by npm run login, shared with
npx @earendil-works/pi-ai login), then provider environment variables such as
ANTHROPIC_API_KEY, then ambient sources. OAuth refresh and the
CredentialStore write path stay inside pi-ai.
login command = provider-owned OAuth flow through pi-ai
(models.login(providerId, 'oauth', interaction)); it never implements a login
flow of its own. Provider sign-in commonly opens a browser or prints a device
code, so:
- tell the user that
npm run loginneeds a browser and an interactive terminal before they try it; loginrefuses to run without a TTY (LOGIN_TTY_REQUIRED) and prints the provider URL or device code as pi emits it;- the OAuth credential lands in
llm.authFile; if the user prefers pi's own CLI,npx @earendil-works/pi-ai login <provider>writes anauth.jsonthey can pointllm.authFileat.
plan reports LLM: <backend> <provider>/<model> auth=ok|missing — <source>
without sending a prompt.
Config keys (generated, strict): mode, provider, model, maxTokens,
temperature, timeoutMs, maxRetries, baseUrlEnv, apiKeyEnv, authFile.
Pick provider/model ids that exist in the pi-ai catalog; a wrong id fails
run with LLM_MODEL_UNKNOWN and lists candidates.
Step 4 — Implement the stages
Every stage after preflight throws STAGE_NOT_IMPLEMENTED with its source
reference. Replace each stub, in order.
-
Process, network and filesystem effects belong in
deps.ts. Stage bodies callctx.deps.*. Add a method toPipelineDepsinstead of importingnode:child_processin a stage. -
Pure domain rules (matching, scoring, formatting, parsing) belong in
src/module/<topic>/: no I/O and no imports frompipeline. Stages call it. The module layer is shared, so a second pipeline can reuse it unchanged. -
Pass arguments as arrays to
ctx.deps.exec. Never build a shell string from config or user input. -
Persist every stage result with
ctx.run.writeArtifact('name.json', value)and report the path withctx.recordOutput(path). -
Fail with a typed error that carries a stable code and context:
throw new PipelineError('CODE_IN_SCREAMING_SNAKE', 'what failed and what to do', { ...context });No bare
Error, noprocess.exitin a stage. -
Re-running a stage must not duplicate effects. Record history through
ctx.storeand write it only after the effect is verified. -
When the skill's prompt text is the logic, port it verbatim into the stage (or a copied reference file) instead of paraphrasing it.
-
A stage that needs a model calls
ctx.deps.llm.complete({ prompt, systemPrompt?, maxTokens? })and saves the reply withctx.run.writeArtifact. Never import@earendil-works/pi-aior an HTTP client from a stage; extenddeps.tsinstead. -
Keep prompts as template strings with explicit placeholders filled from
ctx.config.inputs; no hidden defaults, no silent retries beyondllm.maxRetries. -
Do not add config keys outside
inputs; do not weaken the schema to make a value optional. -
Remove each
TODO(skill2cli)comment once the stage is real.
Step 5 — Verify
node "$SKILL2CLI/scripts/validate-cli.mjs" <cli-dir> --typecheck
cd <cli-dir> && npm test
npx tsx src/cli.ts plan <id> --config config/<id>.json
npx tsx src/cli.ts login <id> --config config/<id>.json --provider <id> # only when no endpoint/key
npx tsx src/cli.ts run <id> --config config/<id>.json --set <input>=<value>
npx tsx src/cli.ts runs <id> --config config/<id>.json
A conversion is done only when all of these hold:
validate-cli.mjsprintsPASSwith noFAILline, andtsc --noEmitis clean. It checks every pipeline listed in.skill2cli.json, including that each is imported bysrc/pipeline/index.tsand thatPIPELINES.mdlists it.npm testpasses the architecture tests and the LLM resolution tests.planworks for the new pipeline id and the pipelines that already existed in that CLI, and printsLLM:for the mode the user chose, neverunset:custom ... auth=okorpi ... auth=ok|missingwith an actionable detail. Forpiwithout credentials, confirm the message points atnpm run loginand mention that it needs a browser sign-in and a terminal.- One real run writes
data/pipelines/<id>/runs/<runId>/whererun.jsonshows every stagesucceededandevents.jsonlhas increasingseq. - A bad config exits 2; a failing stage exits 1;
--seton an unknown input exits 2; an unknown pipeline id exits 2 and lists the known ids.
If a stage needs a model and no credential is available in this environment, do
not fake it: verify preflight, plan, the validator and the LLM resolution
tests, then record the unverified stage under "Known gaps" in the pipeline's
mapping file.
Step 6 — Report
Report the source skill, the target (new CLI or which existing CLI gained a pipeline), pipeline id, the stage list with the source section each came from, the inputs and their CLI overrides, what was deliberately not converted, and the verification evidence (validator summary, run id, test result). Keep it short.
What the generated CLI offers
Command (npx tsx src/cli.ts ...) | Purpose |
|---|---|
plan <id> --config <path> [--set k=v]... | validate config, print stages, LLM auth status and resolved config; no side effects |
run <id> --config <path> [--set k=v]... | run stages, write a run directory |
runs <id> [--config <path>] | list runs, status and failed stage |
login <id> --config <path> [--provider <id>] | provider OAuth login through pi-ai, credentials to llm.authFile |
Every command accepts the pipeline id; omitting it uses the first id in sort
order. PIPELINES.md lists the ids in a CLI and .skill2cli.json is the
machine-readable marker find-cli.mjs and --into rely on.
Exit codes: 0 success, 1 failed run, 2 usage or config error. Storage:
data/pipelines/<id>/runs/<runId>/{run.json,events.jsonl,artifacts/,evidence/}.
Config is strict JSON: an unknown key is an error, not a warning.
Rules
- Never copy credentials, cookies or tokens out of the skill. Environment
variables only, read through
requireEnv; pi-ai credentials stay inllm.authFile. - Never choose an AI backend on the user's behalf. Ask first, record the answer
in the IR, and never ship a config whose
llm.modeis stillunset. - Never modify the source skill; copy what you need into the generated project.
- One CLI hosts several pipelines. Add a pipeline when the CLI already exists and the user agrees; do not create a second project for every skill, and do not merge unrelated skills into one pipeline.
- Dependencies stay at
zod,tsxand@earendil-works/pi-ai. Do not add a second AI SDK, and do not call provider HTTP APIs directly from a stage. - Do not add retries, caching, streaming or concurrency the source skill does not ask for.
- No new documentation files beyond the generated
README.md,PIPELINES.mdand mapping files.
References
references/mapping-rules.md— construct-by-construct conversion table, IR field reference, worked examples, failure modes.references/template-conventions.md— the pipeline-template conventions the skeleton mirrors, and where each one lives in the generated project.