-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ui): add CognitiveMeshPanel, SystemHealthBar, and cogmesh-poller #3
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { parseCogmeshConfig } from './parsers/retortconfig.js' | ||
| import type { CognitiveMeshHealth } from './protocol.js' | ||
|
|
||
| const HEALTH_INTERVAL_MS = 30_000 | ||
| const HEALTH_TIMEOUT_MS = 5_000 | ||
|
|
||
| /** | ||
| * Polls the cognitive-mesh `/health` endpoint on a 30s interval. | ||
| * Emits `unconfigured` when no endpoint is set in `.retortconfig`. | ||
| * | ||
| * Returns `reload()` (call when .retortconfig changes) and `stop()`. | ||
| */ | ||
| export function createCogmeshPoller( | ||
| root: string, | ||
| onHealth: (h: CognitiveMeshHealth) => void, | ||
| ): { reload: () => void; stop: () => void } { | ||
| let config = parseCogmeshConfig(root) | ||
| let timer: ReturnType<typeof setInterval> | null = null | ||
|
|
||
| async function checkHealth(): Promise<void> { | ||
| if (!config.endpoint) { | ||
| onHealth({ status: 'unconfigured' }) | ||
| return | ||
| } | ||
|
|
||
| const url = `${config.endpoint.replace(/\/$/, '')}/health` | ||
| const headers: Record<string, string> = {} | ||
| if (config.secret) headers['Authorization'] = `Bearer ${config.secret}` | ||
|
|
||
| const start = Date.now() | ||
| try { | ||
| const res = await fetch(url, { | ||
| headers, | ||
| signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS), | ||
| }) | ||
| const latencyMs = Date.now() - start | ||
| onHealth(res.ok | ||
| ? { status: 'connected', latencyMs } | ||
| : { status: 'degraded', latencyMs }, | ||
| ) | ||
| } catch { | ||
| onHealth({ status: 'unreachable' }) | ||
| } | ||
| } | ||
|
|
||
| function reload(): void { | ||
| config = parseCogmeshConfig(root) | ||
| void checkHealth() | ||
| } | ||
|
|
||
| function stop(): void { | ||
| if (timer) clearInterval(timer) | ||
| timer = null | ||
| } | ||
|
|
||
| // Start immediately, then on interval | ||
| void checkHealth() | ||
| timer = setInterval(() => { void checkHealth() }, HEALTH_INTERVAL_MS) | ||
|
|
||
| return { reload, stop } | ||
| } | ||
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
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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import * as fs from 'fs' | ||
| import * as path from 'path' | ||
|
|
||
| export interface CogmeshConfig { | ||
| endpoint: string | null | ||
| secret: string | null | ||
| } | ||
|
|
||
| /** | ||
| * Reads .retortconfig and extracts the `cogmesh:` block values. | ||
| * Substitutes ${VAR} references with process.env values. | ||
| */ | ||
| export function parseCogmeshConfig(root: string): CogmeshConfig { | ||
| const configPath = path.join(root, '.retortconfig') | ||
| let content: string | ||
| try { | ||
| content = fs.readFileSync(configPath, 'utf-8') | ||
| } catch { | ||
| return { endpoint: null, secret: null } | ||
| } | ||
|
|
||
| // Extract the indented block under `cogmesh:` | ||
| const blockMatch = /^cogmesh:\s*\n((?:[ \t]+[^\n]*\n?)*)/m.exec(content) | ||
| if (!blockMatch) return { endpoint: null, secret: null } | ||
| const block = blockMatch[1] | ||
|
|
||
| return { | ||
| endpoint: resolveEnv(extractScalar(block, 'endpoint')), | ||
| secret: resolveEnv(extractScalar(block, 'secret')), | ||
| } | ||
| } | ||
|
|
||
| function extractScalar(block: string, key: string): string | null { | ||
| const m = new RegExp(`^[ \\t]+${key}:\\s*["']?([^"'\\n]+?)["']?\\s*$`, 'm').exec(block) | ||
| return m?.[1]?.trim() ?? null | ||
| } | ||
|
|
||
| /** Replaces ${VAR} with process.env.VAR (leaves intact if not set). */ | ||
| function resolveEnv(value: string | null): string | null { | ||
| if (!value) return null | ||
| return value.replace(/\$\{([^}]+)\}/g, (_, name: string) => process.env[name] ?? `\${${name}}`) | ||
| } |
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { useStore } from '../bridge/useStore' | ||
| import type { CognitiveMeshHealth } from '../bridge/types' | ||
|
|
||
| interface ServiceIndicator { | ||
| label: string | ||
| status: 'ok' | 'warn' | 'error' | 'off' | ||
| detail?: string | ||
| } | ||
|
|
||
| function cogmeshIndicator(health: CognitiveMeshHealth | null): ServiceIndicator { | ||
| if (!health || health.status === 'unconfigured') { | ||
| return { label: 'CogMesh', status: 'off', detail: 'not configured' } | ||
| } | ||
| if (health.status === 'connected') { | ||
| return { label: 'CogMesh', status: 'ok', detail: `${health.latencyMs}ms` } | ||
| } | ||
| if (health.status === 'degraded') { | ||
| return { label: 'CogMesh', status: 'warn', detail: `degraded ${health.latencyMs}ms` } | ||
| } | ||
| return { label: 'CogMesh', status: 'error', detail: 'unreachable' } | ||
| } | ||
|
|
||
| function Pill({ indicator }: { indicator: ServiceIndicator }) { | ||
| return ( | ||
| <span | ||
| className={`health-pill health-pill--${indicator.status}`} | ||
| title={indicator.detail} | ||
| > | ||
| <span className="health-pill-dot" /> | ||
| {indicator.label} | ||
| {indicator.detail && <span className="health-pill-detail">{indicator.detail}</span>} | ||
| </span> | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Compact service-health row shown at the top of the Fleet panel. | ||
| * Hidden entirely when all services are unconfigured (avoids noise on fresh installs). | ||
| */ | ||
| export function SystemHealthBar() { | ||
| const cogmeshHealth = useStore((s) => s.cogmeshHealth) | ||
|
|
||
| const indicators: ServiceIndicator[] = [ | ||
| cogmeshIndicator(cogmeshHealth), | ||
| // Future: phoenix-flow, mcp-org, sluice, etc. | ||
| ] | ||
|
|
||
| // Don't render the bar if every service is 'off' — no value shown | ||
| if (indicators.every((i) => i.status === 'off')) return null | ||
|
|
||
| return ( | ||
| <div className="system-health-bar" role="status" aria-label="Service health"> | ||
| {indicators.map((ind) => ( | ||
| <Pill key={ind.label} indicator={ind} /> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } |
Oops, something went wrong.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: phoenixvc/retort-plugins
Length of output: 50
🏁 Script executed:
Repository: phoenixvc/retort-plugins
Length of output: 631
🏁 Script executed:
Repository: phoenixvc/retort-plugins
Length of output: 885
🏁 Script executed:
Repository: phoenixvc/retort-plugins
Length of output: 50
Add explicit
engines.nodefield to package.json to clarify minimum Node.js version.The code uses
AbortSignal.timeout()(requires Node.js ≥17.3) and globalfetch(requires Node.js ≥18). While the project's@types/nodedependency is pinned to^20.0.0, suggesting Node.js 20+, there is no explicitengines.nodefield in eitherpackages/state-watcher/package.jsonor the rootpackage.json. Add"engines": { "node": ">=18.0.0" }(or higher) to both package.json files to enforce this requirement and prevent accidental use with incompatible Node versions.🤖 Prompt for AI Agents