惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
爱范儿
爱范儿
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
博客园 - 聂微东
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
罗磊的独立博客
Jina AI
Jina AI

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(control-ui): keep context usage fresh (#71297) · open...
BunsDev · 2026-04-25 · via Recent Commits to openclaw:main

@@ -1,6 +1,16 @@

11

import { html, nothing } from "lit";

2+

import { icons } from "../icons.ts";

23

import type { GatewaySessionRow } from "../types.ts";

345+

const CONTEXT_NOTICE_RATIO = 0.85;

6+

const CONTEXT_COMPACT_RATIO = 0.9;

7+8+

export type ContextNoticeOptions = {

9+

compactBusy?: boolean;

10+

compactDisabled?: boolean;

11+

onCompact?: () => void | Promise<void>;

12+

};

13+414

/** Parse a 6-digit CSS hex color string to [r, g, b] integer components. */

515

function parseHexRgb(hex: string): [number, number, number] | null {

616

const h = hex.trim().replace(/^#/, "");

@@ -49,6 +59,7 @@ export function getContextNoticeViewModel(

4959

detail: string;

5060

color: string;

5161

bg: string;

62+

compactRecommended: boolean;

5263

} | null {

5364

if (session?.totalTokensFresh === false) {

5465

return null;

@@ -59,7 +70,7 @@ export function getContextNoticeViewModel(

5970

return null;

6071

}

6172

const ratio = used / limit;

62-

if (ratio < 0.85) {

73+

if (ratio < CONTEXT_NOTICE_RATIO) {

6374

return null;

6475

}

6576

const pct = Math.min(Math.round(ratio * 100), 100);

@@ -79,17 +90,21 @@ export function getContextNoticeViewModel(

7990

detail: `${formatTokensCompact(used)} / ${formatTokensCompact(limit)}`,

8091

color,

8192

bg,

93+

compactRecommended: ratio >= CONTEXT_COMPACT_RATIO,

8294

};

8395

}

84968597

export function renderContextNotice(

8698

session: GatewaySessionRow | undefined,

8799

defaultContextTokens: number | null,

100+

options: ContextNoticeOptions = {},

88101

) {

89102

const model = getContextNoticeViewModel(session, defaultContextTokens);

90103

if (!model) {

91104

return nothing;

92105

}

106+

const canRenderCompact = model.compactRecommended && options.onCompact;

107+

const compactDisabled = options.compactDisabled === true || options.compactBusy === true;

93108

return html`

94109

<div

95110

class="context-notice"

@@ -113,6 +128,30 @@ export function renderContextNotice(

113128

</svg>

114129

<span>${model.pct}% context used</span>

115130

<span class="context-notice__detail">${model.detail}</span>

131+

${canRenderCompact

132+

? html`

133+

<button

134+

class="context-notice__action ${options.compactBusy

135+

? "context-notice__action--busy"

136+

: ""}"

137+

type="button"

138+

title="Compact session context"

139+

aria-label="Compact recommended session context"

140+

?disabled=${compactDisabled}

141+

@click=${(event: Event) => {

142+

event.preventDefault();

143+

event.stopPropagation();

144+

if (compactDisabled) {

145+

return;

146+

}

147+

void options.onCompact?.();

148+

}}

149+

>

150+

${options.compactBusy ? icons.loader : icons.minimize}

151+

<span>${options.compactBusy ? "Compacting" : "Compact"}</span>

152+

</button>

153+

`

154+

: nothing}

116155

</div>

117156

`;

118157

}