From 1072f4674637dcde77c7a839a8c9578c61fcc73d Mon Sep 17 00:00:00 2001 From: Vitor Blazius Date: Sat, 14 Nov 2026 21:58:31 -0300 Subject: [PATCH] Run model-sync and deriver as systemd --user timers on Linux Both nightly jobs were macOS-only. On Linux InstallModelSync.ts failed at launchctl, and manage-deriver.sh exited 0 with "macOS only. Skipping", so Services reported the deriver as installed when nothing was scheduled. - InstallModelSync.ts: add a Linux branch on lib/SystemdUser (same shape as InstallHealthSync). Schedule matches the plist: daily 05:10. - InstallDeriverSystemd.ts (new): systemd --user timer for the deriver, daily 03:00, same command as the launchd plist. - manage-deriver.sh: delegate install/uninstall/status to the systemd installer on non-Darwin hosts. macOS path unchanged. Co-Authored-By: Claude Haiku 5.5 Claude-Session: https://claude.ai/code/session_01CNVp6Ee6Tan1v5P3HENTHB --- LifeOS/install/LIFEOS/PULSE/manage-deriver.sh | 11 +++-- .../LIFEOS/TOOLS/InstallDeriverSystemd.ts | 40 +++++++++++++++++++ .../install/LIFEOS/TOOLS/InstallModelSync.ts | 30 +++++++++++++- 3 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 LifeOS/install/LIFEOS/TOOLS/InstallDeriverSystemd.ts diff --git a/LifeOS/install/LIFEOS/PULSE/manage-deriver.sh b/LifeOS/install/LIFEOS/PULSE/manage-deriver.sh index 0eb5c23b34..fd426d3bb1 100755 --- a/LifeOS/install/LIFEOS/PULSE/manage-deriver.sh +++ b/LifeOS/install/LIFEOS/PULSE/manage-deriver.sh @@ -31,9 +31,14 @@ fi OS=$(uname -s) -# Linux/systemd analog is intentionally not implemented — the deriver is a -# nice-to-have on Linux and can be wired by hand via systemd timers if -# needed. Pulse menu bar is already macOS-only; same scope. +# Linux: the same nightly job runs as a systemd --user timer via +# LIFEOS/TOOLS/InstallDeriverSystemd.ts (daily 03:00). macOS keeps launchd below. +if [ "$OS" != "Darwin" ]; then + case "${1:-}" in + install|uninstall|status) + exec "$BUN_PATH" "$HOME/.claude/LIFEOS/TOOLS/InstallDeriverSystemd.ts" "$1" ;; + esac +fi case "${1:-}" in install) diff --git a/LifeOS/install/LIFEOS/TOOLS/InstallDeriverSystemd.ts b/LifeOS/install/LIFEOS/TOOLS/InstallDeriverSystemd.ts new file mode 100644 index 0000000000..116c02efec --- /dev/null +++ b/LifeOS/install/LIFEOS/TOOLS/InstallDeriverSystemd.ts @@ -0,0 +1,40 @@ +#!/usr/bin/env bun +/** + * InstallDeriverSystemd.ts — Linux (systemd --user) install for the nightly Pulse deriver. + * + * Same job as com.lifeos.deriver.plist (macOS): daily 03:00, + * bun run LIFEOS/TOOLS/LearningPatternSynthesis.ts --hypothesize + * manage-deriver.sh delegates here on non-Darwin hosts. + * + * bun InstallDeriverSystemd.ts # install (also: install) + * bun InstallDeriverSystemd.ts uninstall # remove + * bun InstallDeriverSystemd.ts status # check + */ + +import { getClaudeDir, lifeosPath } from "./Paths"; +import * as systemd from "./lib/SystemdUser"; + +const LABEL = "com.lifeos.deriver"; +const log = (m: string) => console.log(`[InstallDeriverSystemd] ${m}`); + +async function main(): Promise { + const verb = (process.argv[2] ?? "install").replace(/^--/, ""); + const bunPath = await systemd.which("bun"); + if (!bunPath) throw new Error("bun not found in PATH - install bun first"); + + const spec: systemd.UnitSpec = { + label: LABEL, + description: "LifeOS proactive deriver (nightly hypotheses)", + exec: [bunPath, "run", lifeosPath("TOOLS", "LearningPatternSynthesis.ts"), "--hypothesize"], + logPath: lifeosPath("MEMORY", "OBSERVABILITY", "deriver.log"), + workingDirectory: getClaudeDir(), + schedule: { kind: "calendar", hour: 3, minute: 0 }, + }; + + if (verb === "uninstall") { await systemd.uninstall(spec, log); return; } + if (verb === "status") { if (!(await systemd.status(spec, log))) process.exit(1); return; } + if (verb !== "install") throw new Error(`unknown verb: ${verb}`); + if (!(await systemd.install(spec, log))) process.exit(1); +} + +main().catch((err) => { console.error(`[InstallDeriverSystemd] Fatal: ${err}`); process.exit(1); }); diff --git a/LifeOS/install/LIFEOS/TOOLS/InstallModelSync.ts b/LifeOS/install/LIFEOS/TOOLS/InstallModelSync.ts index 23ac11bbe0..b4149d544b 100644 --- a/LifeOS/install/LIFEOS/TOOLS/InstallModelSync.ts +++ b/LifeOS/install/LIFEOS/TOOLS/InstallModelSync.ts @@ -11,8 +11,9 @@ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join } from "node:path"; -import { lifeosPath } from "./Paths"; // public issue #1974 @sabo961, PR #1918 @PigLardLord +import { getClaudeDir, lifeosPath } from "./Paths"; // public issue #1974 @sabo961, PR #1918 @PigLardLord import { installVerb } from "./lib/InstallVerb"; +import * as systemd from "./lib/SystemdUser"; const HOME = homedir(); const LABEL = "com.lifeos.modelsync"; @@ -28,7 +29,34 @@ async function sh(cmd: string[]): Promise<{ exit: number; out: string }> { const uid = (await sh(["id", "-u"])).out.trim(); const domain = `gui/${uid}`; +/* ── systemd --user backend (Linux only) ──────────────────────────────────── + * Same shape as InstallHealthSync's Linux branch. On darwin nothing here runs. + * Schedule matches the launchd plist: daily 05:10. + * ------------------------------------------------------------------------- */ +async function linuxMain(arg: string | undefined): Promise { + const log = (m: string) => console.log(`[InstallModelSync] ${m}`); + const bunPath = await systemd.which("bun"); + if (!bunPath) throw new Error("bun not found in PATH - install bun first"); + const spec: systemd.UnitSpec = { + label: LABEL, + description: "LifeOS model sync (lineup + prices)", + exec: [bunPath, lifeosPath("TOOLS", "ModelSync.ts"), "--daily"], + logPath: lifeosPath("MEMORY", "OBSERVABILITY", "model-sync-launchd.log"), + workingDirectory: getClaudeDir(), + schedule: { kind: "calendar", hour: 5, minute: 10 }, + }; + if (arg === "--uninstall") { await systemd.uninstall(spec, log); return; } + if (arg === "--status") { if (!(await systemd.status(spec, log))) process.exit(1); return; } + if (!(await systemd.install(spec, log))) process.exit(1); + const first = await sh([bunPath, lifeosPath("TOOLS", "ModelSync.ts"), "--sync"]); + console.log(first.exit === 0 ? "First sync: done" : `First sync skipped (${first.out.trim().split("\n").pop()}) — the daily job will retry`); +} + installVerb(process.argv, "InstallModelSync"); +if (systemd.isLinux()) { + await linuxMain(process.argv.find((a) => a.startsWith("--"))); + process.exit(0); +} if (process.argv.includes("--status")) { const listed = await sh(["launchctl", "print", `${domain}/${LABEL}`]); console.log(existsSync(TARGET) ? `plist: ${TARGET}` : "plist: not installed");