@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
@@ -1 +1 @@
1
- {"version":3,"file":"git-manager.d.ts","sourceRoot":"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EACb,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC;IAuBZ,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAsBvD,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBxF"}
@@ -1,5 +1,5 @@
1
- import { exec } from 'node:child_process';
2
- import { promisify } from 'node:util';
1
+ import { exec } from 'child_process';
2
+ import { promisify } from 'util';
3
3
  import { Logger } from './utils/logger.js';
4
4
 
5
5
  const execAsync = promisify(exec);
@@ -12,15 +12,14 @@ class GitManager {
12
12
  this.repositoryPath = config.repositoryPath;
13
13
  this.authorName = config.authorName;
14
14
  this.authorEmail = config.authorEmail;
15
- this.logger =
16
- config.logger || new Logger({ debug: false, prefix: "[GitManager]" });
15
+ this.logger = config.logger || new Logger({ debug: false, prefix: '[GitManager]' });
17
16
  }
18
17
  escapeShellArg(str) {
19
18
  return str
20
- .replace(/\\/g, "\\\\")
19
+ .replace(/\\/g, '\\\\')
21
20
  .replace(/"/g, '\\"')
22
- .replace(/`/g, "\\`")
23
- .replace(/\$/g, "\\$");
21
+ .replace(/`/g, '\\`')
22
+ .replace(/\$/g, '\\$');
24
23
  }
25
24
  async runGitCommand(command) {
26
25
  try {
@@ -42,7 +41,7 @@ class GitManager {
42
41
  }
43
42
  async isGitRepository() {
44
43
  try {
45
- await this.runGitCommand("rev-parse --git-dir");
44
+ await this.runGitCommand('rev-parse --git-dir');
46
45
  return true;
47
46
  }
48
47
  catch {
@@ -50,24 +49,24 @@ class GitManager {
50
49
  }
51
50
  }
52
51
  async getCurrentBranch() {
53
- return await this.runGitCommand("branch --show-current");
52
+ return await this.runGitCommand('branch --show-current');
54
53
  }
55
54
  async getDefaultBranch() {
56
55
  try {
57
56
  // Try to get the default branch from remote
58
- const remoteBranch = await this.runGitCommand("symbolic-ref refs/remotes/origin/HEAD");
59
- return remoteBranch.replace("refs/remotes/origin/", "");
57
+ const remoteBranch = await this.runGitCommand('symbolic-ref refs/remotes/origin/HEAD');
58
+ return remoteBranch.replace('refs/remotes/origin/', '');
60
59
  }
61
60
  catch {
62
61
  // Fallback: check if main exists, otherwise use master
63
- if (await this.branchExists("main")) {
64
- return "main";
62
+ if (await this.branchExists('main')) {
63
+ return 'main';
65
64
  }
66
- else if (await this.branchExists("master")) {
67
- return "master";
65
+ else if (await this.branchExists('master')) {
66
+ return 'master';
68
67
  }
69
68
  else {
70
- throw new Error("Cannot determine default branch. No main or master branch found.");
69
+ throw new Error('Cannot determine default branch. No main or master branch found.');
71
70
  }
72
71
  }
73
72
  }
@@ -81,7 +80,7 @@ class GitManager {
81
80
  }
82
81
  }
83
82
  async createBranch(branchName, baseBranch) {
84
- const base = baseBranch || (await this.getCurrentBranch());
83
+ const base = baseBranch || await this.getCurrentBranch();
85
84
  await this.runGitCommand(`checkout -b ${branchName} ${base}`);
86
85
  }
87
86
  async switchToBranch(branchName) {
@@ -91,25 +90,22 @@ class GitManager {
91
90
  const currentBranch = await this.getCurrentBranch();
92
91
  const defaultBranch = await this.getDefaultBranch();
93
92
  if (currentBranch === defaultBranch) {
94
- this.logger.debug("Already on default branch", { branch: defaultBranch });
93
+ this.logger.debug('Already on default branch', { branch: defaultBranch });
95
94
  return true;
96
95
  }
97
96
  if (await this.hasChanges()) {
98
- this.logger.warn("Skipping branch reset - uncommitted changes present", {
97
+ this.logger.warn('Skipping branch reset - uncommitted changes present', {
99
98
  currentBranch,
100
- defaultBranch,
99
+ defaultBranch
101
100
  });
102
101
  return false;
103
102
  }
104
103
  await this.switchToBranch(defaultBranch);
105
- this.logger.info("Reset to default branch", {
106
- from: currentBranch,
107
- to: defaultBranch,
108
- });
104
+ this.logger.info('Reset to default branch', { from: currentBranch, to: defaultBranch });
109
105
  return true;
110
106
  }
111
107
  async createOrSwitchToBranch(branchName, baseBranch) {
112
- await this.ensureCleanWorkingDirectory("switching branches");
108
+ await this.ensureCleanWorkingDirectory('switching branches');
113
109
  const exists = await this.branchExists(branchName);
114
110
  if (exists) {
115
111
  await this.switchToBranch(branchName);
@@ -119,17 +115,17 @@ class GitManager {
119
115
  }
120
116
  }
121
117
  async addFiles(paths) {
122
- const pathList = paths.map((p) => `"${this.escapeShellArg(p)}"`).join(" ");
118
+ const pathList = paths.map(p => `"${this.escapeShellArg(p)}"`).join(' ');
123
119
  await this.runGitCommand(`add ${pathList}`);
124
120
  }
125
121
  async addAllPostHogFiles() {
126
122
  try {
127
123
  // Use -A flag to add all changes (including new files) and ignore errors if directory is empty
128
- await this.runGitCommand("add -A .posthog/");
124
+ await this.runGitCommand('add -A .posthog/');
129
125
  }
130
126
  catch (error) {
131
127
  // If the directory doesn't exist or has no files, that's fine - just log and continue
132
- this.logger.debug("No PostHog files to add", { error });
128
+ this.logger.debug('No PostHog files to add', { error });
133
129
  }
134
130
  }
135
131
  async commitChanges(message, options) {
@@ -138,13 +134,13 @@ class GitManager {
138
134
  }
139
135
  async hasChanges() {
140
136
  try {
141
- const status = await this.runGitCommand("status --porcelain");
137
+ const status = await this.runGitCommand('status --porcelain');
142
138
  if (!status || status.trim().length === 0) {
143
139
  return false;
144
140
  }
145
- const lines = status.split("\n").filter((line) => {
141
+ const lines = status.split('\n').filter(line => {
146
142
  const trimmed = line.trim();
147
- return trimmed.length > 0 && !trimmed.includes(".posthog/");
143
+ return trimmed.length > 0 && !trimmed.includes('.posthog/');
148
144
  });
149
145
  return lines.length > 0;
150
146
  }
@@ -154,7 +150,7 @@ class GitManager {
154
150
  }
155
151
  async hasStagedChanges() {
156
152
  try {
157
- const status = await this.runGitCommand("diff --cached --name-only");
153
+ const status = await this.runGitCommand('diff --cached --name-only');
158
154
  return status.length > 0;
159
155
  }
160
156
  catch {
@@ -168,7 +164,7 @@ class GitManager {
168
164
  }
169
165
  }
170
166
  async generateUniqueBranchName(baseName) {
171
- if (!(await this.branchExists(baseName))) {
167
+ if (!await this.branchExists(baseName)) {
172
168
  return baseName;
173
169
  }
174
170
  let counter = 1;
@@ -183,7 +179,7 @@ class GitManager {
183
179
  const defaultBranch = await this.getDefaultBranch();
184
180
  const currentBranch = await this.getCurrentBranch();
185
181
  if (currentBranch !== defaultBranch) {
186
- await this.ensureCleanWorkingDirectory("switching to default branch");
182
+ await this.ensureCleanWorkingDirectory('switching to default branch');
187
183
  await this.switchToBranch(defaultBranch);
188
184
  }
189
185
  return defaultBranch;
@@ -191,7 +187,7 @@ class GitManager {
191
187
  buildCommitCommand(message, options) {
192
188
  let command = `commit -m "${this.escapeShellArg(message)}"`;
193
189
  if (options?.allowEmpty) {
194
- command += " --allow-empty";
190
+ command += ' --allow-empty';
195
191
  }
196
192
  const authorName = options?.authorName || this.authorName;
197
193
  const authorEmail = options?.authorEmail || this.authorEmail;
@@ -202,14 +198,14 @@ class GitManager {
202
198
  }
203
199
  async getRemoteUrl() {
204
200
  try {
205
- return await this.runGitCommand("remote get-url origin");
201
+ return await this.runGitCommand('remote get-url origin');
206
202
  }
207
203
  catch {
208
204
  return null;
209
205
  }
210
206
  }
211
207
  async pushBranch(branchName, force = false) {
212
- const forceFlag = force ? "--force" : "";
208
+ const forceFlag = force ? '--force' : '';
213
209
  await this.runGitCommand(`push ${forceFlag} -u origin ${branchName}`);
214
210
  }
215
211
  /**
@@ -222,10 +218,10 @@ class GitManager {
222
218
  * const result = await tracker.finalize({ commitMessage: 'fallback message', push: true });
223
219
  */
224
220
  async trackCommitsDuring() {
225
- const initialSha = await this.getCommitSha("HEAD");
221
+ const initialSha = await this.getCommitSha('HEAD');
226
222
  return {
227
223
  finalize: async (options) => {
228
- const currentSha = await this.getCommitSha("HEAD");
224
+ const currentSha = await this.getCommitSha('HEAD');
229
225
  const externalCommitsCreated = initialSha !== currentSha;
230
226
  const hasUncommittedChanges = await this.hasChanges();
231
227
  // If no commits and no changes, nothing to do
@@ -235,7 +231,7 @@ class GitManager {
235
231
  let commitCreated = externalCommitsCreated;
236
232
  // Commit any remaining uncommitted changes
237
233
  if (hasUncommittedChanges) {
238
- await this.runGitCommand("add .");
234
+ await this.runGitCommand('add .');
239
235
  const hasStagedChanges = await this.hasStagedChanges();
240
236
  if (hasStagedChanges) {
241
237
  await this.commitChanges(options.commitMessage);
@@ -248,22 +244,20 @@ class GitManager {
248
244
  const currentBranch = await this.getCurrentBranch();
249
245
  await this.pushBranch(currentBranch);
250
246
  pushedBranch = true;
251
- this.logger.info("Pushed branch after operation", {
252
- branch: currentBranch,
253
- });
247
+ this.logger.info('Pushed branch after operation', { branch: currentBranch });
254
248
  }
255
249
  return { commitCreated, pushedBranch };
256
- },
250
+ }
257
251
  };
258
252
  }
259
253
  async createTaskBranch(taskSlug) {
260
254
  const branchName = `posthog/task-${taskSlug}`;
261
255
  // Ensure we're on default branch before creating task branch
262
256
  const defaultBranch = await this.ensureOnDefaultBranch();
263
- this.logger.info("Creating task branch from default branch", {
257
+ this.logger.info('Creating task branch from default branch', {
264
258
  branchName,
265
259
  taskSlug,
266
- baseBranch: defaultBranch,
260
+ baseBranch: defaultBranch
267
261
  });
268
262
  await this.createOrSwitchToBranch(branchName, defaultBranch);
269
263
  return branchName;
@@ -271,55 +265,49 @@ class GitManager {
271
265
  async createTaskPlanningBranch(taskId, baseBranch) {
272
266
  const baseName = `posthog/task-${taskId}-planning`;
273
267
  const branchName = await this.generateUniqueBranchName(baseName);
274
- this.logger.debug("Creating unique planning branch", {
275
- branchName,
276
- taskId,
277
- });
278
- const base = baseBranch || (await this.ensureOnDefaultBranch());
268
+ this.logger.debug('Creating unique planning branch', { branchName, taskId });
269
+ const base = baseBranch || await this.ensureOnDefaultBranch();
279
270
  await this.createBranch(branchName, base);
280
271
  return branchName;
281
272
  }
282
273
  async createTaskImplementationBranch(taskId, planningBranchName) {
283
274
  const baseName = `posthog/task-${taskId}-implementation`;
284
275
  const branchName = await this.generateUniqueBranchName(baseName);
285
- this.logger.debug("Creating unique implementation branch", {
276
+ this.logger.debug('Creating unique implementation branch', {
286
277
  branchName,
287
278
  taskId,
288
- currentBranch: await this.getCurrentBranch(),
279
+ currentBranch: await this.getCurrentBranch()
289
280
  });
290
281
  // Determine base branch: explicit param > current planning branch > default
291
282
  let baseBranch = planningBranchName;
292
283
  if (!baseBranch) {
293
284
  const currentBranch = await this.getCurrentBranch();
294
- if (currentBranch.includes("-planning")) {
285
+ if (currentBranch.includes('-planning')) {
295
286
  baseBranch = currentBranch;
296
- this.logger.debug("Using current planning branch", { baseBranch });
287
+ this.logger.debug('Using current planning branch', { baseBranch });
297
288
  }
298
289
  else {
299
290
  baseBranch = await this.ensureOnDefaultBranch();
300
- this.logger.debug("Using default branch", { baseBranch });
291
+ this.logger.debug('Using default branch', { baseBranch });
301
292
  }
302
293
  }
303
- this.logger.debug("Creating implementation branch from base", {
304
- baseBranch,
305
- branchName,
306
- });
294
+ this.logger.debug('Creating implementation branch from base', { baseBranch, branchName });
307
295
  await this.createBranch(branchName, baseBranch);
308
- this.logger.info("Implementation branch created", {
296
+ this.logger.info('Implementation branch created', {
309
297
  branchName,
310
- currentBranch: await this.getCurrentBranch(),
298
+ currentBranch: await this.getCurrentBranch()
311
299
  });
312
300
  return branchName;
313
301
  }
314
302
  async commitPlan(taskId, taskTitle) {
315
303
  const currentBranch = await this.getCurrentBranch();
316
- this.logger.debug("Committing plan", { taskId, currentBranch });
304
+ this.logger.debug('Committing plan', { taskId, currentBranch });
317
305
  await this.addAllPostHogFiles();
318
306
  const hasChanges = await this.hasStagedChanges();
319
- this.logger.debug("Checking for staged changes", { hasChanges });
307
+ this.logger.debug('Checking for staged changes', { hasChanges });
320
308
  if (!hasChanges) {
321
- this.logger.info("No plan changes to commit", { taskId });
322
- return "No changes to commit";
309
+ this.logger.info('No plan changes to commit', { taskId });
310
+ return 'No changes to commit';
323
311
  }
324
312
  const message = `📋 Add plan for task: ${taskTitle}
325
313
 
@@ -329,15 +317,15 @@ Generated by PostHog Agent
329
317
  This commit contains the implementation plan and supporting documentation
330
318
  for the task. Review the plan before proceeding with implementation.`;
331
319
  const result = await this.commitChanges(message);
332
- this.logger.info("Plan committed", { taskId, taskTitle });
320
+ this.logger.info('Plan committed', { taskId, taskTitle });
333
321
  return result;
334
322
  }
335
323
  async commitImplementation(taskId, taskTitle, planSummary) {
336
- await this.runGitCommand("add .");
324
+ await this.runGitCommand('add .');
337
325
  const hasChanges = await this.hasStagedChanges();
338
326
  if (!hasChanges) {
339
- this.logger.warn("No implementation changes to commit", { taskId });
340
- return "No changes to commit";
327
+ this.logger.warn('No implementation changes to commit', { taskId });
328
+ return 'No changes to commit';
341
329
  }
342
330
  let message = `✨ Implement task: ${taskTitle}
343
331
 
@@ -348,11 +336,11 @@ Generated by PostHog Agent`;
348
336
  }
349
337
  message += `\n\nThis commit implements the changes described in the task plan.`;
350
338
  const result = await this.commitChanges(message);
351
- this.logger.info("Implementation committed", { taskId, taskTitle });
339
+ this.logger.info('Implementation committed', { taskId, taskTitle });
352
340
  return result;
353
341
  }
354
342
  async deleteBranch(branchName, force = false) {
355
- const forceFlag = force ? "-D" : "-d";
343
+ const forceFlag = force ? '-D' : '-d';
356
344
  await this.runGitCommand(`branch ${forceFlag} ${branchName}`);
357
345
  }
358
346
  async deleteRemoteBranch(branchName) {
@@ -364,19 +352,19 @@ Generated by PostHog Agent`;
364
352
  return {
365
353
  name: branchName,
366
354
  exists,
367
- isCurrentBranch: branchName === currentBranch,
355
+ isCurrentBranch: branchName === currentBranch
368
356
  };
369
357
  }
370
- async getCommitSha(ref = "HEAD") {
358
+ async getCommitSha(ref = 'HEAD') {
371
359
  return await this.runGitCommand(`rev-parse ${ref}`);
372
360
  }
373
- async getCommitMessage(ref = "HEAD") {
361
+ async getCommitMessage(ref = 'HEAD') {
374
362
  return await this.runGitCommand(`log -1 --pretty=%B ${ref}`);
375
363
  }
376
364
  async createPullRequest(branchName, title, body, baseBranch) {
377
365
  const currentBranch = await this.getCurrentBranch();
378
366
  if (currentBranch !== branchName) {
379
- await this.ensureCleanWorkingDirectory("creating PR");
367
+ await this.ensureCleanWorkingDirectory('creating PR');
380
368
  await this.switchToBranch(branchName);
381
369
  }
382
370
  await this.pushBranch(branchName);
@@ -395,14 +383,12 @@ Generated by PostHog Agent`;
395
383
  async getTaskBranch(taskSlug) {
396
384
  try {
397
385
  // Get all branches matching the task slug pattern
398
- const branches = await this.runGitCommand("branch --list --all");
386
+ const branches = await this.runGitCommand('branch --list --all');
399
387
  const branchPattern = `posthog/task-${taskSlug}`;
400
388
  // Look for exact match or with counter suffix
401
- const lines = branches
402
- .split("\n")
403
- .map((l) => l.trim().replace(/^\*\s+/, ""));
389
+ const lines = branches.split('\n').map(l => l.trim().replace(/^\*\s+/, ''));
404
390
  for (const line of lines) {
405
- const cleanBranch = line.replace("remotes/origin/", "");
391
+ const cleanBranch = line.replace('remotes/origin/', '');
406
392
  if (cleanBranch.startsWith(branchPattern)) {
407
393
  return cleanBranch;
408
394
  }
@@ -410,14 +396,14 @@ Generated by PostHog Agent`;
410
396
  return null;
411
397
  }
412
398
  catch (error) {
413
- this.logger.debug("Failed to get task branch", { taskSlug, error });
399
+ this.logger.debug('Failed to get task branch', { taskSlug, error });
414
400
  return null;
415
401
  }
416
402
  }
417
403
  async commitAndPush(message, options) {
418
404
  const hasChanges = await this.hasStagedChanges();
419
405
  if (!hasChanges && !options?.allowEmpty) {
420
- this.logger.debug("No changes to commit, skipping");
406
+ this.logger.debug('No changes to commit, skipping');
421
407
  return;
422
408
  }
423
409
  const command = this.buildCommitCommand(message, options);
@@ -425,10 +411,7 @@ Generated by PostHog Agent`;
425
411
  // Push to origin
426
412
  const currentBranch = await this.getCurrentBranch();
427
413
  await this.pushBranch(currentBranch);
428
- this.logger.info("Committed and pushed changes", {
429
- branch: currentBranch,
430
- message,
431
- });
414
+ this.logger.info('Committed and pushed changes', { branch: currentBranch, message });
432
415
  }
433
416
  }
434
417
 
@@ -1 +1 @@
1
- {"version":3,"file":"git-manager.js","sources":["../../src/git-manager.ts"],"sourcesContent":["import { exec } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { Logger } from \"./utils/logger.js\";\n\nconst execAsync = promisify(exec);\n\nexport interface GitConfig {\n repositoryPath: string;\n authorName?: string;\n authorEmail?: string;\n logger?: Logger;\n}\n\nexport interface BranchInfo {\n name: string;\n exists: boolean;\n isCurrentBranch: boolean;\n}\n\nexport class GitManager {\n private repositoryPath: string;\n private authorName?: string;\n private authorEmail?: string;\n private logger: Logger;\n\n constructor(config: GitConfig) {\n this.repositoryPath = config.repositoryPath;\n this.authorName = config.authorName;\n this.authorEmail = config.authorEmail;\n this.logger =\n config.logger || new Logger({ debug: false, prefix: \"[GitManager]\" });\n }\n\n private escapeShellArg(str: string): string {\n return str\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/`/g, \"\\\\`\")\n .replace(/\\$/g, \"\\\\$\");\n }\n\n private async runGitCommand(command: string): Promise<string> {\n try {\n const { stdout } = await execAsync(\n `cd \"${this.repositoryPath}\" && git ${command}`,\n );\n return stdout.trim();\n } catch (error) {\n throw new Error(`Git command failed: ${command}\\n${error}`);\n }\n }\n\n private async runCommand(command: string): Promise<string> {\n try {\n const { stdout } = await execAsync(\n `cd \"${this.repositoryPath}\" && ${command}`,\n );\n return stdout.trim();\n } catch (error) {\n throw new Error(`Command failed: ${command}\\n${error}`);\n }\n }\n\n async isGitRepository(): Promise<boolean> {\n try {\n await this.runGitCommand(\"rev-parse --git-dir\");\n return true;\n } catch {\n return false;\n }\n }\n\n async getCurrentBranch(): Promise<string> {\n return await this.runGitCommand(\"branch --show-current\");\n }\n\n async getDefaultBranch(): Promise<string> {\n try {\n // Try to get the default branch from remote\n const remoteBranch = await this.runGitCommand(\n \"symbolic-ref refs/remotes/origin/HEAD\",\n );\n return remoteBranch.replace(\"refs/remotes/origin/\", \"\");\n } catch {\n // Fallback: check if main exists, otherwise use master\n if (await this.branchExists(\"main\")) {\n return \"main\";\n } else if (await this.branchExists(\"master\")) {\n return \"master\";\n } else {\n throw new Error(\n \"Cannot determine default branch. No main or master branch found.\",\n );\n }\n }\n }\n\n async branchExists(branchName: string): Promise<boolean> {\n try {\n await this.runGitCommand(`rev-parse --verify ${branchName}`);\n return true;\n } catch {\n return false;\n }\n }\n\n async createBranch(branchName: string, baseBranch?: string): Promise<void> {\n const base = baseBranch || (await this.getCurrentBranch());\n await this.runGitCommand(`checkout -b ${branchName} ${base}`);\n }\n\n async switchToBranch(branchName: string): Promise<void> {\n await this.runGitCommand(`checkout ${branchName}`);\n }\n\n async resetToDefaultBranchIfNeeded(): Promise<boolean> {\n const currentBranch = await this.getCurrentBranch();\n const defaultBranch = await this.getDefaultBranch();\n\n if (currentBranch === defaultBranch) {\n this.logger.debug(\"Already on default branch\", { branch: defaultBranch });\n return true;\n }\n\n if (await this.hasChanges()) {\n this.logger.warn(\"Skipping branch reset - uncommitted changes present\", {\n currentBranch,\n defaultBranch,\n });\n return false;\n }\n\n await this.switchToBranch(defaultBranch);\n this.logger.info(\"Reset to default branch\", {\n from: currentBranch,\n to: defaultBranch,\n });\n return true;\n }\n\n async createOrSwitchToBranch(\n branchName: string,\n baseBranch?: string,\n ): Promise<void> {\n await this.ensureCleanWorkingDirectory(\"switching branches\");\n\n const exists = await this.branchExists(branchName);\n if (exists) {\n await this.switchToBranch(branchName);\n } else {\n await this.createBranch(branchName, baseBranch);\n }\n }\n\n async addFiles(paths: string[]): Promise<void> {\n const pathList = paths.map((p) => `\"${this.escapeShellArg(p)}\"`).join(\" \");\n await this.runGitCommand(`add ${pathList}`);\n }\n\n async addAllPostHogFiles(): Promise<void> {\n try {\n // Use -A flag to add all changes (including new files) and ignore errors if directory is empty\n await this.runGitCommand(\"add -A .posthog/\");\n } catch (error) {\n // If the directory doesn't exist or has no files, that's fine - just log and continue\n this.logger.debug(\"No PostHog files to add\", { error });\n }\n }\n\n async commitChanges(\n message: string,\n options?: {\n authorName?: string;\n authorEmail?: string;\n },\n ): Promise<string> {\n const command = this.buildCommitCommand(message, options);\n return await this.runGitCommand(command);\n }\n\n async hasChanges(): Promise<boolean> {\n try {\n const status = await this.runGitCommand(\"status --porcelain\");\n if (!status || status.trim().length === 0) {\n return false;\n }\n\n const lines = status.split(\"\\n\").filter((line) => {\n const trimmed = line.trim();\n return trimmed.length > 0 && !trimmed.includes(\".posthog/\");\n });\n\n return lines.length > 0;\n } catch {\n return false;\n }\n }\n\n async hasStagedChanges(): Promise<boolean> {\n try {\n const status = await this.runGitCommand(\"diff --cached --name-only\");\n return status.length > 0;\n } catch {\n return false;\n }\n }\n\n // Helper: Centralized safety check for uncommitted changes\n private async ensureCleanWorkingDirectory(operation: string): Promise<void> {\n if (await this.hasChanges()) {\n throw new Error(\n `Uncommitted changes detected. Please commit or stash changes before ${operation}.`,\n );\n }\n }\n\n private async generateUniqueBranchName(baseName: string): Promise<string> {\n if (!(await this.branchExists(baseName))) {\n return baseName;\n }\n\n let counter = 1;\n let uniqueName = `${baseName}-${counter}`;\n while (await this.branchExists(uniqueName)) {\n counter++;\n uniqueName = `${baseName}-${counter}`;\n }\n return uniqueName;\n }\n\n private async ensureOnDefaultBranch(): Promise<string> {\n const defaultBranch = await this.getDefaultBranch();\n const currentBranch = await this.getCurrentBranch();\n\n if (currentBranch !== defaultBranch) {\n await this.ensureCleanWorkingDirectory(\"switching to default branch\");\n await this.switchToBranch(defaultBranch);\n }\n\n return defaultBranch;\n }\n\n private buildCommitCommand(\n message: string,\n options?: {\n allowEmpty?: boolean;\n authorName?: string;\n authorEmail?: string;\n },\n ): string {\n let command = `commit -m \"${this.escapeShellArg(message)}\"`;\n\n if (options?.allowEmpty) {\n command += \" --allow-empty\";\n }\n\n const authorName = options?.authorName || this.authorName;\n const authorEmail = options?.authorEmail || this.authorEmail;\n\n if (authorName && authorEmail) {\n command += ` --author=\"${authorName} <${authorEmail}>\"`;\n }\n\n return command;\n }\n\n async getRemoteUrl(): Promise<string | null> {\n try {\n return await this.runGitCommand(\"remote get-url origin\");\n } catch {\n return null;\n }\n }\n\n async pushBranch(branchName: string, force: boolean = false): Promise<void> {\n const forceFlag = force ? \"--force\" : \"\";\n await this.runGitCommand(`push ${forceFlag} -u origin ${branchName}`);\n }\n\n /**\n * Tracks whether commits were made during an operation by comparing HEAD SHA\n * before and after. Returns an object with methods to finalize the operation.\n *\n * Usage:\n * const tracker = await gitManager.trackCommitsDuring();\n * // ... do work that might create commits ...\n * const result = await tracker.finalize({ commitMessage: 'fallback message', push: true });\n */\n async trackCommitsDuring(): Promise<{\n finalize: (options: {\n commitMessage: string;\n push?: boolean;\n }) => Promise<{ commitCreated: boolean; pushedBranch: boolean }>;\n }> {\n const initialSha = await this.getCommitSha(\"HEAD\");\n\n return {\n finalize: async (options) => {\n const currentSha = await this.getCommitSha(\"HEAD\");\n const externalCommitsCreated = initialSha !== currentSha;\n const hasUncommittedChanges = await this.hasChanges();\n\n // If no commits and no changes, nothing to do\n if (!externalCommitsCreated && !hasUncommittedChanges) {\n return { commitCreated: false, pushedBranch: false };\n }\n\n let commitCreated = externalCommitsCreated;\n\n // Commit any remaining uncommitted changes\n if (hasUncommittedChanges) {\n await this.runGitCommand(\"add .\");\n const hasStagedChanges = await this.hasStagedChanges();\n\n if (hasStagedChanges) {\n await this.commitChanges(options.commitMessage);\n commitCreated = true;\n }\n }\n\n // Push if requested and commits were made\n let pushedBranch = false;\n if (options.push && commitCreated) {\n const currentBranch = await this.getCurrentBranch();\n await this.pushBranch(currentBranch);\n pushedBranch = true;\n this.logger.info(\"Pushed branch after operation\", {\n branch: currentBranch,\n });\n }\n\n return { commitCreated, pushedBranch };\n },\n };\n }\n\n async createTaskBranch(taskSlug: string): Promise<string> {\n const branchName = `posthog/task-${taskSlug}`;\n\n // Ensure we're on default branch before creating task branch\n const defaultBranch = await this.ensureOnDefaultBranch();\n\n this.logger.info(\"Creating task branch from default branch\", {\n branchName,\n taskSlug,\n baseBranch: defaultBranch,\n });\n\n await this.createOrSwitchToBranch(branchName, defaultBranch);\n\n return branchName;\n }\n\n async createTaskPlanningBranch(\n taskId: string,\n baseBranch?: string,\n ): Promise<string> {\n const baseName = `posthog/task-${taskId}-planning`;\n const branchName = await this.generateUniqueBranchName(baseName);\n\n this.logger.debug(\"Creating unique planning branch\", {\n branchName,\n taskId,\n });\n\n const base = baseBranch || (await this.ensureOnDefaultBranch());\n await this.createBranch(branchName, base);\n\n return branchName;\n }\n\n async createTaskImplementationBranch(\n taskId: string,\n planningBranchName?: string,\n ): Promise<string> {\n const baseName = `posthog/task-${taskId}-implementation`;\n const branchName = await this.generateUniqueBranchName(baseName);\n\n this.logger.debug(\"Creating unique implementation branch\", {\n branchName,\n taskId,\n currentBranch: await this.getCurrentBranch(),\n });\n\n // Determine base branch: explicit param > current planning branch > default\n let baseBranch = planningBranchName;\n\n if (!baseBranch) {\n const currentBranch = await this.getCurrentBranch();\n if (currentBranch.includes(\"-planning\")) {\n baseBranch = currentBranch;\n this.logger.debug(\"Using current planning branch\", { baseBranch });\n } else {\n baseBranch = await this.ensureOnDefaultBranch();\n this.logger.debug(\"Using default branch\", { baseBranch });\n }\n }\n\n this.logger.debug(\"Creating implementation branch from base\", {\n baseBranch,\n branchName,\n });\n await this.createBranch(branchName, baseBranch);\n\n this.logger.info(\"Implementation branch created\", {\n branchName,\n currentBranch: await this.getCurrentBranch(),\n });\n\n return branchName;\n }\n\n async commitPlan(taskId: string, taskTitle: string): Promise<string> {\n const currentBranch = await this.getCurrentBranch();\n this.logger.debug(\"Committing plan\", { taskId, currentBranch });\n\n await this.addAllPostHogFiles();\n\n const hasChanges = await this.hasStagedChanges();\n this.logger.debug(\"Checking for staged changes\", { hasChanges });\n\n if (!hasChanges) {\n this.logger.info(\"No plan changes to commit\", { taskId });\n return \"No changes to commit\";\n }\n\n const message = `📋 Add plan for task: ${taskTitle}\n\nTask ID: ${taskId}\nGenerated by PostHog Agent\n\nThis commit contains the implementation plan and supporting documentation\nfor the task. Review the plan before proceeding with implementation.`;\n\n const result = await this.commitChanges(message);\n this.logger.info(\"Plan committed\", { taskId, taskTitle });\n return result;\n }\n\n async commitImplementation(\n taskId: string,\n taskTitle: string,\n planSummary?: string,\n ): Promise<string> {\n await this.runGitCommand(\"add .\");\n\n const hasChanges = await this.hasStagedChanges();\n if (!hasChanges) {\n this.logger.warn(\"No implementation changes to commit\", { taskId });\n return \"No changes to commit\";\n }\n\n let message = `✨ Implement task: ${taskTitle}\n\nTask ID: ${taskId}\nGenerated by PostHog Agent`;\n\n if (planSummary) {\n message += `\\n\\nPlan Summary:\\n${planSummary}`;\n }\n\n message += `\\n\\nThis commit implements the changes described in the task plan.`;\n\n const result = await this.commitChanges(message);\n this.logger.info(\"Implementation committed\", { taskId, taskTitle });\n return result;\n }\n\n async deleteBranch(\n branchName: string,\n force: boolean = false,\n ): Promise<void> {\n const forceFlag = force ? \"-D\" : \"-d\";\n await this.runGitCommand(`branch ${forceFlag} ${branchName}`);\n }\n\n async deleteRemoteBranch(branchName: string): Promise<void> {\n await this.runGitCommand(`push origin --delete ${branchName}`);\n }\n\n async getBranchInfo(branchName: string): Promise<BranchInfo> {\n const exists = await this.branchExists(branchName);\n const currentBranch = await this.getCurrentBranch();\n\n return {\n name: branchName,\n exists,\n isCurrentBranch: branchName === currentBranch,\n };\n }\n\n async getCommitSha(ref: string = \"HEAD\"): Promise<string> {\n return await this.runGitCommand(`rev-parse ${ref}`);\n }\n\n async getCommitMessage(ref: string = \"HEAD\"): Promise<string> {\n return await this.runGitCommand(`log -1 --pretty=%B ${ref}`);\n }\n\n async createPullRequest(\n branchName: string,\n title: string,\n body: string,\n baseBranch?: string,\n ): Promise<string> {\n const currentBranch = await this.getCurrentBranch();\n if (currentBranch !== branchName) {\n await this.ensureCleanWorkingDirectory(\"creating PR\");\n await this.switchToBranch(branchName);\n }\n\n await this.pushBranch(branchName);\n\n let command = `gh pr create --title \"${this.escapeShellArg(title)}\" --body \"${this.escapeShellArg(body)}\"`;\n\n if (baseBranch) {\n command += ` --base ${baseBranch}`;\n }\n\n try {\n const prUrl = await this.runCommand(command);\n return prUrl.trim();\n } catch (error) {\n throw new Error(`Failed to create PR: ${error}`);\n }\n }\n\n async getTaskBranch(taskSlug: string): Promise<string | null> {\n try {\n // Get all branches matching the task slug pattern\n const branches = await this.runGitCommand(\"branch --list --all\");\n const branchPattern = `posthog/task-${taskSlug}`;\n\n // Look for exact match or with counter suffix\n const lines = branches\n .split(\"\\n\")\n .map((l) => l.trim().replace(/^\\*\\s+/, \"\"));\n for (const line of lines) {\n const cleanBranch = line.replace(\"remotes/origin/\", \"\");\n if (cleanBranch.startsWith(branchPattern)) {\n return cleanBranch;\n }\n }\n\n return null;\n } catch (error) {\n this.logger.debug(\"Failed to get task branch\", { taskSlug, error });\n return null;\n }\n }\n\n async commitAndPush(\n message: string,\n options?: { allowEmpty?: boolean },\n ): Promise<void> {\n const hasChanges = await this.hasStagedChanges();\n\n if (!hasChanges && !options?.allowEmpty) {\n this.logger.debug(\"No changes to commit, skipping\");\n return;\n }\n\n const command = this.buildCommitCommand(message, options);\n await this.runGitCommand(command);\n\n // Push to origin\n const currentBranch = await this.getCurrentBranch();\n await this.pushBranch(currentBranch);\n\n this.logger.info(\"Committed and pushed changes\", {\n branch: currentBranch,\n message,\n });\n }\n}\n"],"names":[],"mappings":";;;;AAIA,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;MAepB,UAAU,CAAA;AACb,IAAA,cAAc;AACd,IAAA,UAAU;AACV,IAAA,WAAW;AACX,IAAA,MAAM;AAEd,IAAA,WAAA,CAAY,MAAiB,EAAA;AAC3B,QAAA,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc;AAC3C,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACnC,QAAA,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW;AACrC,QAAA,IAAI,CAAC,MAAM;AACT,YAAA,MAAM,CAAC,MAAM,IAAI,IAAI,MAAM,CA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R,SAAA,CAAC;IACJ;AACD;;;;"}
1
+ {"version":3,"file":"git-manager.js","sources":["../../src/git-manager.ts"],"sourcesContent":["import { exec } from 'child_process';\nimport { promisify } from 'util';\nimport { Logger } from './utils/logger.js';\n\nconst execAsync = promisify(exec);\n\nexport interface GitConfig {\n repositoryPath: string;\n authorName?: string;\n authorEmail?: string;\n logger?: Logger;\n}\n\nexport interface BranchInfo {\n name: string;\n exists: boolean;\n isCurrentBranch: boolean;\n}\n\nexport class GitManager {\n private repositoryPath: string;\n private authorName?: string;\n private authorEmail?: string;\n private logger: Logger;\n\n constructor(config: GitConfig) {\n this.repositoryPath = config.repositoryPath;\n this.authorName = config.authorName;\n this.authorEmail = config.authorEmail;\n this.logger = config.logger || new Logger({ debug: false, prefix: '[GitManager]' });\n }\n\n private escapeShellArg(str: string): string {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/`/g, '\\\\`')\n .replace(/\\$/g, '\\\\$');\n }\n\n private async runGitCommand(command: string): Promise<string> {\n try {\n const { stdout } = await execAsync(`cd \"${this.repositoryPath}\" && git ${command}`);\n return stdout.trim();\n } catch (error) {\n throw new Error(`Git command failed: ${command}\\n${error}`);\n }\n }\n\n private async runCommand(command: string): Promise<string> {\n try {\n const { stdout } = await execAsync(`cd \"${this.repositoryPath}\" && ${command}`);\n return stdout.trim();\n } catch (error) {\n throw new Error(`Command failed: ${command}\\n${error}`);\n }\n }\n\n async isGitRepository(): Promise<boolean> {\n try {\n await this.runGitCommand('rev-parse --git-dir');\n return true;\n } catch {\n return false;\n }\n }\n\n async getCurrentBranch(): Promise<string> {\n return await this.runGitCommand('branch --show-current');\n }\n\n async getDefaultBranch(): Promise<string> {\n try {\n // Try to get the default branch from remote\n const remoteBranch = await this.runGitCommand('symbolic-ref refs/remotes/origin/HEAD');\n return remoteBranch.replace('refs/remotes/origin/', '');\n } catch {\n // Fallback: check if main exists, otherwise use master\n if (await this.branchExists('main')) {\n return 'main';\n } else if (await this.branchExists('master')) {\n return 'master';\n } else {\n throw new Error('Cannot determine default branch. No main or master branch found.');\n }\n }\n }\n\n async branchExists(branchName: string): Promise<boolean> {\n try {\n await this.runGitCommand(`rev-parse --verify ${branchName}`);\n return true;\n } catch {\n return false;\n }\n }\n\n async createBranch(branchName: string, baseBranch?: string): Promise<void> {\n const base = baseBranch || await this.getCurrentBranch();\n await this.runGitCommand(`checkout -b ${branchName} ${base}`);\n }\n\n async switchToBranch(branchName: string): Promise<void> {\n await this.runGitCommand(`checkout ${branchName}`);\n }\n\n async resetToDefaultBranchIfNeeded(): Promise<boolean> {\n const currentBranch = await this.getCurrentBranch();\n const defaultBranch = await this.getDefaultBranch();\n\n if (currentBranch === defaultBranch) {\n this.logger.debug('Already on default branch', { branch: defaultBranch });\n return true;\n }\n\n if (await this.hasChanges()) {\n this.logger.warn('Skipping branch reset - uncommitted changes present', {\n currentBranch,\n defaultBranch\n });\n return false;\n }\n\n await this.switchToBranch(defaultBranch);\n this.logger.info('Reset to default branch', { from: currentBranch, to: defaultBranch });\n return true;\n }\n\n async createOrSwitchToBranch(branchName: string, baseBranch?: string): Promise<void> {\n await this.ensureCleanWorkingDirectory('switching branches');\n\n const exists = await this.branchExists(branchName);\n if (exists) {\n await this.switchToBranch(branchName);\n } else {\n await this.createBranch(branchName, baseBranch);\n }\n }\n\n async addFiles(paths: string[]): Promise<void> {\n const pathList = paths.map(p => `\"${this.escapeShellArg(p)}\"`).join(' ');\n await this.runGitCommand(`add ${pathList}`);\n }\n\n async addAllPostHogFiles(): Promise<void> {\n try {\n // Use -A flag to add all changes (including new files) and ignore errors if directory is empty\n await this.runGitCommand('add -A .posthog/');\n } catch (error) {\n // If the directory doesn't exist or has no files, that's fine - just log and continue\n this.logger.debug('No PostHog files to add', { error });\n }\n }\n\n async commitChanges(message: string, options?: {\n authorName?: string;\n authorEmail?: string;\n }): Promise<string> {\n const command = this.buildCommitCommand(message, options);\n return await this.runGitCommand(command);\n }\n\n async hasChanges(): Promise<boolean> {\n try {\n const status = await this.runGitCommand('status --porcelain');\n if (!status || status.trim().length === 0) {\n return false;\n }\n\n const lines = status.split('\\n').filter(line => {\n const trimmed = line.trim();\n return trimmed.length > 0 && !trimmed.includes('.posthog/');\n });\n\n return lines.length > 0;\n } catch {\n return false;\n }\n }\n\n async hasStagedChanges(): Promise<boolean> {\n try {\n const status = await this.runGitCommand('diff --cached --name-only');\n return status.length > 0;\n } catch {\n return false;\n }\n }\n\n // Helper: Centralized safety check for uncommitted changes\n private async ensureCleanWorkingDirectory(operation: string): Promise<void> {\n if (await this.hasChanges()) {\n throw new Error(`Uncommitted changes detected. Please commit or stash changes before ${operation}.`);\n }\n }\n\n private async generateUniqueBranchName(baseName: string): Promise<string> {\n if (!await this.branchExists(baseName)) {\n return baseName;\n }\n\n let counter = 1;\n let uniqueName = `${baseName}-${counter}`;\n while (await this.branchExists(uniqueName)) {\n counter++;\n uniqueName = `${baseName}-${counter}`;\n }\n return uniqueName;\n }\n\n private async ensureOnDefaultBranch(): Promise<string> {\n const defaultBranch = await this.getDefaultBranch();\n const currentBranch = await this.getCurrentBranch();\n\n if (currentBranch !== defaultBranch) {\n await this.ensureCleanWorkingDirectory('switching to default branch');\n await this.switchToBranch(defaultBranch);\n }\n\n return defaultBranch;\n }\n\n private buildCommitCommand(message: string, options?: { allowEmpty?: boolean; authorName?: string; authorEmail?: string }): string {\n let command = `commit -m \"${this.escapeShellArg(message)}\"`;\n\n if (options?.allowEmpty) {\n command += ' --allow-empty';\n }\n\n const authorName = options?.authorName || this.authorName;\n const authorEmail = options?.authorEmail || this.authorEmail;\n\n if (authorName && authorEmail) {\n command += ` --author=\"${authorName} <${authorEmail}>\"`;\n }\n\n return command;\n }\n\n async getRemoteUrl(): Promise<string | null> {\n try {\n return await this.runGitCommand('remote get-url origin');\n } catch {\n return null;\n }\n }\n\n async pushBranch(branchName: string, force: boolean = false): Promise<void> {\n const forceFlag = force ? '--force' : '';\n await this.runGitCommand(`push ${forceFlag} -u origin ${branchName}`);\n }\n\n /**\n * Tracks whether commits were made during an operation by comparing HEAD SHA\n * before and after. Returns an object with methods to finalize the operation.\n *\n * Usage:\n * const tracker = await gitManager.trackCommitsDuring();\n * // ... do work that might create commits ...\n * const result = await tracker.finalize({ commitMessage: 'fallback message', push: true });\n */\n async trackCommitsDuring(): Promise<{\n finalize: (options: {\n commitMessage: string;\n push?: boolean;\n }) => Promise<{ commitCreated: boolean; pushedBranch: boolean }>;\n }> {\n const initialSha = await this.getCommitSha('HEAD');\n\n return {\n finalize: async (options) => {\n const currentSha = await this.getCommitSha('HEAD');\n const externalCommitsCreated = initialSha !== currentSha;\n const hasUncommittedChanges = await this.hasChanges();\n\n // If no commits and no changes, nothing to do\n if (!externalCommitsCreated && !hasUncommittedChanges) {\n return { commitCreated: false, pushedBranch: false };\n }\n\n let commitCreated = externalCommitsCreated;\n\n // Commit any remaining uncommitted changes\n if (hasUncommittedChanges) {\n await this.runGitCommand('add .');\n const hasStagedChanges = await this.hasStagedChanges();\n\n if (hasStagedChanges) {\n await this.commitChanges(options.commitMessage);\n commitCreated = true;\n }\n }\n\n // Push if requested and commits were made\n let pushedBranch = false;\n if (options.push && commitCreated) {\n const currentBranch = await this.getCurrentBranch();\n await this.pushBranch(currentBranch);\n pushedBranch = true;\n this.logger.info('Pushed branch after operation', { branch: currentBranch });\n }\n\n return { commitCreated, pushedBranch };\n }\n };\n }\n\n async createTaskBranch(taskSlug: string): Promise<string> {\n const branchName = `posthog/task-${taskSlug}`;\n\n // Ensure we're on default branch before creating task branch\n const defaultBranch = await this.ensureOnDefaultBranch();\n\n this.logger.info('Creating task branch from default branch', {\n branchName,\n taskSlug,\n baseBranch: defaultBranch\n });\n\n await this.createOrSwitchToBranch(branchName, defaultBranch);\n\n return branchName;\n }\n\n async createTaskPlanningBranch(taskId: string, baseBranch?: string): Promise<string> {\n const baseName = `posthog/task-${taskId}-planning`;\n const branchName = await this.generateUniqueBranchName(baseName);\n\n this.logger.debug('Creating unique planning branch', { branchName, taskId });\n\n const base = baseBranch || await this.ensureOnDefaultBranch();\n await this.createBranch(branchName, base);\n\n return branchName;\n }\n\n async createTaskImplementationBranch(taskId: string, planningBranchName?: string): Promise<string> {\n const baseName = `posthog/task-${taskId}-implementation`;\n const branchName = await this.generateUniqueBranchName(baseName);\n\n this.logger.debug('Creating unique implementation branch', {\n branchName,\n taskId,\n currentBranch: await this.getCurrentBranch()\n });\n\n // Determine base branch: explicit param > current planning branch > default\n let baseBranch = planningBranchName;\n\n if (!baseBranch) {\n const currentBranch = await this.getCurrentBranch();\n if (currentBranch.includes('-planning')) {\n baseBranch = currentBranch;\n this.logger.debug('Using current planning branch', { baseBranch });\n } else {\n baseBranch = await this.ensureOnDefaultBranch();\n this.logger.debug('Using default branch', { baseBranch });\n }\n }\n\n this.logger.debug('Creating implementation branch from base', { baseBranch, branchName });\n await this.createBranch(branchName, baseBranch);\n\n this.logger.info('Implementation branch created', {\n branchName,\n currentBranch: await this.getCurrentBranch()\n });\n\n return branchName;\n }\n\n async commitPlan(taskId: string, taskTitle: string): Promise<string> {\n const currentBranch = await this.getCurrentBranch();\n this.logger.debug('Committing plan', { taskId, currentBranch });\n\n await this.addAllPostHogFiles();\n\n const hasChanges = await this.hasStagedChanges();\n this.logger.debug('Checking for staged changes', { hasChanges });\n\n if (!hasChanges) {\n this.logger.info('No plan changes to commit', { taskId });\n return 'No changes to commit';\n }\n\n const message = `📋 Add plan for task: ${taskTitle}\n\nTask ID: ${taskId}\nGenerated by PostHog Agent\n\nThis commit contains the implementation plan and supporting documentation\nfor the task. Review the plan before proceeding with implementation.`;\n\n const result = await this.commitChanges(message);\n this.logger.info('Plan committed', { taskId, taskTitle });\n return result;\n }\n\n async commitImplementation(taskId: string, taskTitle: string, planSummary?: string): Promise<string> {\n await this.runGitCommand('add .');\n\n const hasChanges = await this.hasStagedChanges();\n if (!hasChanges) {\n this.logger.warn('No implementation changes to commit', { taskId });\n return 'No changes to commit';\n }\n\n let message = `✨ Implement task: ${taskTitle}\n\nTask ID: ${taskId}\nGenerated by PostHog Agent`;\n\n if (planSummary) {\n message += `\\n\\nPlan Summary:\\n${planSummary}`;\n }\n\n message += `\\n\\nThis commit implements the changes described in the task plan.`;\n\n const result = await this.commitChanges(message);\n this.logger.info('Implementation committed', { taskId, taskTitle });\n return result;\n }\n\n async deleteBranch(branchName: string, force: boolean = false): Promise<void> {\n const forceFlag = force ? '-D' : '-d';\n await this.runGitCommand(`branch ${forceFlag} ${branchName}`);\n }\n\n async deleteRemoteBranch(branchName: string): Promise<void> {\n await this.runGitCommand(`push origin --delete ${branchName}`);\n }\n\n async getBranchInfo(branchName: string): Promise<BranchInfo> {\n const exists = await this.branchExists(branchName);\n const currentBranch = await this.getCurrentBranch();\n\n return {\n name: branchName,\n exists,\n isCurrentBranch: branchName === currentBranch\n };\n }\n\n async getCommitSha(ref: string = 'HEAD'): Promise<string> {\n return await this.runGitCommand(`rev-parse ${ref}`);\n }\n\n async getCommitMessage(ref: string = 'HEAD'): Promise<string> {\n return await this.runGitCommand(`log -1 --pretty=%B ${ref}`);\n }\n\n async createPullRequest(\n branchName: string,\n title: string,\n body: string,\n baseBranch?: string\n ): Promise<string> {\n const currentBranch = await this.getCurrentBranch();\n if (currentBranch !== branchName) {\n await this.ensureCleanWorkingDirectory('creating PR');\n await this.switchToBranch(branchName);\n }\n\n await this.pushBranch(branchName);\n\n let command = `gh pr create --title \"${this.escapeShellArg(title)}\" --body \"${this.escapeShellArg(body)}\"`;\n\n if (baseBranch) {\n command += ` --base ${baseBranch}`;\n }\n\n try {\n const prUrl = await this.runCommand(command);\n return prUrl.trim();\n } catch (error) {\n throw new Error(`Failed to create PR: ${error}`);\n }\n }\n\n async getTaskBranch(taskSlug: string): Promise<string | null> {\n try {\n // Get all branches matching the task slug pattern\n const branches = await this.runGitCommand('branch --list --all');\n const branchPattern = `posthog/task-${taskSlug}`;\n \n // Look for exact match or with counter suffix\n const lines = branches.split('\\n').map(l => l.trim().replace(/^\\*\\s+/, ''));\n for (const line of lines) {\n const cleanBranch = line.replace('remotes/origin/', '');\n if (cleanBranch.startsWith(branchPattern)) {\n return cleanBranch;\n }\n }\n \n return null;\n } catch (error) {\n this.logger.debug('Failed to get task branch', { taskSlug, error });\n return null;\n }\n }\n\n async commitAndPush(message: string, options?: { allowEmpty?: boolean }): Promise<void> {\n const hasChanges = await this.hasStagedChanges();\n\n if (!hasChanges && !options?.allowEmpty) {\n this.logger.debug('No changes to commit, skipping');\n return;\n }\n\n const command = this.buildCommitCommand(message, options);\n await this.runGitCommand(command);\n\n // Push to origin\n const currentBranch = await this.getCurrentBranch();\n await this.pushBranch(currentBranch);\n\n this.logger.info('Committed and pushed changes', { branch: currentBranch, message });\n }\n}\n"],"names":[],"mappings":";;;;AAIA,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;MAepB,UAAU,CAAA;AACb,IAAA,cAAc;AACd,IAAA,UAAU;AACV,IAAA,WAAW;AACX,IAAA,MAAM;AAEd,IAAA,WAAA,CAAY,MAAiB,EAAA;AAC3B,QAAA,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc;AAC3C,QAAA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU;AACnC,QAAA,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;IACrF;AAEQ,IAAA,cAAc,CAAC,GAAW,EAAA;AAChC,QAAA,OAAO;AACJ,aAAA,OAAO,CAAC,KAAK,EAAE,MAAM;AACrB,aAAA,OAAO,CAAC,IAAI,EAAE,KAAK;AACnB,aAAA,OAAO,CAAC,IAAI,EAAE,KAAK;AACnB,aAAA,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;IAC1B;IAEQ,MAAM,aAAa,CAAC,OAAe,EAAA;AACzC,QAAA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AO,IAAI;QACb;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACnE,YAAA,OAAO,IAAI;QACb;IACF;AAEA,IAAA,MAAM,aAAa,CAAC,OAAe,EAAE,OAAkC,EAAA;AACrE,QAAA,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE;QAEhD,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE;AACvC,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC;YACnD;QACF;QAEA,MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC;AACzD,QAAA,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;;AAGjC,QAAA,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE;AACnD,QAAA,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;AAEpC,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;IACtF;AACD;;;;"}
@@ -1,4 +1,4 @@
1
- import type { LogEntry, PostHogAPIConfig, PostHogResource, Task, TaskArtifactUploadPayload, TaskRun, TaskRunArtifact, UrlMention } from "./types.js";
1
+ import type { Task, TaskRun, LogEntry, PostHogAPIConfig, PostHogResource, UrlMention, TaskRunArtifact, TaskArtifactUploadPayload } from './types.js';
2
2
  export interface TaskRunUpdate {
3
3
  status?: TaskRun["status"];
4
4
  branch?: string | null;
@@ -9,6 +9,7 @@ export interface TaskRunUpdate {
9
9
  }
10
10
  export declare class PostHogAPIClient {
11
11
  private config;
12
+ private _teamId;
12
13
  constructor(config: PostHogAPIConfig);
13
14
  private get baseUrl();
14
15
  private get headers();
@@ -26,7 +27,7 @@ export declare class PostHogAPIClient {
26
27
  updateTask(taskId: string, updates: Partial<Task>): Promise<Task>;
27
28
  listTaskRuns(taskId: string): Promise<TaskRun[]>;
28
29
  getTaskRun(taskId: string, runId: string): Promise<TaskRun>;
29
- createTaskRun(taskId: string, payload?: Partial<Omit<TaskRun, "id" | "task" | "team" | "created_at" | "updated_at" | "completed_at">>): Promise<TaskRun>;
30
+ createTaskRun(taskId: string, payload?: Partial<Omit<TaskRun, 'id' | 'task' | 'team' | 'created_at' | 'updated_at' | 'completed_at'>>): Promise<TaskRun>;
30
31
  updateTaskRun(taskId: string, runId: string, payload: TaskRunUpdate): Promise<TaskRun>;
31
32
  setTaskRunOutput(taskId: string, runId: string, output: Record<string, unknown>): Promise<TaskRun>;
32
33
  appendTaskRunLog(taskId: string, runId: string, entries: LogEntry[]): Promise<TaskRun>;
@@ -1 +1 @@
1
- {"version":3,"file":"posthog-api.d.ts","sourceRoot":"","sources":["../../src/posthog-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,IAAI,EACJ,yBAAyB,EACzB,OAAO,EACP,eAAe,EACf,UAAU,EACX,MAAM,YAAY,CAAC;AASpB,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,gBAAgB;IAIpC,OAAO,KAAK,O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