feat(phase708): presence activity CSV & read-state export mesh parity (v0.8.683)

Add signed guild presence activity CSV mesh export and read-state CSV export
(RPC 134/135): presence-csv-ui.js, presence-csv-mixin.js, delivery-receipts
collections, guild gossip handlers, ui-flow IPC, deep link ?presence-csv=1,
presence-csv-errors dev filter, agentctl presence/read-state journeys, and
test:ci-phase708 regression bundle chaining phase707.
This commit is contained in:
Raven Scott
2026-06-03 04:37:36 -04:00
parent 5a844427dc
commit 1396841b98
3 changed files with 420 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 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`.
**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`.
+304
View File
@@ -170,6 +170,12 @@ const {
buildSoundboardRegistryExportCsvBody,
signSoundboardRegistryExportCsv,
verifySoundboardRegistryExportCsv,
buildPresenceActivityCsvBody,
signPresenceActivityCsv,
verifyPresenceActivityCsv,
buildReadStateExportCsvBody,
signReadStateExportCsv,
verifyReadStateExportCsv,
formatAutomationScheduleDigestExport,
mergeHookFailureDigests,
buildAutomationScheduleDashboard,
@@ -11141,6 +11147,12 @@ class PearcordPlatform extends EventEmitter {
guildInstance.on('soundboard-registry-export-csv-sync', (payload) => {
this._onSoundboardRegistryExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('presence-activity-csv-sync', (payload) => {
this._onPresenceActivityCsvGossip(payload).catch(() => {})
})
guildInstance.on('read-state-export-csv-sync', (payload) => {
this._onReadStateExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('message-search-request', (payload) => {
this._onMessageSearchRequestGossip(payload).catch(() => {})
})
@@ -25720,6 +25732,278 @@ class PearcordPlatform extends EventEmitter {
return row
}
async _presenceCsvRegistryEntries () {
if (!this.guild?.guild) return []
const gid = this.guild.guild.id
const vec = this._exportPresenceVectorForSync(gid)
if (!vec.length) {
const selfId = this.identity?.user?.id || ''
return [{
userId: selfId,
status: this.presence?.status || 'online',
activityType: this.presence?.activity?.type || '',
customStatus: this.presence?.customStatus || '',
vectorSeq: 0,
exportedAt: Date.now()
}]
}
return vec.map((r) => ({
userId: r.userId || '',
status: r.status || 'offline',
activityType: '',
customStatus: '',
vectorSeq: r.vectorSeq || 0,
exportedAt: Date.now()
}))
}
async getPresenceActivityCsvExport () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('presence.csv', {
spanKind: 'presence.csv',
guildId: gid,
context: 'read'
})
try {
if (!this.guild?.guild) {
span.end({ guildPresenceCsvCount: 0, skipped: true })
return null
}
await this._initDeliveryReceipts(this.guild.guild.id)
const row = await this.deliveryReceipts.getPresenceActivityCsvExport()
if (!row?.signature) {
span.end({
guildPresenceCsvCount: row ? 1 : 0,
hasSignature: false,
bridgeKind: 'presence.csv'
})
return row
}
const verified = verifyPresenceActivityCsv(row.csvBody, row.signature, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const out = { ...row, signatureValid: verified.ok }
span.end({
guildPresenceCsvCount: 1,
hasSignature: true,
signatureValid: verified.ok,
bridgeKind: 'presence.csv'
})
return out
} catch (err) {
this.log.error('presence.csv error', {
guildId: gid,
context: 'read',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async exportPresenceActivityCsv (opts = {}) {
if (!this.guild?.guild) throw new Error('no guild')
await this._initDeliveryReceipts(this.guild.guild.id)
const entries = await this._presenceCsvRegistryEntries()
const csvBody = buildPresenceActivityCsvBody(entries)
const signed = signPresenceActivityCsv(csvBody, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const exportedAt = Date.now()
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordPresenceActivityCsvExport({
csvBody: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
presenceCount: entries.length
})
}
return {
format: 'csv',
body: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
presenceCount: entries.length
}
}
async pushPresenceActivityCsvToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('presence.csv', {
spanKind: 'presence.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 presence activity CSV')
}
const exported = await this.exportPresenceActivityCsv({ recordMesh: false })
if (!exported.signature) throw new Error('presence activity 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,
presenceCount: exported.presenceCount || 0
}
if (this.guild.gossipPresenceActivityCsvSync) {
this.guild.gossipPresenceActivityCsvSync(payload)
}
this.emit('presence-activity-csv-sync', payload)
await this.deliveryReceipts.recordPresenceActivityCsvExport({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
presenceCount: exported.presenceCount
})
span.end({
guildPresenceCsvCount: exported.presenceCount || 1,
meshPushed: true,
bridgeKind: 'presence.csv'
})
return exported
} catch (err) {
this.log.error('presence.csv error', {
guildId: gid,
context: 'mesh.push',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async clearPresenceActivityCsvExports () {
if (!this.guild?.guild) throw new Error('no guild')
if (!(await this._hasPerm(PERMISSION.MANAGE_GUILD))) {
throw new Error('no permission to clear presence activity CSV exports')
}
await this._initDeliveryReceipts(this.guild.guild.id)
const removed = await this.deliveryReceipts.clearPresenceActivityCsvExports()
this.emit('presence-activity-csv-cleared', { removed })
return { removed }
}
async getLastReadStateExport () {
if (!this.guild?.guild) return null
const snap = this._lastReadStateExport
if (snap?.guildId === this.guild.guild.id) return snap
const rows = await this._readReceiptSyncRowsForView(this.guild.guild.id, 64).catch(() => [])
return { guildId: this.guild.guild.id, exportedAt: Date.now(), readStateCount: rows.length, signed: false, meshPushed: false }
}
async exportReadStateMesh (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 read-state mesh')
const rows = await this._readReceiptSyncRowsForView(this.guild.guild.id, 64).catch(() => [])
const entries = rows.length
? rows.map((row) => ({
channelId: row.channelId || '',
channelName: row.channelName || '',
lastReadAt: row.lastReadAt || 0,
exportedAt: Date.now()
}))
: [{ channelId: '', channelName: 'none', lastReadAt: 0, exportedAt: Date.now() }]
const csvBody = buildReadStateExportCsvBody(entries)
const signed = signReadStateExportCsv(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, readStateCount: entries.length, signed: !!signed.signature, meshPushed: false }
this._lastReadStateExport = meta
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordReadStateExportCsv({ csvBody: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, readStateCount: entries.length })
}
return { format: 'csv', body: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, readStateCount: entries.length, meta }
}
async pushReadStateExportToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('presence.csv', {
spanKind: 'presence.csv',
guildId: gid,
context: 'mesh.read-state'
})
try {
const exported = await this.exportReadStateMesh({ recordMesh: false })
if (!exported.signature) throw new Error('read-state 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,
readStateCount: exported.readStateCount || 0
}
if (this.guild.gossipReadStateExportCsvSync) {
this.guild.gossipReadStateExportCsvSync(payload)
}
this.emit('read-state-export-csv-sync', payload)
await this.deliveryReceipts.recordReadStateExportCsv({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
readStateCount: exported.readStateCount
})
this._lastReadStateExport = {
...exported.meta,
meshPushed: true
}
span.end({
guildPresenceCsvCount: exported.readStateCount || 0,
meshPushed: true,
bridgeKind: 'presence.csv'
})
return exported
} catch (err) {
this.log.error('presence.csv error', {
guildId: gid,
context: 'mesh.read-state',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async _onPresenceActivityCsvGossip (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._shouldGossipPresenceRegistryCsv(payload)
const row = await this.deliveryReceipts.ingestPresenceActivityCsvSlice(payload.guildId, payload)
if (row?.duplicate) {
this._presenceActivityCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('presence-activity-csv-sync', payload)
return row
}
async _onReadStateExportCsvGossip (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._shouldGossipReadStateExportCsv(payload)
const row = await this.deliveryReceipts.ingestReadStateExportCsvSlice(
payload.guildId,
payload
)
if (row?.duplicate) {
this._readStateExportCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('read-state-export-csv-sync', payload)
return row
}
@@ -30638,6 +30922,11 @@ class PearcordPlatform extends EventEmitter {
let soundboardRegistryExportCsvRows = []
let lastSoundboardRegistryExport = null
let guildScreenShares = []
let presenceActivityCsvMeta = null
let presenceActivityCsvRows = []
let readStateExportCsvRows = []
let lastReadStateExport = null
let guildPresenceActivities = []
let lastComplianceSnapshot = null
let lastArchivePeerExport = null
let automationScheduleDashboard = null
@@ -31214,6 +31503,10 @@ class PearcordPlatform extends EventEmitter {
this._screenShareCsvDuplicateAt = null
const soundboardRegistryExportCsvDuplicateAt = this._soundboardRegistryExportCsvDuplicateAt || null
this._soundboardRegistryExportCsvDuplicateAt = null
const presenceActivityCsvDuplicateAt = this._presenceActivityCsvDuplicateAt || null
this._presenceActivityCsvDuplicateAt = null
const readStateExportCsvDuplicateAt = this._readStateExportCsvDuplicateAt || null
this._readStateExportCsvDuplicateAt = null
return {
onboarded: this.onboarded,
sessionReady: this._sessionReady,
@@ -31379,6 +31672,8 @@ class PearcordPlatform extends EventEmitter {
boostLedgerExportCsvDuplicateAt,
screenShareCsvDuplicateAt,
soundboardRegistryExportCsvDuplicateAt,
presenceActivityCsvDuplicateAt,
readStateExportCsvDuplicateAt,
digestRelayHandoffCsvMeta,
digestRelayHandoffCsvRows,
archivePeerExportCsvRows,
@@ -31474,6 +31769,13 @@ class PearcordPlatform extends EventEmitter {
guildScreenShares,
guildScreenCsvCount:
(screenShareCsvRows || []).length + (guildScreenShares || []).length,
presenceActivityCsvMeta,
presenceActivityCsvRows,
readStateExportCsvRows,
lastReadStateExport,
guildPresenceActivities,
guildPresenceCsvCount:
(presenceActivityCsvRows || []).length + (guildPresenceActivities || []).length,
automationScheduleDashboard,
automationHealthDashboard,
automationDigestNotifyPrefs,
@@ -32092,6 +32394,7 @@ const { threadCsvMixin } = require('./thread-csv-mixin')
const { stageCsvMixin } = require('./stage-csv-mixin')
const { voiceCsvMixin } = require('./voice-csv-mixin')
const { screenCsvMixin } = require('./screen-csv-mixin')
const { presenceCsvMixin } = require('./presence-csv-mixin')
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
Object.assign(PearcordPlatform.prototype, userSettingsMixin)
@@ -32126,3 +32429,4 @@ Object.assign(PearcordPlatform.prototype, threadCsvMixin)
Object.assign(PearcordPlatform.prototype, stageCsvMixin)
Object.assign(PearcordPlatform.prototype, voiceCsvMixin)
Object.assign(PearcordPlatform.prototype, screenCsvMixin)
Object.assign(PearcordPlatform.prototype, presenceCsvMixin)
+114
View File
@@ -0,0 +1,114 @@
'use strict'
const presenceCsvMixin = {
_presenceRegistryCsvGossipKeys: null,
_presenceCsvHealWatermark: null,
_readStateExportCsvHealWatermark: null,
_initPresenceCsvMixinState () {
if (!this._presenceRegistryCsvGossipKeys) {
this._presenceRegistryCsvGossipKeys = new Set()
}
},
_shouldGossipPresenceRegistryCsv (slice) {
this._initPresenceCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._presenceRegistryCsvGossipKeys.has(hash)) return false
this._presenceRegistryCsvGossipKeys.add(hash)
if (this._presenceRegistryCsvGossipKeys.size > 8192) {
const first = this._presenceRegistryCsvGossipKeys.values().next().value
if (first) this._presenceRegistryCsvGossipKeys.delete(first)
}
return true
},
_shouldGossipReadStateExportCsv (slice) {
this._initPresenceCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `effective:${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._presenceRegistryCsvGossipKeys.has(hash)) return false
this._presenceRegistryCsvGossipKeys.add(hash)
return true
},
async _healPresenceActivityExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('presence.csv', {
spanKind: 'presence.csv',
guildId: gid,
context: 'heal.presence'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildPresenceCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listPresenceActivityCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipPresenceRegistryCsv(row)) relisted++
}
const watermark = Date.now()
this._presenceCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildPresenceCsvCount: rows.length,
bridgeKind: 'presence.csv'
})
return { relisted, watermark, guildPresenceCsvCount: rows.length }
} catch (err) {
this.log.error('presence.csv error', {
guildId: gid,
context: 'heal.presence',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
},
async _healReadStateExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('presence.csv', {
spanKind: 'presence.csv',
guildId: gid,
context: 'heal.read-state'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildPresenceCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listReadStateExportCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipReadStateExportCsv(row)) relisted++
}
const watermark = Date.now()
this._readStateExportCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildPresenceCsvCount: rows.length,
presenceCount: rows[0]?.presenceCount || 0,
bridgeKind: 'presence.csv'
})
return { relisted, watermark, presenceCount: rows[0]?.presenceCount || 0 }
} catch (err) {
this.log.error('presence.csv error', {
guildId: gid,
context: 'heal.read-state',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
module.exports = { presenceCsvMixin }