@cortexkit/pi-magic-context 0.49.33 → 0.49.35
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/auto-search-worker.js +11 -6
- package/dist/chunk-embedding-write-worker.js +16 -13
- package/dist/{compaction-marker-candidates-p1kqkqhq.js → compaction-marker-candidates-hk2frhac.js} +3 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-8c85ebce.js → compartment-chunk-embedding-5j1d1e3v.js} +8 -7
- package/dist/embedding-backfill-jt459ady.js +26 -0
- package/dist/embedding-worker-process.js +2 -1
- package/dist/embedding-worker.js +5 -4
- package/dist/expand-attachments-8sxeyj26.js +21 -0
- package/dist/historian-calibration-extension.js +2 -1
- package/dist/{index-drmr22ac.js → index-0rvn6vhq.js} +3 -3
- package/dist/{index-hqw0rt9k.js → index-0wtm7g7f.js} +1 -1
- package/dist/{index-r9y6tbbm.js → index-11knwv2h.js} +20 -240
- package/dist/{index-0gymvr5j.js → index-2p691ayw.js} +19 -8
- package/dist/{index-wqpjhx1p.js → index-2qqsnh1b.js} +2 -2
- package/dist/index-3bb24eb6.js +229 -0
- package/dist/{index-48twbev2.js → index-6pk49fc3.js} +37 -51
- package/dist/index-6y6v2wvn.js +194 -0
- package/dist/{index-wpazxe9x.js → index-8m82cez2.js} +4 -4
- package/dist/{index-xn5yh0pn.js → index-a11nmw5t.js} +29 -128
- package/dist/index-by1bzjcd.js +24 -0
- package/dist/index-c6wbq66z.js +168 -0
- package/dist/{index-jn44h81p.js → index-cq71g4dk.js} +1 -1
- package/dist/{index-6wdwv3a6.js → index-d0w84hy5.js} +1 -1
- package/dist/{index-pb3ea2tq.js → index-d107f484.js} +5 -5
- package/dist/index-d21rhpbd.js +4171 -0
- package/dist/index-dnp1jjar.js +222 -0
- package/dist/index-ea37qn4x.js +777 -0
- package/dist/{index-k5ya5k8r.js → index-fzm8fm4z.js} +469 -4976
- package/dist/{index-fgs78jyd.js → index-gymgz20n.js} +5 -222
- package/dist/index-hgd00nas.js +113 -0
- package/dist/{index-d5q1q700.js → index-m68qfjte.js} +2 -2
- package/dist/{index-6981g1xv.js → index-mkh1cm5k.js} +1 -1
- package/dist/{index-4zemngt7.js → index-mp0gh04g.js} +2 -2
- package/dist/{index-23t8ryqw.js → index-n0zjvs3h.js} +1 -168
- package/dist/{index-bvpar0bg.js → index-rgvqh5x7.js} +2 -2
- package/dist/{index-gwxaz0z5.js → index-rzfr7wdv.js} +2 -2
- package/dist/{index-87xkw8xm.js → index-svqk0701.js} +70 -35
- package/dist/{index-9xd7qveg.js → index-vgfk2xa5.js} +4 -4
- package/dist/index-w26zvs1q.js +528 -0
- package/dist/index-wrr9rp9a.js +16 -0
- package/dist/{index-my0dn413.js → index-wt7vmyj4.js} +1 -1
- package/dist/{index-c474g0gj.js → index-yacs388s.js} +1 -1
- package/dist/{index-e59j3yq5.js → index-yg42q9bc.js} +95 -550
- package/dist/{index-eqw9t2ty.js → index-yhsmjvqa.js} +3 -3
- package/dist/index.js +523 -236
- package/dist/{logger-shetp43v.js → logger-2j70hhz4.js} +2 -1
- package/dist/{message-fts-rowid-map-3mbvdgn9.js → message-fts-rowid-map-aw4xa05a.js} +5 -4
- package/dist/{message-index-bounded-n30vk21s.js → message-index-bounded-da34vhs4.js} +12 -10
- package/dist/{message-time-backfill-e3r8ddh1.js → message-time-backfill-x45573rs.js} +3 -2
- package/dist/migration-worker.js +13 -10
- package/dist/{project-embedding-registry-acqb6be4.js → project-embedding-registry-davzvsz9.js} +13 -11
- package/dist/raw-ordinal-warmup-worker.js +12 -7
- package/dist/{read-session-chunk-ka6dhc77.js → read-session-chunk-nbcznexm.js} +14 -8
- package/dist/{read-session-raw-g9b1zdn5.js → read-session-raw-zb8kpa2y.js} +3 -2
- package/dist/render-d931g2vv.js +41 -0
- package/dist/{safe-notification-target-zcpchea6.js → safe-notification-target-jk69jxwp.js} +3 -2
- package/dist/search-archive-a76pp30g.js +24 -0
- package/dist/{search-qbxrnnjb.js → search-atp7g95j.js} +24 -20
- package/dist/{storage-tags-6409qq18.js → storage-tags-jy8b0xsy.js} +5 -4
- package/dist/store-kabezr25.js +453 -0
- package/dist/store-reader-2m80zs5z.js +14 -0
- package/dist/subagent-entry.js +31 -23
- package/dist/tag-snapshot-worker-pi.js +15 -12
- package/dist/v2-archive-reader-wcjcfdzq.js +11 -0
- package/package.json +1 -1
- package/dist/embedding-backfill-rwfmyvze.js +0 -24
- package/dist/search-archive-msy2bczx.js +0 -21
|
@@ -1,48 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./index-
|
|
4
|
-
import {
|
|
5
|
-
inRootAsyncContext2,
|
|
6
|
-
getSqliteDatabasePath2,
|
|
7
|
-
withSqliteBackgroundWriter2,
|
|
8
|
-
isTransientSqliteError2,
|
|
9
|
-
indexCoordinationInput2
|
|
10
|
-
} from "./index-2qtx0q6h.js";
|
|
2
|
+
sanitizeDiagnosticText
|
|
3
|
+
} from "./index-dnp1jjar.js";
|
|
11
4
|
import {
|
|
12
5
|
PROMOTABLE_CATEGORIES,
|
|
13
6
|
CATEGORY_DEFAULT_TTL
|
|
14
7
|
} from "./index-135e8hvg.js";
|
|
8
|
+
import {
|
|
9
|
+
getHarness2
|
|
10
|
+
} from "./index-0h2mkab2.js";
|
|
15
11
|
import {
|
|
16
12
|
getDataDir,
|
|
17
|
-
sanitizeDiagnosticText,
|
|
18
13
|
log2,
|
|
19
14
|
sessionLog2
|
|
20
|
-
} from "./index-
|
|
21
|
-
import {
|
|
22
|
-
resolveWorkspaceShareCategories,
|
|
23
|
-
resolveWorkspaceIdentitySet,
|
|
24
|
-
expandWorkspaceIdentitySetWithAliases,
|
|
25
|
-
resolveStoredPathWorkspaceIdentity,
|
|
26
|
-
sourceNameForMemory,
|
|
27
|
-
managedAuthorityNoteRow
|
|
28
|
-
} from "./index-pb3ea2tq.js";
|
|
29
|
-
import {
|
|
30
|
-
scheduleAfterBootQuiet
|
|
31
|
-
} from "./index-48twbev2.js";
|
|
15
|
+
} from "./index-gymgz20n.js";
|
|
32
16
|
import {
|
|
33
17
|
SubcClient
|
|
34
|
-
} from "./index-
|
|
18
|
+
} from "./index-rzfr7wdv.js";
|
|
19
|
+
import {
|
|
20
|
+
inRootAsyncContext2,
|
|
21
|
+
getSqliteDatabasePath2,
|
|
22
|
+
withSqliteBackgroundWriter2,
|
|
23
|
+
indexCoordinationInput2
|
|
24
|
+
} from "./index-2qtx0q6h.js";
|
|
35
25
|
import {
|
|
36
26
|
runSessionWarmupWorker
|
|
37
|
-
} from "./index-
|
|
27
|
+
} from "./index-mkh1cm5k.js";
|
|
38
28
|
import {
|
|
39
29
|
buildCanonicalChunkTextFromFts2,
|
|
40
30
|
loadCompartmentChunkEmbeddingsForSearch2,
|
|
41
31
|
peekCompartmentChunkSearchPool2,
|
|
42
32
|
warmCompartmentChunkSearchPool2
|
|
43
|
-
} from "./index-
|
|
33
|
+
} from "./index-2p691ayw.js";
|
|
44
34
|
import {
|
|
45
|
-
recordEmbeddingMeasurement,
|
|
46
35
|
saveCommitEmbedding,
|
|
47
36
|
loadProjectCommitEmbeddings,
|
|
48
37
|
loadUnembeddedCommits,
|
|
@@ -58,7 +47,13 @@ import {
|
|
|
58
47
|
getProjectEmbeddingSnapshot2,
|
|
59
48
|
embedTextForProject2,
|
|
60
49
|
embedItemsForProject2
|
|
61
|
-
} from "./index-
|
|
50
|
+
} from "./index-a11nmw5t.js";
|
|
51
|
+
import {
|
|
52
|
+
recordEmbeddingMeasurement
|
|
53
|
+
} from "./index-hgd00nas.js";
|
|
54
|
+
import {
|
|
55
|
+
scheduleAfterBootQuiet
|
|
56
|
+
} from "./index-6pk49fc3.js";
|
|
62
57
|
import {
|
|
63
58
|
saveEmbeddingIfHashMatches,
|
|
64
59
|
getProjectEmbeddings2
|
|
@@ -68,7 +63,7 @@ import {
|
|
|
68
63
|
isEmbeddingEnabled,
|
|
69
64
|
embedText,
|
|
70
65
|
ensureMemoryEmbeddings2
|
|
71
|
-
} from "./index-
|
|
66
|
+
} from "./index-vgfk2xa5.js";
|
|
72
67
|
import {
|
|
73
68
|
getMemorySelectColumns2,
|
|
74
69
|
isMemoryRow2,
|
|
@@ -96,11 +91,22 @@ import {
|
|
|
96
91
|
clearIndexedMessages,
|
|
97
92
|
indexSingleMessage,
|
|
98
93
|
indexMessagesAfterOrdinal
|
|
99
|
-
} from "./index-
|
|
94
|
+
} from "./index-8m82cez2.js";
|
|
100
95
|
import {
|
|
101
96
|
MESSAGE_FTS_SESSION_FILTER_SQL,
|
|
102
97
|
withMessageFtsSessionFilter
|
|
103
98
|
} from "./index-1cvyaw9a.js";
|
|
99
|
+
import {
|
|
100
|
+
resolveWorkspaceShareCategories,
|
|
101
|
+
resolveWorkspaceIdentitySet,
|
|
102
|
+
expandWorkspaceIdentitySetWithAliases,
|
|
103
|
+
resolveStoredPathWorkspaceIdentity,
|
|
104
|
+
sourceNameForMemory
|
|
105
|
+
} from "./index-d107f484.js";
|
|
106
|
+
import {
|
|
107
|
+
getNotes,
|
|
108
|
+
getActivePrimers
|
|
109
|
+
} from "./index-w26zvs1q.js";
|
|
104
110
|
import {
|
|
105
111
|
computeNormalizedHash
|
|
106
112
|
} from "./index-9x1f96r8.js";
|
|
@@ -108,523 +114,6 @@ import {
|
|
|
108
114
|
isKnownAutocommit
|
|
109
115
|
} from "./index-nrzkqte4.js";
|
|
110
116
|
|
|
111
|
-
// ../plugin/src/features/magic-context/storage-notes.ts
|
|
112
|
-
var NOTE_TYPES = new Set(["session", "smart"]);
|
|
113
|
-
var NOTE_STATUSES = new Set(["active", "pending", "ready", "dismissed"]);
|
|
114
|
-
var NOTE_CHECK_STATUSES = new Set([
|
|
115
|
-
"uncompiled",
|
|
116
|
-
"compiled",
|
|
117
|
-
"failing",
|
|
118
|
-
"fallback",
|
|
119
|
-
"parked"
|
|
120
|
-
]);
|
|
121
|
-
var CONDITION_COMPILE_STATUSES = new Set([
|
|
122
|
-
"compiled",
|
|
123
|
-
"plain",
|
|
124
|
-
"refused"
|
|
125
|
-
]);
|
|
126
|
-
var DEFAULT_SMART_STATUSES = ["pending", "ready"];
|
|
127
|
-
function toNullableString(value) {
|
|
128
|
-
return typeof value === "string" && value.length > 0 ? value : null;
|
|
129
|
-
}
|
|
130
|
-
function toNullableNumber(value) {
|
|
131
|
-
return typeof value === "number" ? value : null;
|
|
132
|
-
}
|
|
133
|
-
function isNoteRow(row) {
|
|
134
|
-
if (row === null || typeof row !== "object")
|
|
135
|
-
return false;
|
|
136
|
-
const candidate = row;
|
|
137
|
-
return typeof candidate.id === "number" && typeof candidate.type === "string" && NOTE_TYPES.has(candidate.type) && typeof candidate.status === "string" && NOTE_STATUSES.has(candidate.status) && typeof candidate.content === "string" && (candidate.session_id === null || typeof candidate.session_id === "string") && (candidate.project_path === null || typeof candidate.project_path === "string") && (candidate.surface_condition === null || typeof candidate.surface_condition === "string") && typeof candidate.created_at === "number" && typeof candidate.updated_at === "number" && (candidate.last_checked_at === null || typeof candidate.last_checked_at === "number") && (candidate.ready_at === null || typeof candidate.ready_at === "number") && (candidate.ready_reason === null || typeof candidate.ready_reason === "string");
|
|
138
|
-
}
|
|
139
|
-
function toNote(row) {
|
|
140
|
-
return {
|
|
141
|
-
id: row.id,
|
|
142
|
-
type: row.type,
|
|
143
|
-
status: row.status,
|
|
144
|
-
content: row.content,
|
|
145
|
-
sessionId: toNullableString(row.session_id),
|
|
146
|
-
projectPath: toNullableString(row.project_path),
|
|
147
|
-
surfaceCondition: toNullableString(row.surface_condition),
|
|
148
|
-
compiledProvider: toNullableString(row.compiled_provider),
|
|
149
|
-
compiledConfig: toNullableString(row.compiled_config),
|
|
150
|
-
compiledAt: toNullableNumber(row.compiled_at),
|
|
151
|
-
compileStatus: typeof row.compile_status === "string" && CONDITION_COMPILE_STATUSES.has(row.compile_status) ? row.compile_status : null,
|
|
152
|
-
createdAt: row.created_at,
|
|
153
|
-
updatedAt: row.updated_at,
|
|
154
|
-
lastCheckedAt: toNullableNumber(row.last_checked_at),
|
|
155
|
-
readyAt: toNullableNumber(row.ready_at),
|
|
156
|
-
readyReason: toNullableString(row.ready_reason),
|
|
157
|
-
anchorOrdinal: toNullableNumber(row.anchor_ordinal),
|
|
158
|
-
compiledCheck: toNullableString(row.compiled_check),
|
|
159
|
-
manifestJson: toNullableString(row.manifest_json),
|
|
160
|
-
checkHash: toNullableString(row.check_hash),
|
|
161
|
-
checkCron: toNullableString(row.check_cron),
|
|
162
|
-
checkVersion: toNullableNumber(row.check_version),
|
|
163
|
-
checkStatus: typeof row.check_status === "string" && NOTE_CHECK_STATUSES.has(row.check_status) ? row.check_status : null,
|
|
164
|
-
checkFailureCount: toNullableNumber(row.check_failure_count) ?? 0,
|
|
165
|
-
checkNetworkFailureCount: toNullableNumber(row.check_network_failure_count) ?? 0,
|
|
166
|
-
checkQuarantinedUntil: toNullableNumber(row.check_quarantined_until),
|
|
167
|
-
checkNextDueAt: toNullableNumber(row.check_next_due_at),
|
|
168
|
-
checkCompiledAt: toNullableNumber(row.check_compiled_at),
|
|
169
|
-
checkFalseSinceAt: toNullableNumber(row.check_false_since_at),
|
|
170
|
-
checkLastLivenessAt: toNullableNumber(row.check_last_liveness_at),
|
|
171
|
-
policyVersion: toNullableNumber(row.policy_version)
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function noteCheckColumnsExist(db) {
|
|
175
|
-
try {
|
|
176
|
-
const rows = db.prepare("PRAGMA table_info(notes)").all();
|
|
177
|
-
return rows.some((row) => row.name === "compiled_check");
|
|
178
|
-
} catch {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
var PENDING_SESSION_NOTE_PREDICATE = "type = 'session' AND status = 'pending' AND surface_condition IS NOT NULL";
|
|
183
|
-
function healPendingSessionNotes(db) {
|
|
184
|
-
let predicate = `${PENDING_SESSION_NOTE_PREDICATE} AND NOT ${managedAuthorityNoteRow("notes")}`;
|
|
185
|
-
let healable;
|
|
186
|
-
try {
|
|
187
|
-
healable = db.prepare(`SELECT 1 FROM notes WHERE ${predicate} LIMIT 1`).get();
|
|
188
|
-
} catch (error) {
|
|
189
|
-
if (!(error instanceof Error) || !error.message.includes("no such table"))
|
|
190
|
-
throw error;
|
|
191
|
-
predicate = PENDING_SESSION_NOTE_PREDICATE;
|
|
192
|
-
healable = db.prepare(`SELECT 1 FROM notes WHERE ${predicate} LIMIT 1`).get();
|
|
193
|
-
}
|
|
194
|
-
if (healable == null)
|
|
195
|
-
return;
|
|
196
|
-
try {
|
|
197
|
-
db.prepare(`UPDATE notes SET status = 'active', surface_condition = NULL WHERE ${predicate}`).run();
|
|
198
|
-
} catch (error) {
|
|
199
|
-
if (!isTransientSqliteError2(error))
|
|
200
|
-
throw error;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
function getNoteById(db, noteId) {
|
|
204
|
-
healPendingSessionNotes(db);
|
|
205
|
-
const row = db.prepare("SELECT * FROM notes WHERE id = ?").get(noteId);
|
|
206
|
-
return isNoteRow(row) ? toNote(row) : null;
|
|
207
|
-
}
|
|
208
|
-
function getNoteByIdInScope(db, noteId, scope) {
|
|
209
|
-
const note = getNoteById(db, noteId);
|
|
210
|
-
return note && noteBelongsToScope(note, scope) ? note : null;
|
|
211
|
-
}
|
|
212
|
-
function noteBelongsToScope(note, scope) {
|
|
213
|
-
if (note.type === "session") {
|
|
214
|
-
return note.sessionId === scope.sessionId;
|
|
215
|
-
}
|
|
216
|
-
return note.projectPath === scope.projectPath;
|
|
217
|
-
}
|
|
218
|
-
function buildStatusClause(status) {
|
|
219
|
-
if (status === undefined) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
const statuses = Array.isArray(status) ? status : [status];
|
|
223
|
-
if (statuses.length === 0) {
|
|
224
|
-
return null;
|
|
225
|
-
}
|
|
226
|
-
const placeholders = statuses.map(() => "?").join(", ");
|
|
227
|
-
return {
|
|
228
|
-
sql: `status IN (${placeholders})`,
|
|
229
|
-
params: statuses
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function getNotes(db, options = {}) {
|
|
233
|
-
healPendingSessionNotes(db);
|
|
234
|
-
const clauses = [];
|
|
235
|
-
const params = [];
|
|
236
|
-
if (options.sessionId !== undefined) {
|
|
237
|
-
clauses.push("session_id = ?");
|
|
238
|
-
params.push(options.sessionId);
|
|
239
|
-
}
|
|
240
|
-
if (options.projectPath !== undefined) {
|
|
241
|
-
clauses.push("project_path = ?");
|
|
242
|
-
params.push(options.projectPath);
|
|
243
|
-
}
|
|
244
|
-
if (options.type !== undefined) {
|
|
245
|
-
clauses.push("type = ?");
|
|
246
|
-
params.push(options.type);
|
|
247
|
-
}
|
|
248
|
-
const statusClause = buildStatusClause(options.status);
|
|
249
|
-
if (statusClause) {
|
|
250
|
-
clauses.push(statusClause.sql);
|
|
251
|
-
params.push(...statusClause.params);
|
|
252
|
-
}
|
|
253
|
-
const where = clauses.length > 0 ? ` WHERE ${clauses.join(" AND ")}` : "";
|
|
254
|
-
return db.prepare(`SELECT * FROM notes${where} ORDER BY created_at ASC, id ASC`).all(...params).filter(isNoteRow).map(toNote);
|
|
255
|
-
}
|
|
256
|
-
function addNote(db, type, options) {
|
|
257
|
-
const now = Date.now();
|
|
258
|
-
const result = type === "session" ? db.prepare("INSERT INTO notes (type, status, content, session_id, created_at, updated_at, harness, anchor_ordinal) VALUES ('session', 'active', ?, ?, ?, ?, ?, ?) RETURNING *").get(options.content, options.sessionId, now, now, getHarness2(), options.anchorOrdinal ?? null) : db.prepare("INSERT INTO notes (type, status, content, session_id, project_path, surface_condition, compiled_provider, compiled_config, compiled_at, compile_status, created_at, updated_at, harness, anchor_ordinal) VALUES ('smart', 'pending', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *").get(options.content, options.sessionId ?? null, options.projectPath, options.surfaceCondition, options.compiledProvider ?? null, options.compiledConfig ?? null, options.compiledAt ?? null, options.compileStatus ?? null, now, now, getHarness2(), options.anchorOrdinal ?? null);
|
|
259
|
-
if (!isNoteRow(result)) {
|
|
260
|
-
throw new Error("[notes] failed to insert note");
|
|
261
|
-
}
|
|
262
|
-
return toNote(result);
|
|
263
|
-
}
|
|
264
|
-
function getSessionNotes(db, sessionId) {
|
|
265
|
-
return getNotes(db, { sessionId, type: "session", status: "active" });
|
|
266
|
-
}
|
|
267
|
-
function getSmartNotes(db, projectPath, status) {
|
|
268
|
-
return getNotes(db, {
|
|
269
|
-
projectPath,
|
|
270
|
-
type: "smart",
|
|
271
|
-
status: status ?? DEFAULT_SMART_STATUSES
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
function getPendingSmartNotes(db, projectPath) {
|
|
275
|
-
return getSmartNotes(db, projectPath, "pending");
|
|
276
|
-
}
|
|
277
|
-
function getReadySmartNotes(db, projectPath) {
|
|
278
|
-
return getSmartNotes(db, projectPath, "ready");
|
|
279
|
-
}
|
|
280
|
-
function updateNote(db, noteId, updates, scope) {
|
|
281
|
-
const existing = getNoteByIdInScope(db, noteId, scope);
|
|
282
|
-
if (!existing) {
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
if (updates.surfaceCondition !== undefined && existing.type !== "smart") {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
const now = Date.now();
|
|
289
|
-
const sets = ["updated_at = ?"];
|
|
290
|
-
const params = [now];
|
|
291
|
-
if (updates.content !== undefined) {
|
|
292
|
-
sets.push("content = ?");
|
|
293
|
-
params.push(updates.content);
|
|
294
|
-
}
|
|
295
|
-
if (updates.sessionId !== undefined) {
|
|
296
|
-
sets.push("session_id = ?");
|
|
297
|
-
params.push(updates.sessionId);
|
|
298
|
-
}
|
|
299
|
-
const smartConditionChanged = existing.type === "smart" && updates.surfaceCondition !== undefined && updates.surfaceCondition !== existing.surfaceCondition;
|
|
300
|
-
if (updates.status !== undefined && !smartConditionChanged) {
|
|
301
|
-
sets.push("status = ?");
|
|
302
|
-
params.push(updates.status);
|
|
303
|
-
}
|
|
304
|
-
if (existing.type === "smart") {
|
|
305
|
-
if (updates.projectPath !== undefined) {
|
|
306
|
-
sets.push("project_path = ?");
|
|
307
|
-
params.push(updates.projectPath);
|
|
308
|
-
}
|
|
309
|
-
if (updates.surfaceCondition !== undefined) {
|
|
310
|
-
sets.push("surface_condition = ?");
|
|
311
|
-
params.push(updates.surfaceCondition);
|
|
312
|
-
}
|
|
313
|
-
if (smartConditionChanged) {
|
|
314
|
-
sets.push("status = 'pending'", "last_checked_at = NULL", "ready_at = NULL", "ready_reason = NULL");
|
|
315
|
-
sets.push("compiled_provider = ?", "compiled_config = ?", "compiled_at = ?", "compile_status = ?");
|
|
316
|
-
params.push(updates.compiledProvider ?? null, updates.compiledConfig ?? null, updates.compiledAt ?? null, updates.compileStatus ?? null);
|
|
317
|
-
if (noteCheckColumnsExist(db)) {
|
|
318
|
-
sets.push("compiled_check = NULL", "manifest_json = NULL", "check_hash = NULL", "check_cron = NULL", "check_version = 0", "check_status = 'uncompiled'", "check_failure_count = 0", "check_network_failure_count = 0", "check_quarantined_until = NULL", "check_next_due_at = NULL", "check_compiled_at = NULL", "check_false_since_at = NULL", "check_last_liveness_at = NULL");
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
if (updates.lastCheckedAt !== undefined) {
|
|
322
|
-
sets.push("last_checked_at = ?");
|
|
323
|
-
params.push(updates.lastCheckedAt);
|
|
324
|
-
}
|
|
325
|
-
if (updates.readyAt !== undefined) {
|
|
326
|
-
sets.push("ready_at = ?");
|
|
327
|
-
params.push(updates.readyAt);
|
|
328
|
-
}
|
|
329
|
-
if (updates.readyReason !== undefined) {
|
|
330
|
-
sets.push("ready_reason = ?");
|
|
331
|
-
params.push(updates.readyReason);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if (sets.length === 1) {
|
|
336
|
-
return null;
|
|
337
|
-
}
|
|
338
|
-
params.push(noteId);
|
|
339
|
-
const result = db.prepare(`UPDATE notes SET ${sets.join(", ")} WHERE id = ? RETURNING *`).get(...params);
|
|
340
|
-
return isNoteRow(result) ? toNote(result) : null;
|
|
341
|
-
}
|
|
342
|
-
function dismissNotes(db, noteIds, scope) {
|
|
343
|
-
const now = Date.now();
|
|
344
|
-
return db.transaction(() => noteIds.map((noteId) => {
|
|
345
|
-
const existing = getNoteById(db, noteId);
|
|
346
|
-
if (!existing)
|
|
347
|
-
return { noteId, outcome: "not_found" };
|
|
348
|
-
if (!noteBelongsToScope(existing, scope)) {
|
|
349
|
-
return { noteId, outcome: "not_owned" };
|
|
350
|
-
}
|
|
351
|
-
if (existing.status === "dismissed") {
|
|
352
|
-
return { noteId, outcome: "already_dismissed" };
|
|
353
|
-
}
|
|
354
|
-
const result = db.prepare("UPDATE notes SET status = 'dismissed', updated_at = ? WHERE id = ? AND status != 'dismissed'").run(now, noteId);
|
|
355
|
-
return {
|
|
356
|
-
noteId,
|
|
357
|
-
outcome: result.changes > 0 ? "dismissed" : "already_dismissed"
|
|
358
|
-
};
|
|
359
|
-
})).immediate();
|
|
360
|
-
}
|
|
361
|
-
function dismissNote(db, noteId, scope) {
|
|
362
|
-
return dismissNotes(db, [noteId], scope)[0]?.outcome === "dismissed";
|
|
363
|
-
}
|
|
364
|
-
function markNoteReady(db, noteId, reason) {
|
|
365
|
-
const now = Date.now();
|
|
366
|
-
db.prepare("UPDATE notes SET status = 'ready', ready_at = ?, ready_reason = ?, updated_at = ?, last_checked_at = ? WHERE id = ? AND type = 'smart'").run(now, reason ?? null, now, now, noteId);
|
|
367
|
-
}
|
|
368
|
-
function markNoteChecked(db, noteId) {
|
|
369
|
-
const now = Date.now();
|
|
370
|
-
db.prepare("UPDATE notes SET last_checked_at = ?, updated_at = ? WHERE id = ? AND type = 'smart'").run(now, now, noteId);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// ../plugin/src/features/magic-context/storage-primers.ts
|
|
374
|
-
var PRIMER_CANDIDATE_TTL_MS = 90 * 24 * 60 * 60 * 1000;
|
|
375
|
-
var PRIMER_CANDIDATE_MAX_AGE_MS = 180 * 24 * 60 * 60 * 1000;
|
|
376
|
-
function normalizePrimerQuestion(question) {
|
|
377
|
-
return question.trim().toLowerCase().replace(/[“”]/g, '"').replace(/[’]/g, "'").replace(/\s+/g, " ").replace(/[?.!]+$/g, "").trim();
|
|
378
|
-
}
|
|
379
|
-
function primerOccurrenceKey(candidate) {
|
|
380
|
-
return [
|
|
381
|
-
candidate.projectPath,
|
|
382
|
-
candidate.harness,
|
|
383
|
-
candidate.sessionId,
|
|
384
|
-
candidate.sourceStartMessageId,
|
|
385
|
-
candidate.sourceEndMessageId
|
|
386
|
-
].join("\x1F");
|
|
387
|
-
}
|
|
388
|
-
function primerOccurrenceUtcDay(sourceMessageTime) {
|
|
389
|
-
return new Date(sourceMessageTime).toISOString().slice(0, 10);
|
|
390
|
-
}
|
|
391
|
-
function vectorBlob(vector) {
|
|
392
|
-
if (!vector)
|
|
393
|
-
return null;
|
|
394
|
-
return new Uint8Array(vector.buffer, vector.byteOffset, vector.byteLength);
|
|
395
|
-
}
|
|
396
|
-
function blobToFloat32Array(value) {
|
|
397
|
-
if (!value)
|
|
398
|
-
return null;
|
|
399
|
-
const bytes = value instanceof ArrayBuffer ? new Uint8Array(value) : value;
|
|
400
|
-
return new Float32Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
|
|
401
|
-
}
|
|
402
|
-
function parseCandidateIds(raw) {
|
|
403
|
-
if (!raw)
|
|
404
|
-
return [];
|
|
405
|
-
try {
|
|
406
|
-
const parsed = JSON.parse(raw);
|
|
407
|
-
return Array.isArray(parsed) ? parsed.filter((id) => typeof id === "number" && Number.isFinite(id)) : [];
|
|
408
|
-
} catch {
|
|
409
|
-
return [];
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
function parsePrimerSourceProvenance(raw) {
|
|
413
|
-
if (raw === null)
|
|
414
|
-
return null;
|
|
415
|
-
try {
|
|
416
|
-
const parsed = JSON.parse(raw);
|
|
417
|
-
if (!Array.isArray(parsed))
|
|
418
|
-
return null;
|
|
419
|
-
const provenance = [];
|
|
420
|
-
for (const value of parsed) {
|
|
421
|
-
if (!value || typeof value !== "object")
|
|
422
|
-
return null;
|
|
423
|
-
const source = value;
|
|
424
|
-
if (typeof source.candidate_id !== "number" || !Number.isFinite(source.candidate_id) || typeof source.project_path !== "string" || typeof source.harness !== "string" || typeof source.session_id !== "string" || source.source_compartment_start !== null && typeof source.source_compartment_start !== "number" || source.source_compartment_end !== null && typeof source.source_compartment_end !== "number" || typeof source.source_start_message_id !== "string" || typeof source.source_end_message_id !== "string") {
|
|
425
|
-
return null;
|
|
426
|
-
}
|
|
427
|
-
provenance.push({
|
|
428
|
-
candidateId: source.candidate_id,
|
|
429
|
-
projectPath: source.project_path,
|
|
430
|
-
harness: source.harness,
|
|
431
|
-
sessionId: source.session_id,
|
|
432
|
-
sourceCompartmentStart: source.source_compartment_start,
|
|
433
|
-
sourceCompartmentEnd: source.source_compartment_end,
|
|
434
|
-
sourceStartMessageId: source.source_start_message_id,
|
|
435
|
-
sourceEndMessageId: source.source_end_message_id
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
return provenance;
|
|
439
|
-
} catch {
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
function loadPrimerSourceProvenance(db, candidateIds) {
|
|
444
|
-
const ids = [...new Set(candidateIds)].sort((a, b) => a - b);
|
|
445
|
-
if (ids.length === 0)
|
|
446
|
-
return [];
|
|
447
|
-
const placeholders = ids.map(() => "?").join(",");
|
|
448
|
-
const rows = db.prepare(`SELECT id, project_path, harness, session_id,
|
|
449
|
-
source_compartment_start, source_compartment_end,
|
|
450
|
-
source_start_message_id, source_end_message_id
|
|
451
|
-
FROM primer_candidates
|
|
452
|
-
WHERE id IN (${placeholders})
|
|
453
|
-
ORDER BY id ASC`).all(...ids);
|
|
454
|
-
return rows.map((row) => ({
|
|
455
|
-
candidateId: row.id,
|
|
456
|
-
projectPath: row.project_path,
|
|
457
|
-
harness: row.harness,
|
|
458
|
-
sessionId: row.session_id,
|
|
459
|
-
sourceCompartmentStart: row.source_compartment_start,
|
|
460
|
-
sourceCompartmentEnd: row.source_compartment_end,
|
|
461
|
-
sourceStartMessageId: row.source_start_message_id,
|
|
462
|
-
sourceEndMessageId: row.source_end_message_id
|
|
463
|
-
}));
|
|
464
|
-
}
|
|
465
|
-
function serializePrimerSourceProvenance(provenance, sourceCandidateIds) {
|
|
466
|
-
if (provenance.length === 0 && sourceCandidateIds.length > 0)
|
|
467
|
-
return null;
|
|
468
|
-
return JSON.stringify(provenance.map((source) => ({
|
|
469
|
-
candidate_id: source.candidateId,
|
|
470
|
-
project_path: source.projectPath,
|
|
471
|
-
harness: source.harness,
|
|
472
|
-
session_id: source.sessionId,
|
|
473
|
-
source_compartment_start: source.sourceCompartmentStart,
|
|
474
|
-
source_compartment_end: source.sourceCompartmentEnd,
|
|
475
|
-
source_start_message_id: source.sourceStartMessageId,
|
|
476
|
-
source_end_message_id: source.sourceEndMessageId
|
|
477
|
-
})));
|
|
478
|
-
}
|
|
479
|
-
function normalizedCandidateIds(candidateIds) {
|
|
480
|
-
return [...new Set(candidateIds)].sort((a, b) => a - b);
|
|
481
|
-
}
|
|
482
|
-
function toCandidate(row) {
|
|
483
|
-
return {
|
|
484
|
-
id: row.id,
|
|
485
|
-
projectPath: row.project_path,
|
|
486
|
-
harness: row.harness,
|
|
487
|
-
sessionId: row.session_id,
|
|
488
|
-
question: row.question,
|
|
489
|
-
normalizedQuestion: row.normalized_question,
|
|
490
|
-
sourceCompartmentStart: row.source_compartment_start,
|
|
491
|
-
sourceCompartmentEnd: row.source_compartment_end,
|
|
492
|
-
sourceStartMessageId: row.source_start_message_id,
|
|
493
|
-
sourceEndMessageId: row.source_end_message_id,
|
|
494
|
-
sourceMessageTime: row.source_message_time,
|
|
495
|
-
questionEmbedding: blobToFloat32Array(row.question_embedding),
|
|
496
|
-
questionEmbeddingModelId: row.question_embedding_model_id,
|
|
497
|
-
createdAt: row.created_at
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
function toPrimer(row) {
|
|
501
|
-
const status = row.status === "archived" ? "archived" : "active";
|
|
502
|
-
return {
|
|
503
|
-
id: row.id,
|
|
504
|
-
projectPath: row.project_path,
|
|
505
|
-
question: row.question,
|
|
506
|
-
questionEmbedding: blobToFloat32Array(row.question_embedding),
|
|
507
|
-
questionEmbeddingModelId: row.question_embedding_model_id,
|
|
508
|
-
answer: row.answer,
|
|
509
|
-
status,
|
|
510
|
-
totalSupport: row.total_support,
|
|
511
|
-
lastObservedAt: row.last_observed_at,
|
|
512
|
-
answerRefreshedAt: row.answer_refreshed_at,
|
|
513
|
-
sourceCandidateIds: parseCandidateIds(row.source_candidate_ids),
|
|
514
|
-
sourceProvenance: parsePrimerSourceProvenance(row.source_candidate_provenance),
|
|
515
|
-
createdAt: row.created_at,
|
|
516
|
-
updatedAt: row.updated_at
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
function insertPrimerCandidates(db, candidates) {
|
|
520
|
-
const ids = [];
|
|
521
|
-
const stmt = db.prepare(`
|
|
522
|
-
INSERT INTO primer_candidates (
|
|
523
|
-
project_path, harness, session_id, question, normalized_question,
|
|
524
|
-
source_compartment_start, source_compartment_end,
|
|
525
|
-
source_start_message_id, source_end_message_id, source_message_time,
|
|
526
|
-
question_embedding, question_embedding_model_id, created_at
|
|
527
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
528
|
-
ON CONFLICT(project_path, harness, session_id, source_start_message_id, source_end_message_id)
|
|
529
|
-
DO UPDATE SET
|
|
530
|
-
question = excluded.question,
|
|
531
|
-
normalized_question = excluded.normalized_question,
|
|
532
|
-
source_compartment_start = excluded.source_compartment_start,
|
|
533
|
-
source_compartment_end = excluded.source_compartment_end,
|
|
534
|
-
source_message_time = excluded.source_message_time,
|
|
535
|
-
question_embedding = COALESCE(excluded.question_embedding, primer_candidates.question_embedding),
|
|
536
|
-
question_embedding_model_id = COALESCE(excluded.question_embedding_model_id, primer_candidates.question_embedding_model_id),
|
|
537
|
-
created_at = MIN(primer_candidates.created_at, excluded.created_at)
|
|
538
|
-
`);
|
|
539
|
-
const select = db.prepare(`
|
|
540
|
-
SELECT id FROM primer_candidates
|
|
541
|
-
WHERE project_path = ? AND harness = ? AND session_id = ?
|
|
542
|
-
AND source_start_message_id = ? AND source_end_message_id = ?
|
|
543
|
-
`);
|
|
544
|
-
db.transaction(() => {
|
|
545
|
-
for (const candidate of candidates) {
|
|
546
|
-
const question = candidate.question.trim();
|
|
547
|
-
if (!question)
|
|
548
|
-
continue;
|
|
549
|
-
const normalized = candidate.normalizedQuestion ?? normalizePrimerQuestion(question);
|
|
550
|
-
stmt.run(candidate.projectPath, candidate.harness || "opencode", candidate.sessionId, question, normalized, candidate.sourceCompartmentStart ?? null, candidate.sourceCompartmentEnd ?? null, candidate.sourceStartMessageId, candidate.sourceEndMessageId, candidate.sourceMessageTime, vectorBlob(candidate.questionEmbedding), candidate.questionEmbeddingModelId ?? null, candidate.createdAt ?? Date.now());
|
|
551
|
-
const row = select.get(candidate.projectPath, candidate.harness || "opencode", candidate.sessionId, candidate.sourceStartMessageId, candidate.sourceEndMessageId);
|
|
552
|
-
if (typeof row?.id === "number")
|
|
553
|
-
ids.push(row.id);
|
|
554
|
-
}
|
|
555
|
-
}).immediate();
|
|
556
|
-
return ids;
|
|
557
|
-
}
|
|
558
|
-
function updatePrimerCandidateEmbedding(db, candidateId, vector, modelId) {
|
|
559
|
-
db.prepare("UPDATE primer_candidates SET question_embedding = ?, question_embedding_model_id = ? WHERE id = ?").run(vectorBlob(vector), modelId, candidateId);
|
|
560
|
-
}
|
|
561
|
-
function getPrimerCandidatesByIds(db, ids) {
|
|
562
|
-
if (ids.length === 0)
|
|
563
|
-
return [];
|
|
564
|
-
const placeholders = ids.map(() => "?").join(",");
|
|
565
|
-
const rows = db.prepare(`SELECT * FROM primer_candidates WHERE id IN (${placeholders})`).all(...ids);
|
|
566
|
-
return rows.map(toCandidate);
|
|
567
|
-
}
|
|
568
|
-
function getPrimerCandidatesForPromotion(db, projectPath, now = Date.now(), ttlMs = PRIMER_CANDIDATE_TTL_MS) {
|
|
569
|
-
const cutoff = now - ttlMs;
|
|
570
|
-
const rows = db.prepare(`SELECT * FROM primer_candidates
|
|
571
|
-
WHERE project_path = ? AND source_message_time >= ?
|
|
572
|
-
ORDER BY project_path ASC, harness ASC, session_id ASC, source_start_message_id ASC, source_end_message_id ASC, id ASC`).all(projectPath, cutoff);
|
|
573
|
-
return rows.map(toCandidate);
|
|
574
|
-
}
|
|
575
|
-
function countPrimerCandidatesForProject(db, projectPath) {
|
|
576
|
-
const row = db.prepare("SELECT COUNT(*) AS count FROM primer_candidates WHERE project_path = ?").get(projectPath);
|
|
577
|
-
return row?.count ?? 0;
|
|
578
|
-
}
|
|
579
|
-
function getActivePrimers(db, projectPath) {
|
|
580
|
-
const rows = db.prepare(`SELECT * FROM primers
|
|
581
|
-
WHERE project_path = ? AND status = 'active'
|
|
582
|
-
ORDER BY COALESCE(last_observed_at, created_at) DESC, id ASC`).all(projectPath);
|
|
583
|
-
return rows.map(toPrimer);
|
|
584
|
-
}
|
|
585
|
-
function createPrimer(db, input) {
|
|
586
|
-
return db.transaction(() => {
|
|
587
|
-
const now = input.now ?? Date.now();
|
|
588
|
-
const sourceCandidateIds = normalizedCandidateIds(input.sourceCandidateIds);
|
|
589
|
-
const sourceProvenance = loadPrimerSourceProvenance(db, sourceCandidateIds);
|
|
590
|
-
const info = db.prepare(`INSERT INTO primers (
|
|
591
|
-
project_path, question, question_embedding, question_embedding_model_id, answer,
|
|
592
|
-
status, total_support, last_observed_at, answer_refreshed_at,
|
|
593
|
-
source_candidate_ids, source_candidate_provenance, created_at, updated_at
|
|
594
|
-
) VALUES (?, ?, ?, ?, ?, 'active', ?, ?, NULL, ?, ?, ?, ?)`).run(input.projectPath, input.question, vectorBlob(input.questionEmbedding), input.questionEmbeddingModelId ?? null, input.answer ?? "", input.totalSupport, input.lastObservedAt, JSON.stringify(sourceCandidateIds), serializePrimerSourceProvenance(sourceProvenance, sourceCandidateIds), now, now);
|
|
595
|
-
return Number(info.lastInsertRowid);
|
|
596
|
-
}).immediate();
|
|
597
|
-
}
|
|
598
|
-
function updatePrimerSupport(db, input) {
|
|
599
|
-
db.transaction(() => {
|
|
600
|
-
const sourceCandidateIds = normalizedCandidateIds(input.sourceCandidateIds);
|
|
601
|
-
const allowedIds = new Set(sourceCandidateIds);
|
|
602
|
-
const existingRow = db.prepare("SELECT source_candidate_provenance FROM primers WHERE id = ?").get(input.primerId);
|
|
603
|
-
const provenanceByCandidateId = new Map;
|
|
604
|
-
for (const source of parsePrimerSourceProvenance(existingRow?.source_candidate_provenance ?? null) ?? []) {
|
|
605
|
-
if (allowedIds.has(source.candidateId)) {
|
|
606
|
-
provenanceByCandidateId.set(source.candidateId, source);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
for (const source of loadPrimerSourceProvenance(db, sourceCandidateIds)) {
|
|
610
|
-
provenanceByCandidateId.set(source.candidateId, source);
|
|
611
|
-
}
|
|
612
|
-
const sourceProvenance = [...provenanceByCandidateId.values()].sort((a, b) => a.candidateId - b.candidateId);
|
|
613
|
-
db.prepare(`UPDATE primers
|
|
614
|
-
SET question_embedding = COALESCE(?, question_embedding),
|
|
615
|
-
question_embedding_model_id = COALESCE(?, question_embedding_model_id),
|
|
616
|
-
total_support = ?,
|
|
617
|
-
last_observed_at = ?,
|
|
618
|
-
source_candidate_ids = ?,
|
|
619
|
-
source_candidate_provenance = ?,
|
|
620
|
-
updated_at = ?
|
|
621
|
-
WHERE id = ?`).run(vectorBlob(input.questionEmbedding), input.questionEmbeddingModelId ?? null, input.totalSupport, input.lastObservedAt, JSON.stringify(sourceCandidateIds), serializePrimerSourceProvenance(sourceProvenance, sourceCandidateIds), input.now ?? Date.now(), input.primerId);
|
|
622
|
-
}).immediate();
|
|
623
|
-
}
|
|
624
|
-
function updatePrimerAnswer(db, primerId, answer, refreshedAt = Date.now()) {
|
|
625
|
-
db.prepare("UPDATE primers SET answer = ?, answer_refreshed_at = ?, updated_at = ? WHERE id = ?").run(answer, refreshedAt, refreshedAt, primerId);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
117
|
// ../plugin/src/shared/user-facing-codes.ts
|
|
629
118
|
var USER_FACING_FAILURES = {
|
|
630
119
|
historian_unavailable: {
|
|
@@ -2207,6 +1696,32 @@ function invalidateIncrementalWork(sessionId) {
|
|
|
2207
1696
|
}
|
|
2208
1697
|
}
|
|
2209
1698
|
|
|
1699
|
+
// ../plugin/src/features/magic-context/auto-search-diagnostics.ts
|
|
1700
|
+
function createAutoSearchDiagnostics(threshold) {
|
|
1701
|
+
return {
|
|
1702
|
+
threshold,
|
|
1703
|
+
lanes: {},
|
|
1704
|
+
pool: "unknown",
|
|
1705
|
+
poolRows: null,
|
|
1706
|
+
peek: "not-run",
|
|
1707
|
+
workerStarted: false
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
function autoSearchRelevance(query, result) {
|
|
1711
|
+
if (cleanSearchText(result.source === "compartment" ? result.title : result.content).length === 0)
|
|
1712
|
+
return 0;
|
|
1713
|
+
return result.source === "message" || "matchType" in result && result.source !== "compartment" && result.matchType !== "semantic" ? keywordRelevance(query, result.content) : result.score;
|
|
1714
|
+
}
|
|
1715
|
+
function recordAutoSearchLane(diagnostics, lane, query, results) {
|
|
1716
|
+
if (!diagnostics)
|
|
1717
|
+
return;
|
|
1718
|
+
const scores = results.map((result) => result.relevanceScore ?? autoSearchRelevance(query, result));
|
|
1719
|
+
diagnostics.lanes[lane] = {
|
|
1720
|
+
top: scores.length ? Math.max(...scores) : null,
|
|
1721
|
+
nearMisses: scores.filter((score) => score >= 0.5 && score < diagnostics.threshold).length
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
|
|
2210
1725
|
// ../plugin/src/features/magic-context/literal-probes.ts
|
|
2211
1726
|
var MAX_PROBES = 5;
|
|
2212
1727
|
var MIN_PROBE_LENGTH = 3;
|
|
@@ -3644,11 +3159,17 @@ async function searchCompartmentChunks(args) {
|
|
|
3644
3159
|
if (args.limit <= 0 || !args.modelId || args.modelId === "off") {
|
|
3645
3160
|
if (args.timings)
|
|
3646
3161
|
args.timings.chunkPool = "off";
|
|
3162
|
+
if (args.diagnostics)
|
|
3163
|
+
args.diagnostics.pool = "off";
|
|
3164
|
+
args.reportDiagnostics?.();
|
|
3647
3165
|
return [];
|
|
3648
3166
|
}
|
|
3649
3167
|
if (!args.queryEmbedding) {
|
|
3650
3168
|
if (args.timings)
|
|
3651
3169
|
args.timings.chunkPool = "no-vector";
|
|
3170
|
+
if (args.diagnostics)
|
|
3171
|
+
args.diagnostics.pool = "no-vector";
|
|
3172
|
+
args.reportDiagnostics?.();
|
|
3652
3173
|
if (args.warmOnly)
|
|
3653
3174
|
warmCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
|
|
3654
3175
|
return [];
|
|
@@ -3656,15 +3177,25 @@ async function searchCompartmentChunks(args) {
|
|
|
3656
3177
|
const cutoff = args.maxOrdinal != null && args.maxOrdinal >= 0 ? args.maxOrdinal : null;
|
|
3657
3178
|
let rows;
|
|
3658
3179
|
if (args.warmOnly) {
|
|
3659
|
-
const warm = peekCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId, args.dateRange);
|
|
3180
|
+
const warm = peekCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId, args.dateRange, args.diagnostics);
|
|
3660
3181
|
if (warm === null) {
|
|
3661
3182
|
if (args.timings)
|
|
3662
3183
|
args.timings.chunkPool = "cold";
|
|
3184
|
+
if (args.diagnostics) {
|
|
3185
|
+
args.diagnostics.pool = "cold";
|
|
3186
|
+
args.diagnostics.poolRows = 0;
|
|
3187
|
+
}
|
|
3188
|
+
args.reportDiagnostics?.();
|
|
3663
3189
|
warmCompartmentChunkSearchPool2(args.db, args.sessionId, args.projectPath, args.modelId);
|
|
3664
3190
|
return [];
|
|
3665
3191
|
}
|
|
3666
3192
|
if (args.timings)
|
|
3667
3193
|
args.timings.chunkPool = "warm";
|
|
3194
|
+
if (args.diagnostics) {
|
|
3195
|
+
args.diagnostics.pool = "warm";
|
|
3196
|
+
args.diagnostics.poolRows = warm.length;
|
|
3197
|
+
}
|
|
3198
|
+
args.reportDiagnostics?.();
|
|
3668
3199
|
rows = warm;
|
|
3669
3200
|
} else {
|
|
3670
3201
|
try {
|
|
@@ -4034,6 +3565,8 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
|
|
|
4034
3565
|
lanes.message_fts = (outcome.laneResults ?? outcome.results).slice(0, 25);
|
|
4035
3566
|
if (timings)
|
|
4036
3567
|
timings.messageMs = performance.now() - stepStartedAt;
|
|
3568
|
+
recordAutoSearchLane(options.autoSearchDiagnostics, "messages", trimmedQuery, messageResults);
|
|
3569
|
+
options.onAutoSearchDiagnostics?.();
|
|
4037
3570
|
}
|
|
4038
3571
|
stepStartedAt = performance.now();
|
|
4039
3572
|
const capturedQuery = await queryEmbeddingPromise;
|
|
@@ -4051,6 +3584,8 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
|
|
|
4051
3584
|
stepStartedAt = performance.now();
|
|
4052
3585
|
if (timings)
|
|
4053
3586
|
timings.chunkPool = "off";
|
|
3587
|
+
if (options.autoSearchDiagnostics && !runCompartmentChunks)
|
|
3588
|
+
options.autoSearchDiagnostics.pool = "off";
|
|
4054
3589
|
const compartmentResults = runCompartmentChunks ? await searchCompartmentChunks({
|
|
4055
3590
|
db,
|
|
4056
3591
|
sessionId,
|
|
@@ -4062,8 +3597,13 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
|
|
|
4062
3597
|
dateRange,
|
|
4063
3598
|
warmOnly: options.chunkPoolWarmOnly,
|
|
4064
3599
|
signal: options.signal,
|
|
4065
|
-
timings
|
|
3600
|
+
timings,
|
|
3601
|
+
diagnostics: options.autoSearchDiagnostics,
|
|
3602
|
+
reportDiagnostics: options.onAutoSearchDiagnostics
|
|
4066
3603
|
}) : [];
|
|
3604
|
+
if (runCompartmentChunks)
|
|
3605
|
+
recordAutoSearchLane(options.autoSearchDiagnostics, "summaries", trimmedQuery, compartmentResults);
|
|
3606
|
+
options.onAutoSearchDiagnostics?.();
|
|
4067
3607
|
if (timings && runCompartmentChunks)
|
|
4068
3608
|
timings.chunkMs = performance.now() - stepStartedAt;
|
|
4069
3609
|
stepStartedAt = performance.now();
|
|
@@ -4124,6 +3664,11 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
|
|
|
4124
3664
|
]);
|
|
4125
3665
|
if (timings)
|
|
4126
3666
|
timings.otherLanesMs = performance.now() - stepStartedAt;
|
|
3667
|
+
if (runMemory)
|
|
3668
|
+
recordAutoSearchLane(options.autoSearchDiagnostics, "memory", trimmedQuery, memoryOutcome.results);
|
|
3669
|
+
if (runGitCommits)
|
|
3670
|
+
recordAutoSearchLane(options.autoSearchDiagnostics, "git", trimmedQuery, gitCommitResults);
|
|
3671
|
+
options.onAutoSearchDiagnostics?.();
|
|
4127
3672
|
if (options.diagnostics) {
|
|
4128
3673
|
options.diagnostics.suppressedVisibleMemoryIds = memoryOutcome.suppressedVisibleIds;
|
|
4129
3674
|
}
|
|
@@ -4186,7 +3731,7 @@ async function unifiedSearch2(db, sessionId, projectPath, query, options = {}) {
|
|
|
4186
3731
|
if (options.autoHint) {
|
|
4187
3732
|
return results.map((result) => ({
|
|
4188
3733
|
...result,
|
|
4189
|
-
relevanceScore:
|
|
3734
|
+
relevanceScore: autoSearchRelevance(trimmedQuery, result)
|
|
4190
3735
|
}));
|
|
4191
3736
|
}
|
|
4192
3737
|
return results;
|
|
@@ -4309,4 +3854,4 @@ ${bodyParts.join(`
|
|
|
4309
3854
|
`)}`;
|
|
4310
3855
|
}
|
|
4311
3856
|
|
|
4312
|
-
export {
|
|
3857
|
+
export { USER_FACING_FAILURES, renderUserFacingFailure, userFacingFailureCode, renderCapabilityRefusal, renderDreamFailure, dreamFailureCode, renderEmbeddingFailure, renderSingleStoreMigrationRequiredRefusal, SingleStoreMigrationRequiredError, projectNeedsSingleStoreMigration, promoteSessionFactsDurable, embedPromotedFacts, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, indexCommitsForProject, embedUnembeddedCommits, getMessageIndexEpoch, isMessageIndexSearchable, scheduleReconciliation, scheduleIncrementalIndex, scheduleClearAndReindex, clearSessionTracking, createAutoSearchDiagnostics, createUnifiedSearchDiagnostics2, searchMessageHistory2, parseIdShapedQuery2, resolveMemoriesByIdsForSearch2, unifiedSearch2, formatSearchResults2 };
|