@posthog/agent 2.1.8 → 2.1.15
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 +2 -2
- package/dist/agent.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/server/agent-server.d.ts +2 -0
- package/dist/server/agent-server.js +89 -7
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +89 -7
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/adapters/claude/session/options.ts +1 -1
- package/src/server/agent-server.ts +114 -1
package/dist/server/bin.cjs
CHANGED
|
@@ -1175,7 +1175,7 @@ var import_uuid = require("uuid");
|
|
|
1175
1175
|
// package.json
|
|
1176
1176
|
var package_default = {
|
|
1177
1177
|
name: "@posthog/agent",
|
|
1178
|
-
version: "2.1.
|
|
1178
|
+
version: "2.1.15",
|
|
1179
1179
|
repository: "https://github.com/PostHog/twig",
|
|
1180
1180
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
1181
1181
|
exports: {
|
|
@@ -3073,7 +3073,7 @@ var path2 = __toESM(require("path"), 1);
|
|
|
3073
3073
|
var BRANCH_NAMING_INSTRUCTIONS = `
|
|
3074
3074
|
# Branch Naming
|
|
3075
3075
|
|
|
3076
|
-
|
|
3076
|
+
When working in a detached HEAD state, create a descriptive branch name based on the work being done before committing. Do this automatically without asking the user.
|
|
3077
3077
|
`;
|
|
3078
3078
|
function buildSystemPrompt(customPrompt) {
|
|
3079
3079
|
const defaultPrompt = {
|
|
@@ -9076,9 +9076,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
|
|
|
9076
9076
|
const scopedGit = createGitClient(repoPath, {
|
|
9077
9077
|
abortSignal: options.signal
|
|
9078
9078
|
});
|
|
9079
|
-
return operation(scopedGit.env({ GIT_OPTIONAL_LOCKS: "0" }));
|
|
9079
|
+
return operation(scopedGit.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" }));
|
|
9080
9080
|
}
|
|
9081
|
-
const git = state.client.env({ GIT_OPTIONAL_LOCKS: "0" });
|
|
9081
|
+
const git = state.client.env({ ...process.env, GIT_OPTIONAL_LOCKS: "0" });
|
|
9082
9082
|
return operation(git);
|
|
9083
9083
|
}
|
|
9084
9084
|
async executeWrite(repoPath, operation, options) {
|
|
@@ -9095,9 +9095,9 @@ var GitOperationManagerImpl = class _GitOperationManagerImpl {
|
|
|
9095
9095
|
const scopedGit = createGitClient(repoPath, {
|
|
9096
9096
|
abortSignal: options.signal
|
|
9097
9097
|
});
|
|
9098
|
-
return await operation(scopedGit);
|
|
9098
|
+
return await operation(scopedGit.env(process.env));
|
|
9099
9099
|
}
|
|
9100
|
-
return await operation(state.client);
|
|
9100
|
+
return await operation(state.client.env(process.env));
|
|
9101
9101
|
} catch (error) {
|
|
9102
9102
|
if (options?.signal?.aborted) {
|
|
9103
9103
|
await removeLock(repoPath).catch(() => {
|
|
@@ -10302,7 +10302,11 @@ var AgentServer = class {
|
|
|
10302
10302
|
await clientConnection.newSession({
|
|
10303
10303
|
cwd: this.config.repositoryPath,
|
|
10304
10304
|
mcpServers: [],
|
|
10305
|
-
_meta: {
|
|
10305
|
+
_meta: {
|
|
10306
|
+
sessionId: payload.run_id,
|
|
10307
|
+
taskRunId: payload.run_id,
|
|
10308
|
+
systemPrompt: { append: this.buildCloudSystemPrompt() }
|
|
10309
|
+
}
|
|
10306
10310
|
});
|
|
10307
10311
|
this.session = {
|
|
10308
10312
|
payload,
|
|
@@ -10314,6 +10318,11 @@ var AgentServer = class {
|
|
|
10314
10318
|
logWriter
|
|
10315
10319
|
};
|
|
10316
10320
|
this.logger.info("Session initialized successfully");
|
|
10321
|
+
this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
10322
|
+
status: "in_progress"
|
|
10323
|
+
}).catch(
|
|
10324
|
+
(err) => this.logger.warn("Failed to set task run to in_progress", err)
|
|
10325
|
+
);
|
|
10317
10326
|
await this.sendInitialTaskMessage(payload);
|
|
10318
10327
|
}
|
|
10319
10328
|
async sendInitialTaskMessage(payload) {
|
|
@@ -10350,6 +10359,19 @@ var AgentServer = class {
|
|
|
10350
10359
|
}
|
|
10351
10360
|
}
|
|
10352
10361
|
}
|
|
10362
|
+
buildCloudSystemPrompt() {
|
|
10363
|
+
return `
|
|
10364
|
+
# Cloud Task Execution
|
|
10365
|
+
|
|
10366
|
+
After completing the requested changes:
|
|
10367
|
+
1. Create a new branch with a descriptive name based on the work done
|
|
10368
|
+
2. Stage and commit all changes with a clear commit message
|
|
10369
|
+
3. Push the branch to origin
|
|
10370
|
+
4. Create a pull request using \`gh pr create\` with a descriptive title and body
|
|
10371
|
+
|
|
10372
|
+
Important: Always create the PR. Do not ask for confirmation.
|
|
10373
|
+
`;
|
|
10374
|
+
}
|
|
10353
10375
|
async signalTaskComplete(payload, stopReason) {
|
|
10354
10376
|
const status = stopReason === "cancelled" ? "cancelled" : stopReason === "error" ? "failed" : "completed";
|
|
10355
10377
|
try {
|
|
@@ -10410,10 +10432,70 @@ var AgentServer = class {
|
|
|
10410
10432
|
if ((toolName === "Write" || toolName === "Edit") && toolResponse?.filePath) {
|
|
10411
10433
|
await this.captureTreeState();
|
|
10412
10434
|
}
|
|
10435
|
+
if (toolName && (toolName.includes("Bash") || toolName.includes("bash"))) {
|
|
10436
|
+
this.detectAndAttachPrUrl(payload, params.update);
|
|
10437
|
+
}
|
|
10413
10438
|
}
|
|
10414
10439
|
}
|
|
10415
10440
|
};
|
|
10416
10441
|
}
|
|
10442
|
+
detectAndAttachPrUrl(payload, update) {
|
|
10443
|
+
try {
|
|
10444
|
+
const meta = update?._meta?.claudeCode;
|
|
10445
|
+
const toolResponse = meta?.toolResponse;
|
|
10446
|
+
let textToSearch = "";
|
|
10447
|
+
if (toolResponse) {
|
|
10448
|
+
if (typeof toolResponse === "string") {
|
|
10449
|
+
textToSearch = toolResponse;
|
|
10450
|
+
} else if (typeof toolResponse === "object" && toolResponse !== null) {
|
|
10451
|
+
const respObj = toolResponse;
|
|
10452
|
+
textToSearch = String(respObj.stdout || "") + String(respObj.stderr || "");
|
|
10453
|
+
if (!textToSearch && respObj.output) {
|
|
10454
|
+
textToSearch = String(respObj.output);
|
|
10455
|
+
}
|
|
10456
|
+
}
|
|
10457
|
+
}
|
|
10458
|
+
const content = update?.content;
|
|
10459
|
+
if (Array.isArray(content)) {
|
|
10460
|
+
for (const item of content) {
|
|
10461
|
+
if (item.type === "text" && item.text) {
|
|
10462
|
+
textToSearch += ` ${item.text}`;
|
|
10463
|
+
}
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10466
|
+
if (!textToSearch) return;
|
|
10467
|
+
const prUrlMatch = textToSearch.match(
|
|
10468
|
+
/https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+/
|
|
10469
|
+
);
|
|
10470
|
+
if (!prUrlMatch) return;
|
|
10471
|
+
const prUrl = prUrlMatch[0];
|
|
10472
|
+
this.logger.info("Detected PR URL in bash output", {
|
|
10473
|
+
runId: payload.run_id,
|
|
10474
|
+
prUrl
|
|
10475
|
+
});
|
|
10476
|
+
this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
10477
|
+
output: { pr_url: prUrl }
|
|
10478
|
+
}).then(() => {
|
|
10479
|
+
this.logger.info("PR URL attached to task run", {
|
|
10480
|
+
taskId: payload.task_id,
|
|
10481
|
+
runId: payload.run_id,
|
|
10482
|
+
prUrl
|
|
10483
|
+
});
|
|
10484
|
+
}).catch((err) => {
|
|
10485
|
+
this.logger.error("Failed to attach PR URL to task run", {
|
|
10486
|
+
taskId: payload.task_id,
|
|
10487
|
+
runId: payload.run_id,
|
|
10488
|
+
prUrl,
|
|
10489
|
+
error: err
|
|
10490
|
+
});
|
|
10491
|
+
});
|
|
10492
|
+
} catch (err) {
|
|
10493
|
+
this.logger.debug("Error in PR URL detection", {
|
|
10494
|
+
runId: payload.run_id,
|
|
10495
|
+
error: err
|
|
10496
|
+
});
|
|
10497
|
+
}
|
|
10498
|
+
}
|
|
10417
10499
|
async cleanupSession() {
|
|
10418
10500
|
if (!this.session) return;
|
|
10419
10501
|
this.logger.info("Cleaning up session");
|