@h-rig/cli 0.0.6-alpha.83 → 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.
- package/dist/bin/rig.js +22085 -14618
- package/dist/src/app/board.js +155 -28
- package/dist/src/app-opentui/adapters/doctor.d.ts +0 -2
- package/dist/src/app-opentui/adapters/doctor.js +1 -25
- package/dist/src/app-opentui/adapters/family.d.ts +62 -0
- package/dist/src/app-opentui/adapters/family.js +14305 -0
- package/dist/src/app-opentui/adapters/fleet.d.ts +0 -2
- package/dist/src/app-opentui/adapters/fleet.js +6 -40
- package/dist/src/app-opentui/adapters/inbox.d.ts +12 -2
- package/dist/src/app-opentui/adapters/inbox.js +54 -59
- package/dist/src/app-opentui/adapters/init.d.ts +0 -2
- package/dist/src/app-opentui/adapters/init.js +0 -26
- package/dist/src/app-opentui/adapters/inspect.d.ts +52 -0
- package/dist/src/app-opentui/adapters/inspect.js +1024 -0
- package/dist/src/app-opentui/adapters/pi-attach.d.ts +15 -6
- package/dist/src/app-opentui/adapters/pi-attach.js +348 -93
- package/dist/src/app-opentui/adapters/pi.d.ts +23 -0
- package/dist/src/app-opentui/adapters/pi.js +363 -0
- package/dist/src/app-opentui/adapters/plugin.d.ts +84 -0
- package/dist/src/app-opentui/adapters/plugin.js +544 -0
- package/dist/src/app-opentui/adapters/repo.d.ts +37 -0
- package/dist/src/app-opentui/adapters/repo.js +186 -0
- package/dist/src/app-opentui/adapters/run-detail.d.ts +9 -2
- package/dist/src/app-opentui/adapters/run-detail.js +97 -44
- package/dist/src/app-opentui/adapters/server.d.ts +10 -2
- package/dist/src/app-opentui/adapters/server.js +96 -27
- package/dist/src/app-opentui/adapters/tasks.d.ts +0 -2
- package/dist/src/app-opentui/adapters/tasks.js +437 -105
- package/dist/src/app-opentui/adapters/workspace.d.ts +49 -0
- package/dist/src/app-opentui/adapters/workspace.js +333 -0
- package/dist/src/app-opentui/autocomplete.d.ts +20 -0
- package/dist/src/app-opentui/autocomplete.js +576 -0
- package/dist/src/app-opentui/bootstrap.js +24296 -16919
- package/dist/src/app-opentui/command-palette.d.ts +3 -0
- package/dist/src/app-opentui/command-palette.js +1010 -0
- package/dist/src/app-opentui/drone.js +8 -6
- package/dist/src/app-opentui/fleet-stats.d.ts +32 -0
- package/dist/src/app-opentui/fleet-stats.js +114 -0
- package/dist/src/app-opentui/index.js +3438 -1724
- package/dist/src/app-opentui/intent.js +71 -48
- package/dist/src/app-opentui/keymap.d.ts +6 -5
- package/dist/src/app-opentui/keymap.js +1064 -23
- package/dist/src/app-opentui/layout.d.ts +7 -0
- package/dist/src/app-opentui/layout.js +13 -6
- package/dist/src/app-opentui/list-search.d.ts +24 -0
- package/dist/src/app-opentui/list-search.js +88 -1
- package/dist/src/app-opentui/pi-host-child.js +33 -1
- package/dist/src/app-opentui/pi-pty-host.d.ts +5 -0
- package/dist/src/app-opentui/pi-pty-host.js +21 -3
- package/dist/src/app-opentui/react/App.d.ts +9 -0
- package/dist/src/app-opentui/react/App.js +5144 -0
- package/dist/src/app-opentui/react/Backdrop.d.ts +5 -0
- package/dist/src/app-opentui/react/Backdrop.js +1834 -0
- package/dist/src/app-opentui/react/ChromeHost.d.ts +5 -0
- package/dist/src/app-opentui/react/ChromeHost.js +2942 -0
- package/dist/src/app-opentui/react/SceneFrameView.d.ts +7 -0
- package/dist/src/app-opentui/react/SceneFrameView.js +529 -0
- package/dist/src/app-opentui/react/context.d.ts +17 -0
- package/dist/src/app-opentui/react/context.js +37 -0
- package/dist/src/app-opentui/react/launch.d.ts +2 -0
- package/dist/src/app-opentui/react/launch.js +5743 -0
- package/dist/src/app-opentui/react/nav.d.ts +18 -0
- package/dist/src/app-opentui/react/nav.js +54 -0
- package/dist/src/app-opentui/react/scroll.d.ts +12 -0
- package/dist/src/app-opentui/react/scroll.js +21 -0
- package/dist/src/app-opentui/react/syntax.d.ts +2 -0
- package/dist/src/app-opentui/react/syntax.js +64 -0
- package/dist/src/app-opentui/registry.js +19923 -5151
- package/dist/src/app-opentui/render/constants.d.ts +31 -0
- package/dist/src/app-opentui/render/constants.js +66 -0
- package/dist/src/app-opentui/render/graphics.d.ts +2 -1
- package/dist/src/app-opentui/render/graphics.js +106 -39
- package/dist/src/app-opentui/render/image-visual-layer-worker.js +108 -20
- package/dist/src/app-opentui/render/image-visual-layer.d.ts +7 -0
- package/dist/src/app-opentui/render/image-visual-layer.js +109 -20
- package/dist/src/app-opentui/render/native-host.d.ts +37 -0
- package/dist/src/app-opentui/render/native-host.js +179 -0
- package/dist/src/app-opentui/render/panels.js +18 -11
- package/dist/src/app-opentui/render/preloader.js +8 -6
- package/dist/src/app-opentui/render/scene.d.ts +50 -1
- package/dist/src/app-opentui/render/scene.js +183 -6
- package/dist/src/app-opentui/render/text.d.ts +7 -1
- package/dist/src/app-opentui/render/text.js +10 -7
- package/dist/src/app-opentui/render/type-bar.js +69 -30
- package/dist/src/app-opentui/runtime.d.ts +44 -1
- package/dist/src/app-opentui/runtime.js +3231 -1363
- package/dist/src/app-opentui/scenes/command.js +20 -6
- package/dist/src/app-opentui/scenes/doctor.js +176 -11
- package/dist/src/app-opentui/scenes/error.js +20 -10
- package/dist/src/app-opentui/scenes/family-domains/agent.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/agent.js +348 -0
- package/dist/src/app-opentui/scenes/family-domains/browser.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/browser.js +195 -0
- package/dist/src/app-opentui/scenes/family-domains/dist.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/dist.js +243 -0
- package/dist/src/app-opentui/scenes/family-domains/git.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/git.js +195 -0
- package/dist/src/app-opentui/scenes/family-domains/github.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/github.js +274 -0
- package/dist/src/app-opentui/scenes/family-domains/harness.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/harness.js +152 -0
- package/dist/src/app-opentui/scenes/family-domains/index.d.ts +4 -0
- package/dist/src/app-opentui/scenes/family-domains/index.js +1679 -0
- package/dist/src/app-opentui/scenes/family-domains/kit.d.ts +76 -0
- package/dist/src/app-opentui/scenes/family-domains/kit.js +305 -0
- package/dist/src/app-opentui/scenes/family-domains/profile.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/profile.js +212 -0
- package/dist/src/app-opentui/scenes/family-domains/queue.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/queue.js +146 -0
- package/dist/src/app-opentui/scenes/family-domains/remote.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/remote.js +518 -0
- package/dist/src/app-opentui/scenes/family-domains/review.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/review.js +280 -0
- package/dist/src/app-opentui/scenes/family-domains/setup.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/setup.js +267 -0
- package/dist/src/app-opentui/scenes/family-domains/stats.d.ts +2 -0
- package/dist/src/app-opentui/scenes/family-domains/stats.js +370 -0
- package/dist/src/app-opentui/scenes/family.d.ts +3 -0
- package/dist/src/app-opentui/scenes/family.js +2144 -0
- package/dist/src/app-opentui/scenes/fleet.js +521 -31
- package/dist/src/app-opentui/scenes/handoff.js +204 -12
- package/dist/src/app-opentui/scenes/help.js +609 -40
- package/dist/src/app-opentui/scenes/inbox.js +278 -17
- package/dist/src/app-opentui/scenes/init.js +84 -39
- package/dist/src/app-opentui/scenes/inspect.d.ts +3 -0
- package/dist/src/app-opentui/scenes/inspect.js +793 -0
- package/dist/src/app-opentui/scenes/main.js +218 -39
- package/dist/src/app-opentui/scenes/pi.d.ts +3 -0
- package/dist/src/app-opentui/scenes/pi.js +508 -0
- package/dist/src/app-opentui/scenes/plugin.d.ts +3 -0
- package/dist/src/app-opentui/scenes/plugin.js +486 -0
- package/dist/src/app-opentui/scenes/repo.d.ts +3 -0
- package/dist/src/app-opentui/scenes/repo.js +424 -0
- package/dist/src/app-opentui/scenes/run-detail.js +333 -20
- package/dist/src/app-opentui/scenes/server.js +181 -15
- package/dist/src/app-opentui/scenes/tasks.js +486 -31
- package/dist/src/app-opentui/scenes/workspace.d.ts +3 -0
- package/dist/src/app-opentui/scenes/workspace.js +426 -0
- package/dist/src/app-opentui/selectable.d.ts +19 -0
- package/dist/src/app-opentui/selectable.js +79 -0
- package/dist/src/app-opentui/state.js +83 -30
- package/dist/src/app-opentui/surface-catalog.d.ts +20 -0
- package/dist/src/app-opentui/surface-catalog.js +540 -0
- package/dist/src/app-opentui/theme.d.ts +28 -6
- package/dist/src/app-opentui/theme.js +61 -8
- package/dist/src/app-opentui/types.d.ts +121 -4
- package/dist/src/commands/_authority-runs.d.ts +1 -1
- package/dist/src/commands/_authority-runs.js +2 -12
- package/dist/src/commands/_help-catalog.js +95 -15
- package/dist/src/commands/_operator-view.js +34 -2
- package/dist/src/commands/_pi-frontend.d.ts +2 -0
- package/dist/src/commands/_pi-frontend.js +34 -0
- package/dist/src/commands/_server-events.d.ts +26 -0
- package/dist/src/commands/_server-events.js +310 -0
- package/dist/src/commands/agent.js +2 -12
- package/dist/src/commands/run.js +34 -2
- package/dist/src/commands/server.js +2 -12
- package/dist/src/commands/stats.js +95 -15
- package/dist/src/commands/task-run-driver.js +2 -12
- package/dist/src/commands/task.js +131 -29
- package/dist/src/commands.js +192 -31
- package/dist/src/index.js +192 -31
- package/package.json +11 -9
|
@@ -0,0 +1,2942 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/app-opentui/react/ChromeHost.tsx
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { useRenderer, useTerminalDimensions } from "@opentui/react";
|
|
5
|
+
import { TextRenderable as TextRenderable5 } from "@opentui/core";
|
|
6
|
+
|
|
7
|
+
// packages/cli/src/app-opentui/layout.ts
|
|
8
|
+
var MIN_TERMINAL_WIDTH = 48;
|
|
9
|
+
var MIN_TERMINAL_HEIGHT = 16;
|
|
10
|
+
function computeStageLayout(width, height) {
|
|
11
|
+
const rawWidth = Math.trunc(width || 80);
|
|
12
|
+
const rawHeight = Math.trunc(height || 24);
|
|
13
|
+
const tooSmall = rawWidth < MIN_TERMINAL_WIDTH || rawHeight < MIN_TERMINAL_HEIGHT;
|
|
14
|
+
const safeWidth = Math.max(40, rawWidth);
|
|
15
|
+
const safeHeight = Math.max(18, rawHeight);
|
|
16
|
+
const compact = safeWidth < 92 || safeHeight < 30;
|
|
17
|
+
const horizontalGutter = compact ? 1 : 2;
|
|
18
|
+
const centerWidth = Math.max(36, safeWidth - horizontalGutter * 2);
|
|
19
|
+
const centerLeft = horizontalGutter;
|
|
20
|
+
const footerTop = Math.max(0, safeHeight - 1);
|
|
21
|
+
const typeBarTop = Math.max(0, footerTop - 1);
|
|
22
|
+
const centerTop = compact ? 1 : Math.max(1, Math.floor(safeHeight * 0.055));
|
|
23
|
+
const centerHeight = Math.max(6, typeBarTop - centerTop);
|
|
24
|
+
return { width: safeWidth, height: safeHeight, centerWidth, centerLeft, centerTop, centerHeight, typeBarTop, footerTop, compact, tooSmall };
|
|
25
|
+
}
|
|
26
|
+
function visibleWidth(text) {
|
|
27
|
+
return [...text].length;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// packages/cli/src/app-opentui/render/type-bar.ts
|
|
31
|
+
import { BoxRenderable, InputRenderable, InputRenderableEvents, RGBA, StyledText, TextRenderable } from "@opentui/core";
|
|
32
|
+
|
|
33
|
+
// packages/cli/src/app-opentui/theme.ts
|
|
34
|
+
import {
|
|
35
|
+
bold as otuiBold,
|
|
36
|
+
dim as otuiDim,
|
|
37
|
+
fg as otuiFg,
|
|
38
|
+
t,
|
|
39
|
+
TextAttributes
|
|
40
|
+
} from "@opentui/core";
|
|
41
|
+
var RIG_UI = {
|
|
42
|
+
bg: "#070809",
|
|
43
|
+
bg2: "#0b0c0e",
|
|
44
|
+
panel: "#101115",
|
|
45
|
+
panel2: "#14161b",
|
|
46
|
+
glass: "#1e2230",
|
|
47
|
+
border: "#2a2e3a",
|
|
48
|
+
ink: "#f4f5f8",
|
|
49
|
+
ink2: "#c7c9d3",
|
|
50
|
+
ink3: "#9aa0ae",
|
|
51
|
+
ink4: "#787b86",
|
|
52
|
+
lime: "#ccff4d",
|
|
53
|
+
limeDim: "#a9d63f",
|
|
54
|
+
cyan: "#56d8ff",
|
|
55
|
+
cyanDim: "#3f9fbd",
|
|
56
|
+
red: "#ff5d5d",
|
|
57
|
+
yellow: "#ffd24d",
|
|
58
|
+
magenta: "#ff79b0"
|
|
59
|
+
};
|
|
60
|
+
var styles = {
|
|
61
|
+
ink: otuiFg(RIG_UI.ink),
|
|
62
|
+
ink2: otuiFg(RIG_UI.ink2),
|
|
63
|
+
ink3: otuiFg(RIG_UI.ink3),
|
|
64
|
+
ink4: otuiFg(RIG_UI.ink4),
|
|
65
|
+
lime: otuiFg(RIG_UI.lime),
|
|
66
|
+
limeDim: otuiFg(RIG_UI.limeDim),
|
|
67
|
+
cyan: otuiFg(RIG_UI.cyan),
|
|
68
|
+
red: otuiFg(RIG_UI.red),
|
|
69
|
+
yellow: otuiFg(RIG_UI.yellow),
|
|
70
|
+
magenta: otuiFg(RIG_UI.magenta)
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// packages/cli/src/app-opentui/render/type-bar.ts
|
|
74
|
+
var TYPEBAR_BG = RGBA.fromInts(20, 25, 14, 224);
|
|
75
|
+
var TYPEBAR_BORDER = RGBA.fromInts(204, 255, 77, 92);
|
|
76
|
+
function createTypeBar(renderer) {
|
|
77
|
+
const background = new BoxRenderable(renderer, {
|
|
78
|
+
id: "typebar-card",
|
|
79
|
+
position: "absolute",
|
|
80
|
+
left: 0,
|
|
81
|
+
top: 0,
|
|
82
|
+
width: 1,
|
|
83
|
+
height: 1,
|
|
84
|
+
backgroundColor: TYPEBAR_BG,
|
|
85
|
+
border: true,
|
|
86
|
+
borderColor: TYPEBAR_BORDER,
|
|
87
|
+
zIndex: 4
|
|
88
|
+
});
|
|
89
|
+
const prefix = new TextRenderable(renderer, {
|
|
90
|
+
id: "typebar-prefix",
|
|
91
|
+
content: " \u203A",
|
|
92
|
+
position: "absolute",
|
|
93
|
+
left: 1,
|
|
94
|
+
top: 0,
|
|
95
|
+
fg: RIG_UI.lime,
|
|
96
|
+
zIndex: 7,
|
|
97
|
+
selectable: true
|
|
98
|
+
});
|
|
99
|
+
const input = new InputRenderable(renderer, {
|
|
100
|
+
id: "typebar-input",
|
|
101
|
+
position: "absolute",
|
|
102
|
+
left: 4,
|
|
103
|
+
top: 0,
|
|
104
|
+
width: 40,
|
|
105
|
+
placeholder: "runs \xB7 tasks \xB7 run next \xB7 help",
|
|
106
|
+
textColor: RIG_UI.ink,
|
|
107
|
+
cursorColor: RIG_UI.lime,
|
|
108
|
+
cursorStyle: { style: "block", blinking: false },
|
|
109
|
+
showCursor: true,
|
|
110
|
+
zIndex: 7,
|
|
111
|
+
selectable: true
|
|
112
|
+
});
|
|
113
|
+
const footer = new TextRenderable(renderer, {
|
|
114
|
+
id: "footer",
|
|
115
|
+
content: "",
|
|
116
|
+
position: "absolute",
|
|
117
|
+
left: 0,
|
|
118
|
+
top: 1,
|
|
119
|
+
width: "100%",
|
|
120
|
+
fg: RIG_UI.ink3,
|
|
121
|
+
zIndex: 7,
|
|
122
|
+
selectable: true
|
|
123
|
+
});
|
|
124
|
+
return { background, input, prefix, footer };
|
|
125
|
+
}
|
|
126
|
+
function modePrefix(mode) {
|
|
127
|
+
switch (mode) {
|
|
128
|
+
case "search":
|
|
129
|
+
return { glyph: " /", color: RIG_UI.cyan };
|
|
130
|
+
case "command":
|
|
131
|
+
return { glyph: " /", color: RIG_UI.lime };
|
|
132
|
+
case "prompt":
|
|
133
|
+
return { glyph: " ?", color: RIG_UI.yellow };
|
|
134
|
+
default:
|
|
135
|
+
return { glyph: " \u203A", color: RIG_UI.ink3 };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function positionTypeBar(renderables, input, footer, width, typeBarTop, footerTop) {
|
|
139
|
+
const mode = input.mode ?? "nav";
|
|
140
|
+
const editing = mode !== "nav";
|
|
141
|
+
const { glyph, color } = modePrefix(mode);
|
|
142
|
+
renderables.background.visible = true;
|
|
143
|
+
const cardTop = Math.max(0, typeBarTop - 1);
|
|
144
|
+
renderables.background.left = 0;
|
|
145
|
+
renderables.background.top = cardTop;
|
|
146
|
+
renderables.background.width = width;
|
|
147
|
+
renderables.background.height = Math.max(3, footerTop - cardTop + 1);
|
|
148
|
+
renderables.prefix.content = glyph;
|
|
149
|
+
renderables.prefix.fg = color;
|
|
150
|
+
renderables.prefix.left = 2;
|
|
151
|
+
renderables.prefix.top = typeBarTop;
|
|
152
|
+
renderables.input.top = typeBarTop;
|
|
153
|
+
renderables.input.left = 5;
|
|
154
|
+
renderables.input.width = Math.max(10, width - 8);
|
|
155
|
+
renderables.input.value = editing ? input.value : "";
|
|
156
|
+
renderables.input.placeholder = editing ? mode === "prompt" ? input.prompt?.label ?? "type a value" : mode === "command" ? "rig \u2026" : "filter\u2026" : input.placeholder;
|
|
157
|
+
renderables.input.showCursor = editing;
|
|
158
|
+
if (renderables.input.focused)
|
|
159
|
+
renderables.input.blur();
|
|
160
|
+
renderables.footer.top = footerTop;
|
|
161
|
+
renderables.footer.width = "100%";
|
|
162
|
+
renderables.footer.content = formatFooter(footer, width);
|
|
163
|
+
}
|
|
164
|
+
function hideTypeBar(renderables, height) {
|
|
165
|
+
renderables.background.visible = false;
|
|
166
|
+
renderables.background.top = height + 1;
|
|
167
|
+
renderables.prefix.content = "";
|
|
168
|
+
renderables.prefix.top = height + 1;
|
|
169
|
+
renderables.input.value = "";
|
|
170
|
+
renderables.input.placeholder = "";
|
|
171
|
+
renderables.input.top = height + 1;
|
|
172
|
+
renderables.input.left = 0;
|
|
173
|
+
renderables.input.width = 1;
|
|
174
|
+
renderables.input.blur();
|
|
175
|
+
renderables.footer.content = "";
|
|
176
|
+
renderables.footer.top = height + 1;
|
|
177
|
+
}
|
|
178
|
+
function safeFooterMessage(message) {
|
|
179
|
+
const trimmed = message?.trim();
|
|
180
|
+
if (!trimmed)
|
|
181
|
+
return null;
|
|
182
|
+
if (/https?:|\b[a-z0-9-]+\.[a-z]{2,}\b|\brig\b/i.test(trimmed))
|
|
183
|
+
return null;
|
|
184
|
+
return trimmed;
|
|
185
|
+
}
|
|
186
|
+
function liveCell(live) {
|
|
187
|
+
const connected = live.trimStart().startsWith("\u25CF");
|
|
188
|
+
return { text: live, style: connected ? styles.cyan : styles.ink3 };
|
|
189
|
+
}
|
|
190
|
+
function footerCells(footer) {
|
|
191
|
+
const safeMessage = safeFooterMessage(footer.message);
|
|
192
|
+
const cells = [
|
|
193
|
+
footer.section ? { text: `\u25B8 ${footer.section}`, style: (s) => otuiBold(styles.ink2(s)) } : null,
|
|
194
|
+
footer.live ? liveCell(footer.live) : null,
|
|
195
|
+
footer.project ? { text: "workspace", style: styles.ink3 } : null,
|
|
196
|
+
footer.server ? { text: "server selected", style: styles.ink3 } : null,
|
|
197
|
+
footer.auth ? { text: "auth ready", style: styles.ink3 } : null,
|
|
198
|
+
footer.run ? { text: `run ${footer.run}`, style: styles.ink3 } : null,
|
|
199
|
+
safeMessage ? { text: safeMessage, style: styles.ink2 } : null,
|
|
200
|
+
footer.updated ? { text: footer.updated, style: styles.ink3 } : null
|
|
201
|
+
];
|
|
202
|
+
return cells.filter((cell) => cell !== null);
|
|
203
|
+
}
|
|
204
|
+
var FOOTER_SEPARATOR = " \xB7 ";
|
|
205
|
+
function formatFooter(footer, width) {
|
|
206
|
+
const budget = Math.max(8, width - 2);
|
|
207
|
+
const chunks = [styles.ink3(" ")];
|
|
208
|
+
let used = 1;
|
|
209
|
+
footerCells(footer).forEach((cell, index) => {
|
|
210
|
+
const sep = index === 0 ? "" : FOOTER_SEPARATOR;
|
|
211
|
+
const remaining = budget - used - visibleWidth(sep);
|
|
212
|
+
if (remaining <= 0)
|
|
213
|
+
return;
|
|
214
|
+
if (sep) {
|
|
215
|
+
chunks.push(styles.ink4(sep));
|
|
216
|
+
used += visibleWidth(sep);
|
|
217
|
+
}
|
|
218
|
+
const fits = visibleWidth(cell.text) <= remaining;
|
|
219
|
+
const text = fits ? cell.text : remaining <= 1 ? "\u2026" : `${[...cell.text].slice(0, Math.max(0, remaining - 1)).join("")}\u2026`;
|
|
220
|
+
chunks.push(cell.style(text));
|
|
221
|
+
used += visibleWidth(text);
|
|
222
|
+
});
|
|
223
|
+
return new StyledText(chunks);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// packages/cli/src/app-opentui/runtime.ts
|
|
227
|
+
import { BoxRenderable as BoxRenderable3, RGBA as RGBA8, StyledText as StyledText4, TextRenderable as TextRenderable4, createCliRenderer } from "@opentui/core";
|
|
228
|
+
|
|
229
|
+
// packages/cli/src/app-opentui/command-pty-host.ts
|
|
230
|
+
import { basename } from "path";
|
|
231
|
+
import { fileURLToPath } from "url";
|
|
232
|
+
import { Terminal as XtermTerminal } from "@xterm/headless";
|
|
233
|
+
var MIN_COLS = 40;
|
|
234
|
+
var MIN_ROWS = 10;
|
|
235
|
+
var MAX_ROWS = 300;
|
|
236
|
+
var MAX_SNAPSHOT_LINES = 420;
|
|
237
|
+
var SNAPSHOT_DELAY_MS = 80;
|
|
238
|
+
var fallbackCliScriptPath = fileURLToPath(new URL("../../bin/rig.ts", import.meta.url));
|
|
239
|
+
var activeHost = null;
|
|
240
|
+
function clampCols(cols) {
|
|
241
|
+
return Math.max(MIN_COLS, Math.trunc(cols || 120));
|
|
242
|
+
}
|
|
243
|
+
function clampRows(rows) {
|
|
244
|
+
return Math.max(MIN_ROWS, Math.min(MAX_ROWS, Math.trunc(rows || 36)));
|
|
245
|
+
}
|
|
246
|
+
function childCommandPrefix() {
|
|
247
|
+
const execName = basename(process.execPath).toLowerCase();
|
|
248
|
+
const currentEntry = process.argv[1];
|
|
249
|
+
if (execName === "bun" || execName === "bun.exe") {
|
|
250
|
+
return currentEntry ? [process.execPath, currentEntry] : [process.execPath, fallbackCliScriptPath];
|
|
251
|
+
}
|
|
252
|
+
return [process.execPath];
|
|
253
|
+
}
|
|
254
|
+
function withEnv(base) {
|
|
255
|
+
const env = {};
|
|
256
|
+
for (const [key, value] of Object.entries(base ?? process.env)) {
|
|
257
|
+
if (key === "NO_COLOR")
|
|
258
|
+
continue;
|
|
259
|
+
if (typeof value === "string")
|
|
260
|
+
env[key] = value;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
...env,
|
|
264
|
+
TERM: "xterm-256color",
|
|
265
|
+
COLORTERM: "truecolor",
|
|
266
|
+
FORCE_COLOR: env.FORCE_COLOR ?? "1",
|
|
267
|
+
RIG_PLAIN: "1",
|
|
268
|
+
RIG_OPENTUI_COMMAND_HOST: "1",
|
|
269
|
+
RIG_CLI_PLAIN_HELP: env.RIG_CLI_PLAIN_HELP ?? "1"
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function commandLabel(argv, fallback) {
|
|
273
|
+
const command = argv.join(" ").trim();
|
|
274
|
+
return fallback?.trim() || (command ? `rig ${command}` : "rig");
|
|
275
|
+
}
|
|
276
|
+
class CommandPtyHost {
|
|
277
|
+
argv;
|
|
278
|
+
projectRoot;
|
|
279
|
+
label;
|
|
280
|
+
env;
|
|
281
|
+
onSnapshot;
|
|
282
|
+
onExit;
|
|
283
|
+
onError;
|
|
284
|
+
terminal;
|
|
285
|
+
decoder = new TextDecoder("utf-8");
|
|
286
|
+
proc = null;
|
|
287
|
+
pty = null;
|
|
288
|
+
status = "starting";
|
|
289
|
+
cols;
|
|
290
|
+
rows;
|
|
291
|
+
message = "starting command";
|
|
292
|
+
exitCode;
|
|
293
|
+
signal;
|
|
294
|
+
notifyTimer = null;
|
|
295
|
+
_disposed = false;
|
|
296
|
+
constructor(options) {
|
|
297
|
+
this.argv = [...options.argv];
|
|
298
|
+
this.projectRoot = options.projectRoot;
|
|
299
|
+
this.label = commandLabel(options.argv, options.label);
|
|
300
|
+
this.env = options.env;
|
|
301
|
+
this.cols = clampCols(options.cols);
|
|
302
|
+
this.rows = clampRows(options.rows);
|
|
303
|
+
this.onSnapshot = options.onSnapshot;
|
|
304
|
+
this.onExit = options.onExit;
|
|
305
|
+
this.onError = options.onError;
|
|
306
|
+
this.terminal = new XtermTerminal({ allowProposedApi: true, cols: this.cols, rows: this.rows, scrollback: 2000 });
|
|
307
|
+
}
|
|
308
|
+
get disposed() {
|
|
309
|
+
return this._disposed;
|
|
310
|
+
}
|
|
311
|
+
get snapshot() {
|
|
312
|
+
return this.createSnapshot();
|
|
313
|
+
}
|
|
314
|
+
async start() {
|
|
315
|
+
if (this._disposed)
|
|
316
|
+
throw new Error("Command PTY host is disposed.");
|
|
317
|
+
if (typeof Bun.Terminal !== "function") {
|
|
318
|
+
throw new Error("Bun native PTY is unavailable in this runtime. Command host requires Bun.Terminal.");
|
|
319
|
+
}
|
|
320
|
+
const spawnOptions = {
|
|
321
|
+
cwd: this.projectRoot,
|
|
322
|
+
env: withEnv(this.env),
|
|
323
|
+
terminal: {
|
|
324
|
+
cols: this.cols,
|
|
325
|
+
rows: this.rows,
|
|
326
|
+
name: "xterm-256color",
|
|
327
|
+
data: (_terminal, data) => this.handlePtyData(data)
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const proc = Bun.spawn([...childCommandPrefix(), ...this.argv], spawnOptions);
|
|
331
|
+
if (!proc.terminal)
|
|
332
|
+
throw new Error("Bun did not attach a terminal to the command child process.");
|
|
333
|
+
this.proc = proc;
|
|
334
|
+
this.pty = proc.terminal;
|
|
335
|
+
this.status = "running";
|
|
336
|
+
this.message = "running";
|
|
337
|
+
this.emitSnapshotSoon(0);
|
|
338
|
+
proc.exited.then((exitCode) => {
|
|
339
|
+
if (this._disposed)
|
|
340
|
+
return;
|
|
341
|
+
this.status = exitCode === 0 ? "exited" : "failed";
|
|
342
|
+
this.exitCode = exitCode;
|
|
343
|
+
this.signal = null;
|
|
344
|
+
this.message = exitCode === 0 ? "completed" : `exited with code ${exitCode}`;
|
|
345
|
+
const snapshot = this.createSnapshot();
|
|
346
|
+
this.onSnapshot?.(snapshot);
|
|
347
|
+
this.onExit?.(snapshot);
|
|
348
|
+
if (activeHost === this)
|
|
349
|
+
activeHost = null;
|
|
350
|
+
this.dispose("exit", { kill: false, notify: false });
|
|
351
|
+
}).catch((error) => {
|
|
352
|
+
if (this._disposed)
|
|
353
|
+
return;
|
|
354
|
+
this.status = "failed";
|
|
355
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
356
|
+
const snapshot = this.createSnapshot();
|
|
357
|
+
this.onSnapshot?.(snapshot);
|
|
358
|
+
this.onError?.(error, snapshot);
|
|
359
|
+
if (activeHost === this)
|
|
360
|
+
activeHost = null;
|
|
361
|
+
this.dispose("error", { kill: false, notify: false });
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
write(data) {
|
|
365
|
+
if (this._disposed || !this.pty)
|
|
366
|
+
return;
|
|
367
|
+
try {
|
|
368
|
+
this.pty.write(data);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
this.status = "failed";
|
|
371
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
372
|
+
const snapshot = this.createSnapshot();
|
|
373
|
+
this.onSnapshot?.(snapshot);
|
|
374
|
+
this.onError?.(error, snapshot);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
resize(cols, rows) {
|
|
378
|
+
const nextCols = clampCols(cols);
|
|
379
|
+
const nextRows = clampRows(rows);
|
|
380
|
+
if (nextCols === this.cols && nextRows === this.rows)
|
|
381
|
+
return;
|
|
382
|
+
this.cols = nextCols;
|
|
383
|
+
this.rows = nextRows;
|
|
384
|
+
this.terminal.resize(nextCols, nextRows);
|
|
385
|
+
try {
|
|
386
|
+
this.pty?.resize(nextCols, nextRows);
|
|
387
|
+
} catch {}
|
|
388
|
+
this.emitSnapshotSoon(0);
|
|
389
|
+
}
|
|
390
|
+
dispose(reason = "dispose", options = {}) {
|
|
391
|
+
if (this._disposed)
|
|
392
|
+
return;
|
|
393
|
+
this._disposed = true;
|
|
394
|
+
if (this.notifyTimer)
|
|
395
|
+
clearTimeout(this.notifyTimer);
|
|
396
|
+
this.notifyTimer = null;
|
|
397
|
+
if (options.kill !== false) {
|
|
398
|
+
try {
|
|
399
|
+
this.proc?.kill("SIGTERM");
|
|
400
|
+
} catch {}
|
|
401
|
+
}
|
|
402
|
+
try {
|
|
403
|
+
this.pty?.close();
|
|
404
|
+
} catch {}
|
|
405
|
+
try {
|
|
406
|
+
this.terminal.dispose();
|
|
407
|
+
} catch {}
|
|
408
|
+
if (activeHost === this)
|
|
409
|
+
activeHost = null;
|
|
410
|
+
if (options.notify) {
|
|
411
|
+
this.message = reason;
|
|
412
|
+
this.onSnapshot?.(this.createSnapshot(reason));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
handlePtyData(data) {
|
|
416
|
+
if (this._disposed)
|
|
417
|
+
return;
|
|
418
|
+
this.decoder.decode(data, { stream: true });
|
|
419
|
+
this.terminal.write(data, () => this.emitSnapshotSoon());
|
|
420
|
+
}
|
|
421
|
+
emitSnapshotSoon(delayMs = SNAPSHOT_DELAY_MS) {
|
|
422
|
+
if (this._disposed || this.notifyTimer)
|
|
423
|
+
return;
|
|
424
|
+
this.notifyTimer = setTimeout(() => {
|
|
425
|
+
this.notifyTimer = null;
|
|
426
|
+
if (this._disposed)
|
|
427
|
+
return;
|
|
428
|
+
this.onSnapshot?.(this.createSnapshot());
|
|
429
|
+
}, delayMs);
|
|
430
|
+
}
|
|
431
|
+
createSnapshot(message = this.message) {
|
|
432
|
+
const buffer = this.terminal.buffer.active;
|
|
433
|
+
const end = buffer.length;
|
|
434
|
+
const start = Math.max(0, end - MAX_SNAPSHOT_LINES);
|
|
435
|
+
const lines = [];
|
|
436
|
+
for (let row = start;row < end; row += 1) {
|
|
437
|
+
const line = buffer.getLine(row);
|
|
438
|
+
lines.push((line?.translateToString(false) ?? "").slice(0, this.cols));
|
|
439
|
+
}
|
|
440
|
+
while (lines.length < this.rows)
|
|
441
|
+
lines.push("");
|
|
442
|
+
return {
|
|
443
|
+
command: this.argv,
|
|
444
|
+
label: this.label,
|
|
445
|
+
status: this.status,
|
|
446
|
+
cols: this.cols,
|
|
447
|
+
rows: this.rows,
|
|
448
|
+
lines,
|
|
449
|
+
message,
|
|
450
|
+
...this.exitCode !== undefined ? { exitCode: this.exitCode } : {},
|
|
451
|
+
...this.signal !== undefined ? { signal: this.signal } : {}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// packages/cli/src/commands/_help-catalog.ts
|
|
457
|
+
import pc from "picocolors";
|
|
458
|
+
var PRIMARY_GROUPS = [
|
|
459
|
+
{
|
|
460
|
+
name: "server",
|
|
461
|
+
summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
|
|
462
|
+
usage: ["rig server <status|list|add|use|start> [options]"],
|
|
463
|
+
commands: [
|
|
464
|
+
{ command: "status", description: "Show the selected server for this repo.", primary: true },
|
|
465
|
+
{ command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
|
|
466
|
+
{ command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
|
|
467
|
+
{ command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
|
|
468
|
+
{ command: "list", description: "List saved local/remote server aliases.", primary: true },
|
|
469
|
+
{ command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
|
|
470
|
+
],
|
|
471
|
+
examples: [
|
|
472
|
+
"rig server status",
|
|
473
|
+
"rig server add prod https://where.rig-does.work",
|
|
474
|
+
"rig server use prod",
|
|
475
|
+
"rig server use local",
|
|
476
|
+
"rig server start --port 3773"
|
|
477
|
+
],
|
|
478
|
+
next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."]
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
name: "task",
|
|
482
|
+
summary: "Find work, start Pi-backed runs, and validate task results.",
|
|
483
|
+
usage: ["rig task <list|next|show|run> [options]"],
|
|
484
|
+
commands: [
|
|
485
|
+
{ command: "list [--assignee <login|me|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
|
|
486
|
+
{ command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
|
|
487
|
+
{ command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
|
|
488
|
+
{ command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
|
|
489
|
+
{ command: "ready", description: "List task IDs that are runnable now." },
|
|
490
|
+
{ command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
|
|
491
|
+
{ command: "details --task <id>", description: "Show full task info from the configured source." },
|
|
492
|
+
{ command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
|
|
493
|
+
{ command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
|
|
494
|
+
{ command: "report-bug", description: "Create a structured bug report/task." }
|
|
495
|
+
],
|
|
496
|
+
examples: [
|
|
497
|
+
"rig task list --assignee @me --limit 20",
|
|
498
|
+
"rig task next",
|
|
499
|
+
"rig task show 123 --raw",
|
|
500
|
+
"rig task run --next",
|
|
501
|
+
"rig task run #123 --runtime-adapter pi",
|
|
502
|
+
"rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
|
|
503
|
+
],
|
|
504
|
+
next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: "run",
|
|
508
|
+
summary: "Observe, attach to, and control Rig runs. `attach` opens the Pi console \u2014 the full worker session, live.",
|
|
509
|
+
usage: ["rig run <list|status|show|attach|steer|stop|resume|restart> [options]"],
|
|
510
|
+
commands: [
|
|
511
|
+
{ command: "list", description: "List recent runs from the selected server or local state.", primary: true },
|
|
512
|
+
{ command: "status", description: "Render active and recent run groups.", primary: true },
|
|
513
|
+
{ command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
|
|
514
|
+
{ command: "attach <run-id>|--run <id>", description: "Open the run's Pi console \u2014 see 'Inside the console' below. Works on live AND finished runs.", primary: true },
|
|
515
|
+
{ command: "steer <run-id> --message <text>", description: "Queue a steering message into a live worker without attaching \u2014 delivered into the agent's context within seconds.", primary: true },
|
|
516
|
+
{ command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
|
|
517
|
+
{ command: "resume [<run-id>]", description: "Resume an interrupted run on the selected server (defaults to the most recent resumable)." },
|
|
518
|
+
{ command: "restart [<run-id>]", description: "Re-dispatch a run from a clean runtime, reopening its Pi session where possible." },
|
|
519
|
+
{ command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events (scripts; humans should attach)." },
|
|
520
|
+
{ command: "replay <run-id>|--run <id> [--with-session]", description: "Print the run's consolidated run.jsonl as a merged timeline; --with-session interleaves the Pi session log." },
|
|
521
|
+
{ command: "delete|cleanup", description: "Remove completed run records/artifacts." }
|
|
522
|
+
],
|
|
523
|
+
examples: [
|
|
524
|
+
"rig run attach <run-id> # full session console \u2014 live mirror, steering, worker shell",
|
|
525
|
+
"rig run steer <run-id> --message 'focus on the failing test first'",
|
|
526
|
+
"rig run list",
|
|
527
|
+
"rig run show <run-id>",
|
|
528
|
+
"rig run stop <run-id>"
|
|
529
|
+
],
|
|
530
|
+
next: [
|
|
531
|
+
"Inside the console: the run's COMPLETE transcript loads on open (finished runs too), and new worker turns stream in live.",
|
|
532
|
+
"Inside the console: plain text = steering into the worker's context \xB7 !<cmd> = shell in the WORKER workspace \xB7 /<cmd> includes the worker session's commands \xB7 /rig abort stops the current turn.",
|
|
533
|
+
"The console is read-write but remote-only: nothing runs on your machine; the worker keeps running when you exit.",
|
|
534
|
+
"Use `rig task run --next` to create a new run; interactive mode drops you straight into its console.",
|
|
535
|
+
"Use `--json` when scripts need the full structured record."
|
|
536
|
+
]
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
name: "inbox",
|
|
540
|
+
summary: "Review approval and user-input requests that block worker runs.",
|
|
541
|
+
usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
|
|
542
|
+
commands: [
|
|
543
|
+
{ command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
|
|
544
|
+
{ command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
|
|
545
|
+
{ command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
|
|
546
|
+
{ command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
|
|
547
|
+
],
|
|
548
|
+
examples: [
|
|
549
|
+
"rig inbox approvals",
|
|
550
|
+
"rig inbox inputs --run <run-id>",
|
|
551
|
+
"rig inbox approve --run <run-id> --request <request-id> --decision approve"
|
|
552
|
+
],
|
|
553
|
+
next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
name: "stats",
|
|
557
|
+
summary: "Fleet metrics computed from on-disk run journals (no server required).",
|
|
558
|
+
usage: ["rig stats [show] [--since <7d|30d|ISO date>]"],
|
|
559
|
+
commands: [
|
|
560
|
+
{ command: "show [--since <window>]", description: "Total runs, completion/failure/needs-attention rates, median run time, steering, stalls, approvals.", primary: true }
|
|
561
|
+
],
|
|
562
|
+
examples: [
|
|
563
|
+
"rig stats",
|
|
564
|
+
"rig stats --since 7d",
|
|
565
|
+
"rig stats --since 2026-06-01 --json"
|
|
566
|
+
],
|
|
567
|
+
next: ["Inspect outliers with `rig run list` and `rig run show <run-id>`.", "Use `--json` for the schema'd envelope (see docs/cli-json.md)."]
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
name: "inspect",
|
|
571
|
+
summary: "Inspect logs, artifacts, graphs, failures for a task.",
|
|
572
|
+
usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff> --task <id>"],
|
|
573
|
+
commands: [
|
|
574
|
+
{ command: "logs --task <id>", description: "Latest run log for a task (local or selected server).", primary: true },
|
|
575
|
+
{ command: "artifacts --task <id>", description: "List the task's completion artifacts.", primary: true },
|
|
576
|
+
{ command: "failures --task <id>", description: "Recorded failures for a task.", primary: true },
|
|
577
|
+
{ command: "diff --task <id>", description: "Changed files for a task.", primary: true },
|
|
578
|
+
{ command: "graph", description: "Task dependency graph." },
|
|
579
|
+
{ command: "audit", description: "Controlled-command audit trail." }
|
|
580
|
+
],
|
|
581
|
+
examples: ["rig inspect logs --task <id>", "rig inspect diff --task <id>"],
|
|
582
|
+
next: ["Use `rig stats` for fleet-level metrics across runs."]
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
name: "repo",
|
|
586
|
+
summary: "Repository sync/baseline helpers for the Rig-managed checkout.",
|
|
587
|
+
usage: ["rig repo <sync|reset-baseline>"],
|
|
588
|
+
commands: [
|
|
589
|
+
{ command: "sync", description: "Sync project repository state.", primary: true },
|
|
590
|
+
{ command: "reset-baseline", description: "Reset the managed baseline for the repo." }
|
|
591
|
+
],
|
|
592
|
+
examples: ["rig repo sync"]
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
name: "plugin",
|
|
596
|
+
summary: "Plugin listing, validation, and plugin-contributed commands.",
|
|
597
|
+
usage: ["rig plugin <list|validate|run> [options]"],
|
|
598
|
+
commands: [
|
|
599
|
+
{ command: "list", description: "List plugins declared in rig.config.ts and their contributions.", primary: true },
|
|
600
|
+
{ command: "validate --task <id>", description: "Run plugin-contributed validators for a task.", primary: true },
|
|
601
|
+
{ command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
|
|
602
|
+
],
|
|
603
|
+
examples: ["rig plugin list", "rig plugin run <command-id>"]
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
name: "init",
|
|
607
|
+
summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
|
|
608
|
+
usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
|
|
609
|
+
commands: [
|
|
610
|
+
{ command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
|
|
611
|
+
{ command: "init --demo", description: "Offline demo project: files task source + 3 sample tasks, zero GitHub.", primary: true },
|
|
612
|
+
{ command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
|
|
613
|
+
{ command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
|
|
614
|
+
{ command: "init --repair", description: "Repair missing private state without replacing project config." }
|
|
615
|
+
],
|
|
616
|
+
examples: [
|
|
617
|
+
"rig init",
|
|
618
|
+
"rig init --demo",
|
|
619
|
+
"rig init --yes --repo humanity-org/humanwork",
|
|
620
|
+
"rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
|
|
621
|
+
],
|
|
622
|
+
next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
name: "doctor",
|
|
626
|
+
summary: "Diagnostics for project/server/GitHub/Pi state.",
|
|
627
|
+
usage: ["rig doctor"],
|
|
628
|
+
commands: [
|
|
629
|
+
{ command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
|
|
630
|
+
{ command: "check", description: "Compatibility spelling for diagnostics." }
|
|
631
|
+
],
|
|
632
|
+
examples: ["rig doctor", "rig doctor --json"],
|
|
633
|
+
next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
name: "github",
|
|
637
|
+
summary: "GitHub auth helpers for the selected Rig server.",
|
|
638
|
+
usage: ["rig github auth <status|import-gh|token>"],
|
|
639
|
+
commands: [
|
|
640
|
+
{ command: "auth status", description: "Show GitHub auth state.", primary: true },
|
|
641
|
+
{ command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
|
|
642
|
+
{ command: "auth token --token <token>", description: "Store a token on the selected server." }
|
|
643
|
+
],
|
|
644
|
+
examples: ["rig github auth status", "rig github auth import-gh"],
|
|
645
|
+
next: ["After auth is valid, use `rig task run --next`."]
|
|
646
|
+
}
|
|
647
|
+
];
|
|
648
|
+
var ADVANCED_GROUPS = [
|
|
649
|
+
{
|
|
650
|
+
name: "setup",
|
|
651
|
+
summary: "Bootstrap/check local setup.",
|
|
652
|
+
usage: ["rig setup <bootstrap|check|preflight>"],
|
|
653
|
+
commands: [
|
|
654
|
+
{ command: "bootstrap", description: "Bootstrap local setup dependencies.", primary: true },
|
|
655
|
+
{ command: "check", description: "Check local setup state (toolchain, deps, config).", primary: true },
|
|
656
|
+
{ command: "preflight", description: "Run preflight checks before a run.", primary: true }
|
|
657
|
+
]
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
name: "profile",
|
|
661
|
+
summary: "Runtime profile/model defaults.",
|
|
662
|
+
usage: ["rig profile <show|set>"],
|
|
663
|
+
commands: [
|
|
664
|
+
{ command: "show", description: "Show the active execution profile.", primary: true },
|
|
665
|
+
{ command: "set [--model <model>] [--runtime <runtime>] [--plugin <plugin>]", description: "Set model/runtime/plugin profile defaults.", primary: true }
|
|
666
|
+
]
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
name: "review",
|
|
670
|
+
summary: "Inspect or change completion review gate policy.",
|
|
671
|
+
usage: ["rig review <show|set>"],
|
|
672
|
+
commands: [
|
|
673
|
+
{ command: "show", description: "Show current review gate settings." },
|
|
674
|
+
{ command: "set <off|advisory|required> [--provider <provider>]", description: "Change review strictness/provider (e.g. --provider greptile)." }
|
|
675
|
+
],
|
|
676
|
+
examples: ["rig review show", "rig review set required --provider greptile"],
|
|
677
|
+
next: ["Use `rig inbox approvals` for blocked run handoffs."]
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
name: "browser",
|
|
681
|
+
summary: "Browser workstation actions for browser-required tasks: launch, check, CDP probe, profile reset, and app-specific smokes.",
|
|
682
|
+
usage: ["rig browser <help|explain|demo|hp-next|cdp-probe|profile-persistence|profile-lock-check|smoke-test> [options]"],
|
|
683
|
+
commands: [
|
|
684
|
+
{ command: "help", description: "Rich browser command help (canonical: `rig browser help`).", primary: true },
|
|
685
|
+
{ command: "explain", description: "Explain the browser-required task contract and runtime helper commands.", primary: true },
|
|
686
|
+
{ command: "demo [--port <n>] [--profile <name>] [--state-dir <path>] [--target-url <url>] [--keep-open] [--no-build]", description: "Run a guided real browser/agent demo flow.", primary: true },
|
|
687
|
+
{ command: "hp-next dev", description: "Start hp-next Rig Browser in dev/watch mode.", primary: true },
|
|
688
|
+
{ command: "hp-next start", description: "Build/start the hp-next browser workstation without watch mode.", primary: true },
|
|
689
|
+
{ command: "hp-next check", description: "Validate the hp-next CDP endpoint on the configured port.", primary: true },
|
|
690
|
+
{ command: "hp-next e2e", description: "Run hp-next browser e2e smoke checks through Rig Browser.", primary: true },
|
|
691
|
+
{ command: "hp-next reset", description: "Reset the hp-next browser profile when stale browser state is suspected.", primary: true },
|
|
692
|
+
{ command: "cdp-probe", description: "Run an isolated CDP attach/evaluate/layout probe." },
|
|
693
|
+
{ command: "profile-persistence", description: "Verify a named browser profile persists browser state." },
|
|
694
|
+
{ command: "profile-lock-check", description: "Verify concurrent launches reject the same profile." },
|
|
695
|
+
{ command: "smoke-test", description: "Run the browser package smoke test." }
|
|
696
|
+
],
|
|
697
|
+
examples: [
|
|
698
|
+
"rig browser help",
|
|
699
|
+
"rig browser hp-next check",
|
|
700
|
+
"rig browser hp-next e2e",
|
|
701
|
+
"rig browser cdp-probe",
|
|
702
|
+
"rig browser profile-lock-check"
|
|
703
|
+
],
|
|
704
|
+
next: ["Inside a task run, use rig-browser-launch, rig-browser-check, and rig-browser-attach-info from the worker PATH."]
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
name: "pi",
|
|
708
|
+
summary: "Manage Pi extension packages for this project (community extensions from npm/git).",
|
|
709
|
+
usage: ["rig pi <list|add|remove|search> [args]"],
|
|
710
|
+
commands: [
|
|
711
|
+
{ command: "list", description: "Show project and user Pi extension packages." },
|
|
712
|
+
{ command: "add <source>", description: "Add an npm/git Pi extension to .pi/settings.json (auto-installs at next session)." },
|
|
713
|
+
{ command: "remove <source>", description: "Remove an operator-added Pi extension." },
|
|
714
|
+
{ command: "search [term]", description: "Discover Pi extension packages on the npm registry." }
|
|
715
|
+
],
|
|
716
|
+
examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
|
|
717
|
+
next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
name: "queue",
|
|
721
|
+
summary: "Run task queues locally.",
|
|
722
|
+
usage: ["rig queue run [--workers <n>] [--max-tasks <n>] [--action validate|verify|pipeline] [--isolation off|worktree] [--no-runtime-reuse] [--fail-fast] [--skip-project-sync]"],
|
|
723
|
+
commands: [
|
|
724
|
+
{ command: "run [--workers <n>] [--max-tasks <n>] [--action validate|verify|pipeline] [--isolation off|worktree] [--no-runtime-reuse] [--fail-fast] [--skip-project-sync]", description: "Process queue work: drain matching tasks with N workers, optional per-task action and isolation.", primary: true }
|
|
725
|
+
]
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
name: "agent",
|
|
729
|
+
summary: "Runtime agent workspace helpers.",
|
|
730
|
+
usage: ["rig agent <list|prepare|run|cleanup>"],
|
|
731
|
+
commands: [
|
|
732
|
+
{ command: "list", description: "List prepared agent runtimes.", primary: true },
|
|
733
|
+
{ command: "prepare [--id <id>] [--mode <mode>] [--task <task>]", description: "Prepare an isolated agent runtime workspace.", primary: true },
|
|
734
|
+
{ command: "run [--id <id>] [--mode <mode>] [--task <task>] [--skip-project-sync]", description: "Prepare (if needed) and run an agent in its workspace.", primary: true },
|
|
735
|
+
{ command: "cleanup [--all] [--id <id>]", description: "Remove prepared agent workspaces.", primary: true }
|
|
736
|
+
]
|
|
737
|
+
},
|
|
738
|
+
{ name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
|
|
739
|
+
{
|
|
740
|
+
name: "dist",
|
|
741
|
+
summary: "Build/install packaged Rig CLI.",
|
|
742
|
+
usage: ["rig dist <build|install|doctor|rebuild-agent>"],
|
|
743
|
+
commands: [
|
|
744
|
+
{ command: "build [--output-dir <dir>]", description: "Build the distributable Rig CLI.", primary: true },
|
|
745
|
+
{ command: "install [--scope <scope>] [--path <path>]", description: "Install the built CLI to a scope/path.", primary: true },
|
|
746
|
+
{ command: "doctor", description: "Diagnose the dist toolchain and install state.", primary: true },
|
|
747
|
+
{ command: "rebuild-agent", description: "Rebuild the agent runtime image, pruning stale images.", primary: true }
|
|
748
|
+
]
|
|
749
|
+
},
|
|
750
|
+
{ name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
|
|
751
|
+
{
|
|
752
|
+
name: "remote",
|
|
753
|
+
summary: "Compatibility remote orchestration controls.",
|
|
754
|
+
usage: ["rig remote <status|tasks|watch|pause|resume|continue|stop|refresh|add-iterations|remove-iterations|endpoint ...>"],
|
|
755
|
+
commands: [
|
|
756
|
+
{ command: "status [--remote <alias>]", description: "Show the remote orchestration state.", primary: true },
|
|
757
|
+
{ command: "tasks [--remote <alias>]", description: "List the remote's tracked tasks.", primary: true },
|
|
758
|
+
{ command: "watch [--remote <alias>] [--seconds <n>] [--event <type>]", description: "Stream remote orchestration events.", primary: true },
|
|
759
|
+
{ command: "pause [--remote <alias>]", description: "Pause the running remote orchestration.", primary: true },
|
|
760
|
+
{ command: "resume [--remote <alias>] [--max-workers <n>] [--max-iterations <n>] [--direct-merge]", description: "Resume the remote with optional tuning.", primary: true },
|
|
761
|
+
{ command: "continue [--remote <alias>]", description: "Continue a paused remote orchestration.", primary: true },
|
|
762
|
+
{ command: "stop [--remote <alias>]", description: "Stop the remote orchestration.", primary: true },
|
|
763
|
+
{ command: "refresh [--remote <alias>]", description: "Refresh remote state.", primary: true },
|
|
764
|
+
{ command: "add-iterations [--count <n>] [--remote <alias>]", description: "Grant the remote more iterations.", primary: true },
|
|
765
|
+
{ command: "remove-iterations [--count <n>] [--remote <alias>]", description: "Reduce the remote's iteration budget.", primary: true },
|
|
766
|
+
{ command: "endpoint list", description: "List configured remote endpoints.", primary: true },
|
|
767
|
+
{ command: "endpoint add --alias <alias> --host <host> --port <n> [--token <token>]", description: "Register a remote endpoint.", primary: true },
|
|
768
|
+
{ command: "endpoint remove --alias <alias>", description: "Remove a remote endpoint.", primary: true },
|
|
769
|
+
{ command: "endpoint test [--alias <alias>]", description: "Test connectivity to a remote endpoint.", primary: true },
|
|
770
|
+
{ command: "endpoint doctor", description: "Diagnose remote endpoint configuration.", primary: true }
|
|
771
|
+
]
|
|
772
|
+
},
|
|
773
|
+
{ name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
|
|
774
|
+
{ name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
|
|
775
|
+
{ name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
|
|
776
|
+
];
|
|
777
|
+
var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
|
|
778
|
+
|
|
779
|
+
// packages/cli/src/app-opentui/surface-catalog.ts
|
|
780
|
+
var BESPOKE_FAMILIES = new Set([
|
|
781
|
+
"run",
|
|
782
|
+
"task",
|
|
783
|
+
"inbox",
|
|
784
|
+
"server",
|
|
785
|
+
"init",
|
|
786
|
+
"doctor",
|
|
787
|
+
"pi",
|
|
788
|
+
"plugin",
|
|
789
|
+
"repo",
|
|
790
|
+
"workspace",
|
|
791
|
+
"inspect"
|
|
792
|
+
]);
|
|
793
|
+
var SAFE_DIRECT_COMMANDS = new Set([
|
|
794
|
+
"server status",
|
|
795
|
+
"server list",
|
|
796
|
+
"server use local",
|
|
797
|
+
"task list",
|
|
798
|
+
"task next",
|
|
799
|
+
"task ready",
|
|
800
|
+
"run list",
|
|
801
|
+
"run status",
|
|
802
|
+
"inbox approvals",
|
|
803
|
+
"inbox inputs",
|
|
804
|
+
"stats show",
|
|
805
|
+
"plugin list",
|
|
806
|
+
"doctor doctor",
|
|
807
|
+
"doctor check",
|
|
808
|
+
"github auth status",
|
|
809
|
+
"browser help",
|
|
810
|
+
"browser explain",
|
|
811
|
+
"pi list",
|
|
812
|
+
"pi search",
|
|
813
|
+
"setup check",
|
|
814
|
+
"profile show",
|
|
815
|
+
"review show",
|
|
816
|
+
"repo sync",
|
|
817
|
+
"agent list",
|
|
818
|
+
"dist doctor",
|
|
819
|
+
"workspace summary",
|
|
820
|
+
"remote status"
|
|
821
|
+
]);
|
|
822
|
+
|
|
823
|
+
// packages/cli/src/app-opentui/intent.ts
|
|
824
|
+
var NAV_SCENES = new Map([
|
|
825
|
+
["", "main"],
|
|
826
|
+
["main", "main"],
|
|
827
|
+
["home", "main"],
|
|
828
|
+
["fleet", "fleet"],
|
|
829
|
+
["runs", "fleet"],
|
|
830
|
+
["run", "fleet"],
|
|
831
|
+
["tasks", "tasks"],
|
|
832
|
+
["task", "tasks"],
|
|
833
|
+
["inbox", "inbox"],
|
|
834
|
+
["server", "server"],
|
|
835
|
+
["init", "init"],
|
|
836
|
+
["doctor", "doctor"],
|
|
837
|
+
["pi", "pi"],
|
|
838
|
+
["plugin", "plugin"],
|
|
839
|
+
["repo", "repo"],
|
|
840
|
+
["workspace", "workspace"],
|
|
841
|
+
["inspect", "inspect"],
|
|
842
|
+
["help", "help"]
|
|
843
|
+
]);
|
|
844
|
+
var TASK_VIEW_COMMANDS = new Set([
|
|
845
|
+
"",
|
|
846
|
+
"all",
|
|
847
|
+
"open",
|
|
848
|
+
"ready",
|
|
849
|
+
"blocked",
|
|
850
|
+
"closed",
|
|
851
|
+
"done",
|
|
852
|
+
"mine",
|
|
853
|
+
"me",
|
|
854
|
+
"sort",
|
|
855
|
+
"status",
|
|
856
|
+
"state",
|
|
857
|
+
"assignee",
|
|
858
|
+
"assigned",
|
|
859
|
+
"label",
|
|
860
|
+
"search",
|
|
861
|
+
"q"
|
|
862
|
+
]);
|
|
863
|
+
var HOLLOW_FAMILIES = new Set([
|
|
864
|
+
"browser",
|
|
865
|
+
"stats",
|
|
866
|
+
"dist",
|
|
867
|
+
"agent",
|
|
868
|
+
"queue",
|
|
869
|
+
"remote",
|
|
870
|
+
"harness",
|
|
871
|
+
"git",
|
|
872
|
+
"setup",
|
|
873
|
+
"profile",
|
|
874
|
+
"review",
|
|
875
|
+
"inspector",
|
|
876
|
+
"test"
|
|
877
|
+
]);
|
|
878
|
+
|
|
879
|
+
// packages/cli/src/app-opentui/pi-pty-host.ts
|
|
880
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
881
|
+
import { basename as basename2 } from "path";
|
|
882
|
+
import { RGBA as RGBA2, StyledText as StyledText2, TextAttributes as TextAttributes2 } from "@opentui/core";
|
|
883
|
+
import { Terminal as XtermTerminal2 } from "@xterm/headless";
|
|
884
|
+
var MIN_COLS2 = 40;
|
|
885
|
+
var MIN_ROWS2 = 12;
|
|
886
|
+
var MAX_ROWS2 = 300;
|
|
887
|
+
var MAX_SNAPSHOT_LINES2 = 360;
|
|
888
|
+
var STYLED_SNAPSHOT_MARGIN = 6;
|
|
889
|
+
var SNAPSHOT_DELAY_MS2 = 120;
|
|
890
|
+
var fallbackChildScriptPath = fileURLToPath2(new URL("./pi-host-child.ts", import.meta.url));
|
|
891
|
+
var activeHost2 = null;
|
|
892
|
+
function clampCols2(cols) {
|
|
893
|
+
return Math.max(MIN_COLS2, Math.trunc(cols || 100));
|
|
894
|
+
}
|
|
895
|
+
function clampRows2(rows) {
|
|
896
|
+
return Math.max(MIN_ROWS2, Math.min(MAX_ROWS2, Math.trunc(rows || 35)));
|
|
897
|
+
}
|
|
898
|
+
var XTERM_COLOR_MODE_INDEXED_16 = 16777216;
|
|
899
|
+
var XTERM_COLOR_MODE_INDEXED_256 = 33554432;
|
|
900
|
+
var XTERM_COLOR_MODE_RGB = 50331648;
|
|
901
|
+
function rgbaFromXtermColor(mode, value) {
|
|
902
|
+
if (mode === 1 || mode === 2 || mode === XTERM_COLOR_MODE_INDEXED_16 || mode === XTERM_COLOR_MODE_INDEXED_256) {
|
|
903
|
+
return RGBA2.fromIndex(value);
|
|
904
|
+
}
|
|
905
|
+
if (mode === 3 || mode === XTERM_COLOR_MODE_RGB) {
|
|
906
|
+
return RGBA2.fromInts(value >> 16 & 255, value >> 8 & 255, value & 255);
|
|
907
|
+
}
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
function textAttributesFromCell(cell) {
|
|
911
|
+
let attributes = TextAttributes2.NONE;
|
|
912
|
+
if (cell.isBold())
|
|
913
|
+
attributes |= TextAttributes2.BOLD;
|
|
914
|
+
if (cell.isDim())
|
|
915
|
+
attributes |= TextAttributes2.DIM;
|
|
916
|
+
if (cell.isItalic())
|
|
917
|
+
attributes |= TextAttributes2.ITALIC;
|
|
918
|
+
if (cell.isUnderline())
|
|
919
|
+
attributes |= TextAttributes2.UNDERLINE;
|
|
920
|
+
if (cell.isBlink())
|
|
921
|
+
attributes |= TextAttributes2.BLINK;
|
|
922
|
+
if (cell.isInverse())
|
|
923
|
+
attributes |= TextAttributes2.INVERSE;
|
|
924
|
+
if (cell.isInvisible())
|
|
925
|
+
attributes |= TextAttributes2.HIDDEN;
|
|
926
|
+
if (cell.isStrikethrough())
|
|
927
|
+
attributes |= TextAttributes2.STRIKETHROUGH;
|
|
928
|
+
return attributes;
|
|
929
|
+
}
|
|
930
|
+
function sameRgba(a, b) {
|
|
931
|
+
if (!a && !b)
|
|
932
|
+
return true;
|
|
933
|
+
return Boolean(a && b && a.equals(b));
|
|
934
|
+
}
|
|
935
|
+
function sameStyle(a, b) {
|
|
936
|
+
return sameRgba(a.fg, b.fg) && sameRgba(a.bg, b.bg) && (a.attributes ?? 0) === (b.attributes ?? 0);
|
|
937
|
+
}
|
|
938
|
+
function styleFromCell(cell) {
|
|
939
|
+
return {
|
|
940
|
+
fg: rgbaFromXtermColor(cell.getFgColorMode(), cell.getFgColor()),
|
|
941
|
+
bg: rgbaFromXtermColor(cell.getBgColorMode(), cell.getBgColor()),
|
|
942
|
+
attributes: textAttributesFromCell(cell)
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
function lineToStyledText(line, cols) {
|
|
946
|
+
if (!line)
|
|
947
|
+
return new StyledText2([{ __isChunk: true, text: "" }]);
|
|
948
|
+
const chunks = [];
|
|
949
|
+
let run = "";
|
|
950
|
+
let runStyle = null;
|
|
951
|
+
const flush = () => {
|
|
952
|
+
if (!run)
|
|
953
|
+
return;
|
|
954
|
+
chunks.push({
|
|
955
|
+
__isChunk: true,
|
|
956
|
+
text: run,
|
|
957
|
+
...runStyle?.fg ? { fg: runStyle.fg } : {},
|
|
958
|
+
...runStyle?.bg ? { bg: runStyle.bg } : {},
|
|
959
|
+
...(runStyle?.attributes ?? 0) !== 0 ? { attributes: runStyle.attributes } : {}
|
|
960
|
+
});
|
|
961
|
+
run = "";
|
|
962
|
+
};
|
|
963
|
+
for (let index = 0;index < cols; index += 1) {
|
|
964
|
+
const cell = line.getCell(index);
|
|
965
|
+
if (!cell) {
|
|
966
|
+
if (runStyle !== null)
|
|
967
|
+
flush();
|
|
968
|
+
runStyle = null;
|
|
969
|
+
run += " ";
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
if (cell.getWidth() === 0)
|
|
973
|
+
continue;
|
|
974
|
+
const style = styleFromCell(cell);
|
|
975
|
+
if (!runStyle || !sameStyle(runStyle, style)) {
|
|
976
|
+
flush();
|
|
977
|
+
runStyle = style;
|
|
978
|
+
}
|
|
979
|
+
run += cell.getChars() || " ";
|
|
980
|
+
}
|
|
981
|
+
flush();
|
|
982
|
+
return new StyledText2(chunks.length > 0 ? chunks : [{ __isChunk: true, text: "" }]);
|
|
983
|
+
}
|
|
984
|
+
function childCommandPrefix2() {
|
|
985
|
+
const execName = basename2(process.execPath).toLowerCase();
|
|
986
|
+
const currentEntry = process.argv[1];
|
|
987
|
+
if (execName === "bun" || execName === "bun.exe") {
|
|
988
|
+
return currentEntry ? [process.execPath, currentEntry, "__opentui-pi-host"] : [process.execPath, fallbackChildScriptPath];
|
|
989
|
+
}
|
|
990
|
+
return [process.execPath, "__opentui-pi-host"];
|
|
991
|
+
}
|
|
992
|
+
function withEnv2(base) {
|
|
993
|
+
const env = {};
|
|
994
|
+
for (const [key, value] of Object.entries(base ?? process.env)) {
|
|
995
|
+
if (key === "RIG_PLAIN" || key === "RIG_CLI_PLAIN_HELP" || key === "NO_COLOR")
|
|
996
|
+
continue;
|
|
997
|
+
if (typeof value === "string")
|
|
998
|
+
env[key] = value;
|
|
999
|
+
}
|
|
1000
|
+
return {
|
|
1001
|
+
...env,
|
|
1002
|
+
TERM: "xterm-256color",
|
|
1003
|
+
COLORTERM: "truecolor",
|
|
1004
|
+
FORCE_COLOR: env.FORCE_COLOR ?? "1",
|
|
1005
|
+
RIG_OPENTUI_PI_HOST: "1"
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
class PiPtyHost {
|
|
1009
|
+
runId;
|
|
1010
|
+
projectRoot;
|
|
1011
|
+
onSnapshot;
|
|
1012
|
+
onExit;
|
|
1013
|
+
onError;
|
|
1014
|
+
terminal;
|
|
1015
|
+
disposables = [];
|
|
1016
|
+
decoder = new TextDecoder("utf-8");
|
|
1017
|
+
proc = null;
|
|
1018
|
+
pty = null;
|
|
1019
|
+
status = "starting";
|
|
1020
|
+
cols;
|
|
1021
|
+
rows;
|
|
1022
|
+
message = "starting bundled Pi";
|
|
1023
|
+
lastResizeError = null;
|
|
1024
|
+
exitCode;
|
|
1025
|
+
signal;
|
|
1026
|
+
notifyTimer = null;
|
|
1027
|
+
lastStreamKey = "";
|
|
1028
|
+
_disposed = false;
|
|
1029
|
+
constructor(options) {
|
|
1030
|
+
this.runId = options.runId;
|
|
1031
|
+
this.projectRoot = options.projectRoot;
|
|
1032
|
+
this.cols = clampCols2(options.cols);
|
|
1033
|
+
this.rows = clampRows2(options.rows);
|
|
1034
|
+
this.onSnapshot = options.onSnapshot;
|
|
1035
|
+
this.onExit = options.onExit;
|
|
1036
|
+
this.onError = options.onError;
|
|
1037
|
+
this.terminal = new XtermTerminal2({
|
|
1038
|
+
allowProposedApi: true,
|
|
1039
|
+
cols: this.cols,
|
|
1040
|
+
rows: this.rows,
|
|
1041
|
+
scrollback: 1000
|
|
1042
|
+
});
|
|
1043
|
+
this.registerTerminalResponders();
|
|
1044
|
+
this.disposables.push(this.terminal.onWriteParsed(() => {
|
|
1045
|
+
if (this._disposed)
|
|
1046
|
+
return;
|
|
1047
|
+
const snapshot = this.createSnapshot();
|
|
1048
|
+
const key = snapshot.lines.join(`
|
|
1049
|
+
`);
|
|
1050
|
+
if (key === this.lastStreamKey)
|
|
1051
|
+
return;
|
|
1052
|
+
this.lastStreamKey = key;
|
|
1053
|
+
this.onSnapshot?.(snapshot);
|
|
1054
|
+
}));
|
|
1055
|
+
}
|
|
1056
|
+
get disposed() {
|
|
1057
|
+
return this._disposed;
|
|
1058
|
+
}
|
|
1059
|
+
get snapshot() {
|
|
1060
|
+
return this.createSnapshot();
|
|
1061
|
+
}
|
|
1062
|
+
async start() {
|
|
1063
|
+
if (this._disposed)
|
|
1064
|
+
throw new Error("Pi PTY host is disposed.");
|
|
1065
|
+
if (typeof Bun.Terminal !== "function") {
|
|
1066
|
+
throw new Error("Bun native PTY is unavailable in this runtime. Pi host requires Bun.Terminal.");
|
|
1067
|
+
}
|
|
1068
|
+
const spawnOptions = {
|
|
1069
|
+
cwd: this.projectRoot,
|
|
1070
|
+
env: withEnv2(process.env),
|
|
1071
|
+
terminal: {
|
|
1072
|
+
cols: this.cols,
|
|
1073
|
+
rows: this.rows,
|
|
1074
|
+
name: "xterm-256color",
|
|
1075
|
+
data: (_terminal, data) => this.handlePtyData(data)
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
const proc = Bun.spawn([
|
|
1079
|
+
...childCommandPrefix2(),
|
|
1080
|
+
"--run-id",
|
|
1081
|
+
this.runId,
|
|
1082
|
+
"--project-root",
|
|
1083
|
+
this.projectRoot
|
|
1084
|
+
], spawnOptions);
|
|
1085
|
+
if (!proc.terminal)
|
|
1086
|
+
throw new Error("Bun did not attach a terminal to the bundled Pi child process.");
|
|
1087
|
+
this.proc = proc;
|
|
1088
|
+
this.pty = proc.terminal;
|
|
1089
|
+
this.status = "running";
|
|
1090
|
+
this.message = "bundled Pi running inside this app";
|
|
1091
|
+
this.emitSnapshotSoon(0);
|
|
1092
|
+
proc.exited.then((exitCode) => {
|
|
1093
|
+
if (this._disposed)
|
|
1094
|
+
return;
|
|
1095
|
+
this.status = exitCode === 0 ? "exited" : "failed";
|
|
1096
|
+
this.exitCode = exitCode;
|
|
1097
|
+
this.signal = null;
|
|
1098
|
+
this.message = exitCode === 0 ? "bundled Pi exited" : `bundled Pi exited with code ${exitCode}`;
|
|
1099
|
+
const snapshot = this.createSnapshot();
|
|
1100
|
+
this.onSnapshot?.(snapshot);
|
|
1101
|
+
this.onExit?.(snapshot);
|
|
1102
|
+
if (activeHost2 === this)
|
|
1103
|
+
activeHost2 = null;
|
|
1104
|
+
this.dispose("exit", { kill: false, notify: false });
|
|
1105
|
+
}).catch((error) => {
|
|
1106
|
+
if (this._disposed)
|
|
1107
|
+
return;
|
|
1108
|
+
this.status = "failed";
|
|
1109
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
1110
|
+
const snapshot = this.createSnapshot();
|
|
1111
|
+
this.onSnapshot?.(snapshot);
|
|
1112
|
+
this.onError?.(error, snapshot);
|
|
1113
|
+
if (activeHost2 === this)
|
|
1114
|
+
activeHost2 = null;
|
|
1115
|
+
this.dispose("error", { kill: false, notify: false });
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
write(data) {
|
|
1119
|
+
if (this._disposed || !this.pty)
|
|
1120
|
+
return;
|
|
1121
|
+
try {
|
|
1122
|
+
this.pty.write(data);
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
this.status = "failed";
|
|
1125
|
+
this.message = error instanceof Error ? error.message : String(error);
|
|
1126
|
+
const snapshot = this.createSnapshot();
|
|
1127
|
+
this.onSnapshot?.(snapshot);
|
|
1128
|
+
this.onError?.(error, snapshot);
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
resize(cols, rows) {
|
|
1132
|
+
const nextCols = clampCols2(cols);
|
|
1133
|
+
const nextRows = clampRows2(rows);
|
|
1134
|
+
if (nextCols === this.cols && nextRows === this.rows)
|
|
1135
|
+
return;
|
|
1136
|
+
this.cols = nextCols;
|
|
1137
|
+
this.rows = nextRows;
|
|
1138
|
+
this.terminal.resize(nextCols, nextRows);
|
|
1139
|
+
try {
|
|
1140
|
+
this.pty?.resize(nextCols, nextRows);
|
|
1141
|
+
this.lastResizeError = null;
|
|
1142
|
+
} catch (error) {
|
|
1143
|
+
this.lastResizeError = error instanceof Error ? error.message : String(error);
|
|
1144
|
+
}
|
|
1145
|
+
this.emitSnapshotSoon(0);
|
|
1146
|
+
}
|
|
1147
|
+
detach() {
|
|
1148
|
+
this.dispose("detach");
|
|
1149
|
+
return this.createSnapshot("detached from bundled Pi");
|
|
1150
|
+
}
|
|
1151
|
+
dispose(reason = "dispose", options = {}) {
|
|
1152
|
+
if (this._disposed)
|
|
1153
|
+
return;
|
|
1154
|
+
this._disposed = true;
|
|
1155
|
+
if (this.notifyTimer)
|
|
1156
|
+
clearTimeout(this.notifyTimer);
|
|
1157
|
+
this.notifyTimer = null;
|
|
1158
|
+
for (const disposable of this.disposables.splice(0)) {
|
|
1159
|
+
try {
|
|
1160
|
+
disposable.dispose();
|
|
1161
|
+
} catch {}
|
|
1162
|
+
}
|
|
1163
|
+
if (options.kill !== false) {
|
|
1164
|
+
try {
|
|
1165
|
+
this.proc?.kill("SIGTERM");
|
|
1166
|
+
} catch {}
|
|
1167
|
+
}
|
|
1168
|
+
try {
|
|
1169
|
+
this.pty?.close();
|
|
1170
|
+
} catch {}
|
|
1171
|
+
try {
|
|
1172
|
+
this.terminal.dispose();
|
|
1173
|
+
} catch {}
|
|
1174
|
+
if (activeHost2 === this)
|
|
1175
|
+
activeHost2 = null;
|
|
1176
|
+
if (options.notify) {
|
|
1177
|
+
this.message = reason;
|
|
1178
|
+
this.onSnapshot?.(this.createSnapshot(reason));
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
handlePtyData(data) {
|
|
1182
|
+
if (this._disposed)
|
|
1183
|
+
return;
|
|
1184
|
+
const text = this.decoder.decode(data, { stream: true });
|
|
1185
|
+
this.respondToRawTerminalQueries(text);
|
|
1186
|
+
this.terminal.write(data);
|
|
1187
|
+
}
|
|
1188
|
+
emitSnapshotSoon(delayMs = SNAPSHOT_DELAY_MS2) {
|
|
1189
|
+
if (this._disposed || this.notifyTimer)
|
|
1190
|
+
return;
|
|
1191
|
+
this.notifyTimer = setTimeout(() => {
|
|
1192
|
+
this.notifyTimer = null;
|
|
1193
|
+
if (this._disposed)
|
|
1194
|
+
return;
|
|
1195
|
+
this.onSnapshot?.(this.createSnapshot());
|
|
1196
|
+
}, delayMs);
|
|
1197
|
+
}
|
|
1198
|
+
createSnapshot(message = this.message) {
|
|
1199
|
+
const buffer = this.terminal.buffer.active;
|
|
1200
|
+
const end = buffer.length;
|
|
1201
|
+
const start = Math.max(0, end - MAX_SNAPSHOT_LINES2);
|
|
1202
|
+
const styledStart = Math.max(start, end - this.rows - STYLED_SNAPSHOT_MARGIN);
|
|
1203
|
+
const lines = [];
|
|
1204
|
+
const styledLines = [];
|
|
1205
|
+
for (let row = start;row < end; row += 1) {
|
|
1206
|
+
const line = buffer.getLine(row);
|
|
1207
|
+
lines.push((line?.translateToString(false) ?? "").slice(0, this.cols));
|
|
1208
|
+
if (row >= styledStart)
|
|
1209
|
+
styledLines[lines.length - 1] = lineToStyledText(line, this.cols);
|
|
1210
|
+
}
|
|
1211
|
+
while (lines.length < this.rows) {
|
|
1212
|
+
lines.push("");
|
|
1213
|
+
styledLines[lines.length - 1] = new StyledText2([{ __isChunk: true, text: "" }]);
|
|
1214
|
+
}
|
|
1215
|
+
const resolvedMessage = this.lastResizeError ? `resize degraded: ${this.lastResizeError}` : message;
|
|
1216
|
+
return {
|
|
1217
|
+
runId: this.runId,
|
|
1218
|
+
status: this.status,
|
|
1219
|
+
cols: this.cols,
|
|
1220
|
+
rows: this.rows,
|
|
1221
|
+
lines,
|
|
1222
|
+
styledLines,
|
|
1223
|
+
message: resolvedMessage,
|
|
1224
|
+
...this.lastResizeError ? { resizeError: this.lastResizeError } : {},
|
|
1225
|
+
...this.exitCode !== undefined ? { exitCode: this.exitCode } : {},
|
|
1226
|
+
...this.signal !== undefined ? { signal: this.signal } : {}
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
registerTerminalResponders() {
|
|
1230
|
+
this.disposables.push(this.terminal.parser.registerCsiHandler({ final: "c" }, (params) => {
|
|
1231
|
+
if (params.length === 0 || params[0] === 0)
|
|
1232
|
+
this.write("\x1B[?62;22c");
|
|
1233
|
+
return false;
|
|
1234
|
+
}));
|
|
1235
|
+
this.disposables.push(this.terminal.parser.registerCsiHandler({ prefix: ">", final: "c" }, (params) => {
|
|
1236
|
+
if (params.length === 0 || params[0] === 0)
|
|
1237
|
+
this.write("\x1B[>0;0;0c");
|
|
1238
|
+
return false;
|
|
1239
|
+
}));
|
|
1240
|
+
this.disposables.push(this.terminal.parser.registerCsiHandler({ final: "n" }, (params) => {
|
|
1241
|
+
if (params[0] === 5) {
|
|
1242
|
+
this.write("\x1B[0n");
|
|
1243
|
+
} else if (params[0] === 6) {
|
|
1244
|
+
const row = this.terminal.buffer.active.cursorY + 1;
|
|
1245
|
+
const col = this.terminal.buffer.active.cursorX + 1;
|
|
1246
|
+
this.write(`\x1B[${row};${col}R`);
|
|
1247
|
+
}
|
|
1248
|
+
return false;
|
|
1249
|
+
}));
|
|
1250
|
+
}
|
|
1251
|
+
respondToRawTerminalQueries(text) {
|
|
1252
|
+
if (!text)
|
|
1253
|
+
return;
|
|
1254
|
+
const decrqm = /\x1b\[\?(\d+)\$p/g;
|
|
1255
|
+
let match;
|
|
1256
|
+
while ((match = decrqm.exec(text)) !== null) {
|
|
1257
|
+
this.write(`\x1B[?${match[1]};2$y`);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// packages/cli/src/commands/_server-events.ts
|
|
1263
|
+
import { WsTransport } from "@rig/client";
|
|
1264
|
+
import { RIG_WS_CHANNELS } from "@rig/contracts";
|
|
1265
|
+
|
|
1266
|
+
// packages/cli/src/runner.ts
|
|
1267
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
1268
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
1269
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
1270
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
1271
|
+
|
|
1272
|
+
// packages/cli/src/commands/_server-client.ts
|
|
1273
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
1274
|
+
var scopedGitHubBearerTokens = new Map;
|
|
1275
|
+
var serverReachabilityCache = new Map;
|
|
1276
|
+
var RESUMABLE_RUN_STATUSES = new Set([
|
|
1277
|
+
"created",
|
|
1278
|
+
"preparing",
|
|
1279
|
+
"running",
|
|
1280
|
+
"validating",
|
|
1281
|
+
"reviewing",
|
|
1282
|
+
"stopped",
|
|
1283
|
+
"failed",
|
|
1284
|
+
"needs-attention",
|
|
1285
|
+
"needs_attention"
|
|
1286
|
+
]);
|
|
1287
|
+
|
|
1288
|
+
// packages/cli/src/app-opentui/drone.ts
|
|
1289
|
+
import { RGBA as RGBA3, StyledText as StyledText3, TextAttributes as TextAttributes3 } from "@opentui/core";
|
|
1290
|
+
var COLOR = {
|
|
1291
|
+
body: RGBA3.fromHex(RIG_UI.lime),
|
|
1292
|
+
mini: RGBA3.fromHex(RIG_UI.limeDim),
|
|
1293
|
+
rotor: RGBA3.fromHex(RIG_UI.cyan),
|
|
1294
|
+
path: RGBA3.fromHex(RIG_UI.cyan),
|
|
1295
|
+
eye: RGBA3.fromHex(RIG_UI.ink),
|
|
1296
|
+
dim: RGBA3.fromHex(RIG_UI.ink4),
|
|
1297
|
+
ink: RGBA3.fromHex(RIG_UI.ink2)
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
// packages/cli/src/app-opentui/render/graphics.ts
|
|
1301
|
+
import { FrameBufferRenderable, RGBA as RGBA4 } from "@opentui/core";
|
|
1302
|
+
|
|
1303
|
+
// packages/cli/src/app-opentui/render/ascii-fleet.ts
|
|
1304
|
+
var LEAD_DRONE = [
|
|
1305
|
+
" .-=-. .-=-. ",
|
|
1306
|
+
" ( !!! ) ( !!! ) ",
|
|
1307
|
+
" '-=-'._ _.'-=-' ",
|
|
1308
|
+
" '._ _.' ",
|
|
1309
|
+
" '=$$$$$$$=.' ",
|
|
1310
|
+
" =$$$$$$$$$$$= ",
|
|
1311
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
1312
|
+
" $$$@@ @@$$$ ",
|
|
1313
|
+
" $$@ ? @$$$ ",
|
|
1314
|
+
" $$$@ '-' @$$$ ",
|
|
1315
|
+
" $$$@@ @@$$$ ",
|
|
1316
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
1317
|
+
" =$$$$$$$$$$$= ",
|
|
1318
|
+
" '=$$$$$$$=.' ",
|
|
1319
|
+
" _.' '._ ",
|
|
1320
|
+
" .-=-.' '.-=-. ",
|
|
1321
|
+
" ( !!! ) ( !!! ) ",
|
|
1322
|
+
" '-=-' '-=-' "
|
|
1323
|
+
];
|
|
1324
|
+
var MINI_DRONE = [
|
|
1325
|
+
"(!!!) (!!!)",
|
|
1326
|
+
" \\%==%/ ",
|
|
1327
|
+
" %%?%% ",
|
|
1328
|
+
" /%==%\\ ",
|
|
1329
|
+
"(!!!) (!!!)"
|
|
1330
|
+
];
|
|
1331
|
+
var ROTORS = ["---", "\\\\\\", "|||", "///"];
|
|
1332
|
+
var FLEET_GRID_WIDTH = 52;
|
|
1333
|
+
var FLEET_GRID_HEIGHT = 27;
|
|
1334
|
+
var FLEET = [
|
|
1335
|
+
{ art: MINI_DRONE, x: 0, y: 2, amp: 1, speed: 0.05, phase: 0, dx: 1, driftSpeed: 0.02 },
|
|
1336
|
+
{ art: MINI_DRONE, x: 39, y: 2, amp: 1, speed: 0.044, phase: 2.1, dx: 1, driftSpeed: 0.017 },
|
|
1337
|
+
{ art: MINI_DRONE, x: 1, y: 20, amp: 1, speed: 0.048, phase: 4.2, dx: 1, driftSpeed: 0.023 },
|
|
1338
|
+
{ art: MINI_DRONE, x: 38, y: 20, amp: 1, speed: 0.041, phase: 1.3, dx: 1, driftSpeed: 0.015 },
|
|
1339
|
+
{ art: LEAD_DRONE, x: 10, y: 5, amp: 2, speed: 0.04, phase: 0, dx: 0, driftSpeed: 0.011 }
|
|
1340
|
+
];
|
|
1341
|
+
function fleetRows(tick, options = {}) {
|
|
1342
|
+
const animate = options.animate ?? true;
|
|
1343
|
+
const t2 = animate ? tick : 0;
|
|
1344
|
+
const blade = ROTORS[Math.floor(t2 / 4) % ROTORS.length];
|
|
1345
|
+
const pulse = Math.sin(t2 * 0.07);
|
|
1346
|
+
const eye = pulse > 0.45 ? "@" : pulse > -0.1 ? "o" : ".";
|
|
1347
|
+
const grid = Array.from({ length: FLEET_GRID_HEIGHT }, () => Array.from({ length: FLEET_GRID_WIDTH }, () => " "));
|
|
1348
|
+
for (const drone of FLEET) {
|
|
1349
|
+
const yOffset = drone.y + Math.round(drone.amp * Math.sin(t2 * drone.speed + drone.phase));
|
|
1350
|
+
const xOffset = drone.x + Math.round(drone.dx * Math.sin(t2 * drone.driftSpeed + drone.phase));
|
|
1351
|
+
for (let row = 0;row < drone.art.length; row += 1) {
|
|
1352
|
+
const source = drone.art[row];
|
|
1353
|
+
const targetY = yOffset + row;
|
|
1354
|
+
if (targetY < 0 || targetY >= FLEET_GRID_HEIGHT)
|
|
1355
|
+
continue;
|
|
1356
|
+
for (let col = 0;col < source.length; col += 1) {
|
|
1357
|
+
let char = source[col];
|
|
1358
|
+
if (char === " ")
|
|
1359
|
+
continue;
|
|
1360
|
+
const targetX = xOffset + col;
|
|
1361
|
+
if (targetX < 0 || targetX >= FLEET_GRID_WIDTH)
|
|
1362
|
+
continue;
|
|
1363
|
+
if (source.slice(col, col + 3) === "!!!") {
|
|
1364
|
+
for (let rotorIndex = 0;rotorIndex < 3; rotorIndex += 1) {
|
|
1365
|
+
if (targetX + rotorIndex < FLEET_GRID_WIDTH)
|
|
1366
|
+
grid[targetY][targetX + rotorIndex] = blade[rotorIndex];
|
|
1367
|
+
}
|
|
1368
|
+
col += 2;
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
if (char === "?")
|
|
1372
|
+
char = eye;
|
|
1373
|
+
grid[targetY][targetX] = char;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
return grid.map((row) => row.join("").replace(/\s+$/, ""));
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
// packages/cli/src/app-opentui/render/panel-layout.ts
|
|
1381
|
+
function panelPixelPlacement(layout, panel, size, minPixels = 8) {
|
|
1382
|
+
const cellW = size.width / layout.width;
|
|
1383
|
+
const cellH = size.height / layout.height;
|
|
1384
|
+
const leftCells = layout.centerLeft + (panel.left ?? 0);
|
|
1385
|
+
const topCells = layout.centerTop + panel.top;
|
|
1386
|
+
const widthCells = panel.width ?? layout.centerWidth;
|
|
1387
|
+
const heightCells = panel.height;
|
|
1388
|
+
const left = Math.round(leftCells * cellW);
|
|
1389
|
+
const top = Math.round(topCells * cellH);
|
|
1390
|
+
const width = Math.round(widthCells * cellW);
|
|
1391
|
+
const height = Math.round(heightCells * cellH);
|
|
1392
|
+
return width > minPixels && height > minPixels ? { left, top, width, height, leftCells, topCells, widthCells, heightCells } : null;
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
// packages/cli/src/app-opentui/render/constants.ts
|
|
1396
|
+
var LCG_MULTIPLIER = 1664525;
|
|
1397
|
+
var LCG_INCREMENT = 1013904223;
|
|
1398
|
+
var LCG_DIVISOR = 4294967295;
|
|
1399
|
+
var PACKET_CYAN_PROBABILITY = 0.22;
|
|
1400
|
+
var LANE_INTERP_STEPS = 32;
|
|
1401
|
+
var LANE_LEN_BASE = 0.32;
|
|
1402
|
+
var LANE_LEN_SPREAD = 0.42;
|
|
1403
|
+
var LANE_CURVE_RANGE = 0.7;
|
|
1404
|
+
var PACKET_SPEED_BASE = 0.003;
|
|
1405
|
+
var PACKET_SPEED_SPREAD = 0.009;
|
|
1406
|
+
var DISPATCH_LANES_COMPACT = 7;
|
|
1407
|
+
var DISPATCH_LANES_WIDE = 12;
|
|
1408
|
+
var DISPATCH_PACKETS_COMPACT = 70;
|
|
1409
|
+
var DISPATCH_PACKETS_WIDE = 150;
|
|
1410
|
+
var CARRIER_NODES_COMPACT = 5;
|
|
1411
|
+
var CARRIER_NODES_WIDE = 7;
|
|
1412
|
+
var LOOP_GATES_COMPACT = 4;
|
|
1413
|
+
var LOOP_GATES_WIDE = 5;
|
|
1414
|
+
var DISPATCH_DRONES_COMPACT = 4;
|
|
1415
|
+
var DISPATCH_DRONES_WIDE = 8;
|
|
1416
|
+
var CORE_DISPATCH_X = 0.3;
|
|
1417
|
+
var CORE_DISPATCH_Y = 0.45;
|
|
1418
|
+
var CORE_CARRIER_X = 0.5;
|
|
1419
|
+
var CORE_CARRIER_Y = 0.54;
|
|
1420
|
+
var CORE_LOOP_X = 0.09;
|
|
1421
|
+
var CORE_LOOP_Y = 0.56;
|
|
1422
|
+
var RAIL_YS_LOOP = [0.18, 0.5, 0.82];
|
|
1423
|
+
var RAIL_YS_CARRIER = [0.24, 0.54, 0.82];
|
|
1424
|
+
var RAIL_YS_DISPATCH = [0.18, 0.58, 0.82];
|
|
1425
|
+
var GLOW_FALLOFF_EXP_ASCII = 2.2;
|
|
1426
|
+
var GLOW_FALLOFF_EXP_IMAGE = 2.4;
|
|
1427
|
+
|
|
1428
|
+
// packages/cli/src/app-opentui/render/graphics.ts
|
|
1429
|
+
var BRAILLE_SAMPLES_X = 2;
|
|
1430
|
+
var BRAILLE_SAMPLES_Y = 4;
|
|
1431
|
+
var TRANSPARENT = RGBA4.fromValues(0, 0, 0, 0);
|
|
1432
|
+
var BACKDROP = RGBA4.fromHex(RIG_UI.bg);
|
|
1433
|
+
var PANEL_BG = RGBA4.fromInts(16, 17, 21, 184);
|
|
1434
|
+
var PANEL_HEADER_BG = RGBA4.fromInts(16, 17, 21, 188);
|
|
1435
|
+
var PANEL_LINE = RGBA4.fromInts(255, 255, 255, 20);
|
|
1436
|
+
var PANEL_LINE_DIM = RGBA4.fromInts(255, 255, 255, 8);
|
|
1437
|
+
var PANEL_TEXT_DIM = RGBA4.fromInts(108, 110, 121, 255);
|
|
1438
|
+
var AC_RGB = [204, 255, 77];
|
|
1439
|
+
var C2_RGB = [86, 216, 255];
|
|
1440
|
+
var MG_RGB = [255, 121, 176];
|
|
1441
|
+
var INK_RGB = [108, 110, 121];
|
|
1442
|
+
var BRAILLE_BITS = [
|
|
1443
|
+
[1, 8],
|
|
1444
|
+
[2, 16],
|
|
1445
|
+
[4, 32],
|
|
1446
|
+
[64, 128]
|
|
1447
|
+
];
|
|
1448
|
+
function sceneKind(scene) {
|
|
1449
|
+
if (scene === "tasks")
|
|
1450
|
+
return "loop";
|
|
1451
|
+
if (scene === "help")
|
|
1452
|
+
return "carrier";
|
|
1453
|
+
return "dispatch";
|
|
1454
|
+
}
|
|
1455
|
+
function seeded(seed) {
|
|
1456
|
+
let value = seed >>> 0;
|
|
1457
|
+
return () => {
|
|
1458
|
+
value = value * LCG_MULTIPLIER + LCG_INCREMENT >>> 0;
|
|
1459
|
+
return value / LCG_DIVISOR;
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
function channelBuffer(canvas, channel) {
|
|
1463
|
+
switch (channel) {
|
|
1464
|
+
case 0:
|
|
1465
|
+
return canvas.ac;
|
|
1466
|
+
case 1:
|
|
1467
|
+
return canvas.c2;
|
|
1468
|
+
case 2:
|
|
1469
|
+
return canvas.mg;
|
|
1470
|
+
case 3:
|
|
1471
|
+
return canvas.ink;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
function addSample(canvas, channel, x, y, value) {
|
|
1475
|
+
const ix = Math.trunc(x);
|
|
1476
|
+
const iy = Math.trunc(y);
|
|
1477
|
+
if (ix < 0 || iy < 0 || ix >= canvas.width || iy >= canvas.height)
|
|
1478
|
+
return;
|
|
1479
|
+
const buffer = channelBuffer(canvas, channel);
|
|
1480
|
+
const index = iy * canvas.width + ix;
|
|
1481
|
+
buffer[index] = Math.min(1, buffer[index] + value);
|
|
1482
|
+
}
|
|
1483
|
+
function drawDot(canvas, channel, cx, cy, radius, value) {
|
|
1484
|
+
const minX = Math.floor(cx - radius);
|
|
1485
|
+
const maxX = Math.ceil(cx + radius);
|
|
1486
|
+
const minY = Math.floor(cy - radius);
|
|
1487
|
+
const maxY = Math.ceil(cy + radius);
|
|
1488
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
1489
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
1490
|
+
const dx = x - cx;
|
|
1491
|
+
const dy = y - cy;
|
|
1492
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1493
|
+
if (distance > radius)
|
|
1494
|
+
continue;
|
|
1495
|
+
const falloff = 1 - distance / Math.max(0.001, radius);
|
|
1496
|
+
addSample(canvas, channel, x, y, value * (0.28 + falloff * 0.72));
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
function drawGlow(canvas, channel, cx, cy, radius, value) {
|
|
1501
|
+
const minX = Math.floor(cx - radius);
|
|
1502
|
+
const maxX = Math.ceil(cx + radius);
|
|
1503
|
+
const minY = Math.floor(cy - radius);
|
|
1504
|
+
const maxY = Math.ceil(cy + radius);
|
|
1505
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
1506
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
1507
|
+
const dx = x - cx;
|
|
1508
|
+
const dy = y - cy;
|
|
1509
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1510
|
+
if (distance > radius)
|
|
1511
|
+
continue;
|
|
1512
|
+
const falloff = Math.pow(1 - distance / Math.max(0.001, radius), GLOW_FALLOFF_EXP_ASCII);
|
|
1513
|
+
addSample(canvas, channel, x, y, value * falloff);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
function drawLine(canvas, channel, x0, y0, x1, y1, value, width = 0.8) {
|
|
1518
|
+
const dx = x1 - x0;
|
|
1519
|
+
const dy = y1 - y0;
|
|
1520
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(dx, dy) * 1.7));
|
|
1521
|
+
for (let step = 0;step <= steps; step += 1) {
|
|
1522
|
+
const t2 = step / steps;
|
|
1523
|
+
const x = x0 + dx * t2;
|
|
1524
|
+
const y = y0 + dy * t2;
|
|
1525
|
+
drawDot(canvas, channel, x, y, width, value);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
function drawCircleStroke(canvas, channel, cx, cy, radius, value) {
|
|
1529
|
+
const steps = Math.max(18, Math.ceil(radius * 8));
|
|
1530
|
+
for (let step = 0;step < steps; step += 1) {
|
|
1531
|
+
const a = step / steps * Math.PI * 2;
|
|
1532
|
+
drawDot(canvas, channel, cx + Math.cos(a) * radius, cy + Math.sin(a) * radius, 0.72, value);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
function paletteColor(ac, c2, mg, ink) {
|
|
1536
|
+
const total = Math.max(0.001, ac + c2 + mg + ink);
|
|
1537
|
+
const r = (AC_RGB[0] * ac + C2_RGB[0] * c2 + MG_RGB[0] * mg + INK_RGB[0] * ink) / total;
|
|
1538
|
+
const g = (AC_RGB[1] * ac + C2_RGB[1] * c2 + MG_RGB[1] * mg + INK_RGB[1] * ink) / total;
|
|
1539
|
+
const b = (AC_RGB[2] * ac + C2_RGB[2] * c2 + MG_RGB[2] * mg + INK_RGB[2] * ink) / total;
|
|
1540
|
+
const intensity = Math.min(1, total / 4);
|
|
1541
|
+
const lift = 0.34 + intensity * 0.66;
|
|
1542
|
+
return RGBA4.fromInts(Math.round(r * lift), Math.round(g * lift), Math.round(b * lift), 255);
|
|
1543
|
+
}
|
|
1544
|
+
function clearCanvas(canvas) {
|
|
1545
|
+
canvas.ac.fill(0);
|
|
1546
|
+
canvas.c2.fill(0);
|
|
1547
|
+
canvas.mg.fill(0);
|
|
1548
|
+
canvas.ink.fill(0);
|
|
1549
|
+
}
|
|
1550
|
+
function makeCanvas(layout) {
|
|
1551
|
+
const width = Math.max(1, layout.width * BRAILLE_SAMPLES_X);
|
|
1552
|
+
const height = Math.max(1, layout.height * BRAILLE_SAMPLES_Y);
|
|
1553
|
+
const size = width * height;
|
|
1554
|
+
return {
|
|
1555
|
+
width,
|
|
1556
|
+
height,
|
|
1557
|
+
ac: new Float32Array(size),
|
|
1558
|
+
c2: new Float32Array(size),
|
|
1559
|
+
mg: new Float32Array(size),
|
|
1560
|
+
ink: new Float32Array(size)
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
class MarketingGlyphCanvas {
|
|
1565
|
+
rand = seeded(6221137);
|
|
1566
|
+
canvas;
|
|
1567
|
+
layout;
|
|
1568
|
+
activeKind = null;
|
|
1569
|
+
lanes = [];
|
|
1570
|
+
motes = [];
|
|
1571
|
+
packets = [];
|
|
1572
|
+
constructor(layout) {
|
|
1573
|
+
this.layout = layout;
|
|
1574
|
+
this.canvas = makeCanvas(layout);
|
|
1575
|
+
this.reset("dispatch");
|
|
1576
|
+
}
|
|
1577
|
+
resize(layout) {
|
|
1578
|
+
if (layout.width === this.layout.width && layout.height === this.layout.height)
|
|
1579
|
+
return;
|
|
1580
|
+
this.layout = layout;
|
|
1581
|
+
this.canvas = makeCanvas(layout);
|
|
1582
|
+
this.reset(this.activeKind ?? "dispatch");
|
|
1583
|
+
}
|
|
1584
|
+
render(layer, scene, tick) {
|
|
1585
|
+
const kind = sceneKind(scene);
|
|
1586
|
+
if (kind !== this.activeKind)
|
|
1587
|
+
this.reset(kind);
|
|
1588
|
+
clearCanvas(this.canvas);
|
|
1589
|
+
this.drawMarketingRails(kind, tick);
|
|
1590
|
+
if (kind === "loop")
|
|
1591
|
+
this.drawLoop(tick);
|
|
1592
|
+
else if (kind === "carrier")
|
|
1593
|
+
this.drawCarrier(tick);
|
|
1594
|
+
else
|
|
1595
|
+
this.drawDispatch(tick);
|
|
1596
|
+
this.blit(layer);
|
|
1597
|
+
}
|
|
1598
|
+
reset(kind) {
|
|
1599
|
+
this.activeKind = kind;
|
|
1600
|
+
this.lanes = [];
|
|
1601
|
+
this.motes = [];
|
|
1602
|
+
this.packets = [];
|
|
1603
|
+
if (kind === "dispatch")
|
|
1604
|
+
this.setupDispatch();
|
|
1605
|
+
else if (kind === "loop")
|
|
1606
|
+
this.setupLoop();
|
|
1607
|
+
else
|
|
1608
|
+
this.setupCarrier();
|
|
1609
|
+
}
|
|
1610
|
+
setupDispatch() {
|
|
1611
|
+
const count = this.layout.compact ? DISPATCH_LANES_COMPACT : DISPATCH_LANES_WIDE;
|
|
1612
|
+
for (let i = 0;i < count; i += 1) {
|
|
1613
|
+
const ang = (-0.9 + 1.8 * (i / Math.max(1, count - 1))) * (Math.PI * 0.5);
|
|
1614
|
+
this.lanes.push({ ang, len: this.canvas.width * (LANE_LEN_BASE + this.rand() * LANE_LEN_SPREAD), curve: (this.rand() - 0.5) * LANE_CURVE_RANGE, phase: this.rand() * Math.PI * 2 });
|
|
1615
|
+
}
|
|
1616
|
+
const packets = this.layout.compact ? DISPATCH_PACKETS_COMPACT : DISPATCH_PACKETS_WIDE;
|
|
1617
|
+
for (let i = 0;i < packets; i += 1)
|
|
1618
|
+
this.packets.push(this.packet(true));
|
|
1619
|
+
}
|
|
1620
|
+
setupLoop() {
|
|
1621
|
+
const lanes = this.layout.compact ? 4 : 7;
|
|
1622
|
+
for (let i = 0;i < lanes; i += 1)
|
|
1623
|
+
this.packets.push(this.packet(true));
|
|
1624
|
+
}
|
|
1625
|
+
setupCarrier() {
|
|
1626
|
+
const nodes = this.layout.compact ? CARRIER_NODES_COMPACT : CARRIER_NODES_WIDE;
|
|
1627
|
+
for (let i = 0;i < nodes * 6; i += 1)
|
|
1628
|
+
this.packets.push(this.packet(true));
|
|
1629
|
+
}
|
|
1630
|
+
packet(random = false) {
|
|
1631
|
+
return {
|
|
1632
|
+
lane: Math.floor(this.rand() * Math.max(1, this.lanes.length || 7)),
|
|
1633
|
+
p: random ? this.rand() : 0,
|
|
1634
|
+
spd: PACKET_SPEED_BASE + this.rand() * PACKET_SPEED_SPREAD,
|
|
1635
|
+
channel: this.rand() < PACKET_CYAN_PROBABILITY ? 1 : 0,
|
|
1636
|
+
wobble: (this.rand() - 0.5) * 7,
|
|
1637
|
+
size: 0.8 + this.rand() * 1.3
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
core(kind) {
|
|
1641
|
+
if (kind === "dispatch")
|
|
1642
|
+
return { x: this.canvas.width * CORE_DISPATCH_X, y: this.canvas.height * CORE_DISPATCH_Y };
|
|
1643
|
+
if (kind === "carrier")
|
|
1644
|
+
return { x: this.canvas.width * CORE_CARRIER_X, y: this.canvas.height * CORE_CARRIER_Y };
|
|
1645
|
+
return { x: this.canvas.width * CORE_LOOP_X, y: this.canvas.height * CORE_LOOP_Y };
|
|
1646
|
+
}
|
|
1647
|
+
lanePoint(lane, p, kind = "dispatch") {
|
|
1648
|
+
const core = this.core(kind);
|
|
1649
|
+
const dist = lane.len * p;
|
|
1650
|
+
const bend = Math.sin(p * Math.PI) * lane.curve * 28;
|
|
1651
|
+
const ux = Math.cos(lane.ang);
|
|
1652
|
+
const uy = Math.sin(lane.ang);
|
|
1653
|
+
return { x: core.x + ux * dist + -uy * bend, y: core.y + uy * dist + ux * bend };
|
|
1654
|
+
}
|
|
1655
|
+
drawMotes(tick) {
|
|
1656
|
+
for (const mote of this.motes) {
|
|
1657
|
+
mote.x += 0.1 * mote.z;
|
|
1658
|
+
if (mote.x > this.canvas.width + 2)
|
|
1659
|
+
mote.x = -2;
|
|
1660
|
+
const alpha = (0.035 + 0.08 * mote.z) * (0.55 + 0.45 * Math.sin(tick * 0.03 + mote.tw));
|
|
1661
|
+
drawDot(this.canvas, mote.channel, mote.x, mote.y, 0.45 * mote.z, alpha);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
drawMarketingRails(kind, tick) {
|
|
1665
|
+
const ys = kind === "loop" ? RAIL_YS_LOOP : kind === "carrier" ? RAIL_YS_CARRIER : RAIL_YS_DISPATCH;
|
|
1666
|
+
ys.forEach((ratio, index) => {
|
|
1667
|
+
const y = this.canvas.height * ratio + Math.sin(tick * 0.018 + index) * 1.8;
|
|
1668
|
+
drawLine(this.canvas, index === 1 ? 0 : 1, this.canvas.width * 0.06, y, this.canvas.width * 0.94, y + Math.sin(index) * 2, index === 1 ? 0.11 : 0.07, 0.55);
|
|
1669
|
+
for (let p = (tick * 0.004 + index * 0.21) % 1;p < 1; p += 0.18 + index * 0.02) {
|
|
1670
|
+
const x = this.canvas.width * (0.06 + 0.88 * p);
|
|
1671
|
+
drawDot(this.canvas, index === 2 ? 1 : 0, x, y, 1 + index * 0.25, 0.24);
|
|
1672
|
+
drawGlow(this.canvas, index === 2 ? 1 : 0, x, y, 3.8, 0.035);
|
|
1673
|
+
}
|
|
1674
|
+
});
|
|
1675
|
+
}
|
|
1676
|
+
drawDispatch(tick) {
|
|
1677
|
+
const core = this.core("dispatch");
|
|
1678
|
+
drawGlow(this.canvas, 0, core.x, core.y, 30, 0.12);
|
|
1679
|
+
drawDot(this.canvas, 0, core.x, core.y, 2.2, 0.85);
|
|
1680
|
+
for (const lane of this.lanes) {
|
|
1681
|
+
let prev = this.lanePoint(lane, 0);
|
|
1682
|
+
for (let i = 1;i <= LANE_INTERP_STEPS; i += 1) {
|
|
1683
|
+
const next = this.lanePoint(lane, i / LANE_INTERP_STEPS);
|
|
1684
|
+
drawLine(this.canvas, lane.phase > Math.PI ? 1 : 0, prev.x, prev.y, next.x, next.y, 0.045, 0.38);
|
|
1685
|
+
prev = next;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
for (const packet of this.packets) {
|
|
1689
|
+
packet.p += packet.spd;
|
|
1690
|
+
if (packet.p > 1)
|
|
1691
|
+
Object.assign(packet, this.packet(false));
|
|
1692
|
+
const lane = this.lanes[packet.lane % Math.max(1, this.lanes.length)];
|
|
1693
|
+
if (!lane)
|
|
1694
|
+
continue;
|
|
1695
|
+
const pt = this.lanePoint(lane, packet.p);
|
|
1696
|
+
const fade = packet.p < 0.1 ? packet.p / 0.1 : packet.p > 0.88 ? (1 - packet.p) / 0.12 : 1;
|
|
1697
|
+
const y = pt.y + packet.wobble * Math.sin(packet.p * Math.PI * 2);
|
|
1698
|
+
drawLine(this.canvas, packet.channel, pt.x - 4, y - 1, pt.x, y, 0.08 * fade, 0.38);
|
|
1699
|
+
drawDot(this.canvas, packet.channel, pt.x, y, packet.size, 0.5 * fade);
|
|
1700
|
+
drawGlow(this.canvas, packet.channel, pt.x, y, packet.size * 4, 0.045 * fade);
|
|
1701
|
+
}
|
|
1702
|
+
for (let i = 0;i < (this.layout.compact ? DISPATCH_DRONES_COMPACT : DISPATCH_DRONES_WIDE); i += 1) {
|
|
1703
|
+
const lane = this.lanes[i % Math.max(1, this.lanes.length)];
|
|
1704
|
+
if (!lane)
|
|
1705
|
+
continue;
|
|
1706
|
+
const p = (tick * 0.002 + i * 0.13) % 1;
|
|
1707
|
+
const pt = this.lanePoint(lane, p);
|
|
1708
|
+
this.drawDrone(pt.x, pt.y + Math.sin(tick * 0.04 + i) * 2, 2.6 + i % 2 * 0.6, tick + i * 11, i % 3 === 0 ? 1 : 0);
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
drawLoop(tick) {
|
|
1712
|
+
const y = this.canvas.height * 0.56;
|
|
1713
|
+
const x0 = this.canvas.width * 0.09;
|
|
1714
|
+
const x1 = this.canvas.width * 0.91;
|
|
1715
|
+
drawLine(this.canvas, 0, x0, y, x1, y, 0.12, 0.55);
|
|
1716
|
+
const gates = this.layout.compact ? LOOP_GATES_COMPACT : LOOP_GATES_WIDE;
|
|
1717
|
+
const active = Math.floor(tick / 16) % gates;
|
|
1718
|
+
for (let i = 0;i < gates; i += 1) {
|
|
1719
|
+
const x = x0 + (x1 - x0) * (i / Math.max(1, gates - 1));
|
|
1720
|
+
drawLine(this.canvas, i === active ? 0 : 3, x, y - 22, x, y + 22, i === active ? 0.25 : 0.08, i === active ? 0.7 : 0.42);
|
|
1721
|
+
drawDot(this.canvas, i <= active ? 0 : 3, x, y, i === active ? 2.2 : 1.2, i === active ? 0.72 : 0.25);
|
|
1722
|
+
drawCircleStroke(this.canvas, i <= active ? 0 : 3, x, y, i === active ? 4.2 : 2.4, i === active ? 0.18 : 0.08);
|
|
1723
|
+
}
|
|
1724
|
+
for (const packet of this.packets) {
|
|
1725
|
+
packet.p += packet.spd * 0.7;
|
|
1726
|
+
if (packet.p > 1)
|
|
1727
|
+
packet.p = 0;
|
|
1728
|
+
const x = x0 + (x1 - x0) * packet.p;
|
|
1729
|
+
const segment = Math.min(gates - 1, Math.floor(packet.p * gates));
|
|
1730
|
+
const channel = segment < active ? 0 : segment === active ? 1 : 3;
|
|
1731
|
+
const py = y + packet.wobble * Math.sin(packet.p * Math.PI * 2);
|
|
1732
|
+
drawLine(this.canvas, channel, x - 6, py, x, py, 0.1, 0.42);
|
|
1733
|
+
drawDot(this.canvas, channel, x, py, packet.size, channel === 3 ? 0.22 : 0.58);
|
|
1734
|
+
drawGlow(this.canvas, channel, x, py, 3.8, channel === 3 ? 0.02 : 0.04);
|
|
1735
|
+
}
|
|
1736
|
+
this.drawDrone(x0 + (x1 - x0) * (tick * 0.003 % 1), y - 18, 2.7, tick, 0);
|
|
1737
|
+
this.drawDrone(x0 + (x1 - x0) * ((tick * 0.002 + 0.5) % 1), y + 16, 2.2, tick + 40, 2);
|
|
1738
|
+
}
|
|
1739
|
+
drawCarrier(tick) {
|
|
1740
|
+
const core = this.core("carrier");
|
|
1741
|
+
drawGlow(this.canvas, 0, core.x, core.y, 26, 0.12);
|
|
1742
|
+
drawDot(this.canvas, 0, core.x, core.y, 2.4, 0.92);
|
|
1743
|
+
drawCircleStroke(this.canvas, 0, core.x, core.y, 8 + Math.sin(tick * 0.06) * 2, 0.14);
|
|
1744
|
+
const nodes = this.layout.compact ? CARRIER_NODES_COMPACT : CARRIER_NODES_WIDE;
|
|
1745
|
+
const rx = this.canvas.width * 0.36;
|
|
1746
|
+
const ry = this.canvas.height * 0.22;
|
|
1747
|
+
for (let i = 0;i < nodes; i += 1) {
|
|
1748
|
+
const a = i / nodes * Math.PI * 2 - Math.PI / 2 + tick * 0.006;
|
|
1749
|
+
const x = core.x + Math.cos(a) * rx;
|
|
1750
|
+
const y = core.y + Math.sin(a) * ry;
|
|
1751
|
+
drawLine(this.canvas, i % 2 ? 1 : 0, core.x, core.y, x, y, 0.055, 0.36);
|
|
1752
|
+
drawCircleStroke(this.canvas, i % 2 ? 1 : 0, x, y, 4.2, 0.15);
|
|
1753
|
+
drawDot(this.canvas, i % 2 ? 1 : 0, x, y, 1.7, 0.62);
|
|
1754
|
+
this.drawDrone(x, y - 8, 2.1, tick + i * 9, i % 2 ? 1 : 0);
|
|
1755
|
+
}
|
|
1756
|
+
for (const packet of this.packets) {
|
|
1757
|
+
packet.p += packet.spd;
|
|
1758
|
+
if (packet.p > 1)
|
|
1759
|
+
packet.p = 0;
|
|
1760
|
+
const lane = packet.lane % nodes;
|
|
1761
|
+
const a = lane / nodes * Math.PI * 2 - Math.PI / 2 + tick * 0.006;
|
|
1762
|
+
const nx = core.x + Math.cos(a) * rx;
|
|
1763
|
+
const ny = core.y + Math.sin(a) * ry;
|
|
1764
|
+
const x = core.x + (nx - core.x) * packet.p;
|
|
1765
|
+
const y = core.y + (ny - core.y) * packet.p;
|
|
1766
|
+
drawDot(this.canvas, packet.channel, x, y, packet.size, 0.48);
|
|
1767
|
+
drawGlow(this.canvas, packet.channel, x, y, 3.2, 0.035);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
drawDrone(x, y, scale, tick, channel) {
|
|
1771
|
+
const wobble = Math.sin(tick * 0.08) * 0.7;
|
|
1772
|
+
drawDot(this.canvas, channel, x, y + wobble, scale, 0.58);
|
|
1773
|
+
drawDot(this.canvas, 3, x, y + wobble, Math.max(0.6, scale * 0.28), 0.42);
|
|
1774
|
+
const rotor = scale * 1.75;
|
|
1775
|
+
const arms = [
|
|
1776
|
+
[-rotor, -rotor * 0.75],
|
|
1777
|
+
[rotor, -rotor * 0.75],
|
|
1778
|
+
[-rotor, rotor * 0.75],
|
|
1779
|
+
[rotor, rotor * 0.75]
|
|
1780
|
+
];
|
|
1781
|
+
for (const [dx, dy] of arms) {
|
|
1782
|
+
drawLine(this.canvas, channel, x, y + wobble, x + dx, y + dy + wobble, 0.11, 0.38);
|
|
1783
|
+
drawCircleStroke(this.canvas, channel, x + dx, y + dy + wobble, scale * (0.65 + Math.abs(Math.sin(tick * 0.18)) * 0.25), 0.16);
|
|
1784
|
+
drawDot(this.canvas, channel, x + dx, y + dy + wobble, 0.7, 0.25);
|
|
1785
|
+
}
|
|
1786
|
+
drawLine(this.canvas, channel === 1 ? 0 : 1, x - rotor * 2.4, y + wobble + 1.2, x - rotor * 1.2, y + wobble, 0.05, 0.35);
|
|
1787
|
+
}
|
|
1788
|
+
blit(layer) {
|
|
1789
|
+
const fb = layer.frameBuffer;
|
|
1790
|
+
fb.clear(BACKDROP);
|
|
1791
|
+
const { width, height, ac, c2, mg, ink } = this.canvas;
|
|
1792
|
+
for (let cy = 0;cy < this.layout.height; cy += 1) {
|
|
1793
|
+
for (let cx = 0;cx < this.layout.width; cx += 1) {
|
|
1794
|
+
let bits = 0;
|
|
1795
|
+
let acSum = 0;
|
|
1796
|
+
let c2Sum = 0;
|
|
1797
|
+
let mgSum = 0;
|
|
1798
|
+
let inkSum = 0;
|
|
1799
|
+
for (let sy = 0;sy < BRAILLE_SAMPLES_Y; sy += 1) {
|
|
1800
|
+
for (let sx = 0;sx < BRAILLE_SAMPLES_X; sx += 1) {
|
|
1801
|
+
const px = cx * BRAILLE_SAMPLES_X + sx;
|
|
1802
|
+
const py = cy * BRAILLE_SAMPLES_Y + sy;
|
|
1803
|
+
if (px >= width || py >= height)
|
|
1804
|
+
continue;
|
|
1805
|
+
const index = py * width + px;
|
|
1806
|
+
const a = ac[index];
|
|
1807
|
+
const c = c2[index];
|
|
1808
|
+
const m = mg[index];
|
|
1809
|
+
const k = ink[index];
|
|
1810
|
+
const total2 = a + c + m + k;
|
|
1811
|
+
acSum += a;
|
|
1812
|
+
c2Sum += c;
|
|
1813
|
+
mgSum += m;
|
|
1814
|
+
inkSum += k;
|
|
1815
|
+
if (total2 > 0.11)
|
|
1816
|
+
bits |= BRAILLE_BITS[sy][sx];
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const total = acSum + c2Sum + mgSum + inkSum;
|
|
1820
|
+
if (bits === 0 || total <= 0.02)
|
|
1821
|
+
continue;
|
|
1822
|
+
const char = String.fromCharCode(10240 + bits);
|
|
1823
|
+
fb.setCellWithAlphaBlending(cx, cy, char, paletteColor(acSum, c2Sum, mgSum, inkSum), TRANSPARENT);
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
// packages/cli/src/app-opentui/fleet-stats.ts
|
|
1830
|
+
var ACTIVE_STATUSES = new Set([
|
|
1831
|
+
"running",
|
|
1832
|
+
"preparing",
|
|
1833
|
+
"created",
|
|
1834
|
+
"validating",
|
|
1835
|
+
"reviewing",
|
|
1836
|
+
"closing-out",
|
|
1837
|
+
"stopping",
|
|
1838
|
+
"loading"
|
|
1839
|
+
]);
|
|
1840
|
+
|
|
1841
|
+
// packages/cli/src/app-opentui/render/image-visual-layer.ts
|
|
1842
|
+
import { Worker } from "worker_threads";
|
|
1843
|
+
import { deflateSync } from "zlib";
|
|
1844
|
+
import { allocateImageId, deleteKittyImage } from "@earendil-works/pi-tui";
|
|
1845
|
+
|
|
1846
|
+
// packages/cli/src/app-opentui/terminal-capabilities.ts
|
|
1847
|
+
import { getCapabilities } from "@earendil-works/pi-tui";
|
|
1848
|
+
function getRigTerminalCapabilities() {
|
|
1849
|
+
const imageProtocol = getCapabilities().images;
|
|
1850
|
+
const supportsKittyImages = imageProtocol === "kitty";
|
|
1851
|
+
return {
|
|
1852
|
+
imageProtocol,
|
|
1853
|
+
supportsKittyImages,
|
|
1854
|
+
visualMode: supportsKittyImages ? "kitty-images" : "framebuffer-fallback"
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
// packages/cli/src/app-opentui/render/image-visual-layer.ts
|
|
1859
|
+
var PANEL_MASK_RADIUS_MIN = 14;
|
|
1860
|
+
var PANEL_MASK_RADIUS_MAX = 34;
|
|
1861
|
+
var PANEL_MASK_RADIUS_FACTOR = 0.035;
|
|
1862
|
+
var PANEL_BLUR_RADIUS_MIN = 8;
|
|
1863
|
+
var PANEL_BLUR_RADIUS_MAX = 28;
|
|
1864
|
+
var PANEL_BLUR_RADIUS_FACTOR = 0.018;
|
|
1865
|
+
var BG = [7, 8, 9, 255];
|
|
1866
|
+
var PANEL = [16, 17, 21, 184];
|
|
1867
|
+
var PANEL_HEADER = [16, 17, 21, 190];
|
|
1868
|
+
var PANEL_LINE2 = [255, 255, 255, 24];
|
|
1869
|
+
var LIME = [204, 255, 77, 255];
|
|
1870
|
+
var LIME_DIM = [169, 214, 63, 255];
|
|
1871
|
+
var CYAN = [86, 216, 255, 255];
|
|
1872
|
+
var MAGENTA = [255, 121, 176, 255];
|
|
1873
|
+
var INK_DIM = [108, 110, 121, 255];
|
|
1874
|
+
var PNG_SIGNATURE = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
1875
|
+
var CRC_TABLE = makeCrcTable();
|
|
1876
|
+
var MAX_IMAGE_BYTES = 48 * 1024 * 1024;
|
|
1877
|
+
var KITTY_CHUNK_SIZE = 4096;
|
|
1878
|
+
var PANEL_BLUR_SCALE = 1;
|
|
1879
|
+
var PANEL_MASK_CACHE_LIMIT = 16;
|
|
1880
|
+
var ZLIB_LEVEL = 1;
|
|
1881
|
+
var LOAD_BUCKETS = 5;
|
|
1882
|
+
function loadBucket(load) {
|
|
1883
|
+
if (!Number.isFinite(load ?? NaN))
|
|
1884
|
+
return 0;
|
|
1885
|
+
return Math.max(0, Math.min(LOAD_BUCKETS, Math.round((load ?? 0) * LOAD_BUCKETS)));
|
|
1886
|
+
}
|
|
1887
|
+
var panelMaskCache = new Map;
|
|
1888
|
+
var BG_WORD = rgbaWord(BG);
|
|
1889
|
+
function imageTransport() {
|
|
1890
|
+
const forced = process.env.RIG_OPENTUI_IMAGE_TRANSPORT;
|
|
1891
|
+
if (forced === "rgba-zlib")
|
|
1892
|
+
return "rgba-zlib";
|
|
1893
|
+
return "png";
|
|
1894
|
+
}
|
|
1895
|
+
function rgbaWord(color) {
|
|
1896
|
+
return (color[3] << 24 | color[2] << 16 | color[1] << 8 | color[0]) >>> 0;
|
|
1897
|
+
}
|
|
1898
|
+
function fillRgba(data, color, word = rgbaWord(color)) {
|
|
1899
|
+
if (data.byteOffset % 4 === 0 && data.byteLength % 4 === 0) {
|
|
1900
|
+
new Uint32Array(data.buffer, data.byteOffset, data.byteLength / 4).fill(word);
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
for (let i = 0;i < data.length; i += 4) {
|
|
1904
|
+
data[i] = color[0];
|
|
1905
|
+
data[i + 1] = color[1];
|
|
1906
|
+
data[i + 2] = color[2];
|
|
1907
|
+
data[i + 3] = color[3];
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
var ASCII_GLYPHS = {
|
|
1911
|
+
".": ["00000", "00000", "00000", "00000", "00000", "00100", "00100"],
|
|
1912
|
+
"'": ["00100", "00100", "00000", "00000", "00000", "00000", "00000"],
|
|
1913
|
+
"-": ["00000", "00000", "00000", "11111", "00000", "00000", "00000"],
|
|
1914
|
+
_: ["00000", "00000", "00000", "00000", "00000", "00000", "11111"],
|
|
1915
|
+
"=": ["00000", "11111", "00000", "00000", "11111", "00000", "00000"],
|
|
1916
|
+
"|": ["00100", "00100", "00100", "00100", "00100", "00100", "00100"],
|
|
1917
|
+
"/": ["00001", "00010", "00010", "00100", "01000", "01000", "10000"],
|
|
1918
|
+
"\\": ["10000", "01000", "01000", "00100", "00010", "00010", "00001"],
|
|
1919
|
+
"(": ["00010", "00100", "01000", "01000", "01000", "00100", "00010"],
|
|
1920
|
+
")": ["01000", "00100", "00010", "00010", "00010", "00100", "01000"],
|
|
1921
|
+
"!": ["00100", "00100", "00100", "00100", "00100", "00000", "00100"],
|
|
1922
|
+
"%": ["11001", "11010", "00100", "01000", "10110", "00110", "00000"],
|
|
1923
|
+
$: ["00100", "11110", "10100", "11110", "00101", "11110", "00100"],
|
|
1924
|
+
"@": ["01110", "10001", "10111", "10101", "10111", "10000", "01111"],
|
|
1925
|
+
o: ["00000", "01110", "10001", "10001", "10001", "01110", "00000"],
|
|
1926
|
+
"*": ["00100", "10101", "01110", "11111", "01110", "10101", "00100"]
|
|
1927
|
+
};
|
|
1928
|
+
function sceneStaticTick(scene) {
|
|
1929
|
+
let hash = 0;
|
|
1930
|
+
for (let index = 0;index < scene.length; index += 1)
|
|
1931
|
+
hash = hash * 33 + scene.charCodeAt(index) >>> 0;
|
|
1932
|
+
return 11 + hash % 97;
|
|
1933
|
+
}
|
|
1934
|
+
function charColor(char, row, totalRows) {
|
|
1935
|
+
if (char === "@" || char === "$" || char === "o")
|
|
1936
|
+
return LIME;
|
|
1937
|
+
if (char === "%" || char === "!" || char === "/" || char === "\\" || char === "|")
|
|
1938
|
+
return CYAN;
|
|
1939
|
+
if (char === "." || char === "'" || char === "_" || row < 3 || row > totalRows - 4)
|
|
1940
|
+
return INK_DIM;
|
|
1941
|
+
if (char === "-" || char === "=" || char === "(" || char === ")")
|
|
1942
|
+
return LIME_DIM;
|
|
1943
|
+
return MAGENTA;
|
|
1944
|
+
}
|
|
1945
|
+
function fillRectAlpha(data, width, height, left, top, rectWidth, rectHeight, color, alpha) {
|
|
1946
|
+
const x0 = Math.max(0, Math.floor(left));
|
|
1947
|
+
const y0 = Math.max(0, Math.floor(top));
|
|
1948
|
+
const x1 = Math.min(width, Math.ceil(left + rectWidth));
|
|
1949
|
+
const y1 = Math.min(height, Math.ceil(top + rectHeight));
|
|
1950
|
+
for (let y = y0;y < y1; y += 1) {
|
|
1951
|
+
for (let x = x0;x < x1; x += 1)
|
|
1952
|
+
blendOver(data, (y * width + x) * 4, color, alpha);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
function drawAsciiGlyph(data, width, height, x, y, cellWidth, cellHeight, char, color, alpha) {
|
|
1956
|
+
const pattern = ASCII_GLYPHS[char] ?? ASCII_GLYPHS["*"];
|
|
1957
|
+
const glyphWidth = Math.max(1, cellWidth * 0.56);
|
|
1958
|
+
const glyphHeight = Math.max(1, cellHeight * 0.7);
|
|
1959
|
+
const originX = x + (cellWidth - glyphWidth) * 0.5;
|
|
1960
|
+
const originY = y + (cellHeight - glyphHeight) * 0.5;
|
|
1961
|
+
const pixelWidth = Math.max(1, glyphWidth / pattern[0].length);
|
|
1962
|
+
const pixelHeight = Math.max(1, glyphHeight / pattern.length);
|
|
1963
|
+
for (let row = 0;row < pattern.length; row += 1) {
|
|
1964
|
+
const bits = pattern[row];
|
|
1965
|
+
for (let col = 0;col < bits.length; col += 1) {
|
|
1966
|
+
if (bits[col] !== "1")
|
|
1967
|
+
continue;
|
|
1968
|
+
fillRectAlpha(data, width, height, originX + col * pixelWidth, originY + row * pixelHeight, pixelWidth * 0.72, pixelHeight * 0.72, color, alpha);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
function drawStaticAsciiFleetBackground(data, width, height, scene, layout, load, activeRuns) {
|
|
1973
|
+
const rows = fleetRows(sceneStaticTick(scene), { animate: true });
|
|
1974
|
+
const cellWidth = width / Math.max(1, layout.width);
|
|
1975
|
+
const cellHeight = height / Math.max(1, layout.height);
|
|
1976
|
+
const sideBySide = layout.width >= FLEET_GRID_WIDTH * 1.9;
|
|
1977
|
+
const leftCells = sideBySide ? Math.max(1, Math.floor(layout.width * 0.3 - FLEET_GRID_WIDTH / 2)) : Math.floor((layout.width - FLEET_GRID_WIDTH) / 2);
|
|
1978
|
+
const topCells = Math.floor((layout.height - FLEET_GRID_HEIGHT) / 2);
|
|
1979
|
+
const fleetLeft = leftCells * cellWidth;
|
|
1980
|
+
const fleetTop = topCells * cellHeight;
|
|
1981
|
+
drawGlow2(data, width, height, width * 0.5, height * 0.5, Math.min(width, height) * 0.4, LIME, 0.022 + load * 0.03);
|
|
1982
|
+
drawGlow2(data, width, height, width * 0.18, height * 0.22, Math.min(width, height) * 0.28, CYAN, 0.018 + load * 0.012);
|
|
1983
|
+
drawGlow2(data, width, height, width * 0.82, height * 0.78, Math.min(width, height) * 0.22, MAGENTA, 0.012 + load * 0.008);
|
|
1984
|
+
let droneTotal = 0;
|
|
1985
|
+
for (const line2 of rows)
|
|
1986
|
+
for (const char of line2)
|
|
1987
|
+
if (char === "@" || char === "$" || char === "%")
|
|
1988
|
+
droneTotal += 1;
|
|
1989
|
+
const litTarget = Math.max(0, Math.min(droneTotal, activeRuns));
|
|
1990
|
+
let droneIndex = 0;
|
|
1991
|
+
for (let row = 0;row < rows.length; row += 1) {
|
|
1992
|
+
const line2 = rows[row];
|
|
1993
|
+
for (let col = 0;col < line2.length; col += 1) {
|
|
1994
|
+
const char = line2[col];
|
|
1995
|
+
if (char === " ")
|
|
1996
|
+
continue;
|
|
1997
|
+
const x = fleetLeft + col * cellWidth;
|
|
1998
|
+
const y = fleetTop + row * cellHeight;
|
|
1999
|
+
const color = charColor(char, row, rows.length);
|
|
2000
|
+
const isDrone = char === "@" || char === "$" || char === "%";
|
|
2001
|
+
const lit = isDrone && droneIndex < litTarget;
|
|
2002
|
+
drawAsciiGlyph(data, width, height, x + cellWidth * 0.07, y + cellHeight * 0.05, cellWidth, cellHeight, char, color, lit ? 0.72 : 0.46);
|
|
2003
|
+
if (isDrone) {
|
|
2004
|
+
droneIndex += 1;
|
|
2005
|
+
drawGlow2(data, width, height, x + cellWidth * 0.5, y + cellHeight * 0.5, Math.max(cellWidth, cellHeight) * 0.95, color, lit ? 0.044 : 0.014);
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
function applyStaticAtmosphere(data, width, height, load) {
|
|
2011
|
+
const cx = width * 0.5;
|
|
2012
|
+
const cy = height * 0.42;
|
|
2013
|
+
const radius = Math.max(width, height) * 0.78;
|
|
2014
|
+
const minVignette = 0.1 - load * 0.02;
|
|
2015
|
+
for (let y = 0;y < height; y += 1) {
|
|
2016
|
+
for (let x = 0;x < width; x += 1) {
|
|
2017
|
+
const distance = Math.hypot(x - cx, y - cy) / radius;
|
|
2018
|
+
const alpha = Math.max(minVignette, Math.min(0.82, 0.12 + Math.pow(distance, 1.65) * 0.62));
|
|
2019
|
+
blendOver(data, (y * width + x) * 4, BG, alpha);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
drawGlow2(data, width, height, width * 0.82, height * 0.04, Math.min(width, height) * 0.2, LIME, 0.024 + load * 0.012);
|
|
2023
|
+
drawGlow2(data, width, height, width * 0.12, height * 0.18, Math.min(width, height) * 0.16, CYAN, 0.018 + load * 0.008);
|
|
2024
|
+
}
|
|
2025
|
+
function makeCrcTable() {
|
|
2026
|
+
const table = new Uint32Array(256);
|
|
2027
|
+
for (let n = 0;n < 256; n += 1) {
|
|
2028
|
+
let c = n;
|
|
2029
|
+
for (let k = 0;k < 8; k += 1)
|
|
2030
|
+
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
2031
|
+
table[n] = c >>> 0;
|
|
2032
|
+
}
|
|
2033
|
+
return table;
|
|
2034
|
+
}
|
|
2035
|
+
function crc32(bytes) {
|
|
2036
|
+
let c = 4294967295;
|
|
2037
|
+
for (let i = 0;i < bytes.length; i += 1)
|
|
2038
|
+
c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
|
|
2039
|
+
return (c ^ 4294967295) >>> 0;
|
|
2040
|
+
}
|
|
2041
|
+
function chunk(type, data) {
|
|
2042
|
+
const out = new Uint8Array(12 + data.length);
|
|
2043
|
+
const view = new DataView(out.buffer);
|
|
2044
|
+
view.setUint32(0, data.length);
|
|
2045
|
+
out[4] = type.charCodeAt(0);
|
|
2046
|
+
out[5] = type.charCodeAt(1);
|
|
2047
|
+
out[6] = type.charCodeAt(2);
|
|
2048
|
+
out[7] = type.charCodeAt(3);
|
|
2049
|
+
out.set(data, 8);
|
|
2050
|
+
view.setUint32(8 + data.length, crc32(out.subarray(4, 8 + data.length)));
|
|
2051
|
+
return out;
|
|
2052
|
+
}
|
|
2053
|
+
function encodePng(width, height, rgba) {
|
|
2054
|
+
const ihdr = new Uint8Array(13);
|
|
2055
|
+
const ihdrView = new DataView(ihdr.buffer);
|
|
2056
|
+
ihdrView.setUint32(0, width);
|
|
2057
|
+
ihdrView.setUint32(4, height);
|
|
2058
|
+
ihdr[8] = 8;
|
|
2059
|
+
ihdr[9] = 6;
|
|
2060
|
+
ihdr[10] = 0;
|
|
2061
|
+
ihdr[11] = 0;
|
|
2062
|
+
ihdr[12] = 0;
|
|
2063
|
+
const stride = width * 4;
|
|
2064
|
+
const raw = new Uint8Array((stride + 1) * height);
|
|
2065
|
+
for (let y = 0;y < height; y += 1) {
|
|
2066
|
+
const rawOffset = y * (stride + 1);
|
|
2067
|
+
raw[rawOffset] = 0;
|
|
2068
|
+
raw.set(rgba.subarray(y * stride, y * stride + stride), rawOffset + 1);
|
|
2069
|
+
}
|
|
2070
|
+
const compressed = deflateSync(raw, { level: ZLIB_LEVEL });
|
|
2071
|
+
return Buffer.concat([
|
|
2072
|
+
Buffer.from(PNG_SIGNATURE),
|
|
2073
|
+
Buffer.from(chunk("IHDR", ihdr)),
|
|
2074
|
+
Buffer.from(chunk("IDAT", compressed)),
|
|
2075
|
+
Buffer.from(chunk("IEND", new Uint8Array(0)))
|
|
2076
|
+
]);
|
|
2077
|
+
}
|
|
2078
|
+
function kittyImageSequence(base64, options) {
|
|
2079
|
+
const params = [`a=T`, `f=${options.format}`, `q=2`, `C=1`, `c=${options.columns}`, `r=${options.rows}`, `i=${options.imageId}`, `z=${options.zIndex}`];
|
|
2080
|
+
if (options.format === 32) {
|
|
2081
|
+
params.push(`s=${options.pixelWidth ?? 1}`, `v=${options.pixelHeight ?? 1}`);
|
|
2082
|
+
if (options.compressed)
|
|
2083
|
+
params.push("o=z");
|
|
2084
|
+
}
|
|
2085
|
+
if (base64.length <= KITTY_CHUNK_SIZE)
|
|
2086
|
+
return `\x1B_G${params.join(",")};${base64}\x1B\\`;
|
|
2087
|
+
const chunks = [];
|
|
2088
|
+
for (let offset = 0;offset < base64.length; offset += KITTY_CHUNK_SIZE) {
|
|
2089
|
+
const part = base64.slice(offset, offset + KITTY_CHUNK_SIZE);
|
|
2090
|
+
const last = offset + KITTY_CHUNK_SIZE >= base64.length;
|
|
2091
|
+
chunks.push(`\x1B_G${offset === 0 ? `${params.join(",")},` : ""}m=${last ? 0 : 1};${part}\x1B\\`);
|
|
2092
|
+
}
|
|
2093
|
+
return chunks.join("");
|
|
2094
|
+
}
|
|
2095
|
+
function clampByte(value) {
|
|
2096
|
+
return Math.max(0, Math.min(255, Math.round(value)));
|
|
2097
|
+
}
|
|
2098
|
+
function blendOver(data, index, color, alphaScale = 1) {
|
|
2099
|
+
const alpha = color[3] / 255 * alphaScale;
|
|
2100
|
+
const inv = 1 - alpha;
|
|
2101
|
+
data[index] = clampByte(color[0] * alpha + data[index] * inv);
|
|
2102
|
+
data[index + 1] = clampByte(color[1] * alpha + data[index + 1] * inv);
|
|
2103
|
+
data[index + 2] = clampByte(color[2] * alpha + data[index + 2] * inv);
|
|
2104
|
+
data[index + 3] = 255;
|
|
2105
|
+
}
|
|
2106
|
+
function drawDisc(data, width, height, cx, cy, radius, color, alpha = 1) {
|
|
2107
|
+
const minX = Math.max(0, Math.floor(cx - radius));
|
|
2108
|
+
const maxX = Math.min(width - 1, Math.ceil(cx + radius));
|
|
2109
|
+
const minY = Math.max(0, Math.floor(cy - radius));
|
|
2110
|
+
const maxY = Math.min(height - 1, Math.ceil(cy + radius));
|
|
2111
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
2112
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
2113
|
+
const dx = x + 0.5 - cx;
|
|
2114
|
+
const dy = y + 0.5 - cy;
|
|
2115
|
+
const d = Math.sqrt(dx * dx + dy * dy);
|
|
2116
|
+
if (d > radius)
|
|
2117
|
+
continue;
|
|
2118
|
+
const edge = Math.max(0, Math.min(1, radius - d));
|
|
2119
|
+
blendOver(data, (y * width + x) * 4, color, alpha * Math.min(1, 0.35 + edge));
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
function drawGlow2(data, width, height, cx, cy, radius, color, alpha = 0.18) {
|
|
2124
|
+
const minX = Math.max(0, Math.floor(cx - radius));
|
|
2125
|
+
const maxX = Math.min(width - 1, Math.ceil(cx + radius));
|
|
2126
|
+
const minY = Math.max(0, Math.floor(cy - radius));
|
|
2127
|
+
const maxY = Math.min(height - 1, Math.ceil(cy + radius));
|
|
2128
|
+
for (let y = minY;y <= maxY; y += 1) {
|
|
2129
|
+
for (let x = minX;x <= maxX; x += 1) {
|
|
2130
|
+
const dx = x + 0.5 - cx;
|
|
2131
|
+
const dy = y + 0.5 - cy;
|
|
2132
|
+
const d = Math.sqrt(dx * dx + dy * dy);
|
|
2133
|
+
if (d > radius)
|
|
2134
|
+
continue;
|
|
2135
|
+
const falloff = Math.pow(1 - d / Math.max(1, radius), GLOW_FALLOFF_EXP_IMAGE);
|
|
2136
|
+
blendOver(data, (y * width + x) * 4, color, alpha * falloff);
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
function drawLine2(data, width, height, x0, y0, x1, y1, color, alpha = 0.5, thickness = 1.4) {
|
|
2141
|
+
const dx = x1 - x0;
|
|
2142
|
+
const dy = y1 - y0;
|
|
2143
|
+
const steps = Math.max(1, Math.ceil(Math.hypot(dx, dy) * 1.2));
|
|
2144
|
+
for (let i = 0;i <= steps; i += 1) {
|
|
2145
|
+
const t2 = i / steps;
|
|
2146
|
+
drawDisc(data, width, height, x0 + dx * t2, y0 + dy * t2, thickness, color, alpha);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
function roundRectAlpha(px, py, x, y, w, h, r) {
|
|
2150
|
+
const rx = Math.max(x + r, Math.min(px, x + w - r));
|
|
2151
|
+
const ry = Math.max(y + r, Math.min(py, y + h - r));
|
|
2152
|
+
const dx = px - rx;
|
|
2153
|
+
const dy = py - ry;
|
|
2154
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
2155
|
+
return Math.max(0, Math.min(1, r + 0.75 - dist));
|
|
2156
|
+
}
|
|
2157
|
+
function panelRect(layout, panel, size) {
|
|
2158
|
+
return panelPixelPlacement(layout, panel, size);
|
|
2159
|
+
}
|
|
2160
|
+
function downsampleRegion(data, canvasW, canvasH, rect, scale) {
|
|
2161
|
+
const w = Math.max(1, Math.ceil(rect.width / scale));
|
|
2162
|
+
const h = Math.max(1, Math.ceil(rect.height / scale));
|
|
2163
|
+
const out = new Uint8ClampedArray(w * h * 3);
|
|
2164
|
+
for (let y = 0;y < h; y += 1) {
|
|
2165
|
+
for (let x = 0;x < w; x += 1) {
|
|
2166
|
+
let r = 0, g = 0, b = 0, count = 0;
|
|
2167
|
+
const sx0 = rect.left + x * scale;
|
|
2168
|
+
const sy0 = rect.top + y * scale;
|
|
2169
|
+
for (let yy = 0;yy < scale; yy += 1) {
|
|
2170
|
+
const sy = sy0 + yy;
|
|
2171
|
+
if (sy < 0 || sy >= canvasH)
|
|
2172
|
+
continue;
|
|
2173
|
+
for (let xx = 0;xx < scale; xx += 1) {
|
|
2174
|
+
const sx = sx0 + xx;
|
|
2175
|
+
if (sx < 0 || sx >= canvasW)
|
|
2176
|
+
continue;
|
|
2177
|
+
const i = (sy * canvasW + sx) * 4;
|
|
2178
|
+
r += data[i];
|
|
2179
|
+
g += data[i + 1];
|
|
2180
|
+
b += data[i + 2];
|
|
2181
|
+
count += 1;
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
const oi = (y * w + x) * 3;
|
|
2185
|
+
out[oi] = count ? r / count : BG[0];
|
|
2186
|
+
out[oi + 1] = count ? g / count : BG[1];
|
|
2187
|
+
out[oi + 2] = count ? b / count : BG[2];
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
return { pixels: out, width: w, height: h };
|
|
2191
|
+
}
|
|
2192
|
+
function blurRgb(buffer, width, height, radius) {
|
|
2193
|
+
const tmp = new Uint8ClampedArray(buffer.length);
|
|
2194
|
+
const out = new Uint8ClampedArray(buffer.length);
|
|
2195
|
+
const window = radius * 2 + 1;
|
|
2196
|
+
for (let y = 0;y < height; y += 1) {
|
|
2197
|
+
let r = 0, g = 0, b = 0;
|
|
2198
|
+
for (let x = -radius;x <= radius; x += 1) {
|
|
2199
|
+
const sx = Math.max(0, Math.min(width - 1, x));
|
|
2200
|
+
const i = (y * width + sx) * 3;
|
|
2201
|
+
r += buffer[i];
|
|
2202
|
+
g += buffer[i + 1];
|
|
2203
|
+
b += buffer[i + 2];
|
|
2204
|
+
}
|
|
2205
|
+
for (let x = 0;x < width; x += 1) {
|
|
2206
|
+
const oi = (y * width + x) * 3;
|
|
2207
|
+
tmp[oi] = r / window;
|
|
2208
|
+
tmp[oi + 1] = g / window;
|
|
2209
|
+
tmp[oi + 2] = b / window;
|
|
2210
|
+
const removeX = Math.max(0, x - radius);
|
|
2211
|
+
const addX = Math.min(width - 1, x + radius + 1);
|
|
2212
|
+
const ri = (y * width + removeX) * 3;
|
|
2213
|
+
const ai = (y * width + addX) * 3;
|
|
2214
|
+
r += tmp.length ? buffer[ai] - buffer[ri] : 0;
|
|
2215
|
+
g += tmp.length ? buffer[ai + 1] - buffer[ri + 1] : 0;
|
|
2216
|
+
b += tmp.length ? buffer[ai + 2] - buffer[ri + 2] : 0;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
for (let x = 0;x < width; x += 1) {
|
|
2220
|
+
let r = 0, g = 0, b = 0;
|
|
2221
|
+
for (let y = -radius;y <= radius; y += 1) {
|
|
2222
|
+
const sy = Math.max(0, Math.min(height - 1, y));
|
|
2223
|
+
const i = (sy * width + x) * 3;
|
|
2224
|
+
r += tmp[i];
|
|
2225
|
+
g += tmp[i + 1];
|
|
2226
|
+
b += tmp[i + 2];
|
|
2227
|
+
}
|
|
2228
|
+
for (let y = 0;y < height; y += 1) {
|
|
2229
|
+
const oi = (y * width + x) * 3;
|
|
2230
|
+
out[oi] = r / window;
|
|
2231
|
+
out[oi + 1] = g / window;
|
|
2232
|
+
out[oi + 2] = b / window;
|
|
2233
|
+
const removeY = Math.max(0, y - radius);
|
|
2234
|
+
const addY = Math.min(height - 1, y + radius + 1);
|
|
2235
|
+
const ri = (removeY * width + x) * 3;
|
|
2236
|
+
const ai = (addY * width + x) * 3;
|
|
2237
|
+
r += tmp[ai] - tmp[ri];
|
|
2238
|
+
g += tmp[ai + 1] - tmp[ri + 1];
|
|
2239
|
+
b += tmp[ai + 2] - tmp[ri + 2];
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
return out;
|
|
2243
|
+
}
|
|
2244
|
+
function panelMaskKey(width, height, rect, headerPx, blurScale) {
|
|
2245
|
+
return `${width}x${height}:${rect.left},${rect.top},${rect.width},${rect.height}:${Math.round(headerPx * 100) / 100}:${blurScale}`;
|
|
2246
|
+
}
|
|
2247
|
+
function getPanelMask(width, height, rect, headerPx, blurScale) {
|
|
2248
|
+
const key = panelMaskKey(width, height, rect, headerPx, blurScale);
|
|
2249
|
+
const cached = panelMaskCache.get(key);
|
|
2250
|
+
if (cached)
|
|
2251
|
+
return cached;
|
|
2252
|
+
const radius = Math.max(PANEL_MASK_RADIUS_MIN, Math.min(PANEL_MASK_RADIUS_MAX, Math.round(Math.min(rect.width, rect.height) * PANEL_MASK_RADIUS_FACTOR)));
|
|
2253
|
+
const sampledWidth = Math.max(1, Math.ceil(rect.width / blurScale));
|
|
2254
|
+
const sampledHeight = Math.max(1, Math.ceil(rect.height / blurScale));
|
|
2255
|
+
const x0 = Math.max(0, rect.left);
|
|
2256
|
+
const y0 = Math.max(0, rect.top);
|
|
2257
|
+
const x1 = Math.min(width - 1, rect.left + rect.width - 1);
|
|
2258
|
+
const y1 = Math.min(height - 1, rect.top + rect.height - 1);
|
|
2259
|
+
const indices = [];
|
|
2260
|
+
const sampleIndices = [];
|
|
2261
|
+
const panelAlpha = [];
|
|
2262
|
+
const edgeAlpha = [];
|
|
2263
|
+
const headerFlags = [];
|
|
2264
|
+
const dividerIndices = [];
|
|
2265
|
+
for (let y = y0;y <= y1; y += 1) {
|
|
2266
|
+
for (let x = x0;x <= x1; x += 1) {
|
|
2267
|
+
const a = roundRectAlpha(x + 0.5, y + 0.5, rect.left, rect.top, rect.width, rect.height, radius);
|
|
2268
|
+
if (a <= 0)
|
|
2269
|
+
continue;
|
|
2270
|
+
const edge = roundRectAlpha(x + 0.5, y + 0.5, rect.left + 1.2, rect.top + 1.2, rect.width - 2.4, rect.height - 2.4, Math.max(1, radius - 1.2));
|
|
2271
|
+
const sx = Math.max(0, Math.min(sampledWidth - 1, Math.floor((x - rect.left) / blurScale)));
|
|
2272
|
+
const sy = Math.max(0, Math.min(sampledHeight - 1, Math.floor((y - rect.top) / blurScale)));
|
|
2273
|
+
indices.push((y * width + x) * 4);
|
|
2274
|
+
sampleIndices.push((sy * sampledWidth + sx) * 3);
|
|
2275
|
+
panelAlpha.push(a);
|
|
2276
|
+
edgeAlpha.push(edge < 0.96 ? Math.min(1, (1 - edge) * 0.7) : 0);
|
|
2277
|
+
headerFlags.push(y < rect.top + headerPx ? 1 : 0);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
const dividerY = Math.round(rect.top + headerPx);
|
|
2281
|
+
if (dividerY > y0 && dividerY < y1) {
|
|
2282
|
+
for (let x = x0 + radius;x <= x1 - radius; x += 1) {
|
|
2283
|
+
dividerIndices.push((dividerY * width + x) * 4);
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
const mask = {
|
|
2287
|
+
key,
|
|
2288
|
+
indices: Uint32Array.from(indices),
|
|
2289
|
+
sampleIndices: Uint32Array.from(sampleIndices),
|
|
2290
|
+
panelAlpha: Float32Array.from(panelAlpha),
|
|
2291
|
+
edgeAlpha: Float32Array.from(edgeAlpha),
|
|
2292
|
+
headerFlags: Uint8Array.from(headerFlags),
|
|
2293
|
+
dividerIndices: Uint32Array.from(dividerIndices)
|
|
2294
|
+
};
|
|
2295
|
+
panelMaskCache.set(key, mask);
|
|
2296
|
+
while (panelMaskCache.size > PANEL_MASK_CACHE_LIMIT) {
|
|
2297
|
+
const oldest = panelMaskCache.keys().next().value;
|
|
2298
|
+
if (!oldest)
|
|
2299
|
+
break;
|
|
2300
|
+
panelMaskCache.delete(oldest);
|
|
2301
|
+
}
|
|
2302
|
+
return mask;
|
|
2303
|
+
}
|
|
2304
|
+
function compositePanel(data, width, height, rect, headerPx) {
|
|
2305
|
+
const blurScale = PANEL_BLUR_SCALE;
|
|
2306
|
+
const sampled = downsampleRegion(data, width, height, rect, blurScale);
|
|
2307
|
+
const blurRadius = Math.max(PANEL_BLUR_RADIUS_MIN, Math.min(PANEL_BLUR_RADIUS_MAX, Math.round(Math.min(rect.width, rect.height) * PANEL_BLUR_RADIUS_FACTOR)));
|
|
2308
|
+
const blurred = blurRgb(sampled.pixels, sampled.width, sampled.height, blurRadius);
|
|
2309
|
+
const mask = getPanelMask(width, height, rect, headerPx, blurScale);
|
|
2310
|
+
for (let i = 0;i < mask.indices.length; i += 1) {
|
|
2311
|
+
const idx = mask.indices[i];
|
|
2312
|
+
const sampleIdx = mask.sampleIndices[i];
|
|
2313
|
+
data[idx] = blurred[sampleIdx];
|
|
2314
|
+
data[idx + 1] = blurred[sampleIdx + 1];
|
|
2315
|
+
data[idx + 2] = blurred[sampleIdx + 2];
|
|
2316
|
+
data[idx + 3] = 255;
|
|
2317
|
+
blendOver(data, idx, mask.headerFlags[i] ? PANEL_HEADER : PANEL, mask.panelAlpha[i]);
|
|
2318
|
+
const edge = mask.edgeAlpha[i];
|
|
2319
|
+
if (edge > 0)
|
|
2320
|
+
blendOver(data, idx, PANEL_LINE2, edge);
|
|
2321
|
+
}
|
|
2322
|
+
for (let i = 0;i < mask.dividerIndices.length; i += 1) {
|
|
2323
|
+
blendOver(data, mask.dividerIndices[i], PANEL_LINE2, 0.28);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
var RIG_GLYPH_STROKES = {
|
|
2327
|
+
R: [[0, 0, 0, 1], [0, 0, 0.82, 0], [0.82, 0, 0.82, 0.5], [0, 0.5, 0.82, 0.5], [0.36, 0.5, 0.92, 1]],
|
|
2328
|
+
I: [[0.5, 0, 0.5, 1], [0.18, 0, 0.82, 0], [0.18, 1, 0.82, 1]],
|
|
2329
|
+
G: [[0.92, 0.08, 0.12, 0], [0.12, 0, 0.12, 1], [0.12, 1, 0.92, 1], [0.92, 0.5, 0.92, 1], [0.5, 0.5, 0.92, 0.5]]
|
|
2330
|
+
};
|
|
2331
|
+
function drawBigRigWordmark(data, width, height, layout, load) {
|
|
2332
|
+
const sideBySide = layout.width >= FLEET_GRID_WIDTH * 1.9;
|
|
2333
|
+
if (!sideBySide)
|
|
2334
|
+
return;
|
|
2335
|
+
const letters = "RIG";
|
|
2336
|
+
const min = Math.min(width, height);
|
|
2337
|
+
const glyphH = height * 0.42;
|
|
2338
|
+
const glyphW = width * 0.13;
|
|
2339
|
+
const gap = glyphW * 0.3;
|
|
2340
|
+
const totalW = letters.length * glyphW + (letters.length - 1) * gap;
|
|
2341
|
+
const centerX = width * 0.71;
|
|
2342
|
+
const startX = centerX - totalW / 2;
|
|
2343
|
+
const top = (height - glyphH) / 2;
|
|
2344
|
+
const stroke = Math.max(2, min * 0.013);
|
|
2345
|
+
drawGlow2(data, width, height, centerX, top + glyphH / 2, Math.max(glyphW, glyphH) * 0.9, LIME, 0.022 + load * 0.02);
|
|
2346
|
+
const strokeAlpha = 0.1 + load * 0.06;
|
|
2347
|
+
letters.split("").forEach((letter, index) => {
|
|
2348
|
+
const segments = RIG_GLYPH_STROKES[letter];
|
|
2349
|
+
if (!segments)
|
|
2350
|
+
return;
|
|
2351
|
+
const ox = startX + index * (glyphW + gap);
|
|
2352
|
+
for (const [x0, y0, x1, y1] of segments) {
|
|
2353
|
+
drawLine2(data, width, height, ox + x0 * glyphW, top + y0 * glyphH, ox + x1 * glyphW, top + y1 * glyphH, LIME_DIM, strokeAlpha, stroke);
|
|
2354
|
+
}
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
function drawBackground(data, width, height, _tick, scene, layout, load, activeRuns) {
|
|
2358
|
+
fillRgba(data, BG, BG_WORD);
|
|
2359
|
+
drawStaticAsciiFleetBackground(data, width, height, scene, layout, load, activeRuns);
|
|
2360
|
+
drawBigRigWordmark(data, width, height, layout, load);
|
|
2361
|
+
applyStaticAtmosphere(data, width, height, load);
|
|
2362
|
+
}
|
|
2363
|
+
function imageVisualFrameKey(input) {
|
|
2364
|
+
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
2365
|
+
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
2366
|
+
const layer = "layer" in input ? input.layer ?? "full" : "full";
|
|
2367
|
+
const load = loadBucket(input.load);
|
|
2368
|
+
return `${layer}:${width}x${height}:${input.layout.width}x${input.layout.height}:${input.scene}:${input.tick}:l${load}:${input.panels.map((panel) => `${panel.id}:${panel.top}:${panel.height}:${panel.width ?? ""}:${panel.left ?? ""}:${panel.headerHeight ?? ""}`).join("|")}`;
|
|
2369
|
+
}
|
|
2370
|
+
function encodeKittyFrame(width, height, data, input) {
|
|
2371
|
+
if (input.transport === "png") {
|
|
2372
|
+
const png = encodePng(width, height, data);
|
|
2373
|
+
return kittyImageSequence(png.toString("base64"), { columns: input.layout.width, rows: input.layout.height, imageId: input.imageId, zIndex: input.zIndex, format: 100 });
|
|
2374
|
+
}
|
|
2375
|
+
const compressed = deflateSync(data, { level: ZLIB_LEVEL });
|
|
2376
|
+
return kittyImageSequence(compressed.toString("base64"), {
|
|
2377
|
+
columns: input.layout.width,
|
|
2378
|
+
rows: input.layout.height,
|
|
2379
|
+
imageId: input.imageId,
|
|
2380
|
+
zIndex: input.zIndex,
|
|
2381
|
+
format: 32,
|
|
2382
|
+
pixelWidth: width,
|
|
2383
|
+
pixelHeight: height,
|
|
2384
|
+
compressed: true
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
function cropRgba(data, sourceWidth, rect) {
|
|
2388
|
+
const out = new Uint8ClampedArray(rect.width * rect.height * 4);
|
|
2389
|
+
for (let y = 0;y < rect.height; y += 1) {
|
|
2390
|
+
const sourceStart = ((rect.top + y) * sourceWidth + rect.left) * 4;
|
|
2391
|
+
out.set(data.subarray(sourceStart, sourceStart + rect.width * 4), y * rect.width * 4);
|
|
2392
|
+
}
|
|
2393
|
+
return out;
|
|
2394
|
+
}
|
|
2395
|
+
function encodePanelPatch(data, sourceWidth, placement, imageId, zIndex) {
|
|
2396
|
+
const patch = cropRgba(data, sourceWidth, placement);
|
|
2397
|
+
const png = encodePng(placement.width, placement.height, patch);
|
|
2398
|
+
const sequence = kittyImageSequence(png.toString("base64"), {
|
|
2399
|
+
columns: Math.max(1, Math.round(placement.widthCells)),
|
|
2400
|
+
rows: Math.max(1, Math.round(placement.heightCells)),
|
|
2401
|
+
imageId,
|
|
2402
|
+
zIndex,
|
|
2403
|
+
format: 100
|
|
2404
|
+
});
|
|
2405
|
+
return `\x1B[${Math.max(1, Math.round(placement.topCells) + 1)};${Math.max(1, Math.round(placement.leftCells) + 1)}H${sequence}`;
|
|
2406
|
+
}
|
|
2407
|
+
function renderImageVisualFrame(input) {
|
|
2408
|
+
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
2409
|
+
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
2410
|
+
const byteCount = width * height * 4;
|
|
2411
|
+
if (byteCount > MAX_IMAGE_BYTES)
|
|
2412
|
+
return null;
|
|
2413
|
+
const layer = input.layer ?? "full";
|
|
2414
|
+
const data = new Uint8ClampedArray(byteCount);
|
|
2415
|
+
const load = loadBucket(input.load) / LOAD_BUCKETS;
|
|
2416
|
+
const activeRuns = Math.max(0, Math.floor(input.activeRuns ?? 0));
|
|
2417
|
+
drawBackground(data, width, height, 0, input.scene, input.layout, load, activeRuns);
|
|
2418
|
+
if (layer === "split") {
|
|
2419
|
+
const sequences = [encodeKittyFrame(width, height, data, input)];
|
|
2420
|
+
let panelIndex = 0;
|
|
2421
|
+
for (const panel of input.panels) {
|
|
2422
|
+
if (panel.chrome !== "ad-terminal")
|
|
2423
|
+
continue;
|
|
2424
|
+
const placement = panelPixelPlacement(input.layout, panel, { width, height });
|
|
2425
|
+
if (!placement)
|
|
2426
|
+
continue;
|
|
2427
|
+
const cellH = height / input.layout.height;
|
|
2428
|
+
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
2429
|
+
compositePanel(data, width, height, placement, headerPx);
|
|
2430
|
+
const imageId = input.imageIds?.[panelIndex] ?? (input.imageId + 1000 + panelIndex >>> 0 || panelIndex + 1);
|
|
2431
|
+
sequences.push(encodePanelPatch(data, width, placement, imageId, -12));
|
|
2432
|
+
panelIndex += 1;
|
|
2433
|
+
}
|
|
2434
|
+
return { key: imageVisualFrameKey(input), sequence: sequences.join("") };
|
|
2435
|
+
}
|
|
2436
|
+
if (layer === "panel-chrome")
|
|
2437
|
+
return { key: imageVisualFrameKey(input), sequence: "" };
|
|
2438
|
+
if (layer === "background") {
|
|
2439
|
+
return { key: imageVisualFrameKey(input), sequence: encodeKittyFrame(width, height, data, input) };
|
|
2440
|
+
}
|
|
2441
|
+
if (layer === "panel-patches") {
|
|
2442
|
+
const sequences = [];
|
|
2443
|
+
let panelIndex = 0;
|
|
2444
|
+
for (const panel of input.panels) {
|
|
2445
|
+
if (panel.chrome !== "ad-terminal")
|
|
2446
|
+
continue;
|
|
2447
|
+
const placement = panelPixelPlacement(input.layout, panel, { width, height });
|
|
2448
|
+
if (!placement)
|
|
2449
|
+
continue;
|
|
2450
|
+
const cellH = height / input.layout.height;
|
|
2451
|
+
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
2452
|
+
compositePanel(data, width, height, placement, headerPx);
|
|
2453
|
+
const imageId = input.imageIds?.[panelIndex] ?? (input.imageId + 1000 + panelIndex >>> 0 || panelIndex + 1);
|
|
2454
|
+
sequences.push(encodePanelPatch(data, width, placement, imageId, input.zIndex));
|
|
2455
|
+
panelIndex += 1;
|
|
2456
|
+
}
|
|
2457
|
+
return { key: imageVisualFrameKey(input), sequence: sequences.join("") };
|
|
2458
|
+
}
|
|
2459
|
+
for (const panel of input.panels) {
|
|
2460
|
+
if (panel.chrome !== "ad-terminal")
|
|
2461
|
+
continue;
|
|
2462
|
+
const rect = panelRect(input.layout, panel, { width, height });
|
|
2463
|
+
if (!rect)
|
|
2464
|
+
continue;
|
|
2465
|
+
const cellH = height / input.layout.height;
|
|
2466
|
+
const headerPx = Math.max(cellH * 3, (panel.headerHeight ?? 3) * cellH);
|
|
2467
|
+
compositePanel(data, width, height, rect, headerPx);
|
|
2468
|
+
}
|
|
2469
|
+
return { key: imageVisualFrameKey(input), sequence: encodeKittyFrame(width, height, data, input) };
|
|
2470
|
+
}
|
|
2471
|
+
function shouldRenderImagesInline() {
|
|
2472
|
+
return process.env.RIG_OPENTUI_IMAGE_WORKER === "0" || import.meta.url.includes("$bunfs");
|
|
2473
|
+
}
|
|
2474
|
+
function createImageWorker() {
|
|
2475
|
+
if (shouldRenderImagesInline())
|
|
2476
|
+
return null;
|
|
2477
|
+
const isTypeScriptRuntime = import.meta.url.endsWith(".ts");
|
|
2478
|
+
const workerUrl = new URL(isTypeScriptRuntime ? "./image-visual-layer-worker.ts" : "./image-visual-layer-worker.js", import.meta.url);
|
|
2479
|
+
try {
|
|
2480
|
+
return new Worker(workerUrl);
|
|
2481
|
+
} catch {
|
|
2482
|
+
if (typeof process.versions.bun === "string") {
|
|
2483
|
+
try {
|
|
2484
|
+
return new Worker("./src/app-opentui/render/image-visual-layer-worker.ts");
|
|
2485
|
+
} catch {}
|
|
2486
|
+
}
|
|
2487
|
+
return null;
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
var RECENT_WRITTEN_LIMIT = 24;
|
|
2491
|
+
var DEFAULT_IMAGE_OUTPUT_BACKLOG_BYTES = 256 * 1024;
|
|
2492
|
+
var DEFAULT_IMAGE_OUTPUT_BYTES_PER_SECOND = 850 * 1024;
|
|
2493
|
+
function imageOutputBacklogBytes() {
|
|
2494
|
+
const raw = Number.parseInt(process.env.RIG_OPENTUI_IMAGE_BACKLOG_BYTES ?? "", 10);
|
|
2495
|
+
if (Number.isFinite(raw) && raw > 0)
|
|
2496
|
+
return Math.max(64 * 1024, Math.min(2 * 1024 * 1024, raw));
|
|
2497
|
+
return DEFAULT_IMAGE_OUTPUT_BACKLOG_BYTES;
|
|
2498
|
+
}
|
|
2499
|
+
function imageOutputBytesPerSecond() {
|
|
2500
|
+
const raw = Number.parseInt(process.env.RIG_OPENTUI_IMAGE_BYTES_PER_SECOND ?? "", 10);
|
|
2501
|
+
if (Number.isFinite(raw) && raw > 0)
|
|
2502
|
+
return Math.max(128 * 1024, Math.min(2 * 1024 * 1024, raw));
|
|
2503
|
+
return DEFAULT_IMAGE_OUTPUT_BYTES_PER_SECOND;
|
|
2504
|
+
}
|
|
2505
|
+
function pendingLayerKey(key) {
|
|
2506
|
+
return key.split(":", 1)[0] || "full";
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
class ImageVisualLayer {
|
|
2510
|
+
imageId = allocateImageId();
|
|
2511
|
+
panelImageIds = Array.from({ length: 8 }, () => allocateImageId());
|
|
2512
|
+
panelChromeImageIds = Array.from({ length: 8 }, () => allocateImageId());
|
|
2513
|
+
stdout;
|
|
2514
|
+
onFrameReady;
|
|
2515
|
+
protocol;
|
|
2516
|
+
transport = imageTransport();
|
|
2517
|
+
maxOutputBacklogBytes = imageOutputBacklogBytes();
|
|
2518
|
+
outputBytesPerSecond = imageOutputBytesPerSecond();
|
|
2519
|
+
outputBudgetBytes = imageOutputBytesPerSecond();
|
|
2520
|
+
lastBudgetAtMs = Date.now();
|
|
2521
|
+
motionSlot = this.createSlot();
|
|
2522
|
+
workersStarted = false;
|
|
2523
|
+
pendingFrames = new Map;
|
|
2524
|
+
recentWrittenKeys = [];
|
|
2525
|
+
imagesVisible = false;
|
|
2526
|
+
flushPaused = false;
|
|
2527
|
+
requestId = 0;
|
|
2528
|
+
lastBackgroundKey = "";
|
|
2529
|
+
fatalWorkerError = null;
|
|
2530
|
+
destroyed = false;
|
|
2531
|
+
constructor(stdout = process.stdout, onFrameReady) {
|
|
2532
|
+
this.stdout = stdout;
|
|
2533
|
+
this.onFrameReady = onFrameReady;
|
|
2534
|
+
this.protocol = getRigTerminalCapabilities().imageProtocol;
|
|
2535
|
+
}
|
|
2536
|
+
get enabled() {
|
|
2537
|
+
return this.protocol === "kitty";
|
|
2538
|
+
}
|
|
2539
|
+
clear() {
|
|
2540
|
+
if (this.enabled) {
|
|
2541
|
+
if (this.imagesVisible)
|
|
2542
|
+
this.stdout.write([this.imageId, ...this.panelImageIds, ...this.panelChromeImageIds].map((id) => deleteKittyImage(id)).join("") + "\x1B[?25h");
|
|
2543
|
+
this.imagesVisible = false;
|
|
2544
|
+
this.pendingFrames.clear();
|
|
2545
|
+
this.recentWrittenKeys.length = 0;
|
|
2546
|
+
this.resetSlot(this.motionSlot);
|
|
2547
|
+
this.lastBackgroundKey = "";
|
|
2548
|
+
this.outputBudgetBytes = this.outputBytesPerSecond;
|
|
2549
|
+
this.lastBudgetAtMs = Date.now();
|
|
2550
|
+
this.motionSlot.clearedThroughRequestId = this.requestId;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
destroy() {
|
|
2554
|
+
if (this.destroyed)
|
|
2555
|
+
return;
|
|
2556
|
+
this.clear();
|
|
2557
|
+
this.destroyed = true;
|
|
2558
|
+
const workers = [this.motionSlot.worker];
|
|
2559
|
+
this.motionSlot.worker = null;
|
|
2560
|
+
for (const worker of workers)
|
|
2561
|
+
if (worker)
|
|
2562
|
+
worker.terminate().catch(() => {
|
|
2563
|
+
return;
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
setFlushPaused(paused) {
|
|
2567
|
+
this.flushPaused = paused;
|
|
2568
|
+
}
|
|
2569
|
+
isReady(input) {
|
|
2570
|
+
if (!this.enabled || this.destroyed)
|
|
2571
|
+
return true;
|
|
2572
|
+
this.throwIfFatal();
|
|
2573
|
+
const splitKey = imageVisualFrameKey({ ...input, tick: 0, layer: "split" });
|
|
2574
|
+
return this.recentWrittenKeys.includes(splitKey) || Array.from(this.pendingFrames.values()).some((frame) => frame.key === splitKey);
|
|
2575
|
+
}
|
|
2576
|
+
render(input) {
|
|
2577
|
+
if (!this.enabled || this.destroyed)
|
|
2578
|
+
return;
|
|
2579
|
+
this.throwIfFatal();
|
|
2580
|
+
if (this.transport !== "png")
|
|
2581
|
+
this.failWorker("renderer", new Error("OpenTUI image visuals require PNG transport for static-background rendering."));
|
|
2582
|
+
this.ensureWorkersStarted();
|
|
2583
|
+
const width = Math.max(1, Math.floor(input.pixelSize.width));
|
|
2584
|
+
const height = Math.max(1, Math.floor(input.pixelSize.height));
|
|
2585
|
+
if (width * height * 4 > MAX_IMAGE_BYTES)
|
|
2586
|
+
return;
|
|
2587
|
+
if (this.isOutputBackedUp())
|
|
2588
|
+
return;
|
|
2589
|
+
this.refillOutputBudget();
|
|
2590
|
+
const splitInput = { ...input, tick: 0, layer: "split" };
|
|
2591
|
+
const splitKey = imageVisualFrameKey(splitInput);
|
|
2592
|
+
if (input.force || splitKey !== this.lastBackgroundKey) {
|
|
2593
|
+
this.scheduleRender(this.motionSlot, splitInput, this.imageId, -30, input.force, this.panelImageIds);
|
|
2594
|
+
this.lastBackgroundKey = splitKey;
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
flush() {
|
|
2598
|
+
this.throwIfFatal();
|
|
2599
|
+
if (this.flushPaused)
|
|
2600
|
+
return false;
|
|
2601
|
+
if (this.pendingFrames.size === 0)
|
|
2602
|
+
return false;
|
|
2603
|
+
this.refillOutputBudget();
|
|
2604
|
+
if (this.isOutputBackedUp()) {
|
|
2605
|
+
const retainedSplit = this.pendingFrames.get("split");
|
|
2606
|
+
this.pendingFrames.clear();
|
|
2607
|
+
if (retainedSplit)
|
|
2608
|
+
this.pendingFrames.set("split", retainedSplit);
|
|
2609
|
+
return false;
|
|
2610
|
+
}
|
|
2611
|
+
const framePriority = (frame) => {
|
|
2612
|
+
const layer = pendingLayerKey(frame.key);
|
|
2613
|
+
if (layer === "split")
|
|
2614
|
+
return 1;
|
|
2615
|
+
return 4;
|
|
2616
|
+
};
|
|
2617
|
+
const frames = Array.from(this.pendingFrames.values()).sort((a, b) => framePriority(a) - framePriority(b));
|
|
2618
|
+
const prefix = "\x1B[?25l\x1B7\x1B[s\x1B[H";
|
|
2619
|
+
const suffix = "\x1B[u\x1B8";
|
|
2620
|
+
const selected = [];
|
|
2621
|
+
const retained = new Map;
|
|
2622
|
+
let sequence = "";
|
|
2623
|
+
let byteLength = Buffer.byteLength(prefix + suffix);
|
|
2624
|
+
for (const frame of frames) {
|
|
2625
|
+
const candidate = sequence + frame.sequence;
|
|
2626
|
+
const candidateBytes = Buffer.byteLength(prefix + candidate + suffix);
|
|
2627
|
+
const layer = pendingLayerKey(frame.key);
|
|
2628
|
+
const allowOneStaticFrame = selected.length === 0 && layer === "split";
|
|
2629
|
+
if (candidateBytes <= this.outputBudgetBytes || allowOneStaticFrame) {
|
|
2630
|
+
selected.push(frame);
|
|
2631
|
+
sequence = candidate;
|
|
2632
|
+
byteLength = candidateBytes;
|
|
2633
|
+
} else if (layer === "split") {
|
|
2634
|
+
retained.set(layer, frame);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
this.pendingFrames.clear();
|
|
2638
|
+
for (const [layer, frame] of retained)
|
|
2639
|
+
this.pendingFrames.set(layer, frame);
|
|
2640
|
+
if (!sequence || selected.length === 0)
|
|
2641
|
+
return false;
|
|
2642
|
+
const payload = `${prefix}${sequence}${suffix}`;
|
|
2643
|
+
for (const frame of selected)
|
|
2644
|
+
this.markWritten(frame.key);
|
|
2645
|
+
this.outputBudgetBytes -= byteLength;
|
|
2646
|
+
this.stdout.cork?.();
|
|
2647
|
+
const accepted = this.stdout.write(payload);
|
|
2648
|
+
this.stdout.uncork?.();
|
|
2649
|
+
this.imagesVisible = true;
|
|
2650
|
+
return accepted;
|
|
2651
|
+
}
|
|
2652
|
+
createSlot() {
|
|
2653
|
+
return { worker: null, busy: false, queuedRequest: null, inFlightKey: "", queuedKey: "", clearedThroughRequestId: 0, latestRequestId: 0 };
|
|
2654
|
+
}
|
|
2655
|
+
resetSlot(slot) {
|
|
2656
|
+
slot.busy = false;
|
|
2657
|
+
slot.queuedRequest = null;
|
|
2658
|
+
slot.inFlightKey = "";
|
|
2659
|
+
slot.queuedKey = "";
|
|
2660
|
+
}
|
|
2661
|
+
markWritten(key) {
|
|
2662
|
+
this.recentWrittenKeys.push(key);
|
|
2663
|
+
while (this.recentWrittenKeys.length > RECENT_WRITTEN_LIMIT)
|
|
2664
|
+
this.recentWrittenKeys.shift();
|
|
2665
|
+
}
|
|
2666
|
+
refillOutputBudget() {
|
|
2667
|
+
const now = Date.now();
|
|
2668
|
+
const elapsedMs = Math.max(0, now - this.lastBudgetAtMs);
|
|
2669
|
+
this.lastBudgetAtMs = now;
|
|
2670
|
+
this.outputBudgetBytes = Math.min(this.outputBytesPerSecond, this.outputBudgetBytes + elapsedMs / 1000 * this.outputBytesPerSecond);
|
|
2671
|
+
}
|
|
2672
|
+
isOutputBackedUp() {
|
|
2673
|
+
return Boolean(this.stdout.writableNeedDrain) || this.stdout.writableLength > this.maxOutputBacklogBytes;
|
|
2674
|
+
}
|
|
2675
|
+
stageFrame(frame) {
|
|
2676
|
+
this.pendingFrames.set(pendingLayerKey(frame.key), frame);
|
|
2677
|
+
}
|
|
2678
|
+
isKnownKey(slot, key) {
|
|
2679
|
+
return this.recentWrittenKeys.includes(key) || Array.from(this.pendingFrames.values()).some((frame) => frame.key === key) || key === slot.inFlightKey || key === slot.queuedKey;
|
|
2680
|
+
}
|
|
2681
|
+
ensureWorkersStarted() {
|
|
2682
|
+
if (this.workersStarted)
|
|
2683
|
+
return;
|
|
2684
|
+
this.workersStarted = true;
|
|
2685
|
+
this.startWorker(this.motionSlot, "static-visuals");
|
|
2686
|
+
}
|
|
2687
|
+
failWorker(name, error) {
|
|
2688
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
2689
|
+
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} failed: ${detail}`);
|
|
2690
|
+
throw this.fatalWorkerError;
|
|
2691
|
+
}
|
|
2692
|
+
throwIfFatal() {
|
|
2693
|
+
if (this.fatalWorkerError)
|
|
2694
|
+
throw this.fatalWorkerError;
|
|
2695
|
+
}
|
|
2696
|
+
scheduleRender(slot, input, imageId, zIndex, force, imageIds) {
|
|
2697
|
+
this.throwIfFatal();
|
|
2698
|
+
const key = imageVisualFrameKey(input);
|
|
2699
|
+
if (!force && this.isKnownKey(slot, key))
|
|
2700
|
+
return;
|
|
2701
|
+
const request = {
|
|
2702
|
+
...input,
|
|
2703
|
+
imageId,
|
|
2704
|
+
...imageIds ? { imageIds } : {},
|
|
2705
|
+
zIndex,
|
|
2706
|
+
transport: this.transport,
|
|
2707
|
+
requestId: ++this.requestId,
|
|
2708
|
+
key
|
|
2709
|
+
};
|
|
2710
|
+
slot.latestRequestId = request.requestId;
|
|
2711
|
+
if (!slot.worker) {
|
|
2712
|
+
this.renderInline(slot, request);
|
|
2713
|
+
return;
|
|
2714
|
+
}
|
|
2715
|
+
this.enqueueWorkerRender(slot, request);
|
|
2716
|
+
}
|
|
2717
|
+
startWorker(slot, name) {
|
|
2718
|
+
const worker = createImageWorker();
|
|
2719
|
+
if (!worker)
|
|
2720
|
+
return;
|
|
2721
|
+
slot.worker = worker;
|
|
2722
|
+
worker.on("message", (message) => this.handleWorkerMessage(slot, message));
|
|
2723
|
+
worker.once("error", (error) => {
|
|
2724
|
+
if (!this.destroyed)
|
|
2725
|
+
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
2726
|
+
});
|
|
2727
|
+
worker.once("exit", (code) => {
|
|
2728
|
+
if (!this.destroyed)
|
|
2729
|
+
this.fatalWorkerError ??= new Error(`OpenTUI image worker ${name} exited unexpectedly with code ${code}.`);
|
|
2730
|
+
});
|
|
2731
|
+
}
|
|
2732
|
+
renderInline(slot, request) {
|
|
2733
|
+
try {
|
|
2734
|
+
const result = renderImageVisualFrame(request);
|
|
2735
|
+
if (result?.sequence && !this.isKnownKey(slot, result.key) && (!this.isOutputBackedUp() || pendingLayerKey(result.key) === "split")) {
|
|
2736
|
+
this.stageFrame({ key: result.key, sequence: result.sequence });
|
|
2737
|
+
this.onFrameReady?.();
|
|
2738
|
+
}
|
|
2739
|
+
} catch (error) {
|
|
2740
|
+
this.failWorker(String(request.layer ?? "visual"), error);
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
enqueueWorkerRender(slot, request) {
|
|
2744
|
+
this.throwIfFatal();
|
|
2745
|
+
if (slot.busy) {
|
|
2746
|
+
slot.queuedRequest = request;
|
|
2747
|
+
slot.queuedKey = request.key;
|
|
2748
|
+
return;
|
|
2749
|
+
}
|
|
2750
|
+
this.dispatchWorkerRender(slot, request);
|
|
2751
|
+
}
|
|
2752
|
+
dispatchWorkerRender(slot, request) {
|
|
2753
|
+
this.throwIfFatal();
|
|
2754
|
+
if (!slot.worker)
|
|
2755
|
+
this.failWorker(String(request.layer ?? "visual"), new Error("worker is unavailable"));
|
|
2756
|
+
slot.busy = true;
|
|
2757
|
+
slot.inFlightKey = request.key;
|
|
2758
|
+
try {
|
|
2759
|
+
slot.worker.postMessage(request);
|
|
2760
|
+
} catch (error) {
|
|
2761
|
+
this.failWorker(String(request.layer ?? "visual"), error);
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
handleWorkerMessage(slot, message) {
|
|
2765
|
+
if (this.destroyed || !message || typeof message !== "object")
|
|
2766
|
+
return;
|
|
2767
|
+
const response = message;
|
|
2768
|
+
slot.busy = false;
|
|
2769
|
+
slot.inFlightKey = "";
|
|
2770
|
+
const isStale = response.requestId <= slot.clearedThroughRequestId || response.requestId < slot.latestRequestId;
|
|
2771
|
+
if (!isStale) {
|
|
2772
|
+
if (response.error)
|
|
2773
|
+
this.failWorker(pendingLayerKey(response.key), new Error(response.error));
|
|
2774
|
+
if (response.sequence && !this.isKnownKey(slot, response.key) && (!this.isOutputBackedUp() || pendingLayerKey(response.key) === "split")) {
|
|
2775
|
+
this.stageFrame({ key: response.key, sequence: response.sequence });
|
|
2776
|
+
this.onFrameReady?.();
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
const next = slot.queuedRequest;
|
|
2780
|
+
slot.queuedRequest = null;
|
|
2781
|
+
slot.queuedKey = "";
|
|
2782
|
+
if (next && !this.isKnownKey(slot, next.key))
|
|
2783
|
+
this.dispatchWorkerRender(slot, next);
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
// packages/cli/src/app-opentui/render/text.ts
|
|
2788
|
+
import { RGBA as RGBA5, TextAttributes as TextAttributes4, TextRenderable as TextRenderable2 } from "@opentui/core";
|
|
2789
|
+
var TRANSPARENT2 = RGBA5.fromInts(0, 0, 0, 0);
|
|
2790
|
+
|
|
2791
|
+
// packages/cli/src/app-opentui/render/panels.ts
|
|
2792
|
+
import { RGBA as RGBA6, ScrollBoxRenderable } from "@opentui/core";
|
|
2793
|
+
var TRANSPARENT3 = RGBA6.fromInts(0, 0, 0, 0);
|
|
2794
|
+
var PANEL_BORDER = hexToRgba(RIG_UI.border, 255);
|
|
2795
|
+
function hexToRgba(hex, alpha) {
|
|
2796
|
+
const clean = hex.replace(/^#/, "");
|
|
2797
|
+
const full = clean.length === 3 ? clean.split("").map((part) => `${part}${part}`).join("") : clean;
|
|
2798
|
+
const value = Number.parseInt(full, 16);
|
|
2799
|
+
if (!Number.isFinite(value))
|
|
2800
|
+
return RGBA6.fromInts(14, 15, 17, alpha);
|
|
2801
|
+
return RGBA6.fromInts(value >> 16 & 255, value >> 8 & 255, value & 255, alpha);
|
|
2802
|
+
}
|
|
2803
|
+
|
|
2804
|
+
// packages/cli/src/app-opentui/render/native-host.ts
|
|
2805
|
+
import {
|
|
2806
|
+
BoxRenderable as BoxRenderable2,
|
|
2807
|
+
CodeRenderable,
|
|
2808
|
+
DiffRenderable,
|
|
2809
|
+
RGBA as RGBA7,
|
|
2810
|
+
ScrollBoxRenderable as ScrollBoxRenderable2,
|
|
2811
|
+
SyntaxStyle,
|
|
2812
|
+
TextRenderable as TextRenderable3,
|
|
2813
|
+
TextTableRenderable
|
|
2814
|
+
} from "@opentui/core";
|
|
2815
|
+
|
|
2816
|
+
// packages/cli/src/app-opentui/runtime.ts
|
|
2817
|
+
var PRELOADER_BACKDROP = RGBA8.fromHex(RIG_UI.bg);
|
|
2818
|
+
function inboxPendingCount(state) {
|
|
2819
|
+
const inbox = state.data.inbox;
|
|
2820
|
+
if (!inbox || typeof inbox !== "object" || Array.isArray(inbox))
|
|
2821
|
+
return 0;
|
|
2822
|
+
const record = inbox;
|
|
2823
|
+
const approvals = Array.isArray(record.approvals) ? record.approvals.length : 0;
|
|
2824
|
+
const inputs = Array.isArray(record.inputs) ? record.inputs.length : 0;
|
|
2825
|
+
return approvals + inputs;
|
|
2826
|
+
}
|
|
2827
|
+
var PRIMARY_NAV = [
|
|
2828
|
+
{ id: "cockpit", label: "Cockpit", scene: "main", argv: ["main"], enterLabel: "Cockpit", member: ["main"] },
|
|
2829
|
+
{ id: "runs", label: "Runs", scene: "fleet", argv: ["runs"], enterLabel: "Runs", member: ["fleet", "run-detail", "inspect", "handoff"] },
|
|
2830
|
+
{ id: "tasks", label: "Tasks", scene: "tasks", argv: ["tasks"], enterLabel: "Tasks", member: ["tasks"] },
|
|
2831
|
+
{ id: "inbox", label: "Inbox", scene: "inbox", argv: ["inbox"], enterLabel: "Inbox", member: ["inbox"], badge: inboxPendingCount },
|
|
2832
|
+
{ id: "stats", label: "Stats", scene: "family", argv: ["stats"], enterLabel: "Stats", member: ["family"] },
|
|
2833
|
+
{ id: "setup", label: "Setup", scene: "init", argv: ["init"], enterLabel: "Setup", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
|
|
2834
|
+
{ id: "help", label: "Help", scene: "help", argv: ["help"], enterLabel: "Help", member: ["help"] }
|
|
2835
|
+
];
|
|
2836
|
+
function activeNavSection(scene) {
|
|
2837
|
+
return PRIMARY_NAV.find((section) => section.member.includes(scene)) ?? PRIMARY_NAV[0];
|
|
2838
|
+
}
|
|
2839
|
+
function sceneSectionLabel(scene) {
|
|
2840
|
+
const labels = {
|
|
2841
|
+
main: "cockpit",
|
|
2842
|
+
fleet: "runs",
|
|
2843
|
+
tasks: "tasks",
|
|
2844
|
+
inbox: "inbox",
|
|
2845
|
+
inspect: "inspect",
|
|
2846
|
+
"run-detail": "run",
|
|
2847
|
+
handoff: "pi console",
|
|
2848
|
+
server: "server",
|
|
2849
|
+
doctor: "doctor",
|
|
2850
|
+
init: "setup",
|
|
2851
|
+
pi: "pi",
|
|
2852
|
+
plugin: "plugins",
|
|
2853
|
+
repo: "repo",
|
|
2854
|
+
workspace: "workspace",
|
|
2855
|
+
family: "family",
|
|
2856
|
+
command: "command",
|
|
2857
|
+
help: "help",
|
|
2858
|
+
error: "error"
|
|
2859
|
+
};
|
|
2860
|
+
return labels[scene] ?? scene;
|
|
2861
|
+
}
|
|
2862
|
+
function buildNavStrip(state) {
|
|
2863
|
+
const active = activeNavSection(state.scene);
|
|
2864
|
+
const chunks = [];
|
|
2865
|
+
PRIMARY_NAV.forEach((section, index) => {
|
|
2866
|
+
if (index > 0)
|
|
2867
|
+
chunks.push(styles.ink4(" "));
|
|
2868
|
+
const isActive = section.id === active.id;
|
|
2869
|
+
chunks.push(isActive ? otuiBold(styles.lime(section.label)) : styles.ink3(section.label));
|
|
2870
|
+
const badgeCount = section.badge ? section.badge(state) : 0;
|
|
2871
|
+
if (badgeCount > 0) {
|
|
2872
|
+
chunks.push(styles.ink4(" "));
|
|
2873
|
+
chunks.push(otuiBold(styles.yellow(String(badgeCount))));
|
|
2874
|
+
}
|
|
2875
|
+
});
|
|
2876
|
+
return new StyledText4(chunks);
|
|
2877
|
+
}
|
|
2878
|
+
var DESTRUCTIVE_ACTION_KINDS = new Set(["run-stop", "inbox-reject"]);
|
|
2879
|
+
|
|
2880
|
+
// packages/cli/src/app-opentui/react/ChromeHost.tsx
|
|
2881
|
+
function isTerminalScene(scene) {
|
|
2882
|
+
return scene === "handoff" || scene === "command";
|
|
2883
|
+
}
|
|
2884
|
+
function ChromeHost(props) {
|
|
2885
|
+
const renderer = useRenderer();
|
|
2886
|
+
const dims = useTerminalDimensions();
|
|
2887
|
+
const navRef = useRef(null);
|
|
2888
|
+
const barRef = useRef(null);
|
|
2889
|
+
useEffect(() => {
|
|
2890
|
+
const nav = new TextRenderable5(renderer, { id: "react-primary-nav", content: "", position: "absolute", left: 0, top: -2, width: 1, zIndex: 9, selectable: false });
|
|
2891
|
+
renderer.root.add(nav);
|
|
2892
|
+
navRef.current = nav;
|
|
2893
|
+
const bar = createTypeBar(renderer);
|
|
2894
|
+
renderer.root.add(bar.background);
|
|
2895
|
+
renderer.root.add(bar.prefix);
|
|
2896
|
+
renderer.root.add(bar.input);
|
|
2897
|
+
renderer.root.add(bar.footer);
|
|
2898
|
+
barRef.current = bar;
|
|
2899
|
+
return () => {
|
|
2900
|
+
try {
|
|
2901
|
+
renderer.root.remove(nav.id);
|
|
2902
|
+
} catch {}
|
|
2903
|
+
for (const r of [bar.background, bar.prefix, bar.input, bar.footer]) {
|
|
2904
|
+
try {
|
|
2905
|
+
renderer.root.remove(r.id);
|
|
2906
|
+
} catch {}
|
|
2907
|
+
}
|
|
2908
|
+
navRef.current = null;
|
|
2909
|
+
barRef.current = null;
|
|
2910
|
+
};
|
|
2911
|
+
}, [renderer]);
|
|
2912
|
+
useEffect(() => {
|
|
2913
|
+
const { state, frame } = props;
|
|
2914
|
+
const layout = computeStageLayout(dims.width, dims.height);
|
|
2915
|
+
const nav = navRef.current;
|
|
2916
|
+
const bar = barRef.current;
|
|
2917
|
+
const terminalActive = isTerminalScene(state.scene);
|
|
2918
|
+
const showNav = !frame.fullScreen && !terminalActive && state.typeBar.mode !== "command";
|
|
2919
|
+
if (nav) {
|
|
2920
|
+
nav.visible = showNav;
|
|
2921
|
+
if (showNav) {
|
|
2922
|
+
nav.content = buildNavStrip(state);
|
|
2923
|
+
nav.left = layout.centerLeft;
|
|
2924
|
+
nav.top = Math.max(0, layout.centerTop - 2);
|
|
2925
|
+
nav.width = layout.centerWidth;
|
|
2926
|
+
nav.fg = RIG_UI.ink3;
|
|
2927
|
+
nav.zIndex = 9;
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
if (bar) {
|
|
2931
|
+
if (frame.hideTypeBar) {
|
|
2932
|
+
hideTypeBar(bar, layout.height);
|
|
2933
|
+
} else {
|
|
2934
|
+
positionTypeBar(bar, { ...state.typeBar, placeholder: frame.typeBarPlaceholder ?? state.typeBar.placeholder }, { section: sceneSectionLabel(state.scene), ...state.footer, ...frame.footer ?? {} }, layout.width, layout.typeBarTop, layout.footerTop);
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
});
|
|
2938
|
+
return null;
|
|
2939
|
+
}
|
|
2940
|
+
export {
|
|
2941
|
+
ChromeHost
|
|
2942
|
+
};
|