Add Codex clear and compact slash commands (#541)

* Add Codex clear and compact slash commands

* Stabilize queued thinking event test

* Interrupt active Codex turn before slash commands
This commit is contained in:
NightWatcher314
2026-04-29 14:15:44 +08:00
committed by GitHub
parent 0160da4bb5
commit a612be50d6
15 changed files with 460 additions and 16 deletions
+43 -1
View File
@@ -1,9 +1,16 @@
import { describe, expect, it } from 'vitest'
import { findUnsupportedCodexBuiltinSlashCommand, getBuiltinSlashCommands } from './codexSlashCommands'
import {
findCodexCustomPromptExpansion,
findUnsupportedCodexBuiltinSlashCommand,
getBuiltinSlashCommands,
mergeSlashCommands
} from './codexSlashCommands'
describe('getBuiltinSlashCommands', () => {
it('exposes HAPI-supported codex built-ins in remote web mode', () => {
expect(getBuiltinSlashCommands('codex').map((command) => command.name)).toEqual(expect.arrayContaining([
'clear',
'compact',
'plan',
'status',
'execute',
@@ -13,6 +20,41 @@ describe('getBuiltinSlashCommands', () => {
})
})
describe('mergeSlashCommands', () => {
it('lets custom commands override same-name built-ins', () => {
const commands = mergeSlashCommands([
{ name: 'clear', source: 'builtin' },
{ name: 'compact', source: 'builtin' },
{ name: 'clear', source: 'project', content: 'project clear prompt' }
])
expect(commands).toEqual([
{ name: 'compact', source: 'builtin' },
{ name: 'clear', source: 'project', content: 'project clear prompt' }
])
})
})
describe('findCodexCustomPromptExpansion', () => {
it('expands exact custom codex prompt commands', () => {
expect(findCodexCustomPromptExpansion(' /clear ', [
{ name: 'clear', source: 'builtin' },
{ name: 'clear', source: 'project', content: 'custom clear prompt' }
])).toBe('custom clear prompt')
})
it('ignores built-ins and commands with arguments', () => {
const commands = [
{ name: 'compact', source: 'project', content: 'custom compact prompt' }
] as const
expect(findCodexCustomPromptExpansion('/compact now', commands)).toBeNull()
expect(findCodexCustomPromptExpansion('/clear', [
{ name: 'clear', source: 'builtin' }
])).toBeNull()
})
})
describe('findUnsupportedCodexBuiltinSlashCommand', () => {
it('detects unsupported codex built-ins', () => {
expect(findUnsupportedCodexBuiltinSlashCommand(' /diff ', [])).toBe('diff')