This file guides coding agents working in this repository.
This is the open-source AskWP WordPress plugin codebase.
- Contains plugin code only
- Does not contain marketing site theme/content/config
- Plugin changes are visible on the local marketing site via symlink (
http://localhost:8883/)
Work in this repo for:
- WordPress plugin PHP logic
- Plugin frontend widget/admin JS and CSS
- REST endpoints and provider integrations
Do not implement marketing site changes here. If the request is about site pages/SEO/theme/content/design, use askwp-site/ instead.
askwp.php: plugin bootstrap, defaults, enqueue logic,ASKWP_CONFIGincludes/admin-settings.php: settings UI (includes Usage dashboard tab)includes/security.php: origin checks, rate limiting, text utilitiesincludes/rag.php: page resolution, search, FAQ matching, context assemblyincludes/rest-chat.php:POST /askwp/v1/chatincludes/rest-form.php:POST /askwp/v1/submit_formincludes/stream-chat.php: SSE streaming chat endpoint via admin-ajaxincludes/llm-provider.php: abstract provider baseincludes/llm-openai.php: OpenAI Responses providerincludes/llm-anthropic.php: Anthropic Messages providerincludes/llm-openrouter.php: OpenRouter Chat Completions providerincludes/llm-ollama.php: Ollama providerincludes/llm-factory.php: provider instantiation/factoryassets/widget.js: frontend chat widget (vanilla ES5 IIFE)assets/widget.css: widget stylesassets/admin-form-builder.js: admin form field builderassets/admin-usage-dashboard.js: admin token/cost usage dashboardassets/admin.css: admin stylingreadme.txt: WordPress.org metadata
assets/widget.jsposts{messages, page_url, page_title}to/askwp/v1/chatincludes/rest-chat.phpvalidates origin, rate limits, payload, message lengthsincludes/rest-chat.phpapplies deterministic guards (injection/status handling)includes/rag.phpresolves page + search + FAQ matching + ranked context blocksincludes/llm-factory.phpselects provider; tools are provider-dependentincludes/rest-chat.phpbuilds final system prompt (admin prompt + context + page info)- API returns
{reply, sources, action, usage}
Important retrieval rule:
askwp_rag_build_context()uses the latest user message only for retrieval terms.
- Follow WordPress coding standards
- Prefix plugin functions with
askwp_ - Store options as
askwp_*inwp_options
- Vanilla ES5 IIFE style (no modules/imports/build tooling)
- Prefix DOM classes with
askwp- - Keep frontend state in a single
stateobject when extending widget logic - Use existing
askwp_*_v1localStorage patterns
- Prefix custom properties with
--askwp- - No preprocessor; edit CSS directly
- Preserve host-site font inheritance unless the feature requires explicit override
- Preserve
ASKWP_LLM_Providerabstraction and factory pattern - Keep providers isolated in their own implementation files
Configuration is runtime/site-specific in WordPress DB options (askwp_* in wp_options).
Do not introduce repo-based config for settings already managed in admin.
- No build step: edit
.php,.js,.cssdirectly - Keep changes small, focused, and backwards-compatible
- Maintain REST endpoint compatibility unless explicitly requested
- License remains GPLv2-or-later compatible
- Streaming chat is implemented end-to-end (
stream_urlin config +includes/stream-chat.php+ streaming logic inassets/widget.js). - Multi-provider support currently includes OpenAI, Anthropic, OpenRouter, and Ollama.
- Documentation drift exists: some docs still say "7-tab" settings, while code includes a Usage tab.
- Origin validation logic is duplicated in
includes/security.phpandincludes/stream-chat.php; keep behavior aligned when changing either path. - No automated test suite is currently present in this repository.
Before editing:
- Confirm request belongs to plugin scope
- Identify affected layer (widget, REST, RAG, provider, admin)
When editing:
- Reuse existing naming and prefix conventions
- Avoid broad refactors unless required by task
- Preserve retrieval behavior unless asked to change it
Before finishing:
- Validate changed files for syntax/regression risk
- Summarize what changed and why
- Call out any follow-up testing needed