fix(slashcommand): use slash separator for nested commands
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -250,7 +250,7 @@ Use nested command.
|
|||||||
)
|
)
|
||||||
|
|
||||||
const commands = discoverCommandsSync(projectDir)
|
const commands = discoverCommandsSync(projectDir)
|
||||||
const nestedCommand = commands.find((command) => command.name === "refactor:code")
|
const nestedCommand = commands.find((command) => command.name === "refactor/code")
|
||||||
|
|
||||||
expect(nestedCommand?.content).toContain("Use nested command.")
|
expect(nestedCommand?.content).toContain("Use nested command.")
|
||||||
expect(nestedCommand?.scope).toBe("opencode-project")
|
expect(nestedCommand?.scope).toBe("opencode-project")
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ export interface CommandDiscoveryOptions {
|
|||||||
enabledPluginsOverride?: Record<string, boolean>
|
enabledPluginsOverride?: Record<string, boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const NESTED_COMMAND_SEPARATOR = "/"
|
||||||
|
|
||||||
function discoverCommandsFromDir(
|
function discoverCommandsFromDir(
|
||||||
commandsDir: string,
|
commandsDir: string,
|
||||||
scope: CommandScope,
|
scope: CommandScope,
|
||||||
@@ -31,7 +33,9 @@ function discoverCommandsFromDir(
|
|||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (entry.isDirectory()) {
|
if (entry.isDirectory()) {
|
||||||
if (entry.name.startsWith(".")) continue
|
if (entry.name.startsWith(".")) continue
|
||||||
const nestedPrefix = prefix ? `${prefix}:${entry.name}` : entry.name
|
const nestedPrefix = prefix
|
||||||
|
? `${prefix}${NESTED_COMMAND_SEPARATOR}${entry.name}`
|
||||||
|
: entry.name
|
||||||
commands.push(
|
commands.push(
|
||||||
...discoverCommandsFromDir(join(commandsDir, entry.name), scope, nestedPrefix),
|
...discoverCommandsFromDir(join(commandsDir, entry.name), scope, nestedPrefix),
|
||||||
)
|
)
|
||||||
@@ -42,7 +46,9 @@ function discoverCommandsFromDir(
|
|||||||
|
|
||||||
const commandPath = join(commandsDir, entry.name)
|
const commandPath = join(commandsDir, entry.name)
|
||||||
const baseCommandName = basename(entry.name, ".md")
|
const baseCommandName = basename(entry.name, ".md")
|
||||||
const commandName = prefix ? `${prefix}:${baseCommandName}` : baseCommandName
|
const commandName = prefix
|
||||||
|
? `${prefix}${NESTED_COMMAND_SEPARATOR}${baseCommandName}`
|
||||||
|
: baseCommandName
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const content = readFileSync(commandPath, "utf-8")
|
const content = readFileSync(commandPath, "utf-8")
|
||||||
|
|||||||
Reference in New Issue
Block a user