Skip to content

Migrating with an agent ​

@evobug_com/safe-ts-skill packages a repeatable migration workflow in the Agent Skills format: a SKILL.md playbook, on-demand reference catalogues, and census/gate scripts that keep coding agents fixing architecture instead of patching individual diagnostics.

In short

  • Install into your repo: run npx @evobug_com/safe-ts-skill to copy it into .claude/skills/safe-ts-migrate (match your @evobug_com package version).
  • Architecture first, checker as a gate: the agent drafts a target architecture document, then enforces safe-ts check --deny-warnings with idiomatic rules alongside types, tests, and behavior checks.
  • Ratcheted census: scripts/census.mjs counts both checker findings and hand-rolled anti-patterns per directory so counts can only decrease.
  • Useful without an agent too: the census, pattern catalogue, and checklists are plain files you can run and follow manually.

Why a skill ​

An agent asked to "make safe-ts check pass" does exactly that. It converts null to undefined, wraps throwing calls in unsafe, adds Result return types, and stops. The checker accepts what is left: a loading flag beside an error = ref(''), a '' that means "no error", if chains on strings, x.tag === "Ready". On one large Vue project migrated this way, AsyncState, Enum and <Match> ended up used nowhere, and 24 hand-made loading flags survived.

The skill makes the target architecture the goal (Result for failures, Option for absence, useTask for async work, Enum and match for closed sets, validated boundaries, no module state) and the checker one gate among types, lint, tests, the build, an architecture gate and behaviour checks.

Install ​

sh
npx @evobug_com/[email protected]     # into .claude/skills/safe-ts-migrate
npx @evobug_com/safe-ts-skill --to <dir> # into <dir>/safe-ts-migrate, for agents that look elsewhere
  • Claude Code loads a skill from .claude/skills/ when a request matches its description: adopting SAFE-TS, migrating an area, removing // @safe-ts legacy markers, taking a census, reviewing a migration change.
  • Commit the folder, so everyone working on the project (and CI, for the census) has the same copy.
  • The skill describes one version's APIs and names it in SKILL.md. After upgrading the packages, install the matching version with --force (it refuses to replace a copy that differs, so local edits aren't lost by accident). The whole upgrade is below.
  • Its scripts pass oxlint with the SAFE-TS preset, so a project that lints every file needn't exclude .claude/.
  • An agent without skill support can still follow it: point it at SKILL.md from your AGENTS.md.

The same files are in the repository, under skills/safe-ts-migrate.

What the agent does ​

  1. Reads the project: package manager, framework, build, tests, tsconfig aliases, the HTTP layer, the state library.
  2. Takes a census before anything is marked legacy.
  3. Writes the target architecture document with the census as evidence, and asks you to approve it: the absence policy (where null from the server becomes undefined, which request fields clear with null), errors and requests, state, async work, closed sets, boundaries, tooling, the escape-hatch budget, sanctioned helpers, exceptions, and the areas in order. This is the one point where it asks.
  4. Sets up the packages, both tsconfig flags, the oxlint preset, the Vite plugin (or the Bun plugin), the Node loader, the idiomatic rules, requestFunctions, the gates and a CI job, and a conventions section for CLAUDE.md / AGENTS.md. Then it marks the files that don't pass yet and records the census baseline.
  5. Migrates in order: the shared foundation (transport, requests, error types, stores), then utilities and the component library, then feature areas in parallel by dependency, then the bridges and the last markers. Each change groups the findings by cause and fixes the design behind each group (a type that can't hold the bad value, one definition of a closed set, a boundary that parses once, one owner of the state) rather than patching the reported lines, the way a Rust borrow error is fixed by changing ownership. It uses the pattern catalogue, passes every gate, runs the behaviour checks, and ends with a hand-off report that lists the causes removed and the changed signatures.
  6. Runs a final pass for places where useTask, AsyncState, Enum, match, Option and q would replace hand-rolled code.
  7. Reviews and hands off with the checklist and the escape-hatch counts.

What's in it ​

FileHolds
SKILL.mdthe workflow and the rules for the whole migration
references/architecture.mdthe target architecture document, section by section, with SAFE-TS's defaults
references/fix-the-design.mdfixing the cause of a group of findings instead of each line: the procedure, how to tell a patch from a design fix, examples
references/census.mdrunning and reading the census, and using it as a gate
references/patterns-core.md, patterns-vue.md, patterns-react.mdbefore and after for each common idiom: throws, requests, sentinels, string unions, boolean flags, casts and guards, null on the wire, optional keys, Patch bodies, Open server values, JSON and storage, base64, trust and LegacyNull, parseArgs, IndexedDB, the loading trio, <Match :value>, template refs, stores, props, v-html and URLs
references/order-and-gates.mdthe order of work, legacy markers as scaffolding, parallel builders, the gates per step
references/behaviour.mdcontract checks, comparing request bodies, a browser smoke list, and regressions a real migration produced
references/tool-gaps.mdthe tools' known limits in this version and their workarounds
references/escape-hatches.mdwhen unsafe, panic, trust, LegacyNull, safe-ts-ignore, rule levels, void, casts and legacy markers are allowed, the reason, the budget
references/review-checklist.mdfor reviewers: correctness and architecture
references/templates.mdtsconfig, package.json, oxlint, Vite, CI, the conventions section, the hand-off report
references/final-pass.mdthe "use every feature" pass
scripts/census.mjsthe census and the architecture gate
scripts/safe-ts.mjsfinds and runs the safe-ts binary in node_modules, for the census

The catalogue's examples are checked with the rest of the documentation: each "before" must produce exactly the rules it names (none, for the patterns the checker doesn't see), and each "after" must pass safe-ts check and compile with tsc in strict mode.

