The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Merge batch 11-03 br: #2715 (#2725)
0xken158c3fe9a80ddb
diff --git a/backend/integration/communityReports.test.ts b/backend/integration/communityReports.test.tsnew file mode 100644index 000000000..0d6c3155f--- /dev/null+++ b/backend/integration/communityReports.test.ts@@ -0,0 +1,89 @@+import { randomUUID } from 'node:crypto'+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'+import type { MongoMemoryReplSet } from 'mongodb-memory-server-core'+import type { PrismaClient } from '@prisma/client'+import { planDatabase } from './plans.test-support.js'++// #2299: three reports hid a Hub item only from each reporter. The hide row was created without `restoredAt`, and on Mongo+// `restoredAt: null` matches only an explicit null, so every other reader still saw it while the review queue said hidden.+const shared = vi.hoisted(() => ({ db: null as unknown as PrismaClient }))+vi.mock('../src/lib/prisma.js', async original => ({ ...await original<typeof import('../src/lib/prisma.js')>(), get prisma() { return shared.db } }))+const { fileReport, hiddenFrom, isHiddenFrom } = await import('../src/lib/communityReports.js')++let replica: MongoMemoryReplSet+let db: PrismaClient+const env = 'prod'++beforeAll(async () => {+ ({ replica, db } = await planDatabase('community_reports_test'))+ shared.db = db+})+afterAll(async () => {+ await db?.$disconnect()+ await replica?.stop()+})++const report = (targetType: 'harness' | 'comment', targetId: string, harnessId: string, userId: string) =>+ fileReport({ autonomousEnv: env, targetType, targetId, harnessId, userId, reason: 'spam' })++/** Whether anonymous readers and a stranger are both kept from [targetId], by both readers of the hidden list. */+async function hiddenFromEveryone(targetType: 'harness' | 'comment', targetId: string, harnessId?: string) {+ return {+ anonymous: await isHiddenFrom(env, targetType, targetId),+ stranger: await isHiddenFrom(env, targetType, targetId, 'stranger'),+ anonymousList: (await hiddenFrom(env, targetType, undefined, harnessId)).includes(targetId),+ strangerList: (await hiddenFrom(env, targetType, 'stranger', harnessId)).includes(targetId),+ }+}+const everyone = { anonymous: true, stranger: true, anonymousList: true, strangerList: true }+const nobody = { anonymous: false, stranger: false, anonymousList: false, strangerList: false }++describe('community reports on Mongo', () => {+ it('three reports hide a harness from readers who did not report it', async () => {+ const harness = randomUUID()+ for (const reader of ['r1', 'r2', 'r3']) await report('harness', harness, harness, reader)+ expect(await hiddenFromEveryone('harness', harness)).toEqual(everyone)+ })++ it('the hide row three reports write stores restoredAt as an explicit null', async () => {+ const harness = randomUUID()+ for (const reader of ['r1', 'r2', 'r3']) await report('harness', harness, harness, reader)+ expect(await db.$runCommandRaw({ count: 'community_hidden', query: { targetId: harness, restoredAt: { $type: 'null' } } })).toMatchObject({ n: 1 })+ })++ it('three reports hide a comment from readers who did not report it', async () => {+ const harness = randomUUID(), comment = randomUUID()+ for (const reader of ['r1', 'r2', 'r3']) await report('comment', comment, harness, reader)+ expect(await hiddenFromEveryone('comment', comment)).toEqual(everyone)+ expect(await hiddenFromEveryone('comment', comment, harness)).toEqual(everyone)+ expect((await hiddenFrom(env, 'comment', undefined, randomUUID())).includes(comment)).toBe(false)+ })++ it('a hide row stored without restoredAt, as before the fix, hides it too', async () => {+ const harness = randomUUID(), comment = randomUUID()+ await db.$runCommandRaw({ insert: 'community_hidden', documents: [+ { autonomousEnv: env, targetType: 'harness', targetId: harness, harnessId: harness, createdAt: { $date: new Date().toISOString() } },+ { autonomousEnv: env, targetType: 'comment', targetId: comment, harnessId: harness, createdAt: { $date: new Date().toISOString() } },+ ] })+ expect(await db.$runCommandRaw({ count: 'community_hidden', query: { targetId: { $in: [harness, comment] }, restoredAt: { $exists: true } } }))+ .toMatchObject({ n: 0 })+ expect(await hiddenFromEveryone('harness', harness)).toEqual(everyone)+ expect(await hiddenFromEveryone('comment', comment, harness)).toEqual(everyone)+ })++ it('two reports hide it only from the readers who reported it', async () => {+ const harness = randomUUID()+ for (const reader of ['r1', 'r2']) await report('harness', harness, harness, reader)+ expect(await hiddenFromEveryone('harness', harness)).toEqual(nobody)+ expect(await isHiddenFrom(env, 'harness', harness, 'r1')).toBe(true)+ expect(await hiddenFrom(env, 'harness', 'r2')).toContain(harness)+ })++ it('a restored item is shown again until three new reports', async () => {+ const harness = randomUUID()+ await db.communityHidden.create({ data: { autonomousEnv: env, targetType: 'harness', targetId: harness, harnessId: harness, restoredAt: new Date(Date.now() - 1000) } })+ expect(await hiddenFromEveryone('harness', harness)).toEqual(nobody)+ for (const reader of ['r1', 'r2', 'r3']) await report('harness', harness, harness, reader)+ expect(await hiddenFromEveryone('harness', harness)).toEqual(everyone)+ })+})diff --git a/backend/src/lib/communityReports.ts b/backend/src/lib/communityReports.tsindex 18ca9dde5..b7487e8c7 100644--- a/backend/src/lib/communityReports.ts+++ b/backend/src/lib/communityReports.ts@@ -1,3 +1,4 @@+import type { Prisma } from '@prisma/client'import { env } from '../config/env.js'import { logger } from '../utils/logger.js'import { prisma } from './prisma.js'@@ -9,6 +10,10 @@ export type ReportTarget = typeof communityReportTargets[number]/** Reports from this many readers hide a publication or comment from everyone until a review. */export const hideAfterReports = 3+/** Hidden and not restored since. Rows hidden before #2299 have no `restoredAt` at all, and on Mongo+ * `restoredAt: null` matches only an explicit null (lib/prisma.ts), so the filter accepts both. */+const notRestored: Prisma.CommunityHiddenWhereInput = { OR: [{ restoredAt: null }, { restoredAt: { isSet: false } }] }+/*** The ids of [targetType] a reader is not shown: whatever reports have hidden from everyone, and* whatever they reported themselves (hidden from them at once). [harnessId] narrows to one harness's.@@ -16,7 +21,7 @@ export const hideAfterReports = 3export async function hiddenFrom(autonomousEnv: string, targetType: ReportTarget, userId?: string, harnessId?: string): Promise<string[]> {const scope = { autonomousEnv, targetType, ...(harnessId ? { harnessId } : {}) }const [hidden, reported] = await Promise.all([- prisma.communityHidden.findMany({ where: { ...scope, restoredAt: null }, select: { targetId: true } }),+ prisma.communityHidden.findMany({ where: { ...scope, ...notRestored }, select: { targetId: true } }),userId ? prisma.communityReport.findMany({ where: { ...scope, userId }, select: { targetId: true } }) : [],])return [...new Set([...hidden, ...reported].map(row => row.targetId))]@@ -25,7 +30,7 @@ export async function hiddenFrom(autonomousEnv: string, targetType: ReportTarget/** Whether one publication or comment is hidden from this reader. */export async function isHiddenFrom(autonomousEnv: string, targetType: ReportTarget, targetId: string, userId?: string): Promise<boolean> {const [hidden, reported] = await Promise.all([- prisma.communityHidden.findFirst({ where: { autonomousEnv, targetType, targetId, restoredAt: null }, select: { id: true } }),+ prisma.communityHidden.findFirst({ where: { autonomousEnv, targetType, targetId, ...notRestored }, select: { id: true } }),userId ? prisma.communityReport.findFirst({ where: { autonomousEnv, targetType, targetId, userId }, select: { id: true } }) : null,])return !!hidden || !!reported@@ -63,7 +68,7 @@ export async function fileReport(report: Report): Promise<void> {if (reviewed && !reviewed.restoredAt) returnconst since = reviewed?.restoredAt ? { createdAt: { gt: reviewed.restoredAt } } : {}if (await prisma.communityReport.count({ where: { ...key, ...since } }) < hideAfterReports) return- await prisma.communityHidden.upsert({ where: { autonomousEnv_targetType_targetId: key }, create: { ...key, harnessId }, update: { restoredAt: null, createdAt: new Date() } })+ await prisma.communityHidden.upsert({ where: { autonomousEnv_targetType_targetId: key }, create: { ...key, harnessId, restoredAt: null }, update: { restoredAt: null, createdAt: new Date() } })logger.info('community target hidden after reports', key)await tellReviewers(targetType, targetId)}diff --git a/backend/src/routes/community.test.ts b/backend/src/routes/community.test.tsindex 7bf673356..94aa6ae98 100644--- a/backend/src/routes/community.test.ts+++ b/backend/src/routes/community.test.ts@@ -18,7 +18,7 @@ const db = vi.hoisted(() => {if ('gt' in filter) return (row[key] as Date) > (filter.gt as Date)if ('lt' in filter) return (row[key] as number | Date) < (filter.lt as number | Date)if ('gte' in filter) return (row[key] as number | Date) >= (filter.gte as number | Date)- if ('isSet' in filter || 'not' in filter) return (!filter.isSet || row[key] !== undefined) && (!('not' in filter) || row[key] !== filter.not)+ if ('isSet' in filter || 'not' in filter) return (!('isSet' in filter) || filter.isSet === (row[key] !== undefined)) && (!('not' in filter) || row[key] !== filter.not)return matches(row, filter)}return value instanceof Date ? (row[key] as Date)?.getTime() === value.getTime() : row[key] === value@@ -82,7 +82,7 @@ const db = vi.hoisted(() => {}}return { communityHarness: table({ defaults: { likeCount: 0 } }), communityLike: table({ unique: ['autonomousEnv', 'harnessId', 'userId'] }), communityComment: table(), communityFollow: table(),- communityReport: table({ unique: ['autonomousEnv', 'targetType', 'targetId', 'userId'] }), communityHidden: table({ defaults: { restoredAt: null } }), communityNotification: table(), user: { findUnique: vi.fn(async ({ where }: { where: { id: string } }) => ({ name: where.id === 'alice' ? 'Alice' : 'Bob' })) } }+ communityReport: table({ unique: ['autonomousEnv', 'targetType', 'targetId', 'userId'] }), communityHidden: table(), communityNotification: table(), user: { findUnique: vi.fn(async ({ where }: { where: { id: string } }) => ({ name: where.id === 'alice' ? 'Alice' : 'Bob' })) } }})vi.mock('../lib/prisma.js', () => ({ prisma: db }))import { communityRoutes, publicationSchema } from './community.js'diff --git a/backend/vitest.super-tabs.config.ts b/backend/vitest.super-tabs.config.tsindex aca32dbc4..ee852b029 100644--- a/backend/vitest.super-tabs.config.ts+++ b/backend/vitest.super-tabs.config.ts@@ -8,5 +8,5 @@ export default defineConfig({ test: { include: ['integration/superTabs.test.ts','integration/superTabBuddyProbes.test.ts', 'integration/superTabBuddySessions.test.ts', 'integration/superTabSwarmBuddy.test.ts', 'integration/superTabCosts.test.ts', 'integration/harnessSharesList.test.ts', 'integration/atlasSnapshot.test.ts', 'integration/queryStats.test.ts','integration/superTabEvidence.test.ts', 'integration/superTabAttemptModels.test.ts', 'integration/superTabNamedReads.test.ts', 'integration/swarmSweepPlans.test.ts', 'integration/workerIndexPlans.test.ts', 'integration/superTabReflection.test.ts','integration/superTabMessagePages.test.ts', 'integration/superTabDeliveryCompaction.test.ts', 'integration/superTabNoticeDigest.test.ts', 'integration/superTabCommandLoads.test.ts', 'integration/superTabThreads.test.ts', 'integration/superTabMachineRemovals.test.ts',- 'integration/superTabInstructions.test.ts', 'integration/superTabWorkflow.test.ts', 'integration/superTabTaskLines.test.ts', 'integration/superTabDeletion.test.ts'], hookTimeout: 120000, testTimeout: 30000, setupFiles: ['integration/cacheOn.test-support.ts', 'src/lib/noRedis.test-support.ts'],+ 'integration/superTabInstructions.test.ts', 'integration/superTabWorkflow.test.ts', 'integration/superTabTaskLines.test.ts', 'integration/superTabDeletion.test.ts', 'integration/communityReports.test.ts'], hookTimeout: 120000, testTimeout: 30000, setupFiles: ['integration/cacheOn.test-support.ts', 'src/lib/noRedis.test-support.ts'],fileParallelism: false, env: { NODE_ENV: 'test', HARNESS_CREDENTIAL_ENCRYPTION_KEY: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=' } } })diff --git a/docs/plans/2026-11-03-hub-reports-hide-plan.md b/docs/plans/2026-11-03-hub-reports-hide-plan.mdnew file mode 100644index 000000000..abf35f559--- /dev/null+++ b/docs/plans/2026-11-03-hub-reports-hide-plan.md@@ -0,0 +1,74 @@+# Hub: three reports hide an item from everyone — Implementation Plan++> **For agentic workers:** this plan is carried out by the task's Engineer, task by task, test first, as the project's+> instructions (Engineer role) say. Steps use checkbox (`- [ ]`) syntax for tracking.++**Goal:** A harness or comment that three readers reported is hidden from every reader, including rows of+`community_hidden` written before the fix (no `restoredAt` field at all).++**Architecture:** `fileReport` creates the hide row with `restoredAt: null` written out, and the two readers+(`hiddenFrom`, `isHiddenFrom`) filter on "not restored" as null **or** absent, the `machineAlive` pattern of+`lib/prisma.ts`, so old rows need no migration. The route unit tests' fake table stops supplying `restoredAt: null`,+so it shows Mongo's behavior; a new integration test runs the same flow on a real Mongo replica set.++**Tech Stack:** TypeScript, Prisma (MongoDB), Vitest, mongodb-memory-server (`planDatabase`).++**Spec:** Task #2299 brief (Super Tab conversation f90ee44a6662554cfaa30431), requested by [email protected].++## Global Constraints++- PR body first line: "Requested by [email protected] through Harness."+- Before Ready: a test that fails without the fix for every risk named, red/green evidence in a PR comment, and the+ full Super Tab integration suite (`npm run test:super-tabs` in backend/).+- Never run a test that signs the Mac out of the real CLI. Stop only processes you started, by id. Temp files only in+ mktemp -d folders.+- Owns: backend/src/lib/communityReports.ts, backend/src/routes/community.test.ts, backend/integration. One line in+ backend/vitest.super-tabs.config.ts adds the new test file to the suite.++## Review Focus++- A restored row (`restoredAt` a date) must stay visible: the "absent" branch must not match it (`isSet: false` only).+- A reporter still stops seeing what they reported at once, before the third report.+- After a restore, three new reports hide it again (the upsert's update path), and older reports don't count.+- `hiddenFrom` scoped to one harness (`harnessId`) lists a hidden comment on that harness and not one on another.+- A hide row without `restoredAt` in a later report: `fileReport` treats it as hidden (returns early, no second Slack+ post) — it already does, since Prisma reads the absent field as null.++---++### Task 1: Hidden from everyone, on real Mongo++**Files:**+- Create: `backend/integration/communityReports.test.ts`+- Modify: `backend/vitest.super-tabs.config.ts` (add the file to `include`)+- Modify: `backend/src/lib/communityReports.ts:16-32` (readers), `:66` (create)+- Modify: `backend/src/routes/community.test.ts:21` (fake `isSet: false` matches only an absent field), `:85` (drop+ `defaults: { restoredAt: null }` from `communityHidden`)++**Interfaces:**+- Consumes: `planDatabase(prefix)` from `integration/plans.test-support.ts`; `fileReport`, `hiddenFrom`,+ `isHiddenFrom` from `src/lib/communityReports.ts` (signatures unchanged).+- Produces: nothing new for other code; a module-private `notRestored` where-input+ (`{ OR: [{ restoredAt: null }, { restoredAt: { isSet: false } }] }`).++- [x] **Step 1: Write the failing integration test** — `src/lib/prisma.js` mocked to the `planDatabase` client (the+ `harnessSharesList.test.ts` pattern). Cases:+ - `three reports hide a harness from readers who did not report it`: r1, r2, r3 report harness `h1`;+ `isHiddenFrom(env, 'harness', 'h1')` and `(…, 'h1', 'stranger')` are `true`; `hiddenFrom(env, 'harness')` and+ `(…, 'stranger')` contain `h1`.+ - `three reports hide a comment from readers who did not report it`: the same for comment `c1` on `h1`, and+ `hiddenFrom(env, 'comment', undefined, 'h1')` contains `c1`.+ - `a hide row stored without restoredAt hides it too`: raw insert into `community_hidden` with no `restoredAt`;+ anonymous and stranger see it hidden in both readers.+ - `the hide row three reports write stores restoredAt as an explicit null` (raw `$type: 'null'` count is 1): pins+ change (1), which the readers' fix alone would otherwise hide.+ - `two reports hide it only from those who reported it`: anonymous and r3 not hidden; r1 hidden.+ - `a restored item is shown until three new reports`: restored row (date) is visible; three later reports hide it.+- [x] **Step 2: Run it, watch it fail** — `npx vitest run --config vitest.super-tabs.config.ts integration/communityReports.test.ts`.+ Expected: the three "hide" cases FAIL (`expected false to be true`), the others pass.+- [x] **Step 3: Make the route unit fake honest** — fake `isSet: false` matches only `undefined`; drop the+ `restoredAt` default. Run `npx vitest run src/routes/community.test.ts`: expect the report-hiding cases to FAIL as on Mongo.+- [x] **Step 4: Commit the failing tests.**+- [x] **Step 5: Fix `communityReports.ts`** — `notRestored` in both readers; `create: { ...key, harnessId, restoredAt: null }`.+- [x] **Step 6: Run both test files, then `npm test` and `npm run test:super-tabs`.** Expected: all PASS.+- [x] **Step 7: Commit the fix; post red/green evidence as a PR comment.**