mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 21:03:19 +00:00
The --no-skills flag set options.skills = [] in main.ts, but the
interactive mode UI would rediscover skills anyway because it called
loadSkills() directly instead of using the already-loaded skills.
Changes:
- Add AgentSession.skills and AgentSession.skillWarnings properties
- discoverSkills() now returns { skills, warnings } instead of Skill[]
- Interactive mode uses session.skills instead of calling loadSkills()
- Update SDK docs and examples for new return type
Fixes #577
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { createAgentSession } from "../src/core/sdk.js";
|
|
import { SessionManager } from "../src/core/session-manager.js";
|
|
|
|
describe("createAgentSession skills option", () => {
|
|
let tempDir: string;
|
|
let skillsDir: string;
|
|
|
|
beforeEach(() => {
|
|
tempDir = join(tmpdir(), `pi-sdk-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
skillsDir = join(tempDir, "skills", "test-skill");
|
|
mkdirSync(skillsDir, { recursive: true });
|
|
|
|
// Create a test skill in the pi skills directory
|
|
writeFileSync(
|
|
join(skillsDir, "SKILL.md"),
|
|
`---
|
|
name: test-skill
|
|
description: A test skill for SDK tests.
|
|
---
|
|
|
|
# Test Skill
|
|
|
|
This is a test skill.
|
|
`,
|
|
);
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (tempDir) {
|
|
rmSync(tempDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it("should discover skills by default and expose them on session.skills", async () => {
|
|
const { session } = await createAgentSession({
|
|
cwd: tempDir,
|
|
agentDir: tempDir,
|
|
sessionManager: SessionManager.inMemory(),
|
|
});
|
|
|
|
// Skills should be discovered and exposed on the session
|
|
expect(session.skills.length).toBeGreaterThan(0);
|
|
expect(session.skills.some((s) => s.name === "test-skill")).toBe(true);
|
|
});
|
|
|
|
it("should have empty skills when options.skills is empty array (--no-skills)", async () => {
|
|
const { session } = await createAgentSession({
|
|
cwd: tempDir,
|
|
agentDir: tempDir,
|
|
sessionManager: SessionManager.inMemory(),
|
|
skills: [], // Explicitly empty - like --no-skills
|
|
});
|
|
|
|
// session.skills should be empty
|
|
expect(session.skills).toEqual([]);
|
|
// No warnings since we didn't discover
|
|
expect(session.skillWarnings).toEqual([]);
|
|
});
|
|
|
|
it("should use provided skills when options.skills is explicitly set", async () => {
|
|
const customSkill = {
|
|
name: "custom-skill",
|
|
description: "A custom skill",
|
|
filePath: "/fake/path/SKILL.md",
|
|
baseDir: "/fake/path",
|
|
source: "custom" as const,
|
|
};
|
|
|
|
const { session } = await createAgentSession({
|
|
cwd: tempDir,
|
|
agentDir: tempDir,
|
|
sessionManager: SessionManager.inMemory(),
|
|
skills: [customSkill],
|
|
});
|
|
|
|
// session.skills should contain only the provided skill
|
|
expect(session.skills).toEqual([customSkill]);
|
|
// No warnings since we didn't discover
|
|
expect(session.skillWarnings).toEqual([]);
|
|
});
|
|
});
|