@casualjim/pi-pretty 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,202 @@
1
+ /**
2
+ * pi-pretty shared types.
3
+ */
4
+
5
+ import type { ConstrainedSamplingConfig, ImageContent, TextContent } from "@earendil-works/pi-ai";
6
+ import type { AgentToolResult, CustomEditor } from "@earendil-works/pi-coding-agent";
7
+ import type { FffInitOptions } from "./fff.js";
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Re-export FFF types needed by tools
11
+ // ---------------------------------------------------------------------------
12
+
13
+ export type { FileFinder, FileItem, GrepCursor, GrepMatch, GrepResult, SearchResult } from "@ff-labs/fff-node";
14
+
15
+ // ---------------------------------------------------------------------------
16
+ // Content / Result types
17
+ // ---------------------------------------------------------------------------
18
+
19
+ export type ToolContent = TextContent | ImageContent;
20
+ export type { ImageContent, TextContent };
21
+ // ---------------------------------------------------------------------------
22
+ // Theme / rendering context types
23
+ // ---------------------------------------------------------------------------
24
+
25
+ export interface ThemeLike {
26
+ fg: (key: string, text: string) => string;
27
+ bold: (text: string) => string;
28
+ getBgAnsi?: (key: string) => string;
29
+ }
30
+
31
+ export interface RenderCtxLike {
32
+ lastComponent?: ComponentLike;
33
+ toolCallId?: string;
34
+ isError?: boolean;
35
+ state: Record<string, unknown>;
36
+ expanded?: boolean;
37
+ invalidate?: () => void;
38
+ }
39
+
40
+ export interface TextLike {
41
+ setText(v: string): void;
42
+ getText?(): string;
43
+ }
44
+
45
+ /** Minimal Component interface matching pi-tui's Component. */
46
+ export interface ComponentLike {
47
+ setText(v: string): void;
48
+ render(width: number): string[];
49
+ invalidate?(): void;
50
+ }
51
+
52
+ // ---------------------------------------------------------------------------
53
+ // Render detail types
54
+ // ---------------------------------------------------------------------------
55
+
56
+ export type ReadDetails =
57
+ | { _type: "readImage"; filePath: string }
58
+ | { _type: "readFile"; filePath: string; content: string; offset: number; lineCount: number };
59
+
60
+ export interface BashDetails extends Record<string, unknown> {
61
+ _type: "bashResult";
62
+ text: string;
63
+ exitCode: number | null;
64
+ command: string;
65
+ }
66
+
67
+ export interface LsDetails extends Record<string, unknown> {
68
+ _type: "lsResult";
69
+ text: string;
70
+ path: string;
71
+ entryCount: number;
72
+ }
73
+
74
+ export interface FindDetails extends Record<string, unknown> {
75
+ _type: "findResult";
76
+ text: string;
77
+ pattern: string;
78
+ matchCount: number;
79
+ notices?: string[];
80
+ }
81
+
82
+ export interface GrepDetails extends Record<string, unknown> {
83
+ _type: "grepResult";
84
+ text: string;
85
+ pattern: string;
86
+ matchCount: number;
87
+ }
88
+
89
+ export type AnyDetails = ReadDetails | BashDetails | LsDetails | FindDetails | GrepDetails;
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Tool input types
93
+ // ---------------------------------------------------------------------------
94
+
95
+ export interface ReadInput {
96
+ path: string;
97
+ offset?: number;
98
+ limit?: number;
99
+ }
100
+
101
+ export interface BashInput {
102
+ command: string;
103
+ timeout?: number;
104
+ }
105
+
106
+ export interface LsInput {
107
+ path?: string;
108
+ }
109
+
110
+ export interface FindInput {
111
+ pattern: string;
112
+ path?: string;
113
+ limit?: number;
114
+ }
115
+
116
+ export interface GrepInput {
117
+ pattern: string;
118
+ path?: string;
119
+ glob?: string;
120
+ context?: number;
121
+ limit?: number;
122
+ literal?: boolean;
123
+ ignoreCase?: boolean;
124
+ }
125
+
126
+ // ---------------------------------------------------------------------------
127
+ // SDK tool definition shape (DI-friendly — accepts both mock and real SDK)
128
+ // ---------------------------------------------------------------------------
129
+
130
+ /**
131
+ * Minimal structural type for an SDK-produced tool definition.
132
+ * Accepts both the real SDK's ToolDefinition<> return type and test mocks.
133
+ */
134
+ export interface SdkToolDef {
135
+ name?: string;
136
+ description?: string;
137
+ label?: string;
138
+ parameters?: unknown;
139
+ promptSnippet?: string;
140
+ promptGuidelines?: string[];
141
+ constrainedSampling?: false | ConstrainedSamplingConfig;
142
+ execute: (...args: any[]) => Promise<AgentToolResult<any>>;
143
+ }
144
+
145
+ export interface SdkTools {
146
+ createReadTool?: (cwd: string) => SdkToolDef;
147
+ createReadToolDefinition?: (cwd: string) => SdkToolDef;
148
+ createLsTool?: (cwd: string) => SdkToolDef;
149
+ createLsToolDefinition?: (cwd: string) => SdkToolDef;
150
+ createFindTool?: (cwd: string) => SdkToolDef;
151
+ createFindToolDefinition?: (cwd: string) => SdkToolDef;
152
+ createGrepTool?: (cwd: string) => SdkToolDef;
153
+ createGrepToolDefinition?: (cwd: string) => SdkToolDef;
154
+ getAgentDir?: () => string;
155
+ }
156
+
157
+ // ---------------------------------------------------------------------------
158
+ // FFF service interfaces
159
+ // ---------------------------------------------------------------------------
160
+
161
+ /** Minimal FFF service shape for tools that only need fileSearch. */
162
+ export interface FffServiceLike {
163
+ readonly isAvailable: boolean;
164
+ readonly partialIndex: boolean;
165
+ getFinder(): import("@ff-labs/fff-node").FileFinder | null;
166
+ }
167
+
168
+ /** Full FFF service for grep tools that also need cursor store. */
169
+ export interface FffServiceWithCursor extends FffServiceLike {
170
+ getCursorStore(): CursorStore;
171
+ }
172
+
173
+ /** FFF lifecycle interface (used by session lifecycle code). */
174
+ export interface FffService extends FffServiceWithCursor {
175
+ ensureFinder(cwd: string, options?: FffInitOptions): Promise<void>;
176
+ destroy(): void;
177
+ isModuleLoaded(): boolean;
178
+ tryLoadModule(): Promise<boolean>;
179
+ }
180
+
181
+ export interface CursorStore {
182
+ store(cursor: unknown): string;
183
+ get(id: string): unknown | undefined;
184
+ }
185
+
186
+ // ---------------------------------------------------------------------------
187
+ // DI
188
+ // ---------------------------------------------------------------------------
189
+
190
+ export type CustomEditorConstructor = new (...args: ConstructorParameters<typeof CustomEditor>) => CustomEditor;
191
+
192
+ export interface PiPrettyDeps {
193
+ sdk?: SdkTools;
194
+ TextComponent?: new (text?: string, x?: number, y?: number) => ComponentLike;
195
+ fffModule?: typeof import("@ff-labs/fff-node");
196
+ /** Host AssistantMessageComponent class for the per-row label patch; defaults
197
+ * to the package export. Injectable so tests can verify against the exact
198
+ * class instance they construct rows from. */
199
+ assistantMessageComponent?: unknown;
200
+ /** Host CustomEditor class for the live prompt icon; defaults to the package export. */
201
+ customEditorClass?: CustomEditorConstructor;
202
+ }