@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.
Files changed (116) hide show
  1. package/LICENSE +33 -0
  2. package/dist/index.d.ts +11 -11
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -3
  5. package/dist/src/adapters/claude/claude-adapter.d.ts +3 -3
  6. package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
  7. package/dist/src/adapters/claude/claude-adapter.js +111 -156
  8. package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
  9. package/dist/src/adapters/claude/tool-mapper.d.ts +1 -1
  10. package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -1
  11. package/dist/src/adapters/claude/tool-mapper.js.map +1 -1
  12. package/dist/src/adapters/types.d.ts +1 -1
  13. package/dist/src/adapters/types.d.ts.map +1 -1
  14. package/dist/src/agent.d.ts +7 -7
  15. package/dist/src/agent.d.ts.map +1 -1
  16. package/dist/src/agent.js +85 -143
  17. package/dist/src/agent.js.map +1 -1
  18. package/dist/src/agents/execution.js.map +1 -1
  19. package/dist/src/agents/planning.js.map +1 -1
  20. package/dist/src/agents/research.js.map +1 -1
  21. package/dist/src/file-manager.d.ts +4 -4
  22. package/dist/src/file-manager.d.ts.map +1 -1
  23. package/dist/src/file-manager.js +58 -59
  24. package/dist/src/file-manager.js.map +1 -1
  25. package/dist/src/git-manager.d.ts +1 -1
  26. package/dist/src/git-manager.d.ts.map +1 -1
  27. package/dist/src/git-manager.js +70 -87
  28. package/dist/src/git-manager.js.map +1 -1
  29. package/dist/src/posthog-api.d.ts +3 -2
  30. package/dist/src/posthog-api.d.ts.map +1 -1
  31. package/dist/src/posthog-api.js +22 -22
  32. package/dist/src/posthog-api.js.map +1 -1
  33. package/dist/src/prompt-builder.d.ts +3 -3
  34. package/dist/src/prompt-builder.d.ts.map +1 -1
  35. package/dist/src/prompt-builder.js +93 -123
  36. package/dist/src/prompt-builder.js.map +1 -1
  37. package/dist/src/task-manager.d.ts +4 -4
  38. package/dist/src/task-manager.d.ts.map +1 -1
  39. package/dist/src/task-manager.js +18 -19
  40. package/dist/src/task-manager.js.map +1 -1
  41. package/dist/src/task-progress-reporter.d.ts +4 -3
  42. package/dist/src/task-progress-reporter.d.ts.map +1 -1
  43. package/dist/src/task-progress-reporter.js +54 -59
  44. package/dist/src/task-progress-reporter.js.map +1 -1
  45. package/dist/src/template-manager.d.ts +1 -1
  46. package/dist/src/template-manager.d.ts.map +1 -1
  47. package/dist/src/template-manager.js +28 -30
  48. package/dist/src/template-manager.js.map +1 -1
  49. package/dist/src/todo-manager.d.ts +3 -3
  50. package/dist/src/todo-manager.d.ts.map +1 -1
  51. package/dist/src/todo-manager.js +24 -29
  52. package/dist/src/todo-manager.js.map +1 -1
  53. package/dist/src/tools/registry.d.ts +1 -1
  54. package/dist/src/tools/registry.js +60 -60
  55. package/dist/src/tools/registry.js.map +1 -1
  56. package/dist/src/tools/types.d.ts +31 -31
  57. package/dist/src/types.d.ts +33 -33
  58. package/dist/src/types.d.ts.map +1 -1
  59. package/dist/src/types.js.map +1 -1
  60. package/dist/src/utils/logger.d.ts +4 -4
  61. package/dist/src/utils/logger.d.ts.map +1 -1
  62. package/dist/src/utils/logger.js +8 -8
  63. package/dist/src/utils/logger.js.map +1 -1
  64. package/dist/src/workflow/config.d.ts +1 -1
  65. package/dist/src/workflow/config.d.ts.map +1 -1
  66. package/dist/src/workflow/config.js +18 -18
  67. package/dist/src/workflow/config.js.map +1 -1
  68. package/dist/src/workflow/steps/build.d.ts +1 -1
  69. package/dist/src/workflow/steps/build.d.ts.map +1 -1
  70. package/dist/src/workflow/steps/build.js +38 -46
  71. package/dist/src/workflow/steps/build.js.map +1 -1
  72. package/dist/src/workflow/steps/finalize.d.ts +1 -1
  73. package/dist/src/workflow/steps/finalize.d.ts.map +1 -1
  74. package/dist/src/workflow/steps/finalize.js +48 -54
  75. package/dist/src/workflow/steps/finalize.js.map +1 -1
  76. package/dist/src/workflow/steps/plan.d.ts +1 -1
  77. package/dist/src/workflow/steps/plan.d.ts.map +1 -1
  78. package/dist/src/workflow/steps/plan.js +46 -58
  79. package/dist/src/workflow/steps/plan.js.map +1 -1
  80. package/dist/src/workflow/steps/research.d.ts +1 -1
  81. package/dist/src/workflow/steps/research.d.ts.map +1 -1
  82. package/dist/src/workflow/steps/research.js +56 -68
  83. package/dist/src/workflow/steps/research.js.map +1 -1
  84. package/dist/src/workflow/types.d.ts +12 -12
  85. package/dist/src/workflow/types.d.ts.map +1 -1
  86. package/dist/src/workflow/utils.d.ts +1 -1
  87. package/dist/src/workflow/utils.d.ts.map +1 -1
  88. package/dist/src/workflow/utils.js +4 -7
  89. package/dist/src/workflow/utils.js.map +1 -1
  90. package/package.json +6 -6
  91. package/src/adapters/claude/claude-adapter.ts +168 -220
  92. package/src/adapters/claude/tool-mapper.ts +2 -2
  93. package/src/adapters/types.ts +1 -1
  94. package/src/agent.ts +444 -579
  95. package/src/agents/execution.ts +1 -1
  96. package/src/agents/planning.ts +1 -1
  97. package/src/agents/research.ts +1 -0
  98. package/src/file-manager.ts +63 -64
  99. package/src/git-manager.ts +88 -144
  100. package/src/posthog-api.ts +82 -122
  101. package/src/prompt-builder.ts +135 -180
  102. package/src/task-manager.ts +30 -38
  103. package/src/task-progress-reporter.ts +59 -70
  104. package/src/template-manager.ts +45 -98
  105. package/src/todo-manager.ts +30 -35
  106. package/src/tools/registry.ts +62 -62
  107. package/src/tools/types.ts +36 -36
  108. package/src/types.ts +71 -93
  109. package/src/utils/logger.ts +56 -62
  110. package/src/workflow/config.ts +48 -48
  111. package/src/workflow/steps/build.ts +113 -122
  112. package/src/workflow/steps/finalize.ts +182 -214
  113. package/src/workflow/steps/plan.ts +131 -151
  114. package/src/workflow/steps/research.ts +186 -205
  115. package/src/workflow/types.ts +36 -38
  116. package/src/workflow/utils.ts +34 -37
