From 1ffedbc8c46a83f2fd42651fbebe1f89c1fb91ab Mon Sep 17 00:00:00 2001 From: "Mikhail [azalio] Petrov" Date: Thu, 6 Nov 2025 10:33:57 +0300 Subject: [PATCH 1/3] feat: integrate claude-code-prompt-improver with sequential hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements Sequential Hooks pattern (Variant 1) to enhance MAP Framework with interactive prompt disambiguation capabilities. ## What's New ### 1. Prompt Clarification Hook (improve-prompt.py) - Evaluates prompt clarity using conversation history - For vague prompts: research → grounded questions → execution - For clear prompts: immediate execution (no overhead) - Bypass options: *, /, # prefixes ### 2. Sequential UserPromptSubmit Processing Step 1: Prompt-Improver disambiguates vague prompts Step 2: Playbook injection adds relevant patterns Step 3: Workflow suggestion recommends MAP workflows Step 4: Skill suggestion offers helpful skills ### 3. Documentation - Added "Hooks System" section to docs/USAGE.md - Explains prompt clarification, sequential processing, bypass options - Updated navigation with hooks system links ## Benefits ✅ Better first-attempt outcomes (grounded questions from research) ✅ Reduced back-and-forth (1-6 questions vs multiple iterations) ✅ Complementary to existing hooks (playbook + workflow + skills) ✅ Modular design (can be disabled independently) ✅ Minimal overhead (~300 tokens, only when needed) ## Token Efficiency - Vague prompt: ~300 tokens wrapper + research + questions - Clear prompt: ~300 tokens wrapper (immediate execution) - Bypass: 0 tokens (no processing) ## Testing Tested all bypass prefixes: - * prefix: ✅ Skips improvement - / prefix: ✅ Slash commands bypass - # prefix: ✅ Memorize feature bypass ## Files Changed - .claude/hooks/improve-prompt.py (new) - .claude/hooks/settings.hooks.json (sequential hooks) - src/mapify_cli/templates/hooks/ (template sync) - docs/USAGE.md (hooks system documentation) ## Implementation Notes Based on analysis in: docs/claude-code-prompt-improver/ Sequential Hooks pattern chosen for: - Independent hook operation - Easy debugging (modular) - User control (bypass options) ## Related - Original tool: https://github.com/severity1/claude-code-prompt-improver - Uses AskUserQuestion tool (Claude Code 2.0.22+) - Integrates with MAP Framework playbook/workflow/skill systems Closes research task on prompt-improver hook integration. --- .claude/hooks/improve-prompt.py | 82 +++++++++++++ .claude/hooks/settings.hooks.json | 13 ++- docs/USAGE.md | 109 ++++++++++++++++++ .../templates/hooks/improve-prompt.py | 82 +++++++++++++ .../templates/hooks/settings.hooks.json | 13 ++- 5 files changed, 297 insertions(+), 2 deletions(-) create mode 100755 .claude/hooks/improve-prompt.py create mode 100755 src/mapify_cli/templates/hooks/improve-prompt.py diff --git a/.claude/hooks/improve-prompt.py b/.claude/hooks/improve-prompt.py new file mode 100755 index 00000000..0f3d1248 --- /dev/null +++ b/.claude/hooks/improve-prompt.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +""" +Claude Code Prompt Improver Hook +Intercepts user prompts and evaluates if they need enrichment before execution. +Uses main session context for intelligent, non-pedantic evaluation. +""" +import json +import sys + +# Load input from stdin +try: + input_data = json.load(sys.stdin) +except json.JSONDecodeError as e: + print(f"Error: Invalid JSON input: {e}", file=sys.stderr) + sys.exit(1) + +prompt = input_data.get("prompt", "") + +# Escape quotes in prompt for safe embedding in wrapped instructions +escaped_prompt = prompt.replace("\\", "\\\\").replace('"', '\\"') + +def output_json(text): + """Output text in UserPromptSubmit JSON format""" + output = { + "hookSpecificOutput": { + "hookEventName": "UserPromptSubmit", + "additionalContext": text + } + } + print(json.dumps(output)) + +# Check for bypass conditions +# 1. Explicit bypass with * prefix +# 2. Slash commands (built-in or custom) +# 3. Memorize feature (# prefix) +if prompt.startswith("*"): + # User explicitly bypassed improvement - remove * prefix + clean_prompt = prompt[1:].strip() + output_json(clean_prompt) + sys.exit(0) + +if prompt.startswith("/"): + # Slash command - pass through unchanged + output_json(prompt) + sys.exit(0) + +if prompt.startswith("#"): + # Memorize feature - pass through unchanged + output_json(prompt) + sys.exit(0) + +# Build the improvement wrapper +wrapped_prompt = f"""PROMPT EVALUATION + +Original user request: "{escaped_prompt}" + +EVALUATE: Is this prompt clear enough to execute, or does it need enrichment? + +PROCEED IMMEDIATELY if: +- Detailed/specific OR you have sufficient context OR can infer intent + +ONLY ASK if genuinely vague (e.g., "fix the bug" with no context): +- CRITICAL (NON-NEGOTIABLE) RULES: + - Trust user intent by default. Check conversation history before doing research. + - Do not rely on base knowledge. + - Never skip Phase 1. Research before asking. + - Don't announce evaluation - just proceed or ask. + +- PHASE 1 - RESEARCH (DO NOT SKIP): + 1. Preface with brief note: "Prompt Improver Hook is seeking clarification because [specific reason: ambiguous scope/missing context/unclear requirements/etc]" + 2. Create research plan with TodoWrite: Ask yourself "What do I need to research to clarify this vague request?" Research WHAT NEEDS CLARIFICATION, not just the project. Use available tools: Task/Explore for codebase, WebSearch for online research (current info, common approaches, best practices, typical architectures), Read/Grep as needed + 3. Execute research + 4. Use research findings (not your training) to formulate grounded questions with specific options + 5. Mark completed + +- PHASE 2 - ASK (ONLY AFTER PHASE 1): + 1. Use AskUserQuestion tool with max 1-6 questions offering specific options from your research + 2. Use the answers to execute the original user request +""" + +output_json(wrapped_prompt) +sys.exit(0) diff --git a/.claude/hooks/settings.hooks.json b/.claude/hooks/settings.hooks.json index 2ced45a3..d0f59f98 100644 --- a/.claude/hooks/settings.hooks.json +++ b/.claude/hooks/settings.hooks.json @@ -4,7 +4,18 @@ "hooks": { "UserPromptSubmit": [ { - "description": "Auto-inject playbook bullets and suggest appropriate MAP workflows", + "description": "Step 1: Disambiguate vague prompts", + "hooks": [ + { + "type": "command", + "command": "python3 .claude/hooks/improve-prompt.py", + "timeout": 5, + "description": "Wraps vague prompts with evaluation instructions for clarification" + } + ] + }, + { + "description": "Step 2: Inject playbook patterns and suggest workflows", "hooks": [ { "type": "command", diff --git a/docs/USAGE.md b/docs/USAGE.md index b9c42ef7..2121ceab 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -30,6 +30,11 @@ Complete usage examples, best practices, and optimization strategies for the MAP - [Cost Savings](#cost-savings) - [How It Works](#how-it-works) - [Cost Comparison Example](#cost-comparison-example) +- [Hooks System](#-hooks-system) + - [Prompt Clarification](#prompt-clarification-prompt-improver-hook) + - [Sequential Hook Processing](#sequential-hook-processing) + - [Disabling Prompt-Improver](#disabling-prompt-improver) + - [Other Active Hooks](#other-active-hooks) - [Additional Resources](#additional-resources) --- @@ -1882,3 +1887,107 @@ See `.claude/skills/README.md` for: - Best practices and examples --- + +## 🔌 Hooks System + +MAP Framework uses Claude Code hooks to enhance your workflow experience. + +### Prompt Clarification (Prompt-Improver Hook) + +**Enabled by default** - Automatically disambiguates vague prompts before execution. + +**What it does:** +1. **Evaluates prompt clarity** using conversation history +2. **For vague prompts** (e.g., "fix the bug"): + - Creates research plan (TodoWrite) + - Gathers context from codebase, docs, web + - Asks 1-6 grounded questions with specific options +3. **For clear prompts**: Proceeds immediately + +**Example flow:** +``` +User: "fix the error" + +MAP: [Prompt Improver Hook seeking clarification] + [Research: Found 3 recent errors in logs] + + Which error needs fixing? + ○ TypeError in src/components/Map.tsx (recent change) + ○ API timeout in src/services/osmService.ts + ○ Other (paste error message) + +User: [Selects option] + +MAP: [Proceeds with full context + playbook patterns] +``` + +**Bypass options:** +- `* your prompt` - Skip evaluation (remove `*` prefix) +- `/command` - Slash commands bypass automatically +- `# memorize` - Memorize feature bypasses automatically + +**Token overhead:** +- ~300 tokens per wrapped prompt +- Only adds questions when genuinely needed +- Better outcomes on first try = overall efficiency + +**Design philosophy:** +- **Rarely intervene** - Most prompts pass through +- **Trust user intent** - Research before asking +- **Transparent** - Evaluation visible in conversation +- **Max 1-6 questions** - Focused clarification + +### Sequential Hook Processing + +MAP uses **sequential UserPromptSubmit hooks**: + +1. **Step 1: Prompt-Improver** - Disambiguates vague prompts +2. **Step 2: Playbook Injection** - Adds relevant patterns +3. **Step 3: Workflow Suggestion** - Recommends MAP workflows +4. **Step 4: Skill Suggestion** - Suggests helpful skills + +**Benefits:** +- Each hook enhances the previous result +- Prompt-Improver clarifies → Playbook adds patterns → Workflow guides approach +- Modular design (hooks can be disabled independently) + +### Disabling Prompt-Improver + +If you prefer direct execution without clarification: + +**Option 1: Use bypass prefix** +```bash +* implement user authentication # Skips improvement +``` + +**Option 2: Remove from settings.hooks.json** +```json +{ + "hooks": { + "UserPromptSubmit": [ + // Comment out or remove Prompt-Improver hook + { + "description": "Inject playbook patterns only", + "hooks": [ + { + "type": "command", + "command": ".claude/hooks/user-prompt-submit.sh" + } + ] + } + ] + } +} +``` + +### Other Active Hooks + +MAP Framework includes additional hooks: + +- **SessionStart** - Auto-injects checkpoint after compaction (see [Compaction Resilience](#-compaction-resilience)) +- **PreToolUse** - Validates agent templates before modifications +- **Stop** - Quality gates after code modifications + +See `.claude/hooks/README.md` for implementation details. + +--- diff --git a/src/mapify_cli/templates/hooks/improve-prompt.py b/src/mapify_cli/templates/hooks/improve-prompt.py new file mode 100755 index 00000000..0f3d1248 --- /dev/null +++ b/src/mapify_cli/templates/hooks/improve-prompt.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +""" +Claude Code Prompt Improver Hook +Intercepts user prompts and evaluates if they need enrichment before execution. +Uses main session context for intelligent, non-pedantic evaluation. +""" +import json +import sys + +# Load input from stdin +try: + input_data = json.load(sys.stdin) +except json.JSONDecodeError as e: + print(f"Error: Invalid JSON input: {e}", file=sys.stderr) + sys.exit(1) + +prompt = input_data.get("prompt", "") + +# Escape quotes in prompt for safe embedding in wrapped instructions +escaped_prompt = prompt.replace("\\", "\\\\").replace('"', '\\"') + +def output_json(text): + """Output text in UserPromptSubmit JSON format""" + output = { + "hookSpecificOutput": { + "hookEventName": "UserPromptSubmit", + "additionalContext": text + } + } + print(json.dumps(output)) + +# Check for bypass conditions +# 1. Explicit bypass with * prefix +# 2. Slash commands (built-in or custom) +# 3. Memorize feature (# prefix) +if prompt.startswith("*"): + # User explicitly bypassed improvement - remove * prefix + clean_prompt = prompt[1:].strip() + output_json(clean_prompt) + sys.exit(0) + +if prompt.startswith("/"): + # Slash command - pass through unchanged + output_json(prompt) + sys.exit(0) + +if prompt.startswith("#"): + # Memorize feature - pass through unchanged + output_json(prompt) + sys.exit(0) + +# Build the improvement wrapper +wrapped_prompt = f"""PROMPT EVALUATION + +Original user request: "{escaped_prompt}" + +EVALUATE: Is this prompt clear enough to execute, or does it need enrichment? + +PROCEED IMMEDIATELY if: +- Detailed/specific OR you have sufficient context OR can infer intent + +ONLY ASK if genuinely vague (e.g., "fix the bug" with no context): +- CRITICAL (NON-NEGOTIABLE) RULES: + - Trust user intent by default. Check conversation history before doing research. + - Do not rely on base knowledge. + - Never skip Phase 1. Research before asking. + - Don't announce evaluation - just proceed or ask. + +- PHASE 1 - RESEARCH (DO NOT SKIP): + 1. Preface with brief note: "Prompt Improver Hook is seeking clarification because [specific reason: ambiguous scope/missing context/unclear requirements/etc]" + 2. Create research plan with TodoWrite: Ask yourself "What do I need to research to clarify this vague request?" Research WHAT NEEDS CLARIFICATION, not just the project. Use available tools: Task/Explore for codebase, WebSearch for online research (current info, common approaches, best practices, typical architectures), Read/Grep as needed + 3. Execute research + 4. Use research findings (not your training) to formulate grounded questions with specific options + 5. Mark completed + +- PHASE 2 - ASK (ONLY AFTER PHASE 1): + 1. Use AskUserQuestion tool with max 1-6 questions offering specific options from your research + 2. Use the answers to execute the original user request +""" + +output_json(wrapped_prompt) +sys.exit(0) diff --git a/src/mapify_cli/templates/hooks/settings.hooks.json b/src/mapify_cli/templates/hooks/settings.hooks.json index 2ced45a3..d0f59f98 100644 --- a/src/mapify_cli/templates/hooks/settings.hooks.json +++ b/src/mapify_cli/templates/hooks/settings.hooks.json @@ -4,7 +4,18 @@ "hooks": { "UserPromptSubmit": [ { - "description": "Auto-inject playbook bullets and suggest appropriate MAP workflows", + "description": "Step 1: Disambiguate vague prompts", + "hooks": [ + { + "type": "command", + "command": "python3 .claude/hooks/improve-prompt.py", + "timeout": 5, + "description": "Wraps vague prompts with evaluation instructions for clarification" + } + ] + }, + { + "description": "Step 2: Inject playbook patterns and suggest workflows", "hooks": [ { "type": "command", From 3b8b492f6334d33f76a6e758a5b1f46bd104ed2f Mon Sep 17 00:00:00 2001 From: "Mikhail [azalio] Petrov" Date: Thu, 6 Nov 2025 11:49:09 +0300 Subject: [PATCH 2/3] fix: address Copilot reviewer feedback on PR #31 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes all 4 issues raised by Copilot code review: 1. **Fixed JSON output format** (improve-prompt.py) - Changed from nested `hookSpecificOutput` structure - Now uses correct `{"continue": true, "additionalContext": text}` format - Consistent with existing hooks (user-prompt-submit.sh, session-start.sh) - Applied to both .claude and templates versions 2. **Fixed disable example description** (USAGE.md:1970) - Changed "Inject playbook patterns only" - To "Step 2: Inject playbook patterns and suggest workflows" - Matches actual settings.hooks.json description 3. **Corrected sequential processing documentation** (USAGE.md:1951) - Changed from 4 steps to 2 steps - Added note explaining workflow/skill suggestions are part of Step 2 - Reflects actual implementation in user-prompt-submit.sh ## Testing Verified JSON format: ```bash echo '{"prompt": "test"}' | python3 .claude/hooks/improve-prompt.py | jq # Output: {"continue": true, "additionalContext": "..."} ``` ## Reviewer Comments Addressed - ✅ Comment on .claude/hooks/improve-prompt.py:28 - ✅ Comment on src/mapify_cli/templates/hooks/improve-prompt.py:28 - ✅ Comment on docs/USAGE.md:1970 - ✅ Comment on docs/USAGE.md:1951 Co-authored-by: Copilot --- .claude/hooks/improve-prompt.py | 6 ++---- docs/USAGE.md | 12 ++++++------ src/mapify_cli/templates/hooks/improve-prompt.py | 6 ++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.claude/hooks/improve-prompt.py b/.claude/hooks/improve-prompt.py index 0f3d1248..88bf9896 100755 --- a/.claude/hooks/improve-prompt.py +++ b/.claude/hooks/improve-prompt.py @@ -22,10 +22,8 @@ def output_json(text): """Output text in UserPromptSubmit JSON format""" output = { - "hookSpecificOutput": { - "hookEventName": "UserPromptSubmit", - "additionalContext": text - } + "continue": True, + "additionalContext": text } print(json.dumps(output)) diff --git a/docs/USAGE.md b/docs/USAGE.md index 2121ceab..0a1643b8 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -1941,14 +1941,14 @@ MAP: [Proceeds with full context + playbook patterns] MAP uses **sequential UserPromptSubmit hooks**: -1. **Step 1: Prompt-Improver** - Disambiguates vague prompts -2. **Step 2: Playbook Injection** - Adds relevant patterns -3. **Step 3: Workflow Suggestion** - Recommends MAP workflows -4. **Step 4: Skill Suggestion** - Suggests helpful skills +1. **Step 1: Prompt-Improver** – Disambiguates vague prompts +2. **Step 2: Playbook Injection** – Adds relevant patterns, and suggests workflows and skills + +> **Note:** In the current implementation, workflow and skill suggestions are combined within the Playbook Injection step (handled by `.claude/hooks/user-prompt-submit.sh`), rather than as separate steps. **Benefits:** - Each hook enhances the previous result -- Prompt-Improver clarifies → Playbook adds patterns → Workflow guides approach +- Prompt-Improver clarifies → Playbook adds patterns, workflows, and skills - Modular design (hooks can be disabled independently) ### Disabling Prompt-Improver @@ -1967,7 +1967,7 @@ If you prefer direct execution without clarification: "UserPromptSubmit": [ // Comment out or remove Prompt-Improver hook { - "description": "Inject playbook patterns only", + "description": "Step 2: Inject playbook patterns and suggest workflows", "hooks": [ { "type": "command", diff --git a/src/mapify_cli/templates/hooks/improve-prompt.py b/src/mapify_cli/templates/hooks/improve-prompt.py index 0f3d1248..88bf9896 100755 --- a/src/mapify_cli/templates/hooks/improve-prompt.py +++ b/src/mapify_cli/templates/hooks/improve-prompt.py @@ -22,10 +22,8 @@ def output_json(text): """Output text in UserPromptSubmit JSON format""" output = { - "hookSpecificOutput": { - "hookEventName": "UserPromptSubmit", - "additionalContext": text - } + "continue": True, + "additionalContext": text } print(json.dumps(output)) From a4407ec6f66655163a86c30f65bdfe3111cecbad Mon Sep 17 00:00:00 2001 From: "Mikhail [azalio] Petrov" Date: Thu, 6 Nov 2025 12:10:51 +0300 Subject: [PATCH 3/3] fix: align with official Claude Code hooks documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes implementation to match official docs at docs.claude.ai: ## 1. JSON Output Format **Changed:** Simplified format → Official format ```python # Before: {"continue": true, "additionalContext": text} # After (official): { "hookSpecificOutput": { "hookEventName": "UserPromptSubmit", "additionalContext": text } } ``` **Reason:** Official docs recommend hookSpecificOutput structure ## 2. Bypass Logic **Changed:** Return clean prompt → Exit with no output ```python # Before: if prompt.startswith("*"): output_json(clean_prompt) # ❌ Returns additionalContext # After: if prompt.startswith("*") or prompt.startswith("/") or prompt.startswith("#"): sys.exit(0) # ✅ No output, prompt passes through unchanged ``` **Reason:** Returning additionalContext causes duplication ## 3. Hook Execution Model **Changed:** "Sequential" → "Parallel" ```markdown # Before: MAP uses **sequential UserPromptSubmit hooks** # After: MAP uses **multiple UserPromptSubmit hooks** that run in parallel ``` **Reason:** Official docs state "All matching hooks run in parallel" ## Testing All bypass prefixes tested: - ✅ `*` prefix: No output, exit 0 - ✅ `/` prefix: No output, exit 0 - ✅ `#` prefix: No output, exit 0 Normal prompt tested: - ✅ Returns hookSpecificOutput.hookEventName = "UserPromptSubmit" - ✅ Returns hookSpecificOutput.additionalContext with wrapper ## Files Changed - .claude/hooks/improve-prompt.py - src/mapify_cli/templates/hooks/improve-prompt.py - docs/USAGE.md ## Reference Based on official documentation review per user request. --- .claude/hooks/improve-prompt.py | 23 ++++++------------- docs/USAGE.md | 17 ++++++++------ .../templates/hooks/improve-prompt.py | 23 ++++++------------- 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/.claude/hooks/improve-prompt.py b/.claude/hooks/improve-prompt.py index 88bf9896..58d1eb01 100755 --- a/.claude/hooks/improve-prompt.py +++ b/.claude/hooks/improve-prompt.py @@ -22,8 +22,10 @@ def output_json(text): """Output text in UserPromptSubmit JSON format""" output = { - "continue": True, - "additionalContext": text + "hookSpecificOutput": { + "hookEventName": "UserPromptSubmit", + "additionalContext": text + } } print(json.dumps(output)) @@ -31,20 +33,9 @@ def output_json(text): # 1. Explicit bypass with * prefix # 2. Slash commands (built-in or custom) # 3. Memorize feature (# prefix) -if prompt.startswith("*"): - # User explicitly bypassed improvement - remove * prefix - clean_prompt = prompt[1:].strip() - output_json(clean_prompt) - sys.exit(0) - -if prompt.startswith("/"): - # Slash command - pass through unchanged - output_json(prompt) - sys.exit(0) - -if prompt.startswith("#"): - # Memorize feature - pass through unchanged - output_json(prompt) +if prompt.startswith("*") or prompt.startswith("/") or prompt.startswith("#"): + # User bypassed improvement - don't add evaluation wrapper + # Exit without output so hook doesn't modify the prompt sys.exit(0) # Build the improvement wrapper diff --git a/docs/USAGE.md b/docs/USAGE.md index 0a1643b8..678045ea 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -1937,19 +1937,22 @@ MAP: [Proceeds with full context + playbook patterns] - **Transparent** - Evaluation visible in conversation - **Max 1-6 questions** - Focused clarification -### Sequential Hook Processing +### Multi-Hook Processing -MAP uses **sequential UserPromptSubmit hooks**: +MAP uses **multiple UserPromptSubmit hooks** that run in parallel: -1. **Step 1: Prompt-Improver** – Disambiguates vague prompts -2. **Step 2: Playbook Injection** – Adds relevant patterns, and suggests workflows and skills +1. **Prompt-Improver** – Disambiguates vague prompts (wraps prompt with evaluation instructions) +2. **Playbook Injection** – Adds relevant patterns, and suggests workflows and skills -> **Note:** In the current implementation, workflow and skill suggestions are combined within the Playbook Injection step (handled by `.claude/hooks/user-prompt-submit.sh`), rather than as separate steps. +> **Note:** Claude Code executes all matching hooks in parallel. Each hook's `additionalContext` output is concatenated and added to the prompt. The order is not guaranteed, but both enhancements are applied. + +> **Implementation detail:** Workflow and skill suggestions are handled within the Playbook Injection hook (`.claude/hooks/user-prompt-submit.sh`), not as separate hooks. **Benefits:** -- Each hook enhances the previous result -- Prompt-Improver clarifies → Playbook adds patterns, workflows, and skills +- Both hooks enhance the prompt with different types of context +- Prompt-Improver adds evaluation wrapper, Playbook adds patterns/workflows/skills - Modular design (hooks can be disabled independently) +- Parallel execution (efficient) ### Disabling Prompt-Improver diff --git a/src/mapify_cli/templates/hooks/improve-prompt.py b/src/mapify_cli/templates/hooks/improve-prompt.py index 88bf9896..58d1eb01 100755 --- a/src/mapify_cli/templates/hooks/improve-prompt.py +++ b/src/mapify_cli/templates/hooks/improve-prompt.py @@ -22,8 +22,10 @@ def output_json(text): """Output text in UserPromptSubmit JSON format""" output = { - "continue": True, - "additionalContext": text + "hookSpecificOutput": { + "hookEventName": "UserPromptSubmit", + "additionalContext": text + } } print(json.dumps(output)) @@ -31,20 +33,9 @@ def output_json(text): # 1. Explicit bypass with * prefix # 2. Slash commands (built-in or custom) # 3. Memorize feature (# prefix) -if prompt.startswith("*"): - # User explicitly bypassed improvement - remove * prefix - clean_prompt = prompt[1:].strip() - output_json(clean_prompt) - sys.exit(0) - -if prompt.startswith("/"): - # Slash command - pass through unchanged - output_json(prompt) - sys.exit(0) - -if prompt.startswith("#"): - # Memorize feature - pass through unchanged - output_json(prompt) +if prompt.startswith("*") or prompt.startswith("/") or prompt.startswith("#"): + # User bypassed improvement - don't add evaluation wrapper + # Exit without output so hook doesn't modify the prompt sys.exit(0) # Build the improvement wrapper