Skip to content

Commit de4cddc

Browse files
authored
Merge pull request #556 from joshwand/554-suppress-generation-output-not-headertext
feat: --no-file-summary now also suppresses generationHeader; doesn't suppress headerText (fixes #554)
2 parents fbad7c9 + ce3d025 commit de4cddc

File tree

12 files changed

+333
-61
lines changed

12 files changed

+333
-61
lines changed

src/core/output/outputGenerate.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,19 @@ const generateParsableXmlOutput = async (renderContext: RenderContext): Promise<
5757
const xmlBuilder = new XMLBuilder({ ignoreAttributes: false });
5858
const xmlDocument = {
5959
repomix: {
60-
'#text': renderContext.generationHeader,
6160
file_summary: renderContext.fileSummaryEnabled
6261
? {
63-
'#text': 'This section contains a summary of this file.',
62+
'#text': renderContext.generationHeader,
6463
purpose: renderContext.summaryPurpose,
6564
file_format: `${renderContext.summaryFileFormat}
66-
4. Repository files, each consisting of:
65+
5. Repository files, each consisting of:
6766
- File path as an attribute
6867
- Full contents of the file`,
6968
usage_guidelines: renderContext.summaryUsageGuidelines,
7069
notes: renderContext.summaryNotes,
71-
additional_info: {
72-
user_provided_header: renderContext.headerText,
73-
},
7470
}
7571
: undefined,
72+
user_provided_header: renderContext.headerText,
7673
directory_structure: renderContext.directoryStructureEnabled ? renderContext.treeString : undefined,
7774
files: renderContext.filesEnabled
7875
? {

src/core/output/outputStyles/markdownStyle.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import Handlebars from 'handlebars';
22

33
export const getMarkdownTemplate = () => {
44
return /* md */ `
5+
{{#if fileSummaryEnabled}}
56
{{{generationHeader}}}
67
7-
{{#if fileSummaryEnabled}}
88
# File Summary
99
1010
## Purpose
1111
{{{summaryPurpose}}}
1212
1313
## File Format
1414
{{{summaryFileFormat}}}
15-
4. Multiple file entries, each consisting of:
15+
5. Multiple file entries, each consisting of:
1616
a. A header with the file path (## File: path/to/file)
1717
b. The full contents of the file in a code block
1818
@@ -22,11 +22,10 @@ export const getMarkdownTemplate = () => {
2222
## Notes
2323
{{{summaryNotes}}}
2424
25-
## Additional Info
25+
{{/if}}
2626
{{#if headerText}}
27-
### User Provided Header
27+
# User Provided Header
2828
{{{headerText}}}
29-
{{/if}}
3029
3130
{{/if}}
3231
{{#if directoryStructureEnabled}}

src/core/output/outputStyles/plainStyle.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ const PLAIN_LONG_SEPARATOR = '='.repeat(64);
33

44
export const getPlainTemplate = () => {
55
return `
6+
{{#if fileSummaryEnabled}}
67
{{{generationHeader}}}
78
8-
{{#if fileSummaryEnabled}}
99
${PLAIN_LONG_SEPARATOR}
1010
File Summary
1111
${PLAIN_LONG_SEPARATOR}
@@ -17,7 +17,7 @@ Purpose:
1717
File Format:
1818
------------
1919
{{{summaryFileFormat}}}
20-
4. Multiple file entries, each consisting of:
20+
5. Multiple file entries, each consisting of:
2121
a. A separator line (================)
2222
b. The file path (File: path/to/file)
2323
c. Another separator line
@@ -32,13 +32,13 @@ Notes:
3232
------
3333
{{{summaryNotes}}}
3434
35-
Additional Info:
36-
----------------
35+
{{/if}}
36+
3737
{{#if headerText}}
38-
User Provided Header:
39-
-----------------------
38+
${PLAIN_LONG_SEPARATOR}
39+
User Provided Header
40+
${PLAIN_LONG_SEPARATOR}
4041
{{{headerText}}}
41-
{{/if}}
4242
4343
{{/if}}
4444
{{#if directoryStructureEnabled}}

src/core/output/outputStyles/xmlStyle.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const getXmlTemplate = () => {
22
return /* xml */ `
3+
{{#if fileSummaryEnabled}}
34
{{{generationHeader}}}
45
5-
{{#if fileSummaryEnabled}}
66
<file_summary>
77
This section contains a summary of this file.
88
@@ -12,7 +12,7 @@ This section contains a summary of this file.
1212
1313
<file_format>
1414
{{{summaryFileFormat}}}
15-
4. Repository files, each consisting of:
15+
5. Multiple file entries, each consisting of:
1616
- File path as an attribute
1717
- Full contents of the file
1818
</file_format>
@@ -25,16 +25,13 @@ This section contains a summary of this file.
2525
{{{summaryNotes}}}
2626
</notes>
2727
28-
<additional_info>
28+
</file_summary>
29+
30+
{{/if}}
2931
{{#if headerText}}
3032
<user_provided_header>
3133
{{{headerText}}}
3234
</user_provided_header>
33-
{{/if}}
34-
35-
</additional_info>
36-
37-
</file_summary>
3835
3936
{{/if}}
4037
{{#if directoryStructureEnabled}}

tests/core/output/outputGenerate.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,53 @@ describe('outputGenerate', () => {
138138
expect(output).toContain('## File: dir/file2.txt');
139139
expect(output).toContain('````\n```\ncontent2\n```\n````');
140140
});
141+
142+
test('generateOutput (txt) should omit generationHeader when fileSummaryEnabled is false, but always include headerText if provided', async () => {
143+
const mockConfig = createMockConfig({
144+
output: {
145+
filePath: 'output.txt',
146+
style: 'plain',
147+
fileSummary: false,
148+
headerText: 'ALWAYS SHOW THIS HEADER',
149+
},
150+
});
151+
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }];
152+
const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);
153+
expect(output).not.toContain('This file is a merged representation'); // generationHeader
154+
expect(output).toContain('ALWAYS SHOW THIS HEADER');
155+
});
156+
157+
test('generateOutput (xml) omits generationHeader when fileSummaryEnabled is false, but always includes headerText', async () => {
158+
const mockConfig = createMockConfig({
159+
output: {
160+
filePath: 'output.xml',
161+
style: 'xml',
162+
fileSummary: false,
163+
headerText: 'XML HEADER',
164+
parsableStyle: true,
165+
},
166+
});
167+
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: '<div>foo</div>' }];
168+
const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);
169+
const parser = new XMLParser({ ignoreAttributes: false });
170+
const parsedOutput = parser.parse(output);
171+
expect(parsedOutput.repomix['#text']).toBeUndefined();
172+
expect(parsedOutput.repomix.user_provided_header).toBe('XML HEADER');
173+
});
174+
175+
test('generateOutput (markdown) omits generationHeader when fileSummaryEnabled is false, but always includes headerText', async () => {
176+
const mockConfig = createMockConfig({
177+
output: {
178+
filePath: 'output.md',
179+
style: 'markdown',
180+
fileSummary: false,
181+
headerText: 'MARKDOWN HEADER',
182+
parsableStyle: false,
183+
},
184+
});
185+
const mockProcessedFiles: ProcessedFile[] = [{ path: 'file1.txt', content: 'content1' }];
186+
const output = await generateOutput([process.cwd()], mockConfig, mockProcessedFiles, []);
187+
expect(output).not.toContain('This file is a merged representation');
188+
expect(output).toContain('MARKDOWN HEADER');
189+
});
141190
});

tests/core/output/outputStyles/markdownStyle.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Handlebars from 'handlebars';
22
import { describe, expect, test } from 'vitest';
3+
import { generateOutput } from '../../../../src/core/output/outputGenerate.js';
34
import { getMarkdownTemplate } from '../../../../src/core/output/outputStyles/markdownStyle.js';
5+
import { createMockConfig } from '../../../testing/testUtils.js';
46

57
describe('markdownStyle', () => {
68
describe('getMarkdownTemplate', () => {
@@ -59,7 +61,7 @@ describe('markdownStyle', () => {
5961

6062
const result = compiledTemplate(data);
6163

62-
expect(result).toContain('### User Provided Header');
64+
expect(result).toContain('# User Provided Header');
6365
expect(result).toContain('Custom Header Text');
6466
});
6567

@@ -74,7 +76,7 @@ describe('markdownStyle', () => {
7476

7577
const result = compiledTemplate(data);
7678

77-
expect(result).not.toContain('### User Provided Header');
79+
expect(result).not.toContain('# User Provided Header');
7880
});
7981

8082
test('should render instruction section when provided', () => {
@@ -92,6 +94,35 @@ describe('markdownStyle', () => {
9294
expect(result).toContain('# Instruction');
9395
expect(result).toContain('Custom Instruction Text');
9496
});
97+
98+
test('should display headerText if specified even if fileSummary is disabled', () => {
99+
const template = getMarkdownTemplate();
100+
const compiledTemplate = Handlebars.compile(template);
101+
const data = {
102+
headerText: 'MARKDOWN HEADER',
103+
fileSummaryEnabled: false,
104+
directoryStructureEnabled: true,
105+
processedFiles: [],
106+
};
107+
const result = compiledTemplate(data);
108+
expect(result).not.toContain('This file is a merged representation');
109+
expect(result).toContain('MARKDOWN HEADER');
110+
});
111+
112+
test('should not display generationHeader if fileSummary is disabled', () => {
113+
const template = getMarkdownTemplate();
114+
const compiledTemplate = Handlebars.compile(template);
115+
const data = {
116+
generationHeader: 'Generated Test Header',
117+
fileSummaryEnabled: false,
118+
directoryStructureEnabled: true,
119+
processedFiles: [],
120+
};
121+
const result = compiledTemplate(data);
122+
expect(result).not.toContain('This file is a merged representation');
123+
expect(result).not.toContain('Generated Test Header');
124+
expect(result).toContain('# Directory Structure');
125+
});
95126
});
96127

97128
describe('getFileExtension helper', () => {

tests/core/output/outputStyles/plainStyle.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,18 @@ describe('plainStyle', () => {
3030
expect(output).toContain('Custom header text');
3131
expect(output).toContain('Files');
3232
});
33+
34+
test('plain style: headerText always present, generationHeader only if fileSummaryEnabled', async () => {
35+
const mockConfig = createMockConfig({
36+
output: {
37+
filePath: 'output.txt',
38+
style: 'plain',
39+
fileSummary: false,
40+
headerText: 'PLAIN HEADER',
41+
},
42+
});
43+
const output = await generateOutput([process.cwd()], mockConfig, [], []);
44+
expect(output).not.toContain('This file is a merged representation');
45+
expect(output).toContain('PLAIN HEADER');
46+
});
3347
});

tests/core/output/outputStyles/xmlStyle.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,19 @@ describe('xmlStyle', () => {
3030
expect(output).toContain('Custom header text');
3131
expect(output).toContain('files');
3232
});
33+
34+
test('xml style: headerText always present, generationHeader only if fileSummaryEnabled', async () => {
35+
const mockConfig = createMockConfig({
36+
output: {
37+
filePath: 'output.xml',
38+
style: 'xml',
39+
fileSummary: false,
40+
headerText: 'XML HEADER',
41+
parsableStyle: false,
42+
},
43+
});
44+
const output = await generateOutput([process.cwd()], mockConfig, [], []);
45+
expect(output).not.toContain('This file is a merged representation');
46+
expect(output).toContain('XML HEADER');
47+
});
3348
});

0 commit comments

Comments
 (0)