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
@@ -114,6 +114,8 @@ describe('listSlashCommands', () => {
const commands = await listSlashCommands('codex', projectDir)
expect(commands.map((command) => command.name)).toEqual(expect.arrayContaining([
'clear',
'compact',
'plan',
'status',
'model',
@@ -122,6 +124,21 @@ describe('listSlashCommands', () => {
]))
})
it('lets project codex prompts override same-name built-ins', async () => {
await writeFile(
join(projectDir, '.codex', 'prompts', 'clear.md'),
['---', 'description: Project clear', '---', '', 'Project clear prompt'].join('\n')
)
const commands = await listSlashCommands('codex', projectDir)
const clearCommands = commands.filter(cmd => cmd.name === 'clear')
expect(clearCommands).toHaveLength(1)
expect(clearCommands[0]?.source).toBe('project')
expect(clearCommands[0]?.description).toBe('Project clear')
expect(clearCommands[0]?.content).toBe('Project clear prompt')
})
it('loads Codex global and project prompts', async () => {
await writeFile(
join(codexHome, 'prompts', 'global-prompt.md'),
+2
View File
@@ -33,6 +33,8 @@ const BUILTIN_COMMANDS: Record<string, SlashCommand[]> = {
{ name: 'plan', description: 'Toggle plan mode', source: 'builtin' },
],
codex: [
{ name: 'clear', description: 'Clear current Codex thread context', source: 'builtin' },
{ name: 'compact', description: 'Compact current Codex thread context', source: 'builtin' },
{ name: 'help', description: 'Show supported HAPI Codex slash commands', source: 'builtin' },
{ name: 'plan', description: 'Enable plan mode; use /plan off to return to default', source: 'builtin' },
{ name: 'default', description: 'Return Codex collaboration mode to default', source: 'builtin' },