Skip to content

Commit 9be7431

Browse files
fix(tui): inline ProgressBar to fix empty home/sidebar (#210) (#211)
1 parent 1bc7fc5 commit 9be7431

4 files changed

Lines changed: 70 additions & 3 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@four-bytes/four-opencode-brain",
3-
"version": "1.8.5",
3+
"version": "1.8.6",
44
"description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base",
55
"license": "Apache-2.0",
66
"type": "module",

‎src/progress.tsx‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* ProgressBar component inlined from @four-bytes/opencode-plugin-lib/tui-components
3+
* (Apache-2.0) to avoid the broken raw-.jsx node_modules dependency.
4+
*/
5+
/** @jsxImportSource @opentui/solid */
6+
import { createMemo } from "solid-js";
7+
8+
export interface ProgressBarProps {
9+
current: number;
10+
total: number;
11+
width?: number | "auto" | `${number}%`;
12+
barWidth?: number;
13+
showLabel?: boolean;
14+
rightAlign?: boolean;
15+
fillFg?: string;
16+
fillBg?: string;
17+
unfillFg?: string;
18+
unfillBg?: string;
19+
}
20+
21+
function centerText(s: string, width: number): string {
22+
if (s.length >= width) return s.slice(0, width);
23+
const left = Math.floor((width - s.length) / 2);
24+
return " ".repeat(left) + s + " ".repeat(Math.max(0, width - s.length - left));
25+
}
26+
27+
function formatNum(n: number): string {
28+
return n.toLocaleString("en-US");
29+
}
30+
31+
export function ProgressBar(props: ProgressBarProps) {
32+
const pct = createMemo(() => (props.total > 0 ? (props.current / props.total) * 100 : 0));
33+
const w = createMemo(() => props.barWidth ?? 10);
34+
const filledCount = createMemo(() => Math.round((props.current / props.total) * w()));
35+
const fillFg = createMemo(() => props.fillFg ?? "#fff");
36+
const fillBg = createMemo(() => props.fillBg ?? "#4caf50");
37+
const unfillFg = createMemo(() => props.unfillFg ?? "#888");
38+
const unfillBg = createMemo(() => props.unfillBg ?? "#2a2a2a");
39+
const text = createMemo(() => centerText(` ${pct().toFixed(1)}% `, w()));
40+
const showLabel = createMemo(() => props.showLabel !== false);
41+
const rightAlign = createMemo(() => props.rightAlign === true);
42+
const justify = createMemo(() => (rightAlign() ? "flex-end" : "flex-start"));
43+
44+
return (
45+
<box flexDirection="row" width={props.width ?? "100%"} justifyContent={justify()}>
46+
{showLabel() && <text>{`${formatNum(props.current)}/${formatNum(props.total)} `}</text>}
47+
<box flexDirection="row" justifyContent={justify()}>
48+
{Array.from(text()).map((char, i) => (
49+
<box backgroundColor={i < filledCount() ? fillBg() : unfillBg()}>
50+
<text fg={i < filledCount() ? fillFg() : unfillFg()}>{char}</text>
51+
</box>
52+
))}
53+
</box>
54+
</box>
55+
);
56+
}

‎src/tui.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createSignal, Show } from "solid-js";
44
import type { TuiPlugin, TuiPluginApi } from "@opencode-ai/plugin/tui";
55
import type { RGBA } from "@opentui/core";
66
import { useServiceBus } from "@four-bytes/opencode-plugin-lib/tui";
7-
import { ProgressBar } from "@four-bytes/opencode-plugin-lib/tui-components";
7+
import { ProgressBar } from "./progress";
88
import type { BrainStatusEvent } from "./event-bus";
99
import { Spinner } from "./spinner";
1010
import { readFileSync, existsSync } from "fs";

‎test/dist-integrity.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { describe, test, expect } from "bun:test";
2-
import { readFileSync } from "fs";
2+
import { readFileSync, existsSync } from "fs";
33
import { join } from "path";
44

55
const DIST_PATH = join(import.meta.dir, "..", "dist", "four-opencode-brain.js");
6+
const TUI_DIST_PATH = join(import.meta.dir, "..", "dist", "four-opencode-brain-tui.jsx");
7+
const PROGRESS_DIST_PATH = join(import.meta.dir, "..", "dist", "progress.jsx");
68

79
describe("dist-integrity", () => {
810
const dist = readFileSync(DIST_PATH, "utf-8");
@@ -29,4 +31,13 @@ describe("dist-integrity", () => {
2931
expect(hasReadFileSync).toBe(true);
3032
expect(hasPackageJson).toBe(true);
3133
});
34+
35+
test("TUI bundle does not reference broken tui-components import", () => {
36+
const tui = readFileSync(TUI_DIST_PATH, "utf-8");
37+
expect(tui).not.toContain("tui-components");
38+
});
39+
40+
test("progress.jsx is emitted as the inlined replacement", () => {
41+
expect(existsSync(PROGRESS_DIST_PATH)).toBe(true);
42+
});
3243
});

0 commit comments

Comments
 (0)