Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(main): scheduled missions backend (config + scheduler + IPC)

Chaitanya Giri1fcbb83ed1a3
diff --git a/src/main/config.ts b/src/main/config.ts
index d4df2874..81ccbf1e 100644
--- a/src/main/config.ts
+++ b/src/main/config.ts
@@ -2,6 +2,17 @@ import { app } from 'electron';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
+/** A recurring auto-dispatched mission fired on an interval by the scheduler. */
+export interface ScheduledMission {
+ id: string;
+ label: string;
+ intervalMs: number;
+ to: string;
+ body: string;
+ enabled: boolean;
+ lastFiredAt?: number;
+}
+
export interface HarnessConfig {
/** Has the user completed the first-run onboarding? */
onboardingComplete: boolean;
@@ -19,6 +30,8 @@ export interface HarnessConfig {
semanticMemory: boolean;
/** Embedding model for the palace: lightweight 'minilm' or multilingual 'embeddinggemma'. */
embeddingModel: 'minilm' | 'embeddinggemma';
+ /** Recurring auto-dispatch missions handled by the scheduler. */
+ missions?: ScheduledMission[];
}
const DEFAULTS: HarnessConfig = {
@@ -28,7 +41,8 @@ const DEFAULTS: HarnessConfig = {
autoMode: true,
defaultCommand: 'claude',
semanticMemory: true,
- embeddingModel: 'minilm'
+ embeddingModel: 'minilm',
+ missions: []
};
function configPath(): string {
diff --git a/src/main/index.ts b/src/main/index.ts
index b8771c77..472abd93 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -5,7 +5,7 @@ import { join } from 'node:path';
import { PtyManager, type SpawnOptions } from './pty';
import {
readConfig, writeConfig, resetConfig, ensureHarnessHome,
- type HarnessConfig
+ type HarnessConfig, type ScheduledMission
} from './config';
import { listDir, readFileText, writeFileText } from './fs';
import {
@@ -32,6 +32,37 @@ let mainWindow: BrowserWindow | null = null;
/** When true, skip the quit interceptor (user already confirmed). */
let allowQuit = false;
+/** Active scheduler timers keyed by mission id. */
+const missionTimers = new Map<string, NodeJS.Timeout>();
+
+/** Rebuild the scheduler from persisted config: clear every existing timer,
+ * then arm a fresh interval for each enabled mission. Each tick dispatches the
+ * mission to its target agent and stamps lastFiredAt back into config. Called
+ * on boot (after the router starts) and after every missions:save. */
+function syncMissions(): void {
+ for (const t of missionTimers.values()) clearInterval(t);
+ missionTimers.clear();
+ const missions = readConfig().missions ?? [];
+ for (const m of missions) {
+ if (!m.enabled || !(m.intervalMs > 0)) continue;
+ const timer = setInterval(() => {
+ try {
+ if (hive.enabled()) {
+ hive.send({ to: m.to, act: 'request', subject: m.label, body: m.body }, 'scheduler');
+ }
+ const current = readConfig().missions ?? [];
+ const next = current.map((x) =>
+ x.id === m.id ? { ...x, lastFiredAt: Date.now() } : x
+ );
+ writeConfig({ missions: next });
+ } catch (e) {
+ console.error('[scheduler] mission', m.id, e);
+ }
+ }, m.intervalMs);
+ missionTimers.set(m.id, timer);
+ }
+}
+
/** The live renderer webContents, or null if the window is gone/destroyed.
* Anything that emits to the renderer from a timer/socket/child callback must
* route through here — during quit the window can be destroyed while those
@@ -302,11 +333,20 @@ ipcMain.handle('app:resetAll', () => {
app.exit(0);
});
+// ─── IPC: scheduled missions (recurring auto-dispatch) ──────────────────────
+ipcMain.handle('missions:list', () => readConfig().missions ?? []);
+ipcMain.handle('missions:save', (_evt, missions) => {
+ writeConfig({ missions: missions as ScheduledMission[] });
+ syncMissions();
+ return { ok: true };
+});
+
app.whenReady().then(() => {
// Bootstrap the hive (if harnessHome is configured) and start the message router.
if (hive.enabled()) {
hive.ensureHive();
hive.startRouter();
+ syncMissions(); // arm recurring auto-dispatch missions now the router is live
hookServer.start();
memory.start(); // init shared palace + mine loop (no-op without mempalace)
}