@codeany/open-agent-sdk 0.2.2 → 0.2.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.
- package/dist/agent.d.ts +113 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +453 -0
- package/dist/agent.js.map +1 -0
- package/dist/engine.d.ts +62 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +496 -0
- package/dist/engine.js.map +1 -0
- package/dist/hooks.d.ts +111 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +179 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +19 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +126 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/providers/anthropic.d.ts +17 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +47 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +20 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +26 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +212 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +84 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +11 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/sdk-mcp-server.d.ts +52 -0
- package/dist/sdk-mcp-server.d.ts.map +1 -0
- package/dist/sdk-mcp-server.js +57 -0
- package/dist/sdk-mcp-server.js.map +1 -0
- package/dist/session.d.ts +73 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +159 -0
- package/dist/session.js.map +1 -0
- package/dist/skills/bundled/commit.d.ts +7 -0
- package/dist/skills/bundled/commit.d.ts.map +1 -0
- package/dist/skills/bundled/commit.js +35 -0
- package/dist/skills/bundled/commit.js.map +1 -0
- package/dist/skills/bundled/debug.d.ts +7 -0
- package/dist/skills/bundled/debug.d.ts.map +1 -0
- package/{src/skills/bundled/debug.ts → dist/skills/bundled/debug.js} +20 -22
- package/dist/skills/bundled/debug.js.map +1 -0
- package/dist/skills/bundled/index.d.ts +11 -0
- package/dist/skills/bundled/index.d.ts.map +1 -0
- package/dist/skills/bundled/index.js +26 -0
- package/dist/skills/bundled/index.js.map +1 -0
- package/dist/skills/bundled/review.d.ts +7 -0
- package/dist/skills/bundled/review.d.ts.map +1 -0
- package/{src/skills/bundled/review.ts → dist/skills/bundled/review.js} +18 -21
- package/dist/skills/bundled/review.js.map +1 -0
- package/dist/skills/bundled/simplify.d.ts +8 -0
- package/dist/skills/bundled/simplify.d.ts.map +1 -0
- package/{src/skills/bundled/simplify.ts → dist/skills/bundled/simplify.js} +16 -19
- package/dist/skills/bundled/simplify.js.map +1 -0
- package/dist/skills/bundled/test.d.ts +7 -0
- package/dist/skills/bundled/test.d.ts.map +1 -0
- package/{src/skills/bundled/test.ts → dist/skills/bundled/test.js} +18 -21
- package/dist/skills/bundled/test.js.map +1 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +8 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/registry.d.ts +43 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +111 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +83 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +8 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/tool-helper.d.ts +73 -0
- package/dist/tool-helper.d.ts.map +1 -0
- package/dist/tool-helper.js +86 -0
- package/dist/tool-helper.js.map +1 -0
- package/dist/tools/agent-tool.d.ts +17 -0
- package/dist/tools/agent-tool.d.ts.map +1 -0
- package/dist/tools/agent-tool.js +146 -0
- package/dist/tools/agent-tool.js.map +1 -0
- package/dist/tools/ask-user.d.ts +18 -0
- package/dist/tools/ask-user.d.ts.map +1 -0
- package/dist/tools/ask-user.js +72 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/bash.d.ts +5 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +67 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/config-tool.d.ts +20 -0
- package/dist/tools/config-tool.d.ts.map +1 -0
- package/dist/tools/config-tool.js +83 -0
- package/dist/tools/config-tool.js.map +1 -0
- package/dist/tools/cron-tools.d.ts +33 -0
- package/dist/tools/cron-tools.d.ts.map +1 -0
- package/dist/tools/cron-tools.js +128 -0
- package/dist/tools/cron-tools.js.map +1 -0
- package/dist/tools/edit.d.ts +5 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +70 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +5 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +75 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +5 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +168 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +45 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +162 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/lsp-tool.d.ts +9 -0
- package/dist/tools/lsp-tool.d.ts.map +1 -0
- package/dist/tools/lsp-tool.js +137 -0
- package/dist/tools/lsp-tool.js.map +1 -0
- package/dist/tools/mcp-resource-tools.d.ts +14 -0
- package/dist/tools/mcp-resource-tools.d.ts.map +1 -0
- package/dist/tools/mcp-resource-tools.js +117 -0
- package/dist/tools/mcp-resource-tools.js.map +1 -0
- package/dist/tools/notebook-edit.d.ts +5 -0
- package/dist/tools/notebook-edit.d.ts.map +1 -0
- package/dist/tools/notebook-edit.js +85 -0
- package/dist/tools/notebook-edit.js.map +1 -0
- package/dist/tools/plan-tools.d.ts +12 -0
- package/dist/tools/plan-tools.d.ts.map +1 -0
- package/dist/tools/plan-tools.js +77 -0
- package/dist/tools/plan-tools.js.map +1 -0
- package/dist/tools/read.d.ts +5 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +66 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/send-message.d.ts +31 -0
- package/dist/tools/send-message.d.ts.map +1 -0
- package/dist/tools/send-message.js +77 -0
- package/dist/tools/send-message.js.map +1 -0
- package/dist/tools/skill-tool.d.ts +9 -0
- package/dist/tools/skill-tool.d.ts.map +1 -0
- package/dist/tools/skill-tool.js +115 -0
- package/dist/tools/skill-tool.js.map +1 -0
- package/dist/tools/task-tools.d.ts +48 -0
- package/dist/tools/task-tools.d.ts.map +1 -0
- package/dist/tools/task-tools.js +242 -0
- package/dist/tools/task-tools.js.map +1 -0
- package/dist/tools/team-tools.d.ts +34 -0
- package/dist/tools/team-tools.d.ts.map +1 -0
- package/dist/tools/team-tools.js +103 -0
- package/dist/tools/team-tools.js.map +1 -0
- package/dist/tools/todo-tool.d.ts +22 -0
- package/dist/tools/todo-tool.d.ts.map +1 -0
- package/dist/tools/todo-tool.js +93 -0
- package/dist/tools/todo-tool.js.map +1 -0
- package/dist/tools/tool-search.d.ts +13 -0
- package/dist/tools/tool-search.d.ts.map +1 -0
- package/dist/tools/tool-search.js +76 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/types.d.ts +29 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +52 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +5 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +60 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +5 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +77 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/worktree-tools.d.ts +10 -0
- package/dist/tools/worktree-tools.d.ts.map +1 -0
- package/dist/tools/worktree-tools.js +130 -0
- package/dist/tools/worktree-tools.js.map +1 -0
- package/dist/tools/write.d.ts +5 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +40 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +432 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/compact.d.ts +44 -0
- package/dist/utils/compact.d.ts.map +1 -0
- package/dist/utils/compact.js +162 -0
- package/dist/utils/compact.js.map +1 -0
- package/dist/utils/context.d.ts +35 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +174 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/fileCache.d.ts +64 -0
- package/dist/utils/fileCache.d.ts.map +1 -0
- package/dist/utils/fileCache.js +117 -0
- package/dist/utils/fileCache.js.map +1 -0
- package/dist/utils/messages.d.ts +57 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +152 -0
- package/dist/utils/messages.js.map +1 -0
- package/dist/utils/retry.d.ts +48 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +111 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/tokens.d.ts +57 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +134 -0
- package/dist/utils/tokens.js.map +1 -0
- package/package.json +6 -1
- package/.env.example +0 -8
- package/examples/01-simple-query.ts +0 -43
- package/examples/02-multi-tool.ts +0 -44
- package/examples/03-multi-turn.ts +0 -39
- package/examples/04-prompt-api.ts +0 -29
- package/examples/05-custom-system-prompt.ts +0 -26
- package/examples/06-mcp-server.ts +0 -49
- package/examples/07-custom-tools.ts +0 -87
- package/examples/08-official-api-compat.ts +0 -38
- package/examples/09-subagents.ts +0 -48
- package/examples/10-permissions.ts +0 -40
- package/examples/11-custom-mcp-tools.ts +0 -101
- package/examples/12-skills.ts +0 -88
- package/examples/13-hooks.ts +0 -88
- package/examples/14-openai-compat.ts +0 -71
- package/examples/web/index.html +0 -365
- package/examples/web/server.ts +0 -157
- package/src/agent.ts +0 -516
- package/src/engine.ts +0 -633
- package/src/hooks.ts +0 -261
- package/src/index.ts +0 -426
- package/src/mcp/client.ts +0 -150
- package/src/providers/anthropic.ts +0 -60
- package/src/providers/index.ts +0 -34
- package/src/providers/openai.ts +0 -315
- package/src/providers/types.ts +0 -85
- package/src/sdk-mcp-server.ts +0 -78
- package/src/session.ts +0 -227
- package/src/skills/bundled/commit.ts +0 -38
- package/src/skills/bundled/index.ts +0 -28
- package/src/skills/index.ts +0 -25
- package/src/skills/registry.ts +0 -133
- package/src/skills/types.ts +0 -99
- package/src/tool-helper.ts +0 -127
- package/src/tools/agent-tool.ts +0 -164
- package/src/tools/ask-user.ts +0 -79
- package/src/tools/bash.ts +0 -75
- package/src/tools/config-tool.ts +0 -89
- package/src/tools/cron-tools.ts +0 -153
- package/src/tools/edit.ts +0 -74
- package/src/tools/glob.ts +0 -77
- package/src/tools/grep.ts +0 -168
- package/src/tools/index.ts +0 -240
- package/src/tools/lsp-tool.ts +0 -163
- package/src/tools/mcp-resource-tools.ts +0 -125
- package/src/tools/notebook-edit.ts +0 -93
- package/src/tools/plan-tools.ts +0 -88
- package/src/tools/read.ts +0 -73
- package/src/tools/send-message.ts +0 -96
- package/src/tools/skill-tool.ts +0 -133
- package/src/tools/task-tools.ts +0 -290
- package/src/tools/team-tools.ts +0 -128
- package/src/tools/todo-tool.ts +0 -112
- package/src/tools/tool-search.ts +0 -87
- package/src/tools/types.ts +0 -66
- package/src/tools/web-fetch.ts +0 -66
- package/src/tools/web-search.ts +0 -86
- package/src/tools/worktree-tools.ts +0 -140
- package/src/tools/write.ts +0 -42
- package/src/types.ts +0 -486
- package/src/utils/compact.ts +0 -207
- package/src/utils/context.ts +0 -191
- package/src/utils/fileCache.ts +0 -148
- package/src/utils/messages.ts +0 -195
- package/src/utils/retry.ts +0 -140
- package/src/utils/tokens.ts +0 -145
- package/tsconfig.json +0 -19
package/src/sdk-mcp-server.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-Process MCP Server
|
|
3
|
-
*
|
|
4
|
-
* createSdkMcpServer() creates an in-process MCP server from tool() definitions.
|
|
5
|
-
* Compatible with open-agent-sdk's createSdkMcpServer().
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* import { tool, createSdkMcpServer } from 'open-agent-sdk'
|
|
9
|
-
* import { z } from 'zod'
|
|
10
|
-
*
|
|
11
|
-
* const weatherTool = tool('get_weather', 'Get weather', { city: z.string() },
|
|
12
|
-
* async ({ city }) => ({ content: [{ type: 'text', text: `22°C in ${city}` }] })
|
|
13
|
-
* )
|
|
14
|
-
*
|
|
15
|
-
* const server = createSdkMcpServer({
|
|
16
|
-
* name: 'weather',
|
|
17
|
-
* tools: [weatherTool],
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* // Use as MCP server config:
|
|
21
|
-
* const agent = createAgent({
|
|
22
|
-
* mcpServers: { weather: server },
|
|
23
|
-
* })
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import type { SdkMcpToolDefinition } from './tool-helper.js'
|
|
27
|
-
import { sdkToolToToolDefinition } from './tool-helper.js'
|
|
28
|
-
import type { ToolDefinition, McpServerConfig } from './types.js'
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* SDK MCP server config that includes the in-process server instance.
|
|
32
|
-
*/
|
|
33
|
-
export interface McpSdkServerConfig {
|
|
34
|
-
type: 'sdk'
|
|
35
|
-
name: string
|
|
36
|
-
version: string
|
|
37
|
-
tools: ToolDefinition[]
|
|
38
|
-
_sdkTools: SdkMcpToolDefinition<any>[]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Create an in-process MCP server from tool definitions.
|
|
43
|
-
*
|
|
44
|
-
* The server runs in the same process as the agent, avoiding
|
|
45
|
-
* subprocess overhead. Tools are directly callable.
|
|
46
|
-
*/
|
|
47
|
-
export function createSdkMcpServer(options: {
|
|
48
|
-
name: string
|
|
49
|
-
version?: string
|
|
50
|
-
tools?: SdkMcpToolDefinition<any>[]
|
|
51
|
-
}): McpSdkServerConfig {
|
|
52
|
-
const sdkTools = options.tools || []
|
|
53
|
-
|
|
54
|
-
// Convert SDK tools to engine-compatible tool definitions
|
|
55
|
-
// Prefix tool names with mcp__{server_name}__ for namespace isolation
|
|
56
|
-
const toolDefinitions: ToolDefinition[] = sdkTools.map((sdkTool) => {
|
|
57
|
-
const toolDef = sdkToolToToolDefinition(sdkTool)
|
|
58
|
-
return {
|
|
59
|
-
...toolDef,
|
|
60
|
-
name: `mcp__${options.name}__${sdkTool.name}`,
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
type: 'sdk',
|
|
66
|
-
name: options.name,
|
|
67
|
-
version: options.version || '1.0.0',
|
|
68
|
-
tools: toolDefinitions,
|
|
69
|
-
_sdkTools: sdkTools,
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Check if a server config is an in-process SDK server.
|
|
75
|
-
*/
|
|
76
|
-
export function isSdkServerConfig(config: any): config is McpSdkServerConfig {
|
|
77
|
-
return config?.type === 'sdk' && Array.isArray(config.tools)
|
|
78
|
-
}
|
package/src/session.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Session Storage & Management
|
|
3
|
-
*
|
|
4
|
-
* Persists conversation transcripts to disk for resumption.
|
|
5
|
-
* Manages session lifecycle (create, resume, list, fork).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { readFile, writeFile, mkdir, readdir, stat } from 'fs/promises'
|
|
9
|
-
import { join } from 'path'
|
|
10
|
-
import type { Message } from './types.js'
|
|
11
|
-
import type { NormalizedMessageParam } from './providers/types.js'
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Session metadata.
|
|
15
|
-
*/
|
|
16
|
-
export interface SessionMetadata {
|
|
17
|
-
id: string
|
|
18
|
-
cwd: string
|
|
19
|
-
model: string
|
|
20
|
-
createdAt: string
|
|
21
|
-
updatedAt: string
|
|
22
|
-
messageCount: number
|
|
23
|
-
summary?: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Session data on disk.
|
|
28
|
-
*/
|
|
29
|
-
export interface SessionData {
|
|
30
|
-
metadata: SessionMetadata
|
|
31
|
-
messages: NormalizedMessageParam[]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get the sessions directory path.
|
|
36
|
-
*/
|
|
37
|
-
function getSessionsDir(): string {
|
|
38
|
-
const home = process.env.HOME || process.env.USERPROFILE || '/tmp'
|
|
39
|
-
return join(home, '.open-agent-sdk', 'sessions')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get the path for a specific session.
|
|
44
|
-
*/
|
|
45
|
-
function getSessionPath(sessionId: string): string {
|
|
46
|
-
return join(getSessionsDir(), sessionId)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Save session to disk.
|
|
51
|
-
*/
|
|
52
|
-
export async function saveSession(
|
|
53
|
-
sessionId: string,
|
|
54
|
-
messages: NormalizedMessageParam[],
|
|
55
|
-
metadata: Partial<SessionMetadata>,
|
|
56
|
-
): Promise<void> {
|
|
57
|
-
const dir = getSessionPath(sessionId)
|
|
58
|
-
await mkdir(dir, { recursive: true })
|
|
59
|
-
|
|
60
|
-
const data: SessionData = {
|
|
61
|
-
metadata: {
|
|
62
|
-
id: sessionId,
|
|
63
|
-
cwd: metadata.cwd || process.cwd(),
|
|
64
|
-
model: metadata.model || 'claude-sonnet-4-6',
|
|
65
|
-
createdAt: metadata.createdAt || new Date().toISOString(),
|
|
66
|
-
updatedAt: new Date().toISOString(),
|
|
67
|
-
messageCount: messages.length,
|
|
68
|
-
summary: metadata.summary,
|
|
69
|
-
},
|
|
70
|
-
messages,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await writeFile(
|
|
74
|
-
join(dir, 'transcript.json'),
|
|
75
|
-
JSON.stringify(data, null, 2),
|
|
76
|
-
'utf-8',
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Load session from disk.
|
|
82
|
-
*/
|
|
83
|
-
export async function loadSession(sessionId: string): Promise<SessionData | null> {
|
|
84
|
-
try {
|
|
85
|
-
const filePath = join(getSessionPath(sessionId), 'transcript.json')
|
|
86
|
-
const content = await readFile(filePath, 'utf-8')
|
|
87
|
-
return JSON.parse(content) as SessionData
|
|
88
|
-
} catch {
|
|
89
|
-
return null
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* List all sessions.
|
|
95
|
-
*/
|
|
96
|
-
export async function listSessions(): Promise<SessionMetadata[]> {
|
|
97
|
-
try {
|
|
98
|
-
const dir = getSessionsDir()
|
|
99
|
-
const entries = await readdir(dir)
|
|
100
|
-
const sessions: SessionMetadata[] = []
|
|
101
|
-
|
|
102
|
-
for (const entry of entries) {
|
|
103
|
-
try {
|
|
104
|
-
const data = await loadSession(entry)
|
|
105
|
-
if (data?.metadata) {
|
|
106
|
-
sessions.push(data.metadata)
|
|
107
|
-
}
|
|
108
|
-
} catch {
|
|
109
|
-
// Skip invalid sessions
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Sort by updatedAt descending
|
|
114
|
-
sessions.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt))
|
|
115
|
-
|
|
116
|
-
return sessions
|
|
117
|
-
} catch {
|
|
118
|
-
return []
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Fork a session (create a copy with a new ID).
|
|
124
|
-
*/
|
|
125
|
-
export async function forkSession(
|
|
126
|
-
sourceSessionId: string,
|
|
127
|
-
newSessionId?: string,
|
|
128
|
-
): Promise<string | null> {
|
|
129
|
-
const data = await loadSession(sourceSessionId)
|
|
130
|
-
if (!data) return null
|
|
131
|
-
|
|
132
|
-
const forkId = newSessionId || crypto.randomUUID()
|
|
133
|
-
|
|
134
|
-
await saveSession(forkId, data.messages, {
|
|
135
|
-
...data.metadata,
|
|
136
|
-
id: forkId,
|
|
137
|
-
createdAt: new Date().toISOString(),
|
|
138
|
-
summary: `Forked from session ${sourceSessionId}`,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
return forkId
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Get session messages.
|
|
146
|
-
*/
|
|
147
|
-
export async function getSessionMessages(
|
|
148
|
-
sessionId: string,
|
|
149
|
-
): Promise<NormalizedMessageParam[]> {
|
|
150
|
-
const data = await loadSession(sessionId)
|
|
151
|
-
return data?.messages || []
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Append a message to a session transcript.
|
|
156
|
-
*/
|
|
157
|
-
export async function appendToSession(
|
|
158
|
-
sessionId: string,
|
|
159
|
-
message: NormalizedMessageParam,
|
|
160
|
-
): Promise<void> {
|
|
161
|
-
const data = await loadSession(sessionId)
|
|
162
|
-
if (!data) return
|
|
163
|
-
|
|
164
|
-
data.messages.push(message)
|
|
165
|
-
data.metadata.updatedAt = new Date().toISOString()
|
|
166
|
-
data.metadata.messageCount = data.messages.length
|
|
167
|
-
|
|
168
|
-
await saveSession(sessionId, data.messages, data.metadata)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Delete a session.
|
|
173
|
-
*/
|
|
174
|
-
export async function deleteSession(sessionId: string): Promise<boolean> {
|
|
175
|
-
try {
|
|
176
|
-
const { rm } = await import('fs/promises')
|
|
177
|
-
await rm(getSessionPath(sessionId), { recursive: true, force: true })
|
|
178
|
-
return true
|
|
179
|
-
} catch {
|
|
180
|
-
return false
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Get info about a specific session.
|
|
186
|
-
*/
|
|
187
|
-
export async function getSessionInfo(
|
|
188
|
-
sessionId: string,
|
|
189
|
-
options?: { dir?: string },
|
|
190
|
-
): Promise<SessionMetadata | null> {
|
|
191
|
-
const data = await loadSession(sessionId)
|
|
192
|
-
return data?.metadata || null
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Rename a session.
|
|
197
|
-
*/
|
|
198
|
-
export async function renameSession(
|
|
199
|
-
sessionId: string,
|
|
200
|
-
title: string,
|
|
201
|
-
options?: { dir?: string },
|
|
202
|
-
): Promise<void> {
|
|
203
|
-
const data = await loadSession(sessionId)
|
|
204
|
-
if (!data) return
|
|
205
|
-
|
|
206
|
-
data.metadata.summary = title
|
|
207
|
-
data.metadata.updatedAt = new Date().toISOString()
|
|
208
|
-
|
|
209
|
-
await saveSession(sessionId, data.messages, data.metadata)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Tag a session.
|
|
214
|
-
*/
|
|
215
|
-
export async function tagSession(
|
|
216
|
-
sessionId: string,
|
|
217
|
-
tag: string | null,
|
|
218
|
-
options?: { dir?: string },
|
|
219
|
-
): Promise<void> {
|
|
220
|
-
const data = await loadSession(sessionId)
|
|
221
|
-
if (!data) return
|
|
222
|
-
|
|
223
|
-
;(data.metadata as any).tag = tag
|
|
224
|
-
data.metadata.updatedAt = new Date().toISOString()
|
|
225
|
-
|
|
226
|
-
await saveSession(sessionId, data.messages, data.metadata)
|
|
227
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bundled Skill: commit
|
|
3
|
-
*
|
|
4
|
-
* Create a git commit with a well-crafted message based on staged changes.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { registerSkill } from '../registry.js'
|
|
8
|
-
import type { SkillContentBlock } from '../types.js'
|
|
9
|
-
|
|
10
|
-
const COMMIT_PROMPT = `Create a git commit for the current changes. Follow these steps:
|
|
11
|
-
|
|
12
|
-
1. Run \`git status\` and \`git diff --cached\` to understand what's staged
|
|
13
|
-
2. If nothing is staged, run \`git diff\` to see unstaged changes and suggest what to stage
|
|
14
|
-
3. Analyze the changes and draft a concise commit message that:
|
|
15
|
-
- Uses imperative mood ("Add feature" not "Added feature")
|
|
16
|
-
- Summarizes the "why" not just the "what"
|
|
17
|
-
- Keeps the first line under 72 characters
|
|
18
|
-
- Adds a body with details if the change is complex
|
|
19
|
-
4. Create the commit
|
|
20
|
-
|
|
21
|
-
Do NOT push to remote unless explicitly asked.`
|
|
22
|
-
|
|
23
|
-
export function registerCommitSkill(): void {
|
|
24
|
-
registerSkill({
|
|
25
|
-
name: 'commit',
|
|
26
|
-
description: 'Create a git commit with a well-crafted message based on staged changes.',
|
|
27
|
-
aliases: ['ci'],
|
|
28
|
-
allowedTools: ['Bash', 'Read', 'Glob', 'Grep'],
|
|
29
|
-
userInvocable: true,
|
|
30
|
-
async getPrompt(args): Promise<SkillContentBlock[]> {
|
|
31
|
-
let prompt = COMMIT_PROMPT
|
|
32
|
-
if (args.trim()) {
|
|
33
|
-
prompt += `\n\nAdditional instructions: ${args}`
|
|
34
|
-
}
|
|
35
|
-
return [{ type: 'text', text: prompt }]
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bundled Skills Initialization
|
|
3
|
-
*
|
|
4
|
-
* Registers all built-in skills at SDK startup.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { registerSimplifySkill } from './simplify.js'
|
|
8
|
-
import { registerCommitSkill } from './commit.js'
|
|
9
|
-
import { registerReviewSkill } from './review.js'
|
|
10
|
-
import { registerDebugSkill } from './debug.js'
|
|
11
|
-
import { registerTestSkill } from './test.js'
|
|
12
|
-
|
|
13
|
-
let initialized = false
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initialize all bundled skills.
|
|
17
|
-
* Safe to call multiple times (idempotent).
|
|
18
|
-
*/
|
|
19
|
-
export function initBundledSkills(): void {
|
|
20
|
-
if (initialized) return
|
|
21
|
-
initialized = true
|
|
22
|
-
|
|
23
|
-
registerSimplifySkill()
|
|
24
|
-
registerCommitSkill()
|
|
25
|
-
registerReviewSkill()
|
|
26
|
-
registerDebugSkill()
|
|
27
|
-
registerTestSkill()
|
|
28
|
-
}
|
package/src/skills/index.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skills Module - Public API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Types
|
|
6
|
-
export type {
|
|
7
|
-
SkillDefinition,
|
|
8
|
-
SkillContentBlock,
|
|
9
|
-
SkillResult,
|
|
10
|
-
} from './types.js'
|
|
11
|
-
|
|
12
|
-
// Registry
|
|
13
|
-
export {
|
|
14
|
-
registerSkill,
|
|
15
|
-
getSkill,
|
|
16
|
-
getAllSkills,
|
|
17
|
-
getUserInvocableSkills,
|
|
18
|
-
hasSkill,
|
|
19
|
-
unregisterSkill,
|
|
20
|
-
clearSkills,
|
|
21
|
-
formatSkillsForPrompt,
|
|
22
|
-
} from './registry.js'
|
|
23
|
-
|
|
24
|
-
// Bundled skills
|
|
25
|
-
export { initBundledSkills } from './bundled/index.js'
|
package/src/skills/registry.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skill Registry
|
|
3
|
-
*
|
|
4
|
-
* Central registry for managing skill definitions.
|
|
5
|
-
* Skills can be registered programmatically or loaded from bundled definitions.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { SkillDefinition } from './types.js'
|
|
9
|
-
|
|
10
|
-
/** Internal skill store */
|
|
11
|
-
const skills: Map<string, SkillDefinition> = new Map()
|
|
12
|
-
|
|
13
|
-
/** Alias -> skill name mapping */
|
|
14
|
-
const aliases: Map<string, string> = new Map()
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Register a skill definition.
|
|
18
|
-
*/
|
|
19
|
-
export function registerSkill(definition: SkillDefinition): void {
|
|
20
|
-
skills.set(definition.name, definition)
|
|
21
|
-
|
|
22
|
-
// Register aliases
|
|
23
|
-
if (definition.aliases) {
|
|
24
|
-
for (const alias of definition.aliases) {
|
|
25
|
-
aliases.set(alias, definition.name)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Get a skill by name or alias.
|
|
32
|
-
*/
|
|
33
|
-
export function getSkill(name: string): SkillDefinition | undefined {
|
|
34
|
-
// Direct lookup
|
|
35
|
-
const direct = skills.get(name)
|
|
36
|
-
if (direct) return direct
|
|
37
|
-
|
|
38
|
-
// Alias lookup
|
|
39
|
-
const resolved = aliases.get(name)
|
|
40
|
-
if (resolved) return skills.get(resolved)
|
|
41
|
-
|
|
42
|
-
return undefined
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get all registered skills.
|
|
47
|
-
*/
|
|
48
|
-
export function getAllSkills(): SkillDefinition[] {
|
|
49
|
-
return Array.from(skills.values())
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Get all user-invocable skills (for /command listing).
|
|
54
|
-
*/
|
|
55
|
-
export function getUserInvocableSkills(): SkillDefinition[] {
|
|
56
|
-
return getAllSkills().filter(
|
|
57
|
-
(s) => s.userInvocable !== false && (!s.isEnabled || s.isEnabled()),
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Check if a skill exists.
|
|
63
|
-
*/
|
|
64
|
-
export function hasSkill(name: string): boolean {
|
|
65
|
-
return skills.has(name) || aliases.has(name)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Remove a skill.
|
|
70
|
-
*/
|
|
71
|
-
export function unregisterSkill(name: string): boolean {
|
|
72
|
-
const skill = skills.get(name)
|
|
73
|
-
if (!skill) return false
|
|
74
|
-
|
|
75
|
-
// Remove aliases
|
|
76
|
-
if (skill.aliases) {
|
|
77
|
-
for (const alias of skill.aliases) {
|
|
78
|
-
aliases.delete(alias)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return skills.delete(name)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Clear all skills (for testing).
|
|
87
|
-
*/
|
|
88
|
-
export function clearSkills(): void {
|
|
89
|
-
skills.clear()
|
|
90
|
-
aliases.clear()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Format skills listing for system prompt injection.
|
|
95
|
-
*
|
|
96
|
-
* Uses a budget system: skills listing gets a limited character budget
|
|
97
|
-
* to avoid bloating the context window.
|
|
98
|
-
*/
|
|
99
|
-
export function formatSkillsForPrompt(
|
|
100
|
-
contextWindowTokens?: number,
|
|
101
|
-
): string {
|
|
102
|
-
const invocable = getUserInvocableSkills()
|
|
103
|
-
if (invocable.length === 0) return ''
|
|
104
|
-
|
|
105
|
-
// Budget: 1% of context window in characters (4 chars per token)
|
|
106
|
-
const CHARS_PER_TOKEN = 4
|
|
107
|
-
const DEFAULT_BUDGET = 8000
|
|
108
|
-
const MAX_DESC_CHARS = 250
|
|
109
|
-
const budget = contextWindowTokens
|
|
110
|
-
? Math.floor(contextWindowTokens * 0.01 * CHARS_PER_TOKEN)
|
|
111
|
-
: DEFAULT_BUDGET
|
|
112
|
-
|
|
113
|
-
const lines: string[] = []
|
|
114
|
-
let used = 0
|
|
115
|
-
|
|
116
|
-
for (const skill of invocable) {
|
|
117
|
-
const desc = skill.description.length > MAX_DESC_CHARS
|
|
118
|
-
? skill.description.slice(0, MAX_DESC_CHARS) + '...'
|
|
119
|
-
: skill.description
|
|
120
|
-
|
|
121
|
-
const trigger = skill.whenToUse
|
|
122
|
-
? ` TRIGGER when: ${skill.whenToUse}`
|
|
123
|
-
: ''
|
|
124
|
-
|
|
125
|
-
const line = `- ${skill.name}: ${desc}${trigger}`
|
|
126
|
-
|
|
127
|
-
if (used + line.length > budget) break
|
|
128
|
-
lines.push(line)
|
|
129
|
-
used += line.length
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return lines.join('\n')
|
|
133
|
-
}
|
package/src/skills/types.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skill System Types
|
|
3
|
-
*
|
|
4
|
-
* Skills are reusable prompt templates that extend agent capabilities.
|
|
5
|
-
* They can be invoked by the model via the Skill tool or by users via /skillname.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { ToolContext } from '../types.js'
|
|
9
|
-
import type { HookConfig } from '../hooks.js'
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Content block for skill prompts (compatible with Anthropic API).
|
|
13
|
-
*/
|
|
14
|
-
export type SkillContentBlock =
|
|
15
|
-
| { type: 'text'; text: string }
|
|
16
|
-
| { type: 'image'; source: { type: 'base64'; media_type: string; data: string } }
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Bundled skill definition.
|
|
20
|
-
*
|
|
21
|
-
* Inspired by Claude Code's skill system. Skills provide specialized
|
|
22
|
-
* capabilities by injecting context-specific prompts with optional
|
|
23
|
-
* tool restrictions and model overrides.
|
|
24
|
-
*/
|
|
25
|
-
export interface SkillDefinition {
|
|
26
|
-
/** Unique skill name (e.g., 'simplify', 'commit') */
|
|
27
|
-
name: string
|
|
28
|
-
|
|
29
|
-
/** Human-readable description */
|
|
30
|
-
description: string
|
|
31
|
-
|
|
32
|
-
/** Alternative names for the skill */
|
|
33
|
-
aliases?: string[]
|
|
34
|
-
|
|
35
|
-
/** When the model should invoke this skill (used in system prompt) */
|
|
36
|
-
whenToUse?: string
|
|
37
|
-
|
|
38
|
-
/** Hint for expected arguments */
|
|
39
|
-
argumentHint?: string
|
|
40
|
-
|
|
41
|
-
/** Tools the skill is allowed to use (empty = all tools) */
|
|
42
|
-
allowedTools?: string[]
|
|
43
|
-
|
|
44
|
-
/** Model override for this skill */
|
|
45
|
-
model?: string
|
|
46
|
-
|
|
47
|
-
/** Whether the skill can be invoked by users via /command */
|
|
48
|
-
userInvocable?: boolean
|
|
49
|
-
|
|
50
|
-
/** Runtime check for availability */
|
|
51
|
-
isEnabled?: () => boolean
|
|
52
|
-
|
|
53
|
-
/** Hook overrides while skill is active */
|
|
54
|
-
hooks?: HookConfig
|
|
55
|
-
|
|
56
|
-
/** Execution context: 'inline' runs in current context, 'fork' spawns a subagent */
|
|
57
|
-
context?: 'inline' | 'fork'
|
|
58
|
-
|
|
59
|
-
/** Subagent type for forked execution */
|
|
60
|
-
agent?: string
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Generate the prompt content blocks for this skill.
|
|
64
|
-
*
|
|
65
|
-
* @param args - User-provided arguments (e.g., from "/simplify focus on error handling")
|
|
66
|
-
* @param context - Tool execution context (cwd, etc.)
|
|
67
|
-
* @returns Content blocks to inject into the conversation
|
|
68
|
-
*/
|
|
69
|
-
getPrompt: (
|
|
70
|
-
args: string,
|
|
71
|
-
context: ToolContext,
|
|
72
|
-
) => Promise<SkillContentBlock[]>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Result of executing a skill.
|
|
77
|
-
*/
|
|
78
|
-
export interface SkillResult {
|
|
79
|
-
/** Whether execution succeeded */
|
|
80
|
-
success: boolean
|
|
81
|
-
|
|
82
|
-
/** Skill name that was executed */
|
|
83
|
-
skillName: string
|
|
84
|
-
|
|
85
|
-
/** Execution status */
|
|
86
|
-
status: 'inline' | 'forked'
|
|
87
|
-
|
|
88
|
-
/** Allowed tools override (for inline execution) */
|
|
89
|
-
allowedTools?: string[]
|
|
90
|
-
|
|
91
|
-
/** Model override */
|
|
92
|
-
model?: string
|
|
93
|
-
|
|
94
|
-
/** Result text (for forked execution) */
|
|
95
|
-
result?: string
|
|
96
|
-
|
|
97
|
-
/** Error message */
|
|
98
|
-
error?: string
|
|
99
|
-
}
|