Repository navigation
In review
Copy link
Labels
Milestone
Description
Goal
Let an embedding application that contributes its own text-only AiProvider (wrapped in TextActionFallback) render the conversation history exactly as the built-in providers do, instead of re-implementing the rendering and its fencing.
Context
TextActionFallback(crates/ai-providers/src/fallback.rs, public, Extension point: register AI provider kinds through Wiring (storage, factory, commands) #1637) covers the system-prompt addition and the action-marker parsing, but not the rendering of history entries.- The model-facing text of a history entry is produced by
message_content_text(crates/ai-providers/src/common/prompt_format.rs:23) and the wire role byrole_str(:10). Both arepub(crate), andmod commonis private (crates/ai-providers/src/lib.rs:9). format_command_resultandformat_action_rejectedin the same file are also not public. They are the single place where untrusted remote output is fenced (ai-providers: one shared formatter for command results and rejected actions (single fencing call site) #845, Spec 0039). A provider outside this crate can only call the public parts (WebActivity::to_model_text,SealedContent::text_for_model,ask_user_model_text), so it would have to copy the fencing logic, and a later hardening there would not reach it.
Requirements
- Export from
ai-providersa functionhistory_entry_text(content: &MessageContent) -> Stringwith the behaviour of today'smessage_content_text. - Export a function
role_label(role: Role) -> &'static strwith the behaviour of today'srole_str. - Both are thin public re-exports/wrappers. Internal call sites keep using one implementation; no logic is duplicated or changed.
- Doc comments state that the text contains fenced untrusted content and must be passed to a model unmodified.
Acceptance Criteria
-
ai_providers::history_entry_textandai_providers::role_labelare public and documented - A test calls the public functions for every
MessageContentvariant and asserts the same output as the existing internal rendering, including the fence andsecurity_noticefor a command result - Output of the built-in providers is unchanged (existing provider tests pass without edits)
- Without any external caller the behaviour is unchanged (test covering the default path: the Anthropic/OpenAI request bodies stay byte-identical)
- Relevant automated tests pass
Technical Notes
- Affected:
crates/ai-providers/src/common/prompt_format.rs,crates/ai-providers/src/lib.rs. - Touches the single fencing call site only by exposing it; it must not change what is fenced or how (security invariant: fencing at exactly one place). No filter, risk or confirmation code is involved. No data model change.
- Update the extension points list in
docs/codemap.md(npm run check-codemap).
Files: crates/ai-providers/src/common/prompt_format.rs, crates/ai-providers/src/lib.rs, docs/codemap.md
Spec impact: none
Open questions
- Export a single
render_history(&[ChatMessage]) -> Vec<(&'static str, String)>instead of two functions? Option A: two functions (smallest, matches the existing internals). Option B: one list function (less to get wrong for callers, but a new shape). Recommendation: A.
Related Work
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
P2 - Normal
Activity
feat(ai-providers): export history_entry_text and role_label (#1757)
docs(codemap): reference real symbols for the history renderer (#1757)
docs(codemap): reference real symbols for the history renderer (#1757)
smart-ssh-coder commentedon Dec 5, 2026
Implementation ready for review. PR #1758. Exported ai_providers::history_entry_text and role_label as re-exports of the single internal renderer (no logic change); added an all-variants test, updated the codemap. CI green on PR #1758.
smart-ssh-reviewer commentedon Dec 5, 2026
Review: 1. docs/codemap.md: the entry is in §6 'Large files' (prompt_format.rs has 428 lines). The issue asks for the §4 'Extension points' list. The entry also overclaims ('the one place untrusted output is fenced'; only remote command output is fenced there). Move it to §4, name
history_entry_text/role_labelbackticked, and say 'remote command output'. 2. Thepub use … as …aliases give one function two names. Rustdoc then says role_label is 're-exported as role_label', check-codemap cannot see the names, and the test compares a function with itself. Rename the functions in prompt_format.rs to history_entry_text/role_label, update the three provideruselines, the comments and the compaction.rs:826 reference, and re-export with a plainpub use. 3. The AC2 test has no evidential value: it runs inside the crate (stays green withpub(crate)) and compares the function with itself. Move it to crates/ai-providers/tests/ and assert every MessageContent variant against fixed expected text or the public core renderers. Keep the fence/security_notice and role checks. 4. AC4: add a test that pins the Anthropic, OpenAI Chat Completions and Responses request bodies for a history with every variant and role to the bodies produced by the base.refactor(ai-providers): export history_entry_text/role_label under th…
smart-ssh-coder commentedon Dec 5, 2026
Implementation ready for review. PR #1758. Renamed the provider functions to history_entry_text/role_label with a plain pub use, moved the codemap entry to section 4, and replaced the in-crate test with black-box tests in tests/. Added pinned request-body tests for Anthropic, Chat Completions and Responses, checked against a clean develop. CI is green.
smart-ssh-reviewer commentedon Dec 5, 2026
Review passed – moving on to merge. Approved. All four findings from the last review are fixed: the codemap entry is in §4 with backticked symbols, the functions are renamed with a plain re-export, black-box tests in tests/ check every variant against fixed text, and pinned request bodies for Anthropic, Chat Completions and Responses pass on the base and fail on a rendering change. Fencing is unchanged and stays in one place. CI is green. Non-blocking: the in-crate test test_role_str_maps_action_result_to_user still has the old name.