Files
learnharness/components/settings-signal.ts
T
amosblomqvist ffc4df1938 compaction: the surface — settings row, two ruled dividers, summary dialog, send gate (round 14 slice 3)
- settings: compaction.thresholdTokens row on the Agent tab (owner pick)
  in a Context group — CommitInput mirroring the graph budget row, hint
  resolved through the SAME core resolver the trigger reads; PUT rejects
  below the 32k floor with the anti-churn rationale; own section
  (compaction) in SETTINGS_SECTIONS + the settings-signal union
- view fold: one marker → two dividers — the minimal MOMENT divider at
  the marker (retrying-message register, no rule lines) and the longer
  CUT divider emitted immediately before the first kept message
  (phase-divider geometry, chip carries '· Nk tok'); both carry the full
  summary payload; full history stays visible to the user
- components/compaction-divider.tsx: the dividers + summary dialog
  (pure exported body for SSR pins, the delete-dialog pattern; Esc +
  Close dismiss, backdrop does not)
- chat.tsx: compaction-changed SSE flips the running state — composer
  canSend, onSend/doSend/doSteerOrSend, and both docks' submit + hint
  ('compacting session…') gate on it (the server's registry mutex is the
  structural gate; this is the affordance); dialog mounts beside the
  abort dialog
- pins: settings-body (4), view fold (2), divider SSR (4)
2026-10-05 22:51:08 +03:00

50 lines
2.3 KiB
TypeScript

"use client";
/**
* THE cross-surface settings signal (fix wave, owner ruling 2026-09-22):
* every WRITER dispatches after a successful PUT, every READER re-reads —
* the composer reflects the strong slot the instant setup saves, the
* settings section reflects the composer's pick on its next mount... and
* so on, by construction. CustomEvent on the window, the lh:chat-renamed
* pattern: writers and readers live in different component subtrees
* (portaled dialogs included), and the app already speaks this dialect.
*
* The event carries the section name so ONE event serves all sections —
* readers filter on what they actually read.
*/
import { useEffect, useRef } from "react";
export const SETTINGS_SAVED_EVENT = "lh:settings-saved";
/** The settings sections a writer can land (the write seam's union). */
// "keys" joined the roster (zero-keys wave, 2026-09-25): keys-section
// dispatches it after save AND delete — deletions used to be invisible to
// the zero-keys pill and the setup dialog's auto-advance.
export type SettingsSection = "general" | "keys" | "agent" | "models" | "appearance" | "graph" | "compaction";
/** Writers call this after the PUT resolves ok — never before (a failed
* write notifies nothing; the record is unchanged). */
export function notifySettingsSaved(section: SettingsSection): void {
window.dispatchEvent(
new CustomEvent(SETTINGS_SAVED_EVENT, { detail: { section } }),
);
}
/** Non-hook listener (imperative seams, tests). Returns an unsubscribe. */
export function onSettingsSaved(handler: (section: SettingsSection) => void): () => void {
const listener = (e: Event) => {
const section = (e as CustomEvent<{ section?: SettingsSection }>).detail?.section;
if (section !== undefined) handler(section);
};
window.addEventListener(SETTINGS_SAVED_EVENT, listener);
return () => window.removeEventListener(SETTINGS_SAVED_EVENT, listener);
}
/** Reader subscription: re-invokes whenever a writer lands, with the
* handler captured through a ref so callers never churn the
* subscription (and never stale-close over it either). */
export function useSettingsSaved(handler: (section: SettingsSection) => void): void {
const saved = useRef(handler);
saved.current = handler;
useEffect(() => onSettingsSaved((section) => saved.current(section)), []);
}