Skip to content

[Engine] Backport ConversationManager from lucas-cli (sliding-window history) #221

Description

@pluginslab

Why

Qwen 3 1.7B has a 4096-token context window. The plugin currently sends unbounded conversation history with every LLM call, which causes the model to silently lose earlier context (or fail outright) once the chat grows beyond a few turns. Per the v1 roadmap doc, this is the most urgent engine backport from lucas-cli.

What

Port the ConversationManager class from lucas-cli into src/extensions/services/. It should:

  • Maintain a sliding window over the chat history sized to the active model's MODEL_CONTEXT_SIZES value (4096 for 1.7B, 32768 for 7B, 32768 default for external providers)
  • Reserve headroom for the system prompt + tool descriptions + the maximum expected response tokens
  • Drop oldest turns (or summarize them, if PromptBuilder is also available) when the budget is exceeded
  • Apply to both the local WebLLM path and the ExternalEngine path
  • Expose a hook for /compact style manual compaction down the road

Where

  • src/extensions/services/conversation-manager.js — new file
  • Integrate at react-agent.js and chat-orchestrator.js boundaries where the message array is built before being sent to engine.chat.completions.create()
  • Unit tests in src/extensions/services/__tests__/conversation-manager.test.js

Acceptance

  • Long chats (50+ turns) no longer fail or hallucinate due to context loss
  • Token budget is computed against the active model, not hardcoded
  • Existing unit tests still pass; new tests cover window eviction logic
  • Works for both local (WebLLM) and remote (ExternalEngine) modes

Reference

lucas-cli implementation: see Appendix in the v1 roadmap Google Doc (section "1. ConversationManager — v0.13 (Critical)").

Target

v0.13 (WordPress.org submission release) — without this, the plugin is shipping a known reliability bug.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-mlAI/ML and LLM workenhancementNew feature or requestreact-jsReact/JavaScript frontend work

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions