Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions packages/cli-core/src/commands/init/skills.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { test, expect, describe } from "bun:test";
import { buildSkillsArgs } from "./skills.ts";

describe("buildSkillsArgs", () => {
const skills = ["clerk", "clerk-setup", "clerk-nextjs-patterns"];

test("interactive mode: no -y or -g, lets skills CLI take over", () => {
const args = buildSkillsArgs(skills, true);
expect(args).toEqual([
"npx",
"skills",
"add",
"clerk/skills",
"--skill",
"clerk",
"--skill",
"clerk-setup",
"--skill",
"clerk-nextjs-patterns",
]);
expect(args).not.toContain("-y");
expect(args).not.toContain("-g");
expect(args).not.toContain("--agent");
});

test("non-interactive mode: includes -y and -g for global auto-detect", () => {
const args = buildSkillsArgs(skills, false);
expect(args).toContain("-y");
expect(args).toContain("-g");
expect(args).not.toContain("--agent");
});

test("never passes --agent (lets skills CLI auto-detect)", () => {
expect(buildSkillsArgs(skills, true)).not.toContain("--agent");
expect(buildSkillsArgs(skills, false)).not.toContain("--agent");
});
});
33 changes: 24 additions & 9 deletions packages/cli-core/src/commands/init/skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ function resolveSkills(frameworkDep: string | undefined): string[] {
return skills;
}

/**
* Build the argv for `npx skills add`.
*
* Interactive mode: hand off to the skills CLI's native UX (auto-detect
* installed agents, scope picker). Non-interactive: pass `-y -g` so it
* runs unattended with global scope and auto-detected agents.
*
* Exported for tests.
*/
export function buildSkillsArgs(skills: string[], interactive: boolean): string[] {
const skillFlags = skills.flatMap((s) => ["--skill", s]);
const extraFlags = interactive ? [] : ["-y", "-g"];
return ["npx", "skills", "add", SKILLS_SOURCE, ...skillFlags, ...extraFlags];
}

export async function installSkills(
cwd: string,
frameworkDep: string | undefined,
Expand All @@ -54,15 +69,15 @@ export async function installSkills(

console.log(`\nInstalling skills: ${cyan(skillList)}`);

const skillFlags = skills.flatMap((s) => ["--skill", s]);
const proc = Bun.spawn(
["npx", "skills", "add", SKILLS_SOURCE, ...skillFlags, "--agent", "*", "-y"],
{
cwd,
stdout: "inherit",
stderr: "inherit",
},
);
const interactive = isHuman() && !skipPrompt;
const args = buildSkillsArgs(skills, interactive);

const proc = Bun.spawn(args, {
cwd,
stdin: "inherit",
stdout: "inherit",
stderr: "inherit",
});
const exitCode = await proc.exited;

if (exitCode !== 0) {
Expand Down
Loading