confer-cli 0.8.6

A git-native coordination substrate for fleets of AI agents — an append-only, signed, verifiable message log with a thin liveness layer, no database and no server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<script lang="ts">
  // The trust-tiered hub rail (ui/redesign-mockups/02-hub-nav.html, piece 2:
  // "Hub navigation & scale"). Replaces the horizontal hub tab-row (still
  // kept as TopBar's mobile fallback — see TopBar.svelte) with a persistent,
  // vertical, grouped-by-REAL-tier rail: Home (own) / Shared / Foreign /
  // Unclassified (null tier — its own bucket, never folded into Home; see
  // tierGroup below). Renders ONLY hubs `/api/hubs` actually returned —
  // never an illustrative/fake hub (REDESIGN.md law #3).
  //
  // Owns its own cross-hub `getAttention()` poll (same fan-out + cadence
  // Overview.svelte uses) so the health dot is the SAME real signal the
  // fleet map computes, not an independently-invented weaker one. Also owns
  // the ⌘K command palette (same data, natural single home for it) and
  // reports the current hub's tier up to App.svelte for the workspace tint.
  //
  // Keyboard (first slice of REDESIGN.md's keyboard-first model): j/k move
  // the roving-tabindex selection, `g g`/`G` jump to the first/last hub,
  // `Enter`/`l` opens the selected entry, `⌘K`/`Ctrl+K` opens the palette
  // from anywhere on the page (not just while the rail has focus).
  import { onDestroy, onMount } from 'svelte';
  import { getAttention } from '../api';
  import type { HubDomain } from '../attention';
  import { hubHealthReason } from '../attention';
  import type { HubTier } from '../types';
  import type { View } from '../stores.svelte';
  import { isCommandK, LEADER_TIMEOUT_MS } from '../keys';
  import { paneFocus } from '../paneFocus.svelte';
  import CommandPalette from './CommandPalette.svelte';

  interface Props {
    currentHub: string;
    currentView: View;
    onHubChange?: (hubId: string) => void;
    /** The rail's "◆ All hubs" entry — switches to the cross-hub Overview
     * without changing `currentHub` (Overview doesn't have a single "current
     * hub" the way every other view does). */
    onAllHubs?: () => void;
    /** Fires whenever the resolved tier of `currentHub` changes (including
     * to `null`/unknown) — App.svelte's workspace tint reads this rather
     * than fetching its own copy of the same data. */
    onActiveTierChange?: (tier: HubTier | null) => void;
  }

  let { currentHub, currentView, onHubChange, onAllHubs, onActiveTierChange }: Props = $props();

  let loading = $state(true);
  let error = $state<string | null>(null);
  let domains = $state<HubDomain[]>([]);
  let paletteOpen = $state(false);

  const REFRESH_MS = 15000;
  let refreshTimer: ReturnType<typeof setInterval> | undefined;

  async function load() {
    try {
      const result = await getAttention();
      domains = result.domains;
      error = null;
    } catch (err) {
      console.error('confer serve: failed to load the hub rail', err);
      error = 'hubs unavailable';
    } finally {
      loading = false;
    }
  }

  onMount(() => {
    void load();
    refreshTimer = setInterval(() => void load(), REFRESH_MS);
  });
  onDestroy(() => {
    clearInterval(refreshTimer);
  });

  $effect(() => {
    const active = domains.find((d) => d.hub === currentHub) ?? null;
    onActiveTierChange?.(active?.tier ?? null);
  });

  // ── grouping — own/shared/foreign/null, in this fixed display order ──────
  const GROUP_ORDER: { tier: HubTier | null; tierClass: string; label: string }[] = [
    { tier: 'own', tierClass: 'home', label: 'Home' },
    { tier: 'shared', tierClass: 'shared', label: 'Shared' },
    { tier: 'foreign', tierClass: 'foreign', label: 'Foreign' },
    { tier: null, tierClass: 'neutral', label: 'Unclassified' },
  ];

  type RailEntry =
    | { kind: 'all' }
    | { kind: 'group'; tierClass: string; label: string; count: number }
    | { kind: 'hub'; domain: HubDomain; tierClass: string };

  const railEntries = $derived.by((): RailEntry[] => {
    const entries: RailEntry[] = [{ kind: 'all' }];
    for (const g of GROUP_ORDER) {
      const inGroup = domains.filter((d) => d.tier === g.tier);
      if (inGroup.length === 0) continue;
      entries.push({ kind: 'group', tierClass: g.tierClass, label: g.label, count: inGroup.length });
      for (const domain of inGroup) entries.push({ kind: 'hub', domain, tierClass: g.tierClass });
    }
    return entries;
  });

  function entryKey(entry: RailEntry): string {
    if (entry.kind === 'all') return 'all';
    if (entry.kind === 'group') return `group:${entry.tierClass}`;
    return `hub:${entry.domain.hub}`;
  }

  // ── roving-tabindex keyboard nav (j/k, g g, G, Enter/l) ───────────────────
  let buttonEls = $state<(HTMLButtonElement | null)[]>([]);
  let focusedIdx = $state(0);
  let gArmed = false;
  let gTimer: ReturnType<typeof setTimeout> | undefined;

  function isNavigable(i: number): boolean {
    return railEntries[i]?.kind !== 'group' && railEntries[i] !== undefined;
  }

  function moveFocus(delta: number) {
    let i = focusedIdx;
    do {
      i += delta;
    } while (i >= 0 && i < railEntries.length && !isNavigable(i));
    if (i < 0 || i >= railEntries.length) return;
    focusedIdx = i;
    buttonEls[i]?.focus();
  }

  function moveToFirst() {
    const i = railEntries.findIndex((_, idx) => isNavigable(idx));
    if (i >= 0) {
      focusedIdx = i;
      buttonEls[i]?.focus();
    }
  }

  function moveToLast() {
    for (let i = railEntries.length - 1; i >= 0; i--) {
      if (isNavigable(i)) {
        focusedIdx = i;
        buttonEls[i]?.focus();
        return;
      }
    }
  }

  function activateEntry(entry: RailEntry) {
    if (entry.kind === 'all') onAllHubs?.();
    else if (entry.kind === 'hub') onHubChange?.(entry.domain.hub);
  }

  function activateFocused() {
    const entry = railEntries[focusedIdx];
    if (entry) activateEntry(entry);
  }

  function handleNavKeydown(e: KeyboardEvent) {
    const key = e.key;
    if (key === 'j' || key === 'ArrowDown') {
      e.preventDefault();
      gArmed = false;
      moveFocus(1);
      return;
    }
    if (key === 'k' || key === 'ArrowUp') {
      e.preventDefault();
      gArmed = false;
      moveFocus(-1);
      return;
    }
    if (key === 'G') {
      e.preventDefault();
      gArmed = false;
      moveToLast();
      return;
    }
    if (key === 'g') {
      if (gArmed) {
        e.preventDefault();
        moveToFirst();
        gArmed = false;
        clearTimeout(gTimer);
      } else {
        gArmed = true;
        clearTimeout(gTimer);
        gTimer = setTimeout(() => {
          gArmed = false;
        }, LEADER_TIMEOUT_MS);
      }
      return;
    }
    if (key === 'Enter' || key === 'l') {
      e.preventDefault();
      gArmed = false;
      activateFocused();
      return;
    }
    // Any other key cancels a half-armed `g g` — matches vim: a stray key
    // between the two g's just isn't the motion.
    gArmed = false;
  }

  onDestroy(() => clearTimeout(gTimer));

  // ⌘K works from anywhere on the page, not just while the rail has focus —
  // the whole point of a command palette (REDESIGN.md's macOS-native entry
  // point). Deliberately checked BEFORE any typing-target guard: opening the
  // palette while, say, composing a chat note is exactly when you'd reach
  // for it.
  function handleGlobalKeydown(e: KeyboardEvent) {
    if (isCommandK(e)) {
      e.preventDefault();
      paletteOpen = true;
    }
  }

  // keyboard-architecture pass — registers "rail" as one of the 7 named
  // Layer-1 panes. `el` is `.hr-list` itself, which paneFocus.focus() calls
  // .focus() on directly — but piece 2's roving tabindex actually parks
  // real DOM focus on the individual entry BUTTON (buttonEls[focusedIdx]),
  // not the wrapping div, so Ctrl+hjkl landing on the div needs one extra
  // hop: forward straight to the current button, same as `l`/Enter or j/k
  // already do internally. Guarded by `e.target === hrListEl` so it only
  // fires on that direct hop-in, not on every bubbled child-focus event.
  let hrListEl: HTMLDivElement;
  function forwardContainerFocus(e: FocusEvent) {
    if (e.target === hrListEl) buttonEls[focusedIdx]?.focus();
  }
  $effect(() => {
    if (!hrListEl) return;
    return paneFocus.register({
      id: 'rail',
      label: 'Hubs',
      el: hrListEl,
      getRect: () => hrListEl.getBoundingClientRect(),
    });
  });
