@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,4 +1,4 @@
1
- import type { ToolCallEvent, ToolResultEvent } from "../../types.js";
1
+ import type { ToolCallEvent, ToolResultEvent } from '../../types.js';
2
2
  /**
3
3
  * Maps Claude tool names to our tool type system.
4
4
  * Enriches tool events with metadata for better UI consumption.
@@ -1 +1 @@
1
- {"version":3,"file":"tool-mapper.d.ts","sourceRoot":"","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErE;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAsB;IAEtC;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa;IAcnD;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe;CAa1D"}
1
+ {"version":3,"file":"tool-mapper.d.ts","sourceRoot":"","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGrE;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAsB;IAEtC;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa;IAcnD;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe;CAa1D"}
@@ -1 +1 @@
1
- {"version":3,"file":"tool-mapper.js","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"sourcesContent":["import { ToolRegistry } from \"../../tools/registry.js\";\nimport type { ToolCallEvent, ToolResultEvent } from \"../../types.js\";\n\n/**\n * Maps Claude tool names to our tool type system.\n * Enriches tool events with metadata for better UI consumption.\n */\nexport class ClaudeToolMapper {\n private registry = new ToolRegistry();\n\n /**\n * Enrich a tool call event with tool metadata.\n * Looks up the tool definition and adds it to the event.\n */\n enrichToolCall(event: ToolCallEvent): ToolCallEvent {\n const tool = this.registry.get(event.toolName);\n if (!tool) {\n // Tool not recognized, return as-is\n return event;\n }\n\n return {\n ...event,\n tool,\n category: tool.category,\n };\n }\n\n /**\n * Enrich a tool result event with tool metadata.\n * Looks up the tool definition and adds it to the event.\n */\n enrichToolResult(event: ToolResultEvent): ToolResultEvent {\n const tool = this.registry.get(event.toolName);\n if (!tool) {\n // Tool not recognized, return as-is\n return event;\n }\n\n return {\n ...event,\n tool,\n category: tool.category,\n };\n }\n}\n"],"names":[],"mappings":";;AAGA;;;AAGG;MACU,gBAAgB,CAAA;AACnB,IAAA,QAAQ,GAAG,IAAI,YAAY,EAAE;AAErC;;;AAGG;AACH,IAAA,cAAc,CAAC,KAAoB,EAAA;AACjC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;;AAET,YAAA,OAAO,KAAK;QACd;QAEA,OAAO;AACL,YAAA,GAAG,KAAK;YACR,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;IACH;AAEA;;;AAGG;AACH,IAAA,gBAAgB,CAAC,KAAsB,EAAA;AACrC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;;AAET,YAAA,OAAO,KAAK;QACd;QAEA,OAAO;AACL,YAAA,GAAG,KAAK;YACR,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;IACH;AACD;;;;"}
1
+ {"version":3,"file":"tool-mapper.js","sources":["../../../../src/adapters/claude/tool-mapper.ts"],"sourcesContent":["import type { ToolCallEvent, ToolResultEvent } from '../../types.js';\nimport { ToolRegistry } from '../../tools/registry.js';\n\n/**\n * Maps Claude tool names to our tool type system.\n * Enriches tool events with metadata for better UI consumption.\n */\nexport class ClaudeToolMapper {\n private registry = new ToolRegistry();\n\n /**\n * Enrich a tool call event with tool metadata.\n * Looks up the tool definition and adds it to the event.\n */\n enrichToolCall(event: ToolCallEvent): ToolCallEvent {\n const tool = this.registry.get(event.toolName);\n if (!tool) {\n // Tool not recognized, return as-is\n return event;\n }\n\n return {\n ...event,\n tool,\n category: tool.category,\n };\n }\n\n /**\n * Enrich a tool result event with tool metadata.\n * Looks up the tool definition and adds it to the event.\n */\n enrichToolResult(event: ToolResultEvent): ToolResultEvent {\n const tool = this.registry.get(event.toolName);\n if (!tool) {\n // Tool not recognized, return as-is\n return event;\n }\n\n return {\n ...event,\n tool,\n category: tool.category,\n };\n }\n}\n"],"names":[],"mappings":";;AAGA;;;AAGG;MACU,gBAAgB,CAAA;AACnB,IAAA,QAAQ,GAAG,IAAI,YAAY,EAAE;AAErC;;;AAGG;AACH,IAAA,cAAc,CAAC,KAAoB,EAAA;AACjC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;;AAET,YAAA,OAAO,KAAK;QACd;QAEA,OAAO;AACL,YAAA,GAAG,KAAK;YACR,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;IACH;AAEA;;;AAGG;AACH,IAAA,gBAAgB,CAAC,KAAsB,EAAA;AACrC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE;;AAET,YAAA,OAAO,KAAK;QACd;QAEA,OAAO;AACL,YAAA,GAAG,KAAK;YACR,IAAI;YACJ,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB;IACH;AACD;;;;"}
@@ -1,4 +1,4 @@
1
- import type { AgentEvent, ArtifactEvent, StatusEvent } from "../types.js";
1
+ import type { AgentEvent, StatusEvent, ArtifactEvent } from '../types.js';
2
2
  /**
3
3
  * Provider adapter interface for transforming provider-specific messages
4
4
  * into our standardized AgentEvent format.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7C;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG,GAAG,WAAW,CAAC;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,aAAa,CAAC;IAE/D;;;OAGG;IACH,iBAAiB,CAAC,UAAU,EAAE,GAAG,GAAG,UAAU,CAAC;CAChD"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,SAAS,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7C;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,GAAG,GAAG,WAAW,CAAC;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,aAAa,CAAC;IAE/D;;;OAGG;IACH,iBAAiB,CAAC,UAAU,EAAE,GAAG,GAAG,UAAU,CAAC;CAChD"}
@@ -1,5 +1,5 @@
1
- import { PostHogAPIClient } from "./posthog-api.js";
2
- import type { AgentConfig, CanUseTool, ExecutionResult, Task } from "./types.js";
1
+ import type { Task, ExecutionResult, AgentConfig, CanUseTool } from './types.js';
2
+ import { PostHogAPIClient } from './posthog-api.js';
3
3
  export declare class Agent {
4
4
  private workingDirectory;
5
5
  private onEvent?;
@@ -24,10 +24,10 @@ export declare class Agent {
24
24
  * Configure LLM gateway environment variables for Claude Code CLI
25
25
  */
26
26
  private _configureLlmGateway;
27
- runTask(taskOrId: Task | string, options?: import("./types.js").TaskExecutionOptions): Promise<void>;
27
+ runTask(taskOrId: Task | string, options?: import('./types.js').TaskExecutionOptions): Promise<void>;
28
28
  run(prompt: string, options?: {
29
29
  repositoryPath?: string;
30
- permissionMode?: import("./types.js").PermissionMode;
30
+ permissionMode?: import('./types.js').PermissionMode;
31
31
  queryOverrides?: Record<string, any>;
32
32
  canUseTool?: CanUseTool;
33
33
  }): Promise<ExecutionResult>;
@@ -38,7 +38,7 @@ export declare class Agent {
38
38
  organization?: string;
39
39
  origin_product?: string;
40
40
  }): Promise<Task[]>;
41
- writeTaskFile(taskId: string, fileName: string, content: string, type?: "plan" | "context" | "reference" | "output"): Promise<void>;
41
+ writeTaskFile(taskId: string, fileName: string, content: string, type?: 'plan' | 'context' | 'reference' | 'output'): Promise<void>;
42
42
  readTaskFile(taskId: string, fileName: string): Promise<string | null>;
43
43
  getTaskFiles(taskId: string): Promise<any[]>;
44
44
  writePlan(taskId: string, plan: string): Promise<void>;
@@ -57,6 +57,6 @@ export declare class Agent {
57
57
  private ensurePullRequest;
58
58
  private emitEvent;
59
59
  }
60
- export type { AgentConfig, ExecutionResult, SupportingFile, Task, } from "./types.js";
61
- export { PermissionMode } from "./types.js";
60
+ export { PermissionMode } from './types.js';
61
+ export type { Task, SupportingFile, ExecutionResult, AgentConfig } from './types.js';
62
62
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src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Y,EAAE,IAAI,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
package/dist/src/agent.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { query } from '@anthropic-ai/claude-agent-sdk';
2
- import { ClaudeAdapter } from './adapters/claude/claude-adapter.js';
2
+ import { TaskManager } from './task-manager.js';
3
+ import { PostHogAPIClient } from './posthog-api.js';
3
4
  import { PostHogFileManager } from './file-manager.js';
4
5
  import { GitManager } from './git-manager.js';
5
- import { PostHogAPIClient } from './posthog-api.js';
6
- import { PromptBuilder } from './prompt-builder.js';
7
- import { TaskManager } from './task-manager.js';
8
- import { TaskProgressReporter } from './task-progress-reporter.js';
9
6
  import { TemplateManager } from './template-manager.js';
7
+ import { ClaudeAdapter } from './adapters/claude/claude-adapter.js';
10
8
  import { Logger } from './utils/logger.js';
9
+ import { PromptBuilder } from './prompt-builder.js';
10
+ import { TaskProgressReporter } from './task-progress-reporter.js';
11
11
  import { TASK_WORKFLOW } from './workflow/config.js';
12
12
  export { PermissionMode } from './types.js';
13
13
 
@@ -32,34 +32,34 @@ class Agent {
32
32
  this.canUseTool = config.canUseTool;
33
33
  this.debug = config.debug || false;
34
34
  // Build default PostHog MCP server configuration
35
- const posthogMcpUrl = config.posthogMcpUrl ||
36
- process.env.POSTHOG_MCP_URL ||
37
- "https://mcp.posthog.com/mcp";
35
+ const posthogMcpUrl = config.posthogMcpUrl
36
+ || process.env.POSTHOG_MCP_URL
37
+ || 'https://mcp.posthog.com/mcp';
38
38
  // Add auth if API key provided
39
39
  const headers = {};
40
40
  if (config.posthogApiKey) {
41
- headers.Authorization = `Bearer ${config.posthogApiKey}`;
41
+ headers['Authorization'] = `Bearer ${config.posthogApiKey}`;
42
42
  }
43
43
  const defaultMcpServers = {
44
44
  posthog: {
45
- type: "http",
45
+ type: 'http',
46
46
  url: posthogMcpUrl,
47
47
  ...(Object.keys(headers).length > 0 ? { headers } : {}),
48
- },
48
+ }
49
49
  };
50
50
  // Merge default PostHog MCP with user-provided servers (user config takes precedence)
51
51
  this.mcpServers = {
52
52
  ...defaultMcpServers,
53
- ...config.mcpServers,
53
+ ...config.mcpServers
54
54
  };
55
- this.logger = new Logger({ debug: this.debug, prefix: "[PostHog Agent]" });
55
+ this.logger = new Logger({ debug: this.debug, prefix: '[PostHog Agent]' });
56
56
  this.taskManager = new TaskManager();
57
57
  // Hardcode Claude adapter for now - extensible for other providers later
58
58
  this.adapter = new ClaudeAdapter();
59
- this.fileManager = new PostHogFileManager(this.workingDirectory, this.logger.child("FileManager"));
59
+ this.fileManager = new PostHogFileManager(this.workingDirectory, this.logger.child('FileManager'));
60
60
  this.gitManager = new GitManager({
61
61
  repositoryPath: this.workingDirectory,
62
- logger: this.logger.child("GitManager"),
62
+ logger: this.logger.child('GitManager')
63
63
  // TODO: Add author config from environment or config
64
64
  });
65
65
  this.templateManager = new TemplateManager();
@@ -74,7 +74,7 @@ class Agent {
74
74
  getTaskFiles: (taskId) => this.getTaskFiles(taskId),
75
75
  generatePlanTemplate: (vars) => this.templateManager.generatePlan(vars),
76
76
  posthogClient: this.posthogAPI,
77
- logger: this.logger.child("PromptBuilder"),
77
+ logger: this.logger.child('PromptBuilder')
78
78
  });
79
79
  this.progressReporter = new TaskProgressReporter(this.posthogAPI, this.logger);
80
80
  }
