import fs from 'node:fs'; import path from 'node:path'; import os from 'node:os'; import { DarkCoreTask, inspectTask } from './task-controller.mjs'; import { localFileHost } from './local-file-host.mjs'; // Explicit local demo invocation authorizes only these two newly created demo files. const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'dark-core-demo-'))); const plan = { id: 'DARK-CORE-LOCAL-DEMO', channel: 'ICE-CH-DK001', goal: '创建两个本地演示文件并逐一读回', authorizationRef: 'EXPLICIT_LOCAL_DEMO_INVOCATION', steps: ['第一步完成。', '第二步完成。'].map((text, i) => ({ id: `step-${i + 1}`, capability: 'CREATE_TEXT_FILE', args: { path: path.join(root, `result-${i + 1}.txt`), text } })) }; const host = localFileHost({ root, approvedPlan: plan, approvalReceipt: 'LOCAL_DEMO_SCOPE_ONLY', verifyHuman: e => e.source === 'LOCAL_DEMO_SCRIPT' && ['demo-advice'].includes(e.id) }); const execute = host.execute; let task; host.execute = async args => { const result = await execute(args); if (args.step.id === 'step-1') { await task.human({ id: 'demo-advice', taskId: plan.id, kind: 'ADVICE', source: 'LOCAL_DEMO_SCRIPT', text: '演示中途的新想法:先讨论一个新框架。' }); task.decideAdvice('demo-advice', 'DEFER', '当前两个文件任务已明确,新框架讨论排到任务之后。'); } return result; }; task = new DarkCoreTask({ plan, directory: path.join(root, 'state'), host }); await task.run(); const result = inspectTask(path.join(root, 'state')); console.log(JSON.stringify({ status: result.status, files: result.receipts, advice: result.suggestions, directory: root, scope: 'LOCAL_DEMO_NOT_SERVER_DEPLOYMENT' }, null, 2)); if (result.status !== 'COMPLETED') process.exitCode = 1;