@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.
Files changed (179) hide show
  1. package/dist/build-meta.json +3 -3
  2. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.d.ts +17 -0
  3. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.js +60 -0
  4. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.d.ts +19 -0
  5. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.js +55 -0
  6. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.d.ts +10 -0
  7. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.js +137 -0
  8. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.d.ts +22 -0
  9. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.js +64 -0
  10. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.d.ts +26 -0
  11. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +913 -0
  12. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.d.ts +9 -0
  13. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.js +32 -0
  14. package/dist/node_modules/@pencil-agent/agent-core/dist/agent.d.ts +215 -0
  15. package/dist/node_modules/@pencil-agent/agent-core/dist/agent.js +522 -0
  16. package/dist/node_modules/@pencil-agent/agent-core/dist/errors.d.ts +62 -0
  17. package/dist/node_modules/@pencil-agent/agent-core/dist/errors.js +146 -0
  18. package/dist/node_modules/@pencil-agent/agent-core/dist/index.d.ts +14 -0
  19. package/dist/node_modules/@pencil-agent/agent-core/dist/index.js +19 -0
  20. package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.d.ts +91 -0
  21. package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.js +279 -0
  22. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.d.ts +15 -0
  23. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +625 -0
  24. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.d.ts +33 -0
  25. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.js +189 -0
  26. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.d.ts +35 -0
  27. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.js +319 -0
  28. package/dist/node_modules/@pencil-agent/agent-core/dist/types.d.ts +417 -0
  29. package/dist/node_modules/@pencil-agent/agent-core/dist/types.js +13 -0
  30. package/dist/node_modules/@pencil-agent/agent-core/package.json +28 -0
  31. package/dist/node_modules/@pencil-agent/ai/dist/api-registry.d.ts +27 -0
  32. package/dist/node_modules/@pencil-agent/ai/dist/api-registry.js +152 -0
  33. package/dist/node_modules/@pencil-agent/ai/dist/cli.d.ts +2 -0
  34. package/dist/node_modules/@pencil-agent/ai/dist/cli.js +121 -0
  35. package/dist/node_modules/@pencil-agent/ai/dist/config-path.d.ts +1 -0
  36. package/dist/node_modules/@pencil-agent/ai/dist/config-path.js +17 -0
  37. package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.d.ts +94 -0
  38. package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.js +218 -0
  39. package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.d.ts +8 -0
  40. package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.js +107 -0
  41. package/dist/node_modules/@pencil-agent/ai/dist/env.d.ts +7 -0
  42. package/dist/node_modules/@pencil-agent/ai/dist/env.js +7 -0
  43. package/dist/node_modules/@pencil-agent/ai/dist/events.d.ts +8 -0
  44. package/dist/node_modules/@pencil-agent/ai/dist/events.js +7 -0
  45. package/dist/node_modules/@pencil-agent/ai/dist/index.d.ts +27 -0
  46. package/dist/node_modules/@pencil-agent/ai/dist/index.js +20 -0
  47. package/dist/node_modules/@pencil-agent/ai/dist/json.d.ts +7 -0
  48. package/dist/node_modules/@pencil-agent/ai/dist/json.js +7 -0
  49. package/dist/node_modules/@pencil-agent/ai/dist/models.d.ts +31 -0
  50. package/dist/node_modules/@pencil-agent/ai/dist/models.generated.d.ts +15159 -0
  51. package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +14928 -0
  52. package/dist/node_modules/@pencil-agent/ai/dist/models.js +60 -0
  53. package/dist/node_modules/@pencil-agent/ai/dist/overflow.d.ts +7 -0
  54. package/dist/node_modules/@pencil-agent/ai/dist/overflow.js +7 -0
  55. package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.d.ts +20 -0
  56. package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.js +606 -0
  57. package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.d.ts +38 -0
  58. package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +737 -0
  59. package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.d.ts +21 -0
  60. package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.js +193 -0
  61. package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.d.ts +13 -0
  62. package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.js +34 -0
  63. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.d.ts +79 -0
  64. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.js +753 -0
  65. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.d.ts +70 -0
  66. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.js +311 -0
  67. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.d.ts +20 -0
  68. package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.js +380 -0
  69. package/dist/node_modules/@pencil-agent/ai/dist/providers/google.d.ts +18 -0
  70. package/dist/node_modules/@pencil-agent/ai/dist/providers/google.js +360 -0
  71. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.d.ts +8 -0
  72. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.js +704 -0
  73. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.d.ts +20 -0
  74. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +870 -0
  75. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.d.ts +22 -0
  76. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.js +432 -0
  77. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.d.ts +19 -0
  78. package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +207 -0
  79. package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.d.ts +8 -0
  80. package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.js +86 -0
  81. package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.d.ts +13 -0
  82. package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.js +40 -0
  83. package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.d.ts +13 -0
  84. package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.js +175 -0
  85. package/dist/node_modules/@pencil-agent/ai/dist/registry.d.ts +8 -0
  86. package/dist/node_modules/@pencil-agent/ai/dist/registry.js +8 -0
  87. package/dist/node_modules/@pencil-agent/ai/dist/schema.d.ts +10 -0
  88. package/dist/node_modules/@pencil-agent/ai/dist/schema.js +9 -0
  89. package/dist/node_modules/@pencil-agent/ai/dist/stream.d.ts +25 -0
  90. package/dist/node_modules/@pencil-agent/ai/dist/stream.js +324 -0
  91. package/dist/node_modules/@pencil-agent/ai/dist/types.d.ts +306 -0
  92. package/dist/node_modules/@pencil-agent/ai/dist/types.js +7 -0
  93. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.d.ts +12 -0
  94. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.js +7 -0
  95. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.d.ts +31 -0
  96. package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.js +98 -0
  97. package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.d.ts +13 -0
  98. package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.js +20 -0
  99. package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.d.ts +14 -0
  100. package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.js +34 -0
  101. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.d.ts +22 -0
  102. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.js +109 -0
  103. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.d.ts +12 -0
  104. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.js +25 -0
  105. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.d.ts +35 -0
  106. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.js +286 -0
  107. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.d.ts +31 -0
  108. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.js +378 -0
  109. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.d.ts +31 -0
  110. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.js +483 -0
  111. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.d.ts +60 -0
  112. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.js +131 -0
  113. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.d.ts +39 -0
  114. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.js +385 -0
  115. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.d.ts +18 -0
  116. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.js +36 -0
  117. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.d.ts +52 -0
  118. package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.js +7 -0
  119. package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.d.ts +57 -0
  120. package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.js +120 -0
  121. package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.d.ts +16 -0
  122. package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.js +20 -0
  123. package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.d.ts +22 -0
  124. package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.js +26 -0
  125. package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.d.ts +23 -0
  126. package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.js +78 -0
  127. package/dist/node_modules/@pencil-agent/ai/package.json +94 -0
  128. package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.d.ts +62 -0
  129. package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.js +624 -0
  130. package/dist/node_modules/@pencil-agent/tui/dist/components/box.d.ts +27 -0
  131. package/dist/node_modules/@pencil-agent/tui/dist/components/box.js +109 -0
  132. package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.d.ts +27 -0
  133. package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.js +40 -0
  134. package/dist/node_modules/@pencil-agent/tui/dist/components/editor.d.ts +218 -0
  135. package/dist/node_modules/@pencil-agent/tui/dist/components/editor.js +1697 -0
  136. package/dist/node_modules/@pencil-agent/tui/dist/components/image.d.ts +33 -0
  137. package/dist/node_modules/@pencil-agent/tui/dist/components/image.js +74 -0
  138. package/dist/node_modules/@pencil-agent/tui/dist/components/input.d.ts +42 -0
  139. package/dist/node_modules/@pencil-agent/tui/dist/components/input.js +438 -0
  140. package/dist/node_modules/@pencil-agent/tui/dist/components/loader.d.ts +26 -0
  141. package/dist/node_modules/@pencil-agent/tui/dist/components/loader.js +54 -0
  142. package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.d.ts +100 -0
  143. package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.js +634 -0
  144. package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.d.ts +37 -0
  145. package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.js +157 -0
  146. package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.d.ts +55 -0
  147. package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.js +190 -0
  148. package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.d.ts +17 -0
  149. package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.js +28 -0
  150. package/dist/node_modules/@pencil-agent/tui/dist/components/text.d.ts +24 -0
  151. package/dist/node_modules/@pencil-agent/tui/dist/components/text.js +94 -0
  152. package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.d.ts +18 -0
  153. package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.js +56 -0
  154. package/dist/node_modules/@pencil-agent/tui/dist/editor-component.d.ts +51 -0
  155. package/dist/node_modules/@pencil-agent/tui/dist/editor-component.js +7 -0
  156. package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.d.ts +32 -0
  157. package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.js +152 -0
  158. package/dist/node_modules/@pencil-agent/tui/dist/index.d.ts +28 -0
  159. package/dist/node_modules/@pencil-agent/tui/dist/index.js +37 -0
  160. package/dist/node_modules/@pencil-agent/tui/dist/keybindings.d.ts +44 -0
  161. package/dist/node_modules/@pencil-agent/tui/dist/keybindings.js +119 -0
  162. package/dist/node_modules/@pencil-agent/tui/dist/keys.d.ts +149 -0
  163. package/dist/node_modules/@pencil-agent/tui/dist/keys.js +948 -0
  164. package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.d.ts +33 -0
  165. package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.js +49 -0
  166. package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.d.ts +38 -0
  167. package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.js +307 -0
  168. package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.d.ts +73 -0
  169. package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.js +287 -0
  170. package/dist/node_modules/@pencil-agent/tui/dist/terminal.d.ts +86 -0
  171. package/dist/node_modules/@pencil-agent/tui/dist/terminal.js +266 -0
  172. package/dist/node_modules/@pencil-agent/tui/dist/tui.d.ts +219 -0
  173. package/dist/node_modules/@pencil-agent/tui/dist/tui.js +1001 -0
  174. package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.d.ts +22 -0
  175. package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.js +30 -0
  176. package/dist/node_modules/@pencil-agent/tui/dist/utils.d.ts +83 -0
  177. package/dist/node_modules/@pencil-agent/tui/dist/utils.js +811 -0
  178. package/dist/node_modules/@pencil-agent/tui/package.json +37 -0
  179. package/package.json +3 -2
