@posthog/agent 2.3.213 → 2.3.216
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 +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/posthog-api.js +1 -1
- package/dist/posthog-api.js.map +1 -1
- package/dist/server/agent-server.d.ts +3 -0
- package/dist/server/agent-server.js +9328 -9274
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +9291 -9237
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +1 -1
- package/src/server/agent-server.ts +53 -0
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
PROTOCOL_VERSION,
|
|
6
6
|
} from "@agentclientprotocol/sdk";
|
|
7
7
|
import { type ServerType, serve } from "@hono/node-server";
|
|
8
|
+
import { getCurrentBranch } from "@posthog/git/queries";
|
|
8
9
|
import { Hono } from "hono";
|
|
9
10
|
import packageJson from "../../package.json" with { type: "json" };
|
|
10
11
|
import { POSTHOG_NOTIFICATIONS } from "../acp-extensions";
|
|
@@ -167,6 +168,7 @@ export class AgentServer {
|
|
|
167
168
|
private posthogAPI: PostHogAPIClient;
|
|
168
169
|
private questionRelayedToSlack = false;
|
|
169
170
|
private detectedPrUrl: string | null = null;
|
|
171
|
+
private lastReportedBranch: string | null = null;
|
|
170
172
|
private resumeState: ResumeState | null = null;
|
|
171
173
|
// Guards against concurrent session initialization. autoInitializeSession() and
|
|
172
174
|
// the GET /events SSE handler can both call initializeSession() — the SSE connection
|
|
@@ -524,6 +526,10 @@ export class AgentServer {
|
|
|
524
526
|
stopReason: result.stopReason,
|
|
525
527
|
});
|
|
526
528
|
|
|
529
|
+
if (result.stopReason === "end_turn") {
|
|
530
|
+
void this.syncCloudBranchMetadata(this.session.payload);
|
|
531
|
+
}
|
|
532
|
+
|
|
527
533
|
this.broadcastTurnComplete(result.stopReason);
|
|
528
534
|
|
|
529
535
|
if (result.stopReason === "end_turn") {
|
|
@@ -879,6 +885,10 @@ export class AgentServer {
|
|
|
879
885
|
stopReason: result.stopReason,
|
|
880
886
|
});
|
|
881
887
|
|
|
888
|
+
if (result.stopReason === "end_turn") {
|
|
889
|
+
void this.syncCloudBranchMetadata(payload);
|
|
890
|
+
}
|
|
891
|
+
|
|
882
892
|
this.broadcastTurnComplete(result.stopReason);
|
|
883
893
|
|
|
884
894
|
if (result.stopReason === "end_turn") {
|
|
@@ -964,6 +974,10 @@ export class AgentServer {
|
|
|
964
974
|
stopReason: result.stopReason,
|
|
965
975
|
});
|
|
966
976
|
|
|
977
|
+
if (result.stopReason === "end_turn") {
|
|
978
|
+
void this.syncCloudBranchMetadata(payload);
|
|
979
|
+
}
|
|
980
|
+
|
|
967
981
|
this.broadcastTurnComplete(result.stopReason);
|
|
968
982
|
|
|
969
983
|
if (result.stopReason === "end_turn") {
|
|
@@ -1168,6 +1182,44 @@ ${attributionInstructions}
|
|
|
1168
1182
|
`;
|
|
1169
1183
|
}
|
|
1170
1184
|
|
|
1185
|
+
private async getCurrentGitBranch(): Promise<string | null> {
|
|
1186
|
+
if (!this.config.repositoryPath) {
|
|
1187
|
+
return null;
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
try {
|
|
1191
|
+
return await getCurrentBranch(this.config.repositoryPath);
|
|
1192
|
+
} catch (error) {
|
|
1193
|
+
this.logger.warn("Failed to determine current git branch", {
|
|
1194
|
+
repositoryPath: this.config.repositoryPath,
|
|
1195
|
+
error,
|
|
1196
|
+
});
|
|
1197
|
+
return null;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
private async syncCloudBranchMetadata(payload: JwtPayload): Promise<void> {
|
|
1202
|
+
const branchName = await this.getCurrentGitBranch();
|
|
1203
|
+
if (!branchName || branchName === this.lastReportedBranch) {
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
try {
|
|
1208
|
+
await this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
1209
|
+
branch: branchName,
|
|
1210
|
+
output: { head_branch: branchName },
|
|
1211
|
+
});
|
|
1212
|
+
this.lastReportedBranch = branchName;
|
|
1213
|
+
} catch (error) {
|
|
1214
|
+
this.logger.warn("Failed to attach current branch to task run", {
|
|
1215
|
+
taskId: payload.task_id,
|
|
1216
|
+
runId: payload.run_id,
|
|
1217
|
+
branchName,
|
|
1218
|
+
error,
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1171
1223
|
private async signalTaskComplete(
|
|
1172
1224
|
payload: JwtPayload,
|
|
1173
1225
|
stopReason: string,
|
|
@@ -1556,6 +1608,7 @@ ${attributionInstructions}
|
|
|
1556
1608
|
}
|
|
1557
1609
|
|
|
1558
1610
|
this.pendingEvents = [];
|
|
1611
|
+
this.lastReportedBranch = null;
|
|
1559
1612
|
this.session = null;
|
|
1560
1613
|
}
|
|
1561
1614
|
|