Skip to content

Extract analyze pattern/message constants to eliminate duplication #3694

@FurryWolfX

Description

@FurryWolfX

Prerequisites

  • I will write this issue in English (see our Language Policy)
  • I have searched existing issues to avoid duplicates
  • I am using the latest version of oh-my-opencode
  • I have read the documentation or asked an AI coding agent with this project's GitHub URL loaded and couldn't find the answer

Bug Description

Problem

src/hooks/keyword-detector/constants.ts had ANALYZE_PATTERN regex and ANALYZE_MESSAGE template string defined inline, while analyze/default.ts already exported identical ANALYZE_PATTERN and ANALYZE_MESSAGE. This created unnecessary duplication — any change to the analyze prompt or pattern required syncing two locations, risking drift.

Context

The keyword-detector module supports three detection modes (ultrawork, search, analyze) by scanning the first user message for mode-specific keywords and injecting corresponding system prompts.

The search mode already correctly imported its pattern/message from the dedicated submodule (search/pattern.ts, search/message.ts), but the analyze mode had a legacy inline definition that bypassed the already-exported constants from analyze/default.ts. Additionally, the analyze mode prompt was missing delegate_task parameter guidance that subagents need to generate proper context.

Steps to Reproduce

read the source code of keyword-detector

Expected Behavior

  1. constants.ts: Delete 18 lines of inline ANALYZE_PATTERN regex and ANALYZE_MESSAGE template string; import { ANALYZE_MESSAGE, ANALYZE_PATTERN } from "./analyze" and reference them directly in KEYWORD_DETECTORS

  2. analyze/default.ts: Append the following block to ANALYZE_MESSAGE:

    ---
    MANDATORY delegate_task params: ALWAYS include load_skills=[] and run_in_background when calling delegate_task.
    Example: delegate_task(subagent_type="explore", prompt="...", run_in_background=true, load_skills=[])
    

Actual Behavior

src/hooks/keyword-detector/constants.ts had ANALYZE_PATTERN regex and ANALYZE_MESSAGE template string defined inline

Doctor Output

install via sourcecode

Error Logs

Configuration

Additional Context

No response

Operating System

Linux

OpenCode Version

1.14.28

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions