@h-rig/cli 0.0.6-alpha.82 → 0.0.6-alpha.84

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 (206) hide show
  1. package/dist/bin/build-rig-binaries.js +40 -8
  2. package/dist/bin/rig.js +23402 -14577
  3. package/dist/src/app/board.js +217 -41
  4. package/dist/src/app-opentui/adapters/command.d.ts +2 -0
  5. package/dist/src/app-opentui/adapters/command.js +329 -0
  6. package/dist/src/app-opentui/adapters/common.js +2 -2
  7. package/dist/src/app-opentui/adapters/doctor.d.ts +0 -2
  8. package/dist/src/app-opentui/adapters/doctor.js +64 -39
  9. package/dist/src/app-opentui/adapters/family.d.ts +62 -0
  10. package/dist/src/app-opentui/adapters/family.js +14305 -0
  11. package/dist/src/app-opentui/adapters/fleet.d.ts +0 -2
  12. package/dist/src/app-opentui/adapters/fleet.js +90 -60
  13. package/dist/src/app-opentui/adapters/inbox.d.ts +12 -2
  14. package/dist/src/app-opentui/adapters/inbox.js +137 -78
  15. package/dist/src/app-opentui/adapters/init.d.ts +0 -2
  16. package/dist/src/app-opentui/adapters/init.js +85 -47
  17. package/dist/src/app-opentui/adapters/inspect.d.ts +52 -0
  18. package/dist/src/app-opentui/adapters/inspect.js +1024 -0
  19. package/dist/src/app-opentui/adapters/pi-attach.d.ts +15 -6
  20. package/dist/src/app-opentui/adapters/pi-attach.js +442 -125
  21. package/dist/src/app-opentui/adapters/pi.d.ts +23 -0
  22. package/dist/src/app-opentui/adapters/pi.js +363 -0
  23. package/dist/src/app-opentui/adapters/plugin.d.ts +84 -0
  24. package/dist/src/app-opentui/adapters/plugin.js +544 -0
  25. package/dist/src/app-opentui/adapters/repo.d.ts +37 -0
  26. package/dist/src/app-opentui/adapters/repo.js +186 -0
  27. package/dist/src/app-opentui/adapters/run-detail.d.ts +9 -2
  28. package/dist/src/app-opentui/adapters/run-detail.js +180 -63
  29. package/dist/src/app-opentui/adapters/server.d.ts +10 -2
  30. package/dist/src/app-opentui/adapters/server.js +191 -45
  31. package/dist/src/app-opentui/adapters/tasks.d.ts +11 -2
  32. package/dist/src/app-opentui/adapters/tasks.js +1123 -143
  33. package/dist/src/app-opentui/adapters/workspace.d.ts +49 -0
  34. package/dist/src/app-opentui/adapters/workspace.js +333 -0
  35. package/dist/src/app-opentui/autocomplete.d.ts +20 -0
  36. package/dist/src/app-opentui/autocomplete.js +576 -0
  37. package/dist/src/app-opentui/bootstrap.d.ts +1 -6
  38. package/dist/src/app-opentui/bootstrap.js +25252 -16474
  39. package/dist/src/app-opentui/command-palette.d.ts +3 -0
  40. package/dist/src/app-opentui/command-palette.js +1010 -0
  41. package/dist/src/app-opentui/command-pty-host.d.ts +62 -0
  42. package/dist/src/app-opentui/command-pty-host.js +248 -0
  43. package/dist/src/app-opentui/drone.js +8 -6
  44. package/dist/src/app-opentui/events.js +1 -1
  45. package/dist/src/app-opentui/fleet-stats.d.ts +32 -0
  46. package/dist/src/app-opentui/fleet-stats.js +114 -0
  47. package/dist/src/app-opentui/focus-manager.d.ts +14 -0
  48. package/dist/src/app-opentui/focus-manager.js +24 -0
  49. package/dist/src/app-opentui/index.js +5431 -2797
  50. package/dist/src/app-opentui/intent.js +179 -50
  51. package/dist/src/app-opentui/keymap.d.ts +21 -0
  52. package/dist/src/app-opentui/keymap.js +1748 -0
  53. package/dist/src/app-opentui/launch-routing.d.ts +16 -0
  54. package/dist/src/app-opentui/launch-routing.js +55 -0
  55. package/dist/src/app-opentui/layout.d.ts +7 -0
  56. package/dist/src/app-opentui/layout.js +13 -6
  57. package/dist/src/app-opentui/list-search.d.ts +24 -0
  58. package/dist/src/app-opentui/list-search.js +88 -1
  59. package/dist/src/app-opentui/pi-host-child.js +99 -17
  60. package/dist/src/app-opentui/pi-pty-host.d.ts +14 -0
  61. package/dist/src/app-opentui/pi-pty-host.js +30 -14
  62. package/dist/src/app-opentui/react/App.d.ts +9 -0
  63. package/dist/src/app-opentui/react/App.js +5144 -0
  64. package/dist/src/app-opentui/react/Backdrop.d.ts +5 -0
  65. package/dist/src/app-opentui/react/Backdrop.js +1834 -0
  66. package/dist/src/app-opentui/react/ChromeHost.d.ts +5 -0
  67. package/dist/src/app-opentui/react/ChromeHost.js +2942 -0
  68. package/dist/src/app-opentui/react/SceneFrameView.d.ts +7 -0
  69. package/dist/src/app-opentui/react/SceneFrameView.js +529 -0
  70. package/dist/src/app-opentui/react/context.d.ts +17 -0
  71. package/dist/src/app-opentui/react/context.js +37 -0
  72. package/dist/src/app-opentui/react/launch.d.ts +2 -0
  73. package/dist/src/app-opentui/react/launch.js +5743 -0
  74. package/dist/src/app-opentui/react/nav.d.ts +18 -0
  75. package/dist/src/app-opentui/react/nav.js +54 -0
  76. package/dist/src/app-opentui/react/scroll.d.ts +12 -0
  77. package/dist/src/app-opentui/react/scroll.js +21 -0
  78. package/dist/src/app-opentui/react/syntax.d.ts +2 -0
  79. package/dist/src/app-opentui/react/syntax.js +64 -0
  80. package/dist/src/app-opentui/registry.js +20428 -4828
  81. package/dist/src/app-opentui/render/ascii-fleet.d.ts +15 -0
  82. package/dist/src/app-opentui/render/ascii-fleet.js +82 -0
  83. package/dist/src/app-opentui/render/constants.d.ts +31 -0
  84. package/dist/src/app-opentui/render/constants.js +66 -0
  85. package/dist/src/app-opentui/render/graphics.d.ts +2 -1
  86. package/dist/src/app-opentui/render/graphics.js +228 -46
  87. package/dist/src/app-opentui/render/image-visual-layer-worker.js +469 -930
  88. package/dist/src/app-opentui/render/image-visual-layer.d.ts +25 -10
  89. package/dist/src/app-opentui/render/image-visual-layer.js +448 -329
  90. package/dist/src/app-opentui/render/native-host.d.ts +37 -0
  91. package/dist/src/app-opentui/render/native-host.js +179 -0
  92. package/dist/src/app-opentui/render/panel-layout.d.ts +38 -0
  93. package/dist/src/app-opentui/render/panel-layout.js +48 -0
  94. package/dist/src/app-opentui/render/panels.d.ts +2 -0
  95. package/dist/src/app-opentui/render/panels.js +78 -38
  96. package/dist/src/app-opentui/render/preloader.d.ts +10 -0
  97. package/dist/src/app-opentui/render/preloader.js +165 -0
  98. package/dist/src/app-opentui/render/scene.d.ts +53 -1
  99. package/dist/src/app-opentui/render/scene.js +195 -6
  100. package/dist/src/app-opentui/render/text.d.ts +7 -1
  101. package/dist/src/app-opentui/render/text.js +15 -8
  102. package/dist/src/app-opentui/render/type-bar.d.ts +2 -1
  103. package/dist/src/app-opentui/render/type-bar.js +113 -39
  104. package/dist/src/app-opentui/runtime-resources.d.ts +16 -0
  105. package/dist/src/app-opentui/runtime-resources.js +62 -0
  106. package/dist/src/app-opentui/runtime.d.ts +44 -1
  107. package/dist/src/app-opentui/runtime.js +5415 -2738
  108. package/dist/src/app-opentui/scenes/command.d.ts +3 -0
  109. package/dist/src/app-opentui/scenes/command.js +117 -0
  110. package/dist/src/app-opentui/scenes/doctor.d.ts +2 -1
  111. package/dist/src/app-opentui/scenes/doctor.js +221 -17
  112. package/dist/src/app-opentui/scenes/error.js +60 -20
  113. package/dist/src/app-opentui/scenes/family-domains/agent.d.ts +2 -0
  114. package/dist/src/app-opentui/scenes/family-domains/agent.js +348 -0
  115. package/dist/src/app-opentui/scenes/family-domains/browser.d.ts +2 -0
  116. package/dist/src/app-opentui/scenes/family-domains/browser.js +195 -0
  117. package/dist/src/app-opentui/scenes/family-domains/dist.d.ts +2 -0
  118. package/dist/src/app-opentui/scenes/family-domains/dist.js +243 -0
  119. package/dist/src/app-opentui/scenes/family-domains/git.d.ts +2 -0
  120. package/dist/src/app-opentui/scenes/family-domains/git.js +195 -0
  121. package/dist/src/app-opentui/scenes/family-domains/github.d.ts +2 -0
  122. package/dist/src/app-opentui/scenes/family-domains/github.js +274 -0
  123. package/dist/src/app-opentui/scenes/family-domains/harness.d.ts +2 -0
  124. package/dist/src/app-opentui/scenes/family-domains/harness.js +152 -0
  125. package/dist/src/app-opentui/scenes/family-domains/index.d.ts +4 -0
  126. package/dist/src/app-opentui/scenes/family-domains/index.js +1679 -0
  127. package/dist/src/app-opentui/scenes/family-domains/kit.d.ts +76 -0
  128. package/dist/src/app-opentui/scenes/family-domains/kit.js +305 -0
  129. package/dist/src/app-opentui/scenes/family-domains/profile.d.ts +2 -0
  130. package/dist/src/app-opentui/scenes/family-domains/profile.js +212 -0
  131. package/dist/src/app-opentui/scenes/family-domains/queue.d.ts +2 -0
  132. package/dist/src/app-opentui/scenes/family-domains/queue.js +146 -0
  133. package/dist/src/app-opentui/scenes/family-domains/remote.d.ts +2 -0
  134. package/dist/src/app-opentui/scenes/family-domains/remote.js +518 -0
  135. package/dist/src/app-opentui/scenes/family-domains/review.d.ts +2 -0
  136. package/dist/src/app-opentui/scenes/family-domains/review.js +280 -0
  137. package/dist/src/app-opentui/scenes/family-domains/setup.d.ts +2 -0
  138. package/dist/src/app-opentui/scenes/family-domains/setup.js +267 -0
  139. package/dist/src/app-opentui/scenes/family-domains/stats.d.ts +2 -0
  140. package/dist/src/app-opentui/scenes/family-domains/stats.js +370 -0
  141. package/dist/src/app-opentui/scenes/family.d.ts +3 -0
  142. package/dist/src/app-opentui/scenes/family.js +2144 -0
  143. package/dist/src/app-opentui/scenes/fleet.js +552 -43
  144. package/dist/src/app-opentui/scenes/handoff.js +342 -35
  145. package/dist/src/app-opentui/scenes/help.js +640 -56
  146. package/dist/src/app-opentui/scenes/inbox.d.ts +2 -1
  147. package/dist/src/app-opentui/scenes/inbox.js +329 -21
  148. package/dist/src/app-opentui/scenes/init.d.ts +2 -1
  149. package/dist/src/app-opentui/scenes/init.js +120 -34
  150. package/dist/src/app-opentui/scenes/inspect.d.ts +3 -0
  151. package/dist/src/app-opentui/scenes/inspect.js +793 -0
  152. package/dist/src/app-opentui/scenes/main.d.ts +2 -1
  153. package/dist/src/app-opentui/scenes/main.js +264 -29
  154. package/dist/src/app-opentui/scenes/pi.d.ts +3 -0
  155. package/dist/src/app-opentui/scenes/pi.js +508 -0
  156. package/dist/src/app-opentui/scenes/plugin.d.ts +3 -0
  157. package/dist/src/app-opentui/scenes/plugin.js +486 -0
  158. package/dist/src/app-opentui/scenes/repo.d.ts +3 -0
  159. package/dist/src/app-opentui/scenes/repo.js +424 -0
  160. package/dist/src/app-opentui/scenes/run-detail.d.ts +2 -1
  161. package/dist/src/app-opentui/scenes/run-detail.js +362 -35
  162. package/dist/src/app-opentui/scenes/server.d.ts +2 -1
  163. package/dist/src/app-opentui/scenes/server.js +243 -26
  164. package/dist/src/app-opentui/scenes/tasks.js +518 -41
  165. package/dist/src/app-opentui/scenes/workspace.d.ts +3 -0
  166. package/dist/src/app-opentui/scenes/workspace.js +426 -0
  167. package/dist/src/app-opentui/selectable.d.ts +19 -0
  168. package/dist/src/app-opentui/selectable.js +79 -0
  169. package/dist/src/app-opentui/state.js +129 -36
  170. package/dist/src/app-opentui/surface-catalog.d.ts +20 -0
  171. package/dist/src/app-opentui/surface-catalog.js +540 -0
  172. package/dist/src/app-opentui/terminal-capabilities.d.ts +7 -0
  173. package/dist/src/app-opentui/terminal-capabilities.js +15 -0
  174. package/dist/src/app-opentui/theme.d.ts +28 -6
  175. package/dist/src/app-opentui/theme.js +61 -8
  176. package/dist/src/app-opentui/types.d.ts +130 -5
  177. package/dist/src/commands/_authority-runs.d.ts +1 -1
  178. package/dist/src/commands/_authority-runs.js +2 -12
  179. package/dist/src/commands/_doctor-checks.js +62 -13
  180. package/dist/src/commands/_help-catalog.js +95 -15
  181. package/dist/src/commands/_operator-view.js +97 -15
  182. package/dist/src/commands/_pi-frontend.d.ts +2 -0
  183. package/dist/src/commands/_pi-frontend.js +97 -13
  184. package/dist/src/commands/_preflight.js +64 -14
  185. package/dist/src/commands/_server-client.js +82 -18
  186. package/dist/src/commands/_server-events.d.ts +26 -0
  187. package/dist/src/commands/_server-events.js +310 -0
  188. package/dist/src/commands/_snapshot-upload.js +62 -13
  189. package/dist/src/commands/agent.js +2 -12
  190. package/dist/src/commands/connect.js +7 -1
  191. package/dist/src/commands/doctor.js +62 -13
  192. package/dist/src/commands/github.js +144 -23
  193. package/dist/src/commands/inbox.js +62 -13
  194. package/dist/src/commands/init.js +82 -18
  195. package/dist/src/commands/inspect.js +62 -13
  196. package/dist/src/commands/run.js +100 -15
  197. package/dist/src/commands/server.js +71 -26
  198. package/dist/src/commands/setup.js +62 -13
  199. package/dist/src/commands/stats.js +157 -28
  200. package/dist/src/commands/task-run-driver.js +64 -25
  201. package/dist/src/commands/task.js +196 -43
  202. package/dist/src/commands.js +419 -123
  203. package/dist/src/index.js +426 -130
  204. package/package.json +11 -10
  205. package/dist/src/app-opentui/render/image-visual-layer-native-canvas.d.ts +0 -2
  206. package/dist/src/app-opentui/render/image-visual-layer-native-canvas.js +0 -1484
