@cleocode/core 2026.4.52 → 2026.4.54
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/index.js +177 -83
- package/dist/index.js.map +3 -3
- package/dist/init.d.ts.map +1 -1
- package/dist/internal.js +199 -92
- package/dist/internal.js.map +3 -3
- package/dist/scaffold.d.ts +30 -0
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/store/brain-sqlite.d.ts.map +1 -1
- package/dist/store/migration-manager.d.ts.map +1 -1
- package/dist/system/health.d.ts.map +1 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/init.ts +15 -18
- package/src/scaffold.ts +152 -0
- package/src/store/brain-sqlite.ts +9 -6
- package/src/store/migration-manager.ts +104 -2
- package/src/system/health.ts +2 -0
- package/src/upgrade.ts +17 -0
package/dist/scaffold.d.ts
CHANGED
|
@@ -659,6 +659,36 @@ export declare function ensureGlobalScaffold(): Promise<{
|
|
|
659
659
|
* ```
|
|
660
660
|
*/
|
|
661
661
|
export declare function ensureCleoOsHub(): Promise<ScaffoldResult>;
|
|
662
|
+
/**
|
|
663
|
+
* Ensure the Cleo Prime identity file is deployed to the global XDG path.
|
|
664
|
+
*
|
|
665
|
+
* SSoT architecture (T631): CLEOOS-IDENTITY.md lives ONCE at the global path
|
|
666
|
+
* (`~/.local/share/cleo/CLEOOS-IDENTITY.md`). Per-project override is OPTIONAL —
|
|
667
|
+
* a project may place a customized copy at `.cleo/CLEOOS-IDENTITY.md` and the
|
|
668
|
+
* loader (`cant-context.ts readIdentityFile`) reads project-first then global.
|
|
669
|
+
*
|
|
670
|
+
* Called by both `cleo init` (init.ts deployStarterBundle) and `cleo upgrade`
|
|
671
|
+
* (upgrade.ts) so existing projects self-heal on upgrade if the file is missing
|
|
672
|
+
* or out of date.
|
|
673
|
+
*
|
|
674
|
+
* Idempotent. Always overwrites if `forceRefresh` is true (used by `upgrade
|
|
675
|
+
* --refresh-identity`); otherwise only writes when missing.
|
|
676
|
+
*
|
|
677
|
+
* @param forceRefresh - Overwrite even if the file exists. Default false.
|
|
678
|
+
* @returns ScaffoldResult describing what happened.
|
|
679
|
+
*/
|
|
680
|
+
export declare function ensureGlobalIdentity(forceRefresh?: boolean): Promise<ScaffoldResult>;
|
|
681
|
+
/**
|
|
682
|
+
* Check that the global CLEOOS-IDENTITY.md file is present and non-empty.
|
|
683
|
+
* Read-only diagnostic for `cleo doctor`.
|
|
684
|
+
*
|
|
685
|
+
* @returns Check result with status, path details, and self-heal command.
|
|
686
|
+
*
|
|
687
|
+
* @remarks
|
|
688
|
+
* Used by `cleo doctor` to verify the orchestrator persona is installed.
|
|
689
|
+
* Self-heal: `cleo upgrade --refresh-identity` re-deploys from source.
|
|
690
|
+
*/
|
|
691
|
+
export declare function checkGlobalIdentity(): CheckResult;
|
|
662
692
|
/**
|
|
663
693
|
* Check that the global ~/.cleo/ home and its required subdirectories exist.
|
|
664
694
|
* Read-only: no side effects.
|
package/dist/scaffold.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../src/scaffold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA6BH,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IAC3C,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qCAAqC;AACrC,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAEnE,oFAAoF;AACpF,MAAM,WAAW,WAAW;IAC1B,oEAAoE;I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Root":"","sources":["../../src/store/brain-sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAejD,gFAAgF;AAChF,eAAO,MAAM,oBAAoB,UAAU,CAAC;AAW5C;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,IAAI,MAAM,CAMrD;AAuJD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AA0BD;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,OAAO,WAAW,CAAC,CAAC,CAqE9F;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAcnC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAexC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,GAAG,IAAI,CAEtD;AAED,YAAY,EAAE,kBAAkB,EAAE,CAAC;AACnC;;GAEG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration-manager.d.ts","sourceRoot":"","sources":["../../src/store/migration-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE,sDAAsD;AACtD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,GAAG,EAAE,MAAM,CAAC;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EAAE,MAAM,EACxB,QAAQ,CAAC,EAAE,YAAY,EACvB,cAAc,CAAC,EAAE,MAAM,EACvB,YAAY,CAAC,EAAE,MAAM,GACpB,IAAI,CAkCN;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,cAAc,EAAE,EACjC,YAAY,EAAE,MAAM,GACnB,IAAI,CAmBN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/system/health.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAI5D,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/system/health.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAI5D,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA6GhE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;IACzC,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,IAAI,GAAG,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GA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",
|
|
4
4
|
"description": "CLEO core business logic kernel — tasks, sessions, memory, orchestration, lifecycle, with bundled SQLite store",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"write-file-atomic": "^7.0.1",
|
|
64
64
|
"yaml": "^2.8.3",
|
|
65
65
|
"zod": "^4.3.6",
|
|
66
|
-
"@cleocode/adapters": "2026.4.
|
|
67
|
-
"@cleocode/agents": "2026.4.
|
|
68
|
-
"@cleocode/caamp": "2026.4.
|
|
69
|
-
"@cleocode/contracts": "2026.4.
|
|
70
|
-
"@cleocode/lafs": "2026.4.
|
|
71
|
-
"@cleocode/nexus": "2026.4.
|
|
72
|
-
"@cleocode/skills": "2026.4.
|
|
66
|
+
"@cleocode/adapters": "2026.4.54",
|
|
67
|
+
"@cleocode/agents": "2026.4.54",
|
|
68
|
+
"@cleocode/caamp": "2026.4.54",
|
|
69
|
+
"@cleocode/contracts": "2026.4.54",
|
|
70
|
+
"@cleocode/lafs": "2026.4.54",
|
|
71
|
+
"@cleocode/nexus": "2026.4.54",
|
|
72
|
+
"@cleocode/skills": "2026.4.54"
|
|
73
73
|
},
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=24.0.0"
|
package/src/init.ts
CHANGED
|
@@ -1097,26 +1097,23 @@ export async function deployStarterBundle(
|
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
|
-
//
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
await copyFile(identitySrc, identityDst);
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
// Also deploy CLEOOS-IDENTITY.md to the global XDG data directory so it is
|
|
1108
|
-
// available system-wide (e.g. ~/.local/share/cleo/CLEOOS-IDENTITY.md).
|
|
1109
|
-
// This mirrors the project-level copy above and follows the same
|
|
1110
|
-
// idempotent pattern: never overwrite an existing file.
|
|
1100
|
+
// Deploy CLEOOS-IDENTITY.md to global XDG via shared utility.
|
|
1101
|
+
// Single SSoT at global path; project path reserved for optional per-project
|
|
1102
|
+
// override (loader: cant-context.ts readIdentityFile reads project→global).
|
|
1103
|
+
// Same utility is called by `cleo upgrade` so existing projects self-heal.
|
|
1111
1104
|
try {
|
|
1112
|
-
const {
|
|
1113
|
-
const
|
|
1114
|
-
if (
|
|
1115
|
-
|
|
1105
|
+
const { ensureGlobalIdentity } = await import('./scaffold.js');
|
|
1106
|
+
const identityResult = await ensureGlobalIdentity();
|
|
1107
|
+
if (identityResult.action === 'created') {
|
|
1108
|
+
created.push(`identity: ${identityResult.path}`);
|
|
1109
|
+
} else if (identityResult.action === 'skipped' && identityResult.details) {
|
|
1110
|
+
warnings.push(`identity skipped: ${identityResult.details}`);
|
|
1116
1111
|
}
|
|
1117
|
-
} catch {
|
|
1118
|
-
|
|
1112
|
+
} catch (err) {
|
|
1113
|
+
warnings.push(`identity deploy failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1119
1114
|
}
|
|
1120
1115
|
|
|
1121
|
-
created.push(
|
|
1116
|
+
created.push(
|
|
1117
|
+
'starter-bundle: team + agent .cant files deployed to .cleo/ (identity at global XDG)',
|
|
1118
|
+
);
|
|
1122
1119
|
}
|
package/src/scaffold.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
15
15
|
import type { Dirent } from 'node:fs';
|
|
16
16
|
import { existsSync, constants as fsConstants, readFileSync, statSync } from 'node:fs';
|
|
17
17
|
import { access, copyFile, mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
18
|
+
import { createRequire } from 'node:module';
|
|
18
19
|
import { homedir as getHomedir } from 'node:os';
|
|
19
20
|
import { dirname, join, resolve } from 'node:path';
|
|
20
21
|
import { fileURLToPath } from 'node:url';
|
|
@@ -1836,8 +1837,159 @@ export async function ensureCleoOsHub(): Promise<ScaffoldResult> {
|
|
|
1836
1837
|
};
|
|
1837
1838
|
}
|
|
1838
1839
|
|
|
1840
|
+
/**
|
|
1841
|
+
* Resolve the source location of CLEOOS-IDENTITY.md from the cleo-os starter bundle.
|
|
1842
|
+
*
|
|
1843
|
+
* Search order:
|
|
1844
|
+
* 1. Monorepo development: `packages/cleo-os/starter-bundle/CLEOOS-IDENTITY.md`
|
|
1845
|
+
* 2. Installed package: `node_modules/@cleocode/cleo-os/starter-bundle/CLEOOS-IDENTITY.md`
|
|
1846
|
+
*
|
|
1847
|
+
* @returns Absolute path to the source identity file, or null if not found.
|
|
1848
|
+
* @internal Used by ensureGlobalIdentity.
|
|
1849
|
+
*/
|
|
1850
|
+
function resolveIdentitySourcePath(): string | null {
|
|
1851
|
+
// Prefer monorepo source (development)
|
|
1852
|
+
const monorepoPath = join(
|
|
1853
|
+
process.cwd(),
|
|
1854
|
+
'packages',
|
|
1855
|
+
'cleo-os',
|
|
1856
|
+
'starter-bundle',
|
|
1857
|
+
'CLEOOS-IDENTITY.md',
|
|
1858
|
+
);
|
|
1859
|
+
if (existsSync(monorepoPath)) return monorepoPath;
|
|
1860
|
+
|
|
1861
|
+
// Fall back to installed package via require resolution
|
|
1862
|
+
try {
|
|
1863
|
+
const require = createRequire(import.meta.url);
|
|
1864
|
+
const pkgJson = require.resolve('@cleocode/cleo-os/package.json');
|
|
1865
|
+
const pkgDir = pkgJson.replace(/\/package\.json$/, '');
|
|
1866
|
+
const installedPath = join(pkgDir, 'starter-bundle', 'CLEOOS-IDENTITY.md');
|
|
1867
|
+
if (existsSync(installedPath)) return installedPath;
|
|
1868
|
+
} catch {
|
|
1869
|
+
// Not installed — fall through
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
return null;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
/**
|
|
1876
|
+
* Ensure the Cleo Prime identity file is deployed to the global XDG path.
|
|
1877
|
+
*
|
|
1878
|
+
* SSoT architecture (T631): CLEOOS-IDENTITY.md lives ONCE at the global path
|
|
1879
|
+
* (`~/.local/share/cleo/CLEOOS-IDENTITY.md`). Per-project override is OPTIONAL —
|
|
1880
|
+
* a project may place a customized copy at `.cleo/CLEOOS-IDENTITY.md` and the
|
|
1881
|
+
* loader (`cant-context.ts readIdentityFile`) reads project-first then global.
|
|
1882
|
+
*
|
|
1883
|
+
* Called by both `cleo init` (init.ts deployStarterBundle) and `cleo upgrade`
|
|
1884
|
+
* (upgrade.ts) so existing projects self-heal on upgrade if the file is missing
|
|
1885
|
+
* or out of date.
|
|
1886
|
+
*
|
|
1887
|
+
* Idempotent. Always overwrites if `forceRefresh` is true (used by `upgrade
|
|
1888
|
+
* --refresh-identity`); otherwise only writes when missing.
|
|
1889
|
+
*
|
|
1890
|
+
* @param forceRefresh - Overwrite even if the file exists. Default false.
|
|
1891
|
+
* @returns ScaffoldResult describing what happened.
|
|
1892
|
+
*/
|
|
1893
|
+
export async function ensureGlobalIdentity(forceRefresh = false): Promise<ScaffoldResult> {
|
|
1894
|
+
const sourcePath = resolveIdentitySourcePath();
|
|
1895
|
+
if (!sourcePath) {
|
|
1896
|
+
return {
|
|
1897
|
+
action: 'skipped',
|
|
1898
|
+
path: '',
|
|
1899
|
+
details: 'CLEOOS-IDENTITY.md source not found in monorepo or installed package',
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
const cleoHome = getCleoHome();
|
|
1904
|
+
const dst = join(cleoHome, 'CLEOOS-IDENTITY.md');
|
|
1905
|
+
|
|
1906
|
+
try {
|
|
1907
|
+
await mkdir(cleoHome, { recursive: true });
|
|
1908
|
+
} catch (err) {
|
|
1909
|
+
return {
|
|
1910
|
+
action: 'skipped',
|
|
1911
|
+
path: dst,
|
|
1912
|
+
details: `Failed to create global cleo home: ${err instanceof Error ? err.message : String(err)}`,
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
if (existsSync(dst) && !forceRefresh) {
|
|
1917
|
+
return { action: 'skipped', path: dst, details: 'identity already present' };
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
const existedBefore = existsSync(dst);
|
|
1921
|
+
try {
|
|
1922
|
+
const content = readFileSync(sourcePath, 'utf-8');
|
|
1923
|
+
await writeFile(dst, content);
|
|
1924
|
+
return {
|
|
1925
|
+
action: existedBefore ? 'repaired' : 'created',
|
|
1926
|
+
path: dst,
|
|
1927
|
+
details: `from ${sourcePath}`,
|
|
1928
|
+
};
|
|
1929
|
+
} catch (err) {
|
|
1930
|
+
return {
|
|
1931
|
+
action: 'skipped',
|
|
1932
|
+
path: dst,
|
|
1933
|
+
details: `Failed to write identity: ${err instanceof Error ? err.message : String(err)}`,
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1839
1938
|
// ── Global check* functions (read-only diagnostics) ──────────────────
|
|
1840
1939
|
|
|
1940
|
+
/**
|
|
1941
|
+
* Check that the global CLEOOS-IDENTITY.md file is present and non-empty.
|
|
1942
|
+
* Read-only diagnostic for `cleo doctor`.
|
|
1943
|
+
*
|
|
1944
|
+
* @returns Check result with status, path details, and self-heal command.
|
|
1945
|
+
*
|
|
1946
|
+
* @remarks
|
|
1947
|
+
* Used by `cleo doctor` to verify the orchestrator persona is installed.
|
|
1948
|
+
* Self-heal: `cleo upgrade --refresh-identity` re-deploys from source.
|
|
1949
|
+
*/
|
|
1950
|
+
export function checkGlobalIdentity(): CheckResult {
|
|
1951
|
+
const cleoHome = getCleoHome();
|
|
1952
|
+
const identityPath = join(cleoHome, 'CLEOOS-IDENTITY.md');
|
|
1953
|
+
|
|
1954
|
+
if (!existsSync(identityPath)) {
|
|
1955
|
+
return {
|
|
1956
|
+
id: 'global_identity',
|
|
1957
|
+
category: 'global',
|
|
1958
|
+
status: 'failed',
|
|
1959
|
+
message: 'Global CLEOOS-IDENTITY.md not found — orchestrator persona missing',
|
|
1960
|
+
details: { path: identityPath, exists: false },
|
|
1961
|
+
fix: 'cleo upgrade (auto-deploys identity)',
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
let size = 0;
|
|
1966
|
+
try {
|
|
1967
|
+
size = statSync(identityPath).size;
|
|
1968
|
+
} catch {
|
|
1969
|
+
/* ignore */
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
if (size === 0) {
|
|
1973
|
+
return {
|
|
1974
|
+
id: 'global_identity',
|
|
1975
|
+
category: 'global',
|
|
1976
|
+
status: 'failed',
|
|
1977
|
+
message: 'Global CLEOOS-IDENTITY.md exists but is empty',
|
|
1978
|
+
details: { path: identityPath, exists: true, size: 0 },
|
|
1979
|
+
fix: 'cleo upgrade --refresh-identity',
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
return {
|
|
1984
|
+
id: 'global_identity',
|
|
1985
|
+
category: 'global',
|
|
1986
|
+
status: 'passed',
|
|
1987
|
+
message: 'Global CLEOOS-IDENTITY.md present',
|
|
1988
|
+
details: { path: identityPath, exists: true, size },
|
|
1989
|
+
fix: '',
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1841
1993
|
/**
|
|
1842
1994
|
* Check that the global ~/.cleo/ home and its required subdirectories exist.
|
|
1843
1995
|
* Read-only: no side effects.
|
|
@@ -152,12 +152,15 @@ function runBrainMigrations(
|
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
|
|
155
|
+
// T632 root-cause fix: the migration journal reconciler (Sub-case B) now uses
|
|
156
|
+
// a per-migration DDL probe instead of wholesale-marking-all-applied. ALTER TABLE
|
|
157
|
+
// ADD COLUMN migrations (T417 agent, T528 provenance) now run correctly when
|
|
158
|
+
// their columns are missing.
|
|
159
|
+
//
|
|
160
|
+
// The previous `ensureColumns` band-aids (for `agent` and `provenance`) were
|
|
161
|
+
// removed in v2026.4.54 alongside the reconciler fix. If schema regressions
|
|
162
|
+
// recur, the right action is to debug `probeAndMarkApplied` in
|
|
163
|
+
// migration-manager.ts — NOT to add new band-aids here.
|
|
161
164
|
|
|
162
165
|
// T626-M1: Normalize co_retrieved edge type — idempotent safety-net UPDATE.
|
|
163
166
|
// The shipped Hebbian strengthener emitted edge_type = 'relates_to' instead of
|
|
@@ -98,6 +98,99 @@ function insertJournalEntry(
|
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Probe a migration's DDL against the live schema and mark the journal entry
|
|
103
|
+
* applied IF AND ONLY IF all DDL targets already exist in the database.
|
|
104
|
+
*
|
|
105
|
+
* Supports three DDL forms commonly emitted by drizzle migrations:
|
|
106
|
+
* - `ALTER TABLE foo ADD COLUMN bar text` → mark applied if column foo.bar exists
|
|
107
|
+
* - `CREATE TABLE foo (...)` → mark applied if table foo exists
|
|
108
|
+
* - `CREATE INDEX [IF NOT EXISTS] idx_foo ON foo(...)` → mark applied if index exists
|
|
109
|
+
*
|
|
110
|
+
* If the migration contains DDL that doesn't fall into these patterns, or if any
|
|
111
|
+
* target is missing, the function returns false and DOES NOT mark applied —
|
|
112
|
+
* leaving the migration for Drizzle's normal `migrate()` to run.
|
|
113
|
+
*
|
|
114
|
+
* Used by:
|
|
115
|
+
* - Scenario 2 Sub-case B (after journal reset, decide what was already applied)
|
|
116
|
+
* - Scenario 3 (originally inline; now extracted for reuse)
|
|
117
|
+
*
|
|
118
|
+
* Replaces the broken "wholesale mark applied" pattern that was the root cause
|
|
119
|
+
* of the ensureColumns band-aid sprawl (T632).
|
|
120
|
+
*
|
|
121
|
+
* @param nativeDb - Native SQLite database handle
|
|
122
|
+
* @param migration - One entry from drizzle's readMigrationFiles
|
|
123
|
+
* @param logSubsystem - Logger subsystem name
|
|
124
|
+
* @returns true if the journal entry was inserted; false if migration must run
|
|
125
|
+
*/
|
|
126
|
+
function probeAndMarkApplied(
|
|
127
|
+
nativeDb: DatabaseSync,
|
|
128
|
+
migration: { hash: string; folderMillis: number; name?: string; sql?: string | string[] },
|
|
129
|
+
logSubsystem: string,
|
|
130
|
+
): boolean {
|
|
131
|
+
const sqlStatements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ''];
|
|
132
|
+
const fullSql = sqlStatements.join('\n');
|
|
133
|
+
|
|
134
|
+
// Extract DDL targets we can probe.
|
|
135
|
+
const alterColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
|
|
136
|
+
const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
|
|
137
|
+
const createIndexRegex =
|
|
138
|
+
/CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
|
|
139
|
+
|
|
140
|
+
const alterTargets: Array<{ table: string; column: string }> = [];
|
|
141
|
+
for (const m of fullSql.matchAll(alterColumnRegex)) {
|
|
142
|
+
alterTargets.push({ table: m[1] as string, column: m[2] as string });
|
|
143
|
+
}
|
|
144
|
+
const tableTargets: string[] = [];
|
|
145
|
+
for (const m of fullSql.matchAll(createTableRegex)) {
|
|
146
|
+
tableTargets.push(m[1] as string);
|
|
147
|
+
}
|
|
148
|
+
const indexTargets: string[] = [];
|
|
149
|
+
for (const m of fullSql.matchAll(createIndexRegex)) {
|
|
150
|
+
indexTargets.push(m[1] as string);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const totalTargets = alterTargets.length + tableTargets.length + indexTargets.length;
|
|
154
|
+
if (totalTargets === 0) {
|
|
155
|
+
// No probable DDL — could be UPDATE/INSERT/DELETE/etc. Leave for migrate().
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Probe each target.
|
|
160
|
+
const allAltersPresent = alterTargets.every(({ table, column }) => {
|
|
161
|
+
if (!tableExists(nativeDb, table)) return false;
|
|
162
|
+
const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all() as Array<{
|
|
163
|
+
name: string;
|
|
164
|
+
}>;
|
|
165
|
+
return cols.some((c) => c.name === column);
|
|
166
|
+
});
|
|
167
|
+
const allTablesPresent = tableTargets.every((t) => tableExists(nativeDb, t));
|
|
168
|
+
const allIndexesPresent = indexTargets.every((idx) => {
|
|
169
|
+
const rows = nativeDb
|
|
170
|
+
.prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`)
|
|
171
|
+
.all(idx) as Array<{ name: string }>;
|
|
172
|
+
return rows.length > 0;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (allAltersPresent && allTablesPresent && allIndexesPresent) {
|
|
176
|
+
insertJournalEntry(nativeDb, migration.hash, migration.folderMillis, migration.name ?? '');
|
|
177
|
+
const log = getLogger(logSubsystem);
|
|
178
|
+
log.debug(
|
|
179
|
+
{
|
|
180
|
+
migration: migration.name,
|
|
181
|
+
alters: alterTargets.length,
|
|
182
|
+
tables: tableTargets.length,
|
|
183
|
+
indexes: indexTargets.length,
|
|
184
|
+
},
|
|
185
|
+
`Migration ${migration.name} DDL already present in schema — marked applied.`,
|
|
186
|
+
);
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// At least one target missing — leave for drizzle migrate() to run.
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
|
|
101
194
|
/**
|
|
102
195
|
* Bootstrap and reconcile the Drizzle migration journal.
|
|
103
196
|
*
|
|
@@ -184,14 +277,23 @@ export function reconcileJournal(
|
|
|
184
277
|
);
|
|
185
278
|
} else {
|
|
186
279
|
// Sub-case B: Genuine stale hashes from an older CLEO version.
|
|
280
|
+
// ROOT-CAUSE FIX (T632): The previous implementation DELETEd the journal
|
|
281
|
+
// and INSERTed all local migrations as applied WITHOUT running their SQL.
|
|
282
|
+
// That meant ALTER TABLE migrations (T417 agent, T528 provenance, etc.)
|
|
283
|
+
// got marked applied but their columns were never added — forcing
|
|
284
|
+
// ensureColumns band-aids in brain-sqlite.ts to patch the missing schema.
|
|
285
|
+
//
|
|
286
|
+
// Real fix: clear orphaned entries, then PROBE each local migration's
|
|
287
|
+
// DDL. Mark applied ONLY if the DDL targets already exist in the schema.
|
|
288
|
+
// Drizzle's migrate() (called next) will run whatever remains unjournaled.
|
|
187
289
|
const log = getLogger(logSubsystem);
|
|
188
290
|
log.warn(
|
|
189
291
|
{ orphaned: orphanedEntries.length },
|
|
190
|
-
`Detected stale migration journal entries from a previous CLEO version. Reconciling.`,
|
|
292
|
+
`Detected stale migration journal entries from a previous CLEO version. Reconciling via DDL probe.`,
|
|
191
293
|
);
|
|
192
294
|
nativeDb.exec('DELETE FROM "__drizzle_migrations"');
|
|
193
295
|
for (const m of localMigrations) {
|
|
194
|
-
|
|
296
|
+
probeAndMarkApplied(nativeDb, m, logSubsystem);
|
|
195
297
|
}
|
|
196
298
|
}
|
|
197
299
|
}
|
package/src/system/health.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
checkCleoStructure,
|
|
19
19
|
checkConfig,
|
|
20
20
|
checkGlobalHome,
|
|
21
|
+
checkGlobalIdentity,
|
|
21
22
|
checkGlobalTemplates,
|
|
22
23
|
checkLogDir,
|
|
23
24
|
checkMemoryBridge,
|
|
@@ -842,6 +843,7 @@ export async function coreDoctorReport(projectRoot: string): Promise<DoctorRepor
|
|
|
842
843
|
// 5c. Global scaffold checks: home, templates, schemas
|
|
843
844
|
checks.push(mapCheckResult(checkGlobalHome()));
|
|
844
845
|
checks.push(mapCheckResult(checkGlobalTemplates()));
|
|
846
|
+
checks.push(mapCheckResult(checkGlobalIdentity()));
|
|
845
847
|
checks.push(mapSchemaCheckResult(checkGlobalSchemas()));
|
|
846
848
|
|
|
847
849
|
// 5d. Project scaffold checks: log dir, structure, git hooks, project-info, injection
|
package/src/upgrade.ts
CHANGED
|
@@ -940,6 +940,23 @@ export async function runUpgrade(
|
|
|
940
940
|
/* best-effort */
|
|
941
941
|
}
|
|
942
942
|
|
|
943
|
+
// Ensure global CLEOOS-IDENTITY.md is present (T631 — single SSoT).
|
|
944
|
+
// Self-heals if file is missing on existing projects after upgrade.
|
|
945
|
+
try {
|
|
946
|
+
const { ensureGlobalIdentity } = await import('./scaffold.js');
|
|
947
|
+
const identityResult = await ensureGlobalIdentity();
|
|
948
|
+
actions.push({
|
|
949
|
+
action: 'global_identity',
|
|
950
|
+
status:
|
|
951
|
+
identityResult.action === 'created' || identityResult.action === 'repaired'
|
|
952
|
+
? 'applied'
|
|
953
|
+
: 'skipped',
|
|
954
|
+
details: `${identityResult.path} (${identityResult.details ?? identityResult.action})`,
|
|
955
|
+
});
|
|
956
|
+
} catch {
|
|
957
|
+
/* best-effort — identity is already-kept-or-skipped on failure */
|
|
958
|
+
}
|
|
959
|
+
|
|
943
960
|
// Install core skills
|
|
944
961
|
try {
|
|
945
962
|
const skillsCreated: string[] = [];
|