@posthog/agent 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/src/agent-registry.js +4 -2
- package/dist/src/agent-registry.js.map +1 -1
- package/dist/src/agent.js +7 -6
- package/dist/src/agent.js.map +1 -1
- package/dist/src/agents/execution.js +4 -2
- package/dist/src/agents/execution.js.map +1 -1
- package/dist/src/agents/planning.js +4 -2
- package/dist/src/agents/planning.js.map +1 -1
- package/dist/src/event-transformer.js +4 -2
- package/dist/src/event-transformer.js.map +1 -1
- package/dist/src/file-manager.js +17 -14
- package/dist/src/file-manager.js.map +1 -1
- package/dist/src/git-manager.js +5 -2
- package/dist/src/git-manager.js.map +1 -1
- package/dist/src/posthog-api.js +4 -2
- package/dist/src/posthog-api.js.map +1 -1
- package/dist/src/prompt-builder.js +5 -2
- package/dist/src/prompt-builder.js.map +1 -1
- package/dist/src/stage-executor.js +6 -4
- package/dist/src/stage-executor.js.map +1 -1
- package/dist/src/task-manager.js +5 -2
- package/dist/src/task-manager.js.map +1 -1
- package/dist/src/template-manager.d.ts.map +1 -1
- package/dist/src/template-manager.js +16 -6
- package/dist/src/template-manager.js.map +1 -1
- package/dist/src/types.js +4 -2
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/logger.js +5 -3
- package/dist/src/utils/logger.js.map +1 -1
- package/dist/src/utils/mcp.js +4 -2
- package/dist/src/utils/mcp.js.map +1 -1
- package/dist/src/workflow-registry.js +4 -3
- package/dist/src/workflow-registry.js.map +1 -1
- package/dist/templates/plan-template.md +45 -0
- package/package.json +8 -2
- package/src/template-manager.ts +11 -3
- package/dist/example.js +0 -49
- package/dist/example.js.map +0 -1
- package/dist/src/workflow-types.js +0 -2
- package/dist/src/workflow-types.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger } from './utils/logger.js';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
class PromptBuilder {
|
|
3
4
|
getTaskFiles;
|
|
4
5
|
generatePlanTemplate;
|
|
5
6
|
logger;
|
|
@@ -72,4 +73,6 @@ export class PromptBuilder {
|
|
|
72
73
|
return prompt;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
|
|
77
|
+
export { PromptBuilder };
|
|
78
|
+
//# sourceMappingURL=prompt-builder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-builder.js","
|
|
1
|
+
{"version":3,"file":"prompt-builder.js","sources":["../../src/prompt-builder.ts"],"sourcesContent":["import type { Task } from './types.js';\nimport type { TemplateVariables } from './template-manager.js';\nimport { Logger } from './utils/logger.js';\n\nexport interface PromptBuilderDeps {\n getTaskFiles: (taskId: string) => Promise<any[]>;\n generatePlanTemplate: (vars: TemplateVariables) => Promise<string>;\n logger?: Logger;\n}\n\nexport class PromptBuilder {\n private getTaskFiles: PromptBuilderDeps['getTaskFiles'];\n private generatePlanTemplate: PromptBuilderDeps['generatePlanTemplate'];\n private logger: Logger;\n\n constructor(deps: PromptBuilderDeps) {\n this.getTaskFiles = deps.getTaskFiles;\n this.generatePlanTemplate = deps.generatePlanTemplate;\n this.logger = deps.logger || new Logger({ debug: false, prefix: '[PromptBuilder]' });\n }\n\n async buildPlanningPrompt(task: Task): Promise<string> {\n let prompt = '';\n prompt += `## Current Task\\n\\n**Task**: ${task.title}\\n**Description**: ${task.description}`;\n\n if ((task as any).primary_repository) {\n prompt += `\\n**Repository**: ${(task as any).primary_repository}`;\n }\n\n try {\n const taskFiles = await this.getTaskFiles(task.id);\n const contextFiles = taskFiles.filter((f: any) => f.type === 'context' || f.type === 'reference');\n if (contextFiles.length > 0) {\n prompt += `\\n\\n## Supporting Files`;\n for (const file of contextFiles) {\n prompt += `\\n\\n### ${file.name} (${file.type})\\n${file.content}`;\n }\n }\n } catch (error) {\n this.logger.debug('No existing task files found for planning', { taskId: task.id });\n }\n\n const templateVariables = {\n task_id: task.id,\n task_title: task.title,\n task_description: task.description,\n date: new Date().toISOString().split('T')[0],\n repository: ((task as any).primary_repository || '') as string,\n };\n\n const planTemplate = await this.generatePlanTemplate(templateVariables);\n\n prompt += `\\n\\nPlease analyze the codebase and create a detailed implementation plan for this task. Use the following template structure for your plan:\\n\\n${planTemplate}\\n\\nFill in each section with specific, actionable information based on your analysis. Replace all placeholder content with actual details about this task.`;\n\n return prompt;\n }\n\n async buildExecutionPrompt(task: Task): Promise<string> {\n let prompt = '';\n prompt += `## Current Task\\n\\n**Task**: ${task.title}\\n**Description**: ${task.description}`;\n\n if ((task as any).primary_repository) {\n prompt += `\\n**Repository**: ${(task as any).primary_repository}`;\n }\n\n try {\n const taskFiles = await this.getTaskFiles(task.id);\n const hasPlan = taskFiles.some((f: any) => f.type === 'plan');\n if (taskFiles.length > 0) {\n prompt += `\\n\\n## Context and Supporting Information`;\n for (const file of taskFiles) {\n if (file.type === 'plan') {\n prompt += `\\n\\n### Execution Plan\\n${file.content}`;\n } else {\n prompt += `\\n\\n### ${file.name} (${file.type})\\n${file.content}`;\n }\n }\n }\n if (hasPlan) {\n prompt += `\\n\\nPlease implement the changes described in the execution plan above. Follow the plan step-by-step and make the necessary file modifications. You must actually edit files and make changes - do not just analyze or review.`;\n } else {\n prompt += `\\n\\nPlease implement the changes described in the task above. You must actually edit files and make changes - do not just analyze or review.`;\n }\n } catch (error) {\n this.logger.debug('No supporting files found for execution', { taskId: task.id });\n prompt += `\\n\\nPlease implement the changes described in the task above.`;\n }\n return prompt;\n }\n}\n\n\n"],"names":[],"mappings":";;MAUa,aAAa,CAAA;AAChB,IAAA,YAAY;AACZ,IAAA,oBAAoB;AACpB,IAAA,MAAM;AAEd,IAAA,WAAA,CAAY,IAAuB,EAAA;AACjC,QAAA,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY;AACrC,QAAA,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB;QACrD,IAA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AAO,EAAE;oBAClE;gBACF;YACF;YACA,IAAI,OAAO,EAAE;gBACX,MAAM,IAAI,gOAAgO;YAC5O;iBAAO;gBACL,MAAM,IAAI,8IAA8I;YAC1J;QACF;QAAE,OAAO,KAAK,EAAE;AACd,YAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;YACjF,MAAM,IAAI,+DAA+D;QAC3E;AACA,QAAA,OAAO,MAAM;IACf;AACD;;;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
-
import
|
|
2
|
+
import './utils/logger.js';
|
|
3
3
|
import { EventTransformer } from './event-transformer.js';
|
|
4
|
-
import { AgentRegistry } from './agent-registry.js';
|
|
5
4
|
import { PLANNING_SYSTEM_PROMPT } from './agents/planning.js';
|
|
6
5
|
import { EXECUTION_SYSTEM_PROMPT } from './agents/execution.js';
|
|
7
6
|
import { PromptBuilder } from './prompt-builder.js';
|
|
8
7
|
import { POSTHOG_MCP } from './utils/mcp.js';
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
class StageExecutor {
|
|
10
10
|
registry;
|
|
11
11
|
logger;
|
|
12
12
|
eventTransformer;
|
|
@@ -116,4 +116,6 @@ export class StageExecutor {
|
|
|
116
116
|
return { results };
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
|
|
120
|
+
export { StageExecutor };
|
|
121
|
+
//# sourceMappingURL=stage-executor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage-executor.js","
|
|
1
|
+
{"version":3,"file":"stage-executor.js","sources":["../../src/stage-executor.ts"],"sourcesContent":["import { query } from '@anthropic-ai/claude-agent-sdk';\nimport { Logger } from './utils/logger.js';\nimport { EventTransformer } from './event-transformer.js';\nimport { AgentRegistry } from './agent-registry.js';\nimport type { Task } from './types.js';\nimport type { WorkflowStage, WorkflowStageExecutionResult, WorkflowExecutionOptions } from './workflow-types.js';\nimport { PLANNING_SYSTEM_PROMPT } from './agents/planning.js';\nimport { EXECUTION_SYSTEM_PROMPT } from './agents/execution.js';\nimport { PromptBuilder } from './prompt-builder.js';\nimport { POSTHOG_MCP } from './utils/mcp.js';\n\nexport class StageExecutor {\n private registry: AgentRegistry;\n private logger: Logger;\n private eventTransformer: EventTransformer;\n private promptBuilder: PromptBuilder;\n\n constructor(registry: AgentRegistry, logger: Logger, promptBuilder?: PromptBuilder) {\n this.registry = registry;\n this.logger = logger.child('StageExecutor');\n this.eventTransformer = new EventTransformer();\n this.promptBuilder = promptBuilder || new PromptBuilder({\n getTaskFiles: async () => [],\n generatePlanTemplate: async () => '',\n logger,\n });\n }\n\n async execute(task: Task, stage: WorkflowStage, options: WorkflowExecutionOptions): Promise<WorkflowStageExecutionResult> {\n const isManual = stage.is_manual_only === true;\n if (isManual) {\n this.logger.info('Manual stage detected; skipping agent execution', { stage: stage.key });\n return { results: [] };\n }\n\n const inferredAgent = stage.key.toLowerCase().includes('plan') ? 'planning_basic' : 'code_generation';\n const agentName = stage.agent_name || inferredAgent;\n const agent = this.registry.getAgent(agentName);\n if (!agent) {\n throw new Error(`Unknown agent '${agentName}' for stage '${stage.key}'`);\n }\n\n const permissionMode = (options.permissionMode as any) || 'acceptEdits';\n const cwd = options.repositoryPath || process.cwd();\n\n switch (agent.agent_type) {\n case 'planning':\n return this.runPlanning(task, cwd, options, stage.key);\n case 'execution':\n return this.runExecution(task, cwd, permissionMode, options, stage.key);\n case 'review': // TODO: Implement review\n case 'testing': // TODO: Implement testing\n default:\n // throw new Error(`Unsupported agent type: ${agent.agent_type}`);\n console.warn(`Unsupported agent type: ${agent.agent_type}`);\n return { results: [] };\n }\n }\n\n private async runPlanning(task: Task, cwd: string, options: WorkflowExecutionOptions, stageKey: string): Promise<WorkflowStageExecutionResult> {\n const contextPrompt = await this.promptBuilder.buildPlanningPrompt(task);\n let prompt = PLANNING_SYSTEM_PROMPT + '\\n\\n' + contextPrompt;\n\n const stageOverrides = options.stageOverrides?.[stageKey] || options.stageOverrides?.['plan'];\n const mergedOverrides = {\n ...(options.queryOverrides || {}),\n ...(stageOverrides?.queryOverrides || {}),\n } as Record<string, any>;\n\n const baseOptions: Record<string, any> = {\n model: 'claude-sonnet-4-5-20250929',\n cwd,\n permissionMode: 'plan',\n settingSources: ['local'],\n mcpServers: {\n ...POSTHOG_MCP\n }\n };\n\n const response = query({\n prompt,\n options: { ...baseOptions, ...mergedOverrides },\n });\n\n let plan = '';\n for await (const message of response) {\n const transformed = this.eventTransformer.transform(message);\n if (transformed && transformed.type !== 'token') {\n this.logger.debug('Planning event', { type: transformed.type });\n }\n if (message.type === 'assistant' && message.message?.content) {\n for (const c of message.message.content) {\n if (c.type === 'text' && c.text) plan += c.text + '\\n';\n }\n }\n }\n\n return { plan: plan.trim() };\n }\n\n private async runExecution(task: Task, cwd: string, permissionMode: WorkflowExecutionOptions['permissionMode'], options: WorkflowExecutionOptions, stageKey: string): Promise<WorkflowStageExecutionResult> {\n const contextPrompt = await this.promptBuilder.buildExecutionPrompt(task);\n let prompt = EXECUTION_SYSTEM_PROMPT + '\\n\\n' + contextPrompt;\n\n const stageOverrides = options.stageOverrides?.[stageKey];\n const mergedOverrides = {\n ...(options.queryOverrides || {}),\n ...(stageOverrides?.queryOverrides || {}),\n } as Record<string, any>;\n\n const baseOptions: Record<string, any> = {\n model: 'claude-sonnet-4-5-20250929',\n cwd,\n permissionMode,\n settingSources: ['local'],\n mcpServers: {\n ...POSTHOG_MCP\n }\n };\n\n const response = query({\n prompt,\n options: { ...baseOptions, ...mergedOverrides },\n });\n const results: any[] = [];\n for await (const message of response) {\n const transformed = this.eventTransformer.transform(message);\n if (transformed && transformed.type !== 'token') {\n this.logger.debug('Execution event', { type: transformed.type });\n }\n results.push(message);\n }\n return { results };\n }\n}\n\n"],"names":[],"mappings":";;;;;;;;MAWa,aAAa,CAAA;AAChB,IAA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,CAAC,cAAc,IAAI,EAAE,CAAC;AACjC,YAAA,IAAI,cAAc,EAAE,cAAc,IAAI,EAAE,CAAC;SACnB;AAExB,QAAA,MAAM,WAAW,GAAwB;AACvC,YAAA,KAAK,EAAE,4BAA4B;YACnC,GAAG;YACH,cAAc;YACd,cAAc,EAAE,CAAC,OAAO,CAAC;AACzB,YAAA,UAAU,EAAE;AACV,gBAAA,GAAG;AACJ;SACF;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC;YACrB,MAAM;AACN,YAAA,OAAO,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,eAAe,EAAE;AAChD,SAAA,CAAC;QACF,MAAM,OAAO,GAAU,EAAE;AACzB,QAAA,WAAW,MAAM,OAAO,IAAI,QAAQ,EAAE;YACpC,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,OAAO,CAAC;YAC5D,IAAI,WAAW,IAAI,WAAW,CAAC,IAAI,KAAK,OAAO,EAAE;AAC/C,gBAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;YAClE;AACA,YAAA,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;QACvB;QACA,OAAO,EAAE,OAAO,EAAE;IACpB;AACD;;;;"}
|
package/dist/src/task-manager.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomBytes } from 'crypto';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
class TaskManager {
|
|
3
4
|
executionStates = new Map();
|
|
4
5
|
defaultTimeout = 10 * 60 * 1000; // 10 minutes
|
|
5
6
|
generateExecutionId() {
|
|
@@ -116,4 +117,6 @@ export class TaskManager {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
+
|
|
121
|
+
export { TaskManager };
|
|
122
|
+
//# sourceMappingURL=task-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-manager.js","
|
|
1
|
+
{"version":3,"file":"task-manager.js","sources":["../../src/task-manager.ts"],"sourcesContent":["import { randomBytes } from 'crypto';\n\nexport interface TaskExecutionState {\n taskId: string;\n status: 'running' | 'completed' | 'failed' | 'canceled' | 'timeout';\n mode: 'plan_only' | 'plan_and_build' | 'build_only';\n result?: any;\n startedAt: number;\n completedAt?: number;\n abortController?: AbortController;\n}\n\nexport class TaskManager {\n private executionStates = new Map<string, TaskExecutionState>();\n private defaultTimeout = 10 * 60 * 1000; // 10 minutes\n\n generateExecutionId(): string {\n return randomBytes(16).toString('hex');\n }\n\n startExecution(\n taskId: string, \n mode: 'plan_only' | 'plan_and_build' | 'build_only',\n executionId: string = this.generateExecutionId()\n ): TaskExecutionState {\n const executionState: TaskExecutionState = {\n taskId,\n status: 'running',\n mode,\n startedAt: Date.now(),\n abortController: new AbortController(),\n };\n\n this.executionStates.set(executionId, executionState);\n this.scheduleTimeout(executionId);\n \n return executionState;\n }\n\n async waitForCompletion(executionId: string): Promise<any> {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n if (execution.result && execution.status === 'completed') {\n return execution.result;\n }\n\n return new Promise((resolve, reject) => {\n const checkInterval = setInterval(() => {\n const currentExecution = this.executionStates.get(executionId);\n if (!currentExecution) {\n clearInterval(checkInterval);\n reject(new Error(`Execution ${executionId} disappeared`));\n return;\n }\n\n if (currentExecution.status === 'completed' && currentExecution.result) {\n clearInterval(checkInterval);\n resolve(currentExecution.result);\n } else if (\n currentExecution.status === 'failed' || \n currentExecution.status === 'canceled' || \n currentExecution.status === 'timeout'\n ) {\n clearInterval(checkInterval);\n reject(new Error(`Execution ${executionId} ${currentExecution.status}`));\n }\n }, 100);\n });\n }\n\n completeExecution(executionId: string, result: any): void {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n execution.status = 'completed';\n execution.result = result;\n execution.completedAt = Date.now();\n }\n\n failExecution(executionId: string, error: Error): void {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n execution.status = 'failed';\n execution.completedAt = Date.now();\n execution.result = {\n error: error.message,\n status: 'failed',\n };\n }\n\n cancelExecution(executionId: string): void {\n const execution = this.executionStates.get(executionId);\n if (!execution) {\n throw new Error(`Execution ${executionId} not found`);\n }\n\n execution.status = 'canceled';\n execution.completedAt = Date.now();\n execution.abortController?.abort();\n \n if (!execution.result) {\n execution.result = {\n status: 'canceled',\n message: 'Execution was canceled',\n };\n }\n }\n\n getExecution(executionId: string): TaskExecutionState | undefined {\n return this.executionStates.get(executionId);\n }\n\n getAbortSignal(executionId: string): AbortSignal | undefined {\n return this.executionStates.get(executionId)?.abortController?.signal;\n }\n\n getAbortController(executionId: string): AbortController | undefined {\n return this.executionStates.get(executionId)?.abortController;\n }\n\n private scheduleTimeout(executionId: string, timeout: number = this.defaultTimeout): void {\n setTimeout(() => {\n const execution = this.executionStates.get(executionId);\n if (execution && execution.status === 'running') {\n execution.status = 'timeout';\n execution.completedAt = Date.now();\n execution.abortController?.abort();\n \n if (!execution.result) {\n execution.result = {\n status: 'timeout',\n message: 'Execution timed out',\n };\n }\n }\n }, timeout);\n }\n\n cleanup(olderThan: number = 60 * 60 * 1000): void {\n const cutoff = Date.now() - olderThan;\n for (const [executionId, execution] of this.executionStates) {\n if (execution.completedAt && execution.completedAt < cutoff) {\n this.executionStates.delete(executionId);\n }\n }\n }\n}"],"names":[],"mappings":";;MAYa,WAAW,CAAA;AACd,IAAA,eAAe,GAAG,IAAI,GAAG,EAA8B;IACvD,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAExC,mBAAmB,GAAA;QACjB,OAAO,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;IACxC;IAEA,cAAc,CACZ,MAAc,EACd,IAAmD,EACnD,WAAA,GA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M,EAAE;oBACrB,SAAS,CAAC,MAAM,GAAG;AACjB,wBAAA,MAAM,EAAE,SAAS;AACjB,wBAAA,OAAO,EAAE,qBAAqB;qBAC/B;gBACH;YACF;QACF,CAAC,EAAE,OAAO,CAAC;IACb;AAEA,IAAA,OAAO,CAAC,SAAA,GAAoB,EAAE,GAAG,EAAE,GAAG,IAAI,EAAA;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;QACrC,KAAK,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE;YAC3D,IAAI,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,WAAW,GAAG,MAAM,EAAE;AAC3D,gBAAA,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC;YAC1C;QACF;IACF;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-manager.d.ts","sourceRoot":"","sources":["../../src/template-manager.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAS;;
|
|
1
|
+
{"version":3,"file":"template-manager.d.ts","sourceRoot":"","sources":["../../src/template-manager.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAS;;YAgBf,YAAY;IAS1B,OAAO,CAAC,mBAAmB;IAerB,YAAY,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAS3D,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAQvF,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QACrE,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,eAAe,CAAC,EAAE,KAAK,CAAC;YACtB,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC,CAAC;KACJ,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;KAAE,CAAC,CAAC;IA2CxG,qBAAqB,IAAI,MAAM;CAmChC"}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { promises
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, promises } from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
class TemplateManager {
|
|
5
6
|
templatesDir;
|
|
6
7
|
constructor() {
|
|
7
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
8
9
|
const __dirname = dirname(__filename);
|
|
9
|
-
|
|
10
|
+
const candidateDirs = [
|
|
11
|
+
join(__dirname, 'templates'),
|
|
12
|
+
join(__dirname, '..', 'templates'),
|
|
13
|
+
join(__dirname, '..', '..', 'templates'),
|
|
14
|
+
join(__dirname, '..', '..', 'src', 'templates')
|
|
15
|
+
];
|
|
16
|
+
const resolvedDir = candidateDirs.find((dir) => existsSync(dir));
|
|
17
|
+
this.templatesDir = resolvedDir ?? candidateDirs[0];
|
|
10
18
|
}
|
|
11
19
|
async loadTemplate(templateName) {
|
|
12
20
|
try {
|
|
13
21
|
const templatePath = join(this.templatesDir, templateName);
|
|
14
|
-
return await
|
|
22
|
+
return await promises.readFile(templatePath, 'utf8');
|
|
15
23
|
}
|
|
16
24
|
catch (error) {
|
|
17
25
|
throw new Error(`Failed to load template ${templateName}: ${error}`);
|
|
@@ -115,4 +123,6 @@ Customize \`.posthog/.gitignore\` to control which files are committed:
|
|
|
115
123
|
`;
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
|
-
|
|
126
|
+
|
|
127
|
+
export { TemplateManager };
|
|
128
|
+
//# sourceMappingURL=template-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-manager.js","
|
|
1
|
+
{"version":3,"file":"template-manager.js","sources":["../../src/template-manager.ts"],"sourcesContent":["import { promises as fs, existsSync } from 'fs';\nimport { join, dirname } from 'path';\nimport { fileURLToPath } from 'url';\n\nexport interface TemplateVariables {\n task_id: string;\n task_title: string;\n task_description?: string;\n date: string;\n repository?: string;\n [key: string]: string | undefined;\n}\n\nexport class TemplateManager {\n private templatesDir: string;\n\n constructor() {\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n const candidateDirs = [\n join(__dirname, 'templates'),\n join(__dirname, '..', 'templates'),\n join(__dirname, '..', '..', 'templates'),\n join(__dirname, '..', '..', 'src', 'templates')\n ];\n\n const resolvedDir = candidateDirs.find((dir) => existsSync(dir));\n this.templatesDir = resolvedDir ?? candidateDirs[0];\n }\n\n private async loadTemplate(templateName: string): Promise<string> {\n try {\n const templatePath = join(this.templatesDir, templateName);\n return await fs.readFile(templatePath, 'utf8');\n } catch (error) {\n throw new Error(`Failed to load template ${templateName}: ${error}`);\n }\n }\n\n private substituteVariables(template: string, variables: TemplateVariables): string {\n let result = template;\n \n for (const [key, value] of Object.entries(variables)) {\n if (value !== undefined) {\n const placeholder = new RegExp(`{{${key}}}`, 'g');\n result = result.replace(placeholder, value);\n }\n }\n \n result = result.replace(/{{[^}]+}}/g, '[PLACEHOLDER]');\n \n return result;\n }\n\n async generatePlan(variables: TemplateVariables): Promise<string> {\n const template = await this.loadTemplate('plan-template.md');\n return this.substituteVariables(template, {\n ...variables,\n date: variables.date || new Date().toISOString().split('T')[0]\n });\n }\n\n\n async generateCustomFile(templateName: string, variables: TemplateVariables): Promise<string> {\n const template = await this.loadTemplate(templateName);\n return this.substituteVariables(template, {\n ...variables,\n date: variables.date || new Date().toISOString().split('T')[0]\n });\n }\n\n async createTaskStructure(taskId: string, taskTitle: string, options?: {\n includePlan?: boolean;\n additionalFiles?: Array<{\n name: string;\n template?: string;\n content?: string;\n }>;\n }): Promise<Array<{ name: string; content: string; type: 'plan' | 'context' | 'reference' | 'output' }>> {\n const files: Array<{ name: string; content: string; type: 'plan' | 'context' | 'reference' | 'output' }> = [];\n \n const variables: TemplateVariables = {\n task_id: taskId,\n task_title: taskTitle,\n date: new Date().toISOString().split('T')[0]\n };\n\n // Generate plan file if requested\n if (options?.includePlan !== false) {\n const planContent = await this.generatePlan(variables);\n files.push({\n name: 'plan.md',\n content: planContent,\n type: 'plan'\n });\n }\n\n\n if (options?.additionalFiles) {\n for (const file of options.additionalFiles) {\n let content: string;\n \n if (file.template) {\n content = await this.generateCustomFile(file.template, variables);\n } else if (file.content) {\n content = this.substituteVariables(file.content, variables);\n } else {\n content = `# ${file.name}\\n\\nPlaceholder content for ${file.name}`;\n }\n\n files.push({\n name: file.name,\n content,\n type: file.name.includes('context') ? 'context' : 'reference'\n });\n }\n }\n\n return files;\n }\n\n generatePostHogReadme(): string {\n return `# PostHog Task Files\n\nThis directory contains task-related files generated by the PostHog Agent.\n\n## Structure\n\nEach task has its own subdirectory: \\`.posthog/{task-id}/\\`\n\n### Common Files\n\n- **plan.md** - Implementation plan generated during planning phase\n- **Supporting files** - Any additional files added for task context\n- **artifacts/** - Generated files, outputs, and temporary artifacts\n\n### Usage\n\nThese files are:\n- Version controlled alongside your code\n- Used by the PostHog Agent for context\n- Available for review in pull requests\n- Organized by task ID for easy reference\n\n### Gitignore\n\nCustomize \\`.posthog/.gitignore\\` to control which files are committed:\n- Include plans and documentation by default\n- Exclude temporary files and sensitive data\n- Customize based on your team's workflow\n\n---\n\n*Generated by PostHog Agent*\n`;\n }\n}\n"],"names":["fs"],"mappings":";;;;MAaa,eAAe,CAAA;AAClB,IAAA,YAAY;AAEpB,IAAA,WAAA,GAAA;QACE,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AACjD,QAAA,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;AACrC,QAAA,MAAM,aAAa,GAAG;AACpB,YAAA,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC;AAC5B,YAAA,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC;YAClC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC;YACxC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW;SAC/C;AAED,QAAA,MAAM,WAAW,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,aAAa,CAAC,CAAC,CAAC;IACrD;IAEQ,MAAM,YAAY,CAAC,YAAoB,EAAA;AAC7C,QAAA,IAAI;YACF,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC;YAC1D,OAAO,MAAMA,QAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAChD;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AE,IAAI,CAAC,IAAI;oBACf,OAAO;AACP,oBAAA,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG;AACnD,iBAAA,CAAC;YACJ;QACF;AAEA,QAAA,OAAO,KAAK;IACd;IAEA,qBAAqB,GAAA;QACnB,OAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCV;IACC;AACD;;;;"}
|
package/dist/src/types.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Removed legacy ExecutionMode in favor of configurable workflows
|
|
2
|
-
|
|
2
|
+
var PermissionMode;
|
|
3
3
|
(function (PermissionMode) {
|
|
4
4
|
PermissionMode["PLAN"] = "plan";
|
|
5
5
|
PermissionMode["DEFAULT"] = "default";
|
|
6
6
|
PermissionMode["ACCEPT_EDITS"] = "acceptEdits";
|
|
7
7
|
PermissionMode["BYPASS"] = "bypassPermissions";
|
|
8
8
|
})(PermissionMode || (PermissionMode = {}));
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
export { PermissionMode };
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
package/dist/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../src/types.ts"],"sourcesContent":["// PostHog Task model (matches Array's OpenAPI schema)\nexport interface Task {\n id: string;\n title: string;\n description: string;\n origin_product: 'error_tracking' | 'eval_clusters' | 'user_created' | 'support_queue' | 'session_summaries';\n position?: number;\n workflow?: string | null;\n current_stage?: string | null;\n github_integration?: number | null;\n repository_config?: unknown; // JSONField\n repository_list: string;\n primary_repository: string;\n github_branch: string | null;\n github_pr_url: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface SupportingFile {\n name: string;\n content: string;\n type: 'plan' | 'context' | 'reference' | 'output';\n created_at: string;\n}\n\n// Removed legacy ExecutionMode in favor of configurable workflows\n\nexport enum PermissionMode {\n PLAN = \"plan\",\n DEFAULT = \"default\",\n ACCEPT_EDITS = \"acceptEdits\",\n BYPASS = \"bypassPermissions\"\n}\n\nexport interface ExecutionOptions {\n repositoryPath?: string;\n permissionMode?: PermissionMode;\n}\n\n// Base event with timestamp\ninterface BaseEvent {\n ts: number;\n}\n\n// Streaming content events\nexport interface TokenEvent extends BaseEvent {\n type: 'token';\n content: string;\n contentType?: 'text' | 'thinking' | 'tool_input';\n}\n\nexport interface ContentBlockStartEvent extends BaseEvent {\n type: 'content_block_start';\n index: number;\n contentType: 'text' | 'tool_use' | 'thinking';\n toolName?: string;\n toolId?: string;\n}\n\nexport interface ContentBlockStopEvent extends BaseEvent {\n type: 'content_block_stop';\n index: number;\n}\n\n// Tool events\nexport interface ToolCallEvent extends BaseEvent {\n type: 'tool_call';\n toolName: string;\n callId: string;\n args: Record<string, any>;\n}\n\nexport interface ToolResultEvent extends BaseEvent {\n type: 'tool_result';\n toolName: string;\n callId: string;\n result: any;\n}\n\n// Message lifecycle events\nexport interface MessageStartEvent extends BaseEvent {\n type: 'message_start';\n messageId?: string;\n model?: string;\n}\n\nexport interface MessageDeltaEvent extends BaseEvent {\n type: 'message_delta';\n stopReason?: string;\n stopSequence?: string;\n usage?: {\n outputTokens: number;\n };\n}\n\nexport interface MessageStopEvent extends BaseEvent {\n type: 'message_stop';\n}\n\n// User message events\nexport interface UserMessageEvent extends BaseEvent {\n type: 'user_message';\n content: string;\n isSynthetic?: boolean;\n}\n\n// System events\nexport interface StatusEvent extends BaseEvent {\n type: 'status';\n phase: string;\n [key: string]: any;\n}\n\nexport interface InitEvent extends BaseEvent {\n type: 'init';\n model: string;\n tools: string[];\n permissionMode: string;\n cwd: string;\n apiKeySource: string;\n}\n\nexport interface CompactBoundaryEvent extends BaseEvent {\n type: 'compact_boundary';\n trigger: 'manual' | 'auto';\n preTokens: number;\n}\n\n// Result events\nexport interface DoneEvent extends BaseEvent {\n type: 'done';\n durationMs?: number;\n numTurns?: number;\n totalCostUsd?: number;\n usage?: any;\n}\n\nexport interface ErrorEvent extends BaseEvent {\n type: 'error';\n message: string;\n error?: any;\n errorType?: string;\n}\n\n// Legacy events (keeping for backwards compatibility)\nexport interface DiffEvent extends BaseEvent {\n type: 'diff';\n file: string;\n patch: string;\n summary?: string;\n}\n\nexport interface FileWriteEvent extends BaseEvent {\n type: 'file_write';\n path: string;\n bytes: number;\n}\n\nexport interface MetricEvent extends BaseEvent {\n type: 'metric';\n key: string;\n value: number;\n unit?: string;\n}\n\nexport interface ArtifactEvent extends BaseEvent {\n type: 'artifact';\n kind: string;\n content: any;\n}\n\nexport type AgentEvent =\n | TokenEvent\n | ContentBlockStartEvent\n | ContentBlockStopEvent\n | ToolCallEvent\n | ToolResultEvent\n | MessageStartEvent\n | MessageDeltaEvent\n | MessageStopEvent\n | UserMessageEvent\n | StatusEvent\n | InitEvent\n | CompactBoundaryEvent\n | DoneEvent\n | ErrorEvent\n | DiffEvent\n | FileWriteEvent\n | MetricEvent\n | ArtifactEvent;\n\nexport interface ExecutionResult {\n results: any[];\n}\n\nexport interface PlanResult {\n plan: string;\n}\n\nexport interface TaskExecutionResult {\n task: Task;\n plan?: string;\n executionResult?: ExecutionResult;\n // Deprecated: mode removed in workflow-based execution\n}\n\nexport interface AgentConfig {\n workingDirectory?: string;\n onEvent?: (event: AgentEvent) => void;\n \n // PostHog API configuration\n posthogApiUrl?: string;\n posthogApiKey?: string;\n \n // Logging configuration\n debug?: boolean;\n}\n\nexport interface PostHogAPIConfig {\n apiUrl: string;\n apiKey: string;\n}"],"names":[],"mappings":"AA0BA;IAEY;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,cAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,aAA4B;AAC5B,IAAA,cAAA,CAAA,QAAA,CAAA,GAAA,mBAA4B;AAC9B,CAAC,EALW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;;;;"}
|
package/dist/src/utils/logger.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Simple logger utility with configurable debug mode
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
var LogLevel;
|
|
5
5
|
(function (LogLevel) {
|
|
6
6
|
LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
|
|
7
7
|
LogLevel[LogLevel["WARN"] = 1] = "WARN";
|
|
8
8
|
LogLevel[LogLevel["INFO"] = 2] = "INFO";
|
|
9
9
|
LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG";
|
|
10
10
|
})(LogLevel || (LogLevel = {}));
|
|
11
|
-
|
|
11
|
+
class Logger {
|
|
12
12
|
debugEnabled;
|
|
13
13
|
prefix;
|
|
14
14
|
constructor(config = {}) {
|
|
@@ -63,4 +63,6 @@ export class Logger {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
|
|
67
|
+
export { LogLevel, Logger };
|
|
68
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../../src/utils/logger.ts"],"sourcesContent":["/**\n * Simple logger utility with configurable debug mode\n */\nexport enum LogLevel {\n ERROR = 0,\n WARN = 1,\n INFO = 2,\n DEBUG = 3\n}\n\nexport interface LoggerConfig {\n debug?: boolean;\n prefix?: string;\n}\n\nexport class Logger {\n private debugEnabled: boolean;\n private prefix: string;\n\n constructor(config: LoggerConfig = {}) {\n this.debugEnabled = config.debug ?? false;\n this.prefix = config.prefix ?? '[PostHog Agent]';\n }\n\n setDebug(enabled: boolean) {\n this.debugEnabled = enabled;\n }\n\n private formatMessage(level: string, message: string, data?: any): string {\n const timestamp = new Date().toISOString();\n const base = `${timestamp} ${this.prefix} ${level} ${message}`;\n \n if (data !== undefined) {\n return `${base} ${JSON.stringify(data, null, 2)}`;\n }\n \n return base;\n }\n\n error(message: string, error?: Error | any) {\n // Always log errors\n if (error instanceof Error) {\n console.error(this.formatMessage('[ERROR]', message, {\n message: error.message,\n stack: error.stack\n }));\n } else {\n console.error(this.formatMessage('[ERROR]', message, error));\n }\n }\n\n warn(message: string, data?: any) {\n if (this.debugEnabled) {\n console.warn(this.formatMessage('[WARN]', message, data));\n }\n }\n\n info(message: string, data?: any) {\n if (this.debugEnabled) {\n console.log(this.formatMessage('[INFO]', message, data));\n }\n }\n\n debug(message: string, data?: any) {\n if (this.debugEnabled) {\n console.log(this.formatMessage('[DEBUG]', message, data));\n }\n }\n\n /**\n * Create a child logger with additional prefix\n */\n child(childPrefix: string): Logger {\n return new Logger({\n debug: this.debugEnabled,\n prefix: `${this.prefix} [${childPrefix}]`\n });\n }\n}"],"names":[],"mappings":"AAAA;;AAEG;IACS;AAAZ,CAAA,UAAY,QAAQ,EAAA;AAChB,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS;AACT,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,QAAA,CAAA,QAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAQ;AACR,IAAA,QAAA,CAAA,QAAA,CAAA,OAAA,CAAA,GAAA,CAAA,CAAA,GAAA,OAAS;AACb,CAAC,EALW,QAAQ,KAAR,QAAQ,GAAA,EAAA,CAAA,CAAA;MAYP,MAAM,CAAA;AACP,IAAA,YAAY;AACZ,IAAA,MAAM;AAEd,IAAA,WAAA,CAAY,SAAuB,EAAE,EAAA;QACjC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,iBAAiB;IACpD;AAEA,IAAA,QAAQ,CAAC,OAA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CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC5D;IACJ;IAEA,KAAK,CAAC,OAAe,EAAE,IAAU,EAAA;AAC7B,QAAA,IAAI,IAAI,CAAC,YAAY,EAAE;AACnB,YAAA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC7D;IACJ;AAEA;;AAEG;AACH,IAAA,KAAK,CAAC,WAAmB,EAAA;QACrB,OAAO,IAAI,MAAM,CAAC;YACd,KAAK,EAAE,IAAI,CAAC,YAAY;AACxB,YAAA,MAAM,EAAE,CAAA,EAAG,IAAI,CAAC,MAAM,CAAA,EAAA,EAAK,WAAW,CAAA,CAAA;AACzC,SAAA,CAAC;IACN;AACH;;;;"}
|
package/dist/src/utils/mcp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const POSTHOG_MCP = {
|
|
2
2
|
posthog: {
|
|
3
3
|
command: "npx",
|
|
4
4
|
args: [
|
|
@@ -13,4 +13,6 @@ export const POSTHOG_MCP = {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
export { POSTHOG_MCP };
|
|
18
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","
|
|
1
|
+
{"version":3,"file":"mcp.js","sources":["../../../src/utils/mcp.ts"],"sourcesContent":["export const POSTHOG_MCP = {\n posthog: {\n command: \"npx\",\n args: [\n \"-y\",\n \"mcp-remote@latest\",\n \"https://mcp.posthog.com/mcp\",\n \"--header\",\n \"Authorization:${POSTHOG_AUTH_HEADER}\"\n ],\n env: {\n \"POSTHOG_AUTH_HEADER\": `Bearer ${process.env.POSTHOG_API_KEY}`\n }\n }\n};"],"names":[],"mappings":"AAAO,MAAM,WAAW,GAAG;AACvB,IAAA,OAAO,EAAE;AACL,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,IAAI,EAAE;YACF,IAAI;YACJ,mBAAmB;YACnB,6BAA6B;YAC7B,UAAU;YACV;AACH,SAAA;AACD,QAAA,GAAG,EAAE;AACD,YAAA,qBAAqB,EAAE,CAAA,OAAA,EAAU,OAAO,CAAC,GAAG,CAAC,eAAe,CAAA;AAC/D;AACJ;;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export class WorkflowRegistry {
|
|
1
|
+
class WorkflowRegistry {
|
|
3
2
|
workflowsById = new Map();
|
|
4
3
|
apiClient;
|
|
5
4
|
constructor(apiClient, staticDefinitions) {
|
|
@@ -23,4 +22,6 @@ export class WorkflowRegistry {
|
|
|
23
22
|
return Array.from(this.workflowsById.values());
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
export { WorkflowRegistry };
|
|
27
|
+
//# sourceMappingURL=workflow-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-registry.js","
|
|
1
|
+
{"version":3,"file":"workflow-registry.js","sources":["../../src/workflow-registry.ts"],"sourcesContent":["import type { WorkflowDefinition } from './workflow-types.js';\nimport { PostHogAPIClient } from './posthog-api.js';\n\nexport class WorkflowRegistry {\n private workflowsById: Map<string, WorkflowDefinition> = new Map();\n private apiClient?: PostHogAPIClient;\n\n constructor(apiClient?: PostHogAPIClient, staticDefinitions?: WorkflowDefinition[]) {\n this.apiClient = apiClient;\n if (staticDefinitions) {\n for (const w of staticDefinitions) this.workflowsById.set(w.id, w);\n }\n }\n\n async loadWorkflows(): Promise<void> {\n if (this.apiClient) {\n const workflows = await this.apiClient.listWorkflows();\n for (const w of workflows) this.workflowsById.set(w.id, w);\n }\n }\n\n getWorkflow(id: string): WorkflowDefinition | undefined {\n return this.workflowsById.get(id);\n }\n\n listWorkflows(): WorkflowDefinition[] {\n return Array.from(this.workflowsById.values());\n }\n}\n\n"],"names":[],"mappings":"MAGa,gBAAgB,CAAA;AACnB,IAAA,aAAa,GAAoC,IAAI,GAAG,EAAE;AAC1D,IAAA,SAAS;IAEjB,WAAA,CAAY,SAA4B,EAAE,iBAAwC,EAAA;AAChF,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;QAC1B,IAAI,iBAAiB,EAAE;YACrB,KAAK,MAAM,CAAC,IAAI,iBAAiB;gBAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpE;IACF;AAEA,IAAA,MAAM,aAAa,GAAA;AACjB,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YACtD,KAAK,MAAM,CAAC,IAAI,SAAS;gBAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5D;IACF;AAEA,IAAA,WAAW,CAAC,EAAU,EAAA;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC;IACnC;IAEA,aAAa,GAAA;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC;IAChD;AACD;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Implementation Plan: {{task_title}}
|
|
2
|
+
|
|
3
|
+
**Task ID:** {{task_id}}
|
|
4
|
+
**Generated:** {{date}}
|
|
5
|
+
|
|
6
|
+
## Summary
|
|
7
|
+
|
|
8
|
+
Brief description of what will be implemented and the overall approach.
|
|
9
|
+
|
|
10
|
+
## Implementation Steps
|
|
11
|
+
|
|
12
|
+
### 1. Analysis
|
|
13
|
+
- [ ] Identify relevant files and components
|
|
14
|
+
- [ ] Review existing patterns and constraints
|
|
15
|
+
|
|
16
|
+
### 2. Changes Required
|
|
17
|
+
- [ ] Files to create/modify
|
|
18
|
+
- [ ] Dependencies to add/update
|
|
19
|
+
|
|
20
|
+
### 3. Implementation
|
|
21
|
+
- [ ] Core functionality changes
|
|
22
|
+
- [ ] Tests and validation
|
|
23
|
+
- [ ] Documentation updates
|
|
24
|
+
|
|
25
|
+
## File Changes
|
|
26
|
+
|
|
27
|
+
### New Files
|
|
28
|
+
```
|
|
29
|
+
path/to/new/file.ts - Purpose
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Modified Files
|
|
33
|
+
```
|
|
34
|
+
path/to/existing/file.ts - Changes needed
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Considerations
|
|
38
|
+
|
|
39
|
+
- Key architectural decisions
|
|
40
|
+
- Potential risks and mitigation
|
|
41
|
+
- Testing approach
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
*Generated by PostHog Agent*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/agent",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "TypeScript agent framework wrapping Claude Agent SDK with Git-based workflow for PostHog tasks",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,7 +32,13 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@changesets/cli": "^2.27.8",
|
|
35
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
36
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
35
37
|
"@types/bun": "latest",
|
|
38
|
+
"rimraf": "^6.0.1",
|
|
39
|
+
"rollup": "^4.24.0",
|
|
40
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
41
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
36
42
|
"typescript": "^5.5.0"
|
|
37
43
|
},
|
|
38
44
|
"dependencies": {
|
|
@@ -49,7 +55,7 @@
|
|
|
49
55
|
"access": "public"
|
|
50
56
|
},
|
|
51
57
|
"scripts": {
|
|
52
|
-
"build": "tsc --project tsconfig.build.json",
|
|
58
|
+
"build": "rimraf dist && rollup -c && tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
53
59
|
"example": "bun run example-usage.ts",
|
|
54
60
|
"dev": "bun run example-usage.ts",
|
|
55
61
|
"changeset": "changeset",
|
package/src/template-manager.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
1
|
+
import { promises as fs, existsSync } from 'fs';
|
|
2
2
|
import { join, dirname } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
|
|
@@ -17,7 +17,15 @@ export class TemplateManager {
|
|
|
17
17
|
constructor() {
|
|
18
18
|
const __filename = fileURLToPath(import.meta.url);
|
|
19
19
|
const __dirname = dirname(__filename);
|
|
20
|
-
|
|
20
|
+
const candidateDirs = [
|
|
21
|
+
join(__dirname, 'templates'),
|
|
22
|
+
join(__dirname, '..', 'templates'),
|
|
23
|
+
join(__dirname, '..', '..', 'templates'),
|
|
24
|
+
join(__dirname, '..', '..', 'src', 'templates')
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const resolvedDir = candidateDirs.find((dir) => existsSync(dir));
|
|
28
|
+
this.templatesDir = resolvedDir ?? candidateDirs[0];
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
private async loadTemplate(templateName: string): Promise<string> {
|
|
@@ -146,4 +154,4 @@ Customize \`.posthog/.gitignore\` to control which files are committed:
|
|
|
146
154
|
*Generated by PostHog Agent*
|
|
147
155
|
`;
|
|
148
156
|
}
|
|
149
|
-
}
|
|
157
|
+
}
|
package/dist/example.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
import { config } from "dotenv";
|
|
3
|
-
config();
|
|
4
|
-
import { Agent, PermissionMode } from './src/agent.js';
|
|
5
|
-
async function testAgent() {
|
|
6
|
-
const REPO_PATH = process.argv[2] || process.cwd();
|
|
7
|
-
const TASK_ID = process.argv[3];
|
|
8
|
-
if (!process.env.POSTHOG_API_KEY) {
|
|
9
|
-
console.error("❌ POSTHOG_API_KEY required");
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
console.log(`📁 Working in: ${REPO_PATH}`);
|
|
13
|
-
const agent = new Agent({
|
|
14
|
-
workingDirectory: REPO_PATH,
|
|
15
|
-
posthogApiUrl: process.env.POSTHOG_API_URL || "http://localhost:8010",
|
|
16
|
-
posthogApiKey: process.env.POSTHOG_API_KEY,
|
|
17
|
-
onEvent: (event) => {
|
|
18
|
-
console.log(`[${event.type}]`, event);
|
|
19
|
-
},
|
|
20
|
-
debug: true,
|
|
21
|
-
});
|
|
22
|
-
if (TASK_ID) {
|
|
23
|
-
console.log(`🎯 Running task: ${TASK_ID}`);
|
|
24
|
-
try {
|
|
25
|
-
// Example: list and run a workflow
|
|
26
|
-
await agent['workflowRegistry'].loadWorkflows();
|
|
27
|
-
const workflows = agent['workflowRegistry'].listWorkflows();
|
|
28
|
-
if (workflows.length === 0) {
|
|
29
|
-
throw new Error('No workflows available');
|
|
30
|
-
}
|
|
31
|
-
const selectedWorkflow = workflows[0];
|
|
32
|
-
const options = {
|
|
33
|
-
repositoryPath: REPO_PATH,
|
|
34
|
-
permissionMode: PermissionMode.ACCEPT_EDITS,
|
|
35
|
-
autoProgress: true,
|
|
36
|
-
};
|
|
37
|
-
const result = await agent.runWorkflow(TASK_ID, selectedWorkflow.id, options);
|
|
38
|
-
console.log("✅ Done!");
|
|
39
|
-
console.log(`📁 Plan stored in: .posthog/${TASK_ID}/plan.md`);
|
|
40
|
-
}
|
|
41
|
-
finally {
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log("❌ Please provide a task ID");
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
testAgent().catch(console.error);
|
|
49
|
-
//# sourceMappingURL=example.js.map
|
package/dist/example.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"example.js","sourceRoot":"","sources":["../example.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,MAAM,EAAE,CAAC;AAET,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGvD,KAAK,UAAU,SAAS;IACpB,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACnD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEhC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC;QAC/B,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,kBAAkB,SAAS,EAAE,CAAC,CAAC;IAE3C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC;QACpB,gBAAgB,EAAE,SAAS;QAC3B,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,uBAAuB;QACrE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe;QAC1C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACf,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QACD,KAAK,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,IAAI,OAAO,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC;YACD,mCAAmC;YACnC,MAAM,KAAK,CAAC,kBAAkB,CAAC,CAAC,aAAa,EAAE,CAAC;Y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