feat: enhance AI communication with dynamic system prompts, robust retry, and TUI formatters
This commit is contained in:
39
.opencode/implementation_plan.md
Normal file
39
.opencode/implementation_plan.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Implementation Plan - Integrating Enhanced Agent Communication
|
||||
|
||||
## Goal Description
|
||||
Integrate the new `agent-prompt.mjs` module (concise, direct, informative patterns) into the OpenQode TUI. Refactor `server.js` (if applicable) and primarily `bin/opencode-ink.mjs` and `qwen-oauth.mjs` to support dynamic system prompt injection and robust retry mechanisms for API calls.
|
||||
|
||||
## User Review Required
|
||||
> [!IMPORTANT]
|
||||
> The `qwen-oauth.mjs` `sendMessage` signature will be updated to accept `systemPrompt` as a 5th argument. This is a non-breaking change as it defaults to null, but ensures future compatibility.
|
||||
|
||||
## Proposed Changes
|
||||
|
||||
### Core Logic
|
||||
|
||||
#### [MODIFY] [qwen-oauth.mjs](file:///e:/TRAE%20Playground/Test%20Ideas/OpenQode-v1.01-Preview/qwen-oauth.mjs)
|
||||
- Update `sendMessage` to accept `systemPrompt` as the 5th argument.
|
||||
- Use the provided `systemPrompt` instead of the hardcoded `systemContext`.
|
||||
- Import `fetchWithRetry` from `lib/retry-handler.mjs` (module import).
|
||||
- Wrap `sendVisionMessage`'s `fetch` call with `fetchWithRetry`.
|
||||
|
||||
#### [MODIFY] [bin/opencode-ink.mjs](file:///e:/TRAE%20Playground/Test%20Ideas/OpenQode-v1.01-Preview/bin/opencode-ink.mjs)
|
||||
- Import `getSystemPrompt` from `../lib/agent-prompt.mjs`.
|
||||
- Import `fetchWithRetry` from `../lib/retry-handler.mjs` (for `callOpenCodeFree`).
|
||||
- In `handleSubmit`:
|
||||
- Gather context (CWD, project context, memories).
|
||||
- Call `getSystemPrompt({ capabilities, cwd, context, projectContext })` to generate the cleaner prompt.
|
||||
- Pass this `systemPrompt` to `qwen.sendMessage` as the 5th argument.
|
||||
- PASS ONLY the user request (and maybe immediate context like "clipboard content") as the message content, removing the manual prompt concatenation.
|
||||
- In `callOpenCodeFree`:
|
||||
- Use `fetchWithRetry` instead of raw `fetch`.
|
||||
|
||||
## Verification Plan
|
||||
|
||||
### Automated Tests
|
||||
- None available for TUI interaction.
|
||||
|
||||
### Manual Verification
|
||||
1. **System Prompt Check**: Send a message like "create a file test.txt". Verify the agent responds concisely (OpenCode style) and uses the correct code block format, proving `getSystemPrompt` was used.
|
||||
2. **Retry Check**: Disconnect internet (if possible) or simulate a timeout to verify `fetchWithRetry` logs attempts and handles failure gracefully.
|
||||
3. **Vision Check**: Send an image command (if possible via TUI) to verify `sendVisionMessage` still works with retry.
|
||||
20
.opencode/task.md
Normal file
20
.opencode/task.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Task: Enhance AI Communication Patterns
|
||||
|
||||
## Objectives
|
||||
- [x] Integrate `agent-prompt.mjs` for dynamic system prompts
|
||||
- [x] Implement `fetchWithRetry` for robust API calls
|
||||
- [x] Enhance TUI message rendering with `message-renderer.mjs` formatters
|
||||
|
||||
## Progress
|
||||
- [x] Create Implementation Plan
|
||||
- [x] Backup `qwen-oauth.mjs` and `bin/opencode-ink.mjs`
|
||||
- [x] Update `qwen-oauth.mjs`:
|
||||
- [x] Import `fetchWithRetry`
|
||||
- [x] Add `systemPrompt` support to `sendMessage`
|
||||
- [x] Wrap `sendVisionMessage` with retry logic
|
||||
- [x] Update `bin/opencode-ink.mjs`:
|
||||
- [x] Import `getSystemPrompt` and `fetchWithRetry`
|
||||
- [x] Refactor `handleSubmit` to use dynamic system prompt
|
||||
- [x] Update `callOpenCodeFree` to use `fetchWithRetry`
|
||||
- [x] Apply `formatSuccess`/`formatError` to file save output
|
||||
- [ ] User Verification of functionality
|
||||
37
.opencode/walkthrough.md
Normal file
37
.opencode/walkthrough.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Walkthrough: Enhanced Agent Communication
|
||||
|
||||
I have successfully integrated the enhanced system prompt, retry mechanism, and TUI formatters.
|
||||
|
||||
## Changes Applied
|
||||
|
||||
### 1. Robust API Calls (`qwen-oauth.mjs`)
|
||||
- **Retry Logic**: Integrated `fetchWithRetry` for Vision API calls.
|
||||
- **Dynamic System Prompt**: `sendMessage` now accepts a `systemPrompt` argument, allowing the TUI to inject context-aware instructions instead of relying on hardcoded overrides.
|
||||
|
||||
### 2. TUI Logic (`bin/opencode-ink.mjs`)
|
||||
- **System Prompt Injection**: `handleSubmit` now generates a clean, role-specific system prompt using `lib/agent-prompt.mjs`.
|
||||
- **Stream Refactoring**: Unified the streaming callback logic for cleaner code.
|
||||
- **Retry Integration**: `callOpenCodeFree` now uses `fetchWithRetry` for better resilience.
|
||||
- **Visual Feedback**: File save operations now use `formatSuccess` and `formatFileOperation` for consistent, bordered output.
|
||||
|
||||
## Verification Steps
|
||||
|
||||
> [!IMPORTANT]
|
||||
> You **MUST** restart your TUI process (`node bin/opencode-ink.mjs`) for these changes to take effect.
|
||||
|
||||
1. **Restart the TUI**.
|
||||
2. **Test System Prompt**:
|
||||
- Send a simple greeting: "Hello".
|
||||
- **Expected**: A concise, direct response (no "As an AI..." preamble).
|
||||
- ask "Create a file named `demo.txt` with text 'Hello World'".
|
||||
- **Expected**: The agent should generate the file using the correct code block format.
|
||||
3. **Test Visual Feedback**:
|
||||
- Observe the success message after file creation.
|
||||
- **Expected**: A green bordered box saying "✅ Success" with the file details.
|
||||
4. **Test Retry (Optional)**:
|
||||
- If you can simulate a network glitch, the system should now log "Retrying...".
|
||||
|
||||
## Rollback
|
||||
Backups were created before applying changes:
|
||||
- `qwen-oauth.mjs.bak`
|
||||
- `bin/opencode-ink.mjs.bak`
|
||||
Reference in New Issue
Block a user