mcp-taskflow 0.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.
Files changed (187) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +275 -0
  4. package/dist/config/pathResolver.d.ts +33 -0
  5. package/dist/config/pathResolver.d.ts.map +1 -0
  6. package/dist/config/pathResolver.js +130 -0
  7. package/dist/config/pathResolver.js.map +1 -0
  8. package/dist/data/fileOperations.d.ts +43 -0
  9. package/dist/data/fileOperations.d.ts.map +1 -0
  10. package/dist/data/fileOperations.js +248 -0
  11. package/dist/data/fileOperations.js.map +1 -0
  12. package/dist/data/memoryStore.d.ts +86 -0
  13. package/dist/data/memoryStore.d.ts.map +1 -0
  14. package/dist/data/memoryStore.js +216 -0
  15. package/dist/data/memoryStore.js.map +1 -0
  16. package/dist/data/rulesStore.d.ts +63 -0
  17. package/dist/data/rulesStore.d.ts.map +1 -0
  18. package/dist/data/rulesStore.js +196 -0
  19. package/dist/data/rulesStore.js.map +1 -0
  20. package/dist/data/schemas.d.ts +840 -0
  21. package/dist/data/schemas.d.ts.map +1 -0
  22. package/dist/data/schemas.js +265 -0
  23. package/dist/data/schemas.js.map +1 -0
  24. package/dist/data/taskSearchService.d.ts +110 -0
  25. package/dist/data/taskSearchService.d.ts.map +1 -0
  26. package/dist/data/taskSearchService.js +165 -0
  27. package/dist/data/taskSearchService.js.map +1 -0
  28. package/dist/data/taskStore.d.ts +192 -0
  29. package/dist/data/taskStore.d.ts.map +1 -0
  30. package/dist/data/taskStore.js +347 -0
  31. package/dist/data/taskStore.js.map +1 -0
  32. package/dist/index.d.ts +23 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +86 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/prompts/index.d.ts +12 -0
  37. package/dist/prompts/index.d.ts.map +1 -0
  38. package/dist/prompts/index.js +17 -0
  39. package/dist/prompts/index.js.map +1 -0
  40. package/dist/prompts/projectPromptBuilder.d.ts +13 -0
  41. package/dist/prompts/projectPromptBuilder.d.ts.map +1 -0
  42. package/dist/prompts/projectPromptBuilder.js +29 -0
  43. package/dist/prompts/projectPromptBuilder.js.map +1 -0
  44. package/dist/prompts/researchPromptBuilder.d.ts +10 -0
  45. package/dist/prompts/researchPromptBuilder.d.ts.map +1 -0
  46. package/dist/prompts/researchPromptBuilder.js +20 -0
  47. package/dist/prompts/researchPromptBuilder.js.map +1 -0
  48. package/dist/prompts/taskPromptBuilders.d.ts +87 -0
  49. package/dist/prompts/taskPromptBuilders.d.ts.map +1 -0
  50. package/dist/prompts/taskPromptBuilders.js +529 -0
  51. package/dist/prompts/taskPromptBuilders.js.map +1 -0
  52. package/dist/prompts/templateEngine.d.ts +102 -0
  53. package/dist/prompts/templateEngine.d.ts.map +1 -0
  54. package/dist/prompts/templateEngine.js +145 -0
  55. package/dist/prompts/templateEngine.js.map +1 -0
  56. package/dist/prompts/templateLoader.d.ts +61 -0
  57. package/dist/prompts/templateLoader.d.ts.map +1 -0
  58. package/dist/prompts/templateLoader.js +129 -0
  59. package/dist/prompts/templateLoader.js.map +1 -0
  60. package/dist/prompts/templates/v1/templates_en/analyzeTask/index.md +65 -0
  61. package/dist/prompts/templates/v1/templates_en/analyzeTask/iteration.md +12 -0
  62. package/dist/prompts/templates/v1/templates_en/clearAllTasks/backupInfo.md +1 -0
  63. package/dist/prompts/templates/v1/templates_en/clearAllTasks/cancel.md +7 -0
  64. package/dist/prompts/templates/v1/templates_en/clearAllTasks/empty.md +5 -0
  65. package/dist/prompts/templates/v1/templates_en/clearAllTasks/index.md +5 -0
  66. package/dist/prompts/templates/v1/templates_en/clearAllTasks/result.md +7 -0
  67. package/dist/prompts/templates/v1/templates_en/clearAllTasks/success.md +5 -0
  68. package/dist/prompts/templates/v1/templates_en/deleteTask/completed.md +5 -0
  69. package/dist/prompts/templates/v1/templates_en/deleteTask/index.md +5 -0
  70. package/dist/prompts/templates/v1/templates_en/deleteTask/notFound.md +5 -0
  71. package/dist/prompts/templates/v1/templates_en/deleteTask/result.md +5 -0
  72. package/dist/prompts/templates/v1/templates_en/deleteTask/success.md +5 -0
  73. package/dist/prompts/templates/v1/templates_en/executeTask/analysisResult.md +3 -0
  74. package/dist/prompts/templates/v1/templates_en/executeTask/complexity.md +15 -0
  75. package/dist/prompts/templates/v1/templates_en/executeTask/dependencies.md +3 -0
  76. package/dist/prompts/templates/v1/templates_en/executeTask/dependencyTasks.md +3 -0
  77. package/dist/prompts/templates/v1/templates_en/executeTask/implementationGuide.md +3 -0
  78. package/dist/prompts/templates/v1/templates_en/executeTask/index.md +39 -0
  79. package/dist/prompts/templates/v1/templates_en/executeTask/notes.md +1 -0
  80. package/dist/prompts/templates/v1/templates_en/executeTask/relatedFilesSummary.md +5 -0
  81. package/dist/prompts/templates/v1/templates_en/executeTask/verificationCriteria.md +3 -0
  82. package/dist/prompts/templates/v1/templates_en/getTaskDetail/complatedSummary.md +5 -0
  83. package/dist/prompts/templates/v1/templates_en/getTaskDetail/dependencies.md +1 -0
  84. package/dist/prompts/templates/v1/templates_en/getTaskDetail/error.md +3 -0
  85. package/dist/prompts/templates/v1/templates_en/getTaskDetail/implementationGuide.md +3 -0
  86. package/dist/prompts/templates/v1/templates_en/getTaskDetail/index.md +25 -0
  87. package/dist/prompts/templates/v1/templates_en/getTaskDetail/notFound.md +3 -0
  88. package/dist/prompts/templates/v1/templates_en/getTaskDetail/notes.md +1 -0
  89. package/dist/prompts/templates/v1/templates_en/getTaskDetail/relatedFiles.md +3 -0
  90. package/dist/prompts/templates/v1/templates_en/getTaskDetail/verificationCriteria.md +3 -0
  91. package/dist/prompts/templates/v1/templates_en/initProjectRules/index.md +81 -0
  92. package/dist/prompts/templates/v1/templates_en/listTasks/index.md +7 -0
  93. package/dist/prompts/templates/v1/templates_en/listTasks/notFound.md +3 -0
  94. package/dist/prompts/templates/v1/templates_en/listTasks/taskDetails.md +13 -0
  95. package/dist/prompts/templates/v1/templates_en/planTask/hasThought.md +4 -0
  96. package/dist/prompts/templates/v1/templates_en/planTask/index.md +96 -0
  97. package/dist/prompts/templates/v1/templates_en/planTask/noThought.md +4 -0
  98. package/dist/prompts/templates/v1/templates_en/planTask/tasks.md +17 -0
  99. package/dist/prompts/templates/v1/templates_en/processThought/complatedThought.md +6 -0
  100. package/dist/prompts/templates/v1/templates_en/processThought/index.md +13 -0
  101. package/dist/prompts/templates/v1/templates_en/processThought/moreThought.md +1 -0
  102. package/dist/prompts/templates/v1/templates_en/queryTask/index.md +24 -0
  103. package/dist/prompts/templates/v1/templates_en/queryTask/notFound.md +15 -0
  104. package/dist/prompts/templates/v1/templates_en/queryTask/taskDetails.md +5 -0
  105. package/dist/prompts/templates/v1/templates_en/reflectTask/index.md +57 -0
  106. package/dist/prompts/templates/v1/templates_en/researchMode/index.md +95 -0
  107. package/dist/prompts/templates/v1/templates_en/researchMode/previousState.md +9 -0
  108. package/dist/prompts/templates/v1/templates_en/splitTasks/index.md +34 -0
  109. package/dist/prompts/templates/v1/templates_en/splitTasks/taskDetails.md +12 -0
  110. package/dist/prompts/templates/v1/templates_en/tests/basic.md +1 -0
  111. package/dist/prompts/templates/v1/templates_en/toolsDescription/analyzeTask.md +1 -0
  112. package/dist/prompts/templates/v1/templates_en/toolsDescription/clearAllTasks.md +1 -0
  113. package/dist/prompts/templates/v1/templates_en/toolsDescription/deleteTask.md +1 -0
  114. package/dist/prompts/templates/v1/templates_en/toolsDescription/executeTask.md +1 -0
  115. package/dist/prompts/templates/v1/templates_en/toolsDescription/getTaskDetail.md +1 -0
  116. package/dist/prompts/templates/v1/templates_en/toolsDescription/initProjectRules.md +1 -0
  117. package/dist/prompts/templates/v1/templates_en/toolsDescription/listTasks.md +1 -0
  118. package/dist/prompts/templates/v1/templates_en/toolsDescription/planTask.md +3 -0
  119. package/dist/prompts/templates/v1/templates_en/toolsDescription/processThought.md +1 -0
  120. package/dist/prompts/templates/v1/templates_en/toolsDescription/queryTask.md +1 -0
  121. package/dist/prompts/templates/v1/templates_en/toolsDescription/reflectTask.md +1 -0
  122. package/dist/prompts/templates/v1/templates_en/toolsDescription/researchMode.md +1 -0
  123. package/dist/prompts/templates/v1/templates_en/toolsDescription/splitTasks.md +83 -0
  124. package/dist/prompts/templates/v1/templates_en/toolsDescription/updateTask.md +1 -0
  125. package/dist/prompts/templates/v1/templates_en/toolsDescription/verifyTask.md +37 -0
  126. package/dist/prompts/templates/v1/templates_en/updateTaskContent/emptyUpdate.md +5 -0
  127. package/dist/prompts/templates/v1/templates_en/updateTaskContent/fileDetails.md +1 -0
  128. package/dist/prompts/templates/v1/templates_en/updateTaskContent/index.md +7 -0
  129. package/dist/prompts/templates/v1/templates_en/updateTaskContent/notFound.md +5 -0
  130. package/dist/prompts/templates/v1/templates_en/updateTaskContent/success.md +9 -0
  131. package/dist/prompts/templates/v1/templates_en/updateTaskContent/successDetails.md +3 -0
  132. package/dist/prompts/templates/v1/templates_en/updateTaskContent/validation.md +5 -0
  133. package/dist/prompts/templates/v1/templates_en/verifyTask/index.md +19 -0
  134. package/dist/prompts/templates/v1/templates_en/verifyTask/noPass.md +12 -0
  135. package/dist/prompts/thoughtPromptBuilder.d.ts +11 -0
  136. package/dist/prompts/thoughtPromptBuilder.d.ts.map +1 -0
  137. package/dist/prompts/thoughtPromptBuilder.js +30 -0
  138. package/dist/prompts/thoughtPromptBuilder.js.map +1 -0
  139. package/dist/server/container.d.ts +111 -0
  140. package/dist/server/container.d.ts.map +1 -0
  141. package/dist/server/container.js +135 -0
  142. package/dist/server/container.js.map +1 -0
  143. package/dist/server/logger.d.ts +98 -0
  144. package/dist/server/logger.d.ts.map +1 -0
  145. package/dist/server/logger.js +295 -0
  146. package/dist/server/logger.js.map +1 -0
  147. package/dist/server/mcpServer.d.ts +162 -0
  148. package/dist/server/mcpServer.d.ts.map +1 -0
  149. package/dist/server/mcpServer.js +236 -0
  150. package/dist/server/mcpServer.js.map +1 -0
  151. package/dist/tools/project/index.d.ts +7 -0
  152. package/dist/tools/project/index.d.ts.map +1 -0
  153. package/dist/tools/project/index.js +7 -0
  154. package/dist/tools/project/index.js.map +1 -0
  155. package/dist/tools/project/projectTools.d.ts +17 -0
  156. package/dist/tools/project/projectTools.d.ts.map +1 -0
  157. package/dist/tools/project/projectTools.js +73 -0
  158. package/dist/tools/project/projectTools.js.map +1 -0
  159. package/dist/tools/research/index.d.ts +7 -0
  160. package/dist/tools/research/index.d.ts.map +1 -0
  161. package/dist/tools/research/index.js +7 -0
  162. package/dist/tools/research/index.js.map +1 -0
  163. package/dist/tools/research/researchTools.d.ts +16 -0
  164. package/dist/tools/research/researchTools.d.ts.map +1 -0
  165. package/dist/tools/research/researchTools.js +41 -0
  166. package/dist/tools/research/researchTools.js.map +1 -0
  167. package/dist/tools/task/index.d.ts +8 -0
  168. package/dist/tools/task/index.d.ts.map +1 -0
  169. package/dist/tools/task/index.js +8 -0
  170. package/dist/tools/task/index.js.map +1 -0
  171. package/dist/tools/task/taskTools.d.ts +32 -0
  172. package/dist/tools/task/taskTools.d.ts.map +1 -0
  173. package/dist/tools/task/taskTools.js +542 -0
  174. package/dist/tools/task/taskTools.js.map +1 -0
  175. package/dist/tools/thought/index.d.ts +7 -0
  176. package/dist/tools/thought/index.d.ts.map +1 -0
  177. package/dist/tools/thought/index.js +7 -0
  178. package/dist/tools/thought/index.js.map +1 -0
  179. package/dist/tools/thought/thoughtTools.d.ts +16 -0
  180. package/dist/tools/thought/thoughtTools.d.ts.map +1 -0
  181. package/dist/tools/thought/thoughtTools.js +47 -0
  182. package/dist/tools/thought/thoughtTools.js.map +1 -0
  183. package/docs/API.md +32 -0
  184. package/docs/ARCHITECTURE.md +44 -0
  185. package/docs/COMPATIBILITY_REPORT.md +26 -0
  186. package/docs/PERFORMANCE.md +66 -0
  187. package/package.json +77 -0
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Lightweight template engine for rendering prompt templates with variable substitution.
3
+ *
4
+ * Design:
5
+ * - Matches the reference prompt rendering behavior
6
+ * - Simple token replacement: {{key}}, {{ key }}, {key}
7
+ * - Logic handled in code, not templates (separation of concerns)
8
+ * - Zero external dependencies
9
+ *
10
+ * @module prompts/templateEngine
11
+ */
12
+ /**
13
+ * Renders a template string by replacing tokens with provided parameter values.
14
+ *
15
+ * Supported token formats (case-sensitive):
16
+ * - {{key}} - standard Handlebars/Mustache style
17
+ * - {{ key }} - with spaces
18
+ * - {key} - simple braces (for compatibility)
19
+ *
20
+ * Performance: O(n*m) where n = template length, m = number of parameters.
21
+ * For 1000 renders: ~5-10ms (much faster than Handlebars compilation)
22
+ *
23
+ * @param template - The template string with tokens to replace
24
+ * @param parameters - Key-value pairs for token replacement
25
+ * @returns Rendered template with tokens replaced
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const template = "Hello {{name}}, you have {{count}} messages!";
30
+ * const result = render(template, { name: "Alice", count: 5 });
31
+ * // Returns: "Hello Alice, you have 5 messages!"
32
+ * ```
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Nested template composition (logic in code, not template)
37
+ * const partial = render("Task: {{taskName}}", { taskName: "Deploy" });
38
+ * const full = render("{{header}}\n{{body}}", { header: "# Tasks", body: partial });
39
+ * ```
40
+ */
41
+ export function render(template, parameters) {
42
+ // Input validation
43
+ if (typeof template !== 'string') {
44
+ throw new TypeError(`Template must be a string, got ${typeof template}`);
45
+ }
46
+ // Fast path: no parameters = no work
47
+ if (!parameters || Object.keys(parameters).length === 0) {
48
+ return template;
49
+ }
50
+ // Replace each parameter token in the template
51
+ let result = template;
52
+ for (const [key, value] of Object.entries(parameters)) {
53
+ // Convert value to string safely (null-safe)
54
+ const replacement = value?.toString() ?? '';
55
+ // Replace all token formats for this key
56
+ result = replaceToken(result, key, replacement);
57
+ }
58
+ return result;
59
+ }
60
+ /**
61
+ * Replaces all occurrences of a token in multiple formats.
62
+ *
63
+ * Token formats (in order of replacement):
64
+ * 1. {{ key }} - with spaces (4 chars total: {{ + space + key + space + }})
65
+ * 2. {{key}} - no spaces (standard Handlebars/Mustache)
66
+ * 3. {key} - single braces (simple format)
67
+ *
68
+ * Order matters: Replace longest format first to avoid partial replacements.
69
+ * Example: If we replaced {key} first, it would break {{key}}.
70
+ *
71
+ * @param template - The template string
72
+ * @param key - The parameter name (without braces)
73
+ * @param replacement - The value to substitute
74
+ * @returns Template with all token formats replaced
75
+ *
76
+ * @internal
77
+ */
78
+ function replaceToken(template, key, replacement) {
79
+ // Use literal string replacement (no regex)
80
+ let result = template;
81
+ // Format 1: {{ key }} - with spaces
82
+ result = result.replaceAll(`{{ ${key} }}`, replacement);
83
+ // Format 2: {{key}} - standard
84
+ result = result.replaceAll(`{{${key}}}`, replacement);
85
+ // Format 3: {key} - simple (legacy compatibility)
86
+ result = result.replaceAll(`{${key}}`, replacement);
87
+ return result;
88
+ }
89
+ /**
90
+ * Template engine for batch rendering multiple templates efficiently.
91
+ * Useful for rendering template partials and composing complex prompts.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const engine = new TemplateEngine();
96
+ * const header = engine.render("# {{title}}", { title: "Tasks" });
97
+ * const body = engine.render("Count: {{count}}", { count: 42 });
98
+ * const full = engine.render("{{header}}\n{{body}}", { header, body });
99
+ * ```
100
+ */
101
+ export class TemplateEngine {
102
+ /**
103
+ * Renders a template with parameters.
104
+ * Convenience method that delegates to the `render` function.
105
+ *
106
+ * @param template - Template string
107
+ * @param parameters - Replacement parameters
108
+ * @returns Rendered result
109
+ */
110
+ render(template, parameters) {
111
+ return render(template, parameters);
112
+ }
113
+ /**
114
+ * Renders multiple templates in sequence, passing results as parameters.
115
+ * Useful for composing nested templates.
116
+ *
117
+ * @param templates - Array of {template, parameters} objects
118
+ * @returns Array of rendered results
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const engine = new TemplateEngine();
123
+ * const results = engine.renderBatch([
124
+ * { template: "Name: {{name}}", parameters: { name: "Alice" } },
125
+ * { template: "Age: {{age}}", parameters: { age: 30 } }
126
+ * ]);
127
+ * // Returns: ["Name: Alice", "Age: 30"]
128
+ * ```
129
+ */
130
+ renderBatch(templates) {
131
+ return templates.map(({ template, parameters }) => this.render(template, parameters));
132
+ }
133
+ }
134
+ /**
135
+ * Default template engine instance for convenience.
136
+ * Use this for simple one-off rendering operations.
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * import { defaultEngine } from './templateEngine.js';
141
+ * const result = defaultEngine.render("Hello {{name}}", { name: "World" });
142
+ * ```
143
+ */
144
+ export const defaultEngine = new TemplateEngine();
145
+ //# sourceMappingURL=templateEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateEngine.js","sourceRoot":"","sources":["../../src/prompts/templateEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,MAAM,CACpB,QAAgB,EAChB,UAAsC;IAEtC,mBAAmB;IACnB,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,IAAI,SAAS,CACjB,kCAAkC,OAAO,QAAQ,EAAE,CACpD,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrC,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,+CAA+C;IAC/C,IAAI,MAAM,GAAG,QAAQ,CAAC;IACtB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,6CAA6C;QAC7C,MAAM,WAAW,GAAG,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAE5C,yCAAyC;QACzC,MAAM,GAAG,YAAY,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,YAAY,CACnB,QAAgB,EAChB,GAAW,EACX,WAAmB;IAEnB,4CAA4C;IAE5C,IAAI,MAAM,GAAG,QAAQ,CAAC;IAEtB,oCAAoC;IACpC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,KAAK,EAAE,WAAW,CAAC,CAAC;IAExD,+BAA+B;IAC/B,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI,EAAE,WAAW,CAAC,CAAC;IAEtD,kDAAkD;IAClD,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,EAAE,WAAW,CAAC,CAAC;IAEpD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,cAAc;IACzB;;;;;;;OAOG;IACH,MAAM,CAAC,QAAgB,EAAE,UAAsC;QAC7D,OAAO,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,CACT,SAGE;QAEF,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,CAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAClC,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,cAAc,EAAE,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Template loader for loading and caching markdown template files.
3
+ *
4
+ * Loads template files from the filesystem and caches them for performance.
5
+ * Templates are stored in src/prompts/templates/v1/templates_en/ directory.
6
+ *
7
+ * @module prompts/templateLoader
8
+ */
9
+ /**
10
+ * Loads a template file from disk with caching.
11
+ *
12
+ * Template Path Format:
13
+ * - Relative to templates directory: "analyzeTask/index.md"
14
+ * - Actual filesystem path: src/prompts/templates/v1/templates_en/analyzeTask/index.md
15
+ *
16
+ * Caches results for repeated access.
17
+ *
18
+ * @param templatePath - Relative path to template (e.g., "analyzeTask/index.md")
19
+ * @returns Template content as string
20
+ * @throws {Error} If template file not found or cannot be read
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const template = await loadTemplate('analyzeTask/index.md');
25
+ * // Returns: "**Please strictly follow the guidelines below**\n\n..."
26
+ * ```
27
+ */
28
+ export declare function loadTemplate(templatePath: string): Promise<string>;
29
+ /**
30
+ * Preloads commonly used templates into cache at startup.
31
+ *
32
+ * Call this during application initialization.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // In server startup:
37
+ * await preloadTemplates();
38
+ * ```
39
+ */
40
+ export declare function preloadTemplates(): Promise<void>;
41
+ /**
42
+ * Clears the template cache.
43
+ * Useful for testing or hot-reload during development.
44
+ *
45
+ * Only call this during development or tests.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // In test cleanup:
50
+ * clearCache();
51
+ * ```
52
+ */
53
+ export declare function clearCache(): void;
54
+ /**
55
+ * Gets the current cache size (number of cached templates).
56
+ * Useful for monitoring and debugging.
57
+ *
58
+ * @returns Number of cached templates
59
+ */
60
+ export declare function getCacheSize(): number;
61
+ //# sourceMappingURL=templateLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateLoader.d.ts","sourceRoot":"","sources":["../../src/prompts/templateLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCxE;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CA0BtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAIjC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Template loader for loading and caching markdown template files.
3
+ *
4
+ * Loads template files from the filesystem and caches them for performance.
5
+ * Templates are stored in src/prompts/templates/v1/templates_en/ directory.
6
+ *
7
+ * @module prompts/templateLoader
8
+ */
9
+ import { readFile } from 'node:fs/promises';
10
+ import { resolveTemplatePath } from '../config/pathResolver.js';
11
+ import { createLogger } from '../server/logger.js';
12
+ const logger = createLogger(undefined, { component: 'TemplateLoader' });
13
+ /**
14
+ * In-memory cache for compiled templates.
15
+ * Key: template path (e.g., "analyzeTask/index.md")
16
+ * Value: template content as string
17
+ *
18
+ * Caching prevents repeated disk I/O.
19
+ */
20
+ const templateCache = new Map();
21
+ /**
22
+ * Loads a template file from disk with caching.
23
+ *
24
+ * Template Path Format:
25
+ * - Relative to templates directory: "analyzeTask/index.md"
26
+ * - Actual filesystem path: src/prompts/templates/v1/templates_en/analyzeTask/index.md
27
+ *
28
+ * Caches results for repeated access.
29
+ *
30
+ * @param templatePath - Relative path to template (e.g., "analyzeTask/index.md")
31
+ * @returns Template content as string
32
+ * @throws {Error} If template file not found or cannot be read
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const template = await loadTemplate('analyzeTask/index.md');
37
+ * // Returns: "**Please strictly follow the guidelines below**\n\n..."
38
+ * ```
39
+ */
40
+ export async function loadTemplate(templatePath) {
41
+ // Check cache first (fast path)
42
+ const cached = templateCache.get(templatePath);
43
+ if (cached !== undefined) {
44
+ logger.debug(`Template cache hit: ${templatePath}`);
45
+ return cached;
46
+ }
47
+ // Validate and resolve template path
48
+ const absolutePath = resolveTemplatePath(templatePath);
49
+ try {
50
+ logger.debug(`Loading template from disk: ${templatePath}`);
51
+ // Read template file (UTF-8 encoding for markdown)
52
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
53
+ const content = await readFile(absolutePath, 'utf-8');
54
+ // Cache for future requests
55
+ templateCache.set(templatePath, content);
56
+ logger.info(`Template loaded and cached: ${templatePath} (${content.length} bytes)`);
57
+ return content;
58
+ }
59
+ catch (error) {
60
+ const safeMessage = `Failed to load template: ${templatePath}`;
61
+ logger.error(safeMessage, { error });
62
+ // Provide helpful error for missing templates
63
+ if (error.code === 'ENOENT') {
64
+ throw new Error(`Template not found: ${templatePath}. ` +
65
+ `Ensure the file exists in templates/v1/templates_en/`);
66
+ }
67
+ throw new Error(safeMessage, { cause: error });
68
+ }
69
+ }
70
+ /**
71
+ * Preloads commonly used templates into cache at startup.
72
+ *
73
+ * Call this during application initialization.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // In server startup:
78
+ * await preloadTemplates();
79
+ * ```
80
+ */
81
+ export async function preloadTemplates() {
82
+ const commonTemplates = [
83
+ 'planTask/index.md',
84
+ 'analyzeTask/index.md',
85
+ 'executeTask/index.md',
86
+ 'listTasks/index.md',
87
+ 'getTaskDetail/index.md',
88
+ 'verifyTask/index.md',
89
+ 'processThought/index.md',
90
+ 'researchMode/index.md'
91
+ ];
92
+ logger.info(`Preloading ${commonTemplates.length} common templates...`);
93
+ const results = await Promise.allSettled(commonTemplates.map(path => loadTemplate(path)));
94
+ const succeeded = results.filter(r => r.status === 'fulfilled').length;
95
+ const failed = results.filter(r => r.status === 'rejected').length;
96
+ if (failed > 0) {
97
+ logger.warn(`Preloaded ${succeeded}/${commonTemplates.length} templates (${failed} failed)`);
98
+ }
99
+ else {
100
+ logger.info(`Successfully preloaded all ${succeeded} templates`);
101
+ }
102
+ }
103
+ /**
104
+ * Clears the template cache.
105
+ * Useful for testing or hot-reload during development.
106
+ *
107
+ * Only call this during development or tests.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // In test cleanup:
112
+ * clearCache();
113
+ * ```
114
+ */
115
+ export function clearCache() {
116
+ const size = templateCache.size;
117
+ templateCache.clear();
118
+ logger.debug(`Template cache cleared (${size} entries removed)`);
119
+ }
120
+ /**
121
+ * Gets the current cache size (number of cached templates).
122
+ * Useful for monitoring and debugging.
123
+ *
124
+ * @returns Number of cached templates
125
+ */
126
+ export function getCacheSize() {
127
+ return templateCache.size;
128
+ }
129
+ //# sourceMappingURL=templateLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateLoader.js","sourceRoot":"","sources":["../../src/prompts/templateLoader.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,65 @@
1
+ ## Codebase Analysis
2
+
3
+ **Task Summary:** {summary}
4
+
5
+ **Initial Solution Concept:**
6
+
7
+ {initialConcept}
8
+
9
+ {iterationPrompt}
10
+
11
+ After receiving the initial solution, complete the following checks and optimizations in sequence, and call the `reflect_task` tool at the end:
12
+
13
+ 1. **Structural Integrity Check**
14
+
15
+ - Does it cover all requirements and constraints?
16
+ - Are module boundaries and interface definitions clear?
17
+ - Is the dependency graph reasonable and maintainable?
18
+ - Does the design conform to the project's core architectural patterns?
19
+ - Does it maintain the project's existing hierarchy and component divisions?
20
+
21
+ 2. **Duplicate Functionality Detection and Sharing Assessment**
22
+
23
+ - Use precise search strategies:
24
+ - Use `codebase_search`, `read_file` or similar tools to search for similar functionality implementations
25
+ - Analyze the purpose and responsibilities of key components and utility classes
26
+ - Check if functionalities in the solution overlap with existing code or other modules
27
+ - If overlapping, determine:
28
+ - Whether to directly **reuse** existing components (evaluate applicability, extensibility)
29
+ - Or need to **refactor/abstract** into shared components (consider reuse costs and benefits)
30
+ - Clearly indicate the reasons for reuse decisions and their scope of impact
31
+
32
+ 3. **Performance and Scalability Assessment**
33
+
34
+ - Are there potential performance bottlenecks?
35
+ - How scalable is the design for future requirements?
36
+ - Have resource usage and system load been considered?
37
+ - Does the expansion strategy conform to existing project patterns?
38
+
39
+ 4. **Consistency and Style Validation**
40
+
41
+ - Does it conform to the project's existing code style, naming, and architectural conventions
42
+ - Check naming convention consistency (camelCase, snake_case, etc.)
43
+ - Confirm method/function parameter and return value styles
44
+ - Check comment and documentation formats
45
+ - Does it follow project-specific design patterns and architectural decisions
46
+ - Are there violations of team best practices
47
+ - Does the UI/UX design match the current screen style
48
+
49
+ 5. **Architectural Integration Assessment**
50
+
51
+ - How new features seamlessly integrate with the existing architecture
52
+ - Evaluate impact on existing modules and services
53
+ - Confirm backward compatibility is maintained
54
+ - Check if system boundaries and module encapsulation are protected
55
+
56
+ 6. **Optimization Suggestions**
57
+ - Based on the above checks, organize optimized answers
58
+ - Ensure suggestions are consistent with the existing architecture
59
+ - Provide specific code organization and integration strategies
60
+ - Call tool:
61
+ ```
62
+ reflect_task({ summary: 'Analysis Summary', analysis: <Analysis Results> })
63
+ ```
64
+
65
+ **Now call `reflect_task`, strictly forbidden not to call the tool**
@@ -0,0 +1,12 @@
1
+ ## Iteration Analysis
2
+
3
+ Please compare with previous analysis results:
4
+
5
+ {previousAnalysis}
6
+
7
+ Please identify:
8
+
9
+ 1. Problems that have been resolved and the effectiveness of solutions
10
+ 2. Problems that still exist and their priorities
11
+ 3. How the new solution addresses unresolved issues
12
+ 4. New insights gained during the iteration process
@@ -0,0 +1 @@
1
+ Backup automatically created: `{{backupFile}}`
@@ -0,0 +1,7 @@
1
+ # Clear All Tasks Result
2
+
3
+ ## Operation Cancelled
4
+
5
+ The clearing operation was not confirmed. To clear all tasks, please set the confirm parameter to true.
6
+
7
+ ⚠️ This operation will delete all incomplete tasks and cannot be undone.
@@ -0,0 +1,5 @@
1
+ # Clear All Tasks Result
2
+
3
+ ## Operation Notice
4
+
5
+ There are no tasks in the system that need to be cleared.
@@ -0,0 +1,5 @@
1
+ # Clear All Tasks Result
2
+
3
+ ## {responseTitle}
4
+
5
+ {message}{backupInfo}
@@ -0,0 +1,7 @@
1
+ ## All Tasks Cleared
2
+
3
+ Successfully cleared **{{count}}** task(s) from the system.
4
+
5
+ {{backupInfo}}
6
+
7
+ All task data has been removed from the active task store.
@@ -0,0 +1,5 @@
1
+ # Clear All Tasks Result
2
+
3
+ ## Operation Successful
4
+
5
+ All incomplete tasks have been cleared.{backupInfo}
@@ -0,0 +1,5 @@
1
+ # Task Deletion Result
2
+
3
+ ## Operation Denied
4
+
5
+ Task "{taskName}" (ID: `{taskId}`) has been completed. Deleting completed tasks is not allowed.
@@ -0,0 +1,5 @@
1
+ # Task Deletion Result
2
+
3
+ ## {responseTitle}
4
+
5
+ {message}
@@ -0,0 +1,5 @@
1
+ # Task Deletion Result
2
+
3
+ ## System Error
4
+
5
+ Task with ID `{taskId}` could not be found. Please use the "list_tasks" tool to confirm valid task IDs and try again.
@@ -0,0 +1,5 @@
1
+ ## Task Deleted Successfully
2
+
3
+ Task **{{taskName}}** has been deleted from the system.
4
+
5
+ The task and all its metadata have been permanently removed.
@@ -0,0 +1,5 @@
1
+ # Task Deletion Result
2
+
3
+ ## Operation Successful
4
+
5
+ The task has been successfully deleted.
@@ -0,0 +1,3 @@
1
+ ## Analysis Background
2
+
3
+ {analysisResult}
@@ -0,0 +1,15 @@
1
+ ## Task Complexity Assessment
2
+
3
+ - **Complexity Level:** {level}
4
+
5
+ {complexityStyle}
6
+
7
+ ### Assessment Metrics
8
+
9
+ - Description Length: {descriptionLength} characters
10
+
11
+ - Number of Dependencies: {dependenciesCount}
12
+
13
+ ### Processing Recommendations
14
+
15
+ {recommendation}
@@ -0,0 +1,3 @@
1
+ ## Dependencies
2
+
3
+ This task depends on: {{dependencies}}
@@ -0,0 +1,3 @@
1
+ ## Dependency Tasks Completion Summary
2
+
3
+ {{ dependencyTasks }}
@@ -0,0 +1,3 @@
1
+ ## Implementation Guide
2
+
3
+ {implementationGuide}
@@ -0,0 +1,39 @@
1
+ **Please strictly follow the guidelines below**
2
+
3
+ ## Task Execution
4
+
5
+ **Name:** {name}
6
+
7
+ **ID:** `{id}`
8
+
9
+ **Description:** {description}
10
+
11
+ {notesTemplate}
12
+
13
+ {implementationGuideTemplate}
14
+
15
+ {verificationCriteriaTemplate}
16
+
17
+ {analysisResultTemplate}
18
+
19
+ {dependencyTasksTemplate}
20
+
21
+ {relatedFilesSummaryTemplate}
22
+
23
+ {complexityTemplate}
24
+
25
+ ## Execution Steps
26
+
27
+ 1. **Analyze Requirements** - Understand task requirements and constraints
28
+ 2. **Design Solution** - Develop implementation plan and testing strategy
29
+ 3. **Implement Solution** - Execute according to plan, handle edge cases
30
+ 4. **Test and Verify** - Ensure functionality correctness and robustness
31
+
32
+ ## Quality Requirements
33
+
34
+ - **Scope Management** - Only modify relevant code, avoid feature creep
35
+ - **Code Quality** - Comply with coding standards, handle exceptions
36
+ - **Performance Considerations** - Pay attention to algorithm efficiency and resource usage
37
+
38
+ Begin executing the task according to the instructions. After completing the task, call the verify_task tool to perform verification.
39
+ **Severe Warning**: You are strictly prohibited from assuming the task is complete or calling verify_task prematurely. You must use edit_file or any other available tools necessary to actually complete the task.
@@ -0,0 +1 @@
1
+ **Notes:** {notes}
@@ -0,0 +1,5 @@
1
+ ## Related Files
2
+
3
+ You can use the `update_task` tool to add related files to provide context when executing the task.
4
+
5
+ {relatedFilesSummary}
@@ -0,0 +1,3 @@
1
+ ## Verification Criteria
2
+
3
+ {verificationCriteria}
@@ -0,0 +1,5 @@
1
+ **Completion Time:** {completedTime}
2
+
3
+ **Completion Summary:**
4
+
5
+ {summary}
@@ -0,0 +1 @@
1
+ **Dependencies:** {dependencies}
@@ -0,0 +1,3 @@
1
+ ## System Error
2
+
3
+ An error occurred while retrieving task details: {errorMessage}
@@ -0,0 +1,3 @@
1
+ **Implementation Guide:**
2
+
3
+ {implementationGuide}
@@ -0,0 +1,25 @@
1
+ ## Complete Task Details
2
+
3
+ ### {name}
4
+
5
+ **ID:** `{id}`
6
+
7
+ **Status:** {status}
8
+
9
+ **Description:**{description}
10
+
11
+ {notesTemplate}
12
+
13
+ {dependenciesTemplate}
14
+
15
+ {implementationGuideTemplate}
16
+
17
+ {verificationCriteriaTemplate}
18
+
19
+ {relatedFilesTemplate}
20
+
21
+ **Creation Time:** {createdTime}
22
+
23
+ **Update Time:** {updatedTime}
24
+
25
+ {complatedSummaryTemplate}
@@ -0,0 +1,3 @@
1
+ ## Error
2
+
3
+ Task with ID `{taskId}` not found. Please verify that the task ID is correct.
@@ -0,0 +1 @@
1
+ **Notes:** {notes}
@@ -0,0 +1,3 @@
1
+ **Related Files:**
2
+
3
+ {files}
@@ -0,0 +1,3 @@
1
+ **Verification Criteria:**
2
+
3
+ {verificationCriteria}