@posthog/agent 1.22.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CLAUDE.md +3 -3
  2. package/README.md +3 -3
  3. package/dist/index.d.ts +11 -11
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -3
  6. package/dist/src/adapters/claude/claude-adapter.d.ts +3 -3
  7. package/dist/src/adapters/claude/claude-adapter.d.ts.map +1 -1
  8. package/dist/src/adapters/claude/claude-adapter.js +156 -111
  9. package/dist/src/adapters/claude/claude-adapter.js.map +1 -1
  10. package/dist/src/adapters/claude/tool-mapper.d.ts +1 -1
  11. package/dist/src/adapters/claude/tool-mapper.d.ts.map +1 -1
  12. package/dist/src/adapters/claude/tool-mapper.js.map +1 -1
  13. package/dist/src/adapters/types.d.ts +1 -1
  14. package/dist/src/adapters/types.d.ts.map +1 -1
  15. package/dist/src/agent.d.ts +7 -7
  16. package/dist/src/agent.d.ts.map +1 -1
  17. package/dist/src/agent.js +143 -85
  18. package/dist/src/agent.js.map +1 -1
  19. package/dist/src/agents/execution.js.map +1 -1
  20. package/dist/src/agents/planning.js.map +1 -1
  21. package/dist/src/agents/research.js.map +1 -1
  22. package/dist/src/file-manager.d.ts +4 -4
  23. package/dist/src/file-manager.d.ts.map +1 -1
  24. package/dist/src/file-manager.js +59 -58
  25. package/dist/src/file-manager.js.map +1 -1
  26. package/dist/src/git-manager.d.ts +1 -1
  27. package/dist/src/git-manager.d.ts.map +1 -1
  28. package/dist/src/git-manager.js +93 -69
  29. package/dist/src/git-manager.js.map +1 -1
  30. package/dist/src/posthog-api.d.ts +2 -3
  31. package/dist/src/posthog-api.d.ts.map +1 -1
  32. package/dist/src/posthog-api.js +22 -22
  33. package/dist/src/posthog-api.js.map +1 -1
  34. package/dist/src/prompt-builder.d.ts +3 -3
  35. package/dist/src/prompt-builder.d.ts.map +1 -1
  36. package/dist/src/prompt-builder.js +123 -93
  37. package/dist/src/prompt-builder.js.map +1 -1
  38. package/dist/src/task-manager.d.ts +4 -4
  39. package/dist/src/task-manager.d.ts.map +1 -1
  40. package/dist/src/task-manager.js +19 -18
  41. package/dist/src/task-manager.js.map +1 -1
  42. package/dist/src/task-progress-reporter.d.ts +3 -4
  43. package/dist/src/task-progress-reporter.d.ts.map +1 -1
  44. package/dist/src/task-progress-reporter.js +59 -54
  45. package/dist/src/task-progress-reporter.js.map +1 -1
  46. package/dist/src/template-manager.d.ts +1 -1
  47. package/dist/src/template-manager.d.ts.map +1 -1
  48. package/dist/src/template-manager.js +30 -28
  49. package/dist/src/template-manager.js.map +1 -1
  50. package/dist/src/todo-manager.d.ts +3 -3
  51. package/dist/src/todo-manager.d.ts.map +1 -1
  52. package/dist/src/todo-manager.js +29 -24
  53. package/dist/src/todo-manager.js.map +1 -1
  54. package/dist/src/tools/registry.d.ts +1 -1
  55. package/dist/src/tools/registry.js +60 -60
  56. package/dist/src/tools/registry.js.map +1 -1
  57. package/dist/src/tools/types.d.ts +31 -31
  58. package/dist/src/types.d.ts +33 -33
  59. package/dist/src/types.d.ts.map +1 -1
  60. package/dist/src/types.js.map +1 -1
  61. package/dist/src/utils/logger.d.ts +4 -4
  62. package/dist/src/utils/logger.d.ts.map +1 -1
  63. package/dist/src/utils/logger.js +8 -8
  64. package/dist/src/utils/logger.js.map +1 -1
  65. package/dist/src/workflow/config.d.ts +1 -1
  66. package/dist/src/workflow/config.d.ts.map +1 -1
  67. package/dist/src/workflow/config.js +18 -18
  68. package/dist/src/workflow/config.js.map +1 -1
  69. package/dist/src/workflow/steps/build.d.ts +1 -1
  70. package/dist/src/workflow/steps/build.d.ts.map +1 -1
  71. package/dist/src/workflow/steps/build.js +46 -38
  72. package/dist/src/workflow/steps/build.js.map +1 -1
  73. package/dist/src/workflow/steps/finalize.d.ts +1 -1
  74. package/dist/src/workflow/steps/finalize.d.ts.map +1 -1
  75. package/dist/src/workflow/steps/finalize.js +54 -48
  76. package/dist/src/workflow/steps/finalize.js.map +1 -1
  77. package/dist/src/workflow/steps/plan.d.ts +1 -1
  78. package/dist/src/workflow/steps/plan.d.ts.map +1 -1
  79. package/dist/src/workflow/steps/plan.js +58 -46
  80. package/dist/src/workflow/steps/plan.js.map +1 -1
  81. package/dist/src/workflow/steps/research.d.ts +1 -1
  82. package/dist/src/workflow/steps/research.d.ts.map +1 -1
  83. package/dist/src/workflow/steps/research.js +68 -56
  84. package/dist/src/workflow/steps/research.js.map +1 -1
  85. package/dist/src/workflow/types.d.ts +12 -12
  86. package/dist/src/workflow/types.d.ts.map +1 -1
  87. package/dist/src/workflow/utils.d.ts +1 -1
  88. package/dist/src/workflow/utils.d.ts.map +1 -1
  89. package/dist/src/workflow/utils.js +7 -4
  90. package/dist/src/workflow/utils.js.map +1 -1
  91. package/package.json +8 -8
  92. package/src/adapters/claude/claude-adapter.ts +220 -168
  93. package/src/adapters/claude/tool-mapper.ts +2 -2
  94. package/src/adapters/types.ts +1 -1
  95. package/src/agent.ts +579 -444
  96. package/src/agents/execution.ts +1 -1
  97. package/src/agents/planning.ts +1 -1
  98. package/src/agents/research.ts +0 -1
  99. package/src/file-manager.ts +64 -63
  100. package/src/git-manager.ts +152 -87
  101. package/src/posthog-api.ts +122 -82
  102. package/src/prompt-builder.ts +180 -135
  103. package/src/task-manager.ts +38 -30
  104. package/src/task-progress-reporter.ts +70 -59
  105. package/src/template-manager.ts +98 -45
  106. package/src/todo-manager.ts +35 -30
  107. package/src/tools/registry.ts +62 -62
  108. package/src/tools/types.ts +36 -36
  109. package/src/types.ts +93 -71
  110. package/src/utils/logger.ts +62 -56
  111. package/src/workflow/config.ts +48 -48
  112. package/src/workflow/steps/build.ts +122 -113
  113. package/src/workflow/steps/finalize.ts +214 -182
  114. package/src/workflow/steps/plan.ts +151 -131
  115. package/src/workflow/steps/research.ts +205 -186
  116. package/src/workflow/types.ts +38 -36
  117. package/src/workflow/utils.ts +37 -34
  118. package/LICENSE +0 -33
