fix(slash-command): skip already tagged command output
This commit is contained in:
@@ -56,6 +56,16 @@ function getCommandExecutionEventID(input: CommandExecuteBeforeInput): string |
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function partsContainAutoSlashCommandTags(parts: Array<{ text?: string }>): boolean {
|
||||||
|
return parts.some((part) =>
|
||||||
|
typeof part.text === "string"
|
||||||
|
&& (
|
||||||
|
part.text.includes(AUTO_SLASH_COMMAND_TAG_OPEN)
|
||||||
|
|| part.text.includes(AUTO_SLASH_COMMAND_TAG_CLOSE)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export interface AutoSlashCommandHookOptions {
|
export interface AutoSlashCommandHookOptions {
|
||||||
skills?: LoadedSkill[]
|
skills?: LoadedSkill[]
|
||||||
pluginsEnabled?: boolean
|
pluginsEnabled?: boolean
|
||||||
@@ -153,6 +163,10 @@ export function createAutoSlashCommandHook(options?: AutoSlashCommandHookOptions
|
|||||||
input: CommandExecuteBeforeInput,
|
input: CommandExecuteBeforeInput,
|
||||||
output: CommandExecuteBeforeOutput
|
output: CommandExecuteBeforeOutput
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
|
if (partsContainAutoSlashCommandTags(output.parts)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const eventID = getCommandExecutionEventID(input)
|
const eventID = getCommandExecutionEventID(input)
|
||||||
const commandKey = eventID
|
const commandKey = eventID
|
||||||
? `${input.sessionID}:event:${eventID}`
|
? `${input.sessionID}:event:${eventID}`
|
||||||
|
|||||||
@@ -355,6 +355,22 @@ describe("createAutoSlashCommandHook", () => {
|
|||||||
expect(output.parts[0].text).toContain("/ralph-loop Command")
|
expect(output.parts[0].text).toContain("/ralph-loop Command")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should not duplicate injection when command output is already tagged", async () => {
|
||||||
|
//#given
|
||||||
|
const hook = createAutoSlashCommandHook()
|
||||||
|
const input = createCommandInput("ralph-loop")
|
||||||
|
const taggedContent = "<auto-slash-command>\n/ralph-loop Command\n</auto-slash-command>"
|
||||||
|
const output = createCommandOutput(taggedContent)
|
||||||
|
|
||||||
|
//#when
|
||||||
|
await hook["command.execute.before"](input, output)
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(output.parts).toHaveLength(1)
|
||||||
|
expect(output.parts[0]?.text).toBe(taggedContent)
|
||||||
|
expect(output.parts[0]?.text?.split("<auto-slash-command>").length).toBe(2)
|
||||||
|
})
|
||||||
|
|
||||||
it("should inject template for known builtin commands like ulw-loop", async () => {
|
it("should inject template for known builtin commands like ulw-loop", async () => {
|
||||||
//#given
|
//#given
|
||||||
const hook = createAutoSlashCommandHook()
|
const hook = createAutoSlashCommandHook()
|
||||||
|
|||||||
Reference in New Issue
Block a user