-
Notifications
You must be signed in to change notification settings - Fork 0
feat: enhance PromptSubmitHandler with intent extraction (GIT-99) #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,30 +3,91 @@ | |
| * | ||
| * Handles the prompt:submit event by loading relevant memories | ||
| * and formatting them as context for Claude Code. | ||
| * | ||
| * When intent extraction is enabled, extracts searchable keywords | ||
| * from the prompt and queries memories with those keywords. | ||
| * Falls back to loading recent memories if extraction is skipped | ||
| * or no keywords are found. | ||
| */ | ||
|
|
||
| import type { IPromptSubmitHandler } from '../interfaces/IPromptSubmitHandler'; | ||
| import type { IPromptSubmitEvent } from '../../domain/events/HookEvents'; | ||
| import type { IEventResult } from '../../domain/interfaces/IEventResult'; | ||
| import type { IMemoryContextLoader } from '../../domain/interfaces/IMemoryContextLoader'; | ||
| import type { IMemoryContextLoader, IMemoryContextResult } from '../../domain/interfaces/IMemoryContextLoader'; | ||
| import type { IContextFormatter } from '../../domain/interfaces/IContextFormatter'; | ||
| import type { ILogger } from '../../domain/interfaces/ILogger'; | ||
| import type { IHookConfigLoader } from '../../domain/interfaces/IHookConfigLoader'; | ||
| import type { IIntentExtractor } from '../../domain/interfaces/IIntentExtractor'; | ||
|
|
||
| export class PromptSubmitHandler implements IPromptSubmitHandler { | ||
| constructor( | ||
| private readonly memoryContextLoader: IMemoryContextLoader, | ||
| private readonly contextFormatter: IContextFormatter, | ||
| private readonly logger?: ILogger, | ||
| private readonly hookConfigLoader?: IHookConfigLoader, | ||
| private readonly intentExtractor?: IIntentExtractor | null, | ||
| ) {} | ||
|
|
||
| async handle(event: IPromptSubmitEvent): Promise<IEventResult> { | ||
| try { | ||
| this.logger?.info('Prompt submit handler invoked', { | ||
| sessionId: event.sessionId, | ||
| cwd: event.cwd, | ||
| hasPrompt: !!event.prompt, | ||
| }); | ||
|
|
||
| const result = this.memoryContextLoader.load({ cwd: event.cwd }); | ||
| // Load config | ||
| const config = this.hookConfigLoader?.loadConfig(event.cwd); | ||
| const promptConfig = config?.hooks.promptSubmit ?? { | ||
| surfaceContext: true, | ||
| extractIntent: false, | ||
| memoryLimit: 20, | ||
| minWords: 5, | ||
| intentTimeout: 3000, | ||
| }; | ||
|
|
||
| // Early exit if context surfacing is disabled | ||
| if (!promptConfig.surfaceContext) { | ||
| this.logger?.debug('Context surfacing disabled'); | ||
| return { | ||
| handler: 'PromptSubmitHandler', | ||
| success: true, | ||
| output: '', | ||
| }; | ||
| } | ||
|
|
||
| // Try intent extraction if enabled | ||
| let result: IMemoryContextResult; | ||
|
|
||
| if (promptConfig.extractIntent && this.intentExtractor && event.prompt) { | ||
| const intentResult = await this.intentExtractor.extract({ prompt: event.prompt }); | ||
|
|
||
| if (!intentResult.skipped && intentResult.intent) { | ||
| this.logger?.debug('Intent extracted, querying with keywords', { | ||
| intent: intentResult.intent, | ||
| }); | ||
| result = this.memoryContextLoader.loadWithQuery( | ||
| intentResult.intent, | ||
| promptConfig.memoryLimit, | ||
| event.cwd, | ||
| ); | ||
| } else { | ||
| this.logger?.debug('Intent extraction skipped', { | ||
| reason: intentResult.reason, | ||
| }); | ||
| // Fall back to loading recent memories | ||
| result = this.memoryContextLoader.load({ | ||
| cwd: event.cwd, | ||
| limit: promptConfig.memoryLimit, | ||
| }); | ||
| } | ||
| } else { | ||
| // No intent extraction, load recent memories | ||
| result = this.memoryContextLoader.load({ | ||
| cwd: event.cwd, | ||
| limit: promptConfig.memoryLimit, | ||
| }); | ||
| } | ||
|
Comment on lines
+39
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configured 🔧 Example fix to honor
|
||
|
|
||
| if (result.memories.length === 0) { | ||
| this.logger?.debug('No memories found for prompt context'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback
promptConfigincludesminWordsandintentTimeout, but those values are never applied (they aren’t passed toIntentExtractorand aren’t used in the handler). As a result, the new config fields have no effect. Either wire these settings into the extraction flow (e.g., pass per-call options / enforce timeout & minWords in the handler) or remove them from the config shape to avoid misleading configuration.