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([issue-709]): inline accept/promote actions on the Review Hub queue
[._.]/ Adam Eivy233649098c7c
diff --git a/client/src/pages/Review.jsx b/client/src/pages/Review.jsxindex eec47d4494..8492c38e7c 100644--- a/client/src/pages/Review.jsx+++ b/client/src/pages/Review.jsx@@ -79,6 +79,9 @@ export default function Review() {// than a server mutation — accept/promote actions are a follow-up.const [queue, setQueue] = useState(null);const [dismissedQueueIds, setDismissedQueueIds] = useState(() => new Set());+ // Rows with an inline accept/promote in flight — disables the button so a+ // double-tap can't double-resolve while the request is pending.+ const [resolvingQueueIds, setResolvingQueueIds] = useState(() => new Set());const fetchItems = useCallback(async () => {const params = filter === 'all' ? {} : { status: filter };@@ -169,6 +172,20 @@ export default function Review() {if (item.drillTo) navigate(item.drillTo);};+ const handleQueueResolve = async (item) => {+ if (resolvingQueueIds.has(item.id)) return;+ setResolvingQueueIds(prev => new Set(prev).add(item.id));+ // The helper toasts on failure (default), so don't add a custom catch toast.+ const ok = await api.resolveReviewQueueItem(item.id).then(() => true).catch(() => false);+ setResolvingQueueIds(prev => {+ const next = new Set(prev);+ next.delete(item.id);+ return next;+ });+ // Reactive removal — drop the resolved row in place rather than refetching.+ if (ok) handleQueueDismiss(item.id);+ };+const grouped = items.reduce((acc, item) => {if (!acc[item.type]) acc[item.type] = [];acc[item.type].push(item);@@ -272,7 +289,14 @@ export default function Review() {{queueItems.length > 0 && (<div className="space-y-2">{queueItems.map(item => (- <QueueRow key={item.id} item={item} onDrill={handleQueueDrill} onDismiss={handleQueueDismiss} />+ <QueueRow+ key={item.id}+ item={item}+ onDrill={handleQueueDrill}+ onDismiss={handleQueueDismiss}+ onResolve={handleQueueResolve}+ resolving={resolvingQueueIds.has(item.id)}+ />))}</div>)}@@ -414,7 +438,7 @@ export default function Review() {);}-function QueueRow({ item, onDrill, onDismiss }) {+function QueueRow({ item, onDrill, onDismiss, onResolve, resolving = false }) {const config = QUEUE_SOURCE_CONFIG[item.source] || { icon: Inbox, color: 'text-gray-400' };const Icon = config.icon;const borderTone = QUEUE_SEVERITY_STYLE[item.severity] || QUEUE_SEVERITY_STYLE.normal;@@ -442,6 +466,17 @@ function QueueRow({ item, onDrill, onDismiss }) {)}</div><div className="flex items-center gap-1 shrink-0">+ {item.action && onResolve && (+ <button+ onClick={() => onResolve(item)}+ disabled={resolving}+ className="inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium text-port-success bg-port-success/10 hover:bg-port-success/20 border border-port-success/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"+ title={`${item.action} this item in place`}+ >+ <Check size={14} />+ {item.action}+ </button>+ )}<buttononClick={() => onDrill(item)}className="p-1.5 text-gray-500 hover:text-port-accent transition-colors"diff --git a/client/src/services/apiReview.js b/client/src/services/apiReview.jsindex 5f782b99b8..adec4d9014 100644--- a/client/src/services/apiReview.js+++ b/client/src/services/apiReview.js@@ -12,6 +12,12 @@ export const getReviewCounts = () => request('/review/counts');export const getReviewBriefing = () => request('/review/briefing');// Cross-domain live queue (brain inbox, ask, CoS approvals, drafts, health, backups)export const getReviewQueue = (options = {}) => request('/review/queue', options);+// Accept/promote a single queue row in place (id is `<source>:<rawId>`)+export const resolveReviewQueueItem = (id, options = {}) => request('/review/queue/resolve', {+ method: 'POST',+ body: JSON.stringify({ id }),+ ...options+});export const createReviewTodo = (data) => request('/review/todo', {method: 'POST',body: JSON.stringify(data)diff --git a/server/routes/review.js b/server/routes/review.jsindex 8ce860ba8b..9b283e8600 100644--- a/server/routes/review.js+++ b/server/routes/review.js@@ -3,7 +3,7 @@ import { z } from 'zod';import { asyncHandler } from '../lib/errorHandler.js';import { validateRequest } from '../lib/validation.js';import * as reviewService from '../services/review.js';-import { buildQueue } from '../services/reviewQueue.js';+import { buildQueue, resolveQueueItem } from '../services/reviewQueue.js';const router = express.Router();@@ -48,6 +48,20 @@ router.get('/queue', asyncHandler(async (req, res) => {res.json(queue);}));+const resolveQueueSchema = z.object({+ id: z.string().min(1).max(500)+});++// POST /api/review/queue/resolve — accept/promote a single cross-domain queue+// row in place (mark a brain inbox item done, promote an Ask answer, approve a+// CoS task or message draft) without leaving the Review Hub. The `id` is the+// row's `<source>:<rawId>` — the service dispatches to that source's primitive.+router.post('/queue/resolve', asyncHandler(async (req, res) => {+ const { id } = validateRequest(resolveQueueSchema, req.body);+ const result = await resolveQueueItem(id);+ res.json(result);+}));+// POST /api/review/todo — create a user todorouter.post('/todo', asyncHandler(async (req, res) => {const data = validateRequest(createTodoSchema, req.body);diff --git a/server/services/reviewQueue.js b/server/services/reviewQueue.jsindex 66f6dea043..3460da0077 100644--- a/server/services/reviewQueue.js+++ b/server/services/reviewQueue.js@@ -14,8 +14,14 @@* { id, source, sourceLabel, title, summary, timestamp, severity, drillTo }** `drillTo` is a client route the UI deep-links to so "drill-down" works without- * the queue needing to know how to render each domain. v1 is read + drill-down;- * per-source accept/promote actions are a follow-up (see issue #709).+ * the queue needing to know how to render each domain.+ *+ * A producer may also declare an inline `action` (a verb label) + `resolve(rawId)`+ * primitive, in which case the row carries `action` and `resolveQueueItem()` can+ * accept/promote it in place without leaving the Review Hub (issue #709 follow-up+ * to the v1 read-only aggregator). Sources with no clean local resolve (health+ * alerts are live-computed and clear when the condition does; a failed backup+ * retries by re-running with settings) stay drill-down + session-dismiss only.*/import * as brain from './brain.js';@@ -24,6 +30,7 @@ import * as cosTaskStore from './cosTaskStore.js';import * as messageDrafts from './messageDrafts.js';import * as proactiveAlerts from './proactiveAlerts.js';import * as backup from './backup.js';+import { ServerError } from '../lib/errorHandler.js';// Per-source cap so one noisy producer can't flood the queue; the UI shows a// "+N more in <domain>" affordance via the per-source `total` vs `items.length`.@@ -59,6 +66,11 @@ const PRODUCERS = [source: 'brain',label: 'Brain inbox',drillTo: '/brain/inbox',+ // Marking the entry done clears it from the needs-review queue.+ action: 'Done',+ async resolve(id) {+ return brain.markInboxDone(id);+ },async gather() {// Inbox entries the auto-classifier couldn't place — they need a human// to pick a destination.@@ -80,6 +92,10 @@ const PRODUCERS = [source: 'ask',label: 'Ask answers',drillTo: '/ask',+ action: 'Promote',+ async resolve(id) {+ return askConversations.setPromoted(id, true);+ },async gather() {// Conversations with content that haven't been promoted to brain/task/goal.const convs = await askConversations.listConversations({ limit: PER_SOURCE_LIMIT * 2 });@@ -100,6 +116,14 @@ const PRODUCERS = [source: 'cos',label: 'CoS approvals',drillTo: '/cos/tasks',+ action: 'Approve',+ // approveTask resolves to an `{ error }` object (not a throw) when the task+ // can't be approved; surface that as a failed resolve.+ async resolve(id) {+ const result = await cosTaskStore.approveTask(id);+ if (result && result.error) throw new ServerError(result.error, { status: 409, code: 'CONFLICT' });+ return result;+ },async gather() {// Internal CoS tasks parked awaiting the user's approval before they run.const { awaitingApproval = [] } = await cosTaskStore.getCosTasks();@@ -120,6 +144,12 @@ const PRODUCERS = [source: 'drafts',label: 'Message drafts',drillTo: '/messages/drafts',+ // Approve (not send) — clears it from the awaiting-review queue without an+ // outward side effect; the user still triggers the actual send from /messages.+ action: 'Approve',+ async resolve(id) {+ return messageDrafts.approveDraft(id);+ },async gather() {// Drafts the user (or an AI) prepared that haven't been sent yet. Today// messageDrafts only emits 'draft' (vs 'approved'); 'pending_review' is@@ -130,7 +160,9 @@ const PRODUCERS = [},map(draft) {return {- id: `draft:${draft.id}`,+ // Prefix matches `source` ('drafts') so resolveQueueItem's+ // split-on-first-colon dispatch lands on this producer.+ id: `drafts:${draft.id}`,title: draft.status === 'pending_review' ? 'Draft awaiting review' : 'Unsent message draft',summary: draft.subject || (draft.body || '').slice(0, 120) || '(no subject)',timestamp: draft.updatedAt || draft.createdAt || null,@@ -198,11 +230,41 @@ async function gatherProducer(producer) {const items = list.slice(0, PER_SOURCE_LIMIT).map((item, index) => ({source: producer.source,sourceLabel: producer.label,- ...producer.map(item, index)+ ...producer.map(item, index),+ // Inline-action verb when the producer declares one resolve primitive; the+ // UI shows an accept/promote button only for rows that carry it.+ ...(producer.action && producer.resolve ? { action: producer.action } : {})}));return { items, total: list.length };}+const PRODUCERS_BY_SOURCE = Object.fromEntries(PRODUCERS.map(p => [p.source, p]));++/**+ * Accept/promote a single queue row in place. `queueItemId` is the row's+ * normalized id (`<source>:<rawId>`); we split on the FIRST colon so raw ids+ * that themselves contain colons survive. Throws a 4xx ServerError when the+ * source is unknown, has no inline resolve, or the underlying primitive can't+ * find the record — so the route surfaces a clean status instead of a 500.+ */+export async function resolveQueueItem(queueItemId) {+ const sep = String(queueItemId).indexOf(':');+ const source = sep === -1 ? queueItemId : queueItemId.slice(0, sep);+ const rawId = sep === -1 ? '' : queueItemId.slice(sep + 1);++ const producer = PRODUCERS_BY_SOURCE[source];+ if (!producer || !producer.resolve) {+ throw new ServerError(`No inline action for source "${source}"`, { status: 400, code: 'BAD_REQUEST' });+ }++ const result = await producer.resolve(rawId);+ // Most resolve primitives return null when the record is already gone.+ if (result === null || result === undefined) {+ throw new ServerError(`${producer.label} item not found: ${rawId}`, { status: 404, code: 'NOT_FOUND' });+ }+ return { source, id: queueItemId, resolved: true };+}+/*** Build the cross-domain review queue. Returns the normalized item list (sorted* by severity then recency), aggregate `counts`, and a `sources` map withdiff --git a/server/services/reviewQueue.test.js b/server/services/reviewQueue.test.jsindex c011ad73c1..c8e71ec8c3 100644--- a/server/services/reviewQueue.test.js+++ b/server/services/reviewQueue.test.js@@ -2,10 +2,10 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';// Mock every producer service the aggregator pulls from, so the test exercises// only the normalization / sort / cap / degrade-on-failure logic.-const brain = { getInboxLog: vi.fn() };-const askConversations = { listConversations: vi.fn() };-const cosTaskStore = { getCosTasks: vi.fn() };-const messageDrafts = { listDrafts: vi.fn() };+const brain = { getInboxLog: vi.fn(), markInboxDone: vi.fn() };+const askConversations = { listConversations: vi.fn(), setPromoted: vi.fn() };+const cosTaskStore = { getCosTasks: vi.fn(), approveTask: vi.fn() };+const messageDrafts = { listDrafts: vi.fn(), approveDraft: vi.fn() };const proactiveAlerts = { generateAlerts: vi.fn() };const backup = { getState: vi.fn() };@@ -16,7 +16,7 @@ vi.mock('./messageDrafts.js', () => messageDrafts);vi.mock('./proactiveAlerts.js', () => proactiveAlerts);vi.mock('./backup.js', () => backup);-const { buildQueue, __resetAlertsCache } = await import('./reviewQueue.js');+const { buildQueue, resolveQueueItem, __resetAlertsCache } = await import('./reviewQueue.js');// Default: every producer returns "nothing needs attention".function resetEmpty() {@@ -88,7 +88,7 @@ describe('reviewQueue.buildQueue', () => {expect(queue.items.find(i => i.id === 'cos:sys-1')).toMatchObject({ severity: 'high', drillTo: '/cos/tasks' });const draftRows = queue.items.filter(i => i.source === 'drafts');expect(draftRows).toHaveLength(1);- expect(draftRows[0].id).toBe('draft:d1');+ expect(draftRows[0].id).toBe('drafts:d1');});it('only surfaces critical/high health alerts and a failed backup', async () => {@@ -152,4 +152,63 @@ describe('reviewQueue.buildQueue', () => {expect(queue.sources.brain.total).toBe(40);expect(queue.sources.brain.shown).toBe(25);});++ it('tags resolvable rows with an inline action verb, leaves health/backup without one', async () => {+ brain.getInboxLog.mockResolvedValue([{ id: 'b1', capturedText: 'classify', capturedAt: '2026-06-03T10:00:00.000Z' }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1 }]);+ proactiveAlerts.generateAlerts.mockResolvedValue({ alerts: [{ type: 'disk', severity: 'critical', title: 'crit', detail: 'full', link: '/apps' }] });+ backup.getState.mockResolvedValue({ status: 'error', error: 'disk full' });+ const queue = await buildQueue();+ expect(queue.items.find(i => i.source === 'brain').action).toBe('Done');+ expect(queue.items.find(i => i.source === 'ask').action).toBe('Promote');+ // Live-computed / settings-driven sources have no inline resolve.+ expect(queue.items.find(i => i.source === 'health').action).toBeUndefined();+ expect(queue.items.find(i => i.source === 'backup').action).toBeUndefined();+ });+});++describe('reviewQueue.resolveQueueItem', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it('dispatches brain rows to markInboxDone', async () => {+ brain.markInboxDone.mockResolvedValue({ id: 'b1', status: 'done' });+ const result = await resolveQueueItem('brain:b1');+ expect(brain.markInboxDone).toHaveBeenCalledWith('b1');+ expect(result).toMatchObject({ source: 'brain', id: 'brain:b1', resolved: true });+ });++ it('dispatches ask rows to setPromoted(id, true)', async () => {+ askConversations.setPromoted.mockResolvedValue({ id: 'a1', promoted: true });+ await resolveQueueItem('ask:a1');+ expect(askConversations.setPromoted).toHaveBeenCalledWith('a1', true);+ });++ it('dispatches draft rows to approveDraft', async () => {+ messageDrafts.approveDraft.mockResolvedValue({ id: 'd1', status: 'approved' });+ await resolveQueueItem('drafts:d1');+ expect(messageDrafts.approveDraft).toHaveBeenCalledWith('d1');+ });++ it('preserves colons in the raw id (splits on the first only)', async () => {+ brain.markInboxDone.mockResolvedValue({ id: 'b:1:2', status: 'done' });+ await resolveQueueItem('brain:b:1:2');+ expect(brain.markInboxDone).toHaveBeenCalledWith('b:1:2');+ });++ it('rejects an unknown source with a 400', async () => {+ await expect(resolveQueueItem('health:x')).rejects.toMatchObject({ status: 400 });+ await expect(resolveQueueItem('nope:x')).rejects.toMatchObject({ status: 400 });+ });++ it('surfaces a 404 when the primitive returns null (record gone)', async () => {+ brain.markInboxDone.mockResolvedValue(null);+ await expect(resolveQueueItem('brain:missing')).rejects.toMatchObject({ status: 404 });+ });++ it('maps a CoS approve {error} result to a 409', async () => {+ cosTaskStore.approveTask.mockResolvedValue({ error: 'Task does not require approval' });+ await expect(resolveQueueItem('cos:sys-1')).rejects.toMatchObject({ status: 409 });+ });});