OpenClaw飞书statusline自定义:模型名| ██░░░░░░░░ 18%
标签:#OpenClaw #飞书 #statusline #上下文使用量 #自定义
OpenClaw(5.27) feishu card格式页脚statusline默认:Agent | Model | Provider
但statusline不能修改,不能自定义,对有上下文使用焦虑的人,都希望增加上下文使用量显示。本文就是介绍了一种自定义statusline的方法。
OpenClaw(5.27) feishu card格式页脚statusline自定义:model | 上下文使用滚动条 百分比
createFeishuReplyDispatcher({cfg, agentId, …}) ← 创建回复派发器
│ ├─ createReplyPrefixContext({cfg, agentId}) ← 从配置提取 agent 信息
│ └─ prefixContext.prefixContext ← {model, provider, …}
│ └─ resolveCardNote(agentId, identity, prefixCtx) ← 生成页脚文本
loadSessionStore(storePath) ← 读取整个 session store resolveSessionStoreEntry({store, sessionKey}) ← 获取指定 session entry
└─ entry.existing.totalTokens / contextTokens ← token 使用数据
**位置**:`monitor.account-*.js` → `function resolveCardNote(agentId, identity, prefixCtx)`
默认实现很简单:拼 “Agent: X | Model: Y | Provider: Z”
改造后:从 `prefixCtx._storePath` / `prefixCtx._sessionKey` 读取 store 路径,用 `loadSessionStore` + `resolveSessionStoreEntry` 拿到 token 数据,计算百分比和 ASCII 进度条。
const storePath = prefixCtx._storePath;
const sessionKey = prefixCtx._sessionKey;
if (storePath && sessionKey) {
const entry = resolveSessionStoreEntry({ store: loadSessionStore(storePath), sessionKey })?.existing;
// 读取 totalTokens / contextTokens → 百分比 → 进度条
② createFeishuReplyDispatcher 参数解构
默认只解构了 `{cfg, agentId, chatId, replyToMessageId, …identity}`
改造后:加上 `storePath, sessionKey` 两个参数
const { cfg, agentId, …, identity, storePath, sessionKey } = params;
③ store 信息注入 prefixContext
**位置**: `createReplyPrefixContext(…)` 调用之后
const prefixContext = createReplyPrefixContext({cfg, agentId});
if (storePath && sessionKey) {
prefixContext.prefixContext._storePath = storePath;
prefixContext.prefixContext._sessionKey = sessionKey;
这是把 data flow 串起来的关键——`resolveCardNote` 只能拿到 `prefixCtx`,所以通过给它挂私有属性来传参。
**位置**: `broadcast active dispatch` 日志附近 当前 scope 有 `agentStorePath` 和 `agentSessionKey`,加到传参里:
createFeishuReplyDispatcher({ …, storePath: agentStorePath, sessionKey: agentSessionKey });
**位置**: `dispatching to agent` 日志附近 当前 scope 有 `storePath` 和 `route.sessionKey`:
createFeishuReplyDispatcher({ …, storePath, sessionKey: route.sessionKey });
2. **精确字符串匹配优先** → 减少误匹配风险
3. **失败时 dump 上下文** → 方便手工修复
5. **打完后打印 diff size** → 快速验证修改是否生效
|`~/.openclaw/workspace/patches/patch-feishu-card-footer.mjs` | 补丁脚本,Node.js 直接运行 |
|`~/.openclaw/workspace/patches/monitor.account-*.js.backup` | 打补丁前自动备份 |