Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

24.9 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import {
  applyMentionSuggestion,
  applyPickerSuggestion,
  applySlashSuggestion,
  buildNativeChatPickerItems,
  classifyNativeChatSend,
  deriveComposerAutocomplete,
  editReplacesTriggerToken,
  filterSlashCommands,
  isSkillPickerTriggered,
  isSlashCommandDraft,
  slashCommandDispatchText,
  type SlashCommandSuggestion
} from './native-chat-composer-autocomplete'
import { sessionSlashCommandSuggestions } from './native-chat/input/native-chat-slash-commands'
import type { DiscoveredSkill } from './skills'
import { getNativeChatAgentProfile } from './native-chat-agent-profiles'
import { pickedSkillsInText } from './structured-agent-session-send-mutation'

const COMMANDS: SlashCommandSuggestion[] = [
  { name: 'clear' },
  { name: 'compact' },
  { name: 'help' }
]

function skill(overrides: Partial<DiscoveredSkill>): DiscoveredSkill {
  return {
    id: overrides.name ?? 'skill',
    name: 'typescript',
    description: null,
    providers: ['codex'],
    sourceKind: 'repo',
    sourceLabel: 'Repository',
    rootPath: '/repo/.agents/skills',
    directoryPath: '/repo/.agents/skills/typescript',
    skillFilePath: '/repo/.agents/skills/typescript/SKILL.md',
    installed: true,
    updatedAt: null,
    ...overrides
  }
}

describe('deriveComposerAutocomplete — slash', () => {
  it('enters slash mode for `/` at the start and filters by query', () => {
    const result = deriveComposerAutocomplete('/cl', 3, COMMANDS)
    expect(result.mode).toBe('slash')
    if (result.mode !== 'slash') {
      return
    }
    expect(result.query).toBe('cl')
    expect(result.items.map((item) => item.name)).toEqual(['clear'])
  })

  it('a bare `/` returns the full command list', () => {
    const result = deriveComposerAutocomplete('/', 1, COMMANDS)
    expect(result.mode).toBe('slash')
    if (result.mode !== 'slash') {
      return
    }
    expect(result.items).toHaveLength(3)
  })

  it('does not fire slash mode after a space', () => {
    expect(deriveComposerAutocomplete('/clear now', 10, COMMANDS).mode).toBe('none')
  })

  it('does not fire slash mode mid-line', () => {
    expect(deriveComposerAutocomplete('hi /clear', 9, COMMANDS).mode).toBe('none')
  })
})

describe('deriveComposerAutocomplete — mention', () => {
  it('enters mention mode with the query after `@`', () => {
    const result = deriveComposerAutocomplete('look at @src/ind', 16, COMMANDS)
    expect(result.mode).toBe('mention')
    if (result.mode !== 'mention') {
      return
    }
    expect(result.query).toBe('src/ind')
  })

  it('stays closed for a dismissed `@` token until a new one starts', () => {
    const closed = deriveComposerAutocomplete('a @foo', 6, COMMANDS, [], null, undefined, '@:2')
    expect(closed.mode).toBe('none')
    const next = deriveComposerAutocomplete('a @foo @b', 9, COMMANDS, [], null, undefined, '@:2')
    expect(next.mode).toBe('mention')
  })

  it('fires at the start of input too', () => {
    const result = deriveComposerAutocomplete('@foo', 4, COMMANDS)
    expect(result.mode).toBe('mention')
    if (result.mode !== 'mention') {
      return
    }
    expect(result.query).toBe('foo')
  })

  it('does not fire for an email-like `@` (no preceding whitespace)', () => {
    expect(deriveComposerAutocomplete('me@example', 10, COMMANDS).mode).toBe('none')
  })
})

