@voltui/agent 0.0.0-stage → 0.6.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.
package/skills.js ADDED
@@ -0,0 +1,74 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * The Volt UI agent skills, read from `cli/agent/skills/<name>/SKILL.md` — the one copy. The
5
+ * installer writes them for agents that load skills (Claude Code, Codex, OpenCode); for agents that
6
+ * only read a rules file it writes `routingBlock()`, built from the same files, so a rules file and
7
+ * a skill cannot say different things.
8
+ *
9
+ * Each SKILL.md carries a `<!-- volt:digest:start/end -->` section: the few rules an agent needs when
10
+ * it cannot load the skill itself.
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+
16
+ const SKILLS_DIR = path.join(__dirname, 'skills');
17
+ const DIGEST = /<!-- volt:digest:start -->\n([\s\S]*?)\n<!-- volt:digest:end -->/;
18
+
19
+ /** `volt-ui` first (the router), then the rest alphabetically. */
20
+ function skillNames() {
21
+ return fs
22
+ .readdirSync(SKILLS_DIR, { withFileTypes: true })
23
+ .filter(d => d.isDirectory() && fs.existsSync(path.join(SKILLS_DIR, d.name, 'SKILL.md')))
24
+ .map(d => d.name)
25
+ .sort((a, b) => (a === 'volt-ui' ? -1 : b === 'volt-ui' ? 1 : a.localeCompare(b)));
26
+ }
27
+
28
+ /** @returns {Record<string, string>} skill name → full SKILL.md text */
29
+ function loadSkills() {
30
+ return Object.fromEntries(
31
+ skillNames().map(n => [n, fs.readFileSync(path.join(SKILLS_DIR, n, 'SKILL.md'), 'utf8')])
32
+ );
33
+ }
34
+
35
+ /** Name and (folded) description from the YAML frontmatter. */
36
+ function describe(text) {
37
+ const front = text.match(/^---\n([\s\S]*?)\n---/)?.[1] ?? '';
38
+ const name = front.match(/^name:\s*(.+)$/m)?.[1]?.trim() ?? '';
39
+ const desc = front.match(/^description:\s*>?\s*\n?([\s\S]*)$/m)?.[1] ?? '';
40
+ const description = desc
41
+ .split('\n')
42
+ .map(l => l.trim())
43
+ .filter(Boolean)
44
+ .join(' ');
45
+ return { name, description };
46
+ }
47
+
48
+ function digestOf(text) {
49
+ return text.match(DIGEST)?.[1]?.trim() ?? '';
50
+ }
51
+
52
+ /**
53
+ * The block for agents that read a rules file but do not load skills. Short on purpose: the
54
+ * facts live in the MCP server, the decisions in the digests below.
55
+ */
56
+ function routingBlock(mcpUrl) {
57
+ const skills = loadSkills();
58
+ const sections = Object.entries(skills)
59
+ .filter(([name]) => name !== 'volt-ui')
60
+ .map(([name, text]) => `### ${name.replace('volt-ui-', '')}\n${digestOf(text)}`)
61
+ .join('\n\n');
62
+ return `# Volt UI (Angular)
63
+
64
+ ${digestOf(skills['volt-ui'])}
65
+
66
+ MCP server \`volt-ui\` (${mcpUrl}): \`list_components\`, \`find_components\`, \`get_component\`, \`get_usage_example\`, \`get_theme_info\`, \`generate_cli_command\`.
67
+
68
+ ## Playbooks
69
+
70
+ ${sections}
71
+ `;
72
+ }
73
+
74
+ module.exports = { SKILLS_DIR, skillNames, loadSkills, describe, digestOf, routingBlock };