billion-context-omp 0.1.6 → 0.1.7
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/README.md +12 -9
- package/README.zh-CN.md +12 -9
- package/dist/index.js +48 -40
- package/dist/index.js.map +1 -1
- package/dist/tokens.d.ts +13 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -90,20 +90,23 @@ Rich status display for the user:
|
|
|
90
90
|
╭─────────────────────────────────────────────╮
|
|
91
91
|
│ ACP Context Analysis │
|
|
92
92
|
╰─────────────────────────────────────────────╯
|
|
93
|
-
billion-context-omp@0.
|
|
93
|
+
billion-context-omp@0.2.0
|
|
94
94
|
|
|
95
|
-
Context:
|
|
95
|
+
Context (session accounting, host footer scale): 9% (93k / 1.0M) — never shrinks; includes compressed originals
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Framework ██████████████████░░ 90% 51k
|
|
97
|
+
Sent to LLM (after compression, est.): 63k (6% of limit)
|
|
98
|
+
Session-only (compressed originals, est.): 110k — pruned from every request; the footer/nudge still count them
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
Token Breakdown (sent view):
|
|
101
|
+
Tool ██████████████████░░ 88% 55k
|
|
102
|
+
SysPrompt ██░░░░░░░░░░░░░░░░░ 9% 5.9k
|
|
103
|
+
Text ░░░░░░░░░░░░░░░░░░░░ 1% 553
|
|
104
|
+
Summaries ░░░░░░░░░░░░░░░░░░░░ 2% 1.5k
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
[b1] T1 5.1k→1.0k: Fold architecture port
|
|
105
|
-
[b2] T1 15k→799: Replay guard hardening
|
|
106
|
+
Nudge: idle — growth 0 < floor 20000, ready: T1 50394
|
|
106
107
|
|
|
108
|
+
Blocks: 1 active / 1 total (112k tokens compressed)
|
|
109
|
+
[b1] T1 112k→1.5k: PR141 review + follow-up fixes
|
|
107
110
|
Tag visibility: tags injected to LLM only (deep copy), not persisted in session, not shown in terminal.
|
|
108
111
|
```
|
|
109
112
|
|
package/README.zh-CN.md
CHANGED
|
@@ -90,20 +90,23 @@ omp 内置的 `/compact` 被拦截,替换为 ACP 模型摘要式 compaction,
|
|
|
90
90
|
╭─────────────────────────────────────────────╮
|
|
91
91
|
│ ACP Context Analysis │
|
|
92
92
|
╰─────────────────────────────────────────────╯
|
|
93
|
-
billion-context-omp@0.
|
|
93
|
+
billion-context-omp@0.2.0
|
|
94
94
|
|
|
95
|
-
Context:
|
|
95
|
+
Context (session accounting, host footer scale): 9% (93k / 1.0M) — never shrinks; includes compressed originals
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
Framework ██████████████████░░ 90% 51k
|
|
97
|
+
Sent to LLM (after compression, est.): 63k (6% of limit)
|
|
98
|
+
Session-only (compressed originals, est.): 110k — pruned from every request; the footer/nudge still count them
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
Token Breakdown (sent view):
|
|
101
|
+
Tool ██████████████████░░ 88% 55k
|
|
102
|
+
SysPrompt ██░░░░░░░░░░░░░░░░░ 9% 5.9k
|
|
103
|
+
Text ░░░░░░░░░░░░░░░░░░░░ 1% 553
|
|
104
|
+
Summaries ░░░░░░░░░░░░░░░░░░░░ 2% 1.5k
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
[b1] T1 5.1k→1.0k: Fold architecture port
|
|
105
|
-
[b2] T1 15k→799: Replay guard hardening
|
|
106
|
+
Nudge: idle — growth 0 < floor 20000, ready: T1 50394
|
|
106
107
|
|
|
108
|
+
Blocks: 1 active / 1 total (112k tokens compressed)
|
|
109
|
+
[b1] T1 112k→1.5k: PR141 review + follow-up fixes
|
|
107
110
|
Tag visibility: tags injected to LLM only (deep copy), not persisted in session, not shown in terminal.
|
|
108
111
|
```
|
|
109
112
|
|
package/dist/index.js
CHANGED
|
@@ -3680,6 +3680,23 @@ function truncate(s, n) {
|
|
|
3680
3680
|
// src/status-tool.ts
|
|
3681
3681
|
import { type as type4 } from "@oh-my-pi/omptype";
|
|
3682
3682
|
|
|
3683
|
+
// src/compat.ts
|
|
3684
|
+
function normalizeSystemPrompt(input) {
|
|
3685
|
+
if (input === void 0) return "";
|
|
3686
|
+
if (Array.isArray(input)) return input.join("\n");
|
|
3687
|
+
return input;
|
|
3688
|
+
}
|
|
3689
|
+
function formatSystemPromptForEvent(base, append) {
|
|
3690
|
+
const normalized = normalizeSystemPrompt(base);
|
|
3691
|
+
return [`${normalized}
|
|
3692
|
+
|
|
3693
|
+
${append}`];
|
|
3694
|
+
}
|
|
3695
|
+
function getSystemPromptText(ctx) {
|
|
3696
|
+
const result = ctx.getSystemPrompt?.();
|
|
3697
|
+
return normalizeSystemPrompt(result);
|
|
3698
|
+
}
|
|
3699
|
+
|
|
3683
3700
|
// node_modules/billion-context-kit/dist/index.js
|
|
3684
3701
|
var VIABLE_RANGE_MIN_TOKENS = 200;
|
|
3685
3702
|
function viableRanges(ranges) {
|
|
@@ -3710,9 +3727,10 @@ function buildStatusPanel(input) {
|
|
|
3710
3727
|
const classified = bd ? bd.system + bd.tool + bd.summaries + bd.code + bd.text : 0;
|
|
3711
3728
|
const systemPromptTokens = input.systemPromptTokens;
|
|
3712
3729
|
const sentTotal = classified + systemPromptTokens;
|
|
3713
|
-
const sessionOnly = Math.max(0,
|
|
3730
|
+
const sessionOnly = input.unprunedTokens !== void 0 ? Math.max(0, input.unprunedTokens - sentTotal) : 0;
|
|
3714
3731
|
const displayTotal = tokenCount;
|
|
3715
3732
|
const displayPct = limit > 0 ? Math.round(displayTotal / limit * 100) : 0;
|
|
3733
|
+
const sentPct = limit > 0 ? Math.round(sentTotal / limit * 100) : 0;
|
|
3716
3734
|
const activeBlocksList = state.blocks.filter((b) => b.active);
|
|
3717
3735
|
const totalBlocksList = state.blocks;
|
|
3718
3736
|
const lines = [];
|
|
@@ -3721,16 +3739,16 @@ function buildStatusPanel(input) {
|
|
|
3721
3739
|
lines.push("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F");
|
|
3722
3740
|
if (input.version) lines.push(input.version);
|
|
3723
3741
|
lines.push("");
|
|
3724
|
-
lines.push(`Context (session accounting): ${displayPct}% (${fmt2(displayTotal)} / ${fmt2(limit)})`);
|
|
3742
|
+
lines.push(`Context (session accounting, host footer scale): ${displayPct}% (${fmt2(displayTotal)} / ${fmt2(limit)}) \u2014 never shrinks; includes compressed originals`);
|
|
3725
3743
|
if (nudge && bd) {
|
|
3726
3744
|
const growth = bd.growth;
|
|
3727
3745
|
if (growth > 0 && displayTotal > 0) {
|
|
3728
3746
|
lines.push(`Growth: +${fmt2(growth)} since last nudge`);
|
|
3729
3747
|
}
|
|
3730
3748
|
lines.push("");
|
|
3731
|
-
lines.push(`Sent to LLM (after compression): ${fmt2(sentTotal)}`);
|
|
3732
|
-
if (sessionOnly > 0) {
|
|
3733
|
-
lines.push(`Session-only (compressed originals
|
|
3749
|
+
lines.push(`Sent to LLM (after compression, est.): ${fmt2(sentTotal)}${limit > 0 ? ` (${sentPct}% of limit)` : ""}`);
|
|
3750
|
+
if (input.unprunedTokens !== void 0 && sessionOnly > 0) {
|
|
3751
|
+
lines.push(`Session-only (compressed originals, est.): ${fmt2(sessionOnly)} \u2014 pruned from every request; the footer/nudge still count them`);
|
|
3734
3752
|
}
|
|
3735
3753
|
lines.push("");
|
|
3736
3754
|
lines.push("Token Breakdown (sent view):");
|
|
@@ -3813,13 +3831,16 @@ function makeStatusTool(runtime) {
|
|
|
3813
3831
|
async function handleStatus(args, runtime, ctx) {
|
|
3814
3832
|
const { state, coreMessages } = await runtime.stateFor(ctx);
|
|
3815
3833
|
const config = runtime.configFor(ctx);
|
|
3816
|
-
const tokenCount = estimateTokens(coreMessages, collectCoveredMessageIds(state));
|
|
3817
|
-
const realUsage = ctx.getContextUsage?.();
|
|
3834
|
+
const tokenCount = estimateTokens(coreMessages, collectCoveredMessageIds(state)) + estimateTextTokens2(getSystemPromptText(ctx) ?? "");
|
|
3818
3835
|
const turn = runtime.core.processTurn({
|
|
3819
3836
|
messages: coreMessages,
|
|
3820
3837
|
state,
|
|
3821
3838
|
config,
|
|
3822
|
-
|
|
3839
|
+
// Sent-view scale — see src/index.ts context handler. The session-tree
|
|
3840
|
+
// number (ctx.getContextUsage) must never arbitrate emergencies for the
|
|
3841
|
+
// sent view: a tree that outgrew the model window reads as a permanent
|
|
3842
|
+
// 200%+ emergency while the real sent view is a few percent.
|
|
3843
|
+
tokenCount
|
|
3823
3844
|
});
|
|
3824
3845
|
const processed = turn.messages;
|
|
3825
3846
|
const base = buildStatusReport(turn.state, processed, defaultCountTokens, {
|
|
@@ -3848,23 +3869,6 @@ async function handleStatus(args, runtime, ctx) {
|
|
|
3848
3869
|
${extra.join("\n")}` : base;
|
|
3849
3870
|
}
|
|
3850
3871
|
|
|
3851
|
-
// src/compat.ts
|
|
3852
|
-
function normalizeSystemPrompt(input) {
|
|
3853
|
-
if (input === void 0) return "";
|
|
3854
|
-
if (Array.isArray(input)) return input.join("\n");
|
|
3855
|
-
return input;
|
|
3856
|
-
}
|
|
3857
|
-
function formatSystemPromptForEvent(base, append) {
|
|
3858
|
-
const normalized = normalizeSystemPrompt(base);
|
|
3859
|
-
return [`${normalized}
|
|
3860
|
-
|
|
3861
|
-
${append}`];
|
|
3862
|
-
}
|
|
3863
|
-
function getSystemPromptText(ctx) {
|
|
3864
|
-
const result = ctx.getSystemPrompt?.();
|
|
3865
|
-
return normalizeSystemPrompt(result);
|
|
3866
|
-
}
|
|
3867
|
-
|
|
3868
3872
|
// src/commands.ts
|
|
3869
3873
|
function safeHandler(handler) {
|
|
3870
3874
|
return async (args, ctx) => {
|
|
@@ -3946,17 +3950,21 @@ async function statusReport(runtime, ctx) {
|
|
|
3946
3950
|
const { state, coreMessages } = await runtime.stateFor(ctx);
|
|
3947
3951
|
const config = runtime.configFor(ctx);
|
|
3948
3952
|
const realUsage = ctx.getContextUsage?.();
|
|
3949
|
-
const
|
|
3950
|
-
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount });
|
|
3953
|
+
const sessionTokens = realUsage?.tokens && realUsage.tokens > 0 ? realUsage.tokens : defaultCountTokens(coreMessages.map((m) => m.text ?? "").join("\n"));
|
|
3951
3954
|
const systemPromptText = getSystemPromptText(ctx);
|
|
3952
|
-
const
|
|
3955
|
+
const systemPromptTokens = systemPromptText ? defaultCountTokens(systemPromptText) : 0;
|
|
3956
|
+
const coveredIds = collectCoveredMessageIds(state);
|
|
3957
|
+
const sentTokens = estimateTokens(coreMessages, coveredIds) + systemPromptTokens;
|
|
3958
|
+
const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: sentTokens });
|
|
3959
|
+
const versionStr = "0.1.7" ? `billion-context-omp@${"0.1.7"}` : void 0;
|
|
3953
3960
|
return buildStatusPanel({
|
|
3954
3961
|
version: versionStr,
|
|
3955
|
-
tokenCount,
|
|
3956
|
-
systemPromptTokens
|
|
3962
|
+
tokenCount: sessionTokens,
|
|
3963
|
+
systemPromptTokens,
|
|
3957
3964
|
state: turn.state,
|
|
3958
3965
|
nudge: turn.nudge,
|
|
3959
|
-
modelContextLimit: config.modelContextLimit
|
|
3966
|
+
modelContextLimit: config.modelContextLimit,
|
|
3967
|
+
unprunedTokens: coreMessages.reduce((sum, m) => sum + defaultCountTokens(m.text ?? ""), 0)
|
|
3960
3968
|
});
|
|
3961
3969
|
}
|
|
3962
3970
|
|
|
@@ -4388,7 +4396,7 @@ async function checkForUpdate(autoUpdate, notify) {
|
|
|
4388
4396
|
const data = await res.json();
|
|
4389
4397
|
const latest = data.version;
|
|
4390
4398
|
if (!latest) return;
|
|
4391
|
-
const current = runtimeVersion ?? "0.1.
|
|
4399
|
+
const current = runtimeVersion ?? "0.1.7";
|
|
4392
4400
|
const hasUpdate = isNewer(latest, current);
|
|
4393
4401
|
debug.event("update-check", {
|
|
4394
4402
|
current,
|
|
@@ -4676,7 +4684,7 @@ function wireCompactionDisable(pi, runtime) {
|
|
|
4676
4684
|
function wireSessionLifecycle(pi, runtime) {
|
|
4677
4685
|
pi.on("session_start", async (_event, ctx) => {
|
|
4678
4686
|
const sid = ctx.sessionManager.getSessionId();
|
|
4679
|
-
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.
|
|
4687
|
+
logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.1.7" : null });
|
|
4680
4688
|
try {
|
|
4681
4689
|
const user = await loadUserConfig(ctx.cwd);
|
|
4682
4690
|
runtime.setAdapter(applyUserConfig(runtime.adapter, user));
|
|
@@ -4717,18 +4725,17 @@ function wireContextTransform(pi, runtime) {
|
|
|
4717
4725
|
const { state, coreMessages, originalById, streamLen } = runtime.foldStream(ctx, input);
|
|
4718
4726
|
const config = runtime.configFor(ctx);
|
|
4719
4727
|
const coveredIds = collectCoveredMessageIds(state);
|
|
4720
|
-
const
|
|
4721
|
-
const
|
|
4722
|
-
const
|
|
4728
|
+
const systemPromptTokens = estimateTextTokens2(getSystemPromptText(ctx) ?? "");
|
|
4729
|
+
const sentTokens = estimateTokens(coreMessages, coveredIds) + systemPromptTokens;
|
|
4730
|
+
const sessionTokens = ctx.getContextUsage?.()?.tokens ?? null;
|
|
4731
|
+
const tokenCount = sentTokens;
|
|
4723
4732
|
debug.event("context-in", {
|
|
4724
4733
|
sid,
|
|
4725
4734
|
eventMsgs: event.messages?.length ?? 0,
|
|
4726
4735
|
streamLen,
|
|
4727
4736
|
coreMsgs: coreMessages.length,
|
|
4728
4737
|
tokenCount,
|
|
4729
|
-
|
|
4730
|
-
realTokens: realUsage?.tokens ?? null,
|
|
4731
|
-
realPercent: realUsage?.percent ?? null,
|
|
4738
|
+
sessionTokens,
|
|
4732
4739
|
limit: config.modelContextLimit,
|
|
4733
4740
|
blocksBefore: state.blocks.length,
|
|
4734
4741
|
activeBefore: state.blocks.filter((b) => b.active).length
|
|
@@ -4740,7 +4747,8 @@ function wireContextTransform(pi, runtime) {
|
|
|
4740
4747
|
inMsgs: coreMessages.length,
|
|
4741
4748
|
outMsgs: turn.messages.length,
|
|
4742
4749
|
tokens: tokenCount,
|
|
4743
|
-
|
|
4750
|
+
sessionTokens,
|
|
4751
|
+
pct: config.modelContextLimit > 0 ? Math.round(tokenCount / config.modelContextLimit * 100) : null,
|
|
4744
4752
|
limit: config.modelContextLimit,
|
|
4745
4753
|
nudge: turn.nudge?.shouldInject ? turn.nudge.breakdown?.emergencyOverride === 1 ? "emergency" : "active" : "idle",
|
|
4746
4754
|
nudgeReason: turn.nudge?.reason ?? null,
|