@cleocode/core 2026.4.40 → 2026.4.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/upgrade.ts CHANGED
@@ -855,6 +855,21 @@ export async function runUpgrade(
855
855
  /* best-effort — signaldock.db will be created on first agent operation */
856
856
  }
857
857
 
858
+ // Initialize conduit.db for project-tier agent messaging (T310)
859
+ try {
860
+ const { ensureConduitDb } = await import('./store/conduit-sqlite.js');
861
+ const cdResult = ensureConduitDb(projectRootForMaint);
862
+ if (cdResult.action === 'created') {
863
+ actions.push({
864
+ action: 'ensure_conduit_db',
865
+ status: 'applied',
866
+ details: 'conduit.db created with full schema',
867
+ });
868
+ }
869
+ } catch {
870
+ /* best-effort — conduit.db will be created on first agent operation */
871
+ }
872
+
858
873
  // Regenerate memory-bridge.md
859
874
  try {
860
875
  const { writeMemoryBridge } = await import('./memory/memory-bridge.js');
@@ -1015,6 +1030,51 @@ export async function runUpgrade(
1015
1030
  } catch {
1016
1031
  /* best-effort */
1017
1032
  }
1033
+
1034
+ // Adapter discovery, activation, and install (T5240)
1035
+ // Ensures Claude Code settings.json hooks and other adapter configs stay current.
1036
+ try {
1037
+ const { AdapterManager } = await import('./adapters/index.js');
1038
+ const mgr = AdapterManager.getInstance(projectRootForMaint);
1039
+ const manifests = mgr.discover();
1040
+ if (manifests.length > 0) {
1041
+ const detected = mgr.detectActive();
1042
+ for (const adapterId of detected) {
1043
+ try {
1044
+ const adapter = await mgr.activate(adapterId);
1045
+ const installResult = await adapter.install.install({
1046
+ projectDir: projectRootForMaint,
1047
+ });
1048
+ if (installResult.success) {
1049
+ actions.push({
1050
+ action: 'adapter_install',
1051
+ status: 'applied',
1052
+ details: `Adapter ${adapterId}: installed/updated`,
1053
+ });
1054
+ }
1055
+ } catch {
1056
+ /* best-effort — adapter may not support install */
1057
+ }
1058
+ }
1059
+ }
1060
+ } catch {
1061
+ /* best-effort — adapters are optional */
1062
+ }
1063
+
1064
+ // Ensure the global CleoOS Hub exists (idempotent)
1065
+ try {
1066
+ const { ensureCleoOsHub } = await import('./scaffold.js');
1067
+ const hubResult = await ensureCleoOsHub();
1068
+ if (hubResult.action === 'created') {
1069
+ actions.push({
1070
+ action: 'cleoos_hub',
1071
+ status: 'applied',
1072
+ details: hubResult.details ?? 'CleoOS hub scaffolded',
1073
+ });
1074
+ }
1075
+ } catch {
1076
+ /* best-effort */
1077
+ }
1018
1078
  } else {
1019
1079
  // Dry-run reporting for new steps
1020
1080
  const { existsSync: fsExistsSync } = await import('node:fs');
@@ -1291,6 +1351,66 @@ export async function diagnoseUpgrade(options: { cwd?: string } = {}): Promise<D
1291
1351
  fix: 'Run: cleo upgrade',
1292
1352
  });
1293
1353
  }
