Skip to content
Closed
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
38 changes: 38 additions & 0 deletions apps/cli/src/commands/skills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Cli, SyncSkills } from "incur";
import { createLocalCli } from "../local-cli.js";
import { createStartCli } from "../start-cli.js";
import { CLI_METADATA } from "./registry.js";

type CommandEntry = NonNullable<ReturnType<(typeof Cli.toCommands)["get"]>> extends Map<
string,
infer V
>
? V
: never;

/** Merges every registered command (start + local groups) into one incur command map. */
export async function buildCommandMap(): Promise<Map<string, CommandEntry>> {
const merged = new Map<string, CommandEntry>();
for (const cli of [await createStartCli(), await createLocalCli()]) {
const commands = Cli.toCommands.get(cli);
if (!commands) continue;
for (const [name, entry] of commands) {
merged.set(name, entry);
}
}
return merged;
}

/** Generates skill files from the full command surface and installs them natively. */
export async function runSkillsAdd(): Promise<void> {
const commands = await buildCommandMap();
const result = await SyncSkills.sync(CLI_METADATA.name, commands, {
description: CLI_METADATA.description,
});

const count = result.skills.length;
process.stdout.write(`${count} skill${count === 1 ? "" : "s"} synced\n`);
for (const path of result.paths) {
process.stdout.write(` ${path}\n`);
}
}
20 changes: 16 additions & 4 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ async function run(argv = process.argv.slice(2)): Promise<void> {
return;
}

if (command === "skills") {
if (argv[1] === "add") {
const { runSkillsAdd } = await import("./commands/skills.js");
await runSkillsAdd();
return;
}
process.stdout.write(`Usage:\n ${CLI_METADATA.name} skills add\n`);
return;
}

if (entry?.group === "local") {
const { createLocalCli } = await import("./local-cli.js");
await (await createLocalCli()).serve(argv);
Expand Down Expand Up @@ -49,10 +59,12 @@ Options:
}

function formatCommandHelp(): string {
const width = Math.max(...COMMAND_REGISTRY.map((command) => command.name.length));
return COMMAND_REGISTRY.map(
(command) => ` ${command.name.padEnd(width)} ${command.summary}`,
).join("\n");
const entries = [
...COMMAND_REGISTRY.map((command) => ({ name: command.name, summary: command.summary })),
{ name: "skills add", summary: "Sync skill files to your agent" },
];
const width = Math.max(...entries.map((entry) => entry.name.length));
return entries.map((entry) => ` ${entry.name.padEnd(width)} ${entry.summary}`).join("\n");
}

run().catch((error) => {
Expand Down
13 changes: 13 additions & 0 deletions apps/cli/test/skills.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from "vitest";
import { buildCommandMap } from "../src/commands/skills.js";

describe("buildCommandMap", () => {
it("includes every registered command across both groups", async () => {
const commands = await buildCommandMap();
const names = [...commands.keys()].sort();

expect(names).toEqual(
["clean", "init", "logs", "snapshot", "start", "status", "stop"].sort(),
);
});
});
Loading