goatchain 0.0.7 → 0.0.9
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 +34 -62
- package/README.zh.md +39 -0
- package/dist/acp-adapter/types.d.ts +1 -0
- package/dist/agent/agent.d.ts +25 -11
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/middleware.d.ts +3 -1
- package/dist/agent/types.d.ts +13 -6
- package/dist/index.d.ts +9 -2
- package/dist/index.js +223 -228
- package/dist/middleware/agentRulesMiddleware.d.ts +58 -0
- package/dist/middleware/checkpointMiddleware.d.ts +19 -0
- package/dist/middleware/contextCompressionMiddleware.d.ts +15 -3
- package/dist/middleware/envInfoMiddleware.d.ts +75 -0
- package/dist/middleware/skillsMiddleware.d.ts +152 -0
- package/dist/middleware/utils.d.ts +79 -0
- package/dist/model/createModel.d.ts +4 -70
- package/dist/model/index.d.ts +1 -1
- package/dist/model/types.d.ts +1 -7
- package/dist/session/executors/ToolExecutor.d.ts +2 -0
- package/dist/session/session.d.ts +32 -1
- package/dist/state/FileStateStore.d.ts +0 -1
- package/dist/state/InMemoryStateStore.d.ts +0 -1
- package/dist/state/stateStore.d.ts +0 -4
- package/dist/state/types.d.ts +0 -7
- package/dist/tool/builtin/edit.d.ts +5 -1
- package/dist/tool/builtin/read.d.ts +1 -1
- package/dist/tool/builtin/skill.d.ts +11 -17
- package/dist/tool/builtin/write.d.ts +1 -1
- package/package.json +24 -9
- package/dist/model/health.d.ts +0 -35
- package/dist/model/router.d.ts +0 -17
package/README.md
CHANGED
|
@@ -62,77 +62,51 @@ for await (const event of session.receive()) {
|
|
|
62
62
|
|
|
63
63
|
## 🧰 CLI
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
GoatChain CLI is a terminal UI (TUI) built on `@simon_he/vue-tui`.
|
|
66
|
+
|
|
67
|
+
### Installation
|
|
68
|
+
|
|
69
|
+
**Global installation (recommended):**
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm install -g goatchain-cli@latest
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Or use npx without installation:**
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
npx goatchain-cli@latest
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Usage
|
|
82
|
+
|
|
83
|
+
After installation, simply run:
|
|
66
84
|
|
|
67
85
|
```bash
|
|
68
86
|
goatchain
|
|
69
87
|
```
|
|
70
88
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
- `/set <k> <v>` set request params (e.g. `temperature`, `maxTokens`)
|
|
86
|
-
- `/unset <k>` clear a request param
|
|
87
|
-
- `/params` show current request params
|
|
88
|
-
- `/base-url <url>` set base URL
|
|
89
|
-
- `/api-key <key>` set API key (not printed)
|
|
90
|
-
- `/web-search-key <key>` set Serper API key for WebSearch tool (not printed)
|
|
91
|
-
- `/tools` list enabled tools (Read/Write/Edit/Glob/Grep/WebSearch*)
|
|
92
|
-
- `/sessions` list and pick a saved session
|
|
93
|
-
- `/use <sessionId>` restore a saved session (prints recent history)
|
|
94
|
-
- `/save` persist current config/session
|
|
95
|
-
- `/status` show current model/session info
|
|
96
|
-
- `/new` start a new conversation (clears history)
|
|
97
|
-
|
|
98
|
-
Requires `OPENAI_API_KEY` in the environment.
|
|
99
|
-
|
|
100
|
-
Web search (optional):
|
|
101
|
-
|
|
102
|
-
- Set `SERPER_API_KEY` (or `GOATCHAIN_SERPER_API_KEY`) to enable the builtin `WebSearch` tool for up-to-date info like weather.
|
|
103
|
-
- In interactive mode, you can also run `/web-search-key <key>` to persist the key into the workspace config.
|
|
104
|
-
- You can also set it in `./.goatchain/config.json` (workspace-scoped, gitignored):
|
|
105
|
-
- `{"tools":{"webSearch":{"apiKey":"...","apiEndpoint":"...","numResults":10}}}`
|
|
106
|
-
|
|
107
|
-
Plan mode (interactive planning):
|
|
108
|
-
|
|
109
|
-
- Enable with `/plan on` to enter a plan-first workflow:
|
|
110
|
-
1. Agent explores the codebase and researches your request
|
|
111
|
-
2. Agent may ask clarifying questions using the `AskUserQuestion` tool to understand your preferences (e.g., library choices, architectural decisions)
|
|
112
|
-
3. Agent creates a structured plan using `TodoPlan` (3-8 steps)
|
|
113
|
-
4. You review and approve the plan
|
|
114
|
-
5. Agent executes the approved plan
|
|
115
|
-
- During planning, file modifications are blocked (read-only phase)
|
|
116
|
-
- Set `GOATCHAIN_PLAN_MODE=1` or configure in `.goatchain/config.json` to enable by default
|
|
117
|
-
|
|
118
|
-
Local persistence (workspace-scoped):
|
|
119
|
-
|
|
120
|
-
- Config and sessions are saved under `./.goatchain/` (auto-created).
|
|
121
|
-
- `.goatchain/` is gitignored to avoid accidentally committing secrets.
|
|
122
|
-
|
|
123
|
-
DeepSeek thinking mode compatibility:
|
|
124
|
-
|
|
125
|
-
- Some OpenAI-compatible gateways (e.g. DeepSeek thinking mode) require `reasoning_content` to be present on assistant messages that contain `tool_calls` (and may reject empty strings). GoatChain will attach the accumulated thinking content when available.
|
|
126
|
-
- If you use DeepSeek via a proxy where GoatChain can't detect it from `baseUrl`/`modelId`, you can enable this explicitly:
|
|
127
|
-
- Interactive: Run `/settings` and toggle "Interleaved Thinking"
|
|
128
|
-
- Config file: Set `openai.compat.interleavedThinking=true` in `./.goatchain/config.json`
|
|
89
|
+
Inside the TUI:
|
|
90
|
+
|
|
91
|
+
- `Ctrl+P` opens the command palette (Sessions / New Session / Settings / Tool Approvals; Chat also has Theme)
|
|
92
|
+
- Slash commands in the input: `/settings`, `/approvals`, `/sessions`, `/new` (Chat also supports `/redo`)
|
|
93
|
+
|
|
94
|
+
### Development
|
|
95
|
+
|
|
96
|
+
Run it from this repo:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
bun run cli
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See `docs/cli.md` for the full feature list and flowcharts.
|
|
129
103
|
|
|
130
104
|
## 🔌 ACP Server
|
|
131
105
|
|
|
132
106
|
GoatChain can be exposed as an ACP (Agent Client Protocol) server for integration with editors like Zed.
|
|
133
107
|
|
|
134
108
|
```bash
|
|
135
|
-
|
|
109
|
+
bun run acp-server
|
|
136
110
|
```
|
|
137
111
|
|
|
138
112
|
**Configuration for Zed** (`settings.json`):
|
|
@@ -190,7 +164,6 @@ classDiagram
|
|
|
190
164
|
|
|
191
165
|
class StateStore {
|
|
192
166
|
<<interface>>
|
|
193
|
-
+savePoint: string
|
|
194
167
|
+deleteOnComplete: boolean
|
|
195
168
|
+saveCheckpoint(checkpoint): Promise~void~
|
|
196
169
|
+loadCheckpoint(sessionId): Promise~AgentLoopCheckpoint~
|
|
@@ -404,7 +377,6 @@ import { Agent, FileStateStore } from 'goatchain'
|
|
|
404
377
|
// Create state store with configuration
|
|
405
378
|
const stateStore = new FileStateStore({
|
|
406
379
|
dir: './checkpoints',
|
|
407
|
-
savePoint: 'before', // Save before each iteration
|
|
408
380
|
deleteOnComplete: true, // Clean up after successful completion
|
|
409
381
|
})
|
|
410
382
|
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# GoatChain(中文)
|
|
2
|
+
|
|
3
|
+
GoatChain 是一个轻量、可扩展的 TypeScript Agent SDK,包含一个基于终端 UI 的 CLI(TUI)。
|
|
4
|
+
|
|
5
|
+
- CLI(TUI)能力说明与流程图:`docs/cli.md`
|
|
6
|
+
- 英文 README:`README.md`
|
|
7
|
+
|
|
8
|
+
## CLI 安装和使用
|
|
9
|
+
|
|
10
|
+
### 安装
|
|
11
|
+
|
|
12
|
+
**全局安装(推荐):**
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g goatchain-cli@latest
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**或使用 npx(无需安装):**
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx goatchain-cli@latest
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 使用
|
|
25
|
+
|
|
26
|
+
安装完成后,直接运行:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
goatchain
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### TUI 快捷键
|
|
33
|
+
|
|
34
|
+
- `Ctrl+P` 打开命令面板(会话 / 新建会话 / 设置 / 工具批准;聊天界面还有主题)
|
|
35
|
+
- 输入框中的斜杠命令:`/settings`、`/approvals`、`/sessions`、`/new`(聊天界面还支持 `/redo`)
|
|
36
|
+
|
|
37
|
+
详细功能列表和流程图请查看 [docs/cli.md](./docs/cli.md)。
|
|
38
|
+
|
|
39
|
+
|
package/dist/agent/agent.d.ts
CHANGED
|
@@ -26,7 +26,25 @@ export declare class Agent {
|
|
|
26
26
|
private _middlewares;
|
|
27
27
|
private _middlewareCounter;
|
|
28
28
|
private _middlewareTools;
|
|
29
|
+
private _enableLogging;
|
|
30
|
+
private _initializationPromise;
|
|
31
|
+
private _initialized;
|
|
29
32
|
constructor(options: AgentOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Initialize middleware asynchronously (internal helper for constructor)
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private _initializeMiddleware;
|
|
38
|
+
/**
|
|
39
|
+
* Ensure agent is initialized (all middleware registered)
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private _ensureInitialized;
|
|
43
|
+
/**
|
|
44
|
+
* Internal logging method
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
private _log;
|
|
30
48
|
/**
|
|
31
49
|
* Get the model client
|
|
32
50
|
*/
|
|
@@ -42,10 +60,6 @@ export declare class Agent {
|
|
|
42
60
|
* - Otherwise, returns the model client's default `modelRef` (if supported).
|
|
43
61
|
*/
|
|
44
62
|
get modelRef(): ModelRef | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Get the available model references (e.g. routing fallback order), if supported by the model client.
|
|
47
|
-
*/
|
|
48
|
-
get modelRefs(): ModelRef[];
|
|
49
63
|
/**
|
|
50
64
|
* Get the tool registry
|
|
51
65
|
*/
|
|
@@ -85,7 +99,7 @@ export declare class Agent {
|
|
|
85
99
|
* @example
|
|
86
100
|
* ```ts
|
|
87
101
|
* // Named middleware (recommended)
|
|
88
|
-
* agent.use(async (state, next) => {
|
|
102
|
+
* await agent.use(async (state, next) => {
|
|
89
103
|
* console.log('Before iteration', state.iteration);
|
|
90
104
|
* const result = await next(state);
|
|
91
105
|
* console.log('After iteration', state.iteration);
|
|
@@ -93,20 +107,20 @@ export declare class Agent {
|
|
|
93
107
|
* }, 'logging');
|
|
94
108
|
*
|
|
95
109
|
* // Built-in middleware with default name
|
|
96
|
-
* agent.use(createContextCompressionMiddleware({ ... })); // auto-named 'context-compression'
|
|
110
|
+
* await agent.use(createContextCompressionMiddleware({ ... })); // auto-named 'context-compression'
|
|
97
111
|
*
|
|
98
112
|
* // Override default name
|
|
99
|
-
* agent.use(createPlanModeMiddleware(), 'my-plan-mode');
|
|
113
|
+
* await agent.use(createPlanModeMiddleware(), 'my-plan-mode');
|
|
100
114
|
*
|
|
101
115
|
* // Middleware with tools (auto-registers tools with namespace)
|
|
102
116
|
* const middleware: Middleware = async (state, next) => next(state);
|
|
103
117
|
* middleware.__middlewareName = 'plan-mode';
|
|
104
|
-
* middleware.__createTools = () => [new EnterPlanModeTool()];
|
|
105
|
-
* agent.use(middleware);
|
|
118
|
+
* middleware.__createTools = async () => [new EnterPlanModeTool()];
|
|
119
|
+
* await agent.use(middleware);
|
|
106
120
|
* // Tool registered as: 'plan-mode_EnterPlanMode'
|
|
107
121
|
*
|
|
108
122
|
* // Anonymous middleware (auto-named)
|
|
109
|
-
* const unsubscribe = agent.use(async (state, next) => {
|
|
123
|
+
* const unsubscribe = await agent.use(async (state, next) => {
|
|
110
124
|
* const compressed = { ...state, messages: compress(state.messages) };
|
|
111
125
|
* return next(compressed);
|
|
112
126
|
* });
|
|
@@ -115,7 +129,7 @@ export declare class Agent {
|
|
|
115
129
|
* unsubscribe();
|
|
116
130
|
* ```
|
|
117
131
|
*/
|
|
118
|
-
use(fn: Middleware<AgentLoopState>, name?: string): () => void
|
|
132
|
+
use(fn: Middleware<AgentLoopState>, name?: string): Promise<() => void>;
|
|
119
133
|
/**
|
|
120
134
|
* Remove a specific middleware from the agent by name or function reference.
|
|
121
135
|
*
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { fromLoopCheckpoint, toLoopCheckpoint } from '../middleware/checkpointMiddleware';
|
|
1
|
+
export { extractPersistentMetadata, extractPersistentState, fromLoopCheckpoint, toLoopCheckpoint, } from '../middleware/checkpointMiddleware';
|
|
2
2
|
export type { ToCheckpointOptions } from '../middleware/checkpointMiddleware';
|
|
3
3
|
export { compressSessionManually, createContextCompressionMiddleware } from '../middleware/contextCompressionMiddleware';
|
|
4
4
|
export type { ManualCompressionOptions, ManualCompressionResult } from '../middleware/contextCompressionMiddleware';
|
|
@@ -54,6 +54,8 @@ export interface Middleware<State = AgentLoopState> {
|
|
|
54
54
|
* Tools will be namespaced as: `<middlewareName>_<toolName>`
|
|
55
55
|
* When the middleware is removed, all associated tools are automatically unregistered.
|
|
56
56
|
*
|
|
57
|
+
* Can be synchronous or asynchronous to support dynamic tool creation.
|
|
58
|
+
*
|
|
57
59
|
* @example
|
|
58
60
|
* ```ts
|
|
59
61
|
* const middleware: Middleware = async (state, next) => {
|
|
@@ -67,7 +69,7 @@ export interface Middleware<State = AgentLoopState> {
|
|
|
67
69
|
* ];
|
|
68
70
|
* ```
|
|
69
71
|
*/
|
|
70
|
-
__createTools?: () => BaseTool[]
|
|
72
|
+
__createTools?: () => BaseTool[] | Promise<BaseTool[]>;
|
|
71
73
|
/**
|
|
72
74
|
* Optional function that returns a list of tool names to block for the given state.
|
|
73
75
|
* This allows middleware to dynamically control which tools should be unavailable
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -143,10 +143,21 @@ export interface AgentOptions {
|
|
|
143
143
|
* A SessionManager is automatically created to manage sessions.
|
|
144
144
|
* Sessions will be stored in the StateStore.
|
|
145
145
|
*
|
|
146
|
-
* The state store
|
|
147
|
-
*
|
|
146
|
+
* The state store can be configured with deleteOnComplete to control
|
|
147
|
+
* whether checkpoints are deleted after successful completion.
|
|
148
148
|
*/
|
|
149
149
|
stateStore?: StateStore;
|
|
150
|
+
/**
|
|
151
|
+
* Enable console logging for debugging (default: false).
|
|
152
|
+
*
|
|
153
|
+
* When enabled, the agent will output logs for key operations:
|
|
154
|
+
* - Agent and session creation
|
|
155
|
+
* - Message sending and receiving
|
|
156
|
+
* - Model calls and responses
|
|
157
|
+
* - Tool executions
|
|
158
|
+
* - Middleware execution
|
|
159
|
+
*/
|
|
160
|
+
enableLogging?: boolean;
|
|
150
161
|
}
|
|
151
162
|
/**
|
|
152
163
|
* Input for agent execution
|
|
@@ -239,10 +250,6 @@ export interface CreateSessionOptions extends SessionHandleOptions {
|
|
|
239
250
|
maxIterations?: number;
|
|
240
251
|
}
|
|
241
252
|
export interface SendOptions {
|
|
242
|
-
/**
|
|
243
|
-
* AbortSignal for cancellation support
|
|
244
|
-
*/
|
|
245
|
-
signal?: AbortSignal;
|
|
246
253
|
/**
|
|
247
254
|
* Optional tool execution context input
|
|
248
255
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
export { Agent, AgentAbortError, AgentMaxIterationsError, compose, compressSessionManually, createContextCompressionMiddleware, createInitialLoopState, ensureNotAborted, fromLoopCheckpoint, HookManager, toLoopCheckpoint, } from './agent';
|
|
1
|
+
export { Agent, AgentAbortError, AgentMaxIterationsError, compose, compressSessionManually, createContextCompressionMiddleware, createInitialLoopState, ensureNotAborted, extractPersistentMetadata, extractPersistentState, fromLoopCheckpoint, HookManager, toLoopCheckpoint, } from './agent';
|
|
2
2
|
export type { AgentInput, AgentLoopState, AgentOptions, CompressionStats, ContextCompressionOptions, CreateSessionOptions, HookContext, ManualCompressionOptions, ManualCompressionResult, Middleware, NextFunction, PostToolUseFailureHook, PostToolUseHook, PreToolUseHook, PreToolUseResult, SendOptions, SessionHandleOptions, ToCheckpointOptions, ToolCallWithResult, ToolHooks, } from './agent';
|
|
3
|
+
export { createAgentRulesMiddleware } from './middleware/agentRulesMiddleware';
|
|
4
|
+
export type { AgentRulesMiddlewareOptions } from './middleware/agentRulesMiddleware';
|
|
3
5
|
export { createCommitModeMiddleware } from './middleware/commitModeMiddleware';
|
|
4
6
|
export type { CommitModeMiddlewareOptions } from './middleware/commitModeMiddleware';
|
|
7
|
+
export { createEnvInfoMiddleware } from './middleware/envInfoMiddleware';
|
|
8
|
+
export type { EnvInfoMiddlewareOptions } from './middleware/envInfoMiddleware';
|
|
5
9
|
export { createPlanModeMiddleware } from './middleware/planModeMiddleware';
|
|
6
10
|
export type { PlanModeMiddlewareOptions } from './middleware/planModeMiddleware';
|
|
7
11
|
export { createParallelSubagentMiddleware } from './middleware/parallelSubagentMiddleware';
|
|
8
12
|
export type { ParallelSubagentMiddlewareOptions } from './middleware/parallelSubagentMiddleware';
|
|
9
|
-
export {
|
|
13
|
+
export { createSkillsMiddleware, parseSkillFile, scanMultipleSkillsDirectories, scanSkillsDirectory } from './middleware/skillsMiddleware';
|
|
14
|
+
export type { ParsedSkill, SkillsMiddlewareOptions } from './middleware/skillsMiddleware';
|
|
15
|
+
export { createMessageSnapshot, injectSystemReminderToLastUserMessage, restoreMessageAt, restoreMessages, snapshotMessageByRole, } from './middleware/utils';
|
|
16
|
+
export type { MessageRestoration } from './middleware/utils';
|
|
10
17
|
export * from './subagent';
|
|
11
18
|
export * from './acp-adapter';
|
|
12
19
|
export { runAcpServer } from './acp-server';
|