Skip to content
69 changes: 38 additions & 31 deletions apps/cli/src/helpers/addons/skills-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isSilent } from "../../utils/context";
import { AddonSetupError, UserCancelledError } from "../../utils/errors";
import { shouldSkipExternalCommands } from "../../utils/external-commands";
import { getPackageRunnerPrefix } from "../../utils/package-runner";
import { cliLog, createSpinner } from "../../utils/terminal-output";
import { createSpinner } from "../../utils/terminal-output";
import { supportsEvlogLocalLogs } from "./evlog-setup";

type SkillSource = {
Expand Down Expand Up @@ -77,7 +77,7 @@ const SKILL_SOURCES = {
"elysiajs/skills": {
label: "ElysiaJS",
},
"waynesutton/convexskills": {
"get-convex/agent-skills": {
label: "Convex",
},
"msmps/opentui-skill": {
Expand Down Expand Up @@ -315,7 +315,7 @@ function getRecommendedSourceKeys(config: ProjectConfig): SourceKey[] {
}

if (backend === "convex") {
sources.push("waynesutton/convexskills");
sources.push("get-convex/agent-skills");
}

if (addons.includes("opentui")) {
Expand Down Expand Up @@ -405,45 +405,39 @@ const CURATED_SKILLS_BY_SOURCE = {

return [];
},
"expo/skills": (config) => {
const skills = [
"expo-overview",
"expo-router",
"expo-dev-client",
"expo-native-ui",
"expo-data-fetching",
"eas-app-stores",
"eas-workflows",
];
if (config.frontend.includes("native-uniwind")) {
skills.push("expo-tailwind-setup");
}
return skills;
},
"expo/skills": () => [
"expo-overview",
"expo-router",
"expo-dev-client",
"expo-native-ui",
"expo-data-fetching",
"eas-app-stores",
"eas-workflows",
],
"prisma/skills": (config) => {
const skills: string[] = [];

if (config.orm === "prisma") {
skills.push("prisma-cli", "prisma-client-api", "prisma-database-setup");
skills.push("prisma-cli", "prisma-client-api", "prisma-orm-setup");
}

if (config.dbSetup === "prisma-postgres") {
skills.push("prisma-postgres");
skills.push("prisma-postgres-setup");
}

return skills;
},
"elysiajs/skills": () => ["elysiajs"],
"waynesutton/convexskills": () => [
"convex-best-practices",
"convex-functions",
"convex-schema-validator",
"convex-realtime",
"convex-http-actions",
"convex-cron-jobs",
"convex-file-storage",
"convex-migrations",
"convex-security-check",
"get-convex/agent-skills": () => [
"convex",
"convex-design",
"convex-docs",
"convex-reviewer",
"convex-authz",
"convex-crons",
"convex-migrate",
"convex-env",
"convex-test",
],
"msmps/opentui-skill": () => ["opentui"],
"haydenbleasel/ultracite": () => ["ultracite"],
Expand Down Expand Up @@ -612,6 +606,8 @@ export async function setupSkills(
const globalFlags = scope === "global" ? ["-g"] : [];
const agentTargets = expandSkillsAgentTargets(selectedAgents);

const failures: AddonSetupError[] = [];

// Install skills grouped by source (project scope, no -g flag)
for (const [source, skills] of Object.entries(skillsBySource)) {
const installResult = await Result.tryPromise({
Expand Down Expand Up @@ -639,10 +635,21 @@ export async function setupSkills(
});

if (installResult.isErr()) {
cliLog.warn(pc.yellow(`Warning: Could not install skills from ${source}`));
failures.push(installResult.error);
}
}

if (failures.length > 0) {
installSpinner.stop(pc.red("Failed to install skills"));
return Result.err(
new AddonSetupError({
addon: "skills",
message: failures.map((failure) => failure.message).join("\n"),
cause: failures.map((failure) => failure.cause),
}),
);
}

installSpinner.stop("Skills installed");

return Result.ok(undefined);
Expand Down
37 changes: 35 additions & 2 deletions apps/cli/src/helpers/core/add-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import { errorClass, failureStage, reportDiagnostic, scrubReason } from "../../u
import { formatConfigValue } from "../../utils/display-config";
import { CLIError, UserCancelledError, displayError } from "../../utils/errors";
import { validateAgentSafePathInput } from "../../utils/input-hardening";
import { beginInterruptibleScope, endInterruptibleScope } from "../../utils/interrupt";
import {
beginInterruptibleScope,
endInterruptibleScope,
getStepFailures,
} from "../../utils/interrupt";
import { renderTitle } from "../../utils/render-title";
import { checkLocalRequirements } from "../../utils/requirements";
import { setupAddons } from "../addons/addons-setup";
Expand Down Expand Up @@ -691,8 +695,37 @@ async function addHandlerInternal(
},
});

// Remove the new package on failure so the same add can be retried
// Returns a note when the directory can't be removed, so the error tells the user to delete it
const cleanupReservedPackage = async () => {
if (!reservedPackageDir) return undefined;
const dir = reservedPackageDir;
const removed = await Result.tryPromise({
try: () => fs.remove(dir),
catch: (cause: unknown) => new CLIError({ message: `Failed to remove ${dir}`, cause }),
});
return removed.isErr() ? `Also failed to remove ${dir}; delete it before retrying.` : undefined;
};

if (setupResult.isErr()) {
return Result.err(setupResult.error);
const cleanupNote = await cleanupReservedPackage();
if (!cleanupNote) return Result.err(setupResult.error);
return Result.err(
new CLIError({
message: `${setupResult.error.message}\n${cleanupNote}`,
cause: setupResult.error,
}),
);
}

const stepFailures = getStepFailures();
if (stepFailures.length > 0) {
const cleanupNote = await cleanupReservedPackage();
// Interactive runs already printed each failure as it happened
const message = isSilent() ? stepFailures.join("\n") : "Addon setup failed";
return Result.err(
new CLIError({ message: cleanupNote ? `${message}\n${cleanupNote}` : message }),
);
}

// Update bts.jsonc with new addons
Expand Down
1 change: 1 addition & 0 deletions apps/cli/src/helpers/core/command-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ async function createProjectHandlerInternal(
if (created.interrupted) {
warnings.push("One or more setup steps were cancelled.");
}
warnings.push(...created.stepFailures);
if (created.installError) {
warnings.push(created.installError.message);
await reportDiagnostic("cli_failed", {
Expand Down
10 changes: 9 additions & 1 deletion apps/cli/src/helpers/core/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
beginInterruptibleScope,
endInterruptibleScope,
getInterruptSignal,
getStepFailures,
startInterruptibleStep,
wasAnyStepInterrupted,
wasInterrupted,
Expand All @@ -39,6 +40,7 @@ export interface CreateProjectOutcome {
install: "installed" | "skipped" | "cancelled" | "failed";
installError: ProjectCreationError | null;
interrupted: boolean;
stepFailures: string[];
}

/**
Expand Down Expand Up @@ -177,7 +179,13 @@ async function* runPostScaffoldSteps(
});
}

return Result.ok({ projectDir, install, installError, interrupted: wasAnyStepInterrupted() });
return Result.ok({
projectDir,
install,
installError,
interrupted: wasAnyStepInterrupted(),
stepFailures: getStepFailures(),
});
}

async function setPackageManagerVersion(
Expand Down
17 changes: 17 additions & 0 deletions apps/cli/src/utils/bts-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { CLIError } from "./errors";

const BTS_CONFIG_FILE = "bts.jsonc";

// waynesutton/convexskills was replaced by get-convex/agent-skills, which groups skills differently
const LEGACY_CONVEX_SKILLS = new Map([
["convex-cron-jobs", "convex-crons"],
["convex-migrations", "convex-migrate"],
["convex-security-check", "convex-authz"],
]);

function parseBtsConfig(content: string): BetterTStackConfig {
const errors: ParseError[] = [];
const value = parse(content, errors, { allowTrailingComma: true });
Expand All @@ -19,6 +26,16 @@ function parseBtsConfig(content: string): BetterTStackConfig {
if (selection?.source === "yusukebe/hono-skill") {
selection.source = "honojs/skills";
}
if (selection?.source === "waynesutton/convexskills") {
selection.source = "get-convex/agent-skills";
if (Array.isArray(selection.skills)) {
selection.skills = [
...new Set(
selection.skills.map((skill: string) => LEGACY_CONVEX_SKILLS.get(skill) ?? "convex"),
Comment thread
AmanVarshney01 marked this conversation as resolved.
Resolved
),
];
}
}
}
}
return BetterTStackConfigSchema.parse(value);
Expand Down
4 changes: 4 additions & 0 deletions apps/cli/src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export type CLIContext = {
projectDir?: string;
projectName?: string;
packageManager?: PackageManager;
/** Optional post-scaffold steps that failed during this run. */
stepFailures: string[];
};

const cliStorage = new AsyncLocalStorage<CLIContext>();
Expand All @@ -53,6 +55,7 @@ function defaultContext(): CLIContext {
verbose: false,
promptShown: false,
analyticsDisabled: false,
stepFailures: [],
};
}

Expand Down Expand Up @@ -176,6 +179,7 @@ function createContext(options: ContextOptions): CLIContext {
projectDir: options.projectDir,
projectName: options.projectName,
packageManager: options.packageManager,
stepFailures: [],
};
}

Expand Down
13 changes: 13 additions & 0 deletions apps/cli/src/utils/interrupt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { tryGetContext } from "./context";

let stepInterrupted = false;
let anyStepInterrupted = false;
let controller: AbortController | null = null;
Expand All @@ -12,6 +14,8 @@ export function beginInterruptibleScope(): void {
endInterruptibleScope();
stepInterrupted = false;
anyStepInterrupted = false;
const ctx = tryGetContext();
if (ctx) ctx.stepFailures = [];
listener = () => {
stepInterrupted = true;
anyStepInterrupted = true;
Expand Down Expand Up @@ -40,6 +44,15 @@ export function wasAnyStepInterrupted(): boolean {
return anyStepInterrupted;
}

/** Records an optional step that failed, so silent/JSON callers can report it. */
export function recordStepFailure(message: string): void {
tryGetContext()?.stepFailures.push(message);
}

export function getStepFailures(): string[] {
return [...(tryGetContext()?.stepFailures ?? [])];
}

export function getInterruptSignal(): AbortSignal | undefined {
return controller?.signal;
}
3 changes: 2 additions & 1 deletion apps/cli/src/utils/optional-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Result } from "better-result";
import pc from "picocolors";

import { UserCancelledError } from "./errors";
import { startInterruptibleStep, wasInterrupted } from "./interrupt";
import { recordStepFailure, startInterruptibleStep, wasInterrupted } from "./interrupt";
import { cliConsola, cliLog } from "./terminal-output";

/**
Expand All @@ -21,5 +21,6 @@ export async function runOptionalStep<T>(
cliLog.warn(pc.yellow(cancelledMessage));
return;
}
recordStepFailure(result.error.message);
cliConsola.error(pc.red(result.error.message));
}
13 changes: 11 additions & 2 deletions apps/cli/test/add-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ describe("adding to an existing project", () => {
skills: {
scope: "project",
agents: ["claude-code"],
selections: [{ source: "yusukebe/hono-skill", skills: ["hono"] }],
selections: [
{ source: "yusukebe/hono-skill", skills: ["hono"] },
{
source: "waynesutton/convexskills",
skills: ["convex-best-practices", "convex-functions", "convex-cron-jobs"],
},
],
},
};
await fs.writeFile(file, `// keep my project settings\n${JSON.stringify(config, null, 2)}`);
Expand All @@ -99,7 +105,10 @@ describe("adding to an existing project", () => {
skills: {
scope: "project",
agents: ["claude-code"],
selections: [{ source: "honojs/skills", skills: ["hono"] }],
selections: [
{ source: "honojs/skills", skills: ["hono"] },
{ source: "get-convex/agent-skills", skills: ["convex", "convex-crons"] },
],
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const SkillsSourceSchema = z
"expo/skills",
"prisma/skills",
"elysiajs/skills",
"waynesutton/convexskills",
"get-convex/agent-skills",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"msmps/opentui-skill",
"haydenbleasel/ultracite",
"https://www.evlog.dev",
Expand Down
Loading