fix(auto-slash-command): resolve project commands from session dir

Use the plugin session directory instead of process.cwd() when resolving project slash commands. This restores project and opencode-project slashcommand behavior when the runtime cwd differs from the actual session workspace.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-31 22:08:00 -07:00
parent 7f846b2da3
commit ea14a1a346
5 changed files with 71 additions and 2 deletions
@@ -60,4 +60,32 @@ describe("slashcommand discovery and execution compatibility", () => {
expect(result.replacementText).toContain("Execute from parent config.")
expect(result.replacementText).toContain("**Scope**: opencode")
})
it("executes project commands using the provided directory even when cwd differs", async () => {
// given
const projectDir = join(tempDir, "project")
const commandDir = join(projectDir, ".claude", "commands")
const commandName = "project-only-command"
mkdirSync(commandDir, { recursive: true })
writeFileSync(
join(commandDir, `${commandName}.md`),
`---\ndescription: Project command\n---\nExecute from project directory.\n`,
)
process.chdir("/tmp")
expect(discoverCommandsSync(projectDir).some(command => command.name === commandName)).toBe(true)
// when
const result = await executeSlashCommand({
command: commandName,
args: "",
raw: `/${commandName}`,
}, { skills: [], directory: projectDir })
// then
expect(result.success).toBe(true)
expect(result.replacementText).toContain("Execute from project directory.")
expect(result.replacementText).toContain("**Scope**: project")
})
})