/**
 * `opensquid checkpoints` CLI verb group (CLI.6).
 *
 * Four verbs, all backed by `CheckpointStore` (DURABLE.1) + optional
 * `Resumer` (DURABLE.4):
 *
 *   list    — print interrupted-run summaries. `--limit <n>` caps
 *             (default 20). `--interrupted` is a no-op alias —
 *             `scanInterrupted` already excludes terminated runs.
 *   show    — RAW JSONL dump of one run: manifest line + one line per
 *             checkpoint row (sorted by `stepIdx`) + terminal-marker
 *             line when present. Distinct from `opensquid trace`
 *             (OBSERVE.2), which renders a styled timeline.
 *   resume  — explicit resume that BYPASSES DURABLE.4's 60s window
 *             (`Resumer.resume` is window-free; only `scanInterrupted`
 *             / `resumeOnStartup` consult the window). Confirmation
 *             unless `--yes`. Requires a daemon-wired Resumer.
 *   clean   — prune checkpoints older than a duration (default 30d).
 *             Confirmation unless `--yes`.
 *
 * This file owns commander wiring + dep-building only. Pure handlers
 * live in `./checkpoints_core.ts` (re-exported here so direct-import
 * callers from the DURABLE.4 scaffold keep working). Action bodies +
 * libsql client lifecycle live in `./checkpoints_actions.ts`. Table
 * rendering lives in `./checkpoints_render.ts`.
 *
 * Imports from: commander, @libsql/client, ../../runtime/durable/index.js,
 *   ../../runtime/paths.js, ./checkpoints_actions.js, ./checkpoints_core.js.
 * Imported by: src/setup/cli/checkpoints.test.ts, src/cli.ts.
 */
import { createClient } from '@libsql/client';
import { OPENSQUID_HOME } from '../../runtime/paths.js';
import { actClean, actList, actResume, actShow } from './checkpoints_actions.js';
// Re-export the pure handlers + shapes from the DURABLE.4 scaffold so that
// existing direct-import callers (`import * as cli from './checkpoints.js'`)
// continue to find `cli.list` / `cli.show` / `cli.resume` / `cli.clean`.
export { clean, list, resume, show, } from './checkpoints_core.js';
function defaultDbPath() {
    return `file:${OPENSQUID_HOME()}/opensquid.db`;
}
function defaultOpen(dbPath) {
    const url = dbPath.startsWith('file:') || dbPath === ':memory:' ? dbPath : `file:${dbPath}`;
    return createClient({ url });
}
function buildDeps(deps) {
    const out = {
        open: deps.openClient ?? defaultOpen,
        out: deps.stdout ?? ((s) => void process.stdout.write(s)),
        err: deps.stderr ?? ((s) => void process.stderr.write(s)),
        isTty: deps.isTty ?? (() => process.stdout.isTTY === true),
        now: deps.now ?? (() => Date.now()),
    };
    if (deps.resumerFor !== undefined)
        out.resumerFor = deps.resumerFor;
    return out;
}
/** Register `opensquid checkpoints` on the parent program. */
export function registerCheckpoints(parent, deps = {}) {
    const ad = buildDeps(deps);
    const c = parent.command('checkpoints').description('Durable-execution checkpoint store');
    const db = defaultDbPath();
    c.command('list')
        .description('List interrupted runs (durable-execution checkpoint store)')
        .option('--db <path>', 'Path to the libsql DB', db)
        .option('--interrupted', 'only show interrupted runs (default: true)')
        .option('--limit <n>', 'cap result count (default 20)')
        .action((opts) => actList(ad, opts));
    c.command('show <runId>')
        .description('Raw JSONL dump of one run (manifest + checkpoints + terminal)')
        .option('--db <path>', 'Path to the libsql DB', db)
        .action((runId, opts) => actShow(ad, runId, opts));
    c.command('resume <runId>')
        .description('Manually resume an interrupted run (overrides DURABLE.4 resume window)')
        .option('--db <path>', 'Path to the libsql DB', db)
        .option('--yes', 'skip confirmation', false)
        .action((runId, opts) => actResume(ad, runId, opts));
    c.command('clean')
        .description('Prune old checkpoint rows (confirms unless --yes)')
        .option('--db <path>', 'Path to the libsql DB', db)
        .option('--older-than <duration>', 'e.g. 7d, 30d', '30d')
        .option('--yes', 'skip confirmation', false)
        .action((opts) => actClean(ad, opts));
    return c;
}
//# sourceMappingURL=checkpoints.js.map