@posthog/agent 1.24.0 → 1.24.2
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/LICENSE +33 -0
- 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 +111 -156
- 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 +85 -143
- 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 +58 -59
- 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 +70 -87
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.d.ts +3 -2
- 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 +93 -123
- 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 +18 -19
- package/dist/src/task-manager.js.map +1 -1
- package/dist/src/task-progress-reporter.d.ts +4 -3
- package/dist/src/task-progress-reporter.d.ts.map +1 -1
- package/dist/src/task-progress-reporter.js +54 -59
- 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 +28 -30
- 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 +24 -29
- 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 +38 -46
- 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 +48 -54
- 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 +46 -58
- 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 +56 -68
- 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 +4 -7
- package/dist/src/workflow/utils.js.map +1 -1
- package/package.json +6 -6
- package/src/adapters/claude/claude-adapter.ts +168 -220
- package/src/adapters/claude/tool-mapper.ts +2 -2
- package/src/adapters/types.ts +1 -1
- package/src/agent.ts +444 -579
- package/src/agents/execution.ts +1 -1
- package/src/agents/planning.ts +1 -1
- package/src/agents/research.ts +1 -0
- package/src/file-manager.ts +63 -64
- package/src/git-manager.ts +88 -144
- package/src/posthog-api.ts +82 -122
- package/src/prompt-builder.ts +135 -180
- package/src/task-manager.ts +30 -38
- package/src/task-progress-reporter.ts +59 -70
- package/src/template-manager.ts +45 -98
- package/src/todo-manager.ts +30 -35
- package/src/tools/registry.ts +62 -62
- package/src/tools/types.ts +36 -36
- package/src/types.ts +71 -93
- package/src/utils/logger.ts +56 -62
- package/src/workflow/config.ts +48 -48
- package/src/workflow/steps/build.ts +113 -122
- package/src/workflow/steps/finalize.ts +182 -214
- package/src/workflow/steps/plan.ts +131 -151
- package/src/workflow/steps/research.ts +186 -205
- package/src/workflow/types.ts +36 -38
- package/src/workflow/utils.ts +34 -37
package/dist/src/task-manager.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { randomBytes } from '
|
|
1
|
+
import { randomBytes } from '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,14 +34,13 @@ class TaskManager {
|
|
|
34
34
|
reject(new Error(`Execution ${executionId} disappeared`));
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
if (currentExecution.status ===
|
|
38
|
-
currentExecution.result) {
|
|
37
|
+
if (currentExecution.status === 'completed' && currentExecution.result) {
|
|
39
38
|
clearInterval(checkInterval);
|
|
40
39
|
resolve(currentExecution.result);
|
|
41
40
|
}
|
|
42
|
-
else if (currentExecution.status ===
|
|
43
|
-
currentExecution.status ===
|
|
44
|
-
currentExecution.status ===
|
|
41
|
+
else if (currentExecution.status === 'failed' ||
|
|
42
|
+
currentExecution.status === 'canceled' ||
|
|
43
|
+
currentExecution.status === 'timeout') {
|
|
45
44
|
clearInterval(checkInterval);
|
|
46
45
|
reject(new Error(`Execution ${executionId} ${currentExecution.status}`));
|
|
47
46
|
}
|
|
@@ -53,7 +52,7 @@ class TaskManager {
|
|
|
53
52
|
if (!execution) {
|
|
54
53
|
throw new Error(`Execution ${executionId} not found`);
|
|
55
54
|
}
|
|
56
|
-
execution.status =
|
|
55
|
+
execution.status = 'completed';
|
|
57
56
|
execution.result = result;
|
|
58
57
|
execution.completedAt = Date.now();
|
|
59
58
|
}
|
|
@@ -62,11 +61,11 @@ class TaskManager {
|
|
|
62
61
|
if (!execution) {
|
|
63
62
|
throw new Error(`Execution ${executionId} not found`);
|
|
64
63
|
}
|
|
65
|
-
execution.status =
|
|
64
|
+
execution.status = 'failed';
|
|
66
65
|
execution.completedAt = Date.now();
|
|
67
66
|
execution.result = {
|
|
68
67
|
error: error.message,
|
|
69
|
-
status:
|
|
68
|
+
status: 'failed',
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
cancelExecution(executionId) {
|
|
@@ -74,13 +73,13 @@ class TaskManager {
|
|
|
74
73
|
if (!execution) {
|
|
75
74
|
throw new Error(`Execution ${executionId} not found`);
|
|
76
75
|
}
|
|
77
|
-
execution.status =
|
|
76
|
+
execution.status = 'canceled';
|
|
78
77
|
execution.completedAt = Date.now();
|
|
79
78
|
execution.abortController?.abort();
|
|
80
79
|
if (!execution.result) {
|
|
81
80
|
execution.result = {
|
|
82
|
-
status:
|
|
83
|
-
message:
|
|
81
|
+
status: 'canceled',
|
|
82
|
+
message: 'Execution was canceled',
|
|
84
83
|
};
|
|
85
84
|
}
|
|
86
85
|
}
|
|
@@ -96,14 +95,14 @@ class TaskManager {
|
|
|
96
95
|
scheduleTimeout(executionId, timeout = this.defaultTimeout) {
|
|
97
96
|
setTimeout(() => {
|
|
98
97
|
const execution = this.executionStates.get(executionId);
|
|
99
|
-
if (execution && execution.status ===
|
|
100
|
-
execution.status =
|
|
98
|
+
if (execution && execution.status === 'running') {
|
|
99
|
+
execution.status = 'timeout';
|
|
101
100
|
execution.completedAt = Date.now();
|
|
102
101
|
execution.abortController?.abort();
|
|
103
102
|
if (!execution.result) {
|
|
104
103
|
execution.result = {
|
|
105
|
-
status:
|
|
106
|
-
message:
|
|
104
|
+
status: 'timeout',
|
|
105
|
+
message: 'Execution timed out',
|
|
107
106
|
};
|
|
108
107
|
}
|
|
109
108
|
}
|
|
@@ -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 '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 private 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 (currentExecution.status === 'completed' && currentExecution.result) {\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(new Error(`Execution ${executionId} ${currentExecution.status}`));\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(executionId: string, timeout: number = this.defaultTimeout): 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}"],"names":[],"mappings":";;MAYa,WAAW,CAAA;AACd,IAAA,eAAe,GAAG,IAAI,GAAG,EAA8B;IACvD,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,IAAI,CAAC,mBAAmB,EAAE,EAAA;AAEhD,QAAA,MAAM,cAAc,GAAuB;YACzC,MAAM;AACN,YAAA,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AE,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 { Logger } from './utils/logger.js';
|
|
2
|
+
import type { PostHogAPIClient } from './posthog-api.js';
|
|
3
|
+
import type { AgentEvent } from './types.js';
|
|
4
4
|
interface ProgressMetadata {
|
|
5
5
|
totalSteps?: number;
|
|
6
6
|
}
|
|
@@ -15,6 +15,7 @@ export declare class TaskProgressReporter {
|
|
|
15
15
|
private logger;
|
|
16
16
|
private taskRun?;
|
|
17
17
|
private taskId?;
|
|
18
|
+
private outputLog;
|
|
18
19
|
private totalSteps?;
|
|
19
20
|
private lastLogEntry?;
|
|
20
21
|
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,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,kBAAkB,CAAC;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AU,GAAG,OAAO,CAAC,IAAI,CAAC;YA0OrC,MAAM;CAoCrB"}
|
|
@@ -9,9 +9,10 @@ class TaskProgressReporter {
|
|
|
9
9
|
logger;
|
|
10
10
|
taskRun;
|
|
11
11
|
taskId;
|
|
12
|
+
outputLog = [];
|
|
12
13
|
totalSteps;
|
|
13
14
|
lastLogEntry;
|
|
14
|
-
tokenBuffer =
|
|
15
|
+
tokenBuffer = '';
|
|
15
16
|
tokenCount = 0;
|
|
16
17
|
tokenFlushTimer;
|
|
17
18
|
TOKEN_BATCH_SIZE = 100;
|
|
@@ -21,7 +22,7 @@ class TaskProgressReporter {
|
|
|
21
22
|
LOG_APPEND_RETRY_BASE_DELAY_MS = 200;
|
|
22
23
|
constructor(posthogAPI, logger) {
|
|
23
24
|
this.posthogAPI = posthogAPI;
|
|
24
|
-
this.logger = logger.child(
|
|
25
|
+
this.logger = logger.child('TaskProgressReporter');
|
|
25
26
|
}
|
|
26
27
|
get runId() {
|
|
27
28
|
return this.taskRun?.id;
|
|
@@ -34,16 +35,14 @@ class TaskProgressReporter {
|
|
|
34
35
|
this.totalSteps = metadata.totalSteps;
|
|
35
36
|
try {
|
|
36
37
|
const run = await this.posthogAPI.createTaskRun(taskId, {
|
|
37
|
-
status:
|
|
38
|
+
status: 'started',
|
|
38
39
|
});
|
|
39
40
|
this.taskRun = run;
|
|
40
|
-
this.
|
|
41
|
+
this.outputLog = [];
|
|
42
|
+
this.logger.debug('Created task run', { taskId, runId: run.id });
|
|
41
43
|
}
|
|
42
44
|
catch (error) {
|
|
43
|
-
this.logger.warn(
|
|
44
|
-
taskId,
|
|
45
|
-
error: error.message,
|
|
46
|
-
});
|
|
45
|
+
this.logger.warn('Failed to create task run', { taskId, error: error.message });
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
async complete() {
|
|
@@ -52,27 +51,23 @@ class TaskProgressReporter {
|
|
|
52
51
|
await this.logWriteQueue;
|
|
53
52
|
}
|
|
54
53
|
catch (error) {
|
|
55
|
-
this.logger.debug(
|
|
56
|
-
error,
|
|
57
|
-
});
|
|
54
|
+
this.logger.debug('Pending logs failed to write during completion', { error });
|
|
58
55
|
}
|
|
59
56
|
if (this.tokenFlushTimer) {
|
|
60
57
|
clearTimeout(this.tokenFlushTimer);
|
|
61
58
|
this.tokenFlushTimer = undefined;
|
|
62
59
|
}
|
|
63
|
-
await this.update({ status:
|
|
60
|
+
await this.update({ status: 'completed' }, 'Task execution completed');
|
|
64
61
|
}
|
|
65
62
|
async fail(error) {
|
|
66
63
|
try {
|
|
67
64
|
await this.logWriteQueue;
|
|
68
65
|
}
|
|
69
66
|
catch (logError) {
|
|
70
|
-
this.logger.debug(
|
|
71
|
-
error: logError,
|
|
72
|
-
});
|
|
67
|
+
this.logger.debug('Pending logs failed to write during fail', { error: logError });
|
|
73
68
|
}
|
|
74
|
-
const message = typeof error ===
|
|
75
|
-
await this.update({ status:
|
|
69
|
+
const message = typeof error === 'string' ? error : error.message;
|
|
70
|
+
await this.update({ status: 'failed', error_message: message }, `Task execution failed: ${message}`);
|
|
76
71
|
}
|
|
77
72
|
async appendLog(line) {
|
|
78
73
|
await this.update({}, line);
|
|
@@ -82,10 +77,10 @@ class TaskProgressReporter {
|
|
|
82
77
|
return;
|
|
83
78
|
}
|
|
84
79
|
const buffer = this.tokenBuffer;
|
|
85
|
-
this.tokenBuffer =
|
|
80
|
+
this.tokenBuffer = '';
|
|
86
81
|
this.tokenCount = 0;
|
|
87
82
|
await this.appendLogEntry({
|
|
88
|
-
type:
|
|
83
|
+
type: 'token',
|
|
89
84
|
message: buffer,
|
|
90
85
|
});
|
|
91
86
|
}
|
|
@@ -96,7 +91,7 @@ class TaskProgressReporter {
|
|
|
96
91
|
this.tokenFlushTimer = setTimeout(() => {
|
|
97
92
|
this.tokenFlushTimer = undefined;
|
|
98
93
|
this.flushTokens().catch((err) => {
|
|
99
|
-
this.logger.warn(
|
|
94
|
+
this.logger.warn('Failed to flush tokens', { error: err });
|
|
100
95
|
});
|
|
101
96
|
}, this.TOKEN_FLUSH_INTERVAL_MS);
|
|
102
97
|
}
|
|
@@ -108,7 +103,7 @@ class TaskProgressReporter {
|
|
|
108
103
|
const runId = this.runId;
|
|
109
104
|
this.logWriteQueue = this.logWriteQueue
|
|
110
105
|
.catch((error) => {
|
|
111
|
-
this.logger.debug(
|
|
106
|
+
this.logger.debug('Previous log append failed', {
|
|
112
107
|
taskId,
|
|
113
108
|
runId,
|
|
114
109
|
error: error instanceof Error ? error.message : String(error),
|
|
@@ -127,7 +122,7 @@ class TaskProgressReporter {
|
|
|
127
122
|
return;
|
|
128
123
|
}
|
|
129
124
|
catch (error) {
|
|
130
|
-
this.logger.warn(
|
|
125
|
+
this.logger.warn('Failed to append log entry', {
|
|
131
126
|
taskId,
|
|
132
127
|
runId,
|
|
133
128
|
attempt,
|
|
@@ -137,7 +132,7 @@ class TaskProgressReporter {
|
|
|
137
132
|
if (attempt === this.LOG_APPEND_MAX_RETRIES) {
|
|
138
133
|
return;
|
|
139
134
|
}
|
|
140
|
-
const delayMs = this.LOG_APPEND_RETRY_BASE_DELAY_MS * 2
|
|
135
|
+
const delayMs = this.LOG_APPEND_RETRY_BASE_DELAY_MS * Math.pow(2, attempt - 1);
|
|
141
136
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
142
137
|
}
|
|
143
138
|
}
|
|
@@ -147,7 +142,7 @@ class TaskProgressReporter {
|
|
|
147
142
|
return;
|
|
148
143
|
}
|
|
149
144
|
switch (event.type) {
|
|
150
|
-
case
|
|
145
|
+
case 'token': {
|
|
151
146
|
// Batch tokens for efficiency
|
|
152
147
|
this.tokenBuffer += event.content;
|
|
153
148
|
this.tokenCount++;
|
|
@@ -163,9 +158,9 @@ class TaskProgressReporter {
|
|
|
163
158
|
}
|
|
164
159
|
return;
|
|
165
160
|
}
|
|
166
|
-
case
|
|
161
|
+
case 'content_block_start': {
|
|
167
162
|
await this.appendLogEntry({
|
|
168
|
-
type:
|
|
163
|
+
type: 'content_block_start',
|
|
169
164
|
message: JSON.stringify({
|
|
170
165
|
index: event.index,
|
|
171
166
|
contentType: event.contentType,
|
|
@@ -176,9 +171,9 @@ class TaskProgressReporter {
|
|
|
176
171
|
});
|
|
177
172
|
return;
|
|
178
173
|
}
|
|
179
|
-
case
|
|
174
|
+
case 'content_block_stop': {
|
|
180
175
|
await this.appendLogEntry({
|
|
181
|
-
type:
|
|
176
|
+
type: 'content_block_stop',
|
|
182
177
|
message: JSON.stringify({
|
|
183
178
|
index: event.index,
|
|
184
179
|
ts: event.ts,
|
|
@@ -186,9 +181,9 @@ class TaskProgressReporter {
|
|
|
186
181
|
});
|
|
187
182
|
return;
|
|
188
183
|
}
|
|
189
|
-
case
|
|
184
|
+
case 'message_start': {
|
|
190
185
|
await this.appendLogEntry({
|
|
191
|
-
type:
|
|
186
|
+
type: 'message_start',
|
|
192
187
|
message: JSON.stringify({
|
|
193
188
|
messageId: event.messageId,
|
|
194
189
|
model: event.model,
|
|
@@ -197,9 +192,9 @@ class TaskProgressReporter {
|
|
|
197
192
|
});
|
|
198
193
|
return;
|
|
199
194
|
}
|
|
200
|
-
case
|
|
195
|
+
case 'message_delta': {
|
|
201
196
|
await this.appendLogEntry({
|
|
202
|
-
type:
|
|
197
|
+
type: 'message_delta',
|
|
203
198
|
message: JSON.stringify({
|
|
204
199
|
stopReason: event.stopReason,
|
|
205
200
|
stopSequence: event.stopSequence,
|
|
@@ -209,16 +204,16 @@ class TaskProgressReporter {
|
|
|
209
204
|
});
|
|
210
205
|
return;
|
|
211
206
|
}
|
|
212
|
-
case
|
|
207
|
+
case 'message_stop': {
|
|
213
208
|
await this.appendLogEntry({
|
|
214
|
-
type:
|
|
209
|
+
type: 'message_stop',
|
|
215
210
|
message: JSON.stringify({ ts: event.ts }),
|
|
216
211
|
});
|
|
217
212
|
return;
|
|
218
213
|
}
|
|
219
|
-
case
|
|
214
|
+
case 'status': {
|
|
220
215
|
await this.appendLogEntry({
|
|
221
|
-
type:
|
|
216
|
+
type: 'status',
|
|
222
217
|
message: JSON.stringify({
|
|
223
218
|
phase: event.phase,
|
|
224
219
|
kind: event.kind,
|
|
@@ -232,9 +227,9 @@ class TaskProgressReporter {
|
|
|
232
227
|
});
|
|
233
228
|
return;
|
|
234
229
|
}
|
|
235
|
-
case
|
|
230
|
+
case 'artifact': {
|
|
236
231
|
await this.appendLogEntry({
|
|
237
|
-
type:
|
|
232
|
+
type: 'artifact',
|
|
238
233
|
message: JSON.stringify({
|
|
239
234
|
kind: event.kind,
|
|
240
235
|
content: event.content,
|
|
@@ -243,9 +238,9 @@ class TaskProgressReporter {
|
|
|
243
238
|
});
|
|
244
239
|
return;
|
|
245
240
|
}
|
|
246
|
-
case
|
|
241
|
+
case 'init': {
|
|
247
242
|
await this.appendLogEntry({
|
|
248
|
-
type:
|
|
243
|
+
type: 'init',
|
|
249
244
|
message: JSON.stringify({
|
|
250
245
|
model: event.model,
|
|
251
246
|
tools: event.tools,
|
|
@@ -257,9 +252,9 @@ class TaskProgressReporter {
|
|
|
257
252
|
});
|
|
258
253
|
return;
|
|
259
254
|
}
|
|
260
|
-
case
|
|
255
|
+
case 'metric': {
|
|
261
256
|
await this.appendLogEntry({
|
|
262
|
-
type:
|
|
257
|
+
type: 'metric',
|
|
263
258
|
message: JSON.stringify({
|
|
264
259
|
key: event.key,
|
|
265
260
|
value: event.value,
|
|
@@ -269,9 +264,9 @@ class TaskProgressReporter {
|
|
|
269
264
|
});
|
|
270
265
|
return;
|
|
271
266
|
}
|
|
272
|
-
case
|
|
267
|
+
case 'compact_boundary': {
|
|
273
268
|
await this.appendLogEntry({
|
|
274
|
-
type:
|
|
269
|
+
type: 'compact_boundary',
|
|
275
270
|
message: JSON.stringify({
|
|
276
271
|
trigger: event.trigger,
|
|
277
272
|
preTokens: event.preTokens,
|
|
@@ -280,9 +275,9 @@ class TaskProgressReporter {
|
|
|
280
275
|
});
|
|
281
276
|
return;
|
|
282
277
|
}
|
|
283
|
-
case
|
|
278
|
+
case 'tool_call': {
|
|
284
279
|
await this.appendLogEntry({
|
|
285
|
-
type:
|
|
280
|
+
type: 'tool_call',
|
|
286
281
|
message: JSON.stringify({
|
|
287
282
|
toolName: event.toolName,
|
|
288
283
|
callId: event.callId,
|
|
@@ -293,9 +288,9 @@ class TaskProgressReporter {
|
|
|
293
288
|
});
|
|
294
289
|
return;
|
|
295
290
|
}
|
|
296
|
-
case
|
|
291
|
+
case 'tool_result': {
|
|
297
292
|
await this.appendLogEntry({
|
|
298
|
-
type:
|
|
293
|
+
type: 'tool_result',
|
|
299
294
|
message: JSON.stringify({
|
|
300
295
|
toolName: event.toolName,
|
|
301
296
|
callId: event.callId,
|
|
@@ -307,9 +302,9 @@ class TaskProgressReporter {
|
|
|
307
302
|
});
|
|
308
303
|
return;
|
|
309
304
|
}
|
|
310
|
-
case
|
|
305
|
+
case 'error': {
|
|
311
306
|
await this.appendLogEntry({
|
|
312
|
-
type:
|
|
307
|
+
type: 'error',
|
|
313
308
|
message: JSON.stringify({
|
|
314
309
|
message: event.message,
|
|
315
310
|
errorType: event.errorType,
|
|
@@ -319,9 +314,9 @@ class TaskProgressReporter {
|
|
|
319
314
|
});
|
|
320
315
|
return;
|
|
321
316
|
}
|
|
322
|
-
case
|
|
317
|
+
case 'done': {
|
|
323
318
|
await this.appendLogEntry({
|
|
324
|
-
type:
|
|
319
|
+
type: 'done',
|
|
325
320
|
message: JSON.stringify({
|
|
326
321
|
result: event.result,
|
|
327
322
|
durationMs: event.durationMs,
|
|
@@ -336,9 +331,9 @@ class TaskProgressReporter {
|
|
|
336
331
|
});
|
|
337
332
|
return;
|
|
338
333
|
}
|
|
339
|
-
case
|
|
334
|
+
case 'user_message': {
|
|
340
335
|
await this.appendLogEntry({
|
|
341
|
-
type:
|
|
336
|
+
type: 'user_message',
|
|
342
337
|
message: JSON.stringify({
|
|
343
338
|
content: event.content,
|
|
344
339
|
isSynthetic: event.isSynthetic,
|
|
@@ -347,13 +342,13 @@ class TaskProgressReporter {
|
|
|
347
342
|
});
|
|
348
343
|
return;
|
|
349
344
|
}
|
|
350
|
-
case
|
|
345
|
+
case 'raw_sdk_event': {
|
|
351
346
|
// Skip raw SDK events - too verbose for persistence
|
|
352
347
|
return;
|
|
353
348
|
}
|
|
354
349
|
default:
|
|
355
350
|
// For any unfamiliar event types, log them as-is
|
|
356
|
-
this.logger.debug(
|
|
351
|
+
this.logger.debug('Unknown event type', { type: event.type });
|
|
357
352
|
return;
|
|
358
353
|
}
|
|
359
354
|
}
|
|
@@ -365,12 +360,12 @@ class TaskProgressReporter {
|
|
|
365
360
|
if (logLine && logLine !== this.lastLogEntry) {
|
|
366
361
|
try {
|
|
367
362
|
await this.posthogAPI.appendTaskRunLog(this.taskId, this.runId, [
|
|
368
|
-
{ type:
|
|
363
|
+
{ type: 'info', message: logLine }
|
|
369
364
|
]);
|
|
370
365
|
this.lastLogEntry = logLine;
|
|
371
366
|
}
|
|
372
367
|
catch (error) {
|
|
373
|
-
this.logger.warn(
|
|
368
|
+
this.logger.warn('Failed to append log entry', {
|
|
374
369
|
taskId: this.taskId,
|
|
375
370
|
runId: this.runId,
|
|
376
371
|
error: error.message,
|
|
@@ -384,7 +379,7 @@ class TaskProgressReporter {
|
|
|
384
379
|
this.taskRun = run;
|
|
385
380
|
}
|
|
386
381
|
catch (error) {
|
|
387
|
-
this.logger.warn(
|
|
382
|
+
this.logger.warn('Failed to update task run', {
|
|
388
383
|
taskId: this.taskId,
|
|
389
384
|
runId: this.runId,
|
|
390
385
|
error: error.message,
|
|
@@ -1 +1 @@
|
|
|
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,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;AA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;YAAE,OAAO,KAAK,EAAE;AACd,gBAAA,IAAI,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;AACD;;;;"}
|
|
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,GAA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