From 503de29c8e5c0685fdf78453e2b05421e5cb7b8c Mon Sep 17 00:00:00 2001 From: zhuxf Date: Tue, 3 Feb 2026 12:18:46 +0800 Subject: [PATCH] Fix Codex prompt args and command references --- .gitignore | 3 ++ src/core/command-generation/adapters/codex.ts | 7 +++- src/utils/command-references.ts | 15 +++++++ src/utils/index.ts | 2 +- test/core/command-generation/adapters.test.ts | 10 +++++ test/utils/command-references.test.ts | 42 ++++++++++++++++++- 6 files changed, 76 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index abea4d16..5019e779 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,6 @@ result # OpenCode .opencode/ opencode.json + +# JetBrains +.idea/ diff --git a/src/core/command-generation/adapters/codex.ts b/src/core/command-generation/adapters/codex.ts index 64e73550..e1238264 100644 --- a/src/core/command-generation/adapters/codex.ts +++ b/src/core/command-generation/adapters/codex.ts @@ -10,6 +10,7 @@ import os from 'os'; import path from 'path'; import type { CommandContent, ToolCommandAdapter } from '../types.js'; +import { transformToCodexCommands } from '../../../utils/command-references.js'; /** * Returns the Codex home directory. @@ -33,12 +34,16 @@ export const codexAdapter: ToolCommandAdapter = { }, formatFile(content: CommandContent): string { + const transformedBody = transformToCodexCommands(content.body); + return `--- description: ${content.description} argument-hint: command arguments --- -${content.body} +$ARGUMENTS + +${transformedBody} `; }, }; diff --git a/src/utils/command-references.ts b/src/utils/command-references.ts index bfa49b9f..f2b4246b 100644 --- a/src/utils/command-references.ts +++ b/src/utils/command-references.ts @@ -18,3 +18,18 @@ export function transformToHyphenCommands(text: string): string { return text.replace(/\/opsx:/g, '/opsx-'); } + +/** + * Transforms command references to Codex prompt format. + * Converts `/opsx:` or `/opsx-` patterns to `/prompts:opsx-`. + * + * @param text - The text containing command references + * @returns Text with command references transformed to Codex format + * + * @example + * transformToCodexCommands('/opsx:new') // returns '/prompts:opsx-new' + * transformToCodexCommands('Use /opsx-apply to implement') // returns 'Use /prompts:opsx-apply to implement' + */ +export function transformToCodexCommands(text: string): string { + return text.replace(/\/opsx:/g, '/prompts:opsx-').replace(/\/opsx-/g, '/prompts:opsx-'); +} diff --git a/src/utils/index.ts b/src/utils/index.ts index e77ddf47..d4fba359 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -15,4 +15,4 @@ export { export { FileSystemUtils, removeMarkerBlock } from './file-system.js'; // Command reference utilities -export { transformToHyphenCommands } from './command-references.js'; \ No newline at end of file +export { transformToHyphenCommands, transformToCodexCommands } from './command-references.js'; diff --git a/test/core/command-generation/adapters.test.ts b/test/core/command-generation/adapters.test.ts index 5341f6a2..25245719 100644 --- a/test/core/command-generation/adapters.test.ts +++ b/test/core/command-generation/adapters.test.ts @@ -251,8 +251,18 @@ describe('command-generation/adapters', () => { expect(output).toContain('description: Enter explore mode for thinking'); expect(output).toContain('argument-hint: command arguments'); expect(output).toContain('---\n\n'); + expect(output).toContain('$ARGUMENTS'); expect(output).toContain('This is the command body.'); }); + + it('should transform command references to Codex format', () => { + const contentWithCommand = { + ...sampleContent, + body: 'Run /opsx:apply to implement.', + }; + const output = codexAdapter.formatFile(contentWithCommand); + expect(output).toContain('Run /prompts:opsx-apply to implement.'); + }); }); describe('codebuddyAdapter', () => { diff --git a/test/utils/command-references.test.ts b/test/utils/command-references.test.ts index c7ff2ed8..af18518d 100644 --- a/test/utils/command-references.test.ts +++ b/test/utils/command-references.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { transformToHyphenCommands } from '../../src/utils/command-references.js'; +import { transformToHyphenCommands, transformToCodexCommands } from '../../src/utils/command-references.js'; describe('transformToHyphenCommands', () => { describe('basic transformations', () => { @@ -81,3 +81,43 @@ Finally /opsx-apply to implement`; } }); }); + +describe('transformToCodexCommands', () => { + describe('basic transformations', () => { + it('should transform colon command references', () => { + expect(transformToCodexCommands('/opsx:new')).toBe('/prompts:opsx-new'); + }); + + it('should transform hyphen command references', () => { + expect(transformToCodexCommands('/opsx-apply')).toBe('/prompts:opsx-apply'); + }); + + it('should transform multiple command references', () => { + const input = 'Use /opsx:new then /opsx-apply'; + const expected = 'Use /prompts:opsx-new then /prompts:opsx-apply'; + expect(transformToCodexCommands(input)).toBe(expected); + }); + + it('should handle backtick-quoted commands', () => { + const input = 'Run `/opsx:continue` to proceed'; + const expected = 'Run `/prompts:opsx-continue` to proceed'; + expect(transformToCodexCommands(input)).toBe(expected); + }); + }); + + describe('edge cases', () => { + it('should return unchanged text with no command references', () => { + const input = 'This is plain text without commands'; + expect(transformToCodexCommands(input)).toBe(input); + }); + + it('should return empty string unchanged', () => { + expect(transformToCodexCommands('')).toBe(''); + }); + + it('should not transform similar but non-matching patterns', () => { + const input = '/ops:new opsx: /other:command'; + expect(transformToCodexCommands(input)).toBe(input); + }); + }); +});