@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,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: Box
|
|
3
|
+
* [FROM]: Depends on ../utils.js
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/components/box.ts -
|
|
6
|
+
*/
|
|
7
|
+
import { applyBackgroundToLine, visibleWidth } from "../utils.js";
|
|
8
|
+
/**
|
|
9
|
+
* Box component - a container that applies padding and background to all children
|
|
10
|
+
*/
|
|
11
|
+
export class Box {
|
|
12
|
+
children = [];
|
|
13
|
+
paddingX;
|
|
14
|
+
paddingY;
|
|
15
|
+
bgFn;
|
|
16
|
+
// Cache for rendered output
|
|
17
|
+
cache;
|
|
18
|
+
constructor(paddingX = 1, paddingY = 1, bgFn) {
|
|
19
|
+
this.paddingX = paddingX;
|
|
20
|
+
this.paddingY = paddingY;
|
|
21
|
+
this.bgFn = bgFn;
|
|
22
|
+
}
|
|
23
|
+
addChild(component) {
|
|
24
|
+
this.children.push(component);
|
|
25
|
+
this.invalidateCache();
|
|
26
|
+
}
|
|
27
|
+
removeChild(component) {
|
|
28
|
+
const index = this.children.indexOf(component);
|
|
29
|
+
if (index !== -1) {
|
|
30
|
+
this.children.splice(index, 1);
|
|
31
|
+
this.invalidateCache();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
clear() {
|
|
35
|
+
this.children = [];
|
|
36
|
+
this.invalidateCache();
|
|
37
|
+
}
|
|
38
|
+
setBgFn(bgFn) {
|
|
39
|
+
this.bgFn = bgFn;
|
|
40
|
+
// Don't invalidate here - we'll detect bgFn changes by sampling output
|
|
41
|
+
}
|
|
42
|
+
invalidateCache() {
|
|
43
|
+
this.cache = undefined;
|
|
44
|
+
}
|
|
45
|
+
matchCache(width, childLines, bgSample) {
|
|
46
|
+
const cache = this.cache;
|
|
47
|
+
return (!!cache &&
|
|
48
|
+
cache.width === width &&
|
|
49
|
+
cache.bgSample === bgSample &&
|
|
50
|
+
cache.childLines.length === childLines.length &&
|
|
51
|
+
cache.childLines.every((line, i) => line === childLines[i]));
|
|
52
|
+
}
|
|
53
|
+
invalidate() {
|
|
54
|
+
this.invalidateCache();
|
|
55
|
+
for (const child of this.children) {
|
|
56
|
+
child.invalidate?.();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
render(width) {
|
|
60
|
+
if (this.children.length === 0) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
const contentWidth = Math.max(1, width - this.paddingX * 2);
|
|
64
|
+
const leftPad = " ".repeat(this.paddingX);
|
|
65
|
+
// Render all children
|
|
66
|
+
const childLines = [];
|
|
67
|
+
for (const child of this.children) {
|
|
68
|
+
const lines = child.render(contentWidth);
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
childLines.push(leftPad + line);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (childLines.length === 0) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
// Check if bgFn output changed by sampling
|
|
77
|
+
const bgSample = this.bgFn ? this.bgFn("test") : undefined;
|
|
78
|
+
// Check cache validity
|
|
79
|
+
if (this.matchCache(width, childLines, bgSample)) {
|
|
80
|
+
return this.cache.lines;
|
|
81
|
+
}
|
|
82
|
+
// Apply background and padding
|
|
83
|
+
const result = [];
|
|
84
|
+
// Top padding
|
|
85
|
+
for (let i = 0; i < this.paddingY; i++) {
|
|
86
|
+
result.push(this.applyBg("", width));
|
|
87
|
+
}
|
|
88
|
+
// Content
|
|
89
|
+
for (const line of childLines) {
|
|
90
|
+
result.push(this.applyBg(line, width));
|
|
91
|
+
}
|
|
92
|
+
// Bottom padding
|
|
93
|
+
for (let i = 0; i < this.paddingY; i++) {
|
|
94
|
+
result.push(this.applyBg("", width));
|
|
95
|
+
}
|
|
96
|
+
// Update cache
|
|
97
|
+
this.cache = { childLines, width, bgSample, lines: result };
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
applyBg(line, width) {
|
|
101
|
+
const visLen = visibleWidth(line);
|
|
102
|
+
const padNeeded = Math.max(0, width - visLen);
|
|
103
|
+
const padded = line + " ".repeat(padNeeded);
|
|
104
|
+
if (this.bgFn) {
|
|
105
|
+
return applyBackgroundToLine(padded, width, this.bgFn);
|
|
106
|
+
}
|
|
107
|
+
return padded;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: CancellableLoader
|
|
3
|
+
* [FROM]: Depends on ../keybindings.js, ./loader.js
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/components/cancellable-loader.ts -
|
|
6
|
+
*/
|
|
7
|
+
import { Loader } from "./loader.js";
|
|
8
|
+
/**
|
|
9
|
+
* Loader that can be cancelled with Escape.
|
|
10
|
+
* Extends Loader with an AbortSignal for cancelling async operations.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const loader = new CancellableLoader(tui, cyan, dim, "Working...");
|
|
14
|
+
* loader.onAbort = () => done(null);
|
|
15
|
+
* doWork(loader.signal).then(done);
|
|
16
|
+
*/
|
|
17
|
+
export declare class CancellableLoader extends Loader {
|
|
18
|
+
private abortController;
|
|
19
|
+
/** Called when user presses Escape */
|
|
20
|
+
onAbort?: () => void;
|
|
21
|
+
/** AbortSignal that is aborted when user presses Escape */
|
|
22
|
+
get signal(): AbortSignal;
|
|
23
|
+
/** Whether the loader was aborted */
|
|
24
|
+
get aborted(): boolean;
|
|
25
|
+
handleInput(data: string): void;
|
|
26
|
+
dispose(): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: CancellableLoader
|
|
3
|
+
* [FROM]: Depends on ../keybindings.js, ./loader.js
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/components/cancellable-loader.ts -
|
|
6
|
+
*/
|
|
7
|
+
import { getEditorKeybindings } from "../keybindings.js";
|
|
8
|
+
import { Loader } from "./loader.js";
|
|
9
|
+
/**
|
|
10
|
+
* Loader that can be cancelled with Escape.
|
|
11
|
+
* Extends Loader with an AbortSignal for cancelling async operations.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const loader = new CancellableLoader(tui, cyan, dim, "Working...");
|
|
15
|
+
* loader.onAbort = () => done(null);
|
|
16
|
+
* doWork(loader.signal).then(done);
|
|
17
|
+
*/
|
|
18
|
+
export class CancellableLoader extends Loader {
|
|
19
|
+
abortController = new AbortController();
|
|
20
|
+
/** Called when user presses Escape */
|
|
21
|
+
onAbort;
|
|
22
|
+
/** AbortSignal that is aborted when user presses Escape */
|
|
23
|
+
get signal() {
|
|
24
|
+
return this.abortController.signal;
|
|
25
|
+
}
|
|
26
|
+
/** Whether the loader was aborted */
|
|
27
|
+
get aborted() {
|
|
28
|
+
return this.abortController.signal.aborted;
|
|
29
|
+
}
|
|
30
|
+
handleInput(data) {
|
|
31
|
+
const kb = getEditorKeybindings();
|
|
32
|
+
if (kb.matches(data, "selectCancel")) {
|
|
33
|
+
this.abortController.abort();
|
|
34
|
+
this.onAbort?.();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
dispose() {
|
|
38
|
+
this.stop();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: TextChunk, wordWrapLine, EditorTheme, EditorOptions, Editor
|
|
3
|
+
* [FROM]: Depends on ../keybindings.js, ../keys.js, ../kill-ring.js, ../tui.js, ../undo-stack.js
|
|
4
|
+
* [TO]: Consumed by core/lib/tui/src/index.ts
|
|
5
|
+
* [HERE]: core/lib/tui/src/components/editor.ts -
|
|
6
|
+
*/
|
|
7
|
+
import type { AutocompleteProvider } from "../autocomplete.js";
|
|
8
|
+
import { type Component, type Focusable, type TUI } from "../tui.js";
|
|
9
|
+
import { type SelectListTheme } from "./select-list.js";
|
|
10
|
+
/**
|
|
11
|
+
* Represents a chunk of text for word-wrap layout.
|
|
12
|
+
* Tracks both the text content and its position in the original line.
|
|
13
|
+
*/
|
|
14
|
+
export interface TextChunk {
|
|
15
|
+
text: string;
|
|
16
|
+
startIndex: number;
|
|
17
|
+
endIndex: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Split a line into word-wrapped chunks.
|
|
21
|
+
* Wraps at word boundaries when possible, falling back to character-level
|
|
22
|
+
* wrapping for words longer than the available width.
|
|
23
|
+
*
|
|
24
|
+
* @param line - The text line to wrap
|
|
25
|
+
* @param maxWidth - Maximum visible width per chunk
|
|
26
|
+
* @returns Array of chunks with text and position information
|
|
27
|
+
*/
|
|
28
|
+
export declare function wordWrapLine(line: string, maxWidth: number): TextChunk[];
|
|
29
|
+
export interface EditorTheme {
|
|
30
|
+
borderColor: (str: string) => string;
|
|
31
|
+
selectList: SelectListTheme;
|
|
32
|
+
}
|
|
33
|
+
export interface EditorOptions {
|
|
34
|
+
paddingX?: number;
|
|
35
|
+
autocompleteMaxVisible?: number;
|
|
36
|
+
}
|
|
37
|
+
export declare class Editor implements Component, Focusable {
|
|
38
|
+
private state;
|
|
39
|
+
/** Focusable interface - set by TUI when focus changes */
|
|
40
|
+
focused: boolean;
|
|
41
|
+
protected tui: TUI;
|
|
42
|
+
private theme;
|
|
43
|
+
private paddingX;
|
|
44
|
+
private lastWidth;
|
|
45
|
+
private scrollOffset;
|
|
46
|
+
borderColor: (str: string) => string;
|
|
47
|
+
private autocompleteProvider?;
|
|
48
|
+
private autocompleteList?;
|
|
49
|
+
private autocompleteState;
|
|
50
|
+
private autocompletePrefix;
|
|
51
|
+
private autocompleteMaxVisible;
|
|
52
|
+
private pastes;
|
|
53
|
+
private pasteCounter;
|
|
54
|
+
private pasteBuffer;
|
|
55
|
+
private isInPaste;
|
|
56
|
+
private history;
|
|
57
|
+
private historyIndex;
|
|
58
|
+
private killRing;
|
|
59
|
+
private lastAction;
|
|
60
|
+
private jumpMode;
|
|
61
|
+
private preferredVisualCol;
|
|
62
|
+
private undoStack;
|
|
63
|
+
onSubmit?: (text: string) => void;
|
|
64
|
+
onChange?: (text: string) => void;
|
|
65
|
+
disableSubmit: boolean;
|
|
66
|
+
/** Placeholder text shown when editor is empty */
|
|
67
|
+
placeholder: string;
|
|
68
|
+
constructor(tui: TUI, theme: EditorTheme, options?: EditorOptions);
|
|
69
|
+
getPaddingX(): number;
|
|
70
|
+
setPaddingX(padding: number): void;
|
|
71
|
+
getAutocompleteMaxVisible(): number;
|
|
72
|
+
setAutocompleteMaxVisible(maxVisible: number): void;
|
|
73
|
+
setAutocompleteProvider(provider: AutocompleteProvider): void;
|
|
74
|
+
/**
|
|
75
|
+
* Add a prompt to history for up/down arrow navigation.
|
|
76
|
+
* Called after successful submission.
|
|
77
|
+
*/
|
|
78
|
+
addToHistory(text: string): void;
|
|
79
|
+
private isEditorEmpty;
|
|
80
|
+
private isOnFirstVisualLine;
|
|
81
|
+
/**
|
|
82
|
+
* Public: whether the cursor is on the first visual line (accounts for soft
|
|
83
|
+
* wrapping). Consumers use this to decide whether ↑ should leave the editor
|
|
84
|
+
* (e.g. into an attachments bar above it) rather than move the cursor.
|
|
85
|
+
*/
|
|
86
|
+
isCursorOnFirstVisualLine(): boolean;
|
|
87
|
+
private isOnLastVisualLine;
|
|
88
|
+
private navigateHistory;
|
|
89
|
+
/** Internal setText that doesn't reset history state - used by navigateHistory */
|
|
90
|
+
private setTextInternal;
|
|
91
|
+
invalidate(): void;
|
|
92
|
+
render(width: number): string[];
|
|
93
|
+
handleInput(data: string): void;
|
|
94
|
+
private layoutText;
|
|
95
|
+
getText(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Get text with paste markers expanded to their actual content.
|
|
98
|
+
* Use this when you need the full content (e.g., for external editor).
|
|
99
|
+
*/
|
|
100
|
+
getExpandedText(): string;
|
|
101
|
+
getLines(): string[];
|
|
102
|
+
getCursor(): {
|
|
103
|
+
line: number;
|
|
104
|
+
col: number;
|
|
105
|
+
};
|
|
106
|
+
setText(text: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Insert text at the current cursor position.
|
|
109
|
+
* Used for programmatic insertion (e.g., clipboard image markers).
|
|
110
|
+
* This is atomic for undo - single undo restores entire pre-insert state.
|
|
111
|
+
*/
|
|
112
|
+
insertTextAtCursor(text: string): void;
|
|
113
|
+
/**
|
|
114
|
+
* Internal text insertion at cursor. Handles single and multi-line text.
|
|
115
|
+
* Does not push undo snapshots or trigger autocomplete - caller is responsible.
|
|
116
|
+
* Normalizes line endings and calls onChange once at the end.
|
|
117
|
+
*/
|
|
118
|
+
private insertTextAtCursorInternal;
|
|
119
|
+
private insertCharacter;
|
|
120
|
+
private handlePaste;
|
|
121
|
+
private addNewLine;
|
|
122
|
+
private shouldSubmitOnBackslashEnter;
|
|
123
|
+
private submitValue;
|
|
124
|
+
private handleBackspace;
|
|
125
|
+
/**
|
|
126
|
+
* Set cursor column and clear preferredVisualCol.
|
|
127
|
+
* Use this for all non-vertical cursor movements to reset sticky column behavior.
|
|
128
|
+
*/
|
|
129
|
+
private setCursorCol;
|
|
130
|
+
/**
|
|
131
|
+
* Move cursor to a target visual line, applying sticky column logic.
|
|
132
|
+
* Shared by moveCursor() and pageScroll().
|
|
133
|
+
*/
|
|
134
|
+
private moveToVisualLine;
|
|
135
|
+
/**
|
|
136
|
+
* Compute the target visual column for vertical cursor movement.
|
|
137
|
+
* Implements the sticky column decision table:
|
|
138
|
+
*
|
|
139
|
+
* | P | S | T | U | Scenario | Set Preferred | Move To |
|
|
140
|
+
* |---|---|---|---| ---------------------------------------------------- |---------------|-------------|
|
|
141
|
+
* | 0 | * | 0 | - | Start nav, target fits | null | current |
|
|
142
|
+
* | 0 | * | 1 | - | Start nav, target shorter | current | target end |
|
|
143
|
+
* | 1 | 0 | 0 | 0 | Clamped, target fits preferred | null | preferred |
|
|
144
|
+
* | 1 | 0 | 0 | 1 | Clamped, target longer but still can't fit preferred | keep | target end |
|
|
145
|
+
* | 1 | 0 | 1 | - | Clamped, target even shorter | keep | target end |
|
|
146
|
+
* | 1 | 1 | 0 | - | Rewrapped, target fits current | null | current |
|
|
147
|
+
* | 1 | 1 | 1 | - | Rewrapped, target shorter than current | current | target end |
|
|
148
|
+
*
|
|
149
|
+
* Where:
|
|
150
|
+
* - P = preferred col is set
|
|
151
|
+
* - S = cursor in middle of source line (not clamped to end)
|
|
152
|
+
* - T = target line shorter than current visual col
|
|
153
|
+
* - U = target line shorter than preferred col
|
|
154
|
+
*/
|
|
155
|
+
private computeVerticalMoveColumn;
|
|
156
|
+
private moveToLineStart;
|
|
157
|
+
private moveToLineEnd;
|
|
158
|
+
private deleteToStartOfLine;
|
|
159
|
+
private deleteToEndOfLine;
|
|
160
|
+
private deleteWordBackwards;
|
|
161
|
+
private deleteWordForward;
|
|
162
|
+
private handleForwardDelete;
|
|
163
|
+
/**
|
|
164
|
+
* Build a mapping from visual lines to logical positions.
|
|
165
|
+
* Returns an array where each element represents a visual line with:
|
|
166
|
+
* - logicalLine: index into this.state.lines
|
|
167
|
+
* - startCol: starting column in the logical line
|
|
168
|
+
* - length: length of this visual line segment
|
|
169
|
+
*/
|
|
170
|
+
private buildVisualLineMap;
|
|
171
|
+
/**
|
|
172
|
+
* Find the visual line index for the current cursor position.
|
|
173
|
+
*/
|
|
174
|
+
private findCurrentVisualLine;
|
|
175
|
+
private moveCursor;
|
|
176
|
+
/**
|
|
177
|
+
* Scroll by a page (direction: -1 for up, 1 for down).
|
|
178
|
+
* Moves cursor by the page size while keeping it in bounds.
|
|
179
|
+
*/
|
|
180
|
+
private pageScroll;
|
|
181
|
+
private moveWordBackwards;
|
|
182
|
+
/**
|
|
183
|
+
* Yank (paste) the most recent kill ring entry at cursor position.
|
|
184
|
+
*/
|
|
185
|
+
private yank;
|
|
186
|
+
/**
|
|
187
|
+
* Cycle through kill ring (only works immediately after yank or yank-pop).
|
|
188
|
+
* Replaces the last yanked text with the previous entry in the ring.
|
|
189
|
+
*/
|
|
190
|
+
private yankPop;
|
|
191
|
+
/**
|
|
192
|
+
* Insert text at cursor position (used by yank operations).
|
|
193
|
+
*/
|
|
194
|
+
private insertYankedText;
|
|
195
|
+
/**
|
|
196
|
+
* Delete the previously yanked text (used by yank-pop).
|
|
197
|
+
* The yanked text is derived from killRing[end] since it hasn't been rotated yet.
|
|
198
|
+
*/
|
|
199
|
+
private deleteYankedText;
|
|
200
|
+
private pushUndoSnapshot;
|
|
201
|
+
private undo;
|
|
202
|
+
/**
|
|
203
|
+
* Jump to the first occurrence of a character in the specified direction.
|
|
204
|
+
* Multi-line search. Case-sensitive. Skips the current cursor position.
|
|
205
|
+
*/
|
|
206
|
+
private jumpToChar;
|
|
207
|
+
private moveWordForwards;
|
|
208
|
+
private isSlashMenuAllowed;
|
|
209
|
+
private isAtStartOfMessage;
|
|
210
|
+
private isInSlashCommandContext;
|
|
211
|
+
private tryTriggerAutocomplete;
|
|
212
|
+
private handleTabCompletion;
|
|
213
|
+
private handleSlashCommandCompletion;
|
|
214
|
+
private forceFileAutocomplete;
|
|
215
|
+
private cancelAutocomplete;
|
|
216
|
+
isShowingAutocomplete(): boolean;
|
|
217
|
+
private updateAutocomplete;
|
|
218
|
+
}
|