@posthog/agent 2.3.526 → 2.3.535
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 +30 -5
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +5 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/pr-url-detector.d.ts +12 -0
- package/dist/pr-url-detector.js +34 -0
- package/dist/pr-url-detector.js.map +1 -0
- package/dist/server/agent-server.js +69 -32
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +69 -32
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +7 -3
- package/src/adapters/claude/conversion/sdk-to-acp.ts +28 -3
- package/src/adapters/claude/types.ts +1 -0
- package/src/pr-url-detector.test.ts +140 -0
- package/src/pr-url-detector.ts +46 -0
- package/src/server/agent-server.test.ts +91 -12
- package/src/server/agent-server.ts +12 -35
package/dist/server/bin.cjs
CHANGED
|
@@ -8755,7 +8755,7 @@ var import_zod3 = require("zod");
|
|
|
8755
8755
|
// package.json
|
|
8756
8756
|
var package_default = {
|
|
8757
8757
|
name: "@posthog/agent",
|
|
8758
|
-
version: "2.3.
|
|
8758
|
+
version: "2.3.535",
|
|
8759
8759
|
repository: "https://github.com/PostHog/code",
|
|
8760
8760
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8761
8761
|
exports: {
|
|
@@ -8775,6 +8775,10 @@ var package_default = {
|
|
|
8775
8775
|
types: "./dist/posthog-api.d.ts",
|
|
8776
8776
|
import: "./dist/posthog-api.js"
|
|
8777
8777
|
},
|
|
8778
|
+
"./pr-url-detector": {
|
|
8779
|
+
types: "./dist/pr-url-detector.d.ts",
|
|
8780
|
+
import: "./dist/pr-url-detector.js"
|
|
8781
|
+
},
|
|
8778
8782
|
"./types": {
|
|
8779
8783
|
types: "./dist/types.d.ts",
|
|
8780
8784
|
import: "./dist/types.js"
|
|
@@ -14528,12 +14532,18 @@ ${text2}${text2.endsWith("\n") ? "" : "\n"}${escapedText}`;
|
|
|
14528
14532
|
function messageUpdateType(role) {
|
|
14529
14533
|
return role === "assistant" ? "agent_message_chunk" : "user_message_chunk";
|
|
14530
14534
|
}
|
|
14531
|
-
function toolMeta(toolName, toolResponse, parentToolCallId) {
|
|
14535
|
+
function toolMeta(toolName, toolResponse, parentToolCallId, bashCommand) {
|
|
14532
14536
|
const meta = { toolName };
|
|
14533
14537
|
if (toolResponse !== void 0) meta.toolResponse = toolResponse;
|
|
14534
14538
|
if (parentToolCallId) meta.parentToolCallId = parentToolCallId;
|
|
14539
|
+
if (bashCommand) meta.bashCommand = bashCommand;
|
|
14535
14540
|
return { claudeCode: meta };
|
|
14536
14541
|
}
|
|
14542
|
+
function bashCommandFromToolUse(toolUse) {
|
|
14543
|
+
if (!toolUse || toolUse.name !== "Bash") return void 0;
|
|
14544
|
+
const command = toolUse.input?.command;
|
|
14545
|
+
return typeof command === "string" ? command : void 0;
|
|
14546
|
+
}
|
|
14537
14547
|
function handleTextChunk(chunk, role, parentToolCallId) {
|
|
14538
14548
|
const update = {
|
|
14539
14549
|
sessionUpdate: messageUpdateType(role),
|
|
@@ -14594,7 +14604,12 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
14594
14604
|
await ctx.client.sessionUpdate({
|
|
14595
14605
|
sessionId: ctx.sessionId,
|
|
14596
14606
|
update: {
|
|
14597
|
-
_meta: toolMeta(
|
|
14607
|
+
_meta: toolMeta(
|
|
14608
|
+
toolUse.name,
|
|
14609
|
+
toolResponse,
|
|
14610
|
+
ctx.parentToolCallId,
|
|
14611
|
+
bashCommandFromToolUse(toolUse)
|
|
14612
|
+
),
|
|
14598
14613
|
toolCallId: toolUseId,
|
|
14599
14614
|
sessionUpdate: "tool_call_update",
|
|
14600
14615
|
...editUpdate ? editUpdate : {}
|
|
@@ -14620,7 +14635,12 @@ function handleToolUseChunk(chunk, ctx) {
|
|
|
14620
14635
|
cwd: ctx.cwd
|
|
14621
14636
|
});
|
|
14622
14637
|
const meta = {
|
|
14623
|
-
...toolMeta(
|
|
14638
|
+
...toolMeta(
|
|
14639
|
+
chunk.name,
|
|
14640
|
+
void 0,
|
|
14641
|
+
ctx.parentToolCallId,
|
|
14642
|
+
bashCommandFromToolUse(chunk)
|
|
14643
|
+
)
|
|
14624
14644
|
};
|
|
14625
14645
|
if (chunk.name === "Bash" && ctx.supportsTerminalOutput && !alreadyCached) {
|
|
14626
14646
|
meta.terminal_info = { terminal_id: chunk.id };
|
|
@@ -14725,7 +14745,12 @@ function handleToolResultChunk(chunk, ctx) {
|
|
|
14725
14745
|
});
|
|
14726
14746
|
}
|
|
14727
14747
|
const meta = {
|
|
14728
|
-
...toolMeta(
|
|
14748
|
+
...toolMeta(
|
|
14749
|
+
toolUse.name,
|
|
14750
|
+
void 0,
|
|
14751
|
+
ctx.parentToolCallId,
|
|
14752
|
+
bashCommandFromToolUse(toolUse)
|
|
14753
|
+
),
|
|
14729
14754
|
...resultMeta?.terminal_exit ? { terminal_exit: resultMeta.terminal_exit } : {}
|
|
14730
14755
|
};
|
|
14731
14756
|
updates.push({
|
|
@@ -20287,6 +20312,37 @@ var PostHogAPIClient = class {
|
|
|
20287
20312
|
}
|
|
20288
20313
|
};
|
|
20289
20314
|
|
|
20315
|
+
// src/pr-url-detector.ts
|
|
20316
|
+
var PR_URL_REGEX = /https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+/;
|
|
20317
|
+
var GH_PR_CREATE_REGEX = /\bgh\s+pr\s+create\b/;
|
|
20318
|
+
function extractCreatedPrUrl(input) {
|
|
20319
|
+
const { toolName, bashCommand, toolResponse, content } = input;
|
|
20320
|
+
if (!toolName || !/bash/i.test(toolName)) return null;
|
|
20321
|
+
if (!bashCommand || !GH_PR_CREATE_REGEX.test(bashCommand)) return null;
|
|
20322
|
+
let textToSearch = "";
|
|
20323
|
+
if (toolResponse) {
|
|
20324
|
+
if (typeof toolResponse === "string") {
|
|
20325
|
+
textToSearch = toolResponse;
|
|
20326
|
+
} else if (typeof toolResponse === "object" && toolResponse !== null) {
|
|
20327
|
+
const respObj = toolResponse;
|
|
20328
|
+
textToSearch = String(respObj.stdout || "") + String(respObj.stderr || "");
|
|
20329
|
+
if (!textToSearch && respObj.output) {
|
|
20330
|
+
textToSearch = String(respObj.output);
|
|
20331
|
+
}
|
|
20332
|
+
}
|
|
20333
|
+
}
|
|
20334
|
+
if (Array.isArray(content)) {
|
|
20335
|
+
for (const item of content) {
|
|
20336
|
+
if (item.type === "text" && item.text) {
|
|
20337
|
+
textToSearch += ` ${item.text}`;
|
|
20338
|
+
}
|
|
20339
|
+
}
|
|
20340
|
+
}
|
|
20341
|
+
if (!textToSearch) return null;
|
|
20342
|
+
const match = textToSearch.match(PR_URL_REGEX);
|
|
20343
|
+
return match ? match[0] : null;
|
|
20344
|
+
}
|
|
20345
|
+
|
|
20290
20346
|
// src/adapters/claude/session/jsonl-hydration.ts
|
|
20291
20347
|
var import_node_crypto3 = require("crypto");
|
|
20292
20348
|
var fs12 = __toESM(require("fs/promises"), 1);
|
|
@@ -22691,35 +22747,16 @@ ${attributionInstructions}
|
|
|
22691
22747
|
detectAndAttachPrUrl(payload, update) {
|
|
22692
22748
|
try {
|
|
22693
22749
|
const meta = update?._meta?.claudeCode;
|
|
22694
|
-
const toolResponse = meta?.toolResponse;
|
|
22695
|
-
let textToSearch = "";
|
|
22696
|
-
if (toolResponse) {
|
|
22697
|
-
if (typeof toolResponse === "string") {
|
|
22698
|
-
textToSearch = toolResponse;
|
|
22699
|
-
} else if (typeof toolResponse === "object" && toolResponse !== null) {
|
|
22700
|
-
const respObj = toolResponse;
|
|
22701
|
-
textToSearch = String(respObj.stdout || "") + String(respObj.stderr || "");
|
|
22702
|
-
if (!textToSearch && respObj.output) {
|
|
22703
|
-
textToSearch = String(respObj.output);
|
|
22704
|
-
}
|
|
22705
|
-
}
|
|
22706
|
-
}
|
|
22707
22750
|
const content = update?.content;
|
|
22708
|
-
|
|
22709
|
-
|
|
22710
|
-
|
|
22711
|
-
|
|
22712
|
-
|
|
22713
|
-
|
|
22714
|
-
|
|
22715
|
-
if (!textToSearch) return;
|
|
22716
|
-
const prUrlMatch = textToSearch.match(
|
|
22717
|
-
/https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+/
|
|
22718
|
-
);
|
|
22719
|
-
if (!prUrlMatch) return;
|
|
22720
|
-
const prUrl = prUrlMatch[0];
|
|
22751
|
+
const prUrl = extractCreatedPrUrl({
|
|
22752
|
+
toolName: meta?.toolName,
|
|
22753
|
+
bashCommand: meta?.bashCommand,
|
|
22754
|
+
toolResponse: meta?.toolResponse,
|
|
22755
|
+
content
|
|
22756
|
+
});
|
|
22757
|
+
if (!prUrl) return;
|
|
22721
22758
|
this.detectedPrUrl = prUrl;
|
|
22722
|
-
this.logger.debug("Detected PR URL
|
|
22759
|
+
this.logger.debug("Detected PR URL from gh pr create", {
|
|
22723
22760
|
runId: payload.run_id,
|
|
22724
22761
|
prUrl
|
|
22725
22762
|
});
|