diff --git a/CHANGELOG.md b/CHANGELOG.md index a41c351dd..d0095efe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## Unreleased: workspace prompt-file sync and inject helpers (tinyagents#92) + +New `tinyagents_harness::prompt::workspace_files` module, re-exported from +`prompt`. `sync_workspace_file(workspace_dir, filename, default_content)` +seeds a host's default prompt file into a workspace and ships later defaults +only to files the user has not edited, tracked by a `.{filename}.builtin-hash` +sidecar holding the lowercase hex SHA-256 of the default (`builtin_hash`, +`builtin_hash_sidecar_name`). Legacy `DefaultHasher` sidecars never authorize +an overwrite and are migrated to SHA-256. `inject_inline_content` and +`inject_workspace_file_capped` render content under a `### {label}` heading, +capped at a caller-supplied character budget with a truncation marker naming +the caller's read-file tool. Moved from OpenHuman's +`prompts/workspace_files.rs`; the on-disk format and rendered bytes are +unchanged. See `docs/modules/harness/prompt.md`. + ## 3.1.4 - Releases are cut from `main`: the version bump merges through a pull request diff --git a/crates/tinyagents-harness/src/prompt/README.md b/crates/tinyagents-harness/src/prompt/README.md index 8a3fa32e5..21d486301 100644 --- a/crates/tinyagents-harness/src/prompt/README.md +++ b/crates/tinyagents-harness/src/prompt/README.md @@ -49,6 +49,14 @@ KV-cache/prompt-cache keeps hitting. exported `EXECUTION_DISCIPLINE` block by model family, falling back from an unknown or blank model alias to its provider while explicitly excluding Claude and Gemini families. +- Workspace prompt files (`workspace_files`): `sync_workspace_file` seeds a + host's default file into a workspace and refreshes it when the default + changes unless the user edited it, tracked by a SHA-256 sidecar named by + `builtin_hash_sidecar_name` (`.{filename}.builtin-hash`, contents + `builtin_hash`). `inject_inline_content` and `inject_workspace_file_capped` + render content under a `### {label}` heading, capped at a character budget + with a truncation marker naming the host's read-file tool. The host passes + the default contents, the cap, and the read-tool name. - System-segment helpers: `SYSTEM_SEGMENT_ID`, `system_segment_id`, and `is_system_segment_id` define the canonical `system`, `system.1`, ... IDs used for one cacheable segment per leading system-message tier. @@ -58,6 +66,8 @@ KV-cache/prompt-cache keeps hitting. | File | Role | | --- | --- | | `types.rs` | Every public type: templates, `PromptBuilder` (and its private `BuiltSegment`), section assembly, and tiered dynamic prompt composition. | +| `workspace_files.rs` | Workspace prompt-file seeding (`sync_workspace_file`, SHA-256 builtin-hash sidecar) and capped `###`-heading injection. | +| `workspace_files_tests.rs` | Unit tests for the sidecar format, upgrade/edit/legacy-sidecar cases, and byte-exact injection and truncation. | | `model_guidance.rs` | Model-family matching and the optional execution-discipline prompt block. | | `mod.rs` | Behavioral code: the `{name}` template renderer, `PromptBuilder` methods (segment pushes, `build`, `fingerprint`), and the section-assembly free functions. | | `mod_tests.rs` | Unit tests for placeholder substitution/escaping, error cases, per-role rendering, `MessagesTemplate` ordering, and `PromptBuilder` segment cacheability/fingerprinting. | diff --git a/crates/tinyagents-harness/src/prompt/mod.rs b/crates/tinyagents-harness/src/prompt/mod.rs index 3eeed1029..356e3d91d 100644 --- a/crates/tinyagents-harness/src/prompt/mod.rs +++ b/crates/tinyagents-harness/src/prompt/mod.rs @@ -33,12 +33,17 @@ mod model_guidance; mod types; +pub mod workspace_files; pub use model_guidance::{ EXECUTION_DISCIPLINE, NEEDS_EXECUTION_DISCIPLINE, execution_discipline_for, execution_discipline_for_profile, needs_execution_discipline, }; pub use types::*; +pub use workspace_files::{ + builtin_hash, builtin_hash_sidecar_name, inject_inline_content, inject_workspace_file_capped, + sync_workspace_file, +}; /// Marker that changes a dynamic prompt body's following text to the context tier. pub const PROMPT_TIER_CONTEXT_MARKER: &str = ""; diff --git a/crates/tinyagents-harness/src/prompt/workspace_files.rs b/crates/tinyagents-harness/src/prompt/workspace_files.rs new file mode 100644 index 000000000..414172f27 --- /dev/null +++ b/crates/tinyagents-harness/src/prompt/workspace_files.rs @@ -0,0 +1,214 @@ +//! Workspace prompt files: seeding a host's bundled default files into a +//! workspace directory, and injecting on-disk or inline content into a prompt +//! under a `###` heading with a character cap. +//! +//! The host owns the file contents, the names, and the character budget; this +//! module owns the on-disk contract and the rendered bytes: +//! +//! - [`sync_workspace_file`] writes a default file into the workspace and +//! records the SHA-256 of that default in a `.{filename}.builtin-hash` +//! sidecar ([`builtin_hash_sidecar_name`]). When the default changes it +//! replaces the file only if the file still matches the default the sidecar +//! recorded, so user edits survive releases. +//! - [`inject_inline_content`] and [`inject_workspace_file_capped`] render +//! `### {label}\n\n{content}\n\n`, cut at `max_chars` characters with a +//! marker that names the tool the model can use to read the whole file. + +use std::fmt::Write; +use std::path::Path; + +/// The sidecar file name that records the built-in hash for `filename`: +/// `.{filename}.builtin-hash`, a sibling of the file in the workspace. +#[must_use] +pub fn builtin_hash_sidecar_name(filename: &str) -> String { + format!(".{filename}.builtin-hash") +} + +/// The hash recorded in the `.{filename}.builtin-hash` sidecar: lowercase hex +/// SHA-256 of `content`'s UTF-8 bytes (64 characters). +/// +/// SHA-256's output is fixed forever, unlike `DefaultHasher`, which a +/// toolchain bump may change and so make an edited file look untouched. +#[must_use] +pub fn builtin_hash(content: &str) -> String { + use sha2::{Digest, Sha256}; + Sha256::digest(content.as_bytes()) + .iter() + .map(|byte| format!("{byte:02x}")) + .collect() +} + +/// Whether the on-disk `disk` content still matches the built-in recorded in +/// the `stored` sidecar. +/// +/// Only a SHA-256 sidecar may authorize an overwrite. A legacy 16-hex +/// `DefaultHasher` sidecar is migrated by the caller, but is never trusted to +/// classify disk content as unedited: a collision or a changed `DefaultHasher` +/// implementation could otherwise overwrite a user's file. +fn matches_stored_builtin(disk: &str, stored: &str) -> bool { + stored.len() == 64 && builtin_hash(disk) == stored +} + +/// Ensure `workspace_dir/filename` is up to date with the host's +/// `default_content`. +/// +/// On first install the file doesn't exist, so it is written. Every sync +/// stores the SHA-256 of `default_content` in the +/// [`builtin_hash_sidecar_name`] sidecar. When the default changes (the host +/// shipped a new one), the file is overwritten only if its current content +/// still hashes to the stored built-in, so prompt improvements ship +/// automatically while user edits between releases are preserved. An edited +/// file is left in place and the sidecar moves to the new hash, so the old +/// default is not re-compared on every sync. +/// +/// Does nothing when `default_content` is empty (the host has no default for +/// this file) or when `workspace_dir` is not absolute: a relative path means +/// the caller has no workspace (typically `Path::new(".")` in a test +/// fixture), and seeding into it would drop the file and its sidecar into the +/// process's current directory. +/// +/// Failures are logged, never returned: a failed file write logs a warning +/// and leaves the sidecar unchanged; a failed sidecar write is ignored. +pub fn sync_workspace_file(workspace_dir: &Path, filename: &str, default_content: &str) { + if default_content.is_empty() { + return; + } + + if !workspace_dir.is_absolute() { + tracing::debug!( + "[workspace-sync] refusing to seed {filename} into non-absolute workspace {} \ + — no workspace configured", + workspace_dir.display() + ); + return; + } + + let path = workspace_dir.join(filename); + let hash_path = workspace_dir.join(builtin_hash_sidecar_name(filename)); + + let current_hash = builtin_hash(default_content); + + // Read the last-written hash (if any). + let stored_hash = std::fs::read_to_string(&hash_path).unwrap_or_default(); + let stored_hash = stored_hash.trim(); + + if stored_hash == current_hash && path.exists() { + // Built-in hasn't changed and file exists — nothing to do. + return; + } + + // Two safe cases to write the default: + // 1. The file doesn't exist yet — first install. + // 2. The file exists and its hash matches the stored built-in hash — + // the user hasn't edited it since it was last written. + // Otherwise the file was hand-edited; keep it and only move the sidecar. + let file_exists = path.exists(); + let user_unmodified = if file_exists { + match std::fs::read_to_string(&path) { + Ok(disk) => matches_stored_builtin(&disk, stored_hash), + Err(_) => false, + } + } else { + false + }; + + if let Some(parent) = path.parent() { + let _ = std::fs::create_dir_all(parent); + } + + if !file_exists || user_unmodified { + if let Err(e) = std::fs::write(&path, default_content) { + tracing::warn!("[agent:prompt] failed to write workspace file {filename}: {e}"); + return; + } + tracing::info!( + "[agent:prompt] updated workspace file {filename} (builtin content changed)" + ); + } else { + tracing::info!( + "[agent:prompt] keeping user-edited workspace file {filename} (builtin changed but disk contents diverge)" + ); + } + let _ = std::fs::write(&hash_path, ¤t_hash); +} + +/// Inject `content` into `prompt` under a `### {label}` heading, capped at +/// `max_chars` characters (Unicode scalar values, not bytes). +/// +/// Renders `### {label}\n\n` followed by the trimmed content and `\n\n`. When +/// the trimmed content is longer than `max_chars`, it is cut at that many +/// characters and followed by +/// ``\n\n[... truncated at {max_chars} chars — use `{read_tool}` for full file]\n\n``, +/// where `read_tool` is the host's name for the tool that reads a file. +/// +/// Empty or whitespace-only content is silently skipped. +pub fn inject_inline_content( + prompt: &mut String, + label: &str, + content: &str, + max_chars: usize, + read_tool: &str, +) { + let trimmed = content.trim(); + if trimmed.is_empty() { + return; + } + let _ = writeln!(prompt, "### {label}\n"); + let truncated = if trimmed.chars().count() > max_chars { + trimmed + .char_indices() + .nth(max_chars) + .map(|(idx, _)| &trimmed[..idx]) + .unwrap_or(trimmed) + } else { + trimmed + }; + prompt.push_str(truncated); + if truncated.len() < trimmed.len() { + let _ = writeln!( + prompt, + "\n\n[... truncated at {max_chars} chars — use `{read_tool}` for full file]\n" + ); + } else { + prompt.push_str("\n\n"); + } +} + +/// Inject `workspace_dir/filename` into `prompt` under a `### {filename}` +/// heading, capped at `max_chars` characters. +/// +/// The rendering is exactly [`inject_inline_content`] with `filename` as the +/// label. A missing or empty file is silently skipped, so callers can inject +/// optional files unconditionally; any other read error is logged at debug +/// level and skipped. +/// +/// **KV-cache contract:** the output is a pure function of `filename`, the +/// file bytes at call time, `max_chars`, and `read_tool`. Read each file once +/// per session — re-reading mid-session can change the prompt prefix and +/// break an inference backend's prefix cache. +pub fn inject_workspace_file_capped( + prompt: &mut String, + workspace_dir: &Path, + filename: &str, + max_chars: usize, + read_tool: &str, +) { + let path = workspace_dir.join(filename); + + match std::fs::read_to_string(&path) { + Ok(content) => inject_inline_content(prompt, filename, &content, max_chars, read_tool), + Err(e) => match e.kind() { + std::io::ErrorKind::NotFound => { + // Missing optional files add no placeholder, keeping the + // prompt focused. + } + _ => { + tracing::debug!("[prompt] failed to read {}: {e}", path.display()); + } + }, + } +} + +#[cfg(test)] +#[path = "workspace_files_tests.rs"] +mod tests; diff --git a/crates/tinyagents-harness/src/prompt/workspace_files_tests.rs b/crates/tinyagents-harness/src/prompt/workspace_files_tests.rs new file mode 100644 index 000000000..462336337 --- /dev/null +++ b/crates/tinyagents-harness/src/prompt/workspace_files_tests.rs @@ -0,0 +1,282 @@ +use super::*; + +/// Stands in for a host's bundled default file. +const BUILTIN: &str = "the current built-in SOUL.md\n"; +/// Stands in for a host's read-file tool name. +const READ_TOOL: &str = "file_read"; + +fn sidecar_path(workspace: &Path) -> std::path::PathBuf { + workspace.join(".SOUL.md.builtin-hash") +} + +/// The sidecar format every sync must leave behind: lowercase hex SHA-256 of +/// the built-in. Computed here independently of the code under test. +fn sha256_hex(content: &str) -> String { + use sha2::{Digest, Sha256}; + let digest = Sha256::digest(content.as_bytes()); + let mut out = String::new(); + for byte in digest { + out.push_str(&format!("{byte:02x}")); + } + out +} + +/// The legacy sidecar format: `DefaultHasher`, whose output may change with +/// any Rust release. +fn legacy_hash(content: &str) -> String { + use std::hash::{Hash, Hasher}; + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + content.hash(&mut hasher); + format!("{:016x}", hasher.finish()) +} + +#[test] +fn the_sidecar_is_a_dotfile_named_after_the_file() { + assert_eq!( + builtin_hash_sidecar_name("SOUL.md"), + ".SOUL.md.builtin-hash" + ); +} + +#[test] +fn the_builtin_hash_is_lowercase_hex_sha256() { + // Known SHA-256 vector, pinned so the on-disk format can never drift. + assert_eq!( + builtin_hash("abc"), + "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" + ); + assert_eq!(builtin_hash(BUILTIN), sha256_hex(BUILTIN)); +} + +#[test] +fn a_new_builtin_replaces_an_untouched_file_and_keeps_an_edited_one() { + // A release changes the bundled SOUL.md. A workspace whose copy still + // matches the previous built-in gets the new one; a workspace where the + // user edited it keeps the edit. Both record the new built-in's hash. + let previous = "previous built-in SOUL.md"; + for (on_disk, expected) in [ + (previous, BUILTIN), + ("the user's own SOUL.md", "the user's own SOUL.md"), + ] { + let workspace = tempfile::tempdir().unwrap(); + std::fs::write(workspace.path().join("SOUL.md"), on_disk).unwrap(); + std::fs::write(sidecar_path(workspace.path()), sha256_hex(previous)).unwrap(); + + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + + assert_eq!( + std::fs::read_to_string(workspace.path().join("SOUL.md")).unwrap(), + expected, + "on disk before the upgrade: {on_disk:?}" + ); + assert_eq!( + std::fs::read_to_string(sidecar_path(workspace.path())).unwrap(), + sha256_hex(BUILTIN) + ); + } +} + +#[test] +fn the_builtin_hash_sidecar_is_a_stable_sha256() { + // `DefaultHasher` is not stable across Rust releases, so a toolchain bump + // could make an edited file look like an untouched built-in. The sidecar + // must be a hash whose output is fixed forever. + let workspace = tempfile::tempdir().unwrap(); + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + + assert_eq!( + std::fs::read_to_string(workspace.path().join("SOUL.md")).unwrap(), + BUILTIN + ); + let sidecar = std::fs::read_to_string(sidecar_path(workspace.path())).unwrap(); + assert_eq!(sidecar, sha256_hex(BUILTIN)); + + // A second sync with nothing changed leaves the file and sidecar alone. + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + assert_eq!( + std::fs::read_to_string(sidecar_path(workspace.path())).unwrap(), + sidecar + ); +} + +#[test] +fn a_legacy_sidecar_is_migrated_without_authorizing_an_overwrite() { + // A workspace synced before the SHA-256 sidecar: its SOUL.md is still the + // previous built-in and the sidecar holds that built-in's `DefaultHasher` + // hash. Legacy hashes are not trusted to distinguish an untouched file + // from a colliding user edit. Preserve disk content and migrate the + // sidecar. + let workspace = tempfile::tempdir().unwrap(); + let soul = workspace.path().join("SOUL.md"); + let sidecar = sidecar_path(workspace.path()); + std::fs::write(&soul, "previous built-in SOUL.md").unwrap(); + std::fs::write(&sidecar, legacy_hash("previous built-in SOUL.md")).unwrap(); + + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + + assert_eq!( + std::fs::read_to_string(&soul).unwrap(), + "previous built-in SOUL.md" + ); + assert_eq!( + std::fs::read_to_string(&sidecar).unwrap(), + sha256_hex(BUILTIN) + ); +} + +#[test] +fn a_user_edited_file_with_a_legacy_sidecar_is_never_overwritten() { + // Same legacy workspace, but the user edited SOUL.md. Neither the format + // change nor a legacy sidecar from another toolchain may cost them the + // edit; the sidecar still moves to SHA-256. + for stored in [ + legacy_hash("previous built-in SOUL.md"), + // A collision with the edited disk content must not authorize it. + legacy_hash("the user's own SOUL.md"), + // A sidecar written by a different toolchain's `DefaultHasher`. + "0123456789abcdef".to_string(), + ] { + let workspace = tempfile::tempdir().unwrap(); + let soul = workspace.path().join("SOUL.md"); + let sidecar = sidecar_path(workspace.path()); + std::fs::write(&soul, "the user's own SOUL.md").unwrap(); + std::fs::write(&sidecar, &stored).unwrap(); + + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + + assert_eq!( + std::fs::read_to_string(&soul).unwrap(), + "the user's own SOUL.md", + "stored sidecar: {stored:?}" + ); + assert_eq!( + std::fs::read_to_string(&sidecar).unwrap(), + sha256_hex(BUILTIN) + ); + } +} + +#[test] +fn an_edit_made_after_sync_survives_a_resync() { + let workspace = tempfile::tempdir().unwrap(); + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + let original_hash = std::fs::read_to_string(sidecar_path(workspace.path())).unwrap(); + + std::fs::write(workspace.path().join("SOUL.md"), "user override").unwrap(); + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + + assert_eq!( + std::fs::read_to_string(sidecar_path(workspace.path())).unwrap(), + original_hash + ); + assert_eq!( + std::fs::read_to_string(workspace.path().join("SOUL.md")).unwrap(), + "user override" + ); +} + +#[test] +fn a_deleted_file_is_rewritten_even_when_the_sidecar_is_current() { + let workspace = tempfile::tempdir().unwrap(); + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + std::fs::remove_file(workspace.path().join("SOUL.md")).unwrap(); + + sync_workspace_file(workspace.path(), "SOUL.md", BUILTIN); + + assert_eq!( + std::fs::read_to_string(workspace.path().join("SOUL.md")).unwrap(), + BUILTIN + ); +} + +#[test] +fn an_empty_default_writes_nothing() { + let workspace = tempfile::tempdir().unwrap(); + sync_workspace_file(workspace.path(), "UNKNOWN.md", ""); + assert_eq!(std::fs::read_dir(workspace.path()).unwrap().count(), 0); +} + +#[test] +fn a_relative_workspace_is_never_seeded() { + // Seeding into a relative path would drop the file and its sidecar into + // the process's current directory. + let filename = format!("workspace-files-test-{}.md", uuid::Uuid::new_v4()); + sync_workspace_file(Path::new("."), &filename, BUILTIN); + assert!(!Path::new(&filename).exists()); + assert!(!Path::new(&builtin_hash_sidecar_name(&filename)).exists()); +} + +#[test] +fn the_truncation_marker_names_the_given_read_tool() { + // The model is told how to recover a truncated file; the tool it is told + // to call must be one it has. + let mut inline = String::new(); + inject_inline_content(&mut inline, "NOTES.md", "abcdefghij", 4, READ_TOOL); + assert!(inline.contains("use `file_read` for full file"), "{inline}"); + + let workspace = tempfile::tempdir().unwrap(); + std::fs::write(workspace.path().join("NOTES.md"), "abcdefghij").unwrap(); + let mut from_disk = String::new(); + inject_workspace_file_capped(&mut from_disk, workspace.path(), "NOTES.md", 4, READ_TOOL); + assert!( + from_disk.contains("use `file_read` for full file"), + "{from_disk}" + ); +} + +#[test] +fn injected_content_renders_byte_exact() { + let mut whole = String::new(); + inject_inline_content(&mut whole, "SOUL.md", " be kind \n", 100, READ_TOOL); + assert_eq!(whole, "### SOUL.md\n\nbe kind\n\n"); + + let mut cut = String::new(); + inject_inline_content(&mut cut, "NOTES.md", "abcdefghij", 4, READ_TOOL); + assert_eq!( + cut, + "### NOTES.md\n\nabcd\n\n[... truncated at 4 chars — use `file_read` for full file]\n\n" + ); + + // Exactly at the cap is not truncated. + let mut exact = String::new(); + inject_inline_content(&mut exact, "NOTES.md", "abcd", 4, READ_TOOL); + assert_eq!(exact, "### NOTES.md\n\nabcd\n\n"); +} + +#[test] +fn the_cap_counts_characters_not_bytes() { + let mut prompt = String::new(); + inject_inline_content(&mut prompt, "NOTES.md", "héllo wörld", 5, READ_TOOL); + assert!(prompt.starts_with("### NOTES.md\n\nhéllo\n\n[... truncated at 5 chars")); + + // Five multi-byte characters fit a five-character cap. + let mut fits = String::new(); + inject_inline_content(&mut fits, "NOTES.md", "ééééé", 5, READ_TOOL); + assert_eq!(fits, "### NOTES.md\n\nééééé\n\n"); +} + +#[test] +fn blank_content_and_missing_files_inject_nothing() { + let mut prompt = String::from("before"); + inject_inline_content(&mut prompt, "NOTES.md", " \n\t ", 10, READ_TOOL); + + let workspace = tempfile::tempdir().unwrap(); + inject_workspace_file_capped(&mut prompt, workspace.path(), "MISSING.md", 10, READ_TOOL); + std::fs::write(workspace.path().join("EMPTY.md"), "\n \n").unwrap(); + inject_workspace_file_capped(&mut prompt, workspace.path(), "EMPTY.md", 10, READ_TOOL); + // A read error other than not-found (here: a directory) is skipped too. + std::fs::create_dir(workspace.path().join("DIR.md")).unwrap(); + inject_workspace_file_capped(&mut prompt, workspace.path(), "DIR.md", 10, READ_TOOL); + + assert_eq!(prompt, "before"); +} + +#[test] +fn a_synced_file_injects_under_its_name_and_truncates_at_the_cap() { + let workspace = tempfile::tempdir().unwrap(); + std::fs::write(workspace.path().join("BIG.md"), "x".repeat(20_000 + 50)).unwrap(); + let mut prompt = String::new(); + inject_workspace_file_capped(&mut prompt, workspace.path(), "BIG.md", 20_000, READ_TOOL); + assert!(prompt.contains("### BIG.md")); + assert!(prompt.contains("[... truncated at 20000 chars")); +} diff --git a/docs/modules/harness/prompt.md b/docs/modules/harness/prompt.md index 3e634eeb4..541f0ca94 100644 --- a/docs/modules/harness/prompt.md +++ b/docs/modules/harness/prompt.md @@ -44,6 +44,27 @@ Prompt rendering should be explicit and typed. A template should declare: Prompt rendering errors should happen before model invocation and should be classified separately from provider errors. +## Workspace Prompt Files + +`prompt::workspace_files` covers prompt files a host bundles and lets the user +edit on disk (for example `SOUL.md`). The host keeps the file contents, the +names, the character cap, and the name of its read-file tool; the harness owns +the on-disk contract and the rendered bytes. + +- `sync_workspace_file(workspace_dir, filename, default_content)` writes the + default when the file is absent and records the lowercase hex SHA-256 of the + default in a `.{filename}.builtin-hash` sidecar. When the default changes it + replaces the file only if the file still hashes to the stored built-in, so + user edits survive. A legacy 16-hex `DefaultHasher` sidecar never authorizes + an overwrite; it is replaced by the SHA-256. A relative `workspace_dir` or an + empty default is a no-op, and I/O failures are logged, never returned. +- `inject_inline_content(prompt, label, content, max_chars, read_tool)` and + `inject_workspace_file_capped(prompt, workspace_dir, filename, max_chars, + read_tool)` render `### {label}` plus the trimmed content, cut at + `max_chars` characters with + ``[... truncated at {max_chars} chars — use `{read_tool}` for full file]``. + Blank content and missing files render nothing. + ## Runtime Context Dynamic prompts may use: