@powerhousedao/clint 0.0.0-stage → 6.2.3-dev.101

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 (53) hide show
  1. package/LICENSE +661 -0
  2. package/dist/build-skills-Cfj0OGnW.mjs +293 -0
  3. package/dist/build-skills-Cfj0OGnW.mjs.map +1 -0
  4. package/dist/dist-CUltriBW.mjs +1628 -0
  5. package/dist/dist-CUltriBW.mjs.map +1 -0
  6. package/dist/drive-BEshRPDR.mjs +84 -0
  7. package/dist/drive-BEshRPDR.mjs.map +1 -0
  8. package/dist/esm-C1DOsF1a.mjs +13140 -0
  9. package/dist/esm-C1DOsF1a.mjs.map +1 -0
  10. package/dist/events-BnwGFTjv.mjs +237 -0
  11. package/dist/events-BnwGFTjv.mjs.map +1 -0
  12. package/dist/folders-C-pFsTXT.mjs +256 -0
  13. package/dist/folders-C-pFsTXT.mjs.map +1 -0
  14. package/dist/index.d.mts +1005 -0
  15. package/dist/index.d.mts.map +1 -0
  16. package/dist/index.mjs +8 -0
  17. package/dist/local-signer-EFzJV3bn.mjs +128 -0
  18. package/dist/local-signer-EFzJV3bn.mjs.map +1 -0
  19. package/dist/markdown-D-sP2zw_.mjs +275 -0
  20. package/dist/markdown-D-sP2zw_.mjs.map +1 -0
  21. package/dist/proxy-BFR8GScT.mjs +302 -0
  22. package/dist/proxy-BFR8GScT.mjs.map +1 -0
  23. package/dist/proxy-routes-DP3ztsnS.mjs +215 -0
  24. package/dist/proxy-routes-DP3ztsnS.mjs.map +1 -0
  25. package/dist/reactor-C9VIUX1H.mjs +51 -0
  26. package/dist/reactor-C9VIUX1H.mjs.map +1 -0
  27. package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
  28. package/dist/runners/clint-runner.d.mts +398 -0
  29. package/dist/runners/clint-runner.d.mts.map +1 -0
  30. package/dist/runners/clint-runner.mjs +522 -0
  31. package/dist/runners/clint-runner.mjs.map +1 -0
  32. package/dist/runners/mastra-runner.d.mts +300 -0
  33. package/dist/runners/mastra-runner.d.mts.map +1 -0
  34. package/dist/runners/mastra-runner.mjs +516 -0
  35. package/dist/runners/mastra-runner.mjs.map +1 -0
  36. package/dist/services-9E-r0nWl.mjs +999 -0
  37. package/dist/services-9E-r0nWl.mjs.map +1 -0
  38. package/dist/src-DD8PWpD5.mjs +4767 -0
  39. package/dist/src-DD8PWpD5.mjs.map +1 -0
  40. package/dist/start-b7Mn2cxB.mjs +1526 -0
  41. package/dist/start-b7Mn2cxB.mjs.map +1 -0
  42. package/dist/stdin-BjAO9gPK.mjs +17 -0
  43. package/dist/stdin-BjAO9gPK.mjs.map +1 -0
  44. package/dist/stream-DVuufwIj.mjs +148 -0
  45. package/dist/stream-DVuufwIj.mjs.map +1 -0
  46. package/dist/subscriptions-CfiflAsI.mjs +38 -0
  47. package/dist/subscriptions-CfiflAsI.mjs.map +1 -0
  48. package/dist/switchboard-CyvOavqL.mjs +57 -0
  49. package/dist/switchboard-CyvOavqL.mjs.map +1 -0
  50. package/dist/types-CRkoD-Mm.d.mts +1770 -0
  51. package/dist/types-CRkoD-Mm.d.mts.map +1 -0
  52. package/package.json +102 -3
  53. package/README.md +0 -3
