@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
|
@@ -8599,11 +8599,12 @@ async function getHeadSha(baseDir, options) {
|
|
|
8599
8599
|
|
|
8600
8600
|
// src/server/agent-server.ts
|
|
8601
8601
|
import { Hono } from "hono";
|
|
8602
|
+
import { z as z4 } from "zod";
|
|
8602
8603
|
|
|
8603
8604
|
// package.json
|
|
8604
8605
|
var package_default = {
|
|
8605
8606
|
name: "@posthog/agent",
|
|
8606
|
-
version: "2.3.
|
|
8607
|
+
version: "2.3.356",
|
|
8607
8608
|
repository: "https://github.com/PostHog/code",
|
|
8608
8609
|
description: "TypeScript agent framework wrapping Claude Agent SDK with Git-based task execution for PostHog",
|
|
8609
8610
|
exports: {
|
|
@@ -8764,6 +8765,8 @@ var POSTHOG_NOTIFICATIONS = {
|
|
|
8764
8765
|
CLOSE: "_posthog/close",
|
|
8765
8766
|
/** Agent status update (thinking, working, etc.) */
|
|
8766
8767
|
STATUS: "_posthog/status",
|
|
8768
|
+
/** Structured backend progress notification; events in the same turn group into one card on the client */
|
|
8769
|
+
PROGRESS: "_posthog/progress",
|
|
8767
8770
|
/** Task-level notification (progress, milestones) */
|
|
8768
8771
|
TASK_NOTIFICATION: "_posthog/task_notification",
|
|
8769
8772
|
/** Marks a boundary for log compaction */
|
|
@@ -13764,6 +13767,17 @@ async function handleSystemMessage(message, context) {
|
|
|
13764
13767
|
break;
|
|
13765
13768
|
}
|
|
13766
13769
|
}
|
|
13770
|
+
function classifyAgentError(result) {
|
|
13771
|
+
if (!result) return "agent_error";
|
|
13772
|
+
const text2 = result.trim();
|
|
13773
|
+
if (/API Error:\s*terminated\b/i.test(text2)) {
|
|
13774
|
+
return "upstream_stream_terminated";
|
|
13775
|
+
}
|
|
13776
|
+
if (/API Error:\s*Connection error\b/i.test(text2)) {
|
|
13777
|
+
return "upstream_connection_error";
|
|
13778
|
+
}
|
|
13779
|
+
return "agent_error";
|
|
13780
|
+
}
|
|
13767
13781
|
function handleResultMessage(message) {
|
|
13768
13782
|
const usage = extractUsageFromResult(message);
|
|
13769
13783
|
switch (message.subtype) {
|
|
@@ -13779,9 +13793,13 @@ function handleResultMessage(message) {
|
|
|
13779
13793
|
return { shouldStop: true, stopReason: "max_tokens", usage };
|
|
13780
13794
|
}
|
|
13781
13795
|
if (message.is_error) {
|
|
13796
|
+
const classification = classifyAgentError(message.result);
|
|
13782
13797
|
return {
|
|
13783
13798
|
shouldStop: true,
|
|
13784
|
-
error: RequestError.internalError(
|
|
13799
|
+
error: RequestError.internalError(
|
|
13800
|
+
{ classification, result: message.result },
|
|
13801
|
+
message.result
|
|
13802
|
+
),
|
|
13785
13803
|
usage
|
|
13786
13804
|
};
|
|
13787
13805
|
}
|
|
@@ -19106,6 +19124,14 @@ function validateCommandParams(method, params) {
|
|
|
19106
19124
|
}
|
|
19107
19125
|
|
|
19108
19126
|
// src/server/agent-server.ts
|
|
19127
|
+
var agentErrorClassificationSchema = z4.enum([
|
|
19128
|
+
"upstream_stream_terminated",
|
|
19129
|
+
"upstream_connection_error",
|
|
19130
|
+
"agent_error"
|
|
19131
|
+
]);
|
|
19132
|
+
var errorWithClassificationSchema = z4.object({
|
|
19133
|
+
data: z4.object({ classification: agentErrorClassificationSchema })
|
|
19134
|
+
});
|
|
19109
19135
|
var NdJsonTap = class {
|
|
19110
19136
|
constructor(onMessage) {
|
|
19111
19137
|
this.onMessage = onMessage;
|
|
@@ -19405,7 +19431,9 @@ var AgentServer = class _AgentServer {
|
|
|
19405
19431
|
port: this.config.port
|
|
19406
19432
|
},
|
|
19407
19433
|
() => {
|
|
19408
|
-
this.logger.
|
|
19434
|
+
this.logger.debug(
|
|
19435
|
+
`HTTP server listening on port ${this.config.port}`
|
|
19436
|
+
);
|
|
19409
19437
|
resolve4();
|
|
19410
19438
|
}
|
|
19411
19439
|
);
|
|
@@ -19414,10 +19442,10 @@ var AgentServer = class _AgentServer {
|
|
|
19414
19442
|
}
|
|
19415
19443
|
async autoInitializeSession() {
|
|
19416
19444
|
const { taskId, runId, mode, projectId } = this.config;
|
|
19417
|
-
this.logger.
|
|
19445
|
+
this.logger.debug("Auto-initializing session", { taskId, runId, mode });
|
|
19418
19446
|
const resumeRunId = process.env.POSTHOG_RESUME_RUN_ID;
|
|
19419
19447
|
if (resumeRunId) {
|
|
19420
|
-
this.logger.
|
|
19448
|
+
this.logger.debug("Resuming from previous run", {
|
|
19421
19449
|
resumeRunId,
|
|
19422
19450
|
currentRunId: runId
|
|
19423
19451
|
});
|
|
@@ -19429,13 +19457,13 @@ var AgentServer = class _AgentServer {
|
|
|
19429
19457
|
apiClient: this.posthogAPI,
|
|
19430
19458
|
logger: new Logger({ debug: true, prefix: "[Resume]" })
|
|
19431
19459
|
});
|
|
19432
|
-
this.logger.
|
|
19460
|
+
this.logger.debug("Resume state loaded", {
|
|
19433
19461
|
conversationTurns: this.resumeState.conversation.length,
|
|
19434
19462
|
snapshotApplied: this.resumeState.snapshotApplied,
|
|
19435
19463
|
logEntries: this.resumeState.logEntryCount
|
|
19436
19464
|
});
|
|
19437
19465
|
} catch (error) {
|
|
19438
|
-
this.logger.
|
|
19466
|
+
this.logger.debug("Failed to load resume state, starting fresh", {
|
|
19439
19467
|
error
|
|
19440
19468
|
});
|
|
19441
19469
|
this.resumeState = null;
|
|
@@ -19453,7 +19481,7 @@ var AgentServer = class _AgentServer {
|
|
|
19453
19481
|
await this.initializeSession(payload, null);
|
|
19454
19482
|
}
|
|
19455
19483
|
async stop() {
|
|
19456
|
-
this.logger.
|
|
19484
|
+
this.logger.debug("Stopping agent server...");
|
|
19457
19485
|
if (this.session) {
|
|
19458
19486
|
await this.cleanupSession();
|
|
19459
19487
|
}
|
|
@@ -19461,7 +19489,7 @@ var AgentServer = class _AgentServer {
|
|
|
19461
19489
|
this.server.close();
|
|
19462
19490
|
this.server = null;
|
|
19463
19491
|
}
|
|
19464
|
-
this.logger.
|
|
19492
|
+
this.logger.debug("Agent server stopped");
|
|
19465
19493
|
}
|
|
19466
19494
|
authenticateRequest(getHeader) {
|
|
19467
19495
|
if (!this.config.jwtPublicKey) {
|
|
@@ -19504,7 +19532,7 @@ var AgentServer = class _AgentServer {
|
|
|
19504
19532
|
blockTypes: prompt.map((block) => block.type)
|
|
19505
19533
|
});
|
|
19506
19534
|
const promptPreview = promptBlocksToText(prompt);
|
|
19507
|
-
this.logger.
|
|
19535
|
+
this.logger.debug(
|
|
19508
19536
|
`Processing user message (detectedPrUrl=${this.detectedPrUrl ?? "none"}): ${promptPreview.substring(0, 100)}...`
|
|
19509
19537
|
);
|
|
19510
19538
|
this.session.logWriter.resetTurnMessages(this.session.payload.run_id);
|
|
@@ -19519,7 +19547,7 @@ var AgentServer = class _AgentServer {
|
|
|
19519
19547
|
}
|
|
19520
19548
|
}
|
|
19521
19549
|
});
|
|
19522
|
-
this.logger.
|
|
19550
|
+
this.logger.debug("User message completed", {
|
|
19523
19551
|
stopReason: result.stopReason
|
|
19524
19552
|
});
|
|
19525
19553
|
if (result.stopReason === "end_turn") {
|
|
@@ -19528,7 +19556,7 @@ var AgentServer = class _AgentServer {
|
|
|
19528
19556
|
this.broadcastTurnComplete(result.stopReason);
|
|
19529
19557
|
if (result.stopReason === "end_turn") {
|
|
19530
19558
|
this.relayAgentResponse(this.session.payload).catch(
|
|
19531
|
-
(err2) => this.logger.
|
|
19559
|
+
(err2) => this.logger.debug("Failed to relay follow-up response", err2)
|
|
19532
19560
|
);
|
|
19533
19561
|
}
|
|
19534
19562
|
let assistantMessage;
|
|
@@ -19540,7 +19568,7 @@ var AgentServer = class _AgentServer {
|
|
|
19540
19568
|
this.session.payload.run_id
|
|
19541
19569
|
);
|
|
19542
19570
|
} catch {
|
|
19543
|
-
this.logger.
|
|
19571
|
+
this.logger.debug("Failed to extract assistant message from logs");
|
|
19544
19572
|
}
|
|
19545
19573
|
return {
|
|
19546
19574
|
stopReason: result.stopReason,
|
|
@@ -19549,7 +19577,7 @@ var AgentServer = class _AgentServer {
|
|
|
19549
19577
|
}
|
|
19550
19578
|
case POSTHOG_NOTIFICATIONS.CANCEL:
|
|
19551
19579
|
case "cancel": {
|
|
19552
|
-
this.logger.
|
|
19580
|
+
this.logger.debug("Cancel requested", {
|
|
19553
19581
|
acpSessionId: this.session.acpSessionId
|
|
19554
19582
|
});
|
|
19555
19583
|
await this.session.clientConnection.cancel({
|
|
@@ -19559,7 +19587,7 @@ var AgentServer = class _AgentServer {
|
|
|
19559
19587
|
}
|
|
19560
19588
|
case POSTHOG_NOTIFICATIONS.CLOSE:
|
|
19561
19589
|
case "close": {
|
|
19562
|
-
this.logger.
|
|
19590
|
+
this.logger.debug("Close requested");
|
|
19563
19591
|
await this.cleanupSession();
|
|
19564
19592
|
return { closed: true };
|
|
19565
19593
|
}
|
|
@@ -19567,7 +19595,7 @@ var AgentServer = class _AgentServer {
|
|
|
19567
19595
|
case "set_config_option": {
|
|
19568
19596
|
const configId = params.configId;
|
|
19569
19597
|
const value = params.value;
|
|
19570
|
-
this.logger.
|
|
19598
|
+
this.logger.debug("Set config option requested", { configId, value });
|
|
19571
19599
|
const result = await this.session.clientConnection.setSessionConfigOption({
|
|
19572
19600
|
sessionId: this.session.acpSessionId,
|
|
19573
19601
|
configId,
|
|
@@ -19595,7 +19623,7 @@ var AgentServer = class _AgentServer {
|
|
|
19595
19623
|
const optionId = params.optionId;
|
|
19596
19624
|
const customInput = params.customInput;
|
|
19597
19625
|
const answers = params.answers;
|
|
19598
|
-
this.logger.
|
|
19626
|
+
this.logger.debug("Permission response received", {
|
|
19599
19627
|
requestId,
|
|
19600
19628
|
optionId
|
|
19601
19629
|
});
|
|
@@ -19618,7 +19646,7 @@ var AgentServer = class _AgentServer {
|
|
|
19618
19646
|
}
|
|
19619
19647
|
async initializeSession(payload, sseController) {
|
|
19620
19648
|
if (this.initializationPromise) {
|
|
19621
|
-
this.logger.
|
|
19649
|
+
this.logger.debug("Waiting for in-progress initialization", {
|
|
19622
19650
|
runId: payload.run_id
|
|
19623
19651
|
});
|
|
19624
19652
|
await this.initializationPromise;
|
|
@@ -19643,7 +19671,7 @@ var AgentServer = class _AgentServer {
|
|
|
19643
19671
|
if (this.session) {
|
|
19644
19672
|
await this.cleanupSession();
|
|
19645
19673
|
}
|
|
19646
|
-
this.logger.
|
|
19674
|
+
this.logger.debug("Initializing session", {
|
|
19647
19675
|
runId: payload.run_id,
|
|
19648
19676
|
taskId: payload.task_id
|
|
19649
19677
|
});
|
|
@@ -19654,7 +19682,7 @@ var AgentServer = class _AgentServer {
|
|
|
19654
19682
|
this.configureEnvironment();
|
|
19655
19683
|
const [preTaskRun, preTask] = await Promise.all([
|
|
19656
19684
|
this.posthogAPI.getTaskRun(payload.task_id, payload.run_id).catch((err2) => {
|
|
19657
|
-
this.logger.
|
|
19685
|
+
this.logger.debug("Failed to fetch task run for session context", {
|
|
19658
19686
|
taskId: payload.task_id,
|
|
19659
19687
|
runId: payload.run_id,
|
|
19660
19688
|
error: err2
|
|
@@ -19662,7 +19690,7 @@ var AgentServer = class _AgentServer {
|
|
|
19662
19690
|
return null;
|
|
19663
19691
|
}),
|
|
19664
19692
|
this.posthogAPI.getTask(payload.task_id).catch((err2) => {
|
|
19665
|
-
this.logger.
|
|
19693
|
+
this.logger.debug("Failed to fetch task for session context", {
|
|
19666
19694
|
taskId: payload.task_id,
|
|
19667
19695
|
error: err2
|
|
19668
19696
|
});
|
|
@@ -19772,7 +19800,7 @@ var AgentServer = class _AgentServer {
|
|
|
19772
19800
|
}
|
|
19773
19801
|
});
|
|
19774
19802
|
const acpSessionId = sessionResponse.sessionId;
|
|
19775
|
-
this.logger.
|
|
19803
|
+
this.logger.debug("ACP session created", {
|
|
19776
19804
|
acpSessionId,
|
|
19777
19805
|
runId: payload.run_id
|
|
19778
19806
|
});
|
|
@@ -19792,22 +19820,38 @@ var AgentServer = class _AgentServer {
|
|
|
19792
19820
|
debug: true,
|
|
19793
19821
|
prefix: "[AgentServer]",
|
|
19794
19822
|
onLog: (level, scope, message, data) => {
|
|
19795
|
-
const _formatted = data !== void 0 ? `${message} ${JSON.stringify(data)}` : message;
|
|
19796
19823
|
this.emitConsoleLog(level, scope, message, data);
|
|
19797
19824
|
}
|
|
19798
19825
|
});
|
|
19799
|
-
this.logger.
|
|
19800
|
-
this.logger.
|
|
19826
|
+
this.logger.debug("Session initialized successfully");
|
|
19827
|
+
this.logger.debug(
|
|
19801
19828
|
`Agent version: ${this.config.version ?? package_default.version}`
|
|
19802
19829
|
);
|
|
19803
|
-
this.logger.
|
|
19830
|
+
this.logger.debug(`Initial permission mode: ${initialPermissionMode}`);
|
|
19804
19831
|
this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
19805
19832
|
status: "in_progress"
|
|
19806
19833
|
}).catch(
|
|
19807
|
-
(err2) => this.logger.
|
|
19834
|
+
(err2) => this.logger.debug("Failed to set task run to in_progress", err2)
|
|
19808
19835
|
);
|
|
19809
19836
|
await this.sendInitialTaskMessage(payload, preTaskRun);
|
|
19810
19837
|
}
|
|
19838
|
+
extractErrorClassification(error) {
|
|
19839
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
19840
|
+
const parsed = errorWithClassificationSchema.safeParse(error);
|
|
19841
|
+
if (parsed.success) {
|
|
19842
|
+
return { classification: parsed.data.data.classification, message };
|
|
19843
|
+
}
|
|
19844
|
+
return { classification: classifyAgentError(message), message };
|
|
19845
|
+
}
|
|
19846
|
+
classifyAndSignalFailure(payload, phase, error) {
|
|
19847
|
+
const { classification, message } = this.extractErrorClassification(error);
|
|
19848
|
+
const errorMessage = classification === "upstream_stream_terminated" ? "Upstream LLM stream terminated" : classification === "upstream_connection_error" ? "Upstream LLM connection error" : message || "Agent error";
|
|
19849
|
+
this.logger.error(`send_${phase}_task_message_failed`, {
|
|
19850
|
+
classification,
|
|
19851
|
+
message
|
|
19852
|
+
});
|
|
19853
|
+
return this.signalTaskComplete(payload, "error", errorMessage);
|
|
19854
|
+
}
|
|
19811
19855
|
async sendInitialTaskMessage(payload, prefetchedRun) {
|
|
19812
19856
|
if (!this.session) return;
|
|
19813
19857
|
let taskRun = prefetchedRun ?? null;
|
|
@@ -19818,7 +19862,7 @@ var AgentServer = class _AgentServer {
|
|
|
19818
19862
|
payload.run_id
|
|
19819
19863
|
);
|
|
19820
19864
|
} catch (error) {
|
|
19821
|
-
this.logger.
|
|
19865
|
+
this.logger.debug("Failed to fetch task run", {
|
|
19822
19866
|
taskId: payload.task_id,
|
|
19823
19867
|
runId: payload.run_id,
|
|
19824
19868
|
error
|
|
@@ -19828,7 +19872,7 @@ var AgentServer = class _AgentServer {
|
|
|
19828
19872
|
if (!this.resumeState) {
|
|
19829
19873
|
const resumeRunId = this.getResumeRunId(taskRun);
|
|
19830
19874
|
if (resumeRunId) {
|
|
19831
|
-
this.logger.
|
|
19875
|
+
this.logger.debug("Resuming from previous run (via TaskRun state)", {
|
|
19832
19876
|
resumeRunId,
|
|
19833
19877
|
currentRunId: payload.run_id
|
|
19834
19878
|
});
|
|
@@ -19840,13 +19884,13 @@ var AgentServer = class _AgentServer {
|
|
|
19840
19884
|
apiClient: this.posthogAPI,
|
|
19841
19885
|
logger: new Logger({ debug: true, prefix: "[Resume]" })
|
|
19842
19886
|
});
|
|
19843
|
-
this.logger.
|
|
19887
|
+
this.logger.debug("Resume state loaded (via TaskRun state)", {
|
|
19844
19888
|
conversationTurns: this.resumeState.conversation.length,
|
|
19845
19889
|
snapshotApplied: this.resumeState.snapshotApplied,
|
|
19846
19890
|
logEntries: this.resumeState.logEntryCount
|
|
19847
19891
|
});
|
|
19848
19892
|
} catch (error) {
|
|
19849
|
-
this.logger.
|
|
19893
|
+
this.logger.debug("Failed to load resume state, starting fresh", {
|
|
19850
19894
|
error
|
|
19851
19895
|
});
|
|
19852
19896
|
this.resumeState = null;
|
|
@@ -19870,10 +19914,10 @@ var AgentServer = class _AgentServer {
|
|
|
19870
19914
|
initialPrompt = [{ type: "text", text: task.description }];
|
|
19871
19915
|
}
|
|
19872
19916
|
if (initialPrompt.length === 0) {
|
|
19873
|
-
this.logger.
|
|
19917
|
+
this.logger.debug("Task has no description, skipping initial message");
|
|
19874
19918
|
return;
|
|
19875
19919
|
}
|
|
19876
|
-
this.logger.
|
|
19920
|
+
this.logger.debug("Sending initial task message", {
|
|
19877
19921
|
taskId: payload.task_id,
|
|
19878
19922
|
descriptionLength: promptBlocksToText(initialPrompt).length,
|
|
19879
19923
|
usedInitialPromptOverride: !!initialPromptOverride,
|
|
@@ -19884,7 +19928,7 @@ var AgentServer = class _AgentServer {
|
|
|
19884
19928
|
sessionId: this.session.acpSessionId,
|
|
19885
19929
|
prompt: initialPrompt
|
|
19886
19930
|
});
|
|
19887
|
-
this.logger.
|
|
19931
|
+
this.logger.debug("Initial task message completed", {
|
|
19888
19932
|
stopReason: result.stopReason
|
|
19889
19933
|
});
|
|
19890
19934
|
await this.clearPendingInitialPromptState(payload, taskRun);
|
|
@@ -19900,7 +19944,7 @@ var AgentServer = class _AgentServer {
|
|
|
19900
19944
|
if (this.session) {
|
|
19901
19945
|
await this.session.logWriter.flushAll();
|
|
19902
19946
|
}
|
|
19903
|
-
await this.
|
|
19947
|
+
await this.classifyAndSignalFailure(payload, "initial", error);
|
|
19904
19948
|
}
|
|
19905
19949
|
}
|
|
19906
19950
|
async sendResumeMessage(payload, taskRun) {
|
|
@@ -19946,7 +19990,7 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
19946
19990
|
}
|
|
19947
19991
|
];
|
|
19948
19992
|
}
|
|
19949
|
-
this.logger.
|
|
19993
|
+
this.logger.debug("Sending resume message", {
|
|
19950
19994
|
taskId: payload.task_id,
|
|
19951
19995
|
conversationTurns: this.resumeState.conversation.length,
|
|
19952
19996
|
promptLength: promptBlocksToText(resumePromptBlocks).length,
|
|
@@ -19959,7 +20003,7 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
19959
20003
|
sessionId: this.session.acpSessionId,
|
|
19960
20004
|
prompt: resumePromptBlocks
|
|
19961
20005
|
});
|
|
19962
|
-
this.logger.
|
|
20006
|
+
this.logger.debug("Resume message completed", {
|
|
19963
20007
|
stopReason: result.stopReason
|
|
19964
20008
|
});
|
|
19965
20009
|
if (result.stopReason === "end_turn") {
|
|
@@ -19974,7 +20018,7 @@ Continue from where you left off. The user is waiting for your response.`
|
|
|
19974
20018
|
if (this.session) {
|
|
19975
20019
|
await this.session.logWriter.flushAll();
|
|
19976
20020
|
}
|
|
19977
|
-
await this.
|
|
20021
|
+
await this.classifyAndSignalFailure(payload, "resume", error);
|
|
19978
20022
|
}
|
|
19979
20023
|
}
|
|
19980
20024
|
static RESUME_HISTORY_TOKEN_BUDGET = 5e4;
|
|
@@ -20305,7 +20349,7 @@ ${attributionInstructions}
|
|
|
20305
20349
|
try {
|
|
20306
20350
|
return await getCurrentBranch(this.config.repositoryPath);
|
|
20307
20351
|
} catch (error) {
|
|
20308
|
-
this.logger.
|
|
20352
|
+
this.logger.debug("Failed to determine current git branch", {
|
|
20309
20353
|
repositoryPath: this.config.repositoryPath,
|
|
20310
20354
|
error
|
|
20311
20355
|
});
|
|
@@ -20324,7 +20368,7 @@ ${attributionInstructions}
|
|
|
20324
20368
|
});
|
|
20325
20369
|
this.lastReportedBranch = branchName;
|
|
20326
20370
|
} catch (error) {
|
|
20327
|
-
this.logger.
|
|
20371
|
+
this.logger.debug("Failed to attach current branch to task run", {
|
|
20328
20372
|
taskId: payload.task_id,
|
|
20329
20373
|
runId: payload.run_id,
|
|
20330
20374
|
branchName,
|
|
@@ -20332,14 +20376,14 @@ ${attributionInstructions}
|
|
|
20332
20376
|
});
|
|
20333
20377
|
}
|
|
20334
20378
|
}
|
|
20335
|
-
async signalTaskComplete(payload, stopReason) {
|
|
20379
|
+
async signalTaskComplete(payload, stopReason, errorMessage) {
|
|
20336
20380
|
if (this.session?.payload.run_id === payload.run_id) {
|
|
20337
20381
|
try {
|
|
20338
20382
|
await this.session.logWriter.flush(payload.run_id, {
|
|
20339
20383
|
coalesce: true
|
|
20340
20384
|
});
|
|
20341
20385
|
} catch (error) {
|
|
20342
|
-
this.logger.
|
|
20386
|
+
this.logger.debug("Failed to flush session logs before completion", {
|
|
20343
20387
|
taskId: payload.task_id,
|
|
20344
20388
|
runId: payload.run_id,
|
|
20345
20389
|
error
|
|
@@ -20347,7 +20391,7 @@ ${attributionInstructions}
|
|
|
20347
20391
|
}
|
|
20348
20392
|
}
|
|
20349
20393
|
if (stopReason !== "error") {
|
|
20350
|
-
this.logger.
|
|
20394
|
+
this.logger.debug("Skipping status update for non-error stop reason", {
|
|
20351
20395
|
stopReason
|
|
20352
20396
|
});
|
|
20353
20397
|
return;
|
|
@@ -20356,9 +20400,9 @@ ${attributionInstructions}
|
|
|
20356
20400
|
try {
|
|
20357
20401
|
await this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
20358
20402
|
status,
|
|
20359
|
-
error_message:
|
|
20403
|
+
error_message: errorMessage ?? "Agent error"
|
|
20360
20404
|
});
|
|
20361
|
-
this.logger.
|
|
20405
|
+
this.logger.debug("Task completion signaled", { status, stopReason });
|
|
20362
20406
|
} catch (error) {
|
|
20363
20407
|
this.logger.error("Failed to signal task completion", error);
|
|
20364
20408
|
}
|
|
@@ -20437,7 +20481,7 @@ ${attributionInstructions}
|
|
|
20437
20481
|
const sessionPermissionMode = this.getSessionPermissionMode();
|
|
20438
20482
|
const needsDesktopApproval = isQuestion || this.shouldRelayPermissionToClient(sessionPermissionMode);
|
|
20439
20483
|
if (isPlanApproval || needsDesktopApproval && this.session?.hasDesktopConnected) {
|
|
20440
|
-
this.logger.
|
|
20484
|
+
this.logger.debug("Relaying permission request", {
|
|
20441
20485
|
kind: params.toolCall?.kind,
|
|
20442
20486
|
isQuestion,
|
|
20443
20487
|
hasDesktopConnected: this.session?.hasDesktopConnected ?? false,
|
|
@@ -20467,7 +20511,7 @@ ${attributionInstructions}
|
|
|
20467
20511
|
sessionUpdate: async (params) => {
|
|
20468
20512
|
if (params.update?.sessionUpdate === "current_mode_update" && typeof params.update?.currentModeId === "string" && this.session) {
|
|
20469
20513
|
this.session.permissionMode = params.update.currentModeId;
|
|
20470
|
-
this.logger.
|
|
20514
|
+
this.logger.debug("Permission mode updated", {
|
|
20471
20515
|
mode: params.update.currentModeId
|
|
20472
20516
|
});
|
|
20473
20517
|
}
|
|
@@ -20496,7 +20540,7 @@ ${attributionInstructions}
|
|
|
20496
20540
|
try {
|
|
20497
20541
|
await this.session.logWriter.flush(payload.run_id, { coalesce: true });
|
|
20498
20542
|
} catch (error) {
|
|
20499
|
-
this.logger.
|
|
20543
|
+
this.logger.debug("Failed to flush logs before Slack relay", {
|
|
20500
20544
|
taskId: payload.task_id,
|
|
20501
20545
|
runId: payload.run_id,
|
|
20502
20546
|
error
|
|
@@ -20504,7 +20548,7 @@ ${attributionInstructions}
|
|
|
20504
20548
|
}
|
|
20505
20549
|
const message = this.session.logWriter.getFullAgentResponse(payload.run_id);
|
|
20506
20550
|
if (!message) {
|
|
20507
|
-
this.logger.
|
|
20551
|
+
this.logger.debug("No agent message found for Slack relay", {
|
|
20508
20552
|
taskId: payload.task_id,
|
|
20509
20553
|
runId: payload.run_id,
|
|
20510
20554
|
sessionRegistered: this.session.logWriter.isRegistered(payload.run_id)
|
|
@@ -20518,7 +20562,7 @@ ${attributionInstructions}
|
|
|
20518
20562
|
message
|
|
20519
20563
|
);
|
|
20520
20564
|
} catch (error) {
|
|
20521
|
-
this.logger.
|
|
20565
|
+
this.logger.debug("Failed to relay initial agent response to Slack", {
|
|
20522
20566
|
taskId: payload.task_id,
|
|
20523
20567
|
runId: payload.run_id,
|
|
20524
20568
|
error
|
|
@@ -20545,7 +20589,7 @@ ${attributionInstructions}
|
|
|
20545
20589
|
message += "\nReply in this thread with your choice.";
|
|
20546
20590
|
this.questionRelayedToSlack = true;
|
|
20547
20591
|
this.posthogAPI.relayMessage(payload.task_id, payload.run_id, message).catch(
|
|
20548
|
-
(err2) => this.logger.
|
|
20592
|
+
(err2) => this.logger.debug("Failed to relay question to Slack", { err: err2 })
|
|
20549
20593
|
);
|
|
20550
20594
|
}
|
|
20551
20595
|
getFirstQuestionMeta(toolMeta2) {
|
|
@@ -20607,14 +20651,14 @@ ${attributionInstructions}
|
|
|
20607
20651
|
if (!prUrlMatch) return;
|
|
20608
20652
|
const prUrl = prUrlMatch[0];
|
|
20609
20653
|
this.detectedPrUrl = prUrl;
|
|
20610
|
-
this.logger.
|
|
20654
|
+
this.logger.debug("Detected PR URL in bash output", {
|
|
20611
20655
|
runId: payload.run_id,
|
|
20612
20656
|
prUrl
|
|
20613
20657
|
});
|
|
20614
20658
|
this.posthogAPI.updateTaskRun(payload.task_id, payload.run_id, {
|
|
20615
20659
|
output: { pr_url: prUrl }
|
|
20616
20660
|
}).then(() => {
|
|
20617
|
-
this.logger.
|
|
20661
|
+
this.logger.debug("PR URL attached to task run", {
|
|
20618
20662
|
taskId: payload.task_id,
|
|
20619
20663
|
runId: payload.run_id,
|
|
20620
20664
|
prUrl
|
|
@@ -20636,7 +20680,7 @@ ${attributionInstructions}
|
|
|
20636
20680
|
}
|
|
20637
20681
|
async cleanupSession() {
|
|
20638
20682
|
if (!this.session) return;
|
|
20639
|
-
this.logger.
|
|
20683
|
+
this.logger.debug("Cleaning up session");
|
|
20640
20684
|
try {
|
|
20641
20685
|
await this.captureTreeState();
|
|
20642
20686
|
} catch (error) {
|