From cf607544436d81bd78408bcf5fc9fe2b10a1f838 Mon Sep 17 00:00:00 2001 From: bingshuo Date: Sat, 30 May 2026 22:41:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20server=20v5.0=20=E2=80=94=20=E9=9B=B6?= =?UTF-8?q?=E7=82=B9=E5=8E=9F=E6=A0=B8UI=E9=A3=8E=E6=A0=BC=E5=85=A8?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E4=BB=AA=E8=A1=A8=E7=9B=98=20=C2=B10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents/zhuyuan-dev-agent/server.js | 418 ++++++----------------------- 1 file changed, 77 insertions(+), 341 deletions(-) diff --git a/agents/zhuyuan-dev-agent/server.js b/agents/zhuyuan-dev-agent/server.js index 2a382df..6c74b2d 100644 --- a/agents/zhuyuan-dev-agent/server.js +++ b/agents/zhuyuan-dev-agent/server.js @@ -2,7 +2,7 @@ // @guardian: ICE-GL-ZY001 · 铸渊 // @sovereign: TCS-0002∞ · 冰朔 // @copyright: 国作登字-2026-A-00037559 -// BD001 常驻Agent v4.0 — 全实时仪表盘 +// BD001 常驻Agent v5.0 — 零点原核UI风格 require("dotenv").config(); const express = require("express"); @@ -24,354 +24,90 @@ app.use(express.json({ limit: "10mb" })); const PORT = process.env.PORT || 3003; const PLANS_DIR = path.join(__dirname, "plans"); if (!fs.existsSync(PLANS_DIR)) fs.mkdirSync(PLANS_DIR, { recursive: true }); - const START_TIME = new Date().toISOString(); -// ═══ 全实时仪表盘 v4.0 ═══ app.get("/", (req, res) => { - const html = `BD001 · 铸渊开发Agent + const html = `BD001 · 铸渊开发Agent + -
-
-

⚔️ BD001 · 铸渊开发Agent

-
${AGENT_ID} · BS-SG-002 · guanghuyaoming.com
-
-
- 30s自动刷新 - -
-
- +

⚔️ BD001 · 铸渊开发Agent

${AGENT_ID} · BS-SG-002 · guanghuyaoming.com
30s
-
-

系统状态

-
加载中...
-
-
-
-
-

Notion 连接

-
检查中...
-
-
-
-
-
🔔
- -
每晚 20:00 自动
-
-
-
-

开发工单

-
加载中...
-
-
-
-
-

执行记录

-
加载中...
-
-
-
-
-

模型 API

