mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 23:49:41 +02:00
fix(review): WS state machine, per-tab supersede key, backoff, dot CSS (PR #149)
- _wsState now transitions through the full lifecycle: _connectWs() sets 'connecting', ws.onopen (inside the this._ws === ws guard) sets 'connected', _disconnectWs() resets to 'disconnected' — the connection chip's "WS" state was previously unreachable (stuck on "WS…"/"HTTP" forever). - WS registry supersede is now keyed per TAB: the upgrade URL sends cid = clientId + ':' + per-page nonce (reusing the constructor's page UUID), while input frames keep the bare browser clientId for seq dedup — two tabs/windows on one session coexist instead of 4010-evicting each other in a perpetual 5s ping-pong; a genuine same-tab reconnect still supersedes. - Exponential backoff engages: _disconnectWs() no longer zeroes _wsReconnectAttempts (it's called at the top of _connectWs, so every retry replanned at attempt 0 → ~0ms tight reconnect loop during outages); onopen resets the counter on success. - styles.css: add .connection-dot.connected (green) and .connection-dot.fallback (yellow) — both states rendered an invisible dot (no rule existed). - Remove smuggled dead code: resolveMonitorRowLabels/CodemanMonitorLabels (COD-122, no consumer, referenced test doesn't exist) and the never-written _wsLastClose/_wsInputSendCount/_httpFallbackSendCount diagnostics. - Tests: new test/ws-state-lifecycle.test.ts drives the REAL _connectWs/onopen/onclose/timer cycle (state transitions, escalating backoff delays, composite cid on the upgrade URL); registry two-tab coexistence test; static check that every emitted connection-dot class has a styles.css rule. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -126,38 +126,6 @@ function shouldAutoWrapTabs(input) {
|
||||
return scrollWidth > clientWidth + 1;
|
||||
}
|
||||
|
||||
// COD-122: Monitor "Tmux Sessions" row label policy. A row carries up to three
|
||||
// identifiers — the tab name (user-facing L1 label), the tmux session name
|
||||
// (e.g. "codeman-1fac7304"), and the agent (Claude/Codex) session id. The tab name
|
||||
// must win as the primary label; the other two are secondary metadata shown only
|
||||
// when known and not redundant with the primary, so the row degrades gracefully
|
||||
// when identifiers are missing.
|
||||
function resolveMonitorRowLabels(input) {
|
||||
const clean = (v) => (typeof v === 'string' ? v.trim() : '');
|
||||
const tabName = clean(input && input.tabName);
|
||||
const storedName = clean(input && input.storedName);
|
||||
const muxName = clean(input && input.muxName);
|
||||
const agentId = clean(input && input.agentSessionId);
|
||||
const sessionId = clean(input && input.sessionId);
|
||||
|
||||
// Tab name is the L1 label; fall back through the persisted mux name → tmux name
|
||||
// → a generic placeholder so the primary is never blank.
|
||||
const primary = tabName || storedName || muxName || 'session';
|
||||
|
||||
const secondaries = [];
|
||||
// tmux name — skip when it's already serving as the primary fallback (no dup).
|
||||
if (muxName && muxName !== primary) {
|
||||
secondaries.push({ kind: 'tmux', label: muxName });
|
||||
}
|
||||
// agent session id — show only when genuinely known: non-empty, not the codeman
|
||||
// sessionId placeholder (claudeSessionId is seeded with the session id until a
|
||||
// real agent message arrives), and not redundant with the primary label.
|
||||
if (agentId && agentId !== sessionId && agentId !== primary) {
|
||||
secondaries.push({ kind: 'agent', label: agentId });
|
||||
}
|
||||
return { primary, secondaries };
|
||||
}
|
||||
|
||||
// COD-134 — Terminal WebSocket reconnect policy.
|
||||
//
|
||||
// Decide what to do after a terminal WebSocket closes, given the close `code`
|
||||
@@ -188,9 +156,6 @@ if (typeof window !== 'undefined') {
|
||||
window.CodemanTabOverflow = {
|
||||
shouldAutoWrapTabs,
|
||||
};
|
||||
window.CodemanMonitorLabels = {
|
||||
resolveMonitorRowLabels,
|
||||
};
|
||||
window.CodemanWsReconnect = {
|
||||
plan: planWsReconnect,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user