@evobug_com/safe-ts-skill 0.0.0-stage → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,70 @@
1
+ # Review checklist
2
+
3
+ For a reviewer of a migration change, human or agent. Correctness first, then architecture: a
4
+ change can pass every gate and still be a minimal conversion.
5
+
6
+ ## Gates and behaviour
7
+
8
+ - [ ] Every gate in [order-and-gates.md](order-and-gates.md) ran on this change, and the output is
9
+ in the hand-off report. `safe-ts check` ran with `--deny-warnings` and `"idiomatic": true`
10
+ (a plain run exits 0 with every idiomatic finding left).
11
+ - [ ] The census baseline wasn't rewritten, or the commit that rewrote it says why, and the
12
+ exception list has the line.
13
+ - [ ] Request bodies of the touched write flows are the same as before, or each difference is
14
+ intended and written down. Fields cleared with `null` still send `null`.
15
+ - [ ] Failure paths still show what they showed: inline messages are still inline, dialogs stay
16
+ open with the input kept when the server refuses.
17
+
18
+ ## Signatures that changed
19
+
20
+ - [ ] Every exported function and store member that now returns a `Result` (or takes or returns
21
+ `Option` instead of `null`) is listed in the hand-off report.
22
+ - [ ] Every caller of each, in every area, was found by searching its name and read: no leftover
23
+ `try`/`catch` or `.catch` around a call that no longer rejects, no dropped `Result`. The
24
+ checker reports these through store members and factories; the search covers the rest
25
+ (parameters, class fields, a `ref` or `Map`).
26
+
27
+ ## Architecture
28
+
29
+ - [ ] Findings were fixed at their cause ([fix-the-design.md](fix-the-design.md)): no guard,
30
+ default, `!` or extra branch at a reported line where a type, a single definition of the
31
+ set, a boundary parse or one owner of the state would rule the bug out. Each local fix
32
+ that remains has its reason in the hand-off report.
33
+ - [ ] A closed set that grew in this change (a new variant, phase, code or command) fails to
34
+ compile in every place that handles it: no `if` chain or `switch` on it ends in a silent
35
+ fallback.
36
+ - [ ] No new `loading` / `error` / `data` state: async work goes through `useTask`, shown with
37
+ `<Match>` or `match`.
38
+ - [ ] No `''`, `-1` or `0` meaning "none" or "no error"; no boolean sets that are one state.
39
+ - [ ] Closed sets are `Enum`s, read in the project's one style (`match`, `is`, `variant`,
40
+ `<Match>`); no unions told apart by `'key' in`.
41
+ - [ ] Errors are `Result`s with named error types, passed up with `q(...)` (and a mapping or
42
+ `mapErr` when the type changes), not re-wrapped by hand.
43
+ - [ ] No failure turned into `undefined` (`unwrapOr(x, undefined)`, a helper that wraps it,
44
+ `.catch(() => undefined)`).
45
+ - [ ] Outside data goes through `validate<T>` / `parseJson<T>` or a pack's safe version; no casts
46
+ or hand-written guards on it.
47
+ - [ ] `jsonNull` appears only in outgoing data; no `Option<T | JsonNull>` in app types.
48
+ - [ ] Request bodies that change a record are `Patch<T>`; server fields from a list that can
49
+ grow are `Open<K>` (and `.value` is what goes back); markup and URL props are typed `Html`
50
+ / `SafeUrl`, and no brand is made by a cast.
51
+ - [ ] Optional keys use the one form (`...(x === undefined ? {} : { x })`, or `Option<T>` fields
52
+ always written); wire-keyed tables use `getOwn(table, key, fallback)`; base64 uses
53
+ `toBase64` / `fromBase64`.
54
+ - [ ] No module state; shared state lives in a store or a provided context.
55
+ - [ ] `panic` only for invariants; never on a loading state or server data.
56
+ - [ ] Helpers are the architecture document's sanctioned ones; no new wrapper around std.
57
+
58
+ ## Escape hatches
59
+
60
+ - [ ] Each new `unsafe`, `unsafeAsync`, `panic`, `trust`, `LegacyNull`, `void`, cast,
61
+ `safe-ts-ignore`, rule level in package.json or legacy marker has a reason, fits the policy
62
+ in [escape-hatches.md](escape-hatches.md), and is within the area's budget.
63
+ - [ ] No legacy file was put in `safeTs({ exclude })`, and no project-local bridge type stands in
64
+ for `LegacyNull`.
65
+ - [ ] `unsafeAsync` around project code passes `Panic`, or there is a reason it doesn't.
66
+
67
+ ## Docs and conventions
68
+
69
+ - [ ] The project's conventions (`CLAUDE.md` / `AGENTS.md`) and gate fix texts name the forms this
70
+ skill's catalogue names, and nothing else.
@@ -0,0 +1,260 @@
1
+ # Templates
2
+
3
+ Adapt the paths and the package manager (`npm`, `pnpm`, `bun`, `yarn`) to the project. The
4
+ setup itself is in the guide: Adopting SAFE-TS, and the Vue or React Setup page.
5
+
6
+ ## Packages
7
+
8
+ ```sh
9
+ npm install -D @evobug_com/safe-ts-transform @evobug_com/oxlint-plugin-safe-ts @evobug_com/safe-ts-prelude oxlint
10
+ npm install -D @evobug_com/safe-ts-native # pnpm only: puts the `safe-ts` command on the PATH
11
+ npm install @evobug_com/safe-ts-std
12
+ npm install @evobug_com/safe-ts-vue # Vue 3.5+
13
+ npm install @evobug_com/safe-ts-react # React 18+
14
+ npm install @evobug_com/safe-ts-feature-browser # browser code: fetch, storage, DOM lookups, IndexedDB
15
+ npm install @evobug_com/safe-ts-feature-node # Node code: fs, child_process, util.parseArgs, ...
16
+ ```
17
+
18
+ Every `@evobug_com/*` package has the same version; keep them in step (`npx safe-ts --version`
19
+ prints it).
20
+
21
+ ## tsconfig.json
22
+
23
+ ```jsonc
24
+ {
25
+ "compilerOptions": {
26
+ "strict": true,
27
+ "noUncheckedIndexedAccess": true,
28
+ "exactOptionalPropertyTypes": true,
29
+ // The prelude: Result, Option, q, match, ... without imports. strict-lib: `unknown` where
30
+ // TypeScript's lib hands out `any` (JSON.parse, response.json(), Array.isArray, new Map()).
31
+ // Keep the entries the project already lists ("node", "vite/client"). With "typeRoots" set,
32
+ // add "node_modules" to it, or TypeScript can't find them (TS2688).
33
+ "types": ["@evobug_com/safe-ts-prelude", "@evobug_com/safe-ts-std/strict-lib"]
34
+ }
35
+ }
36
+ ```
37
+
38
+ The flags and strict-lib go in from the first step, in the tsconfig that tsc, vue-tsc and a
39
+ type-aware oxlint all read. Measure their error count first (`tsc --noEmit` with each), and fix
40
+ those errors as part of the setup or the foundation step. strict-lib's errors are a value of
41
+ `JSON.parse`, `response.json()` or `Array.isArray` used unchecked: `validate<T>` in migrated
42
+ code; in a legacy file, the `any` written out (`const data: any = JSON.parse(raw)`) until it is
43
+ migrated. `safe-ts check` warns while the tsconfig doesn't load it, and for each of the flags
44
+ above left off (what each keeps true: docs/guide/adoption.md, "The tsconfig flags SAFE-TS relies
45
+ on").
46
+
47
+ For code Node runs itself (scripts, a server, `node --test`), its tsconfig also wants
48
+ `"verbatimModuleSyntax": true` and `"erasableSyntaxOnly": true`: Node's type stripping fails
49
+ to load a type imported without `type`, a parameter property, an `enum`. `safe-ts check`
50
+ doesn't ask for them.
51
+
52
+ ## package.json
53
+
54
+ ```jsonc
55
+ {
56
+ "scripts": {
57
+ "check:safe-ts": "safe-ts check src --deny-warnings --baseline safe-ts-baseline.json",
58
+ "check:safe-ts:summary": "safe-ts check src --summary",
59
+ "check:architecture": "node scripts/census.mjs --baseline safe-ts-census.json",
60
+ "census": "node scripts/census.mjs"
61
+ },
62
+ "safe-ts": {
63
+ "idiomatic": true,
64
+ "features": ["@evobug_com/safe-ts-feature-browser"],
65
+ "requestFunctions": ["api"]
66
+ }
67
+ }
68
+ ```
69
+
70
+ - `safe-ts` is the command of `@evobug_com/safe-ts-native`, which the transform and the oxlint
71
+ plugin bring. Give `check` the source directories: each file under one is an entry, so
72
+ tests, scripts and workers whose path is built at runtime are checked too
73
+ (`safe-ts check src scripts --deny-warnings`). With file entries instead (it follows relative
74
+ imports, tsconfig `paths` aliases, workspace packages, workers and `import()` from them), it
75
+ names the files under their directories that nothing reached, as warnings. Several apps in a
76
+ monorepo: all their directories or entries in one run.
77
+ - `--baseline safe-ts-baseline.json` fails the run when an escape hatch (`unsafe`, `trust`,
78
+ `@ts-expect-error`, ...), a weakened rule or setting (`infer`, `testRunners`, ...), a file not
79
+ checked, an unresolved import or a rule's warnings rose, or a setting got weaker than it was
80
+ (`"idiomatic"` off, a pack out of `"features"`). Write it with `--write-baseline safe-ts-baseline.json` in the setup
81
+ step, and again only for a reviewed exception.
82
+ - `--deny-warnings` makes warnings fail the run: the idiomatic rules and the cost rules are
83
+ warnings, and without it a run with only warnings exits 0. While an area burns a count down,
84
+ `--max-warnings <n>` holds it at `n`.
85
+ - `"idiomatic": true` turns the idiomatic rules on for every tool (check, editor, Vite, oxlint).
86
+ - `"requestFunctions"` names the project's own request wrapper or axios instance, so
87
+ `fetch-signal` reports a call of it without a `signal` or `timeout`, like a bare `fetch`.
88
+ - `scripts/census.mjs` and `scripts/safe-ts.mjs` are this skill's `scripts/`, copied into the
89
+ project (they import each other by relative path).
90
+ - Rule levels: `"rules": { "stable-shape": "error" }` and `"overrides": [{ "files":
91
+ ["src/generated/**"], "rules": { "no-null": "off" } }]`. Each `"off"` or `"warn"` is an
92
+ exception in the architecture document (`check` names each one, and `--baseline` fails on a
93
+ new one); a count to burn down is ratcheted by the census instead.
94
+ - Feature packs: the browser pack for browser code, `@evobug_com/safe-ts-feature-node` for Node,
95
+ and the packs for the libraries the code uses (Libraries and feature packs). A pack turns
96
+ each unhandled call of its library into a finding, so an existing app gains findings when one
97
+ is enabled: enable it in the setup step, before the first census.
98
+
99
+ ## .oxlintrc.json
100
+
101
+ ```jsonc
102
+ {
103
+ "extends": ["./node_modules/@evobug_com/oxlint-plugin-safe-ts/recommended.json"]
104
+ }
105
+ ```
106
+
107
+ Run it as `oxlint --deny-warnings` (add `--type-aware` if the project uses type-aware rules).
108
+ The plugin checks `.vue` components too, template included. The project's own `rules` win over
109
+ the preset's: while files are legacy, downgrade the preset's oxlint rules that report in them
110
+ (`"no-empty": "warn"`, `"unicorn/prefer-at": "off"`), with a line in the exception list, and
111
+ remove those lines at the end. oxlint takes the level of a `safe-ts/*` finding from this file;
112
+ an `"off"` in package.json's `"safe-ts"` wins in both.
113
+
114
+ ## vite.config.ts
115
+
116
+ ```ts
117
+ import { safeTs } from "@evobug_com/safe-ts-transform";
118
+ import vue from "@vitejs/plugin-vue"; // or: import react from "@vitejs/plugin-react";
119
+ import { defineConfig } from "vite";
120
+
121
+ // safeTs before the framework's plugin: it rewrites q(...), match(...), parseJson<T> and
122
+ // <Match> before the framework compiles the file. `exclude` is for vendored or generated code
123
+ // only: an excluded file isn't checked or transformed, and gets no prelude imports.
124
+ export default defineConfig({ plugins: [safeTs({ check: "error", exclude: ["src/vendor/**"] }), vue()] });
125
+ ```
126
+
127
+ `check: "warn"` (the default) prints findings in the dev server; `"error"` shows the overlay and
128
+ fails the build on errors (warnings are printed). `vite build` ends with
129
+ `safe-ts: N files checked, M legacy, K problems`: if that line is missing, the plugin didn't run. What `vite.config.ts` imports runs without the plugin: keep the prelude and
130
+ `q(...)` out of it, or load those modules with `loadTransformed` (Adopting SAFE-TS, "The Vite
131
+ config").
132
+
133
+ Node processes that run TypeScript directly (scripts, `node --test`, workers) need the loader:
134
+ `node --import @evobug_com/safe-ts-transform/register <file>.ts`.
135
+
136
+ ## Bun
137
+
138
+ `bun run` and `bun test` get the transform from the Bun plugin, not the Node loader:
139
+
140
+ ```toml
141
+ # bunfig.toml
142
+ preload = ["@evobug_com/safe-ts-transform/bun"]
143
+
144
+ [test]
145
+ preload = ["@evobug_com/safe-ts-transform/bun"]
146
+ ```
147
+
148
+ The `bun build` command takes no plugins. Bundle with a script (`bun build.ts`):
149
+
150
+ ```ts
151
+ import { safeTsBun } from "@evobug_com/safe-ts-transform";
152
+
153
+ const result = await Bun.build({ entrypoints: ["src/main.ts"], outdir: "dist", target: "bun", plugins: [safeTsBun({ check: "error" })] });
154
+ if (!result.success) process.exit(1);
155
+ ```
156
+
157
+ A Vite app run with Bun (`bunx --bun vite`) uses the Vite plugin as above.
158
+
159
+ ## CI job
160
+
161
+ GitHub Actions syntax (Forgejo Actions reads the same):
162
+
163
+ ```yaml
164
+ name: checks
165
+ on: [push, pull_request]
166
+ jobs:
167
+ checks:
168
+ runs-on: ubuntu-latest
169
+ steps:
170
+ - uses: actions/checkout@v4
171
+ - uses: actions/setup-node@v4
172
+ with:
173
+ node-version: lts/*
174
+ - run: npm ci
175
+ - run: npx safe-ts --version # the checker's version in the log
176
+ - run: npx vue-tsc --noEmit # or: npx tsc --noEmit
177
+ - run: npx oxlint --deny-warnings
178
+ - run: npm run check:safe-ts # safe-ts check ... --deny-warnings
179
+ - run: npm run check:architecture
180
+ - run: npm test
181
+ - run: npx vite build # ends with "safe-ts: N files checked, ..."
182
+ ```
183
+
184
+ ## Conventions section for CLAUDE.md / AGENTS.md
185
+
186
+ ```markdown
187
+ ## SAFE-TS
188
+
189
+ This project follows SAFE-TS. The decisions are in docs/safe-ts-architecture.md; read it before
190
+ changing code, and follow it over habits from other projects.
191
+
192
+ - A function that can fail returns `Result<T, E>`; pass errors up with `q(...)` (with a mapping
193
+ or `mapErr` when the error type changes). No `throw new Error`. No `try`/`catch` around our
194
+ own code.
195
+ - Absence is `undefined` (`Option<T>`). No `null`; `jsonNull` only in request bodies that clear a
196
+ field. "Not loaded" is an `AsyncState`, "none" an `Option` or an `Enum` variant.
197
+ - Async work goes through `useTask` and is shown with `<Match>` / `match`. No `loading`,
198
+ `error` or `data` refs. Every request takes the task's `signal`.
199
+ - Closed sets are `Enum`s with `constructors`; read them with `match`, `is`, `variant` (and
200
+ `<Match :value="...">` in templates). No raw `.tag ===`. No `''`, `-1` or `0` meaning "none".
201
+ - Outside data goes through `validate<T>` / `parseJson<T>` or a feature pack's safe version. No
202
+ `as`, no hand-written `value is T` guards (`no-type-predicate`) and no overloads over a looser
203
+ implementation (`no-overload`). A trusted boundary inside the program is
204
+ `trust<T>(value)`, listed in the architecture document.
205
+ - Wire-keyed tables: `getOwn(table, key, fallback)`; a server field from a list that can grow is
206
+ `Open<K>`, read with `match` and `lookup`. Base64: `toBase64` / `fromBase64` (`btoa` only of
207
+ an `Ascii`).
208
+ - Request bodies that change a record are `Patch<T>` (`keep`, `clear`, a value).
209
+ - Markup is `Html` (from the sanitizer declared with `defineSanitizer` in <module>), URLs are
210
+ `SafeUrl` (from `safeHref`); never `as Html`. Test numbers and strings explicitly
211
+ (`count > 0`, `name !== ""`), not for truth; a value that may be `undefined` gets both halves
212
+ (`name !== undefined && name !== ""`), never `name !== ""` alone.
213
+ - Optional keys under `exactOptionalPropertyTypes`: `...(x === undefined ? {} : { x })`.
214
+ - No module state: Pinia setup stores (Vue) or provided contexts.
215
+ - Escape hatches (`unsafe`, `unsafeAsync`, `panic`, `trust`, `LegacyNull`, `void`, casts,
216
+ `safe-ts-ignore`, `@ts-expect-error`, legacy markers, rule levels) follow
217
+ docs/safe-ts-architecture.md, each with a reason. Never `@ts-ignore` or `@ts-nocheck`. A line that must stay as it is: `// safe-ts-ignore <rule>: <reason>`. A file not
218
+ migrated yet: `// @safe-ts legacy`. Never a new one without a line in the exception list.
219
+ - Tests use `fixture`, `testDouble`, `unchecked` and `expectPresent` from
220
+ `@evobug_com/safe-ts-std/testing`, not casts.
221
+ - Before a change is done: `npm run check:safe-ts` (`--deny-warnings`: warnings count),
222
+ `npm run check:architecture`, the type check, `oxlint --deny-warnings`, the tests and the
223
+ build pass.
224
+ ```
225
+
226
+ ## Hand-off report, per area
227
+
228
+ ```markdown
229
+ # <area>: SAFE-TS migration
230
+
231
+ ## Gates
232
+ - types / lint / safe-ts (`--deny-warnings`) / architecture / tests / build: pass (paste the
233
+ summary lines, and `safe-ts --version`)
234
+
235
+ ## Census, before → after (this area's directories)
236
+ - checker findings: <n> → <n>
237
+ - legacy files: <n> → 0
238
+ - patterns: trio-files <n> → <n>, loading-flag ..., string-if-chain ..., as-cast ..., ...
239
+ - features: useTask <n> → <n>, Enum ..., match ..., <Match> ..., q ...
240
+ - idiomatic findings: prefer-is-over-tag <n> → <n>, prefer-q ..., no-swallowed-error ..., ...
241
+ - escape hatches: unsafe <n> (each with its reason), panic <n>, trust <n>, LegacyNull <n>,
242
+ safe-ts-ignore <n>, @ts-expect-error <n>, void <n>, casts <n>; weakened: <none, or each>
243
+
244
+ ## Causes removed
245
+ - <the class of bug>: <the design that rules it out> (cleared: <rule> <n>, <pattern> <n>)
246
+ e.g. "an empty id passed as a real one: `Option<UnitId>`, made only by `parseUnitId`
247
+ (cleared: strict-truthiness 14, empty-string-sentinel 9)"
248
+ - local fixes, each with why the cause is local: <file:line>: <why>
249
+
250
+ ## Changed signatures (callers in other areas must be checked)
251
+ - `useIssueStore().rename`: now `Promise<Result<void, RequestError>>` (was rejecting)
252
+ - `formatDue(due)`: takes `Option<string>` (was `string | null`)
253
+
254
+ ## Behaviour
255
+ - bodies compared for: <flows>; differences: <none / intended: ...>
256
+ - smoke: <pages>, failure paths: <which>; findings: <none / ...>
257
+
258
+ ## Remaining exceptions
259
+ - <file:line>: <what>, <why>, <until when> (also in the architecture document)
260
+ ```