Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: add branch reconcile API route + boot registration
Adam Eivyb71d6898e4b4
diff --git a/server/index.js b/server/index.jsindex 0a5d1db426..15fce5ab6a 100644--- a/server/index.js+++ b/server/index.js@@ -76,6 +76,7 @@ import dataManagerRoutes from './routes/dataManager.js';import jiraRoutes from './routes/jira.js';import autobiographyRoutes from './routes/autobiography.js';import backupRoutes from './routes/backup.js';+import branchReconcileRoutes from './routes/branchReconcile.js';import legacyExportRoutes from './routes/legacyExport.js';import cityRoutes from './routes/cityRoutes.js';import databaseRoutes from './routes/database.js';@@ -170,6 +171,7 @@ import * as cos from './services/cos.js';import { startBackupScheduler } from './services/backupScheduler.js';import { startCitySnapshotScheduler } from './services/citySnapshotScheduler.js';import { startImessageScheduler } from './services/imessageScheduler.js';+import { startBranchReconcileScheduler } from './services/branchReconcileScheduler.js';import * as telegram from './services/telegram.js';import * as telegramBridge from './services/telegramBridge.js';import { getSettings as getInitSettings } from './services/settings.js';@@ -452,6 +454,7 @@ app.use('/api/media/sketches', mediaSketchesRoutes);app.use('/api/attachments', attachmentsRoutes);app.use('/api/client-errors', clientErrorsRoutes);app.use('/api/backup', backupRoutes);+app.use('/api/branch-reconcile', branchReconcileRoutes);app.use('/api/legacy-export', legacyExportRoutes);app.use('/api/city', cityRoutes);app.use('/api/database', databaseRoutes);@@ -603,6 +606,10 @@ startCitySnapshotScheduler().catch(err => console.error(`❌ City snapshot sched// Initialize iMessage sync scheduler — OFF by default; only polls chat.db when// the user opts in via Settings → iMessage (needs macOS Full Disk Access) (#2151).startImessageScheduler().catch(err => console.error(`❌ iMessage sync scheduler init failed: ${err.message}`));+// Initialize Branch & PR Reconciler — OFF by default; only registers a daily+// cron when the user opts in via Settings. Reconciles this machine's unfinished+// local branches/PRs (cleanup merged, finish in-flight) without touching peers.+startBranchReconcileScheduler().catch(err => console.error(`❌ Branch reconcile scheduler init failed: ${err.message}`));// Periodically GC orphan zero-issue/zero-canon importer shells left by an// abandoned analyze (issue #727).startOrphanShellGc();diff --git a/server/routes/branchReconcile.js b/server/routes/branchReconcile.jsnew file mode 100644index 0000000000..a7f6b5ef9a--- /dev/null+++ b/server/routes/branchReconcile.js@@ -0,0 +1,19 @@+import { Router } from 'express';+import { asyncHandler } from '../lib/errorHandler.js';+import { runBranchReconcile, getLastRun } from '../services/branchReconcileScheduler.js';++const router = Router();++// GET /api/branch-reconcile/status — last run summary (null until first run).+router.get('/status', asyncHandler(async (req, res) => {+ res.json({ lastRun: getLastRun() });+}));++// POST /api/branch-reconcile/run — run one reconcile pass on demand. An explicit+// user click is its own consent, so it bypasses the enabled gate (force:true).+router.post('/run', asyncHandler(async (req, res) => {+ const summary = await runBranchReconcile({ force: true });+ res.json(summary);+}));++export default router;diff --git a/server/routes/branchReconcile.test.js b/server/routes/branchReconcile.test.jsnew file mode 100644index 0000000000..e37d56e1a1--- /dev/null+++ b/server/routes/branchReconcile.test.js@@ -0,0 +1,46 @@+/**+ * Route tests for /api/branch-reconcile.+ * The service is mocked — we only verify routing (POST /run forces a run,+ * GET /status returns the last summary).+ */++import { describe, it, expect, vi, beforeEach } from 'vitest';+import express from 'express';+import { request } from '../lib/testHelper.js';+import { errorMiddleware } from '../lib/errorHandler.js';++vi.mock('../services/branchReconcileScheduler.js', () => ({+ runBranchReconcile: vi.fn(async () => ({ cleaned: ['old'], dispatched: true })),+ getLastRun: vi.fn(() => ({ at: '2026-07-06T00:00:00.000Z', dispatched: false }))+}));++import branchReconcileRoutes from './branchReconcile.js';+import { runBranchReconcile, getLastRun } from '../services/branchReconcileScheduler.js';++const makeApp = () => {+ const app = express();+ app.use(express.json());+ app.use('/api/branch-reconcile', branchReconcileRoutes);+ app.use(errorMiddleware);+ return app;+};++beforeEach(() => vi.clearAllMocks());++describe('POST /api/branch-reconcile/run', () => {+ it('forces a run and returns the summary', async () => {+ const res = await request(makeApp()).post('/api/branch-reconcile/run').send({});+ expect(res.status).toBe(200);+ expect(res.body).toEqual({ cleaned: ['old'], dispatched: true });+ expect(runBranchReconcile).toHaveBeenCalledWith({ force: true });+ });+});++describe('GET /api/branch-reconcile/status', () => {+ it('returns the last run summary', async () => {+ const res = await request(makeApp()).get('/api/branch-reconcile/status');+ expect(res.status).toBe(200);+ expect(res.body.lastRun.dispatched).toBe(false);+ expect(getLastRun).toHaveBeenCalled();+ });+});