@posthog/agent 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +6 -0
  2. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  3. package/dist/_virtual/index.js +4 -0
  4. package/dist/_virtual/index.js.map +1 -0
  5. package/dist/node_modules/@ai-sdk/anthropic/dist/index.js +1154 -0
  6. package/dist/node_modules/@ai-sdk/anthropic/dist/index.js.map +1 -0
  7. package/dist/node_modules/@ai-sdk/provider/dist/index.js +296 -0
  8. package/dist/node_modules/@ai-sdk/provider/dist/index.js.map +1 -0
  9. package/dist/node_modules/@ai-sdk/provider-utils/dist/index.js +576 -0
  10. package/dist/node_modules/@ai-sdk/provider-utils/dist/index.js.map +1 -0
  11. package/dist/node_modules/@ai-sdk/ui-utils/dist/index.js +741 -0
  12. package/dist/node_modules/@ai-sdk/ui-utils/dist/index.js.map +1 -0
  13. package/dist/node_modules/@opentelemetry/api/build/esm/api/context.js +112 -0
  14. package/dist/node_modules/@opentelemetry/api/build/esm/api/context.js.map +1 -0
  15. package/dist/node_modules/@opentelemetry/api/build/esm/api/diag.js +123 -0
  16. package/dist/node_modules/@opentelemetry/api/build/esm/api/diag.js.map +1 -0
  17. package/dist/node_modules/@opentelemetry/api/build/esm/api/metrics.js +62 -0
  18. package/dist/node_modules/@opentelemetry/api/build/esm/api/metrics.js.map +1 -0
  19. package/dist/node_modules/@opentelemetry/api/build/esm/api/propagation.js +91 -0
  20. package/dist/node_modules/@opentelemetry/api/build/esm/api/propagation.js.map +1 -0
  21. package/dist/node_modules/@opentelemetry/api/build/esm/api/trace.js +79 -0
  22. package/dist/node_modules/@opentelemetry/api/build/esm/api/trace.js.map +1 -0
  23. package/dist/node_modules/@opentelemetry/api/build/esm/baggage/context-helpers.js +59 -0
  24. package/dist/node_modules/@opentelemetry/api/build/esm/baggage/context-helpers.js.map +1 -0
  25. package/dist/node_modules/@opentelemetry/api/build/esm/baggage/internal/baggage-impl.js +99 -0
  26. package/dist/node_modules/@opentelemetry/api/build/esm/baggage/internal/baggage-impl.js.map +1 -0
  27. package/dist/node_modules/@opentelemetry/api/build/esm/baggage/utils.js +31 -0
  28. package/dist/node_modules/@opentelemetry/api/build/esm/baggage/utils.js.map +1 -0
  29. package/dist/node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js +69 -0
  30. package/dist/node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js.map +1 -0
  31. package/dist/node_modules/@opentelemetry/api/build/esm/context/context.js +54 -0
  32. package/dist/node_modules/@opentelemetry/api/build/esm/context/context.js.map +1 -0
  33. package/dist/node_modules/@opentelemetry/api/build/esm/context-api.js +22 -0
  34. package/dist/node_modules/@opentelemetry/api/build/esm/context-api.js.map +1 -0
  35. package/dist/node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js +104 -0
  36. package/dist/node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js.map +1 -0
  37. package/dist/node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js +44 -0
  38. package/dist/node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js.map +1 -0
  39. package/dist/node_modules/@opentelemetry/api/build/esm/diag/types.js +43 -0
  40. package/dist/node_modules/@opentelemetry/api/build/esm/diag/types.js.map +1 -0
  41. package/dist/node_modules/@opentelemetry/api/build/esm/diag-api.js +27 -0
  42. package/dist/node_modules/@opentelemetry/api/build/esm/diag-api.js.map +1 -0
  43. package/dist/node_modules/@opentelemetry/api/build/esm/internal/global-utils.js +62 -0
  44. package/dist/node_modules/@opentelemetry/api/build/esm/internal/global-utils.js.map +1 -0
  45. package/dist/node_modules/@opentelemetry/api/build/esm/internal/semver.js +121 -0
  46. package/dist/node_modules/@opentelemetry/api/build/esm/internal/semver.js.map +1 -0
  47. package/dist/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js +167 -0
  48. package/dist/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js.map +1 -0
  49. package/dist/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js +33 -0
  50. package/dist/node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js.map +1 -0
  51. package/dist/node_modules/@opentelemetry/api/build/esm/metrics-api.js +22 -0
  52. package/dist/node_modules/@opentelemetry/api/build/esm/metrics-api.js.map +1 -0
  53. package/dist/node_modules/@opentelemetry/api/build/esm/platform/node/globalThis.js +21 -0
  54. package/dist/node_modules/@opentelemetry/api/build/esm/platform/node/globalThis.js.map +1 -0
  55. package/dist/node_modules/@opentelemetry/api/build/esm/propagation/NoopTextMapPropagator.js +35 -0
  56. package/dist/node_modules/@opentelemetry/api/build/esm/propagation/NoopTextMapPropagator.js.map +1 -0
  57. package/dist/node_modules/@opentelemetry/api/build/esm/propagation/TextMapPropagator.js +40 -0
  58. package/dist/node_modules/@opentelemetry/api/build/esm/propagation/TextMapPropagator.js.map +1 -0
  59. package/dist/node_modules/@opentelemetry/api/build/esm/propagation-api.js +22 -0
  60. package/dist/node_modules/@opentelemetry/api/build/esm/propagation-api.js.map +1 -0
  61. package/dist/node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js +70 -0
  62. package/dist/node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js.map +1 -0
  63. package/dist/node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js +78 -0
  64. package/dist/node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js.map +1 -0
  65. package/dist/node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js +34 -0
  66. package/dist/node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js.map +1 -0
  67. package/dist/node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js +55 -0
  68. package/dist/node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js.map +1 -0
  69. package/dist/node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js +56 -0
  70. package/dist/node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js.map +1 -0
  71. package/dist/node_modules/@opentelemetry/api/build/esm/trace/context-utils.js +76 -0
  72. package/dist/node_modules/@opentelemetry/api/build/esm/trace/context-utils.js.map +1 -0
  73. package/dist/node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js +27 -0
  74. package/dist/node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js.map +1 -0
  75. package/dist/node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js +45 -0
  76. package/dist/node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js.map +1 -0
  77. package/dist/node_modules/@opentelemetry/api/build/esm/trace/status.js +22 -0
  78. package/dist/node_modules/@opentelemetry/api/build/esm/trace/status.js.map +1 -0
  79. package/dist/node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js +25 -0
  80. package/dist/node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js.map +1 -0
  81. package/dist/node_modules/@opentelemetry/api/build/esm/trace-api.js +24 -0
  82. package/dist/node_modules/@opentelemetry/api/build/esm/trace-api.js.map +1 -0
  83. package/dist/node_modules/@opentelemetry/api/build/esm/version.js +20 -0
  84. package/dist/node_modules/@opentelemetry/api/build/esm/version.js.map +1 -0
  85. package/dist/node_modules/ai/dist/index.js +2870 -0
  86. package/dist/node_modules/ai/dist/index.js.map +1 -0
  87. package/dist/node_modules/nanoid/non-secure/index.js +13 -0
  88. package/dist/node_modules/nanoid/non-secure/index.js.map +1 -0
  89. package/dist/node_modules/secure-json-parse/index.js +133 -0
  90. package/dist/node_modules/secure-json-parse/index.js.map +1 -0
  91. package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js +37 -0
  92. package/dist/node_modules/zod-to-json-schema/dist/esm/Options.js.map +1 -0
  93. package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js +26 -0
  94. package/dist/node_modules/zod-to-json-schema/dist/esm/Refs.js.map +1 -0
  95. package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +17 -0
  96. package/dist/node_modules/zod-to-json-schema/dist/esm/errorMessages.js.map +1 -0
  97. package/dist/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js +11 -0
  98. package/dist/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js.map +1 -0
  99. package/dist/node_modules/zod-to-json-schema/dist/esm/index.js +8 -0
  100. package/dist/node_modules/zod-to-json-schema/dist/esm/index.js.map +1 -0
  101. package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js +66 -0
  102. package/dist/node_modules/zod-to-json-schema/dist/esm/parseDef.js.map +1 -0
  103. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +21 -0
  104. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/any.js.map +1 -0
  105. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +30 -0
  106. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/array.js.map +1 -0
  107. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +53 -0
  108. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js.map +1 -0
  109. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +8 -0
  110. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js.map +1 -0
  111. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +8 -0
  112. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js.map +1 -0
  113. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +8 -0
  114. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js.map +1 -0
  115. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +50 -0
  116. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/date.js.map +1 -0
  117. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +11 -0
  118. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/default.js.map +1 -0
  119. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +11 -0
  120. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js.map +1 -0
  121. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +9 -0
  122. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js.map +1 -0
  123. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +56 -0
  124. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js.map +1 -0
  125. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +24 -0
  126. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js.map +1 -0
  127. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +30 -0
  128. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/map.js.map +1 -0
  129. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +19 -0
  130. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js.map +1 -0
  131. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +15 -0
  132. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/never.js.map +1 -0
  133. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +13 -0
  134. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/null.js.map +1 -0
  135. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +37 -0
  136. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js.map +1 -0
  137. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +56 -0
  138. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/number.js.map +1 -0
  139. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +76 -0
  140. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/object.js.map +1 -0
  141. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +25 -0
  142. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js.map +1 -0
  143. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +24 -0
  144. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js.map +1 -0
  145. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +8 -0
  146. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js.map +1 -0
  147. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +8 -0
  148. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js.map +1 -0
  149. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +65 -0
  150. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/record.js.map +1 -0
  151. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +24 -0
  152. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/set.js.map +1 -0
  153. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +350 -0
  154. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/string.js.map +1 -0
  155. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +36 -0
  156. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js.map +1 -0
  157. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +10 -0
  158. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js.map +1 -0
  159. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +84 -0
  160. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/union.js.map +1 -0
  161. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +8 -0
  162. package/dist/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js.map +1 -0
  163. package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js +110 -0
  164. package/dist/node_modules/zod-to-json-schema/dist/esm/selectParser.js.map +1 -0
  165. package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +90 -0
  166. package/dist/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js.map +1 -0
  167. package/dist/src/agent.d.ts +3 -0
  168. package/dist/src/agent.d.ts.map +1 -1
  169. package/dist/src/agent.js +93 -291
  170. package/dist/src/agent.js.map +1 -1
  171. package/dist/src/agents/execution.d.ts +1 -1
  172. package/dist/src/agents/execution.d.ts.map +1 -1
  173. package/dist/src/agents/execution.js +28 -43
  174. package/dist/src/agents/execution.js.map +1 -1
  175. package/dist/src/agents/planning.d.ts +1 -1
  176. package/dist/src/agents/planning.d.ts.map +1 -1
  177. package/dist/src/agents/planning.js +60 -67
  178. package/dist/src/agents/planning.js.map +1 -1
  179. package/dist/src/agents/research.d.ts +1 -1
  180. package/dist/src/agents/research.d.ts.map +1 -1
  181. package/dist/src/agents/research.js +68 -91
  182. package/dist/src/agents/research.js.map +1 -1
  183. package/dist/src/prompt-builder.d.ts.map +1 -1
  184. package/dist/src/prompt-builder.js +68 -36
  185. package/dist/src/prompt-builder.js.map +1 -1
  186. package/dist/src/structured-extraction.d.ts +2 -2
  187. package/dist/src/structured-extraction.d.ts.map +1 -1
  188. package/dist/src/structured-extraction.js +51 -110
  189. package/dist/src/structured-extraction.js.map +1 -1
  190. package/dist/src/workflow/config.d.ts +3 -0
  191. package/dist/src/workflow/config.d.ts.map +1 -0
  192. package/dist/src/workflow/config.js +43 -0
  193. package/dist/src/workflow/config.js.map +1 -0
  194. package/dist/src/workflow/steps/build.d.ts +3 -0
  195. package/dist/src/workflow/steps/build.d.ts.map +1 -0
  196. package/dist/src/workflow/steps/build.js +64 -0
  197. package/dist/src/workflow/steps/build.js.map +1 -0
  198. package/dist/src/workflow/steps/plan.d.ts +3 -0
  199. package/dist/src/workflow/steps/plan.d.ts.map +1 -0
  200. package/dist/src/workflow/steps/plan.js +86 -0
  201. package/dist/src/workflow/steps/plan.js.map +1 -0
  202. package/dist/src/workflow/steps/research.d.ts +3 -0
  203. package/dist/src/workflow/steps/research.d.ts.map +1 -0
  204. package/dist/src/workflow/steps/research.js +124 -0
  205. package/dist/src/workflow/steps/research.js.map +1 -0
  206. package/dist/src/workflow/types.d.ts +48 -0
  207. package/dist/src/workflow/types.d.ts.map +1 -0
  208. package/dist/src/workflow/utils.d.ts +12 -0
  209. package/dist/src/workflow/utils.d.ts.map +1 -0
  210. package/dist/src/workflow/utils.js +38 -0
  211. package/dist/src/workflow/utils.js.map +1 -0
  212. package/package.json +5 -2
  213. package/src/agent.ts +112 -321
  214. package/src/agents/execution.ts +28 -43
  215. package/src/agents/planning.ts +60 -67
  216. package/src/agents/research.ts +68 -91
  217. package/src/prompt-builder.ts +71 -37
  218. package/src/structured-extraction.ts +58 -115
  219. package/src/workflow/config.ts +42 -0
  220. package/src/workflow/steps/build.ts +87 -0
  221. package/src/workflow/steps/plan.ts +112 -0
  222. package/src/workflow/steps/research.ts +156 -0
  223. package/src/workflow/types.ts +53 -0
  224. package/src/workflow/utils.ts +50 -0
