feat(phase707): screen share CSV & soundboard registry export mesh parity (v0.8.682)

Add signed guild screen share CSV mesh export and soundboard registry CSV
export (RPC 132/133): screen-csv-ui.js, screen-csv-mixin.js, delivery-receipts
collections, guild gossip handlers, ui-flow IPC, deep link ?screen-csv=1,
screen-csv-errors dev filter, agentctl screen/soundboard journeys, and
test:ci-phase707 regression bundle chaining phase706.
This commit is contained in:
Raven Scott
2026-06-03 04:22:55 -04:00
parent 982e39f8f2
commit 5a844427dc
3 changed files with 418 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 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`.
**Phase 706 (v0.8.681):** Voice state CSV & boost ledger export — `voice-csv-mixin.js`, `voice.csv` spans (`guildVoiceCsvCount`), `pushVoiceStateCsvToMesh`, `pushBoostLedgerExportToMesh`, deep link `openVoiceCsv`. Bundle: `npm run test:ci-phase706`.
**Phase 705 (v0.8.680):** Stage instance CSV & guild event export — `stage-csv-mixin.js`, `stage.csv` spans (`guildStageCsvCount`), `pushStageInstanceCsvToMesh`, `pushGuildEventExportToMesh`, deep link `openStageCsv`. Bundle: `npm run test:ci-phase705`.
+302
View File
@@ -164,6 +164,12 @@ const {
buildBoostLedgerExportCsvBody,
signBoostLedgerExportCsv,
verifyBoostLedgerExportCsv,
buildScreenShareCsvBody,
signScreenShareCsv,
verifyScreenShareCsv,
buildSoundboardRegistryExportCsvBody,
signSoundboardRegistryExportCsv,
verifySoundboardRegistryExportCsv,
formatAutomationScheduleDigestExport,
mergeHookFailureDigests,
buildAutomationScheduleDashboard,
@@ -11129,6 +11135,12 @@ class PearcordPlatform extends EventEmitter {
guildInstance.on('boost-ledger-export-csv-sync', (payload) => {
this._onBoostLedgerExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('screen-share-csv-sync', (payload) => {
this._onScreenShareCsvGossip(payload).catch(() => {})
})
guildInstance.on('soundboard-registry-export-csv-sync', (payload) => {
this._onSoundboardRegistryExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('message-search-request', (payload) => {
this._onMessageSearchRequestGossip(payload).catch(() => {})
})
@@ -25441,6 +25453,276 @@ class PearcordPlatform extends EventEmitter {
async _screenCsvRegistryEntries () {
if (!this.guild?.guild || !this.screenShare) return []
const gid = this.guild.guild.id
const all = await this.screenShare.store.find('@pearcord/screen-shares', {}).catch(() => [])
const active = all.filter((r) => r.guildId === gid && r.active)
if (!active.length) {
return [{ channelId: '', userId: '', sessionId: '', label: 'empty', exportedAt: Date.now() }]
}
return active.map((r) => ({
channelId: r.channelId || '',
userId: r.userId || '',
sessionId: r.sessionId || '',
label: r.label || 'Screen',
exportedAt: Date.now()
}))
}
async getScreenShareCsvExport () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('screen.csv', {
spanKind: 'screen.csv',
guildId: gid,
context: 'read'
})
try {
if (!this.guild?.guild) {
span.end({ guildScreenCsvCount: 0, skipped: true })
return null
}
await this._initDeliveryReceipts(this.guild.guild.id)
const row = await this.deliveryReceipts.getScreenShareCsvExport()
if (!row?.signature) {
span.end({
guildScreenCsvCount: row ? 1 : 0,
hasSignature: false,
bridgeKind: 'screen.csv'
})
return row
}
const verified = verifyScreenShareCsv(row.csvBody, row.signature, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const out = { ...row, signatureValid: verified.ok }
span.end({
guildScreenCsvCount: 1,
hasSignature: true,
signatureValid: verified.ok,
bridgeKind: 'screen.csv'
})
return out
} catch (err) {
this.log.error('screen.csv error', {
guildId: gid,
context: 'read',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async exportScreenShareCsv (opts = {}) {
if (!this.guild?.guild) throw new Error('no guild')
await this._initDeliveryReceipts(this.guild.guild.id)
const entries = await this._screenCsvRegistryEntries()
const csvBody = buildScreenShareCsvBody(entries)
const signed = signScreenShareCsv(csvBody, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const exportedAt = Date.now()
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordScreenShareCsvExport({
csvBody: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
shareCount: entries.length
})
}
return {
format: 'csv',
body: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
shareCount: entries.length
}
}
async pushScreenShareCsvToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('screen.csv', {
spanKind: 'screen.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 ban registry CSV')
}
const exported = await this.exportScreenShareCsv({ recordMesh: false })
if (!exported.signature) throw new Error('voice state 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,
shareCount: exported.shareCount || 0
}
if (this.guild.gossipScreenShareCsvSync) {
this.guild.gossipScreenShareCsvSync(payload)
}
this.emit('screen-share-csv-sync', payload)
await this.deliveryReceipts.recordScreenShareCsvExport({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
shareCount: exported.shareCount
})
span.end({
guildScreenCsvCount: exported.shareCount || 1,
meshPushed: true,
bridgeKind: 'screen.csv'
})
return exported
} catch (err) {
this.log.error('screen.csv error', {
guildId: gid,
context: 'mesh.push',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async clearScreenShareCsvExports () {
if (!this.guild?.guild) throw new Error('no guild')
if (!(await this._hasPerm(PERMISSION.MANAGE_GUILD))) {
throw new Error('no permission to clear ban registry CSV exports')
}
await this._initDeliveryReceipts(this.guild.guild.id)
const removed = await this.deliveryReceipts.clearScreenShareCsvExports()
this.emit('thread-archive-csv-cleared', { removed })
return { removed }
}
async getLastSoundboardRegistryExport () {
if (!this.guild?.guild) return null
const snap = this._lastSoundboardRegistryExport
if (snap?.guildId === this.guild.guild.id) return snap
if (!this.soundboardRegistry) return { guildId: this.guild.guild.id, exportedAt: Date.now(), soundCount: 0, signed: false, meshPushed: false }
const sounds = await this.soundboardRegistry.list().catch(() => [])
return { guildId: this.guild.guild.id, exportedAt: Date.now(), soundCount: sounds.length, signed: false, meshPushed: false }
}
async exportSoundboardRegistryMesh (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 soundboard registry mesh')
const sounds = this.soundboardRegistry ? await this.soundboardRegistry.list().catch(() => []) : []
const entries = sounds.map((row) => ({
soundId: row.id || '',
name: row.name || '',
attachmentId: row.attachmentId || '',
exportedAt: Date.now()
}))
if (!entries.length) {
entries.push({ soundId: '', name: 'none', attachmentId: '', exportedAt: Date.now() })
}
const csvBody = buildSoundboardRegistryExportCsvBody(entries)
const signed = signSoundboardRegistryExportCsv(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, soundCount: entries.length, signed: !!signed.signature, meshPushed: false }
this._lastSoundboardRegistryExport = meta
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordSoundboardRegistryExportCsv({ csvBody: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, soundCount: entries.length })
}
return { format: 'csv' , body: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, soundCount: entries.length, meta }
}
async pushSoundboardRegistryExportToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('screen.csv', {
spanKind: 'screen.csv',
guildId: gid,
context: 'mesh.soundboard'
})
try {
const exported = await this.exportSoundboardRegistryMesh({ recordMesh: false })
if (!exported.signature) throw new Error('forum tag 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,
soundCount: exported.soundCount || 0
}
if (this.guild.gossipSoundboardRegistryExportCsvSync) {
this.guild.gossipSoundboardRegistryExportCsvSync(payload)
}
this.emit('soundboard-registry-export-csv-sync', payload)
await this.deliveryReceipts.recordSoundboardRegistryExportCsv({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
soundCount: exported.soundCount
})
this._lastSoundboardRegistryExport = {
...exported.meta,
meshPushed: true
}
span.end({
guildScreenCsvCount: exported.soundCount || 0,
meshPushed: true,
bridgeKind: 'screen.csv'
})
return exported
} catch (err) {
this.log.error('screen.csv error', {
guildId: gid,
context: 'mesh.soundboard',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async _onScreenShareCsvGossip (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._shouldGossipScreenRegistryCsv(payload)
const row = await this.deliveryReceipts.ingestScreenShareCsvSlice(payload.guildId, payload)
if (row?.duplicate) {
this._screenShareCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('screen-share-csv-sync', payload)
return row
}
async _onSoundboardRegistryExportCsvGossip (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._shouldGossipSoundboardRegistryExportCsv(payload)
const row = await this.deliveryReceipts.ingestSoundboardRegistryExportCsvSlice(
payload.guildId,
payload
)
if (row?.duplicate) {
this._soundboardRegistryExportCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('soundboard-registry-export-csv-sync', payload)
return row
}
async getAuditExportSchedule () {
if (!this.guild?.guild) {
return { enabled: false, intervalHours: 24, filter: 'all', lastExportAt: 0 }
@@ -30351,6 +30633,11 @@ class PearcordPlatform extends EventEmitter {
let boostLedgerExportCsvRows = []
let lastBoostLedgerExport = null
let guildVoiceStates = []
let screenShareCsvMeta = null
let screenShareCsvRows = []
let soundboardRegistryExportCsvRows = []
let lastSoundboardRegistryExport = null
let guildScreenShares = []
let lastComplianceSnapshot = null
let lastArchivePeerExport = null
let automationScheduleDashboard = null
@@ -30923,6 +31210,10 @@ class PearcordPlatform extends EventEmitter {
this._voiceStateCsvDuplicateAt = null
const boostLedgerExportCsvDuplicateAt = this._boostLedgerExportCsvDuplicateAt || null
this._boostLedgerExportCsvDuplicateAt = null
const screenShareCsvDuplicateAt = this._screenShareCsvDuplicateAt || null
this._screenShareCsvDuplicateAt = null
const soundboardRegistryExportCsvDuplicateAt = this._soundboardRegistryExportCsvDuplicateAt || null
this._soundboardRegistryExportCsvDuplicateAt = null
return {
onboarded: this.onboarded,
sessionReady: this._sessionReady,
@@ -31086,6 +31377,8 @@ class PearcordPlatform extends EventEmitter {
guildEventExportCsvDuplicateAt,
voiceStateCsvDuplicateAt,
boostLedgerExportCsvDuplicateAt,
screenShareCsvDuplicateAt,
soundboardRegistryExportCsvDuplicateAt,
digestRelayHandoffCsvMeta,
digestRelayHandoffCsvRows,
archivePeerExportCsvRows,
@@ -31174,6 +31467,13 @@ class PearcordPlatform extends EventEmitter {
guildVoiceStates,
guildVoiceCsvCount:
(voiceStateCsvRows || []).length + (guildVoiceStates || []).length,
screenShareCsvMeta,
screenShareCsvRows,
soundboardRegistryExportCsvRows,
lastSoundboardRegistryExport,
guildScreenShares,
guildScreenCsvCount:
(screenShareCsvRows || []).length + (guildScreenShares || []).length,
automationScheduleDashboard,
automationHealthDashboard,
automationDigestNotifyPrefs,
@@ -31791,6 +32091,7 @@ const { pinCsvMixin } = require('./pin-csv-mixin')
const { threadCsvMixin } = require('./thread-csv-mixin')
const { stageCsvMixin } = require('./stage-csv-mixin')
const { voiceCsvMixin } = require('./voice-csv-mixin')
const { screenCsvMixin } = require('./screen-csv-mixin')
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
Object.assign(PearcordPlatform.prototype, userSettingsMixin)
@@ -31824,3 +32125,4 @@ Object.assign(PearcordPlatform.prototype, pinCsvMixin)
Object.assign(PearcordPlatform.prototype, threadCsvMixin)
Object.assign(PearcordPlatform.prototype, stageCsvMixin)
Object.assign(PearcordPlatform.prototype, voiceCsvMixin)
Object.assign(PearcordPlatform.prototype, screenCsvMixin)
+114
View File
@@ -0,0 +1,114 @@
'use strict'
const screenCsvMixin = {
_threadRegistryCsvGossipKeys: null,
_screenCsvHealWatermark: null,
_soundboardRegistryExportCsvHealWatermark: null,
_initScreenCsvMixinState () {
if (!this._threadRegistryCsvGossipKeys) {
this._threadRegistryCsvGossipKeys = new Set()
}
},
_shouldGossipScreenRegistryCsv (slice) {
this._initScreenCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._threadRegistryCsvGossipKeys.has(hash)) return false
this._threadRegistryCsvGossipKeys.add(hash)
if (this._threadRegistryCsvGossipKeys.size > 8192) {
const first = this._threadRegistryCsvGossipKeys.values().next().value
if (first) this._threadRegistryCsvGossipKeys.delete(first)
}
return true
},
_shouldGossipSoundboardRegistryExportCsv (slice) {
this._initScreenCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `effective:${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._threadRegistryCsvGossipKeys.has(hash)) return false
this._threadRegistryCsvGossipKeys.add(hash)
return true
},
async _healScreenShareExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('screen.csv', {
spanKind: 'screen.csv',
guildId: gid,
context: 'heal.thread'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildScreenCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listScreenShareCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipScreenRegistryCsv(row)) relisted++
}
const watermark = Date.now()
this._screenCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildScreenCsvCount: rows.length,
bridgeKind: 'screen.csv'
})
return { relisted, watermark, guildScreenCsvCount: rows.length }
} catch (err) {
this.log.error('screen.csv error', {
guildId: gid,
context: 'heal.thread',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
},
async _healSoundboardRegistryExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('screen.csv', {
spanKind: 'screen.csv',
guildId: gid,
context: 'heal.forum'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildScreenCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listSoundboardRegistryExportCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipSoundboardRegistryExportCsv(row)) relisted++
}
const watermark = Date.now()
this._soundboardRegistryExportCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildScreenCsvCount: rows.length,
shareCount: rows[0]?.shareCount || 0,
bridgeKind: 'screen.csv'
})
return { relisted, watermark, shareCount: rows[0]?.shareCount || 0 }
} catch (err) {
this.log.error('screen.csv error', {
guildId: gid,
context: 'heal.forum',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
module.exports = { screenCsvMixin }