goatchain 0.0.2 → 0.0.4

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.
Files changed (86) hide show
  1. package/README.md +173 -236
  2. package/README.zh.md +430 -0
  3. package/dist/acp-adapter/ACPAgent.d.ts +63 -0
  4. package/dist/acp-adapter/ProtocolConverter.d.ts +48 -0
  5. package/dist/acp-adapter/SessionRouter.d.ts +50 -0
  6. package/dist/acp-adapter/index.d.ts +12 -0
  7. package/dist/acp-adapter/types.d.ts +95 -0
  8. package/dist/acp-server.d.ts +21 -0
  9. package/dist/agent/agent.d.ts +196 -0
  10. package/dist/agent/errors.d.ts +29 -0
  11. package/dist/agent/hooks/index.d.ts +2 -0
  12. package/dist/agent/hooks/manager.d.ts +8 -0
  13. package/dist/agent/hooks/types.d.ts +19 -0
  14. package/dist/agent/index.d.ts +14 -0
  15. package/dist/agent/middleware.d.ts +162 -0
  16. package/dist/agent/tokenCounter.d.ts +55 -0
  17. package/dist/agent/types.d.ts +247 -0
  18. package/dist/index.d.ts +21 -3328
  19. package/dist/index.js +424 -140
  20. package/dist/middleware/checkpointMiddleware.d.ts +29 -0
  21. package/dist/middleware/commitModeMiddleware.d.ts +93 -0
  22. package/dist/middleware/contextCompressionMiddleware.d.ts +131 -0
  23. package/dist/middleware/gitUtils.d.ts +119 -0
  24. package/dist/middleware/parallelSubagentMiddleware.d.ts +83 -0
  25. package/dist/middleware/planModeMiddleware.d.ts +80 -0
  26. package/dist/middleware/utils.d.ts +58 -0
  27. package/dist/model/adapter.d.ts +14 -0
  28. package/dist/model/createModel.d.ts +168 -0
  29. package/dist/model/errors.d.ts +14 -0
  30. package/dist/model/health.d.ts +35 -0
  31. package/dist/model/index.d.ts +7 -0
  32. package/dist/model/openai/createOpenAIAdapter.d.ts +23 -0
  33. package/dist/model/router.d.ts +17 -0
  34. package/dist/model/types.d.ts +190 -0
  35. package/dist/model/utils/http.d.ts +15 -0
  36. package/dist/model/utils/id.d.ts +1 -0
  37. package/dist/model/utils/retry.d.ts +142 -0
  38. package/dist/session/base.d.ts +1 -0
  39. package/dist/session/executors/ParallelTaskExecutor.d.ts +16 -0
  40. package/dist/session/executors/ToolExecutor.d.ts +37 -0
  41. package/dist/session/handlers/ApprovalHandler.d.ts +6 -0
  42. package/dist/session/handlers/CheckpointManager.d.ts +10 -0
  43. package/dist/session/index.d.ts +4 -0
  44. package/dist/session/manager.d.ts +35 -0
  45. package/dist/session/session.d.ts +159 -0
  46. package/dist/session/stateStoreSessionManager.d.ts +36 -0
  47. package/dist/session/utils/AsyncQueue.d.ts +7 -0
  48. package/dist/session/utils/AutoSaveManager.d.ts +6 -0
  49. package/dist/state/FileStateStore.d.ts +72 -0
  50. package/dist/state/InMemoryStateStore.d.ts +46 -0
  51. package/dist/state/index.d.ts +6 -0
  52. package/dist/state/stateStore.d.ts +181 -0
  53. package/dist/state/types.d.ts +85 -0
  54. package/dist/subagent/file-search-specialist.d.ts +16 -0
  55. package/dist/subagent/index.d.ts +7 -0
  56. package/dist/tool/FilteredToolRegistry.d.ts +82 -0
  57. package/dist/tool/base.d.ts +57 -0
  58. package/dist/tool/builtin/askUser.d.ts +90 -0
  59. package/dist/tool/builtin/astGrepCli.d.ts +37 -0
  60. package/dist/tool/builtin/astGrepFormat.d.ts +4 -0
  61. package/dist/tool/builtin/astGrepReplace.d.ts +71 -0
  62. package/dist/tool/builtin/astGrepSearch.d.ts +101 -0
  63. package/dist/tool/builtin/bash.d.ts +96 -0
  64. package/dist/tool/builtin/edit.d.ts +82 -0
  65. package/dist/tool/builtin/enterPlanMode.d.ts +58 -0
  66. package/dist/tool/builtin/exitPlanMode.d.ts +48 -0
  67. package/dist/tool/builtin/glob.d.ts +70 -0
  68. package/dist/tool/builtin/grep.d.ts +122 -0
  69. package/dist/tool/builtin/index.d.ts +30 -0
  70. package/dist/tool/builtin/read.d.ts +127 -0
  71. package/dist/tool/builtin/skill.d.ts +111 -0
  72. package/dist/tool/builtin/task.d.ts +132 -0
  73. package/dist/tool/builtin/todoPlan.d.ts +52 -0
  74. package/dist/tool/builtin/todoWrite.d.ts +94 -0
  75. package/dist/tool/builtin/webFetch.d.ts +62 -0
  76. package/dist/tool/builtin/webSearch.d.ts +89 -0
  77. package/dist/tool/builtin/write.d.ts +103 -0
  78. package/dist/tool/index.d.ts +6 -0
  79. package/dist/tool/registry.d.ts +55 -0
  80. package/dist/tool/types.d.ts +107 -0
  81. package/dist/types/common.d.ts +53 -0
  82. package/dist/types/event.d.ts +217 -0
  83. package/dist/types/index.d.ts +4 -0
  84. package/dist/types/message.d.ts +44 -0
  85. package/dist/types/snapshot.d.ts +329 -0
  86. package/package.json +35 -28
