Commit 5f6e66d
Add react_on_rails:install_rsc_agent_guardrails: ship RSC agent-safety skill + hook into apps (#4606)
## What
Ships an installable **RSC "agent safety" guardrail** for apps that use
React on Rails Pro React Server Components. A new rake task (and the RSC
generator) drops a Claude Code skill + an advisory hook into the host
app's `.claude/`, so AI coding agents working in that app are steered
away from the RSC API footguns surfaced in the recent RSC security
audit.
This is the downstream half of a two-PR effort. The framework-internals
half (a repo-local `rsc-guardrails` skill + payload-escaping regression
test) is #4599.
## Why
RSC spans a trusted-server → untrusted-client boundary. The audit
(issues #4595, #4596, #4597) found the framework solid but identified
**usage** footguns an app can hit: mounting `rsc_payload_route` without
authentication, trusting server-component props, exposing the Node
renderer, or leaking secrets/PII. Those live in app code, not the gem —
so the guardrail has to ship *into the app*.
## Changes
- **`react_on_rails:install_rsc_agent_guardrails` rake task** —
idempotently installs/updates the guardrail assets into the current
app's `.claude/`. Safe to re-run after upgrades.
- **`ReactOnRails::AgentGuardrails` installer** — copies the skill +
hook and registers the hook in `.claude/settings.json` via a **safe JSON
merge** (preserves existing hooks; refuses to touch malformed JSON and
tells you to add the one line manually).
- **`rsc-app-safety` skill template** — the RSC usage footguns + a
per-change checklist, installed as
`.claude/skills/rsc-app-safety/SKILL.md`.
- **App advisory hook template** — a non-blocking `PostToolUse` warning
when `config/routes.rb` mounts `rsc_payload_route`, or an RSC controller
lacks a visible `before_action`. Installed as
`.claude/hooks/rsc-app-safety-check.sh`.
- **RSC generator wiring** — `rails g react_on_rails:rsc` now runs the
installer, so new RSC apps get the guardrails automatically.
## Verification
- New rspec `agent_guardrails_spec.rb`: **4/4 pass** — fresh install,
idempotency, safe merge into an existing `settings.json`, and
raise-not-clobber on malformed JSON.
- `rsc_generator_spec.rb`: passes with the generator wiring.
- Rake task exercised end-to-end into a temp app (create → idempotent
re-run).
- App hook dry-run: warns on unauthenticated `rsc_payload_route` / RSC
controller; silent otherwise. `shellcheck` clean; matching anchored on
the absolute path (robust to symlinked/`/var` checkouts).
- `rubocop` clean; `prettier --check` clean.
## Deliberately deferred (fast-follow)
A dedicated docs page — the `rsc-app-safety` skill and the rake task
`desc` are self-documenting for now; a docs/ page would pull in the
llms-full regeneration gate. Happy to add it in a follow-up if you want
it in the docs site.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added RSC agent guardrails that install a Claude Code “rsc-app-safety”
skill and a safety advisory hook.
* Added `react_on_rails:install_rsc_agent_guardrails` to install/update
the guardrails into the app’s `.claude/` directory.
* RSC generation now automatically installs these guardrails when Pro is
enabled, including payload auth guidance based on routes/controllers.
* **Bug Fixes**
* Guardrails installation is idempotent, preserves unrelated settings,
supports “skip existing”, and removes any legacy hook script.
* Install failures degrade gracefully during generation, while the rake
task reports permission issues cleanly and exits with status `1`.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent a043473 commit 5f6e66d
8 files changed
Lines changed: 1497 additions & 0 deletions
File tree
- react_on_rails
- lib
- generators/react_on_rails
- react_on_rails
- agent_guardrails/templates
- tasks
- spec/react_on_rails
- generators
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
216 | 225 | | |
217 | 226 | | |
218 | 227 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| |||
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
123 | 140 | | |
124 | 141 | | |
125 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 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 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
0 commit comments