Skip to content

fix: stop duplicating directory lines in the reverse-prompt file tree - #145

Open
eeshsaxena wants to merge 3 commits into
filiksyos:mainfrom
eeshsaxena:fix/file-tree-double-print
Open

fix: stop duplicating directory lines in the reverse-prompt file tree#145
eeshsaxena wants to merge 3 commits into
filiksyos:mainfrom
eeshsaxena:fix/file-tree-double-print

Conversation

@eeshsaxena

Copy link
Copy Markdown

treeToString in lib/file-tree-formatter.ts prints every directory twice.

Each node is emitted once by its parent's child loop:

result += `${childPrefix}${child.name}${child.isDirectory ? "/" : ""}
`;

and then again at the top of its own recursive call:

if (!isRoot) {
  result += `${prefix}${node.name}${node.isDirectory ? "/" : ""}
`;
}

The second copy uses the child-continuation prefix rather than the branch connector, so a nested directory also shows up as a stray │ util/ line right after the correct ├── util/ one.

For example, given:

src/index.ts
src/util/helpers.ts
README.md

the current output is:

src/
src/
├── util/
│   util/
│   └── helpers.ts
└── index.ts
README.md

app/api/reverse-prompt/route.ts builds the repo tree with formatAsFilteredTree, which runs through treeToString, so the doubled listing goes straight into the prompt sent to the model.

Removing the redundant if (!isRoot) self-print fixes it. Every node is already printed once by its parent's loop, so each entry now appears exactly once:

src/
├── util/
│   └── helpers.ts
└── index.ts
README.md

Files are unaffected since they never recurse, and the root level is unchanged.

filiksyos and others added 3 commits August 14, 2026 17:09
treeToString printed every non-root node twice: once from the parent's
child loop and again from the node's own `if (!isRoot)` block on recursion.
The second copy also used the child-continuation prefix, so nested
directories rendered as e.g. `|   util/` right after the correct `|-- util/`
line. app/api/reverse-prompt feeds this tree into the LLM prompt, so the
doubled listing degrades the generated prompt.

Remove the redundant self-print; every node is now emitted once by its parent's loop.
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

@eeshsaxena is attempting to deploy a commit to the filiksyos' projects Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@eeshsaxena

Copy link
Copy Markdown
Author

@filiksyos the only red check here is the Vercel preview deploy, which is waiting on a team member to authorize it (Vercel requires that for PRs from outside forks). The GitGuardian security check passes. Could you authorize the deploy when you get a chance? The change itself is a small 4-line fix that stops the reverse-prompt file tree from printing each directory twice. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants