-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathpostinstall.cjs
More file actions
85 lines (73 loc) · 2.53 KB
/
Copy pathpostinstall.cjs
File metadata and controls
85 lines (73 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env node
/*
* Refresh previously installed bundled Soku meta-skills after a global npm
* install. Business skills still update through `soku update skills`, because
* that path verifies catalog zip checksums and may need network access.
*/
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')
const MANIFEST_FILE = '.soku-skills.json'
const SOKU_META = 'soku'
function shouldRun() {
return process.env.npm_config_global === 'true' || process.env.npm_config_global === '1'
}
function copyDir(source, dest) {
fs.mkdirSync(dest, { recursive: true })
for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
const from = path.join(source, entry.name)
const to = path.join(dest, entry.name)
if (entry.isDirectory()) {
copyDir(from, to)
} else if (entry.isFile()) {
fs.copyFileSync(from, to)
}
}
}
function loadManifest(baseDir) {
try {
return JSON.parse(fs.readFileSync(path.join(baseDir, MANIFEST_FILE), 'utf8'))
} catch {
return {}
}
}
function hasSokuSkill(baseDir) {
const manifest = loadManifest(baseDir)
return (
Object.keys(manifest).length > 0 ||
fs.existsSync(path.join(baseDir, SOKU_META, 'SKILL.md'))
)
}
function refreshMetaSkill(baseDir, bundledDir) {
if (!hasSokuSkill(baseDir)) return
const dest = path.join(baseDir, SOKU_META)
fs.mkdirSync(dest, { recursive: true })
fs.rmSync(path.join(dest, 'SKILL.md'), { force: true })
fs.rmSync(path.join(dest, 'references'), { recursive: true, force: true })
fs.copyFileSync(path.join(bundledDir, 'SKILL.md'), path.join(dest, 'SKILL.md'))
const referencesDir = path.join(bundledDir, 'references')
if (fs.existsSync(referencesDir)) {
copyDir(referencesDir, path.join(dest, 'references'))
}
const manifest = loadManifest(baseDir)
manifest[SOKU_META] = {
sha256: '',
installed_at: new Date().toISOString(),
source: 'bundled',
}
fs.writeFileSync(path.join(baseDir, MANIFEST_FILE), `${JSON.stringify(manifest, null, 2)}\n`)
}
function main() {
if (!shouldRun()) return
const bundledDir = path.join(__dirname, 'skills', SOKU_META)
if (!fs.existsSync(path.join(bundledDir, 'SKILL.md'))) return
for (const agentDir of ['.claude/skills', '.codex/skills', '.cursor/skills']) {
try {
refreshMetaSkill(path.join(os.homedir(), agentDir), bundledDir)
} catch {
// Best-effort lifecycle hook: npm install must not fail because an agent
// skill directory is missing, locked, or otherwise temporarily unreadable.
}
}
}
main()