@runminton/pi-tidy-tools 0.1.2 → 0.1.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## [0.1.3] - 2026-08-27
4
+
5
+ ### Added
6
+
7
+ - Added `/tidy-bash`, `/tidy-edit`, and `/tidy-write` commands for toggling tool output.
8
+ - Added `/tidy-key-debug` to inspect the next terminal key sequence.
9
+
10
+ ### Fixed
11
+
12
+ - Normalized the legacy `ESC` + control-character form of `Ctrl+Alt+letter` shortcuts.
13
+
14
+ ### Documentation
15
+
16
+ - Documented the new commands and keyboard input debugging steps.
package/README.md CHANGED
@@ -28,6 +28,16 @@ A notification shows the current state on each toggle; press again to switch bac
28
28
 
29
29
  `bash` expands to the **complete output** in one keypress — it skips Pi's built-in 5-line tail preview. `edit` and `write` expand to Pi's **official default rendering**: they delegate to the official renderers, and whether the content itself is further expanded is still controlled by the global `Ctrl+O`, exactly as without this extension. Only `bash` ignores `Ctrl+O` in its expanded state.
30
30
 
31
+ ## Commands
32
+
33
+ Use these commands when terminal shortcuts conflict or are not delivered:
34
+
35
+ | Command | Tool |
36
+ |---|---|
37
+ | `/tidy-bash` | Toggle `bash` output |
38
+ | `/tidy-edit` | Toggle `edit` output |
39
+ | `/tidy-write` | Toggle `write` output |
40
+
31
41
  ## Usage
32
42
 
33
43
  Load the extension:
@@ -61,6 +71,7 @@ If a shortcut still does nothing on your machine, check:
61
71
  1. **Terminal or input method swallows the key.** Some terminals and IMEs (e.g. Chinese input methods, Windows Alt-menu accelerators) intercept `Ctrl+Alt+...` before Pi ever sees it. Try a different combination or a different terminal.
62
72
  2. **tmux / screen.** If Pi runs inside tmux with the default configuration, tmux's own key handling may interfere.
63
73
  3. **Custom keys.** The bindings are registered in `tidy-tools.ts` via `pi.registerShortcut(...)` — edit the key strings there to rebind. Pi's built-in global expansion (`Ctrl+O`, `app.tools.expand`) is configured separately via `~/.pi/agent/keybindings.json`.
74
+ 4. **Inspect the input.** Run `/tidy-key-debug`, then press one target shortcut. Pi shows the received bytes and any rewrite. If no notification appears, the terminal or input method consumed the key before Pi received it.
64
75
 
65
76
  ## Development
66
77
 
package/README.zh-CN.md CHANGED
@@ -28,6 +28,16 @@
28
28
 
29
29
  `bash` 展开时**一次按键直接显示完整输出**——跳过 Pi 内置的 5 行尾部预览。`edit` 和 `write` 展开时使用 Pi **官方默认渲染**:委托给官方渲染器,内容本身是否进一步展开仍由全局 `Ctrl+O` 控制,与不装本扩展时完全一致。只有 `bash` 在展开状态下不受 `Ctrl+O` 影响。
30
30
 
31
+ ## 命令
32
+
33
+ 终端快捷键冲突或无法传入 Pi 时,使用这些命令:
34
+
35
+ | 命令 | 工具 |
36
+ |---|---|
37
+ | `/tidy-bash` | 切换 `bash` 输出 |
38
+ | `/tidy-edit` | 切换 `edit` 输出 |
39
+ | `/tidy-write` | 切换 `write` 输出 |
40
+
31
41
  ## 使用方法
32
42
 
33
43
  加载扩展:
@@ -61,6 +71,7 @@ Pi 会在终端支持时协商 [Kitty 键盘协议](https://sw.kovidgoyal.net/ki
61
71
  1. **终端或输入法吞掉了按键。** 有些终端和输入法(例如中文输入法、Windows 的 Alt 菜单加速键)会在 Pi 收到按键之前把它拦截。换一个组合键或换一个终端试试。
62
72
  2. **tmux / screen。** 如果 Pi 运行在 tmux 默认配置里,tmux 自己的按键处理可能干扰。
63
73
  3. **自定义按键。** 绑定在 `tidy-tools.ts` 里通过 `pi.registerShortcut(...)` 注册——改那里的按键字符串即可重新绑定。Pi 内置的全局展开(`Ctrl+O`,即 `app.tools.expand`)则单独通过 `~/.pi/agent/keybindings.json` 配置。
74
+ 4. **检查输入。** 执行 `/tidy-key-debug`,再按一次目标快捷键。Pi 会显示收到的字节和改写结果。若没有通知,终端或输入法在 Pi 收到按键前已拦截它。
64
75
 
65
76
  ## 开发
66
77
 
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@runminton/pi-tidy-tools",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Collapse bash/edit/write into one-line summaries in the pi TUI; expand the official rendering per tool with Ctrl+Alt+B/W/E.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "files": [
8
8
  "tidy-tools.ts",
9
9
  "README.md",
10
- "README.zh-CN.md"
10
+ "README.zh-CN.md",
11
+ "CHANGELOG.md"
11
12
  ],
12
13
  "pi": {
13
14
  "extensions": [
package/tidy-tools.ts CHANGED
@@ -180,8 +180,17 @@ const CTRL_CODE_TO_KEY: Record<number, string> = {
180
180
  2: "b", // Ctrl+B
181
181
  };
182
182
  const ALT_MODIFIER = 2;
183
+ let debugNextTerminalInput = false;
183
184
 
184
185
  function convertCtrlAltSequence(data: string): string | undefined {
186
+ // Legacy terminals send Ctrl+Alt+letter as ESC followed by the Ctrl
187
+ // character. Pi deliberately ignores this form after Kitty negotiation,
188
+ // so normalize it before Pi's key matcher sees it.
189
+ if (data.length === 2 && data[0] === "\x1b") {
190
+ const key = CTRL_CODE_TO_KEY[data.charCodeAt(1)];
191
+ if (key) return `\x1b[${key.charCodeAt(0)};7u`; // 7 = Ctrl|Alt (1-indexed)
192
+ }
193
+
185
194
  const match = data.match(/^\x1b\[(\d+);(\d+)(?::(\d+))?u$/);
186
195
  if (!match) return undefined;
187
196
  const code = Number(match[1]);
@@ -455,6 +464,26 @@ export default function (pi: ExtensionAPI) {
455
464
  },
456
465
  );
457
466
 
467
+ pi.registerCommand("tidy-bash", {
468
+ description: "Toggle bash output expansion",
469
+ handler: async (_args, ctx) => toggleToolExpanded(ctx, "bash"),
470
+ });
471
+ pi.registerCommand("tidy-edit", {
472
+ description: "Toggle edit output expansion",
473
+ handler: async (_args, ctx) => toggleToolExpanded(ctx, "edit"),
474
+ });
475
+ pi.registerCommand("tidy-write", {
476
+ description: "Toggle write output expansion",
477
+ handler: async (_args, ctx) => toggleToolExpanded(ctx, "write"),
478
+ });
479
+ pi.registerCommand("tidy-key-debug", {
480
+ description: "Show the next raw terminal key sequence",
481
+ handler: async (_args, ctx) => {
482
+ debugNextTerminalInput = true;
483
+ ctx.ui.notify("Press one key to inspect its terminal sequence.", "info");
484
+ },
485
+ });
486
+
458
487
  // --- Per-tool expansion shortcuts, independent of the global Ctrl+O ---
459
488
  pi.registerShortcut("ctrl+alt+e", {
460
489
  description: "Toggle edit expansion",
@@ -472,8 +501,16 @@ export default function (pi: ExtensionAPI) {
472
501
  // Some terminals encode Ctrl+Alt+letter as a control-character CSI-u
473
502
  // sequence. Rewrite those three sequences before they reach the editor.
474
503
  pi.on("session_start", (_event, ctx) => {
475
- ctx.ui.onTerminalInput?.((data) => {
504
+ ctx.ui.onTerminalInput((data) => {
476
505
  const converted = convertCtrlAltSequence(data);
506
+ if (debugNextTerminalInput) {
507
+ debugNextTerminalInput = false;
508
+ const bytes = [...data].map((char) => char.charCodeAt(0)).join(", ");
509
+ ctx.ui.notify(
510
+ `raw: ${JSON.stringify(data)} [${bytes}]${converted ? ` → ${JSON.stringify(converted)}` : ""}`,
511
+ "info",
512
+ );
513
+ }
477
514
  return converted ? { data: converted } : undefined;
478
515
  });
479
516
  });