@@ -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,4 +158,3 @@ 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 'fs';
2
- import { join, extname } from 'path';
3
- import type { SupportingFile, ResearchEvaluation } from './types.js';
4
- import { Logger } from './utils/logger.js';
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";
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,11 +23,12 @@ export class PostHogFileManager {
23
23
 
24
24
  constructor(repositoryPath: string, logger?: Logger) {
25
25
  this.repositoryPath = repositoryPath;
26
- this.logger = logger || new Logger({ debug: false, prefix: '[FileManager]' });
26
+ this.logger =
27
+ logger || new Logger({ debug: false, prefix: "[FileManager]" });
27
28
  }
28
29
 
29
30
  private getTaskDirectory(taskId: string): string {
30
- return join(this.repositoryPath, '.posthog', taskId);
31
+ return join(this.repositoryPath, ".posthog", taskId);
31
32
  }
32
33
 
33
34
  private getTaskFilePath(taskId: string, fileName: string): string {
@@ -47,23 +48,23 @@ export class PostHogFileManager {
47
48
  await this.ensureTaskDirectory(taskId);
48
49
  const filePath = this.getTaskFilePath(taskId, file.name);
49
50
 
50
- this.logger.debug('Writing task file', {
51
+ this.logger.debug("Writing task file", {
51
52
  filePath,
52
53
  contentLength: file.content.length,
53
- contentType: typeof file.content
54
+ contentType: typeof file.content,
54
55
  });
55
56
 
56
- await fs.writeFile(filePath, file.content, 'utf8');
57
+ await fs.writeFile(filePath, file.content, "utf8");
57
58
 
58
- this.logger.debug('File written successfully', { filePath });
59
+ this.logger.debug("File written successfully", { filePath });
59
60
  }
60
61
 
61
62
  async readTaskFile(taskId: string, fileName: string): Promise<string | null> {
62
63
  try {
63
64
  const filePath = this.getTaskFilePath(taskId, fileName);
64
- return await fs.readFile(filePath, 'utf8');
65
+ return await fs.readFile(filePath, "utf8");
65
66
  } catch (error) {
66
- if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
67
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") {
67
68
  return null;
68
69
  }
69
70
  throw error;
@@ -74,9 +75,9 @@ export class PostHogFileManager {
74
75
  try {
75
76
  const taskDir = this.getTaskDirectory(taskId);
76
77
  const files = await fs.readdir(taskDir);
77
- return files.filter(file => !file.startsWith('.'));
78
+ return files.filter((file) => !file.startsWith("."));
78
79
  } catch (error) {
79
- if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
80
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") {
80
81
  return [];
81
82
  }
82
83
  throw error;
@@ -88,7 +89,7 @@ export class PostHogFileManager {
88
89
  const filePath = this.getTaskFilePath(taskId, fileName);
89
90
  await fs.unlink(filePath);
90
91
  } catch (error) {
91
- if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
92
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
92
93
  throw error;
93
94
  }
94
95
  }
@@ -109,7 +110,7 @@ export class PostHogFileManager {
109
110
  const taskDir = this.getTaskDirectory(taskId);
110
111
  await fs.rm(taskDir, { recursive: true, force: true });
111
112
  } catch (error) {
112
- if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
113
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
113
114
  throw error;
114
115
  }
115
116
  }
@@ -117,51 +118,51 @@ export class PostHogFileManager {
117
118
 
118
119
  // Convenience methods for common file types
119
120
  async writePlan(taskId: string, plan: string): Promise<void> {
120
- this.logger.debug('Writing plan', {
121
+ this.logger.debug("Writing plan", {
121
122
  taskId,
122
123
  planLength: plan.length,
123
- contentPreview: plan.substring(0, 200)
124
+ contentPreview: plan.substring(0, 200),
124
125
  });
125
126
 
126
127
  await this.writeTaskFile(taskId, {
127
- name: 'plan.md',
128
+ name: "plan.md",
128
129
  content: plan,
129
- type: 'plan'
130
+ type: "plan",
130
131
  });
131
132
 
132
- this.logger.info('Plan file written', { taskId });
133
+ this.logger.info("Plan file written", { taskId });
133
134
  }
134
135
 
135
136
  async readPlan(taskId: string): Promise<string | null> {
136
- return await this.readTaskFile(taskId, 'plan.md');
137
+ return await this.readTaskFile(taskId, "plan.md");
137
138
  }
138
139
 
139
140
  async writeContext(taskId: string, context: string): Promise<void> {
140
141
  await this.writeTaskFile(taskId, {
141
- name: 'context.md',
142
+ name: "context.md",
142
143
  content: context,
143
- type: 'context'
144
+ type: "context",
144
145
  });
145
146
  }
146
147
 
147
148
  async readContext(taskId: string): Promise<string | null> {
148
- return await this.readTaskFile(taskId, 'context.md');
149
+ return await this.readTaskFile(taskId, "context.md");
149
150
  }
150
151
 
151
152
  async writeRequirements(taskId: string, requirements: string): Promise<void> {
152
153
  await this.writeTaskFile(taskId, {
153
- name: 'requirements.md',
154
+ name: "requirements.md",
154
155
  content: requirements,
155
- type: 'reference'
156
+ type: "reference",
156
157
  });
157
158
  }
158
159
 
159
160
  async readRequirements(taskId: string): Promise<string | null> {
160
- return await this.readTaskFile(taskId, 'requirements.md');
161
+ return await this.readTaskFile(taskId, "requirements.md");
161
162
  }
162
163
 
163
164
  async writeResearch(taskId: string, data: ResearchEvaluation): Promise<void> {
164
- this.logger.debug('Writing research', {
165
+ this.logger.debug("Writing research", {
165
166
  taskId,
166
167
  score: data.actionabilityScore,
167
168
  hasQuestions: !!data.questions,
@@ -170,13 +171,13 @@ export class PostHogFileManager {
170
171
  });
171
172
 
172
173
  await this.writeTaskFile(taskId, {
173
- name: 'research.json',
174
+ name: "research.json",
174
175
  content: JSON.stringify(data, null, 2),
175
- type: 'artifact'
176
+ type: "artifact",
176
177
  });
177
178
 
178
- this.logger.info('Research file written', {
179
- taskId,
179
+ this.logger.info("Research file written", {
180
+ taskId,
180
181
  score: data.actionabilityScore,
181
182
  hasQuestions: !!data.questions,
182
183
  answered: data.answered ?? false,
@@ -185,28 +186,28 @@ export class PostHogFileManager {
185
186
 
186
187
  async readResearch(taskId: string): Promise<ResearchEvaluation | null> {
187
188
  try {
188
- const content = await this.readTaskFile(taskId, 'research.json');
189
- return content ? JSON.parse(content) as ResearchEvaluation : null;
189
+ const content = await this.readTaskFile(taskId, "research.json");
190
+ return content ? (JSON.parse(content) as ResearchEvaluation) : null;
190
191
  } catch (error) {
191
- this.logger.debug('Failed to parse research.json', { error });
192
+ this.logger.debug("Failed to parse research.json", { error });
192
193
  return null;
193
194
  }
194
195
  }
195
196
 
196
197
  async writeTodos(taskId: string, data: any): Promise<void> {
197
- this.logger.debug('Writing todos', {
198
+ this.logger.debug("Writing todos", {
198
199
  taskId,
199
200
  total: data.metadata?.total ?? 0,
200
201
  completed: data.metadata?.completed ?? 0,
201
202
  });
202
203
 
203
204
  await this.writeTaskFile(taskId, {
204
- name: 'todos.json',
205
+ name: "todos.json",
205
206
  content: JSON.stringify(data, null, 2),
206
- type: 'artifact'
207
+ type: "artifact",
207
208
  });
208
209
 
209
- this.logger.info('Todos file written', {
210
+ this.logger.info("Todos file written", {
210
211
  taskId,
211
212
  total: data.metadata?.total ?? 0,
212
213
  completed: data.metadata?.completed ?? 0,
@@ -215,10 +216,10 @@ export class PostHogFileManager {
215
216
 
216
217
  async readTodos(taskId: string): Promise<any | null> {
217
218
  try {
218
- const content = await this.readTaskFile(taskId, 'todos.json');
219
+ const content = await this.readTaskFile(taskId, "todos.json");
219
220
  return content ? JSON.parse(content) : null;
220
221
  } catch (error) {
221
- this.logger.debug('Failed to parse todos.json', { error });
222
+ this.logger.debug("Failed to parse todos.json", { error });
222
223
  return null;
223
224
  }
224
225
  }
@@ -226,22 +227,22 @@ export class PostHogFileManager {
226
227
  async getTaskFiles(taskId: string): Promise<SupportingFile[]> {
227
228
  const fileNames = await this.listTaskFiles(taskId);
228
229
  const files: SupportingFile[] = [];
229
-
230
+
230
231
  for (const fileName of fileNames) {
231
232
  const content = await this.readTaskFile(taskId, fileName);
232
233
  if (content !== null) {
233
234
  // Determine type based on file name
234
235
  const type = this.resolveFileType(fileName);
235
-
236
+
236
237
  files.push({
237
238
  name: fileName,
238
239
  content,
239
240
  type,
240
- created_at: new Date().toISOString() // Could be enhanced with file stats
241
+ created_at: new Date().toISOString(), // Could be enhanced with file stats
241
242
  });
242
243
  }
243
244
  }
244
-
245
+
245
246
  return files;
246
247
  }
247
248
 
@@ -257,7 +258,7 @@ export class PostHogFileManager {
257
258
 
258
259
  const type = this.resolveFileType(fileName);
259
260
  const contentType = this.inferContentType(fileName);
260
- const size = Buffer.byteLength(content, 'utf8');
261
+ const size = Buffer.byteLength(content, "utf8");
261
262
 
262
263
  artifacts.push({
263
264
  name: fileName,
@@ -271,26 +272,26 @@ export class PostHogFileManager {
271
272
  return artifacts;
272
273
  }
273
274
 
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';
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";
281
282
  }
282
283
 
283
284
  private inferContentType(fileName: string): string {
284
285
  const extension = extname(fileName).toLowerCase();
285
286
  switch (extension) {
286
- case '.md':
287
- return 'text/markdown';
288
- case '.json':
289
- return 'application/json';
290
- case '.txt':
291
- return 'text/plain';
287
+ case ".md":
288
+ return "text/markdown";
289
+ case ".json":
290
+ return "application/json";
291
+ case ".txt":
292
+ return "text/plain";
292
293
  default:
293
- return 'text/plain';
294
+ return "text/plain";
294
295
  }
295
296
  }
296
297
  }