(options?: { all?: boolean; count?: string })
| 3 | import { getCurrentBranch } from "../core/git"; |
| 4 | |
| 5 | export async function logCommand(options?: { all?: boolean; count?: string }) { |
| 6 | if (!(await isInitialized())) { |
| 7 | console.log(chalk.red("✗ DevContext not initialized. Run `devctx init` first.")); |
| 8 | return; |
| 9 | } |
| 10 | |
| 11 | try { |
| 12 | const count = parseInt(options?.count || "10", 10); |
| 13 | |
| 14 | if (options?.all) { |
| 15 | const sessions = await loadAllSessions(); |
| 16 | if (sessions.length === 0) { |
| 17 | console.log(chalk.yellow("No context entries found.")); |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | console.log(chalk.bold("\nAll branches:\n")); |
| 22 | sessions.slice(0, count).forEach((s) => { |
| 23 | const date = new Date(s.timestamp).toLocaleString(); |
| 24 | console.log(` ${chalk.gray(`[${date}]`)} ${chalk.cyan(s.branch)} ${s.task}`); |
| 25 | }); |
| 26 | } else { |
| 27 | const branch = await getCurrentBranch(); |
| 28 | const entries = await loadBranchContext(branch); |
| 29 | |
| 30 | if (entries.length === 0) { |
| 31 | console.log(chalk.yellow(`No context for branch: ${branch}`)); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | console.log(chalk.bold(`\nBranch: ${branch}\n`)); |
| 36 | entries |
| 37 | .slice(-count) |
| 38 | .reverse() |
| 39 | .forEach((e) => { |
| 40 | const date = new Date(e.timestamp).toLocaleString(); |
| 41 | console.log(` ${chalk.gray(`[${date}]`)} ${e.task}`); |
| 42 | if (e.currentState) { |
| 43 | console.log(` ${chalk.gray("└─")} ${e.currentState}`); |
| 44 | } |
| 45 | }); |
| 46 | } |
| 47 | console.log(); |
| 48 | } catch (err: any) { |
| 49 | console.log(chalk.red(`✗ Error: ${err.message}`)); |
| 50 | } |
| 51 | } |
nothing calls this directly
no test coverage detected