ghcralph 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 (160) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +327 -0
  3. package/bin/ghcralph.js +2 -0
  4. package/dist/cli.d.ts +12 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +92 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/commands/config.d.ts +8 -0
  9. package/dist/commands/config.d.ts.map +1 -0
  10. package/dist/commands/config.js +118 -0
  11. package/dist/commands/config.js.map +1 -0
  12. package/dist/commands/index.d.ts +11 -0
  13. package/dist/commands/index.d.ts.map +1 -0
  14. package/dist/commands/index.js +11 -0
  15. package/dist/commands/index.js.map +1 -0
  16. package/dist/commands/init.d.ts +15 -0
  17. package/dist/commands/init.d.ts.map +1 -0
  18. package/dist/commands/init.js +116 -0
  19. package/dist/commands/init.js.map +1 -0
  20. package/dist/commands/rollback.d.ts +8 -0
  21. package/dist/commands/rollback.d.ts.map +1 -0
  22. package/dist/commands/rollback.js +238 -0
  23. package/dist/commands/rollback.js.map +1 -0
  24. package/dist/commands/run.d.ts +28 -0
  25. package/dist/commands/run.d.ts.map +1 -0
  26. package/dist/commands/run.js +407 -0
  27. package/dist/commands/run.js.map +1 -0
  28. package/dist/commands/status.d.ts +8 -0
  29. package/dist/commands/status.d.ts.map +1 -0
  30. package/dist/commands/status.js +399 -0
  31. package/dist/commands/status.js.map +1 -0
  32. package/dist/core/action-executor.d.ts +96 -0
  33. package/dist/core/action-executor.d.ts.map +1 -0
  34. package/dist/core/action-executor.js +289 -0
  35. package/dist/core/action-executor.js.map +1 -0
  36. package/dist/core/checkpoint-manager.d.ts +94 -0
  37. package/dist/core/checkpoint-manager.d.ts.map +1 -0
  38. package/dist/core/checkpoint-manager.js +236 -0
  39. package/dist/core/checkpoint-manager.js.map +1 -0
  40. package/dist/core/config-manager.d.ts +62 -0
  41. package/dist/core/config-manager.d.ts.map +1 -0
  42. package/dist/core/config-manager.js +184 -0
  43. package/dist/core/config-manager.js.map +1 -0
  44. package/dist/core/config-schema.d.ts +74 -0
  45. package/dist/core/config-schema.d.ts.map +1 -0
  46. package/dist/core/config-schema.js +84 -0
  47. package/dist/core/config-schema.js.map +1 -0
  48. package/dist/core/context-builder.d.ts +116 -0
  49. package/dist/core/context-builder.d.ts.map +1 -0
  50. package/dist/core/context-builder.js +388 -0
  51. package/dist/core/context-builder.js.map +1 -0
  52. package/dist/core/feedback-builder.d.ts +94 -0
  53. package/dist/core/feedback-builder.d.ts.map +1 -0
  54. package/dist/core/feedback-builder.js +226 -0
  55. package/dist/core/feedback-builder.js.map +1 -0
  56. package/dist/core/file-safeguard.d.ts +109 -0
  57. package/dist/core/file-safeguard.d.ts.map +1 -0
  58. package/dist/core/file-safeguard.js +200 -0
  59. package/dist/core/file-safeguard.js.map +1 -0
  60. package/dist/core/git-branch-manager.d.ts +122 -0
  61. package/dist/core/git-branch-manager.d.ts.map +1 -0
  62. package/dist/core/git-branch-manager.js +302 -0
  63. package/dist/core/git-branch-manager.js.map +1 -0
  64. package/dist/core/github-plan.d.ts +86 -0
  65. package/dist/core/github-plan.d.ts.map +1 -0
  66. package/dist/core/github-plan.js +333 -0
  67. package/dist/core/github-plan.js.map +1 -0
  68. package/dist/core/index.d.ts +43 -0
  69. package/dist/core/index.d.ts.map +1 -0
  70. package/dist/core/index.js +26 -0
  71. package/dist/core/index.js.map +1 -0
  72. package/dist/core/local-markdown-plan.d.ts +65 -0
  73. package/dist/core/local-markdown-plan.d.ts.map +1 -0
  74. package/dist/core/local-markdown-plan.js +154 -0
  75. package/dist/core/local-markdown-plan.js.map +1 -0
  76. package/dist/core/loop-engine.d.ts +133 -0
  77. package/dist/core/loop-engine.d.ts.map +1 -0
  78. package/dist/core/loop-engine.js +420 -0
  79. package/dist/core/loop-engine.js.map +1 -0
  80. package/dist/core/loop-events.d.ts +48 -0
  81. package/dist/core/loop-events.d.ts.map +1 -0
  82. package/dist/core/loop-events.js +24 -0
  83. package/dist/core/loop-events.js.map +1 -0
  84. package/dist/core/loop-state.d.ts +51 -0
  85. package/dist/core/loop-state.d.ts.map +1 -0
  86. package/dist/core/loop-state.js +48 -0
  87. package/dist/core/loop-state.js.map +1 -0
  88. package/dist/core/markdown-parser.d.ts +51 -0
  89. package/dist/core/markdown-parser.d.ts.map +1 -0
  90. package/dist/core/markdown-parser.js +122 -0
  91. package/dist/core/markdown-parser.js.map +1 -0
  92. package/dist/core/plan-manager.d.ts +61 -0
  93. package/dist/core/plan-manager.d.ts.map +1 -0
  94. package/dist/core/plan-manager.js +7 -0
  95. package/dist/core/plan-manager.js.map +1 -0
  96. package/dist/core/progress-tracker.d.ts +74 -0
  97. package/dist/core/progress-tracker.d.ts.map +1 -0
  98. package/dist/core/progress-tracker.js +198 -0
  99. package/dist/core/progress-tracker.js.map +1 -0
  100. package/dist/core/prompt-examples.d.ts +52 -0
  101. package/dist/core/prompt-examples.d.ts.map +1 -0
  102. package/dist/core/prompt-examples.js +194 -0
  103. package/dist/core/prompt-examples.js.map +1 -0
  104. package/dist/core/response-parser.d.ts +90 -0
  105. package/dist/core/response-parser.d.ts.map +1 -0
  106. package/dist/core/response-parser.js +209 -0
  107. package/dist/core/response-parser.js.map +1 -0
  108. package/dist/core/verification-hooks.d.ts +103 -0
  109. package/dist/core/verification-hooks.d.ts.map +1 -0
  110. package/dist/core/verification-hooks.js +268 -0
  111. package/dist/core/verification-hooks.js.map +1 -0
  112. package/dist/index.d.ts +13 -0
  113. package/dist/index.d.ts.map +1 -0
  114. package/dist/index.js +17 -0
  115. package/dist/index.js.map +1 -0
  116. package/dist/integrations/auth.d.ts +28 -0
  117. package/dist/integrations/auth.d.ts.map +1 -0
  118. package/dist/integrations/auth.js +76 -0
  119. package/dist/integrations/auth.js.map +1 -0
  120. package/dist/integrations/copilot-agent.d.ts +104 -0
  121. package/dist/integrations/copilot-agent.d.ts.map +1 -0
  122. package/dist/integrations/copilot-agent.js +235 -0
  123. package/dist/integrations/copilot-agent.js.map +1 -0
  124. package/dist/integrations/index.d.ts +18 -0
  125. package/dist/integrations/index.d.ts.map +1 -0
  126. package/dist/integrations/index.js +14 -0
  127. package/dist/integrations/index.js.map +1 -0
  128. package/dist/integrations/mcp-tools.d.ts +129 -0
  129. package/dist/integrations/mcp-tools.d.ts.map +1 -0
  130. package/dist/integrations/mcp-tools.js +272 -0
  131. package/dist/integrations/mcp-tools.js.map +1 -0
  132. package/dist/integrations/tokens.d.ts +45 -0
  133. package/dist/integrations/tokens.d.ts.map +1 -0
  134. package/dist/integrations/tokens.js +50 -0
  135. package/dist/integrations/tokens.js.map +1 -0
  136. package/dist/types/index.d.ts +53 -0
  137. package/dist/types/index.d.ts.map +1 -0
  138. package/dist/types/index.js +7 -0
  139. package/dist/types/index.js.map +1 -0
  140. package/dist/utils/index.d.ts +23 -0
  141. package/dist/utils/index.d.ts.map +1 -0
  142. package/dist/utils/index.js +37 -0
  143. package/dist/utils/index.js.map +1 -0
  144. package/dist/utils/output.d.ts +59 -0
  145. package/dist/utils/output.d.ts.map +1 -0
  146. package/dist/utils/output.js +96 -0
  147. package/dist/utils/output.js.map +1 -0
  148. package/dist/utils/paths.d.ts +34 -0
  149. package/dist/utils/paths.d.ts.map +1 -0
  150. package/dist/utils/paths.js +67 -0
  151. package/dist/utils/paths.js.map +1 -0
  152. package/dist/utils/shell.d.ts +26 -0
  153. package/dist/utils/shell.d.ts.map +1 -0
  154. package/dist/utils/shell.js +65 -0
  155. package/dist/utils/shell.js.map +1 -0
  156. package/dist/utils/validation.d.ts +27 -0
  157. package/dist/utils/validation.d.ts.map +1 -0
  158. package/dist/utils/validation.js +43 -0
  159. package/dist/utils/validation.js.map +1 -0
  160. package/package.json +86 -0
