@vox-ai-app/skills 1.0.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/LICENSE +21 -0
- package/package.json +29 -0
- package/src/index.js +3 -0
- package/src/loader.js +117 -0
- package/src/parser.js +73 -0
- package/src/prompt.js +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arnav Gupta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vox-ai-app/skills",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"description": "AgentSkills-compatible skill loader for Vox — load SKILL.md folders, parse frontmatter, inject into LLM prompts",
|
|
7
|
+
"main": "./src/index.js",
|
|
8
|
+
"private": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.js",
|
|
11
|
+
"./loader": "./src/loader.js",
|
|
12
|
+
"./parser": "./src/parser.js",
|
|
13
|
+
"./prompt": "./src/prompt.js"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/vox-ai-app/vox"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {}
|
|
29
|
+
}
|
package/src/index.js
ADDED
package/src/loader.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { parseFrontmatter } from './parser.js'
|
|
4
|
+
|
|
5
|
+
function isPathInside(parent, child) {
|
|
6
|
+
const rel = path.relative(parent, child)
|
|
7
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function loadSingleSkill(skillDir, source, rootReal, maxBytes) {
|
|
11
|
+
const skillPath = path.join(skillDir, 'SKILL.md')
|
|
12
|
+
let raw
|
|
13
|
+
try {
|
|
14
|
+
const stat = fs.statSync(skillPath)
|
|
15
|
+
if (maxBytes && stat.size > maxBytes) return null
|
|
16
|
+
raw = fs.readFileSync(skillPath, 'utf8')
|
|
17
|
+
} catch {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const resolved = fs.realpathSync(skillPath)
|
|
22
|
+
if (!isPathInside(rootReal, resolved) && resolved !== rootReal) {
|
|
23
|
+
const skillReal = fs.realpathSync(skillDir)
|
|
24
|
+
if (!isPathInside(rootReal, skillReal) && skillReal !== rootReal) return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { fields, body } = parseFrontmatter(raw)
|
|
28
|
+
const fallbackName = path.basename(skillDir).trim()
|
|
29
|
+
const name = fields.name?.trim() || fallbackName
|
|
30
|
+
const description = fields.description?.trim()
|
|
31
|
+
if (!name || !description) return null
|
|
32
|
+
|
|
33
|
+
const metadata = fields.metadata || null
|
|
34
|
+
const userInvocable = fields['user-invocable'] !== 'false'
|
|
35
|
+
const disableModelInvocation = fields['disable-model-invocation'] === 'true'
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
name,
|
|
39
|
+
description,
|
|
40
|
+
filePath: path.resolve(skillPath),
|
|
41
|
+
baseDir: path.resolve(skillDir),
|
|
42
|
+
body,
|
|
43
|
+
source,
|
|
44
|
+
metadata,
|
|
45
|
+
userInvocable,
|
|
46
|
+
disableModelInvocation
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function listSkillDirs(dir) {
|
|
51
|
+
try {
|
|
52
|
+
return fs.readdirSync(dir, { withFileTypes: true })
|
|
53
|
+
.filter(e => e.isDirectory() && !e.name.startsWith('.') && e.name !== 'node_modules')
|
|
54
|
+
.map(e => path.join(dir, e.name))
|
|
55
|
+
.sort()
|
|
56
|
+
} catch {
|
|
57
|
+
return []
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function loadSkillsFromDir(dir, source, opts = {}) {
|
|
62
|
+
const maxBytes = opts.maxBytes || 256_000
|
|
63
|
+
const maxSkills = opts.maxSkills || 200
|
|
64
|
+
let rootReal
|
|
65
|
+
try {
|
|
66
|
+
rootReal = fs.realpathSync(path.resolve(dir))
|
|
67
|
+
} catch {
|
|
68
|
+
return []
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const single = loadSingleSkill(rootReal, source, rootReal, maxBytes)
|
|
72
|
+
if (single) return [single]
|
|
73
|
+
|
|
74
|
+
const candidates = listSkillDirs(rootReal).slice(0, maxSkills)
|
|
75
|
+
const skills = []
|
|
76
|
+
for (const candidate of candidates) {
|
|
77
|
+
const skill = loadSingleSkill(candidate, source, rootReal, maxBytes)
|
|
78
|
+
if (skill) skills.push(skill)
|
|
79
|
+
}
|
|
80
|
+
return skills
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function loadAllSkills(skillDirs, opts = {}) {
|
|
84
|
+
const maxTotal = opts.maxTotal || 150
|
|
85
|
+
const all = []
|
|
86
|
+
const seen = new Set()
|
|
87
|
+
|
|
88
|
+
for (const { dir, source } of skillDirs) {
|
|
89
|
+
const skills = loadSkillsFromDir(dir, source, opts)
|
|
90
|
+
for (const skill of skills) {
|
|
91
|
+
if (seen.has(skill.name)) continue
|
|
92
|
+
seen.add(skill.name)
|
|
93
|
+
all.push(skill)
|
|
94
|
+
if (all.length >= maxTotal) return all
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return all
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function resolveDefaultSkillDirs(workspace) {
|
|
101
|
+
const home = process.env.HOME || process.env.USERPROFILE || ''
|
|
102
|
+
const dirs = []
|
|
103
|
+
|
|
104
|
+
if (workspace) {
|
|
105
|
+
dirs.push({ dir: path.join(workspace, 'skills'), source: 'workspace' })
|
|
106
|
+
dirs.push({ dir: path.join(workspace, '.agents', 'skills'), source: 'project-agent' })
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (home) {
|
|
110
|
+
dirs.push({ dir: path.join(home, '.agents', 'skills'), source: 'personal-agent' })
|
|
111
|
+
dirs.push({ dir: path.join(home, '.vox', 'skills'), source: 'managed' })
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return dirs.filter(d => {
|
|
115
|
+
try { return fs.statSync(d.dir).isDirectory() } catch { return false }
|
|
116
|
+
})
|
|
117
|
+
}
|
package/src/parser.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---/
|
|
2
|
+
|
|
3
|
+
function parseYamlLine(line) {
|
|
4
|
+
const idx = line.indexOf(':')
|
|
5
|
+
if (idx === -1) return null
|
|
6
|
+
const key = line.slice(0, idx).trim()
|
|
7
|
+
let value = line.slice(idx + 1).trim()
|
|
8
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
9
|
+
value = value.slice(1, -1)
|
|
10
|
+
}
|
|
11
|
+
return { key, value }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseFrontmatter(content) {
|
|
15
|
+
const match = content.match(FRONTMATTER_RE)
|
|
16
|
+
if (!match) return { fields: {}, body: content }
|
|
17
|
+
|
|
18
|
+
const raw = match[1]
|
|
19
|
+
const fields = {}
|
|
20
|
+
let metadataJson = null
|
|
21
|
+
let collectingMetadata = false
|
|
22
|
+
let metadataBuf = ''
|
|
23
|
+
|
|
24
|
+
for (const line of raw.split('\n')) {
|
|
25
|
+
const trimmed = line.trim()
|
|
26
|
+
|
|
27
|
+
if (collectingMetadata) {
|
|
28
|
+
metadataBuf += trimmed
|
|
29
|
+
let depth = 0
|
|
30
|
+
for (const ch of metadataBuf) {
|
|
31
|
+
if (ch === '{') depth++
|
|
32
|
+
if (ch === '}') depth--
|
|
33
|
+
}
|
|
34
|
+
if (depth <= 0) {
|
|
35
|
+
collectingMetadata = false
|
|
36
|
+
try {
|
|
37
|
+
metadataJson = JSON.parse(metadataBuf)
|
|
38
|
+
} catch {
|
|
39
|
+
metadataJson = null
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (trimmed.startsWith('metadata:')) {
|
|
46
|
+
const rest = trimmed.slice('metadata:'.length).trim()
|
|
47
|
+
if (rest.startsWith('{')) {
|
|
48
|
+
metadataBuf = rest
|
|
49
|
+
let depth = 0
|
|
50
|
+
for (const ch of metadataBuf) {
|
|
51
|
+
if (ch === '{') depth++
|
|
52
|
+
if (ch === '}') depth--
|
|
53
|
+
}
|
|
54
|
+
if (depth <= 0) {
|
|
55
|
+
try { metadataJson = JSON.parse(metadataBuf) } catch { /* skip */ }
|
|
56
|
+
} else {
|
|
57
|
+
collectingMetadata = true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (line.startsWith(' ') || line.startsWith('\t')) continue
|
|
64
|
+
|
|
65
|
+
const parsed = parseYamlLine(trimmed)
|
|
66
|
+
if (parsed) fields[parsed.key] = parsed.value
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (metadataJson) fields.metadata = metadataJson
|
|
70
|
+
|
|
71
|
+
const body = content.slice(match[0].length).trim()
|
|
72
|
+
return { fields, body }
|
|
73
|
+
}
|
package/src/prompt.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os from 'node:os'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
function escapeXml(str) {
|
|
5
|
+
return str
|
|
6
|
+
.replace(/&/g, '&')
|
|
7
|
+
.replace(/</g, '<')
|
|
8
|
+
.replace(/>/g, '>')
|
|
9
|
+
.replace(/"/g, '"')
|
|
10
|
+
.replace(/'/g, ''')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function compactPath(filePath) {
|
|
14
|
+
const home = os.homedir()
|
|
15
|
+
if (!home) return filePath
|
|
16
|
+
const prefix = home.endsWith(path.sep) ? home : home + path.sep
|
|
17
|
+
return filePath.startsWith(prefix) ? '~/' + filePath.slice(prefix.length) : filePath
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function formatSkillsForPrompt(skills) {
|
|
21
|
+
const visible = skills.filter(s => !s.disableModelInvocation)
|
|
22
|
+
if (visible.length === 0) return ''
|
|
23
|
+
|
|
24
|
+
const lines = [
|
|
25
|
+
'',
|
|
26
|
+
'The following skills provide specialized instructions for specific tasks.',
|
|
27
|
+
'When the task matches a skill description, read its file to get detailed instructions.',
|
|
28
|
+
'',
|
|
29
|
+
'<available_skills>'
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
for (const skill of visible) {
|
|
33
|
+
lines.push(' <skill>')
|
|
34
|
+
lines.push(` <name>${escapeXml(skill.name)}</name>`)
|
|
35
|
+
lines.push(` <description>${escapeXml(skill.description)}</description>`)
|
|
36
|
+
lines.push(` <location>${escapeXml(compactPath(skill.filePath))}</location>`)
|
|
37
|
+
lines.push(' </skill>')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
lines.push('</available_skills>')
|
|
41
|
+
return lines.join('\n')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function formatSkillBody(skill) {
|
|
45
|
+
if (!skill.body) return ''
|
|
46
|
+
return `\n\n--- Skill: ${skill.name} ---\n${skill.body}\n--- End Skill ---`
|
|
47
|
+
}
|