@archships/dim-agent-sdk 0.0.1

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 (78) hide show
  1. package/README.md +69 -0
  2. package/dist/agent-core/Agent.d.ts +29 -0
  3. package/dist/agent-core/LoopRunner.d.ts +30 -0
  4. package/dist/agent-core/MessageFactory.d.ts +20 -0
  5. package/dist/agent-core/ModelTurnCollector.d.ts +22 -0
  6. package/dist/agent-core/Session.d.ts +48 -0
  7. package/dist/agent-core/TerminationPolicy.d.ts +14 -0
  8. package/dist/agent-core/ToolExecutor.d.ts +27 -0
  9. package/dist/agent-core/agent-types.d.ts +26 -0
  10. package/dist/agent-core/createModel.d.ts +2 -0
  11. package/dist/agent-core/errors.d.ts +5 -0
  12. package/dist/agent-core/index.d.ts +13 -0
  13. package/dist/agent-core/session-state.d.ts +17 -0
  14. package/dist/agent-core/tool-call.d.ts +9 -0
  15. package/dist/context/AutoContextManager.d.ts +21 -0
  16. package/dist/context/index.d.ts +3 -0
  17. package/dist/context/types.d.ts +19 -0
  18. package/dist/contracts/common.d.ts +19 -0
  19. package/dist/contracts/content-normalize.d.ts +6 -0
  20. package/dist/contracts/content.d.ts +16 -0
  21. package/dist/contracts/event.d.ts +30 -0
  22. package/dist/contracts/index.d.ts +9 -0
  23. package/dist/contracts/message.d.ts +32 -0
  24. package/dist/contracts/model.d.ts +73 -0
  25. package/dist/contracts/state.d.ts +14 -0
  26. package/dist/contracts/tool-normalize.d.ts +3 -0
  27. package/dist/contracts/tool.d.ts +40 -0
  28. package/dist/index.d.ts +16 -0
  29. package/dist/index.js +2997 -0
  30. package/dist/persistence/FileStateStore.d.ts +14 -0
  31. package/dist/persistence/InMemoryStateStore.d.ts +9 -0
  32. package/dist/persistence/SnapshotCodec.d.ts +20 -0
  33. package/dist/persistence/index.d.ts +6 -0
  34. package/dist/persistence/store.d.ts +7 -0
  35. package/dist/plugin-host/HookPipeline.d.ts +7 -0
  36. package/dist/plugin-host/PluginHost.d.ts +36 -0
  37. package/dist/plugin-host/helpers.d.ts +3 -0
  38. package/dist/plugin-host/index.d.ts +4 -0
  39. package/dist/plugin-host/types.d.ts +1 -0
  40. package/dist/providers/anthropic/adapter.d.ts +13 -0
  41. package/dist/providers/anthropic/mapper.d.ts +28 -0
  42. package/dist/providers/gemini/adapter.d.ts +12 -0
  43. package/dist/providers/gemini/mapper.d.ts +30 -0
  44. package/dist/providers/index.d.ts +8 -0
  45. package/dist/providers/openai/adapter.d.ts +12 -0
  46. package/dist/providers/openai/mapper.d.ts +15 -0
  47. package/dist/providers/openai-responses/adapter.d.ts +12 -0
  48. package/dist/providers/openai-responses/mapper.d.ts +40 -0
  49. package/dist/providers/shared/http-error.d.ts +7 -0
  50. package/dist/providers/shared/provider-state.d.ts +4 -0
  51. package/dist/providers/shared/reasoning.d.ts +14 -0
  52. package/dist/providers/shared/tool-call.d.ts +5 -0
  53. package/dist/providers/shared/usage.d.ts +2 -0
  54. package/dist/services/ExecGateway.d.ts +14 -0
  55. package/dist/services/FileSystemGateway.d.ts +35 -0
  56. package/dist/services/GitGateway.d.ts +17 -0
  57. package/dist/services/ModelGateway.d.ts +7 -0
  58. package/dist/services/NetworkGateway.d.ts +6 -0
  59. package/dist/services/PermissionGateway.d.ts +11 -0
  60. package/dist/services/activity.d.ts +10 -0
  61. package/dist/services/index.d.ts +10 -0
  62. package/dist/services/permissions.d.ts +17 -0
  63. package/dist/services/types.d.ts +77 -0
  64. package/dist/tools/BaseTool.d.ts +6 -0
  65. package/dist/tools/ToolRegistry.d.ts +9 -0
  66. package/dist/tools/builtins/EditTool.d.ts +6 -0
  67. package/dist/tools/builtins/ExecTool.d.ts +6 -0
  68. package/dist/tools/builtins/ReadTool.d.ts +6 -0
  69. package/dist/tools/builtins/WriteTool.d.ts +6 -0
  70. package/dist/tools/builtins/index.d.ts +4 -0
  71. package/dist/tools/builtins/utils.d.ts +6 -0
  72. package/dist/tools/index.d.ts +4 -0
  73. package/dist/tools/result.d.ts +3 -0
  74. package/dist/utils/guards.d.ts +2 -0
  75. package/dist/utils/id.d.ts +1 -0
  76. package/dist/utils/json.d.ts +3 -0
  77. package/dist/utils/usage.d.ts +3 -0
  78. package/package.json +54 -0
