Repository navigation
feat: add add command , new skills addon, new history command - #848
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds a new "skills" addon and guided installer, a CLI Changes
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (7)
packages/template-generator/src/processors/runtime-deps.ts (1)
25-37: Align start scripts with Bun execution guidelines.
Guidelines specifybun <file>for running JS/TS; current scripts usebun runandnode. Consider switching both tobun dist/index.mjs, or document an explicit exception if Node execution is required. As per coding guidelines, ...♻️ Suggested adjustment
- pkgJson.scripts.start = "bun run dist/index.mjs"; + pkgJson.scripts.start = "bun dist/index.mjs"; ... - pkgJson.scripts.start = "node dist/index.mjs"; + pkgJson.scripts.start = "bun dist/index.mjs";apps/cli/src/utils/bts-config.ts (2)
13-25: Consider adding validation after parsing to ensure type safety.The
parsefunction returnsunknown, and the cast toBetterTStackConfigdoesn't validate the structure. If the file contains malformed JSON or unexpected schema, downstream code may fail with confusing errors.♻️ Suggested improvement with basic validation
const configContent = await fs.readFile(configPath, "utf-8"); - const config = parse(configContent) as BetterTStackConfig; - return config; + const config = parse(configContent); + if (config && typeof config === "object") { + return config as BetterTStackConfig; + } + return null;
35-53: Silent failures may hide configuration issues.Both
readBtsConfigandupdateBtsConfigsilently swallow errors. While this prevents crashes, it can make debugging difficult when config updates don't persist. Consider logging a debug-level message or returning a status indicator.apps/cli/src/helpers/addons/skills-setup.ts (3)
3-3: Consider usingBun.$instead ofexecafor shell execution.Per coding guidelines,
Bun.$template literal syntax is preferred overexecafor shell command execution. However, if there are specific reasons for usingexeca(e.g., better cross-platform support or specific features), this can be kept.
219-227: Add defensive handling for the::delimiter split.If a source string unexpectedly contains
::, the split will produce more than 2 elements, andskillNamewill be incorrect. Consider using a more robust approach.♻️ Suggested fix using indexOf for safer splitting
for (const skillKey of selectedSkills) { - const [source, skillName] = (skillKey as string).split("::"); + const key = skillKey as string; + const separatorIndex = key.indexOf("::"); + if (separatorIndex === -1) continue; + const source = key.substring(0, separatorIndex); + const skillName = key.substring(separatorIndex + 2); if (!skillsBySource[source]) { skillsBySource[source] = []; } skillsBySource[source].push(skillName); }
232-248: Shell command injection risk with string interpolation.Building shell commands via string concatenation with user-selected values could be risky if any skill names or sources contain shell metacharacters. The
execaarray form would be safer than string interpolation.♻️ Consider using array-based command execution
Instead of building a single command string like
skills@latest add ${source} ${skillFlags} ${agentFlags} -y, consider passing arguments as an array to avoid potential issues with special characters in skill names or sources.apps/cli/src/utils/project-history.ts (1)
56-69: Consider validating the history data structure after reading.Similar to the bts-config issue,
readJsonreturns data that's cast without validation. If the history file is corrupted or has an unexpected schema, it could cause issues downstream.♻️ Suggested validation
try { if (await fs.pathExists(historyPath)) { const data = await fs.readJson(historyPath); - return data as HistoryData; + if (data && typeof data === "object" && Array.isArray(data.entries)) { + return data as HistoryData; + } } } catch { // If file is corrupted, return empty history }
| export interface AddHandlerOptions { | ||
| silent?: boolean; | ||
| } | ||
|
|
||
| export interface AddResult { | ||
| success: boolean; | ||
| addedAddons: Addons[]; | ||
| projectDir: string; | ||
| error?: string; | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
# Check if file exists and view the relevant section
cd /tmp/repo && find . -name "add-handler.ts" -type fRepository: AmanVarshney01/create-better-t-stack
Length of output: 139
🏁 Script executed:
# Display the file content to verify current state
cat -n apps/cli/src/helpers/core/add-handler.ts | sed -n '20,40p'Repository: AmanVarshney01/create-better-t-stack
Length of output: 801
🏁 Script executed:
# Search for usages of AddHandlerOptions and AddResult in the codebase
rg "AddHandlerOptions|AddResult" --type ts --type tsx -B 2 -A 2Repository: AmanVarshney01/create-better-t-stack
Length of output: 107
🏁 Script executed:
# Search for usages of AddHandlerOptions and AddResult
rg "AddHandlerOptions|AddResult" -A 2 -B 2Repository: AmanVarshney01/create-better-t-stack
Length of output: 2111
🏁 Script executed:
# Check if these interfaces are extended or used in type hierarchies
rg "extends.*AddHandlerOptions|extends.*AddResult|implements.*AddHandlerOptions|implements.*AddResult"Repository: AmanVarshney01/create-better-t-stack
Length of output: 62
🏁 Script executed:
# Look for imports of these types from this file
rg "from.*add-handler|import.*AddHandlerOptions|import.*AddResult"Repository: AmanVarshney01/create-better-t-stack
Length of output: 174
Replace interfaces with type aliases.
Project TS rules prefer type over interface. This aligns with the project's documented guidelines for TypeScript files.
♻️ Proposed fix
-export interface AddHandlerOptions {
- silent?: boolean;
-}
-
-export interface AddResult {
- success: boolean;
- addedAddons: Addons[];
- projectDir: string;
- error?: string;
-}
+export type AddHandlerOptions = {
+ silent?: boolean;
+};
+
+export type AddResult = {
+ success: boolean;
+ addedAddons: Addons[];
+ projectDir: string;
+ error?: string;
+};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| export interface AddHandlerOptions { | |
| silent?: boolean; | |
| } | |
| export interface AddResult { | |
| success: boolean; | |
| addedAddons: Addons[]; | |
| projectDir: string; | |
| error?: string; | |
| } | |
| export type AddHandlerOptions = { | |
| silent?: boolean; | |
| }; | |
| export type AddResult = { | |
| success: boolean; | |
| addedAddons: Addons[]; | |
| projectDir: string; | |
| error?: string; | |
| }; |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/template-generator/src/utils/reproducible-command.ts (1)
3-3: Drop the explicit return type to match TS style rules.♻️ Proposed fix
-export function generateReproducibleCommand(config: ProjectConfig): string { +export function generateReproducibleCommand(config: ProjectConfig) {As per coding guidelines:
**/*.{ts,tsx}: Do not use explicit return types.apps/cli/src/helpers/addons/skills-setup.ts (2)
126-163: Remove explicit return type annotations in TS functions.The file specifies explicit return types on multiple functions; the guidelines ask to omit these and rely on inference.
As per coding guidelines: Do not use explicit return types.♻️ Proposed change
-function parseSkillsFromOutput(output: string): string[] { +function parseSkillsFromOutput(output: string) { @@ -async function fetchSkillsFromSource( +async function fetchSkillsFromSource( source: SkillSource, packageManager: ProjectConfig["packageManager"], projectDir: string, -): Promise<string[]> { +) { @@ -export async function setupSkills( - config: ProjectConfig, -): Promise<Result<void, AddonSetupError | UserCancelledError>> { +export async function setupSkills(config: ProjectConfig) {
198-203: Avoid arrow callbacks; extract named functions instead.The guidelines prefer standard function declarations over arrow functions. Consider extracting named helpers for map callbacks here (and similarly for other inline arrows in this file).
As per coding guidelines: Define functions using the standard function declaration syntax, not arrow functions.♻️ Example refactor
+function toSkillOption(skill: FetchedSkill) { + return { + value: `${skill.source}::${skill.name}`, + label: skill.name, + hint: skill.sourceLabel, + }; +} + - const skillOptions = allSkills.map((skill) => ({ - value: `${skill.source}::${skill.name}`, - label: skill.name, - hint: skill.sourceLabel, - })); + const skillOptions = allSkills.map(toSkillOption);Also applies to: 250-256
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/cli/src/helpers/addons/skills-setup.ts (1)
174-183: Static analysis false positive - consider adding a suppression comment.The regex
\x1b\[[0-9;]*mis intentional for stripping ANSI escape codes from CLI output. The static analysis tool flags it as "unexpected control character," but this is the correct pattern for ANSI sequence removal.Consider adding a suppression comment for clarity:
♻️ Suggested change
for (const line of lines) { // Strip ANSI codes first + // biome-ignore lint/suspicious/noControlCharactersInRegex: Intentional ANSI escape sequence stripping const cleanLine = line.replace(/\x1b\[[0-9;]*m/g, "");
492ccc7 to
55baf39
Compare
55baf39 to
2a39655
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (6)
AGENTS.md (1)
29-31: Consider varying sentence structure for readability.Three consecutive bullet points start with "Use". A minor rewording could improve flow.
📝 Suggested rewording
- **Runtime:** This is a **Bun** project. - - Use `Bun.file` over `node:fs`. - - Use `Bun.serve` over `express`. - - Use `Bun.env` or just `process.env` (auto-loaded). + - Prefer `Bun.file` over `node:fs`. + - Prefer `Bun.serve` over `express`. + - Environment variables: use `Bun.env` or `process.env` (auto-loaded).apps/cli/src/utils/bts-config.ts (1)
31-54: Silent failure inupdateBtsConfigmay mask issues.The empty catch block silently swallows all errors, including legitimate issues like malformed JSONC content or disk write failures. Consider at least logging a debug message or returning a boolean to indicate success/failure.
Proposed improvement
} catch { - // Silent failure + // Config update is non-critical; log for debugging if needed + // Consider: return false; or log.debug("Failed to update BTS config") } }apps/cli/src/helpers/addons/skills-setup.ts (2)
290-298: Potential runtime error if skill key doesn't contain the::delimiter.The split assumes the format
source::skillName, but if a malformed key is present,skillNamewill beundefined. Consider adding defensive handling.Proposed fix
for (const skillKey of selectedSkills) { const [source, skillName] = (skillKey as string).split("::"); + if (!source || !skillName) continue; if (!skillsBySource[source]) { skillsBySource[source] = []; } skillsBySource[source].push(skillName); }
303-319: Consider escaping or validating skill/agent names before building command arguments.If skill or agent names contain special shell characters, the current string interpolation approach could cause command injection or parsing issues. The values come from controlled sources (SKILL_SOURCES and AVAILABLE_AGENTS), so this is low risk, but worth noting for future maintenance.
apps/cli/src/index.ts (1)
56-93: Remove explicit return type annotations from new helpers/add API.Let TS infer these return types.
♻️ Proposed fix
-function formatStackSummary(entry: ProjectHistoryEntry): string { +function formatStackSummary(entry: ProjectHistoryEntry) { const parts: string[] = []; ... } -function formatDate(isoString: string): string { +function formatDate(isoString: string) { const date = new Date(isoString); ... } -async function historyHandler(input: { +async function historyHandler(input: { limit: number; clear: boolean; json: boolean; -}): Promise<void> { +}) { ... } -export async function add( +export async function add( options: { addons?: Addons[]; install?: boolean; packageManager?: PackageManager; projectDir?: string; } = {}, -): Promise<AddResult | undefined> { + ) { return addHandler(options, { silent: true }); }As per coding guidelines, Do not use explicit return types.
Also applies to: 477-485
apps/cli/src/helpers/core/add-handler.ts (1)
191-198: PreferBun.filefor reading package.json and remove fs-extra dependency.Align with Bun-first guidelines by replacing
fs-extramethods withBun.file().exists()andBun.file().text(). Sincefs-extrais only used in this section, it can be removed entirely from the imports.♻️ Proposed fix
const packageJsonPaths = ["package.json", "apps/web/package.json"]; for (const pkgPath of packageJsonPaths) { const fullPath = path.join(projectDir, pkgPath); - if (await fs.pathExists(fullPath)) { - const content = await fs.readFile(fullPath, "utf-8"); + const file = Bun.file(fullPath); + if (await file.exists()) { + const content = await file.text(); vfs.writeFile(pkgPath, content); } }Remove the fs-extra import from line 10.
Summary by CodeRabbit
New Features
Documentation
Chores
✏️ Tip: You can customize this high-level summary in your review settings.