fix(root): use agent identifier as scaffolded file name fixes NV-7479#10972
fix(root): use agent identifier as scaffolded file name fixes NV-7479#10972
Conversation
Previously, the scaffolding command always created the agent file as support-agent.tsx regardless of the --agent-identifier value. Now the file, export name, and all references (index.ts, route.ts, page.tsx, README) are renamed to match the provided agent identifier. Co-authored-by: Adam Chmara <adam.chmara1@gmail.com>
✅ Deploy Preview for dashboard-v2-novu-staging canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughWhen initializing the APP_AGENT template with an ChangesAPP_AGENT Template Installation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
Co-authored-by: Adam Chmara <adam.chmara1@gmail.com>
Co-authored-by: Adam Chmara <adam.chmara1@gmail.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/novu/src/commands/init/templates/index.ts (1)
93-99:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDigit-leading identifiers pass validation but produce invalid JS variable names in the generated code.
The existing slug regex
/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/(line 93) allows identifiers like1agentor0-foo. When such a value reaches line 99,camelNameinherits the leading digit (e.g.,1agent,0Foo). A JavaScript identifier must start with a letter, underscore, or dollar sign — it can't start with a digit. The scaffolded.tsxfile would emitexport const 1agent = ..., which is a hard syntax error in the generated project.Fix: tighten the slug regex to require a leading letter:
🐛 Proposed fix
- if (!/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/.test(agentIdentifier)) { + if (!/^[a-z][a-z0-9]*(?:[-_][a-z0-9]+)*$/.test(agentIdentifier)) { throw new Error( `Invalid agent identifier: "${agentIdentifier}". Must be a lowercase slug (a-z, 0-9, hyphens, underscores).` );The error message should also be updated to reflect that the identifier must start with a letter (
a-z).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/novu/src/commands/init/templates/index.ts` around lines 93 - 99, The agentIdentifier validation allows leading digits which later produce invalid JS variable names when used to build camelName; change the regex used in the agent identifier check (the `/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/` test around agentIdentifier) to require a leading letter (e.g. start with [a-z] rather than [a-z0-9]) and update the thrown Error message to state the identifier must start with a letter (a-z) and only contain lowercase letters, digits, hyphens, and underscores so generated variable names (camelName) won't begin with a digit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/novu/src/commands/init/templates/index.ts`:
- Around line 93-99: The agentIdentifier validation allows leading digits which
later produce invalid JS variable names when used to build camelName; change the
regex used in the agent identifier check (the `/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/`
test around agentIdentifier) to require a leading letter (e.g. start with [a-z]
rather than [a-z0-9]) and update the thrown Error message to state the
identifier must start with a letter (a-z) and only contain lowercase letters,
digits, hyphens, and underscores so generated variable names (camelName) won't
begin with a digit.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d363f54e-247a-4b92-8925-cf127a0d15a0
📒 Files selected for processing (1)
packages/novu/src/commands/init/templates/index.ts
| (await fs.readFile(agentFile, 'utf8')).replace("agent('support-agent',", `agent('${agentIdentifier}',`) | ||
| if (renameAgent) { | ||
| const camelName = agentIdentifier.replace(/[-_]([a-z0-9])/g, (_, c) => c.toUpperCase()); | ||
| const files = await glob('**/*.{tsx,ts,md}', { cwd: root, absolute: true }); |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: HIGH
Description: The recursive glob used during agent rename (glob('**/*.{tsx,ts,md}', { cwd: root, absolute: true })) can follow symlinks under the target root and then rewrite matched files. This allows writes outside the intended scaffold directory when a symlink points externally.
Impact: An attacker with control over workspace contents can trigger out-of-root file modification during scaffold execution, potentially overwriting arbitrary files accessible to the current user.
|
@cursoragent check if PR comments are relevant and address |
|
The security finding was valid and has been addressed. The The other PR comments (Linear linkback, Netlify deploy preview, CodeRabbit summary) are informational and don't require action. |
Co-authored-by: Adam Chmara <adam.chmara1@gmail.com>



What changed
The
novu init -t agent --agent-identifier <id>scaffolding command now names the generated agent file after the provided identifier instead of always usingsupport-agent.tsx.Before:
npx novu init -t agent --agent-identifier first-agent→ createsapp/novu/agents/support-agent.tsx(only the string insideagent(...)was replaced).After: the same command creates
app/novu/agents/first-agent.tsxwith all references updated across the scaffolded project.How
The file rename happens during
copy()via the existingrenamecallback — the same mechanism used forgitignore→.gitignoreandREADME-template.md→README.md. Then a single glob-based pass replacessupportAgent→ camelCase name andsupport-agent→ identifier across all.tsx,.ts, and.mdfiles.When no
--agent-identifieris provided, the defaultsupport-agent.tsxtemplate is preserved unchanged.Changes
packages/novu/src/commands/init/templates/index.tscopy()callback + glob-based content replacementLinear Issue: NV-7479
What changed
The scaffolder for
novu init -t agentnow uses the provided --agent-identifier to name the generated agent file and update references across the scaffolded project. When an identifier is supplied, the template file support-agent.tsx is renamed to {identifier}.tsx during copy, the identifier is validated as a lowercase slug, a camelCased export name is derived, and a glob-based pass replaces supportAgent/support-agent across .tsx, .ts, and .md files so code and filenames stay consistent.Affected areas
novu (packages/novu): The template installation logic was updated to support conditional rename of the agent template during copy, validate the agent identifier, derive a camelCase export name, and perform a single glob-based content replacement across scaffolded TypeScript and Markdown files.
Key technical decisions
Testing
No automated tests were added; verification is manual by running
npx novu init -t agent --agent-identifier <id>and confirming the generated filename and cross-file references are correctly updated.