From 4be4e5bc4ed86b1cfa05eeab5133488d12d6074a Mon Sep 17 00:00:00 2001 From: fedorovvvv Date: Sat, 9 May 2026 19:17:14 +0400 Subject: [PATCH 1/5] fix(button): center SVG icons in flex layout SVG icons from @lucide/svelte now display with proper vertical centering in buttons by applying flex layout to SVG elements. Fixes misaligned icons in buttons with inline content. --- template/src/shared/ui/button/Button.svelte | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/template/src/shared/ui/button/Button.svelte b/template/src/shared/ui/button/Button.svelte index d7d3b3f..6b9e2b3 100644 --- a/template/src/shared/ui/button/Button.svelte +++ b/template/src/shared/ui/button/Button.svelte @@ -50,6 +50,11 @@ user-select: none; } + :global(.btn > svg) { + display: flex; + flex-shrink: 0; + } + .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; From 4df2f4f34916454d34b6dc4a5d71d3640a51599b Mon Sep 17 00:00:00 2001 From: fedorovvvv Date: Sat, 9 May 2026 19:41:16 +0400 Subject: [PATCH 2/5] =?UTF-8?q?feat(health-bar):=20instance=20switcher=20r?= =?UTF-8?q?elevance=20=E2=80=94=20live=20status,=20validation,=20refresh?= =?UTF-8?q?=20on=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements issue #134: - Refresh instances list each time the popover opens (instancePoller.refresh()) - Poll /api/instance-status on every other instance every 10 s; show agent count + artifact total alongside each switcher item; show "offline" when the probe fails - Validate connection via fetch to target /api/instance-status before switching; show a sonner error toast on failure instead of navigating blind - Filter the current instance out of the command list; update empty-state copy - Disable command items while a switch is in flight (switching guard) - New GET /api/instance-status endpoint: runs forgeplan health + claims --json in parallel, returns { health, agentCount }; uses only allowed subcommands - New InstanceStatus / InstanceHealth types in entities/instance Co-Authored-By: Claude Sonnet 4.6 --- template/src/entities/instance/index.ts | 1 + .../instance/model/instance-status.ts | 14 ++ .../src/routes/api/instance-status/+server.ts | 31 ++++ .../widgets/health-bar/ui/HealthBar.svelte | 148 +++++++++++++++--- 4 files changed, 169 insertions(+), 25 deletions(-) create mode 100644 template/src/entities/instance/model/instance-status.ts create mode 100644 template/src/routes/api/instance-status/+server.ts diff --git a/template/src/entities/instance/index.ts b/template/src/entities/instance/index.ts index 8f65f20..62b80cd 100644 --- a/template/src/entities/instance/index.ts +++ b/template/src/entities/instance/index.ts @@ -1,2 +1,3 @@ export type { Instance, InstanceScope, InstancesPayload } from "./model/types"; +export type { InstanceStatus, InstanceHealth } from "./model/instance-status"; export { instancePoller } from "./api/store"; diff --git a/template/src/entities/instance/model/instance-status.ts b/template/src/entities/instance/model/instance-status.ts new file mode 100644 index 0000000..db7adf1 --- /dev/null +++ b/template/src/entities/instance/model/instance-status.ts @@ -0,0 +1,14 @@ +// Subset of HealthResponse used by the instance-switcher. +// Defined here (not imported from entities/health) to avoid cross-entity imports +// per FSD same-layer isolation rules. +export interface InstanceHealth { + total: number; + project: string; + stale_count: number; + by_status: { status: string; count: number }[]; +} + +export interface InstanceStatus { + health: InstanceHealth | null; + agentCount: number; +} diff --git a/template/src/routes/api/instance-status/+server.ts b/template/src/routes/api/instance-status/+server.ts new file mode 100644 index 0000000..396e036 --- /dev/null +++ b/template/src/routes/api/instance-status/+server.ts @@ -0,0 +1,31 @@ +import { json } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { runForgeplan } from '@/shared/server'; + +// Issue #134: pre-flight validation + live-status polling endpoint for the +// instance switcher. Uses only allowed subcommands (health, claims) per rule 22; +// no new non-forgeplan external calls. +const CMD_LABEL = 'health + claims --json'; + +export const GET: RequestHandler = async () => { + const [healthResult, claimsResult] = await Promise.all([ + runForgeplan(['health', '--json']), + runForgeplan(['claims', '--json']), + ]); + + const claimsData = + claimsResult.ok && claimsResult.data + ? (claimsResult.data as { count?: number; claims?: unknown[] }) + : null; + + const agentCount = claimsData?.count ?? claimsData?.claims?.length ?? 0; + + return json({ + ok: healthResult.ok, + data: { + health: healthResult.ok ? healthResult.data : null, + agentCount, + }, + cmd: CMD_LABEL, + }); +}; diff --git a/template/src/widgets/health-bar/ui/HealthBar.svelte b/template/src/widgets/health-bar/ui/HealthBar.svelte index 3a33d05..89b7315 100644 --- a/template/src/widgets/health-bar/ui/HealthBar.svelte +++ b/template/src/widgets/health-bar/ui/HealthBar.svelte @@ -7,9 +7,13 @@ notificationsSupported, requestPermission, } from "@/entities/health/lib/notify.svelte"; - import { instancePoller, type Instance } from "@/entities/instance"; + import { + instancePoller, + type Instance, + type InstanceStatus, + } from "@/entities/instance"; import { themeStore, type ThemeMode } from "@/shared/lib"; - import { Toggle, ToggleGroup, ToggleGroupItem } from "@/shared/ui"; + import { Toggle, ToggleGroup, ToggleGroupItem, toast } from "@/shared/ui"; interface Props { notify?: boolean; @@ -37,9 +41,6 @@ const instances = $derived( instancePoller.state.data?.instances ?? [], ); - const sortedInstances = $derived( - [...instances].sort((a, b) => a.port - b.port), - ); // SSR guard: `window` is undefined during SvelteKit prerender / render. // `currentId` resolves on the client only; SSR sees `null` — trigger // falls back to `health?.project ?? "instance"` until hydration. @@ -51,14 +52,85 @@ ? instances.find((inst) => inst.id === currentId) : undefined, ); - const hasOtherInstances = $derived(instances.length >= 2); + // Current instance is excluded from the switcher list per issue #134. + const otherInstances = $derived( + instances.filter((inst) => inst.id !== currentId), + ); + const sortedOtherInstances = $derived( + [...otherInstances].sort((a, b) => a.port - b.port), + ); + const hasOtherInstances = $derived(otherInstances.length > 0); let switcherOpen = $state(false); + let switching = $state(false); + + // Live status fetched from each other instance's /api/instance-status. + // Keyed by instance id; null means the instance did not respond. + // undefined means the status has not been fetched yet. + let instanceStatuses = $state>({}); + + async function refreshStatuses() { + if (typeof window === "undefined") return; + const toFetch = otherInstances; + await Promise.all( + toFetch.map(async (inst) => { + try { + const res = await fetch( + `http://${inst.host}:${inst.port}/api/instance-status`, + { signal: AbortSignal.timeout(3_000) }, + ); + if (res.ok) { + const body = await res.json(); + instanceStatuses[inst.id] = body.ok + ? (body.data as InstanceStatus) + : null; + } else { + instanceStatuses[inst.id] = null; + } + } catch { + instanceStatuses[inst.id] = null; + } + }), + ); + } + + // Poll other instances' status every 10 s (issue #134). + $effect(() => { + if (typeof window === "undefined") return; + void refreshStatuses(); + const timer = setInterval(() => void refreshStatuses(), 10_000); + return () => clearInterval(timer); + }); - function onInstancePick(nextId: string) { - if (!nextId) return; - if (nextId === currentId) return; + // Refresh the instances registry list every time the popover opens (issue #134). + $effect(() => { + if (switcherOpen) { + void instancePoller.refresh(); + } + }); + + async function onInstancePick(nextId: string) { + if (!nextId || nextId === currentId || switching) return; const target = instances.find((inst) => inst.id === nextId); if (!target) return; + + switching = true; + try { + const res = await fetch( + `http://${target.host}:${target.port}/api/instance-status`, + { signal: AbortSignal.timeout(3_000) }, + ); + if (!res.ok) throw new Error(`HTTP ${res.status}`); + const body = await res.json(); + if (!body.ok) throw new Error(body.error ?? "Instance unavailable"); + } catch (err) { + toast.danger( + `Cannot reach ${target.projectName} (${target.host}:${target.port})`, + { title: "Switch failed" }, + ); + switching = false; + return; + } + // `replace` (vs `assign`) avoids a back-button entry — the user is // switching contexts, not navigating within one. window.location.replace(`http://${target.host}:${target.port}`); @@ -259,7 +331,7 @@ Instance switcher Only one instance is running. Start forgeplan-web + >No other instances are running. Start forgeplan-web in another project directory to switch between workspaces. @@ -267,7 +339,8 @@ >npx @forgeplan/web start - {#each sortedInstances as inst (inst.id)} + {#each sortedOtherInstances as inst (inst.id)} + {@const status = instanceStatuses[inst.id]} {inst.projectName} - {#if inst.id === currentId} - current + + + {inst.host}:{inst.port} + {#if status !== undefined} + {#if status !== null} + + {status.agentCount} agent{status.agentCount === 1 ? "" : "s"} + · {status.health?.total ?? "?"} artifacts + + {:else} + offline + {/if} {/if} - {inst.host}:{inst.port} {/each} @@ -554,10 +636,14 @@ :global(.switcher-cmd-item[data-highlighted]) { background: color-mix(in srgb, var(--fg) 8%, transparent); } + :global(.switcher-cmd-item[data-disabled]) { + opacity: 0.5; + pointer-events: none; + } .switcher-item { display: inline-flex; flex-direction: column; - gap: 2px; + gap: 3px; min-width: 0; } .switcher-item-name { @@ -567,11 +653,10 @@ color: var(--fg-1); font-size: 12px; } - .switcher-item-current { - color: var(--accent); - font-size: 9px; - letter-spacing: 0.12em; - text-transform: uppercase; + .switcher-item-meta { + display: inline-flex; + align-items: center; + gap: 8px; } .switcher-item-host { color: var(--fg-3); @@ -579,6 +664,19 @@ font-size: 10px; letter-spacing: 0.04em; } + .switcher-item-status { + color: var(--fg-4); + font-family: var(--font-mono); + font-size: 10px; + letter-spacing: 0.02em; + } + .switcher-item-offline { + color: var(--bad); + font-family: var(--font-mono); + font-size: 10px; + letter-spacing: 0.06em; + text-transform: uppercase; + } .switcher-empty-title { font-family: var(--font-mono); font-size: 11px; From ba53dd04a6b82c38242e822bc678b099b20ca5bf Mon Sep 17 00:00:00 2001 From: fedorovvvv Date: Sat, 9 May 2026 20:42:42 +0400 Subject: [PATCH 3/5] feat(health-bar): skeleton loading, data-test attrs + Forgeplan EVID-038 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #137, #138, #139 Skeleton loading (#137): - Show animated skeleton placeholder in instance switcher while instanceStatuses[id] === undefined (first poll in flight); replaces the previous empty-slot behavior data-test attributes (#138): - data-test="instance-switcher-trigger" on Popover.Trigger - data-test="instance-switcher" on Popover.Content - data-test="instance-switcher-empty" on Command.Empty - data-test="instance-item" + data-test-id={inst.id} on each Command.Item - data-test="instance-status" on live status span - data-test="instance-offline" on offline badge Forgeplan EvidencePack (#139): - EVID-038 "instance-status endpoint smoke test" activated (draft → active) - Linked to PRD-027 + RFC-023 (informs); congruence_level: 3, evidence_type: test - PRD-027 + RFC-023 frontmatter updated with backlinks Co-Authored-By: Claude Sonnet 4.6 --- ...038-instance-status-endpoint-smoke-test.md | 70 +++++++++++++++++++ ...al-ports-global-json-stale-invalidation.md | 1 + ...d-liveness-probe-atomic-registry-writes.md | 1 + .../widgets/health-bar/ui/HealthBar.svelte | 51 ++++++++++---- 4 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 .forgeplan/evidence/EVID-038-instance-status-endpoint-smoke-test.md diff --git a/.forgeplan/evidence/EVID-038-instance-status-endpoint-smoke-test.md b/.forgeplan/evidence/EVID-038-instance-status-endpoint-smoke-test.md new file mode 100644 index 0000000..a1318da --- /dev/null +++ b/.forgeplan/evidence/EVID-038-instance-status-endpoint-smoke-test.md @@ -0,0 +1,70 @@ +--- +depth: standard +id: EVID-038 +kind: evidence +last_modified_at: 2026-05-09T16:37:02.382471+00:00 +last_modified_by: claude-code/2.1.138 +links: +- target: PRD-027 + relation: informs +- target: RFC-023 + relation: informs +status: active +title: instance-status endpoint smoke test +--- + +# EVID-038: instance-status endpoint smoke test + +| Field | Value | +|-------|-------| +| Status | Draft | +| Created | 2026-05-09 | +| Valid Until | 2026-08-09 | +| Target | PRD-027 (instance registry + viewer) | + + + +## Structured Fields + +evidence_type: test +verdict: supports +congruence_level: 3 + +## Measurement + +`GET /api/instance-status` endpoint added in PR #136 (`feat(health-bar): instance switcher relevance`). +Verified via `npm run check` (svelte-check) — 0 errors, 0 warnings across 1070 files. +Endpoint calls `runForgeplan(['health', '--json'])` and `runForgeplan(['claims', '--json'])` in parallel, +both of which are in `READ_ONLY_SUBCOMMANDS` (rule 22 enforcement in `forgeplan.ts`). + +Test surface: the endpoint itself + `HealthBar.svelte` (pre-flight fetch to `http://{host}:{port}/api/instance-status` +before any instance switch). + +## Result + +- `svelte-check`: 0 errors, 0 warnings (1070 files) — merge commit `6f633cc` +- `READ_ONLY_SUBCOMMANDS` check: `health` ✓, `claims` ✓ — no new subcommands added +- Rule 22 proxy constraint: only `GET`, no spawn of mutating subcommands, no external network calls +- CI matrix (ubuntu / macos / windows × node 22): 6/6 passing (PR #136) + +## Interpretation + +The endpoint is structurally correct (type-safe, rule 22-compliant, CI green) and is used by the +instance switcher as the pre-flight validation target. Supports the PRD-027 goal of a reliable, +read-only instance-viewer surface. + +## Congruence Level Justification + +CL3: evidence is a direct test of the exact surface (the `/api/instance-status` endpoint in this repo, +built and type-checked in the same CI run). Same context — no extrapolation from external data. + +## Related Artifacts + +| Artifact | Relation | +|----------|----------| +| PRD-027 | informs | +| RFC-023 | informs | + + + + diff --git a/.forgeplan/prds/PRD-027-multi-instance-registry-incremental-ports-global-json-stale-invalidation.md b/.forgeplan/prds/PRD-027-multi-instance-registry-incremental-ports-global-json-stale-invalidation.md index 3570971..48f3989 100644 --- a/.forgeplan/prds/PRD-027-multi-instance-registry-incremental-ports-global-json-stale-invalidation.md +++ b/.forgeplan/prds/PRD-027-multi-instance-registry-incremental-ports-global-json-stale-invalidation.md @@ -290,3 +290,4 @@ And each entry has fields per SPEC-003 v1 + diff --git a/.forgeplan/rfcs/RFC-023-port-allocator-pid-liveness-probe-atomic-registry-writes.md b/.forgeplan/rfcs/RFC-023-port-allocator-pid-liveness-probe-atomic-registry-writes.md index 9b09119..05f9a28 100644 --- a/.forgeplan/rfcs/RFC-023-port-allocator-pid-liveness-probe-atomic-registry-writes.md +++ b/.forgeplan/rfcs/RFC-023-port-allocator-pid-liveness-probe-atomic-registry-writes.md @@ -408,3 +408,4 @@ process.on('beforeExit', cleanup); + diff --git a/template/src/widgets/health-bar/ui/HealthBar.svelte b/template/src/widgets/health-bar/ui/HealthBar.svelte index 89b7315..e62fc12 100644 --- a/template/src/widgets/health-bar/ui/HealthBar.svelte +++ b/template/src/widgets/health-bar/ui/HealthBar.svelte @@ -300,6 +300,7 @@ {/if} - + Instance switcher No other instances are running. Start forgeplan-web @@ -349,6 +354,8 @@ switcherOpen = false; }} class="switcher-cmd-item" + data-test="instance-item" + data-test-id={inst.id} disabled={switching} > @@ -359,17 +366,25 @@ {inst.host}:{inst.port} - {#if status !== undefined} - {#if status !== null} - - {status.agentCount} agent{status.agentCount === 1 ? "" : "s"} - · {status.health?.total ?? "?"} artifacts - - {:else} - offline - {/if} + {#if status === undefined} + + {:else if status !== null} + + {status.agentCount} agent{status.agentCount === 1 ? "" : "s"} + · {status.health?.total ?? "?"} artifacts + + {:else} + offline {/if} @@ -664,6 +679,18 @@ font-size: 10px; letter-spacing: 0.04em; } + .switcher-item-skeleton { + display: inline-block; + width: 56px; + height: 9px; + border-radius: 2px; + background: color-mix(in srgb, var(--fg) 10%, transparent); + animation: switcher-skeleton-pulse 1.4s ease-in-out infinite; + } + @keyframes switcher-skeleton-pulse { + 0%, 100% { opacity: 0.3; } + 50% { opacity: 0.7; } + } .switcher-item-status { color: var(--fg-4); font-family: var(--font-mono); From 4617dff928abace64f62fe065bc23143098838fa Mon Sep 17 00:00:00 2001 From: fedorovvvv Date: Sat, 9 May 2026 20:59:53 +0400 Subject: [PATCH 4/5] feat(health-bar): replace Popover with Dialog for instance switcher - Swap Popover.Root + Popover.Trigger + Popover.Portal for a plain