billion-context-pi 0.1.52 → 0.1.53-pr.262.50
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/commands.d.ts +2 -2
- package/dist/floor-stale.d.ts +25 -0
- package/dist/index.js +68 -137
- package/dist/index.js.map +1 -1
- package/dist/messages.d.ts +1 -0
- package/dist/runtime.d.ts +0 -12
- package/dist/tokens.d.ts +0 -6
- package/package.json +1 -1
- package/dist/density.d.ts +0 -19
package/dist/commands.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RegisteredCommand } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { ExtensionAPI, RegisteredCommand } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import type { AcpRuntime } from "./runtime.js";
|
|
3
3
|
type CommandOptions = Omit<RegisteredCommand, "name" | "sourceInfo">;
|
|
4
|
-
export declare function makeCommands(runtime: AcpRuntime): Array<{
|
|
4
|
+
export declare function makeCommands(runtime: AcpRuntime, pi?: ExtensionAPI): Array<{
|
|
5
5
|
name: string;
|
|
6
6
|
options: CommandOptions;
|
|
7
7
|
}>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type UsageLike = {
|
|
2
|
+
totalTokens?: number;
|
|
3
|
+
input?: number;
|
|
4
|
+
output?: number;
|
|
5
|
+
cacheRead?: number;
|
|
6
|
+
cacheWrite?: number;
|
|
7
|
+
} | null | undefined;
|
|
8
|
+
type AnchorEntry = {
|
|
9
|
+
type: string;
|
|
10
|
+
message?: {
|
|
11
|
+
role?: string;
|
|
12
|
+
stopReason?: string;
|
|
13
|
+
usage?: UsageLike;
|
|
14
|
+
toolName?: string;
|
|
15
|
+
toolCallId?: string;
|
|
16
|
+
isError?: boolean;
|
|
17
|
+
content?: unknown;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/** True when the last valid assistant usage anchor comes strictly BEFORE the
|
|
21
|
+
* last successful compress toolResult — the host's provider-usage number
|
|
22
|
+
* still reflects the pre-compression request. Failed/no-op compresses don't
|
|
23
|
+
* count (nothing was reclaimed). */
|
|
24
|
+
export declare function usageAnchorPredatesCompression(entries: AnchorEntry[]): boolean;
|
|
25
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -3569,89 +3569,6 @@ function parsePercent(v) {
|
|
|
3569
3569
|
return Number(s);
|
|
3570
3570
|
}
|
|
3571
3571
|
|
|
3572
|
-
// src/density.ts
|
|
3573
|
-
var DENSITY_MIN = 0.5;
|
|
3574
|
-
var DENSITY_MAX = 2.5;
|
|
3575
|
-
var MIN_DELTA_EST = 50;
|
|
3576
|
-
var CONFIRM_RATIO = 0.2;
|
|
3577
|
-
var INITIAL_DENSITY = 1;
|
|
3578
|
-
var DensityEstimator = class {
|
|
3579
|
-
models = /* @__PURE__ */ new Map();
|
|
3580
|
-
/** 重置指定模型(模型切换/会话开始时调用)。 */
|
|
3581
|
-
resetModel(modelId) {
|
|
3582
|
-
this.models.delete(modelId);
|
|
3583
|
-
}
|
|
3584
|
-
/** 返回当前密度系数(未知模型返回初始 1)。 */
|
|
3585
|
-
densityFor(modelId) {
|
|
3586
|
-
return this.models.get(modelId)?.density ?? INITIAL_DENSITY;
|
|
3587
|
-
}
|
|
3588
|
-
/**
|
|
3589
|
-
* 每轮 context 事件调用。realTotal 为 provider 真实 usage(可空),
|
|
3590
|
-
* estTotal 为本地估算总 token。postCompression 为压缩刚发生标志。
|
|
3591
|
-
*/
|
|
3592
|
-
update(modelId, realTotal, estTotal, postCompression = false) {
|
|
3593
|
-
if (realTotal === null) return;
|
|
3594
|
-
let est = this.models.get(modelId);
|
|
3595
|
-
if (!est) {
|
|
3596
|
-
est = {
|
|
3597
|
-
density: INITIAL_DENSITY,
|
|
3598
|
-
anchorReal: null,
|
|
3599
|
-
anchorEst: null,
|
|
3600
|
-
pendingDensity: null,
|
|
3601
|
-
confirmCount: 0,
|
|
3602
|
-
postCompressionSkip: false
|
|
3603
|
-
};
|
|
3604
|
-
this.models.set(modelId, est);
|
|
3605
|
-
}
|
|
3606
|
-
if (postCompression) {
|
|
3607
|
-
est.postCompressionSkip = true;
|
|
3608
|
-
return;
|
|
3609
|
-
}
|
|
3610
|
-
if (est.postCompressionSkip) {
|
|
3611
|
-
est.postCompressionSkip = false;
|
|
3612
|
-
est.anchorReal = realTotal;
|
|
3613
|
-
est.anchorEst = estTotal;
|
|
3614
|
-
est.pendingDensity = null;
|
|
3615
|
-
est.confirmCount = 0;
|
|
3616
|
-
return;
|
|
3617
|
-
}
|
|
3618
|
-
if (est.anchorReal === null || est.anchorEst === null) {
|
|
3619
|
-
est.anchorReal = realTotal;
|
|
3620
|
-
est.anchorEst = estTotal;
|
|
3621
|
-
return;
|
|
3622
|
-
}
|
|
3623
|
-
const dReal = realTotal - est.anchorReal;
|
|
3624
|
-
const dEst = estTotal - est.anchorEst;
|
|
3625
|
-
if (dEst < MIN_DELTA_EST) return;
|
|
3626
|
-
est.anchorReal = realTotal;
|
|
3627
|
-
est.anchorEst = estTotal;
|
|
3628
|
-
const instant = clamp(dReal / dEst, DENSITY_MIN, DENSITY_MAX);
|
|
3629
|
-
if (est.pendingDensity === null) {
|
|
3630
|
-
est.pendingDensity = instant;
|
|
3631
|
-
est.confirmCount = 1;
|
|
3632
|
-
} else if (Math.abs(instant - est.pendingDensity) / est.pendingDensity <= CONFIRM_RATIO) {
|
|
3633
|
-
est.confirmCount += 1;
|
|
3634
|
-
} else {
|
|
3635
|
-
est.pendingDensity = instant;
|
|
3636
|
-
est.confirmCount = 1;
|
|
3637
|
-
}
|
|
3638
|
-
if (est.confirmCount >= 2) {
|
|
3639
|
-
est.density = est.pendingDensity;
|
|
3640
|
-
est.confirmCount = 0;
|
|
3641
|
-
est.pendingDensity = null;
|
|
3642
|
-
}
|
|
3643
|
-
}
|
|
3644
|
-
/** 注入器:估算文本 token = defaultCountTokens × density。 */
|
|
3645
|
-
estimateWithDensity(modelId, text) {
|
|
3646
|
-
const d = this.densityFor(modelId);
|
|
3647
|
-
if (d === 1) return defaultCountTokens(text);
|
|
3648
|
-
return Math.round(defaultCountTokens(text) * d);
|
|
3649
|
-
}
|
|
3650
|
-
};
|
|
3651
|
-
function clamp(v, lo, hi) {
|
|
3652
|
-
return v < lo ? lo : v > hi ? hi : v;
|
|
3653
|
-
}
|
|
3654
|
-
|
|
3655
3572
|
// src/tag-tokens.ts
|
|
3656
3573
|
function formatTokens3(tokens) {
|
|
3657
3574
|
if (tokens < 1e3) return String(tokens);
|
|
@@ -3669,11 +3586,12 @@ function rewriteTagTokens(tag, body) {
|
|
|
3669
3586
|
var REF_TAG_SOURCE = "(?:<acp\\s[^>]*>m\\d{5}</acp>|\\[m\\d{1,5}\\])";
|
|
3670
3587
|
var REF_TAG = new RegExp(`^${REF_TAG_SOURCE}\\s?\\n?`);
|
|
3671
3588
|
var TRAILING_REF_TAG = new RegExp(`\\n*${REF_TAG_SOURCE}\\s*$`);
|
|
3589
|
+
var ACP_STATUS_CUSTOM_TYPE = "acp-status";
|
|
3672
3590
|
function entriesToCoreMessages(entries) {
|
|
3673
3591
|
const out = [];
|
|
3674
3592
|
for (const entry of entries) {
|
|
3675
3593
|
if (entry.type !== "message") {
|
|
3676
|
-
if (entry.type === "custom_message") {
|
|
3594
|
+
if (entry.type === "custom_message" && entry.customType !== ACP_STATUS_CUSTOM_TYPE) {
|
|
3677
3595
|
const text = extractText(entry.content);
|
|
3678
3596
|
if (text.length > 0) {
|
|
3679
3597
|
out.push({ id: entry.id, role: "user", contentType: "text", text });
|
|
@@ -4622,14 +4540,12 @@ function pruneOrphanRefs(state, messages) {
|
|
|
4622
4540
|
}
|
|
4623
4541
|
var MAX_COMPRESS_ATTEMPTS = 3;
|
|
4624
4542
|
function createRuntime(adapter) {
|
|
4625
|
-
const density = new DensityEstimator();
|
|
4626
|
-
let countModelId = "default";
|
|
4627
4543
|
const core = createCore({
|
|
4628
|
-
//
|
|
4629
|
-
|
|
4544
|
+
// CJK-aware base counter (kernel default); the meter's real-scale floor
|
|
4545
|
+
// (src/index.ts) covers provider-anchored calibration.
|
|
4546
|
+
countTokens: defaultCountTokens
|
|
4630
4547
|
});
|
|
4631
4548
|
const store = new SessionStateStore();
|
|
4632
|
-
const lastActiveBlockIds = /* @__PURE__ */ new Map();
|
|
4633
4549
|
const locks = /* @__PURE__ */ new Map();
|
|
4634
4550
|
const factoryAdapter = adapter;
|
|
4635
4551
|
let adapterRef = adapter;
|
|
@@ -4754,19 +4670,7 @@ function createRuntime(adapter) {
|
|
|
4754
4670
|
const sm = ctx.sessionManager;
|
|
4755
4671
|
await store.save(state, sm.getSessionFile() ?? void 0, sm.getSessionId());
|
|
4756
4672
|
}
|
|
4757
|
-
|
|
4758
|
-
const current = new Set(activeBlockIds);
|
|
4759
|
-
const prev = lastActiveBlockIds.get(sid);
|
|
4760
|
-
const isNew = prev !== void 0 && activeBlockIds.some((id) => !prev.has(id));
|
|
4761
|
-
lastActiveBlockIds.set(sid, current);
|
|
4762
|
-
return isNew;
|
|
4763
|
-
}
|
|
4764
|
-
function clearSessionTracking(sid) {
|
|
4765
|
-
lastActiveBlockIds.delete(sid);
|
|
4766
|
-
}
|
|
4767
|
-
return { core, store, density, setCountModel: (m) => {
|
|
4768
|
-
countModelId = m;
|
|
4769
|
-
}, noteActiveBlocks, clearSessionTracking, get adapter() {
|
|
4673
|
+
return { core, store, get adapter() {
|
|
4770
4674
|
return adapterRef;
|
|
4771
4675
|
}, setAdapter: (a) => {
|
|
4772
4676
|
adapterRef = a;
|
|
@@ -9210,9 +9114,6 @@ function estimateTokens(messages, coveredIds, imageTokensById) {
|
|
|
9210
9114
|
}
|
|
9211
9115
|
return tokens;
|
|
9212
9116
|
}
|
|
9213
|
-
function calibrateTokens(estimate, density) {
|
|
9214
|
-
return density === 1 ? estimate : Math.round(estimate * density);
|
|
9215
|
-
}
|
|
9216
9117
|
function lastUserMessageId(entries) {
|
|
9217
9118
|
for (let i = entries.length - 1; i >= 0; i--) {
|
|
9218
9119
|
const e = entries[i];
|
|
@@ -9346,18 +9247,16 @@ async function handleCompress(args, runtime, ctx, toolCallId) {
|
|
|
9346
9247
|
messages: coreMessages,
|
|
9347
9248
|
state: initialState,
|
|
9348
9249
|
config,
|
|
9349
|
-
tokenCount:
|
|
9250
|
+
tokenCount: sentTokens
|
|
9350
9251
|
});
|
|
9351
9252
|
const state = turn.state;
|
|
9352
9253
|
const messages = turn.messages;
|
|
9353
|
-
const
|
|
9354
|
-
const beforeTokens = calibrateTokens(estimateTokens(messages, collectCoveredMessageIds(state), imageTokens), density);
|
|
9254
|
+
const beforeTokens = estimateTokens(messages, collectCoveredMessageIds(state), imageTokens);
|
|
9355
9255
|
const summaryMaxChars = args.summaryMaxChars;
|
|
9356
9256
|
const topLevelTopic = args.topic;
|
|
9357
9257
|
debug.event("compress-in", {
|
|
9358
9258
|
sid: ctx.sessionManager.getSessionId(),
|
|
9359
9259
|
modelId,
|
|
9360
|
-
density,
|
|
9361
9260
|
ranges: ranges.length,
|
|
9362
9261
|
spans: ranges.map((r) => ({ span: `${r.startId}..${r.endId}`, summaryLen: r.summary.length, summary: r.summary, topic: r.topic ?? topLevelTopic ?? null })),
|
|
9363
9262
|
blocksBefore: state.blocks.length,
|
|
@@ -9389,9 +9288,9 @@ async function handleCompress(args, runtime, ctx, toolCallId) {
|
|
|
9389
9288
|
messages: coreMessages,
|
|
9390
9289
|
state: applied.state,
|
|
9391
9290
|
config,
|
|
9392
|
-
tokenCount:
|
|
9291
|
+
tokenCount: sentTokens
|
|
9393
9292
|
});
|
|
9394
|
-
const afterTokens =
|
|
9293
|
+
const afterTokens = estimateTokens(afterTurn.messages, collectCoveredMessageIds(applied.state), imageTokens);
|
|
9395
9294
|
const reclaimed = Math.max(0, beforeTokens - afterTokens);
|
|
9396
9295
|
const newBlocks = applied.state.blocks.slice(-blocksCreated);
|
|
9397
9296
|
debug.event("compress-out", {
|
|
@@ -9748,6 +9647,27 @@ function formatSize(tokens) {
|
|
|
9748
9647
|
return `${(tokens / 1e6).toFixed(1)}M`;
|
|
9749
9648
|
}
|
|
9750
9649
|
|
|
9650
|
+
// src/floor-stale.ts
|
|
9651
|
+
function validAnchorUsage(u) {
|
|
9652
|
+
if (!u) return false;
|
|
9653
|
+
const total = (u.totalTokens ?? 0) || (u.input ?? 0) + (u.output ?? 0) + (u.cacheRead ?? 0) + (u.cacheWrite ?? 0);
|
|
9654
|
+
return total > 0;
|
|
9655
|
+
}
|
|
9656
|
+
function usageAnchorPredatesCompression(entries) {
|
|
9657
|
+
let lastUsageIdx = -1;
|
|
9658
|
+
let lastCompressIdx = -1;
|
|
9659
|
+
for (let i = 0; i < entries.length; i++) {
|
|
9660
|
+
const m = entries[i].message;
|
|
9661
|
+
if (!m) continue;
|
|
9662
|
+
if (m.role === "assistant" && m.stopReason !== "aborted" && m.stopReason !== "error" && validAnchorUsage(m.usage)) {
|
|
9663
|
+
lastUsageIdx = i;
|
|
9664
|
+
} else if (m.role === "toolResult" && m.toolName === "compress" && m.toolCallId !== void 0 && m.isError !== true && isCompressSuccessText(extractText(m.content))) {
|
|
9665
|
+
lastCompressIdx = i;
|
|
9666
|
+
}
|
|
9667
|
+
}
|
|
9668
|
+
return lastCompressIdx > lastUsageIdx;
|
|
9669
|
+
}
|
|
9670
|
+
|
|
9751
9671
|
// src/delegate-tool.ts
|
|
9752
9672
|
import {
|
|
9753
9673
|
spawn
|
|
@@ -11071,15 +10991,16 @@ async function handleStatus(args, runtime, ctx) {
|
|
|
11071
10991
|
const { state, coreMessages, entries } = await runtime.stateFor(ctx);
|
|
11072
10992
|
const config = runtime.configFor(ctx);
|
|
11073
10993
|
const coveredIds = collectCoveredMessageIds(state);
|
|
11074
|
-
const modelId = ctx.model?.id ?? "default";
|
|
11075
10994
|
const systemPromptText = getSystemPromptText(ctx);
|
|
11076
10995
|
const systemPromptTokens = systemPromptText ? defaultCountTokens(systemPromptText) : 0;
|
|
11077
10996
|
const sentTokens = estimateTokens(coreMessages, coveredIds, collectImageTokens(entries, modelSupportsImages(ctx.model))) + systemPromptTokens;
|
|
10997
|
+
const providerReal = ctx.getContextUsage?.()?.tokens ?? 0;
|
|
10998
|
+
const anchorStale = usageAnchorPredatesCompression(entries);
|
|
11078
10999
|
const turn = runtime.core.processTurn({
|
|
11079
11000
|
messages: coreMessages,
|
|
11080
11001
|
state,
|
|
11081
11002
|
config,
|
|
11082
|
-
tokenCount:
|
|
11003
|
+
tokenCount: anchorStale ? sentTokens : Math.max(sentTokens, providerReal)
|
|
11083
11004
|
});
|
|
11084
11005
|
const processed = turn.messages;
|
|
11085
11006
|
const base = buildStatusReport(turn.state, processed, defaultCountTokens, {
|
|
@@ -11094,6 +11015,15 @@ async function handleStatus(args, runtime, ctx) {
|
|
|
11094
11015
|
const ranges = viableRanges(nudge?.compressibleRanges ?? []);
|
|
11095
11016
|
const protectedRanges = nudge?.protectedRanges ?? [];
|
|
11096
11017
|
const extra = [];
|
|
11018
|
+
if (providerReal > 0 && config.modelContextLimit > 0) {
|
|
11019
|
+
const fmtK = (n) => n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n);
|
|
11020
|
+
const estPct = Math.round(sentTokens / config.modelContextLimit * 100);
|
|
11021
|
+
const realPct = Math.round(providerReal / config.modelContextLimit * 100);
|
|
11022
|
+
extra.push("");
|
|
11023
|
+
extra.push(
|
|
11024
|
+
`Estimate: ${fmtK(sentTokens)} (${estPct}%) | Provider-reported: ${fmtK(providerReal)} (${realPct}%)`
|
|
11025
|
+
);
|
|
11026
|
+
}
|
|
11097
11027
|
if (nudge) {
|
|
11098
11028
|
extra.push("");
|
|
11099
11029
|
extra.push(
|
|
@@ -11467,20 +11397,28 @@ function cacheUsageSamples(entries) {
|
|
|
11467
11397
|
}
|
|
11468
11398
|
return out;
|
|
11469
11399
|
}
|
|
11470
|
-
function makeCommands(runtime) {
|
|
11400
|
+
function makeCommands(runtime, pi) {
|
|
11401
|
+
const statusHandler = async (_args, ctx) => {
|
|
11402
|
+
const text = await statusReport(runtime, ctx);
|
|
11403
|
+
if (typeof pi?.sendMessage === "function") {
|
|
11404
|
+
pi.sendMessage({ customType: ACP_STATUS_CUSTOM_TYPE, content: text, display: true });
|
|
11405
|
+
return;
|
|
11406
|
+
}
|
|
11407
|
+
ctx.ui.notify(text);
|
|
11408
|
+
};
|
|
11471
11409
|
return [
|
|
11472
11410
|
{
|
|
11473
11411
|
name: "acp",
|
|
11474
11412
|
options: {
|
|
11475
11413
|
description: "Show ACP context usage, token breakdown, and compression status.",
|
|
11476
|
-
handler:
|
|
11414
|
+
handler: statusHandler
|
|
11477
11415
|
}
|
|
11478
11416
|
},
|
|
11479
11417
|
{
|
|
11480
11418
|
name: "acp-status",
|
|
11481
11419
|
options: {
|
|
11482
11420
|
description: "Detailed ACP status (block tiers, token breakdown, delegate usage).",
|
|
11483
|
-
handler:
|
|
11421
|
+
handler: statusHandler
|
|
11484
11422
|
}
|
|
11485
11423
|
},
|
|
11486
11424
|
{
|
|
@@ -11556,16 +11494,16 @@ async function statusReport(runtime, ctx) {
|
|
|
11556
11494
|
const { state, coreMessages, entries } = await runtime.stateFor(ctx);
|
|
11557
11495
|
const config = runtime.configFor(ctx);
|
|
11558
11496
|
const realUsage = ctx.getContextUsage?.();
|
|
11497
|
+
const anchorStale = usageAnchorPredatesCompression(entries ?? []);
|
|
11559
11498
|
const systemPromptText = getSystemPromptText(ctx);
|
|
11560
11499
|
const systemPromptTokens = systemPromptText ? defaultCountTokens(systemPromptText) : 0;
|
|
11561
11500
|
const imageTokens = collectImageTokens(entries, modelSupportsImages(ctx.model));
|
|
11562
11501
|
const imageTokensTotal = [...imageTokens.values()].reduce((a, b) => a + b, 0);
|
|
11563
|
-
const sessionTokens = realUsage?.tokens && realUsage.tokens > 0 ? realUsage.tokens : defaultCountTokens(coreMessages.map((m) => m.text ?? "").join("\n")) + imageTokensTotal;
|
|
11502
|
+
const sessionTokens = !anchorStale && realUsage?.tokens && realUsage.tokens > 0 ? realUsage.tokens : defaultCountTokens(coreMessages.map((m) => m.text ?? "").join("\n")) + imageTokensTotal;
|
|
11564
11503
|
const coveredIds = collectCoveredMessageIds(state);
|
|
11565
|
-
const modelId = ctx.model?.id ?? "default";
|
|
11566
11504
|
const sentTokens = estimateTokens(coreMessages, coveredIds, imageTokens) + systemPromptTokens;
|
|
11567
|
-
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount:
|
|
11568
|
-
const versionStr = "0.1.
|
|
11505
|
+
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: anchorStale ? sentTokens : Math.max(sentTokens, realUsage?.tokens ?? 0) });
|
|
11506
|
+
const versionStr = "0.1.53" ? `billion-context-pi@${"0.1.53"}` : void 0;
|
|
11569
11507
|
let text = buildStatusPanel({
|
|
11570
11508
|
version: versionStr,
|
|
11571
11509
|
tokenCount: sessionTokens,
|
|
@@ -11928,7 +11866,7 @@ async function autoInstallLatest(latest, extDirOverride) {
|
|
|
11928
11866
|
"--no-fund",
|
|
11929
11867
|
"--no-save"
|
|
11930
11868
|
];
|
|
11931
|
-
const prevVersion = (await readPackageJson(join8(extDir, "package.json")))?.version ?? "0.1.
|
|
11869
|
+
const prevVersion = (await readPackageJson(join8(extDir, "package.json")))?.version ?? "0.1.53";
|
|
11932
11870
|
const { code, stderr } = await runNpmImpl(installArgs(latest), { cwd: npmDir, timeout: 6e4 });
|
|
11933
11871
|
if (code !== 0) {
|
|
11934
11872
|
logWarn("update", {
|
|
@@ -11941,7 +11879,7 @@ async function autoInstallLatest(latest, extDirOverride) {
|
|
|
11941
11879
|
}
|
|
11942
11880
|
const verify = await verifyInstall(npmDir, latest);
|
|
11943
11881
|
if (!verify.ok) {
|
|
11944
|
-
const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.
|
|
11882
|
+
const rollbackTo = SEMVER_RE.test(prevVersion) ? prevVersion : "0.1.53";
|
|
11945
11883
|
logWarn("update", { event: "auto-install-verify-failed", latest, reason: verify.reason, rollbackTo });
|
|
11946
11884
|
const rb = await runNpmImpl(installArgs(rollbackTo), { cwd: npmDir, timeout: 6e4 });
|
|
11947
11885
|
logInfo("update", { event: "rollback", from: latest, to: rollbackTo, ok: rb.code === 0 });
|
|
@@ -12002,7 +11940,7 @@ async function checkForUpdate(autoUpdate, notify) {
|
|
|
12002
11940
|
const runtimeVersion = await getRuntimeVersion();
|
|
12003
11941
|
const latest = await fetchLatestVersion();
|
|
12004
11942
|
if (!latest) return;
|
|
12005
|
-
const current = runtimeVersion ?? "0.1.
|
|
11943
|
+
const current = runtimeVersion ?? "0.1.53";
|
|
12006
11944
|
const hasUpdate = isNewer(latest, current);
|
|
12007
11945
|
debug.event("update-check", {
|
|
12008
11946
|
current,
|
|
@@ -12059,7 +11997,7 @@ function createAcpExtension(adapter = {}) {
|
|
|
12059
11997
|
pi.registerTool(makeDecompressTool(runtime));
|
|
12060
11998
|
pi.registerTool(makeSearchTool(runtime));
|
|
12061
11999
|
pi.registerTool(makeStatusTool(runtime));
|
|
12062
|
-
for (const { name, options } of makeCommands(runtime)) {
|
|
12000
|
+
for (const { name, options } of makeCommands(runtime, pi)) {
|
|
12063
12001
|
pi.registerCommand(name, options);
|
|
12064
12002
|
}
|
|
12065
12003
|
};
|
|
@@ -12074,14 +12012,11 @@ function wireSessionLifecycle(pi, runtime) {
|
|
|
12074
12012
|
runtime.clearNudgeTracking();
|
|
12075
12013
|
runtime.throttleFor(ctx.sessionManager.getSessionId()).reset();
|
|
12076
12014
|
runtime.clearCompressRetryTracking();
|
|
12077
|
-
const modelId = ctx.model?.id ?? "default";
|
|
12078
|
-
runtime.density.resetModel(modelId);
|
|
12079
12015
|
resetDelegateUsage();
|
|
12080
12016
|
setDelegateDisplayUsage("separate");
|
|
12081
12017
|
const sid = ctx.sessionManager.getSessionId();
|
|
12082
|
-
runtime.clearSessionTracking(sid);
|
|
12083
12018
|
const modelInfo = ctx.model;
|
|
12084
|
-
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.
|
|
12019
|
+
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.53" : null, model: modelInfo?.id ?? null, modelApi: modelInfo?.api ?? null, contextWindow: modelInfo?.contextWindow ?? null });
|
|
12085
12020
|
try {
|
|
12086
12021
|
await runtime.reloadConfig(ctx.cwd);
|
|
12087
12022
|
setDelegateDisplayUsage(resolveDelegate(runtime.adapter).displayUsage);
|
|
@@ -12117,7 +12052,6 @@ function wireContextTransform(pi, runtime) {
|
|
|
12117
12052
|
try {
|
|
12118
12053
|
await runtime.reloadConfig(ctx.cwd);
|
|
12119
12054
|
const modelId = ctx.model?.id ?? "default";
|
|
12120
|
-
runtime.setCountModel(modelId);
|
|
12121
12055
|
const { state, coreMessages, entries } = await runtime.stateFor(ctx, event.messages);
|
|
12122
12056
|
const configBase = runtime.configFor(ctx);
|
|
12123
12057
|
const ov = runtime.overflowFor(sid);
|
|
@@ -12141,7 +12075,11 @@ function wireContextTransform(pi, runtime) {
|
|
|
12141
12075
|
const systemPromptText = getSystemPromptText(ctx);
|
|
12142
12076
|
const systemPromptTokens = systemPromptText ? defaultCountTokens(systemPromptText) : 0;
|
|
12143
12077
|
const sentTokens = estimateTokens(coreMessages, coveredIds, collectImageTokens(entries, modelSupportsImages(ctx.model))) + systemPromptTokens;
|
|
12144
|
-
let tokenCount =
|
|
12078
|
+
let tokenCount = sentTokens;
|
|
12079
|
+
const realPromptTokens = realUsage?.tokens ?? 0;
|
|
12080
|
+
if (!usageAnchorPredatesCompression(entries) && realPromptTokens > tokenCount) {
|
|
12081
|
+
tokenCount = realPromptTokens;
|
|
12082
|
+
}
|
|
12145
12083
|
if (ov.armed && config.modelContextLimit > 0) {
|
|
12146
12084
|
ov.armed = false;
|
|
12147
12085
|
const floor = Math.floor(config.modelContextLimit * 0.95);
|
|
@@ -12150,14 +12088,9 @@ function wireContextTransform(pi, runtime) {
|
|
|
12150
12088
|
logWarn("overflow-selfheal", { sid, event: "armed-emergency", tokenCount, limit: config.modelContextLimit });
|
|
12151
12089
|
}
|
|
12152
12090
|
}
|
|
12153
|
-
const postCompression = runtime.noteActiveBlocks(
|
|
12154
|
-
sid,
|
|
12155
|
-
state.blocks.filter((b) => b.active).map((b) => b.blockId)
|
|
12156
|
-
);
|
|
12157
12091
|
debug.event("context-in", {
|
|
12158
12092
|
sid,
|
|
12159
12093
|
modelId,
|
|
12160
|
-
density: runtime.density.densityFor(modelId),
|
|
12161
12094
|
eventMsgs: event.messages?.length ?? 0,
|
|
12162
12095
|
entries: entries.length,
|
|
12163
12096
|
coreMsgs: coreMessages.length,
|
|
@@ -12169,7 +12102,6 @@ function wireContextTransform(pi, runtime) {
|
|
|
12169
12102
|
});
|
|
12170
12103
|
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount });
|
|
12171
12104
|
await runtime.save(turn.state, ctx);
|
|
12172
|
-
runtime.density.update(modelId, realUsage?.tokens ?? null, sentTokens, postCompression);
|
|
12173
12105
|
logInfo("turn", {
|
|
12174
12106
|
sid,
|
|
12175
12107
|
model: ctx.model?.id ?? null,
|
|
@@ -12185,7 +12117,6 @@ function wireContextTransform(pi, runtime) {
|
|
|
12185
12117
|
});
|
|
12186
12118
|
debug.event("processTurn", {
|
|
12187
12119
|
modelId,
|
|
12188
|
-
density: runtime.density.densityFor(modelId),
|
|
12189
12120
|
outMsgs: turn.messages.length,
|
|
12190
12121
|
summaryMsgs: turn.messages.filter((m) => m.id.startsWith("acp_summary")).length,
|
|
12191
12122
|
prunedMsgs: coreMessages.length - turn.messages.length + turn.messages.filter((m) => m.id.startsWith("acp_summary")).length,
|