-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathopencode.ts
More file actions
47 lines (40 loc) · 1.44 KB
/
opencode.ts
File metadata and controls
47 lines (40 loc) · 1.44 KB
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
/**
* OpenCode Command Adapter
*
* Formats commands for OpenCode following its frontmatter specification.
* OpenCode custom commands live in the global home directory
* (~/.config/opencode/commands/) and are not shared through the repository.
* The OPENCODE_HOME env var can override the default ~/.config/opencode location.
*/
import os from 'os';
import path from 'path';
import type { CommandContent, ToolCommandAdapter } from '../types.js';
import { transformToHyphenCommands } from '../../../utils/command-references.js';
/**
* Returns the OpenCode home directory.
* Respects the OPENCODE_HOME env var, defaulting to ~/.config/opencode.
*/
function getOpenCodeHome(): string {
const envHome = process.env.OPENCODE_HOME?.trim();
return path.resolve(envHome ? envHome : path.join(os.homedir(), '.config', 'opencode'));
}
/**
* OpenCode adapter for command generation.
* File path: <OPENCODE_HOME>/commands/opsx-<id>.md (absolute, global)
* Frontmatter: description
*/
export const opencodeAdapter: ToolCommandAdapter = {
toolId: 'opencode',
getFilePath(commandId: string): string {
return path.join(getOpenCodeHome(), 'commands', `opsx-${commandId}.md`);
},
formatFile(content: CommandContent): string {
// Transform command references from colon to hyphen format for OpenCode
const transformedBody = transformToHyphenCommands(content.body);
return `---
description: ${content.description}
---
${transformedBody}
`;
},
};