@@ -0,0 +1,388 @@
1
+ /**
2
+ * Context Builder
3
+ *
4
+ * Builds rich context for AI agent prompts including relevant files,
5
+ * git history, and previous iteration results.
6
+ */
7
+ import fs from 'node:fs/promises';
8
+ import path from 'node:path';
9
+ import { exec } from 'node:child_process';
10
+ import { promisify } from 'node:util';
11
+ import { glob } from 'glob';
12
+ import { debug, warn } from '../utils/index.js';
13
+ import { getExamplesForModel } from './prompt-examples.js';
14
+ const execAsync = promisify(exec);
15
+ /**
16
+ * Default Ralph prompt template (simplified per Ralph pattern)
17
+ * The {output_format} placeholder is replaced with model-appropriate examples
18
+ */
19
+ const DEFAULT_PROMPT_TEMPLATE = `You are an expert software engineer. Your task is: {task_title}
20
+
21
+ ## Task Description
22
+ {task_content}
23
+
24
+ {state_section}
25
+ {context_section}
26
+ {previous_progress}
27
+ {feedback_section}
28
+
29
+ {output_format}
30
+
31
+ ## Instructions
32
+ - Make small, focused changes
33
+ - Test your changes with [ACTION:EXECUTE]
34
+ - Use [ACTION:COMPLETE] when tests pass and task is done`;
35
+ /**
36
+ * Legacy prompt template with meta info (for backwards compatibility)
37
+ */
38
+ const LEGACY_PROMPT_TEMPLATE = `You are an expert software engineer. Your task is: {task_title}
39
+
40
+ ## Task Description
41
+ {task_content}
42
+
43
+ ## Current State
44
+ - Iteration: {iteration} of {max_iterations}
45
+ - Tokens used: {tokens_used} of {max_tokens}
46
+
47
+ {context_section}
48
+ {previous_progress}
49
+
50
+ ## Instructions
51
+ - Make small, focused changes
52
+ - Test your changes when possible
53
+ - Explain your reasoning
54
+ - Stop when the task is complete`;
55
+ /**
56
+ * Default context builder configuration
57
+ */
58
+ const DEFAULT_CONFIG = {
59
+ maxContextTokens: 8000,
60
+ includeGitDiff: true,
61
+ includeGitHistory: true,
62
+ gitHistoryLimit: 5,
63
+ includeProjectStructure: true,
64
+ freshContextPerIteration: true, // Ralph pattern: rely on filesystem, not history
65
+ includeMetaInfo: false, // Ralph pattern: don't include iteration/token counts
66
+ model: 'gpt-4.1', // Default model (0x cost multiplier)
67
+ };
68
+ /**
69
+ * Context builder for creating rich AI prompts
70
+ */
71
+ export class ContextBuilder {
72
+ config;
73
+ cwd;
74
+ constructor(config = {}, cwd) {
75
+ this.config = { ...DEFAULT_CONFIG, ...config };
76
+ this.cwd = cwd ?? process.cwd();
77
+ }
78
+ /**
79
+ * Build a complete context prompt for the current iteration
80
+ */
81
+ async buildContext(task, iteration, maxIterations, tokensUsed, maxTokens, previousIterations = [], feedbackSection) {
82
+ const filesIncluded = [];
83
+ let truncated = false;
84
+ // Select template based on configuration
85
+ let template;
86
+ if (this.config.promptTemplate) {
87
+ template = this.config.promptTemplate;
88
+ }
89
+ else if (this.config.includeMetaInfo) {
90
+ template = LEGACY_PROMPT_TEMPLATE;
91
+ }
92
+ else {
93
+ template = DEFAULT_PROMPT_TEMPLATE;
94
+ }
95
+ // Build context sections
96
+ const contextParts = [];
97
+ // 1. Add explicit context files first (highest priority)
98
+ if (this.config.contextGlobs && this.config.contextGlobs.length > 0) {
99
+ const explicitContext = await this.getExplicitContextFiles();
100
+ if (explicitContext.content) {
101
+ contextParts.push('## Relevant Files\n' + explicitContext.content);
102
+ filesIncluded.push(...explicitContext.files);
103
+ }
104
+ }
105
+ // 2. Add task-relevant files (based on keywords)
106
+ const keywordFiles = await this.findRelevantFiles(task);
107
+ if (keywordFiles.content && !this.exceedsTokenLimit(contextParts.join('\n'), keywordFiles.content)) {
108
+ contextParts.push(keywordFiles.content);
109
+ filesIncluded.push(...keywordFiles.files);
110
+ }
111
+ // 3. Add git diff (current changes) - CRITICAL for Ralph pattern
112
+ // This is the primary way the AI knows what has been done
113
+ if (this.config.includeGitDiff) {
114
+ const gitDiff = await this.getGitDiff();
115
+ if (gitDiff && !this.exceedsTokenLimit(contextParts.join('\n'), gitDiff)) {
116
+ contextParts.push('## Current Changes (git diff)\n```diff\n' + gitDiff + '\n```');
117
+ }
118
+ }
119
+ // 4. Add git history
120
+ if (this.config.includeGitHistory) {
121
+ const gitHistory = await this.getGitHistory();
122
+ if (gitHistory && !this.exceedsTokenLimit(contextParts.join('\n'), gitHistory)) {
123
+ contextParts.push('## Recent Git History\n' + gitHistory);
124
+ }
125
+ }
126
+ // 5. Add project structure overview
127
+ if (this.config.includeProjectStructure) {
128
+ const structure = await this.getProjectStructure();
129
+ if (structure && !this.exceedsTokenLimit(contextParts.join('\n'), structure)) {
130
+ contextParts.push('## Project Structure\n```\n' + structure + '\n```');
131
+ }
132
+ }
133
+ // Build previous progress section
134
+ // In fresh context mode (Ralph pattern), we skip this - rely on git diff instead
135
+ let previousProgress = '';
136
+ if (!this.config.freshContextPerIteration) {
137
+ previousProgress = this.buildPreviousProgress(previousIterations);
138
+ }
139
+ // Build state section (only if includeMetaInfo is true)
140
+ let stateSection = '';
141
+ if (this.config.includeMetaInfo) {
142
+ stateSection = `## Current State
143
+ - Iteration: ${iteration} of ${maxIterations}
144
+ - Tokens used: ${tokensUsed} of ${maxTokens}`;
145
+ }
146
+ // Build context section
147
+ const contextSection = contextParts.length > 0
148
+ ? '## Context\n' + contextParts.join('\n\n')
149
+ : '';
150
+ // Get model-appropriate output format examples
151
+ const outputFormat = getExamplesForModel(this.config.model ?? 'gpt-4.1');
152
+ // Build the final prompt
153
+ let prompt = template
154
+ .replace('{task_title}', task.title)
155
+ .replace('{task_content}', task.content)
156
+ .replace('{iteration}', String(iteration))
157
+ .replace('{max_iterations}', String(maxIterations))
158
+ .replace('{tokens_used}', String(tokensUsed))
159
+ .replace('{max_tokens}', String(maxTokens))
160
+ .replace('{state_section}', stateSection)
161
+ .replace('{context_section}', contextSection)
162
+ .replace('{previous_progress}', previousProgress)
163
+ .replace('{feedback_section}', feedbackSection ?? '')
164
+ .replace('{output_format}', outputFormat);
165
+ // Clean up multiple consecutive newlines
166
+ prompt = prompt.replace(/\n{3,}/g, '\n\n').trim();
167
+ // Estimate token count
168
+ const estimatedTokens = this.estimateTokens(prompt);
169
+ // Check if we exceeded limits and need to truncate
170
+ if (estimatedTokens > this.config.maxContextTokens) {
171
+ truncated = true;
172
+ prompt = this.truncatePrompt(prompt);
173
+ }
174
+ return {
175
+ prompt,
176
+ estimatedTokens: this.estimateTokens(prompt),
177
+ filesIncluded,
178
+ truncated,
179
+ };
180
+ }
181
+ /**
182
+ * Get explicit context files from glob patterns
183
+ */
184
+ async getExplicitContextFiles() {
185
+ if (!this.config.contextGlobs || this.config.contextGlobs.length === 0) {
186
+ return { content: '', files: [] };
187
+ }
188
+ const files = [];
189
+ const contentParts = [];
190
+ for (const pattern of this.config.contextGlobs) {
191
+ try {
192
+ const matches = await glob(pattern, { cwd: this.cwd, nodir: true });
193
+ for (const file of matches) {
194
+ try {
195
+ const fullPath = path.join(this.cwd, file);
196
+ const content = await fs.readFile(fullPath, 'utf-8');
197
+ // Skip very large files
198
+ if (content.length > 50000) {
199
+ debug(`Skipping large file: ${file}`);
200
+ continue;
201
+ }
202
+ files.push(file);
203
+ contentParts.push(`### ${file}\n\`\`\`\n${content}\n\`\`\``);
204
+ }
205
+ catch {
206
+ debug(`Failed to read file: ${file}`);
207
+ }
208
+ }
209
+ }
210
+ catch {
211
+ debug(`Failed to glob pattern: ${pattern}`);
212
+ }
213
+ }
214
+ return {
215
+ content: contentParts.join('\n\n'),
216
+ files,
217
+ };
218
+ }
219
+ /**
220
+ * Find relevant files based on task keywords
221
+ */
222
+ async findRelevantFiles(task) {
223
+ // Extract keywords from task
224
+ const keywords = this.extractKeywords(task.title + ' ' + task.content);
225
+ if (keywords.length === 0) {
226
+ return { content: '', files: [] };
227
+ }
228
+ const files = [];
229
+ const contentParts = [];
230
+ // Try to find files matching keywords
231
+ for (const keyword of keywords.slice(0, 3)) { // Limit to top 3 keywords
232
+ try {
233
+ // Search for files containing the keyword
234
+ const { stdout } = await execAsync(`git grep -l "${keyword}" 2>/dev/null | head -3`, { cwd: this.cwd });
235
+ const matchedFiles = stdout.trim().split('\n').filter(Boolean);
236
+ for (const file of matchedFiles) {
237
+ if (files.includes(file))
238
+ continue;
239
+ try {
240
+ const fullPath = path.join(this.cwd, file);
241
+ const content = await fs.readFile(fullPath, 'utf-8');
242
+ // Skip large files
243
+ if (content.length > 30000)
244
+ continue;
245
+ files.push(file);
246
+ contentParts.push(`### ${file}\n\`\`\`\n${content.substring(0, 5000)}${content.length > 5000 ? '\n...(truncated)' : ''}\n\`\`\``);
247
+ // Limit total files
248
+ if (files.length >= 5)
249
+ break;
250
+ }
251
+ catch {
252
+ // Skip files we can't read
253
+ }
254
+ }
255
+ if (files.length >= 5)
256
+ break;
257
+ }
258
+ catch {
259
+ // git grep not available or no matches
260
+ }
261
+ }
262
+ if (contentParts.length === 0) {
263
+ return { content: '', files: [] };
264
+ }
265
+ return {
266
+ content: '## Relevant Files (keyword matches)\n' + contentParts.join('\n\n'),
267
+ files,
268
+ };
269
+ }
270
+ /**
271
+ * Extract keywords from text
272
+ */
273
+ extractKeywords(text) {
274
+ // Remove common words and extract meaningful terms
275
+ const stopWords = new Set([
276
+ 'the', 'a', 'an', 'and', 'or', 'but', 'in', 'on', 'at', 'to', 'for',
277
+ 'of', 'with', 'by', 'from', 'as', 'is', 'was', 'are', 'were', 'been',
278
+ 'be', 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
279
+ 'should', 'may', 'might', 'must', 'shall', 'can', 'need', 'this', 'that',
280
+ 'these', 'those', 'it', 'its', 'add', 'update', 'create', 'fix', 'implement',
281
+ ]);
282
+ // Extract words
283
+ const words = text
284
+ .toLowerCase()
285
+ .replace(/[^\w\s]/g, ' ')
286
+ .split(/\s+/)
287
+ .filter(w => w.length > 2 && !stopWords.has(w));
288
+ // Return unique words, prioritizing longer ones
289
+ return [...new Set(words)].sort((a, b) => b.length - a.length);
290
+ }
291
+ /**
292
+ * Get current git diff
293
+ */
294
+ async getGitDiff() {
295
+ try {
296
+ const { stdout } = await execAsync('git diff --staged HEAD 2>/dev/null || git diff HEAD 2>/dev/null', {
297
+ cwd: this.cwd,
298
+ maxBuffer: 100000,
299
+ });
300
+ const diff = stdout.trim();
301
+ if (!diff)
302
+ return null;
303
+ // Truncate if too long
304
+ if (diff.length > 10000) {
305
+ return diff.substring(0, 10000) + '\n...(truncated)';
306
+ }
307
+ return diff;
308
+ }
309
+ catch {
310
+ return null;
311
+ }
312
+ }
313
+ /**
314
+ * Get recent git history
315
+ */
316
+ async getGitHistory() {
317
+ try {
318
+ const limit = this.config.gitHistoryLimit ?? 5;
319
+ const { stdout } = await execAsync(`git log --oneline -n ${limit} 2>/dev/null`, { cwd: this.cwd });
320
+ return stdout.trim() || null;
321
+ }
322
+ catch {
323
+ return null;
324
+ }
325
+ }
326
+ /**
327
+ * Get project structure overview
328
+ */
329
+ async getProjectStructure() {
330
+ try {
331
+ // Use find to get directory structure, limited depth
332
+ const { stdout } = await execAsync('find . -type f -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" | head -50', { cwd: this.cwd });
333
+ return stdout.trim() || null;
334
+ }
335
+ catch {
336
+ return null;
337
+ }
338
+ }
339
+ /**
340
+ * Build previous progress section
341
+ */
342
+ buildPreviousProgress(iterations) {
343
+ const successful = iterations.filter(i => i.success && i.summary);
344
+ if (successful.length === 0) {
345
+ return '';
346
+ }
347
+ const summaries = successful
348
+ .map(i => `- Iteration ${i.iteration}: ${i.summary}`)
349
+ .join('\n');
350
+ return `## Previous Progress\n${summaries}`;
351
+ }
352
+ /**
353
+ * Check if adding content would exceed token limit
354
+ */
355
+ exceedsTokenLimit(existing, additional) {
356
+ const estimatedTokens = this.estimateTokens(existing + additional);
357
+ return estimatedTokens > this.config.maxContextTokens;
358
+ }
359
+ /**
360
+ * Estimate token count (rough approximation: ~4 chars per token)
361
+ */
362
+ estimateTokens(text) {
363
+ return Math.ceil(text.length / 4);
364
+ }
365
+ /**
366
+ * Truncate prompt to fit within limits
367
+ */
368
+ truncatePrompt(prompt) {
369
+ const maxChars = this.config.maxContextTokens * 4;
370
+ if (prompt.length <= maxChars) {
371
+ return prompt;
372
+ }
373
+ warn(`Truncating prompt from ${prompt.length} to ${maxChars} characters`);
374
+ // Keep start and end, truncate middle
375
+ const keepStart = Math.floor(maxChars * 0.7);
376
+ const keepEnd = Math.floor(maxChars * 0.25);
377
+ return prompt.substring(0, keepStart) +
378
+ '\n\n...(context truncated due to size limits)...\n\n' +
379
+ prompt.substring(prompt.length - keepEnd);
380
+ }
381
+ }
382
+ /**
383
+ * Create a context builder with custom configuration
384
+ */
385
+ export function createContextBuilder(config, cwd) {
386
+ return new ContextBuilder(config, cwd);
387
+ }
388
+ //# sourceMappingURL=context-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-builder.js","sourceRoot":"","sources":["../../src/core/context-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAElC;;;GAGG;AACH,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;yDAeyB,CAAC;AAE1D;;GAEG;AACH,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;iCAgBE,CAAC;AAyClC;;GAEG;AACH,MAAM,cAAc,GAAyB;IAC3C,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,IAAI;IACvB,eAAe,EAAE,CAAC;IAClB,uBAAuB,EAAE,IAAI;IAC7B,wBAAwB,EAAE,IAAI,EAAE,iDAAiD;IACjF,eAAe,EAAE,KAAK,EAAE,sDAAsD;IAC9E,KAAK,EAAE,SAAS,EAAE,qCAAqC;CACxD,CAAC;AAgBF;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,MAAM,CAAuB;IAC7B,GAAG,CAAS;IAEp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AI,CAAC,MAAM,CAAC,gBAAgB,GAAG,CAAC,CAAC;QAElD,IAAI,MAAM,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;YAC9B,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,IAAI,CAAC,0BAA0B,MAAM,CAAC,MAAM,OAAO,QAAQ,aAAa,CAAC,CAAC;QAE1E,sCAAsC;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;QAE5C,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC;YACnC,sDAAsD;YACtD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAsC,EACtC,GAAY;IAEZ,OAAO,IAAI,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Feedback Builder
3
+ *
4
+ * Builds feedback prompts to show the AI the results of its actions.
5
+ * This is a core component of the Ralph pattern - the AI must see
6
+ * actual results (test output, errors, git diff) to iterate effectively.
7
+ */
8
+ import type { ExecutionResult } from './action-executor.js';
9
+ import type { VerificationResult } from './verification-hooks.js';
10
+ /**
11
+ * Feedback section types
12
+ */
13
+ export type FeedbackSectionType = 'actions' | 'verification' | 'git-diff' | 'error' | 'suggestion';
14
+ /**
15
+ * A section of feedback
16
+ */
17
+ export interface FeedbackSection {
18
+ type: FeedbackSectionType;
19
+ title: string;
20
+ content: string;
21
+ success: boolean;
22
+ }
23
+ /**
24
+ * Complete feedback for the next iteration
25
+ */
26
+ export interface IterationFeedback {
27
+ /** All feedback sections */
28
+ sections: FeedbackSection[];
29
+ /** Overall success status */
30
+ overallSuccess: boolean;
31
+ /** Whether task should be marked complete */
32
+ taskComplete: boolean;
33
+ /** Formatted feedback for prompt */
34
+ formatted: string;
35
+ }
36
+ /**
37
+ * Feedback builder configuration
38
+ */
39
+ export interface FeedbackBuilderConfig {
40
+ /** Working directory */
41
+ cwd: string;
42
+ /** Maximum lines of output to include per section */
43
+ maxOutputLines: number;
44
+ /** Whether to include git diff */
45
+ includeGitDiff: boolean;
46
+ /** Maximum git diff size in characters */
47
+ maxDiffSize: number;
48
+ }
49
+ /**
50
+ * Feedback Builder
51
+ *
52
+ * Creates structured feedback for the AI based on what happened
53
+ * in the previous iteration.
54
+ */
55
+ export declare class FeedbackBuilder {
56
+ private config;
57
+ constructor(config?: Partial<FeedbackBuilderConfig>);
58
+ /**
59
+ * Build feedback from action execution results
60
+ */
61
+ buildFromActions(executionResult: ExecutionResult): FeedbackSection;
62
+ /**
63
+ * Build feedback from verification results
64
+ */
65
+ buildFromVerification(results: VerificationResult[]): FeedbackSection;
66
+ /**
67
+ * Build feedback from current git diff
68
+ */
69
+ buildFromGitDiff(): Promise<FeedbackSection | null>;
70
+ /**
71
+ * Build an error feedback section
72
+ */
73
+ buildError(error: Error | string): FeedbackSection;
74
+ /**
75
+ * Build a suggestion section
76
+ */
77
+ buildSuggestion(suggestion: string): FeedbackSection;
78
+ /**
79
+ * Combine sections into complete iteration feedback
80
+ */
81
+ buildComplete(actionResult: ExecutionResult | null, verificationResults: VerificationResult[], options?: {
82
+ includeGitDiff?: boolean;
83
+ suggestion?: string;
84
+ }): Promise<IterationFeedback>;
85
+ /**
86
+ * Format feedback sections for inclusion in prompt
87
+ */
88
+ formatForPrompt(sections: FeedbackSection[], taskComplete: boolean): string;
89
+ }
90
+ /**
91
+ * Create a feedback builder with custom configuration
92
+ */
93
+ export declare function createFeedbackBuilder(config?: Partial<FeedbackBuilderConfig>): FeedbackBuilder;
94
+ //# sourceMappingURL=feedback-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedback-builder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