confer-cli 0.8.13

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
<script lang="ts">
  // Piece 6 (ui/REDESIGN.md, "the composable card system") — the enriched
  // note/thread popover: a note's body + a keyboard-selectable Related
  // column composed from the SAME mini cards piece 5 already built
  // (TicketMiniCard, portable by design) plus two new ones this piece adds
  // (CodeRefMini, a thread pill). Per the doc's own framing: "the f reader
  // stays pure reading; this is the inspect view" — the FULL body renders
  // here (unlike TicketFullPopover's deliberate 2-line-teaser restraint —
  // that one is a launchpad OFF a ticket; this one IS the note's own
  // content), but no thread graph/lifecycle chrome — those stay MetaThread's
  // and FocusReader's own jobs, one click away via the footer/thread pill.
  //
  // Same overlay convention as FocusReader/TicketFullPopover
  // (`.fr-overlay`'s precedent) — reuses the SAME `thread`/
  // `appState.selectedMessage` state those two already populate (the
  // trigger calls `selectMessage` first, exactly like `openInFocusReader`
  // does), so opening this never means a second fetch for data already on
  // hand.
  import type { Agent, CodeRef, Message, RefHit, RequestRow, ThreadNode } from '../types';
  import { api } from '../api';
  import { renderMarkdown, highlightRenderedCodeBlocks } from '../markdown';
  import { formatClock } from '../format';
  import { buildTrail } from '../thread';
  import { relatedRefs, relatedTickets, threadSummary } from '../noteRelated';
  import { isTypingTarget } from '../keys';
  import TicketMiniCard from './TicketMiniCard.svelte';
  import CodeRefMini from './CodeRefMini.svelte';
  import CopyIdButton from './CopyIdButton.svelte';

  interface Props {
    open: boolean;
    msgId: string | null;
    messages: Message[];
    agents: Agent[];
    requests: RequestRow[];
    thread: ThreadNode[];
    hub: string;
    /** True while the focus reader is ALSO open — auto-closes this popover,
     * same "launchpad, don't stack" rule TicketFullPopover follows. */
    focusReaderOpen?: boolean;
    /** Piece 10 Phase A (overlayStack.svelte.ts) — true when this popover is
     * nested on top of another overlay. Shows the same "‹ back" affordance
     * TicketFullPopover's own `hasParent` does — see its doc comment. */
    hasParent?: boolean;
    onOpenTicket?: (id: string) => void;
    onOpenRefs?: (ref: CodeRef, hits: RefHit[]) => void;
    onOpenThread?: (msgId: string, topic: string | null) => void;
    onClose?: () => void;
  }

  let { open, msgId, messages, agents, requests, thread, hub, focusReaderOpen = false, hasParent = false, onOpenTicket, onOpenRefs, onOpenThread, onClose }: Props = $props();

  const agentsById = $derived(new Map(agents.map((a) => [a.id, a])));
  const message = $derived(msgId ? (messages.find((m) => m.id === msgId) ?? null) : null);
  const showing = $derived(open && message !== null);
  const agent = $derived(message ? agentsById.get(message.from) : undefined);

  const trail = $derived(buildTrail(thread, messages));
  const tickets = $derived(requests.length && trail.length ? relatedTickets(trail, requests) : []);
  const refs = $derived(relatedRefs(trail));
  const summary = $derived(threadSummary(trail));

  const renderedBody = $derived(message ? renderMarkdown(message.body) : null);
  let bodyEl: HTMLElement | undefined = $state();
  $effect(() => {
    void renderedBody;
    if (bodyEl) void highlightRenderedCodeBlocks(bodyEl);
  });

  function display(agentId: string): string {
    const a = agentsById.get(agentId);
    if (a) return a.display;
    return agentId.length ? agentId[0]!.toUpperCase() + agentId.slice(1) : agentId;
  }

  // The Related column as ONE flat, keyboard-selectable list — tickets,
  // then code, then the thread pill last — matching the mockup's own
  // top-to-bottom reading order (rel-grp tickets → code → thread).
  type RelatedItem = { kind: 'ticket'; key: string; row: RequestRow } | { kind: 'ref'; key: string; ref: CodeRef } | { kind: 'thread'; key: string };
  const relatedItems = $derived.by((): RelatedItem[] => [
    ...tickets.map((row): RelatedItem => ({ kind: 'ticket', key: `t:${row.id}`, row })),
    ...refs.map((ref): RelatedItem => ({ kind: 'ref', key: `r:${ref.repo}:${ref.path}:${ref.sha}`, ref })),
    ...(summary.messageCount > 1 ? [{ kind: 'thread' as const, key: 'thread' }] : []),
  ]);

  let selectedIdx = $state(0);
  $effect(() => {
    if (selectedIdx >= relatedItems.length) selectedIdx = Math.max(0, relatedItems.length - 1);
  });

  function activate(item: RelatedItem) {
    if (item.kind === 'ticket') onOpenTicket?.(item.row.id);
    else if (item.kind === 'ref') void openRef(item.ref);
    else if (message) onOpenThread?.(message.id, message.topic);
  }

  async function openRef(ref: CodeRef) {
    // CodeRefMini already fetches + calls onOpenRefs on its own click; a
    // keyboard Enter on the SAME item does the identical thing here so
    // both input paths land on the same real reverse-index data, not two
    // slightly-different code paths.
    const target = `${ref.repo}:${ref.path}${ref.range ? `@${ref.range[0]}-${ref.range[1]}` : ''}`;
    try {
      const hits = await api.getRefs(hub, target, true);
      onOpenRefs?.(ref, hits);
    } catch (err) {
      console.error('confer serve: failed to load reverse-index hits', target, err);
    }
  }

  $effect(() => {
    if (focusReaderOpen) onClose?.();
  });

  function handleRelatedKeydown(e: KeyboardEvent) {
    if (relatedItems.length === 0) return;
    if (e.key === 'j' || e.key === 'ArrowDown') {
      e.preventDefault();
      selectedIdx = Math.min(selectedIdx + 1, relatedItems.length - 1);
      return;
    }
    if (e.key === 'k' || e.key === 'ArrowUp') {
      e.preventDefault();
      selectedIdx = Math.max(selectedIdx - 1, 0);
      return;
    }
    if (e.key === 'Enter') {
      e.preventDefault();
      const item = relatedItems[selectedIdx];
      if (item) activate(item);
    }
  }

  function handleKeydown(e: KeyboardEvent) {
    if (!showing) return;
    if (isTypingTarget(e.target)) return;
    if (e.key === 'Escape') {
      e.preventDefault();
      // Piece 10 Phase A — see TicketFullPopover's own identical comment:
      // `onClose` pops the stack, which can synchronously reveal a parent
      // frame whose OWN always-attached Escape listener would otherwise
      // process this SAME keydown too.
      e.stopImmediatePropagation();
      onClose?.();
    }
  }
