@cueloop/client 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (92) hide show
  1. package/package.json +17 -11
  2. package/src/App.autoclose.test.tsx +109 -0
  3. package/src/App.diff.test.tsx +5 -18
  4. package/src/App.export.test.tsx +8 -13
  5. package/src/App.plan-review.test.tsx +293 -0
  6. package/src/App.readonly.test.tsx +6 -21
  7. package/src/App.rendering.test.tsx +104 -0
  8. package/src/App.review-panel.test.tsx +97 -0
  9. package/src/App.submit-confirm.test.tsx +165 -0
  10. package/src/App.test.tsx +20 -58
  11. package/src/App.tsx +0 -0
  12. package/src/App.walk.test.tsx +208 -0
  13. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  14. package/src/components/AnnotationCard.stories.tsx +75 -0
  15. package/src/components/AnnotationCard.tsx +189 -0
  16. package/src/components/Breadcrumb.stories.tsx +19 -0
  17. package/src/components/Breadcrumb.tsx +38 -0
  18. package/src/components/CodeBlock.stories.tsx +25 -0
  19. package/src/components/CodeBlock.tsx +68 -0
  20. package/src/components/CompletionOverlay.stories.tsx +23 -0
  21. package/src/components/CompletionOverlay.tsx +49 -0
  22. package/src/components/ComposeBar.stories.tsx +18 -0
  23. package/src/components/ComposeBar.tsx +54 -0
  24. package/src/components/ConfirmCard.stories.tsx +37 -0
  25. package/src/components/ConfirmCard.tsx +117 -0
  26. package/src/components/DiffSheet.stories.tsx +44 -0
  27. package/src/components/DiffSheet.tsx +243 -0
  28. package/src/components/InboxList.stories.tsx +18 -0
  29. package/src/components/InboxList.tsx +42 -0
  30. package/src/components/PlanSheet.stories.tsx +81 -0
  31. package/src/components/PlanSheet.tsx +309 -0
  32. package/src/components/ReviewPanel.stories.tsx +86 -0
  33. package/src/components/ReviewPanel.tsx +116 -0
  34. package/src/components/ReviewRail.stories.tsx +103 -0
  35. package/src/components/ReviewRail.tsx +171 -0
  36. package/src/components/SettingsDialog.stories.tsx +63 -0
  37. package/src/components/SettingsDialog.tsx +132 -0
  38. package/src/components/SettingsRows.stories.tsx +18 -0
  39. package/src/components/SettingsRows.tsx +92 -0
  40. package/src/components/WalkWizard.stories.tsx +89 -0
  41. package/src/components/WalkWizard.tsx +146 -0
  42. package/src/components/__snapshots__/stories.test.tsx.snap +1459 -0
  43. package/src/components/primitives/Button.stories.tsx +32 -0
  44. package/src/components/primitives/Button.tsx +44 -0
  45. package/src/components/primitives/Card.stories.tsx +25 -0
  46. package/src/components/primitives/Card.tsx +59 -0
  47. package/src/components/primitives/Dialog.stories.tsx +24 -0
  48. package/src/components/primitives/Dialog.tsx +53 -0
  49. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  50. package/src/components/primitives/StatusBar.tsx +22 -0
  51. package/src/components/primitives/Tabs.stories.tsx +29 -0
  52. package/src/components/primitives/Tabs.tsx +97 -0
  53. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  54. package/src/components/primitives/Toolbar.tsx +14 -0
  55. package/src/components/primitives/frame.test.ts +12 -0
  56. package/src/components/primitives/frame.ts +14 -0
  57. package/src/components/stories-app.tsx +95 -0
  58. package/src/components/stories.test.tsx +51 -0
  59. package/src/components/story-fixtures.ts +90 -0
  60. package/src/components/story.ts +66 -0
  61. package/src/components/syntax-highlight.ts +57 -0
  62. package/src/components/theme-context.stories.tsx +41 -0
  63. package/src/components/theme-context.tsx +30 -0
  64. package/src/components/truncate-text.ts +6 -0
  65. package/src/config.test.ts +105 -30
  66. package/src/config.ts +91 -16
  67. package/src/editor.test.ts +110 -0
  68. package/src/editor.ts +101 -13
  69. package/src/herdr.test.ts +37 -0
  70. package/src/herdr.ts +21 -0
  71. package/src/integrations.test.ts +29 -0
  72. package/src/integrations.ts +28 -0
  73. package/src/key-bindings.test.ts +120 -0
  74. package/src/key-bindings.ts +353 -0
  75. package/src/keymap.test.ts +347 -0
  76. package/src/keymap.ts +229 -0
  77. package/src/review-panel.test.ts +111 -0
  78. package/src/review-panel.ts +76 -0
  79. package/src/run.ts +9 -5
  80. package/src/serve.test.ts +6 -6
  81. package/src/serve.ts +7 -7
  82. package/src/session-controller.ts +512 -0
  83. package/src/test-support.ts +87 -0
  84. package/src/theme.ts +23 -1
  85. package/src/view-diff.test.ts +8 -8
  86. package/src/view-diff.ts +22 -22
  87. package/src/view-plan.test.ts +179 -0
  88. package/src/view-plan.ts +362 -0
  89. package/src/walk.test.ts +110 -0
  90. package/src/walk.ts +65 -0
  91. package/src/view.test.ts +0 -157
  92. package/src/view.ts +0 -0
