feat(scaffold): generate Cursor adapter from kit content at scaffold time#13
Conversation
…time Replace static templates/optional/cursor/ with generateCursorAdapter(), which composes .cursor/rules/, hooks.json, shell hook scripts, and commands/ from kit content/rules, content/skills, and hooks.manifest.json. Add canonical format-on-edit and shell-safety hooks. Assisted-by: Claude Code <noreply@anthropic.com> Signed-off-by: Vaclav Vancura <commit@vancura.dev>
|
Important Review skippedAuto reviews are limited based on label configuration. 🚫 Excluded labels (none allowed) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR adds Cursor adapter generation to the scaffolding pipeline, converting the kit's canonical hook manifest and content sources into Cursor-specific ChangesCursor Adapter Generation
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/create-blit-tech/test/scaffold.test.mjs (1)
221-227: 💤 Low valueConsider guarding array element access for clearer test failure messages.
Lines 226-227 access
beforeShellExecution[0]after only asserting the array exists. If the array were unexpectedly empty,safetyHookwould beundefinedandsafetyHook.failClosedwould throw a TypeError rather than a clean assertion failure. Same pattern applies toafterFileEdit[0]on line 230.Since the implementation should always produce entries, this is unlikely to bite in practice, but a length check yields more actionable failure output:
assert.ok( Array.isArray(hooksJson.hooks.beforeShellExecution), 'hooks.json should have beforeShellExecution entries', ); +assert.ok(hooksJson.hooks.beforeShellExecution.length > 0, 'beforeShellExecution should have at least one entry'); const safetyHook = hooksJson.hooks.beforeShellExecution[0];🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/create-blit-tech/test/scaffold.test.mjs` around lines 221 - 227, The test should guard array element access before indexing: after asserting Array.isArray for hooksJson.hooks.beforeShellExecution and hooksJson.hooks.afterFileEdit, add explicit non-empty checks (e.g. assert.ok(hooksJson.hooks.beforeShellExecution.length > 0, 'beforeShellExecution should contain at least one entry') and same for afterFileEdit) so that accessing beforeShellExecution[0] and afterFileEdit[0] yields a clear assertion failure instead of a TypeError when arrays are empty.packages/kit/content/hooks/shell-safety.sh (1)
9-36: 💤 Low valuePython3 dependency undocumented.
The script silently requires
python3for JSON parsing. If unavailable, the command substitution fails andCOMMAND_TEXTbecomes empty, causing all commands to be allowed (fail-open). Consider adding a brief comment at the top noting the python3 requirement, or check for its presence before attempting the parse:+# Requires: python3 (for JSON parsing) + INPUT_JSON="$(cat)" + +if ! command -v python3 >/dev/null 2>&1; then + printf '{"permission":"deny","user_message":"python3 required for shell safety hook."}\n' + exit 0 +fiAlternatively, keep the fail-open behavior but document it explicitly so future maintainers understand the trade-off.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/kit/content/hooks/shell-safety.sh` around lines 9 - 36, The script assigns COMMAND_TEXT via a command substitution that invokes python3 to parse JSON; add an explicit pre-check and/or documentation to avoid silent fail-open: before the COMMAND_TEXT assignment, detect python3 availability (e.g., test command -v python3) and if missing either (a) print a clear stderr warning and exit non-zero so the hook fails closed, or (b) add a top-of-file comment stating that python3 is required and that the current behavior intentionally falls back to an empty COMMAND_TEXT; update the script around the python3 invocation (the COMMAND_TEXT assignment and its python3 -c block) to implement the chosen behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/create-blit-tech/test/scaffold.test.mjs`:
- Around line 221-227: The test should guard array element access before
indexing: after asserting Array.isArray for hooksJson.hooks.beforeShellExecution
and hooksJson.hooks.afterFileEdit, add explicit non-empty checks (e.g.
assert.ok(hooksJson.hooks.beforeShellExecution.length > 0, 'beforeShellExecution
should contain at least one entry') and same for afterFileEdit) so that
accessing beforeShellExecution[0] and afterFileEdit[0] yields a clear assertion
failure instead of a TypeError when arrays are empty.
In `@packages/kit/content/hooks/shell-safety.sh`:
- Around line 9-36: The script assigns COMMAND_TEXT via a command substitution
that invokes python3 to parse JSON; add an explicit pre-check and/or
documentation to avoid silent fail-open: before the COMMAND_TEXT assignment,
detect python3 availability (e.g., test command -v python3) and if missing
either (a) print a clear stderr warning and exit non-zero so the hook fails
closed, or (b) add a top-of-file comment stating that python3 is required and
that the current behavior intentionally falls back to an empty COMMAND_TEXT;
update the script around the python3 invocation (the COMMAND_TEXT assignment and
its python3 -c block) to implement the chosen behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c51406d7-17cc-48e4-b3d4-a4ab6b62a12b
📒 Files selected for processing (5)
packages/create-blit-tech/src/scaffold.tspackages/create-blit-tech/templates/optional/cursor/dot-cursor/rules/blit-tech-api-names.mdcpackages/create-blit-tech/test/scaffold.test.mjspackages/kit/content/hooks.manifest.jsonpackages/kit/content/hooks/shell-safety.sh
💤 Files with no reviewable changes (1)
- packages/create-blit-tech/templates/optional/cursor/dot-cursor/rules/blit-tech-api-names.mdc
Add explicit non-empty length assertions for hooks.json afterFileEdit and beforeShellExecution arrays before indexing with [0], so an empty array produces a clear assertion failure instead of a TypeError. Add a python3 availability pre-check to shell-safety.sh: if python3 is not installed the hook now exits non-zero with a deny response and a descriptive user/agent message, ensuring fail-closed behaviour rather than silently allowing commands through via an empty COMMAND_TEXT. Assisted-by: Claude Sonnet 4.6 Signed-off-by: Vaclav Vancura <commit@vancura.dev>
Replace static templates/optional/cursor/ with generateCursorAdapter(), which composes .cursor/rules/, hooks.json, shell hook scripts, and commands/ from kit content/rules, content/skills, and hooks.manifest.json. Add canonical format-on-edit and shell-safety hooks.
This PR replaces the static Cursor adapter template with a dynamic generation system that composes the
.cursordirectory at scaffold time from kit content sources.Key Changes
Cursor adapter generation: The scaffolder now invokes a new
generateCursorAdapter()function that assembles the.cursordirectory from canonical kit sources instead of copying a static template tree. The generator:content/hooks.manifest.jsoninto.cursor/hooks.jsonwith template variable rendering.cursor/rules/*.mdcfromcontent/rules/*.md, preserving YAML frontmattercontent/hooks/.cursor/commands/*.mdfromcontent/skills/*/SKILL.mdHook manifest: A new
hooks.manifest.jsondefines two Cursor hooks:format-on-edit: Runs a package-manager-based formatter after AI editsblock-dangerous-shell: Executesshell-safety.shbefore shell execution withfailClosed: trueShell safety hook: A new
shell-safety.shscript blocks destructive git operations (git reset --hard,git clean -f,git checkout --) and prompts for force-push operations, while allowing all other commands.Kit ownership: The
.cursor/hooks.jsonis now classified as kit-owned, ensuringblit agents syncregenerates it when unmodified.Test updates: Test coverage expanded to validate the new dynamic generation, including:
hooks.jsonstructure and hook entriesThe old static template file
blit-tech-api-names.mdcis removed as it is now dynamically generated from kit content.