ruby-anything 0.2.1 → 0.2.3
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +3 -2
- package/README.md +27 -2
- package/adapters/node/harness.mjs +350 -350
- package/adapters/node/package-lock.json +26 -26
- package/adapters/node/package.json +7 -7
- package/adapters/polyglot/harness.py +350 -350
- package/adapters/polyglot/lang_csharp.py +222 -222
- package/adapters/polyglot/lang_go.py +283 -283
- package/adapters/polyglot/lang_java.py +510 -510
- package/adapters/polyglot/lang_kotlin.py +133 -133
- package/adapters/polyglot/lang_php.py +156 -156
- package/adapters/polyglot/lang_ruby.py +148 -148
- package/adapters/polyglot/lang_rust.py +430 -430
- package/adapters/polyglot/lang_swift.py +337 -337
- package/adapters/python/harness.py +459 -459
- package/docs/assets/logo.png +0 -0
- package/docs/test-results.md +102 -0
- package/package.json +6 -3
- package/skills/ruby-anything/SKILL.md +74 -1
- package/src/adapters.js +63 -60
- package/src/cli.js +3 -0
- package/src/mcp.js +2 -1
- package/src/setup.js +32 -7
- package/src/status.js +77 -0
- package/adapters/ruby/harness.rb +0 -134
|
Binary file
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Test results
|
|
2
|
+
|
|
3
|
+
<!-- generated by `npm run test:report`; do not edit by hand -->
|
|
4
|
+
|
|
5
|
+
**25 passed, 0 failed** in 30.0s, ruby-anything 0.2.2 at commit `493cedb`, 2026-11-29.
|
|
6
|
+
|
|
7
|
+
These are end-to-end tests: they run real Python and Node originals through the recorders,
|
|
8
|
+
real Ruby ports through the replay harness, and real HTTP servers, SMTP and SQLite for side
|
|
9
|
+
effects. The workflow tests check both that a correct port passes and that a wrong one is caught.
|
|
10
|
+
|
|
11
|
+
Every push also runs this suite on Ubuntu, Windows and macOS in GitHub Actions:
|
|
12
|
+
[latest runs](https://github.com/akkisavi/ruby-anything/actions/workflows/ruby-anything.yml).
|
|
13
|
+
|
|
14
|
+
| Environment | Version |
|
|
15
|
+
|---|---|
|
|
16
|
+
| OS | win32 x64 |
|
|
17
|
+
| Node | v24.6.0 |
|
|
18
|
+
| Python | Python 3.12.10 |
|
|
19
|
+
| Ruby | ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [x64-mingw-ucrt] |
|
|
20
|
+
|
|
21
|
+
## Whole app over HTTP, with side effects
|
|
22
|
+
|
|
23
|
+
`test/app.test.js`
|
|
24
|
+
|
|
25
|
+
| Result | Test | Time |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| ✅ pass | app record and replay against the original | 1413 ms |
|
|
28
|
+
| ✅ pass | side effects: payment call, email and database rows are recorded and checked | 7278 ms |
|
|
29
|
+
|
|
30
|
+
## Whole CLI app: record, front door, wire, lift
|
|
31
|
+
|
|
32
|
+
`test/cli.test.js`
|
|
33
|
+
|
|
34
|
+
| Result | Test | Time |
|
|
35
|
+
|---|---|---|
|
|
36
|
+
| ✅ pass | CLI record: exit codes, output, stdin and files, without touching the checkout | 1490 ms |
|
|
37
|
+
| ✅ pass | CLI front door: fallback, wire, catch a wrong exit code, lift | 7244 ms |
|
|
38
|
+
|
|
39
|
+
## Comparison rules (numbers, errors, HTML, noise, side effects)
|
|
40
|
+
|
|
41
|
+
`test/compare.test.js`
|
|
42
|
+
|
|
43
|
+
| Result | Test | Time |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| ✅ pass | int and float stay apart | 1 ms |
|
|
46
|
+
| ✅ pass | exact doubles from different harnesses compare equal | 0 ms |
|
|
47
|
+
| ✅ pass | error families map across languages | 0 ms |
|
|
48
|
+
| ✅ pass | compareCase names the first difference | 1 ms |
|
|
49
|
+
| ✅ pass | html text and replay modes | 1 ms |
|
|
50
|
+
| ✅ pass | noise becomes wildcards, word by word | 0 ms |
|
|
51
|
+
| ✅ pass | side effects are compared | 0 ms |
|
|
52
|
+
|
|
53
|
+
## --pin-clock and drift
|
|
54
|
+
|
|
55
|
+
`test/drift.test.js`
|
|
56
|
+
|
|
57
|
+
| Result | Test | Time |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| ✅ pass | --pin-clock: the original and the port see the same instant | 1687 ms |
|
|
60
|
+
| ✅ pass | drift: nothing changed, then an upstream change is reported | 1800 ms |
|
|
61
|
+
|
|
62
|
+
## record --from-tests (Python unittest, node --test)
|
|
63
|
+
|
|
64
|
+
`test/fromtests.test.js`
|
|
65
|
+
|
|
66
|
+
| Result | Test | Time |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| ✅ pass | Python unittest calls are recorded | 745 ms |
|
|
69
|
+
| ✅ pass | node --test calls are recorded | 565 ms |
|
|
70
|
+
| ✅ pass | a leftover backup from a crash is restored first | 629 ms |
|
|
71
|
+
|
|
72
|
+
## status.test.js
|
|
73
|
+
|
|
74
|
+
`test/status.test.js`
|
|
75
|
+
|
|
76
|
+
| Result | Test | Time |
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| ✅ pass | status follows the stages and writes nothing | 550 ms |
|
|
79
|
+
| ✅ pass | the MCP server lists the status tool | 49 ms |
|
|
80
|
+
| ✅ pass | setup registers JSON-config agents and leaves unparseable configs alone | 140 ms |
|
|
81
|
+
|
|
82
|
+
## One function: analyze, bridge, record, diff, gate, rules
|
|
83
|
+
|
|
84
|
+
`test/units.test.js`
|
|
85
|
+
|
|
86
|
+
| Result | Test | Time |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| ✅ pass | analyze finds the functions | 244 ms |
|
|
89
|
+
| ✅ pass | bridge writes a stub that gate rejects | 942 ms |
|
|
90
|
+
| ✅ pass | a correct port passes diff and gate | 2183 ms |
|
|
91
|
+
| ✅ pass | diff catches half-up rounding and int vs float | 1126 ms |
|
|
92
|
+
| ✅ pass | gate rejects copied answers and edited recordings | 992 ms |
|
|
93
|
+
| ✅ pass | rules are kept | 96 ms |
|
|
94
|
+
|
|
95
|
+
## Run it yourself
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
cd packages/ruby-anything
|
|
99
|
+
npm install
|
|
100
|
+
npm test # the suite
|
|
101
|
+
npm run test:report # the suite, and rewrite this file
|
|
102
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruby-anything",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Migrate any app (TypeScript, JavaScript, Python, Go, Java/Spring, Kotlin, C#, PHP, Rust, Swift) to Ruby on Rails with Hotwire, Tailwind and daisyUI, one piece at a time, checked against the original's recorded behavior at every step.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ruby",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"url": "git+https://github.com/akkisavi/ruby-anything.git",
|
|
22
22
|
"directory": "packages/ruby-anything"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://ruby-anything.vercel.app",
|
|
25
|
+
"mcpName": "io.github.akkisavi/ruby-anything",
|
|
25
26
|
"bugs": {
|
|
26
27
|
"url": "https://github.com/akkisavi/ruby-anything/issues"
|
|
27
28
|
},
|
|
@@ -43,7 +44,9 @@
|
|
|
43
44
|
"!adapters/node/node_modules"
|
|
44
45
|
],
|
|
45
46
|
"scripts": {
|
|
46
|
-
"
|
|
47
|
+
"prepack": "node scripts/sync-adapters.js",
|
|
48
|
+
"test": "node scripts/test.js",
|
|
49
|
+
"test:report": "node scripts/test-report.js"
|
|
47
50
|
},
|
|
48
51
|
"engines": {
|
|
49
52
|
"node": ">=18"
|
|
@@ -26,7 +26,7 @@ its constructs map to Ruby and the traps that made recorded cases differ.
|
|
|
26
26
|
[csharp.md](languages/csharp.md) (ASP.NET Core), [php.md](languages/php.md) (Laravel),
|
|
27
27
|
[rust.md](languages/rust.md), [swift.md](languages/swift.md).
|
|
28
28
|
|
|
29
|
-
Tools: the `ruby-anything` CLI, or the same steps as MCP tools (`ruby-anything mcp`): `go`,
|
|
29
|
+
Tools: the `ruby-anything` CLI, or the same steps as MCP tools (`ruby-anything mcp`): `status`, `go`,
|
|
30
30
|
`analyze`, `bridge`, `record`, `diff`, `gate`, `rules`, `app_record`, `app_replay`,
|
|
31
31
|
`app_front_door`, `app_wire`, `app_status`, `app_lift`, `doctor`. If the MCP tools are missing, use
|
|
32
32
|
the CLI. If `ruby-anything` is not installed, ask the user to run `npm i -g ruby-anything` and
|
|
@@ -47,6 +47,24 @@ ruby-anything go # every later run: replay, fallback rate,
|
|
|
47
47
|
Each run moves to the next stage and writes `rails/port/TASK.md`. Do what it says, then run `go`
|
|
48
48
|
again. Report its stage and next step to the user at each checkpoint.
|
|
49
49
|
|
|
50
|
+
## Resuming in a new session: `status`
|
|
51
|
+
|
|
52
|
+
The migration may have started in an earlier session. Before anything else, run:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
ruby-anything status # stage, next step, current TASK.md, open units, fallback rate
|
|
56
|
+
ruby-anything status --json # the same for you to parse
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
It only reads; it records, replays and writes nothing. Then read the files under "read first"
|
|
60
|
+
(TASK.md, RULES.md, DECISIONS.md, MAP.md, HANDOFF.md) before you change any code. Never ask the
|
|
61
|
+
user a decision that DECISIONS.md already settles. Finish the units it lists as `bridged` or
|
|
62
|
+
`in progress` before starting new ones. Tell the user in one line where it stands, then continue
|
|
63
|
+
with its `next` step.
|
|
64
|
+
|
|
65
|
+
Before you stop in the middle of a piece, write `rails/port/HANDOFF.md`: what you were doing,
|
|
66
|
+
what you tried, what failed, and the next command. The next session reads it.
|
|
67
|
+
|
|
50
68
|
## 1. Plan, then stop
|
|
51
69
|
|
|
52
70
|
```sh
|
|
@@ -144,3 +162,58 @@ Then report to the user, and **wait for their go-ahead before the next unit or r
|
|
|
144
162
|
- what changed (files, functions, routes, views),
|
|
145
163
|
- gate output, diff counts, replay result and fallback rate,
|
|
146
164
|
- behavior differences or risks left, and what is left in the plan.
|
|
165
|
+
|
|
166
|
+
## Troubleshooting
|
|
167
|
+
|
|
168
|
+
Change one thing at a time and rerun the narrowest check (one case, one unit) before the full run.
|
|
169
|
+
Never edit a recording, a test or a known-diff to make a check pass.
|
|
170
|
+
|
|
171
|
+
**`diff` is not N/N**
|
|
172
|
+
|
|
173
|
+
- Read the groups first. Mismatches that share a group usually share one cause: fix the
|
|
174
|
+
first one in each group, then rerun.
|
|
175
|
+
- `diff --json` gives each mismatch's args, expected and actual, and where they first differ. Run
|
|
176
|
+
the original on those args yourself if the recorded value surprises you.
|
|
177
|
+
- `1` vs `1.0`, `2.5` rounding to `2` or `3`, `-7 / 2`, `-7 % 3`: number semantics. Check the
|
|
178
|
+
traps in the language file before changing logic.
|
|
179
|
+
- A different error class: raise the class the mapping in step 2 expects, or define the original's
|
|
180
|
+
own class name.
|
|
181
|
+
- Keys in a different order: build the hash in the original's order; sort only where it sorts.
|
|
182
|
+
- Only non-ASCII cases fail: regex classes or string length (bytes, UTF-16 units, characters).
|
|
183
|
+
- `stalled`: stop editing. Show the user the remaining mismatches and ask for the rule you are
|
|
184
|
+
missing, then save it with `rules --add`.
|
|
185
|
+
|
|
186
|
+
**The recording is flaky** (recording twice gives different results, or the original does not replay
|
|
187
|
+
its own recording)
|
|
188
|
+
|
|
189
|
+
- Time and dates: record again with `--pin-clock`.
|
|
190
|
+
- Random values, UUIDs, generated ids: cannot match across languages. Make the value an argument,
|
|
191
|
+
or inject the generator, in both the original call and the port. For whole-app cases, values that
|
|
192
|
+
change between runs become `[..]` wildcards; add `[..]` by hand for noise the double run missed,
|
|
193
|
+
and say why in DECISIONS.md.
|
|
194
|
+
- Time zone, locale or environment: record and diff with the same `TZ`, `LANG` and env vars.
|
|
195
|
+
- Shared state (database rows, files, caches) left by earlier cases: record with
|
|
196
|
+
`--db-reset "<command>"` so every case starts from the same data.
|
|
197
|
+
- Set iteration order (Python `set`, Go maps): the original's own order is not stable. Ask the
|
|
198
|
+
user whether to sort, and record it as an ADR and a rule.
|
|
199
|
+
|
|
200
|
+
**`gate` refuses the port.** Each failed check prints its `fix`: run that first.
|
|
201
|
+
|
|
202
|
+
| Check | What to do |
|
|
203
|
+
|---|---|
|
|
204
|
+
| recording untouched | `cases.jsonl` was edited. `record` again; never edit it by hand |
|
|
205
|
+
| recording fresh | The original changed. `record` again, then `diff`; new mismatches are the upstream change |
|
|
206
|
+
| no stubs / no debugging | Remove `NotImplementedError`, `TODO`, `FIXME`, `binding.irb`, `debugger` |
|
|
207
|
+
| computes its results | Recorded answers are written into the port. Compute them; a lookup table of cases is not a port |
|
|
208
|
+
| error paths recorded | A `raise`/`throw` in the original has no case. Add inputs that reach it with `record --inputs` |
|
|
209
|
+
| tests kept | Tests or assertions went down. Restore them; never weaken a test |
|
|
210
|
+
| size | Over 3x the original's lines plus 50. Fold repeated code with Ruby and ActiveSupport idioms |
|
|
211
|
+
| rubocop | `bundle exec rubocop -a` on the file, then fix what remains by hand |
|
|
212
|
+
| cases match | Go back to `diff` |
|
|
213
|
+
|
|
214
|
+
**A step fails before it starts** ("is not installed", command not found): run
|
|
215
|
+
`ruby-anything doctor` and give the user its fix line. Do not install runtimes without asking.
|
|
216
|
+
|
|
217
|
+
**`app replay` is red**: `app replay <repo> --case <name>` for one case, fix the Rails side, rerun
|
|
218
|
+
that case, then the full replay. If `--original` is red too, the recording is flaky (see above),
|
|
219
|
+
not the port.
|
package/src/adapters.js
CHANGED
|
@@ -1,60 +1,63 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
// Runs
|
|
3
|
-
// Recording EXECUTES the original: work on a copy, with a test database.
|
|
4
|
-
const fs = require('node:fs')
|
|
5
|
-
const path = require('node:path')
|
|
6
|
-
const { PKG, python, which, runHarness, canon } = require('./util')
|
|
7
|
-
|
|
8
|
-
const POLYGLOT = { go: 'go', java: 'javac', kotlin: 'kotlinc', csharp: 'dotnet', php: 'php', rust: 'rustc', swift: 'swiftc', ruby: 'ruby' }
|
|
9
|
-
|
|
10
|
-
function adaptersDir() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return { argv: [
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
// Runs PortPilot's language adapters (the recorders) on the original code.
|
|
3
|
+
// Recording EXECUTES the original: work on a copy, with a test database.
|
|
4
|
+
const fs = require('node:fs')
|
|
5
|
+
const path = require('node:path')
|
|
6
|
+
const { PKG, python, which, runHarness, canon } = require('./util')
|
|
7
|
+
|
|
8
|
+
const POLYGLOT = { go: 'go', java: 'javac', kotlin: 'kotlinc', csharp: 'dotnet', php: 'php', rust: 'rustc', swift: 'swiftc', ruby: 'ruby' }
|
|
9
|
+
|
|
10
|
+
function adaptersDir() {
|
|
11
|
+
// Inside the PortPilot repo the live adapters win over a copy left by `npm pack`.
|
|
12
|
+
const dev = path.resolve(PKG, '..', '..', 'adapters')
|
|
13
|
+
if (fs.existsSync(path.join(dev, 'polyglot', 'harness.py'))) return dev
|
|
14
|
+
const bundled = path.join(PKG, 'adapters')
|
|
15
|
+
if (fs.existsSync(path.join(bundled, 'polyglot'))) return bundled
|
|
16
|
+
throw new Error('language adapters missing: reinstall ruby-anything')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// argv + env for a language's harness, or throws with what to install.
|
|
20
|
+
function harnessFor(lang) {
|
|
21
|
+
const dir = adaptersDir()
|
|
22
|
+
const py = python()
|
|
23
|
+
if (lang === 'python') {
|
|
24
|
+
if (!py) throw new Error('python 3 is required to record Python code')
|
|
25
|
+
return { argv: [py, '-X', 'utf8', '-I', '-B', path.join(dir, 'python', 'harness.py')], env: {} }
|
|
26
|
+
}
|
|
27
|
+
if (lang === 'javascript' || lang === 'typescript') {
|
|
28
|
+
return { argv: [process.execPath, '--enable-source-maps', path.join(dir, 'node', 'harness.mjs')], env: {} }
|
|
29
|
+
}
|
|
30
|
+
if (POLYGLOT[lang]) {
|
|
31
|
+
if (!py) throw new Error(`python 3 is required to drive the ${lang} recorder`)
|
|
32
|
+
if (!which(POLYGLOT[lang])) throw new Error(`${POLYGLOT[lang]} is not installed (needed to record ${lang}); run ruby-anything doctor`)
|
|
33
|
+
return { argv: [py, '-X', 'utf8', '-B', path.join(dir, 'polyglot', 'harness.py')], env: { PORTPILOT_LANGUAGE: lang } }
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`no recorder for ${lang}`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function supported(lang) {
|
|
39
|
+
return lang === 'python' || lang === 'javascript' || lang === 'typescript' || !!POLYGLOT[lang]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function analyzeUnits(root, lang) {
|
|
43
|
+
const h = harnessFor(lang)
|
|
44
|
+
const { events } = await runHarness(h.argv, { command: 'analyze' }, { env: { ...h.env, PORTPILOT_SRC: root }, cwd: root })
|
|
45
|
+
return {
|
|
46
|
+
files: events.filter((e) => e.event === 'file'),
|
|
47
|
+
units: events.filter((e) => e.event === 'unit'),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function record(root, lang, { moduleFile, fn, cases = [], count = 40, seed = 1, mode = 'edge', pinClock = false, onEvent }) {
|
|
52
|
+
const h = harnessFor(lang)
|
|
53
|
+
const req = { command: 'record', module_file: moduleFile, function: fn, cases: '__CASES__', generate: count ? { count, seed, mode } : null, pin_clock: !!pinClock }
|
|
54
|
+
// cases keep their int/float kinds ({ $n } values) on the way in
|
|
55
|
+
const raw = JSON.stringify(req).replace('"__CASES__"', canon(cases))
|
|
56
|
+
const { events } = await runHarness(h.argv, raw, { env: { ...h.env, PORTPILOT_SRC: root }, cwd: root, onEvent })
|
|
57
|
+
return {
|
|
58
|
+
runtime: events.find((e) => e.event === 'plan')?.runtime,
|
|
59
|
+
cases: events.filter((e) => e.event === 'case'),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { adaptersDir, harnessFor, supported, analyzeUnits, record }
|
package/src/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ Start
|
|
|
6
6
|
setup [--remove] install the agent skill and register the MCP server
|
|
7
7
|
doctor check Ruby, Rails and the runtimes the original needs
|
|
8
8
|
go [-- <start command>] move the migration to its next stage; writes rails/port/TASK.md
|
|
9
|
+
status [<repo>] [--json] where the migration stopped (read-only; start of a new session)
|
|
9
10
|
|
|
10
11
|
Plan
|
|
11
12
|
analyze <repo> [--json] [-o f] languages, routes, templates, functions in waves, decisions
|
|
@@ -52,6 +53,8 @@ async function main(argv) {
|
|
|
52
53
|
return require('./setup').cmdDoctor(rest)
|
|
53
54
|
case 'analyze':
|
|
54
55
|
return require('./analyze').cmdAnalyze(rest)
|
|
56
|
+
case 'status':
|
|
57
|
+
return require('./status').cmdStatus(rest)
|
|
55
58
|
case 'go':
|
|
56
59
|
return require('./go').cmdGo(rest)
|
|
57
60
|
case 'bridge':
|
package/src/mcp.js
CHANGED
|
@@ -11,6 +11,7 @@ const flags = { type: 'array', items: { type: 'string' }, description: 'Extra CL
|
|
|
11
11
|
|
|
12
12
|
const TOOLS = [
|
|
13
13
|
['go', 'Move the whole-app migration to its next stage and write rails/port/TASK.md. Pass the command that starts the original app.', { repo, command: { type: 'array', items: { type: 'string' }, description: 'Command that starts the original (reads PORT or uses {port})' }, flags }, (a) => ['go', ...(a.repo ? ['--repo', a.repo] : []), ...(a.flags || []), ...(a.command?.length ? ['--', ...a.command] : [])]],
|
|
14
|
+
['status', 'Where the migration stopped: stage, next step, current TASK.md, open units, fallback rate and the files to read first. Read-only; call it first in a new session.', { repo }, (a) => ['status', a.repo || '.', '--json']],
|
|
14
15
|
['analyze', 'Plan the migration: languages, frameworks, routes, templates, functions in waves, dependencies with Rails equivalents, and the decisions to settle with the user.', { repo, flags }, (a) => ['analyze', a.repo || '.', '--json', ...(a.flags || [])]],
|
|
15
16
|
['bridge', 'Create the Ruby skeleton for one unit (app/services) and its TASK.md.', { repo, unit, flags }, (a) => ['bridge', a.repo || '.', a.unit, ...(a.flags || [])]],
|
|
16
17
|
['record', "Run the original unit on generated edge cases (plus --inputs) and save its behavior to rails/port/cases.", { repo, unit, flags }, (a) => ['record', a.repo || '.', a.unit, ...(a.flags || [])]],
|
|
@@ -59,7 +60,7 @@ async function cmdMcp() {
|
|
|
59
60
|
async function handle(msg) {
|
|
60
61
|
const { id, method, params } = msg
|
|
61
62
|
if (method === 'initialize') {
|
|
62
|
-
return { jsonrpc: '2.0', id, result: { protocolVersion: params?.protocolVersion || '2024-11-05', capabilities: { tools: {}, prompts: {} }, serverInfo: { name: 'ruby-anything', version: require('../package.json').version }, instructions: 'Migrate an app to Ruby on Rails (Hotwire, Tailwind, daisyUI) one piece at a time, checked against the original. Load the ruby-anything skill
|
|
63
|
+
return { jsonrpc: '2.0', id, result: { protocolVersion: params?.protocolVersion || '2024-11-05', capabilities: { tools: {}, prompts: {} }, serverInfo: { name: 'ruby-anything', version: require('../package.json').version }, instructions: 'Migrate an app to Ruby on Rails (Hotwire, Tailwind, daisyUI) one piece at a time, checked against the original. Load the ruby-anything skill. In a new session call the status tool first to see where the migration stopped; otherwise start with the go tool.' } }
|
|
63
64
|
}
|
|
64
65
|
if (method === 'notifications/initialized' || id === undefined) return null
|
|
65
66
|
if (method === 'ping') return { jsonrpc: '2.0', id, result: {} }
|
package/src/setup.js
CHANGED
|
@@ -12,9 +12,28 @@ const SKILL_DIRS = [
|
|
|
12
12
|
['Claude Code', path.join(HOME, '.claude', 'skills', 'ruby-anything'), path.join(HOME, '.claude')],
|
|
13
13
|
['Codex', path.join(HOME, '.codex', 'skills', 'ruby-anything'), path.join(HOME, '.codex')],
|
|
14
14
|
['OpenCode', path.join(HOME, '.config', 'opencode', 'skills', 'ruby-anything'), path.join(HOME, '.config', 'opencode')],
|
|
15
|
+
['GitHub Copilot', path.join(HOME, '.copilot', 'skills', 'ruby-anything'), path.join(HOME, '.copilot')],
|
|
15
16
|
]
|
|
16
17
|
const MCP_ENTRY = { command: 'ruby-anything', args: ['mcp'] }
|
|
17
18
|
|
|
19
|
+
// VS Code keeps its user settings (and extensions' global storage) in a per-OS folder.
|
|
20
|
+
const VSCODE_USER = process.platform === 'win32'
|
|
21
|
+
? path.join(process.env.APPDATA || path.join(HOME, 'AppData', 'Roaming'), 'Code', 'User')
|
|
22
|
+
: process.platform === 'darwin'
|
|
23
|
+
? path.join(HOME, 'Library', 'Application Support', 'Code', 'User')
|
|
24
|
+
: path.join(HOME, '.config', 'Code', 'User')
|
|
25
|
+
|
|
26
|
+
// Agents configured through a JSON file: [agent, config file, folder that shows the agent is
|
|
27
|
+
// installed, key holding the servers, entry]. A file is only written when that folder exists.
|
|
28
|
+
const MCP_JSON = [
|
|
29
|
+
['Cursor', path.join(HOME, '.cursor', 'mcp.json'), path.join(HOME, '.cursor'), 'mcpServers', MCP_ENTRY],
|
|
30
|
+
['Gemini CLI', path.join(HOME, '.gemini', 'settings.json'), path.join(HOME, '.gemini'), 'mcpServers', MCP_ENTRY],
|
|
31
|
+
['Windsurf', path.join(HOME, '.codeium', 'windsurf', 'mcp_config.json'), path.join(HOME, '.codeium', 'windsurf'), 'mcpServers', MCP_ENTRY],
|
|
32
|
+
['GitHub Copilot CLI', path.join(HOME, '.copilot', 'mcp-config.json'), path.join(HOME, '.copilot'), 'mcpServers', { type: 'local', ...MCP_ENTRY, tools: ['*'] }],
|
|
33
|
+
['GitHub Copilot in VS Code', path.join(VSCODE_USER, 'mcp.json'), VSCODE_USER, 'servers', { type: 'stdio', ...MCP_ENTRY }],
|
|
34
|
+
['Cline', path.join(VSCODE_USER, 'globalStorage', 'saoudrizwan.claude-dev', 'settings', 'cline_mcp_settings.json'), path.join(VSCODE_USER, 'globalStorage', 'saoudrizwan.claude-dev'), 'mcpServers', { ...MCP_ENTRY, disabled: false }],
|
|
35
|
+
]
|
|
36
|
+
|
|
18
37
|
function setupSkills(remove) {
|
|
19
38
|
for (const [agent, dir, home] of SKILL_DIRS) {
|
|
20
39
|
if (!fs.existsSync(home)) continue
|
|
@@ -25,7 +44,7 @@ function setupSkills(remove) {
|
|
|
25
44
|
}
|
|
26
45
|
|
|
27
46
|
function setupMcp(remove) {
|
|
28
|
-
// Claude Code and Codex through their own CLIs;
|
|
47
|
+
// Claude Code and Codex through their own CLIs; the others through their JSON configs (MCP_JSON).
|
|
29
48
|
if (which('claude')) {
|
|
30
49
|
runSync('claude', ['mcp', 'remove', '--scope', 'user', 'ruby-anything'])
|
|
31
50
|
if (!remove) {
|
|
@@ -40,12 +59,18 @@ function setupMcp(remove) {
|
|
|
40
59
|
console.log(r.code === 0 ? 'registered MCP server with Codex' : yellow(`Codex: ${r.stderr.trim()}`))
|
|
41
60
|
}
|
|
42
61
|
}
|
|
43
|
-
for (const [agent, file
|
|
44
|
-
if (!fs.existsSync(
|
|
45
|
-
|
|
46
|
-
cfg
|
|
47
|
-
if (
|
|
48
|
-
|
|
62
|
+
for (const [agent, file, home, key, entry] of MCP_JSON) {
|
|
63
|
+
if (!fs.existsSync(home)) continue
|
|
64
|
+
// Never overwrite a config we cannot parse (VS Code allows comments in mcp.json).
|
|
65
|
+
const cfg = fs.existsSync(file) ? readJSON(file, null) : {}
|
|
66
|
+
if (!cfg || typeof cfg !== 'object') {
|
|
67
|
+
console.log(yellow(`${agent}: could not parse ${file}; add "ruby-anything": ${JSON.stringify(entry)} under "${key}" yourself`))
|
|
68
|
+
continue
|
|
69
|
+
}
|
|
70
|
+
if (remove && !cfg[key]?.['ruby-anything']) continue
|
|
71
|
+
cfg[key] = cfg[key] || {}
|
|
72
|
+
if (remove) delete cfg[key]['ruby-anything']
|
|
73
|
+
else cfg[key]['ruby-anything'] = entry
|
|
49
74
|
writeJSON(file, cfg)
|
|
50
75
|
console.log(`${remove ? 'removed MCP server from' : 'registered MCP server with'} ${agent}: ${file}`)
|
|
51
76
|
}
|
package/src/status.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
// status: where the migration stands, for an agent starting a new session. Reads only; writes
|
|
3
|
+
// nothing and runs nothing (unlike `go`, which records, replays and moves to the next stage).
|
|
4
|
+
const fs = require('node:fs')
|
|
5
|
+
const path = require('node:path')
|
|
6
|
+
const { layout, loadState, readJSON, parseArgs, relTo, bold, dim, green, yellow } = require('./util')
|
|
7
|
+
const app = require('./app')
|
|
8
|
+
|
|
9
|
+
const read = (f) => (fs.existsSync(f) ? fs.readFileSync(f, 'utf8') : '')
|
|
10
|
+
|
|
11
|
+
function migrationStatus(L) {
|
|
12
|
+
const st = loadState(L)
|
|
13
|
+
const plan = readJSON(L.planJson, null)
|
|
14
|
+
const adrs = (read(L.decisions).match(/^## ADR-\d+/gm) || []).length
|
|
15
|
+
const rules = read(L.rules).split('\n').filter((l) => l.startsWith('- ')).length
|
|
16
|
+
const units = Object.entries(st.units || {}).map(([id, u]) => ({
|
|
17
|
+
id,
|
|
18
|
+
status: u.status,
|
|
19
|
+
port_file: u.port_file,
|
|
20
|
+
last_diff: u.last_diff ? `${u.last_diff.matched}/${u.last_diff.total}` : null,
|
|
21
|
+
}))
|
|
22
|
+
const cases = app.loadCases(L)
|
|
23
|
+
const lifted = cases.length > 0 && app.isLifted(L)
|
|
24
|
+
const fr = cases.length ? app.fallbackRate(L, cases) : null
|
|
25
|
+
const frontDoor = fs.existsSync(path.join(L.rails, 'config', 'ruby_anything.yml')) || fs.existsSync(path.join(L.rails, 'lib', 'ruby_anything', 'front_door.rb'))
|
|
26
|
+
const taskText = read(L.task)
|
|
27
|
+
const task = taskText ? { file: relTo(L.root, L.task), next: (taskText.match(/^# Next: (.+)$/m) || [])[1] || taskText.split('\n')[0] } : null
|
|
28
|
+
const open = units.filter((u) => u.status !== 'done')
|
|
29
|
+
|
|
30
|
+
let stage
|
|
31
|
+
let next
|
|
32
|
+
if (!plan) [stage, next] = ['not started', 'ruby-anything go']
|
|
33
|
+
else if (!adrs) [stage, next] = ['grill the user', 'settle the decisions in PLAN.md with the user, write them to DECISIONS.md as ## ADR-001: ..., then ruby-anything go']
|
|
34
|
+
else if (!cases.length && !units.length) [stage, next] = ['record the original', 'ruby-anything go -- <command that starts the original>']
|
|
35
|
+
else if (!cases.length) [stage, next] = ['port units', open.length ? `finish ${open[0].id}: diff until N/N, then gate` : 'bridge the next unit in plan.json']
|
|
36
|
+
else if (lifted) [stage, next] = ['lifted', 'nothing left; keep ruby-anything gate --app in CI']
|
|
37
|
+
else if (!frontDoor) [stage, next] = ['build the front door', 'ruby-anything go']
|
|
38
|
+
else if (fr.fallback > 0) [stage, next] = ['port routes', 'ruby-anything go (replays, then writes the next route to TASK.md)']
|
|
39
|
+
else [stage, next] = ['gate and lift', 'ruby-anything gate --app, then ask the user before ruby-anything app lift']
|
|
40
|
+
|
|
41
|
+
const files = [L.task, L.rules, L.decisions, L.map, L.handoff, L.glossary].filter((f) => fs.existsSync(f)).map((f) => relTo(L.root, f))
|
|
42
|
+
return {
|
|
43
|
+
repo: L.root,
|
|
44
|
+
stage,
|
|
45
|
+
next,
|
|
46
|
+
task,
|
|
47
|
+
decisions: adrs,
|
|
48
|
+
rules,
|
|
49
|
+
units: { total: plan ? (plan.units || []).length : 0, bridged: units.length, done: units.length - open.length, open },
|
|
50
|
+
app: cases.length ? { cases: cases.length, fallback: fr.fallback, front_door: frontDoor, lifted, last_replay: st.app?.last_replay || null } : null,
|
|
51
|
+
read_first: files,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function cmdStatus(argv) {
|
|
56
|
+
const a = parseArgs(argv, ['json'])
|
|
57
|
+
const L = layout(a.repo || a._[0] || '.')
|
|
58
|
+
const s = migrationStatus(L)
|
|
59
|
+
if (a.json) {
|
|
60
|
+
process.stdout.write(JSON.stringify(s, null, 2) + '\n')
|
|
61
|
+
return 0
|
|
62
|
+
}
|
|
63
|
+
console.log(`${bold('stage')}: ${s.stage}`)
|
|
64
|
+
console.log(`${bold('next')}: ${s.next}`)
|
|
65
|
+
if (s.task) console.log(`${bold('task')}: ${s.task.next} ${dim(`(${s.task.file})`)}`)
|
|
66
|
+
console.log(`decisions ${s.decisions} ADRs, rules ${s.rules}`)
|
|
67
|
+
if (s.units.total || s.units.bridged) console.log(`units ${s.units.done} done of ${s.units.bridged} bridged (${s.units.total} in plan)`)
|
|
68
|
+
for (const u of s.units.open.slice(0, 10)) console.log(` ${yellow(u.status.padEnd(11))} ${u.id}${u.last_diff ? dim(` last diff ${u.last_diff}`) : ''}`)
|
|
69
|
+
if (s.app) {
|
|
70
|
+
const r = s.app.last_replay
|
|
71
|
+
console.log(`app ${s.app.cases} cases, fallback ${s.app.fallback}/${s.app.cases}${r ? `, last replay ${r.matched}/${r.total} (${r.at.slice(0, 10)})` : ', never replayed'}${s.app.lifted ? green(', lifted') : ''}`)
|
|
72
|
+
}
|
|
73
|
+
if (s.read_first.length) console.log(`read first: ${s.read_first.join(', ')}`)
|
|
74
|
+
return 0
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { cmdStatus, migrationStatus }
|