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

address review (codex): accept writersRoomWork over the peer-sync HTTP schemas + carry updatedAt in coverage (#1565)

[._.]/ Adam Eivy374a59bea8cf
diff --git a/server/lib/peerSyncValidation.js b/server/lib/peerSyncValidation.js
index e7ff831a24..6d7358810a 100644
--- a/server/lib/peerSyncValidation.js
+++ b/server/lib/peerSyncValidation.js
@@ -15,7 +15,7 @@ import { catalogSyncIngredientSchema, catalogSyncRefSchema } from './catalogVali
// subscriptions target another PortOS instance over Tailnet.
export const peerSubscribeSchema = z.object({
peerId: z.string().trim().min(1).max(120),
- recordKind: z.enum(['universe', 'series', 'mediaCollection', 'author', 'artist', 'album', 'track', 'creativeDirectorProject', 'moodBoard']),
+ recordKind: z.enum(['universe', 'series', 'mediaCollection', 'author', 'artist', 'album', 'track', 'creativeDirectorProject', 'moodBoard', 'writersRoomWork']),
recordId: z.string().trim().min(1).max(120),
}).strict();
@@ -198,6 +198,28 @@ const moodBoardPushSchema = z.object({
kind: z.literal('moodBoard'),
...peerSyncPushBase,
}).strict();
+// Writers Room works (#1565) push the bare work manifest (the decomposed
+// draft-version metadata rides inside the record's `drafts[]`). The file-primary
+// `.md` prose bodies do NOT ride `assetManifest` (which keys on a flat basename +
+// single dir per kind) — they ride a dedicated `draftBodyManifest` of per-draft
+// SHA-256 hashes the receiver diffs + pulls by nested `works/<workId>/drafts/<draftId>.md`
+// path. workId/draftId get a second-pass `WORK_ID_RE`/`DRAFT_ID_RE` scrub in the
+// service before any FS op; this schema just caps shape. `.strict()` rejects
+// smuggled bundle keys (same posture as author/creativeDirectorProject/moodBoard).
+const peerDraftBodyManifestEntrySchema = z.object({
+ kind: z.literal('writers-room-draft'),
+ workId: z.string().trim().min(1).max(120),
+ draftId: z.string().trim().min(1).max(120),
+ sha256: hex64,
+}).strict();
+const draftBodyManifestField = {
+ draftBodyManifest: z.array(peerDraftBodyManifestEntrySchema).max(2000).optional(),
+};
+const writersRoomWorkPushSchema = z.object({
+ kind: z.literal('writersRoomWork'),
+ ...peerSyncPushBase,
+ ...draftBodyManifestField,
+}).strict();
export const peerSyncPushSchema = z.discriminatedUnion('kind', [
universePushSchema,
seriesPushSchema,
@@ -208,13 +230,14 @@ export const peerSyncPushSchema = z.discriminatedUnion('kind', [
trackPushSchema,
creativeDirectorProjectPushSchema,
moodBoardPushSchema,
+ writersRoomWorkPushSchema,
]);
// Manual sync action schemas — used by POST /sync-record, /sync-now, /pull-metadata.
export const peerSyncRecordSchema = z.object({
peerId: z.string().trim().min(1).max(120),
- recordKind: z.enum(['universe', 'series', 'mediaCollection', 'author', 'artist', 'album', 'track', 'creativeDirectorProject', 'moodBoard']),
+ recordKind: z.enum(['universe', 'series', 'mediaCollection', 'author', 'artist', 'album', 'track', 'creativeDirectorProject', 'moodBoard', 'writersRoomWork']),
recordId: z.string().trim().min(1).max(200),
}).strict();
diff --git a/server/routes/peerSync.test.js b/server/routes/peerSync.test.js
index 05a33fcbac..08c4e80962 100644
--- a/server/routes/peerSync.test.js
+++ b/server/routes/peerSync.test.js
@@ -134,6 +134,30 @@ describe('peer-sync routes', () => {
}));
});
+ it('accepts a writersRoomWork push that bundles a draftBodyManifest', async () => {
+ // Regression: writersRoomWorkPushSchema is `.strict()`, so without the
+ // draftBodyManifest field (and without the kind in the discriminated
+ // union) the production body-bearing work push 400s at the Zod boundary
+ // before applyIncomingPush ever runs — the feature can't work over the API.
+ svc.applyIncomingPush.mockResolvedValue({ missingAssets: [], reverseSubscriptionCreated: false, ackedDeletesUpTo: 0 });
+ const res = await request(buildApp())
+ .post('/api/peer-sync/push')
+ .send({
+ kind: 'writersRoomWork',
+ record: { id: 'wr-work-1' },
+ assetManifest: [],
+ draftBodyManifest: [
+ { kind: 'writers-room-draft', workId: 'wr-work-1', draftId: 'wr-draft-1', sha256: 'a'.repeat(64) },
+ ],
+ sourceInstanceId: 'peer-a',
+ });
+ expect(res.status).toBe(200);
+ expect(svc.applyIncomingPush).toHaveBeenCalledWith(expect.objectContaining({
+ kind: 'writersRoomWork',
+ draftBodyManifest: expect.any(Array),
+ }));
+ });
+
it('400s when a universe push carries manuscriptReview (series-only field, no side-channel)', async () => {
const res = await request(buildApp())
.post('/api/peer-sync/push')
diff --git a/server/services/sharing/peerSync.js b/server/services/sharing/peerSync.js
index 9e053c2958..b897b7c355 100644
--- a/server/services/sharing/peerSync.js
+++ b/server/services/sharing/peerSync.js
@@ -111,7 +111,7 @@ import {
} from '../moodBoard/index.js';
import {
getWorkForSync,
- listWorkIdsForSync,
+ listWorksForSync,
mergeWorksFromSync,
buildWorkBodyManifest,
diffWorkBodyManifest,
@@ -508,11 +508,11 @@ async function listRecordsForKind(recordKind) {
} else if (recordKind === 'moodBoard') {
records = await listBoards({ includeDeleted: false }).catch(() => []);
} else if (recordKind === 'writersRoomWork') {
- // Live work ids → {id} stubs (the backfill/mirror-status callers only read
- // `id`); without this branch, enabling the writersRoomWorks category (or
- // full-sync) for a peer would backfill nothing and report zero pending works.
- const ids = await listWorkIdsForSync().catch(() => []);
- records = ids.map((id) => ({ id }));
+ // Live works as { id, updatedAt } (full-sync coverage compares updatedAt to
+ // detect a stale confirmed push; bare {id} stubs would report a changed
+ // manuscript as fully mirrored). Without this branch, enabling the
+ // writersRoomWorks category (or full-sync) would backfill nothing.
+ records = await listWorksForSync().catch(() => []);
}
return records.filter(r => r?.ephemeral !== true && isNonEmptyStr(r?.id));
}
diff --git a/server/services/writersRoom/sync.js b/server/services/writersRoom/sync.js
index 1e909dfda2..8bbe1a286b 100644
--- a/server/services/writersRoom/sync.js
+++ b/server/services/writersRoom/sync.js
@@ -36,6 +36,19 @@ export async function listWorkIdsForSync(options = {}) {
return store().listWorkIds(options);
}
+/**
+ * Live works as `{ id, updatedAt }` for the peer-sync backfill + full-sync
+ * coverage status. `updatedAt` is required by `getFullSyncCoverageForPeer` to
+ * detect a confirmed push gone stale — bare `{ id }` stubs would make every
+ * old confirmation look fresh and report a changed manuscript as fully mirrored.
+ */
+export async function listWorksForSync() {
+ const works = await store().listWorks();
+ return works
+ .filter((w) => w && typeof w.id === 'string')
+ .map((w) => ({ id: w.id, updatedAt: w.updatedAt }));
+}
+
/** Merge an incoming batch of work records from a peer (LWW, tombstone-aware). */
export async function mergeWorksFromSync(remoteWorks, options = {}) {
return store().mergeWorksFromSync(remoteWorks, options);