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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Default scope: `vanta-api.all:read vanta-api.all:write`

## Quick start

For guided agent workflows, run `vanta skills list`, then `vanta skills read --name <name>`.

```bash
# List controls
vanta controls list --page-size 50
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
"type": "module",
"scripts": {
"generate": "openapi-ts",
"dev": "tsx src/cli.ts",
"dev": "node --import ./scripts/text-loader.mjs --import tsx src/cli.ts",
"build": "pnpm run generate && tsup",
"typecheck": "tsc --noEmit",
"test": "node --import tsx --test 'src/**/*.test.ts'",
"test": "node --import ./scripts/text-loader.mjs --import tsx --test 'src/**/*.test.ts'",
"build:binaries": "tsx scripts/build-binaries.ts",
"format": "oxfmt",
"format:check": "oxfmt --check"
},
"dependencies": {
"@napi-rs/keyring": "^1.3.0",
"@toon-format/toon": "^4.4.0",
"commander": "^14.0.0"
"commander": "^14.0.0",
"yaml": "^2.9.1"
},
"devDependencies": {
"@hey-api/openapi-ts": "^0.99.0",
Expand Down
19 changes: 15 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/build-binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ async function main(): Promise<void> {
"build",
"--compile",
`--target=${target.bun}`,
"--loader=.md:text",
"--define",
`__VANTA_VERSION__=${JSON.stringify(version)}`,
"--outfile",
Expand Down
17 changes: 17 additions & 0 deletions scripts/text-loader.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFileSync } from "node:fs";
import { register } from "node:module";
import { isMainThread } from "node:worker_threads";

// Match the bundlers' text imports when running source with Node.
if (isMainThread) register(import.meta.url);

export function load(url, context, nextLoad) {
if (url.endsWith(".md")) {
return {
format: "module",
shortCircuit: true,
source: `export default ${JSON.stringify(readFileSync(new URL(url), "utf8"))}`,
};
}
return nextLoad(url, context);
}
9 changes: 8 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { registerApiCommands } from "./commands/index.js";
import { registerLoginCommand } from "./commands/login.js";
import { registerLogoutCommand } from "./commands/logout.js";
import { registerVersionCommand } from "./commands/version.js";
import { registerSkillsCommand } from "./commands/skills.js";
import {
finishBackgroundUpdateCheck,
startBackgroundUpdateCheck,
Expand Down Expand Up @@ -46,6 +47,10 @@ function buildProgram(): Command {
.option(
"--scope <scope>",
"OAuth scope (default: vanta-api.all:read vanta-api.all:write)",
)
.addHelpText(
"after",
'\nRun "vanta skills list" to discover skills that can help you use the CLI for certain tasks.',
);

const getFlags = (): GlobalFlags => {
Expand Down Expand Up @@ -74,7 +79,8 @@ function buildProgram(): Command {
};
};

program.hook("preAction", () => {
program.hook("preAction", (_command, actionCommand) => {
if (actionCommand.parent?.name() === "skills") return;
startBackgroundUpdateCheck({ agentMode: getFlags().agentMode });
});
program.hook("postAction", async () => {
Expand All @@ -84,6 +90,7 @@ function buildProgram(): Command {
registerLoginCommand(program, getFlags);
registerLogoutCommand(program, getFlags);
registerVersionCommand(program);
registerSkillsCommand(program);
registerApiCommands(program, getFlags);

return program;
Expand Down
92 changes: 92 additions & 0 deletions src/commands/skills.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import assert from "node:assert/strict";
import { readFile, readdir } from "node:fs/promises";
import { describe, it } from "node:test";
import { Command } from "commander";
import { registerSkillsCommand } from "./skills.js";

async function runSkills(args: string[]): Promise<string> {
const program = new Command()
.exitOverride()
.configureOutput({ writeErr: () => {} });
registerSkillsCommand(program);
const output: string[] = [];
const log = console.log;
console.log = (text: string) => output.push(text);
try {
await program.parseAsync(["node", "vanta", "skills", ...args]);
} finally {
console.log = log;
}
return output.join("\n");
}

describe("bundled skills", () => {
const root = new URL("../../skills/", import.meta.url);

it("lists every skill without loading its instructions", async () => {
const output = await runSkills(["list"]);
for (const entry of await readdir(root, { withFileTypes: true })) {
if (entry.isDirectory()) assert.ok(output.includes(`${entry.name}\n`));
}
assert.ok(!output.includes("# Test Remediation Digest"));
});

it("returns complete source instructions and references without credentials or network access", async () => {
const fetch = globalThis.fetch;
globalThis.fetch = () => {
throw new Error("Skills must not access the network");
};
try {
for (const entry of await readdir(root, { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
const output = await runSkills(["read", "--name", entry.name]);
const content = await readFile(
new URL(`${entry.name}/SKILL.md`, root),
"utf8",
);
assert.ok(
output.includes(content.trimEnd()),
`${entry.name} is complete`,
);
const references = new URL(`${entry.name}/references/`, root);
const files = await readdir(references).catch(
(error: NodeJS.ErrnoException) => {
if (error.code === "ENOENT") return [];
throw error;
},
);
for (const file of files) {
assert.ok(output.includes(`references/${file}`));
assert.ok(
output.includes(
(await readFile(new URL(file, references), "utf8")).trimEnd(),
),
`${entry.name}/${file} is complete`,
);
}
}
} finally {
globalThis.fetch = fetch;
}
});

it("requires a skill name flag", async () => {
await assert.rejects(
runSkills(["read"]),
/required option '--name <name>'/,
);
await assert.rejects(
runSkills(["read", "vanta"]),
/required option '--name <name>'/,
);
});

it("rejects unknown names and file paths with discovery guidance", async () => {
for (const name of ["missing", "../../README.md", "__proto__"]) {
await assert.rejects(
runSkills(["read", "--name", name]),
/Unknown skill .*vanta skills list/,
);
}
});
});
48 changes: 48 additions & 0 deletions src/commands/skills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { Command } from "commander";
import { bundledSkills } from "../skills.js";

const guidance = `Load a skill's instructions to learn how to use it:
vanta skills read --name <name>
You can load multiple skills; each call returns one skill's instructions and
references. Follow the loaded instructions when carrying out the task.
To describe a skill, use its catalog description instead of loading it.`;

export function registerSkillsCommand(program: Command): void {
const skills = program
.command("skills")
.description("Load skill instructions for a task")
.addHelpText("after", `\n${guidance}`);

skills
.command("list")
.description("List available skills and when to use them")
.action(() => {
console.log(`${guidance}\n\nAvailable skills:\n`);
for (const skill of bundledSkills) {
console.log(`${skill.name}\n ${skill.description}\n`);
}
});

skills
.command("read")
.description("Read a skill's full instructions and bundled references")
.requiredOption("--name <name>", "Skill name from vanta skills list")
.addHelpText(
"after",
"\nExample:\n vanta skills read --name test-remediation-digest\n\nPrints Markdown instructions; does not execute a workflow or call the API.",
)
.action((options: { name: string }) => {
const skill = bundledSkills.find((entry) => entry.name === options.name);
if (!skill) {
throw new Error(
`Unknown skill ${JSON.stringify(options.name)}. Run "vanta skills list" to see available names.`,
);
}
console.log(skill.content.trimEnd());
for (const reference of skill.references) {
console.log(
`\n# Bundled reference: ${reference.path}\n\n${reference.content.trimEnd()}`,
);
}
});
}
57 changes: 57 additions & 0 deletions src/skills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { parse } from "yaml";
import computerSecurity from "../skills/computer-security-blocker-explainer/SKILL.md";
import controlTesting from "../skills/control-testing-procedures/SKILL.md";
import personnel from "../skills/personnel-report/SKILL.md";
import mitigatingControls from "../skills/suggest-mitigating-controls/SKILL.md";
import riskScenarios from "../skills/suggest-risk-scenarios/SKILL.md";
import taxonomy from "../skills/suggest-risk-scenarios/references/scenario-taxonomy.md";
import remediation from "../skills/test-remediation-digest/SKILL.md";
import fixStyle from "../skills/test-remediation-digest/references/how-to-fix-style.md";
import unassignedControls from "../skills/unassigned-controls-report/SKILL.md";
import vanta from "../skills/vanta/SKILL.md";
import vulnerabilityTriage from "../skills/weekly-vulnerability-triage/SKILL.md";

type SkillSource = {
content: string;
references?: { path: string; content: string }[];
};

export const bundledSkills = (
[
{ content: computerSecurity },
{ content: controlTesting },
{ content: personnel },
{ content: mitigatingControls },
{
content: riskScenarios,
references: [
{ path: "references/scenario-taxonomy.md", content: taxonomy },
],
},
{
content: remediation,
references: [
{ path: "references/how-to-fix-style.md", content: fixStyle },
],
},
{ content: unassignedControls },
{ content: vanta },
{ content: vulnerabilityTriage },
] satisfies SkillSource[]
).map(({ content, references = [] }) => {
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
if (!frontmatter) throw new Error("Missing skill frontmatter");
const metadata = parse(frontmatter[1]);
if (
typeof metadata?.name !== "string" ||
typeof metadata?.description !== "string"
) {
throw new Error("Invalid skill name or description");
}
return {
name: metadata.name,
description: metadata.description.trim(),
content,
references,
};
});
4 changes: 4 additions & 0 deletions src/text.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.md" {
const content: string;
export default content;
}
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
outDir: "dist",
clean: true,
sourcemap: true,
loader: { ".md": "text" },
banner: {
js: "#!/usr/bin/env node",
},
Expand Down