File size: 2,216 Bytes
f76c374 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | import { describe, expect, it } from 'vitest'
import { skillInvocationText } from './skill-scaffold'
// Byte-identical to what agent/skill_commands.py emits — a desktop/TUI talking
// to an older gateway sees exactly these strings.
const BODY = 'SPIN UP A WORKTREE. Never edit the primary checkout.\n'.repeat(20)
const singleSkill = (instruction?: string) =>
[
'[IMPORTANT: The user has invoked the "work" skill, indicating they want you to follow its instructions.',
'The full skill content is loaded below.]',
'',
BODY,
'',
'[Skill directory: /Users/x/skills/work]',
...(instruction
? ['', `The user has provided the following instruction alongside the skill invocation: ${instruction}`]
: [])
].join('\n')
const bundle = (instruction?: string) =>
[
'[IMPORTANT: The user has invoked the "/clean /work" stacked skill bundle, loading 2 skills together.]',
'',
'Skills loaded: clean, work',
...(instruction ? ['', `User instruction: ${instruction}`] : []),
'',
'[Loaded as part of the stacked skill invocation "clean".]',
'',
BODY
].join('\n')
describe('skillInvocationText', () => {
it('renders a single-skill turn as the invocation, never the body', () => {
const projected = skillInvocationText(singleSkill('fix the title leak'))
expect(projected).toBe('/work fix the title leak')
expect(projected).not.toContain('WORKTREE')
})
it('renders a bare invocation as just the command', () => {
expect(skillInvocationText(singleSkill())).toBe('/work')
})
it('renders a bundle turn as the typed keys plus the instruction', () => {
const projected = skillInvocationText(bundle('ship it'))
expect(projected).toBe('/clean /work ship it')
expect(projected).not.toContain('WORKTREE')
})
it('collapses newlines in a multi-line instruction so the bubble stays one line', () => {
expect(skillInvocationText(singleSkill('fix the leak\n\nthen ship'))).toBe('/work fix the leak then ship')
})
it('leaves ordinary user prose alone', () => {
expect(skillInvocationText('just a normal message')).toBeNull()
expect(skillInvocationText('[IMPORTANT: read the docs]')).toBeNull()
})
})
|