spb/khaelor Public
KHAELOR — a terminal-native autonomous engineering agent powered by Anthropic.
TypeScript 82.9%
HTML 14.9%
CSS 1.1%
JavaScript 0.7%
1/**2 * KHAELOR3 * File: src/shared/result.ts4 * Description: Result primitive and Unsubscribe type — the shared success/failure vocabulary.5 *6 * Author: Simon-Pierre Boucher7 * Contact: contact@spboucher.ai8 */910import type { KhaelorError } from "./errors.js";1112/** Discriminated success/failure result (ARCHITECTURE.md §2.2). */13export type Result<T, E = KhaelorError> = { ok: true; value: T } | { ok: false; error: E };1415/** Construct a success result. */16export function ok<T>(value: T): { ok: true; value: T } {17 return { ok: true, value };18}1920/** Construct a failure result. */21export function err<E>(error: E): { ok: false; error: E } {22 return { ok: false, error };23}2425/** Unwrap a result or throw its error (for boundaries where throwing is correct). */26export function unwrap<T, E>(result: Result<T, E>): T {27 if (result.ok) return result.value;28 throw result.error instanceof Error29 ? result.error30 : new Error(String(result.error));31}3233/** Returned by every subscription — calling it detaches the handler. */34export type Unsubscribe = () => void;35