Skip to content
This repository was archived by the owner on Nov 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bc0b0ce
fix: escape untrusted values in meta context and warnings
gold-silver-copper Oct 25, 2026
80426ec
fix: keep refused global plugins out of discovery; escape errors
gold-silver-copper Oct 25, 2026
95f3bb2
fix: escape plugin discovery and verbose paths
gold-silver-copper Oct 25, 2026
ba8f81d
fix: skip plugin directories other users could write to
gold-silver-copper Oct 25, 2026
6eb68b8
fix: escape plugin list; don't create or warn about a missing global …
gold-silver-copper Oct 25, 2026
3a4f60e
fix: escape backslashes in meta context cells
gold-silver-copper Oct 25, 2026
41302e8
fix: read and write the context cache as a private store; escape a ve…
gold-silver-copper Oct 25, 2026
29f4aa3
fix: check the registry config and plugin files before trusting them
gold-silver-copper Oct 25, 2026
7360740
fix: allow a registry config reached through the user's own symlinks
gold-silver-copper Oct 25, 2026
81ba778
fix: escape paths in meta init output
gold-silver-copper Oct 25, 2026
a1deefd
fix: escape the cwd in a debug line
gold-silver-copper Oct 25, 2026
acf16df
fix: escape paths and errors in worktree discovery debug logs
gold-silver-copper Oct 25, 2026
681de74
fix: escape paths in worktree, registry and plugin errors
gold-silver-copper Oct 25, 2026
6e34eee
fix: --config --recursive fails on a refused nested .meta; escape cac…
gold-silver-copper Oct 25, 2026
4d0005e
fix: escape plugin names, versions and sources in install and update …
gold-silver-copper Oct 25, 2026
a227b81
docs: repo selection spells a repo as name, ./name or name/; '..' pat…
gold-silver-copper Oct 25, 2026
1c20413
fix: escape control characters in log records
gold-silver-copper Oct 26, 2026
ceee3ce
fix: a refused registry config is an error, not the default registry;…
gold-silver-copper Oct 26, 2026
1de0c89
fix: only a missing registry config means the default registry
gold-silver-copper Oct 26, 2026
b51f514
fix: show what a failing plugin printed; escape newlines in log records
gold-silver-copper Oct 26, 2026
fd46a52
fix: follow the fallible config lookup
gold-silver-copper Oct 26, 2026
419b15d
fix: plugin install and update check the plugins dir, its manifest an…
gold-silver-copper Oct 26, 2026
b5af016
fix: write the plugin manifest 0600 and the plugins dir 0700; a PATH …
gold-silver-copper Oct 26, 2026
f88836b
fix: a meta-* program on PATH gets the same trust check as one in a p…
gold-silver-copper Oct 26, 2026
f85414f
fix: skip only PATH programs that lead into a refused plugin dir; uni…
gold-silver-copper Oct 26, 2026
891b714
fix: a PATH program is skipped if any link on its way leads into a re…
gold-silver-copper Oct 26, 2026
799386b
fix: walk PATH programs component by component to catch directory lin…
gold-silver-copper Oct 26, 2026
24a93af
fix: resolve a PATH program from its absolute path, so a relative ent…
gold-silver-copper Oct 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 75 additions & 32 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::time::{Duration, SystemTime};
use crate::dependency_graph::DependencyGraph;
use crate::git_utils;
use meta_core::config::{self, ProjectInfo};
use meta_core::display::{escape, escape_path};

// ── Cache ───────────────────────────────────────────────

Expand All @@ -26,33 +27,26 @@ struct CachedContext {
workspace_root: PathBuf,
}

