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

hourly email

Louis Beaumont77f051f0fe9a
diff --git a/examples/typescript/pipe-email-daily-log/pipe.json b/examples/typescript/pipe-email-daily-log/pipe.json
index 6318b38fa..47fe15071 100644
--- a/examples/typescript/pipe-email-daily-log/pipe.json
+++ b/examples/typescript/pipe-email-daily-log/pipe.json
@@ -6,11 +6,17 @@
"default": 60,
"description": "Interval in seconds to read your screen data"
},
+ {
+ "name": "summaryFrequency",
+ "type": "string",
+ "default": "daily",
+ "description": "Frequency of summary emails: 'daily' for once a day at emailTime, or 'hourly:X' for every X hours (e.g., 'hourly:4' for every 4 hours)"
+ },
{
"name": "emailTime",
"type": "time",
"default": "11:00",
- "description": "Time to send daily summary email"
+ "description": "Time to send daily summary email (used only if summaryFrequency is 'daily')"
},
{
"name": "emailAddress",
diff --git a/examples/typescript/pipe-email-daily-log/pipe.ts b/examples/typescript/pipe-email-daily-log/pipe.ts
index ed130d3a0..14f5f3d68 100644
--- a/examples/typescript/pipe-email-daily-log/pipe.ts
+++ b/examples/typescript/pipe-email-daily-log/pipe.ts
@@ -135,11 +135,18 @@ async function generateDailySummary(
ollamaModel: string,
ollamaApiUrl: string
): Promise<string> {
+ // if logs is more than 30000 characters, truncate it
+ let truncatedLogs = logs;
+ if (logs.length > 30000) {
+ // HACK!
+ truncatedLogs = logs.slice(0, 30000);
+ }
+
const prompt = `${customPrompt}
Based on the following daily logs, generate a concise summary of the day's activities:
- ${JSON.stringify(logs)}
+ ${JSON.stringify(truncatedLogs)}
Provide a human-readable summary that highlights key activities and insights.`;
@@ -207,6 +214,22 @@ async function sendEmail(
});
}
+async function getTodayLogs(): Promise<DailyLog[]> {
+ const logsDir = `${process.env.PIPE_DIR}/logs`;
+ const today = new Date().toISOString().split("T")[0]; // Get today's date in YYYY-MM-DD format
+
+ const files = fs.readdirSync(logsDir);
+ const todayFiles = files.filter((file) => file.startsWith(today));
+
+ const logs: DailyLog[] = [];
+ for (const file of todayFiles) {
+ const content = fs.readFileSync(`${logsDir}/${file}`);
+ logs.push(JSON.parse(content));
+ }
+
+ return logs;
+}
+
async function dailyLogPipeline(): Promise<void> {
console.log("starting daily log pipeline");
@@ -214,6 +237,7 @@ async function dailyLogPipeline(): Promise<void> {
console.log("loaded config:", JSON.stringify(config, null, 2));
const interval = config.interval * 1000;
+ const summaryFrequency = config.summaryFrequency;
const emailTime = config.emailTime;
const emailAddress = config.emailAddress;
const emailPassword = config.emailPassword;
@@ -225,7 +249,6 @@ async function dailyLogPipeline(): Promise<void> {
const pageSize = config.pageSize;
let lastEmailSent = new Date(0); // Initialize to a past date
- let logEntries: DailyLog[] = []; // Store log entries in memory
// send a welcome email to announce what will happen, when it will happen, and what it will do
const welcomeEmail = `
@@ -263,55 +286,51 @@ async function dailyLogPipeline(): Promise<void> {
);
console.log("log entry:", logEntry);
await saveDailyLog(logEntry);
- logEntries.push(logEntry); // Store the log entry in memory
}
- const [emailHour, emailMinute] = emailTime.split(":").map(Number);
- const emailTimeToday = new Date(
- now.getFullYear(),
- now.getMonth(),
- now.getDate(),
- emailHour,
- emailMinute
- );
+ let shouldSendSummary = false;
- if (
- now >= emailTimeToday &&
- now.getTime() - lastEmailSent.getTime() > 24 * 60 * 60 * 1000
- ) {
- const todayStart = new Date(
+ if (summaryFrequency === "daily") {
+ const [emailHour, emailMinute] = emailTime.split(":").map(Number);
+ const emailTimeToday = new Date(
now.getFullYear(),
now.getMonth(),
- now.getDate()
+ now.getDate(),
+ emailHour,
+ emailMinute
);
+ shouldSendSummary =
+ now >= emailTimeToday &&
+ now.getTime() - lastEmailSent.getTime() > 24 * 60 * 60 * 1000;
+ } else if (summaryFrequency.startsWith("hourly:")) {
+ const hours = parseInt(summaryFrequency.split(":")[1], 10);
+ shouldSendSummary =
+ now.getTime() - lastEmailSent.getTime() >= hours * 60 * 60 * 1000;
+ }
- // Filter log entries for today
- // const todayLogs = logEntries.filter(
- // (log) => new Date(log.timestamp) >= todayStart
- // );
-
- // console.log("today's logs:", todayLogs);
-
- // if (todayLogs.length > 0) {
+ if (shouldSendSummary) {
await retry(async () => {
- const summary = await generateDailySummary(
- logEntries,
- summaryPrompt,
- ollamaModel,
- ollamaApiUrl
- );
- console.log("summary:", summary);
- await sendEmail(
- emailAddress,
- emailPassword,
- "daily activity summary",
- summary
- );
+ const todayLogs = await getTodayLogs();
+ console.log("today's logs:", todayLogs);
+
+ if (todayLogs.length > 0) {
+ const summary = await generateDailySummary(
+ todayLogs,
+ summaryPrompt,
+ ollamaModel,
+ ollamaApiUrl
+ );
+ console.log("summary:", summary);
+ await sendEmail(
+ emailAddress,
+ emailPassword,
+ "activity summary",
+ summary
+ );
+ }
});
lastEmailSent = now;
- logEntries = [];
- // }
}
} catch (error) {
console.error("error in daily log pipeline:", error);
diff --git a/screenpipe-app-tauri/components/pipe-store.tsx b/screenpipe-app-tauri/components/pipe-store.tsx
index 8b5eb12ed..8c57d9186 100644
--- a/screenpipe-app-tauri/components/pipe-store.tsx
+++ b/screenpipe-app-tauri/components/pipe-store.tsx
@@ -69,14 +69,15 @@ const corePipes: CorePipe[] = [
{
id: "pipe-phi3.5-engineering-team-logs",
description:
- "continuously write logs of your days in a notion table using ollama+phi3.5",
+ "continuously write logs of your days in a notion table using ollama+llama3.2",
url: "https://github.com/mediar-ai/screenpipe/tree/main/examples/typescript/pipe-phi3.5-engineering-team-logs",
},
- // {
- // id: "transcriber",
- // description: "generate accurate transcriptions",
- // url: "https://github.com/screenpipe/transcriber-pipe",
- // },
+ {
+ id: "pipe-email-daily-log",
+ description:
+ "send a daily log of your screen time to your email using ollama+llama3.2",
+ url: "https://github.com/mediar-ai/screenpipe/tree/main/examples/typescript/pipe-email-daily-log",
+ },
];
const PipeDialog: React.FC = () => {
diff --git a/screenpipe-app-tauri/src-tauri/Cargo.toml b/screenpipe-app-tauri/src-tauri/Cargo.toml
index 0d84f52ec..fbc0c2302 100644
--- a/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
-version = "0.2.66"
+version = "0.2.67"
description = ""
authors = ["you"]
license = ""