@posthog/agent 2.1.124 → 2.1.131
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +9 -40
- package/dist/agent.js.map +1 -1
- package/dist/claude-cli/cli.js +2420 -2030
- package/dist/posthog-api.js +3 -3
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.js +11 -42
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +26 -57
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/adapters/claude/conversion/sdk-to-acp.ts +2 -0
- package/src/adapters/codex/spawn.ts +4 -3
- package/src/session-log-writer.ts +1 -36
- package/src/test/mocks/claude-sdk.ts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.131",
|
|
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": {
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
78
|
"@agentclientprotocol/sdk": "^0.14.0",
|
|
79
|
-
"@anthropic-ai/claude-agent-sdk": "0.2.
|
|
80
|
-
"@anthropic-ai/sdk": "^0.
|
|
79
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.63",
|
|
80
|
+
"@anthropic-ai/sdk": "^0.78.0",
|
|
81
81
|
"@hono/node-server": "^1.19.9",
|
|
82
82
|
"@opentelemetry/api-logs": "^0.208.0",
|
|
83
83
|
"@opentelemetry/exporter-logs-otlp-http": "^0.208.0",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ChildProcess, spawn } from "node:child_process";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import { delimiter, dirname } from "node:path";
|
|
3
4
|
import type { Readable, Writable } from "node:stream";
|
|
4
5
|
import type { ProcessSpawnedCallback } from "../../types.js";
|
|
5
6
|
import { Logger } from "../../utils/logger.js";
|
|
@@ -79,8 +80,8 @@ export function spawnCodexProcess(options: CodexProcessOptions): CodexProcess {
|
|
|
79
80
|
const { command, args } = findCodexBinary(options);
|
|
80
81
|
|
|
81
82
|
if (options.binaryPath && existsSync(options.binaryPath)) {
|
|
82
|
-
const binDir = options.binaryPath
|
|
83
|
-
env.PATH = `${binDir}
|
|
83
|
+
const binDir = dirname(options.binaryPath);
|
|
84
|
+
env.PATH = `${binDir}${delimiter}${env.PATH ?? ""}`;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
logger.info("Spawning codex-acp process", {
|
|
@@ -100,7 +101,7 @@ export function spawnCodexProcess(options: CodexProcessOptions): CodexProcess {
|
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
child.stderr?.on("data", (data: Buffer) => {
|
|
103
|
-
logger.
|
|
104
|
+
logger.error("codex-acp stderr:", data.toString());
|
|
104
105
|
});
|
|
105
106
|
|
|
106
107
|
child.on("error", (err) => {
|
|
@@ -37,7 +37,7 @@ export class SessionLogWriter {
|
|
|
37
37
|
private lastFlushAttemptTime: Map<string, number> = new Map();
|
|
38
38
|
private retryCounts: Map<string, number> = new Map();
|
|
39
39
|
private sessions: Map<string, SessionState> = new Map();
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
private logger: Logger;
|
|
42
42
|
private localCachePath?: string;
|
|
43
43
|
|
|
@@ -51,20 +51,6 @@ export class SessionLogWriter {
|
|
|
51
51
|
|
|
52
52
|
async flushAll(): Promise<void> {
|
|
53
53
|
const sessionIds = [...this.sessions.keys()];
|
|
54
|
-
const pendingCounts = sessionIds.map((id) => {
|
|
55
|
-
const session = this.sessions.get(id);
|
|
56
|
-
return {
|
|
57
|
-
taskId: session?.context.taskId,
|
|
58
|
-
runId: session?.context.runId,
|
|
59
|
-
pending: this.pendingEntries.get(id)?.length ?? 0,
|
|
60
|
-
messages: this.messageCounts.get(id) ?? 0,
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
this.logger.info("flushAll called", {
|
|
64
|
-
sessions: sessionIds.length,
|
|
65
|
-
pending: pendingCounts,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
54
|
const flushPromises: Promise<void>[] = [];
|
|
69
55
|
for (const sessionId of sessionIds) {
|
|
70
56
|
flushPromises.push(this.flush(sessionId));
|
|
@@ -115,16 +101,6 @@ export class SessionLogWriter {
|
|
|
115
101
|
return;
|
|
116
102
|
}
|
|
117
103
|
|
|
118
|
-
const count = (this.messageCounts.get(sessionId) ?? 0) + 1;
|
|
119
|
-
this.messageCounts.set(sessionId, count);
|
|
120
|
-
if (count % 10 === 1) {
|
|
121
|
-
this.logger.info("Messages received", {
|
|
122
|
-
count,
|
|
123
|
-
taskId: session.context.taskId,
|
|
124
|
-
runId: session.context.runId,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
104
|
try {
|
|
129
105
|
const message = JSON.parse(line);
|
|
130
106
|
const timestamp = new Date().toISOString();
|
|
@@ -186,12 +162,6 @@ export class SessionLogWriter {
|
|
|
186
162
|
|
|
187
163
|
const pending = this.pendingEntries.get(sessionId);
|
|
188
164
|
if (!this.posthogAPI || !pending?.length) {
|
|
189
|
-
this.logger.info("flush: nothing to persist", {
|
|
190
|
-
taskId: session.context.taskId,
|
|
191
|
-
runId: session.context.runId,
|
|
192
|
-
hasPosthogAPI: !!this.posthogAPI,
|
|
193
|
-
pendingCount: pending?.length ?? 0,
|
|
194
|
-
});
|
|
195
165
|
return;
|
|
196
166
|
}
|
|
197
167
|
|
|
@@ -211,11 +181,6 @@ export class SessionLogWriter {
|
|
|
211
181
|
pending,
|
|
212
182
|
);
|
|
213
183
|
this.retryCounts.set(sessionId, 0);
|
|
214
|
-
this.logger.info("Flushed session logs", {
|
|
215
|
-
taskId: session.context.taskId,
|
|
216
|
-
runId: session.context.runId,
|
|
217
|
-
entryCount: pending.length,
|
|
218
|
-
});
|
|
219
184
|
} catch (error) {
|
|
220
185
|
const retryCount = (this.retryCounts.get(sessionId) ?? 0) + 1;
|
|
221
186
|
this.retryCounts.set(sessionId, retryCount);
|
|
@@ -99,6 +99,7 @@ export function createMockQuery(
|
|
|
99
99
|
initializationResult: vi.fn().mockResolvedValue({}),
|
|
100
100
|
reconnectMcpServer: vi.fn().mockResolvedValue(undefined),
|
|
101
101
|
toggleMcpServer: vi.fn().mockResolvedValue(undefined),
|
|
102
|
+
supportedAgents: vi.fn().mockResolvedValue([]),
|
|
102
103
|
stopTask: vi.fn().mockResolvedValue(undefined),
|
|
103
104
|
[Symbol.asyncDispose]: vi.fn().mockResolvedValue(undefined),
|
|
104
105
|
_abortController: abortController,
|
|
@@ -176,6 +177,9 @@ export function createSuccessResult(
|
|
|
176
177
|
},
|
|
177
178
|
server_tool_use: { web_search_requests: 0, web_fetch_requests: 0 },
|
|
178
179
|
service_tier: "standard",
|
|
180
|
+
inference_geo: "us",
|
|
181
|
+
iterations: [],
|
|
182
|
+
speed: "standard",
|
|
179
183
|
},
|
|
180
184
|
modelUsage: {},
|
|
181
185
|
permission_denials: [],
|
|
@@ -209,6 +213,9 @@ export function createErrorResult(
|
|
|
209
213
|
},
|
|
210
214
|
server_tool_use: { web_search_requests: 0, web_fetch_requests: 0 },
|
|
211
215
|
service_tier: "standard",
|
|
216
|
+
inference_geo: "us",
|
|
217
|
+
iterations: [],
|
|
218
|
+
speed: "standard",
|
|
212
219
|
},
|
|
213
220
|
modelUsage: {},
|
|
214
221
|
permission_denials: [],
|