0.1.6: GBrain brains — refreshed after sync, clashes never make a second page

- A vault has a kind on the hub: Obsidian (as before) or GBrain. Set it with
  `lunesync vault kind`, the canvas panel or the window; Lune suggests it when
  it finds gbrain.yml / .gbrain-source. Every change is in the access log.
- GBrain vaults: devices that have `gbrain` (looked for beyond PATH) are asked
  once whether to refresh it after sync. Lune then runs
  `gbrain sync --source <name> --no-pull` in the background after notes arrive
  or are saved; it never holds up syncing. A failed refresh turns the vault
  amber ("GBrain not refreshed") with Retry, also on the canvas.
- Clashes in GBrain vaults: lines both sides added are kept in the one note,
  incoming first. Same lines changed: the incoming version stays, this
  device's waits under Notes to tidy, stored in .git/lune/tidy (never a copy
  file GBrain would index). Applies to syncing, undo, held notes and
  handovers. Held notes moved aside stay red until decided.
- .gbrain-source is kept per device. Obsidian vaults are unchanged.
- SPEC: M8 section and decisions recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 22:55:18 +07:00
parent ac5dba46df
commit e6c3f008a0
30 changed files with 2169 additions and 101 deletions

View File

@@ -320,7 +320,7 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
vaults.forEach((v, i) => {
const p = pos(v.id), delay = (i * 0.7).toFixed(1), vo = relV(v.id) ? 1 : 0.35;
// Amber means a decision is waiting (X6): notes to tidy, handovers to review.
const review = v.handovers.filter((h) => h.state === 'received').length, tidy = v.tidy.length;
const review = v.handovers.filter((h) => h.state === 'received').length, tidy = v.tidy.length + v.tidy_on.reduce((n, t) => n + t.count, 0);
const decide = review + tidy;
if (decide > 0) {
labels.push({
@@ -329,6 +329,13 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
inner: { display: 'inline-block', whiteSpace: 'nowrap', fontWeight: 700, fontSize: 'max(1.05cqw, 9px)', color: '#7A4500', background: '#FBEBD3', border: '1px solid #E09A2B', borderRadius: 999, padding: '0.15em 0.7em', animationDelay: `${delay}s` },
});
}
if (v.kind === 'gbrain') {
labels.push({
text: 'GBrain',
style: { ...pct(p.x - 34, p.y + 44), transform: 'translate(-50%,-50%)', opacity: vo },
inner: { display: 'inline-block', whiteSpace: 'nowrap', fontWeight: 700, fontSize: 'max(0.95cqw, 8px)', color: '#4A3A8F', background: '#ECE7FA', border: '1px solid #B9AEE8', borderRadius: 999, padding: '0.1em 0.6em', animationDelay: `${delay}s` },
});
}
blobs.push({ d: roundRect(p.x, p.y, 138, 70, 26), fill: vaultColor(v.id).fill, delay, op: focus && relV(v.id) ? 1 : 0 });
labels.push({
text: v.name,
@@ -568,6 +575,8 @@ export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload:
cycleRole={cycleRole} remove={(m) => revoke(keyOf(m))} grant={grant} run={run}
compare={(copy) => setSheet({ kind: 'compare', vault: vault(sel.id), copy })}
deleteVault={data.me.owner ? (v) => setSheet({ kind: 'delete', v }) : undefined}
setKind={(v, kind) => run(() => api.vaultKind(v.name, kind), kind === 'gbrain' ? `${v.name} is now a GBrain vault. Every device learns it within a minute.` : `${v.name} is an Obsidian vault again.`)}
dismissHint={(v) => run(() => api.dismissGbrainHint(v.name))}
toggleDelete={(v) => run(() => api.vaultSetting(v.name, !v.delete_from_devices), v.delete_from_devices ? `Removed people keep a read-only copy of ${v.name}.` : `Removed people's copies of ${v.name} are deleted from their devices.`)} />
)}
{sel.kind === 'person' && person(sel.id) && (
@@ -685,7 +694,8 @@ function Overview({ data, members, log, open, close, newVault, signOut }: {
);
}
function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, toggleDelete, run, compare, deleteVault }: {
function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, toggleDelete, run, compare, deleteVault, setKind, dismissHint }: {
setKind: (v: Vault, kind: 'obsidian' | 'gbrain') => void; dismissHint: (v: Vault) => void;
v: Vault; data: CanvasData; members: Member[]; open: (s: Sel) => void; close: () => void; deleteVault?: (v: Vault) => void;
cycleRole: (m: Member) => void; remove: (m: Member) => void; grant: (v: string, p: string) => void; toggleDelete: (v: Vault) => void;
run: (action: () => Promise<unknown>, ok?: string) => Promise<void>; compare: (copy: string) => void;
@@ -696,7 +706,7 @@ function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, t
return (
<>
<div className="panel-head">
<div><span className="eyebrow">Vault · {plural(inVault.length, 'person', 'people')}</span><h2 className="disp">{v.name}</h2></div>
<div><span className="eyebrow">Vault · {plural(inVault.length, 'person', 'people')}</span><h2 className="disp">{v.name}{v.kind === 'gbrain' && <span className="pill" style={{ background: '#ECE7FA', color: '#4A3A8F', marginLeft: 8, fontSize: 12, verticalAlign: 'middle' }}>GBrain</span>}</h2></div>
<CloseButton close={close} />
</div>
{!v.can_manage && mine && <div className="note">You have {roleName(mine.role)} access. People with Manage decide who else can sync it.</div>}
@@ -712,6 +722,29 @@ function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, t
))}
</div>
)}
{v.tidy_on.length > 0 && (
<div className="note amber">
<b>{plural(v.tidy_on.reduce((n, t) => n + t.count, 0), 'note')} to tidy</b>
<span>The same lines were changed in two places. The newer version is in the vault; the other is kept on the device that made it, outside the notes.</span>
{v.tidy_on.map((t) => <span key={t.device}>{plural(t.count, 'note')} to tidy on {t.device}</span>)}
</div>
)}
{v.gbrain_stale.length > 0 && (
<div className="note amber">
<b>GBrain not refreshed</b>
<span>On {v.gbrain_stale.join(', ')}. Notes keep syncing; the device offers Retry.</span>
</div>
)}
{v.suggest_gbrain && (
<div className="note">
<b>This looks like a GBrain</b>
<span>Mark it as one and each device can keep GBrain up to date after notes arrive.</span>
<div style={{ display: 'flex', gap: 8 }}>
<button className="btn btn-small" onClick={() => dismissHint(v)}>Not now</button>
<button className="btn btn-small btn-primary" onClick={() => setKind(v, 'gbrain')}>Mark as GBrain</button>
</div>
</div>
)}
{v.handovers.map((h) => <HandoverCard key={h.id} h={h} vault={v} run={run} />)}
<div>
<h3>People with access</h3>
@@ -741,6 +774,15 @@ function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, t
<div className="chips">{outside.map((p) => <button key={p.id} className="btn btn-small" onClick={() => grant(v.id, p.id)}>+ {p.name}</button>)}</div>
</div>
)}
{v.can_manage && (
<div style={{ borderTop: '1px solid #EEEAF6', paddingTop: 16, display: 'flex', flexDirection: 'column', gap: 6 }}>
<h3>What this vault is</h3>
<label className="check">
<input type="checkbox" checked={v.kind === 'gbrain'} onChange={() => setKind(v, v.kind === 'gbrain' ? 'obsidian' : 'gbrain')} />
<span>A GBrain brain: devices keep GBrain up to date after notes arrive</span>
</label>
</div>
)}
{v.can_manage && (
<div style={{ borderTop: '1px solid #EEEAF6', paddingTop: 16, display: 'flex', flexDirection: 'column', gap: 6 }}>
<h3>When someone is removed</h3>

View File

@@ -7,8 +7,15 @@ export interface Vault {
name: string;
can_manage: boolean;
delete_from_devices: boolean;
kind: 'obsidian' | 'gbrain';
/** Managers: devices whose last GBrain refresh failed. */
gbrain_stale: string[];
/** Managers: the vault looks like a GBrain but isn't marked as one. */
suggest_gbrain: boolean;
/** Notes kept in two versions (S4), from the hub's copy. */
tidy: { note: string; copy: string; label: string }[];
/** GBrain vaults: devices that keep a version of some notes to themselves, waiting to be tidied there. */
tidy_on: { device: string; count: number }[];
/** Departures needing a manager: waiting for the device, or received for review. */
handovers: { id: number; person: string; device: string; state: 'waiting' | 'received' }[];
}
@@ -22,6 +29,7 @@ export interface Health {
waiting: number;
held_secrets: number;
holding: boolean;
gbrain_failed: boolean;
}
export interface Device {
@@ -105,6 +113,8 @@ export const api = {
createVault: (name: string) => call<object>('POST', '/api/vaults', { name }),
vaultSetting: (vault: string, deleteFromDevices: boolean) =>
call<object>('POST', '/api/vaults/settings', { vault, delete_from_devices: deleteFromDevices }),
vaultKind: (vault: string, kind: 'obsidian' | 'gbrain') => call<object>('POST', '/api/vaults/kind', { vault, kind }),
dismissGbrainHint: (vault: string) => call<object>('POST', '/api/vaults/kind', { vault, dismiss_suggestion: true }),
renameDevice: (deviceId: string, label: string) => call<object>('POST', '/api/devices/rename', { device_id: deviceId, label }),
nudge: (deviceId: string) => call<object>('POST', '/api/nudge', { device_id: deviceId }),
compare: (vault: string, copy: string) => call<Comparison>('POST', '/api/tidy/compare', { vault, copy }),

View File

@@ -22,8 +22,14 @@ interface VaultStatus {
running: boolean;
held: { message: string; removed: number; rewritten: number; total: number }[];
secrets: { path: string; found: string[] }[];
tidy: { note: string; copy: string; label: string }[];
tidy: { note: string; copy: string; label: string; local?: boolean; held?: boolean }[];
case_clashes: string[];
kind: 'obsidian' | 'gbrain';
suggest_gbrain: boolean;
gbrain: {
refresh: boolean | null; source: string; found: boolean; ask: boolean; failed: boolean;
error: string | null; refreshing: boolean; last_refreshed: number | null;
} | null;
}
interface Overview {
@@ -156,12 +162,53 @@ function VaultCard({ v, several, canUpload, upload, act, compare }: {
<div className="vault-head">
<Dot level={v.level} />
<div className="vault-name">
<b>{v.name}{several && v.team && <span className="team-tag">{host(v.team)}</span>}</b>
<b>{v.name}{several && v.team && <span className="team-tag">{host(v.team)}</span>}{v.kind === 'gbrain' && <span className="team-tag">GBrain</span>}</b>
<span className="muted">{v.headline}</span>
</div>
{canUpload && !v.team && <button className="btn btn-small" onClick={() => upload(v)}>Upload</button>}
<button className="btn btn-small btn-ghost" onClick={() => act('open_folder', { vault: v.name }, '')}>Open folder</button>
</div>
{v.suggest_gbrain && v.team && (
<div className="need">
<b>This looks like a GBrain</b>
<span className="muted">Mark it as one and Lune keeps GBrain up to date here after notes arrive. Every device on the team learns it.</span>
<div className="actions">
<button className="btn btn-small" onClick={() => act('dismiss_gbrain_hint', { vault: v.name }, 'OK — not asking again')}>Not now</button>
<button className="btn btn-small btn-primary" onClick={() => act('set_vault_kind', { vault: v.name, kind: 'gbrain' }, `${v.name} is now a GBrain vault`)}>Mark as GBrain</button>
</div>
</div>
)}
{v.gbrain?.failed && (
<div className="need">
<b>GBrain not refreshed</b>
<span className="muted">{v.gbrain.error ?? 'The last refresh did not finish.'} Your notes keep syncing.</span>
<div className="actions">
<button className="btn btn-small btn-primary" disabled={v.gbrain.refreshing} onClick={() => act('gbrain_retry', { vault: v.name }, 'Refreshing GBrain')}>{v.gbrain.refreshing ? 'Refreshing…' : 'Retry'}</button>
</div>
</div>
)}
{v.gbrain?.ask && (
<div className="need">
<b>Refresh GBrain after sync?</b>
<span className="muted">GBrain is installed on this Mac. Lune can bring it up to date whenever notes arrive here, in the background.</span>
<div className="actions">
<button className="btn btn-small" onClick={() => act('gbrain_settings', { vault: v.name, refresh: false }, 'OK — GBrain is left alone')}>No</button>
<button className="btn btn-small btn-primary" onClick={() => act('gbrain_settings', { vault: v.name, refresh: true }, 'GBrain will refresh after sync')}>Yes, refresh it</button>
</div>
</div>
)}
{v.gbrain && v.gbrain.refresh !== null && (
<div className="muted" style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
<span>Refresh GBrain after sync: {v.gbrain.refresh ? 'on' : 'off'}</span>
<button className="btn btn-small btn-ghost" onClick={() => act('gbrain_settings', { vault: v.name, refresh: !v.gbrain!.refresh }, v.gbrain!.refresh ? 'GBrain is left alone' : 'GBrain will refresh after sync')}>{v.gbrain.refresh ? 'Turn off' : 'Turn on'}</button>
</div>
)}
{v.team && (
<div className="muted" style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
<span>{v.kind === 'gbrain' ? 'A GBrain vault' : 'An Obsidian vault'}</span>
<button className="btn btn-small btn-ghost" onClick={() => act('set_vault_kind', { vault: v.name, kind: v.kind === 'gbrain' ? 'obsidian' : 'gbrain' }, v.kind === 'gbrain' ? `${v.name} is an Obsidian vault again` : `${v.name} is now a GBrain vault`)}>{v.kind === 'gbrain' ? 'Make it Obsidian' : 'Mark as GBrain'}</button>
</div>
)}
{v.held.map((h) => (
<div key={h.message} className="need">
<b>A big change is waiting for you</b>
@@ -176,7 +223,9 @@ function VaultCard({ v, several, canUpload, upload, act, compare }: {
{v.tidy.map((t) => (
<div key={t.copy} className="need">
<b>{t.note} was changed in two places</b>
<span className="muted">Both versions are kept; pick one when you have a moment.</span>
<span className="muted">{t.local
? (t.held ? "Your version is kept on this Mac, outside your notes, because it looked like it held a secret. Pick one when you have a moment." : "The other version is in your notes. Yours is kept on this Mac, outside them. Pick one when you have a moment.")
: 'Both versions are kept; pick one when you have a moment.'}</span>
<div className="actions">
<button className="btn btn-small btn-primary" onClick={() => compare(v.name, t.copy)}>Compare</button>
</div>
@@ -194,7 +243,7 @@ function CompareSheet({ vault, copy, close, done }: { vault: string; copy: strin
const keep = async (which: 'note' | 'copy' | 'both') => {
try {
await invoke('tidy', { vault, copy, keep: which });
done(which === 'both' ? 'Kept both as separate notes' : 'Tidied — every device gets it shortly');
done(which === 'both' ? 'Kept both' : 'Tidied — every device gets it shortly');
} catch (e) {
setError(String(e));
}