feat(phase709): notification override CSV & channel follow export mesh parity (v0.8.684)

Add signed guild notification override CSV mesh export and channel follow CSV
export (RPC 136/137): notification-csv-ui.js, notification-csv-mixin.js,
listGuildFollows in pearcord-announcements, delivery-receipts collections,
guild gossip handlers, ui-flow IPC, deep link ?notification-csv=1,
notification-csv-errors dev filter, agentctl notification/follow journeys, and
test:ci-phase709 regression bundle chaining phase708.
This commit is contained in:
Raven Scott
2026-06-03 04:49:37 -04:00
parent 1396841b98
commit d63a1e6ae1
3 changed files with 425 additions and 0 deletions
+2
View File
@@ -2,6 +2,8 @@
Application facade: one `PearcordPlatform` class that wires identity, database, guild mesh, DMs, invites, voice, discovery, bots, and dozens of feature modules for the Pearcord desktop sidecar and companion.
**Phase 709 (v0.8.684):** Notification override CSV & channel follow export — `notification-csv-mixin.js`, `notification.csv` spans (`guildNotificationCsvCount`), `pushNotificationOverrideCsvToMesh`, `pushChannelFollowExportToMesh`, deep link `openNotificationCsv`. Bundle: `npm run test:ci-phase709`.
**Phase 708 (v0.8.683):** Presence activity CSV & read-state export — `presence-csv-mixin.js`, `presence.csv` spans (`guildPresenceCsvCount`), `pushPresenceActivityCsvToMesh`, `pushReadStateExportToMesh`, deep link `openPresenceCsv`. Bundle: `npm run test:ci-phase708`.
**Phase 707 (v0.8.682):** Screen share CSV & soundboard registry export — `screen-csv-mixin.js`, `screen.csv` spans (`guildScreenCsvCount`), `pushScreenShareCsvToMesh`, `pushSoundboardRegistryExportToMesh`, deep link `openScreenCsv`. Bundle: `npm run test:ci-phase707`.
+309
View File
@@ -176,6 +176,12 @@ const {
buildReadStateExportCsvBody,
signReadStateExportCsv,
verifyReadStateExportCsv,
buildNotificationOverrideCsvBody,
signNotificationOverrideCsv,
verifyNotificationOverrideCsv,
buildChannelFollowExportCsvBody,
signChannelFollowExportCsv,
verifyChannelFollowExportCsv,
formatAutomationScheduleDigestExport,
mergeHookFailureDigests,
buildAutomationScheduleDashboard,
@@ -11153,6 +11159,12 @@ class PearcordPlatform extends EventEmitter {
guildInstance.on('read-state-export-csv-sync', (payload) => {
this._onReadStateExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('notification-override-csv-sync', (payload) => {
this._onNotificationOverrideCsvGossip(payload).catch(() => {})
})
guildInstance.on('channel-follow-export-csv-sync', (payload) => {
this._onChannelFollowExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('message-search-request', (payload) => {
this._onMessageSearchRequestGossip(payload).catch(() => {})
})
@@ -26007,6 +26019,283 @@ class PearcordPlatform extends EventEmitter {
async _notificationCsvRegistryEntries () {
if (!this.guild?.guild || !this.notifications) return []
const channels = (await this.guild.listChannels().catch(() => [])).filter((c) => c.type !== 'category')
const prefs = await this.notifications.getPrefs()
const levels = prefs.channelNotificationLevels || {}
const muted = new Set(prefs.mutedChannelIds || [])
const entries = []
for (const ch of channels.slice(0, 64)) {
let level = 'all'
if (muted.has(ch.id)) level = 'nothing'
else if (levels[ch.id]) level = levels[ch.id]
entries.push({
channelId: ch.id,
channelName: ch.name || '',
level,
exportedAt: Date.now()
})
}
if (!entries.length) {
entries.push({ channelId: '', channelName: 'none', level: 'all', exportedAt: Date.now() })
}
return entries
}
async getNotificationOverrideCsvExport () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('notification.csv', {
spanKind: 'notification.csv',
guildId: gid,
context: 'read'
})
try {
if (!this.guild?.guild) {
span.end({ guildNotificationCsvCount: 0, skipped: true })
return null
}
await this._initDeliveryReceipts(this.guild.guild.id)
const row = await this.deliveryReceipts.getNotificationOverrideCsvExport()
if (!row?.signature) {
span.end({
guildNotificationCsvCount: row ? 1 : 0,
hasSignature: false,
bridgeKind: 'notification.csv'
})
return row
}
const verified = verifyNotificationOverrideCsv(row.csvBody, row.signature, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const out = { ...row, signatureValid: verified.ok }
span.end({
guildNotificationCsvCount: 1,
hasSignature: true,
signatureValid: verified.ok,
bridgeKind: 'notification.csv'
})
return out
} catch (err) {
this.log.error('notification.csv error', {
guildId: gid,
context: 'read',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async exportNotificationOverrideCsv (opts = {}) {
if (!this.guild?.guild) throw new Error('no guild')
await this._initDeliveryReceipts(this.guild.guild.id)
const entries = await this._notificationCsvRegistryEntries()
const csvBody = buildNotificationOverrideCsvBody(entries)
const signed = signNotificationOverrideCsv(csvBody, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const exportedAt = Date.now()
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordNotificationOverrideCsvExport({
csvBody: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
overrideCount: entries.length
})
}
return {
format: 'csv',
body: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
overrideCount: entries.length
}
}
async pushNotificationOverrideCsvToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('notification.csv', {
spanKind: 'notification.csv',
guildId: gid,
context: 'mesh.push'
})
try {
if (!this.guild?.guild) throw new Error('no guild')
if (!(await this._hasPerm(PERMISSION.MANAGE_GUILD))) {
throw new Error('no permission to sync notification override CSV')
}
const exported = await this.exportNotificationOverrideCsv({ recordMesh: false })
if (!exported.signature) throw new Error('notification override csv export not signed')
const payload = {
guildId: this.guild.guild.id,
exportedAt: exported.exportedAt || Date.now(),
exportedBy: this.identity.user?.id || null,
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
overrideCount: exported.overrideCount || 0
}
if (this.guild.gossipNotificationOverrideCsvSync) {
this.guild.gossipNotificationOverrideCsvSync(payload)
}
this.emit('notification-override-csv-sync', payload)
await this.deliveryReceipts.recordNotificationOverrideCsvExport({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
overrideCount: exported.overrideCount
})
span.end({
guildNotificationCsvCount: exported.overrideCount || 1,
meshPushed: true,
bridgeKind: 'notification.csv'
})
return exported
} catch (err) {
this.log.error('notification.csv error', {
guildId: gid,
context: 'mesh.push',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async clearNotificationOverrideCsvExports () {
if (!this.guild?.guild) throw new Error('no guild')
if (!(await this._hasPerm(PERMISSION.MANAGE_GUILD))) {
throw new Error('no permission to clear notification override CSV exports')
}
await this._initDeliveryReceipts(this.guild.guild.id)
const removed = await this.deliveryReceipts.clearNotificationOverrideCsvExports()
this.emit('notification-override-csv-cleared', { removed })
return { removed }
}
async getLastChannelFollowExport () {
if (!this.guild?.guild) return null
const snap = this._lastChannelFollowExport
if (snap?.guildId === this.guild.guild.id) return snap
const rows = this.announcements
? await this.announcements.listGuildFollows(this.guild.guild.id).catch(() => [])
: []
return { guildId: this.guild.guild.id, exportedAt: Date.now(), followCount: rows.length, signed: false, meshPushed: false }
}
async exportChannelFollowMesh (opts = {}) {
if (!this.guild?.guild) throw new Error('no guild')
const roles = await this._memberRoles()
if (!roleHasPermission(roles, PERMISSION.MANAGE_GUILD)) throw new Error('no permission to export channel follow mesh')
const follows = this.announcements
? await this.announcements.listGuildFollows(this.guild.guild.id).catch(() => [])
: []
const entries = follows.length
? follows.map((row) => ({
channelId: row.channelId || '',
userId: row.userId || '',
exportedAt: Date.now()
}))
: [{ channelId: '', userId: '', exportedAt: Date.now() }]
const csvBody = buildChannelFollowExportCsvBody(entries)
const signed = signChannelFollowExportCsv(csvBody, { guildId: this.guild.guild.id, relaySecret: this.guild.guild.id })
const exportedAt = Date.now()
const meta = { guildId: this.guild.guild.id, exportedAt, exportedBy: this.identity.user?.id || null, followCount: entries.length, signed: !!signed.signature, meshPushed: false }
this._lastChannelFollowExport = meta
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordChannelFollowExportCsv({ csvBody: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, followCount: entries.length })
}
return { format: 'csv', body: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, followCount: entries.length, meta }
}
async pushChannelFollowExportToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('notification.csv', {
spanKind: 'notification.csv',
guildId: gid,
context: 'mesh.channel-follow'
})
try {
const exported = await this.exportChannelFollowMesh({ recordMesh: false })
if (!exported.signature) throw new Error('channel follow export csv not signed')
const payload = {
guildId: this.guild.guild.id,
exportedAt: exported.exportedAt || Date.now(),
exportedBy: this.identity.user?.id || null,
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
followCount: exported.followCount || 0
}
if (this.guild.gossipChannelFollowExportCsvSync) {
this.guild.gossipChannelFollowExportCsvSync(payload)
}
this.emit('channel-follow-export-csv-sync', payload)
await this.deliveryReceipts.recordChannelFollowExportCsv({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
followCount: exported.followCount
})
this._lastChannelFollowExport = {
...exported.meta,
meshPushed: true
}
span.end({
guildNotificationCsvCount: exported.followCount || 0,
meshPushed: true,
bridgeKind: 'notification.csv'
})
return exported
} catch (err) {
this.log.error('notification.csv error', {
guildId: gid,
context: 'mesh.channel-follow',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async _onNotificationOverrideCsvGossip (payload) {
if (!payload?.guildId || !payload?.csvBody || !payload?.signature) return null
if (this.guild?.guild?.id !== payload.guildId) return null
await this._initDeliveryReceipts(payload.guildId)
this._shouldGossipNotificationRegistryCsv(payload)
const row = await this.deliveryReceipts.ingestNotificationOverrideCsvSlice(payload.guildId, payload)
if (row?.duplicate) {
this._notificationOverrideCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('notification-override-csv-sync', payload)
return row
}
async _onChannelFollowExportCsvGossip (payload) {
if (!payload?.guildId || !payload?.csvBody || !payload?.signature) return null
if (this.guild?.guild?.id !== payload.guildId) return null
await this._initDeliveryReceipts(payload.guildId)
this._shouldGossipChannelFollowExportCsv(payload)
const row = await this.deliveryReceipts.ingestChannelFollowExportCsvSlice(
payload.guildId,
payload
)
if (row?.duplicate) {
this._channelFollowExportCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('channel-follow-export-csv-sync', payload)
return row
}
async getAuditExportSchedule () {
if (!this.guild?.guild) {
return { enabled: false, intervalHours: 24, filter: 'all', lastExportAt: 0 }
@@ -30927,6 +31216,11 @@ class PearcordPlatform extends EventEmitter {
let readStateExportCsvRows = []
let lastReadStateExport = null
let guildPresenceActivities = []
let notificationOverrideCsvMeta = null
let notificationOverrideCsvRows = []
let channelFollowExportCsvRows = []
let lastChannelFollowExport = null
let guildNotificationOverrides = []
let lastComplianceSnapshot = null
let lastArchivePeerExport = null
let automationScheduleDashboard = null
@@ -31507,6 +31801,10 @@ class PearcordPlatform extends EventEmitter {
this._presenceActivityCsvDuplicateAt = null
const readStateExportCsvDuplicateAt = this._readStateExportCsvDuplicateAt || null
this._readStateExportCsvDuplicateAt = null
const notificationOverrideCsvDuplicateAt = this._notificationOverrideCsvDuplicateAt || null
this._notificationOverrideCsvDuplicateAt = null
const channelFollowExportCsvDuplicateAt = this._channelFollowExportCsvDuplicateAt || null
this._channelFollowExportCsvDuplicateAt = null
return {
onboarded: this.onboarded,
sessionReady: this._sessionReady,
@@ -31674,6 +31972,8 @@ class PearcordPlatform extends EventEmitter {
soundboardRegistryExportCsvDuplicateAt,
presenceActivityCsvDuplicateAt,
readStateExportCsvDuplicateAt,
notificationOverrideCsvDuplicateAt,
channelFollowExportCsvDuplicateAt,
digestRelayHandoffCsvMeta,
digestRelayHandoffCsvRows,
archivePeerExportCsvRows,
@@ -31776,6 +32076,13 @@ class PearcordPlatform extends EventEmitter {
guildPresenceActivities,
guildPresenceCsvCount:
(presenceActivityCsvRows || []).length + (guildPresenceActivities || []).length,
notificationOverrideCsvMeta,
notificationOverrideCsvRows,
channelFollowExportCsvRows,
lastChannelFollowExport,
guildNotificationOverrides,
guildNotificationCsvCount:
(notificationOverrideCsvRows || []).length + (guildNotificationOverrides || []).length,
automationScheduleDashboard,
automationHealthDashboard,
automationDigestNotifyPrefs,
@@ -32395,6 +32702,7 @@ const { stageCsvMixin } = require('./stage-csv-mixin')
const { voiceCsvMixin } = require('./voice-csv-mixin')
const { screenCsvMixin } = require('./screen-csv-mixin')
const { presenceCsvMixin } = require('./presence-csv-mixin')
const { notificationCsvMixin } = require('./notification-csv-mixin')
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
Object.assign(PearcordPlatform.prototype, userSettingsMixin)
@@ -32430,3 +32738,4 @@ Object.assign(PearcordPlatform.prototype, stageCsvMixin)
Object.assign(PearcordPlatform.prototype, voiceCsvMixin)
Object.assign(PearcordPlatform.prototype, screenCsvMixin)
Object.assign(PearcordPlatform.prototype, presenceCsvMixin)
Object.assign(PearcordPlatform.prototype, notificationCsvMixin)
+114
View File
@@ -0,0 +1,114 @@
'use strict'
const notificationCsvMixin = {
_notificationRegistryCsvGossipKeys: null,
_notificationCsvHealWatermark: null,
_channelFollowExportCsvHealWatermark: null,
_initNotificationCsvMixinState () {
if (!this._notificationRegistryCsvGossipKeys) {
this._notificationRegistryCsvGossipKeys = new Set()
}
},
_shouldGossipNotificationRegistryCsv (slice) {
this._initNotificationCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._notificationRegistryCsvGossipKeys.has(hash)) return false
this._notificationRegistryCsvGossipKeys.add(hash)
if (this._notificationRegistryCsvGossipKeys.size > 8192) {
const first = this._notificationRegistryCsvGossipKeys.values().next().value
if (first) this._notificationRegistryCsvGossipKeys.delete(first)
}
return true
},
_shouldGossipChannelFollowExportCsv (slice) {
this._initNotificationCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `effective:${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._notificationRegistryCsvGossipKeys.has(hash)) return false
this._notificationRegistryCsvGossipKeys.add(hash)
return true
},
async _healNotificationOverrideExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('notification.csv', {
spanKind: 'notification.csv',
guildId: gid,
context: 'heal.notification'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildNotificationCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listNotificationOverrideCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipNotificationRegistryCsv(row)) relisted++
}
const watermark = Date.now()
this._notificationCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildNotificationCsvCount: rows.length,
bridgeKind: 'notification.csv'
})
return { relisted, watermark, guildNotificationCsvCount: rows.length }
} catch (err) {
this.log.error('notification.csv error', {
guildId: gid,
context: 'heal.notification',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
},
async _healChannelFollowExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('notification.csv', {
spanKind: 'notification.csv',
guildId: gid,
context: 'heal.channel-follow'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildNotificationCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listChannelFollowExportCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipChannelFollowExportCsv(row)) relisted++
}
const watermark = Date.now()
this._channelFollowExportCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildNotificationCsvCount: rows.length,
overrideCount: rows[0]?.overrideCount || 0,
bridgeKind: 'notification.csv'
})
return { relisted, watermark, overrideCount: rows[0]?.overrideCount || 0 }
} catch (err) {
this.log.error('notification.csv error', {
guildId: gid,
context: 'heal.channel-follow',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
module.exports = { notificationCsvMixin }