cdspec 0.1.0

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 (73) hide show
  1. package/AGENTS.md +14 -0
  2. package/CLAUDE.md +10 -0
  3. package/README.md +55 -0
  4. package/cdspec.config.yaml +34 -0
  5. package/dist/cli.js +94 -0
  6. package/dist/config/default.js +48 -0
  7. package/dist/config/loader.js +30 -0
  8. package/dist/config/path.js +11 -0
  9. package/dist/config/types.js +1 -0
  10. package/dist/skill-core/adapters/claudecode-adapter.js +35 -0
  11. package/dist/skill-core/adapters/codex-adapter.js +28 -0
  12. package/dist/skill-core/adapters/iflow-adapter.js +39 -0
  13. package/dist/skill-core/adapters/index.js +34 -0
  14. package/dist/skill-core/adapters/shared.js +36 -0
  15. package/dist/skill-core/agent-config.js +40 -0
  16. package/dist/skill-core/manifest-loader.js +63 -0
  17. package/dist/skill-core/scaffold.js +169 -0
  18. package/dist/skill-core/service.js +156 -0
  19. package/dist/skill-core/tool-interactions.js +70 -0
  20. package/dist/skill-core/types.js +1 -0
  21. package/dist/skill-core/validator.js +25 -0
  22. package/dist/task-core/parser.js +70 -0
  23. package/dist/task-core/service.js +28 -0
  24. package/dist/task-core/storage.js +159 -0
  25. package/dist/task-core/types.js +1 -0
  26. package/dist/utils/frontmatter.js +40 -0
  27. package/dist/utils/fs.js +37 -0
  28. package/package.json +29 -0
  29. package/src/cli.ts +105 -0
  30. package/src/config/default.ts +51 -0
  31. package/src/config/loader.ts +37 -0
  32. package/src/config/path.ts +13 -0
  33. package/src/config/types.ts +22 -0
  34. package/src/skill-core/adapters/claudecode-adapter.ts +45 -0
  35. package/src/skill-core/adapters/codex-adapter.ts +36 -0
  36. package/src/skill-core/adapters/iflow-adapter.ts +49 -0
  37. package/src/skill-core/adapters/index.ts +39 -0
  38. package/src/skill-core/adapters/shared.ts +45 -0
  39. package/src/skill-core/manifest-loader.ts +79 -0
  40. package/src/skill-core/scaffold.ts +192 -0
  41. package/src/skill-core/service.ts +199 -0
  42. package/src/skill-core/tool-interactions.ts +95 -0
  43. package/src/skill-core/types.ts +22 -0
  44. package/src/skill-core/validator.ts +28 -0
  45. package/src/task-core/parser.ts +89 -0
  46. package/src/task-core/service.ts +49 -0
  47. package/src/task-core/storage.ts +177 -0
  48. package/src/task-core/types.ts +15 -0
  49. package/src/types/yaml.d.ts +4 -0
  50. package/src/utils/frontmatter.ts +55 -0
  51. package/src/utils/fs.ts +41 -0
  52. package/templates/design-doc/SKILL.md +99 -0
  53. package/templates/design-doc/agents/openai.yaml +4 -0
  54. package/templates/design-doc/references//345/237/272/347/272/277/346/250/241/346/235/277.md +46 -0
  55. package/templates/design-doc/references//345/242/236/351/207/217/351/234/200/346/261/202/346/250/241/346/235/277.md +32 -0
  56. package/templates/design-doc/references//345/275/222/346/241/243/346/243/200/346/237/245/346/270/205/345/215/225.md +15 -0
  57. package/templates/design-doc/references//347/224/237/344/272/247/345/267/245/345/215/225/345/237/272/347/272/277/347/244/272/344/276/213.md +470 -0
  58. package/templates/design-doc/scripts/validate_doc_layout.sh +49 -0
  59. package/templates/frontend-develop-standard/SKILL.md +63 -0
  60. package/templates/frontend-develop-standard/agents/openai.yaml +4 -0
  61. package/templates/frontend-develop-standard/references/frontend_develop_standard.md +749 -0
  62. package/templates/standards-backend/SKILL.md +55 -0
  63. package/templates/standards-backend/agents/openai.yaml +4 -0
  64. package/templates/standards-backend/references/DDD/346/236/266/346/236/204/347/272/246/346/235/237.md +103 -0
  65. package/templates/standards-backend/references/JUC/345/271/266/345/217/221/350/247/204/350/214/203.md +232 -0
  66. package/templates/standards-backend/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 -0
  67. package/templates/standards-backend/references//345/220/216/347/253/257/345/274/200/345/217/221/350/247/204/350/214/203.md +49 -0
  68. package/templates/standards-backend/references//346/225/260/346/215/256/345/272/223/350/256/276/350/256/241/350/247/204/350/214/203.md +116 -0
  69. package/templates/standards-backend/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 -0
  70. package/tests/skill.test.ts +191 -0
  71. package/tests/task.test.ts +55 -0
  72. package/tsconfig.json +16 -0
  73. package/vitest.config.ts +9 -0
