@pencil-agent/nano-pencil 2.0.0-beta.2 → 2.0.0-beta.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/dist/build-meta.json +3 -3
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.js +60 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.js +55 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.js +137 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.js +64 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +913 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.d.ts +9 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.js +32 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.d.ts +215 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.js +522 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.js +146 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.js +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.d.ts +91 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.js +279 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.d.ts +15 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +625 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.js +189 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.js +319 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.d.ts +417 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.js +13 -0
- package/dist/node_modules/@pencil-agent/agent-core/package.json +28 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.js +152 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.d.ts +2 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.js +121 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.d.ts +1 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.js +17 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.d.ts +94 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.js +218 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.js +107 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.d.ts +15159 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +14928 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.js +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.js +606 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +737 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.d.ts +21 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.js +193 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.d.ts +79 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.js +753 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.d.ts +70 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.js +311 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.js +380 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.js +360 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.js +704 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +870 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.js +432 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +207 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.js +86 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.js +40 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.js +175 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.js +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.js +9 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.d.ts +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.js +324 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.d.ts +306 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.js +98 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.js +109 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.js +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.js +286 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.js +378 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.js +483 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.d.ts +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.js +131 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.d.ts +39 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.js +385 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.js +36 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.d.ts +52 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.d.ts +57 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.js +120 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.d.ts +16 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.js +26 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.d.ts +23 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.js +78 -0
- package/dist/node_modules/@pencil-agent/ai/package.json +94 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.js +624 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.js +109 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.js +40 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.d.ts +218 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.js +1697 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.js +74 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.d.ts +42 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.js +438 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.js +54 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.d.ts +100 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.js +634 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.d.ts +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.js +157 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.d.ts +55 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.js +190 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.js +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.d.ts +24 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.js +94 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.js +56 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.d.ts +51 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.js +7 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.d.ts +32 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.js +152 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.d.ts +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.js +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.d.ts +44 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.js +119 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.d.ts +149 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.js +948 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.js +49 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.js +307 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.d.ts +73 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.js +287 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.d.ts +86 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.js +266 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.d.ts +219 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.js +1001 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.js +30 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.d.ts +83 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.js +811 -0
- package/dist/node_modules/@pencil-agent/tui/package.json +37 -0
- package/package.json +3 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ring buffer for Emacs-style kill/yank operations.
|
|
3
|
+
*
|
|
4
|
+
* Tracks killed (deleted) text entries. Consecutive kills can accumulate
|
|
5
|
+
* into a single entry. Supports yank (paste most recent) and yank-pop
|
|
6
|
+
* (cycle through older entries).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* [WHO]: KillRing
|
|
10
|
+
* [FROM]: No external dependencies
|
|
11
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
12
|
+
* [HERE]: core/lib/tui/src/kill-ring.ts -
|
|
13
|
+
*/
|
|
14
|
+
export declare class KillRing {
|
|
15
|
+
private ring;
|
|
16
|
+
/**
|
|
17
|
+
* Add text to the kill ring.
|
|
18
|
+
*
|
|
19
|
+
* @param text - The killed text to add
|
|
20
|
+
* @param opts - Push options
|
|
21
|
+
* @param opts.prepend - If accumulating, prepend (backward deletion) or append (forward deletion)
|
|
22
|
+
* @param opts.accumulate - Merge with the most recent entry instead of creating a new one
|
|
23
|
+
*/
|
|
24
|
+
push(text: string, opts: {
|
|
25
|
+
prepend: boolean;
|
|
26
|
+
accumulate?: boolean;
|
|
27
|
+
}): void;
|
|
28
|
+
/** Get most recent entry without modifying the ring. */
|
|
29
|
+
peek(): string | undefined;
|
|
30
|
+
/** Move last entry to front (for yank-pop cycling). */
|
|
31
|
+
rotate(): void;
|
|
32
|
+
get length(): number;
|
|
33
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ring buffer for Emacs-style kill/yank operations.
|
|
3
|
+
*
|
|
4
|
+
* Tracks killed (deleted) text entries. Consecutive kills can accumulate
|
|
5
|
+
* into a single entry. Supports yank (paste most recent) and yank-pop
|
|
6
|
+
* (cycle through older entries).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* [WHO]: KillRing
|
|
10
|
+
* [FROM]: No external dependencies
|
|
11
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
12
|
+
* [HERE]: core/lib/tui/src/kill-ring.ts -
|
|
13
|
+
*/
|
|
14
|
+
export class KillRing {
|
|
15
|
+
ring = [];
|
|
16
|
+
/**
|
|
17
|
+
* Add text to the kill ring.
|
|
18
|
+
*
|
|
19
|
+
* @param text - The killed text to add
|
|
20
|
+
* @param opts - Push options
|
|
21
|
+
* @param opts.prepend - If accumulating, prepend (backward deletion) or append (forward deletion)
|
|
22
|
+
* @param opts.accumulate - Merge with the most recent entry instead of creating a new one
|
|
23
|
+
*/
|
|
24
|
+
push(text, opts) {
|
|
25
|
+
if (!text)
|
|
26
|
+
return;
|
|
27
|
+
if (opts.accumulate && this.ring.length > 0) {
|
|
28
|
+
const last = this.ring.pop();
|
|
29
|
+
this.ring.push(opts.prepend ? text + last : last + text);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.ring.push(text);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Get most recent entry without modifying the ring. */
|
|
36
|
+
peek() {
|
|
37
|
+
return this.ring.length > 0 ? this.ring[this.ring.length - 1] : undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Move last entry to front (for yank-pop cycling). */
|
|
40
|
+
rotate() {
|
|
41
|
+
if (this.ring.length > 1) {
|
|
42
|
+
const last = this.ring.pop();
|
|
43
|
+
this.ring.unshift(last);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
get length() {
|
|
47
|
+
return this.ring.length;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: StdinBuffer class - buffers input and emits complete sequences
|
|
3
|
+
* [FROM]: Depends on node:events
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts, TUI input handling
|
|
5
|
+
* [HERE]: core/lib/tui/src/stdin-buffer.ts - input buffering for terminal sequences
|
|
6
|
+
*
|
|
7
|
+
* Buffers stdin data events that arrive in partial chunks, especially for
|
|
8
|
+
* escape sequences like mouse events. Based on OpenTUI.
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from "events";
|
|
11
|
+
export type StdinBufferOptions = {
|
|
12
|
+
/**
|
|
13
|
+
* Maximum time to wait for sequence completion (default: 10ms)
|
|
14
|
+
* After this time, the buffer is flushed even if incomplete
|
|
15
|
+
*/
|
|
16
|
+
timeout?: number;
|
|
17
|
+
};
|
|
18
|
+
export type StdinBufferEventMap = {
|
|
19
|
+
data: [string];
|
|
20
|
+
paste: [string];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Buffers stdin input and emits complete sequences via the 'data' event.
|
|
24
|
+
* Handles partial escape sequences that arrive across multiple chunks.
|
|
25
|
+
*/
|
|
26
|
+
export declare class StdinBuffer extends EventEmitter<StdinBufferEventMap> {
|
|
27
|
+
private buffer;
|
|
28
|
+
private timeout;
|
|
29
|
+
private readonly timeoutMs;
|
|
30
|
+
private pasteMode;
|
|
31
|
+
private pasteBuffer;
|
|
32
|
+
constructor(options?: StdinBufferOptions);
|
|
33
|
+
process(data: string | Buffer): void;
|
|
34
|
+
flush(): string[];
|
|
35
|
+
clear(): void;
|
|
36
|
+
getBuffer(): string;
|
|
37
|
+
destroy(): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: StdinBuffer class - buffers input and emits complete sequences
|
|
3
|
+
* [FROM]: Depends on node:events
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts, TUI input handling
|
|
5
|
+
* [HERE]: core/lib/tui/src/stdin-buffer.ts - input buffering for terminal sequences
|
|
6
|
+
*
|
|
7
|
+
* Buffers stdin data events that arrive in partial chunks, especially for
|
|
8
|
+
* escape sequences like mouse events. Based on OpenTUI.
|
|
9
|
+
*/
|
|
10
|
+
import { EventEmitter } from "events";
|
|
11
|
+
const ESC = "\x1b";
|
|
12
|
+
const BRACKETED_PASTE_START = "\x1b[200~";
|
|
13
|
+
const BRACKETED_PASTE_END = "\x1b[201~";
|
|
14
|
+
/**
|
|
15
|
+
* Check if a string is a complete escape sequence or needs more data
|
|
16
|
+
*/
|
|
17
|
+
function isCompleteSequence(data) {
|
|
18
|
+
if (!data.startsWith(ESC)) {
|
|
19
|
+
return "not-escape";
|
|
20
|
+
}
|
|
21
|
+
if (data.length === 1) {
|
|
22
|
+
return "incomplete";
|
|
23
|
+
}
|
|
24
|
+
const afterEsc = data.slice(1);
|
|
25
|
+
// CSI sequences: ESC [
|
|
26
|
+
if (afterEsc.startsWith("[")) {
|
|
27
|
+
// Check for old-style mouse sequence: ESC[M + 3 bytes
|
|
28
|
+
if (afterEsc.startsWith("[M")) {
|
|
29
|
+
// Old-style mouse needs ESC[M + 3 bytes = 6 total
|
|
30
|
+
return data.length >= 6 ? "complete" : "incomplete";
|
|
31
|
+
}
|
|
32
|
+
return isCompleteCsiSequence(data);
|
|
33
|
+
}
|
|
34
|
+
// OSC sequences: ESC ]
|
|
35
|
+
if (afterEsc.startsWith("]")) {
|
|
36
|
+
return isCompleteOscSequence(data);
|
|
37
|
+
}
|
|
38
|
+
// DCS sequences: ESC P ... ESC \ (includes XTVersion responses)
|
|
39
|
+
if (afterEsc.startsWith("P")) {
|
|
40
|
+
return isCompleteDcsSequence(data);
|
|
41
|
+
}
|
|
42
|
+
// APC sequences: ESC _ ... ESC \ (includes Kitty graphics responses)
|
|
43
|
+
if (afterEsc.startsWith("_")) {
|
|
44
|
+
return isCompleteApcSequence(data);
|
|
45
|
+
}
|
|
46
|
+
// SS3 sequences: ESC O
|
|
47
|
+
if (afterEsc.startsWith("O")) {
|
|
48
|
+
// ESC O followed by a single character
|
|
49
|
+
return afterEsc.length >= 2 ? "complete" : "incomplete";
|
|
50
|
+
}
|
|
51
|
+
// Meta key sequences: ESC followed by a single character
|
|
52
|
+
if (afterEsc.length === 1) {
|
|
53
|
+
return "complete";
|
|
54
|
+
}
|
|
55
|
+
// Unknown escape sequence - treat as complete
|
|
56
|
+
return "complete";
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if CSI sequence is complete
|
|
60
|
+
* CSI sequences: ESC [ ... followed by a final byte (0x40-0x7E)
|
|
61
|
+
*/
|
|
62
|
+
function isCompleteCsiSequence(data) {
|
|
63
|
+
if (!data.startsWith(`${ESC}[`)) {
|
|
64
|
+
return "complete";
|
|
65
|
+
}
|
|
66
|
+
// Need at least ESC [ and one more character
|
|
67
|
+
if (data.length < 3) {
|
|
68
|
+
return "incomplete";
|
|
69
|
+
}
|
|
70
|
+
const payload = data.slice(2);
|
|
71
|
+
// CSI sequences end with a byte in the range 0x40-0x7E (@-~)
|
|
72
|
+
// This includes all letters and several special characters
|
|
73
|
+
const lastChar = payload[payload.length - 1];
|
|
74
|
+
const lastCharCode = lastChar.charCodeAt(0);
|
|
75
|
+
if (lastCharCode >= 0x40 && lastCharCode <= 0x7e) {
|
|
76
|
+
// Special handling for SGR mouse sequences
|
|
77
|
+
// Format: ESC[<B;X;Ym or ESC[<B;X;YM
|
|
78
|
+
if (payload.startsWith("<")) {
|
|
79
|
+
// Must have format: <digits;digits;digits[Mm]
|
|
80
|
+
const mouseMatch = /^<\d+;\d+;\d+[Mm]$/.test(payload);
|
|
81
|
+
if (mouseMatch) {
|
|
82
|
+
return "complete";
|
|
83
|
+
}
|
|
84
|
+
// If it ends with M or m but doesn't match the pattern, still incomplete
|
|
85
|
+
if (lastChar === "M" || lastChar === "m") {
|
|
86
|
+
// Check if we have the right structure
|
|
87
|
+
const parts = payload.slice(1, -1).split(";");
|
|
88
|
+
if (parts.length === 3 && parts.every((p) => /^\d+$/.test(p))) {
|
|
89
|
+
return "complete";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return "incomplete";
|
|
93
|
+
}
|
|
94
|
+
return "complete";
|
|
95
|
+
}
|
|
96
|
+
return "incomplete";
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if OSC sequence is complete
|
|
100
|
+
* OSC sequences: ESC ] ... ST (where ST is ESC \ or BEL)
|
|
101
|
+
*/
|
|
102
|
+
function isCompleteOscSequence(data) {
|
|
103
|
+
if (!data.startsWith(`${ESC}]`)) {
|
|
104
|
+
return "complete";
|
|
105
|
+
}
|
|
106
|
+
// OSC sequences end with ST (ESC \) or BEL (\x07)
|
|
107
|
+
if (data.endsWith(`${ESC}\\`) || data.endsWith("\x07")) {
|
|
108
|
+
return "complete";
|
|
109
|
+
}
|
|
110
|
+
return "incomplete";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Check if DCS (Device Control String) sequence is complete
|
|
114
|
+
* DCS sequences: ESC P ... ST (where ST is ESC \)
|
|
115
|
+
* Used for XTVersion responses like ESC P >| ... ESC \
|
|
116
|
+
*/
|
|
117
|
+
function isCompleteDcsSequence(data) {
|
|
118
|
+
if (!data.startsWith(`${ESC}P`)) {
|
|
119
|
+
return "complete";
|
|
120
|
+
}
|
|
121
|
+
// DCS sequences end with ST (ESC \)
|
|
122
|
+
if (data.endsWith(`${ESC}\\`)) {
|
|
123
|
+
return "complete";
|
|
124
|
+
}
|
|
125
|
+
return "incomplete";
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Check if APC (Application Program Command) sequence is complete
|
|
129
|
+
* APC sequences: ESC _ ... ST (where ST is ESC \)
|
|
130
|
+
* Used for Kitty graphics responses like ESC _ G ... ESC \
|
|
131
|
+
*/
|
|
132
|
+
function isCompleteApcSequence(data) {
|
|
133
|
+
if (!data.startsWith(`${ESC}_`)) {
|
|
134
|
+
return "complete";
|
|
135
|
+
}
|
|
136
|
+
// APC sequences end with ST (ESC \)
|
|
137
|
+
if (data.endsWith(`${ESC}\\`)) {
|
|
138
|
+
return "complete";
|
|
139
|
+
}
|
|
140
|
+
return "incomplete";
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Split accumulated buffer into complete sequences
|
|
144
|
+
*/
|
|
145
|
+
function extractCompleteSequences(buffer) {
|
|
146
|
+
const sequences = [];
|
|
147
|
+
let pos = 0;
|
|
148
|
+
while (pos < buffer.length) {
|
|
149
|
+
const remaining = buffer.slice(pos);
|
|
150
|
+
// Try to extract a sequence starting at this position
|
|
151
|
+
if (remaining.startsWith(ESC)) {
|
|
152
|
+
// Find the end of this escape sequence
|
|
153
|
+
let seqEnd = 1;
|
|
154
|
+
while (seqEnd <= remaining.length) {
|
|
155
|
+
const candidate = remaining.slice(0, seqEnd);
|
|
156
|
+
const status = isCompleteSequence(candidate);
|
|
157
|
+
if (status === "complete") {
|
|
158
|
+
sequences.push(candidate);
|
|
159
|
+
pos += seqEnd;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
else if (status === "incomplete") {
|
|
163
|
+
seqEnd++;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Should not happen when starting with ESC
|
|
167
|
+
sequences.push(candidate);
|
|
168
|
+
pos += seqEnd;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (seqEnd > remaining.length) {
|
|
173
|
+
return { sequences, remainder: remaining };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Not an escape sequence - take a single character
|
|
178
|
+
sequences.push(remaining[0]);
|
|
179
|
+
pos++;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { sequences, remainder: "" };
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Buffers stdin input and emits complete sequences via the 'data' event.
|
|
186
|
+
* Handles partial escape sequences that arrive across multiple chunks.
|
|
187
|
+
*/
|
|
188
|
+
export class StdinBuffer extends EventEmitter {
|
|
189
|
+
buffer = "";
|
|
190
|
+
timeout = null;
|
|
191
|
+
timeoutMs;
|
|
192
|
+
pasteMode = false;
|
|
193
|
+
pasteBuffer = "";
|
|
194
|
+
constructor(options = {}) {
|
|
195
|
+
super();
|
|
196
|
+
this.timeoutMs = options.timeout ?? 10;
|
|
197
|
+
}
|
|
198
|
+
process(data) {
|
|
199
|
+
// Clear any pending timeout
|
|
200
|
+
if (this.timeout) {
|
|
201
|
+
clearTimeout(this.timeout);
|
|
202
|
+
this.timeout = null;
|
|
203
|
+
}
|
|
204
|
+
// Handle high-byte conversion (for compatibility with parseKeypress)
|
|
205
|
+
// If buffer has single byte > 127, convert to ESC + (byte - 128)
|
|
206
|
+
let str;
|
|
207
|
+
if (Buffer.isBuffer(data)) {
|
|
208
|
+
if (data.length === 1 && data[0] > 127) {
|
|
209
|
+
const byte = data[0] - 128;
|
|
210
|
+
str = `\x1b${String.fromCharCode(byte)}`;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
str = data.toString();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
str = data;
|
|
218
|
+
}
|
|
219
|
+
if (str.length === 0 && this.buffer.length === 0) {
|
|
220
|
+
this.emit("data", "");
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.buffer += str;
|
|
224
|
+
if (this.pasteMode) {
|
|
225
|
+
this.pasteBuffer += this.buffer;
|
|
226
|
+
this.buffer = "";
|
|
227
|
+
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
228
|
+
if (endIndex !== -1) {
|
|
229
|
+
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
230
|
+
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
231
|
+
this.pasteMode = false;
|
|
232
|
+
this.pasteBuffer = "";
|
|
233
|
+
this.emit("paste", pastedContent);
|
|
234
|
+
if (remaining.length > 0) {
|
|
235
|
+
this.process(remaining);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);
|
|
241
|
+
if (startIndex !== -1) {
|
|
242
|
+
if (startIndex > 0) {
|
|
243
|
+
const beforePaste = this.buffer.slice(0, startIndex);
|
|
244
|
+
const result = extractCompleteSequences(beforePaste);
|
|
245
|
+
for (const sequence of result.sequences) {
|
|
246
|
+
this.emit("data", sequence);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
this.buffer = this.buffer.slice(startIndex + BRACKETED_PASTE_START.length);
|
|
250
|
+
this.pasteMode = true;
|
|
251
|
+
this.pasteBuffer = this.buffer;
|
|
252
|
+
this.buffer = "";
|
|
253
|
+
const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
|
|
254
|
+
if (endIndex !== -1) {
|
|
255
|
+
const pastedContent = this.pasteBuffer.slice(0, endIndex);
|
|
256
|
+
const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
|
|
257
|
+
this.pasteMode = false;
|
|
258
|
+
this.pasteBuffer = "";
|
|
259
|
+
this.emit("paste", pastedContent);
|
|
260
|
+
if (remaining.length > 0) {
|
|
261
|
+
this.process(remaining);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const result = extractCompleteSequences(this.buffer);
|
|
267
|
+
this.buffer = result.remainder;
|
|
268
|
+
for (const sequence of result.sequences) {
|
|
269
|
+
this.emit("data", sequence);
|
|
270
|
+
}
|
|
271
|
+
if (this.buffer.length > 0) {
|
|
272
|
+
this.timeout = setTimeout(() => {
|
|
273
|
+
const flushed = this.flush();
|
|
274
|
+
for (const sequence of flushed) {
|
|
275
|
+
this.emit("data", sequence);
|
|
276
|
+
}
|
|
277
|
+
}, this.timeoutMs);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
flush() {
|
|
281
|
+
if (this.timeout) {
|
|
282
|
+
clearTimeout(this.timeout);
|
|
283
|
+
this.timeout = null;
|
|
284
|
+
}
|
|
285
|
+
if (this.buffer.length === 0) {
|
|
286
|
+
return [];
|
|
287
|
+
}
|
|
288
|
+
const sequences = [this.buffer];
|
|
289
|
+
this.buffer = "";
|
|
290
|
+
return sequences;
|
|
291
|
+
}
|
|
292
|
+
clear() {
|
|
293
|
+
if (this.timeout) {
|
|
294
|
+
clearTimeout(this.timeout);
|
|
295
|
+
this.timeout = null;
|
|
296
|
+
}
|
|
297
|
+
this.buffer = "";
|
|
298
|
+
this.pasteMode = false;
|
|
299
|
+
this.pasteBuffer = "";
|
|
300
|
+
}
|
|
301
|
+
getBuffer() {
|
|
302
|
+
return this.buffer;
|
|
303
|
+
}
|
|
304
|
+
destroy() {
|
|
305
|
+
this.clear();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: ImageProtocol, TerminalCapabilities, CellDimensions, ImageDimensions, ImageLayout
|
|
3
|
+
* [FROM]: No external dependencies
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/terminal-image.ts - terminal image protocol support
|
|
6
|
+
*/
|
|
7
|
+
export type ImageProtocol = "kitty" | "iterm2" | null;
|
|
8
|
+
export interface TerminalCapabilities {
|
|
9
|
+
images: ImageProtocol;
|
|
10
|
+
trueColor: boolean;
|
|
11
|
+
hyperlinks: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface CellDimensions {
|
|
14
|
+
widthPx: number;
|
|
15
|
+
heightPx: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ImageDimensions {
|
|
18
|
+
widthPx: number;
|
|
19
|
+
heightPx: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ImageRenderOptions {
|
|
22
|
+
maxWidthCells?: number;
|
|
23
|
+
maxHeightCells?: number;
|
|
24
|
+
preserveAspectRatio?: boolean;
|
|
25
|
+
/** Kitty image ID. If provided, reuses/replaces existing image with this ID. */
|
|
26
|
+
imageId?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function getCellDimensions(): CellDimensions;
|
|
29
|
+
export declare function setCellDimensions(dims: CellDimensions): void;
|
|
30
|
+
export declare function detectCapabilities(): TerminalCapabilities;
|
|
31
|
+
export declare function getCapabilities(): TerminalCapabilities;
|
|
32
|
+
export declare function resetCapabilitiesCache(): void;
|
|
33
|
+
export declare function isImageLine(line: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Generate a random image ID for Kitty graphics protocol.
|
|
36
|
+
* Uses random IDs to avoid collisions between different module instances
|
|
37
|
+
* (e.g., main app vs extensions).
|
|
38
|
+
*/
|
|
39
|
+
export declare function allocateImageId(): number;
|
|
40
|
+
export declare function encodeKitty(base64Data: string, options?: {
|
|
41
|
+
columns?: number;
|
|
42
|
+
rows?: number;
|
|
43
|
+
imageId?: number;
|
|
44
|
+
}): string;
|
|
45
|
+
/**
|
|
46
|
+
* Delete a Kitty graphics image by ID.
|
|
47
|
+
* Uses uppercase 'I' to also free the image data.
|
|
48
|
+
*/
|
|
49
|
+
export declare function deleteKittyImage(imageId: number): string;
|
|
50
|
+
/**
|
|
51
|
+
* Delete all visible Kitty graphics images.
|
|
52
|
+
* Uses uppercase 'A' to also free the image data.
|
|
53
|
+
*/
|
|
54
|
+
export declare function deleteAllKittyImages(): string;
|
|
55
|
+
export declare function encodeITerm2(base64Data: string, options?: {
|
|
56
|
+
width?: number | string;
|
|
57
|
+
height?: number | string;
|
|
58
|
+
name?: string;
|
|
59
|
+
preserveAspectRatio?: boolean;
|
|
60
|
+
inline?: boolean;
|
|
61
|
+
}): string;
|
|
62
|
+
export declare function calculateImageRows(imageDimensions: ImageDimensions, targetWidthCells: number, cellDimensions?: CellDimensions): number;
|
|
63
|
+
export declare function getPngDimensions(base64Data: string): ImageDimensions | null;
|
|
64
|
+
export declare function getJpegDimensions(base64Data: string): ImageDimensions | null;
|
|
65
|
+
export declare function getGifDimensions(base64Data: string): ImageDimensions | null;
|
|
66
|
+
export declare function getWebpDimensions(base64Data: string): ImageDimensions | null;
|
|
67
|
+
export declare function getImageDimensions(base64Data: string, mimeType: string): ImageDimensions | null;
|
|
68
|
+
export declare function renderImage(base64Data: string, imageDimensions: ImageDimensions, options?: ImageRenderOptions): {
|
|
69
|
+
sequence: string;
|
|
70
|
+
rows: number;
|
|
71
|
+
imageId?: number;
|
|
72
|
+
} | null;
|
|
73
|
+
export declare function imageFallback(mimeType: string, dimensions?: ImageDimensions, filename?: string): string;
|