@edihasaj/recall 0.8.4 → 0.8.6
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/{chunk-VG3MKOXJ.js → chunk-4VBHVY3D.js} +3 -3
- package/dist/{chunk-JAOWDQG4.js → chunk-A4ES3H4Y.js} +2 -2
- package/dist/{chunk-ICG6DSO4.js → chunk-BHTIIKRB.js} +4 -4
- package/dist/{chunk-U2VFIJ3S.js → chunk-BJTLWRZH.js} +2 -2
- package/dist/{chunk-MD2A3WQ3.js → chunk-BUUVZQEV.js} +7 -7
- package/dist/{chunk-PSJ3YWEV.js → chunk-DYAQ4RKX.js} +5 -5
- package/dist/{chunk-I2DRSMD2.js → chunk-EYMC2PDI.js} +2 -2
- package/dist/{chunk-DZHYYRCM.js → chunk-G5IAOZAL.js} +25 -1
- package/dist/chunk-G5IAOZAL.js.map +1 -0
- package/dist/{chunk-OAZPBXRV.js → chunk-OR6VZZI6.js} +3 -3
- package/dist/{chunk-2E34372Y.js → chunk-QJTP6OIZ.js} +532 -598
- package/dist/chunk-QJTP6OIZ.js.map +1 -0
- package/dist/{chunk-3Z6IBPRZ.js → chunk-SAVLATC5.js} +24 -4
- package/dist/chunk-SAVLATC5.js.map +1 -0
- package/dist/{chunk-XYGS5CQU.js → chunk-V4UAYWKI.js} +22 -10
- package/dist/chunk-V4UAYWKI.js.map +1 -0
- package/dist/chunk-WC7S7BOP.js +328 -0
- package/dist/chunk-WC7S7BOP.js.map +1 -0
- package/dist/{cleanup-LAPA52UR.js → cleanup-MPSAZNDH.js} +6 -6
- package/dist/cli.js +47 -30
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +13 -12
- package/dist/daemon.js.map +1 -1
- package/dist/{dispatcher-VUTOVBS4.js → dispatcher-RCCPGNDO.js} +6 -6
- package/dist/{embeddings-OEKBWLMK.js → embeddings-MNNECV6B.js} +3 -3
- package/dist/{ingest-KKJFZUPZ.js → ingest-KVLFQ6J7.js} +6 -6
- package/dist/mcp.js +10 -9
- package/dist/mcp.js.map +1 -1
- package/dist/{quality-6PPLSMMN.js → quality-OXFQ7JXM.js} +8 -4
- package/dist/retrieval-27YV546Y.js +13 -0
- package/dist/{store-2OU73NXB.js → store-KU5H2RA2.js} +3 -3
- package/dist/{tasks-NJL2P26Y.js → tasks-SCYA2PJJ.js} +6 -6
- package/dist/{usage-H54D63YI.js → usage-VVXTCJHT.js} +3 -3
- package/drizzle/0009_memory_value_events.sql +23 -0
- package/drizzle/meta/_journal.json +8 -1
- package/package.json +1 -1
- package/dist/chunk-2E34372Y.js.map +0 -1
- package/dist/chunk-3Z6IBPRZ.js.map +0 -1
- package/dist/chunk-DZHYYRCM.js.map +0 -1
- package/dist/chunk-XYGS5CQU.js.map +0 -1
- package/dist/retrieval-T35UHKSO.js +0 -13
- /package/dist/{chunk-VG3MKOXJ.js.map → chunk-4VBHVY3D.js.map} +0 -0
- /package/dist/{chunk-JAOWDQG4.js.map → chunk-A4ES3H4Y.js.map} +0 -0
- /package/dist/{chunk-ICG6DSO4.js.map → chunk-BHTIIKRB.js.map} +0 -0
- /package/dist/{chunk-U2VFIJ3S.js.map → chunk-BJTLWRZH.js.map} +0 -0
- /package/dist/{chunk-MD2A3WQ3.js.map → chunk-BUUVZQEV.js.map} +0 -0
- /package/dist/{chunk-PSJ3YWEV.js.map → chunk-DYAQ4RKX.js.map} +0 -0
- /package/dist/{chunk-I2DRSMD2.js.map → chunk-EYMC2PDI.js.map} +0 -0
- /package/dist/{chunk-OAZPBXRV.js.map → chunk-OR6VZZI6.js.map} +0 -0
- /package/dist/{cleanup-LAPA52UR.js.map → cleanup-MPSAZNDH.js.map} +0 -0
- /package/dist/{dispatcher-VUTOVBS4.js.map → dispatcher-RCCPGNDO.js.map} +0 -0
- /package/dist/{embeddings-OEKBWLMK.js.map → embeddings-MNNECV6B.js.map} +0 -0
- /package/dist/{ingest-KKJFZUPZ.js.map → ingest-KVLFQ6J7.js.map} +0 -0
- /package/dist/{quality-6PPLSMMN.js.map → quality-OXFQ7JXM.js.map} +0 -0
- /package/dist/{retrieval-T35UHKSO.js.map → retrieval-27YV546Y.js.map} +0 -0
- /package/dist/{store-2OU73NXB.js.map → store-KU5H2RA2.js.map} +0 -0
- /package/dist/{tasks-NJL2P26Y.js.map → tasks-SCYA2PJJ.js.map} +0 -0
- /package/dist/{usage-H54D63YI.js.map → usage-VVXTCJHT.js.map} +0 -0
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
recordInjectionValueEvents,
|
|
3
|
+
recordMemoryInjections,
|
|
4
|
+
recordOutcomeValueEvent,
|
|
5
|
+
resolveMemoryInjectionOutcome
|
|
6
|
+
} from "./chunk-WC7S7BOP.js";
|
|
1
7
|
import {
|
|
2
8
|
computeHealthScore,
|
|
3
9
|
getRepoQualityProfile,
|
|
@@ -5,7 +11,7 @@ import {
|
|
|
5
11
|
recordAudit,
|
|
6
12
|
redactSensitiveValue,
|
|
7
13
|
seedScannedConfidence
|
|
8
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-DYAQ4RKX.js";
|
|
9
15
|
import {
|
|
10
16
|
activityEventDedupeKey,
|
|
11
17
|
confirmMemory,
|
|
@@ -20,11 +26,11 @@ import {
|
|
|
20
26
|
recordFeedback,
|
|
21
27
|
rejectMemory,
|
|
22
28
|
statusFromConfidence
|
|
23
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-4VBHVY3D.js";
|
|
24
30
|
import {
|
|
25
31
|
asc,
|
|
26
32
|
desc
|
|
27
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-BJTLWRZH.js";
|
|
28
34
|
import {
|
|
29
35
|
CONFIDENCE,
|
|
30
36
|
RetrievalEvalCase,
|
|
@@ -40,7 +46,7 @@ import {
|
|
|
40
46
|
queueMemoryEmbeddingSync,
|
|
41
47
|
resolveProvider,
|
|
42
48
|
tagActivitySource
|
|
43
|
-
} from "./chunk-
|
|
49
|
+
} from "./chunk-A4ES3H4Y.js";
|
|
44
50
|
import {
|
|
45
51
|
Column,
|
|
46
52
|
Columns,
|
|
@@ -88,7 +94,6 @@ import {
|
|
|
88
94
|
mapResultRow,
|
|
89
95
|
mapUpdateSet,
|
|
90
96
|
memories,
|
|
91
|
-
memoryInjections,
|
|
92
97
|
memoryMaintenanceTasks,
|
|
93
98
|
ne,
|
|
94
99
|
not,
|
|
@@ -102,7 +107,7 @@ import {
|
|
|
102
107
|
policyRules,
|
|
103
108
|
schema_exports,
|
|
104
109
|
sql
|
|
105
|
-
} from "./chunk-
|
|
110
|
+
} from "./chunk-G5IAOZAL.js";
|
|
106
111
|
|
|
107
112
|
// src/db/client.ts
|
|
108
113
|
import Database from "better-sqlite3";
|
|
@@ -3554,7 +3559,7 @@ import { join, dirname } from "path";
|
|
|
3554
3559
|
import { mkdirSync, existsSync, rmSync, statSync } from "fs";
|
|
3555
3560
|
import { fileURLToPath } from "url";
|
|
3556
3561
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
3557
|
-
var RECALL_DB_USER_VERSION =
|
|
3562
|
+
var RECALL_DB_USER_VERSION = 10;
|
|
3558
3563
|
function getDbPath() {
|
|
3559
3564
|
const dataDir = process.env.RECALL_DATA_DIR ?? join(
|
|
3560
3565
|
process.env.HOME ?? process.env.USERPROFILE ?? ".",
|
|
@@ -3615,7 +3620,7 @@ function getDb(dbPath) {
|
|
|
3615
3620
|
}
|
|
3616
3621
|
function migrateIfNeeded(db) {
|
|
3617
3622
|
const current = Number(db.$client.pragma("user_version", { simple: true }) ?? 0);
|
|
3618
|
-
if (current
|
|
3623
|
+
if (current >= RECALL_DB_USER_VERSION) return;
|
|
3619
3624
|
migrate(db, { migrationsFolder: getMigrationsPath() });
|
|
3620
3625
|
setDbUserVersion(db.$client);
|
|
3621
3626
|
}
|
|
@@ -3658,6 +3663,124 @@ function resetDb(dbPath, options = {}) {
|
|
|
3658
3663
|
}
|
|
3659
3664
|
}
|
|
3660
3665
|
|
|
3666
|
+
// src/models/activity.ts
|
|
3667
|
+
import { randomUUID } from "crypto";
|
|
3668
|
+
function createActivityEvent(db, input) {
|
|
3669
|
+
const safeInput = {
|
|
3670
|
+
...input,
|
|
3671
|
+
request: redactSensitiveValue(input.request ?? {}),
|
|
3672
|
+
result: redactSensitiveValue(input.result ?? {})
|
|
3673
|
+
};
|
|
3674
|
+
const dedupeKey = activityEventDedupeKey(safeInput);
|
|
3675
|
+
if (dedupeKey) {
|
|
3676
|
+
const existingId = findActivityEventByDedupeKey(db, dedupeKey);
|
|
3677
|
+
if (existingId) return existingId;
|
|
3678
|
+
} else {
|
|
3679
|
+
const fuzzyId = findRecentDuplicateActivityEvent(db, safeInput);
|
|
3680
|
+
if (fuzzyId) return fuzzyId;
|
|
3681
|
+
}
|
|
3682
|
+
const id = randomUUID();
|
|
3683
|
+
const result = db.insert(activityEvents).values({
|
|
3684
|
+
id,
|
|
3685
|
+
session_id: safeInput.session_id ?? null,
|
|
3686
|
+
repo: safeInput.repo ?? null,
|
|
3687
|
+
path: safeInput.path ?? null,
|
|
3688
|
+
source: safeInput.source,
|
|
3689
|
+
event_type: safeInput.event_type,
|
|
3690
|
+
memory_ids: safeInput.memory_ids ?? [],
|
|
3691
|
+
dedupe_key: dedupeKey,
|
|
3692
|
+
request: safeInput.request,
|
|
3693
|
+
result: safeInput.result,
|
|
3694
|
+
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3695
|
+
}).onConflictDoNothing({ target: activityEvents.dedupe_key }).run();
|
|
3696
|
+
if (Number(result.changes ?? 0) === 0 && dedupeKey) {
|
|
3697
|
+
const existingId = findActivityEventByDedupeKey(db, dedupeKey);
|
|
3698
|
+
if (existingId) return existingId;
|
|
3699
|
+
}
|
|
3700
|
+
return id;
|
|
3701
|
+
}
|
|
3702
|
+
function findActivityEventByDedupeKey(db, dedupeKey) {
|
|
3703
|
+
const row = db.select({ id: activityEvents.id }).from(activityEvents).where(eq(activityEvents.dedupe_key, dedupeKey)).get();
|
|
3704
|
+
return row?.id ?? null;
|
|
3705
|
+
}
|
|
3706
|
+
function findRecentDuplicateActivityEvent(db, input) {
|
|
3707
|
+
if (!input.session_id) return null;
|
|
3708
|
+
const since = new Date(Date.now() - 2e3).toISOString();
|
|
3709
|
+
const rows = db.select().from(activityEvents).where(and(
|
|
3710
|
+
eq(activityEvents.session_id, input.session_id),
|
|
3711
|
+
eq(activityEvents.source, input.source),
|
|
3712
|
+
eq(activityEvents.event_type, input.event_type),
|
|
3713
|
+
gte(activityEvents.created_at, since)
|
|
3714
|
+
)).all();
|
|
3715
|
+
const requestKey = JSON.stringify(input.request ?? {});
|
|
3716
|
+
const resultKey = JSON.stringify(input.result ?? {});
|
|
3717
|
+
const repo = input.repo ?? null;
|
|
3718
|
+
const path = input.path ?? null;
|
|
3719
|
+
for (const row of rows) {
|
|
3720
|
+
if (row.repo !== repo || row.path !== path) continue;
|
|
3721
|
+
const request = typeof row.request === "string" ? JSON.parse(row.request) : row.request ?? {};
|
|
3722
|
+
const result = typeof row.result === "string" ? JSON.parse(row.result) : row.result ?? {};
|
|
3723
|
+
if (JSON.stringify(request) === requestKey && JSON.stringify(result) === resultKey) {
|
|
3724
|
+
return row.id;
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
return null;
|
|
3728
|
+
}
|
|
3729
|
+
function listActivityEvents(db, query = {}) {
|
|
3730
|
+
const conditions = [];
|
|
3731
|
+
if (query.repo) conditions.push(eq(activityEvents.repo, query.repo));
|
|
3732
|
+
if (query.session_id) conditions.push(eq(activityEvents.session_id, query.session_id));
|
|
3733
|
+
if (query.source) conditions.push(eq(activityEvents.source, query.source));
|
|
3734
|
+
if (query.event_type) conditions.push(eq(activityEvents.event_type, query.event_type));
|
|
3735
|
+
if (query.since) conditions.push(gte(activityEvents.created_at, query.since));
|
|
3736
|
+
const offset = query.offset ?? 0;
|
|
3737
|
+
const limit = query.limit ?? 1e3;
|
|
3738
|
+
const base = db.select().from(activityEvents);
|
|
3739
|
+
const ordered = conditions.length > 0 ? base.where(and(...conditions)).orderBy(desc(activityEvents.created_at)) : base.orderBy(desc(activityEvents.created_at));
|
|
3740
|
+
const rows = ordered.limit(limit).offset(offset).all();
|
|
3741
|
+
return rows.map(rowToActivityEvent);
|
|
3742
|
+
}
|
|
3743
|
+
function listActivitySessions(db, query = {}) {
|
|
3744
|
+
const events = listActivityEvents(db, query).filter((event) => event.session_id);
|
|
3745
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
3746
|
+
for (const event of events) {
|
|
3747
|
+
const sessionId = event.session_id;
|
|
3748
|
+
const bucket = grouped.get(sessionId) ?? [];
|
|
3749
|
+
bucket.push(event);
|
|
3750
|
+
grouped.set(sessionId, bucket);
|
|
3751
|
+
}
|
|
3752
|
+
const sessions = [...grouped.entries()].map(([session_id, items]) => {
|
|
3753
|
+
const sorted = [...items].sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
3754
|
+
return {
|
|
3755
|
+
session_id,
|
|
3756
|
+
repo: sorted[0]?.repo ?? null,
|
|
3757
|
+
event_count: items.length,
|
|
3758
|
+
event_types: [...new Set(items.map((item) => item.event_type))],
|
|
3759
|
+
first_at: sorted[0].created_at,
|
|
3760
|
+
last_at: sorted[sorted.length - 1].created_at
|
|
3761
|
+
};
|
|
3762
|
+
});
|
|
3763
|
+
sessions.sort((a, b) => b.last_at.localeCompare(a.last_at));
|
|
3764
|
+
return query.limit ? sessions.slice(0, query.limit) : sessions;
|
|
3765
|
+
}
|
|
3766
|
+
function rowToActivityEvent(row) {
|
|
3767
|
+
const memory_ids = typeof row.memory_ids === "string" ? JSON.parse(row.memory_ids) : Array.isArray(row.memory_ids) ? row.memory_ids : [];
|
|
3768
|
+
const request = typeof row.request === "string" ? JSON.parse(row.request) : row.request ?? {};
|
|
3769
|
+
const result = typeof row.result === "string" ? JSON.parse(row.result) : row.result ?? {};
|
|
3770
|
+
return {
|
|
3771
|
+
id: row.id,
|
|
3772
|
+
session_id: row.session_id,
|
|
3773
|
+
repo: row.repo,
|
|
3774
|
+
path: row.path,
|
|
3775
|
+
source: row.source,
|
|
3776
|
+
event_type: row.event_type,
|
|
3777
|
+
memory_ids,
|
|
3778
|
+
request,
|
|
3779
|
+
result,
|
|
3780
|
+
created_at: row.created_at
|
|
3781
|
+
};
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3661
3784
|
// src/scanner/repo.ts
|
|
3662
3785
|
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
3663
3786
|
import { join as join2, basename } from "path";
|
|
@@ -4059,93 +4182,265 @@ function makeGotcha(text, repo, file) {
|
|
|
4059
4182
|
};
|
|
4060
4183
|
}
|
|
4061
4184
|
|
|
4062
|
-
// src/
|
|
4063
|
-
import {
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
const conditions = [];
|
|
4089
|
-
if (query.repo) conditions.push(eq(historySnippets.repo, query.repo));
|
|
4090
|
-
if (query.session_id) conditions.push(eq(historySnippets.session_id, query.session_id));
|
|
4091
|
-
if (query.kind) conditions.push(eq(historySnippets.kind, query.kind));
|
|
4092
|
-
let stmt = db.select().from(historySnippets).$dynamic();
|
|
4093
|
-
if (conditions.length > 0) {
|
|
4094
|
-
stmt = stmt.where(and(...conditions));
|
|
4185
|
+
// src/repo/discovery.ts
|
|
4186
|
+
import { existsSync as existsSync3, readdirSync } from "fs";
|
|
4187
|
+
import { execFileSync } from "child_process";
|
|
4188
|
+
import { join as join3, resolve } from "path";
|
|
4189
|
+
var repoPathCache = /* @__PURE__ */ new Map();
|
|
4190
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
4191
|
+
".git",
|
|
4192
|
+
"node_modules",
|
|
4193
|
+
"dist",
|
|
4194
|
+
"build",
|
|
4195
|
+
"coverage",
|
|
4196
|
+
".next",
|
|
4197
|
+
".turbo",
|
|
4198
|
+
".venv",
|
|
4199
|
+
"venv"
|
|
4200
|
+
]);
|
|
4201
|
+
function ensureRepoBootstrapped(db, opts) {
|
|
4202
|
+
const repo = normalizeRepoSlug(opts.repo);
|
|
4203
|
+
const repoPathHint = opts.repoPathHint ?? null;
|
|
4204
|
+
if (!repo && !repoPathHint) {
|
|
4205
|
+
return {
|
|
4206
|
+
repo: null,
|
|
4207
|
+
repo_path: null,
|
|
4208
|
+
created_ids: [],
|
|
4209
|
+
status: "skipped"
|
|
4210
|
+
};
|
|
4095
4211
|
}
|
|
4096
|
-
|
|
4097
|
-
if (
|
|
4098
|
-
|
|
4212
|
+
const resolvedRepo = repo ?? inferRepoSlugFromPath(repoPathHint);
|
|
4213
|
+
if (!resolvedRepo) {
|
|
4214
|
+
return {
|
|
4215
|
+
repo: null,
|
|
4216
|
+
repo_path: null,
|
|
4217
|
+
created_ids: [],
|
|
4218
|
+
status: "unresolved"
|
|
4219
|
+
};
|
|
4099
4220
|
}
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
eq(historySnippets.repo, repo),
|
|
4112
|
-
eq(historySnippets.kind, kind)
|
|
4113
|
-
)).get();
|
|
4114
|
-
return row ? rowToHistorySnippet(row) : void 0;
|
|
4115
|
-
}
|
|
4116
|
-
function updateHistorySnippet(db, id, updates) {
|
|
4117
|
-
const current = getHistorySnippet(db, id);
|
|
4118
|
-
if (!current) return;
|
|
4119
|
-
const nextText = updates.text ?? current.text;
|
|
4120
|
-
const dedupeKey = historySnippetDedupeKey({
|
|
4121
|
-
repo: current.repo,
|
|
4122
|
-
session_id: current.session_id,
|
|
4123
|
-
kind: current.kind,
|
|
4124
|
-
text: nextText
|
|
4221
|
+
if (queryMemories(db, { repo: resolvedRepo }).length > 0) {
|
|
4222
|
+
return {
|
|
4223
|
+
repo: resolvedRepo,
|
|
4224
|
+
repo_path: null,
|
|
4225
|
+
created_ids: [],
|
|
4226
|
+
status: "already_known"
|
|
4227
|
+
};
|
|
4228
|
+
}
|
|
4229
|
+
const repoPath = resolveLocalRepoPath(resolvedRepo, {
|
|
4230
|
+
repoPathHint,
|
|
4231
|
+
searchRoots: opts.searchRoots
|
|
4125
4232
|
});
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
}
|
|
4134
|
-
|
|
4135
|
-
function rowToHistorySnippet(row) {
|
|
4136
|
-
const sourceActivityIds = typeof row.source_activity_ids === "string" ? JSON.parse(row.source_activity_ids) : Array.isArray(row.source_activity_ids) ? row.source_activity_ids : [];
|
|
4233
|
+
if (!repoPath) {
|
|
4234
|
+
return {
|
|
4235
|
+
repo: resolvedRepo,
|
|
4236
|
+
repo_path: null,
|
|
4237
|
+
created_ids: [],
|
|
4238
|
+
status: "unresolved"
|
|
4239
|
+
};
|
|
4240
|
+
}
|
|
4241
|
+
const createdIds = scanAndStore(db, repoPath);
|
|
4137
4242
|
return {
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4243
|
+
repo: resolvedRepo,
|
|
4244
|
+
repo_path: repoPath,
|
|
4245
|
+
created_ids: createdIds,
|
|
4246
|
+
status: createdIds.length > 0 ? "bootstrapped" : "scanned_empty"
|
|
4247
|
+
};
|
|
4248
|
+
}
|
|
4249
|
+
function resolveLocalRepoPath(repo, opts = {}) {
|
|
4250
|
+
const normalizedRepo = normalizeRepoSlug(repo);
|
|
4251
|
+
if (!normalizedRepo) return null;
|
|
4252
|
+
if (repoPathCache.has(normalizedRepo)) {
|
|
4253
|
+
return repoPathCache.get(normalizedRepo) ?? null;
|
|
4254
|
+
}
|
|
4255
|
+
const directHint = normalizeRepoPathHint(opts.repoPathHint);
|
|
4256
|
+
if (directHint && pathMatchesRepo(directHint, normalizedRepo)) {
|
|
4257
|
+
repoPathCache.set(normalizedRepo, directHint);
|
|
4258
|
+
return directHint;
|
|
4259
|
+
}
|
|
4260
|
+
const candidates = collectCandidateRepos(opts.searchRoots ?? getDefaultSearchRoots());
|
|
4261
|
+
const basenameMatches = [];
|
|
4262
|
+
for (const candidate of candidates) {
|
|
4263
|
+
const candidateRepo = inferRepoSlugFromPath(candidate);
|
|
4264
|
+
if (candidateRepo === normalizedRepo) {
|
|
4265
|
+
repoPathCache.set(normalizedRepo, candidate);
|
|
4266
|
+
return candidate;
|
|
4267
|
+
}
|
|
4268
|
+
if (candidate.endsWith(`/${normalizedRepo.split("/").at(-1)}`)) {
|
|
4269
|
+
basenameMatches.push(candidate);
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
const fallback = basenameMatches.length === 1 ? basenameMatches[0] : null;
|
|
4273
|
+
repoPathCache.set(normalizedRepo, fallback);
|
|
4274
|
+
return fallback;
|
|
4275
|
+
}
|
|
4276
|
+
function inferRepoSlugFromPath(repoPath) {
|
|
4277
|
+
const root = normalizeRepoPathHint(repoPath);
|
|
4278
|
+
if (!root) return null;
|
|
4279
|
+
try {
|
|
4280
|
+
const remote = execFileSync(
|
|
4281
|
+
"git",
|
|
4282
|
+
["-C", root, "remote", "get-url", "origin"],
|
|
4283
|
+
{ encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }
|
|
4284
|
+
).trim();
|
|
4285
|
+
return extractRepoSlugFromRemote2(remote);
|
|
4286
|
+
} catch {
|
|
4287
|
+
const parts = root.split("/").filter(Boolean);
|
|
4288
|
+
return parts.at(-1) ?? null;
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
function extractRepoSlugFromRemote2(remote) {
|
|
4292
|
+
const trimmed = remote.trim().replace(/\.git$/, "");
|
|
4293
|
+
const parts = trimmed.split(/[:/]/).filter(Boolean);
|
|
4294
|
+
if (parts.length < 2) return null;
|
|
4295
|
+
return `${parts.at(-2)}/${parts.at(-1)}`;
|
|
4296
|
+
}
|
|
4297
|
+
function pathMatchesRepo(repoPath, repo) {
|
|
4298
|
+
const inferred = inferRepoSlugFromPath(repoPath);
|
|
4299
|
+
if (inferred === repo) return true;
|
|
4300
|
+
return repoPath.endsWith(`/${repo.split("/").at(-1)}`);
|
|
4301
|
+
}
|
|
4302
|
+
function normalizeRepoSlug(repo) {
|
|
4303
|
+
if (!repo) return null;
|
|
4304
|
+
const trimmed = repo.trim().replace(/\.git$/, "").replace(/^https?:\/\/[^/]+\//, "");
|
|
4305
|
+
if (!trimmed.includes("/")) return null;
|
|
4306
|
+
return trimmed.replace(/^git@[^:]+:/, "");
|
|
4307
|
+
}
|
|
4308
|
+
function normalizeRepoPathHint(repoPath) {
|
|
4309
|
+
if (!repoPath) return null;
|
|
4310
|
+
const expanded = repoPath.trim().replace(/^~(?=\/)/, process.env.HOME ?? "~");
|
|
4311
|
+
try {
|
|
4312
|
+
const root = execFileSync(
|
|
4313
|
+
"git",
|
|
4314
|
+
["-C", expanded, "rev-parse", "--show-toplevel"],
|
|
4315
|
+
{ encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }
|
|
4316
|
+
).trim();
|
|
4317
|
+
return root || null;
|
|
4318
|
+
} catch {
|
|
4319
|
+
const resolved = resolve(expanded);
|
|
4320
|
+
return existsSync3(join3(resolved, ".git")) ? resolved : null;
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
function getDefaultSearchRoots() {
|
|
4324
|
+
const configured = process.env.RECALL_REPO_ROOTS?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
4325
|
+
if (configured?.length) return configured;
|
|
4326
|
+
const home = process.env.HOME ?? process.cwd();
|
|
4327
|
+
return [join3(home, "Projects")];
|
|
4328
|
+
}
|
|
4329
|
+
function collectCandidateRepos(searchRoots) {
|
|
4330
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4331
|
+
const repos = [];
|
|
4332
|
+
for (const root of searchRoots) {
|
|
4333
|
+
walkRepos(resolve(root), 4, seen, repos);
|
|
4334
|
+
}
|
|
4335
|
+
return repos;
|
|
4336
|
+
}
|
|
4337
|
+
function walkRepos(dir, depthRemaining, seen, repos) {
|
|
4338
|
+
if (depthRemaining < 0 || seen.has(dir) || !existsSync3(dir)) return;
|
|
4339
|
+
seen.add(dir);
|
|
4340
|
+
if (existsSync3(join3(dir, ".git"))) {
|
|
4341
|
+
repos.push(dir);
|
|
4342
|
+
return;
|
|
4343
|
+
}
|
|
4344
|
+
let entries;
|
|
4345
|
+
try {
|
|
4346
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
4347
|
+
} catch {
|
|
4348
|
+
return;
|
|
4349
|
+
}
|
|
4350
|
+
for (const entry of entries) {
|
|
4351
|
+
if (!entry.isDirectory()) continue;
|
|
4352
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
4353
|
+
walkRepos(join3(dir, entry.name), depthRemaining - 1, seen, repos);
|
|
4354
|
+
}
|
|
4355
|
+
}
|
|
4356
|
+
|
|
4357
|
+
// src/history/snippets.ts
|
|
4358
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
4359
|
+
function createHistorySnippet(db, input) {
|
|
4360
|
+
const dedupeKey = historySnippetDedupeKey(input);
|
|
4361
|
+
const existing = db.select().from(historySnippets).where(eq(historySnippets.dedupe_key, dedupeKey)).get();
|
|
4362
|
+
if (existing) return existing.id;
|
|
4363
|
+
const id = randomUUID2();
|
|
4364
|
+
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
4365
|
+
db.insert(historySnippets).values({
|
|
4366
|
+
id,
|
|
4367
|
+
repo: input.repo ?? null,
|
|
4368
|
+
session_id: input.session_id ?? null,
|
|
4369
|
+
kind: input.kind,
|
|
4370
|
+
text: input.text,
|
|
4371
|
+
dedupe_key: dedupeKey,
|
|
4372
|
+
source_activity_ids: input.source_activity_ids ?? [],
|
|
4373
|
+
created_at: now2,
|
|
4374
|
+
updated_at: now2
|
|
4375
|
+
}).run();
|
|
4376
|
+
return id;
|
|
4377
|
+
}
|
|
4378
|
+
function getHistorySnippet(db, id) {
|
|
4379
|
+
const row = db.select().from(historySnippets).where(eq(historySnippets.id, id)).get();
|
|
4380
|
+
return row ? rowToHistorySnippet(row) : void 0;
|
|
4381
|
+
}
|
|
4382
|
+
function listHistorySnippets(db, query = {}) {
|
|
4383
|
+
const conditions = [];
|
|
4384
|
+
if (query.repo) conditions.push(eq(historySnippets.repo, query.repo));
|
|
4385
|
+
if (query.session_id) conditions.push(eq(historySnippets.session_id, query.session_id));
|
|
4386
|
+
if (query.kind) conditions.push(eq(historySnippets.kind, query.kind));
|
|
4387
|
+
let stmt = db.select().from(historySnippets).$dynamic();
|
|
4388
|
+
if (conditions.length > 0) {
|
|
4389
|
+
stmt = stmt.where(and(...conditions));
|
|
4390
|
+
}
|
|
4391
|
+
stmt = stmt.orderBy(desc(historySnippets.updated_at));
|
|
4392
|
+
if (query.limit != null) {
|
|
4393
|
+
stmt = stmt.limit(query.limit);
|
|
4394
|
+
}
|
|
4395
|
+
return stmt.all().map(rowToHistorySnippet);
|
|
4396
|
+
}
|
|
4397
|
+
function findHistorySnippetBySession(db, sessionId, kind = "session_summary") {
|
|
4398
|
+
const row = db.select().from(historySnippets).where(and(
|
|
4399
|
+
eq(historySnippets.session_id, sessionId),
|
|
4400
|
+
eq(historySnippets.kind, kind)
|
|
4401
|
+
)).get();
|
|
4402
|
+
return row ? rowToHistorySnippet(row) : void 0;
|
|
4403
|
+
}
|
|
4404
|
+
function findHistorySnippetByRepoKind(db, repo, kind) {
|
|
4405
|
+
const row = db.select().from(historySnippets).where(and(
|
|
4406
|
+
eq(historySnippets.repo, repo),
|
|
4407
|
+
eq(historySnippets.kind, kind)
|
|
4408
|
+
)).get();
|
|
4409
|
+
return row ? rowToHistorySnippet(row) : void 0;
|
|
4410
|
+
}
|
|
4411
|
+
function updateHistorySnippet(db, id, updates) {
|
|
4412
|
+
const current = getHistorySnippet(db, id);
|
|
4413
|
+
if (!current) return;
|
|
4414
|
+
const nextText = updates.text ?? current.text;
|
|
4415
|
+
const dedupeKey = historySnippetDedupeKey({
|
|
4416
|
+
repo: current.repo,
|
|
4417
|
+
session_id: current.session_id,
|
|
4418
|
+
kind: current.kind,
|
|
4419
|
+
text: nextText
|
|
4420
|
+
});
|
|
4421
|
+
const collision = db.select().from(historySnippets).where(eq(historySnippets.dedupe_key, dedupeKey)).get();
|
|
4422
|
+
if (collision && collision.id !== id) return;
|
|
4423
|
+
db.update(historySnippets).set({
|
|
4424
|
+
...updates.text != null ? { text: updates.text } : {},
|
|
4425
|
+
dedupe_key: dedupeKey,
|
|
4426
|
+
...updates.source_activity_ids ? { source_activity_ids: updates.source_activity_ids } : {},
|
|
4427
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
4428
|
+
}).where(eq(historySnippets.id, id)).run();
|
|
4429
|
+
}
|
|
4430
|
+
function rowToHistorySnippet(row) {
|
|
4431
|
+
const sourceActivityIds = typeof row.source_activity_ids === "string" ? JSON.parse(row.source_activity_ids) : Array.isArray(row.source_activity_ids) ? row.source_activity_ids : [];
|
|
4432
|
+
return {
|
|
4433
|
+
id: row.id,
|
|
4434
|
+
repo: row.repo,
|
|
4435
|
+
session_id: row.session_id,
|
|
4436
|
+
kind: row.kind,
|
|
4437
|
+
text: row.text,
|
|
4438
|
+
source_activity_ids: sourceActivityIds,
|
|
4439
|
+
created_at: row.created_at,
|
|
4440
|
+
updated_at: row.updated_at
|
|
4441
|
+
};
|
|
4442
|
+
}
|
|
4443
|
+
|
|
4149
4444
|
// src/history/retrieval.ts
|
|
4150
4445
|
import { createHash } from "crypto";
|
|
4151
4446
|
|
|
@@ -4600,96 +4895,6 @@ async function searchHistorySnippets(db, query, options = {}) {
|
|
|
4600
4895
|
return [...merged.values()].sort((a, b) => b.score - a.score).slice(0, limit);
|
|
4601
4896
|
}
|
|
4602
4897
|
|
|
4603
|
-
// src/models/memory-injections.ts
|
|
4604
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
4605
|
-
function recordMemoryInjections(db, input) {
|
|
4606
|
-
if (!input.session_id || input.memory_ids.length === 0) return 0;
|
|
4607
|
-
const injectedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4608
|
-
let inserted = 0;
|
|
4609
|
-
for (const memoryId of input.memory_ids) {
|
|
4610
|
-
const result = db.insert(memoryInjections).values({
|
|
4611
|
-
id: randomUUID2(),
|
|
4612
|
-
memory_id: memoryId,
|
|
4613
|
-
session_id: input.session_id,
|
|
4614
|
-
repo: input.repo ?? null,
|
|
4615
|
-
injected_at: injectedAt,
|
|
4616
|
-
outcome: null,
|
|
4617
|
-
outcome_at: null
|
|
4618
|
-
}).onConflictDoNothing({
|
|
4619
|
-
target: [memoryInjections.memory_id, memoryInjections.session_id]
|
|
4620
|
-
}).run();
|
|
4621
|
-
inserted += Number(result.changes ?? 0);
|
|
4622
|
-
}
|
|
4623
|
-
return inserted;
|
|
4624
|
-
}
|
|
4625
|
-
function listInjectedMemoryIdsForSession(db, sessionId) {
|
|
4626
|
-
const rows = db.select({ memory_id: memoryInjections.memory_id }).from(memoryInjections).where(eq(memoryInjections.session_id, sessionId)).all();
|
|
4627
|
-
return new Set(rows.map((row) => row.memory_id));
|
|
4628
|
-
}
|
|
4629
|
-
function listPendingMemoryInjections(db, sessionId) {
|
|
4630
|
-
const rows = db.select().from(memoryInjections).where(and(
|
|
4631
|
-
eq(memoryInjections.session_id, sessionId),
|
|
4632
|
-
isNull(memoryInjections.outcome)
|
|
4633
|
-
)).orderBy(asc(memoryInjections.injected_at)).all();
|
|
4634
|
-
return rows.map((row) => ({
|
|
4635
|
-
...rowToMemoryInjection(row),
|
|
4636
|
-
memory: getMemory(db, row.memory_id) ?? null
|
|
4637
|
-
}));
|
|
4638
|
-
}
|
|
4639
|
-
function resolveMemoryInjectionOutcome(db, memoryId, sessionId, outcome) {
|
|
4640
|
-
const outcomeAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4641
|
-
const result = db.update(memoryInjections).set({
|
|
4642
|
-
outcome,
|
|
4643
|
-
outcome_at: outcomeAt
|
|
4644
|
-
}).where(and(
|
|
4645
|
-
eq(memoryInjections.memory_id, memoryId),
|
|
4646
|
-
eq(memoryInjections.session_id, sessionId),
|
|
4647
|
-
isNull(memoryInjections.outcome)
|
|
4648
|
-
)).run();
|
|
4649
|
-
return Number(result.changes ?? 0) > 0;
|
|
4650
|
-
}
|
|
4651
|
-
function pathMatchesMemory(mem, targetPath) {
|
|
4652
|
-
if (!targetPath) return mem.scope === "repo" || mem.scope === "team" || mem.scope === "global";
|
|
4653
|
-
if (mem.scope === "repo" || mem.scope === "team" || mem.scope === "global") return true;
|
|
4654
|
-
if (!mem.path_scope) return true;
|
|
4655
|
-
const pattern = mem.path_scope;
|
|
4656
|
-
if (pattern.endsWith("**")) {
|
|
4657
|
-
return targetPath.startsWith(pattern.slice(0, -2));
|
|
4658
|
-
}
|
|
4659
|
-
if (pattern.includes("*")) {
|
|
4660
|
-
const regex = new RegExp(
|
|
4661
|
-
"^" + pattern.replace(/\*/g, "[^/]*").replace(/\*\*/g, ".*") + "$"
|
|
4662
|
-
);
|
|
4663
|
-
return regex.test(targetPath);
|
|
4664
|
-
}
|
|
4665
|
-
return targetPath.startsWith(pattern);
|
|
4666
|
-
}
|
|
4667
|
-
function toolCallTouchesMemory(mem, toolCall) {
|
|
4668
|
-
if (toolCall.path && pathMatchesMemory(mem, toolCall.path)) return true;
|
|
4669
|
-
if (toolCall.input_summary) {
|
|
4670
|
-
const inferredPath = extractPath(toolCall.input_summary);
|
|
4671
|
-
if (inferredPath && pathMatchesMemory(mem, inferredPath)) return true;
|
|
4672
|
-
}
|
|
4673
|
-
return mem.scope === "repo" || mem.scope === "team" || mem.scope === "global";
|
|
4674
|
-
}
|
|
4675
|
-
function rowToMemoryInjection(row) {
|
|
4676
|
-
return {
|
|
4677
|
-
id: row.id,
|
|
4678
|
-
memory_id: row.memory_id,
|
|
4679
|
-
session_id: row.session_id,
|
|
4680
|
-
repo: row.repo,
|
|
4681
|
-
injected_at: row.injected_at,
|
|
4682
|
-
outcome: row.outcome,
|
|
4683
|
-
outcome_at: row.outcome_at
|
|
4684
|
-
};
|
|
4685
|
-
}
|
|
4686
|
-
function extractPath(text) {
|
|
4687
|
-
const match = text.match(
|
|
4688
|
-
/\b((?:src|lib|app|components|utils|test|spec)\/[\w./-]+|[\w./-]+\.(?:ts|tsx|js|jsx|py|rs|go|swift|java|rb|json|toml|ya?ml))\b/
|
|
4689
|
-
);
|
|
4690
|
-
return match?.[1];
|
|
4691
|
-
}
|
|
4692
|
-
|
|
4693
4898
|
// src/models/history-injections.ts
|
|
4694
4899
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
4695
4900
|
function recordHistoryInjections(db, input) {
|
|
@@ -4813,11 +5018,18 @@ function compileContext(db, req) {
|
|
|
4813
5018
|
}
|
|
4814
5019
|
}
|
|
4815
5020
|
const finalText = renderPack(selected, req.repo, selectedHistory);
|
|
5021
|
+
const finalTokenEstimate = Math.ceil(finalText.length / 4);
|
|
4816
5022
|
recordMemoryInjections(db, {
|
|
4817
5023
|
memory_ids: selected.map((memory) => memory.id),
|
|
4818
5024
|
session_id: req.session_id,
|
|
4819
5025
|
repo: req.repo
|
|
4820
5026
|
});
|
|
5027
|
+
recordInjectionValueEvents(db, {
|
|
5028
|
+
memory_ids: selected.map((memory) => memory.id),
|
|
5029
|
+
session_id: req.session_id,
|
|
5030
|
+
repo: req.repo,
|
|
5031
|
+
pack_tokens_estimate: finalTokenEstimate
|
|
5032
|
+
});
|
|
4821
5033
|
recordHistoryInjections(db, {
|
|
4822
5034
|
snippet_ids: selectedHistory.map((snippet) => snippet.id),
|
|
4823
5035
|
session_id: req.session_id,
|
|
@@ -4831,7 +5043,7 @@ function compileContext(db, req) {
|
|
|
4831
5043
|
...sorted.filter((m) => !selected.includes(m)).map((m) => m.id)
|
|
4832
5044
|
],
|
|
4833
5045
|
history_included: selectedHistory.map((snippet) => snippet.id),
|
|
4834
|
-
token_estimate:
|
|
5046
|
+
token_estimate: finalTokenEstimate
|
|
4835
5047
|
};
|
|
4836
5048
|
}
|
|
4837
5049
|
async function compileContextHybrid(db, req) {
|
|
@@ -4942,11 +5154,18 @@ async function compileContextHybrid(db, req) {
|
|
|
4942
5154
|
selected.pop();
|
|
4943
5155
|
}
|
|
4944
5156
|
const finalText = renderPack(selected, req.repo, selectedHistory);
|
|
5157
|
+
const finalTokenEstimate = Math.ceil(finalText.length / 4);
|
|
4945
5158
|
recordMemoryInjections(db, {
|
|
4946
5159
|
memory_ids: selected.map((memory) => memory.id),
|
|
4947
5160
|
session_id: req.session_id,
|
|
4948
5161
|
repo: req.repo
|
|
4949
5162
|
});
|
|
5163
|
+
recordInjectionValueEvents(db, {
|
|
5164
|
+
memory_ids: selected.map((memory) => memory.id),
|
|
5165
|
+
session_id: req.session_id,
|
|
5166
|
+
repo: req.repo,
|
|
5167
|
+
pack_tokens_estimate: finalTokenEstimate
|
|
5168
|
+
});
|
|
4950
5169
|
recordHistoryInjections(db, {
|
|
4951
5170
|
snippet_ids: selectedHistory.map((snippet) => snippet.id),
|
|
4952
5171
|
session_id: req.session_id,
|
|
@@ -4960,7 +5179,7 @@ async function compileContextHybrid(db, req) {
|
|
|
4960
5179
|
...ranked.map((item) => item.memory).filter((memory) => !selected.includes(memory)).map((memory) => memory.id)
|
|
4961
5180
|
],
|
|
4962
5181
|
history_included: selectedHistory.map((snippet) => snippet.id),
|
|
4963
|
-
token_estimate:
|
|
5182
|
+
token_estimate: finalTokenEstimate
|
|
4964
5183
|
};
|
|
4965
5184
|
}
|
|
4966
5185
|
function renderPack(items, repo, history = []) {
|
|
@@ -5163,178 +5382,6 @@ function exportCodex(db, repo) {
|
|
|
5163
5382
|
${result.text}`;
|
|
5164
5383
|
}
|
|
5165
5384
|
|
|
5166
|
-
// src/repo/discovery.ts
|
|
5167
|
-
import { existsSync as existsSync3, readdirSync } from "fs";
|
|
5168
|
-
import { execFileSync } from "child_process";
|
|
5169
|
-
import { join as join3, resolve } from "path";
|
|
5170
|
-
var repoPathCache = /* @__PURE__ */ new Map();
|
|
5171
|
-
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
5172
|
-
".git",
|
|
5173
|
-
"node_modules",
|
|
5174
|
-
"dist",
|
|
5175
|
-
"build",
|
|
5176
|
-
"coverage",
|
|
5177
|
-
".next",
|
|
5178
|
-
".turbo",
|
|
5179
|
-
".venv",
|
|
5180
|
-
"venv"
|
|
5181
|
-
]);
|
|
5182
|
-
function ensureRepoBootstrapped(db, opts) {
|
|
5183
|
-
const repo = normalizeRepoSlug(opts.repo);
|
|
5184
|
-
const repoPathHint = opts.repoPathHint ?? null;
|
|
5185
|
-
if (!repo && !repoPathHint) {
|
|
5186
|
-
return {
|
|
5187
|
-
repo: null,
|
|
5188
|
-
repo_path: null,
|
|
5189
|
-
created_ids: [],
|
|
5190
|
-
status: "skipped"
|
|
5191
|
-
};
|
|
5192
|
-
}
|
|
5193
|
-
const resolvedRepo = repo ?? inferRepoSlugFromPath(repoPathHint);
|
|
5194
|
-
if (!resolvedRepo) {
|
|
5195
|
-
return {
|
|
5196
|
-
repo: null,
|
|
5197
|
-
repo_path: null,
|
|
5198
|
-
created_ids: [],
|
|
5199
|
-
status: "unresolved"
|
|
5200
|
-
};
|
|
5201
|
-
}
|
|
5202
|
-
if (queryMemories(db, { repo: resolvedRepo }).length > 0) {
|
|
5203
|
-
return {
|
|
5204
|
-
repo: resolvedRepo,
|
|
5205
|
-
repo_path: null,
|
|
5206
|
-
created_ids: [],
|
|
5207
|
-
status: "already_known"
|
|
5208
|
-
};
|
|
5209
|
-
}
|
|
5210
|
-
const repoPath = resolveLocalRepoPath(resolvedRepo, {
|
|
5211
|
-
repoPathHint,
|
|
5212
|
-
searchRoots: opts.searchRoots
|
|
5213
|
-
});
|
|
5214
|
-
if (!repoPath) {
|
|
5215
|
-
return {
|
|
5216
|
-
repo: resolvedRepo,
|
|
5217
|
-
repo_path: null,
|
|
5218
|
-
created_ids: [],
|
|
5219
|
-
status: "unresolved"
|
|
5220
|
-
};
|
|
5221
|
-
}
|
|
5222
|
-
const createdIds = scanAndStore(db, repoPath);
|
|
5223
|
-
return {
|
|
5224
|
-
repo: resolvedRepo,
|
|
5225
|
-
repo_path: repoPath,
|
|
5226
|
-
created_ids: createdIds,
|
|
5227
|
-
status: createdIds.length > 0 ? "bootstrapped" : "scanned_empty"
|
|
5228
|
-
};
|
|
5229
|
-
}
|
|
5230
|
-
function resolveLocalRepoPath(repo, opts = {}) {
|
|
5231
|
-
const normalizedRepo = normalizeRepoSlug(repo);
|
|
5232
|
-
if (!normalizedRepo) return null;
|
|
5233
|
-
if (repoPathCache.has(normalizedRepo)) {
|
|
5234
|
-
return repoPathCache.get(normalizedRepo) ?? null;
|
|
5235
|
-
}
|
|
5236
|
-
const directHint = normalizeRepoPathHint(opts.repoPathHint);
|
|
5237
|
-
if (directHint && pathMatchesRepo(directHint, normalizedRepo)) {
|
|
5238
|
-
repoPathCache.set(normalizedRepo, directHint);
|
|
5239
|
-
return directHint;
|
|
5240
|
-
}
|
|
5241
|
-
const candidates = collectCandidateRepos(opts.searchRoots ?? getDefaultSearchRoots());
|
|
5242
|
-
const basenameMatches = [];
|
|
5243
|
-
for (const candidate of candidates) {
|
|
5244
|
-
const candidateRepo = inferRepoSlugFromPath(candidate);
|
|
5245
|
-
if (candidateRepo === normalizedRepo) {
|
|
5246
|
-
repoPathCache.set(normalizedRepo, candidate);
|
|
5247
|
-
return candidate;
|
|
5248
|
-
}
|
|
5249
|
-
if (candidate.endsWith(`/${normalizedRepo.split("/").at(-1)}`)) {
|
|
5250
|
-
basenameMatches.push(candidate);
|
|
5251
|
-
}
|
|
5252
|
-
}
|
|
5253
|
-
const fallback = basenameMatches.length === 1 ? basenameMatches[0] : null;
|
|
5254
|
-
repoPathCache.set(normalizedRepo, fallback);
|
|
5255
|
-
return fallback;
|
|
5256
|
-
}
|
|
5257
|
-
function inferRepoSlugFromPath(repoPath) {
|
|
5258
|
-
const root = normalizeRepoPathHint(repoPath);
|
|
5259
|
-
if (!root) return null;
|
|
5260
|
-
try {
|
|
5261
|
-
const remote = execFileSync(
|
|
5262
|
-
"git",
|
|
5263
|
-
["-C", root, "remote", "get-url", "origin"],
|
|
5264
|
-
{ encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }
|
|
5265
|
-
).trim();
|
|
5266
|
-
return extractRepoSlugFromRemote2(remote);
|
|
5267
|
-
} catch {
|
|
5268
|
-
const parts = root.split("/").filter(Boolean);
|
|
5269
|
-
return parts.at(-1) ?? null;
|
|
5270
|
-
}
|
|
5271
|
-
}
|
|
5272
|
-
function extractRepoSlugFromRemote2(remote) {
|
|
5273
|
-
const trimmed = remote.trim().replace(/\.git$/, "");
|
|
5274
|
-
const parts = trimmed.split(/[:/]/).filter(Boolean);
|
|
5275
|
-
if (parts.length < 2) return null;
|
|
5276
|
-
return `${parts.at(-2)}/${parts.at(-1)}`;
|
|
5277
|
-
}
|
|
5278
|
-
function pathMatchesRepo(repoPath, repo) {
|
|
5279
|
-
const inferred = inferRepoSlugFromPath(repoPath);
|
|
5280
|
-
if (inferred === repo) return true;
|
|
5281
|
-
return repoPath.endsWith(`/${repo.split("/").at(-1)}`);
|
|
5282
|
-
}
|
|
5283
|
-
function normalizeRepoSlug(repo) {
|
|
5284
|
-
if (!repo) return null;
|
|
5285
|
-
const trimmed = repo.trim().replace(/\.git$/, "").replace(/^https?:\/\/[^/]+\//, "");
|
|
5286
|
-
if (!trimmed.includes("/")) return null;
|
|
5287
|
-
return trimmed.replace(/^git@[^:]+:/, "");
|
|
5288
|
-
}
|
|
5289
|
-
function normalizeRepoPathHint(repoPath) {
|
|
5290
|
-
if (!repoPath) return null;
|
|
5291
|
-
const expanded = repoPath.trim().replace(/^~(?=\/)/, process.env.HOME ?? "~");
|
|
5292
|
-
try {
|
|
5293
|
-
const root = execFileSync(
|
|
5294
|
-
"git",
|
|
5295
|
-
["-C", expanded, "rev-parse", "--show-toplevel"],
|
|
5296
|
-
{ encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }
|
|
5297
|
-
).trim();
|
|
5298
|
-
return root || null;
|
|
5299
|
-
} catch {
|
|
5300
|
-
const resolved = resolve(expanded);
|
|
5301
|
-
return existsSync3(join3(resolved, ".git")) ? resolved : null;
|
|
5302
|
-
}
|
|
5303
|
-
}
|
|
5304
|
-
function getDefaultSearchRoots() {
|
|
5305
|
-
const configured = process.env.RECALL_REPO_ROOTS?.split(",").map((value) => value.trim()).filter(Boolean);
|
|
5306
|
-
if (configured?.length) return configured;
|
|
5307
|
-
const home = process.env.HOME ?? process.cwd();
|
|
5308
|
-
return [join3(home, "Projects")];
|
|
5309
|
-
}
|
|
5310
|
-
function collectCandidateRepos(searchRoots) {
|
|
5311
|
-
const seen = /* @__PURE__ */ new Set();
|
|
5312
|
-
const repos = [];
|
|
5313
|
-
for (const root of searchRoots) {
|
|
5314
|
-
walkRepos(resolve(root), 4, seen, repos);
|
|
5315
|
-
}
|
|
5316
|
-
return repos;
|
|
5317
|
-
}
|
|
5318
|
-
function walkRepos(dir, depthRemaining, seen, repos) {
|
|
5319
|
-
if (depthRemaining < 0 || seen.has(dir) || !existsSync3(dir)) return;
|
|
5320
|
-
seen.add(dir);
|
|
5321
|
-
if (existsSync3(join3(dir, ".git"))) {
|
|
5322
|
-
repos.push(dir);
|
|
5323
|
-
return;
|
|
5324
|
-
}
|
|
5325
|
-
let entries;
|
|
5326
|
-
try {
|
|
5327
|
-
entries = readdirSync(dir, { withFileTypes: true });
|
|
5328
|
-
} catch {
|
|
5329
|
-
return;
|
|
5330
|
-
}
|
|
5331
|
-
for (const entry of entries) {
|
|
5332
|
-
if (!entry.isDirectory()) continue;
|
|
5333
|
-
if (SKIP_DIRS.has(entry.name)) continue;
|
|
5334
|
-
walkRepos(join3(dir, entry.name), depthRemaining - 1, seen, repos);
|
|
5335
|
-
}
|
|
5336
|
-
}
|
|
5337
|
-
|
|
5338
5385
|
// src/artifacts/context.ts
|
|
5339
5386
|
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
5340
5387
|
import { join as join4 } from "path";
|
|
@@ -5406,6 +5453,114 @@ function ensureRepoContextExcluded(repoPath) {
|
|
|
5406
5453
|
}
|
|
5407
5454
|
}
|
|
5408
5455
|
|
|
5456
|
+
// src/session/lifecycle.ts
|
|
5457
|
+
function resolveLifecycleSource(input) {
|
|
5458
|
+
if (input.source) return input.source;
|
|
5459
|
+
return input.client ? tagActivitySource("hook", input.client) : "daemon";
|
|
5460
|
+
}
|
|
5461
|
+
function startSessionLifecycle(db, input) {
|
|
5462
|
+
const repo = input.repo ?? inferRepoSlugFromPath(input.repo_path) ?? null;
|
|
5463
|
+
const bootstrap = ensureRepoBootstrapped(db, {
|
|
5464
|
+
repo,
|
|
5465
|
+
repoPathHint: input.repo_path
|
|
5466
|
+
});
|
|
5467
|
+
if (bootstrap.status === "bootstrapped" || bootstrap.status === "scanned_empty") {
|
|
5468
|
+
createActivityEvent(db, {
|
|
5469
|
+
session_id: input.session_id,
|
|
5470
|
+
repo: bootstrap.repo,
|
|
5471
|
+
path: input.path ?? null,
|
|
5472
|
+
source: resolveLifecycleSource(input),
|
|
5473
|
+
event_type: "scan",
|
|
5474
|
+
memory_ids: bootstrap.created_ids,
|
|
5475
|
+
request: {
|
|
5476
|
+
repo_path: bootstrap.repo_path,
|
|
5477
|
+
client: input.client ?? null,
|
|
5478
|
+
trigger: "session_start_bootstrap"
|
|
5479
|
+
},
|
|
5480
|
+
result: {
|
|
5481
|
+
created: bootstrap.created_ids.length,
|
|
5482
|
+
status: bootstrap.status
|
|
5483
|
+
}
|
|
5484
|
+
});
|
|
5485
|
+
}
|
|
5486
|
+
const artifact = writeRepoContextArtifact(db, {
|
|
5487
|
+
repo: bootstrap.repo,
|
|
5488
|
+
repo_path: bootstrap.repo_path ?? input.repo_path ?? null
|
|
5489
|
+
});
|
|
5490
|
+
createActivityEvent(db, {
|
|
5491
|
+
session_id: input.session_id,
|
|
5492
|
+
repo: bootstrap.repo,
|
|
5493
|
+
path: input.path ?? null,
|
|
5494
|
+
source: resolveLifecycleSource(input),
|
|
5495
|
+
event_type: "session_start",
|
|
5496
|
+
request: {
|
|
5497
|
+
client: input.client ?? null,
|
|
5498
|
+
repo_path: bootstrap.repo_path ?? input.repo_path ?? null,
|
|
5499
|
+
meta: input.meta ?? {}
|
|
5500
|
+
},
|
|
5501
|
+
result: {
|
|
5502
|
+
bootstrap_status: bootstrap.status,
|
|
5503
|
+
created: bootstrap.created_ids.length,
|
|
5504
|
+
artifact_path: artifact.output_path,
|
|
5505
|
+
artifact_written: artifact.written
|
|
5506
|
+
}
|
|
5507
|
+
});
|
|
5508
|
+
return {
|
|
5509
|
+
session_id: input.session_id,
|
|
5510
|
+
repo: bootstrap.repo,
|
|
5511
|
+
repo_path: bootstrap.repo_path ?? input.repo_path ?? null,
|
|
5512
|
+
bootstrap_status: bootstrap.status,
|
|
5513
|
+
created_ids: bootstrap.created_ids
|
|
5514
|
+
};
|
|
5515
|
+
}
|
|
5516
|
+
function recordSessionLifecycleEvent(db, input) {
|
|
5517
|
+
const repo = input.repo ?? inferRepoSlugFromPath(input.repo_path) ?? null;
|
|
5518
|
+
createActivityEvent(db, {
|
|
5519
|
+
session_id: input.session_id,
|
|
5520
|
+
repo,
|
|
5521
|
+
path: input.path ?? null,
|
|
5522
|
+
source: resolveLifecycleSource(input),
|
|
5523
|
+
event_type: "session_event",
|
|
5524
|
+
request: {
|
|
5525
|
+
client: input.client ?? null,
|
|
5526
|
+
name: input.name,
|
|
5527
|
+
repo_path: input.repo_path ?? null,
|
|
5528
|
+
meta: input.meta ?? {}
|
|
5529
|
+
},
|
|
5530
|
+
result: input.payload ?? {}
|
|
5531
|
+
});
|
|
5532
|
+
return {
|
|
5533
|
+
session_id: input.session_id,
|
|
5534
|
+
repo,
|
|
5535
|
+
repo_path: input.repo_path ?? null,
|
|
5536
|
+
bootstrap_status: "skipped",
|
|
5537
|
+
created_ids: []
|
|
5538
|
+
};
|
|
5539
|
+
}
|
|
5540
|
+
function endSessionLifecycle(db, input) {
|
|
5541
|
+
const repo = input.repo ?? inferRepoSlugFromPath(input.repo_path) ?? null;
|
|
5542
|
+
createActivityEvent(db, {
|
|
5543
|
+
session_id: input.session_id,
|
|
5544
|
+
repo,
|
|
5545
|
+
path: input.path ?? null,
|
|
5546
|
+
source: resolveLifecycleSource(input),
|
|
5547
|
+
event_type: "session_end",
|
|
5548
|
+
request: {
|
|
5549
|
+
client: input.client ?? null,
|
|
5550
|
+
repo_path: input.repo_path ?? null,
|
|
5551
|
+
meta: input.meta ?? {}
|
|
5552
|
+
},
|
|
5553
|
+
result: input.payload ?? {}
|
|
5554
|
+
});
|
|
5555
|
+
return {
|
|
5556
|
+
session_id: input.session_id,
|
|
5557
|
+
repo,
|
|
5558
|
+
repo_path: input.repo_path ?? null,
|
|
5559
|
+
bootstrap_status: "skipped",
|
|
5560
|
+
created_ids: []
|
|
5561
|
+
};
|
|
5562
|
+
}
|
|
5563
|
+
|
|
5409
5564
|
// src/eval/harness.ts
|
|
5410
5565
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
5411
5566
|
function startEvalSession(db, repo) {
|
|
@@ -6146,232 +6301,6 @@ function formatPruneReport(result, dryRun) {
|
|
|
6146
6301
|
return lines.join("\n");
|
|
6147
6302
|
}
|
|
6148
6303
|
|
|
6149
|
-
// src/models/activity.ts
|
|
6150
|
-
import { randomUUID as randomUUID7 } from "crypto";
|
|
6151
|
-
function createActivityEvent(db, input) {
|
|
6152
|
-
const safeInput = {
|
|
6153
|
-
...input,
|
|
6154
|
-
request: redactSensitiveValue(input.request ?? {}),
|
|
6155
|
-
result: redactSensitiveValue(input.result ?? {})
|
|
6156
|
-
};
|
|
6157
|
-
const dedupeKey = activityEventDedupeKey(safeInput);
|
|
6158
|
-
if (dedupeKey) {
|
|
6159
|
-
const existingId = findActivityEventByDedupeKey(db, dedupeKey);
|
|
6160
|
-
if (existingId) return existingId;
|
|
6161
|
-
} else {
|
|
6162
|
-
const fuzzyId = findRecentDuplicateActivityEvent(db, safeInput);
|
|
6163
|
-
if (fuzzyId) return fuzzyId;
|
|
6164
|
-
}
|
|
6165
|
-
const id = randomUUID7();
|
|
6166
|
-
const result = db.insert(activityEvents).values({
|
|
6167
|
-
id,
|
|
6168
|
-
session_id: safeInput.session_id ?? null,
|
|
6169
|
-
repo: safeInput.repo ?? null,
|
|
6170
|
-
path: safeInput.path ?? null,
|
|
6171
|
-
source: safeInput.source,
|
|
6172
|
-
event_type: safeInput.event_type,
|
|
6173
|
-
memory_ids: safeInput.memory_ids ?? [],
|
|
6174
|
-
dedupe_key: dedupeKey,
|
|
6175
|
-
request: safeInput.request,
|
|
6176
|
-
result: safeInput.result,
|
|
6177
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
6178
|
-
}).onConflictDoNothing({ target: activityEvents.dedupe_key }).run();
|
|
6179
|
-
if (Number(result.changes ?? 0) === 0 && dedupeKey) {
|
|
6180
|
-
const existingId = findActivityEventByDedupeKey(db, dedupeKey);
|
|
6181
|
-
if (existingId) return existingId;
|
|
6182
|
-
}
|
|
6183
|
-
return id;
|
|
6184
|
-
}
|
|
6185
|
-
function findActivityEventByDedupeKey(db, dedupeKey) {
|
|
6186
|
-
const row = db.select({ id: activityEvents.id }).from(activityEvents).where(eq(activityEvents.dedupe_key, dedupeKey)).get();
|
|
6187
|
-
return row?.id ?? null;
|
|
6188
|
-
}
|
|
6189
|
-
function findRecentDuplicateActivityEvent(db, input) {
|
|
6190
|
-
if (!input.session_id) return null;
|
|
6191
|
-
const since = new Date(Date.now() - 2e3).toISOString();
|
|
6192
|
-
const rows = db.select().from(activityEvents).where(and(
|
|
6193
|
-
eq(activityEvents.session_id, input.session_id),
|
|
6194
|
-
eq(activityEvents.source, input.source),
|
|
6195
|
-
eq(activityEvents.event_type, input.event_type),
|
|
6196
|
-
gte(activityEvents.created_at, since)
|
|
6197
|
-
)).all();
|
|
6198
|
-
const requestKey = JSON.stringify(input.request ?? {});
|
|
6199
|
-
const resultKey = JSON.stringify(input.result ?? {});
|
|
6200
|
-
const repo = input.repo ?? null;
|
|
6201
|
-
const path = input.path ?? null;
|
|
6202
|
-
for (const row of rows) {
|
|
6203
|
-
if (row.repo !== repo || row.path !== path) continue;
|
|
6204
|
-
const request = typeof row.request === "string" ? JSON.parse(row.request) : row.request ?? {};
|
|
6205
|
-
const result = typeof row.result === "string" ? JSON.parse(row.result) : row.result ?? {};
|
|
6206
|
-
if (JSON.stringify(request) === requestKey && JSON.stringify(result) === resultKey) {
|
|
6207
|
-
return row.id;
|
|
6208
|
-
}
|
|
6209
|
-
}
|
|
6210
|
-
return null;
|
|
6211
|
-
}
|
|
6212
|
-
function listActivityEvents(db, query = {}) {
|
|
6213
|
-
const conditions = [];
|
|
6214
|
-
if (query.repo) conditions.push(eq(activityEvents.repo, query.repo));
|
|
6215
|
-
if (query.session_id) conditions.push(eq(activityEvents.session_id, query.session_id));
|
|
6216
|
-
if (query.source) conditions.push(eq(activityEvents.source, query.source));
|
|
6217
|
-
if (query.event_type) conditions.push(eq(activityEvents.event_type, query.event_type));
|
|
6218
|
-
if (query.since) conditions.push(gte(activityEvents.created_at, query.since));
|
|
6219
|
-
const offset = query.offset ?? 0;
|
|
6220
|
-
const limit = query.limit ?? 1e3;
|
|
6221
|
-
const base = db.select().from(activityEvents);
|
|
6222
|
-
const ordered = conditions.length > 0 ? base.where(and(...conditions)).orderBy(desc(activityEvents.created_at)) : base.orderBy(desc(activityEvents.created_at));
|
|
6223
|
-
const rows = ordered.limit(limit).offset(offset).all();
|
|
6224
|
-
return rows.map(rowToActivityEvent);
|
|
6225
|
-
}
|
|
6226
|
-
function listActivitySessions(db, query = {}) {
|
|
6227
|
-
const events = listActivityEvents(db, query).filter((event) => event.session_id);
|
|
6228
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
6229
|
-
for (const event of events) {
|
|
6230
|
-
const sessionId = event.session_id;
|
|
6231
|
-
const bucket = grouped.get(sessionId) ?? [];
|
|
6232
|
-
bucket.push(event);
|
|
6233
|
-
grouped.set(sessionId, bucket);
|
|
6234
|
-
}
|
|
6235
|
-
const sessions = [...grouped.entries()].map(([session_id, items]) => {
|
|
6236
|
-
const sorted = [...items].sort((a, b) => a.created_at.localeCompare(b.created_at));
|
|
6237
|
-
return {
|
|
6238
|
-
session_id,
|
|
6239
|
-
repo: sorted[0]?.repo ?? null,
|
|
6240
|
-
event_count: items.length,
|
|
6241
|
-
event_types: [...new Set(items.map((item) => item.event_type))],
|
|
6242
|
-
first_at: sorted[0].created_at,
|
|
6243
|
-
last_at: sorted[sorted.length - 1].created_at
|
|
6244
|
-
};
|
|
6245
|
-
});
|
|
6246
|
-
sessions.sort((a, b) => b.last_at.localeCompare(a.last_at));
|
|
6247
|
-
return query.limit ? sessions.slice(0, query.limit) : sessions;
|
|
6248
|
-
}
|
|
6249
|
-
function rowToActivityEvent(row) {
|
|
6250
|
-
const memory_ids = typeof row.memory_ids === "string" ? JSON.parse(row.memory_ids) : Array.isArray(row.memory_ids) ? row.memory_ids : [];
|
|
6251
|
-
const request = typeof row.request === "string" ? JSON.parse(row.request) : row.request ?? {};
|
|
6252
|
-
const result = typeof row.result === "string" ? JSON.parse(row.result) : row.result ?? {};
|
|
6253
|
-
return {
|
|
6254
|
-
id: row.id,
|
|
6255
|
-
session_id: row.session_id,
|
|
6256
|
-
repo: row.repo,
|
|
6257
|
-
path: row.path,
|
|
6258
|
-
source: row.source,
|
|
6259
|
-
event_type: row.event_type,
|
|
6260
|
-
memory_ids,
|
|
6261
|
-
request,
|
|
6262
|
-
result,
|
|
6263
|
-
created_at: row.created_at
|
|
6264
|
-
};
|
|
6265
|
-
}
|
|
6266
|
-
|
|
6267
|
-
// src/session/lifecycle.ts
|
|
6268
|
-
function resolveLifecycleSource(input) {
|
|
6269
|
-
if (input.source) return input.source;
|
|
6270
|
-
return input.client ? tagActivitySource("hook", input.client) : "daemon";
|
|
6271
|
-
}
|
|
6272
|
-
function startSessionLifecycle(db, input) {
|
|
6273
|
-
const repo = input.repo ?? inferRepoSlugFromPath(input.repo_path) ?? null;
|
|
6274
|
-
const bootstrap = ensureRepoBootstrapped(db, {
|
|
6275
|
-
repo,
|
|
6276
|
-
repoPathHint: input.repo_path
|
|
6277
|
-
});
|
|
6278
|
-
if (bootstrap.status === "bootstrapped" || bootstrap.status === "scanned_empty") {
|
|
6279
|
-
createActivityEvent(db, {
|
|
6280
|
-
session_id: input.session_id,
|
|
6281
|
-
repo: bootstrap.repo,
|
|
6282
|
-
path: input.path ?? null,
|
|
6283
|
-
source: resolveLifecycleSource(input),
|
|
6284
|
-
event_type: "scan",
|
|
6285
|
-
memory_ids: bootstrap.created_ids,
|
|
6286
|
-
request: {
|
|
6287
|
-
repo_path: bootstrap.repo_path,
|
|
6288
|
-
client: input.client ?? null,
|
|
6289
|
-
trigger: "session_start_bootstrap"
|
|
6290
|
-
},
|
|
6291
|
-
result: {
|
|
6292
|
-
created: bootstrap.created_ids.length,
|
|
6293
|
-
status: bootstrap.status
|
|
6294
|
-
}
|
|
6295
|
-
});
|
|
6296
|
-
}
|
|
6297
|
-
const artifact = writeRepoContextArtifact(db, {
|
|
6298
|
-
repo: bootstrap.repo,
|
|
6299
|
-
repo_path: bootstrap.repo_path ?? input.repo_path ?? null
|
|
6300
|
-
});
|
|
6301
|
-
createActivityEvent(db, {
|
|
6302
|
-
session_id: input.session_id,
|
|
6303
|
-
repo: bootstrap.repo,
|
|
6304
|
-
path: input.path ?? null,
|
|
6305
|
-
source: resolveLifecycleSource(input),
|
|
6306
|
-
event_type: "session_start",
|
|
6307
|
-
request: {
|
|
6308
|
-
client: input.client ?? null,
|
|
6309
|
-
repo_path: bootstrap.repo_path ?? input.repo_path ?? null,
|
|
6310
|
-
meta: input.meta ?? {}
|
|
6311
|
-
},
|
|
6312
|
-
result: {
|
|
6313
|
-
bootstrap_status: bootstrap.status,
|
|
6314
|
-
created: bootstrap.created_ids.length,
|
|
6315
|
-
artifact_path: artifact.output_path,
|
|
6316
|
-
artifact_written: artifact.written
|
|
6317
|
-
}
|
|
6318
|
-
});
|
|
6319
|
-
return {
|
|
6320
|
-
session_id: input.session_id,
|
|
6321
|
-
repo: bootstrap.repo,
|
|
6322
|
-
repo_path: bootstrap.repo_path ?? input.repo_path ?? null,
|
|
6323
|
-
bootstrap_status: bootstrap.status,
|
|
6324
|
-
created_ids: bootstrap.created_ids
|
|
6325
|
-
};
|
|
6326
|
-
}
|
|
6327
|
-
function recordSessionLifecycleEvent(db, input) {
|
|
6328
|
-
const repo = input.repo ?? inferRepoSlugFromPath(input.repo_path) ?? null;
|
|
6329
|
-
createActivityEvent(db, {
|
|
6330
|
-
session_id: input.session_id,
|
|
6331
|
-
repo,
|
|
6332
|
-
path: input.path ?? null,
|
|
6333
|
-
source: resolveLifecycleSource(input),
|
|
6334
|
-
event_type: "session_event",
|
|
6335
|
-
request: {
|
|
6336
|
-
client: input.client ?? null,
|
|
6337
|
-
name: input.name,
|
|
6338
|
-
repo_path: input.repo_path ?? null,
|
|
6339
|
-
meta: input.meta ?? {}
|
|
6340
|
-
},
|
|
6341
|
-
result: input.payload ?? {}
|
|
6342
|
-
});
|
|
6343
|
-
return {
|
|
6344
|
-
session_id: input.session_id,
|
|
6345
|
-
repo,
|
|
6346
|
-
repo_path: input.repo_path ?? null,
|
|
6347
|
-
bootstrap_status: "skipped",
|
|
6348
|
-
created_ids: []
|
|
6349
|
-
};
|
|
6350
|
-
}
|
|
6351
|
-
function endSessionLifecycle(db, input) {
|
|
6352
|
-
const repo = input.repo ?? inferRepoSlugFromPath(input.repo_path) ?? null;
|
|
6353
|
-
createActivityEvent(db, {
|
|
6354
|
-
session_id: input.session_id,
|
|
6355
|
-
repo,
|
|
6356
|
-
path: input.path ?? null,
|
|
6357
|
-
source: resolveLifecycleSource(input),
|
|
6358
|
-
event_type: "session_end",
|
|
6359
|
-
request: {
|
|
6360
|
-
client: input.client ?? null,
|
|
6361
|
-
repo_path: input.repo_path ?? null,
|
|
6362
|
-
meta: input.meta ?? {}
|
|
6363
|
-
},
|
|
6364
|
-
result: input.payload ?? {}
|
|
6365
|
-
});
|
|
6366
|
-
return {
|
|
6367
|
-
session_id: input.session_id,
|
|
6368
|
-
repo,
|
|
6369
|
-
repo_path: input.repo_path ?? null,
|
|
6370
|
-
bootstrap_status: "skipped",
|
|
6371
|
-
created_ids: []
|
|
6372
|
-
};
|
|
6373
|
-
}
|
|
6374
|
-
|
|
6375
6304
|
// src/mcp/fallback.ts
|
|
6376
6305
|
async function captureCorrectionFallback(db, input, source) {
|
|
6377
6306
|
const sessionId = input.session_id ?? `${source}-capture`;
|
|
@@ -6417,6 +6346,15 @@ function signalOutcomeFallback(db, input, source) {
|
|
|
6417
6346
|
input.outcome
|
|
6418
6347
|
);
|
|
6419
6348
|
resolveMemoryInjectionOutcome(db, input.memory_id, input.session_id, input.outcome);
|
|
6349
|
+
recordOutcomeValueEvent(db, {
|
|
6350
|
+
memory_id: input.memory_id,
|
|
6351
|
+
session_id: input.session_id,
|
|
6352
|
+
injected: input.injected ?? true,
|
|
6353
|
+
outcome: input.outcome,
|
|
6354
|
+
feedback_id: feedbackId,
|
|
6355
|
+
context: input.context,
|
|
6356
|
+
source
|
|
6357
|
+
});
|
|
6420
6358
|
const memory = getMemory(db, input.memory_id);
|
|
6421
6359
|
createActivityEvent(db, {
|
|
6422
6360
|
session_id: input.session_id,
|
|
@@ -6471,12 +6409,13 @@ export {
|
|
|
6471
6409
|
initDb,
|
|
6472
6410
|
getDbUserVersion,
|
|
6473
6411
|
resetDb,
|
|
6412
|
+
createActivityEvent,
|
|
6413
|
+
listActivityEvents,
|
|
6414
|
+
listActivitySessions,
|
|
6474
6415
|
evaluateScannedMemory,
|
|
6475
6416
|
scanAndStore,
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
pathMatchesMemory,
|
|
6479
|
-
toolCallTouchesMemory,
|
|
6417
|
+
ensureRepoBootstrapped,
|
|
6418
|
+
inferRepoSlugFromPath,
|
|
6480
6419
|
listInjectedHistoryIdsForSession,
|
|
6481
6420
|
createHistorySnippet,
|
|
6482
6421
|
listHistorySnippets,
|
|
@@ -6494,9 +6433,13 @@ export {
|
|
|
6494
6433
|
exportMarkdown,
|
|
6495
6434
|
exportClaude,
|
|
6496
6435
|
exportCodex,
|
|
6497
|
-
ensureRepoBootstrapped,
|
|
6498
|
-
inferRepoSlugFromPath,
|
|
6499
6436
|
writeRepoContextArtifact,
|
|
6437
|
+
startSessionLifecycle,
|
|
6438
|
+
recordSessionLifecycleEvent,
|
|
6439
|
+
endSessionLifecycle,
|
|
6440
|
+
captureCorrectionFallback,
|
|
6441
|
+
signalOutcomeFallback,
|
|
6442
|
+
sessionEndFallback,
|
|
6500
6443
|
startEvalSession,
|
|
6501
6444
|
endEvalSession,
|
|
6502
6445
|
incrementEvalCounter,
|
|
@@ -6518,15 +6461,6 @@ export {
|
|
|
6518
6461
|
resolveApproval,
|
|
6519
6462
|
listPendingApprovals,
|
|
6520
6463
|
pruneMemories,
|
|
6521
|
-
formatPruneReport
|
|
6522
|
-
createActivityEvent,
|
|
6523
|
-
listActivityEvents,
|
|
6524
|
-
listActivitySessions,
|
|
6525
|
-
startSessionLifecycle,
|
|
6526
|
-
recordSessionLifecycleEvent,
|
|
6527
|
-
endSessionLifecycle,
|
|
6528
|
-
captureCorrectionFallback,
|
|
6529
|
-
signalOutcomeFallback,
|
|
6530
|
-
sessionEndFallback
|
|
6464
|
+
formatPruneReport
|
|
6531
6465
|
};
|
|
6532
|
-
//# sourceMappingURL=chunk-
|
|
6466
|
+
//# sourceMappingURL=chunk-QJTP6OIZ.js.map
|