feat(tasks): add status health and maintenance command (#57423)

* feat(tasks): add status health and maintenance command

* fix(tasks): address status and maintenance review feedback
This commit is contained in:
Vincent Koc
2026-03-29 20:10:44 -07:00
committed by GitHub
parent d28349c48e
commit c52fac836c
14 changed files with 476 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ const sessionsCommand = vi.fn();
const sessionsCleanupCommand = vi.fn();
const tasksListCommand = vi.fn();
const tasksAuditCommand = vi.fn();
const tasksMaintenanceCommand = vi.fn();
const tasksShowCommand = vi.fn();
const tasksNotifyCommand = vi.fn();
const tasksCancelCommand = vi.fn();
@@ -34,6 +35,7 @@ vi.mock("../../commands/sessions-cleanup.js", () => ({
vi.mock("../../commands/tasks.js", () => ({
tasksListCommand,
tasksAuditCommand,
tasksMaintenanceCommand,
tasksShowCommand,
tasksNotifyCommand,
tasksCancelCommand,
@@ -70,6 +72,7 @@ describe("registerStatusHealthSessionsCommands", () => {
sessionsCleanupCommand.mockResolvedValue(undefined);
tasksListCommand.mockResolvedValue(undefined);
tasksAuditCommand.mockResolvedValue(undefined);
tasksMaintenanceCommand.mockResolvedValue(undefined);
tasksShowCommand.mockResolvedValue(undefined);
tasksNotifyCommand.mockResolvedValue(undefined);
tasksCancelCommand.mockResolvedValue(undefined);
@@ -245,6 +248,18 @@ describe("registerStatusHealthSessionsCommands", () => {
);
});
it("runs tasks maintenance subcommand with apply forwarding", async () => {
await runCli(["tasks", "--json", "maintenance", "--apply"]);
expect(tasksMaintenanceCommand).toHaveBeenCalledWith(
expect.objectContaining({
json: true,
apply: true,
}),
runtime,
);
});
it("runs tasks audit subcommand with filters", async () => {
await runCli([
"tasks",

View File

@@ -7,6 +7,7 @@ import {
tasksAuditCommand,
tasksCancelCommand,
tasksListCommand,
tasksMaintenanceCommand,
tasksNotifyCommand,
tasksShowCommand,
} from "../../commands/tasks.js";
@@ -305,6 +306,24 @@ export function registerStatusHealthSessionsCommands(program: Command) {
});
});
tasksCmd
.command("maintenance")
.description("Preview or apply task ledger maintenance")
.option("--json", "Output as JSON", false)
.option("--apply", "Apply reconciliation, cleanup stamping, and pruning", false)
.action(async (opts, command) => {
const parentOpts = command.parent?.opts() as { json?: boolean } | undefined;
await runCommandWithRuntime(defaultRuntime, async () => {
await tasksMaintenanceCommand(
{
json: Boolean(opts.json || parentOpts?.json),
apply: Boolean(opts.apply),
},
defaultRuntime,
);
});
});
tasksCmd
.command("show")
.description("Show one background task by task id, run id, or session key")