@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.
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAgCH,sCAAsC;AACtC,MAAM,WAAW,WAAW;IAC1B,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,yCAAyC;IACzC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,oCAAoC;AACpC,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,cAAc,CAAC,EAAE;QACf,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC;QAClC,WAAW,EAAE,MAAM,CAAC;QACpB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;IACF;;;;OAIG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACxD;AAaD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiCnE;AAED;;;GAGG;A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,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAyBnF;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC,CAmFf"}
package/dist/internal.js CHANGED
@@ -11140,44 +11140,6 @@ var init_platform_paths = __esm({
11140
11140
  });
11141
11141
 
11142
11142
  // packages/core/src/paths.ts
11143
- var paths_exports = {};
11144
- __export(paths_exports, {
11145
- getAgentOutputsAbsolute: () => getAgentOutputsAbsolute,
11146
- getAgentOutputsDir: () => getAgentOutputsDir,
11147
- getAgentsHome: () => getAgentsHome,
11148
- getArchivePath: () => getArchivePath,
11149
- getBackupDir: () => getBackupDir,
11150
- getClaudeAgentsDir: () => getClaudeAgentsDir,
11151
- getClaudeMemDbPath: () => getClaudeMemDbPath,
11152
- getCleoCacheDir: () => getCleoCacheDir,
11153
- getCleoCantWorkflowsDir: () => getCleoCantWorkflowsDir,
11154
- getCleoConfigDir: () => getCleoConfigDir,
11155
- getCleoDir: () => getCleoDir,
11156
- getCleoDirAbsolute: () => getCleoDirAbsolute,
11157
- getCleoDocsDir: () => getCleoDocsDir,
11158
- getCleoGlobalAgentsDir: () => getCleoGlobalAgentsDir,
11159
- getCleoGlobalJustfilePath: () => getCleoGlobalJustfilePath,
11160
- getCleoGlobalRecipesDir: () => getCleoGlobalRecipesDir,
11161
- getCleoHome: () => getCleoHome,
11162
- getCleoLogDir: () => getCleoLogDir,
11163
- getCleoPiExtensionsDir: () => getCleoPiExtensionsDir,
11164
- getCleoSchemasDir: () => getCleoSchemasDir,
11165
- getCleoTempDir: () => getCleoTempDir,
11166
- getCleoTemplatesDir: () => getCleoTemplatesDir,
11167
- getCleoTemplatesTildePath: () => getCleoTemplatesTildePath,
11168
- getConfigPath: () => getConfigPath,
11169
- getGlobalConfigPath: () => getGlobalConfigPath,
11170
- getLogPath: () => getLogPath,
11171
- getManifestArchivePath: () => getManifestArchivePath,
11172
- getManifestPath: () => getManifestPath,
11173
- getProjectRoot: () => getProjectRoot,
11174
- getSessionsPath: () => getSessionsPath,
11175
- getTaskPath: () => getTaskPath,
11176
- isAbsolutePath: () => isAbsolutePath,
11177
- isProjectInitialized: () => isProjectInitialized,
11178
- resolveProjectPath: () => resolveProjectPath,
11179
- worktreeScope: () => worktreeScope
11180
- });
11181
11143
  import { AsyncLocalStorage } from "node:async_hooks";
11182
11144
  import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
11183
11145
  import { homedir } from "node:os";