@@ -98,32 +98,24 @@ class Agent {
98
98
  process.env.ANTHROPIC_BASE_URL = gatewayUrl;
99
99
  process.env.ANTHROPIC_AUTH_TOKEN = apiKey;
100
100
  this.ensureOpenAIGatewayEnv(gatewayUrl, apiKey);
101
- this.logger.debug("Configured LLM gateway", { gatewayUrl });
101
+ this.logger.debug('Configured LLM gateway', { gatewayUrl });
102
102
  }
103
103
  catch (error) {
104
- this.logger.error("Failed to configure LLM gateway", error);
104
+ this.logger.error('Failed to configure LLM gateway', error);
105
105
  throw error;
106
106
  }
107
107
  }
108
108
  // Adaptive task execution orchestrated via workflow steps
109
109
  async runTask(taskOrId, options = {}) {
110
110
  await this._configureLlmGateway();
111
- const task = typeof taskOrId === "string" ? await this.fetchTask(taskOrId) : taskOrId;
111
+ const task = typeof taskOrId === 'string' ? await this.fetchTask(taskOrId) : taskOrId;
112
112
  const cwd = options.repositoryPath || this.workingDirectory;
113
113
  const isCloudMode = options.isCloudMode ?? false;
114
114
  const taskSlug = task.slug || task.id;
115
- this.logger.info("Starting adaptive task execution", {
116
- taskId: task.id,
117
- taskSlug,
118
- isCloudMode,
119
- });
115
+ this.logger.info('Starting adaptive task execution', { taskId: task.id, taskSlug, isCloudMode });
120
116
  // Initialize progress reporter for task run tracking (needed for PR attachment)
121
- await this.progressReporter.start(task.id, {
122
- totalSteps: TASK_WORKFLOW.length,
123
- });
124
- this.emitEvent(this.adapter.createStatusEvent("run_started", {
125
- runId: this.progressReporter.runId,
126
- }));
117
+ await this.progressReporter.start(task.id, { totalSteps: TASK_WORKFLOW.length });
118
+ this.emitEvent(this.adapter.createStatusEvent('run_started', { runId: this.progressReporter.runId }));
127
119
  await this.prepareTaskBranch(taskSlug, isCloudMode);
128
120
  let taskError;
129
121
  try {
@@ -154,20 +146,16 @@ class Agent {
154
146
  if (shouldCreatePR) {
155
147
  await this.ensurePullRequest(task, workflowContext.stepResults);
156
148
  }
157
- this.logger.info("Task execution complete", { taskId: task.id });
158
- this.emitEvent(this.adapter.createStatusEvent("task_complete", { taskId: task.id }));
149
+ this.logger.info('Task execution complete', { taskId: task.id });
150
+ this.emitEvent(this.adapter.createStatusEvent('task_complete', { taskId: task.id }));
159
151
  }
160
152
  catch (error) {
161
153
  taskError = error instanceof Error ? error : new Error(String(error));
162
- this.logger.error("Task execution failed", {
163
- taskId: task.id,
164
- error: taskError.message,
165
- });
154
+ this.logger.error('Task execution failed', { taskId: task.id, error: taskError.message });
166
155
  }
167
156
  finally {
168
157
  if (taskError) {
169
158
  await this.progressReporter.fail(taskError);
170
- // biome-ignore lint/correctness/noUnsafeFinally: we actually want to throw the error
171
159
  throw taskError;
172
160
  }
173
161
  else {
@@ -195,30 +183,24 @@ class Agent {
195
183
  options: { ...baseOptions, ...(options.queryOverrides || {}) },
196
184
  });
197
185
  const results = [];
198
- try {
199
- for await (const message of response) {
200
- this.logger.debug("Received message in direct run", message);
201
- // Emit raw SDK event
202
- this.emitEvent(this.adapter.createRawSDKEvent(message));
203
- const transformedEvents = this.adapter.transform(message);
204
- for (const event of transformedEvents) {
205
- this.emitEvent(event);
206
- }
207
- results.push(message);
186
+ for await (const message of response) {
187
+ this.logger.debug('Received message in direct run', message);
188
+ // Emit raw SDK event
189
+ this.emitEvent(this.adapter.createRawSDKEvent(message));
190
+ const transformedEvents = this.adapter.transform(message);
191
+ for (const event of transformedEvents) {
192
+ this.emitEvent(event);
208
193
  }
209
- }
210
- catch (error) {
211
- this.logger.error("Error during direct run", error);
212
- throw error;
194
+ results.push(message);
213
195
  }
214
196
  return { results };
215
197
  }
216
198
  // PostHog task operations
217
199
  async fetchTask(taskId) {
218
- this.logger.debug("Fetching task from PostHog", { taskId });
200
+ this.logger.debug('Fetching task from PostHog', { taskId });
219
201
  if (!this.posthogAPI) {
220
- const error = new Error("PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.");
221
- this.logger.error("PostHog API not configured", error);
202
+ const error = new Error('PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.');
203
+ this.logger.error('PostHog API not configured', error);
222
204
  throw error;
223
205
  }
224
206
  return this.posthogAPI.fetchTask(taskId);
@@ -228,76 +210,60 @@ class Agent {
228
210
  }
229
211
  async listTasks(filters) {
230
212
  if (!this.posthogAPI) {
231
- throw new Error("PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.");
213
+ throw new Error('PostHog API not configured. Provide posthogApiUrl and posthogApiKey in constructor.');
232
214
  }
233
215
  return this.posthogAPI.listTasks(filters);
234
216
  }
235
217
  // File system operations for task artifacts
236
- async writeTaskFile(taskId, fileName, content, type = "reference") {
237
- this.logger.debug("Writing task file", {
238
- taskId,
239
- fileName,
240
- type,
241
- contentLength: content.length,
242
- });
243
- await this.fileManager.writeTaskFile(taskId, {
244
- name: fileName,
245
- content,
246
- type,
247
- });
218
+ async writeTaskFile(taskId, fileName, content, type = 'reference') {
219
+ this.logger.debug('Writing task file', { taskId, fileName, type, contentLength: content.length });
220
+ await this.fileManager.writeTaskFile(taskId, { name: fileName, content, type });
248
221
  }
249
222
  async readTaskFile(taskId, fileName) {
250
- this.logger.debug("Reading task file", { taskId, fileName });
223
+ this.logger.debug('Reading task file', { taskId, fileName });
251
224
  return await this.fileManager.readTaskFile(taskId, fileName);
252
225
  }
253
226
  async getTaskFiles(taskId) {
254
- this.logger.debug("Getting task files", { taskId });
227
+ this.logger.debug('Getting task files', { taskId });
255
228
  const files = await this.fileManager.getTaskFiles(taskId);
256
- this.logger.debug("Found task files", { taskId, fileCount: files.length });
229
+ this.logger.debug('Found task files', { taskId, fileCount: files.length });
257
230
  return files;
258
231
  }
259
232
  async writePlan(taskId, plan) {
260
- this.logger.info("Writing plan", { taskId, planLength: plan.length });
233
+ this.logger.info('Writing plan', { taskId, planLength: plan.length });
261
234
  await this.fileManager.writePlan(taskId, plan);
262
235
  }
263
236
  async readPlan(taskId) {
264
- this.logger.debug("Reading plan", { taskId });
237
+ this.logger.debug('Reading plan', { taskId });
265
238
  return await this.fileManager.readPlan(taskId);
266
239
  }
267
240
  // Git operations for task execution
268
241
  async createPlanningBranch(taskId) {
269
- this.logger.info("Creating planning branch", { taskId });
242
+ this.logger.info('Creating planning branch', { taskId });
270
243
  const branchName = await this.gitManager.createTaskPlanningBranch(taskId);
271
- this.logger.debug("Planning branch created", { taskId, branchName });
244
+ this.logger.debug('Planning branch created', { taskId, branchName });
272
245
  return branchName;
273
246
  }
274
247
  async commitPlan(taskId, taskTitle) {
275
- this.logger.info("Committing plan", { taskId, taskTitle });
248
+ this.logger.info('Committing plan', { taskId, taskTitle });
276
249
  const commitHash = await this.gitManager.commitPlan(taskId, taskTitle);
277
- this.logger.debug("Plan committed", { taskId, commitHash });
250
+ this.logger.debug('Plan committed', { taskId, commitHash });
278
251
  return commitHash;
279
252
  }
280
253
  async createImplementationBranch(taskId, planningBranchName) {
281
- this.logger.info("Creating implementation branch", {
282
- taskId,
283
- fromBranch: planningBranchName,
284
- });
254
+ this.logger.info('Creating implementation branch', { taskId, fromBranch: planningBranchName });
285
255
  const branchName = await this.gitManager.createTaskImplementationBranch(taskId, planningBranchName);
286
- this.logger.debug("Implementation branch created", { taskId, branchName });
256
+ this.logger.debug('Implementation branch created', { taskId, branchName });
287
257
  return branchName;
288
258
  }
289
259
  async commitImplementation(taskId, taskTitle, planSummary) {
290
- this.logger.info("Committing implementation", { taskId, taskTitle });
260
+ this.logger.info('Committing implementation', { taskId, taskTitle });
291
261
  const commitHash = await this.gitManager.commitImplementation(taskId, taskTitle, planSummary);
292
- this.logger.debug("Implementation committed", { taskId, commitHash });
262
+ this.logger.debug('Implementation committed', { taskId, commitHash });
293
263
  return commitHash;
294
264
  }
295
265
  async createPullRequest(taskId, branchName, taskTitle, taskDescription, customBody) {
296
- this.logger.info("Creating pull request", {
297
- taskId,
298
- branchName,
299
- taskTitle,
300
- });
266
+ this.logger.info('Creating pull request', { taskId, branchName, taskTitle });
301
267
  const defaultBody = `## Task Details
302
268
  **Task ID**: ${taskId}
303
269
  **Description**: ${taskDescription}
@@ -308,50 +274,40 @@ This PR implements the changes described in the task.
308
274
  Generated by PostHog Agent`;
309
275
  const prBody = customBody || defaultBody;
310
276
  const prUrl = await this.gitManager.createPullRequest(branchName, taskTitle, prBody);
311
- this.logger.info("Pull request created", { taskId, prUrl });
277
+ this.logger.info('Pull request created', { taskId, prUrl });
312
278
  return prUrl;
313
279
  }
314
280
  async attachPullRequestToTask(taskId, prUrl, branchName) {
315
- this.logger.info("Attaching PR to task run", { taskId, prUrl, branchName });
281
+ this.logger.info('Attaching PR to task run', { taskId, prUrl, branchName });
316
282
  if (!this.posthogAPI || !this.progressReporter.runId) {
317
- const error = new Error("PostHog API not configured or no active run. Cannot attach PR to task.");
318
- this.logger.error("PostHog API not configured", error);
283
+ const error = new Error('PostHog API not configured or no active run. Cannot attach PR to task.');
284
+ this.logger.error('PostHog API not configured', error);
319
285
  throw error;
320
286
  }
321
287
  const updates = {
322
- output: { pr_url: prUrl },
288
+ output: { pr_url: prUrl }
323
289
  };
324
290
  if (branchName) {
325
291
  updates.branch = branchName;
326
292
  }
327
293
  await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, updates);
328
- this.logger.debug("PR attached to task run", {
329
- taskId,
330
- runId: this.progressReporter.runId,
331
- prUrl,
332
- });
294
+ this.logger.debug('PR attached to task run', { taskId, runId: this.progressReporter.runId, prUrl });
333
295
  }
334
296
  async updateTaskBranch(taskId, branchName) {
335
- this.logger.info("Updating task run branch", { taskId, branchName });
297
+ this.logger.info('Updating task run branch', { taskId, branchName });
336
298
  if (!this.posthogAPI || !this.progressReporter.runId) {
337
- const error = new Error("PostHog API not configured or no active run. Cannot update branch.");
338
- this.logger.error("PostHog API not configured", error);
299
+ const error = new Error('PostHog API not configured or no active run. Cannot update branch.');
300
+ this.logger.error('PostHog API not configured', error);
339
301
  throw error;
340
302
  }
341
- await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, {
342
- branch: branchName,
343
- });
344
- this.logger.debug("Task run branch updated", {
345
- taskId,
346
- runId: this.progressReporter.runId,
347
- branchName,
348
- });
303
+ await this.posthogAPI.updateTaskRun(taskId, this.progressReporter.runId, { branch: branchName });
304
+ this.logger.debug('Task run branch updated', { taskId, runId: this.progressReporter.runId, branchName });
349
305
  }
350
306
  // Execution management
351
307
  cancelTask(taskId) {
352
308
  // Find the execution for this task and cancel it
353
- for (const [executionId, execution] of this.taskManager.executionStates) {
354
- if (execution.taskId === taskId && execution.status === "running") {
309
+ for (const [executionId, execution] of this.taskManager['executionStates']) {
310
+ if (execution.taskId === taskId && execution.status === 'running') {
355
311
  this.taskManager.cancelExecution(executionId);
356
312
  break;
357
313
  }
@@ -359,7 +315,7 @@ Generated by PostHog Agent`;
359
315
  }
360
316
  getTaskExecutionStatus(taskId) {
361
317
  // Find the execution for this task
362
- for (const execution of this.taskManager.executionStates.values()) {
318
+ for (const execution of this.taskManager['executionStates'].values()) {
363
319
  if (execution.taskId === taskId) {
364
320
  return execution.status;
365
321
  }
@@ -368,21 +324,17 @@ Generated by PostHog Agent`;
368
324
  }
369
325
  async prepareTaskBranch(taskSlug, isCloudMode) {
370
326
  if (await this.gitManager.hasChanges()) {
371
- throw new Error("Cannot start task with uncommitted changes. Please commit or stash your changes first.");
327
+ throw new Error('Cannot start task with uncommitted changes. Please commit or stash your changes first.');
372
328
  }
373
329
  await this.gitManager.resetToDefaultBranchIfNeeded();
374
330
  const existingBranch = await this.gitManager.getTaskBranch(taskSlug);
375
331
  if (!existingBranch) {
376
332
  const branchName = await this.gitManager.createTaskBranch(taskSlug);
377
- this.emitEvent(this.adapter.createStatusEvent("branch_created", {
378
- branch: branchName,
379
- }));
333
+ this.emitEvent(this.adapter.createStatusEvent('branch_created', { branch: branchName }));
380
334
  await this.gitManager.addAllPostHogFiles();
381
335
  // Only commit if there are changes or we're in cloud mode
382
336
  if (isCloudMode) {
383
- await this.gitManager.commitAndPush(`Initialize task ${taskSlug}`, {
384
- allowEmpty: true,
385
- });
337
+ await this.gitManager.commitAndPush(`Initialize task ${taskSlug}`, { allowEmpty: true });
386
338
  }
387
339
  else {
388
340
  // Check if there are any changes before committing
@@ -393,9 +345,7 @@ Generated by PostHog Agent`;
393
345
  }
394
346
  }
395
347
  else {
396
- this.logger.info("Switching to existing task branch", {
397
- branch: existingBranch,
398
- });
348
+ this.logger.info('Switching to existing task branch', { branch: existingBranch });
399
349
  await this.gitManager.switchToBranch(existingBranch);
400
350
  }
401
351
  }
@@ -411,49 +361,41 @@ Generated by PostHog Agent`;
411
361
  }
412
362
  async ensurePullRequest(task, stepResults) {
413
363
  const latestRun = task.latest_run;
414
- const existingPr = latestRun?.output && typeof latestRun.output === "object"
364
+ const existingPr = latestRun?.output && typeof latestRun.output === 'object'
415
365
  ? latestRun.output.pr_url
416
366
  : null;
417
367
  if (existingPr) {
418
- this.logger.info("PR already exists, skipping creation", {
419
- taskId: task.id,
420
- prUrl: existingPr,
421
- });
368
+ this.logger.info('PR already exists, skipping creation', { taskId: task.id, prUrl: existingPr });
422
369
  return;
423
370
  }
424
- const buildResult = stepResults.build;
371
+ const buildResult = stepResults['build'];
425
372
  if (!buildResult?.commitCreated) {
426
- this.logger.warn("Build step did not produce a commit; skipping PR creation", { taskId: task.id });
373
+ this.logger.warn('Build step did not produce a commit; skipping PR creation', { taskId: task.id });
427
374
  return;
428
375
  }
429
376
  const branchName = await this.gitManager.getCurrentBranch();
430
- const finalizeResult = stepResults.finalize;
377
+ const finalizeResult = stepResults['finalize'];
431
378
  const prBody = finalizeResult?.prBody;
432
- const prUrl = await this.createPullRequest(task.id, branchName, task.title, task.description ?? "", prBody);
433
- this.emitEvent(this.adapter.createStatusEvent("pr_created", { prUrl }));
379
+ const prUrl = await this.createPullRequest(task.id, branchName, task.title, task.description ?? '', prBody);
380
+ this.emitEvent(this.adapter.createStatusEvent('pr_created', { prUrl }));
434
381
  try {
435
382
  await this.attachPullRequestToTask(task.id, prUrl, branchName);
436
- this.logger.info("PR attached to task successfully", {
437
- taskId: task.id,
438
- prUrl,
439
- });
383
+ this.logger.info('PR attached to task successfully', { taskId: task.id, prUrl });
440
384
  }
441
385
  catch (error) {
442
- this.logger.warn("Could not attach PR to task", {
386
+ this.logger.warn('Could not attach PR to task', {
443
387
  error: error instanceof Error ? error.message : String(error),
444
388
  });
445
389
  }
446
390
  }
447
391
  emitEvent(event) {
448
- if (this.debug && event.type !== "token") {
392
+ if (this.debug && event.type !== 'token') {
449
393
  // Log all events except tokens (too verbose)
450
- this.logger.debug("Emitting event", { type: event.type, ts: event.ts });
394
+ this.logger.debug('Emitting event', { type: event.type, ts: event.ts });
451
395
  }
452
396
  const persistPromise = this.progressReporter.recordEvent(event);
453
- if (persistPromise && typeof persistPromise.then === "function") {
454
- persistPromise.catch((error) => this.logger.debug("Failed to persist agent event", {
455
- message: error.message,
456
- }));
397
+ if (persistPromise && typeof persistPromise.then === 'function') {
398
+ persistPromise.catch((error) => this.logger.debug('Failed to persist agent event', { message: error.message }));
457
399
  }
458
400
  this.onEvent?.(event);
459
401
  }