sparkecoder 0.1.3
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/README.md +353 -0
- package/dist/agent/index.d.ts +5 -0
- package/dist/agent/index.js +1979 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +3779 -0
- package/dist/cli.js.map +1 -0
- package/dist/db/index.d.ts +85 -0
- package/dist/db/index.js +450 -0
- package/dist/db/index.js.map +1 -0
- package/dist/index-BxpkHy7X.d.ts +326 -0
- package/dist/index.d.ts +107 -0
- package/dist/index.js +3479 -0
- package/dist/index.js.map +1 -0
- package/dist/schema-EPbMMFza.d.ts +981 -0
- package/dist/server/index.d.ts +18 -0
- package/dist/server/index.js +3458 -0
- package/dist/server/index.js.map +1 -0
- package/dist/tools/index.d.ts +402 -0
- package/dist/tools/index.js +1366 -0
- package/dist/tools/index.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { ModelMessage, streamText } from 'ai';
|
|
2
|
+
import { S as Session, f as ToolExecution } from './schema-EPbMMFza.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const ToolApprovalConfigSchema: z.ZodObject<{
|
|
6
|
+
bash: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
7
|
+
write_file: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
8
|
+
read_file: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
9
|
+
load_skill: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
|
+
todo: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
bash: boolean;
|
|
13
|
+
write_file: boolean;
|
|
14
|
+
read_file: boolean;
|
|
15
|
+
load_skill: boolean;
|
|
16
|
+
todo: boolean;
|
|
17
|
+
}, {
|
|
18
|
+
bash?: boolean | undefined;
|
|
19
|
+
write_file?: boolean | undefined;
|
|
20
|
+
read_file?: boolean | undefined;
|
|
21
|
+
load_skill?: boolean | undefined;
|
|
22
|
+
todo?: boolean | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
declare const SessionConfigSchema: z.ZodObject<{
|
|
25
|
+
toolApprovals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
26
|
+
approvalWebhook: z.ZodOptional<z.ZodString>;
|
|
27
|
+
skillsDirectory: z.ZodOptional<z.ZodString>;
|
|
28
|
+
maxContextChars: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
maxContextChars: number;
|
|
31
|
+
toolApprovals?: Record<string, boolean> | undefined;
|
|
32
|
+
approvalWebhook?: string | undefined;
|
|
33
|
+
skillsDirectory?: string | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
toolApprovals?: Record<string, boolean> | undefined;
|
|
36
|
+
approvalWebhook?: string | undefined;
|
|
37
|
+
skillsDirectory?: string | undefined;
|
|
38
|
+
maxContextChars?: number | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
declare const SparkcoderConfigSchema: z.ZodObject<{
|
|
41
|
+
defaultModel: z.ZodDefault<z.ZodString>;
|
|
42
|
+
workingDirectory: z.ZodOptional<z.ZodString>;
|
|
43
|
+
toolApprovals: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
44
|
+
bash: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
45
|
+
write_file: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
46
|
+
read_file: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
47
|
+
load_skill: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
48
|
+
todo: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
bash: boolean;
|
|
51
|
+
write_file: boolean;
|
|
52
|
+
read_file: boolean;
|
|
53
|
+
load_skill: boolean;
|
|
54
|
+
todo: boolean;
|
|
55
|
+
}, {
|
|
56
|
+
bash?: boolean | undefined;
|
|
57
|
+
write_file?: boolean | undefined;
|
|
58
|
+
read_file?: boolean | undefined;
|
|
59
|
+
load_skill?: boolean | undefined;
|
|
60
|
+
todo?: boolean | undefined;
|
|
61
|
+
}>>>;
|
|
62
|
+
approvalWebhook: z.ZodOptional<z.ZodString>;
|
|
63
|
+
skills: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
64
|
+
directory: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
65
|
+
additionalDirectories: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
66
|
+
}, "strip", z.ZodTypeAny, {
|
|
67
|
+
directory: string;
|
|
68
|
+
additionalDirectories: string[];
|
|
69
|
+
}, {
|
|
70
|
+
directory?: string | undefined;
|
|
71
|
+
additionalDirectories?: string[] | undefined;
|
|
72
|
+
}>>>;
|
|
73
|
+
context: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
74
|
+
maxChars: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
75
|
+
autoSummarize: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
76
|
+
keepRecentMessages: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
maxChars: number;
|
|
79
|
+
autoSummarize: boolean;
|
|
80
|
+
keepRecentMessages: number;
|
|
81
|
+
}, {
|
|
82
|
+
maxChars?: number | undefined;
|
|
83
|
+
autoSummarize?: boolean | undefined;
|
|
84
|
+
keepRecentMessages?: number | undefined;
|
|
85
|
+
}>>>;
|
|
86
|
+
server: z.ZodDefault<z.ZodObject<{
|
|
87
|
+
port: z.ZodDefault<z.ZodNumber>;
|
|
88
|
+
host: z.ZodDefault<z.ZodString>;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
host: string;
|
|
91
|
+
port: number;
|
|
92
|
+
}, {
|
|
93
|
+
host?: string | undefined;
|
|
94
|
+
port?: number | undefined;
|
|
95
|
+
}>>;
|
|
96
|
+
databasePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
defaultModel: string;
|
|
99
|
+
toolApprovals: {
|
|
100
|
+
bash: boolean;
|
|
101
|
+
write_file: boolean;
|
|
102
|
+
read_file: boolean;
|
|
103
|
+
load_skill: boolean;
|
|
104
|
+
todo: boolean;
|
|
105
|
+
};
|
|
106
|
+
skills: {
|
|
107
|
+
directory: string;
|
|
108
|
+
additionalDirectories: string[];
|
|
109
|
+
};
|
|
110
|
+
context: {
|
|
111
|
+
maxChars: number;
|
|
112
|
+
autoSummarize: boolean;
|
|
113
|
+
keepRecentMessages: number;
|
|
114
|
+
};
|
|
115
|
+
server: {
|
|
116
|
+
host: string;
|
|
117
|
+
port: number;
|
|
118
|
+
};
|
|
119
|
+
databasePath: string;
|
|
120
|
+
workingDirectory?: string | undefined;
|
|
121
|
+
approvalWebhook?: string | undefined;
|
|
122
|
+
}, {
|
|
123
|
+
workingDirectory?: string | undefined;
|
|
124
|
+
defaultModel?: string | undefined;
|
|
125
|
+
toolApprovals?: {
|
|
126
|
+
bash?: boolean | undefined;
|
|
127
|
+
write_file?: boolean | undefined;
|
|
128
|
+
read_file?: boolean | undefined;
|
|
129
|
+
load_skill?: boolean | undefined;
|
|
130
|
+
todo?: boolean | undefined;
|
|
131
|
+
} | undefined;
|
|
132
|
+
approvalWebhook?: string | undefined;
|
|
133
|
+
skills?: {
|
|
134
|
+
directory?: string | undefined;
|
|
135
|
+
additionalDirectories?: string[] | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
context?: {
|
|
138
|
+
maxChars?: number | undefined;
|
|
139
|
+
autoSummarize?: boolean | undefined;
|
|
140
|
+
keepRecentMessages?: number | undefined;
|
|
141
|
+
} | undefined;
|
|
142
|
+
server?: {
|
|
143
|
+
host?: string | undefined;
|
|
144
|
+
port?: number | undefined;
|
|
145
|
+
} | undefined;
|
|
146
|
+
databasePath?: string | undefined;
|
|
147
|
+
}>;
|
|
148
|
+
type ToolApprovalConfig = z.infer<typeof ToolApprovalConfigSchema>;
|
|
149
|
+
type SessionConfig = z.infer<typeof SessionConfigSchema>;
|
|
150
|
+
type SparkcoderConfig = z.infer<typeof SparkcoderConfigSchema>;
|
|
151
|
+
interface ResolvedConfig extends Omit<SparkcoderConfig, 'server'> {
|
|
152
|
+
server: {
|
|
153
|
+
port: number;
|
|
154
|
+
host: string;
|
|
155
|
+
};
|
|
156
|
+
resolvedWorkingDirectory: string;
|
|
157
|
+
resolvedSkillsDirectories: string[];
|
|
158
|
+
resolvedDatabasePath: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
interface ContextManagerOptions {
|
|
162
|
+
sessionId: string;
|
|
163
|
+
maxContextChars: number;
|
|
164
|
+
keepRecentMessages: number;
|
|
165
|
+
autoSummarize: boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Manages conversation context including history and summarization
|
|
169
|
+
*
|
|
170
|
+
* Uses AI SDK's ModelMessage format directly for accurate message passing.
|
|
171
|
+
* Messages are stored in the exact format returned by response.messages.
|
|
172
|
+
*/
|
|
173
|
+
declare class ContextManager {
|
|
174
|
+
private sessionId;
|
|
175
|
+
private maxContextChars;
|
|
176
|
+
private keepRecentMessages;
|
|
177
|
+
private autoSummarize;
|
|
178
|
+
private summary;
|
|
179
|
+
constructor(options: ContextManagerOptions);
|
|
180
|
+
/**
|
|
181
|
+
* Get messages for the current context
|
|
182
|
+
* Returns ModelMessage[] that can be passed directly to streamText/generateText
|
|
183
|
+
*/
|
|
184
|
+
getMessages(): Promise<ModelMessage[]>;
|
|
185
|
+
/**
|
|
186
|
+
* Summarize older messages to reduce context size
|
|
187
|
+
*/
|
|
188
|
+
private summarizeContext;
|
|
189
|
+
/**
|
|
190
|
+
* Add a user message to the context
|
|
191
|
+
*/
|
|
192
|
+
addUserMessage(text: string): void;
|
|
193
|
+
/**
|
|
194
|
+
* Add response messages from AI SDK directly
|
|
195
|
+
* This is the preferred method - use result.response.messages from streamText/generateText
|
|
196
|
+
*/
|
|
197
|
+
addResponseMessages(messages: ModelMessage[]): void;
|
|
198
|
+
/**
|
|
199
|
+
* Get current context statistics
|
|
200
|
+
*/
|
|
201
|
+
getStats(): {
|
|
202
|
+
messageCount: number;
|
|
203
|
+
contextChars: number;
|
|
204
|
+
hasSummary: boolean;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Clear all messages in the context
|
|
208
|
+
*/
|
|
209
|
+
clear(): void;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Build the system prompt for the coding agent
|
|
214
|
+
*/
|
|
215
|
+
declare function buildSystemPrompt(options: {
|
|
216
|
+
workingDirectory: string;
|
|
217
|
+
skillsDirectories: string[];
|
|
218
|
+
sessionId: string;
|
|
219
|
+
customInstructions?: string;
|
|
220
|
+
}): Promise<string>;
|
|
221
|
+
|
|
222
|
+
interface AgentOptions {
|
|
223
|
+
sessionId?: string;
|
|
224
|
+
name?: string;
|
|
225
|
+
workingDirectory?: string;
|
|
226
|
+
model?: string;
|
|
227
|
+
sessionConfig?: Partial<SessionConfig>;
|
|
228
|
+
}
|
|
229
|
+
interface AgentRunOptions {
|
|
230
|
+
prompt: string;
|
|
231
|
+
onText?: (text: string) => void;
|
|
232
|
+
onToolCall?: (toolCall: {
|
|
233
|
+
toolCallId: string;
|
|
234
|
+
toolName: string;
|
|
235
|
+
input: unknown;
|
|
236
|
+
}) => void;
|
|
237
|
+
onToolResult?: (result: {
|
|
238
|
+
toolCallId: string;
|
|
239
|
+
toolName: string;
|
|
240
|
+
output: unknown;
|
|
241
|
+
}) => void;
|
|
242
|
+
onApprovalRequired?: (execution: ToolExecution) => void;
|
|
243
|
+
onStepFinish?: (step: {
|
|
244
|
+
text?: string;
|
|
245
|
+
toolCalls?: unknown[];
|
|
246
|
+
usage?: unknown;
|
|
247
|
+
}) => void;
|
|
248
|
+
}
|
|
249
|
+
interface AgentStreamResult {
|
|
250
|
+
sessionId: string;
|
|
251
|
+
stream: ReturnType<typeof streamText>;
|
|
252
|
+
waitForApprovals: () => Promise<ToolExecution[]>;
|
|
253
|
+
/** Call this after stream completes to save response messages */
|
|
254
|
+
saveResponseMessages: () => Promise<void>;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The main coding agent that orchestrates LLM interactions
|
|
258
|
+
*/
|
|
259
|
+
declare class Agent {
|
|
260
|
+
private session;
|
|
261
|
+
private context;
|
|
262
|
+
private tools;
|
|
263
|
+
private pendingApprovals;
|
|
264
|
+
private constructor();
|
|
265
|
+
/**
|
|
266
|
+
* Create or resume an agent session
|
|
267
|
+
*/
|
|
268
|
+
static create(options?: AgentOptions): Promise<Agent>;
|
|
269
|
+
/**
|
|
270
|
+
* Get the session ID
|
|
271
|
+
*/
|
|
272
|
+
get sessionId(): string;
|
|
273
|
+
/**
|
|
274
|
+
* Get session details
|
|
275
|
+
*/
|
|
276
|
+
getSession(): Session;
|
|
277
|
+
/**
|
|
278
|
+
* Run the agent with a prompt (streaming)
|
|
279
|
+
*/
|
|
280
|
+
stream(options: AgentRunOptions): Promise<AgentStreamResult>;
|
|
281
|
+
/**
|
|
282
|
+
* Run the agent with a prompt (non-streaming)
|
|
283
|
+
*/
|
|
284
|
+
run(options: Omit<AgentRunOptions, 'onText'>): Promise<{
|
|
285
|
+
text: string;
|
|
286
|
+
steps: unknown[];
|
|
287
|
+
}>;
|
|
288
|
+
/**
|
|
289
|
+
* Wrap tools to add approval checking
|
|
290
|
+
*/
|
|
291
|
+
private wrapToolsWithApproval;
|
|
292
|
+
/**
|
|
293
|
+
* Wait for all pending approvals
|
|
294
|
+
*/
|
|
295
|
+
waitForApprovals(): Promise<ToolExecution[]>;
|
|
296
|
+
/**
|
|
297
|
+
* Approve a pending tool execution
|
|
298
|
+
*/
|
|
299
|
+
approve(toolCallId: string): Promise<{
|
|
300
|
+
approved: true;
|
|
301
|
+
}>;
|
|
302
|
+
/**
|
|
303
|
+
* Reject a pending tool execution
|
|
304
|
+
*/
|
|
305
|
+
reject(toolCallId: string, reason?: string): {
|
|
306
|
+
rejected: true;
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Get pending approvals
|
|
310
|
+
*/
|
|
311
|
+
getPendingApprovals(): ToolExecution[];
|
|
312
|
+
/**
|
|
313
|
+
* Get context statistics
|
|
314
|
+
*/
|
|
315
|
+
getContextStats(): {
|
|
316
|
+
messageCount: number;
|
|
317
|
+
contextChars: number;
|
|
318
|
+
hasSummary: boolean;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Clear conversation context (start fresh)
|
|
322
|
+
*/
|
|
323
|
+
clearContext(): void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { Agent as A, ContextManager as C, type ResolvedConfig as R, type SparkcoderConfig as S, type ToolApprovalConfig as T, type AgentOptions as a, type AgentRunOptions as b, type AgentStreamResult as c, buildSystemPrompt as d };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { R as ResolvedConfig } from './index-BxpkHy7X.js';
|
|
2
|
+
export { A as Agent, a as AgentOptions, b as AgentRunOptions, c as AgentStreamResult, S as SparkcoderConfig, T as ToolApprovalConfig } from './index-BxpkHy7X.js';
|
|
3
|
+
export { ServerOptions, createApp, startServer, stopServer } from './server/index.js';
|
|
4
|
+
export { closeDatabase, getDb, initDatabase, messageQueries, sessionQueries, skillQueries, terminalQueries, todoQueries, toolExecutionQueries } from './db/index.js';
|
|
5
|
+
export { a as Message, M as ModelMessage, S as Session, g as SessionConfig, T as Terminal, d as TodoItem, f as ToolExecution } from './schema-EPbMMFza.js';
|
|
6
|
+
export { createBashTool, createLoadSkillTool, createReadFileTool, createTerminalTool, createTodoTool, createTools, createWriteFileTool } from './tools/index.js';
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import 'ai';
|
|
9
|
+
import 'zod';
|
|
10
|
+
import 'hono/types';
|
|
11
|
+
import 'hono';
|
|
12
|
+
import 'drizzle-orm/better-sqlite3';
|
|
13
|
+
import 'better-sqlite3';
|
|
14
|
+
import 'drizzle-orm/sqlite-core';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Load and parse the config file
|
|
18
|
+
*/
|
|
19
|
+
declare function loadConfig(configPath?: string, workingDirectory?: string): ResolvedConfig;
|
|
20
|
+
|
|
21
|
+
interface SpawnOptions {
|
|
22
|
+
sessionId: string;
|
|
23
|
+
command: string;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
env?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
interface TerminalInfo {
|
|
29
|
+
id: string;
|
|
30
|
+
name: string | null;
|
|
31
|
+
command: string;
|
|
32
|
+
cwd: string;
|
|
33
|
+
pid: number | null;
|
|
34
|
+
status: 'running' | 'stopped' | 'error';
|
|
35
|
+
exitCode: number | null;
|
|
36
|
+
error: string | null;
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
stoppedAt: Date | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Manages terminal processes for agent sessions
|
|
42
|
+
* - Spawns background processes
|
|
43
|
+
* - Captures stdout/stderr in ring buffers
|
|
44
|
+
* - Tracks process lifecycle
|
|
45
|
+
* - Provides log access
|
|
46
|
+
*/
|
|
47
|
+
declare class TerminalManager extends EventEmitter {
|
|
48
|
+
private processes;
|
|
49
|
+
private static instance;
|
|
50
|
+
private constructor();
|
|
51
|
+
static getInstance(): TerminalManager;
|
|
52
|
+
/**
|
|
53
|
+
* Spawn a new background process
|
|
54
|
+
*/
|
|
55
|
+
spawn(options: SpawnOptions): TerminalInfo;
|
|
56
|
+
/**
|
|
57
|
+
* Get logs from a terminal
|
|
58
|
+
*/
|
|
59
|
+
getLogs(terminalId: string, tail?: number): {
|
|
60
|
+
logs: string;
|
|
61
|
+
lineCount: number;
|
|
62
|
+
} | null;
|
|
63
|
+
/**
|
|
64
|
+
* Get terminal status
|
|
65
|
+
*/
|
|
66
|
+
getStatus(terminalId: string): TerminalInfo | null;
|
|
67
|
+
/**
|
|
68
|
+
* Kill a terminal process
|
|
69
|
+
*/
|
|
70
|
+
kill(terminalId: string, signal?: 'SIGTERM' | 'SIGKILL'): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Write to a terminal's stdin
|
|
73
|
+
*/
|
|
74
|
+
write(terminalId: string, input: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* List all terminals for a session
|
|
77
|
+
*/
|
|
78
|
+
list(sessionId: string): TerminalInfo[];
|
|
79
|
+
/**
|
|
80
|
+
* Get all running terminals for a session
|
|
81
|
+
*/
|
|
82
|
+
getRunning(sessionId: string): TerminalInfo[];
|
|
83
|
+
/**
|
|
84
|
+
* Kill all terminals for a session (cleanup)
|
|
85
|
+
*/
|
|
86
|
+
killAll(sessionId: string): number;
|
|
87
|
+
/**
|
|
88
|
+
* Clean up stopped terminals from memory (keep DB records)
|
|
89
|
+
*/
|
|
90
|
+
cleanup(sessionId?: string): number;
|
|
91
|
+
/**
|
|
92
|
+
* Parse a command string into executable and arguments
|
|
93
|
+
*/
|
|
94
|
+
private parseCommand;
|
|
95
|
+
private toTerminalInfo;
|
|
96
|
+
}
|
|
97
|
+
declare function getTerminalManager(): TerminalManager;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Sparkecoder - A powerful coding agent CLI with HTTP API
|
|
101
|
+
*
|
|
102
|
+
* @packageDocumentation
|
|
103
|
+
*/
|
|
104
|
+
|
|
105
|
+
declare const VERSION = "0.1.0";
|
|
106
|
+
|
|
107
|
+
export { ResolvedConfig, type TerminalInfo, VERSION, getTerminalManager, loadConfig };
|