@@ -11196,9 +11158,6 @@ function getCleoTemplatesDir() {
11196
11158
  function getCleoSchemasDir() {
11197
11159
  return join4(getCleoHome(), "schemas");
11198
11160
  }
11199
- function getCleoDocsDir() {
11200
- return join4(getCleoHome(), "docs");
11201
- }
11202
11161
  function getCleoDir(cwd) {
11203
11162
  if (cwd) {
11204
11163
  return getCleoDirAbsolute(cwd);
@@ -11270,15 +11229,6 @@ function getTaskPath(cwd) {
11270
11229
  function getConfigPath(cwd) {
11271
11230
  return join4(getCleoDirAbsolute(cwd), "config.json");
11272
11231
  }
11273
- function getSessionsPath(cwd) {
11274
- return join4(getCleoDirAbsolute(cwd), "sessions.json");
11275
- }
11276
- function getArchivePath(cwd) {
11277
- return join4(getCleoDirAbsolute(cwd), "tasks-archive.json");
11278
- }
11279
- function getLogPath(cwd) {
11280
- return join4(getCleoDirAbsolute(cwd), "logs", "cleo.log");
11281
- }
11282
11232
  function getBackupDir(cwd) {
11283
11233
  return join4(getCleoDirAbsolute(cwd), "backups", "operational");
11284
11234
  }
@@ -11482,6 +11432,54 @@ function insertJournalEntry(nativeDb, hash2, createdAt, name2) {
11482
11432
  `INSERT OR IGNORE INTO "__drizzle_migrations" ("hash", "created_at", "name") VALUES ('${hash2}', ${createdAt}, '${name2}')`
11483
11433
  );
11484
11434
  }
11435
+ function probeAndMarkApplied(nativeDb, migration, logSubsystem) {
11436
+ const sqlStatements = Array.isArray(migration.sql) ? migration.sql : [migration.sql ?? ""];
11437
+ const fullSql = sqlStatements.join("\n");
11438
+ const alterColumnRegex = /ALTER\s+TABLE\s+[`"]?(\w+)[`"]?\s+ADD\s+COLUMN\s+[`"]?(\w+)[`"]?/gi;
11439
+ const createTableRegex = /CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
11440
+ const createIndexRegex = /CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?[`"]?(\w+)[`"]?/gi;
11441
+ const alterTargets = [];
11442
+ for (const m2 of fullSql.matchAll(alterColumnRegex)) {
11443
+ alterTargets.push({ table: m2[1], column: m2[2] });
11444
+ }
11445
+ const tableTargets = [];
11446
+ for (const m2 of fullSql.matchAll(createTableRegex)) {
11447
+ tableTargets.push(m2[1]);
11448
+ }
11449
+ const indexTargets = [];
11450
+ for (const m2 of fullSql.matchAll(createIndexRegex)) {
11451
+ indexTargets.push(m2[1]);
11452
+ }
11453
+ const totalTargets = alterTargets.length + tableTargets.length + indexTargets.length;
11454
+ if (totalTargets === 0) {
11455
+ return false;
11456
+ }
11457
+ const allAltersPresent = alterTargets.every(({ table, column }) => {
11458
+ if (!tableExists(nativeDb, table)) return false;
11459
+ const cols = nativeDb.prepare(`PRAGMA table_info(${table})`).all();
11460
+ return cols.some((c) => c.name === column);
11461
+ });
11462
+ const allTablesPresent = tableTargets.every((t) => tableExists(nativeDb, t));
11463
+ const allIndexesPresent = indexTargets.every((idx) => {
11464
+ const rows = nativeDb.prepare(`SELECT name FROM sqlite_master WHERE type='index' AND name=?`).all(idx);
11465
+ return rows.length > 0;
11466
+ });
11467
+ if (allAltersPresent && allTablesPresent && allIndexesPresent) {
11468
+ insertJournalEntry(nativeDb, migration.hash, migration.folderMillis, migration.name ?? "");
11469
+ const log12 = getLogger(logSubsystem);
11470
+ log12.debug(
11471
+ {
11472
+ migration: migration.name,
11473
+ alters: alterTargets.length,
11474
+ tables: tableTargets.length,
11475
+ indexes: indexTargets.length
11476
+ },
11477
+ `Migration ${migration.name} DDL already present in schema \u2014 marked applied.`
11478
+ );
11479
+ return true;
11480
+ }
11481
+ return false;
11482
+ }
11485
11483
  function reconcileJournal(nativeDb, migrationsFolder, existenceTable, logSubsystem) {
11486
11484
  if (tableExists(nativeDb, existenceTable) && !tableExists(nativeDb, "__drizzle_migrations")) {
11487
11485
  const migrations = readMigrationFiles({ migrationsFolder });
@@ -11518,11 +11516,11 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable, logSubsyst
11518
11516
  const log12 = getLogger(logSubsystem);
11519
11517
  log12.warn(
11520
11518
  { orphaned: orphanedEntries.length },
11521
- `Detected stale migration journal entries from a previous CLEO version. Reconciling.`
11519
+ `Detected stale migration journal entries from a previous CLEO version. Reconciling via DDL probe.`
11522
11520
  );
11523
11521
  nativeDb.exec('DELETE FROM "__drizzle_migrations"');
11524
11522
  for (const m2 of localMigrations) {
11525
- insertJournalEntry(nativeDb, m2.hash, m2.folderMillis, m2.name ?? "");
11523
+ probeAndMarkApplied(nativeDb, m2, logSubsystem);
11526
11524
  }
11527
11525
  }
11528
11526
  }
@@ -14331,8 +14329,8 @@ async function cleanupMigrationArtifacts(backupPath) {
14331
14329
  }
14332
14330
  async function validateSqliteDatabase(dbPath) {
14333
14331
  try {
14334
- const { createRequire: createRequire15 } = await import("node:module");
14335
- const _req = createRequire15(import.meta.url);
14332
+ const { createRequire: createRequire16 } = await import("node:module");
14333
+ const _req = createRequire16(import.meta.url);
14336
14334
  const { DatabaseSync: DatabaseSync10 } = _req("node:sqlite");
14337
14335
  const db = new DatabaseSync10(dbPath, { readOnly: true });
14338
14336
  const integrityRow = db.prepare("PRAGMA integrity_check").get();
@@ -15049,7 +15047,6 @@ function runBrainMigrations(nativeDb, db) {
15049
15047
  "brain"
15050
15048
  );
15051
15049
  }
15052
- ensureColumns(nativeDb, "brain_observations", [{ name: "agent", ddl: "text" }], "brain");
15053
15050
  if (tableExists(nativeDb, "brain_page_edges")) {
15054
15051
  nativeDb.prepare(
15055
15052
  `UPDATE brain_page_edges
@@ -50708,6 +50705,7 @@ __export(scaffold_exports, {
50708
50705
  checkConfig: () => checkConfig,
50709
50706
  checkGitignore: () => checkGitignore,
50710
50707
  checkGlobalHome: () => checkGlobalHome,
50708
+ checkGlobalIdentity: () => checkGlobalIdentity,
50711
50709
  checkGlobalTemplates: () => checkGlobalTemplates,
50712
50710
  checkLogDir: () => checkLogDir,
50713
50711
  checkMemoryBridge: () => checkMemoryBridge,
@@ -50724,6 +50722,7 @@ __export(scaffold_exports, {
50724
50722
  ensureContributorMcp: () => ensureContributorMcp,
50725
50723
  ensureGitignore: () => ensureGitignore,
50726
50724
  ensureGlobalHome: () => ensureGlobalHome,
50725
+ ensureGlobalIdentity: () => ensureGlobalIdentity,
50727
50726
  ensureGlobalScaffold: () => ensureGlobalScaffold,
50728
50727
  ensureGlobalTemplates: () => ensureGlobalTemplates,
50729
50728
  ensureProjectContext: () => ensureProjectContext,
@@ -50741,6 +50740,7 @@ import { execFile as execFile3 } from "node:child_process";
50741
50740
  import { randomUUID as randomUUID2 } from "node:crypto";
50742
50741
  import { existsSync as existsSync40, constants as fsConstants3, readFileSync as readFileSync23, statSync as statSync8 } from "node:fs";
50743
50742
  import { access as access3, copyFile as copyFile2, mkdir as mkdir6, readdir as readdir2, readFile as readFile7, rm as rm2, writeFile as writeFile6 } from "node:fs/promises";
50743
+ import { createRequire as createRequire6 } from "node:module";
50744
50744
  import { homedir as getHomedir } from "node:os";
50745
50745
  import { dirname as dirname10, join as join41, resolve as resolve5 } from "node:path";
50746
50746
  import { fileURLToPath as fileURLToPath4 } from "node:url";
@@ -51596,6 +51596,102 @@ async function ensureCleoOsHub() {
51596
51596
  details: `pi-extensions: ${piResult.copied} created/${piResult.kept} kept, global-recipes: ${recipesResult.copied} created/${recipesResult.kept} kept`
51597
51597
  };
51598
51598
  }
51599
+ function resolveIdentitySourcePath() {
51600
+ const monorepoPath = join41(
51601
+ process.cwd(),
51602
+ "packages",
51603
+ "cleo-os",
51604
+ "starter-bundle",
51605
+ "CLEOOS-IDENTITY.md"
51606
+ );
51607
+ if (existsSync40(monorepoPath)) return monorepoPath;
51608
+ try {
51609
+ const require2 = createRequire6(import.meta.url);
51610
+ const pkgJson = require2.resolve("@cleocode/cleo-os/package.json");
51611
+ const pkgDir = pkgJson.replace(/\/package\.json$/, "");
51612
+ const installedPath = join41(pkgDir, "starter-bundle", "CLEOOS-IDENTITY.md");
51613
+ if (existsSync40(installedPath)) return installedPath;
51614
+ } catch {
51615
+ }
51616
+ return null;
51617
+ }
51618
+ async function ensureGlobalIdentity(forceRefresh = false) {
51619
+ const sourcePath = resolveIdentitySourcePath();
51620
+ if (!sourcePath) {
51621
+ return {
51622
+ action: "skipped",
51623
+ path: "",
51624
+ details: "CLEOOS-IDENTITY.md source not found in monorepo or installed package"
51625
+ };
51626
+ }
51627
+ const cleoHome = getCleoHome();
51628
+ const dst = join41(cleoHome, "CLEOOS-IDENTITY.md");
51629
+ try {
51630
+ await mkdir6(cleoHome, { recursive: true });
51631
+ } catch (err) {
51632
+ return {
51633
+ action: "skipped",
51634
+ path: dst,
51635
+ details: `Failed to create global cleo home: ${err instanceof Error ? err.message : String(err)}`
51636
+ };
51637
+ }
51638
+ if (existsSync40(dst) && !forceRefresh) {
51639
+ return { action: "skipped", path: dst, details: "identity already present" };
51640
+ }
51641
+ const existedBefore = existsSync40(dst);
51642
+ try {
51643
+ const content = readFileSync23(sourcePath, "utf-8");
51644
+ await writeFile6(dst, content);
51645
+ return {
51646
+ action: existedBefore ? "repaired" : "created",
51647
+ path: dst,
51648
+ details: `from ${sourcePath}`
51649
+ };
51650
+ } catch (err) {
51651
+ return {
51652
+ action: "skipped",
51653
+ path: dst,
51654
+ details: `Failed to write identity: ${err instanceof Error ? err.message : String(err)}`
51655
+ };
51656
+ }
51657
+ }
51658
+ function checkGlobalIdentity() {
51659
+ const cleoHome = getCleoHome();
51660
+ const identityPath = join41(cleoHome, "CLEOOS-IDENTITY.md");
51661
+ if (!existsSync40(identityPath)) {
51662
+ return {
51663
+ id: "global_identity",
51664
+ category: "global",
51665
+ status: "failed",
51666
+ message: "Global CLEOOS-IDENTITY.md not found \u2014 orchestrator persona missing",
51667
+ details: { path: identityPath, exists: false },
51668
+ fix: "cleo upgrade (auto-deploys identity)"
51669
+ };
51670
+ }
51671
+ let size = 0;
51672
+ try {
51673
+ size = statSync8(identityPath).size;
51674
+ } catch {
51675
+ }
51676
+ if (size === 0) {
51677
+ return {
51678
+ id: "global_identity",
51679
+ category: "global",
51680
+ status: "failed",
51681
+ message: "Global CLEOOS-IDENTITY.md exists but is empty",
51682
+ details: { path: identityPath, exists: true, size: 0 },
51683
+ fix: "cleo upgrade --refresh-identity"
51684
+ };
51685
+ }
51686
+ return {
51687
+ id: "global_identity",
51688
+ category: "global",
51689
+ status: "passed",
51690
+ message: "Global CLEOOS-IDENTITY.md present",
51691
+ details: { path: identityPath, exists: true, size },
51692
+ fix: ""
51693
+ };
51694
+ }
51599
51695
  function checkGlobalHome() {
51600
51696
  const cleoHome = getCleoHome();
51601
51697
  if (!existsSync40(cleoHome)) {
@@ -55695,7 +55791,7 @@ __export(parser_exports, {
55695
55791
  parseFile: () => parseFile2
55696
55792
  });
55697
55793
  import { readFileSync as readFileSync64 } from "node:fs";
55698
- import { createRequire as createRequire7 } from "node:module";
55794
+ import { createRequire as createRequire8 } from "node:module";
55699
55795
  import { relative as relative7 } from "node:path";
55700
55796
  function tryRequire(id) {
55701
55797
  try {
@@ -55896,7 +55992,7 @@ var init_parser3 = __esm({
55896
55992
  "packages/core/src/code/parser.ts"() {
55897
55993
  "use strict";
55898
55994
  init_tree_sitter_languages();
55899
- _require7 = createRequire7(import.meta.url);
55995
+ _require7 = createRequire8(import.meta.url);
55900
55996
  _ParserClass = null;
55901
55997
  _QueryClass = null;
55902
55998
  _parserInstance = null;
@@ -56002,7 +56098,7 @@ __export(dependencies_exports, {
56002
56098
  getDependencySpecs: () => getDependencySpecs
56003
56099
  });
56004
56100
  import { execFileSync as execFileSync10 } from "node:child_process";
56005
- import { createRequire as createRequire8 } from "node:module";
56101
+ import { createRequire as createRequire9 } from "node:module";
56006
56102
  import { dirname as dirname19 } from "node:path";
56007
56103
  import { fileURLToPath as fileURLToPath5 } from "node:url";
56008
56104
  function tryExec(cmd, args, timeoutMs = 3e3) {
@@ -56275,7 +56371,7 @@ var init_dependencies = __esm({
56275
56371
  "packages/core/src/system/dependencies.ts"() {
56276
56372
  "use strict";
56277
56373
  init_platform();
56278
- _require8 = createRequire8(import.meta.url);
56374
+ _require8 = createRequire9(import.meta.url);
56279
56375
  _dirname = dirname19(fileURLToPath5(import.meta.url));
56280
56376
  DEPENDENCY_SPECS = [
56281
56377
  // ── Required ────────────────────────────────────────────────────────────
@@ -57578,8 +57674,8 @@ import { platform as platform4 } from "node:os";
57578
57674
  import { basename as basename17, dirname as dirname23, join as join107 } from "node:path";
57579
57675
  async function resolveSeedAgentsDir() {
57580
57676
  try {
57581
- const { createRequire: createRequire15 } = await import("node:module");
57582
- const req = createRequire15(import.meta.url);
57677
+ const { createRequire: createRequire16 } = await import("node:module");
57678
+ const req = createRequire16(import.meta.url);
57583
57679
  const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
57584
57680
  const agentsPkgRoot = dirname23(agentsPkgMain);
57585
57681
  const candidate = join107(agentsPkgRoot, "seed-agents");
@@ -57606,8 +57702,8 @@ async function resolveSeedAgentsDir() {
57606
57702
  async function initAgentDefinition(created, warnings) {
57607
57703
  let agentSourceDir = null;
57608
57704
  try {
57609
- const { createRequire: createRequire15 } = await import("node:module");
57610
- const req = createRequire15(import.meta.url);
57705
+ const { createRequire: createRequire16 } = await import("node:module");
57706
+ const req = createRequire16(import.meta.url);
57611
57707
  const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
57612
57708
  const agentsPkgRoot = dirname23(agentsPkgMain);
57613
57709
  const candidate = join107(agentsPkgRoot, "cleo-subagent");
@@ -57673,8 +57769,8 @@ async function initCoreSkills(created, warnings) {
57673
57769
  const packageRoot = getPackageRoot();
57674
57770
  let ctSkillsRoot = null;
57675
57771
  try {
57676
- const { createRequire: createRequire15 } = await import("node:module");
57677
- const req = createRequire15(import.meta.url);
57772
+ const { createRequire: createRequire16 } = await import("node:module");
57773
+ const req = createRequire16(import.meta.url);
57678
57774
  const skillsPkgMain = req.resolve("@cleocode/skills/package.json");
57679
57775
  const skillsPkgRoot = dirname23(skillsPkgMain);
57680
57776
  if (existsSync108(join107(skillsPkgRoot, "skills.json"))) {
@@ -58182,8 +58278,8 @@ async function deployStarterBundle(cleoDir, created, warnings) {
58182
58278
  if (hasCantFiles) return;
58183
58279
  let starterBundleSrc = null;
58184
58280
  try {
58185
- const { createRequire: createRequire15 } = await import("node:module");
58186
- const req = createRequire15(import.meta.url);
58281
+ const { createRequire: createRequire16 } = await import("node:module");
58282
+ const req = createRequire16(import.meta.url);
58187
58283
  const cleoOsPkgMain = req.resolve("@cleocode/cleo-os/package.json");
58188
58284
  const cleoOsPkgRoot = dirname23(cleoOsPkgMain);
58189
58285
  const candidate = join107(cleoOsPkgRoot, "starter-bundle");
@@ -58223,20 +58319,20 @@ async function deployStarterBundle(cleoDir, created, warnings) {
58223
58319
  }
58224
58320
  }
58225
58321
  }
58226
- const identitySrc = join107(starterBundleSrc, "CLEOOS-IDENTITY.md");
58227
- const identityDst = join107(cleoDir, "CLEOOS-IDENTITY.md");
58228
- if (existsSync108(identitySrc) && !existsSync108(identityDst)) {
58229
- await copyFile4(identitySrc, identityDst);
58230
- }
58231
58322
  try {
58232
- const { getCleoHome: getCleoHome2 } = await Promise.resolve().then(() => (init_paths(), paths_exports));
58233
- const globalIdentityDst = join107(getCleoHome2(), "CLEOOS-IDENTITY.md");
58234
- if (existsSync108(identitySrc) && !existsSync108(globalIdentityDst)) {
58235
- await copyFile4(identitySrc, globalIdentityDst);
58323
+ const { ensureGlobalIdentity: ensureGlobalIdentity2 } = await Promise.resolve().then(() => (init_scaffold(), scaffold_exports));
58324
+ const identityResult = await ensureGlobalIdentity2();
58325
+ if (identityResult.action === "created") {
58326
+ created.push(`identity: ${identityResult.path}`);
58327
+ } else if (identityResult.action === "skipped" && identityResult.details) {
58328
+ warnings.push(`identity skipped: ${identityResult.details}`);
58236
58329
  }
58237
- } catch {
58330
+ } catch (err) {
58331
+ warnings.push(`identity deploy failed: ${err instanceof Error ? err.message : String(err)}`);
58238
58332
  }
58239
- created.push("starter-bundle: team + agent .cant files + identity deployed to .cleo/");
58333
+ created.push(
58334
+ "starter-bundle: team + agent .cant files deployed to .cleo/ (identity at global XDG)"
58335
+ );
58240
58336
  }
58241
58337
  var DIR_SYMLINK_TYPE2;
58242
58338
  var init_init = __esm({
@@ -75836,8 +75932,8 @@ init_agent_outputs();
75836
75932
  // packages/core/src/migration/checksum.ts
75837
75933
  import { createHash as createHash8 } from "node:crypto";
75838
75934
  import { readFileSync as readFileSync34 } from "node:fs";
75839
- import { createRequire as createRequire6 } from "node:module";
75840
- var _require6 = createRequire6(import.meta.url);
75935
+ import { createRequire as createRequire7 } from "node:module";
75936
+ var _require6 = createRequire7(import.meta.url);
75841
75937
  var { DatabaseSync: DatabaseSync4 } = _require6("node:sqlite");
75842
75938
  async function computeChecksum2(filePath) {
75843
75939
  const content = readFileSync34(filePath);
@@ -88188,7 +88284,7 @@ init_schema_management();
88188
88284
  init_data_accessor();
88189
88285
  import { execFileSync as execFileSync11 } from "node:child_process";
88190
88286
  import { existsSync as existsSync92, readFileSync as readFileSync65, statSync as statSync19 } from "node:fs";
88191
- import { createRequire as createRequire9 } from "node:module";
88287
+ import { createRequire as createRequire10 } from "node:module";
88192
88288
  import { join as join93 } from "node:path";
88193
88289
 
88194
88290
  // packages/core/src/validation/doctor/checks.ts
@@ -89002,7 +89098,7 @@ function calculateHealthStatus(checks) {
89002
89098
 
89003
89099
  // packages/core/src/system/health.ts
89004
89100
  init_dependencies();
89005
- var _require9 = createRequire9(import.meta.url);
89101
+ var _require9 = createRequire10(import.meta.url);
89006
89102
  var databaseSyncCtor = (() => {
89007
89103
  try {
89008
89104
  return _require9("node:sqlite").DatabaseSync;
@@ -89550,6 +89646,7 @@ async function coreDoctorReport(projectRoot) {
89550
89646
  });
89551
89647
  checks.push(mapCheckResult(checkGlobalHome()));
89552
89648
  checks.push(mapCheckResult(checkGlobalTemplates()));
89649
+ checks.push(mapCheckResult(checkGlobalIdentity()));
89553
89650
  checks.push(mapSchemaCheckResult(checkGlobalSchemas()));
89554
89651
  checks.push(mapCheckResult(checkLogDir(projectRoot)));
89555
89652
  const hookResults = await checkGitHooks(projectRoot);
@@ -97816,11 +97913,11 @@ init_paths();
97816
97913
  init_brain_sqlite();
97817
97914
  init_brain_search();
97818
97915
  import { existsSync as existsSync111 } from "node:fs";
97819
- import { createRequire as createRequire10 } from "node:module";
97916
+ import { createRequire as createRequire11 } from "node:module";
97820
97917
  function typedAll3(db, sql16) {
97821
97918
  return db.prepare(sql16).all();
97822
97919
  }
97823
- var _require10 = createRequire10(import.meta.url);
97920
+ var _require10 = createRequire11(import.meta.url);
97824
97921
  var { DatabaseSync: DatabaseSync5 } = _require10("node:sqlite");
97825
97922
  var VALID_OBSERVATION_TYPES = /* @__PURE__ */ new Set([
97826
97923
  "discovery",
@@ -100391,7 +100488,7 @@ init_backup();
100391
100488
  // packages/core/src/store/backup-pack.ts
100392
100489
  import crypto5 from "node:crypto";
100393
100490
  import fs4 from "node:fs";
100394
- import { createRequire as createRequire11 } from "node:module";
100491
+ import { createRequire as createRequire12 } from "node:module";
100395
100492
  import os2 from "node:os";
100396
100493
  import path4 from "node:path";
100397
100494
 
@@ -103397,7 +103494,7 @@ function assertT310Ready(projectRoot) {
103397
103494
  }
103398
103495
 
103399
103496
  // packages/core/src/store/backup-pack.ts
103400
- var _require11 = createRequire11(import.meta.url);
103497
+ var _require11 = createRequire12(import.meta.url);
103401
103498
  var { DatabaseSync: DatabaseSync6 } = _require11("node:sqlite");
103402
103499
  function resolveContractsSchemasDir() {
103403
103500
  const candidates = [
@@ -103896,9 +103993,9 @@ init_conduit_sqlite();
103896
103993
  init_global_salt();
103897
103994
  init_signaldock_sqlite();
103898
103995
  import { existsSync as existsSync117, mkdirSync as mkdirSync27, renameSync as renameSync9, unlinkSync as unlinkSync9 } from "node:fs";
103899
- import { createRequire as createRequire12 } from "node:module";
103996
+ import { createRequire as createRequire13 } from "node:module";
103900
103997
  import { join as join114 } from "node:path";
103901
- var _require12 = createRequire12(import.meta.url);
103998
+ var _require12 = createRequire13(import.meta.url);
103902
103999
  var { DatabaseSync: DatabaseSync7 } = _require12("node:sqlite");
103903
104000
  var PROJECT_TIER_TABLES = [
103904
104001
  "messages",
@@ -106058,6 +106155,16 @@ async function runUpgrade(options = {}) {
106058
106155
  }
106059
106156
  } catch {
106060
106157
  }
106158
+ try {
106159
+ const { ensureGlobalIdentity: ensureGlobalIdentity2 } = await Promise.resolve().then(() => (init_scaffold(), scaffold_exports));
106160
+ const identityResult = await ensureGlobalIdentity2();
106161
+ actions.push({
106162
+ action: "global_identity",
106163
+ status: identityResult.action === "created" || identityResult.action === "repaired" ? "applied" : "skipped",
106164
+ details: `${identityResult.path} (${identityResult.details ?? identityResult.action})`
106165
+ });
106166
+ } catch {
106167
+ }
106061
106168
  try {
106062
106169
  const skillsCreated = [];
106063
106170
  const skillsWarnings = [];
@@ -108699,11 +108806,11 @@ init_tasks_schema();
108699
108806
  var import__ = __toESM(require__(), 1);
108700
108807
  import crypto6 from "node:crypto";
108701
108808
  import fs6 from "node:fs";
108702
- import { createRequire as createRequire13 } from "node:module";
108809
+ import { createRequire as createRequire14 } from "node:module";
108703
108810
  import os3 from "node:os";
108704
108811
  import path6 from "node:path";
108705
108812
  import { default as addFormatsImport2 } from "ajv-formats";
108706
- var _require13 = createRequire13(import.meta.url);
108813
+ var _require13 = createRequire14(import.meta.url);
108707
108814
  var { DatabaseSync: DatabaseSync8 } = _require13("node:sqlite");
108708
108815
  var ajv2020Mod = import__.default;
108709
108816
  var Ajv2020 = typeof ajv2020Mod.default === "function" ? ajv2020Mod.default : import__.default;
@@ -110204,7 +110311,7 @@ async function decrypt(ciphertext, projectPath) {
110204
110311
  init_paths();
110205
110312
  import { randomBytes as randomBytes17 } from "node:crypto";
110206
110313
  import { existsSync as existsSync127, mkdirSync as mkdirSync32, readFileSync as readFileSync93, statSync as statSync21, writeFileSync as writeFileSync23 } from "node:fs";
110207
- import { createRequire as createRequire14 } from "node:module";
110314
+ import { createRequire as createRequire15 } from "node:module";
110208
110315
  import { join as join122 } from "node:path";
110209
110316
 
110210
110317
  // packages/core/src/store/api-key-kdf.ts
@@ -110231,7 +110338,7 @@ function deriveApiKey(input) {
110231
110338
  init_conduit_sqlite();
110232
110339
  init_global_salt();
110233
110340
  init_signaldock_sqlite();
110234
- var _require14 = createRequire14(import.meta.url);
110341
+ var _require14 = createRequire15(import.meta.url);
110235
110342
  var { DatabaseSync: DatabaseSync9 } = _require14("node:sqlite");
110236
110343
  var MACHINE_KEY_LENGTH = 32;
110237
110344
  function readMachineKey() {