fn cache_path() -> PathBuf {
fn cache_path() -> anyhow::Result<PathBuf> {
meta_core::data_dir::data_file("context_cache")
}

fn load_cache() -> Option<CachedContext> {
let path = cache_path();
let content = std::fs::read(&path).ok()?;
serde_json::from_slice(&content).ok()
// checked like any store: it is rendered into what agents read
meta_core::store::read::<Option<CachedContext>>(&cache_path().ok()?)
.ok()
.flatten()
}

fn save_cache(cached: &CachedContext, verbose: bool) {
let path = cache_path();
match serde_json::to_vec(cached) {
Ok(json) => {
if let Err(e) = std::fs::write(&path, json) {
if verbose {
eprintln!("Failed to write context cache: {e}");
}
} else if verbose {
eprintln!("Saved context cache to {}", path.display());
}
}
Err(e) => {
if verbose {
eprintln!("Failed to serialize context cache: {e}");
}
}
let Ok(path) = cache_path() else {
return;
};
match meta_core::store::write_atomic(&path, cached) {
Ok(()) if verbose => eprintln!("Saved context cache to {}", escape_path(&path)),
Ok(()) => {}
Err(e) if verbose => eprintln!("Failed to write context cache: {e:#}"),
Err(_) => {}
}
}

Expand Down Expand Up @@ -147,7 +141,7 @@ pub fn handle_context(json: bool, no_status: bool, no_cache: bool, verbose: bool
eprintln!(
"Found {} projects in {}",
projects.len(),
config_path.display()
escape_path(&config_path)
);
}

Expand Down Expand Up @@ -315,15 +309,27 @@ fn build_dependency_map(projects: &[ProjectInfo]) -> Option<HashMap<String, Vec<

// ── Markdown Formatting ─────────────────────────────────

/// Text from `.meta`, git or the filesystem, made safe for this markdown,
/// which agents read: control characters escaped, then `\` and `|` escaped
/// so the value stays in its table cell.
fn md(s: &str) -> String {
escape(s).replace('\\', "\\\\").replace('|', "\\|")
}

fn md_list(items: &[String]) -> String {
items.iter().map(|s| md(s)).collect::<Vec<_>>().join(", ")
}

pub fn format_markdown(ctx: &WorkspaceContext) -> String {
let mut out = String::new();

// Header
out.push_str(&format!(
"# Meta Workspace: {} ({} repos)\n\n",
ctx.name, ctx.repo_count
md(&ctx.name),
ctx.repo_count
));
out.push_str(&ctx.description);
out.push_str(&md(&ctx.description));
out.push_str("\n\n");

// Repo table
Expand All @@ -337,10 +343,10 @@ pub fn format_markdown(ctx: &WorkspaceContext) -> String {
for r in &ctx.repos {
out.push_str(&format!(
"| {} | {} | {} | {} |\n",
r.name,
r.branch.as_deref().unwrap_or("-"),
md(&r.name),
md(r.branch.as_deref().unwrap_or("-")),
format_status(r),
r.tags.join(", "),
md_list(&r.tags),
));
}
} else if has_status {
Expand All @@ -350,8 +356,8 @@ pub fn format_markdown(ctx: &WorkspaceContext) -> String {
for r in &ctx.repos {
out.push_str(&format!(
"| {} | {} | {} |\n",
r.name,
r.branch.as_deref().unwrap_or("-"),
md(&r.name),
md(r.branch.as_deref().unwrap_or("-")),
format_status(r),
));
}
Expand All @@ -361,19 +367,23 @@ pub fn format_markdown(ctx: &WorkspaceContext) -> String {
out.push_str("| Repo | Tags |\n");
out.push_str("|------|------|\n");
for r in &ctx.repos {
out.push_str(&format!("| {} | {} |\n", r.name, r.tags.join(", ")));
out.push_str(&format!("| {} | {} |\n", md(&r.name), md_list(&r.tags)));
}
} else {
for r in &ctx.repos {
out.push_str(&format!("- {}\n", r.name));
out.push_str(&format!("- {}\n", md(&r.name)));
}
}
}

// Key commands
out.push_str("\n## Key Commands\n");
for cmd in &ctx.commands {
out.push_str(&format!("- `{}` — {}\n", cmd.command, cmd.description));
out.push_str(&format!(
"- `{}` — {}\n",
md(&cmd.command),
md(&cmd.description)
));
}

// Dependencies
Expand All @@ -383,7 +393,7 @@ pub fn format_markdown(ctx: &WorkspaceContext) -> String {
sorted_keys.sort();
for key in sorted_keys {
let targets = &deps[key];
out.push_str(&format!("{} → {}\n", key, targets.join(", ")));
out.push_str(&format!("{} → {}\n", md(key), md_list(targets)));
}
}

Expand Down Expand Up @@ -447,6 +457,39 @@ mod tests {
}
}

#[test]
fn markdown_escapes_untrusted_values() {
// Values from git, the filesystem or an old context cache can carry
// terminal escapes or break the table that agents read.
let mut ctx = make_ctx(
vec![make_repo(
"z\u{1b}[2J",
Some("evil|branch\\|x\u{1b}]52;c;cm0K\u{7}"),
Some(false),
Some(0),
vec!["n\nfake"],
)],
Some(HashMap::from([(
"a\u{1b}[1A".to_string(),
vec!["b\nc".to_string()],
)])),
);
ctx.name = "ws\u{1b}]0;TITLE\u{7}".to_string();
let md = format_markdown(&ctx);
assert!(!md.contains('\u{1b}') && !md.contains('\u{7}'), "{md}");
assert!(
md.contains(
"| z\\\\u{1b}[2J | evil\\|branch\\\\\\|x\\\\u{1b}]52;c;cm0K\\\\u{7} | clean | n\\\\nfake |"
),
"{md}"
);
assert!(
md.contains("# Meta Workspace: ws\\\\u{1b}]0;TITLE\\\\u{7} (1 repos)"),
"{md}"
);
assert!(md.contains("a\\\\u{1b}[1A → b\\\\nc"), "{md}");
}

// ── format_status ──────────────────────────────────

#[test]
Expand Down
Loading
Loading