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,329 @@
1
+ import type { ToolCallWithResult } from '../agent/types';
2
+ import type { ModelStopReason } from '../model/types';
3
+ import type { Usage } from './common';
4
+ import type { Message } from './message';
5
+ /**
6
+ * Model configuration for snapshots (serializable)
7
+ */
8
+ export interface ModelConfig {
9
+ /**
10
+ * Model identifier (e.g., "gpt-4o", "claude-3-opus")
11
+ */
12
+ modelId: string;
13
+ /**
14
+ * Provider name (e.g., "openai", "anthropic")
15
+ */
16
+ provider?: string;
17
+ /**
18
+ * Model-specific configuration
19
+ */
20
+ config?: Record<string, unknown>;
21
+ }
22
+ /**
23
+ * Agent configuration (mutable settings)
24
+ */
25
+ export interface AgentConfig {
26
+ /**
27
+ * System prompt that defines the agent's behavior
28
+ */
29
+ systemPrompt: string;
30
+ /**
31
+ * Current model configuration
32
+ */
33
+ model: ModelConfig;
34
+ /**
35
+ * List of registered tool names
36
+ */
37
+ tools: string[];
38
+ }
39
+ /**
40
+ * Agent runtime statistics
41
+ */
42
+ export interface AgentStats {
43
+ /**
44
+ * Last update timestamp (ms)
45
+ */
46
+ updatedAt: number;
47
+ /**
48
+ * Total number of sessions ever created
49
+ */
50
+ totalSessions: number;
51
+ /**
52
+ * Number of currently active sessions
53
+ */
54
+ activeSessions: number;
55
+ }
56
+ /**
57
+ * Complete Agent snapshot for serialization/persistence
58
+ */
59
+ export interface AgentSnapshot {
60
+ /**
61
+ * Unique agent identifier
62
+ */
63
+ id: string;
64
+ /**
65
+ * Human-readable name
66
+ */
67
+ name: string;
68
+ /**
69
+ * Creation timestamp (ms)
70
+ */
71
+ createdAt: number;
72
+ /**
73
+ * Agent configuration
74
+ */
75
+ config: AgentConfig;
76
+ /**
77
+ * Runtime statistics
78
+ */
79
+ stats: AgentStats;
80
+ /**
81
+ * User-defined metadata
82
+ */
83
+ metadata?: Record<string, unknown>;
84
+ }
85
+ /**
86
+ * Session status
87
+ */
88
+ export type SessionStatus = 'active' | 'paused' | 'completed' | 'error' | 'archived';
89
+ /**
90
+ * Session state information
91
+ */
92
+ export interface SessionState {
93
+ /**
94
+ * Current session status
95
+ */
96
+ status: SessionStatus;
97
+ /**
98
+ * Last update timestamp (ms)
99
+ */
100
+ updatedAt: number;
101
+ /**
102
+ * Last activity timestamp (ms)
103
+ */
104
+ lastActiveAt: number;
105
+ /**
106
+ * User-defined session title
107
+ */
108
+ title?: string;
109
+ /**
110
+ * Error message if status is 'error'
111
+ */
112
+ errorMessage?: string;
113
+ }
114
+ /**
115
+ * Session-level configuration overrides
116
+ * These override the parent agent's configuration for this session only
117
+ */
118
+ export interface SessionConfigOverride {
119
+ /**
120
+ * Override model for this session
121
+ */
122
+ model?: ModelConfig;
123
+ /**
124
+ * Override system prompt for this session
125
+ */
126
+ systemPromptOverride?: string;
127
+ /**
128
+ * Tools to disable for this session
129
+ */
130
+ disabledTools?: string[];
131
+ }
132
+ /**
133
+ * Conversation context containing message history
134
+ */
135
+ export interface ConversationContext {
136
+ /**
137
+ * Full message history
138
+ */
139
+ messages: Message[];
140
+ /**
141
+ * Total message count
142
+ */
143
+ messageCount: number;
144
+ /**
145
+ * Preview of the last message (for list display)
146
+ */
147
+ lastMessagePreview?: string;
148
+ /**
149
+ * Number of tool calls made in this session
150
+ */
151
+ toolCallCount: number;
152
+ }
153
+ /**
154
+ * Session usage statistics
155
+ */
156
+ export interface SessionStats {
157
+ /**
158
+ * Token usage for this session
159
+ */
160
+ usage: {
161
+ promptTokens: number;
162
+ completionTokens: number;
163
+ totalTokens: number;
164
+ };
165
+ /**
166
+ * Number of assistant responses
167
+ */
168
+ responseCount: number;
169
+ /**
170
+ * Average response time in milliseconds
171
+ */
172
+ avgResponseTime?: number;
173
+ }
174
+ /**
175
+ * Complete Session snapshot for serialization/persistence
176
+ */
177
+ export interface SessionSnapshot {
178
+ /**
179
+ * Unique session identifier
180
+ */
181
+ id: string;
182
+ /**
183
+ * Creation timestamp (ms)
184
+ */
185
+ createdAt: number;
186
+ /**
187
+ * Session state information
188
+ */
189
+ state: SessionState;
190
+ /**
191
+ * Session-level configuration overrides
192
+ */
193
+ configOverride?: SessionConfigOverride;
194
+ /**
195
+ * Conversation context with message history
196
+ */
197
+ context: ConversationContext;
198
+ /**
199
+ * Usage statistics
200
+ */
201
+ stats: SessionStats;
202
+ /**
203
+ * User-defined metadata
204
+ */
205
+ metadata?: Record<string, unknown>;
206
+ }
207
+ /**
208
+ * Model configuration stored in checkpoint (serializable)
209
+ */
210
+ export interface CheckpointModelConfig {
211
+ /**
212
+ * Model identifier (e.g., "gpt-4o", "claude-3-opus")
213
+ */
214
+ modelId: string;
215
+ /**
216
+ * Provider name (e.g., "openai", "anthropic")
217
+ */
218
+ provider?: string;
219
+ /**
220
+ * Model-specific configuration
221
+ */
222
+ config?: Record<string, unknown>;
223
+ }
224
+ /**
225
+ * Request parameters stored in checkpoint
226
+ */
227
+ export interface CheckpointRequestParams {
228
+ /**
229
+ * Temperature for response randomness
230
+ */
231
+ temperature?: number;
232
+ /**
233
+ * Maximum tokens to generate
234
+ */
235
+ maxTokens?: number;
236
+ /**
237
+ * Stop sequences
238
+ */
239
+ stop?: string[];
240
+ /**
241
+ * Additional model-specific parameters
242
+ */
243
+ [key: string]: unknown;
244
+ }
245
+ /**
246
+ * Checkpoint of AgentLoopState for persistence and resumption.
247
+ *
248
+ * This captures the complete runtime state of an agent loop execution,
249
+ * allowing it to be saved and restored for:
250
+ * - Resuming interrupted executions
251
+ * - Debugging and inspection
252
+ * - Audit logging
253
+ */
254
+ export interface AgentLoopCheckpoint {
255
+ /**
256
+ * Schema version for this checkpoint payload.
257
+ *
258
+ * When absent, treat as version 1 (legacy checkpoints).
259
+ */
260
+ schemaVersion?: number;
261
+ /**
262
+ * Session ID for this execution
263
+ */
264
+ sessionId: string;
265
+ /**
266
+ * Agent name (for display purposes)
267
+ */
268
+ agentName?: string;
269
+ /**
270
+ * Current loop iteration (0-indexed)
271
+ */
272
+ iteration: number;
273
+ /**
274
+ * Current phase of execution
275
+ */
276
+ phase?: 'llm_call' | 'tool_execution' | 'approval_pending' | 'completed';
277
+ /**
278
+ * Current status description (human readable)
279
+ */
280
+ status?: string;
281
+ /**
282
+ * Model configuration at checkpoint time
283
+ */
284
+ modelConfig?: CheckpointModelConfig;
285
+ /**
286
+ * Model request parameters at checkpoint time
287
+ */
288
+ requestParams?: CheckpointRequestParams;
289
+ /**
290
+ * Full message history
291
+ */
292
+ messages: Message[];
293
+ /**
294
+ * Pending tool calls (serialized)
295
+ */
296
+ pendingToolCalls: ToolCallWithResult[];
297
+ /**
298
+ * Text response accumulated so far
299
+ */
300
+ currentResponse: string;
301
+ /**
302
+ * Thinking/reasoning content (if any)
303
+ */
304
+ currentThinking?: string;
305
+ /**
306
+ * Whether the loop should continue
307
+ */
308
+ shouldContinue: boolean;
309
+ /**
310
+ * Stop reason (if stopped)
311
+ */
312
+ stopReason?: 'max_iterations' | 'final_response' | 'error' | 'cancelled' | 'approval_required';
313
+ /**
314
+ * Stop reason reported by the last model call (if available).
315
+ */
316
+ lastModelStopReason?: ModelStopReason;
317
+ /**
318
+ * Cumulative token usage
319
+ */
320
+ usage: Usage;
321
+ /**
322
+ * Custom metadata
323
+ */
324
+ metadata: Record<string, unknown>;
325
+ /**
326
+ * Timestamp when this checkpoint was saved (ms)
327
+ */
328
+ savedAt: number;
329
+ }
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "goatchain",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
+ "workspaces": [
6
+ "packages/*"
7
+ ],
5
8
  "description": "",
