fix(link): install agent skills before creating template subdir#70
fix(link): install agent skills before creating template subdir#70tonychang04 wants to merge 2 commits intomainfrom
Conversation
Move installSkills() in the --template branch to run before mkdir/chdir so skills land in the parent directory. Claude Code, Windsurf, Codex, Gemini, Qwen, Kilo, Augment, and Antigravity all walk up parent directories for skills/rules, so this works for the common case of an agent already driving the CLI from the workspace. Non-template link flow is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
WalkthroughVersion bump to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/commands/projects/link.ts`:
- Around line 205-207: installSkills(json) is being invoked before the directory
prompt and collision checks, causing skills to be installed in the parent
directory even if the user cancels or the target directory already exists; move
the installSkills(json) call so it runs after the directory validation/prompt
logic and after the code that creates or confirms the project subdirectory (the
block that checks for existing directory and prompts the user), ensuring skills
are installed only once the target project directory is validated/created and
not before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4f6174ec-9a46-41b2-a3f9-61d8581ed149
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
package.jsonsrc/commands/projects/link.ts
| // Install agent skills in the current directory before creating the project subdir | ||
| await installSkills(json); | ||
|
|
There was a problem hiding this comment.
Delay skill installation until after directory validation succeeds.
At Line 205, side effects now occur before directory prompt/collision checks. If the user cancels or the directory already exists, skills still get installed in the parent directory even though template setup does not proceed.
Suggested adjustment
- // Install agent skills in the current directory before creating the project subdir
- await installSkills(json);
-
// Ask for directory name
let dirName = project.name;
if (!json) {
const inputDir = await prompts.text({
@@
const templateDir = path.resolve(process.cwd(), dirName);
const dirExists = await fs.stat(templateDir).catch(() => null);
if (dirExists) {
throw new CLIError(`Directory "${dirName}" already exists.`);
}
+
+ // Install agent skills in parent cwd only after validation passes
+ await installSkills(json);
+
await fs.mkdir(templateDir);
process.chdir(templateDir);📝 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.
| // Install agent skills in the current directory before creating the project subdir | |
| await installSkills(json); | |
| // Ask for directory name | |
| let dirName = project.name; | |
| if (!json) { | |
| const inputDir = await prompts.text({ | |
| // ... existing prompt code ... | |
| } | |
| const templateDir = path.resolve(process.cwd(), dirName); | |
| const dirExists = await fs.stat(templateDir).catch(() => null); | |
| if (dirExists) { | |
| throw new CLIError(`Directory "${dirName}" already exists.`); | |
| } | |
| // Install agent skills in parent cwd only after validation passes | |
| await installSkills(json); | |
| await fs.mkdir(templateDir); | |
| process.chdir(templateDir); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/commands/projects/link.ts` around lines 205 - 207, installSkills(json) is
being invoked before the directory prompt and collision checks, causing skills
to be installed in the parent directory even if the user cancels or the target
directory already exists; move the installSkills(json) call so it runs after the
directory validation/prompt logic and after the code that creates or confirms
the project subdirectory (the block that checks for existing directory and
prompts the user), ensuring skills are installed only once the target project
directory is validated/created and not before.
Summary
link --template <name>, moveinstallSkills()to run beforemkdir/chdir, so skills install in the parent cwd instead of inside the newly-created project subdir.linkflow is unchanged.Why
When the agent (Claude Code, Cursor, etc.) is already driving the CLI from a workspace and
link --templatecreates a subproject directory, installing skills inside that subdir hides them from the agent's current session. Moving the install to the parent fixes this.Per each agent's docs, skills installed in the parent still load from subdirs for: Claude Code, Windsurf, Codex CLI (
AGENTS.md), Gemini CLI, Qwen, Kilo, Augment, Antigravity, and GitHub Copilot (opt-in).Caveat: Cursor, Cline, Roo, Qoder, and likely Trae do not walk up parent directories. Users of those agents who later open the new project dir as a fresh workspace won't get skills auto-loaded — they'd need to re-run
npx skills add insforge/agent-skillsinside the project.Test plan
npm run lint— passes (69 tests)npm run build— passesinsforge link --template react— verify skills install in cwd, then subdir is created and template downloads into itinsforge link(no template) — verify behavior unchanged🤖 Generated with Claude Code
Note
Fix agent skill installation to run in the current directory before creating the template subdirectory
When
--templateis used inlink,installSkillswas previously called inside the newly created project subdirectory. It now runs in the current working directory immediately after template validation, before the project directory is created.Macroscope summarized 26cbed5.
Summary by CodeRabbit