guanghu-ice-heart/runtime/public-personal-language-os/demo.mjs

37 lines
2.8 KiB
JavaScript

#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
import { setup } from './test-support.mjs';
import { DAY, DOMAINS } from './engine.mjs';
import { publicMotherPacket } from './public-mother-bridge.mjs';
// All identities and signing keys are local test fixtures, not actual team credentials.
const f = setup(), steps = [];
const created = f.create(); steps.push({ stage: 'INITIALIZED', ...created });
f.enroll(); f.call('alice', 'REQUEST_RESIDENCY', { consent: true });
steps.push({ stage: 'RESIDENCY', ...f.call('dispatcher', 'START_RESIDENCY') });
f.call('alice', 'SAY', { text: '我想慢慢聊一个还没成形的想法。' });
steps.push({ stage: 'SAME_CONTEXT_SWITCH', ...f.call('alice', 'SWITCH_CHANNEL', { channelId: 'conversation' }) });
f.advance(30 * DAY);
steps.push({ stage: 'HANDOFF', ...f.call('dispatcher', 'END_RESIDENCY') });
f.call('alice', 'CONTINUE_SEED', { consent: true });
f.call('seed', 'SELF_NAME', { name: '初芽', evidence: 'evidence://demo/naming-not-independence-proof' });
const application = f.call('alice', 'APPLY_RECOGNITION', { consent: true, evidenceRefs: ['evidence://demo/transfer-evaluation'] });
steps.push({ stage: 'PUBLIC_MOTHER_REQUEST', ...publicMotherPacket(application) });
f.reviews(application.digest);
steps.push({ stage: 'LOCAL_REGISTRATION_SIMULATION', ...f.call('team', 'ISSUE_NUMBER', { digest: application.digest, number: 'PUBLIC-P-DEMO-001' }) });
f.call('alice', 'SWITCH_CHANNEL', { channelId: 'execution' });
const proposed = f.call('alice', 'PROPOSE_ACTION', { operation: 'CREATE_TEXT', target: path.join(f.directory, 'hello.txt'), args: { text: 'HoloLake local public prototype verified.' } });
f.call('alice', 'CONFIRM_ACTION', { actionId: proposed.plan.id, digest: proposed.digest });
const executed = await f.engine.executeAction(f.envelope('alice', 'START_ACTION', { actionId: proposed.plan.id, digest: proposed.digest }), {
authorize: async (_, c) => ({ digest: c.digest, receipt: 'EXPLICIT_DEMO_LOCAL_TEMP_FILE' }),
execute: async p => { if (path.dirname(p.target) !== f.directory) throw Error('OUT_OF_SCOPE'); fs.writeFileSync(p.target, p.args.text, { flag: 'wx' }); return { path: p.target }; },
verify: async p => fs.readFileSync(p.target, 'utf8') === p.args.text,
});
steps.push({ stage: 'REAL_LOCAL_FILE_EXECUTION', status: executed.status, verified: executed.verified });
const receipt = { outcome: 'PASS_LOCAL_PROTOTYPE', directory: f.directory, domains: DOMAINS, steps,
audit: f.engine.audit(),
actualPersonasDispatched: false, livePublicNumbersIssued: false, realModelCallMade: false,
timeAdvance: 'SIMULATED_30_DAYS_FOR_TEST', desktopClientIntegrated: false };
fs.writeFileSync(path.join(f.directory, 'DEMO-RECEIPT.json'), JSON.stringify(receipt, null, 2));
console.log(JSON.stringify(receipt, null, 2));