mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 00:54:33 +00:00
refactor(agent): dedupe harness and command workflows
This commit is contained in:
@@ -24,6 +24,70 @@ import { buildWorkspaceSkillStatus } from "../agents/skills-status.js";
|
||||
import { detectBinary } from "./onboard-helpers.js";
|
||||
import { setupSkills } from "./onboard-skills.js";
|
||||
|
||||
function createBundledSkill(params: {
|
||||
name: string;
|
||||
description: string;
|
||||
bins: string[];
|
||||
os?: string[];
|
||||
installLabel: string;
|
||||
}): {
|
||||
name: string;
|
||||
description: string;
|
||||
source: string;
|
||||
bundled: boolean;
|
||||
filePath: string;
|
||||
baseDir: string;
|
||||
skillKey: string;
|
||||
always: boolean;
|
||||
disabled: boolean;
|
||||
blockedByAllowlist: boolean;
|
||||
eligible: boolean;
|
||||
requirements: {
|
||||
bins: string[];
|
||||
anyBins: string[];
|
||||
env: string[];
|
||||
config: string[];
|
||||
os: string[];
|
||||
};
|
||||
missing: { bins: string[]; anyBins: string[]; env: string[]; config: string[]; os: string[] };
|
||||
configChecks: [];
|
||||
install: Array<{ id: string; kind: string; label: string; bins: string[] }>;
|
||||
} {
|
||||
return {
|
||||
name: params.name,
|
||||
description: params.description,
|
||||
source: "openclaw-bundled",
|
||||
bundled: true,
|
||||
filePath: `/tmp/skills/${params.name}`,
|
||||
baseDir: `/tmp/skills/${params.name}`,
|
||||
skillKey: params.name,
|
||||
always: false,
|
||||
disabled: false,
|
||||
blockedByAllowlist: false,
|
||||
eligible: false,
|
||||
requirements: { bins: params.bins, anyBins: [], env: [], config: [], os: params.os ?? [] },
|
||||
missing: { bins: params.bins, anyBins: [], env: [], config: [], os: params.os ?? [] },
|
||||
configChecks: [],
|
||||
install: [{ id: "brew", kind: "brew", label: params.installLabel, bins: params.bins }],
|
||||
};
|
||||
}
|
||||
|
||||
function mockMissingBrewStatus(skills: Array<ReturnType<typeof createBundledSkill>>): void {
|
||||
vi.mocked(detectBinary).mockResolvedValue(false);
|
||||
vi.mocked(installSkill).mockResolvedValue({
|
||||
ok: true,
|
||||
message: "Installed",
|
||||
stdout: "",
|
||||
stderr: "",
|
||||
code: 0,
|
||||
});
|
||||
vi.mocked(buildWorkspaceSkillStatus).mockReturnValue({
|
||||
workspaceDir: "/tmp/ws",
|
||||
managedSkillsDir: "/tmp/managed",
|
||||
skills,
|
||||
});
|
||||
}
|
||||
|
||||
function createPrompter(params: {
|
||||
configure?: boolean;
|
||||
showBrewInstall?: boolean;
|
||||
@@ -69,56 +133,21 @@ describe("setupSkills", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
vi.mocked(detectBinary).mockResolvedValue(false);
|
||||
vi.mocked(installSkill).mockResolvedValue({
|
||||
ok: true,
|
||||
message: "Installed",
|
||||
stdout: "",
|
||||
stderr: "",
|
||||
code: 0,
|
||||
});
|
||||
vi.mocked(buildWorkspaceSkillStatus).mockReturnValue({
|
||||
workspaceDir: "/tmp/ws",
|
||||
managedSkillsDir: "/tmp/managed",
|
||||
skills: [
|
||||
{
|
||||
name: "apple-reminders",
|
||||
description: "macOS-only",
|
||||
source: "openclaw-bundled",
|
||||
bundled: true,
|
||||
filePath: "/tmp/skills/apple-reminders",
|
||||
baseDir: "/tmp/skills/apple-reminders",
|
||||
skillKey: "apple-reminders",
|
||||
always: false,
|
||||
disabled: false,
|
||||
blockedByAllowlist: false,
|
||||
eligible: false,
|
||||
requirements: { bins: ["remindctl"], anyBins: [], env: [], config: [], os: ["darwin"] },
|
||||
missing: { bins: ["remindctl"], anyBins: [], env: [], config: [], os: ["darwin"] },
|
||||
configChecks: [],
|
||||
install: [
|
||||
{ id: "brew", kind: "brew", label: "Install remindctl (brew)", bins: ["remindctl"] },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "video-frames",
|
||||
description: "ffmpeg",
|
||||
source: "openclaw-bundled",
|
||||
bundled: true,
|
||||
filePath: "/tmp/skills/video-frames",
|
||||
baseDir: "/tmp/skills/video-frames",
|
||||
skillKey: "video-frames",
|
||||
always: false,
|
||||
disabled: false,
|
||||
blockedByAllowlist: false,
|
||||
eligible: false,
|
||||
requirements: { bins: ["ffmpeg"], anyBins: [], env: [], config: [], os: [] },
|
||||
missing: { bins: ["ffmpeg"], anyBins: [], env: [], config: [], os: [] },
|
||||
configChecks: [],
|
||||
install: [{ id: "brew", kind: "brew", label: "Install ffmpeg (brew)", bins: ["ffmpeg"] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
mockMissingBrewStatus([
|
||||
createBundledSkill({
|
||||
name: "apple-reminders",
|
||||
description: "macOS-only",
|
||||
bins: ["remindctl"],
|
||||
os: ["darwin"],
|
||||
installLabel: "Install remindctl (brew)",
|
||||
}),
|
||||
createBundledSkill({
|
||||
name: "video-frames",
|
||||
description: "ffmpeg",
|
||||
bins: ["ffmpeg"],
|
||||
installLabel: "Install ffmpeg (brew)",
|
||||
}),
|
||||
]);
|
||||
|
||||
const { prompter, notes } = createPrompter({ multiselect: ["__skip__"] });
|
||||
await setupSkills({} as OpenClawConfig, "/tmp/ws", runtime, prompter);
|
||||
@@ -136,37 +165,14 @@ describe("setupSkills", () => {
|
||||
return;
|
||||
}
|
||||
|
||||
vi.mocked(detectBinary).mockResolvedValue(false);
|
||||
vi.mocked(installSkill).mockResolvedValue({
|
||||
ok: true,
|
||||
message: "Installed",
|
||||
stdout: "",
|
||||
stderr: "",
|
||||
code: 0,
|
||||
});
|
||||
vi.mocked(buildWorkspaceSkillStatus).mockReturnValue({
|
||||
workspaceDir: "/tmp/ws",
|
||||
managedSkillsDir: "/tmp/managed",
|
||||
skills: [
|
||||
{
|
||||
name: "video-frames",
|
||||
description: "ffmpeg",
|
||||
source: "openclaw-bundled",
|
||||
bundled: true,
|
||||
filePath: "/tmp/skills/video-frames",
|
||||
baseDir: "/tmp/skills/video-frames",
|
||||
skillKey: "video-frames",
|
||||
always: false,
|
||||
disabled: false,
|
||||
blockedByAllowlist: false,
|
||||
eligible: false,
|
||||
requirements: { bins: ["ffmpeg"], anyBins: [], env: [], config: [], os: [] },
|
||||
missing: { bins: ["ffmpeg"], anyBins: [], env: [], config: [], os: [] },
|
||||
configChecks: [],
|
||||
install: [{ id: "brew", kind: "brew", label: "Install ffmpeg (brew)", bins: ["ffmpeg"] }],
|
||||
},
|
||||
],
|
||||
});
|
||||
mockMissingBrewStatus([
|
||||
createBundledSkill({
|
||||
name: "video-frames",
|
||||
description: "ffmpeg",
|
||||
bins: ["ffmpeg"],
|
||||
installLabel: "Install ffmpeg (brew)",
|
||||
}),
|
||||
]);
|
||||
|
||||
const { prompter, notes } = createPrompter({ multiselect: ["video-frames"] });
|
||||
await setupSkills({} as OpenClawConfig, "/tmp/ws", runtime, prompter);
|
||||
|
||||
Reference in New Issue
Block a user