feat(agents): export focused hunk prompts#288
Conversation
Greptile SummaryThis PR introduces a focused-hunk prompt export shared by the TUI and the session CLI. In the TUI,
Confidence Score: 4/5Safe to merge; the only issue is a minor prompt-text inconsistency that affects agent UX but not correctness or data integrity. The feature is well-scoped, the new src/core/agentPrompt.ts — the closing instruction at line 135 warrants a small conditional to avoid referencing a comment that does not exist in the prompt. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant TUI as App.tsx (TUI)
participant AP as agentPrompt.ts
participant FS as Filesystem
participant Clip as Clipboard (OSC52)
User->>TUI: press p
TUI->>AP: "buildAgentPrompt({ file, hunkIndex })"
AP-->>TUI: prompt string
TUI->>Clip: copyToClipboardOSC52(prompt)
alt copy succeeded
Clip-->>TUI: true
TUI-->>User: status notice "Copied"
else copy failed
Clip-->>TUI: false
TUI->>FS: writeAgentPromptFallback(prompt)
FS-->>TUI: savedPath
TUI-->>User: AgentPromptPreviewDialog
end
User->>TUI: press c
TUI-->>User: AgentCommentDialog
User->>TUI: type comment + Enter
TUI->>TUI: review.addLiveComment(...)
TUI->>AP: "buildAgentPrompt({ file, hunkIndex, comment })"
AP-->>TUI: prompt string
TUI->>Clip: copyToClipboardOSC52(prompt)
User->>CLI: hunk session prompt --repo .
CLI->>AP: "buildAgentPrompt({ file, hunkIndex, comment? })"
AP-->>CLI: prompt string
CLI-->>User: stdout (text or JSON)
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/core/agentPrompt.ts:131-136
The closing instruction unconditionally tells the agent to "address my comment" even when no comment was provided. When `p` is used to copy a plain hunk prompt, there is no "My comment:" section, so the imperative becomes a dangling reference that may confuse the agent. The instruction should only appear when a comment or selected text is actually present, with a lighter-touch fallback for the context-only case.
```suggestion
"",
"Diff hunk:",
codeFence("diff", diffSnippet),
"",
normalizedComment || normalizedSelection
? "Please address my comment against this diff. If you need more surrounding code, ask before editing."
: "Please use this diff hunk as context. If you need more surrounding code, ask before editing.",
].join("\n"),
```
Reviews (1): Last reviewed commit: "feat(agents): export focused hunk prompt..." | Re-trigger Greptile |
| "", | ||
| "Diff hunk:", | ||
| codeFence("diff", diffSnippet), | ||
| "", | ||
| "Please address my comment against this diff. If you need more surrounding code, ask before editing.", | ||
| ].join("\n"), |
There was a problem hiding this comment.
The closing instruction unconditionally tells the agent to "address my comment" even when no comment was provided. When
p is used to copy a plain hunk prompt, there is no "My comment:" section, so the imperative becomes a dangling reference that may confuse the agent. The instruction should only appear when a comment or selected text is actually present, with a lighter-touch fallback for the context-only case.
| "", | |
| "Diff hunk:", | |
| codeFence("diff", diffSnippet), | |
| "", | |
| "Please address my comment against this diff. If you need more surrounding code, ask before editing.", | |
| ].join("\n"), | |
| "", | |
| "Diff hunk:", | |
| codeFence("diff", diffSnippet), | |
| "", | |
| normalizedComment || normalizedSelection | |
| ? "Please address my comment against this diff. If you need more surrounding code, ask before editing." | |
| : "Please use this diff hunk as context. If you need more surrounding code, ask before editing.", | |
| ].join("\n"), |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/core/agentPrompt.ts
Line: 131-136
Comment:
The closing instruction unconditionally tells the agent to "address my comment" even when no comment was provided. When `p` is used to copy a plain hunk prompt, there is no "My comment:" section, so the imperative becomes a dangling reference that may confuse the agent. The instruction should only appear when a comment or selected text is actually present, with a lighter-touch fallback for the context-only case.
```suggestion
"",
"Diff hunk:",
codeFence("diff", diffSnippet),
"",
normalizedComment || normalizedSelection
? "Please address my comment against this diff. If you need more surrounding code, ask before editing."
: "Please use this diff hunk as context. If you need more surrounding code, ask before editing.",
].join("\n"),
```
How can I resolve this? If you propose a fix, please make it concise.
Summary
pto copy the focused hunk prompt andcto add a user comment + copy the commented prompthunk session promptfor agents/scripts to export the current focused hunk as a paste-ready promptTesting
bun run format:checkbun run typecheckbun run lintbun test src/core/agentPrompt.test.ts src/core/cli.test.ts src/session/commands.test.ts src/ui/lib/ui-lib.test.tsbun test ./src ./packages ./scripts ./test/cli ./test/session(fails only on existing jj-dependent tests becausejjis not installed in this environment)Closes #114
Related #239