@cortexkit/pi-magic-context 0.46.0 → 0.46.1
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/embedding-worker.js
CHANGED
|
@@ -5293,6 +5293,7 @@ var AgentMetadataSchema = AgentOverrideConfigSchema.pick({
|
|
|
5293
5293
|
maxTokens: true
|
|
5294
5294
|
});
|
|
5295
5295
|
var DreamerConfigSchema = AgentMetadataSchema.extend({
|
|
5296
|
+
disable: boolean2().optional().describe("Disable this agent"),
|
|
5296
5297
|
runner: _enum(["broca", "host"]).optional().describe(`Which side runs the dreamer completions the Rust module routes (classify-memories) in Rust transform mode: "host" runs them on this process's carrier, "broca" routes them to the Broca module. When unset, historian.runner applies, and when that is unset too the harness decides the same way it does for the historian. User-level config only.`),
|
|
5297
5298
|
opencode: DreamerOpenCodeHarnessBlockSchema.optional(),
|
|
5298
5299
|
pi: DreamerPiHarnessBlockSchema.optional(),
|
|
@@ -5559,6 +5560,7 @@ var LIVE_RELOAD_CONFIG_PATHS = [
|
|
|
5559
5560
|
"commit_cluster_trigger.enabled",
|
|
5560
5561
|
"commit_cluster_trigger.min_clusters",
|
|
5561
5562
|
"memory.auto_promote",
|
|
5563
|
+
"dreamer.disable",
|
|
5562
5564
|
"dreamer.maxTokens",
|
|
5563
5565
|
"dreamer.opencode.model",
|
|
5564
5566
|
"dreamer.opencode.fallback_models",
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
getEmbeddingProviderIdentity,
|
|
32
32
|
dominantEmbeddingFailure,
|
|
33
33
|
LocalEmbeddingProvider
|
|
34
|
-
} from "./index-
|
|
34
|
+
} from "./index-r01b1b78.js";
|
|
35
35
|
import {
|
|
36
36
|
piModelRefToCanonical,
|
|
37
37
|
modelRefLookupOrder
|
|
@@ -23514,19 +23514,19 @@ function findBoundaryUserMessage(sessionId, endMessageId) {
|
|
|
23514
23514
|
AND NOT (COALESCE(json_extract(data, '$.summary'), 0) = 1
|
|
23515
23515
|
AND COALESCE(json_extract(data, '$.finish'), '') = 'stop')
|
|
23516
23516
|
AND COALESCE(json_extract(data, '$.role'), '') = 'user'
|
|
23517
|
-
AND (time_created
|
|
23517
|
+
AND (time_created, id) <= (?, ?)
|
|
23518
23518
|
AND NOT (
|
|
23519
23519
|
EXISTS (SELECT 1 FROM part p
|
|
23520
|
-
WHERE p.message_id = message.id AND +p.session_id = message.session_id
|
|
23520
|
+
WHERE likelihood(p.message_id = message.id, 0.000001) AND +p.session_id = message.session_id
|
|
23521
23521
|
AND COALESCE(json_extract(p.data, '$.type'), '') <> 'compaction')
|
|
23522
23522
|
AND NOT EXISTS (SELECT 1 FROM part p
|
|
23523
|
-
WHERE p.message_id = message.id AND +p.session_id = message.session_id
|
|
23523
|
+
WHERE likelihood(p.message_id = message.id, 0.000001) AND +p.session_id = message.session_id
|
|
23524
23524
|
AND COALESCE(json_extract(p.data, '$.type'), '') <> 'compaction'
|
|
23525
23525
|
AND COALESCE(json_extract(p.data, '$.synthetic'), 0) <> 1
|
|
23526
23526
|
AND COALESCE(json_extract(p.data, '$.syntheticTodoMarker'), 0) <> 1)
|
|
23527
23527
|
)
|
|
23528
23528
|
ORDER BY time_created DESC, id DESC
|
|
23529
|
-
LIMIT 1`).get(sessionId, target.timeCreated, target.
|
|
23529
|
+
LIMIT 1`).get(sessionId, target.timeCreated, target.id);
|
|
23530
23530
|
if (typeof boundary?.id !== "string" || typeof boundary.time_created !== "number") {
|
|
23531
23531
|
return null;
|
|
23532
23532
|
}
|
|
@@ -23554,16 +23554,16 @@ function isOpenCodeGapHistorianAbsent(sessionId, endId, nextId) {
|
|
|
23554
23554
|
return false;
|
|
23555
23555
|
const row = getWritableOpenCodeDb().prepare(`SELECT 1 FROM message m
|
|
23556
23556
|
WHERE m.session_id=?
|
|
23557
|
-
AND (m.time_created
|
|
23558
|
-
AND (m.time_created
|
|
23557
|
+
AND (m.time_created, m.id) > (?, ?)
|
|
23558
|
+
AND (m.time_created, m.id) < (?, ?)
|
|
23559
23559
|
AND NOT (COALESCE(json_type(m.data,'$.summary'),'')='true' AND COALESCE(json_extract(m.data,'$.finish'),'')='stop')
|
|
23560
23560
|
AND NOT (
|
|
23561
|
-
EXISTS (SELECT 1 FROM part p WHERE p.message_id=m.id AND +p.session_id=m.session_id AND COALESCE(json_extract(p.data,'$.type'),'')<>'compaction')
|
|
23562
|
-
AND NOT EXISTS (SELECT 1 FROM part p WHERE p.message_id=m.id AND +p.session_id=m.session_id
|
|
23561
|
+
EXISTS (SELECT 1 FROM part p WHERE likelihood(p.message_id=m.id, 0.000001) AND +p.session_id=m.session_id AND COALESCE(json_extract(p.data,'$.type'),'')<>'compaction')
|
|
23562
|
+
AND NOT EXISTS (SELECT 1 FROM part p WHERE likelihood(p.message_id=m.id, 0.000001) AND +p.session_id=m.session_id
|
|
23563
23563
|
AND COALESCE(json_extract(p.data,'$.type'),'')<>'compaction'
|
|
23564
23564
|
AND COALESCE(json_type(p.data,'$.synthetic'),'')<>'true'
|
|
23565
23565
|
AND COALESCE(json_type(p.data,'$.syntheticTodoMarker'),'')<>'true')
|
|
23566
|
-
) LIMIT 1`).get(sessionId, end.timeCreated, end.
|
|
23566
|
+
) LIMIT 1`).get(sessionId, end.timeCreated, end.id, next.timeCreated, next.id);
|
|
23567
23567
|
return !row;
|
|
23568
23568
|
}
|
|
23569
23569
|
function removeLegacyMarkerLineageRows(db, args) {
|
package/dist/index.js
CHANGED
|
@@ -403,7 +403,7 @@ import {
|
|
|
403
403
|
registerTodoStateLifecycle,
|
|
404
404
|
syncCtxMemoryToolEnabled,
|
|
405
405
|
registerMagicContextTools
|
|
406
|
-
} from "./index-
|
|
406
|
+
} from "./index-ykb8kkm3.js";
|
|
407
407
|
import {
|
|
408
408
|
isValidLanguageCode,
|
|
409
409
|
withContentLanguageDirective,
|
|
@@ -418,7 +418,7 @@ import {
|
|
|
418
418
|
connectionFileExists,
|
|
419
419
|
formatSynapseLaneDescriptor,
|
|
420
420
|
computeNormalizedHash
|
|
421
|
-
} from "./index-
|
|
421
|
+
} from "./index-r01b1b78.js";
|
|
422
422
|
import {
|
|
423
423
|
canonicalModelIdentity,
|
|
424
424
|
piModelRefToCanonical,
|
|
@@ -16415,7 +16415,9 @@ function scheduleInitialProjectRun(reg, db) {
|
|
|
16415
16415
|
startupTimers.set(reg.directory, timer);
|
|
16416
16416
|
}
|
|
16417
16417
|
async function runProjectMaintenance(reg, origin, db) {
|
|
16418
|
-
const
|
|
16418
|
+
const sampled = reg.sampleDreamRun?.();
|
|
16419
|
+
const current = sampled ? { ...reg, ...sampled } : reg;
|
|
16420
|
+
const projectMaintenanceEnabled = Boolean(current.dreamerConfig && current.dreamerConfig.disable !== true) || reg.memoryEnabled === true || reg.gitCommitIndexing?.enabled === true || reg.historianChildSweep !== undefined;
|
|
16419
16421
|
if (!projectMaintenanceEnabled)
|
|
16420
16422
|
return;
|
|
16421
16423
|
await reg.ensureRegistered(reg.directory, db);
|
|
@@ -16426,8 +16428,7 @@ async function runProjectMaintenance(reg, origin, db) {
|
|
|
16426
16428
|
log(`[magic-context] proactively embedded ${embeddedCount} ${embeddedCount === 1 ? "memory" : "memories"} for project ${reg.projectIdentity}`);
|
|
16427
16429
|
}
|
|
16428
16430
|
}
|
|
16429
|
-
|
|
16430
|
-
await sweepProject(sampled ? { ...reg, ...sampled } : reg, origin, db);
|
|
16431
|
+
await sweepProject(current, origin, db);
|
|
16431
16432
|
}
|
|
16432
16433
|
async function sweepProject(reg, origin, db, gitCommitEnabled) {
|
|
16433
16434
|
if (!directoryStillExists(reg.directory)) {
|
|
@@ -39735,7 +39736,7 @@ function buildStatusViewFor(check, options) {
|
|
|
39735
39736
|
// package.json
|
|
39736
39737
|
var package_default = {
|
|
39737
39738
|
name: "@cortexkit/pi-magic-context",
|
|
39738
|
-
version: "0.46.
|
|
39739
|
+
version: "0.46.1",
|
|
39739
39740
|
type: "module",
|
|
39740
39741
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
39741
39742
|
main: "dist/index.js",
|
|
@@ -39767,8 +39768,8 @@ var package_default = {
|
|
|
39767
39768
|
build: "bun ../../scripts/check-bun.mjs && tsc -p ../retina-local-fs/tsconfig.build.json && bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js transformers-web.js transformers-node-wasm.js && bun build ../plugin/src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun ../plugin/scripts/build-transformers-node-wasm.ts dist && bun build src/index.ts src/subagent-entry.ts src/historian-calibration-extension.ts ../plugin/src/features/magic-context/memory/embedding-worker.ts ../plugin/src/features/magic-context/migration-worker.ts --outdir dist --entry-naming '[name].[ext]' --target node --format esm --splitting --external @earendil-works/pi-coding-agent --external @earendil-works/pi-tui --external onnxruntime-node --external onnxruntime-web --external sharp --external node:sqlite",
|
|
39768
39769
|
"build:e2e-argv": `bun ../../scripts/clean-dist-chunks.mjs ../../tests/docker/.generated subagent-runner-e2e.mjs && bun build src/subagent-runner.ts --outdir ../../tests/docker/.generated --entry-naming 'subagent-runner-e2e.mjs' --splitting --target node --format esm --external node:sqlite && node --input-type=module -e 'const { __test } = await import("../../tests/docker/.generated/subagent-runner-e2e.mjs"); if (typeof __test.buildArgs !== "function" || typeof __test.resolvePiInvocation !== "function") throw new Error("argv renderer exports missing"); console.log("Node argv renderer: 2 exports loaded")'`,
|
|
39769
39770
|
typecheck: "tsc -p ../retina-local-fs/tsconfig.build.json && tsc --noEmit",
|
|
39770
|
-
test: "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel --timeout 30000",
|
|
39771
|
-
"test:serial": "bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --timeout 30000",
|
|
39771
|
+
test: "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=4 --timeout 30000",
|
|
39772
|
+
"test:serial": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=1 --timeout 30000",
|
|
39772
39773
|
lint: "bun ../../scripts/check-bun.mjs && biome check src",
|
|
39773
39774
|
"lint:fix": "biome check --write src",
|
|
39774
39775
|
format: "biome format --write src",
|
|
@@ -39776,7 +39777,7 @@ var package_default = {
|
|
|
39776
39777
|
clean: "bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js embedding-worker.js migration-worker.js transformers-web.js transformers-node-wasm.js",
|
|
39777
39778
|
prepublishOnly: "bun run build"
|
|
39778
39779
|
},
|
|
39779
|
-
"//test": "
|
|
39780
|
+
"//test": "Test runs cap file-isolated workers at four (one for test:serial) and disable JSC's optimizing WebAssembly tier so per-file isolation does not pay its compilation cost on every file. These are not production settings and do not change host process engine options.",
|
|
39780
39781
|
dependencies: {
|
|
39781
39782
|
"@cortexkit/subc-client": "0.11.1",
|
|
39782
39783
|
"@jitl/quickjs-singlefile-cjs-release-asyncify": "0.32.0",
|
|
@@ -39841,6 +39842,7 @@ var package_default = {
|
|
|
39841
39842
|
|
|
39842
39843
|
// src/dialogs/status-dialog.ts
|
|
39843
39844
|
var REFRESH_INTERVAL_MS = 1000;
|
|
39845
|
+
var DETAIL_REFRESH_INTERVAL_MS = 1e4;
|
|
39844
39846
|
var BORDER_ROWS = 2;
|
|
39845
39847
|
var BORDER_COLUMNS = 2;
|
|
39846
39848
|
var PADDING_COLUMNS = 2;
|
|
@@ -39870,6 +39872,7 @@ function stopStatusDialogRefresh() {
|
|
|
39870
39872
|
class StatusDialogComponent {
|
|
39871
39873
|
props;
|
|
39872
39874
|
detail;
|
|
39875
|
+
detailRefresh;
|
|
39873
39876
|
refreshTimer = null;
|
|
39874
39877
|
closed = false;
|
|
39875
39878
|
scrollOffset = 0;
|
|
@@ -39877,13 +39880,14 @@ class StatusDialogComponent {
|
|
|
39877
39880
|
maxScrollOffset = 0;
|
|
39878
39881
|
constructor(props) {
|
|
39879
39882
|
this.props = props;
|
|
39880
|
-
this.
|
|
39883
|
+
this.detailRefresh = new PiStatusDetailRefresh(props.pi, props.ctx, props.deps, props.sessionId);
|
|
39884
|
+
this.detail = this.detailRefresh.refresh();
|
|
39881
39885
|
openStatusDialogs.add(this);
|
|
39882
39886
|
this.refreshTimer = setInterval(() => {
|
|
39883
39887
|
if (this.closed)
|
|
39884
39888
|
return;
|
|
39885
39889
|
try {
|
|
39886
|
-
this.detail =
|
|
39890
|
+
this.detail = this.detailRefresh.refresh();
|
|
39887
39891
|
this.props.tui.requestRender();
|
|
39888
39892
|
} catch {}
|
|
39889
39893
|
}, REFRESH_INTERVAL_MS);
|
|
@@ -40131,7 +40135,153 @@ function deriveDefaultProtectedTokensFloor(usableSoft) {
|
|
|
40131
40135
|
const val = Math.round(0.05 * soft);
|
|
40132
40136
|
return Math.max(low, Math.min(64000, val));
|
|
40133
40137
|
}
|
|
40138
|
+
function readStatusHostBytes(pi, ctx) {
|
|
40139
|
+
return {
|
|
40140
|
+
modelKey: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined,
|
|
40141
|
+
modelBytes: safeStringify(ctx.model),
|
|
40142
|
+
system: safeRead(() => readHostSystemPrompt(ctx), undefined),
|
|
40143
|
+
tools: safeRead(() => (pi.getAllTools?.() ?? []).map((tool) => `${tool.name ?? ""}
|
|
40144
|
+
${tool.description ?? ""}
|
|
40145
|
+
${safeStringify(tool.parameters)}`), [])
|
|
40146
|
+
};
|
|
40147
|
+
}
|
|
40148
|
+
|
|
40149
|
+
class PiStatusTokenCache {
|
|
40150
|
+
estimate;
|
|
40151
|
+
systemKey;
|
|
40152
|
+
systemTokens = 0;
|
|
40153
|
+
toolsKey;
|
|
40154
|
+
toolTokens = 0;
|
|
40155
|
+
constructor(estimate = estimateTokens) {
|
|
40156
|
+
this.estimate = estimate;
|
|
40157
|
+
}
|
|
40158
|
+
estimates(host, fallbackSystemTokens) {
|
|
40159
|
+
if (host.system !== undefined) {
|
|
40160
|
+
const key = JSON.stringify([host.modelKey, host.system]);
|
|
40161
|
+
if (this.systemKey !== key) {
|
|
40162
|
+
this.systemTokens = this.estimate(host.system);
|
|
40163
|
+
this.systemKey = key;
|
|
40164
|
+
}
|
|
40165
|
+
}
|
|
40166
|
+
const key = JSON.stringify([host.modelKey, host.tools]);
|
|
40167
|
+
if (this.toolsKey !== key) {
|
|
40168
|
+
this.toolTokens = host.tools.reduce((sum, bytes) => sum + this.estimate(bytes), 0);
|
|
40169
|
+
this.toolsKey = key;
|
|
40170
|
+
}
|
|
40171
|
+
return {
|
|
40172
|
+
systemPromptTokens: host.system === undefined ? fallbackSystemTokens : this.systemTokens,
|
|
40173
|
+
toolDefinitionTokens: this.toolTokens
|
|
40174
|
+
};
|
|
40175
|
+
}
|
|
40176
|
+
}
|
|
40177
|
+
|
|
40178
|
+
class PiStatusDetailRefresh {
|
|
40179
|
+
pi;
|
|
40180
|
+
ctx;
|
|
40181
|
+
deps;
|
|
40182
|
+
initialSessionId;
|
|
40183
|
+
detail;
|
|
40184
|
+
state;
|
|
40185
|
+
lastBuildAt = 0;
|
|
40186
|
+
detailKey = "";
|
|
40187
|
+
storeRevision;
|
|
40188
|
+
revisionDb;
|
|
40189
|
+
revisionStatement;
|
|
40190
|
+
constructor(pi, ctx, deps, initialSessionId, tokens = new PiStatusTokenCache) {
|
|
40191
|
+
this.pi = pi;
|
|
40192
|
+
this.ctx = ctx;
|
|
40193
|
+
this.deps = deps;
|
|
40194
|
+
this.initialSessionId = initialSessionId;
|
|
40195
|
+
this.state = { tokens };
|
|
40196
|
+
}
|
|
40197
|
+
readStoreRevision() {
|
|
40198
|
+
if (!isKnownAutocommit(this.deps.db))
|
|
40199
|
+
return;
|
|
40200
|
+
try {
|
|
40201
|
+
if (this.revisionDb !== this.deps.db) {
|
|
40202
|
+
this.revisionStatement = this.deps.db.prepare("SELECT total_changes() AS changes, data_version AS version FROM pragma_data_version");
|
|
40203
|
+
this.revisionDb = this.deps.db;
|
|
40204
|
+
}
|
|
40205
|
+
const row = this.revisionStatement?.get();
|
|
40206
|
+
return row ? `${row.changes}/${row.version}` : undefined;
|
|
40207
|
+
} catch {
|
|
40208
|
+
return;
|
|
40209
|
+
}
|
|
40210
|
+
}
|
|
40211
|
+
refresh(now = Date.now()) {
|
|
40212
|
+
const sessionId = resolveSessionId(this.ctx) ?? this.initialSessionId;
|
|
40213
|
+
const host = readStatusHostBytes(this.pi, this.ctx);
|
|
40214
|
+
const usage = this.ctx.getContextUsage?.();
|
|
40215
|
+
const { db: _db, ...config } = this.deps;
|
|
40216
|
+
const key = JSON.stringify([sessionId, host, usage?.contextWindow, config]);
|
|
40217
|
+
const databaseChanged = this.revisionDb !== this.deps.db;
|
|
40218
|
+
const revision = this.readStoreRevision();
|
|
40219
|
+
if (!this.detail || key !== this.detailKey || revision === undefined || revision !== this.storeRevision || databaseChanged || now - this.lastBuildAt >= DETAIL_REFRESH_INTERVAL_MS) {
|
|
40220
|
+
this.detail = buildStatusDetail(this.pi, this.ctx, this.deps, sessionId, this.state, host);
|
|
40221
|
+
this.detailKey = key;
|
|
40222
|
+
this.lastBuildAt = now;
|
|
40223
|
+
this.storeRevision = this.readStoreRevision();
|
|
40224
|
+
}
|
|
40225
|
+
this.detail = refreshLiveStatus(this.detail, this.state, this.ctx, usage, now);
|
|
40226
|
+
return this.detail;
|
|
40227
|
+
}
|
|
40228
|
+
}
|
|
40229
|
+
function conversationTokensFor(detail) {
|
|
40230
|
+
return Math.max(0, detail.inputTokens - detail.systemPromptTokens - detail.compartmentTokens - detail.factTokens - detail.memoryTokens - detail.docsTokens - detail.profileTokens - detail.toolCallTokens - detail.toolDefinitionTokens);
|
|
40231
|
+
}
|
|
40232
|
+
function refreshLiveStatus(detail, state, ctx, usage, now) {
|
|
40233
|
+
const live = state.live;
|
|
40234
|
+
if (!live)
|
|
40235
|
+
return detail;
|
|
40236
|
+
const windowGeometry = resolvePiWindowGeometry({
|
|
40237
|
+
rawContextWindow: usage?.contextWindow ?? ctx.model?.contextWindow,
|
|
40238
|
+
rawContextWindowSource: "catalog",
|
|
40239
|
+
model: ctx.model,
|
|
40240
|
+
...live
|
|
40241
|
+
});
|
|
40242
|
+
const pressure = resolvePiStatusPressureSnapshot({
|
|
40243
|
+
sessionId: detail.sessionId,
|
|
40244
|
+
persistedPercentage: live.persistedPercentage,
|
|
40245
|
+
persistedInputTokens: live.persistedInputTokens,
|
|
40246
|
+
liveInputTokens: usage?.tokens,
|
|
40247
|
+
usableContextLimit: windowGeometry?.usableSoft
|
|
40248
|
+
});
|
|
40249
|
+
const cacheRemainingMs = cacheRemaining(detail.cacheTtl, detail.lastResponseTime, now);
|
|
40250
|
+
const embeddingRunState = getEmbedDrainUiStatus(detail.sessionId, undefined).status;
|
|
40251
|
+
const current = {
|
|
40252
|
+
...detail,
|
|
40253
|
+
inputTokens: pressure.inputTokens,
|
|
40254
|
+
usagePercentage: pressure.percentage,
|
|
40255
|
+
contextLimit: pressure.contextLimit ?? 0,
|
|
40256
|
+
windowGeometry,
|
|
40257
|
+
cacheRemainingMs,
|
|
40258
|
+
cacheExpired: detail.lastResponseTime > 0 && cacheRemainingMs === 0,
|
|
40259
|
+
recompInFlight: isPiRecompInFlight(detail.sessionId),
|
|
40260
|
+
tailHygiene: resolveTailHygieneStatus(getPiChannel1Baseline(detail.sessionId)),
|
|
40261
|
+
embedding: {
|
|
40262
|
+
...detail.embedding,
|
|
40263
|
+
state: detail.embedding.state === "off" ? "off" : embeddingRunState !== "idle" ? embeddingRunState : detail.embedding.total > 0 && detail.embedding.indexed >= detail.embedding.total ? "ready" : "waiting"
|
|
40264
|
+
}
|
|
40265
|
+
};
|
|
40266
|
+
return { ...current, conversationTokens: conversationTokensFor(current) };
|
|
40267
|
+
}
|
|
40268
|
+
function cacheRemaining(cacheTtl, lastResponseTime, now) {
|
|
40269
|
+
let ttlMs;
|
|
40270
|
+
try {
|
|
40271
|
+
ttlMs = parseCacheTtl(cacheTtl);
|
|
40272
|
+
} catch {
|
|
40273
|
+
ttlMs = 5 * 60 * 1000;
|
|
40274
|
+
}
|
|
40275
|
+
if (ttlMs === Number.POSITIVE_INFINITY)
|
|
40276
|
+
return ttlMs;
|
|
40277
|
+
return lastResponseTime > 0 ? Math.max(0, ttlMs - (now - lastResponseTime)) : ttlMs;
|
|
40278
|
+
}
|
|
40134
40279
|
function buildPiStatusDetail(pi, ctx, deps, sessionId) {
|
|
40280
|
+
return buildStatusDetail(pi, ctx, deps, sessionId, {
|
|
40281
|
+
tokens: new PiStatusTokenCache
|
|
40282
|
+
});
|
|
40283
|
+
}
|
|
40284
|
+
function buildStatusDetail(pi, ctx, deps, sessionId, state, host = readStatusHostBytes(pi, ctx)) {
|
|
40135
40285
|
const usage = ctx.getContextUsage?.();
|
|
40136
40286
|
const meta = getOrCreateSessionMeta(deps.db, sessionId);
|
|
40137
40287
|
let detectedContextLimit;
|
|
@@ -40140,6 +40290,11 @@ function buildPiStatusDetail(pi, ctx, deps, sessionId) {
|
|
|
40140
40290
|
if (detected > 0)
|
|
40141
40291
|
detectedContextLimit = detected;
|
|
40142
40292
|
} catch {}
|
|
40293
|
+
state.live = {
|
|
40294
|
+
persistedInputTokens: meta.lastInputTokens,
|
|
40295
|
+
persistedPercentage: meta.lastContextPercentage,
|
|
40296
|
+
detectedContextLimit
|
|
40297
|
+
};
|
|
40143
40298
|
const windowGeometry = resolvePiWindowGeometry({
|
|
40144
40299
|
rawContextWindow: usage?.contextWindow ?? ctx.model?.contextWindow,
|
|
40145
40300
|
rawContextWindowSource: "catalog",
|
|
@@ -40174,29 +40329,24 @@ function buildPiStatusDetail(pi, ctx, deps, sessionId) {
|
|
|
40174
40329
|
const memoryTokens = m0Blocks.memoryTokens;
|
|
40175
40330
|
const docsTokens = m0Blocks.docsTokens;
|
|
40176
40331
|
const profileTokens = m0Blocks.profileTokens;
|
|
40177
|
-
|
|
40178
|
-
try {
|
|
40179
|
-
const sysPrompt = readHostSystemPrompt(ctx);
|
|
40180
|
-
if (sysPrompt !== undefined && sysPrompt.length > 0) {
|
|
40181
|
-
systemPromptTokens = estimateTokens(sysPrompt);
|
|
40182
|
-
}
|
|
40183
|
-
} catch {}
|
|
40332
|
+
const { systemPromptTokens, toolDefinitionTokens } = state.tokens.estimates(host, meta.systemPromptTokens);
|
|
40184
40333
|
const tags = getTagsBySession(deps.db, sessionId);
|
|
40185
40334
|
const activeTags = tags.filter((tag) => tag.status === "active");
|
|
40186
40335
|
const droppedTags = tags.filter((tag) => tag.status === "dropped");
|
|
40187
40336
|
const activeBytes = activeTags.reduce((sum, tag) => sum + tag.byteSize, 0);
|
|
40188
40337
|
const pendingOps = readPendingOpsCount(deps.db, sessionId);
|
|
40189
40338
|
const toolCallTokens = meta.toolCallTokens;
|
|
40190
|
-
|
|
40191
|
-
|
|
40192
|
-
|
|
40193
|
-
|
|
40194
|
-
|
|
40195
|
-
|
|
40196
|
-
|
|
40197
|
-
|
|
40198
|
-
|
|
40199
|
-
|
|
40339
|
+
const conversationTokens = conversationTokensFor({
|
|
40340
|
+
inputTokens,
|
|
40341
|
+
systemPromptTokens,
|
|
40342
|
+
compartmentTokens,
|
|
40343
|
+
factTokens,
|
|
40344
|
+
memoryTokens,
|
|
40345
|
+
docsTokens,
|
|
40346
|
+
profileTokens,
|
|
40347
|
+
toolCallTokens,
|
|
40348
|
+
toolDefinitionTokens
|
|
40349
|
+
});
|
|
40200
40350
|
const workMetrics = getSessionWorkMetrics(deps.db, sessionId);
|
|
40201
40351
|
const tailHygiene = resolveTailHygieneStatus(getPiChannel1Baseline(sessionId));
|
|
40202
40352
|
const modelKey = ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined;
|
|
@@ -40214,15 +40364,7 @@ ${safeStringify(tool.parameters)}`);
|
|
|
40214
40364
|
sessionModelKey: meta.lastObservedModelKey
|
|
40215
40365
|
});
|
|
40216
40366
|
const cacheTtl = cacheTtlDisplay.value;
|
|
40217
|
-
|
|
40218
|
-
try {
|
|
40219
|
-
cacheTtlMs = parseCacheTtl(cacheTtl);
|
|
40220
|
-
} catch {
|
|
40221
|
-
cacheTtlMs = 5 * 60 * 1000;
|
|
40222
|
-
}
|
|
40223
|
-
const neverExpires = cacheTtlMs === Number.POSITIVE_INFINITY;
|
|
40224
|
-
const elapsed = meta.lastResponseTime > 0 ? Date.now() - meta.lastResponseTime : 0;
|
|
40225
|
-
const cacheRemainingMs = neverExpires ? Number.POSITIVE_INFINITY : meta.lastResponseTime > 0 ? Math.max(0, cacheTtlMs - elapsed) : cacheTtlMs;
|
|
40367
|
+
const cacheRemainingMs = cacheRemaining(cacheTtl, meta.lastResponseTime, Date.now());
|
|
40226
40368
|
const cacheExpired = meta.lastResponseTime > 0 && cacheRemainingMs === 0;
|
|
40227
40369
|
const historyBlockTokens = compartmentTokens + factTokens;
|
|
40228
40370
|
const embeddingCoverage = safeRead(() => getEmbeddingCoverageStatus(deps.db, deps.projectIdentity, sessionId), {
|
package/dist/subagent-entry.js
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
ensureProjectRegisteredFromPiDirectory,
|
|
18
18
|
resolvePiHarnessKind,
|
|
19
19
|
registerMagicContextTools
|
|
20
|
-
} from "./index-
|
|
21
|
-
import"./index-
|
|
20
|
+
} from "./index-ykb8kkm3.js";
|
|
21
|
+
import"./index-r01b1b78.js";
|
|
22
22
|
import"./index-phh7e055.js";
|
|
23
23
|
import {
|
|
24
24
|
setStoragePrivatePermissionEnforcement
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/pi-magic-context",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"build": "bun ../../scripts/check-bun.mjs && tsc -p ../retina-local-fs/tsconfig.build.json && bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js transformers-web.js transformers-node-wasm.js && bun build ../plugin/src/features/magic-context/memory/transformers-web-entry.ts --outfile dist/transformers-web.js --target browser --format esm --external onnxruntime-web && bun ../plugin/scripts/build-transformers-node-wasm.ts dist && bun build src/index.ts src/subagent-entry.ts src/historian-calibration-extension.ts ../plugin/src/features/magic-context/memory/embedding-worker.ts ../plugin/src/features/magic-context/migration-worker.ts --outdir dist --entry-naming '[name].[ext]' --target node --format esm --splitting --external @earendil-works/pi-coding-agent --external @earendil-works/pi-tui --external onnxruntime-node --external onnxruntime-web --external sharp --external node:sqlite",
|
|
33
33
|
"build:e2e-argv": "bun ../../scripts/clean-dist-chunks.mjs ../../tests/docker/.generated subagent-runner-e2e.mjs && bun build src/subagent-runner.ts --outdir ../../tests/docker/.generated --entry-naming 'subagent-runner-e2e.mjs' --splitting --target node --format esm --external node:sqlite && node --input-type=module -e 'const { __test } = await import(\"../../tests/docker/.generated/subagent-runner-e2e.mjs\"); if (typeof __test.buildArgs !== \"function\" || typeof __test.resolvePiInvocation !== \"function\") throw new Error(\"argv renderer exports missing\"); console.log(\"Node argv renderer: 2 exports loaded\")'",
|
|
34
34
|
"typecheck": "tsc -p ../retina-local-fs/tsconfig.build.json && tsc --noEmit",
|
|
35
|
-
"test": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel --timeout 30000",
|
|
36
|
-
"test:serial": "bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --timeout 30000",
|
|
35
|
+
"test": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=4 --timeout 30000",
|
|
36
|
+
"test:serial": "bun ../../scripts/check-bun.mjs && bun install --frozen-lockfile && BUN_JSC_useOMGJIT=0 bun test --parallel=1 --timeout 30000",
|
|
37
37
|
"lint": "bun ../../scripts/check-bun.mjs && biome check src",
|
|
38
38
|
"lint:fix": "biome check --write src",
|
|
39
39
|
"format": "biome format --write src",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"clean": "bun ../../scripts/clean-dist-chunks.mjs dist index.js subagent-entry.js historian-calibration-extension.js embedding-worker.js migration-worker.js transformers-web.js transformers-node-wasm.js",
|
|
42
42
|
"prepublishOnly": "bun run build"
|
|
43
43
|
},
|
|
44
|
-
"//test": "
|
|
44
|
+
"//test": "Test runs cap file-isolated workers at four (one for test:serial) and disable JSC's optimizing WebAssembly tier so per-file isolation does not pay its compilation cost on every file. These are not production settings and do not change host process engine options.",
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@cortexkit/subc-client": "0.11.1",
|
|
47
47
|
"@jitl/quickjs-singlefile-cjs-release-asyncify": "0.32.0",
|