@dungle-scrubs/tallow 0.8.21 → 0.8.23
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/dist/cli.js +35 -4
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/interactive-mode-patch.d.ts +2 -0
- package/dist/interactive-mode-patch.d.ts.map +1 -1
- package/dist/interactive-mode-patch.js +82 -0
- package/dist/interactive-mode-patch.js.map +1 -1
- package/dist/sdk.d.ts +17 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +68 -1
- package/dist/sdk.js.map +1 -1
- package/dist/workspace-transition-relay.d.ts +40 -7
- package/dist/workspace-transition-relay.d.ts.map +1 -1
- package/dist/workspace-transition-relay.js +81 -16
- package/dist/workspace-transition-relay.js.map +1 -1
- package/extensions/__integration__/background-task-widget-ownership.test.ts +216 -0
- package/extensions/__integration__/claude-hooks-compat.test.ts +156 -0
- package/extensions/__integration__/slash-command-bridge.test.ts +169 -23
- package/extensions/_shared/atomic-write.ts +1 -1
- package/extensions/_shared/bordered-box.ts +102 -0
- package/extensions/_shared/interop-events.ts +5 -0
- package/extensions/_shared/pid-registry.ts +1 -1
- package/extensions/agent-commands-tool/index.ts +4 -1
- package/extensions/background-task-tool/__tests__/lifecycle.test.ts +50 -25
- package/extensions/background-task-tool/index.ts +139 -221
- package/extensions/bash-tool-enhanced/index.ts +1 -75
- package/extensions/cd-tool/index.ts +2 -2
- package/extensions/context-fork/spawn.ts +4 -1
- package/extensions/health/index.ts +6 -6
- package/extensions/hooks/__tests__/claude-compat.test.ts +35 -0
- package/extensions/hooks/__tests__/subprocess-hardening.test.ts +73 -0
- package/extensions/hooks/index.ts +27 -4
- package/extensions/loop/__tests__/loop.test.ts +168 -4
- package/extensions/loop/extension.json +6 -5
- package/extensions/loop/index.ts +242 -31
- package/extensions/plan-mode-tool/__tests__/agent-end-execution.test.ts +373 -0
- package/extensions/plan-mode-tool/index.ts +103 -41
- package/extensions/prompt-suggestions/__tests__/editor-compatibility.test.ts +42 -0
- package/extensions/prompt-suggestions/index.ts +41 -6
- package/extensions/slash-command-bridge/__tests__/slash-command-bridge.test.ts +267 -671
- package/extensions/slash-command-bridge/extension.json +1 -1
- package/extensions/slash-command-bridge/index.ts +230 -116
- package/extensions/subagent-tool/index.ts +2 -2
- package/extensions/subagent-tool/process.ts +4 -5
- package/extensions/tasks/commands/register-tasks-extension.ts +41 -0
- package/extensions/teams-tool/__tests__/peer-messaging.test.ts +29 -24
- package/extensions/teams-tool/dashboard.ts +3 -5
- package/extensions/teams-tool/dispatch/auto-dispatch.ts +18 -1
- package/extensions/teams-tool/tools/teammate-tools.ts +9 -6
- package/extensions/wezterm-pane-control/__tests__/index.test.ts +88 -4
- package/extensions/wezterm-pane-control/index.ts +113 -8
- package/package.json +6 -4
- package/packages/tallow-tui/README.md +51 -0
- package/packages/tallow-tui/dist/autocomplete.d.ts +48 -0
- package/packages/tallow-tui/dist/autocomplete.d.ts.map +1 -0
- package/packages/tallow-tui/dist/autocomplete.js +564 -0
- package/packages/tallow-tui/dist/autocomplete.js.map +1 -0
- package/packages/tallow-tui/dist/border-styles.d.ts +32 -0
- package/packages/tallow-tui/dist/border-styles.d.ts.map +1 -0
- package/packages/tallow-tui/dist/border-styles.js +46 -0
- package/packages/tallow-tui/dist/border-styles.js.map +1 -0
- package/packages/tallow-tui/dist/components/bordered-box.d.ts +52 -0
- package/packages/tallow-tui/dist/components/bordered-box.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/bordered-box.js +89 -0
- package/packages/tallow-tui/dist/components/bordered-box.js.map +1 -0
- package/packages/tallow-tui/dist/components/box.d.ts +22 -0
- package/packages/tallow-tui/dist/components/box.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/box.js +104 -0
- package/packages/tallow-tui/dist/components/box.js.map +1 -0
- package/packages/tallow-tui/dist/components/cancellable-loader.d.ts +22 -0
- package/packages/tallow-tui/dist/components/cancellable-loader.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/cancellable-loader.js +35 -0
- package/packages/tallow-tui/dist/components/cancellable-loader.js.map +1 -0
- package/packages/tallow-tui/dist/components/editor.d.ts +240 -0
- package/packages/tallow-tui/dist/components/editor.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/editor.js +1766 -0
- package/packages/tallow-tui/dist/components/editor.js.map +1 -0
- package/packages/tallow-tui/dist/components/image.d.ts +126 -0
- package/packages/tallow-tui/dist/components/image.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/image.js +245 -0
- package/packages/tallow-tui/dist/components/image.js.map +1 -0
- package/packages/tallow-tui/dist/components/input.d.ts +37 -0
- package/packages/tallow-tui/dist/components/input.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/input.js +439 -0
- package/packages/tallow-tui/dist/components/input.js.map +1 -0
- package/packages/tallow-tui/dist/components/loader.d.ts +88 -0
- package/packages/tallow-tui/dist/components/loader.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/loader.js +146 -0
- package/packages/tallow-tui/dist/components/loader.js.map +1 -0
- package/packages/tallow-tui/dist/components/markdown.d.ts +95 -0
- package/packages/tallow-tui/dist/components/markdown.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/markdown.js +633 -0
- package/packages/tallow-tui/dist/components/markdown.js.map +1 -0
- package/packages/tallow-tui/dist/components/select-list.d.ts +32 -0
- package/packages/tallow-tui/dist/components/select-list.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/select-list.js +156 -0
- package/packages/tallow-tui/dist/components/select-list.js.map +1 -0
- package/packages/tallow-tui/dist/components/settings-list.d.ts +50 -0
- package/packages/tallow-tui/dist/components/settings-list.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/settings-list.js +189 -0
- package/packages/tallow-tui/dist/components/settings-list.js.map +1 -0
- package/packages/tallow-tui/dist/components/spacer.d.ts +12 -0
- package/packages/tallow-tui/dist/components/spacer.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/spacer.js +23 -0
- package/packages/tallow-tui/dist/components/spacer.js.map +1 -0
- package/packages/tallow-tui/dist/components/text.d.ts +19 -0
- package/packages/tallow-tui/dist/components/text.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/text.js +91 -0
- package/packages/tallow-tui/dist/components/text.js.map +1 -0
- package/packages/tallow-tui/dist/components/truncated-text.d.ts +13 -0
- package/packages/tallow-tui/dist/components/truncated-text.d.ts.map +1 -0
- package/packages/tallow-tui/dist/components/truncated-text.js +51 -0
- package/packages/tallow-tui/dist/components/truncated-text.js.map +1 -0
- package/packages/tallow-tui/dist/editor-component.d.ts +50 -0
- package/packages/tallow-tui/dist/editor-component.d.ts.map +1 -0
- package/packages/tallow-tui/dist/editor-component.js +2 -0
- package/packages/tallow-tui/dist/editor-component.js.map +1 -0
- package/packages/tallow-tui/dist/fuzzy.d.ts +16 -0
- package/packages/tallow-tui/dist/fuzzy.d.ts.map +1 -0
- package/packages/tallow-tui/dist/fuzzy.js +107 -0
- package/packages/tallow-tui/dist/fuzzy.js.map +1 -0
- package/packages/tallow-tui/dist/index.d.ts +25 -0
- package/packages/tallow-tui/dist/index.d.ts.map +1 -0
- package/packages/tallow-tui/dist/index.js +35 -0
- package/packages/tallow-tui/dist/index.js.map +1 -0
- package/packages/tallow-tui/dist/keybindings.d.ts +39 -0
- package/packages/tallow-tui/dist/keybindings.d.ts.map +1 -0
- package/packages/tallow-tui/dist/keybindings.js +114 -0
- package/packages/tallow-tui/dist/keybindings.js.map +1 -0
- package/packages/tallow-tui/dist/keys.d.ts +168 -0
- package/packages/tallow-tui/dist/keys.d.ts.map +1 -0
- package/packages/tallow-tui/dist/keys.js +971 -0
- package/packages/tallow-tui/dist/keys.js.map +1 -0
- package/packages/tallow-tui/dist/kill-ring.d.ts +28 -0
- package/packages/tallow-tui/dist/kill-ring.d.ts.map +1 -0
- package/packages/tallow-tui/dist/kill-ring.js +44 -0
- package/packages/tallow-tui/dist/kill-ring.js.map +1 -0
- package/packages/tallow-tui/dist/stdin-buffer.d.ts +48 -0
- package/packages/tallow-tui/dist/stdin-buffer.d.ts.map +1 -0
- package/packages/tallow-tui/dist/stdin-buffer.js +317 -0
- package/packages/tallow-tui/dist/stdin-buffer.js.map +1 -0
- package/packages/tallow-tui/dist/terminal-image.d.ts +161 -0
- package/packages/tallow-tui/dist/terminal-image.d.ts.map +1 -0
- package/packages/tallow-tui/dist/terminal-image.js +460 -0
- package/packages/tallow-tui/dist/terminal-image.js.map +1 -0
- package/packages/tallow-tui/dist/terminal.d.ts +102 -0
- package/packages/tallow-tui/dist/terminal.d.ts.map +1 -0
- package/packages/tallow-tui/dist/terminal.js +263 -0
- package/packages/tallow-tui/dist/terminal.js.map +1 -0
- package/packages/tallow-tui/dist/test-utils/capability-env.d.ts +14 -0
- package/packages/tallow-tui/dist/test-utils/capability-env.d.ts.map +1 -0
- package/packages/tallow-tui/dist/test-utils/capability-env.js +55 -0
- package/packages/tallow-tui/dist/test-utils/capability-env.js.map +1 -0
- package/packages/tallow-tui/dist/tui.d.ts +239 -0
- package/packages/tallow-tui/dist/tui.d.ts.map +1 -0
- package/packages/tallow-tui/dist/tui.js +1058 -0
- package/packages/tallow-tui/dist/tui.js.map +1 -0
- package/packages/tallow-tui/dist/undo-stack.d.ts +17 -0
- package/packages/tallow-tui/dist/undo-stack.d.ts.map +1 -0
- package/packages/tallow-tui/dist/undo-stack.js +25 -0
- package/packages/tallow-tui/dist/undo-stack.js.map +1 -0
- package/packages/tallow-tui/dist/utils.d.ts +96 -0
- package/packages/tallow-tui/dist/utils.d.ts.map +1 -0
- package/packages/tallow-tui/dist/utils.js +843 -0
- package/packages/tallow-tui/dist/utils.js.map +1 -0
- package/packages/tallow-tui/package.json +24 -0
- package/packages/tallow-tui/src/__tests__/__snapshots__/render.test.ts.snap +121 -0
- package/packages/tallow-tui/src/__tests__/editor-border.test.ts +72 -0
- package/packages/tallow-tui/src/__tests__/editor-change-listener.test.ts +121 -0
- package/packages/tallow-tui/src/__tests__/editor-ghost-text.test.ts +112 -0
- package/packages/tallow-tui/src/__tests__/fuzzy.test.ts +91 -0
- package/packages/tallow-tui/src/__tests__/image-component.test.ts +113 -0
- package/packages/tallow-tui/src/__tests__/keys.test.ts +141 -0
- package/packages/tallow-tui/src/__tests__/render.test.ts +179 -0
- package/packages/tallow-tui/src/__tests__/stdin-buffer.test.ts +82 -0
- package/packages/tallow-tui/src/__tests__/terminal-image.test.ts +363 -0
- package/packages/tallow-tui/src/__tests__/tui-diff-regression.test.ts +454 -0
- package/packages/tallow-tui/src/__tests__/tui-render-scheduling.test.ts +256 -0
- package/packages/tallow-tui/src/__tests__/utils.test.ts +259 -0
- package/packages/tallow-tui/src/autocomplete.ts +716 -0
- package/packages/tallow-tui/src/border-styles.ts +60 -0
- package/packages/tallow-tui/src/components/bordered-box.ts +113 -0
- package/packages/tallow-tui/src/components/box.ts +137 -0
- package/packages/tallow-tui/src/components/cancellable-loader.ts +40 -0
- package/packages/tallow-tui/src/components/editor.ts +2143 -0
- package/packages/tallow-tui/src/components/image.ts +315 -0
- package/packages/tallow-tui/src/components/input.ts +522 -0
- package/packages/tallow-tui/src/components/loader.ts +187 -0
- package/packages/tallow-tui/src/components/markdown.ts +780 -0
- package/packages/tallow-tui/src/components/select-list.ts +197 -0
- package/packages/tallow-tui/src/components/settings-list.ts +264 -0
- package/packages/tallow-tui/src/components/spacer.ts +28 -0
- package/packages/tallow-tui/src/components/text.ts +113 -0
- package/packages/tallow-tui/src/components/truncated-text.ts +65 -0
- package/packages/tallow-tui/src/editor-component.ts +92 -0
- package/packages/tallow-tui/src/fuzzy.ts +133 -0
- package/packages/tallow-tui/src/index.ts +118 -0
- package/packages/tallow-tui/src/keybindings.ts +183 -0
- package/packages/tallow-tui/src/keys.ts +1189 -0
- package/packages/tallow-tui/src/kill-ring.ts +46 -0
- package/packages/tallow-tui/src/stdin-buffer.ts +386 -0
- package/packages/tallow-tui/src/terminal-image.ts +619 -0
- package/packages/tallow-tui/src/terminal.ts +350 -0
- package/packages/tallow-tui/src/test-utils/capability-env.ts +56 -0
- package/packages/tallow-tui/src/tui.ts +1336 -0
- package/packages/tallow-tui/src/undo-stack.ts +28 -0
- package/packages/tallow-tui/src/utils.ts +948 -0
- package/packages/tallow-tui/tsconfig.build.json +21 -0
- package/runtime/agent-runner.ts +20 -0
- package/runtime/atomic-write.ts +8 -0
- package/runtime/otel.ts +12 -0
- package/runtime/resolve-module.ts +23 -0
- package/runtime/runtime-path-provider.ts +12 -0
- package/runtime/runtime-provenance.ts +17 -0
- package/runtime/workspace-transition-relay.ts +21 -0
- package/runtime/workspace-transition.ts +29 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal terminal interface for TUI
|
|
3
|
+
*/
|
|
4
|
+
export interface Terminal {
|
|
5
|
+
start(onInput: (data: string) => void, onResize: () => void): void;
|
|
6
|
+
stop(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Drain stdin before exiting to prevent Kitty key release events from
|
|
9
|
+
* leaking to the parent shell over slow SSH connections.
|
|
10
|
+
* @param maxMs - Maximum time to drain (default: 1000ms)
|
|
11
|
+
* @param idleMs - Exit early if no input arrives within this time (default: 50ms)
|
|
12
|
+
*/
|
|
13
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
14
|
+
write(data: string): void;
|
|
15
|
+
get columns(): number;
|
|
16
|
+
get rows(): number;
|
|
17
|
+
get kittyProtocolActive(): boolean;
|
|
18
|
+
moveBy(lines: number): void;
|
|
19
|
+
hideCursor(): void;
|
|
20
|
+
showCursor(): void;
|
|
21
|
+
clearLine(): void;
|
|
22
|
+
clearFromCursor(): void;
|
|
23
|
+
clearScreen(): void;
|
|
24
|
+
enterAlternateScreen(): void;
|
|
25
|
+
leaveAlternateScreen(): void;
|
|
26
|
+
setTitle(title: string): void;
|
|
27
|
+
/** Set terminal progress bar via OSC 9;4. Supported by Windows Terminal, iTerm2, ConEmu. */
|
|
28
|
+
setProgress(percent: number): void;
|
|
29
|
+
/** Clear terminal progress bar via OSC 9;4. */
|
|
30
|
+
clearProgress(): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Real terminal using process.stdin/stdout
|
|
34
|
+
*/
|
|
35
|
+
export declare class ProcessTerminal implements Terminal {
|
|
36
|
+
private wasRaw;
|
|
37
|
+
private inputHandler?;
|
|
38
|
+
private resizeHandler?;
|
|
39
|
+
private _kittyProtocolActive;
|
|
40
|
+
private stdinBuffer?;
|
|
41
|
+
private stdinDataHandler?;
|
|
42
|
+
private writeLogPath;
|
|
43
|
+
private alternateScreenActive;
|
|
44
|
+
get kittyProtocolActive(): boolean;
|
|
45
|
+
start(onInput: (data: string) => void, onResize: () => void): void;
|
|
46
|
+
/**
|
|
47
|
+
* Set up StdinBuffer to split batched input into individual sequences.
|
|
48
|
+
* This ensures components receive single events, making matchesKey/isKeyRelease work correctly.
|
|
49
|
+
*
|
|
50
|
+
* Also watches for Kitty protocol response and enables it when detected.
|
|
51
|
+
* This is done here (after stdinBuffer parsing) rather than on raw stdin
|
|
52
|
+
* to handle the case where the response arrives split across multiple events.
|
|
53
|
+
*/
|
|
54
|
+
private setupStdinBuffer;
|
|
55
|
+
/**
|
|
56
|
+
* Query terminal for Kitty keyboard protocol support and enable if available.
|
|
57
|
+
*
|
|
58
|
+
* Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,
|
|
59
|
+
* it supports the protocol and we enable it with CSI > 1 u.
|
|
60
|
+
*
|
|
61
|
+
* The response is detected in setupStdinBuffer's data handler, which properly
|
|
62
|
+
* handles the case where the response arrives split across multiple stdin events.
|
|
63
|
+
*/
|
|
64
|
+
private queryAndEnableKittyProtocol;
|
|
65
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
66
|
+
stop(): void;
|
|
67
|
+
write(data: string): void;
|
|
68
|
+
get columns(): number;
|
|
69
|
+
get rows(): number;
|
|
70
|
+
moveBy(lines: number): void;
|
|
71
|
+
hideCursor(): void;
|
|
72
|
+
showCursor(): void;
|
|
73
|
+
clearLine(): void;
|
|
74
|
+
clearFromCursor(): void;
|
|
75
|
+
clearScreen(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Switch to alternate screen buffer and clear it.
|
|
78
|
+
* @returns void
|
|
79
|
+
*/
|
|
80
|
+
enterAlternateScreen(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Restore normal screen buffer and previous scrollback.
|
|
83
|
+
* @returns void
|
|
84
|
+
*/
|
|
85
|
+
leaveAlternateScreen(): void;
|
|
86
|
+
setTitle(title: string): void;
|
|
87
|
+
private lastProgressWrite;
|
|
88
|
+
/**
|
|
89
|
+
* Set terminal progress bar via OSC 9;4.
|
|
90
|
+
* Throttled to max 1 update per 100ms (percent=100 always passes through).
|
|
91
|
+
* Supported by Windows Terminal (tab indicator), iTerm2 (title bar), ConEmu (taskbar).
|
|
92
|
+
* Unsupported terminals gracefully ignore these sequences.
|
|
93
|
+
* @param percent - Progress percentage, clamped to 0-100
|
|
94
|
+
*/
|
|
95
|
+
setProgress(percent: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Clear terminal progress bar via OSC 9;4.
|
|
98
|
+
* Resets the throttle timestamp so a subsequent setProgress fires immediately.
|
|
99
|
+
*/
|
|
100
|
+
clearProgress(): void;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,QAAQ;IAExB,KAAK,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAGnE,IAAI,IAAI,IAAI,CAAC;IAEb;;;;;OAKG;IACH,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,M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IAM7B,UAAU,CAAC,KAAK,SAAO,EAAE,MAAM,SAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC1D,IAAI,IAAI,IAAI;IA4CZ,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWzB,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAW3B,UAAU,IAAI,IAAI;IAIlB,UAAU,IAAI,IAAI;IAIlB,SAAS,IAAI,IAAI;IAIjB,eAAe,IAAI,IAAI;IAIvB,WAAW,IAAI,IAAI;IAInB;;;OAGG;IACH,oBAAoB,IAAI,IAAI;IAM5B;;;OAGG;IACH,oBAAoB,IAAI,IAAI;IAM5B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,OAAO,CAAC,iBAAiB,CAAK;IAE9B;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQlC;;;OAGG;IACH,aAAa,IAAI,IAAI;CAIrB"}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { setKittyProtocolActive } from "./keys.js";
|
|
3
|
+
import { StdinBuffer } from "./stdin-buffer.js";
|
|
4
|
+
/**
|
|
5
|
+
* Real terminal using process.stdin/stdout
|
|
6
|
+
*/
|
|
7
|
+
export class ProcessTerminal {
|
|
8
|
+
wasRaw = false;
|
|
9
|
+
inputHandler;
|
|
10
|
+
resizeHandler;
|
|
11
|
+
_kittyProtocolActive = false;
|
|
12
|
+
stdinBuffer;
|
|
13
|
+
stdinDataHandler;
|
|
14
|
+
writeLogPath = process.env.PI_TUI_WRITE_LOG || "";
|
|
15
|
+
alternateScreenActive = false;
|
|
16
|
+
get kittyProtocolActive() {
|
|
17
|
+
return this._kittyProtocolActive;
|
|
18
|
+
}
|
|
19
|
+
start(onInput, onResize) {
|
|
20
|
+
this.inputHandler = onInput;
|
|
21
|
+
this.resizeHandler = onResize;
|
|
22
|
+
this.alternateScreenActive = false;
|
|
23
|
+
// Save previous state and enable raw mode
|
|
24
|
+
this.wasRaw = process.stdin.isRaw || false;
|
|
25
|
+
if (process.stdin.setRawMode) {
|
|
26
|
+
process.stdin.setRawMode(true);
|
|
27
|
+
}
|
|
28
|
+
process.stdin.setEncoding("utf8");
|
|
29
|
+
process.stdin.resume();
|
|
30
|
+
// Enable bracketed paste mode - terminal will wrap pastes in \x1b[200~ ... \x1b[201~
|
|
31
|
+
process.stdout.write("\x1b[?2004h");
|
|
32
|
+
// Set up resize handler immediately
|
|
33
|
+
process.stdout.on("resize", this.resizeHandler);
|
|
34
|
+
// Refresh terminal dimensions - they may be stale after suspend/resume
|
|
35
|
+
// (SIGWINCH is lost while process is stopped). Unix only.
|
|
36
|
+
if (process.platform !== "win32") {
|
|
37
|
+
process.kill(process.pid, "SIGWINCH");
|
|
38
|
+
}
|
|
39
|
+
// Query and enable Kitty keyboard protocol
|
|
40
|
+
// The query handler intercepts input temporarily, then installs the user's handler
|
|
41
|
+
// See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/
|
|
42
|
+
this.queryAndEnableKittyProtocol();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set up StdinBuffer to split batched input into individual sequences.
|
|
46
|
+
* This ensures components receive single events, making matchesKey/isKeyRelease work correctly.
|
|
47
|
+
*
|
|
48
|
+
* Also watches for Kitty protocol response and enables it when detected.
|
|
49
|
+
* This is done here (after stdinBuffer parsing) rather than on raw stdin
|
|
50
|
+
* to handle the case where the response arrives split across multiple events.
|
|
51
|
+
*/
|
|
52
|
+
setupStdinBuffer() {
|
|
53
|
+
this.stdinBuffer = new StdinBuffer({ timeout: 10 });
|
|
54
|
+
// Kitty protocol response pattern: \x1b[?<flags>u
|
|
55
|
+
const kittyResponsePattern = /^\x1b\[\?(\d+)u$/;
|
|
56
|
+
// Forward individual sequences to the input handler
|
|
57
|
+
this.stdinBuffer.on("data", (sequence) => {
|
|
58
|
+
// Check for Kitty protocol response (only if not already enabled)
|
|
59
|
+
if (!this._kittyProtocolActive) {
|
|
60
|
+
const match = sequence.match(kittyResponsePattern);
|
|
61
|
+
if (match) {
|
|
62
|
+
this._kittyProtocolActive = true;
|
|
63
|
+
setKittyProtocolActive(true);
|
|
64
|
+
// Enable Kitty keyboard protocol (push flags)
|
|
65
|
+
// Flag 1 = disambiguate escape codes
|
|
66
|
+
// Flag 2 = report event types (press/repeat/release)
|
|
67
|
+
// Flag 4 = report alternate keys (shifted key, base layout key)
|
|
68
|
+
// Base layout key enables shortcuts to work with non-Latin keyboard layouts
|
|
69
|
+
process.stdout.write("\x1b[>7u");
|
|
70
|
+
return; // Don't forward protocol response to TUI
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (this.inputHandler) {
|
|
74
|
+
this.inputHandler(sequence);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
// Re-wrap paste content with bracketed paste markers for existing editor handling
|
|
78
|
+
this.stdinBuffer.on("paste", (content) => {
|
|
79
|
+
if (this.inputHandler) {
|
|
80
|
+
this.inputHandler(`\x1b[200~${content}\x1b[201~`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// Handler that pipes stdin data through the buffer
|
|
84
|
+
this.stdinDataHandler = (data) => {
|
|
85
|
+
this.stdinBuffer?.process(data);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Query terminal for Kitty keyboard protocol support and enable if available.
|
|
90
|
+
*
|
|
91
|
+
* Sends CSI ? u to query current flags. If terminal responds with CSI ? <flags> u,
|
|
92
|
+
* it supports the protocol and we enable it with CSI > 1 u.
|
|
93
|
+
*
|
|
94
|
+
* The response is detected in setupStdinBuffer's data handler, which properly
|
|
95
|
+
* handles the case where the response arrives split across multiple stdin events.
|
|
96
|
+
*/
|
|
97
|
+
queryAndEnableKittyProtocol() {
|
|
98
|
+
this.setupStdinBuffer();
|
|
99
|
+
process.stdin.on("data", this.stdinDataHandler);
|
|
100
|
+
process.stdout.write("\x1b[?u");
|
|
101
|
+
}
|
|
102
|
+
async drainInput(maxMs = 1000, idleMs = 50) {
|
|
103
|
+
if (this._kittyProtocolActive) {
|
|
104
|
+
// Disable Kitty keyboard protocol first so any late key releases
|
|
105
|
+
// do not generate new Kitty escape sequences.
|
|
106
|
+
process.stdout.write("\x1b[<u");
|
|
107
|
+
this._kittyProtocolActive = false;
|
|
108
|
+
setKittyProtocolActive(false);
|
|
109
|
+
}
|
|
110
|
+
const previousHandler = this.inputHandler;
|
|
111
|
+
this.inputHandler = undefined;
|
|
112
|
+
let lastDataTime = Date.now();
|
|
113
|
+
const onData = () => {
|
|
114
|
+
lastDataTime = Date.now();
|
|
115
|
+
};
|
|
116
|
+
process.stdin.on("data", onData);
|
|
117
|
+
const endTime = Date.now() + maxMs;
|
|
118
|
+
try {
|
|
119
|
+
while (true) {
|
|
120
|
+
const now = Date.now();
|
|
121
|
+
const timeLeft = endTime - now;
|
|
122
|
+
if (timeLeft <= 0)
|
|
123
|
+
break;
|
|
124
|
+
if (now - lastDataTime >= idleMs)
|
|
125
|
+
break;
|
|
126
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
process.stdin.removeListener("data", onData);
|
|
131
|
+
this.inputHandler = previousHandler;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
stop() {
|
|
135
|
+
// Always restore normal screen buffer before exiting.
|
|
136
|
+
if (this.alternateScreenActive) {
|
|
137
|
+
this.leaveAlternateScreen();
|
|
138
|
+
}
|
|
139
|
+
// Disable bracketed paste mode
|
|
140
|
+
process.stdout.write("\x1b[?2004l");
|
|
141
|
+
// Disable Kitty keyboard protocol if not already done by drainInput()
|
|
142
|
+
if (this._kittyProtocolActive) {
|
|
143
|
+
process.stdout.write("\x1b[<u");
|
|
144
|
+
this._kittyProtocolActive = false;
|
|
145
|
+
setKittyProtocolActive(false);
|
|
146
|
+
}
|
|
147
|
+
// Clean up StdinBuffer
|
|
148
|
+
if (this.stdinBuffer) {
|
|
149
|
+
this.stdinBuffer.destroy();
|
|
150
|
+
this.stdinBuffer = undefined;
|
|
151
|
+
}
|
|
152
|
+
// Remove event handlers
|
|
153
|
+
if (this.stdinDataHandler) {
|
|
154
|
+
process.stdin.removeListener("data", this.stdinDataHandler);
|
|
155
|
+
this.stdinDataHandler = undefined;
|
|
156
|
+
}
|
|
157
|
+
this.inputHandler = undefined;
|
|
158
|
+
if (this.resizeHandler) {
|
|
159
|
+
process.stdout.removeListener("resize", this.resizeHandler);
|
|
160
|
+
this.resizeHandler = undefined;
|
|
161
|
+
}
|
|
162
|
+
// Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being
|
|
163
|
+
// re-interpreted after raw mode is disabled. This fixes a race condition
|
|
164
|
+
// where Ctrl+D could close the parent shell over SSH.
|
|
165
|
+
process.stdin.pause();
|
|
166
|
+
// Restore raw mode state
|
|
167
|
+
if (process.stdin.setRawMode) {
|
|
168
|
+
process.stdin.setRawMode(this.wasRaw);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
write(data) {
|
|
172
|
+
process.stdout.write(data);
|
|
173
|
+
if (this.writeLogPath) {
|
|
174
|
+
try {
|
|
175
|
+
fs.appendFileSync(this.writeLogPath, data, { encoding: "utf8" });
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Ignore logging errors
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
get columns() {
|
|
183
|
+
return process.stdout.columns || 80;
|
|
184
|
+
}
|
|
185
|
+
get rows() {
|
|
186
|
+
return process.stdout.rows || 24;
|
|
187
|
+
}
|
|
188
|
+
moveBy(lines) {
|
|
189
|
+
if (lines > 0) {
|
|
190
|
+
// Move down
|
|
191
|
+
process.stdout.write(`\x1b[${lines}B`);
|
|
192
|
+
}
|
|
193
|
+
else if (lines < 0) {
|
|
194
|
+
// Move up
|
|
195
|
+
process.stdout.write(`\x1b[${-lines}A`);
|
|
196
|
+
}
|
|
197
|
+
// lines === 0: no movement
|
|
198
|
+
}
|
|
199
|
+
hideCursor() {
|
|
200
|
+
process.stdout.write("\x1b[?25l");
|
|
201
|
+
}
|
|
202
|
+
showCursor() {
|
|
203
|
+
process.stdout.write("\x1b[?25h");
|
|
204
|
+
}
|
|
205
|
+
clearLine() {
|
|
206
|
+
process.stdout.write("\x1b[K");
|
|
207
|
+
}
|
|
208
|
+
clearFromCursor() {
|
|
209
|
+
process.stdout.write("\x1b[J");
|
|
210
|
+
}
|
|
211
|
+
clearScreen() {
|
|
212
|
+
process.stdout.write("\x1b[2J\x1b[H"); // Clear screen and move to home (1,1)
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Switch to alternate screen buffer and clear it.
|
|
216
|
+
* @returns void
|
|
217
|
+
*/
|
|
218
|
+
enterAlternateScreen() {
|
|
219
|
+
if (this.alternateScreenActive)
|
|
220
|
+
return;
|
|
221
|
+
process.stdout.write("\x1b[?1049h");
|
|
222
|
+
this.alternateScreenActive = true;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Restore normal screen buffer and previous scrollback.
|
|
226
|
+
* @returns void
|
|
227
|
+
*/
|
|
228
|
+
leaveAlternateScreen() {
|
|
229
|
+
if (!this.alternateScreenActive)
|
|
230
|
+
return;
|
|
231
|
+
process.stdout.write("\x1b[?1049l");
|
|
232
|
+
this.alternateScreenActive = false;
|
|
233
|
+
}
|
|
234
|
+
setTitle(title) {
|
|
235
|
+
// OSC 0;title BEL - set terminal window title
|
|
236
|
+
process.stdout.write(`\x1b]0;${title}\x07`);
|
|
237
|
+
}
|
|
238
|
+
lastProgressWrite = 0;
|
|
239
|
+
/**
|
|
240
|
+
* Set terminal progress bar via OSC 9;4.
|
|
241
|
+
* Throttled to max 1 update per 100ms (percent=100 always passes through).
|
|
242
|
+
* Supported by Windows Terminal (tab indicator), iTerm2 (title bar), ConEmu (taskbar).
|
|
243
|
+
* Unsupported terminals gracefully ignore these sequences.
|
|
244
|
+
* @param percent - Progress percentage, clamped to 0-100
|
|
245
|
+
*/
|
|
246
|
+
setProgress(percent) {
|
|
247
|
+
const clamped = Math.max(0, Math.min(100, Math.round(percent)));
|
|
248
|
+
const now = Date.now();
|
|
249
|
+
if (clamped !== 100 && now - this.lastProgressWrite < 100)
|
|
250
|
+
return;
|
|
251
|
+
this.lastProgressWrite = now;
|
|
252
|
+
process.stdout.write(`\x1b]9;4;1;${clamped}\x07`);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Clear terminal progress bar via OSC 9;4.
|
|
256
|
+
* Resets the throttle timestamp so a subsequent setProgress fires immediately.
|
|
257
|
+
*/
|
|
258
|
+
clearProgress() {
|
|
259
|
+
this.lastProgressWrite = 0;
|
|
260
|
+
process.stdout.write("\x1b]9;4;0;0\x07");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=terminal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAuDhD;;GAEG;AACH,MAAM,OAAO,eAAe;IACnB,MAAM,GAAG,KAAK,CAAC;IACf,YAAY,CAA0B;IACtC,aAAa,CAAc;IAC3B,oBAAoB,GAAG,KAAK,CAAC;IAC7B,WAAW,CAAe;IAC1B,gBAAgB,CAA0B;IAC1C,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;IAClD,qBAAqB,GAAG,KAAK,CAAC;IAEtC,IAAI,mBAAmB;QACtB,OAAO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C;IAC1C,CAAC;CACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type CapabilityEnvOverrides = Readonly<Record<string, string | undefined>>;
|
|
2
|
+
/**
|
|
3
|
+
* Run a callback with controlled terminal capability environment variables.
|
|
4
|
+
*
|
|
5
|
+
* Resets the terminal capability cache before and after the callback so test
|
|
6
|
+
* assertions always reflect the requested environment.
|
|
7
|
+
*
|
|
8
|
+
* @param overrides - Temporary environment variable overrides
|
|
9
|
+
* @param run - Callback executed with overrides applied
|
|
10
|
+
* @returns Callback return value
|
|
11
|
+
*/
|
|
12
|
+
export declare function withCapabilityEnv<T>(overrides: CapabilityEnvOverrides, run: () => T): T;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=capability-env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability-env.d.ts","sourceRoot":"","sources":["../../src/test-utils/capability-env.ts"],"names":[],"mappings":"AAYA,KAAK,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CA+BvF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { resetCapabilitiesCache } from "../terminal-image.js";
|
|
2
|
+
const CAPABILITY_ENV_KEYS = [
|
|
3
|
+
"COLORTERM",
|
|
4
|
+
"GHOSTTY_RESOURCES_DIR",
|
|
5
|
+
"ITERM_SESSION_ID",
|
|
6
|
+
"KITTY_WINDOW_ID",
|
|
7
|
+
"TERM",
|
|
8
|
+
"TERM_PROGRAM",
|
|
9
|
+
"WEZTERM_PANE",
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* Run a callback with controlled terminal capability environment variables.
|
|
13
|
+
*
|
|
14
|
+
* Resets the terminal capability cache before and after the callback so test
|
|
15
|
+
* assertions always reflect the requested environment.
|
|
16
|
+
*
|
|
17
|
+
* @param overrides - Temporary environment variable overrides
|
|
18
|
+
* @param run - Callback executed with overrides applied
|
|
19
|
+
* @returns Callback return value
|
|
20
|
+
*/
|
|
21
|
+
export function withCapabilityEnv(overrides, run) {
|
|
22
|
+
const previous = {};
|
|
23
|
+
for (const key of CAPABILITY_ENV_KEYS) {
|
|
24
|
+
previous[key] = process.env[key];
|
|
25
|
+
if (Object.hasOwn(overrides, key)) {
|
|
26
|
+
const value = overrides[key];
|
|
27
|
+
if (value === undefined) {
|
|
28
|
+
delete process.env[key];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
process.env[key] = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
delete process.env[key];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
resetCapabilitiesCache();
|
|
39
|
+
try {
|
|
40
|
+
return run();
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
for (const key of CAPABILITY_ENV_KEYS) {
|
|
44
|
+
const value = previous[key];
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
delete process.env[key];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
process.env[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
resetCapabilitiesCache();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=capability-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability-env.js","sourceRoot":"","sources":["../../src/test-utils/capability-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,mBAAmB,GAAG;IAC3B,WAAW;IACX,uBAAuB;IACvB,kBAAkB;IAClB,iBAAiB;IACjB,MAAM;IACN,cAAc;IACd,cAAc;CACL,CAAC;AAIX;;;;;;;;;GASG;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