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
49 changes: 49 additions & 0 deletions packages/core/src/tests/skill-digester.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { cpSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";

const skillSource = fileURLToPath(new URL("../../templates/skills/bundled/skill-digester/", import.meta.url));

for (const type of ["module", "commonjs"]) {
test(`skill-digester's documented helper finds skills inside a ${type} package`, () => {
const root = mkdtempSync(join(tmpdir(), "deepcode-skill-digester-"));
try {
const project = join(root, "project");
const home = join(root, "home");
const installed = join(project, ".agents", "skills", "skill-digester");
cpSync(skillSource, installed, { recursive: true });
mkdirSync(home);
writeFileSync(join(project, "package.json"), JSON.stringify({ type }));
const target = join(project, ".agents", "skills", "work-log", "SKILL.md");
mkdirSync(dirname(target), { recursive: true });
writeFileSync(target, '---\nname: worklog\ndescription: "Project work log"\n---\n# Work Log\n');
const instructions = readFileSync(join(installed, "SKILL.md"), "utf8");
const documentedScript = instructions.match(/scripts\/find-skill\.(?:cjs|js)/)?.[0];
assert.ok(documentedScript, "the skill must document its helper entry point");

const result = spawnSync(process.execPath, [join(installed, documentedScript), "worklog", project], {
cwd: project,
encoding: "utf8",
timeout: 10000,
env: { ...process.env, HOME: home, USERPROFILE: home, NODE_PATH: "" },
});

assert.equal(result.status, 0, result.stderr);
const output = JSON.parse(result.stdout);
assert.equal(output.found, true);
assert.equal(output.activeMatches.length, 1);
assert.equal(output.activeMatches[0].path, target);
assert.equal(output.activeMatches[0].description, "Project work log");
assert.equal(
output.activeMatches[0].digestTarget.path,
join(project, ".deepcode", "skills", "work-log", "SKILL.md")
);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ First classify the request:
- Locate the skill by running the bundled Node script from this skill directory:

```bash
node ~/.deepcode/skills/skill-digester/scripts/find-skill.js "<skill-name-or-path>" "<project-root>"
node ~/.deepcode/skills/skill-digester/scripts/find-skill.cjs "<skill-name-or-path>" "<project-root>"
```

If this skill is loaded from a project-level or different user-level path, use the `scripts/find-skill.js` file next to this `SKILL.md` instead.
If this skill is loaded from a project-level or different user-level path, use the `scripts/find-skill.cjs` file next to this `SKILL.md` instead.

- The script searches the same roots Deep Code CLI scans, in priority order:
1. Project native skills: `./.deepcode/skills/<folder>/SKILL.md`
Expand Down Expand Up @@ -103,7 +103,7 @@ Use this workflow when the user asks to install an Agent Skill. Installation alw
- `./...` relative to the current project root.
- Absolute paths as written.
- A `SKILL.md` path means its parent directory is the source skill directory.
- If the user provided a skill name instead of a path, locate it with `scripts/find-skill.js` using the same command and match rules as the digest workflow.
- If the user provided a skill name instead of a path, locate it with `scripts/find-skill.cjs` using the same command and match rules as the digest workflow.
- If the user did not provide a skill name or path, use `AskUserQuestion` to ask for the source skill name or path.
- The source directory must contain `SKILL.md`. If it does not, report that the path is not an Agent Skill and ask for another source only if the user still wants to install.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const os = require("os");
const path = require("path");

function usage() {
return "Usage: node scripts/find-skill.js <skill-name-or-path> [project-root]";
return "Usage: node scripts/find-skill.cjs <skill-name-or-path> [project-root]";
}

function loadMatter() {
Expand Down
Loading