@cortexkit/opencode-magic-context 0.49.87 → 0.49.89
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/{announcement-fnyxaahs.js → announcement-4ynkaf0d.js} +2 -2
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +5 -5
- package/dist/{context-gnk68pyy.js → context-grdg1k2k.js} +21 -21
- package/dist/{derive-budgets-90869322.js → derive-budgets-hzzq71rm.js} +2 -2
- package/dist/{embedding-backfill-9khxv6a9.js → embedding-backfill-qjkaee9s.js} +6 -6
- package/dist/embedding-worker.js +2 -2
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp-carry.d.ts +4 -0
- package/dist/hooks/magic-context/compartment-runner-recomp-carry.d.ts.map +1 -0
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts +8 -2
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts +3 -5
- package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
- package/dist/{index-watde7a1.js → index-2pdgy88n.js} +3 -3
- package/dist/{index-c1s40xmj.js → index-39rzef89.js} +7 -5
- package/dist/{index-c5tmzym6.js → index-5df2fw5b.js} +108 -13
- package/dist/{index-7svecf3m.js → index-5pgyqgmx.js} +1 -1
- package/dist/{index-k50xhjw1.js → index-60x5d68t.js} +1 -1
- package/dist/{index-jka4y6mv.js → index-61knrt52.js} +1 -1
- package/dist/{index-74sh122g.js → index-9d3qgwq0.js} +1 -1
- package/dist/{index-2kf73btc.js → index-cr483vx6.js} +1 -1
- package/dist/{index-5nmqgvz2.js → index-dk3hy2a2.js} +6 -6
- package/dist/{index-awyqqnd8.js → index-g0mb2kb4.js} +6 -6
- package/dist/{index-kmrv1fw3.js → index-h9hybzr5.js} +2 -2
- package/dist/{index-vyfrgwhk.js → index-jzfsnbmm.js} +2 -2
- package/dist/{index-rvf1726x.js → index-mrjat4eq.js} +75 -12
- package/dist/{index-b364vr04.js → index-n1ty0vd3.js} +22 -22
- package/dist/{index-csztadkj.js → index-q7msfgwz.js} +272 -101
- package/dist/{index-pmcvg3k1.js → index-qfcjrnpe.js} +6 -5
- package/dist/{index-3dtzyred.js → index-r4y0dczp.js} +1 -1
- package/dist/{index-bxrfq3mv.js → index-tt0vs4x5.js} +1 -1
- package/dist/{index-3x4qvp29.js → index-w51n3576.js} +1 -1
- package/dist/{index-3jgzd7nz.js → index-wmb2mcdw.js} +3 -3
- package/dist/{index-zmqx48vt.js → index-xsqw8kbd.js} +1 -1
- package/dist/{index-hdyfvdag.js → index-zxhev8ze.js} +1 -1
- package/dist/index.js +26 -26
- package/dist/migration-worker.js +4 -4
- package/dist/{project-embedding-registry-8t0gwf59.js → project-embedding-registry-m3fp1pa4.js} +5 -5
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-2ztmtxt2.js → recomp-orchestrator-dgyb394j.js} +14 -14
- package/dist/{render-d6q6h9hy.js → render-d014e603.js} +6 -6
- package/dist/{search-d5aajhs3.js → search-9gceftb9.js} +11 -11
- package/dist/{search-archive-g96jn6p0.js → search-archive-gybn6q7s.js} +2 -2
- package/dist/shared/recomp-outcome.d.ts +4 -0
- package/dist/shared/recomp-outcome.d.ts.map +1 -0
- package/dist/shared/storage-permissions.d.ts +16 -2
- package/dist/shared/storage-permissions.d.ts.map +1 -1
- package/dist/shared/user-facing-codes.d.ts +4 -1
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-b2yjw8by.js → transform-postprocess-phase-34k1zwsy.js} +15 -15
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +5 -5
- package/dist/v2/{context-s86114yy.js → context-8bzydxfy.js} +21 -21
- package/dist/v2/{derive-budgets-ecjy1aqh.js → derive-budgets-hr4qqrnv.js} +3 -3
- package/dist/v2/{embedding-backfill-tazkbpyg.js → embedding-backfill-0ar1bm97.js} +6 -6
- package/dist/v2/embedding-worker.js +2 -2
- package/dist/v2/migration-worker.js +4 -4
- package/dist/v2/{project-embedding-registry-ah3gsg48.js → project-embedding-registry-gx2waee8.js} +5 -5
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{recomp-orchestrator-kc62xgb9.js → recomp-orchestrator-wq7gbkqa.js} +15 -15
- package/dist/v2/{render-j05per51.js → render-2dan17xc.js} +6 -6
- package/dist/v2/{search-archive-b4ptw02k.js → search-archive-89hdy0a2.js} +2 -2
- package/dist/v2/{search-kg31ad2s.js → search-nyqykx7q.js} +10 -10
- package/dist/v2/{server-ct0gs8fc.js → server-09h2vyvs.js} +2 -2
- package/dist/v2/{server-r2es6zt7.js → server-0tv6kytx.js} +108 -13
- package/dist/v2/{server-rz4snd3x.js → server-1rrmxhd1.js} +1 -1
- package/dist/v2/{server-xa8fefhw.js → server-96nm9vk4.js} +1 -1
- package/dist/v2/{server-2p0qayr1.js → server-a85j3kam.js} +1 -1
- package/dist/v2/{server-gwhj0362.js → server-add0j5n3.js} +7 -5
- package/dist/v2/{server-ff5wcfy4.js → server-b0a9h3ds.js} +2 -2
- package/dist/v2/{server-xn7zqs4j.js → server-dgjqvpgd.js} +3 -3
- package/dist/v2/{server-2r9btf0g.js → server-dtcwkdqj.js} +274 -103
- package/dist/v2/{server-axdmkvd5.js → server-f7tzvmzs.js} +1 -1
- package/dist/v2/{server-yh2z4gg2.js → server-fb5hvvfc.js} +75 -12
- package/dist/v2/{server-pbp58w5x.js → server-fn4ky6mn.js} +1 -1
- package/dist/v2/{server-3p6b0qya.js → server-gqkdfdvw.js} +1 -1
- package/dist/v2/{server-cwtehwbb.js → server-j4jjtdc5.js} +1 -1
- package/dist/v2/{server-b93f0bqh.js → server-pjk9spbf.js} +1 -1
- package/dist/v2/{server-gqrw0br5.js → server-ta4h0fch.js} +6 -6
- package/dist/v2/{server-e2k9mt86.js → server-tj65pgvg.js} +1 -1
- package/dist/v2/{server-6vnbz81n.js → server-vy0beygw.js} +1 -1
- package/dist/v2/server.js +5 -5
- package/dist/v2/{v2-archive-reader-2ayz16s4.js → v2-archive-reader-gh1jghf7.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-e20sjbdz.js → wrapup-orchestrator-2h7ayss9.js} +15 -15
- package/dist/{v2-archive-reader-x39mzvwn.js → v2-archive-reader-8158kyfd.js} +1 -1
- package/dist/{wrapup-orchestrator-h3s905vs.js → wrapup-orchestrator-ct59br0c.js} +15 -15
- package/package.json +1 -1
- package/src/shared/recomp-outcome.ts +8 -0
- package/src/shared/storage-permissions-startup.test.ts +296 -6
- package/src/shared/storage-permissions.ts +143 -18
- package/src/shared/user-facing-codes.ts +5 -2
- package/src/tui/dialogs/status-dialog.tsx +3 -0
- package/src/tui/slots/sidebar-content.tsx +6 -2
- package/src/tui-compiled/dialogs/status-dialog.tsx +12 -0
- package/src/tui-compiled/slots/sidebar-content.tsx +7 -2
|
@@ -19,13 +19,13 @@ import {
|
|
|
19
19
|
cortexKitProjectConfigBasePath,
|
|
20
20
|
resolveLegacyConfigSourcesForHarness,
|
|
21
21
|
loadPluginConfigDetailed
|
|
22
|
-
} from "./server-
|
|
22
|
+
} from "./server-tj65pgvg.js";
|
|
23
23
|
import {
|
|
24
24
|
catalogOutputReserve,
|
|
25
25
|
getSdkContextLimit,
|
|
26
26
|
modelSupportsVision,
|
|
27
27
|
getSdkOutputLimit
|
|
28
|
-
} from "./server-
|
|
28
|
+
} from "./server-96nm9vk4.js";
|
|
29
29
|
import {
|
|
30
30
|
withContentLanguageDirective,
|
|
31
31
|
buildPrimaryLanguageDirective,
|
|
@@ -210,7 +210,7 @@ import {
|
|
|
210
210
|
getProjectState,
|
|
211
211
|
recordSubagentInvocation,
|
|
212
212
|
getLatestHistorianInvocationId
|
|
213
|
-
} from "./server-
|
|
213
|
+
} from "./server-09h2vyvs.js";
|
|
214
214
|
import {
|
|
215
215
|
invalidateAutoEmbedSession
|
|
216
216
|
} from "./server-2amn2s73.js";
|
|
@@ -238,14 +238,14 @@ import {
|
|
|
238
238
|
import {
|
|
239
239
|
shouldSkipHomeProjectMemory,
|
|
240
240
|
resolveProjectIdentity
|
|
241
|
-
} from "./server-
|
|
241
|
+
} from "./server-1rrmxhd1.js";
|
|
242
242
|
import {
|
|
243
243
|
contentSha2562,
|
|
244
244
|
enqueueShadowEmbeddingItems2,
|
|
245
245
|
getProjectChunkEmbeddingModelId2,
|
|
246
246
|
getProjectEmbeddingMaxInputTokens2,
|
|
247
247
|
embedItemsWindowBounded2
|
|
248
|
-
} from "./server-
|
|
248
|
+
} from "./server-dgjqvpgd.js";
|
|
249
249
|
import {
|
|
250
250
|
V2_MEMORY_CATEGORIES,
|
|
251
251
|
CATEGORY_PRIORITY,
|
|
@@ -256,7 +256,7 @@ import {
|
|
|
256
256
|
userFacingFailureCode,
|
|
257
257
|
promoteSessionFactsDurable,
|
|
258
258
|
embedPromotedFacts
|
|
259
|
-
} from "./server-
|
|
259
|
+
} from "./server-add0j5n3.js";
|
|
260
260
|
import {
|
|
261
261
|
computeCueContentHash,
|
|
262
262
|
getMuralCueState,
|
|
@@ -270,7 +270,7 @@ import {
|
|
|
270
270
|
LATEST_SUPPORTED_VERSION,
|
|
271
271
|
getPersistedSchemaVersion,
|
|
272
272
|
openDatabase
|
|
273
|
-
} from "./server-
|
|
273
|
+
} from "./server-fb5hvvfc.js";
|
|
274
274
|
import {
|
|
275
275
|
parseCompartmentOutput,
|
|
276
276
|
resolveWorkspaceShareCategories,
|
|
@@ -279,7 +279,7 @@ import {
|
|
|
279
279
|
resolveStoredPathWorkspaceIdentity,
|
|
280
280
|
sourceNameForMemory,
|
|
281
281
|
computeWorkspaceEpochFingerprint
|
|
282
|
-
} from "./server-
|
|
282
|
+
} from "./server-a85j3kam.js";
|
|
283
283
|
import {
|
|
284
284
|
FAIL_CLOSED_DOCTOR_COMMAND
|
|
285
285
|
} from "./server-39bcszk4.js";
|
|
@@ -287,7 +287,7 @@ import {
|
|
|
287
287
|
getSessionNotes,
|
|
288
288
|
getReadySmartNotes,
|
|
289
289
|
insertPrimerCandidates
|
|
290
|
-
} from "./server-
|
|
290
|
+
} from "./server-fn4ky6mn.js";
|
|
291
291
|
import {
|
|
292
292
|
pushNotification2
|
|
293
293
|
} from "./server-y14pawe1.js";
|
|
@@ -295,7 +295,7 @@ import {
|
|
|
295
295
|
deriveTriggerBudget2,
|
|
296
296
|
resolveHistorianProducerLimits2,
|
|
297
297
|
producerSourceLocalBudget2
|
|
298
|
-
} from "./server-
|
|
298
|
+
} from "./server-j4jjtdc5.js";
|
|
299
299
|
import {
|
|
300
300
|
sendStatusNotification2
|
|
301
301
|
} from "./server-6250cxzs.js";
|
|
@@ -15663,15 +15663,54 @@ ${chunkText}`,
|
|
|
15663
15663
|
}
|
|
15664
15664
|
}
|
|
15665
15665
|
|
|
15666
|
+
// src/shared/recomp-outcome.ts
|
|
15667
|
+
var RECOMP_PAUSED_HEADING = "## Magic Recomp — Paused";
|
|
15668
|
+
function pausedRecompReason(message) {
|
|
15669
|
+
const prefix = `${RECOMP_PAUSED_HEADING}
|
|
15670
|
+
`;
|
|
15671
|
+
if (!message?.startsWith(prefix))
|
|
15672
|
+
return null;
|
|
15673
|
+
return message.slice(prefix.length).replace(/\s+/g, " ").trim();
|
|
15674
|
+
}
|
|
15675
|
+
|
|
15676
|
+
// src/hooks/magic-context/compartment-runner-recomp-carry.ts
|
|
15677
|
+
function compartmentToInput(c, sequence) {
|
|
15678
|
+
return {
|
|
15679
|
+
sequence,
|
|
15680
|
+
startMessage: c.startMessage,
|
|
15681
|
+
endMessage: c.endMessage,
|
|
15682
|
+
startMessageId: c.startMessageId,
|
|
15683
|
+
endMessageId: c.endMessageId,
|
|
15684
|
+
startBlockIndex: c.startBlockIndex,
|
|
15685
|
+
endBlockIndex: c.endBlockIndex,
|
|
15686
|
+
title: c.title,
|
|
15687
|
+
content: c.content,
|
|
15688
|
+
p1: c.p1,
|
|
15689
|
+
p2: c.p2,
|
|
15690
|
+
p3: c.p3,
|
|
15691
|
+
p4: c.p4,
|
|
15692
|
+
importance: c.importance,
|
|
15693
|
+
episodeType: c.episodeType
|
|
15694
|
+
};
|
|
15695
|
+
}
|
|
15696
|
+
|
|
15666
15697
|
// src/hooks/magic-context/compartment-runner-recomp.ts
|
|
15667
|
-
function insertRecompCompartmentRows(db, sessionId, compartments, now) {
|
|
15668
|
-
const stmt = db.prepare(
|
|
15698
|
+
function insertRecompCompartmentRows(db, sessionId, compartments, now, carriedRows) {
|
|
15699
|
+
const stmt = db.prepare(`INSERT INTO compartments (session_id, sequence, start_message, end_message,
|
|
15700
|
+
start_message_id, end_message_id, title, content, p1, p2, p3, p4, importance,
|
|
15701
|
+
episode_type, legacy, created_at, harness, start_block_index, end_block_index, rebase_status)
|
|
15702
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
|
|
15669
15703
|
for (const c of compartments) {
|
|
15670
15704
|
const hasTiers = typeof c.p1 === "string" && c.p1.length > 0;
|
|
15671
|
-
|
|
15705
|
+
const carried = carriedRows?.get(c.sequence);
|
|
15706
|
+
stmt.run(sessionId, c.sequence, c.startMessage, c.endMessage, c.startMessageId, c.endMessageId, c.title, c.content, c.p1 ?? null, c.p2 ?? null, c.p3 ?? null, c.p4 ?? null, typeof c.importance === "number" ? c.importance : 50, c.episodeType ?? null, carried?.legacy ?? (hasTiers ? 0 : 1), now, getHarness2(), c.startBlockIndex ?? null, c.endBlockIndex ?? null, carried?.rebaseStatus ?? "ok");
|
|
15672
15707
|
}
|
|
15673
15708
|
}
|
|
15674
|
-
function promoteRecompStagingWithM0Mutation(db, sessionId, holderId) {
|
|
15709
|
+
function promoteRecompStagingWithM0Mutation(db, sessionId, holderId, carriedRows) {
|
|
15710
|
+
const promoted = promoteRecompStaging(db, sessionId, holderId, undefined, carriedRows);
|
|
15711
|
+
return typeof promoted === "string" ? null : promoted;
|
|
15712
|
+
}
|
|
15713
|
+
function promoteRecompStaging(db, sessionId, holderId, stopped, carriedRows) {
|
|
15675
15714
|
const now = Date.now();
|
|
15676
15715
|
db.exec("BEGIN IMMEDIATE");
|
|
15677
15716
|
const transactionStartedAt = performance.now();
|
|
@@ -15680,18 +15719,40 @@ function promoteRecompStagingWithM0Mutation(db, sessionId, holderId) {
|
|
|
15680
15719
|
if (!isCompartmentLeaseHeld(db, sessionId, holderId)) {
|
|
15681
15720
|
db.exec("ROLLBACK");
|
|
15682
15721
|
finished = true;
|
|
15683
|
-
return
|
|
15722
|
+
return "lease-lost";
|
|
15684
15723
|
}
|
|
15685
15724
|
const staging = getRecompStaging(db, sessionId);
|
|
15686
|
-
|
|
15725
|
+
const staged = staging?.compartments.at(-1);
|
|
15726
|
+
if (!staging || !staged) {
|
|
15687
15727
|
db.exec("ROLLBACK");
|
|
15688
15728
|
finished = true;
|
|
15689
|
-
return
|
|
15729
|
+
return "staging-removed";
|
|
15730
|
+
}
|
|
15731
|
+
let carried = null;
|
|
15732
|
+
if (stopped) {
|
|
15733
|
+
const live = readLiveRanges(db, sessionId);
|
|
15734
|
+
const stagedEnd = resolvedOrdinal(sessionId, staged.endMessageId) ?? staged.endMessage;
|
|
15735
|
+
if (live.some((row) => row.end > stagedEnd)) {
|
|
15736
|
+
if (stopped.allowCarry)
|
|
15737
|
+
carried = readAlignedLiveTail(db, sessionId, live, staging, stagedEnd);
|
|
15738
|
+
if (!carried) {
|
|
15739
|
+
if (stopped.discardIfShort) {
|
|
15740
|
+
clearRecompStaging(db, sessionId);
|
|
15741
|
+
db.exec("COMMIT");
|
|
15742
|
+
finished = true;
|
|
15743
|
+
return "discarded";
|
|
15744
|
+
}
|
|
15745
|
+
db.exec("ROLLBACK");
|
|
15746
|
+
finished = true;
|
|
15747
|
+
return "would-shrink";
|
|
15748
|
+
}
|
|
15749
|
+
}
|
|
15690
15750
|
}
|
|
15751
|
+
const compartments = carried ? [...staging.compartments, ...carried.compartments] : staging.compartments;
|
|
15691
15752
|
deleteChunkEmbedBackoffForSession2(db, sessionId);
|
|
15692
15753
|
db.prepare("DELETE FROM compartments WHERE session_id = ?").run(sessionId);
|
|
15693
15754
|
db.prepare("DELETE FROM session_facts WHERE session_id = ?").run(sessionId);
|
|
15694
|
-
insertRecompCompartmentRows(db, sessionId,
|
|
15755
|
+
insertRecompCompartmentRows(db, sessionId, compartments, now, carried?.rows ?? carriedRows);
|
|
15695
15756
|
queueM0Mutation(db, {
|
|
15696
15757
|
sessionId,
|
|
15697
15758
|
mutationType: "recomp_boundary_change",
|
|
@@ -15705,7 +15766,12 @@ function promoteRecompStagingWithM0Mutation(db, sessionId, holderId) {
|
|
|
15705
15766
|
finished = true;
|
|
15706
15767
|
invalidateAutoEmbedSession(sessionId);
|
|
15707
15768
|
logSlowWriteTransaction("historian-publish:recomp", transactionStartedAt);
|
|
15708
|
-
return {
|
|
15769
|
+
return {
|
|
15770
|
+
compartments,
|
|
15771
|
+
facts: staging.facts,
|
|
15772
|
+
carriedCount: carried?.compartments.length ?? 0,
|
|
15773
|
+
carriedThrough: carried?.end ?? null
|
|
15774
|
+
};
|
|
15709
15775
|
} finally {
|
|
15710
15776
|
if (!finished) {
|
|
15711
15777
|
try {
|
|
@@ -15714,6 +15780,69 @@ function promoteRecompStagingWithM0Mutation(db, sessionId, holderId) {
|
|
|
15714
15780
|
}
|
|
15715
15781
|
}
|
|
15716
15782
|
}
|
|
15783
|
+
function resolvedOrdinal(sessionId, id) {
|
|
15784
|
+
return id ? readRawSessionMessageOrdinalById2(sessionId, id) : null;
|
|
15785
|
+
}
|
|
15786
|
+
function readLiveRanges(db, sessionId) {
|
|
15787
|
+
const rows = db.prepare(`SELECT sequence, start_message, start_message_id, end_message, end_message_id FROM compartments
|
|
15788
|
+
WHERE session_id = ? ORDER BY sequence`).all(sessionId);
|
|
15789
|
+
return rows.map((row) => {
|
|
15790
|
+
const resolvedEnd = resolvedOrdinal(sessionId, row.end_message_id);
|
|
15791
|
+
return { ...row, end: resolvedEnd ?? row.end_message, resolvedEnd };
|
|
15792
|
+
});
|
|
15793
|
+
}
|
|
15794
|
+
function readAlignedLiveTail(db, sessionId, live, staging, stagedEnd) {
|
|
15795
|
+
let next = 1;
|
|
15796
|
+
let seam;
|
|
15797
|
+
for (const row of live) {
|
|
15798
|
+
const start = resolvedOrdinal(sessionId, row.start_message_id);
|
|
15799
|
+
if ((start ?? row.start_message) !== next || row.end < next)
|
|
15800
|
+
return null;
|
|
15801
|
+
if (seam !== undefined && (start === null || row.resolvedEnd === null))
|
|
15802
|
+
return null;
|
|
15803
|
+
if (row.end === stagedEnd)
|
|
15804
|
+
seam = row.sequence;
|
|
15805
|
+
next = row.end + 1;
|
|
15806
|
+
}
|
|
15807
|
+
if (seam === undefined)
|
|
15808
|
+
return null;
|
|
15809
|
+
const seamSequence = seam;
|
|
15810
|
+
const tail = getCompartments(db, sessionId).filter((row) => row.sequence > seamSequence);
|
|
15811
|
+
if (!tail.length || tail.length !== live.filter((row) => row.sequence > seamSequence).length)
|
|
15812
|
+
return null;
|
|
15813
|
+
return {
|
|
15814
|
+
compartments: tail.map((row, index) => compartmentToInput(row, staging.compartments.length + index)),
|
|
15815
|
+
rows: new Map(tail.map((row, index) => [staging.compartments.length + index, row])),
|
|
15816
|
+
end: next - 1
|
|
15817
|
+
};
|
|
15818
|
+
}
|
|
15819
|
+
function getResumableFullStaging(db, sessionId, rawMessageCount) {
|
|
15820
|
+
const staging = getRecompStaging(db, sessionId);
|
|
15821
|
+
let reason = null;
|
|
15822
|
+
if (getRecompPartialRange(db, sessionId)) {
|
|
15823
|
+
reason = "the staged passes were for a range rebuild";
|
|
15824
|
+
} else if (staging) {
|
|
15825
|
+
reason = validateStoredCompartments(staging.compartments);
|
|
15826
|
+
if (!reason) {
|
|
15827
|
+
const ordinals = readRawSessionMessageIdOrdinalsForRange2(sessionId, 1, Math.min(rawMessageCount, staging.lastEndMessage));
|
|
15828
|
+
if (staging.compartments.some(({ startMessage, endMessage, startMessageId, endMessageId }) => ordinals.get(startMessageId) !== startMessage || ordinals.get(endMessageId) !== endMessage)) {
|
|
15829
|
+
reason = "staged endpoints no longer match the raw history";
|
|
15830
|
+
}
|
|
15831
|
+
}
|
|
15832
|
+
}
|
|
15833
|
+
if (!reason)
|
|
15834
|
+
return staging;
|
|
15835
|
+
clearRecompStaging(db, sessionId);
|
|
15836
|
+
sessionLog2(sessionId, `recomp discarded staging: ${reason}`);
|
|
15837
|
+
return null;
|
|
15838
|
+
}
|
|
15839
|
+
var PUBLISH_LEASE_LOST = `## Magic Recomp — Skipped
|
|
15840
|
+
|
|
15841
|
+
Another process acquired the compartment-state lease before recomp could publish. No state was written.`;
|
|
15842
|
+
var STAGING_REMOVED = `## Magic Recomp — Failed
|
|
15843
|
+
|
|
15844
|
+
The unfinished rebuild was removed because the session's history changed. Nothing was published.
|
|
15845
|
+
Run /ctx-recomp again.`;
|
|
15717
15846
|
async function executeContextRecompInternal(deps) {
|
|
15718
15847
|
const {
|
|
15719
15848
|
client,
|
|
@@ -15756,6 +15885,12 @@ Session ordinals are warming in the background. Retry shortly; no history was re
|
|
|
15756
15885
|
updateSessionMeta(db, sessionId, { compartmentInProgress: true });
|
|
15757
15886
|
try {
|
|
15758
15887
|
const rawMessageCount = getRawSessionMessageCount2(sessionId);
|
|
15888
|
+
const existingStaging = getResumableFullStaging(db, sessionId, rawMessageCount);
|
|
15889
|
+
if (rawMessageCount <= 0) {
|
|
15890
|
+
return `## Magic Recomp
|
|
15891
|
+
|
|
15892
|
+
No raw history exists, so nothing was rebuilt.`;
|
|
15893
|
+
}
|
|
15759
15894
|
const boundarySnapshot = resolveOpenCodeProtectedTailBoundary({
|
|
15760
15895
|
db,
|
|
15761
15896
|
sessionId,
|
|
@@ -15766,21 +15901,21 @@ Session ordinals are warming in the background. Retry shortly; no history was re
|
|
|
15766
15901
|
usageSource: "provisional-zero"
|
|
15767
15902
|
});
|
|
15768
15903
|
const protectedTailStart = Math.min(boundarySnapshot.protectedTailStart, rawMessageCount + 1);
|
|
15769
|
-
if (
|
|
15770
|
-
return `## Magic Recomp
|
|
15904
|
+
if (!existingStaging && protectedTailStart === 1) {
|
|
15905
|
+
return `## Magic Recomp — Skipped
|
|
15771
15906
|
|
|
15772
|
-
|
|
15907
|
+
Nothing to rebuild yet: every message is still in the recent part that is kept raw.`;
|
|
15773
15908
|
}
|
|
15774
15909
|
const parentSessionResponse = await client?.session.get({ path: { id: sessionId } }).catch(() => null);
|
|
15775
15910
|
const parentSession = normalizeSDKResponse(parentSessionResponse, null, { preferResponseOnMissingData: true });
|
|
15776
15911
|
const sessionDirectory = parentSession?.directory ?? directory;
|
|
15777
|
-
const existingStaging = getRecompStaging(db, sessionId);
|
|
15778
15912
|
let candidateCompartments = existingStaging?.compartments ?? [];
|
|
15779
15913
|
let candidateFacts = existingStaging?.facts ?? [];
|
|
15780
15914
|
let offset = existingStaging ? existingStaging.lastEndMessage + 1 : 1;
|
|
15781
15915
|
let passCount = existingStaging?.passCount ?? 0;
|
|
15782
15916
|
let currentTokenBudget = historianChunkTokens;
|
|
15783
15917
|
let passAttempt = 1;
|
|
15918
|
+
let hadModelFailureOrBudgetReduction = false;
|
|
15784
15919
|
const resumed = existingStaging !== null;
|
|
15785
15920
|
if (resumed) {
|
|
15786
15921
|
await sendStatusNotification2(client, sessionId, `## Magic Recomp — Resumed
|
|
@@ -15805,19 +15940,53 @@ Found ${existingStaging.compartments.length} staged compartment(s) from ${existi
|
|
|
15805
15940
|
} catch {}
|
|
15806
15941
|
};
|
|
15807
15942
|
emitProgress("Preparing…");
|
|
15808
|
-
async function promoteAndFinalize(reason) {
|
|
15943
|
+
async function promoteAndFinalize(reason, heading = "Partial", failure = "recomp_unavailable", sentence, deterministicStop = false) {
|
|
15809
15944
|
if (passCount === 0 || candidateCompartments.length === 0)
|
|
15810
15945
|
return null;
|
|
15811
15946
|
const mergedError = validateStoredCompartments(candidateCompartments);
|
|
15812
15947
|
if (mergedError)
|
|
15813
15948
|
return null;
|
|
15814
|
-
saveRecompStagingPass(db, sessionId, passCount, candidateCompartments, candidateFacts);
|
|
15815
15949
|
const lastCompartmentEnd = candidateCompartments[candidateCompartments.length - 1]?.endMessage ?? 0;
|
|
15816
15950
|
const compartmentTagKeys = lastCompartmentEnd > 0 ? await getRawSessionTagKeysThrough2(sessionId, lastCompartmentEnd, { db }) : null;
|
|
15817
|
-
const promoted =
|
|
15818
|
-
|
|
15819
|
-
|
|
15820
|
-
|
|
15951
|
+
const promoted = promoteRecompStaging(db, sessionId, leaseHolderId, {
|
|
15952
|
+
allowCarry: heading === "Complete",
|
|
15953
|
+
discardIfShort: deterministicStop && passAttempt === 1 && !hadModelFailureOrBudgetReduction && resumed && passCount === existingStaging.passCount
|
|
15954
|
+
});
|
|
15955
|
+
if (promoted === "would-shrink" || promoted === "discarded") {
|
|
15956
|
+
const detail = renderUserFacingFailure(failure, "markdown", {
|
|
15957
|
+
sentence,
|
|
15958
|
+
...failure !== "historian_window_too_small" ? { action: "" } : {}
|
|
15959
|
+
});
|
|
15960
|
+
if (promoted === "discarded") {
|
|
15961
|
+
return [
|
|
15962
|
+
"## Magic Recomp — Failed",
|
|
15963
|
+
"",
|
|
15964
|
+
`The rebuild could not get past message ${offset}. ${detail}`,
|
|
15965
|
+
"The unfinished rebuild was discarded.",
|
|
15966
|
+
"Your current history is unchanged."
|
|
15967
|
+
].join(`
|
|
15968
|
+
`);
|
|
15969
|
+
}
|
|
15970
|
+
const continueFrom = `Run /ctx-recomp again to continue from message ${lastCompartmentEnd + 1}.`;
|
|
15971
|
+
return [
|
|
15972
|
+
RECOMP_PAUSED_HEADING,
|
|
15973
|
+
"",
|
|
15974
|
+
resumed ? `Messages 1-${lastCompartmentEnd} of ${totalMessages} are rebuilt and kept for the next run. ${detail}` : `Rebuilt messages 1-${lastCompartmentEnd} of ${totalMessages}, then stopped. ${detail}`,
|
|
15975
|
+
"Your current history is unchanged.",
|
|
15976
|
+
deterministicStop ? `${continueFrom} If it stops at the same place again, the unfinished rebuild is discarded and your history stays as it is.` : continueFrom
|
|
15977
|
+
].join(`
|
|
15978
|
+
`);
|
|
15979
|
+
}
|
|
15980
|
+
if (promoted === "lease-lost")
|
|
15981
|
+
return PUBLISH_LEASE_LOST;
|
|
15982
|
+
if (promoted === "staging-removed")
|
|
15983
|
+
return STAGING_REMOVED;
|
|
15984
|
+
afterPublish("compression-depth", () => {
|
|
15985
|
+
if (promoted.carriedCount > 0)
|
|
15986
|
+
clearCompressionDepthRange(db, sessionId, 1, lastCompartmentEnd);
|
|
15987
|
+
else
|
|
15988
|
+
clearCompressionDepth(db, sessionId);
|
|
15989
|
+
});
|
|
15821
15990
|
if (deps.preserveInjectionCacheUntilConsumed !== true) {
|
|
15822
15991
|
clearInjectionCache(sessionId);
|
|
15823
15992
|
}
|
|
@@ -15837,9 +16006,10 @@ Found ${existingStaging.compartments.length} staged compartment(s) from ${existi
|
|
|
15837
16006
|
afterPublish("drop-queue", () => queueDropsForCompartmentalizedMessages(db, sessionId, lastCompartmentEnd, compartmentTagKeys));
|
|
15838
16007
|
}
|
|
15839
16008
|
afterPublish("publication-signal", () => deps.onCompartmentStatePublished?.(sessionId));
|
|
15840
|
-
|
|
16009
|
+
const publishedEnd = promoted.carriedThrough ?? lastCompartmentEnd;
|
|
16010
|
+
if (publishedEnd > 0) {
|
|
15841
16011
|
afterPublish("compaction-marker", () => {
|
|
15842
|
-
const markerUpdated = (deps.compactionMarkerStrategy?.publish ?? updateCompactionMarkerAfterPublication)(db, sessionId,
|
|
16012
|
+
const markerUpdated = (deps.compactionMarkerStrategy?.publish ?? updateCompactionMarkerAfterPublication)(db, sessionId, publishedEnd, deps.directory);
|
|
15843
16013
|
if (markerUpdated) {
|
|
15844
16014
|
const stalePending = getPendingCompactionMarkerState(db, sessionId);
|
|
15845
16015
|
if (stalePending) {
|
|
@@ -15848,8 +16018,26 @@ Found ${existingStaging.compartments.length} staged compartment(s) from ${existi
|
|
|
15848
16018
|
}
|
|
15849
16019
|
});
|
|
15850
16020
|
}
|
|
16021
|
+
const rebuilt = promoted.compartments.length - promoted.carriedCount;
|
|
16022
|
+
const rebuiltThrough = `Rebuilt ${rebuilt} history block${rebuilt === 1 ? "" : "s"} through message ${lastCompartmentEnd}.`;
|
|
16023
|
+
if (promoted.carriedCount > 0) {
|
|
16024
|
+
return [
|
|
16025
|
+
"## Magic Recomp — Complete",
|
|
16026
|
+
"",
|
|
16027
|
+
rebuiltThrough,
|
|
16028
|
+
`Kept ${promoted.carriedCount} existing history block${promoted.carriedCount === 1 ? "" : "s"} through message ${publishedEnd}.`
|
|
16029
|
+
].join(`
|
|
16030
|
+
`);
|
|
16031
|
+
}
|
|
16032
|
+
if (heading === "Complete") {
|
|
16033
|
+
return `## Magic Recomp — Complete
|
|
16034
|
+
|
|
16035
|
+
${rebuiltThrough} Messages ${offset} to ${protectedTailStart - 1} have nothing to summarize and stay as they are.`;
|
|
16036
|
+
}
|
|
15851
16037
|
sessionLog2(sessionId, `recomp partial code=${userFacingFailureCode("recomp_unavailable")} reason="${reason}"`);
|
|
15852
16038
|
return [
|
|
16039
|
+
`## Magic Recomp — ${heading}`,
|
|
16040
|
+
"",
|
|
15853
16041
|
`Rebuilt ${promoted.compartments.length} history block${promoted.compartments.length === 1 ? "" : "s"} across ${passCount} successful pass${passCount === 1 ? "" : "es"}.`,
|
|
15854
16042
|
renderUserFacingFailure("recomp_unavailable")
|
|
15855
16043
|
].join(`
|
|
@@ -15879,12 +16067,9 @@ Found ${existingStaging.compartments.length} staged compartment(s) from ${existi
|
|
|
15879
16067
|
compartmentsProduced: 0
|
|
15880
16068
|
});
|
|
15881
16069
|
sessionLog2(sessionId, `recomp failed code=${userFacingFailureCode("historian_window_too_small")} reason="${promptFit.reason}"`);
|
|
15882
|
-
const partial = await promoteAndFinalize(`the history model's window cannot hold a historian prompt: ${promptFit.reason}
|
|
15883
|
-
if (partial)
|
|
15884
|
-
return
|
|
15885
|
-
|
|
15886
|
-
${partial}`;
|
|
15887
|
-
}
|
|
16070
|
+
const partial = await promoteAndFinalize(`the history model's window cannot hold a historian prompt: ${promptFit.reason}`, "Partial", "historian_window_too_small");
|
|
16071
|
+
if (partial)
|
|
16072
|
+
return partial;
|
|
15888
16073
|
return `## Magic Recomp — Failed
|
|
15889
16074
|
|
|
15890
16075
|
${renderUserFacingFailure("historian_window_too_small")}`;
|
|
@@ -15892,26 +16077,22 @@ ${renderUserFacingFailure("historian_window_too_small")}`;
|
|
|
15892
16077
|
if (promptFit.trimmed || promptFit.chunkTokens < currentTokenBudget) {
|
|
15893
16078
|
sessionLog2(sessionId, `recomp prompt fit: ${describeHistorianPromptTrim(promptFit)} requestedChunkTokens=${currentTokenBudget}`);
|
|
15894
16079
|
}
|
|
16080
|
+
if (promptFit.chunkTokens < currentTokenBudget)
|
|
16081
|
+
hadModelFailureOrBudgetReduction = true;
|
|
15895
16082
|
const chunk = readSessionChunk2(sessionId, promptFit.chunkTokens, offset, protectedTailStart, { expandTools: deps.historianExpandTools });
|
|
15896
16083
|
if (!chunk.text || chunk.messageCount === 0 || chunk.endIndex < offset) {
|
|
15897
|
-
const promoted = await promoteAndFinalize(`remaining messages ${offset}-${protectedTailStart - 1} were too few or all noise to form a historian chunk`);
|
|
15898
|
-
if (promoted)
|
|
15899
|
-
return
|
|
15900
|
-
|
|
15901
|
-
${promoted}`;
|
|
15902
|
-
}
|
|
16084
|
+
const promoted = await promoteAndFinalize(`remaining messages ${offset}-${protectedTailStart - 1} were too few or all noise to form a historian chunk`, "Complete", "recomp_unavailable", `Raw history ${offset}-${protectedTailStart - 1} could not be turned into a valid historian chunk.`, true);
|
|
16085
|
+
if (promoted)
|
|
16086
|
+
return promoted;
|
|
15903
16087
|
return `## Magic Recomp — Failed
|
|
15904
16088
|
|
|
15905
16089
|
Recomp stopped because raw history ${offset}-${protectedTailStart - 1} could not be turned into a valid historian chunk. Nothing was written.`;
|
|
15906
16090
|
}
|
|
15907
16091
|
const chunkCoverageError = validateChunkCoverage(chunk);
|
|
15908
16092
|
if (chunkCoverageError) {
|
|
15909
|
-
const partial = await promoteAndFinalize(`chunk could not be represented safely: ${chunkCoverageError}
|
|
15910
|
-
if (partial)
|
|
15911
|
-
return
|
|
15912
|
-
|
|
15913
|
-
${partial}`;
|
|
15914
|
-
}
|
|
16093
|
+
const partial = await promoteAndFinalize(`chunk could not be represented safely: ${chunkCoverageError}`, "Partial", "recomp_unavailable", "The next chunk could not be represented safely.", true);
|
|
16094
|
+
if (partial)
|
|
16095
|
+
return partial;
|
|
15915
16096
|
sessionLog2(sessionId, `recomp failed code=${userFacingFailureCode("recomp_unavailable")} reason="${chunkCoverageError}"`);
|
|
15916
16097
|
return `## Magic Recomp — Failed
|
|
15917
16098
|
|
|
@@ -15953,6 +16134,7 @@ Historian pass ${passCount + 1}, attempt ${passAttempt} started for messages ${c
|
|
|
15953
16134
|
language: deps.language,
|
|
15954
16135
|
callbacks: {
|
|
15955
16136
|
onRepairRetry: async (error) => {
|
|
16137
|
+
hadModelFailureOrBudgetReduction = true;
|
|
15956
16138
|
emitProgress(`Repair retry (pass ${passCount + 1})…`);
|
|
15957
16139
|
sessionLog2(sessionId, `recomp retry code=${userFacingFailureCode("recomp_unavailable")} reason="${error}"`);
|
|
15958
16140
|
await sendStatusNotification2(client, sessionId, `## Magic Recomp
|
|
@@ -15960,12 +16142,14 @@ Historian pass ${passCount + 1}, attempt ${passAttempt} started for messages ${c
|
|
|
15960
16142
|
History compression is retrying this pass. ${renderUserFacingFailure("recomp_unavailable")}`, notifParams());
|
|
15961
16143
|
},
|
|
15962
16144
|
onModelFallback: (modelId, index, total) => {
|
|
16145
|
+
hadModelFailureOrBudgetReduction = true;
|
|
15963
16146
|
const short = modelId.includes("/") ? modelId.split("/").pop() : modelId;
|
|
15964
16147
|
emitProgress(`Trying fallback ${short} (${index}/${total})…`);
|
|
15965
16148
|
}
|
|
15966
16149
|
}
|
|
15967
16150
|
});
|
|
15968
16151
|
if (!validatedPass.ok) {
|
|
16152
|
+
hadModelFailureOrBudgetReduction = true;
|
|
15969
16153
|
const reducedBudget = getReducedRecompTokenBudget(promptFit.chunkTokens);
|
|
15970
16154
|
if (reducedBudget !== null) {
|
|
15971
16155
|
const smallerChunk = readSessionChunk2(sessionId, reducedBudget, offset, protectedTailStart, { expandTools: deps.historianExpandTools });
|
|
@@ -15991,11 +16175,8 @@ History compression is retrying with a smaller set of messages. ${renderUserFaci
|
|
|
15991
16175
|
});
|
|
15992
16176
|
sessionLog2(sessionId, `recomp failed code=${userFacingFailureCode("recomp_unavailable")} reason="${validatedPass.error}" messageRange=${chunk.startIndex}-${chunk.endIndex}`);
|
|
15993
16177
|
const partial = await promoteAndFinalize(`history model response did not validate for messages ${chunk.startIndex}-${chunk.endIndex}`);
|
|
15994
|
-
if (partial)
|
|
15995
|
-
return
|
|
15996
|
-
|
|
15997
|
-
${partial}`;
|
|
15998
|
-
}
|
|
16178
|
+
if (partial)
|
|
16179
|
+
return partial;
|
|
15999
16180
|
return `## Magic Recomp — Failed
|
|
16000
16181
|
|
|
16001
16182
|
${renderUserFacingFailure("recomp_unavailable")}`;
|
|
@@ -16022,6 +16203,17 @@ ${renderUserFacingFailure("recomp_unavailable")}`;
|
|
|
16022
16203
|
importanceAvg: imp.avg
|
|
16023
16204
|
});
|
|
16024
16205
|
}
|
|
16206
|
+
const nextOffset = (validatedPass.compartments?.[validatedPass.compartments.length - 1]?.endMessage ?? chunk.endIndex) + 1;
|
|
16207
|
+
if (nextOffset <= offset) {
|
|
16208
|
+
const reason = `Recomp made no forward progress after messages ${chunk.startIndex}-${chunk.endIndex}.`;
|
|
16209
|
+
const partial = await promoteAndFinalize(reason, "Partial", "recomp_unavailable", reason, true);
|
|
16210
|
+
if (partial)
|
|
16211
|
+
return partial;
|
|
16212
|
+
return `## Magic Recomp — Failed
|
|
16213
|
+
|
|
16214
|
+
${reason} Nothing was written.`;
|
|
16215
|
+
}
|
|
16216
|
+
const hadStagedPrefix = candidateCompartments.length > 0;
|
|
16025
16217
|
candidateCompartments = [
|
|
16026
16218
|
...candidateCompartments,
|
|
16027
16219
|
...validatedPass.compartments ?? []
|
|
@@ -16030,19 +16222,14 @@ ${renderUserFacingFailure("recomp_unavailable")}`;
|
|
|
16030
16222
|
passCount += 1;
|
|
16031
16223
|
currentTokenBudget = historianChunkTokens;
|
|
16032
16224
|
passAttempt = 1;
|
|
16033
|
-
|
|
16034
|
-
|
|
16035
|
-
|
|
16036
|
-
|
|
16037
|
-
|
|
16038
|
-
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
}
|
|
16042
|
-
return `## Magic Recomp — Failed
|
|
16043
|
-
|
|
16044
|
-
Recomp made no forward progress after messages ${chunk.startIndex}-${chunk.endIndex}. Nothing was written.`;
|
|
16045
|
-
}
|
|
16225
|
+
const saved = db.transaction(() => {
|
|
16226
|
+
if (hadStagedPrefix && !db.prepare("SELECT 1 FROM recomp_compartments WHERE session_id = ? LIMIT 1").get(sessionId))
|
|
16227
|
+
return false;
|
|
16228
|
+
saveRecompStagingPass(db, sessionId, passCount, candidateCompartments, candidateFacts);
|
|
16229
|
+
return true;
|
|
16230
|
+
}).immediate();
|
|
16231
|
+
if (!saved)
|
|
16232
|
+
return STAGING_REMOVED;
|
|
16046
16233
|
offset = nextOffset;
|
|
16047
16234
|
emitProgress();
|
|
16048
16235
|
}
|
|
@@ -16054,15 +16241,15 @@ Recomp made no forward progress after messages ${chunk.startIndex}-${chunk.endIn
|
|
|
16054
16241
|
|
|
16055
16242
|
${renderUserFacingFailure("recomp_unavailable")}`;
|
|
16056
16243
|
}
|
|
16057
|
-
saveRecompStagingPass(db, sessionId, passCount, candidateCompartments, candidateFacts);
|
|
16058
16244
|
const lastCompartmentEnd = candidateCompartments[candidateCompartments.length - 1]?.endMessage ?? 0;
|
|
16059
16245
|
const compartmentTagKeys = lastCompartmentEnd > 0 ? await getRawSessionTagKeysThrough2(sessionId, lastCompartmentEnd, { db }) : null;
|
|
16060
|
-
const promoted =
|
|
16061
|
-
if (
|
|
16246
|
+
const promoted = promoteRecompStaging(db, sessionId, leaseHolderId);
|
|
16247
|
+
if (promoted === "staging-removed") {
|
|
16248
|
+
return candidateCompartments.length > 0 ? STAGING_REMOVED : PUBLISH_LEASE_LOST;
|
|
16249
|
+
}
|
|
16250
|
+
if (typeof promoted === "string") {
|
|
16062
16251
|
sessionLog2(sessionId, "recomp publish skipped: compartment lease no longer held");
|
|
16063
|
-
return
|
|
16064
|
-
|
|
16065
|
-
Another process acquired the compartment-state lease before recomp could publish. No state was written.`;
|
|
16252
|
+
return PUBLISH_LEASE_LOST;
|
|
16066
16253
|
}
|
|
16067
16254
|
afterPublish("compression-depth", () => clearCompressionDepth(db, sessionId));
|
|
16068
16255
|
if (deps.preserveInjectionCacheUntilConsumed !== true) {
|
|
@@ -16155,25 +16342,6 @@ function snapRangeToCompartments(compartments, range) {
|
|
|
16155
16342
|
tailCompartments: sorted.slice(lastEnclosingIdx + 1)
|
|
16156
16343
|
};
|
|
16157
16344
|
}
|
|
16158
|
-
function compartmentToInput(c, newSequence) {
|
|
16159
|
-
return {
|
|
16160
|
-
sequence: newSequence,
|
|
16161
|
-
startMessage: c.startMessage,
|
|
16162
|
-
endMessage: c.endMessage,
|
|
16163
|
-
startMessageId: c.startMessageId,
|
|
16164
|
-
endMessageId: c.endMessageId,
|
|
16165
|
-
startBlockIndex: c.startBlockIndex,
|
|
16166
|
-
endBlockIndex: c.endBlockIndex,
|
|
16167
|
-
title: c.title,
|
|
16168
|
-
content: c.content,
|
|
16169
|
-
p1: c.p1,
|
|
16170
|
-
p2: c.p2,
|
|
16171
|
-
p3: c.p3,
|
|
16172
|
-
p4: c.p4,
|
|
16173
|
-
importance: c.importance,
|
|
16174
|
-
episodeType: c.episodeType
|
|
16175
|
-
};
|
|
16176
|
-
}
|
|
16177
16345
|
async function executePartialRecompInternal(deps, range) {
|
|
16178
16346
|
const {
|
|
16179
16347
|
client,
|
|
@@ -16193,6 +16361,7 @@ Could not acquire the compartment-state lease for this session.`;
|
|
|
16193
16361
|
}
|
|
16194
16362
|
const leaseHolderId = holderId;
|
|
16195
16363
|
updateSessionMeta(db, sessionId, { compartmentInProgress: true });
|
|
16364
|
+
let wroteStaging = false;
|
|
16196
16365
|
try {
|
|
16197
16366
|
let promoteFinal = function() {
|
|
16198
16367
|
const newBuilt = candidateCompartments.slice(priorCompartments.length);
|
|
@@ -16228,7 +16397,12 @@ Could not acquire the compartment-state lease for this session.`;
|
|
|
16228
16397
|
return null;
|
|
16229
16398
|
}
|
|
16230
16399
|
saveRecompStagingPass(db, sessionId, passCount + 1, merged, stagedFacts);
|
|
16231
|
-
|
|
16400
|
+
wroteStaging = true;
|
|
16401
|
+
const carriedRows = new Map([
|
|
16402
|
+
...priorCompartments.map((c, idx) => [idx, c]),
|
|
16403
|
+
...tailCompartments.map((c, idx) => [candidateCompartments.length + idx, c])
|
|
16404
|
+
]);
|
|
16405
|
+
const promoted = promoteRecompStagingWithM0Mutation(db, sessionId, leaseHolderId, carriedRows);
|
|
16232
16406
|
if (!promoted) {
|
|
16233
16407
|
log2("[magic-context] partial recomp promote returned null");
|
|
16234
16408
|
return null;
|
|
@@ -16277,8 +16451,7 @@ ${snapResult.error}`;
|
|
|
16277
16451
|
"",
|
|
16278
16452
|
`An unfinished partial recomp is already staged for range ${storedRange.start}-${storedRange.end}, which does not match the requested range ${snapStart}-${snapEnd}.`,
|
|
16279
16453
|
"",
|
|
16280
|
-
"
|
|
16281
|
-
"or cancel it by running `/ctx-flush` before starting a new partial recomp."
|
|
16454
|
+
"Finish that range by running `/ctx-recomp` with the same original arguments, or run `/ctx-recomp` without arguments to start a full rebuild."
|
|
16282
16455
|
].join(`
|
|
16283
16456
|
`);
|
|
16284
16457
|
}
|
|
@@ -16286,9 +16459,7 @@ ${snapResult.error}`;
|
|
|
16286
16459
|
return [
|
|
16287
16460
|
"## Magic Recomp — Failed",
|
|
16288
16461
|
"",
|
|
16289
|
-
|
|
16290
|
-
"Resume it by running `/ctx-recomp` without arguments,",
|
|
16291
|
-
"or cancel it before starting a partial recomp."
|
|
16462
|
+
`A full rebuild is paused at message ${existingStaging.lastEndMessage}. Run \`/ctx-recomp\` without arguments to continue it. A partial recomp can start when it completes or is discarded.`
|
|
16292
16463
|
].join(`
|
|
16293
16464
|
`);
|
|
16294
16465
|
}
|
|
@@ -16310,6 +16481,7 @@ ${snapResult.error}`;
|
|
|
16310
16481
|
passCount = 0;
|
|
16311
16482
|
offset = snapStart;
|
|
16312
16483
|
saveRecompStagingPass(db, sessionId, 0, candidateCompartments, stagedFacts);
|
|
16484
|
+
wroteStaging = true;
|
|
16313
16485
|
setRecompPartialRange(db, sessionId, { start: snapStart, end: snapEnd });
|
|
16314
16486
|
}
|
|
16315
16487
|
let currentTokenBudget = historianChunkTokens;
|
|
@@ -16419,6 +16591,7 @@ ${renderUserFacingFailure("recomp_unavailable")}`;
|
|
|
16419
16591
|
currentTokenBudget = historianChunkTokens;
|
|
16420
16592
|
passAttempt = 1;
|
|
16421
16593
|
saveRecompStagingPass(db, sessionId, passCount, candidateCompartments, stagedFacts);
|
|
16594
|
+
wroteStaging = true;
|
|
16422
16595
|
const nextOffset = (validatedPass.compartments?.[validatedPass.compartments.length - 1]?.endMessage ?? chunk.endIndex) + 1;
|
|
16423
16596
|
if (nextOffset <= offset) {
|
|
16424
16597
|
return `## Magic Recomp — Failed
|
|
@@ -16450,9 +16623,7 @@ Partial recomp completed historian passes but the final compartment set failed v
|
|
|
16450
16623
|
${renderUserFacingFailure("recomp_unavailable")}`;
|
|
16451
16624
|
} finally {
|
|
16452
16625
|
updateSessionMeta(db, sessionId, { compartmentInProgress: false });
|
|
16453
|
-
|
|
16454
|
-
const leftoverRange = getRecompPartialRange(db, sessionId);
|
|
16455
|
-
if (leftoverStaging && leftoverRange) {} else if (leftoverStaging && !leftoverRange) {
|
|
16626
|
+
if (wroteStaging && getRecompStaging(db, sessionId) && !getRecompPartialRange(db, sessionId)) {
|
|
16456
16627
|
log2(`[magic-context] partial recomp cleanup: clearing orphaned staging without range marker for session ${sessionId}`);
|
|
16457
16628
|
clearRecompStaging(db, sessionId);
|
|
16458
16629
|
}
|
|
@@ -16658,7 +16829,7 @@ function resolveLiveModelKey(liveSessionState, sessionId) {
|
|
|
16658
16829
|
return model ? `${model.providerID}/${model.modelID}` : undefined;
|
|
16659
16830
|
}
|
|
16660
16831
|
function isRecompFailure2(message) {
|
|
16661
|
-
return /—\s*(Failed|Skipped)/.test(message);
|
|
16832
|
+
return /—\s*(Failed|Skipped|Paused)/.test(message);
|
|
16662
16833
|
}
|
|
16663
16834
|
function isRecompSkip2(message) {
|
|
16664
16835
|
return /—\s*Skipped|already mutating compartment state|already running/i.test(message);
|
|
@@ -16765,7 +16936,7 @@ async function runManagedRecomp2(ctx, sessionId, options) {
|
|
|
16765
16936
|
clearEmergencyRecovery(ctx.db, sessionId);
|
|
16766
16937
|
} catch {}
|
|
16767
16938
|
}
|
|
16768
|
-
setRecompTerminal2(ctx.liveSessionState, sessionId, terminalPhase, extractRecompReason2(message));
|
|
16939
|
+
setRecompTerminal2(ctx.liveSessionState, sessionId, terminalPhase, pausedRecompReason(message) === null ? extractRecompReason2(message) : message);
|
|
16769
16940
|
return message;
|
|
16770
16941
|
} catch (error) {
|
|
16771
16942
|
const failure = renderUserFacingFailure("recomp_unavailable");
|