6
9
  "author": "Simon He",
7
10
  "license": "MIT",
@@ -14,10 +17,36 @@
14
17
  "engines": {
15
18
  "node": ">=18"
16
19
  },
20
+ "scripts": {
21
+ "build": "rm -rf dist && bun build src/index.ts --outdir dist --target bun --format esm --minify --external @ast-grep/napi && tsc --project tsconfig.build.json",
22
+ "dev": "tsc --watch",
23
+ "typecheck": "tsc --noEmit",
24
+ "lint": "eslint --no-error-on-unmatched-pattern src/**/*.ts examples/**/*.ts test/**/*.ts packages/cli/src/**/*.ts",
25
+ "lint:fix": "eslint --no-error-on-unmatched-pattern src/**/*.ts examples/**/*.ts test/**/*.ts packages/cli/src/**/*.ts --fix",
26
+ "format": "eslint --fix --no-error-on-unmatched-pattern \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" && prettier --cache --write \"**/*.{json,md,yaml,yml}\"",
27
+ "prettier": "prettier --write \"src/**/*.{ts,js,json,md}\" \"examples/**/*.{ts,js,json,md}\" \"packages/cli/src/**/*.{ts,js,json,md}\"",
28
+ "prettier:check": "prettier --check \"src/**/*.{ts,js,json,md}\" \"examples/**/*.{ts,js,json,md}\" \"packages/cli/src/**/*.{ts,js,json,md}\"",
29
+ "test": "bun test",
30
+ "test:serial": "bun run --filter '*' build && bun test",
31
+ "test:integration": "GOATCHAIN_RUN_INTEGRATION=1 bun run --filter '*' build && bun test",
32
+ "start": "bun run dist/index.js",
33
+ "prepack": "bun run build",
34
+ "build:all": "bun run build && bun run --filter '*' build && bun run --filter '*' build --binary",
35
+ "cli": "cd packages/cli && bun run cli",
36
+ "cli:smoke": "cd packages/cli && bun run smoke",
37
+ "cli:publish": "cd packages/cli && bun publish",
38
+ "acp-server": "bun run src/acp-server.ts",
39
+ "release": "bumpp --commit --no-tag --no-push && bun run build && bun publish"
40
+ },
17
41
  "dependencies": {
18
- "@anthropic-ai/claude-agent-sdk": "^0.1.76",
42
+ "@agentclientprotocol/sdk": "^0.12.0",
43
+ "@ast-grep/cli": "^0.40.4",
44
+ "@ast-grep/napi": "^0.40.4",
19
45
  "@modelcontextprotocol/sdk": "^1.17.3",
46
+ "@types/picomatch": "^4.0.2",
47
+ "fast-glob": "^3.3.3",
20
48
  "openai": "^6.9.1",
49
+ "picomatch": "^4.0.3",
21
50
  "tiktoken": "^1.0.22"
22
51
  },
