@cortexkit/pi-magic-context 0.43.0 → 0.43.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-y33j7m6y.js → index-17102c1m.js} +1 -1
- package/dist/index-5v60m046.js +40 -0
- package/dist/{index-83wwtw1q.js → index-bfd52y8p.js} +7 -1
- package/dist/{index-5tw61yhp.js → index-bkrh6jhp.js} +25 -7
- package/dist/{index-vcjgpb6f.js → index-mea04n1j.js} +69 -4
- package/dist/index.js +466 -219
- package/dist/{message-time-backfill-dah83bcz.js → message-time-backfill-f0v3yvza.js} +2 -2
- package/dist/{read-session-chunk-3zybnn0f.js → read-session-chunk-ky2sprnf.js} +4 -2
- package/dist/safe-notification-target-d7f3t5qk.js +9 -0
- package/dist/subagent-entry.js +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
log
|
|
3
|
+
} from "./index-bfd52y8p.js";
|
|
4
|
+
|
|
5
|
+
// ../plugin/src/shared/safe-notification-target.ts
|
|
6
|
+
var DEFAULT_TITLE_RE = /^(New session - |Child session - )\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
7
|
+
function isDefaultSessionTitle2(title) {
|
|
8
|
+
return DEFAULT_TITLE_RE.test(title);
|
|
9
|
+
}
|
|
10
|
+
async function readSessionTitle(client, sessionId) {
|
|
11
|
+
try {
|
|
12
|
+
const c = client;
|
|
13
|
+
if (typeof c.session?.get !== "function")
|
|
14
|
+
return null;
|
|
15
|
+
const raw = await Promise.resolve(c.session.get({ path: { id: sessionId } }));
|
|
16
|
+
const obj = raw;
|
|
17
|
+
const title = obj && typeof obj === "object" ? obj.data?.title ?? obj.title : undefined;
|
|
18
|
+
return typeof title === "string" ? title : null;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function waitForSafeNotificationTarget2(client, sessionId, options) {
|
|
24
|
+
const attempts = Math.max(1, options?.attempts ?? 4);
|
|
25
|
+
const delayMs = options?.delayMs ?? 15000;
|
|
26
|
+
for (let attempt = 0;attempt < attempts; attempt += 1) {
|
|
27
|
+
const title = await readSessionTitle(client, sessionId);
|
|
28
|
+
if (title === null)
|
|
29
|
+
return "safe";
|
|
30
|
+
if (!isDefaultSessionTitle2(title))
|
|
31
|
+
return "safe";
|
|
32
|
+
if (attempt < attempts - 1) {
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
log(`[magic-context] notification skipped: session ${sessionId} still has its default title (would suppress title generation); will retry on a later startup`);
|
|
37
|
+
return "skip";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { isDefaultSessionTitle2, waitForSafeNotificationTarget2 };
|
|
@@ -13,9 +13,15 @@ function getHarness() {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// ../plugin/src/shared/data-path.ts
|
|
16
|
-
import { existsSync, mkdirSync,
|
|
16
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
17
|
import * as os from "node:os";
|
|
18
18
|
import * as path from "node:path";
|
|
19
|
+
|
|
20
|
+
// ../plugin/src/shared/test-temp-dir.ts
|
|
21
|
+
var STALE_TEMP_DIR_AGE_MS = 60 * 60 * 1000;
|
|
22
|
+
var registeredTempDirs = new Set;
|
|
23
|
+
|
|
24
|
+
// ../plugin/src/shared/data-path.ts
|
|
19
25
|
function getDataDir() {
|
|
20
26
|
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
21
27
|
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
sanitizeDiagnosticText,
|
|
7
7
|
log,
|
|
8
8
|
sessionLog
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-bfd52y8p.js";
|
|
10
10
|
import {
|
|
11
11
|
removeSystemReminders,
|
|
12
12
|
hasMeaningfulUserText2,
|
|
@@ -41,10 +41,10 @@ import {
|
|
|
41
41
|
cleanUserText2,
|
|
42
42
|
readRawSessionMessages2,
|
|
43
43
|
readSessionChunk2
|
|
44
|
-
} from "./index-
|
|
44
|
+
} from "./index-mea04n1j.js";
|
|
45
45
|
import {
|
|
46
46
|
logSlowWriteTransaction
|
|
47
|
-
} from "./index-
|
|
47
|
+
} from "./index-17102c1m.js";
|
|
48
48
|
|
|
49
49
|
// ../plugin/src/config/agent-disable.ts
|
|
50
50
|
var COMPACTION_ENABLED_PATH = `compaction${"."}enabled`;
|
|
@@ -16898,8 +16898,8 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
16898
16898
|
{ readRawSessionMessagePage, readRawSessionMessages },
|
|
16899
16899
|
{ startMessageTimeBackfill }
|
|
16900
16900
|
] = await Promise.all([
|
|
16901
|
-
import("./read-session-chunk-
|
|
16902
|
-
import("./message-time-backfill-
|
|
16901
|
+
import("./read-session-chunk-ky2sprnf.js"),
|
|
16902
|
+
import("./message-time-backfill-f0v3yvza.js")
|
|
16903
16903
|
]);
|
|
16904
16904
|
await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
|
|
16905
16905
|
readPage: readRawSessionMessagePage
|
|
@@ -19457,6 +19457,19 @@ function updateFnv1a32(hash, value) {
|
|
|
19457
19457
|
}
|
|
19458
19458
|
return next;
|
|
19459
19459
|
}
|
|
19460
|
+
function contentSnapshotValue(value) {
|
|
19461
|
+
if (!value || typeof value !== "object")
|
|
19462
|
+
return value;
|
|
19463
|
+
const message = value;
|
|
19464
|
+
const info = message.info;
|
|
19465
|
+
const summary = info?.summary;
|
|
19466
|
+
if (!Array.isArray(message.parts) || info?.role !== "user" || summary === null || typeof summary !== "object" || Array.isArray(summary) || Object.keys(summary).length !== 1 || !Array.isArray(summary.diffs) || summary.diffs.length !== 0)
|
|
19467
|
+
return value;
|
|
19468
|
+
return {
|
|
19469
|
+
...message,
|
|
19470
|
+
info: Object.fromEntries(Object.entries(info).filter(([key]) => key !== "summary"))
|
|
19471
|
+
};
|
|
19472
|
+
}
|
|
19460
19473
|
function signatureForFields(fields) {
|
|
19461
19474
|
let hash = FNV1A_32_OFFSET;
|
|
19462
19475
|
for (const field of fields) {
|
|
@@ -19504,7 +19517,7 @@ function lkgContentFields(value) {
|
|
|
19504
19517
|
fields.push(LKG_SNAPSHOT_UNDEFINED);
|
|
19505
19518
|
};
|
|
19506
19519
|
try {
|
|
19507
|
-
visit(value);
|
|
19520
|
+
visit(contentSnapshotValue(value));
|
|
19508
19521
|
return fields;
|
|
19509
19522
|
} catch {
|
|
19510
19523
|
return null;
|
|
@@ -33012,7 +33025,12 @@ async function runGit(cwd, args) {
|
|
|
33012
33025
|
encoding: "utf8"
|
|
33013
33026
|
});
|
|
33014
33027
|
return String(result.stdout);
|
|
33015
|
-
} catch {
|
|
33028
|
+
} catch (error) {
|
|
33029
|
+
if (error.killed || error.code === "ETIMEDOUT") {
|
|
33030
|
+
throw new Error(`Git verification command timed out after ${GIT_TIMEOUT_MS2}ms`, {
|
|
33031
|
+
cause: error
|
|
33032
|
+
});
|
|
33033
|
+
}
|
|
33016
33034
|
return null;
|
|
33017
33035
|
}
|
|
33018
33036
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getHarness,
|
|
3
3
|
log
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-bfd52y8p.js";
|
|
5
5
|
|
|
6
6
|
// ../plugin/src/features/magic-context/reclaim-protection.ts
|
|
7
7
|
var CTX_REDUCE_KEEP = 3;
|
|
@@ -2042,7 +2042,7 @@ function retreatPastHostUnservedRows(messages, exclusiveEnd, floor) {
|
|
|
2042
2042
|
// ../plugin/src/shared/opencode-db-path.ts
|
|
2043
2043
|
import { existsSync as existsSync2, readdirSync, statSync as statSync2 } from "node:fs";
|
|
2044
2044
|
import { homedir as homedir2 } from "node:os";
|
|
2045
|
-
import { isAbsolute, join as join2 } from "node:path";
|
|
2045
|
+
import { isAbsolute, join as join2, resolve as resolve2 } from "node:path";
|
|
2046
2046
|
var cachedResolution = null;
|
|
2047
2047
|
var lastReadFailure = null;
|
|
2048
2048
|
var claimedDiagnostics = new Set;
|
|
@@ -2125,7 +2125,7 @@ function resolveV2Fresh(dataDir, channel, env) {
|
|
|
2125
2125
|
const filename = sourceOpenCodeDatabaseFilename("v2", channel, env);
|
|
2126
2126
|
const explicit = env.OPENCODE_DB !== undefined;
|
|
2127
2127
|
return {
|
|
2128
|
-
path: filename === ":memory:" ? filename :
|
|
2128
|
+
path: filename === ":memory:" ? filename : resolve2(dataDir, filename),
|
|
2129
2129
|
source: explicit ? "OPENCODE_DB" : env.OPENCODE_CHANNEL ? "channel" : "default",
|
|
2130
2130
|
channel: explicit ? null : channel
|
|
2131
2131
|
};
|
|
@@ -2717,6 +2717,34 @@ function readRawSessionTailFromDb(db, sessionId, baseOrdinal, anchorMessageId) {
|
|
|
2717
2717
|
}
|
|
2718
2718
|
return { messages, absoluteMessageCount: Math.max(0, ord - 1) };
|
|
2719
2719
|
}
|
|
2720
|
+
function readRawSessionMessageOrdinalByIdFromDb(db, sessionId, messageId) {
|
|
2721
|
+
const row = db.prepare(`SELECT COUNT(candidate.id) AS ordinal
|
|
2722
|
+
FROM message AS target
|
|
2723
|
+
JOIN message AS candidate
|
|
2724
|
+
ON candidate.session_id = target.session_id
|
|
2725
|
+
AND NOT (
|
|
2726
|
+
CASE WHEN json_valid(candidate.data) = 1
|
|
2727
|
+
THEN COALESCE(json_extract(candidate.data, '$.summary'), 0)
|
|
2728
|
+
ELSE 0 END = 1
|
|
2729
|
+
AND CASE WHEN json_valid(candidate.data) = 1
|
|
2730
|
+
THEN COALESCE(json_extract(candidate.data, '$.finish'), '')
|
|
2731
|
+
ELSE '' END = 'stop'
|
|
2732
|
+
)
|
|
2733
|
+
AND (candidate.time_created < target.time_created
|
|
2734
|
+
OR (candidate.time_created = target.time_created AND candidate.id <= target.id))
|
|
2735
|
+
WHERE target.session_id = ?
|
|
2736
|
+
AND target.id = ?
|
|
2737
|
+
AND NOT (
|
|
2738
|
+
CASE WHEN json_valid(target.data) = 1
|
|
2739
|
+
THEN COALESCE(json_extract(target.data, '$.summary'), 0)
|
|
2740
|
+
ELSE 0 END = 1
|
|
2741
|
+
AND CASE WHEN json_valid(target.data) = 1
|
|
2742
|
+
THEN COALESCE(json_extract(target.data, '$.finish'), '')
|
|
2743
|
+
ELSE '' END = 'stop'
|
|
2744
|
+
)`).get(sessionId, messageId);
|
|
2745
|
+
const ordinal = row?.ordinal;
|
|
2746
|
+
return typeof ordinal === "number" && ordinal > 0 ? ordinal : null;
|
|
2747
|
+
}
|
|
2720
2748
|
function readRawSessionMessageByIdFromDb(db, sessionId, messageId) {
|
|
2721
2749
|
const row = db.prepare("SELECT id, data, time_created, time_updated FROM message WHERE session_id = ? AND id = ?").get(sessionId, messageId);
|
|
2722
2750
|
if (!row || !isRawMessageRow(row) || typeof row.time_created !== "number") {
|
|
@@ -4272,6 +4300,43 @@ function hasRawSessionMessageById2(sessionId, messageId) {
|
|
|
4272
4300
|
return provider.hasMessageById(messageId);
|
|
4273
4301
|
return readRawSessionMessageById(sessionId, messageId) !== null;
|
|
4274
4302
|
}
|
|
4303
|
+
function readRawSessionMessageOrdinalById2(sessionId, messageId) {
|
|
4304
|
+
const provider = sessionProviders.get(sessionId);
|
|
4305
|
+
if (provider?.readMessageOrdinalById) {
|
|
4306
|
+
return provider.readMessageOrdinalById(messageId);
|
|
4307
|
+
}
|
|
4308
|
+
if (provider?.readMessageIdOrdinals) {
|
|
4309
|
+
return provider.readMessageIdOrdinals().get(messageId) ?? null;
|
|
4310
|
+
}
|
|
4311
|
+
if (provider?.readMessageOrdinalPage) {
|
|
4312
|
+
let after = null;
|
|
4313
|
+
let ordinal = 0;
|
|
4314
|
+
while (true) {
|
|
4315
|
+
const page = provider.readMessageOrdinalPage(after, 500);
|
|
4316
|
+
if (page.length === 0)
|
|
4317
|
+
return null;
|
|
4318
|
+
for (const entry of page) {
|
|
4319
|
+
if (entry.contributesOrdinal)
|
|
4320
|
+
ordinal += 1;
|
|
4321
|
+
if (entry.id === messageId)
|
|
4322
|
+
return entry.contributesOrdinal ? ordinal : null;
|
|
4323
|
+
}
|
|
4324
|
+
const last = page.at(-1);
|
|
4325
|
+
if (!last || page.length < 500)
|
|
4326
|
+
return null;
|
|
4327
|
+
after = { timeCreated: last.timeCreated, id: last.id };
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
if (provider?.readMessageById) {
|
|
4331
|
+
return provider.readMessageById(messageId)?.ordinal ?? null;
|
|
4332
|
+
}
|
|
4333
|
+
if (provider) {
|
|
4334
|
+
return provider.readMessages().find((message) => message.id === messageId)?.ordinal ?? null;
|
|
4335
|
+
}
|
|
4336
|
+
if (!openCodeDbExists())
|
|
4337
|
+
return null;
|
|
4338
|
+
return withReadOnlySessionDb((db) => readRawSessionMessageOrdinalByIdFromDb(db, sessionId, messageId));
|
|
4339
|
+
}
|
|
4275
4340
|
function readRawSessionMessageById(sessionId, messageId) {
|
|
4276
4341
|
const provider = sessionProviders.get(sessionId);
|
|
4277
4342
|
if (provider?.readMessageById) {
|
|
@@ -4650,4 +4715,4 @@ function readSessionChunk2(sessionId, tokenBudget, offset = 1, eligibleEndOrdina
|
|
|
4650
4715
|
toolResultBoundaries
|
|
4651
4716
|
};
|
|
4652
4717
|
}
|
|
4653
|
-
export { CTX_REDUCE_KEEP, newestCtxReduceTagNumbers, textMentionsRecentCommit, removeSystemReminders, hasMeaningfulUserText2, extractTexts2, extractToolCallSummaries, preloadTokenizer, estimateTokens, normalizeText, stripWellFormedLeadingTagPrefix, stripPersistedAssistantText, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isRecord, stableStringify, estimateImageTokensFromDataUrl, TODO_STATUSES, TODO_PRIORITIES, TITLE_DONE_STATUSES, normalizeTodoStateJson, buildSyntheticTodoPart, stripChannel1ReminderSpans, compareMeasuredTailPrefix, formatTailHygienePrefixMismatch, freezeTailHygieneMeasurement, effectiveTailHygiene, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, decideChannel1, evaluateChannel2, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, planEmergencyDrop, measureEmergencyTag, updateTagByteSize, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, updateTagInputByteSize, updateTagTokenCount, getPersistedToolTagAccounting, getAllStatusTagTokenTotalsFlat, updateTagInputTokenCount, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, hasPiFallbackMessageTags, findAdoptableFallbackTags, hasPiFallbackToolOwnerTags, findPiFallbackToolOwnerTags, adoptPiFallbackToolOwnerTag, adoptPiFallbackMessageTag, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, TAG_SELECT_COLUMNS, getTagsBySession, getActiveTagsBySession, getTagsForPendingOperations, getTagsByNumbers, getDroppedTagsByNumbers, getMaxDroppedTagNumber, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, retreatPastHostUnservedRows, resolveOpenCodeDbPath, hasV1MessageTables, assertOpenCodeStoreGeneration, openCodeDbPathExists, getOpenCodeDbProbeDescriptions, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce, registerSlowWriteReporter, detectSqliteRuntime, Database, withPrivilegedWriter, closeQuietly, withReadOnlySessionDb, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, invalidateTrueRawTokenCache, droppedInputMarker, createDroppedInputGuard, isEditTool, applyEditMarkerToInput, setDatabase, loadToolDefinitionMeasurements, resolveDecisionCalibration, providerMass, localBudget, calibrationForModelKey, historyLocalBudget, resolveHostServedBoundaryId2, hasRawMessageProvider2, setRawMessageProvider2, withRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, readRawSessionMessageRange2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageIdOrdinalsForRange2, hasRawSessionMessageById2, getRawSessionMessageCount2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, readSessionChunk2 };
|
|
4718
|
+
export { CTX_REDUCE_KEEP, newestCtxReduceTagNumbers, textMentionsRecentCommit, removeSystemReminders, hasMeaningfulUserText2, extractTexts2, extractToolCallSummaries, preloadTokenizer, estimateTokens, normalizeText, stripWellFormedLeadingTagPrefix, stripPersistedAssistantText, byteSize, stripTagPrefix, peelLeadingMcTagNotation, prependTag, isRecord, stableStringify, estimateImageTokensFromDataUrl, TODO_STATUSES, TODO_PRIORITIES, TITLE_DONE_STATUSES, normalizeTodoStateJson, buildSyntheticTodoPart, stripChannel1ReminderSpans, compareMeasuredTailPrefix, formatTailHygienePrefixMismatch, freezeTailHygieneMeasurement, effectiveTailHygiene, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, decideChannel1, evaluateChannel2, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, planEmergencyDrop, measureEmergencyTag, updateTagByteSize, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, updateTagInputByteSize, updateTagTokenCount, getPersistedToolTagAccounting, getAllStatusTagTokenTotalsFlat, updateTagInputTokenCount, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, getInertWhitespaceAssistantTags, updateTagDropMode, updateCavemanDepth, hasPiFallbackMessageTags, findAdoptableFallbackTags, hasPiFallbackToolOwnerTags, findPiFallbackToolOwnerTags, adoptPiFallbackToolOwnerTag, adoptPiFallbackMessageTag, getMaxTagNumberBySession, getTagNumberByMessageId, getAssignableTagNumberByMessageId, deriveTagLoadFloor, TAG_SELECT_COLUMNS, getTagsBySession, getActiveTagsBySession, getTagsForPendingOperations, getTagsByNumbers, getDroppedTagsByNumbers, getMaxDroppedTagNumber, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, retreatPastHostUnservedRows, resolveOpenCodeDbPath, hasV1MessageTables, assertOpenCodeStoreGeneration, openCodeDbPathExists, getOpenCodeDbProbeDescriptions, recordOpenCodeDbReadFailure, clearOpenCodeDbReadFailure, claimOpenCodeDbDiagnosticOnce, registerSlowWriteReporter, detectSqliteRuntime, Database, withPrivilegedWriter, closeQuietly, withReadOnlySessionDb, completedToolArcCrossesBoundary, estimateTrueRawMessageTokens, buildToolArcs, fenceBoundaryForCompletedToolArcs, fenceBoundaryForToolArcs, buildTrueRawTokenIndex, computeRawRangeFingerprint, invalidateTrueRawTokenCache, droppedInputMarker, createDroppedInputGuard, isEditTool, applyEditMarkerToInput, setDatabase, loadToolDefinitionMeasurements, resolveDecisionCalibration, providerMass, localBudget, calibrationForModelKey, historyLocalBudget, resolveHostServedBoundaryId2, hasRawMessageProvider2, setRawMessageProvider2, withRawMessageProvider2, cleanUserText2, withRawSessionMessageCache2, readRawSessionMessages2, readRawSessionMessagePage2, getRawSessionMessageOrdinalCount2, readRawSessionMessageRange2, primeTailRawMessageCache2, getCachedAbsoluteMessageCount2, primeInMemoryTailRawMessageCache2, readRawSessionMessageIdOrdinalsForRange2, hasRawSessionMessageById2, readRawSessionMessageOrdinalById2, getRawSessionMessageCount2, getRawSessionTagKeysThrough2, getLegacyProtectedTailStartOrdinal2, readSessionChunk2 };
|