mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-21 07:55:08 +00:00
refactor(desktop): one reference vocabulary behind @ and / alike
`@` and `/` were two menus that happened to live in the same file: `@` rows were horizontal with an icon, `/` rows were stacked with none, and each kept its own hand-maintained icon map. Picking a file and picking a skill felt like features from different apps. Adds reference-kinds.ts — one table mapping every kind a reference can be (file, folder, url, image, tool, line, terminal, session, git, diff, staged, command, skill, theme, emoji) to its icon, accent, and section label. Both surfaces that show a reference now read from it: - the popover row, browsing for one - the chip, having picked one so a thing is the same colour with the same glyph wherever you meet it, and a row looks like the chip it will become. `/` rows gain icons in the process, which is what the shared layout gives them for free. Chips lose their pill: no background, no padding, no border, just the icon and coloured text. A filled badge turns every mention into a UI element the eye has to step over, and the icon plus accent already carry the kind. Slash pills are the same component — SLASH_CHIP_BASE_CLASS is now literally DIRECTIVE_CHIP_CLASS. Emoji rows stay icon-less: the emoji is its own glyph. Also drops three duplicated definitions (ICON_PATHS, SLASH_ICON_PATHS, SLASH_CHIP_VARIANT) and an inline copy of DirectiveIcon inside SlashChip.
This commit is contained in:
parent
c17053c4f7
commit
d83d296473
6 changed files with 482 additions and 180 deletions
87
apps/desktop/src/app/chat/composer/chip-typography.test.ts
Normal file
87
apps/desktop/src/app/chat/composer/chip-typography.test.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
DIRECTIVE_CHIP_CLASS,
|
||||
directiveChipClass,
|
||||
SLASH_CHIP_BASE_CLASS
|
||||
} from '@/components/assistant-ui/directive-text'
|
||||
import { REFERENCE_STYLES, referenceStyle } from '@/components/assistant-ui/reference-kinds'
|
||||
|
||||
/**
|
||||
* A chip is inline text, not a badge: same size as the words around it, no
|
||||
* background or padding to step over, and a per-kind color + icon carrying the
|
||||
* "what kind of thing is this" signal.
|
||||
*/
|
||||
describe('chip typography', () => {
|
||||
for (const [name, cls] of [
|
||||
['directive chip', DIRECTIVE_CHIP_CLASS],
|
||||
['slash chip', SLASH_CHIP_BASE_CLASS]
|
||||
] as const) {
|
||||
it(`${name} inherits the surrounding font size`, () => {
|
||||
expect(cls).not.toMatch(/\btext-\[0\.\d+em\]/)
|
||||
})
|
||||
|
||||
it(`${name} renders as text, with no badge chrome`, () => {
|
||||
for (const chrome of ['bg-', 'rounded', 'px-', 'py-', 'border']) {
|
||||
expect(cls).not.toContain(chrome)
|
||||
}
|
||||
})
|
||||
|
||||
it(`${name} sits on the text baseline without a nudge`, () => {
|
||||
// With no vertical padding there's nothing to cancel, so the pill needs
|
||||
// no magic em offset to stop riding low.
|
||||
expect(cls).toContain('align-baseline')
|
||||
expect(cls).not.toMatch(/align-\[-/)
|
||||
})
|
||||
}
|
||||
|
||||
it('directive and slash chips are literally the same shape', () => {
|
||||
expect(SLASH_CHIP_BASE_CLASS).toBe(DIRECTIVE_CHIP_CLASS)
|
||||
})
|
||||
|
||||
it('resolves to the same font size as its container', () => {
|
||||
const host = document.createElement('div')
|
||||
|
||||
host.style.fontSize = '16px'
|
||||
host.innerHTML = `<span id="chip" class="${DIRECTIVE_CHIP_CLASS}">apps/desktop/</span>`
|
||||
document.body.append(host)
|
||||
|
||||
const chip = host.querySelector('#chip') as HTMLElement
|
||||
|
||||
expect(getComputedStyle(chip).fontSize).toBe(getComputedStyle(host).fontSize)
|
||||
|
||||
host.remove()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the shared reference vocabulary', () => {
|
||||
it('gives every kind an icon, a color, and a label', () => {
|
||||
for (const [kind, style] of Object.entries(REFERENCE_STYLES)) {
|
||||
expect(style.codicon, `${kind} codicon`).toBeTruthy()
|
||||
expect(style.color, `${kind} color`).toBeTruthy()
|
||||
expect(style.label, `${kind} label`).toBeTruthy()
|
||||
|
||||
// Emoji rows render the emoji itself instead of a glyph.
|
||||
if (kind !== 'emoji') {
|
||||
expect(style.paths.length, `${kind} paths`).toBeGreaterThan(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('carries the kind colour into the chip class', () => {
|
||||
for (const kind of ['file', 'url', 'skill', 'command'] as const) {
|
||||
expect(directiveChipClass(kind)).toContain(referenceStyle(kind).color)
|
||||
}
|
||||
})
|
||||
|
||||
it('falls back to a real style for an unknown kind', () => {
|
||||
const style = referenceStyle('something-new')
|
||||
|
||||
expect(style).toBe(REFERENCE_STYLES.other)
|
||||
expect(style.codicon).toBeTruthy()
|
||||
})
|
||||
|
||||
it('gives commands and skills distinct accents so a list reads at a glance', () => {
|
||||
expect(referenceStyle('skill').color).not.toBe(referenceStyle('command').color)
|
||||
})
|
||||
})
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
* plain-text round-trip.
|
||||
*/
|
||||
import {
|
||||
DIRECTIVE_CHIP_CLASS,
|
||||
directiveChipClass,
|
||||
directiveIconElement,
|
||||
directiveIconSvg,
|
||||
formatRefValue,
|
||||
|
|
@ -60,7 +60,7 @@ export function refChipHtml(kind: string, rawValue: string, displayLabel?: strin
|
|||
|
||||
const label = displayLabel || refChipLabel(kind, id)
|
||||
|
||||
return `<span contenteditable="false" title="${escapeHtml(id)}" data-ref-text="${escapeHtml(text)}" data-ref-id="${escapeHtml(id)}" data-ref-kind="${escapeHtml(kind)}" class="${DIRECTIVE_CHIP_CLASS}">${directiveIconSvg(kind)}<span class="truncate">${escapeHtml(label)}</span></span>`
|
||||
return `<span contenteditable="false" title="${escapeHtml(id)}" data-ref-text="${escapeHtml(text)}" data-ref-id="${escapeHtml(id)}" data-ref-kind="${escapeHtml(kind)}" class="${directiveChipClass(kind)}">${directiveIconSvg(kind)}<span class="truncate">${escapeHtml(label)}</span></span>`
|
||||
}
|
||||
|
||||
export function refChipElement(kind: string, rawValue: string, displayLabel?: string) {
|
||||
|
|
@ -74,7 +74,7 @@ export function refChipElement(kind: string, rawValue: string, displayLabel?: st
|
|||
chip.dataset.refText = text
|
||||
chip.dataset.refId = id
|
||||
chip.dataset.refKind = kind
|
||||
chip.className = DIRECTIVE_CHIP_CLASS
|
||||
chip.className = directiveChipClass(kind)
|
||||
label.className = 'truncate'
|
||||
label.textContent = displayLabel || refChipLabel(kind, id)
|
||||
chip.append(directiveIconElement(kind), label)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,151 @@
|
|||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { ComposerTriggerPopover } from './trigger-popover'
|
||||
|
||||
vi.mock('@/i18n', () => ({
|
||||
useI18n: () => ({
|
||||
t: {
|
||||
composer: {
|
||||
lookupLoading: 'Loading…',
|
||||
lookupNoMatches: 'No matches',
|
||||
lookupTry: 'Try',
|
||||
lookupOr: 'or'
|
||||
}
|
||||
}
|
||||
})
|
||||
}))
|
||||
|
||||
function atItem(type: string, display: string, rawText: string, meta = '') {
|
||||
return {
|
||||
id: `${rawText}|0`,
|
||||
type,
|
||||
label: display,
|
||||
metadata: { icon: type, display, meta, rawText, insertId: display }
|
||||
}
|
||||
}
|
||||
|
||||
function slashItem(command: string, group: string, meta = '') {
|
||||
return {
|
||||
id: `${command}|0`,
|
||||
type: 'slash',
|
||||
label: command.slice(1),
|
||||
metadata: { command, display: command, meta, group, action: '', rawText: command }
|
||||
}
|
||||
}
|
||||
|
||||
const noop = () => {}
|
||||
|
||||
/** The rendered shape of one row: does it have an icon, and how is it laid out?
|
||||
* Icons are codicons — an `<i class="codicon codicon-<name>">`, not an SVG. */
|
||||
function rowShape(root: HTMLElement) {
|
||||
const row = root.querySelector('button') as HTMLElement
|
||||
const icon = row.querySelector('i.codicon')
|
||||
|
||||
return {
|
||||
hasIcon: Boolean(icon),
|
||||
iconName: icon?.className.match(/codicon-([\w-]+)/)?.[1],
|
||||
classes: row.className
|
||||
}
|
||||
}
|
||||
|
||||
describe('@ and / are one menu', () => {
|
||||
it('a slash row has an icon, just like an @ row', () => {
|
||||
const at = render(
|
||||
<ComposerTriggerPopover
|
||||
activeIndex={0}
|
||||
items={[atItem('folder', 'apps/desktop/', '@folder:apps/desktop/', 'dir')]}
|
||||
kind="@"
|
||||
loading={false}
|
||||
onHover={noop}
|
||||
onPick={noop}
|
||||
/>
|
||||
)
|
||||
|
||||
const atShape = rowShape(at.container)
|
||||
at.unmount()
|
||||
|
||||
const slash = render(
|
||||
<ComposerTriggerPopover
|
||||
activeIndex={0}
|
||||
items={[slashItem('/work', 'Skills', 'Start in a worktree')]}
|
||||
kind="/"
|
||||
loading={false}
|
||||
onHover={noop}
|
||||
onPick={noop}
|
||||
/>
|
||||
)
|
||||
|
||||
const slashShape = rowShape(slash.container)
|
||||
|
||||
// The whole point: `/` used to render a stacked, icon-less row.
|
||||
expect(slashShape.hasIcon).toBe(true)
|
||||
expect(atShape.hasIcon).toBe(true)
|
||||
expect(slashShape.classes).toBe(atShape.classes)
|
||||
|
||||
// And the glyph reflects the kind, not one generic bullet.
|
||||
expect(slashShape.iconName).toBe('zap')
|
||||
expect(atShape.iconName).toBe('folder')
|
||||
})
|
||||
|
||||
it('renders the name and description for both kinds', () => {
|
||||
const { rerender } = render(
|
||||
<ComposerTriggerPopover
|
||||
activeIndex={0}
|
||||
items={[slashItem('/work', 'Skills', 'Start in a worktree')]}
|
||||
kind="/"
|
||||
loading={false}
|
||||
onHover={noop}
|
||||
onPick={noop}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('/work')).toBeTruthy()
|
||||
expect(screen.getByText('Start in a worktree')).toBeTruthy()
|
||||
|
||||
rerender(
|
||||
<ComposerTriggerPopover
|
||||
activeIndex={0}
|
||||
items={[atItem('file', 'src/main.tsx', '@file:src/main.tsx', 'src')]}
|
||||
kind="@"
|
||||
loading={false}
|
||||
onHover={noop}
|
||||
onPick={noop}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('src/main.tsx')).toBeTruthy()
|
||||
expect(screen.getByText('src')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('an emoji row stays icon-less — the emoji IS the icon', () => {
|
||||
const { container } = render(
|
||||
<ComposerTriggerPopover
|
||||
activeIndex={0}
|
||||
items={[{ id: ':joy:|0', type: 'emoji', label: '😂 :joy:', metadata: { display: '😂 :joy:' } }]}
|
||||
kind=":"
|
||||
loading={false}
|
||||
onHover={noop}
|
||||
onPick={noop}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(rowShape(container).hasIcon).toBe(false)
|
||||
})
|
||||
|
||||
it('labels the active browse scope from the shared vocabulary', () => {
|
||||
render(
|
||||
<ComposerTriggerPopover
|
||||
activeIndex={0}
|
||||
items={[atItem('folder', 'apps/', '@folder:apps/', 'dir')]}
|
||||
kind="@"
|
||||
loading={false}
|
||||
onHover={noop}
|
||||
onPick={noop}
|
||||
scope="folder"
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Folders')).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import type { Unstable_TriggerItem } from '@assistant-ui/core'
|
||||
import { Fragment } from 'react'
|
||||
|
||||
import { referenceStyle } from '@/components/assistant-ui/reference-kinds'
|
||||
import { Codicon } from '@/components/ui/codicon'
|
||||
import { GlyphSpinner } from '@/components/ui/glyph-spinner'
|
||||
import { useI18n } from '@/i18n'
|
||||
|
|
@ -9,45 +10,47 @@ import { cn } from '@/lib/utils'
|
|||
import { COMPLETION_DRAWER_BELOW_CLASS, COMPLETION_DRAWER_CLASS, CompletionDrawerEmpty } from './completion-drawer'
|
||||
import type { DirectiveScope } from './text-utils'
|
||||
|
||||
const AT_ICON_BY_TYPE: Record<string, string> = {
|
||||
diff: 'diff',
|
||||
file: 'book',
|
||||
folder: 'folder',
|
||||
git: 'git-branch',
|
||||
image: 'file-media',
|
||||
simple: 'symbol-misc',
|
||||
staged: 'diff-added',
|
||||
tool: 'tools',
|
||||
url: 'globe'
|
||||
}
|
||||
|
||||
function atIcon(item: Unstable_TriggerItem) {
|
||||
const meta = item.metadata as { rawText?: string } | undefined
|
||||
const raw = meta?.rawText || item.label
|
||||
|
||||
if (raw.startsWith('@diff')) {
|
||||
return AT_ICON_BY_TYPE.diff
|
||||
}
|
||||
|
||||
if (raw.startsWith('@staged')) {
|
||||
return AT_ICON_BY_TYPE.staged
|
||||
}
|
||||
|
||||
return AT_ICON_BY_TYPE[item.type] || AT_ICON_BY_TYPE.simple
|
||||
}
|
||||
|
||||
interface RowMeta {
|
||||
display?: string
|
||||
group?: string
|
||||
meta?: string
|
||||
}
|
||||
|
||||
const ROW_BASE_CLASS = [
|
||||
'relative flex w-full cursor-default select-none rounded-md px-2 py-1 text-left',
|
||||
/** The kind a row represents, for its icon. `@` rows carry it as the item type;
|
||||
* `/` rows carry it as the completion group (Skills / Themes / Commands). */
|
||||
function rowKind(item: Unstable_TriggerItem, isSlash: boolean): string {
|
||||
const meta = item.metadata as (RowMeta & { rawText?: string }) | undefined
|
||||
|
||||
if (isSlash) {
|
||||
const group = meta?.group?.trim()
|
||||
|
||||
return group === 'Skills' ? 'skill' : group === 'Themes' ? 'theme' : 'command'
|
||||
}
|
||||
|
||||
// The gateway's simple refs (`@diff`, `@staged`) share one item type, so the
|
||||
// glyph comes from the directive itself.
|
||||
const raw = meta?.rawText || item.label
|
||||
|
||||
if (raw.startsWith('@diff')) {
|
||||
return 'diff'
|
||||
}
|
||||
|
||||
if (raw.startsWith('@staged')) {
|
||||
return 'staged'
|
||||
}
|
||||
|
||||
return item.type
|
||||
}
|
||||
|
||||
const ROW_CLASS = [
|
||||
'relative flex w-full cursor-default select-none items-center gap-2 rounded-md px-2 py-1 text-left',
|
||||
'outline-hidden transition-colors hover:bg-(--ui-bg-tertiary)',
|
||||
'data-[highlighted]:bg-(--ui-bg-tertiary) data-[highlighted]:text-foreground'
|
||||
].join(' ')
|
||||
|
||||
const GROUP_HEADER_CLASS =
|
||||
'select-none px-2 pb-0.5 text-[0.625rem] font-semibold uppercase tracking-wider text-(--ui-text-tertiary)'
|
||||
|
||||
interface ComposerTriggerPopoverProps {
|
||||
activeIndex: number
|
||||
items: readonly Unstable_TriggerItem[]
|
||||
|
|
@ -62,16 +65,18 @@ interface ComposerTriggerPopoverProps {
|
|||
scope?: DirectiveScope
|
||||
}
|
||||
|
||||
/** What each scope is actually browsing, for the popover header. */
|
||||
const SCOPE_LABEL: Record<DirectiveScope, string> = {
|
||||
file: 'Files',
|
||||
folder: 'Folders',
|
||||
git: 'Git',
|
||||
image: 'Images',
|
||||
tool: 'Tools',
|
||||
url: 'URL'
|
||||
}
|
||||
|
||||
/**
|
||||
* The composer's completion list, for every trigger.
|
||||
*
|
||||
* `@` and `/` render through the SAME row: icon, name, description. They used
|
||||
* to be two layouts in one file — `@` horizontal with an icon, `/` stacked with
|
||||
* none — which is why picking a file and picking a skill felt like features
|
||||
* from different apps. Icons and accents come from the shared reference
|
||||
* vocabulary, so a row looks like the chip it will become.
|
||||
*
|
||||
* `:` emoji is the one exception: the emoji IS the icon, so it renders as a
|
||||
* single display string (Slack's exact shape).
|
||||
*/
|
||||
export function ComposerTriggerPopover({
|
||||
activeIndex,
|
||||
items,
|
||||
|
|
@ -85,6 +90,7 @@ export function ComposerTriggerPopover({
|
|||
const { t } = useI18n()
|
||||
const copy = t.composer
|
||||
const isSlash = kind === '/'
|
||||
const isEmoji = kind === ':'
|
||||
|
||||
let lastGroup: string | undefined
|
||||
|
||||
|
|
@ -96,11 +102,7 @@ export function ComposerTriggerPopover({
|
|||
onMouseDown={event => event.preventDefault()}
|
||||
role="listbox"
|
||||
>
|
||||
{scope && (
|
||||
<div className="select-none px-2 pb-0.5 pt-0.5 text-[0.625rem] font-semibold uppercase tracking-wider text-(--ui-text-tertiary)">
|
||||
{SCOPE_LABEL[scope]}
|
||||
</div>
|
||||
)}
|
||||
{scope && <div className={cn(GROUP_HEADER_CLASS, 'pt-0.5')}>{referenceStyle(scope).label}</div>}
|
||||
{items.length === 0 ? (
|
||||
loading ? (
|
||||
<div className="flex items-center gap-2 px-2 py-1.5 text-(--ui-text-tertiary)">
|
||||
|
|
@ -114,7 +116,7 @@ export function ComposerTriggerPopover({
|
|||
{copy.lookupTry} <span className="font-mono text-foreground/80">@file:</span> {copy.lookupOr}{' '}
|
||||
<span className="font-mono text-foreground/80">@folder:</span>.
|
||||
</>
|
||||
) : kind === ':' ? (
|
||||
) : isEmoji ? (
|
||||
<>
|
||||
{copy.lookupTry} <span className="font-mono text-foreground/80">:joy:</span>.
|
||||
</>
|
||||
|
|
@ -138,58 +140,26 @@ export function ComposerTriggerPopover({
|
|||
|
||||
return (
|
||||
<Fragment key={item.id}>
|
||||
{showHeader && (
|
||||
<div
|
||||
className={cn(
|
||||
'select-none px-2 pb-0.5 text-[0.625rem] font-semibold uppercase tracking-wider text-(--ui-text-tertiary)',
|
||||
isFirstHeader ? 'pt-0.5' : 'pt-2'
|
||||
)}
|
||||
>
|
||||
{group}
|
||||
</div>
|
||||
)}
|
||||
{showHeader && <div className={cn(GROUP_HEADER_CLASS, isFirstHeader ? 'pt-0.5' : 'pt-2')}>{group}</div>}
|
||||
<button
|
||||
className={cn(ROW_BASE_CLASS, isSlash ? 'flex-col gap-0' : 'items-center gap-2')}
|
||||
className={ROW_CLASS}
|
||||
data-highlighted={active ? '' : undefined}
|
||||
onClick={() => onPick(item)}
|
||||
onMouseEnter={() => onHover(index)}
|
||||
type="button"
|
||||
>
|
||||
{isSlash ? (
|
||||
<>
|
||||
{/* Active row (keyboard nav or hover) un-truncates inline so
|
||||
long command names / descriptions stay readable without a
|
||||
floating tooltip. */}
|
||||
<span
|
||||
className={cn(
|
||||
'font-medium leading-snug text-foreground',
|
||||
active ? 'whitespace-normal break-words' : 'truncate'
|
||||
)}
|
||||
>
|
||||
{display}
|
||||
</span>
|
||||
{description && (
|
||||
<span
|
||||
className={cn(
|
||||
'leading-snug text-(--ui-text-tertiary)',
|
||||
active ? 'whitespace-normal break-words' : 'truncate'
|
||||
)}
|
||||
>
|
||||
{description}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
) : kind === ':' ? (
|
||||
// Just the emoji + :shortcode:, Slack-style — no icon column.
|
||||
{isEmoji ? (
|
||||
// The emoji is its own icon — a glyph column beside it reads
|
||||
// as decoration.
|
||||
<span className="min-w-0 shrink truncate leading-5 text-foreground">{display}</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="grid size-4 shrink-0 place-items-center text-(--ui-text-tertiary)">
|
||||
<Codicon name={atIcon(item)} size="0.875rem" />
|
||||
</span>
|
||||
<span className="min-w-0 shrink truncate font-mono font-medium leading-5 text-foreground">
|
||||
{display}
|
||||
<span
|
||||
className={cn('grid size-4 shrink-0 place-items-center', referenceStyle(rowKind(item, isSlash)).color)}
|
||||
>
|
||||
<Codicon name={referenceStyle(rowKind(item, isSlash)).codicon} size="0.875rem" />
|
||||
</span>
|
||||
<span className="min-w-0 shrink truncate font-medium leading-5 text-foreground">{display}</span>
|
||||
{description && (
|
||||
<span className="min-w-0 flex-1 truncate leading-5 text-(--ui-text-tertiary)">{description}</span>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -13,46 +13,41 @@ import { useSessionLinkTitle } from '@/lib/session-link-title'
|
|||
import { parseSessionRefValue, sessionRefFallbackLabel } from '@/lib/session-refs'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
import { referenceStyle } from './reference-kinds'
|
||||
|
||||
const HERMES_REF_TYPES = ['file', 'folder', 'url', 'image', 'tool', 'line', 'terminal', 'session'] as const
|
||||
type HermesRefType = (typeof HERMES_REF_TYPES)[number]
|
||||
|
||||
/** Single source of truth for chip icon glyphs (Tabler outline @ 24×24).
|
||||
* Used both by the rendered <DirectiveIcon> and the raw SVG markup the
|
||||
* contenteditable composer embeds via `directiveIconSvg`. */
|
||||
const ICON_PATHS: Record<HermesRefType, string[]> = {
|
||||
file: [
|
||||
'M14 3v4a1 1 0 0 0 1 1h4',
|
||||
'M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2',
|
||||
'M9 9l1 0',
|
||||
'M9 13l6 0',
|
||||
'M9 17l6 0'
|
||||
],
|
||||
folder: [
|
||||
'M5 19l2.757 -7.351a1 1 0 0 1 .936 -.649h12.307a1 1 0 0 1 .986 1.164l-.996 5.211a2 2 0 0 1 -1.964 1.625h-14.026a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2'
|
||||
],
|
||||
url: [
|
||||
'M9 15l6 -6',
|
||||
'M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464',
|
||||
'M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463'
|
||||
],
|
||||
image: [
|
||||
'M15 8h.01',
|
||||
'M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12',
|
||||
'M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5',
|
||||
'M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3'
|
||||
],
|
||||
tool: ['M7 10h3v-3l-3.5 -3.5a6 6 0 0 1 8 8l6 6a2 2 0 0 1 -3 3l-6 -6a6 6 0 0 1 -8 -8l3.5 3.5'],
|
||||
line: ['M5 9l14 0', 'M5 15l14 0', 'M11 4l-4 16', 'M17 4l-4 16'],
|
||||
terminal: ['M5 7l5 5l-5 5', 'M12 19l7 0'],
|
||||
session: ['M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227']
|
||||
}
|
||||
|
||||
const ICON_FALLBACK = ['M8 12a4 4 0 1 0 8 0a4 4 0 1 0 -8 0', 'M16 12v1.5a2.5 2.5 0 0 0 5 0v-1.5a9 9 0 1 0 -5.5 8.28']
|
||||
/** Icon glyphs come from the shared reference vocabulary, so the popover row
|
||||
* and the chip can never drift apart. */
|
||||
const iconPathsFor = (type: string) => referenceStyle(type).paths
|
||||
|
||||
const SVG_ATTRS =
|
||||
'xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"'
|
||||
|
||||
const iconPathsFor = (type: string) => ICON_PATHS[type as HermesRefType] ?? ICON_FALLBACK
|
||||
/**
|
||||
* Shared chip styling — used by the rendered <DirectiveChip> and by the raw
|
||||
* HTML composer chips in `rich-editor.ts`.
|
||||
*
|
||||
* A chip is inline TEXT, not a badge: no background, no padding, no border.
|
||||
* The icon says what kind of thing it is and the color reinforces it, which is
|
||||
* all the signal a reference needs when it's sitting in the middle of a
|
||||
* sentence — a filled pill turns every mention into a UI element the eye has
|
||||
* to step over. Per-kind color comes from REFERENCE_STYLES so a `@file:` reads
|
||||
* the same here as it does in the popover you picked it from.
|
||||
*
|
||||
* Font size is inherited rather than shrunk: a reference is content the user
|
||||
* chose, and rendering it smaller than the words around it reads as a
|
||||
* footnote. With no vertical padding the glyphs sit in the normal line box, so
|
||||
* `align-baseline` is enough — no nudge needed.
|
||||
*/
|
||||
export const DIRECTIVE_CHIP_CLASS = 'inline-flex max-w-56 items-baseline gap-1 align-baseline font-medium leading-none'
|
||||
|
||||
/** Per-kind chip classes: the shared shape plus the kind's own color. */
|
||||
export function directiveChipClass(type: string): string {
|
||||
return `${DIRECTIVE_CHIP_CLASS} ${referenceStyle(type).color}`
|
||||
}
|
||||
|
||||
|
||||
/** SVG markup string for embedding directly in HTML (composer contenteditable). */
|
||||
export function directiveIconSvg(type: string) {
|
||||
|
|
@ -60,12 +55,12 @@ export function directiveIconSvg(type: string) {
|
|||
.map(d => `<path d="${d}"/>`)
|
||||
.join('')
|
||||
|
||||
return `<svg ${SVG_ATTRS} class="size-3 shrink-0 opacity-80">${inner}</svg>`
|
||||
return `<svg ${SVG_ATTRS} class="size-[0.875em] shrink-0 opacity-80">${inner}</svg>`
|
||||
}
|
||||
|
||||
function iconElementFromPaths(paths: string[]) {
|
||||
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
||||
svg.setAttribute('class', 'size-3 shrink-0 opacity-80')
|
||||
svg.setAttribute('class', 'size-[0.875em] shrink-0 opacity-80')
|
||||
svg.setAttribute('fill', 'none')
|
||||
svg.setAttribute('stroke', 'currentColor')
|
||||
svg.setAttribute('stroke-linecap', 'round')
|
||||
|
|
@ -87,45 +82,24 @@ export function directiveIconElement(type: string) {
|
|||
return iconElementFromPaths(iconPathsFor(type))
|
||||
}
|
||||
|
||||
/** Per-type slash-command pill styling. The composer inserts these chips when a
|
||||
* command is picked; the kind drives a theme-aware accent so commands, skills,
|
||||
* and themes read distinctly (Cursor-style). */
|
||||
/** Slash pills are references too — commands, skills, and themes are just
|
||||
* three more kinds in the shared vocabulary, so they share the chip shape and
|
||||
* read their icon + accent from the same table. */
|
||||
export type SlashChipKind = 'command' | 'skill' | 'theme'
|
||||
|
||||
const SLASH_ICON_PATHS: Record<SlashChipKind, string[]> = {
|
||||
command: ['M5 7l5 5l-5 5', 'M12 19l7 0'],
|
||||
skill: ['M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11'],
|
||||
theme: [
|
||||
'M3 21v-4a4 4 0 1 1 4 4h-4',
|
||||
'M21 3a16 16 0 0 0 -12.8 10.2',
|
||||
'M21 3a16 16 0 0 1 -10.2 12.8',
|
||||
'M10.6 9a9 9 0 0 1 4.4 4.4'
|
||||
]
|
||||
}
|
||||
|
||||
const SLASH_CHIP_VARIANT: Record<SlashChipKind, string> = {
|
||||
command:
|
||||
'bg-[color-mix(in_srgb,var(--ui-accent)_14%,transparent)] text-[color-mix(in_srgb,var(--ui-accent)_82%,var(--foreground))]',
|
||||
skill:
|
||||
'bg-[color-mix(in_srgb,var(--ui-warm)_18%,transparent)] text-[color-mix(in_srgb,var(--ui-warm)_82%,var(--foreground))]',
|
||||
theme:
|
||||
'bg-[color-mix(in_srgb,var(--ui-accent-secondary)_16%,transparent)] text-[color-mix(in_srgb,var(--ui-accent-secondary)_82%,var(--foreground))]'
|
||||
}
|
||||
|
||||
export const SLASH_CHIP_BASE_CLASS =
|
||||
'mx-0.5 inline-flex max-w-64 items-center gap-1 rounded px-1.5 py-0.5 align-[-0.12em] text-[0.86em] font-medium leading-none'
|
||||
export const SLASH_CHIP_BASE_CLASS = DIRECTIVE_CHIP_CLASS
|
||||
|
||||
export function slashChipClass(kind: SlashChipKind): string {
|
||||
return `${SLASH_CHIP_BASE_CLASS} ${SLASH_CHIP_VARIANT[kind]}`
|
||||
return directiveChipClass(kind)
|
||||
}
|
||||
|
||||
export function slashIconElement(kind: SlashChipKind) {
|
||||
return iconElementFromPaths(SLASH_ICON_PATHS[kind])
|
||||
return iconElementFromPaths(iconPathsFor(kind))
|
||||
}
|
||||
|
||||
const DirectiveIcon: FC<{ type: string; className?: string }> = ({
|
||||
type,
|
||||
className = 'size-3 shrink-0 opacity-80'
|
||||
className = 'size-[0.875em] shrink-0 opacity-80'
|
||||
}) => (
|
||||
<svg
|
||||
className={className}
|
||||
|
|
@ -143,18 +117,6 @@ const DirectiveIcon: FC<{ type: string; className?: string }> = ({
|
|||
</svg>
|
||||
)
|
||||
|
||||
/** Shared chip styling — used by both the rendered <DirectiveChip> and the
|
||||
* raw HTML composer chips in `rich-editor.ts`. Neutral subtle wash + plain
|
||||
* muted-foreground text so chips read as quiet tags on any bubble color.
|
||||
*
|
||||
* `align-[-0.12em]` rather than `align-middle`: `middle` centers the pill on
|
||||
* the x-height midpoint, which sits above the center of the surrounding text
|
||||
* box, so the chip visibly rides low next to the words it's nestled in. The
|
||||
* em nudge lands the chip's own text baseline on the line's baseline (measured
|
||||
* to within 0.08px) without growing the line box. */
|
||||
export const DIRECTIVE_CHIP_CLASS =
|
||||
'mx-0.5 inline-flex max-w-56 items-center gap-1 rounded px-1.5 py-0.5 align-[-0.12em] text-[0.86em] font-normal leading-none bg-[color-mix(in_srgb,currentColor_8%,transparent)] text-muted-foreground'
|
||||
|
||||
/**
|
||||
* Parses our composer's `@type:value` references into directive segments
|
||||
* so they render as inline chips in user messages instead of raw text.
|
||||
|
|
@ -555,20 +517,7 @@ export const SessionRefLink: FC<{
|
|||
* composer's slash pill, so a picked skill stays a chip after send. */
|
||||
const SlashChip: FC<{ kind: SlashChipKind; label: string; value: string }> = ({ kind, label, value }) => (
|
||||
<span className={slashChipClass(kind)} data-slot="aui_slash-chip" title={value}>
|
||||
<svg
|
||||
className="size-3 shrink-0 opacity-80"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
{SLASH_ICON_PATHS[kind].map(d => (
|
||||
<path d={d} key={d} />
|
||||
))}
|
||||
</svg>
|
||||
<DirectiveIcon type={kind} />
|
||||
<span className="truncate">{label}</span>
|
||||
</span>
|
||||
)
|
||||
|
|
@ -589,7 +538,7 @@ const DirectiveChip: FC<{
|
|||
)
|
||||
|
||||
const props = {
|
||||
className: cn(DIRECTIVE_CHIP_CLASS, onClick && 'cursor-pointer transition-colors hover:text-foreground'),
|
||||
className: cn(directiveChipClass(type), onClick && 'cursor-pointer transition-colors hover:text-foreground'),
|
||||
'data-directive-id': id,
|
||||
'data-directive-type': type,
|
||||
'data-slot': 'aui_directive-chip',
|
||||
|
|
|
|||
145
apps/desktop/src/components/assistant-ui/reference-kinds.ts
Normal file
145
apps/desktop/src/components/assistant-ui/reference-kinds.ts
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
* The composer's reference vocabulary: one place that decides what a `@file:`,
|
||||
* a `@folder:`, a picked `/skill`, or any other reference LOOKS like — its
|
||||
* icon, its accent, and the word for its kind.
|
||||
*
|
||||
* Both surfaces that show a reference read from this table:
|
||||
*
|
||||
* - the trigger popover row (browsing for one)
|
||||
* - the chip (having picked one)
|
||||
*
|
||||
* so a thing is the same color with the same glyph wherever you meet it. They
|
||||
* used to be two hand-maintained icon maps and two unrelated row layouts, which
|
||||
* is why `@` and `/` looked like features from different apps.
|
||||
*/
|
||||
|
||||
/** Every kind of thing the composer can reference. */
|
||||
export type ReferenceKind =
|
||||
| 'file'
|
||||
| 'folder'
|
||||
| 'url'
|
||||
| 'image'
|
||||
| 'tool'
|
||||
| 'line'
|
||||
| 'terminal'
|
||||
| 'session'
|
||||
| 'git'
|
||||
| 'diff'
|
||||
| 'staged'
|
||||
| 'command'
|
||||
| 'skill'
|
||||
| 'theme'
|
||||
| 'emoji'
|
||||
| 'other'
|
||||
|
||||
interface ReferenceStyle {
|
||||
/** Codicon name — the popover row's leading glyph. */
|
||||
codicon: string
|
||||
/** Tabler outline path data — the chip's inline SVG. */
|
||||
paths: string[]
|
||||
/** Chip text color. Chips are text-only now, so this carries the whole
|
||||
* signal for "what kind of thing is this". */
|
||||
color: string
|
||||
/** Section label when the popover groups by this kind. */
|
||||
label: string
|
||||
}
|
||||
|
||||
// Accents map to the theme's own tokens rather than raw hues, so a reference
|
||||
// keeps its meaning across every skin. Files/folders/paths share the neutral
|
||||
// secondary text color — they're the common case and shouldn't shout; the
|
||||
// things that ACT (commands, skills) take the accent colors.
|
||||
const NEUTRAL = 'text-(--ui-text-secondary)'
|
||||
const ACCENT = 'text-[color-mix(in_srgb,var(--ui-accent)_82%,var(--foreground))]'
|
||||
const WARM = 'text-[color-mix(in_srgb,var(--ui-warm)_82%,var(--foreground))]'
|
||||
const SECONDARY = 'text-[color-mix(in_srgb,var(--ui-accent-secondary)_82%,var(--foreground))]'
|
||||
|
||||
const FILE_PATHS = [
|
||||
'M14 3v4a1 1 0 0 0 1 1h4',
|
||||
'M17 21h-10a2 2 0 0 1 -2 -2v-14a2 2 0 0 1 2 -2h7l5 5v11a2 2 0 0 1 -2 2',
|
||||
'M9 9l1 0',
|
||||
'M9 13l6 0',
|
||||
'M9 17l6 0'
|
||||
]
|
||||
|
||||
const TERMINAL_PATHS = ['M5 7l5 5l-5 5', 'M12 19l7 0']
|
||||
|
||||
export const REFERENCE_STYLES: Record<ReferenceKind, ReferenceStyle> = {
|
||||
file: { codicon: 'file', paths: FILE_PATHS, color: NEUTRAL, label: 'Files' },
|
||||
folder: {
|
||||
codicon: 'folder',
|
||||
paths: [
|
||||
'M5 19l2.757 -7.351a1 1 0 0 1 .936 -.649h12.307a1 1 0 0 1 .986 1.164l-.996 5.211a2 2 0 0 1 -1.964 1.625h-14.026a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2'
|
||||
],
|
||||
color: NEUTRAL,
|
||||
label: 'Folders'
|
||||
},
|
||||
url: {
|
||||
codicon: 'globe',
|
||||
paths: [
|
||||
'M9 15l6 -6',
|
||||
'M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464',
|
||||
'M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463'
|
||||
],
|
||||
color: SECONDARY,
|
||||
label: 'Links'
|
||||
},
|
||||
image: {
|
||||
codicon: 'file-media',
|
||||
paths: [
|
||||
'M15 8h.01',
|
||||
'M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12',
|
||||
'M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5',
|
||||
'M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3'
|
||||
],
|
||||
color: SECONDARY,
|
||||
label: 'Images'
|
||||
},
|
||||
tool: {
|
||||
codicon: 'tools',
|
||||
paths: ['M7 10h3v-3l-3.5 -3.5a6 6 0 0 1 8 8l6 6a2 2 0 0 1 -3 3l-6 -6a6 6 0 0 1 -8 -8l3.5 3.5'],
|
||||
color: ACCENT,
|
||||
label: 'Tools'
|
||||
},
|
||||
line: {
|
||||
codicon: 'list-selection',
|
||||
paths: ['M5 9l14 0', 'M5 15l14 0', 'M11 4l-4 16', 'M17 4l-4 16'],
|
||||
color: NEUTRAL,
|
||||
label: 'Lines'
|
||||
},
|
||||
terminal: { codicon: 'terminal', paths: TERMINAL_PATHS, color: NEUTRAL, label: 'Terminal' },
|
||||
session: {
|
||||
codicon: 'comment-discussion',
|
||||
paths: ['M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227'],
|
||||
color: SECONDARY,
|
||||
label: 'Sessions'
|
||||
},
|
||||
git: { codicon: 'git-branch', paths: ['M7 18l0 -12', 'M7 8a2 2 0 1 0 0 -4a2 2 0 0 0 0 4'], color: WARM, label: 'Git' },
|
||||
diff: { codicon: 'diff', paths: ['M12 5l0 14', 'M5 12l14 0'], color: WARM, label: 'Changes' },
|
||||
staged: { codicon: 'diff-added', paths: ['M12 5l0 14', 'M5 12l14 0'], color: WARM, label: 'Staged' },
|
||||
command: { codicon: 'terminal', paths: TERMINAL_PATHS, color: ACCENT, label: 'Commands' },
|
||||
skill: { codicon: 'zap', paths: ['M13 3l0 7l6 0l-8 11l0 -7l-6 0l8 -11'], color: WARM, label: 'Skills' },
|
||||
theme: {
|
||||
codicon: 'symbol-color',
|
||||
paths: [
|
||||
'M3 21v-4a4 4 0 1 1 4 4h-4',
|
||||
'M21 3a16 16 0 0 0 -12.8 10.2',
|
||||
'M21 3a16 16 0 0 1 -10.2 12.8',
|
||||
'M10.6 9a9 9 0 0 1 4.4 4.4'
|
||||
],
|
||||
color: SECONDARY,
|
||||
label: 'Themes'
|
||||
},
|
||||
emoji: { codicon: 'smiley', paths: [], color: NEUTRAL, label: 'Emoji' },
|
||||
other: { codicon: 'symbol-misc', paths: FILE_PATHS, color: NEUTRAL, label: 'Other' }
|
||||
}
|
||||
|
||||
const KNOWN = new Set(Object.keys(REFERENCE_STYLES))
|
||||
|
||||
/** Coerce any incoming type string to a kind we have a style for. */
|
||||
export function referenceKind(type: string | undefined): ReferenceKind {
|
||||
return type && KNOWN.has(type) ? (type as ReferenceKind) : 'other'
|
||||
}
|
||||
|
||||
export function referenceStyle(type: string | undefined): ReferenceStyle {
|
||||
return REFERENCE_STYLES[referenceKind(type)]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue