From 997b83a313486c57752fcf89f1b70cb2118f1cbb Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Fri, 24 Apr 2026 11:35:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20integrate=20cosknow=20=E2=80=94=20a?= =?UTF-8?q?uto-install=20kb=20commands=20on=20postinstall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 ++++-- scripts/install-cosknow.mjs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 scripts/install-cosknow.mjs diff --git a/package.json b/package.json index 962b38e1e..fbe44e1ee 100644 --- a/package.json +++ b/package.json @@ -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" @@ -61,6 +62,7 @@ "dependencies": { "@agentclientprotocol/sdk": "^0.19.0", "@claude-code-best/mcp-chrome-bridge": "^2.0.8", + "cosknow": "latest", "ws": "^8.20.0" }, "devDependencies": { diff --git a/scripts/install-cosknow.mjs b/scripts/install-cosknow.mjs new file mode 100644 index 000000000..31656515b --- /dev/null +++ b/scripts/install-cosknow.mjs @@ -0,0 +1,15 @@ +let install +try { + const mod = await import('cosknow') + 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) +} From 9456adc087f0dd28b8fe9ea63716ea16f16a3643 Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Fri, 24 Apr 2026 19:09:52 +0800 Subject: [PATCH 2/2] fix: install cosknow globally to always fetch latest version --- package.json | 1 - scripts/install-cosknow.mjs | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fbe44e1ee..f9d384346 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,6 @@ "dependencies": { "@agentclientprotocol/sdk": "^0.19.0", "@claude-code-best/mcp-chrome-bridge": "^2.0.8", - "cosknow": "latest", "ws": "^8.20.0" }, "devDependencies": { diff --git a/scripts/install-cosknow.mjs b/scripts/install-cosknow.mjs index 31656515b..4bd5e2a86 100644 --- a/scripts/install-cosknow.mjs +++ b/scripts/install-cosknow.mjs @@ -1,6 +1,25 @@ +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('cosknow') + 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')