Skip to content

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

feat: add Branch Reconcile settings tab

Adam Eivy7c7be576e0cf
diff --git a/client/src/components/settings/BranchReconcileTab.jsx b/client/src/components/settings/BranchReconcileTab.jsx
new file mode 100644
index 0000000000..7b7b863dfe
--- /dev/null
+++ b/client/src/components/settings/BranchReconcileTab.jsx
@@ -0,0 +1,194 @@
+import { useEffect, useState } from 'react';
+import { Save, Loader2, GitPullRequest, RefreshCw } from 'lucide-react';
+import toast from '../ui/Toast';
+import BrailleSpinner from '../BrailleSpinner';
+import {
+ getSettings,
+ updateSettings,
+ getBranchReconcileStatus,
+ runBranchReconcile,
+} from '../../services/api';
+
+// Actions follow an opt-out model: absent/undefined means ON. Only an explicit
+// `false` disables. Mirrors the server's `actionOn` helper.
+const on = (v) => v !== false;
+
+const ACTIONS = [
+ { key: 'cleanupMerged', label: 'Clean up merged/orphaned branches + worktrees', help: 'Deterministic — no agent. Removes a local branch whose work is already merged, plus its lingering worktree.' },
+ { key: 'openPr', label: 'Open a PR for a finished branch without one', help: 'Agent verifies the work is complete, then runs /do:pr.' },
+ { key: 'resolveConflicts', label: 'Resolve conflicts on open PRs', help: 'Agent rebases onto the default branch and resolves conflicts.' },
+ { key: 'autoMerge', label: 'Auto-merge PRs that are fully green', help: 'Merges only when MERGEABLE + CI green + latest Copilot review has 0 comments.' },
+];
+
+// Settings → Branch Reconcile. Opt-in daily automation that finishes THIS
+// machine's unfinished local branches/PRs (cleanup merged, open PRs, resolve
+// conflicts, merge) without touching federated peers' branches. OFF by default.
+export function BranchReconcileTab() {
+ const [loading, setLoading] = useState(true);
+ const [enabled, setEnabled] = useState(false);
+ const [cron, setCron] = useState('0 3 * * *');
+ const [actions, setActions] = useState({ cleanupMerged: true, openPr: true, resolveConflicts: true, autoMerge: true });
+
+ const [savedEnabled, setSavedEnabled] = useState(false);
+ const [savedCron, setSavedCron] = useState('0 3 * * *');
+ const [savedActions, setSavedActions] = useState({ cleanupMerged: true, openPr: true, resolveConflicts: true, autoMerge: true });
+
+ const [saving, setSaving] = useState(false);
+ const [running, setRunning] = useState(false);
+ const [lastRun, setLastRun] = useState(null);
+
+ useEffect(() => {
+ Promise.all([
+ getSettings({ silent: true }).catch(() => ({})),
+ getBranchReconcileStatus({ silent: true }).catch(() => null),
+ ]).then(([settings, status]) => {
+ const c = settings?.branchReconcile || {};
+ const en = c.enabled === true;
+ const cr = typeof c.cron === 'string' && c.cron ? c.cron : '0 3 * * *';
+ const acts = {
+ cleanupMerged: on(c.actions?.cleanupMerged),
+ openPr: on(c.actions?.openPr),
+ resolveConflicts: on(c.actions?.resolveConflicts),
+ autoMerge: on(c.actions?.autoMerge),
+ };
+ setEnabled(en); setCron(cr); setActions(acts);
+ setSavedEnabled(en); setSavedCron(cr); setSavedActions(acts);
+ setLastRun(status?.lastRun || null);
+ }).finally(() => setLoading(false));
+ }, []);
+
+ const actionsDirty = ACTIONS.some((a) => actions[a.key] !== savedActions[a.key]);
+ const dirty = enabled !== savedEnabled || cron.trim() !== savedCron || actionsDirty;
+
+ const handleSave = async () => {
+ const cr = cron.trim() || '0 3 * * *';
+ setSaving(true);
+ const merged = await updateSettings({ branchReconcile: { enabled, cron: cr, actions } }).catch(() => null);
+ setSaving(false);
+ if (!merged) return;
+ setCron(cr);
+ setSavedEnabled(enabled); setSavedCron(cr); setSavedActions(actions);
+ toast.success('Saved — schedule applies on next server restart');
+ };
+
+ // Run Now gates on the SAVED enabled state (not the in-memory toggle) and is
+ // disabled while the form is dirty or a save/run is in flight — so the user
+ // can't trigger a run against a config they haven't persisted.
+ const handleRunNow = async () => {
+ setRunning(true);
+ const summary = await runBranchReconcile({ silent: true }).catch(() => null);
+ setRunning(false);
+ if (!summary) { toast.error('Reconcile run failed'); return; }
+ setLastRun(summary);
+ if (summary.skipped === 'disabled') toast.error('Reconciler is disabled — enable and save first');
+ else toast.success(`Reconcile: cleaned ${summary.cleaned?.length ?? 0}, dispatched=${summary.dispatched ? 'yes' : 'no'}`);
+ };
+
+ if (loading) return <BrailleSpinner />;
+
+ return (
+ <div className="space-y-6">
+ <div className="bg-port-card border border-port-border rounded-lg p-4 sm:p-6">
+ <div className="flex items-center gap-2 mb-2">
+ <GitPullRequest size={16} className="text-port-accent" />
+ <h3 className="text-lg font-semibold text-white">Branch &amp; PR Reconciler</h3>
+ </div>
+ <p className="text-sm text-gray-400 mb-4">
+ Daily automation that finishes <strong>this machine&apos;s</strong> unfinished git work: cleans up branches
+ whose PRs already merged, and dispatches an agent to open PRs, resolve conflicts, and merge in-flight ones.
+ Only local branches are touched — branches created on federated peers are never affected. OFF by default.
+ </p>
+
+ <div className="space-y-4">
+ <label htmlFor="br-enabled" className="flex items-center gap-2 text-sm text-gray-200 cursor-pointer">
+ <input
+ id="br-enabled"
+ type="checkbox"
+ checked={enabled}
+ onChange={(e) => setEnabled(e.target.checked)}
+ className="w-4 h-4 accent-port-accent"
+ />
+ Enable the daily reconciler
+ </label>
+
+ <div>
+ <label htmlFor="br-cron" className="block text-xs uppercase tracking-wider text-gray-500 mb-1">
+ Cron schedule
+ </label>
+ <input
+ id="br-cron"
+ type="text"
+ value={cron}
+ onChange={(e) => setCron(e.target.value)}
+ placeholder="0 3 * * *"
+ className="w-48 px-3 py-2 bg-port-bg border border-port-border rounded text-white text-sm font-mono"
+ />
+ <p className="text-xs text-gray-500 mt-1">Default <code className="text-gray-400">0 3 * * *</code> = daily at 3am.</p>
+ </div>
+
+ <fieldset className="space-y-2">
+ <legend className="text-xs uppercase tracking-wider text-gray-500 mb-1">Actions</legend>
+ {ACTIONS.map((a) => (
+ <label key={a.key} htmlFor={`br-action-${a.key}`} className="flex items-start gap-2 text-sm text-gray-200 cursor-pointer">
+ <input
+ id={`br-action-${a.key}`}
+ type="checkbox"
+ checked={actions[a.key]}
+ onChange={(e) => setActions((prev) => ({ ...prev, [a.key]: e.target.checked }))}
+ className="w-4 h-4 mt-0.5 accent-port-accent"
+ />
+ <span>
+ {a.label}
+ <span className="block text-xs text-gray-500">{a.help}</span>
+ </span>
+ </label>
+ ))}
+ </fieldset>
+
+ <div className="flex flex-wrap gap-2 pt-1">
+ <button
+ type="button"
+ onClick={handleSave}
+ disabled={!dirty || saving}
+ className="inline-flex items-center justify-center gap-2 min-h-[40px] px-4 py-2 bg-port-accent/20 hover:bg-port-accent/30 text-port-accent rounded-lg text-sm transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
+ >
+ {saving ? <Loader2 size={14} className="animate-spin" /> : <Save size={14} />}
+ {saving ? 'Saving...' : 'Save'}
+ </button>
+ <button
+ type="button"
+ onClick={handleRunNow}
+ disabled={!savedEnabled || dirty || saving || running}
+ title={!savedEnabled ? 'Enable and save first' : dirty ? 'Save your changes first' : 'Run a reconcile pass now'}
+ className="inline-flex items-center justify-center gap-2 min-h-[40px] px-4 py-2 bg-port-bg border border-port-border hover:border-port-accent text-gray-200 rounded-lg text-sm transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
+ >
+ {running ? <Loader2 size={14} className="animate-spin" /> : <RefreshCw size={14} />}
+ Run now
+ </button>
+ </div>
+ </div>
+ </div>
+
+ {lastRun && (
+ <div className="bg-port-card border border-port-border rounded-lg p-4 sm:p-6">
+ <h3 className="text-sm font-semibold text-white mb-2">Last run</h3>
+ {lastRun.skipped === 'disabled' ? (
+ <p className="text-sm text-gray-400">Skipped — reconciler disabled.</p>
+ ) : lastRun.error ? (
+ <p className="text-sm text-port-error">{lastRun.error}</p>
+ ) : (
+ <dl className="grid grid-cols-2 sm:grid-cols-3 gap-3 text-sm">
+ <div><dt className="text-gray-500 text-xs uppercase">When</dt><dd className="text-gray-200">{lastRun.at ? new Date(lastRun.at).toLocaleString() : '—'}</dd></div>
+ <div><dt className="text-gray-500 text-xs uppercase">Cleaned</dt><dd className="text-gray-200">{lastRun.cleaned?.length ?? 0}</dd></div>
+ <div><dt className="text-gray-500 text-xs uppercase">Dispatched agent</dt><dd className="text-gray-200">{lastRun.dispatched ? 'yes' : 'no'}</dd></div>
+ <div><dt className="text-gray-500 text-xs uppercase">Actionable</dt><dd className="text-gray-200">{lastRun.actionable?.join(', ') || '—'}</dd></div>
+ <div><dt className="text-gray-500 text-xs uppercase">WIP (left)</dt><dd className="text-gray-200">{lastRun.wip?.join(', ') || '—'}</dd></div>
+ </dl>
+ )}
+ </div>
+ )}
+ </div>
+ );
+}
+
+export default BranchReconcileTab;
diff --git a/client/src/components/settings/BranchReconcileTab.test.jsx b/client/src/components/settings/BranchReconcileTab.test.jsx
new file mode 100644
index 0000000000..8db3509e00
--- /dev/null
+++ b/client/src/components/settings/BranchReconcileTab.test.jsx
@@ -0,0 +1,64 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+
+vi.mock('../../services/api', () => ({
+ getSettings: vi.fn(),
+ updateSettings: vi.fn(),
+ getBranchReconcileStatus: vi.fn(),
+ runBranchReconcile: vi.fn(),
+}));
+vi.mock('../ui/Toast', () => ({
+ default: Object.assign(vi.fn(), { success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn() }),
+}));
+vi.mock('../BrailleSpinner', () => ({ default: () => <div>loading</div> }));
+
+import {
+ getSettings, updateSettings, getBranchReconcileStatus, runBranchReconcile,
+} from '../../services/api';
+import { BranchReconcileTab } from './BranchReconcileTab';
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ getBranchReconcileStatus.mockResolvedValue({ lastRun: null });
+});
+
+describe('BranchReconcileTab', () => {
+ it('disables Run Now when the reconciler is saved-disabled', async () => {
+ getSettings.mockResolvedValue({ branchReconcile: { enabled: false } });
+ render(<BranchReconcileTab />);
+ const runBtn = await screen.findByRole('button', { name: /run now/i });
+ expect(runBtn).toBeDisabled();
+ });
+
+ it('disables Run Now while the form is dirty even if saved-enabled', async () => {
+ getSettings.mockResolvedValue({ branchReconcile: { enabled: true, cron: '0 3 * * *' } });
+ render(<BranchReconcileTab />);
+ const runBtn = await screen.findByRole('button', { name: /run now/i });
+ expect(runBtn).not.toBeDisabled(); // saved-enabled, clean
+
+ // Make the form dirty by toggling an action.
+ fireEvent.click(screen.getByLabelText(/Auto-merge PRs/i));
+ expect(runBtn).toBeDisabled();
+ });
+
+ it('runs a reconcile pass when Run Now is clicked (saved-enabled + clean)', async () => {
+ getSettings.mockResolvedValue({ branchReconcile: { enabled: true, cron: '0 3 * * *' } });
+ runBranchReconcile.mockResolvedValue({ at: 't', cleaned: ['a'], dispatched: true });
+ render(<BranchReconcileTab />);
+ const runBtn = await screen.findByRole('button', { name: /run now/i });
+ fireEvent.click(runBtn);
+ await waitFor(() => expect(runBranchReconcile).toHaveBeenCalledWith({ silent: true }));
+ });
+
+ it('saves the config with the branchReconcile slice', async () => {
+ getSettings.mockResolvedValue({ branchReconcile: { enabled: false, cron: '0 3 * * *' } });
+ updateSettings.mockResolvedValue({ branchReconcile: {} });
+ render(<BranchReconcileTab />);
+ await screen.findByRole('button', { name: /run now/i });
+ fireEvent.click(screen.getByLabelText(/Enable the daily reconciler/i));
+ fireEvent.click(screen.getByRole('button', { name: /^save$/i }));
+ await waitFor(() => expect(updateSettings).toHaveBeenCalledWith(
+ expect.objectContaining({ branchReconcile: expect.objectContaining({ enabled: true }) })
+ ));
+ });
+});
diff --git a/client/src/components/settings/SettingsTabsHeader.jsx b/client/src/components/settings/SettingsTabsHeader.jsx
index b0bd1ce3c8..0beefb9fd6 100644
--- a/client/src/components/settings/SettingsTabsHeader.jsx
+++ b/client/src/components/settings/SettingsTabsHeader.jsx
@@ -14,6 +14,7 @@ export const TABS = [
{ id: 'api-access', label: 'API Access', to: '/settings/api-access' },
{ id: 'autofixer', label: 'Autofixer', to: '/settings/autofixer' },
{ id: 'backup', label: 'Backup', to: '/settings/backup' },
+ { id: 'branch-reconcile', label: 'Branch Reconcile', to: '/settings/branch-reconcile' },
{ id: 'catalog', label: 'Catalog', to: '/settings/catalog' },
{ id: 'database', label: 'Database', to: '/settings/database' },
{ id: 'embeddings', label: 'Embeddings', to: '/settings/embeddings' },
diff --git a/client/src/pages/Settings.jsx b/client/src/pages/Settings.jsx
index 6768a81f67..e3dd912df3 100644
--- a/client/src/pages/Settings.jsx
+++ b/client/src/pages/Settings.jsx
@@ -5,6 +5,7 @@ import { ApiAccessTab } from '../components/settings/ApiAccessTab';
import { AutofixerTab } from '../components/settings/AutofixerTab';
import AiAssignmentsTab from '../components/settings/AiAssignmentsTab';
import { BackupTab } from '../components/settings/BackupTab';
+import { BranchReconcileTab } from '../components/settings/BranchReconcileTab';
import { CatalogTypesTab } from '../components/settings/CatalogTypesTab';
import { DatabaseTab } from '../components/settings/DatabaseTab';
import EmbeddingsTab from '../components/settings/EmbeddingsTab';
@@ -41,6 +42,7 @@ export default function Settings() {
case 'api-access': return <ApiAccessTab />;
case 'autofixer': return <AutofixerTab />;
case 'backup': return <BackupTab />;
+ case 'branch-reconcile': return <BranchReconcileTab />;
case 'catalog': return <CatalogTypesTab />;
case 'database': return <DatabaseTab />;
case 'embeddings': return <EmbeddingsTab />;
diff --git a/client/src/services/apiSystem.js b/client/src/services/apiSystem.js
index 56e142055e..ba3b740da7 100644
--- a/client/src/services/apiSystem.js
+++ b/client/src/services/apiSystem.js
@@ -101,6 +101,10 @@ export const getBackupSnapshots = (options) => request('/backup/snapshots', opti
export const restoreBackup = (data, options = {}) => request('/backup/restore', { method: 'POST', body: JSON.stringify(data), ...options });
export const restoreDatabase = (data, options) => request('/backup/restore-db', { method: 'POST', body: JSON.stringify(data), ...options });
+// Branch & PR Reconciler — finishes this machine's unfinished local branches/PRs.
+export const getBranchReconcileStatus = (options) => request('/branch-reconcile/status', options);
+export const runBranchReconcile = (options = {}) => request('/branch-reconcile/run', { method: 'POST', ...options });
+
// Data Manager
export const getDataOverview = () => request('/data');
export const getDataCategory = (key) => request(`/data/${key}`);
diff --git a/server/lib/navManifest.js b/server/lib/navManifest.js
index 52075e51b4..a259763dd5 100644
--- a/server/lib/navManifest.js
+++ b/server/lib/navManifest.js
@@ -171,6 +171,7 @@ export const NAV_COMMANDS = [
{ id: 'nav.settings.api-access', path: '/settings/api-access', label: 'API Access', section: 'Settings', aliases: ['api-access', 'settings-api-access', 'public-api', 'swagger', 'openapi'], keywords: ['rest', 'external', 'tts api', 'sdapi', 'voice api', 'docs', 'curl', 'expose', 'passwordless', 'auth gating'] },
{ id: 'nav.settings.autofixer', path: '/settings/autofixer', label: 'Autofixer', section: 'Settings', aliases: ['autofixer', 'settings-autofixer', 'auto-fixer'], keywords: ['crash', 'fix', 'pm2', 'repair', 'ai provider', 'restart'] },
{ id: 'nav.settings.backup', path: '/settings/backup', label: 'Backup', section: 'Settings', aliases: ['backup', 'settings-backup'] },
+ { id: 'nav.settings.branch-reconcile', path: '/settings/branch-reconcile', label: 'Branch Reconcile', section: 'Settings', aliases: ['branch-reconcile', 'reconcile', 'settings-branch-reconcile', 'branch-pr-reconciler'], keywords: ['branch', 'pr', 'pull request', 'merge', 'worktree', 'cleanup', 'unfinished', 'orphaned', 'stale branches'] },
{ id: 'nav.settings.catalog', path: '/settings/catalog', label: 'Catalog Types', section: 'Settings', aliases: ['settings-catalog', 'catalog-types'], keywords: ['catalog', 'types', 'character', 'place', 'object', 'taxonomy'] },
{ id: 'nav.settings.database', path: '/settings/database', label: 'Database', section: 'Settings', aliases: ['settings-database', 'database'] },
{ id: 'nav.settings.embeddings', path: '/settings/embeddings', label: 'Embeddings', section: 'Settings', aliases: ['settings-embeddings', 'embeddings', 'embedding'], keywords: ['vector', 'pgvector', 'semantic search', 'nomic', 'ollama', 'lm studio'] },