Merge pull request #39 from Askhz/feat/add-cosknow

feat: integrate cosknow — auto-install kb commands on postinstall
This commit is contained in:
geroge 2026-04-27 11:27:54 +08:00 committed by GitHub
commit fc78a84ccf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 2 deletions

View File

@ -36,7 +36,8 @@
"dist",
"scripts/postinstall.cjs",
"scripts/run-parallel.mjs",
"scripts/setup-chrome-mcp.mjs"
"scripts/setup-chrome-mcp.mjs",
"scripts/install-cosknow.mjs"
],
"scripts": {
"build": "bun run build.ts",
@ -53,7 +54,7 @@
"test": "bun test",
"check:unused": "knip-bun",
"health": "bun run scripts/health-check.ts",
"postinstall": "node scripts/run-parallel.mjs scripts/postinstall.cjs scripts/setup-chrome-mcp.mjs",
"postinstall": "node scripts/run-parallel.mjs scripts/postinstall.cjs scripts/setup-chrome-mcp.mjs scripts/install-cosknow.mjs",
"docs:dev": "npx mintlify dev",
"typecheck": "tsc --noEmit",
"rcs": "bun run scripts/rcs.ts"

View File

@ -0,0 +1,34 @@
import { spawnSync, execSync } from 'node:child_process'
import { join } from 'node:path'
import { pathToFileURL } from 'node:url'
// 全局安装最新版
spawnSync('npm', ['install', '-g', '@costrict/cosknow@latest'], {
stdio: 'inherit',
shell: true,
})
// 获取全局 node_modules 路径
let globalPrefix
try {
globalPrefix = execSync('npm root -g', { encoding: 'utf8' }).trim()
} catch {
console.warn('[cosknow] cannot determine global npm root, skipping')
process.exit(0)
}
let install
try {
const mod = await import(pathToFileURL(join(globalPrefix, '@costrict', 'cosknow', 'dist', 'index.js')).href)
install = mod.install
} catch {
console.warn('[cosknow] package not available, skipping command installation')
process.exit(0)
}
try {
await install({ target: 'claude-commands' })
console.log('[cosknow] commands installed to ~/.claude/commands/')
} catch (e) {
console.warn('[cosknow] install failed (non-fatal):', e.message)
}