project-resume.mjs 2.7 KB

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