Skip to content

Commit 40dbb8b

Browse files
authored
Merge pull request #380 from xiaofeilovecoding/fix/skill-digester-commonjs
fix(core): run the skill-digester helper as CommonJS
2 parents 03c7ebb + 7a51820 commit 40dbb8b

3 files changed

Lines changed: 53 additions & 4 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import assert from "node:assert/strict";
2+
import { spawnSync } from "node:child_process";
3+
import { cpSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { dirname, join } from "node:path";
6+
import { test } from "node:test";
7+
import { fileURLToPath } from "node:url";
8+
9+
const skillSource = fileURLToPath(new URL("../../templates/skills/bundled/skill-digester/", import.meta.url));
10+
11+
for (const type of ["module", "commonjs"]) {
12+
test(`skill-digester's documented helper finds skills inside a ${type} package`, () => {
13+
const root = mkdtempSync(join(tmpdir(), "deepcode-skill-digester-"));
14+
try {
15+
const project = join(root, "project");
16+
const home = join(root, "home");
17+
const installed = join(project, ".agents", "skills", "skill-digester");
18+
cpSync(skillSource, installed, { recursive: true });
19+
mkdirSync(home);
20+
writeFileSync(join(project, "package.json"), JSON.stringify({ type }));
21+
const target = join(project, ".agents", "skills", "work-log", "SKILL.md");
22+
mkdirSync(dirname(target), { recursive: true });
23+
writeFileSync(target, '---\nname: worklog\ndescription: "Project work log"\n---\n# Work Log\n');
24+
const instructions = readFileSync(join(installed, "SKILL.md"), "utf8");
25+
const documentedScript = instructions.match(/scripts\/find-skill\.(?:cjs|js)/)?.[0];
26+
assert.ok(documentedScript, "the skill must document its helper entry point");
27+
28+
const result = spawnSync(process.execPath, [join(installed, documentedScript), "worklog", project], {
29+
cwd: project,
30+
encoding: "utf8",
31+
timeout: 10000,
32+
env: { ...process.env, HOME: home, USERPROFILE: home, NODE_PATH: "" },
33+
});
34+
35+
assert.equal(result.status, 0, result.stderr);
36+
const output = JSON.parse(result.stdout);
37+
assert.equal(output.found, true);
38+
assert.equal(output.activeMatches.length, 1);
39+
assert.equal(output.activeMatches[0].path, target);
40+
assert.equal(output.activeMatches[0].description, "Project work log");
41+
assert.equal(
42+
output.activeMatches[0].digestTarget.path,
43+
join(project, ".deepcode", "skills", "work-log", "SKILL.md")
44+
);
45+
} finally {
46+
rmSync(root, { recursive: true, force: true });
47+
}
48+
});
49+
}

‎packages/core/templates/skills/bundled/skill-digester/SKILL.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ First classify the request:
2828
- Locate the skill by running the bundled Node script from this skill directory:
2929

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

34-
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.
34+
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.
3535

3636
- The script searches the same roots Deep Code CLI scans, in priority order:
3737
1. Project native skills: `./.deepcode/skills/<folder>/SKILL.md`
@@ -103,7 +103,7 @@ Use this workflow when the user asks to install an Agent Skill. Installation alw
103103
- `./...` relative to the current project root.
104104
- Absolute paths as written.
105105
- A `SKILL.md` path means its parent directory is the source skill directory.
106-
- 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.
106+
- 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.
107107
- If the user did not provide a skill name or path, use `AskUserQuestion` to ask for the source skill name or path.
108108
- 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.
109109

packages/core/templates/skills/bundled/skill-digester/scripts/find-skill.js renamed to packages/core/templates/skills/bundled/skill-digester/scripts/find-skill.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const os = require("os");
66
const path = require("path");
77

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

1212
function loadMatter() {

0 commit comments

Comments
 (0)