refactor(keyword-detector): inject keywords on every message (#99)
Remove first-message-only restriction and move keyword injection to chat.message hook for consistent keyword presence across all messages. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -6,8 +6,6 @@ export * from "./detector"
|
|||||||
export * from "./constants"
|
export * from "./constants"
|
||||||
export * from "./types"
|
export * from "./types"
|
||||||
|
|
||||||
const injectedSessions = new Set<string>()
|
|
||||||
|
|
||||||
export function createKeywordDetectorHook() {
|
export function createKeywordDetectorHook() {
|
||||||
return {
|
return {
|
||||||
"chat.message": async (
|
"chat.message": async (
|
||||||
@@ -22,10 +20,6 @@ export function createKeywordDetectorHook() {
|
|||||||
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
||||||
}
|
}
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
if (injectedSessions.has(input.sessionID)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const promptText = extractPromptText(output.parts)
|
const promptText = extractPromptText(output.parts)
|
||||||
const messages = detectKeywords(promptText)
|
const messages = detectKeywords(promptText)
|
||||||
|
|
||||||
@@ -52,22 +46,8 @@ export function createKeywordDetectorHook() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
injectedSessions.add(input.sessionID)
|
|
||||||
log("Keyword context injected", { sessionID: input.sessionID })
|
log("Keyword context injected", { sessionID: input.sessionID })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
event: async ({
|
|
||||||
event,
|
|
||||||
}: {
|
|
||||||
event: { type: string; properties?: unknown }
|
|
||||||
}) => {
|
|
||||||
if (event.type === "session.deleted") {
|
|
||||||
const props = event.properties as { info?: { id?: string } } | undefined
|
|
||||||
if (props?.info?.id) {
|
|
||||||
injectedSessions.delete(props.info.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -410,7 +410,6 @@ const OhMyOpenCodePlugin: Plugin = async (ctx) => {
|
|||||||
await rulesInjector?.event(input);
|
await rulesInjector?.event(input);
|
||||||
await thinkMode?.event(input);
|
await thinkMode?.event(input);
|
||||||
await anthropicAutoCompact?.event(input);
|
await anthropicAutoCompact?.event(input);
|
||||||
await keywordDetector?.event(input);
|
|
||||||
await agentUsageReminder?.event(input);
|
await agentUsageReminder?.event(input);
|
||||||
await interactiveBashSession?.event(input);
|
await interactiveBashSession?.event(input);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user