Implement the following plan: Plan: Improve Remediation Prompt Quality Context The…
- User
Implement the following plan:
Plan: Improve Remediation Prompt Quality
Context
The remediation prompt generator (
src/shared/remediation/prompt-generator.ts) produces prompts sent to AI agents to fix/enrich documentation. Several issues waste tokens and reduce prompt clarity:- Evaluator recommendations contain "You can use Packmind to achieve this" boilerplate that leaks into prompts
- When multiple gaps reference the same snippet, it's repeated verbatim (7x duplication observed in real usage)
- No guidance to consolidate related gaps into cohesive sections
- The Role line uses
.split(".")[0]producing awkward "Claude Code uses CLAUDE" fragment
Changes
All changes in
src/shared/remediation/prompt-generator.ts:1. Strip Packmind boilerplate from recommendations
In
formatIssueFix()(line 51), strip trailing "You can use Packmind to achieve this." before returning:tsfunction formatIssueFix(issue: RemediationIssue): string { const raw = issue.fix || issue.recommendation || "Review and fix this issue"; return raw.replace(/\s*You can use Packmind to achieve this\.?\s*$/i, "").trimEnd(); }2. Deduplicate repeated snippets
Add a snippet deduplication layer used by both
buildErrorFixPromptandbuildSuggestionEnrichPrompt:- Collect all unique
(file, snippet)pairs across sorted issues - Only deduplicate snippets that appear 2+ times (single-use snippets stay inline)
- Assign labels
[A],[B], etc. to deduplicated snippets - Render a
## Referenced Contentsection before the issue blocks listing each labeled snippet once - In each issue block, replace the inline snippet with
**Current content**: See [A]when deduplicated
Helper functions to add:
buildSnippetIndex(issues)→Map<string, { label: string; file?: string; snippet: string }>keyed byfile + "\n" + snippetgetSnippetRef(issue, index)→ returns either inline snippet block or reference
Assistant
I'll start by reading the files I need to modify.
Assistant
Now let me check the
TargetAgenttype.Assistant
There's already a
TARGET_AGENTSmap with display names. I can reuse it. Let me implement all 4 changes.Assistant
1. Strip Packmind boilerplate
Assistant
2. Deduplicate repeated snippets
First, add the helper functions and update the format functions to accept the snippet index.
Assistant
Now add the snippet dedup helpers after
formatIssueFix:Assistant
Now update
formatErrorIssueBlockandformatSuggestionIssueBlockto accept the snippet index:Assistant
Now update
buildErrorFixPromptandbuildSuggestionEnrichPromptto use the snippet index:Assistant
Now update
buildSuggestionEnrichPromptsimilarly:Assistant
Now add the referenced content section and consolidation instruction in the suggestion prompt:
Assistant
3. Add referenced content section + consolidation instruction in suggestion prompt
Assistant
Let me verify the final state of the source file before writing tests.
Assistant
Source file looks good. Now let me write the tests.
Assistant
4. Add tests
Assistant
Now add the remaining tests at the end of the file, before the final closing
});:Assistant
Now let me run the tests.
Assistant
All 1241 tests pass. Now let me run lint.
Assistant
Lint fixed. Let me verify everything still passes.
Assistant
All done. Here's a summary of the changes made to
src/shared/remediation/prompt-generator.ts:- Packmind boilerplate stripping —
formatIssueFix()now strips trailing "You can use Packmind to achieve this." from fix/recommendation text before returning - Snippet deduplication — Added
buildSnippetIndex(),buildReferencedContentSection(), andgetSnippetRef()helpers. Snippets appearing 2+ times get labeled[A],[B], etc. and rendered once in a## Referenced Contentsection, with issue blocks referencing them viaSee [A]. Single-use snippets stay inline. - Consolidation guidance — Added step 4 in the suggestion prompt instructions: "When multiple gaps target the same file and related topics, consolidate them into well-organized sections rather than creating many small isolated additions"
- Role line fix — Replaced
.split(".")[0]withTARGET_AGENTS[input.targetAgent](imported from@shared/types/remediation), producing clean names like "Claude Code", "AGENTS.md", "GitHub Copilot"
Tests added covering all 4 behaviors: 1241 tests pass, lint clean.
- Packmind boilerplate stripping —
- User
commit
Assistant
Commit succeeded — pre-commit hook passed all checks (1241 tests, lint, typecheck). Commit:
3478dc9.