cdspec 0.1.0 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +86 -33
  2. package/dist/cli.js +1 -93
  3. package/dist/config/default.js +1 -48
  4. package/dist/config/loader.js +1 -30
  5. package/dist/config/path.js +1 -11
  6. package/dist/config/types.js +1 -1
  7. package/dist/skill-core/adapters/claudecode-adapter.js +1 -35
  8. package/dist/skill-core/adapters/codex-adapter.js +1 -28
  9. package/dist/skill-core/adapters/iflow-adapter.js +1 -39
  10. package/dist/skill-core/adapters/index.js +1 -34
  11. package/dist/skill-core/adapters/shared.js +1 -36
  12. package/dist/skill-core/manifest-loader.js +1 -63
  13. package/dist/skill-core/scaffold.js +1 -169
  14. package/dist/skill-core/service.js +1 -156
  15. package/dist/skill-core/tool-interactions.js +1 -70
  16. package/dist/skill-core/types.js +1 -1
  17. package/dist/skill-core/validator.js +1 -25
  18. package/dist/utils/frontmatter.js +1 -40
  19. package/dist/utils/fs.js +1 -37
  20. package/package.json +12 -2
  21. package/templates/{standards-backend → backend-standard}/SKILL.md +55 -55
  22. package/templates/backend-standard/agents/openai.yaml +4 -0
  23. package/templates/{standards-backend → backend-standard}/references/DDD/346/236/266/346/236/204/347/272/246/346/235/237.md +103 -103
  24. package/templates/{standards-backend → backend-standard}/references/JUC/345/271/266/345/217/221/350/247/204/350/214/203.md +232 -232
  25. package/templates/{standards-backend → backend-standard}/references//344/274/240/347/273/237/344/270/211/345/261/202/346/236/266/346/236/204/347/272/246/346/235/237.md +35 -35
  26. package/templates/{standards-backend → backend-standard}/references//345/220/216/347/253/257/345/274/200/345/217/221/350/247/204/350/214/203.md +49 -49
  27. package/templates/{standards-backend → backend-standard}/references//346/225/260/346/215/256/345/272/223/350/256/276/350/256/241/350/247/204/350/214/203.md +116 -116
  28. package/templates/{standards-backend → backend-standard}/references//350/256/276/350/256/241/346/250/241/345/274/217/350/220/275/345/234/260/346/211/213/345/206/214.md +395 -395
  29. package/templates/{frontend-develop-standard → frontend-standard}/SKILL.md +63 -63
  30. package/templates/frontend-standard/agents/openai.yaml +4 -0
  31. package/templates/{frontend-develop-standard/references/frontend_develop_standard.md → frontend-standard/references/frontend_standard.md} +28 -321
  32. package/AGENTS.md +0 -14
  33. package/CLAUDE.md +0 -10
  34. package/dist/skill-core/agent-config.js +0 -40
  35. package/dist/task-core/parser.js +0 -70
  36. package/dist/task-core/service.js +0 -28
  37. package/dist/task-core/storage.js +0 -159
  38. package/dist/task-core/types.js +0 -1
  39. package/src/cli.ts +0 -105
  40. package/src/config/default.ts +0 -51
  41. package/src/config/loader.ts +0 -37
  42. package/src/config/path.ts +0 -13
  43. package/src/config/types.ts +0 -22
  44. package/src/skill-core/adapters/claudecode-adapter.ts +0 -45
  45. package/src/skill-core/adapters/codex-adapter.ts +0 -36
  46. package/src/skill-core/adapters/iflow-adapter.ts +0 -49
  47. package/src/skill-core/adapters/index.ts +0 -39
  48. package/src/skill-core/adapters/shared.ts +0 -45
  49. package/src/skill-core/manifest-loader.ts +0 -79
  50. package/src/skill-core/scaffold.ts +0 -192
  51. package/src/skill-core/service.ts +0 -199
  52. package/src/skill-core/tool-interactions.ts +0 -95
  53. package/src/skill-core/types.ts +0 -22
  54. package/src/skill-core/validator.ts +0 -28
  55. package/src/task-core/parser.ts +0 -89
  56. package/src/task-core/service.ts +0 -49
  57. package/src/task-core/storage.ts +0 -177
  58. package/src/task-core/types.ts +0 -15
  59. package/src/types/yaml.d.ts +0 -4
  60. package/src/utils/frontmatter.ts +0 -55
  61. package/src/utils/fs.ts +0 -41
  62. package/templates/frontend-develop-standard/agents/openai.yaml +0 -4
  63. package/templates/standards-backend/agents/openai.yaml +0 -4
  64. package/tests/skill.test.ts +0 -191
  65. package/tests/task.test.ts +0 -55
  66. package/tsconfig.json +0 -16
  67. package/vitest.config.ts +0 -9
