@cueloop/client 0.1.0-alpha.6 → 0.1.0-alpha.61

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 (161) hide show
  1. package/native/build-pty.sh +51 -0
  2. package/native/build.sh +82 -0
  3. package/native/darwin-arm64/libcuelooppty.dylib +0 -0
  4. package/native/darwin-arm64/libcueloopvt.dylib +0 -0
  5. package/native/src/pty.zig +193 -0
  6. package/native/src/shim.zig +114 -0
  7. package/package.json +37 -33
  8. package/src/App.appearance.test.tsx +51 -0
  9. package/src/App.autoclose.test.tsx +73 -47
  10. package/src/App.diff.test.tsx +169 -22
  11. package/src/App.export.test.tsx +49 -37
  12. package/src/App.plan-review.test.tsx +714 -0
  13. package/src/App.prototype.test.tsx +194 -0
  14. package/src/App.readonly.test.tsx +69 -35
  15. package/src/App.rendering.test.tsx +59 -31
  16. package/src/App.review-panel.test.tsx +143 -0
  17. package/src/App.submit-confirm.test.tsx +229 -0
  18. package/src/App.test.tsx +139 -68
  19. package/src/App.toast.test.tsx +77 -0
  20. package/src/App.tsx +0 -0
  21. package/src/App.walk.test.tsx +299 -0
  22. package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
  23. package/src/app-key-state.ts +61 -0
  24. package/src/app-screens.tsx +270 -0
  25. package/src/app-view-model.ts +307 -0
  26. package/src/attribution.test.ts +31 -0
  27. package/src/attribution.ts +42 -0
  28. package/src/clipboard.test.ts +23 -0
  29. package/src/clipboard.ts +33 -0
  30. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  31. package/src/components/AnnotationCard.stories.tsx +94 -0
  32. package/src/components/AnnotationCard.tsx +250 -0
  33. package/src/components/Breadcrumb.stories.tsx +19 -0
  34. package/src/components/Breadcrumb.tsx +45 -0
  35. package/src/components/CodeBlock.stories.tsx +42 -0
  36. package/src/components/CodeBlock.tsx +84 -0
  37. package/src/components/CompletionOverlay.stories.tsx +23 -0
  38. package/src/components/CompletionOverlay.tsx +60 -0
  39. package/src/components/ConfirmCard.stories.tsx +35 -0
  40. package/src/components/ConfirmCard.tsx +129 -0
  41. package/src/components/ConfirmDialog.stories.tsx +21 -0
  42. package/src/components/ConfirmDialog.tsx +66 -0
  43. package/src/components/DiffSheet.scroll.test.tsx +135 -0
  44. package/src/components/DiffSheet.stories.tsx +78 -0
  45. package/src/components/DiffSheet.syntax.test.tsx +65 -0
  46. package/src/components/DiffSheet.tsx +374 -0
  47. package/src/components/InboxList.stories.tsx +31 -0
  48. package/src/components/InboxList.tsx +64 -0
  49. package/src/components/KeybindsDialog.stories.tsx +31 -0
  50. package/src/components/KeybindsDialog.tsx +59 -0
  51. package/src/components/MarkerPopover.stories.tsx +58 -0
  52. package/src/components/MarkerPopover.tsx +109 -0
  53. package/src/components/MenuBar.stories.tsx +37 -0
  54. package/src/components/MenuBar.tsx +75 -0
  55. package/src/components/PlanSheet.stories.tsx +113 -0
  56. package/src/components/PlanSheet.tsx +422 -0
  57. package/src/components/PromptDialog.stories.tsx +36 -0
  58. package/src/components/PromptDialog.tsx +80 -0
  59. package/src/components/PrototypeSheet.stories.tsx +20 -0
  60. package/src/components/PrototypeSheet.tsx +450 -0
  61. package/src/components/ReviewPanel.stories.tsx +86 -0
  62. package/src/components/ReviewPanel.tsx +103 -0
  63. package/src/components/ReviewRail.stories.tsx +218 -0
  64. package/src/components/ReviewRail.tsx +318 -0
  65. package/src/components/SettingsDialog.stories.tsx +111 -0
  66. package/src/components/SettingsDialog.tsx +147 -0
  67. package/src/components/SettingsRows.stories.tsx +18 -0
  68. package/src/components/SettingsRows.tsx +112 -0
  69. package/src/components/Toast.stories.tsx +12 -0
  70. package/src/components/Toast.tsx +45 -0
  71. package/src/components/WalkWizard.stories.tsx +100 -0
  72. package/src/components/WalkWizard.tsx +152 -0
  73. package/src/components/__snapshots__/stories.test.tsx.snap +1857 -0
  74. package/src/components/agent-launcher.stories.tsx +26 -0
  75. package/src/components/agent-launcher.test.tsx +50 -0
  76. package/src/components/agent-launcher.tsx +149 -0
  77. package/src/components/diff-sheet-layout.test.ts +128 -0
  78. package/src/components/diff-sheet-layout.ts +184 -0
  79. package/src/components/plan-sheet-run-style.ts +90 -0
  80. package/src/components/primitives/Button.stories.tsx +32 -0
  81. package/src/components/primitives/Button.tsx +52 -0
  82. package/src/components/primitives/Card.stories.tsx +25 -0
  83. package/src/components/primitives/Card.tsx +60 -0
  84. package/src/components/primitives/Dialog.stories.tsx +24 -0
  85. package/src/components/primitives/Dialog.tsx +66 -0
  86. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  87. package/src/components/primitives/StatusBar.tsx +23 -0
  88. package/src/components/primitives/Tabs.stories.tsx +29 -0
  89. package/src/components/primitives/Tabs.tsx +102 -0
  90. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  91. package/src/components/primitives/Toolbar.tsx +14 -0
  92. package/src/components/primitives/frame.test.ts +12 -0
  93. package/src/components/primitives/frame.ts +14 -0
  94. package/src/components/quick-actions-editor.stories.tsx +54 -0
  95. package/src/components/quick-actions-editor.tsx +138 -0
  96. package/src/components/stories-app.tsx +124 -0
  97. package/src/components/stories.test.tsx +66 -0
  98. package/src/components/story-fixtures.ts +98 -0
  99. package/src/components/story.ts +75 -0
  100. package/src/components/syntax-highlight.ts +102 -0
  101. package/src/components/terminal-pane.test.tsx +40 -0
  102. package/src/components/terminal-pane.ts +193 -0
  103. package/src/components/theme-context.stories.tsx +46 -0
  104. package/src/components/theme-context.tsx +37 -0
  105. package/src/components/truncate-text.ts +7 -0
  106. package/src/config.test.ts +448 -31
  107. package/src/config.ts +339 -57
  108. package/src/diff-hunk-curate.test.ts +315 -0
  109. package/src/diff-hunk-curate.ts +253 -0
  110. package/src/diff-intraline.test.ts +165 -0
  111. package/src/diff-intraline.ts +146 -0
  112. package/src/diff-syntax.test.ts +96 -0
  113. package/src/diff-syntax.ts +176 -0
  114. package/src/editor.test.ts +149 -0
  115. package/src/editor.ts +135 -9
  116. package/src/ghostty-terminal.test.ts +84 -0
  117. package/src/ghostty-terminal.ts +176 -0
  118. package/src/herdr.test.ts +9 -34
  119. package/src/herdr.ts +17 -21
  120. package/src/index.ts +10 -0
  121. package/src/integrations.test.ts +41 -0
  122. package/src/integrations.ts +32 -0
  123. package/src/intent-dispatch.test.ts +499 -0
  124. package/src/intent-dispatch.ts +585 -0
  125. package/src/key-bindings.test.ts +156 -0
  126. package/src/key-bindings.ts +452 -0
  127. package/src/keymap.test.ts +635 -0
  128. package/src/keymap.ts +404 -0
  129. package/src/kitty-image.test.ts +66 -0
  130. package/src/kitty-image.ts +138 -0
  131. package/src/prototype-browser.test.ts +56 -0
  132. package/src/prototype-browser.ts +289 -0
  133. package/src/pty.test.ts +81 -0
  134. package/src/pty.ts +237 -0
  135. package/src/review-panel.test.ts +113 -0
  136. package/src/review-panel.ts +83 -0
  137. package/src/run.ts +16 -5
  138. package/src/serve.test.ts +25 -9
  139. package/src/serve.ts +19 -8
  140. package/src/session-controller.curate.test.ts +260 -0
  141. package/src/session-controller.share.test.ts +320 -0
  142. package/src/session-controller.ts +993 -0
  143. package/src/share.ts +120 -0
  144. package/src/test-support.test.ts +60 -0
  145. package/src/test-support.ts +197 -0
  146. package/src/theme-presets.test.ts +51 -0
  147. package/src/theme-presets.ts +187 -0
  148. package/src/theme.ts +64 -17
  149. package/src/use-settings-dialog.tsx +275 -0
  150. package/src/version.ts +5 -0
  151. package/src/view-diff.test.ts +22 -8
  152. package/src/view-diff.ts +39 -23
  153. package/src/view-plan.regression.test.ts +60 -0
  154. package/src/view-plan.test.ts +406 -0
  155. package/src/view-plan.ts +554 -0
  156. package/src/walk.test.ts +121 -0
  157. package/src/walk.ts +74 -0
  158. package/src/syntax.test.ts +0 -41
  159. package/src/syntax.ts +0 -88
  160. package/src/view.test.ts +0 -157
  161. package/src/view.ts +0 -0