@@ -0,0 +1,10 @@
1
+ import type { StateStore } from '../../state';
2
+ import type { AgentLoopCheckpoint } from '../../types';
3
+ export declare class CheckpointManager {
4
+ private readonly stateStore?;
5
+ constructor(stateStore?: StateStore | undefined);
6
+ hasStore(): boolean;
7
+ saveCheckpoint(checkpoint: AgentLoopCheckpoint): Promise<void>;
8
+ loadCheckpoint(sessionId: string): Promise<AgentLoopCheckpoint | undefined>;
9
+ clearCheckpoint(sessionId: string): Promise<void>;
10
+ }
@@ -0,0 +1,4 @@
1
+ export { BaseSession } from './base';
2
+ export { BaseSessionManager } from './manager';
3
+ export { Session } from './session';
4
+ export { StateStoreSessionManager } from './stateStoreSessionManager';
@@ -0,0 +1,35 @@
1
+ import type { Session } from './session';
2
+ /**
3
+ * Abstract base class for session management.
4
+ *
5
+ * Handles session lifecycle: creation, retrieval, listing, and destruction.
6
+ * Implement this class for different storage backends (e.g., Redis, SQLite, in-memory).
7
+ */
8
+ export declare abstract class BaseSessionManager {
9
+ /**
10
+ * Create a new session for an agent
11
+ *
12
+ * @param sessionId - Optional session ID to use. If not provided, a random UUID will be generated.
13
+ * @returns Newly created session
14
+ */
15
+ abstract create(sessionId?: string): Promise<Session>;
16
+ /**
17
+ * Get a session by ID
18
+ *
19
+ * @param sessionId - Session identifier
20
+ * @returns Session or undefined if not found
21
+ */
22
+ abstract get(sessionId: string): Promise<Session | undefined>;
23
+ /**
24
+ * List all sessions for an agent
25
+ *
26
+ * @returns Array of sessions belonging to the agent
27
+ */
28
+ abstract list(): Promise<Session[]>;
29
+ /**
30
+ * Destroy a session
31
+ *
32
+ * @param sessionId - Session identifier to destroy
33
+ */
34
+ abstract destroy(sessionId: string): Promise<void>;
35
+ }
@@ -0,0 +1,159 @@
1
+ import type { Middleware } from '../agent/middleware';
2
+ import type { AgentLoopState, CreateSessionOptions, SendOptions } from '../agent/types';
3
+ import type { ModelClient } from '../model';
4
+ import type { StateStore } from '../state';
5
+ import type { ToolApprovalResult, ToolRegistry } from '../tool';
6
+ import type { AgentEvent, Message, MessageContent, ModelConfig, SessionConfigOverride, SessionSnapshot, SessionStatus } from '../types';
7
+ import { EventEmitter } from 'node:events';
8
+ interface SessionRuntimeOptions extends CreateSessionOptions {
9
+ modelClient?: ModelClient;
10
+ systemPrompt?: string;
11
+ agentName?: string;
12
+ tools?: ToolRegistry;
13
+ middlewares?: Middleware<AgentLoopState>[];
14
+ onUsage?: (usage: {
15
+ promptTokens: number;
16
+ completionTokens: number;
17
+ totalTokens: number;
18
+ }) => void;
19
+ hasCheckpoint?: boolean;
20
+ emitSessionCreatedEvent?: boolean;
21
+ }
22
+ /**
23
+ * Concrete Session implementation that stores data in StateStore.
24
+ */
25
+ export declare class Session extends EventEmitter {
26
+ readonly id: string;
27
+ readonly createdAt: number;
28
+ status: SessionStatus;
29
+ title?: string;
30
+ updatedAt: number;
31
+ lastActiveAt: number;
32
+ errorMessage?: string;
33
+ configOverride?: SessionConfigOverride;
34
+ messages: Message[];
35
+ toolCallCount: number;
36
+ usage: {
37
+ promptTokens: number;
38
+ completionTokens: number;
39
+ totalTokens: number;
40
+ };
41
+ responseCount: number;
42
+ avgResponseTime?: number;
43
+ private readonly _stateStore;
44
+ private readonly _checkpointManager;
45
+ private readonly _approvalHandler;
46
+ private readonly _parallelTaskExecutor;
47
+ private readonly _toolExecutor;
48
+ private _autoSave;
49
+ private readonly _autoSaveManager;
50
+ private readonly _modelClient?;
51
+ private readonly _tools?;
52
+ private _middlewares;
53
+ private readonly _systemPrompt?;
54
+ private readonly _agentName?;
55
+ private readonly _onUsage?;
56
+ private _hasCheckpoint;
57
+ private _checkpointRestored;
58
+ private _pendingInput;
59
+ private _isReceiving;
60
+ private readonly _hooks?;
61
+ private _modelOverride?;
62
+ private readonly _maxIterations?;
63
+ private readonly _requestParams?;
64
+ private readonly _emitSessionCreatedEvent;
65
+ private _sessionCreatedEventEmitted;
66
+ private getDisabledToolNames;
67
+ private isToolDisabled;
68
+ private collectBlockedTools;
69
+ private isToolBlocked;
70
+ private getToolsForModel;
71
+ private getEffectiveSystemPrompt;
72
+ /**
73
+ * Create a new Session or load from StateStore.
74
+ *
75
+ * @param stateStore - StateStore instance for persistence
76
+ * @param sessionId - Session identifier
77
+ * @param snapshot - Optional snapshot to restore from (if not provided, will create new session)
78
+ */
79
+ constructor(stateStore: StateStore, sessionId: string, snapshot?: SessionSnapshot, options?: SessionRuntimeOptions);
80
+ get hasCheckpoint(): boolean;
81
+ send(input: MessageContent, options?: SendOptions): void;
82
+ receive(options?: SendOptions): AsyncIterable<AgentEvent>;
83
+ /**
84
+ * Convenience helper for "pause → decide → resume" flows.
85
+ *
86
+ * This merges `decisions` into `toolContext.approval.decisions` and resumes streaming.
87
+ */
88
+ receiveWithApprovals(decisions: Record<string, ToolApprovalResult>, options?: SendOptions): AsyncIterable<AgentEvent>;
89
+ private _stream;
90
+ private resolveModelRef;
91
+ private getRuntimeModelOverride;
92
+ private _ensureRuntimeConfigured;
93
+ private extractTextFromContent;
94
+ private createTitle;
95
+ private _recordUsage;
96
+ private executeModelStream;
97
+ private mergeStateResults;
98
+ private addToolResultToHistory;
99
+ private addAssistantMessageWithToolCalls;
100
+ private addFinalAssistantMessage;
101
+ private persistSessionState;
102
+ private _streamWithState;
103
+ /**
104
+ * Check if there's an assistant message containing the tool call
105
+ */
106
+ private hasAssistantToolCallMessage;
107
+ private handleFinalResponse;
108
+ private _finalizeRun;
109
+ /**
110
+ * Get preview of the last message (truncated for display)
111
+ *
112
+ * @param maxLength - Maximum length of preview
113
+ * @returns Preview string or undefined if no messages
114
+ */
115
+ getLastMessagePreview(maxLength?: number): string | undefined;
116
+ /**
117
+ * Create a snapshot of the session for persistence
118
+ *
119
+ * @returns Session snapshot
120
+ */
121
+ toSnapshot(): SessionSnapshot;
122
+ /**
123
+ * Restore session state from a snapshot
124
+ *
125
+ * @param snapshot - Session snapshot to restore from
126
+ */
127
+ restoreFromSnapshot(snapshot: SessionSnapshot): void;
128
+ /**
129
+ * Save session to StateStore.
130
+ */
131
+ save(): Promise<void>;
132
+ /**
133
+ * Load session from StateStore.
134
+ */
135
+ load(): Promise<boolean>;
136
+ private triggerAutoSave;
137
+ setStatus(status: SessionStatus, errorMessage?: string): void;
138
+ markActive(): void;
139
+ addMessage(message: Message): void;
140
+ addUsage(usage: {
141
+ promptTokens: number;
142
+ completionTokens: number;
143
+ totalTokens: number;
144
+ }): void;
145
+ recordResponse(durationMs: number): void;
146
+ incrementToolCallCount(): void;
147
+ setModelOverride(model: ModelConfig): void;
148
+ clearModelOverride(): void;
149
+ setSystemPromptOverride(systemPrompt: string): void;
150
+ clearSystemPromptOverride(): void;
151
+ disableTools(toolNames: string[]): void;
152
+ enableAllTools(): void;
153
+ setMiddlewares(middlewares: Middleware<AgentLoopState>[]): void;
154
+ /**
155
+ * Enable or disable auto-save.
156
+ */
157
+ setAutoSave(enabled: boolean): void;
158
+ }
159
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { StateStore } from '../state';
2
+ import { BaseSessionManager } from './manager';
3
+ import { Session } from './session';
4
+ /**
5
+ * SessionManager implementation using StateStore for persistence.
6
+ */
7
+ export declare class StateStoreSessionManager extends BaseSessionManager {
8
+ private readonly _stateStore;
9
+ constructor(stateStore: StateStore);
10
+ /**
11
+ * Create a new session for an agent.
12
+ *
13
+ * @param sessionId - Optional session ID to use. If not provided, a random UUID will be generated.
14
+ * @returns Newly created session
15
+ */
16
+ create(sessionId?: string): Promise<Session>;
17
+ /**
18
+ * Get a session by ID.
19
+ *
20
+ * @param sessionId - Session identifier
21
+ * @returns Session or undefined if not found
22
+ */
23
+ get(sessionId: string): Promise<Session | undefined>;
24
+ /**
25
+ * List all sessions for an agent.
26
+ *
27
+ * @returns Array of sessions belonging to the agent
28
+ */
29
+ list(): Promise<Session[]>;
30
+ /**
31
+ * Destroy a session.
32
+ *
33
+ * @param sessionId - Session identifier to destroy
34
+ */
35
+ destroy(sessionId: string): Promise<void>;
36
+ }
@@ -0,0 +1,7 @@
1
+ export declare class AsyncQueue<T> {
2
+ private readonly queue;
3
+ private readonly waiters;
4
+ enqueue(item: T): void;
5
+ isEmpty(): boolean;
6
+ dequeueOrWait(timeoutMs: number): Promise<T | undefined>;
7
+ }
@@ -0,0 +1,6 @@
1
+ export declare class AutoSaveManager {
2
+ private readonly saveHandler;
3
+ private readonly onError?;
4
+ constructor(saveHandler: () => Promise<void>, onError?: ((error: Error) => void) | undefined);
5
+ trigger(): Promise<void>;
6
+ }
@@ -0,0 +1,72 @@
1
+ import type { StateStoreOptions } from './types';
2
+ import { StateStore } from './stateStore';
3
+ /**
4
+ * Options for creating a FileStateStore.
5
+ */
6
+ export interface FileStateStoreOptions extends StateStoreOptions {
7
+ /**
8
+ * Directory path for storing state files.
9
+ */
10
+ dir: string;
11
+ }
12
+ /**
13
+ * File-based implementation of StateStore.
14
+ *
15
+ * Stores state data as JSON files in a directory structure organized by session:
16
+ *
17
+ * ```
18
+ * <baseDir>/
19
+ * <sessionId>/
20
+ * checkpoint.json
21
+ * compression.json
22
+ * session.json
23
+ * custom-key.json
24
+ * ```
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const store = new FileStateStore({
29
+ * dir: './state',
30
+ * savePoint: 'before',
31
+ * deleteOnComplete: true,
32
+ * })
33
+ *
34
+ * const agent = new Agent({
35
+ * name: 'MyAgent',
36
+ * stateStore: store,
37
+ * // ...
38
+ * })
39
+ * ```
40
+ */
41
+ export declare class FileStateStore extends StateStore {
42
+ private baseDir;
43
+ constructor(options: FileStateStoreOptions);
44
+ protected _write(storagePath: string, data: string): Promise<void>;
45
+ protected _read(storagePath: string): Promise<string | undefined>;
46
+ protected _delete(storagePath: string): Promise<void>;
47
+ protected _exists(storagePath: string): Promise<boolean>;
48
+ protected _list(prefix: string): Promise<string[]>;
49
+ /**
50
+ * Convert storage path to file system path.
51
+ * Storage path: `{sessionId}/{key}`
52
+ * File path: `{baseDir}/{sessionId}/{key}.json`
53
+ */
54
+ private toFilePath;
55
+ /**
56
+ * Ensure a directory exists.
57
+ */
58
+ private ensureDir;
59
+ /**
60
+ * List all JSON files in a directory.
61
+ */
62
+ private listJsonFiles;
63
+ /**
64
+ * Get the base directory path.
65
+ */
66
+ getBaseDir(): string;
67
+ /**
68
+ * Clear all state data from the store.
69
+ * WARNING: This will delete all files in the base directory.
70
+ */
71
+ clear(): void;
72
+ }
@@ -0,0 +1,46 @@
1
+ import type { StateStoreOptions } from './types';
2
+ import { StateStore } from './stateStore';
3
+ /**
4
+ * In-memory implementation of StateStore.
5
+ *
6
+ * Useful for development, testing, and short-lived applications.
7
+ * Data is lost when the process exits.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const store = new InMemoryStateStore({
12
+ * savePoint: 'before',
13
+ * deleteOnComplete: true,
14
+ * })
15
+ *
16
+ * const agent = new Agent({
17
+ * name: 'MyAgent',
18
+ * stateStore: store,
19
+ * // ...
20
+ * })
21
+ * ```
22
+ */
23
+ export declare class InMemoryStateStore extends StateStore {
24
+ /**
25
+ * Internal storage: path -> data
26
+ */
27
+ private store;
28
+ constructor(options?: StateStoreOptions);
29
+ protected _write(path: string, data: string): Promise<void>;
30
+ protected _read(path: string): Promise<string | undefined>;
31
+ protected _delete(path: string): Promise<void>;
32
+ protected _exists(path: string): Promise<boolean>;
33
+ protected _list(prefix: string): Promise<string[]>;
34
+ /**
35
+ * Clear all data from the store.
36
+ * Useful for testing.
37
+ */
38
+ clear(): void;
39
+ /**
40
+ * Get statistics about the store.
41
+ */
42
+ stats(): {
43
+ entryCount: number;
44
+ sessionCount: number;
45
+ };
46
+ }
@@ -0,0 +1,6 @@
1
+ export { FileStateStore } from './FileStateStore';
2
+ export type { FileStateStoreOptions } from './FileStateStore';
3
+ export { InMemoryStateStore } from './InMemoryStateStore';
4
+ export { StateStore } from './stateStore';
5
+ export type { CompressedMessagesSnapshot, CompressionState, StateKey, StateStoreOptions } from './types';
6
+ export { StateKeys } from './types';
@@ -0,0 +1,181 @@
1
+ import type { AgentLoopCheckpoint } from '../types';
2
+ import type { StateStoreOptions } from './types';
3
+ /**
4
+ * Abstract base class for state storage.
5
+ *
6
+ * StateStore provides a session-centric storage abstraction where all data
7
+ * is organized by sessionId. Each session can have multiple keys storing
8
+ * different types of data (checkpoint, compression state, session info, etc.).
9
+ *
10
+ * Subclasses only need to implement the low-level storage primitives:
11
+ * - _write: Write data to a path
12
+ * - _read: Read data from a path
13
+ * - _delete: Delete data at a path
14
+ * - _exists: Check if data exists at a path
15
+ * - _list: List all paths with a given prefix
16
+ *
17
+ * The base class provides:
18
+ * - High-level API for session-based storage (save, load, delete, etc.)
19
+ * - Convenience methods for checkpoint operations
20
+ * - JSON serialization/deserialization
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Using with an agent
25
+ * const store = new FileStateStore({ dir: './state' })
26
+ *
27
+ * const agent = new Agent({
28
+ * name: 'MyAgent',
29
+ * stateStore: store,
30
+ * // ...
31
+ * })
32
+ *
33
+ * // Manual state operations
34
+ * await store.save(sessionId, 'custom-key', { myData: 123 })
35
+ * const data = await store.load(sessionId, 'custom-key')
36
+ * ```
37
+ */
38
+ export declare abstract class StateStore {
39
+ /**
40
+ * When to save checkpoints during agent execution.
41
+ */
42
+ readonly savePoint: 'before' | 'after' | 'both';
43
+ /**
44
+ * Whether to delete checkpoint after successful completion.
45
+ */
46
+ readonly deleteOnComplete: boolean;
47
+ constructor(options?: StateStoreOptions);
48
+ protected assertValidStorageSegment(label: string, value: string): void;
49
+ /**
50
+ * Save data for a session under a specific key.
51
+ *
52
+ * @param sessionId - Session identifier
53
+ * @param key - Data key (e.g., 'checkpoint', 'compression', or custom keys)
54
+ * @param data - Data to save (will be JSON serialized)
55
+ */
56
+ save<T>(sessionId: string, key: string, data: T): Promise<void>;
57
+ /**
58
+ * Load data for a session by key.
59
+ *
60
+ * @param sessionId - Session identifier
61
+ * @param key - Data key
62
+ * @returns The data or undefined if not found
63
+ */
64
+ load<T>(sessionId: string, key: string): Promise<T | undefined>;
65
+ /**
66
+ * Delete data for a session by key.
67
+ *
68
+ * @param sessionId - Session identifier
69
+ * @param key - Data key
70
+ */
71
+ delete(sessionId: string, key: string): Promise<void>;
72
+ /**
73
+ * Delete all data for a session.
74
+ *
75
+ * @param sessionId - Session identifier
76
+ */
77
+ deleteSession(sessionId: string): Promise<void>;
78
+ /**
79
+ * List all keys for a session.
80
+ *
81
+ * @param sessionId - Session identifier
82
+ * @returns Array of keys
83
+ */
84
+ listKeys(sessionId: string): Promise<string[]>;
85
+ /**
86
+ * Check if data exists for a session key.
87
+ *
88
+ * @param sessionId - Session identifier
89
+ * @param key - Data key
90
+ * @returns True if data exists
91
+ */
92
+ exists(sessionId: string, key: string): Promise<boolean>;
93
+ /**
94
+ * Save an agent loop checkpoint.
95
+ *
96
+ * This is a convenience method that saves the checkpoint under the
97
+ * predefined CHECKPOINT key with additional metadata.
98
+ *
99
+ * @param checkpoint - Checkpoint to save
100
+ */
101
+ saveCheckpoint(checkpoint: AgentLoopCheckpoint): Promise<void>;
102
+ /**
103
+ * Load an agent loop checkpoint by session ID.
104
+ *
105
+ * @param sessionId - Session identifier
106
+ * @returns Checkpoint or undefined if not found
107
+ */
108
+ loadCheckpoint(sessionId: string): Promise<AgentLoopCheckpoint | undefined>;
109
+ /**
110
+ * Delete an agent loop checkpoint.
111
+ *
112
+ * @param sessionId - Session identifier
113
+ */
114
+ deleteCheckpoint(sessionId: string): Promise<void>;
115
+ /**
116
+ * List all checkpoints across all sessions.
117
+ *
118
+ * @returns Array of checkpoints
119
+ */
120
+ listCheckpoints(): Promise<AgentLoopCheckpoint[]>;
121
+ /**
122
+ * List all session IDs that have stored data.
123
+ *
124
+ * @returns Array of session IDs
125
+ */
126
+ listSessions(): Promise<string[]>;
127
+ /**
128
+ * Build a storage path from sessionId and key.
129
+ * Default format: `{sessionId}/{key}`
130
+ *
131
+ * Subclasses can override this for different path formats.
132
+ */
133
+ protected buildPath(sessionId: string, key: string): string;
134
+ /**
135
+ * Build a prefix for listing all data under a session.
136
+ * Default format: `{sessionId}/`
137
+ */
138
+ protected buildPrefix(sessionId: string): string;
139
+ /**
140
+ * Extract the key from a full path.
141
+ */
142
+ protected extractKey(sessionId: string, path: string): string;
143
+ /**
144
+ * Extract the sessionId from a full path.
145
+ */
146
+ protected extractSessionId(path: string): string | undefined;
147
+ /**
148
+ * Write data to a storage path.
149
+ *
150
+ * @param path - Storage path
151
+ * @param data - Serialized data string
152
+ */
153
+ protected abstract _write(path: string, data: string): Promise<void>;
154
+ /**
155
+ * Read data from a storage path.
156
+ *
157
+ * @param path - Storage path
158
+ * @returns Data string or undefined if not found
159
+ */
160
+ protected abstract _read(path: string): Promise<string | undefined>;
161
+ /**
162
+ * Delete data at a storage path.
163
+ *
164
+ * @param path - Storage path
165
+ */
166
+ protected abstract _delete(path: string): Promise<void>;
167
+ /**
168
+ * Check if data exists at a storage path.
169
+ *
170
+ * @param path - Storage path
171
+ * @returns True if data exists
172
+ */
173
+ protected abstract _exists(path: string): Promise<boolean>;
174
+ /**
175
+ * List all paths with a given prefix.
176
+ *
177
+ * @param prefix - Path prefix (empty string for all paths)
178
+ * @returns Array of full paths
179
+ */
180
+ protected abstract _list(prefix: string): Promise<string[]>;
181
+ }
@@ -0,0 +1,85 @@
1
+ import type { CompressionStats } from '../middleware/contextCompressionMiddleware';
2
+ import type { MessageContent } from '../types';
3
+ /**
4
+ * State store configuration options.
5
+ */
6
+ export interface StateStoreOptions {
7
+ /**
8
+ * When to save checkpoints:
9
+ * - 'before': Save before each iteration (default)
10
+ * - 'after': Save after each iteration
11
+ * - 'both': Save before and after
12
+ */
13
+ savePoint?: 'before' | 'after' | 'both';
14
+ /**
15
+ * Whether to delete the checkpoint after successful completion.
16
+ * Default: true
17
+ */
18
+ deleteOnComplete?: boolean;
19
+ }
20
+ /**
21
+ * Predefined state keys for common data types.
22
+ */
23
+ export declare const StateKeys: {
24
+ /** AgentLoopCheckpoint data */
25
+ readonly CHECKPOINT: "checkpoint";
26
+ /** CompressionState data */
27
+ readonly COMPRESSION: "compression";
28
+ /** SessionSnapshot data */
29
+ readonly SESSION: "session";
30
+ /**
31
+ * Compressed messages snapshot key pattern.
32
+ * Use with timestamp: `compression-snapshot-${timestamp}`
33
+ */
34
+ readonly COMPRESSION_SNAPSHOT: "compression-snapshot";
35
+ };
36
+ export type StateKey = (typeof StateKeys)[keyof typeof StateKeys];
37
+ /**
38
+ * Compressed messages snapshot.
39
+ * Stores the compressed messages after a compression operation.
40
+ */
41
+ export interface CompressedMessagesSnapshot {
42
+ /**
43
+ * Compressed messages after compression.
44
+ */
45
+ messages: Array<{
46
+ role: string;
47
+ content: MessageContent;
48
+ tool_call_id?: string;
49
+ name?: string;
50
+ tool_calls?: unknown[];
51
+ }>;
52
+ /**
53
+ * Compression statistics.
54
+ */
55
+ stats: CompressionStats;
56
+ /**
57
+ * Timestamp when this compression occurred (ms).
58
+ */
59
+ timestamp: number;
60
+ }
61
+ /**
62
+ * Compression state for context compression middleware.
63
+ *
64
+ * This stores all compression-related data for a session,
65
+ * allowing the middleware to restore its state after a restart.
66
+ */
67
+ export interface CompressionState {
68
+ /**
69
+ * Statistics from the last compression operation.
70
+ */
71
+ lastStats?: CompressionStats;
72
+ /**
73
+ * History of all compression operations.
74
+ */
75
+ history: CompressionStats[];
76
+ /**
77
+ * Rolling summary content from summarized messages.
78
+ * This can be used when resuming from a checkpoint to provide context.
79
+ */
80
+ summary?: string;
81
+ /**
82
+ * Last update timestamp (ms).
83
+ */
84
+ updatedAt: number;
85
+ }
@@ -0,0 +1,16 @@
1
+ import type { SubagentDefinition } from '../tool/builtin/task';
2
+ /**
3
+ * System prompt for File Search Specialist
4
+ *
5
+ * Based on the configuration from subagent_file.json, this prompt
6
+ * defines the specialist's role, capabilities, and guidelines.
7
+ */
8
+ export declare function buildFileSearchSpecialistPrompt(cwd: string, now?: Date): string;
9
+ export declare const fileSearchSpecialistPrompt: string;
10
+ /**
11
+ * File Search Specialist Subagent Definition
12
+ *
13
+ * This subagent specializes in navigating and exploring codebases,
14
+ * finding files, searching content, and analyzing file structures.
15
+ */
16
+ export declare const fileSearchSpecialist: SubagentDefinition;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Subagent Definitions
3
+ *
4
+ * This module exports predefined subagent configurations
5
+ * that can be used with the parallel subagent middleware.
6
+ */
7
+ export * from './file-search-specialist';