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

fix: dismiss retired CoS review alerts

[._.]/ Adam Eivybd38a8b6b4b0
diff --git a/scripts/migrations/401-dismiss-retired-cos-review-alerts.js b/scripts/migrations/401-dismiss-retired-cos-review-alerts.js
new file mode 100644
index 0000000000..1f05a7939d
--- /dev/null
+++ b/scripts/migrations/401-dismiss-retired-cos-review-alerts.js
@@ -0,0 +1,77 @@
+/**
+ * Dismiss pending Review Hub items from the retired `task:ready` bridge.
+ *
+ * The old bridge created a `type: 'cos'` review item for every task ready to
+ * spawn, including tasks whose description began with the generated SWARM MODE
+ * prompt. That bridge no longer exists; the live CoS approval producer is the
+ * authoritative source now. Existing bridge records otherwise remain visible
+ * as "Stored review obligations" and can offer an approve action for work that
+ * is not actually awaiting approval.
+ *
+ * Match the old record shape rather than every `type: 'cos'` item so a future
+ * producer can keep using the review store without being swept up by this
+ * compatibility cleanup. Dismiss instead of deleting so the old records stay
+ * auditable while disappearing from pending action projections.
+ */
+
+import { readFile } from 'fs/promises';
+import { join } from 'path';
+import { atomicWrite } from '../../server/lib/fileUtils.js';
+
+const ITEMS_REL = join('data', 'review', 'items.json');
+
+const hasReference = (value) => (
+ (typeof value === 'string' && value.trim().length > 0)
+ || (typeof value === 'number' && Number.isFinite(value))
+);
+
+export const isRetiredCosReviewAlert = (item) => {
+ const metadata = item?.metadata;
+ return item?.type === 'cos'
+ && item?.status === 'pending'
+ && metadata
+ && typeof metadata === 'object'
+ && !Array.isArray(metadata)
+ && hasReference(metadata.taskId)
+ && hasReference(metadata.referenceId)
+ && metadata.category == null
+ && metadata.actionKind == null
+ && metadata.sourceOwned !== true;
+};
+
+export default {
+ async up({ rootDir }) {
+ const path = join(rootDir, ITEMS_REL);
+ const raw = await readFile(path, 'utf-8').catch((error) => {
+ if (error.code === 'ENOENT') return null;
+ throw error;
+ });
+ if (raw === null) return { dismissed: 0, reason: 'no-file' };
+
+ let items;
+ try {
+ items = JSON.parse(raw);
+ } catch {
+ console.warn('⚠️ Review alerts: items file is not valid JSON — skipping retired CoS cleanup');
+ return { dismissed: 0, reason: 'unparseable' };
+ }
+ if (!Array.isArray(items)) {
+ console.warn('⚠️ Review alerts: items file is not an array — skipping retired CoS cleanup');
+ return { dismissed: 0, reason: 'unexpected-shape' };
+ }
+
+ const now = new Date().toISOString();
+ let dismissed = 0;
+ const next = items.map((item) => {
+ if (!isRetiredCosReviewAlert(item)) return item;
+ dismissed++;
+ return { ...item, status: 'dismissed', updatedAt: now };
+ });
+
+ if (dismissed === 0) return { dismissed: 0 };
+
+ await atomicWrite(path, `${JSON.stringify(next, null, 2)}\n`);
+ console.log(`🧹 Review alerts: dismissed ${dismissed} retired CoS alert(s)`);
+ return { dismissed };
+ },
+};
diff --git a/scripts/migrations/401-dismiss-retired-cos-review-alerts.test.js b/scripts/migrations/401-dismiss-retired-cos-review-alerts.test.js
new file mode 100644
index 0000000000..f948d1caf5
--- /dev/null
+++ b/scripts/migrations/401-dismiss-retired-cos-review-alerts.test.js
@@ -0,0 +1,99 @@
+import { afterEach, describe, expect, it } from 'vitest';
+import { mkdtemp, mkdir, readFile, rm, writeFile } from 'fs/promises';
+import { tmpdir } from 'os';
+import { join } from 'path';
+import migration, { isRetiredCosReviewAlert } from './401-dismiss-retired-cos-review-alerts.js';
+
+const ITEMS_REL = join('data', 'review', 'items.json');
+
+let rootDir;
+
+const seed = async (items) => {
+ await mkdir(join(rootDir, 'data', 'review'), { recursive: true });
+ await writeFile(join(rootDir, ITEMS_REL), JSON.stringify(items, null, 2));
+};
+
+const readItems = async () => JSON.parse(await readFile(join(rootDir, ITEMS_REL), 'utf-8'));
+
+const retiredAlert = (overrides = {}) => ({
+ id: 'review-1',
+ type: 'cos',
+ title: '# ⚡ SWARM MODE — claim and ship up to 6 independent issues in parallel',
+ description: 'Claim and ship the selected issues.',
+ status: 'pending',
+ metadata: { taskId: 'task-1', referenceId: 'task-1' },
+ createdAt: '2026-09-20T10:00:00.000Z',
+ updatedAt: '2026-09-20T10:00:00.000Z',
+ ...overrides,
+});
+
+afterEach(async () => {
+ if (rootDir) await rm(rootDir, { recursive: true, force: true });
+ rootDir = null;
+});
+
+describe('migration 401 — dismiss retired CoS review alerts', () => {
+ it('dismisses pending records from the retired task-ready bridge', async () => {
+ rootDir = await mkdtemp(join(tmpdir(), 'portos-migration-401-'));
+ await seed([
+ retiredAlert(),
+ retiredAlert({ id: 'review-2', title: 'Ordinary task description' }),
+ { id: 'todo-1', type: 'todo', status: 'pending', title: 'Keep this todo' },
+ ]);
+
+ const result = await migration.up({ rootDir });
+
+ expect(result.dismissed).toBe(2);
+ const items = await readItems();
+ expect(items[0]).toMatchObject({ status: 'dismissed', updatedAt: expect.any(String) });
+ expect(items[1]).toMatchObject({ status: 'dismissed' });
+ expect(items[2]).toMatchObject({ status: 'pending', title: 'Keep this todo' });
+ });
+
+ it('preserves already-triaged and future-shaped CoS records', async () => {
+ rootDir = await mkdtemp(join(tmpdir(), 'portos-migration-401-'));
+ await seed([
+ retiredAlert({ id: 'completed', status: 'completed' }),
+ retiredAlert({ id: 'dismissed', status: 'dismissed' }),
+ retiredAlert({ id: 'categorized', metadata: { taskId: 'task-2', referenceId: 'task-2', category: 'task-approval' } }),
+ retiredAlert({ id: 'source-owned', metadata: { taskId: 'task-3', referenceId: 'task-3', sourceOwned: true } }),
+ ]);
+
+ const result = await migration.up({ rootDir });
+
+ expect(result).toEqual({ dismissed: 0 });
+ expect((await readItems()).map((item) => item.status)).toEqual([
+ 'completed', 'dismissed', 'pending', 'pending',
+ ]);
+ });
+
+ it('is idempotent and does not rewrite an install with no matching records', async () => {
+ rootDir = await mkdtemp(join(tmpdir(), 'portos-migration-401-'));
+ await seed([{ id: 'todo-1', type: 'todo', status: 'pending', title: 'Keep this todo' }]);
+ const before = await readFile(join(rootDir, ITEMS_REL), 'utf-8');
+
+ expect(await migration.up({ rootDir })).toEqual({ dismissed: 0 });
+ expect(await readFile(join(rootDir, ITEMS_REL), 'utf-8')).toBe(before);
+ });
+
+ it('fails closed on missing or malformed review data', async () => {
+ rootDir = await mkdtemp(join(tmpdir(), 'portos-migration-401-'));
+ expect(await migration.up({ rootDir })).toEqual({ dismissed: 0, reason: 'no-file' });
+
+ await mkdir(join(rootDir, 'data', 'review'), { recursive: true });
+ await writeFile(join(rootDir, ITEMS_REL), '{not json');
+ expect(await migration.up({ rootDir })).toEqual({ dismissed: 0, reason: 'unparseable' });
+ expect(await readFile(join(rootDir, ITEMS_REL), 'utf-8')).toBe('{not json');
+
+ await writeFile(join(rootDir, ITEMS_REL), JSON.stringify({ items: [] }));
+ expect(await migration.up({ rootDir })).toEqual({ dismissed: 0, reason: 'unexpected-shape' });
+ });
+});
+
+describe('isRetiredCosReviewAlert', () => {
+ it('requires the old task-ready metadata shape', () => {
+ expect(isRetiredCosReviewAlert(retiredAlert())).toBe(true);
+ expect(isRetiredCosReviewAlert(retiredAlert({ metadata: { taskId: 'task-1' } }))).toBe(false);
+ expect(isRetiredCosReviewAlert(retiredAlert({ metadata: { taskId: 'task-1', referenceId: 'task-1', category: 'task-approval' } }))).toBe(false);
+ });
+});