@cleocode/cleo 2026.4.144 → 2026.4.145

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
@@ -1291,12 +1291,61 @@ var init_task_evidence = __esm({
1291
1291
  }
1292
1292
  });
1293
1293
 
1294
+ // packages/contracts/src/tasks/archive.ts
1295
+ import { z as z6 } from "zod";
1296
+ function isArchiveTombstoneAllowed() {
1297
+ const env = globalThis?.process?.env;
1298
+ return env?.[ARCHIVE_REASON_TOMBSTONE_ENV] === "1";
1299
+ }
1300
+ function assertArchiveReason(reason, taskId) {
1301
+ const parsed = ArchiveReason.parse(reason);
1302
+ if (parsed === ARCHIVE_REASON_TOMBSTONE && !isArchiveTombstoneAllowed()) {
1303
+ throw new ArchiveReasonTombstoneError(taskId);
1304
+ }
1305
+ return parsed;
1306
+ }
1307
+ var ArchiveReason, ArchiveReasonSchema, ARCHIVE_REASON_VALUES, ARCHIVE_REASON_TOMBSTONE, ArchiveReasonTombstoneError, ARCHIVE_REASON_TOMBSTONE_ENV;
1308
+ var init_archive = __esm({
1309
+ "packages/contracts/src/tasks/archive.ts"() {
1310
+ "use strict";
1311
+ ArchiveReason = z6.enum([
1312
+ "verified",
1313
+ "reconciled",
1314
+ "superseded",
1315
+ "shadowed",
1316
+ "cancelled",
1317
+ "completed-unverified"
1318
+ ]);
1319
+ ArchiveReasonSchema = ArchiveReason;
1320
+ ARCHIVE_REASON_VALUES = ArchiveReason.options;
1321
+ ARCHIVE_REASON_TOMBSTONE = "completed-unverified";
1322
+ ArchiveReasonTombstoneError = class extends Error {
1323
+ code = "E_ARCHIVE_REASON_TOMBSTONE";
1324
+ taskId;
1325
+ constructor(taskId) {
1326
+ super(
1327
+ taskId ? `archiveReason='completed-unverified' is a tombstone \u2014 only migration backfill may write it (taskId=${taskId})` : "archiveReason='completed-unverified' is a tombstone \u2014 only migration backfill may write it"
1328
+ );
1329
+ this.name = "ArchiveReasonTombstoneError";
1330
+ this.taskId = taskId;
1331
+ }
1332
+ };
1333
+ ARCHIVE_REASON_TOMBSTONE_ENV = "CLEO_ARCHIVE_ALLOW_TOMBSTONE";
1334
+ }
1335
+ });
1336
+
1294
1337
  // packages/contracts/src/index.ts
1295
1338
  var src_exports = {};
