Bruno-Cunha-Souza/ValarMindSkills / skills/context-optimization
context-optimization
UnverifiedLifecycle context audit/optimize/plan. Audit mode (Phase 0..6) + Guide mode (catalog lookup). Targets long-conv agents, RAG pipelines, sub-agents, large-doc workflows. Detects bloat/dedup/cache/masking/partition opportunities. Emits findings (SAFE/REVIEW/BREAKING) + optimization plan + token delta. Read-only — LGTM if sound. Triggers: 'optimize context', 'compact context', 'auditar contexto', 'otimizar contexto', '/context-optimization'.
| File | Kind | Size |
|---|---|---|
| EXAMPLE.md | markdown | 13.7 KB |
| SKILL.md | skill md | 10.5 KB |
| references/CHECKLIST.md | markdown | 5.7 KB |
| references/HARNESS_NOTES.md | markdown | 7.8 KB |
| references/SEVERITY_RUBRIC.md | markdown | 9.0 KB |
| references/TECHNIQUES.md | markdown | 19.6 KB |
| references/USE_CASES.md | markdown | 13.8 KB |
| scripts/.gitignore | other | 139 B |
| scripts/README.md | markdown | 6.8 KB |
| scripts/ctxopt/Cargo.lock | manifest | 27.2 KB |
| scripts/ctxopt/Cargo.toml | manifest | 676 B |
| scripts/ctxopt/src/cli.rs | script | 3.3 KB |
| scripts/ctxopt/src/count.rs | script | 5.5 KB |
| scripts/ctxopt/src/dedup.rs | script | 5.5 KB |
| scripts/ctxopt/src/emit.rs | script | 4.4 KB |
| scripts/ctxopt/src/finding.rs | script | 2.3 KB |
| scripts/ctxopt/src/main.rs | script | 7.4 KB |
| scripts/ctxopt/src/report.rs | script | 11.8 KB |
| scripts/ctxopt/src/scan.rs | script | 5.1 KB |
| scripts/ctxopt/src/toon.rs | script | 5.6 KB |
| scripts/ctxopt/tests/integration.rs | script | 3.2 KB |
| scripts/run-all.shexecutable | script | 1.3 KB |
scripts/ctxopt/src/emit.rs
View on GitHub//! FindingWriter trait + implementations for JSONL / TOON / JSON output.
use crate::cli::Format;
use crate::finding::Finding;
use crate::toon;
use std::fs::OpenOptions;
use std::io::{self, BufWriter, Write};
use std::path::Path;
pub trait FindingWriter {
/// Append a single finding to the output stream.
fn write(&mut self, f: &Finding) -> io::Result<()>;
/// Flush + finalize (no-op for JSONL; needed for TOON to flush buffered count).
fn finalize(&mut self) -> io::Result<()>;
}
/// JSONL: one finding per line.
pub struct JsonlWriter {
inner: BufWriter<std::fs::File>,
}
impl JsonlWriter {
pub fn create(path: &Path) -> io::Result<Self> {
let f = OpenOptions::new()
.create(true)
.append(true)
.open(path)?;
Ok(Self {
inner: BufWriter::new(f),
})
}
}
impl FindingWriter for JsonlWriter {
fn write(&mut self, f: &Finding) -> io::Result<()> {
let line = serde_json::to_string(f).map_err(io::Error::other)?;
self.inner.write_all(line.as_bytes())?;
self.inner.write_all(b"\n")?;
Ok(())
}
fn finalize(&mut self) -> io::Result<()> {
self.inner.flush()
}
}
/// TOON: buffer all findings; emit a single `findings[N]{...}:` block on finalize.
pub struct ToonWriter {
path: std::path::PathBuf,
buffer: Vec<Finding>,
}
impl ToonWriter {
pub fn create(path: &Path) -> io::Result<Self> {
// Truncate (or create) target file early so a partial run leaves a valid empty file.
let _ = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)?;
Ok(Self {
path: path.to_path_buf(),
buffer: Vec::new(),
})
}
}
impl FindingWriter for ToonWriter {
fn write(&mut self, f: &Finding) -> io::Result<()> {
self.buffer.push(f.clone());
Ok(())
}
fn finalize(&mut self) -> io::Result<()> {
let f = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&self.path)?;
let mut w = BufWriter::new(f);
toon::write_findings(&mut w, &self.buffer)?;
w.flush()
}
}
/// JSON: buffer all findings; emit a single JSON array.
pub struct JsonWriter {
path: std::path::PathBuf,
buffer: Vec<Finding>,
}
impl JsonWriter {
pub fn create(path: &Path) -> io::Result<Self> {
let _ = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path)?;
Ok(Self {
path: path.to_path_buf(),
buffer: Vec::new(),
})
}
}
impl FindingWriter for JsonWriter {
fn write(&mut self, f: &Finding) -> io::Result<()> {
self.buffer.push(f.clone());
Ok(())
}
fn finalize(&mut self) -> io::Result<()> {
let f = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&self.path)?;
let mut w = BufWriter::new(f);
serde_json::to_writer_pretty(&mut w, &self.buffer).map_err(io::Error::other)?;
w.write_all(b"\n")?;
w.flush()
}
}
/// Build the appropriate writer based on `--format`. Filename extension is set accordingly.
pub fn open_findings_writer(out_dir: &Path, format: Format) -> io::Result<Box<dyn FindingWriter>> {
std::fs::create_dir_all(out_dir)?;
let (filename, writer): (&str, Box<dyn FindingWriter>) = match format {
Format::Jsonl => ("findings.jsonl", Box::new(JsonlWriter::create(&out_dir.join("findings.jsonl"))?)),
Format::Toon => ("findings.toon", Box::new(ToonWriter::create(&out_dir.join("findings.toon"))?)),
Format::Json => ("findings.json", Box::new(JsonWriter::create(&out_dir.join("findings.json"))?)),
};
let _ = filename; // referenced for log-side identification if needed
Ok(writer)
}
/// Log a finding to stderr at the appropriate level given its severity.
pub fn log_finding(f: &Finding, quiet: bool) {
if quiet {
return;
}
let sev = f.severity.as_str().to_uppercase();
let prefix = match f.severity {
crate::finding::Severity::Critical | crate::finding::Severity::High => "[ERR]",
crate::finding::Severity::Medium | crate::finding::Severity::Low => "[WARN]",
crate::finding::Severity::Info => "[INFO]",
};
eprintln!("{prefix} [{}] {} — {}", f.id, sev, f.target);
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |