pi-chassis 0.0.0-stage → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/LICENSE +21 -0
  3. package/README.md +51 -2
  4. package/THIRD_PARTY_NOTICES +30 -0
  5. package/dist/chassis/alert.d.ts +50 -0
  6. package/dist/chassis/alert.js +107 -0
  7. package/dist/chassis/api.d.ts +411 -0
  8. package/dist/chassis/api.js +676 -0
  9. package/dist/chassis/bash-output.d.ts +89 -0
  10. package/dist/chassis/bash-output.js +157 -0
  11. package/dist/chassis/brand.d.ts +99 -0
  12. package/dist/chassis/brand.js +79 -0
  13. package/dist/chassis/client.d.ts +87 -0
  14. package/dist/chassis/client.js +271 -0
  15. package/dist/chassis/commands.d.ts +60 -0
  16. package/dist/chassis/commands.js +211 -0
  17. package/dist/chassis/editor.d.ts +70 -0
  18. package/dist/chassis/editor.js +213 -0
  19. package/dist/chassis/footer.d.ts +14 -0
  20. package/dist/chassis/footer.js +136 -0
  21. package/dist/chassis/header.d.ts +12 -0
  22. package/dist/chassis/header.js +38 -0
  23. package/dist/chassis/home.d.ts +48 -0
  24. package/dist/chassis/home.js +184 -0
  25. package/dist/chassis/icons.d.ts +203 -0
  26. package/dist/chassis/icons.js +190 -0
  27. package/dist/chassis/index.d.ts +21 -0
  28. package/dist/chassis/index.js +582 -0
  29. package/dist/chassis/layout.d.ts +40 -0
  30. package/dist/chassis/layout.js +264 -0
  31. package/dist/chassis/message-modes.d.ts +21 -0
  32. package/dist/chassis/message-modes.js +49 -0
  33. package/dist/chassis/messages.d.ts +75 -0
  34. package/dist/chassis/messages.js +392 -0
  35. package/dist/chassis/modes.d.ts +21 -0
  36. package/dist/chassis/modes.js +99 -0
  37. package/dist/chassis/palette.d.ts +84 -0
  38. package/dist/chassis/palette.js +235 -0
  39. package/dist/chassis/peek.d.ts +61 -0
  40. package/dist/chassis/peek.js +156 -0
  41. package/dist/chassis/prompt-row.d.ts +42 -0
  42. package/dist/chassis/prompt-row.js +68 -0
  43. package/dist/chassis/provider-view.d.ts +34 -0
  44. package/dist/chassis/provider-view.js +107 -0
  45. package/dist/chassis/provider.d.ts +69 -0
  46. package/dist/chassis/provider.js +73 -0
  47. package/dist/chassis/readonly-command.d.ts +19 -0
  48. package/dist/chassis/readonly-command.js +454 -0
  49. package/dist/chassis/sanitize.d.ts +42 -0
  50. package/dist/chassis/sanitize.js +103 -0
  51. package/dist/chassis/session-info.d.ts +39 -0
  52. package/dist/chassis/session-info.js +107 -0
  53. package/dist/chassis/sidebar.d.ts +48 -0
  54. package/dist/chassis/sidebar.js +273 -0
  55. package/dist/chassis/state.d.ts +38 -0
  56. package/dist/chassis/state.js +19 -0
  57. package/dist/chassis/telemetry.d.ts +60 -0
  58. package/dist/chassis/telemetry.js +191 -0
  59. package/dist/chassis/tools.d.ts +112 -0
  60. package/dist/chassis/tools.js +588 -0
  61. package/dist/chassis/version.d.ts +2 -0
  62. package/dist/chassis/version.js +20 -0
  63. package/dist/diff/git-diff.d.ts +71 -0
  64. package/dist/diff/git-diff.js +325 -0
  65. package/dist/diff/host.d.ts +34 -0
  66. package/dist/diff/host.js +50 -0
  67. package/dist/diff/index.d.ts +13 -0
  68. package/dist/diff/index.js +86 -0
  69. package/dist/diff/render.d.ts +67 -0
  70. package/dist/diff/render.js +196 -0
  71. package/dist/diff/types.d.ts +60 -0
  72. package/dist/diff/types.js +4 -0
  73. package/dist/diff/view.d.ts +118 -0
  74. package/dist/diff/view.js +528 -0
  75. package/dist/git/flows.d.ts +92 -0
  76. package/dist/git/flows.js +415 -0
  77. package/dist/git/forge.d.ts +26 -0
  78. package/dist/git/forge.js +41 -0
  79. package/dist/git/index.d.ts +20 -0
  80. package/dist/git/index.js +121 -0
  81. package/dist/git/repo.d.ts +64 -0
  82. package/dist/git/repo.js +186 -0
  83. package/dist/git/run.d.ts +38 -0
  84. package/dist/git/run.js +127 -0
  85. package/dist/git/settings.d.ts +8 -0
  86. package/dist/git/settings.js +38 -0
  87. package/dist/git/text.d.ts +51 -0
  88. package/dist/git/text.js +109 -0
  89. package/dist/widgets/container/detect.d.ts +23 -0
  90. package/dist/widgets/container/detect.js +67 -0
  91. package/dist/widgets/container/index.d.ts +9 -0
  92. package/dist/widgets/container/index.js +26 -0
  93. package/dist/widgets/mcp/index.d.ts +13 -0
  94. package/dist/widgets/mcp/index.js +50 -0
  95. package/dist/widgets/mcp/status.d.ts +50 -0
  96. package/dist/widgets/mcp/status.js +70 -0
  97. package/dist/widgets/session-todos/index.d.ts +12 -0
  98. package/dist/widgets/session-todos/index.js +52 -0
  99. package/dist/widgets/subagents/index.d.ts +16 -0
  100. package/dist/widgets/subagents/index.js +173 -0
  101. package/dist/widgets/subagents/status.d.ts +61 -0
  102. package/dist/widgets/subagents/status.js +198 -0
  103. package/dist/widgets/todo/index.d.ts +13 -0
  104. package/dist/widgets/todo/index.js +65 -0
  105. package/dist/widgets/todo/parse.d.ts +29 -0
  106. package/dist/widgets/todo/parse.js +122 -0
  107. package/docs/branding.md +25 -0
  108. package/docs/development.md +22 -0
  109. package/docs/diff-api.md +18 -0
  110. package/docs/git.md +23 -0
  111. package/docs/internals.md +13 -0
  112. package/docs/provider-status.md +23 -0
  113. package/docs/status-widgets.md +157 -0
  114. package/docs/tool-rows.md +50 -0
  115. package/docs/usage.md +62 -0
  116. package/docs/widgets.md +113 -0
  117. package/extensions/chassis/alert.ts +127 -0
  118. package/extensions/chassis/api.ts +967 -0
  119. package/extensions/chassis/bash-output.ts +186 -0
  120. package/extensions/chassis/brand.ts +151 -0
  121. package/extensions/chassis/client.ts +284 -0
  122. package/extensions/chassis/commands.ts +244 -0
  123. package/extensions/chassis/editor.ts +253 -0
  124. package/extensions/chassis/footer.ts +131 -0
  125. package/extensions/chassis/header.ts +43 -0
  126. package/extensions/chassis/home.ts +186 -0
  127. package/extensions/chassis/icons.ts +220 -0
  128. package/extensions/chassis/index.ts +605 -0
  129. package/extensions/chassis/layout.ts +298 -0
  130. package/extensions/chassis/message-modes.ts +48 -0
  131. package/extensions/chassis/messages.ts +403 -0
  132. package/extensions/chassis/modes.ts +108 -0
  133. package/extensions/chassis/palette.ts +258 -0
  134. package/extensions/chassis/peek.ts +167 -0
  135. package/extensions/chassis/prompt-row.ts +86 -0
  136. package/extensions/chassis/provider-view.ts +118 -0
  137. package/extensions/chassis/provider.ts +115 -0
  138. package/extensions/chassis/readonly-command.ts +440 -0
  139. package/extensions/chassis/sanitize.ts +108 -0
  140. package/extensions/chassis/session-info.ts +127 -0
  141. package/extensions/chassis/sidebar.ts +285 -0
  142. package/extensions/chassis/state.ts +50 -0
  143. package/extensions/chassis/telemetry.ts +222 -0
  144. package/extensions/chassis/tools.ts +618 -0
  145. package/extensions/chassis/version.ts +20 -0
  146. package/extensions/diff/git-diff.ts +365 -0
  147. package/extensions/diff/host.ts +58 -0
  148. package/extensions/diff/index.ts +101 -0
  149. package/extensions/diff/render.ts +217 -0
  150. package/extensions/diff/types.ts +67 -0
  151. package/extensions/diff/view.ts +523 -0
  152. package/extensions/git/flows.ts +485 -0
  153. package/extensions/git/forge.ts +54 -0
  154. package/extensions/git/index.ts +117 -0
  155. package/extensions/git/repo.ts +200 -0
  156. package/extensions/git/run.ts +143 -0
  157. package/extensions/git/settings.ts +38 -0
  158. package/extensions/git/text.ts +133 -0
  159. package/extensions/widgets/container/detect.ts +81 -0
  160. package/extensions/widgets/container/index.ts +29 -0
  161. package/extensions/widgets/mcp/index.ts +53 -0
  162. package/extensions/widgets/mcp/status.ts +94 -0
  163. package/extensions/widgets/session-todos/index.ts +55 -0
  164. package/extensions/widgets/subagents/index.ts +170 -0
  165. package/extensions/widgets/subagents/status.ts +237 -0
  166. package/extensions/widgets/todo/index.ts +66 -0
  167. package/extensions/widgets/todo/parse.ts +119 -0
  168. package/package.json +91 -4
  169. package/scripts/link-pi.mjs +76 -0
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Sidebar layout.
3
+ *
4
+ * Fullscreen mode: pi renders one layout root (a VStack of transcript + input dock). We wrap it in
5
+ * an HStack with the sidebar as a fixed-width right column, which is what OpenCode looks like.
6
+ * There is no extension API for this: it relies on the TUI's `layoutRoot` field and
7
+ * `setLayoutRoot()` (pi-tui ViewportTUI), verified on pi 1.1.0. If either is missing, or pi
8
+ * swaps the root back (renderer switch), the guard widget re-wraps it or we fall back.
9
+ *
10
+ * Regular mode has no layout root, so the sidebar is a toggleable overlay instead.
11
+ *
12
+ * Home screen: until the session has a message, the same root swaps to OpenCode's home layout
13
+ * (home.ts): logo, centred prompt, tip and a bottom bar, with no transcript or sidebar. The root
14
+ * picks its layout node each frame, so the switch happens on the first message with no remount.
15
+ */
16
+ import { HStack, VStack } from "@earendil-works/pi-tui";
17
+ import { HOME_PROMPT_WIDTH, renderHomeFooter, renderLogo, renderTip } from "./home.js";
18
+ import { runWidgetClick } from "./api.js";
19
+ import { renderSidebar } from "./sidebar.js";
20
+ const ORIGINAL = Symbol.for("pi-chassis/original-root");
21
+ /**
22
+ * The tree to search for pi's own components. Once chassis has wrapped the layout root in its
23
+ * sidebar split, `tui.layoutRoot` is a plain object with no children; pi's real root hangs off it
24
+ * under a symbol. Without it, a search for message and tool components finds nothing.
25
+ */
26
+ export function piRootOf(tui) {
27
+ const root = tui?.layoutRoot ?? tui;
28
+ return root?.[ORIGINAL] ?? root;
29
+ }
30
+ /** pi-tui's layout-node hook (layout-node.ts); not exported, but a registered symbol. */
31
+ const LAYOUT_NODE = Symbol.for("@earendil-works/pi-tui/layout-node");
32
+ const GUARD_WIDGET = "chassis-layout";
33
+ const GUTTER = 2;
34
+ /** Blank column used as horizontal padding around the transcript and prompt. */
35
+ const gutter = { invalidate() { }, render: () => [] };
36
+ /** Blank rows (or columns); the size comes from the stack entry. */
37
+ const blank = () => ({ invalidate() { }, render: () => [] });
38
+ /** pi's input dock: the second entry of its root VStack (transcript, dock). */
39
+ function findDock(root) {
40
+ try {
41
+ const node = root[LAYOUT_NODE]?.();
42
+ const entries = node?.entries;
43
+ return entries && entries.length === 2 ? entries[1].component : undefined;
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }
49
+ export function installLayout(ctx, state, opts) {
50
+ let tui;
51
+ let theme;
52
+ let ourRoot;
53
+ let overlay;
54
+ let disposed = false;
55
+ const termWidth = () => tui?.terminal.columns ?? process.stdout.columns ?? 120;
56
+ const splitVisible = () => state.sidebarVisible && termWidth() >= opts.minTerminalWidth;
57
+ // The clickable rows of the last render. Only this leaf handles the mouse: the layout root has no
58
+ // handleMouse on purpose (see below), and a move or a click on any other row is left unhandled.
59
+ const hits = [];
60
+ const hitAt = (y) => hits.find((h) => h.y === y);
61
+ const sidebar = {
62
+ invalidate() { },
63
+ render(width) {
64
+ if (!theme)
65
+ return [];
66
+ return renderSidebar(state, theme, width, tui?.terminal.rows ?? 40, opts.piVersion, hits);
67
+ },
68
+ handleMouse(e) {
69
+ if (e.button !== "left" || (e.type !== "press" && e.type !== "click"))
70
+ return undefined;
71
+ const hit = hitAt(e.y);
72
+ if (!hit)
73
+ return undefined;
74
+ // A press claims the gesture so the click arrives; only the click acts, and neither repaints.
75
+ if (e.type === "click" && state.ctx) {
76
+ const ctx = state.ctx;
77
+ void runWidgetClick(hit.widgetId, hit.index, ctx).then((msg) => {
78
+ if (msg)
79
+ ctx.ui.notify(msg, "warning");
80
+ });
81
+ }
82
+ return { handled: true, render: false };
83
+ },
84
+ };
85
+ const wrap = () => {
86
+ if (!tui || disposed || typeof tui.setLayoutRoot !== "function")
87
+ return false;
88
+ const current = tui.layoutRoot;
89
+ if (!current)
90
+ return false;
91
+ if (current === ourRoot)
92
+ return true;
93
+ // A root we built earlier (previous session or /reload): unwrap to pi's own root.
94
+ const original = current[ORIGINAL] ?? current;
95
+ // OpenCode pads the session column 2 columns on each side (routes/session/index.tsx).
96
+ const split = new HStack([
97
+ { component: gutter, basis: GUTTER, grow: 0, shrink: 0 },
98
+ { component: original, basis: 0, grow: 1, shrink: 1, minSize: 20 },
99
+ { component: gutter, basis: GUTTER, grow: 0, shrink: 0 },
100
+ {
101
+ component: sidebar,
102
+ basis: opts.width,
103
+ grow: 0,
104
+ shrink: 0,
105
+ visible: (vp) => state.sidebarVisible && vp.width >= opts.minTerminalWidth,
106
+ },
107
+ ], { align: "stretch" });
108
+ const home = buildHome(original);
109
+ const pick = () => (home && opts.home() ? home : split);
110
+ // One root for both layouts: pi-tui asks for the layout node every frame.
111
+ // No handleMouse here on purpose: pi-tui routes mouse events to the leaf components through
112
+ // the cached layout frame. A handleMouse on the root makes it dispatch to the stack's
113
+ // Container.handleMouse, which re-renders the whole transcript on every event (fullscreen
114
+ // reports every pointer move), pinning a CPU core and freezing long sessions.
115
+ const root = {
116
+ invalidate() {
117
+ split.invalidate();
118
+ home?.invalidate();
119
+ },
120
+ render: (w) => pick().render(w),
121
+ [LAYOUT_NODE]: () => pick()[LAYOUT_NODE](),
122
+ };
123
+ root[ORIGINAL] = original;
124
+ ourRoot = root;
125
+ tui.setLayoutRoot(root);
126
+ return true;
127
+ };
128
+ /**
129
+ * OpenCode's home route, centred vertically: logo, the prompt (pi's whole input dock) centred at
130
+ * most 75 columns wide (with the brand line under it), a tip 3 rows below it, flexible space, and the bottom bar.
131
+ */
132
+ const buildHome = (original) => {
133
+ const dock = findDock(original);
134
+ if (!dock)
135
+ return undefined;
136
+ const logo = { invalidate() { }, render: (w) => (theme ? renderLogo(theme, w) : []) };
137
+ const tip = { invalidate() { }, render: (w) => (theme ? ["", "", "", ...renderTip(theme, w, opts.tipIndex)] : []) };
138
+ const footer = { invalidate() { }, render: (w) => (theme ? renderHomeFooter(state, theme, w, opts.piVersion) : []) };
139
+ // Left padding is sized each frame: pi-tui hands spare width to grow entries unevenly (the
140
+ // first gets the larger share), so two grow spacers wouldn't centre the prompt.
141
+ const leftPad = { component: blank(), basis: 0, grow: 0, shrink: 1 };
142
+ const promptRow = new HStack([
143
+ { component: blank(), basis: GUTTER, grow: 0, shrink: 0 },
144
+ leftPad,
145
+ { component: dock, basis: HOME_PROMPT_WIDTH, grow: 0, shrink: 1, minSize: 20 },
146
+ { component: blank(), basis: 0, grow: 1, shrink: 1 },
147
+ { component: blank(), basis: GUTTER, grow: 0, shrink: 0 },
148
+ ], { align: "start" });
149
+ const entries = promptRow.entries;
150
+ const centre = () => {
151
+ const free = termWidth() - GUTTER * 2 - HOME_PROMPT_WIDTH;
152
+ if (entries[1])
153
+ entries[1].basis = Math.max(0, Math.floor(free / 2));
154
+ };
155
+ // The top space is sized each frame from the content height so the logo, prompt and tip sit
156
+ // in the middle of the screen (grow spacers split spare rows unevenly, as above).
157
+ const contentHeight = (w) => logo.render(w).length + 1 + promptRow.render(w).length + tip.render(w).length;
158
+ const stack = new VStack([
159
+ { component: blank(), basis: 0, grow: 0, shrink: 1, minSize: 0 },
160
+ { component: logo, basis: "auto", grow: 0, shrink: 0 },
161
+ { component: blank(), basis: 1, grow: 0, shrink: 1, minSize: 0 },
162
+ { component: promptRow, basis: "auto", grow: 0, shrink: 1, minSize: 3 },
163
+ { component: tip, basis: "auto", grow: 0, shrink: 1, minSize: 0 },
164
+ { component: blank(), basis: 0, grow: 1, shrink: 1, minSize: 0 },
165
+ { component: footer, basis: "auto", grow: 0, shrink: 0 },
166
+ ]);
167
+ // VStack keeps its own copy of the entries; update that copy.
168
+ const rows = stack.entries;
169
+ const middle = () => {
170
+ const w = termWidth();
171
+ const free = (tui?.terminal.rows ?? 40) - contentHeight(w);
172
+ if (rows[0])
173
+ rows[0].basis = Math.max(0, Math.floor(free / 2));
174
+ };
175
+ const node = stack[LAYOUT_NODE].bind(stack);
176
+ return Object.assign(stack, {
177
+ [LAYOUT_NODE]: () => {
178
+ centre();
179
+ middle();
180
+ return node();
181
+ },
182
+ });
183
+ };
184
+ const unwrap = () => {
185
+ if (!tui || typeof tui.setLayoutRoot !== "function")
186
+ return;
187
+ const current = tui.layoutRoot;
188
+ if (current && current === ourRoot && current[ORIGINAL])
189
+ tui.setLayoutRoot(current[ORIGINAL]);
190
+ ourRoot = undefined;
191
+ };
192
+ // The guard is an empty widget inside pi's own layout. It renders every frame, so it notices
193
+ // when pi has replaced the root (e.g. after a renderer switch) and re-wraps on the next tick.
194
+ ctx.ui.setWidget(GUARD_WIDGET, (t, th) => {
195
+ tui = t;
196
+ theme = th;
197
+ if (wrap())
198
+ state.layout = "split";
199
+ else
200
+ state.layout = "overlay";
201
+ return {
202
+ invalidate() { },
203
+ render() {
204
+ theme = th;
205
+ if (!disposed && state.layout === "split" && tui?.layoutRoot !== ourRoot) {
206
+ queueMicrotask(() => {
207
+ if (!wrap())
208
+ state.layout = "overlay";
209
+ });
210
+ }
211
+ return [];
212
+ },
213
+ };
214
+ }, { placement: "belowEditor" });
215
+ const openOverlay = () => {
216
+ if (overlay || !theme)
217
+ return;
218
+ const entry = { close: () => { } };
219
+ overlay = entry;
220
+ void ctx.ui
221
+ .custom((t, th, _kb, done) => {
222
+ entry.close = () => done();
223
+ return {
224
+ invalidate() { },
225
+ render: (w) => renderSidebar(state, th, w, Math.min(t.terminal.rows - 2, 40), opts.piVersion),
226
+ };
227
+ }, {
228
+ overlay: true,
229
+ overlayOptions: { anchor: "top-right", width: opts.width, maxHeight: "90%", nonCapturing: true, margin: { top: 1, right: 1 } },
230
+ onHandle: (h) => {
231
+ entry.handle = h;
232
+ },
233
+ })
234
+ .finally(() => {
235
+ if (overlay === entry)
236
+ overlay = undefined;
237
+ });
238
+ };
239
+ return {
240
+ isShown: () => (state.layout === "split" ? splitVisible() && !opts.home() : overlay !== undefined),
241
+ toggle() {
242
+ if (state.layout === "split") {
243
+ state.sidebarVisible = !state.sidebarVisible;
244
+ tui?.requestRender();
245
+ return;
246
+ }
247
+ if (overlay)
248
+ overlay.close();
249
+ else
250
+ openOverlay();
251
+ },
252
+ dispose() {
253
+ disposed = true;
254
+ overlay?.close();
255
+ unwrap();
256
+ try {
257
+ ctx.ui.setWidget(GUARD_WIDGET, undefined);
258
+ }
259
+ catch {
260
+ // stale ctx
261
+ }
262
+ },
263
+ };
264
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Which mode each user message was sent in, read from the session.
3
+ *
4
+ * chassis writes a `chassis-mode` custom entry at every Build/Plan switch, so the mode of a
5
+ * message is the last such entry before it on the branch (build when there is none). The result is
6
+ * one mode per user message box that pi draws, in order, so the Nth box in the chat is the Nth
7
+ * mode. pi draws a box for a user message only when it has text, and for a skill block only when
8
+ * the block carries a message of its own (the skill itself is a different component).
9
+ */
10
+ import type { AgentMode } from "./state.ts";
11
+ /** Whether pi draws a user message box for this message. */
12
+ export declare function drawsUserBox(message: {
13
+ role?: string;
14
+ content?: unknown;
15
+ }): boolean;
16
+ /**
17
+ * The mode of every user message box, in order. `branch` is the whole branch from the root;
18
+ * `contextIds` are the ids of the entries pi draws (after a compaction, older ones are left out,
19
+ * but their mode entries still count).
20
+ */
21
+ export declare function userMessageModes(branch: readonly any[], contextIds: ReadonlySet<string>): AgentMode[];
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Which mode each user message was sent in, read from the session.
3
+ *
4
+ * chassis writes a `chassis-mode` custom entry at every Build/Plan switch, so the mode of a
5
+ * message is the last such entry before it on the branch (build when there is none). The result is
6
+ * one mode per user message box that pi draws, in order, so the Nth box in the chat is the Nth
7
+ * mode. pi draws a box for a user message only when it has text, and for a skill block only when
8
+ * the block carries a message of its own (the skill itself is a different component).
9
+ */
10
+ import { parseSkillBlock } from "@earendil-works/pi-coding-agent";
11
+ import { MODE_ENTRY } from "./modes.js";
12
+ /** The text pi shows for a user message: its text blocks joined, as pi's getUserMessageText does. */
13
+ function userText(message) {
14
+ const c = message.content;
15
+ if (typeof c === "string")
16
+ return c;
17
+ if (!Array.isArray(c))
18
+ return "";
19
+ return c.filter((b) => b?.type === "text").map((b) => String(b.text ?? "")).join("");
20
+ }
21
+ /** Whether pi draws a user message box for this message. */
22
+ export function drawsUserBox(message) {
23
+ if (message.role !== "user")
24
+ return false;
25
+ const text = userText(message);
26
+ if (!text)
27
+ return false;
28
+ const skill = parseSkillBlock(text);
29
+ return skill ? Boolean(skill.userMessage) : true;
30
+ }
31
+ /**
32
+ * The mode of every user message box, in order. `branch` is the whole branch from the root;
33
+ * `contextIds` are the ids of the entries pi draws (after a compaction, older ones are left out,
34
+ * but their mode entries still count).
35
+ */
36
+ export function userMessageModes(branch, contextIds) {
37
+ const modes = [];
38
+ let mode = "build";
39
+ for (const e of branch) {
40
+ if (e?.type === "custom" && e.customType === MODE_ENTRY) {
41
+ if (e.data?.mode === "plan" || e.data?.mode === "build")
42
+ mode = e.data.mode;
43
+ }
44
+ else if (e?.type === "message" && contextIds.has(e.id) && drawsUserBox(e.message ?? {})) {
45
+ modes.push(mode);
46
+ }
47
+ }
48
+ return modes;
49
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * OpenCode-style transcript styling. pi has no renderer hooks for these, so two prototype patches
3
+ * (pi and extensions share one module instance; verified on pi 1.1.0), both undone on uninstall:
4
+ *
5
+ * 1. User messages (UserMessageComponent.render): a ┃ bar in the agent colour, then the message
6
+ * on the panel background with 1 row of padding above and below and 2 columns on the left,
7
+ * like OpenCode's UserMessage box.
8
+ *
9
+ * ┃
10
+ * ┃ fix the failing test in src/app.ts
11
+ * ┃
12
+ *
13
+ * 2. Tool rows (ToolExecutionComponent.render): pi puts a blank line above every tool. OpenCode
14
+ * stacks consecutive one-line tools with no gap, so for our one-line rows ("self" shell, a
15
+ * single content line) the blank line is dropped when the item above is also a tool or a
16
+ * hidden thinking-only message.
17
+ *
18
+ * Other extensions' tools (default shell: a padded, shaded box) are compacted the same way
19
+ * when collapsed and their box holds at most 2 short lines: one row with "⚙", the call line,
20
+ * and the result line right-aligned and dim, e.g.
21
+ * lsp_diagnostics button.ts ✓ No diagnostics
22
+ * Errors, partial results, multi-line output and the expanded view (ctrl+o) keep pi's box.
23
+ *
24
+ * 3. Finished thinking (AssistantMessageComponent.render): with thinking blocks hidden, pi leaves a
25
+ * "Thinking..." label plus a blank line for every thinking block, i.e. between most tool calls
26
+ * and above every answer. OpenCode shows nothing once thinking is done, so in a finished message
27
+ * the hidden-thinking labels (and the spacer after each) are left out, and a message left with
28
+ * nothing visible renders no lines. While streaming the label stays (the thinking peek lives
29
+ * there). ctrl+t (pi's app.thinking.toggle) still shows full thinking.
30
+ *
31
+ * 4. Extension messages (CustomMessageComponent.render, e.g. a recall notice from a memory extension): pi
32
+ * draws them in a full-width shaded box. OpenCode draws notices as a ┃ bar in a muted colour
33
+ * beside a panel-shaded block, like its revert/error notices, so the box's own background is
34
+ * replaced with the panel shade and a dim bar is added. Messages whose renderer draws a plain
35
+ * row of its own (PLAIN_MESSAGE_TYPES) are left as that renderer draws them: no panel, no bar.
36
+ *
37
+ * Lines keep their OSC 133 prompt markers, which pi uses for prompt-to-prompt navigation.
38
+ */
39
+ import { type Theme } from "@earendil-works/pi-coding-agent";
40
+ import type { AgentMode, UiState } from "./state.ts";
41
+ export declare function memoLines(owner: object, slot: string, width: number, key: string, src: string[], build: () => string[]): string[];
42
+ /**
43
+ * Custom message types that draw themselves as a plain row, like a tool row, and so get no panel
44
+ * or bar from chassis. Extensions in other module scopes add theirs through the shared set, with
45
+ * `globalThis[Symbol.for("pi-chassis/plainMessageTypes")]`, so no import of chassis is needed.
46
+ */
47
+ export declare const PLAIN_MESSAGE_TYPES: Set<string>;
48
+ /**
49
+ * The mode a user box was sent in, so its bar keeps that colour when the mode changes later. It is
50
+ * read from the session once the box can be matched to its message: the Nth box is the Nth user
51
+ * message, trusted only when the two counts agree. Until then (a message not saved yet, or the chat
52
+ * not found yet) it is the mode the box was first drawn in, and `final` is false so the caller does
53
+ * not cache that guess.
54
+ */
55
+ export declare function modeOfUserBox(state: UiState, box: object): {
56
+ mode: AgentMode;
57
+ final: boolean;
58
+ };
59
+ /**
60
+ * Width of the label column on the right of a user box. It is the same for every mode, so a message
61
+ * wraps at the same place whichever mode it was sent in.
62
+ */
63
+ export declare const LABEL_COLUMN: number;
64
+ /** The text area is never narrower than this: a box too narrow to keep it has no label column at all. */
65
+ export declare const MIN_TEXT_WIDTH = 24;
66
+ export declare function installMessageStyle(state: UiState, getTheme: () => Theme | undefined): () => void;
67
+ /** True when a tool row draws more than one content line (a block, or an expanded row). */
68
+ export declare function isTall(c: any, width: number): boolean;
69
+ /**
70
+ * A finished assistant message whose only visible content is hidden thinking (it renders nothing).
71
+ */
72
+ export declare function isHiddenThoughtOnly(c: any): boolean;
73
+ export declare function setChatContainer(c: {
74
+ children: unknown[];
75
+ } | undefined): void;