1354
+
1355
+ // T528/T531/T549 column validation — ensure brain schema expansions applied
1356
+ const brainColumnChecks: Array<{ table: string; columns: string[]; task: string }> = [
1357
+ {
1358
+ table: 'brain_page_nodes',
1359
+ columns: ['quality_score', 'content_hash', 'last_activity_at', 'updated_at'],
1360
+ task: 'T528',
1361
+ },
1362
+ {
1363
+ table: 'brain_decisions',
1364
+ columns: [
1365
+ 'quality_score',
1366
+ 'memory_tier',
1367
+ 'memory_type',
1368
+ 'verified',
1369
+ 'valid_at',
1370
+ 'invalid_at',
1371
+ 'source_confidence',
1372
+ 'citation_count',
1373
+ ],
1374
+ task: 'T531/T549',
1375
+ },
1376
+ {
1377
+ table: 'brain_observations',
1378
+ columns: ['quality_score', 'memory_tier', 'memory_type', 'verified'],
1379
+ task: 'T531/T549',
1380
+ },
1381
+ ];
1382
+
1383
+ const allBrainColsMissing: string[] = [];
1384
+ for (const { table, columns, task } of brainColumnChecks) {
1385
+ const hasTable = nativeDb
1386
+ .prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?")
1387
+ .get(table) as { name?: string } | undefined;
1388
+ if (!hasTable?.name) continue;
1389
+
1390
+ const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all() as Array<{
1391
+ name: string;
1392
+ }>;
1393
+ const colNames = new Set(cols.map((c: { name: string }) => c.name));
1394
+ const missing = columns.filter((c) => !colNames.has(c));
1395
+ if (missing.length > 0) {
1396
+ allBrainColsMissing.push(`${table}: ${missing.join(', ')} (${task})`);
1397
+ }
1398
+ }
1399
+
1400
+ if (allBrainColsMissing.length > 0) {
1401
+ findings.push({
1402
+ check: 'brain.db.schema_columns',
1403
+ status: 'error',
1404
+ details: `Missing brain schema columns: ${allBrainColsMissing.join('; ')}`,
1405
+ fix: 'Run: cleo upgrade (will add missing columns automatically)',
1406
+ });
1407
+ } else {
1408
+ findings.push({
1409
+ check: 'brain.db.schema_columns',
1410
+ status: 'ok',
1411
+ details: 'All T528/T531/T549 brain schema columns present',
1412
+ });
1413
+ }
1294
1414
  } else {
1295
1415
  findings.push({
1296
1416
  check: 'brain.db.connection',
@@ -1310,6 +1430,85 @@ export async function diagnoseUpgrade(options: { cwd?: string } = {}): Promise<D
1310
1430
  check: 'brain.db',
1311
1431
  status: 'warning',
1312
1432
  details: 'brain.db not found (will be created on first use)',
1433
+ fix: 'Run: cleo upgrade',
1434
+ });
1435
+ }
1436
+
1437
+ // ── signaldock.db validation ──
1438
+ const signaldockDbPath = join(cleoDir, 'signaldock.db');
1439
+ if (existsSync(signaldockDbPath)) {
1440
+ findings.push({
1441
+ check: 'signaldock.db',
1442
+ status: 'ok',
1443
+ details: 'signaldock.db exists',
1444
+ });
1445
+ } else {
1446
+ findings.push({
1447
+ check: 'signaldock.db',
1448
+ status: 'warning',
1449
+ details: 'signaldock.db not found',
1450
+ fix: 'Run: cleo upgrade',
1451
+ });
1452
+ }
1453
+
1454
+ // ── conduit.db validation ──
1455
+ const conduitDbPath = join(cleoDir, 'conduit.db');
1456
+ if (existsSync(conduitDbPath)) {
1457
+ findings.push({
1458
+ check: 'conduit.db',
1459
+ status: 'ok',
1460
+ details: 'conduit.db exists',
1461
+ });
1462
+ } else {
1463
+ findings.push({
1464
+ check: 'conduit.db',
1465
+ status: 'warning',
1466
+ details: 'conduit.db not found',
1467
+ fix: 'Run: cleo upgrade',
1468
+ });
1469
+ }
1470
+
1471
+ // ── memory-bridge.md validation ──
1472
+ const memoryBridgePath = join(cleoDir, 'memory-bridge.md');
1473
+ if (existsSync(memoryBridgePath)) {
1474
+ try {
1475
+ const content = readFileSync(memoryBridgePath, 'utf-8');
1476
+ const hasAutoGenMarker = content.includes('Auto-generated');
1477
+ const hasGarbage = content.includes('undefined') && content.length < 100;
1478
+ if (hasGarbage) {
1479
+ findings.push({
1480
+ check: 'memory-bridge.md',
1481
+ status: 'error',
1482
+ details: 'memory-bridge.md contains garbage content',
1483
+ fix: 'Run: cleo upgrade (will regenerate)',
1484
+ });
1485
+ } else if (hasAutoGenMarker) {
1486
+ findings.push({
1487
+ check: 'memory-bridge.md',
1488
+ status: 'ok',
1489
+ details: 'memory-bridge.md exists and has valid content',
1490
+ });
1491
+ } else {
1492
+ findings.push({
1493
+ check: 'memory-bridge.md',
1494
+ status: 'warning',
1495
+ details: 'memory-bridge.md exists but may be stale (no auto-generated marker)',
1496
+ fix: 'Run: cleo upgrade (will regenerate)',
1497
+ });
1498
+ }
1499
+ } catch {
1500
+ findings.push({
1501
+ check: 'memory-bridge.md',
1502
+ status: 'warning',
1503
+ details: 'memory-bridge.md exists but could not be read',
1504
+ });
1505
+ }
1506
+ } else {
1507
+ findings.push({
1508
+ check: 'memory-bridge.md',
1509
+ status: 'warning',
1510
+ details: 'memory-bridge.md not found',
1511
+ fix: 'Run: cleo upgrade (will regenerate)',
1313
1512
  });
1314
1513
  }
1315
1514