@@ -0,0 +1,293 @@
1
+ import { T as renderSkillTemplate } from "./src-DD8PWpD5.mjs";
2
+ import { p as slugToTitle } from "./services-9E-r0nWl.mjs";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ //#region src/dev/agent-profiles.ts
6
+ /**
7
+ * Find the first existing file across multiple include directories.
8
+ */
9
+ function findInIncludes(includes, subdir, filename) {
10
+ for (const dir of includes) {
11
+ const p = path.join(dir, subdir, filename);
12
+ if (fs.existsSync(p)) return p;
13
+ }
14
+ }
15
+ /**
16
+ * Build agent profile instructions by rendering base+specialized template pairs.
17
+ * Writes each profile as a Markdown file in {output}/agents/{ProfileName}.md.
18
+ *
19
+ * @returns Number of profiles built and any warnings.
20
+ */
21
+ function buildAgentProfiles(config) {
22
+ const log = config.logger;
23
+ const profiles = config.agentProfiles;
24
+ if (profiles.length === 0) return {
25
+ count: 0,
26
+ warnings: []
27
+ };
28
+ const profilesSubdir = config.subdirs?.profiles ?? "agent-profiles";
29
+ log("\n--- Building agent instructions ---");
30
+ const allWarnings = [];
31
+ let count = 0;
32
+ for (const profile of profiles) {
33
+ const sectionPaths = [];
34
+ let missing = false;
35
+ for (const section of profile.sections) {
36
+ const found = findInIncludes(config.include, profilesSubdir, section);
37
+ if (!found) {
38
+ log(` SKIP ${profile.name}: missing section ${section}`);
39
+ missing = true;
40
+ break;
41
+ }
42
+ sectionPaths.push(found);
43
+ }
44
+ if (missing) continue;
45
+ const agentContext = {
46
+ ...config.context,
47
+ agentName: profile.name
48
+ };
49
+ const renderOpts = config.customHelpers ? { helpers: config.customHelpers } : void 0;
50
+ const renderedSections = [];
51
+ for (let i = 0; i < profile.sections.length; i++) {
52
+ const raw = fs.readFileSync(sectionPaths[i], "utf-8");
53
+ const result = renderSkillTemplate(raw, agentContext, renderOpts);
54
+ for (const w of result.warnings) {
55
+ const msg = `${profile.name}/${profile.sections[i]}: ${w}`;
56
+ allWarnings.push(msg);
57
+ log(` WARN ${msg}`);
58
+ }
59
+ renderedSections.push(result.rendered.trim());
60
+ }
61
+ const combined = renderedSections.join("\n\n") + "\n";
62
+ for (const out of config.output) {
63
+ const agentsDir = path.join(out, "agent-profiles");
64
+ fs.mkdirSync(agentsDir, { recursive: true });
65
+ fs.writeFileSync(path.join(agentsDir, `${profile.name}.md`), combined, "utf-8");
66
+ }
67
+ log(` OK ${profile.name} → ${profile.name}.md (${combined.length} chars)`);
68
+ count++;
69
+ }
70
+ return {
71
+ count,
72
+ warnings: allWarnings
73
+ };
74
+ }
75
+ //#endregion
76
+ //#region src/dev/skill-builder.ts
77
+ /**
78
+ * Find the first existing directory across multiple include paths.
79
+ */
80
+ function findSubdir(includes, subdir) {
81
+ for (const dir of includes) {
82
+ const p = path.join(dir, subdir);
83
+ if (fs.existsSync(p)) return p;
84
+ }
85
+ }
86
+ /**
87
+ * Build SKILL.md files from Handlebars templates in skills-tpl/.
88
+ * Each skill directory produces a SKILL.md + references/ folder.
89
+ *
90
+ * @returns Number of skills built and any warnings.
91
+ */
92
+ function buildSkillTemplates(config) {
93
+ const log = config.logger;
94
+ const skillsTplSubdir = config.subdirs?.skillsTpl ?? "skills-tpl";
95
+ const skillsTplDir = findSubdir(config.include, skillsTplSubdir);
96
+ log("\n--- Building SKILL.md files (templates) ---");
97
+ if (!skillsTplDir) {
98
+ log(" No skills-tpl/ directory — skipping.");
99
+ return {
100
+ count: 0,
101
+ warnings: []
102
+ };
103
+ }
104
+ const skillDirs = fs.readdirSync(skillsTplDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
105
+ const allWarnings = [];
106
+ const renderOpts = config.customHelpers ? { helpers: config.customHelpers } : void 0;
107
+ let count = 0;
108
+ for (const skillName of skillDirs) {
109
+ const skillDir = path.join(skillsTplDir, skillName);
110
+ const preamblePath = path.join(skillDir, ".preamble.md");
111
+ const preambleRaw = fs.existsSync(preamblePath) ? fs.readFileSync(preamblePath, "utf-8").trim() : "";
112
+ let preamble = "";
113
+ if (preambleRaw) {
114
+ const r = renderSkillTemplate(preambleRaw, config.context, renderOpts);
115
+ preamble = r.rendered;
116
+ for (const w of r.warnings) {
117
+ const msg = `${skillName}/.preamble.md: ${w}`;
118
+ allWarnings.push(msg);
119
+ log(` WARN ${msg}`);
120
+ }
121
+ }
122
+ const scenarioFiles = fs.readdirSync(skillDir).filter((f) => /^\d+\..*\.md$/.test(f)).sort();
123
+ const resultPath = path.join(skillDir, ".result.md");
124
+ const hasResult = fs.existsSync(resultPath);
125
+ if (!preamble && scenarioFiles.length === 0 && !hasResult) {
126
+ log(` SKIP ${skillName}: no content files found`);
127
+ continue;
128
+ }
129
+ const files = /* @__PURE__ */ new Map();
130
+ const refLinks = [];
131
+ for (const scenarioFile of scenarioFiles) {
132
+ const content = fs.readFileSync(path.join(skillDir, scenarioFile), "utf-8").trim();
133
+ const r = renderSkillTemplate(content, config.context, renderOpts);
134
+ for (const w of r.warnings) {
135
+ const msg = `${skillName}/${scenarioFile}: ${w}`;
136
+ allWarnings.push(msg);
137
+ log(` WARN ${msg}`);
138
+ }
139
+ files.set(path.join("references", scenarioFile), r.rendered + "\n");
140
+ const label = slugToTitle(scenarioFile.replace(/^\d+\./, "").replace(/\.md$/, ""));
141
+ refLinks.push(`* **${label}** [references/${scenarioFile}](references/${scenarioFile})`);
142
+ }
143
+ if (hasResult) {
144
+ const content = fs.readFileSync(resultPath, "utf-8").trim();
145
+ const r = renderSkillTemplate(content, config.context, renderOpts);
146
+ for (const w of r.warnings) {
147
+ const msg = `${skillName}/.result.md: ${w}`;
148
+ allWarnings.push(msg);
149
+ log(` WARN ${msg}`);
150
+ }
151
+ files.set(path.join("references", "expected-outcome.md"), r.rendered + "\n");
152
+ refLinks.push(`* **Expected Outcome** [references/expected-outcome.md](references/expected-outcome.md)`);
153
+ }
154
+ const description = config.skillDescriptions[skillName] ?? `${slugToTitle(skillName)} tasks`;
155
+ const frontmatter = [
156
+ "---",
157
+ `name: ${skillName}`,
158
+ `description: "${description}"`,
159
+ "metadata:",
160
+ " author: Powerhouse",
161
+ " version: \"1.0.0\"",
162
+ "---"
163
+ ].join("\n");
164
+ const sections = [preamble];
165
+ if (refLinks.length > 0) sections.push("## Specific tasks\n\n" + refLinks.join("\n"));
166
+ const skillMd = frontmatter + "\n\n" + sections.filter(Boolean).join("\n\n") + "\n";
167
+ files.set("SKILL.md", skillMd);
168
+ const cliDocsPath = path.join(skillDir, ".cli-docs.md");
169
+ if (fs.existsSync(cliDocsPath)) {
170
+ const cliDocsRaw = fs.readFileSync(cliDocsPath, "utf-8").trim();
171
+ if (cliDocsRaw) {
172
+ const r = renderSkillTemplate(cliDocsRaw, config.context, renderOpts);
173
+ for (const w of r.warnings) {
174
+ const msg = `${skillName}/.cli-docs.md: ${w}`;
175
+ allWarnings.push(msg);
176
+ log(` WARN ${msg}`);
177
+ }
178
+ files.set(".cli-docs.md", r.rendered + "\n");
179
+ }
180
+ }
181
+ for (const out of config.output) {
182
+ const outputDir = path.join(out, "skills", skillName);
183
+ for (const [relPath, content] of files) {
184
+ const fullPath = path.join(outputDir, relPath);
185
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
186
+ fs.writeFileSync(fullPath, content, "utf-8");
187
+ }
188
+ }
189
+ log(` OK ${skillName} → SKILL.md + ${scenarioFiles.length + (hasResult ? 1 : 0)} references (${skillMd.length} chars)`);
190
+ count++;
191
+ }
192
+ return {
193
+ count,
194
+ warnings: allWarnings
195
+ };
196
+ }
197
+ //#endregion
198
+ //#region src/dev/skill-copier.ts
199
+ /**
200
+ * Copy external skills from skills-ext/ to the output directory without processing.
201
+ *
202
+ * @returns Number of skills copied.
203
+ */
204
+ function copyExternalSkills(config) {
205
+ const log = config.logger;
206
+ const skillsExtSubdir = config.subdirs?.skillsExt ?? "skills-ext";
207
+ log("\n--- Copying external skills ---");
208
+ let found = false;
209
+ let total = 0;
210
+ for (const dir of config.include) {
211
+ const skillsExtDir = path.join(dir, skillsExtSubdir);
212
+ if (!fs.existsSync(skillsExtDir)) continue;
213
+ found = true;
214
+ const skillDirs = fs.readdirSync(skillsExtDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
215
+ for (const skillName of skillDirs) {
216
+ const srcDir = path.join(skillsExtDir, skillName);
217
+ for (const out of config.output) fs.cpSync(srcDir, path.join(out, "skills", skillName), { recursive: true });
218
+ log(` OK ${skillName} → copied as-is`);
219
+ }
220
+ total += skillDirs.length;
221
+ }
222
+ if (!found) log(" No skills-ext/ directory — skipping.");
223
+ return total;
224
+ }
225
+ //#endregion
226
+ //#region src/dev/build-skills.ts
227
+ function firstExisting(rootDir, candidates) {
228
+ const dirs = [];
229
+ for (const candidate of candidates) {
230
+ if (!candidate) continue;
231
+ const abs = path.resolve(rootDir, candidate);
232
+ if (fs.existsSync(abs)) dirs.push(abs);
233
+ }
234
+ return dirs;
235
+ }
236
+ function readProfilesManifest(include) {
237
+ for (const dir of include) {
238
+ const manifest = path.join(dir, "profiles.json");
239
+ if (fs.existsSync(manifest)) try {
240
+ return JSON.parse(fs.readFileSync(manifest, "utf8"));
241
+ } catch {
242
+ return [];
243
+ }
244
+ }
245
+ return [];
246
+ }
247
+ async function buildSkills(options) {
248
+ const log = options.logger ?? console.log;
249
+ const include = firstExisting(options.rootDir, [
250
+ options.skillsDir,
251
+ options.agentsDir,
252
+ "prompts",
253
+ "agents"
254
+ ]);
255
+ const outDir = path.resolve(options.rootDir, options.outDir ?? "dist/skills");
256
+ if (include.length === 0) {
257
+ log("No prompt template directories found (prompts/ or agents/) — nothing to build.");
258
+ return {
259
+ skills: 0,
260
+ profiles: 0,
261
+ copied: 0,
262
+ warnings: [],
263
+ outDir
264
+ };
265
+ }
266
+ const resolved = {
267
+ include,
268
+ output: [outDir],
269
+ context: {
270
+ builtAt: (/* @__PURE__ */ new Date()).toISOString(),
271
+ ...options.context
272
+ },
273
+ agentProfiles: readProfilesManifest(include),
274
+ skillDescriptions: {},
275
+ clean: true,
276
+ logger: log
277
+ };
278
+ for (const dir of resolved.output) if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true });
279
+ const profiles = buildAgentProfiles(resolved);
280
+ const templates = buildSkillTemplates(resolved);
281
+ const copied = copyExternalSkills(resolved);
282
+ return {
283
+ skills: templates.count,
284
+ profiles: profiles.count,
285
+ copied,
286
+ warnings: [...profiles.warnings, ...templates.warnings],
287
+ outDir
288
+ };
289
+ }
290
+ //#endregion
291
+ export { buildSkills };
292
+
293
+ //# sourceMappingURL=build-skills-Cfj0OGnW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-skills-Cfj0OGnW.mjs","names":[],"sources":["../src/dev/agent-profiles.ts","../src/dev/skill-builder.ts","../src/dev/skill-copier.ts","../src/dev/build-skills.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { renderSkillTemplate } from \"../index.js\";\nimport type { ResolvedBuildConfig } from \"./types.js\";\n\n/**\n * Find the first existing file across multiple include directories.\n */\nfunction findInIncludes(\n includes: string[],\n subdir: string,\n filename: string,\n): string | undefined {\n for (const dir of includes) {\n const p = path.join(dir, subdir, filename);\n if (fs.existsSync(p)) return p;\n }\n return undefined;\n}\n\n/**\n * Build agent profile instructions by rendering base+specialized template pairs.\n * Writes each profile as a Markdown file in {output}/agents/{ProfileName}.md.\n *\n * @returns Number of profiles built and any warnings.\n */\nexport function buildAgentProfiles(config: ResolvedBuildConfig): {\n count: number;\n warnings: string[];\n} {\n const log = config.logger;\n const profiles = config.agentProfiles;\n if (profiles.length === 0) return { count: 0, warnings: [] };\n\n const profilesSubdir = config.subdirs?.profiles ?? \"agent-profiles\";\n\n log(\"\\n--- Building agent instructions ---\");\n\n const allWarnings: string[] = [];\n let count = 0;\n\n for (const profile of profiles) {\n // Check all section files exist before rendering\n const sectionPaths: string[] = [];\n let missing = false;\n for (const section of profile.sections) {\n const found = findInIncludes(config.include, profilesSubdir, section);\n if (!found) {\n log(` SKIP ${profile.name}: missing section ${section}`);\n missing = true;\n break;\n }\n sectionPaths.push(found);\n }\n if (missing) continue;\n\n const agentContext = { ...config.context, agentName: profile.name };\n const renderOpts = config.customHelpers\n ? { helpers: config.customHelpers }\n : undefined;\n\n const renderedSections: string[] = [];\n for (let i = 0; i < profile.sections.length; i++) {\n const raw = fs.readFileSync(sectionPaths[i], \"utf-8\");\n const result = renderSkillTemplate(raw, agentContext, renderOpts);\n for (const w of result.warnings) {\n const msg = `${profile.name}/${profile.sections[i]}: ${w}`;\n allWarnings.push(msg);\n log(` WARN ${msg}`);\n }\n renderedSections.push(result.rendered.trim());\n }\n\n const combined = renderedSections.join(\"\\n\\n\") + \"\\n\";\n for (const out of config.output) {\n const agentsDir = path.join(out, \"agent-profiles\");\n fs.mkdirSync(agentsDir, { recursive: true });\n fs.writeFileSync(\n path.join(agentsDir, `${profile.name}.md`),\n combined,\n \"utf-8\",\n );\n }\n\n log(` OK ${profile.name} → ${profile.name}.md (${combined.length} chars)`);\n count++;\n }\n\n return { count, warnings: allWarnings };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { renderSkillTemplate, slugToTitle } from \"../index.js\";\nimport type { ResolvedBuildConfig } from \"./types.js\";\n\n/**\n * Find the first existing directory across multiple include paths.\n */\nfunction findSubdir(includes: string[], subdir: string): string | undefined {\n for (const dir of includes) {\n const p = path.join(dir, subdir);\n if (fs.existsSync(p)) return p;\n }\n return undefined;\n}\n\n/**\n * Build SKILL.md files from Handlebars templates in skills-tpl/.\n * Each skill directory produces a SKILL.md + references/ folder.\n *\n * @returns Number of skills built and any warnings.\n */\nexport function buildSkillTemplates(config: ResolvedBuildConfig): {\n count: number;\n warnings: string[];\n} {\n const log = config.logger;\n const skillsTplSubdir = config.subdirs?.skillsTpl ?? \"skills-tpl\";\n const skillsTplDir = findSubdir(config.include, skillsTplSubdir);\n\n log(\"\\n--- Building SKILL.md files (templates) ---\");\n\n if (!skillsTplDir) {\n log(\" No skills-tpl/ directory — skipping.\");\n return { count: 0, warnings: [] };\n }\n\n const skillDirs = fs\n .readdirSync(skillsTplDir, { withFileTypes: true })\n .filter((d) => d.isDirectory())\n .map((d) => d.name)\n .sort();\n\n const allWarnings: string[] = [];\n const renderOpts = config.customHelpers\n ? { helpers: config.customHelpers }\n : undefined;\n let count = 0;\n\n for (const skillName of skillDirs) {\n const skillDir = path.join(skillsTplDir, skillName);\n\n // Preamble\n const preamblePath = path.join(skillDir, \".preamble.md\");\n const preambleRaw = fs.existsSync(preamblePath)\n ? fs.readFileSync(preamblePath, \"utf-8\").trim()\n : \"\";\n let preamble = \"\";\n if (preambleRaw) {\n const r = renderSkillTemplate(preambleRaw, config.context, renderOpts);\n preamble = r.rendered;\n for (const w of r.warnings) {\n const msg = `${skillName}/.preamble.md: ${w}`;\n allWarnings.push(msg);\n log(` WARN ${msg}`);\n }\n }\n\n // Scenario files (NN.name.md)\n const scenarioFiles = fs\n .readdirSync(skillDir)\n .filter((f) => /^\\d+\\..*\\.md$/.test(f))\n .sort();\n\n // Result file\n const resultPath = path.join(skillDir, \".result.md\");\n const hasResult = fs.existsSync(resultPath);\n\n if (!preamble && scenarioFiles.length === 0 && !hasResult) {\n log(` SKIP ${skillName}: no content files found`);\n continue;\n }\n\n // Render references into memory\n const files: Map<string, string> = new Map();\n const refLinks: string[] = [];\n\n for (const scenarioFile of scenarioFiles) {\n const content = fs\n .readFileSync(path.join(skillDir, scenarioFile), \"utf-8\")\n .trim();\n const r = renderSkillTemplate(content, config.context, renderOpts);\n for (const w of r.warnings) {\n const msg = `${skillName}/${scenarioFile}: ${w}`;\n allWarnings.push(msg);\n log(` WARN ${msg}`);\n }\n files.set(path.join(\"references\", scenarioFile), r.rendered + \"\\n\");\n const label = slugToTitle(\n scenarioFile.replace(/^\\d+\\./, \"\").replace(/\\.md$/, \"\"),\n );\n refLinks.push(\n `* **${label}** [references/${scenarioFile}](references/${scenarioFile})`,\n );\n }\n\n if (hasResult) {\n const content = fs.readFileSync(resultPath, \"utf-8\").trim();\n const r = renderSkillTemplate(content, config.context, renderOpts);\n for (const w of r.warnings) {\n const msg = `${skillName}/.result.md: ${w}`;\n allWarnings.push(msg);\n log(` WARN ${msg}`);\n }\n files.set(\n path.join(\"references\", \"expected-outcome.md\"),\n r.rendered + \"\\n\",\n );\n refLinks.push(\n `* **Expected Outcome** [references/expected-outcome.md](references/expected-outcome.md)`,\n );\n }\n\n // Build SKILL.md\n const description =\n config.skillDescriptions[skillName] ?? `${slugToTitle(skillName)} tasks`;\n\n const frontmatter = [\n \"---\",\n `name: ${skillName}`,\n `description: \"${description}\"`,\n \"metadata:\",\n \" author: Powerhouse\",\n ' version: \"1.0.0\"',\n \"---\",\n ].join(\"\\n\");\n\n const sections = [preamble];\n if (refLinks.length > 0) {\n sections.push(\"## Specific tasks\\n\\n\" + refLinks.join(\"\\n\"));\n }\n\n const skillMd =\n frontmatter + \"\\n\\n\" + sections.filter(Boolean).join(\"\\n\\n\") + \"\\n\";\n files.set(\"SKILL.md\", skillMd);\n\n // Copy .cli-docs.md if present (render through Handlebars)\n const cliDocsPath = path.join(skillDir, \".cli-docs.md\");\n if (fs.existsSync(cliDocsPath)) {\n const cliDocsRaw = fs.readFileSync(cliDocsPath, \"utf-8\").trim();\n if (cliDocsRaw) {\n const r = renderSkillTemplate(cliDocsRaw, config.context, renderOpts);\n for (const w of r.warnings) {\n const msg = `${skillName}/.cli-docs.md: ${w}`;\n allWarnings.push(msg);\n log(` WARN ${msg}`);\n }\n files.set(\".cli-docs.md\", r.rendered + \"\\n\");\n }\n }\n\n // Write to all output directories\n for (const out of config.output) {\n const outputDir = path.join(out, \"skills\", skillName);\n for (const [relPath, content] of files) {\n const fullPath = path.join(outputDir, relPath);\n fs.mkdirSync(path.dirname(fullPath), { recursive: true });\n fs.writeFileSync(fullPath, content, \"utf-8\");\n }\n }\n\n log(\n ` OK ${skillName} → SKILL.md + ${scenarioFiles.length + (hasResult ? 1 : 0)} references (${skillMd.length} chars)`,\n );\n count++;\n }\n\n return { count, warnings: allWarnings };\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { ResolvedBuildConfig } from \"./types.js\";\n\n/**\n * Copy external skills from skills-ext/ to the output directory without processing.\n *\n * @returns Number of skills copied.\n */\nexport function copyExternalSkills(config: ResolvedBuildConfig): number {\n const log = config.logger;\n const skillsExtSubdir = config.subdirs?.skillsExt ?? \"skills-ext\";\n\n log(\"\\n--- Copying external skills ---\");\n\n // Search all include dirs for skills-ext/\n let found = false;\n let total = 0;\n\n for (const dir of config.include) {\n const skillsExtDir = path.join(dir, skillsExtSubdir);\n if (!fs.existsSync(skillsExtDir)) continue;\n found = true;\n\n const skillDirs = fs\n .readdirSync(skillsExtDir, { withFileTypes: true })\n .filter((d) => d.isDirectory())\n .map((d) => d.name)\n .sort();\n\n for (const skillName of skillDirs) {\n const srcDir = path.join(skillsExtDir, skillName);\n for (const out of config.output) {\n fs.cpSync(srcDir, path.join(out, \"skills\", skillName), {\n recursive: true,\n });\n }\n log(` OK ${skillName} → copied as-is`);\n }\n\n total += skillDirs.length;\n }\n\n if (!found) {\n log(\" No skills-ext/ directory — skipping.\");\n }\n\n return total;\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { buildAgentProfiles } from \"./agent-profiles.js\";\nimport { buildSkillTemplates } from \"./skill-builder.js\";\nimport { copyExternalSkills } from \"./skill-copier.js\";\nimport type { AgentProfile, ResolvedBuildConfig } from \"./types.js\";\n\n/**\n * Path-driven skill/profile compilation (ph-clint-dev's pipeline, decoupled\n * from the old BuildConfig.cli metadata coupling). Conventions:\n *\n * <skillsDir>/ include root (default: prompts/ then agents/)\n * agent-profiles/ profile section templates\n * skills-tpl/<skill>/ Handlebars skill templates → SKILL.md\n * skills-ext/<skill>/ external skills copied as-is\n * profiles.json optional [{ name, sections: [...] }]\n *\n * Output: <outDir> (default: dist/skills).\n */\nexport interface BuildSkillsOptions {\n rootDir: string;\n skillsDir?: string;\n agentsDir?: string;\n outDir?: string;\n context?: Record<string, unknown>;\n logger?: (msg: string) => void;\n}\n\nexport interface BuildSkillsResult {\n skills: number;\n profiles: number;\n copied: number;\n warnings: string[];\n outDir: string;\n}\n\nfunction firstExisting(\n rootDir: string,\n candidates: (string | undefined)[],\n): string[] {\n const dirs: string[] = [];\n for (const candidate of candidates) {\n if (!candidate) continue;\n const abs = path.resolve(rootDir, candidate);\n if (fs.existsSync(abs)) dirs.push(abs);\n }\n return dirs;\n}\n\nfunction readProfilesManifest(include: string[]): AgentProfile[] {\n for (const dir of include) {\n const manifest = path.join(dir, \"profiles.json\");\n if (fs.existsSync(manifest)) {\n try {\n return JSON.parse(fs.readFileSync(manifest, \"utf8\")) as AgentProfile[];\n } catch {\n return [];\n }\n }\n }\n return [];\n}\n\nexport async function buildSkills(\n options: BuildSkillsOptions,\n): Promise<BuildSkillsResult> {\n const log = options.logger ?? console.log;\n const include = firstExisting(options.rootDir, [\n options.skillsDir,\n options.agentsDir,\n \"prompts\",\n \"agents\",\n ]);\n const outDir = path.resolve(options.rootDir, options.outDir ?? \"dist/skills\");\n\n if (include.length === 0) {\n log(\n \"No prompt template directories found (prompts/ or agents/) — nothing to build.\",\n );\n return { skills: 0, profiles: 0, copied: 0, warnings: [], outDir };\n }\n\n const resolved: ResolvedBuildConfig = {\n include,\n output: [outDir],\n context: { builtAt: new Date().toISOString(), ...options.context },\n agentProfiles: readProfilesManifest(include),\n skillDescriptions: {},\n clean: true,\n logger: log,\n };\n\n for (const dir of resolved.output) {\n if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true });\n }\n\n const profiles = buildAgentProfiles(resolved);\n const templates = buildSkillTemplates(resolved);\n const copied = copyExternalSkills(resolved);\n\n return {\n skills: templates.count,\n profiles: profiles.count,\n copied,\n warnings: [...profiles.warnings, ...templates.warnings],\n outDir,\n };\n}\n"],"mappings":";;;;;;;;AAQA,SAAS,eACP,UACA,QACA,UACoB;CACpB,KAAK,MAAM,OAAO,UAAU;EAC1B,MAAM,IAAI,KAAK,KAAK,KAAK,QAAQ,QAAQ;EACzC,IAAI,GAAG,WAAW,CAAC,GAAG,OAAO;CAC/B;AAEF;;;;;;;AAQA,SAAgB,mBAAmB,QAGjC;CACA,MAAM,MAAM,OAAO;CACnB,MAAM,WAAW,OAAO;CACxB,IAAI,SAAS,WAAW,GAAG,OAAO;EAAE,OAAO;EAAG,UAAU,CAAC;CAAE;CAE3D,MAAM,iBAAiB,OAAO,SAAS,YAAY;CAEnD,IAAI,uCAAuC;CAE3C,MAAM,cAAwB,CAAC;CAC/B,IAAI,QAAQ;CAEZ,KAAK,MAAM,WAAW,UAAU;EAE9B,MAAM,eAAyB,CAAC;EAChC,IAAI,UAAU;EACd,KAAK,MAAM,WAAW,QAAQ,UAAU;GACtC,MAAM,QAAQ,eAAe,OAAO,SAAS,gBAAgB,OAAO;GACpE,IAAI,CAAC,OAAO;IACV,IAAI,UAAU,QAAQ,KAAK,oBA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