@@ -0,0 +1,111 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import {
3
+ REVIEW_DEFAULT_WIDTH,
4
+ REVIEW_MAX_WIDTH,
5
+ REVIEW_MIN_WIDTH,
6
+ REVIEW_PLAN_MIN_WIDTH,
7
+ REVIEW_RESIZE_STEP,
8
+ clampWidth,
9
+ cycleReviewPanelMode,
10
+ maxWidthForTerminal,
11
+ resolveReviewWidth,
12
+ reviewRowsToDivider,
13
+ toggleReviewPanelMode,
14
+ widthFromMouseColumn,
15
+ } from "./review-panel";
16
+
17
+ describe("clampWidth", () => {
18
+ test("keeps a width inside the bounds untouched", () => {
19
+ expect(clampWidth(REVIEW_DEFAULT_WIDTH)).toBe(REVIEW_DEFAULT_WIDTH);
20
+ });
21
+
22
+ test("clamps below the minimum and above the maximum", () => {
23
+ expect(clampWidth(REVIEW_MIN_WIDTH - 10)).toBe(REVIEW_MIN_WIDTH);
24
+ expect(clampWidth(REVIEW_MAX_WIDTH + 10)).toBe(REVIEW_MAX_WIDTH);
25
+ });
26
+
27
+ test("rounds a fractional column to a whole one", () => {
28
+ expect(clampWidth(30.7)).toBe(31);
29
+ });
30
+
31
+ test("honors explicit bounds", () => {
32
+ expect(clampWidth(100, 10, 20)).toBe(20);
33
+ expect(clampWidth(5, 10, 20)).toBe(10);
34
+ });
35
+ });
36
+
37
+ describe("cycleReviewPanelMode", () => {
38
+ test("cycles expanded -> compact -> hidden -> expanded", () => {
39
+ expect(cycleReviewPanelMode("expanded")).toBe("compact");
40
+ expect(cycleReviewPanelMode("compact")).toBe("hidden");
41
+ expect(cycleReviewPanelMode("hidden")).toBe("expanded");
42
+ });
43
+ });
44
+
45
+ describe("toggleReviewPanelMode", () => {
46
+ test("the chevron toggles only between expanded and compact, never hidden", () => {
47
+ expect(toggleReviewPanelMode("expanded")).toBe("compact");
48
+ expect(toggleReviewPanelMode("compact")).toBe("expanded");
49
+ // a hidden panel has no chevron; a stray toggle still opens it
50
+ expect(toggleReviewPanelMode("hidden")).toBe("expanded");
51
+ });
52
+ });
53
+
54
+ describe("widthFromMouseColumn", () => {
55
+ test("measures the rail from the mouse column to the right edge", () => {
56
+ // divider dragged to column 80 of a 120-wide terminal -> a 40-col rail
57
+ expect(widthFromMouseColumn(80, 120)).toBe(40);
58
+ });
59
+
60
+ test("clamps the dragged width to the bounds", () => {
61
+ expect(widthFromMouseColumn(0, 120)).toBe(REVIEW_MAX_WIDTH);
62
+ expect(widthFromMouseColumn(119, 120)).toBe(REVIEW_MIN_WIDTH);
63
+ });
64
+
65
+ test("cannot drag the rail wide enough to starve the plan on a narrow terminal", () => {
66
+ // dragging to the far left edge of a 60-col terminal still leaves the plan its minimum
67
+ expect(widthFromMouseColumn(0, 60)).toBe(60 - REVIEW_PLAN_MIN_WIDTH - 1);
68
+ });
69
+
70
+ test("the resize step widens and narrows within the clamp", () => {
71
+ expect(clampWidth(REVIEW_DEFAULT_WIDTH + REVIEW_RESIZE_STEP)).toBe(REVIEW_DEFAULT_WIDTH + REVIEW_RESIZE_STEP);
72
+ expect(clampWidth(REVIEW_MIN_WIDTH - REVIEW_RESIZE_STEP)).toBe(REVIEW_MIN_WIDTH);
73
+ });
74
+ });
75
+
76
+ describe("maxWidthForTerminal", () => {
77
+ test("allows the full rail on a wide terminal", () => {
78
+ expect(maxWidthForTerminal(120)).toBe(REVIEW_MAX_WIDTH);
79
+ });
80
+
81
+ test("reserves the plan its minimum on a narrow terminal", () => {
82
+ // 60-col terminal: 30 for the plan and 1 for the divider leaves 29 for the rail
83
+ expect(maxWidthForTerminal(60)).toBe(60 - REVIEW_PLAN_MIN_WIDTH - 1);
84
+ });
85
+
86
+ test("never drops below the rail minimum, however narrow the terminal", () => {
87
+ expect(maxWidthForTerminal(40)).toBe(REVIEW_MIN_WIDTH);
88
+ });
89
+ });
90
+
91
+ describe("resolveReviewWidth", () => {
92
+ test("leaves a width that already fits untouched", () => {
93
+ expect(resolveReviewWidth(REVIEW_DEFAULT_WIDTH, 120)).toBe(REVIEW_DEFAULT_WIDTH);
94
+ });
95
+
96
+ test("shrinks a wide persisted width so the plan keeps its room", () => {
97
+ // a saved 50-col rail on a 60-col terminal would leave the plan 9 cols; clamp it back
98
+ expect(resolveReviewWidth(REVIEW_MAX_WIDTH, 60)).toBe(60 - REVIEW_PLAN_MIN_WIDTH - 1);
99
+ });
100
+ });
101
+
102
+ describe("reviewRowsToDivider", () => {
103
+ test("builds one vertical glyph per row", () => {
104
+ expect(reviewRowsToDivider(3)).toBe("│\n│\n│");
105
+ });
106
+
107
+ test("never collapses to an empty column", () => {
108
+ expect(reviewRowsToDivider(0)).toBe("│");
109
+ expect(reviewRowsToDivider(-4)).toBe("│");
110
+ });
111
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Pure geometry and state for the resizable review panel. The panel shows the
3
+ * review rail in one of three modes and the expanded rail resizes within a
4
+ * clamp; App owns the React state and the mouse wiring, this module owns the
5
+ * arithmetic so the layout math stays unit-tested and out of the JSX. Bounds
6
+ * and the compact width carry over verbatim from the approved prototype.
7
+ */
8
+
9
+ /** Expanded (full rail), compact (count + dots strip), or hidden (nothing). */
10
+ export type ReviewPanelMode = "expanded" | "compact" | "hidden";
11
+
12
+ /** Expanded-rail width bounds, in terminal columns. */
13
+ export const REVIEW_MIN_WIDTH = 24;
14
+ export const REVIEW_MAX_WIDTH = 50;
15
+ export const REVIEW_DEFAULT_WIDTH = 34;
16
+ /**
17
+ * Columns the plan/diff column keeps for itself: the expanded rail yields past
18
+ * this so a narrow terminal (or a wide persisted width) can never crowd the
19
+ * plan out to nothing - the whole reason the panel is resizable. On terminals
20
+ * wide enough for the full 50-col rail this bound never binds.
21
+ */
22
+ export const REVIEW_PLAN_MIN_WIDTH = 30;
23
+ /** The compact strip is a fixed narrow column: count on top, one dot per card. */
24
+ export const REVIEW_COMPACT_WIDTH = 6;
25
+ /** Keyboard resize step, in columns, for the widen/narrow keys. */
26
+ export const REVIEW_RESIZE_STEP = 2;
27
+
28
+ /** Round a desired width to a whole column and clamp it to the bounds. */
29
+ export function clampWidth(desiredWidth: number, min = REVIEW_MIN_WIDTH, max = REVIEW_MAX_WIDTH): number {
30
+ return Math.max(min, Math.min(max, Math.round(desiredWidth)));
31
+ }
32
+
33
+ /**
34
+ * The widest the expanded rail may be on a given terminal, reserving the plan
35
+ * its minimum and one column for the divider. Never drops below REVIEW_MIN_WIDTH
36
+ * (an extremely narrow terminal is the auto-collapse case, handled elsewhere).
37
+ */
38
+ export function maxWidthForTerminal(terminalWidth: number): number {
39
+ return Math.max(REVIEW_MIN_WIDTH, Math.min(REVIEW_MAX_WIDTH, terminalWidth - REVIEW_PLAN_MIN_WIDTH - 1));
40
+ }
41
+
42
+ /** Clamp a desired rail width to the bounds AND the terminal, so the plan keeps its room. */
43
+ export function resolveReviewWidth(desiredWidth: number, terminalWidth: number): number {
44
+ return clampWidth(desiredWidth, REVIEW_MIN_WIDTH, maxWidthForTerminal(terminalWidth));
45
+ }
46
+
47
+ /** The keybinding cycle: expanded -> compact -> hidden -> expanded. */
48
+ export function cycleReviewPanelMode(mode: ReviewPanelMode): ReviewPanelMode {
49
+ return mode === "expanded" ? "compact" : mode === "compact" ? "hidden" : "expanded";
50
+ }
51
+
52
+ /**
53
+ * The clickable chevron toggles only between expanded and compact - hidden is
54
+ * reachable by keybinding alone, so it never leaves a leftover tab behind. A
55
+ * toggle from hidden still opens the panel rather than doing nothing.
56
+ */
57
+ export function toggleReviewPanelMode(mode: ReviewPanelMode): ReviewPanelMode {
58
+ return mode === "expanded" ? "compact" : "expanded";
59
+ }
60
+
61
+ /**
62
+ * Rail width from an absolute mouse column while dragging the divider: the rail
63
+ * spans from the mouse column to the terminal's right edge, then clamps.
64
+ */
65
+ export function widthFromMouseColumn(mouseColumn: number, terminalWidth: number): number {
66
+ return resolveReviewWidth(terminalWidth - mouseColumn, terminalWidth);
67
+ }
68
+
69
+ /**
70
+ * The divider is a single-column stack of vertical glyphs (a text block, not a
71
+ * bordered box - a one-column box with a border renders a full box). One glyph
72
+ * per row, at least one so the column never collapses.
73
+ */
74
+ export function reviewRowsToDivider(rows: number): string {
75
+ return Array.from({ length: Math.max(1, rows) }, () => "│").join("\n");
76
+ }
package/src/run.ts CHANGED
@@ -10,17 +10,21 @@ export interface RunClientOptions {
10
10
  home?: string;
11
11
  }
12
12
 
13
- export async function runClient(opts: RunClientOptions): Promise<number> {
14
- const renderer = await createCliRenderer();
13
+ export async function runClient(options: RunClientOptions): Promise<number> {
14
+ // mouse movement reporting makes multiplexers forward drags to the app,
15
+ // so the renderer's native selection is the drag driver
16
+ const renderer = await createCliRenderer({ enableMouseMovement: true });
15
17
  return new Promise<number>((resolve) => {
16
18
  createRoot(renderer).render(
17
19
  React.createElement(App, {
18
- home: opts.home,
19
- sessionId: opts.sessionId,
20
+ home: options.home,
21
+ sessionId: options.sessionId,
20
22
  onExit: (code: number) => {
21
23
  renderer.destroy();
22
24
  resolve(code);
23
- process.exit(code);
25
+ // one microtask between destroy and exit lets the renderer flush
26
+ // its terminal-restore sequences before the process dies
27
+ queueMicrotask(() => process.exit(code));
24
28
  },
25
29
  }),
26
30
  );
package/src/serve.test.ts CHANGED
@@ -38,7 +38,7 @@ afterEach(async () => {
38
38
  });
39
39
 
40
40
  /** Connect, open a PTY shell, resolve with the bytes seen until `until` matches. */
41
- function sshCapture(port: number, until: (s: string) => boolean, timeoutMs = 8000): Promise<string> {
41
+ function sshCapture(port: number, until: (frame: string) => boolean, timeoutMs = 8000): Promise<string> {
42
42
  return new Promise((resolve, reject) => {
43
43
  const conn = new Client();
44
44
  let out = "";
@@ -55,8 +55,8 @@ function sshCapture(port: number, until: (s: string) => boolean, timeoutMs = 800
55
55
  .on("ready", () => {
56
56
  conn.shell({ term: "xterm-256color", cols: 100, rows: 30 }, (err, stream) => {
57
57
  if (err) return finish(err);
58
- stream.on("data", (d: Buffer) => {
59
- out += d.toString("utf8");
58
+ stream.on("data", (chunk: Buffer) => {
59
+ out += chunk.toString("utf8");
60
60
  if (until(out)) finish();
61
61
  });
62
62
  stream.on("close", () => finish(new Error(`stream closed early; captured:\n${out}`)));
@@ -78,7 +78,7 @@ describe("cueloop serve", () => {
78
78
  });
79
79
 
80
80
  test("an anonymous ssh client gets the observer TUI for the session", async () => {
81
- const bytes = await sshCapture(handle.port, (s) => s.includes("Rollout Plan") && s.includes("observer"));
81
+ const bytes = await sshCapture(handle.port, (frame) => frame.includes("Rollout Plan") && frame.includes("observer"));
82
82
  expect(bytes).toContain("cueloop");
83
83
  expect(bytes).toContain("Rollout Plan");
84
84
  // observer chrome, not the controller's mutating hint bar
@@ -87,8 +87,8 @@ describe("cueloop serve", () => {
87
87
 
88
88
  test("two observers can watch at once", async () => {
89
89
  const [a, b] = await Promise.all([
90
- sshCapture(handle.port, (s) => s.includes("Rollout Plan")),
91
- sshCapture(handle.port, (s) => s.includes("Rollout Plan")),
90
+ sshCapture(handle.port, (frame) => frame.includes("Rollout Plan")),
91
+ sshCapture(handle.port, (frame) => frame.includes("Rollout Plan")),
92
92
  ]);
93
93
  expect(a).toContain("Rollout Plan");
94
94
  expect(b).toContain("Rollout Plan");
package/src/serve.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * SSH-served TUI (#22 share path): `cueloop serve` lets teammates join a
2
+ * SSH-served TUI: `cueloop serve` lets teammates join a
3
3
  * review session over plain ssh. Every SSH connection renders <App> in
4
4
  * observer mode (readOnly) against the same local daemon; the one writable
5
5
  * controller stays the local owner's own `cueloop` TUI.
@@ -44,8 +44,8 @@ export interface ServeHandle {
44
44
  close(): Promise<void>;
45
45
  }
46
46
 
47
- export async function serveClient(opts: ServeOptions = {}): Promise<ServeHandle> {
48
- const home = opts.home ?? cueloopHome();
47
+ export async function serveClient(options: ServeOptions = {}): Promise<ServeHandle> {
48
+ const home = options.home ?? cueloopHome();
49
49
  const sshDir = join(home, "ssh");
50
50
  mkdirSync(sshDir, { recursive: true, mode: 0o700 });
51
51
 
@@ -53,15 +53,15 @@ export async function serveClient(opts: ServeOptions = {}): Promise<ServeHandle>
53
53
  // password-less by design; see the trust model in the module comment
54
54
  auth: "open",
55
55
  hostKey: { path: join(sshDir, "host_key") },
56
- startupBanner: opts.banner ?? true,
56
+ startupBanner: options.banner ?? true,
57
57
  idleTimeout: "2h",
58
- onError: opts.onError,
58
+ onError: options.onError,
59
59
  }).serve((session) => {
60
60
  const root = createRoot(session.renderer);
61
61
  root.render(
62
62
  React.createElement(App, {
63
63
  home,
64
- sessionId: opts.sessionId,
64
+ sessionId: options.sessionId,
65
65
  readOnly: true,
66
66
  // q disconnects only this observer, never the server
67
67
  onExit: () => session.end(),
@@ -70,6 +70,6 @@ export async function serveClient(opts: ServeOptions = {}): Promise<ServeHandle>
70
70
  session.onClose(() => root.unmount());
71
71
  });
72
72
 
73
- const info = await server.listen(opts.port ?? 2222, opts.host ?? "127.0.0.1");
73
+ const info = await server.listen(options.port ?? 2222, options.host ?? "127.0.0.1");
74
74
  return { ...info, close: () => server.close() };
75
75
  }