@posthog/agent 1.30.0 → 2.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.
- package/LICENSE +1 -1
- package/README.md +221 -219
- package/dist/adapters/claude/conversion/tool-use-to-acp.d.ts +21 -0
- package/dist/adapters/claude/conversion/tool-use-to-acp.js +547 -0
- package/dist/adapters/claude/conversion/tool-use-to-acp.js.map +1 -0
- package/dist/adapters/claude/permissions/permission-options.d.ts +13 -0
- package/dist/adapters/claude/permissions/permission-options.js +117 -0
- package/dist/adapters/claude/permissions/permission-options.js.map +1 -0
- package/dist/adapters/claude/questions/utils.d.ts +132 -0
- package/dist/adapters/claude/questions/utils.js +63 -0
- package/dist/adapters/claude/questions/utils.js.map +1 -0
- package/dist/adapters/claude/tools.d.ts +18 -0
- package/dist/adapters/claude/tools.js +95 -0
- package/dist/adapters/claude/tools.js.map +1 -0
- package/dist/agent-DBQY1BfC.d.ts +123 -0
- package/dist/agent.d.ts +5 -0
- package/dist/agent.js +3656 -0
- package/dist/agent.js.map +1 -0
- package/dist/claude-cli/cli.js +3695 -2746
- package/dist/claude-cli/vendor/ripgrep/COPYING +3 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-darwin/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/arm64-linux/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-darwin/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-linux/ripgrep.node +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/dist/claude-cli/vendor/ripgrep/x64-win32/ripgrep.node +0 -0
- package/dist/gateway-models.d.ts +24 -0
- package/dist/gateway-models.js +93 -0
- package/dist/gateway-models.js.map +1 -0
- package/dist/index.d.ts +172 -1203
- package/dist/index.js +3704 -6826
- package/dist/index.js.map +1 -1
- package/dist/logger-DDBiMOOD.d.ts +24 -0
- package/dist/posthog-api.d.ts +40 -0
- package/dist/posthog-api.js +175 -0
- package/dist/posthog-api.js.map +1 -0
- package/dist/server/agent-server.d.ts +41 -0
- package/dist/server/agent-server.js +4451 -0
- package/dist/server/agent-server.js.map +1 -0
- package/dist/server/bin.d.ts +1 -0
- package/dist/server/bin.js +4507 -0
- package/dist/server/bin.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -14
- package/src/acp-extensions.ts +93 -61
- package/src/adapters/acp-connection.ts +494 -0
- package/src/adapters/base-acp-agent.ts +150 -0
- package/src/adapters/claude/claude-agent.ts +596 -0
- package/src/adapters/claude/conversion/acp-to-sdk.ts +102 -0
- package/src/adapters/claude/conversion/sdk-to-acp.ts +571 -0
- package/src/adapters/claude/conversion/tool-use-to-acp.ts +618 -0
- package/src/adapters/claude/hooks.ts +64 -0
- package/src/adapters/claude/mcp/tool-metadata.ts +102 -0
- package/src/adapters/claude/permissions/permission-handlers.ts +433 -0
- package/src/adapters/claude/permissions/permission-options.ts +103 -0
- package/src/adapters/claude/plan/utils.ts +56 -0
- package/src/adapters/claude/questions/utils.ts +92 -0
- package/src/adapters/claude/session/commands.ts +38 -0
- package/src/adapters/claude/session/mcp-config.ts +37 -0
- package/src/adapters/claude/session/models.ts +12 -0
- package/src/adapters/claude/session/options.ts +236 -0
- package/src/adapters/claude/tool-meta.ts +143 -0
- package/src/adapters/claude/tools.ts +53 -611
- package/src/adapters/claude/types.ts +61 -0
- package/src/adapters/codex/spawn.ts +130 -0
- package/src/agent.ts +97 -734
- package/src/execution-mode.ts +43 -0
- package/src/gateway-models.ts +135 -0
- package/src/index.ts +79 -0
- package/src/otel-log-writer.test.ts +105 -0
- package/src/otel-log-writer.ts +94 -0
- package/src/posthog-api.ts +75 -235
- package/src/resume.ts +115 -0
- package/src/sagas/apply-snapshot-saga.test.ts +690 -0
- package/src/sagas/apply-snapshot-saga.ts +88 -0
- package/src/sagas/capture-tree-saga.test.ts +892 -0
- package/src/sagas/capture-tree-saga.ts +141 -0
- package/src/sagas/resume-saga.test.ts +558 -0
- package/src/sagas/resume-saga.ts +332 -0
- package/src/sagas/test-fixtures.ts +250 -0
- package/src/server/agent-server.test.ts +220 -0
- package/src/server/agent-server.ts +748 -0
- package/src/server/bin.ts +88 -0
- package/src/server/jwt.ts +65 -0
- package/src/server/schemas.ts +47 -0
- package/src/server/types.ts +13 -0
- package/src/server/utils/retry.test.ts +122 -0
- package/src/server/utils/retry.ts +61 -0
- package/src/server/utils/sse-parser.test.ts +93 -0
- package/src/server/utils/sse-parser.ts +46 -0
- package/src/session-log-writer.test.ts +140 -0
- package/src/session-log-writer.ts +137 -0
- package/src/test/assertions.ts +114 -0
- package/src/test/controllers/sse-controller.ts +107 -0
- package/src/test/fixtures/api.ts +111 -0
- package/src/test/fixtures/config.ts +33 -0
- package/src/test/fixtures/notifications.ts +92 -0
- package/src/test/mocks/claude-sdk.ts +251 -0
- package/src/test/mocks/msw-handlers.ts +48 -0
- package/src/test/setup.ts +114 -0
- package/src/test/wait.ts +41 -0
- package/src/tree-tracker.ts +173 -0
- package/src/types.ts +51 -154
- package/src/utils/acp-content.ts +58 -0
- package/src/utils/async-mutex.test.ts +104 -0
- package/src/utils/async-mutex.ts +31 -0
- package/src/utils/common.ts +15 -0
- package/src/utils/gateway.ts +9 -6
- package/src/utils/logger.ts +0 -30
- package/src/utils/streams.ts +220 -0
- package/CLAUDE.md +0 -331
- package/dist/templates/plan-template.md +0 -41
- package/src/adapters/claude/claude.ts +0 -1543
- package/src/adapters/claude/mcp-server.ts +0 -810
- package/src/adapters/claude/utils.ts +0 -267
- package/src/agents/execution.ts +0 -37
- package/src/agents/planning.ts +0 -60
- package/src/agents/research.ts +0 -160
- package/src/file-manager.ts +0 -306
- package/src/git-manager.ts +0 -577
- package/src/prompt-builder.ts +0 -499
- package/src/schemas.ts +0 -241
- package/src/session-store.ts +0 -259
- package/src/task-manager.ts +0 -163
- package/src/template-manager.ts +0 -236
- package/src/templates/plan-template.md +0 -41
- package/src/todo-manager.ts +0 -180
- package/src/tools/registry.ts +0 -129
- package/src/tools/types.ts +0 -127
- package/src/utils/tapped-stream.ts +0 -60
- package/src/workflow/config.ts +0 -53
- package/src/workflow/steps/build.ts +0 -135
- package/src/workflow/steps/finalize.ts +0 -241
- package/src/workflow/steps/plan.ts +0 -167
- package/src/workflow/steps/research.ts +0 -223
- package/src/workflow/types.ts +0 -62
- package/src/workflow/utils.ts +0 -53
- package/src/worktree-manager.ts +0 -928
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
export { A as AcpConnection, a as AcpConnectionConfig, b as Agent, c as AgentAdapter, C as CodexProcessOptions, I as InProcessAcpConnection, O as OtelLogConfig, d as OtelLogWriter, S as SessionContext, e as SessionLogWriter, f as SessionLogWriterOptions, g as createAcpConnection } from './agent-DBQY1BfC.js';
|
|
2
|
+
import { McpServerConfig } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
import { L as Logger } from './logger-DDBiMOOD.js';
|
|
4
|
+
export { a as LoggerConfig } from './logger-DDBiMOOD.js';
|
|
5
|
+
export { ArrayModelInfo, BLOCKED_MODELS, DEFAULT_GATEWAY_MODEL, FetchGatewayModelsOptions, GatewayModel, fetchArrayModels, fetchGatewayModels, formatGatewayModelName, getProviderName, isAnthropicModel } from './gateway-models.js';
|
|
6
|
+
import { PostHogAPIClient } from './posthog-api.js';
|
|
7
|
+
export { getLlmGatewayUrl } from './posthog-api.js';
|
|
8
|
+
import { ContentBlock } from '@agentclientprotocol/sdk';
|
|
9
|
+
import { TreeSnapshotEvent, DeviceInfo, TreeSnapshot } from './types.js';
|
|
10
|
+
export { AgentConfig, AgentMode, FileChange, FileStatus, LogLevel, OnLogCallback, OtelTransportConfig, StoredEntry, StoredNotification, Task, TaskRun } from './types.js';
|
|
5
11
|
|
|
6
12
|
/**
|
|
7
13
|
* PostHog-specific ACP extensions.
|
|
@@ -10,6 +16,10 @@ import { z } from 'zod';
|
|
|
10
16
|
* - Custom notification methods are prefixed with `_posthog/`
|
|
11
17
|
* - Custom data can be attached via `_meta` fields
|
|
12
18
|
*
|
|
19
|
+
* Note: When using `extNotification()` from the ACP SDK, it automatically
|
|
20
|
+
* adds an extra underscore prefix (e.g., `_posthog/tree_snapshot` becomes
|
|
21
|
+
* `__posthog/tree_snapshot` in the log). Code that reads logs should handle both.
|
|
22
|
+
*
|
|
13
23
|
* See: https://agentclientprotocol.com/docs/extensibility
|
|
14
24
|
*/
|
|
15
25
|
/**
|
|
@@ -17,59 +27,46 @@ import { z } from 'zod';
|
|
|
17
27
|
* Used with AgentSideConnection.extNotification() or Client.extNotification()
|
|
18
28
|
*/
|
|
19
29
|
declare const POSTHOG_NOTIFICATIONS: {
|
|
20
|
-
/**
|
|
21
|
-
readonly ARTIFACT: "_posthog/artifact";
|
|
22
|
-
/** Phase has started (research, plan, build, etc.) */
|
|
23
|
-
readonly PHASE_START: "_posthog/phase_start";
|
|
24
|
-
/** Phase has completed */
|
|
25
|
-
readonly PHASE_COMPLETE: "_posthog/phase_complete";
|
|
26
|
-
/** Git branch was created */
|
|
30
|
+
/** Git branch was created for a task */
|
|
27
31
|
readonly BRANCH_CREATED: "_posthog/branch_created";
|
|
28
|
-
/**
|
|
29
|
-
readonly PR_CREATED: "_posthog/pr_created";
|
|
30
|
-
/** Task run has started */
|
|
32
|
+
/** Task run has started execution */
|
|
31
33
|
readonly RUN_STARTED: "_posthog/run_started";
|
|
32
|
-
/** Task has completed */
|
|
34
|
+
/** Task has completed (success or failure) */
|
|
33
35
|
readonly TASK_COMPLETE: "_posthog/task_complete";
|
|
34
36
|
/** Error occurred during task execution */
|
|
35
37
|
readonly ERROR: "_posthog/error";
|
|
36
|
-
/** Console/log output */
|
|
38
|
+
/** Console/log output from the agent */
|
|
37
39
|
readonly CONSOLE: "_posthog/console";
|
|
38
|
-
/**
|
|
40
|
+
/** Maps taskRunId to agent's sessionId and adapter type (for resumption) */
|
|
39
41
|
readonly SDK_SESSION: "_posthog/sdk_session";
|
|
40
|
-
/**
|
|
41
|
-
readonly
|
|
42
|
+
/** Tree state snapshot captured (git tree hash + file archive) */
|
|
43
|
+
readonly TREE_SNAPSHOT: "_posthog/tree_snapshot";
|
|
44
|
+
/** Agent mode changed (interactive/background) */
|
|
45
|
+
readonly MODE_CHANGE: "_posthog/mode_change";
|
|
46
|
+
/** Request to resume a session from previous state */
|
|
47
|
+
readonly SESSION_RESUME: "_posthog/session/resume";
|
|
48
|
+
/** User message sent from client to agent */
|
|
49
|
+
readonly USER_MESSAGE: "_posthog/user_message";
|
|
50
|
+
/** Request to cancel current operation */
|
|
51
|
+
readonly CANCEL: "_posthog/cancel";
|
|
52
|
+
/** Request to close the session */
|
|
53
|
+
readonly CLOSE: "_posthog/close";
|
|
54
|
+
/** Agent status update (thinking, working, etc.) */
|
|
55
|
+
readonly STATUS: "_posthog/status";
|
|
56
|
+
/** Task-level notification (progress, milestones) */
|
|
57
|
+
readonly TASK_NOTIFICATION: "_posthog/task_notification";
|
|
58
|
+
/** Marks a boundary for log compaction */
|
|
59
|
+
readonly COMPACT_BOUNDARY: "_posthog/compact_boundary";
|
|
42
60
|
};
|
|
43
61
|
type PostHogNotificationType = (typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS];
|
|
44
|
-
interface ArtifactNotificationPayload {
|
|
45
|
-
sessionId: string;
|
|
46
|
-
kind: "research_evaluation" | "research_questions" | "plan" | "pr_body" | string;
|
|
47
|
-
content: unknown;
|
|
48
|
-
}
|
|
49
|
-
interface PhaseNotificationPayload {
|
|
50
|
-
sessionId: string;
|
|
51
|
-
phase: "research" | "plan" | "build" | "finalize" | string;
|
|
52
|
-
[key: string]: unknown;
|
|
53
|
-
}
|
|
54
62
|
interface BranchCreatedPayload {
|
|
55
|
-
sessionId: string;
|
|
56
63
|
branch: string;
|
|
57
64
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Payload for PR created notification
|
|
60
|
-
*/
|
|
61
|
-
interface PrCreatedPayload {
|
|
62
|
-
sessionId: string;
|
|
63
|
-
prUrl: string;
|
|
64
|
-
}
|
|
65
65
|
interface RunStartedPayload {
|
|
66
66
|
sessionId: string;
|
|
67
67
|
runId: string;
|
|
68
68
|
taskId?: string;
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Payload for task complete notification
|
|
72
|
-
*/
|
|
73
70
|
interface TaskCompletePayload {
|
|
74
71
|
sessionId: string;
|
|
75
72
|
taskId: string;
|
|
@@ -79,1212 +76,184 @@ interface ErrorNotificationPayload {
|
|
|
79
76
|
message: string;
|
|
80
77
|
error?: unknown;
|
|
81
78
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Console output for a session
|
|
84
|
-
*/
|
|
85
79
|
interface ConsoleNotificationPayload {
|
|
86
80
|
sessionId: string;
|
|
87
81
|
level: "debug" | "info" | "warn" | "error";
|
|
88
82
|
message: string;
|
|
89
83
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Maps a session ID to a SDKs session ID
|
|
92
|
-
*/
|
|
93
84
|
interface SdkSessionPayload {
|
|
85
|
+
taskRunId: string;
|
|
94
86
|
sessionId: string;
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
type PostHogNotificationPayload = ArtifactNotificationPayload | PhaseNotificationPayload | BranchCreatedPayload | PrCreatedPayload | RunStartedPayload | TaskCompletePayload | ErrorNotificationPayload | ConsoleNotificationPayload | SdkSessionPayload | SandboxOutputPayload;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Stored custom notification following ACP extensibility model.
|
|
110
|
-
* Custom notifications use underscore-prefixed methods (e.g., `_posthog/phase_start`).
|
|
111
|
-
* See: https://agentclientprotocol.com/docs/extensibility
|
|
112
|
-
*/
|
|
113
|
-
interface StoredNotification {
|
|
114
|
-
type: "notification";
|
|
115
|
-
/** When this notification was stored */
|
|
87
|
+
adapter: "claude" | "codex";
|
|
88
|
+
}
|
|
89
|
+
interface TreeSnapshotPayload {
|
|
90
|
+
treeHash: string;
|
|
91
|
+
baseCommit: string | null;
|
|
92
|
+
archiveUrl?: string;
|
|
93
|
+
changes: Array<{
|
|
94
|
+
path: string;
|
|
95
|
+
status: "A" | "M" | "D";
|
|
96
|
+
}>;
|
|
116
97
|
timestamp: string;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
params?: Record<string, unknown>;
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Type alias for stored log entries.
|
|
126
|
-
*/
|
|
127
|
-
type StoredEntry = StoredNotification;
|
|
128
|
-
interface Task {
|
|
129
|
-
id: string;
|
|
130
|
-
task_number?: number;
|
|
131
|
-
slug?: string;
|
|
132
|
-
title: string;
|
|
133
|
-
description: string;
|
|
134
|
-
origin_product: "error_tracking" | "eval_clusters" | "user_created" | "support_queue" | "session_summaries";
|
|
135
|
-
github_integration?: number | null;
|
|
136
|
-
repository: string;
|
|
137
|
-
json_schema?: Record<string, unknown> | null;
|
|
138
|
-
created_at: string;
|
|
139
|
-
updated_at: string;
|
|
140
|
-
created_by?: {
|
|
141
|
-
id: number;
|
|
142
|
-
uuid: string;
|
|
143
|
-
distinct_id: string;
|
|
144
|
-
first_name: string;
|
|
145
|
-
email: string;
|
|
98
|
+
interrupted?: boolean;
|
|
99
|
+
device?: {
|
|
100
|
+
type: "local" | "cloud";
|
|
101
|
+
name?: string;
|
|
146
102
|
};
|
|
147
|
-
latest_run?: TaskRun;
|
|
148
|
-
}
|
|
149
|
-
type ArtifactType = "plan" | "context" | "reference" | "output" | "artifact";
|
|
150
|
-
interface TaskRunArtifact {
|
|
151
|
-
name: string;
|
|
152
|
-
type: ArtifactType;
|
|
153
|
-
size?: number;
|
|
154
|
-
content_type?: string;
|
|
155
|
-
storage_path?: string;
|
|
156
|
-
uploaded_at?: string;
|
|
157
|
-
}
|
|
158
|
-
type TaskRunStatus = "not_started" | "queued" | "in_progress" | "completed" | "failed" | "cancelled";
|
|
159
|
-
type TaskRunEnvironment = "local" | "cloud";
|
|
160
|
-
interface TaskRun {
|
|
161
|
-
id: string;
|
|
162
|
-
task: string;
|
|
163
|
-
team: number;
|
|
164
|
-
branch: string | null;
|
|
165
|
-
stage: string | null;
|
|
166
|
-
environment: TaskRunEnvironment;
|
|
167
|
-
status: TaskRunStatus;
|
|
168
|
-
log_url: string;
|
|
169
|
-
error_message: string | null;
|
|
170
|
-
output: Record<string, unknown> | null;
|
|
171
|
-
state: Record<string, unknown>;
|
|
172
|
-
artifacts?: TaskRunArtifact[];
|
|
173
|
-
created_at: string;
|
|
174
|
-
updated_at: string;
|
|
175
|
-
completed_at: string | null;
|
|
176
|
-
}
|
|
177
|
-
interface SupportingFile {
|
|
178
|
-
name: string;
|
|
179
|
-
content: string;
|
|
180
|
-
type: ArtifactType;
|
|
181
|
-
created_at: string;
|
|
182
|
-
}
|
|
183
|
-
interface TaskArtifactUploadPayload {
|
|
184
|
-
name: string;
|
|
185
|
-
type: ArtifactType;
|
|
186
|
-
content: string;
|
|
187
|
-
content_type?: string;
|
|
188
103
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
ACCEPT_EDITS = "acceptEdits",
|
|
193
|
-
BYPASS = "bypassPermissions"
|
|
104
|
+
interface ModeChangePayload {
|
|
105
|
+
mode: "interactive" | "background";
|
|
106
|
+
previous_mode: "interactive" | "background";
|
|
194
107
|
}
|
|
195
|
-
interface
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
isCloudMode?: boolean;
|
|
199
|
-
createPR?: boolean;
|
|
200
|
-
autoProgress?: boolean;
|
|
201
|
-
queryOverrides?: Record<string, unknown>;
|
|
202
|
-
canUseTool?: CanUseTool;
|
|
203
|
-
skipGitBranch?: boolean;
|
|
204
|
-
}
|
|
205
|
-
interface ExecutionResult {
|
|
206
|
-
results: any[];
|
|
207
|
-
}
|
|
208
|
-
type McpServerConfig = {
|
|
209
|
-
type?: "stdio";
|
|
210
|
-
command: string;
|
|
211
|
-
args?: string[];
|
|
212
|
-
env?: Record<string, string>;
|
|
213
|
-
} | {
|
|
214
|
-
type: "sse";
|
|
215
|
-
url: string;
|
|
216
|
-
headers?: Record<string, string>;
|
|
217
|
-
} | {
|
|
218
|
-
type: "http";
|
|
219
|
-
url: string;
|
|
220
|
-
headers?: Record<string, string>;
|
|
221
|
-
} | {
|
|
222
|
-
type: "sdk";
|
|
223
|
-
name: string;
|
|
224
|
-
instance?: any;
|
|
225
|
-
};
|
|
226
|
-
type LogLevel$1 = "debug" | "info" | "warn" | "error";
|
|
227
|
-
type OnLogCallback = (level: LogLevel$1, scope: string, message: string, data?: unknown) => void;
|
|
228
|
-
interface AgentConfig {
|
|
229
|
-
workingDirectory?: string;
|
|
230
|
-
posthogApiUrl?: string;
|
|
231
|
-
getPosthogApiKey?: () => string;
|
|
232
|
-
posthogProjectId?: number;
|
|
233
|
-
posthogMcpUrl?: string;
|
|
234
|
-
mcpServers?: Record<string, McpServerConfig>;
|
|
235
|
-
debug?: boolean;
|
|
236
|
-
onLog?: OnLogCallback;
|
|
237
|
-
canUseTool?: CanUseTool;
|
|
238
|
-
}
|
|
239
|
-
interface PostHogAPIConfig {
|
|
240
|
-
apiUrl: string;
|
|
241
|
-
getApiKey: () => string;
|
|
242
|
-
projectId: number;
|
|
108
|
+
interface SessionResumePayload {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
fromSnapshot?: string;
|
|
243
111
|
}
|
|
244
|
-
|
|
245
|
-
interface PostHogResource {
|
|
246
|
-
type: ResourceType;
|
|
247
|
-
id: string;
|
|
248
|
-
url: string;
|
|
249
|
-
title?: string;
|
|
112
|
+
interface UserMessagePayload {
|
|
250
113
|
content: string;
|
|
251
|
-
metadata?: Record<string, any>;
|
|
252
|
-
}
|
|
253
|
-
interface UrlMention {
|
|
254
|
-
url: string;
|
|
255
|
-
type: ResourceType;
|
|
256
|
-
id?: string;
|
|
257
|
-
label?: string;
|
|
258
114
|
}
|
|
259
|
-
interface
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
interface ResearchAnswer {
|
|
265
|
-
questionId: string;
|
|
266
|
-
selectedOption: string;
|
|
267
|
-
customInput?: string;
|
|
115
|
+
interface StatusPayload {
|
|
116
|
+
sessionId: string;
|
|
117
|
+
status: string;
|
|
118
|
+
message?: string;
|
|
268
119
|
}
|
|
269
|
-
interface
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
questions?: ResearchQuestion[];
|
|
275
|
-
answered?: boolean;
|
|
276
|
-
answers?: ResearchAnswer[];
|
|
120
|
+
interface TaskNotificationPayload {
|
|
121
|
+
sessionId: string;
|
|
122
|
+
type: string;
|
|
123
|
+
message?: string;
|
|
124
|
+
data?: Record<string, unknown>;
|
|
277
125
|
}
|
|
278
|
-
interface
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
branchName: string;
|
|
282
|
-
baseBranch: string;
|
|
283
|
-
createdAt: string;
|
|
126
|
+
interface CompactBoundaryPayload {
|
|
127
|
+
sessionId: string;
|
|
128
|
+
timestamp: string;
|
|
284
129
|
}
|
|
130
|
+
type PostHogNotificationPayload = BranchCreatedPayload | RunStartedPayload | TaskCompletePayload | ErrorNotificationPayload | ConsoleNotificationPayload | SdkSessionPayload | TreeSnapshotPayload | ModeChangePayload | SessionResumePayload | UserMessagePayload | StatusPayload | TaskNotificationPayload | CompactBoundaryPayload;
|
|
285
131
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
declare class PostHogAPIClient {
|
|
289
|
-
private config;
|
|
290
|
-
constructor(config: PostHogAPIConfig);
|
|
291
|
-
private get baseUrl();
|
|
292
|
-
private get headers();
|
|
293
|
-
private apiRequest;
|
|
294
|
-
getTeamId(): number;
|
|
295
|
-
getBaseUrl(): string;
|
|
296
|
-
getApiKey(): string;
|
|
297
|
-
getLlmGatewayUrl(): string;
|
|
298
|
-
fetchTask(taskId: string): Promise<Task>;
|
|
299
|
-
listTasks(filters?: {
|
|
300
|
-
repository?: string;
|
|
301
|
-
organization?: string;
|
|
302
|
-
origin_product?: string;
|
|
303
|
-
}): Promise<Task[]>;
|
|
304
|
-
updateTask(taskId: string, updates: Partial<Task>): Promise<Task>;
|
|
305
|
-
createTask(payload: TaskCreatePayload): Promise<Task>;
|
|
306
|
-
listTaskRuns(taskId: string): Promise<TaskRun[]>;
|
|
307
|
-
getTaskRun(taskId: string, runId: string): Promise<TaskRun>;
|
|
308
|
-
createTaskRun(taskId: string, payload?: Partial<Omit<TaskRun, "id" | "task" | "team" | "created_at" | "updated_at" | "completed_at" | "artifacts">>): Promise<TaskRun>;
|
|
309
|
-
updateTaskRun(taskId: string, runId: string, payload: TaskRunUpdate): Promise<TaskRun>;
|
|
310
|
-
setTaskRunOutput(taskId: string, runId: string, output: Record<string, unknown>): Promise<TaskRun>;
|
|
311
|
-
appendTaskRunLog(taskId: string, runId: string, entries: StoredEntry[]): Promise<TaskRun>;
|
|
312
|
-
uploadTaskArtifacts(taskId: string, runId: string, artifacts: TaskArtifactUploadPayload[]): Promise<TaskRunArtifact[]>;
|
|
313
|
-
/**
|
|
314
|
-
* Fetch logs from S3 using presigned URL from TaskRun
|
|
315
|
-
* @param taskRun - The task run containing the log_url
|
|
316
|
-
* @returns Array of stored entries, or empty array if no logs available
|
|
317
|
-
*/
|
|
318
|
-
fetchTaskRunLogs(taskRun: TaskRun): Promise<StoredEntry[]>;
|
|
319
|
-
/**
|
|
320
|
-
* Fetch error details from PostHog error tracking
|
|
321
|
-
*/
|
|
322
|
-
fetchErrorDetails(errorId: string, projectId?: string): Promise<PostHogResource>;
|
|
323
|
-
/**
|
|
324
|
-
* Generic resource fetcher by URL or ID
|
|
325
|
-
*/
|
|
326
|
-
fetchResourceByUrl(urlMention: UrlMention): Promise<PostHogResource>;
|
|
327
|
-
/**
|
|
328
|
-
* Format error data for agent consumption
|
|
329
|
-
*/
|
|
330
|
-
private formatErrorContent;
|
|
331
|
-
}
|
|
132
|
+
declare function fetchMcpToolMetadata(mcpServers: Record<string, McpServerConfig>, logger?: Logger): Promise<void>;
|
|
133
|
+
declare function isMcpToolReadOnly(toolName: string): boolean;
|
|
332
134
|
|
|
333
135
|
/**
|
|
334
|
-
*
|
|
136
|
+
* Resume - Restore agent state from persisted log
|
|
137
|
+
*
|
|
138
|
+
* Handles resuming a task from any point:
|
|
139
|
+
* - Fetches log via the PostHog API
|
|
140
|
+
* - Finds latest tree_snapshot event
|
|
141
|
+
* - Rebuilds conversation from log events
|
|
142
|
+
* - Restores working tree from snapshot
|
|
143
|
+
*
|
|
144
|
+
* Uses Saga pattern for atomic operations with clear success/failure tracking.
|
|
145
|
+
*
|
|
146
|
+
* The log is the single source of truth for:
|
|
147
|
+
* - Conversation history (user_message, agent_message_chunk, tool_call, tool_result)
|
|
148
|
+
* - Working tree state (tree_snapshot events)
|
|
149
|
+
* - Session metadata (device info, mode changes)
|
|
335
150
|
*/
|
|
336
|
-
declare enum LogLevel {
|
|
337
|
-
ERROR = 0,
|
|
338
|
-
WARN = 1,
|
|
339
|
-
INFO = 2,
|
|
340
|
-
DEBUG = 3
|
|
341
|
-
}
|
|
342
|
-
interface LoggerConfig {
|
|
343
|
-
debug?: boolean;
|
|
344
|
-
prefix?: string;
|
|
345
|
-
scope?: string;
|
|
346
|
-
onLog?: OnLogCallback;
|
|
347
|
-
}
|
|
348
|
-
declare class Logger {
|
|
349
|
-
private debugEnabled;
|
|
350
|
-
private prefix;
|
|
351
|
-
private scope;
|
|
352
|
-
private onLog?;
|
|
353
|
-
constructor(config?: LoggerConfig);
|
|
354
|
-
setDebug(enabled: boolean): void;
|
|
355
|
-
setOnLog(onLog: OnLogCallback | undefined): void;
|
|
356
|
-
private formatMessage;
|
|
357
|
-
private emitLog;
|
|
358
|
-
error(message: string, error?: Error | unknown): void;
|
|
359
|
-
warn(message: string, data?: unknown): void;
|
|
360
|
-
info(message: string, data?: unknown): void;
|
|
361
|
-
debug(message: string, data?: unknown): void;
|
|
362
|
-
log(level: LogLevel$1, message: string, data?: unknown, scope?: string): void;
|
|
363
|
-
/**
|
|
364
|
-
* Create a child logger with additional prefix and scope
|
|
365
|
-
*/
|
|
366
|
-
child(childPrefix: string): Logger;
|
|
367
|
-
}
|
|
368
151
|
|
|
369
|
-
interface
|
|
152
|
+
interface ResumeState {
|
|
153
|
+
conversation: ConversationTurn[];
|
|
154
|
+
latestSnapshot: TreeSnapshotEvent | null;
|
|
155
|
+
/** Whether the tree snapshot was successfully applied (files restored) */
|
|
156
|
+
snapshotApplied: boolean;
|
|
157
|
+
interrupted: boolean;
|
|
158
|
+
lastDevice?: DeviceInfo;
|
|
159
|
+
logEntryCount: number;
|
|
160
|
+
}
|
|
161
|
+
interface ConversationTurn {
|
|
162
|
+
role: "user" | "assistant";
|
|
163
|
+
content: ContentBlock[];
|
|
164
|
+
toolCalls?: ToolCallInfo[];
|
|
165
|
+
}
|
|
166
|
+
interface ToolCallInfo {
|
|
167
|
+
toolCallId: string;
|
|
168
|
+
toolName: string;
|
|
169
|
+
input: unknown;
|
|
170
|
+
result?: unknown;
|
|
171
|
+
}
|
|
172
|
+
interface ResumeConfig {
|
|
370
173
|
taskId: string;
|
|
371
174
|
runId: string;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
declare class SessionStore {
|
|
376
|
-
private posthogAPI?;
|
|
377
|
-
private pendingEntries;
|
|
378
|
-
private flushTimeouts;
|
|
379
|
-
private configs;
|
|
380
|
-
private logger;
|
|
381
|
-
constructor(posthogAPI?: PostHogAPIClient, logger?: Logger);
|
|
382
|
-
/** Register a session for persistence */
|
|
383
|
-
register(sessionId: string, config: SessionPersistenceConfig): void;
|
|
384
|
-
/** Unregister and flush pending */
|
|
385
|
-
unregister(sessionId: string): Promise<void>;
|
|
386
|
-
/** Check if a session is registered for persistence */
|
|
387
|
-
isRegistered(sessionId: string): boolean;
|
|
388
|
-
/**
|
|
389
|
-
* Append a raw JSON-RPC line for persistence.
|
|
390
|
-
* Parses and wraps as StoredNotification for the API.
|
|
391
|
-
*/
|
|
392
|
-
appendRawLine(sessionId: string, line: string): void;
|
|
393
|
-
/** Load raw JSON-RPC messages from S3 */
|
|
394
|
-
load(logUrl: string): Promise<StoredNotification[]>;
|
|
395
|
-
/**
|
|
396
|
-
* Poll S3 for new entries since last check.
|
|
397
|
-
* Used for interrupt handling in cloud mode.
|
|
398
|
-
*/
|
|
399
|
-
pollForNewEntries(sessionId: string, lastKnownCount: number): Promise<StoredNotification[]>;
|
|
400
|
-
/** Force flush pending entries */
|
|
401
|
-
flush(sessionId: string): Promise<void>;
|
|
402
|
-
private scheduleFlush;
|
|
403
|
-
/** Get the persistence config for a session */
|
|
404
|
-
getConfig(sessionId: string): SessionPersistenceConfig | undefined;
|
|
405
|
-
/**
|
|
406
|
-
* Start a session for persistence.
|
|
407
|
-
* Loads the task run and updates status to "in_progress".
|
|
408
|
-
*/
|
|
409
|
-
start(sessionId: string, taskId: string, runId: string): Promise<TaskRun | undefined>;
|
|
410
|
-
/**
|
|
411
|
-
* Mark a session as completed.
|
|
412
|
-
*/
|
|
413
|
-
complete(sessionId: string): Promise<void>;
|
|
414
|
-
/**
|
|
415
|
-
* Mark a session as failed.
|
|
416
|
-
*/
|
|
417
|
-
fail(sessionId: string, error: Error | string): Promise<void>;
|
|
418
|
-
/**
|
|
419
|
-
* Update the task run associated with a session.
|
|
420
|
-
*/
|
|
421
|
-
updateTaskRun(sessionId: string, update: TaskRunUpdate): Promise<TaskRun | undefined>;
|
|
175
|
+
repositoryPath: string;
|
|
176
|
+
apiClient: PostHogAPIClient;
|
|
177
|
+
logger?: Logger;
|
|
422
178
|
}
|
|
423
|
-
|
|
424
|
-
type StreamPair = {
|
|
425
|
-
readable: globalThis.ReadableStream<Uint8Array>;
|
|
426
|
-
writable: globalThis.WritableStream<Uint8Array>;
|
|
427
|
-
};
|
|
428
|
-
|
|
429
179
|
/**
|
|
430
|
-
*
|
|
431
|
-
*
|
|
180
|
+
* Resume a task from its persisted log.
|
|
181
|
+
* Returns the rebuilt state for the agent to continue from.
|
|
432
182
|
*
|
|
433
|
-
*
|
|
183
|
+
* Uses Saga pattern internally for atomic operations.
|
|
184
|
+
* Note: snapshotApplied field indicates if files were actually restored -
|
|
185
|
+
* even if latestSnapshot is non-null, files may not have been restored if
|
|
186
|
+
* the snapshot had no archive URL or download/extraction failed.
|
|
434
187
|
*/
|
|
435
|
-
|
|
436
|
-
type AcpConnectionConfig = {
|
|
437
|
-
sessionStore?: SessionStore;
|
|
438
|
-
sessionId?: string;
|
|
439
|
-
taskId?: string;
|
|
440
|
-
};
|
|
441
|
-
type InProcessAcpConnection = {
|
|
442
|
-
agentConnection: AgentSideConnection;
|
|
443
|
-
clientStreams: StreamPair;
|
|
444
|
-
};
|
|
445
|
-
declare function createAcpConnection(config?: AcpConnectionConfig): InProcessAcpConnection;
|
|
446
|
-
|
|
447
|
-
declare class Agent {
|
|
448
|
-
private workingDirectory;
|
|
449
|
-
private taskManager;
|
|
450
|
-
private posthogAPI?;
|
|
451
|
-
private fileManager;
|
|
452
|
-
private gitManager;
|
|
453
|
-
private templateManager;
|
|
454
|
-
private logger;
|
|
455
|
-
private acpConnection?;
|
|
456
|
-
private promptBuilder;
|
|
457
|
-
private mcpServers?;
|
|
458
|
-
private canUseTool?;
|
|
459
|
-
private currentRunId?;
|
|
460
|
-
private sessionStore?;
|
|
461
|
-
debug: boolean;
|
|
462
|
-
constructor(config: AgentConfig);
|
|
463
|
-
/**
|
|
464
|
-
* Enable or disable debug logging
|
|
465
|
-
*/
|
|
466
|
-
setDebug(enabled: boolean): void;
|
|
467
|
-
/**
|
|
468
|
-
* Configure LLM gateway environment variables for Claude Code CLI.
|
|
469
|
-
*/
|
|
470
|
-
private _configureLlmGateway;
|
|
471
|
-
private getOrCreateConnection;
|
|
472
|
-
runTask(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<void>;
|
|
473
|
-
/**
|
|
474
|
-
* Creates an in-process ACP connection for client communication.
|
|
475
|
-
* Sets up git branch for the task, configures LLM gateway.
|
|
476
|
-
* The client handles all prompting/querying via the returned streams.
|
|
477
|
-
*
|
|
478
|
-
* @returns InProcessAcpConnection with clientStreams for the client to use
|
|
479
|
-
*/
|
|
480
|
-
runTaskV2(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<InProcessAcpConnection>;
|
|
481
|
-
fetchTask(taskId: string): Promise<Task>;
|
|
482
|
-
getPostHogClient(): PostHogAPIClient | undefined;
|
|
483
|
-
/**
|
|
484
|
-
* Send a notification to a cloud task run's S3 log.
|
|
485
|
-
* The cloud runner will pick up new notifications via interrupt polling.
|
|
486
|
-
*/
|
|
487
|
-
sendNotification(taskId: string, runId: string, notification: StoredNotification): Promise<void>;
|
|
488
|
-
getTaskFiles(taskId: string): Promise<any[]>;
|
|
489
|
-
createPullRequest(taskId: string, branchName: string, taskTitle: string, taskDescription: string, customBody?: string): Promise<string>;
|
|
490
|
-
attachPullRequestToTask(taskId: string, prUrl: string, branchName?: string): Promise<void>;
|
|
491
|
-
updateTaskBranch(taskId: string, branchName: string): Promise<void>;
|
|
492
|
-
cancelTask(taskId: string): void;
|
|
493
|
-
getTaskExecutionStatus(taskId: string): string | null;
|
|
494
|
-
private prepareTaskBranch;
|
|
495
|
-
private ensureOpenAIGatewayEnv;
|
|
496
|
-
private ensureGeminiGatewayEnv;
|
|
497
|
-
runTaskCloud(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<void>;
|
|
498
|
-
private ensurePullRequest;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
declare const TokenEventSchema: z.ZodObject<{
|
|
502
|
-
ts: z.ZodNumber;
|
|
503
|
-
} & {
|
|
504
|
-
type: z.ZodLiteral<"token">;
|
|
505
|
-
content: z.ZodString;
|
|
506
|
-
contentType: z.ZodOptional<z.ZodEnum<["text", "thinking", "tool_input"]>>;
|
|
507
|
-
}, "strip", z.ZodTypeAny, {
|
|
508
|
-
type: "token";
|
|
509
|
-
content: string;
|
|
510
|
-
ts: number;
|
|
511
|
-
contentType?: "text" | "thinking" | "tool_input" | undefined;
|
|
512
|
-
}, {
|
|
513
|
-
type: "token";
|
|
514
|
-
content: string;
|
|
515
|
-
ts: number;
|
|
516
|
-
contentType?: "text" | "thinking" | "tool_input" | undefined;
|
|
517
|
-
}>;
|
|
518
|
-
declare const StatusEventSchema: z.ZodObject<{
|
|
519
|
-
ts: z.ZodNumber;
|
|
520
|
-
} & {
|
|
521
|
-
type: z.ZodLiteral<"status">;
|
|
522
|
-
phase: z.ZodString;
|
|
523
|
-
kind: z.ZodOptional<z.ZodString>;
|
|
524
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
525
|
-
prUrl: z.ZodOptional<z.ZodString>;
|
|
526
|
-
taskId: z.ZodOptional<z.ZodString>;
|
|
527
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
528
|
-
model: z.ZodOptional<z.ZodString>;
|
|
529
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
530
|
-
ts: z.ZodNumber;
|
|
531
|
-
} & {
|
|
532
|
-
type: z.ZodLiteral<"status">;
|
|
533
|
-
phase: z.ZodString;
|
|
534
|
-
kind: z.ZodOptional<z.ZodString>;
|
|
535
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
536
|
-
prUrl: z.ZodOptional<z.ZodString>;
|
|
537
|
-
taskId: z.ZodOptional<z.ZodString>;
|
|
538
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
539
|
-
model: z.ZodOptional<z.ZodString>;
|
|
540
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
541
|
-
ts: z.ZodNumber;
|
|
542
|
-
} & {
|
|
543
|
-
type: z.ZodLiteral<"status">;
|
|
544
|
-
phase: z.ZodString;
|
|
545
|
-
kind: z.ZodOptional<z.ZodString>;
|
|
546
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
547
|
-
prUrl: z.ZodOptional<z.ZodString>;
|
|
548
|
-
taskId: z.ZodOptional<z.ZodString>;
|
|
549
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
550
|
-
model: z.ZodOptional<z.ZodString>;
|
|
551
|
-
}, z.ZodTypeAny, "passthrough">>;
|
|
552
|
-
declare const ConsoleEventSchema: z.ZodObject<{
|
|
553
|
-
ts: z.ZodNumber;
|
|
554
|
-
} & {
|
|
555
|
-
type: z.ZodLiteral<"console">;
|
|
556
|
-
level: z.ZodEnum<["debug", "info", "warn", "error"]>;
|
|
557
|
-
message: z.ZodString;
|
|
558
|
-
}, "strip", z.ZodTypeAny, {
|
|
559
|
-
type: "console";
|
|
560
|
-
message: string;
|
|
561
|
-
ts: number;
|
|
562
|
-
level: "debug" | "info" | "warn" | "error";
|
|
563
|
-
}, {
|
|
564
|
-
type: "console";
|
|
565
|
-
message: string;
|
|
566
|
-
ts: number;
|
|
567
|
-
level: "debug" | "info" | "warn" | "error";
|
|
568
|
-
}>;
|
|
569
|
-
declare const ErrorEventSchema: z.ZodObject<{
|
|
570
|
-
ts: z.ZodNumber;
|
|
571
|
-
} & {
|
|
572
|
-
type: z.ZodLiteral<"error">;
|
|
573
|
-
message: z.ZodString;
|
|
574
|
-
error: z.ZodOptional<z.ZodUnknown>;
|
|
575
|
-
errorType: z.ZodOptional<z.ZodString>;
|
|
576
|
-
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
577
|
-
sdkError: z.ZodOptional<z.ZodUnknown>;
|
|
578
|
-
}, "strip", z.ZodTypeAny, {
|
|
579
|
-
type: "error";
|
|
580
|
-
message: string;
|
|
581
|
-
ts: number;
|
|
582
|
-
error?: unknown;
|
|
583
|
-
context?: Record<string, unknown> | undefined;
|
|
584
|
-
errorType?: string | undefined;
|
|
585
|
-
sdkError?: unknown;
|
|
586
|
-
}, {
|
|
587
|
-
type: "error";
|
|
588
|
-
message: string;
|
|
589
|
-
ts: number;
|
|
590
|
-
error?: unknown;
|
|
591
|
-
context?: Record<string, unknown> | undefined;
|
|
592
|
-
errorType?: string | undefined;
|
|
593
|
-
sdkError?: unknown;
|
|
594
|
-
}>;
|
|
595
|
-
declare const AgentEventSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
596
|
-
ts: z.ZodNumber;
|
|
597
|
-
} & {
|
|
598
|
-
type: z.ZodLiteral<"token">;
|
|
599
|
-
content: z.ZodString;
|
|
600
|
-
contentType: z.ZodOptional<z.ZodEnum<["text", "thinking", "tool_input"]>>;
|
|
601
|
-
}, "strip", z.ZodTypeAny, {
|
|
602
|
-
type: "token";
|
|
603
|
-
content: string;
|
|
604
|
-
ts: number;
|
|
605
|
-
contentType?: "text" | "thinking" | "tool_input" | undefined;
|
|
606
|
-
}, {
|
|
607
|
-
type: "token";
|
|
608
|
-
content: string;
|
|
609
|
-
ts: number;
|
|
610
|
-
contentType?: "text" | "thinking" | "tool_input" | undefined;
|
|
611
|
-
}>, z.ZodObject<{
|
|
612
|
-
ts: z.ZodNumber;
|
|
613
|
-
} & {
|
|
614
|
-
type: z.ZodLiteral<"content_block_start">;
|
|
615
|
-
index: z.ZodNumber;
|
|
616
|
-
contentType: z.ZodEnum<["text", "tool_use", "thinking"]>;
|
|
617
|
-
toolName: z.ZodOptional<z.ZodString>;
|
|
618
|
-
toolId: z.ZodOptional<z.ZodString>;
|
|
619
|
-
}, "strip", z.ZodTypeAny, {
|
|
620
|
-
type: "content_block_start";
|
|
621
|
-
ts: number;
|
|
622
|
-
contentType: "text" | "tool_use" | "thinking";
|
|
623
|
-
index: number;
|
|
624
|
-
toolName?: string | undefined;
|
|
625
|
-
toolId?: string | undefined;
|
|
626
|
-
}, {
|
|
627
|
-
type: "content_block_start";
|
|
628
|
-
ts: number;
|
|
629
|
-
contentType: "text" | "tool_use" | "thinking";
|
|
630
|
-
index: number;
|
|
631
|
-
toolName?: string | undefined;
|
|
632
|
-
toolId?: string | undefined;
|
|
633
|
-
}>, z.ZodObject<{
|
|
634
|
-
ts: z.ZodNumber;
|
|
635
|
-
} & {
|
|
636
|
-
type: z.ZodLiteral<"content_block_stop">;
|
|
637
|
-
index: z.ZodNumber;
|
|
638
|
-
}, "strip", z.ZodTypeAny, {
|
|
639
|
-
type: "content_block_stop";
|
|
640
|
-
ts: number;
|
|
641
|
-
index: number;
|
|
642
|
-
}, {
|
|
643
|
-
type: "content_block_stop";
|
|
644
|
-
ts: number;
|
|
645
|
-
index: number;
|
|
646
|
-
}>, z.ZodObject<{
|
|
647
|
-
ts: z.ZodNumber;
|
|
648
|
-
} & {
|
|
649
|
-
type: z.ZodLiteral<"tool_call">;
|
|
650
|
-
toolName: z.ZodString;
|
|
651
|
-
callId: z.ZodString;
|
|
652
|
-
args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
653
|
-
parentToolUseId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
654
|
-
tool: z.ZodOptional<z.ZodUnknown>;
|
|
655
|
-
category: z.ZodOptional<z.ZodUnknown>;
|
|
656
|
-
}, "strip", z.ZodTypeAny, {
|
|
657
|
-
type: "tool_call";
|
|
658
|
-
args: Record<string, unknown>;
|
|
659
|
-
toolName: string;
|
|
660
|
-
ts: number;
|
|
661
|
-
callId: string;
|
|
662
|
-
parentToolUseId?: string | null | undefined;
|
|
663
|
-
tool?: unknown;
|
|
664
|
-
category?: unknown;
|
|
665
|
-
}, {
|
|
666
|
-
type: "tool_call";
|
|
667
|
-
args: Record<string, unknown>;
|
|
668
|
-
toolName: string;
|
|
669
|
-
ts: number;
|
|
670
|
-
callId: string;
|
|
671
|
-
parentToolUseId?: string | null | undefined;
|
|
672
|
-
tool?: unknown;
|
|
673
|
-
category?: unknown;
|
|
674
|
-
}>, z.ZodObject<{
|
|
675
|
-
ts: z.ZodNumber;
|
|
676
|
-
} & {
|
|
677
|
-
type: z.ZodLiteral<"tool_result">;
|
|
678
|
-
toolName: z.ZodString;
|
|
679
|
-
callId: z.ZodString;
|
|
680
|
-
result: z.ZodUnknown;
|
|
681
|
-
isError: z.ZodOptional<z.ZodBoolean>;
|
|
682
|
-
parentToolUseId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
683
|
-
tool: z.ZodOptional<z.ZodUnknown>;
|
|
684
|
-
category: z.ZodOptional<z.ZodUnknown>;
|
|
685
|
-
}, "strip", z.ZodTypeAny, {
|
|
686
|
-
type: "tool_result";
|
|
687
|
-
toolName: string;
|
|
688
|
-
ts: number;
|
|
689
|
-
callId: string;
|
|
690
|
-
isError?: boolean | undefined;
|
|
691
|
-
result?: unknown;
|
|
692
|
-
parentToolUseId?: string | null | undefined;
|
|
693
|
-
tool?: unknown;
|
|
694
|
-
category?: unknown;
|
|
695
|
-
}, {
|
|
696
|
-
type: "tool_result";
|
|
697
|
-
toolName: string;
|
|
698
|
-
ts: number;
|
|
699
|
-
callId: string;
|
|
700
|
-
isError?: boolean | undefined;
|
|
701
|
-
result?: unknown;
|
|
702
|
-
parentToolUseId?: string | null | undefined;
|
|
703
|
-
tool?: unknown;
|
|
704
|
-
category?: unknown;
|
|
705
|
-
}>, z.ZodObject<{
|
|
706
|
-
ts: z.ZodNumber;
|
|
707
|
-
} & {
|
|
708
|
-
type: z.ZodLiteral<"message_start">;
|
|
709
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
710
|
-
model: z.ZodOptional<z.ZodString>;
|
|
711
|
-
}, "strip", z.ZodTypeAny, {
|
|
712
|
-
type: "message_start";
|
|
713
|
-
ts: number;
|
|
714
|
-
model?: string | undefined;
|
|
715
|
-
messageId?: string | undefined;
|
|
716
|
-
}, {
|
|
717
|
-
type: "message_start";
|
|
718
|
-
ts: number;
|
|
719
|
-
model?: string | undefined;
|
|
720
|
-
messageId?: string | undefined;
|
|
721
|
-
}>, z.ZodObject<{
|
|
722
|
-
ts: z.ZodNumber;
|
|
723
|
-
} & {
|
|
724
|
-
type: z.ZodLiteral<"message_delta">;
|
|
725
|
-
stopReason: z.ZodOptional<z.ZodString>;
|
|
726
|
-
stopSequence: z.ZodOptional<z.ZodString>;
|
|
727
|
-
usage: z.ZodOptional<z.ZodObject<{
|
|
728
|
-
outputTokens: z.ZodNumber;
|
|
729
|
-
}, "strip", z.ZodTypeAny, {
|
|
730
|
-
outputTokens: number;
|
|
731
|
-
}, {
|
|
732
|
-
outputTokens: number;
|
|
733
|
-
}>>;
|
|
734
|
-
}, "strip", z.ZodTypeAny, {
|
|
735
|
-
type: "message_delta";
|
|
736
|
-
ts: number;
|
|
737
|
-
stopReason?: string | undefined;
|
|
738
|
-
usage?: {
|
|
739
|
-
outputTokens: number;
|
|
740
|
-
} | undefined;
|
|
741
|
-
stopSequence?: string | undefined;
|
|
742
|
-
}, {
|
|
743
|
-
type: "message_delta";
|
|
744
|
-
ts: number;
|
|
745
|
-
stopReason?: string | undefined;
|
|
746
|
-
usage?: {
|
|
747
|
-
outputTokens: number;
|
|
748
|
-
} | undefined;
|
|
749
|
-
stopSequence?: string | undefined;
|
|
750
|
-
}>, z.ZodObject<{
|
|
751
|
-
ts: z.ZodNumber;
|
|
752
|
-
} & {
|
|
753
|
-
type: z.ZodLiteral<"message_stop">;
|
|
754
|
-
}, "strip", z.ZodTypeAny, {
|
|
755
|
-
type: "message_stop";
|
|
756
|
-
ts: number;
|
|
757
|
-
}, {
|
|
758
|
-
type: "message_stop";
|
|
759
|
-
ts: number;
|
|
760
|
-
}>, z.ZodObject<{
|
|
761
|
-
ts: z.ZodNumber;
|
|
762
|
-
} & {
|
|
763
|
-
type: z.ZodLiteral<"user_message">;
|
|
764
|
-
content: z.ZodString;
|
|
765
|
-
isSynthetic: z.ZodOptional<z.ZodBoolean>;
|
|
766
|
-
}, "strip", z.ZodTypeAny, {
|
|
767
|
-
type: "user_message";
|
|
768
|
-
content: string;
|
|
769
|
-
ts: number;
|
|
770
|
-
isSynthetic?: boolean | undefined;
|
|
771
|
-
}, {
|
|
772
|
-
type: "user_message";
|
|
773
|
-
content: string;
|
|
774
|
-
ts: number;
|
|
775
|
-
isSynthetic?: boolean | undefined;
|
|
776
|
-
}>, z.ZodObject<{
|
|
777
|
-
ts: z.ZodNumber;
|
|
778
|
-
} & {
|
|
779
|
-
type: z.ZodLiteral<"status">;
|
|
780
|
-
phase: z.ZodString;
|
|
781
|
-
kind: z.ZodOptional<z.ZodString>;
|
|
782
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
783
|
-
prUrl: z.ZodOptional<z.ZodString>;
|
|
784
|
-
taskId: z.ZodOptional<z.ZodString>;
|
|
785
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
786
|
-
model: z.ZodOptional<z.ZodString>;
|
|
787
|
-
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
788
|
-
ts: z.ZodNumber;
|
|
789
|
-
} & {
|
|
790
|
-
type: z.ZodLiteral<"status">;
|
|
791
|
-
phase: z.ZodString;
|
|
792
|
-
kind: z.ZodOptional<z.ZodString>;
|
|
793
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
794
|
-
prUrl: z.ZodOptional<z.ZodString>;
|
|
795
|
-
taskId: z.ZodOptional<z.ZodString>;
|
|
796
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
797
|
-
model: z.ZodOptional<z.ZodString>;
|
|
798
|
-
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
799
|
-
ts: z.ZodNumber;
|
|
800
|
-
} & {
|
|
801
|
-
type: z.ZodLiteral<"status">;
|
|
802
|
-
phase: z.ZodString;
|
|
803
|
-
kind: z.ZodOptional<z.ZodString>;
|
|
804
|
-
branch: z.ZodOptional<z.ZodString>;
|
|
805
|
-
prUrl: z.ZodOptional<z.ZodString>;
|
|
806
|
-
taskId: z.ZodOptional<z.ZodString>;
|
|
807
|
-
messageId: z.ZodOptional<z.ZodString>;
|
|
808
|
-
model: z.ZodOptional<z.ZodString>;
|
|
809
|
-
}, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
|
|
810
|
-
ts: z.ZodNumber;
|
|
811
|
-
} & {
|
|
812
|
-
type: z.ZodLiteral<"init">;
|
|
813
|
-
model: z.ZodString;
|
|
814
|
-
tools: z.ZodArray<z.ZodString, "many">;
|
|
815
|
-
permissionMode: z.ZodString;
|
|
816
|
-
cwd: z.ZodString;
|
|
817
|
-
apiKeySource: z.ZodString;
|
|
818
|
-
agents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
819
|
-
slashCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
820
|
-
outputStyle: z.ZodOptional<z.ZodString>;
|
|
821
|
-
mcpServers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
822
|
-
name: z.ZodString;
|
|
823
|
-
status: z.ZodString;
|
|
824
|
-
}, "strip", z.ZodTypeAny, {
|
|
825
|
-
status: string;
|
|
826
|
-
name: string;
|
|
827
|
-
}, {
|
|
828
|
-
status: string;
|
|
829
|
-
name: string;
|
|
830
|
-
}>, "many">>;
|
|
831
|
-
}, "strip", z.ZodTypeAny, {
|
|
832
|
-
type: "init";
|
|
833
|
-
tools: string[];
|
|
834
|
-
cwd: string;
|
|
835
|
-
model: string;
|
|
836
|
-
permissionMode: string;
|
|
837
|
-
apiKeySource: string;
|
|
838
|
-
ts: number;
|
|
839
|
-
mcpServers?: {
|
|
840
|
-
status: string;
|
|
841
|
-
name: string;
|
|
842
|
-
}[] | undefined;
|
|
843
|
-
agents?: string[] | undefined;
|
|
844
|
-
slashCommands?: string[] | undefined;
|
|
845
|
-
outputStyle?: string | undefined;
|
|
846
|
-
}, {
|
|
847
|
-
type: "init";
|
|
848
|
-
tools: string[];
|
|
849
|
-
cwd: string;
|
|
850
|
-
model: string;
|
|
851
|
-
permissionMode: string;
|
|
852
|
-
apiKeySource: string;
|
|
853
|
-
ts: number;
|
|
854
|
-
mcpServers?: {
|
|
855
|
-
status: string;
|
|
856
|
-
name: string;
|
|
857
|
-
}[] | undefined;
|
|
858
|
-
agents?: string[] | undefined;
|
|
859
|
-
slashCommands?: string[] | undefined;
|
|
860
|
-
outputStyle?: string | undefined;
|
|
861
|
-
}>, z.ZodObject<{
|
|
862
|
-
ts: z.ZodNumber;
|
|
863
|
-
} & {
|
|
864
|
-
type: z.ZodLiteral<"console">;
|
|
865
|
-
level: z.ZodEnum<["debug", "info", "warn", "error"]>;
|
|
866
|
-
message: z.ZodString;
|
|
867
|
-
}, "strip", z.ZodTypeAny, {
|
|
868
|
-
type: "console";
|
|
869
|
-
message: string;
|
|
870
|
-
ts: number;
|
|
871
|
-
level: "debug" | "info" | "warn" | "error";
|
|
872
|
-
}, {
|
|
873
|
-
type: "console";
|
|
874
|
-
message: string;
|
|
875
|
-
ts: number;
|
|
876
|
-
level: "debug" | "info" | "warn" | "error";
|
|
877
|
-
}>, z.ZodObject<{
|
|
878
|
-
ts: z.ZodNumber;
|
|
879
|
-
} & {
|
|
880
|
-
type: z.ZodLiteral<"compact_boundary">;
|
|
881
|
-
trigger: z.ZodEnum<["manual", "auto"]>;
|
|
882
|
-
preTokens: z.ZodNumber;
|
|
883
|
-
}, "strip", z.ZodTypeAny, {
|
|
884
|
-
type: "compact_boundary";
|
|
885
|
-
ts: number;
|
|
886
|
-
trigger: "manual" | "auto";
|
|
887
|
-
preTokens: number;
|
|
888
|
-
}, {
|
|
889
|
-
type: "compact_boundary";
|
|
890
|
-
ts: number;
|
|
891
|
-
trigger: "manual" | "auto";
|
|
892
|
-
preTokens: number;
|
|
893
|
-
}>, z.ZodObject<{
|
|
894
|
-
ts: z.ZodNumber;
|
|
895
|
-
} & {
|
|
896
|
-
type: z.ZodLiteral<"done">;
|
|
897
|
-
result: z.ZodOptional<z.ZodString>;
|
|
898
|
-
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
899
|
-
durationApiMs: z.ZodOptional<z.ZodNumber>;
|
|
900
|
-
numTurns: z.ZodOptional<z.ZodNumber>;
|
|
901
|
-
totalCostUsd: z.ZodOptional<z.ZodNumber>;
|
|
902
|
-
usage: z.ZodOptional<z.ZodUnknown>;
|
|
903
|
-
modelUsage: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
904
|
-
inputTokens: z.ZodNumber;
|
|
905
|
-
outputTokens: z.ZodNumber;
|
|
906
|
-
cacheReadInputTokens: z.ZodNumber;
|
|
907
|
-
cacheCreationInputTokens: z.ZodNumber;
|
|
908
|
-
webSearchRequests: z.ZodNumber;
|
|
909
|
-
costUSD: z.ZodNumber;
|
|
910
|
-
contextWindow: z.ZodNumber;
|
|
911
|
-
}, "strip", z.ZodTypeAny, {
|
|
912
|
-
outputTokens: number;
|
|
913
|
-
inputTokens: number;
|
|
914
|
-
cacheReadInputTokens: number;
|
|
915
|
-
cacheCreationInputTokens: number;
|
|
916
|
-
webSearchRequests: number;
|
|
917
|
-
costUSD: number;
|
|
918
|
-
contextWindow: number;
|
|
919
|
-
}, {
|
|
920
|
-
outputTokens: number;
|
|
921
|
-
inputTokens: number;
|
|
922
|
-
cacheReadInputTokens: number;
|
|
923
|
-
cacheCreationInputTokens: number;
|
|
924
|
-
webSearchRequests: number;
|
|
925
|
-
costUSD: number;
|
|
926
|
-
contextWindow: number;
|
|
927
|
-
}>>>;
|
|
928
|
-
permissionDenials: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
929
|
-
tool_name: z.ZodString;
|
|
930
|
-
tool_use_id: z.ZodString;
|
|
931
|
-
tool_input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
932
|
-
}, "strip", z.ZodTypeAny, {
|
|
933
|
-
tool_use_id: string;
|
|
934
|
-
tool_name: string;
|
|
935
|
-
tool_input: Record<string, unknown>;
|
|
936
|
-
}, {
|
|
937
|
-
tool_use_id: string;
|
|
938
|
-
tool_name: string;
|
|
939
|
-
tool_input: Record<string, unknown>;
|
|
940
|
-
}>, "many">>;
|
|
941
|
-
}, "strip", z.ZodTypeAny, {
|
|
942
|
-
type: "done";
|
|
943
|
-
ts: number;
|
|
944
|
-
result?: string | undefined;
|
|
945
|
-
usage?: unknown;
|
|
946
|
-
modelUsage?: Record<string, {
|
|
947
|
-
outputTokens: number;
|
|
948
|
-
inputTokens: number;
|
|
949
|
-
cacheReadInputTokens: number;
|
|
950
|
-
cacheCreationInputTokens: number;
|
|
951
|
-
webSearchRequests: number;
|
|
952
|
-
costUSD: number;
|
|
953
|
-
contextWindow: number;
|
|
954
|
-
}> | undefined;
|
|
955
|
-
durationMs?: number | undefined;
|
|
956
|
-
durationApiMs?: number | undefined;
|
|
957
|
-
numTurns?: number | undefined;
|
|
958
|
-
totalCostUsd?: number | undefined;
|
|
959
|
-
permissionDenials?: {
|
|
960
|
-
tool_use_id: string;
|
|
961
|
-
tool_name: string;
|
|
962
|
-
tool_input: Record<string, unknown>;
|
|
963
|
-
}[] | undefined;
|
|
964
|
-
}, {
|
|
965
|
-
type: "done";
|
|
966
|
-
ts: number;
|
|
967
|
-
result?: string | undefined;
|
|
968
|
-
usage?: unknown;
|
|
969
|
-
modelUsage?: Record<string, {
|
|
970
|
-
outputTokens: number;
|
|
971
|
-
inputTokens: number;
|
|
972
|
-
cacheReadInputTokens: number;
|
|
973
|
-
cacheCreationInputTokens: number;
|
|
974
|
-
webSearchRequests: number;
|
|
975
|
-
costUSD: number;
|
|
976
|
-
contextWindow: number;
|
|
977
|
-
}> | undefined;
|
|
978
|
-
durationMs?: number | undefined;
|
|
979
|
-
durationApiMs?: number | undefined;
|
|
980
|
-
numTurns?: number | undefined;
|
|
981
|
-
totalCostUsd?: number | undefined;
|
|
982
|
-
permissionDenials?: {
|
|
983
|
-
tool_use_id: string;
|
|
984
|
-
tool_name: string;
|
|
985
|
-
tool_input: Record<string, unknown>;
|
|
986
|
-
}[] | undefined;
|
|
987
|
-
}>, z.ZodObject<{
|
|
988
|
-
ts: z.ZodNumber;
|
|
989
|
-
} & {
|
|
990
|
-
type: z.ZodLiteral<"error">;
|
|
991
|
-
message: z.ZodString;
|
|
992
|
-
error: z.ZodOptional<z.ZodUnknown>;
|
|
993
|
-
errorType: z.ZodOptional<z.ZodString>;
|
|
994
|
-
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
995
|
-
sdkError: z.ZodOptional<z.ZodUnknown>;
|
|
996
|
-
}, "strip", z.ZodTypeAny, {
|
|
997
|
-
type: "error";
|
|
998
|
-
message: string;
|
|
999
|
-
ts: number;
|
|
1000
|
-
error?: unknown;
|
|
1001
|
-
context?: Record<string, unknown> | undefined;
|
|
1002
|
-
errorType?: string | undefined;
|
|
1003
|
-
sdkError?: unknown;
|
|
1004
|
-
}, {
|
|
1005
|
-
type: "error";
|
|
1006
|
-
message: string;
|
|
1007
|
-
ts: number;
|
|
1008
|
-
error?: unknown;
|
|
1009
|
-
context?: Record<string, unknown> | undefined;
|
|
1010
|
-
errorType?: string | undefined;
|
|
1011
|
-
sdkError?: unknown;
|
|
1012
|
-
}>, z.ZodObject<{
|
|
1013
|
-
ts: z.ZodNumber;
|
|
1014
|
-
} & {
|
|
1015
|
-
type: z.ZodLiteral<"metric">;
|
|
1016
|
-
key: z.ZodString;
|
|
1017
|
-
value: z.ZodNumber;
|
|
1018
|
-
unit: z.ZodOptional<z.ZodString>;
|
|
1019
|
-
}, "strip", z.ZodTypeAny, {
|
|
1020
|
-
key: string;
|
|
1021
|
-
value: number;
|
|
1022
|
-
type: "metric";
|
|
1023
|
-
ts: number;
|
|
1024
|
-
unit?: string | undefined;
|
|
1025
|
-
}, {
|
|
1026
|
-
key: string;
|
|
1027
|
-
value: number;
|
|
1028
|
-
type: "metric";
|
|
1029
|
-
ts: number;
|
|
1030
|
-
unit?: string | undefined;
|
|
1031
|
-
}>, z.ZodObject<{
|
|
1032
|
-
ts: z.ZodNumber;
|
|
1033
|
-
} & {
|
|
1034
|
-
type: z.ZodLiteral<"artifact">;
|
|
1035
|
-
kind: z.ZodString;
|
|
1036
|
-
content: z.ZodUnknown;
|
|
1037
|
-
}, "strip", z.ZodTypeAny, {
|
|
1038
|
-
type: "artifact";
|
|
1039
|
-
kind: string;
|
|
1040
|
-
ts: number;
|
|
1041
|
-
content?: unknown;
|
|
1042
|
-
}, {
|
|
1043
|
-
type: "artifact";
|
|
1044
|
-
kind: string;
|
|
1045
|
-
ts: number;
|
|
1046
|
-
content?: unknown;
|
|
1047
|
-
}>, z.ZodObject<{
|
|
1048
|
-
ts: z.ZodNumber;
|
|
1049
|
-
} & {
|
|
1050
|
-
type: z.ZodLiteral<"raw_sdk_event">;
|
|
1051
|
-
sdkMessage: z.ZodUnknown;
|
|
1052
|
-
}, "strip", z.ZodTypeAny, {
|
|
1053
|
-
type: "raw_sdk_event";
|
|
1054
|
-
ts: number;
|
|
1055
|
-
sdkMessage?: unknown;
|
|
1056
|
-
}, {
|
|
1057
|
-
type: "raw_sdk_event";
|
|
1058
|
-
ts: number;
|
|
1059
|
-
sdkMessage?: unknown;
|
|
1060
|
-
}>]>;
|
|
1061
|
-
type TokenEvent = z.infer<typeof TokenEventSchema>;
|
|
1062
|
-
type StatusEvent = z.infer<typeof StatusEventSchema>;
|
|
1063
|
-
type ConsoleEvent = z.infer<typeof ConsoleEventSchema>;
|
|
1064
|
-
type ErrorEvent = z.infer<typeof ErrorEventSchema>;
|
|
1065
|
-
type AgentEvent = z.infer<typeof AgentEventSchema>;
|
|
188
|
+
declare function resumeFromLog(config: ResumeConfig): Promise<ResumeState>;
|
|
1066
189
|
/**
|
|
1067
|
-
*
|
|
1068
|
-
* Returns the parsed event if valid, or null if invalid.
|
|
190
|
+
* Convert resumed conversation back to API format for continuation.
|
|
1069
191
|
*/
|
|
1070
|
-
declare function
|
|
192
|
+
declare function conversationToPromptHistory(conversation: ConversationTurn[]): Array<{
|
|
193
|
+
role: "user" | "assistant";
|
|
194
|
+
content: ContentBlock[];
|
|
195
|
+
}>;
|
|
196
|
+
|
|
1071
197
|
/**
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
198
|
+
* TreeTracker - Git tree-based state capture for cloud/local sync
|
|
199
|
+
*
|
|
200
|
+
* Captures the entire working state as a git tree hash + archive:
|
|
201
|
+
* - Atomic state snapshots (no partial syncs)
|
|
202
|
+
* - Efficient delta detection using git's diffing
|
|
203
|
+
* - Simpler resume logic (restore tree, continue)
|
|
204
|
+
*
|
|
205
|
+
* Uses Saga pattern for atomic operations with automatic rollback on failure.
|
|
206
|
+
* Uses a temporary git index to avoid modifying the user's staging area.
|
|
1074
207
|
*/
|
|
1075
|
-
declare function parseAgentEvents(inputs: unknown[]): AgentEvent[];
|
|
1076
208
|
|
|
1077
|
-
interface
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
name: string;
|
|
1084
|
-
content: string;
|
|
1085
|
-
type: TaskFile["type"];
|
|
1086
|
-
contentType: string;
|
|
1087
|
-
size: number;
|
|
209
|
+
interface TreeTrackerConfig {
|
|
210
|
+
repositoryPath: string;
|
|
211
|
+
taskId: string;
|
|
212
|
+
runId: string;
|
|
213
|
+
apiClient?: PostHogAPIClient;
|
|
214
|
+
logger?: Logger;
|
|
1088
215
|
}
|
|
1089
|
-
declare class
|
|
216
|
+
declare class TreeTracker {
|
|
1090
217
|
private repositoryPath;
|
|
218
|
+
private taskId;
|
|
219
|
+
private runId;
|
|
220
|
+
private apiClient?;
|
|
1091
221
|
private logger;
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
private getTaskFilePath;
|
|
1095
|
-
ensureTaskDirectory(taskId: string): Promise<void>;
|
|
1096
|
-
writeTaskFile(taskId: string, file: TaskFile): Promise<void>;
|
|
1097
|
-
readTaskFile(taskId: string, fileName: string): Promise<string | null>;
|
|
1098
|
-
listTaskFiles(taskId: string): Promise<string[]>;
|
|
1099
|
-
deleteTaskFile(taskId: string, fileName: string): Promise<void>;
|
|
1100
|
-
taskDirectoryExists(taskId: string): Promise<boolean>;
|
|
1101
|
-
cleanupTaskDirectory(taskId: string): Promise<void>;
|
|
1102
|
-
writePlan(taskId: string, plan: string): Promise<void>;
|
|
1103
|
-
readPlan(taskId: string): Promise<string | null>;
|
|
1104
|
-
writeContext(taskId: string, context: string): Promise<void>;
|
|
1105
|
-
readContext(taskId: string): Promise<string | null>;
|
|
1106
|
-
writeRequirements(taskId: string, requirements: string): Promise<void>;
|
|
1107
|
-
readRequirements(taskId: string): Promise<string | null>;
|
|
1108
|
-
writeResearch(taskId: string, data: ResearchEvaluation): Promise<void>;
|
|
1109
|
-
readResearch(taskId: string): Promise<ResearchEvaluation | null>;
|
|
1110
|
-
writeTodos(taskId: string, data: unknown): Promise<void>;
|
|
1111
|
-
readTodos(taskId: string): Promise<unknown | null>;
|
|
1112
|
-
getTaskFiles(taskId: string): Promise<SupportingFile[]>;
|
|
1113
|
-
collectTaskArtifacts(taskId: string): Promise<LocalArtifact[]>;
|
|
1114
|
-
private resolveFileType;
|
|
1115
|
-
private inferContentType;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
interface TodoItem {
|
|
1119
|
-
content: string;
|
|
1120
|
-
status: "pending" | "in_progress" | "completed";
|
|
1121
|
-
activeForm: string;
|
|
1122
|
-
}
|
|
1123
|
-
interface TodoList {
|
|
1124
|
-
items: TodoItem[];
|
|
1125
|
-
metadata: {
|
|
1126
|
-
total: number;
|
|
1127
|
-
pending: number;
|
|
1128
|
-
in_progress: number;
|
|
1129
|
-
completed: number;
|
|
1130
|
-
last_updated: string;
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
declare class TodoManager {
|
|
1134
|
-
private fileManager;
|
|
1135
|
-
private logger;
|
|
1136
|
-
constructor(fileManager: PostHogFileManager, logger?: Logger);
|
|
1137
|
-
readTodos(taskId: string): Promise<TodoList | null>;
|
|
1138
|
-
writeTodos(taskId: string, todos: TodoList): Promise<void>;
|
|
1139
|
-
parseTodoWriteInput(toolInput: Record<string, unknown>): TodoList;
|
|
1140
|
-
private calculateMetadata;
|
|
1141
|
-
getTodoContext(taskId: string): Promise<string>;
|
|
1142
|
-
checkAndPersistFromMessage(message: Record<string, unknown>, taskId: string): Promise<TodoList | null>;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
/**
|
|
1146
|
-
* Tool category classification for grouping related tools.
|
|
1147
|
-
* Makes it easier for UIs to filter and display tools by function.
|
|
1148
|
-
*/
|
|
1149
|
-
type ToolCategory = "filesystem" | "shell" | "web" | "assistant" | "search" | "unknown";
|
|
1150
|
-
/**
|
|
1151
|
-
* Base tool interface representing a tool that can be called by the agent.
|
|
1152
|
-
* Each tool has a name, category, and human-readable description.
|
|
1153
|
-
*/
|
|
1154
|
-
interface Tool {
|
|
1155
|
-
name: string;
|
|
1156
|
-
category: ToolCategory;
|
|
1157
|
-
description: string;
|
|
1158
|
-
}
|
|
1159
|
-
interface ReadTool extends Tool {
|
|
1160
|
-
name: "Read";
|
|
1161
|
-
category: "filesystem";
|
|
1162
|
-
}
|
|
1163
|
-
interface WriteTool extends Tool {
|
|
1164
|
-
name: "Write";
|
|
1165
|
-
category: "filesystem";
|
|
1166
|
-
}
|
|
1167
|
-
interface EditTool extends Tool {
|
|
1168
|
-
name: "Edit";
|
|
1169
|
-
category: "filesystem";
|
|
1170
|
-
}
|
|
1171
|
-
interface GlobTool extends Tool {
|
|
1172
|
-
name: "Glob";
|
|
1173
|
-
category: "filesystem";
|
|
1174
|
-
}
|
|
1175
|
-
interface NotebookEditTool extends Tool {
|
|
1176
|
-
name: "NotebookEdit";
|
|
1177
|
-
category: "filesystem";
|
|
1178
|
-
}
|
|
1179
|
-
interface BashTool extends Tool {
|
|
1180
|
-
name: "Bash";
|
|
1181
|
-
category: "shell";
|
|
1182
|
-
}
|
|
1183
|
-
interface BashOutputTool extends Tool {
|
|
1184
|
-
name: "BashOutput";
|
|
1185
|
-
category: "shell";
|
|
1186
|
-
}
|
|
1187
|
-
interface KillShellTool extends Tool {
|
|
1188
|
-
name: "KillShell";
|
|
1189
|
-
category: "shell";
|
|
1190
|
-
}
|
|
1191
|
-
interface WebFetchTool extends Tool {
|
|
1192
|
-
name: "WebFetch";
|
|
1193
|
-
category: "web";
|
|
1194
|
-
}
|
|
1195
|
-
interface WebSearchTool extends Tool {
|
|
1196
|
-
name: "WebSearch";
|
|
1197
|
-
category: "web";
|
|
1198
|
-
}
|
|
1199
|
-
interface GrepTool extends Tool {
|
|
1200
|
-
name: "Grep";
|
|
1201
|
-
category: "search";
|
|
1202
|
-
}
|
|
1203
|
-
interface TaskTool extends Tool {
|
|
1204
|
-
name: "Task";
|
|
1205
|
-
category: "assistant";
|
|
1206
|
-
}
|
|
1207
|
-
interface TodoWriteTool extends Tool {
|
|
1208
|
-
name: "TodoWrite";
|
|
1209
|
-
category: "assistant";
|
|
1210
|
-
}
|
|
1211
|
-
interface ExitPlanModeTool extends Tool {
|
|
1212
|
-
name: "ExitPlanMode";
|
|
1213
|
-
category: "assistant";
|
|
1214
|
-
}
|
|
1215
|
-
interface SlashCommandTool extends Tool {
|
|
1216
|
-
name: "SlashCommand";
|
|
1217
|
-
category: "assistant";
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* Union type of all known tool types.
|
|
1221
|
-
* Useful for discriminated unions and type narrowing.
|
|
1222
|
-
*/
|
|
1223
|
-
type KnownTool = ReadTool | WriteTool | EditTool | GlobTool | NotebookEditTool | BashTool | BashOutputTool | KillShellTool | WebFetchTool | WebSearchTool | GrepTool | TaskTool | TodoWriteTool | ExitPlanModeTool | SlashCommandTool;
|
|
1224
|
-
|
|
1225
|
-
/**
|
|
1226
|
-
* Tool registry for looking up tool definitions by name.
|
|
1227
|
-
* Provides metadata about tools for UI consumption.
|
|
1228
|
-
*/
|
|
1229
|
-
declare class ToolRegistry {
|
|
222
|
+
private lastTreeHash;
|
|
223
|
+
constructor(config: TreeTrackerConfig);
|
|
1230
224
|
/**
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
225
|
+
* Capture current working tree state as a snapshot.
|
|
226
|
+
* Uses a temporary index to avoid modifying user's staging area.
|
|
227
|
+
* Uses Saga pattern for atomic operation with automatic cleanup on failure.
|
|
1233
228
|
*/
|
|
1234
|
-
|
|
229
|
+
captureTree(options?: {
|
|
230
|
+
interrupted?: boolean;
|
|
231
|
+
}): Promise<TreeSnapshot | null>;
|
|
1235
232
|
/**
|
|
1236
|
-
*
|
|
233
|
+
* Download and apply a tree snapshot.
|
|
234
|
+
* Uses Saga pattern for atomic operation with rollback on failure.
|
|
1237
235
|
*/
|
|
1238
|
-
|
|
236
|
+
applyTreeSnapshot(snapshot: TreeSnapshot): Promise<void>;
|
|
1239
237
|
/**
|
|
1240
|
-
*
|
|
238
|
+
* Get the last captured tree hash.
|
|
1241
239
|
*/
|
|
1242
|
-
|
|
240
|
+
getLastTreeHash(): string | null;
|
|
1243
241
|
/**
|
|
1244
|
-
*
|
|
242
|
+
* Set the last tree hash (used when resuming).
|
|
1245
243
|
*/
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
declare function getLlmGatewayUrl(posthogHost: string): string;
|
|
1250
|
-
|
|
1251
|
-
interface WorktreeConfig {
|
|
1252
|
-
mainRepoPath: string;
|
|
1253
|
-
worktreeBasePath?: string;
|
|
1254
|
-
logger?: Logger;
|
|
1255
|
-
}
|
|
1256
|
-
declare class WorktreeManager {
|
|
1257
|
-
private mainRepoPath;
|
|
1258
|
-
private worktreeBasePath;
|
|
1259
|
-
private repoName;
|
|
1260
|
-
private logger;
|
|
1261
|
-
constructor(config: WorktreeConfig);
|
|
1262
|
-
private usesExternalPath;
|
|
1263
|
-
private runGitCommand;
|
|
1264
|
-
private randomElement;
|
|
1265
|
-
generateWorktreeName(): string;
|
|
1266
|
-
private getWorktreeFolderPath;
|
|
1267
|
-
private getWorktreePath;
|
|
1268
|
-
worktreeExists(name: string): Promise<boolean>;
|
|
1269
|
-
ensureArrayDirIgnored(): Promise<void>;
|
|
1270
|
-
private generateUniqueWorktreeName;
|
|
1271
|
-
private getDefaultBranch;
|
|
1272
|
-
createWorktree(options?: {
|
|
1273
|
-
baseBranch?: string;
|
|
1274
|
-
}): Promise<WorktreeInfo>;
|
|
1275
|
-
deleteWorktree(worktreePath: string): Promise<void>;
|
|
1276
|
-
getWorktreeInfo(worktreePath: string): Promise<WorktreeInfo | null>;
|
|
1277
|
-
listWorktrees(): Promise<WorktreeInfo[]>;
|
|
1278
|
-
private parseWorktreeList;
|
|
1279
|
-
isWorktree(repoPath: string): Promise<boolean>;
|
|
1280
|
-
getMainRepoPathFromWorktree(worktreePath: string): Promise<string | null>;
|
|
1281
|
-
cleanupOrphanedWorktrees(associatedWorktreePaths: string[]): Promise<{
|
|
1282
|
-
deleted: string[];
|
|
1283
|
-
errors: Array<{
|
|
1284
|
-
path: string;
|
|
1285
|
-
error: string;
|
|
1286
|
-
}>;
|
|
1287
|
-
}>;
|
|
244
|
+
setLastTreeHash(hash: string | null): void;
|
|
1288
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Check if a commit is available on any remote branch.
|
|
248
|
+
* Used to validate that cloud can fetch the base commit during handoff.
|
|
249
|
+
*/
|
|
250
|
+
declare function isCommitOnRemote(commit: string, cwd: string): Promise<boolean>;
|
|
251
|
+
/**
|
|
252
|
+
* Validate that a snapshot can be handed off to cloud execution.
|
|
253
|
+
* Cloud needs to be able to fetch the baseCommit from a remote.
|
|
254
|
+
*
|
|
255
|
+
* @throws Error if the snapshot cannot be restored on cloud
|
|
256
|
+
*/
|
|
257
|
+
declare function validateForCloudHandoff(snapshot: TreeSnapshot, repositoryPath: string): Promise<void>;
|
|
1289
258
|
|
|
1290
|
-
export { type
|
|
259
|
+
export { type BranchCreatedPayload, type CompactBoundaryPayload, type ConsoleNotificationPayload, type ConversationTurn, DeviceInfo, type ErrorNotificationPayload, Logger, type ModeChangePayload, POSTHOG_NOTIFICATIONS, PostHogAPIClient, type PostHogNotificationPayload, type PostHogNotificationType, type ResumeConfig, type ResumeState, type RunStartedPayload, type SdkSessionPayload, type SessionResumePayload, type StatusPayload, type TaskCompletePayload, type TaskNotificationPayload, type ToolCallInfo, TreeSnapshot, TreeSnapshotEvent, type TreeSnapshotPayload, TreeTracker, type TreeTrackerConfig, type UserMessagePayload, conversationToPromptHistory, fetchMcpToolMetadata, isCommitOnRemote, isMcpToolReadOnly, resumeFromLog, validateForCloudHandoff };
|