The census ​

sh
node .claude/skills/safe-ts-migrate/scripts/census.mjs            # the report
node .claude/skills/safe-ts-migrate/scripts/census.mjs --show trio-files
node .claude/skills/safe-ts-migrate/scripts/census.mjs --json > census.json

It runs safe-ts check <dirs> --json --idiomatic once over the directories it scans (every source file in them is an entry, so tests and scripts nothing imports count too; one run, so the rules that decide from the whole program see all of it and the counts equal that command's), and groups the findings, errors and warnings, by rule and directory, with the root causes. The idiomatic rules report several hand-rolled forms on their own: raw .tag reads, if (isErr(x)) return x, 'key' in on a union, unwrapOr(x, undefined), JsonNull as app state, casts in tests. Then it searches the source for what no rule reports: loading, error and data states, '', -1 and 0 sentinels, string comparisons in if chains, sets of boolean flags, raw fetch and HTTP clients, try/catch and .catch, as casts, JSON.parse and direct storage, and the escape hatches (unsafe without a reason comment, trust, LegacyNull, safe-ts-ignore comments, legacy markers). Last, how often the code uses each SAFE-TS feature. The patterns are regular expressions, so they are a map of where to look, not findings. Renames aren't counted as casts (a as b in an import or export list, on one line or several, and a mapped type's [K in Keys as NewKey]), nor is English in a string, a template or a comment ("rejected as DUPLICATE_SEQ"); a fetch the file imports by name (a feature pack's) isn't a raw fetch; a top-level let in a test file isn't module state, a named sentinel (const NONE = -1) counts once, at its declaration, and the skill's own folder isn't scanned.

With a baseline, the census is a gate: it fails when any file's count of a pattern or a rule rose, so the old patterns can be burned down area by area while no new ones get in.

sh
node scripts/census.mjs --write-baseline safe-ts-census.json
node scripts/census.mjs --baseline safe-ts-census.json   # exit 1 if a count rose

Upgrading between versions ​

For a project already on SAFE-TS, moving to a newer release. SKILL.md has the same steps for the agent; the CHANGELOG sections in between list the new rules (Added) and the rules that report more (Changed). <version> is the new version. Run each command over all of the project's source directories at once (apps packages scripts), so calls and imports across packages resolve.

  1. Bump every @evobug_com package together, then take the census. All of them are released with one version, and each package's peer range is its own minor (^0.5.0 is >=0.5.0 <0.6.0 for a 0.x version), so a mix doesn't install. Changing every pin and running npm install stops with ERESOLVE while the lockfile still holds the old safe-ts-vue, whose peer range is the old safe-ts-std. Either install them all in one command (npm keeps each in the field it is already in):

    sh
    npm install @evobug_com/safe-ts-std@<version> @evobug_com/safe-ts-vue@<version> \
      @evobug_com/safe-ts-transform@<version> @evobug_com/oxlint-plugin-safe-ts@<version> ...

    or change the pins, delete the node_modules/@evobug_com/... entries from package-lock.json, and run npm install. Then run the census against the baseline: the new rules' findings show as rises, by file.

  2. Moving to 0.5 or later from an earlier version: lend every Mut. Mut<T> is a type of its own since 0.5.0, and tsc refuses a value passed to a Mut parameter without mut(value). npx safe-ts migrate mut <dirs> --write writes them over the whole program (without --write it prints the diff); review the diff and its "Needs a decision" list.

  3. Apply the new rules' fixes one rule at a time, and review each.census.mjs --show <rule> lists a rule's places. npx safe-ts fix <rule> <dirs> prints the diff of the rule's quick fixes and --write applies them: read the diff, run the tests, then go to the next rule. Take most care with strict-truthiness on values that may be undefined: if (x) on an x?: string meant "set and not empty", and a 0.4.0 quick fix wrote x !== '', which is true for undefined. Write x !== undefined && x !== '', or the half the code means.

  4. Audit the comparisons with '' or 0 whose operand can be undefined (x !== '', x === 0), from the fixes and from before. --show empty-string-sentinel lists the '' ones. Where the type includes undefined, the comparison also decides what happens to it.

  5. Reinstall the skill: npx @evobug_com/safe-ts-skill@<version> --force.

When the new findings are fixed or recorded as exceptions, write the census baseline again, in a commit that names the upgrade.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra