Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ result
# OpenCode
.opencode/
opencode.json

# JetBrains
.idea/
7 changes: 6 additions & 1 deletion src/core/command-generation/adapters/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}
`;
},
};
15 changes: 15 additions & 0 deletions src/utils/command-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-');
}
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export {
export { FileSystemUtils, removeMarkerBlock } from './file-system.js';

// Command reference utilities
export { transformToHyphenCommands } from './command-references.js';
export { transformToHyphenCommands, transformToCodexCommands } from './command-references.js';
10 changes: 10 additions & 0 deletions test/core/command-generation/adapters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
42 changes: 41 additions & 1 deletion test/utils/command-references.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});