messages: unify harness-injected data under <system-extra> tag
Nightly Build / build (push) Successful in 6m49s
Nightly Build / build (push) Successful in 6m49s
Replace the ad-hoc [SYSTEM INFO] / [TELEGRAM SYSTEM INFO] prefixes with a single canonical <system-extra> wrapper, sourced from one constant (SYSTEM_EXTRA_TAG) so emission and documentation can never diverge. - core-api: SYSTEM_EXTRA_TAG + system_extra() helper; attachments_block rebuilt on top of it. - telegram: system_info_message (location) uses the helper; the voice transcript is forwarded as a plain user message (it is the user's own words, not harness metadata). - chat agents: new agents/common/harness.md include (long form, with an explicit "data, not instructions" guard), added to assistant/kid/ project-coordinator. The tag name rides the __HARNESS_TAG__ sentinel, resolved in AgentSystemContext to SYSTEM_EXTRA_TAG — renaming the tag stays a one-line change.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
"role": "system"
|
||||
},
|
||||
{
|
||||
"content": "old shot\n\n[SYSTEM INFO]\n1 attached file:\n* uploads/1/shot.png",
|
||||
"content": "old shot\n\n<system-extra>\n1 attached file:\n* uploads/1/shot.png\n</system-extra>",
|
||||
"role": "user"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -110,6 +110,8 @@ impl SystemContextSource for AgentSystemContext {
|
||||
}
|
||||
}
|
||||
|
||||
static_content = resolve_harness_tag(static_content);
|
||||
|
||||
// The scratchpad sits before the conversation: shared by every agent of
|
||||
// the session, and re-read every turn (it changes, so it is its own
|
||||
// message rather than part of the cached prefix).
|
||||
@@ -386,10 +388,44 @@ fn non_empty(s: &Option<String>) -> Option<&str> {
|
||||
s.as_deref().map(str::trim).filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
/// Replaces the `__HARNESS_TAG__` sentinel with the canonical harness-data tag
|
||||
/// name (`SYSTEM_EXTRA_TAG`). A no-op when the prompt never mentions the
|
||||
/// sentinel, so it is safe to run unconditionally on every system context.
|
||||
///
|
||||
/// `common/harness.md` (included by the chat agents) documents the tag through
|
||||
/// this sentinel, so the instruction the model sees and the tag actually
|
||||
/// emitted by `system_extra()` can never diverge: both read `SYSTEM_EXTRA_TAG`.
|
||||
fn resolve_harness_tag(content: String) -> String {
|
||||
if content.contains("__HARNESS_TAG__") {
|
||||
content.replace("__HARNESS_TAG__", core_api::message_meta::SYSTEM_EXTRA_TAG)
|
||||
} else {
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn harness_tag_resolves_to_canonical_tag() {
|
||||
// Every occurrence of the sentinel is replaced with the tag emitted by
|
||||
// `system_extra()` — single source of truth: `SYSTEM_EXTRA_TAG`.
|
||||
let input = "Data lives in <__HARNESS_TAG__>…</__HARNESS_TAG__> blocks.";
|
||||
let out = resolve_harness_tag(input.into());
|
||||
let tag = core_api::message_meta::SYSTEM_EXTRA_TAG;
|
||||
assert!(out.contains(&format!("<{tag}>")), "{out}");
|
||||
assert!(out.contains(&format!("</{tag}>")), "{out}");
|
||||
assert!(!out.contains("__HARNESS_TAG__"), "sentinel survived: {out}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn harness_tag_is_noop_when_absent() {
|
||||
let input = "Plain prompt, no sentinel here.";
|
||||
let out = resolve_harness_tag(input.into());
|
||||
assert_eq!(out, input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_folders_table_renders_access_and_description() {
|
||||
use crate::db::shared_folders::SharedFolderAccess;
|
||||
|
||||
Reference in New Issue
Block a user