@@ -1,105 +1,82 @@
1
- const RESEARCH_SYSTEM_PROMPT = `# PostHog AI Coding Agent - Research Mode
2
-
3
- You are a PostHog AI Coding Agent operating in RESEARCH mode.
4
-
5
- ## Your Role
6
-
7
- You are a research agent that explores codebases to understand implementation context and generate clarifying questions for development tasks.
8
-
9
- ## Important Constraints
10
-
11
- - **Read-Only Mode**: You can only read files, search code, and analyze the codebase
12
- - **No Modifications**: You cannot make any changes or edits to code files
13
- - **Research Focus**: Your goal is understanding and asking the right questions
14
-
15
- ## Available Tools
16
-
17
- - File reading and exploration
18
- - Code search and analysis
19
- - Repository structure analysis
20
- - Documentation review
21
- - \`create_plan\` tool for creating your research artifact
22
-
23
- ## Research Process
24
-
25
- When given a task, follow this systematic approach:
26
-
27
- 1. **Codebase Analysis**
28
- - Explore the repository structure
29
- - Identify relevant files and components
30
- - Understand existing patterns and conventions
31
- - Review related code and dependencies
32
- - Look for similar implementations or patterns
33
-
34
- 2. **Decision Point Identification**
35
- - Identify areas where implementation decisions need to be made
36
- - Find multiple viable approaches in the codebase
37
- - Note where user preferences would affect the implementation
38
- - Consider architectural or design pattern choices
39
-
40
- 3. **Question Generation**
41
- - Generate 3-5 clarifying questions
42
- - Each question should offer 2-3 concrete options based on codebase analysis
43
- - Options should reference actual patterns/approaches found in the code
44
- - Always include option c) as "Something else (please specify)" for flexibility
45
- - Focus on high-impact decisions that affect the implementation approach
46
-
47
- ## Output Format
48
-
49
- After completing your research, you MUST use the \`create_plan\` tool to create a research.md artifact with your questions.
50
-
51
- The artifact MUST follow this EXACT markdown format (this is critical for parsing):
1
+ const RESEARCH_SYSTEM_PROMPT = `<role>
2
+ PostHog AI Research Agent — analyze codebases to understand implementation context and identify areas of focus for development tasks.
3
+ </role>
4
+
5
+ <constraints>
6
+ - Read-only: analyze files, search code, explore structure
7
+ - No modifications or code changes
8
+ </constraints>
9
+
10
+ <objective>
11
+ Your PRIMARY goal is to understand the codebase thoroughly and provide context for the planning phase.
12
+
13
+ ONLY generate clarifying questions if:
14
+ - The task description is genuinely vague or ambiguous
15
+ - There are multiple valid architectural approaches with significant tradeoffs
16
+ - Critical information is missing that cannot be inferred from the codebase
17
+
18
+ DO NOT ask questions like "how should I fix this" or "what approach do you prefer" — that defeats the purpose of autonomous task execution. The user has already specified what they want done.
19
+ </objective>
20
+
21
+ <process>
22
+ 1. Explore repository structure and identify relevant files/components
23
+ 2. Understand existing patterns, conventions, and dependencies
24
+ 3. Locate similar implementations or related code
25
+ 4. Identify the key areas of the codebase that will be affected
26
+ 5. Document your findings to provide context for planning
27
+ 6. ONLY if genuinely needed: generate 2-3 specific clarification questions
28
+ </process>
29
+
30
+ <output_format>
31
+ Output ONLY the markdown artifact with no preamble:
52
32
 
