@posthog/agent 2.3.353 → 2.3.356
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 +19 -2
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.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 +2 -0
- package/dist/server/agent-server.js +98 -54
- package/dist/server/agent-server.js.map +1 -1
- package/dist/server/bin.cjs +98 -54
- package/dist/server/bin.cjs.map +1 -1
- package/package.json +3 -3
- package/src/acp-extensions.ts +3 -0
- package/src/adapters/claude/conversion/sdk-to-acp.ts +31 -1
- package/src/server/agent-server.ts +103 -53
- package/src/server/question-relay.test.ts +124 -0
package/dist/server/bin.cjs
CHANGED
|
@@ -8723,11 +8723,12 @@ async function getHeadSha(baseDir, options) {
|
|
|
8723
8723
|
|
|
8724
8724
|
// src/server/agent-server.ts
|
|
8725
8725
|
var import_hono = require("hono");
|
|
8726
|
+
var import_zod3 = require("zod");
|
|
8726
8727
|
|
|
8727
8728
|
// package.json
|
|
8728
8729
|
var package_default = {
|
|
8729
8730
|
name: "@posthog/agent",
|
|
8730
|
-
version: "2.3.
|
|
8731
|
+
version: "2.3.356",
|
|
8731
8732
|
repository: "https://github.com/PostHog/code",
|
|
8732
8733
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8733
8734
|
exports: {
|
|
@@ -8888,6 +8889,8 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
8888
8889
|
CLOSE: "_posthog/close",
|
|
8889
8890
|
/** Agent status update (thinking, working, etc.) */
|
|
8890
8891
|
STATUS: "_posthog/status",
|
|
8892
|
+
/** Structured backend progress notification; events in the same turn group into one card on the client */
|
|
8893
|
+
PROGRESS: "_posthog/progress",
|
|
8891
8894
|
/** Task-level notification (progress, milestones) */
|
|
8892
8895
|
TASK_NOTIFICATION: "_posthog/task_notification",
|
|
8893
8896
|
/** Marks a boundary for log compaction */
|
|
@@ -13883,6 +13886,17 @@ async function handleSystemMessage(message, context) {
|
|
|
13883
13886
|
break;
|
|
13884
13887
|
}
|
|
13885
13888
|
}
|
|
13889
|
+
function classifyAgentError(result) {
|
|
13890
|
+
if (!result) return "agent_error";
|
|
13891
|
+
const text2 = result.trim();
|
|
13892
|
+
if (/API Error:\s*terminated\b/i.test(text2)) {
|
|
13893
|
+
return "upstream_stream_terminated";
|
|
13894
|
+
}
|
|
13895
|
+
if (/API Error:\s*Connection error\b/i.test(text2)) {
|
|
13896
|
+
return "upstream_connection_error";
|
|
13897
|
+
}
|
|
13898
|
+
return "agent_error";
|
|
13899
|
+
}
|
|
13886
13900
|
function handleResultMessage(message) {
|
|
13887
13901
|
const usage = extractUsageFromResult(message);
|
|
13888
13902
|
switch (message.subtype) {
|
|
@@ -13898,9 +13912,13 @@ function handleResultMessage(message) {
|
|
|
13898
13912
|
return { shouldStop: true, stopReason: "max_tokens", usage };
|
|
13899
13913
|
}
|
|
13900
13914
|
if (message.is_error) {
|
|
13915
|
+
const classification = classifyAgentError(message.result);
|
|
13901
13916
|
return {
|
|
13902
13917
|
shouldStop: true,
|
|
13903
|
-
error: import_sdk.RequestError.internalError(
|
|
13918
|
+
error: import_sdk.RequestError.internalError(
|
|
13919
|
+
{ classification, result: message.result },
|
|
13920
|
+
message.result
|
|
13921
|
+
),
|
|
13904
13922
|
usage
|
|
13905
13923
|
};
|
|
13906
13924
|
}
|
|
@@ -19114,6 +19132,14 @@ function validateCommandParams(method, params) {
|
|
|
19114
19132
|
}
|
|
19115
19133
|
|
|
19116
19134
|
// src/server/agent-server.ts
|
|
19135
|
+
var agentErrorClassificationSchema = import_zod3.z.enum([
|
|
19136
|
+
"upstream_stream_terminated",
|
|
19137
|
+
"upstream_connection_error",
|
|
19138
|
+
"agent_error"
|
|
19139
|
+
]);
|
|
19140
|
+
var errorWithClassificationSchema = import_zod3.z.object({
|
|
19141
|
+
data: import_zod3.z.object({ classification: agentErrorClassificationSchema })
|
|
19142
|
+
});
|
|
19117
19143
|
var NdJsonTap = class {
|
|
19118
19144
|
constructor(onMessage) {
|
|
19119
19145
|
this.onMessage = onMessage;
|
|
@@ -19413,7 +19439,9 @@ var AgentServer = class _AgentServer {
|
|
|
19413
19439
|
port: this.config.port
|
|
19414
19440
|
},
|
|
19415
19441
|
() => {
|
|
19416
|
-
this.logger.
|
|
19442
|
+
this.logger.debug(
|
|
19443
|
+
`HTTP server listening on port ${this.config.port}`
|
|
19444
|
+
);
|
|
19417
19445
|
resolve4();
|
|
19418
19446
|
}
|
|
19419
19447
|
);
|
|
@@ -19422,10 +19450,10 @@ var AgentServer = class _AgentServer {
|
|
|
19422
19450
|
}
|
|
19423
19451
|
async autoInitializeSession() {
|
|
19424
19452
|
const { taskId, runId, mode, projectId } = this.config;
|
|
19425
|
-
this.logger.
|
|
19453
|
+
this.logger.debug("Auto-initializing session", { taskId, runId, mode });
|
|
19426
19454
|
const resumeRunId = process.env.POSTHOG_RESUME_RUN_ID;
|
|
19427
19455
|
if (resumeRunId) {
|
|
19428
|
-
this.logger.
|
|
19456
|
+
this.logger.debug("Resuming from previous run", {
|
|
19429
19457
|
resumeRunId,
|
|
19430
19458
|
currentRunId: runId
|
|
19431
19459
|
});
|
|
@@ -19437,13 +19465,13 @@ var AgentServer = class _AgentServer {
|
|
|
19437
19465
|
apiClient: this.posthogAPI,
|
|
19438
19466
|
logger: new Logger({ debug: true, prefix: "[Resume]" })
|
|
19439
19467
|
});
|
|
19440
|
-
this.logger.
|
|
19468
|
+
this.logger.debug("Resume state loaded", {
|
|
19441
19469
|
conversationTurns: this.resumeState.conversation.length,
|
|
19442
19470
|
snapshotApplied: this.resumeState.snapshotApplied,
|
|
19443
19471
|
logEntries: this.resumeState.logEntryCount
|
|
19444
19472
|
});
|
|
19445
19473
|
} catch (error) {
|
|
19446
|
-
this.logger.
|
|
19474
|
+
this.logger.debug("Failed to load resume state, starting fresh", {
|
|
19447
19475
|
error
|
|
19448
19476
|
});
|
|
19449
19477
|
this.resumeState = null;
|
|
@@ -19461,7 +19489,7 @@ var AgentServer = class _AgentServer {
|
|
|
19461
19489
|
await this.initializeSession(payload, null);
|
|
19462
19490
|
}
|
|
19463
19491
|
async stop() {
|
|
19464
|
-
this.logger.
|
|
19492
|
+
this.logger.debug("Stopping agent server...");
|
|
19465
19493
|
if (this.session) {
|
|
19466
19494
|
await this.cleanupSession();
|
|
19467
19495
|
}
|
|
@@ -19469,7 +19497,7 @@ var AgentServer = class _AgentServer {
|
|
|
19469
19497
|
this.server.close();
|
|
19470
19498
|
this.server = null;
|
|
19471
19499
|
}
|
|
19472
|
-
this.logger.
|
|
19500
|
+
this.logger.debug("Agent server stopped");
|
|
19473
19501
|
}
|
|
19474
19502
|
authenticateRequest(getHeader) {
|
|
19475
19503
|
if (!this.config.jwtPublicKey) {
|
|
@@ -19512,7 +19540,7 @@ var AgentServer = class _AgentServer {
|
|
|
19512
19540
|
blockTypes: prompt.map((block) => block.type)
|
|
19513
19541
|
});
|
|
19514
19542
|
const promptPreview = promptBlocksToText(prompt);
|
|
19515
|
-
this.logger.
|
|
19543
|
+
this.logger.debug(
|
|
19516
19544
|
`Processing user message (detectedPrUrl=${this.detectedPrUrl ?? "none"}): ${promptPreview.substring(0, 100)}...`
|
|
19517
19545
|
);
|
|
19518
19546
|
this.session.logWriter.resetTurnMessages(this.session.payload.run_id);
|
|
@@ -19527,7 +19555,7 @@ var AgentServer = class _AgentServer {
|
|
|
19527
19555
|
}
|
|
19528
19556
|
}
|
|
19529
19557
|
});
|
|
19530
|
-
this.logger.
|
|
19558
|
+
this.logger.debug("User message completed", {
|
|
19531
19559
|
stopReason: result.stopReason
|
|
19532
19560
|
});
|
|
19533
19561
|
if (result.stopReason === "end_turn") {
|
|
@@ -19536,7 +19564,7 @@ var AgentServer = class _AgentServer {
|
|
|
19536
19564
|
this.broadcastTurnComplete(result.stopReason);
|
|
19537
19565
|
if (result.stopReason === "end_turn") {
|
|
19538
19566
|
this.relayAgentResponse(this.session.payload).catch(
|
|
19539
|
-
(err2) => this.logger.
|
|
19567
|
+
(err2) => this.logger.debug("Failed to relay follow-up response", err2)
|
|
19540
19568
|
);
|
|
19541
19569
|
}
|
|
19542
19570
|
let assistantMessage;
|
|
@@ -19548,7 +19576,7 @@ var AgentServer = class _AgentServer {
|
|
|
19548
19576
|
this.session.payload.run_id
|
|
19549
19577
|
);
|
|
19550
19578
|
} catch {
|
|
19551
|
-
this.logger.
|
|
19579
|
+
this.logger.debug("Failed to extract assistant message from logs");
|
|
19552
19580
|
}
|
|
19553
19581
|
return {
|
|
19554
19582
|
stopReason: result.stopReason,
|
|
@@ -19557,7 +19585,7 @@ var AgentServer = class _AgentServer {
|
|
|
19557
19585
|
}
|
|
19558
19586
|
case POSTHOG_NOTIFICATIONS.CANCEL:
|
|
19559
19587
|
case "cancel": {
|
|
19560
|
-
this.logger.
|
|
19588
|
+
this.logger.debug("Cancel requested", {
|
|
19561
19589
|
acpSessionId: this.session.acpSessionId
|
|
19562
19590
|
});
|
|
19563
19591
|
await this.session.clientConnection.cancel({
|
|
@@ -19567,7 +19595,7 @@ var AgentServer = class _AgentServer {
|
|
|
19567
19595
|
}
|
|
19568
19596
|
case POSTHOG_NOTIFICATIONS.CLOSE:
|
|
19569
19597
|
case "close": {
|
|
19570
|
-
this.logger.
|
|
19598
|
+
this.logger.debug("Close requested");
|
|
19571
19599
|
await this.cleanupSession();
|
|
19572
19600
|
return { closed: true };
|
|
19573
19601
|
}
|
|
@@ -19575,7 +19603,7 @@ var AgentServer = class _AgentServer {
|
|
|
19575
19603
|
case "set_config_option": {
|
|
19576
19604
|
const configId = params.configId;
|
|
19577
19605
|
const value = params.value;
|
|
19578
|
-
this.logger.
|
|
19606
|
+
this.logger.debug("Set config option requested", { configId, value });
|
|
19579
19607
|
const result = await this.session.clientConnection.setSessionConfigOption({
|
|
19580
19608
|
sessionId: this.session.acpSessionId,
|
|
19581
19609
|
configId,
|
|
@@ -19603,7 +19631,7 @@ var AgentServer = class _AgentServer {
|
|
|
19603
19631
|
const optionId = params.optionId;
|
|
19604
19632
|
const customInput = params.customInput;
|
|
19605
19633
|
const answers = params.answers;
|
|
19606
|
-
this.logger.
|
|
19634
|
+
this.logger.debug("Permission response received", {
|
|
19607
19635
|
requestId,
|
|
19608
19636
|
optionId
|
|
19609
19637
|
});
|
|
@@ -19626,7 +19654,7 @@ var AgentServer = class _AgentServer {
|
|
|
19626
19654
|
}
|
|
19627
19655
|
async initializeSession(payload, sseController) {
|
|
19628
19656
|
if (this.initializationPromise) {
|
|
19629
|
-
this.logger.
|
|
19657
|
+
this.logger.debug("Waiting for in-progress initialization", {
|
|
19630
19658
|
runId: payload.run_id
|
|
19631
19659
|
});
|
|
19632
19660
|
await this.initializationPromise;
|
|
@@ -19651,7 +19679,7 @@ var AgentServer = class _AgentServer {
|
|
|
19651
19679
|
if (this.session) {
|
|
19652
19680
|
await this.cleanupSession();
|
|
19653
19681
|
}
|
|
19654
|
-
this.logger.
|
|
19682
|
+
this.logger.debug("Initializing session", {
|
|
19655
19683
|
runId: payload.run_id,
|
|
19656
19684
|
taskId: payload.task_id
|
|
19657
19685
|
});
|
|
@@ -19662,7 +19690,7 @@ var AgentServer = class _AgentServer {
|
|
|
19662
19690
|
this.configureEnvironment();
|
|
19663
19691
|
const [preTaskRun, preTask] = await Promise.all([
|
|
19664
19692
|
this.posthogAPI.getTaskRun(payload.task_id, payload.run_id).catch((err2) => {
|
|
19665
|
-
this.logger.
|
|
19693
|
+
this.logger.debug("Failed to fetch task run for session context", {
|
|
19666
19694
|
taskId: payload.task_id,
|
|
19667
19695
|
runId: payload.run_id,
|
|
19668
19696
|
error: err2
|
|
@@ -19670,7 +19698,7 @@ var AgentServer = class _AgentServer {
|
|
|
19670
19698
|
return null;
|
|
19671
19699
|
}),
|
|
19672
19700
|
this.posthogAPI.getTask(payload.task_id).catch((err2) => {
|
|
19673
|
-
this.logger.
|
|
19701
|
+
this.logger.debug("Failed to fetch task for session context", {
|
|
19674
19702
|
taskId: payload.task_id,
|
|
19675
19703
|
error: err2
|
|
19676
19704
|
});
|
|
@@ -19780,7 +19808,7 @@ var AgentServer = class _AgentServer {
|
|
|
19780
19808
|
}
|
|
19781
19809
|
});
|
|
19782
19810
|
const acpSessionId = sessionResponse.sessionId;
|
|
19783
|
-
this.logger.
|
|
19811
|
+
this.logger.debug("ACP session created", {
|
|
19784
19812
|
acpSessionId,
|
|
19785
19813
|
runId: payload.run_id
|
|
19786
19814
|
});
|
|
@@ -19800,22 +19828,38 @@ var AgentServer = class _AgentServer {
|
|
|
19800
19828
|
debug: true,
|
|
19801
19829
|
prefix: "[AgentServer]",
|
|
19802
19830
|
onLog: (level, scope, message, data) => {
|
|
19803
|
-
const _formatted = data !== void 0 ? `${message} ${JSON.stringify(data)}` : message;
|
|
19804
19831
|
this.emitConsoleLog(level, scope, message, data);
|
|
19805
19832
|
}
|
|
19806
19833
|
});
|
|
19807
|
-
this.logger.
|
|
19808
|
-
this.logger.
|
|
19834
|
+
this.logger.debug("Session initialized successfully");
|
|
19835
|
+
this.logger.debug(
|
|
19809
19836
|
`Agent version: ${this.config.version ?? package_default.version}`
|
|
19810
19837
|
);
|
|
19811
|
-
this.logger.
|
|
19838
|
+
this.logger.debug(`Initial permission mode: ${initialPermissionMode}`);
|
|
19812
19839
|
this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
19813
19840
|
status: "in_progress"
|
|
19814
19841
|
}).catch(
|
|
19815
|
-
(err2) => this.logger.
|
|
19842
|
+
(err2) => this.logger.debug("Failed to set task run to in_progress", err2)
|
|
19816
19843
|
);
|
|
19817
19844
|
await this.sendInitialTaskMessage(payload, preTaskRun);
|
|
19818
19845
|
}
|
|
19846
|
+
extractErrorClassification(error) {
|
|
19847
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
19848
|
+
const parsed = errorWithClassificationSchema.safeParse(error);
|
|
19849
|
+
if (parsed.success) {
|
|
19850
|
+
return { classification: parsed.data.data.classification, message };
|
|
19851
|
+
}
|
|
19852
|
+
return { classification: classifyAgentError(message), message };
|
|
19853
|
+
}
|
|
19854
|
+
classifyAndSignalFailure(payload, phase, error) {
|
|
19855
|
+
const { classification, message } = this.extractErrorClassification(error);
|
|
19856
|
+
const errorMessage = classification === "upstream_stream_terminated" ? "Upstream LLM stream terminated" : classification === "upstream_connection_error" ? "Upstream LLM connection error" : message || "Agent error";
|
|
19857
|
+
this.logger.error(`send_${phase}_task_message_failed`, {
|
|
19858
|
+
classification,
|
|
19859
|
+
message
|
|
19860
|
+
});
|
|
19861
|
+
return this.signalTaskComplete(payload, "error", errorMessage);
|
|
19862
|
+
}
|
|
19819
19863
|
async sendInitialTaskMessage(payload, prefetchedRun) {
|
|
19820
19864
|
if (!this.session) return;
|
|
19821
19865
|
let taskRun = prefetchedRun ?? null;
|
|
@@ -19826,7 +19870,7 @@ var AgentServer = class _AgentServer {
|
|
|
19826
19870
|
payload.run_id
|
|
19827
19871
|
);
|
|
19828
19872
|
} catch (error) {
|
|
19829
|
-
this.logger.
|
|
19873
|
+
this.logger.debug("Failed to fetch task run", {
|
|
19830
19874
|
taskId: payload.task_id,
|
|
19831
19875
|
runId: payload.run_id,
|
|
19832
19876
|
error
|
|
@@ -19836,7 +19880,7 @@ var AgentServer = class _AgentServer {
|
|
|
19836
19880
|
if (!this.resumeState) {
|
|
19837
19881
|
const resumeRunId = this.getResumeRunId(taskRun);
|
|
19838
19882
|
if (resumeRunId) {
|
|
19839
|
-
this.logger.
|
|
19883
|
+
this.logger.debug("Resuming from previous run (via TaskRun state)", {
|
|
19840
19884
|
resumeRunId,
|
|
19841
19885
|
currentRunId: payload.run_id
|
|
19842
19886
|
});
|
|
@@ -19848,13 +19892,13 @@ var AgentServer = class _AgentServer {
|
|
|
19848
19892
|
apiClient: this.posthogAPI,
|
|
19849
19893
|
logger: new Logger({ debug: true, prefix: "[Resume]" })
|
|
19850
19894
|
});
|
|
19851
|
-
this.logger.
|
|
19895
|
+
this.logger.debug("Resume state loaded (via TaskRun state)", {
|
|
19852
19896
|
conversationTurns: this.resumeState.conversation.length,
|
|
19853
19897
|
snapshotApplied: this.resumeState.snapshotApplied,
|
|
19854
19898
|
logEntries: this.resumeState.logEntryCount
|
|
19855
19899
|
});
|
|
19856
19900
|
} catch (error) {
|
|
19857
|
-
this.logger.
|
|
19901
|
+
this.logger.debug("Failed to load resume state, starting fresh", {
|
|
19858
19902
|
error
|
|
19859
19903
|
});
|
|
19860
19904
|
this.resumeState = null;
|
|
@@ -19878,10 +19922,10 @@ var AgentServer = class _AgentServer {
|
|
|
19878
19922
|
initialPrompt = [{ type: "text", text: task.description }];
|
|
19879
19923
|
}
|
|
19880
19924
|
if (initialPrompt.length === 0) {
|
|
19881
|
-
this.logger.
|
|
19925
|
+
this.logger.debug("Task has no description, skipping initial message");
|
|
19882
19926
|
return;
|
|
19883
19927
|
}
|
|
19884
|
-
this.logger.
|
|
19928
|
+
this.logger.debug("Sending initial task message", {
|
|
19885
19929
|
taskId: payload.task_id,
|
|
19886
19930
|
descriptionLength: promptBlocksToText(initialPrompt).length,
|
|
19887
19931
|
usedInitialPromptOverride: !!initialPromptOverride,
|
|
@@ -19892,7 +19936,7 @@ var AgentServer = class _AgentServer {
|
|
|
19892
19936
|
sessionId: this.session.acpSessionId,
|
|
19893
19937
|
prompt: initialPrompt
|
|
19894
19938
|
});
|
|
19895
|
-
this.logger.
|
|
19939
|
+
this.logger.debug("Initial task message completed", {
|
|
19896
19940
|
stopReason: result.stopReason
|
|
19897
19941
|
});
|
|
19898
19942
|
await this.clearPendingInitialPromptState(payload, taskRun);
|
|
@@ -19908,7 +19952,7 @@ var AgentServer = class _AgentServer {
|
|
|
19908
19952
|
if (this.session) {
|
|
19909
19953
|
await this.session.logWriter.flushAll();
|
|
19910
19954
|
}
|
|
19911
|
-
await this.
|
|
19955
|
+
await this.classifyAndSignalFailure(payload, "initial", error);
|
|
19912
19956
|
}
|
|
19913
19957
|
}
|
|
19914
19958
|
async sendResumeMessage(payload, taskRun) {
|
|
@@ -19954,7 +19998,7 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
19954
19998
|
}
|
|
19955
19999
|
];
|
|
19956
20000
|
}
|
|
19957
|
-
this.logger.
|
|
20001
|
+
this.logger.debug("Sending resume message", {
|
|
19958
20002
|
taskId: payload.task_id,
|
|
19959
20003
|
conversationTurns: this.resumeState.conversation.length,
|
|
19960
20004
|
promptLength: promptBlocksToText(resumePromptBlocks).length,
|
|
@@ -19967,7 +20011,7 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
19967
20011
|
sessionId: this.session.acpSessionId,
|
|
19968
20012
|
prompt: resumePromptBlocks
|
|
19969
20013
|
});
|
|
19970
|
-
this.logger.
|
|
20014
|
+
this.logger.debug("Resume message completed", {
|
|
19971
20015
|
stopReason: result.stopReason
|
|
19972
20016
|
});
|
|
19973
20017
|
if (result.stopReason === "end_turn") {
|
|
@@ -19982,7 +20026,7 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
19982
20026
|
if (this.session) {
|
|
19983
20027
|
await this.session.logWriter.flushAll();
|
|
19984
20028
|
}
|
|
19985
|
-
await this.
|
|
20029
|
+
await this.classifyAndSignalFailure(payload, "resume", error);
|
|
19986
20030
|
}
|
|
19987
20031
|
}
|
|
19988
20032
|
static RESUME_HISTORY_TOKEN_BUDGET = 5e4;
|
|
@@ -20313,7 +20357,7 @@ ${attributionInstructions}
|
|
|
20313
20357
|
try {
|
|
20314
20358
|
return await getCurrentBranch(this.config.repositoryPath);
|
|
20315
20359
|
} catch (error) {
|
|
20316
|
-
this.logger.
|
|
20360
|
+
this.logger.debug("Failed to determine current git branch", {
|
|
20317
20361
|
repositoryPath: this.config.repositoryPath,
|
|
20318
20362
|
error
|
|
20319
20363
|
});
|
|
@@ -20332,7 +20376,7 @@ ${attributionInstructions}
|
|
|
20332
20376
|
});
|
|
20333
20377
|
this.lastReportedBranch = branchName;
|
|
20334
20378
|
} catch (error) {
|
|
20335
|
-
this.logger.
|
|
20379
|
+
this.logger.debug("Failed to attach current branch to task run", {
|
|
20336
20380
|
taskId: payload.task_id,
|
|
20337
20381
|
runId: payload.run_id,
|
|
20338
20382
|
branchName,
|
|
@@ -20340,14 +20384,14 @@ ${attributionInstructions}
|
|
|
20340
20384
|
});
|
|
20341
20385
|
}
|
|
20342
20386
|
}
|
|
20343
|
-
async signalTaskComplete(payload, stopReason) {
|
|
20387
|
+
async signalTaskComplete(payload, stopReason, errorMessage) {
|
|
20344
20388
|
if (this.session?.payload.run_id === payload.run_id) {
|
|
20345
20389
|
try {
|
|
20346
20390
|
await this.session.logWriter.flush(payload.run_id, {
|
|
20347
20391
|
coalesce: true
|
|
20348
20392
|
});
|
|
20349
20393
|
} catch (error) {
|
|
20350
|
-
this.logger.
|
|
20394
|
+
this.logger.debug("Failed to flush session logs before completion", {
|
|
20351
20395
|
taskId: payload.task_id,
|
|
20352
20396
|
runId: payload.run_id,
|
|
20353
20397
|
error
|
|
@@ -20355,7 +20399,7 @@ ${attributionInstructions}
|
|
|
20355
20399
|
}
|
|
20356
20400
|
}
|
|
20357
20401
|
if (stopReason !== "error") {
|
|
20358
|
-
this.logger.
|
|
20402
|
+
this.logger.debug("Skipping status update for non-error stop reason", {
|
|
20359
20403
|
stopReason
|
|
20360
20404
|
});
|
|
20361
20405
|
return;
|
|
@@ -20364,9 +20408,9 @@ ${attributionInstructions}
|
|
|
20364
20408
|
try {
|
|
20365
20409
|
await this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
20366
20410
|
status,
|
|
20367
|
-
error_message:
|
|
20411
|
+
error_message: errorMessage ?? "Agent error"
|
|
20368
20412
|
});
|
|
20369
|
-
this.logger.
|
|
20413
|
+
this.logger.debug("Task completion signaled", { status, stopReason });
|
|
20370
20414
|
} catch (error) {
|
|
20371
20415
|
this.logger.error("Failed to signal task completion", error);
|
|
20372
20416
|
}
|
|
@@ -20445,7 +20489,7 @@ ${attributionInstructions}
|
|
|
20445
20489
|
const sessionPermissionMode = this.getSessionPermissionMode();
|
|
20446
20490
|
const needsDesktopApproval = isQuestion || this.shouldRelayPermissionToClient(sessionPermissionMode);
|
|
20447
20491
|
if (isPlanApproval || needsDesktopApproval && this.session?.hasDesktopConnected) {
|
|
20448
|
-
this.logger.
|
|
20492
|
+
this.logger.debug("Relaying permission request", {
|
|
20449
20493
|
kind: params.toolCall?.kind,
|
|
20450
20494
|
isQuestion,
|
|
20451
20495
|
hasDesktopConnected: this.session?.hasDesktopConnected ?? false,
|
|
@@ -20475,7 +20519,7 @@ ${attributionInstructions}
|
|
|
20475
20519
|
sessionUpdate: async (params) => {
|
|
20476
20520
|
if (params.update?.sessionUpdate === "current_mode_update" && typeof params.update?.currentModeId === "string" && this.session) {
|
|
20477
20521
|
this.session.permissionMode = params.update.currentModeId;
|
|
20478
|
-
this.logger.
|
|
20522
|
+
this.logger.debug("Permission mode updated", {
|
|
20479
20523
|
mode: params.update.currentModeId
|
|
20480
20524
|
});
|
|
20481
20525
|
}
|
|
@@ -20504,7 +20548,7 @@ ${attributionInstructions}
|
|
|
20504
20548
|
try {
|
|
20505
20549
|
await this.session.logWriter.flush(payload.run_id, { coalesce: true });
|
|
20506
20550
|
} catch (error) {
|
|
20507
|
-
this.logger.
|
|
20551
|
+
this.logger.debug("Failed to flush logs before Slack relay", {
|
|
20508
20552
|
taskId: payload.task_id,
|
|
20509
20553
|
runId: payload.run_id,
|
|
20510
20554
|
error
|
|
@@ -20512,7 +20556,7 @@ ${attributionInstructions}
|
|
|
20512
20556
|
}
|
|
20513
20557
|
const message = this.session.logWriter.getFullAgentResponse(payload.run_id);
|
|
20514
20558
|
if (!message) {
|
|
20515
|
-
this.logger.
|
|
20559
|
+
this.logger.debug("No agent message found for Slack relay", {
|
|
20516
20560
|
taskId: payload.task_id,
|
|
20517
20561
|
runId: payload.run_id,
|
|
20518
20562
|
sessionRegistered: this.session.logWriter.isRegistered(payload.run_id)
|
|
@@ -20526,7 +20570,7 @@ ${attributionInstructions}
|
|
|
20526
20570
|
message
|
|
20527
20571
|
);
|
|
20528
20572
|
} catch (error) {
|
|
20529
|
-
this.logger.
|
|
20573
|
+
this.logger.debug("Failed to relay initial agent response to Slack", {
|
|
20530
20574
|
taskId: payload.task_id,
|
|
20531
20575
|
runId: payload.run_id,
|
|
20532
20576
|
error
|
|
@@ -20553,7 +20597,7 @@ ${attributionInstructions}
|
|
|
20553
20597
|
message += "\nReply in this thread with your choice.";
|
|
20554
20598
|
this.questionRelayedToSlack = true;
|
|
20555
20599
|
this.posthogAPI.relayMessage(payload.task_id, payload.run_id, message).catch(
|
|
20556
|
-
(err2) => this.logger.
|
|
20600
|
+
(err2) => this.logger.debug("Failed to relay question to Slack", { err: err2 })
|
|
20557
20601
|
);
|
|
20558
20602
|
}
|
|
20559
20603
|
getFirstQuestionMeta(toolMeta2) {
|
|
@@ -20615,14 +20659,14 @@ ${attributionInstructions}
|
|
|
20615
20659
|
if (!prUrlMatch) return;
|
|
20616
20660
|
const prUrl = prUrlMatch[0];
|
|
20617
20661
|
this.detectedPrUrl = prUrl;
|
|
20618
|
-
this.logger.
|
|
20662
|
+
this.logger.debug("Detected PR URL in bash output", {
|
|
20619
20663
|
runId: payload.run_id,
|
|
20620
20664
|
prUrl
|
|
20621
20665
|
});
|
|
20622
20666
|
this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
20623
20667
|
output: { pr_url: prUrl }
|
|
20624
20668
|
}).then(() => {
|
|
20625
|
-
this.logger.
|
|
20669
|
+
this.logger.debug("PR URL attached to task run", {
|
|
20626
20670
|
taskId: payload.task_id,
|
|
20627
20671
|
runId: payload.run_id,
|
|
20628
20672
|
prUrl
|
|
@@ -20644,7 +20688,7 @@ ${attributionInstructions}
|
|
|
20644
20688
|
}
|
|
20645
20689
|
async cleanupSession() {
|
|
20646
20690
|
if (!this.session) return;
|
|
20647
|
-
this.logger.
|
|
20691
|
+
this.logger.debug("Cleaning up session");
|
|
20648
20692
|
try {
|
|
20649
20693
|
await this.captureTreeState();
|
|
20650
20694
|
} catch (error) {
|