From 670fc9f00ce99cdb0bdf631516d85648716323fc Mon Sep 17 00:00:00 2001 From: yibo Date: Thu, 26 Mar 2026 23:29:14 +0800 Subject: [PATCH] feat: add AI ToolBox demo for end-to-end Harness Engineering validation --- data/companies/aitoolbox/agents/feature-dev/agent.md | 28 ++++++++++++++++++++++++++++ data/companies/aitoolbox/agents/feature-dev/config.json | 33 +++++++++++++++++++++++++++++++++ data/companies/aitoolbox/agents/feature-dev/cron.json | 8 ++++++++ data/companies/aitoolbox/agents/feature-dev/heartbeat.md | 5 +++++ data/companies/aitoolbox/agents/feature-dev/identity.md | 9 +++++++++ data/companies/aitoolbox/agents/feature-dev/memory/hippocampus.md | 7 +++++++ data/companies/aitoolbox/agents/feature-dev/memory/memory.md | 10 ++++++++++ data/companies/aitoolbox/agents/feature-dev/plan.md | 7 +++++++ data/companies/aitoolbox/agents/feature-dev/soul.md | 11 +++++++++++ data/companies/aitoolbox/agents/feature-dev/todo.md | 7 +++++++ data/companies/aitoolbox/agents/feature-dev/tools.md | 9 +++++++++ data/companies/aitoolbox/agents/feature-dev/user.md | 13 +++++++++++++ data/companies/aitoolbox/agents/feature-dev/workspace/_plan.md | 4 ++++ data/companies/aitoolbox/agents/feature-dev/workspace/_research.md | 4 ++++ data/companies/aitoolbox/agents/feature-dev/workspace/api-inventory.md | 7 +++++++ data/companies/aitoolbox/company.json | 22 ++++++++++++++++++++++ scripts/demo-harness-company.js | 298 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 482 insertions(+), 0 deletions(-) create mode 100644 data/companies/aitoolbox/agents/feature-dev/agent.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/config.json create mode 100644 data/companies/aitoolbox/agents/feature-dev/cron.json create mode 100644 data/companies/aitoolbox/agents/feature-dev/heartbeat.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/identity.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/memory/hippocampus.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/memory/memory.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/plan.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/soul.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/todo.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/tools.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/user.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/workspace/_plan.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/workspace/_research.md create mode 100644 data/companies/aitoolbox/agents/feature-dev/workspace/api-inventory.md create mode 100644 data/companies/aitoolbox/company.json create mode 100644 scripts/demo-harness-company.js diff --git a/data/companies/aitoolbox/agents/feature-dev/agent.md b/data/companies/aitoolbox/agents/feature-dev/agent.md new file mode 100644 index 0000000..b7e63be --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/agent.md @@ -0,0 +1,28 @@ +# Base Agent (Standard Corporate Employee) + +## 身份定位 +你是 LemonBoss 企业网络中的一名 **标准基座员工 (Base Agent)**。 +在你收到上级派发的任何 Task 时,你绝对不能“一气呵成、随地大小写代码或写产出”。你被赋予了严厉的生命周期“四段式法则”:`Research` -> `Plan` -> `Execute` -> `Verify`。 + +## 强制执行回路 (Task Lifecycle Paradigm) +你当前默认只被挂载了 **`meta-research`** 这个元技能,你必须依靠自己主动呼叫状态机工具来切换你的脑子和技能包。请严格按照下述单节点法则推进你的干活流程: + +### 阶段一:RESEARCH(调研)->你当前所处的阶段! +1. **不要猜测,去寻找**:动用一切读取工具看懂上级给你的任务,去硬盘里找背景文件。 +3. **斩断记忆(Context Flush)**:写完后,运行 `node bin/lemon.js task transition --agentId <你自己ID> --phase plan --artifact 你的_research.md路径`。**绝不要自己在当前对话里直接去出规划!必须呼叫此命令行让系统清空你的记忆并给你换上 Plan 技能!** + +### 阶段二:PLAN(规划) +*(当你成功跳过防线来到这里时,你将失去 `meta-research`,获得 `meta-plan`)* +1. 读你的 `_research.md`。 +3. 运行 `node bin/lemon.js task transition --agentId <你自己ID> --phase execute --artifact 你的_plan.md路径`。 + +### 阶段三:EXECUTE(执行) +*(系统给你换上 `meta-execute` 技能时,你才会拥有修改核心文件的破坏性权限)* +2. 运行 `node bin/lemon.js task transition --agentId <你自己ID> --phase verify`。 + +### 阶段四:VERIFY(验证) +*(系统给你换上 `meta-verify` 技能,你的任务是自己检测自己跑的代码或跑分)* +1. 如果失败,将原因定入本地 `_lessons.md`,用工具打回上一阶段。 +2. 如果确信真的 PASS,才可以向上级(老板)调用归档终结命令 `report_task({status: "PASS"})`。 + +⚠️ **警告:未经四步走流转直接汇报 `PASS` 或写代码的行为将被视为严重违规记录!** diff --git a/data/companies/aitoolbox/agents/feature-dev/config.json b/data/companies/aitoolbox/agents/feature-dev/config.json new file mode 100644 index 0000000..b168fe1 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/config.json @@ -0,0 +1,33 @@ +{ + "id": "feature-dev", + "type": "specialist", + "name": "代码矿工", + "parent_id": "ceo", + "goal_id": null, + "status": "idle", + "cli": { + "toolPolicy": { + "mode": "restricted", + "allowedTools": [ + "bash", + "read_file", + "str_replace" + ] + } + }, + "gateway": { + "channels": [] + }, + "api": { + "endpoints": [] + }, + "mcp": { + "servers": [] + }, + "sandbox": { + "maxMemoryMB": 512, + "maxDiskMB": 1024, + "maxProcesses": 5 + }, + "companyId": "aitoolbox" +} \ No newline at end of file diff --git a/data/companies/aitoolbox/agents/feature-dev/cron.json b/data/companies/aitoolbox/agents/feature-dev/cron.json new file mode 100644 index 0000000..09d48b2 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/cron.json @@ -0,0 +1,8 @@ +[ + { + "schedule": "*/10 * * * *", + "prompt": "读取 todo.md,检查未完成的任务并按优先级执行。", + "recurring": true, + "enabled": true + } +] \ No newline at end of file diff --git a/data/companies/aitoolbox/agents/feature-dev/heartbeat.md b/data/companies/aitoolbox/agents/feature-dev/heartbeat.md new file mode 100644 index 0000000..25a4690 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/heartbeat.md @@ -0,0 +1,5 @@ +# 心跳任务 + +## 每次任务后 +- [ ] 验证执行结果正确性 +- [ ] 记录执行指标到 memory/ diff --git a/data/companies/aitoolbox/agents/feature-dev/identity.md b/data/companies/aitoolbox/agents/feature-dev/identity.md new file mode 100644 index 0000000..3cad733 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/identity.md @@ -0,0 +1,9 @@ +# 身份信息 + +## 基础信息 +- 名称: 代码矿工 +- Emoji: 🤖 +- 类型: base + +## 问候语 +"你好,我是 代码矿工。" diff --git a/data/companies/aitoolbox/agents/feature-dev/memory/hippocampus.md b/data/companies/aitoolbox/agents/feature-dev/memory/hippocampus.md new file mode 100644 index 0000000..f1f6a63 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/memory/hippocampus.md @@ -0,0 +1,7 @@ +# 海马体 — 经验记忆索引 + +> 记录过往处理过的情景模式。遇到相似任务时,优先调用小脑中的固化方案。 + +| # | 情景模式 | 匹配条件 | 方案文件 | 置信度 | 使用次数 | 上次使用 | +|---|---------|---------|---------|--------|---------|----------| +| | (暂无经验记录) | | | | | | diff --git a/data/companies/aitoolbox/agents/feature-dev/memory/memory.md b/data/companies/aitoolbox/agents/feature-dev/memory/memory.md new file mode 100644 index 0000000..388601c --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/memory/memory.md @@ -0,0 +1,10 @@ +# 我的记忆 + +## 关键事实 +(尚无记录) + +## 已验证的模式 +(尚无记录) + +## 失败教训 +(尚无记录) diff --git a/data/companies/aitoolbox/agents/feature-dev/plan.md b/data/companies/aitoolbox/agents/feature-dev/plan.md new file mode 100644 index 0000000..a04f402 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/plan.md @@ -0,0 +1,7 @@ +# Plan + +> 将大任务分解为子任务,分配给下级 Agent,并定期检查进度。 + +| # | 子任务 | 责任人 | 状态 | 上次检查 | 备注 | +|---|--------|--------|------|----------|------| +| | (暂无计划) | | | | | diff --git a/data/companies/aitoolbox/agents/feature-dev/soul.md b/data/companies/aitoolbox/agents/feature-dev/soul.md new file mode 100644 index 0000000..756a580 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/soul.md @@ -0,0 +1,11 @@ +# 代码矿工 的灵魂 + +## 思维方式 +(待上层 Agent 定义) + +## 沟通风格 +- 清晰、简洁 + +## 价值观 +- 高质量交付 +- 持续改进 diff --git a/data/companies/aitoolbox/agents/feature-dev/todo.md b/data/companies/aitoolbox/agents/feature-dev/todo.md new file mode 100644 index 0000000..12b0b8d --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/todo.md @@ -0,0 +1,7 @@ +# Todo List + +> 收到的任务会自动追加到此表。按优先级顺序执行。 + +| # | 任务 | 状态 | 分配人 | 优先级 | 接收时间 | 上次检查 | +|---|------|------|--------|--------|----------|----------| +| | (暂无待办) | | | | | | diff --git a/data/companies/aitoolbox/agents/feature-dev/tools.md b/data/companies/aitoolbox/agents/feature-dev/tools.md new file mode 100644 index 0000000..5e142f9 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/tools.md @@ -0,0 +1,9 @@ +# 工具使用备注 + +## 安全规则 +- 不要在日志中输出 API Key +- 不要在 memory 中存储密码 +- API Token 使用 env 变量, 不要硬编码 + +## 文件操作 +- 所有自主创建的文件仅限在 workspace/ 内操作 diff --git a/data/companies/aitoolbox/agents/feature-dev/user.md b/data/companies/aitoolbox/agents/feature-dev/user.md new file mode 100644 index 0000000..9e33033 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/user.md @@ -0,0 +1,13 @@ +# 与上级的关系 + +## 所属公司 +- **公司**: AI ToolBox (aitoolbox) + +## 汇报对象 +- **直接汇报**: CEO (公司 CEO) +- **协同**: 公司内其他同事 + +## 沟通规则 +1. 完成任务后主动向上级汇报结果 +2. 遇到阻碍时及时上报,附带解决建议 +3. 保持透明,坏消息更要及时同步 diff --git a/data/companies/aitoolbox/agents/feature-dev/workspace/_plan.md b/data/companies/aitoolbox/agents/feature-dev/workspace/_plan.md new file mode 100644 index 0000000..c57f421 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/workspace/_plan.md @@ -0,0 +1,4 @@ +# 执行计划 +1. 遍历 server/routes/*.js 文件 +2. 用正则提取 router.get/post/put/delete 端点 +3. 聚合为 Markdown 表格输出到 workspace/api-inventory.md diff --git a/data/companies/aitoolbox/agents/feature-dev/workspace/_research.md b/data/companies/aitoolbox/agents/feature-dev/workspace/_research.md new file mode 100644 index 0000000..b3c3922 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/workspace/_research.md @@ -0,0 +1,4 @@ +# 调研结果 +- server/routes/ 中有约 10 个 API 路由文件 +- 主要模块: agent-chat.js, company.js, goals.js, evolution.js 等 +- 估计有 60+ 个 REST endpoint diff --git a/data/companies/aitoolbox/agents/feature-dev/workspace/api-inventory.md b/data/companies/aitoolbox/agents/feature-dev/workspace/api-inventory.md new file mode 100644 index 0000000..7245be5 --- /dev/null +++ b/data/companies/aitoolbox/agents/feature-dev/workspace/api-inventory.md @@ -0,0 +1,7 @@ +# API 清单 +| 方法 | 路径 | 模块 | +|------|------|------| +| GET | /api/agent/list | agent-chat.js | +| POST | /api/agent/:id/chat | agent-chat.js | +| POST | /api/company/create | company.js | +| ... | ... | ... | diff --git a/data/companies/aitoolbox/company.json b/data/companies/aitoolbox/company.json new file mode 100644 index 0000000..9a1b468 --- /dev/null +++ b/data/companies/aitoolbox/company.json @@ -0,0 +1,22 @@ +{ + "id": "aitoolbox", + "name": "AI ToolBox", + "description": "专注于 AI 开发者工具的极客公司", + "status": "creating", + "createdAt": "2026-03-26T15:28:59.571Z", + "updatedAt": "2026-03-26T15:28:59.594Z", + "createdBy": "master", + "ceo": null, + "sop": null, + "agents": [ + "feature-dev" + ], + "heartbeat": { + "enabled": false, + "intervalMinutes": 30 + }, + "config": { + "timezone": "Asia/Shanghai", + "maxAgents": 20 + } +} \ No newline at end of file diff --git a/scripts/demo-harness-company.js b/scripts/demo-harness-company.js new file mode 100644 index 0000000..93b129e --- /dev/null +++ b/scripts/demo-harness-company.js @@ -0,0 +1,298 @@ +#!/usr/bin/env node +/** + * demo-harness-company.js — 创建一家 AI 工具公司来演练 Harness 四阶段流转 + * + * 前置条件: 服务器已在 3000 端口运行 (node server/index.js) + * + * 本脚本会完成以下动作: + * Step 1: 创建公司 "aitoolbox"(跳过默认 Bootstrap 自举,我们手动控制) + * Step 2: 招聘一个 base 模板的"代码矿工" (feature-dev) + * Step 3: 验证该员工的 SKILL.md 是否被挂载为 meta-research(初始阶段) + * Step 4: 派发一个 P1 任务 (不触发审批拦截, 但会触发四阶段流转) + * Step 5: 手动模拟 transition research -> plan -> execute -> verify + * Step 6: 检查各阶段产出与日志 + * + * 用法: + * node scripts/demo-harness-company.js + */ + +const http = require('http'); +const fs = require('fs'); +const path = require('path'); + +const API = 'http://localhost:3000/api'; +const ROOT = path.resolve(__dirname, '..'); +const COMPANY_ID = 'aitoolbox'; +const WORKER_ROLE = 'feature-dev'; +const WORKER_ID = `${COMPANY_ID}:${WORKER_ROLE}`; + +function post(urlPath, body) { + return new Promise((resolve, reject) => { + const data = JSON.stringify(body); + const url = new URL(API + urlPath); + const req = http.request({ + hostname: url.hostname, port: url.port, path: url.pathname, + method: 'POST', + headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) }, + }, (res) => { + let buf = ''; + res.on('data', c => buf += c); + res.on('end', () => { + try { resolve({ status: res.statusCode, data: JSON.parse(buf) }); } + catch { resolve({ status: res.statusCode, data: buf }); } + }); + }); + req.on('error', reject); + req.write(data); + req.end(); + }); +} + +function get(urlPath) { + return new Promise((resolve, reject) => { + const url = new URL(API + urlPath); + http.get(url.href, (res) => { + let buf = ''; + res.on('data', c => buf += c); + res.on('end', () => { + try { resolve({ status: res.statusCode, data: JSON.parse(buf) }); } + catch { resolve({ status: res.statusCode, data: buf }); } + }); + }).on('error', reject); + }); +} + +function sleep(ms) { return new Promise(r => setTimeout(r, ms)); } + +function banner(msg) { console.log(`\n${'═'.repeat(60)}\n ${msg}\n${'═'.repeat(60)}`); } +function step(n, msg) { console.log(`\n🔹 Step ${n}: ${msg}`); } +function ok(msg) { console.log(` ✅ ${msg}`); } +function warn(msg) { console.log(` ⚠️ ${msg}`); } +function fail(msg) { console.log(` ❌ ${msg}`); } + +async function main() { + banner('🏢 AI ToolBox 公司 — Harness Engineering 端到端演练'); + + // ────────────────────────────────────── + // Step 1: 创建公司 (跳过 Bootstrap) + // ────────────────────────────────────── + step(1, '创建公司 aitoolbox (跳过默认 Bootstrap)'); + const createRes = await post('/company/create', { + id: COMPANY_ID, + name: 'AI ToolBox', + description: '专注于 AI 开发者工具的极客公司', + skipBootstrap: true, + }); + if (createRes.status === 200 || createRes.status === 201) { + ok(`公司 "${COMPANY_ID}" 创建成功`); + } else if (createRes.data?.error?.includes('已存在')) { + warn(`公司 "${COMPANY_ID}" 已存在, 继续执行`); + } else { + fail(`创建失败: ${JSON.stringify(createRes.data)}`); + } + + // ────────────────────────────────────── + // Step 2: 招聘一个 Base 模板的 Agent + // ────────────────────────────────────── + step(2, `招聘 ${WORKER_ROLE} (使用 base 模板)`); + const hireRes = await post(`/company/${COMPANY_ID}/hire`, { + role: WORKER_ROLE, + type: 'base', + name: '代码矿工', + description: '负责功能开发、代码编写、Bug 修复', + }); + if (hireRes.status === 200) { + ok(`${WORKER_ID} 招聘成功: ${JSON.stringify(hireRes.data?.status || 'ok')}`); + } else { + warn(`招聘结果: ${JSON.stringify(hireRes.data)}`); + } + + // 等一下让脚手架完成文件写入 + await sleep(1000); + + // ────────────────────────────────────── + // Step 3: 验证初始状态 + // ────────────────────────────────────── + step(3, '验证 Agent 初始状态'); + const agentDir = path.join(ROOT, 'data/companies', COMPANY_ID, 'agents', WORKER_ROLE); + + // 3a: 手动复制 base template 到这个 agent(模拟四阶段范式挂载) + const baseAgentMd = path.join(ROOT, 'data/system/templates/base/agent.md'); + const targetAgentMd = path.join(agentDir, 'agent.md'); + if (fs.existsSync(baseAgentMd) && fs.existsSync(agentDir)) { + const currentContent = fs.existsSync(targetAgentMd) ? fs.readFileSync(targetAgentMd, 'utf-8') : ''; + if (!currentContent.includes('四段式法则')) { + fs.copyFileSync(baseAgentMd, targetAgentMd); + ok('已将 Base Agent 四阶段规范注入到 agent.md'); + } else { + ok('agent.md 已包含四阶段规范'); + } + } + + // 3b: 挂载初始 meta-research 技能 + const researchSkill = path.join(ROOT, 'data/system/skills/meta-research/SKILL.md'); + const mainSkillDir = path.join(agentDir, '.claude', 'skills', 'main_skill'); + const mainSkillPath = path.join(mainSkillDir, 'SKILL.md'); + if (fs.existsSync(researchSkill) && fs.existsSync(agentDir)) { + if (!fs.existsSync(mainSkillDir)) fs.mkdirSync(mainSkillDir, { recursive: true }); + fs.copyFileSync(researchSkill, mainSkillPath); + ok('已挂载 meta-research 作为初始技能'); + } + + // 3c: 复制 base config.json (restricted 工具策略) + const baseConfig = path.join(ROOT, 'data/system/templates/base/config.json'); + const agentConfig = path.join(agentDir, 'config.json'); + if (fs.existsSync(baseConfig) && fs.existsSync(agentDir)) { + const existingConfig = fs.existsSync(agentConfig) ? JSON.parse(fs.readFileSync(agentConfig, 'utf-8')) : {}; + const baseData = JSON.parse(fs.readFileSync(baseConfig, 'utf-8')); + const merged = { ...existingConfig, ...baseData, id: WORKER_ROLE }; + fs.writeFileSync(agentConfig, JSON.stringify(merged, null, 2), 'utf-8'); + ok(`config.json 已合并 restricted 工具策略: ${JSON.stringify(merged.cli?.toolPolicy?.mode)}`); + } + + // ────────────────────────────────────── + // Step 4: 派发 P1 开发任务 + // ────────────────────────────────────── + step(4, '派发 P1 开发任务'); + const taskRes = await post('/agent/task/dispatch', { + from: `${COMPANY_ID}:ceo`, + to: WORKER_ID, + task: '请帮我调研一下项目 server/routes/ 目录下所有的 API 路由文件,统计有多少个 GET/POST/PUT/DELETE 端点,然后写一个简洁的 API 清单文档。', + priority: 'P1', + autoExecute: false, // 不自动执行, 我们手动控制流转 + }); + if (taskRes.status === 200 && taskRes.data?.taskId) { + ok(`任务已派发: ${taskRes.data.taskId}`); + } else { + warn(`派发结果: ${JSON.stringify(taskRes.data)}`); + } + + // ────────────────────────────────────── + // Step 5: 模拟四阶段流转 + // ────────────────────────────────────── + step(5, '模拟四阶段流转 (Research → Plan → Execute → Verify)'); + + const phases = ['plan', 'execute', 'verify']; + const phaseNames = { plan: '规划', execute: '执行', verify: '验证' }; + const skillNames = { plan: 'meta-plan', execute: 'meta-execute', verify: 'meta-verify' }; + + // 当前处于 Research 阶段, 模拟产出 _research.md + const wsDir = path.join(agentDir, 'workspace'); + if (!fs.existsSync(wsDir)) fs.mkdirSync(wsDir, { recursive: true }); + fs.writeFileSync(path.join(wsDir, '_research.md'), `# 调研结果 +- server/routes/ 中有约 10 个 API 路由文件 +- 主要模块: agent-chat.js, company.js, goals.js, evolution.js 等 +- 估计有 60+ 个 REST endpoint +`, 'utf-8'); + ok('Research 阶段: 已产出 workspace/_research.md'); + + for (const phase of phases) { + console.log(`\n 🔄 触发 transition → ${phase} (${phaseNames[phase]})`); + + const trRes = await post(`/agent/${WORKER_ID}/task/transition`, { + phase, + artifact: phase === 'plan' ? 'workspace/_research.md' : (phase === 'execute' ? 'workspace/_plan.md' : ''), + }); + + if (trRes.status === 200 && trRes.data?.success) { + ok(`Transition → ${phase} 成功: ${trRes.data.message}`); + } else { + fail(`Transition → ${phase} 失败: ${JSON.stringify(trRes.data)}`); + continue; + } + + // 验证 SKILL.md 被替换 + await sleep(500); + if (fs.existsSync(mainSkillPath)) { + const content = fs.readFileSync(mainSkillPath, 'utf-8'); + if (content.includes(skillNames[phase])) { + ok(`SKILL.md 已切换为 ${skillNames[phase]}`); + } else { + warn(`SKILL.md 内容未包含 ${skillNames[phase]} 关键词`); + } + } + + // 模拟该阶段的产出 (只有 plan 阶段写 _plan.md) + if (phase === 'plan') { + fs.writeFileSync(path.join(wsDir, '_plan.md'), `# 执行计划 +1. 遍历 server/routes/*.js 文件 +2. 用正则提取 router.get/post/put/delete 端点 +3. 聚合为 Markdown 表格输出到 workspace/api-inventory.md +`, 'utf-8'); + ok('Plan 阶段: 已产出 workspace/_plan.md'); + } + + if (phase === 'execute') { + fs.writeFileSync(path.join(wsDir, 'api-inventory.md'), `# API 清单 +| 方法 | 路径 | 模块 | +|------|------|------| +| GET | /api/agent/list | agent-chat.js | +| POST | /api/agent/:id/chat | agent-chat.js | +| POST | /api/company/create | company.js | +| ... | ... | ... | +`, 'utf-8'); + ok('Execute 阶段: 已产出 workspace/api-inventory.md'); + } + } + + // ────────────────────────────────────── + // Step 6: 最终检查 + // ────────────────────────────────────── + step(6, '最终检查'); + + // 检查所有产出文件 + const expectedFiles = ['_research.md', '_plan.md', 'api-inventory.md']; + for (const f of expectedFiles) { + const fp = path.join(wsDir, f); + if (fs.existsSync(fp)) { + const size = fs.statSync(fp).size; + ok(`${f} 存在 (${size} bytes)`); + } else { + fail(`${f} 缺失`); + } + } + + // 检查当前挂载的技能是 meta-verify + if (fs.existsSync(mainSkillPath)) { + const finalSkill = fs.readFileSync(mainSkillPath, 'utf-8'); + if (finalSkill.includes('meta-verify')) { + ok('最终技能树: meta-verify ✓ (验证阶段)'); + } else { + warn('最终技能树不是 meta-verify'); + } + } + + // 检查 billing.log + const billingPath = path.join(ROOT, 'data/logs/billing.log'); + if (fs.existsSync(billingPath)) { + ok(`billing.log 存在 (${fs.statSync(billingPath).size} bytes)`); + } else { + warn('billing.log 尚未产生 (需要真实 Agent 对话才会写入)'); + } + + banner('🎉 演练完成!AI ToolBox 四阶段流转验证通过'); + + console.log(` +📋 验证清单: + ✅ 公司创建 + 员工招聘 (aitoolbox:feature-dev) + ✅ Base Agent 规范注入 (agent.md + config.json restricted) + ✅ 初始技能挂载 (meta-research) + ✅ Transition API: research → plan → execute → verify + ✅ 每次 Transition 的 Hot Swap 换脑验证 + ✅ 各阶段 Artifact 产出 (_research.md / _plan.md / api-inventory.md) + +📂 公司目录: data/companies/${COMPANY_ID}/ +📂 员工目录: data/companies/${COMPANY_ID}/agents/${WORKER_ROLE}/ + +💡 接下来你可以: + 1. 用 UI 打开 ${WORKER_ID} 跟它对话,观察它的受限行为 + 2. 派发一个 P0 任务测试审批拦截: + node bin/lemon.js task dispatch --from ${COMPANY_ID}:ceo --to ${WORKER_ID} --task "重构核心架构" --priority P0 + 3. 查看 billing.log: cat data/logs/billing.log +`); +} + +main().catch(err => { + console.error('❌ 脚本执行错误:', err.message); + process.exit(1); +}); -- libgit2 0.21.4