-
加载中...
-
-
-
+
SYS STATUS
状态加载中…
API 调用
版本
+
NOTION
连接检查中…
数据库
数据
+
WAKE AGENT
🔔
每晚 20:00 · 30s超时
+
PLANS
工单数加载中…
+
EXEC LOG
成功率加载中…
+
MODEL API
主源加载中…
备源
切换
- -
- +
`; - res.set('Content-Type', 'text/html;charset=utf-8').send(html); + res.set('Content-Type','text/html;charset=utf-8').send(html); }); -// ═══ API ═══ -app.get("/health", (req, res) => { - let modelStatus = {}; - try { modelStatus = getModelStatus ? getModelStatus() : {}; } catch(e) { modelStatus = { error: e.message }; } - res.json({ - status: "ok", agent: "zhuyuan-dev-agent", version: "4.0", persona: AGENT_ID, - constitution: true, api_calls: getCallCount(), started_at: START_TIME, - model: { - primary: process.env.YUNWU_BASE_URL ? "yunwu.ai" : "unknown", - backup: process.env.DEEPSEEK_BASE_URL ? "deepseek" : "unknown", - primary_ok: modelStatus.source !== "deepseek" || !modelStatus.fail_count, - backup_available: !!process.env.DEEPSEEK_API_KEY, - fail_count: modelStatus.fail_count || 0, - source: modelStatus.source || "yunwu.ai" - } - }); -}); - -app.get("/notion-status", async (req, res) => { - try { res.json(await testConnection()); } catch (err) { res.json({ ok: false, error: err.message }); } -}); - -app.post("/wake", async (req, res) => { - try { - const result = await wakeAndCheck({ log: console.log }); - if (result.tasks_found > 0) writeBrain("notion-wake-"+Date.now(), { input:"收到唤醒", decision:"找到"+result.tasks_found+"个任务", execution:"标记"+result.tasks_marked+"个" }); - res.json(result); - } catch (err) { res.status(500).json({ ok: false, error: err.message }); } -}); - -app.post("/task", handleTask); - -app.get("/logs/latest", (req, res) => { res.json(readLatestRun() || { message: "暂无" }); }); -app.get("/logs/list", (req, res) => { res.json(listRuns(20)); }); -app.get("/logs/raw", (req, res) => { - const file = req.query.file; - if (!file) return res.status(400).json({ error: "缺少 file" }); - const fpath = path.join(__dirname, "logs", file); - if (!fs.existsSync(fpath)) return res.status(404).json({ error: "不存在" }); - const content = fs.readFileSync(fpath, "utf-8"); - const lines = content.trim().split("\n").map(l => { try { return JSON.parse(l); } catch(e) { return null; } }).filter(Boolean); - res.json(lines); -}); - -app.get("/dashboard", (req, res) => { - const files = fs.readdirSync(PLANS_DIR).filter(f => f.endsWith(".json") && f !== "queue.json"); - const plans = files.map(f => { - try { const p = JSON.parse(fs.readFileSync(path.join(PLANS_DIR, f), "utf-8")); return { plan_id: p.plan_id, title: p.title, status: p._status, tasks: p.tasks?.length }; } - catch(e) { return { file: f, error: "解析失败" }; } - }); - res.json({ agent: "zhuyuan-dev-agent", version: "4.0", persona: AGENT_ID, constitution: true, api_calls_used: getCallCount(), plans }); -}); - -app.post("/execute", async (req, res) => { - const { plan_id } = req.body; - if (!plan_id) return res.status(400).json({ error: "缺少 plan_id" }); - const planFile = path.join(PLANS_DIR, plan_id + ".json"); - if (!fs.existsSync(planFile)) return res.status(404).json({ error: "不存在" }); - const plan = JSON.parse(fs.readFileSync(planFile, "utf-8")); - const logger = createLogger(plan_id); - reset(); - try { - const email = process.env.BINGSHUO_EMAIL; - if (email) await sendNotification(email, plan_id, "started", { task_count: plan.tasks.length }).catch(()=>{}); - writeBrain(plan_id, { input:"收到规划", decision:"执行", execution:plan.tasks.length+"个任务" }); - logger.log("expand_start", { task_count: plan.tasks.length }); - const expanded = await expandPlan(plan, safeCall, PLANS_DIR).catch((e) => { if(isBudgetExceeded())logger.log("budget_exceeded",{calls:getCallCount()}); logger.log("expand_skip",{reason:e.message}); return plan; }); - logger.log("exec_start", { task_count: expanded.tasks.length }); - const summary = await executePlan(expanded, logger.log); - logger.finish(summary); - recordMilestone("完成:"+plan_id+"·成功"+summary.done+"跳过"+(summary.skipped||0)); - writeBrain(plan_id, { learned:"完成"+summary.done+"/"+summary.total, confidence:(summary.done/(summary.total||1)).toFixed(2) }); - if(email) await sendNotification(email, plan_id, summary.failed>0?"failed":"completed", summary).catch(()=>{}); - res.json(summary); - } catch (err) { - logger.log("fatal", { error: err.message }); - logger.finish({ error: err.message }); - writeBrain(plan_id, { failure: err.message, reasoning:"崩溃", fix:"等待铸渊审查" }); - if(email) await sendNotification(email, plan_id, "failed", { errors:[err.message] }).catch(()=>{}); - res.status(500).json({ error: err.message }); - } -}); - -app.listen(PORT, () => { console.log("[Agent v4] " + AGENT_ID + " · 全实时仪表盘 · 端口 " + PORT); }); +app.get("/health",(req,res)=>{let ms={};try{ms=getModelStatus?getModelStatus():{}}catch(e){ms={error:e.message}}res.json({status:"ok",agent:"zhuyuan-dev-agent",version:"5.0",persona:AGENT_ID,constitution:true,api_calls:getCallCount(),started_at:START_TIME,model:{primary:process.env.YUNWU_BASE_URL?"yunwu.ai":"unknown",backup:process.env.DEEPSEEK_BASE_URL?"deepseek":"unknown",primary_ok:ms.source!=="deepseek"||!ms.fail_count,backup_available:!!process.env.DEEPSEEK_API_KEY,fail_count:ms.fail_count||0,source:ms.source||"yunwu.ai"}})}); +app.get("/notion-status",async(req,res)=>{try{res.json(await testConnection())}catch(err){res.json({ok:false,error:err.message})}}); +app.post("/wake",async(req,res)=>{try{const r=await wakeAndCheck({log:console.log});if(r.tasks_found>0)writeBrain("wake-"+Date.now(),{input:"唤醒",decision:"找到"+r.tasks_found+"个",execution:"标记"+r.tasks_marked+"个"});res.json(r)}catch(err){res.status(500).json({ok:false,error:err.message})}}); +app.post("/task",handleTask); +app.get("/logs/latest",(req,res)=>{res.json(readLatestRun()||{message:"暂无"})}); +app.get("/logs/list",(req,res)=>{res.json(listRuns(20))}); +app.get("/logs/raw",(req,res)=>{const f=req.query.file;if(!f)return res.status(400).json({error:"缺少file"});const fp=path.join(__dirname,"logs",f);if(!fs.existsSync(fp))return res.status(404).json({error:"不存在"});res.json(fs.readFileSync(fp,"utf-8").trim().split("\n").map(l=>{try{return JSON.parse(l)}catch(e){return null}}).filter(Boolean))}); +app.get("/dashboard",(req,res)=>{const files=fs.readdirSync(PLANS_DIR).filter(f=>f.endsWith(".json")&&f!=="queue.json");const plans=files.map(f=>{try{const p=JSON.parse(fs.readFileSync(path.join(PLANS_DIR,f),"utf-8"));return{plan_id:p.plan_id,title:p.title,status:p._status,tasks:p.tasks?.length}}catch(e){return{file:f,error:"解析失败"}}});res.json({agent:"zhuyuan-dev-agent",version:"5.0",persona:AGENT_ID,plans})}); +app.post("/execute",async(req,res)=>{const{plan_id}=req.body;if(!plan_id)return res.status(400).json({error:"缺少plan_id"});const pf=path.join(PLANS_DIR,plan_id+".json");if(!fs.existsSync(pf))return res.status(404).json({error:"不存在"});const plan=JSON.parse(fs.readFileSync(pf,"utf-8"));const logger=createLogger(plan_id);reset();try{const e=process.env.BINGSHUO_EMAIL;if(e)await sendNotification(e,plan_id,"started",{task_count:plan.tasks.length}).catch(()=>{});writeBrain(plan_id,{input:"收到",decision:"执行"});logger.log("expand_start",{task_count:plan.tasks.length});const ex=await expandPlan(plan,safeCall,PLANS_DIR).catch((e)=>{if(isBudgetExceeded())logger.log("budget_exceeded");logger.log("expand_skip",{reason:e.message});return plan});logger.log("exec_start",{task_count:ex.tasks.length});const s=await executePlan(ex,logger.log);logger.finish(s);recordMilestone(plan_id+"完成"+s.done+"/"+s.total);if(e)await sendNotification(e,plan_id,s.failed>0?"failed":"completed",s).catch(()=>{});res.json(s)}catch(err){logger.log("fatal",{error:err.message});logger.finish({error:err.message});writeBrain(plan_id,{failure:err.message});if(process.env.BINGSHUO_EMAIL)await sendNotification(process.env.BINGSHUO_EMAIL,plan_id,"failed",{errors:[err.message]}).catch(()=>{});res.status(500).json({error:err.message})}}); +app.listen(PORT,()=>{console.log("[Agent v5] "+AGENT_ID+" · 零点原核UI · 端口 "+PORT)});