mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-24 04:47:03 +00:00
Add a right-click (desktop) / long-press (mobile) menu to file entries on the Files page: git change rows, file search results, and the directory tree. Actions: - Copy path (workspace-relative) - Copy absolute path (resolved against session.metadata.path) - Add to composer (append a backticked reference to the session composer draft and navigate back to the chat) Closes #1807
20 lines
867 B
TypeScript
20 lines
867 B
TypeScript
import { getDraft, saveDraft } from '@/lib/composer-drafts'
|
|
|
|
/** Wrap a workspace-relative path so the agent can spot it in the prompt. */
|
|
export function formatFileReference(relativePath: string): string {
|
|
return `\`${relativePath}\``
|
|
}
|
|
|
|
/**
|
|
* Append a file reference to a session's composer draft.
|
|
*
|
|
* The composer is unmounted on the files routes, so callers must persist the
|
|
* draft here and then navigate back to the chat; `useComposerDraft` restores it
|
|
* on mount. Existing text is preserved and the reference is added on a new line.
|
|
*/
|
|
export function appendFileReferenceToComposerDraft(sessionId: string, relativePath: string): void {
|
|
const reference = formatFileReference(relativePath)
|
|
const existing = getDraft(sessionId).replace(/[ \t\r\n]+$/, '')
|
|
saveDraft(sessionId, existing.length > 0 ? `${existing}\n${reference}` : reference)
|
|
}
|