Skip to content

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

work on pipes

Louis Beaumontd7028b2b3e5b
diff --git a/examples/typescript/pipe-stream-ocr-text/pipe.js b/examples/typescript/pipe-stream-ocr-text/pipe.js
index 43764b46b..109cd348e 100644
--- a/examples/typescript/pipe-stream-ocr-text/pipe.js
+++ b/examples/typescript/pipe-stream-ocr-text/pipe.js
@@ -1,5 +1,4 @@
-import * as fs from "fs";
-import * as path from "path";
+"use strict";
let INTERVAL = 10 * 1000; // 10 seconds in milliseconds
async function queryScreenpipe() {
try {
@@ -23,7 +22,9 @@ async function writeToMarkdown(data) {
const content = data
.map((item) => `## ${item.content.timestamp}\n\n${item.content.text}\n\n---\n`)
.join("\n");
- fs.writeFileSync(path.join(process.env.PIPE_DIR, fileName), content);
+ const dir = path.join(process.env.PIPE_DIR, fileName);
+ console.log("Writing to", dir);
+ fs.writeFileSync(dir, content);
console.log(`Written OCR data to ${fileName}`);
}
async function runOCRTracker() {
diff --git a/examples/typescript/pipe-stream-ocr-text/pipe.ts b/examples/typescript/pipe-stream-ocr-text/pipe.ts
index 1d3d92d74..fdc9fbccd 100644
--- a/examples/typescript/pipe-stream-ocr-text/pipe.ts
+++ b/examples/typescript/pipe-stream-ocr-text/pipe.ts
@@ -1,6 +1,3 @@
-import * as fs from "fs";
-import * as path from "path";
-
let INTERVAL = 10 * 1000; // 10 seconds in milliseconds
async function queryScreenpipe() {
@@ -33,7 +30,9 @@ async function writeToMarkdown(data: any) {
)
.join("\n");
- fs.writeFileSync(path.join(__dirname, fileName), content);
+ const dir = path.join(process.env.PIPE_DIR, fileName);
+ console.log("Writing to", dir);
+ fs.writeFileSync(dir, content);
console.log(`Written OCR data to ${fileName}`);
}
diff --git a/examples/typescript/pipe-stream-ocr-text/screenpipe.d.ts b/examples/typescript/pipe-stream-ocr-text/screenpipe.d.ts
index bf0d8c312..fe1bb5343 100644
--- a/examples/typescript/pipe-stream-ocr-text/screenpipe.d.ts
+++ b/examples/typescript/pipe-stream-ocr-text/screenpipe.d.ts
@@ -17,6 +17,15 @@ declare global {
};
};
+ const fs: {
+ readFileSync: (path: string) => string;
+ writeFileSync: (path: string, contents: string) => void;
+ };
+
+ const path: {
+ join: (...paths: string[]) => string;
+ };
+
namespace NodeJS {
interface ProcessEnv {
SCREENPIPE_DIR: string;
diff --git a/screenpipe-core/src/deno/runtime.js b/screenpipe-core/src/deno/runtime.js
index 2b9e43f52..1fde05b41 100644
--- a/screenpipe-core/src/deno/runtime.js
+++ b/screenpipe-core/src/deno/runtime.js
@@ -147,6 +147,37 @@ const pipe = {
// }
};
+const fs = { // TODO does not work?
+ readFileSync: (path) => {
+ // This is a synchronous wrapper around the async operation
+ // Note: This will block the event loop and should be used carefully
+ return new Promise((resolve, reject) => {
+ ops.op_read_file(path)
+ .then(resolve)
+ .catch(reject);
+ });
+ },
+ writeFileSync: (path, contents) => {
+ // Similarly, this is a synchronous wrapper
+ return new Promise((resolve, reject) => {
+ ops.op_write_file(path, contents)
+ .then(resolve)
+ .catch(reject);
+ });
+ }
+};
+
+const path = {
+ join: (...paths) => {
+ const sep = process.env.OS === "windows" ? "\\" : "/";
+ // This implementation works on both Unix and Windows
+ return paths.join(sep).replace(new RegExp(`\\${sep}+`, 'g'), sep);
+ },
+};
+
+globalThis.fs = fs;
+globalThis.path = path;
+
globalThis.setTimeout = (callback, delay) => {
ops.op_set_timeout(delay).then(callback);
};
diff --git a/screenpipe-core/src/pipes.rs b/screenpipe-core/src/pipes.rs
index 827dcbf04..3b12439a2 100644
--- a/screenpipe-core/src/pipes.rs
+++ b/screenpipe-core/src/pipes.rs
@@ -324,6 +324,7 @@ mod pipes {
globalThis.process.env.PIPE_ID = "{}";
globalThis.process.env.PIPE_FILE = "{}";
globalThis.process.env.PIPE_DIR = "{}";
+ globalThis.process.env.OS = "{}";
"#,
screenpipe_dir
.to_string_lossy()
@@ -349,6 +350,11 @@ mod pipes {
.to_string_lossy()
.replace('\\', "\\\\")
.replace('\"', "\\\""),
+ if cfg!(target_os = "windows") {
+ "windows"
+ } else {
+ "unix"
+ }
),
)?;
@@ -376,7 +382,6 @@ mod pipes {
}
}
- #[allow(clippy::manual_async_fn)]
pub async fn run_pipe(pipe: String, screenpipe_dir: PathBuf) -> anyhow::Result<()> {
debug!(
"Running pipe: {}, screenpipe_dir: {}",
@@ -406,6 +411,8 @@ mod pipes {
let main_module = find_pipe_file(&pipe_dir)?;
+ info!("Executing pipe: {:?}", main_module);
+
match run_js(&pipe, &main_module.to_string_lossy(), screenpipe_dir).await {
Ok(_) => info!("JS execution completed successfully"),
Err(error) => {
@@ -557,7 +564,7 @@ mod pipes {
let entry = entry?;
let file_name = entry.file_name();
let file_name_str = file_name.to_str().unwrap();
- if file_name_str.contains("pipe.js") {
+ if file_name_str == "pipe.js" {
return Ok(entry.path());
}
}