feat(keywords): Magic Keyword System — Master Plan (issue #391)#393
feat(keywords): Magic Keyword System — Master Plan (issue #391)#393quangdang46 wants to merge 9 commits into
Conversation
Comprehensive 2,209-line implementation plan for the magic keyword system: - 50+ NL keyword triggers with sanitization, intent disambiguation, multilingual - 14 workflow handlers (ultrawork, ralplan, tdd, code-review, etc.) - Persistent mode state (TOML) - Visual effects (rainbow, shimmer, toast) - Task size classification + cancel system Research: oh-my-codex, oh-my-openagent, oh-my-claudecode, claude-code, codebuff, oh-my-pi Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move clap Args::try_parse() to main() before rustls crypto provider, tokio runtime, logging, and telemetry initialization. For --help and --version invocations, clap prints and exits without any heavy setup. Benchmark results (macOS, 10 runs): --help: 17.94ms -> 7.89ms median (-56%) --version: 17.66ms -> 7.82ms median (-56%)
…ction (#391) New crate jcode-keywords (~1,845 lines) implementing the magic keyword system: - Detection engine: 14 keyword entries with aliases, multilingual triggers (EN/KO/JA/ZH/VI), fuzzy Levenshtein matching, overlap filtering - Mode state: TOML persistence at .jcode/state/modes.toml, auto-deactivate after configurable turn count - Prompt injection: active modes injected into system prompt dynamic_part - Task size classification: suppress heavy workflows for simple tasks - Conflict detection: warn about incompatible mode combinations - 14 workflow handlers: ultrawork, ultragoal, ultraqa, ralplan, deep-interview, tdd, code-review, security-review, ultrathink, deepsearch, analyze, wiki, ai-slop-cleaner, cancel - Visual effects: rainbow highlight computation for TUI rendering Integration: keyword detection wired into app-core prompting.rs, detects keywords in latest user message and injects mode prompts. 40/40 tests pass, workspace compiles clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
#391) Phase 1-7: Full workflow execution implementation. ## WorkflowHandler Trait Enhancement - Added WorkflowContext (user_input, working_dir, session_id, mode_state, metadata) - Added WorkflowAction enum (InjectReminder, SpawnAgent, SpawnParallel, AskUser, Continue, Complete, ContinueWithMetadata) - Added SpawnSpec and SpawnResult types - Added execute() and on_turn_complete() methods to WorkflowHandler trait ## New Modules - spawn.rs: Sub-agent spawning utility (spawn_agent, spawn_parallel, aggregate_results, spawn_with_retry) - executor.rs: Workflow execution engine (execute_active_workflows, process_turn_response, build_workflow_prompt) ## State Enhancement - Added metadata: HashMap<String, String> field to ActiveMode for workflow-specific state ## 14 Workflow Implementations ### Tier 1: Prompt-Only - ultrathink: Deep reasoning instructions, single-turn completion - analyze: Structured analysis with findings format - wiki: Documentation search strategy - ai-slop-cleaner: AI code quality improvement checklist ### Tier 2: Sub-Agent Spawning - ultrawork: Parallel sub-agent spawning (4 agents) with retry - code-review: Reviewer agent spawn with OWASP checklist - security-review: Security auditor agent spawn - deepsearch: Parallel search agents (text, structural, semantic) ### Tier 3: Loop Orchestration - ultraqa: implement → test → fix cycle (max 5 iterations) - tdd: red → green → refactor cycle per behavior - ralplan: plan → review → revise → approve → execute ### Tier 4: Interactive - deep-interview: Q&A with ambiguity scoring (threshold < 3) ### Tier 5: State Management - ultragoal: Durable goal tracking with token budget ### Tier 6: System Action - cancel: Clear all modes, return to normal 49/40 tests pass, workspace compiles clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Keyword Workflow Execution — Fix Plan (Post-Review)Based on 4-reviewer swarm review of PR #393. 17 findings across intent, security, performance, and contracts. Critical (fix before merge)C1. No action dispatch — execution engine is inertProblem:
C2. ContinueWithMetadata metadata never persistedProblem: Executor takes
High (fix soon)H1. Sub-agent spawn storm — no re-spawn guardProblem: H2. Prompt injection via unsanitized user_inputProblem: H3. ContinueWithMetadata discards pre-existing metadataProblem: ralplan/tdd/ultraqa create H4. execute() phase advance logic invertedProblem: H5. Tier 1 handlers auto-complete after one turnProblem: ultrathink/analyze/wiki/ai-slop-cleaner/code-review/security-review return H6. get_handler() allocates 14 Boxes per callProblem: H7. spawn_parallel silently drops JoinErrorsProblem: H8. String-based signal detection is fragileProblem: H9. No tests for execute()/on_turn_complete()Problem: Zero tests for phase state machines. Medium (fix if time permits)
Implementation OrderFiles to Modify
Estimated: ~500 lines modified |
…rsistence, handler logic (#391) ## Critical Fixes - Wire execute_active_workflows + apply_actions + build_workflow_prompt into prompting.rs - Add metadata persistence: ContinueWithMetadata now writes back to ActiveMode.metadata - Replace build_keyword_prompt with build_workflow_prompt (deprecates old prompt builder) ## High Fixes - get_handler() now uses match-based static dispatch (zero allocations) - WorkflowContext borrows mode_state instead of cloning (no more N² clones) - User input wrapped in <user_request> delimiters (prompt injection prevention) - spawn_parallel now handles JoinErrors instead of silently dropping - Tier 1 handlers (ultrathink, analyze, wiki, ai-slop-cleaner) return Continue (defer to turn-limit) - Phase advance moved from execute() to on_turn_complete() (fixes inverted logic) - Metadata cloning fixed in ralplan/tdd/ultraqa (clone first, then modify) - Re-spawn guards added in deepsearch/ultrawork - Structured completion markers: [PHASE:RED_DONE], [PHASE:GREEN_DONE], etc. - extract_ambiguity_score tightened: requires 'ambiguity' keyword + N/10 pattern - extract_progress tightened: requires 'progress' keyword on same line - WorkflowAction::Error variant added for error propagation ## Medium Fixes - spawn.rs: MAX_CONCURRENT cap (4), JoinError logging - cancel.rs: documented as no-op (handled by state::update_modes) - Removed unused imports via cargo fix - Removed unused DEFAULT_TOKEN_BUDGET constant 53 tests pass, workspace compiles clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tization (#391) ## Critical Fixes - Wire process_turn_response: process PREVIOUS turn's LLM response at start of CURRENT turn (phase transitions, completion markers, ambiguity extraction now work) - Persist metadata to disk: call save_state() after apply_actions() - Log workflow summaries instead of silently discarding ## High Fixes - sanitize_user_input: escape </user_request> delimiter to prevent breakout - apply_actions: insert *_spawned keys after SpawnAgent/SpawnParallel (re-spawn guards now actually trigger) ## Medium Fixes - extract_progress: default to None instead of 10.0 (no false goal completion) - Delete orphaned prompt_builder.rs file - truncate_str: UTF-8 safe truncation (no panics on CJK/emoji) - extract_progress: only update when LLM actually reports progress 53 tests pass, workspace compiles clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- #5 Memory leak: make keyword registry truly static via OnceLock + Box::leak, eliminating per-detection heap allocations. - #3 truncate_str byte-vs-char bug: rewrite on char_indices so CJK and other multi-byte reminders are truncated by character count and never on a non-char-boundary. - #6 Duplicate save_state + silent TOML parse errors: move the single save to the integration in process_turn; surface parse/IO errors via eprintln instead of silently returning Default. - #4 Empty-input turn-limit decrement: skip the entire keyword pipeline (including the per-mode turn_count increment) when the latest user message has no text content. - #7 Wire task_size::should_suppress into execute_active_workflows and conflict::check_conflicts into the integration; remove dead search_triggers/analyze_triggers from registry. - #1 TUI path gap: extract a single process_turn entry point used by both Agent::build_system_prompt_split and App::build_system_prompt_split so the two paths cannot drift apart. Add jcode-keywords dep to jcode-tui and wire the call. - #2 Spawn actions are still stubbed at the executor level, but apply_actions now returns DeferredSpawn values and the integration logs a clear warning that execution must be wired via SubagentTool. This is a follow-up. - #8 Remove unused serde_json dep from jcode-keywords. - #9 Multi-byte alias slice panic: compute the matched window's byte length from the actual haystack instead of the static alias string, with a non-char-boundary guard in the short-alias path. Tests: 55 keyword tests pass (was 53, +2 for new truncation and multi-byte safety cases; -2 for removed search_triggers_count and analyze_triggers_count).
# Conflicts: # src/lib.rs
Summary
Master implementation plan for the Magic Keyword System — full keyword detection + workflow handlers for natural language mode activation.
Closes #391
What This Plan Covers
1. Keyword Detection (50+ triggers)
$prefix)2. Workflow Handlers (14 modes)
$ralplan$ultrawork$ultragoalcanceljcode$ultraqa$deep-interview$ultrathink$deepsearch$tdd$code-review$security-review$analyze$wiki3. Additional Features
.jcode/state/modes.toml)Plan Location
Full plan:
docs/keyword-system-master-plan.md(2,209 lines)Implementation Phases
Estimate
~6,080 lines of new/modified code across 27 new files + 8 modified files.
For Implementer
Start with Phase 1 (Detection Engine) in
crates/jcode-keywords/. The plan has exact Rust code snippets for every component. Follow the phases in order — each phase builds on the previous one.