- Hook name:
prompt-improver - Registered in session hooks via
createSessionHooks() - Exposed handler:
chat.messageonly - Config surface:
src/config/schema/hooks.tsincludes"prompt-improver"inHookNameSchema
The current runtime does not intercept delegate_task and does not register a tool.execute.before handler. It rewrites the first text part of a user chat message before the active model handles it.
Source of truth:
src/hooks/prompt-improver/index.tssrc/plugin/hooks/create-session-hooks.tssrc/config/schema/hooks.ts
Verified flow:
createSessionHooks()registerscreatePromptImproverHook(ctx)when the hook is enabled.- The hook runs on
chat.message. - It exits early when there is no active model, no text part, only whitespace, or an unrecognized provider family.
- It also skips slash commands and messages wrapped in the auto-slash-command guard tags.
- It detects provider family from the active session model string, not from a
delegate_taskcategory or subagent selection. - It calls
improvePromptWithLLM()and replaces the text part only when the rewrite differs from the original.
The implementation is narrower than the earlier documentation claimed.
- It rewrites top-level chat input, not downstream delegated task payloads.
- It operates on the current session model, including model names coming from alternate provider prefixes such as
github-copilot/...when the model name still matches Anthropic, OpenAI, or Google families. - It leaves non-text parts untouched.
- It preserves the original prompt only when rewrite infrastructure is unavailable or normalization produces an empty result.
improvePromptWithLLM() and rewritePromptViaSession() currently enforce these behaviors:
- Internal rewrite sessions disable
task,delegate_task,call_omo_agent, andquestiontools. - Rewrite sessions set
thinking: { type: "disabled" }. - Rewrite sessions strip
-thinking,-max, and-highsuffixes from the model ID before prompting. - Assistant output is extracted only from
textparts, including nested text content on text parts. - Rewrites are normalized before use, including stripping the internal marker and unwrapping a single fenced block.
- Empty normalized results fall back to the original prompt.
The verified OpenAI branch is now execution-ready and avoids visible reasoning language.
- Target structure remains markdown with
# Taskand## Output Contractas the fixed base. - The rewrite must preserve user intent and constraints.
- The output contract now requires
Deliverable,Scope,Verification, andFinal Responsebullets. - Conditional sections are added only when the original prompt shape warrants them:
## Execution Rulesfor multi-step or tool-driven prompts## Research Rulesfor investigation/evidence-driven prompts## Completion Rulesfor batch or coverage-sensitive prompts
- The rewrite must not ask for visible reasoning, progress narration, or chain-of-thought output.
Current coverage is focused and file-backed, not broad integration marketing.
src/hooks/prompt-improver/index.test.ts- verifies the hook exposes
chat.messageand does not exposetool.execute.before - covers early exits for missing model, unknown provider, empty input, missing text parts, slash commands, and auto-slash-command tags
- covers provider detection from active model strings and OpenAI rewrites without schema validation
- verifies the hook exposes
src/hooks/prompt-improver/llm-improver.test.ts- covers passthrough OpenAI rewrites, marker stripping, fenced-output normalization, and empty-normalization fallback
- covers non-OpenAI fence normalization behavior
src/hooks/prompt-improver/session-manager.test.ts- covers disabled thinking, reasoning suffix stripping, and assistant text extraction rules
src/hooks/prompt-improver/prompt-builder.test.ts- covers OpenAI execution-ready instructions and Gemini guide injection behavior
src/hooks/prompt-improver/codex-guide.test.ts- covers the no-visible-reasoning Codex guidance block
src/hooks/prompt-improver/transformer.test.ts- covers provider-family detection across Anthropic, OpenAI, Google, unknown, and mixed provider-prefix cases
- No claim of automatic
delegate_taskinterception - No claim of
tool.execute.beforeintegration - No claim of category-based or subagent-based routing inside this hook
- No claim of broad end-to-end production coverage beyond the focused hook test suite and typecheck verification
Required verification for this documentation pass:
bun test src/hooks/prompt-improver && bun run typecheck