describe('deriveComposerAutocomplete — one grammar for every agent', () => {
  it('keeps selected files in intact punctuated mentions but drops deleted or longer tokens', () => {
    const picked = [{ name: 'review', path: '/review/SKILL.md' }]
    expect(pickedSkillsInText('($review), **$review**', picked)).toEqual(picked)
    expect(pickedSkillsInText('$reviewer deleted', picked)).toEqual([])
  })
  const skills = [
    skill({ name: 'typescript' }),
    skill({ name: 'react-useeffect', directoryPath: '/repo/.agents/skills/react-useeffect' })
  ]
  const codex = getNativeChatAgentProfile('codex')

  it('lists each skill Codex reported by its file, so a shared name stays two picks', () => {
    const reported = [
      { name: 'review', path: '/home/me/.agents/skills/review/SKILL.md' },
      { name: 'review', path: '/repo/.agents/skills/review/SKILL.md' },
      { name: 'work-pets:create-pet', path: '/plugins/pets/create-pet/SKILL.md' }
    ]
    const discovery = { status: 'ready' as const, skills }
    const result = deriveComposerAutocomplete('$', 1, [], skills, codex, discovery, null, reported)
    expect(result.mode === 'slash' ? result.items : []).toEqual(
      reported.map(({ name, path }) =>
        expect.objectContaining({
          token: `$${name}`,
          path,
          ...(name === 'review' ? { location: path } : {})
        })
      )
    )
  })

  it('uses provider authority, including empty, instead of scanner loading or failure', () => {
    for (const status of ['loading', 'error'] as const) {
      const discovery = { status, skills: [], errorKind: 'host' as const }
      for (const reported of [[], [{ name: 'review', path: '/review/SKILL.md' }]]) {
        const result = deriveComposerAutocomplete('$', 1, [], [], codex, discovery, null, reported)
        expect(result).toMatchObject({ mode: 'slash', skillStatus: 'ready' })
        expect(result).not.toHaveProperty('skillErrorKind')
      }
      expect(deriveComposerAutocomplete('$', 1, [], [], codex, discovery)).toMatchObject({
        mode: 'slash',
        skillStatus: status,
        skillErrorKind: 'host'
      })
    }
  })

  it('offers Codex skills under `/`, tokenised as the form Codex invokes', () => {
    const result = deriveComposerAutocomplete('use /type', 9, COMMANDS, skills, codex)
    expect(result.mode).toBe('slash')
    if (result.mode !== 'slash') {
      return
    }
    expect(result.query).toBe('type')
    expect(result.items.map((entry) => entry.token)).toEqual(['$typescript'])
  })

  it('tokenises Pi skills as `/skill:<name>`, before and after its session reports them', () => {
    const pi = getNativeChatAgentProfile('pi')
    const scanned = [skill({ name: 'caveman', description: 'On disk', sourceKind: 'home' })]
    const tokens = (sessionSkills?: { name: string }[]) => {
      const result = deriveComposerAutocomplete(
        '/cave',
        5,
        [],
        scanned,
        pi,
        undefined,
        null,
        sessionSkills
      )
      return result.mode === 'slash'
        ? result.items.map((entry) => [entry.token, entry.kind === 'skill' && entry.description])
        : []
    }
    expect(tokens()).toEqual([['/skill:caveman', 'On disk']])
    expect(tokens([{ name: 'skill:caveman' }])).toEqual([['/skill:caveman', 'On disk']])
  })

  it('does not offer scanned OMP skills or wait on a scan without native metadata', () => {
    for (const reported of [undefined, []]) {
      const result = deriveComposerAutocomplete(
        '/',
        1,
        [],
        skills,
        getNativeChatAgentProfile('omp'),
        { status: 'idle', skills },
        null,
        reported
      )
      expect(result).toMatchObject({ mode: 'slash', items: [], skillStatus: 'ready' })
    }
  })

  it('opens only Codex skills under `$`, and a pick keeps Codex `$` token', () => {
    for (const [draft, query] of [
      ['use $type', 'type'],
      ['$', '']
    ] as const) {
      const result = deriveComposerAutocomplete(draft, draft.length, COMMANDS, skills, codex)
      expect(result).toMatchObject({ mode: 'slash', prefix: '$', query, dispatchable: false })
      if (result.mode !== 'slash') {
        return
      }
      expect(result.items.every((entry) => entry.kind === 'skill')).toBe(true)
    }
    const picked = applyPickerSuggestion('use $typ now', 8, {
      kind: 'skill',
      id: 'skill:typescript',
      name: 'typescript',
      token: '$typescript',
      description: null,
      sources: []
    })
    expect(picked.draft).toBe('use $typescript  now')
  })

  it('leaves `$` as prose for agents whose skills use `/`', () => {
    const claude = getNativeChatAgentProfile('claude')
    expect(deriveComposerAutocomplete('use $type', 9, COMMANDS, skills, claude).mode).toBe('none')
  })

  it('does not fire inside shell-style text', () => {
    expect(deriveComposerAutocomplete('price$tag', 9, COMMANDS, skills, codex).mode).toBe('none')
  })

  // `echo $HOME` + Enter once swapped `$HOME` for a skill whose description named $CODEX_HOME.
  it.each(['echo $HOME', 'costs $5', 'run $(pwd)'])('leaves shell `$` in %j as prose', (draft) => {
    expect(isSkillPickerTriggered(draft, codex)).toBe(false)
    expect(deriveComposerAutocomplete(draft, draft.length, COMMANDS, skills, codex).mode).toBe(
      'none'
    )
  })

  it('matches `$` on skill names only, while `/` still searches descriptions', () => {
    const installer = [
      skill({
        name: 'skill-installer',
        description: 'Install Codex skills into $CODEX_HOME/skills'
      })
    ]
    const dollar = deriveComposerAutocomplete('echo $CODEX_HOME', 16, [], installer, codex)
    expect(dollar.mode === 'slash' && dollar.items).toEqual([])
    const slash = deriveComposerAutocomplete('use /codex_home', 15, [], installer, codex)
    expect(slash.mode === 'slash' && slash.items.map((entry) => entry.name)).toEqual([
      'skill-installer'
    ])
  })
})