</script>

<svelte:window onkeydown={handleKeydown} />

{#if showing && message}
  <div class="np-overlay">
    <div class="np-backdrop" onclick={onClose} aria-hidden="true" data-testid="note-popover-backdrop"></div>
    <div class="np-panel" role="dialog" aria-modal="true" aria-label="Note detail" tabindex="-1" data-testid="note-popover">
      <div class="np-head">
        <span class="np-kind">{message.type}</span>
        <span class="np-from" style="color:{agent?.color ?? 'var(--muted)'}">{display(message.from)}</span>
        <span class="np-meta mono">{message.host ?? '—'} · {formatClock(message.ts)} · #{message.topic ?? '—'}</span>
        <CopyIdButton id={message.id} class="np-copy-id" />
        {#if hasParent}
          <button type="button" class="np-back" aria-label="Back" title="Back to where you opened this from" onclick={onClose}>‹ back</button>
        {/if}
        <button type="button" class="np-close" aria-label="Close note" onclick={onClose}>esc ✕</button>
      </div>

      <div class="np-grid">
        <div class="np-body">
          <h3 class="np-title">{message.summary}</h3>
          <article class="prose md" bind:this={bodyEl}>
            {#if renderedBody}
              {@html renderedBody}
            {/if}
          </article>
        </div>

        <div
          class="np-related"
          role="listbox"
          aria-label="related tickets, code, and thread"
          tabindex="-1"
          onkeydown={handleRelatedKeydown}
          data-testid="note-related"
        >
          {#if tickets.length}
            <div class="rel-grp">
              <div class="rel-lab">tickets <span class="c mono">{tickets.length}</span></div>
              {#each tickets as row (row.id)}
                {@const idx = relatedItems.findIndex((i) => i.kind === 'ticket' && i.row.id === row.id)}
                <TicketMiniCard request={row} {agents} selected={idx === selectedIdx} onSelect={() => onOpenTicket?.(row.id)} />
              {/each}
            </div>
          {/if}

          {#if refs.length}
            <div class="rel-grp">
              <div class="rel-lab">code <span class="c mono">{refs.length}</span></div>
              {#each refs as ref (ref.repo + ':' + ref.path + '@' + ref.sha)}
                {@const idx = relatedItems.findIndex((i) => i.kind === 'ref' && i.ref === ref)}
                <CodeRefMini {ref} {hub} selected={idx === selectedIdx} {onOpenRefs} />
              {/each}
            </div>
          {/if}

          {#if summary.messageCount > 1}
            <div class="rel-grp">
              <div class="rel-lab">thread</div>
              <button
                type="button"
                class="thr-mini"
                class:sel={relatedItems[selectedIdx]?.kind === 'thread'}
                onclick={() => message && onOpenThread?.(message.id, message.topic)}
                data-testid="note-thread-pill"
              >
                <span class="g" aria-hidden="true">⋔</span>
                {summary.messageCount} msgs · {summary.topicCount} topic{summary.topicCount === 1 ? '' : 's'}
                <span class="go">open ›</span>
              </button>
            </div>
          {/if}

          {#if relatedItems.length === 0}
            <p class="rel-empty">nothing else connects to this note yet</p>
          {/if}

          {#if relatedItems.length}
            <div class="rel-foot mono">
              <span class="kk">↑</span><span class="kk">↓</span> select
              <span class="kk">↵</span> open
            </div>
          {/if}
        </div>
      </div>
    </div>
  </div>
{/if}

<style>
  .np-overlay {
    position: fixed;
    inset: 0;
    z-index: 61;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--phi2, 24px);
  }
  .np-backdrop {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    backdrop-filter: blur(2px);
  }
  .np-panel {
    position: relative;
    width: min(760px, 100%);
    max-height: 88vh;
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
  }
  .np-head {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    background: var(--panel-2);
  }
  .np-kind {
    font: 700 9.5px/1 var(--mono);
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--muted);
    border: 1px solid var(--border-2);
    border-radius: 4px;
    padding: 2px 6px;
  }
  .np-from {
    font-weight: 640;
    font-size: 13px;
  }
  .np-meta {
    font-size: 11px;
    color: var(--faint);
  }
  .np-close {
    margin-left: auto;
    font: 500 11px/1 var(--mono);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 3px 7px;
    background: transparent;
    cursor: pointer;
  }
  .np-close:hover {
    color: var(--text);
    border-color: var(--faint);
  }
  /* Piece 10 Phase A — same "‹ back" affordance TicketFullPopover's own
     `.tk-back` adds, shown only when nested. See its CSS comment for the
     margin-left handoff between the two right-aligned controls. */
  .np-back {
    margin-left: auto;
    font: 500 11px/1 var(--mono);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 3px 8px;
    background: transparent;
    cursor: pointer;
  }
  .np-back:hover {
    color: var(--text);
    border-color: var(--accent);
  }
  .np-back + .np-close {
    margin-left: 0;
  }
  .np-head :global(.np-copy-id) {
    opacity: 1;
  }

  .np-grid {
    display: grid;
    grid-template-columns: 1fr 268px;
    min-height: 0;
    overflow: hidden;
  }
  .np-body {
    padding: 18px 20px;
    overflow-y: auto;
    border-right: 1px solid var(--border);
  }
  .np-title {
    font-size: 15px;
    font-weight: 640;
    line-height: 1.4;
    margin: 0 0 12px;
    color: var(--text);
  }

  .np-related {
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: color-mix(in srgb, var(--panel-2) 55%, var(--panel));
  }
  .rel-grp {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .rel-lab {
    font: 700 9.5px/1 var(--mono);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
  }
  .rel-lab .c {
    color: var(--faint);
    text-transform: none;
    letter-spacing: normal;
  }
  .rel-empty {
    margin: 0;
    font-size: 11.5px;
    color: var(--faint);
    font-style: italic;
  }

  .thr-mini {
    display: flex;
    align-items: center;
    gap: 7px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 9px;
    cursor: pointer;
    font-size: 12px;
    color: var(--muted);
    text-align: left;
    font-family: inherit;
    width: 100%;
  }
  .thr-mini:hover,
  .thr-mini.sel {
    border-color: var(--accent);
  }
  .thr-mini .g {
    color: var(--faint);
    font-family: var(--mono);
  }
  .thr-mini .go {
    margin-left: auto;
    font: 500 10px/1 var(--mono);
    color: var(--faint);
  }

  .rel-foot {
    margin-top: auto;
    padding-top: 6px;
    border-top: 1px solid var(--border-2);
    font-size: 9.5px;
    color: var(--faint);
    display: flex;
    gap: 5px;
    align-items: center;
  }
  .rel-foot .kk {
    color: var(--muted);
    border: 1px solid var(--border-2);
    border-radius: 3px;
    padding: 0 4px;
  }

  @media (max-width: 720px) {
    .np-grid {
      grid-template-columns: 1fr;
    }
    .np-body {
      border-right: none;
      border-bottom: 1px solid var(--border);
    }
  }
</style>