/** 默认只读;--snapshot 显式保存交接;--note/--step 显式更新接续记录。 */ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import { collectRecovery, createSnapshot, recordProgress, updateStep } from './lib/project-recovery.mjs'; const args = process.argv.slice(2); const arg = name => args.find(x => x.startsWith('--' + name + '='))?.slice(name.length + 3); const root = path.resolve(arg('root') || path.join(path.dirname(fileURLToPath(import.meta.url)), '..')); const commands = [args.includes('--snapshot'), arg('note') !== undefined, arg('step') !== undefined].filter(Boolean); if (commands.length > 1 || args.some(x => !['--json', '--offline', '--snapshot'].includes(x) && !/^--(root|note|step)=/.test(x))) { throw Error('用法:node scripts/project-resume.mjs [--json] [--offline] [--snapshot | --note=记录 | --step=当前步骤]'); } if (args.includes('--snapshot')) { recordProgress(root, '准备保存显式交接快照;包含当前修改、未跟踪源码及活动证据,不包含 Docker 数据卷。'); const result = createSnapshot(root); recordProgress(root, '交接快照已逐文件 SHA256 回读校验:' + result.directory + ';共 ' + result.files + ' 个文件,Docker 卷未备份。'); console.log(JSON.stringify(result, null, 2)); } else if (arg('note') !== undefined) { recordProgress(root, arg('note')); console.log('已同步检查点与操作追踪。'); } else if (arg('step') !== undefined) { updateStep(root, arg('step')); console.log('已保存当前步骤与检查点。'); } else { const result = collectRecovery(root, { probe: !args.includes('--offline') }); if (args.includes('--json')) console.log(JSON.stringify(result, null, 2)); else { console.log(`当前任务:${result.goal}\n当前步骤:${result.currentStep}\n账号:${result.account.phone || '未知'} / ${result.account.userId || '未知'}\n活动账本:${result.ledger}`); console.log('\n验收项目:'); for (const item of result.acceptance) console.log(`- ${item.name}:${item.status}${item.evidence ? ';' + item.evidence : ''}`); console.log('\n已登记动作(只读,不重试):'); for (const item of result.actions) console.log(`- ${item.key}:${item.status};${item.target || ''}`); if (result.lastFailure) console.log('\n最近留存失败:' + result.lastFailure.stage + ':' + result.lastFailure.message); for (const warning of result.warnings) console.log('注意:' + warning); if (result.environment.checked) console.log('\n本机环境:' + JSON.stringify(result.environment)); console.log('\n下一步:' + (result.nextSteps.join(' → ') || '先核对未确认动作的真实回执')); console.log('\n工作树:\n' + result.worktree.status); } }