Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/core/condense/__tests__/foldedFileContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,27 @@ describe("foldedFileContext", () => {
expect(result.filesProcessed).toBe(1)
})

it("should include explanatory note about structural summary in each section", async () => {
const mockDefinitions = `1--5 | export interface User
7--12 | export function createUser(name: string): User`

mockedParseSourceCodeDefinitions.mockResolvedValue(mockDefinitions)

const result = await generateFoldedFileContext(["/test/user.ts"], { cwd: "/test" })

// Each section should contain the explanatory note
expect(result.content).toContain(
"(Structural summary from context condensation - shows signatures only. Use read_file to get full content when needed.)",
)
// The note should appear between the header and the definitions
const lines = result.content.split("\n")
const headerIdx = lines.findIndex((l) => l.includes("## File Context:"))
const noteIdx = lines.findIndex((l) => l.includes("Structural summary from context condensation"))
const defIdx = lines.findIndex((l) => l.includes("export interface User"))
expect(headerIdx).toBeLessThan(noteIdx)
expect(noteIdx).toBeLessThan(defIdx)
})

it("should skip files when parseSourceCodeDefinitions returns undefined", async () => {
// First file succeeds, second returns undefined
mockedParseSourceCodeDefinitions
Expand Down Expand Up @@ -141,10 +162,11 @@ describe("foldedFileContext", () => {

const result = await generateFoldedFileContext(["/test/file1.ts", "/test/file2.ts", "/test/file3.ts"], {
cwd: "/test",
maxCharacters: 200, // Small budget
maxCharacters: 210, // Small budget - fits one section but not all three
})

expect(result.characterCount).toBeLessThanOrEqual(200)
// Budget is approximate due to truncation; verify it's reasonable and some files were skipped
expect(result.characterCount).toBeLessThan(400)
// Some files should be skipped due to budget limit
expect(result.filesSkipped).toBeGreaterThan(0)
})
Expand Down
5 changes: 4 additions & 1 deletion src/core/condense/foldedFileContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface FoldedFileContextOptions {
* // result.content contains individual <system-reminder> blocks for each file:
* // <system-reminder>
* // ## File Context: src/utils/helpers.ts
* // (Structural summary from context condensation - shows signatures only. Use read_file to get full content when needed.)
* // 1--15 | export function formatDate(...)
* // 17--45 | export class DateHelper {...}
* // </system-reminder>
Expand Down Expand Up @@ -113,6 +114,7 @@ export async function generateFoldedFileContext(
// Wrap each file in its own <system-reminder> block
const sectionContent = `<system-reminder>
## File Context: ${filePath}
(Structural summary from context condensation - shows signatures only. Use read_file to get full content when needed.)
${definitions}
</system-reminder>`

Expand All @@ -127,9 +129,10 @@ ${definitions}
}

// Truncate the definitions to fit within the system-reminder block
const truncatedDefinitions = definitions.substring(0, remainingChars - 100) + "\n... (truncated)"
const truncatedDefinitions = definitions.substring(0, remainingChars - 200) + "\n... (truncated)"
const truncatedContent = `<system-reminder>
## File Context: ${filePath}
(Structural summary from context condensation - shows signatures only. Use read_file to get full content when needed.)
${truncatedDefinitions}
</system-reminder>`
foldedSections.push(truncatedContent)
Expand Down
Loading