describe('filterSlashCommands', () => {
  it('is case-insensitive prefix match', () => {
    expect(filterSlashCommands(COMMANDS, 'C').map((c) => c.name)).toEqual(['clear', 'compact'])
  })
})

describe('isSlashCommandDraft', () => {
  it('treats leading slash drafts as TUI commands, not chat prompts', () => {
    expect(isSlashCommandDraft('/clear')).toBe(true)
    expect(isSlashCommandDraft('  /compact')).toBe(true)
    expect(isSlashCommandDraft('please run /clear')).toBe(false)
  })
})

describe('apply suggestions', () => {
  it('applySlashSuggestion replaces the token with a trailing space', () => {
    expect(applySlashSuggestion({ name: 'clear' })).toBe('/clear ')
  })

  it('slashCommandDispatchText returns the command without completion whitespace', () => {
    expect(slashCommandDispatchText({ name: 'clear' })).toBe('/clear')
  })

  it('applyMentionSuggestion replaces the active @token at the caret', () => {
    const result = applyMentionSuggestion('open @sr more', 8, 'src/app.ts')
    expect(result.draft).toBe('open @src/app.ts more')
    expect(result.caret).toBe('open @src/app.ts '.length)
  })

  it('applyMentionSuggestion quotes a path the agent would otherwise split', () => {
    const result = applyMentionSuggestion('@my', 3, 'docs/my notes.md')
    expect(result.draft).toBe('@"docs/my notes.md" ')
  })

  it('applyPickerSuggestion swaps the typed /token for the agent-native token', () => {
    const result = applyPickerSuggestion('use /typ now', 8, {
      kind: 'skill',
      id: 'skill:typescript',
      name: 'typescript',
      token: '$typescript',
      description: null,
      sources: []
    })
    expect(result.draft).toBe('use $typescript  now')
    expect(result.caret).toBe('use $typescript '.length)
    expect(result.insertedToken).toBe('$typescript')
  })
})

