All files / renderer/types ipc-client.ts

0% Statements 0/0
0% Branches 1/1
0% Functions 1/1
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                                                                                                   
import type { SessionState, TimelineLine, AgentState } from "../../shared/types";
 
// Mirrors `SessionPatch` from `src/main/session-store.ts`. Redeclared here because
// the renderer tsconfig (`tsconfig.web.json`) does not include `src/main`, and we
// want the renderer to depend only on a stable IPC contract, not on main-process
// internals.
export interface SessionPatch {
  sessionId: string;
  changes: Array<
    | { kind: "session-upsert"; session: Omit<SessionState, "agents" | "timeline"> }
    | { kind: "agent-upsert"; agent: AgentState }
    | { kind: "agent-remove"; agentId: string }
    | { kind: "timeline-append"; line: TimelineLine }
  >;
}
 
// Wire representation of a session across IPC: `agents` and `timeline` are
// serialized as arrays (Map is not structured-clonable across contextBridge).
export type SessionWire = Omit<SessionState, "agents" | "timeline"> & {
  agents: AgentState[];
  timeline: TimelineLine[];
};
 
export interface HookReadOk {
  ok: true;
  settingsPath: string;
  currentText: string;
  currentParsed: unknown;
  mergedText: string;
  diffText: string;
  isInstalled: boolean;
}
 
export interface HookMutationOk {
  ok: true;
  settingsPath: string;
  previousText: string;
  nextText: string;
  changed: boolean;
}
 
export interface HookErr {
  ok: false;
  error: string;
}
 
export type HookReadResponse = HookReadOk | HookErr;
export type HookMutationResponse = HookMutationOk | HookErr;
 
export interface UserSettingsReadOk {
  ok: true;
  idleBeforeGhostMinutes: number;
}
 
export interface UserSettingsWriteOk {
  ok: true;
  changed: boolean;
  next: { idleBeforeGhostMinutes: number };
}
 
export interface UserSettingsErr {
  ok: false;
  error: string;
}
 
export type UserSettingsReadResponse = UserSettingsReadOk | UserSettingsErr;
export type UserSettingsWriteResponse = UserSettingsWriteOk | UserSettingsErr;
 
export interface ClaudeVillageAPI {
  listSessions: () => Promise<SessionWire[]>;
  getSession: (id: string) => Promise<SessionWire | null>;
  pinSession: (id: string) => Promise<void>;
  unpinSession: (id: string) => Promise<void>;
  onPatch: (cb: (p: SessionPatch) => void) => () => void;
  onMenuAbout: (cb: () => void) => () => void;
  readHooks: () => Promise<HookReadResponse>;
  installHooks: () => Promise<HookMutationResponse>;
  uninstallHooks: () => Promise<HookMutationResponse>;
  readUserSettings: () => Promise<UserSettingsReadResponse>;
  writeUserSettings: (payload: {
    idleBeforeGhostMinutes: number;
  }) => Promise<UserSettingsWriteResponse>;
}
 
declare global {
  interface Window {
    claudeVillage: ClaudeVillageAPI;
  }
}