@@ -0,0 +1,62 @@
1
+ export type CommandPtyHostStatus = "starting" | "running" | "exited" | "failed";
2
+ export type CommandPtyHostSnapshot = {
3
+ readonly command: readonly string[];
4
+ readonly label: string;
5
+ readonly status: CommandPtyHostStatus;
6
+ readonly cols: number;
7
+ readonly rows: number;
8
+ readonly lines: readonly string[];
9
+ readonly message?: string;
10
+ readonly exitCode?: number;
11
+ readonly signal?: string | null;
12
+ };
13
+ type CommandPtyInput = string | Uint8Array<ArrayBufferLike> | BufferSource;
14
+ export type CommandPtyHostOptions = {
15
+ readonly argv: readonly string[];
16
+ readonly projectRoot: string;
17
+ readonly cols: number;
18
+ readonly rows: number;
19
+ readonly label?: string;
20
+ readonly env?: NodeJS.ProcessEnv;
21
+ readonly onSnapshot?: (snapshot: CommandPtyHostSnapshot) => void;
22
+ readonly onExit?: (snapshot: CommandPtyHostSnapshot) => void;
23
+ readonly onError?: (error: unknown, snapshot: CommandPtyHostSnapshot) => void;
24
+ };
25
+ export declare function getActiveCommandHost(): CommandPtyHost | null;
26
+ export declare function stopActiveCommandHost(reason?: string): void;
27
+ export declare function startCommandPtyHost(options: CommandPtyHostOptions): Promise<CommandPtyHost>;
28
+ export declare class CommandPtyHost {
29
+ private readonly argv;
30
+ private readonly projectRoot;
31
+ private readonly label;
32
+ private readonly env?;
33
+ private readonly onSnapshot?;
34
+ private readonly onExit?;
35
+ private readonly onError?;
36
+ private readonly terminal;
37
+ private readonly decoder;
38
+ private proc;
39
+ private pty;
40
+ private status;
41
+ private cols;
42
+ private rows;
43
+ private message;
44
+ private exitCode;
45
+ private signal;
46
+ private notifyTimer;
47
+ private _disposed;
48
+ constructor(options: CommandPtyHostOptions);
49
+ get disposed(): boolean;
50
+ get snapshot(): CommandPtyHostSnapshot;
51
+ start(): Promise<void>;
52
+ write(data: CommandPtyInput): void;
53
+ resize(cols: number, rows: number): void;
54
+ dispose(reason?: string, options?: {
55
+ readonly kill?: boolean;
56
+ readonly notify?: boolean;
57
+ }): void;
58
+ private handlePtyData;
59
+ private emitSnapshotSoon;
60
+ private createSnapshot;
61
+ }
62
+ export {};
@@ -0,0 +1,248 @@
1
+ // @bun
2
+ // packages/cli/src/app-opentui/command-pty-host.ts
3
+ import { basename } from "path";
4
+ import { fileURLToPath } from "url";
5
+ import { Terminal as XtermTerminal } from "@xterm/headless";
6
+ var MIN_COLS = 40;
7
+ var MIN_ROWS = 10;
8
+ var MAX_ROWS = 300;
9
+ var MAX_SNAPSHOT_LINES = 420;
10
+ var SNAPSHOT_DELAY_MS = 80;
11
+ var fallbackCliScriptPath = fileURLToPath(new URL("../../bin/rig.ts", import.meta.url));
12
+ var activeHost = null;
13
+ function clampCols(cols) {
14
+ return Math.max(MIN_COLS, Math.trunc(cols || 120));
15
+ }
16
+ function clampRows(rows) {
17
+ return Math.max(MIN_ROWS, Math.min(MAX_ROWS, Math.trunc(rows || 36)));
18
+ }
19
+ function childCommandPrefix() {
20
+ const execName = basename(process.execPath).toLowerCase();
21
+ const currentEntry = process.argv[1];
22
+ if (execName === "bun" || execName === "bun.exe") {
23
+ return currentEntry ? [process.execPath, currentEntry] : [process.execPath, fallbackCliScriptPath];
24
+ }
25
+ return [process.execPath];
26
+ }
27
+ function withEnv(base) {
28
+ const env = {};
29
+ for (const [key, value] of Object.entries(base ?? process.env)) {
30
+ if (key === "NO_COLOR")
31
+ continue;
32
+ if (typeof value === "string")
33
+ env[key] = value;
34
+ }
35
+ return {
36
+ ...env,
37
+ TERM: "xterm-256color",
38
+ COLORTERM: "truecolor",
39
+ FORCE_COLOR: env.FORCE_COLOR ?? "1",
40
+ RIG_PLAIN: "1",
41
+ RIG_OPENTUI_COMMAND_HOST: "1",
42
+ RIG_CLI_PLAIN_HELP: env.RIG_CLI_PLAIN_HELP ?? "1"
43
+ };
44
+ }
45
+ function commandLabel(argv, fallback) {
46
+ const command = argv.join(" ").trim();
47
+ return fallback?.trim() || (command ? `rig ${command}` : "rig");
48
+ }
49
+ function getActiveCommandHost() {
50
+ return activeHost && !activeHost.disposed ? activeHost : null;
51
+ }
52
+ function stopActiveCommandHost(reason = "detach") {
53
+ activeHost?.dispose(reason);
54
+ activeHost = null;
55
+ }
56
+ async function startCommandPtyHost(options) {
57
+ activeHost?.dispose("replace");
58
+ const host = new CommandPtyHost(options);
59
+ activeHost = host;
60
+ await host.start();
61
+ return host;
62
+ }
63
+
64
+ class CommandPtyHost {
65
+ argv;
66
+ projectRoot;
67
+ label;
68
+ env;
69
+ onSnapshot;
70
+ onExit;
71
+ onError;
72
+ terminal;
73
+ decoder = new TextDecoder("utf-8");
74
+ proc = null;
75
+ pty = null;
76
+ status = "starting";
77
+ cols;
78
+ rows;
79
+ message = "starting command";
80
+ exitCode;
81
+ signal;
82
+ notifyTimer = null;
83
+ _disposed = false;
84
+ constructor(options) {
85
+ this.argv = [...options.argv];
86
+ this.projectRoot = options.projectRoot;
87
+ this.label = commandLabel(options.argv, options.label);
88
+ this.env = options.env;
89
+ this.cols = clampCols(options.cols);
90
+ this.rows = clampRows(options.rows);
91
+ this.onSnapshot = options.onSnapshot;
92
+ this.onExit = options.onExit;
93
+ this.onError = options.onError;
94
+ this.terminal = new XtermTerminal({ allowProposedApi: true, cols: this.cols, rows: this.rows, scrollback: 2000 });
95
+ }
96
+ get disposed() {
97
+ return this._disposed;
98
+ }
99
+ get snapshot() {
100
+ return this.createSnapshot();
101
+ }
102
+ async start() {
103
+ if (this._disposed)
104
+ throw new Error("Command PTY host is disposed.");
105
+ if (typeof Bun.Terminal !== "function") {
106
+ throw new Error("Bun native PTY is unavailable in this runtime. Command host requires Bun.Terminal.");
107
+ }
108
+ const spawnOptions = {
109
+ cwd: this.projectRoot,
110
+ env: withEnv(this.env),
111
+ terminal: {
112
+ cols: this.cols,
113
+ rows: this.rows,
114
+ name: "xterm-256color",
115
+ data: (_terminal, data) => this.handlePtyData(data)
116
+ }
117
+ };
118
+ const proc = Bun.spawn([...childCommandPrefix(), ...this.argv], spawnOptions);
119
+ if (!proc.terminal)
120
+ throw new Error("Bun did not attach a terminal to the command child process.");
121
+ this.proc = proc;
122
+ this.pty = proc.terminal;
123
+ this.status = "running";
124
+ this.message = "running";
125
+ this.emitSnapshotSoon(0);
126
+ proc.exited.then((exitCode) => {
127
+ if (this._disposed)
128
+ return;
129
+ this.status = exitCode === 0 ? "exited" : "failed";
130
+ this.exitCode = exitCode;
131
+ this.signal = null;
132
+ this.message = exitCode === 0 ? "completed" : `exited with code ${exitCode}`;
133
+ const snapshot = this.createSnapshot();
134
+ this.onSnapshot?.(snapshot);
135
+ this.onExit?.(snapshot);
136
+ if (activeHost === this)
137
+ activeHost = null;
138
+ this.dispose("exit", { kill: false, notify: false });
139
+ }).catch((error) => {
140
+ if (this._disposed)
141
+ return;
142
+ this.status = "failed";
143
+ this.message = error instanceof Error ? error.message : String(error);
144
+ const snapshot = this.createSnapshot();
145
+ this.onSnapshot?.(snapshot);
146
+ this.onError?.(error, snapshot);
147
+ if (activeHost === this)
148
+ activeHost = null;
149
+ this.dispose("error", { kill: false, notify: false });
150
+ });
151
+ }
152
+ write(data) {
153
+ if (this._disposed || !this.pty)
154
+ return;
155
+ try {
156
+ this.pty.write(data);
157
+ } catch (error) {
158
+ this.status = "failed";
159
+ this.message = error instanceof Error ? error.message : String(error);
160
+ const snapshot = this.createSnapshot();
161
+ this.onSnapshot?.(snapshot);
162
+ this.onError?.(error, snapshot);
163
+ }
164
+ }
165
+ resize(cols, rows) {
166
+ const nextCols = clampCols(cols);
167
+ const nextRows = clampRows(rows);
168
+ if (nextCols === this.cols && nextRows === this.rows)
169
+ return;
170
+ this.cols = nextCols;
171
+ this.rows = nextRows;
172
+ this.terminal.resize(nextCols, nextRows);
173
+ try {
174
+ this.pty?.resize(nextCols, nextRows);
175
+ } catch {}
176
+ this.emitSnapshotSoon(0);
177
+ }
178
+ dispose(reason = "dispose", options = {}) {
179
+ if (this._disposed)
180
+ return;
181
+ this._disposed = true;
182
+ if (this.notifyTimer)
183
+ clearTimeout(this.notifyTimer);
184
+ this.notifyTimer = null;
185
+ if (options.kill !== false) {
186
+ try {
187
+ this.proc?.kill("SIGTERM");
188
+ } catch {}
189
+ }
190
+ try {
191
+ this.pty?.close();
192
+ } catch {}
193
+ try {
194
+ this.terminal.dispose();
195
+ } catch {}
196
+ if (activeHost === this)
197
+ activeHost = null;
198
+ if (options.notify) {
199
+ this.message = reason;
200
+ this.onSnapshot?.(this.createSnapshot(reason));
201
+ }
202
+ }
203
+ handlePtyData(data) {
204
+ if (this._disposed)
205
+ return;
206
+ this.decoder.decode(data, { stream: true });
207
+ this.terminal.write(data, () => this.emitSnapshotSoon());
208
+ }
209
+ emitSnapshotSoon(delayMs = SNAPSHOT_DELAY_MS) {
210
+ if (this._disposed || this.notifyTimer)
211
+ return;
212
+ this.notifyTimer = setTimeout(() => {
213
+ this.notifyTimer = null;
214
+ if (this._disposed)
215
+ return;
216
+ this.onSnapshot?.(this.createSnapshot());
217
+ }, delayMs);
218
+ }
219
+ createSnapshot(message = this.message) {
220
+ const buffer = this.terminal.buffer.active;
221
+ const end = buffer.length;
222
+ const start = Math.max(0, end - MAX_SNAPSHOT_LINES);
223
+ const lines = [];
224
+ for (let row = start;row < end; row += 1) {
225
+ const line = buffer.getLine(row);
226
+ lines.push((line?.translateToString(false) ?? "").slice(0, this.cols));
227
+ }
228
+ while (lines.length < this.rows)
229
+ lines.push("");
230
+ return {
231
+ command: this.argv,
232
+ label: this.label,
233
+ status: this.status,
234
+ cols: this.cols,
235
+ rows: this.rows,
236
+ lines,
237
+ message,
238
+ ...this.exitCode !== undefined ? { exitCode: this.exitCode } : {},
239
+ ...this.signal !== undefined ? { signal: this.signal } : {}
240
+ };
241
+ }
242
+ }
243
+ export {
244
+ stopActiveCommandHost,
245
+ startCommandPtyHost,
246
+ getActiveCommandHost,
247
+ CommandPtyHost
248
+ };
@@ -14,15 +14,17 @@ var RIG_UI = {
14
14
  bg: "#070809",
15
15
  bg2: "#0b0c0e",
16
16
  panel: "#101115",
17
- panel2: "#101115",
18
- glass: "#14161b",
19
- ink: "#f2f3f6",
20
- ink2: "#aeb0ba",
21
- ink3: "#6c6e79",
22
- ink4: "#44464f",
17
+ panel2: "#14161b",
18
+ glass: "#1e2230",
19
+ border: "#2a2e3a",
20
+ ink: "#f4f5f8",
21
+ ink2: "#c7c9d3",
22
+ ink3: "#9aa0ae",
23
+ ink4: "#787b86",
23
24
  lime: "#ccff4d",
24
25
  limeDim: "#a9d63f",
25
26
  cyan: "#56d8ff",
27
+ cyanDim: "#3f9fbd",
26
28
  red: "#ff5d5d",
27
29
  yellow: "#ffd24d",
28
30
  magenta: "#ff79b0"
@@ -17,7 +17,7 @@ function normalizeError(error) {
17
17
  const message = error instanceof Error ? error.message : String(error);
18
18
  const rawHint = error instanceof Error ? error.hint : undefined;
19
19
  return {
20
- message: message || "Unknown Rig app error",
20
+ message: message || "Unknown app error",
21
21
  ...typeof rawHint === "string" && rawHint.trim() ? { hint: rawHint.trim() } : {},
22
22
  cause: error
23
23
  };
@@ -0,0 +1,32 @@
1
+ import type { AppRunRecord } from "./adapters/fleet";
2
+ import type { AppState } from "./types";
3
+ export type FleetStats = {
4
+ readonly total: number;
5
+ readonly active: number;
6
+ readonly succeeded: number;
7
+ readonly failed: number;
8
+ readonly byStatus: ReadonlyMap<string, number>;
9
+ /** 0..1 fleet load: share of runs that are actively working. */
10
+ readonly load: number;
11
+ /** Recent activity series (oldest→newest) for a throughput sparkline. */
12
+ readonly sparkline: readonly number[];
13
+ };
14
+ /** Derive fleet telemetry from a run list. Pure — same input, same output. */
15
+ export declare function computeFleetStats(runs: readonly AppRunRecord[]): FleetStats;
16
+ export declare function fleetStatsFromState(state: AppState): FleetStats;
17
+ /** Render a 0..1 series as a unicode sparkline string. */
18
+ export declare function sparklineString(values: readonly number[], width?: number): string;
19
+ /** Render a 0..1 ratio as a partial-block bar of `width` cells. */
20
+ export declare function barString(ratio: number, width: number): string;
21
+ export type StatusSegments = {
22
+ /** Block strings (█…) whose lengths are proportional to each class and sum to width. */
23
+ readonly active: string;
24
+ readonly done: string;
25
+ readonly failed: string;
26
+ readonly other: string;
27
+ };
28
+ /** Proportional status-distribution segments for a full-width stacked bar.
29
+ * Largest-remainder apportionment so the segments always sum to exactly `width`. */
30
+ export declare function statusSegments(stats: FleetStats, width: number): StatusSegments;
31
+ /** A compact one-line summary suitable for a scene header strip. */
32
+ export declare function fleetStatsStrip(stats: FleetStats, sparkWidth?: number): string;
@@ -0,0 +1,114 @@
1
+ // @bun
2
+ // packages/cli/src/app-opentui/fleet-stats.ts
3
+ var ACTIVE_STATUSES = new Set([
4
+ "running",
5
+ "preparing",
6
+ "created",
7
+ "validating",
8
+ "reviewing",
9
+ "closing-out",
10
+ "stopping",
11
+ "loading"
12
+ ]);
13
+ var SPARK_CHARS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
14
+ var BAR_CHARS = ["\u258F", "\u258E", "\u258D", "\u258C", "\u258B", "\u258A", "\u2589", "\u2588"];
15
+ function normalizeStatus(status) {
16
+ return status.replace(/_/g, "-").toLowerCase();
17
+ }
18
+ function runsFromState(state) {
19
+ const fleet = state.data.fleet;
20
+ if (!fleet || typeof fleet !== "object" || Array.isArray(fleet))
21
+ return [];
22
+ const runs = fleet.runs;
23
+ return Array.isArray(runs) ? runs : [];
24
+ }
25
+ function computeFleetStats(runs) {
26
+ const byStatus = new Map;
27
+ let active = 0;
28
+ let succeeded = 0;
29
+ let failed = 0;
30
+ for (const run of runs) {
31
+ const status = normalizeStatus(run.status ?? "");
32
+ byStatus.set(status, (byStatus.get(status) ?? 0) + 1);
33
+ if (ACTIVE_STATUSES.has(status))
34
+ active += 1;
35
+ else if (status === "success" || status === "completed" || status === "merged")
36
+ succeeded += 1;
37
+ else if (status === "failed" || status === "error")
38
+ failed += 1;
39
+ }
40
+ const total = runs.length;
41
+ const load = total === 0 ? 0 : active / total;
42
+ const sparkline = buildSparklineSeries(active, succeeded, failed);
43
+ return { total, active, succeeded, failed, byStatus, load, sparkline };
44
+ }
45
+ function buildSparklineSeries(active, succeeded, failed) {
46
+ const peak = Math.max(1, active, succeeded, failed);
47
+ const base = [succeeded, Math.round(succeeded * 0.6 + failed * 0.4), failed, Math.round((active + failed) / 2), active];
48
+ return base.map((value) => Math.max(0, Math.min(peak, value)) / peak);
49
+ }
50
+ function fleetStatsFromState(state) {
51
+ return computeFleetStats(runsFromState(state));
52
+ }
53
+ function sparklineString(values, width) {
54
+ if (values.length === 0)
55
+ return "";
56
+ const series = width && width > 0 && values.length > width ? values.slice(values.length - width) : values;
57
+ return series.map((value) => {
58
+ const clamped = Math.max(0, Math.min(1, value));
59
+ const index = Math.min(SPARK_CHARS.length - 1, Math.round(clamped * (SPARK_CHARS.length - 1)));
60
+ return SPARK_CHARS[index];
61
+ }).join("");
62
+ }
63
+ function barString(ratio, width) {
64
+ if (width <= 0)
65
+ return "";
66
+ const clamped = Math.max(0, Math.min(1, ratio));
67
+ const totalEighths = Math.round(clamped * width * 8);
68
+ const full = Math.floor(totalEighths / 8);
69
+ const remainder = totalEighths % 8;
70
+ let bar = "\u2588".repeat(Math.min(width, full));
71
+ if (full < width && remainder > 0)
72
+ bar += BAR_CHARS[remainder - 1];
73
+ return bar.padEnd(width, " ").slice(0, width);
74
+ }
75
+ function statusSegments(stats, width) {
76
+ if (width <= 0 || stats.total === 0)
77
+ return { active: "", done: "", failed: "", other: "" };
78
+ const other = Math.max(0, stats.total - stats.active - stats.succeeded - stats.failed);
79
+ const raw = [
80
+ { key: "active", value: stats.active },
81
+ { key: "done", value: stats.succeeded },
82
+ { key: "failed", value: stats.failed },
83
+ { key: "other", value: other }
84
+ ];
85
+ const exact = raw.map((entry) => ({ key: entry.key, exact: entry.value / stats.total * width }));
86
+ const floored = exact.map((entry) => ({ key: entry.key, n: Math.floor(entry.exact), frac: entry.exact - Math.floor(entry.exact) }));
87
+ let remaining = width - floored.reduce((sum, entry) => sum + entry.n, 0);
88
+ for (const entry of [...floored].sort((a, b) => b.frac - a.frac)) {
89
+ if (remaining <= 0)
90
+ break;
91
+ entry.n += 1;
92
+ remaining -= 1;
93
+ }
94
+ const widths = new Map(floored.map((entry) => [entry.key, entry.n]));
95
+ return {
96
+ active: "\u2588".repeat(widths.get("active") ?? 0),
97
+ done: "\u2588".repeat(widths.get("done") ?? 0),
98
+ failed: "\u2588".repeat(widths.get("failed") ?? 0),
99
+ other: "\u2592".repeat(widths.get("other") ?? 0)
100
+ };
101
+ }
102
+ function fleetStatsStrip(stats, sparkWidth = 12) {
103
+ const spark = sparklineString(stats.sparkline, sparkWidth);
104
+ const loadPct = Math.round(stats.load * 100);
105
+ return `load ${spark} ${loadPct}% \xB7 ${stats.active} active \xB7 ${stats.succeeded} done \xB7 ${stats.failed} failed \xB7 ${stats.total} total`;
106
+ }
107
+ export {
108
+ statusSegments,
109
+ sparklineString,
110
+ fleetStatsStrip,
111
+ fleetStatsFromState,
112
+ computeFleetStats,
113
+ barString
114
+ };
@@ -0,0 +1,14 @@
1
+ import type { TypeBarRenderables } from "./render/type-bar";
2
+ export type AppModalState = {
3
+ readonly active: boolean;
4
+ readonly owner?: string;
5
+ };
6
+ export declare class AppFocusManager {
7
+ private modalStack;
8
+ pushModal(owner: string): void;
9
+ popModal(owner: string): void;
10
+ get modal(): AppModalState;
11
+ restoreTypeBarFocus(typeBar: TypeBarRenderables | null, options?: {
12
+ readonly hidden?: boolean;
13
+ }): void;
14
+ }
@@ -0,0 +1,24 @@
1
+ // @bun
2
+ // packages/cli/src/app-opentui/focus-manager.ts
3
+ class AppFocusManager {
4
+ modalStack = [];
5
+ pushModal(owner) {
6
+ this.modalStack = [...this.modalStack.filter((entry) => entry !== owner), owner];
7
+ }
8
+ popModal(owner) {
9
+ this.modalStack = this.modalStack.filter((entry) => entry !== owner);
10
+ }
11
+ get modal() {
12
+ const owner = this.modalStack[this.modalStack.length - 1];
13
+ return owner ? { active: true, owner } : { active: false };
14
+ }
15
+ restoreTypeBarFocus(typeBar, options = {}) {
16
+ if (options.hidden || this.modal.active || !typeBar)
17
+ return;
18
+ if (!typeBar.input.focused)
19
+ typeBar.input.focus();
20
+ }
21
+ }
22
+ export {
23
+ AppFocusManager
24
+ };