describe('native skill and command picker', () => {
  it('puts Codex commands and skills in one `/` menu, each with its own token', () => {
    const slash = deriveComposerAutocomplete(
      '/',
      1,
      COMMANDS,
      [skill({ name: 'browser' })],
      getNativeChatAgentProfile('codex')
    )
    expect(slash.mode).toBe('slash')
    if (slash.mode !== 'slash') {
      return
    }
    expect(slash.grouped).toBe(true)
    expect(slash.items.filter((item) => item.kind === 'command').map((item) => item.token)).toEqual(
      ['/clear', '/compact', '/help']
    )
    expect(slash.items.filter((item) => item.kind === 'skill').map((item) => item.token)).toEqual([
      '$browser'
    ])
  })

  it('keeps a Codex command and a same-named skill as separate rows', () => {
    const result = deriveComposerAutocomplete(
      '/clear',
      6,
      COMMANDS,
      [skill({ name: 'clear' })],
      getNativeChatAgentProfile('codex')
    )
    expect(result.mode).toBe('slash')
    if (result.mode !== 'slash') {
      return
    }
    expect(result.items.map((item) => item.token)).toEqual(['/clear', '$clear'])
    expect(result.items.find((item) => item.kind === 'command')?.skillCollision).toBe(false)
  })

  it('offers the same commands and skills for a `/` typed mid-prompt as for a leading one', () => {
    const args = [
      COMMANDS,
      [skill({ name: 'electron' })],
      getNativeChatAgentProfile('claude')
    ] as const
    const leading = deriveComposerAutocomplete('/', 1, ...args)
    const midPrompt = deriveComposerAutocomplete('validate it with /', 18, ...args)
    expect(midPrompt.mode).toBe('slash')
    if (midPrompt.mode !== 'slash' || leading.mode !== 'slash') {
      return
    }
    expect(midPrompt.items).toEqual(leading.items)
    expect(midPrompt.items.map((item) => item.kind)).toContain('command')
    expect(midPrompt.items.map((item) => item.kind)).toContain('skill')
    expect(midPrompt.grouped).toBe(leading.grouped)
  })

  it('filters the mid-prompt `/` menu by the typed token', () => {
    const result = deriveComposerAutocomplete(
      'validate it with /elec',
      22,
      COMMANDS,
      [skill({ name: 'electron' })],
      getNativeChatAgentProfile('claude')
    )
    expect(result.mode).toBe('slash')
    if (result.mode === 'slash') {
      expect(result.prefix).toBe('/')
      expect(result.items.map((item) => item.name)).toEqual(['electron'])
    }
  })

  it('marks only a draft-leading `/command` dispatchable', () => {
    const profile = getNativeChatAgentProfile('claude')
    const leading = deriveComposerAutocomplete('/comp', 5, COMMANDS, [], profile)
    const midPrompt = deriveComposerAutocomplete('then /comp', 10, COMMANDS, [], profile)
    expect(leading.mode === 'slash' && leading.dispatchable).toBe(true)
    expect(midPrompt.mode === 'slash' && midPrompt.dispatchable).toBe(false)
  })

  it('leaves a mid-prompt path alone', () => {
    expect(
      deriveComposerAutocomplete(
        'open /Users/me/notes',
        20,
        COMMANDS,
        [skill({ name: 'electron' })],
        getNativeChatAgentProfile('claude')
      ).mode
    ).toBe('none')
  })

  it('opens the mid-prompt `/` menu for Codex too, tokenised for Codex', () => {
    const result = deriveComposerAutocomplete(
      'validate it with /elec',
      22,
      COMMANDS,
      [skill({ name: 'electron' })],
      getNativeChatAgentProfile('codex')
    )
    expect(result.mode).toBe('slash')
    if (result.mode !== 'slash') {
      return
    }
    expect(result.dispatchable).toBe(false)
    expect(result.items.map((item) => item.token)).toEqual(['$electron'])
  })

  it.each(['claude', 'codex'] as const)(
    'loads the skill catalog for both `/` trigger positions on %s',
    (agent) => {
      const profile = getNativeChatAgentProfile(agent)
      expect(isSkillPickerTriggered('/elec', profile)).toBe(true)
      expect(isSkillPickerTriggered('validate it with /elec', profile)).toBe(true)
      expect(isSkillPickerTriggered('open /Users/me', profile)).toBe(false)
      // Without a catalog fetch the menu would sit on a permanent loading row.
      expect(isSkillPickerTriggered('use $elec', profile)).toBe(agent === 'codex')
    }
  )

  it('applyPickerSuggestion replaces a mid-prompt /token at the caret', () => {
    const result = applyPickerSuggestion('validate it with /elec now', 22, {
      kind: 'skill',
      id: 'skill:electron',
      name: 'electron',
      token: '/electron',
      description: null,
      sources: []
    })
    expect(result.draft).toBe('validate it with /electron  now')
    expect(result.caret).toBe('validate it with /electron '.length)
  })

  it('groups Claude commands and skills under slash', () => {
    const result = deriveComposerAutocomplete(
      '/',
      1,
      COMMANDS,
      [skill({ name: 'browser' })],
      getNativeChatAgentProfile('claude')
    )
    expect(result.mode).toBe('slash')
    if (result.mode === 'slash') {
      expect(result.grouped).toBe(true)
      expect(result.items.map((item) => item.kind)).toContain('command')
      expect(result.items.map((item) => item.kind)).toContain('skill')
    }
  })

  it('lets a session report replace the disk scan and enrich the names it knows', () => {
    const items = buildNativeChatPickerItems(
      [],
      [
        skill({
          name: 'ref-oss',
          description: 'On disk',
          skillFilePath: '/home/ref-oss/SKILL.md',
          sourceKind: 'home'
        }),
        skill({ name: 'stale-on-disk', skillFilePath: '/home/stale/SKILL.md', sourceKind: 'home' })
      ],
      '',
      '/',
      [{ name: 'dataviz' }, { name: 'ref-oss' }]
    )
    // Keep only reported skills; unscanned reports sort after located skills without inventing scope.
    expect(items.map((item) => item.name)).toEqual(['ref-oss', 'dataviz'])
    expect(items[0]).toMatchObject({ kind: 'skill', description: 'On disk' })
    expect(items[1]).toMatchObject({ kind: 'skill', description: null, sources: [] })
  })

  it('keeps the first reported description for duplicate unlocated skill names', () => {
    const items = buildNativeChatPickerItems([], [], '', '/', [
      { name: 'missing' },
      { name: 'missing', description: 'Later description' },
      { name: 'present', description: 'First description' },
      { name: 'present', description: 'Later description' }
    ])
    expect(items).toMatchObject([
      { name: 'missing', description: null },
      { name: 'present', description: 'First description' }
    ])
  })

  it('keeps the disk scan only when a session report is absent', () => {
    const items = buildNativeChatPickerItems(
      [],
      [skill({ name: 'ref-oss', skillFilePath: '/home/ref-oss/SKILL.md' })],
      '',
      '/',
      undefined
    )
    expect(items.map((item) => item.name)).toEqual(['ref-oss'])
    expect(buildNativeChatPickerItems([], [skill({})], '', '/', [])).toEqual([])
  })

  it('rejects a session-reported name that is not a safe insertion token', () => {
    const items = buildNativeChatPickerItems([], [], '', '/', [
      { name: 'ok' },
      { name: 'two words' },
      { name: 'cle\u200bar' }
    ])
    expect(items.map((item) => item.name)).toEqual(['ok'])
  })

  it('ranks exact, prefix, fuzzy, then description matches within a group', () => {
    const items = buildNativeChatPickerItems(
      [],
      [
        skill({ name: 'deploy', skillFilePath: '/1/SKILL.md' }),
        skill({ name: 'deployment', skillFilePath: '/2/SKILL.md' }),
        skill({ name: 'd-e-p-l-o-y', skillFilePath: '/3/SKILL.md' }),
        skill({
          name: 'release',
          description: 'Deploy an application',
          skillFilePath: '/4/SKILL.md'
        })
      ],
      'deploy',
      '$'
    )
    expect(items.map((item) => item.name)).toEqual([
      'deploy',
      'deployment',
      'd-e-p-l-o-y',
      'release'
    ])
  })

  it('merges duplicate names but annotates command collisions on one command row', () => {
    const duplicateSkills = [
      skill({ name: 'clear', skillFilePath: '/project/clear/SKILL.md', sourceKind: 'repo' }),
      skill({ name: 'clear', skillFilePath: '/home/clear/SKILL.md', sourceKind: 'home' })
    ]
    const skillOnly = buildNativeChatPickerItems([], duplicateSkills, '', '$')
    expect(skillOnly).toEqual([
      expect.objectContaining({ kind: 'skill', name: 'clear', sources: expect.any(Array) })
    ])
    expect(skillOnly[0].kind === 'skill' ? skillOnly[0].sources : []).toHaveLength(2)

    const collision = buildNativeChatPickerItems(COMMANDS, duplicateSkills, 'clear', '/')
    expect(collision).toEqual([
      expect.objectContaining({ kind: 'command', name: 'clear', skillCollision: true })
    ])
  })

  it('keeps a long token-safe name intact for insertion instead of truncating it', () => {
    const longName = `skill-${'x'.repeat(100)}`
    const items = buildNativeChatPickerItems(
      [],
      [skill({ name: longName, skillFilePath: '/long/SKILL.md' })],
      '',
      '$'
    )
    expect(items.map((item) => item.name)).toEqual([longName])
    const applied = applyPickerSuggestion('/sk', 3, items[0])
    expect(applied.draft).toBe(`$${longName} `)
  })

  it('rejects names carrying zero-width characters instead of inserting them', () => {
    const items = buildNativeChatPickerItems(
      [],
      [
        skill({
          name: 'cle\u200bar',
          directoryPath: '/repo/.agents/skills/safe-dir',
          skillFilePath: '/repo/.agents/skills/safe-dir/SKILL.md'
        })
      ],
      '',
      '$'
    )
    expect(items.map((item) => item.name)).toEqual(['safe-dir'])
  })

  it('falls back to a token-safe directory name and strips unsafe display text', () => {
    const items = buildNativeChatPickerItems(
      [],
      [
        skill({
          name: 'Spoof\u202e Name',
          directoryPath: '/repo/.agents/skills/safe-name',
          skillFilePath: '/repo/.agents/skills/safe-name/SKILL.md'
        })
      ],
      '',
      '$'
    )
    expect(items.map((item) => item.name)).toEqual(['safe-name'])
  })

  it('replaces only the active slash token and preserves text after the caret', () => {
    const result = applyPickerSuggestion('/bro trailing', 4, {
      kind: 'skill',
      id: 'skill:browser',
      name: 'browser',
      token: '/browser',
      description: null,
      sources: []
    })
    expect(result.draft).toBe('/browser  trailing')
    expect(result.caret).toBe('/browser '.length)
  })

  it('classifies sends only from the origin tag and exact command catalog', () => {
    expect(classifyNativeChatSend('/browser do work', COMMANDS, '/browser', '/')).toBe('chat')
    expect(classifyNativeChatSend('/clear', COMMANDS, null, '/')).toBe('command')
    expect(classifyNativeChatSend('/Clear', COMMANDS, null, '/')).toBe('unknown-token')
    expect(classifyNativeChatSend('/usr/bin/python is missing', COMMANDS, null, '/')).toBe(
      'unknown-token'
    )
    expect(classifyNativeChatSend('ordinary prompt', COMMANDS, null, '/')).toBe('chat')
  })

  it('leading whitespace makes a slash draft prose, never a dispatched command', () => {
    expect(classifyNativeChatSend(' /clear', COMMANDS, null, '/')).toBe('chat')
  })

  it('treats a leading $ token as unknown only for the $-prefix (Codex) profile', () => {
    expect(classifyNativeChatSend('$deploy now', COMMANDS, null, '$')).toBe('unknown-token')
    expect(classifyNativeChatSend('$PATH is wrong', COMMANDS, null, '/')).toBe('chat')
    expect(classifyNativeChatSend('$50 is the budget', COMMANDS, null, null)).toBe('chat')
  })

  it('treats a one-edit token swap as a new trigger occurrence', () => {
    expect(editReplacesTriggerToken('/foo', '/bar', '/:0')).toBe(true)
    expect(editReplacesTriggerToken('use /foo', 'use /bar', '/:4')).toBe(true)
  })

  it('keeps suppression while typing or deleting inside the dismissed token', () => {
    expect(editReplacesTriggerToken('/foo', '/food', '/:0')).toBe(false)
    expect(editReplacesTriggerToken('/food', '/foo', '/:0')).toBe(false)
    expect(editReplacesTriggerToken('use /foo now', 'ran /foo now', '/:4')).toBe(false)
  })

  it('suppresses only the dismissed trigger occurrence', () => {
    const profile = getNativeChatAgentProfile('codex')
    expect(deriveComposerAutocomplete('use /bro', 8, COMMANDS, [skill({})], profile).mode).toBe(
      'slash'
    )
    expect(
      deriveComposerAutocomplete(
        'use /bro',
        8,
        COMMANDS,
        [skill({})],
        profile,
        { status: 'ready', skills: [skill({})] },
        '/:4'
      ).mode
    ).toBe('none')
  })
})

