@posthog/agent 2.1.71 → 2.1.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/claude/conversion/tool-use-to-acp.d.ts +22 -2
- package/dist/adapters/claude/permissions/permission-options.d.ts +3 -1
- package/dist/adapters/claude/permissions/permission-options.js +5 -2
- package/dist/adapters/claude/permissions/permission-options.js.map +1 -1
- package/dist/adapters/claude/questions/utils.d.ts +1 -0
- package/dist/adapters/claude/tools.js.map +1 -1
- package/dist/agent.d.ts +30 -5
- package/dist/agent.js +22 -12
- package/dist/agent.js.map +1 -1
- package/dist/gateway-models.d.ts +1 -2
- package/dist/gateway-models.js +0 -5
- package/dist/gateway-models.js.map +1 -1
- package/dist/index.d.ts +1 -257
- package/dist/index.js +1 -10532
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.js +31 -17
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +31 -17
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -4
- package/src/acp-extensions.ts +0 -98
- package/src/adapters/acp-connection.ts +6 -5
- package/src/adapters/claude/claude-agent.ts +1 -1
- package/src/adapters/claude/conversion/sdk-to-acp.ts +6 -3
- package/src/adapters/claude/mcp/tool-metadata.ts +8 -5
- package/src/adapters/claude/permissions/permission-handlers.ts +2 -1
- package/src/adapters/claude/permissions/permission-options.ts +10 -1
- package/src/adapters/claude/session/options.ts +11 -2
- package/src/agent.ts +2 -2
- package/src/gateway-models.ts +0 -7
- package/src/index.ts +1 -79
- package/src/sagas/apply-snapshot-saga.ts +6 -3
- package/src/sagas/capture-tree-saga.test.ts +1 -1
- package/src/test/mocks/msw-handlers.ts +0 -3
- package/dist/agent-DK1apkaG.d.ts +0 -133
- package/dist/logger-DDBiMOOD.d.ts +0 -24
- package/src/adapters/claude/tool-meta.ts +0 -143
- package/src/test/assertions.ts +0 -114
- package/src/test/controllers/sse-controller.ts +0 -107
- package/src/test/fixtures/notifications.ts +0 -92
- package/src/test/setup.ts +0 -114
- package/src/test/wait.ts +0 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.83",
|
|
4
4
|
"repository": "https://github.com/PostHog/twig",
|
|
5
5
|
"description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
6
6
|
"exports": {
|
|
@@ -63,7 +63,6 @@
|
|
|
63
63
|
"node": ">=20.0.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@changesets/cli": "^2.27.8",
|
|
67
66
|
"@types/bun": "latest",
|
|
68
67
|
"@types/tar": "^6.1.13",
|
|
69
68
|
"minimatch": "^10.0.3",
|
|
@@ -88,8 +87,6 @@
|
|
|
88
87
|
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
89
88
|
"@types/jsonwebtoken": "^9.0.10",
|
|
90
89
|
"commander": "^14.0.2",
|
|
91
|
-
"diff": "^8.0.2",
|
|
92
|
-
"dotenv": "^17.2.3",
|
|
93
90
|
"hono": "^4.11.7",
|
|
94
91
|
"jsonwebtoken": "^9.0.2",
|
|
95
92
|
"tar": "^7.5.0",
|
package/src/acp-extensions.ts
CHANGED
|
@@ -62,101 +62,3 @@ export const POSTHOG_NOTIFICATIONS = {
|
|
|
62
62
|
/** Marks a boundary for log compaction */
|
|
63
63
|
COMPACT_BOUNDARY: "_posthog/compact_boundary",
|
|
64
64
|
} as const;
|
|
65
|
-
|
|
66
|
-
export type PostHogNotificationType =
|
|
67
|
-
(typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS];
|
|
68
|
-
|
|
69
|
-
// --- Payload types for each notification ---
|
|
70
|
-
|
|
71
|
-
export interface BranchCreatedPayload {
|
|
72
|
-
branch: string;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface RunStartedPayload {
|
|
76
|
-
sessionId: string;
|
|
77
|
-
runId: string;
|
|
78
|
-
taskId?: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface TaskCompletePayload {
|
|
82
|
-
sessionId: string;
|
|
83
|
-
taskId: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface ErrorNotificationPayload {
|
|
87
|
-
sessionId: string;
|
|
88
|
-
message: string;
|
|
89
|
-
error?: unknown;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface ConsoleNotificationPayload {
|
|
93
|
-
sessionId: string;
|
|
94
|
-
level: "debug" | "info" | "warn" | "error";
|
|
95
|
-
message: string;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface SdkSessionPayload {
|
|
99
|
-
taskRunId: string;
|
|
100
|
-
sessionId: string;
|
|
101
|
-
adapter: "claude" | "codex";
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface TreeSnapshotPayload {
|
|
105
|
-
treeHash: string;
|
|
106
|
-
baseCommit: string | null;
|
|
107
|
-
archiveUrl?: string;
|
|
108
|
-
changes: Array<{ path: string; status: "A" | "M" | "D" }>;
|
|
109
|
-
timestamp: string;
|
|
110
|
-
interrupted?: boolean;
|
|
111
|
-
device?: {
|
|
112
|
-
type: "local" | "cloud";
|
|
113
|
-
name?: string;
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface ModeChangePayload {
|
|
118
|
-
mode: "interactive" | "background";
|
|
119
|
-
previous_mode: "interactive" | "background";
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface SessionResumePayload {
|
|
123
|
-
sessionId: string;
|
|
124
|
-
fromSnapshot?: string;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export interface UserMessagePayload {
|
|
128
|
-
content: string;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface StatusPayload {
|
|
132
|
-
sessionId: string;
|
|
133
|
-
status: string;
|
|
134
|
-
message?: string;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface TaskNotificationPayload {
|
|
138
|
-
sessionId: string;
|
|
139
|
-
type: string;
|
|
140
|
-
message?: string;
|
|
141
|
-
data?: Record<string, unknown>;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export interface CompactBoundaryPayload {
|
|
145
|
-
sessionId: string;
|
|
146
|
-
timestamp: string;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export type PostHogNotificationPayload =
|
|
150
|
-
| BranchCreatedPayload
|
|
151
|
-
| RunStartedPayload
|
|
152
|
-
| TaskCompletePayload
|
|
153
|
-
| ErrorNotificationPayload
|
|
154
|
-
| ConsoleNotificationPayload
|
|
155
|
-
| SdkSessionPayload
|
|
156
|
-
| TreeSnapshotPayload
|
|
157
|
-
| ModeChangePayload
|
|
158
|
-
| SessionResumePayload
|
|
159
|
-
| UserMessagePayload
|
|
160
|
-
| StatusPayload
|
|
161
|
-
| TaskNotificationPayload
|
|
162
|
-
| CompactBoundaryPayload;
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { ClaudeAcpAgent } from "./claude/claude-agent.js";
|
|
14
14
|
import { type CodexProcessOptions, spawnCodexProcess } from "./codex/spawn.js";
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
type AgentAdapter = "claude" | "codex";
|
|
17
17
|
|
|
18
18
|
export type AcpConnectionConfig = {
|
|
19
19
|
adapter?: AgentAdapter;
|
|
@@ -170,16 +170,17 @@ function createClaudeConnection(config: AcpConnectionConfig): AcpConnection {
|
|
|
170
170
|
});
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
const taskRunId = config.taskRunId;
|
|
173
174
|
agentWritable = createTappedWritableStream(streams.agent.writable, {
|
|
174
175
|
onMessage: (line) => {
|
|
175
|
-
logWriter.appendRawLine(
|
|
176
|
+
logWriter.appendRawLine(taskRunId, line);
|
|
176
177
|
},
|
|
177
178
|
logger,
|
|
178
179
|
});
|
|
179
180
|
|
|
180
181
|
clientWritable = createTappedWritableStream(streams.client.writable, {
|
|
181
182
|
onMessage: (line) => {
|
|
182
|
-
logWriter.appendRawLine(
|
|
183
|
+
logWriter.appendRawLine(taskRunId, line);
|
|
183
184
|
},
|
|
184
185
|
logger,
|
|
185
186
|
});
|
|
@@ -425,8 +426,8 @@ function createCodexConnection(config: AcpConnectionConfig): AcpConnection {
|
|
|
425
426
|
|
|
426
427
|
const shouldTapLogs = config.taskRunId && logWriter;
|
|
427
428
|
|
|
428
|
-
if (shouldTapLogs) {
|
|
429
|
-
const taskRunId = config.taskRunId
|
|
429
|
+
if (shouldTapLogs && config.taskRunId) {
|
|
430
|
+
const taskRunId = config.taskRunId;
|
|
430
431
|
if (!logWriter.isRegistered(taskRunId)) {
|
|
431
432
|
logWriter.register(taskRunId, {
|
|
432
433
|
taskId: config.taskId ?? taskRunId,
|
|
@@ -181,7 +181,7 @@ export class ClaudeAcpAgent extends BaseAcpAgent {
|
|
|
181
181
|
|
|
182
182
|
if (meta?.taskRunId) {
|
|
183
183
|
await this.client.extNotification("_posthog/sdk_session", {
|
|
184
|
-
taskRunId: meta.taskRunId
|
|
184
|
+
taskRunId: meta.taskRunId,
|
|
185
185
|
sessionId,
|
|
186
186
|
adapter: "claude",
|
|
187
187
|
});
|
|
@@ -5,7 +5,10 @@ import type {
|
|
|
5
5
|
} from "@agentclientprotocol/sdk";
|
|
6
6
|
import { RequestError } from "@agentclientprotocol/sdk";
|
|
7
7
|
import type {
|
|
8
|
+
SDKAssistantMessage,
|
|
9
|
+
SDKMessage,
|
|
8
10
|
SDKPartialAssistantMessage,
|
|
11
|
+
SDKResultMessage,
|
|
9
12
|
SDKUserMessage,
|
|
10
13
|
} from "@anthropic-ai/claude-agent-sdk";
|
|
11
14
|
import type { ContentBlockParam } from "@anthropic-ai/sdk/resources";
|
|
@@ -357,7 +360,7 @@ function streamEventToAcpNotifications(
|
|
|
357
360
|
}
|
|
358
361
|
|
|
359
362
|
export async function handleSystemMessage(
|
|
360
|
-
message:
|
|
363
|
+
message: Extract<SDKMessage, { type: "system" }>,
|
|
361
364
|
context: MessageHandlerContext,
|
|
362
365
|
): Promise<void> {
|
|
363
366
|
const { sessionId, client, logger } = context;
|
|
@@ -409,7 +412,7 @@ export async function handleSystemMessage(
|
|
|
409
412
|
}
|
|
410
413
|
|
|
411
414
|
export function handleResultMessage(
|
|
412
|
-
message:
|
|
415
|
+
message: SDKResultMessage,
|
|
413
416
|
context: MessageHandlerContext,
|
|
414
417
|
): { shouldStop: boolean; stopReason?: string; error?: Error } {
|
|
415
418
|
const { session } = context;
|
|
@@ -556,7 +559,7 @@ function filterMessageContent(
|
|
|
556
559
|
}
|
|
557
560
|
|
|
558
561
|
export async function handleUserAssistantMessage(
|
|
559
|
-
message: SDKUserMessage |
|
|
562
|
+
message: SDKUserMessage | SDKAssistantMessage,
|
|
560
563
|
context: MessageHandlerContext,
|
|
561
564
|
): Promise<{ shouldStop?: boolean; error?: Error }> {
|
|
562
565
|
const { session, sessionId, client, toolUseCache, fileContentCache, logger } =
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
McpHttpServerConfig,
|
|
3
|
+
McpServerConfig,
|
|
4
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
2
5
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
6
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
7
|
import type { Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
@@ -16,17 +19,17 @@ function buildToolKey(serverName: string, toolName: string): string {
|
|
|
16
19
|
|
|
17
20
|
function isHttpMcpServer(
|
|
18
21
|
config: McpServerConfig,
|
|
19
|
-
): config is
|
|
20
|
-
return config.type === "http" && typeof
|
|
22
|
+
): config is McpHttpServerConfig {
|
|
23
|
+
return config.type === "http" && typeof config.url === "string";
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
async function fetchToolsFromHttpServer(
|
|
24
27
|
_serverName: string,
|
|
25
|
-
config:
|
|
28
|
+
config: McpHttpServerConfig,
|
|
26
29
|
): Promise<Tool[]> {
|
|
27
30
|
const transport = new StreamableHTTPClientTransport(new URL(config.url), {
|
|
28
31
|
requestInit: {
|
|
29
|
-
headers:
|
|
32
|
+
headers: config.headers ?? {},
|
|
30
33
|
},
|
|
31
34
|
});
|
|
32
35
|
|
|
@@ -192,7 +192,7 @@ async function applyPlanApproval(
|
|
|
192
192
|
async function handleEnterPlanModeTool(
|
|
193
193
|
context: ToolHandlerContext,
|
|
194
194
|
): Promise<ToolPermissionResult> {
|
|
195
|
-
const { session, toolInput
|
|
195
|
+
const { session, toolInput } = context;
|
|
196
196
|
|
|
197
197
|
session.permissionMode = "plan";
|
|
198
198
|
await session.query.setPermissionMode("plan");
|
|
@@ -325,6 +325,7 @@ async function handleDefaultPermissionFlow(
|
|
|
325
325
|
toolName,
|
|
326
326
|
toolInput as Record<string, unknown>,
|
|
327
327
|
session?.cwd,
|
|
328
|
+
suggestions,
|
|
328
329
|
);
|
|
329
330
|
|
|
330
331
|
const response = await client.requestPermission({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PermissionUpdate } from "@anthropic-ai/claude-agent-sdk";
|
|
1
2
|
import { BASH_TOOLS, READ_TOOLS, SEARCH_TOOLS, WRITE_TOOLS } from "../tools.js";
|
|
2
3
|
|
|
3
4
|
export interface PermissionOption {
|
|
@@ -24,13 +25,21 @@ export function buildPermissionOptions(
|
|
|
24
25
|
toolName: string,
|
|
25
26
|
toolInput: Record<string, unknown>,
|
|
26
27
|
cwd?: string,
|
|
28
|
+
suggestions?: PermissionUpdate[],
|
|
27
29
|
): PermissionOption[] {
|
|
28
30
|
if (BASH_TOOLS.has(toolName)) {
|
|
31
|
+
const rawRuleContent = suggestions
|
|
32
|
+
?.flatMap((s) => ("rules" in s ? s.rules : []))
|
|
33
|
+
.find((r) => r.toolName === "Bash" && r.ruleContent)?.ruleContent;
|
|
34
|
+
const ruleContent = rawRuleContent?.replace(/:?\*$/, "");
|
|
35
|
+
|
|
29
36
|
const command = toolInput?.command as string | undefined;
|
|
30
37
|
const cmdName = command?.split(/\s+/)[0] ?? "this command";
|
|
31
38
|
const cwdLabel = cwd ? ` in ${cwd}` : "";
|
|
39
|
+
const label = ruleContent ?? `\`${cmdName}\` commands`;
|
|
40
|
+
|
|
32
41
|
return permissionOptions(
|
|
33
|
-
`Yes, and don't ask again for
|
|
42
|
+
`Yes, and don't ask again for ${label}${cwdLabel}`,
|
|
34
43
|
);
|
|
35
44
|
}
|
|
36
45
|
|
|
@@ -152,9 +152,15 @@ function buildSpawnWrapper(
|
|
|
152
152
|
});
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
if (!child.stdin || !child.stdout) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Failed to get stdio streams for spawned process (pid=${child.pid})`,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
155
161
|
return {
|
|
156
|
-
stdin: child.stdin
|
|
157
|
-
stdout: child.stdout
|
|
162
|
+
stdin: child.stdin,
|
|
163
|
+
stdout: child.stdout,
|
|
158
164
|
get killed() {
|
|
159
165
|
return child.killed;
|
|
160
166
|
},
|
|
@@ -164,12 +170,15 @@ function buildSpawnWrapper(
|
|
|
164
170
|
kill(signal: NodeJS.Signals) {
|
|
165
171
|
return child.kill(signal);
|
|
166
172
|
},
|
|
173
|
+
// biome-ignore lint/suspicious/noExplicitAny: ChildProcess event listener types require any[]
|
|
167
174
|
on(event: "exit" | "error", listener: (...args: any[]) => void) {
|
|
168
175
|
child.on(event, listener);
|
|
169
176
|
},
|
|
177
|
+
// biome-ignore lint/suspicious/noExplicitAny: ChildProcess event listener types require any[]
|
|
170
178
|
once(event: "exit" | "error", listener: (...args: any[]) => void) {
|
|
171
179
|
child.once(event, listener);
|
|
172
180
|
},
|
|
181
|
+
// biome-ignore lint/suspicious/noExplicitAny: ChildProcess event listener types require any[]
|
|
173
182
|
off(event: "exit" | "error", listener: (...args: any[]) => void) {
|
|
174
183
|
child.off(event, listener);
|
|
175
184
|
},
|
package/src/agent.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
DEFAULT_GATEWAY_MODEL,
|
|
8
8
|
fetchArrayModels,
|
|
9
9
|
} from "./gateway-models.js";
|
|
10
|
-
import { PostHogAPIClient } from "./posthog-api.js";
|
|
10
|
+
import { PostHogAPIClient, type TaskRunUpdate } from "./posthog-api.js";
|
|
11
11
|
import { SessionLogWriter } from "./session-log-writer.js";
|
|
12
12
|
import type { AgentConfig, TaskExecutionOptions } from "./types.js";
|
|
13
13
|
import { Logger } from "./utils/logger.js";
|
|
@@ -142,7 +142,7 @@ export class Agent {
|
|
|
142
142
|
throw error;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
const updates:
|
|
145
|
+
const updates: TaskRunUpdate = {
|
|
146
146
|
output: { pr_url: prUrl },
|
|
147
147
|
};
|
|
148
148
|
if (branchName) {
|
package/src/gateway-models.ts
CHANGED
|
@@ -79,13 +79,6 @@ export function isAnthropicModel(model: GatewayModel): boolean {
|
|
|
79
79
|
return model.id.startsWith("claude-") || model.id.startsWith("anthropic/");
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export async function fetchArrayModelIds(
|
|
83
|
-
options?: FetchGatewayModelsOptions,
|
|
84
|
-
): Promise<string[]> {
|
|
85
|
-
const models = await fetchArrayModels(options);
|
|
86
|
-
return models.map((model) => model.id);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
82
|
export interface ArrayModelInfo {
|
|
90
83
|
id: string;
|
|
91
84
|
owned_by?: string;
|
package/src/index.ts
CHANGED
|
@@ -1,79 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
BranchCreatedPayload,
|
|
3
|
-
CompactBoundaryPayload,
|
|
4
|
-
ConsoleNotificationPayload,
|
|
5
|
-
ErrorNotificationPayload,
|
|
6
|
-
ModeChangePayload,
|
|
7
|
-
PostHogNotificationPayload,
|
|
8
|
-
PostHogNotificationType,
|
|
9
|
-
RunStartedPayload,
|
|
10
|
-
SdkSessionPayload,
|
|
11
|
-
SessionResumePayload,
|
|
12
|
-
StatusPayload,
|
|
13
|
-
TaskCompletePayload,
|
|
14
|
-
TaskNotificationPayload,
|
|
15
|
-
TreeSnapshotPayload,
|
|
16
|
-
UserMessagePayload,
|
|
17
|
-
} from "./acp-extensions.js";
|
|
18
|
-
export { POSTHOG_NOTIFICATIONS } from "./acp-extensions.js";
|
|
19
|
-
export type {
|
|
20
|
-
AcpConnection,
|
|
21
|
-
AcpConnectionConfig,
|
|
22
|
-
AgentAdapter,
|
|
23
|
-
InProcessAcpConnection,
|
|
24
|
-
} from "./adapters/acp-connection.js";
|
|
25
|
-
export { createAcpConnection } from "./adapters/acp-connection.js";
|
|
26
|
-
export {
|
|
27
|
-
fetchMcpToolMetadata,
|
|
28
|
-
isMcpToolReadOnly,
|
|
29
|
-
} from "./adapters/claude/mcp/tool-metadata.js";
|
|
30
|
-
export type { CodexProcessOptions } from "./adapters/codex/spawn.js";
|
|
31
|
-
export { Agent } from "./agent.js";
|
|
32
|
-
export {
|
|
33
|
-
type ArrayModelInfo,
|
|
34
|
-
BLOCKED_MODELS,
|
|
35
|
-
DEFAULT_GATEWAY_MODEL,
|
|
36
|
-
type FetchGatewayModelsOptions,
|
|
37
|
-
fetchArrayModels,
|
|
38
|
-
fetchGatewayModels,
|
|
39
|
-
formatGatewayModelName,
|
|
40
|
-
type GatewayModel,
|
|
41
|
-
getProviderName,
|
|
42
|
-
isAnthropicModel,
|
|
43
|
-
} from "./gateway-models.js";
|
|
44
|
-
export type { OtelLogConfig, SessionContext } from "./otel-log-writer.js";
|
|
45
|
-
export { OtelLogWriter } from "./otel-log-writer.js";
|
|
46
|
-
export { PostHogAPIClient } from "./posthog-api.js";
|
|
47
|
-
export type {
|
|
48
|
-
ConversationTurn,
|
|
49
|
-
ResumeConfig,
|
|
50
|
-
ResumeState,
|
|
51
|
-
ToolCallInfo,
|
|
52
|
-
} from "./resume.js";
|
|
53
|
-
export { conversationToPromptHistory, resumeFromLog } from "./resume.js";
|
|
54
|
-
export type { SessionLogWriterOptions } from "./session-log-writer.js";
|
|
55
|
-
export { SessionLogWriter } from "./session-log-writer.js";
|
|
56
|
-
export type { TreeSnapshot, TreeTrackerConfig } from "./tree-tracker.js";
|
|
57
|
-
export {
|
|
58
|
-
isCommitOnRemote,
|
|
59
|
-
TreeTracker,
|
|
60
|
-
validateForCloudHandoff,
|
|
61
|
-
} from "./tree-tracker.js";
|
|
62
|
-
export type {
|
|
63
|
-
AgentConfig,
|
|
64
|
-
AgentMode,
|
|
65
|
-
DeviceInfo,
|
|
66
|
-
FileChange,
|
|
67
|
-
FileStatus,
|
|
68
|
-
LogLevel,
|
|
69
|
-
OnLogCallback,
|
|
70
|
-
OtelTransportConfig,
|
|
71
|
-
StoredEntry,
|
|
72
|
-
StoredNotification,
|
|
73
|
-
Task,
|
|
74
|
-
TaskRun,
|
|
75
|
-
TreeSnapshotEvent,
|
|
76
|
-
} from "./types.js";
|
|
77
|
-
export { getLlmGatewayUrl } from "./utils/gateway.js";
|
|
78
|
-
export type { LoggerConfig } from "./utils/logger.js";
|
|
79
|
-
export { Logger } from "./utils/logger.js";
|
|
1
|
+
export { isMcpToolReadOnly } from "./adapters/claude/mcp/tool-metadata.js";
|
|
@@ -33,27 +33,30 @@ export class ApplySnapshotSaga extends Saga<
|
|
|
33
33
|
throw new Error("Cannot apply snapshot: no archive URL");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
const archiveUrl = snapshot.archiveUrl;
|
|
37
|
+
|
|
36
38
|
await this.step({
|
|
37
39
|
name: "create_tmp_dir",
|
|
38
40
|
execute: () => mkdir(tmpDir, { recursive: true }),
|
|
39
41
|
rollback: async () => {},
|
|
40
42
|
});
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
const archivePath = join(tmpDir, `${snapshot.treeHash}.tar.gz`);
|
|
45
|
+
this.archivePath = archivePath;
|
|
43
46
|
await this.step({
|
|
44
47
|
name: "download_archive",
|
|
45
48
|
execute: async () => {
|
|
46
49
|
const arrayBuffer = await apiClient.downloadArtifact(
|
|
47
50
|
taskId,
|
|
48
51
|
runId,
|
|
49
|
-
|
|
52
|
+
archiveUrl,
|
|
50
53
|
);
|
|
51
54
|
if (!arrayBuffer) {
|
|
52
55
|
throw new Error("Failed to download archive");
|
|
53
56
|
}
|
|
54
57
|
const base64Content = Buffer.from(arrayBuffer).toString("utf-8");
|
|
55
58
|
const binaryContent = Buffer.from(base64Content, "base64");
|
|
56
|
-
await writeFile(
|
|
59
|
+
await writeFile(archivePath, binaryContent);
|
|
57
60
|
},
|
|
58
61
|
rollback: async () => {
|
|
59
62
|
if (this.archivePath) {
|
|
@@ -583,7 +583,7 @@ describe("CaptureTreeSaga", () => {
|
|
|
583
583
|
});
|
|
584
584
|
|
|
585
585
|
it("handles symlinks", async () => {
|
|
586
|
-
const { symlink
|
|
586
|
+
const { symlink } = await import("node:fs/promises");
|
|
587
587
|
|
|
588
588
|
await repo.writeFile("target.txt", "symlink target content");
|
|
589
589
|
await symlink("target.txt", join(repo.path, "link.txt"));
|
package/dist/agent-DK1apkaG.d.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { AgentSideConnection } from '@agentclientprotocol/sdk';
|
|
2
|
-
import { StoredNotification, ProcessSpawnedCallback, AgentConfig, TaskExecutionOptions } from './types.js';
|
|
3
|
-
import { L as Logger } from './logger-DDBiMOOD.js';
|
|
4
|
-
import { PostHogAPIClient } from './posthog-api.js';
|
|
5
|
-
|
|
6
|
-
interface OtelLogConfig {
|
|
7
|
-
/** PostHog ingest host, e.g., "https://us.i.posthog.com" */
|
|
8
|
-
posthogHost: string;
|
|
9
|
-
/** Project API key, e.g., "phc_xxx" */
|
|
10
|
-
apiKey: string;
|
|
11
|
-
/** Batch flush interval in ms (default: 500) */
|
|
12
|
-
flushIntervalMs?: number;
|
|
13
|
-
/** Override the logs endpoint path (default: /i/v1/agent-logs) */
|
|
14
|
-
logsPath?: string;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Session context for resource attributes.
|
|
18
|
-
* These are set once per OTEL logger instance and indexed via resource_fingerprint
|
|
19
|
-
*/
|
|
20
|
-
interface SessionContext {
|
|
21
|
-
/** Parent task grouping - all runs for a task share this */
|
|
22
|
-
taskId: string;
|
|
23
|
-
/** Primary conversation identifier - all events in a run share this */
|
|
24
|
-
runId: string;
|
|
25
|
-
/** Deployment environment - "local" for desktop, "cloud" for cloud sandbox */
|
|
26
|
-
deviceType?: "local" | "cloud";
|
|
27
|
-
}
|
|
28
|
-
declare class OtelLogWriter {
|
|
29
|
-
private loggerProvider;
|
|
30
|
-
private logger;
|
|
31
|
-
constructor(config: OtelLogConfig, sessionContext: SessionContext, _debugLogger?: Logger);
|
|
32
|
-
/**
|
|
33
|
-
* Emit an agent event to PostHog Logs via OTEL.
|
|
34
|
-
*/
|
|
35
|
-
emit(entry: {
|
|
36
|
-
notification: StoredNotification;
|
|
37
|
-
}): void;
|
|
38
|
-
flush(): Promise<void>;
|
|
39
|
-
shutdown(): Promise<void>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface SessionLogWriterOptions {
|
|
43
|
-
/** PostHog API client for log persistence */
|
|
44
|
-
posthogAPI?: PostHogAPIClient;
|
|
45
|
-
/** Logger instance */
|
|
46
|
-
logger?: Logger;
|
|
47
|
-
/** Local cache path for instant log loading (e.g., ~/.twig) */
|
|
48
|
-
localCachePath?: string;
|
|
49
|
-
}
|
|
50
|
-
declare class SessionLogWriter {
|
|
51
|
-
private static readonly FLUSH_DEBOUNCE_MS;
|
|
52
|
-
private static readonly FLUSH_MAX_INTERVAL_MS;
|
|
53
|
-
private static readonly MAX_FLUSH_RETRIES;
|
|
54
|
-
private static readonly MAX_RETRY_DELAY_MS;
|
|
55
|
-
private posthogAPI?;
|
|
56
|
-
private pendingEntries;
|
|
57
|
-
private flushTimeouts;
|
|
58
|
-
private lastFlushAttemptTime;
|
|
59
|
-
private retryCounts;
|
|
60
|
-
private sessions;
|
|
61
|
-
private messageCounts;
|
|
62
|
-
private logger;
|
|
63
|
-
private localCachePath?;
|
|
64
|
-
constructor(options?: SessionLogWriterOptions);
|
|
65
|
-
flushAll(): Promise<void>;
|
|
66
|
-
register(sessionId: string, context: SessionContext): void;
|
|
67
|
-
isRegistered(sessionId: string): boolean;
|
|
68
|
-
appendRawLine(sessionId: string, line: string): void;
|
|
69
|
-
flush(sessionId: string): Promise<void>;
|
|
70
|
-
private isAgentMessageChunk;
|
|
71
|
-
private extractChunkText;
|
|
72
|
-
private emitCoalescedMessage;
|
|
73
|
-
private scheduleFlush;
|
|
74
|
-
private writeToLocalCache;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
type StreamPair = {
|
|
78
|
-
readable: globalThis.ReadableStream<Uint8Array>;
|
|
79
|
-
writable: globalThis.WritableStream<Uint8Array>;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
interface CodexProcessOptions {
|
|
83
|
-
cwd?: string;
|
|
84
|
-
apiBaseUrl?: string;
|
|
85
|
-
apiKey?: string;
|
|
86
|
-
model?: string;
|
|
87
|
-
binaryPath?: string;
|
|
88
|
-
logger?: Logger;
|
|
89
|
-
processCallbacks?: ProcessSpawnedCallback;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
type AgentAdapter = "claude" | "codex";
|
|
93
|
-
type AcpConnectionConfig = {
|
|
94
|
-
adapter?: AgentAdapter;
|
|
95
|
-
logWriter?: SessionLogWriter;
|
|
96
|
-
taskRunId?: string;
|
|
97
|
-
taskId?: string;
|
|
98
|
-
/** Deployment environment - "local" for desktop, "cloud" for cloud sandbox */
|
|
99
|
-
deviceType?: "local" | "cloud";
|
|
100
|
-
logger?: Logger;
|
|
101
|
-
processCallbacks?: ProcessSpawnedCallback;
|
|
102
|
-
codexOptions?: CodexProcessOptions;
|
|
103
|
-
allowedModelIds?: Set<string>;
|
|
104
|
-
};
|
|
105
|
-
type AcpConnection = {
|
|
106
|
-
agentConnection?: AgentSideConnection;
|
|
107
|
-
clientStreams: StreamPair;
|
|
108
|
-
cleanup: () => Promise<void>;
|
|
109
|
-
};
|
|
110
|
-
type InProcessAcpConnection = AcpConnection;
|
|
111
|
-
/**
|
|
112
|
-
* Creates an ACP connection with the specified agent framework.
|
|
113
|
-
*
|
|
114
|
-
* @param config - Configuration including framework selection
|
|
115
|
-
* @returns Connection with agent and client streams
|
|
116
|
-
*/
|
|
117
|
-
declare function createAcpConnection(config?: AcpConnectionConfig): AcpConnection;
|
|
118
|
-
|
|
119
|
-
declare class Agent {
|
|
120
|
-
private posthogAPI?;
|
|
121
|
-
private logger;
|
|
122
|
-
private acpConnection?;
|
|
123
|
-
private taskRunId?;
|
|
124
|
-
private sessionLogWriter?;
|
|
125
|
-
constructor(config: AgentConfig);
|
|
126
|
-
private _configureLlmGateway;
|
|
127
|
-
run(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<InProcessAcpConnection>;
|
|
128
|
-
attachPullRequestToTask(taskId: string, prUrl: string, branchName?: string): Promise<void>;
|
|
129
|
-
flushAllLogs(): Promise<void>;
|
|
130
|
-
cleanup(): Promise<void>;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export { type AcpConnection as A, type CodexProcessOptions as C, type InProcessAcpConnection as I, type OtelLogConfig as O, type SessionContext as S, type AcpConnectionConfig as a, Agent as b, type AgentAdapter as c, OtelLogWriter as d, SessionLogWriter as e, type SessionLogWriterOptions as f, createAcpConnection as g };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { OnLogCallback } from './types.js';
|
|
2
|
-
|
|
3
|
-
interface LoggerConfig {
|
|
4
|
-
debug?: boolean;
|
|
5
|
-
prefix?: string;
|
|
6
|
-
scope?: string;
|
|
7
|
-
onLog?: OnLogCallback;
|
|
8
|
-
}
|
|
9
|
-
declare class Logger {
|
|
10
|
-
private debugEnabled;
|
|
11
|
-
private prefix;
|
|
12
|
-
private scope;
|
|
13
|
-
private onLog?;
|
|
14
|
-
constructor(config?: LoggerConfig);
|
|
15
|
-
private formatMessage;
|
|
16
|
-
private emitLog;
|
|
17
|
-
error(message: string, error?: Error | unknown): void;
|
|
18
|
-
warn(message: string, data?: unknown): void;
|
|
19
|
-
info(message: string, data?: unknown): void;
|
|
20
|
-
debug(message: string, data?: unknown): void;
|
|
21
|
-
child(childPrefix: string): Logger;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { Logger as L, type LoggerConfig as a };
|