@@ -0,0 +1,193 @@
1
+ /**
2
+ * An OpenTUI renderable that runs a real child process (a shell, cc, pi, codex)
3
+ * on a PTY and paints its live screen into the box - the terminal-in-the-rail
4
+ * primitive. It wires the forkpty shim (child + tty, ../pty) to a Ghostty VT emulator
5
+ * (ghostty-terminal.ts) and blits the emulator's cell grid every frame via
6
+ * OptimizedBuffer.setCell. Register once with `registerTerminalPane`, then use
7
+ * `<terminalPane command="claude" ... />` in the OpenTUI React tree.
8
+ */
9
+
10
+ import { Renderable, RGBA, createTextAttributes, type RenderContext } from "@opentui/core";
11
+ import type { OptimizedBuffer } from "@opentui/core";
12
+ import type { RenderableOptions } from "@opentui/core";
13
+ import { extend } from "@opentui/react";
14
+ import { spawn, ptyAvailable, type IPty } from "../pty";
15
+ import {
16
+ loadGhosttyTerminals,
17
+ type GhosttyColor,
18
+ type GhosttyTerminal,
19
+ type GhosttyTerminalFactory,
20
+ } from "../ghostty-terminal";
21
+
22
+ /** One shared VT library load; null when this platform ships no prebuilt dylib. */
23
+ let ghosttyFactory: GhosttyTerminalFactory | null | undefined;
24
+
25
+ function factory(): GhosttyTerminalFactory | null {
26
+ if (ghosttyFactory === undefined) ghosttyFactory = loadGhosttyTerminals();
27
+
28
+ return ghosttyFactory;
29
+ }
30
+
31
+ /** Whether the embedded terminal can run here: both native shims ship for this
32
+ * platform (the Ghostty VT renderer and the forkpty PTY). */
33
+ export function embeddedTerminalAvailable(): boolean {
34
+ return factory() !== null && ptyAvailable();
35
+ }
36
+
37
+ /** Props for `<terminalPane>`: the child to run plus its cwd/env and a plan-context seed. */
38
+ export interface TerminalPaneOptions extends RenderableOptions {
39
+ /** The program to run, e.g. "claude" / "pi" / "codex" / a shell. */
40
+ command?: string;
41
+ args?: string[];
42
+ cwd?: string;
43
+ env?: Record<string, string>;
44
+ /** Text left unsubmitted in the child after it starts (plan-context seed). */
45
+ seedText?: string;
46
+ /** Fired when the child process exits. */
47
+ onExit?: (exitCode: number) => void;
48
+ }
49
+
50
+ const encoder = new TextEncoder();
51
+ const DEFAULT_FG = RGBA.fromInts(208, 208, 208, 255);
52
+ const TRANSPARENT = RGBA.fromValues(0, 0, 0, 0);
53
+ /** Glyph color under the block cursor (dark ink on the light cursor block). */
54
+ const CURSOR_INK = RGBA.fromInts(20, 20, 24, 255);
55
+
56
+ /** Runs a PTY child and paints its Ghostty-rendered screen into this box. */
57
+ export class TerminalPaneRenderable extends Renderable {
58
+ private pty: IPty | null = null;
59
+ private vt: GhosttyTerminal | null = null;
60
+ private cols = 0;
61
+ private rows = 0;
62
+ // The seed is held until the child's first output, so it lands in a ready
63
+ // prompt rather than racing the harness's startup (readline/TUI not up yet).
64
+ private pendingSeed: string | undefined;
65
+ private readonly opts: TerminalPaneOptions;
66
+
67
+ constructor(ctx: RenderContext, options: TerminalPaneOptions) {
68
+ super(ctx, options);
69
+ this.opts = options;
70
+ this.focusable = true;
71
+ }
72
+
73
+ /** Start the child + emulator once real layout dimensions are known. */
74
+ private start(cols: number, rows: number): void {
75
+ const terminals = factory();
76
+
77
+ if (!terminals) return;
78
+ const vt = terminals.create(cols, rows);
79
+
80
+ if (!vt) return; // no emulator, no visible screen - do not spawn a blind child
81
+ this.vt = vt;
82
+ this.cols = cols;
83
+ this.rows = rows;
84
+ this.pendingSeed = this.opts.seedText;
85
+ this.pty = spawn(this.opts.command ?? process.env.SHELL ?? "/bin/sh", this.opts.args ?? [], {
86
+ name: "xterm-256color",
87
+ cols,
88
+ rows,
89
+ cwd: this.opts.cwd ?? process.cwd(),
90
+ env: (this.opts.env ?? process.env) as Record<string, string>,
91
+ });
92
+ this.pty.onData((data) => {
93
+ // the shim streams a UTF-8-decoded string (split multibyte is handled); a
94
+ // rare non-UTF-8 byte arrives as U+FFFD - acceptable for agent TUIs.
95
+ this.vt?.write(encoder.encode(data));
96
+ if (this.pendingSeed !== undefined) {
97
+ this.pty?.write(this.pendingSeed);
98
+ this.pendingSeed = undefined;
99
+ }
100
+ this.requestRender();
101
+ });
102
+ this.pty.onExit(({ exitCode }) => this.opts.onExit?.(exitCode));
103
+ }
104
+
105
+ /** Send raw bytes to the child (a key's escape sequence, or pasted text). */
106
+ write(data: string): void {
107
+ this.pty?.write(data);
108
+ }
109
+
110
+ protected onResize(width: number, height: number): void {
111
+ if (width <= 0 || height <= 0) return;
112
+ if (!this.pty) {
113
+ this.start(width, height);
114
+
115
+ return;
116
+ }
117
+ if (width === this.cols && height === this.rows) return;
118
+ this.cols = width;
119
+ this.rows = height;
120
+ this.vt?.resize(width, height);
121
+ this.pty.resize(width, height);
122
+ }
123
+
124
+ protected renderSelf(buffer: OptimizedBuffer): void {
125
+ if (!this.vt) return;
126
+ for (let y = 0; y < this.height; y++) {
127
+ for (let x = 0; x < this.width; x++) {
128
+ const cell = this.vt.readCell(x, y);
129
+
130
+ // Skip an empty normal-width cell; the buffer already starts blank.
131
+ if (cell && cell.width === 0 && cell.codepoint === 0) continue;
132
+ const char = cell && cell.codepoint ? String.fromCodePoint(cell.codepoint) : " ";
133
+ let fg = cell ? resolveColor(cell.fg, DEFAULT_FG) : DEFAULT_FG;
134
+ let bg = cell ? resolveColor(cell.bg, TRANSPARENT) : TRANSPARENT;
135
+
136
+ if (cell?.inverse) [fg, bg] = [bg, fg];
137
+ const attributes = cell
138
+ ? createTextAttributes({
139
+ bold: cell.bold,
140
+ italic: cell.italic,
141
+ underline: cell.underline,
142
+ dim: cell.faint,
143
+ strikethrough: cell.strikethrough,
144
+ })
145
+ : 0;
146
+
147
+ buffer.setCell(this.x + x, this.y + y, char, fg, bg, attributes);
148
+ }
149
+ }
150
+ // cursor is active-area coords; equal to viewport at the bottom (the live
151
+ // typing case). It can drift if the child scrolls the viewport back.
152
+ const cursor = this.vt.readCursor();
153
+
154
+ if (cursor.visible && cursor.x < this.width && cursor.y < this.height) {
155
+ const under = this.vt.readCell(cursor.x, cursor.y);
156
+ const char = under && under.codepoint ? String.fromCodePoint(under.codepoint) : " ";
157
+
158
+ // a block cursor: paint the cell with fg/bg swapped
159
+ buffer.setCell(this.x + cursor.x, this.y + cursor.y, char, CURSOR_INK, DEFAULT_FG, 0);
160
+ }
161
+ }
162
+
163
+ /** Kill the child and free the VT. Idempotent - the detach path calls this
164
+ * directly because the React reconciler removes a child without destroying it. */
165
+ shutdown(): void {
166
+ this.pty?.kill();
167
+ this.vt?.free();
168
+ this.pty = null;
169
+ this.vt = null;
170
+ }
171
+
172
+ protected destroySelf(): void {
173
+ this.shutdown();
174
+ super.destroySelf();
175
+ }
176
+ }
177
+
178
+ /** Map a Ghostty cell color to an OpenTUI RGBA, using `fallback` for the terminal default. */
179
+ function resolveColor(color: GhosttyColor, fallback: RGBA): RGBA {
180
+ if (color.kind === "rgb") return RGBA.fromInts(color.r, color.g, color.b, 255);
181
+ if (color.kind === "palette") return RGBA.fromIndex(color.index);
182
+
183
+ return fallback;
184
+ }
185
+
186
+ let registered = false;
187
+
188
+ /** Register `<terminalPane>` with the OpenTUI React reconciler (idempotent). */
189
+ export function registerTerminalPane(): void {
190
+ if (registered) return;
191
+ registered = true;
192
+ extend({ terminalPane: TerminalPaneRenderable });
193
+ }
@@ -0,0 +1,46 @@
1
+ import React from "react";
2
+ import { DARK, type Theme } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { ThemeProvider } from "./theme-context";
5
+ import { Card } from "./primitives/Card";
6
+
7
+ export const meta: StoryMeta = { title: "theme-context" };
8
+
9
+ /** A high-contrast variant to prove tokens flow through the provider. */
10
+ const HIGH_CONTRAST: Theme = { ...DARK, accent: "#00ffff", elevated: "#000000", border: "#ffffff" };
11
+
12
+ export const ContextDefault: Story = {
13
+ render: () => (
14
+ <Card title=" default dark theme " contentRows={1}>
15
+ <text>no provider needed</text>
16
+ </Card>
17
+ ),
18
+ expectedColors: [DARK.elevated],
19
+ };
20
+
21
+ export const ProviderSwap: Story = {
22
+ render: () => (
23
+ <ThemeProvider theme={HIGH_CONTRAST}>
24
+ <Card title=" provider theme " contentRows={1} borderColor={HIGH_CONTRAST.accent}>
25
+ <text>tokens come from the provider</text>
26
+ </Card>
27
+ </ThemeProvider>
28
+ ),
29
+ expectedColors: ["#00ffff", "#000000"],
30
+ };
31
+
32
+ export const PropOverride: Story = {
33
+ render: () => (
34
+ <ThemeProvider theme={DARK}>
35
+ <Card
36
+ title=" prop-overridden theme "
37
+ contentRows={1}
38
+ theme={HIGH_CONTRAST}
39
+ borderColor={HIGH_CONTRAST.accent}
40
+ >
41
+ <text>the theme prop beats the context</text>
42
+ </Card>
43
+ </ThemeProvider>
44
+ ),
45
+ expectedColors: ["#00ffff"],
46
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Provider theming for the component system. The context default is the
3
+ * built-in dark theme, so embedding a component (or rendering a story) needs
4
+ * no provider at all. One ThemeProvider swap switches the live theme; every
5
+ * component also accepts an optional `theme` prop that overrides the context
6
+ * for explicit control. Components consume named tokens only - a hardcoded
7
+ * color inside components/ is a review rejection.
8
+ */
9
+
10
+ import React, { createContext, useContext } from "react";
11
+ import { DARK, type Theme } from "../theme";
12
+
13
+ const ThemeContext = createContext<Theme>(DARK);
14
+
15
+ export function ThemeProvider({
16
+ theme,
17
+ children,
18
+ }: {
19
+ theme: Theme;
20
+ children: React.ReactNode;
21
+ }): React.ReactNode {
22
+ return <ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>;
23
+ }
24
+
25
+ export function useTheme(): Theme {
26
+ return useContext(ThemeContext);
27
+ }
28
+
29
+ /**
30
+ * Token resolution for a component: the explicit `theme` prop wins over the
31
+ * provider context, which defaults to the built-in dark theme.
32
+ */
33
+ export function useComponentTheme(override?: Theme): Theme {
34
+ const contextTheme = useContext(ThemeContext);
35
+
36
+ return override ?? contextTheme;
37
+ }
@@ -0,0 +1,7 @@
1
+ /** Truncate text to one line of at most maxLength characters, ellipsis-terminated. */
2
+
3
+ export function truncateToSingleLine(value: string, maxLength: number): string {
4
+ const oneLine = value.replace(/\n/g, " ");
5
+
6
+ return oneLine.length > maxLength ? oneLine.slice(0, maxLength - 1) + "…" : oneLine;
7
+ }