it('preserves known skill completion for unclassified session members only', () => {
  const commands = sessionSlashCommandSuggestions('claude', [
    { name: 'clear', kind: 'command', kindUnspecified: true },
    { name: 'typescript', kind: 'command', kindUnspecified: true },
    { name: 'project-check', kind: 'command', kindUnspecified: true }
  ])
  const diskSkills = [
    skill({ description: 'TypeScript skill' }),
    skill({ name: 'not-loaded', skillFilePath: '/not-loaded/SKILL.md' })
  ]
  const items = buildNativeChatPickerItems(commands, diskSkills, '', '/', [])
  expect(items.map(({ name, kind }) => ({ name, kind }))).toEqual([
    { name: 'clear', kind: 'command' },
    { name: 'project-check', kind: 'command' },
    { name: 'typescript', kind: 'skill' }
  ])
  expect(items[2]).toMatchObject({
    description: 'TypeScript skill',
    sources: [{ sourceKind: 'repo' }]
  })
  const classified = sessionSlashCommandSuggestions('claude', [
    { name: 'typescript', kind: 'command' }
  ])
  expect(
    buildNativeChatPickerItems(classified, diskSkills, '', '/', []).map(({ kind }) => kind)
  ).toEqual(['command'])
})

it('selected slash membership uses real token starts and keeps Codex provider membership dollar-only', () => {
  const picked = [{ name: 'model', path: '/A/SKILL.md' }]
  for (const text of ['/model', 'use /model,', '/model\nnext']) {
    expect(pickedSkillsInText(text, picked, ['$', '/'])).toEqual(picked)
    expect(pickedSkillsInText(text, picked)).toEqual([])
  }
  for (const text of ['/dir/model', '/model-extra', '/model:other', 'prefix/model']) {
    expect(pickedSkillsInText(text, picked, ['$', '/'])).toEqual([])
  }
})