fix(acp-driver): send the user's task before the host preamble - #153
Luna Qiu (lunaqiu) wants to merge 6 commits into
Conversation
External ACP agents receive Huabu's one-shot system preamble and the user's first prompt concatenated into a single session/prompt message (ACP has no separate system-role channel). The preamble was sent first, so every externally-bound Huabu session started with the exact same static boilerplate text. Several external agents (Copilot CLI observed) title a session from the leading characters of that first message, so every session showed an identical, uninformative title in the agent's own session list (e.g. its VS Code picker) regardless of what the user actually asked. Swap the order so the user's task leads and the preamble trails. The agent still reads the whole message before responding either way, but title heuristics now key off unique, per-session content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Recovery fallback still prepends static history, and architecture documentation still specifies the old ordering.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Reorders ACP’s initial prompt so the user request precedes the host preamble, improving external session titles.
Changes:
- Appends the initial preamble after user content.
- Updates the recovery test’s expected block order.
File summaries
| File | Description |
|---|---|
external/agenetes/packages/acp-driver/src/handle.ts |
Reorders ACP prompt blocks and serialized content. |
external/agenetes/packages/acp-driver/src/recovery.test.ts |
Updates the ordering assertion. |
Review details
Suppressed comments (1)
external/agenetes/packages/acp-driver/src/handle.ts:501
- The current request still does not lead the first ACP prompt on history-fallback recovery:
preparedprependshistoryTextat lines 515–520. When native resume is unavailable, the newly created external session will therefore be titled from the same static history header rather than the user's task, so this fix does not cover all newly opened ACP sessions. Keeplowered.blocksfirst when assembling a fallback prompt (while preserving the intended history and preamble semantics) and cover that ordering in the recovery test.
? `${lowered.serialized}\n\n${preamble}`
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
Recovery and fork prompts still prepend replay history, so the current task does not always lead as documented.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Balanced
There was a problem hiding this comment.
🟡 Changes recommended
Contextual prompts still place selection or attachment metadata before the user’s task, leaving the reported title issue unresolved.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Balanced
| ? `${lowered.serialized}\n\n${preamble}` | ||
| : lowered.serialized, | ||
| blocks: includedPreamble | ||
| ? [{ type: 'text', text: preamble }, ...lowered.blocks] | ||
| ? [...lowered.blocks, { type: 'text', text: preamble }] |
Root cause
Every externally-bound Huabu thread (Copilot CLI / Claude Code / Codex over ACP) opens its session/new + first session/prompt with the host's static system preamble concatenated before the user's actual request, because ACP has no separate system-role channel — both land in the same first message.
External agents that title a session from the leading characters of that first message (Copilot CLI observed) therefore show the exact same uninformative title — "You are a helpful assistant collaborating with a user inside Huabu, an infinite visual Space. The user wor…" — for every externally-bound session, regardless of what the user actually asked. Confirmed by inspecting the agent's own Sessions picker in another tool (VS Code) and matching the truncated text verbatim against �pps/server/src/prompt/external-agent/system_prompt.md.
Fix
Swap the concatenation order in \handle.ts\ so the user's task leads and the host preamble trails (still delivered once, still fully read by the agent before it responds — only the ordering within the single first message changes). Updated the one test that asserted the old order.
Testing
Scope
External-only (\�xternal/agenetes) subtree change; no Huabu-app-side files touched.