Skip to content

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

fix:/statusline help,json子命令用户友好

openJiuwen-bot57c7f01444fc
diff --git a/docs/en/SlashCommands.md b/docs/en/SlashCommands.md
index 7581f25270..53b4271c79 100644
--- a/docs/en/SlashCommands.md
+++ b/docs/en/SlashCommands.md
@@ -574,11 +574,12 @@ Configure the TUI footer status bar with a custom shell command that dynamically
| `/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 |
+| `/statusline help` | Show usage guide (writing patterns, practical examples, field list) |
+| `/statusline json` | Show the actual current JSON data values (useful for debugging jq expressions) |
#### 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.
+- **StatusLine**: A text area at the bottom of the TUI that displays user-defined dynamic information, supporting multi-line output. 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`).
@@ -670,7 +671,8 @@ Use the following template to write commands. `input=$(cat)` reads JSON into a v
- `/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 set 'input=$(cat); dirs=$(echo "$input" | jq -r '.trusted_dirs // [] | join(" ")'); mode=$(echo "$input" | jq -r '.mode // "?"'); echo "$mode | dirs:$dirs"'` — Show mode and trusted workspace directories
- `/statusline clear` — Remove status line configuration
-- `/statusline help` — View JSON input fields reference
+- `/statusline help` — View usage guide (writing patterns, practical examples, available fields)
+- `/statusline json` — View actual current JSON data values (useful for debugging jq expressions)
#### Behavior Details
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 be446987b9..b574df2ba2 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"
@@ -585,11 +585,12 @@
| `/statusline` 或 `/statusline get` | 查看当前状态栏配置 |
| `/statusline set <shell-command>` | 设置状态栏命令(命令输出将显示在 TUI 底部) |
| `/statusline clear` | 清除状态栏配置(底部栏将不再显示) |
-| `/statusline help` | 显示状态栏 JSON 输入字段参考 |
+| `/statusline help` | 显示使用指南(含写法模式、实用示例、字段列表) |
+| `/statusline json` | 显示当前实际的 JSON 数据值(方便调试 jq 表达式) |
#### 概念说明
-- **状态栏(StatusLine)**:TUI 底部的一行文字区域,实时显示用户自定义的动态信息。配置了自定义状态栏后,内置状态栏会自动隐藏,避免信息冗余。
+- **状态栏(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`)。
@@ -681,7 +682,8 @@
- `/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 set 'input=$(cat); dirs=$(echo "$input" | jq -r '.trusted_dirs // [] | join(" ")'); mode=$(echo "$input" | jq -r '.mode // "?"'); echo "$mode | dirs:$dirs"'` — 显示模式与可信工作目录
- `/statusline clear` — 清除状态栏配置
-- `/statusline help` — 查看 JSON 输入字段参考
+- `/statusline help` — 查看使用指南(含写法模式、实用示例、可用字段)
+- `/statusline json` — 查看当前实际的 JSON 数据值(方便调试 jq 表达式)
#### 行为细节
diff --git a/jiuwenswarm/channels/tui/frontend/src/app-state.ts b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
index 0dd026b7c8..5b1ca54010 100644
--- a/jiuwenswarm/channels/tui/frontend/src/app-state.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/app-state.ts
@@ -660,6 +660,7 @@ export class CliPiAppState {
enterStatusView: undefined,
getUsageSummary: () => this.getUsageSummary(),
restartStatusLine: () => this.restartStatusLinePoll(),
+ getStatusLineJsonInput: () => this.buildStatusLineJsonInput(),
};
}
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/statusline.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/statusline.ts
index a54dc9a165..867ac9e5bf 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/statusline.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/statusline.ts
@@ -74,39 +74,57 @@ function clearConfig(ctx: CommandContext): void {
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",
- "trusted_dirs — trusted workspace directories (array of paths)",
- "usage.total_input_tokens — total input tokens",
- "usage.total_output_tokens — total output tokens",
- "usage.total_tokens — total tokens (input + output)",
- "context_window.context_window_size — model max context tokens",
- "context_window.used_percentage — context occupancy (0-100)",
- "context_window.remaining_percentage — context remaining (0-100)",
+function showHelp(ctx: CommandContext): void {
+ const helpLines = [
+ "StatusLine — runs a shell command every 2s and displays the output at the bottom of the screen. Supports multi-line output.",
+ "",
+ "How data is passed:",
+ " JSON is piped via stdin. On Windows, you can also use the file at $JIUWENSWARM_SL_FILE.",
+ "",
+ "Subcommands:",
+ " /statusline set <command> — set the shell command to run",
+ " /statusline padding <n> — set left & right padding (0 or positive)",
+ " /statusline clear — remove statusline configuration",
+ " /statusline help — show this guide",
+ " /statusline json — show the real JSON data your command receives right now",
+ "",
+ "How to write a command:",
+ " Single field: jq -r '.field'",
+ " Multiple fields: input=$(cat); echo \"$(echo \"$input\" | jq -r .field1) | $(echo \"$input\" | jq -r .field2)\"",
+ " Multi-line output: printf \"line1\\nline2\"",
+ "",
+ "Examples:",
+ " /statusline set 'jq -r \".mode + \" | \" + .model\"'",
+ " /statusline set 'input=$(cat); echo \"$(echo \"$input\" | jq -r .mode) | $(echo \"$input\" | jq -r .model)\"'",
+ " /statusline set 'basename \"$PWD\" && git branch --show-current 2>/dev/null || echo \"\"'",
+ " /statusline set 'printf \"%s\\n%s\" \"$(jq -r .mode)\" \"$(jq -r .cwd)\"'",
+ " /statusline set 'input=$(cat); pct=$(echo \"$input\" | jq -r \".context_window.remaining_percentage // empty\"); [ -n \"$pct\" ] && echo \"ctx: $pct% left\"'",
+ "",
+ "Tip: for long commands, save a script file and reference it in /statusline set.",
+ "",
+ "Available JSON fields:",
+ " session_id, session_name, cwd, mode, model, provider, version,",
+ " connection, theme, accent_color, transcript_mode, transcript_fold_mode,",
+ " is_processing, is_paused, is_interrupted, cancellable_work,",
+ " streaming_state, last_error, evolution_status,",
+ " active_subtask_count, todo_count, trusted_dirs,",
+ " usage.total_input_tokens, usage.total_output_tokens, usage.total_tokens,",
+ " context_window.context_window_size, .used_percentage, .remaining_percentage",
+ "",
+ "Use /statusline json to see the actual values right now.",
];
+ ctx.addItem(makeItem(ctx.sessionId, "info", helpLines.join("\n"), "m"));
+ showCurrentConfig(ctx);
+}
+
+function showActualJsonData(ctx: CommandContext): void {
+ const data = ctx.getStatusLineJsonInput?.();
+ if (!data) {
+ ctx.addItem(makeItem(ctx.sessionId, "info", "StatusLine — JSON data not available", "m"));
+ return;
+ }
ctx.addItem(
- makeItem(ctx.sessionId, "info", `StatusLine — JSON input fields\n${fields.map((f) => ` ${f}`).join("\n")}`, "m"),
+ makeItem(ctx.sessionId, "info", `StatusLine — current JSON input:\n${JSON.stringify(data, null, 2)}`, "m"),
);
}
@@ -148,30 +166,27 @@ export function createStatusLineCommand(): SlashCommand {
},
{
name: "help",
- description: "Show statusline help and available fields",
+ description: "Show statusline usage guide",
usage: "/statusline help",
kind: CommandKind.BUILT_IN,
takesArgs: false,
isSafeConcurrent: true,
- action: (ctx) => {
- showCurrentConfig(ctx);
- showJsonInput(ctx);
- },
+ action: (ctx) => showHelp(ctx),
},
{
name: "json",
- description: "Show current JSON input data",
+ description: "Show the current JSON data your command would receive",
usage: "/statusline json",
kind: CommandKind.BUILT_IN,
takesArgs: false,
isSafeConcurrent: true,
- action: (ctx) => showJsonInput(ctx),
+ action: (ctx) => showActualJsonData(ctx),
},
],
action: (ctx, args) => {
const sub = args.trim().split(/\s+/)[0];
if (!sub) {
- showCurrentConfig(ctx);
+ showHelp(ctx);
return;
}
const matched = createStatusLineCommand().subCommands?.find((s) => s.name === sub);
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts
index 1c7eb9d5ee..dd27b4744c 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/types.ts
@@ -92,6 +92,8 @@ export interface CommandContext {
/** Enter FileViewer mode to view large content (e.g., formatted logs) */
enterFileViewer?: (content: string, title: string, source: string) => void;
restartStatusLine?: () => void;
+ /** Get the current JSON data that would be piped to the statusline command */
+ getStatusLineJsonInput?: () => Record<string, unknown>;
}
export interface SlashCommand {