@@ -0,0 +1,192 @@
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
+ }
@@ -0,0 +1,199 @@
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
+ }
@@ -0,0 +1,95 @@
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
+ }
@@ -0,0 +1,22 @@
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
+
@@ -0,0 +1,28 @@
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
+
@@ -0,0 +1,89 @@
1
+ import { createHash } from "node:crypto";
2
+ import path from "node:path";
3
+ import { TaskItem } from "./types.js";
4
+
5
+ export function splitMarkdownToTasks(
6
+ markdown: string,
7
+ sourcePath: string,
8
+ rootTitle: string
9
+ ): TaskItem[] {
10
+ const normalized = markdown.replace(/\r\n/g, "\n");
11
+ const lines = normalized.split("\n");
12
+ const headingStack: string[] = [];
13
+ const extracted: string[] = [];
14
+
15
+ for (const line of lines) {
16
+ const headingMatch = line.match(/^(#{1,6})\s+(.+?)\s*$/);
17
+ if (headingMatch) {
18
+ const level = headingMatch[1].length;
19
+ const title = headingMatch[2].trim();
20
+ headingStack.splice(level - 1);
21
+ headingStack[level - 1] = title;
22
+ continue;
23
+ }
24
+
25
+ const listMatch = line.match(/^\s*(?:[-*+]|\d+\.)\s+(.+?)\s*$/);
26
+ if (!listMatch) continue;
27
+ const item = listMatch[1].trim();
28
+ const prefix = headingStack.filter(Boolean).join(" / ");
29
+ extracted.push(prefix ? `${prefix} - ${item}` : item);
30
+ }
31
+
32
+ if (extracted.length === 0) {
33
+ for (const line of lines) {
34
+ const headingMatch = line.match(/^#{2,6}\s+(.+?)\s*$/);
35
+ if (headingMatch) extracted.push(headingMatch[1].trim());
36
+ }
37
+ }
38
+
39
+ if (extracted.length === 0) {
40
+ extracted.push(rootTitle);
41
+ }
42
+
43
+ return dedupe(extracted).map((title, idx) =>
44
+ createTaskItem({
45
+ sourcePath,
46
+ title,
47
+ order: idx + 1
48
+ })
49
+ );
50
+ }
51
+
52
+ function createTaskItem(input: {
53
+ sourcePath: string;
54
+ title: string;
55
+ order: number;
56
+ }): TaskItem {
57
+ const now = new Date().toISOString();
58
+ return {
59
+ id: buildStableId(input.sourcePath, input.title, input.order),
60
+ title: input.title,
61
+ status: "todo",
62
+ source: normalizePath(input.sourcePath),
63
+ createdAt: now,
64
+ updatedAt: now
65
+ };
66
+ }
67
+
68
+ function buildStableId(sourcePath: string, title: string, order: number): string {
69
+ const digest = createHash("sha1")
70
+ .update(`${normalizePath(sourcePath)}::${title}::${order}`)
71
+ .digest("hex");
72
+ return digest.slice(0, 10);
73
+ }
74
+
75
+ function normalizePath(input: string): string {
76
+ return input.replaceAll("\\", "/").replaceAll(path.sep, "/");
77
+ }
78
+
79
+ function dedupe(items: string[]): string[] {
80
+ const seen = new Set<string>();
81
+ const result: string[] = [];
82
+ for (const item of items) {
83
+ if (seen.has(item)) continue;
84
+ seen.add(item);
85
+ result.push(item);
86
+ }
87
+ return result;
88
+ }
89
+
@@ -0,0 +1,49 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { pathExists } from "../utils/fs.js";
4
+ import { splitMarkdownToTasks } from "./parser.js";
5
+ import {
6
+ archiveTask,
7
+ initTaskWorkspace,
8
+ refreshArchiveIndex,
9
+ refreshTaskIndex,
10
+ saveTask,
11
+ updateTaskStatus
12
+ } from "./storage.js";
13
+ import { TaskStatus } from "./types.js";
14
+
15
+ export async function splitTasks(
16
+ cwd: string,
17
+ fromFile: string,
18
+ title: string
19
+ ): Promise<number> {
20
+ const absoluteInput = path.resolve(cwd, fromFile);
21
+ if (!(await pathExists(absoluteInput))) {
22
+ throw new Error(`Input file not found: ${fromFile}`);
23
+ }
24
+
25
+ const markdown = await readFile(absoluteInput, "utf8");
26
+ const tasks = splitMarkdownToTasks(markdown, fromFile, title);
27
+ await initTaskWorkspace(cwd);
28
+ for (const task of tasks) {
29
+ await saveTask(cwd, task);
30
+ }
31
+ await refreshTaskIndex(cwd);
32
+ return tasks.length;
33
+ }
34
+
35
+ export async function archiveTaskById(cwd: string, id: string): Promise<void> {
36
+ await archiveTask(cwd, id);
37
+ await refreshTaskIndex(cwd);
38
+ await refreshArchiveIndex(cwd);
39
+ }
40
+
41
+ export async function updateTask(
42
+ cwd: string,
43
+ id: string,
44
+ status: TaskStatus
45
+ ): Promise<void> {
46
+ await updateTaskStatus(cwd, id, status);
47
+ await refreshTaskIndex(cwd);
48
+ }
49
+