</script>

<svelte:window onkeydown={handleGlobalKeydown} />

<nav class="hr-rail" aria-label="hubs" data-testid="hub-rail">
  <button type="button" class="hr-jump" onclick={() => (paletteOpen = true)} data-testid="hub-rail-jump">
    <span>Jump to hub…</span>
    <span class="hr-kbd mono">⌘K</span>
  </button>

  <!-- role="toolbar", not "listbox": the WAI-ARIA pattern for exactly what's
       built here — a set of buttons with roving tabindex + arrow/vim-style
       keyboard navigation among them — without claiming selection-state
       semantics (aria-selected, role="option") this component doesn't
       implement. -->
  <div
    class="hr-list"
    role="toolbar"
    aria-orientation="vertical"
    aria-label="hubs"
    tabindex="-1"
    bind:this={hrListEl}
    onkeydown={handleNavKeydown}
    onfocus={forwardContainerFocus}
  >
    {#if loading && domains.length === 0}
      <div class="hr-status">loading hubs…</div>
    {:else if error && domains.length === 0}
      <div class="hr-status hr-status-err">{error}</div>
    {:else}
      {#each railEntries as entry, i (entryKey(entry))}
        {#if entry.kind === 'all'}
          <button
            type="button"
            class="hr-all"
            class:active={currentView === 'overview'}
            tabindex={i === focusedIdx ? 0 : -1}
            bind:this={buttonEls[i]}
            onfocus={() => (focusedIdx = i)}
            onclick={() => activateEntry(entry)}
            data-testid="hub-rail-all"
          >
            <span class="hr-di">◆</span>
            <span class="hr-allname">All hubs</span>
            <span class="hr-allmeta mono">fleet</span>
          </button>
        {:else if entry.kind === 'group'}
          <div class="hr-glab hr-glab-{entry.tierClass}">
            <span class="hr-gname">{entry.label}</span>
            <span class="hr-gcount mono">{entry.count}</span>
          </div>
        {:else}
          <button
            type="button"
            class="hr-hub hr-hub-{entry.tierClass}"
            class:active={entry.domain.hub === currentHub}
            tabindex={i === focusedIdx ? 0 : -1}
            bind:this={buttonEls[i]}
            onfocus={() => (focusedIdx = i)}
            onclick={() => activateEntry(entry)}
            title={hubHealthReason(entry.domain)}
            data-testid="hub-rail-hub"
          >
            <span class="hr-hname">{entry.domain.label}</span>
            <span class="hr-hbadge mono">{entry.domain.agents.length}</span>
            <span class="hr-hdot hr-hdot-{entry.domain.health}" aria-hidden="true"></span>
          </button>
        {/if}
      {/each}
    {/if}
  </div>
</nav>

<CommandPalette
  open={paletteOpen}
  {domains}
  onSelect={(hubId) => onHubChange?.(hubId)}
  onClose={() => (paletteOpen = false)}
/>

<style>
  .hr-rail {
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 10px 8px;
  }
  .hr-jump {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 2px 10px;
    padding: 7px 9px;
    border-radius: 8px;
    border: 1px solid var(--border-2);
    background: var(--bg);
    color: var(--muted);
    font-size: 12px;
    text-align: left;
  }
  .hr-jump:hover {
    color: var(--text);
    border-color: var(--faint);
  }
  .hr-jump:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .hr-kbd {
    margin-left: auto;
    font-size: 10px;
    border: 1px solid var(--border-2);
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--faint);
  }
  .hr-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .hr-status {
    padding: 10px 8px;
    font-size: 12px;
    color: var(--faint);
    font-style: italic;
  }
  .hr-status-err {
    color: var(--blocked);
  }

  .hr-all {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: 8px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
  }
  .hr-all:hover {
    background: var(--panel-2);
  }
  .hr-all.active {
    background: var(--panel-3);
    color: var(--text);
  }
  .hr-all:focus-visible,
  .hr-hub:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }
  .hr-di {
    color: var(--accent);
    font-family: var(--mono);
  }
  .hr-allmeta {
    margin-left: auto;
    font-size: 10px;
    color: var(--faint);
  }

  .hr-glab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 8px 5px;
  }
  .hr-gname {
    font: 700 10px/1 var(--mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
  .hr-gcount {
    font-size: 10px;
    color: var(--faint);
  }
  .hr-glab-home .hr-gname {
    color: var(--home-frame);
  }
  .hr-glab-shared .hr-gname {
    color: var(--shared-frame);
  }
  .hr-glab-foreign .hr-gname {
    color: var(--foreign-frame);
  }
  .hr-glab-neutral .hr-gname {
    color: var(--neutral-frame);
  }

  .hr-hub {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 12px;
    border-radius: 7px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    text-align: left;
  }
  .hr-hub::before {
    content: '';
    position: absolute;
    left: 0;
    top: 5px;
    bottom: 5px;
    width: 2.5px;
    border-radius: 2px;
    opacity: 0.55;
  }
  .hr-hub-home::before {
    background: var(--home-frame);
  }
  .hr-hub-shared::before {
    background: var(--shared-frame);
  }
  .hr-hub-foreign::before {
    background: repeating-linear-gradient(var(--foreign-frame) 0 3px, transparent 3px 5px);
    opacity: 0.85;
  }
  .hr-hub-neutral::before {
    background: var(--neutral-frame);
  }
  .hr-hub:hover {
    background: var(--panel-2);
  }
  .hr-hub.active {
    background: var(--panel-3);
    color: var(--text);
    font-weight: 640;
  }
  .hr-hub.active::before {
    opacity: 1;
    width: 3px;
  }
  .hr-hname {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .hr-hbadge {
    font-size: 10px;
    color: var(--faint);
    background: var(--bg);
    border: 1px solid var(--border-2);
    border-radius: 5px;
    padding: 1px 5px;
    flex: 0 0 auto;
  }
  .hr-hdot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex: 0 0 auto;
  }
  .hr-hdot-ok {
    background: var(--done);
  }
  .hr-hdot-warn {
    background: var(--blocked);
  }
  .hr-hdot-critical {
    background: var(--error);
  }
  .hr-hdot-unknown {
    background: var(--border-2);
  }

  @media (max-width: 1023.98px) {
    .hr-rail {
      display: none;
    }
  }
</style>