@cortexkit/pi-magic-context 0.49.81 → 0.49.83
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 +3 -3
- package/dist/chunk-embedding-write-worker.js +4 -4
- package/dist/{embedding-backfill-arvg2p6f.js → embedding-backfill-yh10bmx5.js} +4 -4
- package/dist/{index-0bmsfzqf.js → index-3g1wy4z9.js} +2 -2
- package/dist/{index-pz85rpzf.js → index-47g3pgzk.js} +10 -5
- package/dist/{index-q1yc6bs0.js → index-7thk2cwt.js} +15 -4
- package/dist/{index-gavj3e6h.js → index-e0zdn1p3.js} +1 -1
- package/dist/{index-79xfn84y.js → index-gdy08gn6.js} +1 -1
- package/dist/{index-453s1hj6.js → index-hna2sxy8.js} +1 -1
- package/dist/{index-5tkveh4p.js → index-k8xz22jc.js} +1 -1
- package/dist/{index-k7a8x7ba.js → index-nmmge3j6.js} +1 -1
- package/dist/{index-nvh6d3bz.js → index-qky62xze.js} +34 -2
- package/dist/{index-6crdakkm.js → index-qz43gkqe.js} +31 -12
- package/dist/{index-hnvq96j6.js → index-wtqv3vha.js} +4 -4
- package/dist/{index-0th11rhf.js → index-xz5b9t4g.js} +2 -2
- package/dist/{index-5009ew3c.js → index-y573dt51.js} +21 -20
- package/dist/index.js +372 -217
- package/dist/migration-worker.js +3 -3
- package/dist/{project-embedding-registry-zgzq9ehw.js → project-embedding-registry-3sss39rx.js} +3 -3
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{render-fhrce5g6.js → render-9xgp0jka.js} +6 -6
- package/dist/{rpc-notifications-gm1mdpwh.js → rpc-notifications-889zvhn2.js} +3 -1
- package/dist/{search-archive-661vc3fb.js → search-archive-wr38qtkw.js} +1 -1
- package/dist/{search-vw6ps2me.js → search-dh4ryftv.js} +7 -7
- package/dist/{store-reader-mmfw2h48.js → store-reader-8j41p18c.js} +1 -1
- package/dist/{store-e9ve3qzt.js → store-xg9ez6jn.js} +1 -1
- package/dist/subagent-entry.js +12 -12
- package/dist/tag-snapshot-worker-pi.js +3 -3
- package/dist/{v2-archive-reader-zndhp4c4.js → v2-archive-reader-8m9mw6sv.js} +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -166,7 +166,7 @@ import {
|
|
|
166
166
|
registerTodoStateLifecycle,
|
|
167
167
|
syncCtxMemoryToolEnabled,
|
|
168
168
|
registerMagicContextTools
|
|
169
|
-
} from "./index-
|
|
169
|
+
} from "./index-y573dt51.js";
|
|
170
170
|
import"./index-4knyh1kt.js";
|
|
171
171
|
import {
|
|
172
172
|
canonicalModelIdentity,
|
|
@@ -198,6 +198,7 @@ import {
|
|
|
198
198
|
pruneMissingProjectIdentities,
|
|
199
199
|
setHomeProjectPermission,
|
|
200
200
|
ProjectIdentityError,
|
|
201
|
+
directoryFallback,
|
|
201
202
|
resolveProjectIdentityStrict,
|
|
202
203
|
isUserHomeDirectory,
|
|
203
204
|
resolveProjectIdentity,
|
|
@@ -205,7 +206,7 @@ import {
|
|
|
205
206
|
resolveProjectIdentityForSession,
|
|
206
207
|
beginBootQuietPeriod,
|
|
207
208
|
scheduleAfterBootQuiet
|
|
208
|
-
} from "./index-
|
|
209
|
+
} from "./index-hna2sxy8.js";
|
|
209
210
|
import {
|
|
210
211
|
detectThinkingBindingMismatch,
|
|
211
212
|
detectLatestTurnThinkingMismatch,
|
|
@@ -469,7 +470,7 @@ import {
|
|
|
469
470
|
openCurrentDatabase,
|
|
470
471
|
openDatabaseAsync,
|
|
471
472
|
closeDatabase
|
|
472
|
-
} from "./index-
|
|
473
|
+
} from "./index-xz5b9t4g.js";
|
|
473
474
|
import {
|
|
474
475
|
LkgRecoveryFenceError,
|
|
475
476
|
clearLkgFenceProcessState,
|
|
@@ -599,7 +600,7 @@ import {
|
|
|
599
600
|
getSourceContents,
|
|
600
601
|
recordSubagentInvocation,
|
|
601
602
|
getLatestHistorianInvocationId
|
|
602
|
-
} from "./index-
|
|
603
|
+
} from "./index-qz43gkqe.js";
|
|
603
604
|
import {
|
|
604
605
|
resolveOpenCodeDbPath,
|
|
605
606
|
assertOpenCodeStoreGeneration,
|
|
@@ -666,7 +667,7 @@ import {
|
|
|
666
667
|
getLegacyProtectedTailStartOrdinal2,
|
|
667
668
|
readSessionChunk2
|
|
668
669
|
} from "./index-hpbdnbtf.js";
|
|
669
|
-
import"./index-
|
|
670
|
+
import"./index-qky62xze.js";
|
|
670
671
|
import {
|
|
671
672
|
formatSynapseLaneDescriptor
|
|
672
673
|
} from "./index-5rcjs14a.js";
|
|
@@ -689,7 +690,7 @@ import {
|
|
|
689
690
|
markGitSweepSuccessAndRelease,
|
|
690
691
|
parkGitSweepNonIndexable,
|
|
691
692
|
releaseGitSweepLease
|
|
692
|
-
} from "./index-
|
|
693
|
+
} from "./index-gdy08gn6.js";
|
|
693
694
|
import {
|
|
694
695
|
embedPauseBySession,
|
|
695
696
|
embedRunStateBySession,
|
|
@@ -720,7 +721,7 @@ import {
|
|
|
720
721
|
expandWorkspaceIdentitySetWithAliases,
|
|
721
722
|
sourceNameForMemory,
|
|
722
723
|
computeWorkspaceEpochFingerprint
|
|
723
|
-
} from "./index-
|
|
724
|
+
} from "./index-e0zdn1p3.js";
|
|
724
725
|
import {
|
|
725
726
|
configureContextDatabasePragmas2
|
|
726
727
|
} from "./index-fapenpch.js";
|
|
@@ -745,7 +746,7 @@ import {
|
|
|
745
746
|
createPrimer,
|
|
746
747
|
updatePrimerSupport,
|
|
747
748
|
updatePrimerAnswer
|
|
748
|
-
} from "./index-
|
|
749
|
+
} from "./index-nmmge3j6.js";
|
|
749
750
|
import {
|
|
750
751
|
setEmbeddingSessionBusy2,
|
|
751
752
|
isEmbeddingHostBusy2
|
|
@@ -769,6 +770,7 @@ import {
|
|
|
769
770
|
updateMemoryVerification2,
|
|
770
771
|
setMemoryClassification2,
|
|
771
772
|
archiveMemory2,
|
|
773
|
+
getMemoryCount2,
|
|
772
774
|
getMemoryCountsByStatus2
|
|
773
775
|
} from "./index-29nw7n1r.js";
|
|
774
776
|
import {
|
|
@@ -776,7 +778,7 @@ import {
|
|
|
776
778
|
} from "./index-yhzhdp3m.js";
|
|
777
779
|
import {
|
|
778
780
|
pushNotification2
|
|
779
|
-
} from "./index-
|
|
781
|
+
} from "./index-7thk2cwt.js";
|
|
780
782
|
import {
|
|
781
783
|
getCachedLocalEmbeddingPooling
|
|
782
784
|
} from "./index-txcs0vnj.js";
|
|
@@ -797,7 +799,7 @@ import {
|
|
|
797
799
|
embedSessionCompartmentChunks2,
|
|
798
800
|
getEmbeddingCoverageStatus2,
|
|
799
801
|
getAutoEmbeddingSessionCoverage2
|
|
800
|
-
} from "./index-
|
|
802
|
+
} from "./index-3g1wy4z9.js";
|
|
801
803
|
import {
|
|
802
804
|
USER_FACING_FAILURES,
|
|
803
805
|
renderUserFacingFailure,
|
|
@@ -832,8 +834,8 @@ import {
|
|
|
832
834
|
scheduleClearAndReindex,
|
|
833
835
|
clearSessionTracking,
|
|
834
836
|
createAutoSearchDiagnostics
|
|
835
|
-
} from "./index-
|
|
836
|
-
import"./index-
|
|
837
|
+
} from "./index-47g3pgzk.js";
|
|
838
|
+
import"./index-k8xz22jc.js";
|
|
837
839
|
import"./index-3s39a1md.js";
|
|
838
840
|
import {
|
|
839
841
|
DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
|
|
@@ -866,7 +868,7 @@ import {
|
|
|
866
868
|
} from "./index-pdrberjp.js";
|
|
867
869
|
import"./index-71rg8j43.js";
|
|
868
870
|
import"./index-8d2z6503.js";
|
|
869
|
-
import"./index-
|
|
871
|
+
import"./index-wtqv3vha.js";
|
|
870
872
|
import"./index-fvfq9gva.js";
|
|
871
873
|
import {
|
|
872
874
|
__toESM
|
|
@@ -915,6 +917,7 @@ var CANONICAL_DREAM_TASKS = [
|
|
|
915
917
|
"promote-primers",
|
|
916
918
|
"refresh-primers"
|
|
917
919
|
];
|
|
920
|
+
var MIN_POOL_TO_CLASSIFY = 10;
|
|
918
921
|
function availableDreamTasks(smartNotesEnabled = true) {
|
|
919
922
|
return CANONICAL_DREAM_TASKS.filter((task) => smartNotesEnabled || task !== "evaluate-smart-notes");
|
|
920
923
|
}
|
|
@@ -3619,7 +3622,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3619
3622
|
// package.json
|
|
3620
3623
|
var package_default = {
|
|
3621
3624
|
name: "@cortexkit/pi-magic-context",
|
|
3622
|
-
version: "0.49.
|
|
3625
|
+
version: "0.49.83",
|
|
3623
3626
|
type: "module",
|
|
3624
3627
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3625
3628
|
main: "dist/index.js",
|
|
@@ -4359,6 +4362,91 @@ function backoffMs(failureCount) {
|
|
|
4359
4362
|
return minutes * 60 * 1000;
|
|
4360
4363
|
}
|
|
4361
4364
|
|
|
4365
|
+
// ../plugin/src/features/magic-context/dreamer/map-memories-retry.ts
|
|
4366
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
4367
|
+
|
|
4368
|
+
// ../plugin/src/features/magic-context/dreamer/storage-dream-state.ts
|
|
4369
|
+
var getDreamStateStatements = new WeakMap;
|
|
4370
|
+
var setDreamStateStatements = new WeakMap;
|
|
4371
|
+
var deleteDreamStateStatements = new WeakMap;
|
|
4372
|
+
function getGetDreamStateStatement(db) {
|
|
4373
|
+
let stmt = getDreamStateStatements.get(db);
|
|
4374
|
+
if (!stmt) {
|
|
4375
|
+
stmt = db.prepare("SELECT value FROM dream_state WHERE key = ?");
|
|
4376
|
+
getDreamStateStatements.set(db, stmt);
|
|
4377
|
+
}
|
|
4378
|
+
return stmt;
|
|
4379
|
+
}
|
|
4380
|
+
function getSetDreamStateStatement(db) {
|
|
4381
|
+
let stmt = setDreamStateStatements.get(db);
|
|
4382
|
+
if (!stmt) {
|
|
4383
|
+
stmt = db.prepare("INSERT INTO dream_state (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value");
|
|
4384
|
+
setDreamStateStatements.set(db, stmt);
|
|
4385
|
+
}
|
|
4386
|
+
return stmt;
|
|
4387
|
+
}
|
|
4388
|
+
function getDeleteDreamStateStatement(db) {
|
|
4389
|
+
let stmt = deleteDreamStateStatements.get(db);
|
|
4390
|
+
if (!stmt) {
|
|
4391
|
+
stmt = db.prepare("DELETE FROM dream_state WHERE key = ?");
|
|
4392
|
+
deleteDreamStateStatements.set(db, stmt);
|
|
4393
|
+
}
|
|
4394
|
+
return stmt;
|
|
4395
|
+
}
|
|
4396
|
+
function getDreamState(db, key) {
|
|
4397
|
+
const row = getGetDreamStateStatement(db).get(key);
|
|
4398
|
+
return typeof row?.value === "string" ? row.value : null;
|
|
4399
|
+
}
|
|
4400
|
+
function setDreamState(db, key, value) {
|
|
4401
|
+
getSetDreamStateStatement(db).run(key, value);
|
|
4402
|
+
}
|
|
4403
|
+
function deleteDreamState(db, key) {
|
|
4404
|
+
getDeleteDreamStateStatement(db).run(key);
|
|
4405
|
+
}
|
|
4406
|
+
|
|
4407
|
+
// ../plugin/src/features/magic-context/dreamer/map-memories-retry.ts
|
|
4408
|
+
function mapMemoryRetryKey(project) {
|
|
4409
|
+
return `map-memories:retry:${project}`;
|
|
4410
|
+
}
|
|
4411
|
+
function readMapMemoryRetries(db, project) {
|
|
4412
|
+
try {
|
|
4413
|
+
const parsed = JSON.parse(getDreamState(db, mapMemoryRetryKey(project)) ?? "{}");
|
|
4414
|
+
if (!isRecord(parsed))
|
|
4415
|
+
return {};
|
|
4416
|
+
const retries = {};
|
|
4417
|
+
for (const [id, value] of Object.entries(parsed)) {
|
|
4418
|
+
if (isRecord(value) && typeof value.content === "string" && typeof value.failures === "number" && typeof value.deferUntil === "number") {
|
|
4419
|
+
retries[id] = {
|
|
4420
|
+
content: value.content,
|
|
4421
|
+
failures: value.failures,
|
|
4422
|
+
deferUntil: value.deferUntil
|
|
4423
|
+
};
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
return retries;
|
|
4427
|
+
} catch {
|
|
4428
|
+
return {};
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4431
|
+
function contentKey(memory) {
|
|
4432
|
+
return createHash3("sha256").update(`${memory.category}
|
|
4433
|
+
${memory.content}`).digest("hex");
|
|
4434
|
+
}
|
|
4435
|
+
function isMapMemoryDeferred(memory, retries, now = Date.now()) {
|
|
4436
|
+
const retry = retries[memory.id];
|
|
4437
|
+
return !!retry && retry.deferUntil > now && retry.content === contentKey(memory);
|
|
4438
|
+
}
|
|
4439
|
+
function nextMapMemoryRetry(memory, prior) {
|
|
4440
|
+
const content = contentKey(memory);
|
|
4441
|
+
const failures = (prior?.content === content ? prior.failures : 0) + 1;
|
|
4442
|
+
const maxWaitHours = 7 * 24;
|
|
4443
|
+
return {
|
|
4444
|
+
content,
|
|
4445
|
+
failures,
|
|
4446
|
+
deferUntil: failures < 2 ? 0 : Date.now() + Math.min(maxWaitHours, 2 ** (failures - 2)) * 3600000
|
|
4447
|
+
};
|
|
4448
|
+
}
|
|
4449
|
+
|
|
4362
4450
|
// ../plugin/src/features/magic-context/dreamer/task-gates.ts
|
|
4363
4451
|
function countActiveMemories(db, projectPath) {
|
|
4364
4452
|
const row = db.prepare("SELECT COUNT(*) AS cnt FROM memories WHERE project_path = ? AND status IN ('active','permanent')").get(projectPath);
|
|
@@ -4375,16 +4463,24 @@ function countLiveMemories(db, projectPath, options = {}) {
|
|
|
4375
4463
|
const row = options.category ? db.prepare(`${sql} AND category = ?`).get(projectPath, Date.now(), options.category) : db.prepare(sql).get(projectPath, Date.now());
|
|
4376
4464
|
return row?.cnt ?? 0;
|
|
4377
4465
|
}
|
|
4466
|
+
var UNMAPPED_LIVE_MEMORIES_SQL = `FROM memories m
|
|
4467
|
+
WHERE m.project_path = ?
|
|
4468
|
+
AND m.status IN ('active','permanent')
|
|
4469
|
+
AND (m.expires_at IS NULL OR m.expires_at > ?)
|
|
4470
|
+
AND NOT EXISTS (SELECT 1 FROM memory_verifications v WHERE v.memory_id = m.id)`;
|
|
4378
4471
|
function countUnmappedActiveMemories(db, projectPath) {
|
|
4379
|
-
const
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4472
|
+
const now = Date.now();
|
|
4473
|
+
const row = db.prepare(`SELECT COUNT(*) AS cnt ${UNMAPPED_LIVE_MEMORIES_SQL}`).get(projectPath, now);
|
|
4474
|
+
const total = row?.cnt ?? 0;
|
|
4475
|
+
if (total === 0)
|
|
4476
|
+
return 0;
|
|
4477
|
+
const retries = readMapMemoryRetries(db, projectPath);
|
|
4478
|
+
const waitingIds = Object.entries(retries).filter(([, retry]) => retry.deferUntil > now).map(([id]) => id);
|
|
4479
|
+
if (waitingIds.length === 0)
|
|
4480
|
+
return total;
|
|
4481
|
+
const waiting = db.prepare(`SELECT m.id, m.category, m.content ${UNMAPPED_LIVE_MEMORIES_SQL}
|
|
4482
|
+
AND m.id IN (SELECT CAST(value AS INTEGER) FROM json_each(?))`).all(projectPath, now, JSON.stringify(waitingIds));
|
|
4483
|
+
return total - waiting.filter((memory) => isMapMemoryDeferred(memory, retries, now)).length;
|
|
4388
4484
|
}
|
|
4389
4485
|
function countCompartmentsSince(db, projectPath, since) {
|
|
4390
4486
|
const row = db.prepare(`SELECT COUNT(*) AS cnt
|
|
@@ -4567,7 +4663,7 @@ function getDreamTaskBacklog(db, projectPath, task, options = {}) {
|
|
|
4567
4663
|
case "classify-memories": {
|
|
4568
4664
|
const total = countLiveMemories(db, projectPath);
|
|
4569
4665
|
return {
|
|
4570
|
-
pending: countLiveMemories(db, projectPath, { unclassifiedOnly: true }),
|
|
4666
|
+
pending: total >= MIN_POOL_TO_CLASSIFY ? countLiveMemories(db, projectPath, { unclassifiedOnly: true }) : 0,
|
|
4571
4667
|
total
|
|
4572
4668
|
};
|
|
4573
4669
|
}
|
|
@@ -4673,6 +4769,9 @@ function getDreamTaskBacklogs(db, projectPath, tasks = CANONICAL_DREAM_TASKS, op
|
|
|
4673
4769
|
cache.eligibleProjects.clear();
|
|
4674
4770
|
cache.eligibleProjects.set(projectPath, eligible);
|
|
4675
4771
|
}
|
|
4772
|
+
if (eligible && tasks.includes("map-memories")) {
|
|
4773
|
+
eligible = !Object.values(readMapMemoryRetries(db, projectPath)).some(({ deferUntil }) => deferUntil > 0);
|
|
4774
|
+
}
|
|
4676
4775
|
const optionKey = (value) => value === undefined ? "omitted" : value === null ? "null" : `number:${value}`;
|
|
4677
4776
|
const key = JSON.stringify([
|
|
4678
4777
|
getHarness2(),
|
|
@@ -4708,7 +4807,7 @@ function evaluateTaskGate(task, ctx) {
|
|
|
4708
4807
|
case "compress-cues":
|
|
4709
4808
|
return countLiveMemories(db, project) > 0;
|
|
4710
4809
|
case "classify-memories":
|
|
4711
|
-
return countLiveMemories(db, project)
|
|
4810
|
+
return countLiveMemories(db, project) >= MIN_POOL_TO_CLASSIFY;
|
|
4712
4811
|
case "retrospective":
|
|
4713
4812
|
return countProjectSessionsSince(db, project, ctx.retrospectiveWatermarkMs ?? null) > 0;
|
|
4714
4813
|
case "maintain-docs":
|
|
@@ -4765,7 +4864,7 @@ function openOpenCodeDb() {
|
|
|
4765
4864
|
}
|
|
4766
4865
|
|
|
4767
4866
|
// ../plugin/src/features/magic-context/dreamer/task-executor.ts
|
|
4768
|
-
import { createHash as
|
|
4867
|
+
import { createHash as createHash12 } from "node:crypto";
|
|
4769
4868
|
import { existsSync as existsSync9, readFileSync as readFileSync8 } from "node:fs";
|
|
4770
4869
|
|
|
4771
4870
|
// ../plugin/src/agents/dreamer.ts
|
|
@@ -4904,7 +5003,7 @@ class HiddenCompletionRefusal extends Error {
|
|
|
4904
5003
|
}
|
|
4905
5004
|
}
|
|
4906
5005
|
// ../plugin/src/features/magic-context/dreamer/provider-output-failure.ts
|
|
4907
|
-
import { createHash as
|
|
5006
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
4908
5007
|
var MAX_NEAR_ZERO_OUTPUT_TOKENS = 32;
|
|
4909
5008
|
|
|
4910
5009
|
class DreamerProviderOutputFailureError extends Error {
|
|
@@ -4966,7 +5065,7 @@ function providerOutputFailureFromInvalidManifest(messages, responseText) {
|
|
|
4966
5065
|
return null;
|
|
4967
5066
|
if (!isAccountPoolQuotaNotice(responseText) && completion.outputTokens > MAX_NEAR_ZERO_OUTPUT_TOKENS)
|
|
4968
5067
|
return null;
|
|
4969
|
-
const fingerprint =
|
|
5068
|
+
const fingerprint = createHash4("sha256").update(normalized).digest("hex").slice(0, 16);
|
|
4970
5069
|
return new DreamerProviderOutputFailureError(fingerprint, completion.outputTokens, completion.reasoningTokens, responseText);
|
|
4971
5070
|
}
|
|
4972
5071
|
|
|
@@ -6445,7 +6544,7 @@ function parseFields(json) {
|
|
|
6445
6544
|
}
|
|
6446
6545
|
|
|
6447
6546
|
// ../plugin/src/features/magic-context/mural/compress-cues.ts
|
|
6448
|
-
import { createHash as
|
|
6547
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
6449
6548
|
|
|
6450
6549
|
// ../plugin/src/hooks/magic-context/compartment-runner-historian.ts
|
|
6451
6550
|
import { mkdirSync, unlinkSync as unlinkSync2, writeFileSync } from "node:fs";
|
|
@@ -10473,45 +10572,6 @@ function sanitizeDumpName(value) {
|
|
|
10473
10572
|
return value.replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
10474
10573
|
}
|
|
10475
10574
|
|
|
10476
|
-
// ../plugin/src/features/magic-context/dreamer/storage-dream-state.ts
|
|
10477
|
-
var getDreamStateStatements = new WeakMap;
|
|
10478
|
-
var setDreamStateStatements = new WeakMap;
|
|
10479
|
-
var deleteDreamStateStatements = new WeakMap;
|
|
10480
|
-
function getGetDreamStateStatement(db) {
|
|
10481
|
-
let stmt = getDreamStateStatements.get(db);
|
|
10482
|
-
if (!stmt) {
|
|
10483
|
-
stmt = db.prepare("SELECT value FROM dream_state WHERE key = ?");
|
|
10484
|
-
getDreamStateStatements.set(db, stmt);
|
|
10485
|
-
}
|
|
10486
|
-
return stmt;
|
|
10487
|
-
}
|
|
10488
|
-
function getSetDreamStateStatement(db) {
|
|
10489
|
-
let stmt = setDreamStateStatements.get(db);
|
|
10490
|
-
if (!stmt) {
|
|
10491
|
-
stmt = db.prepare("INSERT INTO dream_state (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value");
|
|
10492
|
-
setDreamStateStatements.set(db, stmt);
|
|
10493
|
-
}
|
|
10494
|
-
return stmt;
|
|
10495
|
-
}
|
|
10496
|
-
function getDeleteDreamStateStatement(db) {
|
|
10497
|
-
let stmt = deleteDreamStateStatements.get(db);
|
|
10498
|
-
if (!stmt) {
|
|
10499
|
-
stmt = db.prepare("DELETE FROM dream_state WHERE key = ?");
|
|
10500
|
-
deleteDreamStateStatements.set(db, stmt);
|
|
10501
|
-
}
|
|
10502
|
-
return stmt;
|
|
10503
|
-
}
|
|
10504
|
-
function getDreamState(db, key) {
|
|
10505
|
-
const row = getGetDreamStateStatement(db).get(key);
|
|
10506
|
-
return typeof row?.value === "string" ? row.value : null;
|
|
10507
|
-
}
|
|
10508
|
-
function setDreamState(db, key, value) {
|
|
10509
|
-
getSetDreamStateStatement(db).run(key, value);
|
|
10510
|
-
}
|
|
10511
|
-
function deleteDreamState(db, key) {
|
|
10512
|
-
getDeleteDreamStateStatement(db).run(key);
|
|
10513
|
-
}
|
|
10514
|
-
|
|
10515
10575
|
// ../plugin/src/features/magic-context/dreamer/lease.ts
|
|
10516
10576
|
var LEASE_DURATION_MS = 2 * 60 * 1000;
|
|
10517
10577
|
var DREAMING_LEASE_KEY = "dreaming";
|
|
@@ -11216,7 +11276,7 @@ async function applyCuesThroughModule(args, chunk, manifestText, signal) {
|
|
|
11216
11276
|
log2(`[dreamer] compress-cues: skipped cue for memory ${entry.id} (${failure.reason}; rejection ${rejectionCount}/${CUE_REJECTION_LATCH_THRESHOLD})`);
|
|
11217
11277
|
}
|
|
11218
11278
|
}
|
|
11219
|
-
const commandId = `mural-cues:${route.moduleCommandId}:${
|
|
11279
|
+
const commandId = `mural-cues:${route.moduleCommandId}:${createHash5("sha256").update(chunk.map((candidate) => candidate.memory.id).join(",")).digest("hex").slice(0, 24)}`;
|
|
11220
11280
|
let response;
|
|
11221
11281
|
try {
|
|
11222
11282
|
response = await route.moduleClient.call({
|
|
@@ -11833,7 +11893,7 @@ function applyReviewVerdict(args, leaseKey, parsed, result) {
|
|
|
11833
11893
|
}
|
|
11834
11894
|
|
|
11835
11895
|
// ../plugin/src/features/magic-context/dreamer/classify.ts
|
|
11836
|
-
import { createHash as
|
|
11896
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
11837
11897
|
|
|
11838
11898
|
// ../plugin/src/plugin/rust-tool-backends.ts
|
|
11839
11899
|
function isRustAuthorityDrainingError(error) {
|
|
@@ -12006,7 +12066,6 @@ async function readFailedChildMessages(client, sessionId, directory) {
|
|
|
12006
12066
|
}
|
|
12007
12067
|
|
|
12008
12068
|
// ../plugin/src/features/magic-context/dreamer/classify.ts
|
|
12009
|
-
var MIN_POOL_TO_CLASSIFY = 10;
|
|
12010
12069
|
var FULL_POOL_CEILING = 100;
|
|
12011
12070
|
var STAGE3_ANCHOR_COUNT = 30;
|
|
12012
12071
|
var CLASSIFY_CHUNK_SIZE = 100;
|
|
@@ -12271,7 +12330,7 @@ async function runClassifyThroughModule(args, chunk, anchors, signal, runOnHost)
|
|
|
12271
12330
|
if (entry.qualifier)
|
|
12272
12331
|
modelVariants[entry.model] = entry.qualifier;
|
|
12273
12332
|
}
|
|
12274
|
-
const commandId = `classify:${args.moduleCommandId ?? Date.now()}:${
|
|
12333
|
+
const commandId = `classify:${args.moduleCommandId ?? Date.now()}:${createHash6("sha256").update(chunk.map((candidate) => candidate.id).join(",")).digest("hex").slice(0, 24)}`;
|
|
12275
12334
|
const runTask = (hostCompletion) => args.moduleClient?.call({
|
|
12276
12335
|
sessionId: args.moduleSessionId,
|
|
12277
12336
|
projectRoot: args.moduleProjectRoot,
|
|
@@ -12473,7 +12532,7 @@ function recordInvocation(args, startedAt, params) {
|
|
|
12473
12532
|
|
|
12474
12533
|
// ../plugin/src/features/magic-context/dreamer/docs-proposals.ts
|
|
12475
12534
|
import { execFileSync } from "node:child_process";
|
|
12476
|
-
import { createHash as
|
|
12535
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
12477
12536
|
import {
|
|
12478
12537
|
existsSync as existsSync6,
|
|
12479
12538
|
mkdirSync as mkdirSync2,
|
|
@@ -12488,7 +12547,7 @@ import {
|
|
|
12488
12547
|
import { tmpdir } from "node:os";
|
|
12489
12548
|
import { join as join8 } from "node:path";
|
|
12490
12549
|
var FILES = ["ARCHITECTURE.md", "STRUCTURE.md"];
|
|
12491
|
-
var hash = (text) =>
|
|
12550
|
+
var hash = (text) => createHash7("sha256").update(text).digest("hex");
|
|
12492
12551
|
var proposalDir = (projectDir) => join8(projectDir, ".cortexkit/magic-context/docs-update-proposals");
|
|
12493
12552
|
function docsBaseHashes(projectDir) {
|
|
12494
12553
|
return Object.fromEntries(FILES.map((name) => [
|
|
@@ -13559,7 +13618,7 @@ function throwIfAborted2(signal) {
|
|
|
13559
13618
|
}
|
|
13560
13619
|
|
|
13561
13620
|
// ../plugin/src/features/magic-context/smart-notes/compiler.ts
|
|
13562
|
-
import { createHash as
|
|
13621
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
13563
13622
|
|
|
13564
13623
|
// ../plugin/src/features/magic-context/smart-notes/compiler-prompt.ts
|
|
13565
13624
|
var SMART_NOTE_COMPILER_SYSTEM_PROMPT = `You are the Magic Context smart-note compiler for the magic-context system.
|
|
@@ -14340,7 +14399,7 @@ function manifestAdvisoryWarnings(code, manifest) {
|
|
|
14340
14399
|
return warnings;
|
|
14341
14400
|
}
|
|
14342
14401
|
function hashCheck(surfaceCondition, compiledCheck, manifest, checkCron) {
|
|
14343
|
-
return
|
|
14402
|
+
return createHash8("sha256").update(surfaceCondition ?? "").update("\x00").update(compiledCheck).update("\x00").update(JSON.stringify(manifest)).update("\x00").update(checkCron).digest("hex");
|
|
14344
14403
|
}
|
|
14345
14404
|
function extractJsonObject(output) {
|
|
14346
14405
|
const fenced = output.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
@@ -15056,7 +15115,7 @@ function snapshotMaintainDocsFiles(docsDir) {
|
|
|
15056
15115
|
}
|
|
15057
15116
|
|
|
15058
15117
|
// ../plugin/src/features/magic-context/dreamer/map-memories.ts
|
|
15059
|
-
import { createHash as
|
|
15118
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
15060
15119
|
|
|
15061
15120
|
// ../plugin/src/features/magic-context/dreamer/map-memories-prompt.ts
|
|
15062
15121
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -15266,37 +15325,6 @@ var MAP_BATCH_SIZE = 5;
|
|
|
15266
15325
|
var MAP_BATCH_FLOOR_MS = 240000;
|
|
15267
15326
|
var CONSECUTIVE_TIMEOUT_LIMIT2 = 2;
|
|
15268
15327
|
var MAX_INDEPENDENT_REQUEUE_PER_RUN = MAP_BATCH_SIZE;
|
|
15269
|
-
function retryKey(project) {
|
|
15270
|
-
return `map-memories:retry:${project}`;
|
|
15271
|
-
}
|
|
15272
|
-
function readRetries(db, project) {
|
|
15273
|
-
try {
|
|
15274
|
-
const parsed = JSON.parse(getDreamState(db, retryKey(project)) ?? "{}");
|
|
15275
|
-
if (!isRecord(parsed))
|
|
15276
|
-
return {};
|
|
15277
|
-
const retries = {};
|
|
15278
|
-
for (const [id, value] of Object.entries(parsed)) {
|
|
15279
|
-
if (isRecord(value) && typeof value.content === "string" && typeof value.failures === "number" && typeof value.deferUntil === "number") {
|
|
15280
|
-
retries[id] = {
|
|
15281
|
-
content: value.content,
|
|
15282
|
-
failures: value.failures,
|
|
15283
|
-
deferUntil: value.deferUntil
|
|
15284
|
-
};
|
|
15285
|
-
}
|
|
15286
|
-
}
|
|
15287
|
-
return retries;
|
|
15288
|
-
} catch {
|
|
15289
|
-
return {};
|
|
15290
|
-
}
|
|
15291
|
-
}
|
|
15292
|
-
function contentKey(memory) {
|
|
15293
|
-
return createHash8("sha256").update(`${memory.category}
|
|
15294
|
-
${memory.content}`).digest("hex");
|
|
15295
|
-
}
|
|
15296
|
-
function isDeferred(memory, retries) {
|
|
15297
|
-
const retry = retries[memory.id];
|
|
15298
|
-
return !!retry && retry.content === contentKey(memory) && retry.deferUntil > Date.now();
|
|
15299
|
-
}
|
|
15300
15328
|
function assistantText(messages) {
|
|
15301
15329
|
const joined = messages.filter((message) => isRecord(message) && (message.role === "assistant" || isRecord(message.info) && message.info.role === "assistant")).map((message) => extractLatestAssistantText([message]) ?? (isRecord(message) && Array.isArray(message.content) ? message.content.filter(isRecord).filter((part) => part.type === "text" && typeof part.text === "string").map((part) => part.text).join(`
|
|
15302
15330
|
`) : "")).join(`
|
|
@@ -15365,8 +15393,8 @@ function selectMapMemoryInputs(db, projectIdentity, repoDir, includeDeferred = f
|
|
|
15365
15393
|
if (requeue.length >= MAX_INDEPENDENT_REQUEUE_PER_RUN)
|
|
15366
15394
|
break;
|
|
15367
15395
|
}
|
|
15368
|
-
const retries =
|
|
15369
|
-
return [...unmappedInputs, ...requeue].filter((memory) => includeDeferred || !
|
|
15396
|
+
const retries = readMapMemoryRetries(db, projectIdentity);
|
|
15397
|
+
return [...unmappedInputs, ...requeue].filter((memory) => includeDeferred || !isMapMemoryDeferred(memory, retries));
|
|
15370
15398
|
}
|
|
15371
15399
|
async function mapMemories(args) {
|
|
15372
15400
|
const result = {
|
|
@@ -15377,12 +15405,12 @@ async function mapMemories(args) {
|
|
|
15377
15405
|
complete: true
|
|
15378
15406
|
};
|
|
15379
15407
|
const allInputs = selectMapMemoryInputs(args.db, args.projectIdentity, args.sessionDirectory, true);
|
|
15380
|
-
const retries =
|
|
15408
|
+
const retries = readMapMemoryRetries(args.db, args.projectIdentity);
|
|
15381
15409
|
const activeIds = new Set(allInputs.map((memory) => String(memory.id)));
|
|
15382
15410
|
for (const id of Object.keys(retries))
|
|
15383
15411
|
if (!activeIds.has(id))
|
|
15384
15412
|
delete retries[id];
|
|
15385
|
-
const inputs = allInputs.filter((memory) => !
|
|
15413
|
+
const inputs = allInputs.filter((memory) => !isMapMemoryDeferred(memory, retries));
|
|
15386
15414
|
result.remaining = allInputs.length;
|
|
15387
15415
|
result.complete = result.remaining === 0;
|
|
15388
15416
|
if (inputs.length === 0) {
|
|
@@ -15399,6 +15427,7 @@ async function mapMemories(args) {
|
|
|
15399
15427
|
try {
|
|
15400
15428
|
let consecutiveTimeouts = 0;
|
|
15401
15429
|
let timeoutStreakElapsedMs = [];
|
|
15430
|
+
const countedMisses = new Set;
|
|
15402
15431
|
for (let i = 0;i < batches.length; i += 1) {
|
|
15403
15432
|
const remainingMs = Math.max(0, args.deadline - Date.now());
|
|
15404
15433
|
if (remainingMs <= 0) {
|
|
@@ -15421,22 +15450,19 @@ async function mapMemories(args) {
|
|
|
15421
15450
|
}
|
|
15422
15451
|
const committed = outcome.mapped + outcome.independent;
|
|
15423
15452
|
const committedIds = new Set(outcome.committedIds);
|
|
15453
|
+
const missedIds = new Set(outcome.missedIds);
|
|
15424
15454
|
runLeaseGuardedWrite(args.db, args.holderId, args.leaseKey, () => {
|
|
15425
15455
|
for (const memory of batch.inputs) {
|
|
15426
15456
|
if (committedIds.has(memory.id)) {
|
|
15427
15457
|
delete retries[memory.id];
|
|
15428
15458
|
continue;
|
|
15429
15459
|
}
|
|
15430
|
-
|
|
15431
|
-
|
|
15432
|
-
|
|
15433
|
-
|
|
15434
|
-
content,
|
|
15435
|
-
failures,
|
|
15436
|
-
deferUntil: failures < 2 ? 0 : Date.now() + Math.min(24, 2 ** (failures - 2)) * 3600000
|
|
15437
|
-
};
|
|
15460
|
+
if (missedIds.has(memory.id) && !countedMisses.has(memory.id)) {
|
|
15461
|
+
countedMisses.add(memory.id);
|
|
15462
|
+
retries[memory.id] = nextMapMemoryRetry(memory, retries[memory.id]);
|
|
15463
|
+
}
|
|
15438
15464
|
}
|
|
15439
|
-
setDreamState(args.db,
|
|
15465
|
+
setDreamState(args.db, mapMemoryRetryKey(args.projectIdentity), JSON.stringify(retries));
|
|
15440
15466
|
});
|
|
15441
15467
|
result.mapped += outcome.mapped;
|
|
15442
15468
|
result.independent += outcome.independent;
|
|
@@ -15448,7 +15474,7 @@ async function mapMemories(args) {
|
|
|
15448
15474
|
if (outcome.requeue?.length) {
|
|
15449
15475
|
if (!batch.isOmissionRetry) {
|
|
15450
15476
|
batches.push({
|
|
15451
|
-
inputs: outcome.requeue.filter((memory) => !
|
|
15477
|
+
inputs: outcome.requeue.filter((memory) => !isMapMemoryDeferred(memory, retries)),
|
|
15452
15478
|
isOmissionRetry: true
|
|
15453
15479
|
});
|
|
15454
15480
|
log2(`[dreamer] map-memories: committed ${committed}/${batch.inputs.length} mapping(s); requeueing ${outcome.requeue.length} omitted id(s) in a targeted retry`);
|
|
@@ -15536,11 +15562,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
15536
15562
|
stage = "apply";
|
|
15537
15563
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
15538
15564
|
logBatchUsage(run.completion.messages ?? [], outcome.mapped + outcome.independent, startedAt);
|
|
15539
|
-
|
|
15540
|
-
return {
|
|
15541
|
-
...outcome,
|
|
15542
|
-
requeue: budgetFinalized ? [] : batch.filter((memory) => !returnedIds.has(memory.id))
|
|
15543
|
-
};
|
|
15565
|
+
return completedMapBatch(outcome, batch, run.validated, budgetFinalized);
|
|
15544
15566
|
}
|
|
15545
15567
|
const client = args.client;
|
|
15546
15568
|
if (!client)
|
|
@@ -15594,11 +15616,7 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
15594
15616
|
stage = "apply";
|
|
15595
15617
|
const outcome = await applyParsedBatchMappings(args, batch, run.validated, budgetFinalized, true);
|
|
15596
15618
|
logBatchUsage(run.output, outcome.mapped + outcome.independent, startedAt);
|
|
15597
|
-
|
|
15598
|
-
return {
|
|
15599
|
-
...outcome,
|
|
15600
|
-
requeue: budgetFinalized ? [] : batch.filter((memory) => !returnedIds.has(memory.id))
|
|
15601
|
-
};
|
|
15619
|
+
return completedMapBatch(outcome, batch, run.validated, budgetFinalized);
|
|
15602
15620
|
} catch (error) {
|
|
15603
15621
|
const desc = describeError(error);
|
|
15604
15622
|
log2(`[dreamer] map-memories batch failed: ${desc.brief}`, desc.stackHead ? { stackHead: desc.stackHead } : undefined);
|
|
@@ -15640,6 +15658,17 @@ async function mapOneBatch(args, batch, sliceMs, signal) {
|
|
|
15640
15658
|
});
|
|
15641
15659
|
}
|
|
15642
15660
|
}
|
|
15661
|
+
function completedMapBatch(outcome, batch, parsed, budgetFinalized) {
|
|
15662
|
+
if (budgetFinalized)
|
|
15663
|
+
return outcome;
|
|
15664
|
+
const decided = new Set(parsed.map(({ id }) => id));
|
|
15665
|
+
const committed = new Set(outcome.committedIds);
|
|
15666
|
+
return {
|
|
15667
|
+
...outcome,
|
|
15668
|
+
missedIds: batch.filter(({ id }) => !decided.has(id)).map(({ id }) => id),
|
|
15669
|
+
requeue: batch.filter(({ id }) => !committed.has(id))
|
|
15670
|
+
};
|
|
15671
|
+
}
|
|
15643
15672
|
async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = false, allowPartial = false) {
|
|
15644
15673
|
const batchIds = new Set(batch.map((memory) => memory.id));
|
|
15645
15674
|
const valid = parsed.filter((entry) => batchIds.has(entry.id));
|
|
@@ -15731,7 +15760,7 @@ async function applyParsedBatchMappings(args, batch, parsed, budgetFinalized = f
|
|
|
15731
15760
|
name: "memory.set_mapping",
|
|
15732
15761
|
arguments: {
|
|
15733
15762
|
memory_project: args.projectIdentity,
|
|
15734
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
15763
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash9("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
15735
15764
|
rows
|
|
15736
15765
|
}
|
|
15737
15766
|
}
|
|
@@ -16635,6 +16664,33 @@ ${buildFrictionGatePrompt({ userLines })}`;
|
|
|
16635
16664
|
function retrospectiveGatePromptTokens(messages) {
|
|
16636
16665
|
return estimateTokens(retrospectiveGatePrompt(messages));
|
|
16637
16666
|
}
|
|
16667
|
+
function admitRetrospectiveCohorts(rows, firstUnreadTs, maxMessages, promptInputLimitTokens) {
|
|
16668
|
+
const kept = [];
|
|
16669
|
+
let start = 0;
|
|
16670
|
+
for (let first = rows[start];first && first.ts < firstUnreadTs; first = rows[start]) {
|
|
16671
|
+
const ts = first.ts;
|
|
16672
|
+
let end = start + 1;
|
|
16673
|
+
while (end < rows.length && rows[end]?.ts === ts)
|
|
16674
|
+
end += 1;
|
|
16675
|
+
const cohort = rows.slice(start, end);
|
|
16676
|
+
const tooManyRows = end > maxMessages;
|
|
16677
|
+
const tooManyTokens = !tooManyRows && promptInputLimitTokens !== undefined && retrospectiveGatePromptTokens([...kept, ...cohort]) > promptInputLimitTokens;
|
|
16678
|
+
if (tooManyRows || tooManyTokens) {
|
|
16679
|
+
return {
|
|
16680
|
+
kept,
|
|
16681
|
+
budgetTruncated: tooManyTokens,
|
|
16682
|
+
...kept.length === 0 ? { oversized: { ts, rows: cohort } } : {}
|
|
16683
|
+
};
|
|
16684
|
+
}
|
|
16685
|
+
kept.push(...cohort);
|
|
16686
|
+
start = end;
|
|
16687
|
+
}
|
|
16688
|
+
return { kept, budgetTruncated: false };
|
|
16689
|
+
}
|
|
16690
|
+
function logSkippedRetrospectiveCohort(sessionIds, ts, count, lowerBound) {
|
|
16691
|
+
const sessions = [...new Set(sessionIds)].join(",");
|
|
16692
|
+
log2(`[dreamer] retrospective: oversized timestamp cohort sessionIds=${sessions} timestamp=${ts} ${lowerBound ? "skippedAtLeast" : "skipped"}=${count}`);
|
|
16693
|
+
}
|
|
16638
16694
|
async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, overlapUserCount, options) {
|
|
16639
16695
|
const maxMessages = options?.maxMessagesPerRun ?? RETROSPECTIVE_MAX_MESSAGES_PER_RUN;
|
|
16640
16696
|
const capPerSession = options?.capPerSession ?? RETROSPECTIVE_MAX_MESSAGES_PER_SESSION;
|
|
@@ -16664,59 +16720,57 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
16664
16720
|
if (sessionsToRead.length > 0) {
|
|
16665
16721
|
sinceReads.push(...await Promise.all(sessionsToRead.map((session) => provider.readUserMessagesSince(session.sessionId, scanSinceMs, capPerSession))));
|
|
16666
16722
|
}
|
|
16667
|
-
|
|
16668
|
-
|
|
16669
|
-
|
|
16670
|
-
|
|
16671
|
-
|
|
16672
|
-
|
|
16673
|
-
|
|
16674
|
-
|
|
16675
|
-
|
|
16676
|
-
|
|
16677
|
-
|
|
16678
|
-
|
|
16679
|
-
|
|
16680
|
-
|
|
16681
|
-
|
|
16682
|
-
|
|
16683
|
-
if (!row)
|
|
16684
|
-
continue;
|
|
16685
|
-
const candidate = [...keptSince, row];
|
|
16686
|
-
if (retrospectiveGatePromptTokens(candidate) <= promptInputLimitTokens) {
|
|
16687
|
-
keptSince.push(row);
|
|
16688
|
-
continue;
|
|
16689
|
-
}
|
|
16690
|
-
budgetDropped = countCandidates.slice(index);
|
|
16691
|
-
break;
|
|
16723
|
+
const allSince = sinceReads.flatMap((read) => read.messages).filter((message) => message.ts > scanSinceMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
16724
|
+
let unknownBoundary = !!firstExcludedSession && firstExcludedPendingTs === undefined;
|
|
16725
|
+
let firstUnreadTs = firstExcludedPendingTs ?? Number.POSITIVE_INFINITY;
|
|
16726
|
+
const oversizedSessions = new Map;
|
|
16727
|
+
for (const [index, read] of sinceReads.entries()) {
|
|
16728
|
+
if (!read.truncated)
|
|
16729
|
+
continue;
|
|
16730
|
+
const unreadTs = read.firstOmittedTs ?? read.messages.at(-1)?.ts;
|
|
16731
|
+
if (unreadTs === undefined) {
|
|
16732
|
+
unknownBoundary = true;
|
|
16733
|
+
continue;
|
|
16734
|
+
}
|
|
16735
|
+
firstUnreadTs = Math.min(firstUnreadTs, unreadTs);
|
|
16736
|
+
const sessionId = sessionsToRead[index]?.sessionId;
|
|
16737
|
+
if (sessionId !== undefined && read.firstOmittedTs !== undefined && read.firstOmittedTs === oldestBySession?.get(sessionId)) {
|
|
16738
|
+
oversizedSessions.set(sessionId, read.firstOmittedTs);
|
|
16692
16739
|
}
|
|
16693
16740
|
}
|
|
16694
|
-
const
|
|
16741
|
+
const {
|
|
16742
|
+
kept: keptSince,
|
|
16743
|
+
budgetTruncated,
|
|
16744
|
+
oversized
|
|
16745
|
+
} = admitRetrospectiveCohorts(allSince, unknownBoundary ? scanSinceMs : firstUnreadTs, maxMessages, promptInputLimitTokens);
|
|
16746
|
+
const lastKept = keptSince.at(-1);
|
|
16695
16747
|
let maxScannedTs = scanSinceMs;
|
|
16696
|
-
if (
|
|
16697
|
-
|
|
16698
|
-
maxScannedTs =
|
|
16748
|
+
if (!unknownBoundary) {
|
|
16749
|
+
if (oversized) {
|
|
16750
|
+
maxScannedTs = oversized.ts;
|
|
16751
|
+
logSkippedRetrospectiveCohort(oversized.rows.map(({ sessionId }) => sessionId), maxScannedTs, oversized.rows.length, false);
|
|
16752
|
+
} else if (lastKept) {
|
|
16753
|
+
maxScannedTs = lastKept.ts;
|
|
16754
|
+
} else if (Number.isFinite(firstUnreadTs)) {
|
|
16755
|
+
const blockedSessions = sessions.filter(({ session }) => oldestBySession?.get(session.sessionId) === firstUnreadTs);
|
|
16756
|
+
const hitSessionReadCap = blockedSessions.some(({ session }) => oversizedSessions.get(session.sessionId) === firstUnreadTs);
|
|
16757
|
+
if (hitSessionReadCap || blockedSessions.length > sessionLimit) {
|
|
16758
|
+
maxScannedTs = firstUnreadTs;
|
|
16759
|
+
logSkippedRetrospectiveCohort(blockedSessions.map(({ session }) => session.sessionId), maxScannedTs, Math.max(blockedSessions.length, hitSessionReadCap ? capPerSession + 1 : 0), true);
|
|
16760
|
+
} else {
|
|
16761
|
+
maxScannedTs = Math.max(scanSinceMs, firstUnreadTs - 1);
|
|
16762
|
+
}
|
|
16763
|
+
} else if (oldestBySession && allSince.length === 0) {
|
|
16764
|
+
for (const { session } of eligibleSessions) {
|
|
16765
|
+
maxScannedTs = Math.max(maxScannedTs, session.updatedAt ?? scanSinceMs);
|
|
16766
|
+
}
|
|
16699
16767
|
}
|
|
16700
16768
|
}
|
|
16701
|
-
for (const row of keptSince) {
|
|
16702
|
-
if (row.ts > maxScannedTs)
|
|
16703
|
-
maxScannedTs = row.ts;
|
|
16704
|
-
}
|
|
16705
|
-
let frontier = saturatedFrontier;
|
|
16706
|
-
const firstDropped = droppedSince[0];
|
|
16707
|
-
if (firstDropped)
|
|
16708
|
-
frontier = Math.min(frontier, firstDropped.ts - 1);
|
|
16709
|
-
if (typeof firstExcludedPendingTs === "number") {
|
|
16710
|
-
frontier = Math.min(frontier, firstExcludedPendingTs - 1);
|
|
16711
|
-
} else if (typeof firstExcludedSession?.updatedAt === "number") {
|
|
16712
|
-
frontier = Math.min(frontier, firstExcludedSession.updatedAt - 1);
|
|
16713
|
-
}
|
|
16714
|
-
maxScannedTs = Math.max(scanSinceMs, Math.min(maxScannedTs, frontier));
|
|
16715
16769
|
const keptSessionIds = new Set(keptSince.map((message) => message.sessionId));
|
|
16716
16770
|
const overlapSessions = sessionsToRead.filter((session) => keptSessionIds.has(session.sessionId));
|
|
16717
16771
|
const overlapBatches = overlapUserCount > 0 && watermarkMs > 0 && watermarkMs >= recencyCutoffMs ? await Promise.all(overlapSessions.map((session) => provider.readUserMessagesBefore(session.sessionId, watermarkMs, overlapUserCount))) : [];
|
|
16718
16772
|
const seen = new Set;
|
|
16719
|
-
const merged = [];
|
|
16773
|
+
const merged = [...keptSince];
|
|
16720
16774
|
const appendUnique = (row) => {
|
|
16721
16775
|
const key = `${row.sessionId}\x00${row.ts}\x00${row.role}\x00${row.toolName ?? ""}`;
|
|
16722
16776
|
if (seen.has(key))
|
|
@@ -16725,9 +16779,7 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
16725
16779
|
merged.push(row);
|
|
16726
16780
|
return true;
|
|
16727
16781
|
};
|
|
16728
|
-
|
|
16729
|
-
appendUnique(row);
|
|
16730
|
-
const overlapRows = overlapBatches.flat().filter((message) => message.ts >= recencyCutoffMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
16782
|
+
const overlapRows = overlapBatches.flat().filter((message) => message.ts >= recencyCutoffMs && message.ts <= watermarkMs).map(clampRetrospectiveMessage).sort((a, b) => a.ts - b.ts || a.ordinal - b.ordinal);
|
|
16731
16783
|
for (const row of overlapRows) {
|
|
16732
16784
|
const beforeLength = merged.length;
|
|
16733
16785
|
if (!appendUnique(row))
|
|
@@ -16747,7 +16799,7 @@ async function readRetrospectiveScanWindow(provider, projectIdentity, watermarkM
|
|
|
16747
16799
|
maxScannedTs,
|
|
16748
16800
|
promptTokens,
|
|
16749
16801
|
...promptInputLimitTokens === undefined ? {} : { promptInputLimitTokens },
|
|
16750
|
-
budgetTruncated
|
|
16802
|
+
budgetTruncated
|
|
16751
16803
|
};
|
|
16752
16804
|
} finally {
|
|
16753
16805
|
provider.dispose?.();
|
|
@@ -16780,7 +16832,12 @@ function readOpenCodeMessagesSince(db, sessionId, sinceMs, capPerSession) {
|
|
|
16780
16832
|
LIMIT ?`).all(sessionId, sinceMs, limit + 1);
|
|
16781
16833
|
const truncated = rows.length > limit;
|
|
16782
16834
|
const kept = truncated ? rows.slice(0, limit) : rows;
|
|
16783
|
-
|
|
16835
|
+
const firstOmitted = rows[limit];
|
|
16836
|
+
return {
|
|
16837
|
+
messages: normalizeOpenCodeRows(db, sessionId, kept),
|
|
16838
|
+
truncated,
|
|
16839
|
+
...firstOmitted ? { firstOmittedTs: firstOmitted.time_created } : {}
|
|
16840
|
+
};
|
|
16784
16841
|
}
|
|
16785
16842
|
function readOpenCodeOldestMessageTimesSince(db, sessionIds, sinceMs) {
|
|
16786
16843
|
const result = new Map;
|
|
@@ -17013,7 +17070,7 @@ function insertDreamRun(db, run) {
|
|
|
17013
17070
|
}
|
|
17014
17071
|
|
|
17015
17072
|
// ../plugin/src/features/magic-context/dreamer/verify.ts
|
|
17016
|
-
import { createHash as
|
|
17073
|
+
import { createHash as createHash11 } from "node:crypto";
|
|
17017
17074
|
|
|
17018
17075
|
// ../plugin/src/features/magic-context/dreamer/verify-diff.ts
|
|
17019
17076
|
import { execFile as execFile3 } from "node:child_process";
|
|
@@ -17137,7 +17194,7 @@ Read only these changed line ranges if they may affect the claim.`
|
|
|
17137
17194
|
import path12 from "node:path";
|
|
17138
17195
|
|
|
17139
17196
|
// ../plugin/src/features/magic-context/dreamer/verify-state.ts
|
|
17140
|
-
import { createHash as
|
|
17197
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
17141
17198
|
import { readFile, realpath as realpath2 } from "node:fs/promises";
|
|
17142
17199
|
import path11 from "node:path";
|
|
17143
17200
|
function verificationMetadata(memory) {
|
|
@@ -17150,7 +17207,7 @@ function verificationMetadata(memory) {
|
|
|
17150
17207
|
}
|
|
17151
17208
|
async function verificationFilesFingerprint(directory, files) {
|
|
17152
17209
|
const root = await resolveGitTopLevel(directory) ?? path11.resolve(directory);
|
|
17153
|
-
const hash =
|
|
17210
|
+
const hash = createHash10("sha256");
|
|
17154
17211
|
for (const file of [...new Set(files)].sort()) {
|
|
17155
17212
|
const absolute = path11.resolve(root, file);
|
|
17156
17213
|
const withinRoot = (candidate) => {
|
|
@@ -17163,7 +17220,7 @@ async function verificationFilesFingerprint(directory, files) {
|
|
|
17163
17220
|
try {
|
|
17164
17221
|
if (!withinRoot(await realpath2(absolute)))
|
|
17165
17222
|
return null;
|
|
17166
|
-
hash.update(
|
|
17223
|
+
hash.update(createHash10("sha256").update(await readFile(absolute)).digest("hex"));
|
|
17167
17224
|
} catch (error) {
|
|
17168
17225
|
if (error.code !== "ENOENT")
|
|
17169
17226
|
return null;
|
|
@@ -17968,7 +18025,7 @@ async function applyParsedVerifyManifest(args, batch, parsed, headAtPrompt, budg
|
|
|
17968
18025
|
name: "memory.set_verification",
|
|
17969
18026
|
arguments: {
|
|
17970
18027
|
memory_project: args.projectIdentity,
|
|
17971
|
-
command_id: `${args.moduleRoute.moduleCommandId}:${
|
|
18028
|
+
command_id: `${args.moduleRoute.moduleCommandId}:${createHash11("sha256").update(rows.map((row) => row.memory_id).join(",")).digest("hex").slice(0, 16)}`,
|
|
17972
18029
|
rows
|
|
17973
18030
|
}
|
|
17974
18031
|
}
|
|
@@ -18882,7 +18939,7 @@ function parseFrictionGateVerdict(verdict) {
|
|
|
18882
18939
|
}
|
|
18883
18940
|
function computeRetrospectiveWindowKey(flagged) {
|
|
18884
18941
|
const anchors = flagged.map((message) => `${message.sessionId}:${message.ts}`).sort().join("|");
|
|
18885
|
-
return
|
|
18942
|
+
return createHash12("sha256").update(anchors).digest("hex").slice(0, 32);
|
|
18886
18943
|
}
|
|
18887
18944
|
function renderFrictionWindow(messages, flaggedOrdinals, radius = 2) {
|
|
18888
18945
|
const flagged = new Set(flaggedOrdinals);
|
|
@@ -19001,6 +19058,13 @@ async function runRetrospectiveTask(config, ctx, helpers) {
|
|
|
19001
19058
|
const recencyDays = Math.max(1, Math.floor(config.retrospectiveRecencyDays ?? 30));
|
|
19002
19059
|
const recencyCutoffMs = helpers.invocationStartedAt - recencyDays * RETROSPECTIVE_DAY_MS;
|
|
19003
19060
|
const scan = await readRetrospectiveScanWindow(provider, projectIdentity, watermarkMs, RETROSPECTIVE_OVERLAP_USER_LINES, { usableInputTokens, recencyCutoffMs });
|
|
19061
|
+
ctx.onRetrospectiveScan?.({
|
|
19062
|
+
watermarkMs,
|
|
19063
|
+
maxScannedTs: scan.maxScannedTs,
|
|
19064
|
+
usableInputTokens,
|
|
19065
|
+
recencyCutoffMs,
|
|
19066
|
+
budgetTruncated: scan.budgetTruncated
|
|
19067
|
+
});
|
|
19004
19068
|
const clearedTaskStateJson = activeOverflow ? writeRetrospectiveOverflowState(taskState.root, null) : undefined;
|
|
19005
19069
|
const completedWindow = (retrospectiveWatermarkMs, noOpReason) => ({
|
|
19006
19070
|
retrospectiveWatermarkMs,
|
|
@@ -19788,6 +19852,7 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
19788
19852
|
}
|
|
19789
19853
|
}
|
|
19790
19854
|
let outcome;
|
|
19855
|
+
const diagnostics = {};
|
|
19791
19856
|
const startedAt = Date.now();
|
|
19792
19857
|
try {
|
|
19793
19858
|
outcome = await executor(due.config, {
|
|
@@ -19795,7 +19860,12 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
19795
19860
|
projectIdentity,
|
|
19796
19861
|
holderId,
|
|
19797
19862
|
leaseKey,
|
|
19798
|
-
leaseAcquisition: acquisition
|
|
19863
|
+
leaseAcquisition: acquisition,
|
|
19864
|
+
...due.config.task === "retrospective" ? {
|
|
19865
|
+
onRetrospectiveScan: (scan) => {
|
|
19866
|
+
diagnostics.retrospectiveScan = scan;
|
|
19867
|
+
}
|
|
19868
|
+
} : {}
|
|
19799
19869
|
});
|
|
19800
19870
|
} catch (error) {
|
|
19801
19871
|
outcome = { status: "failed", transient: true, error: String(error) };
|
|
@@ -19806,6 +19876,11 @@ async function runDomainGroup(deps, group, cb) {
|
|
|
19806
19876
|
cb?.onSkipped?.(due.config.task, outcome.detail);
|
|
19807
19877
|
} else if (outcome.status === "completed") {
|
|
19808
19878
|
advanceAfterRun(db, projectIdentity, due, finishedAt, "completed", null, outcome.schedulePatch, startedAt);
|
|
19879
|
+
const scan = diagnostics.retrospectiveScan;
|
|
19880
|
+
if (scan) {
|
|
19881
|
+
const stored = readRetrospectiveWatermark(db, projectIdentity, due.config.task);
|
|
19882
|
+
log2(`[dreamer] retrospective: watermark start=${scan.watermarkMs} maxScannedTs=${scan.maxScannedTs} patch=${outcome.schedulePatch?.retrospectiveWatermarkMs ?? "none"} stored=${stored ?? "none"} usableInputTokens=${scan.usableInputTokens} recencyCutoffMs=${scan.recencyCutoffMs} budgetTruncated=${scan.budgetTruncated}`, { projectIdentity });
|
|
19883
|
+
}
|
|
19809
19884
|
cb?.onRan?.(due.config.task, outcome.detail, outcome.backlog);
|
|
19810
19885
|
} else if (outcome.transient) {
|
|
19811
19886
|
recordTransientFailure(db, projectIdentity, due, finishedAt, outcome.error ?? null, outcome.schedulePatch);
|
|
@@ -23016,9 +23091,11 @@ class PiRetrospectiveRawProvider {
|
|
|
23016
23091
|
async readUserMessagesSince(sessionId, sinceMs, capPerSession) {
|
|
23017
23092
|
const limit = Math.max(1, Math.floor(capPerSession));
|
|
23018
23093
|
const messages = await this.selectUserEntries(sessionId, (ts) => ts > sinceMs, limit + 1, false, sinceMs);
|
|
23094
|
+
const firstOmitted = messages[limit];
|
|
23019
23095
|
return {
|
|
23020
23096
|
messages: messages.slice(0, limit),
|
|
23021
|
-
truncated: messages.length > limit
|
|
23097
|
+
truncated: messages.length > limit,
|
|
23098
|
+
...firstOmitted ? { firstOmittedTs: firstOmitted.ts } : {}
|
|
23022
23099
|
};
|
|
23023
23100
|
}
|
|
23024
23101
|
async readOldestMessageTimesSince(sessionIds, sinceMs) {
|
|
@@ -24341,6 +24418,79 @@ function commitPiCompactionModeRecord(db, sessionId, record) {
|
|
|
24341
24418
|
// src/context-handler.ts
|
|
24342
24419
|
import * as crypto3 from "node:crypto";
|
|
24343
24420
|
|
|
24421
|
+
// ../plugin/src/features/magic-context/memory/identity-merge-command.ts
|
|
24422
|
+
var IDENTITY_MERGE_COMMAND = "npx @cortexkit/magic-context@latest doctor merge-identities";
|
|
24423
|
+
var IDENTITY_MERGE_PREVIEW_HINT = "It shows what would move. Add --apply to move them.";
|
|
24424
|
+
function shellArg(value, platform) {
|
|
24425
|
+
if (/^[\w.:/-]+$/.test(value))
|
|
24426
|
+
return value;
|
|
24427
|
+
return platform === "win32" ? `"${value}"` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
24428
|
+
}
|
|
24429
|
+
function identityMergeCommand(from, to, platform = process.platform) {
|
|
24430
|
+
return `${IDENTITY_MERGE_COMMAND} --from ${shellArg(from, platform)} --to ${to ? shellArg(to, platform) : '"DESTINATION_IDENTITY"'}`;
|
|
24431
|
+
}
|
|
24432
|
+
|
|
24433
|
+
// ../plugin/src/features/magic-context/memory/project-binding-notice.ts
|
|
24434
|
+
var observedBindings = new WeakMap;
|
|
24435
|
+
function bindingLog(harness, directory, old, identity, memories) {
|
|
24436
|
+
return `project binding changed harness=${harness} cwd=${directory || "unknown"} old=${old ?? "none"} new=${identity} memories=${memories}`;
|
|
24437
|
+
}
|
|
24438
|
+
function observeSessionProjectBinding(db, sessionId, identity, directory, notify) {
|
|
24439
|
+
const change = recordSessionProjectIdentity(db, sessionId, identity);
|
|
24440
|
+
const harness = getHarness2();
|
|
24441
|
+
let observations = observedBindings.get(db);
|
|
24442
|
+
if (!observations) {
|
|
24443
|
+
observations = new BoundedSessionMap(1000);
|
|
24444
|
+
observedBindings.set(db, observations);
|
|
24445
|
+
}
|
|
24446
|
+
const key = `${harness}\x00${sessionId}`;
|
|
24447
|
+
const last = observations.get(key);
|
|
24448
|
+
const noticed = last?.noticed ?? new Set;
|
|
24449
|
+
const observation = {
|
|
24450
|
+
directory,
|
|
24451
|
+
noticed,
|
|
24452
|
+
warning: change ? undefined : last?.warning
|
|
24453
|
+
};
|
|
24454
|
+
observations.set(key, observation);
|
|
24455
|
+
const old = change?.previousProjectPath;
|
|
24456
|
+
if (!change || !old && harness !== "pi" && harness !== "omp")
|
|
24457
|
+
return;
|
|
24458
|
+
const memories = old ? getMemoryCount2(db, old) : 0;
|
|
24459
|
+
const binding = bindingLog(harness, directory, old, identity, memories);
|
|
24460
|
+
if (!old || !memories) {
|
|
24461
|
+
sessionLog2(sessionId, binding);
|
|
24462
|
+
return;
|
|
24463
|
+
}
|
|
24464
|
+
const oldDirectory = [last?.directory, directory].find((path) => path && directoryFallback(path) === old);
|
|
24465
|
+
const location = oldDirectory ? `the old folder (${oldDirectory})` : `the old project (${old})`;
|
|
24466
|
+
let guidance;
|
|
24467
|
+
if (old.startsWith("dir:") && /^(dir|git):/.test(identity)) {
|
|
24468
|
+
guidance = `Review the merge first:
|
|
24469
|
+
${identityMergeCommand(oldDirectory ?? old, identity)}
|
|
24470
|
+
${IDENTITY_MERGE_PREVIEW_HINT}`;
|
|
24471
|
+
} else if (old.startsWith("git:") && identity.startsWith("dir:")) {
|
|
24472
|
+
guidance = "A repository's memories cannot be merged into a folder project.";
|
|
24473
|
+
} else {
|
|
24474
|
+
guidance = "Run `npx @cortexkit/magic-context@latest doctor` to see how these memories can be merged.";
|
|
24475
|
+
}
|
|
24476
|
+
const count = `${memories} ${memories === 1 ? "memory" : "memories"}`;
|
|
24477
|
+
observation.warning = `${count} stayed under this session's previous project. Nothing was moved.
|
|
24478
|
+
${guidance}`;
|
|
24479
|
+
if (noticed.has(old)) {
|
|
24480
|
+
sessionLog2(sessionId, binding);
|
|
24481
|
+
return;
|
|
24482
|
+
}
|
|
24483
|
+
noticed.add(old);
|
|
24484
|
+
const notice = `This session changed projects. ${count} stayed with ${location}; nothing moved. ${guidance}`;
|
|
24485
|
+
sessionLog2(sessionId, `${binding} notice=${JSON.stringify(notice)}`);
|
|
24486
|
+
try {
|
|
24487
|
+
notify?.(notice);
|
|
24488
|
+
} catch {}
|
|
24489
|
+
}
|
|
24490
|
+
function getProjectBindingWarning(db, sessionId) {
|
|
24491
|
+
return observedBindings.get(db)?.peek(`${getHarness2()}\x00${sessionId}`)?.warning;
|
|
24492
|
+
}
|
|
24493
|
+
|
|
24344
24494
|
// ../plugin/src/hooks/magic-context/event-resolvers.ts
|
|
24345
24495
|
var DEFAULT_CONTEXT_LIMIT = 200000;
|
|
24346
24496
|
var WRAPUP_WINDOW_UNAVAILABLE = "Cannot run /ctx-wrapup: the model's context window is unknown. Select a model with a configured context window or send a message with that model, then retry.";
|
|
@@ -28857,7 +29007,7 @@ function recoveryReasoningPrefixes(messages, partsKey) {
|
|
|
28857
29007
|
}
|
|
28858
29008
|
|
|
28859
29009
|
// ../plugin/src/shared/tag-transcript.ts
|
|
28860
|
-
import { createHash as
|
|
29010
|
+
import { createHash as createHash13 } from "node:crypto";
|
|
28861
29011
|
function buildPersistedDropTargets(transcript, tags, options = {}) {
|
|
28862
29012
|
const targets = new Map;
|
|
28863
29013
|
const tools = new Map(tags.filter((tag) => tag.type === "tool").map((tag) => [makeToolCompositeKey(tag.toolOwnerMessageId ?? "", tag.messageId), tag]));
|
|
@@ -28940,7 +29090,7 @@ function buildPersistedDropTargets(transcript, tags, options = {}) {
|
|
|
28940
29090
|
return targets;
|
|
28941
29091
|
}
|
|
28942
29092
|
function textIdentityDigest(value) {
|
|
28943
|
-
return
|
|
29093
|
+
return createHash13("sha256").update(value).digest("hex");
|
|
28944
29094
|
}
|
|
28945
29095
|
function buildContentDerivedTextIds(messageId, parts) {
|
|
28946
29096
|
const sources = parts.filter((part) => part.kind === "text").map((part) => stripTagPrefix(part.getText() ?? ""));
|
|
@@ -32743,7 +32893,7 @@ function clearPiCtxReduceCallableSession(sessionId) {
|
|
|
32743
32893
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
32744
32894
|
|
|
32745
32895
|
// src/tail-hygiene-walk-pi.ts
|
|
32746
|
-
import { createHash as
|
|
32896
|
+
import { createHash as createHash14 } from "node:crypto";
|
|
32747
32897
|
|
|
32748
32898
|
// src/provider-visible-parts-pi.ts
|
|
32749
32899
|
function isRecord4(value) {
|
|
@@ -32872,7 +33022,7 @@ function memoizedContent(kind, content) {
|
|
|
32872
33022
|
function contentMemoKey(kind, content) {
|
|
32873
33023
|
if (content.length <= INLINE_CONTENT_KEY_CHARS)
|
|
32874
33024
|
return `${kind}\x00=${content}`;
|
|
32875
|
-
const digest =
|
|
33025
|
+
const digest = createHash14("sha256").update(content, "utf16le").digest("base64");
|
|
32876
33026
|
return `${kind}\x00#${content.length}\x00${digest}`;
|
|
32877
33027
|
}
|
|
32878
33028
|
function measuredContent(kind, content) {
|
|
@@ -34306,7 +34456,7 @@ function extractToastTitle(text) {
|
|
|
34306
34456
|
}
|
|
34307
34457
|
async function sendStatusNotification(_client, sessionId, text, params) {
|
|
34308
34458
|
try {
|
|
34309
|
-
const { pushNotification } = await importPluginModule(() => import("./rpc-notifications-
|
|
34459
|
+
const { pushNotification } = await importPluginModule(() => import("./rpc-notifications-889zvhn2.js"));
|
|
34310
34460
|
pushNotification("toast", {
|
|
34311
34461
|
title: extractToastTitle(text),
|
|
34312
34462
|
message: text,
|
|
@@ -37499,9 +37649,9 @@ function authorizePiToolRemoval(args) {
|
|
|
37499
37649
|
}
|
|
37500
37650
|
|
|
37501
37651
|
// src/native-replay-tag-provenance-pi.ts
|
|
37502
|
-
import { createHash as
|
|
37652
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
37503
37653
|
function nativeResponseTagStripKey(id, phase, text) {
|
|
37504
|
-
return
|
|
37654
|
+
return createHash15("sha256").update(JSON.stringify([id, phase, text])).digest("hex");
|
|
37505
37655
|
}
|
|
37506
37656
|
|
|
37507
37657
|
// src/native-replay-tags-pi.ts
|
|
@@ -40807,7 +40957,7 @@ function piDispatchMismatchDiagnostic(payload, prepared, mismatch) {
|
|
|
40807
40957
|
}
|
|
40808
40958
|
|
|
40809
40959
|
// src/pi-foreign-session-index.ts
|
|
40810
|
-
import { createHash as
|
|
40960
|
+
import { createHash as createHash16 } from "node:crypto";
|
|
40811
40961
|
|
|
40812
40962
|
// src/pi-foreign-omp-kinds.ts
|
|
40813
40963
|
var PI_FOREIGN_RENDERED_CONTENT_KINDS = [
|
|
@@ -41640,7 +41790,7 @@ function fingerprint(text, index, wire = false) {
|
|
|
41640
41790
|
index.stats.wireHashes++;
|
|
41641
41791
|
else
|
|
41642
41792
|
index.stats.hashes++;
|
|
41643
|
-
return
|
|
41793
|
+
return createHash16("sha256").update(stableStringify([{ type: "text", text }])).digest("hex");
|
|
41644
41794
|
}
|
|
41645
41795
|
function protectSession(index, message, roleOverride, trackEntry = false) {
|
|
41646
41796
|
const rendering = texts(index, message, roleOverride, trackEntry);
|
|
@@ -42533,7 +42683,7 @@ function piExpandChainedRequest(payload, chained, anchor, prepared, pass) {
|
|
|
42533
42683
|
}
|
|
42534
42684
|
|
|
42535
42685
|
// src/pi-dispatch-cursor.ts
|
|
42536
|
-
import { createHash as
|
|
42686
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
42537
42687
|
var MAX_BYTES = 32 * 1024 * 1024;
|
|
42538
42688
|
var MAX_ENTRIES = 1e5;
|
|
42539
42689
|
function object14(value) {
|
|
@@ -42660,7 +42810,7 @@ Today: ${day}; current working directory: '${cwd.replace(/\\/gu, "/")}'. Do not
|
|
|
42660
42810
|
const hash = (content) => {
|
|
42661
42811
|
const json = JSON.stringify({ role: "user", content });
|
|
42662
42812
|
if (json.length <= MAX_BYTES)
|
|
42663
|
-
roots.add(
|
|
42813
|
+
roots.add(createHash17("sha256").update(json).digest("hex"));
|
|
42664
42814
|
};
|
|
42665
42815
|
hash(parts);
|
|
42666
42816
|
if (reminder) {
|
|
@@ -45050,7 +45200,7 @@ function createPiFallbackIndex() {
|
|
|
45050
45200
|
}
|
|
45051
45201
|
|
|
45052
45202
|
// src/pi-fit-reclaim.ts
|
|
45053
|
-
import { createHash as
|
|
45203
|
+
import { createHash as createHash18, randomUUID as randomUUID4 } from "node:crypto";
|
|
45054
45204
|
var pendingInput = new Set;
|
|
45055
45205
|
var KEY3 = "piUpperEstimateReclaim";
|
|
45056
45206
|
function piFitOverflowPossible(args) {
|
|
@@ -45086,7 +45236,7 @@ function piUpperReclaimCursor(args) {
|
|
|
45086
45236
|
sessionId: args.sessionId,
|
|
45087
45237
|
modelKey: args.modelKey,
|
|
45088
45238
|
contextWindow: args.contextWindow ?? null,
|
|
45089
|
-
head: head ?
|
|
45239
|
+
head: head ? createHash18("sha256").update(JSON.stringify([
|
|
45090
45240
|
Buffer.from(head.cachedM0Bytes ?? []).toString("base64"),
|
|
45091
45241
|
Buffer.from(head.cachedM1Bytes ?? []).toString("base64"),
|
|
45092
45242
|
head.cachedM0MuralDataUrl ?? null
|
|
@@ -45173,7 +45323,7 @@ async function waitForPiHistorianInTurn(sessionId, remainingMs, wait) {
|
|
|
45173
45323
|
}
|
|
45174
45324
|
|
|
45175
45325
|
// src/pi-lkg-fit-envelope.ts
|
|
45176
|
-
import { createHash as
|
|
45326
|
+
import { createHash as createHash19 } from "node:crypto";
|
|
45177
45327
|
function readPiLkgFitEnvelope(ctx, pi, modelKey, frozen, wireSchema) {
|
|
45178
45328
|
try {
|
|
45179
45329
|
if (!modelKey || typeof pi.getAllTools !== "function")
|
|
@@ -45235,7 +45385,7 @@ function readPiLkgFitEnvelope(ctx, pi, modelKey, frozen, wireSchema) {
|
|
|
45235
45385
|
refusalToolDefinitionTokens,
|
|
45236
45386
|
toolDefinitionsMeasured: refusalToolDefinitionTokens !== undefined,
|
|
45237
45387
|
envelopeBytes: Buffer.byteLength(envelopeJson),
|
|
45238
|
-
envelopeSignature: activeNames ?
|
|
45388
|
+
envelopeSignature: activeNames ? createHash19("sha256").update(envelopeJson).update(JSON.stringify(activeNames)).digest("hex") : undefined,
|
|
45239
45389
|
calibration,
|
|
45240
45390
|
...piModelAcceptsImages(ctx.model) ? {} : { modelAcceptsImages: false }
|
|
45241
45391
|
};
|
|
@@ -45245,13 +45395,13 @@ function readPiLkgFitEnvelope(ctx, pi, modelKey, frozen, wireSchema) {
|
|
|
45245
45395
|
}
|
|
45246
45396
|
|
|
45247
45397
|
// src/pi-message-identity.ts
|
|
45248
|
-
import { createHash as
|
|
45398
|
+
import { createHash as createHash22 } from "node:crypto";
|
|
45249
45399
|
|
|
45250
45400
|
// src/pi-tool-identity.ts
|
|
45251
|
-
import { createHash as
|
|
45401
|
+
import { createHash as createHash21 } from "node:crypto";
|
|
45252
45402
|
|
|
45253
45403
|
// src/served-array-ledger.ts
|
|
45254
|
-
import { createHash as
|
|
45404
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
45255
45405
|
import {
|
|
45256
45406
|
closeSync as closeSync2,
|
|
45257
45407
|
fstatSync,
|
|
@@ -45529,7 +45679,7 @@ function getPiLastServedArray(sessionId) {
|
|
|
45529
45679
|
return previous ? `[${previous.serializedMessages.join(",")}]` : undefined;
|
|
45530
45680
|
}
|
|
45531
45681
|
function sha256(value) {
|
|
45532
|
-
return
|
|
45682
|
+
return createHash20("sha256").update(value).digest("hex");
|
|
45533
45683
|
}
|
|
45534
45684
|
function safeSessionFileStem(sessionId) {
|
|
45535
45685
|
const readable = sessionId.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 96);
|
|
@@ -45864,7 +46014,7 @@ function readPiServedCachedArray(sessionId) {
|
|
|
45864
46014
|
const memory = getPiLastServedArray(sessionId);
|
|
45865
46015
|
const slot = memory === undefined ? getSlot(sessionId) : undefined;
|
|
45866
46016
|
const jsonPrefix = memory ?? slot?.jsonPrefix;
|
|
45867
|
-
if (jsonPrefix === undefined ||
|
|
46017
|
+
if (jsonPrefix === undefined || createHash21("sha256").update(jsonPrefix).digest("hex") !== getPiLastServedDigest(sessionId))
|
|
45868
46018
|
return;
|
|
45869
46019
|
let parsed;
|
|
45870
46020
|
try {
|
|
@@ -45888,7 +46038,7 @@ function piMessageEntryFingerprint(message) {
|
|
|
45888
46038
|
const m = message;
|
|
45889
46039
|
if (typeof m.role !== "string")
|
|
45890
46040
|
return null;
|
|
45891
|
-
const contentHash =
|
|
46041
|
+
const contentHash = createHash22("sha256").update(stableStringify(m.content)).digest("hex");
|
|
45892
46042
|
return JSON.stringify([
|
|
45893
46043
|
typeof m.responseId === "string" ? m.responseId : null,
|
|
45894
46044
|
typeof m.timestamp === "number" || typeof m.timestamp === "string" ? m.timestamp : null,
|
|
@@ -48788,7 +48938,7 @@ function trackSessionForProject(projectIdentity, sessionId) {
|
|
|
48788
48938
|
function isContextHandlerSessionActive(sessionId) {
|
|
48789
48939
|
return activeContextHandlerSessions.has(sessionId);
|
|
48790
48940
|
}
|
|
48791
|
-
function updateSessionProjectTracking(sessionId, projectIdentity, db, observedCwd) {
|
|
48941
|
+
function updateSessionProjectTracking(sessionId, projectIdentity, db, observedCwd, notify) {
|
|
48792
48942
|
if (!projectIdentity)
|
|
48793
48943
|
return;
|
|
48794
48944
|
const prev = lastSeenProjectIdentityBySession.get(sessionId);
|
|
@@ -48801,11 +48951,8 @@ function updateSessionProjectTracking(sessionId, projectIdentity, db, observedCw
|
|
|
48801
48951
|
}
|
|
48802
48952
|
if (db && persistedProjectIdentityBySession.get(sessionId) !== projectIdentity) {
|
|
48803
48953
|
try {
|
|
48804
|
-
|
|
48954
|
+
observeSessionProjectBinding(db, sessionId, projectIdentity, observedCwd ?? "", notify);
|
|
48805
48955
|
persistedProjectIdentityBySession.set(sessionId, projectIdentity);
|
|
48806
|
-
if (change) {
|
|
48807
|
-
sessionLog2(sessionId, `project binding changed harness=${getHarness2()} cwd=${observedCwd ?? "unknown"} old=${change.previousProjectPath ?? "none"} new=${change.projectPath}`);
|
|
48808
|
-
}
|
|
48809
48956
|
} catch (error) {
|
|
48810
48957
|
const now = Date.now();
|
|
48811
48958
|
const lastLoggedAt = sessionProjectBindingFailureLogAtBySession.get(sessionId);
|
|
@@ -50526,7 +50673,7 @@ function registerPiContextHandler(pi, baseOptions) {
|
|
|
50526
50673
|
}));
|
|
50527
50674
|
assertCurrentPass();
|
|
50528
50675
|
const historyHead = sessionMetaForUsage.isSubagent ? undefined : options.injection;
|
|
50529
|
-
updateSessionProjectTracking(sessionId, projectIdentity, options.db, projectDirectory);
|
|
50676
|
+
updateSessionProjectTracking(sessionId, projectIdentity, options.db, projectDirectory, ctx.hasUI ? (text) => ctx.ui.notify(text, "warning") : undefined);
|
|
50530
50677
|
const lkgInputIdByRef = new Map;
|
|
50531
50678
|
for (const input of lkgPassSnapshot.inputs)
|
|
50532
50679
|
lkgInputIdByRef.set(event.messages[input.messageIndex], input.id);
|
|
@@ -55462,6 +55609,10 @@ function renderUserStatusSummary(summary, style) {
|
|
|
55462
55609
|
for (const warning of summary.hiddenVariantWarnings ?? []) {
|
|
55463
55610
|
lines.push(style === "markdown" ? `- **Warning:** ${warning}` : `Warning: ${warning}`);
|
|
55464
55611
|
}
|
|
55612
|
+
if (summary.projectBindingWarning) {
|
|
55613
|
+
const label = style === "markdown" ? "- **Warning:**" : "Warning:";
|
|
55614
|
+
lines.push(`${label} ${summary.projectBindingWarning}`);
|
|
55615
|
+
}
|
|
55465
55616
|
for (const warning of summary.warnings) {
|
|
55466
55617
|
lines.push(style === "markdown" ? `- **Warning:** ${renderUserFacingFailure(warning)}` : `Warning: ${renderUserFacingFailure(warning)}`);
|
|
55467
55618
|
}
|
|
@@ -55644,6 +55795,7 @@ function checkStatusViewSource(candidate) {
|
|
|
55644
55795
|
compactionEnabled: optional.read("compactionEnabled", isBoolean),
|
|
55645
55796
|
warnings: optional.readArray("warnings", isUserFacingFailureKey),
|
|
55646
55797
|
hiddenVariantWarnings: optional.readArray("hiddenVariantWarnings", isString),
|
|
55798
|
+
projectBindingWarning: optional.read("projectBindingWarning", isString),
|
|
55647
55799
|
unconfirmedMigrationHolders: optional.read("unconfirmedMigrationHolders", isUnconfirmedMigrationHolders)
|
|
55648
55800
|
};
|
|
55649
55801
|
return { ok: true, source, ignoredFields: optional.ignored };
|
|
@@ -56111,6 +56263,7 @@ function warningBlock(source) {
|
|
|
56111
56263
|
}
|
|
56112
56264
|
] : [],
|
|
56113
56265
|
...(source.hiddenVariantWarnings ?? []).map((text) => ({ text, tone: "warning" })),
|
|
56266
|
+
...source.projectBindingWarning ? [{ text: source.projectBindingWarning, tone: "warning" }] : [],
|
|
56114
56267
|
...source.configReloadFailure ? [
|
|
56115
56268
|
{
|
|
56116
56269
|
text: `Config reload failed ${source.configReloadFailure.path}: ${source.configReloadFailure.message}`,
|
|
@@ -56413,6 +56566,7 @@ function formatPiStatusSummary(s) {
|
|
|
56413
56566
|
tokens: s.tailHygiene?.u ?? 0
|
|
56414
56567
|
},
|
|
56415
56568
|
memoryCount: s.memoryCount,
|
|
56569
|
+
projectBindingWarning: s.projectBindingWarning,
|
|
56416
56570
|
noteCount: s.sessionNoteCount + s.readySmartNoteCount,
|
|
56417
56571
|
embedding: s.embedding,
|
|
56418
56572
|
warnings: piStatusWarnings(s),
|
|
@@ -56845,6 +56999,7 @@ function buildStatusDetail(pi, ctx, deps, sessionId, state, host = readStatusHos
|
|
|
56845
56999
|
return last ? `${last.startMessage}-${last.endMessage}` : null;
|
|
56846
57000
|
})(),
|
|
56847
57001
|
memoryCount: memoryImportanceHistogram.total,
|
|
57002
|
+
projectBindingWarning: getProjectBindingWarning(deps.db, sessionId),
|
|
56848
57003
|
memoryBlockCount,
|
|
56849
57004
|
memoryImportanceHistogram,
|
|
56850
57005
|
sessionNoteCount: safeRead(() => getNotes(deps.db, {
|