|
| 1 | +// Structural subset of Command Code's ModApi. Type-only: no runtime dependencies. |
| 2 | +// Command Code's community-mods contract tests check this against the actual API. |
| 3 | +export interface Disposable { |
| 4 | + dispose(): void; |
| 5 | +} |
| 6 | +export interface CommandResult { |
| 7 | + readonly message?: string; |
| 8 | + readonly prompt?: string; |
| 9 | +} |
| 10 | +export interface ExecResult { |
| 11 | + readonly stdout: string; |
| 12 | + readonly stderr: string; |
| 13 | + readonly code: number; |
| 14 | +} |
| 15 | +export interface ExecParams { |
| 16 | + readonly command: string; |
| 17 | + readonly args?: readonly string[]; |
| 18 | + readonly cwd?: string; |
| 19 | +} |
| 20 | +export type ModExec = (params: ExecParams) => Promise<ExecResult>; |
| 21 | +export interface CommandContext { |
| 22 | + readonly args: string; |
| 23 | + readonly cwd: string; |
| 24 | + readonly exec: ModExec; |
| 25 | +} |
| 26 | +export interface ModCommand { |
| 27 | + readonly name: string; |
| 28 | + readonly description: string; |
| 29 | + readonly argumentHint?: string; |
| 30 | + readonly handler: ( |
| 31 | + ctx: CommandContext, |
| 32 | + ) => CommandResult | Promise<CommandResult>; |
| 33 | +} |
| 34 | +export interface ModEvent { |
| 35 | + readonly type: string; |
| 36 | +} |
| 37 | +export interface SessionEntry<T> { |
| 38 | + readonly data?: T; |
| 39 | +} |
| 40 | +export interface SessionStore { |
| 41 | + appendCustomEntry<T = unknown>(params: { |
| 42 | + readonly customType: string; |
| 43 | + readonly data?: T; |
| 44 | + }): string; |
| 45 | + getCustomEntries<T = unknown>(params: { |
| 46 | + readonly customType: string; |
| 47 | + }): readonly SessionEntry<T>[]; |
| 48 | +} |
| 49 | +export interface SessionNode { |
| 50 | + readonly id: string; |
| 51 | + readonly label?: string; |
| 52 | + readonly children: readonly SessionNode[]; |
| 53 | +} |
| 54 | +export interface ContextUsage { |
| 55 | + readonly tokens: number | null; |
| 56 | + readonly contextWindow: number; |
| 57 | + readonly percent: number | null; |
| 58 | +} |
| 59 | +export interface ModHooks { |
| 60 | + readonly appendSystemPrompt?: () => string | undefined; |
| 61 | + readonly onSessionStart?: () => void; |
| 62 | +} |
| 63 | +export interface ModApi { |
| 64 | + readonly ui: { |
| 65 | + readonly capabilities: {readonly status: boolean}; |
| 66 | + setStatus(text: string | null): Disposable; |
| 67 | + notify(text: string, level?: 'info' | 'warning' | 'error'): void; |
| 68 | + }; |
| 69 | + readonly session: SessionStore | undefined; |
| 70 | + readonly sessions: { |
| 71 | + leafId(): string | null; |
| 72 | + tree(): readonly SessionNode[]; |
| 73 | + setLabel(params: { |
| 74 | + readonly targetId: string; |
| 75 | + readonly label: string | undefined; |
| 76 | + }): void; |
| 77 | + navigateTree(params: {readonly targetId: string}): Promise<void>; |
| 78 | + }; |
| 79 | + addCommand(command: ModCommand): Disposable; |
| 80 | + hooks(hooks: ModHooks): Disposable; |
| 81 | + on( |
| 82 | + event: |
| 83 | + | 'session_start' |
| 84 | + | 'run_start' |
| 85 | + | 'run_end' |
| 86 | + | 'run_error' |
| 87 | + | 'tool_completed' |
| 88 | + | 'tool_errored' |
| 89 | + | 'model_request_end' |
| 90 | + | 'compaction_done', |
| 91 | + handler: (event: ModEvent) => void, |
| 92 | + ): Disposable; |
| 93 | + getContextUsage(): ContextUsage | undefined; |
| 94 | + isIdle(): boolean; |
| 95 | +} |
0 commit comments