specweave 0.24.8 → 0.24.9

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 (130) hide show
  1. package/dist/src/cli/commands/init.d.ts.map +1 -1
  2. package/dist/src/cli/commands/init.js +3 -1
  3. package/dist/src/cli/commands/init.js.map +1 -1
  4. package/dist/src/cli/helpers/issue-tracker/github-multi-repo.d.ts.map +1 -1
  5. package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js +18 -2
  6. package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js.map +1 -1
  7. package/dist/src/core/repo-structure/git-error-handler.d.ts +1 -1
  8. package/dist/src/core/repo-structure/git-error-handler.d.ts.map +1 -1
  9. package/dist/src/core/repo-structure/git-provider.d.ts +1 -1
  10. package/dist/src/core/repo-structure/git-provider.d.ts.map +1 -1
  11. package/dist/src/core/repo-structure/platform-registry.d.ts.map +1 -1
  12. package/dist/src/core/repo-structure/platform-registry.js +20 -9
  13. package/dist/src/core/repo-structure/platform-registry.js.map +1 -1
  14. package/dist/src/core/repo-structure/prompt-consolidator.d.ts +13 -1
  15. package/dist/src/core/repo-structure/prompt-consolidator.d.ts.map +1 -1
  16. package/dist/src/core/repo-structure/prompt-consolidator.js +38 -5
  17. package/dist/src/core/repo-structure/prompt-consolidator.js.map +1 -1
  18. package/dist/src/core/repo-structure/providers/azure-devops-provider.d.ts +64 -0
  19. package/dist/src/core/repo-structure/providers/azure-devops-provider.d.ts.map +1 -0
  20. package/dist/src/core/repo-structure/providers/azure-devops-provider.js +263 -0
  21. package/dist/src/core/repo-structure/providers/azure-devops-provider.js.map +1 -0
  22. package/dist/src/core/repo-structure/providers/bitbucket-provider.d.ts +12 -11
  23. package/dist/src/core/repo-structure/providers/bitbucket-provider.d.ts.map +1 -1
  24. package/dist/src/core/repo-structure/providers/bitbucket-provider.js +164 -30
  25. package/dist/src/core/repo-structure/providers/bitbucket-provider.js.map +1 -1
  26. package/dist/src/core/repo-structure/providers/gitlab-provider.d.ts +10 -9
  27. package/dist/src/core/repo-structure/providers/gitlab-provider.d.ts.map +1 -1
  28. package/dist/src/core/repo-structure/providers/gitlab-provider.js +182 -28
  29. package/dist/src/core/repo-structure/providers/gitlab-provider.js.map +1 -1
  30. package/dist/src/core/repo-structure/providers/index.d.ts +3 -1
  31. package/dist/src/core/repo-structure/providers/index.d.ts.map +1 -1
  32. package/dist/src/core/repo-structure/providers/index.js +10 -2
  33. package/dist/src/core/repo-structure/providers/index.js.map +1 -1
  34. package/dist/src/core/repo-structure/providers/local-provider.d.ts +61 -0
  35. package/dist/src/core/repo-structure/providers/local-provider.d.ts.map +1 -0
  36. package/dist/src/core/repo-structure/providers/local-provider.js +148 -0
  37. package/dist/src/core/repo-structure/providers/local-provider.js.map +1 -0
  38. package/dist/src/core/repo-structure/repo-structure-manager.d.ts +11 -1
  39. package/dist/src/core/repo-structure/repo-structure-manager.d.ts.map +1 -1
  40. package/dist/src/core/repo-structure/repo-structure-manager.js +268 -84
  41. package/dist/src/core/repo-structure/repo-structure-manager.js.map +1 -1
  42. package/package.json +1 -1
  43. package/plugins/specweave/agents/pm/AGENT.md.bak +1893 -0
  44. package/plugins/specweave/hooks/docs-changed.sh.backup +79 -0
  45. package/plugins/specweave/hooks/human-input-required.sh.backup +75 -0
  46. package/plugins/specweave/hooks/lib/migrate-increment-work.sh.bak +245 -0
  47. package/plugins/specweave/hooks/lib/sync-spec-content.sh.bak +149 -0
  48. package/plugins/specweave/hooks/lib/validate-spec-status.sh.bak +163 -0
  49. package/plugins/specweave/hooks/post-first-increment.sh.backup +61 -0
  50. package/plugins/specweave/hooks/post-first-increment.sh.bak +61 -0
  51. package/plugins/specweave/hooks/post-increment-change.sh.backup +98 -0
  52. package/plugins/specweave/hooks/post-increment-completion.sh.backup +231 -0
  53. package/plugins/specweave/hooks/post-increment-planning.sh.backup +1048 -0
  54. package/plugins/specweave/hooks/post-increment-status-change.sh.backup +147 -0
  55. package/plugins/specweave/hooks/post-spec-update.sh.backup +158 -0
  56. package/plugins/specweave/hooks/post-spec-update.sh.bak +158 -0
  57. package/plugins/specweave/hooks/post-task-completion.sh +69 -175
  58. package/plugins/specweave/hooks/post-user-story-complete.sh.backup +179 -0
  59. package/plugins/specweave/hooks/post-user-story-complete.sh.bak +179 -0
  60. package/plugins/specweave/hooks/pre-command-deduplication.sh.backup +83 -0
  61. package/plugins/specweave/hooks/pre-command-deduplication.sh.bak +83 -0
  62. package/plugins/specweave/hooks/pre-implementation.sh.backup +67 -0
  63. package/plugins/specweave/hooks/pre-task-completion.sh.backup +194 -0
  64. package/plugins/specweave/hooks/pre-tool-use.sh.backup +133 -0
  65. package/plugins/specweave/hooks/user-prompt-submit.sh.backup +386 -0
  66. package/plugins/specweave/hooks/user-prompt-submit.sh.bak +386 -0
  67. package/plugins/specweave/lib/hooks/auto-transition.js.bak +50 -0
  68. package/plugins/specweave/lib/hooks/auto-transition.ts.bak +84 -0
  69. package/plugins/specweave/lib/hooks/consolidated-sync.js +183 -0
  70. package/plugins/specweave/lib/hooks/git-diff-analyzer.d.js.bak +0 -0
  71. package/plugins/specweave/lib/hooks/git-diff-analyzer.d.ts.bak +89 -0
  72. package/plugins/specweave/lib/hooks/git-diff-analyzer.js.bak +142 -0
  73. package/plugins/specweave/lib/hooks/git-diff-analyzer.ts.bak +269 -0
  74. package/plugins/specweave/lib/hooks/invoke-translator-skill.d.js.bak +0 -0
  75. package/plugins/specweave/lib/hooks/invoke-translator-skill.d.ts.bak +60 -0
  76. package/plugins/specweave/lib/hooks/invoke-translator-skill.js.bak +155 -0
  77. package/plugins/specweave/lib/hooks/invoke-translator-skill.ts.bak +264 -0
  78. package/plugins/specweave/lib/hooks/prepare-reflection-context.d.js.bak +0 -0
  79. package/plugins/specweave/lib/hooks/prepare-reflection-context.d.ts.bak +42 -0
  80. package/plugins/specweave/lib/hooks/prepare-reflection-context.js.bak +110 -0
  81. package/plugins/specweave/lib/hooks/prepare-reflection-context.ts.bak +178 -0
  82. package/plugins/specweave/lib/hooks/reflection-config-loader.d.js.bak +0 -0
  83. package/plugins/specweave/lib/hooks/reflection-config-loader.d.ts.bak +45 -0
  84. package/plugins/specweave/lib/hooks/reflection-config-loader.js.bak +92 -0
  85. package/plugins/specweave/lib/hooks/reflection-config-loader.ts.bak +156 -0
  86. package/plugins/specweave/lib/hooks/reflection-parser.d.js.bak +0 -0
  87. package/plugins/specweave/lib/hooks/reflection-parser.d.ts.bak +33 -0
  88. package/plugins/specweave/lib/hooks/reflection-parser.js.bak +301 -0
  89. package/plugins/specweave/lib/hooks/reflection-parser.ts.bak +484 -0
  90. package/plugins/specweave/lib/hooks/reflection-prompt-builder.d.js.bak +0 -0
  91. package/plugins/specweave/lib/hooks/reflection-prompt-builder.d.ts.bak +56 -0
  92. package/plugins/specweave/lib/hooks/reflection-prompt-builder.js.bak +182 -0
  93. package/plugins/specweave/lib/hooks/reflection-prompt-builder.ts.bak +306 -0
  94. package/plugins/specweave/lib/hooks/reflection-storage.d.js.bak +0 -0
  95. package/plugins/specweave/lib/hooks/reflection-storage.d.ts.bak +64 -0
  96. package/plugins/specweave/lib/hooks/reflection-storage.js.bak +231 -0
  97. package/plugins/specweave/lib/hooks/reflection-storage.ts.bak +369 -0
  98. package/plugins/specweave/lib/hooks/run-self-reflection.d.js.bak +0 -0
  99. package/plugins/specweave/lib/hooks/run-self-reflection.d.ts.bak +43 -0
  100. package/plugins/specweave/lib/hooks/run-self-reflection.js.bak +132 -0
  101. package/plugins/specweave/lib/hooks/run-self-reflection.ts.bak +258 -0
  102. package/plugins/specweave/lib/hooks/sync-cache.js.bak +294 -0
  103. package/plugins/specweave/lib/hooks/sync-living-docs.d.js.bak +1 -0
  104. package/plugins/specweave/lib/hooks/sync-living-docs.d.ts.bak +27 -0
  105. package/plugins/specweave/lib/hooks/sync-living-docs.js.bak +339 -0
  106. package/plugins/specweave/lib/hooks/sync-us-tasks.js.bak +476 -0
  107. package/plugins/specweave/lib/hooks/translate-file.d.js.bak +0 -0
  108. package/plugins/specweave/lib/hooks/translate-file.d.ts.bak +59 -0
  109. package/plugins/specweave/lib/hooks/translate-file.js.bak +289 -0
  110. package/plugins/specweave/lib/hooks/translate-file.ts.bak +428 -0
  111. package/plugins/specweave/lib/hooks/translate-living-docs.d.js.bak +0 -0
  112. package/plugins/specweave/lib/hooks/translate-living-docs.d.ts.bak +13 -0
  113. package/plugins/specweave/lib/hooks/translate-living-docs.js.bak +119 -0
  114. package/plugins/specweave/lib/hooks/translate-living-docs.ts.bak +224 -0
  115. package/plugins/specweave/lib/hooks/update-ac-status.js.bak +51 -0
  116. package/plugins/specweave/lib/hooks/update-ac-status.ts.bak +103 -0
  117. package/plugins/specweave/lib/hooks/update-tasks-md.d.js.bak +1 -0
  118. package/plugins/specweave/lib/hooks/update-tasks-md.d.ts.bak +29 -0
  119. package/plugins/specweave/lib/hooks/update-tasks-md.js.bak +296 -0
  120. package/plugins/specweave/lib/hooks/update-tasks-md.ts.bak +489 -0
  121. package/plugins/specweave-ado/hooks/post-living-docs-update.sh.backup +353 -0
  122. package/plugins/specweave-ado/hooks/post-task-completion.sh.backup +172 -0
  123. package/plugins/specweave-ado/lib/ado-multi-project-sync.js +1 -0
  124. package/plugins/specweave-ado/lib/enhanced-ado-sync.js +170 -0
  125. package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +424 -0
  126. package/plugins/specweave-github/hooks/post-task-completion.sh.backup +258 -0
  127. package/plugins/specweave-jira/hooks/post-task-completion.sh.backup +172 -0
  128. package/plugins/specweave-jira/lib/enhanced-jira-sync.js +3 -3
  129. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +540 -0
  130. package/plugins/specweave-release/hooks/post-task-completion.sh.backup +110 -0
