@cortexkit/pi-magic-context 0.49.57 → 0.49.59
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 +5 -5
- package/dist/chunk-embedding-write-worker.js +12 -12
- package/dist/{compaction-marker-candidates-9yhrstyb.js → compaction-marker-candidates-nxaamfej.js} +2 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-wg7emg3z.js → compartment-chunk-embedding-avkyp2df.js} +7 -7
- package/dist/{embedding-backfill-qde2zywg.js → embedding-backfill-3g3cm51d.js} +12 -12
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +4 -4
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/{index-j0eagxkz.js → index-1ts77n1b.js} +1 -1
- package/dist/{index-tz8431zx.js → index-2tk7e0bx.js} +19 -19
- package/dist/{index-xssjy4z9.js → index-3s39a1md.js} +1 -1
- package/dist/{index-xx1911hb.js → index-453s1hj6.js} +1 -1
- package/dist/{index-8ej7crnf.js → index-5hhhxck7.js} +10 -10
- package/dist/{index-qm139qq2.js → index-5rcjs14a.js} +2 -2
- package/dist/{index-yjgkjkjs.js → index-71rg8j43.js} +1 -1
- package/dist/{index-zxm7ckvc.js → index-79xfn84y.js} +2 -2
- package/dist/{index-xgkq843e.js → index-8gvbskcm.js} +4 -4
- package/dist/{index-15eq9z3a.js → index-9cqfbdgb.js} +3 -3
- package/dist/{index-ndg15t3x.js → index-cxczethe.js} +4 -4
- package/dist/{index-erkb5dee.js → index-e9wkbh8y.js} +8 -8
- package/dist/{index-prhdb9c5.js → index-f4n7tnsf.js} +2 -2
- package/dist/{index-mmwgmz8f.js → index-fz4gexgk.js} +2 -2
- package/dist/{index-d40ecdbn.js → index-gavj3e6h.js} +4 -4
- package/dist/{index-6d0bby9d.js → index-ghp32f9m.js} +2 -2
- package/dist/{index-v858d5d1.js → index-jhmz9tgv.js} +1 -1
- package/dist/{index-awpx91y5.js → index-k7a8x7ba.js} +1 -1
- package/dist/{index-15rx61th.js → index-m6kszx0e.js} +4 -4
- package/dist/{index-7y60kyea.js → index-pefn1gt5.js} +1 -1
- package/dist/{index-jnh7a6a3.js → index-qdy49kwk.js} +4 -4
- package/dist/{index-yxeg8zaa.js → index-tm11k42a.js} +9 -4
- package/dist/{index-hec3bwev.js → index-txcs0vnj.js} +2 -2
- package/dist/{index-0133ybm6.js → index-w4sqw9mf.js} +8 -8
- package/dist/{index-7mvsg371.js → index-xan5mt5f.js} +5 -5
- package/dist/{index-szn2tac8.js → index-xjhq27z9.js} +1 -1
- package/dist/{index-mbzqrp0s.js → index-zgsemyph.js} +10 -10
- package/dist/index.js +341 -231
- package/dist/{logger-hhgpkbx1.js → logger-93cnqyh0.js} +1 -1
- package/dist/{message-fts-rowid-map-tec2x7qe.js → message-fts-rowid-map-dtbragnt.js} +4 -4
- package/dist/{message-index-bounded-q6dyk780.js → message-index-bounded-behq385r.js} +9 -9
- package/dist/{message-time-backfill-krre2qnb.js → message-time-backfill-8zwv9byv.js} +2 -2
- package/dist/migration-worker.js +9 -9
- package/dist/{project-embedding-registry-qx2zjbgs.js → project-embedding-registry-63wsm3a8.js} +11 -11
- package/dist/raw-ordinal-warmup-worker.js +8 -8
- package/dist/{read-session-chunk-ksn2r664.js → read-session-chunk-ksh32zfv.js} +7 -7
- package/dist/{read-session-raw-75dcxtdy.js → read-session-raw-0tytrjye.js} +2 -2
- package/dist/{render-nejsk0az.js → render-2qed2svq.js} +16 -16
- package/dist/{safe-notification-target-8s1xg0q9.js → safe-notification-target-fkyrd95h.js} +2 -2
- package/dist/{search-archive-4yfsc0xb.js → search-archive-qqj7j1w1.js} +9 -9
- package/dist/{search-h61ec8kh.js → search-vmw1xbqx.js} +19 -19
- package/dist/{storage-tags-jfewemtk.js → storage-tags-s0m7e39a.js} +5 -5
- package/dist/subagent-entry.js +25 -25
- package/dist/tag-snapshot-worker-pi.js +11 -11
- package/dist/{v2-archive-reader-hveb3ajf.js → v2-archive-reader-cc7sx6dk.js} +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
harnessOwnsOpenCodeStore2
|
|
5
5
|
} from "./index-0h2mkab2.js";
|
|
6
6
|
import {
|
|
7
|
+
getMagicContextHistorianSessionDir,
|
|
7
8
|
ensureCortexKitArtifactGitignore,
|
|
8
|
-
getProjectMagicContextHistorianDir,
|
|
9
9
|
getMagicContextStorageDir,
|
|
10
10
|
isMagicContextStorageOutsideEngram,
|
|
11
11
|
claimStorageBackupWarningCheck,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
log2,
|
|
16
16
|
sessionLog2,
|
|
17
17
|
flushLogger2
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-tm11k42a.js";
|
|
19
19
|
import {
|
|
20
20
|
sanitizeDiagnosticText,
|
|
21
21
|
hasShareabilitySensitiveText
|
|
@@ -154,7 +154,7 @@ import {
|
|
|
154
154
|
registerTodoStateLifecycle,
|
|
155
155
|
syncCtxMemoryToolEnabled,
|
|
156
156
|
registerMagicContextTools
|
|
157
|
-
} from "./index-
|
|
157
|
+
} from "./index-2tk7e0bx.js";
|
|
158
158
|
import"./index-4knyh1kt.js";
|
|
159
159
|
import {
|
|
160
160
|
canonicalModelIdentity,
|
|
@@ -193,7 +193,7 @@ import {
|
|
|
193
193
|
resolveProjectIdentityForSession,
|
|
194
194
|
beginBootQuietPeriod,
|
|
195
195
|
scheduleAfterBootQuiet
|
|
196
|
-
} from "./index-
|
|
196
|
+
} from "./index-453s1hj6.js";
|
|
197
197
|
import {
|
|
198
198
|
detectThinkingBindingMismatch,
|
|
199
199
|
detectLatestTurnThinkingMismatch,
|
|
@@ -403,7 +403,7 @@ import {
|
|
|
403
403
|
setSessionWorkMetrics,
|
|
404
404
|
getSessionWorkMetrics,
|
|
405
405
|
resolveEpochFloorForPass
|
|
406
|
-
} from "./index-
|
|
406
|
+
} from "./index-8gvbskcm.js";
|
|
407
407
|
import {
|
|
408
408
|
textMentionsRecentCommit,
|
|
409
409
|
hasMeaningfulUserText2,
|
|
@@ -415,7 +415,7 @@ import {
|
|
|
415
415
|
estimateTokens,
|
|
416
416
|
estimateFixedPromptTokens,
|
|
417
417
|
normalizeText
|
|
418
|
-
} from "./index-
|
|
418
|
+
} from "./index-pefn1gt5.js";
|
|
419
419
|
import {
|
|
420
420
|
stableStringify,
|
|
421
421
|
BoundedSessionMap,
|
|
@@ -423,7 +423,7 @@ import {
|
|
|
423
423
|
observeTemporalDecisions,
|
|
424
424
|
freezeTemporalDecisions,
|
|
425
425
|
tagIdentityRevisionKey
|
|
426
|
-
} from "./index-
|
|
426
|
+
} from "./index-jhmz9tgv.js";
|
|
427
427
|
import {
|
|
428
428
|
inRootAsyncContext2,
|
|
429
429
|
Database2,
|
|
@@ -454,7 +454,7 @@ import {
|
|
|
454
454
|
openCurrentDatabase,
|
|
455
455
|
openDatabaseAsync,
|
|
456
456
|
closeDatabase
|
|
457
|
-
} from "./index-
|
|
457
|
+
} from "./index-w4sqw9mf.js";
|
|
458
458
|
import {
|
|
459
459
|
LkgRecoveryFenceError,
|
|
460
460
|
clearLkgFenceProcessState,
|
|
@@ -581,7 +581,7 @@ import {
|
|
|
581
581
|
getSourceContents,
|
|
582
582
|
recordSubagentInvocation,
|
|
583
583
|
getLatestHistorianInvocationId
|
|
584
|
-
} from "./index-
|
|
584
|
+
} from "./index-zgsemyph.js";
|
|
585
585
|
import {
|
|
586
586
|
resolveOpenCodeDbPath,
|
|
587
587
|
assertOpenCodeStoreGeneration,
|
|
@@ -599,7 +599,7 @@ import {
|
|
|
599
599
|
} from "./index-x2n261wp.js";
|
|
600
600
|
import {
|
|
601
601
|
RAW_SUMMARY_TEXT_MAX_CHARS2
|
|
602
|
-
} from "./index-
|
|
602
|
+
} from "./index-xjhq27z9.js";
|
|
603
603
|
import {
|
|
604
604
|
askAnswerLines,
|
|
605
605
|
removeUnsupportedCommitHashes,
|
|
@@ -647,12 +647,12 @@ import {
|
|
|
647
647
|
getRawSessionTagKeysThrough2,
|
|
648
648
|
getLegacyProtectedTailStartOrdinal2,
|
|
649
649
|
readSessionChunk2
|
|
650
|
-
} from "./index-
|
|
650
|
+
} from "./index-xan5mt5f.js";
|
|
651
651
|
import"./index-nvh6d3bz.js";
|
|
652
652
|
import {
|
|
653
653
|
formatSynapseLaneDescriptor
|
|
654
|
-
} from "./index-
|
|
655
|
-
import"./index-
|
|
654
|
+
} from "./index-5rcjs14a.js";
|
|
655
|
+
import"./index-ghp32f9m.js";
|
|
656
656
|
import {
|
|
657
657
|
buildCanonicalChunkTextFromFts2,
|
|
658
658
|
buildCompartmentSummaryFallbackText2,
|
|
@@ -662,7 +662,7 @@ import {
|
|
|
662
662
|
replaceCompartmentChunkEmbeddings2,
|
|
663
663
|
deleteChunkEmbedBackoffForSession2,
|
|
664
664
|
chunkWindowSourceKey2
|
|
665
|
-
} from "./index-
|
|
665
|
+
} from "./index-cxczethe.js";
|
|
666
666
|
import {
|
|
667
667
|
recordSessionProjectIdentity,
|
|
668
668
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
@@ -671,7 +671,7 @@ import {
|
|
|
671
671
|
markGitSweepSuccessAndRelease,
|
|
672
672
|
parkGitSweepNonIndexable,
|
|
673
673
|
releaseGitSweepLease
|
|
674
|
-
} from "./index-
|
|
674
|
+
} from "./index-79xfn84y.js";
|
|
675
675
|
import {
|
|
676
676
|
embedPauseBySession,
|
|
677
677
|
embedRunStateBySession,
|
|
@@ -687,7 +687,7 @@ import {
|
|
|
687
687
|
clearCompressionDepthRange,
|
|
688
688
|
cleanSearchText,
|
|
689
689
|
matchedSearchSnippet
|
|
690
|
-
} from "./index-
|
|
690
|
+
} from "./index-m6kszx0e.js";
|
|
691
691
|
import {
|
|
692
692
|
rememberV1HiddenRun
|
|
693
693
|
} from "./index-6x556c2q.js";
|
|
@@ -702,7 +702,7 @@ import {
|
|
|
702
702
|
expandWorkspaceIdentitySetWithAliases,
|
|
703
703
|
sourceNameForMemory,
|
|
704
704
|
computeWorkspaceEpochFingerprint
|
|
705
|
-
} from "./index-
|
|
705
|
+
} from "./index-gavj3e6h.js";
|
|
706
706
|
import {
|
|
707
707
|
configureContextDatabasePragmas2
|
|
708
708
|
} from "./index-fapenpch.js";
|
|
@@ -727,7 +727,7 @@ import {
|
|
|
727
727
|
createPrimer,
|
|
728
728
|
updatePrimerSupport,
|
|
729
729
|
updatePrimerAnswer
|
|
730
|
-
} from "./index-
|
|
730
|
+
} from "./index-k7a8x7ba.js";
|
|
731
731
|
import {
|
|
732
732
|
setEmbeddingSessionBusy2,
|
|
733
733
|
isEmbeddingHostBusy2
|
|
@@ -761,7 +761,7 @@ import {
|
|
|
761
761
|
} from "./index-q1yc6bs0.js";
|
|
762
762
|
import {
|
|
763
763
|
getCachedLocalEmbeddingPooling
|
|
764
|
-
} from "./index-
|
|
764
|
+
} from "./index-txcs0vnj.js";
|
|
765
765
|
import {
|
|
766
766
|
describeShadowBackfillWriteRefusal2,
|
|
767
767
|
contentSha2562,
|
|
@@ -779,10 +779,10 @@ import {
|
|
|
779
779
|
embedSessionCompartmentChunks2,
|
|
780
780
|
getEmbeddingCoverageStatus2,
|
|
781
781
|
getAutoEmbeddingSessionCoverage2
|
|
782
|
-
} from "./index-
|
|
782
|
+
} from "./index-e9wkbh8y.js";
|
|
783
783
|
import {
|
|
784
784
|
cosineSimilarity
|
|
785
|
-
} from "./index-
|
|
785
|
+
} from "./index-qdy49kwk.js";
|
|
786
786
|
import {
|
|
787
787
|
USER_FACING_FAILURES,
|
|
788
788
|
renderUserFacingFailure,
|
|
@@ -816,8 +816,8 @@ import {
|
|
|
816
816
|
scheduleClearAndReindex,
|
|
817
817
|
clearSessionTracking,
|
|
818
818
|
createAutoSearchDiagnostics
|
|
819
|
-
} from "./index-
|
|
820
|
-
import"./index-
|
|
819
|
+
} from "./index-5hhhxck7.js";
|
|
820
|
+
import"./index-3s39a1md.js";
|
|
821
821
|
import {
|
|
822
822
|
DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
|
|
823
823
|
buildHiddenAgentRegistrations,
|
|
@@ -845,11 +845,11 @@ import {
|
|
|
845
845
|
drainPiTagSnapshotSession,
|
|
846
846
|
assertPiTagSnapshotReady,
|
|
847
847
|
ensurePiTagSnapshotReady
|
|
848
|
-
} from "./index-
|
|
849
|
-
import"./index-
|
|
848
|
+
} from "./index-fz4gexgk.js";
|
|
849
|
+
import"./index-71rg8j43.js";
|
|
850
850
|
import"./index-8d2z6503.js";
|
|
851
|
-
import"./index-
|
|
852
|
-
import"./index-
|
|
851
|
+
import"./index-9cqfbdgb.js";
|
|
852
|
+
import"./index-f4n7tnsf.js";
|
|
853
853
|
import {
|
|
854
854
|
__toESM
|
|
855
855
|
} from "./index-22jkk6wg.js";
|
|
@@ -869,7 +869,7 @@ import {
|
|
|
869
869
|
import {
|
|
870
870
|
logSlowWriteTransaction,
|
|
871
871
|
WriteTransactionSteps
|
|
872
|
-
} from "./index-
|
|
872
|
+
} from "./index-1ts77n1b.js";
|
|
873
873
|
import {
|
|
874
874
|
setStoragePrivatePermissionEnforcement,
|
|
875
875
|
ensureStorageDirectorySync,
|
|
@@ -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.59",
|
|
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",
|
|
@@ -9759,9 +9759,6 @@ function fitHistorianPrompt(args) {
|
|
|
9759
9759
|
}
|
|
9760
9760
|
|
|
9761
9761
|
// ../plugin/src/hooks/magic-context/compartment-runner-historian.ts
|
|
9762
|
-
function historianResponseDumpDir(directory) {
|
|
9763
|
-
return getProjectMagicContextHistorianDir(directory);
|
|
9764
|
-
}
|
|
9765
9762
|
var MAX_HISTORIAN_RETRIES = 2;
|
|
9766
9763
|
var unknownProducerWindows = new Set;
|
|
9767
9764
|
var HISTORIAN_REASONING_PART_TYPES = new Set(["reasoning", "thinking", "redacted_thinking"]);
|
|
@@ -10235,7 +10232,7 @@ async function runHistorianPrompt(args) {
|
|
|
10235
10232
|
invocationId: invocationId ?? undefined
|
|
10236
10233
|
};
|
|
10237
10234
|
}
|
|
10238
|
-
const dumpPath = dumpHistorianResponse(parentSessionId,
|
|
10235
|
+
const dumpPath = dumpHistorianResponse(parentSessionId, dumpLabel ?? "historian-response", result);
|
|
10239
10236
|
return { ok: true, result, dumpPath, invocationId: invocationId ?? undefined };
|
|
10240
10237
|
} catch (modelError) {
|
|
10241
10238
|
hiddenModelCooldowns.record(handle?.attemptedModel ?? toModelEntry(modelOverride)?.model, modelError);
|
|
@@ -10389,14 +10386,12 @@ function cleanupHistorianDump(sessionId, dumpPath) {
|
|
|
10389
10386
|
});
|
|
10390
10387
|
}
|
|
10391
10388
|
}
|
|
10392
|
-
function dumpHistorianResponse(sessionId,
|
|
10389
|
+
function dumpHistorianResponse(sessionId, label, text) {
|
|
10393
10390
|
try {
|
|
10394
|
-
const dumpDir =
|
|
10391
|
+
const dumpDir = getMagicContextHistorianSessionDir(sessionId);
|
|
10395
10392
|
mkdirSync(dumpDir, { recursive: true });
|
|
10396
|
-
ensureCortexKitArtifactGitignore(directory);
|
|
10397
|
-
const safeSessionId = sanitizeDumpName(sessionId);
|
|
10398
10393
|
const safeLabel = sanitizeDumpName(label);
|
|
10399
|
-
const dumpPath = join7(dumpDir, `${
|
|
10394
|
+
const dumpPath = join7(dumpDir, `${safeLabel}-${Date.now()}.xml`);
|
|
10400
10395
|
writeFileSync(dumpPath, text, "utf8");
|
|
10401
10396
|
sessionLog2(sessionId, "compartment agent: historian response dumped", {
|
|
10402
10397
|
label,
|
|
@@ -32028,6 +32023,230 @@ function recordPiTransformTiming(sample) {
|
|
|
32028
32023
|
timingObserver?.(sample);
|
|
32029
32024
|
}
|
|
32030
32025
|
|
|
32026
|
+
// src/pi-request-tools.ts
|
|
32027
|
+
var schemaDigests = {
|
|
32028
|
+
omp: new WeakMap,
|
|
32029
|
+
anthropic: new WeakMap,
|
|
32030
|
+
"anthropic-strict": new WeakMap,
|
|
32031
|
+
raw: new WeakMap
|
|
32032
|
+
};
|
|
32033
|
+
function anthropicWireSchema(parameters, strict) {
|
|
32034
|
+
const schema = typeof parameters === "object" && parameters !== null ? parameters : {};
|
|
32035
|
+
const legacy = {
|
|
32036
|
+
type: "object",
|
|
32037
|
+
properties: schema.properties ?? {},
|
|
32038
|
+
required: schema.required ?? []
|
|
32039
|
+
};
|
|
32040
|
+
return strict ? { ...schema, ...legacy } : legacy;
|
|
32041
|
+
}
|
|
32042
|
+
function schemaDigest(tool, mode, wireSchema) {
|
|
32043
|
+
const key = tool.parameters;
|
|
32044
|
+
const cacheable = typeof key === "object" && key !== null || typeof key === "function";
|
|
32045
|
+
const cache = schemaDigests[mode];
|
|
32046
|
+
if (cacheable) {
|
|
32047
|
+
const cached = cache.get(key);
|
|
32048
|
+
if (cached !== undefined)
|
|
32049
|
+
return cached;
|
|
32050
|
+
}
|
|
32051
|
+
const digest = requestToolSchemaDigest(mode === "omp" && wireSchema ? wireSchema(tool) : mode === "anthropic" || mode === "anthropic-strict" ? anthropicWireSchema(tool.parameters, mode === "anthropic-strict") : tool.parameters);
|
|
32052
|
+
if (cacheable)
|
|
32053
|
+
cache.set(key, digest);
|
|
32054
|
+
return digest;
|
|
32055
|
+
}
|
|
32056
|
+
var CLAUDE_CODE_TOOL_NAMES = new Map([
|
|
32057
|
+
"Read",
|
|
32058
|
+
"Write",
|
|
32059
|
+
"Edit",
|
|
32060
|
+
"Bash",
|
|
32061
|
+
"Grep",
|
|
32062
|
+
"Glob",
|
|
32063
|
+
"AskUserQuestion",
|
|
32064
|
+
"EnterPlanMode",
|
|
32065
|
+
"ExitPlanMode",
|
|
32066
|
+
"KillShell",
|
|
32067
|
+
"NotebookEdit",
|
|
32068
|
+
"Skill",
|
|
32069
|
+
"Task",
|
|
32070
|
+
"TaskOutput",
|
|
32071
|
+
"TodoWrite",
|
|
32072
|
+
"WebFetch",
|
|
32073
|
+
"WebSearch"
|
|
32074
|
+
].map((name) => [name.toLowerCase(), name]));
|
|
32075
|
+
var identityName = (name) => name;
|
|
32076
|
+
var claudeCodeName = (name) => CLAUDE_CODE_TOOL_NAMES.get(name.toLowerCase()) ?? name;
|
|
32077
|
+
function compatFlag(model, flag) {
|
|
32078
|
+
const value = model?.compat?.[flag];
|
|
32079
|
+
return typeof value === "boolean" ? value : undefined;
|
|
32080
|
+
}
|
|
32081
|
+
function supportsToolReferences(model) {
|
|
32082
|
+
const declared = compatFlag(model, "supportsToolReferences");
|
|
32083
|
+
if (declared !== undefined)
|
|
32084
|
+
return declared;
|
|
32085
|
+
if (model.provider !== "anthropic" || typeof model.id !== "string")
|
|
32086
|
+
return false;
|
|
32087
|
+
if (model.id.includes("haiku"))
|
|
32088
|
+
return false;
|
|
32089
|
+
const version = model.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
|
|
32090
|
+
if (!version)
|
|
32091
|
+
return false;
|
|
32092
|
+
const major = Number(version[1]);
|
|
32093
|
+
const minor = version[2] && version[2].length < 8 ? Number(version[2]) : 0;
|
|
32094
|
+
return major > 4 || major === 4 && minor >= 5;
|
|
32095
|
+
}
|
|
32096
|
+
function deferredAndReferencedNames(messages, normalizeName) {
|
|
32097
|
+
const deferred = new Set;
|
|
32098
|
+
const referenced = new Set;
|
|
32099
|
+
for (const message of messages) {
|
|
32100
|
+
const { role, content, addedToolNames } = message ?? {};
|
|
32101
|
+
if (role === "assistant" && Array.isArray(content)) {
|
|
32102
|
+
for (const block of content) {
|
|
32103
|
+
const { type, name } = block ?? {};
|
|
32104
|
+
if (type === "toolCall" && typeof name === "string")
|
|
32105
|
+
referenced.add(normalizeName(name));
|
|
32106
|
+
}
|
|
32107
|
+
} else if (role === "toolResult" && Array.isArray(addedToolNames)) {
|
|
32108
|
+
for (const name of addedToolNames) {
|
|
32109
|
+
if (typeof name !== "string")
|
|
32110
|
+
continue;
|
|
32111
|
+
const normalized = normalizeName(name);
|
|
32112
|
+
if (!referenced.has(normalized))
|
|
32113
|
+
deferred.add(normalized);
|
|
32114
|
+
}
|
|
32115
|
+
}
|
|
32116
|
+
}
|
|
32117
|
+
for (const name of deferred)
|
|
32118
|
+
referenced.add(name);
|
|
32119
|
+
return { deferred, referenced };
|
|
32120
|
+
}
|
|
32121
|
+
function calledToolNames(messages) {
|
|
32122
|
+
const names = new Set;
|
|
32123
|
+
for (const message of messages) {
|
|
32124
|
+
const content = message?.content;
|
|
32125
|
+
if (!Array.isArray(content))
|
|
32126
|
+
continue;
|
|
32127
|
+
for (const part of content) {
|
|
32128
|
+
const { type, name } = part ?? {};
|
|
32129
|
+
if (typeof type === "string" && type.toLowerCase().includes("tool") && typeof name === "string")
|
|
32130
|
+
names.add(name);
|
|
32131
|
+
}
|
|
32132
|
+
}
|
|
32133
|
+
return names;
|
|
32134
|
+
}
|
|
32135
|
+
function readPiRequestSendsTool(pi, name) {
|
|
32136
|
+
try {
|
|
32137
|
+
if (typeof pi.getAllTools !== "function" || typeof pi.getActiveTools !== "function")
|
|
32138
|
+
return;
|
|
32139
|
+
const active = pi.getActiveTools();
|
|
32140
|
+
if (!Array.isArray(active))
|
|
32141
|
+
return;
|
|
32142
|
+
if (!active.includes(name))
|
|
32143
|
+
return false;
|
|
32144
|
+
const all = pi.getAllTools();
|
|
32145
|
+
if (!Array.isArray(all))
|
|
32146
|
+
return;
|
|
32147
|
+
return all.some((tool) => typeof tool === "object" && tool !== null && tool.name === name);
|
|
32148
|
+
} catch {
|
|
32149
|
+
return;
|
|
32150
|
+
}
|
|
32151
|
+
}
|
|
32152
|
+
function readPiRequestToolsFingerprint(pi, wireSchema, messages, route = {}) {
|
|
32153
|
+
try {
|
|
32154
|
+
if (typeof pi.getAllTools !== "function" || typeof pi.getActiveTools !== "function")
|
|
32155
|
+
return;
|
|
32156
|
+
const all = pi.getAllTools();
|
|
32157
|
+
const active = pi.getActiveTools();
|
|
32158
|
+
if (!Array.isArray(all) || !Array.isArray(active))
|
|
32159
|
+
return;
|
|
32160
|
+
const registered = new Map;
|
|
32161
|
+
for (const tool of all) {
|
|
32162
|
+
if (!tool || typeof tool !== "object")
|
|
32163
|
+
return;
|
|
32164
|
+
const { name } = tool;
|
|
32165
|
+
if (typeof name !== "string")
|
|
32166
|
+
return;
|
|
32167
|
+
registered.set(name, tool);
|
|
32168
|
+
}
|
|
32169
|
+
const model = route.model;
|
|
32170
|
+
const anthropicWriter = route.host === "pi" && wireSchema === undefined && model?.api === "anthropic-messages";
|
|
32171
|
+
const mode = wireSchema ? "omp" : anthropicWriter ? compatFlag(model, "supportsStrictTools") === true ? "anthropic-strict" : "anthropic" : "raw";
|
|
32172
|
+
const normalizeName = anthropicWriter && route.oauth === true ? claudeCodeName : identityName;
|
|
32173
|
+
const sent = new Map;
|
|
32174
|
+
for (const name of active) {
|
|
32175
|
+
if (typeof name !== "string")
|
|
32176
|
+
return;
|
|
32177
|
+
const tool = registered.get(name);
|
|
32178
|
+
if (!tool)
|
|
32179
|
+
continue;
|
|
32180
|
+
sent.set(normalizeName(name), tool);
|
|
32181
|
+
}
|
|
32182
|
+
const split = anthropicWriter && model && supportsToolReferences(model) ? deferredAndReferencedNames(messages, normalizeName) : undefined;
|
|
32183
|
+
const anyImmediate = [...sent.keys()].some((name) => !split?.deferred.has(name));
|
|
32184
|
+
const tools = [];
|
|
32185
|
+
for (const [name, tool] of sent) {
|
|
32186
|
+
const description = typeof tool.description === "string" ? tool.description : "";
|
|
32187
|
+
tools.push({
|
|
32188
|
+
name,
|
|
32189
|
+
description,
|
|
32190
|
+
schemaDigest: schemaDigest({
|
|
32191
|
+
name: tool.name,
|
|
32192
|
+
description,
|
|
32193
|
+
parameters: tool.parameters
|
|
32194
|
+
}, mode, wireSchema),
|
|
32195
|
+
deferLoading: split ? anyImmediate && split.deferred.has(name) : tool.defer_loading === true || tool.deferLoading === true
|
|
32196
|
+
});
|
|
32197
|
+
}
|
|
32198
|
+
return requestToolsFingerprint(tools, () => split?.referenced ?? calledToolNames(messages));
|
|
32199
|
+
} catch {
|
|
32200
|
+
return;
|
|
32201
|
+
}
|
|
32202
|
+
}
|
|
32203
|
+
|
|
32204
|
+
// src/ctx-reduce-callable-pi.ts
|
|
32205
|
+
var CTX_REDUCE = "ctx_reduce";
|
|
32206
|
+
function piCtxReduceCallable(pi, compactionOff, session) {
|
|
32207
|
+
if (compactionOff)
|
|
32208
|
+
return false;
|
|
32209
|
+
const sent = readPiRequestSendsTool(pi, CTX_REDUCE);
|
|
32210
|
+
if (sent !== undefined)
|
|
32211
|
+
return sent;
|
|
32212
|
+
return session ? readServedPiCtxReduceCallable(session.db, session.sessionId) : true;
|
|
32213
|
+
}
|
|
32214
|
+
var NAMESPACE4 = "piCtxReduceCallable";
|
|
32215
|
+
var servedBySession = new BoundedSessionMap(1000);
|
|
32216
|
+
function readServedPiCtxReduceCallable(db, sessionId) {
|
|
32217
|
+
const cached = servedBySession.get(sessionId);
|
|
32218
|
+
if (cached !== undefined)
|
|
32219
|
+
return cached;
|
|
32220
|
+
let served = true;
|
|
32221
|
+
try {
|
|
32222
|
+
const stored = readReplayEnvelope(db, sessionId, "read")[NAMESPACE4];
|
|
32223
|
+
if (typeof stored === "boolean")
|
|
32224
|
+
served = stored;
|
|
32225
|
+
} catch (error) {
|
|
32226
|
+
sessionLog2(sessionId, "ctx_reduce served record unreadable:", error);
|
|
32227
|
+
}
|
|
32228
|
+
servedBySession.set(sessionId, served);
|
|
32229
|
+
return served;
|
|
32230
|
+
}
|
|
32231
|
+
function recordServedPiCtxReduceCallable(db, sessionId, callable) {
|
|
32232
|
+
if (readServedPiCtxReduceCallable(db, sessionId) === callable)
|
|
32233
|
+
return;
|
|
32234
|
+
servedBySession.set(sessionId, callable);
|
|
32235
|
+
const written = updateReplayDocument(db, sessionId, (doc) => {
|
|
32236
|
+
const stored = doc[NAMESPACE4];
|
|
32237
|
+
if ((typeof stored === "boolean" ? stored : true) === callable)
|
|
32238
|
+
return false;
|
|
32239
|
+
doc.version = 2;
|
|
32240
|
+
doc[NAMESPACE4] = callable;
|
|
32241
|
+
return true;
|
|
32242
|
+
});
|
|
32243
|
+
if (!written)
|
|
32244
|
+
sessionLog2(sessionId, "ctx_reduce served record not written");
|
|
32245
|
+
}
|
|
32246
|
+
function clearPiCtxReduceCallableSession(sessionId) {
|
|
32247
|
+
servedBySession.delete(sessionId);
|
|
32248
|
+
}
|
|
32249
|
+
|
|
32031
32250
|
// src/ctx-reduce-nudge-pi.ts
|
|
32032
32251
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
32033
32252
|
|
|
@@ -41663,6 +41882,16 @@ ${OMITTED_IMAGE}` : OMITTED_IMAGE : joined);
|
|
|
41663
41882
|
return items;
|
|
41664
41883
|
}
|
|
41665
41884
|
|
|
41885
|
+
// src/pi-provider-input.ts
|
|
41886
|
+
function piProviderInput(message) {
|
|
41887
|
+
if (!message || typeof message !== "object" || Array.isArray(message))
|
|
41888
|
+
return message;
|
|
41889
|
+
const descriptors = Object.getOwnPropertyDescriptors(message);
|
|
41890
|
+
delete descriptors.completedAt;
|
|
41891
|
+
delete descriptors.contextSnapshot;
|
|
41892
|
+
return Object.create(Object.getPrototypeOf(message), descriptors);
|
|
41893
|
+
}
|
|
41894
|
+
|
|
41666
41895
|
// src/pi-dispatch-chain.ts
|
|
41667
41896
|
function object13(value) {
|
|
41668
41897
|
return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
@@ -41694,7 +41923,7 @@ function piPreparedHistory(messages, model) {
|
|
|
41694
41923
|
for (const [index, message] of messages.entries()) {
|
|
41695
41924
|
const source = object13(message);
|
|
41696
41925
|
const identity = head >= 0 && (index === head || index === head + 1) ? Object.fromEntries(Object.entries(source ?? {}).filter(([key]) => key !== "timestamp")) : message;
|
|
41697
|
-
const fields = lkgContentFields(identity);
|
|
41926
|
+
const fields = lkgContentFields(piProviderInput(identity));
|
|
41698
41927
|
if (!fields)
|
|
41699
41928
|
return;
|
|
41700
41929
|
snapshots.push({ id: "", fields });
|
|
@@ -42352,14 +42581,6 @@ function omitsRootBookkeeping(args) {
|
|
|
42352
42581
|
}
|
|
42353
42582
|
return typeof api === "string" && bookkeepingOmittingApis.has(api);
|
|
42354
42583
|
}
|
|
42355
|
-
function piProviderInput(message) {
|
|
42356
|
-
if (!message || typeof message !== "object" || Array.isArray(message))
|
|
42357
|
-
return message;
|
|
42358
|
-
const descriptors = Object.getOwnPropertyDescriptors(message);
|
|
42359
|
-
delete descriptors.completedAt;
|
|
42360
|
-
delete descriptors.contextSnapshot;
|
|
42361
|
-
return Object.create(Object.getPrototypeOf(message), descriptors);
|
|
42362
|
-
}
|
|
42363
42584
|
function restorePiLkgInputForFit(snapshot, branchEntries) {
|
|
42364
42585
|
if (!snapshot || snapshot.preparationFailure || !branchEntries || !snapshot.inputs.length)
|
|
42365
42586
|
return;
|
|
@@ -45381,167 +45602,6 @@ function resolvePiProvenInputFloor(args) {
|
|
|
45381
45602
|
return observed;
|
|
45382
45603
|
}
|
|
45383
45604
|
|
|
45384
|
-
// src/pi-request-tools.ts
|
|
45385
|
-
var schemaDigests = {
|
|
45386
|
-
omp: new WeakMap,
|
|
45387
|
-
anthropic: new WeakMap,
|
|
45388
|
-
"anthropic-strict": new WeakMap,
|
|
45389
|
-
raw: new WeakMap
|
|
45390
|
-
};
|
|
45391
|
-
function anthropicWireSchema(parameters, strict) {
|
|
45392
|
-
const schema = typeof parameters === "object" && parameters !== null ? parameters : {};
|
|
45393
|
-
const legacy = {
|
|
45394
|
-
type: "object",
|
|
45395
|
-
properties: schema.properties ?? {},
|
|
45396
|
-
required: schema.required ?? []
|
|
45397
|
-
};
|
|
45398
|
-
return strict ? { ...schema, ...legacy } : legacy;
|
|
45399
|
-
}
|
|
45400
|
-
function schemaDigest(tool, mode, wireSchema) {
|
|
45401
|
-
const key = tool.parameters;
|
|
45402
|
-
const cacheable = typeof key === "object" && key !== null || typeof key === "function";
|
|
45403
|
-
const cache = schemaDigests[mode];
|
|
45404
|
-
if (cacheable) {
|
|
45405
|
-
const cached = cache.get(key);
|
|
45406
|
-
if (cached !== undefined)
|
|
45407
|
-
return cached;
|
|
45408
|
-
}
|
|
45409
|
-
const digest = requestToolSchemaDigest(mode === "omp" && wireSchema ? wireSchema(tool) : mode === "anthropic" || mode === "anthropic-strict" ? anthropicWireSchema(tool.parameters, mode === "anthropic-strict") : tool.parameters);
|
|
45410
|
-
if (cacheable)
|
|
45411
|
-
cache.set(key, digest);
|
|
45412
|
-
return digest;
|
|
45413
|
-
}
|
|
45414
|
-
var CLAUDE_CODE_TOOL_NAMES = new Map([
|
|
45415
|
-
"Read",
|
|
45416
|
-
"Write",
|
|
45417
|
-
"Edit",
|
|
45418
|
-
"Bash",
|
|
45419
|
-
"Grep",
|
|
45420
|
-
"Glob",
|
|
45421
|
-
"AskUserQuestion",
|
|
45422
|
-
"EnterPlanMode",
|
|
45423
|
-
"ExitPlanMode",
|
|
45424
|
-
"KillShell",
|
|
45425
|
-
"NotebookEdit",
|
|
45426
|
-
"Skill",
|
|
45427
|
-
"Task",
|
|
45428
|
-
"TaskOutput",
|
|
45429
|
-
"TodoWrite",
|
|
45430
|
-
"WebFetch",
|
|
45431
|
-
"WebSearch"
|
|
45432
|
-
].map((name) => [name.toLowerCase(), name]));
|
|
45433
|
-
var identityName = (name) => name;
|
|
45434
|
-
var claudeCodeName = (name) => CLAUDE_CODE_TOOL_NAMES.get(name.toLowerCase()) ?? name;
|
|
45435
|
-
function compatFlag(model, flag) {
|
|
45436
|
-
const value = model?.compat?.[flag];
|
|
45437
|
-
return typeof value === "boolean" ? value : undefined;
|
|
45438
|
-
}
|
|
45439
|
-
function supportsToolReferences(model) {
|
|
45440
|
-
const declared = compatFlag(model, "supportsToolReferences");
|
|
45441
|
-
if (declared !== undefined)
|
|
45442
|
-
return declared;
|
|
45443
|
-
if (model.provider !== "anthropic" || typeof model.id !== "string")
|
|
45444
|
-
return false;
|
|
45445
|
-
if (model.id.includes("haiku"))
|
|
45446
|
-
return false;
|
|
45447
|
-
const version = model.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
|
|
45448
|
-
if (!version)
|
|
45449
|
-
return false;
|
|
45450
|
-
const major = Number(version[1]);
|
|
45451
|
-
const minor = version[2] && version[2].length < 8 ? Number(version[2]) : 0;
|
|
45452
|
-
return major > 4 || major === 4 && minor >= 5;
|
|
45453
|
-
}
|
|
45454
|
-
function deferredAndReferencedNames(messages, normalizeName) {
|
|
45455
|
-
const deferred = new Set;
|
|
45456
|
-
const referenced = new Set;
|
|
45457
|
-
for (const message of messages) {
|
|
45458
|
-
const { role, content, addedToolNames } = message ?? {};
|
|
45459
|
-
if (role === "assistant" && Array.isArray(content)) {
|
|
45460
|
-
for (const block of content) {
|
|
45461
|
-
const { type, name } = block ?? {};
|
|
45462
|
-
if (type === "toolCall" && typeof name === "string")
|
|
45463
|
-
referenced.add(normalizeName(name));
|
|
45464
|
-
}
|
|
45465
|
-
} else if (role === "toolResult" && Array.isArray(addedToolNames)) {
|
|
45466
|
-
for (const name of addedToolNames) {
|
|
45467
|
-
if (typeof name !== "string")
|
|
45468
|
-
continue;
|
|
45469
|
-
const normalized = normalizeName(name);
|
|
45470
|
-
if (!referenced.has(normalized))
|
|
45471
|
-
deferred.add(normalized);
|
|
45472
|
-
}
|
|
45473
|
-
}
|
|
45474
|
-
}
|
|
45475
|
-
for (const name of deferred)
|
|
45476
|
-
referenced.add(name);
|
|
45477
|
-
return { deferred, referenced };
|
|
45478
|
-
}
|
|
45479
|
-
function calledToolNames(messages) {
|
|
45480
|
-
const names = new Set;
|
|
45481
|
-
for (const message of messages) {
|
|
45482
|
-
const content = message?.content;
|
|
45483
|
-
if (!Array.isArray(content))
|
|
45484
|
-
continue;
|
|
45485
|
-
for (const part of content) {
|
|
45486
|
-
const { type, name } = part ?? {};
|
|
45487
|
-
if (typeof type === "string" && type.toLowerCase().includes("tool") && typeof name === "string")
|
|
45488
|
-
names.add(name);
|
|
45489
|
-
}
|
|
45490
|
-
}
|
|
45491
|
-
return names;
|
|
45492
|
-
}
|
|
45493
|
-
function readPiRequestToolsFingerprint(pi, wireSchema, messages, route = {}) {
|
|
45494
|
-
try {
|
|
45495
|
-
if (typeof pi.getAllTools !== "function" || typeof pi.getActiveTools !== "function")
|
|
45496
|
-
return;
|
|
45497
|
-
const all = pi.getAllTools();
|
|
45498
|
-
const active = pi.getActiveTools();
|
|
45499
|
-
if (!Array.isArray(all) || !Array.isArray(active))
|
|
45500
|
-
return;
|
|
45501
|
-
const registered = new Map;
|
|
45502
|
-
for (const tool of all) {
|
|
45503
|
-
if (!tool || typeof tool !== "object")
|
|
45504
|
-
return;
|
|
45505
|
-
const { name } = tool;
|
|
45506
|
-
if (typeof name !== "string")
|
|
45507
|
-
return;
|
|
45508
|
-
registered.set(name, tool);
|
|
45509
|
-
}
|
|
45510
|
-
const model = route.model;
|
|
45511
|
-
const anthropicWriter = route.host === "pi" && wireSchema === undefined && model?.api === "anthropic-messages";
|
|
45512
|
-
const mode = wireSchema ? "omp" : anthropicWriter ? compatFlag(model, "supportsStrictTools") === true ? "anthropic-strict" : "anthropic" : "raw";
|
|
45513
|
-
const normalizeName = anthropicWriter && route.oauth === true ? claudeCodeName : identityName;
|
|
45514
|
-
const sent = new Map;
|
|
45515
|
-
for (const name of active) {
|
|
45516
|
-
if (typeof name !== "string")
|
|
45517
|
-
return;
|
|
45518
|
-
const tool = registered.get(name);
|
|
45519
|
-
if (!tool)
|
|
45520
|
-
continue;
|
|
45521
|
-
sent.set(normalizeName(name), tool);
|
|
45522
|
-
}
|
|
45523
|
-
const split = anthropicWriter && model && supportsToolReferences(model) ? deferredAndReferencedNames(messages, normalizeName) : undefined;
|
|
45524
|
-
const anyImmediate = [...sent.keys()].some((name) => !split?.deferred.has(name));
|
|
45525
|
-
const tools = [];
|
|
45526
|
-
for (const [name, tool] of sent) {
|
|
45527
|
-
const description = typeof tool.description === "string" ? tool.description : "";
|
|
45528
|
-
tools.push({
|
|
45529
|
-
name,
|
|
45530
|
-
description,
|
|
45531
|
-
schemaDigest: schemaDigest({
|
|
45532
|
-
name: tool.name,
|
|
45533
|
-
description,
|
|
45534
|
-
parameters: tool.parameters
|
|
45535
|
-
}, mode, wireSchema),
|
|
45536
|
-
deferLoading: split ? anyImmediate && split.deferred.has(name) : tool.defer_loading === true || tool.deferLoading === true
|
|
45537
|
-
});
|
|
45538
|
-
}
|
|
45539
|
-
return requestToolsFingerprint(tools, () => split?.referenced ?? calledToolNames(messages));
|
|
45540
|
-
} catch {
|
|
45541
|
-
return;
|
|
45542
|
-
}
|
|
45543
|
-
}
|
|
45544
|
-
|
|
45545
45605
|
// src/pi-tag-identity-repair.ts
|
|
45546
45606
|
var PI_TAG_IDENTITY_REPAIR_REASON = "tag_identity_repair";
|
|
45547
45607
|
var unreadableLedgerLogged = new Set;
|
|
@@ -49781,6 +49841,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
49781
49841
|
}
|
|
49782
49842
|
}));
|
|
49783
49843
|
assertCurrentPass();
|
|
49844
|
+
const historyHead = sessionMetaForUsage.isSubagent ? undefined : options.injection;
|
|
49784
49845
|
updateSessionProjectTracking(sessionId, projectIdentity, options.db, projectDirectory);
|
|
49785
49846
|
const lkgInputIdByRef = new Map;
|
|
49786
49847
|
for (const input of lkgPassSnapshot.inputs)
|
|
@@ -49831,17 +49892,17 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
49831
49892
|
}
|
|
49832
49893
|
}
|
|
49833
49894
|
const tMeta = performance.now();
|
|
49834
|
-
let piM0M1PassSnapshot =
|
|
49895
|
+
let piM0M1PassSnapshot = historyHead ? createPiM0M1PassSnapshot({
|
|
49835
49896
|
db: options.db,
|
|
49836
49897
|
sessionId,
|
|
49837
49898
|
compactionOff: options.compactionOff === true,
|
|
49838
49899
|
sessionMeta: sessionMetaForUsage
|
|
49839
49900
|
}) : undefined;
|
|
49840
49901
|
logTransformTiming(sessionId, "getOrCreateSessionMeta", tMeta);
|
|
49841
|
-
if (strictEntryIds && branchEntries &&
|
|
49902
|
+
if (strictEntryIds && branchEntries && historyHead && !options.compactionOff && stripMcOwnedPiCompactionSummary(event.messages, strictEntryIds, branchEntries)) {
|
|
49842
49903
|
logTransformTiming(sessionId, "mcCompactionSummarySuppression", tEntryBranch);
|
|
49843
49904
|
}
|
|
49844
|
-
if (strictEntryIds &&
|
|
49905
|
+
if (strictEntryIds && historyHead && !options.compactionOff) {
|
|
49845
49906
|
const removed = trimPiMessagesToCachedBoundary(options.db, sessionId, event.messages, strictEntryIds, piM0M1PassSnapshot);
|
|
49846
49907
|
if (removed > 0) {
|
|
49847
49908
|
logTransformTiming(sessionId, "cachedBoundaryEarlyTrim", tEntryBranch, `removed=${removed}`);
|
|
@@ -49903,7 +49964,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
49903
49964
|
clearPiInjectionTokenCountCache(sessionId);
|
|
49904
49965
|
sessionMetaForUsage.cachedM0Bytes = null;
|
|
49905
49966
|
sessionMetaForUsage.cachedM1Bytes = null;
|
|
49906
|
-
piM0M1PassSnapshot =
|
|
49967
|
+
piM0M1PassSnapshot = historyHead ? createPiM0M1PassSnapshot({
|
|
49907
49968
|
db: options.db,
|
|
49908
49969
|
sessionId,
|
|
49909
49970
|
compactionOff: options.compactionOff === true,
|
|
@@ -50127,7 +50188,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50127
50188
|
}
|
|
50128
50189
|
assertCurrentPass();
|
|
50129
50190
|
sessionMeta = getOrCreateSessionMeta(options.db, sessionId);
|
|
50130
|
-
piM0M1PassSnapshot =
|
|
50191
|
+
piM0M1PassSnapshot = historyHead ? createPiM0M1PassSnapshot({
|
|
50131
50192
|
db: options.db,
|
|
50132
50193
|
sessionId,
|
|
50133
50194
|
compactionOff: false,
|
|
@@ -50171,7 +50232,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50171
50232
|
recoveryArmed: emergencyRecoveryArmed || !!recovery.rebuildReason,
|
|
50172
50233
|
forceMaterialization,
|
|
50173
50234
|
imported: looksLikeImportedSession || usageInputTokens <= 0 && (isFirstContextPassForSession || lkgPassSnapshot?.replayFailure !== null),
|
|
50174
|
-
coldInjection: !!
|
|
50235
|
+
coldInjection: !!historyHead && !sessionMeta.cachedM0Bytes,
|
|
50175
50236
|
cacheBusting: isCacheBusting,
|
|
50176
50237
|
sessionId,
|
|
50177
50238
|
appendedMessages: lkgPassSnapshot?.pristineTail ?? event.messages.slice(-1),
|
|
@@ -50193,7 +50254,13 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50193
50254
|
}
|
|
50194
50255
|
maintainExecuteFloorMark(options.db, sessionId, promptId, usagePercentage < effectiveExecuteThresholdPercentage);
|
|
50195
50256
|
}
|
|
50257
|
+
const ctxReduceCallable = piCtxReduceCallable(pi, options.compactionOff === true, { db: options.db, sessionId });
|
|
50258
|
+
const servedCtxReduceCallable = options.compactionOff || budget.sideTurn ? ctxReduceCallable : readServedPiCtxReduceCallable(options.db, sessionId);
|
|
50259
|
+
if (!ctxReduceCallable && !budget.sideTurn)
|
|
50260
|
+
clearPiChannel1State(sessionId);
|
|
50196
50261
|
const pipelineArgs = {
|
|
50262
|
+
ctxReduceCallable,
|
|
50263
|
+
servedCtxReduceCallable,
|
|
50197
50264
|
providerOverflowRecovery: emergencyRecoveryArmed && historianStateForPass.emergencyRecoveryOrigin === "provider_overflow",
|
|
50198
50265
|
dropBranchEntries: branchEntries ?? undefined,
|
|
50199
50266
|
recoveryPrefix: recovery.prefix,
|
|
@@ -50218,9 +50285,9 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50218
50285
|
reclaimUsableWindow: windowGeometry?.usableSoft ?? usageContextLimit ?? 0,
|
|
50219
50286
|
heuristics: options.heuristics,
|
|
50220
50287
|
emergencyCeilingTokens,
|
|
50221
|
-
injection:
|
|
50222
|
-
...
|
|
50223
|
-
memoryEnabled:
|
|
50288
|
+
injection: historyHead ? {
|
|
50289
|
+
...historyHead,
|
|
50290
|
+
memoryEnabled: historyHead.memoryEnabled,
|
|
50224
50291
|
historyBudgetPolicyIdentity: historyBudgetPolicyIdentity(options.historian?.historyBudgetPercentage, options.historian?.executeThresholdPercentage, liveModelBySession.get(sessionId), options.historian?.executeThresholdTokens),
|
|
50225
50292
|
historyBudgetTokens: resolveHistoryBudgetTokensForPi({
|
|
50226
50293
|
historyBudgetPercentage: options.historian?.historyBudgetPercentage,
|
|
@@ -50241,7 +50308,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50241
50308
|
schedulerDeferReason,
|
|
50242
50309
|
forceMaterialization: forceMaterialization || isEmergency,
|
|
50243
50310
|
forceMaterializationPercentage,
|
|
50244
|
-
signedThinkingHold: requestToolsChange === null && resolvePiSignedThinkingHold({
|
|
50311
|
+
signedThinkingHold: requestToolsChange === null && ctxReduceCallable === servedCtxReduceCallable && resolvePiSignedThinkingHold({
|
|
50245
50312
|
sessionId,
|
|
50246
50313
|
db: options.db,
|
|
50247
50314
|
messages: event.messages,
|
|
@@ -50304,7 +50371,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50304
50371
|
if (!options.compactionOff)
|
|
50305
50372
|
assertPiTagSnapshotReady(options.db, sessionId);
|
|
50306
50373
|
let historianEvaluatedThisPass = false;
|
|
50307
|
-
const historian = options.historian;
|
|
50374
|
+
const historian = sessionMeta.isSubagent ? undefined : options.historian;
|
|
50308
50375
|
const scheduleHistorian = (result) => {
|
|
50309
50376
|
if (historianEvaluatedThisPass)
|
|
50310
50377
|
return;
|
|
@@ -50426,7 +50493,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50426
50493
|
const todoAnchorBefore = JSON.stringify(getPersistedTodoSyntheticAnchor(options.db, sessionId));
|
|
50427
50494
|
const tNoteNudges = performance.now();
|
|
50428
50495
|
try {
|
|
50429
|
-
if (!options.compactionOff) {
|
|
50496
|
+
if (!options.compactionOff && !sessionMeta.isSubagent) {
|
|
50430
50497
|
outputMessages = applyNoteNudges({
|
|
50431
50498
|
sessionId,
|
|
50432
50499
|
db: options.db,
|
|
@@ -50445,7 +50512,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50445
50512
|
logTransformTiming(sessionId, "noteNudges", tNoteNudges);
|
|
50446
50513
|
const tAutoSearch = performance.now();
|
|
50447
50514
|
budget.stage = "auto-search";
|
|
50448
|
-
if (options.autoSearch?.enabled && !options.compactionOff && result.prefixMutationAllowed && budget.remainingWork() > PI_CONTEXT_BUDGET.searchMs) {
|
|
50515
|
+
if (options.autoSearch?.enabled && !options.compactionOff && !sessionMeta.isSubagent && result.prefixMutationAllowed && budget.remainingWork() > PI_CONTEXT_BUDGET.searchMs) {
|
|
50449
50516
|
guardSqliteTransformPass2({
|
|
50450
50517
|
assert: budget.assert,
|
|
50451
50518
|
remainingMs: budget.remainingWork
|
|
@@ -50582,7 +50649,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50582
50649
|
const tChannelAccounting = performance.now();
|
|
50583
50650
|
try {
|
|
50584
50651
|
const sessionMetaForCh1 = sessionMeta;
|
|
50585
|
-
if (
|
|
50652
|
+
if (ctxReduceCallable) {
|
|
50586
50653
|
const { tags, protectedTagNumbers, pendingDropTagNumbers } = result.channelBaselineSnapshot;
|
|
50587
50654
|
const stableId = (message) => message && typeof message === "object" ? result.postCommitEntryIdByRef.get(message) : undefined;
|
|
50588
50655
|
const hygieneCalibration = sessionDecisionCalibration(options.db, sessionId);
|
|
@@ -50849,7 +50916,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50849
50916
|
upperEstimateOnly: !recoverUnknownUsage && fitCase === "upper-estimate-pressure",
|
|
50850
50917
|
forceSignedRebuildForFit: fitCase === "over-window-proof",
|
|
50851
50918
|
isCacheBusting: historyRefreshSessions.has(sessionId) || deferredHistoryRefreshSessions.has(sessionId),
|
|
50852
|
-
injectionPassSnapshot:
|
|
50919
|
+
injectionPassSnapshot: historyHead ? createPiM0M1PassSnapshot({
|
|
50853
50920
|
db: options.db,
|
|
50854
50921
|
sessionId,
|
|
50855
50922
|
compactionOff: false,
|
|
@@ -51006,6 +51073,8 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
51006
51073
|
sessionLog2(sessionId, "request tools release not recorded: the end strip order could not be written");
|
|
51007
51074
|
});
|
|
51008
51075
|
afterCapture(sessionId, "served system hash record", recordServedSystemHash);
|
|
51076
|
+
if (!budget.sideTurn && !options.compactionOff)
|
|
51077
|
+
afterCapture(sessionId, "ctx_reduce served record", () => recordServedPiCtxReduceCallable(options.db, sessionId, ctxReduceCallable));
|
|
51009
51078
|
return { messages: outputMessages };
|
|
51010
51079
|
} catch (err) {
|
|
51011
51080
|
if (budget.isCancelled(err))
|
|
@@ -52252,7 +52321,10 @@ async function runPipeline(args) {
|
|
|
52252
52321
|
return findLatestUserMessageIdPi(args.messages, ids)?.messageId ?? null;
|
|
52253
52322
|
})();
|
|
52254
52323
|
const alreadyRanHeuristicsThisTurn = currentTurnId !== null && lastHeuristicsTurnIdBySession.get(args.sessionId) === currentTurnId;
|
|
52255
|
-
const ctxReduceCallable =
|
|
52324
|
+
const ctxReduceCallable = args.ctxReduceCallable;
|
|
52325
|
+
const requestToolListChanged = args.ctxReduceCallable !== args.servedCtxReduceCallable;
|
|
52326
|
+
if (requestToolListChanged)
|
|
52327
|
+
sessionLog2(args.sessionId, `request tool list changed: ctx_reduce ${args.ctxReduceCallable ? "added; tag prefixes return" : "removed; tag prefixes stop"} on this rebuild`);
|
|
52256
52328
|
const canConsumeDeferredLate = args.schedulerDecision === "execute" || args.forceMaterialization === true || args.contextUsage.percentage >= forceMaterializationPercentage;
|
|
52257
52329
|
let deferredMaterializeEligible = canConsumeDeferredLate && deferredMaterializationSessions.has(args.sessionId) && !protectedSignedPrefix;
|
|
52258
52330
|
const executePressureEligible = args.schedulerDecision === "execute" || emergencyDropEligible;
|
|
@@ -52267,7 +52339,7 @@ async function runPipeline(args) {
|
|
|
52267
52339
|
const rideSignals = {
|
|
52268
52340
|
executeReclaim: false,
|
|
52269
52341
|
subagentExecute: args.sessionMeta.isSubagent && args.schedulerDecision === "execute",
|
|
52270
|
-
hardFold: foldBustsServedPrefixThisPass || systemPrefixChangedThisPass || firstRenderBust || isCacheBustingPass,
|
|
52342
|
+
hardFold: foldBustsServedPrefixThisPass || systemPrefixChangedThisPass || requestToolListChanged || firstRenderBust || isCacheBustingPass,
|
|
52271
52343
|
force: (args.forceMaterialization === true || emergencyDropEligible) && (args.contextUsage.percentage >= 95 || getEmergencyInputSample(args.db, args.sessionId) === 0),
|
|
52272
52344
|
explicitFlush: !protectedSignedPrefix && (args.userFlushOrigin === true || hasPendingMaterializationOrigin(pendingMaterializationSessions, args.sessionId, "user_flush")),
|
|
52273
52345
|
publishedHistory: !prefixPreflightContended && publishedM1RefreshedThisPass
|
|
@@ -52300,7 +52372,7 @@ async function runPipeline(args) {
|
|
|
52300
52372
|
onRejectedProjectOverride: (warning) => sessionLog2(args.sessionId, warning)
|
|
52301
52373
|
});
|
|
52302
52374
|
let protectionFloorResolution = resolveProtectionFloor();
|
|
52303
|
-
let shouldRunHeuristics = args.heuristics !== undefined && isCacheBustingPass && (rideSignals.publishedHistory || systemPrefixChangedThisPass || rideSignals.explicitFlush || args.forceMaterialization === true || hasPendingMaterializeSignal || deferredMaterializeEligible || foldBustsServedPrefixThisPass || firstRenderBust || args.recoveryRebuildReason !== undefined && isCacheBustingPass || rideSignals.subagentExecute || args.schedulerDecision === "execute" && !alreadyRanHeuristicsThisTurn);
|
|
52375
|
+
let shouldRunHeuristics = args.heuristics !== undefined && isCacheBustingPass && (rideSignals.publishedHistory || systemPrefixChangedThisPass || requestToolListChanged || rideSignals.explicitFlush || args.forceMaterialization === true || hasPendingMaterializeSignal || deferredMaterializeEligible || foldBustsServedPrefixThisPass || firstRenderBust || args.recoveryRebuildReason !== undefined && isCacheBustingPass || rideSignals.subagentExecute || args.schedulerDecision === "execute" && !alreadyRanHeuristicsThisTurn);
|
|
52304
52376
|
let unavoidableCarriedIdentityRebuild = false;
|
|
52305
52377
|
if (protectedSignedPrefix && readPiIdentityRebuilds(args.db, args.sessionId).length > 0) {
|
|
52306
52378
|
args.tryReplayHeldIdentityRebuild?.();
|
|
@@ -52814,7 +52886,7 @@ async function runPipeline(args) {
|
|
|
52814
52886
|
const tHeuristic = performance.now();
|
|
52815
52887
|
const providerOverflow = args.providerOverflowRecovery === true;
|
|
52816
52888
|
const recoveryCalibration = sessionDecisionCalibration(args.db, args.sessionId);
|
|
52817
|
-
const independentMutationBeforeHeuristics = pendingOpsDidMutate || systemPrefixChangedThisPass || foldBustsServedPrefixThisPass || identityRebuild || firstRenderBust;
|
|
52889
|
+
const independentMutationBeforeHeuristics = pendingOpsDidMutate || systemPrefixChangedThisPass || requestToolListChanged || foldBustsServedPrefixThisPass || identityRebuild || firstRenderBust;
|
|
52818
52890
|
if (args.forceMaterialization === true && independentMutationBeforeHeuristics && getEmergencyInputSample(args.db, args.sessionId) > 0) {
|
|
52819
52891
|
clearEmergencyDropSample(args.db, args.sessionId);
|
|
52820
52892
|
}
|
|
@@ -53717,6 +53789,7 @@ function clearContextHandlerSession(sessionId) {
|
|
|
53717
53789
|
dropServedRecord(sessionId, "session_cleared");
|
|
53718
53790
|
cancelPiTagSnapshotSession(sessionId);
|
|
53719
53791
|
lastServedSystemHashBySession.delete(sessionId);
|
|
53792
|
+
clearPiCtxReduceCallableSession(sessionId);
|
|
53720
53793
|
clearPiHistoryBoundaryRepairSession(sessionId);
|
|
53721
53794
|
clearPiUpperReclaimSession(sessionId);
|
|
53722
53795
|
invalidateTrueRawTokenCache({ sessionId, reason: "pi.branch.changed" });
|
|
@@ -56836,6 +56909,34 @@ function schedulePiAssistantIndexOnMessageEnd(db, sessionId, endedMessage, sessi
|
|
|
56836
56909
|
});
|
|
56837
56910
|
}
|
|
56838
56911
|
|
|
56912
|
+
// src/pi-agent-identity.ts
|
|
56913
|
+
var checkedSessions = new BoundedSessionMap(1000);
|
|
56914
|
+
function readAgentKind(ctx) {
|
|
56915
|
+
try {
|
|
56916
|
+
return ctx?.agent?.kind;
|
|
56917
|
+
} catch {
|
|
56918
|
+
return;
|
|
56919
|
+
}
|
|
56920
|
+
}
|
|
56921
|
+
function recordPiSpawnedSession(db, sessionId, ctx) {
|
|
56922
|
+
if (checkedSessions.has(sessionId))
|
|
56923
|
+
return;
|
|
56924
|
+
checkedSessions.set(sessionId, true);
|
|
56925
|
+
if (readAgentKind(ctx) !== "sub")
|
|
56926
|
+
return;
|
|
56927
|
+
if (getOrCreateSessionMeta(db, sessionId).isSubagent)
|
|
56928
|
+
return;
|
|
56929
|
+
if (hasCompartments(db, sessionId)) {
|
|
56930
|
+
sessionLog2(sessionId, "Oh My Pi spawned session (agent kind sub) has compartments from its source session: kept primary");
|
|
56931
|
+
return;
|
|
56932
|
+
}
|
|
56933
|
+
updateSessionMeta(db, sessionId, { isSubagent: true });
|
|
56934
|
+
sessionLog2(sessionId, "Oh My Pi spawned session (agent kind sub): recorded as a subagent");
|
|
56935
|
+
}
|
|
56936
|
+
function hasCompartments(db, sessionId) {
|
|
56937
|
+
return db.prepare("SELECT 1 AS present FROM compartments WHERE session_id = ? LIMIT 1").get(sessionId) != null;
|
|
56938
|
+
}
|
|
56939
|
+
|
|
56839
56940
|
// ../plugin/src/plugin/boot-deadline.ts
|
|
56840
56941
|
async function runBootPhaseWithDeadline(phase, operation, timeoutMs, report, deadlineDescription = `its ${timeoutMs}ms deadline`) {
|
|
56841
56942
|
const startedAt = performance.now();
|
|
@@ -58169,6 +58270,8 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
|
|
|
58169
58270
|
onInherited: (sessionId) => prewarmPiTagSnapshot(db, sessionId, "pass")
|
|
58170
58271
|
});
|
|
58171
58272
|
const sessionId = resolveSessionId(ctx);
|
|
58273
|
+
if (sessionId)
|
|
58274
|
+
recordPiSpawnedSession(db, sessionId, ctx);
|
|
58172
58275
|
if (!piMarkerRehydrationLogged && pendingPiMarkerSessions.length > 0 && sessionId) {
|
|
58173
58276
|
log2(formatPiMarkerRehydrationLine(pendingPiMarkerSessions, sessionId));
|
|
58174
58277
|
piMarkerRehydrationLogged = true;
|
|
@@ -58431,6 +58534,7 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
|
|
|
58431
58534
|
}
|
|
58432
58535
|
}
|
|
58433
58536
|
if (sessionId) {
|
|
58537
|
+
recordPiSpawnedSession(db, sessionId, ctx);
|
|
58434
58538
|
trackSessionForProject(currentProject.projectIdentity, sessionId);
|
|
58435
58539
|
try {
|
|
58436
58540
|
const smForDrain = sm;
|
|
@@ -58458,7 +58562,7 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
|
|
|
58458
58562
|
memoryEnabled: effectiveConfig.memory.enabled,
|
|
58459
58563
|
includeGuidance: true,
|
|
58460
58564
|
protectedTags: effectiveConfig.protected_tags,
|
|
58461
|
-
ctxReduceCallable:
|
|
58565
|
+
ctxReduceCallable: piCtxReduceCallable(pi, compactionOff, sessionId ? { db, sessionId } : undefined),
|
|
58462
58566
|
dreamerEnabled: effectiveProjectDeps.dreamerEnabled,
|
|
58463
58567
|
smartNotesEnabled: config.smart_notes.enabled,
|
|
58464
58568
|
temporalAwarenessEnabled: effectiveConfig.temporal_awareness ?? false,
|
|
@@ -58513,8 +58617,12 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
|
|
|
58513
58617
|
const lastAssistant = Array.isArray(msgs) ? [...msgs].reverse().find((m) => m?.role === "assistant") : undefined;
|
|
58514
58618
|
if (lastAssistant?.stopReason === "stop") {
|
|
58515
58619
|
const sessionId = ctx.sessionManager?.getSessionId?.();
|
|
58516
|
-
if (sessionId && db
|
|
58517
|
-
|
|
58620
|
+
if (sessionId && db) {
|
|
58621
|
+
if (piCtxReduceCallable(pi, compactionOff, { db, sessionId }))
|
|
58622
|
+
maybeDeliverChannel2Pi(pi, db, sessionId);
|
|
58623
|
+
else
|
|
58624
|
+
clearPiChannel1State(sessionId);
|
|
58625
|
+
}
|
|
58518
58626
|
}
|
|
58519
58627
|
} catch (err) {
|
|
58520
58628
|
log2(`agent_end: channel2 delivery skipped: ${String(err)}`);
|
|
@@ -58568,8 +58676,10 @@ async function startPiMagicContextRuntime(pi, database, dbPath) {
|
|
|
58568
58676
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
58569
58677
|
if (typeof sessionId !== "string" || sessionId.length === 0)
|
|
58570
58678
|
return;
|
|
58571
|
-
if (compactionOff)
|
|
58679
|
+
if (!piCtxReduceCallable(pi, compactionOff, db ? { db, sessionId } : undefined)) {
|
|
58680
|
+
clearPiChannel1State(sessionId);
|
|
58572
58681
|
return;
|
|
58682
|
+
}
|
|
58573
58683
|
const block = maybeChannel1ReminderForToolResult({
|
|
58574
58684
|
db,
|
|
58575
58685
|
sessionId,
|