Skip to content

fix: make the usage panel work on installed builds - #4

Open
toshon-jennings wants to merge 2 commits into
mainfrom
fix/usage-panel-resolution
Open

fix: make the usage panel work on installed builds#4
toshon-jennings wants to merge 2 commits into
mainfrom
fix/usage-panel-resolution

Conversation

@toshon-jennings

Copy link
Copy Markdown
Owner

The usage panel failed with Executable not found in $PATH: "opencode-usage", and fixing that surfaced a second, independent failure underneath it. Both are addressed here.

1. opencode-usage is unreachable from an installed build

usageCommand in packages/opencode/src/server/routes/instance/httpapi/server.ts tried three locations, and all three require the repo source tree to be on disk:

  • the import.meta.url-relative path — resolves into the embedded filesystem in a compiled single-file build, where no packages/ directory exists
  • resolve("packages/desktop/resources/opencode-usage") and resolve("../desktop/resources/opencode-usage") — cwd-relative, so they only hit when the process happens to be launched from the repo root

A compiled build therefore always fell through to the bare-name PATH lookup, and nothing in the install puts the script on PATH. The README already documents the PATH fallback as the escape hatch, but there was no supported way to reach it.

This adds a fourth candidate: the script sitting next to the running executable (dirname(process.execPath)), checked before giving up on PATH. That makes "install the helper alongside the binary" work, which is the natural layout for a single-binary install.

The Electron path in packages/desktop/src/main/ipc.ts already handles this correctly via process.resourcesPath and is left alone.

2. A missing sqlite3 CLI was reported as a missing database

The table probe in packages/desktop/resources/opencode-usage sends sqlite3's stderr to /dev/null. With no sqlite3 on PATH, every candidate database looks unreadable, the loop skips them all, and the script exits with:

No OpenCode database with usage data found in <dir>

That points at the data when the tool is what is missing — the database was completely intact. Worth calling out that the libsqlite3 shared library is not the sqlite3 CLI: a system can ship the library (and so look sqlite-capable) while lacking the binary this script needs, which is exactly how this presented.

A preflight check now names the real cause and gives the install command per platform.

Verification

Reproduced against a running opencode serve on a compiled build, where GET /usage returned:

{"stdout":"","stderr":"Executable not found in $PATH: \"opencode-usage\"","code":1}

After both fixes, with the script installed next to the binary and sqlite3 present, the same endpoint returns code: 0 and the panel renders the full table — nine columns plus the TOTAL row, confirmed in the browser rather than just over HTTP.

Intermediate state was checked too: with the script resolvable but sqlite3 still absent, the endpoint now reports the missing tool instead of the misleading database error.

Not covered: bun install was not run in this checkout, so the TypeScript change has not been compiled. It is a two-identifier import addition (dirname, join from node:path) with no shadowing in that scope. The shell script passes bash -n.

🤖 Generated with Claude Code

toshon-jennings and others added 2 commits August 22, 2026 20:07
The three existing candidates all require the repo source tree to be on
disk. A compiled single-file build has no `packages/` directory:
`import.meta.url` resolves into the embedded filesystem, and the two
cwd-relative paths only hit when the process happens to be launched from
the repo root. Installed builds therefore always fell through to the bare
`opencode-usage` PATH lookup, and nothing in the install puts it there --
so the usage panel failed with `Executable not found in $PATH`.

Look for the script alongside the running binary before giving up on
PATH, so a script installed next to the executable is found.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The table probe sends sqlite3's stderr to /dev/null, so when the sqlite3
CLI is absent every candidate database looks unreadable, the loop skips
them all, and the script exits with "No OpenCode database with usage data
found" -- pointing at the data when the tool is what is missing.

Check for sqlite3 up front and say so, noting that the libsqlite3 shared
library is not the same thing as the CLI, since a system can have the
library and still lack the binary this script needs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1eb7995156

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

fileURLToPath(new URL("../../../../../../desktop/resources/opencode-usage", import.meta.url)),
resolve("packages/desktop/resources/opencode-usage"),
resolve("../desktop/resources/opencode-usage"),
join(dirname(process.execPath), "opencode-usage"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Package the helper beside installed binaries

This lookup still does not make the usage panel work for normal CLI installations because no release path installs opencode-usage beside process.execPath: packages/opencode/script/build.ts clears dist, creates only bin/opencode, and archives that directory, while the shell installer moves only opencode into INSTALL_DIR and the npm postinstall likewise copies only the binary. Consequently official archive, install-script, and npm builds still fall through to the same missing PATH command unless users manually install an undocumented sidecar; add the helper to the produced packages/install flows along with this lookup.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant