[HLCC-ICE-000001][ZY-CONTRIB-20260723-001] feat: 以来光者贡献链启用冰朔第五域个人子频道
This commit is contained in:
commit
5615453e4e
660 changed files with 122355 additions and 0 deletions
24
server-tools/server-state-mirror/MODULE.hdlp
Normal file
24
server-tools/server-state-mirror/MODULE.hdlp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# ZL-MOD-SERVER-MIRROR-001 · 服务器镜子系统
|
||||
|
||||
```yaml
|
||||
module_id: ZL-MOD-SERVER-MIRROR-001
|
||||
name: 服务器镜子系统
|
||||
human_id: ICE-GL∞
|
||||
persona_id: ICE-GL-ZL-001
|
||||
collaboration_id: ICE-GL∞xICE-GL-ZL-001
|
||||
origin_memory_id: ZL-MEM-REALITY-VISION-001
|
||||
origin_memory_path: 光之湖/ICE-GL-ZL-001-铸澜/ZL-MEM-REALITY-VISION-001.hdlp
|
||||
source_path: server-tools/server-state-mirror/
|
||||
runtime_id: ZL-RUN-SERVER-MIRROR-001
|
||||
status: registered
|
||||
required_skill: true
|
||||
```
|
||||
|
||||
## 使用方法
|
||||
|
||||
Gatekeeper 工作会话确认后自动生成脱敏快照并返回:服务器、资源、仓库版本、PM2/systemd、监听端口、Nginx 路由、MODULE 映射、依赖、部署版本和变化。不得返回 Secret、Token、邮箱、环境变量值、数据库内容或用户数据。
|
||||
|
||||
```text
|
||||
session/confirm → mirror capture → redact → registry resolve
|
||||
→ current snapshot + changes since last snapshot → 铸澜获得现实视野
|
||||
```
|
||||
46
server-tools/server-state-mirror/mirror.js
Normal file
46
server-tools/server-state-mirror/mirror.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const { execFileSync } = require("node:child_process");
|
||||
const { buildRegistry } = require("../module-registry/registry");
|
||||
|
||||
function run(file, args, timeout = 8000) {
|
||||
try { return { ok:true, output:execFileSync(file,args,{encoding:"utf8",timeout,maxBuffer:1024*1024}).trim() }; }
|
||||
catch (error) { return { ok:false, error:String(error.message).slice(0,300) }; }
|
||||
}
|
||||
function gitState(repo) {
|
||||
const branch=run("/usr/bin/git",["-C",repo,"branch","--show-current"]);
|
||||
const commit=run("/usr/bin/git",["-C",repo,"rev-parse","HEAD"]);
|
||||
const status=run("/usr/bin/git",["-C",repo,"status","--porcelain"]);
|
||||
return { path:repo, branch:branch.output||null, commit:commit.output||null, dirty:status.ok?Boolean(status.output):null, error:commit.error };
|
||||
}
|
||||
function redact(value) {
|
||||
function visit(node) {
|
||||
if (Array.isArray(node)) return node.map(visit);
|
||||
if (node && typeof node === "object") {
|
||||
const out={};
|
||||
for (const [key,val] of Object.entries(node)) out[key]=/(token|secret|password|credential|private.?key)/i.test(key)?"[REDACTED]":visit(val);
|
||||
return out;
|
||||
}
|
||||
if (typeof node === "string") return node.replace(/[\w.+-]+@[\w.-]+\.[A-Za-z]{2,}/g,"[REDACTED_EMAIL]");
|
||||
return node;
|
||||
}
|
||||
return visit(value);
|
||||
}
|
||||
function capture({repoRoot=path.resolve(__dirname,"../.."),repoPaths=[path.resolve(__dirname,"../..")]}={}) {
|
||||
const pm2=run("/usr/bin/env",["pm2","jlist"]);
|
||||
const sockets=run("/usr/bin/ss",["-lntp"]);
|
||||
const snapshot={
|
||||
schema:"ZL-SERVER-MIRROR-1",captured_at:new Date().toISOString(),
|
||||
server:{hostname:os.hostname(),platform:os.platform(),release:os.release(),arch:os.arch(),uptime_seconds:os.uptime(),load:os.loadavg(),memory:{total:os.totalmem(),free:os.freemem()}},
|
||||
repositories:repoPaths.filter(p=>fs.existsSync(path.join(p,".git"))).map(gitState),
|
||||
processes:pm2.ok?JSON.parse(pm2.output||"[]").map(p=>({name:p.name,status:p.pm2_env?.status,script:p.pm2_env?.pm_exec_path,restarts:p.pm2_env?.restart_time})):[],
|
||||
listening:sockets.ok?sockets.output.split("\n").slice(1).map(line=>line.replace(/users:\(.*\)$/,"users:[REDACTED]")):[],
|
||||
registry:buildRegistry(repoRoot)
|
||||
};
|
||||
return redact(snapshot);
|
||||
}
|
||||
if(require.main===module) process.stdout.write(JSON.stringify(capture(),null,2)+"\n");
|
||||
module.exports={capture,redact};
|
||||
5
server-tools/server-state-mirror/mirror.test.js
Normal file
5
server-tools/server-state-mirror/mirror.test.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"use strict";
|
||||
const test=require("node:test"),assert=require("node:assert/strict"),path=require("node:path");
|
||||
const {capture,redact}=require("./mirror");
|
||||
test("redacts secrets and email",()=>{const v=redact({api_token:"abc",email:"person@example.com"});assert.equal(v.api_token,"[REDACTED]");assert.equal(v.email,"[REDACTED_EMAIL]");});
|
||||
test("captures server and module registry",()=>{const root=path.resolve(__dirname,"../..");const s=capture({repoRoot:root,repoPaths:[root]});assert.equal(s.schema,"ZL-SERVER-MIRROR-1");assert.ok(s.registry.module_count>=3);assert.ok(s.repositories[0].commit);});
|
||||
1
server-tools/server-state-mirror/package.json
Normal file
1
server-tools/server-state-mirror/package.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"name":"zhulan-server-state-mirror","version":"1.0.0","private":true,"scripts":{"capture":"node mirror.js","test":"node --test mirror.test.js"},"engines":{"node":">=18"}}
|
||||
Loading…
Reference in a new issue