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

example: daily log

Louis Beaumontf2769edad9c2
diff --git a/examples/ts/daily-log/.gitignore b/examples/ts/daily-log/.gitignore
new file mode 100644
index 000000000..b512c09d4
--- /dev/null
+++ b/examples/ts/daily-log/.gitignore
@@ -0,0 +1 @@
+node_modules
\ No newline at end of file
diff --git a/examples/ts/daily-log/main.ts b/examples/ts/daily-log/main.ts
new file mode 100644
index 000000000..e3515046c
--- /dev/null
+++ b/examples/ts/daily-log/main.ts
@@ -0,0 +1,172 @@
+// npx ts-node dailyLogger.ts
+
+import fetch from "node-fetch";
+import fs from "fs/promises";
+import path from "path";
+
+const OPENAI_API_URL = "https://api.openai.com/v1/chat/completions";
+const OPENAI_MODEL = "gpt-4o";
+// Uncomment the following lines to use Ollama instead
+// const OPENAI_API_URL = "http://localhost:11434/api/chat";
+// const OPENAI_MODEL = "llama3.1";
+
+const SCREENPIPE_API_URL = "http://localhost:3030/search";
+const LOG_INTERVAL = 1 * 60 * 1000; // 5 minutes in milliseconds
+
+interface ActivityLog {
+ startTime: string;
+ endTime: string;
+ content: string;
+}
+
+async function getOpenAIKey(): Promise<string> {
+ const secretsPath = path.join(process.env.HOME || "", "secrets.json");
+ try {
+ const secrets = JSON.parse(await fs.readFile(secretsPath, "utf-8"));
+ return secrets.OPENAI_API_KEY;
+ } catch (error) {
+ return process.env.OPENAI_API_KEY!;
+ }
+}
+
+async function queryScreenpipe(
+ startTime: string,
+ endTime: string
+): Promise<string> {
+ const url = `${SCREENPIPE_API_URL}?start_time=${startTime}&end_time=${endTime}&limit=100&content_type=ocr`;
+ console.log("Querying Screenpipe:", url);
+ const response = await fetch(url);
+ const data = await response.json();
+ return JSON.stringify(data);
+}
+
+async function generateLogEntry(
+ prompt: string,
+ data: string
+): Promise<ActivityLog> {
+ const openAIKey = await getOpenAIKey();
+ console.log("Generating log entry...");
+ const response = await fetch(OPENAI_API_URL, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${openAIKey}`,
+ },
+ body: JSON.stringify({
+ model: OPENAI_MODEL,
+ stream: false,
+ messages: [
+ {
+ role: "system",
+ content: `You are an AI assistant that creates concise and informative log entries based on a person's daily activities. Focus on the aspects the user wants to track.
+
+ Rules:
+ - YOUR LOGS ARE BASED ON THE DATA YOU RECEIVE WHICH IS THE SCREEN TEXT & AUDIO TRANSCRIPTIONS FROM THE USER COMPUTER
+ - Do not use '"' around your response
+ - Date & time now is ${new Date().toISOString()}
+ - Use short title with max 4 words
+ - Be concise in the content, if you can use bullet list with times if necessary
+ - YOUR MESSAGES ARE LESS THAN 4 LINES LONG
+
+ Example of your answer:
+
+ ### 073024 - 9.05 AM - 9.10 AM - Emails & LinkedIn
+ - 3 min: Scrolled emails
+ - 2 min: Opened LinkedIn and scrolled posts
+ `,
+ },
+ {
+ role: "user",
+ content: `Based on the following data and keeping in mind the user wants to track ${prompt}, create a short log entry with a title and content. Data: ${data}
+
+
+ AGAIN you are returning ONLY daily log of what the user do, plus tailored to his prompt. Example of your answer:
+
+
+ ### 073024 - 9.05 AM - 9.10 AM - Emails & LinkedIn
+ - 3 min: Scrolled emails
+ - 2 min: Opened LinkedIn and scrolled posts
+
+
+ Rules:
+ - YOUR LOGS ARE BASED ON THE DATA YOU RECEIVE WHICH IS THE SCREEN TEXT & AUDIO TRANSCRIPTIONS FROM THE USER COMPUTER
+ - Do not use '"' around your response
+ - Date & time now is ${new Date().toISOString()}
+ - Use short title with max 4 words
+ - Be concise in the content, if you can use bullet list with times if necessary
+ - YOUR MESSAGES ARE LESS THAN 4 LINES LONG
+
+ Log?`,
+ },
+ ],
+ }),
+ });
+
+ const result: any = await response.json();
+ // if error console log and throw
+ if (result.error) {
+ console.error("Error generating log entry:", result.error);
+ throw new Error(result);
+ }
+ // phi3 models are drunk af thats why
+ const log =
+ result.choices?.[0]?.message?.content ||
+ // ollama not respecting openai api
+ result.message?.content;
+
+ console.log("Log entry generated:", log);
+
+ return {
+ startTime: new Date(Date.now() - LOG_INTERVAL).toISOString(),
+ endTime: new Date().toISOString(),
+ content: log,
+ };
+}
+
+async function appendToLogFile(log: ActivityLog): Promise<void> {
+ const date = new Date().toISOString().split("T")[0];
+ const fileName = `daily_log_${date}.md`;
+ const logEntry = log.content;
+
+ await fs.appendFile(fileName, logEntry);
+}
+
+async function startLogging(trackingPrompt: string): Promise<void> {
+ console.log(`Starting to log activities. Tracking: ${trackingPrompt}`);
+
+ setInterval(async () => {
+ const endTime = new Date().toISOString();
+ const startTime = new Date(Date.now() - LOG_INTERVAL).toISOString();
+
+ try {
+ const screenpipeData = await queryScreenpipe(startTime, endTime);
+ const logEntry = await generateLogEntry(trackingPrompt, screenpipeData);
+ await appendToLogFile(logEntry);
+ console.log(`Log entry added: ${logEntry}`);
+ } catch (error) {
+ console.error("Error generating log entry:", error);
+ }
+ }, LOG_INTERVAL);
+}
+
+// Main execution
+(async () => {
+ const trackingPrompt = await new Promise<string>((resolve) => {
+ const readline = require("readline").createInterface({
+ input: process.stdin,
+ output: process.stdout,
+ });
+
+ readline.question(
+ "What aspects of your day do you want to track? ",
+ (answer: string) => {
+ readline.close();
+ resolve(answer);
+ }
+ );
+ });
+
+ await startLogging(trackingPrompt);
+})();
+
+// npx tsx main.ts
diff --git a/examples/ts/daily-log/package.json b/examples/ts/daily-log/package.json
new file mode 100644
index 000000000..e353d1845
--- /dev/null
+++ b/examples/ts/daily-log/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "daily-log",
+ "version": "1.0.0",
+ "description": "",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "keywords": [],
+ "author": "",
+ "license": "ISC",
+ "dependencies": {
+ "@types/node": "^22.0.0",
+ "@types/node-fetch": "^2.6.11",
+ "node-fetch": "^3.3.2",
+ "ts-node": "^10.9.2",
+ "typescript": "^5.5.4"
+ }
+}
diff --git a/examples/ts/daily-log/pnpm-lock.yaml b/examples/ts/daily-log/pnpm-lock.yaml
new file mode 100644
index 000000000..16536b004
--- /dev/null
+++ b/examples/ts/daily-log/pnpm-lock.yaml
@@ -0,0 +1,232 @@
+lockfileVersion: '6.0'
+
+settings:
+ autoInstallPeers: true
+ excludeLinksFromLockfile: false
+
+dependencies:
+ '@types/node':
+ specifier: ^22.0.0
+ version: 22.0.0
+ '@types/node-fetch':
+ specifier: ^2.6.11
+ version: 2.6.11
+ node-fetch:
+ specifier: ^3.3.2
+ version: 3.3.2
+ ts-node:
+ specifier: ^10.9.2
+ version: 10.9.2(@types/[email protected])([email protected])
+ typescript:
+ specifier: ^5.5.4
+ version: 5.5.4
+
+packages:
+
+ /@cspotcode/[email protected]:
+ resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}
+ engines: {node: '>=12'}
+ dependencies:
+ '@jridgewell/trace-mapping': 0.3.9
+ dev: false
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==}
+ engines: {node: '>=6.0.0'}
+ dev: false
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==}
+ dev: false
+
+ /@jridgewell/[email protected]:
+ resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==}
+ dependencies:
+ '@jridgewell/resolve-uri': 3.1.2
+ '@jridgewell/sourcemap-codec': 1.5.0
+ dev: false
+
+ /@tsconfig/[email protected]:
+ resolution: {integrity: sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==}
+ dev: false
+
+ /@tsconfig/[email protected]:
+ resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==}
+ dev: false
+
+ /@tsconfig/[email protected]:
+ resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==}
+ dev: false
+
+ /@tsconfig/[email protected]:
+ resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==}
+ dev: false
+
+ resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==}
+ dependencies:
+ '@types/node': 22.0.0
+ form-data: 4.0.0
+ dev: false
+
+ resolution: {integrity: sha512-VT7KSYudcPOzP5Q0wfbowyNLaVR8QWUdw+088uFWwfvpY6uCWaXpqV6ieLAu9WBcnTa7H4Z5RLK8I5t2FuOcqw==}
+ dependencies:
+ undici-types: 6.11.1
+ dev: false
+
+ resolution: {integrity: sha512-MxXdReSRhGO7VlFe1bRG/oI7/mdLV9B9JJT0N8vZOhF7gFRR5l3M8W9G8JxmKV+JC5mGqJ0QvqfSOLsCPa4nUw==}
+ engines: {node: '>=0.4.0'}
+ dependencies:
+ acorn: 8.12.1
+ dev: false
+
+ resolution: {integrity: sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==}
+ engines: {node: '>=0.4.0'}
+ hasBin: true
+ dev: false
+
+ resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==}
+ dev: false
+
+ resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
+ dev: false
+
+ resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
+ engines: {node: '>= 0.8'}
+ dependencies:
+ delayed-stream: 1.0.0
+ dev: false
+
+ resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
+ dev: false
+
+ resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
+ engines: {node: '>= 12'}
+ dev: false
+
+ resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
+ engines: {node: '>=0.4.0'}
+ dev: false
+
+ resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==}
+ engines: {node: '>=0.3.1'}
+ dev: false
+
+ resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
+ engines: {node: ^12.20 || >= 14.13}
+ dependencies:
+ node-domexception: 1.0.0
+ web-streams-polyfill: 3.3.3
+ dev: false
+
+ resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
+ engines: {node: '>= 6'}
+ dependencies:
+ asynckit: 0.4.0
+ combined-stream: 1.0.8
+ mime-types: 2.1.35
+ dev: false
+
+ resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
+ engines: {node: '>=12.20.0'}
+ dependencies:
+ fetch-blob: 3.2.0
+ dev: false
+
+ resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==}
+ dev: false
+
+ resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
+ engines: {node: '>= 0.6'}
+ dev: false
+
+ resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
+ engines: {node: '>= 0.6'}
+ dependencies:
+ mime-db: 1.52.0
+ dev: false
+
+ resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
+ engines: {node: '>=10.5.0'}
+ dev: false
+
+ resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
+ engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
+ dependencies:
+ data-uri-to-buffer: 4.0.1
+ fetch-blob: 3.2.0
+ formdata-polyfill: 4.0.10
+ dev: false
+
+ resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==}
+ hasBin: true
+ peerDependencies:
+ '@swc/core': '>=1.2.50'
+ '@swc/wasm': '>=1.2.50'
+ '@types/node': '*'
+ typescript: '>=2.7'
+ peerDependenciesMeta:
+ '@swc/core':
+ optional: true
+ '@swc/wasm':
+ optional: true
+ dependencies:
+ '@cspotcode/source-map-support': 0.8.1
+ '@tsconfig/node10': 1.0.11
+ '@tsconfig/node12': 1.0.11
+ '@tsconfig/node14': 1.0.3
+ '@tsconfig/node16': 1.0.4
+ '@types/node': 22.0.0
+ acorn: 8.12.1
+ acorn-walk: 8.3.3
+ arg: 4.1.3
+ create-require: 1.1.1
+ diff: 4.0.2
+ make-error: 1.3.6
+ typescript: 5.5.4
+ v8-compile-cache-lib: 3.0.1
+ yn: 3.1.1
+ dev: false
+
+ resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==}
+ engines: {node: '>=14.17'}
+ hasBin: true
+ dev: false
+
+ resolution: {integrity: sha512-mIDEX2ek50x0OlRgxryxsenE5XaQD4on5U2inY7RApK3SOJpofyw7uW2AyfMKkhAxXIceo2DeWGVGwyvng1GNQ==}
+ dev: false
+
+ resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
+ dev: false
+
+ resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==}
+ engines: {node: '>= 8'}
+ dev: false
+
+ resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==}
+ engines: {node: '>=6'}
+ dev: false
diff --git a/examples/ts/daily-log/tsconfig.json b/examples/ts/daily-log/tsconfig.json
new file mode 100644
index 000000000..fb885e1cc
--- /dev/null
+++ b/examples/ts/daily-log/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "compilerOptions": {
+ "target": "ES2018",
+ "module": "commonjs",
+ "strict": true,
+ "esModuleInterop": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true
+ }
+ }
\ No newline at end of file