import type { z } from "zod"; export type Scope = "global" | "project"; export type JsonObject = Record; export interface ChiConfigChange { scope: Scope; key: string; previous: unknown; current: unknown; } export interface ChiConfigContract { schemaVersion: number; schema: z.ZodObject; migrate?: ( data: JsonObject, fromSchemaVersion: number, scope: Scope, ) => JsonObject; } export interface ChiModuleDefinition< TApi = unknown, TConfig extends JsonObject = JsonObject, > { id: string; version: string; dependencies?: readonly string[]; api?: TApi; config: ChiConfigContract; initialize(chi: ChiBase, config: TConfig): void | Promise; onConfigChange?( chi: ChiBase, current: TConfig, changes: readonly ChiConfigChange[], ): void | Promise; } export interface CohortIdentity extends JsonObject { github: string; displayName: string; team: string; role: string; relayPublicKey: string; } export interface ChiBaseApi { getIdentity(): CohortIdentity; onIdentityChange( listener: (identity: CohortIdentity) => void, ): () => void; } export interface PromptContributionInput { priority: number; maxChars: number; content: string; } export interface PromptContribution extends PromptContributionInput { moduleId: string; updatedAt: string; } export type ChiModuleState = | "registered" | "initializing" | "ready" | "blocked" | "failed"; export interface ChiModuleStatus { id: string; version: string; dependencies: readonly string[]; state: ChiModuleState; diagnostic?: string; } export interface ChiBase { register( definition: ChiModuleDefinition, ): void; get(id: string): TApi | undefined; require(id: string): TApi; list(): readonly ChiModuleStatus[]; getConfig(id: string): TConfig | undefined; setConfigValue( id: string, scope: Scope, key: string, value: unknown | undefined, ): Promise; setPromptContribution( moduleId: string, contribution: PromptContributionInput | undefined, ): void; getPromptContributions(): readonly PromptContribution[]; }