feat: add uv skill installers

This commit is contained in:
Peter Steinberger
2025-12-20 17:50:29 +01:00
parent b9eabe532e
commit 4c054917ef
6 changed files with 49 additions and 30 deletions

View File

@@ -1,13 +1,14 @@
import type { ClawdisConfig } from "../config/config.js";
import { runCommandWithTimeout } from "../process/exec.js";
import { resolveUserPath } from "../utils.js";
import {
hasBinary,
loadWorkspaceSkillEntries,
resolveSkillsInstallPreferences,
type SkillEntry,
type SkillInstallSpec,
type SkillsInstallPreferences,
} from "./skills.js";
import type { ClawdisConfig } from "../config/config.js";
export type SkillInstallRequest = {
workspaceDir: string;
@@ -40,10 +41,6 @@ function findInstallSpec(
return undefined;
}
function runShell(command: string, timeoutMs: number) {
return runCommandWithTimeout(["/bin/zsh", "-lc", command], { timeoutMs });
}
function buildNodeInstallCommand(
packageName: string,
prefs: SkillsInstallPreferences,
@@ -63,36 +60,33 @@ function buildInstallCommand(
prefs: SkillsInstallPreferences,
): {
argv: string[] | null;
shell: string | null;
cwd?: string;
error?: string;
} {
switch (spec.kind) {
case "brew": {
if (!spec.formula)
return { argv: null, shell: null, error: "missing brew formula" };
return { argv: ["brew", "install", spec.formula], shell: null };
return { argv: null, error: "missing brew formula" };
return { argv: ["brew", "install", spec.formula] };
}
case "node": {
if (!spec.package)
return { argv: null, shell: null, error: "missing node package" };
return { argv: null, error: "missing node package" };
return {
argv: buildNodeInstallCommand(spec.package, prefs),
shell: null,
};
}
case "go": {
if (!spec.module)
return { argv: null, shell: null, error: "missing go module" };
return { argv: ["go", "install", spec.module], shell: null };
return { argv: null, error: "missing go module" };
return { argv: ["go", "install", spec.module] };
}
case "shell": {
if (!spec.command)
return { argv: null, shell: null, error: "missing shell command" };
return { argv: null, shell: spec.command };
case "uv": {
if (!spec.package)
return { argv: null, error: "missing uv package" };
return { argv: ["uv", "tool", "install", spec.package] };
}
default:
return { argv: null, shell: null, error: "unsupported installer" };
return { argv: null, error: "unsupported installer" };
}
}
@@ -138,7 +132,34 @@ export async function installSkill(
code: null,
};
}
if (!command.shell && (!command.argv || command.argv.length === 0)) {
if (spec.kind === "uv" && !hasBinary("uv")) {
if (hasBinary("brew")) {
const brewResult = await runCommandWithTimeout(
["brew", "install", "uv"],
{
timeoutMs,
},
);
if (brewResult.code !== 0) {
return {
ok: false,
message: "Failed to install uv (brew)",
stdout: brewResult.stdout.trim(),
stderr: brewResult.stderr.trim(),
code: brewResult.code,
};
}
} else {
return {
ok: false,
message: "uv not installed (install via brew)",
stdout: "",
stderr: "",
code: null,
};
}
}
if (!command.argv || command.argv.length === 0) {
return {
ok: false,
message: "invalid install command",
@@ -149,14 +170,12 @@ export async function installSkill(
}
const result = await (async () => {
if (command.shell) return runShell(command.shell, timeoutMs);
const argv = command.argv;
if (!argv || argv.length === 0) {
return { code: null, stdout: "", stderr: "invalid install command" };
}
return runCommandWithTimeout(argv, {
timeoutMs,
cwd: command.cwd,
});
})();

View File

@@ -76,13 +76,13 @@ function selectPreferredInstallSpec(
const brewSpec = findKind("brew");
const nodeSpec = findKind("node");
const goSpec = findKind("go");
const shellSpec = findKind("shell");
const uvSpec = findKind("uv");
if (prefs.preferBrew && hasBinary("brew") && brewSpec) return brewSpec;
if (uvSpec) return uvSpec;
if (nodeSpec) return nodeSpec;
if (brewSpec) return brewSpec;
if (goSpec) return goSpec;
if (shellSpec) return shellSpec;
return indexed[0];
}
@@ -108,6 +108,8 @@ function normalizeInstallOptions(
label = `Install ${spec.package} (${prefs.nodeManager})`;
} else if (spec.kind === "go" && spec.module) {
label = `Install ${spec.module} (go)`;
} else if (spec.kind === "uv" && spec.package) {
label = `Install ${spec.package} (uv)`;
} else {
label = "Run installer";
}

View File

@@ -13,13 +13,12 @@ import { CONFIG_DIR, resolveUserPath } from "../utils.js";
export type SkillInstallSpec = {
id?: string;
kind: "brew" | "node" | "go" | "shell";
kind: "brew" | "node" | "go" | "uv";
label?: string;
bins?: string[];
formula?: string;
package?: string;
module?: string;
command?: string;
};
export type ClawdisSkillMetadata = {
@@ -143,7 +142,7 @@ function parseInstallSpec(input: unknown): SkillInstallSpec | undefined {
kind !== "brew" &&
kind !== "node" &&
kind !== "go" &&
kind !== "shell"
kind !== "uv"
) {
return undefined;
}
@@ -159,7 +158,6 @@ function parseInstallSpec(input: unknown): SkillInstallSpec | undefined {
if (typeof raw.formula === "string") spec.formula = raw.formula;
if (typeof raw.package === "string") spec.package = raw.package;
if (typeof raw.module === "string") spec.module = raw.module;
if (typeof raw.command === "string") spec.command = raw.command;
return spec;
}