@cortexkit/pi-magic-context 0.32.2 → 0.32.4
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 +173 -70
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -158851,6 +158851,7 @@ var STRICT_TOOL_ALLOWLIST_ENTRIES = [
|
|
|
158851
158851
|
["magic-context-dreamer", ["ctx_memory"]]
|
|
158852
158852
|
];
|
|
158853
158853
|
var STRICT_TOOL_ALLOWLIST = new Map(STRICT_TOOL_ALLOWLIST_ENTRIES);
|
|
158854
|
+
var ZERO_TOOL_PROMPT_REQUIRED_AGENTS = new Set(STRICT_TOOL_ALLOWLIST_ENTRIES.filter(([, tools]) => tools.length === 0).map(([agent]) => agent));
|
|
158854
158855
|
function inferAccountingSubagent(agent) {
|
|
158855
158856
|
if (agent.includes("sidekick"))
|
|
158856
158857
|
return "sidekick";
|
|
@@ -158968,12 +158969,13 @@ class PiSubagentRunner {
|
|
|
158968
158969
|
}
|
|
158969
158970
|
return result;
|
|
158970
158971
|
}
|
|
158971
|
-
const failBeforeSpawn = (reason, error) => {
|
|
158972
|
+
const failBeforeSpawn = (reason, error, transient = false) => {
|
|
158972
158973
|
const result = {
|
|
158973
158974
|
ok: false,
|
|
158974
158975
|
reason,
|
|
158975
158976
|
error,
|
|
158976
|
-
durationMs: Date.now() - startTime
|
|
158977
|
+
durationMs: Date.now() - startTime,
|
|
158978
|
+
...transient ? { transient: true } : {}
|
|
158977
158979
|
};
|
|
158978
158980
|
try {
|
|
158979
158981
|
recordAccounting(result);
|
|
@@ -158982,6 +158984,9 @@ class PiSubagentRunner {
|
|
|
158982
158984
|
}
|
|
158983
158985
|
return result;
|
|
158984
158986
|
};
|
|
158987
|
+
if (ZERO_TOOL_PROMPT_REQUIRED_AGENTS.has(options.agent) && options.systemPrompt.trim().length === 0) {
|
|
158988
|
+
return failBeforeSpawn("invalid_prompt", `zero-tool Pi subagent "${options.agent}" requires a non-empty system prompt`, true);
|
|
158989
|
+
}
|
|
158985
158990
|
const promptBytes = Buffer.byteLength(options.userMessage, "utf8");
|
|
158986
158991
|
const deliverViaStdin = promptBytes > PROMPT_ARGV_MAX_BYTES || this.platform === "win32";
|
|
158987
158992
|
let systemPromptTempDir;
|
|
@@ -159549,26 +159554,32 @@ init_logger();
|
|
|
159549
159554
|
// ../plugin/src/features/magic-context/compaction-marker.ts
|
|
159550
159555
|
init_data_path();
|
|
159551
159556
|
init_logger();
|
|
159557
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
159552
159558
|
import { existsSync as existsSync10 } from "node:fs";
|
|
159553
159559
|
import { join as join9 } from "node:path";
|
|
159554
159560
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
159555
|
-
|
|
159556
|
-
|
|
159557
|
-
|
|
159558
|
-
|
|
159561
|
+
var ID_PREFIX_HEX_LENGTH = 12;
|
|
159562
|
+
var ID_SUFFIX_LENGTH = 14;
|
|
159563
|
+
var ID_PREFIX_MASK = (1n << BigInt(ID_PREFIX_HEX_LENGTH * 4)) - 1n;
|
|
159564
|
+
function deterministicBase62(seed, length) {
|
|
159565
|
+
let value = BigInt(`0x${createHash7("sha256").update(seed).digest("hex")}`);
|
|
159566
|
+
const chars = Array(length);
|
|
159567
|
+
for (let index = length - 1;index >= 0; index -= 1) {
|
|
159568
|
+
chars[index] = BASE62_CHARS[Number(value % 62n)];
|
|
159569
|
+
value /= 62n;
|
|
159559
159570
|
}
|
|
159560
159571
|
return chars.join("");
|
|
159561
159572
|
}
|
|
159562
|
-
function generateId(prefix, timestampMs, counter
|
|
159563
|
-
const encoded = BigInt(timestampMs) * 0x1000n + counter;
|
|
159564
|
-
const hex = encoded.toString(16).padStart(
|
|
159565
|
-
return `${prefix}_${hex}${
|
|
159573
|
+
function generateId(prefix, timestampMs, counter, identity) {
|
|
159574
|
+
const encoded = BigInt(Math.max(0, Math.floor(timestampMs))) * 0x1000n + counter & ID_PREFIX_MASK;
|
|
159575
|
+
const hex = encoded.toString(16).padStart(ID_PREFIX_HEX_LENGTH, "0");
|
|
159576
|
+
return `${prefix}_${hex}${deterministicBase62(`${prefix}\x00${identity}`, ID_SUFFIX_LENGTH)}`;
|
|
159566
159577
|
}
|
|
159567
|
-
function generateMessageId(timestampMs, counter = 0n) {
|
|
159568
|
-
return generateId("msg", timestampMs, counter);
|
|
159578
|
+
function generateMessageId(timestampMs, counter = 0n, identity = "") {
|
|
159579
|
+
return generateId("msg", timestampMs, counter, identity);
|
|
159569
159580
|
}
|
|
159570
|
-
function generatePartId(timestampMs, counter = 0n) {
|
|
159571
|
-
return generateId("prt", timestampMs, counter);
|
|
159581
|
+
function generatePartId(timestampMs, counter = 0n, identity = "") {
|
|
159582
|
+
return generateId("prt", timestampMs, counter, identity);
|
|
159572
159583
|
}
|
|
159573
159584
|
function getOpenCodeDbPath2() {
|
|
159574
159585
|
return join9(getDataDir(), "opencode", "opencode.db");
|
|
@@ -159673,6 +159684,38 @@ function compareOpenCodeMessagesByCanonicalOrder(sessionId, leftMessageId, right
|
|
|
159673
159684
|
return 1;
|
|
159674
159685
|
return 0;
|
|
159675
159686
|
}
|
|
159687
|
+
function removeLegacyMarkerLineageRows(db, args) {
|
|
159688
|
+
const legacySummaries = db.prepare(`SELECT m.id
|
|
159689
|
+
FROM message m
|
|
159690
|
+
WHERE m.session_id = ?
|
|
159691
|
+
AND m.id <> ?
|
|
159692
|
+
AND COALESCE(json_extract(m.data, '$.summary'), 0) = 1
|
|
159693
|
+
AND COALESCE(json_extract(m.data, '$.finish'), '') = 'stop'
|
|
159694
|
+
AND COALESCE(json_extract(m.data, '$.parentID'), '') = ?
|
|
159695
|
+
AND EXISTS (
|
|
159696
|
+
SELECT 1
|
|
159697
|
+
FROM part p
|
|
159698
|
+
WHERE p.session_id = m.session_id
|
|
159699
|
+
AND p.message_id = m.id
|
|
159700
|
+
AND COALESCE(json_extract(p.data, '$.type'), '') = 'text'
|
|
159701
|
+
AND COALESCE(json_extract(p.data, '$.text'), '') = ?
|
|
159702
|
+
)`).all(args.sessionId, args.summaryMessageId, args.boundaryMessageId, args.summaryText);
|
|
159703
|
+
const legacySummaryIds = legacySummaries.flatMap((row) => typeof row.id === "string" ? [row.id] : []);
|
|
159704
|
+
if (legacySummaryIds.length === 0)
|
|
159705
|
+
return;
|
|
159706
|
+
const deleteSummaryParts = db.prepare("DELETE FROM part WHERE session_id = ? AND message_id = ?");
|
|
159707
|
+
const deleteSummary = db.prepare("DELETE FROM message WHERE session_id = ? AND id = ?");
|
|
159708
|
+
for (const summaryMessageId of legacySummaryIds) {
|
|
159709
|
+
deleteSummaryParts.run(args.sessionId, summaryMessageId);
|
|
159710
|
+
deleteSummary.run(args.sessionId, summaryMessageId);
|
|
159711
|
+
}
|
|
159712
|
+
db.prepare(`DELETE FROM part
|
|
159713
|
+
WHERE session_id = ?
|
|
159714
|
+
AND message_id = ?
|
|
159715
|
+
AND id <> ?
|
|
159716
|
+
AND COALESCE(json_extract(data, '$.type'), '') = 'compaction'
|
|
159717
|
+
AND COALESCE(json_extract(data, '$.auto'), 0) = 1`).run(args.sessionId, args.boundaryMessageId, args.compactionPartId);
|
|
159718
|
+
}
|
|
159676
159719
|
function injectCompactionMarker(args) {
|
|
159677
159720
|
const db = getWritableOpenCodeDb();
|
|
159678
159721
|
if (!isOpenCodeSchemaCompatible(db, getOpenCodeDbPath2())) {
|
|
@@ -159684,9 +159727,10 @@ function injectCompactionMarker(args) {
|
|
|
159684
159727
|
return null;
|
|
159685
159728
|
}
|
|
159686
159729
|
const boundaryTime = boundary.timeCreated;
|
|
159687
|
-
const
|
|
159688
|
-
const
|
|
159689
|
-
const
|
|
159730
|
+
const markerIdentity = `${args.sessionId}\x00${args.endMessageId}`;
|
|
159731
|
+
const summaryMsgId = generateMessageId(boundaryTime + 1, 1n, `${markerIdentity}\x00summary-message`);
|
|
159732
|
+
const compactionPartId = generatePartId(boundaryTime, 1n, `${markerIdentity}\x00compaction-part`);
|
|
159733
|
+
const summaryPartId = generatePartId(boundaryTime + 1, 2n, `${markerIdentity}\x00summary-part`);
|
|
159690
159734
|
const summaryMsgData = JSON.stringify({
|
|
159691
159735
|
role: "assistant",
|
|
159692
159736
|
parentID: boundary.id,
|
|
@@ -159703,9 +159747,36 @@ function injectCompactionMarker(args) {
|
|
|
159703
159747
|
});
|
|
159704
159748
|
try {
|
|
159705
159749
|
db.transaction(() => {
|
|
159706
|
-
db
|
|
159707
|
-
|
|
159708
|
-
|
|
159750
|
+
removeLegacyMarkerLineageRows(db, {
|
|
159751
|
+
sessionId: args.sessionId,
|
|
159752
|
+
boundaryMessageId: boundary.id,
|
|
159753
|
+
summaryText: args.summaryText,
|
|
159754
|
+
summaryMessageId: summaryMsgId,
|
|
159755
|
+
compactionPartId
|
|
159756
|
+
});
|
|
159757
|
+
db.prepare(`INSERT INTO part (id, message_id, session_id, time_created, time_updated, data)
|
|
159758
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
159759
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
159760
|
+
message_id = excluded.message_id,
|
|
159761
|
+
session_id = excluded.session_id,
|
|
159762
|
+
time_created = excluded.time_created,
|
|
159763
|
+
time_updated = excluded.time_updated,
|
|
159764
|
+
data = excluded.data`).run(compactionPartId, boundary.id, args.sessionId, boundaryTime, boundaryTime, '{"type":"compaction","auto":true}');
|
|
159765
|
+
db.prepare(`INSERT INTO message (id, session_id, time_created, time_updated, data)
|
|
159766
|
+
VALUES (?, ?, ?, ?, ?)
|
|
159767
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
159768
|
+
session_id = excluded.session_id,
|
|
159769
|
+
time_created = excluded.time_created,
|
|
159770
|
+
time_updated = excluded.time_updated,
|
|
159771
|
+
data = excluded.data`).run(summaryMsgId, args.sessionId, boundaryTime + 1, boundaryTime + 1, summaryMsgData);
|
|
159772
|
+
db.prepare(`INSERT INTO part (id, message_id, session_id, time_created, time_updated, data)
|
|
159773
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
159774
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
159775
|
+
message_id = excluded.message_id,
|
|
159776
|
+
session_id = excluded.session_id,
|
|
159777
|
+
time_created = excluded.time_created,
|
|
159778
|
+
time_updated = excluded.time_updated,
|
|
159779
|
+
data = excluded.data`).run(summaryPartId, summaryMsgId, args.sessionId, boundaryTime + 1, boundaryTime + 1, JSON.stringify({ type: "text", text: args.summaryText }));
|
|
159709
159780
|
})();
|
|
159710
159781
|
log(`[magic-context] compaction-marker: injected boundary at user msg ${boundary.id} (ordinal ~${args.endOrdinal}), summary msg ${summaryMsgId}`);
|
|
159711
159782
|
return {
|
|
@@ -159752,7 +159823,7 @@ function openOpenCodeDb() {
|
|
|
159752
159823
|
}
|
|
159753
159824
|
|
|
159754
159825
|
// ../plugin/src/features/magic-context/dreamer/task-executor.ts
|
|
159755
|
-
import { createHash as
|
|
159826
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
159756
159827
|
import { existsSync as existsSync15 } from "node:fs";
|
|
159757
159828
|
|
|
159758
159829
|
// ../plugin/src/agents/dreamer.ts
|
|
@@ -159770,6 +159841,9 @@ init_logger();
|
|
|
159770
159841
|
// ../plugin/src/shared/model-suggestion-retry.ts
|
|
159771
159842
|
init_logger();
|
|
159772
159843
|
var ABORT_CALL_TIMEOUT_MS = 3000;
|
|
159844
|
+
function copyPromptArgs(args, body) {
|
|
159845
|
+
return { ...args, body: { ...body } };
|
|
159846
|
+
}
|
|
159773
159847
|
function extractMessage(error) {
|
|
159774
159848
|
if (typeof error === "string")
|
|
159775
159849
|
return error;
|
|
@@ -159883,40 +159957,41 @@ function shortErr(error) {
|
|
|
159883
159957
|
return extractMessage(error);
|
|
159884
159958
|
}
|
|
159885
159959
|
async function attemptOnce(client, args, timeoutMs, signal, callContext, label) {
|
|
159960
|
+
const originalBody = { ...args.body };
|
|
159961
|
+
const attemptArgs = copyPromptArgs(args, originalBody);
|
|
159886
159962
|
try {
|
|
159887
|
-
await promptWithTimeout(client,
|
|
159963
|
+
await promptWithTimeout(client, attemptArgs, timeoutMs, signal);
|
|
159888
159964
|
return;
|
|
159889
159965
|
} catch (error) {
|
|
159890
159966
|
if (isNonRetryable(error, signal))
|
|
159891
159967
|
throw error;
|
|
159892
159968
|
const suggestion = parseModelSuggestion(error);
|
|
159893
|
-
if (!suggestion || !
|
|
159969
|
+
if (!suggestion || !originalBody.model) {
|
|
159894
159970
|
throw error;
|
|
159895
159971
|
}
|
|
159896
159972
|
log(`[${callContext}] ${label}: model not found, retrying with suggestion`, {
|
|
159897
159973
|
original: `${suggestion.providerID}/${suggestion.modelID}`,
|
|
159898
159974
|
suggested: suggestion.suggestion
|
|
159899
159975
|
});
|
|
159900
|
-
await promptWithTimeout(client, {
|
|
159901
|
-
...
|
|
159902
|
-
|
|
159903
|
-
|
|
159904
|
-
|
|
159905
|
-
providerID: suggestion.providerID,
|
|
159906
|
-
modelID: suggestion.suggestion
|
|
159907
|
-
}
|
|
159976
|
+
await promptWithTimeout(client, copyPromptArgs(args, {
|
|
159977
|
+
...originalBody,
|
|
159978
|
+
model: {
|
|
159979
|
+
providerID: suggestion.providerID,
|
|
159980
|
+
modelID: suggestion.suggestion
|
|
159908
159981
|
}
|
|
159909
|
-
}, timeoutMs, signal);
|
|
159982
|
+
}), timeoutMs, signal);
|
|
159910
159983
|
}
|
|
159911
159984
|
}
|
|
159912
159985
|
async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
159913
159986
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
159914
159987
|
const callContext = options.callContext ?? "subagent";
|
|
159915
159988
|
const fallbacks = options.fallbackModels ?? [];
|
|
159916
|
-
const
|
|
159989
|
+
const baseBody = { ...args.body };
|
|
159990
|
+
const baseArgs = copyPromptArgs(args, baseBody);
|
|
159991
|
+
const explicitPrimaryLabel = baseBody.model?.providerID && baseBody.model.modelID ? `${baseBody.model.providerID}/${baseBody.model.modelID}` : "primary";
|
|
159917
159992
|
let lastError = null;
|
|
159918
159993
|
try {
|
|
159919
|
-
await attemptOnce(client,
|
|
159994
|
+
await attemptOnce(client, baseArgs, timeoutMs, options.signal, callContext, explicitPrimaryLabel);
|
|
159920
159995
|
return;
|
|
159921
159996
|
} catch (error) {
|
|
159922
159997
|
lastError = error;
|
|
@@ -159934,10 +160009,10 @@ async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
|
159934
160009
|
continue;
|
|
159935
160010
|
}
|
|
159936
160011
|
const label = `${parsed.providerID}/${parsed.modelID}`;
|
|
159937
|
-
const attemptArgs = {
|
|
159938
|
-
...
|
|
159939
|
-
|
|
159940
|
-
};
|
|
160012
|
+
const attemptArgs = copyPromptArgs(baseArgs, {
|
|
160013
|
+
...baseBody,
|
|
160014
|
+
model: parsed
|
|
160015
|
+
});
|
|
159941
160016
|
try {
|
|
159942
160017
|
await attemptOnce(client, attemptArgs, timeoutMs, options.signal, callContext, label);
|
|
159943
160018
|
log(`[${callContext}] fallback succeeded with ${label} (attempt ${i + 2}/${fallbacks.length + 1})`);
|
|
@@ -159965,17 +160040,19 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
159965
160040
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
159966
160041
|
const callContext = options.callContext ?? "subagent";
|
|
159967
160042
|
const fallbacks = options.fallbackModels ?? [];
|
|
159968
|
-
const
|
|
160043
|
+
const baseBody = { ...args.body };
|
|
160044
|
+
const baseArgs = copyPromptArgs(args, baseBody);
|
|
160045
|
+
const explicitPrimaryLabel = baseBody.model?.providerID && baseBody.model.modelID ? `${baseBody.model.providerID}/${baseBody.model.modelID}` : "primary";
|
|
159969
160046
|
const totalAttempts = fallbacks.length + 1;
|
|
159970
160047
|
let firstError = null;
|
|
159971
160048
|
let lastError = null;
|
|
159972
160049
|
try {
|
|
159973
|
-
return await attemptAndValidate(client,
|
|
160050
|
+
return await attemptAndValidate(client, baseArgs, timeoutMs, options.signal, callContext, {
|
|
159974
160051
|
label: explicitPrimaryLabel,
|
|
159975
160052
|
attemptIndex: 0,
|
|
159976
160053
|
isFallback: false,
|
|
159977
160054
|
totalAttempts,
|
|
159978
|
-
model:
|
|
160055
|
+
model: baseBody.model
|
|
159979
160056
|
}, options);
|
|
159980
160057
|
} catch (error) {
|
|
159981
160058
|
firstError = error;
|
|
@@ -159994,10 +160071,10 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
159994
160071
|
continue;
|
|
159995
160072
|
}
|
|
159996
160073
|
const label = `${parsed.providerID}/${parsed.modelID}`;
|
|
159997
|
-
const attemptArgs = {
|
|
159998
|
-
...
|
|
159999
|
-
|
|
160000
|
-
};
|
|
160074
|
+
const attemptArgs = copyPromptArgs(baseArgs, {
|
|
160075
|
+
...baseBody,
|
|
160076
|
+
model: parsed
|
|
160077
|
+
});
|
|
160001
160078
|
const attempt = {
|
|
160002
160079
|
label,
|
|
160003
160080
|
attemptIndex: i + 1,
|
|
@@ -174844,7 +174921,7 @@ var MagicContextConfigSchema = exports_external.object({
|
|
|
174844
174921
|
init_logger();
|
|
174845
174922
|
|
|
174846
174923
|
// ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
|
|
174847
|
-
import { createHash as
|
|
174924
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
174848
174925
|
init_logger();
|
|
174849
174926
|
|
|
174850
174927
|
// ../plugin/src/features/magic-context/recursive-text-splitter.ts
|
|
@@ -175056,7 +175133,7 @@ function parseCanonicalLineRange(line) {
|
|
|
175056
175133
|
return { start, end };
|
|
175057
175134
|
}
|
|
175058
175135
|
function hashChunkText(text) {
|
|
175059
|
-
return
|
|
175136
|
+
return createHash8("sha256").update(text).digest("hex");
|
|
175060
175137
|
}
|
|
175061
175138
|
function vectorBlob2(vector) {
|
|
175062
175139
|
return new Uint8Array(vector.buffer, vector.byteOffset, vector.byteLength);
|
|
@@ -175449,7 +175526,7 @@ function cosineSimilarity(a, b) {
|
|
|
175449
175526
|
}
|
|
175450
175527
|
|
|
175451
175528
|
// ../plugin/src/features/magic-context/memory/embedding-synapse.ts
|
|
175452
|
-
import { createHash as
|
|
175529
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
175453
175530
|
|
|
175454
175531
|
// ../../node_modules/.bun/@cortexkit+subc-client@0.4.1/node_modules/@cortexkit/subc-client/dist/client.js
|
|
175455
175532
|
import { promises as fs4 } from "node:fs";
|
|
@@ -177663,7 +177740,7 @@ function wait(ms) {
|
|
|
177663
177740
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
177664
177741
|
}
|
|
177665
177742
|
function sha256(value) {
|
|
177666
|
-
return
|
|
177743
|
+
return createHash9("sha256").update(value).digest("hex");
|
|
177667
177744
|
}
|
|
177668
177745
|
function stableJson(value) {
|
|
177669
177746
|
if (Array.isArray(value))
|
|
@@ -178069,13 +178146,13 @@ class SynapseEmbeddingProvider {
|
|
|
178069
178146
|
}
|
|
178070
178147
|
|
|
178071
178148
|
// ../plugin/src/features/magic-context/memory/normalize-hash.ts
|
|
178072
|
-
import { createHash as
|
|
178149
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
178073
178150
|
function normalizeMemoryContent(content) {
|
|
178074
178151
|
return content.toLowerCase().replace(/\s+/g, " ").trim();
|
|
178075
178152
|
}
|
|
178076
178153
|
function computeNormalizedHash(content) {
|
|
178077
178154
|
const normalized = normalizeMemoryContent(content);
|
|
178078
|
-
return
|
|
178155
|
+
return createHash10("md5").update(normalized).digest("hex");
|
|
178079
178156
|
}
|
|
178080
178157
|
|
|
178081
178158
|
// ../plugin/src/features/magic-context/memory/embedding-identity.ts
|
|
@@ -178884,7 +178961,7 @@ function getMemoryEmbedCoverage(db, projectPath, modelId) {
|
|
|
178884
178961
|
}
|
|
178885
178962
|
|
|
178886
178963
|
// ../plugin/src/features/magic-context/project-embedding-registry.ts
|
|
178887
|
-
import { createHash as
|
|
178964
|
+
import { createHash as createHash11, randomUUID as randomUUID2 } from "node:crypto";
|
|
178888
178965
|
init_logger();
|
|
178889
178966
|
|
|
178890
178967
|
// ../plugin/src/features/magic-context/git-commits/storage-git-commit-embeddings.ts
|
|
@@ -179416,10 +179493,10 @@ function stableStringify2(value) {
|
|
|
179416
179493
|
return JSON.stringify(value);
|
|
179417
179494
|
}
|
|
179418
179495
|
function sha256Prefix(value, length = 16) {
|
|
179419
|
-
return
|
|
179496
|
+
return createHash11("sha256").update(value).digest("hex").slice(0, length);
|
|
179420
179497
|
}
|
|
179421
179498
|
function contentSha256(value) {
|
|
179422
|
-
return
|
|
179499
|
+
return createHash11("sha256").update(value).digest("hex");
|
|
179423
179500
|
}
|
|
179424
179501
|
function getRuntimeFingerprint(config2) {
|
|
179425
179502
|
if (config2.provider === "off") {
|
|
@@ -183386,7 +183463,7 @@ function throwIfAborted2(signal) {
|
|
|
183386
183463
|
}
|
|
183387
183464
|
|
|
183388
183465
|
// ../plugin/src/features/magic-context/smart-notes/compiler.ts
|
|
183389
|
-
import { createHash as
|
|
183466
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
183390
183467
|
init_logger();
|
|
183391
183468
|
|
|
183392
183469
|
// ../plugin/src/features/magic-context/smart-notes/compiler-prompt.ts
|
|
@@ -183820,7 +183897,7 @@ function manifestAdvisoryWarnings(code, manifest) {
|
|
|
183820
183897
|
return warnings;
|
|
183821
183898
|
}
|
|
183822
183899
|
function hashCheck(surfaceCondition, compiledCheck, manifest, checkCron) {
|
|
183823
|
-
return
|
|
183900
|
+
return createHash12("sha256").update(surfaceCondition ?? "").update("\x00").update(compiledCheck).update("\x00").update(JSON.stringify(manifest)).update("\x00").update(checkCron).digest("hex");
|
|
183824
183901
|
}
|
|
183825
183902
|
function extractJsonObject(output) {
|
|
183826
183903
|
const fenced = output.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
@@ -186632,7 +186709,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
186632
186709
|
}
|
|
186633
186710
|
function computeRetrospectiveWindowKey(flagged) {
|
|
186634
186711
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
186635
|
-
return
|
|
186712
|
+
return createHash13("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
186636
186713
|
}
|
|
186637
186714
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
186638
186715
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -187959,7 +188036,7 @@ async function sweepGitCommits(args) {
|
|
|
187959
188036
|
import { statSync as statSync7 } from "node:fs";
|
|
187960
188037
|
|
|
187961
188038
|
// ../plugin/src/plugin/embedding-bootstrap-helpers.ts
|
|
187962
|
-
import { createHash as
|
|
188039
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
187963
188040
|
init_logger();
|
|
187964
188041
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
187965
188042
|
"embedding.api_key",
|
|
@@ -188006,7 +188083,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
188006
188083
|
];
|
|
188007
188084
|
var loggedFailureSignatures = new Map;
|
|
188008
188085
|
function sha256Prefix2(value, length = 16) {
|
|
188009
|
-
return
|
|
188086
|
+
return createHash14("sha256").update(value).digest("hex").slice(0, length);
|
|
188010
188087
|
}
|
|
188011
188088
|
function warningLooksEmbeddingRelated(message) {
|
|
188012
188089
|
const lower = message.toLowerCase();
|
|
@@ -189594,7 +189671,11 @@ function createPiDreamerClient(opts) {
|
|
|
189594
189671
|
try {
|
|
189595
189672
|
const result = await runPromise;
|
|
189596
189673
|
if (!result.ok) {
|
|
189597
|
-
|
|
189674
|
+
const error51 = new Error(`Pi dreamer subagent failed (${result.reason}): ${result.error}`);
|
|
189675
|
+
if (result.transient) {
|
|
189676
|
+
error51.transient = true;
|
|
189677
|
+
}
|
|
189678
|
+
throw error51;
|
|
189598
189679
|
}
|
|
189599
189680
|
dreamSession.messages = [
|
|
189600
189681
|
makeMessage("user", [{ type: "text", text: userMessage }]),
|
|
@@ -194190,7 +194271,7 @@ function containsProbeVerbatim(text, probes) {
|
|
|
194190
194271
|
}
|
|
194191
194272
|
|
|
194192
194273
|
// ../plugin/src/features/magic-context/search-measurement.ts
|
|
194193
|
-
import { createHash as
|
|
194274
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
194194
194275
|
function resultId(result) {
|
|
194195
194276
|
switch (result.source) {
|
|
194196
194277
|
case "memory":
|
|
@@ -194273,7 +194354,7 @@ async function recordShadowMeasurement(args) {
|
|
|
194273
194354
|
});
|
|
194274
194355
|
}
|
|
194275
194356
|
function sha2562(value) {
|
|
194276
|
-
return
|
|
194357
|
+
return createHash15("sha256").update(value).digest("hex");
|
|
194277
194358
|
}
|
|
194278
194359
|
|
|
194279
194360
|
// ../plugin/src/features/magic-context/search.ts
|
|
@@ -201761,7 +201842,7 @@ function stripPiProcessedImages(args) {
|
|
|
201761
201842
|
}
|
|
201762
201843
|
|
|
201763
201844
|
// src/system-prompt.ts
|
|
201764
|
-
import { createHash as
|
|
201845
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
201765
201846
|
|
|
201766
201847
|
// ../plugin/src/agents/magic-context-prompt.ts
|
|
201767
201848
|
var LONG_TERM_PARTNER_FRAME = `### You are the user's long-term partner on this project — not a one-off hire
|
|
@@ -201914,7 +201995,7 @@ function processSystemPromptForCache(args) {
|
|
|
201914
201995
|
sessionLog(sessionId, `system prompt date frozen: real=${liveDate}, using=${stickyDate} (cache-stable pass)`);
|
|
201915
201996
|
}
|
|
201916
201997
|
}
|
|
201917
|
-
const currentHash =
|
|
201998
|
+
const currentHash = createHash16("md5").update(frozenPrompt).digest("hex");
|
|
201918
201999
|
const hashChanged = !isFirstHash && currentHash !== previousHash;
|
|
201919
202000
|
if (hashChanged) {
|
|
201920
202001
|
sessionLog(sessionId, `system prompt hash changed: ${previousHash} → ${currentHash} (len=${frozenPrompt.length})`);
|
|
@@ -205062,6 +205143,19 @@ init_logger();
|
|
|
205062
205143
|
init_data_path();
|
|
205063
205144
|
init_logger();
|
|
205064
205145
|
var MARKER_SUMMARY_TEXT = "[Compacted by magic-context — session history is managed by the plugin]";
|
|
205146
|
+
function dropMarkerSummaryTag(db, sessionId, summaryMessageId) {
|
|
205147
|
+
const tagNumber = getTagNumberByMessageId(db, sessionId, `${summaryMessageId}:p0`);
|
|
205148
|
+
if (tagNumber !== null)
|
|
205149
|
+
updateTagStatus(db, sessionId, tagNumber, "dropped");
|
|
205150
|
+
}
|
|
205151
|
+
function persistMarkerStateAndDropReplacedTag(db, sessionId, state, replacedSummaryMessageId) {
|
|
205152
|
+
db.transaction(() => {
|
|
205153
|
+
setPersistedCompactionMarkerState(db, sessionId, state);
|
|
205154
|
+
if (replacedSummaryMessageId !== null) {
|
|
205155
|
+
dropMarkerSummaryTag(db, sessionId, replacedSummaryMessageId);
|
|
205156
|
+
}
|
|
205157
|
+
})();
|
|
205158
|
+
}
|
|
205065
205159
|
function getCompartmentEndMessageIdForOrdinal(db, sessionId, endOrdinal) {
|
|
205066
205160
|
const row = db.prepare(`SELECT end_message_id
|
|
205067
205161
|
FROM compartments
|
|
@@ -205102,6 +205196,7 @@ function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEn
|
|
|
205102
205196
|
return false;
|
|
205103
205197
|
}
|
|
205104
205198
|
const existing = getPersistedCompactionMarkerState(db, sessionId);
|
|
205199
|
+
const removedSummaryMessageId = existing?.summaryMessageId ?? null;
|
|
205105
205200
|
if (existing) {
|
|
205106
205201
|
if (existingMarkerAlreadyCoversTarget(sessionId, existing, lastCompartmentEnd, targetEndMessageId)) {
|
|
205107
205202
|
return true;
|
|
@@ -205118,7 +205213,7 @@ function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEn
|
|
|
205118
205213
|
sessionLog(sessionId, `compaction-marker: failed to remove old boundary at ordinal ${existing.boundaryOrdinal}; preserving persisted state for retry (not injecting new marker this pass)`);
|
|
205119
205214
|
return false;
|
|
205120
205215
|
}
|
|
205121
|
-
|
|
205216
|
+
persistMarkerStateAndDropReplacedTag(db, sessionId, null, removedSummaryMessageId);
|
|
205122
205217
|
sessionLog(sessionId, `compaction-marker: removed old boundary at ordinal ${existing.boundaryOrdinal}, moving to ${lastCompartmentEnd}`);
|
|
205123
205218
|
}
|
|
205124
205219
|
const result = injectCompactionMarker({
|
|
@@ -205130,11 +205225,11 @@ function updateCompactionMarkerAfterPublication(db, sessionId, lastCompartmentEn
|
|
|
205130
205225
|
resolvedBoundary: boundary
|
|
205131
205226
|
});
|
|
205132
205227
|
if (result) {
|
|
205133
|
-
|
|
205228
|
+
persistMarkerStateAndDropReplacedTag(db, sessionId, {
|
|
205134
205229
|
...result,
|
|
205135
205230
|
boundaryOrdinal: lastCompartmentEnd,
|
|
205136
205231
|
targetEndMessageId
|
|
205137
|
-
});
|
|
205232
|
+
}, removedSummaryMessageId);
|
|
205138
205233
|
sessionLog(sessionId, `compaction-marker: injected at ordinal ${lastCompartmentEnd}, boundary user msg ${result.boundaryMessageId}`);
|
|
205139
205234
|
return true;
|
|
205140
205235
|
}
|
|
@@ -207461,7 +207556,13 @@ import {
|
|
|
207461
207556
|
|
|
207462
207557
|
// ../plugin/src/hooks/magic-context/m0-token-breakdown.ts
|
|
207463
207558
|
function computeM0BlockTokens(db, sessionId, args) {
|
|
207464
|
-
const {
|
|
207559
|
+
const {
|
|
207560
|
+
m0Text,
|
|
207561
|
+
projectIdentity,
|
|
207562
|
+
injectionBudgetTokens,
|
|
207563
|
+
memoryBlockCount,
|
|
207564
|
+
compartmentTokensOverride
|
|
207565
|
+
} = args;
|
|
207465
207566
|
const docsBlock = extractM0Block(m0Text, "project-docs");
|
|
207466
207567
|
const docsTokens = docsBlock ? estimateTokens(docsBlock) : 0;
|
|
207467
207568
|
const profileBlock = extractM0Block(m0Text, "user-profile");
|
|
@@ -207475,7 +207576,9 @@ function computeM0BlockTokens(db, sessionId, args) {
|
|
|
207475
207576
|
}
|
|
207476
207577
|
let compartmentTokens = 0;
|
|
207477
207578
|
const historyBlock = extractM0Block(m0Text, "session-history");
|
|
207478
|
-
if (
|
|
207579
|
+
if (typeof compartmentTokensOverride === "number" && Number.isFinite(compartmentTokensOverride) && compartmentTokensOverride >= 0) {
|
|
207580
|
+
compartmentTokens = compartmentTokensOverride;
|
|
207581
|
+
} else if (historyBlock) {
|
|
207479
207582
|
compartmentTokens = estimateTokens(historyBlock);
|
|
207480
207583
|
} else {
|
|
207481
207584
|
try {
|
|
@@ -207512,7 +207615,7 @@ function formatThresholdPercent(value) {
|
|
|
207512
207615
|
// package.json
|
|
207513
207616
|
var package_default = {
|
|
207514
207617
|
name: "@cortexkit/pi-magic-context",
|
|
207515
|
-
version: "0.32.
|
|
207618
|
+
version: "0.32.4",
|
|
207516
207619
|
type: "module",
|
|
207517
207620
|
description: "Pi coding agent extension for Magic Context — cross-session memory and context management",
|
|
207518
207621
|
main: "dist/index.js",
|
package/package.json
CHANGED