1296
1339
  __export(src_exports, {
1297
1340
  ADR_STATUSES: () => ADR_STATUSES,
1298
1341
  AGENT_INSTANCE_STATUSES: () => AGENT_INSTANCE_STATUSES,
1299
1342
  AGENT_TYPES: () => AGENT_TYPES,
1343
+ ARCHIVE_REASON_TOMBSTONE: () => ARCHIVE_REASON_TOMBSTONE,
1344
+ ARCHIVE_REASON_TOMBSTONE_ENV: () => ARCHIVE_REASON_TOMBSTONE_ENV,
1345
+ ARCHIVE_REASON_VALUES: () => ARCHIVE_REASON_VALUES,
1346
+ ArchiveReason: () => ArchiveReason,
1347
+ ArchiveReasonSchema: () => ArchiveReasonSchema,
1348
+ ArchiveReasonTombstoneError: () => ArchiveReasonTombstoneError,
1300
1349
  BRAIN_OBSERVATION_TYPES: () => BRAIN_OBSERVATION_TYPES,
1301
1350
  BRANCH_LOCK_ERROR_CODES: () => BRANCH_LOCK_ERROR_CODES,
1302
1351
  ClassifierUnregisteredAgentError: () => ClassifierUnregisteredAgentError,
@@ -1323,6 +1372,7 @@ __export(src_exports, {
1323
1372
  acceptanceGateResultSchema: () => acceptanceGateResultSchema,
1324
1373
  acceptanceGateSchema: () => acceptanceGateSchema,
1325
1374
  acceptanceItemSchema: () => acceptanceItemSchema,
1375
+ assertArchiveReason: () => assertArchiveReason,
1326
1376
  assertPeerIdentity: () => assertPeerIdentity,
1327
1377
  attachmentMetadataSchema: () => attachmentMetadataSchema,
1328
1378
  attachmentRefSchema: () => attachmentRefSchema,
@@ -1345,6 +1395,7 @@ __export(src_exports, {
1345
1395
  getExitCodeName: () => getExitCodeName,
1346
1396
  httpGateSchema: () => httpGateSchema,
1347
1397
  implDiffRecordSchema: () => implDiffRecordSchema,
1398
+ isArchiveTombstoneAllowed: () => isArchiveTombstoneAllowed,
1348
1399
  isErrorCode: () => isErrorCode,
1349
1400
  isErrorResult: () => isErrorResult,
1350
1401
  isErrorType: () => isErrorType,
@@ -1394,6 +1445,7 @@ var init_src = __esm({
1394
1445
  init_session_journal();
1395
1446
  init_status_registry();
1396
1447
  init_task_evidence();
1448
+ init_archive();
1397
1449
  }
1398
1450
  });
1399
1451
 
@@ -11514,8 +11566,8 @@ async function releaseIvtrAutoSuggest(taskId, projectRoot) {
11514
11566
  const cwd = projectRoot ?? resolveProjectRoot2();
11515
11567
  try {
11516
11568
  const accessor = await getAccessor4(cwd);
11517
- const taskResult = await accessor.queryTasks({ id: taskId });
11518
- const taskRecord = (taskResult?.tasks ?? [])[0];
11569
+ const tasks = await accessor.loadTasks([taskId]);
11570
+ const taskRecord = tasks[0];
11519
11571
  if (!taskRecord) {
11520
11572
  return engineError("E_NOT_FOUND", `Task ${taskId} not found`);
11521
11573
  }
@@ -16710,7 +16762,7 @@ var init_admin = __esm({
16710
16762
  try {
16711
16763
  const envelope = await typedDispatch(_adminTypedHandler, mutateKey(operation), params ?? {});
16712
16764
  if (operation === "adr.sync") {
16713
- const data = envelope.data;
16765
+ const data = envelope.success ? envelope.data : void 0;
16714
16766
  if (data && "valid" in data && !data.valid) {
16715
16767
  const errors = Array.isArray(data.errors) ? data.errors : [];
16716
16768
  return {
@@ -17513,7 +17565,6 @@ var init_check = __esm({
17513
17565
  return lafsSuccess(result.data ?? {}, "archive.stats");
17514
17566
  },
17515
17567
  "chain.validate": async (params) => {
17516
- const _projectRoot = getProjectRoot3();
17517
17568
  if (!params.chain) {
17518
17569
  return lafsError("E_INVALID_INPUT", "chain is required", "chain.validate");
17519
17570
  }
@@ -17603,6 +17654,21 @@ var init_check = __esm({
17603
17654
  "test.run"
17604
17655
  );
17605
17656
  },
17657
+ "test.coverage": async (_params) => {
17658
+ const projectRoot = getProjectRoot3();
17659
+ const result = validateTestCoverage(projectRoot);
17660
+ if (!result.success) {
17661
+ return lafsError(
17662
+ String(result.error?.code ?? "E_INTERNAL"),
17663
+ result.error?.message ?? "Unknown error",
17664
+ "test.coverage"
17665
+ );
17666
+ }
17667
+ return lafsSuccess(
17668
+ result.data ?? { lineCoverage: 0, branchCoverage: 0, functionCoverage: 0, threshold: 0 },
17669
+ "test.coverage"
17670
+ );
17671
+ },
17606
17672
  "compliance.sync": async (params) => {
17607
17673
  const projectRoot = getProjectRoot3();
17608
17674
  const { syncComplianceMetrics } = await import("@cleocode/core/internal");
@@ -17652,11 +17718,20 @@ var init_check = __esm({
17652
17718
  async query(operation, params) {
17653
17719
  const startTime = Date.now();
17654
17720
  try {
17655
- const envelope = await typedDispatch(_checkTypedHandler, operation, params ?? {});
17721
+ const envelope = await typedDispatch(
17722
+ _checkTypedHandler,
17723
+ operation,
17724
+ params ?? {}
17725
+ );
17656
17726
  return {
17657
17727
  meta: dispatchMeta("query", "check", operation, startTime),
17658
17728
  success: envelope.success,
17659
- ...envelope.success ? { data: envelope.data } : { error: envelope.error }
17729
+ ...envelope.success ? { data: envelope.data } : {
17730
+ error: {
17731
+ code: envelope.error?.code !== void 0 ? String(envelope.error.code) : "E_INTERNAL",
17732
+ message: envelope.error?.message ?? "Unknown error"
17733
+ }
17734
+ }
17660
17735
  };
17661
17736
  } catch (error) {
17662
17737
  const message = error instanceof Error ? error.message : String(error);
@@ -17670,11 +17745,20 @@ var init_check = __esm({
17670
17745
  async mutate(operation, params) {
17671
17746
  const startTime = Date.now();
17672
17747
  try {
17673
- const envelope = await typedDispatch(_checkTypedHandler, operation, params ?? {});
17748
+ const envelope = await typedDispatch(
17749
+ _checkTypedHandler,
17750
+ operation,
17751
+ params ?? {}
17752
+ );
17674
17753
  return {
17675
17754
  meta: dispatchMeta("mutate", "check", operation, startTime),
17676
17755
  success: envelope.success,
17677
- ...envelope.success ? { data: envelope.data } : { error: envelope.error }
17756
+ ...envelope.success ? { data: envelope.data } : {
17757
+ error: {
17758
+ code: envelope.error?.code !== void 0 ? String(envelope.error.code) : "E_INTERNAL",
17759
+ message: envelope.error?.message ?? "Unknown error"
17760
+ }
17761
+ }
17678
17762
  };
17679
17763
  } catch (error) {
17680
17764
  const message = error instanceof Error ? error.message : String(error);
@@ -17720,13 +17804,25 @@ function envelopeToEngineResult2(envelope) {
17720
17804
  return {
17721
17805
  success: false,
17722
17806
  error: {
17723
- code: envelope.error?.code ?? "E_INTERNAL",
17807
+ code: envelope.error?.code !== void 0 ? String(envelope.error.code) : "E_INTERNAL",
17724
17808
  message: envelope.error?.message ?? "Unknown error"
17725
17809
  }
17726
17810
  };
17727
17811
  }
17812
+ async function _resolveCredential(agentId) {
17813
+ const { AgentRegistryAccessor, getDb: getDb3 } = await import("@cleocode/core/internal");
17814
+ await getDb3();
17815
+ const registry = new AgentRegistryAccessor(process.cwd());
17816
+ const credential = agentId ? await registry.get(agentId) : await registry.getActive();
17817
+ if (!credential) {
17818
+ throw new Error(
17819
+ "No agent credential found. Run: cleo agent register --id <id> --api-key <key>"
17820
+ );
17821
+ }
17822
+ return credential;
17823
+ }
17728
17824
  async function getStatusImpl(agentId) {
17729
- const credential = await this.resolveCredential(agentId);
17825
+ const credential = await _resolveCredential(agentId);
17730
17826
  const pollerRunning = activePoller !== null && activeAgentId === credential.agentId;
17731
17827
  const { LocalTransport } = await import("@cleocode/core/conduit");
17732
17828
  if (LocalTransport.isAvailable(process.cwd())) {
@@ -17785,7 +17881,7 @@ async function getStatusImpl(agentId) {
17785
17881
  };
17786
17882
  }
17787
17883
  async function peekImpl(agentId, limit) {
17788
- const credential = await this.resolveCredential(agentId);
17884
+ const credential = await _resolveCredential(agentId);
17789
17885
  const { LocalTransport } = await import("@cleocode/core/conduit");
17790
17886
  if (LocalTransport.isAvailable(process.cwd())) {
17791
17887
  const transport = new LocalTransport();
@@ -17854,7 +17950,7 @@ async function startPollingImpl(agentId, pollIntervalMs, groupConversationIds) {
17854
17950
  }
17855
17951
  };
17856
17952
  }
17857
- const credential = await this.resolveCredential(agentId);
17953
+ const credential = await _resolveCredential(agentId);
17858
17954
  const { AgentPoller } = await import("@cleocode/runtime");
17859
17955
  const { LocalTransport } = await import("@cleocode/core/conduit");
17860
17956
  let transport;
@@ -17916,7 +18012,7 @@ async function subscribeTopicImpl(topicName, agentId, _filter) {
17916
18012
  error: { code: "E_ARGS", message: 'Must specify "topicName"' }
17917
18013
  };
17918
18014
  }
17919
- const credential = await this.resolveCredential(agentId);
18015
+ const credential = await _resolveCredential(agentId);
17920
18016
  const { LocalTransport } = await import("@cleocode/core/conduit");
17921
18017
  if (!LocalTransport.isAvailable(process.cwd())) {
17922
18018
  return {
@@ -17957,7 +18053,7 @@ async function publishToTopicImpl(topicName, content, kind, payload, agentId) {
17957
18053
  error: { code: "E_ARGS", message: 'Must specify "content"' }
17958
18054
  };
17959
18055
  }
17960
- const credential = await this.resolveCredential(agentId);
18056
+ const credential = await _resolveCredential(agentId);
17961
18057
  const { LocalTransport } = await import("@cleocode/core/conduit");
17962
18058
  if (!LocalTransport.isAvailable(process.cwd())) {
17963
18059
  return {
@@ -17995,7 +18091,7 @@ async function listenTopicImpl(topicName, agentId, limit, since) {
17995
18091
  };
17996
18092
  }
17997
18093
  const startMs = Date.now();
17998
- const credential = await this.resolveCredential(agentId);
18094
+ const credential = await _resolveCredential(agentId);
17999
18095
  const { LocalTransport } = await import("@cleocode/core/conduit");
18000
18096
  if (!LocalTransport.isAvailable(process.cwd())) {
18001
18097
  return {
@@ -18040,7 +18136,7 @@ async function sendMessageImpl(content, to, conversationId, agentId) {
18040
18136
  error: { code: "E_ARGS", message: 'Must specify "to" (agent ID) or "conversationId"' }
18041
18137
  };
18042
18138
  }
18043
- const credential = await this.resolveCredential(agentId);
18139
+ const credential = await _resolveCredential(agentId);
18044
18140
  const { LocalTransport } = await import("@cleocode/core/conduit");
18045
18141
  if (LocalTransport.isAvailable(process.cwd())) {
18046
18142
  const transport = new LocalTransport();
@@ -19243,7 +19339,8 @@ import {
19243
19339
  getBrainDb,
19244
19340
  getBrainNativeDb,
19245
19341
  resolveAnthropicApiKey,
19246
- resolveAnthropicApiKeySource
19342
+ resolveAnthropicApiKeySource,
19343
+ typedAll
19247
19344
  } from "@cleocode/core/internal";
19248
19345
  import {
19249
19346
  approveBackfillRun,
@@ -20226,29 +20323,29 @@ var init_memory2 = __esm({
20226
20323
  }
20227
20324
  let stdpWeights = [];
20228
20325
  try {
20229
- const edgeRows = nativeDb.prepare(
20326
+ const stmt = nativeDb.prepare(
20230
20327
  `SELECT from_id, to_id, edge_type, weight,
20328
+ COALESCE(reinforcement_count, 0) AS reinforcement_count,
20329
+ last_reinforced_at
20330
+ FROM brain_page_edges
20331
+ WHERE (from_id = ? OR to_id = ?)
20332
+ AND plasticity_class IN ('hebbian', 'stdp')
20333
+ ORDER BY weight DESC
20334
+ LIMIT 20`
20335
+ );
20336
+ stdpWeights = typedAll(stmt, entryId, entryId);
20337
+ } catch {
20338
+ try {
20339
+ const stmt = nativeDb.prepare(
20340
+ `SELECT from_id, to_id, edge_type, weight,
20231
20341
  COALESCE(reinforcement_count, 0) AS reinforcement_count,
20232
20342
  last_reinforced_at
20233
20343
  FROM brain_page_edges
20234
- WHERE (from_id = ? OR to_id = ?)
20235
- AND plasticity_class IN ('hebbian', 'stdp')
20344
+ WHERE from_id = ? OR to_id = ?
20236
20345
  ORDER BY weight DESC
20237
20346
  LIMIT 20`
20238
- ).all(entryId, entryId);
20239
- stdpWeights = edgeRows;
20240
- } catch {
20241
- try {
20242
- const edgeRows = nativeDb.prepare(
20243
- `SELECT from_id, to_id, edge_type, weight,
20244
- COALESCE(reinforcement_count, 0) AS reinforcement_count,
20245
- last_reinforced_at
20246
- FROM brain_page_edges
20247
- WHERE from_id = ? OR to_id = ?
20248
- ORDER BY weight DESC
20249
- LIMIT 20`
20250
- ).all(entryId, entryId);
20251
- stdpWeights = edgeRows;
20347
+ );
20348
+ stdpWeights = typedAll(stmt, entryId, entryId);
20252
20349
  } catch {
20253
20350
  }
20254
20351
  }
@@ -21634,7 +21731,15 @@ async function nexusProfileUpsert(trait) {
21634
21731
  try {
21635
21732
  const nexusDb = await getNexusDb();
21636
21733
  const existing = await getUserProfileTrait(nexusDb, trait.traitKey);
21637
- await upsertUserProfileTrait(nexusDb, trait);
21734
+ const now = (/* @__PURE__ */ new Date()).toISOString();
21735
+ const fullTrait = {
21736
+ ...trait,
21737
+ firstObservedAt: existing?.firstObservedAt ?? now,
21738
+ lastReinforcedAt: now,
21739
+ reinforcementCount: existing ? existing.reinforcementCount + 1 : 1,
21740
+ supersededBy: existing?.supersededBy ?? null
21741
+ };
21742
+ await upsertUserProfileTrait(nexusDb, fullTrait);
21638
21743
  return engineSuccess({ created: existing === null });
21639
21744
  } catch (error) {
21640
21745
  return engineError("E_INTERNAL", error instanceof Error ? error.message : String(error));
@@ -30430,7 +30535,7 @@ function envelopeToEngineResult3(envelope) {
30430
30535
  return {
30431
30536
  success: false,
30432
30537
  error: {
30433
- code: envelope.error?.code ?? "E_INTERNAL",
30538
+ code: envelope.error?.code !== void 0 ? String(envelope.error.code) : "E_INTERNAL",
30434
30539
  message: envelope.error?.message ?? "Unknown error"
30435
30540
  }
30436
30541
  };