UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** > **100% local • No token cost • Private by design • GDPR-friendly** — made in Denmark/EU with ❤️.

97 lines (96 loc) 3.03 kB
import chalk from "chalk"; import { getDbForRepo } from "../db/client.js"; import { getRl } from "./ReadlineSingleton.js"; function oneLineTruncate(input, max = 80) { const singleLine = input.replace(/\s+/g, " ").trim(); if (singleLine.length <= max) return singleLine; return singleLine.slice(0, max - 1) + "…"; } export async function runTasksCommand() { const { rl, isTemporary } = getRl(); // 👈 unified readline ownership try { const db = getDbForRepo(); const tasks = db.prepare(` SELECT id, status, initial_query, created_at FROM tasks ORDER BY id DESC `).all(); if (!tasks.length) { console.log(chalk.dim("No tasks found.")); return; } console.log(chalk.bold("\nTasks:\n")); for (const t of tasks) { console.log(`${chalk.cyan(`[${t.id}]`)} ${chalk.yellow(t.status.padEnd(9))} ${oneLineTruncate(t.initial_query)}`); } await new Promise((resolve) => { rl.question("\nSelect task id (enter to quit): ", answer => { if (!answer.trim() || answer.trim().toLowerCase() === "q") { resolve(); return; } const id = Number(answer); if (!Number.isInteger(id)) { console.log(chalk.red("Invalid task id.")); resolve(); return; } showTaskDetails(id); resolve(); }); }); } finally { if (isTemporary) { rl.close(); // 👈 REQUIRED for clean process exit } } } export function showTaskDetails(taskId) { const db = getDbForRepo(); const task = db.prepare(` SELECT * FROM tasks WHERE id = ? `).get(taskId); if (!task) { console.log(chalk.red(`Task ${taskId} not found.`)); return; } console.log(chalk.bold(`\nTask ${task.id}\n`)); const print = (label, value) => { if (value == null) return; console.log(chalk.gray(label)); if (typeof value === "string") { console.log(value); } else { console.dir(value, { depth: null, colors: true }); } console.log(); }; print("Status", task.status); print("Initial query", task.initial_query); print("Summary", task.summary); print("Agreed intent", task.agreed_intent); if (task.constraints_json) { try { print("Constraints", JSON.parse(task.constraints_json)); } catch { print("Constraints", "[invalid JSON]"); } } if (task.file_scope_json) { try { print("File scope", JSON.parse(task.file_scope_json)); } catch { print("File scope", "[invalid JSON]"); } } print("Created", task.created_at); print("Updated", task.updated_at); }