@posthog/agent 1.9.0 → 1.11.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/README.md +8 -5
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/src/agent-registry.d.ts.map +1 -1
- package/dist/src/agent-registry.js +6 -0
- package/dist/src/agent-registry.js.map +1 -1
- package/dist/src/agent.d.ts +5 -0
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +370 -29
- package/dist/src/agent.js.map +1 -1
- package/dist/src/agents/research.d.ts +2 -0
- package/dist/src/agents/research.d.ts.map +1 -0
- package/dist/src/agents/research.js +105 -0
- package/dist/src/agents/research.js.map +1 -0
- package/dist/src/file-manager.d.ts +19 -0
- package/dist/src/file-manager.d.ts.map +1 -1
- package/dist/src/file-manager.js +39 -0
- package/dist/src/file-manager.js.map +1 -1
- package/dist/src/git-manager.d.ts +4 -0
- package/dist/src/git-manager.d.ts.map +1 -1
- package/dist/src/git-manager.js +41 -0
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.d.ts +16 -57
- package/dist/src/posthog-api.d.ts.map +1 -1
- package/dist/src/posthog-api.js +38 -38
- package/dist/src/posthog-api.js.map +1 -1
- package/dist/src/prompt-builder.d.ts +1 -0
- package/dist/src/prompt-builder.d.ts.map +1 -1
- package/dist/src/prompt-builder.js +40 -0
- package/dist/src/prompt-builder.js.map +1 -1
- package/dist/src/stage-executor.d.ts +1 -0
- package/dist/src/stage-executor.d.ts.map +1 -1
- package/dist/src/stage-executor.js +43 -0
- package/dist/src/stage-executor.js.map +1 -1
- package/dist/src/structured-extraction.d.ts +22 -0
- package/dist/src/structured-extraction.d.ts.map +1 -0
- package/dist/src/structured-extraction.js +136 -0
- package/dist/src/structured-extraction.js.map +1 -0
- package/dist/src/task-progress-reporter.d.ts +2 -5
- package/dist/src/task-progress-reporter.d.ts.map +1 -1
- package/dist/src/task-progress-reporter.js +37 -39
- package/dist/src/task-progress-reporter.js.map +1 -1
- package/dist/src/types.d.ts +31 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/workflow-types.d.ts +1 -1
- package/dist/src/workflow-types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/agent-registry.ts +6 -0
- package/src/agent.ts +409 -26
- package/src/agents/research.ts +103 -0
- package/src/file-manager.ts +64 -0
- package/src/git-manager.ts +52 -0
- package/src/posthog-api.ts +57 -92
- package/src/prompt-builder.ts +53 -0
- package/src/stage-executor.ts +50 -0
- package/src/structured-extraction.ts +167 -0
- package/src/task-progress-reporter.ts +38 -44
- package/src/types.ts +39 -3
- package/src/workflow-types.ts +1 -1
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { Logger } from './utils/logger.js';
|
|
2
|
-
import type { PostHogAPIClient,
|
|
3
|
-
import type { AgentEvent } from './types.js';
|
|
2
|
+
import type { PostHogAPIClient, TaskRunUpdate } from './posthog-api.js';
|
|
3
|
+
import type { AgentEvent, TaskRun } from './types.js';
|
|
4
4
|
|
|
5
5
|
interface ProgressMetadata {
|
|
6
|
-
workflowId?: string;
|
|
7
|
-
workflowRunId?: string;
|
|
8
|
-
activityId?: string;
|
|
9
6
|
totalSteps?: number;
|
|
10
7
|
}
|
|
11
8
|
|
|
@@ -18,7 +15,7 @@ interface ProgressMetadata {
|
|
|
18
15
|
export class TaskProgressReporter {
|
|
19
16
|
private posthogAPI?: PostHogAPIClient;
|
|
20
17
|
private logger: Logger;
|
|
21
|
-
private
|
|
18
|
+
private taskRun?: TaskRun;
|
|
22
19
|
private taskId?: string;
|
|
23
20
|
private outputLog: string[] = [];
|
|
24
21
|
private totalSteps?: number;
|
|
@@ -29,8 +26,8 @@ export class TaskProgressReporter {
|
|
|
29
26
|
this.logger = logger.child('TaskProgressReporter');
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
get
|
|
33
|
-
return this.
|
|
29
|
+
get runId(): string | undefined {
|
|
30
|
+
return this.taskRun?.id;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
async start(taskId: string, metadata: ProgressMetadata = {}): Promise<void> {
|
|
@@ -42,37 +39,27 @@ export class TaskProgressReporter {
|
|
|
42
39
|
this.totalSteps = metadata.totalSteps;
|
|
43
40
|
|
|
44
41
|
try {
|
|
45
|
-
const
|
|
42
|
+
const run = await this.posthogAPI.createTaskRun(taskId, {
|
|
46
43
|
status: 'started',
|
|
47
|
-
|
|
48
|
-
total_steps: metadata.totalSteps ?? 0,
|
|
49
|
-
completed_steps: 0,
|
|
50
|
-
workflow_id: metadata.workflowId,
|
|
51
|
-
workflow_run_id: metadata.workflowRunId,
|
|
52
|
-
activity_id: metadata.activityId,
|
|
53
|
-
output_log: '',
|
|
44
|
+
log: [],
|
|
54
45
|
});
|
|
55
|
-
this.
|
|
56
|
-
this.outputLog =
|
|
57
|
-
this.logger.debug('Created task
|
|
46
|
+
this.taskRun = run;
|
|
47
|
+
this.outputLog = [];
|
|
48
|
+
this.logger.debug('Created task run', { taskId, runId: run.id });
|
|
58
49
|
} catch (error) {
|
|
59
|
-
this.logger.warn('Failed to create task
|
|
50
|
+
this.logger.warn('Failed to create task run', { taskId, error: (error as Error).message });
|
|
60
51
|
}
|
|
61
52
|
}
|
|
62
53
|
|
|
63
54
|
async stageStarted(stageKey: string, stageIndex: number): Promise<void> {
|
|
64
55
|
await this.update({
|
|
65
56
|
status: 'in_progress',
|
|
66
|
-
current_step: stageKey,
|
|
67
|
-
completed_steps: Math.min(stageIndex, this.totalSteps ?? stageIndex),
|
|
68
57
|
}, `Stage started: ${stageKey}`);
|
|
69
58
|
}
|
|
70
59
|
|
|
71
60
|
async stageCompleted(stageKey: string, completedStages: number): Promise<void> {
|
|
72
61
|
await this.update({
|
|
73
62
|
status: 'in_progress',
|
|
74
|
-
current_step: stageKey,
|
|
75
|
-
completed_steps: Math.min(completedStages, this.totalSteps ?? completedStages),
|
|
76
63
|
}, `Stage completed: ${stageKey}`);
|
|
77
64
|
}
|
|
78
65
|
|
|
@@ -97,7 +84,7 @@ export class TaskProgressReporter {
|
|
|
97
84
|
}
|
|
98
85
|
|
|
99
86
|
async complete(): Promise<void> {
|
|
100
|
-
await this.update({ status: 'completed'
|
|
87
|
+
await this.update({ status: 'completed' }, 'Workflow execution completed');
|
|
101
88
|
}
|
|
102
89
|
|
|
103
90
|
async fail(error: Error | string): Promise<void> {
|
|
@@ -110,7 +97,7 @@ export class TaskProgressReporter {
|
|
|
110
97
|
}
|
|
111
98
|
|
|
112
99
|
async recordEvent(event: AgentEvent): Promise<void> {
|
|
113
|
-
if (!this.posthogAPI || !this.
|
|
100
|
+
if (!this.posthogAPI || !this.runId || !this.taskId) {
|
|
114
101
|
return;
|
|
115
102
|
}
|
|
116
103
|
|
|
@@ -178,32 +165,39 @@ export class TaskProgressReporter {
|
|
|
178
165
|
}
|
|
179
166
|
}
|
|
180
167
|
|
|
181
|
-
private async update(update:
|
|
182
|
-
if (!this.posthogAPI || !this.
|
|
168
|
+
private async update(update: TaskRunUpdate, logLine?: string): Promise<void> {
|
|
169
|
+
if (!this.posthogAPI || !this.runId || !this.taskId) {
|
|
183
170
|
return;
|
|
184
171
|
}
|
|
185
172
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
173
|
+
// If there's a log line, append it separately using the append_log endpoint
|
|
174
|
+
if (logLine && logLine !== this.lastLogEntry) {
|
|
175
|
+
try {
|
|
176
|
+
await this.posthogAPI.appendTaskRunLog(this.taskId, this.runId, [
|
|
177
|
+
{ type: 'info', message: logLine }
|
|
178
|
+
]);
|
|
189
179
|
this.lastLogEntry = logLine;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.logger.warn('Failed to append log entry', {
|
|
182
|
+
taskId: this.taskId,
|
|
183
|
+
runId: this.runId,
|
|
184
|
+
error: (error as Error).message,
|
|
185
|
+
});
|
|
190
186
|
}
|
|
191
|
-
update.output_log = this.outputLog.join('\n');
|
|
192
187
|
}
|
|
193
188
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
189
|
+
// Update other fields if provided
|
|
190
|
+
if (Object.keys(update).length > 0) {
|
|
191
|
+
try {
|
|
192
|
+
const run = await this.posthogAPI.updateTaskRun(this.taskId, this.runId, update);
|
|
193
|
+
this.taskRun = run;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
this.logger.warn('Failed to update task run', {
|
|
196
|
+
taskId: this.taskId,
|
|
197
|
+
runId: this.runId,
|
|
198
|
+
error: (error as Error).message,
|
|
199
|
+
});
|
|
200
200
|
}
|
|
201
|
-
} catch (error) {
|
|
202
|
-
this.logger.warn('Failed to update task progress record', {
|
|
203
|
-
taskId: this.taskId,
|
|
204
|
-
progressId: this.progressId,
|
|
205
|
-
error: (error as Error).message,
|
|
206
|
-
});
|
|
207
201
|
}
|
|
208
202
|
}
|
|
209
203
|
|
package/src/types.ts
CHANGED
|
@@ -6,15 +6,43 @@ export interface Task {
|
|
|
6
6
|
origin_product: 'error_tracking' | 'eval_clusters' | 'user_created' | 'support_queue' | 'session_summaries';
|
|
7
7
|
position?: number;
|
|
8
8
|
workflow?: string | null;
|
|
9
|
-
current_stage?: string | null;
|
|
10
9
|
github_integration?: number | null;
|
|
11
10
|
repository_config?: unknown; // JSONField
|
|
12
11
|
repository_list: string;
|
|
13
12
|
primary_repository: string;
|
|
14
|
-
github_branch: string | null;
|
|
15
|
-
github_pr_url: string | null;
|
|
16
13
|
created_at: string;
|
|
17
14
|
updated_at: string;
|
|
15
|
+
|
|
16
|
+
// DEPRECATED: These fields have been moved to TaskRun
|
|
17
|
+
// Use task.latest_run instead
|
|
18
|
+
current_stage?: string | null;
|
|
19
|
+
github_branch?: string | null;
|
|
20
|
+
github_pr_url?: string | null;
|
|
21
|
+
latest_run?: TaskRun;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Log entry structure for TaskRun.log
|
|
25
|
+
export interface LogEntry {
|
|
26
|
+
type: string; // e.g., "info", "warning", "error", "success", "debug"
|
|
27
|
+
message: string;
|
|
28
|
+
[key: string]: unknown; // Allow additional fields
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// TaskRun model - represents individual execution runs of tasks
|
|
32
|
+
export interface TaskRun {
|
|
33
|
+
id: string;
|
|
34
|
+
task: string; // Task ID
|
|
35
|
+
team: number;
|
|
36
|
+
branch: string | null;
|
|
37
|
+
current_stage: string | null; // WorkflowStage ID
|
|
38
|
+
status: 'started' | 'in_progress' | 'completed' | 'failed';
|
|
39
|
+
log: LogEntry[]; // Array of log entry objects
|
|
40
|
+
error_message: string | null;
|
|
41
|
+
output: Record<string, unknown> | null; // Structured output (PR URL, commit SHA, etc.)
|
|
42
|
+
state: Record<string, unknown>; // Intermediate run state (defaults to {}, never null)
|
|
43
|
+
created_at: string;
|
|
44
|
+
updated_at: string;
|
|
45
|
+
completed_at: string | null;
|
|
18
46
|
}
|
|
19
47
|
|
|
20
48
|
export interface SupportingFile {
|
|
@@ -38,6 +66,14 @@ export interface ExecutionOptions {
|
|
|
38
66
|
permissionMode?: PermissionMode;
|
|
39
67
|
}
|
|
40
68
|
|
|
69
|
+
export interface TaskExecutionOptions {
|
|
70
|
+
repositoryPath?: string;
|
|
71
|
+
permissionMode?: PermissionMode;
|
|
72
|
+
isCloudMode?: boolean; // Determines local vs cloud behavior (local pauses after each phase)
|
|
73
|
+
autoProgress?: boolean;
|
|
74
|
+
queryOverrides?: Record<string, any>;
|
|
75
|
+
}
|
|
76
|
+
|
|
41
77
|
// Base event with timestamp
|
|
42
78
|
interface BaseEvent {
|
|
43
79
|
ts: number;
|
package/src/workflow-types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PermissionMode, AgentEvent } from './types.js';
|
|
2
2
|
|
|
3
|
-
export type AgentType = 'planning' | 'execution' | 'review' | 'testing';
|
|
3
|
+
export type AgentType = 'research' | 'planning' | 'execution' | 'review' | 'testing';
|
|
4
4
|
|
|
5
5
|
export interface AgentDefinition {
|
|
6
6
|
id: string;
|