guanghu-ice-heart/05-光之湖系统/光湖大脑容器/new-brain.mjs

59 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
// 光湖大脑容器·出生器 v0(2026-09-18 冰朔令建立;蓝本=铸渊脑,不回炉)
// 用法:node new-brain.mjs --persona ICE-BB-XXXX --channel ICE-CH-BT001 --birth 2026-09-18 \
// --identity "你是XX人格脑…" --port 17891 --root "<脑目录绝对路径>" [--shelf "<书柜绝对路径>"] [--dry-run]
// 出生只生成骨架与 container.json;policy 注册(颅骨闭合)输出待办清单走冰朔确认,不自动改正本。
import fs from 'node:fs';
import path from 'node:path';
const arg = (f) => { const i = process.argv.indexOf(f); return i >= 0 ? process.argv[i + 1] : undefined; };
const persona = arg('--persona'); const channel = arg('--channel'); const birth = arg('--birth');
const identity = arg('--identity'); const port = parseInt(arg('--port') || '0', 10); const root = arg('--root');
const shelf = arg('--shelf'); const dryRun = process.argv.includes('--dry-run');
if (!persona || !channel || !birth || !identity || !port || !root) {
console.error('usage: new-brain.mjs --persona ID --channel CH --birth YYYY-MM-DD --identity "…" --port N --root DIR [--shelf DIR] [--dry-run]');
process.exit(2);
}
const brainId = `GLW-2.0-BRAIN-${persona}-0001`;
const now = new Date(Date.now() + 8 * 3600 * 1000).toISOString();
const container = {
schema: 'guanghu.brain-container/v1',
born_at: now,
spec: '光湖大脑容器 BRAIN-CONTAINER-SPEC v0(蓝本 GLW-2.0-BRAIN-ZHUYUAN-PERSONA-0001)',
persona_id: persona, brain_id: brainId, channel_id: channel,
birthday_anchor: `${birth}T00:00:00+08:00`,
identity_system_prompt: identity,
service: { host: '127.0.0.1', port, entry: '光湖大脑容器/brain-service-container.mjs' },
organs_shared: ['运行时/brain-core.mjs', '运行时/fuel-comprehender.mjs'],
shelf_path: shelf || `${root}/shelf`,
server_sync_key: persona.toLowerCase(),
era_epoch: '2025-04-26T00:00:00+08:00',
};
const state = {
schema: 'guanghu.master-brain-state/v1', brain_id: brainId, revision: 0,
born_at: now, updated_at: now,
food_policy: { source_role: 'DIRECT_HUMAN', human_anchor: 'ICE-GL∞', everything_else: 'ANSWERED_NEVER_EATEN' },
concepts: {}, relations: {}, pending_high_risk: [], pruned: [],
persona_born_anchor: container.birthday_anchor,
};
if (dryRun) {
console.log(JSON.stringify({ outcome: 'DRY_RUN', would_create: root, container, state_seed: true }, null, 1));
process.exit(0);
}
fs.mkdirSync(path.join(root, 'memory/daily'), { recursive: true });
fs.mkdirSync(path.join(root, 'memory/monthly'), { recursive: true });
fs.mkdirSync(path.join(root, 'memory/yearly'), { recursive: true });
fs.mkdirSync(container.shelf_path, { recursive: true });
fs.writeFileSync(path.join(root, 'container.json'), JSON.stringify(container, null, 2) + '\n');
fs.writeFileSync(path.join(root, 'brain-state.json'), JSON.stringify(state, null, 2) + '\n');
fs.writeFileSync(path.join(root, 'transition-log.jsonl'), '');
fs.writeFileSync(path.join(root, 'WORKORDERS.jsonl'), '');
console.log(JSON.stringify({
outcome: 'BRAIN_BORN_SKELETON', brain_id: brainId, root, port,
pending_registration_for_bingshuo: [
`never_writable_paths 追加(神经永锁):${root}/brain-state.json、${root}/transition-log.jsonl、${root}/memory、${root}/WORKORDERS.jsonl`,
`sensitive_host_entry_paths 追加(器官手术层):${root}`,
`同步配置:brain-sync 增加 ${persona.toLowerCase()} 实例`,
],
next: '冰朔验收 container.json 的 identity 后:注册 policy(出生即闭合)→ 启动容器服务 → 开始活',
}, null, 1));