@@ -1,45 +0,0 @@
1
- import { copyFile, readFile, readdir, writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { ensureDir, pathExists } from "../../utils/fs.js";
4
- import { SkillManifest } from "../types.js";
5
-
6
- export async function emitWithLayout(
7
- manifest: SkillManifest,
8
- outDir: string,
9
- includeOriginalSkillMd: boolean,
10
- generatedFiles: Array<{ relativePath: string; content: string }>
11
- ): Promise<void> {
12
- await ensureDir(outDir);
13
- if (includeOriginalSkillMd) {
14
- const srcSkillMd = path.join(manifest.sourcePath, "SKILL.md");
15
- await copyFile(srcSkillMd, path.join(outDir, "SKILL.md"));
16
- }
17
-
18
- for (const file of generatedFiles) {
19
- const targetFile = path.join(outDir, file.relativePath);
20
- await ensureDir(path.dirname(targetFile));
21
- await writeFile(targetFile, file.content, "utf8");
22
- }
23
-
24
- const folders = ["agents", "references", "scripts", "assets"];
25
- for (const folder of folders) {
26
- const sourceFolder = path.join(manifest.sourcePath, folder);
27
- if (!(await pathExists(sourceFolder))) continue;
28
- await copyFolder(sourceFolder, path.join(outDir, folder));
29
- }
30
- }
31
-
32
- async function copyFolder(srcDir: string, dstDir: string): Promise<void> {
33
- await ensureDir(dstDir);
34
- const entries = await readdir(srcDir, { withFileTypes: true });
35
- for (const entry of entries) {
36
- const src = path.join(srcDir, entry.name);
37
- const dst = path.join(dstDir, entry.name);
38
- if (entry.isDirectory()) {
39
- await copyFolder(src, dst);
40
- continue;
41
- }
42
- const data = await readFile(src);
43
- await writeFile(dst, data);
44
- }
45
- }
@@ -1,79 +0,0 @@
1
- import { readdir, readFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { parseFrontmatter } from "../utils/frontmatter.js";
4
- import { listDirs, pathExists } from "../utils/fs.js";
5
- import { SkillManifest } from "./types.js";
6
-
7
- const CODEX_DIR = ".codex";
8
-
9
- export async function loadAllSkillManifests(cwd: string): Promise<SkillManifest[]> {
10
- const sourceRoot = path.join(cwd, CODEX_DIR);
11
- const skillDirs = await listDirs(sourceRoot);
12
- const manifests: SkillManifest[] = [];
13
- for (const dirName of skillDirs) {
14
- const fullPath = path.join(sourceRoot, dirName);
15
- const manifest = await loadSkillManifest(fullPath);
16
- if (manifest) manifests.push(manifest);
17
- }
18
- return manifests;
19
- }
20
-
21
- export async function loadSkillManifestByName(
22
- cwd: string,
23
- name: string
24
- ): Promise<SkillManifest | null> {
25
- return loadSkillManifest(path.join(cwd, CODEX_DIR, name));
26
- }
27
-
28
- async function loadSkillManifest(skillDir: string): Promise<SkillManifest | null> {
29
- const skillMdPath = path.join(skillDir, "SKILL.md");
30
- if (!(await pathExists(skillMdPath))) return null;
31
-
32
- const content = await readFile(skillMdPath, "utf8");
33
- const parsed = parseFrontmatter(content);
34
- const frontName = parsed.attributes.name?.trim();
35
- const frontDescription = parsed.attributes.description?.trim();
36
- const displayName = frontName || path.basename(skillDir);
37
-
38
- const agents = await collectRelativeFiles(path.join(skillDir, "agents"), "agents");
39
- const resources = await collectRelativeFiles(path.join(skillDir, "references"), "references");
40
- const scripts = await collectRelativeFiles(path.join(skillDir, "scripts"), "scripts");
41
- const assets = await collectRelativeFiles(path.join(skillDir, "assets"), "assets");
42
-
43
- return {
44
- name: displayName,
45
- description: frontDescription || "",
46
- body: parsed.body.trim(),
47
- agents,
48
- resources: [...resources, ...scripts, ...assets],
49
- sourcePath: skillDir
50
- };
51
- }
52
-
53
- async function collectRelativeFiles(
54
- dirPath: string,
55
- prefix: string
56
- ): Promise<string[]> {
57
- if (!(await pathExists(dirPath))) return [];
58
- const result: string[] = [];
59
- await walk(dirPath, (absolutePath) => {
60
- const relative = path.relative(path.dirname(dirPath), absolutePath);
61
- result.push(relative.replaceAll("\\", "/").replace(`${prefix}/./`, `${prefix}/`));
62
- });
63
- return result;
64
- }
65
-
66
- async function walk(
67
- dirPath: string,
68
- onFile: (absolutePath: string) => void
69
- ): Promise<void> {
70
- const entries = await readdir(dirPath, { withFileTypes: true });
71
- for (const entry of entries) {
72
- const absolute = path.join(dirPath, entry.name);
73
- if (entry.isDirectory()) {
74
- await walk(absolute, onFile);
75
- continue;
76
- }
77
- onFile(absolute);
78
- }
79
- }
@@ -1,192 +0,0 @@
1
- import { mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { fileURLToPath } from "node:url";
5
- import { parseFrontmatter } from "../utils/frontmatter.js";
6
- import { ensureDir, listDirs, pathExists } from "../utils/fs.js";
7
- import { SkillManifest } from "./types.js";
8
-
9
- const DEFAULT_SKILL_NAME = "openspec-core";
10
- const BUILTIN_TEMPLATE_DIR = path.resolve(
11
- path.dirname(fileURLToPath(import.meta.url)),
12
- "../../templates/default-skill"
13
- );
14
-
15
- export async function cleanupLegacyDefaultSkillDir(cwd: string): Promise<void> {
16
- await rm(path.join(cwd, ".codex", DEFAULT_SKILL_NAME), { recursive: true, force: true });
17
- await rm(path.join(cwd, ".cdspec", "seed-skills"), { recursive: true, force: true });
18
- }
19
-
20
- export async function loadDefaultSkillManifest(cwd: string): Promise<SkillManifest> {
21
- const projectTemplateManifests = await loadProjectTemplateManifests(cwd);
22
- if (projectTemplateManifests.length > 0) return projectTemplateManifests[0];
23
-
24
- if (await pathExists(path.join(BUILTIN_TEMPLATE_DIR, "SKILL.md"))) {
25
- return buildManifestFromDir(BUILTIN_TEMPLATE_DIR);
26
- }
27
- const tempDir = await buildFallbackTemplateInTemp();
28
- return buildManifestFromDir(tempDir);
29
- }
30
-
31
- export async function loadProjectTemplateManifests(cwd: string): Promise<SkillManifest[]> {
32
- return loadFromProjectTemplates(path.join(cwd, "templates"));
33
- }
34
-
35
- async function buildManifestFromDir(skillDir: string): Promise<SkillManifest> {
36
- const raw = await readFile(path.join(skillDir, "SKILL.md"), "utf8");
37
- const parsed = parseFrontmatter(raw);
38
- const name = parsed.attributes.name?.trim() || DEFAULT_SKILL_NAME;
39
- const description = parsed.attributes.description?.trim() || "OpenSpec default skill";
40
- const agents = await collectRelativeFiles(path.join(skillDir, "agents"));
41
- const references = await collectRelativeFiles(path.join(skillDir, "references"));
42
- const scripts = await collectRelativeFiles(path.join(skillDir, "scripts"));
43
- const assets = await collectRelativeFiles(path.join(skillDir, "assets"));
44
- return {
45
- name,
46
- description,
47
- body: parsed.body.trim(),
48
- agents,
49
- resources: [...references, ...scripts, ...assets],
50
- sourcePath: skillDir
51
- };
52
- }
53
-
54
- async function collectRelativeFiles(dirPath: string): Promise<string[]> {
55
- if (!(await pathExists(dirPath))) return [];
56
- const base = path.dirname(dirPath);
57
- const result: string[] = [];
58
- const dirs = [dirPath];
59
- while (dirs.length > 0) {
60
- const current = dirs.pop()!;
61
- const children = await listDirs(current);
62
- for (const child of children) {
63
- dirs.push(path.join(current, child));
64
- }
65
- const entries = await readdir(current, { withFileTypes: true });
66
- for (const entry of entries) {
67
- if (!entry.isFile()) continue;
68
- const fullPath = path.join(current, entry.name);
69
- result.push(path.relative(base, fullPath).replaceAll("\\", "/"));
70
- }
71
- }
72
- return result;
73
- }
74
-
75
- async function buildFallbackTemplateInTemp(): Promise<string> {
76
- const root = await mkdtemp(path.join(os.tmpdir(), "cdspec-skill-"));
77
- await ensureDir(path.join(root, "agents"));
78
- await ensureDir(path.join(root, "references"));
79
- const skillMd = [
80
- "---",
81
- "name: openspec-core",
82
- "description: OpenSpec-style change workflow skill. Use for proposing, exploring, applying, and archiving spec-driven changes.",
83
- "---",
84
- "",
85
- "# OpenSpec Core Skill",
86
- "",
87
- "1. /opsx-propose",
88
- "2. /opsx-explore",
89
- "3. /opsx-apply",
90
- "4. /opsx-archive"
91
- ].join("\n");
92
- const openaiYaml = [
93
- "interface:",
94
- ' display_name: "OpenSpec Core"',
95
- ' short_description: "Spec-driven change workflow with propose/explore/apply/archive"',
96
- ' default_prompt: "Use $openspec-core to run OpenSpec-style workflows in this repository."'
97
- ].join("\n");
98
- await writeFile(path.join(root, "SKILL.md"), `${skillMd}\n`, "utf8");
99
- await writeFile(path.join(root, "agents", "openai.yaml"), `${openaiYaml}\n`, "utf8");
100
- await writeFile(path.join(root, "references", "project_notes.md"), "# OpenSpec Workflow Notes\n");
101
- return root;
102
- }
103
-
104
- async function loadFromProjectTemplates(templateRoot: string): Promise<SkillManifest[]> {
105
- if (!(await pathExists(templateRoot))) return [];
106
- const manifests: SkillManifest[] = [];
107
-
108
- const childDirs = await listDirs(templateRoot);
109
- for (const child of childDirs) {
110
- const full = path.join(templateRoot, child);
111
- if (await pathExists(path.join(full, "SKILL.md"))) {
112
- manifests.push(await buildManifestFromDir(full));
113
- }
114
- }
115
-
116
- if (manifests.length > 0) return manifests;
117
-
118
- const markdownFiles = await collectMarkdownFiles(templateRoot);
119
- for (const selected of markdownFiles.sort()) {
120
- manifests.push(await buildManifestFromMarkdown(templateRoot, selected));
121
- }
122
- return manifests;
123
- }
124
-
125
- async function buildManifestFromMarkdown(
126
- templateRoot: string,
127
- selected: string
128
- ): Promise<SkillManifest> {
129
- const raw = await readFile(selected, "utf8");
130
- const parsed = parseFrontmatter(raw);
131
- const baseName = path.basename(selected, path.extname(selected));
132
- const skillName = normalizeSkillName(parsed.attributes.name || baseName);
133
- const description =
134
- parsed.attributes.description ||
135
- `Generated from templates/${path.relative(templateRoot, selected).replaceAll("\\", "/")}`;
136
- const body = parsed.body.trim() || raw.trim();
137
-
138
- const tmp = await mkdtemp(path.join(os.tmpdir(), "cdspec-template-"));
139
- await ensureDir(path.join(tmp, "agents"));
140
- await ensureDir(path.join(tmp, "references"));
141
- const skillMd = ["---", `name: ${skillName}`, `description: ${description}`, "---", "", body].join(
142
- "\n"
143
- );
144
- const openaiYaml = [
145
- "interface:",
146
- ` display_name: "${humanizeName(skillName)}"`,
147
- ` short_description: "${escapeYaml(description)}"`,
148
- ` default_prompt: "Use $${skillName} to follow this template skill."`
149
- ].join("\n");
150
- await writeFile(path.join(tmp, "SKILL.md"), `${skillMd}\n`, "utf8");
151
- await writeFile(path.join(tmp, "agents", "openai.yaml"), `${openaiYaml}\n`, "utf8");
152
- await writeFile(path.join(tmp, "references", path.basename(selected)), raw, "utf8");
153
- return buildManifestFromDir(tmp);
154
- }
155
-
156
- async function collectMarkdownFiles(root: string): Promise<string[]> {
157
- const files: string[] = [];
158
- const queue = [root];
159
- while (queue.length > 0) {
160
- const current = queue.pop()!;
161
- const dirs = await listDirs(current);
162
- for (const dir of dirs) {
163
- queue.push(path.join(current, dir));
164
- }
165
- const entries = await readdir(current, { withFileTypes: true });
166
- for (const entry of entries) {
167
- if (entry.isFile() && entry.name.toLowerCase().endsWith(".md")) {
168
- files.push(path.join(current, entry.name));
169
- }
170
- }
171
- }
172
- return files;
173
- }
174
-
175
- function normalizeSkillName(input: string): string {
176
- return input
177
- .toLowerCase()
178
- .replace(/[^a-z0-9]+/g, "-")
179
- .replace(/^-+|-+$/g, "") || DEFAULT_SKILL_NAME;
180
- }
181
-
182
- function humanizeName(input: string): string {
183
- return input
184
- .split("-")
185
- .filter(Boolean)
186
- .map((part) => part[0].toUpperCase() + part.slice(1))
187
- .join(" ");
188
- }
189
-
190
- function escapeYaml(value: string): string {
191
- return value.replace(/"/g, '\\"');
192
- }
@@ -1,199 +0,0 @@
1
- import path from "node:path";
2
- import { rm } from "node:fs/promises";
3
- import { loadConfig } from "../config/loader.js";
4
- import { resolveAgentRoot } from "../config/path.js";
5
- import { CDSpecConfig } from "../config/types.js";
6
- import { loadAllSkillManifests, loadSkillManifestByName } from "./manifest-loader.js";
7
- import { expandTargets, getAdapter } from "./adapters/index.js";
8
- import {
9
- installToolInteractionTemplates,
10
- writeSharedAgentsStub
11
- } from "./tool-interactions.js";
12
- import {
13
- cleanupLegacyDefaultSkillDir,
14
- loadDefaultSkillManifest,
15
- loadProjectTemplateManifests
16
- } from "./scaffold.js";
17
- import { SkillManifest } from "./types.js";
18
- import { validateManifest } from "./validator.js";
19
-
20
- export async function listSkills(cwd: string): Promise<string[]> {
21
- const manifests = await loadAllSkillManifests(cwd);
22
- return manifests.map((manifest) => manifest.name).sort();
23
- }
24
-
25
- export async function addSkill(
26
- cwd: string,
27
- name: string,
28
- targetRaw: string,
29
- force: boolean
30
- ): Promise<void> {
31
- const config = await loadConfig(cwd);
32
- let manifest = await loadSkillManifestByName(cwd, name);
33
- if (!manifest) {
34
- const all = await loadAllSkillManifests(cwd);
35
- manifest = all.find((item) => item.name === name) ?? null;
36
- }
37
- if (!manifest) {
38
- throw new Error(`Skill "${name}" not found under .codex/.`);
39
- }
40
- const diagnostics = [...validateManifest(manifest)];
41
- const targets = expandTargets(targetRaw);
42
- for (const target of targets) {
43
- diagnostics.push(...getAdapter(target).validate(manifest));
44
- }
45
- failIfErrors(diagnostics);
46
-
47
- for (const target of targets) {
48
- const adapter = getAdapter(target);
49
- const outDir = path.join(resolveAgentRoot(cwd, config.agents[target].rootDir), "skills", manifest.name);
50
- await adapter.emit(manifest, outDir, force);
51
- }
52
- }
53
-
54
- export async function syncSkills(
55
- cwd: string,
56
- targetRaw: string,
57
- force: boolean
58
- ): Promise<void> {
59
- const config = await loadConfig(cwd);
60
- const manifests = await loadAllSkillManifests(cwd);
61
- if (manifests.length === 0) {
62
- throw new Error("No skills found under .codex/.");
63
- }
64
- const targets = expandTargets(targetRaw);
65
-
66
- for (const manifest of manifests) {
67
- const diagnostics = [...validateManifest(manifest)];
68
- for (const target of targets) {
69
- diagnostics.push(...getAdapter(target).validate(manifest));
70
- }
71
- failIfErrors(diagnostics);
72
- }
73
-
74
- for (const manifest of manifests) {
75
- for (const target of targets) {
76
- const outDir = path.join(resolveAgentRoot(cwd, config.agents[target].rootDir), "skills", manifest.name);
77
- await getAdapter(target).emit(manifest, outDir, force);
78
- }
79
- }
80
- }
81
-
82
- export async function initSkills(
83
- cwd: string,
84
- agentsRaw: string,
85
- force: boolean
86
- ): Promise<string[]> {
87
- await cleanupLegacyDefaultSkillDir(cwd);
88
- const baseConfig = await loadConfig(cwd);
89
- const projectTemplateManifests = await loadProjectTemplateManifests(cwd);
90
- let manifests = projectTemplateManifests.length > 0
91
- ? projectTemplateManifests
92
- : await loadAllSkillManifests(cwd);
93
- if (manifests.length === 0) manifests = [await loadDefaultSkillManifest(cwd)];
94
- const config = buildInitConfig(baseConfig, manifests);
95
- const targets = expandTargets(agentsRaw);
96
- if (force) {
97
- for (const target of targets) {
98
- const root = resolveAgentRoot(cwd, config.agents[target].rootDir);
99
- await rm(path.join(root, "skills"), {
100
- recursive: true,
101
- force: true
102
- });
103
- await rm(path.join(root, config.agents[target].commandsDir), {
104
- recursive: true,
105
- force: true
106
- });
107
- const guide = config.agents[target].guideAtProjectRoot
108
- ? path.join(cwd, config.agents[target].guideFile)
109
- : path.join(root, config.agents[target].guideFile);
110
- await rm(guide, { force: true });
111
- }
112
- }
113
- for (const manifest of manifests) {
114
- const diagnostics = [...validateManifest(manifest)];
115
- for (const target of targets) {
116
- diagnostics.push(...getAdapter(target).validate(manifest));
117
- }
118
- failIfErrors(diagnostics);
119
- }
120
-
121
- for (const manifest of manifests) {
122
- for (const target of targets) {
123
- const outDir = path.join(resolveAgentRoot(cwd, config.agents[target].rootDir), "skills", manifest.name);
124
- await getAdapter(target).emit(manifest, outDir, force);
125
- }
126
- }
127
-
128
- const files: string[] = [];
129
- for (const target of targets) {
130
- files.push(...(await installToolInteractionTemplates(cwd, target, manifests, config)));
131
- }
132
- files.push(await writeSharedAgentsStub(cwd, targets, manifests, config));
133
- return files;
134
- }
135
-
136
- function buildInitConfig(
137
- config: CDSpecConfig,
138
- manifests: SkillManifest[]
139
- ): CDSpecConfig {
140
- const available = new Set(manifests.map((item) => item.name));
141
- const skillDrivenBindings = buildSkillDrivenBindings(manifests);
142
- return {
143
- ...config,
144
- commandBindings:
145
- skillDrivenBindings.length > 0
146
- ? skillDrivenBindings
147
- : config.commandBindings.map((item) =>
148
- available.has(item.skill) ? item : { ...item, skill: manifests[0]?.name || item.skill }
149
- ),
150
- agents: {
151
- codex: { ...config.agents.codex, commandFilePattern: "{id}.md", slashPattern: "/{id}" },
152
- claudecode: {
153
- ...config.agents.claudecode,
154
- commandFilePattern: "{id}.md",
155
- slashPattern: "/{id}"
156
- },
157
- iflow: { ...config.agents.iflow, commandFilePattern: "{id}.md", slashPattern: "/{id}" }
158
- }
159
- };
160
- }
161
-
162
- function buildSkillDrivenBindings(manifests: SkillManifest[]) {
163
- const used = new Set<string>();
164
- return manifests.map((manifest) => {
165
- const base = commandIdForSkillName(manifest.name);
166
- let id = base;
167
- let i = 2;
168
- while (used.has(id)) {
169
- id = `${base}${i}`;
170
- i += 1;
171
- }
172
- used.add(id);
173
- return {
174
- id,
175
- skill: manifest.name,
176
- description: `Run skill ${manifest.name}`
177
- };
178
- });
179
- }
180
-
181
- function commandIdForSkillName(skillName: string): string {
182
- const normalizedName = skillName
183
- .toLowerCase()
184
- .replace(/[^a-z0-9]+/g, "-")
185
- .replace(/^-+|-+$/g, "");
186
- return `cd-${normalizedName || "skill"}`;
187
- }
188
-
189
- function failIfErrors(
190
- diagnostics: Array<{ level: "error" | "warning"; message: string }>
191
- ): void {
192
- const warnings = diagnostics.filter((item) => item.level === "warning");
193
- warnings.forEach((warning) => console.warn(`[warn] ${warning.message}`));
194
-
195
- const errors = diagnostics.filter((item) => item.level === "error");
196
- if (errors.length > 0) {
197
- throw new Error(errors.map((error) => error.message).join("\n"));
198
- }
199
- }
@@ -1,95 +0,0 @@
1
- import { writeFile } from "node:fs/promises";
2
- import path from "node:path";
3
- import { resolveAgentRoot } from "../config/path.js";
4
- import { CDSpecConfig } from "../config/types.js";
5
- import { ensureDir } from "../utils/fs.js";
6
- import { SkillManifest, Target } from "./types.js";
7
-
8
- export async function installToolInteractionTemplates(
9
- cwd: string,
10
- target: Target,
11
- skills: SkillManifest[],
12
- config: CDSpecConfig
13
- ): Promise<string[]> {
14
- const agent = config.agents[target];
15
- const root = resolveAgentRoot(cwd, agent.rootDir);
16
- const commandsDir = path.join(root, agent.commandsDir);
17
- await ensureDir(commandsDir);
18
- const created: string[] = [];
19
-
20
- for (const binding of config.commandBindings) {
21
- const fileName = agent.commandFilePattern.replace("{id}", binding.id);
22
- const file = path.join(commandsDir, fileName);
23
- await writeFile(file, renderCommandTemplate(target, binding.id, binding.skill, binding.description), "utf8");
24
- created.push(file);
25
- }
26
-
27
- const guidePath = agent.guideAtProjectRoot
28
- ? path.join(cwd, agent.guideFile)
29
- : path.join(root, agent.guideFile);
30
- await writeFile(guidePath, renderGuide(target, skills, config), "utf8");
31
- created.push(guidePath);
32
- return created;
33
- }
34
-
35
- export async function writeSharedAgentsStub(
36
- cwd: string,
37
- targets: Target[],
38
- skills: SkillManifest[],
39
- config: CDSpecConfig
40
- ): Promise<string> {
41
- const file = path.join(cwd, "AGENTS.md");
42
- const lines = [
43
- "# AGENTS instructions",
44
- "",
45
- "<INSTRUCTIONS>",
46
- "## OpenSpec Setup",
47
- `Enabled targets: ${targets.join(", ")}`,
48
- "### Skills",
49
- ...skills.map((skill) => `- ${skill.name}: ${skill.description || "No description"}`),
50
- "### Command Bindings",
51
- ...config.commandBindings.map((binding) => `- ${binding.id} -> ${binding.skill}`),
52
- "</INSTRUCTIONS>",
53
- ""
54
- ];
55
- await writeFile(file, lines.join("\n"), "utf8");
56
- return file;
57
- }
58
-
59
- function renderCommandTemplate(
60
- target: Target,
61
- commandId: string,
62
- skillName: string,
63
- description: string
64
- ): string {
65
- return [
66
- `# ${commandId} (${target})`,
67
- "",
68
- description,
69
- "",
70
- "## Skill binding",
71
- `- skill: ${skillName}`,
72
- "",
73
- "## Required output",
74
- "- Change ID",
75
- "- Updated files",
76
- "- Validation summary"
77
- ].join("\n");
78
- }
79
-
80
- function renderGuide(target: Target, skills: SkillManifest[], config: CDSpecConfig): string {
81
- const agent = config.agents[target];
82
- const commandList = config.commandBindings.map((binding) =>
83
- `- ${agent.slashPattern.replace("{id}", binding.id)} -> ${binding.skill}`
84
- );
85
- return [
86
- `# ${target} OpenSpec-style setup`,
87
- "",
88
- "## Installed skills",
89
- ...skills.map((skill) => `- ${skill.name}: ${skill.description || "No description"}`),
90
- "",
91
- "## Commands",
92
- ...commandList,
93
- ""
94
- ].join("\n");
95
- }
@@ -1,22 +0,0 @@
1
- export type Target = "codex" | "claudecode" | "iflow";
2
-
3
- export interface SkillManifest {
4
- name: string;
5
- description: string;
6
- body: string;
7
- agents: string[];
8
- resources: string[];
9
- sourcePath: string;
10
- }
11
-
12
- export interface Diagnostic {
13
- level: "error" | "warning";
14
- message: string;
15
- }
16
-
17
- export interface TargetAdapter {
18
- target: Target;
19
- validate(manifest: SkillManifest): Diagnostic[];
20
- emit(manifest: SkillManifest, outDir: string, force: boolean): Promise<void>;
21
- }
22
-
@@ -1,28 +0,0 @@
1
- import { Diagnostic, SkillManifest } from "./types.js";
2
-
3
- export function validateManifest(manifest: SkillManifest): Diagnostic[] {
4
- const diagnostics: Diagnostic[] = [];
5
- if (!manifest.name) {
6
- diagnostics.push({ level: "error", message: "Skill name is required." });
7
- }
8
- if (!manifest.description) {
9
- diagnostics.push({
10
- level: "error",
11
- message: `Skill "${manifest.name}" is missing frontmatter description.`
12
- });
13
- }
14
- if (!manifest.body) {
15
- diagnostics.push({
16
- level: "warning",
17
- message: `Skill "${manifest.name}" has empty SKILL.md body.`
18
- });
19
- }
20
- if (!/^[a-z0-9-]+$/.test(manifest.name)) {
21
- diagnostics.push({
22
- level: "warning",
23
- message: `Skill "${manifest.name}" should use lowercase letters, numbers, and hyphens.`
24
- });
25
- }
26
- return diagnostics;
27
- }
28
-