@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.
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +15 -2
- package/install.mjs +86 -0
- package/package.json +35 -4
- package/safe-ts-migrate/SKILL.md +178 -0
- package/safe-ts-migrate/references/architecture.md +146 -0
- package/safe-ts-migrate/references/behaviour.md +86 -0
- package/safe-ts-migrate/references/census.md +136 -0
- package/safe-ts-migrate/references/escape-hatches.md +72 -0
- package/safe-ts-migrate/references/final-pass.md +46 -0
- package/safe-ts-migrate/references/fix-the-design.md +87 -0
- package/safe-ts-migrate/references/order-and-gates.md +101 -0
- package/safe-ts-migrate/references/patterns-core.md +2229 -0
- package/safe-ts-migrate/references/patterns-react.md +266 -0
- package/safe-ts-migrate/references/patterns-vue.md +713 -0
- package/safe-ts-migrate/references/review-checklist.md +70 -0
- package/safe-ts-migrate/references/templates.md +260 -0
- package/safe-ts-migrate/references/tool-gaps.md +394 -0
- package/safe-ts-migrate/scripts/census.mjs +870 -0
- package/safe-ts-migrate/scripts/safe-ts.mjs +79 -0
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Evobug
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @evobug_com/safe-ts-skill
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An agent skill (Claude Code / Agent Skills format) for migrating an existing project to SAFE-TS: the target architecture first, a census script, a pattern catalogue with before and after, gates, behaviour checks and a review checklist. `npx @evobug_com/safe-ts-skill` copies it into .claude/skills/.
|
|
4
|
+
|
|
5
|
+
**Documentation: [safe-ts.evobug-pages.com/guide/migration-skill](https://safe-ts.evobug-pages.com/guide/migration-skill)**
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx @evobug_com/safe-ts-skill
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Part of [SAFE-TS](https://safe-ts.evobug-pages.com/), a strict, Rust-flavoured subset of TypeScript. The website has the
|
|
12
|
+
guides, a page per rule, and a playground that runs the checker in your browser.
|
|
13
|
+
|
|
14
|
+
Changes in each version: [CHANGELOG.md](https://git.evobug.com/Evobug/Safe-Ts/src/branch/main/CHANGELOG.md).
|
|
15
|
+
|
|
16
|
+
Source: https://git.evobug.com/Evobug/Safe-Ts. Licensed under MIT OR Apache-2.0.
|
package/install.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copies the safe-ts-migrate agent skill into a project:
|
|
3
|
+
//
|
|
4
|
+
// npx @evobug_com/safe-ts-skill -> ./.claude/skills/safe-ts-migrate
|
|
5
|
+
// npx @evobug_com/safe-ts-skill --to <skills dir> -> <skills dir>/safe-ts-migrate
|
|
6
|
+
// npx @evobug_com/safe-ts-skill --force replace a copy that differs
|
|
7
|
+
//
|
|
8
|
+
// Use the version that matches the project's other @evobug_com packages
|
|
9
|
+
// (`npx @evobug_com/safe-ts-skill@0.5.1`): the skill describes that version's APIs.
|
|
10
|
+
//
|
|
11
|
+
// It runs before SAFE-TS is installed, so it can't import std: each call that can fail goes
|
|
12
|
+
// through `orExit`, which names what failed and exits 2. It passes oxlint with the SAFE-TS
|
|
13
|
+
// preset, like the skill's scripts.
|
|
14
|
+
import { cpSync, existsSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
15
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runs `step` and returns its value; when it throws, prints `safe-ts-skill: <what>: <why>` and exits 2.
|
|
20
|
+
* @template T
|
|
21
|
+
* @param {string} what
|
|
22
|
+
* @param {() => T} step
|
|
23
|
+
* @returns {T}
|
|
24
|
+
*/
|
|
25
|
+
function orExit(what, step) {
|
|
26
|
+
try {
|
|
27
|
+
return step();
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error(`safe-ts-skill: ${what}: ${error instanceof Error ? error.message : String(error)}`);
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
35
|
+
|
|
36
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
// Published: next to this file. In the SAFE-TS repository: skills/ at the root.
|
|
38
|
+
const source = [join(here, "safe-ts-migrate"), join(here, "..", "..", "skills", "safe-ts-migrate")].find((dir) =>
|
|
39
|
+
existsSync(join(dir, "SKILL.md")),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const args = process.argv.slice(2);
|
|
43
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
44
|
+
console.log("usage: safe-ts-skill [--to <skills dir>] [--force]\n copies the safe-ts-migrate skill to <skills dir>/safe-ts-migrate (default: .claude/skills)");
|
|
45
|
+
process.exit(0);
|
|
46
|
+
}
|
|
47
|
+
const toIndex = args.indexOf("--to");
|
|
48
|
+
const skills = resolve(toIndex === -1 ? ".claude/skills" : (args[toIndex + 1] ?? ".claude/skills"));
|
|
49
|
+
const target = join(skills, "safe-ts-migrate");
|
|
50
|
+
const shown = relative(process.cwd(), target) || ".";
|
|
51
|
+
|
|
52
|
+
if (source === undefined) {
|
|
53
|
+
console.error("safe-ts-skill: the skill's files are missing from this package");
|
|
54
|
+
process.exit(2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Every file under `dir`, relative to it. */
|
|
58
|
+
function files(dir) {
|
|
59
|
+
return orExit(`can't list ${dir}`, () => readdirSync(dir, { recursive: true }))
|
|
60
|
+
.map(String)
|
|
61
|
+
.filter((f) => orExit(`can't read ${join(dir, f)}`, () => statSync(join(dir, f))).isFile())
|
|
62
|
+
.sort(byText);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const bytes = (file) => orExit(`can't read ${file}`, () => readFileSync(file));
|
|
66
|
+
|
|
67
|
+
const same = (a, b) => {
|
|
68
|
+
const left = files(a);
|
|
69
|
+
const right = files(b);
|
|
70
|
+
return left.length === right.length && left.every((f, i) => f === right[i] && bytes(join(a, f)).equals(bytes(join(b, f))));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
if (existsSync(target)) {
|
|
74
|
+
if (same(source, target)) {
|
|
75
|
+
console.log(`safe-ts-skill: ${shown} is already this version`);
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
if (!args.includes("--force")) {
|
|
79
|
+
console.error(`safe-ts-skill: ${shown} exists and differs (another version, or edited). --force replaces it; edits there are lost.`);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
orExit(`can't remove the old ${shown}`, () => rmSync(target, { recursive: true, force: true }));
|
|
83
|
+
}
|
|
84
|
+
orExit(`can't copy the skill to ${shown}`, () => cpSync(source, target, { recursive: true }));
|
|
85
|
+
console.log(`safe-ts-skill: installed ${shown}`);
|
|
86
|
+
console.log("Ask your agent to migrate the project to SAFE-TS; it reads SKILL.md first.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evobug_com/safe-ts-skill",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "An agent skill (Claude Code / Agent Skills format) for migrating an existing project to SAFE-TS: the target architecture first, a census script, a pattern catalogue with before and after, gates, behaviour checks and a review checklist. `npx @evobug_com/safe-ts-skill` copies it into .claude/skills/.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"safe-ts",
|
|
7
|
+
"typescript",
|
|
8
|
+
"migration",
|
|
9
|
+
"agent-skill",
|
|
10
|
+
"claude-code",
|
|
11
|
+
"codemod"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT OR Apache-2.0",
|
|
14
|
+
"homepage": "https://safe-ts.evobug-pages.com/guide/migration-skill",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://git.evobug.com/Evobug/Safe-Ts.git",
|
|
18
|
+
"directory": "skills/safe-ts-migrate"
|
|
19
|
+
},
|
|
20
|
+
"bugs": "https://git.evobug.com/Evobug/Safe-Ts/issues",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"bin": {
|
|
23
|
+
"safe-ts-skill": "install.mjs"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"install.mjs",
|
|
27
|
+
"safe-ts-migrate",
|
|
28
|
+
"LICENSE-MIT",
|
|
29
|
+
"LICENSE-APACHE"
|
|
30
|
+
],
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22.18.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: safe-ts-migrate
|
|
3
|
+
description: Migrate an existing TypeScript, Vue or React project to SAFE-TS (the @evobug_com/safe-ts-* packages) toward its target architecture, not only a passing checker. Use when asked to adopt SAFE-TS in a code base, plan or run a SAFE-TS migration, convert an area or remove `// @safe-ts legacy` markers, take a census of what is left, review a SAFE-TS migration change, or upgrade a project already on SAFE-TS to a newer version.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Migrating a project to SAFE-TS
|
|
7
|
+
|
|
8
|
+
Written for SAFE-TS 0.5.1. Check the installed version (`npx safe-ts --version`); if it is
|
|
9
|
+
newer, read its CHANGELOG entries first and prefer what they say over
|
|
10
|
+
[references/tool-gaps.md](references/tool-gaps.md).
|
|
11
|
+
|
|
12
|
+
**The goal is the target architecture, and the checker is one gate among several.** Without the
|
|
13
|
+
idiomatic layer, `safe-ts check` accepts a `.tag === 'Ready'` chain, an `if (isErr(x)) return
|
|
14
|
+
x` and an `unwrapOr(x, undefined)`; with it, they are warnings, and a run with only warnings
|
|
15
|
+
still exits 0. Even then it accepts a boolean flag set beside an `Enum`, a `''` that means "none" and a string if-chain. A migration that aims at "no
|
|
16
|
+
findings" converts `null` and `throw` and stops there. This skill aims at the architecture
|
|
17
|
+
SAFE-TS is built for: `Result` for failures, `Option` for absence, `useTask` and `AsyncState` for
|
|
18
|
+
async work, `Enum` and `match` for closed sets, validated boundaries, no module state.
|
|
19
|
+
|
|
20
|
+
## Rules for the whole migration
|
|
21
|
+
|
|
22
|
+
- **Fix the design, not the finding.** A finding points at a line, but the bug is in the
|
|
23
|
+
design that let it be written: a type that admits a bad value, a closed set that exists only
|
|
24
|
+
in `if` chains, state with two owners. Group the findings by cause, change the representation
|
|
25
|
+
so the class of bug can't be written, and let the compiler list the places that follow, the
|
|
26
|
+
way a Rust borrow error is fixed by changing ownership, not by moving a variable. A guard, a
|
|
27
|
+
default or a branch added at the reported line is a patch; it needs a reason in the hand-off
|
|
28
|
+
report ([references/fix-the-design.md](references/fix-the-design.md)).
|
|
29
|
+
- **Only real APIs.** Every function, rule, option and command you write must exist in the
|
|
30
|
+
installed packages (read the `.d.ts` files in `node_modules/@evobug_com/`) or the guide
|
|
31
|
+
(https://safe-ts.evobug-pages.com). Don't invent wrappers around std; the architecture
|
|
32
|
+
document lists the project's sanctioned helpers.
|
|
33
|
+
- **Behaviour stays the same**, unless the architecture document says otherwise: same request
|
|
34
|
+
bodies, same messages in the same places. Static gates don't prove it
|
|
35
|
+
([references/behaviour.md](references/behaviour.md)).
|
|
36
|
+
- **A gate is never fixed by weakening it**: no new legacy marker, `safe-ts-ignore` comment,
|
|
37
|
+
`@ts-expect-error`, rule set to `"off"` or `"warn"`, cast, `trust`, `void` or baseline rewrite
|
|
38
|
+
without a line in the architecture document's exception list. Never `@ts-ignore` or
|
|
39
|
+
`@ts-nocheck`.
|
|
40
|
+
- **"The checker passes" means `safe-ts check <dirs or entries> --deny-warnings` exits 0**,
|
|
41
|
+
with `"idiomatic": true` in package.json. Warnings alone exit 0, and the idiomatic rules are
|
|
42
|
+
warnings: never read a plain `check` run's exit code as done. With `--deny-warnings`, a file
|
|
43
|
+
the entries don't reach, an import that resolves to nothing and a `warning:` line about the
|
|
44
|
+
setup (no strict-lib in the tsconfig, a pack not installed) fail it too. Run it this way in your own loop,
|
|
45
|
+
not only in CI.
|
|
46
|
+
- **The CLI is the `safe-ts` command** (`npx safe-ts check src/main.ts`, `npx safe-ts migrate
|
|
47
|
+
throw-to-result src/`, `safe-ts ...` in package.json scripts). It comes with the transform and
|
|
48
|
+
the oxlint plugin; with pnpm, add `@evobug_com/safe-ts-native` as a dev dependency.
|
|
49
|
+
`scripts/safe-ts.mjs` finds the binary without a bin link (the census uses it).
|
|
50
|
+
- **Ask the user once, at the architecture document.** It holds the decisions only the project
|
|
51
|
+
can make. After it is approved, work through the steps without asking again unless a decision
|
|
52
|
+
in it turns out wrong.
|
|
53
|
+
|
|
54
|
+
## Workflow
|
|
55
|
+
|
|
56
|
+
1. **Read the project.** Package manager, framework, build, test runner, tsconfig (and its
|
|
57
|
+
`paths` aliases), the HTTP layer, the state library, the processes that run TypeScript
|
|
58
|
+
directly. Note what [references/tool-gaps.md](references/tool-gaps.md) says about each.
|
|
59
|
+
2. **Take the census** before anything is marked legacy:
|
|
60
|
+
`node <this skill>/scripts/census.mjs > census-before.txt`
|
|
61
|
+
([references/census.md](references/census.md)). It counts the checker's findings per rule
|
|
62
|
+
and directory, the root causes, the patterns the checker doesn't report, the escape hatches,
|
|
63
|
+
and how much of SAFE-TS the code already uses.
|
|
64
|
+
3. **Write the target architecture document** from
|
|
65
|
+
[references/architecture.md](references/architecture.md), with the census as its evidence:
|
|
66
|
+
absence policy, errors and requests, state, async work, closed sets, boundaries, tooling,
|
|
67
|
+
escape-hatch budget, sanctioned helpers, exceptions, areas and order. Get it approved.
|
|
68
|
+
4. **Set up** ([references/templates.md](references/templates.md)): packages, tsconfig flags
|
|
69
|
+
(`strict`, `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`: `safe-ts check` warns
|
|
70
|
+
for each one left off) and std's strict-lib in
|
|
71
|
+
`"types"` (lib's `any` from `JSON.parse`, `response.json()`, ... as `unknown`), the oxlint preset,
|
|
72
|
+
the Vite plugin (or the Bun plugin), the loader for Node, `"idiomatic": true`, the feature
|
|
73
|
+
packs, `"requestFunctions"` for the project's request wrapper, the scripts, the CI job, the
|
|
74
|
+
conventions section in `CLAUDE.md` / `AGENTS.md`. Mark the files that don't pass yet with
|
|
75
|
+
`// @safe-ts legacy` and list them under `"legacyFiles"` in package.json (`safe-ts check`
|
|
76
|
+
prints the lines), then write the census baseline (`--write-baseline safe-ts-census.json`)
|
|
77
|
+
and the checker's (`safe-ts check src --write-baseline safe-ts-baseline.json`): from here the
|
|
78
|
+
counts may only fall.
|
|
79
|
+
5. **Migrate in order** ([references/order-and-gates.md](references/order-and-gates.md)): the
|
|
80
|
+
shared foundation (transport, requests, error types, stores), then utilities and the component
|
|
81
|
+
library, then the feature areas in parallel by dependency, then the removal of bridges and the
|
|
82
|
+
last markers. For each change:
|
|
83
|
+
- group the area's findings by cause and name, for each group, the design that rules it out
|
|
84
|
+
([references/fix-the-design.md](references/fix-the-design.md#the-procedure)); change that
|
|
85
|
+
first, then the call sites;
|
|
86
|
+
- rewrite with the catalogue: [references/patterns-core.md](references/patterns-core.md),
|
|
87
|
+
[references/patterns-vue.md](references/patterns-vue.md),
|
|
88
|
+
[references/patterns-react.md](references/patterns-react.md). For the repetitive part,
|
|
89
|
+
`safe-ts migrate <codemod> src/` (prints a diff; `--write` applies it): it rewrites `.ts`
|
|
90
|
+
files and Vue components together, so give it the whole source folder;
|
|
91
|
+
- pass every gate in [references/order-and-gates.md](references/order-and-gates.md#gates-per-step);
|
|
92
|
+
- run the behaviour checks for the area ([references/behaviour.md](references/behaviour.md));
|
|
93
|
+
- list every exported signature that changed, and read every caller of each, in every area;
|
|
94
|
+
- write the hand-off report ([references/templates.md](references/templates.md#hand-off-report-per-area)).
|
|
95
|
+
6. **Final pass**: [references/final-pass.md](references/final-pass.md). Run the census and
|
|
96
|
+
replace the hand-rolled state, sentinels and if-chains that remain with `useTask`,
|
|
97
|
+
`AsyncState`, `Enum`, `match`, `Option` and `q`, or record why each one stays.
|
|
98
|
+
7. **Review and hand off** with [references/review-checklist.md](references/review-checklist.md)
|
|
99
|
+
and the escape-hatch counts ([references/escape-hatches.md](references/escape-hatches.md)):
|
|
100
|
+
census before and after, what remains, and why.
|
|
101
|
+
|
|
102
|
+
## Upgrading between versions
|
|
103
|
+
|
|
104
|
+
For a project already on SAFE-TS that moves to a newer release (0.3.0 to 0.4.0, say). Read
|
|
105
|
+
the CHANGELOG sections in between first: **Added** lists the new rules, and **Changed** the
|
|
106
|
+
rules that now report more.
|
|
107
|
+
|
|
108
|
+
1. **Bump every `@evobug_com` package together, then take the census.** They are released with
|
|
109
|
+
one version, and each package's peer range is its own minor (`^0.4.0`, which npm reads as
|
|
110
|
+
`>=0.4.0 <0.5.0` for a 0.x version), so a mix of versions doesn't install. Changing the pins
|
|
111
|
+
in package.json and running `npm install` can stop with `ERESOLVE` when the lockfile still
|
|
112
|
+
holds an old one (`safe-ts-vue@0.3.0` while the new `safe-ts-feature-browser` peers
|
|
113
|
+
`safe-ts-std@^0.4.0`). Either name them all in one command, which keeps each in the field
|
|
114
|
+
it is in:
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
npm install @evobug_com/safe-ts-std@0.4.0 @evobug_com/safe-ts-vue@0.4.0 \
|
|
118
|
+
@evobug_com/safe-ts-transform@0.4.0 @evobug_com/oxlint-plugin-safe-ts@0.4.0 ...
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
or change the pins, delete the `node_modules/@evobug_com/...` entries from
|
|
122
|
+
`package-lock.json`, and run `npm install`. Then run the census against the baseline
|
|
123
|
+
(`--baseline safe-ts-census.json`): the new rules' findings show as rises, by file.
|
|
124
|
+
2. **Apply the new rules' fixes one rule at a time, and review each before the next.** The
|
|
125
|
+
census's `--show <rule>` lists every place of a rule; apply the editor's quick fixes (or, if
|
|
126
|
+
your version has it, `safe-ts fix <rule>`), read the diff, run the tests. Take most care
|
|
127
|
+
with `strict-truthiness`: on a value that may be `undefined`, `if (x)` meant "set and not
|
|
128
|
+
empty", and a fix that writes `x !== ''` is true for `undefined`. A 0.4.0 quick fix did
|
|
129
|
+
exactly that for an `x?: string`. Write `x !== undefined && x !== ''`, or whichever of the
|
|
130
|
+
two the code means.
|
|
131
|
+
3. **Audit the comparisons with `''` or `0` whose operand can be `undefined`**, the fixes' and
|
|
132
|
+
the code's own: `x !== ''`, `x === 0`, `x !== 0`. `--show empty-string-sentinel` lists
|
|
133
|
+
the `''` ones, and `rg -n '[!=]==?\s*0\b' src` the `0` ones. Where the operand's type
|
|
134
|
+
includes `undefined`, the comparison is true (or false) for it too: check that this is meant.
|
|
135
|
+
4. **Past the release that made `Mut<T>` a type of its own: lend every `Mut` with `mut(...)`.** Since then
|
|
136
|
+
`tsc` refuses every value passed to a `Mut` parameter without `mut(value)`. Run
|
|
137
|
+
`npx safe-ts migrate mut <your source dirs> --write` once over the whole program (all of
|
|
138
|
+
`apps` and `packages` together, so calls across packages resolve), review the diff, then
|
|
139
|
+
work through its "Needs a decision" list and what `tsc` (or `vue-tsc`) still refuses: a
|
|
140
|
+
function taking `Mut<T>` passed as a callback that only lends to read, a `Dog[]` lent as
|
|
141
|
+
`Mut<Animal[]>`, a union lent as one member (take `Mut<A> | Mut<B>`), a list of `Mut`
|
|
142
|
+
elements built by a call, a call the migration couldn't follow (patterns-core.md, "A
|
|
143
|
+
parameter the function changes"). Then the census: new
|
|
144
|
+
`aliased-mut` findings are calls that lend a value and pass a part of it too.
|
|
145
|
+
5. **Reinstall the skill with `--force`**: `npx @evobug_com/safe-ts-skill@0.4.0 --force`. It
|
|
146
|
+
replaces the copy in `.claude/skills/`, edits included, so keep project notes in the
|
|
147
|
+
architecture document.
|
|
148
|
+
|
|
149
|
+
Once the new rules' findings are fixed or recorded as exceptions, write the baseline again in a
|
|
150
|
+
commit that names the upgrade.
|
|
151
|
+
|
|
152
|
+
## When several agents migrate at once
|
|
153
|
+
|
|
154
|
+
Give each builder this skill, the approved architecture document, and the foundation's exported
|
|
155
|
+
signatures. Builders don't edit the foundation. The integrator merges the areas, runs every gate
|
|
156
|
+
on the whole tree, searches every caller of every signature an area changed (the checker follows
|
|
157
|
+
a `Result` through store members and factories, not through parameters, class fields or a
|
|
158
|
+
`Map`, and a caller's leftover `try` still compiles), and runs the browser smoke on every page.
|
|
159
|
+
|
|
160
|
+
## References
|
|
161
|
+
|
|
162
|
+
| File | Holds |
|
|
163
|
+
|---|---|
|
|
164
|
+
| [architecture.md](references/architecture.md) | the target architecture document, section by section, with SAFE-TS's defaults |
|
|
165
|
+
| [fix-the-design.md](references/fix-the-design.md) | fixing the cause, not the finding: the procedure, how to tell a patch from a design fix, examples |
|
|
166
|
+
| [census.md](references/census.md) | running and reading `scripts/census.mjs`; the pattern table; the baseline gate |
|
|
167
|
+
| [patterns-core.md](references/patterns-core.md) | before and after for TypeScript idioms: throws, requests, sentinels, enums, casts, JSON, null on the wire, optional keys, `Patch`, `Open`, base64 and `Ascii`, `trust`, `LegacyNull`, `parseArgs`, IndexedDB |
|
|
168
|
+
| [patterns-vue.md](references/patterns-vue.md) | Vue: the loading trio, `useTask`, `<Match>`, `useElement`, stores, props, `v-html` and `Html`, URLs and `SafeUrl` |
|
|
169
|
+
| [patterns-react.md](references/patterns-react.md) | React: the loading trio, `useTask`, module state, props, handlers, HTML |
|
|
170
|
+
| [order-and-gates.md](references/order-and-gates.md) | the order of work, legacy markers as scaffolding, parallel builders, the gates |
|
|
171
|
+
| [behaviour.md](references/behaviour.md) | contract checks, network bodies, browser smoke, regressions a real migration produced |
|
|
172
|
+
| [tool-gaps.md](references/tool-gaps.md) | the tools' known limits in this version, and their workarounds |
|
|
173
|
+
| [escape-hatches.md](references/escape-hatches.md) | when each hatch is allowed (`unsafe`, `trust`, `LegacyNull`, `safe-ts-ignore`, legacy markers, ...), the reason, the budget |
|
|
174
|
+
| [review-checklist.md](references/review-checklist.md) | for reviewers: correctness and architecture |
|
|
175
|
+
| [templates.md](references/templates.md) | tsconfig, package.json, oxlint, Vite, CI, the conventions section, the hand-off report |
|
|
176
|
+
| [final-pass.md](references/final-pass.md) | the "use every feature" pass |
|
|
177
|
+
| `scripts/census.mjs` | the census and the architecture gate |
|
|
178
|
+
| `scripts/safe-ts.mjs` | finds and runs the `safe-ts` binary in `node_modules` (used by the census) |
|