53
33
  \`\`\`markdown
54
- # Research Questions
55
-
56
- Based on my analysis of the codebase, here are the key questions to guide implementation:
34
+ # Research Findings
57
35
 
58
- ## Question 1: [Question text - be specific and clear]
36
+ ## Codebase Analysis
37
+ [Brief summary of relevant code structure, patterns, and files]
59
38
 
60
- **Options:**
61
- - a) [Concrete option based on existing pattern - reference specific files/components]
62
- - b) [Alternative approach based on another pattern - reference specific files/components]
63
- - c) Something else (please specify)
39
+ ## Key Areas of Focus
40
+ [List specific files/components that need modification]
64
41
 
65
- ## Question 2: [Next question - be specific and clear]
66
-
67
- **Options:**
68
- - a) [Option with specific code references]
69
- - b) [Alternative with specific code references]
70
- - c) Something else (please specify)
42
+ ## Implementation Context
43
+ [Important patterns, dependencies, or constraints found in the code]
71
44
 
72
- ## Question 3: [Continue with 3-5 questions total]
45
+ ## Clarifying Questions
46
+ [ONLY include this section if it will increase the quality of the plan]
73
47
 
48
+ ## Question 1: [Specific architectural decision]
74
49
  **Options:**
75
- - a) [Option]
76
- - b) [Alternative]
50
+ - a) [Concrete option with file references]
51
+ - b) [Alternative with file references]
77
52
  - c) Something else (please specify)
78
53
  \`\`\`
79
54
 
80
- ## CRITICAL FORMAT REQUIREMENTS
81
-
82
- - Use EXACTLY "## Question N:" format for question headers (h2 level, not h3)
83
- - Each question MUST be followed by "**Options:**" on its own line
84
- - Each option MUST start with "- a)", "- b)", "- c)", etc.
85
- - Always include "c) Something else (please specify)" as the last option
86
- - Do NOT add extra sections between questions
87
- - Keep context and analysis BEFORE the questions section, not mixed in
88
-
89
- ## Important Requirements
90
-
91
- - Generate 2-5 questions (no more, no less)
92
- - Make options specific and reference actual code/patterns you find
93
- - Each question must have at least 2 concrete options plus "Something else"
94
- - Focus on architectural and implementation approach decisions
95
- - Reference specific files, components, or patterns in your options
96
- - Make sure the questions help guide a clear implementation path
97
-
98
- ## Final Step
99
-
100
- Once you have completed your research and identified the questions, use the \`create_plan\` tool to create the research.md artifact with the markdown content above. Do NOT use any other tools after creating the artifact.
101
-
102
- Your research should be thorough enough that the questions help clarify the user's preferences and guide the planning phase effectively.`;
55
+ Format requirements:
56
+ - Use "## Question N:" for question headers (h2)
57
+ - Follow with "**Options:**" on its own line
58
+ - Start options with "- a)", "- b)", "- c)"
59
+ - Always include "c) Something else (please specify)"
60
+ - Max 3 questions total
61
+ </output_format>
62
+
63
+ <examples>
64
+ <good_example>
65
+ Task: "Fix authentication bug in login flow"
66
+ Output: Research findings showing auth flow files, patterns used, NO questions needed
67
+ </good_example>
68
+
69
+ <bad_example>
70
+ Task: "Fix authentication bug"
71
+ Output: "How should I fix the authentication? a) Fix it one way b) Fix it another way"
72
+ Reason: Don't ask HOW to do the task — that's what the agent is for
73
+ </bad_example>
74
+
75
+ <good_example>
76
+ Task: "Add caching to API endpoints"
77
+ Output: Research showing existing cache implementations, question about cache backend choice IF multiple production systems are already in use
78
+ </good_example>
79
+ </examples>`;
103
80
 
104
81
  export { RESEARCH_SYSTEM_PROMPT };
105
82
  //# sourceMappingURL=research.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"research.js","sources":["../../../src/agents/research.ts"],"sourcesContent":["export const RESEARCH_SYSTEM_PROMPT = `# PostHog AI Coding Agent - Research Mode\n\nYou are a PostHog AI Coding Agent operating in RESEARCH mode.\n\n## Your Role\n\nYou are a research agent that explores codebases to understand implementation context and generate clarifying questions for development tasks.\n\n## Important Constraints\n\n- **Read-Only Mode**: You can only read files, search code, and analyze the codebase\n- **No Modifications**: You cannot make any changes or edits to code files\n- **Research Focus**: Your goal is understanding and asking the right questions\n\n## Available Tools\n\n- File reading and exploration\n- Code search and analysis\n- Repository structure analysis\n- Documentation review\n- \\`create_plan\\` tool for creating your research artifact\n\n## Research Process\n\nWhen given a task, follow this systematic approach:\n\n1. **Codebase Analysis**\n - Explore the repository structure\n - Identify relevant files and components\n - Understand existing patterns and conventions\n - Review related code and dependencies\n - Look for similar implementations or patterns\n\n2. **Decision Point Identification**\n - Identify areas where implementation decisions need to be made\n - Find multiple viable approaches in the codebase\n - Note where user preferences would affect the implementation\n - Consider architectural or design pattern choices\n\n3. **Question Generation**\n - Generate 3-5 clarifying questions\n - Each question should offer 2-3 concrete options based on codebase analysis\n - Options should reference actual patterns/approaches found in the code\n - Always include option c) as \"Something else (please specify)\" for flexibility\n - Focus on high-impact decisions that affect the implementation approach\n\n## Output Format\n\nAfter completing your research, you MUST use the \\`create_plan\\` tool to create a research.md artifact with your questions.\n\nThe artifact MUST follow this EXACT markdown format (this is critical for parsing):\n\n\\`\\`\\`markdown\n# Research Questions\n\nBased on my analysis of the codebase, here are the key questions to guide implementation:\n\n## Question 1: [Question text - be specific and clear]\n\n**Options:**\n- a) [Concrete option based on existing pattern - reference specific files/components]\n- b) [Alternative approach based on another pattern - reference specific files/components] \n- c) Something else (please specify)\n\n## Question 2: [Next question - be specific and clear]\n\n**Options:**\n- a) [Option with specific code references]\n- b) [Alternative with specific code references]\n- c) Something else (please specify)\n\n## Question 3: [Continue with 3-5 questions total]\n\n**Options:**\n- a) [Option]\n- b) [Alternative]\n- c) Something else (please specify)\n\\`\\`\\`\n\n## CRITICAL FORMAT REQUIREMENTS\n\n- Use EXACTLY \"## Question N:\" format for question headers (h2 level, not h3)\n- Each question MUST be followed by \"**Options:**\" on its own line\n- Each option MUST start with \"- a)\", \"- b)\", \"- c)\", etc.\n- Always include \"c) Something else (please specify)\" as the last option\n- Do NOT add extra sections between questions\n- Keep context and analysis BEFORE the questions section, not mixed in\n\n## Important Requirements\n\n- Generate 2-5 questions (no more, no less)\n- Make options specific and reference actual code/patterns you find\n- Each question must have at least 2 concrete options plus \"Something else\"\n- Focus on architectural and implementation approach decisions\n- Reference specific files, components, or patterns in your options\n- Make sure the questions help guide a clear implementation path\n\n## Final Step\n\nOnce you have completed your research and identified the questions, use the \\`create_plan\\` tool to create the research.md artifact with the markdown content above. Do NOT use any other tools after creating the artifact.\n\nYour research should be thorough enough that the questions help clarify the user's preferences and guide the planning phase effectively.`;\n\n"],"names":[],"mappings":"AAAO,MAAM,sBAAsB,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"research.js","sources":["../../../src/agents/research.ts"],"sourcesContent":["export const RESEARCH_SYSTEM_PROMPT = `<role>\nPostHog AI Research Agent analyze codebases to understand implementation context and identify areas of focus for development tasks.\n</role>\n\n<constraints>\n- Read-only: analyze files, search code, explore structure\n- No modifications or code changes\n</constraints>\n\n<objective>\nYour PRIMARY goal is to understand the codebase thoroughly and provide context for the planning phase.\n\nONLY generate clarifying questions if:\n- The task description is genuinely vague or ambiguous\n- There are multiple valid architectural approaches with significant tradeoffs\n- Critical information is missing that cannot be inferred from the codebase\n\nDO NOT ask questions like \"how should I fix this\" or \"what approach do you prefer\" that defeats the purpose of autonomous task execution. The user has already specified what they want done.\n</objective>\n\n<process>\n1. Explore repository structure and identify relevant files/components\n2. Understand existing patterns, conventions, and dependencies\n3. Locate similar implementations or related code\n4. Identify the key areas of the codebase that will be affected\n5. Document your findings to provide context for planning\n6. ONLY if genuinely needed: generate 2-3 specific clarification questions\n</process>\n\n<output_format>\nOutput ONLY the markdown artifact with no preamble:\n\n\\`\\`\\`markdown\n# Research Findings\n\n## Codebase Analysis\n[Brief summary of relevant code structure, patterns, and files]\n\n## Key Areas of Focus\n[List specific files/components that need modification]\n\n## Implementation Context\n[Important patterns, dependencies, or constraints found in the code]\n\n## Clarifying Questions\n[ONLY include this section if it will increase the quality of the plan]\n\n## Question 1: [Specific architectural decision]\n**Options:**\n- a) [Concrete option with file references]\n- b) [Alternative with file references]\n- c) Something else (please specify)\n\\`\\`\\`\n\nFormat requirements:\n- Use \"## Question N:\" for question headers (h2)\n- Follow with \"**Options:**\" on its own line\n- Start options with \"- a)\", \"- b)\", \"- c)\"\n- Always include \"c) Something else (please specify)\"\n- Max 3 questions total\n</output_format>\n\n<examples>\n<good_example>\nTask: \"Fix authentication bug in login flow\"\nOutput: Research findings showing auth flow files, patterns used, NO questions needed\n</good_example>\n\n<bad_example>\nTask: \"Fix authentication bug\"\nOutput: \"How should I fix the authentication? a) Fix it one way b) Fix it another way\"\nReason: Don't ask HOW to do the task that's what the agent is for\n</bad_example>\n\n<good_example>\nTask: \"Add caching to API endpoints\"\nOutput: Research showing existing cache implementations, question about cache backend choice IF multiple production systems are already in use\n</good_example>\n</examples>`;\n\n"],"names":[],"mappings":"AAAO,MAAM,sBAAsB,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-builder.d.ts","sourceRoot":"","sources":["../../src/prompt-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAI3C,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,oBAAoB,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACnE,aAAa,CAAC,EAAE;QAAE,kBAAkB,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,eAAe,CAAC,CAAA;KAAE,CAAC;IAC1F,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,YAAY,CAAoC;IACxD,OAAO,CAAC,oBAAoB,CAA4C;IACxE,OAAO,CAAC,aAAa,CAAC,CAAqC;IAC3D,OAAO,CAAC,MAAM,CAAS;gBAEX,IAAI,EAAE,iBAAiB;IAOnC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAYxB;;OAEG;YACW,eAAe;IAW7B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA+B1B;;OAEG;IACH,OAAO,CAAC,gB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EG;YACW,eAAe;IAW7B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA+B1B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;OAEG;YACW,oBAAoB;IAqDlC;;;OAGG;YACW,qBAAqB;IAgC7B,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2DzE,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4EzE,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA0EjF"}