@@ -0,0 +1,33 @@
1
+ /**
2
+ * [WHO]: ImageTheme, ImageOptions, Image
3
+ * [FROM]: No external dependencies
4
+ * [TO]: Consumed by core/lib/tui/src/index.ts
5
+ * [HERE]: core/lib/tui/src/components/image.ts -
6
+ */
7
+ import { type ImageDimensions } from "../terminal-image.js";
8
+ import type { Component } from "../tui.js";
9
+ export interface ImageTheme {
10
+ fallbackColor: (str: string) => string;
11
+ }
12
+ export interface ImageOptions {
13
+ maxWidthCells?: number;
14
+ maxHeightCells?: number;
15
+ filename?: string;
16
+ /** Kitty image ID. If provided, reuses this ID (for animations/updates). */
17
+ imageId?: number;
18
+ }
19
+ export declare class Image implements Component {
20
+ private base64Data;
21
+ private mimeType;
22
+ private dimensions;
23
+ private theme;
24
+ private options;
25
+ private imageId?;
26
+ private cachedLines?;
27
+ private cachedWidth?;
28
+ constructor(base64Data: string, mimeType: string, theme: ImageTheme, options?: ImageOptions, dimensions?: ImageDimensions);
29
+ /** Get the Kitty image ID used by this image (if any). */
30
+ getImageId(): number | undefined;
31
+ invalidate(): void;
32
+ render(width: number): string[];
33
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * [WHO]: ImageTheme, ImageOptions, Image
3
+ * [FROM]: No external dependencies
4
+ * [TO]: Consumed by core/lib/tui/src/index.ts
5
+ * [HERE]: core/lib/tui/src/components/image.ts -
6
+ */
7
+ import { getCapabilities, getImageDimensions, imageFallback, renderImage, } from "../terminal-image.js";
8
+ export class Image {
9
+ base64Data;
10
+ mimeType;
11
+ dimensions;
12
+ theme;
13
+ options;
14
+ imageId;
15
+ cachedLines;
16
+ cachedWidth;
17
+ constructor(base64Data, mimeType, theme, options = {}, dimensions) {
18
+ this.base64Data = base64Data;
19
+ this.mimeType = mimeType;
20
+ this.theme = theme;
21
+ this.options = options;
22
+ this.dimensions = dimensions || getImageDimensions(base64Data, mimeType) || { widthPx: 800, heightPx: 600 };
23
+ this.imageId = options.imageId;
24
+ }
25
+ /** Get the Kitty image ID used by this image (if any). */
26
+ getImageId() {
27
+ return this.imageId;
28
+ }
29
+ invalidate() {
30
+ this.cachedLines = undefined;
31
+ this.cachedWidth = undefined;
32
+ }
33
+ render(width) {
34
+ if (this.cachedLines && this.cachedWidth === width) {
35
+ return this.cachedLines;
36
+ }
37
+ const maxWidth = Math.min(width - 2, this.options.maxWidthCells ?? 60);
38
+ const caps = getCapabilities();
39
+ let lines;
40
+ if (caps.images) {
41
+ const result = renderImage(this.base64Data, this.dimensions, {
42
+ maxWidthCells: maxWidth,
43
+ imageId: this.imageId,
44
+ });
45
+ if (result) {
46
+ // Store the image ID for later cleanup
47
+ if (result.imageId) {
48
+ this.imageId = result.imageId;
49
+ }
50
+ // Return `rows` lines so TUI accounts for image height
51
+ // First (rows-1) lines are empty (TUI clears them)
52
+ // Last line: move cursor back up, then output image sequence
53
+ lines = [];
54
+ for (let i = 0; i < result.rows - 1; i++) {
55
+ lines.push("");
56
+ }
57
+ // Move cursor up to first row, then output image
58
+ const moveUp = result.rows > 1 ? `\x1b[${result.rows - 1}A` : "";
59
+ lines.push(moveUp + result.sequence);
60
+ }
61
+ else {
62
+ const fallback = imageFallback(this.mimeType, this.dimensions, this.options.filename);
63
+ lines = [this.theme.fallbackColor(fallback)];
64
+ }
65
+ }
66
+ else {
67
+ const fallback = imageFallback(this.mimeType, this.dimensions, this.options.filename);
68
+ lines = [this.theme.fallbackColor(fallback)];
69
+ }
70
+ this.cachedLines = lines;
71
+ this.cachedWidth = width;
72
+ return lines;
73
+ }
74
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * [WHO]: Input
3
+ * [FROM]: Depends on ../keybindings.js, ../kill-ring.js, ../tui.js, ../undo-stack.js, ../utils.js
4
+ * [TO]: Consumed by core/lib/tui/src/index.ts
5
+ * [HERE]: core/lib/tui/src/components/input.ts -
6
+ */
7
+ import { type Component, type Focusable } from "../tui.js";
8
+ /**
9
+ * Input component - single-line text input with horizontal scrolling
10
+ */
11
+ export declare class Input implements Component, Focusable {
12
+ private value;
13
+ private cursor;
14
+ onSubmit?: (value: string) => void;
15
+ onEscape?: () => void;
16
+ /** Focusable interface - set by TUI when focus changes */
17
+ focused: boolean;
18
+ private pasteBuffer;
19
+ private isInPaste;
20
+ private killRing;
21
+ private lastAction;
22
+ private undoStack;
23
+ getValue(): string;
24
+ setValue(value: string): void;
25
+ handleInput(data: string): void;
26
+ private insertCharacter;
27
+ private handleBackspace;
28
+ private handleForwardDelete;
29
+ private deleteToLineStart;
30
+ private deleteToLineEnd;
31
+ private deleteWordBackwards;
32
+ private deleteWordForward;
33
+ private yank;
34
+ private yankPop;
35
+ private pushUndo;
36
+ private undo;
37
+ private moveWordBackwards;
38
+ private moveWordForwards;
39
+ private handlePaste;
40
+ invalidate(): void;
41
+ render(width: number): string[];
42
+ }
@@ -0,0 +1,438 @@
1
+ /**
2
+ * [WHO]: Input
3
+ * [FROM]: Depends on ../keybindings.js, ../kill-ring.js, ../tui.js, ../undo-stack.js, ../utils.js
4
+ * [TO]: Consumed by core/lib/tui/src/index.ts
5
+ * [HERE]: core/lib/tui/src/components/input.ts -
6
+ */
7
+ import { getEditorKeybindings } from "../keybindings.js";
8
+ import { KillRing } from "../kill-ring.js";
9
+ import { CURSOR_MARKER } from "../tui.js";
10
+ import { UndoStack } from "../undo-stack.js";
11
+ import { getSegmenter, isPunctuationChar, isWhitespaceChar, visibleWidth } from "../utils.js";
12
+ const segmenter = getSegmenter();
13
+ /**
14
+ * Input component - single-line text input with horizontal scrolling
15
+ */
16
+ export class Input {
17
+ value = "";
18
+ cursor = 0; // Cursor position in the value
19
+ onSubmit;
20
+ onEscape;
21
+ /** Focusable interface - set by TUI when focus changes */
22
+ focused = false;
23
+ // Bracketed paste mode buffering
24
+ pasteBuffer = "";
25
+ isInPaste = false;
26
+ // Kill ring for Emacs-style kill/yank operations
27
+ killRing = new KillRing();
28
+ lastAction = null;
29
+ // Undo support
30
+ undoStack = new UndoStack();
31
+ getValue() {
32
+ return this.value;
33
+ }
34
+ setValue(value) {
35
+ this.value = value;
36
+ this.cursor = Math.min(this.cursor, value.length);
37
+ }
38
+ handleInput(data) {
39
+ // Handle bracketed paste mode
40
+ // Start of paste: \x1b[200~
41
+ // End of paste: \x1b[201~
42
+ // Check if we're starting a bracketed paste
43
+ if (data.includes("\x1b[200~")) {
44
+ this.isInPaste = true;
45
+ this.pasteBuffer = "";
46
+ data = data.replace("\x1b[200~", "");
47
+ }
48
+ // If we're in a paste, buffer the data
49
+ if (this.isInPaste) {
50
+ // Check if this chunk contains the end marker
51
+ this.pasteBuffer += data;
52
+ const endIndex = this.pasteBuffer.indexOf("\x1b[201~");
53
+ if (endIndex !== -1) {
54
+ // Extract the pasted content
55
+ const pasteContent = this.pasteBuffer.substring(0, endIndex);
56
+ // Process the complete paste
57
+ this.handlePaste(pasteContent);
58
+ // Reset paste state
59
+ this.isInPaste = false;
60
+ // Handle any remaining input after the paste marker
61
+ const remaining = this.pasteBuffer.substring(endIndex + 6); // 6 = length of \x1b[201~
62
+ this.pasteBuffer = "";
63
+ if (remaining) {
64
+ this.handleInput(remaining);
65
+ }
66
+ }
67
+ return;
68
+ }
69
+ const kb = getEditorKeybindings();
70
+ // Escape/Cancel
71
+ if (kb.matches(data, "selectCancel")) {
72
+ if (this.onEscape)
73
+ this.onEscape();
74
+ return;
75
+ }
76
+ // Undo
77
+ if (kb.matches(data, "undo")) {
78
+ this.undo();
79
+ return;
80
+ }
81
+ // Submit
82
+ if (kb.matches(data, "submit") || data === "\n") {
83
+ if (this.onSubmit)
84
+ this.onSubmit(this.value);
85
+ return;
86
+ }
87
+ // Deletion
88
+ if (kb.matches(data, "deleteCharBackward")) {
89
+ this.handleBackspace();
90
+ return;
91
+ }
92
+ if (kb.matches(data, "deleteCharForward")) {
93
+ this.handleForwardDelete();
94
+ return;
95
+ }
96
+ if (kb.matches(data, "deleteWordBackward")) {
97
+ this.deleteWordBackwards();
98
+ return;
99
+ }
100
+ if (kb.matches(data, "deleteWordForward")) {
101
+ this.deleteWordForward();
102
+ return;
103
+ }
104
+ if (kb.matches(data, "deleteToLineStart")) {
105
+ this.deleteToLineStart();
106
+ return;
107
+ }
108
+ if (kb.matches(data, "deleteToLineEnd")) {
109
+ this.deleteToLineEnd();
110
+ return;
111
+ }
112
+ // Kill ring actions
113
+ if (kb.matches(data, "yank")) {
114
+ this.yank();
115
+ return;
116
+ }
117
+ if (kb.matches(data, "yankPop")) {
118
+ this.yankPop();
119
+ return;
120
+ }
121
+ // Cursor movement
122
+ if (kb.matches(data, "cursorLeft")) {
123
+ this.lastAction = null;
124
+ if (this.cursor > 0) {
125
+ const beforeCursor = this.value.slice(0, this.cursor);
126
+ const graphemes = [...segmenter.segment(beforeCursor)];
127
+ const lastGrapheme = graphemes[graphemes.length - 1];
128
+ this.cursor -= lastGrapheme ? lastGrapheme.segment.length : 1;
129
+ }
130
+ return;
131
+ }
132
+ if (kb.matches(data, "cursorRight")) {
133
+ this.lastAction = null;
134
+ if (this.cursor < this.value.length) {
135
+ const afterCursor = this.value.slice(this.cursor);
136
+ const graphemes = [...segmenter.segment(afterCursor)];
137
+ const firstGrapheme = graphemes[0];
138
+ this.cursor += firstGrapheme ? firstGrapheme.segment.length : 1;
139
+ }
140
+ return;
141
+ }
142
+ if (kb.matches(data, "cursorLineStart")) {
143
+ this.lastAction = null;
144
+ this.cursor = 0;
145
+ return;
146
+ }
147
+ if (kb.matches(data, "cursorLineEnd")) {
148
+ this.lastAction = null;
149
+ this.cursor = this.value.length;
150
+ return;
151
+ }
152
+ if (kb.matches(data, "cursorWordLeft")) {
153
+ this.moveWordBackwards();
154
+ return;
155
+ }
156
+ if (kb.matches(data, "cursorWordRight")) {
157
+ this.moveWordForwards();
158
+ return;
159
+ }
160
+ // Regular character input - accept printable characters including Unicode,
161
+ // but reject control characters (C0: 0x00-0x1F, DEL: 0x7F, C1: 0x80-0x9F)
162
+ const hasControlChars = [...data].some((ch) => {
163
+ const code = ch.charCodeAt(0);
164
+ return code < 32 || code === 0x7f || (code >= 0x80 && code <= 0x9f);
165
+ });
166
+ if (!hasControlChars) {
167
+ this.insertCharacter(data);
168
+ }
169
+ }
170
+ insertCharacter(char) {
171
+ // Undo coalescing: consecutive word chars coalesce into one undo unit
172
+ if (isWhitespaceChar(char) || this.lastAction !== "type-word") {
173
+ this.pushUndo();
174
+ }
175
+ this.lastAction = "type-word";
176
+ this.value = this.value.slice(0, this.cursor) + char + this.value.slice(this.cursor);
177
+ this.cursor += char.length;
178
+ }
179
+ handleBackspace() {
180
+ this.lastAction = null;
181
+ if (this.cursor > 0) {
182
+ this.pushUndo();
183
+ const beforeCursor = this.value.slice(0, this.cursor);
184
+ const graphemes = [...segmenter.segment(beforeCursor)];
185
+ const lastGrapheme = graphemes[graphemes.length - 1];
186
+ const graphemeLength = lastGrapheme ? lastGrapheme.segment.length : 1;
187
+ this.value = this.value.slice(0, this.cursor - graphemeLength) + this.value.slice(this.cursor);
188
+ this.cursor -= graphemeLength;
189
+ }
190
+ }
191
+ handleForwardDelete() {
192
+ this.lastAction = null;
193
+ if (this.cursor < this.value.length) {
194
+ this.pushUndo();
195
+ const afterCursor = this.value.slice(this.cursor);
196
+ const graphemes = [...segmenter.segment(afterCursor)];
197
+ const firstGrapheme = graphemes[0];
198
+ const graphemeLength = firstGrapheme ? firstGrapheme.segment.length : 1;
199
+ this.value = this.value.slice(0, this.cursor) + this.value.slice(this.cursor + graphemeLength);
200
+ }
201
+ }
202
+ deleteToLineStart() {
203
+ if (this.cursor === 0)
204
+ return;
205
+ this.pushUndo();
206
+ const deletedText = this.value.slice(0, this.cursor);
207
+ this.killRing.push(deletedText, { prepend: true, accumulate: this.lastAction === "kill" });
208
+ this.lastAction = "kill";
209
+ this.value = this.value.slice(this.cursor);
210
+ this.cursor = 0;
211
+ }
212
+ deleteToLineEnd() {
213
+ if (this.cursor >= this.value.length)
214
+ return;
215
+ this.pushUndo();
216
+ const deletedText = this.value.slice(this.cursor);
217
+ this.killRing.push(deletedText, { prepend: false, accumulate: this.lastAction === "kill" });
218
+ this.lastAction = "kill";
219
+ this.value = this.value.slice(0, this.cursor);
220
+ }
221
+ deleteWordBackwards() {
222
+ if (this.cursor === 0)
223
+ return;
224
+ // Save lastAction before cursor movement (moveWordBackwards resets it)
225
+ const wasKill = this.lastAction === "kill";
226
+ this.pushUndo();
227
+ const oldCursor = this.cursor;
228
+ this.moveWordBackwards();
229
+ const deleteFrom = this.cursor;
230
+ this.cursor = oldCursor;
231
+ const deletedText = this.value.slice(deleteFrom, this.cursor);
232
+ this.killRing.push(deletedText, { prepend: true, accumulate: wasKill });
233
+ this.lastAction = "kill";
234
+ this.value = this.value.slice(0, deleteFrom) + this.value.slice(this.cursor);
235
+ this.cursor = deleteFrom;
236
+ }
237
+ deleteWordForward() {
238
+ if (this.cursor >= this.value.length)
239
+ return;
240
+ // Save lastAction before cursor movement (moveWordForwards resets it)
241
+ const wasKill = this.lastAction === "kill";
242
+ this.pushUndo();
243
+ const oldCursor = this.cursor;
244
+ this.moveWordForwards();
245
+ const deleteTo = this.cursor;
246
+ this.cursor = oldCursor;
247
+ const deletedText = this.value.slice(this.cursor, deleteTo);
248
+ this.killRing.push(deletedText, { prepend: false, accumulate: wasKill });
249
+ this.lastAction = "kill";
250
+ this.value = this.value.slice(0, this.cursor) + this.value.slice(deleteTo);
251
+ }
252
+ yank() {
253
+ const text = this.killRing.peek();
254
+ if (!text)
255
+ return;
256
+ this.pushUndo();
257
+ this.value = this.value.slice(0, this.cursor) + text + this.value.slice(this.cursor);
258
+ this.cursor += text.length;
259
+ this.lastAction = "yank";
260
+ }
261
+ yankPop() {
262
+ if (this.lastAction !== "yank" || this.killRing.length <= 1)
263
+ return;
264
+ this.pushUndo();
265
+ // Delete the previously yanked text (still at end of ring before rotation)
266
+ const prevText = this.killRing.peek() || "";
267
+ this.value = this.value.slice(0, this.cursor - prevText.length) + this.value.slice(this.cursor);
268
+ this.cursor -= prevText.length;
269
+ // Rotate and insert new entry
270
+ this.killRing.rotate();
271
+ const text = this.killRing.peek() || "";
272
+ this.value = this.value.slice(0, this.cursor) + text + this.value.slice(this.cursor);
273
+ this.cursor += text.length;
274
+ this.lastAction = "yank";
275
+ }
276
+ pushUndo() {
277
+ this.undoStack.push({ value: this.value, cursor: this.cursor });
278
+ }
279
+ undo() {
280
+ const snapshot = this.undoStack.pop();
281
+ if (!snapshot)
282
+ return;
283
+ this.value = snapshot.value;
284
+ this.cursor = snapshot.cursor;
285
+ this.lastAction = null;
286
+ }
287
+ moveWordBackwards() {
288
+ if (this.cursor === 0) {
289
+ return;
290
+ }
291
+ this.lastAction = null;
292
+ const textBeforeCursor = this.value.slice(0, this.cursor);
293
+ const graphemes = [...segmenter.segment(textBeforeCursor)];
294
+ // Skip trailing whitespace
295
+ while (graphemes.length > 0 && isWhitespaceChar(graphemes[graphemes.length - 1]?.segment || "")) {
296
+ this.cursor -= graphemes.pop()?.segment.length || 0;
297
+ }
298
+ if (graphemes.length > 0) {
299
+ const lastGrapheme = graphemes[graphemes.length - 1]?.segment || "";
300
+ if (isPunctuationChar(lastGrapheme)) {
301
+ // Skip punctuation run
302
+ while (graphemes.length > 0 && isPunctuationChar(graphemes[graphemes.length - 1]?.segment || "")) {
303
+ this.cursor -= graphemes.pop()?.segment.length || 0;
304
+ }
305
+ }
306
+ else {
307
+ // Skip word run
308
+ while (graphemes.length > 0 &&
309
+ !isWhitespaceChar(graphemes[graphemes.length - 1]?.segment || "") &&
310
+ !isPunctuationChar(graphemes[graphemes.length - 1]?.segment || "")) {
311
+ this.cursor -= graphemes.pop()?.segment.length || 0;
312
+ }
313
+ }
314
+ }
315
+ }
316
+ moveWordForwards() {
317
+ if (this.cursor >= this.value.length) {
318
+ return;
319
+ }
320
+ this.lastAction = null;
321
+ const textAfterCursor = this.value.slice(this.cursor);
322
+ const segments = segmenter.segment(textAfterCursor);
323
+ const iterator = segments[Symbol.iterator]();
324
+ let next = iterator.next();
325
+ // Skip leading whitespace
326
+ while (!next.done && isWhitespaceChar(next.value.segment)) {
327
+ this.cursor += next.value.segment.length;
328
+ next = iterator.next();
329
+ }
330
+ if (!next.done) {
331
+ const firstGrapheme = next.value.segment;
332
+ if (isPunctuationChar(firstGrapheme)) {
333
+ // Skip punctuation run
334
+ while (!next.done && isPunctuationChar(next.value.segment)) {
335
+ this.cursor += next.value.segment.length;
336
+ next = iterator.next();
337
+ }
338
+ }
339
+ else {
340
+ // Skip word run
341
+ while (!next.done && !isWhitespaceChar(next.value.segment) && !isPunctuationChar(next.value.segment)) {
342
+ this.cursor += next.value.segment.length;
343
+ next = iterator.next();
344
+ }
345
+ }
346
+ }
347
+ }
348
+ handlePaste(pastedText) {
349
+ this.lastAction = null;
350
+ this.pushUndo();
351
+ // Clean the pasted text - remove newlines and carriage returns
352
+ const cleanText = pastedText.replace(/\r\n/g, "").replace(/\r/g, "").replace(/\n/g, "");
353
+ // Insert at cursor position
354
+ this.value = this.value.slice(0, this.cursor) + cleanText + this.value.slice(this.cursor);
355
+ this.cursor += cleanText.length;
356
+ }
357
+ invalidate() {
358
+ // No cached state to invalidate currently
359
+ }
360
+ render(width) {
361
+ // Calculate visible window
362
+ const prompt = "> ";
363
+ const availableWidth = width - prompt.length;
364
+ if (availableWidth <= 0) {
365
+ return [prompt];
366
+ }
367
+ let visibleText = "";
368
+ let cursorDisplay = this.cursor;
369
+ if (this.value.length < availableWidth) {
370
+ // Everything fits (leave room for cursor at end)
371
+ visibleText = this.value;
372
+ }
373
+ else {
374
+ // Need horizontal scrolling
375
+ // Reserve one character for cursor if it's at the end
376
+ const scrollWidth = this.cursor === this.value.length ? availableWidth - 1 : availableWidth;
377
+ const halfWidth = Math.floor(scrollWidth / 2);
378
+ const findValidStart = (start) => {
379
+ while (start < this.value.length) {
380
+ const charCode = this.value.charCodeAt(start);
381
+ // this is low surrogate, not a valid start
382
+ if (charCode >= 0xdc00 && charCode < 0xe000) {
383
+ start++;
384
+ continue;
385
+ }
386
+ break;
387
+ }
388
+ return start;
389
+ };
390
+ const findValidEnd = (end) => {
391
+ while (end > 0) {
392
+ const charCode = this.value.charCodeAt(end - 1);
393
+ // this is high surrogate, might be split.
394
+ if (charCode >= 0xd800 && charCode < 0xdc00) {
395
+ end--;
396
+ continue;
397
+ }
398
+ break;
399
+ }
400
+ return end;
401
+ };
402
+ if (this.cursor < halfWidth) {
403
+ // Cursor near start
404
+ visibleText = this.value.slice(0, findValidEnd(scrollWidth));
405
+ cursorDisplay = this.cursor;
406
+ }
407
+ else if (this.cursor > this.value.length - halfWidth) {
408
+ // Cursor near end
409
+ const start = findValidStart(this.value.length - scrollWidth);
410
+ visibleText = this.value.slice(start);
411
+ cursorDisplay = this.cursor - start;
412
+ }
413
+ else {
414
+ // Cursor in middle
415
+ const start = findValidStart(this.cursor - halfWidth);
416
+ visibleText = this.value.slice(start, findValidEnd(start + scrollWidth));
417
+ cursorDisplay = halfWidth;
418
+ }
419
+ }
420
+ // Build line with fake cursor
421
+ // Insert cursor character at cursor position
422
+ const graphemes = [...segmenter.segment(visibleText.slice(cursorDisplay))];
423
+ const cursorGrapheme = graphemes[0];
424
+ const beforeCursor = visibleText.slice(0, cursorDisplay);
425
+ const atCursor = cursorGrapheme?.segment ?? " "; // Character at cursor, or space if at end
426
+ const afterCursor = visibleText.slice(cursorDisplay + atCursor.length);
427
+ // Hardware cursor marker (zero-width, emitted before fake cursor for IME positioning)
428
+ const marker = this.focused ? CURSOR_MARKER : "";
429
+ // Use inverse video to show cursor
430
+ const cursorChar = `\x1b[7m${atCursor}\x1b[27m`; // ESC[7m = reverse video, ESC[27m = normal
431
+ const textWithCursor = beforeCursor + marker + cursorChar + afterCursor;
432
+ // Calculate visual width
433
+ const visualLength = visibleWidth(textWithCursor);
434
+ const padding = " ".repeat(Math.max(0, availableWidth - visualLength));
435
+ const line = prompt + textWithCursor + padding;
436
+ return [line];
437
+ }
438
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * [WHO]: Loader
3
+ * [FROM]: Depends on ./text.js
4
+ * [TO]: Consumed by core/lib/tui/src/index.ts
5
+ * [HERE]: core/lib/tui/src/components/loader.ts -
6
+ */
7
+ import type { TUI } from "../tui.js";
8
+ import { Text } from "./text.js";
9
+ /**
10
+ * Loader component that updates every 80ms with spinning animation
11
+ */
12
+ export declare class Loader extends Text {
13
+ private spinnerColorFn;
14
+ private messageColorFn;
15
+ private message;
16
+ private frames;
17
+ private currentFrame;
18
+ private intervalId;
19
+ private ui;
20
+ constructor(ui: TUI, spinnerColorFn: (str: string) => string, messageColorFn: (str: string) => string, message?: string);
21
+ render(width: number): string[];
22
+ start(): void;
23
+ stop(): void;
24
+ setMessage(message: string): void;
25
+ private updateDisplay;
26
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * [WHO]: Loader
3
+ * [FROM]: Depends on ./text.js
4
+ * [TO]: Consumed by core/lib/tui/src/index.ts
5
+ * [HERE]: core/lib/tui/src/components/loader.ts -
6
+ */
7
+ import { Text } from "./text.js";
8
+ /**
9
+ * Loader component that updates every 80ms with spinning animation
10
+ */
11
+ export class Loader extends Text {
12
+ spinnerColorFn;
13
+ messageColorFn;
14
+ message;
15
+ frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
16
+ currentFrame = 0;
17
+ intervalId = null;
18
+ ui = null;
19
+ constructor(ui, spinnerColorFn, messageColorFn, message = "Loading...") {
20
+ super("", 1, 0);
21
+ this.spinnerColorFn = spinnerColorFn;
22
+ this.messageColorFn = messageColorFn;
23
+ this.message = message;
24
+ this.ui = ui;
25
+ this.start();
26
+ }
27
+ render(width) {
28
+ return ["", ...super.render(width)];
29
+ }
30
+ start() {
31
+ this.updateDisplay();
32
+ this.intervalId = setInterval(() => {
33
+ this.currentFrame = (this.currentFrame + 1) % this.frames.length;
34
+ this.updateDisplay();
35
+ }, 80);
36
+ }
37
+ stop() {
38
+ if (this.intervalId) {
39
+ clearInterval(this.intervalId);
40
+ this.intervalId = null;
41
+ }
42
+ }
43
+ setMessage(message) {
44
+ this.message = message;
45
+ this.updateDisplay();
46
+ }
47
+ updateDisplay() {
48
+ const frame = this.frames[this.currentFrame];
49
+ this.setText(`${this.spinnerColorFn(frame)} ${this.messageColorFn(this.message)}`);
50
+ if (this.ui) {
51
+ this.ui.requestRender();
52
+ }
53
+ }
54
+ }