@@ -0,0 +1,14 @@
1
+ import type { SessionSnapshot } from '../contracts/state';
2
+ import type { StateStore } from './store';
3
+ export interface FileStateStoreOptions {
4
+ directory: string;
5
+ }
6
+ export declare class FileStateStore implements StateStore {
7
+ readonly directory: string;
8
+ constructor(options: FileStateStoreOptions);
9
+ save(snapshot: SessionSnapshot): Promise<void>;
10
+ load(sessionId: string): Promise<SessionSnapshot | null>;
11
+ delete(sessionId: string): Promise<void>;
12
+ list(): Promise<SessionSnapshot[]>;
13
+ private filePath;
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { SessionSnapshot } from '../contracts/state';
2
+ import type { StateStore } from './store';
3
+ export declare class InMemoryStateStore implements StateStore {
4
+ private readonly snapshots;
5
+ save(snapshot: SessionSnapshot): Promise<void>;
6
+ load(sessionId: string): Promise<SessionSnapshot | null>;
7
+ delete(sessionId: string): Promise<void>;
8
+ list(): Promise<SessionSnapshot[]>;
9
+ }
@@ -0,0 +1,20 @@
1
+ import type { Message, ModelRef, SessionSnapshot, Usage } from '../contracts';
2
+ export interface SnapshotCodecInput {
3
+ sessionId: string;
4
+ model?: ModelRef;
5
+ cwd?: string;
6
+ messages: Message[];
7
+ usage?: Usage;
8
+ createdAt: number;
9
+ updatedAt: number;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export interface SnapshotCodec {
13
+ encode(input: SnapshotCodecInput): SessionSnapshot;
14
+ decode(value: unknown): SessionSnapshot;
15
+ }
16
+ export declare class JsonSnapshotCodec implements SnapshotCodec {
17
+ encode(input: SnapshotCodecInput): SessionSnapshot;
18
+ decode(value: unknown): SessionSnapshot;
19
+ }
20
+ export declare const sessionSnapshotCodec: JsonSnapshotCodec;
@@ -0,0 +1,6 @@
1
+ export { FileStateStore } from './FileStateStore';
2
+ export type { FileStateStoreOptions } from './FileStateStore';
3
+ export { InMemoryStateStore } from './InMemoryStateStore';
4
+ export { JsonSnapshotCodec, sessionSnapshotCodec } from './SnapshotCodec';
5
+ export type { SnapshotCodec, SnapshotCodecInput } from './SnapshotCodec';
6
+ export type { StateStore } from './store';
@@ -0,0 +1,7 @@
1
+ import type { SessionSnapshot } from '../contracts/state';
2
+ export interface StateStore {
3
+ save(snapshot: SessionSnapshot): Promise<void>;
4
+ load(sessionId: string): Promise<SessionSnapshot | null>;
5
+ delete(sessionId: string): Promise<void>;
6
+ list(): Promise<SessionSnapshot[]>;
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { HookName, HookPayloadMap, HookRegistration, PluginRuntimeContext } from './types';
2
+ export declare class HookPipeline {
3
+ private readonly registrations;
4
+ register(pluginId: string, priority: number, hooks?: HookRegistration): void;
5
+ runMiddleware<N extends HookName>(name: N, payload: HookPayloadMap[N], context: PluginRuntimeContext): Promise<HookPayloadMap[N]>;
6
+ runObservers<N extends HookName>(name: N, payload: HookPayloadMap[N], context: PluginRuntimeContext): Promise<void>;
7
+ }
@@ -0,0 +1,36 @@
1
+ import type { ContextItem } from '../context';
2
+ import { PermissionGateway } from '../services';
3
+ import type { ActivityTracker, AgentServices } from '../services';
4
+ import type { Tool } from '../contracts';
5
+ import { HookPipeline } from './HookPipeline';
6
+ import type { ContextContributorInput, DimPlugin, PluginRuntimeContext, PromptContributorInput } from './types';
7
+ export interface PluginHostOptions {
8
+ agentId: string;
9
+ cwd?: string;
10
+ plugins?: DimPlugin[];
11
+ services: AgentServices;
12
+ permissionGateway: PermissionGateway;
13
+ tracker?: ActivityTracker;
14
+ }
15
+ export declare class PluginHost {
16
+ readonly pipeline: HookPipeline;
17
+ private readonly contextContributors;
18
+ private readonly promptContributors;
19
+ private readonly tools;
20
+ private readonly services;
21
+ private readonly cwd?;
22
+ private readonly agentId;
23
+ private readonly tracker?;
24
+ constructor(options: PluginHostOptions);
25
+ pluginTools(): Tool[];
26
+ recentFiles(limit?: number): string[];
27
+ runMiddleware<N extends keyof import('./types').HookPayloadMap>(name: N, payload: import('./types').HookPayloadMap[N], context?: Omit<PluginRuntimeContext, 'agentId' | 'services'> & {
28
+ services?: AgentServices;
29
+ }): Promise<import('./types').HookPayloadMap[N]>;
30
+ runObservers<N extends keyof import('./types').HookPayloadMap>(name: N, payload: import('./types').HookPayloadMap[N], context?: Omit<PluginRuntimeContext, 'agentId' | 'services'> & {
31
+ services?: AgentServices;
32
+ }): Promise<void>;
33
+ collectContext(input: ContextContributorInput): Promise<ContextItem[]>;
34
+ collectPromptSegments(input: PromptContributorInput): Promise<string[]>;
35
+ private createRuntimeContext;
36
+ }
@@ -0,0 +1,3 @@
1
+ import type { HookControlResult } from '@archships/dim-plugin-api';
2
+ export { continueHook, replaceHook, stopHook } from '@archships/dim-plugin-api';
3
+ export declare function isHookControlResult<T>(value: unknown): value is HookControlResult<T>;
@@ -0,0 +1,4 @@
1
+ export { continueHook, replaceHook, stopHook } from './helpers';
2
+ export { HookPipeline } from './HookPipeline';
3
+ export { PluginHost } from './PluginHost';
4
+ export type { AgentMode, ContextContributor, ContextContributorInput, DimPlugin, HookControlResult, HookHandler, HookMiddleware, HookName, HookObserver, HookPayloadMap, HookRegistration, PluginContext, PluginManifest, PluginRuntimeContext, PluginSetupResult, PromptContributor, PromptContributorInput, } from './types';
@@ -0,0 +1 @@
1
+ export type { AgentMode, CallToolResult, ContextContributor, ContextContributorInput, ContextItem, DimPlugin, HookControlResult, HookHandler, HookMiddleware, HookName, HookObserver, HookPayloadMap, HookRegistration, PermissionSpec, PluginContext, PluginManifest, PluginRuntimeContext, PluginServices, PluginSetupResult, PromptContributor, PromptContributorInput, Tool, ToolCall, ToolDefinition, } from '@archships/dim-plugin-api';
@@ -0,0 +1,13 @@
1
+ import type { ConfiguredModelAdapter } from '../../contracts';
2
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface AnthropicAdapterOptions {
4
+ apiKey?: string;
5
+ baseUrl?: string;
6
+ defaultModel: string;
7
+ provider?: string;
8
+ fetch?: FetchLike;
9
+ headers?: Record<string, string>;
10
+ anthropicVersion?: string;
11
+ }
12
+ export declare function createAnthropicAdapter(options: AnthropicAdapterOptions): ConfiguredModelAdapter;
13
+ export {};
@@ -0,0 +1,28 @@
1
+ import type { Message, ModelStopReason, ToolDefinition } from '../../contracts';
2
+ import type { RawToolCallPayload } from '../shared/tool-call';
3
+ export type AnthropicThinkingBlock = {
4
+ type: 'thinking';
5
+ thinking?: string;
6
+ signature?: string;
7
+ } | {
8
+ type: 'redacted_thinking';
9
+ data?: string;
10
+ };
11
+ export type AnthropicContentBlock = {
12
+ type: 'text';
13
+ text?: string;
14
+ } | AnthropicThinkingBlock | {
15
+ type: 'tool_use';
16
+ id?: string;
17
+ name?: string;
18
+ input?: Record<string, unknown>;
19
+ };
20
+ export declare function mapToolDefinitionsToAnthropic(tools: ToolDefinition[] | undefined): unknown[] | undefined;
21
+ export declare function mapAnthropicStopReason(reason: unknown, toolCallCount: number): ModelStopReason;
22
+ export declare function messagesToAnthropic(messages: Message[]): {
23
+ system?: string;
24
+ messages: unknown[];
25
+ };
26
+ export declare function normalizeAnthropicToolCalls(value: AnthropicContentBlock[] | undefined): RawToolCallPayload[];
27
+ export declare function extractAnthropicThinking(value: AnthropicContentBlock[] | undefined): string[];
28
+ export declare function createAnthropicThinkingState(value: AnthropicContentBlock[] | undefined): Record<string, unknown> | undefined;
@@ -0,0 +1,12 @@
1
+ import type { ConfiguredModelAdapter } from '../../contracts';
2
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface GeminiAdapterOptions {
4
+ apiKey?: string;
5
+ baseUrl?: string;
6
+ defaultModel: string;
7
+ provider?: string;
8
+ fetch?: FetchLike;
9
+ headers?: Record<string, string>;
10
+ }
11
+ export declare function createGeminiAdapter(options: GeminiAdapterOptions): ConfiguredModelAdapter;
12
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { Message, ModelStopReason, ToolDefinition } from '../../contracts';
2
+ import type { RawToolCallPayload } from '../shared/tool-call';
3
+ export type GeminiPart = {
4
+ text?: string;
5
+ thought?: boolean;
6
+ thoughtSignature?: string;
7
+ } | {
8
+ functionCall?: {
9
+ name?: string;
10
+ args?: Record<string, unknown>;
11
+ };
12
+ thought?: boolean;
13
+ thoughtSignature?: string;
14
+ };
15
+ export declare function mapToolDefinitionsToGemini(tools: ToolDefinition[] | undefined): {
16
+ tools?: unknown[];
17
+ toolConfig?: unknown;
18
+ };
19
+ export declare function mapGeminiStopReason(reason: unknown, toolCallCount: number): ModelStopReason;
20
+ export declare function messagesToGemini(messages: Message[]): {
21
+ contents: unknown[];
22
+ systemInstruction?: {
23
+ parts: Array<{
24
+ text: string;
25
+ }>;
26
+ };
27
+ };
28
+ export declare function normalizeGeminiToolCalls(value: GeminiPart[] | undefined): RawToolCallPayload[];
29
+ export declare function extractGeminiThinking(value: GeminiPart[] | undefined): string[];
30
+ export declare function createGeminiThoughtState(value: GeminiPart[] | undefined): Record<string, unknown> | undefined;
@@ -0,0 +1,8 @@
1
+ export { createAnthropicAdapter } from './anthropic/adapter';
2
+ export type { AnthropicAdapterOptions } from './anthropic/adapter';
3
+ export { createGeminiAdapter } from './gemini/adapter';
4
+ export type { GeminiAdapterOptions } from './gemini/adapter';
5
+ export { createOpenAIAdapter } from './openai/adapter';
6
+ export type { OpenAIAdapterOptions } from './openai/adapter';
7
+ export { createOpenAIResponsesAdapter } from './openai-responses/adapter';
8
+ export type { OpenAIResponsesAdapterOptions } from './openai-responses/adapter';
@@ -0,0 +1,12 @@
1
+ import type { ConfiguredModelAdapter } from '../../contracts';
2
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface OpenAIAdapterOptions {
4
+ apiKey?: string;
5
+ baseUrl?: string;
6
+ defaultModel: string;
7
+ provider?: string;
8
+ fetch?: FetchLike;
9
+ headers?: Record<string, string>;
10
+ }
11
+ export declare function createOpenAIAdapter(options: OpenAIAdapterOptions): ConfiguredModelAdapter;
12
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { ContentBlock, Message, ModelStopReason, ToolDefinition } from '../../contracts';
2
+ import type { RawToolCallPayload } from '../shared/tool-call';
3
+ export declare function mapToolDefinitionsToOpenAI(tools: ToolDefinition[] | undefined): unknown[] | undefined;
4
+ export declare function mapOpenAIStopReason(reason: unknown, toolCallCount: number): ModelStopReason;
5
+ export declare function messageContentToOpenAI(content: ContentBlock[]): string | Array<Record<string, unknown>>;
6
+ export declare function messagesToOpenAI(messages: Message[]): unknown[];
7
+ type OpenAIToolCallPayload = {
8
+ id?: string;
9
+ function?: {
10
+ name?: string;
11
+ arguments?: string;
12
+ };
13
+ };
14
+ export declare function normalizeOpenAIToolCalls(value: OpenAIToolCallPayload[] | undefined): RawToolCallPayload[];
15
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { ConfiguredModelAdapter } from '../../contracts';
2
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
+ export interface OpenAIResponsesAdapterOptions {
4
+ apiKey?: string;
5
+ baseUrl?: string;
6
+ defaultModel: string;
7
+ provider?: string;
8
+ fetch?: FetchLike;
9
+ headers?: Record<string, string>;
10
+ }
11
+ export declare function createOpenAIResponsesAdapter(options: OpenAIResponsesAdapterOptions): ConfiguredModelAdapter;
12
+ export {};
@@ -0,0 +1,40 @@
1
+ import type { Message, ModelStopReason } from '../../contracts';
2
+ import type { RawToolCallPayload } from '../shared/tool-call';
3
+ export interface OpenAIResponsesRequestPayload {
4
+ instructions?: string;
5
+ input: unknown[];
6
+ previousResponseId?: string;
7
+ }
8
+ export interface OpenAIResponsesTextPart {
9
+ type?: string;
10
+ text?: string;
11
+ }
12
+ export interface OpenAIResponsesOutputItem {
13
+ type?: string;
14
+ id?: string;
15
+ call_id?: string;
16
+ name?: string;
17
+ arguments?: string | Record<string, unknown>;
18
+ role?: string;
19
+ encrypted_content?: string | null;
20
+ summary?: Array<{
21
+ type?: string;
22
+ text?: string;
23
+ }>;
24
+ content?: OpenAIResponsesTextPart[];
25
+ }
26
+ export type OpenAIResponsesState = Record<string, unknown> & {
27
+ responseId: string;
28
+ };
29
+ export declare function mapToolDefinitionsToOpenAIResponses(tools: import('../../contracts').ToolDefinition[] | undefined): unknown[] | undefined;
30
+ export declare function mapOpenAIResponsesStopReason(response: {
31
+ status?: string;
32
+ incomplete_details?: {
33
+ reason?: string | null;
34
+ };
35
+ } | undefined, toolCallCount: number): ModelStopReason;
36
+ export declare function messagesToOpenAIResponses(messages: Message[]): OpenAIResponsesRequestPayload;
37
+ export declare function normalizeOpenAIResponsesToolCalls(output: OpenAIResponsesOutputItem[] | undefined): RawToolCallPayload[];
38
+ export declare function extractOpenAIResponsesText(output: OpenAIResponsesOutputItem[] | undefined): string[];
39
+ export declare function extractOpenAIResponsesThinking(output: OpenAIResponsesOutputItem[] | undefined): string[];
40
+ export declare function createOpenAIResponsesState(responseId: string | undefined): OpenAIResponsesState | undefined;
@@ -0,0 +1,7 @@
1
+ import type { ModelErrorPayload } from '../../contracts';
2
+ export declare function createHttpErrorPayload(input: {
3
+ code: string;
4
+ provider: string;
5
+ endpoint: string;
6
+ response: Response;
7
+ }): Promise<ModelErrorPayload>;
@@ -0,0 +1,4 @@
1
+ import type { Message } from '../../contracts';
2
+ export declare const PROVIDER_STATE_METADATA_KEY = "_dimProviderState";
3
+ export declare function attachProviderState(metadata: Record<string, unknown> | undefined, provider: string, state: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
4
+ export declare function readProviderState(message: Message, provider: string): Record<string, unknown> | undefined;
@@ -0,0 +1,14 @@
1
+ export declare function normalizeReasoningConfig(reasoning: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
2
+ export declare function resolveReasoningBudget(reasoning: Record<string, unknown> | undefined, fallback?: number): number | undefined;
3
+ export declare function buildOpenAIResponsesReasoning(reasoning: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
4
+ export declare function buildAnthropicThinking(reasoning: Record<string, unknown> | undefined): {
5
+ maxTokens?: number;
6
+ thinking?: {
7
+ type: 'enabled';
8
+ budget_tokens: number;
9
+ };
10
+ };
11
+ export declare function buildGeminiThinkingConfig(reasoning: Record<string, unknown> | undefined): {
12
+ thinkingBudget: number;
13
+ includeThoughts: boolean;
14
+ } | undefined;
@@ -0,0 +1,5 @@
1
+ export interface RawToolCallPayload {
2
+ id: string;
3
+ name: string;
4
+ argsText: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { Usage } from '../../contracts';
2
+ export declare function normalizeUsage(raw: unknown): Usage | undefined;
@@ -0,0 +1,14 @@
1
+ import { ActivityTracker } from './activity';
2
+ import type { ExecGateway, ExecOptions, ExecResult } from './types';
3
+ export interface ExecGatewayOptions {
4
+ cwd?: string;
5
+ env?: Record<string, string>;
6
+ tracker?: ActivityTracker;
7
+ }
8
+ export declare class NodeExecGateway implements ExecGateway {
9
+ private readonly cwd?;
10
+ private readonly env;
11
+ private readonly tracker?;
12
+ constructor(options?: ExecGatewayOptions);
13
+ execute(command: string, options?: ExecOptions): Promise<ExecResult>;
14
+ }
@@ -0,0 +1,35 @@
1
+ import { ActivityTracker } from './activity';
2
+ import type { FileSystemGateway, GlobOptions, GrepMatch, GrepOptions } from './types';
3
+ export interface FileSystemGatewayOptions {
4
+ cwd?: string;
5
+ tracker?: ActivityTracker;
6
+ }
7
+ export declare class NodeFileSystemGateway implements FileSystemGateway {
8
+ private readonly cwd?;
9
+ private readonly tracker?;
10
+ constructor(options?: FileSystemGatewayOptions);
11
+ readText(targetPath: string, options?: {
12
+ cwd?: string;
13
+ }): Promise<string>;
14
+ writeText(targetPath: string, content: string, options?: {
15
+ cwd?: string;
16
+ }): Promise<{
17
+ path: string;
18
+ bytes: number;
19
+ }>;
20
+ editText(targetPath: string, options: {
21
+ oldText: string;
22
+ newText: string;
23
+ replaceAll?: boolean;
24
+ cwd?: string;
25
+ }): Promise<{
26
+ path: string;
27
+ replacements: number;
28
+ }>;
29
+ exists(targetPath: string, options?: {
30
+ cwd?: string;
31
+ }): Promise<boolean>;
32
+ glob(pattern: string, options?: GlobOptions): Promise<string[]>;
33
+ grep(query: string, options?: GrepOptions): Promise<GrepMatch[]>;
34
+ private recordFile;
35
+ }
@@ -0,0 +1,17 @@
1
+ import type { ExecGateway, GitGateway } from './types';
2
+ export interface GitGatewayOptions {
3
+ exec: ExecGateway;
4
+ cwd?: string;
5
+ }
6
+ export declare class DefaultGitGateway implements GitGateway {
7
+ private readonly exec;
8
+ private readonly cwd?;
9
+ constructor(options: GitGatewayOptions);
10
+ status(options?: {
11
+ cwd?: string;
12
+ }): Promise<string | null>;
13
+ diff(options?: {
14
+ cwd?: string;
15
+ }): Promise<string | null>;
16
+ private runGitCommand;
17
+ }
@@ -0,0 +1,7 @@
1
+ import type { ModelClient, ModelRequest, ModelStreamEvent } from '../contracts';
2
+ import type { ModelGateway } from './types';
3
+ export declare class DefaultModelGateway implements ModelGateway {
4
+ private readonly model;
5
+ constructor(model: ModelClient);
6
+ stream(request: ModelRequest): AsyncIterable<ModelStreamEvent>;
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { NetworkGateway } from './types';
2
+ export declare class DefaultNetworkGateway implements NetworkGateway {
3
+ private readonly fetchImpl;
4
+ constructor(fetchImpl?: typeof fetch);
5
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
6
+ }
@@ -0,0 +1,11 @@
1
+ import type { AgentServices } from './types';
2
+ import type { PermissionSpec } from './permissions';
3
+ export interface PermissionGatewayOptions {
4
+ permissions?: PermissionSpec;
5
+ }
6
+ export declare class PermissionGateway {
7
+ private readonly permissions;
8
+ constructor(options?: PermissionGatewayOptions);
9
+ get agentPermissions(): PermissionSpec;
10
+ scopeServices(services: AgentServices, pluginId: string, requested?: PermissionSpec): AgentServices;
11
+ }
@@ -0,0 +1,10 @@
1
+ export interface ActivityRecord {
2
+ type: 'file' | 'command';
3
+ label: string;
4
+ timestamp: number;
5
+ }
6
+ export declare class ActivityTracker {
7
+ private readonly records;
8
+ record(record: ActivityRecord): void;
9
+ recentFiles(limit?: number): string[];
10
+ }
@@ -0,0 +1,10 @@
1
+ export { ActivityTracker } from './activity';
2
+ export { NodeExecGateway } from './ExecGateway';
3
+ export { NodeFileSystemGateway } from './FileSystemGateway';
4
+ export { DefaultGitGateway } from './GitGateway';
5
+ export { DefaultModelGateway } from './ModelGateway';
6
+ export { DefaultNetworkGateway } from './NetworkGateway';
7
+ export { PermissionDeniedError, fullPermissions, normalizePermissions } from './permissions';
8
+ export type { FileSystemPermission, PermissionSpec } from './permissions';
9
+ export { PermissionGateway } from './PermissionGateway';
10
+ export type { AgentServices, ExecGateway, ExecOptions, ExecResult, FileSystemGateway, GitGateway, GlobOptions, GrepMatch, GrepOptions, ModelGateway, NetworkGateway, } from './types';
@@ -0,0 +1,17 @@
1
+ export type FileSystemPermission = boolean | 'read' | 'write' | 'full';
2
+ export interface PermissionSpec {
3
+ fs?: FileSystemPermission;
4
+ git?: boolean;
5
+ network?: boolean;
6
+ process?: boolean;
7
+ model?: boolean;
8
+ mcp?: boolean;
9
+ }
10
+ export declare const fullPermissions: PermissionSpec;
11
+ export declare class PermissionDeniedError extends Error {
12
+ readonly code = "permission_denied";
13
+ constructor(message: string);
14
+ }
15
+ export declare function normalizePermissions(input?: PermissionSpec): PermissionSpec;
16
+ export declare function canReadFs(permissions: PermissionSpec): boolean;
17
+ export declare function canWriteFs(permissions: PermissionSpec): boolean;
@@ -0,0 +1,77 @@
1
+ import type { ModelRequest, ModelStreamEvent } from '../contracts';
2
+ export interface ExecOptions {
3
+ cwd?: string;
4
+ env?: Record<string, string>;
5
+ timeoutMs?: number;
6
+ signal?: AbortSignal;
7
+ }
8
+ export interface ExecResult {
9
+ command: string;
10
+ cwd: string | null;
11
+ stdout: string;
12
+ stderr: string;
13
+ exitCode: number | null;
14
+ signal: string | null;
15
+ timedOut?: boolean;
16
+ }
17
+ export interface GlobOptions {
18
+ cwd?: string;
19
+ limit?: number;
20
+ }
21
+ export interface GrepOptions extends GlobOptions {
22
+ pattern?: string;
23
+ }
24
+ export interface GrepMatch {
25
+ path: string;
26
+ lineNumber: number;
27
+ line: string;
28
+ }
29
+ export interface FileSystemGateway {
30
+ readText(path: string, options?: {
31
+ cwd?: string;
32
+ }): Promise<string>;
33
+ writeText(path: string, content: string, options?: {
34
+ cwd?: string;
35
+ }): Promise<{
36
+ path: string;
37
+ bytes: number;
38
+ }>;
39
+ editText(path: string, options: {
40
+ oldText: string;
41
+ newText: string;
42
+ replaceAll?: boolean;
43
+ cwd?: string;
44
+ }): Promise<{
45
+ path: string;
46
+ replacements: number;
47
+ }>;
48
+ exists(path: string, options?: {
49
+ cwd?: string;
50
+ }): Promise<boolean>;
51
+ glob(pattern: string, options?: GlobOptions): Promise<string[]>;
52
+ grep(query: string, options?: GrepOptions): Promise<GrepMatch[]>;
53
+ }
54
+ export interface ExecGateway {
55
+ execute(command: string, options?: ExecOptions): Promise<ExecResult>;
56
+ }
57
+ export interface GitGateway {
58
+ status(options?: {
59
+ cwd?: string;
60
+ }): Promise<string | null>;
61
+ diff(options?: {
62
+ cwd?: string;
63
+ }): Promise<string | null>;
64
+ }
65
+ export interface NetworkGateway {
66
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
67
+ }
68
+ export interface ModelGateway {
69
+ stream(request: ModelRequest): AsyncIterable<ModelStreamEvent>;
70
+ }
71
+ export interface AgentServices {
72
+ fileSystem: FileSystemGateway;
73
+ exec: ExecGateway;
74
+ git: GitGateway;
75
+ network: NetworkGateway;
76
+ model: ModelGateway;
77
+ }
@@ -0,0 +1,6 @@
1
+ import type { CallToolResult, Tool, ToolDefinition, ToolExecutionContext } from '../contracts/tool';
2
+ export declare abstract class BaseTool implements Tool {
3
+ readonly definition: ToolDefinition;
4
+ constructor(definition: ToolDefinition);
5
+ abstract execute(args: Record<string, unknown>, context: ToolExecutionContext): Promise<CallToolResult>;
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { Tool, ToolDefinition } from '../contracts/tool';
2
+ export declare class ToolRegistry {
3
+ private readonly tools;
4
+ register(tool: Tool): this;
5
+ unregister(name: string): boolean;
6
+ get(name: string): Tool | undefined;
7
+ list(): Tool[];
8
+ definitions(): ToolDefinition[];
9
+ }
@@ -0,0 +1,6 @@
1
+ import type { CallToolResult, ToolExecutionContext } from '../../contracts/tool';
2
+ import { BaseTool } from '../BaseTool';
3
+ export declare class EditTool extends BaseTool {
4
+ constructor();
5
+ execute(args: Record<string, unknown>, context: ToolExecutionContext): Promise<CallToolResult>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { CallToolResult, ToolExecutionContext } from '../../contracts/tool';
2
+ import { BaseTool } from '../BaseTool';
3
+ export declare class ExecTool extends BaseTool {
4
+ constructor();
5
+ execute(args: Record<string, unknown>, context: ToolExecutionContext): Promise<CallToolResult>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { CallToolResult, ToolExecutionContext } from '../../contracts/tool';
2
+ import { BaseTool } from '../BaseTool';
3
+ export declare class ReadTool extends BaseTool {
4
+ constructor();
5
+ execute(args: Record<string, unknown>, context: ToolExecutionContext): Promise<CallToolResult>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import type { CallToolResult, ToolExecutionContext } from '../../contracts/tool';
2
+ import { BaseTool } from '../BaseTool';
3
+ export declare class WriteTool extends BaseTool {
4
+ constructor();
5
+ execute(args: Record<string, unknown>, context: ToolExecutionContext): Promise<CallToolResult>;
6
+ }
@@ -0,0 +1,4 @@
1
+ export { EditTool } from './EditTool';
2
+ export { ExecTool } from './ExecTool';
3
+ export { ReadTool } from './ReadTool';
4
+ export { WriteTool } from './WriteTool';
@@ -0,0 +1,6 @@
1
+ export declare function resolvePathFromCwd(cwd: string | undefined, targetPath: string): string;
2
+ export declare function readStringArg(args: Record<string, unknown>, key: string, options?: {
3
+ allowEmpty?: boolean;
4
+ }): string;
5
+ export declare function readOptionalBooleanArg(args: Record<string, unknown>, key: string): boolean | undefined;
6
+ export declare function readOptionalNumberArg(args: Record<string, unknown>, key: string): number | undefined;
@@ -0,0 +1,4 @@
1
+ export { BaseTool } from './BaseTool';
2
+ export { errorToolResult, textToolResult } from './result';
3
+ export { ToolRegistry } from './ToolRegistry';
4
+ export * from './builtins';