Lines 1-70javascript
1import fs from "node:fs";
2import os from "node:os";
3import path from "node:path";
4import { spawnSync } from "node:child_process";
5import { fileURLToPath } from "node:url";
HighChild Process
Package source references child process execution.
install/burnboard-agent.mjsView on unpkg · L3 7try { if (!process.env.BURNBOARD_FORCE_SQLITE_FALLBACK) ({ DatabaseSync } = await import("node:sqlite")); } catch {}
8
MediumDynamic Require
Package source references dynamic require/import behavior.
install/burnboard-agent.mjsView on unpkg · L6 10async function openSqlite(file) {
12 const database = new DatabaseSync(file, { readOnly: true });
13 return { all: (sql) => database.prepare(sql).all(), close: () => database.close() };
15 BetterSqlite3 ||= (await import(new URL("./sqlite/lib/index.js", import.meta.url))).default;
16 const nativeBinding = path.join(path.dirname(fileURLToPath(import.meta.url)), "sqlite", "better_sqlite3.node");
17 const database = new BetterSqlite3(file, { readonly: true, fileMustExist: true, nativeBinding });
18 return { all: (sql) => database.prepare(sql).all(), close: () => database.close() };
21const home = os.homedir();
22const root = path.join(home, ".burnboard");
23const dryRun = process.argv.includes("--dry-run");
24const jsonOutput = process.argv.includes("--json");
25const onlyTool = process.argv.find((argument) => argument.startsWith("--only="))?.slice(7);
26const config = dryRun ? null : JSON.parse(fs.readFileSync(path.join(root, "config.json"), "utf8").replace(/^\uFEFF/, ""));
30 title = String(title || "BurnBoard").slice(0, 100);
31 message = String(message || "").slice(0, 200);
35 const candidate = new URL(destination);
36 if (candidate.protocol === "https:" || (candidate.protocol === "http:" && ["localhost","127.0.0.1"].includes(candidate.hostname))) notificationUrl = candidate.origin;
38 if (!notificationUrl) return;
39 if (process.platform === "win32") {
41[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
42[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] > $null
43$title = [Security.SecurityElement]::Escape($env:BURNBOARD_NOTIFICATION_TITLE)
44$message = [Security.SecurityElement]::Escape($env:BURNBOARD_NOTIFICATION_MESSAGE)
45$url = [Security.SecurityElement]::Escape($env:BURNBOARD_NOTIFICATION_URL)
46$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
47$xml.LoadXml("<toast activationType='protocol' launch='$url'><visual><binding template='ToastGeneric'><text>$title</text><text>$message</text></binding></visual></toast>")
48$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
49[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('BurnBoard.Desktop').Show($toast)
51 spawnSync("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-EncodedCommand", Buffer.from(script, "utf16le").toString("base64")], {
52 stdio:"ignore", env:{ ...process.env, BURNBOARD_NOTIFICATION_TITLE:title, BURNBOARD_NOTIFICATION_MESSAGE:message, BURNBOARD_NOTIFICATION_URL:notificationUrl },
54 } else if (process.platform === "darwin") {
55 spawnSync("osascript", ["-e", "display notification (system attribute \"BURNBOARD_NOTIFICATION_MESSAGE\") with title (system attribute \"BURNBOARD_NOTIFICATION_TITLE\")"], {
56 stdio:"ignore", env:{ ...process.env, BURNBOARD_NOTIFICATION_TITLE:title, BURNBOARD_NOTIFICATION_MESSAGE:message },
59 spawnSync("notify-send", [title, message], { stdio:"ignore" });
63function localDate(value) {
64 const parts = new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Kolkata", year: "numeric", month: "2-digit", day: "2-digit" }).formatToParts(new Date(value));
65 const get = (type) => parts.find((part) => part.type === type)?.value;
66 return `${get("year")}-${get("month")}-${get("day")}`;
69function addUsage({ recordedAt, tool, model, input = 0, output = 0, cacheRead = 0, cacheCreation = 0 }) {
70 const values = [input, output, cacheRead, cacheCreation].map(Number);