23
52
  "devDependencies": {
@@ -28,38 +57,16 @@
28
57
  "@sxzz/prettier-config": "^2.2.6",
29
58
  "@tsconfig/recommended": "^1.0.10",
30
59
  "@types/node": "^22.13.5",
31
- "@vitest/ui": "^2.1.8",
32
60
  "bumpp": "^10.3.2",
61
+ "bun-types": "latest",
33
62
  "chokidar": "^4.0.1",
34
63
  "dotenv": "^17.2.1",
35
64
  "eslint": "^9.19.0",
36
65
  "picocolors": "^1.1.1",
37
66
  "prettier": "^3.6.2",
38
- "tsdown": "^0.15.12",
39
67
  "tsx": "^4.20.5",
40
68
  "typescript": "^5.9.2",
41
- "typescript-eslint": "^8.22.0",
42
- "vitest": "^4.0.16"
69
+ "typescript-eslint": "^8.22.0"
43
70
  },
44
- "prettier": "@sxzz/prettier-config",
45
- "scripts": {
46
- "build": "tsdown --minify --format esm",
47
- "dev": "tsc --watch",
48
- "typecheck": "tsc --noEmit",
49
- "lint": "eslint --no-error-on-unmatched-pattern src/**/*.ts examples/**/*.ts test/**/*.ts",
50
- "lint:fix": "eslint --no-error-on-unmatched-pattern src/**/*.ts examples/**/*.ts test/**/*.ts --fix",
51
- "format": "eslint --fix --no-error-on-unmatched-pattern \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" && prettier --cache --write \"**/*.{json,md,yaml,yml}\"",
52
- "prettier": "prettier --write \"src/**/*.{ts,js,json,md}\" \"examples/**/*.{ts,js,json,md}\" \"packages/cli/src/**/*.{ts,js,json,md}\"",
53
- "prettier:check": "prettier --check \"src/**/*.{ts,js,json,md}\" \"examples/**/*.{ts,js,json,md}\" \"packages/cli/src/**/*.{ts,js,json,md}\"",
54
- "test": "pnpm -r -s build && vitest run",
55
- "start": "node dist/index.js",
56
- "build:all": "pnpm -r -s build",
57
- "cli": "pnpm -C packages/cli -s cli",
58
- "cli:smoke": "pnpm -C packages/cli -s smoke",
59
- "cli:publish": "pnpm -C packages/cli publish",
60
- "slides:gen": "node scripts/gen-slidev-readme.mjs",
61
- "slides:dev": "pnpm -s slides:gen && slidev slides/README.slides.md",
62
- "slides:build": "pnpm -s slides:gen && slidev build slides/README.slides.md --out dist/slides",
63
- "slides:export": "pnpm -s slides:gen && slidev export slides/README.slides.md --output dist/agent-loop-readme.pdf"
64
- }
65
- }
71
+ "prettier": "@sxzz/prettier-config"
72
+ }