@@ -34,4 +34,4 @@ Before completing the task, verify:
34
34
 
35
35
  <output_format>
36
36
  Provide a concise summary of changes made when finished.
37
- </output_format>`;
37
+ </output_format>`;
@@ -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>`;
@@ -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
+
@@ -1,18 +1,18 @@
1
- import { promises as fs } from "node:fs";
2
- import { extname, join } from "node:path";
3
- import type { ResearchEvaluation, SupportingFile } from "./types.js";
4
- import { Logger } from "./utils/logger.js";
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: "plan" | "context" | "reference" | "output" | "artifact";
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["type"];
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, ".posthog", taskId);
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("Writing task file", {
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, "utf8");
56
+ await fs.writeFile(filePath, file.content, 'utf8');
58
57
 
59
- this.logger.debug("File written successfully", { filePath });
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, "utf8");
64
+ return await fs.readFile(filePath, 'utf8');
66
65
  } catch (error) {
67
- if ((error as NodeJS.ErrnoException).code === "ENOENT") {
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((file) => !file.startsWith("."));
77
+ return files.filter(file => !file.startsWith('.'));
79
78
  } catch (error) {
80
- if ((error as NodeJS.ErrnoException).code === "ENOENT") {
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 !== "ENOENT") {
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 !== "ENOENT") {
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("Writing plan", {
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: "plan.md",
127
+ name: 'plan.md',
129
128
  content: plan,
130
- type: "plan",
129
+ type: 'plan'
131
130
  });
132
131
 
133
- this.logger.info("Plan file written", { taskId });
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, "plan.md");
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: "context.md",
141
+ name: 'context.md',
143
142
  content: context,
144
- type: "context",
143
+ type: 'context'
145
144
  });
146
145
  }
147
146
 
148
147
  async readContext(taskId: string): Promise<string | null> {
149
- return await this.readTaskFile(taskId, "context.md");
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: "requirements.md",
153
+ name: 'requirements.md',
155
154
  content: requirements,
156
- type: "reference",
155
+ type: 'reference'
157
156
  });
158
157
  }
159
158
 
160
159
  async readRequirements(taskId: string): Promise<string | null> {
161
- return await this.readTaskFile(taskId, "requirements.md");
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("Writing research", {
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: "research.json",
173
+ name: 'research.json',
175
174
  content: JSON.stringify(data, null, 2),
176
- type: "artifact",
175
+ type: 'artifact'
177
176
  });
178
177
 
179
- this.logger.info("Research file written", {
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, "research.json");
190
- return content ? (JSON.parse(content) as ResearchEvaluation) : null;
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("Failed to parse research.json", { error });
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("Writing todos", {
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: "todos.json",
204
+ name: 'todos.json',
206
205
  content: JSON.stringify(data, null, 2),
207
- type: "artifact",
206
+ type: 'artifact'
208
207
  });
209
208
 
210
- this.logger.info("Todos file written", {
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, "todos.json");
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("Failed to parse todos.json", { error });
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(), // Could be enhanced with file stats
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, "utf8");
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["type"] {
276
- if (fileName === "plan.md") return "plan";
277
- if (fileName === "context.md") return "context";
278
- if (fileName === "requirements.md") return "reference";
279
- if (fileName.startsWith("output_")) return "output";
280
- if (fileName.endsWith(".md")) return "reference";
281
- return "artifact";
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 ".md":
288
- return "text/markdown";
289
- case ".json":
290
- return "application/json";
291
- case ".txt":
292
- return "text/plain";
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 "text/plain";
293
+ return 'text/plain';
295
294
  }
296
295
  }
297
296
  }