Initial commit: ai4se-harness-suite
Import harness suite (skills, installers, overnight-runner, docs) as a fresh history for InspireChina. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
51
tool-chain-installer/README.md
Normal file
51
tool-chain-installer/README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# tool-chain-installer
|
||||
|
||||
把 MCP 工具链写进项目配置,**不依赖开发机的全局状态**。
|
||||
|
||||
```
|
||||
tool-chain-installer/
|
||||
├── SKILL.md
|
||||
├── scripts/install-tools.mjs
|
||||
└── catalog/mcp-catalog.json # 工具清单(可自行扩展)
|
||||
```
|
||||
|
||||
## 用法
|
||||
|
||||
```bash
|
||||
# 看清单
|
||||
node tool-chain-installer/scripts/install-tools.mjs --list
|
||||
|
||||
# 装浏览器 + 上下文工具
|
||||
node tool-chain-installer/scripts/install-tools.mjs ../my-project --group browser --group context
|
||||
|
||||
# 按名称
|
||||
node tool-chain-installer/scripts/install-tools.mjs ../my-project --tools chrome-devtools,playwright
|
||||
|
||||
# 全部 + 预览
|
||||
node tool-chain-installer/scripts/install-tools.mjs ../my-project --all --dry-run
|
||||
```
|
||||
|
||||
## 写入位置
|
||||
|
||||
| 文件 | 键名 | 适用 |
|
||||
|---|---|---|
|
||||
| `.mcp.json` | `mcpServers` | Claude Code / 通用 MCP 客户端 |
|
||||
| `opencode.jsonc` | `mcp` | opencode 原生格式 |
|
||||
|
||||
两个文件默认都写(`--format both`)。已有配置会被 **合并**,其他字段保留。
|
||||
|
||||
## 现有工具
|
||||
|
||||
| 分组 | 工具 | 用途 |
|
||||
|---|---|---|
|
||||
| browser | `chrome-devtools` | 调试:导航 / 截图 / 控制台 / 网络 / 性能 |
|
||||
| browser | `playwright` | 浏览器自动化 |
|
||||
| context | `context7` | 拉最新官方文档 |
|
||||
| context | `sequential-thinking` | 结构化推理 |
|
||||
| data | `filesystem` | 限定目录文件读写 |
|
||||
| data | `git` | 仓库历史 / 分支 / diff |
|
||||
| observability | `sentry` | 线上错误排查(需 `SENTRY_TOKEN`) |
|
||||
|
||||
## 扩展
|
||||
|
||||
编辑 `catalog/mcp-catalog.json` 加一项即可,脚本自动读取。
|
||||
97
tool-chain-installer/SKILL.md
Normal file
97
tool-chain-installer/SKILL.md
Normal file
@@ -0,0 +1,97 @@
|
||||
---
|
||||
name: tool-chain-installer
|
||||
description: 安装 MCP 工具链(chrome-devtools / playwright / context7 / sequential-thinking / filesystem / git / sentry 等)到指定项目。当用户说"装 MCP"、"安装工具链"、"配置 chrome-devtools"、"把 playwright 装上"、"tool chain 安装"时使用。
|
||||
---
|
||||
|
||||
# 工具链安装器
|
||||
|
||||
把 MCP 工具链写进项目配置,**不依赖开发机的全局状态** —— 换一台机器 clone 下来就能跑。
|
||||
|
||||
## 可用工具
|
||||
|
||||
| 分组 | 工具 | 用途 | 谁用 |
|
||||
|---|---|---|---|
|
||||
| `browser` | `chrome-devtools` | 页面导航、截图、无障碍树、控制台、网络、性能追踪 | `dev-debug` |
|
||||
| `browser` | `playwright` | 跨浏览器自动化、截图、表单填写 | `dev-debug`、QA |
|
||||
| `context` | `context7` | 拉取框架/库的最新官方文档 | `dev-build` |
|
||||
| `context` | `sequential-thinking` | 结构化推理,拆解复杂任务 | `dev-plan` |
|
||||
| `data` | `filesystem` | 限定目录范围内的文件读写 | 通用 |
|
||||
| `data` | `git` | 查询仓库历史、分支、diff | 通用 |
|
||||
| `observability` | `sentry` | 线上错误排查(需 `SENTRY_TOKEN`) | `dev-debug` |
|
||||
|
||||
完整清单以 [`catalog/mcp-catalog.json`](catalog/mcp-catalog.json) 为准,脚本会读取它。
|
||||
|
||||
## 执行
|
||||
|
||||
```bash
|
||||
# 查看全部可用工具
|
||||
node tool-chain-installer/scripts/install-tools.mjs --list
|
||||
|
||||
# 按分组安装
|
||||
node tool-chain-installer/scripts/install-tools.mjs <目标项目目录> --group browser --group context
|
||||
|
||||
# 按名称安装
|
||||
node tool-chain-installer/scripts/install-tools.mjs <目标项目目录> --tools chrome-devtools,playwright
|
||||
|
||||
# 全部安装
|
||||
node tool-chain-installer/scripts/install-tools.mjs <目标项目目录> --all
|
||||
|
||||
# 先预览
|
||||
node tool-chain-installer/scripts/install-tools.mjs <目标项目目录> --all --dry-run
|
||||
```
|
||||
|
||||
| 参数 | 说明 |
|
||||
|---|---|
|
||||
| `--tools <a,b>` | 按名称安装 |
|
||||
| `--group <name>` | 按分组安装,可重复 |
|
||||
| `--all` | 安装全部 |
|
||||
| `--dry-run` | 只打印将要发生的改动 |
|
||||
| `--format <fmt>` | `both`(默认) \| `mcp-json` \| `opencode` |
|
||||
|
||||
## 写入哪些文件
|
||||
|
||||
| 文件 | 写入位置 | 用途 |
|
||||
|---|---|---|
|
||||
| `.mcp.json` | `mcpServers.<name>.{command,args,env}` | Claude Code / 通用 MCP 客户端 |
|
||||
| `opencode.jsonc` | `mcp.<name>.{type,command,enabled,environment}` | opencode 原生格式 |
|
||||
|
||||
脚本会 **合并** 进已有配置,不会覆盖 `skills` 等其他字段;同名工具以本次配置为准。
|
||||
|
||||
## 密钥处理
|
||||
|
||||
需要密钥的工具(如 `sentry`)在配置里写占位引用,**不要把真值写进仓库**:
|
||||
|
||||
```json
|
||||
{ "env": { "SENTRY_TOKEN": "{env:SENTRY_TOKEN}" } }
|
||||
```
|
||||
|
||||
开发者自行 `export SENTRY_TOKEN=xxx`。opencode 配置里用 `{env:VAR}`,MCP 的 `env` 字段里同样用 `{env:VAR}`。
|
||||
|
||||
## 加一个新工具
|
||||
|
||||
编辑 `catalog/mcp-catalog.json`,在对应分组里加一项:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my-tool",
|
||||
"description": "一句话说明",
|
||||
"package": "my-mcp@1.2.3",
|
||||
"command": "npx",
|
||||
"args": ["-y", "my-mcp@1.2.3"],
|
||||
"env": {},
|
||||
"usedBy": ["dev-build"]
|
||||
}
|
||||
```
|
||||
|
||||
`package` 只是给人看的说明,真正生效的是 `command` + `args`。
|
||||
|
||||
## 注意
|
||||
|
||||
- MCP 配置在 opencode **启动时加载,不热更新** —— 装完必须重启 opencode。
|
||||
- `npx -y <pkg>@latest` 每次启动都会检查 registry,离线环境会失败;内网请改用固定版本 + 本地安装。
|
||||
- 装完在项目里记一笔:`docs/standards/toolchain.md`,方便交接。
|
||||
|
||||
## 相关
|
||||
|
||||
- `agile-team-sdd/` — `dev-debug` 依赖本目录装的 `chrome-devtools`
|
||||
- `harness-installer/` — 装 MCP 之前应先铺好 `AGENTS.md` 与 `docs/`
|
||||
73
tool-chain-installer/catalog/mcp-catalog.json
Normal file
73
tool-chain-installer/catalog/mcp-catalog.json
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"browser": [
|
||||
{
|
||||
"name": "chrome-devtools",
|
||||
"description": "Chrome DevTools MCP:页面导航、截图、无障碍树、控制台、网络请求、性能追踪",
|
||||
"package": "chrome-devtools-mcp@latest",
|
||||
"command": "npx",
|
||||
"args": ["-y", "chrome-devtools-mcp@latest"],
|
||||
"env": {},
|
||||
"usedBy": ["dev-debug"]
|
||||
},
|
||||
{
|
||||
"name": "playwright",
|
||||
"description": "Playwright MCP:跨浏览器自动化操作、截图、表单填写",
|
||||
"package": "@playwright/mcp@latest",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@playwright/mcp@latest", "--browser", "chromium"],
|
||||
"env": {},
|
||||
"usedBy": ["dev-debug", "qa"]
|
||||
}
|
||||
],
|
||||
"context": [
|
||||
{
|
||||
"name": "context7",
|
||||
"description": "Context7:拉取框架/库的最新版官方文档",
|
||||
"package": "context7-mcp@latest",
|
||||
"command": "npx",
|
||||
"args": ["-y", "context7-mcp@latest"],
|
||||
"env": {},
|
||||
"usedBy": ["dev-build"]
|
||||
},
|
||||
{
|
||||
"name": "sequential-thinking",
|
||||
"description": "Sequential Thinking MCP:结构化推理,拆解复杂任务",
|
||||
"package": "@modelcontextprotocol/server-sequential-thinking@latest",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-sequential-thinking@latest"],
|
||||
"env": {},
|
||||
"usedBy": ["dev-plan"]
|
||||
}
|
||||
],
|
||||
"data": [
|
||||
{
|
||||
"name": "filesystem",
|
||||
"description": "Filesystem MCP:限定目录范围内的文件读写",
|
||||
"package": "@modelcontextprotocol/server-filesystem@latest",
|
||||
"command": "npx",
|
||||
"args": ["-y", "@modelcontextprotocol/server-filesystem@latest", "."],
|
||||
"env": {},
|
||||
"usedBy": []
|
||||
},
|
||||
{
|
||||
"name": "git",
|
||||
"description": "Git MCP:查询仓库历史、分支、diff",
|
||||
"package": "mcp-server-git@latest",
|
||||
"command": "uvx",
|
||||
"args": ["mcp-server-git", "--repository", "."],
|
||||
"env": {},
|
||||
"usedBy": []
|
||||
}
|
||||
],
|
||||
"observability": [
|
||||
{
|
||||
"name": "sentry",
|
||||
"description": "Sentry MCP:线上错误与性能问题排查(需 SENTRY_TOKEN)",
|
||||
"package": "mcp-remote",
|
||||
"command": "npx",
|
||||
"args": ["-y", "mcp-remote", "https://mcp.sentry.dev/mcp"],
|
||||
"env": { "SENTRY_TOKEN": "{env:SENTRY_TOKEN}" },
|
||||
"usedBy": ["dev-debug"]
|
||||
}
|
||||
]
|
||||
}
|
||||
222
tool-chain-installer/scripts/install-tools.mjs
Executable file
222
tool-chain-installer/scripts/install-tools.mjs
Executable file
@@ -0,0 +1,222 @@
|
||||
#!/usr/bin/env node
|
||||
// 安装 MCP 工具链到指定项目。
|
||||
//
|
||||
// 用法:
|
||||
// node install-tools.mjs <目标项目目录> [选项]
|
||||
//
|
||||
// --tools <a,b,c> 安装指定工具(逗号分隔)
|
||||
// --group <name> 安装某一组(browser / context / data / observability)
|
||||
// --all 安装全部
|
||||
// --dry-run 只打印将要发生的改动
|
||||
// --format <fmt> 写入格式:both(默认) | mcp-json | opencode
|
||||
// --list 列出所有可用工具并退出
|
||||
|
||||
import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
const HERE = path.dirname(fileURLToPath(import.meta.url))
|
||||
const CATALOG_PATH = path.join(HERE, "..", "catalog", "mcp-catalog.json")
|
||||
|
||||
// ── 参数解析 ────────────────────────────────────────────────────────
|
||||
const args = process.argv.slice(2)
|
||||
const opts = { tools: [], groups: [], all: false, dryRun: false, format: "both", list: false }
|
||||
let target = null
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const a = args[i]
|
||||
switch (a) {
|
||||
case "--tools": opts.tools = (args[++i] || "").split(",").map(s => s.trim()).filter(Boolean); break
|
||||
case "--group": opts.groups.push(args[++i]); break
|
||||
case "--all": opts.all = true; break
|
||||
case "--dry-run": opts.dryRun = true; break
|
||||
case "--format": opts.format = args[++i] || "both"; break
|
||||
case "--list": opts.list = true; break
|
||||
case "-h": case "--help": printUsage(0); break
|
||||
default:
|
||||
if (a.startsWith("-")) { console.error(`未知参数: ${a}`); printUsage(1) }
|
||||
target = a
|
||||
}
|
||||
}
|
||||
|
||||
function printUsage(code) {
|
||||
console.log(fs.readFileSync(fileURLToPath(import.meta.url), "utf8").split("\n").slice(1, 11).map(l => l.replace(/^#\s?/, "")).join("\n"))
|
||||
process.exit(code)
|
||||
}
|
||||
|
||||
// ── 目录 ────────────────────────────────────────────────────────────
|
||||
const catalog = JSON.parse(fs.readFileSync(CATALOG_PATH, "utf8"))
|
||||
|
||||
if (opts.list) {
|
||||
for (const [group, items] of Object.entries(catalog)) {
|
||||
console.log(`\n${group}`)
|
||||
for (const t of items) {
|
||||
console.log(` ${t.name.padEnd(20)} ${t.description}`)
|
||||
console.log(` ${"".padEnd(20)} → ${t.command} ${t.args.join(" ")}`)
|
||||
}
|
||||
}
|
||||
console.log("")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (!target) {
|
||||
console.error("错误:缺少目标项目目录。")
|
||||
printUsage(1)
|
||||
}
|
||||
if (!fs.existsSync(target)) {
|
||||
console.error(`错误:目标目录不存在: ${target}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const PROJECT_ROOT = fs.realpathSync(target)
|
||||
|
||||
// ── 选择工具 ────────────────────────────────────────────────────────
|
||||
const selected = []
|
||||
if (opts.all) {
|
||||
for (const items of Object.values(catalog)) selected.push(...items)
|
||||
}
|
||||
for (const g of opts.groups) {
|
||||
const items = catalog[g]
|
||||
if (!items) {
|
||||
console.error(`错误:未知分组 "${g}"。可用分组:${Object.keys(catalog).join(", ")}`)
|
||||
process.exit(1)
|
||||
}
|
||||
selected.push(...items)
|
||||
}
|
||||
if (opts.tools.length) {
|
||||
const all = Object.values(catalog).flat()
|
||||
for (const name of opts.tools) {
|
||||
const found = all.find(t => t.name === name)
|
||||
if (!found) {
|
||||
console.error(`错误:未知工具 "${name}"。用 --list 查看全部。`)
|
||||
process.exit(1)
|
||||
}
|
||||
selected.push(found)
|
||||
}
|
||||
}
|
||||
if (!selected.length) {
|
||||
console.error("错误:没有指定要安装的工具。用 --tools / --group / --all 指定。")
|
||||
printUsage(1)
|
||||
}
|
||||
|
||||
// 去重
|
||||
const unique = [...new Map(selected.map(t => [t.name, t])).values()]
|
||||
|
||||
// ── JSONC 容忍解析 / 写回 ──────────────────────────────────────────
|
||||
function stripJsonComments(text) {
|
||||
let out = ""
|
||||
let inString = false
|
||||
let inLine = false
|
||||
let inBlock = false
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const c = text[i]
|
||||
const n = text[i + 1]
|
||||
if (inLine) {
|
||||
if (c === "\n") { inLine = false; out += c }
|
||||
continue
|
||||
}
|
||||
if (inBlock) {
|
||||
if (c === "*" && n === "/") { inBlock = false; i++ }
|
||||
continue
|
||||
}
|
||||
if (inString) {
|
||||
out += c
|
||||
if (c === "\\") { out += n ?? ""; i++; continue }
|
||||
if (c === '"') inString = false
|
||||
continue
|
||||
}
|
||||
if (c === '"') { inString = true; out += c; continue }
|
||||
if (c === "/" && n === "/") { inLine = true; i++; continue }
|
||||
if (c === "/" && n === "*") { inBlock = true; i++; continue }
|
||||
out += c
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function readJsonc(file) {
|
||||
if (!fs.existsSync(file)) return null
|
||||
const raw = fs.readFileSync(file, "utf8")
|
||||
try {
|
||||
return JSON.parse(stripJsonComments(raw))
|
||||
} catch (e) {
|
||||
console.error(`错误:无法解析 ${file} —— ${e.message}`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
function writeJson(file, data) {
|
||||
fs.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8")
|
||||
}
|
||||
|
||||
// ── 安装 ────────────────────────────────────────────────────────────
|
||||
console.log("MCP 工具链安装器")
|
||||
console.log(` 目标项目 : ${PROJECT_ROOT}`)
|
||||
console.log(` 写入格式 : ${opts.format}`)
|
||||
console.log(` 待安装 : ${unique.map(t => t.name).join(", ")}`)
|
||||
console.log("")
|
||||
|
||||
const writeMcpJson = opts.format === "both" || opts.format === "mcp-json"
|
||||
const writeOpencode = opts.format === "both" || opts.format === "opencode"
|
||||
|
||||
const mcpJsonPath = path.join(PROJECT_ROOT, ".mcp.json")
|
||||
const opencodePath = path.join(PROJECT_ROOT, "opencode.jsonc")
|
||||
|
||||
if (writeMcpJson) {
|
||||
const existing = readJsonc(mcpJsonPath) || {}
|
||||
if (!existing.mcpServers) existing.mcpServers = {}
|
||||
for (const t of unique) {
|
||||
existing.mcpServers[t.name] = {
|
||||
command: t.command,
|
||||
args: t.args,
|
||||
...(t.env && Object.keys(t.env).length ? { env: t.env } : {})
|
||||
}
|
||||
}
|
||||
if (opts.dryRun) {
|
||||
console.log(` [计划] 写入 ${mcpJsonPath}`)
|
||||
} else {
|
||||
writeJson(mcpJsonPath, existing)
|
||||
console.log(` [写入] ${mcpJsonPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (writeOpencode) {
|
||||
const existing = readJsonc(opencodePath) || { $schema: "https://opencode.ai/config.json" }
|
||||
if (!existing.$schema) existing.$schema = "https://opencode.ai/config.json"
|
||||
if (!existing.mcp) existing.mcp = {}
|
||||
for (const t of unique) {
|
||||
existing.mcp[t.name] = {
|
||||
type: "local",
|
||||
command: [t.command, ...t.args],
|
||||
enabled: true,
|
||||
...(t.env && Object.keys(t.env).length ? { environment: t.env } : {})
|
||||
}
|
||||
}
|
||||
if (opts.dryRun) {
|
||||
console.log(` [计划] 写入 ${opencodePath}`)
|
||||
} else {
|
||||
writeJson(opencodePath, existing)
|
||||
console.log(` [写入] ${opencodePath}`)
|
||||
}
|
||||
}
|
||||
|
||||
// ── 报告 ────────────────────────────────────────────────────────────
|
||||
console.log("")
|
||||
console.log("已配置的工具:")
|
||||
for (const t of unique) {
|
||||
const used = t.usedBy?.length ? `(供 ${t.usedBy.join(", ")} 使用)` : ""
|
||||
console.log(` - ${t.name.padEnd(20)} ${t.description} ${used}`)
|
||||
}
|
||||
|
||||
const needsEnv = unique.filter(t => t.env && Object.keys(t.env).length)
|
||||
if (needsEnv.length) {
|
||||
console.log("")
|
||||
console.log("需要配置环境变量(不要把密钥写进仓库):")
|
||||
for (const t of needsEnv) {
|
||||
for (const [k] of Object.entries(t.env)) {
|
||||
console.log(` - ${k} (${t.name})`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log("")
|
||||
console.log("提示:修改 MCP 配置后需重启 opencode 才会生效。")
|
||||
Reference in New Issue
Block a user