Repository navigation
Expand file tree
/
Copy pathprotocol.ts
More file actions
75 lines (66 loc) · 2.63 KB
/
Copy pathprotocol.ts
File metadata and controls
75 lines (66 loc) · 2.63 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
/**
* IDE ↔ Pi protocol types.
*
* All messages are newline-delimited JSON (\n terminated) over a Unix domain
* socket located at <project-root>/.pi/ide/<ide-name>.sock.
*
* The IDE name is taken from the socket filename — no in-band handshake is
* required. Forward compatibility is maintained by adding new opcodes and
* keeping new fields optional; receivers ignore unknown opcodes.
*/
// ---------------------------------------------------------------------------
// IDE → Pi
// ---------------------------------------------------------------------------
/**
* Pushed by the IDE whenever the active editor or selection changes
* (debounced ~200 ms).
*/
export interface IdeContext {
type: "context";
/** Path relative to project root. `null` / omitted when no file is focused. */
file?: string | null;
/** 1-indexed inclusive start line of the selection. Omitted when no selection. */
startLine?: number;
/** 1-indexed inclusive end line of the selection. Omitted when no selection. */
endLine?: number;
}
/**
* Sent by the IDE when the user submits or cancels a review opened via
* {@link IdeReviewRequest}. At most one review is in flight at a time, so no
* correlation id is required.
*/
export interface IdeReviewResult {
type: "reviewResult";
status: "submitted" | "cancelled";
/** Empty when cancelled or approved without comments. */
comments: ReviewComment[];
}
export interface ReviewComment {
/** Workspace-relative path. */
file: string;
/** 1-indexed start line in the post-change file. */
line: number;
/** Inclusive end line for multi-line comments. Omitted for single-line. */
endLine?: number;
/** User's comment body. */
text: string;
/** ±3 lines around the commented line(s) as displayed to the user, with
* line numbers and `>` markers preserved. Captured by the IDE so the
* agent sees what the user actually saw, even if files change later. */
context: string[];
}
/** Union of every message the IDE can send to pi. */
export type IdeMessage = IdeContext | IdeReviewResult;
// ---------------------------------------------------------------------------
// Pi → IDE
// ---------------------------------------------------------------------------
/** Asks the IDE to open a review session over a list of files. */
export interface IdeReviewRequest {
/** Workspace-relative paths to review. */
files: string[];
}
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
/** Name of the directory under `.pi/` that holds IDE sockets. */
export const IDE_SOCK_DIR = "ide";