codex-supervisor-mcp 0.10.3 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/cleanup.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { createCleanupPlan, removePlannedWorktree } from "./cleanup-plan.js";
3
- import { appendTaskEvent, getTask, markCleanupPlanItemApplied, saveCleanupPlan, updateWorkItemDelivery, runIdFor } from "./task-store.js";
2
+ import { applyCleanupPlan, createCleanupPlan } from "./cleanup-plan.js";
3
+ import { getCleanupPlan, saveCleanupPlan } from "./task-store.js";
4
4
 
5
5
  function parseArgs(argv) {
6
- const options = { apply: false, taskIds: [] };
6
+ const options = { apply: false, taskIds: [], itemIds: [], planId: null };
7
7
  for (let index = 0; index < argv.length; index += 1) {
8
8
  const arg = argv[index];
9
9
  if (arg === "--apply") options.apply = true;
@@ -11,10 +11,19 @@ function parseArgs(argv) {
11
11
  else if (arg === "--task") {
12
12
  options.taskIds.push(argv[index + 1]);
13
13
  index += 1;
14
+ } else if (arg === "--plan") {
15
+ options.planId = argv[index + 1];
16
+ index += 1;
17
+ } else if (arg === "--item") {
18
+ options.itemIds.push(argv[index + 1]);
19
+ index += 1;
14
20
  } else if (arg === "--help" || arg === "-h") options.help = true;
15
21
  else throw new Error(`Unknown argument: ${arg}`);
16
22
  }
17
23
  if (options.taskIds.some((id) => !id)) throw new Error("--task requires a task id");
24
+ if (options.itemIds.some((id) => !id)) throw new Error("--item requires a cleanup plan item id");
25
+ if (options.apply && (!options.planId || options.itemIds.length === 0)) throw new Error("--apply requires --plan <plan_id> and one or more --item <item_id>");
26
+ if (!options.apply && (options.planId || options.itemIds.length)) throw new Error("--plan and --item are only valid with --apply");
18
27
  return options;
19
28
  }
20
29
 
@@ -23,50 +32,49 @@ function printHelp() {
23
32
 
24
33
  Options:
25
34
  --dry-run Create and print a SAFE / REVIEW / BLOCKED plan. Default.
26
- --apply Remove every SAFE worktree in the generated plan.
35
+ --apply Apply selected SAFE items from an existing plan.
27
36
  --task <task_id> Limit the plan to one task; repeatable.
37
+ --plan <plan_id> Existing cleanup plan to apply (required with --apply).
38
+ --item <item_id> SAFE item to apply; repeatable (required with --apply).
28
39
  -h, --help Show help.
29
40
 
30
41
  Cleanup never removes branches, task rows, events, JSONL logs or artifacts.
31
42
  `);
32
43
  }
33
44
 
34
- const options = parseArgs(process.argv.slice(2));
35
- if (options.help) {
36
- printHelp();
37
- process.exit(0);
38
- }
39
-
40
- const plan = await createCleanupPlan({ taskIds: options.taskIds.length ? options.taskIds : null });
41
- await saveCleanupPlan(plan);
42
- const applied = [];
43
- const skipped = [];
44
- if (options.apply) {
45
- for (const item of plan.items.filter((entry) => entry.verdict === "safe")) {
46
- const task = await getTask(item.task_id);
47
- try {
48
- await removePlannedWorktree(task, item.fingerprint);
49
- const now = await markCleanupPlanItemApplied(item.id, "cleanup_cli");
50
- await updateWorkItemDelivery(task.id, "cleanup_removed");
51
- await appendTaskEvent(task.id, { type: "supervisor.cleanup_removed", plan_id: plan.id, item_id: item.id, removed_at: now, retained: ["branch", "task", "events", "jsonl", "artifacts"] }, {
52
- runId: runIdFor(task.id, task.run_count ?? 1), actor: "supervisor"
53
- });
54
- applied.push({ task_id: task.id, worktree_path: task.worktree_path, removed_at: now });
55
- } catch (error) {
56
- skipped.push({ task_id: item.task_id, reason: error.message.split("\n")[0] });
57
- }
45
+ async function main() {
46
+ const options = parseArgs(process.argv.slice(2));
47
+ if (options.help) {
48
+ printHelp();
49
+ return;
58
50
  }
51
+
52
+ const plan = options.apply
53
+ ? await getCleanupPlan(options.planId)
54
+ : await createCleanupPlan({ taskIds: options.taskIds.length ? options.taskIds : null });
55
+ if (!plan) throw new Error(`cleanup plan not found: ${options.planId}`);
56
+ if (!options.apply) await saveCleanupPlan(plan);
57
+ const outcome = options.apply
58
+ ? await applyCleanupPlan({ plan, itemIds: options.itemIds, actor: "cleanup_cli" })
59
+ : { applied: [], skipped: [] };
60
+
61
+ console.log(JSON.stringify({
62
+ dry_run: !options.apply,
63
+ plan_id: plan.id,
64
+ generated_at: plan.generated_at,
65
+ expires_at: plan.expires_at,
66
+ policy: plan.policy,
67
+ summary: plan.summary,
68
+ items: plan.items,
69
+ applied: outcome.applied,
70
+ skipped: outcome.skipped,
71
+ retained: ["branch", "task", "events", "jsonl", "artifacts"]
72
+ }, null, 2));
59
73
  }
60
74
 
61
- console.log(JSON.stringify({
62
- dry_run: !options.apply,
63
- plan_id: plan.id,
64
- generated_at: plan.generated_at,
65
- expires_at: plan.expires_at,
66
- policy: plan.policy,
67
- summary: plan.summary,
68
- items: plan.items,
69
- applied,
70
- skipped,
71
- retained: ["branch", "task", "events", "jsonl", "artifacts"]
72
- }, null, 2));
75
+ try {
76
+ await main();
77
+ } catch (error) {
78
+ console.error(error.message);
79
+ process.exitCode = 1;
80
+ }