@cleocode/core 2026.3.49 → 2026.3.51

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 CHANGED
@@ -1783,7 +1783,7 @@ var init_sql = __esm({
1783
1783
  return new SQL([new StringChunk(str)]);
1784
1784
  }
1785
1785
  _sql.raw = raw;
1786
- function join103(chunks, separator) {
1786
+ function join104(chunks, separator) {
1787
1787
  const result = [];
1788
1788
  for (const [i, chunk] of chunks.entries()) {
1789
1789
  if (i > 0 && separator !== void 0) result.push(separator);
@@ -1791,7 +1791,7 @@ var init_sql = __esm({
1791
1791
  }
1792
1792
  return new SQL(result);
1793
1793
  }
1794
- _sql.join = join103;
1794
+ _sql.join = join104;
1795
1795
  function identifier(value) {
1796
1796
  return new Name(value);
1797
1797
  }
@@ -6565,7 +6565,7 @@ var init_select2 = __esm({
6565
6565
  const baseTableName = this.tableName;
6566
6566
  const tableName = getTableLikeName(table);
6567
6567
  for (const item of extractUsedTable(table)) this.usedTables.add(item);
6568
- if (typeof tableName === "string" && this.config.joins?.some((join103) => join103.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
6568
+ if (typeof tableName === "string" && this.config.joins?.some((join104) => join104.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
6569
6569
  if (!this.isPartialSelect) {
6570
6570
  if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
6571
6571
  if (typeof tableName === "string" && !is(table, SQL)) {
@@ -7850,7 +7850,7 @@ var init_dialect = __esm({
7850
7850
  if (!joins2) return;
7851
7851
  const withEntries = Object.entries(joins2).filter(([_, v]) => v);
7852
7852
  if (!withEntries.length) return;
7853
- return sql.join(withEntries.map(([k, join103]) => {
7853
+ return sql.join(withEntries.map(([k, join104]) => {
7854
7854
  const relation = tableConfig.relations[k];
7855
7855
  const isSingle2 = is(relation, One3);
7856
7856
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -7861,7 +7861,7 @@ var init_dialect = __esm({
7861
7861
  table: targetTable,
7862
7862
  mode: isSingle2 ? "first" : "many",
7863
7863
  schema,
7864
- queryConfig: join103,
7864
+ queryConfig: join104,
7865
7865
  tableConfig: schema[relation.targetTableName],
7866
7866
  relationWhere: filter,
7867
7867
  isNested: true,
@@ -7875,7 +7875,7 @@ var init_dialect = __esm({
7875
7875
  key: k,
7876
7876
  selection: innerQuery.selection,
7877
7877
  isArray: !isSingle2,
7878
- isOptional: (relation.optional ?? false) || join103 !== true && !!join103.where
7878
+ isOptional: (relation.optional ?? false) || join104 !== true && !!join104.where
7879
7879
  });
7880
7880
  const jsonColumns = sql.join(innerQuery.selection.map((s) => {
7881
7881
  return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb2}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
@@ -8274,7 +8274,7 @@ var init_update = __esm({
8274
8274
  createJoin(joinType) {
8275
8275
  return ((table, on) => {
8276
8276
  const tableName = getTableLikeName(table);
8277
- if (typeof tableName === "string" && this.config.joins.some((join103) => join103.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
8277
+ if (typeof tableName === "string" && this.config.joins.some((join104) => join104.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
8278
8278
  if (typeof on === "function") {
8279
8279
  const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
8280
8280
  on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
@@ -20966,6 +20966,225 @@ var init_decisions2 = __esm({
20966
20966
  }
20967
20967
  });
20968
20968
 
20969
+ // packages/core/src/migration/agent-outputs.ts
20970
+ import {
20971
+ copyFileSync as copyFileSync5,
20972
+ existsSync as existsSync45,
20973
+ mkdirSync as mkdirSync10,
20974
+ readdirSync as readdirSync20,
20975
+ readFileSync as readFileSync30,
20976
+ rmSync,
20977
+ statSync as statSync11,
20978
+ writeFileSync as writeFileSync4
20979
+ } from "node:fs";
20980
+ import { join as join50 } from "node:path";
20981
+ function detectLegacyAgentOutputs(projectRoot, cleoDir) {
20982
+ const hasResearchOutputs = existsSync45(join50(projectRoot, "claudedocs", "research-outputs"));
20983
+ const hasLegacyAgentOutputs = existsSync45(join50(projectRoot, "claudedocs", "agent-outputs"));
20984
+ const hasCanonical = existsSync45(join50(cleoDir, "agent-outputs"));
20985
+ const legacyPaths = [];
20986
+ if (hasResearchOutputs) legacyPaths.push("claudedocs/research-outputs/");
20987
+ if (hasLegacyAgentOutputs) legacyPaths.push("claudedocs/agent-outputs/");
20988
+ return {
20989
+ hasLegacy: hasResearchOutputs || hasLegacyAgentOutputs,
20990
+ hasResearchOutputs,
20991
+ hasLegacyAgentOutputs,
20992
+ hasCanonical,
20993
+ legacyPaths
20994
+ };
20995
+ }
20996
+ function migrateAgentOutputs(projectRoot, cleoDir) {
20997
+ const detection = detectLegacyAgentOutputs(projectRoot, cleoDir);
20998
+ if (!detection.hasLegacy) {
20999
+ return {
21000
+ migrated: false,
21001
+ filesCopied: 0,
21002
+ manifestEntries: 0,
21003
+ removed: [],
21004
+ summary: "No legacy output directories found"
21005
+ };
21006
+ }
21007
+ const newDir = join50(cleoDir, "agent-outputs");
21008
+ const hadCanonical = detection.hasCanonical;
21009
+ mkdirSync10(newDir, { recursive: true });
21010
+ let totalCopied = 0;
21011
+ const mergedManifestLines = [];
21012
+ const copiedFiles = /* @__PURE__ */ new Set();
21013
+ const legacySources = [
21014
+ {
21015
+ path: join50(projectRoot, "claudedocs", "research-outputs"),
21016
+ exists: detection.hasResearchOutputs
21017
+ },
21018
+ {
21019
+ path: join50(projectRoot, "claudedocs", "agent-outputs"),
21020
+ exists: detection.hasLegacyAgentOutputs
21021
+ }
21022
+ ];
21023
+ for (const source of legacySources) {
21024
+ if (!source.exists) continue;
21025
+ totalCopied += copyDirContents(source.path, newDir, mergedManifestLines, copiedFiles);
21026
+ }
21027
+ const manifestEntries2 = mergeManifests(newDir, hadCanonical, mergedManifestLines);
21028
+ updateConfigPaths(cleoDir);
21029
+ const removed = removeLegacyDirs(projectRoot, detection);
21030
+ const parts = [`Migrated ${totalCopied} files \u2192 ${CANONICAL_DIR}/`];
21031
+ if (manifestEntries2 > 0) parts.push(`merged ${manifestEntries2} manifest entries`);
21032
+ if (removed.length > 0) parts.push(`removed: ${removed.join(", ")}`);
21033
+ return {
21034
+ migrated: true,
21035
+ filesCopied: totalCopied,
21036
+ manifestEntries: manifestEntries2,
21037
+ removed,
21038
+ summary: parts.join("; ")
21039
+ };
21040
+ }
21041
+ function copyDirContents(srcDir, dstDir, manifestLines, copiedFiles) {
21042
+ let count2 = 0;
21043
+ const entries = readdirSync20(srcDir);
21044
+ for (const entry of entries) {
21045
+ if (entry === "MANIFEST.jsonl") {
21046
+ collectManifestLines(join50(srcDir, entry), manifestLines);
21047
+ continue;
21048
+ }
21049
+ const srcPath = join50(srcDir, entry);
21050
+ const dstPath = join50(dstDir, entry);
21051
+ try {
21052
+ const st = statSync11(srcPath);
21053
+ if (st.isDirectory()) {
21054
+ mkdirSync10(dstPath, { recursive: true });
21055
+ for (const sf of readdirSync20(srcPath)) {
21056
+ if (!copiedFiles.has(sf)) {
21057
+ try {
21058
+ copyFileSync5(join50(srcPath, sf), join50(dstPath, sf));
21059
+ copiedFiles.add(sf);
21060
+ count2++;
21061
+ } catch {
21062
+ }
21063
+ }
21064
+ }
21065
+ } else if (!copiedFiles.has(entry)) {
21066
+ copyFileSync5(srcPath, dstPath);
21067
+ copiedFiles.add(entry);
21068
+ count2++;
21069
+ }
21070
+ } catch {
21071
+ }
21072
+ }
21073
+ return count2;
21074
+ }
21075
+ function collectManifestLines(manifestPath, out) {
21076
+ try {
21077
+ const content = readFileSync30(manifestPath, "utf-8");
21078
+ for (const line2 of content.split("\n")) {
21079
+ if (!line2.trim()) continue;
21080
+ let rewritten = line2;
21081
+ for (const [pattern, replacement] of MANIFEST_PATH_REWRITES) {
21082
+ rewritten = rewritten.replace(pattern, replacement);
21083
+ }
21084
+ out.push(rewritten);
21085
+ }
21086
+ } catch {
21087
+ }
21088
+ }
21089
+ function mergeManifests(newDir, hadCanonical, legacyLines) {
21090
+ const manifestPath = join50(newDir, "MANIFEST.jsonl");
21091
+ const existingLines = [];
21092
+ if (hadCanonical && existsSync45(manifestPath)) {
21093
+ try {
21094
+ const existing = readFileSync30(manifestPath, "utf-8");
21095
+ for (const line2 of existing.split("\n")) {
21096
+ if (line2.trim()) existingLines.push(line2);
21097
+ }
21098
+ } catch {
21099
+ }
21100
+ }
21101
+ const seenIds = /* @__PURE__ */ new Set();
21102
+ const finalLines = [];
21103
+ for (const line2 of existingLines) {
21104
+ try {
21105
+ const p = JSON.parse(line2);
21106
+ if (p.id) seenIds.add(p.id);
21107
+ } catch {
21108
+ }
21109
+ finalLines.push(line2);
21110
+ }
21111
+ for (const line2 of legacyLines) {
21112
+ try {
21113
+ const p = JSON.parse(line2);
21114
+ if (p.id && seenIds.has(p.id)) continue;
21115
+ if (p.id) seenIds.add(p.id);
21116
+ } catch {
21117
+ }
21118
+ finalLines.push(line2);
21119
+ }
21120
+ if (finalLines.length > 0) {
21121
+ writeFileSync4(manifestPath, finalLines.join("\n") + "\n");
21122
+ }
21123
+ return finalLines.length;
21124
+ }
21125
+ function updateConfigPaths(cleoDir) {
21126
+ const configPath = join50(cleoDir, "config.json");
21127
+ if (!existsSync45(configPath)) return;
21128
+ try {
21129
+ const config2 = JSON.parse(readFileSync30(configPath, "utf-8"));
21130
+ const currentDir = config2.agentOutputs?.directory ?? config2.agentOutputs ?? config2.research?.outputDir;
21131
+ if (currentDir && currentDir !== CANONICAL_DIR) {
21132
+ if (typeof config2.agentOutputs === "object") {
21133
+ config2.agentOutputs.directory = CANONICAL_DIR;
21134
+ } else {
21135
+ config2.agentOutputs = { directory: CANONICAL_DIR };
21136
+ }
21137
+ if (config2.research?.outputDir) {
21138
+ delete config2.research.outputDir;
21139
+ if (Object.keys(config2.research).length === 0) {
21140
+ delete config2.research;
21141
+ }
21142
+ }
21143
+ writeFileSync4(configPath, JSON.stringify(config2, null, 2));
21144
+ }
21145
+ } catch {
21146
+ }
21147
+ }
21148
+ function removeLegacyDirs(projectRoot, detection) {
21149
+ const removed = [];
21150
+ if (detection.hasResearchOutputs) {
21151
+ try {
21152
+ rmSync(join50(projectRoot, "claudedocs", "research-outputs"), { recursive: true, force: true });
21153
+ removed.push("claudedocs/research-outputs/");
21154
+ } catch {
21155
+ }
21156
+ }
21157
+ if (detection.hasLegacyAgentOutputs) {
21158
+ try {
21159
+ rmSync(join50(projectRoot, "claudedocs", "agent-outputs"), { recursive: true, force: true });
21160
+ removed.push("claudedocs/agent-outputs/");
21161
+ } catch {
21162
+ }
21163
+ }
21164
+ const claudedocsDir = join50(projectRoot, "claudedocs");
21165
+ if (existsSync45(claudedocsDir)) {
21166
+ try {
21167
+ if (readdirSync20(claudedocsDir).length === 0) {
21168
+ rmSync(claudedocsDir, { recursive: true, force: true });
21169
+ removed.push("claudedocs/ (empty)");
21170
+ }
21171
+ } catch {
21172
+ }
21173
+ }
21174
+ return removed;
21175
+ }
21176
+ var CANONICAL_DIR, MANIFEST_PATH_REWRITES;
21177
+ var init_agent_outputs = __esm({
21178
+ "packages/core/src/migration/agent-outputs.ts"() {
21179
+ "use strict";
21180
+ CANONICAL_DIR = ".cleo/agent-outputs";
21181
+ MANIFEST_PATH_REWRITES = [
21182
+ [/claudedocs\/research-outputs\//g, `${CANONICAL_DIR}/`],
21183
+ [/claudedocs\/agent-outputs\//g, `${CANONICAL_DIR}/`]
21184
+ ];
21185
+ }
21186
+ });
21187
+
20969
21188
  // packages/core/src/nexus/migrate-json-to-sqlite.ts
20970
21189
  var migrate_json_to_sqlite_exports = {};
20971
21190
  __export(migrate_json_to_sqlite_exports, {
@@ -21202,10 +21421,10 @@ async function readProjectMeta(projectPath) {
21202
21421
  }
21203
21422
  async function readProjectId(projectPath) {
21204
21423
  try {
21205
- const { readFileSync: readFileSync76, existsSync: existsSync102 } = await import("node:fs");
21424
+ const { readFileSync: readFileSync77, existsSync: existsSync103 } = await import("node:fs");
21206
21425
  const infoPath = join57(projectPath, ".cleo", "project-info.json");
21207
- if (!existsSync102(infoPath)) return "";
21208
- const data = JSON.parse(readFileSync76(infoPath, "utf-8"));
21426
+ if (!existsSync103(infoPath)) return "";
21427
+ const data = JSON.parse(readFileSync77(infoPath, "utf-8"));
21209
21428
  return typeof data.projectId === "string" ? data.projectId : "";
21210
21429
  } catch {
21211
21430
  return "";
@@ -24005,6 +24224,539 @@ var init_hooks = __esm({
24005
24224
  }
24006
24225
  });
24007
24226
 
24227
+ // packages/core/src/init.ts
24228
+ var init_exports = {};
24229
+ __export(init_exports, {
24230
+ ensureInitialized: () => ensureInitialized,
24231
+ getVersion: () => getVersion2,
24232
+ initAgentDefinition: () => initAgentDefinition,
24233
+ initCoreSkills: () => initCoreSkills,
24234
+ initMcpServer: () => initMcpServer,
24235
+ initNexusRegistration: () => initNexusRegistration,
24236
+ initProject: () => initProject,
24237
+ installGitHubTemplates: () => installGitHubTemplates,
24238
+ isAutoInitEnabled: () => isAutoInitEnabled,
24239
+ updateDocs: () => updateDocs
24240
+ });
24241
+ import { existsSync as existsSync99, readdirSync as readdirSync33, readFileSync as readFileSync73 } from "node:fs";
24242
+ import { copyFile as copyFile3, lstat, mkdir as mkdir16, readFile as readFile17, symlink, unlink as unlink4, writeFile as writeFile11 } from "node:fs/promises";
24243
+ import { platform as platform4 } from "node:os";
24244
+ import { basename as basename17, dirname as dirname19, join as join100 } from "node:path";
24245
+ async function initAgentDefinition(created, warnings) {
24246
+ let agentSourceDir = null;
24247
+ try {
24248
+ const { createRequire: createRequire5 } = await import("node:module");
24249
+ const req = createRequire5(import.meta.url);
24250
+ const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
24251
+ const agentsPkgRoot = dirname19(agentsPkgMain);
24252
+ const candidate = join100(agentsPkgRoot, "cleo-subagent");
24253
+ if (existsSync99(candidate)) {
24254
+ agentSourceDir = candidate;
24255
+ }
24256
+ } catch {
24257
+ }
24258
+ if (!agentSourceDir) {
24259
+ const packageRoot = getPackageRoot();
24260
+ const bundled = join100(packageRoot, "agents", "cleo-subagent");
24261
+ if (existsSync99(bundled)) {
24262
+ agentSourceDir = bundled;
24263
+ }
24264
+ }
24265
+ if (!agentSourceDir) {
24266
+ warnings.push("agents/cleo-subagent/ not found in package, skipping agent definition install");
24267
+ return;
24268
+ }
24269
+ const globalAgentsDir = join100(getAgentsHome(), "agents", "cleo-subagent");
24270
+ await mkdir16(dirname19(globalAgentsDir), { recursive: true });
24271
+ try {
24272
+ try {
24273
+ const stat2 = await lstat(globalAgentsDir);
24274
+ if (stat2.isSymbolicLink()) {
24275
+ const { readlink } = await import("node:fs/promises");
24276
+ const currentTarget = await readlink(globalAgentsDir);
24277
+ if (currentTarget === agentSourceDir) {
24278
+ return;
24279
+ }
24280
+ await unlink4(globalAgentsDir);
24281
+ } else if (stat2.isDirectory()) {
24282
+ return;
24283
+ }
24284
+ } catch {
24285
+ }
24286
+ await symlink(agentSourceDir, globalAgentsDir, DIR_SYMLINK_TYPE2);
24287
+ created.push("agent: cleo-subagent (symlinked)");
24288
+ } catch (_err) {
24289
+ try {
24290
+ await mkdir16(globalAgentsDir, { recursive: true });
24291
+ const files = readdirSync33(agentSourceDir);
24292
+ for (const file2 of files) {
24293
+ await copyFile3(join100(agentSourceDir, file2), join100(globalAgentsDir, file2));
24294
+ }
24295
+ created.push("agent: cleo-subagent (copied)");
24296
+ } catch (copyErr) {
24297
+ warnings.push(
24298
+ `Agent definition install: ${copyErr instanceof Error ? copyErr.message : String(copyErr)}`
24299
+ );
24300
+ }
24301
+ }
24302
+ }
24303
+ async function initMcpServer(projectRoot, created, warnings) {
24304
+ try {
24305
+ const { detectEnvMode: detectEnvMode2, generateMcpServerEntry: generateMcpServerEntry2, getMcpServerName: getMcpServerName2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
24306
+ const { getInstalledProviders: getInstalledProviders3, installMcpServerToAll } = await import("@cleocode/caamp");
24307
+ const env = detectEnvMode2();
24308
+ const serverEntry = generateMcpServerEntry2(env);
24309
+ const serverName = getMcpServerName2(env);
24310
+ const providers = getInstalledProviders3();
24311
+ if (providers.length === 0) {
24312
+ return;
24313
+ }
24314
+ const results = await installMcpServerToAll(
24315
+ providers,
24316
+ serverName,
24317
+ serverEntry,
24318
+ "global",
24319
+ projectRoot
24320
+ );
24321
+ const successes = results.filter((r) => r.success);
24322
+ const failures = results.filter((r) => !r.success);
24323
+ if (successes.length > 0) {
24324
+ created.push(`MCP server: ${successes.map((r) => r.provider.id).join(", ")}`);
24325
+ }
24326
+ for (const f of failures) {
24327
+ if (f.error) {
24328
+ warnings.push(`MCP install to ${f.provider.id}: ${f.error}`);
24329
+ }
24330
+ }
24331
+ } catch (err) {
24332
+ warnings.push(`MCP server install: ${err instanceof Error ? err.message : String(err)}`);
24333
+ }
24334
+ }
24335
+ async function initCoreSkills(created, warnings) {
24336
+ try {
24337
+ const { getInstalledProviders: getInstalledProviders3, installSkill: installSkill2, registerSkillLibraryFromPath } = await import("@cleocode/caamp");
24338
+ const providers = getInstalledProviders3();
24339
+ if (providers.length === 0) {
24340
+ return;
24341
+ }
24342
+ const packageRoot = getPackageRoot();
24343
+ let ctSkillsRoot = null;
24344
+ try {
24345
+ const { createRequire: createRequire5 } = await import("node:module");
24346
+ const req = createRequire5(import.meta.url);
24347
+ const skillsPkgMain = req.resolve("@cleocode/skills/package.json");
24348
+ const skillsPkgRoot = dirname19(skillsPkgMain);
24349
+ if (existsSync99(join100(skillsPkgRoot, "skills.json"))) {
24350
+ ctSkillsRoot = skillsPkgRoot;
24351
+ }
24352
+ } catch {
24353
+ }
24354
+ if (!ctSkillsRoot) {
24355
+ try {
24356
+ const bundledPath = join100(packageRoot, "packages", "skills");
24357
+ if (existsSync99(join100(bundledPath, "skills.json"))) {
24358
+ ctSkillsRoot = bundledPath;
24359
+ } else {
24360
+ const ctSkillsPath = join100(packageRoot, "node_modules", "@cleocode", "skills");
24361
+ if (existsSync99(join100(ctSkillsPath, "skills.json"))) {
24362
+ ctSkillsRoot = ctSkillsPath;
24363
+ }
24364
+ }
24365
+ } catch {
24366
+ }
24367
+ }
24368
+ if (!ctSkillsRoot) {
24369
+ warnings.push("skills package not found, skipping core skill installation");
24370
+ return;
24371
+ }
24372
+ try {
24373
+ registerSkillLibraryFromPath(ctSkillsRoot);
24374
+ } catch {
24375
+ warnings.push("Failed to register skill library with CAAMP");
24376
+ }
24377
+ const catalogPath = join100(ctSkillsRoot, "skills.json");
24378
+ const catalog3 = JSON.parse(readFileSync73(catalogPath, "utf-8"));
24379
+ const skills = catalog3.skills ?? [];
24380
+ const coreSkills = skills.filter((s) => s.tier <= 2);
24381
+ const installed = [];
24382
+ for (const skill of coreSkills) {
24383
+ const skillSourceDir = dirname19(join100(ctSkillsRoot, skill.path));
24384
+ if (!existsSync99(skillSourceDir)) {
24385
+ continue;
24386
+ }
24387
+ try {
24388
+ const result = await installSkill2(skillSourceDir, skill.name, providers, true);
24389
+ if (result.success) {
24390
+ installed.push(skill.name);
24391
+ }
24392
+ } catch {
24393
+ }
24394
+ }
24395
+ if (installed.length > 0) {
24396
+ created.push(`skills: ${installed.length} core skills installed`);
24397
+ }
24398
+ } catch (err) {
24399
+ warnings.push(`Core skill install: ${err instanceof Error ? err.message : String(err)}`);
24400
+ }
24401
+ }
24402
+ async function initNexusRegistration(projectRoot, created, warnings) {
24403
+ try {
24404
+ const { nexusReconcile: nexusReconcile2 } = await Promise.resolve().then(() => (init_registry3(), registry_exports3));
24405
+ const result = await nexusReconcile2(projectRoot);
24406
+ if (result.status === "auto_registered") {
24407
+ created.push("NEXUS registration (auto-registered new project)");
24408
+ } else if (result.status === "path_updated") {
24409
+ created.push(`NEXUS registration (path updated: ${result.oldPath} \u2192 ${result.newPath})`);
24410
+ } else if (result.status === "ok") {
24411
+ created.push("NEXUS registration (project verified and active)");
24412
+ }
24413
+ } catch (err) {
24414
+ const errStr = String(err);
24415
+ if (errStr.includes("NEXUS_PROJECT_EXISTS")) {
24416
+ warnings.push("NEXUS registration: Project already registered");
24417
+ } else if (errStr.includes("NEXUS_REGISTRY_CORRUPT")) {
24418
+ warnings.push(
24419
+ `NEXUS registration: Identity conflict - ${err instanceof Error ? err.message : errStr}. Run 'cleo nexus unregister' and re-register.`
24420
+ );
24421
+ } else {
24422
+ warnings.push(`NEXUS registration: ${err instanceof Error ? err.message : errStr}`);
24423
+ }
24424
+ }
24425
+ }
24426
+ async function installGitHubTemplates(projectRoot, created, skipped) {
24427
+ if (!existsSync99(join100(projectRoot, ".git"))) {
24428
+ return;
24429
+ }
24430
+ const githubDir = join100(projectRoot, ".github");
24431
+ const issueTemplateDir = join100(githubDir, "ISSUE_TEMPLATE");
24432
+ const packageRoot = getPackageRoot();
24433
+ const templateSrcDir = join100(packageRoot, "templates", "github");
24434
+ if (!existsSync99(templateSrcDir)) {
24435
+ return;
24436
+ }
24437
+ await mkdir16(issueTemplateDir, { recursive: true });
24438
+ const issueSrcDir = join100(templateSrcDir, "ISSUE_TEMPLATE");
24439
+ if (existsSync99(issueSrcDir)) {
24440
+ const issueFiles = readdirSync33(issueSrcDir);
24441
+ for (const file2 of issueFiles) {
24442
+ const dest = join100(issueTemplateDir, file2);
24443
+ if (existsSync99(dest)) {
24444
+ skipped.push(`.github/ISSUE_TEMPLATE/${file2}`);
24445
+ continue;
24446
+ }
24447
+ const content = readFileSync73(join100(issueSrcDir, file2), "utf-8");
24448
+ await writeFile11(dest, content, "utf-8");
24449
+ created.push(`.github/ISSUE_TEMPLATE/${file2}`);
24450
+ }
24451
+ }
24452
+ const prTemplateSrc = join100(templateSrcDir, "pull_request_template.md");
24453
+ const prTemplateDest = join100(githubDir, "pull_request_template.md");
24454
+ if (existsSync99(prTemplateSrc)) {
24455
+ if (existsSync99(prTemplateDest)) {
24456
+ skipped.push(".github/pull_request_template.md");
24457
+ } else {
24458
+ const content = readFileSync73(prTemplateSrc, "utf-8");
24459
+ await writeFile11(prTemplateDest, content, "utf-8");
24460
+ created.push(".github/pull_request_template.md");
24461
+ }
24462
+ }
24463
+ }
24464
+ async function updateDocs() {
24465
+ const cleoDir = getCleoDirAbsolute();
24466
+ const projRoot = getProjectRoot();
24467
+ const created = [];
24468
+ const warnings = [];
24469
+ try {
24470
+ const result = await ensureInjection(projRoot);
24471
+ if (result.action !== "skipped") {
24472
+ created.push(`injection: ${result.details ?? result.action}`);
24473
+ }
24474
+ } catch (err) {
24475
+ warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
24476
+ }
24477
+ return {
24478
+ initialized: true,
24479
+ directory: cleoDir,
24480
+ created,
24481
+ skipped: [],
24482
+ warnings,
24483
+ updateDocsOnly: true
24484
+ };
24485
+ }
24486
+ async function initProject(opts = {}) {
24487
+ const cleoDir = getCleoDirAbsolute();
24488
+ const projRoot = getProjectRoot();
24489
+ const alreadyInitialized = existsSync99(cleoDir) && (existsSync99(join100(cleoDir, "tasks.db")) || existsSync99(join100(cleoDir, "config.json")));
24490
+ if (alreadyInitialized && !opts.force) {
24491
+ throw new CleoError(
24492
+ 1 /* GENERAL_ERROR */,
24493
+ "Project already initialized. DANGER ZONE: use --force to wipe and re-init.",
24494
+ { fix: "cleo init --force" }
24495
+ );
24496
+ }
24497
+ const force = !!opts.force;
24498
+ const created = [];
24499
+ const skipped = [];
24500
+ const warnings = [];
24501
+ const structureResult = await ensureCleoStructure(projRoot);
24502
+ if (structureResult.action === "created") {
24503
+ created.push(".cleo/ directory structure");
24504
+ }
24505
+ const configResult = await ensureConfig(projRoot, { force });
24506
+ if (configResult.action === "skipped") {
24507
+ skipped.push("config.json");
24508
+ } else {
24509
+ created.push("config.json");
24510
+ }
24511
+ try {
24512
+ const { getDb: getDb3 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
24513
+ await getDb3(join100(cleoDir, ".."));
24514
+ created.push("tasks.db");
24515
+ } catch (err) {
24516
+ created.push(`tasks.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
24517
+ }
24518
+ try {
24519
+ const brainResult = await ensureBrainDb(projRoot);
24520
+ if (brainResult.action === "created") {
24521
+ created.push("brain.db");
24522
+ }
24523
+ } catch (err) {
24524
+ created.push(`brain.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
24525
+ }
24526
+ if (force) {
24527
+ const gitignoreResult = await ensureGitignore(projRoot);
24528
+ if (gitignoreResult.action === "skipped") {
24529
+ skipped.push(".gitignore");
24530
+ } else {
24531
+ created.push(".gitignore");
24532
+ }
24533
+ } else {
24534
+ const gitignorePath = join100(cleoDir, ".gitignore");
24535
+ if (existsSync99(gitignorePath)) {
24536
+ skipped.push(".gitignore");
24537
+ } else {
24538
+ const gitignoreResult = await ensureGitignore(projRoot);
24539
+ if (gitignoreResult.action !== "skipped") {
24540
+ created.push(".gitignore");
24541
+ } else {
24542
+ skipped.push(".gitignore");
24543
+ }
24544
+ }
24545
+ }
24546
+ const legacySequencePath = join100(cleoDir, ".sequence");
24547
+ try {
24548
+ await unlink4(legacySequencePath);
24549
+ } catch {
24550
+ }
24551
+ const legacySequenceJsonPath = join100(cleoDir, ".sequence.json");
24552
+ try {
24553
+ await unlink4(legacySequenceJsonPath);
24554
+ } catch {
24555
+ }
24556
+ try {
24557
+ const gitRepoResult = await ensureCleoGitRepo(projRoot);
24558
+ if (gitRepoResult.action === "created") {
24559
+ created.push(".cleo/.git (isolated checkpoint repository)");
24560
+ }
24561
+ } catch (err) {
24562
+ warnings.push(
24563
+ `Could not initialize .cleo/.git: ${err instanceof Error ? err.message : String(err)}`
24564
+ );
24565
+ }
24566
+ try {
24567
+ const migrationResult = migrateAgentOutputs(projRoot, cleoDir);
24568
+ if (migrationResult.migrated) {
24569
+ created.push(`agent-outputs migration: ${migrationResult.summary}`);
24570
+ }
24571
+ } catch {
24572
+ warnings.push("Agent-outputs migration failed (best-effort, run cleo upgrade to retry)");
24573
+ }
24574
+ try {
24575
+ const schemaResult = ensureGlobalSchemas({ force });
24576
+ const total = schemaResult.installed + schemaResult.updated;
24577
+ if (total > 0) {
24578
+ created.push(`schemas/ (${total} files)`);
24579
+ }
24580
+ } catch (err) {
24581
+ warnings.push(`Schema installation: ${err instanceof Error ? err.message : String(err)}`);
24582
+ }
24583
+ try {
24584
+ const hooksResult = await ensureGitHooks(projRoot, { force });
24585
+ if (hooksResult.action === "created") {
24586
+ created.push(hooksResult.details ?? "git hooks installed");
24587
+ } else if (hooksResult.action === "skipped" && hooksResult.details?.includes("No .git/")) {
24588
+ warnings.push(hooksResult.details);
24589
+ } else if (hooksResult.action === "skipped" && hooksResult.details?.includes("not found in package root")) {
24590
+ warnings.push(hooksResult.details);
24591
+ } else if (hooksResult.action === "repaired" && hooksResult.details?.includes("error")) {
24592
+ const match = hooksResult.details.match(/Installed (\d+)/);
24593
+ if (match && parseInt(match[1], 10) > 0) {
24594
+ created.push(`git hooks (${match[1]} installed)`);
24595
+ }
24596
+ warnings.push(hooksResult.details);
24597
+ }
24598
+ } catch (err) {
24599
+ warnings.push(`Git hook installation: ${err instanceof Error ? err.message : String(err)}`);
24600
+ }
24601
+ const projectInfoResult = await ensureProjectInfo(projRoot, { force });
24602
+ if (projectInfoResult.action === "skipped") {
24603
+ skipped.push("project-info.json");
24604
+ } else {
24605
+ created.push("project-info.json");
24606
+ }
24607
+ try {
24608
+ const detectResult = await ensureProjectContext(projRoot, { force: !!opts.detect });
24609
+ if (detectResult.action !== "skipped") {
24610
+ created.push("project-context.json");
24611
+ }
24612
+ } catch (err) {
24613
+ warnings.push(`Project detection failed: ${err instanceof Error ? err.message : String(err)}`);
24614
+ }
24615
+ if (opts.mapCodebase) {
24616
+ try {
24617
+ const { mapCodebase: mapCodebase2 } = await Promise.resolve().then(() => (init_codebase_map(), codebase_map_exports));
24618
+ const mapResult = await mapCodebase2(projRoot, { storeToBrain: true });
24619
+ created.push(
24620
+ `codebase-map: ${mapResult.stack.languages.length} languages, ${mapResult.architecture.layers.length} layers analyzed`
24621
+ );
24622
+ } catch (err) {
24623
+ warnings.push(`Codebase mapping: ${err instanceof Error ? err.message : String(err)}`);
24624
+ }
24625
+ }
24626
+ try {
24627
+ const bridgeResult = await writeMemoryBridge(projRoot);
24628
+ if (bridgeResult.written) {
24629
+ created.push("memory-bridge.md");
24630
+ }
24631
+ } catch (err) {
24632
+ warnings.push(`Memory bridge: ${err instanceof Error ? err.message : String(err)}`);
24633
+ }
24634
+ try {
24635
+ const injectionResult = await ensureInjection(projRoot);
24636
+ if (injectionResult.action !== "skipped") {
24637
+ if (injectionResult.details) {
24638
+ created.push(`injection: ${injectionResult.details}`);
24639
+ }
24640
+ } else if (injectionResult.details) {
24641
+ warnings.push(injectionResult.details);
24642
+ }
24643
+ } catch (err) {
24644
+ warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
24645
+ }
24646
+ try {
24647
+ const { ensureContributorMcp: ensureContributorMcp2 } = await Promise.resolve().then(() => (init_scaffold(), scaffold_exports));
24648
+ const mcpResult = await ensureContributorMcp2(projRoot);
24649
+ if (mcpResult.action !== "skipped") {
24650
+ created.push(`contributor MCP: ${mcpResult.details ?? mcpResult.action}`);
24651
+ }
24652
+ } catch (err) {
24653
+ warnings.push(`Contributor MCP setup: ${err instanceof Error ? err.message : String(err)}`);
24654
+ }
24655
+ await initAgentDefinition(created, warnings);
24656
+ await initNexusRegistration(projRoot, created, warnings);
24657
+ try {
24658
+ const { AdapterManager: AdapterManager2 } = await Promise.resolve().then(() => (init_adapters(), adapters_exports));
24659
+ const mgr = AdapterManager2.getInstance(projRoot);
24660
+ const manifests = mgr.discover();
24661
+ if (manifests.length > 0) {
24662
+ created.push(`adapters: ${manifests.length} adapter(s) discovered`);
24663
+ const detected = mgr.detectActive();
24664
+ if (detected.length > 0) {
24665
+ created.push(`adapters: active provider detected (${detected.join(", ")})`);
24666
+ for (const adapterId of detected) {
24667
+ try {
24668
+ const adapter = await mgr.activate(adapterId);
24669
+ const installResult = await adapter.install.install({
24670
+ projectDir: projRoot
24671
+ });
24672
+ if (installResult.success) {
24673
+ created.push(`adapter install (${adapterId}): installed`);
24674
+ } else {
24675
+ warnings.push(`adapter install (${adapterId}): failed`);
24676
+ }
24677
+ } catch (err) {
24678
+ warnings.push(
24679
+ `adapter activate/install (${adapterId}): ${err instanceof Error ? err.message : String(err)}`
24680
+ );
24681
+ }
24682
+ }
24683
+ }
24684
+ }
24685
+ } catch (err) {
24686
+ warnings.push(`Adapter discovery: ${err instanceof Error ? err.message : String(err)}`);
24687
+ }
24688
+ try {
24689
+ await installGitHubTemplates(projRoot, created, skipped);
24690
+ } catch (err) {
24691
+ warnings.push(`GitHub templates: ${err instanceof Error ? err.message : String(err)}`);
24692
+ }
24693
+ const rootGitignoreResult = await removeCleoFromRootGitignore(projRoot);
24694
+ if (rootGitignoreResult.removed) {
24695
+ warnings.push(
24696
+ ".cleo/ was found in root .gitignore and has been removed. CLEO uses .cleo/.gitignore for selective tracking."
24697
+ );
24698
+ }
24699
+ return {
24700
+ initialized: true,
24701
+ directory: cleoDir,
24702
+ created,
24703
+ skipped,
24704
+ warnings
24705
+ };
24706
+ }
24707
+ function isAutoInitEnabled() {
24708
+ return process.env.CLEO_AUTO_INIT === "true";
24709
+ }
24710
+ async function ensureInitialized(projectRoot) {
24711
+ const root = projectRoot ?? getProjectRoot();
24712
+ const cleoDir = join100(root, ".cleo");
24713
+ const isInit = existsSync99(cleoDir) && (existsSync99(join100(cleoDir, "tasks.db")) || existsSync99(join100(cleoDir, "config.json")));
24714
+ if (isInit) {
24715
+ return { initialized: true };
24716
+ }
24717
+ if (isAutoInitEnabled()) {
24718
+ await initProject({ name: basename17(root) });
24719
+ return { initialized: true };
24720
+ }
24721
+ throw new Error("CLEO project not initialized. Run system.init or set CLEO_AUTO_INIT=true");
24722
+ }
24723
+ async function getVersion2(projectRoot) {
24724
+ const root = projectRoot ?? getProjectRoot();
24725
+ const versionPaths = [join100(root, "VERSION"), join100(root, "..", "VERSION")];
24726
+ for (const versionPath of versionPaths) {
24727
+ try {
24728
+ const content = await readFile17(versionPath, "utf-8");
24729
+ const version2 = content.trim();
24730
+ if (version2) {
24731
+ return { version: version2 };
24732
+ }
24733
+ } catch {
24734
+ }
24735
+ }
24736
+ const pkg = await readJson(join100(root, "package.json"));
24737
+ if (pkg?.version) {
24738
+ return { version: pkg.version };
24739
+ }
24740
+ return { version: "0.0.0" };
24741
+ }
24742
+ var DIR_SYMLINK_TYPE2;
24743
+ var init_init = __esm({
24744
+ "packages/core/src/init.ts"() {
24745
+ "use strict";
24746
+ init_src();
24747
+ init_errors3();
24748
+ init_hooks();
24749
+ init_injection();
24750
+ init_memory_bridge();
24751
+ init_agent_outputs();
24752
+ init_paths();
24753
+ init_scaffold();
24754
+ init_schema_management();
24755
+ init_json2();
24756
+ DIR_SYMLINK_TYPE2 = platform4() === "win32" ? "junction" : "dir";
24757
+ }
24758
+ });
24759
+
24008
24760
  // packages/core/src/index.ts
24009
24761
  init_src();
24010
24762
  init_adapters();
@@ -42540,219 +43292,7 @@ __export(migration_exports, {
42540
43292
  verifyBackup: () => verifyBackup,
42541
43293
  verifySourceIntegrity: () => verifySourceIntegrity
42542
43294
  });
42543
-
42544
- // packages/core/src/migration/agent-outputs.ts
42545
- import {
42546
- copyFileSync as copyFileSync5,
42547
- existsSync as existsSync45,
42548
- mkdirSync as mkdirSync10,
42549
- readdirSync as readdirSync20,
42550
- readFileSync as readFileSync30,
42551
- rmSync,
42552
- statSync as statSync11,
42553
- writeFileSync as writeFileSync4
42554
- } from "node:fs";
42555
- import { join as join50 } from "node:path";
42556
- var CANONICAL_DIR = ".cleo/agent-outputs";
42557
- var MANIFEST_PATH_REWRITES = [
42558
- [/claudedocs\/research-outputs\//g, `${CANONICAL_DIR}/`],
42559
- [/claudedocs\/agent-outputs\//g, `${CANONICAL_DIR}/`]
42560
- ];
42561
- function detectLegacyAgentOutputs(projectRoot, cleoDir) {
42562
- const hasResearchOutputs = existsSync45(join50(projectRoot, "claudedocs", "research-outputs"));
42563
- const hasLegacyAgentOutputs = existsSync45(join50(projectRoot, "claudedocs", "agent-outputs"));
42564
- const hasCanonical = existsSync45(join50(cleoDir, "agent-outputs"));
42565
- const legacyPaths = [];
42566
- if (hasResearchOutputs) legacyPaths.push("claudedocs/research-outputs/");
42567
- if (hasLegacyAgentOutputs) legacyPaths.push("claudedocs/agent-outputs/");
42568
- return {
42569
- hasLegacy: hasResearchOutputs || hasLegacyAgentOutputs,
42570
- hasResearchOutputs,
42571
- hasLegacyAgentOutputs,
42572
- hasCanonical,
42573
- legacyPaths
42574
- };
42575
- }
42576
- function migrateAgentOutputs(projectRoot, cleoDir) {
42577
- const detection = detectLegacyAgentOutputs(projectRoot, cleoDir);
42578
- if (!detection.hasLegacy) {
42579
- return {
42580
- migrated: false,
42581
- filesCopied: 0,
42582
- manifestEntries: 0,
42583
- removed: [],
42584
- summary: "No legacy output directories found"
42585
- };
42586
- }
42587
- const newDir = join50(cleoDir, "agent-outputs");
42588
- const hadCanonical = detection.hasCanonical;
42589
- mkdirSync10(newDir, { recursive: true });
42590
- let totalCopied = 0;
42591
- const mergedManifestLines = [];
42592
- const copiedFiles = /* @__PURE__ */ new Set();
42593
- const legacySources = [
42594
- {
42595
- path: join50(projectRoot, "claudedocs", "research-outputs"),
42596
- exists: detection.hasResearchOutputs
42597
- },
42598
- {
42599
- path: join50(projectRoot, "claudedocs", "agent-outputs"),
42600
- exists: detection.hasLegacyAgentOutputs
42601
- }
42602
- ];
42603
- for (const source of legacySources) {
42604
- if (!source.exists) continue;
42605
- totalCopied += copyDirContents(source.path, newDir, mergedManifestLines, copiedFiles);
42606
- }
42607
- const manifestEntries2 = mergeManifests(newDir, hadCanonical, mergedManifestLines);
42608
- updateConfigPaths(cleoDir);
42609
- const removed = removeLegacyDirs(projectRoot, detection);
42610
- const parts = [`Migrated ${totalCopied} files \u2192 ${CANONICAL_DIR}/`];
42611
- if (manifestEntries2 > 0) parts.push(`merged ${manifestEntries2} manifest entries`);
42612
- if (removed.length > 0) parts.push(`removed: ${removed.join(", ")}`);
42613
- return {
42614
- migrated: true,
42615
- filesCopied: totalCopied,
42616
- manifestEntries: manifestEntries2,
42617
- removed,
42618
- summary: parts.join("; ")
42619
- };
42620
- }
42621
- function copyDirContents(srcDir, dstDir, manifestLines, copiedFiles) {
42622
- let count2 = 0;
42623
- const entries = readdirSync20(srcDir);
42624
- for (const entry of entries) {
42625
- if (entry === "MANIFEST.jsonl") {
42626
- collectManifestLines(join50(srcDir, entry), manifestLines);
42627
- continue;
42628
- }
42629
- const srcPath = join50(srcDir, entry);
42630
- const dstPath = join50(dstDir, entry);
42631
- try {
42632
- const st = statSync11(srcPath);
42633
- if (st.isDirectory()) {
42634
- mkdirSync10(dstPath, { recursive: true });
42635
- for (const sf of readdirSync20(srcPath)) {
42636
- if (!copiedFiles.has(sf)) {
42637
- try {
42638
- copyFileSync5(join50(srcPath, sf), join50(dstPath, sf));
42639
- copiedFiles.add(sf);
42640
- count2++;
42641
- } catch {
42642
- }
42643
- }
42644
- }
42645
- } else if (!copiedFiles.has(entry)) {
42646
- copyFileSync5(srcPath, dstPath);
42647
- copiedFiles.add(entry);
42648
- count2++;
42649
- }
42650
- } catch {
42651
- }
42652
- }
42653
- return count2;
42654
- }
42655
- function collectManifestLines(manifestPath, out) {
42656
- try {
42657
- const content = readFileSync30(manifestPath, "utf-8");
42658
- for (const line2 of content.split("\n")) {
42659
- if (!line2.trim()) continue;
42660
- let rewritten = line2;
42661
- for (const [pattern, replacement] of MANIFEST_PATH_REWRITES) {
42662
- rewritten = rewritten.replace(pattern, replacement);
42663
- }
42664
- out.push(rewritten);
42665
- }
42666
- } catch {
42667
- }
42668
- }
42669
- function mergeManifests(newDir, hadCanonical, legacyLines) {
42670
- const manifestPath = join50(newDir, "MANIFEST.jsonl");
42671
- const existingLines = [];
42672
- if (hadCanonical && existsSync45(manifestPath)) {
42673
- try {
42674
- const existing = readFileSync30(manifestPath, "utf-8");
42675
- for (const line2 of existing.split("\n")) {
42676
- if (line2.trim()) existingLines.push(line2);
42677
- }
42678
- } catch {
42679
- }
42680
- }
42681
- const seenIds = /* @__PURE__ */ new Set();
42682
- const finalLines = [];
42683
- for (const line2 of existingLines) {
42684
- try {
42685
- const p = JSON.parse(line2);
42686
- if (p.id) seenIds.add(p.id);
42687
- } catch {
42688
- }
42689
- finalLines.push(line2);
42690
- }
42691
- for (const line2 of legacyLines) {
42692
- try {
42693
- const p = JSON.parse(line2);
42694
- if (p.id && seenIds.has(p.id)) continue;
42695
- if (p.id) seenIds.add(p.id);
42696
- } catch {
42697
- }
42698
- finalLines.push(line2);
42699
- }
42700
- if (finalLines.length > 0) {
42701
- writeFileSync4(manifestPath, finalLines.join("\n") + "\n");
42702
- }
42703
- return finalLines.length;
42704
- }
42705
- function updateConfigPaths(cleoDir) {
42706
- const configPath = join50(cleoDir, "config.json");
42707
- if (!existsSync45(configPath)) return;
42708
- try {
42709
- const config2 = JSON.parse(readFileSync30(configPath, "utf-8"));
42710
- const currentDir = config2.agentOutputs?.directory ?? config2.agentOutputs ?? config2.research?.outputDir;
42711
- if (currentDir && currentDir !== CANONICAL_DIR) {
42712
- if (typeof config2.agentOutputs === "object") {
42713
- config2.agentOutputs.directory = CANONICAL_DIR;
42714
- } else {
42715
- config2.agentOutputs = { directory: CANONICAL_DIR };
42716
- }
42717
- if (config2.research?.outputDir) {
42718
- delete config2.research.outputDir;
42719
- if (Object.keys(config2.research).length === 0) {
42720
- delete config2.research;
42721
- }
42722
- }
42723
- writeFileSync4(configPath, JSON.stringify(config2, null, 2));
42724
- }
42725
- } catch {
42726
- }
42727
- }
42728
- function removeLegacyDirs(projectRoot, detection) {
42729
- const removed = [];
42730
- if (detection.hasResearchOutputs) {
42731
- try {
42732
- rmSync(join50(projectRoot, "claudedocs", "research-outputs"), { recursive: true, force: true });
42733
- removed.push("claudedocs/research-outputs/");
42734
- } catch {
42735
- }
42736
- }
42737
- if (detection.hasLegacyAgentOutputs) {
42738
- try {
42739
- rmSync(join50(projectRoot, "claudedocs", "agent-outputs"), { recursive: true, force: true });
42740
- removed.push("claudedocs/agent-outputs/");
42741
- } catch {
42742
- }
42743
- }
42744
- const claudedocsDir = join50(projectRoot, "claudedocs");
42745
- if (existsSync45(claudedocsDir)) {
42746
- try {
42747
- if (readdirSync20(claudedocsDir).length === 0) {
42748
- rmSync(claudedocsDir, { recursive: true, force: true });
42749
- removed.push("claudedocs/ (empty)");
42750
- }
42751
- } catch {
42752
- }
42753
- }
42754
- return removed;
42755
- }
43295
+ init_agent_outputs();
42756
43296
 
42757
43297
  // packages/core/src/migration/checksum.ts
42758
43298
  import { createHash as createHash5 } from "node:crypto";
@@ -54215,8 +54755,8 @@ async function initializeSpawnAdapters(manifests) {
54215
54755
  if (!manifest.capabilities?.supportsSpawn) continue;
54216
54756
  if (spawnRegistry.hasAdapterForProvider(manifest.provider)) continue;
54217
54757
  try {
54218
- const { join: join103 } = await import("node:path");
54219
- const modulePath = join103(manifest.packagePath, manifest.entryPoint);
54758
+ const { join: join104 } = await import("node:path");
54759
+ const modulePath = join104(manifest.packagePath, manifest.entryPoint);
54220
54760
  const adapterModule = await import(modulePath);
54221
54761
  let SpawnProviderClass;
54222
54762
  for (const [exportName, exportValue] of Object.entries(adapterModule)) {
@@ -55804,6 +56344,7 @@ var CORE_PROTECTED_FILES = [
55804
56344
  ];
55805
56345
 
55806
56346
  // packages/core/src/validation/doctor/checks.ts
56347
+ init_agent_outputs();
55807
56348
  init_paths();
55808
56349
  init_scaffold();
55809
56350
  init_schema_management();
@@ -61813,400 +62354,7 @@ function isCleoRegisteredCode(lafsCode) {
61813
62354
 
61814
62355
  // packages/core/src/index.ts
61815
62356
  init_errors3();
61816
-
61817
- // packages/core/src/init.ts
61818
- init_src();
61819
- init_errors3();
61820
- init_hooks();
61821
- init_injection();
61822
- init_memory_bridge();
61823
- import { existsSync as existsSync99, readdirSync as readdirSync33, readFileSync as readFileSync73 } from "node:fs";
61824
- import { copyFile as copyFile3, lstat, mkdir as mkdir16, readFile as readFile17, symlink, unlink as unlink4, writeFile as writeFile11 } from "node:fs/promises";
61825
- import { platform as platform4 } from "node:os";
61826
- import { basename as basename17, dirname as dirname19, join as join100 } from "node:path";
61827
- init_paths();
61828
- init_scaffold();
61829
- init_schema_management();
61830
- init_json2();
61831
- var DIR_SYMLINK_TYPE2 = platform4() === "win32" ? "junction" : "dir";
61832
- async function initAgentDefinition(created, warnings) {
61833
- let agentSourceDir = null;
61834
- try {
61835
- const { createRequire: createRequire5 } = await import("node:module");
61836
- const req = createRequire5(import.meta.url);
61837
- const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
61838
- const agentsPkgRoot = dirname19(agentsPkgMain);
61839
- const candidate = join100(agentsPkgRoot, "cleo-subagent");
61840
- if (existsSync99(candidate)) {
61841
- agentSourceDir = candidate;
61842
- }
61843
- } catch {
61844
- }
61845
- if (!agentSourceDir) {
61846
- const packageRoot = getPackageRoot();
61847
- const bundled = join100(packageRoot, "agents", "cleo-subagent");
61848
- if (existsSync99(bundled)) {
61849
- agentSourceDir = bundled;
61850
- }
61851
- }
61852
- if (!agentSourceDir) {
61853
- warnings.push("agents/cleo-subagent/ not found in package, skipping agent definition install");
61854
- return;
61855
- }
61856
- const globalAgentsDir = join100(getAgentsHome(), "agents", "cleo-subagent");
61857
- await mkdir16(dirname19(globalAgentsDir), { recursive: true });
61858
- try {
61859
- try {
61860
- const stat2 = await lstat(globalAgentsDir);
61861
- if (stat2.isSymbolicLink()) {
61862
- const { readlink } = await import("node:fs/promises");
61863
- const currentTarget = await readlink(globalAgentsDir);
61864
- if (currentTarget === agentSourceDir) {
61865
- return;
61866
- }
61867
- await unlink4(globalAgentsDir);
61868
- } else if (stat2.isDirectory()) {
61869
- return;
61870
- }
61871
- } catch {
61872
- }
61873
- await symlink(agentSourceDir, globalAgentsDir, DIR_SYMLINK_TYPE2);
61874
- created.push("agent: cleo-subagent (symlinked)");
61875
- } catch (_err) {
61876
- try {
61877
- await mkdir16(globalAgentsDir, { recursive: true });
61878
- const files = readdirSync33(agentSourceDir);
61879
- for (const file2 of files) {
61880
- await copyFile3(join100(agentSourceDir, file2), join100(globalAgentsDir, file2));
61881
- }
61882
- created.push("agent: cleo-subagent (copied)");
61883
- } catch (copyErr) {
61884
- warnings.push(
61885
- `Agent definition install: ${copyErr instanceof Error ? copyErr.message : String(copyErr)}`
61886
- );
61887
- }
61888
- }
61889
- }
61890
- async function initNexusRegistration(projectRoot, created, warnings) {
61891
- try {
61892
- const { nexusReconcile: nexusReconcile2 } = await Promise.resolve().then(() => (init_registry3(), registry_exports3));
61893
- const result = await nexusReconcile2(projectRoot);
61894
- if (result.status === "auto_registered") {
61895
- created.push("NEXUS registration (auto-registered new project)");
61896
- } else if (result.status === "path_updated") {
61897
- created.push(`NEXUS registration (path updated: ${result.oldPath} \u2192 ${result.newPath})`);
61898
- } else if (result.status === "ok") {
61899
- created.push("NEXUS registration (project verified and active)");
61900
- }
61901
- } catch (err) {
61902
- const errStr = String(err);
61903
- if (errStr.includes("NEXUS_PROJECT_EXISTS")) {
61904
- warnings.push("NEXUS registration: Project already registered");
61905
- } else if (errStr.includes("NEXUS_REGISTRY_CORRUPT")) {
61906
- warnings.push(
61907
- `NEXUS registration: Identity conflict - ${err instanceof Error ? err.message : errStr}. Run 'cleo nexus unregister' and re-register.`
61908
- );
61909
- } else {
61910
- warnings.push(`NEXUS registration: ${err instanceof Error ? err.message : errStr}`);
61911
- }
61912
- }
61913
- }
61914
- async function installGitHubTemplates(projectRoot, created, skipped) {
61915
- if (!existsSync99(join100(projectRoot, ".git"))) {
61916
- return;
61917
- }
61918
- const githubDir = join100(projectRoot, ".github");
61919
- const issueTemplateDir = join100(githubDir, "ISSUE_TEMPLATE");
61920
- const packageRoot = getPackageRoot();
61921
- const templateSrcDir = join100(packageRoot, "templates", "github");
61922
- if (!existsSync99(templateSrcDir)) {
61923
- return;
61924
- }
61925
- await mkdir16(issueTemplateDir, { recursive: true });
61926
- const issueSrcDir = join100(templateSrcDir, "ISSUE_TEMPLATE");
61927
- if (existsSync99(issueSrcDir)) {
61928
- const issueFiles = readdirSync33(issueSrcDir);
61929
- for (const file2 of issueFiles) {
61930
- const dest = join100(issueTemplateDir, file2);
61931
- if (existsSync99(dest)) {
61932
- skipped.push(`.github/ISSUE_TEMPLATE/${file2}`);
61933
- continue;
61934
- }
61935
- const content = readFileSync73(join100(issueSrcDir, file2), "utf-8");
61936
- await writeFile11(dest, content, "utf-8");
61937
- created.push(`.github/ISSUE_TEMPLATE/${file2}`);
61938
- }
61939
- }
61940
- const prTemplateSrc = join100(templateSrcDir, "pull_request_template.md");
61941
- const prTemplateDest = join100(githubDir, "pull_request_template.md");
61942
- if (existsSync99(prTemplateSrc)) {
61943
- if (existsSync99(prTemplateDest)) {
61944
- skipped.push(".github/pull_request_template.md");
61945
- } else {
61946
- const content = readFileSync73(prTemplateSrc, "utf-8");
61947
- await writeFile11(prTemplateDest, content, "utf-8");
61948
- created.push(".github/pull_request_template.md");
61949
- }
61950
- }
61951
- }
61952
- async function initProject(opts = {}) {
61953
- const cleoDir = getCleoDirAbsolute();
61954
- const projRoot = getProjectRoot();
61955
- const alreadyInitialized = existsSync99(cleoDir) && (existsSync99(join100(cleoDir, "tasks.db")) || existsSync99(join100(cleoDir, "config.json")));
61956
- if (alreadyInitialized && !opts.force) {
61957
- throw new CleoError(
61958
- 1 /* GENERAL_ERROR */,
61959
- "Project already initialized. DANGER ZONE: use --force to wipe and re-init.",
61960
- { fix: "cleo init --force" }
61961
- );
61962
- }
61963
- const force = !!opts.force;
61964
- const created = [];
61965
- const skipped = [];
61966
- const warnings = [];
61967
- const structureResult = await ensureCleoStructure(projRoot);
61968
- if (structureResult.action === "created") {
61969
- created.push(".cleo/ directory structure");
61970
- }
61971
- const configResult = await ensureConfig(projRoot, { force });
61972
- if (configResult.action === "skipped") {
61973
- skipped.push("config.json");
61974
- } else {
61975
- created.push("config.json");
61976
- }
61977
- try {
61978
- const { getDb: getDb3 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
61979
- await getDb3(join100(cleoDir, ".."));
61980
- created.push("tasks.db");
61981
- } catch (err) {
61982
- created.push(`tasks.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
61983
- }
61984
- try {
61985
- const brainResult = await ensureBrainDb(projRoot);
61986
- if (brainResult.action === "created") {
61987
- created.push("brain.db");
61988
- }
61989
- } catch (err) {
61990
- created.push(`brain.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
61991
- }
61992
- if (force) {
61993
- const gitignoreResult = await ensureGitignore(projRoot);
61994
- if (gitignoreResult.action === "skipped") {
61995
- skipped.push(".gitignore");
61996
- } else {
61997
- created.push(".gitignore");
61998
- }
61999
- } else {
62000
- const gitignorePath = join100(cleoDir, ".gitignore");
62001
- if (existsSync99(gitignorePath)) {
62002
- skipped.push(".gitignore");
62003
- } else {
62004
- const gitignoreResult = await ensureGitignore(projRoot);
62005
- if (gitignoreResult.action !== "skipped") {
62006
- created.push(".gitignore");
62007
- } else {
62008
- skipped.push(".gitignore");
62009
- }
62010
- }
62011
- }
62012
- const legacySequencePath = join100(cleoDir, ".sequence");
62013
- try {
62014
- await unlink4(legacySequencePath);
62015
- } catch {
62016
- }
62017
- const legacySequenceJsonPath = join100(cleoDir, ".sequence.json");
62018
- try {
62019
- await unlink4(legacySequenceJsonPath);
62020
- } catch {
62021
- }
62022
- try {
62023
- const gitRepoResult = await ensureCleoGitRepo(projRoot);
62024
- if (gitRepoResult.action === "created") {
62025
- created.push(".cleo/.git (isolated checkpoint repository)");
62026
- }
62027
- } catch (err) {
62028
- warnings.push(
62029
- `Could not initialize .cleo/.git: ${err instanceof Error ? err.message : String(err)}`
62030
- );
62031
- }
62032
- try {
62033
- const migrationResult = migrateAgentOutputs(projRoot, cleoDir);
62034
- if (migrationResult.migrated) {
62035
- created.push(`agent-outputs migration: ${migrationResult.summary}`);
62036
- }
62037
- } catch {
62038
- warnings.push("Agent-outputs migration failed (best-effort, run cleo upgrade to retry)");
62039
- }
62040
- try {
62041
- const schemaResult = ensureGlobalSchemas({ force });
62042
- const total = schemaResult.installed + schemaResult.updated;
62043
- if (total > 0) {
62044
- created.push(`schemas/ (${total} files)`);
62045
- }
62046
- } catch (err) {
62047
- warnings.push(`Schema installation: ${err instanceof Error ? err.message : String(err)}`);
62048
- }
62049
- try {
62050
- const hooksResult = await ensureGitHooks(projRoot, { force });
62051
- if (hooksResult.action === "created") {
62052
- created.push(hooksResult.details ?? "git hooks installed");
62053
- } else if (hooksResult.action === "skipped" && hooksResult.details?.includes("No .git/")) {
62054
- warnings.push(hooksResult.details);
62055
- } else if (hooksResult.action === "skipped" && hooksResult.details?.includes("not found in package root")) {
62056
- warnings.push(hooksResult.details);
62057
- } else if (hooksResult.action === "repaired" && hooksResult.details?.includes("error")) {
62058
- const match = hooksResult.details.match(/Installed (\d+)/);
62059
- if (match && parseInt(match[1], 10) > 0) {
62060
- created.push(`git hooks (${match[1]} installed)`);
62061
- }
62062
- warnings.push(hooksResult.details);
62063
- }
62064
- } catch (err) {
62065
- warnings.push(`Git hook installation: ${err instanceof Error ? err.message : String(err)}`);
62066
- }
62067
- const projectInfoResult = await ensureProjectInfo(projRoot, { force });
62068
- if (projectInfoResult.action === "skipped") {
62069
- skipped.push("project-info.json");
62070
- } else {
62071
- created.push("project-info.json");
62072
- }
62073
- try {
62074
- const detectResult = await ensureProjectContext(projRoot, { force: !!opts.detect });
62075
- if (detectResult.action !== "skipped") {
62076
- created.push("project-context.json");
62077
- }
62078
- } catch (err) {
62079
- warnings.push(`Project detection failed: ${err instanceof Error ? err.message : String(err)}`);
62080
- }
62081
- if (opts.mapCodebase) {
62082
- try {
62083
- const { mapCodebase: mapCodebase2 } = await Promise.resolve().then(() => (init_codebase_map(), codebase_map_exports));
62084
- const mapResult = await mapCodebase2(projRoot, { storeToBrain: true });
62085
- created.push(
62086
- `codebase-map: ${mapResult.stack.languages.length} languages, ${mapResult.architecture.layers.length} layers analyzed`
62087
- );
62088
- } catch (err) {
62089
- warnings.push(`Codebase mapping: ${err instanceof Error ? err.message : String(err)}`);
62090
- }
62091
- }
62092
- try {
62093
- const bridgeResult = await writeMemoryBridge(projRoot);
62094
- if (bridgeResult.written) {
62095
- created.push("memory-bridge.md");
62096
- }
62097
- } catch (err) {
62098
- warnings.push(`Memory bridge: ${err instanceof Error ? err.message : String(err)}`);
62099
- }
62100
- try {
62101
- const injectionResult = await ensureInjection(projRoot);
62102
- if (injectionResult.action !== "skipped") {
62103
- if (injectionResult.details) {
62104
- created.push(`injection: ${injectionResult.details}`);
62105
- }
62106
- } else if (injectionResult.details) {
62107
- warnings.push(injectionResult.details);
62108
- }
62109
- } catch (err) {
62110
- warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
62111
- }
62112
- try {
62113
- const { ensureContributorMcp: ensureContributorMcp2 } = await Promise.resolve().then(() => (init_scaffold(), scaffold_exports));
62114
- const mcpResult = await ensureContributorMcp2(projRoot);
62115
- if (mcpResult.action !== "skipped") {
62116
- created.push(`contributor MCP: ${mcpResult.details ?? mcpResult.action}`);
62117
- }
62118
- } catch (err) {
62119
- warnings.push(`Contributor MCP setup: ${err instanceof Error ? err.message : String(err)}`);
62120
- }
62121
- await initAgentDefinition(created, warnings);
62122
- await initNexusRegistration(projRoot, created, warnings);
62123
- try {
62124
- const { AdapterManager: AdapterManager2 } = await Promise.resolve().then(() => (init_adapters(), adapters_exports));
62125
- const mgr = AdapterManager2.getInstance(projRoot);
62126
- const manifests = mgr.discover();
62127
- if (manifests.length > 0) {
62128
- created.push(`adapters: ${manifests.length} adapter(s) discovered`);
62129
- const detected = mgr.detectActive();
62130
- if (detected.length > 0) {
62131
- created.push(`adapters: active provider detected (${detected.join(", ")})`);
62132
- for (const adapterId of detected) {
62133
- try {
62134
- const adapter = await mgr.activate(adapterId);
62135
- const installResult = await adapter.install.install({
62136
- projectDir: projRoot
62137
- });
62138
- if (installResult.success) {
62139
- created.push(`adapter install (${adapterId}): installed`);
62140
- } else {
62141
- warnings.push(`adapter install (${adapterId}): failed`);
62142
- }
62143
- } catch (err) {
62144
- warnings.push(
62145
- `adapter activate/install (${adapterId}): ${err instanceof Error ? err.message : String(err)}`
62146
- );
62147
- }
62148
- }
62149
- }
62150
- }
62151
- } catch (err) {
62152
- warnings.push(`Adapter discovery: ${err instanceof Error ? err.message : String(err)}`);
62153
- }
62154
- try {
62155
- await installGitHubTemplates(projRoot, created, skipped);
62156
- } catch (err) {
62157
- warnings.push(`GitHub templates: ${err instanceof Error ? err.message : String(err)}`);
62158
- }
62159
- const rootGitignoreResult = await removeCleoFromRootGitignore(projRoot);
62160
- if (rootGitignoreResult.removed) {
62161
- warnings.push(
62162
- ".cleo/ was found in root .gitignore and has been removed. CLEO uses .cleo/.gitignore for selective tracking."
62163
- );
62164
- }
62165
- return {
62166
- initialized: true,
62167
- directory: cleoDir,
62168
- created,
62169
- skipped,
62170
- warnings
62171
- };
62172
- }
62173
- function isAutoInitEnabled() {
62174
- return process.env.CLEO_AUTO_INIT === "true";
62175
- }
62176
- async function ensureInitialized(projectRoot) {
62177
- const root = projectRoot ?? getProjectRoot();
62178
- const cleoDir = join100(root, ".cleo");
62179
- const isInit = existsSync99(cleoDir) && (existsSync99(join100(cleoDir, "tasks.db")) || existsSync99(join100(cleoDir, "config.json")));
62180
- if (isInit) {
62181
- return { initialized: true };
62182
- }
62183
- if (isAutoInitEnabled()) {
62184
- await initProject({ name: basename17(root) });
62185
- return { initialized: true };
62186
- }
62187
- throw new Error("CLEO project not initialized. Run system.init or set CLEO_AUTO_INIT=true");
62188
- }
62189
- async function getVersion2(projectRoot) {
62190
- const root = projectRoot ?? getProjectRoot();
62191
- const versionPaths = [join100(root, "VERSION"), join100(root, "..", "VERSION")];
62192
- for (const versionPath of versionPaths) {
62193
- try {
62194
- const content = await readFile17(versionPath, "utf-8");
62195
- const version2 = content.trim();
62196
- if (version2) {
62197
- return { version: version2 };
62198
- }
62199
- } catch {
62200
- }
62201
- }
62202
- const pkg = await readJson(join100(root, "package.json"));
62203
- if (pkg?.version) {
62204
- return { version: pkg.version };
62205
- }
62206
- return { version: "0.0.0" };
62207
- }
62208
-
62209
- // packages/core/src/index.ts
62357
+ init_init();
62210
62358
  init_json_schema_validator();
62211
62359
  init_logger();
62212
62360
 
@@ -62346,6 +62494,219 @@ function getProjectInfoSync(cwd) {
62346
62494
  init_scaffold();
62347
62495
  init_adapters();
62348
62496
 
62497
+ // packages/core/src/bootstrap.ts
62498
+ init_paths();
62499
+ init_scaffold();
62500
+ import { existsSync as existsSync102, readFileSync as readFileSync76 } from "node:fs";
62501
+ import { mkdir as mkdir17, readFile as readFile19, writeFile as writeFile12 } from "node:fs/promises";
62502
+ import { homedir as homedir6 } from "node:os";
62503
+ import { join as join103 } from "node:path";
62504
+ async function bootstrapGlobalCleo(options) {
62505
+ const ctx = {
62506
+ created: [],
62507
+ warnings: [],
62508
+ isDryRun: options?.dryRun ?? false
62509
+ };
62510
+ try {
62511
+ await ensureGlobalHome();
62512
+ } catch {
62513
+ }
62514
+ await ensureGlobalTemplatesBootstrap(ctx, options?.packageRoot);
62515
+ await injectAgentsHub(ctx);
62516
+ await installMcpToProviders(ctx);
62517
+ await installSkillsGlobally(ctx);
62518
+ await installAgentDefinitionGlobally(ctx);
62519
+ await installProviderAdapters(ctx, options?.packageRoot);
62520
+ return ctx;
62521
+ }
62522
+ async function ensureGlobalTemplatesBootstrap(ctx, packageRootOverride) {
62523
+ const globalTemplatesDir = getCleoTemplatesDir();
62524
+ if (!ctx.isDryRun) {
62525
+ await mkdir17(globalTemplatesDir, { recursive: true });
62526
+ }
62527
+ try {
62528
+ const pkgRoot = packageRootOverride ?? getPackageRoot();
62529
+ const templatePath = join103(pkgRoot, "templates", "CLEO-INJECTION.md");
62530
+ if (existsSync102(templatePath)) {
62531
+ const content = readFileSync76(templatePath, "utf-8");
62532
+ const destPath = join103(globalTemplatesDir, "CLEO-INJECTION.md");
62533
+ if (!ctx.isDryRun) {
62534
+ await writeFile12(destPath, content);
62535
+ }
62536
+ ctx.created.push(
62537
+ `~/.cleo/templates/CLEO-INJECTION.md (${ctx.isDryRun ? "would refresh" : "refreshed"})`
62538
+ );
62539
+ } else {
62540
+ try {
62541
+ const { getInjectionTemplateContent: getInjectionTemplateContent2 } = await Promise.resolve().then(() => (init_injection(), injection_exports));
62542
+ const content = getInjectionTemplateContent2();
62543
+ if (content) {
62544
+ const destPath = join103(globalTemplatesDir, "CLEO-INJECTION.md");
62545
+ if (!ctx.isDryRun) {
62546
+ await writeFile12(destPath, content);
62547
+ }
62548
+ ctx.created.push(
62549
+ `~/.cleo/templates/CLEO-INJECTION.md (${ctx.isDryRun ? "would refresh" : "refreshed"} from embedded)`
62550
+ );
62551
+ }
62552
+ } catch {
62553
+ ctx.warnings.push("Could not refresh CLEO-INJECTION.md template");
62554
+ }
62555
+ }
62556
+ } catch {
62557
+ ctx.warnings.push("Could not refresh CLEO-INJECTION.md template");
62558
+ }
62559
+ }
62560
+ async function injectAgentsHub(ctx) {
62561
+ const globalAgentsDir = getAgentsHome();
62562
+ const globalAgentsMd = join103(globalAgentsDir, "AGENTS.md");
62563
+ try {
62564
+ const { inject: inject2, getInstalledProviders: getInstalledProviders3, injectAll: injectAll2, buildInjectionContent } = await import("@cleocode/caamp");
62565
+ if (!ctx.isDryRun) {
62566
+ await mkdir17(globalAgentsDir, { recursive: true });
62567
+ if (existsSync102(globalAgentsMd)) {
62568
+ const content = await readFile19(globalAgentsMd, "utf8");
62569
+ const stripped = content.replace(/\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g, "").replace(/\n?<!-- CAAMP:START -->[\s\S]*?<!-- CAAMP:END -->\n?/g, "").trim();
62570
+ await writeFile12(globalAgentsMd, stripped ? `${stripped}
62571
+ ` : "", "utf8");
62572
+ }
62573
+ const expectedContent = "@~/.cleo/templates/CLEO-INJECTION.md";
62574
+ const action = await inject2(globalAgentsMd, expectedContent);
62575
+ ctx.created.push(`~/.agents/AGENTS.md (${action})`);
62576
+ } else {
62577
+ ctx.created.push("~/.agents/AGENTS.md (would create/update CAAMP block)");
62578
+ }
62579
+ const providers = getInstalledProviders3();
62580
+ if (providers.length === 0) {
62581
+ ctx.warnings.push("No AI provider installations detected");
62582
+ } else {
62583
+ const injectionContent = buildInjectionContent({
62584
+ references: ["@~/.agents/AGENTS.md"]
62585
+ });
62586
+ if (!ctx.isDryRun) {
62587
+ for (const provider of providers) {
62588
+ const instructFilePath = join103(provider.pathGlobal, provider.instructFile);
62589
+ if (existsSync102(instructFilePath)) {
62590
+ const fileContent = await readFile19(instructFilePath, "utf8");
62591
+ const stripped = fileContent.replace(
62592
+ /\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
62593
+ ""
62594
+ );
62595
+ if (stripped !== fileContent) {
62596
+ await writeFile12(instructFilePath, stripped, "utf8");
62597
+ }
62598
+ }
62599
+ }
62600
+ const results = await injectAll2(providers, homedir6(), "global", injectionContent);
62601
+ for (const [filePath, action] of results) {
62602
+ const displayPath = filePath.replace(homedir6(), "~");
62603
+ ctx.created.push(`${displayPath} (${action})`);
62604
+ }
62605
+ } else {
62606
+ for (const p of providers) {
62607
+ const displayPath = join103(p.pathGlobal, p.instructFile).replace(homedir6(), "~");
62608
+ ctx.created.push(`${displayPath} (would update CAAMP block)`);
62609
+ }
62610
+ }
62611
+ }
62612
+ } catch (err) {
62613
+ ctx.warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
62614
+ }
62615
+ }
62616
+ async function installMcpToProviders(ctx) {
62617
+ try {
62618
+ const { detectEnvMode: detectEnvMode2, generateMcpServerEntry: generateMcpServerEntry2, getMcpServerName: getMcpServerName2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
62619
+ const { getInstalledProviders: getInstalledProviders3, installMcpServerToAll } = await import("@cleocode/caamp");
62620
+ const env = detectEnvMode2();
62621
+ const serverEntry = generateMcpServerEntry2(env);
62622
+ const serverName = getMcpServerName2(env);
62623
+ const providers = getInstalledProviders3();
62624
+ if (providers.length > 0) {
62625
+ if (!ctx.isDryRun) {
62626
+ const results = await installMcpServerToAll(
62627
+ providers,
62628
+ serverName,
62629
+ serverEntry,
62630
+ "global",
62631
+ homedir6()
62632
+ );
62633
+ const successes = results.filter((r) => r.success);
62634
+ if (successes.length > 0) {
62635
+ ctx.created.push(
62636
+ `MCP configs: ${successes.map((r) => r.provider.id).join(", ")}`
62637
+ );
62638
+ }
62639
+ } else {
62640
+ ctx.created.push("MCP configs (would update)");
62641
+ }
62642
+ }
62643
+ } catch {
62644
+ ctx.warnings.push("MCP config update skipped (non-critical)");
62645
+ }
62646
+ }
62647
+ async function installSkillsGlobally(ctx) {
62648
+ try {
62649
+ if (!ctx.isDryRun) {
62650
+ const { initCoreSkills: initCoreSkills2 } = await Promise.resolve().then(() => (init_init(), init_exports));
62651
+ await initCoreSkills2(ctx.created, ctx.warnings);
62652
+ } else {
62653
+ ctx.created.push("core skills (would install/update)");
62654
+ }
62655
+ } catch (err) {
62656
+ ctx.warnings.push(
62657
+ `Core skills installation failed: ${err instanceof Error ? err.message : String(err)}`
62658
+ );
62659
+ }
62660
+ }
62661
+ async function installAgentDefinitionGlobally(ctx) {
62662
+ try {
62663
+ if (!ctx.isDryRun) {
62664
+ const { initAgentDefinition: initAgentDefinition2 } = await Promise.resolve().then(() => (init_init(), init_exports));
62665
+ await initAgentDefinition2(ctx.created, ctx.warnings);
62666
+ } else {
62667
+ ctx.created.push("agent: cleo-subagent (would symlink)");
62668
+ }
62669
+ } catch (err) {
62670
+ ctx.warnings.push(
62671
+ `Agent definition install: ${err instanceof Error ? err.message : String(err)}`
62672
+ );
62673
+ }
62674
+ }
62675
+ async function installProviderAdapters(ctx, packageRootOverride) {
62676
+ try {
62677
+ const { AdapterManager: AdapterManager2 } = await Promise.resolve().then(() => (init_adapters(), adapters_exports));
62678
+ const pkgRoot = packageRootOverride ?? getPackageRoot();
62679
+ const manager = AdapterManager2.getInstance(pkgRoot);
62680
+ manager.discover();
62681
+ const detected = manager.detectActive();
62682
+ for (const adapterId of detected) {
62683
+ try {
62684
+ const adapter = await manager.activate(adapterId);
62685
+ if (adapter.install) {
62686
+ if (!ctx.isDryRun) {
62687
+ const installResult = await adapter.install.install({
62688
+ projectDir: process.cwd()
62689
+ });
62690
+ if (installResult.success) {
62691
+ ctx.created.push(`${adapterId} adapter (installed)`);
62692
+ }
62693
+ } else {
62694
+ ctx.created.push(`${adapterId} adapter (would install)`);
62695
+ }
62696
+ }
62697
+ } catch (activateErr) {
62698
+ ctx.warnings.push(
62699
+ `Adapter ${adapterId} skipped: ${activateErr instanceof Error ? activateErr.message : String(activateErr)}`
62700
+ );
62701
+ }
62702
+ }
62703
+ } catch (err) {
62704
+ ctx.warnings.push(
62705
+ `Adapter install skipped: ${err instanceof Error ? err.message : String(err)}`
62706
+ );
62707
+ }
62708
+ }
62709
+
62349
62710
  // packages/core/src/cleo.ts
62350
62711
  import path from "node:path";
62351
62712
  init_brain_retrieval();
@@ -62632,6 +62993,7 @@ export {
62632
62993
  agentTypeSchema,
62633
62994
  agents_exports as agents,
62634
62995
  archiveTasks,
62996
+ bootstrapGlobalCleo,
62635
62997
  brainConfidenceLevelSchema,
62636
62998
  brainDecisionTypeSchema,
62637
62999
  brainEdgeTypeSchema,