@cortexkit/pi-magic-context 0.49.46 → 0.49.47
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-ewf0sd7d.js → index-j9bhd718.js} +106 -6
- package/dist/{index-6bedye3n.js → index-nev91y6k.js} +1 -1
- package/dist/{index-ea37qn4x.js → index-nvh6d3bz.js} +66 -14
- package/dist/{index-nvgq29cw.js → index-tcm1gqcb.js} +4 -4
- package/dist/index.js +319 -21
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{render-s6k2xqhj.js → render-zcwm5nz3.js} +2 -2
- package/dist/{search-archive-qza20zkm.js → search-archive-9svkd0f6.js} +1 -1
- package/dist/{store-v60q7dje.js → store-0hhs1db3.js} +1 -1
- package/dist/{store-reader-2m80zs5z.js → store-reader-mmfw2h48.js} +1 -1
- package/dist/subagent-entry.js +4 -4
- package/dist/{v2-archive-reader-2v7a879f.js → v2-archive-reader-ksmk6bfw.js} +1 -1
- package/package.json +1 -1
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
renderMessageByOrdinal2,
|
|
71
71
|
renderVerboseRange2,
|
|
72
72
|
renderItemByTag2
|
|
73
|
-
} from "./index-
|
|
73
|
+
} from "./index-nev91y6k.js";
|
|
74
74
|
import {
|
|
75
75
|
getLastIndexedOrdinal
|
|
76
76
|
} from "./index-fzadydec.js";
|
|
@@ -4792,15 +4792,115 @@ function resolveMuralWire(db, projectIdentity, modelKey, enabled, budgetTokens =
|
|
|
4792
4792
|
};
|
|
4793
4793
|
}
|
|
4794
4794
|
|
|
4795
|
-
// ../plugin/src/features/magic-context/
|
|
4795
|
+
// ../plugin/src/features/magic-context/request-tool-definitions.ts
|
|
4796
4796
|
import { createHash as createHash4 } from "node:crypto";
|
|
4797
|
+
var sha = (value) => createHash4("sha256").update(JSON.stringify(value)).digest("hex");
|
|
4798
|
+
var v2SchemaDigests = new Map;
|
|
4799
|
+
function requestToolsFingerprint(tools, referencedNames) {
|
|
4800
|
+
let referenced;
|
|
4801
|
+
const included = [];
|
|
4802
|
+
for (const tool of tools) {
|
|
4803
|
+
if (tool.deferLoading === true) {
|
|
4804
|
+
referenced ??= referencedNames?.() ?? new Set;
|
|
4805
|
+
if (!referenced.has(tool.name))
|
|
4806
|
+
continue;
|
|
4807
|
+
}
|
|
4808
|
+
included.push(tool);
|
|
4809
|
+
}
|
|
4810
|
+
included.sort((left, right) => left.name < right.name ? -1 : left.name > right.name ? 1 : 0);
|
|
4811
|
+
return {
|
|
4812
|
+
names: sha(included.map((tool) => tool.name)),
|
|
4813
|
+
descriptions: sha(included.map((tool) => [tool.name, tool.description])),
|
|
4814
|
+
schemas: sha(included.map((tool) => tool.deferLoading === true ? [tool.name, tool.description, tool.schemaDigest, "defer_loading"] : [tool.name, tool.description, tool.schemaDigest]))
|
|
4815
|
+
};
|
|
4816
|
+
}
|
|
4817
|
+
function classifyRequestToolsChange(previous, current) {
|
|
4818
|
+
if (previous.names !== current.names)
|
|
4819
|
+
return "names";
|
|
4820
|
+
if (previous.descriptions !== current.descriptions)
|
|
4821
|
+
return "descriptions";
|
|
4822
|
+
if (previous.schemas !== current.schemas)
|
|
4823
|
+
return "schemas";
|
|
4824
|
+
return null;
|
|
4825
|
+
}
|
|
4826
|
+
function requestToolSchemaDigest(schema) {
|
|
4827
|
+
const pieces = [];
|
|
4828
|
+
writeCanonicalJson(toJsonValue(schema, ""), [], pieces);
|
|
4829
|
+
return createHash4("sha256").update(pieces.join("")).digest("hex");
|
|
4830
|
+
}
|
|
4831
|
+
function isJsonValue(value) {
|
|
4832
|
+
return value !== undefined && typeof value !== "function" && typeof value !== "symbol";
|
|
4833
|
+
}
|
|
4834
|
+
function toJsonValue(value, key) {
|
|
4835
|
+
if (typeof value !== "object" || value === null)
|
|
4836
|
+
return value;
|
|
4837
|
+
const toJSON = value.toJSON;
|
|
4838
|
+
const resolved = typeof toJSON === "function" ? toJSON.call(value, key) : value;
|
|
4839
|
+
if (resolved instanceof Number)
|
|
4840
|
+
return Number(resolved);
|
|
4841
|
+
if (resolved instanceof String)
|
|
4842
|
+
return String(resolved);
|
|
4843
|
+
if (resolved instanceof Boolean)
|
|
4844
|
+
return resolved.valueOf();
|
|
4845
|
+
return resolved;
|
|
4846
|
+
}
|
|
4847
|
+
function writeCanonicalJson(value, ancestors, out) {
|
|
4848
|
+
if (value === null || typeof value === "boolean" || typeof value === "string") {
|
|
4849
|
+
out.push(JSON.stringify(value));
|
|
4850
|
+
return;
|
|
4851
|
+
}
|
|
4852
|
+
if (typeof value === "number") {
|
|
4853
|
+
out.push(Number.isFinite(value) ? JSON.stringify(value) : "null");
|
|
4854
|
+
return;
|
|
4855
|
+
}
|
|
4856
|
+
if (typeof value === "bigint") {
|
|
4857
|
+
out.push(JSON.stringify(value.toString()));
|
|
4858
|
+
return;
|
|
4859
|
+
}
|
|
4860
|
+
if (typeof value !== "object") {
|
|
4861
|
+
out.push("null");
|
|
4862
|
+
return;
|
|
4863
|
+
}
|
|
4864
|
+
if (ancestors.includes(value)) {
|
|
4865
|
+
out.push('"[Circular]"');
|
|
4866
|
+
return;
|
|
4867
|
+
}
|
|
4868
|
+
ancestors.push(value);
|
|
4869
|
+
if (Array.isArray(value)) {
|
|
4870
|
+
out.push("[");
|
|
4871
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
4872
|
+
if (index > 0)
|
|
4873
|
+
out.push(",");
|
|
4874
|
+
const item = toJsonValue(value[index], String(index));
|
|
4875
|
+
if (isJsonValue(item))
|
|
4876
|
+
writeCanonicalJson(item, ancestors, out);
|
|
4877
|
+
else
|
|
4878
|
+
out.push("null");
|
|
4879
|
+
}
|
|
4880
|
+
out.push("]");
|
|
4881
|
+
} else {
|
|
4882
|
+
const entries = Object.entries(value).map(([key, child]) => [key, toJsonValue(child, key)]).filter(([, child]) => isJsonValue(child)).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0);
|
|
4883
|
+
out.push("{");
|
|
4884
|
+
entries.forEach(([key, child], index) => {
|
|
4885
|
+
if (index > 0)
|
|
4886
|
+
out.push(",");
|
|
4887
|
+
out.push(JSON.stringify(key), ":");
|
|
4888
|
+
writeCanonicalJson(child, ancestors, out);
|
|
4889
|
+
});
|
|
4890
|
+
out.push("}");
|
|
4891
|
+
}
|
|
4892
|
+
ancestors.pop();
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4895
|
+
// ../plugin/src/features/magic-context/compaction-marker.ts
|
|
4896
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
4797
4897
|
import { existsSync as existsSync6, statSync as statSync4 } from "node:fs";
|
|
4798
4898
|
var BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
4799
4899
|
var ID_PREFIX_HEX_LENGTH = 12;
|
|
4800
4900
|
var ID_SUFFIX_LENGTH = 14;
|
|
4801
4901
|
var ID_PREFIX_MASK = (1n << BigInt(ID_PREFIX_HEX_LENGTH * 4)) - 1n;
|
|
4802
4902
|
function deterministicBase62(seed, length) {
|
|
4803
|
-
let value = BigInt(`0x${
|
|
4903
|
+
let value = BigInt(`0x${createHash5("sha256").update(seed).digest("hex")}`);
|
|
4804
4904
|
const chars = Array(length);
|
|
4805
4905
|
for (let index = length - 1;index >= 0; index -= 1) {
|
|
4806
4906
|
chars[index] = BASE62_CHARS[Number(value % 62n)];
|
|
@@ -6446,7 +6546,7 @@ async function wakePlaneStatus() {
|
|
|
6446
6546
|
import { statSync as statSync5 } from "node:fs";
|
|
6447
6547
|
|
|
6448
6548
|
// ../plugin/src/plugin/embedding-bootstrap-helpers.ts
|
|
6449
|
-
import { createHash as
|
|
6549
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
6450
6550
|
var EMBEDDING_AFFECTING_KEYS = new Set([
|
|
6451
6551
|
"embedding.api_key",
|
|
6452
6552
|
"embedding.endpoint",
|
|
@@ -6494,7 +6594,7 @@ var EMBEDDING_WARNING_TERMS = [
|
|
|
6494
6594
|
];
|
|
6495
6595
|
var loggedFailureSignatures = new Map;
|
|
6496
6596
|
function sha256Prefix(value, length = 16) {
|
|
6497
|
-
return
|
|
6597
|
+
return createHash6("sha256").update(value).digest("hex").slice(0, length);
|
|
6498
6598
|
}
|
|
6499
6599
|
function warningLooksEmbeddingRelated(message) {
|
|
6500
6600
|
const lower = message.toLowerCase();
|
|
@@ -10710,4 +10810,4 @@ function registerMagicContextTools(pi, opts) {
|
|
|
10710
10810
|
}
|
|
10711
10811
|
}
|
|
10712
10812
|
|
|
10713
|
-
export { COMPACTION_ENABLED_PATH, isDreamerRunnable, isCompactionEnabled, isCommitRetentionPaused, copyCommitRetentionRecovery, formatConfigParseStatusLine, formatConfigParseNotice, claimConfigParseFailuresOnce, parseJsoncRecovering, detectConfigFile, OPENCODE_OUTPUT_CAP, MIN_PLAUSIBLE_CONTEXT_LIMIT, catalogOutputReserve, deriveWindowGeometry, hasTrustedAbsoluteWall, applyProvenInputFloor, formatWindowDerivationLine, formatWindowSource, isSaneLimit, resolveOutputReserve, getSdkWindowGeometry, getSdkContextLimit, getSdkOutputLimit, getSdkInputLimit, cortexKitUserConfigBasePath, cortexKitProjectConfigBasePath, migrateMagicContextConfigLocations, getProtectedTokensTierOverrides, noteTouchedAt, noteNudgePickIndex, formatNoteNudge, systemPromptFingerprint, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, SYNTH_USER_ID_PREFIX, resolvePiStableId, resolvePiRealStableId, isPiContentFallbackId, isPiIndexFallbackId, piContentFallbackIds, readPiSessionSnapshot, readPiSessionMessages, readPiSessionMessagePage, findRestartModelSeedFromBranch, iterateEntriesToRawMessageRange, iterateAsyncEntriesToRawMessageRange, convertEntriesToRawMessages, convertPiAssistantEntryById, convertEntriesToRawMessagePage, countPiRawMessages, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, getTaskScheduleState, getFailingDreamTasks, getSkippedDreamTasks, getMostRecentTaskRunAt, pruneNonCanonicalTaskRows, deleteTaskScheduleRowsForProject, seedTaskScheduleState, writeTaskScheduleState, isRetrospectiveWindowProcessed, recordRetrospectiveWindowProcessed, curateCategoryForMemoryCategory, peekCurateCategoryScope, beginCurateCategoryRun, curateTaskStateAfterSuccess, MEMORY_MURAL_BLOCK, buildMagicContextSection, resolveMuralWire, updateCompactionMarkerAfterPublication, COMPARTMENT_RENDER_EPOCH, MEMORY_RENDER_FORMAT_EPOCH, encodeCachedM0UpgradeIdentity, decodeCachedM0UpgradeIdentity, withCachedM0MemoryIds, readCachedM0MemoryIds, renderBudgetIdentityChanged, renderedBudgetSnapshot, renderedBudgetShrinkReason, DEFAULT_HISTORY_BUDGET_TOKENS, renderCompartmentAtTier, renderDecayedCompartments, extractM0Block, TEMPORAL_MARKER_PATTERN, TEMPORAL_MARKER_REPLAY_PATTERN, temporalMarkerPrefix, renderUserProfileContent, clearInjectionCache, getVisibleMemoryIds, orderHistorianMemories, renderHistorianMemoryBlock, DEFAULT_MEMORY_BUDGET_TOKENS, DEFAULT_USER_PROFILE_BUDGET_TOKENS, trimMemoriesToBudgetV2, trimWorkspaceMemoriesToBudgetV2, trimUserMemoriesToBudget, renderMemoryBlockV2, stripMemoryMuralBlock, resetPrefixTrimFallbackState, isDirectiveShapedProjectRule, takeCurateSafetyRefusalCount, wakePlaneStatus, loadPiConfig, loadPiConfigDetailed, unregisterPiProjectEmbeddings, ensureProjectRegisteredFromPiDirectory, neutralizeOmpMentions, restoreOmpMentions, resolvePiHarnessDetection, resolvePiHarnessKind, resolvePiOrdinalAlignment, piRawOrdinalOffsetSource, resolvePiOrdinalAlignmentForContext, isPiOrdinalAlignmentUnanchored, clearPiOrdinalAlignmentSession, rememberTodowriteToolCallTodos, parseTodos, setTodoSnapshot, registerTodoOverlay, registerTodoStateLifecycle, syncCtxMemoryToolEnabled, registerMagicContextTools };
|
|
10813
|
+
export { COMPACTION_ENABLED_PATH, isDreamerRunnable, isCompactionEnabled, isCommitRetentionPaused, copyCommitRetentionRecovery, formatConfigParseStatusLine, formatConfigParseNotice, claimConfigParseFailuresOnce, parseJsoncRecovering, detectConfigFile, OPENCODE_OUTPUT_CAP, MIN_PLAUSIBLE_CONTEXT_LIMIT, catalogOutputReserve, deriveWindowGeometry, hasTrustedAbsoluteWall, applyProvenInputFloor, formatWindowDerivationLine, formatWindowSource, isSaneLimit, resolveOutputReserve, getSdkWindowGeometry, getSdkContextLimit, getSdkOutputLimit, getSdkInputLimit, cortexKitUserConfigBasePath, cortexKitProjectConfigBasePath, migrateMagicContextConfigLocations, getProtectedTokensTierOverrides, noteTouchedAt, noteNudgePickIndex, formatNoteNudge, systemPromptFingerprint, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, SYNTH_USER_ID_PREFIX, resolvePiStableId, resolvePiRealStableId, isPiContentFallbackId, isPiIndexFallbackId, piContentFallbackIds, readPiSessionSnapshot, readPiSessionMessages, readPiSessionMessagePage, findRestartModelSeedFromBranch, iterateEntriesToRawMessageRange, iterateAsyncEntriesToRawMessageRange, convertEntriesToRawMessages, convertPiAssistantEntryById, convertEntriesToRawMessagePage, countPiRawMessages, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, getTaskScheduleState, getFailingDreamTasks, getSkippedDreamTasks, getMostRecentTaskRunAt, pruneNonCanonicalTaskRows, deleteTaskScheduleRowsForProject, seedTaskScheduleState, writeTaskScheduleState, isRetrospectiveWindowProcessed, recordRetrospectiveWindowProcessed, curateCategoryForMemoryCategory, peekCurateCategoryScope, beginCurateCategoryRun, curateTaskStateAfterSuccess, MEMORY_MURAL_BLOCK, buildMagicContextSection, resolveMuralWire, requestToolsFingerprint, classifyRequestToolsChange, requestToolSchemaDigest, updateCompactionMarkerAfterPublication, COMPARTMENT_RENDER_EPOCH, MEMORY_RENDER_FORMAT_EPOCH, encodeCachedM0UpgradeIdentity, decodeCachedM0UpgradeIdentity, withCachedM0MemoryIds, readCachedM0MemoryIds, renderBudgetIdentityChanged, renderedBudgetSnapshot, renderedBudgetShrinkReason, DEFAULT_HISTORY_BUDGET_TOKENS, renderCompartmentAtTier, renderDecayedCompartments, extractM0Block, TEMPORAL_MARKER_PATTERN, TEMPORAL_MARKER_REPLAY_PATTERN, temporalMarkerPrefix, renderUserProfileContent, clearInjectionCache, getVisibleMemoryIds, orderHistorianMemories, renderHistorianMemoryBlock, DEFAULT_MEMORY_BUDGET_TOKENS, DEFAULT_USER_PROFILE_BUDGET_TOKENS, trimMemoriesToBudgetV2, trimWorkspaceMemoriesToBudgetV2, trimUserMemoriesToBudget, renderMemoryBlockV2, stripMemoryMuralBlock, resetPrefixTrimFallbackState, isDirectiveShapedProjectRule, takeCurateSafetyRefusalCount, wakePlaneStatus, loadPiConfig, loadPiConfigDetailed, unregisterPiProjectEmbeddings, ensureProjectRegisteredFromPiDirectory, neutralizeOmpMentions, restoreOmpMentions, resolvePiHarnessDetection, resolvePiHarnessKind, resolvePiOrdinalAlignment, piRawOrdinalOffsetSource, resolvePiOrdinalAlignmentForContext, isPiOrdinalAlignmentUnanchored, clearPiOrdinalAlignmentSession, rememberTodowriteToolCallTodos, parseTodos, setTodoSnapshot, registerTodoOverlay, registerTodoStateLifecycle, syncCtxMemoryToolEnabled, registerMagicContextTools };
|
|
@@ -301,6 +301,50 @@ class V2StoreReader2 {
|
|
|
301
301
|
}
|
|
302
302
|
return statement;
|
|
303
303
|
}
|
|
304
|
+
hasPartTable() {
|
|
305
|
+
this.connection.partTable ??= Boolean(this.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'session_part'").get());
|
|
306
|
+
return this.connection.partTable;
|
|
307
|
+
}
|
|
308
|
+
withParts(rows) {
|
|
309
|
+
const ids = rows.flatMap((row) => row.type === "assistant" ? [row.id] : []);
|
|
310
|
+
if (ids.length === 0 || !this.hasPartTable())
|
|
311
|
+
return rows;
|
|
312
|
+
const parts = new Map;
|
|
313
|
+
for (let offset = 0;offset < ids.length; offset += 500) {
|
|
314
|
+
const chunk = ids.slice(offset, offset + 500);
|
|
315
|
+
const partRows = this.prepare(`SELECT message_id, ordinal, data FROM session_part
|
|
316
|
+
WHERE message_id IN (${chunk.map(() => "?").join(", ")})
|
|
317
|
+
ORDER BY message_id ASC, ordinal ASC`).all(...chunk);
|
|
318
|
+
for (const part of partRows) {
|
|
319
|
+
let data;
|
|
320
|
+
try {
|
|
321
|
+
data = JSON.parse(part.data);
|
|
322
|
+
} catch {
|
|
323
|
+
throw new Error(`Invalid session_part data for ${part.message_id} at ordinal ${part.ordinal}`);
|
|
324
|
+
}
|
|
325
|
+
const list = parts.get(part.message_id);
|
|
326
|
+
if (list)
|
|
327
|
+
list.push(data);
|
|
328
|
+
else
|
|
329
|
+
parts.set(part.message_id, [data]);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (parts.size === 0)
|
|
333
|
+
return rows;
|
|
334
|
+
return rows.map((row) => {
|
|
335
|
+
const content = parts.get(row.id);
|
|
336
|
+
if (!content)
|
|
337
|
+
return row;
|
|
338
|
+
const inline = row.data.content;
|
|
339
|
+
return {
|
|
340
|
+
...row,
|
|
341
|
+
data: {
|
|
342
|
+
...row.data,
|
|
343
|
+
content: Array.isArray(inline) ? [...content, ...inline] : content
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
}
|
|
304
348
|
close() {
|
|
305
349
|
if (this.closed)
|
|
306
350
|
return;
|
|
@@ -330,9 +374,9 @@ class V2StoreReader2 {
|
|
|
330
374
|
predicates.push("type = ?");
|
|
331
375
|
parameters.push(options.type);
|
|
332
376
|
}
|
|
333
|
-
const rows = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
377
|
+
const rows = this.withParts(this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
334
378
|
WHERE ${predicates.join(" AND ")}
|
|
335
|
-
ORDER BY seq ASC LIMIT ?`).all(...parameters, limit).map(decode);
|
|
379
|
+
ORDER BY seq ASC LIMIT ?`).all(...parameters, limit).map(decode));
|
|
336
380
|
return { rows, cursor: rows.at(-1)?.seq };
|
|
337
381
|
});
|
|
338
382
|
}
|
|
@@ -350,14 +394,14 @@ class V2StoreReader2 {
|
|
|
350
394
|
if (after) {
|
|
351
395
|
const anchor = this.prepare("SELECT seq FROM session_message WHERE session_id = ? AND id = ?").get(sessionID, after.id);
|
|
352
396
|
if (anchor) {
|
|
353
|
-
return this.prepare(`SELECT id, session_id, type, seq, time_created, data
|
|
397
|
+
return this.withParts(this.prepare(`SELECT id, session_id, type, seq, time_created, data
|
|
354
398
|
FROM session_message WHERE session_id = ? AND seq > ?
|
|
355
|
-
AND type IN (${RAW_MESSAGE_TYPE_PARAMETERS}) ORDER BY seq ASC LIMIT ?`).all(sessionID, anchor.seq, ...RAW_MESSAGE_TYPES2, pageSize).map(decode);
|
|
399
|
+
AND type IN (${RAW_MESSAGE_TYPE_PARAMETERS}) ORDER BY seq ASC LIMIT ?`).all(sessionID, anchor.seq, ...RAW_MESSAGE_TYPES2, pageSize).map(decode));
|
|
356
400
|
}
|
|
357
401
|
}
|
|
358
402
|
const maximumSeq = Number.MAX_SAFE_INTEGER;
|
|
359
403
|
const rows = this.prepare(V2_MESSAGE_PAGE_SQL).all(afterOrdinal, sessionID, ...RAW_MESSAGE_TYPES2, Math.max(0, afterOrdinal - 1), sessionID, sessionID, ...RAW_MESSAGE_TYPES2, finalWatermark - 1, maximumSeq, sessionID, ...RAW_MESSAGE_TYPES2, pageSize);
|
|
360
|
-
return rows.map(decode);
|
|
404
|
+
return this.withParts(rows.map(decode));
|
|
361
405
|
});
|
|
362
406
|
}
|
|
363
407
|
messageCount(sessionID) {
|
|
@@ -491,7 +535,7 @@ class V2StoreReader2 {
|
|
|
491
535
|
const rawTypes = RAW_MESSAGE_TYPES2.map(() => "?").join(", ");
|
|
492
536
|
const row = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
493
537
|
WHERE session_id = ? AND id = ? AND type IN (${rawTypes}) LIMIT 1`).get(sessionID, id, ...RAW_MESSAGE_TYPES2);
|
|
494
|
-
return row ? decode(row) : null;
|
|
538
|
+
return row ? this.withParts([decode(row)])[0] ?? null : null;
|
|
495
539
|
});
|
|
496
540
|
}
|
|
497
541
|
messageTimeVersions(sessionID, ids, span) {
|
|
@@ -626,12 +670,20 @@ class V2StoreReader2 {
|
|
|
626
670
|
spanRowStamps(sessionID, after, through) {
|
|
627
671
|
if (!Number.isSafeInteger(after) || !Number.isSafeInteger(through))
|
|
628
672
|
throw new Error("Invalid seq span");
|
|
629
|
-
const
|
|
630
|
-
|
|
631
|
-
|
|
673
|
+
const partJoin = this.hasPartTable() ? `LEFT JOIN (SELECT p.message_id AS message_id, COUNT(*) AS parts,
|
|
674
|
+
MAX(p.time_updated) AS partsUpdated,
|
|
675
|
+
SUM(length(CAST(p.data AS BLOB))) AS partsBytes
|
|
676
|
+
FROM session_message s JOIN session_part p ON p.message_id = s.id
|
|
677
|
+
WHERE s.session_id = ? AND s.seq > ? AND s.seq <= ?
|
|
678
|
+
GROUP BY p.message_id) g ON g.message_id = m.id` : "";
|
|
679
|
+
const rows = this.prepare(`SELECT m.seq AS seq, m.id AS id, m.time_updated AS updated,
|
|
680
|
+
length(CAST(m.data AS BLOB)) AS bytes${partJoin ? ", g.parts AS parts, g.partsUpdated AS partsUpdated, g.partsBytes AS partsBytes" : ""}
|
|
681
|
+
FROM session_message m ${partJoin}
|
|
682
|
+
WHERE m.session_id = ? AND m.seq > ? AND m.seq <= ?
|
|
683
|
+
ORDER BY m.seq ASC`).all(...partJoin ? [sessionID, after, through] : [], sessionID, after, through);
|
|
632
684
|
const stamps = new Map;
|
|
633
685
|
for (const row of rows)
|
|
634
|
-
stamps.set(row.seq, `${row.id}\x00${row.updated ?? ""}\x00${row.bytes ?? ""}`);
|
|
686
|
+
stamps.set(row.seq, `${row.id}\x00${row.updated ?? ""}\x00${row.bytes ?? ""}${row.parts ? `\x00${row.parts}\x00${row.partsUpdated ?? ""}\x00${row.partsBytes ?? ""}` : ""}`);
|
|
635
687
|
return stamps;
|
|
636
688
|
}
|
|
637
689
|
rawRowsThrough(sessionID, throughSeq, limit) {
|
|
@@ -641,9 +693,9 @@ class V2StoreReader2 {
|
|
|
641
693
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e4)
|
|
642
694
|
throw new Error("Invalid page limit");
|
|
643
695
|
const rawTypes = RAW_MESSAGE_TYPES2.map(() => "?").join(", ");
|
|
644
|
-
return this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
696
|
+
return this.withParts(this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
645
697
|
WHERE session_id = ? AND type IN (${rawTypes}) AND seq <= ?
|
|
646
|
-
ORDER BY seq DESC LIMIT ?`).all(sessionID, ...RAW_MESSAGE_TYPES2, throughSeq, limit).map(decode);
|
|
698
|
+
ORDER BY seq DESC LIMIT ?`).all(sessionID, ...RAW_MESSAGE_TYPES2, throughSeq, limit).map(decode));
|
|
647
699
|
});
|
|
648
700
|
}
|
|
649
701
|
instructionRowsThrough(sessionID, throughSeq) {
|
|
@@ -734,7 +786,7 @@ class V2StoreReader2 {
|
|
|
734
786
|
const rows = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
735
787
|
WHERE session_id = ? AND type = 'assistant' AND seq > ?
|
|
736
788
|
ORDER BY seq ASC`).all(sessionID, afterSeq);
|
|
737
|
-
return rows.map(
|
|
789
|
+
return this.withParts(rows.map(decode));
|
|
738
790
|
});
|
|
739
791
|
}
|
|
740
792
|
latestAssistant(sessionID) {
|
|
@@ -742,7 +794,7 @@ class V2StoreReader2 {
|
|
|
742
794
|
const row = this.prepare(`SELECT id, session_id, type, seq, time_created, data FROM session_message
|
|
743
795
|
WHERE session_id = ? AND type = 'assistant'
|
|
744
796
|
ORDER BY seq DESC LIMIT 1`).get(sessionID);
|
|
745
|
-
return row ? decode(row) : undefined;
|
|
797
|
+
return row ? this.withParts([decode(row)])[0] : undefined;
|
|
746
798
|
});
|
|
747
799
|
}
|
|
748
800
|
latestIdle(sessionID) {
|
|
@@ -137,11 +137,11 @@ async function serveV2ArchiveReads2(port, openConnections) {
|
|
|
137
137
|
{ createV2RecoveryAttachments }
|
|
138
138
|
] = await Promise.all([
|
|
139
139
|
import("./sqlite-v89bj0yy.js"),
|
|
140
|
-
import("./store-reader-
|
|
141
|
-
import("./store-
|
|
140
|
+
import("./store-reader-mmfw2h48.js"),
|
|
141
|
+
import("./store-0hhs1db3.js"),
|
|
142
142
|
import("./read-session-chunk-0ecmbegv.js"),
|
|
143
|
-
import("./render-
|
|
144
|
-
import("./search-archive-
|
|
143
|
+
import("./render-zcwm5nz3.js"),
|
|
144
|
+
import("./search-archive-9svkd0f6.js"),
|
|
145
145
|
import("./expand-attachments-8sxeyj26.js")
|
|
146
146
|
]);
|
|
147
147
|
const pool = new V2StoreReaderPool;
|
package/dist/index.js
CHANGED
|
@@ -97,6 +97,9 @@ import {
|
|
|
97
97
|
MEMORY_MURAL_BLOCK,
|
|
98
98
|
buildMagicContextSection,
|
|
99
99
|
resolveMuralWire,
|
|
100
|
+
requestToolsFingerprint,
|
|
101
|
+
classifyRequestToolsChange,
|
|
102
|
+
requestToolSchemaDigest,
|
|
100
103
|
updateCompactionMarkerAfterPublication,
|
|
101
104
|
COMPARTMENT_RENDER_EPOCH,
|
|
102
105
|
MEMORY_RENDER_FORMAT_EPOCH,
|
|
@@ -150,7 +153,7 @@ import {
|
|
|
150
153
|
registerTodoStateLifecycle,
|
|
151
154
|
syncCtxMemoryToolEnabled,
|
|
152
155
|
registerMagicContextTools
|
|
153
|
-
} from "./index-
|
|
156
|
+
} from "./index-j9bhd718.js";
|
|
154
157
|
import"./index-4knyh1kt.js";
|
|
155
158
|
import {
|
|
156
159
|
canonicalModelIdentity,
|
|
@@ -607,7 +610,7 @@ import {
|
|
|
607
610
|
getSourceContents,
|
|
608
611
|
recordSubagentInvocation,
|
|
609
612
|
getLatestHistorianInvocationId
|
|
610
|
-
} from "./index-
|
|
613
|
+
} from "./index-nev91y6k.js";
|
|
611
614
|
import {
|
|
612
615
|
resolveOpenCodeDbPath,
|
|
613
616
|
assertOpenCodeStoreGeneration,
|
|
@@ -626,7 +629,7 @@ import {
|
|
|
626
629
|
import {
|
|
627
630
|
RAW_SUMMARY_TEXT_MAX_CHARS2
|
|
628
631
|
} from "./index-3g9fnq6y.js";
|
|
629
|
-
import"./index-
|
|
632
|
+
import"./index-nvh6d3bz.js";
|
|
630
633
|
import {
|
|
631
634
|
formatSynapseLaneDescriptor
|
|
632
635
|
} from "./index-gwvahsdz.js";
|
|
@@ -828,7 +831,7 @@ import {
|
|
|
828
831
|
} from "./index-jaqdcqwz.js";
|
|
829
832
|
import"./index-cq71g4dk.js";
|
|
830
833
|
import"./index-1cvyaw9a.js";
|
|
831
|
-
import"./index-
|
|
834
|
+
import"./index-tcm1gqcb.js";
|
|
832
835
|
import"./index-v7m1nqwz.js";
|
|
833
836
|
import {
|
|
834
837
|
__toESM
|
|
@@ -3584,7 +3587,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3584
3587
|
// package.json
|
|
3585
3588
|
var package_default = {
|
|
3586
3589
|
name: "@cortexkit/pi-magic-context",
|
|
3587
|
-
version: "0.49.
|
|
3590
|
+
version: "0.49.47",
|
|
3588
3591
|
type: "module",
|
|
3589
3592
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3590
3593
|
main: "dist/index.js",
|
|
@@ -25344,7 +25347,7 @@ function hasReclaimRide(signals) {
|
|
|
25344
25347
|
return signals.hardFold || signals.force || signals.explicitFlush || signals.publishedHistory || signals.subagentExecute === true || signals.executeReclaim === true || signals.servedShapeRepair === true;
|
|
25345
25348
|
}
|
|
25346
25349
|
function prefixMutationPermitted(gate) {
|
|
25347
|
-
return !gate.signedThinkingHold || gate.firstRender || gate.emergency;
|
|
25350
|
+
return !gate.signedThinkingHold || gate.firstRender || gate.hostCheckpointHead === true || gate.emergency;
|
|
25348
25351
|
}
|
|
25349
25352
|
function reclaimRidePermitted(signals, gate) {
|
|
25350
25353
|
return prefixMutationPermitted(gate) && hasReclaimRide(signals);
|
|
@@ -27387,6 +27390,89 @@ function recoveryRefusalNotice(historyRemains) {
|
|
|
27387
27390
|
return historyRemains ? RECOVERY_REFUSAL_NOTICE : RECOVERY_NO_HISTORY_REFUSAL_NOTICE;
|
|
27388
27391
|
}
|
|
27389
27392
|
|
|
27393
|
+
// ../plugin/src/hooks/magic-context/request-tools-release.ts
|
|
27394
|
+
var NAMESPACE3 = "requestToolsRelease";
|
|
27395
|
+
var MAX_MODEL_RECORDS = 8;
|
|
27396
|
+
function parseEntry(value) {
|
|
27397
|
+
if (typeof value !== "object" || value === null)
|
|
27398
|
+
return null;
|
|
27399
|
+
const record = value;
|
|
27400
|
+
if (typeof record.modelKey !== "string" || typeof record.names !== "string" || typeof record.descriptions !== "string" || typeof record.schemas !== "string")
|
|
27401
|
+
return null;
|
|
27402
|
+
return {
|
|
27403
|
+
modelKey: record.modelKey,
|
|
27404
|
+
names: record.names,
|
|
27405
|
+
descriptions: record.descriptions,
|
|
27406
|
+
schemas: record.schemas
|
|
27407
|
+
};
|
|
27408
|
+
}
|
|
27409
|
+
function parseStored(value) {
|
|
27410
|
+
const models = value?.models;
|
|
27411
|
+
if (!Array.isArray(models))
|
|
27412
|
+
return [];
|
|
27413
|
+
const entries = [];
|
|
27414
|
+
for (const item of models) {
|
|
27415
|
+
const entry = parseEntry(item);
|
|
27416
|
+
if (entry)
|
|
27417
|
+
entries.push(entry);
|
|
27418
|
+
}
|
|
27419
|
+
return entries;
|
|
27420
|
+
}
|
|
27421
|
+
function sameEntry(left, right) {
|
|
27422
|
+
return left !== undefined && left.modelKey === right.modelKey && left.names === right.names && left.descriptions === right.descriptions && left.schemas === right.schemas;
|
|
27423
|
+
}
|
|
27424
|
+
function isLatest(entries, current) {
|
|
27425
|
+
return sameEntry(entries.at(-1), current);
|
|
27426
|
+
}
|
|
27427
|
+
function withLatest(entries, current) {
|
|
27428
|
+
const next = entries.filter((entry) => entry.modelKey !== current.modelKey);
|
|
27429
|
+
next.push(current);
|
|
27430
|
+
return next.slice(-MAX_MODEL_RECORDS);
|
|
27431
|
+
}
|
|
27432
|
+
function evaluateRequestToolsRelease(args) {
|
|
27433
|
+
const current = { modelKey: args.modelKey, ...args.fingerprint };
|
|
27434
|
+
let entries = [];
|
|
27435
|
+
let readable = true;
|
|
27436
|
+
try {
|
|
27437
|
+
entries = parseStored(readReplayEnvelope(args.db, args.sessionId, "read")[NAMESPACE3]);
|
|
27438
|
+
} catch (error) {
|
|
27439
|
+
readable = false;
|
|
27440
|
+
sessionLog2(args.sessionId, "request tools record unreadable:", error);
|
|
27441
|
+
}
|
|
27442
|
+
const stored = entries.find((entry) => entry.modelKey === current.modelKey);
|
|
27443
|
+
const change = stored ? classifyRequestToolsChange(stored, current) : null;
|
|
27444
|
+
if (change !== null) {
|
|
27445
|
+
sessionLog2(args.sessionId, `request tools changed (kind=${change === "schemas" ? "schema-only" : change}, model=${current.modelKey}, schemas ${stored?.schemas.slice(0, 12)}→${current.schemas.slice(0, 12)}): releasing signed thinking`);
|
|
27446
|
+
} else if (readable && !stored) {
|
|
27447
|
+
sessionLog2(args.sessionId, `request tools fingerprint adopted for model=${current.modelKey}${entries.length > 0 ? ` (records kept for ${entries.map((entry) => entry.modelKey).join(",")})` : ""}`);
|
|
27448
|
+
}
|
|
27449
|
+
return {
|
|
27450
|
+
change,
|
|
27451
|
+
commit: () => {
|
|
27452
|
+
if (!readable || isLatest(entries, current))
|
|
27453
|
+
return;
|
|
27454
|
+
try {
|
|
27455
|
+
let next = entries;
|
|
27456
|
+
const written = updateReplayDocument(args.db, args.sessionId, (doc) => {
|
|
27457
|
+
const latest = parseStored(doc[NAMESPACE3]);
|
|
27458
|
+
if (isLatest(latest, current))
|
|
27459
|
+
return false;
|
|
27460
|
+
next = withLatest(latest, current);
|
|
27461
|
+
doc.version = 2;
|
|
27462
|
+
doc[NAMESPACE3] = { models: next };
|
|
27463
|
+
return true;
|
|
27464
|
+
});
|
|
27465
|
+
if (written)
|
|
27466
|
+
entries = next;
|
|
27467
|
+
else
|
|
27468
|
+
sessionLog2(args.sessionId, "request tools record not written");
|
|
27469
|
+
} catch (error) {
|
|
27470
|
+
sessionLog2(args.sessionId, "request tools record write failed:", error);
|
|
27471
|
+
}
|
|
27472
|
+
}
|
|
27473
|
+
};
|
|
27474
|
+
}
|
|
27475
|
+
|
|
27390
27476
|
// ../plugin/src/hooks/magic-context/signed-thinking-hold.ts
|
|
27391
27477
|
var HEAVY_REASONING_TOKENS = 1500;
|
|
27392
27478
|
var HEAVY_REASONING_WINDOW_STEPS = 15;
|
|
@@ -42283,6 +42369,167 @@ function resolvePiProvenInputFloor(args) {
|
|
|
42283
42369
|
return observed;
|
|
42284
42370
|
}
|
|
42285
42371
|
|
|
42372
|
+
// src/pi-request-tools.ts
|
|
42373
|
+
var schemaDigests = {
|
|
42374
|
+
omp: new WeakMap,
|
|
42375
|
+
anthropic: new WeakMap,
|
|
42376
|
+
"anthropic-strict": new WeakMap,
|
|
42377
|
+
raw: new WeakMap
|
|
42378
|
+
};
|
|
42379
|
+
function anthropicWireSchema(parameters, strict) {
|
|
42380
|
+
const schema = typeof parameters === "object" && parameters !== null ? parameters : {};
|
|
42381
|
+
const legacy = {
|
|
42382
|
+
type: "object",
|
|
42383
|
+
properties: schema.properties ?? {},
|
|
42384
|
+
required: schema.required ?? []
|
|
42385
|
+
};
|
|
42386
|
+
return strict ? { ...schema, ...legacy } : legacy;
|
|
42387
|
+
}
|
|
42388
|
+
function schemaDigest(tool, mode, wireSchema) {
|
|
42389
|
+
const key = tool.parameters;
|
|
42390
|
+
const cacheable = typeof key === "object" && key !== null || typeof key === "function";
|
|
42391
|
+
const cache = schemaDigests[mode];
|
|
42392
|
+
if (cacheable) {
|
|
42393
|
+
const cached = cache.get(key);
|
|
42394
|
+
if (cached !== undefined)
|
|
42395
|
+
return cached;
|
|
42396
|
+
}
|
|
42397
|
+
const digest = requestToolSchemaDigest(mode === "omp" && wireSchema ? wireSchema(tool) : mode === "anthropic" || mode === "anthropic-strict" ? anthropicWireSchema(tool.parameters, mode === "anthropic-strict") : tool.parameters);
|
|
42398
|
+
if (cacheable)
|
|
42399
|
+
cache.set(key, digest);
|
|
42400
|
+
return digest;
|
|
42401
|
+
}
|
|
42402
|
+
var CLAUDE_CODE_TOOL_NAMES = new Map([
|
|
42403
|
+
"Read",
|
|
42404
|
+
"Write",
|
|
42405
|
+
"Edit",
|
|
42406
|
+
"Bash",
|
|
42407
|
+
"Grep",
|
|
42408
|
+
"Glob",
|
|
42409
|
+
"AskUserQuestion",
|
|
42410
|
+
"EnterPlanMode",
|
|
42411
|
+
"ExitPlanMode",
|
|
42412
|
+
"KillShell",
|
|
42413
|
+
"NotebookEdit",
|
|
42414
|
+
"Skill",
|
|
42415
|
+
"Task",
|
|
42416
|
+
"TaskOutput",
|
|
42417
|
+
"TodoWrite",
|
|
42418
|
+
"WebFetch",
|
|
42419
|
+
"WebSearch"
|
|
42420
|
+
].map((name) => [name.toLowerCase(), name]));
|
|
42421
|
+
var identityName = (name) => name;
|
|
42422
|
+
var claudeCodeName = (name) => CLAUDE_CODE_TOOL_NAMES.get(name.toLowerCase()) ?? name;
|
|
42423
|
+
function compatFlag(model, flag) {
|
|
42424
|
+
const value = model?.compat?.[flag];
|
|
42425
|
+
return typeof value === "boolean" ? value : undefined;
|
|
42426
|
+
}
|
|
42427
|
+
function supportsToolReferences(model) {
|
|
42428
|
+
const declared = compatFlag(model, "supportsToolReferences");
|
|
42429
|
+
if (declared !== undefined)
|
|
42430
|
+
return declared;
|
|
42431
|
+
if (model.provider !== "anthropic" || typeof model.id !== "string")
|
|
42432
|
+
return false;
|
|
42433
|
+
if (model.id.includes("haiku"))
|
|
42434
|
+
return false;
|
|
42435
|
+
const version = model.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
|
|
42436
|
+
if (!version)
|
|
42437
|
+
return false;
|
|
42438
|
+
const major = Number(version[1]);
|
|
42439
|
+
const minor = version[2] && version[2].length < 8 ? Number(version[2]) : 0;
|
|
42440
|
+
return major > 4 || major === 4 && minor >= 5;
|
|
42441
|
+
}
|
|
42442
|
+
function deferredAndReferencedNames(messages, normalizeName) {
|
|
42443
|
+
const deferred = new Set;
|
|
42444
|
+
const referenced = new Set;
|
|
42445
|
+
for (const message of messages) {
|
|
42446
|
+
const { role, content, addedToolNames } = message ?? {};
|
|
42447
|
+
if (role === "assistant" && Array.isArray(content)) {
|
|
42448
|
+
for (const block of content) {
|
|
42449
|
+
const { type, name } = block ?? {};
|
|
42450
|
+
if (type === "toolCall" && typeof name === "string")
|
|
42451
|
+
referenced.add(normalizeName(name));
|
|
42452
|
+
}
|
|
42453
|
+
} else if (role === "toolResult" && Array.isArray(addedToolNames)) {
|
|
42454
|
+
for (const name of addedToolNames) {
|
|
42455
|
+
if (typeof name !== "string")
|
|
42456
|
+
continue;
|
|
42457
|
+
const normalized = normalizeName(name);
|
|
42458
|
+
if (!referenced.has(normalized))
|
|
42459
|
+
deferred.add(normalized);
|
|
42460
|
+
}
|
|
42461
|
+
}
|
|
42462
|
+
}
|
|
42463
|
+
for (const name of deferred)
|
|
42464
|
+
referenced.add(name);
|
|
42465
|
+
return { deferred, referenced };
|
|
42466
|
+
}
|
|
42467
|
+
function calledToolNames(messages) {
|
|
42468
|
+
const names = new Set;
|
|
42469
|
+
for (const message of messages) {
|
|
42470
|
+
const content = message?.content;
|
|
42471
|
+
if (!Array.isArray(content))
|
|
42472
|
+
continue;
|
|
42473
|
+
for (const part of content) {
|
|
42474
|
+
const { type, name } = part ?? {};
|
|
42475
|
+
if (typeof type === "string" && type.toLowerCase().includes("tool") && typeof name === "string")
|
|
42476
|
+
names.add(name);
|
|
42477
|
+
}
|
|
42478
|
+
}
|
|
42479
|
+
return names;
|
|
42480
|
+
}
|
|
42481
|
+
function readPiRequestToolsFingerprint(pi, wireSchema, messages, route = {}) {
|
|
42482
|
+
try {
|
|
42483
|
+
if (typeof pi.getAllTools !== "function" || typeof pi.getActiveTools !== "function")
|
|
42484
|
+
return;
|
|
42485
|
+
const all = pi.getAllTools();
|
|
42486
|
+
const active = pi.getActiveTools();
|
|
42487
|
+
if (!Array.isArray(all) || !Array.isArray(active))
|
|
42488
|
+
return;
|
|
42489
|
+
const registered = new Map;
|
|
42490
|
+
for (const tool of all) {
|
|
42491
|
+
if (!tool || typeof tool !== "object")
|
|
42492
|
+
return;
|
|
42493
|
+
const { name } = tool;
|
|
42494
|
+
if (typeof name !== "string")
|
|
42495
|
+
return;
|
|
42496
|
+
registered.set(name, tool);
|
|
42497
|
+
}
|
|
42498
|
+
const model = route.model;
|
|
42499
|
+
const anthropicWriter = route.host === "pi" && wireSchema === undefined && model?.api === "anthropic-messages";
|
|
42500
|
+
const mode = wireSchema ? "omp" : anthropicWriter ? compatFlag(model, "supportsStrictTools") === true ? "anthropic-strict" : "anthropic" : "raw";
|
|
42501
|
+
const normalizeName = anthropicWriter && route.oauth === true ? claudeCodeName : identityName;
|
|
42502
|
+
const sent = new Map;
|
|
42503
|
+
for (const name of active) {
|
|
42504
|
+
if (typeof name !== "string")
|
|
42505
|
+
return;
|
|
42506
|
+
const tool = registered.get(name);
|
|
42507
|
+
if (!tool)
|
|
42508
|
+
continue;
|
|
42509
|
+
sent.set(normalizeName(name), tool);
|
|
42510
|
+
}
|
|
42511
|
+
const split = anthropicWriter && model && supportsToolReferences(model) ? deferredAndReferencedNames(messages, normalizeName) : undefined;
|
|
42512
|
+
const anyImmediate = [...sent.keys()].some((name) => !split?.deferred.has(name));
|
|
42513
|
+
const tools = [];
|
|
42514
|
+
for (const [name, tool] of sent) {
|
|
42515
|
+
const description = typeof tool.description === "string" ? tool.description : "";
|
|
42516
|
+
tools.push({
|
|
42517
|
+
name,
|
|
42518
|
+
description,
|
|
42519
|
+
schemaDigest: schemaDigest({
|
|
42520
|
+
name: tool.name,
|
|
42521
|
+
description,
|
|
42522
|
+
parameters: tool.parameters
|
|
42523
|
+
}, mode, wireSchema),
|
|
42524
|
+
deferLoading: split ? anyImmediate && split.deferred.has(name) : tool.defer_loading === true || tool.deferLoading === true
|
|
42525
|
+
});
|
|
42526
|
+
}
|
|
42527
|
+
return requestToolsFingerprint(tools, () => split?.referenced ?? calledToolNames(messages));
|
|
42528
|
+
} catch {
|
|
42529
|
+
return;
|
|
42530
|
+
}
|
|
42531
|
+
}
|
|
42532
|
+
|
|
42286
42533
|
// src/pi-tag-identity-repair.ts
|
|
42287
42534
|
var PI_TAG_IDENTITY_REPAIR_REASON = "tag_identity_repair";
|
|
42288
42535
|
var unreadableLedgerLogged = new Set;
|
|
@@ -42779,13 +43026,26 @@ function resolvePiBindingStripOrder(args) {
|
|
|
42779
43026
|
if (hasThinkingPart(args.messages[index]))
|
|
42780
43027
|
carriesThinking = true;
|
|
42781
43028
|
}
|
|
42782
|
-
|
|
42783
|
-
if (mayChangeOrder && addMergedReasoningStrippedIds(args.db, args.sessionId, [
|
|
43029
|
+
if (onBranch && carriesThinking && args.bustPermittedAtStart && addMergedReasoningStrippedIds(args.db, args.sessionId, [
|
|
42784
43030
|
THINKING_BINDING_STRIP_ORDER_END_MARKER
|
|
42785
43031
|
])) {
|
|
42786
43032
|
return "end";
|
|
42787
43033
|
}
|
|
42788
|
-
return "start";
|
|
43034
|
+
return args.releasesAllThinking === true ? "end" : "start";
|
|
43035
|
+
}
|
|
43036
|
+
function recordPiBindingStripEndOrder(db, sessionId) {
|
|
43037
|
+
try {
|
|
43038
|
+
const ledger = getMergedReasoningStrippedIds(db, sessionId);
|
|
43039
|
+
if (ledger.has(THINKING_BINDING_STRIP_ORDER_END_MARKER))
|
|
43040
|
+
return true;
|
|
43041
|
+
if (frozenBindingEntryIds(db, sessionId).size === 0)
|
|
43042
|
+
return true;
|
|
43043
|
+
return addMergedReasoningStrippedIds(db, sessionId, [
|
|
43044
|
+
THINKING_BINDING_STRIP_ORDER_END_MARKER
|
|
43045
|
+
]);
|
|
43046
|
+
} catch {
|
|
43047
|
+
return false;
|
|
43048
|
+
}
|
|
42789
43049
|
}
|
|
42790
43050
|
function shouldRunPiProactiveThinkingStrip(args) {
|
|
42791
43051
|
return !args.compactionOff && args.bindingStripOrder === "end";
|
|
@@ -46236,12 +46496,34 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
46236
46496
|
const lkgInputIdByRef = new Map;
|
|
46237
46497
|
for (const input of lkgPassSnapshot.inputs)
|
|
46238
46498
|
lkgInputIdByRef.set(event.messages[input.messageIndex], input.id);
|
|
46499
|
+
const requestToolsRelease = isPrefixBoundThinkingModel(ctx.model?.provider, ctx.model?.id) ? (() => {
|
|
46500
|
+
const fingerprint = readPiRequestToolsFingerprint(pi, toolWireSchema, event.messages, {
|
|
46501
|
+
host: getHarness2() === "omp" ? "omp" : "pi",
|
|
46502
|
+
model: ctx.model,
|
|
46503
|
+
oauth: (() => {
|
|
46504
|
+
try {
|
|
46505
|
+
const registry = ctx.modelRegistry;
|
|
46506
|
+
return ctx.model && typeof registry?.isUsingOAuth === "function" ? registry.isUsingOAuth(ctx.model) === true : false;
|
|
46507
|
+
} catch {
|
|
46508
|
+
return false;
|
|
46509
|
+
}
|
|
46510
|
+
})()
|
|
46511
|
+
});
|
|
46512
|
+
return fingerprint ? evaluateRequestToolsRelease({
|
|
46513
|
+
db: options.db,
|
|
46514
|
+
sessionId,
|
|
46515
|
+
modelKey: `${ctx.model?.provider}/${ctx.model?.id}`,
|
|
46516
|
+
fingerprint
|
|
46517
|
+
}) : undefined;
|
|
46518
|
+
})() : undefined;
|
|
46519
|
+
const requestToolsChange = requestToolsRelease?.change ?? null;
|
|
46239
46520
|
const bindingStripOrder = resolvePiBindingStripOrder({
|
|
46240
46521
|
db: options.db,
|
|
46241
46522
|
sessionId,
|
|
46242
46523
|
messages: event.messages,
|
|
46243
46524
|
entryIds: lkgEntryIds ?? [],
|
|
46244
|
-
bustPermittedAtStart: hasPendingMaterialization(sessionId)
|
|
46525
|
+
bustPermittedAtStart: hasPendingMaterialization(sessionId),
|
|
46526
|
+
releasesAllThinking: requestToolsChange !== null
|
|
46245
46527
|
});
|
|
46246
46528
|
const startOfPassBindingRecovery = bindingStripOrder === "start" ? applyPiThinkingBindingRecovery({
|
|
46247
46529
|
db: options.db,
|
|
@@ -46657,7 +46939,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
46657
46939
|
schedulerDeferReason,
|
|
46658
46940
|
forceMaterialization: forceMaterialization || isEmergency,
|
|
46659
46941
|
forceMaterializationPercentage,
|
|
46660
|
-
signedThinkingHold: resolvePiSignedThinkingHold({
|
|
46942
|
+
signedThinkingHold: requestToolsChange === null && resolvePiSignedThinkingHold({
|
|
46661
46943
|
sessionId,
|
|
46662
46944
|
db: options.db,
|
|
46663
46945
|
messages: event.messages,
|
|
@@ -46665,6 +46947,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
46665
46947
|
usagePercentage,
|
|
46666
46948
|
executeThresholdPercentage: effectiveExecuteThresholdPercentage
|
|
46667
46949
|
}),
|
|
46950
|
+
requestToolsChange,
|
|
46668
46951
|
contextUsage: {
|
|
46669
46952
|
percentage: usagePercentage,
|
|
46670
46953
|
inputTokens: usageInputTokens
|
|
@@ -47400,7 +47683,11 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
47400
47683
|
}
|
|
47401
47684
|
budget.assertOutcome();
|
|
47402
47685
|
publishTransformDecision?.();
|
|
47403
|
-
if (
|
|
47686
|
+
if (requestToolsChange === null || recordPiBindingStripEndOrder(options.db, sessionId))
|
|
47687
|
+
requestToolsRelease?.commit();
|
|
47688
|
+
else
|
|
47689
|
+
sessionLog2(sessionId, "request tools release not recorded: the end strip order could not be written");
|
|
47690
|
+
if (!budget.sideTurn && (result.strictThinkingKept && !result.signedPrefixRewritten || result.heldHeadReleasedForSystemChange === true) && !result.materialized)
|
|
47404
47691
|
recordPiHeldSystemHead(sessionId, (ownsHistory) => deferPiDeliveredSystemRefresh(sessionId, ownsHistory));
|
|
47405
47692
|
recordServedSystemHash();
|
|
47406
47693
|
return { messages: outputMessages };
|
|
@@ -48143,7 +48430,7 @@ async function runCompactionOffPipeline(args) {
|
|
|
48143
48430
|
muralEnabled: args.injection.muralEnabled === true,
|
|
48144
48431
|
compactionOff: true
|
|
48145
48432
|
};
|
|
48146
|
-
const signedTurnHoldsHead = args.reasoningClearing?.prefixBound === true && hasActiveAnthropicThinkingTurn(args.messages, args.resolvedProviderID, args.resolvedModelID);
|
|
48433
|
+
const signedTurnHoldsHead = !args.requestToolsChange && args.reasoningClearing?.prefixBound === true && hasActiveAnthropicThinkingTurn(args.messages, args.resolvedProviderID, args.resolvedModelID);
|
|
48147
48434
|
if (signedTurnHoldsHead)
|
|
48148
48435
|
state.preparedPrefix = prepareCachedM0M1PiReplay(state, args.db, args.injectionPassSnapshot?.cachedRow);
|
|
48149
48436
|
const servedBeforeFirstRender = signedTurnHoldsHead && !state.preparedPrefix ? args.readLastServedMessages?.() ?? null : undefined;
|
|
@@ -48160,7 +48447,7 @@ async function runCompactionOffPipeline(args) {
|
|
|
48160
48447
|
sessionLog2(args.sessionId, "compaction-off fold changed the head: stripping signed thinking");
|
|
48161
48448
|
}
|
|
48162
48449
|
}
|
|
48163
|
-
if (headChangedUnderSignedThinking)
|
|
48450
|
+
if (headChangedUnderSignedThinking || args.requestToolsChange)
|
|
48164
48451
|
applyPiProactiveThinkingStrip({
|
|
48165
48452
|
db: args.db,
|
|
48166
48453
|
sessionId: args.sessionId,
|
|
@@ -48271,7 +48558,7 @@ async function runPipeline(args) {
|
|
|
48271
48558
|
cacheBustingPass: isCacheBustingPass,
|
|
48272
48559
|
stripActiveTurn: true,
|
|
48273
48560
|
persistOnly: true,
|
|
48274
|
-
requirePersistence: !!args.recoveryRebuildReason
|
|
48561
|
+
requirePersistence: !!args.recoveryRebuildReason || !!args.requestToolsChange
|
|
48275
48562
|
});
|
|
48276
48563
|
if (activeThinkingTurn && isCacheBustingPass && !result)
|
|
48277
48564
|
throw new Error("Cannot persist signed thinking omission before prefix rewrite");
|
|
@@ -48281,6 +48568,8 @@ async function runPipeline(args) {
|
|
|
48281
48568
|
};
|
|
48282
48569
|
if (args.recoveryRebuildReason || args.forceSignedRebuildForFit && signedTurnOnPrefixBoundModel)
|
|
48283
48570
|
stripForPrefixRewrite(isCacheBustingPass);
|
|
48571
|
+
if (args.requestToolsChange && !rewritingSignedPrefix)
|
|
48572
|
+
stripForPrefixRewrite();
|
|
48284
48573
|
const stripUnheldSignedTurnOnBust = () => {
|
|
48285
48574
|
if (isCacheBustingPass && signedTurnOnPrefixBoundModel && !protectedSignedPrefix && !rewritingSignedPrefix)
|
|
48286
48575
|
stripForPrefixRewrite();
|
|
@@ -48458,6 +48747,12 @@ async function runPipeline(args) {
|
|
|
48458
48747
|
const mismatch = foldDueDecision.mismatch ? ` mismatch=${JSON.stringify(foldDueDecision.mismatch)}` : "";
|
|
48459
48748
|
sessionLog2(args.sessionId, `pi m[0] HARD fold decision: reason=${preFoldInjectionResult?.m0Reason ?? foldDueDecision.reason ?? "soft_refresh"}${mismatch} executed=${foldExecutedThisPass} bustsServedPrefix=${foldBustsServedPrefixThisPass}`);
|
|
48460
48749
|
}
|
|
48750
|
+
let heldHeadReleasedForSystemChange = false;
|
|
48751
|
+
if (effectiveSystemChangedThisPass && protectedSignedPrefix) {
|
|
48752
|
+
sessionLog2(args.sessionId, "system prompt changed under a held signed turn: releasing signed thinking");
|
|
48753
|
+
heldHeadReleasedForSystemChange = !firstRenderBust && piM0State !== undefined;
|
|
48754
|
+
stripForPrefixRewrite();
|
|
48755
|
+
}
|
|
48461
48756
|
const temporalCandidates = args.temporalAwareness ? collectPiTemporalCandidates(args.messages, args.entryIds ?? []) : new Map;
|
|
48462
48757
|
for (const entry of readPiIdentityDecisions(args.db, args.sessionId) ?? []) {
|
|
48463
48758
|
const decision = decodePiContentDecision(entry);
|
|
@@ -49469,12 +49764,14 @@ async function runPipeline(args) {
|
|
|
49469
49764
|
stripPiLeadingTemporalMarker(message);
|
|
49470
49765
|
}
|
|
49471
49766
|
}
|
|
49472
|
-
if (
|
|
49473
|
-
|
|
49474
|
-
|
|
49475
|
-
|
|
49476
|
-
|
|
49477
|
-
|
|
49767
|
+
if (!heldHeadReleasedForSystemChange) {
|
|
49768
|
+
if (args.isCacheBusting && prefixMutationAllowed) {
|
|
49769
|
+
historyRefreshSessions.delete(args.sessionId);
|
|
49770
|
+
historyWasConsumedThisPass = true;
|
|
49771
|
+
}
|
|
49772
|
+
if (deferredHistoryRefresh && prefixMutationAllowed) {
|
|
49773
|
+
historyWasConsumedThisPass = true;
|
|
49774
|
+
}
|
|
49478
49775
|
}
|
|
49479
49776
|
logTransformTiming(args.sessionId, "prepareCompartmentInjection", tInjection);
|
|
49480
49777
|
logTransformTiming(args.sessionId, "compartmentPhase", tInjection);
|
|
@@ -49722,6 +50019,7 @@ async function runPipeline(args) {
|
|
|
49722
50019
|
prefixBustPermitted: isCacheBustingPass,
|
|
49723
50020
|
prefixMutationAllowed,
|
|
49724
50021
|
strictThinkingKept: protectedSignedPrefix,
|
|
50022
|
+
heldHeadReleasedForSystemChange,
|
|
49725
50023
|
signedPrefixRewritten: rewritingSignedPrefix,
|
|
49726
50024
|
prefixRebuildAlreadyPriced: firstRenderBust || !!args.recoveryRebuildReason && isCacheBustingPass,
|
|
49727
50025
|
identityRebuilt: identityRebuild,
|
|
@@ -19,7 +19,7 @@ serveWorkerJobs(async (input, port) => {
|
|
|
19
19
|
await main();
|
|
20
20
|
async function main() {
|
|
21
21
|
if (input.v2ArchiveReader) {
|
|
22
|
-
const { serveV2ArchiveReads } = await import("./v2-archive-reader-
|
|
22
|
+
const { serveV2ArchiveReads } = await import("./v2-archive-reader-ksmk6bfw.js");
|
|
23
23
|
await serveV2ArchiveReads(port, openConnections);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
@@ -51,7 +51,7 @@ serveWorkerJobs(async (input, port) => {
|
|
|
51
51
|
await runMessageFtsRowidMapBackfill(db);
|
|
52
52
|
reply = { kind: "fts-rowid-backfill" };
|
|
53
53
|
} else if (input.searchArchive) {
|
|
54
|
-
const { renderSearchArchive } = await import("./search-archive-
|
|
54
|
+
const { renderSearchArchive } = await import("./search-archive-9svkd0f6.js");
|
|
55
55
|
const { readRawSessionMessageIdOrdinalsForRangeFromDb } = await import("./read-session-raw-nttnwy8p.js");
|
|
56
56
|
const archive = input.searchArchive;
|
|
57
57
|
let raw;
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
renderVerboseRange2,
|
|
4
4
|
renderVerboseRangeForTool2,
|
|
5
5
|
renderItemByTag2
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-nev91y6k.js";
|
|
7
7
|
import"./index-w26zvs1q.js";
|
|
8
8
|
import"./index-fzadydec.js";
|
|
9
9
|
import"./index-hgd00nas.js";
|
|
10
|
-
import"./index-
|
|
10
|
+
import"./index-nvh6d3bz.js";
|
|
11
11
|
import"./index-4sa1rx3h.js";
|
|
12
12
|
import"./index-7esg5v2x.js";
|
|
13
13
|
import"./index-zchc0df8.js";
|
package/dist/subagent-entry.js
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
ensureProjectRegisteredFromPiDirectory,
|
|
35
35
|
resolvePiHarnessKind,
|
|
36
36
|
registerMagicContextTools
|
|
37
|
-
} from "./index-
|
|
37
|
+
} from "./index-j9bhd718.js";
|
|
38
38
|
import"./index-gzk7d940.js";
|
|
39
39
|
import"./index-gwvahsdz.js";
|
|
40
40
|
import"./index-4sa1rx3h.js";
|
|
@@ -45,14 +45,14 @@ import"./index-9p40dgkm.js";
|
|
|
45
45
|
import"./index-mp0gh04g.js";
|
|
46
46
|
import"./index-yhzhdp3m.js";
|
|
47
47
|
import"./index-zwbgxt01.js";
|
|
48
|
-
import"./index-
|
|
48
|
+
import"./index-nev91y6k.js";
|
|
49
49
|
import"./index-fzadydec.js";
|
|
50
50
|
import"./index-zchc0df8.js";
|
|
51
51
|
import"./index-6x556c2q.js";
|
|
52
|
-
import"./index-
|
|
52
|
+
import"./index-nvh6d3bz.js";
|
|
53
53
|
import"./index-w26zvs1q.js";
|
|
54
54
|
import"./index-1cvyaw9a.js";
|
|
55
|
-
import"./index-
|
|
55
|
+
import"./index-tcm1gqcb.js";
|
|
56
56
|
import"./index-v7m1nqwz.js";
|
|
57
57
|
import"./index-29nw7n1r.js";
|
|
58
58
|
import"./index-qt711raa.js";
|
package/package.json
CHANGED