JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
feat:新增/statusline命令和文档
openJiuwen-bot8cab68bf8b63
diff --git a/docs/en/SlashCommands.md b/docs/en/SlashCommands.mdindex 88020fa446..a2c8a4589e 100644--- a/docs/en/SlashCommands.md+++ b/docs/en/SlashCommands.md@@ -25,6 +25,7 @@ Executed locally in the terminal UI, not through Gateway control pipeline.| `/teamskills` | TeamSkills Hub publish/delete (`publish`/`delete`) || `/export` | Export current conversation to file or clipboard (see below) || `/status` | Show jiuwenclaw status overview, usage, config (see below) |+| `/statusline` | Configure the TUI footer status bar with a custom command (see below) || `/permissions` | Manage tool permissions (`allow`/`ask`/`deny`) |> Note: `/mode` controlled switching logic is primarily on Gateway side, see "`/mode` and `/switch`" below.@@ -444,6 +445,126 @@ If StatusView is unavailable, the command falls back to inline key-value display- `/status usage` — Show token usage- `/status config` — Open config editor+### `/statusline` (TUI Footer Status Bar)++Configure the TUI footer status bar with a custom shell command that dynamically displays session info (mode, model, cwd, etc.), modeled after Claude Code's `/statusline` implementation.++#### Subcommands++| Command | Description |+|---|---|+| `/statusline` or `/statusline get` | View current status line configuration |+| `/statusline set <shell-command>` | Set the status line command (its output will appear in the TUI footer) |+| `/statusline clear` | Remove the status line configuration (footer bar will hide) |+| `/statusline help` | Show the JSON input fields reference |++#### Concepts++- **StatusLine**: A one-line text area at the bottom of the TUI that displays user-defined dynamic information. When a custom statusline is configured, the built-in status line is automatically hidden to avoid redundant information.+- **Shell command**: The configured shell command is automatically executed every 2 seconds; its stdout output is rendered as the status bar text.+- **JSON input**: Each execution receives current session info as JSON, which can be parsed with `jq` or other tools. On POSIX (Linux/macOS), JSON is passed via stdin pipe; on Windows, due to MSYS2 pipe inheritance limitations, the system automatically writes JSON to a temp file and replaces `$(cat)` in the command with `$(cat "filepath")` — the user doesn't need to modify their command format.+- **Prerequisites**: Requires `jq` (https://stedolan.github.io/jq/) for JSON parsing; Windows users also need to add Git Bash's `usr\bin` directory to the system PATH (e.g., `E:\Git\usr\bin`).++#### JSON Input Fields++The command receives the following JSON data on each execution:++| Field | Description |+|---|---|+| `session_id` | Current session ID |+| `session_name` | Session title (set via `/rename`) |+| `cwd` | Current working directory |+| `mode` | Current mode (`agent.plan` / `agent.fast` / `code.plan` / `code.normal` / `team`) |+| `model` | Current model name |+| `provider` | Model provider |+| `version` | jiuwenclaw version |+| `connection` | Connection status (`idle` / `connecting` / `connected` / `reconnecting` / `auth_failed`) |+| `theme` | Current theme name |+| `accent_color` | Current accent color name |+| `transcript_mode` | Transcript display mode (`compact` / `detailed`) |+| `transcript_fold_mode` | Fold mode (`none` / `tools` / `thinking` / `all`) |+| `is_processing` | Whether agent is working (`true` / `false`) |+| `is_paused` | Whether paused (`true` / `false`) |+| `is_interrupted` | Whether interrupted (`true` / `false`) |+| `cancellable_work` | Whether there is running work (`true` / `false`) |+| `streaming_state` | Streaming state (`idle` / `streaming` / `tool_call` / `tool_result`) |+| `last_error` | Last error message or `null` |+| `evolution_status` | Evolution status (`idle` / `running`) |+| `active_subtask_count` | Number of active subtasks |+| `todo_count` | Number of todo items |+| `usage.total_input_tokens` | Total input tokens for session |+| `usage.total_output_tokens` | Total output tokens for session |+| `usage.total_tokens` | Total tokens for session |++#### Command Writing Template++Use the following template to write commands. `input=$(cat)` reads JSON into a variable, then `echo "$input" | jq -r .field` extracts each field. `// "default"` is jq's fallback syntax — when a field is null or empty, the default value is used.++**General formula**:++```+/statusline set 'input=$(cat); field1=$(echo "$input" | jq -r '.field1 // "default"'); field2=$(echo "$input" | jq -r '.field2 // "default"'); echo "format string"'+```++**Recommended universal command** (shows mode, model, tokens, connection):++```+/statusline set 'input=$(cat); mode=$(echo "$input" | jq -r '.mode // "?"'); model=$(echo "$input" | jq -r '.model // "?"'); tokens=$(echo "$input" | jq -r '.usage.total_tokens // 0'); conn=$(echo "$input" | jq -r '.connection // "?"'); echo "$mode | $model | tokens:$tokens | $conn"'+```++**Field extraction quick reference**:++| Field to display | jq syntax |+|---|---|+| Session name | `jq -r '.session_name // ""'` |+| Working directory | `jq -r '.cwd // "?"'` |+| Mode | `jq -r '.mode // "?"'` |+| Model name | `jq -r '.model // "?"'` |+| Provider | `jq -r '.provider // "?"'` |+| Version | `jq -r '.version // "?"'` |+| Connection | `jq -r '.connection // "?"'` |+| Is processing | `jq -r '.is_processing // false'` |+| Is paused | `jq -r '.is_paused // false'` |+| Streaming state | `jq -r '.streaming_state // "idle"'` |+| Last error | `jq -r '.last_error // ""'` |+| Evolution status | `jq -r '.evolution_status // "idle"'` |+| Subtask count | `jq -r '.active_subtask_count // 0'` |+| Todo count | `jq -r '.todo_count // 0'` |+| Total input tokens | `jq -r '.usage.total_input_tokens // 0'` |+| Total output tokens | `jq -r '.usage.total_output_tokens // 0'` |+| Total tokens | `jq -r '.usage.total_tokens // 0'` |++#### More Examples++- `/statusline` — View current configuration+- `/statusline set 'input=$(cat); model=$(echo "$input" | jq -r .model); echo "$model"'` — Show model name only+- `/statusline set 'input=$(cat); proc=$(echo "$input" | jq -r .is_processing); model=$(echo "$input" | jq -r .model); echo "$proc | $model"'` — Show processing state and model+- `/statusline set 'input=$(cat); err=$(echo "$input" | jq -r .last_error); if [ "$err" != "null" ] && [ "$err" != "" ]; then echo "error: $err"; else echo "ok"; fi'` — Show error when present, otherwise "ok"+- `/statusline clear` — Remove status line configuration+- `/statusline help` — View JSON input fields reference++#### Behavior Details++- **Poll frequency**: The configured command runs every 2 seconds automatically.+- **Timeout protection**: Individual executions timeout after 3 seconds; no impact on subsequent polls.+- **Output limit**: Command output over 10KB is truncated; display width auto-fits the TUI terminal width.+- **Failure silence**: Command execution failures don't show errors; previous successful output is kept or the bar hides.+- **Persistence**: Configuration is saved in `~/.jiuwenclaw-tui/config.json` under the `statusLine` field; restored on TUI restart.+- **Alias**: `/sl`+- **Windows adaptation**: The system automatically replaces `$(cat)` with reading from a temp file; the user's command format remains unchanged. Git Bash's `usr\bin` must be in the system PATH.++#### Config File Structure++```json+{+ "statusLine": {+ "type": "command",+ "command": "input=$(cat); mode=$(echo \"$input\" | jq -r '.mode // \"?\"'); model=$(echo \"$input\" | jq -r '.model // \"?\"'); tokens=$(echo \"$input\" | jq -r '.usage.total_tokens // 0'); echo \"$mode | $model | tokens:$tokens\"",+ "padding": 0+ }+}+```+---diff --git "a/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md" "b/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md"index 65319f40b8..c244ab4f28 100644--- "a/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md"+++ "b/docs/zh/Slash\345\221\275\344\273\244\350\241\250.md"@@ -25,6 +25,7 @@| `/teamskills` | TeamSkills 管理(`init/validate/pack/info/search/list/install/uninstall/config/publish/delete`) || `/export` | 导出当前会话到文件或剪贴板(见下文) || `/status` | 查看 jiuwenclaw 运行状态概览、用量统计、配置编辑(见下文) |+| `/statusline` | 配置 TUI 底部状态栏的自定义命令(见下文) || `/permissions` | 管理工具权限(`allow`/`ask`/`deny`) |> 说明:`/mode` 的受控切换逻辑以 Gateway 侧行为为主,详见下文「`/mode` 与 `/switch`」。@@ -455,6 +456,126 @@- `/status usage` — 显示 token 用量- `/status config` — 打开配置编辑器+### `/statusline`(TUI 状态栏配置)++配置 TUI 底部状态栏,通过自定义 shell 命令动态显示会话信息(模式、模型、工作目录等),仿照 Claude Code 的 `/statusline` 实现。++#### 子命令++| 命令 | 说明 |+|---|---|+| `/statusline` 或 `/statusline get` | 查看当前状态栏配置 |+| `/statusline set <shell-command>` | 设置状态栏命令(命令输出将显示在 TUI 底部) |+| `/statusline clear` | 清除状态栏配置(底部栏将不再显示) |+| `/statusline help` | 显示状态栏 JSON 输入字段参考 |++#### 概念说明++- **状态栏(StatusLine)**:TUI 底部的一行文字区域,实时显示用户自定义的动态信息。配置了自定义状态栏后,内置状态栏会自动隐藏,避免信息冗余。+- **Shell 命令**:用户配置的 shell 命令每 2 秒自动执行一次,其 stdout 输出渲染为状态栏文字。+- **JSON 输入**:每次执行时,系统将当前会话信息以 JSON 格式传入命令,用户可在命令中用 `jq` 等工具解析。POSIX(Linux/macOS)通过 stdin 管道传入;Windows 上因 MSYS2 管道继承限制,系统自动将 JSON 写入临时文件,并将命令中的 `$(cat)` 替换为 `$(cat "文件路径")`,用户无需修改命令格式。+- **前置依赖**:需要 `jq`(https://stedolan.github.io/jq/)用于解析 JSON;Windows 用户还需将 Git Bash 的 `usr\bin` 目录加入系统 PATH(如 `E:\Git\usr\bin`)。++#### JSON 输入字段++命令执行时接收如下 JSON 数据:++| 字段 | 说明 |+|---|---|+| `session_id` | 当前会话 ID |+| `session_name` | 会话标题(通过 `/rename` 设置) |+| `cwd` | 当前工作目录 |+| `mode` | 当前模式(`agent.plan` / `agent.fast` / `code.plan` / `code.normal` / `team`) |+| `model` | 当前模型名称 |+| `provider` | 模型提供商 |+| `version` | jiuwenclaw 版本号 |+| `connection` | 连接状态(`idle` / `connecting` / `connected` / `reconnecting` / `auth_failed`) |+| `theme` | 当前主题名 |+| `accent_color` | 当前强调色名 |+| `transcript_mode` | 对话显示模式(`compact` / `detailed`) |+| `transcript_fold_mode` | 折叠模式(`none` / `tools` / `thinking` / `all`) |+| `is_processing` | 是否正在处理(`true` / `false`) |+| `is_paused` | 是否暂停(`true` / `false`) |+| `is_interrupted` | 是否中断(`true` / `false`) |+| `cancellable_work` | 是否有可取消的工作(`true` / `false`) |+| `streaming_state` | 流式传输状态(`idle` / `streaming` / `tool_call` / `tool_result`) |+| `last_error` | 最近错误信息或 `null` |+| `evolution_status` | 演化状态(`idle` / `running`) |+| `active_subtask_count` | 活跃子任务数 |+| `todo_count` | 待办事项数 |+| `usage.total_input_tokens` | 会话总输入 token |+| `usage.total_output_tokens` | 会话总输出 token |+| `usage.total_tokens` | 会话总 token |++#### 命令编写模板++推荐使用以下模板编写命令。`input=$(cat)` 将 JSON 读入变量,后续用 `echo "$input" | jq -r .字段` 提取各字段。`// "默认值"` 是 jq 的备选语法,字段为空时使用默认值。++**通用公式**:++```+/statusline set 'input=$(cat); 字段1=$(echo "$input" | jq -r '.字段1 // "默认值"'); 字段2=$(echo "$input" | jq -r '.字段2 // "默认值"'); echo "格式化字符串"'+```++**推荐通用命令**(显示模式、模型、token、连接状态):++```+/statusline set 'input=$(cat); mode=$(echo "$input" | jq -r '.mode // "?"'); model=$(echo "$input" | jq -r '.model // "?"'); tokens=$(echo "$input" | jq -r '.usage.total_tokens // 0'); conn=$(echo "$input" | jq -r '.connection // "?"'); echo "$mode | $model | tokens:$tokens | $conn"'+```++**各字段提取速查**:++| 要显示的字段 | jq 写法 |+|---|---|+| 会话名 | `jq -r '.session_name // ""'` |+| 工作目录 | `jq -r '.cwd // "?"'` |+| 模式 | `jq -r '.mode // "?"'` |+| 模型名 | `jq -r '.model // "?"'` |+| 提供商 | `jq -r '.provider // "?"'` |+| 版本号 | `jq -r '.version // "?"'` |+| 连接状态 | `jq -r '.connection // "?"'` |+| 是否在处理 | `jq -r '.is_processing // false'` |+| 是否暂停 | `jq -r '.is_paused // false'` |+| 流式状态 | `jq -r '.streaming_state // "idle"'` |+| 最近错误 | `jq -r '.last_error // ""'` |+| 演化状态 | `jq -r '.evolution_status // "idle"'` |+| 子任务数 | `jq -r '.active_subtask_count // 0'` |+| 待办数 | `jq -r '.todo_count // 0'` |+| 总输入 token | `jq -r '.usage.total_input_tokens // 0'` |+| 总输出 token | `jq -r '.usage.total_output_tokens // 0'` |+| 总 token | `jq -r '.usage.total_tokens // 0'` |++#### 更多示例++- `/statusline` — 查看当前配置+- `/statusline set 'input=$(cat); model=$(echo "$input" | jq -r .model); echo "$model"'` — 只显示模型名+- `/statusline set 'input=$(cat); proc=$(echo "$input" | jq -r .is_processing); model=$(echo "$input" | jq -r .model); echo "$proc | $model"'` — 显示是否在处理和模型名+- `/statusline set 'input=$(cat); err=$(echo "$input" | jq -r .last_error); if [ "$err" != "null" ] && [ "$err" != "" ]; then echo "error: $err"; else echo "ok"; fi'` — 有错误时显示错误信息,无错误时显示 ok+- `/statusline clear` — 清除状态栏配置+- `/statusline help` — 查看 JSON 输入字段参考++#### 行为细节++- **轮询频率**:每 2 秒自动执行一次配置的命令。+- **超时保护**:单次执行超时 3 秒后自动终止,不影响后续轮询。+- **输出限制**:命令输出超过 10KB 时截断;显示宽度自动适配 TUI 终端宽度。+- **故障静默**:命令执行失败时不显示错误,保持上一次成功输出或隐藏状态栏。+- **持久化**:配置保存在 `~/.jiuwenclaw-tui/config.json` 的 `statusLine` 字段,重启 TUI 后自动恢复。+- **别名**:`/sl`+- **Windows 适配**:系统自动将 `$(cat)` 替换为读取临时文件,用户命令格式不变;需确保 Git Bash 的 `usr\bin` 在系统 PATH 中。++#### 配置文件结构++```json+{+ "statusLine": {+ "type": "command",+ "command": "input=$(cat); mode=$(echo \"$input\" | jq -r '.mode // \"?\"'); model=$(echo \"$input\" | jq -r '.model // \"?\"'); tokens=$(echo \"$input\" | jq -r '.usage.total_tokens // 0'); echo \"$mode | $model | tokens:$tokens\"",+ "padding": 0+ }+}+```+---diff --git a/jiuwenclaw/channels/tui/frontend/src/app-state.ts b/jiuwenclaw/channels/tui/frontend/src/app-state.tsindex c80b098bcc..e7ef335d2d 100644--- a/jiuwenclaw/channels/tui/frontend/src/app-state.ts+++ b/jiuwenclaw/channels/tui/frontend/src/app-state.ts@@ -46,7 +46,6 @@ import {type ThemeName,} from "./ui/theme.js";import { type ConnectionStatus, WsClient } from "./core/ws-client.js";-import { loadTuiConfig } from "./core/tui-config-store.js";import {getTrustedDirs,validateDirPath,@@ -55,6 +54,11 @@ import {removeTrustedDir,clearTrustedDirs,} from "./core/tui-trusted-dirs-store.js";+import { loadTuiConfig, type StatusLineSetting } from "./core/tui-config-store.js";+import { execFile } from "node:child_process";+import { writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join, sep } from "node:path";export interface ModelUsageEntry {model: string;@@ -101,6 +105,7 @@ export interface AppSnapshot {contextCompression: ContextCompressionStats | null;modelInfo: { provider: string; model: string; version: string };sessionTitle: string;+ statusLineText: string | null;}export class CliPiAppState {@@ -152,6 +157,8 @@ export class CliPiAppState {private historyPageDoneResolvers = new Map<number, () => void>();private unlistenStatus: (() => void) | null = null;private unlistenFrames: (() => void) | null = null;+ private statusLineText: string | null = null;+ private statusLineTimer: ReturnType<typeof setInterval> | null = null;private usageByModel = new Map<string, ModelUsageEntry>();private modelInfo: { provider: string; model: string; version: string } = {provider: "",@@ -296,6 +303,7 @@ export class CliPiAppState {});this.wsClient.connect();+ this.startStatusLinePoll();}stop(): void {@@ -315,6 +323,7 @@ export class CliPiAppState {this.unlistenStatus = null;this.unlistenFrames?.();this.unlistenFrames = null;+ this.stopStatusLinePoll();this.wsClient.disconnect();}@@ -410,6 +419,7 @@ export class CliPiAppState {contextCompression: this.contextCompression ? { ...this.contextCompression } : null,modelInfo: this.modelInfo,sessionTitle: this.sessionTitle,+ statusLineText: this.statusLineText,};}@@ -487,6 +497,7 @@ export class CliPiAppState {setInput: this._setInputRef ?? undefined,enterStatusView: undefined,getUsageSummary: () => this.getUsageSummary(),+ restartStatusLine: () => this.restartStatusLinePoll(),};}@@ -1337,6 +1348,115 @@ readonly request = async <T = Record<string, unknown>>(this.scheduleToolTimeoutCheck();}+ private startStatusLinePoll(): void {+ this.executeStatusLineCommand();+ this.statusLineTimer = setInterval(() => {+ this.executeStatusLineCommand();+ }, 2_000);+ }++ private stopStatusLinePoll(): void {+ if (this.statusLineTimer) {+ clearInterval(this.statusLineTimer);+ this.statusLineTimer = null;+ }+ }++ restartStatusLinePoll(): void {+ this.stopStatusLinePoll();+ this.statusLineText = null;+ this.emitChange();+ this.startStatusLinePoll();+ }+++ private buildStatusLineJsonInput(): Record<string, unknown> {+ const snapshot = this.getSnapshot();+ const usage = this.getUsageSummary();+ const trustedDirs = getTrustedDirs();+ const cwd = trustedDirs[0] || process.cwd();+ return {+ session_id: snapshot.sessionId,+ session_name: snapshot.sessionTitle,+ cwd,+ mode: snapshot.mode,+ model: snapshot.modelInfo.model,+ provider: snapshot.modelInfo.provider,+ version: snapshot.modelInfo.version,+ connection: snapshot.connectionStatus,+ theme: snapshot.themeName,+ accent_color: snapshot.accentColor,+ transcript_mode: snapshot.transcriptMode,+ transcript_fold_mode: snapshot.transcriptFoldMode,+ is_processing: snapshot.isProcessing,+ is_paused: snapshot.isPaused,+ is_interrupted: snapshot.isInterrupted,+ cancellable_work: snapshot.cancellableWork,+ streaming_state: snapshot.streamingState,+ last_error: snapshot.lastError,+ evolution_status: snapshot.evolutionStatus,+ active_subtask_count: snapshot.activeSubtasks.length,+ todo_count: snapshot.todos.length,+ usage: {+ total_input_tokens: usage.total_input_tokens,+ total_output_tokens: usage.total_output_tokens,+ total_tokens: usage.total_tokens,+ },+ };+ }++ private executeStatusLineCommand(): void {+ const config = loadTuiConfig();+ const sl = config.statusLine;+ if (!sl || sl.type !== "command" || !sl.command) {+ if (this.statusLineText !== null) {+ this.statusLineText = null;+ this.emitChange();+ }+ return;+ }+ const jsonInput = JSON.stringify(this.buildStatusLineJsonInput());+ const cmd = sl.command;+ const isWindows = process.platform === "win32";++ try {+ if (isWindows) {+ // On Windows, sh.exe from MSYS2/Git Bash can't read stdin in $(cat)+ // inside sh -c. Solution: write JSON to a temp file and:+ // 1. Replace $(cat) (no args) with $(cat "filepath") for inline commands+ // 2. Export JIUWENCLAW_SL_FILE so script files can use it too:+ // input=$(cat "$JIUWENCLAW_SL_FILE")+ const tmpFile = join(tmpdir(), "jiuwenclaw-sl.json");+ writeFileSync(tmpFile, jsonInput, "utf8");+ const msysPath = tmpFile.split(sep).join("/").replace(/^([A-Za-z]):/, (_, d) => "/" + d.toLowerCase());+ const patchedCmd = cmd.replace(/\$\(cat\)/g, `$(cat "${msysPath}")`);+ const fullCmd = `export JIUWENCLAW_SL_FILE="${msysPath}"; ${patchedCmd}`;++ const child = execFile("sh", ["-c", fullCmd], { timeout: 3_000, maxBuffer: 10_240, cwd: process.cwd() }, (err, stdout) => {+ if (err) return;+ const text = stdout.trim();+ if (text !== this.statusLineText) {+ this.statusLineText = text || null;+ this.emitChange();+ }+ });+ } else {+ // On POSIX, stdin piping works correctly in sh -c.+ const child = execFile("sh", ["-c", cmd], { timeout: 3_000, maxBuffer: 10_240 }, (err, stdout) => {+ if (err) return;+ const text = stdout.trim();+ if (text !== this.statusLineText) {+ this.statusLineText = text || null;+ this.emitChange();+ }+ });+ child.stdin?.end(jsonInput);+ }+ } catch {+ // Silently ignore — sh may not be in PATH on Windows+ }+ }+private emitChange(): void {for (const listener of this.listeners) {listener();diff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/statusline.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/statusline.tsnew file mode 100644index 0000000000..17c34f0b81--- /dev/null+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/builtins/statusline.ts@@ -0,0 +1,139 @@+import { makeItem } from "../helpers.js";+import { loadTuiConfig, saveTuiConfig, type StatusLineSetting } from "../../tui-config-store.js";+import { CommandKind, type CommandContext, type SlashCommand } from "../types.js";++function getStatusLineConfig(): StatusLineSetting | undefined {+ return loadTuiConfig().statusLine;+}++function showCurrentConfig(ctx: CommandContext): void {+ const sl = getStatusLineConfig();+ if (!sl || sl.type !== "command" || !sl.command) {+ ctx.addItem(makeItem(ctx.sessionId, "info", "StatusLine — not configured", "m"));+ return;+ }+ const lines = [+ `command: '${sl.command}'`,+ `padding: ${sl.padding ?? 0}`,+ ];+ ctx.addItem(makeItem(ctx.sessionId, "info", `StatusLine\n ${lines.join("\n ")}`, "m"));+}++function setConfig(ctx: CommandContext, args: string): void {+ const command = args.trim().replace(/^['"]|['"]$/g, "");+ if (!command) {+ ctx.addItem(makeItem(ctx.sessionId, "error", "usage: /statusline set <command>", "m"));+ return;+ }+ saveTuiConfig({ statusLine: { type: "command", command } });+ ctx.restartStatusLine?.();+ ctx.addItem(+ makeItem(ctx.sessionId, "info", `StatusLine — Updated\n command: '${command}'\n padding: 0`, "m"),+ );+}++function clearConfig(ctx: CommandContext): void {+ saveTuiConfig({ statusLine: undefined });+ ctx.restartStatusLine?.();+ ctx.addItem(makeItem(ctx.sessionId, "info", "StatusLine — cleared", "m"));+}++function showJsonInput(ctx: CommandContext): void {+ const fields = [+ "session_id — current session ID",+ "session_name — session title / name",+ "cwd — current working directory",+ "mode — chat mode (agent.plan, code.normal, team, etc.)",+ "model — AI model name",+ "provider — model provider",+ "version — TUI version",+ "connection — connection status (connected, connecting, etc.)",+ "theme — current theme name",+ "accent_color — current accent color",+ "transcript_mode — transcript display mode (compact/detailed)",+ "transcript_fold_mode — fold mode (none/tools/thinking/all)",+ "is_processing — whether a request is in progress (true/false)",+ "is_paused — whether session is paused (true/false)",+ "is_interrupted — whether session was interrupted (true/false)",+ "cancellable_work — whether cancellable work exists (true/false)",+ "streaming_state — streaming state (idle, streaming, etc.)",+ "last_error — last error message (empty string if none)",+ "evolution_status — evolution status (idle/running)",+ "active_subtask_count — number of active subtasks",+ "todo_count — number of todo items",+ "usage.total_input_tokens — total input tokens",+ "usage.total_output_tokens — total output tokens",+ "usage.total_tokens — total tokens (input + output)",+ ];+ ctx.addItem(+ makeItem(ctx.sessionId, "info", `StatusLine — JSON input fields\n${fields.map((f) => ` ${f}`).join("\n")}`, "m"),+ );+}++export function createStatusLineCommand(): SlashCommand {+ return {+ name: "statusline",+ description: "Configure custom status line footer",+ usage: "/statusline <set|clear|help|json>",+ example: "/statusline set 'echo $mode | $model'",+ kind: CommandKind.BUILT_IN,+ takesArgs: true,+ subCommands: [+ {+ name: "set",+ description: "Set statusline command",+ usage: "/statusline set <command>",+ example: "/statusline set 'echo mode:$mode model:$model'",+ kind: CommandKind.BUILT_IN,+ takesArgs: true,+ action: (ctx, args) => setConfig(ctx, args),+ },+ {+ name: "clear",+ description: "Clear statusline configuration",+ usage: "/statusline clear",+ kind: CommandKind.BUILT_IN,+ takesArgs: false,+ isSafeConcurrent: true,+ action: (ctx) => clearConfig(ctx),+ },+ {+ name: "help",+ description: "Show statusline help and available fields",+ usage: "/statusline help",+ kind: CommandKind.BUILT_IN,+ takesArgs: false,+ isSafeConcurrent: true,+ action: (ctx) => {+ showCurrentConfig(ctx);+ showJsonInput(ctx);+ },+ },+ {+ name: "json",+ description: "Show current JSON input data",+ usage: "/statusline json",+ kind: CommandKind.BUILT_IN,+ takesArgs: false,+ isSafeConcurrent: true,+ action: (ctx) => showJsonInput(ctx),+ },+ ],+ action: (ctx, args) => {+ const sub = args.trim().split(/\s+/)[0];+ if (!sub) {+ showCurrentConfig(ctx);+ return;+ }+ const matched = createStatusLineCommand().subCommands?.find((s) => s.name === sub);+ if (matched) {+ const rest = args.trim().slice(sub.length).trim();+ matched.action(ctx, rest);+ return;+ }+ ctx.addItem(+ makeItem(ctx.sessionId, "error", `Unknown sub-command: ${sub}\nUsage: /statusline <set|clear|help|json>`, "m"),+ );+ },+ };+}\ No newline at end of filediff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/registry.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/registry.tsindex 71b859099c..566aabe2ae 100644--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/registry.ts+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/registry.ts@@ -31,6 +31,7 @@ import { createRenameCommand } from "./builtins/rename.js";import { createRewindCommand } from "./builtins/rewind.js";import { createSessionCommand } from "./builtins/session.js";import { createStatusCommand } from "./builtins/status.js";+import { createStatusLineCommand } from "./builtins/statusline.js";import { createSkillsCommand } from "./builtins/skills.js";import { createTeamSkillsCommand } from "./builtins/teamskills.js";import { createAutoHarnessCommand } from "./builtins/auto-harness.js";@@ -67,6 +68,7 @@ export function createBuiltinCommands(): SlashCommand[] {createSessionCommand(),createSkillsCommand(),createStatusCommand(),+ createStatusLineCommand(),createTeamSkillsCommand(),createAutoHarnessCommand(),createThemeCommand(),diff --git a/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts b/jiuwenclaw/channels/tui/frontend/src/core/commands/types.tsindex 19508c26da..2742876262 100644--- a/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts+++ b/jiuwenclaw/channels/tui/frontend/src/core/commands/types.ts@@ -87,6 +87,7 @@ export interface CommandContext {) => void;enterStatusView?: (tab?: StatusViewTab) => void;openInEditor?: (filePath: string) => void;+ restartStatusLine?: () => void;}export interface SlashCommand {diff --git a/jiuwenclaw/channels/tui/frontend/src/core/tui-config-store.ts b/jiuwenclaw/channels/tui/frontend/src/core/tui-config-store.tsindex 37156123e6..8aeb3d5898 100644--- a/jiuwenclaw/channels/tui/frontend/src/core/tui-config-store.ts+++ b/jiuwenclaw/channels/tui/frontend/src/core/tui-config-store.ts@@ -7,10 +7,17 @@ import type { AccentColorName, ThemeName } from "../ui/theme.js";const CONFIG_DIR = join(homedir(), ".jiuwenclaw-tui");const CONFIG_FILE = join(CONFIG_DIR, "config.json");+export interface StatusLineSetting {+ type: "command";+ command: string;+ padding?: number;+}+export interface TuiConfig {theme?: ThemeName;accentColor?: AccentColorName;trustedDirs?: string[];+ statusLine?: StatusLineSetting;}export function loadTuiConfig(): TuiConfig {diff --git a/jiuwenclaw/channels/tui/frontend/src/ui/screen-layout.ts b/jiuwenclaw/channels/tui/frontend/src/ui/screen-layout.tsindex 99f2ef0830..7d3cf6c1fd 100644--- a/jiuwenclaw/channels/tui/frontend/src/ui/screen-layout.ts+++ b/jiuwenclaw/channels/tui/frontend/src/ui/screen-layout.ts@@ -8,6 +8,7 @@ import { APP_SCREEN_KEY_BINDINGS } from "./keymap.js";import { padToWidth } from "./rendering/text.js";import { palette } from "./theme.js";import { buildTranscriptLines } from "./transcript-renderer.js";+import { loadTuiConfig } from "../core/tui-config-store.js";export interface ScreenLayoutOptions {width: number;@@ -150,6 +151,19 @@ function buildStatusLines(return lines;}+function buildStatusLineBar(snapshot: AppSnapshot, width: number): string[] {+ if (!snapshot.statusLineText) return [];+ const config = loadTuiConfig();+ const sl = config.statusLine;+ const paddingX = sl?.padding ?? 0;+ const paddedWidth = width - paddingX * 2;+ if (paddedWidth <= 0) return [];+ const text = snapshot.statusLineText.length > paddedWidth+ ? snapshot.statusLineText.slice(0, paddedWidth)+ : snapshot.statusLineText;+ return [padToWidth(palette.text.dim(text), paddedWidth)];+}+function buildShortcutLines(width: number): string[] {const lines = [padToWidth(palette.text.secondary("Shortcuts"), width),@@ -171,6 +185,11 @@ export function buildAppScreenLines(snapshot: AppSnapshot, options: ScreenLayoutoptions.runningElapsedMs,);const shortcutLines = options.showShortcutHelp ? buildShortcutLines(options.width) : [];+ const statusLineBarLines = buildStatusLineBar(snapshot, options.width);++ // When a custom statusline bar is active, replace the built-in status lines+ // to avoid redundant information (both show session name, mode, etc.)+ const effectiveStatusLines = statusLineBarLines.length > 0 ? [] : statusLines;const transcriptLines = buildTranscriptLines(snapshot,@@ -229,7 +248,8 @@ export function buildAppScreenLines(snapshot: AppSnapshot, options: ScreenLayout...options.questionLines,...options.editorLines,...options.composerPreviewLines,- ...statusLines,+ ...effectiveStatusLines,+ ...statusLineBarLines,...shortcutLines,];const height = Math.floor(options.height ?? 0);