read-thread.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { ThreadLedgerReader } from '../storage/adapters/ThreadLedgerReader.js'
  2. /**
  3. * read-thread <条目ID> [--履历|--收尾计划|--描述](默认基本信息)
  4. * 契约:纯返回 {ok, output?, error?}(见 design §6.2)。
  5. */
  6. export async function run(args, options, ctx) {
  7. const threadId = args[0]
  8. if (!threadId) {
  9. return { ok: false, error: '请指定条目 ID(如 伏笔-001)' }
  10. }
  11. const reader = new ThreadLedgerReader(ctx.repoPath, ctx.cache)
  12. if (options['履历']) {
  13. const r = await reader.readHistory(threadId)
  14. return r.ok ? { ok: true, output: JSON.stringify(r.history, null, 2) } : { ok: false, error: r.error }
  15. }
  16. if (options['收尾计划']) {
  17. const r = await reader.readClosurePlan(threadId)
  18. return r.ok ? { ok: true, output: r.plan } : { ok: false, error: r.error }
  19. }
  20. if (options['描述']) {
  21. const r = await reader.readDescription(threadId)
  22. return r.ok ? { ok: true, output: r.description } : { ok: false, error: r.error }
  23. }
  24. // 默认:基本信息
  25. const r = await reader.readBasicInfo(threadId)
  26. return r.ok ? { ok: true, output: JSON.stringify(r.data, null, 2) } : { ok: false, error: r.error }
  27. }