@cleocode/core 2026.3.50 → 2026.3.52
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/bootstrap.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1003 -629
- package/dist/index.js.map +4 -4
- package/dist/scaffold.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/bootstrap.ts +9 -10
- package/src/index.ts +3 -0
- package/src/scaffold.ts +24 -13
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
|
|
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 =
|
|
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((
|
|
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,
|
|
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:
|
|
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) ||
|
|
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((
|
|
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({
|
|
@@ -19748,16 +19748,24 @@ async function ensureGlobalHome() {
|
|
|
19748
19748
|
for (const subdir of REQUIRED_GLOBAL_SUBDIRS) {
|
|
19749
19749
|
await mkdir5(join37(cleoHome, subdir), { recursive: true });
|
|
19750
19750
|
}
|
|
19751
|
-
|
|
19752
|
-
|
|
19753
|
-
|
|
19754
|
-
|
|
19755
|
-
|
|
19756
|
-
|
|
19757
|
-
|
|
19758
|
-
|
|
19759
|
-
|
|
19760
|
-
|
|
19751
|
+
const homedir7 = (await import("node:os")).homedir();
|
|
19752
|
+
const legacyCleoHome = join37(homedir7, ".cleo");
|
|
19753
|
+
const cleanupPaths = [cleoHome];
|
|
19754
|
+
if (legacyCleoHome !== cleoHome && existsSync33(legacyCleoHome)) {
|
|
19755
|
+
cleanupPaths.push(legacyCleoHome);
|
|
19756
|
+
}
|
|
19757
|
+
for (const homeDir of cleanupPaths) {
|
|
19758
|
+
for (const stale of STALE_GLOBAL_ENTRIES) {
|
|
19759
|
+
const stalePath = join37(homeDir, stale);
|
|
19760
|
+
if (existsSync33(stalePath)) {
|
|
19761
|
+
try {
|
|
19762
|
+
await rm2(stalePath, { recursive: true, force: true });
|
|
19763
|
+
console.warn(`[CLEO] Removed stale global entry: ${stalePath}`);
|
|
19764
|
+
} catch (err) {
|
|
19765
|
+
console.warn(
|
|
19766
|
+
`[CLEO] Could not remove stale global entry ${stalePath}: ${err instanceof Error ? err.message : String(err)}`
|
|
19767
|
+
);
|
|
19768
|
+
}
|
|
19761
19769
|
}
|
|
19762
19770
|
}
|
|
19763
19771
|
}
|
|
@@ -20966,6 +20974,225 @@ var init_decisions2 = __esm({
|
|
|
20966
20974
|
}
|
|
20967
20975
|
});
|
|
20968
20976
|
|
|
20977
|
+
// packages/core/src/migration/agent-outputs.ts
|
|
20978
|
+
import {
|
|
20979
|
+
copyFileSync as copyFileSync5,
|
|
20980
|
+
existsSync as existsSync45,
|
|
20981
|
+
mkdirSync as mkdirSync10,
|
|
20982
|
+
readdirSync as readdirSync20,
|
|
20983
|
+
readFileSync as readFileSync30,
|
|
20984
|
+
rmSync,
|
|
20985
|
+
statSync as statSync11,
|
|
20986
|
+
writeFileSync as writeFileSync4
|
|
20987
|
+
} from "node:fs";
|
|
20988
|
+
import { join as join50 } from "node:path";
|
|
20989
|
+
function detectLegacyAgentOutputs(projectRoot, cleoDir) {
|
|
20990
|
+
const hasResearchOutputs = existsSync45(join50(projectRoot, "claudedocs", "research-outputs"));
|
|
20991
|
+
const hasLegacyAgentOutputs = existsSync45(join50(projectRoot, "claudedocs", "agent-outputs"));
|
|
20992
|
+
const hasCanonical = existsSync45(join50(cleoDir, "agent-outputs"));
|
|
20993
|
+
const legacyPaths = [];
|
|
20994
|
+
if (hasResearchOutputs) legacyPaths.push("claudedocs/research-outputs/");
|
|
20995
|
+
if (hasLegacyAgentOutputs) legacyPaths.push("claudedocs/agent-outputs/");
|
|
20996
|
+
return {
|
|
20997
|
+
hasLegacy: hasResearchOutputs || hasLegacyAgentOutputs,
|
|
20998
|
+
hasResearchOutputs,
|
|
20999
|
+
hasLegacyAgentOutputs,
|
|
21000
|
+
hasCanonical,
|
|
21001
|
+
legacyPaths
|
|
21002
|
+
};
|
|
21003
|
+
}
|
|
21004
|
+
function migrateAgentOutputs(projectRoot, cleoDir) {
|
|
21005
|
+
const detection = detectLegacyAgentOutputs(projectRoot, cleoDir);
|
|
21006
|
+
if (!detection.hasLegacy) {
|
|
21007
|
+
return {
|
|
21008
|
+
migrated: false,
|
|
21009
|
+
filesCopied: 0,
|
|
21010
|
+
manifestEntries: 0,
|
|
21011
|
+
removed: [],
|
|
21012
|
+
summary: "No legacy output directories found"
|
|
21013
|
+
};
|
|
21014
|
+
}
|
|
21015
|
+
const newDir = join50(cleoDir, "agent-outputs");
|
|
21016
|
+
const hadCanonical = detection.hasCanonical;
|
|
21017
|
+
mkdirSync10(newDir, { recursive: true });
|
|
21018
|
+
let totalCopied = 0;
|
|
21019
|
+
const mergedManifestLines = [];
|
|
21020
|
+
const copiedFiles = /* @__PURE__ */ new Set();
|
|
21021
|
+
const legacySources = [
|
|
21022
|
+
{
|
|
21023
|
+
path: join50(projectRoot, "claudedocs", "research-outputs"),
|
|
21024
|
+
exists: detection.hasResearchOutputs
|
|
21025
|
+
},
|
|
21026
|
+
{
|
|
21027
|
+
path: join50(projectRoot, "claudedocs", "agent-outputs"),
|
|
21028
|
+
exists: detection.hasLegacyAgentOutputs
|
|
21029
|
+
}
|
|
21030
|
+
];
|
|
21031
|
+
for (const source of legacySources) {
|
|
21032
|
+
if (!source.exists) continue;
|
|
21033
|
+
totalCopied += copyDirContents(source.path, newDir, mergedManifestLines, copiedFiles);
|
|
21034
|
+
}
|
|
21035
|
+
const manifestEntries2 = mergeManifests(newDir, hadCanonical, mergedManifestLines);
|
|
21036
|
+
updateConfigPaths(cleoDir);
|
|
21037
|
+
const removed = removeLegacyDirs(projectRoot, detection);
|
|
21038
|
+
const parts = [`Migrated ${totalCopied} files \u2192 ${CANONICAL_DIR}/`];
|
|
21039
|
+
if (manifestEntries2 > 0) parts.push(`merged ${manifestEntries2} manifest entries`);
|
|
21040
|
+
if (removed.length > 0) parts.push(`removed: ${removed.join(", ")}`);
|
|
21041
|
+
return {
|
|
21042
|
+
migrated: true,
|
|
21043
|
+
filesCopied: totalCopied,
|
|
21044
|
+
manifestEntries: manifestEntries2,
|
|
21045
|
+
removed,
|
|
21046
|
+
summary: parts.join("; ")
|
|
21047
|
+
};
|
|
21048
|
+
}
|
|
21049
|
+
function copyDirContents(srcDir, dstDir, manifestLines, copiedFiles) {
|
|
21050
|
+
let count2 = 0;
|
|
21051
|
+
const entries = readdirSync20(srcDir);
|
|
21052
|
+
for (const entry of entries) {
|
|
21053
|
+
if (entry === "MANIFEST.jsonl") {
|
|
21054
|
+
collectManifestLines(join50(srcDir, entry), manifestLines);
|
|
21055
|
+
continue;
|
|
21056
|
+
}
|
|
21057
|
+
const srcPath = join50(srcDir, entry);
|
|
21058
|
+
const dstPath = join50(dstDir, entry);
|
|
21059
|
+
try {
|
|
21060
|
+
const st = statSync11(srcPath);
|
|
21061
|
+
if (st.isDirectory()) {
|
|
21062
|
+
mkdirSync10(dstPath, { recursive: true });
|
|
21063
|
+
for (const sf of readdirSync20(srcPath)) {
|
|
21064
|
+
if (!copiedFiles.has(sf)) {
|
|
21065
|
+
try {
|
|
21066
|
+
copyFileSync5(join50(srcPath, sf), join50(dstPath, sf));
|
|
21067
|
+
copiedFiles.add(sf);
|
|
21068
|
+
count2++;
|
|
21069
|
+
} catch {
|
|
21070
|
+
}
|
|
21071
|
+
}
|
|
21072
|
+
}
|
|
21073
|
+
} else if (!copiedFiles.has(entry)) {
|
|
21074
|
+
copyFileSync5(srcPath, dstPath);
|
|
21075
|
+
copiedFiles.add(entry);
|
|
21076
|
+
count2++;
|
|
21077
|
+
}
|
|
21078
|
+
} catch {
|
|
21079
|
+
}
|
|
21080
|
+
}
|
|
21081
|
+
return count2;
|
|
21082
|
+
}
|
|
21083
|
+
function collectManifestLines(manifestPath, out) {
|
|
21084
|
+
try {
|
|
21085
|
+
const content = readFileSync30(manifestPath, "utf-8");
|
|
21086
|
+
for (const line2 of content.split("\n")) {
|
|
21087
|
+
if (!line2.trim()) continue;
|
|
21088
|
+
let rewritten = line2;
|
|
21089
|
+
for (const [pattern, replacement] of MANIFEST_PATH_REWRITES) {
|
|
21090
|
+
rewritten = rewritten.replace(pattern, replacement);
|
|
21091
|
+
}
|
|
21092
|
+
out.push(rewritten);
|
|
21093
|
+
}
|
|
21094
|
+
} catch {
|
|
21095
|
+
}
|
|
21096
|
+
}
|
|
21097
|
+
function mergeManifests(newDir, hadCanonical, legacyLines) {
|
|
21098
|
+
const manifestPath = join50(newDir, "MANIFEST.jsonl");
|
|
21099
|
+
const existingLines = [];
|
|
21100
|
+
if (hadCanonical && existsSync45(manifestPath)) {
|
|
21101
|
+
try {
|
|
21102
|
+
const existing = readFileSync30(manifestPath, "utf-8");
|
|
21103
|
+
for (const line2 of existing.split("\n")) {
|
|
21104
|
+
if (line2.trim()) existingLines.push(line2);
|
|
21105
|
+
}
|
|
21106
|
+
} catch {
|
|
21107
|
+
}
|
|
21108
|
+
}
|
|
21109
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
21110
|
+
const finalLines = [];
|
|
21111
|
+
for (const line2 of existingLines) {
|
|
21112
|
+
try {
|
|
21113
|
+
const p = JSON.parse(line2);
|
|
21114
|
+
if (p.id) seenIds.add(p.id);
|
|
21115
|
+
} catch {
|
|
21116
|
+
}
|
|
21117
|
+
finalLines.push(line2);
|
|
21118
|
+
}
|
|
21119
|
+
for (const line2 of legacyLines) {
|
|
21120
|
+
try {
|
|
21121
|
+
const p = JSON.parse(line2);
|
|
21122
|
+
if (p.id && seenIds.has(p.id)) continue;
|
|
21123
|
+
if (p.id) seenIds.add(p.id);
|
|
21124
|
+
} catch {
|
|
21125
|
+
}
|
|
21126
|
+
finalLines.push(line2);
|
|
21127
|
+
}
|
|
21128
|
+
if (finalLines.length > 0) {
|
|
21129
|
+
writeFileSync4(manifestPath, finalLines.join("\n") + "\n");
|
|
21130
|
+
}
|
|
21131
|
+
return finalLines.length;
|
|
21132
|
+
}
|
|
21133
|
+
function updateConfigPaths(cleoDir) {
|
|
21134
|
+
const configPath = join50(cleoDir, "config.json");
|
|
21135
|
+
if (!existsSync45(configPath)) return;
|
|
21136
|
+
try {
|
|
21137
|
+
const config2 = JSON.parse(readFileSync30(configPath, "utf-8"));
|
|
21138
|
+
const currentDir = config2.agentOutputs?.directory ?? config2.agentOutputs ?? config2.research?.outputDir;
|
|
21139
|
+
if (currentDir && currentDir !== CANONICAL_DIR) {
|
|
21140
|
+
if (typeof config2.agentOutputs === "object") {
|
|
21141
|
+
config2.agentOutputs.directory = CANONICAL_DIR;
|
|
21142
|
+
} else {
|
|
21143
|
+
config2.agentOutputs = { directory: CANONICAL_DIR };
|
|
21144
|
+
}
|
|
21145
|
+
if (config2.research?.outputDir) {
|
|
21146
|
+
delete config2.research.outputDir;
|
|
21147
|
+
if (Object.keys(config2.research).length === 0) {
|
|
21148
|
+
delete config2.research;
|
|
21149
|
+
}
|
|
21150
|
+
}
|
|
21151
|
+
writeFileSync4(configPath, JSON.stringify(config2, null, 2));
|
|
21152
|
+
}
|
|
21153
|
+
} catch {
|
|
21154
|
+
}
|
|
21155
|
+
}
|
|
21156
|
+
function removeLegacyDirs(projectRoot, detection) {
|
|
21157
|
+
const removed = [];
|
|
21158
|
+
if (detection.hasResearchOutputs) {
|
|
21159
|
+
try {
|
|
21160
|
+
rmSync(join50(projectRoot, "claudedocs", "research-outputs"), { recursive: true, force: true });
|
|
21161
|
+
removed.push("claudedocs/research-outputs/");
|
|
21162
|
+
} catch {
|
|
21163
|
+
}
|
|
21164
|
+
}
|
|
21165
|
+
if (detection.hasLegacyAgentOutputs) {
|
|
21166
|
+
try {
|
|
21167
|
+
rmSync(join50(projectRoot, "claudedocs", "agent-outputs"), { recursive: true, force: true });
|
|
21168
|
+
removed.push("claudedocs/agent-outputs/");
|
|
21169
|
+
} catch {
|
|
21170
|
+
}
|
|
21171
|
+
}
|
|
21172
|
+
const claudedocsDir = join50(projectRoot, "claudedocs");
|
|
21173
|
+
if (existsSync45(claudedocsDir)) {
|
|
21174
|
+
try {
|
|
21175
|
+
if (readdirSync20(claudedocsDir).length === 0) {
|
|
21176
|
+
rmSync(claudedocsDir, { recursive: true, force: true });
|
|
21177
|
+
removed.push("claudedocs/ (empty)");
|
|
21178
|
+
}
|
|
21179
|
+
} catch {
|
|
21180
|
+
}
|
|
21181
|
+
}
|
|
21182
|
+
return removed;
|
|
21183
|
+
}
|
|
21184
|
+
var CANONICAL_DIR, MANIFEST_PATH_REWRITES;
|
|
21185
|
+
var init_agent_outputs = __esm({
|
|
21186
|
+
"packages/core/src/migration/agent-outputs.ts"() {
|
|
21187
|
+
"use strict";
|
|
21188
|
+
CANONICAL_DIR = ".cleo/agent-outputs";
|
|
21189
|
+
MANIFEST_PATH_REWRITES = [
|
|
21190
|
+
[/claudedocs\/research-outputs\//g, `${CANONICAL_DIR}/`],
|
|
21191
|
+
[/claudedocs\/agent-outputs\//g, `${CANONICAL_DIR}/`]
|
|
21192
|
+
];
|
|
21193
|
+
}
|
|
21194
|
+
});
|
|
21195
|
+
|
|
20969
21196
|
// packages/core/src/nexus/migrate-json-to-sqlite.ts
|
|
20970
21197
|
var migrate_json_to_sqlite_exports = {};
|
|
20971
21198
|
__export(migrate_json_to_sqlite_exports, {
|
|
@@ -21202,10 +21429,10 @@ async function readProjectMeta(projectPath) {
|
|
|
21202
21429
|
}
|
|
21203
21430
|
async function readProjectId(projectPath) {
|
|
21204
21431
|
try {
|
|
21205
|
-
const { readFileSync:
|
|
21432
|
+
const { readFileSync: readFileSync77, existsSync: existsSync103 } = await import("node:fs");
|
|
21206
21433
|
const infoPath = join57(projectPath, ".cleo", "project-info.json");
|
|
21207
|
-
if (!
|
|
21208
|
-
const data = JSON.parse(
|
|
21434
|
+
if (!existsSync103(infoPath)) return "";
|
|
21435
|
+
const data = JSON.parse(readFileSync77(infoPath, "utf-8"));
|
|
21209
21436
|
return typeof data.projectId === "string" ? data.projectId : "";
|
|
21210
21437
|
} catch {
|
|
21211
21438
|
return "";
|
|
@@ -24005,6 +24232,539 @@ var init_hooks = __esm({
|
|
|
24005
24232
|
}
|
|
24006
24233
|
});
|
|
24007
24234
|
|
|
24235
|
+
// packages/core/src/init.ts
|
|
24236
|
+
var init_exports = {};
|
|
24237
|
+
__export(init_exports, {
|
|
24238
|
+
ensureInitialized: () => ensureInitialized,
|
|
24239
|
+
getVersion: () => getVersion2,
|
|
24240
|
+
initAgentDefinition: () => initAgentDefinition,
|
|
24241
|
+
initCoreSkills: () => initCoreSkills,
|
|
24242
|
+
initMcpServer: () => initMcpServer,
|
|
24243
|
+
initNexusRegistration: () => initNexusRegistration,
|
|
24244
|
+
initProject: () => initProject,
|
|
24245
|
+
installGitHubTemplates: () => installGitHubTemplates,
|
|
24246
|
+
isAutoInitEnabled: () => isAutoInitEnabled,
|
|
24247
|
+
updateDocs: () => updateDocs
|
|
24248
|
+
});
|
|
24249
|
+
import { existsSync as existsSync99, readdirSync as readdirSync33, readFileSync as readFileSync73 } from "node:fs";
|
|
24250
|
+
import { copyFile as copyFile3, lstat, mkdir as mkdir16, readFile as readFile17, symlink, unlink as unlink4, writeFile as writeFile11 } from "node:fs/promises";
|
|
24251
|
+
import { platform as platform4 } from "node:os";
|
|
24252
|
+
import { basename as basename17, dirname as dirname19, join as join100 } from "node:path";
|
|
24253
|
+
async function initAgentDefinition(created, warnings) {
|
|
24254
|
+
let agentSourceDir = null;
|
|
24255
|
+
try {
|
|
24256
|
+
const { createRequire: createRequire5 } = await import("node:module");
|
|
24257
|
+
const req = createRequire5(import.meta.url);
|
|
24258
|
+
const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
|
|
24259
|
+
const agentsPkgRoot = dirname19(agentsPkgMain);
|
|
24260
|
+
const candidate = join100(agentsPkgRoot, "cleo-subagent");
|
|
24261
|
+
if (existsSync99(candidate)) {
|
|
24262
|
+
agentSourceDir = candidate;
|
|
24263
|
+
}
|
|
24264
|
+
} catch {
|
|
24265
|
+
}
|
|
24266
|
+
if (!agentSourceDir) {
|
|
24267
|
+
const packageRoot = getPackageRoot();
|
|
24268
|
+
const bundled = join100(packageRoot, "agents", "cleo-subagent");
|
|
24269
|
+
if (existsSync99(bundled)) {
|
|
24270
|
+
agentSourceDir = bundled;
|
|
24271
|
+
}
|
|
24272
|
+
}
|
|
24273
|
+
if (!agentSourceDir) {
|
|
24274
|
+
warnings.push("agents/cleo-subagent/ not found in package, skipping agent definition install");
|
|
24275
|
+
return;
|
|
24276
|
+
}
|
|
24277
|
+
const globalAgentsDir = join100(getAgentsHome(), "agents", "cleo-subagent");
|
|
24278
|
+
await mkdir16(dirname19(globalAgentsDir), { recursive: true });
|
|
24279
|
+
try {
|
|
24280
|
+
try {
|
|
24281
|
+
const stat2 = await lstat(globalAgentsDir);
|
|
24282
|
+
if (stat2.isSymbolicLink()) {
|
|
24283
|
+
const { readlink } = await import("node:fs/promises");
|
|
24284
|
+
const currentTarget = await readlink(globalAgentsDir);
|
|
24285
|
+
if (currentTarget === agentSourceDir) {
|
|
24286
|
+
return;
|
|
24287
|
+
}
|
|
24288
|
+
await unlink4(globalAgentsDir);
|
|
24289
|
+
} else if (stat2.isDirectory()) {
|
|
24290
|
+
return;
|
|
24291
|
+
}
|
|
24292
|
+
} catch {
|
|
24293
|
+
}
|
|
24294
|
+
await symlink(agentSourceDir, globalAgentsDir, DIR_SYMLINK_TYPE2);
|
|
24295
|
+
created.push("agent: cleo-subagent (symlinked)");
|
|
24296
|
+
} catch (_err) {
|
|
24297
|
+
try {
|
|
24298
|
+
await mkdir16(globalAgentsDir, { recursive: true });
|
|
24299
|
+
const files = readdirSync33(agentSourceDir);
|
|
24300
|
+
for (const file2 of files) {
|
|
24301
|
+
await copyFile3(join100(agentSourceDir, file2), join100(globalAgentsDir, file2));
|
|
24302
|
+
}
|
|
24303
|
+
created.push("agent: cleo-subagent (copied)");
|
|
24304
|
+
} catch (copyErr) {
|
|
24305
|
+
warnings.push(
|
|
24306
|
+
`Agent definition install: ${copyErr instanceof Error ? copyErr.message : String(copyErr)}`
|
|
24307
|
+
);
|
|
24308
|
+
}
|
|
24309
|
+
}
|
|
24310
|
+
}
|
|
24311
|
+
async function initMcpServer(projectRoot, created, warnings) {
|
|
24312
|
+
try {
|
|
24313
|
+
const { detectEnvMode: detectEnvMode2, generateMcpServerEntry: generateMcpServerEntry2, getMcpServerName: getMcpServerName2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
24314
|
+
const { getInstalledProviders: getInstalledProviders3, installMcpServerToAll } = await import("@cleocode/caamp");
|
|
24315
|
+
const env = detectEnvMode2();
|
|
24316
|
+
const serverEntry = generateMcpServerEntry2(env);
|
|
24317
|
+
const serverName = getMcpServerName2(env);
|
|
24318
|
+
const providers = getInstalledProviders3();
|
|
24319
|
+
if (providers.length === 0) {
|
|
24320
|
+
return;
|
|
24321
|
+
}
|
|
24322
|
+
const results = await installMcpServerToAll(
|
|
24323
|
+
providers,
|
|
24324
|
+
serverName,
|
|
24325
|
+
serverEntry,
|
|
24326
|
+
"global",
|
|
24327
|
+
projectRoot
|
|
24328
|
+
);
|
|
24329
|
+
const successes = results.filter((r) => r.success);
|
|
24330
|
+
const failures = results.filter((r) => !r.success);
|
|
24331
|
+
if (successes.length > 0) {
|
|
24332
|
+
created.push(`MCP server: ${successes.map((r) => r.provider.id).join(", ")}`);
|
|
24333
|
+
}
|
|
24334
|
+
for (const f of failures) {
|
|
24335
|
+
if (f.error) {
|
|
24336
|
+
warnings.push(`MCP install to ${f.provider.id}: ${f.error}`);
|
|
24337
|
+
}
|
|
24338
|
+
}
|
|
24339
|
+
} catch (err) {
|
|
24340
|
+
warnings.push(`MCP server install: ${err instanceof Error ? err.message : String(err)}`);
|
|
24341
|
+
}
|
|
24342
|
+
}
|
|
24343
|
+
async function initCoreSkills(created, warnings) {
|
|
24344
|
+
try {
|
|
24345
|
+
const { getInstalledProviders: getInstalledProviders3, installSkill: installSkill2, registerSkillLibraryFromPath } = await import("@cleocode/caamp");
|
|
24346
|
+
const providers = getInstalledProviders3();
|
|
24347
|
+
if (providers.length === 0) {
|
|
24348
|
+
return;
|
|
24349
|
+
}
|
|
24350
|
+
const packageRoot = getPackageRoot();
|
|
24351
|
+
let ctSkillsRoot = null;
|
|
24352
|
+
try {
|
|
24353
|
+
const { createRequire: createRequire5 } = await import("node:module");
|
|
24354
|
+
const req = createRequire5(import.meta.url);
|
|
24355
|
+
const skillsPkgMain = req.resolve("@cleocode/skills/package.json");
|
|
24356
|
+
const skillsPkgRoot = dirname19(skillsPkgMain);
|
|
24357
|
+
if (existsSync99(join100(skillsPkgRoot, "skills.json"))) {
|
|
24358
|
+
ctSkillsRoot = skillsPkgRoot;
|
|
24359
|
+
}
|
|
24360
|
+
} catch {
|
|
24361
|
+
}
|
|
24362
|
+
if (!ctSkillsRoot) {
|
|
24363
|
+
try {
|
|
24364
|
+
const bundledPath = join100(packageRoot, "packages", "skills");
|
|
24365
|
+
if (existsSync99(join100(bundledPath, "skills.json"))) {
|
|
24366
|
+
ctSkillsRoot = bundledPath;
|
|
24367
|
+
} else {
|
|
24368
|
+
const ctSkillsPath = join100(packageRoot, "node_modules", "@cleocode", "skills");
|
|
24369
|
+
if (existsSync99(join100(ctSkillsPath, "skills.json"))) {
|
|
24370
|
+
ctSkillsRoot = ctSkillsPath;
|
|
24371
|
+
}
|
|
24372
|
+
}
|
|
24373
|
+
} catch {
|
|
24374
|
+
}
|
|
24375
|
+
}
|
|
24376
|
+
if (!ctSkillsRoot) {
|
|
24377
|
+
warnings.push("skills package not found, skipping core skill installation");
|
|
24378
|
+
return;
|
|
24379
|
+
}
|
|
24380
|
+
try {
|
|
24381
|
+
registerSkillLibraryFromPath(ctSkillsRoot);
|
|
24382
|
+
} catch {
|
|
24383
|
+
warnings.push("Failed to register skill library with CAAMP");
|
|
24384
|
+
}
|
|
24385
|
+
const catalogPath = join100(ctSkillsRoot, "skills.json");
|
|
24386
|
+
const catalog3 = JSON.parse(readFileSync73(catalogPath, "utf-8"));
|
|
24387
|
+
const skills = catalog3.skills ?? [];
|
|
24388
|
+
const coreSkills = skills.filter((s) => s.tier <= 2);
|
|
24389
|
+
const installed = [];
|
|
24390
|
+
for (const skill of coreSkills) {
|
|
24391
|
+
const skillSourceDir = dirname19(join100(ctSkillsRoot, skill.path));
|
|
24392
|
+
if (!existsSync99(skillSourceDir)) {
|
|
24393
|
+
continue;
|
|
24394
|
+
}
|
|
24395
|
+
try {
|
|
24396
|
+
const result = await installSkill2(skillSourceDir, skill.name, providers, true);
|
|
24397
|
+
if (result.success) {
|
|
24398
|
+
installed.push(skill.name);
|
|
24399
|
+
}
|
|
24400
|
+
} catch {
|
|
24401
|
+
}
|
|
24402
|
+
}
|
|
24403
|
+
if (installed.length > 0) {
|
|
24404
|
+
created.push(`skills: ${installed.length} core skills installed`);
|
|
24405
|
+
}
|
|
24406
|
+
} catch (err) {
|
|
24407
|
+
warnings.push(`Core skill install: ${err instanceof Error ? err.message : String(err)}`);
|
|
24408
|
+
}
|
|
24409
|
+
}
|
|
24410
|
+
async function initNexusRegistration(projectRoot, created, warnings) {
|
|
24411
|
+
try {
|
|
24412
|
+
const { nexusReconcile: nexusReconcile2 } = await Promise.resolve().then(() => (init_registry3(), registry_exports3));
|
|
24413
|
+
const result = await nexusReconcile2(projectRoot);
|
|
24414
|
+
if (result.status === "auto_registered") {
|
|
24415
|
+
created.push("NEXUS registration (auto-registered new project)");
|
|
24416
|
+
} else if (result.status === "path_updated") {
|
|
24417
|
+
created.push(`NEXUS registration (path updated: ${result.oldPath} \u2192 ${result.newPath})`);
|
|
24418
|
+
} else if (result.status === "ok") {
|
|
24419
|
+
created.push("NEXUS registration (project verified and active)");
|
|
24420
|
+
}
|
|
24421
|
+
} catch (err) {
|
|
24422
|
+
const errStr = String(err);
|
|
24423
|
+
if (errStr.includes("NEXUS_PROJECT_EXISTS")) {
|
|
24424
|
+
warnings.push("NEXUS registration: Project already registered");
|
|
24425
|
+
} else if (errStr.includes("NEXUS_REGISTRY_CORRUPT")) {
|
|
24426
|
+
warnings.push(
|
|
24427
|
+
`NEXUS registration: Identity conflict - ${err instanceof Error ? err.message : errStr}. Run 'cleo nexus unregister' and re-register.`
|
|
24428
|
+
);
|
|
24429
|
+
} else {
|
|
24430
|
+
warnings.push(`NEXUS registration: ${err instanceof Error ? err.message : errStr}`);
|
|
24431
|
+
}
|
|
24432
|
+
}
|
|
24433
|
+
}
|
|
24434
|
+
async function installGitHubTemplates(projectRoot, created, skipped) {
|
|
24435
|
+
if (!existsSync99(join100(projectRoot, ".git"))) {
|
|
24436
|
+
return;
|
|
24437
|
+
}
|
|
24438
|
+
const githubDir = join100(projectRoot, ".github");
|
|
24439
|
+
const issueTemplateDir = join100(githubDir, "ISSUE_TEMPLATE");
|
|
24440
|
+
const packageRoot = getPackageRoot();
|
|
24441
|
+
const templateSrcDir = join100(packageRoot, "templates", "github");
|
|
24442
|
+
if (!existsSync99(templateSrcDir)) {
|
|
24443
|
+
return;
|
|
24444
|
+
}
|
|
24445
|
+
await mkdir16(issueTemplateDir, { recursive: true });
|
|
24446
|
+
const issueSrcDir = join100(templateSrcDir, "ISSUE_TEMPLATE");
|
|
24447
|
+
if (existsSync99(issueSrcDir)) {
|
|
24448
|
+
const issueFiles = readdirSync33(issueSrcDir);
|
|
24449
|
+
for (const file2 of issueFiles) {
|
|
24450
|
+
const dest = join100(issueTemplateDir, file2);
|
|
24451
|
+
if (existsSync99(dest)) {
|
|
24452
|
+
skipped.push(`.github/ISSUE_TEMPLATE/${file2}`);
|
|
24453
|
+
continue;
|
|
24454
|
+
}
|
|
24455
|
+
const content = readFileSync73(join100(issueSrcDir, file2), "utf-8");
|
|
24456
|
+
await writeFile11(dest, content, "utf-8");
|
|
24457
|
+
created.push(`.github/ISSUE_TEMPLATE/${file2}`);
|
|
24458
|
+
}
|
|
24459
|
+
}
|
|
24460
|
+
const prTemplateSrc = join100(templateSrcDir, "pull_request_template.md");
|
|
24461
|
+
const prTemplateDest = join100(githubDir, "pull_request_template.md");
|
|
24462
|
+
if (existsSync99(prTemplateSrc)) {
|
|
24463
|
+
if (existsSync99(prTemplateDest)) {
|
|
24464
|
+
skipped.push(".github/pull_request_template.md");
|
|
24465
|
+
} else {
|
|
24466
|
+
const content = readFileSync73(prTemplateSrc, "utf-8");
|
|
24467
|
+
await writeFile11(prTemplateDest, content, "utf-8");
|
|
24468
|
+
created.push(".github/pull_request_template.md");
|
|
24469
|
+
}
|
|
24470
|
+
}
|
|
24471
|
+
}
|
|
24472
|
+
async function updateDocs() {
|
|
24473
|
+
const cleoDir = getCleoDirAbsolute();
|
|
24474
|
+
const projRoot = getProjectRoot();
|
|
24475
|
+
const created = [];
|
|
24476
|
+
const warnings = [];
|
|
24477
|
+
try {
|
|
24478
|
+
const result = await ensureInjection(projRoot);
|
|
24479
|
+
if (result.action !== "skipped") {
|
|
24480
|
+
created.push(`injection: ${result.details ?? result.action}`);
|
|
24481
|
+
}
|
|
24482
|
+
} catch (err) {
|
|
24483
|
+
warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
|
|
24484
|
+
}
|
|
24485
|
+
return {
|
|
24486
|
+
initialized: true,
|
|
24487
|
+
directory: cleoDir,
|
|
24488
|
+
created,
|
|
24489
|
+
skipped: [],
|
|
24490
|
+
warnings,
|
|
24491
|
+
updateDocsOnly: true
|
|
24492
|
+
};
|
|
24493
|
+
}
|
|
24494
|
+
async function initProject(opts = {}) {
|
|
24495
|
+
const cleoDir = getCleoDirAbsolute();
|
|
24496
|
+
const projRoot = getProjectRoot();
|
|
24497
|
+
const alreadyInitialized = existsSync99(cleoDir) && (existsSync99(join100(cleoDir, "tasks.db")) || existsSync99(join100(cleoDir, "config.json")));
|
|
24498
|
+
if (alreadyInitialized && !opts.force) {
|
|
24499
|
+
throw new CleoError(
|
|
24500
|
+
1 /* GENERAL_ERROR */,
|
|
24501
|
+
"Project already initialized. DANGER ZONE: use --force to wipe and re-init.",
|
|
24502
|
+
{ fix: "cleo init --force" }
|
|
24503
|
+
);
|
|
24504
|
+
}
|
|
24505
|
+
const force = !!opts.force;
|
|
24506
|
+
const created = [];
|
|
24507
|
+
const skipped = [];
|
|
24508
|
+
const warnings = [];
|
|
24509
|
+
const structureResult = await ensureCleoStructure(projRoot);
|
|
24510
|
+
if (structureResult.action === "created") {
|
|
24511
|
+
created.push(".cleo/ directory structure");
|
|
24512
|
+
}
|
|
24513
|
+
const configResult = await ensureConfig(projRoot, { force });
|
|
24514
|
+
if (configResult.action === "skipped") {
|
|
24515
|
+
skipped.push("config.json");
|
|
24516
|
+
} else {
|
|
24517
|
+
created.push("config.json");
|
|
24518
|
+
}
|
|
24519
|
+
try {
|
|
24520
|
+
const { getDb: getDb3 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
24521
|
+
await getDb3(join100(cleoDir, ".."));
|
|
24522
|
+
created.push("tasks.db");
|
|
24523
|
+
} catch (err) {
|
|
24524
|
+
created.push(`tasks.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
|
|
24525
|
+
}
|
|
24526
|
+
try {
|
|
24527
|
+
const brainResult = await ensureBrainDb(projRoot);
|
|
24528
|
+
if (brainResult.action === "created") {
|
|
24529
|
+
created.push("brain.db");
|
|
24530
|
+
}
|
|
24531
|
+
} catch (err) {
|
|
24532
|
+
created.push(`brain.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
|
|
24533
|
+
}
|
|
24534
|
+
if (force) {
|
|
24535
|
+
const gitignoreResult = await ensureGitignore(projRoot);
|
|
24536
|
+
if (gitignoreResult.action === "skipped") {
|
|
24537
|
+
skipped.push(".gitignore");
|
|
24538
|
+
} else {
|
|
24539
|
+
created.push(".gitignore");
|
|
24540
|
+
}
|
|
24541
|
+
} else {
|
|
24542
|
+
const gitignorePath = join100(cleoDir, ".gitignore");
|
|
24543
|
+
if (existsSync99(gitignorePath)) {
|
|
24544
|
+
skipped.push(".gitignore");
|
|
24545
|
+
} else {
|
|
24546
|
+
const gitignoreResult = await ensureGitignore(projRoot);
|
|
24547
|
+
if (gitignoreResult.action !== "skipped") {
|
|
24548
|
+
created.push(".gitignore");
|
|
24549
|
+
} else {
|
|
24550
|
+
skipped.push(".gitignore");
|
|
24551
|
+
}
|
|
24552
|
+
}
|
|
24553
|
+
}
|
|
24554
|
+
const legacySequencePath = join100(cleoDir, ".sequence");
|
|
24555
|
+
try {
|
|
24556
|
+
await unlink4(legacySequencePath);
|
|
24557
|
+
} catch {
|
|
24558
|
+
}
|
|
24559
|
+
const legacySequenceJsonPath = join100(cleoDir, ".sequence.json");
|
|
24560
|
+
try {
|
|
24561
|
+
await unlink4(legacySequenceJsonPath);
|
|
24562
|
+
} catch {
|
|
24563
|
+
}
|
|
24564
|
+
try {
|
|
24565
|
+
const gitRepoResult = await ensureCleoGitRepo(projRoot);
|
|
24566
|
+
if (gitRepoResult.action === "created") {
|
|
24567
|
+
created.push(".cleo/.git (isolated checkpoint repository)");
|
|
24568
|
+
}
|
|
24569
|
+
} catch (err) {
|
|
24570
|
+
warnings.push(
|
|
24571
|
+
`Could not initialize .cleo/.git: ${err instanceof Error ? err.message : String(err)}`
|
|
24572
|
+
);
|
|
24573
|
+
}
|
|
24574
|
+
try {
|
|
24575
|
+
const migrationResult = migrateAgentOutputs(projRoot, cleoDir);
|
|
24576
|
+
if (migrationResult.migrated) {
|
|
24577
|
+
created.push(`agent-outputs migration: ${migrationResult.summary}`);
|
|
24578
|
+
}
|
|
24579
|
+
} catch {
|
|
24580
|
+
warnings.push("Agent-outputs migration failed (best-effort, run cleo upgrade to retry)");
|
|
24581
|
+
}
|
|
24582
|
+
try {
|
|
24583
|
+
const schemaResult = ensureGlobalSchemas({ force });
|
|
24584
|
+
const total = schemaResult.installed + schemaResult.updated;
|
|
24585
|
+
if (total > 0) {
|
|
24586
|
+
created.push(`schemas/ (${total} files)`);
|
|
24587
|
+
}
|
|
24588
|
+
} catch (err) {
|
|
24589
|
+
warnings.push(`Schema installation: ${err instanceof Error ? err.message : String(err)}`);
|
|
24590
|
+
}
|
|
24591
|
+
try {
|
|
24592
|
+
const hooksResult = await ensureGitHooks(projRoot, { force });
|
|
24593
|
+
if (hooksResult.action === "created") {
|
|
24594
|
+
created.push(hooksResult.details ?? "git hooks installed");
|
|
24595
|
+
} else if (hooksResult.action === "skipped" && hooksResult.details?.includes("No .git/")) {
|
|
24596
|
+
warnings.push(hooksResult.details);
|
|
24597
|
+
} else if (hooksResult.action === "skipped" && hooksResult.details?.includes("not found in package root")) {
|
|
24598
|
+
warnings.push(hooksResult.details);
|
|
24599
|
+
} else if (hooksResult.action === "repaired" && hooksResult.details?.includes("error")) {
|
|
24600
|
+
const match = hooksResult.details.match(/Installed (\d+)/);
|
|
24601
|
+
if (match && parseInt(match[1], 10) > 0) {
|
|
24602
|
+
created.push(`git hooks (${match[1]} installed)`);
|
|
24603
|
+
}
|
|
24604
|
+
warnings.push(hooksResult.details);
|
|
24605
|
+
}
|
|
24606
|
+
} catch (err) {
|
|
24607
|
+
warnings.push(`Git hook installation: ${err instanceof Error ? err.message : String(err)}`);
|
|
24608
|
+
}
|
|
24609
|
+
const projectInfoResult = await ensureProjectInfo(projRoot, { force });
|
|
24610
|
+
if (projectInfoResult.action === "skipped") {
|
|
24611
|
+
skipped.push("project-info.json");
|
|
24612
|
+
} else {
|
|
24613
|
+
created.push("project-info.json");
|
|
24614
|
+
}
|
|
24615
|
+
try {
|
|
24616
|
+
const detectResult = await ensureProjectContext(projRoot, { force: !!opts.detect });
|
|
24617
|
+
if (detectResult.action !== "skipped") {
|
|
24618
|
+
created.push("project-context.json");
|
|
24619
|
+
}
|
|
24620
|
+
} catch (err) {
|
|
24621
|
+
warnings.push(`Project detection failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
24622
|
+
}
|
|
24623
|
+
if (opts.mapCodebase) {
|
|
24624
|
+
try {
|
|
24625
|
+
const { mapCodebase: mapCodebase2 } = await Promise.resolve().then(() => (init_codebase_map(), codebase_map_exports));
|
|
24626
|
+
const mapResult = await mapCodebase2(projRoot, { storeToBrain: true });
|
|
24627
|
+
created.push(
|
|
24628
|
+
`codebase-map: ${mapResult.stack.languages.length} languages, ${mapResult.architecture.layers.length} layers analyzed`
|
|
24629
|
+
);
|
|
24630
|
+
} catch (err) {
|
|
24631
|
+
warnings.push(`Codebase mapping: ${err instanceof Error ? err.message : String(err)}`);
|
|
24632
|
+
}
|
|
24633
|
+
}
|
|
24634
|
+
try {
|
|
24635
|
+
const bridgeResult = await writeMemoryBridge(projRoot);
|
|
24636
|
+
if (bridgeResult.written) {
|
|
24637
|
+
created.push("memory-bridge.md");
|
|
24638
|
+
}
|
|
24639
|
+
} catch (err) {
|
|
24640
|
+
warnings.push(`Memory bridge: ${err instanceof Error ? err.message : String(err)}`);
|
|
24641
|
+
}
|
|
24642
|
+
try {
|
|
24643
|
+
const injectionResult = await ensureInjection(projRoot);
|
|
24644
|
+
if (injectionResult.action !== "skipped") {
|
|
24645
|
+
if (injectionResult.details) {
|
|
24646
|
+
created.push(`injection: ${injectionResult.details}`);
|
|
24647
|
+
}
|
|
24648
|
+
} else if (injectionResult.details) {
|
|
24649
|
+
warnings.push(injectionResult.details);
|
|
24650
|
+
}
|
|
24651
|
+
} catch (err) {
|
|
24652
|
+
warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
|
|
24653
|
+
}
|
|
24654
|
+
try {
|
|
24655
|
+
const { ensureContributorMcp: ensureContributorMcp2 } = await Promise.resolve().then(() => (init_scaffold(), scaffold_exports));
|
|
24656
|
+
const mcpResult = await ensureContributorMcp2(projRoot);
|
|
24657
|
+
if (mcpResult.action !== "skipped") {
|
|
24658
|
+
created.push(`contributor MCP: ${mcpResult.details ?? mcpResult.action}`);
|
|
24659
|
+
}
|
|
24660
|
+
} catch (err) {
|
|
24661
|
+
warnings.push(`Contributor MCP setup: ${err instanceof Error ? err.message : String(err)}`);
|
|
24662
|
+
}
|
|
24663
|
+
await initAgentDefinition(created, warnings);
|
|
24664
|
+
await initNexusRegistration(projRoot, created, warnings);
|
|
24665
|
+
try {
|
|
24666
|
+
const { AdapterManager: AdapterManager2 } = await Promise.resolve().then(() => (init_adapters(), adapters_exports));
|
|
24667
|
+
const mgr = AdapterManager2.getInstance(projRoot);
|
|
24668
|
+
const manifests = mgr.discover();
|
|
24669
|
+
if (manifests.length > 0) {
|
|
24670
|
+
created.push(`adapters: ${manifests.length} adapter(s) discovered`);
|
|
24671
|
+
const detected = mgr.detectActive();
|
|
24672
|
+
if (detected.length > 0) {
|
|
24673
|
+
created.push(`adapters: active provider detected (${detected.join(", ")})`);
|
|
24674
|
+
for (const adapterId of detected) {
|
|
24675
|
+
try {
|
|
24676
|
+
const adapter = await mgr.activate(adapterId);
|
|
24677
|
+
const installResult = await adapter.install.install({
|
|
24678
|
+
projectDir: projRoot
|
|
24679
|
+
});
|
|
24680
|
+
if (installResult.success) {
|
|
24681
|
+
created.push(`adapter install (${adapterId}): installed`);
|
|
24682
|
+
} else {
|
|
24683
|
+
warnings.push(`adapter install (${adapterId}): failed`);
|
|
24684
|
+
}
|
|
24685
|
+
} catch (err) {
|
|
24686
|
+
warnings.push(
|
|
24687
|
+
`adapter activate/install (${adapterId}): ${err instanceof Error ? err.message : String(err)}`
|
|
24688
|
+
);
|
|
24689
|
+
}
|
|
24690
|
+
}
|
|
24691
|
+
}
|
|
24692
|
+
}
|
|
24693
|
+
} catch (err) {
|
|
24694
|
+
warnings.push(`Adapter discovery: ${err instanceof Error ? err.message : String(err)}`);
|
|
24695
|
+
}
|
|
24696
|
+
try {
|
|
24697
|
+
await installGitHubTemplates(projRoot, created, skipped);
|
|
24698
|
+
} catch (err) {
|
|
24699
|
+
warnings.push(`GitHub templates: ${err instanceof Error ? err.message : String(err)}`);
|
|
24700
|
+
}
|
|
24701
|
+
const rootGitignoreResult = await removeCleoFromRootGitignore(projRoot);
|
|
24702
|
+
if (rootGitignoreResult.removed) {
|
|
24703
|
+
warnings.push(
|
|
24704
|
+
".cleo/ was found in root .gitignore and has been removed. CLEO uses .cleo/.gitignore for selective tracking."
|
|
24705
|
+
);
|
|
24706
|
+
}
|
|
24707
|
+
return {
|
|
24708
|
+
initialized: true,
|
|
24709
|
+
directory: cleoDir,
|
|
24710
|
+
created,
|
|
24711
|
+
skipped,
|
|
24712
|
+
warnings
|
|
24713
|
+
};
|
|
24714
|
+
}
|
|
24715
|
+
function isAutoInitEnabled() {
|
|
24716
|
+
return process.env.CLEO_AUTO_INIT === "true";
|
|
24717
|
+
}
|
|
24718
|
+
async function ensureInitialized(projectRoot) {
|
|
24719
|
+
const root = projectRoot ?? getProjectRoot();
|
|
24720
|
+
const cleoDir = join100(root, ".cleo");
|
|
24721
|
+
const isInit = existsSync99(cleoDir) && (existsSync99(join100(cleoDir, "tasks.db")) || existsSync99(join100(cleoDir, "config.json")));
|
|
24722
|
+
if (isInit) {
|
|
24723
|
+
return { initialized: true };
|
|
24724
|
+
}
|
|
24725
|
+
if (isAutoInitEnabled()) {
|
|
24726
|
+
await initProject({ name: basename17(root) });
|
|
24727
|
+
return { initialized: true };
|
|
24728
|
+
}
|
|
24729
|
+
throw new Error("CLEO project not initialized. Run system.init or set CLEO_AUTO_INIT=true");
|
|
24730
|
+
}
|
|
24731
|
+
async function getVersion2(projectRoot) {
|
|
24732
|
+
const root = projectRoot ?? getProjectRoot();
|
|
24733
|
+
const versionPaths = [join100(root, "VERSION"), join100(root, "..", "VERSION")];
|
|
24734
|
+
for (const versionPath of versionPaths) {
|
|
24735
|
+
try {
|
|
24736
|
+
const content = await readFile17(versionPath, "utf-8");
|
|
24737
|
+
const version2 = content.trim();
|
|
24738
|
+
if (version2) {
|
|
24739
|
+
return { version: version2 };
|
|
24740
|
+
}
|
|
24741
|
+
} catch {
|
|
24742
|
+
}
|
|
24743
|
+
}
|
|
24744
|
+
const pkg = await readJson(join100(root, "package.json"));
|
|
24745
|
+
if (pkg?.version) {
|
|
24746
|
+
return { version: pkg.version };
|
|
24747
|
+
}
|
|
24748
|
+
return { version: "0.0.0" };
|
|
24749
|
+
}
|
|
24750
|
+
var DIR_SYMLINK_TYPE2;
|
|
24751
|
+
var init_init = __esm({
|
|
24752
|
+
"packages/core/src/init.ts"() {
|
|
24753
|
+
"use strict";
|
|
24754
|
+
init_src();
|
|
24755
|
+
init_errors3();
|
|
24756
|
+
init_hooks();
|
|
24757
|
+
init_injection();
|
|
24758
|
+
init_memory_bridge();
|
|
24759
|
+
init_agent_outputs();
|
|
24760
|
+
init_paths();
|
|
24761
|
+
init_scaffold();
|
|
24762
|
+
init_schema_management();
|
|
24763
|
+
init_json2();
|
|
24764
|
+
DIR_SYMLINK_TYPE2 = platform4() === "win32" ? "junction" : "dir";
|
|
24765
|
+
}
|
|
24766
|
+
});
|
|
24767
|
+
|
|
24008
24768
|
// packages/core/src/index.ts
|
|
24009
24769
|
init_src();
|
|
24010
24770
|
init_adapters();
|
|
@@ -42540,219 +43300,7 @@ __export(migration_exports, {
|
|
|
42540
43300
|
verifyBackup: () => verifyBackup,
|
|
42541
43301
|
verifySourceIntegrity: () => verifySourceIntegrity
|
|
42542
43302
|
});
|
|
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
|
-
}
|
|
43303
|
+
init_agent_outputs();
|
|
42756
43304
|
|
|
42757
43305
|
// packages/core/src/migration/checksum.ts
|
|
42758
43306
|
import { createHash as createHash5 } from "node:crypto";
|
|
@@ -54215,8 +54763,8 @@ async function initializeSpawnAdapters(manifests) {
|
|
|
54215
54763
|
if (!manifest.capabilities?.supportsSpawn) continue;
|
|
54216
54764
|
if (spawnRegistry.hasAdapterForProvider(manifest.provider)) continue;
|
|
54217
54765
|
try {
|
|
54218
|
-
const { join:
|
|
54219
|
-
const modulePath =
|
|
54766
|
+
const { join: join104 } = await import("node:path");
|
|
54767
|
+
const modulePath = join104(manifest.packagePath, manifest.entryPoint);
|
|
54220
54768
|
const adapterModule = await import(modulePath);
|
|
54221
54769
|
let SpawnProviderClass;
|
|
54222
54770
|
for (const [exportName, exportValue] of Object.entries(adapterModule)) {
|
|
@@ -55804,6 +56352,7 @@ var CORE_PROTECTED_FILES = [
|
|
|
55804
56352
|
];
|
|
55805
56353
|
|
|
55806
56354
|
// packages/core/src/validation/doctor/checks.ts
|
|
56355
|
+
init_agent_outputs();
|
|
55807
56356
|
init_paths();
|
|
55808
56357
|
init_scaffold();
|
|
55809
56358
|
init_schema_management();
|
|
@@ -61813,400 +62362,7 @@ function isCleoRegisteredCode(lafsCode) {
|
|
|
61813
62362
|
|
|
61814
62363
|
// packages/core/src/index.ts
|
|
61815
62364
|
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
|
|
62365
|
+
init_init();
|
|
62210
62366
|
init_json_schema_validator();
|
|
62211
62367
|
init_logger();
|
|
62212
62368
|
|
|
@@ -62346,6 +62502,223 @@ function getProjectInfoSync(cwd) {
|
|
|
62346
62502
|
init_scaffold();
|
|
62347
62503
|
init_adapters();
|
|
62348
62504
|
|
|
62505
|
+
// packages/core/src/bootstrap.ts
|
|
62506
|
+
init_paths();
|
|
62507
|
+
init_scaffold();
|
|
62508
|
+
import { existsSync as existsSync102, readFileSync as readFileSync76 } from "node:fs";
|
|
62509
|
+
import { mkdir as mkdir17, readFile as readFile19, writeFile as writeFile12 } from "node:fs/promises";
|
|
62510
|
+
import { homedir as homedir6 } from "node:os";
|
|
62511
|
+
import { join as join103 } from "node:path";
|
|
62512
|
+
async function bootstrapGlobalCleo(options) {
|
|
62513
|
+
const ctx = {
|
|
62514
|
+
created: [],
|
|
62515
|
+
warnings: [],
|
|
62516
|
+
isDryRun: options?.dryRun ?? false
|
|
62517
|
+
};
|
|
62518
|
+
try {
|
|
62519
|
+
await ensureGlobalHome();
|
|
62520
|
+
} catch {
|
|
62521
|
+
}
|
|
62522
|
+
await ensureGlobalTemplatesBootstrap(ctx, options?.packageRoot);
|
|
62523
|
+
await injectAgentsHub(ctx);
|
|
62524
|
+
await installMcpToProviders(ctx);
|
|
62525
|
+
await installSkillsGlobally(ctx);
|
|
62526
|
+
await installAgentDefinitionGlobally(ctx);
|
|
62527
|
+
await installProviderAdapters(ctx, options?.packageRoot);
|
|
62528
|
+
return ctx;
|
|
62529
|
+
}
|
|
62530
|
+
async function ensureGlobalTemplatesBootstrap(ctx, packageRootOverride) {
|
|
62531
|
+
const globalTemplatesDir = getCleoTemplatesDir();
|
|
62532
|
+
if (!ctx.isDryRun) {
|
|
62533
|
+
await mkdir17(globalTemplatesDir, { recursive: true });
|
|
62534
|
+
}
|
|
62535
|
+
try {
|
|
62536
|
+
const pkgRoot = packageRootOverride ?? getPackageRoot();
|
|
62537
|
+
const templatePath = join103(pkgRoot, "templates", "CLEO-INJECTION.md");
|
|
62538
|
+
if (existsSync102(templatePath)) {
|
|
62539
|
+
const content = readFileSync76(templatePath, "utf-8");
|
|
62540
|
+
const destPath = join103(globalTemplatesDir, "CLEO-INJECTION.md");
|
|
62541
|
+
if (!ctx.isDryRun) {
|
|
62542
|
+
await writeFile12(destPath, content);
|
|
62543
|
+
}
|
|
62544
|
+
ctx.created.push(
|
|
62545
|
+
`~/.cleo/templates/CLEO-INJECTION.md (${ctx.isDryRun ? "would refresh" : "refreshed"})`
|
|
62546
|
+
);
|
|
62547
|
+
} else {
|
|
62548
|
+
try {
|
|
62549
|
+
const { getInjectionTemplateContent: getInjectionTemplateContent2 } = await Promise.resolve().then(() => (init_injection(), injection_exports));
|
|
62550
|
+
const content = getInjectionTemplateContent2();
|
|
62551
|
+
if (content) {
|
|
62552
|
+
const destPath = join103(globalTemplatesDir, "CLEO-INJECTION.md");
|
|
62553
|
+
if (!ctx.isDryRun) {
|
|
62554
|
+
await writeFile12(destPath, content);
|
|
62555
|
+
}
|
|
62556
|
+
ctx.created.push(
|
|
62557
|
+
`~/.cleo/templates/CLEO-INJECTION.md (${ctx.isDryRun ? "would refresh" : "refreshed"} from embedded)`
|
|
62558
|
+
);
|
|
62559
|
+
}
|
|
62560
|
+
} catch {
|
|
62561
|
+
ctx.warnings.push("Could not refresh CLEO-INJECTION.md template");
|
|
62562
|
+
}
|
|
62563
|
+
}
|
|
62564
|
+
} catch {
|
|
62565
|
+
ctx.warnings.push("Could not refresh CLEO-INJECTION.md template");
|
|
62566
|
+
}
|
|
62567
|
+
}
|
|
62568
|
+
async function injectAgentsHub(ctx) {
|
|
62569
|
+
const globalAgentsDir = getAgentsHome();
|
|
62570
|
+
const globalAgentsMd = join103(globalAgentsDir, "AGENTS.md");
|
|
62571
|
+
try {
|
|
62572
|
+
const { inject: inject2, getInstalledProviders: getInstalledProviders3, injectAll: injectAll2, buildInjectionContent } = await import("@cleocode/caamp");
|
|
62573
|
+
if (!ctx.isDryRun) {
|
|
62574
|
+
await mkdir17(globalAgentsDir, { recursive: true });
|
|
62575
|
+
if (existsSync102(globalAgentsMd)) {
|
|
62576
|
+
const content = await readFile19(globalAgentsMd, "utf8");
|
|
62577
|
+
const stripped = content.replace(
|
|
62578
|
+
/\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
|
|
62579
|
+
""
|
|
62580
|
+
);
|
|
62581
|
+
if (stripped !== content) {
|
|
62582
|
+
await writeFile12(globalAgentsMd, stripped, "utf8");
|
|
62583
|
+
}
|
|
62584
|
+
}
|
|
62585
|
+
const expectedContent = "@~/.cleo/templates/CLEO-INJECTION.md";
|
|
62586
|
+
const action = await inject2(globalAgentsMd, expectedContent);
|
|
62587
|
+
ctx.created.push(`~/.agents/AGENTS.md (${action})`);
|
|
62588
|
+
} else {
|
|
62589
|
+
ctx.created.push("~/.agents/AGENTS.md (would create/update CAAMP block)");
|
|
62590
|
+
}
|
|
62591
|
+
const providers = getInstalledProviders3();
|
|
62592
|
+
if (providers.length === 0) {
|
|
62593
|
+
ctx.warnings.push("No AI provider installations detected");
|
|
62594
|
+
} else {
|
|
62595
|
+
const injectionContent = buildInjectionContent({
|
|
62596
|
+
references: ["@~/.agents/AGENTS.md"]
|
|
62597
|
+
});
|
|
62598
|
+
if (!ctx.isDryRun) {
|
|
62599
|
+
for (const provider of providers) {
|
|
62600
|
+
const instructFilePath = join103(provider.pathGlobal, provider.instructFile);
|
|
62601
|
+
if (existsSync102(instructFilePath)) {
|
|
62602
|
+
const fileContent = await readFile19(instructFilePath, "utf8");
|
|
62603
|
+
const stripped = fileContent.replace(
|
|
62604
|
+
/\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
|
|
62605
|
+
""
|
|
62606
|
+
);
|
|
62607
|
+
if (stripped !== fileContent) {
|
|
62608
|
+
await writeFile12(instructFilePath, stripped, "utf8");
|
|
62609
|
+
}
|
|
62610
|
+
}
|
|
62611
|
+
}
|
|
62612
|
+
const results = await injectAll2(providers, homedir6(), "global", injectionContent);
|
|
62613
|
+
for (const [filePath, action] of results) {
|
|
62614
|
+
const displayPath = filePath.replace(homedir6(), "~");
|
|
62615
|
+
ctx.created.push(`${displayPath} (${action})`);
|
|
62616
|
+
}
|
|
62617
|
+
} else {
|
|
62618
|
+
for (const p of providers) {
|
|
62619
|
+
const displayPath = join103(p.pathGlobal, p.instructFile).replace(homedir6(), "~");
|
|
62620
|
+
ctx.created.push(`${displayPath} (would update CAAMP block)`);
|
|
62621
|
+
}
|
|
62622
|
+
}
|
|
62623
|
+
}
|
|
62624
|
+
} catch (err) {
|
|
62625
|
+
ctx.warnings.push(`CAAMP injection: ${err instanceof Error ? err.message : String(err)}`);
|
|
62626
|
+
}
|
|
62627
|
+
}
|
|
62628
|
+
async function installMcpToProviders(ctx) {
|
|
62629
|
+
try {
|
|
62630
|
+
const { detectEnvMode: detectEnvMode2, generateMcpServerEntry: generateMcpServerEntry2, getMcpServerName: getMcpServerName2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
62631
|
+
const { getInstalledProviders: getInstalledProviders3, installMcpServerToAll } = await import("@cleocode/caamp");
|
|
62632
|
+
const env = detectEnvMode2();
|
|
62633
|
+
const serverEntry = generateMcpServerEntry2(env);
|
|
62634
|
+
const serverName = getMcpServerName2(env);
|
|
62635
|
+
const providers = getInstalledProviders3();
|
|
62636
|
+
if (providers.length > 0) {
|
|
62637
|
+
if (!ctx.isDryRun) {
|
|
62638
|
+
const results = await installMcpServerToAll(
|
|
62639
|
+
providers,
|
|
62640
|
+
serverName,
|
|
62641
|
+
serverEntry,
|
|
62642
|
+
"global",
|
|
62643
|
+
homedir6()
|
|
62644
|
+
);
|
|
62645
|
+
const successes = results.filter((r) => r.success);
|
|
62646
|
+
if (successes.length > 0) {
|
|
62647
|
+
ctx.created.push(
|
|
62648
|
+
`MCP configs: ${successes.map((r) => r.provider.id).join(", ")}`
|
|
62649
|
+
);
|
|
62650
|
+
}
|
|
62651
|
+
} else {
|
|
62652
|
+
ctx.created.push("MCP configs (would update)");
|
|
62653
|
+
}
|
|
62654
|
+
}
|
|
62655
|
+
} catch {
|
|
62656
|
+
ctx.warnings.push("MCP config update skipped (non-critical)");
|
|
62657
|
+
}
|
|
62658
|
+
}
|
|
62659
|
+
async function installSkillsGlobally(ctx) {
|
|
62660
|
+
try {
|
|
62661
|
+
if (!ctx.isDryRun) {
|
|
62662
|
+
const { initCoreSkills: initCoreSkills2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
62663
|
+
await initCoreSkills2(ctx.created, ctx.warnings);
|
|
62664
|
+
} else {
|
|
62665
|
+
ctx.created.push("core skills (would install/update)");
|
|
62666
|
+
}
|
|
62667
|
+
} catch (err) {
|
|
62668
|
+
ctx.warnings.push(
|
|
62669
|
+
`Core skills installation failed: ${err instanceof Error ? err.message : String(err)}`
|
|
62670
|
+
);
|
|
62671
|
+
}
|
|
62672
|
+
}
|
|
62673
|
+
async function installAgentDefinitionGlobally(ctx) {
|
|
62674
|
+
try {
|
|
62675
|
+
if (!ctx.isDryRun) {
|
|
62676
|
+
const { initAgentDefinition: initAgentDefinition2 } = await Promise.resolve().then(() => (init_init(), init_exports));
|
|
62677
|
+
await initAgentDefinition2(ctx.created, ctx.warnings);
|
|
62678
|
+
} else {
|
|
62679
|
+
ctx.created.push("agent: cleo-subagent (would symlink)");
|
|
62680
|
+
}
|
|
62681
|
+
} catch (err) {
|
|
62682
|
+
ctx.warnings.push(
|
|
62683
|
+
`Agent definition install: ${err instanceof Error ? err.message : String(err)}`
|
|
62684
|
+
);
|
|
62685
|
+
}
|
|
62686
|
+
}
|
|
62687
|
+
async function installProviderAdapters(ctx, packageRootOverride) {
|
|
62688
|
+
try {
|
|
62689
|
+
const { AdapterManager: AdapterManager2 } = await Promise.resolve().then(() => (init_adapters(), adapters_exports));
|
|
62690
|
+
const pkgRoot = packageRootOverride ?? getPackageRoot();
|
|
62691
|
+
const manager = AdapterManager2.getInstance(pkgRoot);
|
|
62692
|
+
manager.discover();
|
|
62693
|
+
const detected = manager.detectActive();
|
|
62694
|
+
for (const adapterId of detected) {
|
|
62695
|
+
try {
|
|
62696
|
+
const adapter = await manager.activate(adapterId);
|
|
62697
|
+
if (adapter.install) {
|
|
62698
|
+
if (!ctx.isDryRun) {
|
|
62699
|
+
const installResult = await adapter.install.install({
|
|
62700
|
+
projectDir: process.cwd()
|
|
62701
|
+
});
|
|
62702
|
+
if (installResult.success) {
|
|
62703
|
+
ctx.created.push(`${adapterId} adapter (installed)`);
|
|
62704
|
+
}
|
|
62705
|
+
} else {
|
|
62706
|
+
ctx.created.push(`${adapterId} adapter (would install)`);
|
|
62707
|
+
}
|
|
62708
|
+
}
|
|
62709
|
+
} catch (activateErr) {
|
|
62710
|
+
ctx.warnings.push(
|
|
62711
|
+
`Adapter ${adapterId} skipped: ${activateErr instanceof Error ? activateErr.message : String(activateErr)}`
|
|
62712
|
+
);
|
|
62713
|
+
}
|
|
62714
|
+
}
|
|
62715
|
+
} catch (err) {
|
|
62716
|
+
ctx.warnings.push(
|
|
62717
|
+
`Adapter install skipped: ${err instanceof Error ? err.message : String(err)}`
|
|
62718
|
+
);
|
|
62719
|
+
}
|
|
62720
|
+
}
|
|
62721
|
+
|
|
62349
62722
|
// packages/core/src/cleo.ts
|
|
62350
62723
|
import path from "node:path";
|
|
62351
62724
|
init_brain_retrieval();
|
|
@@ -62632,6 +63005,7 @@ export {
|
|
|
62632
63005
|
agentTypeSchema,
|
|
62633
63006
|
agents_exports as agents,
|
|
62634
63007
|
archiveTasks,
|
|
63008
|
+
bootstrapGlobalCleo,
|
|
62635
63009
|
brainConfidenceLevelSchema,
|
|
62636
63010
|
brainDecisionTypeSchema,
|
|
62637
63011
|
brainEdgeTypeSchema,
|