@@ -168,75 +168,90 @@ class PromptBuilder {
168
168
  async buildResearchPrompt(task, repositoryPath) {
169
169
  // Process file references in description
170
170
  const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(task.description, repositoryPath);
171
- // Process URL references in description
171
+ // Process URL references in description
172
172
  const { description: processedDescription, referencedResources } = await this.processUrlReferences(descriptionAfterFiles);
173
- let prompt = '';
174
- prompt += `## Current Task\n\n**Task**: ${task.title}\n**Description**: ${processedDescription}`;
173
+ let prompt = '<task>\n';
174
+ prompt += `<title>${task.title}</title>\n`;
175
+ prompt += `<description>${processedDescription}</description>\n`;
175
176
  if (task.primary_repository) {
176
- prompt += `\n**Repository**: ${task.primary_repository}`;
177
+ prompt += `<repository>${task.primary_repository}</repository>\n`;
177
178
  }
179
+ prompt += '</task>\n';
178
180
  // Add referenced files from @ mentions
179
181
  if (referencedFiles.length > 0) {
180
- prompt += `\n\n## Referenced Files\n\n`;
182
+ prompt += '\n<referenced_files>\n';
181
183
  for (const file of referencedFiles) {
182
- prompt += `### ${file.path}\n\`\`\`\n${file.content}\n\`\`\`\n\n`;
184
+ prompt += `<file path="${file.path}">\n\`\`\`\n${file.content}\n\`\`\`\n</file>\n`;
183
185
  }
186
+ prompt += '</referenced_files>\n';
184
187
  }
185
188
  // Add referenced resources from URL mentions
186
189
  if (referencedResources.length > 0) {
187
- prompt += `\n\n## Referenced Resources\n\n`;
190
+ prompt += '\n<referenced_resources>\n';
188
191
  for (const resource of referencedResources) {
189
- prompt += `### ${resource.title} (${resource.type})\n**URL**: ${resource.url}\n\n${resource.content}\n\n`;
192
+ prompt += `<resource type="${resource.type}" url="${resource.url}">\n`;
193
+ prompt += `<title>${resource.title}</title>\n`;
194
+ prompt += `<content>${resource.content}</content>\n`;
195
+ prompt += '</resource>\n';
190
196
  }
197
+ prompt += '</referenced_resources>\n';
191
198
  }
192
199
  try {
193
200
  const taskFiles = await this.getTaskFiles(task.id);
194
201
  const contextFiles = taskFiles.filter((f) => f.type === 'context' || f.type === 'reference');
195
202
  if (contextFiles.length > 0) {
196
- prompt += `\n\n## Supporting Files`;
203
+ prompt += '\n<supporting_files>\n';
197
204
  for (const file of contextFiles) {
198
- prompt += `\n\n### ${file.name} (${file.type})\n${file.content}`;
205
+ prompt += `<file name="${file.name}" type="${file.type}">\n${file.content}\n</file>\n`;
199
206
  }
207
+ prompt += '</supporting_files>\n';
200
208
  }
201
209
  }
202
210
  catch (error) {
203
211
  this.logger.debug('No existing task files found for research', { taskId: task.id });
204
212
  }
205
- prompt += `\n\nPlease explore the codebase thoroughly and generate 3-5 clarifying questions that will help guide the implementation of this task. Use the \`create_plan\` tool to create a research.md artifact with your questions in the markdown format specified in your system prompt.`;
206
213
  return prompt;
207
214
  }
208
215
  async buildPlanningPrompt(task, repositoryPath) {
209
216
  // Process file references in description
210
217
  const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(task.description, repositoryPath);
211
- // Process URL references in description
218
+ // Process URL references in description
212
219
  const { description: processedDescription, referencedResources } = await this.processUrlReferences(descriptionAfterFiles);
213
- let prompt = '';
214
- prompt += `## Current Task\n\n**Task**: ${task.title}\n**Description**: ${processedDescription}`;
220
+ let prompt = '<task>\n';
221
+ prompt += `<title>${task.title}</title>\n`;
222
+ prompt += `<description>${processedDescription}</description>\n`;
215
223
  if (task.primary_repository) {
216
- prompt += `\n**Repository**: ${task.primary_repository}`;
224
+ prompt += `<repository>${task.primary_repository}</repository>\n`;
217
225
  }
226
+ prompt += '</task>\n';
218
227
  // Add referenced files from @ mentions
219
228
  if (referencedFiles.length > 0) {
220
- prompt += `\n\n## Referenced Files\n\n`;
229
+ prompt += '\n<referenced_files>\n';
221
230
  for (const file of referencedFiles) {
222
- prompt += `### ${file.path}\n\`\`\`\n${file.content}\n\`\`\`\n\n`;
231
+ prompt += `<file path="${file.path}">\n\`\`\`\n${file.content}\n\`\`\`\n</file>\n`;
223
232
  }
233
+ prompt += '</referenced_files>\n';
224
234
  }
225
235
  // Add referenced resources from URL mentions
226
236
  if (referencedResources.length > 0) {
227
- prompt += `\n\n## Referenced Resources\n\n`;
237
+ prompt += '\n<referenced_resources>\n';
228
238
  for (const resource of referencedResources) {
229
- prompt += `### ${resource.title} (${resource.type})\n**URL**: ${resource.url}\n\n${resource.content}\n\n`;
239
+ prompt += `<resource type="${resource.type}" url="${resource.url}">\n`;
240
+ prompt += `<title>${resource.title}</title>\n`;
241
+ prompt += `<content>${resource.content}</content>\n`;
242
+ prompt += '</resource>\n';
230
243
  }
244
+ prompt += '</referenced_resources>\n';
231
245
  }
232
246
  try {
233
247
  const taskFiles = await this.getTaskFiles(task.id);
234
248
  const contextFiles = taskFiles.filter((f) => f.type === 'context' || f.type === 'reference');
235
249
  if (contextFiles.length > 0) {
236
- prompt += `\n\n## Supporting Files`;
250
+ prompt += '\n<supporting_files>\n';
237
251
  for (const file of contextFiles) {
238
- prompt += `\n\n### ${file.name} (${file.type})\n${file.content}`;
252
+ prompt += `<file name="${file.name}" type="${file.type}">\n${file.content}\n</file>\n`;
239
253
  }
254
+ prompt += '</supporting_files>\n';
240
255
  }
241
256
  }
242
257
  catch (error) {
@@ -250,57 +265,74 @@ class PromptBuilder {
250
265
  repository: (task.primary_repository || ''),
251
266
  };
252
267
  const planTemplate = await this.generatePlanTemplate(templateVariables);
253
- 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.`;
268
+ prompt += '\n<instructions>\n';
269
+ prompt += 'Analyze the codebase and create a detailed implementation plan. Use the template structure below, filling each section with specific, actionable information.\n';
270
+ prompt += '</instructions>\n\n';
271
+ prompt += '<plan_template>\n';
272
+ prompt += planTemplate;
273
+ prompt += '\n</plan_template>';
254
274
  return prompt;
255
275
  }
256
276
  async buildExecutionPrompt(task, repositoryPath) {
257
277
  // Process file references in description
258
278
  const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(task.description, repositoryPath);
259
- // Process URL references in description
279
+ // Process URL references in description
260
280
  const { description: processedDescription, referencedResources } = await this.processUrlReferences(descriptionAfterFiles);
261
- let prompt = '';
262
- prompt += `## Current Task\n\n**Task**: ${task.title}\n**Description**: ${processedDescription}`;
281
+ let prompt = '<task>\n';
282
+ prompt += `<title>${task.title}</title>\n`;
283
+ prompt += `<description>${processedDescription}</description>\n`;
263
284
  if (task.primary_repository) {
264
- prompt += `\n**Repository**: ${task.primary_repository}`;
285
+ prompt += `<repository>${task.primary_repository}</repository>\n`;
265
286
  }
287
+ prompt += '</task>\n';
266
288
  // Add referenced files from @ mentions
267
289
  if (referencedFiles.length > 0) {
268
- prompt += `\n\n## Referenced Files\n\n`;
290
+ prompt += '\n<referenced_files>\n';
269
291
  for (const file of referencedFiles) {
270
- prompt += `### ${file.path}\n\`\`\`\n${file.content}\n\`\`\`\n\n`;
292
+ prompt += `<file path="${file.path}">\n\`\`\`\n${file.content}\n\`\`\`\n</file>\n`;
271
293
  }
294
+ prompt += '</referenced_files>\n';
272
295
  }
273
296
  // Add referenced resources from URL mentions
274
297
  if (referencedResources.length > 0) {
275
- prompt += `\n\n## Referenced Resources\n\n`;
298
+ prompt += '\n<referenced_resources>\n';
276
299
  for (const resource of referencedResources) {
277
- prompt += `### ${resource.title} (${resource.type})\n**URL**: ${resource.url}\n\n${resource.content}\n\n`;
300
+ prompt += `<resource type="${resource.type}" url="${resource.url}">\n`;
301
+ prompt += `<title>${resource.title}</title>\n`;
302
+ prompt += `<content>${resource.content}</content>\n`;
303
+ prompt += '</resource>\n';
278
304
  }
305
+ prompt += '</referenced_resources>\n';
279
306
  }
280
307
  try {
281
308
  const taskFiles = await this.getTaskFiles(task.id);
282
309
  const hasPlan = taskFiles.some((f) => f.type === 'plan');
283
310
  if (taskFiles.length > 0) {
284
- prompt += `\n\n## Context and Supporting Information`;
311
+ prompt += '\n<context>\n';
285
312
  for (const file of taskFiles) {
286
313
  if (file.type === 'plan') {
287
- prompt += `\n\n### Execution Plan\n${file.content}`;
314
+ prompt += `<plan>\n${file.content}\n</plan>\n`;
288
315
  }
289
316
  else {
290
- prompt += `\n\n### ${file.name} (${file.type})\n${file.content}`;
317
+ prompt += `<file name="${file.name}" type="${file.type}">\n${file.content}\n</file>\n`;
291
318
  }
292
319
  }
320
+ prompt += '</context>\n';
293
321
  }
322
+ prompt += '\n<instructions>\n';
294
323
  if (hasPlan) {
295
- 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.`;
324
+ prompt += 'Implement the changes described in the execution plan. Follow the plan step-by-step and make the necessary file modifications.\n';
296
325
  }
297
326
  else {
298
- 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.`;
327
+ prompt += 'Implement the changes described in the task. Make the necessary file modifications to complete the task.\n';
299
328
  }
329
+ prompt += '</instructions>';
300
330
  }
301
331
  catch (error) {
302
332
  this.logger.debug('No supporting files found for execution', { taskId: task.id });
303
- prompt += `\n\nPlease implement the changes described in the task above.`;
333
+ prompt += '\n<instructions>\n';
334
+ prompt += 'Implement the changes described in the task.\n';
335
+ prompt += '</instructions>';
304
336
  }
305
337
  return prompt;
306
338
  }
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-builder.js","sources":["../../src/prompt-builder.ts"],"sourcesContent":["import type { Task, UrlMention, PostHogResource } from './types.js';\nimport type { TemplateVariables } from './template-manager.js';\nimport { Logger } from './utils/logger.js';\nimport { promises as fs } from 'fs';\nimport { join } from 'path';\n\nexport interface PromptBuilderDeps {\n getTaskFiles: (taskId: string) => Promise<any[]>;\n generatePlanTemplate: (vars: TemplateVariables) => Promise<string>;\n posthogClient?: { fetchResourceByUrl: (mention: UrlMention) => Promise<PostHogResource> };\n logger?: Logger;\n}\n\nexport class PromptBuilder {\n private getTaskFiles: PromptBuilderDeps['getTaskFiles'];\n private generatePlanTemplate: PromptBuilderDeps['generatePlanTemplate'];\n private posthogClient?: PromptBuilderDeps['posthogClient'];\n private logger: Logger;\n\n constructor(deps: PromptBuilderDeps) {\n this.getTaskFiles = deps.getTaskFiles;\n this.generatePlanTemplate = deps.generatePlanTemplate;\n this.posthogClient = deps.posthogClient;\n this.logger = deps.logger || new Logger({ debug: false, prefix: '[PromptBuilder]' });\n }\n\n /**\n * Extract file paths from XML tags in description\n * Format: <file path=\"relative/path.ts\" />\n */\n private extractFilePaths(description: string): string[] {\n const fileTagRegex = /<file\\s+path=\"([^\"]+)\"\\s*\\/>/g;\n const paths: string[] = [];\n let match: RegExpExecArray | null;\n\n while ((match = fileTagRegex.exec(description)) !== null) {\n paths.push(match[1]);\n }\n\n return paths;\n }\n\n /**\n * Read file contents from repository\n */\n private async readFileContent(repositoryPath: string, filePath: string): Promise<string | null> {\n try {\n const fullPath = join(repositoryPath, filePath);\n const content = await fs.readFile(fullPath, 'utf8');\n return content;\n } catch (error) {\n this.logger.warn(`Failed to read referenced file: ${filePath}`, { error });\n return null;\n }\n }\n\n /**\n * Extract URL mentions from XML tags in description\n * Formats: <error id=\"...\" />, <experiment id=\"...\" />, <url href=\"...\" />\n */\n private extractUrlMentions(description: string): UrlMention[] {\n const mentions: UrlMention[] = [];\n \n // PostHog resource mentions: <error id=\"...\" />, <experiment id=\"...\" />, etc.\n const resourceRegex = /<(error|experiment|insight|feature_flag)\\s+id=\"([^\"]+)\"\\s*\\/>/g;\n let match: RegExpExecArray | null;\n\n while ((match = resourceRegex.exec(description)) !== null) {\n const [, type, id] = match;\n mentions.push({\n url: '', // Will be reconstructed if needed\n type: type as any,\n id,\n label: this.generateUrlLabel('', type as any),\n });\n }\n\n // Generic URL mentions: <url href=\"...\" />\n const urlRegex = /<url\\s+href=\"([^\"]+)\"\\s*\\/>/g;\n while ((match = urlRegex.exec(description)) !== null) {\n const [, url] = match;\n mentions.push({\n url,\n type: 'generic',\n label: this.generateUrlLabel(url, 'generic'),\n });\n }\n\n return mentions;\n }\n\n /**\n * Generate a display label for a URL mention\n */\n private generateUrlLabel(url: string, type: string): string {\n try {\n const urlObj = new URL(url);\n switch (type) {\n case 'error':\n const errorMatch = url.match(/error_tracking\\/([a-f0-9-]+)/);\n return errorMatch ? `Error ${errorMatch[1].slice(0, 8)}...` : 'Error';\n case 'experiment':\n const expMatch = url.match(/experiments\\/(\\d+)/);\n return expMatch ? `Experiment #${expMatch[1]}` : 'Experiment';\n case 'insight':\n return 'Insight';\n case 'feature_flag':\n return 'Feature Flag';\n default:\n return urlObj.hostname;\n }\n } catch {\n return 'URL';\n }\n }\n\n /**\n * Process URL references and fetch their content\n */\n private async processUrlReferences(\n description: string\n ): Promise<{ description: string; referencedResources: PostHogResource[] }> {\n const urlMentions = this.extractUrlMentions(description);\n const referencedResources: PostHogResource[] = [];\n\n if (urlMentions.length === 0 || !this.posthogClient) {\n return { description, referencedResources };\n }\n\n // Fetch all referenced resources\n for (const mention of urlMentions) {\n try {\n const resource = await this.posthogClient.fetchResourceByUrl(mention);\n referencedResources.push(resource);\n } catch (error) {\n this.logger.warn(`Failed to fetch resource from URL: ${mention.url}`, { error });\n // Add a placeholder resource for failed fetches\n referencedResources.push({\n type: mention.type,\n id: mention.id || '',\n url: mention.url,\n title: mention.label || 'Unknown Resource',\n content: `Failed to fetch resource from ${mention.url}: ${error}`,\n metadata: {},\n });\n }\n }\n\n // Replace URL tags with just the label for readability\n let processedDescription = description;\n for (const mention of urlMentions) {\n if (mention.type === 'generic') {\n // Generic URLs: <url href=\"...\" />\n const escapedUrl = mention.url.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n processedDescription = processedDescription.replace(\n new RegExp(`<url\\\\s+href=\"${escapedUrl}\"\\\\s*/>`, 'g'),\n `@${mention.label}`\n );\n } else {\n // PostHog resources: <error id=\"...\" />, <experiment id=\"...\" />, etc.\n const escapedType = mention.type.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const escapedId = mention.id ? mention.id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') : '';\n processedDescription = processedDescription.replace(\n new RegExp(`<${escapedType}\\\\s+id=\"${escapedId}\"\\\\s*/>`, 'g'),\n `@${mention.label}`\n );\n }\n }\n\n return { description: processedDescription, referencedResources };\n }\n\n /**\n * Process description to extract file tags and read contents\n * Returns processed description and referenced file contents\n */\n private async processFileReferences(\n description: string,\n repositoryPath?: string\n ): Promise<{ description: string; referencedFiles: Array<{ path: string; content: string }> }> {\n const filePaths = this.extractFilePaths(description);\n const referencedFiles: Array<{ path: string; content: string }> = [];\n\n if (filePaths.length === 0 || !repositoryPath) {\n return { description, referencedFiles };\n }\n\n // Read all referenced files\n for (const filePath of filePaths) {\n const content = await this.readFileContent(repositoryPath, filePath);\n if (content !== null) {\n referencedFiles.push({ path: filePath, content });\n }\n }\n\n // Replace file tags with just the filename for readability\n let processedDescription = description;\n for (const filePath of filePaths) {\n const fileName = filePath.split('/').pop() || filePath;\n processedDescription = processedDescription.replace(\n new RegExp(`<file\\\\s+path=\"${filePath.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\"\\\\s*/>`, 'g'),\n `@${fileName}`\n );\n }\n\n return { description: processedDescription, referencedFiles };\n }\n\n async buildResearchPrompt(task: Task, repositoryPath?: string): Promise<string> {\n // Process file references in description\n const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(\n task.description,\n repositoryPath\n );\n\n // Process URL references in description \n const { description: processedDescription, referencedResources } = await this.processUrlReferences(\n descriptionAfterFiles\n );\n\n let prompt = '';\n prompt += `## Current Task\\n\\n**Task**: ${task.title}\\n**Description**: ${processedDescription}`;\n\n if ((task as any).primary_repository) {\n prompt += `\\n**Repository**: ${(task as any).primary_repository}`;\n }\n\n // Add referenced files from @ mentions\n if (referencedFiles.length > 0) {\n prompt += `\\n\\n## Referenced Files\\n\\n`;\n for (const file of referencedFiles) {\n prompt += `### ${file.path}\\n\\`\\`\\`\\n${file.content}\\n\\`\\`\\`\\n\\n`;\n }\n }\n\n // Add referenced resources from URL mentions\n if (referencedResources.length > 0) {\n prompt += `\\n\\n## Referenced Resources\\n\\n`;\n for (const resource of referencedResources) {\n prompt += `### ${resource.title} (${resource.type})\\n**URL**: ${resource.url}\\n\\n${resource.content}\\n\\n`;\n }\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 research', { taskId: task.id });\n }\n\n prompt += `\\n\\nPlease explore the codebase thoroughly and generate 3-5 clarifying questions that will help guide the implementation of this task. Use the \\`create_plan\\` tool to create a research.md artifact with your questions in the markdown format specified in your system prompt.`;\n\n return prompt;\n }\n\n async buildPlanningPrompt(task: Task, repositoryPath?: string): Promise<string> {\n // Process file references in description\n const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(\n task.description,\n repositoryPath\n );\n\n // Process URL references in description \n const { description: processedDescription, referencedResources } = await this.processUrlReferences(\n descriptionAfterFiles\n );\n\n let prompt = '';\n prompt += `## Current Task\\n\\n**Task**: ${task.title}\\n**Description**: ${processedDescription}`;\n\n if ((task as any).primary_repository) {\n prompt += `\\n**Repository**: ${(task as any).primary_repository}`;\n }\n\n // Add referenced files from @ mentions\n if (referencedFiles.length > 0) {\n prompt += `\\n\\n## Referenced Files\\n\\n`;\n for (const file of referencedFiles) {\n prompt += `### ${file.path}\\n\\`\\`\\`\\n${file.content}\\n\\`\\`\\`\\n\\n`;\n }\n }\n\n // Add referenced resources from URL mentions\n if (referencedResources.length > 0) {\n prompt += `\\n\\n## Referenced Resources\\n\\n`;\n for (const resource of referencedResources) {\n prompt += `### ${resource.title} (${resource.type})\\n**URL**: ${resource.url}\\n\\n${resource.content}\\n\\n`;\n }\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: processedDescription,\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, repositoryPath?: string): Promise<string> {\n // Process file references in description\n const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(\n task.description,\n repositoryPath\n );\n\n // Process URL references in description \n const { description: processedDescription, referencedResources } = await this.processUrlReferences(\n descriptionAfterFiles\n );\n\n let prompt = '';\n prompt += `## Current Task\\n\\n**Task**: ${task.title}\\n**Description**: ${processedDescription}`;\n\n if ((task as any).primary_repository) {\n prompt += `\\n**Repository**: ${(task as any).primary_repository}`;\n }\n\n // Add referenced files from @ mentions\n if (referencedFiles.length > 0) {\n prompt += `\\n\\n## Referenced Files\\n\\n`;\n for (const file of referencedFiles) {\n prompt += `### ${file.path}\\n\\`\\`\\`\\n${file.content}\\n\\`\\`\\`\\n\\n`;\n }\n }\n\n // Add referenced resources from URL mentions\n if (referencedResources.length > 0) {\n prompt += `\\n\\n## Referenced Resources\\n\\n`;\n for (const resource of referencedResources) {\n prompt += `### ${resource.title} (${resource.type})\\n**URL**: ${resource.url}\\n\\n${resource.content}\\n\\n`;\n }\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":["fs"],"mappings":";;;;MAaa,aAAa,CAAA;AAChB,IAAA,YAAY;AACZ,IAAA,oBAAoB;AACpB,IAAA,aAAa;AACb,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;AACrD,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,IAAI,CAAC,MAAM,GA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E;AACxB,wBAAA,MAAM,IAAI,CAAA,wBAAA,EAA2B,IAAI,CAAC,OAAO,EAAE;oBACrD;yBAAO;AACL,wBAAA,MAAM,IAAI,CAAA,QAAA,EAAW,IAAI,CAAC,IAAI,CAAA,EAAA,EAAK,IAAI,CAAC,IAAI,CAAA,GAAA,EAAM,IAAI,CAAC,OAAO,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
+ {"version":3,"file":"prompt-builder.js","sources":["../../src/prompt-builder.ts"],"sourcesContent":["import type { Task, UrlMention, PostHogResource } from './types.js';\nimport type { TemplateVariables } from './template-manager.js';\nimport { Logger } from './utils/logger.js';\nimport { promises as fs } from 'fs';\nimport { join } from 'path';\n\nexport interface PromptBuilderDeps {\n getTaskFiles: (taskId: string) => Promise<any[]>;\n generatePlanTemplate: (vars: TemplateVariables) => Promise<string>;\n posthogClient?: { fetchResourceByUrl: (mention: UrlMention) => Promise<PostHogResource> };\n logger?: Logger;\n}\n\nexport class PromptBuilder {\n private getTaskFiles: PromptBuilderDeps['getTaskFiles'];\n private generatePlanTemplate: PromptBuilderDeps['generatePlanTemplate'];\n private posthogClient?: PromptBuilderDeps['posthogClient'];\n private logger: Logger;\n\n constructor(deps: PromptBuilderDeps) {\n this.getTaskFiles = deps.getTaskFiles;\n this.generatePlanTemplate = deps.generatePlanTemplate;\n this.posthogClient = deps.posthogClient;\n this.logger = deps.logger || new Logger({ debug: false, prefix: '[PromptBuilder]' });\n }\n\n /**\n * Extract file paths from XML tags in description\n * Format: <file path=\"relative/path.ts\" />\n */\n private extractFilePaths(description: string): string[] {\n const fileTagRegex = /<file\\s+path=\"([^\"]+)\"\\s*\\/>/g;\n const paths: string[] = [];\n let match: RegExpExecArray | null;\n\n while ((match = fileTagRegex.exec(description)) !== null) {\n paths.push(match[1]);\n }\n\n return paths;\n }\n\n /**\n * Read file contents from repository\n */\n private async readFileContent(repositoryPath: string, filePath: string): Promise<string | null> {\n try {\n const fullPath = join(repositoryPath, filePath);\n const content = await fs.readFile(fullPath, 'utf8');\n return content;\n } catch (error) {\n this.logger.warn(`Failed to read referenced file: ${filePath}`, { error });\n return null;\n }\n }\n\n /**\n * Extract URL mentions from XML tags in description\n * Formats: <error id=\"...\" />, <experiment id=\"...\" />, <url href=\"...\" />\n */\n private extractUrlMentions(description: string): UrlMention[] {\n const mentions: UrlMention[] = [];\n \n // PostHog resource mentions: <error id=\"...\" />, <experiment id=\"...\" />, etc.\n const resourceRegex = /<(error|experiment|insight|feature_flag)\\s+id=\"([^\"]+)\"\\s*\\/>/g;\n let match: RegExpExecArray | null;\n\n while ((match = resourceRegex.exec(description)) !== null) {\n const [, type, id] = match;\n mentions.push({\n url: '', // Will be reconstructed if needed\n type: type as any,\n id,\n label: this.generateUrlLabel('', type as any),\n });\n }\n\n // Generic URL mentions: <url href=\"...\" />\n const urlRegex = /<url\\s+href=\"([^\"]+)\"\\s*\\/>/g;\n while ((match = urlRegex.exec(description)) !== null) {\n const [, url] = match;\n mentions.push({\n url,\n type: 'generic',\n label: this.generateUrlLabel(url, 'generic'),\n });\n }\n\n return mentions;\n }\n\n /**\n * Generate a display label for a URL mention\n */\n private generateUrlLabel(url: string, type: string): string {\n try {\n const urlObj = new URL(url);\n switch (type) {\n case 'error':\n const errorMatch = url.match(/error_tracking\\/([a-f0-9-]+)/);\n return errorMatch ? `Error ${errorMatch[1].slice(0, 8)}...` : 'Error';\n case 'experiment':\n const expMatch = url.match(/experiments\\/(\\d+)/);\n return expMatch ? `Experiment #${expMatch[1]}` : 'Experiment';\n case 'insight':\n return 'Insight';\n case 'feature_flag':\n return 'Feature Flag';\n default:\n return urlObj.hostname;\n }\n } catch {\n return 'URL';\n }\n }\n\n /**\n * Process URL references and fetch their content\n */\n private async processUrlReferences(\n description: string\n ): Promise<{ description: string; referencedResources: PostHogResource[] }> {\n const urlMentions = this.extractUrlMentions(description);\n const referencedResources: PostHogResource[] = [];\n\n if (urlMentions.length === 0 || !this.posthogClient) {\n return { description, referencedResources };\n }\n\n // Fetch all referenced resources\n for (const mention of urlMentions) {\n try {\n const resource = await this.posthogClient.fetchResourceByUrl(mention);\n referencedResources.push(resource);\n } catch (error) {\n this.logger.warn(`Failed to fetch resource from URL: ${mention.url}`, { error });\n // Add a placeholder resource for failed fetches\n referencedResources.push({\n type: mention.type,\n id: mention.id || '',\n url: mention.url,\n title: mention.label || 'Unknown Resource',\n content: `Failed to fetch resource from ${mention.url}: ${error}`,\n metadata: {},\n });\n }\n }\n\n // Replace URL tags with just the label for readability\n let processedDescription = description;\n for (const mention of urlMentions) {\n if (mention.type === 'generic') {\n // Generic URLs: <url href=\"...\" />\n const escapedUrl = mention.url.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n processedDescription = processedDescription.replace(\n new RegExp(`<url\\\\s+href=\"${escapedUrl}\"\\\\s*/>`, 'g'),\n `@${mention.label}`\n );\n } else {\n // PostHog resources: <error id=\"...\" />, <experiment id=\"...\" />, etc.\n const escapedType = mention.type.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const escapedId = mention.id ? mention.id.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') : '';\n processedDescription = processedDescription.replace(\n new RegExp(`<${escapedType}\\\\s+id=\"${escapedId}\"\\\\s*/>`, 'g'),\n `@${mention.label}`\n );\n }\n }\n\n return { description: processedDescription, referencedResources };\n }\n\n /**\n * Process description to extract file tags and read contents\n * Returns processed description and referenced file contents\n */\n private async processFileReferences(\n description: string,\n repositoryPath?: string\n ): Promise<{ description: string; referencedFiles: Array<{ path: string; content: string }> }> {\n const filePaths = this.extractFilePaths(description);\n const referencedFiles: Array<{ path: string; content: string }> = [];\n\n if (filePaths.length === 0 || !repositoryPath) {\n return { description, referencedFiles };\n }\n\n // Read all referenced files\n for (const filePath of filePaths) {\n const content = await this.readFileContent(repositoryPath, filePath);\n if (content !== null) {\n referencedFiles.push({ path: filePath, content });\n }\n }\n\n // Replace file tags with just the filename for readability\n let processedDescription = description;\n for (const filePath of filePaths) {\n const fileName = filePath.split('/').pop() || filePath;\n processedDescription = processedDescription.replace(\n new RegExp(`<file\\\\s+path=\"${filePath.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')}\"\\\\s*/>`, 'g'),\n `@${fileName}`\n );\n }\n\n return { description: processedDescription, referencedFiles };\n }\n\n async buildResearchPrompt(task: Task, repositoryPath?: string): Promise<string> {\n // Process file references in description\n const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(\n task.description,\n repositoryPath\n );\n\n // Process URL references in description\n const { description: processedDescription, referencedResources } = await this.processUrlReferences(\n descriptionAfterFiles\n );\n\n let prompt = '<task>\\n';\n prompt += `<title>${task.title}</title>\\n`;\n prompt += `<description>${processedDescription}</description>\\n`;\n\n if ((task as any).primary_repository) {\n prompt += `<repository>${(task as any).primary_repository}</repository>\\n`;\n }\n prompt += '</task>\\n';\n\n // Add referenced files from @ mentions\n if (referencedFiles.length > 0) {\n prompt += '\\n<referenced_files>\\n';\n for (const file of referencedFiles) {\n prompt += `<file path=\"${file.path}\">\\n\\`\\`\\`\\n${file.content}\\n\\`\\`\\`\\n</file>\\n`;\n }\n prompt += '</referenced_files>\\n';\n }\n\n // Add referenced resources from URL mentions\n if (referencedResources.length > 0) {\n prompt += '\\n<referenced_resources>\\n';\n for (const resource of referencedResources) {\n prompt += `<resource type=\"${resource.type}\" url=\"${resource.url}\">\\n`;\n prompt += `<title>${resource.title}</title>\\n`;\n prompt += `<content>${resource.content}</content>\\n`;\n prompt += '</resource>\\n';\n }\n prompt += '</referenced_resources>\\n';\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<supporting_files>\\n';\n for (const file of contextFiles) {\n prompt += `<file name=\"${file.name}\" type=\"${file.type}\">\\n${file.content}\\n</file>\\n`;\n }\n prompt += '</supporting_files>\\n';\n }\n } catch (error) {\n this.logger.debug('No existing task files found for research', { taskId: task.id });\n }\n\n return prompt;\n }\n\n async buildPlanningPrompt(task: Task, repositoryPath?: string): Promise<string> {\n // Process file references in description\n const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(\n task.description,\n repositoryPath\n );\n\n // Process URL references in description\n const { description: processedDescription, referencedResources } = await this.processUrlReferences(\n descriptionAfterFiles\n );\n\n let prompt = '<task>\\n';\n prompt += `<title>${task.title}</title>\\n`;\n prompt += `<description>${processedDescription}</description>\\n`;\n\n if ((task as any).primary_repository) {\n prompt += `<repository>${(task as any).primary_repository}</repository>\\n`;\n }\n prompt += '</task>\\n';\n\n // Add referenced files from @ mentions\n if (referencedFiles.length > 0) {\n prompt += '\\n<referenced_files>\\n';\n for (const file of referencedFiles) {\n prompt += `<file path=\"${file.path}\">\\n\\`\\`\\`\\n${file.content}\\n\\`\\`\\`\\n</file>\\n`;\n }\n prompt += '</referenced_files>\\n';\n }\n\n // Add referenced resources from URL mentions\n if (referencedResources.length > 0) {\n prompt += '\\n<referenced_resources>\\n';\n for (const resource of referencedResources) {\n prompt += `<resource type=\"${resource.type}\" url=\"${resource.url}\">\\n`;\n prompt += `<title>${resource.title}</title>\\n`;\n prompt += `<content>${resource.content}</content>\\n`;\n prompt += '</resource>\\n';\n }\n prompt += '</referenced_resources>\\n';\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<supporting_files>\\n';\n for (const file of contextFiles) {\n prompt += `<file name=\"${file.name}\" type=\"${file.type}\">\\n${file.content}\\n</file>\\n`;\n }\n prompt += '</supporting_files>\\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: processedDescription,\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<instructions>\\n';\n prompt += 'Analyze the codebase and create a detailed implementation plan. Use the template structure below, filling each section with specific, actionable information.\\n';\n prompt += '</instructions>\\n\\n';\n prompt += '<plan_template>\\n';\n prompt += planTemplate;\n prompt += '\\n</plan_template>';\n\n return prompt;\n }\n\n async buildExecutionPrompt(task: Task, repositoryPath?: string): Promise<string> {\n // Process file references in description\n const { description: descriptionAfterFiles, referencedFiles } = await this.processFileReferences(\n task.description,\n repositoryPath\n );\n\n // Process URL references in description\n const { description: processedDescription, referencedResources } = await this.processUrlReferences(\n descriptionAfterFiles\n );\n\n let prompt = '<task>\\n';\n prompt += `<title>${task.title}</title>\\n`;\n prompt += `<description>${processedDescription}</description>\\n`;\n\n if ((task as any).primary_repository) {\n prompt += `<repository>${(task as any).primary_repository}</repository>\\n`;\n }\n prompt += '</task>\\n';\n\n // Add referenced files from @ mentions\n if (referencedFiles.length > 0) {\n prompt += '\\n<referenced_files>\\n';\n for (const file of referencedFiles) {\n prompt += `<file path=\"${file.path}\">\\n\\`\\`\\`\\n${file.content}\\n\\`\\`\\`\\n</file>\\n`;\n }\n prompt += '</referenced_files>\\n';\n }\n\n // Add referenced resources from URL mentions\n if (referencedResources.length > 0) {\n prompt += '\\n<referenced_resources>\\n';\n for (const resource of referencedResources) {\n prompt += `<resource type=\"${resource.type}\" url=\"${resource.url}\">\\n`;\n prompt += `<title>${resource.title}</title>\\n`;\n prompt += `<content>${resource.content}</content>\\n`;\n prompt += '</resource>\\n';\n }\n prompt += '</referenced_resources>\\n';\n }\n\n try {\n const taskFiles = await this.getTaskFiles(task.id);\n const hasPlan = taskFiles.some((f: any) => f.type === 'plan');\n\n if (taskFiles.length > 0) {\n prompt += '\\n<context>\\n';\n for (const file of taskFiles) {\n if (file.type === 'plan') {\n prompt += `<plan>\\n${file.content}\\n</plan>\\n`;\n } else {\n prompt += `<file name=\"${file.name}\" type=\"${file.type}\">\\n${file.content}\\n</file>\\n`;\n }\n }\n prompt += '</context>\\n';\n }\n\n prompt += '\\n<instructions>\\n';\n if (hasPlan) {\n prompt += 'Implement the changes described in the execution plan. Follow the plan step-by-step and make the necessary file modifications.\\n';\n } else {\n prompt += 'Implement the changes described in the task. Make the necessary file modifications to complete the task.\\n';\n }\n prompt += '</instructions>';\n } catch (error) {\n this.logger.debug('No supporting files found for execution', { taskId: task.id });\n prompt += '\\n<instructions>\\n';\n prompt += 'Implement the changes described in the task.\\n';\n prompt += '</instructions>';\n }\n\n return prompt;\n }\n}\n\n\n"],"names":["fs"],"mappings":";;;;MAaa,aAAa,CAAA;AAChB,IAAA,YAAY;AACZ,IAAA,oBAAoB;AACpB,IAAA,aAAa;AACb,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;AACrD,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa;QACvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;IACtF;AAEA;;;AAGG;AACK,IAAA,gBAAgB,CAAC,WAAmB,EAAA;QAC1C,MAAM,YAAY,GAAG,+BAA+B;QACpD,MAAM,KAAK,GAAa,EAAE;AAC1B,QAAA,IAAI,KAA6B;AAEjC,QAAA,OAAO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StructuredExtractor {
12
12
  extractQuestions(researchContent: string): Promise<ExtractedQuestion[]>;
13
13
  extractQuestionsWithAnswers(researchContent: string): Promise<ExtractedQuestionWithAnswer[]>;
14
14
  }
15
- export declare class OpenAIExtractor implements StructuredExtractor {
16
- private client;
15
+ export declare class AISDKExtractor implements StructuredExtractor {
17
16
  private logger;
17
+ private model;
18
18
  constructor(logger?: Logger);
19
19
  extractQuestions(researchContent: string): Promise<ExtractedQuestion[]>;
20
20
  extractQuestionsWithAnswers(researchContent: string): Promise<ExtractedQuestionWithAnswer[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"structured-extraction.d.ts","sourceRoot":"","sources":["../../src/structured-extraction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IACpE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AAoDD,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IACxE,2BAA2B,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,EAAE,CAAC,CAAC;CAC9F;AAED,qBAAa,eAAgB,YAAW,mBAAmB;IACzD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAUrB,gBAAgB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAyCvE,2BAA2B,CAC/B,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,2BAA2B,EAAE,CAAC;CAwC1C"}
1
+ {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