Files
hapi/web/src/lib/file-composer.ts
T
DebinandGitHub d124c106a4 feat(web): file context menu with copy path / absolute path / add to composer (#1808)
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
2026-09-11 14:20:22 +08:00

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)
}