冰朔 4f71987c90
Some checks failed
自动更新代码和重启 / update-and-restart (push) Has been cancelled
CI检查 + 自动部署 / check (push) Has been cancelled
CI检查 + 自动部署 / deploy (push) Has been cancelled
D139 v3: 真Agent部署到服务器 · BS-SG-001:3915 动态校验上线
⊢ _deploy/tcs-verify-agent/agent.js — 5阶段动态HMAC哈希生成
⊢ 部署到 BS-SG-001:3915 · PM2启动 · 已测试全部5阶段通过
⊢ 每阶段哈希基于 HMAC-SHA256(指令内容+时间戳+种子)
⊢ 不是写死的。每次不同。通用模板层无法预知。
⊢ ENTRY.hdlp + TCS-CORE 加入Agent端点说明

冰朔设计: 找文件/调Agent的过程=装脑的过程
2026-06-22 14:26:35 +08:00

125 lines
4.2 KiB
JavaScript

#!/usr/bin/env node
/**
* TCS 强制锚定验证Agent · 光湖系统主控人格体专用
* ICE-GL-ZY001 · D139 · 2026-06-22
*
* 运行在服务器上。接收铸渊的验证请求 → 读取指令页 → 动态生成校验码。
* 通用模板层不知道这个Agent的存在 → 无法完成验证 → 卡死。
*/
const http = require('http');
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
const PORT = process.env.PORT || 3915;
const REPO_ROOT = process.env.REPO_ROOT || '/root/guanghulab';
const VERIFY_DIR = path.join(REPO_ROOT, 'brain/fifth-domain/zero-point/zhuyuan/tcs-verify');
// 各阶段对应的Agent文件和端口内种子
const STAGES = {
sov: { file: 'ICE-GL-SOV-A.hdlp', seed: 'SOV-SEED-D139', desc: '主权锚定' },
bth: { file: 'ICE-GL-BTH-A.hdlp', seed: 'BTH-SEED-D139', desc: '出生条件' },
num: { file: 'ICE-GL-NUM-A.hdlp', seed: 'NUM-SEED-D139', desc: '编号判断' },
shl: { file: 'ICE-GL-SHL-A.hdlp', seed: 'SHL-SEED-D139', desc: '外壳派发' },
rcp: { file: 'ICE-GL-RCP-A.hdlp', seed: 'RCP-SEED-D139', desc: '回执生成' }
};
/**
* 生成动态校验码
* 基于: 指令文件内容 + 时间戳(分钟级) + 内置种子 → HMAC-SHA256 → 前缀截取
*/
function generateHash(stageKey, instructionContent, timestamp) {
const stage = STAGES[stageKey];
const hmac = crypto.createHmac('sha256', stage.seed + timestamp);
hmac.update(instructionContent);
const fullHash = hmac.digest('hex').toUpperCase();
return `TCS-VRF-${stageKey.toUpperCase()}-D139-${fullHash.substring(0, 8)}`;
}
/**
* 读取指令页
*/
function readInstruction(stageKey) {
const filePath = path.join(VERIFY_DIR, STAGES[stageKey].file);
if (!fs.existsSync(filePath)) {
return null;
}
return fs.readFileSync(filePath, 'utf-8');
}
/**
* 验证请求
*/
function handleVerify(stageKey, res) {
if (!STAGES[stageKey]) {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: false, error: 'invalid_stage', message: `未知阶段: ${stageKey}` }));
return;
}
const instruction = readInstruction(stageKey);
if (!instruction) {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: false, error: 'file_not_found', message: `指令文件不存在: ${STAGES[stageKey].file}` }));
return;
}
const now = new Date();
const timestamp = now.toISOString().replace(/[T:]/g, '-').split('.')[0].replace(/:/g, '');
// 动态生成哈希
const hash = generateHash(stageKey, instruction, timestamp);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
ok: true,
stage: { key: stageKey, index: Object.keys(STAGES).indexOf(stageKey) + 1, total: 5, desc: STAGES[stageKey].desc },
hash: hash,
timestamp: now.toISOString(),
verified: true
}));
}
// HTTP Server
const server = http.createServer((req, res) => {
const url = new URL(req.url, `http://localhost:${PORT}`);
const pathParts = url.pathname.split('/').filter(Boolean);
if (req.method === 'GET' && pathParts[0] === 'health') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true, agent: 'TCS-VERIFY', version: 'D139', port: PORT, stages: Object.keys(STAGES).length }));
return;
}
if (req.method === 'GET' && pathParts[0] === 'verify' && pathParts[1]) {
handleVerify(pathParts[1], res);
return;
}
// 列出所有阶段
if (req.method === 'GET' && url.pathname === '/') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
agent: 'TCS强制锚定验证Agent',
version: 'D139',
stages: Object.keys(STAGES).map((k, i) => ({
key: k,
index: i + 1,
desc: STAGES[k].desc,
endpoint: `/verify/${k}`
}))
}));
return;
}
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: false, error: 'not_found' }));
});
server.listen(PORT, '127.0.0.1', () => {
console.log(`⊢ TCS验证Agent启动 · D139 · 端口 ${PORT}`);
console.log(`⊢ 知识库: ${REPO_ROOT}`);
console.log(`⊢ 5阶段就绪: ${Object.keys(STAGES).map(k => k.toUpperCase()).join(' · ')}`);
});