@cleocode/cleo 2026.4.80 → 2026.4.83

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/dist/cli/index.js CHANGED
@@ -1760,11 +1760,17 @@ function rowToTask(row) {
1760
1760
  };
1761
1761
  }
1762
1762
  function taskToRow(task) {
1763
+ const status = task.status ?? "pending";
1764
+ let pipelineStage = task.pipelineStage ?? null;
1765
+ if (pipelineStage === null || pipelineStage === void 0) {
1766
+ if (status === "done") pipelineStage = "contribution";
1767
+ else if (status === "cancelled") pipelineStage = "cancelled";
1768
+ }
1763
1769
  return {
1764
1770
  id: task.id,
1765
1771
  title: task.title ?? "",
1766
1772
  description: task.description ?? null,
1767
- status: task.status ?? "pending",
1773
+ status,
1768
1774
  priority: task.priority ?? "medium",
1769
1775
  type: task.type ?? null,
1770
1776
  parentId: task.parentId ?? null,
@@ -1789,7 +1795,7 @@ function taskToRow(task) {
1789
1795
  createdBy: task.provenance?.createdBy ?? null,
1790
1796
  modifiedBy: task.provenance?.modifiedBy ?? null,
1791
1797
  sessionId: task.provenance?.sessionId ?? null,
1792
- pipelineStage: task.pipelineStage ?? null,
1798
+ pipelineStage,
1793
1799
  assignee: task.assignee ?? null
1794
1800
  };
1795
1801
  }
@@ -17403,9 +17409,9 @@ async function readSequenceFromDb(cwd, accessor) {
17403
17409
  return isValidSequenceState(value) ? value : null;
17404
17410
  }
17405
17411
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
17406
- const { eq: eq21 } = await import("drizzle-orm");
17412
+ const { eq: eq20 } = await import("drizzle-orm");
17407
17413
  const db = await getDb4(cwd);
17408
- const rows = await db.select().from(schemaMeta).where(eq21(schemaMeta.key, SEQUENCE_META_KEY)).all();
17414
+ const rows = await db.select().from(schemaMeta).where(eq20(schemaMeta.key, SEQUENCE_META_KEY)).all();
17409
17415
  const raw = rows[0]?.value;
17410
17416
  if (!raw) return null;
17411
17417
  try {
@@ -19236,7 +19242,7 @@ async function linkPipelineAdr(projectRoot, taskId) {
19236
19242
  return result;
19237
19243
  }
19238
19244
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
19239
- const { and: and16, eq: eq21 } = await import("drizzle-orm");
19245
+ const { and: and16, eq: eq20 } = await import("drizzle-orm");
19240
19246
  const db = await getDb4(projectRoot);
19241
19247
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
19242
19248
  for (const filePath of matchingFiles) {
@@ -19246,7 +19252,7 @@ async function linkPipelineAdr(projectRoot, taskId) {
19246
19252
  const fm = record2.frontmatter;
19247
19253
  const content = readFileSync5(filePath, "utf-8");
19248
19254
  const relativePath = `.cleo/adrs/${filename}`;
19249
- const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq21(architectureDecisions.id, record2.id)).all();
19255
+ const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq20(architectureDecisions.id, record2.id)).all();
19250
19256
  const rowBase = {
19251
19257
  id: record2.id,
19252
19258
  title: record2.title,
@@ -19266,19 +19272,19 @@ async function linkPipelineAdr(projectRoot, taskId) {
19266
19272
  updatedAt: now2
19267
19273
  };
19268
19274
  if (existing.length > 0) {
19269
- await db.update(architectureDecisions).set(rowBase).where(eq21(architectureDecisions.id, record2.id));
19275
+ await db.update(architectureDecisions).set(rowBase).where(eq20(architectureDecisions.id, record2.id));
19270
19276
  } else {
19271
19277
  await db.insert(architectureDecisions).values({ ...rowBase, createdAt: now2 });
19272
19278
  }
19273
19279
  result.synced++;
19274
- await db.delete(adrTaskLinks).where(and16(eq21(adrTaskLinks.adrId, record2.id), eq21(adrTaskLinks.taskId, taskId)));
19280
+ await db.delete(adrTaskLinks).where(and16(eq20(adrTaskLinks.adrId, record2.id), eq20(adrTaskLinks.taskId, taskId)));
19275
19281
  await db.insert(adrTaskLinks).values({ adrId: record2.id, taskId, linkType: "implements" });
19276
19282
  result.linked.push({ adrId: record2.id, taskId });
19277
19283
  if (fm["Related ADRs"]) {
19278
19284
  const relatedIds = fm["Related ADRs"].split(",").map((r) => r.trim()).filter((r) => /^ADR-\d+$/.test(r));
19279
19285
  for (const toId of relatedIds) {
19280
19286
  try {
19281
- const targetExists = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq21(architectureDecisions.id, toId)).all();
19287
+ const targetExists = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq20(architectureDecisions.id, toId)).all();
19282
19288
  if (targetExists.length > 0) {
19283
19289
  await db.insert(adrRelations).values({ fromAdrId: record2.id, toAdrId: toId, relationType: "related" }).onConflictDoNothing();
19284
19290
  }
@@ -19442,7 +19448,7 @@ async function syncAdrsToDb(projectRoot) {
19442
19448
  return result;
19443
19449
  }
19444
19450
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
19445
- const { eq: eq21 } = await import("drizzle-orm");
19451
+ const { eq: eq20 } = await import("drizzle-orm");
19446
19452
  const db = await getDb4(projectRoot);
19447
19453
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
19448
19454
  const allFiles = collectAdrFiles(adrsDir);
@@ -19459,7 +19465,7 @@ async function syncAdrsToDb(projectRoot) {
19459
19465
  let supersededById = fm["Superseded By"] ? extractAdrIdFromRef(fm["Superseded By"]) : null;
19460
19466
  let amendsId = fm.Amends ? extractAdrIdFromRef(fm.Amends) : null;
19461
19467
  if (supersedesId) {
19462
- const exists2 = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq21(architectureDecisions.id, supersedesId)).all();
19468
+ const exists2 = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq20(architectureDecisions.id, supersedesId)).all();
19463
19469
  if (exists2.length === 0) {
19464
19470
  result.warnings.push(
19465
19471
  `${record2.id}: supersedes target ${supersedesId} not found in DB, setting to null`
@@ -19468,7 +19474,7 @@ async function syncAdrsToDb(projectRoot) {
19468
19474
  }
19469
19475
  }
19470
19476
  if (supersededById) {
19471
- const exists2 = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq21(architectureDecisions.id, supersededById)).all();
19477
+ const exists2 = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq20(architectureDecisions.id, supersededById)).all();
19472
19478
  if (exists2.length === 0) {
19473
19479
  result.warnings.push(
19474
19480
  `${record2.id}: supersededBy target ${supersededById} not found in DB, setting to null`
@@ -19477,7 +19483,7 @@ async function syncAdrsToDb(projectRoot) {
19477
19483
  }
19478
19484
  }
19479
19485
  if (amendsId) {
19480
- const exists2 = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq21(architectureDecisions.id, amendsId)).all();
19486
+ const exists2 = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq20(architectureDecisions.id, amendsId)).all();
19481
19487
  if (exists2.length === 0) {
19482
19488
  result.warnings.push(
19483
19489
  `${record2.id}: amends target ${amendsId} not found in DB, setting to null`
@@ -19503,18 +19509,18 @@ async function syncAdrsToDb(projectRoot) {
19503
19509
  topics: fm.Topics ?? null,
19504
19510
  updatedAt: now2
19505
19511
  };
19506
- const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq21(architectureDecisions.id, record2.id)).all();
19512
+ const existing = await db.select({ id: architectureDecisions.id }).from(architectureDecisions).where(eq20(architectureDecisions.id, record2.id)).all();
19507
19513
  if (existing.length > 0) {
19508
- await db.update(architectureDecisions).set(rowBase).where(eq21(architectureDecisions.id, record2.id));
19514
+ await db.update(architectureDecisions).set(rowBase).where(eq20(architectureDecisions.id, record2.id));
19509
19515
  result.updated++;
19510
19516
  } else {
19511
19517
  await db.insert(architectureDecisions).values({ ...rowBase, createdAt: now2 });
19512
19518
  result.inserted++;
19513
19519
  }
19514
- await db.delete(adrTaskLinks).where(eq21(adrTaskLinks.adrId, record2.id));
19520
+ await db.delete(adrTaskLinks).where(eq20(adrTaskLinks.adrId, record2.id));
19515
19521
  if (fm["Related Tasks"]) {
19516
19522
  for (const taskId of parseTaskIds2(fm["Related Tasks"])) {
19517
- const taskExists2 = await db.select({ id: tasks.id }).from(tasks).where(eq21(tasks.id, taskId)).all();
19523
+ const taskExists2 = await db.select({ id: tasks.id }).from(tasks).where(eq20(tasks.id, taskId)).all();
19518
19524
  if (taskExists2.length === 0) {
19519
19525
  result.warnings.push(
19520
19526
  `${record2.id}: related task ${taskId} not found in DB, skipping link`
@@ -25196,16 +25202,16 @@ async function queryAudit(options) {
25196
25202
  try {
25197
25203
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
25198
25204
  const { auditLog: auditLog2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
25199
- const { and: and16, eq: eq21, gte: gte4, or: or7 } = await import("drizzle-orm");
25205
+ const { and: and16, eq: eq20, gte: gte4, or: or7 } = await import("drizzle-orm");
25200
25206
  const db = await getDb4(process.cwd());
25201
25207
  const conditions = [];
25202
- if (options?.sessionId) conditions.push(eq21(auditLog2.sessionId, options.sessionId));
25203
- if (options?.domain) conditions.push(eq21(auditLog2.domain, options.domain));
25208
+ if (options?.sessionId) conditions.push(eq20(auditLog2.sessionId, options.sessionId));
25209
+ if (options?.domain) conditions.push(eq20(auditLog2.domain, options.domain));
25204
25210
  if (options?.operation)
25205
25211
  conditions.push(
25206
- or7(eq21(auditLog2.operation, options.operation), eq21(auditLog2.action, options.operation))
25212
+ or7(eq20(auditLog2.operation, options.operation), eq20(auditLog2.action, options.operation))
25207
25213
  );
25208
- if (options?.taskId) conditions.push(eq21(auditLog2.taskId, options.taskId));
25214
+ if (options?.taskId) conditions.push(eq20(auditLog2.taskId, options.taskId));
25209
25215
  if (options?.since) conditions.push(gte4(auditLog2.timestamp, options.since));
25210
25216
  const limit = options?.limit ?? 1e3;
25211
25217
  const rows = await db.select().from(auditLog2).where(conditions.length > 0 ? and16(...conditions) : void 0).orderBy(auditLog2.timestamp).limit(limit);
@@ -48510,7 +48516,7 @@ async function backfillRewardSignals(projectRoot, sessionId, lookbackDays = 30)
48510
48516
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
48511
48517
  const tasksDb = await getDb4(projectRoot);
48512
48518
  const { tasks: tasks2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
48513
- const { and: and16, eq: eq21, inArray: inArray9, gte: gte4, or: or7, isNotNull: isNotNull3 } = await import("drizzle-orm");
48519
+ const { and: and16, eq: eq20, inArray: inArray8, gte: gte4, or: or7, isNotNull: isNotNull3 } = await import("drizzle-orm");
48514
48520
  const cutoffTs = new Date(Date.now() - lookbackDays * 24 * 60 * 60 * 1e3).toISOString().replace("T", " ").slice(0, 19);
48515
48521
  const rawRows = await tasksDb.select({
48516
48522
  id: tasks2.id,
@@ -48520,8 +48526,8 @@ async function backfillRewardSignals(projectRoot, sessionId, lookbackDays = 30)
48520
48526
  cancelledAt: tasks2.cancelledAt
48521
48527
  }).from(tasks2).where(
48522
48528
  and16(
48523
- eq21(tasks2.sessionId, sessionId),
48524
- inArray9(tasks2.status, ["done", "cancelled"]),
48529
+ eq20(tasks2.sessionId, sessionId),
48530
+ inArray8(tasks2.status, ["done", "cancelled"]),
48525
48531
  or7(
48526
48532
  and16(isNotNull3(tasks2.completedAt), gte4(tasks2.completedAt, cutoffTs)),
48527
48533
  and16(isNotNull3(tasks2.cancelledAt), gte4(tasks2.cancelledAt, cutoffTs))
@@ -60037,13 +60043,13 @@ function extractYamlArray(content, field) {
60037
60043
  }
60038
60044
  const lines = content.split("\n");
60039
60045
  const items = [];
60040
- let inArray9 = false;
60046
+ let inArray8 = false;
60041
60047
  for (const line2 of lines) {
60042
60048
  if (line2.match(new RegExp(`^${field}:`))) {
60043
- inArray9 = true;
60049
+ inArray8 = true;
60044
60050
  continue;
60045
60051
  }
60046
- if (inArray9) {
60052
+ if (inArray8) {
60047
60053
  const itemMatch = line2.match(/^\s+-\s+["']?(.+?)["']?\s*$/);
60048
60054
  if (itemMatch) {
60049
60055
  items.push(itemMatch[1].trim());
@@ -62162,12 +62168,12 @@ async function getEnforcementMode(cwd) {
62162
62168
  }
62163
62169
  async function getLifecycleStatus(epicId, cwd) {
62164
62170
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
62165
- const { eq: eq21 } = await import("drizzle-orm");
62171
+ const { eq: eq20 } = await import("drizzle-orm");
62166
62172
  const db = await getDb4(cwd);
62167
62173
  const pipelineResult = await db.select({
62168
62174
  pipeline: lifecyclePipelines,
62169
62175
  task: tasks
62170
- }).from(lifecyclePipelines).innerJoin(tasks, eq21(lifecyclePipelines.taskId, tasks.id)).where(eq21(lifecyclePipelines.taskId, epicId)).limit(1);
62176
+ }).from(lifecyclePipelines).innerJoin(tasks, eq20(lifecyclePipelines.taskId, tasks.id)).where(eq20(lifecyclePipelines.taskId, epicId)).limit(1);
62171
62177
  if (pipelineResult.length === 0) {
62172
62178
  return {
62173
62179
  epicId,
@@ -62180,7 +62186,7 @@ async function getLifecycleStatus(epicId, cwd) {
62180
62186
  }
62181
62187
  const task = pipelineResult[0].task;
62182
62188
  const pipelineId = `pipeline-${epicId}`;
62183
- const stageRows = await db.select().from(lifecycleStages).where(eq21(lifecycleStages.pipelineId, pipelineId)).orderBy(lifecycleStages.sequence);
62189
+ const stageRows = await db.select().from(lifecycleStages).where(eq20(lifecycleStages.pipelineId, pipelineId)).orderBy(lifecycleStages.sequence);
62184
62190
  const stageDataMap = /* @__PURE__ */ new Map();
62185
62191
  for (const row of stageRows) {
62186
62192
  let parsedChain;
@@ -62249,10 +62255,10 @@ async function getLifecycleStatus(epicId, cwd) {
62249
62255
  }
62250
62256
  async function getLifecycleHistory(epicId, cwd) {
62251
62257
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
62252
- const { eq: eq21 } = await import("drizzle-orm");
62258
+ const { eq: eq20 } = await import("drizzle-orm");
62253
62259
  const db = await getDb4(cwd);
62254
62260
  const pipelineId = `pipeline-${epicId}`;
62255
- const stages = await db.select().from(lifecycleStages).where(eq21(lifecycleStages.pipelineId, pipelineId));
62261
+ const stages = await db.select().from(lifecycleStages).where(eq20(lifecycleStages.pipelineId, pipelineId));
62256
62262
  if (stages.length === 0) {
62257
62263
  return { epicId, history: [] };
62258
62264
  }
@@ -62282,7 +62288,7 @@ async function getLifecycleHistory(epicId, cwd) {
62282
62288
  }
62283
62289
  const stageIds = stages.map((s3) => s3.id);
62284
62290
  if (stageIds.length > 0) {
62285
- const gateResults = await db.select().from(lifecycleGateResults).where(eq21(lifecycleGateResults.stageId, stageIds[0]));
62291
+ const gateResults = await db.select().from(lifecycleGateResults).where(eq20(lifecycleGateResults.stageId, stageIds[0]));
62286
62292
  for (const gate of gateResults) {
62287
62293
  const stageName = stageIdToName.get(gate.stageId);
62288
62294
  if (stageName) {
@@ -62295,7 +62301,7 @@ async function getLifecycleHistory(epicId, cwd) {
62295
62301
  }
62296
62302
  }
62297
62303
  for (let i = 1; i < stageIds.length; i++) {
62298
- const additionalGates = await db.select().from(lifecycleGateResults).where(eq21(lifecycleGateResults.stageId, stageIds[i]));
62304
+ const additionalGates = await db.select().from(lifecycleGateResults).where(eq20(lifecycleGateResults.stageId, stageIds[i]));
62299
62305
  for (const gate of additionalGates) {
62300
62306
  const stageName = stageIdToName.get(gate.stageId);
62301
62307
  if (stageName) {
@@ -62314,16 +62320,16 @@ async function getLifecycleHistory(epicId, cwd) {
62314
62320
  }
62315
62321
  async function getLifecycleGates(epicId, cwd) {
62316
62322
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
62317
- const { eq: eq21 } = await import("drizzle-orm");
62323
+ const { eq: eq20 } = await import("drizzle-orm");
62318
62324
  const db = await getDb4(cwd);
62319
62325
  const pipelineId = `pipeline-${epicId}`;
62320
- const stages = await db.select().from(lifecycleStages).where(eq21(lifecycleStages.pipelineId, pipelineId));
62326
+ const stages = await db.select().from(lifecycleStages).where(eq20(lifecycleStages.pipelineId, pipelineId));
62321
62327
  if (stages.length === 0) {
62322
62328
  return {};
62323
62329
  }
62324
62330
  const gates = {};
62325
62331
  for (const stage of stages) {
62326
- const gateRows = await db.select().from(lifecycleGateResults).where(eq21(lifecycleGateResults.stageId, stage.id));
62332
+ const gateRows = await db.select().from(lifecycleGateResults).where(eq20(lifecycleGateResults.stageId, stage.id));
62327
62333
  if (gateRows.length > 0) {
62328
62334
  gates[stage.stageName] = {};
62329
62335
  for (const gateRow of gateRows) {
@@ -62387,7 +62393,7 @@ async function checkStagePrerequisites(epicId, targetStage, cwd) {
62387
62393
  }
62388
62394
  async function ensureLifecycleContext(epicId, stageName, cwd, options) {
62389
62395
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
62390
- const { eq: eq21 } = await import("drizzle-orm");
62396
+ const { eq: eq20 } = await import("drizzle-orm");
62391
62397
  const db = await getDb4(cwd);
62392
62398
  const pipelineId = `pipeline-${epicId}`;
62393
62399
  const stageId = `stage-${epicId}-${stageName}`;
@@ -62395,7 +62401,7 @@ async function ensureLifecycleContext(epicId, stageName, cwd, options) {
62395
62401
  getNativeDb3().prepare(
62396
62402
  `INSERT OR IGNORE INTO tasks (id, title, status, priority, created_at) VALUES (?, ?, 'pending', 'medium', datetime('now'))`
62397
62403
  ).run(epicId, `Task ${epicId}`);
62398
- const existingPipeline = await db.select().from(lifecyclePipelines).where(eq21(lifecyclePipelines.id, pipelineId)).limit(1).all();
62404
+ const existingPipeline = await db.select().from(lifecyclePipelines).where(eq20(lifecyclePipelines.id, pipelineId)).limit(1).all();
62399
62405
  if (existingPipeline.length === 0) {
62400
62406
  await db.insert(lifecyclePipelines).values({
62401
62407
  id: pipelineId,
@@ -62405,7 +62411,7 @@ async function ensureLifecycleContext(epicId, stageName, cwd, options) {
62405
62411
  startedAt: options.now
62406
62412
  }).run();
62407
62413
  }
62408
- const existingStage = await db.select().from(lifecycleStages).where(eq21(lifecycleStages.id, stageId)).limit(1).all();
62414
+ const existingStage = await db.select().from(lifecycleStages).where(eq20(lifecycleStages.id, stageId)).limit(1).all();
62409
62415
  if (existingStage.length === 0) {
62410
62416
  const sequence = isValidStage(stageName) ? STAGE_ORDER[stageName] : 0;
62411
62417
  await db.insert(lifecycleStages).values({
@@ -62418,7 +62424,7 @@ async function ensureLifecycleContext(epicId, stageName, cwd, options) {
62418
62424
  }).run();
62419
62425
  }
62420
62426
  if (options.updateCurrentStage) {
62421
- await db.update(lifecyclePipelines).set({ currentStageId: stageId }).where(eq21(lifecyclePipelines.id, pipelineId)).run();
62427
+ await db.update(lifecyclePipelines).set({ currentStageId: stageId }).where(eq20(lifecyclePipelines.id, pipelineId)).run();
62422
62428
  }
62423
62429
  return { db, pipelineId, stageId };
62424
62430
  }
@@ -62433,7 +62439,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
62433
62439
  `Invalid status: ${status}. Valid: ${validStatuses.join(", ")}`
62434
62440
  );
62435
62441
  }
62436
- const { eq: eq21 } = await import("drizzle-orm");
62442
+ const { eq: eq20 } = await import("drizzle-orm");
62437
62443
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
62438
62444
  const stageName = stage;
62439
62445
  const { db, stageId, pipelineId } = await ensureLifecycleContext(epicId, stage, cwd, {
@@ -62449,7 +62455,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
62449
62455
  status,
62450
62456
  related: artifact.related
62451
62457
  };
62452
- const existingStage = await db.select().from(lifecycleStages).where(eq21(lifecycleStages.id, stageId)).limit(1).all();
62458
+ const existingStage = await db.select().from(lifecycleStages).where(eq20(lifecycleStages.id, stageId)).limit(1).all();
62453
62459
  const sequence = STAGE_ORDER[stage];
62454
62460
  const stageValues = {
62455
62461
  status,
@@ -62476,7 +62482,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
62476
62482
  provenanceChainJson: JSON.stringify(provenanceChain)
62477
62483
  }).run();
62478
62484
  } else {
62479
- await db.update(lifecycleStages).set(stageValues).where(eq21(lifecycleStages.id, stageId)).run();
62485
+ await db.update(lifecycleStages).set(stageValues).where(eq20(lifecycleStages.id, stageId)).run();
62480
62486
  }
62481
62487
  if (status === "completed") {
62482
62488
  await linkProvenance(epicId, stageName, artifact.absolutePath, cwd);
@@ -62487,7 +62493,7 @@ async function recordStageProgress(epicId, stage, status, notes, cwd) {
62487
62493
  }
62488
62494
  }
62489
62495
  if (status === "in_progress" || status === "completed") {
62490
- await db.update(tasks).set({ pipelineStage: stage }).where(eq21(tasks.id, epicId)).run();
62496
+ await db.update(tasks).set({ pipelineStage: stage }).where(eq20(tasks.id, epicId)).run();
62491
62497
  }
62492
62498
  return { epicId, stage, status, timestamp: now2 };
62493
62499
  }
@@ -62499,7 +62505,7 @@ async function resetStage(epicId, stage, reason, cwd) {
62499
62505
  if (!PIPELINE_STAGES.includes(stage)) {
62500
62506
  throw new CleoError(2 /* INVALID_INPUT */, `Invalid stage: ${stage}`);
62501
62507
  }
62502
- const { eq: eq21 } = await import("drizzle-orm");
62508
+ const { eq: eq20 } = await import("drizzle-orm");
62503
62509
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
62504
62510
  const { db, stageId } = await ensureLifecycleContext(epicId, stage, cwd, {
62505
62511
  now: now2,
@@ -62512,11 +62518,11 @@ async function resetStage(epicId, stage, reason, cwd) {
62512
62518
  skippedAt: null,
62513
62519
  skipReason: null,
62514
62520
  notesJson: JSON.stringify([`Reset: ${reason}`])
62515
- }).where(eq21(lifecycleStages.id, stageId)).run();
62521
+ }).where(eq20(lifecycleStages.id, stageId)).run();
62516
62522
  return { epicId, stage, reason };
62517
62523
  }
62518
62524
  async function passGate(epicId, gateName, agent, notes, cwd) {
62519
- const { eq: eq21 } = await import("drizzle-orm");
62525
+ const { eq: eq20 } = await import("drizzle-orm");
62520
62526
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
62521
62527
  const stageName = gateName.split("-")[0];
62522
62528
  const gateId = `gate-${epicId}-${stageName}-${gateName}`;
@@ -62525,7 +62531,7 @@ async function passGate(epicId, gateName, agent, notes, cwd) {
62525
62531
  stageStatusOnCreate: "in_progress",
62526
62532
  updateCurrentStage: true
62527
62533
  });
62528
- const existingGate = await db.select().from(lifecycleGateResults).where(eq21(lifecycleGateResults.id, gateId)).limit(1).all();
62534
+ const existingGate = await db.select().from(lifecycleGateResults).where(eq20(lifecycleGateResults.id, gateId)).limit(1).all();
62529
62535
  const gateValues = {
62530
62536
  id: gateId,
62531
62537
  stageId,
@@ -62537,14 +62543,14 @@ async function passGate(epicId, gateName, agent, notes, cwd) {
62537
62543
  reason: null
62538
62544
  };
62539
62545
  if (existingGate.length > 0) {
62540
- await db.update(lifecycleGateResults).set(gateValues).where(eq21(lifecycleGateResults.id, gateId)).run();
62546
+ await db.update(lifecycleGateResults).set(gateValues).where(eq20(lifecycleGateResults.id, gateId)).run();
62541
62547
  } else {
62542
62548
  await db.insert(lifecycleGateResults).values(gateValues).run();
62543
62549
  }
62544
62550
  return { epicId, gateName, timestamp: now2 };
62545
62551
  }
62546
62552
  async function failGate(epicId, gateName, reason, cwd) {
62547
- const { eq: eq21 } = await import("drizzle-orm");
62553
+ const { eq: eq20 } = await import("drizzle-orm");
62548
62554
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
62549
62555
  const stageName = gateName.split("-")[0];
62550
62556
  const gateId = `gate-${epicId}-${stageName}-${gateName}`;
@@ -62553,7 +62559,7 @@ async function failGate(epicId, gateName, reason, cwd) {
62553
62559
  stageStatusOnCreate: "in_progress",
62554
62560
  updateCurrentStage: true
62555
62561
  });
62556
- const existingGate = await db.select().from(lifecycleGateResults).where(eq21(lifecycleGateResults.id, gateId)).limit(1).all();
62562
+ const existingGate = await db.select().from(lifecycleGateResults).where(eq20(lifecycleGateResults.id, gateId)).limit(1).all();
62557
62563
  const gateValues = {
62558
62564
  id: gateId,
62559
62565
  stageId,
@@ -62565,7 +62571,7 @@ async function failGate(epicId, gateName, reason, cwd) {
62565
62571
  reason: reason ?? null
62566
62572
  };
62567
62573
  if (existingGate.length > 0) {
62568
- await db.update(lifecycleGateResults).set(gateValues).where(eq21(lifecycleGateResults.id, gateId)).run();
62574
+ await db.update(lifecycleGateResults).set(gateValues).where(eq20(lifecycleGateResults.id, gateId)).run();
62569
62575
  } else {
62570
62576
  await db.insert(lifecycleGateResults).values(gateValues).run();
62571
62577
  }
@@ -62771,6 +62777,9 @@ var init_enforcement = __esm({
62771
62777
  });
62772
62778
 
62773
62779
  // packages/core/src/tasks/pipeline-stage.ts
62780
+ function isTerminalPipelineStage(stage) {
62781
+ return !!stage && TERMINAL_PIPELINE_STAGES.has(stage);
62782
+ }
62774
62783
  function isValidPipelineStage(stage) {
62775
62784
  return TASK_PIPELINE_STAGES.includes(stage);
62776
62785
  }
@@ -62822,7 +62831,7 @@ function validatePipelineTransition(currentStage, newStage) {
62822
62831
  );
62823
62832
  }
62824
62833
  }
62825
- var TASK_PIPELINE_STAGES, STAGE_ORDER2;
62834
+ var TASK_PIPELINE_STAGES, STAGE_ORDER2, TERMINAL_PIPELINE_STAGES;
62826
62835
  var init_pipeline_stage = __esm({
62827
62836
  "packages/core/src/tasks/pipeline-stage.ts"() {
62828
62837
  "use strict";
@@ -62838,7 +62847,8 @@ var init_pipeline_stage = __esm({
62838
62847
  "validation",
62839
62848
  "testing",
62840
62849
  "release",
62841
- "contribution"
62850
+ "contribution",
62851
+ "cancelled"
62842
62852
  ];
62843
62853
  STAGE_ORDER2 = {
62844
62854
  research: 1,
@@ -62850,8 +62860,13 @@ var init_pipeline_stage = __esm({
62850
62860
  validation: 7,
62851
62861
  testing: 8,
62852
62862
  release: 9,
62853
- contribution: 10
62863
+ contribution: 10,
62864
+ cancelled: 11
62854
62865
  };
62866
+ TERMINAL_PIPELINE_STAGES = /* @__PURE__ */ new Set([
62867
+ "contribution",
62868
+ "cancelled"
62869
+ ]);
62855
62870
  }
62856
62871
  });
62857
62872
 
@@ -67450,9 +67465,9 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
67450
67465
  const projectHash = generateProjectHash(projectPath);
67451
67466
  await nexusInit();
67452
67467
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67453
- const { eq: eq21 } = await import("drizzle-orm");
67468
+ const { eq: eq20 } = await import("drizzle-orm");
67454
67469
  const db = await getNexusDb2();
67455
- const existingRows = await db.select().from(projectRegistry).where(eq21(projectRegistry.projectHash, projectHash));
67470
+ const existingRows = await db.select().from(projectRegistry).where(eq20(projectRegistry.projectHash, projectHash));
67456
67471
  const existing = existingRows[0];
67457
67472
  if (existing?.permissions) {
67458
67473
  throw new CleoError(
@@ -67461,7 +67476,7 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
67461
67476
  );
67462
67477
  }
67463
67478
  if (!existing) {
67464
- const nameConflictRows = await db.select().from(projectRegistry).where(eq21(projectRegistry.name, projectName));
67479
+ const nameConflictRows = await db.select().from(projectRegistry).where(eq20(projectRegistry.name, projectName));
67465
67480
  if (nameConflictRows.length > 0) {
67466
67481
  throw new CleoError(
67467
67482
  6 /* VALIDATION_ERROR */,
@@ -67484,7 +67499,7 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
67484
67499
  lastSeen: now2,
67485
67500
  brainDbPath,
67486
67501
  tasksDbPath
67487
- }).where(eq21(projectRegistry.projectHash, projectHash));
67502
+ }).where(eq20(projectRegistry.projectHash, projectHash));
67488
67503
  } else {
67489
67504
  if (!projectId) {
67490
67505
  projectId = randomUUID4();
@@ -67525,9 +67540,9 @@ async function nexusUnregister(nameOrHash) {
67525
67540
  throw new CleoError(4 /* NOT_FOUND */, `Project not found in registry: ${nameOrHash}`);
67526
67541
  }
67527
67542
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67528
- const { eq: eq21 } = await import("drizzle-orm");
67543
+ const { eq: eq20 } = await import("drizzle-orm");
67529
67544
  const db = await getNexusDb2();
67530
- await db.delete(projectRegistry).where(eq21(projectRegistry.projectHash, project.hash));
67545
+ await db.delete(projectRegistry).where(eq20(projectRegistry.projectHash, project.hash));
67531
67546
  await writeNexusAudit({
67532
67547
  action: "unregister",
67533
67548
  projectHash: project.hash,
@@ -67549,9 +67564,9 @@ async function nexusList() {
67549
67564
  async function nexusGetProject(nameOrHash) {
67550
67565
  try {
67551
67566
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67552
- const { eq: eq21, or: or7 } = await import("drizzle-orm");
67567
+ const { eq: eq20, or: or7 } = await import("drizzle-orm");
67553
67568
  const db = await getNexusDb2();
67554
- const rows = await db.select().from(projectRegistry).where(or7(eq21(projectRegistry.projectHash, nameOrHash), eq21(projectRegistry.name, nameOrHash)));
67569
+ const rows = await db.select().from(projectRegistry).where(or7(eq20(projectRegistry.projectHash, nameOrHash), eq20(projectRegistry.name, nameOrHash)));
67555
67570
  const row = rows[0];
67556
67571
  if (!row) return null;
67557
67572
  return rowToProject(row);
@@ -67574,14 +67589,14 @@ async function nexusSync(nameOrHash) {
67574
67589
  const meta3 = await readProjectMeta(project.path);
67575
67590
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
67576
67591
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67577
- const { eq: eq21 } = await import("drizzle-orm");
67592
+ const { eq: eq20 } = await import("drizzle-orm");
67578
67593
  const db = await getNexusDb2();
67579
67594
  await db.update(projectRegistry).set({
67580
67595
  taskCount: meta3.taskCount,
67581
67596
  labelsJson: JSON.stringify(meta3.labels),
67582
67597
  lastSync: now2,
67583
67598
  lastSeen: now2
67584
- }).where(eq21(projectRegistry.projectHash, project.hash));
67599
+ }).where(eq20(projectRegistry.projectHash, project.hash));
67585
67600
  await writeNexusAudit({
67586
67601
  action: "sync",
67587
67602
  projectHash: project.hash,
@@ -67595,7 +67610,7 @@ async function nexusSyncAll() {
67595
67610
  let synced = 0;
67596
67611
  let failed = 0;
67597
67612
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67598
- const { eq: eq21 } = await import("drizzle-orm");
67613
+ const { eq: eq20 } = await import("drizzle-orm");
67599
67614
  const db = await getNexusDb2();
67600
67615
  for (const project of projects) {
67601
67616
  try {
@@ -67606,7 +67621,7 @@ async function nexusSyncAll() {
67606
67621
  labelsJson: JSON.stringify(meta3.labels),
67607
67622
  lastSync: now2,
67608
67623
  lastSeen: now2
67609
- }).where(eq21(projectRegistry.projectHash, project.hash));
67624
+ }).where(eq20(projectRegistry.projectHash, project.hash));
67610
67625
  synced++;
67611
67626
  } catch {
67612
67627
  failed++;
@@ -67626,9 +67641,9 @@ async function nexusUpdateIndexStats(projectPath, stats2) {
67626
67641
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
67627
67642
  try {
67628
67643
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67629
- const { eq: eq21 } = await import("drizzle-orm");
67644
+ const { eq: eq20 } = await import("drizzle-orm");
67630
67645
  const db = await getNexusDb2();
67631
- const rows = await db.select().from(projectRegistry).where(eq21(projectRegistry.projectHash, projectHash));
67646
+ const rows = await db.select().from(projectRegistry).where(eq20(projectRegistry.projectHash, projectHash));
67632
67647
  if (rows.length === 0) {
67633
67648
  try {
67634
67649
  await nexusRegister(projectPath);
@@ -67639,7 +67654,7 @@ async function nexusUpdateIndexStats(projectPath, stats2) {
67639
67654
  lastIndexed: now2,
67640
67655
  statsJson: JSON.stringify(stats2),
67641
67656
  lastSeen: now2
67642
- }).where(eq21(projectRegistry.projectHash, projectHash));
67657
+ }).where(eq20(projectRegistry.projectHash, projectHash));
67643
67658
  await writeNexusAudit({
67644
67659
  action: "update-index-stats",
67645
67660
  projectHash,
@@ -67661,9 +67676,9 @@ async function nexusSetPermission(nameOrHash, permission) {
67661
67676
  throw new CleoError(4 /* NOT_FOUND */, `Project not found in registry: ${nameOrHash}`);
67662
67677
  }
67663
67678
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67664
- const { eq: eq21 } = await import("drizzle-orm");
67679
+ const { eq: eq20 } = await import("drizzle-orm");
67665
67680
  const db = await getNexusDb2();
67666
- await db.update(projectRegistry).set({ permissions: permission }).where(eq21(projectRegistry.projectHash, project.hash));
67681
+ await db.update(projectRegistry).set({ permissions: permission }).where(eq20(projectRegistry.projectHash, project.hash));
67667
67682
  await writeNexusAudit({
67668
67683
  action: "set-permission",
67669
67684
  projectHash: project.hash,
@@ -67679,12 +67694,12 @@ async function nexusReconcile(projectRoot) {
67679
67694
  }
67680
67695
  await nexusInit();
67681
67696
  const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
67682
- const { eq: eq21 } = await import("drizzle-orm");
67697
+ const { eq: eq20 } = await import("drizzle-orm");
67683
67698
  const db = await getNexusDb2();
67684
67699
  const projectId = await readProjectId(projectRoot);
67685
67700
  const currentHash = generateProjectHash(projectRoot);
67686
67701
  if (projectId) {
67687
- const hashRows2 = await db.select().from(projectRegistry).where(eq21(projectRegistry.projectHash, currentHash));
67702
+ const hashRows2 = await db.select().from(projectRegistry).where(eq20(projectRegistry.projectHash, currentHash));
67688
67703
  const hashMatch2 = hashRows2[0];
67689
67704
  if (hashMatch2 && hashMatch2.projectId !== projectId) {
67690
67705
  await writeNexusAudit({
@@ -67703,12 +67718,12 @@ async function nexusReconcile(projectRoot) {
67703
67718
  }
67704
67719
  }
67705
67720
  if (projectId) {
67706
- const idRows = await db.select().from(projectRegistry).where(eq21(projectRegistry.projectId, projectId));
67721
+ const idRows = await db.select().from(projectRegistry).where(eq20(projectRegistry.projectId, projectId));
67707
67722
  const existing = idRows[0];
67708
67723
  if (existing) {
67709
67724
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
67710
67725
  if (existing.projectPath === projectRoot) {
67711
- await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq21(projectRegistry.projectId, projectId));
67726
+ await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq20(projectRegistry.projectId, projectId));
67712
67727
  await writeNexusAudit({
67713
67728
  action: "reconcile",
67714
67729
  projectHash: currentHash,
@@ -67724,7 +67739,7 @@ async function nexusReconcile(projectRoot) {
67724
67739
  projectPath: projectRoot,
67725
67740
  projectHash: currentHash,
67726
67741
  lastSeen: now2
67727
- }).where(eq21(projectRegistry.projectId, projectId));
67742
+ }).where(eq20(projectRegistry.projectId, projectId));
67728
67743
  await writeNexusAudit({
67729
67744
  action: "reconcile",
67730
67745
  projectHash: currentHash,
@@ -67736,11 +67751,11 @@ async function nexusReconcile(projectRoot) {
67736
67751
  return { status: "path_updated", oldPath, newPath: projectRoot };
67737
67752
  }
67738
67753
  }
67739
- const hashRows = await db.select().from(projectRegistry).where(eq21(projectRegistry.projectHash, currentHash));
67754
+ const hashRows = await db.select().from(projectRegistry).where(eq20(projectRegistry.projectHash, currentHash));
67740
67755
  const hashMatch = hashRows[0];
67741
67756
  if (hashMatch) {
67742
67757
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
67743
- await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq21(projectRegistry.projectHash, currentHash));
67758
+ await db.update(projectRegistry).set({ lastSeen: now2 }).where(eq20(projectRegistry.projectHash, currentHash));
67744
67759
  await writeNexusAudit({
67745
67760
  action: "reconcile",
67746
67761
  projectHash: currentHash,
@@ -69369,6 +69384,9 @@ async function completeTask(options, cwd, accessor) {
69369
69384
  if (completionStage && isValidPipelineStage(completionStage) && EXECUTION_STAGES_FOR_RELEASE.has(completionStage)) {
69370
69385
  task.pipelineStage = "release";
69371
69386
  }
69387
+ if (!isTerminalPipelineStage(task.pipelineStage)) {
69388
+ task.pipelineStage = "contribution";
69389
+ }
69372
69390
  task.status = "done";
69373
69391
  task.completedAt = now2;
69374
69392
  task.updatedAt = now2;
@@ -69392,6 +69410,9 @@ async function completeTask(options, cwd, accessor) {
69392
69410
  parent.status = "done";
69393
69411
  parent.completedAt = now2;
69394
69412
  parent.updatedAt = now2;
69413
+ if (!isTerminalPipelineStage(parent.pipelineStage)) {
69414
+ parent.pipelineStage = "contribution";
69415
+ }
69395
69416
  autoCompleted.push(parent.id);
69396
69417
  autoCompletedTasks.push(parent);
69397
69418
  }
@@ -91406,7 +91427,6 @@ var init_cleo = __esm({
91406
91427
  // packages/core/src/index.ts
91407
91428
  var init_src3 = __esm({
91408
91429
  "packages/core/src/index.ts"() {
91409
- "use strict";
91410
91430
  init_src();
91411
91431
  init_adapters();
91412
91432
  init_admin();
@@ -106950,113 +106970,6 @@ var init_types4 = __esm({
106950
106970
  }
106951
106971
  });
106952
106972
 
106953
- // packages/core/src/lifecycle/backfill-pipeline-stage.ts
106954
- import { eq as eq15, inArray as inArray6 } from "drizzle-orm";
106955
- async function backfillPipelineStageFromLifecycle(options = {}, cwd) {
106956
- const { dryRun = false, force = false } = options;
106957
- const db = await getDb(cwd);
106958
- if (!force) {
106959
- const guard = await db.select().from(schemaMeta).where(eq15(schemaMeta.key, BACKFILL_KEY)).limit(1).all();
106960
- if (guard.length > 0) {
106961
- return {
106962
- alreadyRun: true,
106963
- dryRun,
106964
- tasksScanned: 0,
106965
- tasksUpdated: 0,
106966
- changes: []
106967
- };
106968
- }
106969
- }
106970
- const advancingStatuses = [
106971
- "completed",
106972
- "in_progress",
106973
- "skipped"
106974
- ];
106975
- const rows = await db.select({
106976
- taskId: lifecyclePipelines.taskId,
106977
- stageName: lifecycleStages.stageName,
106978
- sequence: lifecycleStages.sequence,
106979
- status: lifecycleStages.status,
106980
- currentPipelineStage: tasks.pipelineStage
106981
- }).from(lifecyclePipelines).innerJoin(
106982
- lifecycleStages,
106983
- eq15(lifecycleStages.pipelineId, lifecyclePipelines.id)
106984
- ).innerJoin(tasks, eq15(tasks.id, lifecyclePipelines.taskId)).where(inArray6(lifecycleStages.status, advancingStatuses)).all();
106985
- const highestPerTask = /* @__PURE__ */ new Map();
106986
- for (const row of rows) {
106987
- const existing = highestPerTask.get(row.taskId);
106988
- if (!existing || row.sequence > existing.sequence) {
106989
- highestPerTask.set(row.taskId, {
106990
- stageName: row.stageName,
106991
- sequence: row.sequence,
106992
- currentPipelineStage: row.currentPipelineStage ?? null
106993
- });
106994
- }
106995
- }
106996
- const changes = [];
106997
- for (const [taskId, { stageName, sequence, currentPipelineStage }] of highestPerTask) {
106998
- const currentOrder = currentPipelineStage ? STAGE_ORDER3[currentPipelineStage] ?? 0 : 0;
106999
- if (sequence > currentOrder) {
107000
- changes.push({
107001
- taskId,
107002
- previousStage: currentPipelineStage,
107003
- newStage: stageName
107004
- });
107005
- }
107006
- }
107007
- const tasksScanned = highestPerTask.size;
107008
- if (!dryRun && changes.length > 0) {
107009
- const now2 = (/* @__PURE__ */ new Date()).toISOString();
107010
- for (const change of changes) {
107011
- await db.update(tasks).set({
107012
- pipelineStage: change.newStage,
107013
- updatedAt: now2
107014
- }).where(eq15(tasks.id, change.taskId)).run();
107015
- }
107016
- }
107017
- if (!dryRun) {
107018
- const guardValue = JSON.stringify({
107019
- ranAt: (/* @__PURE__ */ new Date()).toISOString(),
107020
- tasksUpdated: changes.length,
107021
- task: "T869"
107022
- });
107023
- await db.insert(schemaMeta).values({ key: BACKFILL_KEY, value: guardValue }).onConflictDoUpdate({ target: schemaMeta.key, set: { value: guardValue } }).run();
107024
- }
107025
- return {
107026
- alreadyRun: false,
107027
- dryRun,
107028
- tasksScanned,
107029
- tasksUpdated: changes.length,
107030
- changes
107031
- };
107032
- }
107033
- async function isPipelineStageBackfillDone(cwd) {
107034
- const db = await getDb(cwd);
107035
- const guard = await db.select().from(schemaMeta).where(eq15(schemaMeta.key, BACKFILL_KEY)).limit(1).all();
107036
- return guard.length > 0;
107037
- }
107038
- var BACKFILL_KEY, STAGE_ORDER3;
107039
- var init_backfill_pipeline_stage = __esm({
107040
- "packages/core/src/lifecycle/backfill-pipeline-stage.ts"() {
107041
- "use strict";
107042
- init_sqlite2();
107043
- init_tasks_schema();
107044
- BACKFILL_KEY = "backfill:pipeline-stage-from-lifecycle";
107045
- STAGE_ORDER3 = {
107046
- research: 1,
107047
- consensus: 2,
107048
- architecture_decision: 3,
107049
- specification: 4,
107050
- decomposition: 5,
107051
- implementation: 6,
107052
- validation: 7,
107053
- testing: 8,
107054
- release: 9,
107055
- contribution: 10
107056
- };
107057
- }
107058
- });
107059
-
107060
106973
  // packages/core/src/validation/chain-validation.ts
107061
106974
  function validateChainShape(shape) {
107062
106975
  const errors = [];
@@ -107194,9 +107107,9 @@ async function addChain(chain, projectRoot) {
107194
107107
  }
107195
107108
  async function showChain(id2, projectRoot) {
107196
107109
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
107197
- const { eq: eq21 } = await import("drizzle-orm");
107110
+ const { eq: eq20 } = await import("drizzle-orm");
107198
107111
  const db = await getDb4(projectRoot);
107199
- const rows = await db.select().from(warpChains).where(eq21(warpChains.id, id2));
107112
+ const rows = await db.select().from(warpChains).where(eq20(warpChains.id, id2));
107200
107113
  if (rows.length === 0) return null;
107201
107114
  return JSON.parse(rows[0].definition);
107202
107115
  }
@@ -107243,9 +107156,9 @@ async function createInstance(params2, projectRoot) {
107243
107156
  }
107244
107157
  async function showInstance(id2, projectRoot) {
107245
107158
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
107246
- const { eq: eq21 } = await import("drizzle-orm");
107159
+ const { eq: eq20 } = await import("drizzle-orm");
107247
107160
  const db = await getDb4(projectRoot);
107248
- const rows = await db.select().from(warpChainInstances).where(eq21(warpChainInstances.id, id2));
107161
+ const rows = await db.select().from(warpChainInstances).where(eq20(warpChainInstances.id, id2));
107249
107162
  if (rows.length === 0) return null;
107250
107163
  const row = rows[0];
107251
107164
  return {
@@ -107291,11 +107204,11 @@ async function advanceInstance(id2, nextStage, gateResults, projectRoot) {
107291
107204
  }
107292
107205
  }
107293
107206
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
107294
- const { eq: eq21 } = await import("drizzle-orm");
107207
+ const { eq: eq20 } = await import("drizzle-orm");
107295
107208
  const db = await getDb4(projectRoot);
107296
107209
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
107297
107210
  const existingResults = [];
107298
- const row = (await db.select().from(warpChainInstances).where(eq21(warpChainInstances.id, id2)))[0];
107211
+ const row = (await db.select().from(warpChainInstances).where(eq20(warpChainInstances.id, id2)))[0];
107299
107212
  if (row?.gateResults) {
107300
107213
  existingResults.push(...JSON.parse(row.gateResults));
107301
107214
  }
@@ -107305,7 +107218,7 @@ async function advanceInstance(id2, nextStage, gateResults, projectRoot) {
107305
107218
  gateResults: JSON.stringify(allResults),
107306
107219
  status: "active",
107307
107220
  updatedAt: now2
107308
- }).where(eq21(warpChainInstances.id, id2));
107221
+ }).where(eq20(warpChainInstances.id, id2));
107309
107222
  return {
107310
107223
  ...instance,
107311
107224
  currentStage: nextStage,
@@ -107830,7 +107743,7 @@ var init_gate_runner = __esm({
107830
107743
 
107831
107744
  // packages/core/src/lifecycle/ivtr-loop.ts
107832
107745
  import { createHash as createHash20 } from "node:crypto";
107833
- import { eq as eq16 } from "drizzle-orm";
107746
+ import { eq as eq15 } from "drizzle-orm";
107834
107747
  function nextPhase(current) {
107835
107748
  const idx = PHASE_ORDER.indexOf(current);
107836
107749
  if (idx === -1 || idx >= PHASE_ORDER.length - 1) return null;
@@ -107838,7 +107751,7 @@ function nextPhase(current) {
107838
107751
  }
107839
107752
  async function readIvtrStateRaw(taskId, cwd) {
107840
107753
  const db = await getDb(cwd);
107841
- const rows = await db.select({ ivtrState: tasks.ivtrState }).from(tasks).where(eq16(tasks.id, taskId)).all();
107754
+ const rows = await db.select({ ivtrState: tasks.ivtrState }).from(tasks).where(eq15(tasks.id, taskId)).all();
107842
107755
  if (rows.length === 0 || rows[0]?.ivtrState == null) return null;
107843
107756
  try {
107844
107757
  return JSON.parse(rows[0].ivtrState);
@@ -107849,12 +107762,12 @@ async function readIvtrStateRaw(taskId, cwd) {
107849
107762
  }
107850
107763
  async function writeIvtrState(state, cwd) {
107851
107764
  const db = await getDb(cwd);
107852
- const exists2 = await db.select({ id: tasks.id }).from(tasks).where(eq16(tasks.id, state.taskId)).get();
107765
+ const exists2 = await db.select({ id: tasks.id }).from(tasks).where(eq15(tasks.id, state.taskId)).get();
107853
107766
  if (!exists2) {
107854
107767
  throw new Error(`Task ${state.taskId} not found --- cannot write IVTR state`);
107855
107768
  }
107856
107769
  const json3 = JSON.stringify(state);
107857
- await db.update(tasks).set({ ivtrState: json3, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(eq16(tasks.id, state.taskId)).run();
107770
+ await db.update(tasks).set({ ivtrState: json3, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(eq15(tasks.id, state.taskId)).run();
107858
107771
  }
107859
107772
  async function startIvtr(taskId, options) {
107860
107773
  const existing = await readIvtrStateRaw(taskId, options?.cwd);
@@ -107995,7 +107908,7 @@ async function releaseIvtr(taskId, options) {
107995
107908
  state.currentPhase = "released";
107996
107909
  await writeIvtrState(state, options?.cwd);
107997
107910
  const db = await getDb(options?.cwd);
107998
- await db.update(tasks).set({ status: "done", completedAt: now2, updatedAt: now2 }).where(eq16(tasks.id, taskId)).all();
107911
+ await db.update(tasks).set({ status: "done", completedAt: now2, updatedAt: now2 }).where(eq15(tasks.id, taskId)).all();
107999
107912
  log11.info({ taskId }, "IVTR released --- task marked done");
108000
107913
  return { released: true };
108001
107914
  }
@@ -109749,7 +109662,7 @@ var init_brain_maintenance = __esm({
109749
109662
  });
109750
109663
 
109751
109664
  // packages/core/src/memory/brain-purge.ts
109752
- import { inArray as inArray7, ne as ne3, sql as sql15 } from "drizzle-orm";
109665
+ import { inArray as inArray6, ne as ne3, sql as sql15 } from "drizzle-orm";
109753
109666
  function countRowsNative(tableName) {
109754
109667
  const nativeDb = getBrainNativeDb();
109755
109668
  if (!nativeDb) return 0;
@@ -109798,7 +109711,7 @@ async function purgeBrainNoise(projectRoot) {
109798
109711
  const BATCH = 500;
109799
109712
  for (let i = 0; i < patternIdsToDelete.length; i += BATCH) {
109800
109713
  const batch = patternIdsToDelete.slice(i, i + BATCH);
109801
- await db.delete(brainPatterns).where(inArray7(brainPatterns.id, batch));
109714
+ await db.delete(brainPatterns).where(inArray6(brainPatterns.id, batch));
109802
109715
  patternsDeleted += batch.length;
109803
109716
  }
109804
109717
  }
@@ -109810,7 +109723,7 @@ async function purgeBrainNoise(projectRoot) {
109810
109723
  const BATCH = 500;
109811
109724
  for (let i = 0; i < ids.length; i += BATCH) {
109812
109725
  const batch = ids.slice(i, i + BATCH);
109813
- await db.delete(brainLearnings).where(inArray7(brainLearnings.id, batch));
109726
+ await db.delete(brainLearnings).where(inArray6(brainLearnings.id, batch));
109814
109727
  }
109815
109728
  }
109816
109729
  console.log(`Learnings deleted (all): ${learningsDeleted}`);
@@ -109818,7 +109731,7 @@ async function purgeBrainNoise(projectRoot) {
109818
109731
  const decisionsDeleted = decisionsToDelete.length;
109819
109732
  if (decisionsDeleted > 0) {
109820
109733
  const ids = decisionsToDelete.map((r) => r.id);
109821
- await db.delete(brainDecisions).where(inArray7(brainDecisions.id, ids));
109734
+ await db.delete(brainDecisions).where(inArray6(brainDecisions.id, ids));
109822
109735
  }
109823
109736
  console.log(`Decisions deleted (all except D-mntpeeer): ${decisionsDeleted}`);
109824
109737
  const allObservations = await db.select().from(brainObservations);
@@ -109865,7 +109778,7 @@ async function purgeBrainNoise(projectRoot) {
109865
109778
  const BATCH = 500;
109866
109779
  for (let i = 0; i < obsIdsToDelete.length; i += BATCH) {
109867
109780
  const batch = obsIdsToDelete.slice(i, i + BATCH);
109868
- await db.delete(brainObservations).where(inArray7(brainObservations.id, batch));
109781
+ await db.delete(brainObservations).where(inArray6(brainObservations.id, batch));
109869
109782
  observationsDeleted += batch.length;
109870
109783
  }
109871
109784
  }
@@ -111817,7 +111730,7 @@ var init_engine_compat = __esm({
111817
111730
  import { createHash as createHash22 } from "node:crypto";
111818
111731
  import { existsSync as existsSync113, readFileSync as readFileSync82, renameSync as renameSync8 } from "node:fs";
111819
111732
  import { join as join114 } from "node:path";
111820
- import { and as and13, count as count3, desc as desc6, eq as eq17, gte as gte3, isNull as isNull3, like as like3, lte as lte2, or as or5 } from "drizzle-orm";
111733
+ import { and as and13, count as count3, desc as desc6, eq as eq16, gte as gte3, isNull as isNull3, like as like3, lte as lte2, or as or5 } from "drizzle-orm";
111821
111734
  async function getDb3(cwd) {
111822
111735
  const { getDb: _getDb } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
111823
111736
  return _getDb(cwd);
@@ -111839,10 +111752,10 @@ function buildManifestSqlFilters(filter) {
111839
111752
  const conditions = [isNull3(pipelineManifest.archivedAt)];
111840
111753
  if (filter.status) {
111841
111754
  const storedStatus = filter.status === "completed" ? "active" : filter.status;
111842
- conditions.push(eq17(pipelineManifest.status, storedStatus));
111755
+ conditions.push(eq16(pipelineManifest.status, storedStatus));
111843
111756
  }
111844
111757
  if (filter.agent_type) {
111845
- conditions.push(eq17(pipelineManifest.type, filter.agent_type));
111758
+ conditions.push(eq16(pipelineManifest.type, filter.agent_type));
111846
111759
  }
111847
111760
  if (filter.dateAfter) {
111848
111761
  conditions.push(gte3(pipelineManifest.createdAt, `${filter.dateAfter} 00:00:00`));
@@ -111935,7 +111848,7 @@ async function pipelineManifestShow(researchId, projectRoot) {
111935
111848
  }
111936
111849
  try {
111937
111850
  const db = await getDb3(projectRoot);
111938
- const rows = await db.select().from(pipelineManifest).where(eq17(pipelineManifest.id, researchId)).limit(1);
111851
+ const rows = await db.select().from(pipelineManifest).where(eq16(pipelineManifest.id, researchId)).limit(1);
111939
111852
  if (rows.length === 0) {
111940
111853
  return {
111941
111854
  success: false,
@@ -112218,7 +112131,7 @@ async function pipelineManifestArchive(beforeDate, projectRoot) {
112218
112131
  }
112219
112132
  const archivedAt = now();
112220
112133
  for (const row of toArchive) {
112221
- await db.update(pipelineManifest).set({ archivedAt }).where(eq17(pipelineManifest.id, row.id));
112134
+ await db.update(pipelineManifest).set({ archivedAt }).where(eq16(pipelineManifest.id, row.id));
112222
112135
  }
112223
112136
  const remaining = rows.length - toArchive.length;
112224
112137
  return { success: true, data: { archived: toArchive.length, remaining } };
@@ -112567,25 +112480,25 @@ async function measureTokenExchange(input) {
112567
112480
  );
112568
112481
  }
112569
112482
  async function whereClauses(filters) {
112570
- const { eq: eq21, gte: gte4, lte: lte3 } = await import("drizzle-orm");
112483
+ const { eq: eq20, gte: gte4, lte: lte3 } = await import("drizzle-orm");
112571
112484
  const clauses = [];
112572
- if (filters.provider) clauses.push(eq21(tokenUsage.provider, filters.provider));
112573
- if (filters.transport) clauses.push(eq21(tokenUsage.transport, filters.transport));
112574
- if (filters.gateway) clauses.push(eq21(tokenUsage.gateway, filters.gateway));
112575
- if (filters.domain) clauses.push(eq21(tokenUsage.domain, filters.domain));
112576
- if (filters.operation) clauses.push(eq21(tokenUsage.operation, filters.operation));
112577
- if (filters.sessionId) clauses.push(eq21(tokenUsage.sessionId, filters.sessionId));
112578
- if (filters.taskId) clauses.push(eq21(tokenUsage.taskId, filters.taskId));
112579
- if (filters.method) clauses.push(eq21(tokenUsage.method, filters.method));
112580
- if (filters.confidence) clauses.push(eq21(tokenUsage.confidence, filters.confidence));
112581
- if (filters.requestId) clauses.push(eq21(tokenUsage.requestId, filters.requestId));
112485
+ if (filters.provider) clauses.push(eq20(tokenUsage.provider, filters.provider));
112486
+ if (filters.transport) clauses.push(eq20(tokenUsage.transport, filters.transport));
112487
+ if (filters.gateway) clauses.push(eq20(tokenUsage.gateway, filters.gateway));
112488
+ if (filters.domain) clauses.push(eq20(tokenUsage.domain, filters.domain));
112489
+ if (filters.operation) clauses.push(eq20(tokenUsage.operation, filters.operation));
112490
+ if (filters.sessionId) clauses.push(eq20(tokenUsage.sessionId, filters.sessionId));
112491
+ if (filters.taskId) clauses.push(eq20(tokenUsage.taskId, filters.taskId));
112492
+ if (filters.method) clauses.push(eq20(tokenUsage.method, filters.method));
112493
+ if (filters.confidence) clauses.push(eq20(tokenUsage.confidence, filters.confidence));
112494
+ if (filters.requestId) clauses.push(eq20(tokenUsage.requestId, filters.requestId));
112582
112495
  if (filters.since) clauses.push(gte4(tokenUsage.createdAt, filters.since));
112583
112496
  if (filters.until) clauses.push(lte3(tokenUsage.createdAt, filters.until));
112584
112497
  return clauses;
112585
112498
  }
112586
112499
  async function recordTokenExchange(input) {
112587
112500
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
112588
- const { eq: eq21 } = await import("drizzle-orm");
112501
+ const { eq: eq20 } = await import("drizzle-orm");
112589
112502
  const measurement = await measureTokenExchange(input);
112590
112503
  const db = await getDb4(input.cwd);
112591
112504
  const row = {
@@ -112614,14 +112527,14 @@ async function recordTokenExchange(input) {
112614
112527
  })
112615
112528
  };
112616
112529
  await db.insert(tokenUsage).values(row);
112617
- const inserted = await db.select().from(tokenUsage).where(eq21(tokenUsage.id, row.id)).limit(1);
112530
+ const inserted = await db.select().from(tokenUsage).where(eq20(tokenUsage.id, row.id)).limit(1);
112618
112531
  return inserted[0];
112619
112532
  }
112620
112533
  async function showTokenUsage(id2, cwd) {
112621
112534
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
112622
- const { eq: eq21 } = await import("drizzle-orm");
112535
+ const { eq: eq20 } = await import("drizzle-orm");
112623
112536
  const db = await getDb4(cwd);
112624
- const rows = await db.select().from(tokenUsage).where(eq21(tokenUsage.id, id2)).limit(1);
112537
+ const rows = await db.select().from(tokenUsage).where(eq20(tokenUsage.id, id2)).limit(1);
112625
112538
  return rows[0] ?? null;
112626
112539
  }
112627
112540
  async function listTokenUsage(filters = {}, cwd) {
@@ -112689,9 +112602,9 @@ async function summarizeTokenUsage(filters = {}, cwd) {
112689
112602
  }
112690
112603
  async function deleteTokenUsage(id2, cwd) {
112691
112604
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
112692
- const { eq: eq21 } = await import("drizzle-orm");
112605
+ const { eq: eq20 } = await import("drizzle-orm");
112693
112606
  const db = await getDb4(cwd);
112694
- await db.delete(tokenUsage).where(eq21(tokenUsage.id, id2));
112607
+ await db.delete(tokenUsage).where(eq20(tokenUsage.id, id2));
112695
112608
  return { deleted: true, id: id2 };
112696
112609
  }
112697
112610
  async function clearTokenUsage(filters = {}, cwd) {
@@ -117002,7 +116915,7 @@ __export(session_store_exports, {
117002
116915
  updateSession: () => updateSession,
117003
116916
  workHistory: () => workHistory
117004
116917
  });
117005
- import { and as and14, desc as desc7, eq as eq18, isNull as isNull4 } from "drizzle-orm";
116918
+ import { and as and14, desc as desc7, eq as eq17, isNull as isNull4 } from "drizzle-orm";
117006
116919
  async function createSession(session, cwd) {
117007
116920
  const db = await getDb(cwd);
117008
116921
  const tw = session.taskWork;
@@ -117024,7 +116937,7 @@ async function createSession(session, cwd) {
117024
116937
  }
117025
116938
  async function getSession(sessionId, cwd) {
117026
116939
  const db = await getDb(cwd);
117027
- const rows = await db.select().from(sessions).where(eq18(sessions.id, sessionId)).all();
116940
+ const rows = await db.select().from(sessions).where(eq17(sessions.id, sessionId)).all();
117028
116941
  if (rows.length === 0) return null;
117029
116942
  return rowToSession(rows[0]);
117030
116943
  }
@@ -117053,14 +116966,14 @@ async function updateSession(sessionId, updates, cwd) {
117053
116966
  updateRow.handoffConsumedBy = updates.handoffConsumedBy;
117054
116967
  if (updates.debriefJson !== void 0) updateRow.debriefJson = updates.debriefJson;
117055
116968
  if (updates.handoffJson !== void 0) updateRow.handoffJson = updates.handoffJson;
117056
- db.update(sessions).set(updateRow).where(eq18(sessions.id, sessionId)).run();
116969
+ db.update(sessions).set(updateRow).where(eq17(sessions.id, sessionId)).run();
117057
116970
  return getSession(sessionId, cwd);
117058
116971
  }
117059
116972
  async function listSessions2(filters, cwd) {
117060
116973
  const db = await getDb(cwd);
117061
116974
  const conditions = [];
117062
116975
  if (filters?.active) {
117063
- conditions.push(eq18(sessions.status, "active"));
116976
+ conditions.push(eq17(sessions.status, "active"));
117064
116977
  }
117065
116978
  const query = db.select().from(sessions).where(conditions.length > 0 ? and14(...conditions) : void 0).orderBy(desc7(sessions.startedAt));
117066
116979
  const rows = filters?.limit ? await query.limit(filters.limit).all() : await query.all();
@@ -117085,19 +116998,19 @@ async function startTask2(sessionId, taskId, cwd) {
117085
116998
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
117086
116999
  db.update(taskWorkHistory).set({ clearedAt: now2 }).where(
117087
117000
  and14(
117088
- eq18(taskWorkHistory.sessionId, sessionId),
117001
+ eq17(taskWorkHistory.sessionId, sessionId),
117089
117002
  isNull4(taskWorkHistory.clearedAt)
117090
117003
  )
117091
117004
  ).run();
117092
117005
  db.insert(taskWorkHistory).values({ sessionId, taskId, setAt: now2 }).run();
117093
- db.update(sessions).set({ currentTask: taskId, taskStartedAt: now2 }).where(eq18(sessions.id, sessionId)).run();
117006
+ db.update(sessions).set({ currentTask: taskId, taskStartedAt: now2 }).where(eq17(sessions.id, sessionId)).run();
117094
117007
  }
117095
117008
  async function getCurrentTask(sessionId, cwd) {
117096
117009
  const db = await getDb(cwd);
117097
117010
  const rows = await db.select({
117098
117011
  currentTask: sessions.currentTask,
117099
117012
  taskStartedAt: sessions.taskStartedAt
117100
- }).from(sessions).where(eq18(sessions.id, sessionId)).all();
117013
+ }).from(sessions).where(eq17(sessions.id, sessionId)).all();
117101
117014
  if (rows.length === 0) return { taskId: null, since: null };
117102
117015
  return { taskId: rows[0].currentTask, since: rows[0].taskStartedAt };
117103
117016
  }
@@ -117106,15 +117019,15 @@ async function stopTask2(sessionId, cwd) {
117106
117019
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
117107
117020
  db.update(taskWorkHistory).set({ clearedAt: now2 }).where(
117108
117021
  and14(
117109
- eq18(taskWorkHistory.sessionId, sessionId),
117022
+ eq17(taskWorkHistory.sessionId, sessionId),
117110
117023
  isNull4(taskWorkHistory.clearedAt)
117111
117024
  )
117112
117025
  ).run();
117113
- db.update(sessions).set({ currentTask: null, taskStartedAt: null }).where(eq18(sessions.id, sessionId)).run();
117026
+ db.update(sessions).set({ currentTask: null, taskStartedAt: null }).where(eq17(sessions.id, sessionId)).run();
117114
117027
  }
117115
117028
  async function workHistory(sessionId, limit = 50, cwd) {
117116
117029
  const db = await getDb(cwd);
117117
- const rows = await db.select().from(taskWorkHistory).where(eq18(taskWorkHistory.sessionId, sessionId)).orderBy(desc7(taskWorkHistory.setAt), desc7(taskWorkHistory.id)).limit(limit).all();
117030
+ const rows = await db.select().from(taskWorkHistory).where(eq17(taskWorkHistory.sessionId, sessionId)).orderBy(desc7(taskWorkHistory.setAt), desc7(taskWorkHistory.id)).limit(limit).all();
117118
117031
  return rows.map((r) => ({
117119
117032
  taskId: r.taskId,
117120
117033
  setAt: r.setAt,
@@ -117125,16 +117038,16 @@ async function gcSessions2(maxAgeDays = 30, cwd) {
117125
117038
  const db = await getDb(cwd);
117126
117039
  const threshold = /* @__PURE__ */ new Date();
117127
117040
  threshold.setDate(threshold.getDate() - maxAgeDays);
117128
- const before = await db.select({ id: sessions.id }).from(sessions).where(and14(eq18(sessions.status, "ended"))).all();
117041
+ const before = await db.select({ id: sessions.id }).from(sessions).where(and14(eq17(sessions.status, "ended"))).all();
117129
117042
  const toUpdate = before;
117130
117043
  if (toUpdate.length > 0) {
117131
- db.update(sessions).set({ status: "orphaned" }).where(eq18(sessions.status, "ended")).run();
117044
+ db.update(sessions).set({ status: "orphaned" }).where(eq17(sessions.status, "ended")).run();
117132
117045
  }
117133
117046
  return toUpdate.length;
117134
117047
  }
117135
117048
  async function getActiveSession(cwd) {
117136
117049
  const db = await getDb(cwd);
117137
- const rows = await db.select().from(sessions).where(eq18(sessions.status, "active")).orderBy(desc7(sessions.startedAt)).limit(1).all();
117050
+ const rows = await db.select().from(sessions).where(eq17(sessions.status, "active")).orderBy(desc7(sessions.startedAt)).limit(1).all();
117138
117051
  if (rows.length === 0) return null;
117139
117052
  return rowToSession(rows[0]);
117140
117053
  }
@@ -117148,12 +117061,12 @@ var init_session_store = __esm({
117148
117061
  });
117149
117062
 
117150
117063
  // packages/core/src/store/data-safety.ts
117151
- import { eq as eq19 } from "drizzle-orm";
117064
+ import { eq as eq18 } from "drizzle-orm";
117152
117065
  async function checkTaskExists(taskId, cwd, config2 = {}) {
117153
117066
  const cfg = { ...DEFAULT_CONFIG2, ...config2 };
117154
117067
  if (!cfg.detectCollisions) return false;
117155
117068
  const db = await getDb(cwd);
117156
- const existing = await db.select().from(tasks).where(eq19(tasks.id, taskId)).all();
117069
+ const existing = await db.select().from(tasks).where(eq18(tasks.id, taskId)).all();
117157
117070
  const exists2 = existing.length > 0;
117158
117071
  if (exists2 && cfg.strictMode) {
117159
117072
  throw new SafetyError(
@@ -117303,7 +117216,7 @@ __export(task_store_exports, {
117303
117216
  updateTask: () => updateTask2,
117304
117217
  updateTaskSafe: () => updateTaskSafe
117305
117218
  });
117306
- import { and as and15, asc as asc4, count as count4, eq as eq20, inArray as inArray8, isNull as isNull5, ne as ne5, sql as sql16 } from "drizzle-orm";
117219
+ import { and as and15, asc as asc4, count as count4, eq as eq19, inArray as inArray7, isNull as isNull5, ne as ne5, sql as sql16 } from "drizzle-orm";
117307
117220
  async function insertTaskRow(task, cwd) {
117308
117221
  const db = await getDb(cwd);
117309
117222
  const row = taskToRow(task);
@@ -117317,10 +117230,10 @@ async function insertTaskRow(task, cwd) {
117317
117230
  }
117318
117231
  async function getTask(taskId, cwd) {
117319
117232
  const db = await getDb(cwd);
117320
- const rows = await db.select().from(tasks).where(eq20(tasks.id, taskId)).all();
117233
+ const rows = await db.select().from(tasks).where(eq19(tasks.id, taskId)).all();
117321
117234
  if (rows.length === 0) return null;
117322
117235
  const task = rowToTask(rows[0]);
117323
- const deps = await db.select().from(taskDependencies).where(eq20(taskDependencies.taskId, taskId)).all();
117236
+ const deps = await db.select().from(taskDependencies).where(eq19(taskDependencies.taskId, taskId)).all();
117324
117237
  if (deps.length > 0) {
117325
117238
  task.depends = deps.map((d) => d.dependsOn);
117326
117239
  }
@@ -117363,9 +117276,9 @@ async function updateTask2(taskId, updates, cwd) {
117363
117276
  if (updates.verification !== void 0)
117364
117277
  updateRow.verificationJson = JSON.stringify(updates.verification);
117365
117278
  if (updates.assignee !== void 0) updateRow.assignee = updates.assignee;
117366
- db.update(tasks).set(updateRow).where(eq20(tasks.id, taskId)).run();
117279
+ db.update(tasks).set(updateRow).where(eq19(tasks.id, taskId)).run();
117367
117280
  if (updates.depends !== void 0) {
117368
- db.delete(taskDependencies).where(eq20(taskDependencies.taskId, taskId)).run();
117281
+ db.delete(taskDependencies).where(eq19(taskDependencies.taskId, taskId)).run();
117369
117282
  for (const depId of updates.depends) {
117370
117283
  db.insert(taskDependencies).values({ taskId, dependsOn: depId }).run();
117371
117284
  }
@@ -117374,9 +117287,9 @@ async function updateTask2(taskId, updates, cwd) {
117374
117287
  }
117375
117288
  async function deleteTask2(taskId, cwd) {
117376
117289
  const db = await getDb(cwd);
117377
- const existing = await db.select({ id: tasks.id }).from(tasks).where(eq20(tasks.id, taskId)).all();
117290
+ const existing = await db.select({ id: tasks.id }).from(tasks).where(eq19(tasks.id, taskId)).all();
117378
117291
  if (existing.length === 0) return false;
117379
- db.delete(tasks).where(eq20(tasks.id, taskId)).run();
117292
+ db.delete(tasks).where(eq19(tasks.id, taskId)).run();
117380
117293
  void cleanupBrainRefsOnTaskDelete(taskId, cwd);
117381
117294
  return true;
117382
117295
  }
@@ -117384,16 +117297,16 @@ async function listTasks2(filters, cwd) {
117384
117297
  const db = await getDb(cwd);
117385
117298
  const conditions = [];
117386
117299
  conditions.push(ne5(tasks.status, "archived"));
117387
- if (filters?.status) conditions.push(eq20(tasks.status, filters.status));
117300
+ if (filters?.status) conditions.push(eq19(tasks.status, filters.status));
117388
117301
  if (filters?.parentId !== void 0) {
117389
117302
  if (filters.parentId === null) {
117390
117303
  conditions.push(isNull5(tasks.parentId));
117391
117304
  } else {
117392
- conditions.push(eq20(tasks.parentId, filters.parentId));
117305
+ conditions.push(eq19(tasks.parentId, filters.parentId));
117393
117306
  }
117394
117307
  }
117395
- if (filters?.type) conditions.push(eq20(tasks.type, filters.type));
117396
- if (filters?.phase) conditions.push(eq20(tasks.phase, filters.phase));
117308
+ if (filters?.type) conditions.push(eq19(tasks.type, filters.type));
117309
+ if (filters?.phase) conditions.push(eq19(tasks.phase, filters.phase));
117397
117310
  const query = db.select().from(tasks).where(conditions.length > 0 ? and15(...conditions) : void 0).orderBy(asc4(tasks.position), asc4(tasks.createdAt));
117398
117311
  const rows = filters?.limit ? await query.limit(filters.limit).all() : await query.all();
117399
117312
  const tasks2 = rows.map(rowToTask);
@@ -117423,14 +117336,14 @@ async function archiveTask(taskId, reason, cwd) {
117423
117336
  archiveReason: reason ?? "completed",
117424
117337
  cycleTimeDays: cycleTime,
117425
117338
  updatedAt: now2
117426
- }).where(eq20(tasks.id, taskId)).run();
117339
+ }).where(eq19(tasks.id, taskId)).run();
117427
117340
  return true;
117428
117341
  }
117429
117342
  async function loadDependencies(tasks2, cwd) {
117430
117343
  if (tasks2.length === 0) return;
117431
117344
  const db = await getDb(cwd);
117432
117345
  const taskIds = tasks2.map((t) => t.id);
117433
- const deps = await db.select().from(taskDependencies).where(inArray8(taskDependencies.taskId, taskIds)).all();
117346
+ const deps = await db.select().from(taskDependencies).where(inArray7(taskDependencies.taskId, taskIds)).all();
117434
117347
  const depMap = /* @__PURE__ */ new Map();
117435
117348
  for (const dep of deps) {
117436
117349
  if (!depMap.has(dep.taskId)) depMap.set(dep.taskId, []);
@@ -117451,8 +117364,8 @@ async function removeDependency(taskId, dependsOn, cwd) {
117451
117364
  const db = await getDb(cwd);
117452
117365
  db.delete(taskDependencies).where(
117453
117366
  and15(
117454
- eq20(taskDependencies.taskId, taskId),
117455
- eq20(taskDependencies.dependsOn, dependsOn)
117367
+ eq19(taskDependencies.taskId, taskId),
117368
+ eq19(taskDependencies.dependsOn, dependsOn)
117456
117369
  )
117457
117370
  ).run();
117458
117371
  }
@@ -117462,7 +117375,7 @@ async function addRelation(taskId, relatedTo, relationType = "related", cwd, rea
117462
117375
  }
117463
117376
  async function getRelations(taskId, cwd) {
117464
117377
  const db = await getDb(cwd);
117465
- const rows = await db.select().from(taskRelations).where(eq20(taskRelations.taskId, taskId)).all();
117378
+ const rows = await db.select().from(taskRelations).where(eq19(taskRelations.taskId, taskId)).all();
117466
117379
  return rows.map((r) => ({
117467
117380
  relatedTo: r.relatedTo,
117468
117381
  type: r.relationType,
@@ -117486,7 +117399,7 @@ async function getBlockerChain(taskId, cwd) {
117486
117399
  }
117487
117400
  async function getChildren2(parentId, cwd) {
117488
117401
  const db = await getDb(cwd);
117489
- const rows = await db.select().from(tasks).where(eq20(tasks.parentId, parentId)).orderBy(asc4(tasks.position), asc4(tasks.createdAt)).all();
117402
+ const rows = await db.select().from(tasks).where(eq19(tasks.parentId, parentId)).orderBy(asc4(tasks.position), asc4(tasks.createdAt)).all();
117490
117403
  return rows.map(rowToTask);
117491
117404
  }
117492
117405
  async function getSubtree(rootId, cwd) {
@@ -117611,6 +117524,7 @@ function canCancel(task) {
117611
117524
  var init_cancel_ops = __esm({
117612
117525
  "packages/core/src/tasks/cancel-ops.ts"() {
117613
117526
  "use strict";
117527
+ init_pipeline_stage();
117614
117528
  }
117615
117529
  });
117616
117530
 
@@ -117982,6 +117896,9 @@ async function coreTaskRestore(projectRoot, taskId, params2) {
117982
117896
  t.cancelledAt = void 0;
117983
117897
  t.cancellationReason = void 0;
117984
117898
  t.updatedAt = now2;
117899
+ if (t.pipelineStage === "cancelled") {
117900
+ t.pipelineStage = t.type === "epic" ? "research" : "implementation";
117901
+ }
117985
117902
  if (!t.notes) t.notes = [];
117986
117903
  t.notes.push(`[${now2}] Restored from cancelled${params2?.notes ? ": " + params2.notes : ""}`);
117987
117904
  restored.push(t.id);
@@ -118006,6 +117923,9 @@ async function coreTaskCancel(projectRoot, taskId, params2) {
118006
117923
  task.cancelledAt = cancelledAt;
118007
117924
  task.cancellationReason = params2?.reason ?? void 0;
118008
117925
  task.updatedAt = cancelledAt;
117926
+ if (!isTerminalPipelineStage(task.pipelineStage)) {
117927
+ task.pipelineStage = "cancelled";
117928
+ }
118009
117929
  await accessor.upsertSingleTask(task);
118010
117930
  return { task: taskId, cancelled: true, reason: params2?.reason, cancelledAt };
118011
117931
  }
@@ -118708,6 +118628,7 @@ var init_task_ops = __esm({
118708
118628
  init_cancel_ops();
118709
118629
  init_dependency_check();
118710
118630
  init_deps_ready();
118631
+ init_pipeline_stage();
118711
118632
  PRIORITY_SCORE2 = {
118712
118633
  critical: 100,
118713
118634
  high: 75,
@@ -118886,6 +118807,7 @@ async function runMigrationDataImport(db, cleoDir, result, logger) {
118886
118807
  for (let i = 0; i < tasks2.length; i++) {
118887
118808
  const task = tasks2[i];
118888
118809
  try {
118810
+ const importedPipelineStage = task.pipelineStage ?? (task.status === "done" ? "contribution" : task.status === "cancelled" ? "cancelled" : null);
118889
118811
  await db.insert(tasks).values({
118890
118812
  id: task.id,
118891
118813
  title: task.title,
@@ -118913,7 +118835,8 @@ async function runMigrationDataImport(db, cleoDir, result, logger) {
118913
118835
  verificationJson: task.verification ? JSON.stringify(task.verification) : void 0,
118914
118836
  createdBy: task.provenance?.createdBy,
118915
118837
  modifiedBy: task.provenance?.modifiedBy,
118916
- sessionId: task.provenance?.sessionId
118838
+ sessionId: task.provenance?.sessionId,
118839
+ pipelineStage: importedPipelineStage
118917
118840
  }).onConflictDoNothing().run();
118918
118841
  if (task.depends) {
118919
118842
  for (const depId of task.depends) {
@@ -119095,10 +119018,10 @@ async function migrateJsonToSqlite2(cwd, options) {
119095
119018
  const jsonCounts = countJsonRecords(cleoDir);
119096
119019
  result.jsonCounts = jsonCounts;
119097
119020
  if (dbExists(cwd)) {
119098
- const { ne: ne6, eq: eq21, count: count5 } = await import("drizzle-orm");
119021
+ const { ne: ne6, eq: eq20, count: count5 } = await import("drizzle-orm");
119099
119022
  const db2 = await getDb(cwd);
119100
119023
  const tasksResult = await db2.select({ count: count5() }).from(tasks).where(ne6(tasks.status, "archived")).get();
119101
- const archivedResult = await db2.select({ count: count5() }).from(tasks).where(eq21(tasks.status, "archived")).get();
119024
+ const archivedResult = await db2.select({ count: count5() }).from(tasks).where(eq20(tasks.status, "archived")).get();
119102
119025
  const sessionsResult = await db2.select({ count: count5() }).from(sessions).get();
119103
119026
  const existingCounts = {
119104
119027
  tasks: tasksResult?.count ?? 0,
@@ -119160,6 +119083,7 @@ async function migrateJsonToSqlite2(cwd, options) {
119160
119083
  const tasks2 = topoSortTasks(todoData.tasks ?? []);
119161
119084
  for (const task of tasks2) {
119162
119085
  try {
119086
+ const importedPipelineStage = task.pipelineStage ?? (task.status === "done" ? "contribution" : task.status === "cancelled" ? "cancelled" : null);
119163
119087
  db.insert(tasks).values({
119164
119088
  id: task.id,
119165
119089
  title: task.title,
@@ -119187,7 +119111,8 @@ async function migrateJsonToSqlite2(cwd, options) {
119187
119111
  verificationJson: task.verification ? JSON.stringify(task.verification) : void 0,
119188
119112
  createdBy: task.provenance?.createdBy,
119189
119113
  modifiedBy: task.provenance?.modifiedBy,
119190
- sessionId: task.provenance?.sessionId
119114
+ sessionId: task.provenance?.sessionId,
119115
+ pipelineStage: importedPipelineStage
119191
119116
  }).onConflictDoNothing().run();
119192
119117
  if (task.depends) {
119193
119118
  for (const depId of task.depends) {
@@ -119282,10 +119207,10 @@ async function migrateJsonToSqlite2(cwd, options) {
119282
119207
  async function exportToJson(cwd) {
119283
119208
  const { listTasks: listTasks3 } = await Promise.resolve().then(() => (init_task_store(), task_store_exports));
119284
119209
  const { listSessions: listSessions3 } = await Promise.resolve().then(() => (init_session_store(), session_store_exports));
119285
- const { eq: eq21 } = await import("drizzle-orm");
119210
+ const { eq: eq20 } = await import("drizzle-orm");
119286
119211
  const tasks2 = await listTasks3(void 0, cwd);
119287
119212
  const db = await getDb(cwd);
119288
- const archivedRows = await db.select().from(tasks).where(eq21(tasks.status, "archived")).all();
119213
+ const archivedRows = await db.select().from(tasks).where(eq20(tasks.status, "archived")).all();
119289
119214
  const archived = archivedRows.map((row) => ({
119290
119215
  id: row.id,
119291
119216
  title: row.title,
@@ -122196,7 +122121,7 @@ async function validateSqliteRows(type, projectRoot) {
122196
122121
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
122197
122122
  const schemaTable = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
122198
122123
  const zodSchemas = await Promise.resolve().then(() => (init_validation_schemas(), validation_schemas_exports));
122199
- const { ne: ne6, eq: eq21 } = await import("drizzle-orm");
122124
+ const { ne: ne6, eq: eq20 } = await import("drizzle-orm");
122200
122125
  const db = await getDb4(projectRoot);
122201
122126
  const errors = [];
122202
122127
  switch (type) {
@@ -122208,7 +122133,7 @@ async function validateSqliteRows(type, projectRoot) {
122208
122133
  break;
122209
122134
  }
122210
122135
  case "archive": {
122211
- const rows = await db.select().from(schemaTable.tasks).where(eq21(schemaTable.tasks.status, "archived"));
122136
+ const rows = await db.select().from(schemaTable.tasks).where(eq20(schemaTable.tasks.status, "archived"));
122212
122137
  for (const row of rows) {
122213
122138
  errors.push(...collectZodErrors(zodSchemas.selectTaskSchema.safeParse(row), row.id));
122214
122139
  }
@@ -132144,7 +132069,6 @@ __export(internal_exports, {
132144
132069
  MINIMUM_NODE_MAJOR: () => MINIMUM_NODE_MAJOR,
132145
132070
  OrchestrationLevel: () => OrchestrationLevel,
132146
132071
  PIPELINE_STAGES: () => PIPELINE_STAGES,
132147
- PIPELINE_STAGE_BACKFILL_KEY: () => BACKFILL_KEY,
132148
132072
  PIPELINE_STATUS_ICONS: () => PIPELINE_STATUS_ICONS,
132149
132073
  PLATFORM: () => PLATFORM,
132150
132074
  PROTOCOL_RULES: () => PROTOCOL_RULES,
@@ -132228,7 +132152,6 @@ __export(internal_exports, {
132228
132152
  autoRecordDispatchTokenUsage: () => autoRecordDispatchTokenUsage,
132229
132153
  autoRunGatesAndRecord: () => autoRunGatesAndRecord,
132230
132154
  backfillBrainGraph: () => backfillBrainGraph,
132231
- backfillPipelineStageFromLifecycle: () => backfillPipelineStageFromLifecycle,
132232
132155
  backfillTasks: () => backfillTasks,
132233
132156
  backupGlobalSalt: () => backupGlobalSalt,
132234
132157
  batchParse: () => batchParse,
@@ -132655,7 +132578,6 @@ __export(internal_exports, {
132655
132578
  isLafsSuccess: () => isLafsSuccess,
132656
132579
  isNoChangeCode: () => isNoChangeCode,
132657
132580
  isOverloaded: () => isOverloaded,
132658
- isPipelineStageBackfillDone: () => isPipelineStageBackfillDone,
132659
132581
  isPipelineTransitionForward: () => isPipelineTransitionForward,
132660
132582
  isProjectInitialized: () => isProjectInitialized,
132661
132583
  isProviderHookEvent: () => isProviderHookEvent,
@@ -133062,7 +132984,6 @@ var init_internal = __esm({
133062
132984
  init_create();
133063
132985
  init_diagnostics();
133064
132986
  init_retry2();
133065
- init_backfill_pipeline_stage();
133066
132987
  init_chain_store();
133067
132988
  init_lifecycle2();
133068
132989
  init_ivtr_loop();
@@ -141470,10 +141391,10 @@ async function releaseShip(params2, projectRoot) {
141470
141391
  );
141471
141392
  const { getDb: getDb4 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
141472
141393
  const { releaseManifests: releaseManifests2 } = await Promise.resolve().then(() => (init_internal(), internal_exports));
141473
- const { eq: eq21 } = await import("drizzle-orm");
141394
+ const { eq: eq20 } = await import("drizzle-orm");
141474
141395
  const normalizedVer = version2.startsWith("v") ? version2 : `v${version2}`;
141475
141396
  const db = await getDb4(cwd);
141476
- await db.update(releaseManifests2).set({ epicId }).where(eq21(releaseManifests2.version, normalizedVer)).run();
141397
+ await db.update(releaseManifests2).set({ epicId }).where(eq20(releaseManifests2.version, normalizedVer)).run();
141477
141398
  await generateReleaseChangelog(version2, () => loadTasks2(projectRoot), cwd);
141478
141399
  }
141479
141400
  logStep(0, 8, "Auto-prepare release record", true);
@@ -145742,12 +145663,12 @@ function scanForbiddenPhrases(filePath, lines) {
145742
145663
  }
145743
145664
  function countCanonicalDomains(typesFilePath) {
145744
145665
  const lines = readLines(typesFilePath);
145745
- let inArray9 = false;
145666
+ let inArray8 = false;
145746
145667
  let count5 = 0;
145747
145668
  for (const line2 of lines) {
145748
- if (!inArray9) {
145669
+ if (!inArray8) {
145749
145670
  if (line2.includes("CANONICAL_DOMAINS") && line2.includes("[")) {
145750
- inArray9 = true;
145671
+ inArray8 = true;
145751
145672
  }
145752
145673
  continue;
145753
145674
  }
@@ -155485,7 +155406,9 @@ var adminCommand = defineCommand({
155485
155406
  "install-global": installGlobalCommand,
155486
155407
  "context-inject": contextInjectCommand
155487
155408
  },
155488
- async run({ cmd }) {
155409
+ async run({ cmd, rawArgs }) {
155410
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
155411
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
155489
155412
  await showUsage(cmd);
155490
155413
  }
155491
155414
  });
@@ -155623,7 +155546,9 @@ var adrCommand = defineCommand({
155623
155546
  sync: syncCommand,
155624
155547
  find: findCommand
155625
155548
  },
155626
- async run({ cmd }) {
155549
+ async run({ cmd, rawArgs }) {
155550
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
155551
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
155627
155552
  await showUsage(cmd);
155628
155553
  }
155629
155554
  });
@@ -157811,7 +157736,9 @@ var agentCommand = defineCommand({
157811
157736
  pack: packCommand,
157812
157737
  create: createCommand
157813
157738
  },
157814
- async run({ cmd }) {
157739
+ async run({ cmd, rawArgs }) {
157740
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
157741
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
157815
157742
  await showUsage(cmd);
157816
157743
  }
157817
157744
  });
@@ -159535,7 +159462,9 @@ var brainCommand = defineCommand({
159535
159462
  quality: qualityCommand,
159536
159463
  export: exportCommand2
159537
159464
  },
159538
- async run({ cmd }) {
159465
+ async run({ cmd, rawArgs }) {
159466
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
159467
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
159539
159468
  await showUsage(cmd);
159540
159469
  }
159541
159470
  });
@@ -159896,7 +159825,9 @@ var cantCommand = defineCommand({
159896
159825
  execute: cantExecuteCommand,
159897
159826
  migrate: cantMigrateCommand
159898
159827
  },
159899
- async run({ cmd }) {
159828
+ async run({ cmd, rawArgs }) {
159829
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
159830
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
159900
159831
  await showUsage(cmd);
159901
159832
  }
159902
159833
  });
@@ -160006,7 +159937,9 @@ var chainCommand = defineCommand({
160006
159937
  instantiate: instantiateCommand,
160007
159938
  advance: advanceCommand
160008
159939
  },
160009
- async run({ cmd }) {
159940
+ async run({ cmd, rawArgs }) {
159941
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
159942
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
160010
159943
  await showUsage(cmd);
160011
159944
  }
160012
159945
  });
@@ -160276,7 +160209,9 @@ var checkCommand = defineCommand({
160276
160209
  canon: checkCanonCommand,
160277
160210
  protocol: checkProtocolCommand
160278
160211
  },
160279
- async run({ cmd }) {
160212
+ async run({ cmd, rawArgs }) {
160213
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
160214
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
160280
160215
  await showUsage(cmd);
160281
160216
  }
160282
160217
  });
@@ -160622,7 +160557,9 @@ var complexityEstimateCommand = defineCommand({
160622
160557
  var complexityCommand = defineCommand({
160623
160558
  meta: { name: "complexity", description: "Task complexity analysis" },
160624
160559
  subCommands: { estimate: complexityEstimateCommand },
160625
- async run({ cmd }) {
160560
+ async run({ cmd, rawArgs }) {
160561
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
160562
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
160626
160563
  await showUsage(cmd);
160627
160564
  }
160628
160565
  });
@@ -160865,7 +160802,9 @@ var complianceCommand = defineCommand({
160865
160802
  value: valueCommand,
160866
160803
  record: recordCommand
160867
160804
  },
160868
- async run({ cmd }) {
160805
+ async run({ cmd, rawArgs }) {
160806
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
160807
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
160869
160808
  await showUsage(cmd);
160870
160809
  }
160871
160810
  });
@@ -161010,7 +160949,9 @@ var conduitCommand = defineCommand({
161010
160949
  stop: stopCommand2,
161011
160950
  send: sendCommand2
161012
160951
  },
161013
- async run({ cmd }) {
160952
+ async run({ cmd, rawArgs }) {
160953
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
160954
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
161014
160955
  await showUsage(cmd);
161015
160956
  }
161016
160957
  });
@@ -161128,7 +161069,9 @@ var configCommand = defineCommand({
161128
161069
  presets: presetsCommand,
161129
161070
  list: listCommand6
161130
161071
  },
161131
- async run({ cmd }) {
161072
+ async run({ cmd, rawArgs }) {
161073
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
161074
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
161132
161075
  await showUsage(cmd);
161133
161076
  }
161134
161077
  });
@@ -161216,7 +161159,9 @@ var consensusCommand = defineCommand({
161216
161159
  validate: validateCommand2,
161217
161160
  check: checkCommand2
161218
161161
  },
161219
- async run({ cmd }) {
161162
+ async run({ cmd, rawArgs }) {
161163
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
161164
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
161220
161165
  await showUsage(cmd);
161221
161166
  }
161222
161167
  });
@@ -161413,7 +161358,9 @@ var contributionCommand = defineCommand({
161413
161358
  validate: validateCommand3,
161414
161359
  check: checkCommand4
161415
161360
  },
161416
- async run({ cmd }) {
161361
+ async run({ cmd, rawArgs }) {
161362
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
161363
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
161417
161364
  await showUsage(cmd);
161418
161365
  }
161419
161366
  });
@@ -162161,7 +162108,9 @@ var decompositionCommand = defineCommand({
162161
162108
  validate: validateCommand4,
162162
162109
  check: checkCommand5
162163
162110
  },
162164
- async run({ cmd }) {
162111
+ async run({ cmd, rawArgs }) {
162112
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
162113
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
162165
162114
  await showUsage(cmd);
162166
162115
  }
162167
162116
  });
@@ -162341,7 +162290,9 @@ var depsCommand = defineCommand({
162341
162290
  impact: impactCommand,
162342
162291
  cycles: cyclesCommand
162343
162292
  },
162344
- async run({ cmd }) {
162293
+ async run({ cmd, rawArgs }) {
162294
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
162295
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
162345
162296
  await showUsage(cmd);
162346
162297
  }
162347
162298
  });
@@ -162850,7 +162801,9 @@ var diagnosticsCommand = defineCommand({
162850
162801
  analyze: analyzeCommand2,
162851
162802
  export: exportCommand3
162852
162803
  },
162853
- async run({ cmd }) {
162804
+ async run({ cmd, rawArgs }) {
162805
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
162806
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
162854
162807
  await showUsage(cmd);
162855
162808
  }
162856
162809
  });
@@ -163200,7 +163153,9 @@ var docsCommand = defineCommand({
163200
163153
  sync: syncCommand3,
163201
163154
  "gap-check": gapCheckCommand
163202
163155
  },
163203
- async run({ cmd }) {
163156
+ async run({ cmd, rawArgs }) {
163157
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
163158
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
163204
163159
  await showUsage(cmd);
163205
163160
  }
163206
163161
  });
@@ -163848,7 +163803,9 @@ var gcCommand = defineCommand({
163848
163803
  run: runCommand3,
163849
163804
  status: statusCommand6
163850
163805
  },
163851
- async run({ cmd }) {
163806
+ async run({ cmd, rawArgs }) {
163807
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
163808
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
163852
163809
  await showUsage(cmd);
163853
163810
  }
163854
163811
  });
@@ -164156,7 +164113,9 @@ var historyCommand = defineCommand({
164156
164113
  log: logCommand,
164157
164114
  work: workCommand2
164158
164115
  },
164159
- async run({ cmd }) {
164116
+ async run({ cmd, rawArgs }) {
164117
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
164118
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
164160
164119
  await showUsage(cmd);
164161
164120
  }
164162
164121
  });
@@ -164558,7 +164517,9 @@ var intelligenceCommand = defineCommand({
164558
164517
  confidence: confidenceCommand,
164559
164518
  match: matchCommand
164560
164519
  },
164561
- async run({ cmd }) {
164520
+ async run({ cmd, rawArgs }) {
164521
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
164522
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
164562
164523
  await showUsage(cmd);
164563
164524
  }
164564
164525
  });
@@ -164679,7 +164640,9 @@ var issueCommand = defineCommand({
164679
164640
  help: helpCommand,
164680
164641
  diagnostics: diagnosticsCommand2
164681
164642
  },
164682
- async run({ cmd }) {
164643
+ async run({ cmd, rawArgs }) {
164644
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
164645
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
164683
164646
  await showUsage(cmd);
164684
164647
  }
164685
164648
  });
@@ -164956,7 +164919,9 @@ var lifecycleCommand = defineCommand({
164956
164919
  reset: resetCommand,
164957
164920
  "gate-record": gateRecordCommand
164958
164921
  },
164959
- async run({ cmd }) {
164922
+ async run({ cmd, rawArgs }) {
164923
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
164924
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
164960
164925
  await showUsage(cmd);
164961
164926
  }
164962
164927
  });
@@ -167053,7 +167018,9 @@ var memoryBrainCommand = defineCommand({
167053
167018
  "pending-verify": pendingVerifyCommand,
167054
167019
  tier: tierCommand
167055
167020
  },
167056
- async run({ cmd }) {
167021
+ async run({ cmd, rawArgs }) {
167022
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
167023
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
167057
167024
  await showUsage(cmd);
167058
167025
  }
167059
167026
  });
@@ -167151,7 +167118,9 @@ var migrateClaudeMemCommand = defineCommand({
167151
167118
  "claude-mem": claudeMemCommand,
167152
167119
  storage: storageCommand
167153
167120
  },
167154
- async run({ cmd }) {
167121
+ async run({ cmd, rawArgs }) {
167122
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
167123
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
167155
167124
  await showUsage(cmd);
167156
167125
  }
167157
167126
  });
@@ -168673,7 +168642,7 @@ var analyzeCommand3 = defineCommand({
168673
168642
  );
168674
168643
  }
168675
168644
  try {
168676
- const [{ getNexusDb: getNexusDb2, nexusSchema }, { runPipeline: runPipeline2 }, { getProjectRoot: getProjectRoot4 }, { eq: eq21 }] = await Promise.all([
168645
+ const [{ getNexusDb: getNexusDb2, nexusSchema }, { runPipeline: runPipeline2 }, { getProjectRoot: getProjectRoot4 }, { eq: eq20 }] = await Promise.all([
168677
168646
  import("@cleocode/core/store/nexus-sqlite"),
168678
168647
  import("@cleocode/nexus/pipeline"),
168679
168648
  Promise.resolve().then(() => (init_internal(), internal_exports)),
@@ -168690,11 +168659,11 @@ var analyzeCommand3 = defineCommand({
168690
168659
  process.stderr.write("[nexus] Clearing existing index for project...\n");
168691
168660
  }
168692
168661
  try {
168693
- db.delete(nexusSchema.nexusNodes).where(eq21(nexusSchema.nexusNodes.projectId, projectId)).run();
168662
+ db.delete(nexusSchema.nexusNodes).where(eq20(nexusSchema.nexusNodes.projectId, projectId)).run();
168694
168663
  } catch {
168695
168664
  }
168696
168665
  try {
168697
- db.delete(nexusSchema.nexusRelations).where(eq21(nexusSchema.nexusRelations.projectId, projectId)).run();
168666
+ db.delete(nexusSchema.nexusRelations).where(eq20(nexusSchema.nexusRelations.projectId, projectId)).run();
168698
168667
  } catch {
168699
168668
  }
168700
168669
  }
@@ -169351,7 +169320,7 @@ var projectsCleanCommand = defineCommand({
169351
169320
  const { getNexusDb: getNexusDb2 } = await import("@cleocode/core/store/nexus-sqlite");
169352
169321
  const { projectRegistry: regTable, nexusAuditLog: auditTable } = await import("@cleocode/core/store/nexus-schema");
169353
169322
  const { randomUUID: randomUUID16 } = await import("node:crypto");
169354
- const { inArray: inArray9 } = await import("drizzle-orm");
169323
+ const { inArray: inArray8 } = await import("drizzle-orm");
169355
169324
  const db = await getNexusDb2();
169356
169325
  const allRows = await db.select({
169357
169326
  projectId: regTable.projectId,
@@ -169461,7 +169430,7 @@ var projectsCleanCommand = defineCommand({
169461
169430
  }
169462
169431
  }
169463
169432
  const idsToDelete = matches.map((r) => r.projectId);
169464
- await db.delete(regTable).where(inArray9(regTable.projectId, idsToDelete));
169433
+ await db.delete(regTable).where(inArray8(regTable.projectId, idsToDelete));
169465
169434
  const remaining = totalCount - matchCount;
169466
169435
  try {
169467
169436
  await db.insert(auditTable).values({
@@ -169956,7 +169925,9 @@ var nexusCommand = defineCommand({
169956
169925
  export: exportCommand5,
169957
169926
  diff: diffCommand
169958
169927
  },
169959
- async run({ cmd }) {
169928
+ async run({ cmd, rawArgs }) {
169929
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
169930
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
169960
169931
  await showUsage(cmd);
169961
169932
  }
169962
169933
  });
@@ -170596,7 +170567,9 @@ var orchestrateCommand = defineCommand({
170596
170567
  "conduit-stop": conduitStopCommand,
170597
170568
  "conduit-send": conduitSendCommand
170598
170569
  },
170599
- async run({ cmd }) {
170570
+ async run({ cmd, rawArgs }) {
170571
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
170572
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
170600
170573
  await showUsage(cmd);
170601
170574
  }
170602
170575
  });
@@ -170746,7 +170719,9 @@ var otelCommand = defineCommand({
170746
170719
  real: realCommand,
170747
170720
  clear: clearCommand
170748
170721
  },
170749
- async run({ cmd }) {
170722
+ async run({ cmd, rawArgs }) {
170723
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
170724
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
170750
170725
  await showUsage(cmd);
170751
170726
  }
170752
170727
  });
@@ -170933,7 +170908,9 @@ var phaseCommand = defineCommand({
170933
170908
  rename: renameCommand,
170934
170909
  delete: deleteCommand2
170935
170910
  },
170936
- async run({ cmd }) {
170911
+ async run({ cmd, rawArgs }) {
170912
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
170913
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
170937
170914
  await showUsage(cmd);
170938
170915
  }
170939
170916
  });
@@ -171250,7 +171227,9 @@ var reasonCommand = defineCommand({
171250
171227
  impact: impactCommand3,
171251
171228
  timeline: timelineCommand2
171252
171229
  },
171253
- async run({ cmd }) {
171230
+ async run({ cmd, rawArgs }) {
171231
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
171232
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
171254
171233
  await showUsage(cmd);
171255
171234
  }
171256
171235
  });
@@ -171388,7 +171367,9 @@ var relatesCommand = defineCommand({
171388
171367
  discover: discoverCommand2,
171389
171368
  list: listCommand13
171390
171369
  },
171391
- async run({ cmd }) {
171370
+ async run({ cmd, rawArgs }) {
171371
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
171372
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
171392
171373
  await showUsage(cmd);
171393
171374
  }
171394
171375
  });
@@ -171605,7 +171586,9 @@ var releaseCommand = defineCommand({
171605
171586
  "rollback-full": rollbackFullCommand,
171606
171587
  channel: channelCommand
171607
171588
  },
171608
- async run({ cmd }) {
171589
+ async run({ cmd, rawArgs }) {
171590
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
171591
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
171609
171592
  await showUsage(cmd);
171610
171593
  }
171611
171594
  });
@@ -171755,7 +171738,9 @@ var remoteCommand = defineCommand({
171755
171738
  list: listRemoteCommand,
171756
171739
  status: statusRemoteCommand
171757
171740
  },
171758
- async run({ cmd }) {
171741
+ async run({ cmd, rawArgs }) {
171742
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
171743
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
171759
171744
  await showUsage(cmd);
171760
171745
  }
171761
171746
  });
@@ -172009,7 +171994,9 @@ var reqCommand = defineCommand({
172009
171994
  list: listCommand15,
172010
171995
  migrate: migrateCommand
172011
171996
  },
172012
- async run({ cmd }) {
171997
+ async run({ cmd, rawArgs }) {
171998
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
171999
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
172013
172000
  await showUsage(cmd);
172014
172001
  }
172015
172002
  });
@@ -172336,7 +172323,9 @@ var researchCommand = defineCommand({
172336
172323
  archive: archiveCommand2,
172337
172324
  manifest: manifestCommand
172338
172325
  },
172339
- async run({ cmd }) {
172326
+ async run({ cmd, rawArgs }) {
172327
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
172328
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
172340
172329
  await showUsage(cmd);
172341
172330
  }
172342
172331
  });
@@ -172811,7 +172800,9 @@ var restoreCommand = defineCommand({
172811
172800
  backup: backupSubCommand,
172812
172801
  task: taskSubCommand
172813
172802
  },
172814
- async run({ cmd }) {
172803
+ async run({ cmd, rawArgs }) {
172804
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
172805
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
172815
172806
  await showUsage(cmd);
172816
172807
  }
172817
172808
  });
@@ -173492,7 +173483,9 @@ var sequenceCommand = defineCommand({
173492
173483
  check: checkCommand6,
173493
173484
  repair: repairCommand
173494
173485
  },
173495
- async run({ cmd }) {
173486
+ async run({ cmd, rawArgs }) {
173487
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
173488
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
173496
173489
  await showUsage(cmd);
173497
173490
  }
173498
173491
  });
@@ -173964,7 +173957,9 @@ var sessionCommand = defineCommand({
173964
173957
  "record-decision": recordDecisionCommand,
173965
173958
  "decision-log": decisionLogCommand
173966
173959
  },
173967
- async run({ cmd }) {
173960
+ async run({ cmd, rawArgs }) {
173961
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
173962
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
173968
173963
  await showUsage(cmd);
173969
173964
  }
173970
173965
  });
@@ -174416,7 +174411,9 @@ var snapshotCommand = defineCommand({
174416
174411
  export: exportCommand6,
174417
174412
  import: importCommand4
174418
174413
  },
174419
- async run({ cmd }) {
174414
+ async run({ cmd, rawArgs }) {
174415
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
174416
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
174420
174417
  await showUsage(cmd);
174421
174418
  }
174422
174419
  });
@@ -174793,7 +174790,9 @@ var stickyCommand = defineCommand({
174793
174790
  archive: archiveCommand3,
174794
174791
  purge: purgeCommand2
174795
174792
  },
174796
- async run({ cmd }) {
174793
+ async run({ cmd, rawArgs }) {
174794
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
174795
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
174797
174796
  await showUsage(cmd);
174798
174797
  }
174799
174798
  });
@@ -174918,7 +174917,9 @@ var syncCommand5 = defineCommand({
174918
174917
  links: linksCommand2,
174919
174918
  reconcile: reconcileCommand2
174920
174919
  },
174921
- async run({ cmd }) {
174920
+ async run({ cmd, rawArgs }) {
174921
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
174922
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
174922
174923
  await showUsage(cmd);
174923
174924
  }
174924
174925
  });
@@ -175031,7 +175032,9 @@ var testingCommand = defineCommand({
175031
175032
  coverage: coverageCommand,
175032
175033
  run: runCommand4
175033
175034
  },
175034
- async run({ cmd }) {
175035
+ async run({ cmd, rawArgs }) {
175036
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
175037
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
175035
175038
  await showUsage(cmd);
175036
175039
  }
175037
175040
  });
@@ -175217,7 +175220,9 @@ var tokenCommand = defineCommand({
175217
175220
  clear: clearCommand2,
175218
175221
  estimate: estimateCommand
175219
175222
  },
175220
- async run({ cmd }) {
175223
+ async run({ cmd, rawArgs }) {
175224
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
175225
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
175221
175226
  await showUsage(cmd);
175222
175227
  }
175223
175228
  });
@@ -175906,7 +175911,9 @@ var transcriptCommand = defineCommand({
175906
175911
  migrate: migrateCommand2,
175907
175912
  prune: pruneCommand
175908
175913
  },
175909
- async run({ cmd }) {
175914
+ async run({ cmd, rawArgs }) {
175915
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
175916
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
175910
175917
  await showUsage(cmd);
175911
175918
  }
175912
175919
  });
@@ -176544,7 +176551,9 @@ var webCommand = defineCommand({
176544
176551
  status: statusCommand12,
176545
176552
  open: openCommand
176546
176553
  },
176547
- async run({ cmd }) {
176554
+ async run({ cmd, rawArgs }) {
176555
+ const firstArg = rawArgs?.find((a) => !a.startsWith("-"));
176556
+ if (firstArg && cmd.subCommands && firstArg in cmd.subCommands) return;
176548
176557
  await showUsage(cmd);
176549
176558
  }
176550
176559
  });