@saccolabs/pi-claude-cli 0.4.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/LICENSE +21 -0
- package/README.md +54 -0
- package/index.ts +133 -0
- package/package.json +72 -0
- package/src/control-handler.ts +68 -0
- package/src/event-bridge.ts +385 -0
- package/src/mcp-config.ts +93 -0
- package/src/mcp-schema-server.cjs +49 -0
- package/src/process-manager.ts +255 -0
- package/src/prompt-builder.ts +514 -0
- package/src/provider.ts +358 -0
- package/src/stream-parser.ts +37 -0
- package/src/thinking-config.ts +87 -0
- package/src/tool-mapping.ts +147 -0
- package/src/types.ts +85 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Wire protocol types for Claude CLI stream-json NDJSON communication
|
|
2
|
+
|
|
3
|
+
// NDJSON message types from Claude CLI stdout
|
|
4
|
+
|
|
5
|
+
export interface ClaudeStreamEventMessage {
|
|
6
|
+
type: "stream_event";
|
|
7
|
+
event: ClaudeApiEvent;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ClaudeResultMessage {
|
|
11
|
+
type: "result";
|
|
12
|
+
subtype: "success" | "error";
|
|
13
|
+
result?: string;
|
|
14
|
+
error?: string;
|
|
15
|
+
session_id?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ClaudeSystemMessage {
|
|
19
|
+
type: "system";
|
|
20
|
+
subtype: string;
|
|
21
|
+
session_id?: string;
|
|
22
|
+
tools?: unknown[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ClaudeControlRequest {
|
|
26
|
+
type: "control_request";
|
|
27
|
+
request_id: string;
|
|
28
|
+
request: {
|
|
29
|
+
subtype: "can_use_tool";
|
|
30
|
+
tool_name: string;
|
|
31
|
+
input: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type NdjsonMessage =
|
|
36
|
+
| ClaudeStreamEventMessage
|
|
37
|
+
| ClaudeResultMessage
|
|
38
|
+
| ClaudeSystemMessage
|
|
39
|
+
| ClaudeControlRequest;
|
|
40
|
+
|
|
41
|
+
// Claude API event types (inside stream_event wrapper)
|
|
42
|
+
|
|
43
|
+
export interface ClaudeApiEvent {
|
|
44
|
+
type: string; // message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop
|
|
45
|
+
index?: number;
|
|
46
|
+
message?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
type?: string;
|
|
49
|
+
role?: string;
|
|
50
|
+
content?: unknown[];
|
|
51
|
+
model?: string;
|
|
52
|
+
usage?: ClaudeUsage;
|
|
53
|
+
};
|
|
54
|
+
content_block?: {
|
|
55
|
+
type: string; // "text", "tool_use", "thinking"
|
|
56
|
+
text?: string;
|
|
57
|
+
id?: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
input?: string;
|
|
60
|
+
};
|
|
61
|
+
delta?: {
|
|
62
|
+
type?: string; // "text_delta", "input_json_delta", "thinking_delta", "signature_delta"
|
|
63
|
+
text?: string;
|
|
64
|
+
partial_json?: string;
|
|
65
|
+
thinking?: string;
|
|
66
|
+
signature?: string;
|
|
67
|
+
stop_reason?: string;
|
|
68
|
+
};
|
|
69
|
+
usage?: ClaudeUsage;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ClaudeUsage {
|
|
73
|
+
input_tokens?: number;
|
|
74
|
+
output_tokens?: number;
|
|
75
|
+
cache_read_input_tokens?: number;
|
|
76
|
+
cache_creation_input_tokens?: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Content block tracking during stream processing
|
|
80
|
+
|
|
81
|
+
export interface TrackedContentBlock {
|
|
82
|
+
type: "text" | "thinking";
|
|
83
|
+
text: string;
|
|
84
|
+
index: number; // Claude's content_block index
|
|
85
|
+
}
|