goatchain 0.0.20 → 0.0.22
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 +32 -25
- package/dist/acp-adapter/types.d.ts +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +923 -402
- package/dist/middleware/skillsMiddleware.d.ts +12 -5
- package/dist/model/anthropic/createAnthropicAdapter.d.ts +7 -0
- package/dist/model/gemini/createGeminiAdapter.d.ts +7 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/types.d.ts +1 -0
- package/dist/server/core/event-store.d.ts +15 -0
- package/dist/server/core/mode-manager.d.ts +17 -0
- package/dist/server/core/state-store.d.ts +11 -0
- package/dist/server/core/types.d.ts +66 -0
- package/dist/server/http/server.d.ts +27 -0
- package/dist/server/http/sse.d.ts +4 -0
- package/dist/server/http/static.d.ts +2 -0
- package/dist/server/http/uploads.d.ts +27 -0
- package/dist/server/http/utils.d.ts +5 -0
- package/dist/server/index.d.ts +36 -0
- package/dist/server/ports/findAvailablePort.d.ts +9 -0
- package/dist/server/use-cases/query.d.ts +27 -0
- package/dist/session/utils/AsyncQueue.d.ts +19 -0
- package/dist/state/FileStateStore.d.ts +2 -0
- package/dist/tool/builtin/edit.d.ts +7 -0
- package/dist/tool/builtin/index.d.ts +0 -4
- package/dist/tool/builtin/read.d.ts +18 -0
- package/dist/tool/builtin/utils.d.ts +1 -0
- package/dist/tool/builtin/write.d.ts +7 -0
- package/dist/tool/converters/base.d.ts +20 -0
- package/dist/tool/converters/cache.d.ts +33 -0
- package/dist/tool/converters/detector.d.ts +11 -0
- package/dist/tool/converters/index.d.ts +11 -0
- package/dist/tool/converters/iwork.d.ts +11 -0
- package/dist/tool/converters/metrics.d.ts +40 -0
- package/dist/tool/converters/office.d.ts +13 -0
- package/dist/tool/converters/pdf.d.ts +14 -0
- package/dist/tool/converters/processor.d.ts +51 -0
- package/dist/tool/converters/registry.d.ts +9 -0
- package/dist/tool/converters/types.d.ts +73 -0
- package/dist/tool/converters/validator.d.ts +18 -0
- package/dist/tool/index.d.ts +2 -2
- package/dist/types/common.d.ts +1 -0
- package/package.json +19 -10
- package/dist/tool/builtin/astGrepCli.d.ts +0 -37
- package/dist/tool/builtin/astGrepFormat.d.ts +0 -4
- package/dist/tool/builtin/astGrepReplace.d.ts +0 -81
- package/dist/tool/builtin/astGrepSearch.d.ts +0 -105
package/README.md
CHANGED
|
@@ -120,6 +120,7 @@ session.send('Read the README.md file')
|
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
**Benefits:**
|
|
123
|
+
|
|
123
124
|
- Automatically sets the working directory for all tools that support it
|
|
124
125
|
- Persisted across session saves and restores
|
|
125
126
|
- Can be changed at runtime with `session.setCwd()`
|
|
@@ -614,10 +615,10 @@ interface ToolHooks {
|
|
|
614
615
|
// - If allow: false, tool is blocked
|
|
615
616
|
// - Can modify tool call with modifiedToolCall
|
|
616
617
|
preToolUse?: (ctx: HookContext) => Promise<PreToolUseResult>
|
|
617
|
-
|
|
618
|
+
|
|
618
619
|
// Called after successful tool execution
|
|
619
620
|
postToolUse?: (ctx: HookContext, result: unknown) => Promise<void>
|
|
620
|
-
|
|
621
|
+
|
|
621
622
|
// Called after tool execution failure
|
|
622
623
|
postToolUseFailure?: (ctx: HookContext, error: Error) => Promise<void>
|
|
623
624
|
}
|
|
@@ -653,9 +654,7 @@ const agent = new Agent({
|
|
|
653
654
|
name: 'MyAgent',
|
|
654
655
|
systemPrompt: 'You are helpful.',
|
|
655
656
|
model,
|
|
656
|
-
tools: new ToolRegistry()
|
|
657
|
-
.register(new ReadTool())
|
|
658
|
-
.register(new WriteTool()),
|
|
657
|
+
tools: new ToolRegistry().register(new ReadTool()).register(new WriteTool()),
|
|
659
658
|
})
|
|
660
659
|
|
|
661
660
|
// Create session with hooks
|
|
@@ -664,16 +663,16 @@ const session = await agent.createSession({
|
|
|
664
663
|
preToolUse: async (ctx) => {
|
|
665
664
|
const toolName = ctx.toolCall.function.name
|
|
666
665
|
console.log(`Tool requested: ${toolName}`)
|
|
667
|
-
|
|
666
|
+
|
|
668
667
|
// Returning { allow: true } skips approval flow and executes tool immediately
|
|
669
668
|
// Returning { allow: false } blocks tool execution
|
|
670
669
|
return { allow: true }
|
|
671
670
|
},
|
|
672
|
-
|
|
671
|
+
|
|
673
672
|
postToolUse: async (ctx, result) => {
|
|
674
673
|
console.log(`Tool ${ctx.toolCall.function.name} completed successfully`)
|
|
675
674
|
},
|
|
676
|
-
|
|
675
|
+
|
|
677
676
|
postToolUseFailure: async (ctx, error) => {
|
|
678
677
|
console.error(`Tool ${ctx.toolCall.function.name} failed:`, error)
|
|
679
678
|
},
|
|
@@ -694,12 +693,12 @@ function shouldAutoApprove(toolName: string, riskLevel: RiskLevel): boolean {
|
|
|
694
693
|
if (riskLevel === 'safe' || riskLevel === 'low') {
|
|
695
694
|
return true
|
|
696
695
|
}
|
|
697
|
-
|
|
696
|
+
|
|
698
697
|
// Block critical tools
|
|
699
698
|
if (riskLevel === 'critical') {
|
|
700
699
|
return false
|
|
701
700
|
}
|
|
702
|
-
|
|
701
|
+
|
|
703
702
|
// For medium/high risk, you can implement custom logic
|
|
704
703
|
// e.g., check environment, user permissions, etc.
|
|
705
704
|
return process.env.AUTO_APPROVE_ALL === 'true'
|
|
@@ -711,13 +710,13 @@ const session = await agent.createSession({
|
|
|
711
710
|
const tool = agent.tools.get(ctx.toolCall.function.name)
|
|
712
711
|
const riskLevel = tool?.riskLevel ?? 'safe'
|
|
713
712
|
const allow = shouldAutoApprove(ctx.toolCall.function.name, riskLevel)
|
|
714
|
-
|
|
713
|
+
|
|
715
714
|
if (allow) {
|
|
716
715
|
console.log(`✓ Auto-approved: ${ctx.toolCall.function.name}`)
|
|
717
716
|
} else {
|
|
718
717
|
console.log(`✗ Blocked: ${ctx.toolCall.function.name}`)
|
|
719
718
|
}
|
|
720
|
-
|
|
719
|
+
|
|
721
720
|
return { allow }
|
|
722
721
|
},
|
|
723
722
|
},
|
|
@@ -747,6 +746,7 @@ for await (const event of session.receive()) {
|
|
|
747
746
|
```
|
|
748
747
|
|
|
749
748
|
**Use cases:**
|
|
749
|
+
|
|
750
750
|
- **Automated workflows**: Scripts that run without user interaction
|
|
751
751
|
- **Testing**: E2E tests that need tools to execute automatically
|
|
752
752
|
- **Trusted environments**: When you trust the agent's tool usage completely
|
|
@@ -789,8 +789,9 @@ session.send('Create a file and delete it', {
|
|
|
789
789
|
for await (const event of session.receive()) {
|
|
790
790
|
if (event.type === 'requires_action') {
|
|
791
791
|
// Save checkpoint
|
|
792
|
-
checkpoint =
|
|
793
|
-
|
|
792
|
+
checkpoint =
|
|
793
|
+
event.checkpoint ||
|
|
794
|
+
(await agent.stateStore?.loadCheckpoint(event.checkpointRef?.sessionId))
|
|
794
795
|
break // Pause here
|
|
795
796
|
}
|
|
796
797
|
}
|
|
@@ -802,12 +803,12 @@ if (checkpoint) {
|
|
|
802
803
|
checkpoint.pendingToolCalls.map((pending) => {
|
|
803
804
|
const toolName = pending.toolCall.function.name
|
|
804
805
|
const approved = confirm(`Approve ${toolName}?`)
|
|
805
|
-
|
|
806
|
+
|
|
806
807
|
return [
|
|
807
808
|
pending.toolCall.id,
|
|
808
809
|
{ approved, reason: approved ? undefined : 'User denied' },
|
|
809
810
|
]
|
|
810
|
-
})
|
|
811
|
+
}),
|
|
811
812
|
)
|
|
812
813
|
|
|
813
814
|
// Resume session with decisions
|
|
@@ -836,6 +837,7 @@ bun run examples/tool-approval-session.ts
|
|
|
836
837
|
```
|
|
837
838
|
|
|
838
839
|
**Key features shown:**
|
|
840
|
+
|
|
839
841
|
- Creating custom tools with risk levels
|
|
840
842
|
- Implementing approval hooks with async delays
|
|
841
843
|
- Pausing execution on `requires_action` events
|
|
@@ -851,11 +853,11 @@ const session = await agent.createSession({
|
|
|
851
853
|
hooks: {
|
|
852
854
|
preToolUse: async (ctx) => {
|
|
853
855
|
const toolName = ctx.toolCall.function.name
|
|
854
|
-
|
|
856
|
+
|
|
855
857
|
// Example: Add safety constraints to file writes
|
|
856
858
|
if (toolName === 'Write') {
|
|
857
859
|
const args = JSON.parse(ctx.toolCall.function.arguments)
|
|
858
|
-
|
|
860
|
+
|
|
859
861
|
// Modify the tool call to add restrictions
|
|
860
862
|
const modifiedToolCall = {
|
|
861
863
|
...ctx.toolCall,
|
|
@@ -868,13 +870,13 @@ const session = await agent.createSession({
|
|
|
868
870
|
}),
|
|
869
871
|
},
|
|
870
872
|
}
|
|
871
|
-
|
|
873
|
+
|
|
872
874
|
return {
|
|
873
875
|
allow: true,
|
|
874
876
|
modifiedToolCall,
|
|
875
877
|
}
|
|
876
878
|
}
|
|
877
|
-
|
|
879
|
+
|
|
878
880
|
return { allow: true }
|
|
879
881
|
},
|
|
880
882
|
},
|
|
@@ -892,8 +894,8 @@ session.send('Do something risky', {
|
|
|
892
894
|
strategy: 'high_risk', // Pause on high-risk tools
|
|
893
895
|
// or
|
|
894
896
|
decisions: {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
+
tool_call_id_123: { approved: true },
|
|
898
|
+
tool_call_id_456: { approved: false, reason: 'Too dangerous' },
|
|
897
899
|
},
|
|
898
900
|
},
|
|
899
901
|
// Your custom context
|
|
@@ -1451,7 +1453,12 @@ console.log(`Total tokens: ${session.usage.totalTokens}`)
|
|
|
1451
1453
|
Combine session-level working directory with auto-approval for automated file operations:
|
|
1452
1454
|
|
|
1453
1455
|
```typescript
|
|
1454
|
-
import {
|
|
1456
|
+
import {
|
|
1457
|
+
Agent,
|
|
1458
|
+
createModel,
|
|
1459
|
+
createOpenAIAdapter,
|
|
1460
|
+
createBuiltinTools,
|
|
1461
|
+
} from 'goatchain'
|
|
1455
1462
|
|
|
1456
1463
|
const model = createModel({
|
|
1457
1464
|
adapter: createOpenAIAdapter({
|
|
@@ -1484,8 +1491,7 @@ session.send('List all TypeScript files, then create a summary.md file', {
|
|
|
1484
1491
|
for await (const event of session.receive()) {
|
|
1485
1492
|
if (event.type === 'text_delta') {
|
|
1486
1493
|
process.stdout.write(event.delta)
|
|
1487
|
-
}
|
|
1488
|
-
else if (event.type === 'tool_call_start') {
|
|
1494
|
+
} else if (event.type === 'tool_call_start') {
|
|
1489
1495
|
console.log(`\nExecuting: ${event.toolName}`)
|
|
1490
1496
|
}
|
|
1491
1497
|
}
|
|
@@ -1506,6 +1512,7 @@ for await (const event of session.receive()) {
|
|
|
1506
1512
|
```
|
|
1507
1513
|
|
|
1508
1514
|
**Perfect for:**
|
|
1515
|
+
|
|
1509
1516
|
- CI/CD pipelines that need file analysis
|
|
1510
1517
|
- Automated code review bots
|
|
1511
1518
|
- Project documentation generators
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from './acp-adapter';
|
|
2
2
|
export { runAcpServer } from './acp-server';
|
|
3
|
+
export { startApiServer } from './server';
|
|
4
|
+
export type { ApiServerHandle, StartApiServerOptions, QueryHandler, QueryHandlerResult, ServerCapabilities } from './server';
|
|
3
5
|
export { Agent, AgentAbortError, AgentMaxIterationsError, compose, compressSessionManually, createContextCompressionMiddleware, createInitialLoopState, ensureNotAborted, extractPersistentMetadata, extractPersistentState, fromLoopCheckpoint, HookManager, toLoopCheckpoint, } from './agent';
|
|
4
6
|
export type { AgentInput, AgentLoopState, AgentOptions, CompressionStats, ContextCompressionOptions, CreateSessionOptions, HookContext, ManualCompressionOptions, ManualCompressionResult, Middleware, NextFunction, PostToolUseFailureHook, PostToolUseHook, PreToolUseHook, PreToolUseResult, SendOptions, SessionHandleOptions, ToCheckpointOptions, ToolCallWithResult, ToolHooks, } from './agent';
|
|
7
|
+
export * from './mcp-client';
|
|
5
8
|
export { createAgentRulesMiddleware } from './middleware/agentRulesMiddleware';
|
|
6
9
|
export type { AgentRulesMiddlewareOptions } from './middleware/agentRulesMiddleware';
|
|
7
10
|
export { createCommitModeMiddleware } from './middleware/commitModeMiddleware';
|
|
@@ -19,13 +22,13 @@ export type { ParsedSkill, SkillsMiddlewareOptions } from './middleware/skillsMi
|
|
|
19
22
|
export { injectSystemReminderToLastUserMessage, } from './middleware/utils';
|
|
20
23
|
export * from './model';
|
|
21
24
|
export type { OpenAITool } from './model';
|
|
22
|
-
export * from './mcp-client';
|
|
23
25
|
export { BaseSession, BaseSessionManager, Session } from './session';
|
|
24
26
|
export { FileStateStore, InMemoryStateStore, StateKeys, StateStore, } from './state';
|
|
25
27
|
export type { CompressionState, FileStateStoreOptions, StateKey, StateStoreOptions, } from './state';
|
|
26
28
|
export * from './subagent';
|
|
27
29
|
export { BaseTool, errorContent, FilteredToolRegistry, imageContent, textContent, ToolRegistry } from './tool';
|
|
28
|
-
export { AskUserTool,
|
|
30
|
+
export { AskUserTool, BashTool, EditTool, GlobTool, GrepTool, ReadTool, TodoPlanTool, TodoWriteTool, WebFetchTool, WebSearchTool, WriteTool, } from './tool';
|
|
29
31
|
export type { BashArgs, BashResult, RiskLevel, ToolApprovalResult, ToolApprovalSettings, ToolApprovalStrategy, ToolExecutionContext, ToolExecutionContextInput, ToolRunUsage, } from './tool';
|
|
30
|
-
export type { AskUserArgs, AskUserResult,
|
|
32
|
+
export type { AskUserArgs, AskUserResult, EditArgs, EditResult, FetchFormat, GlobArgs, GlobResult, GrepArgs, GrepOutputMode, GrepResult, Question, QuestionOption, ReadArgs, ReadResult, TodoItem, TodoPlanArgs, TodoPlanResult, TodoStatus, TodoWriteArgs, TodoWriteResult, WebFetchArgs, WebFetchResult, WebSearchArgs, WebSearchResult, WriteArgs, WriteResult, } from './tool';
|
|
33
|
+
export * from './tool/converters';
|
|
31
34
|
export type { AgentEvent, AgentEventType, AgentLoopCheckpoint, AssistantMessage, BaseEvent, CallToolResult, ContentBlock, DoneEvent, ImageContent, IterationEndEvent, IterationStartEvent, JSONSchemaProperty, Message, MessageContent, MessageRole, SystemMessage, TextContent, TextDeltaEvent, TextEndEvent, TextStartEvent, ThinkingDeltaEvent, Tool, ToolCall, ToolCallDeltaEvent, ToolCallEndEvent, ToolCallStartEvent, ToolMessage, ToolResultEvent, Usage, UserMessage, } from './types';
|