@cortexkit/pi-magic-context 0.49.15 → 0.49.16
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 +3 -3
- package/dist/chunk-embedding-write-worker.js +8 -6
- package/dist/{embedding-backfill-7kj16fh9.js → embedding-backfill-c4bdw8pp.js} +10 -8
- package/dist/embedding-worker.js +2 -2
- package/dist/index-1cvyaw9a.js +58 -0
- package/dist/{index-hshd96pt.js → index-4178cbfw.js} +19 -68
- package/dist/{index-75ah9413.js → index-44h64qza.js} +3 -3
- package/dist/{index-9jvktm7k.js → index-657xh9w4.js} +1 -1
- package/dist/{index-7qc73yk5.js → index-afy3dzf9.js} +3 -3
- package/dist/{index-1k729e4f.js → index-bxmf4dhr.js} +6 -6
- package/dist/{index-j0n09wtp.js → index-dne4ja7a.js} +7 -5
- package/dist/{index-a4pk5yv9.js → index-fhyy4ave.js} +14 -14
- package/dist/index-ja1c33qa.js +62 -0
- package/dist/{index-1mrvw9en.js → index-mx59cve4.js} +1 -1
- package/dist/{index-nwbhe6qv.js → index-n3r2d2pr.js} +5 -5
- package/dist/{index-7wagp5jp.js → index-p3evwech.js} +3 -3
- package/dist/{index-he9s4qsj.js → index-qqxqwqhp.js} +22 -2
- package/dist/{index-djxc8w8c.js → index-s1xn8qfw.js} +21 -25
- package/dist/{index-bet4sd3e.js → index-tympym62.js} +1 -1
- package/dist/{index-ccsscaap.js → index-v8d4vgam.js} +37 -16
- package/dist/index-wrr9rp9a.js +16 -0
- package/dist/{index-1vw4f2pe.js → index-x3k1530z.js} +5 -7
- package/dist/{index-0awvkeb5.js → index-xmzhrht0.js} +10 -61
- package/dist/{index-6ex901g3.js → index-y5c73caa.js} +2 -2
- package/dist/index.js +183 -130
- package/dist/message-fts-rowid-map-mbanfkt1.js +22 -0
- package/dist/{message-index-bounded-z4d3x9ty.js → message-index-bounded-xzerjxmp.js} +7 -7
- package/dist/{message-index-dw4z9efj.js → message-index-easvmz22.js} +8 -8
- package/dist/{message-time-backfill-r2ar1qvk.js → message-time-backfill-3q4kemfc.js} +4 -4
- package/dist/migration-worker.js +6 -4
- package/dist/{project-embedding-registry-52zwmtbn.js → project-embedding-registry-xwnmqmx8.js} +9 -7
- package/dist/raw-ordinal-warmup-worker.js +37 -7
- package/dist/{read-session-chunk-0fsgg2k1.js → read-session-chunk-1sb5n7zs.js} +5 -5
- package/dist/{read-session-raw-azkqjgzg.js → read-session-raw-jz5e9jz0.js} +1 -1
- package/dist/search-archive-3ma5n0wr.js +20 -0
- package/dist/{search-ddbz6v60.js → search-x3fa0561.js} +16 -15
- package/dist/{storage-tags-3kb5tvgg.js → storage-tags-jtessrec.js} +1 -1
- package/dist/subagent-entry.js +19 -17
- package/dist/tag-snapshot-worker-pi.js +15 -18
- package/package.json +1 -1
|
@@ -18,11 +18,11 @@ var [
|
|
|
18
18
|
{ Database, registerSqliteDiagnosticSink },
|
|
19
19
|
{ log }
|
|
20
20
|
] = await Promise.all([
|
|
21
|
-
import("./embedding-backfill-
|
|
21
|
+
import("./embedding-backfill-c4bdw8pp.js"),
|
|
22
22
|
import("./embedding-cache-7rp4gqzr.js"),
|
|
23
23
|
import("./storage-memory-axnsk5t1.js"),
|
|
24
|
-
import("./project-embedding-registry-
|
|
25
|
-
import("./search-
|
|
24
|
+
import("./project-embedding-registry-xwnmqmx8.js"),
|
|
25
|
+
import("./search-x3fa0561.js"),
|
|
26
26
|
import("./embedding-activity-ew6dshfd.js"),
|
|
27
27
|
import("./harness-9872e0ym.js"),
|
|
28
28
|
import("./sqlite-adjpy399.js"),
|
|
@@ -10,26 +10,28 @@ import {
|
|
|
10
10
|
import"./index-g4jf772p.js";
|
|
11
11
|
import"./index-7bqrfyny.js";
|
|
12
12
|
import"./index-6dz2ed1v.js";
|
|
13
|
-
import"./index-
|
|
13
|
+
import"./index-399p688g.js";
|
|
14
|
+
import"./index-qqxqwqhp.js";
|
|
15
|
+
import"./index-s1xn8qfw.js";
|
|
14
16
|
import {
|
|
15
17
|
replaceCompartmentChunkEmbeddings,
|
|
16
18
|
recordChunkEmbedBackoff,
|
|
17
19
|
loadUnembeddedSessionChunkCandidates,
|
|
18
20
|
countUnembeddedSessionCompartments
|
|
19
|
-
} from "./index-
|
|
21
|
+
} from "./index-afy3dzf9.js";
|
|
20
22
|
import {
|
|
21
23
|
recordSessionProjectIdentity,
|
|
22
24
|
acquireGitSweepLease,
|
|
23
25
|
renewGitSweepLease,
|
|
24
26
|
releaseGitSweepLease
|
|
25
|
-
} from "./index-
|
|
26
|
-
import"./index-
|
|
27
|
+
} from "./index-mx59cve4.js";
|
|
28
|
+
import"./index-y5c73caa.js";
|
|
27
29
|
import"./index-apgwdby5.js";
|
|
28
30
|
import {
|
|
29
31
|
LATEST_SUPPORTED_VERSION,
|
|
30
32
|
enforceSchemaFence
|
|
31
|
-
} from "./index-
|
|
32
|
-
import"./index-
|
|
33
|
+
} from "./index-v8d4vgam.js";
|
|
34
|
+
import"./index-tympym62.js";
|
|
33
35
|
import"./index-jrap43gc.js";
|
|
34
36
|
import"./index-135e8hvg.js";
|
|
35
37
|
import"./index-8976mezv.js";
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureMemoryEmbeddings2
|
|
3
|
-
} from "./index-
|
|
4
|
-
import"./index-
|
|
3
|
+
} from "./index-p3evwech.js";
|
|
4
|
+
import"./index-n3r2d2pr.js";
|
|
5
5
|
import"./index-9p40dgkm.js";
|
|
6
6
|
import"./index-yhzhdp3m.js";
|
|
7
|
-
import"./index-
|
|
8
|
-
import"./index-
|
|
9
|
-
import"./index-
|
|
7
|
+
import"./index-mx59cve4.js";
|
|
8
|
+
import"./index-afy3dzf9.js";
|
|
9
|
+
import"./index-657xh9w4.js";
|
|
10
10
|
import"./index-6dz2ed1v.js";
|
|
11
|
-
import"./index-
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-
|
|
11
|
+
import"./index-bxmf4dhr.js";
|
|
12
|
+
import"./index-y5c73caa.js";
|
|
13
|
+
import"./index-s1xn8qfw.js";
|
|
14
|
+
import"./index-qqxqwqhp.js";
|
|
15
|
+
import"./index-399p688g.js";
|
|
14
16
|
import"./index-d4dt19md.js";
|
|
15
17
|
import"./index-g4jf772p.js";
|
|
16
18
|
import"./index-asrxgdt4.js";
|
package/dist/embedding-worker.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
log2
|
|
6
6
|
} from "./index-7bqrfyny.js";
|
|
7
|
-
import"./index-
|
|
7
|
+
import"./index-bxmf4dhr.js";
|
|
8
8
|
import"./index-6dz2ed1v.js";
|
|
9
9
|
import"./index-g4jf772p.js";
|
|
10
10
|
import"./index-asrxgdt4.js";
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
resolveLocalEmbeddingWorkerRuntime,
|
|
13
13
|
getLocalEmbeddingNativeMemoryStats,
|
|
14
14
|
LocalEmbeddingProvider
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-657xh9w4.js";
|
|
16
16
|
import {
|
|
17
17
|
setStoragePrivatePermissionEnforcement
|
|
18
18
|
} from "./index-81nthk8j.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// ../plugin/src/features/magic-context/message-fts-session-filter.ts
|
|
2
|
+
var MESSAGE_FTS_SESSION_FILTER_SQL = `+message_history_fts.rowid IN (
|
|
3
|
+
SELECT fts_rowid FROM message_fts_rowid_map WHERE session_id = ?1
|
|
4
|
+
) AND `;
|
|
5
|
+
var coverageCaches = new WeakMap;
|
|
6
|
+
var coverageScansOnThisThread = 0;
|
|
7
|
+
function getCoverageCache(db) {
|
|
8
|
+
let cache = coverageCaches.get(db);
|
|
9
|
+
if (!cache) {
|
|
10
|
+
cache = {
|
|
11
|
+
pin: db.prepare("SELECT fts_rowid FROM message_fts_rowid_map LIMIT 1"),
|
|
12
|
+
stamp: db.prepare("SELECT total_changes() AS changes, data_version AS version FROM pragma_data_version"),
|
|
13
|
+
missing: db.prepare(`SELECT DISTINCT session_id AS sessionId
|
|
14
|
+
FROM message_history_fts WHERE rowid IN (
|
|
15
|
+
SELECT id FROM message_history_fts_docsize
|
|
16
|
+
EXCEPT SELECT fts_rowid FROM message_fts_rowid_map
|
|
17
|
+
)`)
|
|
18
|
+
};
|
|
19
|
+
coverageCaches.set(db, cache);
|
|
20
|
+
}
|
|
21
|
+
return cache;
|
|
22
|
+
}
|
|
23
|
+
function withMessageFtsSessionFilter(db, sessionId, read) {
|
|
24
|
+
let cacheable = false;
|
|
25
|
+
try {
|
|
26
|
+
const transaction = db;
|
|
27
|
+
cacheable = transaction.inTransaction === false || transaction.isTransaction === false;
|
|
28
|
+
if (!cacheable)
|
|
29
|
+
coverageCaches.delete(db);
|
|
30
|
+
} catch {
|
|
31
|
+
coverageCaches.delete(db);
|
|
32
|
+
}
|
|
33
|
+
return db.transaction(() => {
|
|
34
|
+
let sessionFirst = false;
|
|
35
|
+
try {
|
|
36
|
+
const cache = getCoverageCache(db);
|
|
37
|
+
cache.pin.get();
|
|
38
|
+
const stamp = cache.stamp.get();
|
|
39
|
+
let incomplete = cache.incompleteSessions;
|
|
40
|
+
if (!cacheable || !incomplete || cache.version !== stamp.version || cache.changes !== stamp.changes) {
|
|
41
|
+
coverageScansOnThisThread += 1;
|
|
42
|
+
const rows = cache.missing.all();
|
|
43
|
+
incomplete = new Set(rows.map((row) => row.sessionId));
|
|
44
|
+
if (cacheable) {
|
|
45
|
+
cache.version = stamp.version;
|
|
46
|
+
cache.changes = stamp.changes;
|
|
47
|
+
cache.incompleteSessions = incomplete;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
sessionFirst = !incomplete.has(sessionId);
|
|
51
|
+
} catch {
|
|
52
|
+
coverageCaches.delete(db);
|
|
53
|
+
}
|
|
54
|
+
return read(sessionFirst);
|
|
55
|
+
}).deferred();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { MESSAGE_FTS_SESSION_FILTER_SQL, withMessageFtsSessionFilter };
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
PER_HARNESS_MODEL_KEYS,
|
|
21
21
|
ConfigProfilesSchema,
|
|
22
22
|
MagicContextConfigSchema
|
|
23
|
-
} from "./index-
|
|
23
|
+
} from "./index-bxmf4dhr.js";
|
|
24
24
|
import {
|
|
25
25
|
MERGED_REASONING_PARTS_PREFIX,
|
|
26
26
|
decodeMergedReasoningParts,
|
|
@@ -53,10 +53,9 @@ import {
|
|
|
53
53
|
hasRawMessageProvider2,
|
|
54
54
|
setRawMessageProvider2,
|
|
55
55
|
visitRawSessionMessages2,
|
|
56
|
-
readRawSessionMessageIdOrdinalsForRange2,
|
|
57
56
|
readRawSessionMessageById2,
|
|
58
57
|
readSessionChunk2
|
|
59
|
-
} from "./index-
|
|
58
|
+
} from "./index-44h64qza.js";
|
|
60
59
|
import {
|
|
61
60
|
isRecord,
|
|
62
61
|
providerVisibleMessage,
|
|
@@ -70,7 +69,7 @@ import {
|
|
|
70
69
|
getTagNumberByMessageId2,
|
|
71
70
|
getTagsBySession2,
|
|
72
71
|
getTagById2
|
|
73
|
-
} from "./index-
|
|
72
|
+
} from "./index-dne4ja7a.js";
|
|
74
73
|
import {
|
|
75
74
|
estimateTokens
|
|
76
75
|
} from "./index-g4jf772p.js";
|
|
@@ -91,7 +90,7 @@ import {
|
|
|
91
90
|
} from "./index-8976mezv.js";
|
|
92
91
|
import {
|
|
93
92
|
noteRawSessionSummaryRowWritten2
|
|
94
|
-
} from "./index-
|
|
93
|
+
} from "./index-qqxqwqhp.js";
|
|
95
94
|
import {
|
|
96
95
|
piHarnessKindFromExecutable,
|
|
97
96
|
isPidAlive
|
|
@@ -103,7 +102,7 @@ import {
|
|
|
103
102
|
clearLkgRecoveryFence,
|
|
104
103
|
deleteSessionScopedRows,
|
|
105
104
|
getLastIndexedOrdinal2
|
|
106
|
-
} from "./index-
|
|
105
|
+
} from "./index-fhyy4ave.js";
|
|
107
106
|
import {
|
|
108
107
|
SubcClient,
|
|
109
108
|
connectionFileExists,
|
|
@@ -111,9 +110,6 @@ import {
|
|
|
111
110
|
toSynapseLaneDescriptor,
|
|
112
111
|
SynapseEmbeddingProvider
|
|
113
112
|
} from "./index-6dz2ed1v.js";
|
|
114
|
-
import {
|
|
115
|
-
sameProjectDirectory
|
|
116
|
-
} from "./index-djxc8w8c.js";
|
|
117
113
|
import {
|
|
118
114
|
invalidateAutoEmbedSession,
|
|
119
115
|
drainBackgroundBatches,
|
|
@@ -126,10 +122,10 @@ import {
|
|
|
126
122
|
unregisterProjectEmbedding2,
|
|
127
123
|
getProjectEmbeddingSnapshot2,
|
|
128
124
|
embedTextForProject2
|
|
129
|
-
} from "./index-
|
|
125
|
+
} from "./index-n3r2d2pr.js";
|
|
130
126
|
import {
|
|
131
127
|
getErrorMessage
|
|
132
|
-
} from "./index-
|
|
128
|
+
} from "./index-v8d4vgam.js";
|
|
133
129
|
import {
|
|
134
130
|
V2_MEMORY_CATEGORIES,
|
|
135
131
|
CATEGORY_PRIORITY,
|
|
@@ -143,13 +139,13 @@ import {
|
|
|
143
139
|
expandWorkspaceIdentitySetWithAliases,
|
|
144
140
|
resolveStoredPathWorkspaceIdentity,
|
|
145
141
|
storedPathBelongsToWorkspace
|
|
146
|
-
} from "./index-
|
|
142
|
+
} from "./index-tympym62.js";
|
|
147
143
|
import {
|
|
148
144
|
directoryHasGitMetadata,
|
|
149
145
|
resolveProjectIdentityForSession,
|
|
150
146
|
normalizeStoredProjectPath,
|
|
151
147
|
storedPathBelongsToIdentity
|
|
152
|
-
} from "./index-
|
|
148
|
+
} from "./index-y5c73caa.js";
|
|
153
149
|
import {
|
|
154
150
|
getNoteByIdInScope,
|
|
155
151
|
getNotes,
|
|
@@ -160,13 +156,12 @@ import {
|
|
|
160
156
|
updateNote,
|
|
161
157
|
dismissNotes,
|
|
162
158
|
dismissNote,
|
|
163
|
-
withMessageFtsSessionFilter,
|
|
164
159
|
createUnifiedSearchDiagnostics2,
|
|
165
160
|
parseIdShapedQuery2,
|
|
166
161
|
resolveMemoriesByIdsForSearch2,
|
|
167
162
|
unifiedSearch2,
|
|
168
163
|
formatSearchResults2
|
|
169
|
-
} from "./index-
|
|
164
|
+
} from "./index-xmzhrht0.js";
|
|
170
165
|
import {
|
|
171
166
|
computeCueContentHash,
|
|
172
167
|
getMuralCueState,
|
|
@@ -192,9 +187,15 @@ import {
|
|
|
192
187
|
invalidateMarkerCandidateBasis2,
|
|
193
188
|
readMarkerCandidateBasis2
|
|
194
189
|
} from "./index-46q4e104.js";
|
|
190
|
+
import {
|
|
191
|
+
renderSearchArchive2
|
|
192
|
+
} from "./index-ja1c33qa.js";
|
|
195
193
|
import {
|
|
196
194
|
computeNormalizedHash
|
|
197
195
|
} from "./index-9x1f96r8.js";
|
|
196
|
+
import {
|
|
197
|
+
sameProjectDirectory
|
|
198
|
+
} from "./index-wrr9rp9a.js";
|
|
198
199
|
import {
|
|
199
200
|
logSlowWriteTransaction
|
|
200
201
|
} from "./index-d4dt19md.js";
|
|
@@ -12648,56 +12649,6 @@ function renderItemByTag(db, sessionId, number, textIndexDomain = "part") {
|
|
|
12648
12649
|
return selected ? renderPartFull(selected) ?? "" : `Tag ${number}'s original text part is no longer in stored history.`;
|
|
12649
12650
|
}
|
|
12650
12651
|
|
|
12651
|
-
// ../plugin/src/tools/ctx-expand/search-archive.ts
|
|
12652
|
-
function renderSearchArchive(db, sessionId, start, end, tokenBudget, archiveOnly = false) {
|
|
12653
|
-
return withMessageFtsSessionFilter(db, sessionId, (sessionFirst) => {
|
|
12654
|
-
let rawIds;
|
|
12655
|
-
const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
|
|
12656
|
-
FROM message_fts_rowid_map AS m
|
|
12657
|
-
JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
|
|
12658
|
-
WHERE m.session_id = ?1 AND m.message_ordinal BETWEEN ?2 AND ?3
|
|
12659
|
-
AND f.session_id = ?1 AND f.message_ordinal BETWEEN ?2 AND ?3
|
|
12660
|
-
ORDER BY m.message_ordinal` : `SELECT message_ordinal AS ordinal, message_id AS id, role, content
|
|
12661
|
-
FROM message_history_fts
|
|
12662
|
-
WHERE session_id = ?1 AND message_ordinal BETWEEN ?2 AND ?3
|
|
12663
|
-
ORDER BY CAST(message_ordinal AS INTEGER)`);
|
|
12664
|
-
const blocks = [];
|
|
12665
|
-
let tokens = 0;
|
|
12666
|
-
let lastOrdinal = start - 1;
|
|
12667
|
-
let truncated = false;
|
|
12668
|
-
for (const row of rows.iterate(sessionId, start, end)) {
|
|
12669
|
-
if (!row.content)
|
|
12670
|
-
continue;
|
|
12671
|
-
if (!archiveOnly) {
|
|
12672
|
-
rawIds ??= readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end);
|
|
12673
|
-
if (rawIds.get(row.id) === row.ordinal)
|
|
12674
|
-
continue;
|
|
12675
|
-
}
|
|
12676
|
-
const block = `[${row.ordinal}] ${row.role === "user" ? "U" : "A"}: ${row.content}`;
|
|
12677
|
-
const cost = estimateTokens(block);
|
|
12678
|
-
if (blocks.length > 0 && tokens + cost > tokenBudget) {
|
|
12679
|
-
truncated = true;
|
|
12680
|
-
break;
|
|
12681
|
-
}
|
|
12682
|
-
blocks.push(block);
|
|
12683
|
-
tokens += cost;
|
|
12684
|
-
lastOrdinal = row.ordinal;
|
|
12685
|
-
}
|
|
12686
|
-
if (blocks.length === 0)
|
|
12687
|
-
return null;
|
|
12688
|
-
const text = [
|
|
12689
|
-
"From the search archive: indexed text only; no surrounding messages or tool output.",
|
|
12690
|
-
"",
|
|
12691
|
-
...blocks
|
|
12692
|
-
];
|
|
12693
|
-
if (truncated) {
|
|
12694
|
-
text.push("", `Truncated at message ${lastOrdinal} (budget: ~${tokenBudget} tokens). Call ctx_expand(start=${lastOrdinal + 1}, end=${end}) for more archived text.`);
|
|
12695
|
-
}
|
|
12696
|
-
return text.join(`
|
|
12697
|
-
`);
|
|
12698
|
-
});
|
|
12699
|
-
}
|
|
12700
|
-
|
|
12701
12652
|
// ../plugin/src/tools/unwrap-imitated-reduced-args.ts
|
|
12702
12653
|
var MAX_DECODED_STRING_LENGTH = 1024 * 1024;
|
|
12703
12654
|
var MAX_DECODED_ARRAY_ITEMS = 100;
|
|
@@ -13142,7 +13093,7 @@ function createCtxExpandTool(deps) {
|
|
|
13142
13093
|
}
|
|
13143
13094
|
const alignment = resolvePiOrdinalAlignmentForContext(deps.db, sessionId, ctx);
|
|
13144
13095
|
if (isPiOrdinalAlignmentUnanchored(alignment)) {
|
|
13145
|
-
const archived =
|
|
13096
|
+
const archived = renderSearchArchive2(deps.db, sessionId, mode.kind === "message" ? mode.message : mode.start, mode.kind === "message" ? mode.message : mode.end, CTX_EXPAND_TOKEN_BUDGET, true);
|
|
13146
13097
|
if (archived)
|
|
13147
13098
|
return ok(archived);
|
|
13148
13099
|
return err("This session's history numbering can't be verified right now, so message ordinals can't be expanded. Tags (ctx_expand tag=N) still work.");
|
|
@@ -13150,7 +13101,7 @@ function createCtxExpandTool(deps) {
|
|
|
13150
13101
|
const lostThrough = alignment.offset;
|
|
13151
13102
|
const firstAvailable = lostThrough + 1;
|
|
13152
13103
|
if (mode.kind === "message") {
|
|
13153
|
-
const archived =
|
|
13104
|
+
const archived = renderSearchArchive2(deps.db, sessionId, mode.message, mode.message, CTX_EXPAND_TOKEN_BUDGET);
|
|
13154
13105
|
if (archived)
|
|
13155
13106
|
return ok(archived);
|
|
13156
13107
|
if (mode.message <= lostThrough) {
|
|
@@ -13165,7 +13116,7 @@ function createCtxExpandTool(deps) {
|
|
|
13165
13116
|
return ok(`Range ${requestedStart}-${end} is entirely within the live tail (after the last compacted message ${lastCompartmentEnd}); those messages are already visible in context.`);
|
|
13166
13117
|
}
|
|
13167
13118
|
const effectiveEnd = lastCompartmentEnd >= 0 ? Math.min(end, lastCompartmentEnd) : end;
|
|
13168
|
-
const archived =
|
|
13119
|
+
const archived = renderSearchArchive2(deps.db, sessionId, requestedStart, effectiveEnd, CTX_EXPAND_TOKEN_BUDGET);
|
|
13169
13120
|
if (archived)
|
|
13170
13121
|
return ok(archived);
|
|
13171
13122
|
if (effectiveEnd <= lostThrough) {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
renderToolTemplate,
|
|
5
5
|
resolveModelConfigValue,
|
|
6
6
|
deriveDefaultProtectedTokens
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-bxmf4dhr.js";
|
|
8
8
|
import {
|
|
9
9
|
getHarness2,
|
|
10
10
|
harnessOwnsOpenCodeStore2
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
TAG_SELECT_COLUMNS2,
|
|
24
24
|
getCandidateToolOwners2,
|
|
25
25
|
pickNearestPriorOwner2
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-dne4ja7a.js";
|
|
27
27
|
import {
|
|
28
28
|
OMO_INTERNAL_INITIATOR_MARKER,
|
|
29
29
|
isSystemDirective,
|
|
@@ -71,7 +71,7 @@ import {
|
|
|
71
71
|
hasRawSessionMessageByIdFromDb2,
|
|
72
72
|
readRawSeedTailFromDb2,
|
|
73
73
|
readRawSessionBoundaryEndpointsFromDb2
|
|
74
|
-
} from "./index-
|
|
74
|
+
} from "./index-qqxqwqhp.js";
|
|
75
75
|
import {
|
|
76
76
|
logSlowWriteTransaction
|
|
77
77
|
} from "./index-d4dt19md.js";
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
isSynapseEmbeddingTruncated
|
|
13
13
|
} from "./index-6dz2ed1v.js";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
} from "./index-
|
|
15
|
+
messageFtsOrdinalRangeIsMapped2
|
|
16
|
+
} from "./index-s1xn8qfw.js";
|
|
17
17
|
|
|
18
18
|
// ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
|
|
19
19
|
import { createHash } from "node:crypto";
|
|
@@ -514,7 +514,7 @@ function toFloat32Array(blob) {
|
|
|
514
514
|
function buildCanonicalChunkTextFromFts(db, sessionId, startOrdinal, endOrdinal) {
|
|
515
515
|
if (endOrdinal < startOrdinal)
|
|
516
516
|
return "";
|
|
517
|
-
if (!
|
|
517
|
+
if (!messageFtsOrdinalRangeIsMapped2(db, sessionId, startOrdinal, endOrdinal))
|
|
518
518
|
return null;
|
|
519
519
|
const rows = getLoadFtsRowsStatement(db).all(sessionId, startOrdinal, endOrdinal).map((row) => row);
|
|
520
520
|
const lines = [];
|
|
@@ -5399,18 +5399,18 @@ var OmpEntryObjectSchema = object({
|
|
|
5399
5399
|
}).strict();
|
|
5400
5400
|
var OmpEntrySchema = union([string2(), OmpEntryObjectSchema]);
|
|
5401
5401
|
var OpenCodeHarnessBlockSchema = object({
|
|
5402
|
-
model: OcEntrySchema.optional().describe("Primary OpenCode model entry."),
|
|
5403
|
-
fallback_models: array(OcEntrySchema).optional().describe("Ordered fallback OpenCode entries.
|
|
5402
|
+
model: OcEntrySchema.optional().describe("Primary historian OpenCode model entry. When set, only this model and fallback_models are used; exhaustion reports failure, never the session model. When absent, OpenCode inherits the session model."),
|
|
5403
|
+
fallback_models: array(OcEntrySchema).optional().describe("Ordered historian fallback OpenCode entries. A configured primary never adds the session model after this list. Requires an array; legacy singleton values migrate to a one-element array."),
|
|
5404
5404
|
variant: string2().optional().describe("OpenCode reasoning variant for the primary entry when it declares none. Fallback entries declare variants per-entry.")
|
|
5405
5405
|
}).strict().describe("Strict OpenCode model-resolution block. It accepts no Pi vocabulary.");
|
|
5406
5406
|
var PiHarnessBlockSchema = object({
|
|
5407
|
-
model: PiEntrySchema.optional().describe("Primary Pi model entry."),
|
|
5408
|
-
fallback_models: array(PiEntrySchema).optional().describe("Ordered fallback Pi entries.
|
|
5407
|
+
model: PiEntrySchema.optional().describe("Primary historian Pi model entry. When set, only this model and fallback_models are used; exhaustion reports failure, never the session model. When absent, Pi does not run the historian."),
|
|
5408
|
+
fallback_models: array(PiEntrySchema).optional().describe("Ordered historian fallback Pi entries. The session model is never appended. Requires an array; legacy singleton values migrate to a one-element array."),
|
|
5409
5409
|
thinking_level: PiThinkingLevelSchema.describe("Pi thinking level for the primary entry when it declares none. Fallback entries declare thinking levels per-entry.")
|
|
5410
5410
|
}).strict().describe("Strict Pi model-resolution block. It accepts no OpenCode vocabulary.");
|
|
5411
5411
|
var OmpHarnessBlockSchema = object({
|
|
5412
|
-
model: OmpEntrySchema.optional().describe("Primary OMP model entry."),
|
|
5413
|
-
fallback_models: array(OmpEntrySchema).optional().describe("Ordered fallback OMP entries."),
|
|
5412
|
+
model: OmpEntrySchema.optional().describe("Primary historian OMP model entry. When set, only this model and fallback_models are used; exhaustion reports failure, never the session model. An absent OMP block inherits the Pi block; a selected block without a model does not run the historian."),
|
|
5413
|
+
fallback_models: array(OmpEntrySchema).optional().describe("Ordered historian fallback OMP entries. The session model is never appended."),
|
|
5414
5414
|
thinking_level: OmpThinkingLevelSchema.describe("OMP thinking level for the primary entry when it declares none. Fallback entries declare thinking levels per-entry.")
|
|
5415
5415
|
}).strict().describe("Strict OMP model-resolution block. It accepts no OpenCode vocabulary.");
|
|
5416
5416
|
var OpenCodeTaskExecutionSchema = object({
|
|
@@ -1658,9 +1658,11 @@ function planEmergencyDrop(input) {
|
|
|
1658
1658
|
const workingSpan = Math.max(ceilingTokens - fixedFloor, 0);
|
|
1659
1659
|
const target = fixedFloor + TARGET_FRACTION * workingSpan;
|
|
1660
1660
|
const reclaimTokens = Math.round(currentTotalInputTokens - target);
|
|
1661
|
-
|
|
1661
|
+
if (fixedFloor > ceilingTokens) {
|
|
1662
|
+
return noop(`fixed floor ≈${Math.round(fixedFloor)} already exceeds ceiling ${Math.round(ceilingTokens)}: tool drops cannot reach the target`);
|
|
1663
|
+
}
|
|
1662
1664
|
if (reclaimTokens <= EMERGENCY_REARM_MIN_TOKENS) {
|
|
1663
|
-
return noop(`reclaim<=min (${reclaimTokens} <= ${EMERGENCY_REARM_MIN_TOKENS})
|
|
1665
|
+
return noop(`reclaim<=min (${reclaimTokens} <= ${EMERGENCY_REARM_MIN_TOKENS})`);
|
|
1664
1666
|
}
|
|
1665
1667
|
const cutoff = input.protectedCutoff;
|
|
1666
1668
|
const windowYields = absoluteEmergency;
|
|
@@ -1715,16 +1717,16 @@ function planEmergencyDrop(input) {
|
|
|
1715
1717
|
}
|
|
1716
1718
|
}
|
|
1717
1719
|
if (selected.length === 0) {
|
|
1718
|
-
return noop(
|
|
1720
|
+
return noop("no-candidates");
|
|
1719
1721
|
}
|
|
1720
1722
|
if (!input.passAlreadyPriced && reclaimed < EMERGENCY_MIN_ACHIEVABLE_RECLAIM_TOKENS) {
|
|
1721
|
-
return noop(`achievable reclaim below minimum (${selected.length} tags, reclaim≈${Math.round(reclaimed)} < ${EMERGENCY_MIN_ACHIEVABLE_RECLAIM_TOKENS} against gap ${reclaimTokens})
|
|
1723
|
+
return noop(`achievable reclaim below minimum (${selected.length} tags, reclaim≈${Math.round(reclaimed)} < ${EMERGENCY_MIN_ACHIEVABLE_RECLAIM_TOKENS} against gap ${reclaimTokens})`);
|
|
1722
1724
|
}
|
|
1723
1725
|
return {
|
|
1724
1726
|
shouldDrop: true,
|
|
1725
1727
|
tagNumbers: selected,
|
|
1726
1728
|
reclaimTokens,
|
|
1727
|
-
reason: `tiered drop: ${selected.length} tags, reclaim≈${reclaimed}/${reclaimTokens} tokens (floor≈${fixedFloor}, ceiling=${Math.round(ceilingTokens)})
|
|
1729
|
+
reason: `tiered drop: ${selected.length} tags, reclaim≈${reclaimed}/${reclaimTokens} tokens (floor≈${fixedFloor}, ceiling=${Math.round(ceilingTokens)})`
|
|
1728
1730
|
};
|
|
1729
1731
|
}
|
|
1730
1732
|
function measureEmergencyTag(tag, target, calibration, skeleton) {
|
|
@@ -18,14 +18,14 @@ import {
|
|
|
18
18
|
withoutSqliteTransformPass2
|
|
19
19
|
} from "./index-asrxgdt4.js";
|
|
20
20
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} from "./index-
|
|
21
|
+
recordMessageFtsRowid2,
|
|
22
|
+
recordIndexedMessageTime2,
|
|
23
|
+
messageFtsOrdinalRangeIsMapped2,
|
|
24
|
+
deleteUnmappedMessageFtsRows2
|
|
25
|
+
} from "./index-s1xn8qfw.js";
|
|
26
26
|
import {
|
|
27
27
|
deleteChunkEmbedBackoffForSession
|
|
28
|
-
} from "./index-
|
|
28
|
+
} from "./index-afy3dzf9.js";
|
|
29
29
|
import {
|
|
30
30
|
closeQuietly,
|
|
31
31
|
TAG_TOMBSTONE_OWNER_PREFIX,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from "./index-jrap43gc.js";
|
|
38
38
|
import {
|
|
39
39
|
cleanUserText2
|
|
40
|
-
} from "./index-
|
|
40
|
+
} from "./index-44h64qza.js";
|
|
41
41
|
import {
|
|
42
42
|
logSlowWriteTransaction
|
|
43
43
|
} from "./index-d4dt19md.js";
|
|
@@ -616,7 +616,7 @@ function deleteSessionScopedRows(db, sessionIds, harness, options = {}) {
|
|
|
616
616
|
FROM message_fts_rowid_map
|
|
617
617
|
WHERE session_id IN (${placeholders})
|
|
618
618
|
)`).run(...deletableSessionIds);
|
|
619
|
-
|
|
619
|
+
deleteUnmappedMessageFtsRows2(db, deletableSessionIds);
|
|
620
620
|
continue;
|
|
621
621
|
}
|
|
622
622
|
const predicates = [`session_id IN (${placeholders})`];
|
|
@@ -887,7 +887,7 @@ function getDeleteMessageFtsMapStatement(db) {
|
|
|
887
887
|
}
|
|
888
888
|
function insertMessageFtsRow(db, sessionId, messageOrdinal, messageId, role, content, messageTimeMs) {
|
|
889
889
|
const result = getInsertMessageStatement(db).run(sessionId, messageOrdinal, messageId, role, content);
|
|
890
|
-
|
|
890
|
+
recordMessageFtsRowid2(db, sessionId, messageOrdinal, result.lastInsertRowid, messageTimeMs ?? null);
|
|
891
891
|
}
|
|
892
892
|
function normalizeSourceVersion(version) {
|
|
893
893
|
if (typeof version === "number")
|
|
@@ -987,7 +987,7 @@ function deleteIndexedMessage2(db, sessionId, messageId) {
|
|
|
987
987
|
function clearIndexedMessagesInTransaction2(db, sessionId) {
|
|
988
988
|
deleteMessageIndexSkips(db, sessionId);
|
|
989
989
|
getDeleteFtsStatement(db).run(sessionId);
|
|
990
|
-
|
|
990
|
+
deleteUnmappedMessageFtsRows2(db, [sessionId]);
|
|
991
991
|
getDeleteFtsMapStatement(db).run(sessionId);
|
|
992
992
|
getDeleteMessageSourceStatement(db).run(sessionId);
|
|
993
993
|
getDeleteIndexStatement(db).run(sessionId);
|
|
@@ -1018,10 +1018,10 @@ function indexSingleMessageInTransaction(db, sessionId, message, now, dirtyFloor
|
|
|
1018
1018
|
const dirtyFloor = getDirtyIndexFloor(db, sessionId);
|
|
1019
1019
|
if (message.ordinal <= currentWatermark) {
|
|
1020
1020
|
if (isIndexSourceCurrent(db, sessionId, source)) {
|
|
1021
|
-
|
|
1021
|
+
recordIndexedMessageTime2(db, sessionId, message.ordinal, message.createdAt);
|
|
1022
1022
|
return false;
|
|
1023
1023
|
}
|
|
1024
|
-
if (!
|
|
1024
|
+
if (!messageFtsOrdinalRangeIsMapped2(db, sessionId, message.ordinal, message.ordinal)) {
|
|
1025
1025
|
return false;
|
|
1026
1026
|
}
|
|
1027
1027
|
getDeleteMessageFtsStatement(db).run(sessionId, message.id);
|
|
@@ -1051,7 +1051,7 @@ function indexSingleMessage2(db, sessionId, message, shouldCommit = () => true,
|
|
|
1051
1051
|
const source = preparedSource ?? getMessageSourceSnapshot(message);
|
|
1052
1052
|
const currentWatermark = getLastIndexedOrdinal2(db, sessionId);
|
|
1053
1053
|
if (message.ordinal <= currentWatermark && isIndexSourceCurrent(db, sessionId, source)) {
|
|
1054
|
-
|
|
1054
|
+
recordIndexedMessageTime2(db, sessionId, message.ordinal, message.createdAt);
|
|
1055
1055
|
return false;
|
|
1056
1056
|
}
|
|
1057
1057
|
const dirtyFloorBeforeAttempt = getDirtyIndexFloor(db, sessionId);
|
|
@@ -1092,7 +1092,7 @@ function indexItemsAfterOrdinal(db, sessionId, items, finalWatermark, toSource)
|
|
|
1092
1092
|
const currentWatermark = getLastIndexedOrdinal2(db, sessionId);
|
|
1093
1093
|
const dirtyFloor = getDirtyIndexFloor(db, sessionId);
|
|
1094
1094
|
const effectiveWatermark = dirtyFloor === null ? currentWatermark : Math.min(currentWatermark, Math.max(0, dirtyFloor - 1));
|
|
1095
|
-
if (dirtyFloor !== null && dirtyFloor <= currentWatermark && !
|
|
1095
|
+
if (dirtyFloor !== null && dirtyFloor <= currentWatermark && !messageFtsOrdinalRangeIsMapped2(db, sessionId, dirtyFloor, Math.min(currentWatermark, finalWatermark))) {
|
|
1096
1096
|
db.exec("COMMIT");
|
|
1097
1097
|
committed = true;
|
|
1098
1098
|
logSlowWriteTransaction("message_index_reconcile", transactionStartedAt);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withMessageFtsSessionFilter
|
|
3
|
+
} from "./index-1cvyaw9a.js";
|
|
4
|
+
import {
|
|
5
|
+
estimateTokens
|
|
6
|
+
} from "./index-g4jf772p.js";
|
|
7
|
+
import {
|
|
8
|
+
readRawSessionMessageIdOrdinalsForRange2
|
|
9
|
+
} from "./index-44h64qza.js";
|
|
10
|
+
|
|
11
|
+
// ../plugin/src/tools/ctx-expand/search-archive.ts
|
|
12
|
+
var archiveReadsOnThisThread = 0;
|
|
13
|
+
function renderSearchArchive2(db, sessionId, start, end, tokenBudget, archiveOnly = false, readRawIds = () => readRawSessionMessageIdOrdinalsForRange2(sessionId, start, end)) {
|
|
14
|
+
archiveReadsOnThisThread += 1;
|
|
15
|
+
return withMessageFtsSessionFilter(db, sessionId, (sessionFirst) => {
|
|
16
|
+
let rawIds;
|
|
17
|
+
const rows = db.prepare(sessionFirst ? `SELECT f.message_ordinal AS ordinal, f.message_id AS id, f.role, f.content
|
|
18
|
+
FROM message_fts_rowid_map AS m
|
|
19
|
+
JOIN message_history_fts AS f ON f.rowid = m.fts_rowid
|
|
20
|
+
WHERE m.session_id = ?1 AND m.message_ordinal BETWEEN ?2 AND ?3
|
|
21
|
+
AND f.session_id = ?1 AND f.message_ordinal BETWEEN ?2 AND ?3
|
|
22
|
+
ORDER BY m.message_ordinal` : `SELECT message_ordinal AS ordinal, message_id AS id, role, content
|
|
23
|
+
FROM message_history_fts
|
|
24
|
+
WHERE session_id = ?1 AND message_ordinal BETWEEN ?2 AND ?3
|
|
25
|
+
ORDER BY CAST(message_ordinal AS INTEGER)`);
|
|
26
|
+
const blocks = [];
|
|
27
|
+
let tokens = 0;
|
|
28
|
+
let lastOrdinal = start - 1;
|
|
29
|
+
let truncated = false;
|
|
30
|
+
for (const row of rows.iterate(sessionId, start, end)) {
|
|
31
|
+
if (!row.content)
|
|
32
|
+
continue;
|
|
33
|
+
if (!archiveOnly) {
|
|
34
|
+
rawIds ??= readRawIds();
|
|
35
|
+
if (rawIds.get(row.id) === row.ordinal)
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const block = `[${row.ordinal}] ${row.role === "user" ? "U" : "A"}: ${row.content}`;
|
|
39
|
+
const cost = estimateTokens(block);
|
|
40
|
+
if (blocks.length > 0 && tokens + cost > tokenBudget) {
|
|
41
|
+
truncated = true;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
blocks.push(block);
|
|
45
|
+
tokens += cost;
|
|
46
|
+
lastOrdinal = row.ordinal;
|
|
47
|
+
}
|
|
48
|
+
if (blocks.length === 0)
|
|
49
|
+
return null;
|
|
50
|
+
const text = [
|
|
51
|
+
"From the search archive: indexed text only; no surrounding messages or tool output.",
|
|
52
|
+
"",
|
|
53
|
+
...blocks
|
|
54
|
+
];
|
|
55
|
+
if (truncated) {
|
|
56
|
+
text.push("", `Truncated at message ${lastOrdinal} (budget: ~${tokenBudget} tokens). Call ctx_expand(start=${lastOrdinal + 1}, end=${end}) for more archived text.`);
|
|
57
|
+
}
|
|
58
|
+
return text.join(`
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export { renderSearchArchive2 };
|