@cleocode/core 2026.4.47 → 2026.4.49
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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +730 -362
- package/dist/index.js.map +4 -4
- package/dist/internal.d.ts +4 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1061 -683
- package/dist/internal.js.map +4 -4
- package/dist/nexus/index.d.ts +1 -1
- package/dist/nexus/index.d.ts.map +1 -1
- package/dist/nexus/registry.d.ts +25 -0
- package/dist/nexus/registry.d.ts.map +1 -1
- package/dist/store/nexus-schema.d.ts +64 -0
- package/dist/store/nexus-schema.d.ts.map +1 -1
- package/dist/store/nexus-validation-schemas.d.ts +128 -0
- package/dist/store/nexus-validation-schemas.d.ts.map +1 -1
- package/dist/telemetry/index.d.ts +107 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/schema.d.ts +228 -0
- package/dist/telemetry/schema.d.ts.map +1 -0
- package/dist/telemetry/sqlite.d.ts +33 -0
- package/dist/telemetry/sqlite.d.ts.map +1 -0
- package/migrations/drizzle-telemetry/20260415000001_t624-initial/migration.sql +23 -0
- package/migrations/drizzle-telemetry/20260415000001_t624-initial/snapshot.json +35 -0
- package/package.json +8 -8
- package/src/__tests__/telemetry.test.ts +221 -0
- package/src/index.ts +1 -0
- package/src/internal.ts +20 -1
- package/src/nexus/index.ts +2 -0
- package/src/nexus/registry.ts +103 -1
- package/src/store/nexus-schema.ts +9 -0
- package/src/telemetry/index.ts +341 -0
- package/src/telemetry/schema.ts +68 -0
- package/src/telemetry/sqlite.ts +140 -0
package/dist/internal.js
CHANGED
|
@@ -14,11 +14,11 @@ var __export = (target, all) => {
|
|
|
14
14
|
for (var name2 in all)
|
|
15
15
|
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
16
16
|
};
|
|
17
|
-
var __copyProps = (to2, from, except2,
|
|
17
|
+
var __copyProps = (to2, from, except2, desc8) => {
|
|
18
18
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
19
|
for (let key of __getOwnPropNames(from))
|
|
20
20
|
if (!__hasOwnProp.call(to2, key) && key !== except2)
|
|
21
|
-
__defProp(to2, key, { get: () => from[key], enumerable: !(
|
|
21
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc8 = __getOwnPropDesc(from, key)) || desc8.enumerable });
|
|
22
22
|
}
|
|
23
23
|
return to2;
|
|
24
24
|
};
|
|
@@ -753,15 +753,15 @@ function getLogDir() {
|
|
|
753
753
|
return currentLogDir;
|
|
754
754
|
}
|
|
755
755
|
function closeLogger() {
|
|
756
|
-
return new Promise((
|
|
756
|
+
return new Promise((resolve15) => {
|
|
757
757
|
if (rootLogger) {
|
|
758
758
|
rootLogger.flush(() => {
|
|
759
759
|
rootLogger = null;
|
|
760
760
|
currentLogDir = null;
|
|
761
|
-
|
|
761
|
+
resolve15();
|
|
762
762
|
});
|
|
763
763
|
} else {
|
|
764
|
-
|
|
764
|
+
resolve15();
|
|
765
765
|
}
|
|
766
766
|
});
|
|
767
767
|
}
|
|
@@ -1569,10 +1569,10 @@ var init_subquery = __esm({
|
|
|
1569
1569
|
init_entity();
|
|
1570
1570
|
Subquery = class {
|
|
1571
1571
|
static [entityKind] = "Subquery";
|
|
1572
|
-
constructor(
|
|
1572
|
+
constructor(sql16, fields, alias, isWith = false, usedTables = []) {
|
|
1573
1573
|
this._ = {
|
|
1574
1574
|
brand: "Subquery",
|
|
1575
|
-
sql:
|
|
1575
|
+
sql: sql16,
|
|
1576
1576
|
selectedFields: fields,
|
|
1577
1577
|
alias,
|
|
1578
1578
|
isWith,
|
|
@@ -1923,7 +1923,7 @@ var init_sql = __esm({
|
|
|
1923
1923
|
return new SQL([new StringChunk(str)]);
|
|
1924
1924
|
}
|
|
1925
1925
|
_sql.raw = raw;
|
|
1926
|
-
function
|
|
1926
|
+
function join123(chunks, separator) {
|
|
1927
1927
|
const result = [];
|
|
1928
1928
|
for (const [i, chunk] of chunks.entries()) {
|
|
1929
1929
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -1931,7 +1931,7 @@ var init_sql = __esm({
|
|
|
1931
1931
|
}
|
|
1932
1932
|
return new SQL(result);
|
|
1933
1933
|
}
|
|
1934
|
-
_sql.join =
|
|
1934
|
+
_sql.join = join123;
|
|
1935
1935
|
function identifier(value) {
|
|
1936
1936
|
return new Name(value);
|
|
1937
1937
|
}
|
|
@@ -1952,8 +1952,8 @@ var init_sql = __esm({
|
|
|
1952
1952
|
isSelectionField = false;
|
|
1953
1953
|
/** @internal */
|
|
1954
1954
|
origin;
|
|
1955
|
-
constructor(
|
|
1956
|
-
this.sql =
|
|
1955
|
+
constructor(sql16, fieldAlias) {
|
|
1956
|
+
this.sql = sql16;
|
|
1957
1957
|
this.fieldAlias = fieldAlias;
|
|
1958
1958
|
}
|
|
1959
1959
|
getSQL() {
|
|
@@ -2657,17 +2657,17 @@ var init_custom = __esm({
|
|
|
2657
2657
|
mapFromJsonValue(value) {
|
|
2658
2658
|
return typeof this.mapJson === "function" ? this.mapJson(value) : this.mapFromDriverValue(value);
|
|
2659
2659
|
}
|
|
2660
|
-
jsonSelectIdentifier(identifier,
|
|
2661
|
-
if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier,
|
|
2660
|
+
jsonSelectIdentifier(identifier, sql16) {
|
|
2661
|
+
if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier, sql16);
|
|
2662
2662
|
const rawType = this.getSQLType().toLowerCase();
|
|
2663
2663
|
const parenPos = rawType.indexOf("(");
|
|
2664
2664
|
switch (parenPos + 1 ? rawType.slice(0, parenPos) : rawType) {
|
|
2665
2665
|
case "numeric":
|
|
2666
2666
|
case "decimal":
|
|
2667
2667
|
case "bigint":
|
|
2668
|
-
return
|
|
2668
|
+
return sql16`cast(${identifier} as text)`;
|
|
2669
2669
|
case "blob":
|
|
2670
|
-
return
|
|
2670
|
+
return sql16`hex(${identifier})`;
|
|
2671
2671
|
default:
|
|
2672
2672
|
return identifier;
|
|
2673
2673
|
}
|
|
@@ -3835,8 +3835,8 @@ var init_custom2 = __esm({
|
|
|
3835
3835
|
mapFromJsonValue(value) {
|
|
3836
3836
|
return typeof this.mapJson === "function" ? this.mapJson(value) : this.mapFromDriverValue(value);
|
|
3837
3837
|
}
|
|
3838
|
-
jsonSelectIdentifier(identifier,
|
|
3839
|
-
if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier,
|
|
3838
|
+
jsonSelectIdentifier(identifier, sql16, arrayDimensions) {
|
|
3839
|
+
if (typeof this.forJsonSelect === "function") return this.forJsonSelect(identifier, sql16, arrayDimensions);
|
|
3840
3840
|
const rawType = this.getSQLType().toLowerCase();
|
|
3841
3841
|
const parenPos = rawType.indexOf("(");
|
|
3842
3842
|
switch (parenPos + 1 ? rawType.slice(0, parenPos) : rawType) {
|
|
@@ -3846,7 +3846,7 @@ var init_custom2 = __esm({
|
|
|
3846
3846
|
case "numeric":
|
|
3847
3847
|
case "bigint": {
|
|
3848
3848
|
const arrVal = "[]".repeat(arrayDimensions ?? 0);
|
|
3849
|
-
return
|
|
3849
|
+
return sql16`${identifier}::text${sql16.raw(arrVal).if(arrayDimensions)}`;
|
|
3850
3850
|
}
|
|
3851
3851
|
default:
|
|
3852
3852
|
return identifier;
|
|
@@ -6705,7 +6705,7 @@ var init_select2 = __esm({
|
|
|
6705
6705
|
const baseTableName = this.tableName;
|
|
6706
6706
|
const tableName = getTableLikeName(table);
|
|
6707
6707
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
6708
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
6708
|
+
if (typeof tableName === "string" && this.config.joins?.some((join123) => join123.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
6709
6709
|
if (!this.isPartialSelect) {
|
|
6710
6710
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
6711
6711
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -7727,8 +7727,8 @@ var init_dialect = __esm({
|
|
|
7727
7727
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
|
7728
7728
|
return sql`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflict?.length ? sql.join(onConflict) : void 0}${returningSql}`;
|
|
7729
7729
|
}
|
|
7730
|
-
sqlToQuery(
|
|
7731
|
-
return
|
|
7730
|
+
sqlToQuery(sql16, invokeSource) {
|
|
7731
|
+
return sql16.toQuery({
|
|
7732
7732
|
casing: this.casing,
|
|
7733
7733
|
escapeName: this.escapeName,
|
|
7734
7734
|
escapeParam: this.escapeParam,
|
|
@@ -7990,7 +7990,7 @@ var init_dialect = __esm({
|
|
|
7990
7990
|
if (!joins2) return;
|
|
7991
7991
|
const withEntries = Object.entries(joins2).filter(([_2, v2]) => v2);
|
|
7992
7992
|
if (!withEntries.length) return;
|
|
7993
|
-
return sql.join(withEntries.map(([k2,
|
|
7993
|
+
return sql.join(withEntries.map(([k2, join123]) => {
|
|
7994
7994
|
const relation = tableConfig.relations[k2];
|
|
7995
7995
|
const isSingle2 = is(relation, One3);
|
|
7996
7996
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -8001,7 +8001,7 @@ var init_dialect = __esm({
|
|
|
8001
8001
|
table: targetTable,
|
|
8002
8002
|
mode: isSingle2 ? "first" : "many",
|
|
8003
8003
|
schema,
|
|
8004
|
-
queryConfig:
|
|
8004
|
+
queryConfig: join123,
|
|
8005
8005
|
tableConfig: schema[relation.targetTableName],
|
|
8006
8006
|
relationWhere: filter,
|
|
8007
8007
|
isNested: true,
|
|
@@ -8015,7 +8015,7 @@ var init_dialect = __esm({
|
|
|
8015
8015
|
key: k2,
|
|
8016
8016
|
selection: innerQuery.selection,
|
|
8017
8017
|
isArray: !isSingle2,
|
|
8018
|
-
isOptional: (relation.optional ?? false) ||
|
|
8018
|
+
isOptional: (relation.optional ?? false) || join123 !== true && !!join123.where
|
|
8019
8019
|
});
|
|
8020
8020
|
const jsonColumns = sql.join(innerQuery.selection.map((s3) => {
|
|
8021
8021
|
return sql`${sql.raw(this.escapeString(s3.key))}, ${s3.selection ? sql`${jsonb2}(${sql.identifier(s3.key)})` : sql.identifier(s3.key)}`;
|
|
@@ -8414,7 +8414,7 @@ var init_update = __esm({
|
|
|
8414
8414
|
createJoin(joinType) {
|
|
8415
8415
|
return ((table, on) => {
|
|
8416
8416
|
const tableName = getTableLikeName(table);
|
|
8417
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
8417
|
+
if (typeof tableName === "string" && this.config.joins.some((join123) => join123.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
8418
8418
|
if (typeof on === "function") {
|
|
8419
8419
|
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;
|
|
8420
8420
|
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -8825,8 +8825,8 @@ var init_db = __esm({
|
|
|
8825
8825
|
});
|
|
8826
8826
|
|
|
8827
8827
|
// node_modules/.pnpm/drizzle-orm@1.0.0-beta.19-d95b7a4_@sinclair+typebox@0.34.49_@types+mssql@9.1.9_@azure+c_7d603f9dc53f6bedf2f8e8db5954b691/node_modules/drizzle-orm/cache/core/cache.js
|
|
8828
|
-
async function hashQuery(
|
|
8829
|
-
const dataToHash = `${
|
|
8828
|
+
async function hashQuery(sql16, params) {
|
|
8829
|
+
const dataToHash = `${sql16}-${JSON.stringify(params, (_2, v2) => typeof v2 === "bigint" ? `${v2}n` : v2)}`;
|
|
8830
8830
|
const data = new TextEncoder().encode(dataToHash);
|
|
8831
8831
|
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
8832
8832
|
return [...new Uint8Array(hashBuffer)].map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
@@ -9005,8 +9005,8 @@ var init_session3 = __esm({
|
|
|
9005
9005
|
values(query) {
|
|
9006
9006
|
return this.prepareOneTimeQuery(this.dialect.sqlToQuery(query), void 0, "run", false).values();
|
|
9007
9007
|
}
|
|
9008
|
-
async count(
|
|
9009
|
-
return (await this.values(
|
|
9008
|
+
async count(sql16) {
|
|
9009
|
+
return (await this.values(sql16))[0][0];
|
|
9010
9010
|
}
|
|
9011
9011
|
/** @internal */
|
|
9012
9012
|
extractRawValuesValueFromBatchResult(_result) {
|
|
@@ -11693,12 +11693,12 @@ function detachAgentFromProject(db, agentId) {
|
|
|
11693
11693
|
}
|
|
11694
11694
|
function listProjectAgentRefs(db, opts) {
|
|
11695
11695
|
const enabledOnly = opts?.enabledOnly ?? true;
|
|
11696
|
-
const
|
|
11696
|
+
const sql16 = enabledOnly ? `SELECT agent_id, attached_at, role, capabilities_override, last_used_at, enabled
|
|
11697
11697
|
FROM project_agent_refs WHERE enabled = 1
|
|
11698
11698
|
ORDER BY attached_at DESC` : `SELECT agent_id, attached_at, role, capabilities_override, last_used_at, enabled
|
|
11699
11699
|
FROM project_agent_refs
|
|
11700
11700
|
ORDER BY attached_at DESC`;
|
|
11701
|
-
const rows = db.prepare(
|
|
11701
|
+
const rows = db.prepare(sql16).all();
|
|
11702
11702
|
return rows.map((r) => ({
|
|
11703
11703
|
agentId: r.agent_id,
|
|
11704
11704
|
attachedAt: r.attached_at,
|
|
@@ -12102,12 +12102,21 @@ var init_nexus_schema = __esm({
|
|
|
12102
12102
|
permissions: text("permissions").notNull().default("read"),
|
|
12103
12103
|
lastSync: text("last_sync").notNull().default(sql3`(datetime('now'))`),
|
|
12104
12104
|
taskCount: integer("task_count").notNull().default(0),
|
|
12105
|
-
labelsJson: text("labels_json").notNull().default("[]")
|
|
12105
|
+
labelsJson: text("labels_json").notNull().default("[]"),
|
|
12106
|
+
/** Absolute path to the project's brain.db file. */
|
|
12107
|
+
brainDbPath: text("brain_db_path"),
|
|
12108
|
+
/** Absolute path to the project's tasks.db file. */
|
|
12109
|
+
tasksDbPath: text("tasks_db_path"),
|
|
12110
|
+
/** ISO 8601 timestamp of the last successful code intelligence index run. */
|
|
12111
|
+
lastIndexed: text("last_indexed"),
|
|
12112
|
+
/** JSON object with per-project code intelligence stats (node_count, relation_count, file_count). */
|
|
12113
|
+
statsJson: text("stats_json").notNull().default("{}")
|
|
12106
12114
|
},
|
|
12107
12115
|
(table) => [
|
|
12108
12116
|
index("idx_project_registry_hash").on(table.projectHash),
|
|
12109
12117
|
index("idx_project_registry_health").on(table.healthStatus),
|
|
12110
|
-
index("idx_project_registry_name").on(table.name)
|
|
12118
|
+
index("idx_project_registry_name").on(table.name),
|
|
12119
|
+
index("idx_project_registry_last_indexed").on(table.lastIndexed)
|
|
12111
12120
|
]
|
|
12112
12121
|
);
|
|
12113
12122
|
nexusAuditLog = sqliteTable(
|
|
@@ -17224,7 +17233,7 @@ async function linkPipelineAdr(projectRoot, taskId) {
|
|
|
17224
17233
|
return result;
|
|
17225
17234
|
}
|
|
17226
17235
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
17227
|
-
const { and:
|
|
17236
|
+
const { and: and14, eq: eq17 } = await import("drizzle-orm");
|
|
17228
17237
|
const db = await getDb4(projectRoot);
|
|
17229
17238
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
17230
17239
|
for (const filePath of matchingFiles) {
|
|
@@ -17259,7 +17268,7 @@ async function linkPipelineAdr(projectRoot, taskId) {
|
|
|
17259
17268
|
await db.insert(architectureDecisions).values({ ...rowBase, createdAt: now2 });
|
|
17260
17269
|
}
|
|
17261
17270
|
result.synced++;
|
|
17262
|
-
await db.delete(adrTaskLinks).where(
|
|
17271
|
+
await db.delete(adrTaskLinks).where(and14(eq17(adrTaskLinks.adrId, record2.id), eq17(adrTaskLinks.taskId, taskId)));
|
|
17263
17272
|
await db.insert(adrTaskLinks).values({ adrId: record2.id, taskId, linkType: "implements" });
|
|
17264
17273
|
result.linked.push({ adrId: record2.id, taskId });
|
|
17265
17274
|
if (fm["Related ADRs"]) {
|
|
@@ -18098,7 +18107,7 @@ async function withRetry(fn2, policy) {
|
|
|
18098
18107
|
if (!shouldRetry(err, attempt, effectivePolicy)) break;
|
|
18099
18108
|
const delay = calculateDelay(attempt, effectivePolicy);
|
|
18100
18109
|
totalDelayMs += delay;
|
|
18101
|
-
await new Promise((
|
|
18110
|
+
await new Promise((resolve15) => setTimeout(resolve15, delay));
|
|
18102
18111
|
}
|
|
18103
18112
|
}
|
|
18104
18113
|
const error48 = lastError instanceof Error ? lastError : new Error(String(lastError));
|
|
@@ -18794,7 +18803,7 @@ function analyzeStructure(projectRoot) {
|
|
|
18794
18803
|
}
|
|
18795
18804
|
function countFiles(dir, depth = 0) {
|
|
18796
18805
|
if (depth > 5) return 0;
|
|
18797
|
-
let
|
|
18806
|
+
let count5 = 0;
|
|
18798
18807
|
const entries = safeReaddir2(dir);
|
|
18799
18808
|
for (const entry of entries) {
|
|
18800
18809
|
if (EXCLUDED_DIRS.has(entry) || entry.startsWith(".")) continue;
|
|
@@ -18802,14 +18811,14 @@ function countFiles(dir, depth = 0) {
|
|
|
18802
18811
|
try {
|
|
18803
18812
|
const stat3 = statSync3(entryPath);
|
|
18804
18813
|
if (stat3.isDirectory()) {
|
|
18805
|
-
|
|
18814
|
+
count5 += countFiles(entryPath, depth + 1);
|
|
18806
18815
|
} else {
|
|
18807
|
-
|
|
18816
|
+
count5++;
|
|
18808
18817
|
}
|
|
18809
18818
|
} catch {
|
|
18810
18819
|
}
|
|
18811
18820
|
}
|
|
18812
|
-
return
|
|
18821
|
+
return count5;
|
|
18813
18822
|
}
|
|
18814
18823
|
function safeReaddir2(dir) {
|
|
18815
18824
|
try {
|
|
@@ -20168,8 +20177,8 @@ function checkFts5Available(nativeDb) {
|
|
|
20168
20177
|
}
|
|
20169
20178
|
return _fts5Available;
|
|
20170
20179
|
}
|
|
20171
|
-
function execDDL(nativeDb,
|
|
20172
|
-
nativeDb.prepare(
|
|
20180
|
+
function execDDL(nativeDb, sql16) {
|
|
20181
|
+
nativeDb.prepare(sql16).run();
|
|
20173
20182
|
}
|
|
20174
20183
|
function ensureFts5Tables(nativeDb) {
|
|
20175
20184
|
if (!checkFts5Available(nativeDb)) {
|
|
@@ -21002,8 +21011,8 @@ __export(memory_bridge_exports, {
|
|
|
21002
21011
|
});
|
|
21003
21012
|
import { existsSync as existsSync29, mkdirSync as mkdirSync8, readFileSync as readFileSync15, writeFileSync as writeFileSync2 } from "node:fs";
|
|
21004
21013
|
import { join as join31 } from "node:path";
|
|
21005
|
-
function typedAll2(db,
|
|
21006
|
-
return db.prepare(
|
|
21014
|
+
function typedAll2(db, sql16, ...params) {
|
|
21015
|
+
return db.prepare(sql16).all(...params);
|
|
21007
21016
|
}
|
|
21008
21017
|
async function generateMemoryBridgeContent(projectRoot, config2) {
|
|
21009
21018
|
const cfg = { ...DEFAULT_CONFIG, ...config2 };
|
|
@@ -21325,7 +21334,7 @@ async function queryAudit(options) {
|
|
|
21325
21334
|
try {
|
|
21326
21335
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
21327
21336
|
const { auditLog: auditLog2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
|
|
21328
|
-
const { and:
|
|
21337
|
+
const { and: and14, eq: eq17, gte: gte4, or: or7 } = await import("drizzle-orm");
|
|
21329
21338
|
const db = await getDb4(process.cwd());
|
|
21330
21339
|
const conditions = [];
|
|
21331
21340
|
if (options?.sessionId) conditions.push(eq17(auditLog2.sessionId, options.sessionId));
|
|
@@ -21337,7 +21346,7 @@ async function queryAudit(options) {
|
|
|
21337
21346
|
if (options?.taskId) conditions.push(eq17(auditLog2.taskId, options.taskId));
|
|
21338
21347
|
if (options?.since) conditions.push(gte4(auditLog2.timestamp, options.since));
|
|
21339
21348
|
const limit = options?.limit ?? 1e3;
|
|
21340
|
-
const rows = await db.select().from(auditLog2).where(conditions.length > 0 ?
|
|
21349
|
+
const rows = await db.select().from(auditLog2).where(conditions.length > 0 ? and14(...conditions) : void 0).orderBy(auditLog2.timestamp).limit(limit);
|
|
21341
21350
|
return rows.map((row) => ({
|
|
21342
21351
|
timestamp: row.timestamp,
|
|
21343
21352
|
sessionId: row.sessionId,
|
|
@@ -21465,8 +21474,8 @@ async function gradeSession(sessionId, cwd) {
|
|
|
21465
21474
|
);
|
|
21466
21475
|
let hygieneScore = 20;
|
|
21467
21476
|
for (const addCall of addCalls) {
|
|
21468
|
-
const
|
|
21469
|
-
if (!
|
|
21477
|
+
const desc8 = addCall.params?.description;
|
|
21478
|
+
if (!desc8 || desc8.trim().length === 0) {
|
|
21470
21479
|
hygieneScore -= 5;
|
|
21471
21480
|
result.flags.push(
|
|
21472
21481
|
`tasks.add without description (taskId: ${addCall.metadata?.taskId ?? "unknown"})`
|
|
@@ -21695,9 +21704,9 @@ __export(decisions_exports, {
|
|
|
21695
21704
|
async function nextDecisionId(projectRoot) {
|
|
21696
21705
|
const { getBrainDb: getBrainDb2 } = await Promise.resolve().then(() => (init_brain_sqlite(), brain_sqlite_exports));
|
|
21697
21706
|
const { brainDecisions: brainDecisions2 } = await Promise.resolve().then(() => (init_brain_schema(), brain_schema_exports));
|
|
21698
|
-
const { desc:
|
|
21707
|
+
const { desc: desc8 } = await import("drizzle-orm");
|
|
21699
21708
|
const db = await getBrainDb2(projectRoot);
|
|
21700
|
-
const rows = await db.select({ id: brainDecisions2.id }).from(brainDecisions2).orderBy(
|
|
21709
|
+
const rows = await db.select({ id: brainDecisions2.id }).from(brainDecisions2).orderBy(desc8(brainDecisions2.id)).limit(1);
|
|
21701
21710
|
if (rows.length === 0) {
|
|
21702
21711
|
return "D001";
|
|
21703
21712
|
}
|
|
@@ -22123,7 +22132,7 @@ var init_values = __esm({
|
|
|
22123
22132
|
var sleep;
|
|
22124
22133
|
var init_sleep = __esm({
|
|
22125
22134
|
"node_modules/.pnpm/@anthropic-ai+sdk@0.88.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs"() {
|
|
22126
|
-
sleep = (ms2) => new Promise((
|
|
22135
|
+
sleep = (ms2) => new Promise((resolve15) => setTimeout(resolve15, ms2));
|
|
22127
22136
|
}
|
|
22128
22137
|
});
|
|
22129
22138
|
|
|
@@ -22901,8 +22910,8 @@ var init_api_promise = __esm({
|
|
|
22901
22910
|
init_parse2();
|
|
22902
22911
|
APIPromise = class _APIPromise extends Promise {
|
|
22903
22912
|
constructor(client, responsePromise, parseResponse = defaultParseResponse) {
|
|
22904
|
-
super((
|
|
22905
|
-
|
|
22913
|
+
super((resolve15) => {
|
|
22914
|
+
resolve15(null);
|
|
22906
22915
|
});
|
|
22907
22916
|
this.responsePromise = responsePromise;
|
|
22908
22917
|
this.parseResponse = parseResponse;
|
|
@@ -24338,12 +24347,12 @@ var init_BetaMessageStream = __esm({
|
|
|
24338
24347
|
}
|
|
24339
24348
|
return this._emit("error", new AnthropicError(String(error48)));
|
|
24340
24349
|
});
|
|
24341
|
-
__classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((
|
|
24342
|
-
__classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise,
|
|
24350
|
+
__classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((resolve15, reject) => {
|
|
24351
|
+
__classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise, resolve15, "f");
|
|
24343
24352
|
__classPrivateFieldSet(this, _BetaMessageStream_rejectConnectedPromise, reject, "f");
|
|
24344
24353
|
}), "f");
|
|
24345
|
-
__classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((
|
|
24346
|
-
__classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise,
|
|
24354
|
+
__classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((resolve15, reject) => {
|
|
24355
|
+
__classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise, resolve15, "f");
|
|
24347
24356
|
__classPrivateFieldSet(this, _BetaMessageStream_rejectEndPromise, reject, "f");
|
|
24348
24357
|
}), "f");
|
|
24349
24358
|
__classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f").catch(() => {
|
|
@@ -24513,11 +24522,11 @@ var init_BetaMessageStream = __esm({
|
|
|
24513
24522
|
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
24514
24523
|
*/
|
|
24515
24524
|
emitted(event) {
|
|
24516
|
-
return new Promise((
|
|
24525
|
+
return new Promise((resolve15, reject) => {
|
|
24517
24526
|
__classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
|
|
24518
24527
|
if (event !== "error")
|
|
24519
24528
|
this.once("error", reject);
|
|
24520
|
-
this.once(event,
|
|
24529
|
+
this.once(event, resolve15);
|
|
24521
24530
|
});
|
|
24522
24531
|
}
|
|
24523
24532
|
async done() {
|
|
@@ -24860,7 +24869,7 @@ var init_BetaMessageStream = __esm({
|
|
|
24860
24869
|
if (done) {
|
|
24861
24870
|
return { value: void 0, done: true };
|
|
24862
24871
|
}
|
|
24863
|
-
return new Promise((
|
|
24872
|
+
return new Promise((resolve15, reject) => readQueue.push({ resolve: resolve15, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
|
|
24864
24873
|
}
|
|
24865
24874
|
const chunk = pushQueue.shift();
|
|
24866
24875
|
return { value: chunk, done: false };
|
|
@@ -24931,13 +24940,13 @@ Wrap your summary in <summary></summary> tags.`;
|
|
|
24931
24940
|
|
|
24932
24941
|
// node_modules/.pnpm/@anthropic-ai+sdk@0.88.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/lib/tools/BetaToolRunner.mjs
|
|
24933
24942
|
function promiseWithResolvers() {
|
|
24934
|
-
let
|
|
24943
|
+
let resolve15;
|
|
24935
24944
|
let reject;
|
|
24936
24945
|
const promise2 = new Promise((res, rej) => {
|
|
24937
|
-
|
|
24946
|
+
resolve15 = res;
|
|
24938
24947
|
reject = rej;
|
|
24939
24948
|
});
|
|
24940
|
-
return { promise: promise2, resolve:
|
|
24949
|
+
return { promise: promise2, resolve: resolve15, reject };
|
|
24941
24950
|
}
|
|
24942
24951
|
async function generateToolResponse(params, lastMessage = params.messages.at(-1), requestOptions) {
|
|
24943
24952
|
if (!lastMessage || lastMessage.role !== "assistant" || !lastMessage.content || typeof lastMessage.content === "string") {
|
|
@@ -26757,12 +26766,12 @@ var init_MessageStream = __esm({
|
|
|
26757
26766
|
}
|
|
26758
26767
|
return this._emit("error", new AnthropicError(String(error48)));
|
|
26759
26768
|
});
|
|
26760
|
-
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((
|
|
26761
|
-
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise,
|
|
26769
|
+
__classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve15, reject) => {
|
|
26770
|
+
__classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve15, "f");
|
|
26762
26771
|
__classPrivateFieldSet(this, _MessageStream_rejectConnectedPromise, reject, "f");
|
|
26763
26772
|
}), "f");
|
|
26764
|
-
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((
|
|
26765
|
-
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise,
|
|
26773
|
+
__classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve15, reject) => {
|
|
26774
|
+
__classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve15, "f");
|
|
26766
26775
|
__classPrivateFieldSet(this, _MessageStream_rejectEndPromise, reject, "f");
|
|
26767
26776
|
}), "f");
|
|
26768
26777
|
__classPrivateFieldGet(this, _MessageStream_connectedPromise, "f").catch(() => {
|
|
@@ -26932,11 +26941,11 @@ var init_MessageStream = __esm({
|
|
|
26932
26941
|
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
26933
26942
|
*/
|
|
26934
26943
|
emitted(event) {
|
|
26935
|
-
return new Promise((
|
|
26944
|
+
return new Promise((resolve15, reject) => {
|
|
26936
26945
|
__classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
|
|
26937
26946
|
if (event !== "error")
|
|
26938
26947
|
this.once("error", reject);
|
|
26939
|
-
this.once(event,
|
|
26948
|
+
this.once(event, resolve15);
|
|
26940
26949
|
});
|
|
26941
26950
|
}
|
|
26942
26951
|
async done() {
|
|
@@ -27254,7 +27263,7 @@ var init_MessageStream = __esm({
|
|
|
27254
27263
|
if (done) {
|
|
27255
27264
|
return { value: void 0, done: true };
|
|
27256
27265
|
}
|
|
27257
|
-
return new Promise((
|
|
27266
|
+
return new Promise((resolve15, reject) => readQueue.push({ resolve: resolve15, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
|
|
27258
27267
|
}
|
|
27259
27268
|
const chunk = pushQueue.shift();
|
|
27260
27269
|
return { value: chunk, done: false };
|
|
@@ -31022,8 +31031,8 @@ var init_schemas = __esm({
|
|
|
31022
31031
|
});
|
|
31023
31032
|
$ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def2) => {
|
|
31024
31033
|
$ZodType.init(inst, def2);
|
|
31025
|
-
const
|
|
31026
|
-
if (!
|
|
31034
|
+
const desc8 = Object.getOwnPropertyDescriptor(def2, "shape");
|
|
31035
|
+
if (!desc8?.get) {
|
|
31027
31036
|
const sh = def2.shape;
|
|
31028
31037
|
Object.defineProperty(def2, "shape", {
|
|
31029
31038
|
get: () => {
|
|
@@ -32265,8 +32274,8 @@ var init_az = __esm({
|
|
|
32265
32274
|
});
|
|
32266
32275
|
|
|
32267
32276
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/locales/be.js
|
|
32268
|
-
function getBelarusianPlural(
|
|
32269
|
-
const absCount = Math.abs(
|
|
32277
|
+
function getBelarusianPlural(count5, one, few, many) {
|
|
32278
|
+
const absCount = Math.abs(count5);
|
|
32270
32279
|
const lastDigit = absCount % 10;
|
|
32271
32280
|
const lastTwoDigits = absCount % 100;
|
|
32272
32281
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -34180,8 +34189,8 @@ var init_hu = __esm({
|
|
|
34180
34189
|
});
|
|
34181
34190
|
|
|
34182
34191
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/locales/hy.js
|
|
34183
|
-
function getArmenianPlural(
|
|
34184
|
-
return Math.abs(
|
|
34192
|
+
function getArmenianPlural(count5, one, many) {
|
|
34193
|
+
return Math.abs(count5) === 1 ? one : many;
|
|
34185
34194
|
}
|
|
34186
34195
|
function withDefiniteArticle(word) {
|
|
34187
34196
|
if (!word)
|
|
@@ -36296,8 +36305,8 @@ var init_pt = __esm({
|
|
|
36296
36305
|
});
|
|
36297
36306
|
|
|
36298
36307
|
// node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/locales/ru.js
|
|
36299
|
-
function getRussianPlural(
|
|
36300
|
-
const absCount = Math.abs(
|
|
36308
|
+
function getRussianPlural(count5, one, few, many) {
|
|
36309
|
+
const absCount = Math.abs(count5);
|
|
36301
36310
|
const lastDigit = absCount % 10;
|
|
36302
36311
|
const lastTwoDigits = absCount % 100;
|
|
36303
36312
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -44011,8 +44020,8 @@ async function strengthenCoRetrievedEdges(projectRoot) {
|
|
|
44011
44020
|
}
|
|
44012
44021
|
}
|
|
44013
44022
|
let strengthened = 0;
|
|
44014
|
-
for (const [pair,
|
|
44015
|
-
if (
|
|
44023
|
+
for (const [pair, count5] of coOccurrence) {
|
|
44024
|
+
if (count5 < 3) continue;
|
|
44016
44025
|
const [fromId, toId] = pair.split("|");
|
|
44017
44026
|
if (!fromId || !toId) continue;
|
|
44018
44027
|
const nodeFrom = `observation:${fromId}`;
|
|
@@ -44360,8 +44369,8 @@ async function runObserver(projectRoot, sessionId) {
|
|
|
44360
44369
|
} catch {
|
|
44361
44370
|
return empty;
|
|
44362
44371
|
}
|
|
44363
|
-
const
|
|
44364
|
-
if (
|
|
44372
|
+
const count5 = countSessionObservations(sessionId);
|
|
44373
|
+
if (count5 < cfg.threshold) return empty;
|
|
44365
44374
|
const observations = fetchSessionObservations(sessionId, OBSERVER_BATCH_LIMIT);
|
|
44366
44375
|
if (observations.length < 2) return empty;
|
|
44367
44376
|
const observationList = observations.map(
|
|
@@ -51619,14 +51628,14 @@ async function validateEpicCreation(options, cwd) {
|
|
|
51619
51628
|
const mode = await getLifecycleMode(cwd);
|
|
51620
51629
|
if (mode === "off") return { valid: true };
|
|
51621
51630
|
const ac = options.acceptance ?? [];
|
|
51622
|
-
const
|
|
51631
|
+
const desc8 = (options.description ?? "").trim();
|
|
51623
51632
|
const violations = [];
|
|
51624
51633
|
if (ac.length < EPIC_MIN_AC) {
|
|
51625
51634
|
violations.push(
|
|
51626
51635
|
`Epic requires at least ${EPIC_MIN_AC} acceptance criteria (${ac.length} provided). Regular tasks need ${TASK_MIN_AC}.`
|
|
51627
51636
|
);
|
|
51628
51637
|
}
|
|
51629
|
-
if (!
|
|
51638
|
+
if (!desc8) {
|
|
51630
51639
|
violations.push("Epic must have a non-empty description (used as completion criteria).");
|
|
51631
51640
|
}
|
|
51632
51641
|
if (violations.length === 0) return { valid: true };
|
|
@@ -52547,7 +52556,7 @@ function migrateAgentOutputs(projectRoot, cleoDir) {
|
|
|
52547
52556
|
};
|
|
52548
52557
|
}
|
|
52549
52558
|
function copyDirContents(srcDir, dstDir, manifestLines, copiedFiles) {
|
|
52550
|
-
let
|
|
52559
|
+
let count5 = 0;
|
|
52551
52560
|
const entries = readdirSync21(srcDir);
|
|
52552
52561
|
for (const entry of entries) {
|
|
52553
52562
|
if (entry === "MANIFEST.jsonl") {
|
|
@@ -52565,7 +52574,7 @@ function copyDirContents(srcDir, dstDir, manifestLines, copiedFiles) {
|
|
|
52565
52574
|
try {
|
|
52566
52575
|
copyFileSync6(join56(srcPath, sf), join56(dstPath, sf));
|
|
52567
52576
|
copiedFiles.add(sf);
|
|
52568
|
-
|
|
52577
|
+
count5++;
|
|
52569
52578
|
} catch {
|
|
52570
52579
|
}
|
|
52571
52580
|
}
|
|
@@ -52573,12 +52582,12 @@ function copyDirContents(srcDir, dstDir, manifestLines, copiedFiles) {
|
|
|
52573
52582
|
} else if (!copiedFiles.has(entry)) {
|
|
52574
52583
|
copyFileSync6(srcPath, dstPath);
|
|
52575
52584
|
copiedFiles.add(entry);
|
|
52576
|
-
|
|
52585
|
+
count5++;
|
|
52577
52586
|
}
|
|
52578
52587
|
} catch {
|
|
52579
52588
|
}
|
|
52580
52589
|
}
|
|
52581
|
-
return
|
|
52590
|
+
return count5;
|
|
52582
52591
|
}
|
|
52583
52592
|
function collectManifestLines(manifestPath, out) {
|
|
52584
52593
|
try {
|
|
@@ -53402,13 +53411,14 @@ __export(registry_exports3, {
|
|
|
53402
53411
|
nexusSync: () => nexusSync,
|
|
53403
53412
|
nexusSyncAll: () => nexusSyncAll,
|
|
53404
53413
|
nexusUnregister: () => nexusUnregister,
|
|
53414
|
+
nexusUpdateIndexStats: () => nexusUpdateIndexStats,
|
|
53405
53415
|
readRegistry: () => readRegistry,
|
|
53406
53416
|
readRegistryRequired: () => readRegistryRequired,
|
|
53407
53417
|
resetNexusDbState: () => resetNexusDbState
|
|
53408
53418
|
});
|
|
53409
53419
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
53410
53420
|
import { mkdir as mkdir12 } from "node:fs/promises";
|
|
53411
|
-
import { basename as basename9, join as join63 } from "node:path";
|
|
53421
|
+
import { basename as basename9, join as join63, resolve as resolve7 } from "node:path";
|
|
53412
53422
|
function getNexusHome() {
|
|
53413
53423
|
return process.env["NEXUS_HOME"] ?? join63(getCleoHome(), "nexus");
|
|
53414
53424
|
}
|
|
@@ -53425,6 +53435,17 @@ function rowToProject(row) {
|
|
|
53425
53435
|
} catch {
|
|
53426
53436
|
labels = [];
|
|
53427
53437
|
}
|
|
53438
|
+
let stats2 = { nodeCount: 0, relationCount: 0, fileCount: 0 };
|
|
53439
|
+
try {
|
|
53440
|
+
const parsed = JSON.parse(row.statsJson ?? "{}");
|
|
53441
|
+
stats2 = {
|
|
53442
|
+
nodeCount: parsed.nodeCount ?? 0,
|
|
53443
|
+
relationCount: parsed.relationCount ?? 0,
|
|
53444
|
+
fileCount: parsed.fileCount ?? 0
|
|
53445
|
+
};
|
|
53446
|
+
} catch {
|
|
53447
|
+
stats2 = { nodeCount: 0, relationCount: 0, fileCount: 0 };
|
|
53448
|
+
}
|
|
53428
53449
|
return {
|
|
53429
53450
|
hash: row.projectHash,
|
|
53430
53451
|
projectId: row.projectId,
|
|
@@ -53437,7 +53458,11 @@ function rowToProject(row) {
|
|
|
53437
53458
|
permissions: row.permissions,
|
|
53438
53459
|
lastSync: row.lastSync,
|
|
53439
53460
|
taskCount: row.taskCount,
|
|
53440
|
-
labels
|
|
53461
|
+
labels,
|
|
53462
|
+
brainDbPath: row.brainDbPath ?? null,
|
|
53463
|
+
tasksDbPath: row.tasksDbPath ?? null,
|
|
53464
|
+
lastIndexed: row.lastIndexed ?? null,
|
|
53465
|
+
stats: stats2
|
|
53441
53466
|
};
|
|
53442
53467
|
}
|
|
53443
53468
|
async function writeNexusAudit(fields) {
|
|
@@ -53533,10 +53558,10 @@ async function readProjectMeta(projectPath) {
|
|
|
53533
53558
|
}
|
|
53534
53559
|
async function readProjectId(projectPath) {
|
|
53535
53560
|
try {
|
|
53536
|
-
const { readFileSync:
|
|
53561
|
+
const { readFileSync: readFileSync94, existsSync: existsSync128 } = await import("node:fs");
|
|
53537
53562
|
const infoPath = join63(projectPath, ".cleo", "project-info.json");
|
|
53538
|
-
if (!
|
|
53539
|
-
const data = JSON.parse(
|
|
53563
|
+
if (!existsSync128(infoPath)) return "";
|
|
53564
|
+
const data = JSON.parse(readFileSync94(infoPath, "utf-8"));
|
|
53540
53565
|
return typeof data.projectId === "string" ? data.projectId : "";
|
|
53541
53566
|
} catch {
|
|
53542
53567
|
return "";
|
|
@@ -53577,13 +53602,18 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
|
|
|
53577
53602
|
const meta3 = await readProjectMeta(projectPath);
|
|
53578
53603
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
53579
53604
|
let projectId = await readProjectId(projectPath);
|
|
53605
|
+
const resolvedPath = resolve7(projectPath);
|
|
53606
|
+
const brainDbPath = join63(resolvedPath, ".cleo", "brain.db");
|
|
53607
|
+
const tasksDbPath = join63(resolvedPath, ".cleo", "tasks.db");
|
|
53580
53608
|
if (existing) {
|
|
53581
53609
|
await db.update(projectRegistry).set({
|
|
53582
53610
|
permissions,
|
|
53583
53611
|
lastSync: now2,
|
|
53584
53612
|
taskCount: meta3.taskCount,
|
|
53585
53613
|
labelsJson: JSON.stringify(meta3.labels),
|
|
53586
|
-
lastSeen: now2
|
|
53614
|
+
lastSeen: now2,
|
|
53615
|
+
brainDbPath,
|
|
53616
|
+
tasksDbPath
|
|
53587
53617
|
}).where(eq17(projectRegistry.projectHash, projectHash));
|
|
53588
53618
|
} else {
|
|
53589
53619
|
if (!projectId) {
|
|
@@ -53601,7 +53631,10 @@ async function nexusRegister(projectPath, name2, permissions = "read") {
|
|
|
53601
53631
|
permissions,
|
|
53602
53632
|
lastSync: now2,
|
|
53603
53633
|
taskCount: meta3.taskCount,
|
|
53604
|
-
labelsJson: JSON.stringify(meta3.labels)
|
|
53634
|
+
labelsJson: JSON.stringify(meta3.labels),
|
|
53635
|
+
brainDbPath,
|
|
53636
|
+
tasksDbPath,
|
|
53637
|
+
statsJson: "{}"
|
|
53605
53638
|
});
|
|
53606
53639
|
}
|
|
53607
53640
|
await writeNexusAudit({
|
|
@@ -53717,6 +53750,41 @@ async function nexusSyncAll() {
|
|
|
53717
53750
|
});
|
|
53718
53751
|
return { synced, failed };
|
|
53719
53752
|
}
|
|
53753
|
+
async function nexusUpdateIndexStats(projectPath, stats2) {
|
|
53754
|
+
if (!projectPath) return;
|
|
53755
|
+
const projectHash = generateProjectHash(projectPath);
|
|
53756
|
+
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
53757
|
+
try {
|
|
53758
|
+
const { getNexusDb: getNexusDb2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
|
|
53759
|
+
const { eq: eq17 } = await import("drizzle-orm");
|
|
53760
|
+
const db = await getNexusDb2();
|
|
53761
|
+
const rows = await db.select().from(projectRegistry).where(eq17(projectRegistry.projectHash, projectHash));
|
|
53762
|
+
if (rows.length === 0) {
|
|
53763
|
+
try {
|
|
53764
|
+
await nexusRegister(projectPath);
|
|
53765
|
+
} catch {
|
|
53766
|
+
}
|
|
53767
|
+
}
|
|
53768
|
+
await db.update(projectRegistry).set({
|
|
53769
|
+
lastIndexed: now2,
|
|
53770
|
+
statsJson: JSON.stringify(stats2),
|
|
53771
|
+
lastSeen: now2
|
|
53772
|
+
}).where(eq17(projectRegistry.projectHash, projectHash));
|
|
53773
|
+
await writeNexusAudit({
|
|
53774
|
+
action: "update-index-stats",
|
|
53775
|
+
projectHash,
|
|
53776
|
+
operation: "update-index-stats",
|
|
53777
|
+
success: true,
|
|
53778
|
+
details: {
|
|
53779
|
+
nodeCount: stats2.nodeCount,
|
|
53780
|
+
relationCount: stats2.relationCount,
|
|
53781
|
+
fileCount: stats2.fileCount
|
|
53782
|
+
}
|
|
53783
|
+
});
|
|
53784
|
+
} catch (err) {
|
|
53785
|
+
getLogger("nexus").warn({ err }, "nexus: failed to update index stats");
|
|
53786
|
+
}
|
|
53787
|
+
}
|
|
53720
53788
|
async function nexusSetPermission(nameOrHash, permission) {
|
|
53721
53789
|
const project = await nexusGetProject(nameOrHash);
|
|
53722
53790
|
if (!project) {
|
|
@@ -56907,29 +56975,29 @@ var init_validation_schemas = __esm({
|
|
|
56907
56975
|
});
|
|
56908
56976
|
|
|
56909
56977
|
// packages/core/src/discovery.ts
|
|
56910
|
-
import { existsSync as
|
|
56911
|
-
import { join as
|
|
56978
|
+
import { existsSync as existsSync107, readdirSync as readdirSync34, statSync as statSync20 } from "node:fs";
|
|
56979
|
+
import { join as join106, resolve as resolve11 } from "node:path";
|
|
56912
56980
|
function countMeaningfulTopLevelFiles(directory) {
|
|
56913
|
-
if (!
|
|
56981
|
+
if (!existsSync107(directory)) return 0;
|
|
56914
56982
|
try {
|
|
56915
56983
|
const entries = readdirSync34(directory);
|
|
56916
|
-
let
|
|
56984
|
+
let count5 = 0;
|
|
56917
56985
|
for (const entry of entries) {
|
|
56918
56986
|
if (entry.startsWith(".") || entry === ".cleo" || entry === "node_modules" || entry === "target" || entry === "dist" || entry === "build") {
|
|
56919
56987
|
continue;
|
|
56920
56988
|
}
|
|
56921
|
-
|
|
56989
|
+
count5 += 1;
|
|
56922
56990
|
}
|
|
56923
|
-
return
|
|
56991
|
+
return count5;
|
|
56924
56992
|
} catch {
|
|
56925
56993
|
return 0;
|
|
56926
56994
|
}
|
|
56927
56995
|
}
|
|
56928
56996
|
function classifyProject(directory) {
|
|
56929
|
-
const root =
|
|
56997
|
+
const root = resolve11(directory ?? process.cwd());
|
|
56930
56998
|
const signals = [];
|
|
56931
|
-
const gitPath =
|
|
56932
|
-
const hasGit =
|
|
56999
|
+
const gitPath = join106(root, ".git");
|
|
57000
|
+
const hasGit = existsSync107(gitPath);
|
|
56933
57001
|
if (hasGit) {
|
|
56934
57002
|
signals.push({
|
|
56935
57003
|
id: "git-dir",
|
|
@@ -56938,8 +57006,8 @@ function classifyProject(directory) {
|
|
|
56938
57006
|
});
|
|
56939
57007
|
}
|
|
56940
57008
|
for (const manifest of MANIFESTS) {
|
|
56941
|
-
const manifestPath =
|
|
56942
|
-
if (
|
|
57009
|
+
const manifestPath = join106(root, manifest.file);
|
|
57010
|
+
if (existsSync107(manifestPath)) {
|
|
56943
57011
|
signals.push({
|
|
56944
57012
|
id: manifest.signal,
|
|
56945
57013
|
description: manifest.description,
|
|
@@ -56948,8 +57016,8 @@ function classifyProject(directory) {
|
|
|
56948
57016
|
}
|
|
56949
57017
|
}
|
|
56950
57018
|
for (const dir of SOURCE_DIRS) {
|
|
56951
|
-
const srcPath =
|
|
56952
|
-
if (
|
|
57019
|
+
const srcPath = join106(root, dir);
|
|
57020
|
+
if (existsSync107(srcPath) && isNonEmptyDir(srcPath)) {
|
|
56953
57021
|
signals.push({
|
|
56954
57022
|
id: "source-dir",
|
|
56955
57023
|
description: `Source directory ${dir}/ contains files`,
|
|
@@ -56959,8 +57027,8 @@ function classifyProject(directory) {
|
|
|
56959
57027
|
}
|
|
56960
57028
|
}
|
|
56961
57029
|
for (const marker of DOCS_MARKERS) {
|
|
56962
|
-
const markerPath =
|
|
56963
|
-
if (
|
|
57030
|
+
const markerPath = join106(root, marker.path);
|
|
57031
|
+
if (existsSync107(markerPath)) {
|
|
56964
57032
|
signals.push({
|
|
56965
57033
|
id: marker.signal,
|
|
56966
57034
|
description: `${marker.path} present`,
|
|
@@ -57033,18 +57101,18 @@ __export(init_exports, {
|
|
|
57033
57101
|
resolveSeedAgentsDir: () => resolveSeedAgentsDir,
|
|
57034
57102
|
updateDocs: () => updateDocs
|
|
57035
57103
|
});
|
|
57036
|
-
import { existsSync as
|
|
57104
|
+
import { existsSync as existsSync108, readdirSync as readdirSync35, readFileSync as readFileSync76 } from "node:fs";
|
|
57037
57105
|
import { copyFile as copyFile4, lstat, mkdir as mkdir16, readFile as readFile19, symlink, unlink as unlink4, writeFile as writeFile11 } from "node:fs/promises";
|
|
57038
57106
|
import { platform as platform4 } from "node:os";
|
|
57039
|
-
import { basename as basename17, dirname as
|
|
57107
|
+
import { basename as basename17, dirname as dirname23, join as join107 } from "node:path";
|
|
57040
57108
|
async function resolveSeedAgentsDir() {
|
|
57041
57109
|
try {
|
|
57042
57110
|
const { createRequire: createRequire15 } = await import("node:module");
|
|
57043
57111
|
const req = createRequire15(import.meta.url);
|
|
57044
57112
|
const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
|
|
57045
|
-
const agentsPkgRoot =
|
|
57046
|
-
const candidate =
|
|
57047
|
-
if (
|
|
57113
|
+
const agentsPkgRoot = dirname23(agentsPkgMain);
|
|
57114
|
+
const candidate = join107(agentsPkgRoot, "seed-agents");
|
|
57115
|
+
if (existsSync108(candidate)) {
|
|
57048
57116
|
return candidate;
|
|
57049
57117
|
}
|
|
57050
57118
|
} catch {
|
|
@@ -57052,17 +57120,17 @@ async function resolveSeedAgentsDir() {
|
|
|
57052
57120
|
const packageRoot = getPackageRoot();
|
|
57053
57121
|
const candidates = [
|
|
57054
57122
|
// Workspace fallback: bundled alongside core under packages/agents/seed-agents
|
|
57055
|
-
|
|
57123
|
+
join107(packageRoot, "agents", "seed-agents"),
|
|
57056
57124
|
// Sibling-package layout (e.g. node_modules/@cleocode/core -> ../agents)
|
|
57057
|
-
|
|
57125
|
+
join107(packageRoot, "..", "agents", "seed-agents"),
|
|
57058
57126
|
// Bundled CLI: packages/cleo/dist -> ../../agents/seed-agents
|
|
57059
|
-
|
|
57127
|
+
join107(packageRoot, "..", "..", "agents", "seed-agents"),
|
|
57060
57128
|
// Bundled CLI dist subdir: packages/cleo/dist/cli -> ../../../packages/agents
|
|
57061
|
-
|
|
57129
|
+
join107(packageRoot, "..", "..", "packages", "agents", "seed-agents"),
|
|
57062
57130
|
// Monorepo workspace from repo root
|
|
57063
|
-
|
|
57131
|
+
join107(packageRoot, "..", "..", "..", "packages", "agents", "seed-agents")
|
|
57064
57132
|
];
|
|
57065
|
-
return candidates.find((p2) =>
|
|
57133
|
+
return candidates.find((p2) => existsSync108(p2)) ?? null;
|
|
57066
57134
|
}
|
|
57067
57135
|
async function initAgentDefinition(created, warnings) {
|
|
57068
57136
|
let agentSourceDir = null;
|
|
@@ -57070,17 +57138,17 @@ async function initAgentDefinition(created, warnings) {
|
|
|
57070
57138
|
const { createRequire: createRequire15 } = await import("node:module");
|
|
57071
57139
|
const req = createRequire15(import.meta.url);
|
|
57072
57140
|
const agentsPkgMain = req.resolve("@cleocode/agents/package.json");
|
|
57073
|
-
const agentsPkgRoot =
|
|
57074
|
-
const candidate =
|
|
57075
|
-
if (
|
|
57141
|
+
const agentsPkgRoot = dirname23(agentsPkgMain);
|
|
57142
|
+
const candidate = join107(agentsPkgRoot, "cleo-subagent");
|
|
57143
|
+
if (existsSync108(candidate)) {
|
|
57076
57144
|
agentSourceDir = candidate;
|
|
57077
57145
|
}
|
|
57078
57146
|
} catch {
|
|
57079
57147
|
}
|
|
57080
57148
|
if (!agentSourceDir) {
|
|
57081
57149
|
const packageRoot = getPackageRoot();
|
|
57082
|
-
const bundled =
|
|
57083
|
-
if (
|
|
57150
|
+
const bundled = join107(packageRoot, "agents", "cleo-subagent");
|
|
57151
|
+
if (existsSync108(bundled)) {
|
|
57084
57152
|
agentSourceDir = bundled;
|
|
57085
57153
|
}
|
|
57086
57154
|
}
|
|
@@ -57088,8 +57156,8 @@ async function initAgentDefinition(created, warnings) {
|
|
|
57088
57156
|
warnings.push("agents/cleo-subagent/ not found in package, skipping agent definition install");
|
|
57089
57157
|
return;
|
|
57090
57158
|
}
|
|
57091
|
-
const globalAgentsDir =
|
|
57092
|
-
await mkdir16(
|
|
57159
|
+
const globalAgentsDir = join107(getAgentsHome(), "agents", "cleo-subagent");
|
|
57160
|
+
await mkdir16(dirname23(globalAgentsDir), { recursive: true });
|
|
57093
57161
|
try {
|
|
57094
57162
|
try {
|
|
57095
57163
|
const stat3 = await lstat(globalAgentsDir);
|
|
@@ -57112,7 +57180,7 @@ async function initAgentDefinition(created, warnings) {
|
|
|
57112
57180
|
await mkdir16(globalAgentsDir, { recursive: true });
|
|
57113
57181
|
const files = readdirSync35(agentSourceDir);
|
|
57114
57182
|
for (const file2 of files) {
|
|
57115
|
-
await copyFile4(
|
|
57183
|
+
await copyFile4(join107(agentSourceDir, file2), join107(globalAgentsDir, file2));
|
|
57116
57184
|
}
|
|
57117
57185
|
created.push("agent: cleo-subagent (copied)");
|
|
57118
57186
|
} catch (copyErr) {
|
|
@@ -57137,20 +57205,20 @@ async function initCoreSkills(created, warnings) {
|
|
|
57137
57205
|
const { createRequire: createRequire15 } = await import("node:module");
|
|
57138
57206
|
const req = createRequire15(import.meta.url);
|
|
57139
57207
|
const skillsPkgMain = req.resolve("@cleocode/skills/package.json");
|
|
57140
|
-
const skillsPkgRoot =
|
|
57141
|
-
if (
|
|
57208
|
+
const skillsPkgRoot = dirname23(skillsPkgMain);
|
|
57209
|
+
if (existsSync108(join107(skillsPkgRoot, "skills.json"))) {
|
|
57142
57210
|
ctSkillsRoot = skillsPkgRoot;
|
|
57143
57211
|
}
|
|
57144
57212
|
} catch {
|
|
57145
57213
|
}
|
|
57146
57214
|
if (!ctSkillsRoot) {
|
|
57147
57215
|
try {
|
|
57148
|
-
const bundledPath =
|
|
57149
|
-
if (
|
|
57216
|
+
const bundledPath = join107(packageRoot, "packages", "skills");
|
|
57217
|
+
if (existsSync108(join107(bundledPath, "skills.json"))) {
|
|
57150
57218
|
ctSkillsRoot = bundledPath;
|
|
57151
57219
|
} else {
|
|
57152
|
-
const ctSkillsPath =
|
|
57153
|
-
if (
|
|
57220
|
+
const ctSkillsPath = join107(packageRoot, "node_modules", "@cleocode", "skills");
|
|
57221
|
+
if (existsSync108(join107(ctSkillsPath, "skills.json"))) {
|
|
57154
57222
|
ctSkillsRoot = ctSkillsPath;
|
|
57155
57223
|
}
|
|
57156
57224
|
}
|
|
@@ -57166,14 +57234,14 @@ async function initCoreSkills(created, warnings) {
|
|
|
57166
57234
|
} catch {
|
|
57167
57235
|
warnings.push("Failed to register skill library with CAAMP");
|
|
57168
57236
|
}
|
|
57169
|
-
const catalogPath =
|
|
57170
|
-
const catalog3 = JSON.parse(
|
|
57237
|
+
const catalogPath = join107(ctSkillsRoot, "skills.json");
|
|
57238
|
+
const catalog3 = JSON.parse(readFileSync76(catalogPath, "utf-8"));
|
|
57171
57239
|
const skills = catalog3.skills ?? [];
|
|
57172
57240
|
const coreSkills = skills.filter((s3) => s3.tier <= 2);
|
|
57173
57241
|
const installed = [];
|
|
57174
57242
|
for (const skill of coreSkills) {
|
|
57175
|
-
const skillSourceDir =
|
|
57176
|
-
if (!
|
|
57243
|
+
const skillSourceDir = dirname23(join107(ctSkillsRoot, skill.path));
|
|
57244
|
+
if (!existsSync108(skillSourceDir)) {
|
|
57177
57245
|
continue;
|
|
57178
57246
|
}
|
|
57179
57247
|
try {
|
|
@@ -57216,38 +57284,38 @@ async function initNexusRegistration(projectRoot, created, warnings) {
|
|
|
57216
57284
|
}
|
|
57217
57285
|
}
|
|
57218
57286
|
async function installGitHubTemplates(projectRoot, created, skipped) {
|
|
57219
|
-
if (!
|
|
57287
|
+
if (!existsSync108(join107(projectRoot, ".git"))) {
|
|
57220
57288
|
return;
|
|
57221
57289
|
}
|
|
57222
|
-
const githubDir =
|
|
57223
|
-
const issueTemplateDir =
|
|
57290
|
+
const githubDir = join107(projectRoot, ".github");
|
|
57291
|
+
const issueTemplateDir = join107(githubDir, "ISSUE_TEMPLATE");
|
|
57224
57292
|
const packageRoot = getPackageRoot();
|
|
57225
|
-
const templateSrcDir =
|
|
57226
|
-
if (!
|
|
57293
|
+
const templateSrcDir = join107(packageRoot, "templates", "github");
|
|
57294
|
+
if (!existsSync108(templateSrcDir)) {
|
|
57227
57295
|
return;
|
|
57228
57296
|
}
|
|
57229
57297
|
await mkdir16(issueTemplateDir, { recursive: true });
|
|
57230
|
-
const issueSrcDir =
|
|
57231
|
-
if (
|
|
57298
|
+
const issueSrcDir = join107(templateSrcDir, "ISSUE_TEMPLATE");
|
|
57299
|
+
if (existsSync108(issueSrcDir)) {
|
|
57232
57300
|
const issueFiles = readdirSync35(issueSrcDir);
|
|
57233
57301
|
for (const file2 of issueFiles) {
|
|
57234
|
-
const dest =
|
|
57235
|
-
if (
|
|
57302
|
+
const dest = join107(issueTemplateDir, file2);
|
|
57303
|
+
if (existsSync108(dest)) {
|
|
57236
57304
|
skipped.push(`.github/ISSUE_TEMPLATE/${file2}`);
|
|
57237
57305
|
continue;
|
|
57238
57306
|
}
|
|
57239
|
-
const content =
|
|
57307
|
+
const content = readFileSync76(join107(issueSrcDir, file2), "utf-8");
|
|
57240
57308
|
await writeFile11(dest, content, "utf-8");
|
|
57241
57309
|
created.push(`.github/ISSUE_TEMPLATE/${file2}`);
|
|
57242
57310
|
}
|
|
57243
57311
|
}
|
|
57244
|
-
const prTemplateSrc =
|
|
57245
|
-
const prTemplateDest =
|
|
57246
|
-
if (
|
|
57247
|
-
if (
|
|
57312
|
+
const prTemplateSrc = join107(templateSrcDir, "pull_request_template.md");
|
|
57313
|
+
const prTemplateDest = join107(githubDir, "pull_request_template.md");
|
|
57314
|
+
if (existsSync108(prTemplateSrc)) {
|
|
57315
|
+
if (existsSync108(prTemplateDest)) {
|
|
57248
57316
|
skipped.push(".github/pull_request_template.md");
|
|
57249
57317
|
} else {
|
|
57250
|
-
const content =
|
|
57318
|
+
const content = readFileSync76(prTemplateSrc, "utf-8");
|
|
57251
57319
|
await writeFile11(prTemplateDest, content, "utf-8");
|
|
57252
57320
|
created.push(".github/pull_request_template.md");
|
|
57253
57321
|
}
|
|
@@ -57277,8 +57345,8 @@ async function updateDocs() {
|
|
|
57277
57345
|
}
|
|
57278
57346
|
async function initProject(opts = {}) {
|
|
57279
57347
|
const cleoDir = getCleoDirAbsolute();
|
|
57280
|
-
const projRoot =
|
|
57281
|
-
const alreadyInitialized =
|
|
57348
|
+
const projRoot = dirname23(cleoDir);
|
|
57349
|
+
const alreadyInitialized = existsSync108(cleoDir) && (existsSync108(join107(cleoDir, "tasks.db")) || existsSync108(join107(cleoDir, "config.json")));
|
|
57282
57350
|
if (alreadyInitialized && !opts.force) {
|
|
57283
57351
|
throw new CleoError(
|
|
57284
57352
|
1 /* GENERAL_ERROR */,
|
|
@@ -57310,7 +57378,7 @@ async function initProject(opts = {}) {
|
|
|
57310
57378
|
}
|
|
57311
57379
|
try {
|
|
57312
57380
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
57313
|
-
await getDb4(
|
|
57381
|
+
await getDb4(join107(cleoDir, ".."));
|
|
57314
57382
|
created.push("tasks.db");
|
|
57315
57383
|
} catch (err) {
|
|
57316
57384
|
created.push(`tasks.db (deferred: ${err instanceof Error ? err.message : String(err)})`);
|
|
@@ -57340,8 +57408,8 @@ async function initProject(opts = {}) {
|
|
|
57340
57408
|
created.push(".gitignore");
|
|
57341
57409
|
}
|
|
57342
57410
|
} else {
|
|
57343
|
-
const gitignorePath =
|
|
57344
|
-
if (
|
|
57411
|
+
const gitignorePath = join107(cleoDir, ".gitignore");
|
|
57412
|
+
if (existsSync108(gitignorePath)) {
|
|
57345
57413
|
skipped.push(".gitignore");
|
|
57346
57414
|
} else {
|
|
57347
57415
|
const gitignoreResult = await ensureGitignore(projRoot);
|
|
@@ -57352,12 +57420,12 @@ async function initProject(opts = {}) {
|
|
|
57352
57420
|
}
|
|
57353
57421
|
}
|
|
57354
57422
|
}
|
|
57355
|
-
const legacySequencePath =
|
|
57423
|
+
const legacySequencePath = join107(cleoDir, ".sequence");
|
|
57356
57424
|
try {
|
|
57357
57425
|
await unlink4(legacySequencePath);
|
|
57358
57426
|
} catch {
|
|
57359
57427
|
}
|
|
57360
|
-
const legacySequenceJsonPath =
|
|
57428
|
+
const legacySequenceJsonPath = join107(cleoDir, ".sequence.json");
|
|
57361
57429
|
try {
|
|
57362
57430
|
await unlink4(legacySequenceJsonPath);
|
|
57363
57431
|
} catch {
|
|
@@ -57513,15 +57581,15 @@ async function initProject(opts = {}) {
|
|
|
57513
57581
|
if (opts.installSeedAgents) {
|
|
57514
57582
|
try {
|
|
57515
57583
|
const seedDir = await resolveSeedAgentsDir();
|
|
57516
|
-
if (seedDir &&
|
|
57517
|
-
const targetDir =
|
|
57584
|
+
if (seedDir && existsSync108(seedDir)) {
|
|
57585
|
+
const targetDir = join107(projRoot, ".cleo", "agents");
|
|
57518
57586
|
await mkdir16(targetDir, { recursive: true });
|
|
57519
57587
|
const seeds = readdirSync35(seedDir).filter((f2) => f2.endsWith(".cant"));
|
|
57520
57588
|
let installed = 0;
|
|
57521
57589
|
for (const seed of seeds) {
|
|
57522
|
-
const dst =
|
|
57523
|
-
if (!
|
|
57524
|
-
await copyFile4(
|
|
57590
|
+
const dst = join107(targetDir, seed);
|
|
57591
|
+
if (!existsSync108(dst)) {
|
|
57592
|
+
await copyFile4(join107(seedDir, seed), dst);
|
|
57525
57593
|
installed++;
|
|
57526
57594
|
}
|
|
57527
57595
|
}
|
|
@@ -57604,8 +57672,8 @@ function isAutoInitEnabled() {
|
|
|
57604
57672
|
}
|
|
57605
57673
|
async function ensureInitialized(projectRoot) {
|
|
57606
57674
|
const root = projectRoot ?? getProjectRoot();
|
|
57607
|
-
const cleoDir =
|
|
57608
|
-
const isInit =
|
|
57675
|
+
const cleoDir = join107(root, ".cleo");
|
|
57676
|
+
const isInit = existsSync108(cleoDir) && (existsSync108(join107(cleoDir, "tasks.db")) || existsSync108(join107(cleoDir, "config.json")));
|
|
57609
57677
|
if (isInit) {
|
|
57610
57678
|
return { initialized: true };
|
|
57611
57679
|
}
|
|
@@ -57617,7 +57685,7 @@ async function ensureInitialized(projectRoot) {
|
|
|
57617
57685
|
}
|
|
57618
57686
|
async function getVersion2(projectRoot) {
|
|
57619
57687
|
const root = projectRoot ?? getProjectRoot();
|
|
57620
|
-
const versionPaths = [
|
|
57688
|
+
const versionPaths = [join107(root, "VERSION"), join107(root, "..", "VERSION")];
|
|
57621
57689
|
for (const versionPath of versionPaths) {
|
|
57622
57690
|
try {
|
|
57623
57691
|
const content = await readFile19(versionPath, "utf-8");
|
|
@@ -57628,16 +57696,16 @@ async function getVersion2(projectRoot) {
|
|
|
57628
57696
|
} catch {
|
|
57629
57697
|
}
|
|
57630
57698
|
}
|
|
57631
|
-
const pkg = await readJson(
|
|
57699
|
+
const pkg = await readJson(join107(root, "package.json"));
|
|
57632
57700
|
if (pkg?.version) {
|
|
57633
57701
|
return { version: pkg.version };
|
|
57634
57702
|
}
|
|
57635
57703
|
return { version: "0.0.0" };
|
|
57636
57704
|
}
|
|
57637
57705
|
async function deployStarterBundle(cleoDir, created, warnings) {
|
|
57638
|
-
const cantDir =
|
|
57639
|
-
const cantAgentsDir =
|
|
57640
|
-
const hasCantFiles =
|
|
57706
|
+
const cantDir = join107(cleoDir, "cant");
|
|
57707
|
+
const cantAgentsDir = join107(cantDir, "agents");
|
|
57708
|
+
const hasCantFiles = existsSync108(cantDir) && readdirSync35(cantDir, { recursive: true }).some(
|
|
57641
57709
|
(f2) => typeof f2 === "string" && f2.endsWith(".cant")
|
|
57642
57710
|
);
|
|
57643
57711
|
if (hasCantFiles) return;
|
|
@@ -57646,9 +57714,9 @@ async function deployStarterBundle(cleoDir, created, warnings) {
|
|
|
57646
57714
|
const { createRequire: createRequire15 } = await import("node:module");
|
|
57647
57715
|
const req = createRequire15(import.meta.url);
|
|
57648
57716
|
const cleoOsPkgMain = req.resolve("@cleocode/cleo-os/package.json");
|
|
57649
|
-
const cleoOsPkgRoot =
|
|
57650
|
-
const candidate =
|
|
57651
|
-
if (
|
|
57717
|
+
const cleoOsPkgRoot = dirname23(cleoOsPkgMain);
|
|
57718
|
+
const candidate = join107(cleoOsPkgRoot, "starter-bundle");
|
|
57719
|
+
if (existsSync108(candidate)) {
|
|
57652
57720
|
starterBundleSrc = candidate;
|
|
57653
57721
|
}
|
|
57654
57722
|
} catch {
|
|
@@ -57656,10 +57724,10 @@ async function deployStarterBundle(cleoDir, created, warnings) {
|
|
|
57656
57724
|
if (!starterBundleSrc) {
|
|
57657
57725
|
const packageRoot = getPackageRoot();
|
|
57658
57726
|
const fallbacks = [
|
|
57659
|
-
|
|
57660
|
-
|
|
57727
|
+
join107(packageRoot, "..", "cleo-os", "starter-bundle"),
|
|
57728
|
+
join107(packageRoot, "..", "..", "packages", "cleo-os", "starter-bundle")
|
|
57661
57729
|
];
|
|
57662
|
-
starterBundleSrc = fallbacks.find((p2) =>
|
|
57730
|
+
starterBundleSrc = fallbacks.find((p2) => existsSync108(p2)) ?? null;
|
|
57663
57731
|
}
|
|
57664
57732
|
if (!starterBundleSrc) {
|
|
57665
57733
|
warnings.push(
|
|
@@ -57669,30 +57737,30 @@ async function deployStarterBundle(cleoDir, created, warnings) {
|
|
|
57669
57737
|
}
|
|
57670
57738
|
await mkdir16(cantDir, { recursive: true });
|
|
57671
57739
|
await mkdir16(cantAgentsDir, { recursive: true });
|
|
57672
|
-
const teamSrc =
|
|
57673
|
-
const teamDst =
|
|
57674
|
-
if (
|
|
57740
|
+
const teamSrc = join107(starterBundleSrc, "team.cant");
|
|
57741
|
+
const teamDst = join107(cantDir, "team.cant");
|
|
57742
|
+
if (existsSync108(teamSrc) && !existsSync108(teamDst)) {
|
|
57675
57743
|
await copyFile4(teamSrc, teamDst);
|
|
57676
57744
|
}
|
|
57677
|
-
const agentsSrc =
|
|
57678
|
-
if (
|
|
57745
|
+
const agentsSrc = join107(starterBundleSrc, "agents");
|
|
57746
|
+
if (existsSync108(agentsSrc)) {
|
|
57679
57747
|
const agentFiles = readdirSync35(agentsSrc).filter((f2) => f2.endsWith(".cant"));
|
|
57680
57748
|
for (const agentFile of agentFiles) {
|
|
57681
|
-
const dst =
|
|
57682
|
-
if (!
|
|
57683
|
-
await copyFile4(
|
|
57749
|
+
const dst = join107(cantAgentsDir, agentFile);
|
|
57750
|
+
if (!existsSync108(dst)) {
|
|
57751
|
+
await copyFile4(join107(agentsSrc, agentFile), dst);
|
|
57684
57752
|
}
|
|
57685
57753
|
}
|
|
57686
57754
|
}
|
|
57687
|
-
const identitySrc =
|
|
57688
|
-
const identityDst =
|
|
57689
|
-
if (
|
|
57755
|
+
const identitySrc = join107(starterBundleSrc, "CLEOOS-IDENTITY.md");
|
|
57756
|
+
const identityDst = join107(cleoDir, "CLEOOS-IDENTITY.md");
|
|
57757
|
+
if (existsSync108(identitySrc) && !existsSync108(identityDst)) {
|
|
57690
57758
|
await copyFile4(identitySrc, identityDst);
|
|
57691
57759
|
}
|
|
57692
57760
|
try {
|
|
57693
57761
|
const { getCleoHome: getCleoHome2 } = await Promise.resolve().then(() => (init_paths(), paths_exports));
|
|
57694
|
-
const globalIdentityDst =
|
|
57695
|
-
if (
|
|
57762
|
+
const globalIdentityDst = join107(getCleoHome2(), "CLEOOS-IDENTITY.md");
|
|
57763
|
+
if (existsSync108(identitySrc) && !existsSync108(globalIdentityDst)) {
|
|
57696
57764
|
await copyFile4(identitySrc, globalIdentityDst);
|
|
57697
57765
|
}
|
|
57698
57766
|
} catch {
|
|
@@ -58088,7 +58156,7 @@ __export(session_store_exports, {
|
|
|
58088
58156
|
updateSession: () => updateSession,
|
|
58089
58157
|
workHistory: () => workHistory
|
|
58090
58158
|
});
|
|
58091
|
-
import { and as
|
|
58159
|
+
import { and as and12, desc as desc7, eq as eq14, isNull as isNull4 } from "drizzle-orm";
|
|
58092
58160
|
async function createSession(session, cwd) {
|
|
58093
58161
|
const db = await getDb(cwd);
|
|
58094
58162
|
const tw = session.taskWork;
|
|
@@ -58148,7 +58216,7 @@ async function listSessions2(filters, cwd) {
|
|
|
58148
58216
|
if (filters?.active) {
|
|
58149
58217
|
conditions.push(eq14(sessions.status, "active"));
|
|
58150
58218
|
}
|
|
58151
|
-
const query = db.select().from(sessions).where(conditions.length > 0 ?
|
|
58219
|
+
const query = db.select().from(sessions).where(conditions.length > 0 ? and12(...conditions) : void 0).orderBy(desc7(sessions.startedAt));
|
|
58152
58220
|
const rows = filters?.limit ? await query.limit(filters.limit).all() : await query.all();
|
|
58153
58221
|
return rows.map(rowToSession);
|
|
58154
58222
|
}
|
|
@@ -58170,7 +58238,7 @@ async function startTask2(sessionId, taskId, cwd) {
|
|
|
58170
58238
|
const db = await getDb(cwd);
|
|
58171
58239
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
58172
58240
|
db.update(taskWorkHistory).set({ clearedAt: now2 }).where(
|
|
58173
|
-
|
|
58241
|
+
and12(
|
|
58174
58242
|
eq14(taskWorkHistory.sessionId, sessionId),
|
|
58175
58243
|
isNull4(taskWorkHistory.clearedAt)
|
|
58176
58244
|
)
|
|
@@ -58191,7 +58259,7 @@ async function stopTask2(sessionId, cwd) {
|
|
|
58191
58259
|
const db = await getDb(cwd);
|
|
58192
58260
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
58193
58261
|
db.update(taskWorkHistory).set({ clearedAt: now2 }).where(
|
|
58194
|
-
|
|
58262
|
+
and12(
|
|
58195
58263
|
eq14(taskWorkHistory.sessionId, sessionId),
|
|
58196
58264
|
isNull4(taskWorkHistory.clearedAt)
|
|
58197
58265
|
)
|
|
@@ -58200,7 +58268,7 @@ async function stopTask2(sessionId, cwd) {
|
|
|
58200
58268
|
}
|
|
58201
58269
|
async function workHistory(sessionId, limit = 50, cwd) {
|
|
58202
58270
|
const db = await getDb(cwd);
|
|
58203
|
-
const rows = await db.select().from(taskWorkHistory).where(eq14(taskWorkHistory.sessionId, sessionId)).orderBy(
|
|
58271
|
+
const rows = await db.select().from(taskWorkHistory).where(eq14(taskWorkHistory.sessionId, sessionId)).orderBy(desc7(taskWorkHistory.setAt), desc7(taskWorkHistory.id)).limit(limit).all();
|
|
58204
58272
|
return rows.map((r) => ({
|
|
58205
58273
|
taskId: r.taskId,
|
|
58206
58274
|
setAt: r.setAt,
|
|
@@ -58211,7 +58279,7 @@ async function gcSessions2(maxAgeDays = 30, cwd) {
|
|
|
58211
58279
|
const db = await getDb(cwd);
|
|
58212
58280
|
const threshold = /* @__PURE__ */ new Date();
|
|
58213
58281
|
threshold.setDate(threshold.getDate() - maxAgeDays);
|
|
58214
|
-
const before = await db.select({ id: sessions.id }).from(sessions).where(
|
|
58282
|
+
const before = await db.select({ id: sessions.id }).from(sessions).where(and12(eq14(sessions.status, "ended"))).all();
|
|
58215
58283
|
const toUpdate = before;
|
|
58216
58284
|
if (toUpdate.length > 0) {
|
|
58217
58285
|
db.update(sessions).set({ status: "orphaned" }).where(eq14(sessions.status, "ended")).run();
|
|
@@ -58220,7 +58288,7 @@ async function gcSessions2(maxAgeDays = 30, cwd) {
|
|
|
58220
58288
|
}
|
|
58221
58289
|
async function getActiveSession(cwd) {
|
|
58222
58290
|
const db = await getDb(cwd);
|
|
58223
|
-
const rows = await db.select().from(sessions).where(eq14(sessions.status, "active")).orderBy(
|
|
58291
|
+
const rows = await db.select().from(sessions).where(eq14(sessions.status, "active")).orderBy(desc7(sessions.startedAt)).limit(1).all();
|
|
58224
58292
|
if (rows.length === 0) return null;
|
|
58225
58293
|
return rowToSession(rows[0]);
|
|
58226
58294
|
}
|
|
@@ -58389,7 +58457,7 @@ __export(task_store_exports, {
|
|
|
58389
58457
|
updateTask: () => updateTask2,
|
|
58390
58458
|
updateTaskSafe: () => updateTaskSafe
|
|
58391
58459
|
});
|
|
58392
|
-
import { and as
|
|
58460
|
+
import { and as and13, asc as asc4, count as count4, eq as eq16, inArray as inArray7, isNull as isNull5, ne as ne5, sql as sql15 } from "drizzle-orm";
|
|
58393
58461
|
async function insertTaskRow(task, cwd) {
|
|
58394
58462
|
const db = await getDb(cwd);
|
|
58395
58463
|
const row = taskToRow(task);
|
|
@@ -58480,7 +58548,7 @@ async function listTasks2(filters, cwd) {
|
|
|
58480
58548
|
}
|
|
58481
58549
|
if (filters?.type) conditions.push(eq16(tasks.type, filters.type));
|
|
58482
58550
|
if (filters?.phase) conditions.push(eq16(tasks.phase, filters.phase));
|
|
58483
|
-
const query = db.select().from(tasks).where(conditions.length > 0 ?
|
|
58551
|
+
const query = db.select().from(tasks).where(conditions.length > 0 ? and13(...conditions) : void 0).orderBy(asc4(tasks.position), asc4(tasks.createdAt));
|
|
58484
58552
|
const rows = filters?.limit ? await query.limit(filters.limit).all() : await query.all();
|
|
58485
58553
|
const tasks2 = rows.map(rowToTask);
|
|
58486
58554
|
await loadDependencies(tasks2, cwd);
|
|
@@ -58490,9 +58558,9 @@ async function findTasks2(query, limit = 20, cwd) {
|
|
|
58490
58558
|
const db = await getDb(cwd);
|
|
58491
58559
|
const pattern = `%${query}%`;
|
|
58492
58560
|
const rows = await db.select().from(tasks).where(
|
|
58493
|
-
|
|
58561
|
+
and13(
|
|
58494
58562
|
ne5(tasks.status, "archived"),
|
|
58495
|
-
|
|
58563
|
+
sql15`(${tasks.id} LIKE ${pattern} OR ${tasks.title} LIKE ${pattern} OR ${tasks.description} LIKE ${pattern})`
|
|
58496
58564
|
)
|
|
58497
58565
|
).limit(limit).all();
|
|
58498
58566
|
return rows.map(rowToTask);
|
|
@@ -58536,7 +58604,7 @@ async function addDependency(taskId, dependsOn, cwd) {
|
|
|
58536
58604
|
async function removeDependency(taskId, dependsOn, cwd) {
|
|
58537
58605
|
const db = await getDb(cwd);
|
|
58538
58606
|
db.delete(taskDependencies).where(
|
|
58539
|
-
|
|
58607
|
+
and13(
|
|
58540
58608
|
eq16(taskDependencies.taskId, taskId),
|
|
58541
58609
|
eq16(taskDependencies.dependsOn, dependsOn)
|
|
58542
58610
|
)
|
|
@@ -58594,7 +58662,7 @@ async function countByStatus2(cwd) {
|
|
|
58594
58662
|
const db = await getDb(cwd);
|
|
58595
58663
|
const rows = await db.select({
|
|
58596
58664
|
status: tasks.status,
|
|
58597
|
-
count:
|
|
58665
|
+
count: count4()
|
|
58598
58666
|
}).from(tasks).where(ne5(tasks.status, "archived")).groupBy(tasks.status).all();
|
|
58599
58667
|
const result = {};
|
|
58600
58668
|
for (const row of rows) {
|
|
@@ -58604,7 +58672,7 @@ async function countByStatus2(cwd) {
|
|
|
58604
58672
|
}
|
|
58605
58673
|
async function countTasks(cwd) {
|
|
58606
58674
|
const db = await getDb(cwd);
|
|
58607
|
-
const result = await db.select({ count:
|
|
58675
|
+
const result = await db.select({ count: count4() }).from(tasks).where(ne5(tasks.status, "archived")).get();
|
|
58608
58676
|
return result?.count ?? 0;
|
|
58609
58677
|
}
|
|
58610
58678
|
async function createTask(task, cwd, config2) {
|
|
@@ -58700,8 +58768,8 @@ __export(migration_sqlite_exports, {
|
|
|
58700
58768
|
migrateJsonToSqlite: () => migrateJsonToSqlite2,
|
|
58701
58769
|
migrateJsonToSqliteAtomic: () => migrateJsonToSqliteAtomic
|
|
58702
58770
|
});
|
|
58703
|
-
import { existsSync as
|
|
58704
|
-
import { dirname as
|
|
58771
|
+
import { existsSync as existsSync118, mkdirSync as mkdirSync28, readFileSync as readFileSync83 } from "node:fs";
|
|
58772
|
+
import { dirname as dirname24, join as join115 } from "node:path";
|
|
58705
58773
|
function topoSortTasks(tasks2) {
|
|
58706
58774
|
const taskMap = new Map(tasks2.map((t) => [t.id, t]));
|
|
58707
58775
|
const sorted = [];
|
|
@@ -58736,26 +58804,26 @@ function countJsonRecords(cleoDir) {
|
|
|
58736
58804
|
let tasks2 = 0;
|
|
58737
58805
|
let archived = 0;
|
|
58738
58806
|
let sessions2 = 0;
|
|
58739
|
-
const todoPath =
|
|
58740
|
-
if (
|
|
58807
|
+
const todoPath = join115(cleoDir, "todo.json");
|
|
58808
|
+
if (existsSync118(todoPath)) {
|
|
58741
58809
|
try {
|
|
58742
|
-
const data = JSON.parse(
|
|
58810
|
+
const data = JSON.parse(readFileSync83(todoPath, "utf-8"));
|
|
58743
58811
|
tasks2 = (data.tasks ?? []).length;
|
|
58744
58812
|
} catch {
|
|
58745
58813
|
}
|
|
58746
58814
|
}
|
|
58747
|
-
const archivePath =
|
|
58748
|
-
if (
|
|
58815
|
+
const archivePath = join115(cleoDir, "todo-archive.json");
|
|
58816
|
+
if (existsSync118(archivePath)) {
|
|
58749
58817
|
try {
|
|
58750
|
-
const data = JSON.parse(
|
|
58818
|
+
const data = JSON.parse(readFileSync83(archivePath, "utf-8"));
|
|
58751
58819
|
archived = (data.tasks ?? data.archivedTasks ?? []).length;
|
|
58752
58820
|
} catch {
|
|
58753
58821
|
}
|
|
58754
58822
|
}
|
|
58755
|
-
const sessionsPath =
|
|
58756
|
-
if (
|
|
58823
|
+
const sessionsPath = join115(cleoDir, "sessions.json");
|
|
58824
|
+
if (existsSync118(sessionsPath)) {
|
|
58757
58825
|
try {
|
|
58758
|
-
const data = JSON.parse(
|
|
58826
|
+
const data = JSON.parse(readFileSync83(sessionsPath, "utf-8"));
|
|
58759
58827
|
sessions2 = (data.sessions ?? []).length;
|
|
58760
58828
|
} catch {
|
|
58761
58829
|
}
|
|
@@ -58779,7 +58847,7 @@ async function migrateJsonToSqliteAtomic(cwd, tempDbPath, logger) {
|
|
|
58779
58847
|
closeDb2();
|
|
58780
58848
|
try {
|
|
58781
58849
|
logger?.info("import", "init", "Initializing node:sqlite for migration");
|
|
58782
|
-
|
|
58850
|
+
mkdirSync28(dirname24(tempDbPath), { recursive: true });
|
|
58783
58851
|
const nativeDb = openNativeDatabase(tempDbPath, { enableWal: true });
|
|
58784
58852
|
const db = drizzle({ client: nativeDb, schema: tasks_schema_exports });
|
|
58785
58853
|
logger?.info("import", "create-tables", "Running drizzle migrations to create tables");
|
|
@@ -58822,13 +58890,13 @@ async function migrateJsonToSqliteAtomic(cwd, tempDbPath, logger) {
|
|
|
58822
58890
|
}
|
|
58823
58891
|
}
|
|
58824
58892
|
async function runMigrationDataImport(db, cleoDir, result, logger) {
|
|
58825
|
-
const todoPath =
|
|
58826
|
-
if (
|
|
58893
|
+
const todoPath = join115(cleoDir, "todo.json");
|
|
58894
|
+
if (existsSync118(todoPath)) {
|
|
58827
58895
|
try {
|
|
58828
58896
|
logger?.info("import", "read-todo", "Reading todo.json", {
|
|
58829
58897
|
path: todoPath.replace(cleoDir, ".")
|
|
58830
58898
|
});
|
|
58831
|
-
const todoData = JSON.parse(
|
|
58899
|
+
const todoData = JSON.parse(readFileSync83(todoPath, "utf-8"));
|
|
58832
58900
|
const tasks2 = topoSortTasks(todoData.tasks ?? []);
|
|
58833
58901
|
const totalTasks = tasks2.length;
|
|
58834
58902
|
logger?.info("import", "tasks-start", `Starting import of ${totalTasks} tasks`, {
|
|
@@ -58902,13 +58970,13 @@ async function runMigrationDataImport(db, cleoDir, result, logger) {
|
|
|
58902
58970
|
result.warnings.push("todo.json not found, skipping task import");
|
|
58903
58971
|
logger?.warn("import", "todo-missing", "todo.json not found, skipping task import");
|
|
58904
58972
|
}
|
|
58905
|
-
const archivePath =
|
|
58906
|
-
if (
|
|
58973
|
+
const archivePath = join115(cleoDir, "todo-archive.json");
|
|
58974
|
+
if (existsSync118(archivePath)) {
|
|
58907
58975
|
try {
|
|
58908
58976
|
logger?.info("import", "read-archive", "Reading todo-archive.json", {
|
|
58909
58977
|
path: archivePath.replace(cleoDir, ".")
|
|
58910
58978
|
});
|
|
58911
|
-
const archiveData = JSON.parse(
|
|
58979
|
+
const archiveData = JSON.parse(readFileSync83(archivePath, "utf-8"));
|
|
58912
58980
|
const archivedTasks = topoSortTasks(archiveData.tasks ?? archiveData.archivedTasks ?? []);
|
|
58913
58981
|
const totalArchived = archivedTasks.length;
|
|
58914
58982
|
logger?.info(
|
|
@@ -58971,13 +59039,13 @@ async function runMigrationDataImport(db, cleoDir, result, logger) {
|
|
|
58971
59039
|
logger?.error("import", "parse-archive", errorMsg);
|
|
58972
59040
|
}
|
|
58973
59041
|
}
|
|
58974
|
-
const sessionsPath =
|
|
58975
|
-
if (
|
|
59042
|
+
const sessionsPath = join115(cleoDir, "sessions.json");
|
|
59043
|
+
if (existsSync118(sessionsPath)) {
|
|
58976
59044
|
try {
|
|
58977
59045
|
logger?.info("import", "read-sessions", "Reading sessions.json", {
|
|
58978
59046
|
path: sessionsPath.replace(cleoDir, ".")
|
|
58979
59047
|
});
|
|
58980
|
-
const sessionsData = JSON.parse(
|
|
59048
|
+
const sessionsData = JSON.parse(readFileSync83(sessionsPath, "utf-8"));
|
|
58981
59049
|
const sessions2 = sessionsData.sessions ?? [];
|
|
58982
59050
|
const totalSessions = sessions2.length;
|
|
58983
59051
|
logger?.info("import", "sessions-start", `Starting import of ${totalSessions} sessions`, {
|
|
@@ -59046,11 +59114,11 @@ async function migrateJsonToSqlite2(cwd, options) {
|
|
|
59046
59114
|
const jsonCounts = countJsonRecords(cleoDir);
|
|
59047
59115
|
result.jsonCounts = jsonCounts;
|
|
59048
59116
|
if (dbExists(cwd)) {
|
|
59049
|
-
const { ne: ne6, eq: eq17, count:
|
|
59117
|
+
const { ne: ne6, eq: eq17, count: count5 } = await import("drizzle-orm");
|
|
59050
59118
|
const db2 = await getDb(cwd);
|
|
59051
|
-
const tasksResult = await db2.select({ count:
|
|
59052
|
-
const archivedResult = await db2.select({ count:
|
|
59053
|
-
const sessionsResult = await db2.select({ count:
|
|
59119
|
+
const tasksResult = await db2.select({ count: count5() }).from(tasks).where(ne6(tasks.status, "archived")).get();
|
|
59120
|
+
const archivedResult = await db2.select({ count: count5() }).from(tasks).where(eq17(tasks.status, "archived")).get();
|
|
59121
|
+
const sessionsResult = await db2.select({ count: count5() }).from(sessions).get();
|
|
59054
59122
|
const existingCounts = {
|
|
59055
59123
|
tasks: tasksResult?.count ?? 0,
|
|
59056
59124
|
archived: archivedResult?.count ?? 0,
|
|
@@ -59104,10 +59172,10 @@ async function migrateJsonToSqlite2(cwd, options) {
|
|
|
59104
59172
|
return result;
|
|
59105
59173
|
}
|
|
59106
59174
|
const db = await getDb(cwd);
|
|
59107
|
-
const todoPath =
|
|
59108
|
-
if (
|
|
59175
|
+
const todoPath = join115(cleoDir, "todo.json");
|
|
59176
|
+
if (existsSync118(todoPath)) {
|
|
59109
59177
|
try {
|
|
59110
|
-
const todoData = JSON.parse(
|
|
59178
|
+
const todoData = JSON.parse(readFileSync83(todoPath, "utf-8"));
|
|
59111
59179
|
const tasks2 = topoSortTasks(todoData.tasks ?? []);
|
|
59112
59180
|
for (const task of tasks2) {
|
|
59113
59181
|
try {
|
|
@@ -59156,10 +59224,10 @@ async function migrateJsonToSqlite2(cwd, options) {
|
|
|
59156
59224
|
} else {
|
|
59157
59225
|
result.warnings.push("todo.json not found, skipping task import");
|
|
59158
59226
|
}
|
|
59159
|
-
const archivePath =
|
|
59160
|
-
if (
|
|
59227
|
+
const archivePath = join115(cleoDir, "todo-archive.json");
|
|
59228
|
+
if (existsSync118(archivePath)) {
|
|
59161
59229
|
try {
|
|
59162
|
-
const archiveData = JSON.parse(
|
|
59230
|
+
const archiveData = JSON.parse(readFileSync83(archivePath, "utf-8"));
|
|
59163
59231
|
const archivedTasks = topoSortTasks(archiveData.tasks ?? archiveData.archivedTasks ?? []);
|
|
59164
59232
|
for (const task of archivedTasks) {
|
|
59165
59233
|
try {
|
|
@@ -59194,10 +59262,10 @@ async function migrateJsonToSqlite2(cwd, options) {
|
|
|
59194
59262
|
result.errors.push(`Failed to parse todo-archive.json: ${String(err)}`);
|
|
59195
59263
|
}
|
|
59196
59264
|
}
|
|
59197
|
-
const sessionsPath =
|
|
59198
|
-
if (
|
|
59265
|
+
const sessionsPath = join115(cleoDir, "sessions.json");
|
|
59266
|
+
if (existsSync118(sessionsPath)) {
|
|
59199
59267
|
try {
|
|
59200
|
-
const sessionsData = JSON.parse(
|
|
59268
|
+
const sessionsData = JSON.parse(readFileSync83(sessionsPath, "utf-8"));
|
|
59201
59269
|
const sessions2 = sessionsData.sessions ?? [];
|
|
59202
59270
|
for (const session of sessions2) {
|
|
59203
59271
|
try {
|
|
@@ -59299,10 +59367,10 @@ async function repairMissingSizes(cwd, dryRun) {
|
|
|
59299
59367
|
async function repairMissingCompletedAt(cwd, dryRun) {
|
|
59300
59368
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
59301
59369
|
const { tasks: tasks2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
|
|
59302
|
-
const { sql:
|
|
59370
|
+
const { sql: sql16 } = await import("drizzle-orm");
|
|
59303
59371
|
const db = await getDb4(cwd);
|
|
59304
59372
|
const affected = await db.select({ id: tasks2.id }).from(tasks2).where(
|
|
59305
|
-
|
|
59373
|
+
sql16`(${tasks2.status} = 'done' OR ${tasks2.status} = 'cancelled') AND ${tasks2.completedAt} IS NULL`
|
|
59306
59374
|
);
|
|
59307
59375
|
if (affected.length === 0) {
|
|
59308
59376
|
return {
|
|
@@ -59320,7 +59388,7 @@ async function repairMissingCompletedAt(cwd, dryRun) {
|
|
|
59320
59388
|
}
|
|
59321
59389
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
59322
59390
|
await db.update(tasks2).set({ completedAt: now2 }).where(
|
|
59323
|
-
|
|
59391
|
+
sql16`(${tasks2.status} = 'done' OR ${tasks2.status} = 'cancelled') AND ${tasks2.completedAt} IS NULL`
|
|
59324
59392
|
);
|
|
59325
59393
|
return {
|
|
59326
59394
|
action: "fix_completed_at",
|
|
@@ -59331,8 +59399,8 @@ async function repairMissingCompletedAt(cwd, dryRun) {
|
|
|
59331
59399
|
async function repairMissingColumns(cwd, dryRun) {
|
|
59332
59400
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
59333
59401
|
const db = await getDb4(cwd);
|
|
59334
|
-
const { sql:
|
|
59335
|
-
const columns = db.all(
|
|
59402
|
+
const { sql: sql16 } = await import("drizzle-orm");
|
|
59403
|
+
const columns = db.all(sql16`PRAGMA table_info(tasks)`);
|
|
59336
59404
|
const existingCols = new Set(columns.map((c) => c.name));
|
|
59337
59405
|
const missingCols = ["pipeline_stage"].filter((c) => !existingCols.has(c));
|
|
59338
59406
|
if (missingCols.length === 0) {
|
|
@@ -59350,7 +59418,7 @@ async function repairMissingColumns(cwd, dryRun) {
|
|
|
59350
59418
|
};
|
|
59351
59419
|
}
|
|
59352
59420
|
for (const col of missingCols) {
|
|
59353
|
-
db.run(
|
|
59421
|
+
db.run(sql16.raw(`ALTER TABLE tasks ADD COLUMN ${col} text`));
|
|
59354
59422
|
}
|
|
59355
59423
|
return {
|
|
59356
59424
|
action: "fix_missing_columns",
|
|
@@ -60373,10 +60441,10 @@ var require_codegen = __commonJS({
|
|
|
60373
60441
|
}
|
|
60374
60442
|
exports.not = not2;
|
|
60375
60443
|
var andCode = mappend(exports.operators.AND);
|
|
60376
|
-
function
|
|
60444
|
+
function and14(...args) {
|
|
60377
60445
|
return args.reduce(andCode);
|
|
60378
60446
|
}
|
|
60379
|
-
exports.and =
|
|
60447
|
+
exports.and = and14;
|
|
60380
60448
|
var orCode = mappend(exports.operators.OR);
|
|
60381
60449
|
function or7(...args) {
|
|
60382
60450
|
return args.reduce(orCode);
|
|
@@ -61559,20 +61627,20 @@ var require_resolve = __commonJS({
|
|
|
61559
61627
|
return false;
|
|
61560
61628
|
}
|
|
61561
61629
|
function countKeys(schema) {
|
|
61562
|
-
let
|
|
61630
|
+
let count5 = 0;
|
|
61563
61631
|
for (const key in schema) {
|
|
61564
61632
|
if (key === "$ref")
|
|
61565
61633
|
return Infinity;
|
|
61566
|
-
|
|
61634
|
+
count5++;
|
|
61567
61635
|
if (SIMPLE_INLINED.has(key))
|
|
61568
61636
|
continue;
|
|
61569
61637
|
if (typeof schema[key] == "object") {
|
|
61570
|
-
(0, util_1.eachItem)(schema[key], (sch) =>
|
|
61638
|
+
(0, util_1.eachItem)(schema[key], (sch) => count5 += countKeys(sch));
|
|
61571
61639
|
}
|
|
61572
|
-
if (
|
|
61640
|
+
if (count5 === Infinity)
|
|
61573
61641
|
return Infinity;
|
|
61574
61642
|
}
|
|
61575
|
-
return
|
|
61643
|
+
return count5;
|
|
61576
61644
|
}
|
|
61577
61645
|
function getFullPath(resolver, id = "", normalize2) {
|
|
61578
61646
|
if (normalize2 !== false)
|
|
@@ -62323,7 +62391,7 @@ var require_compile = __commonJS({
|
|
|
62323
62391
|
const schOrFunc = root.refs[ref];
|
|
62324
62392
|
if (schOrFunc)
|
|
62325
62393
|
return schOrFunc;
|
|
62326
|
-
let _sch =
|
|
62394
|
+
let _sch = resolve15.call(this, root, ref);
|
|
62327
62395
|
if (_sch === void 0) {
|
|
62328
62396
|
const schema = (_a3 = root.localRefs) === null || _a3 === void 0 ? void 0 : _a3[ref];
|
|
62329
62397
|
const { schemaId } = this.opts;
|
|
@@ -62350,7 +62418,7 @@ var require_compile = __commonJS({
|
|
|
62350
62418
|
function sameSchemaEnv(s1, s22) {
|
|
62351
62419
|
return s1.schema === s22.schema && s1.root === s22.root && s1.baseId === s22.baseId;
|
|
62352
62420
|
}
|
|
62353
|
-
function
|
|
62421
|
+
function resolve15(root, ref) {
|
|
62354
62422
|
let sch;
|
|
62355
62423
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
62356
62424
|
ref = sch;
|
|
@@ -62925,7 +62993,7 @@ var require_fast_uri = __commonJS({
|
|
|
62925
62993
|
}
|
|
62926
62994
|
return uri;
|
|
62927
62995
|
}
|
|
62928
|
-
function
|
|
62996
|
+
function resolve15(baseURI, relativeURI, options) {
|
|
62929
62997
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
62930
62998
|
const resolved = resolveComponent(parse3(baseURI, schemelessOptions), parse3(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
62931
62999
|
schemelessOptions.skipEscape = true;
|
|
@@ -63152,7 +63220,7 @@ var require_fast_uri = __commonJS({
|
|
|
63152
63220
|
var fastUri = {
|
|
63153
63221
|
SCHEMES,
|
|
63154
63222
|
normalize: normalize2,
|
|
63155
|
-
resolve:
|
|
63223
|
+
resolve: resolve15,
|
|
63156
63224
|
resolveComponent,
|
|
63157
63225
|
equal,
|
|
63158
63226
|
serialize,
|
|
@@ -64657,8 +64725,8 @@ var require_contains = __commonJS({
|
|
|
64657
64725
|
cxt.result(valid, () => cxt.reset());
|
|
64658
64726
|
function validateItemsWithCount() {
|
|
64659
64727
|
const schValid = gen.name("_valid");
|
|
64660
|
-
const
|
|
64661
|
-
validateItems(schValid, () => gen.if(schValid, () => checkLimits(
|
|
64728
|
+
const count5 = gen.let("count", 0);
|
|
64729
|
+
validateItems(schValid, () => gen.if(schValid, () => checkLimits(count5)));
|
|
64662
64730
|
}
|
|
64663
64731
|
function validateItems(_valid, block) {
|
|
64664
64732
|
gen.forRange("i", 0, len, (i) => {
|
|
@@ -64671,16 +64739,16 @@ var require_contains = __commonJS({
|
|
|
64671
64739
|
block();
|
|
64672
64740
|
});
|
|
64673
64741
|
}
|
|
64674
|
-
function checkLimits(
|
|
64675
|
-
gen.code((0, codegen_1._)`${
|
|
64742
|
+
function checkLimits(count5) {
|
|
64743
|
+
gen.code((0, codegen_1._)`${count5}++`);
|
|
64676
64744
|
if (max === void 0) {
|
|
64677
|
-
gen.if((0, codegen_1._)`${
|
|
64745
|
+
gen.if((0, codegen_1._)`${count5} >= ${min}`, () => gen.assign(valid, true).break());
|
|
64678
64746
|
} else {
|
|
64679
|
-
gen.if((0, codegen_1._)`${
|
|
64747
|
+
gen.if((0, codegen_1._)`${count5} > ${max}`, () => gen.assign(valid, false).break());
|
|
64680
64748
|
if (min === 1)
|
|
64681
64749
|
gen.assign(valid, true);
|
|
64682
64750
|
else
|
|
64683
|
-
gen.if((0, codegen_1._)`${
|
|
64751
|
+
gen.if((0, codegen_1._)`${count5} >= ${min}`, () => gen.assign(valid, true));
|
|
64684
64752
|
}
|
|
64685
64753
|
}
|
|
64686
64754
|
}
|
|
@@ -67929,8 +67997,8 @@ function providerInstalled() {
|
|
|
67929
67997
|
}
|
|
67930
67998
|
function providerCount() {
|
|
67931
67999
|
try {
|
|
67932
|
-
const
|
|
67933
|
-
return { success: true, data: { count:
|
|
68000
|
+
const count5 = getProviderCount();
|
|
68001
|
+
return { success: true, data: { count: count5 } };
|
|
67934
68002
|
} catch (err) {
|
|
67935
68003
|
return {
|
|
67936
68004
|
success: false,
|
|
@@ -68738,7 +68806,7 @@ var SseTransport = class {
|
|
|
68738
68806
|
// --------------------------------------------------------------------------
|
|
68739
68807
|
/** Establish SSE connection. Resolves when open, rejects on error. */
|
|
68740
68808
|
connectSse() {
|
|
68741
|
-
return new Promise((
|
|
68809
|
+
return new Promise((resolve15, reject) => {
|
|
68742
68810
|
if (!this.state) {
|
|
68743
68811
|
reject(new Error("No state"));
|
|
68744
68812
|
return;
|
|
@@ -68754,7 +68822,7 @@ var SseTransport = class {
|
|
|
68754
68822
|
clearTimeout(timeout);
|
|
68755
68823
|
this.state.connected = true;
|
|
68756
68824
|
this.state.reconnectAttempts = 0;
|
|
68757
|
-
|
|
68825
|
+
resolve15();
|
|
68758
68826
|
});
|
|
68759
68827
|
es2.addEventListener("message", (event) => {
|
|
68760
68828
|
this.handleSseMessage(event);
|
|
@@ -69736,16 +69804,16 @@ function collectTransitiveDependents(taskId, dependentsMap) {
|
|
|
69736
69804
|
return visited;
|
|
69737
69805
|
}
|
|
69738
69806
|
function countBlockedWork(taskId, transitiveDependents, taskMap) {
|
|
69739
|
-
let
|
|
69807
|
+
let count5 = 0;
|
|
69740
69808
|
for (const depId of transitiveDependents) {
|
|
69741
69809
|
if (depId === taskId) continue;
|
|
69742
69810
|
const task = taskMap.get(depId);
|
|
69743
69811
|
if (!task) continue;
|
|
69744
69812
|
if (task.status !== "done" && task.status !== "cancelled") {
|
|
69745
|
-
|
|
69813
|
+
count5++;
|
|
69746
69814
|
}
|
|
69747
69815
|
}
|
|
69748
|
-
return
|
|
69816
|
+
return count5;
|
|
69749
69817
|
}
|
|
69750
69818
|
function findAffectedPipelines(taskId, transitiveDependents, tasks2) {
|
|
69751
69819
|
const affectedEpicIds = /* @__PURE__ */ new Set();
|
|
@@ -70354,19 +70422,19 @@ async function extractWorkflowPatterns(accessor, minFrequency) {
|
|
|
70354
70422
|
depTargetCounts.set(dep, (depTargetCounts.get(dep) || 0) + 1);
|
|
70355
70423
|
}
|
|
70356
70424
|
}
|
|
70357
|
-
for (const [taskId,
|
|
70358
|
-
if (
|
|
70425
|
+
for (const [taskId, count5] of depTargetCounts) {
|
|
70426
|
+
if (count5 >= minFrequency) {
|
|
70359
70427
|
const hubTask = allTasks.find((t) => t.id === taskId);
|
|
70360
70428
|
const title = hubTask?.title ?? taskId;
|
|
70361
70429
|
patterns.push({
|
|
70362
70430
|
type: "workflow",
|
|
70363
|
-
pattern: `Task "${title}" (${taskId}) is a dependency hub with ${
|
|
70431
|
+
pattern: `Task "${title}" (${taskId}) is a dependency hub with ${count5} dependents`,
|
|
70364
70432
|
context: "Dependency graph analysis \u2014 hub tasks are critical path candidates",
|
|
70365
|
-
frequency:
|
|
70433
|
+
frequency: count5,
|
|
70366
70434
|
successRate: hubTask?.status === "done" ? 1 : null,
|
|
70367
|
-
impact:
|
|
70368
|
-
antiPattern:
|
|
70369
|
-
mitigation:
|
|
70435
|
+
impact: count5 >= 5 ? "high" : "medium",
|
|
70436
|
+
antiPattern: count5 >= 8 ? `Task ${taskId} may be an overly-centralized bottleneck` : null,
|
|
70437
|
+
mitigation: count5 >= 8 ? "Consider decomposing this task to reduce coupling" : null,
|
|
70370
70438
|
examples: allTasks.filter((t) => t.depends?.includes(taskId)).slice(0, 10).map((t) => t.id),
|
|
70371
70439
|
confidence: 0.7
|
|
70372
70440
|
});
|
|
@@ -70408,18 +70476,18 @@ async function extractObservationPatterns(brainAccessor, minFrequency) {
|
|
|
70408
70476
|
for (const obs of observations) {
|
|
70409
70477
|
typeCounts.set(obs.type, (typeCounts.get(obs.type) || 0) + 1);
|
|
70410
70478
|
}
|
|
70411
|
-
for (const [type,
|
|
70412
|
-
if (
|
|
70479
|
+
for (const [type, count5] of typeCounts) {
|
|
70480
|
+
if (count5 >= minFrequency) {
|
|
70413
70481
|
const patternType = observationTypeToPatternType(type);
|
|
70414
70482
|
patterns.push({
|
|
70415
70483
|
type: patternType,
|
|
70416
|
-
pattern: `${
|
|
70484
|
+
pattern: `${count5} "${type}" observations recorded`,
|
|
70417
70485
|
context: "Brain observation frequency analysis",
|
|
70418
|
-
frequency:
|
|
70486
|
+
frequency: count5,
|
|
70419
70487
|
successRate: type === "feature" || type === "refactor" ? 0.8 : null,
|
|
70420
|
-
impact:
|
|
70421
|
-
antiPattern: type === "bugfix" &&
|
|
70422
|
-
mitigation: type === "bugfix" &&
|
|
70488
|
+
impact: count5 >= 10 ? "high" : count5 >= 5 ? "medium" : "low",
|
|
70489
|
+
antiPattern: type === "bugfix" && count5 >= 5 ? "High number of bugfix observations may indicate quality issues" : null,
|
|
70490
|
+
mitigation: type === "bugfix" && count5 >= 5 ? "Consider adding more automated tests and code review" : null,
|
|
70423
70491
|
examples: observations.filter((o) => o.type === type).slice(0, 5).map((o) => o.id),
|
|
70424
70492
|
confidence: 0.5
|
|
70425
70493
|
});
|
|
@@ -70431,13 +70499,13 @@ async function extractObservationPatterns(brainAccessor, minFrequency) {
|
|
|
70431
70499
|
projectCounts.set(obs.project, (projectCounts.get(obs.project) || 0) + 1);
|
|
70432
70500
|
}
|
|
70433
70501
|
}
|
|
70434
|
-
for (const [project,
|
|
70435
|
-
if (
|
|
70502
|
+
for (const [project, count5] of projectCounts) {
|
|
70503
|
+
if (count5 >= minFrequency * 2) {
|
|
70436
70504
|
patterns.push({
|
|
70437
70505
|
type: "workflow",
|
|
70438
|
-
pattern: `Project "${project}" has ${
|
|
70506
|
+
pattern: `Project "${project}" has ${count5} observations \u2014 high activity area`,
|
|
70439
70507
|
context: "Cross-project observation density analysis",
|
|
70440
|
-
frequency:
|
|
70508
|
+
frequency: count5,
|
|
70441
70509
|
successRate: null,
|
|
70442
70510
|
impact: "medium",
|
|
70443
70511
|
antiPattern: null,
|
|
@@ -70951,7 +71019,7 @@ function augmentError(err, context) {
|
|
|
70951
71019
|
}
|
|
70952
71020
|
}
|
|
70953
71021
|
function sleep2(ms2) {
|
|
70954
|
-
return new Promise((
|
|
71022
|
+
return new Promise((resolve15) => setTimeout(resolve15, ms2));
|
|
70955
71023
|
}
|
|
70956
71024
|
|
|
70957
71025
|
// packages/core/src/lib/index.ts
|
|
@@ -75854,6 +75922,7 @@ __export(nexus_exports, {
|
|
|
75854
75922
|
nexusSync: () => nexusSync,
|
|
75855
75923
|
nexusSyncAll: () => nexusSyncAll,
|
|
75856
75924
|
nexusUnregister: () => nexusUnregister,
|
|
75925
|
+
nexusUpdateIndexStats: () => nexusUpdateIndexStats,
|
|
75857
75926
|
orphanDetection: () => orphanDetection,
|
|
75858
75927
|
parseDirective: () => parseDirective,
|
|
75859
75928
|
parseQuery: () => parseQuery,
|
|
@@ -76003,8 +76072,8 @@ async function resolveProjectPath2(projectName) {
|
|
|
76003
76072
|
if (projectName === ".") {
|
|
76004
76073
|
try {
|
|
76005
76074
|
const accessor = await getAccessor(process.cwd());
|
|
76006
|
-
const
|
|
76007
|
-
if (
|
|
76075
|
+
const count5 = await accessor.countTasks();
|
|
76076
|
+
if (count5 >= 0) return process.cwd();
|
|
76008
76077
|
throw new Error("No task data");
|
|
76009
76078
|
} catch {
|
|
76010
76079
|
throw new CleoError(
|
|
@@ -80826,17 +80895,17 @@ async function generateReleaseChangelog(version2, loadTasksFn, cwd) {
|
|
|
80826
80895
|
function buildEntry(task) {
|
|
80827
80896
|
const cleanTitle = capitalize(stripConventionalPrefix(task.title));
|
|
80828
80897
|
const safeDesc = task.description?.replace(/\r?\n/g, " ").replace(/\s{2,}/g, " ").trim();
|
|
80829
|
-
const
|
|
80898
|
+
const desc8 = safeDesc;
|
|
80830
80899
|
const shouldIncludeDesc = (() => {
|
|
80831
|
-
if (!
|
|
80900
|
+
if (!desc8 || desc8.length === 0) return false;
|
|
80832
80901
|
const titleNorm = cleanTitle.toLowerCase().replace(/[^a-z0-9\s]/g, "").trim();
|
|
80833
|
-
const descNorm =
|
|
80902
|
+
const descNorm = desc8.toLowerCase().replace(/[^a-z0-9\s]/g, "").trim();
|
|
80834
80903
|
if (titleNorm === descNorm) return false;
|
|
80835
80904
|
if (descNorm.startsWith(titleNorm) && descNorm.length < titleNorm.length * 1.3) return false;
|
|
80836
|
-
return
|
|
80905
|
+
return desc8.length >= 20;
|
|
80837
80906
|
})();
|
|
80838
80907
|
if (shouldIncludeDesc) {
|
|
80839
|
-
const descDisplay =
|
|
80908
|
+
const descDisplay = desc8.length > 150 ? desc8.slice(0, 147) + "..." : desc8;
|
|
80840
80909
|
return `- **${cleanTitle}**: ${descDisplay} (${task.id})`;
|
|
80841
80910
|
}
|
|
80842
80911
|
return `- ${cleanTitle} (${task.id})`;
|
|
@@ -81402,11 +81471,11 @@ __export(remote_exports, {
|
|
|
81402
81471
|
init_paths();
|
|
81403
81472
|
init_git_checkpoint();
|
|
81404
81473
|
import { execFile as execFile5 } from "node:child_process";
|
|
81405
|
-
import { resolve as
|
|
81474
|
+
import { resolve as resolve8 } from "node:path";
|
|
81406
81475
|
import { promisify as promisify5 } from "node:util";
|
|
81407
81476
|
var execFileAsync5 = promisify5(execFile5);
|
|
81408
81477
|
async function cleoGitExec(args, cleoDir) {
|
|
81409
|
-
const abs =
|
|
81478
|
+
const abs = resolve8(cleoDir);
|
|
81410
81479
|
const result = await execFileAsync5("git", args, {
|
|
81411
81480
|
cwd: abs,
|
|
81412
81481
|
env: makeCleoGitEnv(cleoDir),
|
|
@@ -83273,7 +83342,7 @@ __export(security_exports, {
|
|
|
83273
83342
|
// packages/core/src/security/input-sanitization.ts
|
|
83274
83343
|
init_src();
|
|
83275
83344
|
init_tasks_schema();
|
|
83276
|
-
import { isAbsolute as isAbsolute2, normalize, relative as relative6, resolve as
|
|
83345
|
+
import { isAbsolute as isAbsolute2, normalize, relative as relative6, resolve as resolve9 } from "path";
|
|
83277
83346
|
|
|
83278
83347
|
// packages/core/src/tasks/id-generator.ts
|
|
83279
83348
|
function normalizeTaskId(input) {
|
|
@@ -83335,12 +83404,12 @@ function sanitizePath(path8, projectRoot) {
|
|
|
83335
83404
|
if (trimmedPath.includes("\0")) {
|
|
83336
83405
|
throw new SecurityError("Path contains null bytes", "E_PATH_TRAVERSAL", "path");
|
|
83337
83406
|
}
|
|
83338
|
-
const normalizedRoot =
|
|
83407
|
+
const normalizedRoot = resolve9(projectRoot);
|
|
83339
83408
|
let resolvedPath;
|
|
83340
83409
|
if (isAbsolute2(trimmedPath)) {
|
|
83341
83410
|
resolvedPath = normalize(trimmedPath);
|
|
83342
83411
|
} else {
|
|
83343
|
-
resolvedPath =
|
|
83412
|
+
resolvedPath = resolve9(normalizedRoot, trimmedPath);
|
|
83344
83413
|
}
|
|
83345
83414
|
const relativePath = relative6(normalizedRoot, resolvedPath);
|
|
83346
83415
|
if (relativePath.startsWith("..") || isAbsolute2(relativePath)) {
|
|
@@ -85228,7 +85297,7 @@ async function validateOrchestratorCompliance(epicId, cwd) {
|
|
|
85228
85297
|
|
|
85229
85298
|
// packages/core/src/skills/skill-paths.ts
|
|
85230
85299
|
import { existsSync as existsSync82, lstatSync, readlinkSync as readlinkSync2, realpathSync } from "node:fs";
|
|
85231
|
-
import { delimiter, join as join82, resolve as
|
|
85300
|
+
import { delimiter, join as join82, resolve as resolve10 } from "node:path";
|
|
85232
85301
|
import { getCanonicalSkillsDir as getCanonicalSkillsDir2 } from "@cleocode/caamp";
|
|
85233
85302
|
function getCaampCanonical() {
|
|
85234
85303
|
return getCanonicalSkillsDir2();
|
|
@@ -85345,7 +85414,7 @@ function getSkillSourceType(skillDir, projectRoot) {
|
|
|
85345
85414
|
}
|
|
85346
85415
|
} catch {
|
|
85347
85416
|
}
|
|
85348
|
-
if (normalizedDir.startsWith(
|
|
85417
|
+
if (normalizedDir.startsWith(resolve10(embeddedDir)) || normalizedDir.startsWith(join82(root, "skills"))) {
|
|
85349
85418
|
return "embedded";
|
|
85350
85419
|
}
|
|
85351
85420
|
if (normalizedDir.startsWith(caampDir)) {
|
|
@@ -85876,8 +85945,8 @@ async function initializeSpawnAdapters(manifests) {
|
|
|
85876
85945
|
if (!manifest.capabilities?.supportsSpawn) continue;
|
|
85877
85946
|
if (spawnRegistry.hasAdapterForProvider(manifest.provider)) continue;
|
|
85878
85947
|
try {
|
|
85879
|
-
const { join:
|
|
85880
|
-
const modulePath =
|
|
85948
|
+
const { join: join123 } = await import("node:path");
|
|
85949
|
+
const modulePath = join123(manifest.packagePath, manifest.entryPoint);
|
|
85881
85950
|
const adapterModule = await import(modulePath);
|
|
85882
85951
|
let SpawnProviderClass;
|
|
85883
85952
|
for (const [exportName, exportValue] of Object.entries(adapterModule)) {
|
|
@@ -85921,7 +85990,7 @@ async function queryTasks(cwd, since) {
|
|
|
85921
85990
|
try {
|
|
85922
85991
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
85923
85992
|
const { tasks: tasks2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
|
|
85924
|
-
const { and:
|
|
85993
|
+
const { and: and14, gte: gte4 } = await import("drizzle-orm");
|
|
85925
85994
|
const db = await getDb4(cwd);
|
|
85926
85995
|
const conditions = [];
|
|
85927
85996
|
if (since) {
|
|
@@ -85935,7 +86004,7 @@ async function queryTasks(cwd, since) {
|
|
|
85935
86004
|
sessionId: tasks2.sessionId,
|
|
85936
86005
|
completedAt: tasks2.completedAt,
|
|
85937
86006
|
createdAt: tasks2.createdAt
|
|
85938
|
-
}).from(tasks2).where(conditions.length > 0 ?
|
|
86007
|
+
}).from(tasks2).where(conditions.length > 0 ? and14(...conditions) : void 0).all();
|
|
85939
86008
|
return rows;
|
|
85940
86009
|
} catch (err) {
|
|
85941
86010
|
log9.warn({ err }, "Failed to query tasks for workflow telemetry");
|
|
@@ -85946,7 +86015,7 @@ async function queryCompletionAuditRows(cwd, since) {
|
|
|
85946
86015
|
try {
|
|
85947
86016
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
85948
86017
|
const { auditLog: auditLog2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
|
|
85949
|
-
const { and:
|
|
86018
|
+
const { and: and14, gte: gte4 } = await import("drizzle-orm");
|
|
85950
86019
|
const db = await getDb4(cwd);
|
|
85951
86020
|
const conditions = [];
|
|
85952
86021
|
if (since) conditions.push(gte4(auditLog2.timestamp, since));
|
|
@@ -85958,7 +86027,7 @@ async function queryCompletionAuditRows(cwd, since) {
|
|
|
85958
86027
|
afterJson: auditLog2.afterJson,
|
|
85959
86028
|
operation: auditLog2.operation,
|
|
85960
86029
|
domain: auditLog2.domain
|
|
85961
|
-
}).from(auditLog2).where(conditions.length > 0 ?
|
|
86030
|
+
}).from(auditLog2).where(conditions.length > 0 ? and14(...conditions) : void 0).orderBy(auditLog2.timestamp).all();
|
|
85962
86031
|
return allRows.filter((row) => {
|
|
85963
86032
|
const isComplete = row.action === "task_completed" || row.action === "complete" || row.operation === "complete" && row.domain === "tasks";
|
|
85964
86033
|
if (!isComplete && row.afterJson) {
|
|
@@ -86413,7 +86482,7 @@ async function getDashboard(opts, accessor) {
|
|
|
86413
86482
|
labelMap[label] = (labelMap[label] ?? 0) + 1;
|
|
86414
86483
|
}
|
|
86415
86484
|
}
|
|
86416
|
-
const topLabels = Object.entries(labelMap).map(([label,
|
|
86485
|
+
const topLabels = Object.entries(labelMap).map(([label, count5]) => ({ label, count: count5 })).sort((a, b2) => b2.count - a.count).slice(0, 8);
|
|
86417
86486
|
return {
|
|
86418
86487
|
project,
|
|
86419
86488
|
currentPhase,
|
|
@@ -86451,7 +86520,7 @@ async function getCompletionHistory(opts) {
|
|
|
86451
86520
|
const date6 = c.timestamp.split("T")[0];
|
|
86452
86521
|
byDate[date6] = (byDate[date6] ?? 0) + 1;
|
|
86453
86522
|
}
|
|
86454
|
-
const dailyCounts = Object.entries(byDate).sort(([a], [b2]) => a.localeCompare(b2)).map(([date6,
|
|
86523
|
+
const dailyCounts = Object.entries(byDate).sort(([a], [b2]) => a.localeCompare(b2)).map(([date6, count5]) => ({ date: date6, count: count5 }));
|
|
86455
86524
|
const totalCompletions = completions.length;
|
|
86456
86525
|
const avgPerDay = days > 0 ? Math.round(totalCompletions / days * 100) / 100 : 0;
|
|
86457
86526
|
const peakDay = dailyCounts.reduce((max, d) => d.count > max.count ? d : max, {
|
|
@@ -86948,7 +87017,7 @@ function byLabelReport(tasks2) {
|
|
|
86948
87017
|
counts[label] = (counts[label] ?? 0) + 1;
|
|
86949
87018
|
}
|
|
86950
87019
|
}
|
|
86951
|
-
return Object.entries(counts).map(([label,
|
|
87020
|
+
return Object.entries(counts).map(([label, count5]) => ({ label, count: count5 })).sort((a, b2) => b2.count - a.count);
|
|
86952
87021
|
}
|
|
86953
87022
|
function byPriorityReport(tasks2) {
|
|
86954
87023
|
const PRIO_ORDER = ["critical", "high", "medium", "low", "unset"];
|
|
@@ -87008,15 +87077,15 @@ function trendsReport(tasks2) {
|
|
|
87008
87077
|
const date6 = t.archive.archivedAt.slice(0, 10);
|
|
87009
87078
|
byDay[date6] = (byDay[date6] ?? 0) + 1;
|
|
87010
87079
|
}
|
|
87011
|
-
const dailyEntries = Object.entries(byDay).map(([date6,
|
|
87080
|
+
const dailyEntries = Object.entries(byDay).map(([date6, count5]) => ({ date: date6, count: count5 })).sort((a, b2) => a.date.localeCompare(b2.date));
|
|
87012
87081
|
const byMonth = {};
|
|
87013
|
-
for (const { date: date6, count:
|
|
87082
|
+
for (const { date: date6, count: count5 } of dailyEntries) {
|
|
87014
87083
|
const month = date6.slice(0, 7);
|
|
87015
|
-
byMonth[month] = (byMonth[month] ?? 0) +
|
|
87084
|
+
byMonth[month] = (byMonth[month] ?? 0) + count5;
|
|
87016
87085
|
}
|
|
87017
|
-
const monthlyEntries = Object.entries(byMonth).map(([month,
|
|
87086
|
+
const monthlyEntries = Object.entries(byMonth).map(([month, count5]) => ({
|
|
87018
87087
|
month,
|
|
87019
|
-
count:
|
|
87088
|
+
count: count5
|
|
87020
87089
|
}));
|
|
87021
87090
|
const totalPeriod = dailyEntries.reduce((sum, d) => sum + d.count, 0);
|
|
87022
87091
|
return {
|
|
@@ -89887,6 +89956,304 @@ init_list();
|
|
|
89887
89956
|
init_show();
|
|
89888
89957
|
init_update2();
|
|
89889
89958
|
|
|
89959
|
+
// packages/core/src/telemetry/index.ts
|
|
89960
|
+
var telemetry_exports = {};
|
|
89961
|
+
__export(telemetry_exports, {
|
|
89962
|
+
buildDiagnosticsReport: () => buildDiagnosticsReport,
|
|
89963
|
+
disableTelemetry: () => disableTelemetry,
|
|
89964
|
+
enableTelemetry: () => enableTelemetry,
|
|
89965
|
+
exportTelemetryEvents: () => exportTelemetryEvents,
|
|
89966
|
+
getTelemetryConfigPath: () => getTelemetryConfigPath,
|
|
89967
|
+
getTelemetryDb: () => getTelemetryDb,
|
|
89968
|
+
getTelemetryDbPath: () => getTelemetryDbPath,
|
|
89969
|
+
isTelemetryEnabled: () => isTelemetryEnabled,
|
|
89970
|
+
loadTelemetryConfig: () => loadTelemetryConfig,
|
|
89971
|
+
recordTelemetryEvent: () => recordTelemetryEvent,
|
|
89972
|
+
saveTelemetryConfig: () => saveTelemetryConfig,
|
|
89973
|
+
telemetryEvents: () => telemetryEvents,
|
|
89974
|
+
telemetrySchemaMeta: () => telemetrySchemaMeta
|
|
89975
|
+
});
|
|
89976
|
+
init_paths();
|
|
89977
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
89978
|
+
import { existsSync as existsSync98, mkdirSync as mkdirSync25, readFileSync as readFileSync68, writeFileSync as writeFileSync16 } from "node:fs";
|
|
89979
|
+
import { join as join100 } from "node:path";
|
|
89980
|
+
import { and as and10, count as count2, desc as desc5, gt as gt2, sql as sql13 } from "drizzle-orm";
|
|
89981
|
+
|
|
89982
|
+
// packages/core/src/telemetry/schema.ts
|
|
89983
|
+
var schema_exports = {};
|
|
89984
|
+
__export(schema_exports, {
|
|
89985
|
+
telemetryEvents: () => telemetryEvents,
|
|
89986
|
+
telemetrySchemaMeta: () => telemetrySchemaMeta
|
|
89987
|
+
});
|
|
89988
|
+
init_sqlite_core();
|
|
89989
|
+
import { sql as sql12 } from "drizzle-orm";
|
|
89990
|
+
var telemetryEvents = sqliteTable(
|
|
89991
|
+
"telemetry_events",
|
|
89992
|
+
{
|
|
89993
|
+
/** UUID primary key. */
|
|
89994
|
+
id: text("id").primaryKey(),
|
|
89995
|
+
/** Anonymous install identifier (UUIDv4, generated once on first enable). */
|
|
89996
|
+
anonymousId: text("anonymous_id").notNull(),
|
|
89997
|
+
/** Canonical domain (e.g. "tasks", "session", "memory", "admin"). */
|
|
89998
|
+
domain: text("domain").notNull(),
|
|
89999
|
+
/** CQRS gateway ("query" or "mutate"). */
|
|
90000
|
+
gateway: text("gateway").notNull(),
|
|
90001
|
+
/** Operation name (e.g. "show", "add", "complete"). */
|
|
90002
|
+
operation: text("operation").notNull(),
|
|
90003
|
+
/** Composed command string "{domain}.{operation}" for easy grouping. */
|
|
90004
|
+
command: text("command").notNull(),
|
|
90005
|
+
/** LAFS exit code (0 = success, non-zero = failure). */
|
|
90006
|
+
exitCode: integer("exit_code").notNull().default(0),
|
|
90007
|
+
/** Wall-clock duration in milliseconds. */
|
|
90008
|
+
durationMs: integer("duration_ms").notNull(),
|
|
90009
|
+
/** Machine-readable error code when exit_code != 0. NULL on success. */
|
|
90010
|
+
errorCode: text("error_code"),
|
|
90011
|
+
/** ISO-8601 timestamp of the invocation. */
|
|
90012
|
+
timestamp: text("timestamp").notNull().default(sql12`(datetime('now'))`)
|
|
90013
|
+
},
|
|
90014
|
+
(table) => [
|
|
90015
|
+
index("idx_telemetry_command").on(table.command),
|
|
90016
|
+
index("idx_telemetry_domain").on(table.domain),
|
|
90017
|
+
index("idx_telemetry_exit_code").on(table.exitCode),
|
|
90018
|
+
index("idx_telemetry_timestamp").on(table.timestamp),
|
|
90019
|
+
index("idx_telemetry_duration").on(table.durationMs)
|
|
90020
|
+
]
|
|
90021
|
+
);
|
|
90022
|
+
var telemetrySchemaMeta = sqliteTable("telemetry_schema_meta", {
|
|
90023
|
+
/** Config key. */
|
|
90024
|
+
key: text("key").primaryKey(),
|
|
90025
|
+
/** Config value. */
|
|
90026
|
+
value: text("value").notNull()
|
|
90027
|
+
});
|
|
90028
|
+
|
|
90029
|
+
// packages/core/src/telemetry/sqlite.ts
|
|
90030
|
+
init_node_sqlite();
|
|
90031
|
+
init_paths();
|
|
90032
|
+
init_migration_manager();
|
|
90033
|
+
init_sqlite2();
|
|
90034
|
+
import { mkdirSync as mkdirSync24 } from "node:fs";
|
|
90035
|
+
import { dirname as dirname20, join as join99 } from "node:path";
|
|
90036
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
90037
|
+
var DB_FILENAME4 = "telemetry.db";
|
|
90038
|
+
var TELEMETRY_SCHEMA_VERSION = "1.0.0";
|
|
90039
|
+
var _db3 = null;
|
|
90040
|
+
var _nativeDb3 = null;
|
|
90041
|
+
var _dbPath3 = null;
|
|
90042
|
+
var _initPromise3 = null;
|
|
90043
|
+
function getTelemetryDbPath() {
|
|
90044
|
+
return join99(getCleoHome(), DB_FILENAME4);
|
|
90045
|
+
}
|
|
90046
|
+
function resolveTelemetryMigrationsFolder() {
|
|
90047
|
+
const __filename = fileURLToPath6(import.meta.url);
|
|
90048
|
+
const __dir = dirname20(__filename);
|
|
90049
|
+
const isBundled = __dir.endsWith("/dist") || __dir.endsWith("\\dist");
|
|
90050
|
+
const pkgRoot = isBundled ? join99(__dir, "..") : join99(__dir, "..", "..");
|
|
90051
|
+
return join99(pkgRoot, "migrations", "drizzle-telemetry");
|
|
90052
|
+
}
|
|
90053
|
+
function runTelemetryMigrations(nativeDb, db) {
|
|
90054
|
+
const migrationsFolder = resolveTelemetryMigrationsFolder();
|
|
90055
|
+
reconcileJournal(nativeDb, migrationsFolder, "telemetry_events", "telemetry");
|
|
90056
|
+
migrateWithRetry(db, migrationsFolder, nativeDb, "telemetry_events", "telemetry");
|
|
90057
|
+
ensureColumns(
|
|
90058
|
+
nativeDb,
|
|
90059
|
+
"telemetry_events",
|
|
90060
|
+
[
|
|
90061
|
+
{ name: "anonymous_id", ddl: "text NOT NULL DEFAULT ''" },
|
|
90062
|
+
{ name: "domain", ddl: "text NOT NULL DEFAULT ''" },
|
|
90063
|
+
{ name: "gateway", ddl: "text NOT NULL DEFAULT 'query'" },
|
|
90064
|
+
{ name: "operation", ddl: "text NOT NULL DEFAULT ''" },
|
|
90065
|
+
{ name: "command", ddl: "text NOT NULL DEFAULT ''" },
|
|
90066
|
+
{ name: "exit_code", ddl: "integer NOT NULL DEFAULT 0" },
|
|
90067
|
+
{ name: "duration_ms", ddl: "integer NOT NULL DEFAULT 0" },
|
|
90068
|
+
{ name: "error_code", ddl: "text" }
|
|
90069
|
+
],
|
|
90070
|
+
"telemetry"
|
|
90071
|
+
);
|
|
90072
|
+
}
|
|
90073
|
+
function resetTelemetryDbState() {
|
|
90074
|
+
try {
|
|
90075
|
+
_nativeDb3?.close();
|
|
90076
|
+
} catch {
|
|
90077
|
+
}
|
|
90078
|
+
_db3 = null;
|
|
90079
|
+
_nativeDb3 = null;
|
|
90080
|
+
_dbPath3 = null;
|
|
90081
|
+
_initPromise3 = null;
|
|
90082
|
+
}
|
|
90083
|
+
async function getTelemetryDb() {
|
|
90084
|
+
const requestedPath = getTelemetryDbPath();
|
|
90085
|
+
if (_db3 && _dbPath3 !== requestedPath) {
|
|
90086
|
+
resetTelemetryDbState();
|
|
90087
|
+
}
|
|
90088
|
+
if (_db3) return _db3;
|
|
90089
|
+
if (_initPromise3) return _initPromise3;
|
|
90090
|
+
_initPromise3 = (async () => {
|
|
90091
|
+
const dbPath = requestedPath;
|
|
90092
|
+
_dbPath3 = dbPath;
|
|
90093
|
+
mkdirSync24(dirname20(dbPath), { recursive: true });
|
|
90094
|
+
const nativeDb = openNativeDatabase(dbPath);
|
|
90095
|
+
_nativeDb3 = nativeDb;
|
|
90096
|
+
const db = drizzle({ client: nativeDb, schema: schema_exports });
|
|
90097
|
+
runTelemetryMigrations(nativeDb, db);
|
|
90098
|
+
nativeDb.prepare(
|
|
90099
|
+
`INSERT OR IGNORE INTO telemetry_schema_meta (key, value) VALUES ('schemaVersion', '${TELEMETRY_SCHEMA_VERSION}')`
|
|
90100
|
+
).run();
|
|
90101
|
+
_db3 = db;
|
|
90102
|
+
return db;
|
|
90103
|
+
})();
|
|
90104
|
+
return _initPromise3;
|
|
90105
|
+
}
|
|
90106
|
+
|
|
90107
|
+
// packages/core/src/telemetry/index.ts
|
|
90108
|
+
var TELEMETRY_CONFIG_FILENAME = "telemetry-config.json";
|
|
90109
|
+
function getTelemetryConfigPath() {
|
|
90110
|
+
return join100(getCleoHome(), TELEMETRY_CONFIG_FILENAME);
|
|
90111
|
+
}
|
|
90112
|
+
function loadTelemetryConfig() {
|
|
90113
|
+
const path8 = getTelemetryConfigPath();
|
|
90114
|
+
if (!existsSync98(path8)) {
|
|
90115
|
+
return { enabled: false, anonymousId: "" };
|
|
90116
|
+
}
|
|
90117
|
+
try {
|
|
90118
|
+
return JSON.parse(readFileSync68(path8, "utf-8"));
|
|
90119
|
+
} catch {
|
|
90120
|
+
return { enabled: false, anonymousId: "" };
|
|
90121
|
+
}
|
|
90122
|
+
}
|
|
90123
|
+
function saveTelemetryConfig(config2) {
|
|
90124
|
+
const path8 = getTelemetryConfigPath();
|
|
90125
|
+
mkdirSync25(join100(path8, ".."), { recursive: true });
|
|
90126
|
+
writeFileSync16(path8, JSON.stringify(config2, null, 2), "utf-8");
|
|
90127
|
+
}
|
|
90128
|
+
function isTelemetryEnabled() {
|
|
90129
|
+
return loadTelemetryConfig().enabled;
|
|
90130
|
+
}
|
|
90131
|
+
function enableTelemetry() {
|
|
90132
|
+
const existing = loadTelemetryConfig();
|
|
90133
|
+
const config2 = {
|
|
90134
|
+
enabled: true,
|
|
90135
|
+
anonymousId: existing.anonymousId || randomUUID7()
|
|
90136
|
+
};
|
|
90137
|
+
saveTelemetryConfig(config2);
|
|
90138
|
+
return config2;
|
|
90139
|
+
}
|
|
90140
|
+
function disableTelemetry() {
|
|
90141
|
+
const existing = loadTelemetryConfig();
|
|
90142
|
+
const config2 = { ...existing, enabled: false };
|
|
90143
|
+
saveTelemetryConfig(config2);
|
|
90144
|
+
return config2;
|
|
90145
|
+
}
|
|
90146
|
+
async function recordTelemetryEvent(event) {
|
|
90147
|
+
const config2 = loadTelemetryConfig();
|
|
90148
|
+
if (!config2.enabled || !config2.anonymousId) return;
|
|
90149
|
+
try {
|
|
90150
|
+
const db = await getTelemetryDb();
|
|
90151
|
+
const command = `${event.domain}.${event.operation}`;
|
|
90152
|
+
await db.insert(telemetryEvents).values({
|
|
90153
|
+
id: randomUUID7(),
|
|
90154
|
+
anonymousId: config2.anonymousId,
|
|
90155
|
+
domain: event.domain,
|
|
90156
|
+
gateway: event.gateway,
|
|
90157
|
+
operation: event.operation,
|
|
90158
|
+
command,
|
|
90159
|
+
exitCode: event.exitCode,
|
|
90160
|
+
durationMs: event.durationMs,
|
|
90161
|
+
errorCode: event.errorCode ?? null,
|
|
90162
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
90163
|
+
}).run();
|
|
90164
|
+
} catch {
|
|
90165
|
+
}
|
|
90166
|
+
}
|
|
90167
|
+
function daysAgo(n) {
|
|
90168
|
+
const d = /* @__PURE__ */ new Date();
|
|
90169
|
+
d.setDate(d.getDate() - n);
|
|
90170
|
+
return d.toISOString();
|
|
90171
|
+
}
|
|
90172
|
+
async function buildDiagnosticsReport(days = 30) {
|
|
90173
|
+
const config2 = loadTelemetryConfig();
|
|
90174
|
+
if (!config2.enabled) return null;
|
|
90175
|
+
const db = await getTelemetryDb();
|
|
90176
|
+
const from = daysAgo(days);
|
|
90177
|
+
const to2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
90178
|
+
const [totalRow] = await db.select({ n: count2(telemetryEvents.id) }).from(telemetryEvents).where(gt2(telemetryEvents.timestamp, from)).all();
|
|
90179
|
+
const totalEvents = totalRow?.n ?? 0;
|
|
90180
|
+
if (totalEvents === 0)
|
|
90181
|
+
return {
|
|
90182
|
+
period: { from, to: to2 },
|
|
90183
|
+
totalEvents: 0,
|
|
90184
|
+
topFailing: [],
|
|
90185
|
+
topSlow: [],
|
|
90186
|
+
rareCommands: [],
|
|
90187
|
+
observations: []
|
|
90188
|
+
};
|
|
90189
|
+
const rows = await db.select({
|
|
90190
|
+
command: telemetryEvents.command,
|
|
90191
|
+
total: count2(telemetryEvents.id),
|
|
90192
|
+
failures: sql13`SUM(CASE WHEN ${telemetryEvents.exitCode} != 0 THEN 1 ELSE 0 END)`,
|
|
90193
|
+
avgMs: sql13`AVG(${telemetryEvents.durationMs})`,
|
|
90194
|
+
maxMs: sql13`MAX(${telemetryEvents.durationMs})`
|
|
90195
|
+
}).from(telemetryEvents).where(gt2(telemetryEvents.timestamp, from)).groupBy(telemetryEvents.command).all();
|
|
90196
|
+
const errorCodeRows = await db.select({
|
|
90197
|
+
command: telemetryEvents.command,
|
|
90198
|
+
errorCode: telemetryEvents.errorCode,
|
|
90199
|
+
n: count2(telemetryEvents.id)
|
|
90200
|
+
}).from(telemetryEvents).where(and10(gt2(telemetryEvents.timestamp, from), sql13`${telemetryEvents.errorCode} IS NOT NULL`)).groupBy(telemetryEvents.command, telemetryEvents.errorCode).orderBy(desc5(count2(telemetryEvents.id))).all();
|
|
90201
|
+
const topErrorMap = /* @__PURE__ */ new Map();
|
|
90202
|
+
for (const r of errorCodeRows) {
|
|
90203
|
+
if (!topErrorMap.has(r.command)) {
|
|
90204
|
+
topErrorMap.set(r.command, r.errorCode ?? "");
|
|
90205
|
+
}
|
|
90206
|
+
}
|
|
90207
|
+
const stats2 = rows.map((r) => {
|
|
90208
|
+
const failures = Number(r.failures) || 0;
|
|
90209
|
+
const total = Number(r.total) || 0;
|
|
90210
|
+
return {
|
|
90211
|
+
command: r.command,
|
|
90212
|
+
count: total,
|
|
90213
|
+
failureCount: failures,
|
|
90214
|
+
failureRate: total > 0 ? failures / total : 0,
|
|
90215
|
+
avgDurationMs: Math.round(Number(r.avgMs) || 0),
|
|
90216
|
+
maxDurationMs: Math.round(Number(r.maxMs) || 0),
|
|
90217
|
+
topErrorCode: topErrorMap.get(r.command) ?? null
|
|
90218
|
+
};
|
|
90219
|
+
});
|
|
90220
|
+
const topFailing = stats2.filter((s3) => s3.count >= 5 && s3.failureRate > 0).sort((a, b2) => b2.failureRate - a.failureRate).slice(0, 10);
|
|
90221
|
+
const topSlow = [...stats2].sort((a, b2) => b2.avgDurationMs - a.avgDurationMs).slice(0, 10);
|
|
90222
|
+
const rareCommands = stats2.filter((s3) => s3.count === 1).map((s3) => s3.command);
|
|
90223
|
+
const observations = [];
|
|
90224
|
+
for (const s3 of topFailing.slice(0, 5)) {
|
|
90225
|
+
const pct = Math.round(s3.failureRate * 100);
|
|
90226
|
+
const errPart = s3.topErrorCode ? ` (most common error: ${s3.topErrorCode})` : "";
|
|
90227
|
+
observations.push(
|
|
90228
|
+
`Command '${s3.command}' fails ${pct}% of the time across ${s3.count} invocations${errPart}. Investigate root cause.`
|
|
90229
|
+
);
|
|
90230
|
+
}
|
|
90231
|
+
const sortedAvg = stats2.map((s3) => s3.avgDurationMs).sort((a, b2) => a - b2);
|
|
90232
|
+
const median = sortedAvg[Math.floor(sortedAvg.length / 2)] ?? 0;
|
|
90233
|
+
for (const s3 of topSlow.slice(0, 5)) {
|
|
90234
|
+
if (median > 0 && s3.avgDurationMs > median * 2) {
|
|
90235
|
+
observations.push(
|
|
90236
|
+
`Command '${s3.command}' averages ${s3.avgDurationMs}ms \u2014 ${Math.round(s3.avgDurationMs / median)}x slower than the ${median}ms median. Profile for performance improvement.`
|
|
90237
|
+
);
|
|
90238
|
+
}
|
|
90239
|
+
}
|
|
90240
|
+
return { period: { from, to: to2 }, totalEvents, topFailing, topSlow, rareCommands, observations };
|
|
90241
|
+
}
|
|
90242
|
+
async function exportTelemetryEvents(days) {
|
|
90243
|
+
const config2 = loadTelemetryConfig();
|
|
90244
|
+
if (!config2.enabled) return [];
|
|
90245
|
+
const db = await getTelemetryDb();
|
|
90246
|
+
const rows = days ? await db.select().from(telemetryEvents).where(gt2(telemetryEvents.timestamp, daysAgo(days))).orderBy(desc5(telemetryEvents.timestamp)).all() : await db.select().from(telemetryEvents).orderBy(desc5(telemetryEvents.timestamp)).all();
|
|
90247
|
+
return rows.map((r) => ({
|
|
90248
|
+
domain: r.domain,
|
|
90249
|
+
gateway: r.gateway,
|
|
90250
|
+
operation: r.operation,
|
|
90251
|
+
durationMs: r.durationMs,
|
|
90252
|
+
exitCode: r.exitCode,
|
|
90253
|
+
errorCode: r.errorCode
|
|
90254
|
+
}));
|
|
90255
|
+
}
|
|
90256
|
+
|
|
89890
90257
|
// packages/core/src/templates/index.ts
|
|
89891
90258
|
var templates_exports = {};
|
|
89892
90259
|
__export(templates_exports, {
|
|
@@ -89898,8 +90265,8 @@ __export(templates_exports, {
|
|
|
89898
90265
|
|
|
89899
90266
|
// packages/core/src/templates/parser.ts
|
|
89900
90267
|
init_platform();
|
|
89901
|
-
import { existsSync as
|
|
89902
|
-
import { join as
|
|
90268
|
+
import { existsSync as existsSync99, readdirSync as readdirSync30, readFileSync as readFileSync69 } from "fs";
|
|
90269
|
+
import { join as join101 } from "path";
|
|
89903
90270
|
import { parse as parseYaml } from "yaml";
|
|
89904
90271
|
var SUFFIX_PATTERNS = ["_report", "_request", "_question"];
|
|
89905
90272
|
function deriveSubcommand(filename) {
|
|
@@ -89914,8 +90281,8 @@ function deriveSubcommand(filename) {
|
|
|
89914
90281
|
return firstWord.toLowerCase();
|
|
89915
90282
|
}
|
|
89916
90283
|
function parseTemplateFile2(templateDir, filename) {
|
|
89917
|
-
const filePath =
|
|
89918
|
-
const raw =
|
|
90284
|
+
const filePath = join101(templateDir, filename);
|
|
90285
|
+
const raw = readFileSync69(filePath, "utf-8");
|
|
89919
90286
|
const parsed = parseYaml(raw);
|
|
89920
90287
|
const name2 = typeof parsed.name === "string" ? parsed.name : filename;
|
|
89921
90288
|
const titlePrefix = typeof parsed.title === "string" ? parsed.title : "";
|
|
@@ -89964,8 +90331,8 @@ function parseTemplateFile2(templateDir, filename) {
|
|
|
89964
90331
|
};
|
|
89965
90332
|
}
|
|
89966
90333
|
function parseIssueTemplates2(projectRoot) {
|
|
89967
|
-
const templateDir =
|
|
89968
|
-
if (!
|
|
90334
|
+
const templateDir = join101(projectRoot, ".github", "ISSUE_TEMPLATE");
|
|
90335
|
+
if (!existsSync99(templateDir)) {
|
|
89969
90336
|
return {
|
|
89970
90337
|
success: false,
|
|
89971
90338
|
error: { code: "E_NOT_FOUND", message: `Issue template directory not found: ${templateDir}` }
|
|
@@ -90112,9 +90479,9 @@ __export(ui_exports, {
|
|
|
90112
90479
|
});
|
|
90113
90480
|
|
|
90114
90481
|
// packages/core/src/ui/aliases.ts
|
|
90115
|
-
import { existsSync as
|
|
90482
|
+
import { existsSync as existsSync100, readFileSync as readFileSync70, writeFileSync as writeFileSync17 } from "node:fs";
|
|
90116
90483
|
import { homedir as homedir6, platform as platform3 } from "node:os";
|
|
90117
|
-
import { join as
|
|
90484
|
+
import { join as join102 } from "node:path";
|
|
90118
90485
|
var MARKER_START = "# CLEO-CLAUDE-ALIASES:START";
|
|
90119
90486
|
var MARKER_END = "# CLEO-CLAUDE-ALIASES:END";
|
|
90120
90487
|
var ALIASES_VERSION = "1.0.0";
|
|
@@ -90136,22 +90503,22 @@ function getRcFilePath(shell) {
|
|
|
90136
90503
|
const sh = shell ?? getCurrentShell();
|
|
90137
90504
|
switch (sh) {
|
|
90138
90505
|
case "bash":
|
|
90139
|
-
return
|
|
90506
|
+
return join102(home, ".bashrc");
|
|
90140
90507
|
case "zsh":
|
|
90141
|
-
return
|
|
90508
|
+
return join102(home, ".zshrc");
|
|
90142
90509
|
case "powershell":
|
|
90143
|
-
return
|
|
90510
|
+
return join102(home, "Documents", "PowerShell", "Microsoft.PowerShell_profile.ps1");
|
|
90144
90511
|
case "cmd":
|
|
90145
90512
|
return "";
|
|
90146
90513
|
// CMD doesn't have a standard RC
|
|
90147
90514
|
default:
|
|
90148
|
-
return
|
|
90515
|
+
return join102(home, ".bashrc");
|
|
90149
90516
|
}
|
|
90150
90517
|
}
|
|
90151
90518
|
function detectAvailableShells() {
|
|
90152
90519
|
const shells = [];
|
|
90153
|
-
if (
|
|
90154
|
-
if (
|
|
90520
|
+
if (existsSync100(getRcFilePath("bash")) || existsSync100("/bin/bash")) shells.push("bash");
|
|
90521
|
+
if (existsSync100(getRcFilePath("zsh")) || existsSync100("/bin/zsh")) shells.push("zsh");
|
|
90155
90522
|
if (platform3() === "win32") shells.push("powershell");
|
|
90156
90523
|
return shells;
|
|
90157
90524
|
}
|
|
@@ -90183,47 +90550,47 @@ function generatePowershellAliases(cleoPath) {
|
|
|
90183
90550
|
].join("\n");
|
|
90184
90551
|
}
|
|
90185
90552
|
function hasAliasBlock(filePath) {
|
|
90186
|
-
if (!
|
|
90187
|
-
const content =
|
|
90553
|
+
if (!existsSync100(filePath)) return false;
|
|
90554
|
+
const content = readFileSync70(filePath, "utf-8");
|
|
90188
90555
|
return content.includes(MARKER_START) && content.includes(MARKER_END);
|
|
90189
90556
|
}
|
|
90190
90557
|
function getInstalledVersion(filePath) {
|
|
90191
|
-
if (!
|
|
90192
|
-
const content =
|
|
90558
|
+
if (!existsSync100(filePath)) return null;
|
|
90559
|
+
const content = readFileSync70(filePath, "utf-8");
|
|
90193
90560
|
const match = content.match(/CLEO CLI aliases \(v([^)]+)\)/);
|
|
90194
90561
|
return match?.[1] ?? null;
|
|
90195
90562
|
}
|
|
90196
90563
|
function injectAliases(filePath, shell = "bash", cleoPath) {
|
|
90197
90564
|
const content = shell === "powershell" ? generatePowershellAliases(cleoPath) : generateBashAliases(cleoPath);
|
|
90198
|
-
if (!
|
|
90199
|
-
|
|
90565
|
+
if (!existsSync100(filePath)) {
|
|
90566
|
+
writeFileSync17(filePath, content + "\n", "utf-8");
|
|
90200
90567
|
return { action: "created", version: ALIASES_VERSION };
|
|
90201
90568
|
}
|
|
90202
|
-
const existing =
|
|
90569
|
+
const existing = readFileSync70(filePath, "utf-8");
|
|
90203
90570
|
if (hasAliasBlock(filePath)) {
|
|
90204
90571
|
const startIdx = existing.indexOf(MARKER_START);
|
|
90205
90572
|
const endIdx = existing.indexOf(MARKER_END) + MARKER_END.length;
|
|
90206
90573
|
const updated = existing.slice(0, startIdx) + content + existing.slice(endIdx);
|
|
90207
|
-
|
|
90574
|
+
writeFileSync17(filePath, updated, "utf-8");
|
|
90208
90575
|
return { action: "updated", version: ALIASES_VERSION };
|
|
90209
90576
|
}
|
|
90210
|
-
|
|
90577
|
+
writeFileSync17(filePath, existing + "\n" + content + "\n", "utf-8");
|
|
90211
90578
|
return { action: "added", version: ALIASES_VERSION };
|
|
90212
90579
|
}
|
|
90213
90580
|
function removeAliases(filePath) {
|
|
90214
|
-
if (!
|
|
90215
|
-
const existing =
|
|
90581
|
+
if (!existsSync100(filePath) || !hasAliasBlock(filePath)) return false;
|
|
90582
|
+
const existing = readFileSync70(filePath, "utf-8");
|
|
90216
90583
|
const startIdx = existing.indexOf(MARKER_START);
|
|
90217
90584
|
const endIdx = existing.indexOf(MARKER_END) + MARKER_END.length;
|
|
90218
90585
|
const before = existing.slice(0, startIdx).replace(/\n+$/, "\n");
|
|
90219
90586
|
const after = existing.slice(endIdx).replace(/^\n+/, "\n");
|
|
90220
|
-
|
|
90587
|
+
writeFileSync17(filePath, before + after, "utf-8");
|
|
90221
90588
|
return true;
|
|
90222
90589
|
}
|
|
90223
90590
|
function checkAliasesStatus(shell) {
|
|
90224
90591
|
const sh = shell ?? getCurrentShell();
|
|
90225
90592
|
const rcFile = getRcFilePath(sh);
|
|
90226
|
-
if (!rcFile || !
|
|
90593
|
+
if (!rcFile || !existsSync100(rcFile)) {
|
|
90227
90594
|
return { shell: sh, rcFile, installed: false, version: null, needsUpdate: false };
|
|
90228
90595
|
}
|
|
90229
90596
|
const installed = hasAliasBlock(rcFile);
|
|
@@ -90234,7 +90601,7 @@ function checkAliasesStatus(shell) {
|
|
|
90234
90601
|
|
|
90235
90602
|
// packages/core/src/ui/changelog.ts
|
|
90236
90603
|
init_data_accessor();
|
|
90237
|
-
import { appendFileSync as appendFileSync9, existsSync as
|
|
90604
|
+
import { appendFileSync as appendFileSync9, existsSync as existsSync101, readFileSync as readFileSync71, writeFileSync as writeFileSync18 } from "node:fs";
|
|
90238
90605
|
var LABEL_CATEGORIES = {
|
|
90239
90606
|
feature: "Features",
|
|
90240
90607
|
feat: "Features",
|
|
@@ -90335,21 +90702,21 @@ function formatChangelogJson(version2, date6, sections) {
|
|
|
90335
90702
|
};
|
|
90336
90703
|
}
|
|
90337
90704
|
function writeChangelogFile(filePath, content) {
|
|
90338
|
-
|
|
90705
|
+
writeFileSync18(filePath, content, "utf-8");
|
|
90339
90706
|
}
|
|
90340
90707
|
function appendToChangelog(filePath, newContent) {
|
|
90341
|
-
if (!
|
|
90342
|
-
|
|
90708
|
+
if (!existsSync101(filePath)) {
|
|
90709
|
+
writeFileSync18(filePath, `# Changelog
|
|
90343
90710
|
|
|
90344
90711
|
${newContent}`, "utf-8");
|
|
90345
90712
|
return;
|
|
90346
90713
|
}
|
|
90347
|
-
const existing =
|
|
90714
|
+
const existing = readFileSync71(filePath, "utf-8");
|
|
90348
90715
|
const headerMatch = existing.match(/^# .+\n/m);
|
|
90349
90716
|
if (headerMatch) {
|
|
90350
90717
|
const insertPos = (headerMatch.index ?? 0) + headerMatch[0].length;
|
|
90351
90718
|
const updated = existing.slice(0, insertPos) + "\n" + newContent + existing.slice(insertPos);
|
|
90352
|
-
|
|
90719
|
+
writeFileSync18(filePath, updated, "utf-8");
|
|
90353
90720
|
} else {
|
|
90354
90721
|
appendFileSync9(filePath, "\n" + newContent);
|
|
90355
90722
|
}
|
|
@@ -90384,13 +90751,13 @@ ${markdown}`);
|
|
|
90384
90751
|
}
|
|
90385
90752
|
|
|
90386
90753
|
// packages/core/src/ui/command-registry.ts
|
|
90387
|
-
import { existsSync as
|
|
90388
|
-
import { basename as basename16, join as
|
|
90754
|
+
import { existsSync as existsSync102, readdirSync as readdirSync31, readFileSync as readFileSync72 } from "node:fs";
|
|
90755
|
+
import { basename as basename16, join as join103 } from "node:path";
|
|
90389
90756
|
var CLEO_HEADER_START = "###CLEO";
|
|
90390
90757
|
var CLEO_HEADER_END = "###END";
|
|
90391
90758
|
function parseCommandHeader(scriptPath) {
|
|
90392
|
-
if (!
|
|
90393
|
-
const content =
|
|
90759
|
+
if (!existsSync102(scriptPath)) return null;
|
|
90760
|
+
const content = readFileSync72(scriptPath, "utf-8");
|
|
90394
90761
|
const lines = content.split("\n");
|
|
90395
90762
|
let inHeader = false;
|
|
90396
90763
|
const headerLines = [];
|
|
@@ -90468,10 +90835,10 @@ function parseCommandHeader(scriptPath) {
|
|
|
90468
90835
|
}
|
|
90469
90836
|
function scanAllCommands(scriptsDir) {
|
|
90470
90837
|
const registry2 = /* @__PURE__ */ new Map();
|
|
90471
|
-
if (!
|
|
90838
|
+
if (!existsSync102(scriptsDir)) return registry2;
|
|
90472
90839
|
for (const file2 of readdirSync31(scriptsDir)) {
|
|
90473
90840
|
if (!file2.endsWith(".sh") && !file2.endsWith(".ts")) continue;
|
|
90474
|
-
const meta3 = parseCommandHeader(
|
|
90841
|
+
const meta3 = parseCommandHeader(join103(scriptsDir, file2));
|
|
90475
90842
|
if (meta3) {
|
|
90476
90843
|
registry2.set(meta3.command, meta3);
|
|
90477
90844
|
}
|
|
@@ -90877,10 +91244,10 @@ function calculateOrchestrationOverhead(orchestratorTokens, totalSubagentTokens,
|
|
|
90877
91244
|
}
|
|
90878
91245
|
|
|
90879
91246
|
// packages/core/src/validation/docs-sync.ts
|
|
90880
|
-
import { existsSync as
|
|
90881
|
-
import { join as
|
|
91247
|
+
import { existsSync as existsSync103, readdirSync as readdirSync32, readFileSync as readFileSync73 } from "node:fs";
|
|
91248
|
+
import { join as join104 } from "node:path";
|
|
90882
91249
|
function getScriptCommands(scriptsDir) {
|
|
90883
|
-
if (!
|
|
91250
|
+
if (!existsSync103(scriptsDir)) return [];
|
|
90884
91251
|
try {
|
|
90885
91252
|
return readdirSync32(scriptsDir).filter((f2) => f2.endsWith(".sh")).map((f2) => f2.replace(/\.sh$/, "")).sort();
|
|
90886
91253
|
} catch {
|
|
@@ -90888,9 +91255,9 @@ function getScriptCommands(scriptsDir) {
|
|
|
90888
91255
|
}
|
|
90889
91256
|
}
|
|
90890
91257
|
function getIndexScripts(indexPath) {
|
|
90891
|
-
if (!
|
|
91258
|
+
if (!existsSync103(indexPath)) return [];
|
|
90892
91259
|
try {
|
|
90893
|
-
const content =
|
|
91260
|
+
const content = readFileSync73(indexPath, "utf-8");
|
|
90894
91261
|
const index2 = JSON.parse(content);
|
|
90895
91262
|
return index2.commands.map((cmd) => cmd.script ?? "").filter((s3) => s3).map((s3) => s3.replace(/\.sh$/, "")).sort();
|
|
90896
91263
|
} catch {
|
|
@@ -90898,9 +91265,9 @@ function getIndexScripts(indexPath) {
|
|
|
90898
91265
|
}
|
|
90899
91266
|
}
|
|
90900
91267
|
function getIndexCommands(indexPath) {
|
|
90901
|
-
if (!
|
|
91268
|
+
if (!existsSync103(indexPath)) return [];
|
|
90902
91269
|
try {
|
|
90903
|
-
const content =
|
|
91270
|
+
const content = readFileSync73(indexPath, "utf-8");
|
|
90904
91271
|
const index2 = JSON.parse(content);
|
|
90905
91272
|
return index2.commands.map((cmd) => cmd.name).sort();
|
|
90906
91273
|
} catch {
|
|
@@ -90934,11 +91301,11 @@ function checkCommandsSync(scriptsDir, indexPath) {
|
|
|
90934
91301
|
return issues;
|
|
90935
91302
|
}
|
|
90936
91303
|
function checkWrapperSync(wrapperPath, indexPath) {
|
|
90937
|
-
if (!
|
|
91304
|
+
if (!existsSync103(wrapperPath) || !existsSync103(indexPath)) return [];
|
|
90938
91305
|
const issues = [];
|
|
90939
91306
|
try {
|
|
90940
|
-
const wrapperContent =
|
|
90941
|
-
const indexContent =
|
|
91307
|
+
const wrapperContent = readFileSync73(wrapperPath, "utf-8");
|
|
91308
|
+
const indexContent = readFileSync73(indexPath, "utf-8");
|
|
90942
91309
|
const index2 = JSON.parse(indexContent);
|
|
90943
91310
|
const match = wrapperContent.match(/_get_all_commands\(\)\s*\{[^}]*echo\s+"([^"]+)"/);
|
|
90944
91311
|
const wrapperCmds = new Set(match ? match[1].split(/\s+/).filter(Boolean) : []);
|
|
@@ -90971,16 +91338,16 @@ var CRITICAL_COMMANDS = [
|
|
|
90971
91338
|
];
|
|
90972
91339
|
function detectDrift(mode = "full", projectRoot = ".") {
|
|
90973
91340
|
const issues = [];
|
|
90974
|
-
const scriptsDir =
|
|
90975
|
-
const indexPath =
|
|
91341
|
+
const scriptsDir = join104(projectRoot, "scripts");
|
|
91342
|
+
const indexPath = join104(projectRoot, "docs/commands/COMMANDS-INDEX.json");
|
|
90976
91343
|
issues.push(...checkCommandsSync(scriptsDir, indexPath));
|
|
90977
|
-
const wrapperPath =
|
|
91344
|
+
const wrapperPath = join104(projectRoot, "installer/lib/link.sh");
|
|
90978
91345
|
issues.push(...checkWrapperSync(wrapperPath, indexPath));
|
|
90979
91346
|
if (mode === "full") {
|
|
90980
|
-
const readmePath =
|
|
90981
|
-
if (
|
|
91347
|
+
const readmePath = join104(projectRoot, "README.md");
|
|
91348
|
+
if (existsSync103(readmePath)) {
|
|
90982
91349
|
try {
|
|
90983
|
-
const readme =
|
|
91350
|
+
const readme = readFileSync73(readmePath, "utf-8");
|
|
90984
91351
|
const readmeCmds = new Set(
|
|
90985
91352
|
(readme.match(/cleo [a-z-]+/g) ?? []).map((m2) => m2.replace("cleo ", ""))
|
|
90986
91353
|
);
|
|
@@ -91014,14 +91381,14 @@ function shouldRunDriftDetection(enabled = true, autoCheck = false, command, cri
|
|
|
91014
91381
|
// packages/core/src/validation/doctor/project-cache.ts
|
|
91015
91382
|
init_paths();
|
|
91016
91383
|
import { createHash as createHash13 } from "node:crypto";
|
|
91017
|
-
import { existsSync as
|
|
91018
|
-
import { dirname as
|
|
91384
|
+
import { existsSync as existsSync104, mkdirSync as mkdirSync26, readFileSync as readFileSync74, unlinkSync as unlinkSync8, writeFileSync as writeFileSync19 } from "node:fs";
|
|
91385
|
+
import { dirname as dirname21, join as join105 } from "node:path";
|
|
91019
91386
|
var CACHE_VERSION = "1.0.0";
|
|
91020
91387
|
var CACHE_TTL_SECONDS = 300;
|
|
91021
91388
|
var CACHE_FILE2 = "doctor-project-cache.json";
|
|
91022
91389
|
function getCacheFilePath(cleoHome) {
|
|
91023
91390
|
const home = cleoHome ?? getCleoHome();
|
|
91024
|
-
return
|
|
91391
|
+
return join105(home, CACHE_FILE2);
|
|
91025
91392
|
}
|
|
91026
91393
|
function initCacheFile(cacheFile) {
|
|
91027
91394
|
const cache = {
|
|
@@ -91029,26 +91396,26 @@ function initCacheFile(cacheFile) {
|
|
|
91029
91396
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
|
|
91030
91397
|
projects: {}
|
|
91031
91398
|
};
|
|
91032
|
-
const dir =
|
|
91033
|
-
if (!
|
|
91034
|
-
|
|
91399
|
+
const dir = dirname21(cacheFile);
|
|
91400
|
+
if (!existsSync104(dir)) {
|
|
91401
|
+
mkdirSync26(dir, { recursive: true });
|
|
91035
91402
|
}
|
|
91036
|
-
|
|
91403
|
+
writeFileSync19(cacheFile, JSON.stringify(cache, null, 2));
|
|
91037
91404
|
return cache;
|
|
91038
91405
|
}
|
|
91039
91406
|
function loadCache(cacheFile) {
|
|
91040
|
-
if (!
|
|
91407
|
+
if (!existsSync104(cacheFile)) return null;
|
|
91041
91408
|
try {
|
|
91042
|
-
const content =
|
|
91409
|
+
const content = readFileSync74(cacheFile, "utf-8");
|
|
91043
91410
|
return JSON.parse(content);
|
|
91044
91411
|
} catch {
|
|
91045
91412
|
return null;
|
|
91046
91413
|
}
|
|
91047
91414
|
}
|
|
91048
91415
|
function getFileHash(filePath) {
|
|
91049
|
-
if (!
|
|
91416
|
+
if (!existsSync104(filePath)) return "";
|
|
91050
91417
|
try {
|
|
91051
|
-
const content =
|
|
91418
|
+
const content = readFileSync74(filePath);
|
|
91052
91419
|
return createHash13("sha256").update(content).digest("hex");
|
|
91053
91420
|
} catch {
|
|
91054
91421
|
return "";
|
|
@@ -91065,8 +91432,8 @@ function getCachedValidation(projectHash, projectPath, cacheFile) {
|
|
|
91065
91432
|
const now2 = Date.now();
|
|
91066
91433
|
const age = (now2 - lastValidated) / 1e3;
|
|
91067
91434
|
if (age > (entry.ttl || CACHE_TTL_SECONDS)) return null;
|
|
91068
|
-
const currentTasksDbHash = getFileHash(
|
|
91069
|
-
const currentConfigHash = getFileHash(
|
|
91435
|
+
const currentTasksDbHash = getFileHash(join105(projectPath, ".cleo", "tasks.db"));
|
|
91436
|
+
const currentConfigHash = getFileHash(join105(projectPath, ".cleo", "config.json"));
|
|
91070
91437
|
if (currentTasksDbHash !== (entry.fileHashes["tasks.db"] ?? "")) return null;
|
|
91071
91438
|
if (currentConfigHash !== (entry.fileHashes["config.json"] ?? "")) return null;
|
|
91072
91439
|
return entry;
|
|
@@ -91077,8 +91444,8 @@ function cacheValidationResult(projectHash, projectPath, validationStatus, issue
|
|
|
91077
91444
|
if (!cache) {
|
|
91078
91445
|
cache = initCacheFile(cachePath);
|
|
91079
91446
|
}
|
|
91080
|
-
const tasksDbHash = getFileHash(
|
|
91081
|
-
const configHash = getFileHash(
|
|
91447
|
+
const tasksDbHash = getFileHash(join105(projectPath, ".cleo", "tasks.db"));
|
|
91448
|
+
const configHash = getFileHash(join105(projectPath, ".cleo", "config.json"));
|
|
91082
91449
|
const timestamp2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
91083
91450
|
cache.projects[projectHash] = {
|
|
91084
91451
|
path: projectPath,
|
|
@@ -91093,18 +91460,18 @@ function cacheValidationResult(projectHash, projectPath, validationStatus, issue
|
|
|
91093
91460
|
ttl: CACHE_TTL_SECONDS
|
|
91094
91461
|
};
|
|
91095
91462
|
cache.lastUpdated = timestamp2;
|
|
91096
|
-
|
|
91463
|
+
writeFileSync19(cachePath, JSON.stringify(cache, null, 2));
|
|
91097
91464
|
}
|
|
91098
91465
|
function clearProjectCache(projectHash, cacheFile) {
|
|
91099
91466
|
const cachePath = cacheFile ?? getCacheFilePath();
|
|
91100
91467
|
const cache = loadCache(cachePath);
|
|
91101
91468
|
if (!cache) return;
|
|
91102
91469
|
delete cache.projects[projectHash];
|
|
91103
|
-
|
|
91470
|
+
writeFileSync19(cachePath, JSON.stringify(cache, null, 2));
|
|
91104
91471
|
}
|
|
91105
91472
|
function clearEntireCache(cacheFile) {
|
|
91106
91473
|
const cachePath = cacheFile ?? getCacheFilePath();
|
|
91107
|
-
if (
|
|
91474
|
+
if (existsSync104(cachePath)) {
|
|
91108
91475
|
unlinkSync8(cachePath);
|
|
91109
91476
|
}
|
|
91110
91477
|
initCacheFile(cachePath);
|
|
@@ -91373,15 +91740,15 @@ function validateTitle2(title) {
|
|
|
91373
91740
|
}
|
|
91374
91741
|
return { valid: errors.length === 0, errors, warnings };
|
|
91375
91742
|
}
|
|
91376
|
-
function validateDescription(
|
|
91377
|
-
if (!
|
|
91378
|
-
if (
|
|
91743
|
+
function validateDescription(desc8) {
|
|
91744
|
+
if (!desc8) return { valid: true, errors: [], warnings: [] };
|
|
91745
|
+
if (desc8.length > FIELD_LIMITS.MAX_DESCRIPTION_LENGTH) {
|
|
91379
91746
|
return {
|
|
91380
91747
|
valid: false,
|
|
91381
91748
|
errors: [
|
|
91382
91749
|
{
|
|
91383
91750
|
field: "description",
|
|
91384
|
-
message: `Description exceeds ${FIELD_LIMITS.MAX_DESCRIPTION_LENGTH} characters (${
|
|
91751
|
+
message: `Description exceeds ${FIELD_LIMITS.MAX_DESCRIPTION_LENGTH} characters (${desc8.length} provided)`,
|
|
91385
91752
|
severity: "error"
|
|
91386
91753
|
}
|
|
91387
91754
|
],
|
|
@@ -92090,9 +92457,9 @@ function formatGapReport(report) {
|
|
|
92090
92457
|
|
|
92091
92458
|
// packages/core/src/validation/manifest.ts
|
|
92092
92459
|
init_paths();
|
|
92093
|
-
import { existsSync as
|
|
92460
|
+
import { existsSync as existsSync105 } from "node:fs";
|
|
92094
92461
|
import { appendFile as appendFile3, mkdir as mkdir15, readFile as readFile18 } from "node:fs/promises";
|
|
92095
|
-
import { dirname as
|
|
92462
|
+
import { dirname as dirname22 } from "node:path";
|
|
92096
92463
|
var DEFAULT_MANIFEST_PATH = ".cleo/agent-outputs/MANIFEST.jsonl";
|
|
92097
92464
|
var DEFAULT_COMPLIANCE_PATH = ".cleo/metrics/COMPLIANCE.jsonl";
|
|
92098
92465
|
async function findManifestEntry(taskId, manifestPath) {
|
|
@@ -92103,7 +92470,7 @@ async function findManifestEntry(taskId, manifestPath) {
|
|
|
92103
92470
|
manifestPath = DEFAULT_MANIFEST_PATH;
|
|
92104
92471
|
}
|
|
92105
92472
|
}
|
|
92106
|
-
if (!
|
|
92473
|
+
if (!existsSync105(manifestPath)) return null;
|
|
92107
92474
|
const content = await readFile18(manifestPath, "utf-8");
|
|
92108
92475
|
const lines = content.split("\n").filter((l) => l.trim());
|
|
92109
92476
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -92215,7 +92582,7 @@ async function validateManifestEntry(taskId, manifestEntry, manifestPath = DEFAU
|
|
|
92215
92582
|
};
|
|
92216
92583
|
}
|
|
92217
92584
|
async function logRealCompliance(taskId, validationResult, agentType = "unknown", compliancePath = DEFAULT_COMPLIANCE_PATH) {
|
|
92218
|
-
const metricsDir =
|
|
92585
|
+
const metricsDir = dirname22(compliancePath);
|
|
92219
92586
|
await mkdir15(metricsDir, { recursive: true });
|
|
92220
92587
|
const { score, pass, violations } = validationResult;
|
|
92221
92588
|
const violationCount = violations.length;
|
|
@@ -92275,9 +92642,9 @@ async function validateAndLog(taskId, manifestPath = DEFAULT_MANIFEST_PATH, comp
|
|
|
92275
92642
|
|
|
92276
92643
|
// packages/core/src/validation/protocol-common.ts
|
|
92277
92644
|
init_src();
|
|
92278
|
-
import { existsSync as
|
|
92645
|
+
import { existsSync as existsSync106, readdirSync as readdirSync33, readFileSync as readFileSync75 } from "node:fs";
|
|
92279
92646
|
function checkOutputFileExists(taskId, expectedDir, pattern) {
|
|
92280
|
-
if (!
|
|
92647
|
+
if (!existsSync106(expectedDir)) return false;
|
|
92281
92648
|
const filePattern = pattern ?? `${taskId}`;
|
|
92282
92649
|
try {
|
|
92283
92650
|
const files = readdirSync33(expectedDir);
|
|
@@ -92287,9 +92654,9 @@ function checkOutputFileExists(taskId, expectedDir, pattern) {
|
|
|
92287
92654
|
}
|
|
92288
92655
|
}
|
|
92289
92656
|
function checkDocumentationSections(filePath, sections) {
|
|
92290
|
-
if (!
|
|
92657
|
+
if (!existsSync106(filePath)) return false;
|
|
92291
92658
|
try {
|
|
92292
|
-
const content =
|
|
92659
|
+
const content = readFileSync75(filePath, "utf-8");
|
|
92293
92660
|
return sections.every((section) => {
|
|
92294
92661
|
const regex = new RegExp(`^#+ .*${escapeRegex3(section)}`, "m");
|
|
92295
92662
|
return regex.test(content);
|
|
@@ -92382,9 +92749,9 @@ function checkLinkedTasksPresent(entry, requiredIds) {
|
|
|
92382
92749
|
return requiredIds.every((id) => linkedTasks.includes(id));
|
|
92383
92750
|
}
|
|
92384
92751
|
function checkProvenanceTags(filePath, taskId) {
|
|
92385
|
-
if (!
|
|
92752
|
+
if (!existsSync106(filePath)) return false;
|
|
92386
92753
|
try {
|
|
92387
|
-
const content =
|
|
92754
|
+
const content = readFileSync75(filePath, "utf-8");
|
|
92388
92755
|
if (taskId) {
|
|
92389
92756
|
return content.includes(`@task ${taskId}`);
|
|
92390
92757
|
}
|
|
@@ -93044,17 +93411,17 @@ init_logger();
|
|
|
93044
93411
|
|
|
93045
93412
|
// packages/core/src/output.ts
|
|
93046
93413
|
init_errors3();
|
|
93047
|
-
import { randomUUID as
|
|
93414
|
+
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
93048
93415
|
|
|
93049
93416
|
// packages/core/src/sessions/context-alert.ts
|
|
93050
93417
|
init_paths();
|
|
93051
|
-
import { existsSync as
|
|
93052
|
-
import { join as
|
|
93418
|
+
import { existsSync as existsSync109, readFileSync as readFileSync77, writeFileSync as writeFileSync20 } from "node:fs";
|
|
93419
|
+
import { join as join108 } from "node:path";
|
|
93053
93420
|
function getCurrentSessionId(cwd) {
|
|
93054
93421
|
if (process.env.CLEO_SESSION) return process.env.CLEO_SESSION;
|
|
93055
|
-
const sessionFile =
|
|
93056
|
-
if (
|
|
93057
|
-
return
|
|
93422
|
+
const sessionFile = join108(getCleoDir(cwd), ".current-session");
|
|
93423
|
+
if (existsSync109(sessionFile)) {
|
|
93424
|
+
return readFileSync77(sessionFile, "utf-8").trim() || null;
|
|
93058
93425
|
}
|
|
93059
93426
|
return null;
|
|
93060
93427
|
}
|
|
@@ -93074,7 +93441,7 @@ function createCliMeta(operation, duration_ms = 0) {
|
|
|
93074
93441
|
const warnings = drainWarnings();
|
|
93075
93442
|
const meta3 = {
|
|
93076
93443
|
operation,
|
|
93077
|
-
requestId:
|
|
93444
|
+
requestId: randomUUID8(),
|
|
93078
93445
|
duration_ms,
|
|
93079
93446
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
93080
93447
|
};
|
|
@@ -93139,10 +93506,10 @@ init_adapters();
|
|
|
93139
93506
|
// packages/core/src/bootstrap.ts
|
|
93140
93507
|
init_paths();
|
|
93141
93508
|
init_scaffold();
|
|
93142
|
-
import { existsSync as
|
|
93509
|
+
import { existsSync as existsSync110, readFileSync as readFileSync78 } from "node:fs";
|
|
93143
93510
|
import { mkdir as mkdir17, readFile as readFile20, writeFile as writeFile12 } from "node:fs/promises";
|
|
93144
93511
|
import { homedir as homedir7 } from "node:os";
|
|
93145
|
-
import { join as
|
|
93512
|
+
import { join as join109 } from "node:path";
|
|
93146
93513
|
async function bootstrapGlobalCleo(options) {
|
|
93147
93514
|
const ctx = {
|
|
93148
93515
|
created: [],
|
|
@@ -93163,8 +93530,8 @@ async function bootstrapGlobalCleo(options) {
|
|
|
93163
93530
|
}
|
|
93164
93531
|
async function writeTemplateTo(content, destPath, isDryRun) {
|
|
93165
93532
|
if (isDryRun) return false;
|
|
93166
|
-
const { dirname:
|
|
93167
|
-
await mkdir17(
|
|
93533
|
+
const { dirname: dirname27 } = await import("node:path");
|
|
93534
|
+
await mkdir17(dirname27(destPath), { recursive: true });
|
|
93168
93535
|
await writeFile12(destPath, content);
|
|
93169
93536
|
return true;
|
|
93170
93537
|
}
|
|
@@ -93176,9 +93543,9 @@ async function ensureGlobalTemplatesBootstrap(ctx, packageRootOverride) {
|
|
|
93176
93543
|
let templateContent = null;
|
|
93177
93544
|
try {
|
|
93178
93545
|
const pkgRoot = packageRootOverride ?? getPackageRoot();
|
|
93179
|
-
const templatePath =
|
|
93180
|
-
if (
|
|
93181
|
-
templateContent =
|
|
93546
|
+
const templatePath = join109(pkgRoot, "templates", "CLEO-INJECTION.md");
|
|
93547
|
+
if (existsSync110(templatePath)) {
|
|
93548
|
+
templateContent = readFileSync78(templatePath, "utf-8");
|
|
93182
93549
|
}
|
|
93183
93550
|
} catch {
|
|
93184
93551
|
}
|
|
@@ -93195,15 +93562,15 @@ async function ensureGlobalTemplatesBootstrap(ctx, packageRootOverride) {
|
|
|
93195
93562
|
ctx.warnings.push("Could not refresh CLEO-INJECTION.md template");
|
|
93196
93563
|
return;
|
|
93197
93564
|
}
|
|
93198
|
-
const xdgDest =
|
|
93565
|
+
const xdgDest = join109(globalTemplatesDir, "CLEO-INJECTION.md");
|
|
93199
93566
|
const xdgWritten = await writeTemplateTo(templateContent, xdgDest, ctx.isDryRun);
|
|
93200
93567
|
ctx.created.push(
|
|
93201
93568
|
`${getCleoTemplatesTildePath()}/CLEO-INJECTION.md (${xdgWritten ? "refreshed" : "would refresh"})`
|
|
93202
93569
|
);
|
|
93203
93570
|
const home = homedir7();
|
|
93204
|
-
const legacyTemplatesDir =
|
|
93205
|
-
if (legacyTemplatesDir !== globalTemplatesDir &&
|
|
93206
|
-
const legacyDest =
|
|
93571
|
+
const legacyTemplatesDir = join109(home, ".cleo", "templates");
|
|
93572
|
+
if (legacyTemplatesDir !== globalTemplatesDir && existsSync110(join109(home, ".cleo"))) {
|
|
93573
|
+
const legacyDest = join109(legacyTemplatesDir, "CLEO-INJECTION.md");
|
|
93207
93574
|
const legacyWritten = await writeTemplateTo(templateContent, legacyDest, ctx.isDryRun);
|
|
93208
93575
|
if (legacyWritten) {
|
|
93209
93576
|
ctx.created.push("~/.cleo/templates/CLEO-INJECTION.md (legacy sync)");
|
|
@@ -93222,12 +93589,12 @@ function sanitizeCaampFile(content) {
|
|
|
93222
93589
|
}
|
|
93223
93590
|
async function injectAgentsHub(ctx) {
|
|
93224
93591
|
const globalAgentsDir = getAgentsHome();
|
|
93225
|
-
const globalAgentsMd =
|
|
93592
|
+
const globalAgentsMd = join109(globalAgentsDir, "AGENTS.md");
|
|
93226
93593
|
try {
|
|
93227
93594
|
const { inject: inject2, getInstalledProviders: getInstalledProviders3, injectAll: injectAll2, buildInjectionContent } = await import("@cleocode/caamp");
|
|
93228
93595
|
if (!ctx.isDryRun) {
|
|
93229
93596
|
await mkdir17(globalAgentsDir, { recursive: true });
|
|
93230
|
-
if (
|
|
93597
|
+
if (existsSync110(globalAgentsMd)) {
|
|
93231
93598
|
const content = await readFile20(globalAgentsMd, "utf8");
|
|
93232
93599
|
const stripped = content.replace(
|
|
93233
93600
|
/\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
|
|
@@ -93262,8 +93629,8 @@ async function injectAgentsHub(ctx) {
|
|
|
93262
93629
|
});
|
|
93263
93630
|
if (!ctx.isDryRun) {
|
|
93264
93631
|
for (const provider of providers) {
|
|
93265
|
-
const instructFilePath =
|
|
93266
|
-
if (
|
|
93632
|
+
const instructFilePath = join109(provider.pathGlobal, provider.instructFile);
|
|
93633
|
+
if (existsSync110(instructFilePath)) {
|
|
93267
93634
|
const fileContent = await readFile20(instructFilePath, "utf8");
|
|
93268
93635
|
const stripped = fileContent.replace(
|
|
93269
93636
|
/\n?<!-- CLEO:START[^>]*-->[\s\S]*?<!-- CLEO:END -->\n?/g,
|
|
@@ -93281,7 +93648,7 @@ async function injectAgentsHub(ctx) {
|
|
|
93281
93648
|
}
|
|
93282
93649
|
} else {
|
|
93283
93650
|
for (const p2 of providers) {
|
|
93284
|
-
const displayPath =
|
|
93651
|
+
const displayPath = join109(p2.pathGlobal, p2.instructFile).replace(homedir7(), "~");
|
|
93285
93652
|
ctx.created.push(`${displayPath} (would update CAAMP block)`);
|
|
93286
93653
|
}
|
|
93287
93654
|
}
|
|
@@ -93403,17 +93770,17 @@ async function verifyBootstrapComplete() {
|
|
|
93403
93770
|
async function verifyBootstrapHealth(ctx) {
|
|
93404
93771
|
if (ctx.isDryRun) return;
|
|
93405
93772
|
try {
|
|
93406
|
-
const xdgTemplatePath =
|
|
93407
|
-
const agentsMd =
|
|
93408
|
-
if (!
|
|
93773
|
+
const xdgTemplatePath = join109(getCleoTemplatesDir(), "CLEO-INJECTION.md");
|
|
93774
|
+
const agentsMd = join109(getAgentsHome(), "AGENTS.md");
|
|
93775
|
+
if (!existsSync110(xdgTemplatePath)) {
|
|
93409
93776
|
ctx.warnings.push("Health: XDG template missing after bootstrap");
|
|
93410
93777
|
return;
|
|
93411
93778
|
}
|
|
93412
93779
|
const xdgContent = await readFile20(xdgTemplatePath, "utf8");
|
|
93413
93780
|
const xdgVersion = xdgContent.match(/^Version:\s*(.+)$/m)?.[1]?.trim();
|
|
93414
93781
|
const home = homedir7();
|
|
93415
|
-
const legacyTemplatePath =
|
|
93416
|
-
if (
|
|
93782
|
+
const legacyTemplatePath = join109(home, ".cleo", "templates", "CLEO-INJECTION.md");
|
|
93783
|
+
if (existsSync110(legacyTemplatePath)) {
|
|
93417
93784
|
const legacyContent = await readFile20(legacyTemplatePath, "utf8");
|
|
93418
93785
|
const legacyVersion = legacyContent.match(/^Version:\s*(.+)$/m)?.[1]?.trim();
|
|
93419
93786
|
if (legacyVersion !== xdgVersion) {
|
|
@@ -93422,7 +93789,7 @@ async function verifyBootstrapHealth(ctx) {
|
|
|
93422
93789
|
);
|
|
93423
93790
|
}
|
|
93424
93791
|
}
|
|
93425
|
-
if (
|
|
93792
|
+
if (existsSync110(agentsMd)) {
|
|
93426
93793
|
const agentsContent = await readFile20(agentsMd, "utf8");
|
|
93427
93794
|
const expectedRef = `@${getCleoTemplatesTildePath()}/CLEO-INJECTION.md`;
|
|
93428
93795
|
if (!agentsContent.includes(expectedRef)) {
|
|
@@ -93506,13 +93873,13 @@ async function serializeSession(projectRoot, options = {}, accessor) {
|
|
|
93506
93873
|
const { tasks: tasks2 } = await acc.queryTasks({});
|
|
93507
93874
|
const task = tasks2.find((t) => t.id === session.taskWork?.taskId);
|
|
93508
93875
|
if (task) {
|
|
93509
|
-
const
|
|
93876
|
+
const desc8 = task.description ?? "";
|
|
93510
93877
|
activeTask = {
|
|
93511
93878
|
taskId: task.id,
|
|
93512
93879
|
title: task.title,
|
|
93513
93880
|
status: task.status,
|
|
93514
93881
|
priority: task.priority ?? "medium",
|
|
93515
|
-
description:
|
|
93882
|
+
description: desc8.length > maxDescLen ? desc8.slice(0, maxDescLen) + "..." : desc8,
|
|
93516
93883
|
acceptance: Array.isArray(task.acceptance) ? task.acceptance.join("\n") : task.acceptance ?? void 0
|
|
93517
93884
|
};
|
|
93518
93885
|
}
|
|
@@ -94386,10 +94753,10 @@ var DECOMPOSITION_RULES = [
|
|
|
94386
94753
|
message: "Must include acceptance criteria in task description",
|
|
94387
94754
|
fix: "Add clear acceptance criteria: what must be true when the task is done",
|
|
94388
94755
|
validate: (entry) => {
|
|
94389
|
-
const
|
|
94390
|
-
if (!
|
|
94756
|
+
const desc8 = entry.description;
|
|
94757
|
+
if (!desc8) return false;
|
|
94391
94758
|
return /\b(must|should|acceptance|criteria|verify|test|passes when|done when|complete when)\b/i.test(
|
|
94392
|
-
|
|
94759
|
+
desc8
|
|
94393
94760
|
);
|
|
94394
94761
|
}
|
|
94395
94762
|
},
|
|
@@ -95078,7 +95445,7 @@ init_prediction();
|
|
|
95078
95445
|
|
|
95079
95446
|
// packages/core/src/lifecycle/chain-store.ts
|
|
95080
95447
|
init_chain_schema();
|
|
95081
|
-
import { randomUUID as
|
|
95448
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
95082
95449
|
|
|
95083
95450
|
// packages/core/src/validation/chain-validation.ts
|
|
95084
95451
|
function validateChainShape(shape) {
|
|
@@ -95227,7 +95594,7 @@ async function createInstance(params, projectRoot) {
|
|
|
95227
95594
|
if (!chain) {
|
|
95228
95595
|
throw new Error(`Chain "${params.chainId}" not found`);
|
|
95229
95596
|
}
|
|
95230
|
-
const id = `wci-${
|
|
95597
|
+
const id = `wci-${randomUUID9().slice(0, 8)}`;
|
|
95231
95598
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
95232
95599
|
const variables = params.variables ?? {};
|
|
95233
95600
|
const stageToTask = params.stageToTask ?? {};
|
|
@@ -96662,7 +97029,7 @@ async function runBrainMaintenance(projectRoot, options) {
|
|
|
96662
97029
|
init_brain_schema();
|
|
96663
97030
|
init_brain_sqlite();
|
|
96664
97031
|
init_brain_search();
|
|
96665
|
-
import { inArray as inArray6, ne as ne3, sql as
|
|
97032
|
+
import { inArray as inArray6, ne as ne3, sql as sql14 } from "drizzle-orm";
|
|
96666
97033
|
function countRowsNative(tableName) {
|
|
96667
97034
|
const nativeDb = getBrainNativeDb();
|
|
96668
97035
|
if (!nativeDb) return 0;
|
|
@@ -96684,7 +97051,7 @@ async function purgeBrainNoise(projectRoot) {
|
|
|
96684
97051
|
console.log(` Learnings: ${beforeLearnings}`);
|
|
96685
97052
|
console.log(` Decisions: ${beforeDecisions}`);
|
|
96686
97053
|
console.log(` Observations: ${beforeObservations}`);
|
|
96687
|
-
const realDecision = await db.select().from(brainDecisions).where(
|
|
97054
|
+
const realDecision = await db.select().from(brainDecisions).where(sql14`id = 'D-mntpeeer'`);
|
|
96688
97055
|
if (realDecision.length === 0) {
|
|
96689
97056
|
throw new Error(
|
|
96690
97057
|
"SAFETY ABORT: D-mntpeeer not found in brain_decisions. Backup and restore required."
|
|
@@ -96828,10 +97195,10 @@ init_brain_retrieval();
|
|
|
96828
97195
|
init_paths();
|
|
96829
97196
|
init_brain_sqlite();
|
|
96830
97197
|
init_brain_search();
|
|
96831
|
-
import { existsSync as
|
|
97198
|
+
import { existsSync as existsSync111 } from "node:fs";
|
|
96832
97199
|
import { createRequire as createRequire10 } from "node:module";
|
|
96833
|
-
function typedAll3(db,
|
|
96834
|
-
return db.prepare(
|
|
97200
|
+
function typedAll3(db, sql16) {
|
|
97201
|
+
return db.prepare(sql16).all();
|
|
96835
97202
|
}
|
|
96836
97203
|
var _require10 = createRequire10(import.meta.url);
|
|
96837
97204
|
var { DatabaseSync: DatabaseSync5 } = _require10("node:sqlite");
|
|
@@ -96875,7 +97242,7 @@ async function migrateClaudeMem(projectRoot, options = {}) {
|
|
|
96875
97242
|
errors: [],
|
|
96876
97243
|
dryRun
|
|
96877
97244
|
};
|
|
96878
|
-
if (!
|
|
97245
|
+
if (!existsSync111(sourcePath)) {
|
|
96879
97246
|
throw new Error(
|
|
96880
97247
|
`claude-mem database not found at: ${sourcePath}
|
|
96881
97248
|
Expected location: ~/.claude-mem/claude-mem.db
|
|
@@ -97090,19 +97457,19 @@ var _timer;
|
|
|
97090
97457
|
async function drainQueue() {
|
|
97091
97458
|
if (_queue.length === 0) return 0;
|
|
97092
97459
|
const batch = _queue.splice(0, _queue.length);
|
|
97093
|
-
let
|
|
97460
|
+
let count5 = 0;
|
|
97094
97461
|
const { observeBrain: observeBrain2 } = await Promise.resolve().then(() => (init_brain_retrieval(), brain_retrieval_exports));
|
|
97095
97462
|
for (const entry of batch) {
|
|
97096
97463
|
try {
|
|
97097
97464
|
const result = await observeBrain2(entry.projectRoot, entry.params);
|
|
97098
97465
|
entry.resolve(result);
|
|
97099
|
-
|
|
97466
|
+
count5++;
|
|
97100
97467
|
} catch (err) {
|
|
97101
97468
|
const error48 = err instanceof Error ? err : new Error(String(err));
|
|
97102
97469
|
entry.reject(error48);
|
|
97103
97470
|
}
|
|
97104
97471
|
}
|
|
97105
|
-
return
|
|
97472
|
+
return count5;
|
|
97106
97473
|
}
|
|
97107
97474
|
function exitFlush() {
|
|
97108
97475
|
if (_queue.length === 0) return;
|
|
@@ -97145,8 +97512,8 @@ var mentalModelQueue = {
|
|
|
97145
97512
|
enqueue(projectRoot, params) {
|
|
97146
97513
|
registerExitHooks();
|
|
97147
97514
|
ensureTimer();
|
|
97148
|
-
return new Promise((
|
|
97149
|
-
_queue.push({ projectRoot, params, resolve:
|
|
97515
|
+
return new Promise((resolve15, reject) => {
|
|
97516
|
+
_queue.push({ projectRoot, params, resolve: resolve15, reject });
|
|
97150
97517
|
if (_queue.length >= FLUSH_WATERMARK && !_flushing) {
|
|
97151
97518
|
_flushing = true;
|
|
97152
97519
|
drainQueue().catch(() => {
|
|
@@ -98151,9 +98518,9 @@ init_tasks_schema();
|
|
|
98151
98518
|
init_pagination();
|
|
98152
98519
|
init_paths();
|
|
98153
98520
|
import { createHash as createHash15 } from "node:crypto";
|
|
98154
|
-
import { existsSync as
|
|
98155
|
-
import { join as
|
|
98156
|
-
import { and as
|
|
98521
|
+
import { existsSync as existsSync112, readFileSync as readFileSync79, renameSync as renameSync8 } from "node:fs";
|
|
98522
|
+
import { join as join110 } from "node:path";
|
|
98523
|
+
import { and as and11, count as count3, desc as desc6, eq as eq13, gte as gte3, isNull as isNull3, like as like3, lte as lte2, or as or5 } from "drizzle-orm";
|
|
98157
98524
|
async function getDb3(cwd) {
|
|
98158
98525
|
const { getDb: _getDb } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
98159
98526
|
return _getDb(cwd);
|
|
@@ -98282,9 +98649,9 @@ async function pipelineManifestShow(researchId, projectRoot) {
|
|
|
98282
98649
|
const root = getProjectRoot(projectRoot);
|
|
98283
98650
|
let fileContent = null;
|
|
98284
98651
|
try {
|
|
98285
|
-
const filePath =
|
|
98286
|
-
if (
|
|
98287
|
-
fileContent =
|
|
98652
|
+
const filePath = join110(root, entry.file);
|
|
98653
|
+
if (existsSync112(filePath)) {
|
|
98654
|
+
fileContent = readFileSync79(filePath, "utf-8");
|
|
98288
98655
|
}
|
|
98289
98656
|
} catch {
|
|
98290
98657
|
}
|
|
@@ -98313,13 +98680,13 @@ async function pipelineManifestList(params, projectRoot) {
|
|
|
98313
98680
|
const offset = normalizeOffset2(params.offset);
|
|
98314
98681
|
const pageLimit = effectivePageLimit2(limit, offset);
|
|
98315
98682
|
const { conditions, requiresInMemoryFiltering } = buildManifestSqlFilters(filter);
|
|
98316
|
-
const whereClause =
|
|
98317
|
-
const totalRow = await db.select({ count:
|
|
98683
|
+
const whereClause = and11(...conditions);
|
|
98684
|
+
const totalRow = await db.select({ count: count3() }).from(pipelineManifest).where(isNull3(pipelineManifest.archivedAt)).get();
|
|
98318
98685
|
const total = totalRow?.count ?? 0;
|
|
98319
98686
|
if (!requiresInMemoryFiltering) {
|
|
98320
|
-
const filteredRow = await db.select({ count:
|
|
98687
|
+
const filteredRow = await db.select({ count: count3() }).from(pipelineManifest).where(whereClause).get();
|
|
98321
98688
|
const filtered2 = filteredRow?.count ?? 0;
|
|
98322
|
-
let query = db.select().from(pipelineManifest).where(whereClause).orderBy(
|
|
98689
|
+
let query = db.select().from(pipelineManifest).where(whereClause).orderBy(desc6(pipelineManifest.createdAt));
|
|
98323
98690
|
if (pageLimit !== void 0) {
|
|
98324
98691
|
query = query.limit(pageLimit);
|
|
98325
98692
|
}
|
|
@@ -98333,7 +98700,7 @@ async function pipelineManifestList(params, projectRoot) {
|
|
|
98333
98700
|
page: createPage({ total: filtered2, limit: pageLimit, offset })
|
|
98334
98701
|
};
|
|
98335
98702
|
}
|
|
98336
|
-
const rows = await db.select().from(pipelineManifest).where(whereClause).orderBy(
|
|
98703
|
+
const rows = await db.select().from(pipelineManifest).where(whereClause).orderBy(desc6(pipelineManifest.createdAt));
|
|
98337
98704
|
const filteredEntries = applyManifestMemoryOnlyFilters(rows.map(rowToEntry), filter);
|
|
98338
98705
|
const filtered = filteredEntries.length;
|
|
98339
98706
|
const start = offset ?? 0;
|
|
@@ -98361,11 +98728,11 @@ async function pipelineManifestFind(query, options, projectRoot) {
|
|
|
98361
98728
|
const db = await getDb3(projectRoot);
|
|
98362
98729
|
const likePattern = `%${query}%`;
|
|
98363
98730
|
const rows = await db.select().from(pipelineManifest).where(
|
|
98364
|
-
|
|
98731
|
+
and11(
|
|
98365
98732
|
isNull3(pipelineManifest.archivedAt),
|
|
98366
98733
|
or5(like3(pipelineManifest.content, likePattern), like3(pipelineManifest.type, likePattern))
|
|
98367
98734
|
)
|
|
98368
|
-
).orderBy(
|
|
98735
|
+
).orderBy(desc6(pipelineManifest.createdAt));
|
|
98369
98736
|
const queryLower = query.toLowerCase();
|
|
98370
98737
|
const entries = rows.map(rowToEntry);
|
|
98371
98738
|
const scored = entries.map((entry) => {
|
|
@@ -98405,7 +98772,7 @@ async function pipelineManifestFind(query, options, projectRoot) {
|
|
|
98405
98772
|
async function pipelineManifestPending(epicId, projectRoot) {
|
|
98406
98773
|
try {
|
|
98407
98774
|
const db = await getDb3(projectRoot);
|
|
98408
|
-
const rows = await db.select().from(pipelineManifest).where(isNull3(pipelineManifest.archivedAt)).orderBy(
|
|
98775
|
+
const rows = await db.select().from(pipelineManifest).where(isNull3(pipelineManifest.archivedAt)).orderBy(desc6(pipelineManifest.createdAt));
|
|
98409
98776
|
const entries = rows.map(rowToEntry);
|
|
98410
98777
|
let pending = entries.filter(
|
|
98411
98778
|
(e) => e.status === "partial" || e.status === "blocked" || e.needs_followup && e.needs_followup.length > 0
|
|
@@ -98571,7 +98938,7 @@ async function pipelineManifestArchive(beforeDate, projectRoot) {
|
|
|
98571
98938
|
async function readManifestEntries2(projectRoot) {
|
|
98572
98939
|
try {
|
|
98573
98940
|
const db = await getDb3(projectRoot);
|
|
98574
|
-
const rows = await db.select().from(pipelineManifest).where(isNull3(pipelineManifest.archivedAt)).orderBy(
|
|
98941
|
+
const rows = await db.select().from(pipelineManifest).where(isNull3(pipelineManifest.archivedAt)).orderBy(desc6(pipelineManifest.createdAt));
|
|
98575
98942
|
return rows.map(rowToEntry);
|
|
98576
98943
|
} catch {
|
|
98577
98944
|
return [];
|
|
@@ -98584,9 +98951,9 @@ init_quality_feedback();
|
|
|
98584
98951
|
// packages/core/src/metrics/token-service.ts
|
|
98585
98952
|
init_paths();
|
|
98586
98953
|
init_tasks_schema();
|
|
98587
|
-
import { createHash as createHash16, randomUUID as
|
|
98588
|
-
import { existsSync as
|
|
98589
|
-
import { join as
|
|
98954
|
+
import { createHash as createHash16, randomUUID as randomUUID10 } from "node:crypto";
|
|
98955
|
+
import { existsSync as existsSync113, readdirSync as readdirSync36, readFileSync as readFileSync80 } from "node:fs";
|
|
98956
|
+
import { join as join111 } from "node:path";
|
|
98590
98957
|
|
|
98591
98958
|
// packages/core/src/metrics/model-provider-registry.ts
|
|
98592
98959
|
var MODELS_DEV_URL = "https://models.dev/api.json";
|
|
@@ -98746,15 +99113,15 @@ function getOtelDir2() {
|
|
|
98746
99113
|
if (endpoint.startsWith("file://")) {
|
|
98747
99114
|
return endpoint.slice("file://".length);
|
|
98748
99115
|
}
|
|
98749
|
-
return
|
|
99116
|
+
return join111(getCleoHome(), "metrics", "otel");
|
|
98750
99117
|
}
|
|
98751
99118
|
function readOtelJsonl(dir) {
|
|
98752
|
-
if (!
|
|
99119
|
+
if (!existsSync113(dir)) return [];
|
|
98753
99120
|
const entries = [];
|
|
98754
99121
|
for (const file2 of readdirSync36(dir)) {
|
|
98755
99122
|
if (!file2.endsWith(".json") && !file2.endsWith(".jsonl")) continue;
|
|
98756
|
-
const filePath =
|
|
98757
|
-
const raw =
|
|
99123
|
+
const filePath = join111(dir, file2);
|
|
99124
|
+
const raw = readFileSync80(filePath, "utf-8").trim();
|
|
98758
99125
|
if (!raw) continue;
|
|
98759
99126
|
for (const line2 of raw.split("\n")) {
|
|
98760
99127
|
try {
|
|
@@ -98918,7 +99285,7 @@ async function recordTokenExchange(input) {
|
|
|
98918
99285
|
const measurement = await measureTokenExchange(input);
|
|
98919
99286
|
const db = await getDb4(input.cwd);
|
|
98920
99287
|
const row = {
|
|
98921
|
-
id:
|
|
99288
|
+
id: randomUUID10(),
|
|
98922
99289
|
provider: measurement.provider,
|
|
98923
99290
|
model: measurement.model,
|
|
98924
99291
|
transport: input.transport ?? "unknown",
|
|
@@ -98955,13 +99322,13 @@ async function showTokenUsage(id, cwd) {
|
|
|
98955
99322
|
}
|
|
98956
99323
|
async function listTokenUsage(filters = {}, cwd) {
|
|
98957
99324
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
98958
|
-
const { and:
|
|
99325
|
+
const { and: and14, count: count5, desc: desc8 } = await import("drizzle-orm");
|
|
98959
99326
|
const db = await getDb4(cwd);
|
|
98960
99327
|
const clauses = await whereClauses(filters);
|
|
98961
|
-
const where = clauses.length > 0 ?
|
|
98962
|
-
const totalRows = await db.select({ count:
|
|
98963
|
-
const filteredRows = await db.select({ count:
|
|
98964
|
-
let query = db.select().from(tokenUsage).orderBy(
|
|
99328
|
+
const where = clauses.length > 0 ? and14(...clauses) : void 0;
|
|
99329
|
+
const totalRows = await db.select({ count: count5() }).from(tokenUsage);
|
|
99330
|
+
const filteredRows = await db.select({ count: count5() }).from(tokenUsage).where(where);
|
|
99331
|
+
let query = db.select().from(tokenUsage).orderBy(desc8(tokenUsage.createdAt));
|
|
98965
99332
|
if (where) query = query.where(where);
|
|
98966
99333
|
const limit = typeof filters.limit === "number" && filters.limit > 0 ? filters.limit : 20;
|
|
98967
99334
|
const offset = typeof filters.offset === "number" && filters.offset > 0 ? filters.offset : 0;
|
|
@@ -98974,11 +99341,11 @@ async function listTokenUsage(filters = {}, cwd) {
|
|
|
98974
99341
|
}
|
|
98975
99342
|
async function summarizeTokenUsage(filters = {}, cwd) {
|
|
98976
99343
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
98977
|
-
const { and:
|
|
99344
|
+
const { and: and14, desc: desc8 } = await import("drizzle-orm");
|
|
98978
99345
|
const db = await getDb4(cwd);
|
|
98979
99346
|
const clauses = await whereClauses(filters);
|
|
98980
|
-
const where = clauses.length > 0 ?
|
|
98981
|
-
const rows = await db.select().from(tokenUsage).where(where).orderBy(
|
|
99347
|
+
const where = clauses.length > 0 ? and14(...clauses) : void 0;
|
|
99348
|
+
const rows = await db.select().from(tokenUsage).where(where).orderBy(desc8(tokenUsage.createdAt));
|
|
98982
99349
|
const byMethod = /* @__PURE__ */ new Map();
|
|
98983
99350
|
const byTransport = /* @__PURE__ */ new Map();
|
|
98984
99351
|
const byOperation = /* @__PURE__ */ new Map();
|
|
@@ -99025,11 +99392,11 @@ async function deleteTokenUsage(id, cwd) {
|
|
|
99025
99392
|
}
|
|
99026
99393
|
async function clearTokenUsage(filters = {}, cwd) {
|
|
99027
99394
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
99028
|
-
const { and:
|
|
99395
|
+
const { and: and14, count: count5 } = await import("drizzle-orm");
|
|
99029
99396
|
const db = await getDb4(cwd);
|
|
99030
99397
|
const clauses = await whereClauses(filters);
|
|
99031
|
-
const where = clauses.length > 0 ?
|
|
99032
|
-
const countRows = await db.select({ count:
|
|
99398
|
+
const where = clauses.length > 0 ? and14(...clauses) : void 0;
|
|
99399
|
+
const countRows = await db.select({ count: count5() }).from(tokenUsage).where(where);
|
|
99033
99400
|
await db.delete(tokenUsage).where(where);
|
|
99034
99401
|
return { deleted: countRows[0]?.count ?? 0 };
|
|
99035
99402
|
}
|
|
@@ -99132,34 +99499,34 @@ async function getParallelStatus(cwd, accessor) {
|
|
|
99132
99499
|
// packages/core/src/orchestration/skill-ops.ts
|
|
99133
99500
|
init_src();
|
|
99134
99501
|
init_errors3();
|
|
99135
|
-
import { existsSync as
|
|
99136
|
-
import { join as
|
|
99502
|
+
import { existsSync as existsSync114, readdirSync as readdirSync37, readFileSync as readFileSync81 } from "node:fs";
|
|
99503
|
+
import { join as join112 } from "node:path";
|
|
99137
99504
|
import { getCanonicalSkillsDir as getCanonicalSkillsDir3 } from "@cleocode/caamp";
|
|
99138
99505
|
function getSkillContent(skillName, projectRoot) {
|
|
99139
99506
|
if (!skillName) {
|
|
99140
99507
|
throw new CleoError(2 /* INVALID_INPUT */, "skill name is required");
|
|
99141
99508
|
}
|
|
99142
|
-
const projectSkillDir =
|
|
99143
|
-
const canonicalSkillDir =
|
|
99144
|
-
const skillDir =
|
|
99145
|
-
if (!
|
|
99509
|
+
const projectSkillDir = join112(projectRoot, ".cleo", "skills", skillName);
|
|
99510
|
+
const canonicalSkillDir = join112(getCanonicalSkillsDir3(), skillName);
|
|
99511
|
+
const skillDir = existsSync114(projectSkillDir) ? projectSkillDir : canonicalSkillDir;
|
|
99512
|
+
if (!existsSync114(skillDir)) {
|
|
99146
99513
|
throw new CleoError(
|
|
99147
99514
|
4 /* NOT_FOUND */,
|
|
99148
99515
|
`Skill '${skillName}' not found at ${canonicalSkillDir} or ${projectSkillDir}`
|
|
99149
99516
|
);
|
|
99150
99517
|
}
|
|
99151
|
-
const skillFilePath =
|
|
99152
|
-
if (!
|
|
99518
|
+
const skillFilePath = join112(skillDir, "SKILL.md");
|
|
99519
|
+
if (!existsSync114(skillFilePath)) {
|
|
99153
99520
|
throw new CleoError(4 /* NOT_FOUND */, `Skill file not found: ${skillFilePath}`);
|
|
99154
99521
|
}
|
|
99155
|
-
const content =
|
|
99156
|
-
const refsDir =
|
|
99522
|
+
const content = readFileSync81(skillFilePath, "utf-8");
|
|
99523
|
+
const refsDir = join112(skillDir, "references");
|
|
99157
99524
|
let references = [];
|
|
99158
|
-
if (
|
|
99525
|
+
if (existsSync114(refsDir)) {
|
|
99159
99526
|
try {
|
|
99160
99527
|
references = readdirSync37(refsDir).filter((f2) => f2.endsWith(".md") || f2.endsWith(".txt")).map((f2) => ({
|
|
99161
99528
|
name: f2,
|
|
99162
|
-
path:
|
|
99529
|
+
path: join112(skillDir, "references", f2)
|
|
99163
99530
|
}));
|
|
99164
99531
|
} catch {
|
|
99165
99532
|
}
|
|
@@ -99340,8 +99707,8 @@ init_briefing();
|
|
|
99340
99707
|
init_src();
|
|
99341
99708
|
init_errors3();
|
|
99342
99709
|
init_paths();
|
|
99343
|
-
import { existsSync as
|
|
99344
|
-
import { resolve as
|
|
99710
|
+
import { existsSync as existsSync115, readFileSync as readFileSync82 } from "node:fs";
|
|
99711
|
+
import { resolve as resolve12 } from "node:path";
|
|
99345
99712
|
function resolveRoot2(projectRoot) {
|
|
99346
99713
|
return projectRoot || getProjectRoot();
|
|
99347
99714
|
}
|
|
@@ -99351,16 +99718,16 @@ function injectContext(protocolType, params, projectRoot) {
|
|
|
99351
99718
|
}
|
|
99352
99719
|
const root = resolveRoot2(projectRoot);
|
|
99353
99720
|
const protocolLocations = [
|
|
99354
|
-
|
|
99355
|
-
|
|
99356
|
-
|
|
99721
|
+
resolve12(root, "protocols", `${protocolType}.md`),
|
|
99722
|
+
resolve12(root, "skills", "_shared", `${protocolType}.md`),
|
|
99723
|
+
resolve12(root, "agents", "cleo-subagent", "protocols", `${protocolType}.md`)
|
|
99357
99724
|
];
|
|
99358
99725
|
let protocolContent = null;
|
|
99359
99726
|
let protocolPath = null;
|
|
99360
99727
|
for (const loc of protocolLocations) {
|
|
99361
|
-
if (
|
|
99728
|
+
if (existsSync115(loc)) {
|
|
99362
99729
|
try {
|
|
99363
|
-
protocolContent =
|
|
99730
|
+
protocolContent = readFileSync82(loc, "utf-8");
|
|
99364
99731
|
protocolPath = loc.replace(root + "/", "");
|
|
99365
99732
|
break;
|
|
99366
99733
|
} catch {
|
|
@@ -99419,7 +99786,7 @@ import Vt from "node:fs";
|
|
|
99419
99786
|
import { dirname as xn, parse as Ln } from "path";
|
|
99420
99787
|
import { EventEmitter as _n } from "events";
|
|
99421
99788
|
import Mi from "assert";
|
|
99422
|
-
import { Buffer as
|
|
99789
|
+
import { Buffer as gt3 } from "buffer";
|
|
99423
99790
|
import * as ks from "zlib";
|
|
99424
99791
|
import qr from "zlib";
|
|
99425
99792
|
import { posix as Zt } from "node:path";
|
|
@@ -100058,11 +100425,11 @@ var K = (s3, t, e, i, r) => Object.assign((n = [], o, h) => {
|
|
|
100058
100425
|
}, { syncFile: s3, asyncFile: t, syncNoFile: e, asyncNoFile: i, validate: r });
|
|
100059
100426
|
var jr = qr.constants || { ZLIB_VERNUM: 4736 };
|
|
100060
100427
|
var M = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), { Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5, Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9, Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0, DEFLATE: 1, INFLATE: 2, GZIP: 3, GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7, BROTLI_DECODE: 8, BROTLI_ENCODE: 9, Z_MIN_WINDOWBITS: 8, Z_MAX_WINDOWBITS: 15, Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: 1 / 0, Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9, Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1, Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1, BROTLI_OPERATION_PROCESS: 0, BROTLI_OPERATION_FLUSH: 1, BROTLI_OPERATION_FINISH: 2, BROTLI_OPERATION_EMIT_METADATA: 3, BROTLI_MODE_GENERIC: 0, BROTLI_MODE_TEXT: 1, BROTLI_MODE_FONT: 2, BROTLI_DEFAULT_MODE: 0, BROTLI_MIN_QUALITY: 0, BROTLI_MAX_QUALITY: 11, BROTLI_DEFAULT_QUALITY: 11, BROTLI_MIN_WINDOW_BITS: 10, BROTLI_MAX_WINDOW_BITS: 24, BROTLI_LARGE_MAX_WINDOW_BITS: 30, BROTLI_DEFAULT_WINDOW: 22, BROTLI_MIN_INPUT_BLOCK_BITS: 16, BROTLI_MAX_INPUT_BLOCK_BITS: 24, BROTLI_PARAM_MODE: 0, BROTLI_PARAM_QUALITY: 1, BROTLI_PARAM_LGWIN: 2, BROTLI_PARAM_LGBLOCK: 3, BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, BROTLI_PARAM_SIZE_HINT: 5, BROTLI_PARAM_LARGE_WINDOW: 6, BROTLI_PARAM_NPOSTFIX: 7, BROTLI_PARAM_NDIRECT: 8, BROTLI_DECODER_RESULT_ERROR: 0, BROTLI_DECODER_RESULT_SUCCESS: 1, BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0, BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, BROTLI_DECODER_NO_ERROR: 0, BROTLI_DECODER_SUCCESS: 1, BROTLI_DECODER_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5, BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7, BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11, BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13, BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15, BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21, BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27, BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, BROTLI_DECODER_ERROR_UNREACHABLE: -31 }, jr));
|
|
100061
|
-
var Qr =
|
|
100062
|
-
var vs = Object.getOwnPropertyDescriptor(
|
|
100428
|
+
var Qr = gt3.concat;
|
|
100429
|
+
var vs = Object.getOwnPropertyDescriptor(gt3, "concat");
|
|
100063
100430
|
var Jr = (s3) => s3;
|
|
100064
100431
|
var ki = vs?.writable === true || vs?.set !== void 0 ? (s3) => {
|
|
100065
|
-
|
|
100432
|
+
gt3.concat = s3 ? Jr : Qr;
|
|
100066
100433
|
} : (s3) => {
|
|
100067
100434
|
};
|
|
100068
100435
|
var Ot = /* @__PURE__ */ Symbol("_superWrite");
|
|
@@ -100113,7 +100480,7 @@ var ne4 = class extends D {
|
|
|
100113
100480
|
if (!this.#t) return Mi(this.#e, "zlib binding closed"), this.#e.reset?.();
|
|
100114
100481
|
}
|
|
100115
100482
|
flush(t) {
|
|
100116
|
-
this.ended || (typeof t != "number" && (t = this.#r), this.write(Object.assign(
|
|
100483
|
+
this.ended || (typeof t != "number" && (t = this.#r), this.write(Object.assign(gt3.alloc(0), { [vi]: t })));
|
|
100117
100484
|
}
|
|
100118
100485
|
end(t, e, i) {
|
|
100119
100486
|
return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), t && (e ? this.write(t, e) : this.write(t)), this.flush(this.#n), this.#i = true, super.end(i);
|
|
@@ -100125,7 +100492,7 @@ var ne4 = class extends D {
|
|
|
100125
100492
|
return super.write(t);
|
|
100126
100493
|
}
|
|
100127
100494
|
write(t, e, i) {
|
|
100128
|
-
if (typeof e == "function" && (i = e, e = "utf8"), typeof t == "string" && (t =
|
|
100495
|
+
if (typeof e == "function" && (i = e, e = "utf8"), typeof t == "string" && (t = gt3.from(t, e)), this.#t) return;
|
|
100129
100496
|
Mi(this.#e, "zlib binding closed");
|
|
100130
100497
|
let r = this.#e._handle, n = r.close;
|
|
100131
100498
|
r.close = () => {
|
|
@@ -100146,9 +100513,9 @@ var ne4 = class extends D {
|
|
|
100146
100513
|
let a;
|
|
100147
100514
|
if (h) if (Array.isArray(h) && h.length > 0) {
|
|
100148
100515
|
let l = h[0];
|
|
100149
|
-
a = this[Ot](
|
|
100516
|
+
a = this[Ot](gt3.from(l));
|
|
100150
100517
|
for (let c = 1; c < h.length; c++) a = this[Ot](h[c]);
|
|
100151
|
-
} else a = this[Ot](
|
|
100518
|
+
} else a = this[Ot](gt3.from(h));
|
|
100152
100519
|
return i && i(), a;
|
|
100153
100520
|
}
|
|
100154
100521
|
};
|
|
@@ -102385,8 +102752,8 @@ init_signaldock_sqlite();
|
|
|
102385
102752
|
|
|
102386
102753
|
// packages/core/src/store/t310-readiness.ts
|
|
102387
102754
|
init_paths();
|
|
102388
|
-
import { existsSync as
|
|
102389
|
-
import { join as
|
|
102755
|
+
import { existsSync as existsSync116 } from "node:fs";
|
|
102756
|
+
import { join as join113 } from "node:path";
|
|
102390
102757
|
var T310MigrationRequiredError = class extends Error {
|
|
102391
102758
|
/**
|
|
102392
102759
|
* @param projectRoot - Absolute path to the project root that needs migration.
|
|
@@ -102402,9 +102769,9 @@ var T310MigrationRequiredError = class extends Error {
|
|
|
102402
102769
|
};
|
|
102403
102770
|
function assertT310Ready(projectRoot) {
|
|
102404
102771
|
const root = projectRoot ?? getProjectRoot();
|
|
102405
|
-
const legacyPath =
|
|
102406
|
-
const conduitPath =
|
|
102407
|
-
if (
|
|
102772
|
+
const legacyPath = join113(root, ".cleo", "signaldock.db");
|
|
102773
|
+
const conduitPath = join113(root, ".cleo", "conduit.db");
|
|
102774
|
+
if (existsSync116(legacyPath) && !existsSync116(conduitPath)) {
|
|
102408
102775
|
throw new T310MigrationRequiredError(root);
|
|
102409
102776
|
}
|
|
102410
102777
|
}
|
|
@@ -102908,9 +103275,9 @@ init_paths();
|
|
|
102908
103275
|
init_conduit_sqlite();
|
|
102909
103276
|
init_global_salt();
|
|
102910
103277
|
init_signaldock_sqlite();
|
|
102911
|
-
import { existsSync as
|
|
103278
|
+
import { existsSync as existsSync117, mkdirSync as mkdirSync27, renameSync as renameSync9, unlinkSync as unlinkSync9 } from "node:fs";
|
|
102912
103279
|
import { createRequire as createRequire12 } from "node:module";
|
|
102913
|
-
import { join as
|
|
103280
|
+
import { join as join114 } from "node:path";
|
|
102914
103281
|
var _require12 = createRequire12(import.meta.url);
|
|
102915
103282
|
var { DatabaseSync: DatabaseSync7 } = _require12("node:sqlite");
|
|
102916
103283
|
var PROJECT_TIER_TABLES = [
|
|
@@ -102940,9 +103307,9 @@ var GLOBAL_IDENTITY_TABLES = [
|
|
|
102940
103307
|
"org_agent_keys"
|
|
102941
103308
|
];
|
|
102942
103309
|
function needsSignaldockToConduitMigration(projectRoot) {
|
|
102943
|
-
const legacyPath =
|
|
102944
|
-
const conduitPath =
|
|
102945
|
-
return
|
|
103310
|
+
const legacyPath = join114(projectRoot, ".cleo", "signaldock.db");
|
|
103311
|
+
const conduitPath = join114(projectRoot, ".cleo", "conduit.db");
|
|
103312
|
+
return existsSync117(legacyPath) && !existsSync117(conduitPath);
|
|
102946
103313
|
}
|
|
102947
103314
|
function tableExistsInDb(db, tableName) {
|
|
102948
103315
|
const row = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name=?").get(tableName);
|
|
@@ -102982,9 +103349,9 @@ function brokenTimestamp() {
|
|
|
102982
103349
|
}
|
|
102983
103350
|
function migrateSignaldockToConduit(projectRoot) {
|
|
102984
103351
|
const log12 = getLogger("migrate-signaldock-to-conduit");
|
|
102985
|
-
const legacyPath =
|
|
102986
|
-
const conduitPath =
|
|
102987
|
-
const globalSignaldockPath =
|
|
103352
|
+
const legacyPath = join114(projectRoot, ".cleo", "signaldock.db");
|
|
103353
|
+
const conduitPath = join114(projectRoot, ".cleo", "conduit.db");
|
|
103354
|
+
const globalSignaldockPath = join114(getCleoHome(), "signaldock.db");
|
|
102988
103355
|
const bakPath = `${legacyPath}.pre-t310.bak`;
|
|
102989
103356
|
const result = {
|
|
102990
103357
|
status: "no-op",
|
|
@@ -103028,8 +103395,8 @@ function migrateSignaldockToConduit(projectRoot) {
|
|
|
103028
103395
|
}
|
|
103029
103396
|
const cleoHome = getCleoHome();
|
|
103030
103397
|
try {
|
|
103031
|
-
if (!
|
|
103032
|
-
|
|
103398
|
+
if (!existsSync117(cleoHome)) {
|
|
103399
|
+
mkdirSync27(cleoHome, { recursive: true });
|
|
103033
103400
|
}
|
|
103034
103401
|
void ensureGlobalSignaldockDb();
|
|
103035
103402
|
} catch {
|
|
@@ -103108,7 +103475,7 @@ function migrateSignaldockToConduit(projectRoot) {
|
|
|
103108
103475
|
conduit.close();
|
|
103109
103476
|
conduit = null;
|
|
103110
103477
|
try {
|
|
103111
|
-
if (
|
|
103478
|
+
if (existsSync117(conduitPath)) {
|
|
103112
103479
|
unlinkSync9(conduitPath);
|
|
103113
103480
|
}
|
|
103114
103481
|
} catch {
|
|
@@ -103148,8 +103515,8 @@ function migrateSignaldockToConduit(projectRoot) {
|
|
|
103148
103515
|
conduit = null;
|
|
103149
103516
|
let globalDb = null;
|
|
103150
103517
|
try {
|
|
103151
|
-
if (!
|
|
103152
|
-
|
|
103518
|
+
if (!existsSync117(globalSignaldockPath)) {
|
|
103519
|
+
mkdirSync27(cleoHome, { recursive: true });
|
|
103153
103520
|
}
|
|
103154
103521
|
globalDb = new DatabaseSync7(globalSignaldockPath);
|
|
103155
103522
|
globalDb.exec("PRAGMA journal_mode = WAL");
|
|
@@ -103346,11 +103713,11 @@ function buildUpstreamTree(taskId, taskMap, visited = /* @__PURE__ */ new Set())
|
|
|
103346
103713
|
return nodes;
|
|
103347
103714
|
}
|
|
103348
103715
|
function countNodes(nodes) {
|
|
103349
|
-
let
|
|
103716
|
+
let count5 = nodes.length;
|
|
103350
103717
|
for (const node of nodes) {
|
|
103351
|
-
|
|
103718
|
+
count5 += countNodes(node.children);
|
|
103352
103719
|
}
|
|
103353
|
-
return
|
|
103720
|
+
return count5;
|
|
103354
103721
|
}
|
|
103355
103722
|
function measureDependencyDepth(taskId, taskMap, visited = /* @__PURE__ */ new Set()) {
|
|
103356
103723
|
if (visited.has(taskId)) return 0;
|
|
@@ -103444,9 +103811,9 @@ async function coreTaskNext(projectRoot, params) {
|
|
|
103444
103811
|
}
|
|
103445
103812
|
} catch {
|
|
103446
103813
|
}
|
|
103447
|
-
const
|
|
103814
|
+
const count5 = Math.min(params?.count || 1, scored.length);
|
|
103448
103815
|
const explain = params?.explain ?? false;
|
|
103449
|
-
const suggestions = scored.slice(0,
|
|
103816
|
+
const suggestions = scored.slice(0, count5).map(({ task, score, reasons }) => ({
|
|
103450
103817
|
id: task.id,
|
|
103451
103818
|
title: task.title,
|
|
103452
103819
|
priority: task.priority,
|
|
@@ -103493,9 +103860,9 @@ async function coreTaskBlockers(projectRoot, params) {
|
|
|
103493
103860
|
blockerCounts.set(depId, (blockerCounts.get(depId) ?? 0) + 1);
|
|
103494
103861
|
}
|
|
103495
103862
|
}
|
|
103496
|
-
const criticalBlockers = [...blockerCounts.entries()].sort((a, b2) => b2[1] - a[1]).slice(0, 5).map(([id,
|
|
103863
|
+
const criticalBlockers = [...blockerCounts.entries()].sort((a, b2) => b2[1] - a[1]).slice(0, 5).map(([id, count5]) => {
|
|
103497
103864
|
const task = taskMap.get(id);
|
|
103498
|
-
return { id, title: task?.title ?? "Unknown", blocksCount:
|
|
103865
|
+
return { id, title: task?.title ?? "Unknown", blocksCount: count5 };
|
|
103499
103866
|
});
|
|
103500
103867
|
return {
|
|
103501
103868
|
blockedTasks: pagedBlockerInfos,
|
|
@@ -104115,11 +104482,11 @@ async function coreTaskHistory(projectRoot, taskId, limit) {
|
|
|
104115
104482
|
try {
|
|
104116
104483
|
const { getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
104117
104484
|
const { auditLog: auditLog2 } = await Promise.resolve().then(() => (init_tasks_schema(), tasks_schema_exports));
|
|
104118
|
-
const { sql:
|
|
104485
|
+
const { sql: sql16 } = await import("drizzle-orm");
|
|
104119
104486
|
const db = await getDb4(projectRoot);
|
|
104120
104487
|
const maxRows = limit && limit > 0 ? limit : 100;
|
|
104121
104488
|
const rows = await db.all(
|
|
104122
|
-
|
|
104489
|
+
sql16`SELECT * FROM ${auditLog2}
|
|
104123
104490
|
WHERE ${auditLog2.taskId} = ${taskId}
|
|
104124
104491
|
ORDER BY ${auditLog2.timestamp} DESC
|
|
104125
104492
|
LIMIT ${maxRows}`
|
|
@@ -104403,13 +104770,13 @@ init_scaffold();
|
|
|
104403
104770
|
init_schema_management();
|
|
104404
104771
|
import {
|
|
104405
104772
|
copyFileSync as copyFileSync9,
|
|
104406
|
-
existsSync as
|
|
104407
|
-
mkdirSync as
|
|
104773
|
+
existsSync as existsSync119,
|
|
104774
|
+
mkdirSync as mkdirSync29,
|
|
104408
104775
|
readdirSync as readdirSync38,
|
|
104409
|
-
readFileSync as
|
|
104410
|
-
writeFileSync as
|
|
104776
|
+
readFileSync as readFileSync84,
|
|
104777
|
+
writeFileSync as writeFileSync21
|
|
104411
104778
|
} from "node:fs";
|
|
104412
|
-
import { join as
|
|
104779
|
+
import { join as join116 } from "node:path";
|
|
104413
104780
|
|
|
104414
104781
|
// packages/core/src/store/index.ts
|
|
104415
104782
|
init_atomic();
|
|
@@ -104448,8 +104815,8 @@ async function runUpgrade(options = {}) {
|
|
|
104448
104815
|
};
|
|
104449
104816
|
}
|
|
104450
104817
|
const cleoDir = getCleoDirAbsolute(options.cwd);
|
|
104451
|
-
const dbPath =
|
|
104452
|
-
const dbExists2 =
|
|
104818
|
+
const dbPath = join116(cleoDir, "tasks.db");
|
|
104819
|
+
const dbExists2 = existsSync119(dbPath);
|
|
104453
104820
|
const legacyRecordCount = preflight.details.todoJsonTaskCount + preflight.details.archiveJsonTaskCount + preflight.details.sessionsJsonCount;
|
|
104454
104821
|
const needsMigration = !dbExists2 && legacyRecordCount > 0;
|
|
104455
104822
|
const needsCleanup = dbExists2 && preflight.migrationNeeded;
|
|
@@ -104465,7 +104832,7 @@ async function runUpgrade(options = {}) {
|
|
|
104465
104832
|
let migrationLock = null;
|
|
104466
104833
|
try {
|
|
104467
104834
|
const cleoDir2 = getCleoDirAbsolute(options.cwd);
|
|
104468
|
-
const dbPath2 =
|
|
104835
|
+
const dbPath2 = join116(cleoDir2, "tasks.db");
|
|
104469
104836
|
try {
|
|
104470
104837
|
migrationLock = await acquireLock(dbPath2, { stale: 3e4, retries: 0 });
|
|
104471
104838
|
} catch {
|
|
@@ -104490,28 +104857,28 @@ async function runUpgrade(options = {}) {
|
|
|
104490
104857
|
} = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
104491
104858
|
const logger = new MigrationLogger2(cleoDir2);
|
|
104492
104859
|
await createMigrationState2(cleoDir2, {
|
|
104493
|
-
todoJson: { path:
|
|
104494
|
-
sessionsJson: { path:
|
|
104495
|
-
archiveJson: { path:
|
|
104860
|
+
todoJson: { path: join116(cleoDir2, "todo.json"), checksum: "" },
|
|
104861
|
+
sessionsJson: { path: join116(cleoDir2, "sessions.json"), checksum: "" },
|
|
104862
|
+
archiveJson: { path: join116(cleoDir2, "todo-archive.json"), checksum: "" }
|
|
104496
104863
|
});
|
|
104497
104864
|
await updateMigrationPhase2(cleoDir2, "backup");
|
|
104498
104865
|
logger.info("init", "start", "Migration state initialized");
|
|
104499
|
-
const dbBackupPath =
|
|
104866
|
+
const dbBackupPath = join116(
|
|
104500
104867
|
cleoDir2,
|
|
104501
104868
|
"backups",
|
|
104502
104869
|
"safety",
|
|
104503
104870
|
`tasks.db.pre-migration.${Date.now()}`
|
|
104504
104871
|
);
|
|
104505
|
-
const dbTempPath =
|
|
104506
|
-
if (
|
|
104507
|
-
const backupDir =
|
|
104508
|
-
if (!
|
|
104509
|
-
|
|
104872
|
+
const dbTempPath = join116(cleoDir2, "tasks.db.migrating");
|
|
104873
|
+
if (existsSync119(dbPath2)) {
|
|
104874
|
+
const backupDir = join116(cleoDir2, "backups", "safety");
|
|
104875
|
+
if (!existsSync119(backupDir)) {
|
|
104876
|
+
mkdirSync29(backupDir, { recursive: true });
|
|
104510
104877
|
}
|
|
104511
104878
|
copyFileSync9(dbPath2, dbBackupPath);
|
|
104512
104879
|
const { createHash: createHash17 } = await import("node:crypto");
|
|
104513
|
-
const origChecksum = createHash17("sha256").update(
|
|
104514
|
-
const backupChecksum = createHash17("sha256").update(
|
|
104880
|
+
const origChecksum = createHash17("sha256").update(readFileSync84(dbPath2)).digest("hex");
|
|
104881
|
+
const backupChecksum = createHash17("sha256").update(readFileSync84(dbBackupPath)).digest("hex");
|
|
104515
104882
|
if (origChecksum !== backupChecksum) {
|
|
104516
104883
|
throw new Error(
|
|
104517
104884
|
`Backup verification failed: checksum mismatch. Aborting migration to prevent data loss.`
|
|
@@ -104528,14 +104895,14 @@ async function runUpgrade(options = {}) {
|
|
|
104528
104895
|
checksum: origChecksum
|
|
104529
104896
|
});
|
|
104530
104897
|
}
|
|
104531
|
-
if (
|
|
104898
|
+
if (existsSync119(dbTempPath)) {
|
|
104532
104899
|
const { unlinkSync: unlinkSync10 } = await import("node:fs");
|
|
104533
104900
|
unlinkSync10(dbTempPath);
|
|
104534
104901
|
}
|
|
104535
|
-
const configPath =
|
|
104902
|
+
const configPath = join116(cleoDir2, "config.json");
|
|
104536
104903
|
let configBackup = null;
|
|
104537
|
-
if (
|
|
104538
|
-
configBackup =
|
|
104904
|
+
if (existsSync119(configPath)) {
|
|
104905
|
+
configBackup = readFileSync84(configPath, "utf-8");
|
|
104539
104906
|
}
|
|
104540
104907
|
const { resetDbState: resetDbState2 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
104541
104908
|
resetDbState2();
|
|
@@ -104563,10 +104930,10 @@ async function runUpgrade(options = {}) {
|
|
|
104563
104930
|
resetDbState2();
|
|
104564
104931
|
if (result.success) {
|
|
104565
104932
|
const totalImported = result.tasksImported + result.archivedImported;
|
|
104566
|
-
if (totalImported === 0 &&
|
|
104933
|
+
if (totalImported === 0 && existsSync119(dbBackupPath)) {
|
|
104567
104934
|
copyFileSync9(dbBackupPath, dbPath2);
|
|
104568
104935
|
if (configBackup) {
|
|
104569
|
-
|
|
104936
|
+
writeFileSync21(configPath, configBackup);
|
|
104570
104937
|
}
|
|
104571
104938
|
actions.push({
|
|
104572
104939
|
action: "storage_migration",
|
|
@@ -104577,9 +104944,9 @@ async function runUpgrade(options = {}) {
|
|
|
104577
104944
|
errors.push("Migration imported 0 tasks \u2014 restored from backup to prevent data loss");
|
|
104578
104945
|
} else {
|
|
104579
104946
|
let config2 = {};
|
|
104580
|
-
if (
|
|
104947
|
+
if (existsSync119(configPath)) {
|
|
104581
104948
|
try {
|
|
104582
|
-
config2 = JSON.parse(
|
|
104949
|
+
config2 = JSON.parse(readFileSync84(configPath, "utf-8"));
|
|
104583
104950
|
} catch {
|
|
104584
104951
|
}
|
|
104585
104952
|
}
|
|
@@ -104587,7 +104954,7 @@ async function runUpgrade(options = {}) {
|
|
|
104587
104954
|
config2.storage = {};
|
|
104588
104955
|
}
|
|
104589
104956
|
config2.storage.engine = "sqlite";
|
|
104590
|
-
|
|
104957
|
+
writeFileSync21(configPath, JSON.stringify(config2, null, 2));
|
|
104591
104958
|
actions.push({
|
|
104592
104959
|
action: "storage_migration",
|
|
104593
104960
|
status: "applied",
|
|
@@ -104605,11 +104972,11 @@ async function runUpgrade(options = {}) {
|
|
|
104605
104972
|
logger.info("complete", "finish", "Migration completed successfully");
|
|
104606
104973
|
}
|
|
104607
104974
|
} else {
|
|
104608
|
-
if (
|
|
104975
|
+
if (existsSync119(dbBackupPath)) {
|
|
104609
104976
|
copyFileSync9(dbBackupPath, dbPath2);
|
|
104610
104977
|
}
|
|
104611
104978
|
if (configBackup) {
|
|
104612
|
-
|
|
104979
|
+
writeFileSync21(configPath, configBackup);
|
|
104613
104980
|
}
|
|
104614
104981
|
await updateMigrationPhase2(cleoDir2, "failed");
|
|
104615
104982
|
for (const error48 of result.errors) {
|
|
@@ -104628,12 +104995,12 @@ async function runUpgrade(options = {}) {
|
|
|
104628
104995
|
} catch (err) {
|
|
104629
104996
|
try {
|
|
104630
104997
|
const cleoDir2 = getCleoDirAbsolute(options.cwd);
|
|
104631
|
-
const dbPath2 =
|
|
104632
|
-
const safetyDir =
|
|
104633
|
-
if (
|
|
104998
|
+
const dbPath2 = join116(cleoDir2, "tasks.db");
|
|
104999
|
+
const safetyDir = join116(cleoDir2, "backups", "safety");
|
|
105000
|
+
if (existsSync119(safetyDir)) {
|
|
104634
105001
|
const backups = readdirSync38(safetyDir).filter((f2) => f2.startsWith("tasks.db.pre-migration.")).sort().reverse();
|
|
104635
|
-
if (backups.length > 0 && !
|
|
104636
|
-
copyFileSync9(
|
|
105002
|
+
if (backups.length > 0 && !existsSync119(dbPath2)) {
|
|
105003
|
+
copyFileSync9(join116(safetyDir, backups[0]), dbPath2);
|
|
104637
105004
|
}
|
|
104638
105005
|
}
|
|
104639
105006
|
} catch {
|
|
@@ -104669,7 +105036,7 @@ async function runUpgrade(options = {}) {
|
|
|
104669
105036
|
reason: dbExists2 ? "SQLite DB exists and is accessible \u2014 no migration needed. Use --diagnose for column/migration validation." : "No legacy JSON data found and no DB exists \u2014 nothing to migrate."
|
|
104670
105037
|
});
|
|
104671
105038
|
}
|
|
104672
|
-
if (
|
|
105039
|
+
if (existsSync119(dbPath)) {
|
|
104673
105040
|
try {
|
|
104674
105041
|
const { runAllRepairs: runAllRepairs2 } = await Promise.resolve().then(() => (init_repair(), repair_exports));
|
|
104675
105042
|
const repairActions = await runAllRepairs2(options.cwd, isDryRun);
|
|
@@ -104679,9 +105046,9 @@ async function runUpgrade(options = {}) {
|
|
|
104679
105046
|
} catch {
|
|
104680
105047
|
}
|
|
104681
105048
|
}
|
|
104682
|
-
if (
|
|
105049
|
+
if (existsSync119(dbPath)) {
|
|
104683
105050
|
const legacySequenceFiles = [".sequence", ".sequence.json"].filter(
|
|
104684
|
-
(f2) =>
|
|
105051
|
+
(f2) => existsSync119(join116(cleoDir, f2))
|
|
104685
105052
|
);
|
|
104686
105053
|
if (legacySequenceFiles.length > 0) {
|
|
104687
105054
|
if (isDryRun) {
|
|
@@ -104717,7 +105084,7 @@ async function runUpgrade(options = {}) {
|
|
|
104717
105084
|
".sequence",
|
|
104718
105085
|
".sequence.json"
|
|
104719
105086
|
];
|
|
104720
|
-
const foundStale = staleJsonFiles.filter((f2) =>
|
|
105087
|
+
const foundStale = staleJsonFiles.filter((f2) => existsSync119(join116(cleoDir, f2)));
|
|
104721
105088
|
if (foundStale.length > 0) {
|
|
104722
105089
|
if (isDryRun) {
|
|
104723
105090
|
actions.push({
|
|
@@ -104727,15 +105094,15 @@ async function runUpgrade(options = {}) {
|
|
|
104727
105094
|
});
|
|
104728
105095
|
} else {
|
|
104729
105096
|
try {
|
|
104730
|
-
const backupDir =
|
|
104731
|
-
|
|
105097
|
+
const backupDir = join116(cleoDir, ".backups", `legacy-json-${Date.now()}`);
|
|
105098
|
+
mkdirSync29(backupDir, { recursive: true });
|
|
104732
105099
|
for (const f2 of foundStale) {
|
|
104733
|
-
const src =
|
|
104734
|
-
copyFileSync9(src,
|
|
105100
|
+
const src = join116(cleoDir, f2);
|
|
105101
|
+
copyFileSync9(src, join116(backupDir, f2));
|
|
104735
105102
|
}
|
|
104736
105103
|
const { unlinkSync: unlinkSync10 } = await import("node:fs");
|
|
104737
105104
|
for (const f2 of foundStale) {
|
|
104738
|
-
unlinkSync10(
|
|
105105
|
+
unlinkSync10(join116(cleoDir, f2));
|
|
104739
105106
|
}
|
|
104740
105107
|
actions.push({
|
|
104741
105108
|
action: "stale_json_cleanup",
|
|
@@ -104755,7 +105122,7 @@ async function runUpgrade(options = {}) {
|
|
|
104755
105122
|
if (options.includeGlobal) {
|
|
104756
105123
|
try {
|
|
104757
105124
|
const globalDir = getCleoHome();
|
|
104758
|
-
const globalPreflight = checkStorageMigration(
|
|
105125
|
+
const globalPreflight = checkStorageMigration(join116(globalDir, ".."));
|
|
104759
105126
|
if (globalPreflight.migrationNeeded) {
|
|
104760
105127
|
actions.push({
|
|
104761
105128
|
action: "global_storage_check",
|
|
@@ -104776,8 +105143,8 @@ async function runUpgrade(options = {}) {
|
|
|
104776
105143
|
try {
|
|
104777
105144
|
const projectRoot = getProjectRoot(options.cwd);
|
|
104778
105145
|
if (isDryRun) {
|
|
104779
|
-
const gitignorePath =
|
|
104780
|
-
if (!
|
|
105146
|
+
const gitignorePath = join116(cleoDir, ".gitignore");
|
|
105147
|
+
if (!existsSync119(gitignorePath)) {
|
|
104781
105148
|
actions.push({
|
|
104782
105149
|
action: "gitignore_integrity",
|
|
104783
105150
|
status: "preview",
|
|
@@ -104828,8 +105195,8 @@ async function runUpgrade(options = {}) {
|
|
|
104828
105195
|
try {
|
|
104829
105196
|
const projectRootForContext = getProjectRoot(options.cwd);
|
|
104830
105197
|
if (isDryRun) {
|
|
104831
|
-
const contextPath =
|
|
104832
|
-
if (!
|
|
105198
|
+
const contextPath = join116(cleoDir, "project-context.json");
|
|
105199
|
+
if (!existsSync119(contextPath)) {
|
|
104833
105200
|
actions.push({
|
|
104834
105201
|
action: "project_context_detection",
|
|
104835
105202
|
status: "preview",
|
|
@@ -104837,7 +105204,7 @@ async function runUpgrade(options = {}) {
|
|
|
104837
105204
|
});
|
|
104838
105205
|
} else {
|
|
104839
105206
|
try {
|
|
104840
|
-
const context = JSON.parse(
|
|
105207
|
+
const context = JSON.parse(readFileSync84(contextPath, "utf-8"));
|
|
104841
105208
|
if (context.detectedAt) {
|
|
104842
105209
|
const daysSince = (Date.now() - new Date(context.detectedAt).getTime()) / (1e3 * 60 * 60 * 24);
|
|
104843
105210
|
if (daysSince > 30) {
|
|
@@ -105236,9 +105603,9 @@ async function runUpgrade(options = {}) {
|
|
|
105236
105603
|
async function diagnoseUpgrade(options = {}) {
|
|
105237
105604
|
const findings = [];
|
|
105238
105605
|
const cleoDir = getCleoDirAbsolute(options.cwd);
|
|
105239
|
-
const dbPath =
|
|
105240
|
-
const brainDbPath =
|
|
105241
|
-
if (
|
|
105606
|
+
const dbPath = join116(cleoDir, "tasks.db");
|
|
105607
|
+
const brainDbPath = join116(cleoDir, "brain.db");
|
|
105608
|
+
if (existsSync119(dbPath)) {
|
|
105242
105609
|
try {
|
|
105243
105610
|
const { getNativeDb: getNativeDb3, getDb: getDb4 } = await Promise.resolve().then(() => (init_sqlite2(), sqlite_exports));
|
|
105244
105611
|
const projectRoot = getProjectRoot(options.cwd);
|
|
@@ -105331,7 +105698,7 @@ async function diagnoseUpgrade(options = {}) {
|
|
|
105331
105698
|
fix: "Run: cleo init"
|
|
105332
105699
|
});
|
|
105333
105700
|
}
|
|
105334
|
-
if (
|
|
105701
|
+
if (existsSync119(brainDbPath)) {
|
|
105335
105702
|
try {
|
|
105336
105703
|
const { getBrainNativeDb: getBrainNativeDb2, getBrainDb: getBrainDb2 } = await Promise.resolve().then(() => (init_brain_sqlite(), brain_sqlite_exports));
|
|
105337
105704
|
await getBrainDb2(options.cwd);
|
|
@@ -105463,8 +105830,8 @@ async function diagnoseUpgrade(options = {}) {
|
|
|
105463
105830
|
fix: "Run: cleo upgrade"
|
|
105464
105831
|
});
|
|
105465
105832
|
}
|
|
105466
|
-
const signaldockDbPath =
|
|
105467
|
-
if (
|
|
105833
|
+
const signaldockDbPath = join116(cleoDir, "signaldock.db");
|
|
105834
|
+
if (existsSync119(signaldockDbPath)) {
|
|
105468
105835
|
findings.push({
|
|
105469
105836
|
check: "signaldock.db",
|
|
105470
105837
|
status: "ok",
|
|
@@ -105478,8 +105845,8 @@ async function diagnoseUpgrade(options = {}) {
|
|
|
105478
105845
|
fix: "Run: cleo upgrade"
|
|
105479
105846
|
});
|
|
105480
105847
|
}
|
|
105481
|
-
const conduitDbPath =
|
|
105482
|
-
if (
|
|
105848
|
+
const conduitDbPath = join116(cleoDir, "conduit.db");
|
|
105849
|
+
if (existsSync119(conduitDbPath)) {
|
|
105483
105850
|
findings.push({
|
|
105484
105851
|
check: "conduit.db",
|
|
105485
105852
|
status: "ok",
|
|
@@ -105493,10 +105860,10 @@ async function diagnoseUpgrade(options = {}) {
|
|
|
105493
105860
|
fix: "Run: cleo upgrade"
|
|
105494
105861
|
});
|
|
105495
105862
|
}
|
|
105496
|
-
const memoryBridgePath =
|
|
105497
|
-
if (
|
|
105863
|
+
const memoryBridgePath = join116(cleoDir, "memory-bridge.md");
|
|
105864
|
+
if (existsSync119(memoryBridgePath)) {
|
|
105498
105865
|
try {
|
|
105499
|
-
const content =
|
|
105866
|
+
const content = readFileSync84(memoryBridgePath, "utf-8");
|
|
105500
105867
|
const hasAutoGenMarker = content.includes("Auto-generated");
|
|
105501
105868
|
const hasGarbage = content.includes("undefined") && content.length < 100;
|
|
105502
105869
|
if (hasGarbage) {
|
|
@@ -106681,11 +107048,11 @@ function validateRequiredParamsDef(def2, params) {
|
|
|
106681
107048
|
// packages/core/src/validation/protocols/_shared.ts
|
|
106682
107049
|
init_src();
|
|
106683
107050
|
init_errors3();
|
|
106684
|
-
import { existsSync as
|
|
107051
|
+
import { existsSync as existsSync120, readFileSync as readFileSync85 } from "node:fs";
|
|
106685
107052
|
init_paths();
|
|
106686
107053
|
function findManifestEntry2(taskId, manifestPath) {
|
|
106687
|
-
if (!
|
|
106688
|
-
const content =
|
|
107054
|
+
if (!existsSync120(manifestPath)) return null;
|
|
107055
|
+
const content = readFileSync85(manifestPath, "utf-8").trim();
|
|
106689
107056
|
if (content.length === 0) return null;
|
|
106690
107057
|
const lines = content.split("\n");
|
|
106691
107058
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -106706,13 +107073,13 @@ function loadManifestEntryByTaskId(taskId) {
|
|
|
106706
107073
|
return JSON.parse(entry);
|
|
106707
107074
|
}
|
|
106708
107075
|
function loadManifestEntryFromFile(manifestFile) {
|
|
106709
|
-
if (!
|
|
107076
|
+
if (!existsSync120(manifestFile)) {
|
|
106710
107077
|
throw new CleoError(4 /* NOT_FOUND */, `Manifest file not found: ${manifestFile}`, {
|
|
106711
107078
|
fix: `Ensure the manifest file exists at: ${manifestFile}`,
|
|
106712
107079
|
details: { field: "manifestFile", actual: manifestFile }
|
|
106713
107080
|
});
|
|
106714
107081
|
}
|
|
106715
|
-
return JSON.parse(
|
|
107082
|
+
return JSON.parse(readFileSync85(manifestFile, "utf-8"));
|
|
106716
107083
|
}
|
|
106717
107084
|
function throwIfStrictFailed(result, opts, protocol, taskId) {
|
|
106718
107085
|
if (!opts.strict || result.valid) return;
|
|
@@ -106759,10 +107126,10 @@ async function checkArtifactPublishManifest(manifestFile, opts) {
|
|
|
106759
107126
|
}
|
|
106760
107127
|
|
|
106761
107128
|
// packages/core/src/validation/protocols/consensus.ts
|
|
106762
|
-
import { existsSync as
|
|
107129
|
+
import { existsSync as existsSync121, readFileSync as readFileSync86 } from "node:fs";
|
|
106763
107130
|
function loadVotingMatrix(votingMatrixFile) {
|
|
106764
|
-
if (!votingMatrixFile || !
|
|
106765
|
-
const raw = JSON.parse(
|
|
107131
|
+
if (!votingMatrixFile || !existsSync121(votingMatrixFile)) return { options: [] };
|
|
107132
|
+
const raw = JSON.parse(readFileSync86(votingMatrixFile, "utf-8"));
|
|
106766
107133
|
const options = Array.isArray(raw.options) ? raw.options : Object.values(raw.options ?? {});
|
|
106767
107134
|
return {
|
|
106768
107135
|
options: options.filter(
|
|
@@ -106878,10 +107245,10 @@ async function checkResearchManifest(manifestFile, opts) {
|
|
|
106878
107245
|
}
|
|
106879
107246
|
|
|
106880
107247
|
// packages/core/src/validation/protocols/specification.ts
|
|
106881
|
-
import { existsSync as
|
|
107248
|
+
import { existsSync as existsSync122, readFileSync as readFileSync87 } from "node:fs";
|
|
106882
107249
|
async function validateSpecificationTask(taskId, opts) {
|
|
106883
107250
|
const entry = loadManifestEntryByTaskId(taskId);
|
|
106884
|
-
const specContent = opts.specFile &&
|
|
107251
|
+
const specContent = opts.specFile && existsSync122(opts.specFile) ? readFileSync87(opts.specFile, "utf-8") : void 0;
|
|
106885
107252
|
const result = validateSpecificationProtocol(entry, specContent);
|
|
106886
107253
|
throwIfStrictFailed(result, opts, "specification", taskId);
|
|
106887
107254
|
return result;
|
|
@@ -106889,7 +107256,7 @@ async function validateSpecificationTask(taskId, opts) {
|
|
|
106889
107256
|
async function checkSpecificationManifest(manifestFile, opts) {
|
|
106890
107257
|
const entry = loadManifestEntryFromFile(manifestFile);
|
|
106891
107258
|
const taskId = entry.linked_tasks?.[0] ?? "UNKNOWN";
|
|
106892
|
-
const specContent = opts.specFile &&
|
|
107259
|
+
const specContent = opts.specFile && existsSync122(opts.specFile) ? readFileSync87(opts.specFile, "utf-8") : void 0;
|
|
106893
107260
|
const result = validateSpecificationProtocol(entry, specContent);
|
|
106894
107261
|
throwIfStrictFailed(result, opts, "specification", taskId);
|
|
106895
107262
|
return result;
|
|
@@ -106932,15 +107299,15 @@ init_data_accessor();
|
|
|
106932
107299
|
init_json2();
|
|
106933
107300
|
init_dependency_check();
|
|
106934
107301
|
import { execFileSync as execFileSync12 } from "node:child_process";
|
|
106935
|
-
import { appendFileSync as appendFileSync10, existsSync as
|
|
106936
|
-
import { dirname as
|
|
107302
|
+
import { appendFileSync as appendFileSync10, existsSync as existsSync123, mkdirSync as mkdirSync30, readFileSync as readFileSync89 } from "node:fs";
|
|
107303
|
+
import { dirname as dirname25, join as join117, resolve as resolve13 } from "node:path";
|
|
106937
107304
|
|
|
106938
107305
|
// packages/core/src/validation/schema-validator.ts
|
|
106939
107306
|
init_schema_management();
|
|
106940
107307
|
init_validation_schemas();
|
|
106941
107308
|
import AjvModule from "ajv";
|
|
106942
107309
|
import addFormatsModule from "ajv-formats";
|
|
106943
|
-
import { readFileSync as
|
|
107310
|
+
import { readFileSync as readFileSync88 } from "fs";
|
|
106944
107311
|
var _ajvMod = AjvModule;
|
|
106945
107312
|
var Ajv3 = typeof _ajvMod["default"] === "function" ? _ajvMod["default"] : AjvModule;
|
|
106946
107313
|
var _fmtMod = addFormatsModule;
|
|
@@ -106975,7 +107342,7 @@ function getValidator(schemaType) {
|
|
|
106975
107342
|
return null;
|
|
106976
107343
|
}
|
|
106977
107344
|
try {
|
|
106978
|
-
const schemaContent =
|
|
107345
|
+
const schemaContent = readFileSync88(schemaPath, "utf-8");
|
|
106979
107346
|
const schema = JSON.parse(schemaContent);
|
|
106980
107347
|
const ajv = getAjv2();
|
|
106981
107348
|
const validate = ajv.compile(schema);
|
|
@@ -107018,7 +107385,7 @@ init_validation_rules();
|
|
|
107018
107385
|
init_repair();
|
|
107019
107386
|
function readJsonFile2(filePath) {
|
|
107020
107387
|
try {
|
|
107021
|
-
const raw =
|
|
107388
|
+
const raw = readFileSync89(filePath, "utf-8");
|
|
107022
107389
|
return JSON.parse(raw);
|
|
107023
107390
|
} catch {
|
|
107024
107391
|
return null;
|
|
@@ -107033,8 +107400,8 @@ async function coreValidateSchema(type, data, projectRoot) {
|
|
|
107033
107400
|
throw new Error(`Unknown schema type: ${type}. Valid types: ${validTypes.join(", ")}`);
|
|
107034
107401
|
}
|
|
107035
107402
|
if (type === "config") {
|
|
107036
|
-
const filePath =
|
|
107037
|
-
if (!
|
|
107403
|
+
const filePath = join117(projectRoot, ".cleo", "config.json");
|
|
107404
|
+
if (!existsSync123(filePath)) {
|
|
107038
107405
|
throw new Error("File not found: .cleo/config.json");
|
|
107039
107406
|
}
|
|
107040
107407
|
const configData = data ?? readJsonFile2(filePath);
|
|
@@ -107173,7 +107540,7 @@ async function coreValidateProtocol(taskId, protocolType, projectRoot) {
|
|
|
107173
107540
|
}
|
|
107174
107541
|
function coreValidateManifest(projectRoot) {
|
|
107175
107542
|
const manifestPath = getManifestPath(projectRoot);
|
|
107176
|
-
if (!
|
|
107543
|
+
if (!existsSync123(manifestPath)) {
|
|
107177
107544
|
return {
|
|
107178
107545
|
valid: true,
|
|
107179
107546
|
totalEntries: 0,
|
|
@@ -107183,7 +107550,7 @@ function coreValidateManifest(projectRoot) {
|
|
|
107183
107550
|
message: "No manifest file found"
|
|
107184
107551
|
};
|
|
107185
107552
|
}
|
|
107186
|
-
const content =
|
|
107553
|
+
const content = readFileSync89(manifestPath, "utf-8");
|
|
107187
107554
|
const lines = content.split("\n").filter((l) => l.trim());
|
|
107188
107555
|
let validCount = 0;
|
|
107189
107556
|
let invalidCount = 0;
|
|
@@ -107223,11 +107590,11 @@ function coreValidateOutput(filePath, taskId, projectRoot) {
|
|
|
107223
107590
|
if (!filePath) {
|
|
107224
107591
|
throw new Error("filePath is required");
|
|
107225
107592
|
}
|
|
107226
|
-
const fullPath =
|
|
107227
|
-
if (!
|
|
107593
|
+
const fullPath = resolve13(projectRoot, filePath);
|
|
107594
|
+
if (!existsSync123(fullPath)) {
|
|
107228
107595
|
throw new Error(`Output file not found: ${filePath}`);
|
|
107229
107596
|
}
|
|
107230
|
-
const content =
|
|
107597
|
+
const content = readFileSync89(fullPath, "utf-8");
|
|
107231
107598
|
const issues = [];
|
|
107232
107599
|
if (!content.includes("# ")) {
|
|
107233
107600
|
issues.push({
|
|
@@ -107259,11 +107626,11 @@ function coreValidateOutput(filePath, taskId, projectRoot) {
|
|
|
107259
107626
|
};
|
|
107260
107627
|
}
|
|
107261
107628
|
function parseComplianceEntries(projectRoot) {
|
|
107262
|
-
const compliancePath =
|
|
107263
|
-
if (!
|
|
107629
|
+
const compliancePath = join117(projectRoot, ".cleo", "metrics", "COMPLIANCE.jsonl");
|
|
107630
|
+
if (!existsSync123(compliancePath)) {
|
|
107264
107631
|
return [];
|
|
107265
107632
|
}
|
|
107266
|
-
const content =
|
|
107633
|
+
const content = readFileSync89(compliancePath, "utf-8");
|
|
107267
107634
|
const entries = [];
|
|
107268
107635
|
for (const line2 of content.split("\n")) {
|
|
107269
107636
|
const trimmed = line2.trim();
|
|
@@ -107322,10 +107689,10 @@ function coreComplianceRecord(taskId, result, protocol, violations, projectRoot)
|
|
|
107322
107689
|
if (!validResults.includes(result)) {
|
|
107323
107690
|
throw new Error(`Invalid result: ${result}. Valid: ${validResults.join(", ")}`);
|
|
107324
107691
|
}
|
|
107325
|
-
const compliancePath =
|
|
107326
|
-
const dir =
|
|
107327
|
-
if (!
|
|
107328
|
-
|
|
107692
|
+
const compliancePath = join117(projectRoot, ".cleo", "metrics", "COMPLIANCE.jsonl");
|
|
107693
|
+
const dir = dirname25(compliancePath);
|
|
107694
|
+
if (!existsSync123(dir)) {
|
|
107695
|
+
mkdirSync30(dir, { recursive: true });
|
|
107329
107696
|
}
|
|
107330
107697
|
const entry = {
|
|
107331
107698
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -107344,10 +107711,10 @@ function coreComplianceRecord(taskId, result, protocol, violations, projectRoot)
|
|
|
107344
107711
|
};
|
|
107345
107712
|
}
|
|
107346
107713
|
function coreTestStatus(projectRoot) {
|
|
107347
|
-
const testDir =
|
|
107348
|
-
const dispatchTestDir =
|
|
107349
|
-
const hasBatsTests =
|
|
107350
|
-
const hasDispatchTests =
|
|
107714
|
+
const testDir = join117(projectRoot, "tests");
|
|
107715
|
+
const dispatchTestDir = join117(projectRoot, "src", "dispatch", "__tests__");
|
|
107716
|
+
const hasBatsTests = existsSync123(testDir);
|
|
107717
|
+
const hasDispatchTests = existsSync123(dispatchTestDir);
|
|
107351
107718
|
return {
|
|
107352
107719
|
batsTests: {
|
|
107353
107720
|
available: hasBatsTests,
|
|
@@ -107488,8 +107855,8 @@ async function coreCoherenceCheck(projectRoot) {
|
|
|
107488
107855
|
};
|
|
107489
107856
|
}
|
|
107490
107857
|
function coreTestRun(params, projectRoot) {
|
|
107491
|
-
const hasVitest =
|
|
107492
|
-
const hasBats =
|
|
107858
|
+
const hasVitest = existsSync123(join117(projectRoot, "node_modules", ".bin", "vitest"));
|
|
107859
|
+
const hasBats = existsSync123(join117(projectRoot, "tests"));
|
|
107493
107860
|
if (!hasVitest && !hasBats) {
|
|
107494
107861
|
return {
|
|
107495
107862
|
ran: false,
|
|
@@ -107579,8 +107946,8 @@ async function coreBatchValidate(projectRoot) {
|
|
|
107579
107946
|
};
|
|
107580
107947
|
}
|
|
107581
107948
|
function coreTestCoverage(projectRoot) {
|
|
107582
|
-
const coveragePath =
|
|
107583
|
-
if (!
|
|
107949
|
+
const coveragePath = join117(projectRoot, "coverage", "coverage-summary.json");
|
|
107950
|
+
if (!existsSync123(coveragePath)) {
|
|
107584
107951
|
return {
|
|
107585
107952
|
available: false,
|
|
107586
107953
|
message: "No coverage data found. Run tests with coverage first."
|
|
@@ -107598,8 +107965,8 @@ function coreTestCoverage(projectRoot) {
|
|
|
107598
107965
|
|
|
107599
107966
|
// packages/core/src/orchestration/bootstrap.ts
|
|
107600
107967
|
init_data_accessor();
|
|
107601
|
-
import { existsSync as
|
|
107602
|
-
import { join as
|
|
107968
|
+
import { existsSync as existsSync124, readFileSync as readFileSync90 } from "node:fs";
|
|
107969
|
+
import { join as join118 } from "node:path";
|
|
107603
107970
|
async function buildBrainState(projectRoot, opts, accessor) {
|
|
107604
107971
|
const speed = opts?.speed || "fast";
|
|
107605
107972
|
const brain = {
|
|
@@ -107665,9 +108032,9 @@ async function buildBrainState(projectRoot, opts, accessor) {
|
|
|
107665
108032
|
blockedBy: b2.depends || []
|
|
107666
108033
|
}));
|
|
107667
108034
|
try {
|
|
107668
|
-
const decisionLogPath =
|
|
107669
|
-
if (
|
|
107670
|
-
const content =
|
|
108035
|
+
const decisionLogPath = join118(projectRoot, ".cleo", "decision-log.jsonl");
|
|
108036
|
+
if (existsSync124(decisionLogPath)) {
|
|
108037
|
+
const content = readFileSync90(decisionLogPath, "utf-8").trim();
|
|
107671
108038
|
if (content) {
|
|
107672
108039
|
const entries = content.split("\n").filter((l) => l.trim()).map((l) => {
|
|
107673
108040
|
try {
|
|
@@ -107687,9 +108054,9 @@ async function buildBrainState(projectRoot, opts, accessor) {
|
|
|
107687
108054
|
} catch {
|
|
107688
108055
|
}
|
|
107689
108056
|
try {
|
|
107690
|
-
const contextStatePath =
|
|
107691
|
-
if (
|
|
107692
|
-
const state = JSON.parse(
|
|
108057
|
+
const contextStatePath = join118(projectRoot, ".cleo", ".context-state.json");
|
|
108058
|
+
if (existsSync124(contextStatePath)) {
|
|
108059
|
+
const state = JSON.parse(readFileSync90(contextStatePath, "utf-8"));
|
|
107693
108060
|
const percentage = state.contextWindow?.percentage ?? 0;
|
|
107694
108061
|
const factors = [];
|
|
107695
108062
|
if (percentage > 80) factors.push("high_context_usage");
|
|
@@ -108003,22 +108370,22 @@ init_hash();
|
|
|
108003
108370
|
init_scaffold();
|
|
108004
108371
|
init_schema_management();
|
|
108005
108372
|
init_project_detect();
|
|
108006
|
-
import { randomUUID as
|
|
108007
|
-
import { existsSync as
|
|
108008
|
-
import { join as
|
|
108373
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
108374
|
+
import { existsSync as existsSync125, readFileSync as readFileSync91 } from "node:fs";
|
|
108375
|
+
import { join as join119, resolve as resolve14 } from "node:path";
|
|
108009
108376
|
var SQLITE_SCHEMA_VERSION_MIRROR = "2.0.0";
|
|
108010
108377
|
function isContributorProject(projectRoot) {
|
|
108011
|
-
const at2 = (p2) =>
|
|
108378
|
+
const at2 = (p2) => existsSync125(join119(projectRoot, p2));
|
|
108012
108379
|
if (!at2("src/dispatch") || !at2("src/core")) return false;
|
|
108013
108380
|
try {
|
|
108014
|
-
const pkg = JSON.parse(
|
|
108381
|
+
const pkg = JSON.parse(readFileSync91(join119(projectRoot, "package.json"), "utf-8"));
|
|
108015
108382
|
return pkg.name === "@cleocode/cleo";
|
|
108016
108383
|
} catch {
|
|
108017
108384
|
return false;
|
|
108018
108385
|
}
|
|
108019
108386
|
}
|
|
108020
108387
|
function regenerateConfigJson(projectRoot) {
|
|
108021
|
-
const resolvedRoot =
|
|
108388
|
+
const resolvedRoot = resolve14(projectRoot);
|
|
108022
108389
|
const content = createDefaultConfig();
|
|
108023
108390
|
if (isContributorProject(resolvedRoot)) {
|
|
108024
108391
|
content["contributor"] = {
|
|
@@ -108030,7 +108397,7 @@ function regenerateConfigJson(projectRoot) {
|
|
|
108030
108397
|
return { filename: "config.json", content };
|
|
108031
108398
|
}
|
|
108032
108399
|
function regenerateProjectInfoJson(projectRoot) {
|
|
108033
|
-
const resolvedRoot =
|
|
108400
|
+
const resolvedRoot = resolve14(projectRoot);
|
|
108034
108401
|
const projectHash = generateProjectHash(resolvedRoot);
|
|
108035
108402
|
const cleoVersion = getCleoVersion();
|
|
108036
108403
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -108039,7 +108406,7 @@ function regenerateProjectInfoJson(projectRoot) {
|
|
|
108039
108406
|
const content = {
|
|
108040
108407
|
$schema: "./schemas/project-info.schema.json",
|
|
108041
108408
|
schemaVersion: "1.0.0",
|
|
108042
|
-
projectId:
|
|
108409
|
+
projectId: randomUUID11(),
|
|
108043
108410
|
projectHash,
|
|
108044
108411
|
cleoVersion,
|
|
108045
108412
|
lastUpdated: now2,
|
|
@@ -108067,7 +108434,7 @@ function regenerateProjectInfoJson(projectRoot) {
|
|
|
108067
108434
|
return { filename: "project-info.json", content };
|
|
108068
108435
|
}
|
|
108069
108436
|
function regenerateProjectContextJson(projectRoot) {
|
|
108070
|
-
const resolvedRoot =
|
|
108437
|
+
const resolvedRoot = resolve14(projectRoot);
|
|
108071
108438
|
const content = detectProjectType(resolvedRoot);
|
|
108072
108439
|
return { filename: "project-context.json", content };
|
|
108073
108440
|
}
|
|
@@ -108440,13 +108807,13 @@ init_memory_bridge();
|
|
|
108440
108807
|
init_session_memory();
|
|
108441
108808
|
|
|
108442
108809
|
// packages/core/src/nexus/nexus-bridge.ts
|
|
108443
|
-
import { existsSync as
|
|
108444
|
-
import { join as
|
|
108445
|
-
function typedAll4(db,
|
|
108446
|
-
return db.prepare(
|
|
108810
|
+
import { existsSync as existsSync126, mkdirSync as mkdirSync31, readFileSync as readFileSync92, writeFileSync as writeFileSync22 } from "node:fs";
|
|
108811
|
+
import { join as join120 } from "node:path";
|
|
108812
|
+
function typedAll4(db, sql16, ...params) {
|
|
108813
|
+
return db.prepare(sql16).all(...params);
|
|
108447
108814
|
}
|
|
108448
|
-
function typedGet2(db,
|
|
108449
|
-
return db.prepare(
|
|
108815
|
+
function typedGet2(db, sql16, ...params) {
|
|
108816
|
+
return db.prepare(sql16).get(...params);
|
|
108450
108817
|
}
|
|
108451
108818
|
function queryIndexMeta(db, projectId) {
|
|
108452
108819
|
try {
|
|
@@ -108657,22 +109024,22 @@ async function generateNexusBridgeContent(projectId, repoPath) {
|
|
|
108657
109024
|
return lines.join("\n");
|
|
108658
109025
|
}
|
|
108659
109026
|
async function writeNexusBridge(projectRoot, projectId) {
|
|
108660
|
-
const cleoDir =
|
|
108661
|
-
const bridgePath =
|
|
109027
|
+
const cleoDir = join120(projectRoot, ".cleo");
|
|
109028
|
+
const bridgePath = join120(cleoDir, "nexus-bridge.md");
|
|
108662
109029
|
const resolvedProjectId = projectId ?? Buffer.from(projectRoot).toString("base64url").slice(0, 32);
|
|
108663
109030
|
try {
|
|
108664
109031
|
const content = await generateNexusBridgeContent(resolvedProjectId, projectRoot);
|
|
108665
|
-
if (!
|
|
108666
|
-
|
|
109032
|
+
if (!existsSync126(cleoDir)) {
|
|
109033
|
+
mkdirSync31(cleoDir, { recursive: true });
|
|
108667
109034
|
}
|
|
108668
|
-
if (
|
|
108669
|
-
const existing =
|
|
109035
|
+
if (existsSync126(bridgePath)) {
|
|
109036
|
+
const existing = readFileSync92(bridgePath, "utf-8");
|
|
108670
109037
|
const stripDate = (s3) => s3.replace(/^> Date: .*/m, "");
|
|
108671
109038
|
if (stripDate(existing) === stripDate(content)) {
|
|
108672
109039
|
return { path: bridgePath, written: false };
|
|
108673
109040
|
}
|
|
108674
109041
|
}
|
|
108675
|
-
|
|
109042
|
+
writeFileSync22(bridgePath, content, "utf-8");
|
|
108676
109043
|
return { path: bridgePath, written: true };
|
|
108677
109044
|
} catch (err) {
|
|
108678
109045
|
console.error(
|
|
@@ -109092,7 +109459,7 @@ init_global_salt();
|
|
|
109092
109459
|
import { execFileSync as execFileSync13 } from "node:child_process";
|
|
109093
109460
|
import { createCipheriv, createDecipheriv, createHmac, randomBytes as randomBytes16 } from "node:crypto";
|
|
109094
109461
|
import { chmod as chmod2, mkdir as mkdir18, readFile as readFile21, stat as stat2, writeFile as writeFile13 } from "node:fs/promises";
|
|
109095
|
-
import { dirname as
|
|
109462
|
+
import { dirname as dirname26, join as join121 } from "node:path";
|
|
109096
109463
|
var ALGORITHM = "aes-256-gcm";
|
|
109097
109464
|
var IV_LENGTH = 12;
|
|
109098
109465
|
var AUTH_TAG_LENGTH = 16;
|
|
@@ -109101,18 +109468,18 @@ var CIPHERTEXT_VERSION = 1;
|
|
|
109101
109468
|
function getMachineKeyPath() {
|
|
109102
109469
|
if (process.platform === "win32") {
|
|
109103
109470
|
const appData = process.env["LOCALAPPDATA"] ?? process.env["APPDATA"];
|
|
109104
|
-
if (appData) return
|
|
109471
|
+
if (appData) return join121(appData, "cleo", "Data", "machine-key");
|
|
109105
109472
|
} else if (process.platform === "darwin") {
|
|
109106
109473
|
const home = process.env["HOME"];
|
|
109107
|
-
if (home) return
|
|
109474
|
+
if (home) return join121(home, "Library", "Application Support", "cleo", "machine-key");
|
|
109108
109475
|
}
|
|
109109
|
-
const dataHome = process.env["XDG_DATA_HOME"] ??
|
|
109476
|
+
const dataHome = process.env["XDG_DATA_HOME"] ?? join121(process.env["HOME"] ?? "", ".local", "share");
|
|
109110
109477
|
if (!dataHome) {
|
|
109111
109478
|
throw new Error(
|
|
109112
109479
|
"Cannot determine data directory. Set HOME or XDG_DATA_HOME environment variable. Machine key cannot be stored securely without a persistent data directory."
|
|
109113
109480
|
);
|
|
109114
109481
|
}
|
|
109115
|
-
return
|
|
109482
|
+
return join121(dataHome, "cleo", "machine-key");
|
|
109116
109483
|
}
|
|
109117
109484
|
async function getMachineKey() {
|
|
109118
109485
|
const keyPath = getMachineKeyPath();
|
|
@@ -109148,7 +109515,7 @@ async function getMachineKey() {
|
|
|
109148
109515
|
} catch (err) {
|
|
109149
109516
|
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
109150
109517
|
const key = randomBytes16(KEY_LENGTH);
|
|
109151
|
-
await mkdir18(
|
|
109518
|
+
await mkdir18(dirname26(keyPath), { recursive: true });
|
|
109152
109519
|
await writeFile13(keyPath, key, { mode: 384 });
|
|
109153
109520
|
if (process.platform === "win32") {
|
|
109154
109521
|
try {
|
|
@@ -109216,9 +109583,9 @@ async function decrypt(ciphertext, projectPath) {
|
|
|
109216
109583
|
// packages/core/src/store/agent-registry-accessor.ts
|
|
109217
109584
|
init_paths();
|
|
109218
109585
|
import { randomBytes as randomBytes17 } from "node:crypto";
|
|
109219
|
-
import { existsSync as
|
|
109586
|
+
import { existsSync as existsSync127, mkdirSync as mkdirSync32, readFileSync as readFileSync93, statSync as statSync21, writeFileSync as writeFileSync23 } from "node:fs";
|
|
109220
109587
|
import { createRequire as createRequire14 } from "node:module";
|
|
109221
|
-
import { join as
|
|
109588
|
+
import { join as join122 } from "node:path";
|
|
109222
109589
|
|
|
109223
109590
|
// packages/core/src/store/api-key-kdf.ts
|
|
109224
109591
|
import { createHmac as createHmac2 } from "node:crypto";
|
|
@@ -109248,14 +109615,14 @@ var _require14 = createRequire14(import.meta.url);
|
|
|
109248
109615
|
var { DatabaseSync: DatabaseSync9 } = _require14("node:sqlite");
|
|
109249
109616
|
var MACHINE_KEY_LENGTH = 32;
|
|
109250
109617
|
function readMachineKey() {
|
|
109251
|
-
const keyPath =
|
|
109252
|
-
if (!
|
|
109618
|
+
const keyPath = join122(getCleoHome(), "machine-key");
|
|
109619
|
+
if (!existsSync127(keyPath)) {
|
|
109253
109620
|
const cleoHome = getCleoHome();
|
|
109254
|
-
if (!
|
|
109255
|
-
|
|
109621
|
+
if (!existsSync127(cleoHome)) {
|
|
109622
|
+
mkdirSync32(cleoHome, { recursive: true });
|
|
109256
109623
|
}
|
|
109257
109624
|
const key2 = randomBytes17(MACHINE_KEY_LENGTH);
|
|
109258
|
-
|
|
109625
|
+
writeFileSync23(keyPath, key2, { mode: 384 });
|
|
109259
109626
|
return key2;
|
|
109260
109627
|
}
|
|
109261
109628
|
if (process.platform !== "win32") {
|
|
@@ -109267,7 +109634,7 @@ function readMachineKey() {
|
|
|
109267
109634
|
);
|
|
109268
109635
|
}
|
|
109269
109636
|
}
|
|
109270
|
-
const key =
|
|
109637
|
+
const key = readFileSync93(keyPath);
|
|
109271
109638
|
if (key.length !== MACHINE_KEY_LENGTH) {
|
|
109272
109639
|
throw new Error(
|
|
109273
109640
|
`Machine key at ${keyPath} has wrong length: expected ${MACHINE_KEY_LENGTH} bytes, got ${key.length}.`
|
|
@@ -109976,6 +110343,7 @@ export {
|
|
|
109976
110343
|
buildCommanderArgs,
|
|
109977
110344
|
buildCommanderOptionString,
|
|
109978
110345
|
buildConflictReport,
|
|
110346
|
+
buildDiagnosticsReport,
|
|
109979
110347
|
buildDispatchInputSchema,
|
|
109980
110348
|
buildGlobalGraph,
|
|
109981
110349
|
buildMcpInputSchema,
|
|
@@ -110132,7 +110500,9 @@ export {
|
|
|
110132
110500
|
detectVersion2 as detectVersion,
|
|
110133
110501
|
determineInstallationTargets,
|
|
110134
110502
|
diagnoseUpgrade,
|
|
110503
|
+
disableTelemetry,
|
|
110135
110504
|
discoverRelated2 as discoverRelated,
|
|
110505
|
+
enableTelemetry,
|
|
110136
110506
|
encrypt,
|
|
110137
110507
|
encryptBundle,
|
|
110138
110508
|
endParallelExecution,
|
|
@@ -110155,6 +110525,7 @@ export {
|
|
|
110155
110525
|
exportSnapshot,
|
|
110156
110526
|
exportTasks,
|
|
110157
110527
|
exportTasksPackage,
|
|
110528
|
+
exportTelemetryEvents,
|
|
110158
110529
|
externalLinkTypeSchema,
|
|
110159
110530
|
externalTaskLinks,
|
|
110160
110531
|
extractFromTranscript2 as extractFromTranscript,
|
|
@@ -110298,6 +110669,8 @@ export {
|
|
|
110298
110669
|
getTask,
|
|
110299
110670
|
getTaskHistory,
|
|
110300
110671
|
getTaskPath,
|
|
110672
|
+
getTelemetryConfigPath,
|
|
110673
|
+
getTelemetryDbPath,
|
|
110301
110674
|
getTemplateForSubcommand2 as getTemplateForSubcommand,
|
|
110302
110675
|
getUnblockOpportunities,
|
|
110303
110676
|
getVersion2 as getVersion,
|
|
@@ -110351,6 +110724,7 @@ export {
|
|
|
110351
110724
|
isProviderHookEvent,
|
|
110352
110725
|
isRecoverableCode,
|
|
110353
110726
|
isSuccessCode,
|
|
110727
|
+
isTelemetryEnabled,
|
|
110354
110728
|
isTreeSitterAvailable3 as isTreeSitterAvailable,
|
|
110355
110729
|
isValidStage,
|
|
110356
110730
|
isValidStatus,
|
|
@@ -110391,6 +110765,7 @@ export {
|
|
|
110391
110765
|
extractFromTranscript as llmExtractFromTranscript,
|
|
110392
110766
|
loadConfig,
|
|
110393
110767
|
loadReleaseConfig,
|
|
110768
|
+
loadTelemetryConfig,
|
|
110394
110769
|
lookupAgent,
|
|
110395
110770
|
manifestStatusSchema,
|
|
110396
110771
|
mapCodebase,
|
|
@@ -110448,6 +110823,7 @@ export {
|
|
|
110448
110823
|
nexusSync,
|
|
110449
110824
|
nexusSyncAll,
|
|
110450
110825
|
nexusUnregister,
|
|
110826
|
+
nexusUpdateIndexStats,
|
|
110451
110827
|
normalizeError,
|
|
110452
110828
|
normalizeTaskId,
|
|
110453
110829
|
observability_exports as observability,
|
|
@@ -110510,6 +110886,7 @@ export {
|
|
|
110510
110886
|
recordFailurePattern,
|
|
110511
110887
|
recordHeartbeat,
|
|
110512
110888
|
recordStageProgress,
|
|
110889
|
+
recordTelemetryEvent,
|
|
110513
110890
|
recordTokenExchange,
|
|
110514
110891
|
recoverCrashedAgents,
|
|
110515
110892
|
refreshMemoryBridge,
|
|
@@ -110632,6 +111009,7 @@ export {
|
|
|
110632
111009
|
taskTypeSchema,
|
|
110633
111010
|
task_work_exports as taskWork,
|
|
110634
111011
|
tasks,
|
|
111012
|
+
telemetry_exports as telemetry,
|
|
110635
111013
|
templates_exports as templates,
|
|
110636
111014
|
timelineBrain,
|
|
110637
111015
|
toCompact,
|