@cortexkit/pi-magic-context 0.49.35 → 0.49.36
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 +163 -160
- package/dist/chunk-embedding-write-worker.js +59 -57
- package/dist/{compaction-marker-candidates-hk2frhac.js → compaction-marker-candidates-9fzqg6y0.js} +4 -2
- package/dist/compaction-marker-candidates-worker.js +24 -23
- package/dist/{compartment-chunk-embedding-5j1d1e3v.js → compartment-chunk-embedding-jpcme6tz.js} +6 -5
- package/dist/{embedding-backfill-jt459ady.js → embedding-backfill-002vyexq.js} +8 -7
- package/dist/{index-399p688g.js → index-8sqebjzk.js} +4 -1
- package/dist/{index-11knwv2h.js → index-a7sj2bam.js} +6 -3
- package/dist/{index-mkh1cm5k.js → index-c1dqxr10.js} +34 -4
- package/dist/{index-rgvqh5x7.js → index-ck8wj35v.js} +1 -1
- package/dist/{index-fzm8fm4z.js → index-dgqjq8sg.js} +143 -64
- package/dist/{index-yg42q9bc.js → index-f6y7mdq9.js} +8 -7
- package/dist/{index-2p691ayw.js → index-f9qet7y8.js} +1 -1
- package/dist/{index-6y6v2wvn.js → index-gxqmh9hq.js} +6 -6
- package/dist/{index-vgfk2xa5.js → index-jbkwszd5.js} +1 -1
- package/dist/{index-8m82cez2.js → index-kj49vs41.js} +2 -2
- package/dist/{index-svqk0701.js → index-mx757f3g.js} +13 -5
- package/dist/index-nypgv96r.js +58 -0
- package/dist/{index-d21rhpbd.js → index-p9jfa33t.js} +5 -5
- package/dist/{index-yhsmjvqa.js → index-pwp6zyx3.js} +12 -1
- package/dist/{index-m68qfjte.js → index-ry84c8dr.js} +1 -1
- package/dist/index-wfqysrwq.js +204 -0
- package/dist/{index-0rvn6vhq.js → index-wwsfevck.js} +6 -3
- package/dist/{index-54wmg4rj.js → index-x2n261wp.js} +16 -14
- package/dist/{index-d0w84hy5.js → index-y90fxz4t.js} +9 -3
- package/dist/{index-a11nmw5t.js → index-z7dktknj.js} +6 -4
- package/dist/index.js +846 -305
- package/dist/{message-fts-rowid-map-aw4xa05a.js → message-fts-rowid-map-hmgyfxxa.js} +5 -4
- package/dist/{message-index-bounded-da34vhs4.js → message-index-bounded-82sergz7.js} +8 -7
- package/dist/migration-worker.js +46 -41
- package/dist/{project-embedding-registry-davzvsz9.js → project-embedding-registry-16pj4vyf.js} +7 -6
- package/dist/raw-ordinal-warmup-worker.js +114 -118
- package/dist/{read-session-chunk-nbcznexm.js → read-session-chunk-jxq427v6.js} +6 -5
- package/dist/{read-session-raw-zb8kpa2y.js → read-session-raw-a9ntjqap.js} +4 -3
- package/dist/{render-d931g2vv.js → render-2wan3bfh.js} +11 -10
- package/dist/{search-atp7g95j.js → search-3p18trsb.js} +12 -11
- package/dist/{search-archive-a76pp30g.js → search-archive-pgrv04gv.js} +8 -7
- package/dist/{storage-tags-jy8b0xsy.js → storage-tags-p9y3bnw7.js} +1 -1
- package/dist/{store-kabezr25.js → store-v60q7dje.js} +1 -2
- package/dist/subagent-entry.js +18 -17
- package/dist/tag-snapshot-worker-pi.js +208 -202
- package/dist/{v2-archive-reader-wcjcfdzq.js → v2-archive-reader-5zpj8hrg.js} +3 -3
- package/package.json +1 -1
|
@@ -5,13 +5,16 @@ import {
|
|
|
5
5
|
} from "./index-2qtx0q6h.js";
|
|
6
6
|
import {
|
|
7
7
|
registerExitAbort
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-8sqebjzk.js";
|
|
9
9
|
import {
|
|
10
10
|
log2
|
|
11
11
|
} from "./index-gymgz20n.js";
|
|
12
|
+
import {
|
|
13
|
+
reuseWorker
|
|
14
|
+
} from "./index-wfqysrwq.js";
|
|
12
15
|
import {
|
|
13
16
|
createWorkerShutdown
|
|
14
|
-
} from "./index-
|
|
17
|
+
} from "./index-x2n261wp.js";
|
|
15
18
|
|
|
16
19
|
// ../plugin/src/hooks/magic-context/read-session-raw.ts
|
|
17
20
|
import { isMainThread } from "node:worker_threads";
|
|
@@ -60,6 +63,7 @@ function runSessionWarmupWorker(input, options) {
|
|
|
60
63
|
clearTimeout(deadline);
|
|
61
64
|
options.signal?.removeEventListener("abort", abort);
|
|
62
65
|
if (worker) {
|
|
66
|
+
worker.off("online", startDeadline);
|
|
63
67
|
activeWorkers.delete(worker);
|
|
64
68
|
const stopped = shutdown?.close() ?? worker.terminate();
|
|
65
69
|
worker.unref();
|
|
@@ -77,6 +81,10 @@ function runSessionWarmupWorker(input, options) {
|
|
|
77
81
|
deadline = setTimeout(() => finish({ failure, detail: `no reply within ${ms} ms` }), ms);
|
|
78
82
|
deadline.unref?.();
|
|
79
83
|
};
|
|
84
|
+
const startDeadline = () => {
|
|
85
|
+
if (!settled)
|
|
86
|
+
arm("not-accepted", options.acceptMs ?? ACCEPT_TIMEOUT_MS);
|
|
87
|
+
};
|
|
80
88
|
const abort = () => finish({ failure: "stopped", detail: "stopped" });
|
|
81
89
|
if (options.signal?.aborted) {
|
|
82
90
|
abort();
|
|
@@ -84,8 +92,14 @@ function runSessionWarmupWorker(input, options) {
|
|
|
84
92
|
}
|
|
85
93
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
86
94
|
try {
|
|
87
|
-
worker = inRootAsyncContext2(() => new Worker(options.entry
|
|
95
|
+
worker = inRootAsyncContext2(() => options.entry ? new Worker(options.entry, {
|
|
88
96
|
workerData: { ...input, openCancellation: openCancellation.buffer }
|
|
97
|
+
}) : reuseWorker(defaultEntry(), {
|
|
98
|
+
workerData: {
|
|
99
|
+
...input,
|
|
100
|
+
job: rawWorkerJobKind(input),
|
|
101
|
+
openCancellation: openCancellation.buffer
|
|
102
|
+
}
|
|
89
103
|
}));
|
|
90
104
|
shutdown = createWorkerShutdown(worker, "raw-ordinal-warmup", WARMUP_CLOSE_DEADLINE_MS);
|
|
91
105
|
} catch (error) {
|
|
@@ -94,7 +108,10 @@ function runSessionWarmupWorker(input, options) {
|
|
|
94
108
|
}
|
|
95
109
|
worker.unref();
|
|
96
110
|
activeWorkers.set(worker, (failure) => finish({ failure, detail: "stopped" }));
|
|
97
|
-
|
|
111
|
+
if (options.entry)
|
|
112
|
+
startDeadline();
|
|
113
|
+
else
|
|
114
|
+
worker.once("online", startDeadline);
|
|
98
115
|
worker.on("message", (reply) => {
|
|
99
116
|
if (reply.kind === "accepted")
|
|
100
117
|
arm("no-result", options.resultMs ?? RESULT_TIMEOUT_MS);
|
|
@@ -124,6 +141,19 @@ function runSessionWarmupWorker(input, options) {
|
|
|
124
141
|
worker.on("exit", (code) => finish({ failure: "exited", detail: `exit code ${code}` }));
|
|
125
142
|
});
|
|
126
143
|
}
|
|
144
|
+
function rawWorkerJobKind(input) {
|
|
145
|
+
if (input.indexMessage)
|
|
146
|
+
return "index-message";
|
|
147
|
+
if (input.ftsRowidBackfill)
|
|
148
|
+
return "fts-rowid-backfill";
|
|
149
|
+
if (input.searchArchive)
|
|
150
|
+
return "search-archive";
|
|
151
|
+
if (input.exactOrdinalIds)
|
|
152
|
+
return "exact-ordinal-ids";
|
|
153
|
+
if (input.tagRatio !== undefined)
|
|
154
|
+
return input.tagState ? "tag-delta" : "tag-summary";
|
|
155
|
+
return "ordinal-scan";
|
|
156
|
+
}
|
|
127
157
|
function prewarmRawSessionOrdinalsForDb(db, sessionId, options = {}) {
|
|
128
158
|
if (isRawSessionSummaryWarm2(db, sessionId))
|
|
129
159
|
return Promise.resolve("warm");
|
|
@@ -52,11 +52,11 @@ import {
|
|
|
52
52
|
} from "./index-2qtx0q6h.js";
|
|
53
53
|
import {
|
|
54
54
|
noteRawSessionSummaryRowWritten2
|
|
55
|
-
} from "./index-
|
|
55
|
+
} from "./index-c1dqxr10.js";
|
|
56
56
|
import {
|
|
57
57
|
piHarnessKindFromExecutable,
|
|
58
58
|
getErrorMessage
|
|
59
|
-
} from "./index-
|
|
59
|
+
} from "./index-a7sj2bam.js";
|
|
60
60
|
import {
|
|
61
61
|
getOrCreateSessionMeta,
|
|
62
62
|
updateSessionMeta,
|
|
@@ -70,10 +70,10 @@ import {
|
|
|
70
70
|
renderMessageByOrdinal2,
|
|
71
71
|
renderVerboseRange2,
|
|
72
72
|
renderItemByTag2
|
|
73
|
-
} from "./index-
|
|
73
|
+
} from "./index-p9jfa33t.js";
|
|
74
74
|
import {
|
|
75
75
|
getLastIndexedOrdinal
|
|
76
|
-
} from "./index-
|
|
76
|
+
} from "./index-kj49vs41.js";
|
|
77
77
|
import {
|
|
78
78
|
setNoteLastReadAt,
|
|
79
79
|
getPersistedCompactionMarkerState,
|
|
@@ -83,7 +83,7 @@ import {
|
|
|
83
83
|
hasRawMessageProvider2,
|
|
84
84
|
setRawMessageProvider2,
|
|
85
85
|
readSessionChunk2
|
|
86
|
-
} from "./index-
|
|
86
|
+
} from "./index-mx757f3g.js";
|
|
87
87
|
import {
|
|
88
88
|
stableStringify
|
|
89
89
|
} from "./index-yacs388s.js";
|
|
@@ -120,7 +120,7 @@ import {
|
|
|
120
120
|
unregisterProjectEmbedding2,
|
|
121
121
|
getProjectEmbeddingSnapshot2,
|
|
122
122
|
embedTextForProject2
|
|
123
|
-
} from "./index-
|
|
123
|
+
} from "./index-z7dktknj.js";
|
|
124
124
|
import {
|
|
125
125
|
directoryHasGitMetadata,
|
|
126
126
|
resolveProjectIdentityForSession,
|
|
@@ -133,7 +133,7 @@ import {
|
|
|
133
133
|
resolveMemoriesByIdsForSearch2,
|
|
134
134
|
unifiedSearch2,
|
|
135
135
|
formatSearchResults2
|
|
136
|
-
} from "./index-
|
|
136
|
+
} from "./index-f6y7mdq9.js";
|
|
137
137
|
import {
|
|
138
138
|
TODO_STATUSES,
|
|
139
139
|
TODO_PRIORITIES,
|
|
@@ -144,7 +144,7 @@ import {
|
|
|
144
144
|
getInertWhitespaceAssistantTagsByNumbers2,
|
|
145
145
|
getTagNumberByMessageId2,
|
|
146
146
|
getTagsBySession2
|
|
147
|
-
} from "./index-
|
|
147
|
+
} from "./index-pwp6zyx3.js";
|
|
148
148
|
import {
|
|
149
149
|
resolveOpenCodeDbPath,
|
|
150
150
|
assertOpenCodeStoreGeneration
|
|
@@ -174,10 +174,10 @@ import {
|
|
|
174
174
|
isMarkerCandidateBasisCurrent2,
|
|
175
175
|
invalidateMarkerCandidateBasis2,
|
|
176
176
|
readMarkerCandidateBasis2
|
|
177
|
-
} from "./index-
|
|
177
|
+
} from "./index-y90fxz4t.js";
|
|
178
178
|
import {
|
|
179
179
|
renderSearchArchive2
|
|
180
|
-
} from "./index-
|
|
180
|
+
} from "./index-ry84c8dr.js";
|
|
181
181
|
import {
|
|
182
182
|
computeNormalizedHash
|
|
183
183
|
} from "./index-9x1f96r8.js";
|
|
@@ -5017,46 +5017,36 @@ function isCompactionMarkerIntentAbsent(marker, targetEndMessageId) {
|
|
|
5017
5017
|
function withCompactionMarkerPublicationLock(operation) {
|
|
5018
5018
|
return runMarkerWriteTransaction(getWritableOpenCodeDb(), "compaction-marker-replace", operation);
|
|
5019
5019
|
}
|
|
5020
|
-
function inspectCompactionMarkerPublication(sessionId, recognized, summaryText) {
|
|
5020
|
+
function inspectCompactionMarkerPublication(sessionId, recognized, summaryText, targetBoundaryMessageId, preferred) {
|
|
5021
5021
|
const db = getWritableOpenCodeDb();
|
|
5022
5022
|
const basis = readMarkerCandidateBasis2(db, sessionId);
|
|
5023
5023
|
if (!basis)
|
|
5024
5024
|
return { kind: "deferred" };
|
|
5025
5025
|
const pairs = [];
|
|
5026
5026
|
for (const id of basis.ids) {
|
|
5027
|
-
const rows = db.prepare(`SELECT m.id AS summaryId, p.message_id AS boundaryId, p.id AS partId
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
AND json_extract(
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
return { kind: "ambiguous" };
|
|
5037
|
-
if (pairs.length === 0) {
|
|
5038
|
-
for (const marker of recognized) {
|
|
5039
|
-
if (db.prepare(`SELECT 1 FROM message WHERE id = ?
|
|
5040
|
-
UNION ALL SELECT 1 FROM part WHERE id IN (?, ?) LIMIT 1`).get(marker.summaryMessageId, marker.compactionPartId, marker.summaryPartId))
|
|
5041
|
-
return { kind: "ambiguous" };
|
|
5042
|
-
}
|
|
5043
|
-
return { kind: "verified", marker: null };
|
|
5044
|
-
}
|
|
5045
|
-
const pair = pairs[0];
|
|
5046
|
-
const marker = recognized.find((item) => item.summaryMessageId === pair.summaryId && item.boundaryMessageId === pair.boundaryId && item.compactionPartId === pair.partId);
|
|
5047
|
-
if (!marker)
|
|
5048
|
-
return { kind: "ambiguous" };
|
|
5049
|
-
for (const other of recognized) {
|
|
5050
|
-
if (other.summaryMessageId === marker.summaryMessageId && other.compactionPartId === marker.compactionPartId && other.summaryPartId === marker.summaryPartId)
|
|
5051
|
-
continue;
|
|
5052
|
-
if (db.prepare(`SELECT 1 FROM message WHERE id = ?
|
|
5053
|
-
UNION ALL SELECT 1 FROM part WHERE id IN (?, ?) LIMIT 1`).get(other.summaryMessageId, other.compactionPartId, other.summaryPartId))
|
|
5027
|
+
const rows = db.prepare(`SELECT m.id AS summaryId, p.message_id AS boundaryId, p.id AS partId,
|
|
5028
|
+
p.data AS compactionData
|
|
5029
|
+
FROM message m LEFT JOIN part p ON p.message_id = json_extract(m.data, '$.parentID')
|
|
5030
|
+
AND +p.session_id = m.session_id
|
|
5031
|
+
AND json_extract(p.data, '$.type') = 'compaction'
|
|
5032
|
+
WHERE m.id = ? AND m.session_id = ? AND json_extract(m.data, '$.summary') = 1
|
|
5033
|
+
AND json_extract(m.data, '$.providerID') = 'magic-context'`).all(id, sessionId);
|
|
5034
|
+
const canonical = rows.filter((row) => isMcCanonicalCompactionPartData(JSON.parse(row.compactionData ?? "null")));
|
|
5035
|
+
if (rows.length > 0 && canonical.length === 0)
|
|
5054
5036
|
return { kind: "ambiguous" };
|
|
5037
|
+
pairs.push(...canonical);
|
|
5055
5038
|
}
|
|
5056
|
-
const
|
|
5039
|
+
const verified = [];
|
|
5040
|
+
for (const pair of pairs) {
|
|
5041
|
+
if (pair.partId === null)
|
|
5042
|
+
return { kind: "ambiguous" };
|
|
5043
|
+
if (verified.some((marker) => marker.boundaryMessageId === pair.boundaryId))
|
|
5044
|
+
return { kind: "ambiguous" };
|
|
5045
|
+
const row = db.prepare(`SELECT c.data AS compactionData, t.id AS summaryPartId,
|
|
5046
|
+
m.time_created AS timeCreated FROM message m
|
|
5057
5047
|
JOIN message b ON b.id = ? AND b.session_id = m.session_id
|
|
5058
5048
|
JOIN part c ON c.id = ? AND c.message_id = b.id AND c.session_id = m.session_id
|
|
5059
|
-
JOIN part t ON t.
|
|
5049
|
+
JOIN part t ON t.message_id = m.id AND t.session_id = m.session_id
|
|
5060
5050
|
WHERE m.id = ? AND m.session_id = ?
|
|
5061
5051
|
AND json_extract(b.data, '$.role') = 'user'
|
|
5062
5052
|
AND json_extract(m.data, '$.role') = 'assistant'
|
|
@@ -5067,10 +5057,39 @@ function inspectCompactionMarkerPublication(sessionId, recognized, summaryText)
|
|
|
5067
5057
|
AND json_extract(m.data, '$.providerID') = 'magic-context'
|
|
5068
5058
|
AND json_extract(m.data, '$.modelID') = 'magic-context'
|
|
5069
5059
|
AND json_extract(t.data, '$.type') = 'text' AND json_extract(t.data, '$.text') = ?
|
|
5070
|
-
AND (SELECT COUNT(*) FROM part p WHERE p.message_id = m.id AND +p.session_id = m.session_id) = 1`).get(
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5060
|
+
AND (SELECT COUNT(*) FROM part p WHERE p.message_id = m.id AND +p.session_id = m.session_id) = 1`).get(pair.boundaryId, pair.partId, pair.summaryId, sessionId, summaryText);
|
|
5061
|
+
const order = compareOpenCodeMessagesByCanonicalOrder(sessionId, pair.boundaryId, targetBoundaryMessageId);
|
|
5062
|
+
const isRecorded = preferred && preferred.summaryMessageId === pair.summaryId && preferred.boundaryMessageId === pair.boundaryId && preferred.compactionPartId === pair.partId && preferred.summaryPartId === row?.summaryPartId;
|
|
5063
|
+
if (!row || !isMcCanonicalCompactionPartData(JSON.parse(row.compactionData)) || findBoundaryUserMessage(sessionId, pair.boundaryId)?.id !== pair.boundaryId || order === null || order > 0 && !isRecorded)
|
|
5064
|
+
return { kind: "ambiguous" };
|
|
5065
|
+
verified.push({
|
|
5066
|
+
boundaryMessageId: pair.boundaryId,
|
|
5067
|
+
summaryMessageId: pair.summaryId,
|
|
5068
|
+
compactionPartId: pair.partId,
|
|
5069
|
+
summaryPartId: row.summaryPartId,
|
|
5070
|
+
timeCreated: row.timeCreated
|
|
5071
|
+
});
|
|
5072
|
+
}
|
|
5073
|
+
const matches = (left, right) => left.summaryMessageId === right.summaryMessageId && left.boundaryMessageId === right.boundaryMessageId && left.compactionPartId === right.compactionPartId && left.summaryPartId === right.summaryPartId;
|
|
5074
|
+
for (const marker of recognized) {
|
|
5075
|
+
if (verified.some((item) => matches(item, marker)))
|
|
5076
|
+
continue;
|
|
5077
|
+
if (db.prepare(`SELECT 1 FROM message WHERE id = ?
|
|
5078
|
+
UNION ALL SELECT 1 FROM part WHERE id IN (?, ?) LIMIT 1`).get(marker.summaryMessageId, marker.compactionPartId, marker.summaryPartId))
|
|
5079
|
+
return { kind: "ambiguous" };
|
|
5080
|
+
}
|
|
5081
|
+
verified.sort((left, right) => right.timeCreated - left.timeCreated || (left.summaryMessageId < right.summaryMessageId ? 1 : -1));
|
|
5082
|
+
const state = (marker) => {
|
|
5083
|
+
if (!marker)
|
|
5084
|
+
return null;
|
|
5085
|
+
const { timeCreated: _, ...ids } = marker;
|
|
5086
|
+
return ids;
|
|
5087
|
+
};
|
|
5088
|
+
return {
|
|
5089
|
+
kind: "verified",
|
|
5090
|
+
marker: state(preferred && verified.find((item) => matches(item, preferred)) || verified[0]),
|
|
5091
|
+
markerAtTarget: state(verified.find((item) => item.boundaryMessageId === targetBoundaryMessageId))
|
|
5092
|
+
};
|
|
5074
5093
|
}
|
|
5075
5094
|
var LEGACY_MARKER_LINEAGE_SQL = `SELECT m.id
|
|
5076
5095
|
FROM message m
|
|
@@ -5100,7 +5119,7 @@ function removeLegacyMarkerLineageRows(db, args) {
|
|
|
5100
5119
|
AND COALESCE(json_extract(data, '$.type'), '') = 'compaction'
|
|
5101
5120
|
AND COALESCE(json_extract(data, '$.auto'), 0) = 1`).run(args.sessionId, args.boundaryMessageId, args.compactionPartId);
|
|
5102
5121
|
}
|
|
5103
|
-
function injectCompactionMarkerFromBasis(args, validatedBasis) {
|
|
5122
|
+
function injectCompactionMarkerFromBasis(args, validatedBasis, preserveExistingLineages = false) {
|
|
5104
5123
|
const db = getWritableOpenCodeDb();
|
|
5105
5124
|
if (!isOpenCodeSchemaCompatible(db, getOpenCodeDbPath())) {
|
|
5106
5125
|
return null;
|
|
@@ -5137,14 +5156,15 @@ function injectCompactionMarkerFromBasis(args, validatedBasis) {
|
|
|
5137
5156
|
runMarkerWriteTransaction(db, "compaction-marker-inject", () => {
|
|
5138
5157
|
if (!validatedBasis && !isMarkerCandidateBasisCurrent2(db, basis))
|
|
5139
5158
|
throw new Error("host store changed after marker candidate preparation; marker unchanged");
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5159
|
+
if (!preserveExistingLineages)
|
|
5160
|
+
removeLegacyMarkerLineageRows(db, {
|
|
5161
|
+
sessionId: args.sessionId,
|
|
5162
|
+
boundaryMessageId: boundary.id,
|
|
5163
|
+
candidateIds: basis.ids,
|
|
5164
|
+
summaryText: args.summaryText,
|
|
5165
|
+
summaryMessageId: summaryMsgId,
|
|
5166
|
+
compactionPartId
|
|
5167
|
+
});
|
|
5148
5168
|
db.prepare(`INSERT INTO part (id, message_id, session_id, time_created, time_updated, data)
|
|
5149
5169
|
VALUES (?, ?, ?, ?, ?, ?)
|
|
5150
5170
|
ON CONFLICT(id) DO UPDATE SET
|
|
@@ -5186,7 +5206,7 @@ function injectCompactionMarkerFromBasis(args, validatedBasis) {
|
|
|
5186
5206
|
|
|
5187
5207
|
class MarkerCandidateUnavailableError extends Error {
|
|
5188
5208
|
}
|
|
5189
|
-
function replaceCompactionMarker(existing, args) {
|
|
5209
|
+
function replaceCompactionMarker(existing, args, preserveExistingLineages = false) {
|
|
5190
5210
|
let connection;
|
|
5191
5211
|
let entered = false;
|
|
5192
5212
|
let readyToCommit = false;
|
|
@@ -5205,11 +5225,25 @@ function replaceCompactionMarker(existing, args) {
|
|
|
5205
5225
|
if (!isMarkerCandidateBasisCurrent2(db, basis))
|
|
5206
5226
|
throw new MarkerCandidateUnavailableError("host store changed after marker candidate preparation; marker unchanged");
|
|
5207
5227
|
if (existing) {
|
|
5228
|
+
const referenced = db.prepare(`WITH deleted(id) AS (VALUES (?), (?), (?)), surviving(data) AS (
|
|
5229
|
+
SELECT data FROM part WHERE session_id = ?
|
|
5230
|
+
AND id NOT IN (SELECT id FROM deleted)
|
|
5231
|
+
AND json_extract(data, '$.type') = 'compaction'
|
|
5232
|
+
UNION ALL
|
|
5233
|
+
SELECT data FROM message WHERE session_id = ?
|
|
5234
|
+
AND id NOT IN (SELECT id FROM deleted)
|
|
5235
|
+
)
|
|
5236
|
+
SELECT 1 FROM surviving
|
|
5237
|
+
WHERE json_extract(data, '$.tail_start_id') IN (SELECT id FROM deleted)
|
|
5238
|
+
OR json_extract(data, '$.compaction.tail_start_id') IN (SELECT id FROM deleted)
|
|
5239
|
+
LIMIT 1`).get(existing.summaryMessageId, existing.summaryPartId, existing.compactionPartId, args.sessionId, args.sessionId);
|
|
5240
|
+
if (referenced)
|
|
5241
|
+
throw new Error("a surviving tail_start_id references a recorded marker row; marker unchanged");
|
|
5208
5242
|
db.prepare("DELETE FROM part WHERE id = ?").run(existing.summaryPartId);
|
|
5209
5243
|
db.prepare("DELETE FROM message WHERE id = ?").run(existing.summaryMessageId);
|
|
5210
5244
|
db.prepare("DELETE FROM part WHERE id = ?").run(existing.compactionPartId);
|
|
5211
5245
|
}
|
|
5212
|
-
const replacement = injectCompactionMarkerFromBasis(args, basis);
|
|
5246
|
+
const replacement = injectCompactionMarkerFromBasis(args, basis, preserveExistingLineages);
|
|
5213
5247
|
if (!replacement) {
|
|
5214
5248
|
throw new Error(`failed to inject replacement marker at ordinal ${args.endOrdinal}`);
|
|
5215
5249
|
}
|
|
@@ -5291,7 +5325,7 @@ function publishRecoverableCompactionMarker(db, args, targetIsCurrent) {
|
|
|
5291
5325
|
if (!validTarget || !pendingBoundary || !pendingTarget || !samePair(pending, planCompactionMarker({ ...args, endMessageId: pendingTarget }, pendingBoundary)))
|
|
5292
5326
|
pending = null;
|
|
5293
5327
|
}
|
|
5294
|
-
const inspection = inspectCompactionMarkerPublication(sessionId, [intended, ...previous ? [previous] : [], ...pending ? [pending] : []], args.summaryText);
|
|
5328
|
+
const inspection = inspectCompactionMarkerPublication(sessionId, [intended, ...previous ? [previous] : [], ...pending ? [pending] : []], args.summaryText, boundary.id, previous);
|
|
5295
5329
|
if (inspection.kind === "deferred") {
|
|
5296
5330
|
reason = "candidate-preparation";
|
|
5297
5331
|
return {
|
|
@@ -5308,22 +5342,34 @@ function publishRecoverableCompactionMarker(db, args, targetIsCurrent) {
|
|
|
5308
5342
|
}
|
|
5309
5343
|
cut = "definitely-no-cut";
|
|
5310
5344
|
const host = inspection.marker;
|
|
5311
|
-
if (
|
|
5312
|
-
const
|
|
5313
|
-
|
|
5345
|
+
if (inspection.markerAtTarget) {
|
|
5346
|
+
const hostOrder = host ? compareOpenCodeMessagesByCanonicalOrder(sessionId, host.boundaryMessageId, boundary.id) : 0;
|
|
5347
|
+
if (hostOrder === null || hostOrder > 0) {
|
|
5348
|
+
reason = "ahead-of-target-left-alone";
|
|
5349
|
+
return {
|
|
5350
|
+
kind: cut,
|
|
5351
|
+
error: new Error("a later recorded host cut prevents target adoption")
|
|
5352
|
+
};
|
|
5353
|
+
}
|
|
5354
|
+
intended = { ...intended, ...inspection.markerAtTarget };
|
|
5355
|
+
recovered = pending && samePair(intended, pending) ? "pending-intent-recovered" : "adopted-existing-pair";
|
|
5314
5356
|
cut = "uncertain";
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5357
|
+
return { kind: "committed", marker: inspection.markerAtTarget };
|
|
5358
|
+
}
|
|
5359
|
+
if (host && pending && samePair(host, pending)) {
|
|
5360
|
+
recovered = "pending-intent-recovered";
|
|
5361
|
+
cut = "uncertain";
|
|
5362
|
+
persist(pending);
|
|
5318
5363
|
}
|
|
5319
5364
|
writingState = true;
|
|
5320
5365
|
raw = compareAndSetCompactionMarkerPublicationState(db, sessionId, raw, previous, intended);
|
|
5321
5366
|
writingState = false;
|
|
5322
5367
|
cut = "uncertain";
|
|
5323
|
-
const
|
|
5368
|
+
const ownedHost = host && (previous && samePair(host, previous) || pending && samePair(host, pending)) ? host : null;
|
|
5369
|
+
const replacement = replaceCompactionMarker(ownedHost, {
|
|
5324
5370
|
...args,
|
|
5325
5371
|
resolvedBoundary: boundary
|
|
5326
|
-
});
|
|
5372
|
+
}, true);
|
|
5327
5373
|
if (recovered && replacement.kind !== "committed")
|
|
5328
5374
|
return { kind: "uncertain", error: replacement.error };
|
|
5329
5375
|
if (replacement.kind !== "committed")
|
|
@@ -8147,6 +8193,20 @@ var DreamerParamsSchema = _Object_({
|
|
|
8147
8193
|
description: "Active same-project/category memory that survives a curate consolidation"
|
|
8148
8194
|
}))
|
|
8149
8195
|
}, { additionalProperties: true });
|
|
8196
|
+
function rejectInvalidMemoryArguments(args) {
|
|
8197
|
+
if (args === null || typeof args !== "object")
|
|
8198
|
+
return;
|
|
8199
|
+
const record = args;
|
|
8200
|
+
if (record.content !== undefined && typeof record.content !== "string") {
|
|
8201
|
+
throw new Error("Error: 'content' must be a string.");
|
|
8202
|
+
}
|
|
8203
|
+
if (record.reason !== undefined && typeof record.reason !== "string") {
|
|
8204
|
+
throw new Error("Error: 'reason' must be a string.");
|
|
8205
|
+
}
|
|
8206
|
+
if (record.ids !== undefined && (!Array.isArray(record.ids) || record.ids.some((id) => typeof id !== "number" || !Number.isSafeInteger(id) || id < 1))) {
|
|
8207
|
+
throw new Error("Error: 'ids' must be an array of positive memory IDs.");
|
|
8208
|
+
}
|
|
8209
|
+
}
|
|
8150
8210
|
function ok2(text) {
|
|
8151
8211
|
return { content: [{ type: "text", text }], details: undefined };
|
|
8152
8212
|
}
|
|
@@ -8271,6 +8331,10 @@ function createCtxMemoryTool(deps) {
|
|
|
8271
8331
|
label: "Magic Context: Memory",
|
|
8272
8332
|
description: CTX_MEMORY_DESCRIPTION,
|
|
8273
8333
|
parameters: dreamerAllowed ? DreamerParamsSchema : PrimaryParamsSchema,
|
|
8334
|
+
prepareArguments(args) {
|
|
8335
|
+
rejectInvalidMemoryArguments(args);
|
|
8336
|
+
return args;
|
|
8337
|
+
},
|
|
8274
8338
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
8275
8339
|
params = unwrapImitatedReducedArgs(params, ["action"], {
|
|
8276
8340
|
action: { type: "enum", values: ALL_ACTIONS },
|
|
@@ -9199,6 +9263,17 @@ var ParamsSchema2 = _Object_({
|
|
|
9199
9263
|
description: "Skip this many newest rows (default 0)."
|
|
9200
9264
|
}))
|
|
9201
9265
|
}, { additionalProperties: true });
|
|
9266
|
+
function rejectInvalidNoteArguments(args) {
|
|
9267
|
+
if (args === null || typeof args !== "object")
|
|
9268
|
+
return;
|
|
9269
|
+
const record = args;
|
|
9270
|
+
if (record.content !== undefined && typeof record.content !== "string") {
|
|
9271
|
+
throw new Error("Error: 'content' must be a string.");
|
|
9272
|
+
}
|
|
9273
|
+
if (record.note_ids !== undefined && (!Array.isArray(record.note_ids) || record.note_ids.some((id) => typeof id !== "number" || !Number.isSafeInteger(id) || id < 1))) {
|
|
9274
|
+
throw new Error("Error: 'note_ids' must be an array of positive note IDs.");
|
|
9275
|
+
}
|
|
9276
|
+
}
|
|
9202
9277
|
function ok3(text) {
|
|
9203
9278
|
return { content: [{ type: "text", text }], details: undefined };
|
|
9204
9279
|
}
|
|
@@ -9261,6 +9336,10 @@ function createCtxNoteTool(deps) {
|
|
|
9261
9336
|
label: "Magic Context: Notes",
|
|
9262
9337
|
description: smartNoteSurface ? CTX_NOTE_DESCRIPTION : withoutSmartNoteText(CTX_NOTE_DESCRIPTION),
|
|
9263
9338
|
parameters,
|
|
9339
|
+
prepareArguments(args) {
|
|
9340
|
+
rejectInvalidNoteArguments(args);
|
|
9341
|
+
return args;
|
|
9342
|
+
},
|
|
9264
9343
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
9265
9344
|
params = unwrapImitatedReducedArgs(params, ["action", "content"], {
|
|
9266
9345
|
action: {
|
|
@@ -24,13 +24,13 @@ import {
|
|
|
24
24
|
} from "./index-2qtx0q6h.js";
|
|
25
25
|
import {
|
|
26
26
|
runSessionWarmupWorker
|
|
27
|
-
} from "./index-
|
|
27
|
+
} from "./index-c1dqxr10.js";
|
|
28
28
|
import {
|
|
29
29
|
buildCanonicalChunkTextFromFts2,
|
|
30
30
|
loadCompartmentChunkEmbeddingsForSearch2,
|
|
31
31
|
peekCompartmentChunkSearchPool2,
|
|
32
32
|
warmCompartmentChunkSearchPool2
|
|
33
|
-
} from "./index-
|
|
33
|
+
} from "./index-f9qet7y8.js";
|
|
34
34
|
import {
|
|
35
35
|
saveCommitEmbedding,
|
|
36
36
|
loadProjectCommitEmbeddings,
|
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
getProjectEmbeddingSnapshot2,
|
|
48
48
|
embedTextForProject2,
|
|
49
49
|
embedItemsForProject2
|
|
50
|
-
} from "./index-
|
|
50
|
+
} from "./index-z7dktknj.js";
|
|
51
51
|
import {
|
|
52
52
|
recordEmbeddingMeasurement
|
|
53
53
|
} from "./index-hgd00nas.js";
|
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
isEmbeddingEnabled,
|
|
64
64
|
embedText,
|
|
65
65
|
ensureMemoryEmbeddings2
|
|
66
|
-
} from "./index-
|
|
66
|
+
} from "./index-jbkwszd5.js";
|
|
67
67
|
import {
|
|
68
68
|
getMemorySelectColumns2,
|
|
69
69
|
isMemoryRow2,
|
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
clearIndexedMessages,
|
|
92
92
|
indexSingleMessage,
|
|
93
93
|
indexMessagesAfterOrdinal
|
|
94
|
-
} from "./index-
|
|
94
|
+
} from "./index-kj49vs41.js";
|
|
95
95
|
import {
|
|
96
96
|
MESSAGE_FTS_SESSION_FILTER_SQL,
|
|
97
97
|
withMessageFtsSessionFilter
|
|
@@ -1886,6 +1886,7 @@ var RERANK_MODEL = "gte-reranker-modernbert-base-f32";
|
|
|
1886
1886
|
var RERANK_LANE_LIMIT = 25;
|
|
1887
1887
|
var DEADLINE_MS = 1500;
|
|
1888
1888
|
var DOCUMENT_BYTES = 1024;
|
|
1889
|
+
var proseWordSegmenter = new Intl.Segmenter(undefined, { granularity: "word" });
|
|
1889
1890
|
function isProseQuery(query) {
|
|
1890
1891
|
const text = query.trim();
|
|
1891
1892
|
if (!text || /[\n;]|^["'`]|["'`]$/.test(text))
|
|
@@ -1894,10 +1895,10 @@ function isProseQuery(query) {
|
|
|
1894
1895
|
return false;
|
|
1895
1896
|
if (/\b(?:[A-Z][A-Z_]+:|\w*(?:Error|Exception):)|\bat\s+\S+\s*\(/.test(text))
|
|
1896
1897
|
return false;
|
|
1897
|
-
const words = text.replace(/[?!.]$/, "").split(/\s+/);
|
|
1898
|
+
const words = /(?![a-zA-Z])\p{L}/u.test(text) ? [...proseWordSegmenter.segment(text)].filter((word) => word.isWordLike).map((word) => word.segment) : text.replace(/[?!.]$/, "").split(/\s+/);
|
|
1898
1899
|
if (words.length < 3)
|
|
1899
1900
|
return false;
|
|
1900
|
-
const plain = words.filter((word) => /^[
|
|
1901
|
+
const plain = words.filter((word) => /^[\p{L}\p{M}]+(?:['’-][\p{L}\p{M}]+)*$/u.test(word));
|
|
1901
1902
|
if (/^(?:how|why|what|where|when|which|who)\b/i.test(text))
|
|
1902
1903
|
return plain.length >= 3;
|
|
1903
1904
|
return words.length >= 4 && plain.length >= 3 && !/[\\/]|::|=/.test(text);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
registerExitAbort
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-8sqebjzk.js";
|
|
4
4
|
import {
|
|
5
5
|
inRootAsyncContext2
|
|
6
6
|
} from "./index-2qtx0q6h.js";
|
|
7
7
|
import {
|
|
8
8
|
createWorkerShutdown
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-x2n261wp.js";
|
|
10
10
|
|
|
11
11
|
// ../plugin/src/tools/ctx-expand/v2-archive-reader.ts
|
|
12
12
|
import { Worker } from "node:worker_threads";
|
|
@@ -138,10 +138,10 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
138
138
|
] = await Promise.all([
|
|
139
139
|
import("./sqlite-v89bj0yy.js"),
|
|
140
140
|
import("./store-reader-2m80zs5z.js"),
|
|
141
|
-
import("./store-
|
|
142
|
-
import("./read-session-chunk-
|
|
143
|
-
import("./render-
|
|
144
|
-
import("./search-archive-
|
|
141
|
+
import("./store-v60q7dje.js"),
|
|
142
|
+
import("./read-session-chunk-jxq427v6.js"),
|
|
143
|
+
import("./render-2wan3bfh.js"),
|
|
144
|
+
import("./search-archive-pgrv04gv.js"),
|
|
145
145
|
import("./expand-attachments-8sxeyj26.js")
|
|
146
146
|
]);
|
|
147
147
|
const pool = new V2StoreReaderPool;
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
} from "./index-wt7vmyj4.js";
|
|
10
10
|
import {
|
|
11
11
|
cleanUserText2
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-mx757f3g.js";
|
|
13
13
|
import {
|
|
14
14
|
recordMessageFtsRowid2,
|
|
15
15
|
recordIndexedMessageTime2,
|
|
16
16
|
messageFtsOrdinalRangeIsMapped2,
|
|
17
17
|
deleteUnmappedMessageFtsRows2
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-ck8wj35v.js";
|
|
19
19
|
import {
|
|
20
20
|
logSlowWriteTransaction
|
|
21
21
|
} from "./index-0wtm7g7f.js";
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
TAG_SELECT_COLUMNS2,
|
|
24
24
|
getCandidateToolOwners2,
|
|
25
25
|
pickNearestPriorOwner2
|
|
26
|
-
} from "./index-
|
|
26
|
+
} from "./index-pwp6zyx3.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-c1dqxr10.js";
|
|
75
75
|
import {
|
|
76
76
|
markHostUnservedRow,
|
|
77
77
|
isHostUnservedRow
|
|
@@ -102,6 +102,8 @@ var OVERFLOW_PATTERNS = [
|
|
|
102
102
|
/request entity too large/i,
|
|
103
103
|
/context length is only \d+ tokens/i,
|
|
104
104
|
/input length.*exceeds.*context length/i,
|
|
105
|
+
/\bContextWindowExceededError\b/i,
|
|
106
|
+
/\bthe input \(\d+ tokens?\) is longer than the model's context length \(\d+ tokens?\)/i,
|
|
105
107
|
/prompt too long; exceeded (?:max )?context length/i,
|
|
106
108
|
/too large for model with \d+ maximum context length/i,
|
|
107
109
|
/model_context_window_exceeded/i,
|
|
@@ -124,6 +126,10 @@ var LIMIT_EXTRACTION_PATTERNS = [
|
|
|
124
126
|
},
|
|
125
127
|
{ pattern: /context size[^0-9]{0,40}(\d{4,})\s*tokens?/i, provenance: "combined" },
|
|
126
128
|
{ pattern: /exceeds? the context length of (\d+)/i, provenance: "combined" },
|
|
129
|
+
{
|
|
130
|
+
pattern: /\bthe input \(\d+ tokens?\) is longer than the model's context length \((\d+) tokens?\)/i,
|
|
131
|
+
provenance: "combined"
|
|
132
|
+
},
|
|
127
133
|
{
|
|
128
134
|
pattern: />\s*(\d+)\s*(?:tokens?\s*)?(?:maximum|max|limit)\b/i,
|
|
129
135
|
provenance: "prompt_only"
|
|
@@ -262,7 +268,9 @@ function parseReportedInputTokens(message) {
|
|
|
262
268
|
/input token count\s*\(?\s*(\d+)/i,
|
|
263
269
|
/input length\s*(\d+)/i,
|
|
264
270
|
/prompt was\s*(\d+)/i,
|
|
265
|
-
/messages resulted in\s*(\d+)\s*tokens?/i
|
|
271
|
+
/messages resulted in\s*(\d+)\s*tokens?/i,
|
|
272
|
+
/\bthe input \((\d+) tokens?\) is longer than the model's context length \(\d+ tokens?\)/i,
|
|
273
|
+
/\(\s*(\d+)\s+in the messages,\s*\d+\s+in the completion\s*\)/i
|
|
266
274
|
];
|
|
267
275
|
for (const pattern of patterns) {
|
|
268
276
|
const raw = message.match(pattern)?.[1];
|
|
@@ -3126,7 +3134,7 @@ function looksImageLike(part) {
|
|
|
3126
3134
|
const type = typeof part.type === "string" ? part.type.toLowerCase() : "";
|
|
3127
3135
|
const mime = typeof part.mime === "string" ? part.mime.toLowerCase() : "";
|
|
3128
3136
|
const mediaType = typeof part.mediaType === "string" ? part.mediaType.toLowerCase() : "";
|
|
3129
|
-
return type.includes("image") || mime.startsWith("image/") || mediaType.startsWith("image/") || part.image_url !== undefined || part.imageUrl !== undefined || part.image !== undefined;
|
|
3137
|
+
return type.includes("image") || mime.startsWith("image/") || mediaType.startsWith("image/") || part.image_url !== undefined || part.imageUrl !== undefined || part.image !== undefined || type.includes("file") && (typeof part.url === "string" && part.url.startsWith("data:image/") || typeof part.data === "string" && /^(?:data:image\/|\/9j\/|iVBORw0KGgo|R0lGOD)/.test(part.data));
|
|
3130
3138
|
}
|
|
3131
3139
|
function defaultImageTokenHeuristic(part) {
|
|
3132
3140
|
if (isRecord(part)) {
|
|
@@ -3490,7 +3498,7 @@ function buildTrueRawTokenIndex(sessionId, messages, options) {
|
|
|
3490
3498
|
} else {
|
|
3491
3499
|
const raw = tokenForMessage(message, options);
|
|
3492
3500
|
const seed = options.calibration;
|
|
3493
|
-
total = seed ? (raw.toolInput + raw.toolOutput) * seed.toolsRatio + (raw.text + raw.reasoning + raw.other) * seed.proseRatio + raw.image : raw.total;
|
|
3501
|
+
total = options.measure === "summary-removed" ? raw.text * (seed?.proseRatio ?? 1) + raw.toolInput * (seed?.toolsRatio ?? 1) : seed ? (raw.toolInput + raw.toolOutput) * seed.toolsRatio + (raw.text + raw.reasoning + raw.other) * seed.proseRatio + raw.image : raw.total;
|
|
3494
3502
|
}
|
|
3495
3503
|
tokensByOrdinal.set(message.ordinal, total);
|
|
3496
3504
|
idsByOrdinal.set(message.ordinal, message.id);
|