-
Notifications
You must be signed in to change notification settings - Fork 0
fix: wire HTTP polling fallback for brain TUI status #170 #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,10 @@ import { useServiceBus } from "@four-bytes/opencode-plugin-lib/tui"; | |
| import { ProgressBar } from "@four-bytes/opencode-plugin-lib/tui-components"; | ||
| import type { BrainStatusEvent } from "./event-bus"; | ||
| import { Spinner } from "./spinner"; | ||
| import { readFileSync, existsSync } from "fs"; | ||
| import { join } from "path"; | ||
| import { homedir } from "os"; | ||
| import { createHash } from "crypto"; | ||
|
|
||
| /** | ||
| * Derives a stable project ID from a directory path. | ||
|
|
@@ -73,12 +77,34 @@ function BrainStatusBar(props: { variant: "sidebar" | "home"; api: TuiPluginApi; | |
| setHasError(true); | ||
| } | ||
|
|
||
| }; | ||
| }; | ||
|
|
||
| // Discover the server's HTTP status port from the cache file | ||
| const discoverPollEndpoint = (): string | undefined => { | ||
| try { | ||
| const scopes = [props.sessionId, props.api.state.path.directory].filter(Boolean) as string[]; | ||
| for (const scope of scopes) { | ||
| const hash = createHash("sha256").update(scope).digest("hex").slice(0, 12); | ||
| const portFile = join(homedir(), ".cache", "opencode", "brain", `status-port-${hash}.json`); | ||
| if (existsSync(portFile)) { | ||
| const data = JSON.parse(readFileSync(portFile, "utf-8")); | ||
| if (data.port) return `http://127.0.0.1:${data.port}`; | ||
| } | ||
| } | ||
| } catch { /* port file not found or not ready yet */ } | ||
| return undefined; | ||
| }; | ||
|
|
||
| const pollEndpoint = discoverPollEndpoint(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
|
|
||
| // Reactive bus subscription — project-scoped (brain status is project-wide, not session-scoped). | ||
| useServiceBus("brain", () => deriveProjectId(props.api.state.path.directory), "status", (payload) => { | ||
| handleStatus(payload as BrainStatusEvent); | ||
| }); | ||
| useServiceBus( | ||
| "brain", | ||
| () => deriveProjectId(props.api.state.path.directory), | ||
| "status", | ||
| (payload) => { handleStatus(payload as BrainStatusEvent); }, | ||
| pollEndpoint ? { pollEndpoint } : undefined, | ||
| ); | ||
|
|
||
| const indicatorColor = () => connecting() ? theme().error : (hasError() ? theme().error : fg()); | ||
| const textColor = () => connecting() ? theme().error : theme().textMuted; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the fixed polling endpoint instead of cache-file port discovery.
This adds
~/.cache/.../status-port-*.jsondiscovery and makes polling conditional on a one-time cache hit. That conflicts with the fixed port contract and can still leave the TUI without HTTP polling when the file is missing or stale at mount. Prefer wiring the fixed localhost endpoint; if the status server is not already bound to 4099, update that side in the same stack.Proposed fix
As per coding guidelines,
Set fixed bus port to 4099 (no port discovery or port.json configuration).Also applies to: 82-107
Prompt for AI Agents
Source: Coding guidelines