@@ -0,0 +1,182 @@
1
+ import { ReflectionDepth } from "./types/reflection-types";
2
+ function buildAnalysisInstructions(config) {
3
+ const { depth, categories } = config;
4
+ const instructions = [];
5
+ switch (depth) {
6
+ case ReflectionDepth.QUICK:
7
+ instructions.push("**Analysis Mode**: QUICK (<15s)");
8
+ instructions.push("- Focus on CRITICAL and HIGH severity issues only");
9
+ instructions.push("- Skip lessons learned section");
10
+ instructions.push("- Provide concise feedback (1-2 sentences per issue)");
11
+ break;
12
+ case ReflectionDepth.STANDARD:
13
+ instructions.push("**Analysis Mode**: STANDARD (<30s)");
14
+ instructions.push("- Full analysis across all enabled categories");
15
+ instructions.push("- Include lessons learned");
16
+ instructions.push("- Provide actionable feedback with code examples");
17
+ break;
18
+ case ReflectionDepth.DEEP:
19
+ instructions.push("**Analysis Mode**: DEEP (<60s)");
20
+ instructions.push("- Comprehensive analysis with detailed explanations");
21
+ instructions.push("- Include architectural recommendations");
22
+ instructions.push("- Suggest refactoring opportunities");
23
+ instructions.push("- Analyze code metrics (complexity, coupling, cohesion)");
24
+ break;
25
+ }
26
+ instructions.push("");
27
+ instructions.push("**Enabled Analysis Categories**:");
28
+ if (categories.security) {
29
+ instructions.push("- \u2705 **Security**: OWASP Top 10 vulnerabilities (SQL injection, XSS, secrets, etc.)");
30
+ }
31
+ if (categories.quality) {
32
+ instructions.push("- \u2705 **Quality**: Code duplication, complexity, error handling, naming conventions");
33
+ }
34
+ if (categories.testing) {
35
+ instructions.push("- \u2705 **Testing**: Edge cases, error paths, integration/E2E coverage");
36
+ }
37
+ if (categories.performance) {
38
+ instructions.push("- \u2705 **Performance**: N+1 queries, algorithmic complexity, caching opportunities");
39
+ }
40
+ if (categories.technicalDebt) {
41
+ instructions.push("- \u2705 **Technical Debt**: TODOs, deprecated APIs, temporary hacks");
42
+ }
43
+ return instructions.join("\n");
44
+ }
45
+ function buildFileContext(modifiedFiles, includeFullDiff = false) {
46
+ const context = [];
47
+ context.push("## Modified Files Context");
48
+ context.push("");
49
+ context.push(`**Files Changed**: ${modifiedFiles.length}`);
50
+ const totalAdded = modifiedFiles.reduce((sum, f) => sum + f.linesAdded, 0);
51
+ const totalRemoved = modifiedFiles.reduce((sum, f) => sum + f.linesRemoved, 0);
52
+ context.push(`**Lines Added**: +${totalAdded}`);
53
+ context.push(`**Lines Removed**: -${totalRemoved}`);
54
+ context.push("");
55
+ context.push("### File Summary");
56
+ context.push("");
57
+ for (const file of modifiedFiles) {
58
+ context.push(`- \`${file.file}\`: +${file.linesAdded} -${file.linesRemoved}`);
59
+ }
60
+ context.push("");
61
+ if (includeFullDiff) {
62
+ context.push("### Detailed Changes");
63
+ context.push("");
64
+ for (const file of modifiedFiles) {
65
+ context.push(`#### ${file.file}`);
66
+ context.push("");
67
+ context.push("```diff");
68
+ const diffLines = file.content.split("\n").slice(0, 100);
69
+ context.push(diffLines.join("\n"));
70
+ if (file.content.split("\n").length > 100) {
71
+ context.push("... (diff truncated)");
72
+ }
73
+ context.push("```");
74
+ context.push("");
75
+ }
76
+ }
77
+ return context.join("\n");
78
+ }
79
+ function buildTaskContext(taskId, taskName) {
80
+ const context = [];
81
+ context.push("## Task Information");
82
+ context.push("");
83
+ context.push(`**Task ID**: ${taskId}`);
84
+ if (taskName) {
85
+ context.push(`**Task Name**: ${taskName}`);
86
+ }
87
+ context.push("");
88
+ return context.join("\n");
89
+ }
90
+ function buildReflectionPrompt(options) {
91
+ const {
92
+ taskId,
93
+ taskName,
94
+ modifiedFiles,
95
+ config,
96
+ incrementId,
97
+ includeFullDiff = false
98
+ } = options;
99
+ const sections = [];
100
+ sections.push("# Self-Reflection Request");
101
+ sections.push("");
102
+ sections.push("You are a senior software engineer performing self-reflection on recently completed work.");
103
+ sections.push("Analyze the following code changes and provide comprehensive, actionable feedback.");
104
+ sections.push("");
105
+ sections.push(buildTaskContext(taskId, taskName));
106
+ if (incrementId) {
107
+ sections.push(`**Increment**: ${incrementId}`);
108
+ sections.push("");
109
+ }
110
+ sections.push("---");
111
+ sections.push("");
112
+ sections.push(buildAnalysisInstructions(config));
113
+ sections.push("");
114
+ sections.push("---");
115
+ sections.push("");
116
+ sections.push(buildFileContext(modifiedFiles, includeFullDiff));
117
+ sections.push("---");
118
+ sections.push("");
119
+ sections.push("## Analysis Request");
120
+ sections.push("");
121
+ sections.push("Please analyze the modified files and provide a comprehensive self-reflection following the exact format specified in the reflective-reviewer agent documentation.");
122
+ sections.push("");
123
+ sections.push("**Required Sections**:");
124
+ sections.push("1. \u2705 What Was Accomplished");
125
+ sections.push("2. \u{1F3AF} Quality Assessment (Strengths + Issues)");
126
+ sections.push("3. \u{1F527} Recommended Follow-Up Actions (Priority 1/2/3)");
127
+ if (config.depth !== ReflectionDepth.QUICK) {
128
+ sections.push("4. \u{1F4DA} Lessons Learned");
129
+ sections.push("5. \u{1F4CA} Metrics (Code Quality, Security, Test Coverage, Technical Debt, Performance)");
130
+ }
131
+ sections.push("");
132
+ sections.push("**Critical Requirements**:");
133
+ sections.push("- \u2705 Be SPECIFIC: Always include file paths and line numbers");
134
+ sections.push("- \u2705 Be CONSTRUCTIVE: Provide code examples for fixes, not just criticism");
135
+ sections.push("- \u2705 Be ACTIONABLE: Every issue should have a clear next step");
136
+ sections.push("- \u2705 Be BALANCED: Mention both strengths and issues");
137
+ sections.push("- \u2705 Be HONEST: Don't sugarcoat issues, but acknowledge strengths");
138
+ sections.push("");
139
+ sections.push(`**Severity Threshold**: Flag issues with severity >= ${config.criticalThreshold}`);
140
+ sections.push("");
141
+ sections.push("---");
142
+ sections.push("");
143
+ sections.push("**Please provide your self-reflection analysis now.**");
144
+ return sections.join("\n");
145
+ }
146
+ function estimatePromptTokens(prompt) {
147
+ return Math.ceil(prompt.length / 4);
148
+ }
149
+ function truncateModifiedFiles(modifiedFiles, maxTokens = 8e3) {
150
+ const maxChars = maxTokens * 4;
151
+ let currentChars = 0;
152
+ const truncated = [];
153
+ for (const file of modifiedFiles) {
154
+ const fileChars = file.content.length + file.file.length + 50;
155
+ if (currentChars + fileChars > maxChars) {
156
+ const remainingChars = maxChars - currentChars;
157
+ if (remainingChars > 200) {
158
+ const truncatedContent = file.content.slice(0, remainingChars - 50) + "\n... (diff truncated)";
159
+ truncated.push({
160
+ ...file,
161
+ content: truncatedContent
162
+ });
163
+ }
164
+ break;
165
+ }
166
+ truncated.push(file);
167
+ currentChars += fileChars;
168
+ }
169
+ return truncated;
170
+ }
171
+ function buildSimplifiedPrompt(options) {
172
+ return buildReflectionPrompt({
173
+ ...options,
174
+ includeFullDiff: false
175
+ });
176
+ }
177
+ export {
178
+ buildReflectionPrompt,
179
+ buildSimplifiedPrompt,
180
+ estimatePromptTokens,
181
+ truncateModifiedFiles
182
+ };
@@ -0,0 +1,306 @@
1
+ /**
2
+ * Reflection Prompt Builder
3
+ *
4
+ * Builds comprehensive prompts for the reflective-reviewer agent
5
+ * Includes modified files context, configuration, task information
6
+ *
7
+ * @module reflection-prompt-builder
8
+ */
9
+
10
+ import { ReflectionConfig, ReflectionDepth, GitDiffInfo } from './types/reflection-types';
11
+
12
+ /**
13
+ * Build analysis instructions based on configuration
14
+ * @param config Reflection configuration
15
+ * @returns Markdown-formatted analysis instructions
16
+ */
17
+ function buildAnalysisInstructions(config: ReflectionConfig): string {
18
+ const { depth, categories } = config;
19
+
20
+ const instructions: string[] = [];
21
+
22
+ // Depth-specific instructions
23
+ switch (depth) {
24
+ case ReflectionDepth.QUICK:
25
+ instructions.push('**Analysis Mode**: QUICK (<15s)');
26
+ instructions.push('- Focus on CRITICAL and HIGH severity issues only');
27
+ instructions.push('- Skip lessons learned section');
28
+ instructions.push('- Provide concise feedback (1-2 sentences per issue)');
29
+ break;
30
+
31
+ case ReflectionDepth.STANDARD:
32
+ instructions.push('**Analysis Mode**: STANDARD (<30s)');
33
+ instructions.push('- Full analysis across all enabled categories');
34
+ instructions.push('- Include lessons learned');
35
+ instructions.push('- Provide actionable feedback with code examples');
36
+ break;
37
+
38
+ case ReflectionDepth.DEEP:
39
+ instructions.push('**Analysis Mode**: DEEP (<60s)');
40
+ instructions.push('- Comprehensive analysis with detailed explanations');
41
+ instructions.push('- Include architectural recommendations');
42
+ instructions.push('- Suggest refactoring opportunities');
43
+ instructions.push('- Analyze code metrics (complexity, coupling, cohesion)');
44
+ break;
45
+ }
46
+
47
+ instructions.push('');
48
+ instructions.push('**Enabled Analysis Categories**:');
49
+
50
+ // Category-specific instructions
51
+ if (categories.security) {
52
+ instructions.push('- ✅ **Security**: OWASP Top 10 vulnerabilities (SQL injection, XSS, secrets, etc.)');
53
+ }
54
+ if (categories.quality) {
55
+ instructions.push('- ✅ **Quality**: Code duplication, complexity, error handling, naming conventions');
56
+ }
57
+ if (categories.testing) {
58
+ instructions.push('- ✅ **Testing**: Edge cases, error paths, integration/E2E coverage');
59
+ }
60
+ if (categories.performance) {
61
+ instructions.push('- ✅ **Performance**: N+1 queries, algorithmic complexity, caching opportunities');
62
+ }
63
+ if (categories.technicalDebt) {
64
+ instructions.push('- ✅ **Technical Debt**: TODOs, deprecated APIs, temporary hacks');
65
+ }
66
+
67
+ return instructions.join('\n');
68
+ }
69
+
70
+ /**
71
+ * Build file context section with modified files
72
+ * @param modifiedFiles Array of modified files
73
+ * @param includeFullDiff Whether to include full diff content (default: false for large changes)
74
+ * @returns Markdown-formatted file context
75
+ */
76
+ function buildFileContext(
77
+ modifiedFiles: GitDiffInfo[],
78
+ includeFullDiff: boolean = false
79
+ ): string {
80
+ const context: string[] = [];
81
+
82
+ context.push('## Modified Files Context');
83
+ context.push('');
84
+ context.push(`**Files Changed**: ${modifiedFiles.length}`);
85
+
86
+ const totalAdded = modifiedFiles.reduce((sum, f) => sum + f.linesAdded, 0);
87
+ const totalRemoved = modifiedFiles.reduce((sum, f) => sum + f.linesRemoved, 0);
88
+
89
+ context.push(`**Lines Added**: +${totalAdded}`);
90
+ context.push(`**Lines Removed**: -${totalRemoved}`);
91
+ context.push('');
92
+
93
+ // List all modified files with stats
94
+ context.push('### File Summary');
95
+ context.push('');
96
+ for (const file of modifiedFiles) {
97
+ context.push(`- \`${file.file}\`: +${file.linesAdded} -${file.linesRemoved}`);
98
+ }
99
+ context.push('');
100
+
101
+ // Include diff content if requested and not too large
102
+ if (includeFullDiff) {
103
+ context.push('### Detailed Changes');
104
+ context.push('');
105
+
106
+ for (const file of modifiedFiles) {
107
+ context.push(`#### ${file.file}`);
108
+ context.push('');
109
+ context.push('```diff');
110
+ // Truncate very large diffs (max 100 lines per file)
111
+ const diffLines = file.content.split('\n').slice(0, 100);
112
+ context.push(diffLines.join('\n'));
113
+ if (file.content.split('\n').length > 100) {
114
+ context.push('... (diff truncated)');
115
+ }
116
+ context.push('```');
117
+ context.push('');
118
+ }
119
+ }
120
+
121
+ return context.join('\n');
122
+ }
123
+
124
+ /**
125
+ * Build task information section
126
+ * @param taskId Task identifier (e.g., "T-005")
127
+ * @param taskName Human-readable task name
128
+ * @returns Markdown-formatted task context
129
+ */
130
+ function buildTaskContext(taskId: string, taskName?: string): string {
131
+ const context: string[] = [];
132
+
133
+ context.push('## Task Information');
134
+ context.push('');
135
+ context.push(`**Task ID**: ${taskId}`);
136
+
137
+ if (taskName) {
138
+ context.push(`**Task Name**: ${taskName}`);
139
+ }
140
+
141
+ context.push('');
142
+
143
+ return context.join('\n');
144
+ }
145
+
146
+ /**
147
+ * Build the complete reflection prompt
148
+ * Main function for creating agent prompts
149
+ *
150
+ * @param options Prompt options
151
+ * @returns Complete markdown-formatted prompt for reflective-reviewer agent
152
+ */
153
+ export function buildReflectionPrompt(options: {
154
+ taskId: string;
155
+ taskName?: string;
156
+ modifiedFiles: GitDiffInfo[];
157
+ config: ReflectionConfig;
158
+ incrementId?: string;
159
+ includeFullDiff?: boolean;
160
+ }): string {
161
+ const {
162
+ taskId,
163
+ taskName,
164
+ modifiedFiles,
165
+ config,
166
+ incrementId,
167
+ includeFullDiff = false
168
+ } = options;
169
+
170
+ const sections: string[] = [];
171
+
172
+ // Header
173
+ sections.push('# Self-Reflection Request');
174
+ sections.push('');
175
+ sections.push('You are a senior software engineer performing self-reflection on recently completed work.');
176
+ sections.push('Analyze the following code changes and provide comprehensive, actionable feedback.');
177
+ sections.push('');
178
+
179
+ // Task context
180
+ sections.push(buildTaskContext(taskId, taskName));
181
+
182
+ // Increment context (if provided)
183
+ if (incrementId) {
184
+ sections.push(`**Increment**: ${incrementId}`);
185
+ sections.push('');
186
+ }
187
+
188
+ // Analysis instructions
189
+ sections.push('---');
190
+ sections.push('');
191
+ sections.push(buildAnalysisInstructions(config));
192
+ sections.push('');
193
+
194
+ // File context
195
+ sections.push('---');
196
+ sections.push('');
197
+ sections.push(buildFileContext(modifiedFiles, includeFullDiff));
198
+
199
+ // Analysis request
200
+ sections.push('---');
201
+ sections.push('');
202
+ sections.push('## Analysis Request');
203
+ sections.push('');
204
+ sections.push('Please analyze the modified files and provide a comprehensive self-reflection following the exact format specified in the reflective-reviewer agent documentation.');
205
+ sections.push('');
206
+ sections.push('**Required Sections**:');
207
+ sections.push('1. ✅ What Was Accomplished');
208
+ sections.push('2. 🎯 Quality Assessment (Strengths + Issues)');
209
+ sections.push('3. 🔧 Recommended Follow-Up Actions (Priority 1/2/3)');
210
+
211
+ if (config.depth !== ReflectionDepth.QUICK) {
212
+ sections.push('4. 📚 Lessons Learned');
213
+ sections.push('5. 📊 Metrics (Code Quality, Security, Test Coverage, Technical Debt, Performance)');
214
+ }
215
+
216
+ sections.push('');
217
+ sections.push('**Critical Requirements**:');
218
+ sections.push('- ✅ Be SPECIFIC: Always include file paths and line numbers');
219
+ sections.push('- ✅ Be CONSTRUCTIVE: Provide code examples for fixes, not just criticism');
220
+ sections.push('- ✅ Be ACTIONABLE: Every issue should have a clear next step');
221
+ sections.push('- ✅ Be BALANCED: Mention both strengths and issues');
222
+ sections.push('- ✅ Be HONEST: Don\'t sugarcoat issues, but acknowledge strengths');
223
+
224
+ sections.push('');
225
+ sections.push(`**Severity Threshold**: Flag issues with severity >= ${config.criticalThreshold}`);
226
+
227
+ sections.push('');
228
+ sections.push('---');
229
+ sections.push('');
230
+ sections.push('**Please provide your self-reflection analysis now.**');
231
+
232
+ return sections.join('\n');
233
+ }
234
+
235
+ /**
236
+ * Estimate token count for prompt (rough approximation)
237
+ * Used for cost estimation
238
+ *
239
+ * @param prompt Reflection prompt
240
+ * @returns Estimated token count (1 token ≈ 4 characters)
241
+ */
242
+ export function estimatePromptTokens(prompt: string): number {
243
+ // Rough approximation: 1 token ≈ 4 characters
244
+ return Math.ceil(prompt.length / 4);
245
+ }
246
+
247
+ /**
248
+ * Truncate large diffs to fit within token budget
249
+ * Preserves most recent changes (bottom of diff)
250
+ *
251
+ * @param modifiedFiles Array of modified files
252
+ * @param maxTokens Maximum tokens to use (default: 8000)
253
+ * @returns Truncated array of modified files
254
+ */
255
+ export function truncateModifiedFiles(
256
+ modifiedFiles: GitDiffInfo[],
257
+ maxTokens: number = 8000
258
+ ): GitDiffInfo[] {
259
+ const maxChars = maxTokens * 4; // Approximate token-to-char ratio
260
+ let currentChars = 0;
261
+ const truncated: GitDiffInfo[] = [];
262
+
263
+ for (const file of modifiedFiles) {
264
+ const fileChars = file.content.length + file.file.length + 50; // File metadata
265
+
266
+ if (currentChars + fileChars > maxChars) {
267
+ // Truncate this file's diff
268
+ const remainingChars = maxChars - currentChars;
269
+ if (remainingChars > 200) {
270
+ // Only include if we can show at least 200 chars
271
+ const truncatedContent = file.content.slice(0, remainingChars - 50) + '\n... (diff truncated)';
272
+ truncated.push({
273
+ ...file,
274
+ content: truncatedContent
275
+ });
276
+ }
277
+ break;
278
+ }
279
+
280
+ truncated.push(file);
281
+ currentChars += fileChars;
282
+ }
283
+
284
+ return truncated;
285
+ }
286
+
287
+ /**
288
+ * Build a simplified prompt for very large changes
289
+ * Used when full diff exceeds reasonable token budget
290
+ *
291
+ * @param options Prompt options (same as buildReflectionPrompt)
292
+ * @returns Simplified prompt with file list only (no diffs)
293
+ */
294
+ export function buildSimplifiedPrompt(options: {
295
+ taskId: string;
296
+ taskName?: string;
297
+ modifiedFiles: GitDiffInfo[];
298
+ config: ReflectionConfig;
299
+ incrementId?: string;
300
+ }): string {
301
+ // Build prompt without full diff content
302
+ return buildReflectionPrompt({
303
+ ...options,
304
+ includeFullDiff: false
305
+ });
306
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Reflection Storage Manager
3
+ *
4
+ * Writes reflection results to markdown files in increment logs
5
+ * Stores reflections in .specweave/increments/{id}/logs/reflections/
6
+ *
7
+ * @module reflection-storage
8
+ */
9
+ import { ReflectionResult } from './types/reflection-types';
10
+ /**
11
+ * Generate markdown content from reflection result
12
+ * Follows the exact format specified in reflective-reviewer agent
13
+ *
14
+ * @param result Reflection result object
15
+ * @returns Markdown-formatted reflection content
16
+ */
17
+ export declare function generateReflectionMarkdown(result: ReflectionResult): string;
18
+ /**
19
+ * Get reflection log directory for an increment
20
+ * @param incrementId Increment identifier (e.g., "0016-self-reflection-system")
21
+ * @param projectRoot Project root directory (optional, auto-detected if not provided)
22
+ * @returns Path to reflection logs directory
23
+ */
24
+ export declare function getReflectionLogDir(incrementId: string, projectRoot?: string): string;
25
+ /**
26
+ * Generate filename for reflection log
27
+ * @param taskId Task identifier (e.g., "T-005")
28
+ * @param timestamp Optional timestamp (defaults to current date)
29
+ * @returns Filename (e.g., "task-T-005-reflection-2025-11-10.md")
30
+ */
31
+ export declare function getReflectionFilename(taskId: string, timestamp?: Date): string;
32
+ /**
33
+ * Save reflection result to markdown file
34
+ * Creates directory structure if it doesn't exist
35
+ *
36
+ * @param result Reflection result to save
37
+ * @param incrementId Increment identifier
38
+ * @param taskId Task identifier
39
+ * @param projectRoot Project root directory (optional)
40
+ * @returns Path to saved reflection file
41
+ * @throws Error if file cannot be written
42
+ */
43
+ export declare function saveReflection(result: ReflectionResult, incrementId: string, taskId: string, projectRoot?: string): string;
44
+ /**
45
+ * List all reflection files for an increment
46
+ * @param incrementId Increment identifier
47
+ * @param projectRoot Project root directory (optional)
48
+ * @returns Array of reflection file paths (sorted by date, newest first)
49
+ */
50
+ export declare function listReflections(incrementId: string, projectRoot?: string): string[];
51
+ /**
52
+ * Read reflection from file
53
+ * @param filepath Path to reflection markdown file
54
+ * @returns Markdown content as string
55
+ * @throws Error if file cannot be read
56
+ */
57
+ export declare function readReflection(filepath: string): string;
58
+ /**
59
+ * Delete reflection file
60
+ * @param filepath Path to reflection markdown file
61
+ * @throws Error if file cannot be deleted
62
+ */
63
+ export declare function deleteReflection(filepath: string): void;
64
+ //# sourceMappingURL=reflection-storage.d.ts.map