Repository navigation
Expand file tree
/
Copy pathapi.ts
More file actions
95 lines (95 loc) · 2.5 KB
/
Copy pathapi.ts
File metadata and controls
95 lines (95 loc) · 2.5 KB
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
91
92
93
94
95
// Structural subset of Command Code's ModApi. Type-only: no runtime dependencies.
// Command Code's community-mods contract tests check this against the actual API.
export interface Disposable {
dispose(): void;
}
export interface CommandResult {
readonly message?: string;
readonly prompt?: string;
}
export interface ExecResult {
readonly stdout: string;
readonly stderr: string;
readonly code: number;
}
export interface ExecParams {
readonly command: string;
readonly args?: readonly string[];
readonly cwd?: string;
}
export type ModExec = (params: ExecParams) => Promise<ExecResult>;
export interface CommandContext {
readonly args: string;
readonly cwd: string;
readonly exec: ModExec;
}
export interface ModCommand {
readonly name: string;
readonly description: string;
readonly argumentHint?: string;
readonly handler: (
ctx: CommandContext,
) => CommandResult | Promise<CommandResult>;
}
export interface ModEvent {
readonly type: string;
}
export interface SessionEntry<T> {
readonly data?: T;
}
export interface SessionStore {
appendCustomEntry<T = unknown>(params: {
readonly customType: string;
readonly data?: T;
}): string;
getCustomEntries<T = unknown>(params: {
readonly customType: string;
}): readonly SessionEntry<T>[];
}
export interface SessionNode {
readonly id: string;
readonly label?: string;
readonly children: readonly SessionNode[];
}
export interface ContextUsage {
readonly tokens: number | null;
readonly contextWindow: number;
readonly percent: number | null;
}
export interface ModHooks {
readonly appendSystemPrompt?: () => string | undefined;
readonly onSessionStart?: () => void;
}
export interface ModApi {
readonly ui: {
readonly capabilities: {readonly status: boolean};
setStatus(text: string | null): Disposable;
notify(text: string, level?: 'info' | 'warning' | 'error'): void;
};
readonly session: SessionStore | undefined;
readonly sessions: {
leafId(): string | null;
tree(): readonly SessionNode[];
setLabel(params: {
readonly targetId: string;
readonly label: string | undefined;
}): void;
navigateTree(params: {readonly targetId: string}): Promise<void>;
};
addCommand(command: ModCommand): Disposable;
hooks(hooks: ModHooks): Disposable;
on(
event:
| 'session_start'
| 'run_start'
| 'run_end'
| 'run_error'
| 'tool_completed'
| 'tool_errored'
| 'model_request_end'
| 'compaction_done',
handler: (event: ModEvent) => void,
): Disposable;
getContextUsage(): ContextUsage | undefined;
isIdle(): boolean;
}