@clinebot/agents 0.0.0

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 (90) hide show
  1. package/README.md +145 -0
  2. package/dist/agent-input.d.ts +2 -0
  3. package/dist/agent.d.ts +56 -0
  4. package/dist/extensions.d.ts +21 -0
  5. package/dist/hooks/engine.d.ts +42 -0
  6. package/dist/hooks/index.d.ts +2 -0
  7. package/dist/hooks/lifecycle.d.ts +5 -0
  8. package/dist/hooks/node.d.ts +2 -0
  9. package/dist/hooks/subprocess-runner.d.ts +16 -0
  10. package/dist/hooks/subprocess.d.ts +268 -0
  11. package/dist/index.browser.d.ts +1 -0
  12. package/dist/index.browser.js +49 -0
  13. package/dist/index.d.ts +15 -0
  14. package/dist/index.js +49 -0
  15. package/dist/index.node.d.ts +5 -0
  16. package/dist/index.node.js +49 -0
  17. package/dist/mcp/index.d.ts +4 -0
  18. package/dist/mcp/policies.d.ts +14 -0
  19. package/dist/mcp/tools.d.ts +9 -0
  20. package/dist/mcp/types.d.ts +35 -0
  21. package/dist/message-builder.d.ts +31 -0
  22. package/dist/prompts/cline.d.ts +1 -0
  23. package/dist/prompts/index.d.ts +1 -0
  24. package/dist/runtime/agent-runtime-bus.d.ts +13 -0
  25. package/dist/runtime/conversation-store.d.ts +16 -0
  26. package/dist/runtime/lifecycle-orchestrator.d.ts +28 -0
  27. package/dist/runtime/tool-orchestrator.d.ts +39 -0
  28. package/dist/runtime/turn-processor.d.ts +21 -0
  29. package/dist/teams/index.d.ts +3 -0
  30. package/dist/teams/multi-agent.d.ts +566 -0
  31. package/dist/teams/spawn-agent-tool.d.ts +85 -0
  32. package/dist/teams/team-tools.d.ts +51 -0
  33. package/dist/tools/ask-question.d.ts +12 -0
  34. package/dist/tools/create.d.ts +59 -0
  35. package/dist/tools/execution.d.ts +61 -0
  36. package/dist/tools/formatting.d.ts +20 -0
  37. package/dist/tools/index.d.ts +11 -0
  38. package/dist/tools/registry.d.ts +26 -0
  39. package/dist/tools/validation.d.ts +27 -0
  40. package/dist/types.d.ts +826 -0
  41. package/package.json +54 -0
  42. package/src/agent-input.ts +116 -0
  43. package/src/agent.test.ts +931 -0
  44. package/src/agent.ts +1050 -0
  45. package/src/example.test.ts +564 -0
  46. package/src/extensions.ts +337 -0
  47. package/src/hooks/engine.test.ts +163 -0
  48. package/src/hooks/engine.ts +537 -0
  49. package/src/hooks/index.ts +6 -0
  50. package/src/hooks/lifecycle.ts +239 -0
  51. package/src/hooks/node.ts +18 -0
  52. package/src/hooks/subprocess-runner.ts +140 -0
  53. package/src/hooks/subprocess.test.ts +180 -0
  54. package/src/hooks/subprocess.ts +620 -0
  55. package/src/index.browser.ts +1 -0
  56. package/src/index.node.ts +21 -0
  57. package/src/index.ts +133 -0
  58. package/src/mcp/index.ts +17 -0
  59. package/src/mcp/policies.test.ts +51 -0
  60. package/src/mcp/policies.ts +53 -0
  61. package/src/mcp/tools.test.ts +76 -0
  62. package/src/mcp/tools.ts +60 -0
  63. package/src/mcp/types.ts +41 -0
  64. package/src/message-builder.test.ts +175 -0
  65. package/src/message-builder.ts +429 -0
  66. package/src/prompts/cline.ts +49 -0
  67. package/src/prompts/index.ts +1 -0
  68. package/src/runtime/agent-runtime-bus.ts +53 -0
  69. package/src/runtime/conversation-store.ts +61 -0
  70. package/src/runtime/lifecycle-orchestrator.ts +90 -0
  71. package/src/runtime/tool-orchestrator.ts +177 -0
  72. package/src/runtime/turn-processor.ts +250 -0
  73. package/src/streaming.test.ts +197 -0
  74. package/src/streaming.ts +307 -0
  75. package/src/teams/index.ts +63 -0
  76. package/src/teams/multi-agent.lifecycle.test.ts +48 -0
  77. package/src/teams/multi-agent.ts +1866 -0
  78. package/src/teams/spawn-agent-tool.test.ts +172 -0
  79. package/src/teams/spawn-agent-tool.ts +223 -0
  80. package/src/teams/team-tools.test.ts +448 -0
  81. package/src/teams/team-tools.ts +929 -0
  82. package/src/tools/ask-question.ts +78 -0
  83. package/src/tools/create.ts +104 -0
  84. package/src/tools/execution.ts +311 -0
  85. package/src/tools/formatting.ts +73 -0
  86. package/src/tools/index.ts +45 -0
  87. package/src/tools/registry.ts +52 -0
  88. package/src/tools/tools.test.ts +292 -0
  89. package/src/tools/validation.ts +73 -0
  90. package/src/types.ts +966 -0
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # @clinebot/agents
2
+
3
+ `@clinebot/agents` is the runtime-agnostic agent loop package in the Cline SDK.
4
+ It gives you the core primitives for building tool-using LLM agents without
5
+ bringing in session storage, RPC transport, or host-specific default tools.
6
+
7
+ ## What You Get
8
+
9
+ - `Agent` / `createAgent` for running and continuing agent conversations
10
+ - `createTool` for defining strongly typed tools
11
+ - `AgentHooks` and hook helpers for lifecycle interception
12
+ - event streaming via `onEvent` and `agent.subscribeEvents(...)`
13
+ - sub-agent, team, and MCP bridge primitives for advanced runtimes
14
+
15
+ ## What This Package Does Not Include
16
+
17
+ `@clinebot/agents` does not ship a full application runtime by itself.
18
+
19
+ - Default host tools like filesystem access, shell execution, or web fetching live in `@clinebot/core`
20
+ - Session persistence and stateful orchestration live in `@clinebot/core`
21
+ - Remote runtime/session transport lives in `@clinebot/rpc`
22
+
23
+ That split keeps this package usable in Node, browser, and custom host
24
+ environments where you want to supply your own tools and runtime policy.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @clinebot/agents @clinebot/llms zod
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```ts
35
+ import { Agent, createTool } from "@clinebot/agents";
36
+ import { z } from "zod";
37
+
38
+ const getWeather = createTool({
39
+ name: "get_weather",
40
+ description: "Return the current weather for a city.",
41
+ inputSchema: z.object({
42
+ city: z.string(),
43
+ }),
44
+ async execute({ city }) {
45
+ return {
46
+ city,
47
+ forecast: "sunny",
48
+ temperatureC: 22,
49
+ };
50
+ },
51
+ });
52
+
53
+ const agent = new Agent({
54
+ providerId: "anthropic",
55
+ modelId: "claude-sonnet-4-6",
56
+ apiKey: process.env.ANTHROPIC_API_KEY,
57
+ systemPrompt: "You are a concise assistant.",
58
+ tools: [getWeather],
59
+ });
60
+
61
+ const result = await agent.run("What's the weather in San Francisco?");
62
+ console.log(result.text);
63
+ ```
64
+
65
+ ## Core Concepts
66
+
67
+ ### Tools
68
+
69
+ Use `createTool(...)` to define tools with either JSON Schema or Zod input
70
+ schemas. The agent exposes the tool to the model and calls your `execute(...)`
71
+ handler with validated input plus a `ToolContext`.
72
+
73
+ ```ts
74
+ import { createTool } from "@clinebot/agents";
75
+ import { z } from "zod";
76
+
77
+ const summarize = createTool({
78
+ name: "summarize_text",
79
+ description: "Summarize text into a few bullet points.",
80
+ inputSchema: z.object({
81
+ text: z.string(),
82
+ }),
83
+ async execute({ text }) {
84
+ return { summary: text.slice(0, 120) };
85
+ },
86
+ });
87
+ ```
88
+
89
+ ### Events
90
+
91
+ You can observe execution in two ways:
92
+
93
+ - pass `onEvent` in `AgentConfig`
94
+ - subscribe later with `agent.subscribeEvents(listener)`
95
+
96
+ `AgentEvent` covers model text/reasoning chunks, tool lifecycle events, usage,
97
+ iteration boundaries, completion, and errors.
98
+
99
+ ### Conversation Control
100
+
101
+ - `agent.run(message)` starts a new run
102
+ - `agent.continue(message)` continues the current conversation
103
+ - `initialMessages` and `agent.restore(messages)` support resume flows
104
+
105
+ ### Hooks
106
+
107
+ `AgentHooks` let hosts observe or influence lifecycle stages such as run start,
108
+ turn start, tool call start/end, and run completion. This is the right place for
109
+ policy checks, telemetry, or injecting additional context.
110
+
111
+ If you need subprocess-backed hooks, use the Node entrypoint:
112
+
113
+ ```ts
114
+ import { createSubprocessHooks } from "@clinebot/agents/node";
115
+ ```
116
+
117
+ ### Teams and Spawn
118
+
119
+ For multi-agent workflows, the package exports:
120
+
121
+ - `createSpawnAgentTool(...)`
122
+ - `AgentTeamsRuntime`
123
+ - `createAgentTeamsTools(...)`
124
+ - `bootstrapAgentTeams(...)`
125
+
126
+ These helpers provide in-memory coordination primitives for delegated runs,
127
+ mailboxes, task management, and outcome convergence.
128
+
129
+ ## Entry Points
130
+
131
+ - `@clinebot/agents`: main package entrypoint
132
+ - `@clinebot/agents/node`: Node-only exports such as subprocess hook helpers
133
+ - `@clinebot/agents/browser`: browser-safe bundle
134
+
135
+ ## Related Packages
136
+
137
+ - `@clinebot/llms`: provider settings, model catalogs, and handler creation
138
+ - `@clinebot/core`: stateful runtime assembly, storage, and default tools
139
+ - `@clinebot/rpc`: remote runtime/session transport
140
+
141
+ ## More Examples
142
+
143
+ - Repo examples: [apps/examples/cline-sdk](https://github.com/cline/sdk/tree/main/apps/examples/cline-sdk)
144
+ - Workspace overview: [README.md](https://github.com/cline/sdk/blob/main/README.md)
145
+ - API and architecture references: [DOC.md](https://github.com/cline/sdk/blob/main/DOC.md), [ARCHITECTURE.md](https://github.com/cline/sdk/blob/main/ARCHITECTURE.md)
@@ -0,0 +1,2 @@
1
+ import type { providers } from "@clinebot/llms";
2
+ export declare function buildInitialUserContent(userMessage: string, userImages?: string[], userFiles?: string[], userFileContentLoader?: (path: string) => Promise<string>): Promise<string | providers.ContentBlock[]>;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Agent Class
3
+ *
4
+ * The main class for building and running agentic loops with LLMs.
5
+ */
6
+ import { providers } from "@clinebot/llms";
7
+ import type { AgentConfig, AgentEvent, AgentExtensionRegistry, AgentResult } from "./types.js";
8
+ export declare class Agent {
9
+ private config;
10
+ private handler;
11
+ private toolRegistry;
12
+ private abortController;
13
+ private contributionRegistry;
14
+ private readonly hookEngine;
15
+ private messageBuilder;
16
+ private readonly logger?;
17
+ private extensionsInitialized;
18
+ private activeRunId;
19
+ private runState;
20
+ private readonly runtimeBus;
21
+ private readonly conversationStore;
22
+ private readonly lifecycle;
23
+ private turnProcessor;
24
+ private readonly toolOrchestrator;
25
+ private readonly agentId;
26
+ private readonly parentAgentId;
27
+ constructor(config: AgentConfig);
28
+ run(userMessage: string, userImages?: string[], userFiles?: string[]): Promise<AgentResult>;
29
+ continue(userMessage: string, userImages?: string[], userFiles?: string[]): Promise<AgentResult>;
30
+ getMessages(): providers.Message[];
31
+ clearHistory(): void;
32
+ restore(messages: providers.Message[]): void;
33
+ abort(): void;
34
+ subscribeEvents(listener: (event: AgentEvent) => void): () => void;
35
+ shutdown(reason?: string): Promise<void>;
36
+ getExtensionRegistry(): AgentExtensionRegistry;
37
+ getAgentId(): string;
38
+ getConversationId(): string;
39
+ updateConnection(overrides: Partial<Pick<AgentConfig, "providerId" | "modelId" | "apiKey" | "baseUrl" | "headers" | "knownModels" | "reasoningEffort" | "thinkingBudgetTokens" | "thinking" | "abortSignal">>): void;
40
+ private assertCanStartRun;
41
+ private createHandlerFromConfig;
42
+ private executeLoop;
43
+ private ensureExtensionsInitialized;
44
+ private prepareUserInput;
45
+ private buildInitialUserContent;
46
+ private buildAbortedResult;
47
+ private emit;
48
+ private reportRecoverableError;
49
+ private resolveToolPolicy;
50
+ private requestToolApproval;
51
+ private authorizeToolCall;
52
+ private appendHookContext;
53
+ private log;
54
+ private mergeAbortSignals;
55
+ }
56
+ export declare function createAgent(config: AgentConfig): Agent;
@@ -0,0 +1,21 @@
1
+ import type { AgentExtension, AgentExtensionRegistry, Tool } from "./types.js";
2
+ export interface ContributionRegistryOptions {
3
+ extensions?: AgentExtension[];
4
+ }
5
+ export declare class ContributionRegistry {
6
+ private readonly extensions;
7
+ private readonly registry;
8
+ private normalized;
9
+ private phase;
10
+ constructor(options?: ContributionRegistryOptions);
11
+ resolve(): void;
12
+ validate(): void;
13
+ setup(): Promise<void>;
14
+ activate(): void;
15
+ initialize(): Promise<void>;
16
+ isActivated(): boolean;
17
+ getRegistrySnapshot(): AgentExtensionRegistry;
18
+ getRegisteredTools(): Tool[];
19
+ getValidatedExtensions(): AgentExtension[];
20
+ }
21
+ export declare function createContributionRegistry(options?: ContributionRegistryOptions): ContributionRegistry;
@@ -0,0 +1,42 @@
1
+ import type { AgentHookControl, HookDispatchResult, HookEventEnvelope, HookPolicies, HookStage, HookStagePolicy } from "../types.js";
2
+ export interface HookHandler {
3
+ name: string;
4
+ stage: HookStage;
5
+ priority?: number;
6
+ handle: (event: HookEventEnvelope) => Promise<AgentHookControl | undefined> | AgentHookControl | undefined;
7
+ }
8
+ export interface HookDispatchInput<TPayload = unknown> {
9
+ stage: HookStage;
10
+ runId: string;
11
+ agentId: string;
12
+ conversationId: string;
13
+ parentAgentId: string | null;
14
+ iteration?: number;
15
+ parentEventId?: string;
16
+ payload: TPayload;
17
+ }
18
+ export interface HookEngineOptions {
19
+ policies?: HookPolicies;
20
+ onDispatchError?: (error: Error, event: HookEventEnvelope, handlerName: string) => void;
21
+ onDroppedEvent?: (event: HookEventEnvelope, policy: HookStagePolicy) => void;
22
+ }
23
+ export declare class HookEngine {
24
+ private readonly handlers;
25
+ private readonly options;
26
+ private sequence;
27
+ private eventCounter;
28
+ private readonly stageQueues;
29
+ private readonly inFlight;
30
+ constructor(options?: HookEngineOptions);
31
+ register(handler: HookHandler): void;
32
+ dispatch<TPayload>(input: HookDispatchInput<TPayload>): Promise<HookDispatchResult>;
33
+ shutdown(drainTimeoutMs?: number): Promise<void>;
34
+ private getHandlers;
35
+ private getStageQueueState;
36
+ private kickQueue;
37
+ private resolveStagePolicy;
38
+ private resolveHandlerPolicy;
39
+ private executeHandlers;
40
+ private executeHandler;
41
+ private mergeControlsFromResults;
42
+ }
@@ -0,0 +1,2 @@
1
+ export { type HookDispatchInput, HookEngine, type HookHandler, } from "./engine.js";
2
+ export { registerLifecycleHandlers } from "./lifecycle.js";
@@ -0,0 +1,5 @@
1
+ import type { AgentConfig } from "../types.js";
2
+ import type { HookEngine } from "./engine.js";
3
+ type LifecycleConfig = Pick<AgentConfig, "hooks" | "extensions">;
4
+ export declare function registerLifecycleHandlers(hookEngine: HookEngine, config: LifecycleConfig): void;
5
+ export {};
@@ -0,0 +1,2 @@
1
+ export { createSubprocessHooks, type HookEventName, HookEventNameSchema, type HookEventPayload, HookEventPayloadSchema, parseHookEventPayload, type RunHookOptions, type RunHookResult, runHook, type SubprocessHookControl, type SubprocessHooksOptions, } from "./subprocess.js";
2
+ export { type RunSubprocessEventOptions, type RunSubprocessEventResult, runSubprocessEvent, } from "./subprocess-runner.js";
@@ -0,0 +1,16 @@
1
+ export interface RunSubprocessEventOptions {
2
+ command: string[];
3
+ cwd?: string;
4
+ env?: NodeJS.ProcessEnv;
5
+ detached?: boolean;
6
+ timeoutMs?: number;
7
+ }
8
+ export interface RunSubprocessEventResult {
9
+ exitCode: number | null;
10
+ stdout: string;
11
+ stderr: string;
12
+ parsedJson?: unknown;
13
+ parseError?: string;
14
+ timedOut?: boolean;
15
+ }
16
+ export declare function runSubprocessEvent(payload: unknown, options: RunSubprocessEventOptions): Promise<RunSubprocessEventResult | undefined>;
@@ -0,0 +1,268 @@
1
+ import type { HookSessionContext, HookSessionContextProvider } from "@clinebot/shared";
2
+ import { z } from "zod";
3
+ import type { AgentHooks, AgentHookTurnEndContext, ToolCallRecord } from "../types.js";
4
+ import { type RunSubprocessEventResult } from "./subprocess-runner.js";
5
+ export declare const HookEventNameSchema: z.ZodEnum<{
6
+ tool_result: "tool_result";
7
+ session_shutdown: "session_shutdown";
8
+ tool_call: "tool_call";
9
+ agent_start: "agent_start";
10
+ agent_resume: "agent_resume";
11
+ agent_abort: "agent_abort";
12
+ agent_end: "agent_end";
13
+ prompt_submit: "prompt_submit";
14
+ pre_compact: "pre_compact";
15
+ }>;
16
+ export type HookEventName = z.infer<typeof HookEventNameSchema>;
17
+ export interface HookOutput {
18
+ contextModification: string;
19
+ cancel: boolean;
20
+ review?: boolean;
21
+ errorMessage: string;
22
+ }
23
+ export declare const HookOutputSchema: z.ZodObject<{
24
+ contextModification: z.ZodOptional<z.ZodString>;
25
+ cancel: z.ZodOptional<z.ZodBoolean>;
26
+ review: z.ZodOptional<z.ZodBoolean>;
27
+ errorMessage: z.ZodOptional<z.ZodString>;
28
+ context: z.ZodOptional<z.ZodString>;
29
+ overrideInput: z.ZodOptional<z.ZodUnknown>;
30
+ }, z.core.$loose>;
31
+ export interface PreToolUseData {
32
+ toolName: string;
33
+ parameters: Record<string, string>;
34
+ }
35
+ export interface PostToolUseData {
36
+ toolName: string;
37
+ parameters: Record<string, string>;
38
+ result: string;
39
+ success: boolean;
40
+ executionTimeMs: number;
41
+ }
42
+ export interface UserPromptSubmitData {
43
+ prompt: string;
44
+ attachments: string[];
45
+ }
46
+ export interface TaskStartData {
47
+ taskMetadata: Record<string, string>;
48
+ }
49
+ export interface TaskResumeData {
50
+ taskMetadata: Record<string, string>;
51
+ previousState: Record<string, string>;
52
+ }
53
+ export interface TaskCancelData {
54
+ taskMetadata: Record<string, string>;
55
+ }
56
+ export interface TaskCompleteData {
57
+ taskMetadata: Record<string, string>;
58
+ }
59
+ export interface PreCompactData {
60
+ taskId: string;
61
+ ulid: string;
62
+ contextSize: number;
63
+ compactionStrategy: string;
64
+ previousApiReqIndex: number;
65
+ tokensIn: number;
66
+ tokensOut: number;
67
+ tokensInCache: number;
68
+ tokensOutCache: number;
69
+ deletedRangeStart: number;
70
+ deletedRangeEnd: number;
71
+ contextJsonPath: string;
72
+ contextRawPath: string;
73
+ }
74
+ export interface HookEventPayloadBase {
75
+ clineVersion: string;
76
+ hookName: HookEventName;
77
+ timestamp: string;
78
+ taskId: string;
79
+ sessionContext?: HookSessionContext;
80
+ workspaceRoots: string[];
81
+ userId: string;
82
+ agent_id: string;
83
+ parent_agent_id: string | null;
84
+ preToolUse?: PreToolUseData | undefined;
85
+ postToolUse?: PostToolUseData | undefined;
86
+ userPromptSubmit?: UserPromptSubmitData | undefined;
87
+ taskStart?: TaskStartData | undefined;
88
+ taskResume?: TaskResumeData | undefined;
89
+ taskCancel?: TaskCancelData | undefined;
90
+ taskComplete?: TaskCompleteData | undefined;
91
+ preCompact?: PreCompactData | undefined;
92
+ }
93
+ export interface ToolCallHookPayload extends HookEventPayloadBase {
94
+ hookName: "tool_call";
95
+ iteration: number;
96
+ tool_call: {
97
+ id: string;
98
+ name: string;
99
+ input: unknown;
100
+ };
101
+ }
102
+ export interface ToolResultHookPayload extends HookEventPayloadBase {
103
+ hookName: "tool_result";
104
+ iteration: number;
105
+ tool_result: ToolCallRecord;
106
+ }
107
+ export interface AgentEndHookPayload extends HookEventPayloadBase {
108
+ hookName: "agent_end";
109
+ iteration: number;
110
+ turn: AgentHookTurnEndContext["turn"];
111
+ }
112
+ export interface AgentStartHookPayload extends HookEventPayloadBase {
113
+ hookName: "agent_start";
114
+ }
115
+ export interface AgentResumeHookPayload extends HookEventPayloadBase {
116
+ hookName: "agent_resume";
117
+ }
118
+ export interface AgentAbortHookPayload extends HookEventPayloadBase {
119
+ hookName: "agent_abort";
120
+ reason?: string;
121
+ }
122
+ export interface PromptSubmitHookPayload extends HookEventPayloadBase {
123
+ hookName: "prompt_submit";
124
+ }
125
+ export interface PreCompactHookPayload extends HookEventPayloadBase {
126
+ hookName: "pre_compact";
127
+ preCompact: PreCompactData;
128
+ }
129
+ export interface SessionShutdownHookPayload extends HookEventPayloadBase {
130
+ hookName: "session_shutdown";
131
+ reason?: string;
132
+ }
133
+ export type HookEventPayload = ToolCallHookPayload | ToolResultHookPayload | AgentStartHookPayload | AgentResumeHookPayload | AgentAbortHookPayload | PromptSubmitHookPayload | PreCompactHookPayload | AgentEndHookPayload | SessionShutdownHookPayload;
134
+ export declare const HookEventPayloadSchema: z.ZodObject<{
135
+ clineVersion: z.ZodString;
136
+ hookName: z.ZodEnum<{
137
+ tool_result: "tool_result";
138
+ session_shutdown: "session_shutdown";
139
+ tool_call: "tool_call";
140
+ agent_start: "agent_start";
141
+ agent_resume: "agent_resume";
142
+ agent_abort: "agent_abort";
143
+ agent_end: "agent_end";
144
+ prompt_submit: "prompt_submit";
145
+ pre_compact: "pre_compact";
146
+ }>;
147
+ timestamp: z.ZodString;
148
+ taskId: z.ZodString;
149
+ sessionContext: z.ZodOptional<z.ZodObject<{
150
+ rootSessionId: z.ZodOptional<z.ZodString>;
151
+ hookLogPath: z.ZodOptional<z.ZodString>;
152
+ }, z.core.$strip>>;
153
+ workspaceRoots: z.ZodArray<z.ZodString>;
154
+ userId: z.ZodString;
155
+ agent_id: z.ZodString;
156
+ parent_agent_id: z.ZodNullable<z.ZodString>;
157
+ iteration: z.ZodOptional<z.ZodNumber>;
158
+ reason: z.ZodOptional<z.ZodString>;
159
+ tool_call: z.ZodOptional<z.ZodObject<{
160
+ id: z.ZodString;
161
+ name: z.ZodString;
162
+ input: z.ZodUnknown;
163
+ }, z.core.$strip>>;
164
+ tool_result: z.ZodOptional<z.ZodCustom<ToolCallRecord, ToolCallRecord>>;
165
+ turn: z.ZodOptional<z.ZodCustom<import("../types.js").ProcessedTurn, import("../types.js").ProcessedTurn>>;
166
+ preToolUse: z.ZodOptional<z.ZodObject<{
167
+ toolName: z.ZodString;
168
+ parameters: z.ZodRecord<z.ZodString, z.ZodString>;
169
+ }, z.core.$strip>>;
170
+ postToolUse: z.ZodOptional<z.ZodObject<{
171
+ toolName: z.ZodString;
172
+ parameters: z.ZodRecord<z.ZodString, z.ZodString>;
173
+ result: z.ZodString;
174
+ success: z.ZodBoolean;
175
+ executionTimeMs: z.ZodNumber;
176
+ }, z.core.$strip>>;
177
+ userPromptSubmit: z.ZodOptional<z.ZodObject<{
178
+ prompt: z.ZodString;
179
+ attachments: z.ZodArray<z.ZodString>;
180
+ }, z.core.$strip>>;
181
+ taskStart: z.ZodOptional<z.ZodObject<{
182
+ taskMetadata: z.ZodRecord<z.ZodString, z.ZodString>;
183
+ }, z.core.$strip>>;
184
+ taskResume: z.ZodOptional<z.ZodObject<{
185
+ taskMetadata: z.ZodRecord<z.ZodString, z.ZodString>;
186
+ previousState: z.ZodRecord<z.ZodString, z.ZodString>;
187
+ }, z.core.$strip>>;
188
+ taskCancel: z.ZodOptional<z.ZodObject<{
189
+ taskMetadata: z.ZodRecord<z.ZodString, z.ZodString>;
190
+ }, z.core.$strip>>;
191
+ taskComplete: z.ZodOptional<z.ZodObject<{
192
+ taskMetadata: z.ZodRecord<z.ZodString, z.ZodString>;
193
+ }, z.core.$strip>>;
194
+ preCompact: z.ZodOptional<z.ZodObject<{
195
+ taskId: z.ZodString;
196
+ ulid: z.ZodString;
197
+ contextSize: z.ZodNumber;
198
+ compactionStrategy: z.ZodString;
199
+ previousApiReqIndex: z.ZodNumber;
200
+ tokensIn: z.ZodNumber;
201
+ tokensOut: z.ZodNumber;
202
+ tokensInCache: z.ZodNumber;
203
+ tokensOutCache: z.ZodNumber;
204
+ deletedRangeStart: z.ZodNumber;
205
+ deletedRangeEnd: z.ZodNumber;
206
+ contextJsonPath: z.ZodString;
207
+ contextRawPath: z.ZodString;
208
+ }, z.core.$strip>>;
209
+ }, z.core.$loose>;
210
+ export declare function parseHookEventPayload(value: unknown): HookEventPayload | undefined;
211
+ export interface RunHookOptions {
212
+ command?: string[];
213
+ cwd?: string;
214
+ env?: NodeJS.ProcessEnv;
215
+ detached?: boolean;
216
+ timeoutMs?: number;
217
+ }
218
+ export type RunHookResult = RunSubprocessEventResult;
219
+ /**
220
+ * Dispatch a single hook event to an external CLI.
221
+ * Payload is serialized as JSON and piped via stdin.
222
+ */
223
+ export declare function runHook(payload: HookEventPayload, options?: RunHookOptions): Promise<RunHookResult | undefined>;
224
+ export interface SubprocessHooksOptions {
225
+ command?: string[];
226
+ cwd?: string;
227
+ env?: NodeJS.ProcessEnv;
228
+ /**
229
+ * Timeout in milliseconds for blocking tool_call hook invocation.
230
+ */
231
+ timeoutMs?: number;
232
+ /**
233
+ * Optional callback for non-fatal hook dispatch errors.
234
+ */
235
+ onDispatchError?: (error: Error, payload: HookEventPayload) => void;
236
+ /**
237
+ * Optional callback invoked after a hook dispatch is attempted.
238
+ */
239
+ onDispatch?: (event: {
240
+ payload: HookEventPayload;
241
+ result?: RunHookResult;
242
+ detached: boolean;
243
+ }) => void;
244
+ /**
245
+ * Optional context attached to every hook payload.
246
+ * Use this to scope hook events to a root runtime session without global env state.
247
+ */
248
+ sessionContext?: HookSessionContextProvider;
249
+ }
250
+ export interface SubprocessHookControl {
251
+ hooks: AgentHooks;
252
+ shutdown: (ctx: {
253
+ agentId: string;
254
+ conversationId: string;
255
+ parentAgentId: string | null;
256
+ reason?: string;
257
+ }) => Promise<void>;
258
+ }
259
+ /**
260
+ * Create lifecycle hooks that mirror Pi-style hook events:
261
+ * - tool_call (blocking)
262
+ * - tool_result (fire-and-forget)
263
+ * - agent_start (fire-and-forget)
264
+ * - prompt_submit (fire-and-forget)
265
+ * - agent_end (fire-and-forget)
266
+ * - session_shutdown (fire-and-forget via returned `shutdown()`)
267
+ */
268
+ export declare function createSubprocessHooks(options?: SubprocessHooksOptions): SubprocessHookControl;
@@ -0,0 +1 @@
1
+ export * from "./index.js";