@rcrsr/rill-ext-claude-code 0.9.0 → 0.11.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/dist/index.d.ts CHANGED
@@ -1,16 +1,261 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ import { ExtensionConfigSchema, ExtensionResult } from '@rcrsr/rill';
4
+ import * as pty from 'node-pty';
5
+
6
+ /**
7
+ * Type definitions for Claude Code extension.
8
+ * Defines message types, token tracking, and result structures.
9
+ */
10
+ /**
11
+ * Token count breakdown from Claude Code CLI.
12
+ * Tracks prompt tokens, cache operations, and output tokens.
13
+ */
14
+ export interface TokenCounts {
15
+ /** Non-cached prompt tokens */
16
+ readonly prompt: number;
17
+ /** Tokens written to 5-minute cache */
18
+ readonly cacheWrite5m: number;
19
+ /** Tokens written to 1-hour cache */
20
+ readonly cacheWrite1h: number;
21
+ /** Tokens read from cache */
22
+ readonly cacheRead: number;
23
+ /** Output tokens generated */
24
+ readonly output: number;
25
+ }
26
+ /**
27
+ * Token usage data from Claude API response.
28
+ * Maps to TokenCounts fields via extraction logic.
29
+ */
30
+ export interface TokenUsage {
31
+ /** Non-cached input tokens */
32
+ readonly input_tokens?: number | undefined;
33
+ /** Generated output tokens */
34
+ readonly output_tokens?: number | undefined;
35
+ /** Cache read tokens */
36
+ readonly cache_read_input_tokens?: number | undefined;
37
+ /** Structured cache creation tracking */
38
+ readonly cache_creation?: {
39
+ /** 5-minute cache write tokens */
40
+ readonly ephemeral_5m_input_tokens?: number | undefined;
41
+ /** 1-hour cache write tokens */
42
+ readonly ephemeral_1h_input_tokens?: number | undefined;
43
+ } | undefined;
44
+ }
45
+ /**
46
+ * Text content block.
47
+ */
48
+ export interface TextBlock {
49
+ readonly type: "text";
50
+ readonly text: string;
51
+ }
52
+ /**
53
+ * Tool use request block.
54
+ */
55
+ export interface ToolUseBlock {
56
+ readonly type: "tool_use";
57
+ readonly id: string;
58
+ readonly name: string;
59
+ readonly input: Record<string, unknown>;
60
+ }
61
+ /**
62
+ * Tool result response block.
63
+ */
64
+ export interface ToolResultBlock {
65
+ readonly type: "tool_result";
66
+ readonly tool_use_id: string;
67
+ readonly content: string | unknown;
68
+ readonly is_error?: boolean | undefined;
69
+ }
70
+ /**
71
+ * Content block variants for message content arrays.
72
+ */
73
+ export type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock;
74
+ /**
75
+ * System initialization message.
76
+ * First message in stream, establishes session config.
77
+ */
78
+ export interface SystemMessage {
79
+ readonly type: "system";
80
+ readonly subtype: "init";
81
+ readonly model: string;
82
+ readonly tools?: readonly unknown[] | undefined;
83
+ readonly mcp_servers?: readonly unknown[] | undefined;
84
+ }
85
+ /**
86
+ * Assistant response message.
87
+ * Contains text and tool use blocks.
88
+ */
89
+ export interface AssistantMessage {
90
+ readonly type: "assistant";
91
+ readonly message: {
92
+ readonly content: readonly ContentBlock[];
93
+ readonly usage?: TokenUsage | undefined;
94
+ };
95
+ }
96
+ /**
97
+ * User message with tool results.
98
+ * Contains tool result blocks.
99
+ */
100
+ export interface UserMessage {
101
+ readonly type: "user";
102
+ readonly message: {
103
+ readonly content: readonly ContentBlock[];
104
+ };
105
+ }
106
+ /**
107
+ * Result message with cost and duration.
108
+ * Final message in stream with aggregated metrics.
109
+ */
110
+ export interface ResultMessage {
111
+ readonly type: "result";
112
+ readonly cost_usd: number;
113
+ readonly duration_ms: number;
114
+ readonly is_error: boolean;
115
+ readonly usage: TokenUsage;
116
+ }
117
+ /**
118
+ * Discriminated union of all Claude Code message types.
119
+ * Discriminant field: `type`
120
+ */
121
+ export type ClaudeMessage = SystemMessage | AssistantMessage | UserMessage | ResultMessage;
122
+ /**
123
+ * Configuration options for Claude Code integration.
124
+ */
125
+ export interface ClaudeCodeConfig {
126
+ /** Path to Claude Code CLI binary (default: 'claude') */
127
+ readonly binaryPath?: string | undefined;
128
+ /** Default timeout in milliseconds (default: 1800000) */
129
+ readonly defaultTimeout?: number | undefined;
130
+ /** Skip permission checks (default: true) */
131
+ readonly dangerouslySkipPermissions?: boolean | undefined;
132
+ /** Setting sources to load: 'user', 'project', 'local' (default: '') */
133
+ readonly settingSources?: string | undefined;
134
+ }
135
+ /**
136
+ * Options for prompt execution.
137
+ */
138
+ export interface PromptOptions {
139
+ /** Execution timeout in milliseconds (overrides defaultTimeout) */
140
+ readonly timeout?: number | undefined;
141
+ }
142
+ /**
143
+ * Complete result from Claude Code prompt execution.
144
+ * Aggregates all stream messages into single structure.
145
+ */
146
+ export interface ClaudeCodeResult {
147
+ /** Combined text result from all assistant messages */
148
+ readonly result: string;
149
+ /** Token count breakdown */
150
+ readonly tokens: TokenCounts;
151
+ /** Total cost in USD */
152
+ readonly cost: number;
153
+ /** Exit code from CLI process (0 = success) */
154
+ readonly exitCode: number;
155
+ /** Total execution duration in milliseconds */
156
+ readonly duration: number;
157
+ }
158
+ /**
159
+ * Stream parser for line-delimited JSON.
160
+ * Buffers incomplete lines across chunks.
161
+ */
162
+ export interface StreamParser {
163
+ /**
164
+ * Process a chunk of raw PTY output.
165
+ * Emits parsed messages via callback.
166
+ * Throws RuntimeError RILL-R004 for invalid JSON on complete lines.
167
+ *
168
+ * @param chunk - Raw data from PTY (Buffer or string)
169
+ * @param onMessage - Callback for each parsed message
170
+ * @throws RuntimeError with code RILL-R004 for invalid JSON
171
+ */
172
+ processChunk(chunk: Buffer | string, onMessage: (message: ClaudeMessage) => void): void;
173
+ /**
174
+ * Flush remaining buffered data.
175
+ * Call when stream ends to process incomplete lines.
176
+ *
177
+ * @param onMessage - Callback for final parsed messages
178
+ * @throws RuntimeError with code RILL-R004 for invalid JSON
179
+ */
180
+ flush(onMessage: (message: ClaudeMessage) => void): void;
181
+ }
182
+ /**
183
+ * Create a new stream parser instance.
184
+ *
185
+ * @returns Stream parser with buffering state
186
+ */
187
+ export declare function createStreamParser(): StreamParser;
188
+ /**
189
+ * Extracts complete ClaudeCodeResult from parsed message stream.
190
+ * Accumulates token counts across assistant messages and extracts cost/duration from final result message.
191
+ *
192
+ * @param messages - Parsed stream messages (ClaudeMessage[])
193
+ * @returns Complete result dict with text, tokens, cost, and exitCode
194
+ */
195
+ export declare function extractResult(messages: readonly ClaudeMessage[]): ClaudeCodeResult;
196
+ /**
197
+ * Process spawn result.
198
+ * Includes PTY instance and cleanup function.
199
+ */
200
+ export interface SpawnResult {
201
+ /** PTY process instance */
202
+ readonly ptyProcess: pty.IPty;
203
+ /** Exit code promise (resolves when process exits) */
204
+ readonly exitCode: Promise<number>;
205
+ /** Cleanup function (kills process if running) */
206
+ readonly dispose: () => void;
207
+ }
208
+ /**
209
+ * Options for spawning Claude CLI process.
210
+ */
211
+ export interface SpawnOptions {
212
+ /** Path to Claude CLI binary (default: 'claude') */
213
+ readonly binaryPath?: string | undefined;
214
+ /** Timeout in milliseconds (kills process after duration) */
215
+ readonly timeoutMs?: number | undefined;
216
+ /** Working directory for process (default: inherit) */
217
+ readonly cwd?: string | undefined;
218
+ /** Environment variables (default: inherit) */
219
+ readonly env?: Record<string, string | undefined> | undefined;
220
+ /** Skip permission checks (default: true) */
221
+ readonly dangerouslySkipPermissions?: boolean | undefined;
222
+ /** Setting sources to load: 'user', 'project', 'local' (default: '') */
223
+ readonly settingSources?: string | undefined;
224
+ }
225
+ /**
226
+ * Spawn Claude CLI process with timeout enforcement.
227
+ *
228
+ * @param prompt - User prompt to send to Claude
229
+ * @param options - Spawn options
230
+ * @returns Process handle with exit code and cleanup
231
+ * @throws RuntimeError RILL-R004 for spawn failures
232
+ */
233
+ export declare function spawnClaudeCli(prompt: string, options?: SpawnOptions): SpawnResult;
234
+ /**
235
+ * Create Claude Code extension instance.
236
+ * Validates configuration and returns host functions with cleanup.
237
+ *
238
+ * @param config - Extension configuration
239
+ * @returns ExtensionResult with prompt, skill, command functions and dispose
240
+ * @throws Error for invalid configuration (EC-1, EC-2)
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const ext = createClaudeCodeExtension({
245
+ * binaryPath: '/usr/local/bin/claude',
246
+ * defaultTimeout: 60000
247
+ * });
248
+ * // Use with rill runtime...
249
+ * await ext.dispose();
250
+ * ```
251
+ */
252
+ export declare function createClaudeCodeExtension(config?: ClaudeCodeConfig): ExtensionResult;
1
253
  /**
2
254
  * @rcrsr/rill-ext-claude-code
3
255
  *
4
256
  * Extension for executing Claude Code toolkit operations from rill scripts.
5
257
  */
6
258
  export declare const VERSION = "0.1.0";
7
- export type { TokenCounts, TokenUsage, TextBlock, ToolUseBlock, ToolResultBlock, ContentBlock, SystemMessage, AssistantMessage, UserMessage, ResultMessage, ClaudeMessage, ClaudeCodeConfig, PromptOptions, ClaudeCodeResult, } from './types.js';
8
- export type { StreamParser } from './stream-parser.js';
9
- export { createStreamParser } from './stream-parser.js';
10
- export { extractResult } from './result.js';
11
- export type { SpawnResult, SpawnOptions } from './process.js';
12
- export { spawnClaudeCli } from './process.js';
13
- export { createClaudeCodeExtension } from './factory.js';
14
- import type { ExtensionConfigSchema } from '@rcrsr/rill';
15
259
  export declare const configSchema: ExtensionConfigSchema;
16
- //# sourceMappingURL=index.d.ts.map
260
+
261
+ export {};