@posthog/agent 1.29.0 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +19 -5
- package/dist/index.js +47 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/acp-extensions.ts +14 -1
- package/src/adapters/claude/claude.ts +7 -3
- package/src/agent.ts +20 -8
- package/src/git-manager.ts +2 -20
- package/src/posthog-api.ts +4 -4
- package/src/prompt-builder.ts +5 -3
- package/src/template-manager.ts +2 -6
- package/src/types.ts +2 -2
- package/src/utils/gateway.ts +15 -0
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ declare const POSTHOG_NOTIFICATIONS: {
|
|
|
37
37
|
readonly CONSOLE: "_posthog/console";
|
|
38
38
|
/** SDK session ID notification (for resumption) */
|
|
39
39
|
readonly SDK_SESSION: "_posthog/sdk_session";
|
|
40
|
+
/** Sandbox execution output (stdout/stderr from Modal or Docker) */
|
|
41
|
+
readonly SANDBOX_OUTPUT: "_posthog/sandbox_output";
|
|
40
42
|
};
|
|
41
43
|
type PostHogNotificationType = (typeof POSTHOG_NOTIFICATIONS)[keyof typeof POSTHOG_NOTIFICATIONS];
|
|
42
44
|
interface ArtifactNotificationPayload {
|
|
@@ -92,7 +94,16 @@ interface SdkSessionPayload {
|
|
|
92
94
|
sessionId: string;
|
|
93
95
|
sdkSessionId: string;
|
|
94
96
|
}
|
|
95
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Sandbox execution output
|
|
99
|
+
*/
|
|
100
|
+
interface SandboxOutputPayload {
|
|
101
|
+
sessionId: string;
|
|
102
|
+
stdout: string;
|
|
103
|
+
stderr: string;
|
|
104
|
+
exitCode: number;
|
|
105
|
+
}
|
|
106
|
+
type PostHogNotificationPayload = ArtifactNotificationPayload | PhaseNotificationPayload | BranchCreatedPayload | PrCreatedPayload | RunStartedPayload | TaskCompletePayload | ErrorNotificationPayload | ConsoleNotificationPayload | SdkSessionPayload | SandboxOutputPayload;
|
|
96
107
|
|
|
97
108
|
/**
|
|
98
109
|
* Stored custom notification following ACP extensibility model.
|
|
@@ -217,7 +228,7 @@ type OnLogCallback = (level: LogLevel$1, scope: string, message: string, data?:
|
|
|
217
228
|
interface AgentConfig {
|
|
218
229
|
workingDirectory?: string;
|
|
219
230
|
posthogApiUrl?: string;
|
|
220
|
-
|
|
231
|
+
getPosthogApiKey?: () => string;
|
|
221
232
|
posthogProjectId?: number;
|
|
222
233
|
posthogMcpUrl?: string;
|
|
223
234
|
mcpServers?: Record<string, McpServerConfig>;
|
|
@@ -227,7 +238,7 @@ interface AgentConfig {
|
|
|
227
238
|
}
|
|
228
239
|
interface PostHogAPIConfig {
|
|
229
240
|
apiUrl: string;
|
|
230
|
-
|
|
241
|
+
getApiKey: () => string;
|
|
231
242
|
projectId: number;
|
|
232
243
|
}
|
|
233
244
|
type ResourceType = "error" | "experiment" | "insight" | "feature_flag" | "generic";
|
|
@@ -454,7 +465,7 @@ declare class Agent {
|
|
|
454
465
|
*/
|
|
455
466
|
setDebug(enabled: boolean): void;
|
|
456
467
|
/**
|
|
457
|
-
* Configure LLM gateway environment variables for Claude Code CLI
|
|
468
|
+
* Configure LLM gateway environment variables for Claude Code CLI.
|
|
458
469
|
*/
|
|
459
470
|
private _configureLlmGateway;
|
|
460
471
|
private getOrCreateConnection;
|
|
@@ -482,6 +493,7 @@ declare class Agent {
|
|
|
482
493
|
getTaskExecutionStatus(taskId: string): string | null;
|
|
483
494
|
private prepareTaskBranch;
|
|
484
495
|
private ensureOpenAIGatewayEnv;
|
|
496
|
+
private ensureGeminiGatewayEnv;
|
|
485
497
|
runTaskCloud(taskId: string, taskRunId: string, options?: TaskExecutionOptions): Promise<void>;
|
|
486
498
|
private ensurePullRequest;
|
|
487
499
|
}
|
|
@@ -1234,6 +1246,8 @@ declare class ToolRegistry {
|
|
|
1234
1246
|
getByCategory(category: string): Tool[];
|
|
1235
1247
|
}
|
|
1236
1248
|
|
|
1249
|
+
declare function getLlmGatewayUrl(posthogHost: string): string;
|
|
1250
|
+
|
|
1237
1251
|
interface WorktreeConfig {
|
|
1238
1252
|
mainRepoPath: string;
|
|
1239
1253
|
worktreeBasePath?: string;
|
|
@@ -1273,4 +1287,4 @@ declare class WorktreeManager {
|
|
|
1273
1287
|
}>;
|
|
1274
1288
|
}
|
|
1275
1289
|
|
|
1276
|
-
export { type AcpConnectionConfig, Agent, type AgentConfig, type AgentEvent, type ArtifactNotificationPayload, type BashOutputTool, type BashTool, type BranchCreatedPayload, type ConsoleEvent, type ConsoleNotificationPayload, type EditTool, type ErrorEvent, type ErrorNotificationPayload, type ExecutionResult, type ExitPlanModeTool, type GlobTool, type GrepTool, type InProcessAcpConnection, type KillShellTool, type KnownTool, LogLevel, type LogLevel$1 as LogLevelType, Logger, type LoggerConfig, type McpServerConfig, type NotebookEditTool, type OnLogCallback, POSTHOG_NOTIFICATIONS, PermissionMode, type PhaseNotificationPayload, type PostHogNotificationPayload, type PostHogNotificationType, type PrCreatedPayload, type ReadTool, type ResearchEvaluation, type RunStartedPayload, type SdkSessionPayload, type SessionPersistenceConfig, SessionStore, type SlashCommandTool, type StatusEvent, type StoredEntry, type StoredNotification, type SupportingFile, type Task, type TaskCompletePayload, type TaskRun, type TaskTool, type TodoItem, type TodoList, TodoManager, type TodoWriteTool, type TokenEvent, type Tool, type ToolCategory, ToolRegistry, type WebFetchTool, type WebSearchTool, type WorktreeConfig, type WorktreeInfo, WorktreeManager, type WriteTool, createAcpConnection, parseAgentEvent, parseAgentEvents };
|
|
1290
|
+
export { type AcpConnectionConfig, Agent, type AgentConfig, type AgentEvent, type ArtifactNotificationPayload, type BashOutputTool, type BashTool, type BranchCreatedPayload, type ConsoleEvent, type ConsoleNotificationPayload, type EditTool, type ErrorEvent, type ErrorNotificationPayload, type ExecutionResult, type ExitPlanModeTool, type GlobTool, type GrepTool, type InProcessAcpConnection, type KillShellTool, type KnownTool, LogLevel, type LogLevel$1 as LogLevelType, Logger, type LoggerConfig, type McpServerConfig, type NotebookEditTool, type OnLogCallback, POSTHOG_NOTIFICATIONS, PermissionMode, type PhaseNotificationPayload, type PostHogNotificationPayload, type PostHogNotificationType, type PrCreatedPayload, type ReadTool, type ResearchEvaluation, type RunStartedPayload, type SdkSessionPayload, type SessionPersistenceConfig, SessionStore, type SlashCommandTool, type StatusEvent, type StoredEntry, type StoredNotification, type SupportingFile, type Task, type TaskCompletePayload, type TaskRun, type TaskTool, type TodoItem, type TodoList, TodoManager, type TodoWriteTool, type TokenEvent, type Tool, type ToolCategory, ToolRegistry, type WebFetchTool, type WebSearchTool, type WorktreeConfig, type WorktreeInfo, WorktreeManager, type WriteTool, createAcpConnection, getLlmGatewayUrl, parseAgentEvent, parseAgentEvents };
|
package/dist/index.js
CHANGED
|
@@ -65,7 +65,9 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
65
65
|
/** Console/log output */
|
|
66
66
|
CONSOLE: "_posthog/console",
|
|
67
67
|
/** SDK session ID notification (for resumption) */
|
|
68
|
-
SDK_SESSION: "_posthog/sdk_session"
|
|
68
|
+
SDK_SESSION: "_posthog/sdk_session",
|
|
69
|
+
/** Sandbox execution output (stdout/stderr from Modal or Docker) */
|
|
70
|
+
SANDBOX_OUTPUT: "_posthog/sandbox_output"
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
// src/adapters/claude/claude.ts
|
|
@@ -196,7 +198,7 @@ function createTappedWritableStream(underlying, options) {
|
|
|
196
198
|
// package.json
|
|
197
199
|
var package_default = {
|
|
198
200
|
name: "@posthog/agent",
|
|
199
|
-
version: "1.
|
|
201
|
+
version: "1.30.0",
|
|
200
202
|
repository: "https://github.com/PostHog/array",
|
|
201
203
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
202
204
|
main: "./dist/index.js",
|
|
@@ -1913,8 +1915,11 @@ var ClaudeAcpAgent = class {
|
|
|
1913
1915
|
throw RequestError.authRequired();
|
|
1914
1916
|
}
|
|
1915
1917
|
const content = message.message.content;
|
|
1918
|
+
const contentToProcess = Array.isArray(content) ? content.filter(
|
|
1919
|
+
(block) => block.type !== "text" && block.type !== "thinking"
|
|
1920
|
+
) : content;
|
|
1916
1921
|
for (const notification of toAcpNotifications(
|
|
1917
|
-
|
|
1922
|
+
contentToProcess,
|
|
1918
1923
|
message.message.role,
|
|
1919
1924
|
params.sessionId,
|
|
1920
1925
|
this.toolUseCache,
|
|
@@ -2877,13 +2882,9 @@ import { promisify } from "util";
|
|
|
2877
2882
|
var execAsync = promisify(exec);
|
|
2878
2883
|
var GitManager = class {
|
|
2879
2884
|
repositoryPath;
|
|
2880
|
-
authorName;
|
|
2881
|
-
authorEmail;
|
|
2882
2885
|
logger;
|
|
2883
2886
|
constructor(config) {
|
|
2884
2887
|
this.repositoryPath = config.repositoryPath;
|
|
2885
|
-
this.authorName = config.authorName;
|
|
2886
|
-
this.authorEmail = config.authorEmail;
|
|
2887
2888
|
this.logger = config.logger || new Logger({ debug: false, prefix: "[GitManager]" });
|
|
2888
2889
|
}
|
|
2889
2890
|
escapeShellArg(str) {
|
|
@@ -3057,11 +3058,6 @@ ${error}`);
|
|
|
3057
3058
|
if (options?.allowEmpty) {
|
|
3058
3059
|
command += " --allow-empty";
|
|
3059
3060
|
}
|
|
3060
|
-
const authorName = options?.authorName || this.authorName;
|
|
3061
|
-
const authorEmail = options?.authorEmail || this.authorEmail;
|
|
3062
|
-
if (authorName && authorEmail) {
|
|
3063
|
-
command += ` --author="${authorName} <${authorEmail}>"`;
|
|
3064
|
-
}
|
|
3065
3061
|
return command;
|
|
3066
3062
|
}
|
|
3067
3063
|
async getRemoteUrl() {
|
|
@@ -3181,7 +3177,6 @@ ${error}`);
|
|
|
3181
3177
|
const message = `\u{1F4CB} Add plan for task: ${taskTitle}
|
|
3182
3178
|
|
|
3183
3179
|
Task ID: ${taskId}
|
|
3184
|
-
Generated by PostHog Agent
|
|
3185
3180
|
|
|
3186
3181
|
This commit contains the implementation plan and supporting documentation
|
|
3187
3182
|
for the task. Review the plan before proceeding with implementation.`;
|
|
@@ -3198,8 +3193,7 @@ for the task. Review the plan before proceeding with implementation.`;
|
|
|
3198
3193
|
}
|
|
3199
3194
|
let message = `\u2728 Implement task: ${taskTitle}
|
|
3200
3195
|
|
|
3201
|
-
Task ID: ${taskId}
|
|
3202
|
-
Generated by PostHog Agent`;
|
|
3196
|
+
Task ID: ${taskId}`;
|
|
3203
3197
|
if (planSummary) {
|
|
3204
3198
|
message += `
|
|
3205
3199
|
|
|
@@ -3303,6 +3297,18 @@ This commit implements the changes described in the task plan.`;
|
|
|
3303
3297
|
}
|
|
3304
3298
|
};
|
|
3305
3299
|
|
|
3300
|
+
// src/utils/gateway.ts
|
|
3301
|
+
function getLlmGatewayUrl(posthogHost) {
|
|
3302
|
+
const url = new URL(posthogHost);
|
|
3303
|
+
const hostname = url.hostname;
|
|
3304
|
+
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
3305
|
+
return `${url.protocol}//localhost:3308`;
|
|
3306
|
+
}
|
|
3307
|
+
const regionMatch = hostname.match(/^(us|eu)\.posthog\.com$/);
|
|
3308
|
+
const region = regionMatch ? regionMatch[1] : "us";
|
|
3309
|
+
return `https://gateway.${region}.posthog.com`;
|
|
3310
|
+
}
|
|
3311
|
+
|
|
3306
3312
|
// src/posthog-api.ts
|
|
3307
3313
|
var PostHogAPIClient = class {
|
|
3308
3314
|
config;
|
|
@@ -3315,7 +3321,7 @@ var PostHogAPIClient = class {
|
|
|
3315
3321
|
}
|
|
3316
3322
|
get headers() {
|
|
3317
3323
|
return {
|
|
3318
|
-
Authorization: `Bearer ${this.config.
|
|
3324
|
+
Authorization: `Bearer ${this.config.getApiKey()}`,
|
|
3319
3325
|
"Content-Type": "application/json"
|
|
3320
3326
|
};
|
|
3321
3327
|
}
|
|
@@ -3347,11 +3353,10 @@ var PostHogAPIClient = class {
|
|
|
3347
3353
|
return this.baseUrl;
|
|
3348
3354
|
}
|
|
3349
3355
|
getApiKey() {
|
|
3350
|
-
return this.config.
|
|
3356
|
+
return this.config.getApiKey();
|
|
3351
3357
|
}
|
|
3352
3358
|
getLlmGatewayUrl() {
|
|
3353
|
-
|
|
3354
|
-
return `${this.baseUrl}/api/projects/${teamId}/llm_gateway`;
|
|
3359
|
+
return getLlmGatewayUrl(this.baseUrl);
|
|
3355
3360
|
}
|
|
3356
3361
|
async fetchTask(taskId) {
|
|
3357
3362
|
const teamId = this.getTeamId();
|
|
@@ -3742,14 +3747,16 @@ var PromptBuilder = class {
|
|
|
3742
3747
|
if (filePaths.length === 0 || !repositoryPath) {
|
|
3743
3748
|
return { description, referencedFiles };
|
|
3744
3749
|
}
|
|
3750
|
+
const successfulPaths = /* @__PURE__ */ new Set();
|
|
3745
3751
|
for (const filePath of filePaths) {
|
|
3746
3752
|
const content = await this.readFileContent(repositoryPath, filePath);
|
|
3747
3753
|
if (content !== null) {
|
|
3748
3754
|
referencedFiles.push({ path: filePath, content });
|
|
3755
|
+
successfulPaths.add(filePath);
|
|
3749
3756
|
}
|
|
3750
3757
|
}
|
|
3751
3758
|
let processedDescription = description;
|
|
3752
|
-
for (const filePath of
|
|
3759
|
+
for (const filePath of successfulPaths) {
|
|
3753
3760
|
const fileName = filePath.split("/").pop() || filePath;
|
|
3754
3761
|
processedDescription = processedDescription.replace(
|
|
3755
3762
|
new RegExp(
|
|
@@ -4464,7 +4471,7 @@ Placeholder content for ${file.name}`;
|
|
|
4464
4471
|
generatePostHogReadme() {
|
|
4465
4472
|
return `# PostHog Task Files
|
|
4466
4473
|
|
|
4467
|
-
This directory contains task-related files
|
|
4474
|
+
This directory contains task-related files.
|
|
4468
4475
|
|
|
4469
4476
|
## Structure
|
|
4470
4477
|
|
|
@@ -4480,7 +4487,7 @@ Each task has its own subdirectory: \`.posthog/{task-id}/\`
|
|
|
4480
4487
|
|
|
4481
4488
|
These files are:
|
|
4482
4489
|
- Version controlled alongside your code
|
|
4483
|
-
- Used
|
|
4490
|
+
- Used for task context and planning
|
|
4484
4491
|
- Available for review in pull requests
|
|
4485
4492
|
- Organized by task ID for easy reference
|
|
4486
4493
|
|
|
@@ -4490,10 +4497,6 @@ Customize \`.posthog/.gitignore\` to control which files are committed:
|
|
|
4490
4497
|
- Include plans and documentation by default
|
|
4491
4498
|
- Exclude temporary files and sensitive data
|
|
4492
4499
|
- Customize based on your team's needs
|
|
4493
|
-
|
|
4494
|
-
---
|
|
4495
|
-
|
|
4496
|
-
*Generated by PostHog Agent*
|
|
4497
4500
|
`;
|
|
4498
4501
|
}
|
|
4499
4502
|
};
|
|
@@ -5650,8 +5653,8 @@ var Agent = class {
|
|
|
5650
5653
|
this.debug = config.debug || false;
|
|
5651
5654
|
const posthogMcpUrl = config.posthogMcpUrl || process.env.POSTHOG_MCP_URL || "https://mcp.posthog.com/mcp";
|
|
5652
5655
|
const headers = {};
|
|
5653
|
-
if (config.
|
|
5654
|
-
headers.Authorization = `Bearer ${config.
|
|
5656
|
+
if (config.getPosthogApiKey) {
|
|
5657
|
+
headers.Authorization = `Bearer ${config.getPosthogApiKey()}`;
|
|
5655
5658
|
}
|
|
5656
5659
|
const defaultMcpServers = {
|
|
5657
5660
|
posthog: {
|
|
@@ -5679,10 +5682,10 @@ var Agent = class {
|
|
|
5679
5682
|
logger: this.logger.child("GitManager")
|
|
5680
5683
|
});
|
|
5681
5684
|
this.templateManager = new TemplateManager();
|
|
5682
|
-
if (config.posthogApiUrl && config.
|
|
5685
|
+
if (config.posthogApiUrl && config.getPosthogApiKey && config.posthogProjectId) {
|
|
5683
5686
|
this.posthogAPI = new PostHogAPIClient({
|
|
5684
5687
|
apiUrl: config.posthogApiUrl,
|
|
5685
|
-
|
|
5688
|
+
getApiKey: config.getPosthogApiKey,
|
|
5686
5689
|
projectId: config.posthogProjectId
|
|
5687
5690
|
});
|
|
5688
5691
|
this.sessionStore = new SessionStore(
|
|
@@ -5705,7 +5708,7 @@ var Agent = class {
|
|
|
5705
5708
|
this.logger.setDebug(enabled);
|
|
5706
5709
|
}
|
|
5707
5710
|
/**
|
|
5708
|
-
* Configure LLM gateway environment variables for Claude Code CLI
|
|
5711
|
+
* Configure LLM gateway environment variables for Claude Code CLI.
|
|
5709
5712
|
*/
|
|
5710
5713
|
async _configureLlmGateway() {
|
|
5711
5714
|
if (!this.posthogAPI) {
|
|
@@ -5717,6 +5720,7 @@ var Agent = class {
|
|
|
5717
5720
|
process.env.ANTHROPIC_BASE_URL = gatewayUrl;
|
|
5718
5721
|
process.env.ANTHROPIC_AUTH_TOKEN = apiKey;
|
|
5719
5722
|
this.ensureOpenAIGatewayEnv(gatewayUrl, apiKey);
|
|
5723
|
+
this.ensureGeminiGatewayEnv(gatewayUrl, apiKey);
|
|
5720
5724
|
} catch (error) {
|
|
5721
5725
|
this.logger.error("Failed to configure LLM gateway", error);
|
|
5722
5726
|
throw error;
|
|
@@ -5900,9 +5904,7 @@ var Agent = class {
|
|
|
5900
5904
|
**Description**: ${taskDescription}
|
|
5901
5905
|
|
|
5902
5906
|
## Changes
|
|
5903
|
-
This PR implements the changes described in the task
|
|
5904
|
-
|
|
5905
|
-
Generated by PostHog Agent`;
|
|
5907
|
+
This PR implements the changes described in the task.`;
|
|
5906
5908
|
const prBody = customBody || defaultBody;
|
|
5907
5909
|
const prUrl = await this.gitManager.createPullRequest(
|
|
5908
5910
|
branchName,
|
|
@@ -6021,6 +6023,16 @@ Generated by PostHog Agent`;
|
|
|
6021
6023
|
process.env.OPENAI_API_KEY = resolvedToken;
|
|
6022
6024
|
}
|
|
6023
6025
|
}
|
|
6026
|
+
ensureGeminiGatewayEnv(gatewayUrl, token) {
|
|
6027
|
+
const resolvedGatewayUrl = gatewayUrl || process.env.ANTHROPIC_BASE_URL;
|
|
6028
|
+
const resolvedToken = token || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
6029
|
+
if (resolvedGatewayUrl) {
|
|
6030
|
+
process.env.GEMINI_BASE_URL = resolvedGatewayUrl;
|
|
6031
|
+
}
|
|
6032
|
+
if (resolvedToken) {
|
|
6033
|
+
process.env.GEMINI_API_KEY = resolvedToken;
|
|
6034
|
+
}
|
|
6035
|
+
}
|
|
6024
6036
|
async runTaskCloud(taskId, taskRunId, options = {}) {
|
|
6025
6037
|
await this._configureLlmGateway();
|
|
6026
6038
|
const task = await this.fetchTask(taskId);
|
|
@@ -7338,6 +7350,7 @@ export {
|
|
|
7338
7350
|
ToolRegistry,
|
|
7339
7351
|
WorktreeManager,
|
|
7340
7352
|
createAcpConnection,
|
|
7353
|
+
getLlmGatewayUrl,
|
|
7341
7354
|
parseAgentEvent,
|
|
7342
7355
|
parseAgentEvents
|
|
7343
7356
|
};
|