@cortexkit/pi-magic-context 0.49.61 → 0.49.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +60 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3601,7 +3601,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3601
3601
|
// package.json
|
|
3602
3602
|
var package_default = {
|
|
3603
3603
|
name: "@cortexkit/pi-magic-context",
|
|
3604
|
-
version: "0.49.
|
|
3604
|
+
version: "0.49.63",
|
|
3605
3605
|
type: "module",
|
|
3606
3606
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3607
3607
|
main: "dist/index.js",
|
|
@@ -24799,26 +24799,24 @@ function schedulePiTransformDecisionResolve(args) {
|
|
|
24799
24799
|
return false;
|
|
24800
24800
|
pendingPiDecisionBySession.delete(args.sessionId);
|
|
24801
24801
|
const token = addScheduledWriteToken(args.sessionId);
|
|
24802
|
+
const assertQueuedWrite = args.assertQueuedWrite ?? args.assertCurrentPass;
|
|
24802
24803
|
inRootAsyncContext2(() => setTimeout(() => {
|
|
24804
|
+
if (!hasScheduledWriteToken(args.sessionId, token))
|
|
24805
|
+
return;
|
|
24803
24806
|
try {
|
|
24804
|
-
|
|
24805
|
-
|
|
24806
|
-
|
|
24807
|
-
pending.publicationGuard?.();
|
|
24808
|
-
args.assertCurrentPass?.();
|
|
24809
|
-
} catch {
|
|
24810
|
-
sessionLog2(args.sessionId, "DISCARDED CONTEXT RESULT: queued Pi transform decision");
|
|
24811
|
-
return;
|
|
24812
|
-
}
|
|
24813
|
-
writeTransformDecisionBestEffort(dbPath, {
|
|
24814
|
-
...pending,
|
|
24815
|
-
sessionId: args.sessionId,
|
|
24816
|
-
harness: "pi",
|
|
24817
|
-
messageId: targetMessageId
|
|
24818
|
-
});
|
|
24819
|
-
} finally {
|
|
24807
|
+
pending.publicationGuard?.();
|
|
24808
|
+
assertQueuedWrite?.();
|
|
24809
|
+
} catch {
|
|
24820
24810
|
deleteScheduledWriteToken(args.sessionId, token);
|
|
24811
|
+
sessionLog2(args.sessionId, "DISCARDED CONTEXT RESULT: queued Pi transform decision");
|
|
24812
|
+
return;
|
|
24821
24813
|
}
|
|
24814
|
+
writeQueuedTransformDecision(dbPath, token, {
|
|
24815
|
+
...pending,
|
|
24816
|
+
sessionId: args.sessionId,
|
|
24817
|
+
harness: "pi",
|
|
24818
|
+
messageId: targetMessageId
|
|
24819
|
+
});
|
|
24822
24820
|
}, 0));
|
|
24823
24821
|
return true;
|
|
24824
24822
|
}
|
|
@@ -24879,11 +24877,25 @@ function findNewestPiAssistantEntryIdAfter(entries, snapshotNewestAssistantEntry
|
|
|
24879
24877
|
}
|
|
24880
24878
|
return null;
|
|
24881
24879
|
}
|
|
24882
|
-
|
|
24880
|
+
var DECISION_WRITE_RETRY_DELAYS_MS = [10, 25, 50, 100, 250, 500, 1000];
|
|
24881
|
+
function writeQueuedTransformDecision(dbPath, token, row, attempt = 0) {
|
|
24882
|
+
let retryInMs;
|
|
24883
24883
|
try {
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
|
|
24884
|
+
if (!hasScheduledWriteToken(row.sessionId, token))
|
|
24885
|
+
return;
|
|
24886
|
+
try {
|
|
24887
|
+
(writerOverrideForTests ?? writeTransformDecisionRow)(dbPath, row);
|
|
24888
|
+
} catch (error) {
|
|
24889
|
+
if (isTransientSqliteError2(error))
|
|
24890
|
+
retryInMs = DECISION_WRITE_RETRY_DELAYS_MS[attempt];
|
|
24891
|
+
}
|
|
24892
|
+
} finally {
|
|
24893
|
+
if (retryInMs === undefined)
|
|
24894
|
+
deleteScheduledWriteToken(row.sessionId, token);
|
|
24895
|
+
}
|
|
24896
|
+
if (retryInMs === undefined)
|
|
24897
|
+
return;
|
|
24898
|
+
inRootAsyncContext2(() => setTimeout(() => writeQueuedTransformDecision(dbPath, token, row, attempt + 1), retryInMs));
|
|
24887
24899
|
}
|
|
24888
24900
|
function writeTransformDecisionRow(dbPath, row) {
|
|
24889
24901
|
const db = new Database2(dbPath);
|
|
@@ -29134,10 +29146,13 @@ function safeJsonStringify(value) {
|
|
|
29134
29146
|
function isRecord2(value) {
|
|
29135
29147
|
return typeof value === "object" && value !== null;
|
|
29136
29148
|
}
|
|
29149
|
+
function isUntaggedAssistantText(role, text, preserveTagOnlyAssistantText) {
|
|
29150
|
+
return role === "assistant" && (stripWellFormedLeadingTagPrefix(text).trim().length === 0 || preserveTagOnlyAssistantText === true && text.includes("§") && stripPersistedAssistantText(text).length === 0);
|
|
29151
|
+
}
|
|
29137
29152
|
function tagTextPart(args) {
|
|
29138
29153
|
const identityStart = args.timing ? performance.now() : 0;
|
|
29139
29154
|
const text = args.part.getText() ?? "";
|
|
29140
|
-
if (args.message.info.role
|
|
29155
|
+
if (isUntaggedAssistantText(args.message.info.role, text, args.preserveTagOnlyAssistantText)) {
|
|
29141
29156
|
if (args.timing)
|
|
29142
29157
|
args.timing.identity += performance.now() - identityStart;
|
|
29143
29158
|
return;
|
|
@@ -48079,13 +48094,27 @@ var piTagTextTokenCacheBySession = new Map;
|
|
|
48079
48094
|
var piTagToolTokenCacheBySession = new Map;
|
|
48080
48095
|
var piTextIdentitySourceCacheBySession = new Map;
|
|
48081
48096
|
var piFallbackIndexesBySession = new Map;
|
|
48097
|
+
var PI_PRESERVE_TAG_ONLY_ASSISTANT_TEXT = true;
|
|
48082
48098
|
function buildPiTextIdentityPlan(db, sessionId, tagger, transcript, reuseCandidates = new Set) {
|
|
48083
48099
|
const currentSourcesByMessageId = new Map;
|
|
48100
|
+
const untaggedOrdinalsByMessageId = new Map;
|
|
48084
48101
|
for (const message of transcript.messages) {
|
|
48085
48102
|
const messageId = message.info.id;
|
|
48086
48103
|
if (messageId === undefined)
|
|
48087
48104
|
continue;
|
|
48088
|
-
|
|
48105
|
+
const sources = [];
|
|
48106
|
+
const untagged = new Set;
|
|
48107
|
+
for (const part of message.parts) {
|
|
48108
|
+
if (part.kind !== "text")
|
|
48109
|
+
continue;
|
|
48110
|
+
const text = part.getText() ?? "";
|
|
48111
|
+
if (isUntaggedAssistantText(message.info.role, text, PI_PRESERVE_TAG_ONLY_ASSISTANT_TEXT))
|
|
48112
|
+
untagged.add(sources.length);
|
|
48113
|
+
sources.push(withoutPiLeadingTemporalMarker(stripTagPrefix(text)));
|
|
48114
|
+
}
|
|
48115
|
+
currentSourcesByMessageId.set(messageId, sources);
|
|
48116
|
+
if (untagged.size > 0)
|
|
48117
|
+
untaggedOrdinalsByMessageId.set(messageId, untagged);
|
|
48089
48118
|
}
|
|
48090
48119
|
const legacyRowsByMessageId = new Map;
|
|
48091
48120
|
const versionedMessageIds = new Set;
|
|
@@ -48133,11 +48162,12 @@ function buildPiTextIdentityPlan(db, sessionId, tagger, transcript, reuseCandida
|
|
|
48133
48162
|
if (legacyRows.length === 0)
|
|
48134
48163
|
continue;
|
|
48135
48164
|
legacyRows.sort((left, right) => left.ordinal - right.ordinal);
|
|
48136
|
-
const
|
|
48137
|
-
|
|
48138
|
-
|
|
48165
|
+
const untagged = untaggedOrdinalsByMessageId.get(messageId);
|
|
48166
|
+
const rowOrdinals = new Set(legacyRows.map((row) => row.ordinal));
|
|
48167
|
+
const vectorAligned = rowOrdinals.size === legacyRows.length && legacyRows.every((row) => row.ordinal < currentSources.length) && currentSources.every((_, ordinal) => rowOrdinals.has(ordinal) || untagged?.has(ordinal) === true);
|
|
48168
|
+
const vectorMatches = vectorAligned && legacyRows.every((row) => {
|
|
48139
48169
|
const stored = withoutPiLeadingTemporalMarker(sourceCache.get(row.tagId) ?? "");
|
|
48140
|
-
const current = currentSources[
|
|
48170
|
+
const current = currentSources[row.ordinal] ?? "";
|
|
48141
48171
|
if (stored === current)
|
|
48142
48172
|
return true;
|
|
48143
48173
|
const strippedCurrent = stripSystemInjection(current);
|
|
@@ -49938,7 +49968,8 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
49938
49968
|
db: options.db,
|
|
49939
49969
|
sessionId,
|
|
49940
49970
|
branchEntries,
|
|
49941
|
-
assertCurrentPass
|
|
49971
|
+
assertCurrentPass,
|
|
49972
|
+
assertQueuedWrite: budget.assertDecisionPublication
|
|
49942
49973
|
});
|
|
49943
49974
|
let rawOrdinalCount;
|
|
49944
49975
|
let passOrdinalAlignment;
|
|
@@ -52678,7 +52709,7 @@ async function runPipeline(args) {
|
|
|
52678
52709
|
args.assertCurrentPass?.();
|
|
52679
52710
|
return tagTranscript(args.sessionId, { ...transcript, messages: taggingView }, args.tagger, args.db, {
|
|
52680
52711
|
skipPrefixInjection: !ctxReduceCallable,
|
|
52681
|
-
preserveTagOnlyAssistantText:
|
|
52712
|
+
preserveTagOnlyAssistantText: PI_PRESERVE_TAG_ONLY_ASSISTANT_TEXT,
|
|
52682
52713
|
entryFingerprintByMessageId,
|
|
52683
52714
|
reuseMessageIds: textIdentityPlan.reusableMessageIds,
|
|
52684
52715
|
reuseTextMessageIds: textIdentityPlan.reusableTextMessageIds,
|
package/package.json
CHANGED