@posthog/agent 1.22.0 → 1.24.0
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/CLAUDE.md +3 -3
- package/README.md +3 -3
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/src/adapters/claude/claude-adapter.d.ts +3 -3
- package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
- package/dist/src/adapters/claude/claude-adapter.js +156 -111
- package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
- package/dist/src/adapters/claude/tool-mapper.d.ts +1 -1
- package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -1
- package/dist/src/adapters/claude/tool-mapper.js.map +1 -1
- package/dist/src/adapters/types.d.ts +1 -1
- package/dist/src/adapters/types.d.ts.map +1 -1
- package/dist/src/agent.d.ts +7 -7
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +143 -85
- package/dist/src/agent.js.map +1 -1
- package/dist/src/agents/execution.js.map +1 -1
- package/dist/src/agents/planning.js.map +1 -1
- package/dist/src/agents/research.js.map +1 -1
- package/dist/src/file-manager.d.ts +4 -4
- package/dist/src/file-manager.d.ts.map +1 -1
- package/dist/src/file-manager.js +59 -58
- package/dist/src/file-manager.js.map +1 -1
- package/dist/src/git-manager.d.ts +1 -1
- package/dist/src/git-manager.d.ts.map +1 -1
- package/dist/src/git-manager.js +93 -69
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.d.ts +2 -3
- package/dist/src/posthog-api.d.ts.map +1 -1
- package/dist/src/posthog-api.js +22 -22
- package/dist/src/posthog-api.js.map +1 -1
- package/dist/src/prompt-builder.d.ts +3 -3
- package/dist/src/prompt-builder.d.ts.map +1 -1
- package/dist/src/prompt-builder.js +123 -93
- package/dist/src/prompt-builder.js.map +1 -1
- package/dist/src/task-manager.d.ts +4 -4
- package/dist/src/task-manager.d.ts.map +1 -1
- package/dist/src/task-manager.js +19 -18
- package/dist/src/task-manager.js.map +1 -1
- package/dist/src/task-progress-reporter.d.ts +3 -4
- package/dist/src/task-progress-reporter.d.ts.map +1 -1
- package/dist/src/task-progress-reporter.js +59 -54
- package/dist/src/task-progress-reporter.js.map +1 -1
- package/dist/src/template-manager.d.ts +1 -1
- package/dist/src/template-manager.d.ts.map +1 -1
- package/dist/src/template-manager.js +30 -28
- package/dist/src/template-manager.js.map +1 -1
- package/dist/src/todo-manager.d.ts +3 -3
- package/dist/src/todo-manager.d.ts.map +1 -1
- package/dist/src/todo-manager.js +29 -24
- package/dist/src/todo-manager.js.map +1 -1
- package/dist/src/tools/registry.d.ts +1 -1
- package/dist/src/tools/registry.js +60 -60
- package/dist/src/tools/registry.js.map +1 -1
- package/dist/src/tools/types.d.ts +31 -31
- package/dist/src/types.d.ts +33 -33
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/logger.d.ts +4 -4
- package/dist/src/utils/logger.d.ts.map +1 -1
- package/dist/src/utils/logger.js +8 -8
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/workflow/config.d.ts +1 -1
- package/dist/src/workflow/config.d.ts.map +1 -1
- package/dist/src/workflow/config.js +18 -18
- package/dist/src/workflow/config.js.map +1 -1
- package/dist/src/workflow/steps/build.d.ts +1 -1
- package/dist/src/workflow/steps/build.d.ts.map +1 -1
- package/dist/src/workflow/steps/build.js +46 -38
- package/dist/src/workflow/steps/build.js.map +1 -1
- package/dist/src/workflow/steps/finalize.d.ts +1 -1
- package/dist/src/workflow/steps/finalize.d.ts.map +1 -1
- package/dist/src/workflow/steps/finalize.js +54 -48
- package/dist/src/workflow/steps/finalize.js.map +1 -1
- package/dist/src/workflow/steps/plan.d.ts +1 -1
- package/dist/src/workflow/steps/plan.d.ts.map +1 -1
- package/dist/src/workflow/steps/plan.js +58 -46
- package/dist/src/workflow/steps/plan.js.map +1 -1
- package/dist/src/workflow/steps/research.d.ts +1 -1
- package/dist/src/workflow/steps/research.d.ts.map +1 -1
- package/dist/src/workflow/steps/research.js +68 -56
- package/dist/src/workflow/steps/research.js.map +1 -1
- package/dist/src/workflow/types.d.ts +12 -12
- package/dist/src/workflow/types.d.ts.map +1 -1
- package/dist/src/workflow/utils.d.ts +1 -1
- package/dist/src/workflow/utils.d.ts.map +1 -1
- package/dist/src/workflow/utils.js +7 -4
- package/dist/src/workflow/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/adapters/claude/claude-adapter.ts +220 -168
- package/src/adapters/claude/tool-mapper.ts +2 -2
- package/src/adapters/types.ts +1 -1
- package/src/agent.ts +579 -444
- package/src/agents/execution.ts +1 -1
- package/src/agents/planning.ts +1 -1
- package/src/agents/research.ts +0 -1
- package/src/file-manager.ts +64 -63
- package/src/git-manager.ts +152 -87
- package/src/posthog-api.ts +122 -82
- package/src/prompt-builder.ts +180 -135
- package/src/task-manager.ts +38 -30
- package/src/task-progress-reporter.ts +70 -59
- package/src/template-manager.ts +98 -45
- package/src/todo-manager.ts +35 -30
- package/src/tools/registry.ts +62 -62
- package/src/tools/types.ts +36 -36
- package/src/types.ts +93 -71
- package/src/utils/logger.ts +62 -56
- package/src/workflow/config.ts +48 -48
- package/src/workflow/steps/build.ts +122 -113
- package/src/workflow/steps/finalize.ts +214 -182
- package/src/workflow/steps/plan.ts +151 -131
- package/src/workflow/steps/research.ts +205 -186
- package/src/workflow/types.ts +38 -36
- package/src/workflow/utils.ts +37 -34
- package/LICENSE +0 -33
package/dist/src/task-manager.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { randomBytes } from 'crypto';
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
2
|
|
|
3
3
|
class TaskManager {
|
|
4
4
|
executionStates = new Map();
|
|
5
5
|
defaultTimeout = 10 * 60 * 1000; // 10 minutes
|
|
6
6
|
generateExecutionId() {
|
|
7
|
-
return randomBytes(16).toString(
|
|
7
|
+
return randomBytes(16).toString("hex");
|
|
8
8
|
}
|
|
9
9
|
startExecution(taskId, mode, executionId = this.generateExecutionId()) {
|
|
10
10
|
const executionState = {
|
|
11
11
|
taskId,
|
|
12
|
-
status:
|
|
12
|
+
status: "running",
|
|
13
13
|
mode,
|
|
14
14
|
startedAt: Date.now(),
|
|
15
15
|
abortController: new AbortController(),
|
|
@@ -23,7 +23,7 @@ class TaskManager {
|
|
|
23
23
|
if (!execution) {
|
|
24
24
|
throw new Error(`Execution ${executionId} not found`);
|
|
25
25
|
}
|
|
26
|
-
if (execution.result && execution.status ===
|
|
26
|
+
if (execution.result && execution.status === "completed") {
|
|
27
27
|
return execution.result;
|
|
28
28
|
}
|
|
29
29
|
return new Promise((resolve, reject) => {
|
|
@@ -34,13 +34,14 @@ class TaskManager {
|
|
|
34
34
|
reject(new Error(`Execution ${executionId} disappeared`));
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
if (currentExecution.status ===
|
|
37
|
+
if (currentExecution.status === "completed" &&
|
|
38
|
+
currentExecution.result) {
|
|
38
39
|
clearInterval(checkInterval);
|
|
39
40
|
resolve(currentExecution.result);
|
|
40
41
|
}
|
|
41
|
-
else if (currentExecution.status ===
|
|
42
|
-
currentExecution.status ===
|
|
43
|
-
currentExecution.status ===
|
|
42
|
+
else if (currentExecution.status === "failed" ||
|
|
43
|
+
currentExecution.status === "canceled" ||
|
|
44
|
+
currentExecution.status === "timeout") {
|
|
44
45
|
clearInterval(checkInterval);
|
|
45
46
|
reject(new Error(`Execution ${executionId} ${currentExecution.status}`));
|
|
46
47
|
}
|
|
@@ -52,7 +53,7 @@ class TaskManager {
|
|
|
52
53
|
if (!execution) {
|
|
53
54
|
throw new Error(`Execution ${executionId} not found`);
|
|
54
55
|
}
|
|
55
|
-
execution.status =
|
|
56
|
+
execution.status = "completed";
|
|
56
57
|
execution.result = result;
|
|
57
58
|
execution.completedAt = Date.now();
|
|
58
59
|
}
|
|
@@ -61,11 +62,11 @@ class TaskManager {
|
|
|
61
62
|
if (!execution) {
|
|
62
63
|
throw new Error(`Execution ${executionId} not found`);
|
|
63
64
|
}
|
|
64
|
-
execution.status =
|
|
65
|
+
execution.status = "failed";
|
|
65
66
|
execution.completedAt = Date.now();
|
|
66
67
|
execution.result = {
|
|
67
68
|
error: error.message,
|
|
68
|
-
status:
|
|
69
|
+
status: "failed",
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
cancelExecution(executionId) {
|
|
@@ -73,13 +74,13 @@ class TaskManager {
|
|
|
73
74
|
if (!execution) {
|
|
74
75
|
throw new Error(`Execution ${executionId} not found`);
|
|
75
76
|
}
|
|
76
|
-
execution.status =
|
|
77
|
+
execution.status = "canceled";
|
|
77
78
|
execution.completedAt = Date.now();
|
|
78
79
|
execution.abortController?.abort();
|
|
79
80
|
if (!execution.result) {
|
|
80
81
|
execution.result = {
|
|
81
|
-
status:
|
|
82
|
-
message:
|
|
82
|
+
status: "canceled",
|
|
83
|
+
message: "Execution was canceled",
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -95,14 +96,14 @@ class TaskManager {
|
|
|
95
96
|
scheduleTimeout(executionId, timeout = this.defaultTimeout) {
|
|
96
97
|
setTimeout(() => {
|
|
97
98
|
const execution = this.executionStates.get(executionId);
|
|
98
|
-
if (execution && execution.status ===
|
|
99
|
-
execution.status =
|
|
99
|
+
if (execution && execution.status === "running") {
|
|
100
|
+
execution.status = "timeout";
|
|
100
101
|
execution.completedAt = Date.now();
|
|
101
102
|
execution.abortController?.abort();
|
|
102
103
|
if (!execution.result) {
|
|
103
104
|
execution.result = {
|
|
104
|
-
status:
|
|
105
|
-
message:
|
|
105
|
+
status: "timeout",
|
|
106
|
+
message: "Execution timed out",
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-manager.js","sources":["../../src/task-manager.ts"],"sourcesContent":["import { randomBytes } from
|
|
1
|
+
{"version":3,"file":"task-manager.js","sources":["../../src/task-manager.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\n\nexport interface TaskExecutionState {\n taskId: string;\n status: \"running\" | \"completed\" | \"failed\" | \"canceled\" | \"timeout\";\n mode: \"plan_only\" | \"plan_and_build\" | \"build_only\";\n result?: any;\n startedAt: number;\n completedAt?: number;\n abortController?: AbortController;\n}\n\nexport class TaskManager {\n public executionStates = new Map<string, TaskExecutionState>();\n private defaultTimeout = 10 * 60 * 1000; // 10 minutes\n\n generateExecutionId(): string {\n return randomBytes(16).toString(\"hex\");\n }\n\n startExecution(\n taskId: string,\n mode: \"plan_only\" | \"plan_and_build\" | \"build_only\",\n executionId: string = this.generateExecutionId(),\n ): TaskExecutionState {\n const executionState: TaskExecutionState = {\n taskId,\n status: \"running\",\n mode,\n startedAt: Date.now(),\n abortController: new AbortController(),\n };\n\n this.executionStates.set(executionId, executionState);\n this.scheduleTimeout(executionId);\n\n return executionState;\n }\n\n async waitForCompletion(executionId: string): Promise<any> {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n if (execution.result && execution.status === \"completed\") {\n return execution.result;\n }\n\n return new Promise((resolve, reject) => {\n const checkInterval = setInterval(() => {\n const currentExecution = this.executionStates.get(executionId);\n if (!currentExecution) {\n clearInterval(checkInterval);\n reject(new Error(`Execution ${executionId} disappeared`));\n return;\n }\n\n if (\n currentExecution.status === \"completed\" &&\n currentExecution.result\n ) {\n clearInterval(checkInterval);\n resolve(currentExecution.result);\n } else if (\n currentExecution.status === \"failed\" ||\n currentExecution.status === \"canceled\" ||\n currentExecution.status === \"timeout\"\n ) {\n clearInterval(checkInterval);\n reject(\n new Error(`Execution ${executionId} ${currentExecution.status}`),\n );\n }\n }, 100);\n });\n }\n\n completeExecution(executionId: string, result: any): void {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n execution.status = \"completed\";\n execution.result = result;\n execution.completedAt = Date.now();\n }\n\n failExecution(executionId: string, error: Error): void {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n execution.status = \"failed\";\n execution.completedAt = Date.now();\n execution.result = {\n error: error.message,\n status: \"failed\",\n };\n }\n\n cancelExecution(executionId: string): void {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n execution.status = \"canceled\";\n execution.completedAt = Date.now();\n execution.abortController?.abort();\n\n if (!execution.result) {\n execution.result = {\n status: \"canceled\",\n message: \"Execution was canceled\",\n };\n }\n }\n\n getExecution(executionId: string): TaskExecutionState | undefined {\n return this.executionStates.get(executionId);\n }\n\n getAbortSignal(executionId: string): AbortSignal | undefined {\n return this.executionStates.get(executionId)?.abortController?.signal;\n }\n\n getAbortController(executionId: string): AbortController | undefined {\n return this.executionStates.get(executionId)?.abortController;\n }\n\n private scheduleTimeout(\n executionId: string,\n timeout: number = this.defaultTimeout,\n ): void {\n setTimeout(() => {\n const execution = this.executionStates.get(executionId);\n if (execution && execution.status === \"running\") {\n execution.status = \"timeout\";\n execution.completedAt = Date.now();\n execution.abortController?.abort();\n\n if (!execution.result) {\n execution.result = {\n status: \"timeout\",\n message: \"Execution timed out\",\n };\n }\n }\n }, timeout);\n }\n\n cleanup(olderThan: number = 60 * 60 * 1000): void {\n const cutoff = Date.now() - olderThan;\n for (const [executionId, execution] of this.executionStates) {\n if (execution.completedAt && execution.completedAt < cutoff) {\n this.executionStates.delete(executionId);\n }\n }\n }\n}\n"],"names":[],"mappings":";;MAYa,WAAW,CAAA;AACf,IAAA,eAAe,GAAG,IAAI,GAAG,EAA8B;IACtD,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAExC,mBAAmB,GAAA;QACjB,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;IACxC;IAEA,cAAc,CACZ,MAAc,EACd,IAAmD,EACnD,WAAA,GAAsB,IA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AE;oBACrB,SAAS,CAAC,MAAM,GAAG;AACjB,wBAAA,MAAM,EAAE,SAAS;AACjB,wBAAA,OAAO,EAAE,qBAAqB;qBAC/B;gBACH;YACF;QACF,CAAC,EAAE,OAAO,CAAC;IACb;AAEA,IAAA,OAAO,CAAC,SAAA,GAAoB,EAAE,GAAG,EAAE,GAAG,IAAI,EAAA;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;QACrC,KAAK,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE;YAC3D,IAAI,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,WAAW,GAAG,MAAM,EAAE;AAC3D,gBAAA,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC;YAC1C;QACF;IACF;AACD;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { PostHogAPIClient } from "./posthog-api.js";
|
|
2
|
+
import type { AgentEvent } from "./types.js";
|
|
3
|
+
import type { Logger } from "./utils/logger.js";
|
|
4
4
|
interface ProgressMetadata {
|
|
5
5
|
totalSteps?: number;
|
|
6
6
|
}
|
|
@@ -15,7 +15,6 @@ export declare class TaskProgressReporter {
|
|
|
15
15
|
private logger;
|
|
16
16
|
private taskRun?;
|
|
17
17
|
private taskId?;
|
|
18
|
-
private outputLog;
|
|
19
18
|
private totalSteps?;
|
|
20
19
|
private lastLogEntry?;
|
|
21
20
|
private tokenBuffer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-progress-reporter.d.ts","sourceRoot":"","sources":["../../src/task-progress-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"task-progress-reporter.d.ts","sourceRoot":"","sources":["../../src/task-progress-reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,g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AO,CAAC,cAAc;YAqBR,aAAa;IAiCrB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;YA0OrC,MAAM;CAuCrB"}
|
|
@@ -9,10 +9,9 @@ class TaskProgressReporter {
|
|
|
9
9
|
logger;
|
|
10
10
|
taskRun;
|
|
11
11
|
taskId;
|
|
12
|
-
outputLog = [];
|
|
13
12
|
totalSteps;
|
|
14
13
|
lastLogEntry;
|
|
15
|
-
tokenBuffer =
|
|
14
|
+
tokenBuffer = "";
|
|
16
15
|
tokenCount = 0;
|
|
17
16
|
tokenFlushTimer;
|
|
18
17
|
TOKEN_BATCH_SIZE = 100;
|
|
@@ -22,7 +21,7 @@ class TaskProgressReporter {
|
|
|
22
21
|
LOG_APPEND_RETRY_BASE_DELAY_MS = 200;
|
|
23
22
|
constructor(posthogAPI, logger) {
|
|
24
23
|
this.posthogAPI = posthogAPI;
|
|
25
|
-
this.logger = logger.child(
|
|
24
|
+
this.logger = logger.child("TaskProgressReporter");
|
|
26
25
|
}
|
|
27
26
|
get runId() {
|
|
28
27
|
return this.taskRun?.id;
|
|
@@ -35,14 +34,16 @@ class TaskProgressReporter {
|
|
|
35
34
|
this.totalSteps = metadata.totalSteps;
|
|
36
35
|
try {
|
|
37
36
|
const run = await this.posthogAPI.createTaskRun(taskId, {
|
|
38
|
-
status:
|
|
37
|
+
status: "started",
|
|
39
38
|
});
|
|
40
39
|
this.taskRun = run;
|
|
41
|
-
this.
|
|
42
|
-
this.logger.debug('Created task run', { taskId, runId: run.id });
|
|
40
|
+
this.logger.debug("Created task run", { taskId, runId: run.id });
|
|
43
41
|
}
|
|
44
42
|
catch (error) {
|
|
45
|
-
this.logger.warn(
|
|
43
|
+
this.logger.warn("Failed to create task run", {
|
|
44
|
+
taskId,
|
|
45
|
+
error: error.message,
|
|
46
|
+
});
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
async complete() {
|
|
@@ -51,23 +52,27 @@ class TaskProgressReporter {
|
|
|
51
52
|
await this.logWriteQueue;
|
|
52
53
|
}
|
|
53
54
|
catch (error) {
|
|
54
|
-
this.logger.debug(
|
|
55
|
+
this.logger.debug("Pending logs failed to write during completion", {
|
|
56
|
+
error,
|
|
57
|
+
});
|
|
55
58
|
}
|
|
56
59
|
if (this.tokenFlushTimer) {
|
|
57
60
|
clearTimeout(this.tokenFlushTimer);
|
|
58
61
|
this.tokenFlushTimer = undefined;
|
|
59
62
|
}
|
|
60
|
-
await this.update({ status:
|
|
63
|
+
await this.update({ status: "completed" }, "Task execution completed");
|
|
61
64
|
}
|
|
62
65
|
async fail(error) {
|
|
63
66
|
try {
|
|
64
67
|
await this.logWriteQueue;
|
|
65
68
|
}
|
|
66
69
|
catch (logError) {
|
|
67
|
-
this.logger.debug(
|
|
70
|
+
this.logger.debug("Pending logs failed to write during fail", {
|
|
71
|
+
error: logError,
|
|
72
|
+
});
|
|
68
73
|
}
|
|
69
|
-
const message = typeof error ===
|
|
70
|
-
await this.update({ status:
|
|
74
|
+
const message = typeof error === "string" ? error : error.message;
|
|
75
|
+
await this.update({ status: "failed", error_message: message }, `Task execution failed: ${message}`);
|
|
71
76
|
}
|
|
72
77
|
async appendLog(line) {
|
|
73
78
|
await this.update({}, line);
|
|
@@ -77,10 +82,10 @@ class TaskProgressReporter {
|
|
|
77
82
|
return;
|
|
78
83
|
}
|
|
79
84
|
const buffer = this.tokenBuffer;
|
|
80
|
-
this.tokenBuffer =
|
|
85
|
+
this.tokenBuffer = "";
|
|
81
86
|
this.tokenCount = 0;
|
|
82
87
|
await this.appendLogEntry({
|
|
83
|
-
type:
|
|
88
|
+
type: "token",
|
|
84
89
|
message: buffer,
|
|
85
90
|
});
|
|
86
91
|
}
|
|
@@ -91,7 +96,7 @@ class TaskProgressReporter {
|
|
|
91
96
|
this.tokenFlushTimer = setTimeout(() => {
|
|
92
97
|
this.tokenFlushTimer = undefined;
|
|
93
98
|
this.flushTokens().catch((err) => {
|
|
94
|
-
this.logger.warn(
|
|
99
|
+
this.logger.warn("Failed to flush tokens", { error: err });
|
|
95
100
|
});
|
|
96
101
|
}, this.TOKEN_FLUSH_INTERVAL_MS);
|
|
97
102
|
}
|
|
@@ -103,7 +108,7 @@ class TaskProgressReporter {
|
|
|
103
108
|
const runId = this.runId;
|
|
104
109
|
this.logWriteQueue = this.logWriteQueue
|
|
105
110
|
.catch((error) => {
|
|
106
|
-
this.logger.debug(
|
|
111
|
+
this.logger.debug("Previous log append failed", {
|
|
107
112
|
taskId,
|
|
108
113
|
runId,
|
|
109
114
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -122,7 +127,7 @@ class TaskProgressReporter {
|
|
|
122
127
|
return;
|
|
123
128
|
}
|
|
124
129
|
catch (error) {
|
|
125
|
-
this.logger.warn(
|
|
130
|
+
this.logger.warn("Failed to append log entry", {
|
|
126
131
|
taskId,
|
|
127
132
|
runId,
|
|
128
133
|
attempt,
|
|
@@ -132,7 +137,7 @@ class TaskProgressReporter {
|
|
|
132
137
|
if (attempt === this.LOG_APPEND_MAX_RETRIES) {
|
|
133
138
|
return;
|
|
134
139
|
}
|
|
135
|
-
const delayMs = this.LOG_APPEND_RETRY_BASE_DELAY_MS *
|
|
140
|
+
const delayMs = this.LOG_APPEND_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1);
|
|
136
141
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
137
142
|
}
|
|
138
143
|
}
|
|
@@ -142,7 +147,7 @@ class TaskProgressReporter {
|
|
|
142
147
|
return;
|
|
143
148
|
}
|
|
144
149
|
switch (event.type) {
|
|
145
|
-
case
|
|
150
|
+
case "token": {
|
|
146
151
|
// Batch tokens for efficiency
|
|
147
152
|
this.tokenBuffer += event.content;
|
|
148
153
|
this.tokenCount++;
|
|
@@ -158,9 +163,9 @@ class TaskProgressReporter {
|
|
|
158
163
|
}
|
|
159
164
|
return;
|
|
160
165
|
}
|
|
161
|
-
case
|
|
166
|
+
case "content_block_start": {
|
|
162
167
|
await this.appendLogEntry({
|
|
163
|
-
type:
|
|
168
|
+
type: "content_block_start",
|
|
164
169
|
message: JSON.stringify({
|
|
165
170
|
index: event.index,
|
|
166
171
|
contentType: event.contentType,
|
|
@@ -171,9 +176,9 @@ class TaskProgressReporter {
|
|
|
171
176
|
});
|
|
172
177
|
return;
|
|
173
178
|
}
|
|
174
|
-
case
|
|
179
|
+
case "content_block_stop": {
|
|
175
180
|
await this.appendLogEntry({
|
|
176
|
-
type:
|
|
181
|
+
type: "content_block_stop",
|
|
177
182
|
message: JSON.stringify({
|
|
178
183
|
index: event.index,
|
|
179
184
|
ts: event.ts,
|
|
@@ -181,9 +186,9 @@ class TaskProgressReporter {
|
|
|
181
186
|
});
|
|
182
187
|
return;
|
|
183
188
|
}
|
|
184
|
-
case
|
|
189
|
+
case "message_start": {
|
|
185
190
|
await this.appendLogEntry({
|
|
186
|
-
type:
|
|
191
|
+
type: "message_start",
|
|
187
192
|
message: JSON.stringify({
|
|
188
193
|
messageId: event.messageId,
|
|
189
194
|
model: event.model,
|
|
@@ -192,9 +197,9 @@ class TaskProgressReporter {
|
|
|
192
197
|
});
|
|
193
198
|
return;
|
|
194
199
|
}
|
|
195
|
-
case
|
|
200
|
+
case "message_delta": {
|
|
196
201
|
await this.appendLogEntry({
|
|
197
|
-
type:
|
|
202
|
+
type: "message_delta",
|
|
198
203
|
message: JSON.stringify({
|
|
199
204
|
stopReason: event.stopReason,
|
|
200
205
|
stopSequence: event.stopSequence,
|
|
@@ -204,16 +209,16 @@ class TaskProgressReporter {
|
|
|
204
209
|
});
|
|
205
210
|
return;
|
|
206
211
|
}
|
|
207
|
-
case
|
|
212
|
+
case "message_stop": {
|
|
208
213
|
await this.appendLogEntry({
|
|
209
|
-
type:
|
|
214
|
+
type: "message_stop",
|
|
210
215
|
message: JSON.stringify({ ts: event.ts }),
|
|
211
216
|
});
|
|
212
217
|
return;
|
|
213
218
|
}
|
|
214
|
-
case
|
|
219
|
+
case "status": {
|
|
215
220
|
await this.appendLogEntry({
|
|
216
|
-
type:
|
|
221
|
+
type: "status",
|
|
217
222
|
message: JSON.stringify({
|
|
218
223
|
phase: event.phase,
|
|
219
224
|
kind: event.kind,
|
|
@@ -227,9 +232,9 @@ class TaskProgressReporter {
|
|
|
227
232
|
});
|
|
228
233
|
return;
|
|
229
234
|
}
|
|
230
|
-
case
|
|
235
|
+
case "artifact": {
|
|
231
236
|
await this.appendLogEntry({
|
|
232
|
-
type:
|
|
237
|
+
type: "artifact",
|
|
233
238
|
message: JSON.stringify({
|
|
234
239
|
kind: event.kind,
|
|
235
240
|
content: event.content,
|
|
@@ -238,9 +243,9 @@ class TaskProgressReporter {
|
|
|
238
243
|
});
|
|
239
244
|
return;
|
|
240
245
|
}
|
|
241
|
-
case
|
|
246
|
+
case "init": {
|
|
242
247
|
await this.appendLogEntry({
|
|
243
|
-
type:
|
|
248
|
+
type: "init",
|
|
244
249
|
message: JSON.stringify({
|
|
245
250
|
model: event.model,
|
|
246
251
|
tools: event.tools,
|
|
@@ -252,9 +257,9 @@ class TaskProgressReporter {
|
|
|
252
257
|
});
|
|
253
258
|
return;
|
|
254
259
|
}
|
|
255
|
-
case
|
|
260
|
+
case "metric": {
|
|
256
261
|
await this.appendLogEntry({
|
|
257
|
-
type:
|
|
262
|
+
type: "metric",
|
|
258
263
|
message: JSON.stringify({
|
|
259
264
|
key: event.key,
|
|
260
265
|
value: event.value,
|
|
@@ -264,9 +269,9 @@ class TaskProgressReporter {
|
|
|
264
269
|
});
|
|
265
270
|
return;
|
|
266
271
|
}
|
|
267
|
-
case
|
|
272
|
+
case "compact_boundary": {
|
|
268
273
|
await this.appendLogEntry({
|
|
269
|
-
type:
|
|
274
|
+
type: "compact_boundary",
|
|
270
275
|
message: JSON.stringify({
|
|
271
276
|
trigger: event.trigger,
|
|
272
277
|
preTokens: event.preTokens,
|
|
@@ -275,9 +280,9 @@ class TaskProgressReporter {
|
|
|
275
280
|
});
|
|
276
281
|
return;
|
|
277
282
|
}
|
|
278
|
-
case
|
|
283
|
+
case "tool_call": {
|
|
279
284
|
await this.appendLogEntry({
|
|
280
|
-
type:
|
|
285
|
+
type: "tool_call",
|
|
281
286
|
message: JSON.stringify({
|
|
282
287
|
toolName: event.toolName,
|
|
283
288
|
callId: event.callId,
|
|
@@ -288,9 +293,9 @@ class TaskProgressReporter {
|
|
|
288
293
|
});
|
|
289
294
|
return;
|
|
290
295
|
}
|
|
291
|
-
case
|
|
296
|
+
case "tool_result": {
|
|
292
297
|
await this.appendLogEntry({
|
|
293
|
-
type:
|
|
298
|
+
type: "tool_result",
|
|
294
299
|
message: JSON.stringify({
|
|
295
300
|
toolName: event.toolName,
|
|
296
301
|
callId: event.callId,
|
|
@@ -302,9 +307,9 @@ class TaskProgressReporter {
|
|
|
302
307
|
});
|
|
303
308
|
return;
|
|
304
309
|
}
|
|
305
|
-
case
|
|
310
|
+
case "error": {
|
|
306
311
|
await this.appendLogEntry({
|
|
307
|
-
type:
|
|
312
|
+
type: "error",
|
|
308
313
|
message: JSON.stringify({
|
|
309
314
|
message: event.message,
|
|
310
315
|
errorType: event.errorType,
|
|
@@ -314,9 +319,9 @@ class TaskProgressReporter {
|
|
|
314
319
|
});
|
|
315
320
|
return;
|
|
316
321
|
}
|
|
317
|
-
case
|
|
322
|
+
case "done": {
|
|
318
323
|
await this.appendLogEntry({
|
|
319
|
-
type:
|
|
324
|
+
type: "done",
|
|
320
325
|
message: JSON.stringify({
|
|
321
326
|
result: event.result,
|
|
322
327
|
durationMs: event.durationMs,
|
|
@@ -331,9 +336,9 @@ class TaskProgressReporter {
|
|
|
331
336
|
});
|
|
332
337
|
return;
|
|
333
338
|
}
|
|
334
|
-
case
|
|
339
|
+
case "user_message": {
|
|
335
340
|
await this.appendLogEntry({
|
|
336
|
-
type:
|
|
341
|
+
type: "user_message",
|
|
337
342
|
message: JSON.stringify({
|
|
338
343
|
content: event.content,
|
|
339
344
|
isSynthetic: event.isSynthetic,
|
|
@@ -342,13 +347,13 @@ class TaskProgressReporter {
|
|
|
342
347
|
});
|
|
343
348
|
return;
|
|
344
349
|
}
|
|
345
|
-
case
|
|
350
|
+
case "raw_sdk_event": {
|
|
346
351
|
// Skip raw SDK events - too verbose for persistence
|
|
347
352
|
return;
|
|
348
353
|
}
|
|
349
354
|
default:
|
|
350
355
|
// For any unfamiliar event types, log them as-is
|
|
351
|
-
this.logger.debug(
|
|
356
|
+
this.logger.debug("Unknown event type", { type: event.type });
|
|
352
357
|
return;
|
|
353
358
|
}
|
|
354
359
|
}
|
|
@@ -360,12 +365,12 @@ class TaskProgressReporter {
|
|
|
360
365
|
if (logLine && logLine !== this.lastLogEntry) {
|
|
361
366
|
try {
|
|
362
367
|
await this.posthogAPI.appendTaskRunLog(this.taskId, this.runId, [
|
|
363
|
-
{ type:
|
|
368
|
+
{ type: "info", message: logLine },
|
|
364
369
|
]);
|
|
365
370
|
this.lastLogEntry = logLine;
|
|
366
371
|
}
|
|
367
372
|
catch (error) {
|
|
368
|
-
this.logger.warn(
|
|
373
|
+
this.logger.warn("Failed to append log entry", {
|
|
369
374
|
taskId: this.taskId,
|
|
370
375
|
runId: this.runId,
|
|
371
376
|
error: error.message,
|
|
@@ -379,7 +384,7 @@ class TaskProgressReporter {
|
|
|
379
384
|
this.taskRun = run;
|
|
380
385
|
}
|
|
381
386
|
catch (error) {
|
|
382
|
-
this.logger.warn(
|
|
387
|
+
this.logger.warn("Failed to update task run", {
|
|
383
388
|
taskId: this.taskId,
|
|
384
389
|
runId: this.runId,
|
|
385
390
|
error: error.message,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-progress-reporter.js","sources":["../../src/task-progress-reporter.ts"],"sourcesContent":["import type { Logger } from './utils/logger.js';\nimport type { PostHogAPIClient, TaskRunUpdate } from './posthog-api.js';\nimport type { AgentEvent, TaskRun, LogEntry } from './types.js';\n\ninterface ProgressMetadata {\n totalSteps?: number;\n}\n\n/**\n * Persists task execution progress to PostHog so clients can poll for updates.\n *\n * The reporter is intentionally best-effort – failures are logged but never\n * allowed to break the agent execution flow.\n */\nexport class TaskProgressReporter {\n private posthogAPI?: PostHogAPIClient;\n private logger: Logger;\n private taskRun?: TaskRun;\n private taskId?: string;\n private outputLog: string[] = [];\n private totalSteps?: number;\n private lastLogEntry?: string;\n private tokenBuffer: string = '';\n private tokenCount: number = 0;\n private tokenFlushTimer?: NodeJS.Timeout;\n private readonly TOKEN_BATCH_SIZE = 100;\n private readonly TOKEN_FLUSH_INTERVAL_MS = 1000;\n private logWriteQueue: Promise<void> = Promise.resolve();\n private readonly LOG_APPEND_MAX_RETRIES = 3;\n private readonly LOG_APPEND_RETRY_BASE_DELAY_MS = 200;\n\n constructor(posthogAPI: PostHogAPIClient | undefined, logger: Logger) {\n this.posthogAPI = posthogAPI;\n this.logger = logger.child('TaskProgressReporter');\n }\n\n get runId(): string | undefined {\n return this.taskRun?.id;\n }\n\n async start(taskId: string, metadata: ProgressMetadata = {}): Promise<void> {\n if (!this.posthogAPI) {\n return;\n }\n\n this.taskId = taskId;\n this.totalSteps = metadata.totalSteps;\n\n try {\n const run = await this.posthogAPI.createTaskRun(taskId, {\n status: 'started',\n });\n this.taskRun = run;\n this.outputLog = [];\n this.logger.debug('Created task run', { taskId, runId: run.id });\n } catch (error) {\n this.logger.warn('Failed to create task run', { taskId, error: (error as Error).message });\n }\n }\n\n async complete(): Promise<void> {\n await this.flushTokens(); // Flush any remaining tokens before completion\n try {\n await this.logWriteQueue;\n } catch (error) {\n this.logger.debug('Pending logs failed to write during completion', { error });\n }\n\n if (this.tokenFlushTimer) {\n clearTimeout(this.tokenFlushTimer);\n this.tokenFlushTimer = undefined;\n }\n await this.update({ status: 'completed' }, 'Task execution completed');\n }\n\n async fail(error: Error | string): Promise<void> {\n try {\n await this.logWriteQueue;\n } catch (logError) {\n this.logger.debug('Pending logs failed to write during fail', { error: logError });\n }\n\n const message = typeof error === 'string' ? error : error.message;\n await this.update({ status: 'failed', error_message: message }, `Task execution failed: ${message}`);\n }\n\n async appendLog(line: string): Promise<void> {\n await this.update({}, line);\n }\n\n private async flushTokens(): Promise<void> {\n if (!this.tokenBuffer || this.tokenCount === 0) {\n return;\n }\n\n const buffer = this.tokenBuffer;\n this.tokenBuffer = '';\n this.tokenCount = 0;\n\n await this.appendLogEntry({\n type: 'token',\n message: buffer,\n });\n }\n\n private scheduleTokenFlush(): void {\n if (this.tokenFlushTimer) {\n return;\n }\n\n this.tokenFlushTimer = setTimeout(() => {\n this.tokenFlushTimer = undefined;\n this.flushTokens().catch((err) => {\n this.logger.warn('Failed to flush tokens', { error: err });\n });\n }, this.TOKEN_FLUSH_INTERVAL_MS);\n }\n\n private appendLogEntry(entry: LogEntry): Promise<void> {\n if (!this.posthogAPI || !this.runId || !this.taskId) {\n return Promise.resolve();\n }\n\n const taskId = this.taskId;\n const runId = this.runId;\n\n this.logWriteQueue = this.logWriteQueue\n .catch((error) => {\n this.logger.debug('Previous log append failed', {\n taskId,\n runId,\n error: error instanceof Error ? error.message : String(error),\n });\n })\n .then(() => this.writeLogEntry(taskId, runId, entry));\n\n return this.logWriteQueue;\n }\n\n private async writeLogEntry(\n taskId: string,\n runId: string,\n entry: LogEntry,\n ): Promise<void> {\n if (!this.posthogAPI) {\n return;\n }\n\n for (let attempt = 1; attempt <= this.LOG_APPEND_MAX_RETRIES; attempt++) {\n try {\n await this.posthogAPI.appendTaskRunLog(taskId, runId, [entry]);\n return;\n } catch (error) {\n this.logger.warn('Failed to append log entry', {\n taskId,\n runId,\n attempt,\n maxAttempts: this.LOG_APPEND_MAX_RETRIES,\n error: (error as Error).message,\n });\n\n if (attempt === this.LOG_APPEND_MAX_RETRIES) {\n return;\n }\n\n const delayMs =\n this.LOG_APPEND_RETRY_BASE_DELAY_MS * Math.pow(2, attempt - 1);\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n }\n }\n\n async recordEvent(event: AgentEvent): Promise<void> {\n if (!this.posthogAPI || !this.runId || !this.taskId) {\n return;\n }\n\n switch (event.type) {\n case 'token': {\n // Batch tokens for efficiency\n this.tokenBuffer += event.content;\n this.tokenCount++;\n\n if (this.tokenCount >= this.TOKEN_BATCH_SIZE) {\n await this.flushTokens();\n if (this.tokenFlushTimer) {\n clearTimeout(this.tokenFlushTimer);\n this.tokenFlushTimer = undefined;\n }\n } else {\n this.scheduleTokenFlush();\n }\n return;\n }\n\n case 'content_block_start': {\n await this.appendLogEntry({\n type: 'content_block_start',\n message: JSON.stringify({\n index: event.index,\n contentType: event.contentType,\n toolName: event.toolName,\n toolId: event.toolId,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'content_block_stop': {\n await this.appendLogEntry({\n type: 'content_block_stop',\n message: JSON.stringify({\n index: event.index,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'message_start': {\n await this.appendLogEntry({\n type: 'message_start',\n message: JSON.stringify({\n messageId: event.messageId,\n model: event.model,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'message_delta': {\n await this.appendLogEntry({\n type: 'message_delta',\n message: JSON.stringify({\n stopReason: event.stopReason,\n stopSequence: event.stopSequence,\n usage: event.usage,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'message_stop': {\n await this.appendLogEntry({\n type: 'message_stop',\n message: JSON.stringify({ ts: event.ts }),\n });\n return;\n }\n\n case 'status': {\n await this.appendLogEntry({\n type: 'status',\n message: JSON.stringify({\n phase: event.phase,\n kind: event.kind,\n branch: event.branch,\n prUrl: event.prUrl,\n taskId: event.taskId,\n messageId: event.messageId,\n model: event.model,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'artifact': {\n await this.appendLogEntry({\n type: 'artifact',\n message: JSON.stringify({\n kind: event.kind,\n content: event.content,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'init': {\n await this.appendLogEntry({\n type: 'init',\n message: JSON.stringify({\n model: event.model,\n tools: event.tools,\n permissionMode: event.permissionMode,\n cwd: event.cwd,\n apiKeySource: event.apiKeySource,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'metric': {\n await this.appendLogEntry({\n type: 'metric',\n message: JSON.stringify({\n key: event.key,\n value: event.value,\n unit: event.unit,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'compact_boundary': {\n await this.appendLogEntry({\n type: 'compact_boundary',\n message: JSON.stringify({\n trigger: event.trigger,\n preTokens: event.preTokens,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'tool_call': {\n await this.appendLogEntry({\n type: 'tool_call',\n message: JSON.stringify({\n toolName: event.toolName,\n callId: event.callId,\n args: event.args,\n parentToolUseId: event.parentToolUseId,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'tool_result': {\n await this.appendLogEntry({\n type: 'tool_result',\n message: JSON.stringify({\n toolName: event.toolName,\n callId: event.callId,\n result: event.result,\n isError: event.isError,\n parentToolUseId: event.parentToolUseId,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'error': {\n await this.appendLogEntry({\n type: 'error',\n message: JSON.stringify({\n message: event.message,\n errorType: event.errorType,\n context: event.context,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'done': {\n await this.appendLogEntry({\n type: 'done',\n message: JSON.stringify({\n result: event.result,\n durationMs: event.durationMs,\n durationApiMs: event.durationApiMs,\n numTurns: event.numTurns,\n totalCostUsd: event.totalCostUsd,\n usage: event.usage,\n modelUsage: event.modelUsage,\n permissionDenials: event.permissionDenials,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'user_message': {\n await this.appendLogEntry({\n type: 'user_message',\n message: JSON.stringify({\n content: event.content,\n isSynthetic: event.isSynthetic,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case 'raw_sdk_event': {\n // Skip raw SDK events - too verbose for persistence\n return;\n }\n\n default:\n // For any unfamiliar event types, log them as-is\n this.logger.debug('Unknown event type', { type: (event as any).type });\n return;\n }\n }\n\n private async update(update: TaskRunUpdate, logLine?: string): Promise<void> {\n if (!this.posthogAPI || !this.runId || !this.taskId) {\n return;\n }\n\n // If there's a log line, append it separately using the append_log endpoint\n if (logLine && logLine !== this.lastLogEntry) {\n try {\n await this.posthogAPI.appendTaskRunLog(this.taskId, this.runId, [\n { type: 'info', message: logLine }\n ]);\n this.lastLogEntry = logLine;\n } catch (error) {\n this.logger.warn('Failed to append log entry', {\n taskId: this.taskId,\n runId: this.runId,\n error: (error as Error).message,\n });\n }\n }\n\n // Update other fields if provided\n if (Object.keys(update).length > 0) {\n try {\n const run = await this.posthogAPI.updateTaskRun(this.taskId, this.runId, update);\n this.taskRun = run;\n } catch (error) {\n this.logger.warn('Failed to update task run', {\n taskId: this.taskId,\n runId: this.runId,\n error: (error as Error).message,\n });\n }\n }\n }\n\n}\n"],"names":[],"mappings":"AAQA;;;;;AAKG;MACU,oBAAoB,CAAA;AACvB,IAAA,UAAU;AACV,IAAA,MAAM;AACN,IAAA,OAAO;AACP,IAAA,MAAM;IACN,SAAS,GAAa,EAAE;AACxB,IAAA,UAAU;AACV,IAAA,YAAY;IACZ,WAAW,GAAW,EAAE;IACxB,UAAU,GAAW,CAAC;AACtB,IAAA,eAAe;IACN,gBAAgB,GAAG,GAAG;IACtB,uBAAuB,GAAG,IAAI;AACvC,IAAA,aAAa,GAAkB,OAAO,CAAC,OAAO,EAAE;IACvC,sBAAsB,GAAG,CAAC;IAC1B,8BAA8B,GAAG,GAAG;IAErD,WAAA,CAAY,UAAwC,EAAE,MAAc,EAAA;AAClE,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC;IACpD;AAEA,IAAA,IAAI,KAAK,GAAA;AACP,QAAA,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE;IACzB;AAEA,IAAA,MAAM,KAAK,CAAC,MAAc,EAAE,WAA6B,EAAE,EAAA;AACzD,QAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB;QACF;AAEA,QAAA,IAAI,CAAC,MAAM,GAAG,MAAM;AACpB,QAAA,IAAI,CAAC,UAAU,G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I,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;oBAC5C,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,KAAK,EAAG,KAAe,CAAC,OAAO;AAChC,iBAAA,CAAC;YACJ;QACF;IACF;AAED;;;;"}
|
|
1
|
+
{"version":3,"file":"task-progress-reporter.js","sources":["../../src/task-progress-reporter.ts"],"sourcesContent":["import type { PostHogAPIClient, TaskRunUpdate } from \"./posthog-api.js\";\nimport type { AgentEvent, LogEntry, TaskRun } from \"./types.js\";\nimport type { Logger } from \"./utils/logger.js\";\n\ninterface ProgressMetadata {\n totalSteps?: number;\n}\n\n/**\n * Persists task execution progress to PostHog so clients can poll for updates.\n *\n * The reporter is intentionally best-effort – failures are logged but never\n * allowed to break the agent execution flow.\n */\nexport class TaskProgressReporter {\n private posthogAPI?: PostHogAPIClient;\n private logger: Logger;\n private taskRun?: TaskRun;\n private taskId?: string;\n private totalSteps?: number;\n private lastLogEntry?: string;\n private tokenBuffer: string = \"\";\n private tokenCount: number = 0;\n private tokenFlushTimer?: NodeJS.Timeout;\n private readonly TOKEN_BATCH_SIZE = 100;\n private readonly TOKEN_FLUSH_INTERVAL_MS = 1000;\n private logWriteQueue: Promise<void> = Promise.resolve();\n private readonly LOG_APPEND_MAX_RETRIES = 3;\n private readonly LOG_APPEND_RETRY_BASE_DELAY_MS = 200;\n\n constructor(posthogAPI: PostHogAPIClient | undefined, logger: Logger) {\n this.posthogAPI = posthogAPI;\n this.logger = logger.child(\"TaskProgressReporter\");\n }\n\n get runId(): string | undefined {\n return this.taskRun?.id;\n }\n\n async start(taskId: string, metadata: ProgressMetadata = {}): Promise<void> {\n if (!this.posthogAPI) {\n return;\n }\n\n this.taskId = taskId;\n this.totalSteps = metadata.totalSteps;\n\n try {\n const run = await this.posthogAPI.createTaskRun(taskId, {\n status: \"started\",\n });\n this.taskRun = run;\n this.logger.debug(\"Created task run\", { taskId, runId: run.id });\n } catch (error) {\n this.logger.warn(\"Failed to create task run\", {\n taskId,\n error: (error as Error).message,\n });\n }\n }\n\n async complete(): Promise<void> {\n await this.flushTokens(); // Flush any remaining tokens before completion\n try {\n await this.logWriteQueue;\n } catch (error) {\n this.logger.debug(\"Pending logs failed to write during completion\", {\n error,\n });\n }\n\n if (this.tokenFlushTimer) {\n clearTimeout(this.tokenFlushTimer);\n this.tokenFlushTimer = undefined;\n }\n await this.update({ status: \"completed\" }, \"Task execution completed\");\n }\n\n async fail(error: Error | string): Promise<void> {\n try {\n await this.logWriteQueue;\n } catch (logError) {\n this.logger.debug(\"Pending logs failed to write during fail\", {\n error: logError,\n });\n }\n\n const message = typeof error === \"string\" ? error : error.message;\n await this.update(\n { status: \"failed\", error_message: message },\n `Task execution failed: ${message}`,\n );\n }\n\n async appendLog(line: string): Promise<void> {\n await this.update({}, line);\n }\n\n private async flushTokens(): Promise<void> {\n if (!this.tokenBuffer || this.tokenCount === 0) {\n return;\n }\n\n const buffer = this.tokenBuffer;\n this.tokenBuffer = \"\";\n this.tokenCount = 0;\n\n await this.appendLogEntry({\n type: \"token\",\n message: buffer,\n });\n }\n\n private scheduleTokenFlush(): void {\n if (this.tokenFlushTimer) {\n return;\n }\n\n this.tokenFlushTimer = setTimeout(() => {\n this.tokenFlushTimer = undefined;\n this.flushTokens().catch((err) => {\n this.logger.warn(\"Failed to flush tokens\", { error: err });\n });\n }, this.TOKEN_FLUSH_INTERVAL_MS);\n }\n\n private appendLogEntry(entry: LogEntry): Promise<void> {\n if (!this.posthogAPI || !this.runId || !this.taskId) {\n return Promise.resolve();\n }\n\n const taskId = this.taskId;\n const runId = this.runId;\n\n this.logWriteQueue = this.logWriteQueue\n .catch((error) => {\n this.logger.debug(\"Previous log append failed\", {\n taskId,\n runId,\n error: error instanceof Error ? error.message : String(error),\n });\n })\n .then(() => this.writeLogEntry(taskId, runId, entry));\n\n return this.logWriteQueue;\n }\n\n private async writeLogEntry(\n taskId: string,\n runId: string,\n entry: LogEntry,\n ): Promise<void> {\n if (!this.posthogAPI) {\n return;\n }\n\n for (let attempt = 1; attempt <= this.LOG_APPEND_MAX_RETRIES; attempt++) {\n try {\n await this.posthogAPI.appendTaskRunLog(taskId, runId, [entry]);\n return;\n } catch (error) {\n this.logger.warn(\"Failed to append log entry\", {\n taskId,\n runId,\n attempt,\n maxAttempts: this.LOG_APPEND_MAX_RETRIES,\n error: (error as Error).message,\n });\n\n if (attempt === this.LOG_APPEND_MAX_RETRIES) {\n return;\n }\n\n const delayMs =\n this.LOG_APPEND_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1);\n await new Promise((resolve) => setTimeout(resolve, delayMs));\n }\n }\n }\n\n async recordEvent(event: AgentEvent): Promise<void> {\n if (!this.posthogAPI || !this.runId || !this.taskId) {\n return;\n }\n\n switch (event.type) {\n case \"token\": {\n // Batch tokens for efficiency\n this.tokenBuffer += event.content;\n this.tokenCount++;\n\n if (this.tokenCount >= this.TOKEN_BATCH_SIZE) {\n await this.flushTokens();\n if (this.tokenFlushTimer) {\n clearTimeout(this.tokenFlushTimer);\n this.tokenFlushTimer = undefined;\n }\n } else {\n this.scheduleTokenFlush();\n }\n return;\n }\n\n case \"content_block_start\": {\n await this.appendLogEntry({\n type: \"content_block_start\",\n message: JSON.stringify({\n index: event.index,\n contentType: event.contentType,\n toolName: event.toolName,\n toolId: event.toolId,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"content_block_stop\": {\n await this.appendLogEntry({\n type: \"content_block_stop\",\n message: JSON.stringify({\n index: event.index,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"message_start\": {\n await this.appendLogEntry({\n type: \"message_start\",\n message: JSON.stringify({\n messageId: event.messageId,\n model: event.model,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"message_delta\": {\n await this.appendLogEntry({\n type: \"message_delta\",\n message: JSON.stringify({\n stopReason: event.stopReason,\n stopSequence: event.stopSequence,\n usage: event.usage,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"message_stop\": {\n await this.appendLogEntry({\n type: \"message_stop\",\n message: JSON.stringify({ ts: event.ts }),\n });\n return;\n }\n\n case \"status\": {\n await this.appendLogEntry({\n type: \"status\",\n message: JSON.stringify({\n phase: event.phase,\n kind: event.kind,\n branch: event.branch,\n prUrl: event.prUrl,\n taskId: event.taskId,\n messageId: event.messageId,\n model: event.model,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"artifact\": {\n await this.appendLogEntry({\n type: \"artifact\",\n message: JSON.stringify({\n kind: event.kind,\n content: event.content,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"init\": {\n await this.appendLogEntry({\n type: \"init\",\n message: JSON.stringify({\n model: event.model,\n tools: event.tools,\n permissionMode: event.permissionMode,\n cwd: event.cwd,\n apiKeySource: event.apiKeySource,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"metric\": {\n await this.appendLogEntry({\n type: \"metric\",\n message: JSON.stringify({\n key: event.key,\n value: event.value,\n unit: event.unit,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"compact_boundary\": {\n await this.appendLogEntry({\n type: \"compact_boundary\",\n message: JSON.stringify({\n trigger: event.trigger,\n preTokens: event.preTokens,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"tool_call\": {\n await this.appendLogEntry({\n type: \"tool_call\",\n message: JSON.stringify({\n toolName: event.toolName,\n callId: event.callId,\n args: event.args,\n parentToolUseId: event.parentToolUseId,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"tool_result\": {\n await this.appendLogEntry({\n type: \"tool_result\",\n message: JSON.stringify({\n toolName: event.toolName,\n callId: event.callId,\n result: event.result,\n isError: event.isError,\n parentToolUseId: event.parentToolUseId,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"error\": {\n await this.appendLogEntry({\n type: \"error\",\n message: JSON.stringify({\n message: event.message,\n errorType: event.errorType,\n context: event.context,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"done\": {\n await this.appendLogEntry({\n type: \"done\",\n message: JSON.stringify({\n result: event.result,\n durationMs: event.durationMs,\n durationApiMs: event.durationApiMs,\n numTurns: event.numTurns,\n totalCostUsd: event.totalCostUsd,\n usage: event.usage,\n modelUsage: event.modelUsage,\n permissionDenials: event.permissionDenials,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"user_message\": {\n await this.appendLogEntry({\n type: \"user_message\",\n message: JSON.stringify({\n content: event.content,\n isSynthetic: event.isSynthetic,\n ts: event.ts,\n }),\n });\n return;\n }\n\n case \"raw_sdk_event\": {\n // Skip raw SDK events - too verbose for persistence\n return;\n }\n\n default:\n // For any unfamiliar event types, log them as-is\n this.logger.debug(\"Unknown event type\", { type: (event as any).type });\n return;\n }\n }\n\n private async update(update: TaskRunUpdate, logLine?: string): Promise<void> {\n if (!this.posthogAPI || !this.runId || !this.taskId) {\n return;\n }\n\n // If there's a log line, append it separately using the append_log endpoint\n if (logLine && logLine !== this.lastLogEntry) {\n try {\n await this.posthogAPI.appendTaskRunLog(this.taskId, this.runId, [\n { type: \"info\", message: logLine },\n ]);\n this.lastLogEntry = logLine;\n } catch (error) {\n this.logger.warn(\"Failed to append log entry\", {\n taskId: this.taskId,\n runId: this.runId,\n error: (error as Error).message,\n });\n }\n }\n\n // Update other fields if provided\n if (Object.keys(update).length > 0) {\n try {\n const run = await this.posthogAPI.updateTaskRun(\n this.taskId,\n this.runId,\n update,\n );\n this.taskRun = run;\n } catch (error) {\n this.logger.warn(\"Failed to update task run\", {\n taskId: this.taskId,\n runId: this.runId,\n error: (error as Error).message,\n });\n }\n }\n }\n}\n"],"names":[],"mappings":"AAQA;;;;;AAKG;MACU,oBAAoB,CAAA;AACvB,IAAA,UAAU;AACV,IAAA,MAAM;AACN,IAAA,OAAO;AACP,IAAA,MAAM;AACN,IAAA,UAAU;AACV,IAAA,YAAY;IACZ,WAAW,GAAW,EAAE;IACxB,UAAU,GAAW,CAAC;AACtB,IAAA,eAAe;IACN,gBAAgB,GAAG,GAAG;IACtB,u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