ruby-anything 0.1.0 → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ruby-anything",
3
- "owner": { "name": "PortPilot" },
3
+ "owner": { "name": "akkisavi" },
4
4
  "description": "ruby-anything: migrate any app to Ruby on Rails one piece at a time, and prove it still behaves the same.",
5
5
  "plugins": [
6
6
  {
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "ruby-anything",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Migrate any app to Ruby on Rails 8 with Hotwire, Tailwind and daisyUI, one piece at a time, checked against the original's recorded behavior at every step. Needs the ruby-anything CLI on PATH (npm i -g ruby-anything).",
5
5
  "license": "MIT",
6
- "keywords": ["ruby", "rails", "hotwire", "daisyui", "migration", "mcp"]
6
+ "keywords": [
7
+ "ruby",
8
+ "rails",
9
+ "hotwire",
10
+ "daisyui",
11
+ "migration",
12
+ "mcp"
13
+ ]
7
14
  }
package/README.md CHANGED
@@ -15,6 +15,10 @@ Rails 8 · Hotwire (Turbo + Stimulus) · Tailwind CSS · daisyUI<br>
15
15
  from TypeScript, JavaScript, Python, Go, Java/Spring Boot, Kotlin, C#, PHP, Rust and Swift
16
16
  </p>
17
17
 
18
+ <p align="center">
19
+ Inspired by <a href="https://github.com/erkamyaman/rust-anything">rust-anything</a> by <a href="https://github.com/erkamyaman">erkamyaman</a> 🦀 ➜ 💎
20
+ </p>
21
+
18
22
  ## Quick start
19
23
 
20
24
  Paste this into your coding agent:
@@ -45,8 +49,16 @@ ruby-anything doctor # checks Ruby, Rails and the runtimes your origina
45
49
 
46
50
  **What counts as done.** Behavior, not your tests. `record` runs the original on generated and given inputs and saves what each call returns, raises and prints; `app record` saves what each HTTP request answers (status, redirects, JSON, page text), running every request twice so changing values become wildcards. A piece is done when `gate` passes: every recorded case matches, and the checks for edited recordings, stubs, recorded answers pasted into the port, unrecorded error paths, fewer tests than before, rubocop and brakeman all pass. Your own `bin/rails test` runs too.
47
51
 
52
+ **Your tests become cases.** `record --from-tests -- pytest` (or `npx jest`, `node --test`) runs the original's own suite with the function instrumented, and every call it makes becomes a recorded case. The source is restored byte for byte afterwards. `--pin-clock` freezes time at 2026-01-01 for the original and the Ruby port alike, so date-dependent code can match.
53
+
54
+ **Side effects count.** A port that forgets to charge the card or send the receipt must fail. `app record --effect-env PAYMENT_API_URL=http,SMTP_HOST=smtp_host,SMTP_PORT=smtp_port --db-dump "<cmd>"` points the app at local stand-ins that record every outgoing HTTP call and email, and dumps the database after every write; replay checks the Rails app makes the same calls, sends the same mail and leaves the same rows.
55
+
56
+ **Web apps and CLI tools.** `app record --http` records a server; `app record --cli --inputs cli.jsonl` records a command-line tool (exit code, stdout, stderr, files written, stdin), each run in a throwaway copy of the repo. A CLI's front door is `rails/bin/<name>`: ported commands run in Rails, the rest exec the original.
57
+
48
58
  **The app keeps running.** `app front-door` runs `rails new` with Tailwind and importmap, adds daisyUI, and puts a small Rack middleware in front that proxies every route Rails does not own yet to the original. Routes move over one at a time with `app wire`, each with a kill switch (`RUBY_ANYTHING_UNIT_<NAME>=original`). `app replay` must stay at 100% while the fallback rate drops to zero; then `app lift` removes the proxy.
49
59
 
60
+ **The original keeps changing?** `ruby-anything drift` re-runs the original on every recorded case and lists what now answers differently, plus routes no case records. CI runs the tests on Linux, Windows and macOS, and the bundled GitHub Action runs `gate` on every pull request.
61
+
50
62
  **A new frontend, the same pages.** Pages are rebuilt as ERB views with Turbo Frames and Streams, Stimulus controllers and daisyUI components. Replay compares them by visible text, so the markup is new but every heading, label, price and empty state must still be there. JSON responses must match exactly.
51
63
 
52
64
  **Report or migrate, you pick.** `analyze` only reports: languages, frameworks, routes, templates and functions in waves (models, logic, routes, views, jobs), every dependency with its Rails equivalent, and the decisions to settle with you. It is a plain command, so the report costs no tokens. `go` migrates: each run moves to the next stage and writes the next task to `rails/port/TASK.md` for your agent.
@@ -64,20 +76,40 @@ Everything it writes lives in `<repo>/rails/`: the Rails app, and `rails/port/`
64
76
  | `ruby-anything go [-- <start command>]` | Move the migration to its next stage and write `rails/port/TASK.md` |
65
77
  | `ruby-anything analyze <repo>` | Plan: routes, templates, functions in waves, dependencies, decisions |
66
78
  | `ruby-anything bridge <repo> <unit>` | Ruby skeleton for one function in `app/services` |
67
- | `ruby-anything record <repo> <unit>` | Record the original function on edge cases and `--inputs` |
79
+ | `ruby-anything record <repo> <unit>` | Record the original function on edge cases, `--inputs`, `--from-tests -- <test cmd>`, `--pin-clock` |
68
80
  | `ruby-anything diff <repo> <unit>` | Replay the cases against the Ruby port (must be N/N) |
69
81
  | `ruby-anything gate <repo> <unit> \| --all \| --app` | Done means gate passes |
70
82
  | `ruby-anything rules <repo> [--add "<rule>"]` | Behavior you corrected, kept by every later piece |
71
- | `ruby-anything app record <repo> --http -- <start command>` | Record the whole original over HTTP |
83
+ | `ruby-anything drift <repo>` | Has the original changed since it was recorded? |
84
+ | `ruby-anything app record <repo> --http -- <start command>` | Record the whole original over HTTP (`--effect-env`, `--db-dump` for side effects) |
85
+ | `ruby-anything app record <repo> --cli --inputs cli.jsonl -- <command>` | Record a CLI tool |
72
86
  | `ruby-anything app front-door <repo>` | Rails app that proxies routes not ported yet |
73
- | `ruby-anything app wire <repo> <unit> --route "GET /path/:id"` | Hand a route to Rails |
87
+ | `ruby-anything app wire <repo> <unit> --route "GET /path/:id"` | Hand a route to Rails (`--command <name>` for a CLI) |
74
88
  | `ruby-anything app replay <repo>` | Replay every HTTP case through Rails (`--original`, `--case`) |
75
89
  | `ruby-anything app status <repo>` | Fallback rate, wired routes, units done |
76
90
  | `ruby-anything app lift <repo>` | Remove the proxy once nothing falls back |
77
91
  | `ruby-anything setup \| doctor \| mcp` | Install for agents, check runtimes, MCP server |
78
92
 
93
+ ## In CI
94
+
95
+ ```yaml
96
+ - uses: akkisavi/ruby-anything/packages/ruby-anything@master
97
+ with:
98
+ app: "true" # also bin/rails test, rubocop, brakeman and the full replay
99
+ ```
100
+
101
+ ## Inspiration and credits
102
+
103
+ Ruby Anything is inspired by **[rust-anything](https://github.com/erkamyaman/rust-anything)** by
104
+ **[erkamyaman](https://github.com/erkamyaman)**, which migrates apps to Rust the same way. The
105
+ core ideas come from it: the original's recorded behavior is the spec, a `gate` that refuses
106
+ shortcuts, one piece at a time behind a front door, a `go` command and an agent skill that guides
107
+ the work. Ruby Anything applies them to Ruby on Rails with Hotwire, Tailwind and daisyUI.
108
+ If you're moving code to Rust, use rust-anything, and give it a ⭐.
109
+
110
+ The recorders are PortPilot's language adapters.
111
+
79
112
  ## License
80
113
 
81
114
  Licensed under [MIT](./LICENSE). Ports and generated code in your repository are yours.
82
115
 
83
- Inspired by [rust-anything](https://github.com/erkamyaman/rust-anything) by Erkam Yaman, which does the same for Rust. The recorders are PortPilot's language adapters.
package/action.yml ADDED
@@ -0,0 +1,56 @@
1
+ name: ruby-anything gate
2
+ description: Fail the pull request unless every ruby-anything port still matches the original's recorded behavior.
3
+ branding:
4
+ icon: check-circle
5
+ color: red
6
+
7
+ inputs:
8
+ path:
9
+ description: Repository being migrated (the folder that contains rails/).
10
+ default: "."
11
+ units:
12
+ description: Unit ids to gate, one per line. Empty gates every bridged unit (gate --all).
13
+ default: ""
14
+ app:
15
+ description: Also run the whole-app gate (bin/rails test, rubocop, brakeman, HTTP replay).
16
+ default: "false"
17
+ version:
18
+ description: ruby-anything version from npm.
19
+ default: latest
20
+ no-lint:
21
+ description: Skip rubocop in the unit gate.
22
+ default: "false"
23
+
24
+ runs:
25
+ using: composite
26
+ steps:
27
+ - name: Install ruby-anything
28
+ shell: bash
29
+ run: npm install -g "ruby-anything@${{ inputs.version }}"
30
+ - name: Check runtimes
31
+ shell: bash
32
+ run: ruby-anything doctor || true
33
+ - name: Gate units
34
+ shell: bash
35
+ working-directory: ${{ inputs.path }}
36
+ env:
37
+ UNITS: ${{ inputs.units }}
38
+ NO_LINT: ${{ inputs.no-lint }}
39
+ run: |
40
+ flags=()
41
+ [ "$NO_LINT" = "true" ] && flags+=(--no-lint)
42
+ if [ -z "$UNITS" ]; then
43
+ ruby-anything gate . --all "${flags[@]}"
44
+ else
45
+ status=0
46
+ while IFS= read -r unit; do
47
+ [ -z "$unit" ] && continue
48
+ ruby-anything gate . "$unit" "${flags[@]}" || status=1
49
+ done <<< "$UNITS"
50
+ exit $status
51
+ fi
52
+ - name: Gate the app
53
+ if: inputs.app == 'true'
54
+ shell: bash
55
+ working-directory: ${{ inputs.path }}
56
+ run: ruby-anything gate . --app
@@ -11,6 +11,7 @@ import path from 'node:path';
11
11
  import os from 'node:os';
12
12
  import crypto from 'node:crypto';
13
13
  import { pathToFileURL } from 'node:url';
14
+ import { createRequire } from 'node:module';
14
15
 
15
16
  const SRC = process.env.PORTPILOT_SRC || '/work/src';
16
17
  const realWrite = process.stdout.write.bind(process.stdout);
@@ -71,7 +72,8 @@ let tsMirror = null;
71
72
  async function mirrorFor(file) {
72
73
  if (!/\.m?ts$/.test(file)) return file;
73
74
  if (!tsMirror) {
74
- const ts = (await import('./node_modules/typescript/lib/typescript.js')).default;
75
+ // Resolved like any dependency: this folder's node_modules in development, the package's when installed.
76
+ const ts = createRequire(import.meta.url)('typescript');
75
77
  tsMirror = fs.mkdtempSync(path.join(os.tmpdir(), 'pp-ts-'));
76
78
  fs.writeFileSync(path.join(tsMirror, 'package.json'), '{"type":"module"}');
77
79
  for (const src of walk(SRC)) {
@@ -285,7 +287,28 @@ async function target(req) {
285
287
  if (typeof fn !== 'function') { emit('fatal', { message: `${req.function} is not an exported function of ${req.module_file}` }); process.exit(2); }
286
288
  return { fn, file };
287
289
  }
290
+ // Opt-in (req.pin_clock): the clock reads 2026-01-01T00:00:00Z and Math.random restarts from seed 0
291
+ // before every run, so time- and random-dependent results are reproducible.
292
+ const PIN_MS = 1767225600000;
293
+ let rngState = 0;
294
+ function reseed() { rngState = 0; }
295
+ function pinClock() {
296
+ const RealDate = Date;
297
+ class PinnedDate extends RealDate {
298
+ constructor(...a) { if (a.length === 0) super(PIN_MS); else super(...a); }
299
+ static now() { return PIN_MS; }
300
+ }
301
+ globalThis.Date = PinnedDate;
302
+ Math.random = () => { // mulberry32
303
+ rngState = (rngState + 0x6D2B79F5) | 0;
304
+ let t = Math.imul(rngState ^ (rngState >>> 15), 1 | rngState);
305
+ t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
306
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
307
+ };
308
+ }
288
309
  async function record(req) {
310
+ const pinned = !!req.pin_clock;
311
+ if (pinned) pinClock();
289
312
  const { fn, file } = await target(req);
290
313
  const raw = fs.readFileSync(file, 'utf8'); const start = locate(raw, req.function, /ts$/.test(file));
291
314
  const params = paramsOf((start >= 0 ? sliceFunction(raw, start) : Function.prototype.toString.call(fn)).replace(/^\s*export\s+(default\s+)?/, '').replace(/^(async\s+)?function\s*\*?\s*[\w$]*/, ''));
@@ -296,7 +319,10 @@ async function record(req) {
296
319
  emit('plan', { total: cases.length, runtime: `node ${process.versions.node}` });
297
320
  const obs = r => JSON.stringify([r.outcome, r.stdout, r.stderr, r.effects]);
298
321
  for (const [index, c] of cases.entries()) {
299
- const first = await runCase(fn, file, c); const second = await runCase(fn, file, c);
322
+ if (pinned) reseed();
323
+ const first = await runCase(fn, file, c);
324
+ if (pinned) reseed();
325
+ const second = await runCase(fn, file, c);
300
326
  emit('case', { index, ref: c.ref ?? null, origin: c.origin || 'manual', args: c.args || [], kwargs: c.kwargs || {}, stable: obs(first) === obs(second), ...first });
301
327
  }
302
328
  emit('done');
@@ -1,26 +1,26 @@
1
- {
2
- "name": "portpilot-node-adapter",
3
- "lockfileVersion": 3,
4
- "requires": true,
5
- "packages": {
6
- "": {
7
- "name": "portpilot-node-adapter",
8
- "dependencies": {
9
- "typescript": "5.9.3"
10
- }
11
- },
12
- "node_modules/typescript": {
13
- "version": "5.9.3",
14
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
15
- "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
16
- "license": "Apache-2.0",
17
- "bin": {
18
- "tsc": "bin/tsc",
19
- "tsserver": "bin/tsserver"
20
- },
21
- "engines": {
22
- "node": ">=14.17"
23
- }
24
- }
25
- }
26
- }
1
+ {
2
+ "name": "portpilot-node-adapter",
3
+ "lockfileVersion": 3,
4
+ "requires": true,
5
+ "packages": {
6
+ "": {
7
+ "name": "portpilot-node-adapter",
8
+ "dependencies": {
9
+ "typescript": "5.9.3"
10
+ }
11
+ },
12
+ "node_modules/typescript": {
13
+ "version": "5.9.3",
14
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
15
+ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
16
+ "license": "Apache-2.0",
17
+ "bin": {
18
+ "tsc": "bin/tsc",
19
+ "tsserver": "bin/tsserver"
20
+ },
21
+ "engines": {
22
+ "node": ">=14.17"
23
+ }
24
+ }
25
+ }
26
+ }
@@ -1,7 +1,7 @@
1
- {
2
- "name": "portpilot-node-adapter",
3
- "private": true,
4
- "type": "module",
5
- "description": "Sandbox-side JS/TS adapter. TypeScript is transpiled with the official compiler before import.",
6
- "dependencies": { "typescript": "5.9.3" }
7
- }
1
+ {
2
+ "name": "portpilot-node-adapter",
3
+ "private": true,
4
+ "type": "module",
5
+ "description": "Sandbox-side JS/TS adapter. TypeScript is transpiled with the official compiler before import.",
6
+ "dependencies": { "typescript": "5.9.3" }
7
+ }