specweave 0.26.2 → 0.26.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +172 -1413
- package/dist/src/cli/commands/plan/plan-orchestrator.js +2 -2
- package/dist/src/cli/commands/plan/plan-orchestrator.js.map +1 -1
- package/dist/src/cli/helpers/issue-tracker/github-multi-repo.d.ts.map +1 -1
- package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js +147 -55
- package/dist/src/cli/helpers/issue-tracker/github-multi-repo.js.map +1 -1
- package/dist/src/core/increment/completion-validator.d.ts +4 -0
- package/dist/src/core/increment/completion-validator.d.ts.map +1 -1
- package/dist/src/core/increment/completion-validator.js +36 -0
- package/dist/src/core/increment/completion-validator.js.map +1 -1
- package/dist/src/core/living-docs/living-docs-sync.d.ts.map +1 -1
- package/dist/src/core/living-docs/living-docs-sync.js +47 -13
- package/dist/src/core/living-docs/living-docs-sync.js.map +1 -1
- package/dist/src/core/us-sync-throttle.d.ts +113 -0
- package/dist/src/core/us-sync-throttle.d.ts.map +1 -0
- package/dist/src/core/us-sync-throttle.js +195 -0
- package/dist/src/core/us-sync-throttle.js.map +1 -0
- package/dist/src/utils/external-tool-drift-detector.d.ts +76 -0
- package/dist/src/utils/external-tool-drift-detector.d.ts.map +1 -0
- package/dist/src/utils/external-tool-drift-detector.js +235 -0
- package/dist/src/utils/external-tool-drift-detector.js.map +1 -0
- package/package.json +4 -4
- package/plugins/specweave/hooks/post-task-completion.sh +6 -6
- package/plugins/specweave/hooks/pre-increment-start.sh +6 -1
- package/plugins/specweave/lib/hooks/us-completion-orchestrator.js +62 -89
- package/plugins/specweave/lib/hooks/us-completion-orchestrator.ts +215 -0
- package/plugins/specweave-ado/lib/ado-multi-project-sync.js +0 -1
- package/plugins/specweave-jira/lib/enhanced-jira-sync.js +3 -3
- package/plugins/specweave-release/hooks/post-task-completion.sh +5 -1
- package/plugins/specweave/agents/pm/AGENT.md.bak +0 -1893
- package/plugins/specweave/hooks/docs-changed.sh.backup +0 -79
- package/plugins/specweave/hooks/human-input-required.sh.backup +0 -75
- package/plugins/specweave/hooks/lib/migrate-increment-work.sh.bak +0 -245
- package/plugins/specweave/hooks/lib/sync-spec-content.sh.bak +0 -149
- package/plugins/specweave/hooks/lib/validate-spec-status.sh.bak +0 -163
- package/plugins/specweave/hooks/post-first-increment.sh.backup +0 -61
- package/plugins/specweave/hooks/post-first-increment.sh.bak +0 -61
- package/plugins/specweave/hooks/post-increment-change.sh.backup +0 -98
- package/plugins/specweave/hooks/post-increment-completion.sh.backup +0 -231
- package/plugins/specweave/hooks/post-increment-planning.sh.backup +0 -1048
- package/plugins/specweave/hooks/post-increment-status-change.sh.backup +0 -147
- package/plugins/specweave/hooks/post-spec-update.sh.backup +0 -158
- package/plugins/specweave/hooks/post-spec-update.sh.bak +0 -158
- package/plugins/specweave/hooks/post-user-story-complete.sh.backup +0 -179
- package/plugins/specweave/hooks/post-user-story-complete.sh.bak +0 -179
- package/plugins/specweave/hooks/pre-command-deduplication.sh.backup +0 -83
- package/plugins/specweave/hooks/pre-command-deduplication.sh.bak +0 -83
- package/plugins/specweave/hooks/pre-implementation.sh.backup +0 -67
- package/plugins/specweave/hooks/pre-task-completion.sh.backup +0 -194
- package/plugins/specweave/hooks/pre-tool-use.sh.backup +0 -133
- package/plugins/specweave/hooks/user-prompt-submit.sh.backup +0 -386
- package/plugins/specweave/hooks/user-prompt-submit.sh.bak +0 -386
- package/plugins/specweave/lib/hooks/auto-transition.js.bak +0 -50
- package/plugins/specweave/lib/hooks/auto-transition.ts.bak +0 -84
- package/plugins/specweave/lib/hooks/git-diff-analyzer.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/git-diff-analyzer.d.ts.bak +0 -89
- package/plugins/specweave/lib/hooks/git-diff-analyzer.js.bak +0 -142
- package/plugins/specweave/lib/hooks/git-diff-analyzer.ts.bak +0 -269
- package/plugins/specweave/lib/hooks/invoke-translator-skill.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/invoke-translator-skill.d.ts.bak +0 -60
- package/plugins/specweave/lib/hooks/invoke-translator-skill.js.bak +0 -155
- package/plugins/specweave/lib/hooks/invoke-translator-skill.ts.bak +0 -264
- package/plugins/specweave/lib/hooks/prepare-reflection-context.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/prepare-reflection-context.d.ts.bak +0 -42
- package/plugins/specweave/lib/hooks/prepare-reflection-context.js.bak +0 -110
- package/plugins/specweave/lib/hooks/prepare-reflection-context.ts.bak +0 -178
- package/plugins/specweave/lib/hooks/reflection-config-loader.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-config-loader.d.ts.bak +0 -45
- package/plugins/specweave/lib/hooks/reflection-config-loader.js.bak +0 -92
- package/plugins/specweave/lib/hooks/reflection-config-loader.ts.bak +0 -156
- package/plugins/specweave/lib/hooks/reflection-parser.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-parser.d.ts.bak +0 -33
- package/plugins/specweave/lib/hooks/reflection-parser.js.bak +0 -301
- package/plugins/specweave/lib/hooks/reflection-parser.ts.bak +0 -484
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.d.ts.bak +0 -56
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.js.bak +0 -182
- package/plugins/specweave/lib/hooks/reflection-prompt-builder.ts.bak +0 -306
- package/plugins/specweave/lib/hooks/reflection-storage.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/reflection-storage.d.ts.bak +0 -64
- package/plugins/specweave/lib/hooks/reflection-storage.js.bak +0 -231
- package/plugins/specweave/lib/hooks/reflection-storage.ts.bak +0 -369
- package/plugins/specweave/lib/hooks/run-self-reflection.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/run-self-reflection.d.ts.bak +0 -43
- package/plugins/specweave/lib/hooks/run-self-reflection.js.bak +0 -132
- package/plugins/specweave/lib/hooks/run-self-reflection.ts.bak +0 -258
- package/plugins/specweave/lib/hooks/sync-cache.js.bak +0 -294
- package/plugins/specweave/lib/hooks/sync-living-docs.d.js.bak +0 -1
- package/plugins/specweave/lib/hooks/sync-living-docs.d.ts.bak +0 -27
- package/plugins/specweave/lib/hooks/sync-living-docs.js.bak +0 -339
- package/plugins/specweave/lib/hooks/sync-us-tasks.js.bak +0 -476
- package/plugins/specweave/lib/hooks/translate-file.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/translate-file.d.ts.bak +0 -59
- package/plugins/specweave/lib/hooks/translate-file.js.bak +0 -289
- package/plugins/specweave/lib/hooks/translate-file.ts.bak +0 -428
- package/plugins/specweave/lib/hooks/translate-living-docs.d.js.bak +0 -0
- package/plugins/specweave/lib/hooks/translate-living-docs.d.ts.bak +0 -13
- package/plugins/specweave/lib/hooks/translate-living-docs.js.bak +0 -119
- package/plugins/specweave/lib/hooks/translate-living-docs.ts.bak +0 -224
- package/plugins/specweave/lib/hooks/update-ac-status.js.bak +0 -51
- package/plugins/specweave/lib/hooks/update-ac-status.ts.bak +0 -103
- package/plugins/specweave/lib/hooks/update-tasks-md.d.js.bak +0 -1
- package/plugins/specweave/lib/hooks/update-tasks-md.d.ts.bak +0 -29
- package/plugins/specweave/lib/hooks/update-tasks-md.js.bak +0 -296
- package/plugins/specweave/lib/hooks/update-tasks-md.ts.bak +0 -489
- package/plugins/specweave-ado/hooks/post-living-docs-update.sh.backup +0 -353
- package/plugins/specweave-ado/hooks/post-task-completion.sh.backup +0 -172
- package/plugins/specweave-ado/lib/enhanced-ado-sync.js +0 -170
- package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +0 -904
- package/plugins/specweave-github/hooks/post-task-completion.sh.backup +0 -258
- package/plugins/specweave-jira/hooks/post-task-completion.sh.backup +0 -172
- package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +0 -738
- package/plugins/specweave-release/hooks/post-task-completion.sh.backup +0 -110
|
@@ -1,182 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,306 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|