Skip to content

Day 3a: Rails worker — real substrate copy + Ruby AST rename#6

Merged
dadachi merged 1 commit intomainfrom
feat/day3a-rails-worker
Apr 21, 2026
Merged

Day 3a: Rails worker — real substrate copy + Ruby AST rename#6
dadachi merged 1 commit intomainfrom
feat/day3a-rails-worker

Conversation

@dadachi
Copy link
Copy Markdown
Contributor

@dadachi dadachi commented Apr 21, 2026

Summary

  • src/agents/workers/rails.ts — real implementation: copy \$NATEMPLATE_API./out/<slug>/rails (filtered: no .git, node_modules, tmp, log, vendor/bundle, sockets/FIFOs), invoke rename.rb, run git init -q -b main. Stub path preserved behind isStub("rails").
  • scripts/ruby/rename.rb — takes {renamePlan, root} on stdin, rewrites file contents AND renames paths (deepest-first) for PascalCase / snake_case / plural / SCREAMING variants.
  • src/ruby.ts — thin execFile wrapper per CLAUDE.md convention; JSON on stdin/stdout, propagates non-zero exit codes with stderr tail.

Tricky bit worth flagging

Ruby's \b treats _ as a word char, so \bshops\b silently fails to match inside shops_controller or accounts_shopkeeper. First attempt left 10+ files unrenamed. Fix: letter-aware boundary (?<![A-Za-z])...(?![A-Za-z]) — treats _, ., digits, punctuation as boundaries; only letters block a match. After the fix, 2220 substitutions vs 1334 before.

Verified against clinic-queue (stub planner for determinism)

Metric Value
Files scanned 305
Files changed (content) 125
Substitutions 2,220
File/dir renames 49
Leftover Shop/Shopkeeper tokens 0 (grep returned empty)
ruby -c on renamed models Syntax OK across spot-checks
Migration filename + class-name coherence Confirmed (e.g. change_vet_foreign_keys_to_nullify_on_delete.rb / class ChangeVetForeignKeysToNullifyOnDelete)
config/routes.rb clean — resources :clinics, namespace :vet_auth, accounts_vets

What this doesn't do (deferred)

  • Actual bin/dev boot verification — that's Layer 2 (Day 5 morning).
  • acts_as_tenant / devise_token_auth deeper semantic edits — rename is complete; any missing wiring surfaces when Day 5 Layer 2 boots the server.
  • Migration table-name validation — we rename class + filename, but DB table rename (if any) would need explicit AST work. Not needed for the hackathon specs.

Test plan

  • npm run ci — green (stub path still used in tests under NATEMPLATE_STUB_ALL=1)
  • NATEMPLATE_STUB_PLANNER=1 npm run dev -- "a walk-in clinic queue..." — real copy + rename runs, no errors
  • Spot check: grep -rln '\\bshop\\|\\bshopkeeper\\|shops_\\|shopkeepers_' out/clinic-queue/rails returns empty
  • Spot check: ruby -c on 3 renamed model files — all Syntax OK
  • Full bin/dev boot — deferred to Day 5 Layer 2 validation

- scripts/ruby/rename.rb: takes a rename plan + root on stdin, rewrites
  file contents AND renames files/dirs for PascalCase / snake_case /
  plural / SCREAMING variants. Uses a letter-aware boundary
  `(?<![A-Za-z])...(?![A-Za-z])` instead of \\b because Ruby treats `_`
  as a word char and \\b misses inside snake_case.
- src/ruby.ts: thin execFile wrapper per CLAUDE.md convention; JSON on
  stdin/stdout, propagates non-zero exit codes with stderr tail.
- src/agents/workers/rails.ts: substrate -> ./out/<slug>/rails via
  fs.cp with recursive filter (skips .git, node_modules, tmp, log,
  vendor/bundle, sockets/FIFOs); invokes rename.rb; runs
  `git init -q -b main` on the result. isStub("rails") gates the
  existing stub path for CI.

Verified against walk-in clinic queue spec (stub planner for
determinism): 305 files scanned, 125 changed, 2220 substitutions,
49 file/dir renames. ruby -c confirms syntax validity on renamed
models; routes.rb, migrations, controllers, policies, serializers
all rename coherently. No leftover Shop/Shopkeeper tokens.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dadachi dadachi merged commit b590abe into main Apr 21, 2026
1 check passed
@dadachi dadachi deleted the feat/day3a-rails-worker branch April 21, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant