YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(pi): normalize bundled compaction patch line endings (#7178)
Ezra Ellette5048253876d1
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 72a3c4b2a..84506b6c1 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -15,6 +15,7 @@ on:- '**.rs'# Core embeds these assets with include_str! and tests their contracts.- 'crates/screenpipe-core/assets/**'+ - 'apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts'- '**/Cargo.toml'- '**/Cargo.lock'- '.github/workflows/ci.yml'@@ -23,6 +24,7 @@ on:paths:- '**.rs'- 'crates/screenpipe-core/assets/**'+ - 'apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts'- '**/Cargo.toml'- '**/Cargo.lock'- '.github/workflows/ci.yml'@@ -107,6 +109,9 @@ jobs:- name: Install dependenciesrun: .github/scripts/install_dependencies.sh+ - name: Pi context compaction runtime eval (production Rust patcher)+ run: bun apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts+- name: Copy test imagerun: |mkdir -p target/debug/deps@@ -182,6 +187,9 @@ jobs:- name: Set up MSVCuses: ilammy/msvc-dev-cmd@v1+ - name: Pi context compaction runtime eval (production Rust patcher)+ run: bun apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts+- name: Ensure 7-Zip is availableshell: pwshrun: |diff --git a/.github/workflows/test-frontend.yml b/.github/workflows/test-frontend.ymlindex 1cf454125..765aa5d3f 100644--- a/.github/workflows/test-frontend.yml+++ b/.github/workflows/test-frontend.yml@@ -80,9 +80,6 @@ jobs:# must pass for CI green.run: bun run test:bun- - name: Pi context compaction runtime eval- run: bun scripts/eval-pi-compaction.ts-- name: Pi extension startup runtime evalrun: bun scripts/eval-pi-extensions.tsdiff --git a/apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts b/apps/screenpipe-app-tauri/scripts/eval-pi-compaction.tsindex 81ba72695..b8471b4c4 100644--- a/apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts+++ b/apps/screenpipe-app-tauri/scripts/eval-pi-compaction.ts@@ -20,8 +20,17 @@ try {} }));await run([process.execPath, "install", "--ignore-scripts"]);if (!process.argv.includes("--baseline")) {- await run(["git", "apply", join(repo, "crates/screenpipe-core/assets/pi-context-compaction.patch")],- join(root, "node_modules/@earendil-works/pi-coding-agent"));+ // Exercise the same parser and atomic write as app/automation startup.+ // git apply accepts patch formats that the production diffy parser rejects.+ const patcher = ["cargo", "run", "--locked", "-p", "screenpipe-core",+ "--example", "patch_pi_compaction", "--", root];+ await run(patcher, repo);+ const runtime = join(root, "node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js");+ const patched = await readFile(runtime, "utf8");+ await run(patcher, repo);+ if (await readFile(runtime, "utf8") !== patched) {+ throw new Error("Pi compaction patch changed an already-patched runtime");+ }}await run([process.execPath, "test", join(repo, "crates/screenpipe-core/assets/pi-context-compaction.test.ts")], root,{ ...process.env, SCREENPIPE_TEST_PI_DIR: root });diff --git a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rsindex 7009a4951..0468d5279 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/diagnostic_logs.rs@@ -243,6 +243,45 @@ mod tests {}use tempfile::tempdir;+ #[tokio::test]+ async fn pi_compaction_failure_survives_rotation_and_support_redaction() {+ let install = tempdir().unwrap();+ let runtime = install+ .path()+ .join("node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js");+ std::fs::create_dir_all(runtime.parent().unwrap()).unwrap();+ std::fs::write(&runtime, "unrecognized runtime").unwrap();+ let error = screenpipe_core::agents::pi_compaction::ensure(install.path()).unwrap_err();++ let logs = tempdir().unwrap();+ let current = logs.path().join("screenpipe-app.2026-09-21.log");+ // Both Pi startup and pipe execution report errors with Display.+ std::fs::write(+ ¤t,+ format!("ERROR pipe 'meeting-summary' error: {error}\nWARN Failed to prepare Pi compaction: {error}\n"),+ )+ .unwrap();+ std::fs::rename(+ ¤t,+ logs.path().join("screenpipe-app.2026-09-21.1.log"),+ )+ .unwrap();+ std::fs::write(+ ¤t,+ "recorder restarted\[email protected]\n",+ )+ .unwrap();++ let report = collect_redacted_from_dirs(&[logs.path().to_path_buf()])+ .await+ .unwrap();+ assert!(report.contains("pipe 'meeting-summary' error:"));+ assert!(report.contains("Failed to prepare Pi compaction:"));+ assert!(report.contains(&error.to_string()));+ assert!(report.contains("Pi runtime does not match the pinned compaction patch:"));+ assert!(!report.contains("[email protected]"));+ }+fn log_file(path: &Path, modified_at: u64) -> LogFile {LogFile {name: path.file_name().unwrap().to_string_lossy().to_string(),diff --git a/crates/screenpipe-core/examples/patch_pi_compaction.rs b/crates/screenpipe-core/examples/patch_pi_compaction.rsnew file mode 100644index 000000000..c15ea4deb--- /dev/null+++ b/crates/screenpipe-core/examples/patch_pi_compaction.rs@@ -0,0 +1,11 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com++//! Apply the production patcher to the runtime eval's disposable Pi install.++fn main() -> anyhow::Result<()> {+ let install_dir = std::env::args_os()+ .nth(1)+ .ok_or_else(|| anyhow::anyhow!("expected a disposable Pi install directory"))?;+ screenpipe_core::agents::pi_compaction::ensure(std::path::Path::new(&install_dir))+}diff --git a/crates/screenpipe-core/src/agents/pi_compaction.rs b/crates/screenpipe-core/src/agents/pi_compaction.rsindex ed4daba64..27c5efad9 100644--- a/crates/screenpipe-core/src/agents/pi_compaction.rs+++ b/crates/screenpipe-core/src/agents/pi_compaction.rs@@ -21,11 +21,15 @@ pub fn ensure_for_entrypoint(entrypoint: &Path) -> Result<()> {Ok(())}-fn patched_source(source: &str) -> Result<Option<String>> {+fn patched_source(source: &str, patch: &str) -> Result<Option<String>> {if source.contains(MARKER) {return Ok(None);}- let patch = diffy::Patch::from_str(PATCH).context("invalid bundled Pi compaction patch")?;+ // Windows checkouts can embed CRLF in this asset. diffy requires LF in+ // patch headers, and the package-manager-installed JS runtime also uses LF.+ let patch = patch.replace("\r\n", "\n");+ let patch = diffy::Patch::from_str(&patch)+ .map_err(|error| anyhow!("invalid bundled Pi compaction patch: {error}"))?;diffy::apply(source, &patch).map(Some).map_err(|error| anyhow!("Pi runtime does not match the pinned compaction patch: {error}"))@@ -39,7 +43,7 @@ pub fn ensure(install_dir: &Path) -> Result<()> {let runtime =install_dir.join("node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js");let source = std::fs::read_to_string(&runtime).context("cannot read managed Pi runtime")?;- let Some(patched) = patched_source(&source)? else {+ let Some(patched) = patched_source(&source, PATCH)? else {return Ok(());};let mut output = tempfile::NamedTempFile::new_in(runtime.parent().unwrap())?;@@ -57,7 +61,44 @@ mod tests {#[test]fn already_patched_runtime_is_unchanged() {- assert!(patched_source(MARKER).unwrap().is_none());+ assert!(patched_source(MARKER, PATCH).unwrap().is_none());+ }++ #[test]+ fn bundled_patch_parses_with_lf_and_crlf() {+ let lf = PATCH.replace("\r\n", "\n");+ for patch in [&lf, &lf.replace('\n', "\r\n")] {+ // An unknown runtime must fail application, not parsing. Windows+ // checkouts can give include_str! a CRLF copy of the real asset.+ let error = patched_source("unrecognized runtime", patch).unwrap_err();+ assert!(+ error+ .to_string()+ .starts_with("Pi runtime does not match the pinned compaction patch:"),+ "{error:#}"+ );+ }+ }++ #[test]+ fn crlf_patch_applies_to_lf_runtime_and_remains_idempotent() {+ let source = "const original = true;\n";+ let expected = format!("{MARKER}const original = false;\n");+ let patch = diffy::create_patch(source, &expected)+ .to_string()+ .replace('\n', "\r\n");+ let patched = patched_source(source, &patch).unwrap().unwrap();+ assert_eq!(patched, expected);+ assert!(patched_source(&patched, &patch).unwrap().is_none());+ }++ #[test]+ fn invalid_patch_preserves_parser_cause_in_display() {+ let error = patched_source("unrecognized runtime", "--- unterminated").unwrap_err();+ assert_eq!(+ error.to_string(),+ "invalid bundled Pi compaction patch: error parsing patch: filename unterminated"+ );}#[test]@@ -68,7 +109,10 @@ mod tests {.join("node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js");std::fs::create_dir_all(runtime.parent().unwrap()).unwrap();std::fs::write(&runtime, "unrecognized runtime").unwrap();- assert!(ensure(dir.path()).is_err());+ let error = ensure(dir.path()).unwrap_err();+ assert!(error+ .to_string()+ .starts_with("Pi runtime does not match the pinned compaction patch:"));assert_eq!(std::fs::read_to_string(runtime).unwrap(),"unrecognized runtime"