@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/src/agents/execution.ts
CHANGED
package/src/agents/planning.ts
CHANGED
|
@@ -57,4 +57,4 @@ If research findings, context files, or reference materials are provided:
|
|
|
57
57
|
- Follow patterns and approaches identified in research
|
|
58
58
|
- Build upon or refine any existing planning work
|
|
59
59
|
- Reference specific files and components mentioned in context
|
|
60
|
-
</context_integration>`;
|
|
60
|
+
</context_integration>`;
|
package/src/agents/research.ts
CHANGED
|
@@ -158,3 +158,4 @@ Reason: Options request user input instead of being actionable choices. Should b
|
|
|
158
158
|
Reason: "Let me specify" requires user input. Should be "Primary blue (#0066FF, existing theme)" or "Secondary gray (#6B7280, existing theme)"
|
|
159
159
|
</bad_example>
|
|
160
160
|
</question_examples>`;
|
|
161
|
+
|
package/src/file-manager.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { promises as fs } from
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import { Logger } from
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { join, extname } from 'path';
|
|
3
|
+
import type { SupportingFile, ResearchEvaluation } from './types.js';
|
|
4
|
+
import { Logger } from './utils/logger.js';
|
|
5
5
|
|
|
6
6
|
export interface TaskFile {
|
|
7
7
|
name: string;
|
|
8
8
|
content: string;
|
|
9
|
-
type:
|
|
9
|
+
type: 'plan' | 'context' | 'reference' | 'output' | 'artifact';
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface LocalArtifact {
|
|
13
13
|
name: string;
|
|
14
14
|
content: string;
|
|
15
|
-
type: TaskFile[
|
|
15
|
+
type: TaskFile['type'];
|
|
16
16
|
contentType: string;
|
|
17
17
|
size: number;
|
|
18
18
|
}
|
|
@@ -23,12 +23,11 @@ export class PostHogFileManager {
|
|
|
23
23
|
|
|
24
24
|
constructor(repositoryPath: string, logger?: Logger) {
|
|
25
25
|
this.repositoryPath = repositoryPath;
|
|
26
|
-
this.logger =
|
|
27
|
-
logger || new Logger({ debug: false, prefix: "[FileManager]" });
|
|
26
|
+
this.logger = logger || new Logger({ debug: false, prefix: '[FileManager]' });
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
private getTaskDirectory(taskId: string): string {
|
|
31
|
-
return join(this.repositoryPath,
|
|
30
|
+
return join(this.repositoryPath, '.posthog', taskId);
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
private getTaskFilePath(taskId: string, fileName: string): string {
|
|
@@ -48,23 +47,23 @@ export class PostHogFileManager {
|
|
|
48
47
|
await this.ensureTaskDirectory(taskId);
|
|
49
48
|
const filePath = this.getTaskFilePath(taskId, file.name);
|
|
50
49
|
|
|
51
|
-
this.logger.debug(
|
|
50
|
+
this.logger.debug('Writing task file', {
|
|
52
51
|
filePath,
|
|
53
52
|
contentLength: file.content.length,
|
|
54
|
-
contentType: typeof file.content
|
|
53
|
+
contentType: typeof file.content
|
|
55
54
|
});
|
|
56
55
|
|
|
57
|
-
await fs.writeFile(filePath, file.content,
|
|
56
|
+
await fs.writeFile(filePath, file.content, 'utf8');
|
|
58
57
|
|
|
59
|
-
this.logger.debug(
|
|
58
|
+
this.logger.debug('File written successfully', { filePath });
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
async readTaskFile(taskId: string, fileName: string): Promise<string | null> {
|
|
63
62
|
try {
|
|
64
63
|
const filePath = this.getTaskFilePath(taskId, fileName);
|
|
65
|
-
return await fs.readFile(filePath,
|
|
64
|
+
return await fs.readFile(filePath, 'utf8');
|
|
66
65
|
} catch (error) {
|
|
67
|
-
if ((error as NodeJS.ErrnoException).code ===
|
|
66
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
68
67
|
return null;
|
|
69
68
|
}
|
|
70
69
|
throw error;
|
|
@@ -75,9 +74,9 @@ export class PostHogFileManager {
|
|
|
75
74
|
try {
|
|
76
75
|
const taskDir = this.getTaskDirectory(taskId);
|
|
77
76
|
const files = await fs.readdir(taskDir);
|
|
78
|
-
return files.filter(
|
|
77
|
+
return files.filter(file => !file.startsWith('.'));
|
|
79
78
|
} catch (error) {
|
|
80
|
-
if ((error as NodeJS.ErrnoException).code ===
|
|
79
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
81
80
|
return [];
|
|
82
81
|
}
|
|
83
82
|
throw error;
|
|
@@ -89,7 +88,7 @@ export class PostHogFileManager {
|
|
|
89
88
|
const filePath = this.getTaskFilePath(taskId, fileName);
|
|
90
89
|
await fs.unlink(filePath);
|
|
91
90
|
} catch (error) {
|
|
92
|
-
if ((error as NodeJS.ErrnoException).code !==
|
|
91
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
93
92
|
throw error;
|
|
94
93
|
}
|
|
95
94
|
}
|
|
@@ -110,7 +109,7 @@ export class PostHogFileManager {
|
|
|
110
109
|
const taskDir = this.getTaskDirectory(taskId);
|
|
111
110
|
await fs.rm(taskDir, { recursive: true, force: true });
|
|
112
111
|
} catch (error) {
|
|
113
|
-
if ((error as NodeJS.ErrnoException).code !==
|
|
112
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
|
114
113
|
throw error;
|
|
115
114
|
}
|
|
116
115
|
}
|
|
@@ -118,51 +117,51 @@ export class PostHogFileManager {
|
|
|
118
117
|
|
|
119
118
|
// Convenience methods for common file types
|
|
120
119
|
async writePlan(taskId: string, plan: string): Promise<void> {
|
|
121
|
-
this.logger.debug(
|
|
120
|
+
this.logger.debug('Writing plan', {
|
|
122
121
|
taskId,
|
|
123
122
|
planLength: plan.length,
|
|
124
|
-
contentPreview: plan.substring(0, 200)
|
|
123
|
+
contentPreview: plan.substring(0, 200)
|
|
125
124
|
});
|
|
126
125
|
|
|
127
126
|
await this.writeTaskFile(taskId, {
|
|
128
|
-
name:
|
|
127
|
+
name: 'plan.md',
|
|
129
128
|
content: plan,
|
|
130
|
-
type:
|
|
129
|
+
type: 'plan'
|
|
131
130
|
});
|
|
132
131
|
|
|
133
|
-
this.logger.info(
|
|
132
|
+
this.logger.info('Plan file written', { taskId });
|
|
134
133
|
}
|
|
135
134
|
|
|
136
135
|
async readPlan(taskId: string): Promise<string | null> {
|
|
137
|
-
return await this.readTaskFile(taskId,
|
|
136
|
+
return await this.readTaskFile(taskId, 'plan.md');
|
|
138
137
|
}
|
|
139
138
|
|
|
140
139
|
async writeContext(taskId: string, context: string): Promise<void> {
|
|
141
140
|
await this.writeTaskFile(taskId, {
|
|
142
|
-
name:
|
|
141
|
+
name: 'context.md',
|
|
143
142
|
content: context,
|
|
144
|
-
type:
|
|
143
|
+
type: 'context'
|
|
145
144
|
});
|
|
146
145
|
}
|
|
147
146
|
|
|
148
147
|
async readContext(taskId: string): Promise<string | null> {
|
|
149
|
-
return await this.readTaskFile(taskId,
|
|
148
|
+
return await this.readTaskFile(taskId, 'context.md');
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
async writeRequirements(taskId: string, requirements: string): Promise<void> {
|
|
153
152
|
await this.writeTaskFile(taskId, {
|
|
154
|
-
name:
|
|
153
|
+
name: 'requirements.md',
|
|
155
154
|
content: requirements,
|
|
156
|
-
type:
|
|
155
|
+
type: 'reference'
|
|
157
156
|
});
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
async readRequirements(taskId: string): Promise<string | null> {
|
|
161
|
-
return await this.readTaskFile(taskId,
|
|
160
|
+
return await this.readTaskFile(taskId, 'requirements.md');
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
async writeResearch(taskId: string, data: ResearchEvaluation): Promise<void> {
|
|
165
|
-
this.logger.debug(
|
|
164
|
+
this.logger.debug('Writing research', {
|
|
166
165
|
taskId,
|
|
167
166
|
score: data.actionabilityScore,
|
|
168
167
|
hasQuestions: !!data.questions,
|
|
@@ -171,13 +170,13 @@ export class PostHogFileManager {
|
|
|
171
170
|
});
|
|
172
171
|
|
|
173
172
|
await this.writeTaskFile(taskId, {
|
|
174
|
-
name:
|
|
173
|
+
name: 'research.json',
|
|
175
174
|
content: JSON.stringify(data, null, 2),
|
|
176
|
-
type:
|
|
175
|
+
type: 'artifact'
|
|
177
176
|
});
|
|
178
177
|
|
|
179
|
-
this.logger.info(
|
|
180
|
-
taskId,
|
|
178
|
+
this.logger.info('Research file written', {
|
|
179
|
+
taskId,
|
|
181
180
|
score: data.actionabilityScore,
|
|
182
181
|
hasQuestions: !!data.questions,
|
|
183
182
|
answered: data.answered ?? false,
|
|
@@ -186,28 +185,28 @@ export class PostHogFileManager {
|
|
|
186
185
|
|
|
187
186
|
async readResearch(taskId: string): Promise<ResearchEvaluation | null> {
|
|
188
187
|
try {
|
|
189
|
-
const content = await this.readTaskFile(taskId,
|
|
190
|
-
return content ?
|
|
188
|
+
const content = await this.readTaskFile(taskId, 'research.json');
|
|
189
|
+
return content ? JSON.parse(content) as ResearchEvaluation : null;
|
|
191
190
|
} catch (error) {
|
|
192
|
-
this.logger.debug(
|
|
191
|
+
this.logger.debug('Failed to parse research.json', { error });
|
|
193
192
|
return null;
|
|
194
193
|
}
|
|
195
194
|
}
|
|
196
195
|
|
|
197
196
|
async writeTodos(taskId: string, data: any): Promise<void> {
|
|
198
|
-
this.logger.debug(
|
|
197
|
+
this.logger.debug('Writing todos', {
|
|
199
198
|
taskId,
|
|
200
199
|
total: data.metadata?.total ?? 0,
|
|
201
200
|
completed: data.metadata?.completed ?? 0,
|
|
202
201
|
});
|
|
203
202
|
|
|
204
203
|
await this.writeTaskFile(taskId, {
|
|
205
|
-
name:
|
|
204
|
+
name: 'todos.json',
|
|
206
205
|
content: JSON.stringify(data, null, 2),
|
|
207
|
-
type:
|
|
206
|
+
type: 'artifact'
|
|
208
207
|
});
|
|
209
208
|
|
|
210
|
-
this.logger.info(
|
|
209
|
+
this.logger.info('Todos file written', {
|
|
211
210
|
taskId,
|
|
212
211
|
total: data.metadata?.total ?? 0,
|
|
213
212
|
completed: data.metadata?.completed ?? 0,
|
|
@@ -216,10 +215,10 @@ export class PostHogFileManager {
|
|
|
216
215
|
|
|
217
216
|
async readTodos(taskId: string): Promise<any | null> {
|
|
218
217
|
try {
|
|
219
|
-
const content = await this.readTaskFile(taskId,
|
|
218
|
+
const content = await this.readTaskFile(taskId, 'todos.json');
|
|
220
219
|
return content ? JSON.parse(content) : null;
|
|
221
220
|
} catch (error) {
|
|
222
|
-
this.logger.debug(
|
|
221
|
+
this.logger.debug('Failed to parse todos.json', { error });
|
|
223
222
|
return null;
|
|
224
223
|
}
|
|
225
224
|
}
|
|
@@ -227,22 +226,22 @@ export class PostHogFileManager {
|
|
|
227
226
|
async getTaskFiles(taskId: string): Promise<SupportingFile[]> {
|
|
228
227
|
const fileNames = await this.listTaskFiles(taskId);
|
|
229
228
|
const files: SupportingFile[] = [];
|
|
230
|
-
|
|
229
|
+
|
|
231
230
|
for (const fileName of fileNames) {
|
|
232
231
|
const content = await this.readTaskFile(taskId, fileName);
|
|
233
232
|
if (content !== null) {
|
|
234
233
|
// Determine type based on file name
|
|
235
234
|
const type = this.resolveFileType(fileName);
|
|
236
|
-
|
|
235
|
+
|
|
237
236
|
files.push({
|
|
238
237
|
name: fileName,
|
|
239
238
|
content,
|
|
240
239
|
type,
|
|
241
|
-
created_at: new Date().toISOString()
|
|
240
|
+
created_at: new Date().toISOString() // Could be enhanced with file stats
|
|
242
241
|
});
|
|
243
242
|
}
|
|
244
243
|
}
|
|
245
|
-
|
|
244
|
+
|
|
246
245
|
return files;
|
|
247
246
|
}
|
|
248
247
|
|
|
@@ -258,7 +257,7 @@ export class PostHogFileManager {
|
|
|
258
257
|
|
|
259
258
|
const type = this.resolveFileType(fileName);
|
|
260
259
|
const contentType = this.inferContentType(fileName);
|
|
261
|
-
const size = Buffer.byteLength(content,
|
|
260
|
+
const size = Buffer.byteLength(content, 'utf8');
|
|
262
261
|
|
|
263
262
|
artifacts.push({
|
|
264
263
|
name: fileName,
|
|
@@ -272,26 +271,26 @@ export class PostHogFileManager {
|
|
|
272
271
|
return artifacts;
|
|
273
272
|
}
|
|
274
273
|
|
|
275
|
-
private resolveFileType(fileName: string): TaskFile[
|
|
276
|
-
if (fileName ===
|
|
277
|
-
if (fileName ===
|
|
278
|
-
if (fileName ===
|
|
279
|
-
if (fileName.startsWith(
|
|
280
|
-
if (fileName.endsWith(
|
|
281
|
-
return
|
|
274
|
+
private resolveFileType(fileName: string): TaskFile['type'] {
|
|
275
|
+
if (fileName === 'plan.md') return 'plan';
|
|
276
|
+
if (fileName === 'context.md') return 'context';
|
|
277
|
+
if (fileName === 'requirements.md') return 'reference';
|
|
278
|
+
if (fileName.startsWith('output_')) return 'output';
|
|
279
|
+
if (fileName.endsWith('.md')) return 'reference';
|
|
280
|
+
return 'artifact';
|
|
282
281
|
}
|
|
283
282
|
|
|
284
283
|
private inferContentType(fileName: string): string {
|
|
285
284
|
const extension = extname(fileName).toLowerCase();
|
|
286
285
|
switch (extension) {
|
|
287
|
-
case
|
|
288
|
-
return
|
|
289
|
-
case
|
|
290
|
-
return
|
|
291
|
-
case
|
|
292
|
-
return
|
|
286
|
+
case '.md':
|
|
287
|
+
return 'text/markdown';
|
|
288
|
+
case '.json':
|
|
289
|
+
return 'application/json';
|
|
290
|
+
case '.txt':
|
|
291
|
+
return 'text/plain';
|
|
293
292
|
default:
|
|
294
|
-
return
|
|
293
|
+
return 'text/plain';
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
296
|
}
|