sparkecoder 0.1.3 → 0.1.5

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.
@@ -1,6 +1,7 @@
1
1
  import { ModelMessage, streamText } from 'ai';
2
- import { S as Session, f as ToolExecution } from './schema-EPbMMFza.js';
2
+ import { S as Session, e as ToolExecution } from './schema-CkrIadxa.js';
3
3
  import { z } from 'zod';
4
+ import { B as BashToolProgress } from './bash-CGAqW7HR.js';
4
5
 
5
6
  declare const ToolApprovalConfigSchema: z.ZodObject<{
6
7
  bash: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
@@ -228,6 +229,9 @@ interface AgentOptions {
228
229
  }
229
230
  interface AgentRunOptions {
230
231
  prompt: string;
232
+ abortSignal?: AbortSignal;
233
+ /** Skip saving user message (if already saved externally) */
234
+ skipSaveUserMessage?: boolean;
231
235
  onText?: (text: string) => void;
232
236
  onToolCall?: (toolCall: {
233
237
  toolCallId: string;
@@ -245,6 +249,14 @@ interface AgentRunOptions {
245
249
  toolCalls?: unknown[];
246
250
  usage?: unknown;
247
251
  }) => void;
252
+ onAbort?: (info: {
253
+ steps: unknown[];
254
+ }) => void;
255
+ /** Called when a tool (like bash) has progress to report (e.g., terminal started) */
256
+ onToolProgress?: (progress: {
257
+ toolName: string;
258
+ data: BashToolProgress;
259
+ }) => void;
248
260
  }
249
261
  interface AgentStreamResult {
250
262
  sessionId: string;
@@ -259,9 +271,13 @@ interface AgentStreamResult {
259
271
  declare class Agent {
260
272
  private session;
261
273
  private context;
262
- private tools;
274
+ private baseTools;
263
275
  private pendingApprovals;
264
276
  private constructor();
277
+ /**
278
+ * Create tools with optional progress callbacks
279
+ */
280
+ private createToolsWithCallbacks;
265
281
  /**
266
282
  * Create or resume an agent session
267
283
  */
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
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';
1
+ import { R as ResolvedConfig } from './index-Btr542-G.js';
2
+ export { A as Agent, a as AgentOptions, b as AgentRunOptions, c as AgentStreamResult, S as SparkcoderConfig, T as ToolApprovalConfig } from './index-Btr542-G.js';
3
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';
4
+ export { checkpointQueries, closeDatabase, fileBackupQueries, getDb, initDatabase, messageQueries, sessionQueries, skillQueries, todoQueries, toolExecutionQueries } from './db/index.js';
5
+ import { F as FileBackup, C as Checkpoint } from './schema-CkrIadxa.js';
6
+ export { a as Message, M as ModelMessage, S as Session, b as SessionConfig, g as Terminal, T as TodoItem, e as ToolExecution } from './schema-CkrIadxa.js';
7
+ export { createLoadSkillTool, createReadFileTool, createTodoTool, createTools, createWriteFileTool } from './tools/index.js';
8
+ export { c as createBashTool } from './bash-CGAqW7HR.js';
8
9
  import 'ai';
9
10
  import 'zod';
10
11
  import 'hono/types';
@@ -18,90 +19,190 @@ import 'drizzle-orm/sqlite-core';
18
19
  */
19
20
  declare function loadConfig(configPath?: string, workingDirectory?: string): ResolvedConfig;
20
21
 
21
- interface SpawnOptions {
22
+ /**
23
+ * Checkpoint system for session revert functionality
24
+ *
25
+ * Creates checkpoints before each user message, backs up modified files,
26
+ * and allows reverting to any previous checkpoint.
27
+ */
28
+
29
+ interface CheckpointManager {
22
30
  sessionId: string;
23
- command: string;
24
- cwd?: string;
25
- name?: string;
26
- env?: Record<string, string>;
31
+ workingDirectory: string;
32
+ currentCheckpointId: string | null;
27
33
  }
28
- interface TerminalInfo {
34
+ /**
35
+ * Get or create a checkpoint manager for a session
36
+ */
37
+ declare function getCheckpointManager(sessionId: string, workingDirectory: string): CheckpointManager;
38
+ /**
39
+ * Create a new checkpoint before processing a user message
40
+ * Called when a user message is about to be processed
41
+ */
42
+ declare function createCheckpoint(sessionId: string, workingDirectory: string, messageSequence: number): Promise<Checkpoint>;
43
+ /**
44
+ * Backup a file before it's modified
45
+ * Called by the write_file tool before writing
46
+ */
47
+ declare function backupFile(sessionId: string, workingDirectory: string, filePath: string): Promise<FileBackup | null>;
48
+ /**
49
+ * Revert a session to a specific checkpoint
50
+ * This will:
51
+ * 1. Restore all files to their state at that checkpoint
52
+ * 2. Delete all messages after the checkpoint's message sequence
53
+ * 3. Delete all tool executions after the checkpoint
54
+ * 4. Delete all checkpoints after this one
55
+ */
56
+ declare function revertToCheckpoint(sessionId: string, checkpointId: string): Promise<{
57
+ success: boolean;
58
+ filesRestored: number;
59
+ filesDeleted: number;
60
+ messagesDeleted: number;
61
+ checkpointsDeleted: number;
62
+ error?: string;
63
+ }>;
64
+ /**
65
+ * Get all checkpoints for a session
66
+ */
67
+ declare function getCheckpoints(sessionId: string): Checkpoint[];
68
+ /**
69
+ * Get the diff for an entire session (all file changes from start to now)
70
+ */
71
+ declare function getSessionDiff(sessionId: string): Promise<{
72
+ files: Array<{
73
+ path: string;
74
+ status: 'created' | 'modified' | 'deleted';
75
+ originalContent: string | null;
76
+ currentContent: string | null;
77
+ }>;
78
+ }>;
79
+ /**
80
+ * Clear the checkpoint manager for a session (called when session is deleted)
81
+ */
82
+ declare function clearCheckpointManager(sessionId: string): void;
83
+
84
+ /**
85
+ * tmux wrapper for terminal session management
86
+ *
87
+ * Provides a thin abstraction over tmux commands for:
88
+ * - Session creation and management
89
+ * - Output capture and logging
90
+ * - Process lifecycle management
91
+ */
92
+ interface TerminalMeta {
29
93
  id: string;
30
- name: string | null;
31
94
  command: string;
32
95
  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;
96
+ createdAt: string;
97
+ sessionId: string;
98
+ background: boolean;
39
99
  }
100
+ interface TerminalResult {
101
+ id: string;
102
+ output: string;
103
+ exitCode: number;
104
+ status: 'completed' | 'running' | 'stopped' | 'error';
105
+ }
106
+ /**
107
+ * Check if tmux is installed and available
108
+ */
109
+ declare function isTmuxAvailable(): Promise<boolean>;
40
110
  /**
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;
111
+ * Generate a unique terminal ID
112
+ * Ensure it starts with a letter (tmux session names work better this way)
113
+ */
114
+ declare function generateTerminalId(): string;
115
+ /**
116
+ * Get the tmux session name for a terminal ID
117
+ */
118
+ declare function getSessionName(terminalId: string): string;
119
+ /**
120
+ * Get the log directory for a terminal (session-scoped)
121
+ */
122
+ declare function getLogDir(terminalId: string, workingDirectory: string, sessionId?: string): string;
123
+ /**
124
+ * Run a command synchronously in tmux (waits for completion)
125
+ */
126
+ declare function runSync(command: string, workingDirectory: string, options: {
127
+ sessionId: string;
128
+ timeout?: number;
129
+ terminalId?: string;
130
+ }): Promise<TerminalResult>;
131
+ /**
132
+ * Run a command in the background (returns immediately)
133
+ */
134
+ declare function runBackground(command: string, workingDirectory: string, options: {
135
+ sessionId: string;
136
+ terminalId?: string;
137
+ }): Promise<TerminalResult>;
138
+ /**
139
+ * Get logs from a terminal
140
+ */
141
+ declare function getLogs(terminalId: string, workingDirectory: string, options?: {
142
+ tail?: number;
143
+ sessionId?: string;
144
+ }): Promise<{
145
+ output: string;
146
+ status: 'running' | 'stopped' | 'unknown';
147
+ }>;
148
+ /**
149
+ * Check if a terminal is running
150
+ */
151
+ declare function isRunning(terminalId: string): Promise<boolean>;
152
+ /**
153
+ * Kill a terminal session
154
+ */
155
+ declare function killTerminal(terminalId: string): Promise<boolean>;
156
+ /**
157
+ * List all sparkecoder terminal sessions
158
+ */
159
+ declare function listSessions(): Promise<string[]>;
160
+ /**
161
+ * Get metadata for a terminal
162
+ */
163
+ declare function getMeta(terminalId: string, workingDirectory: string, sessionId?: string): Promise<TerminalMeta | null>;
164
+ /**
165
+ * List all terminals for a session
166
+ */
167
+ declare function listSessionTerminals(sessionId: string, workingDirectory: string): Promise<TerminalMeta[]>;
168
+ /**
169
+ * Send input (keystrokes) to a running terminal
170
+ * Use this to respond to interactive prompts
171
+ */
172
+ declare function sendInput(terminalId: string, input: string, options?: {
173
+ pressEnter?: boolean;
174
+ }): Promise<boolean>;
175
+ /**
176
+ * Send special keys to a terminal (like arrow keys, escape, etc.)
177
+ */
178
+ declare function sendKey(terminalId: string, key: 'Enter' | 'Escape' | 'Up' | 'Down' | 'Left' | 'Right' | 'Tab' | 'C-c' | 'C-d' | 'y' | 'n'): Promise<boolean>;
179
+
180
+ type tmux_TerminalMeta = TerminalMeta;
181
+ type tmux_TerminalResult = TerminalResult;
182
+ declare const tmux_generateTerminalId: typeof generateTerminalId;
183
+ declare const tmux_getLogDir: typeof getLogDir;
184
+ declare const tmux_getLogs: typeof getLogs;
185
+ declare const tmux_getMeta: typeof getMeta;
186
+ declare const tmux_getSessionName: typeof getSessionName;
187
+ declare const tmux_isRunning: typeof isRunning;
188
+ declare const tmux_isTmuxAvailable: typeof isTmuxAvailable;
189
+ declare const tmux_killTerminal: typeof killTerminal;
190
+ declare const tmux_listSessionTerminals: typeof listSessionTerminals;
191
+ declare const tmux_listSessions: typeof listSessions;
192
+ declare const tmux_runBackground: typeof runBackground;
193
+ declare const tmux_runSync: typeof runSync;
194
+ declare const tmux_sendInput: typeof sendInput;
195
+ declare const tmux_sendKey: typeof sendKey;
196
+ declare namespace tmux {
197
+ export { type tmux_TerminalMeta as TerminalMeta, type tmux_TerminalResult as TerminalResult, tmux_generateTerminalId as generateTerminalId, tmux_getLogDir as getLogDir, tmux_getLogs as getLogs, tmux_getMeta as getMeta, tmux_getSessionName as getSessionName, tmux_isRunning as isRunning, tmux_isTmuxAvailable as isTmuxAvailable, tmux_killTerminal as killTerminal, tmux_listSessionTerminals as listSessionTerminals, tmux_listSessions as listSessions, tmux_runBackground as runBackground, tmux_runSync as runSync, tmux_sendInput as sendInput, tmux_sendKey as sendKey };
96
198
  }
97
- declare function getTerminalManager(): TerminalManager;
98
199
 
99
200
  /**
100
- * Sparkecoder - A powerful coding agent CLI with HTTP API
201
+ * SparkECoder - A powerful coding agent CLI with HTTP API
101
202
  *
102
203
  * @packageDocumentation
103
204
  */
104
205
 
105
206
  declare const VERSION = "0.1.0";
106
207
 
107
- export { ResolvedConfig, type TerminalInfo, VERSION, getTerminalManager, loadConfig };
208
+ export { Checkpoint, FileBackup, ResolvedConfig, VERSION, backupFile, clearCheckpointManager, createCheckpoint, getCheckpointManager, getCheckpoints, getSessionDiff, loadConfig, revertToCheckpoint, tmux };