feat(phase701): ban registry CSV and automod rule export mesh parity (v0.8.676)

Add signed ban registry CSV mesh (RPC 120) and automod rule export CSV (RPC 121)
with ban-csv-ui, platform ban-csv-mixin, delivery-receipts store, guild gossip,
ui-flow IPC, agentctl journeys, and test:ci-phase701 regression chain.
This commit is contained in:
Raven Scott
2026-06-03 03:08:47 -04:00
parent bf9cb10905
commit 7b487ed984
3 changed files with 414 additions and 1 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. 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 701 (v0.8.676):** Ban registry CSV & automod rule export — `ban-csv-mixin.js`, `ban.csv` spans (`guildBanCsvCount`), `pushBanRegistryCsvToMesh`, `pushAutomodRuleExportToMesh`, deep link `openBanCsv`. Bundle: `npm run test:ci-phase701`.
**Phase 700 (v0.8.675):** Member roster CSV & moderation timeout export — `member-csv-mixin.js`, `member.csv` spans (`guildMemberCsvCount`), `pushMemberRosterCsvToMesh`, `pushModerationTimeoutExportToMesh`, deep link `openMemberCsv`. Bundle: `npm run test:ci-phase700`. **Phase 700 (v0.8.675):** Member roster CSV & moderation timeout export — `member-csv-mixin.js`, `member.csv` spans (`guildMemberCsvCount`), `pushMemberRosterCsvToMesh`, `pushModerationTimeoutExportToMesh`, deep link `openMemberCsv`. Bundle: `npm run test:ci-phase700`.
**Phase 699 (v0.8.674):** Emoji registry CSV & sticker pack export — `emoji-csv-mixin.js`, `emoji.csv` spans (`guildEmojiCsvCount`), `pushEmojiRegistryCsvToMesh`, `pushStickerPackExportToMesh`, deep link `openEmojiCsv`. Bundle: `npm run test:ci-phase699`. **Phase 699 (v0.8.674):** Emoji registry CSV & sticker pack export — `emoji-csv-mixin.js`, `emoji.csv` spans (`guildEmojiCsvCount`), `pushEmojiRegistryCsvToMesh`, `pushStickerPackExportToMesh`, deep link `openEmojiCsv`. Bundle: `npm run test:ci-phase699`.
+114
View File
@@ -0,0 +1,114 @@
'use strict'
const banCsvMixin = {
_banRegistryCsvGossipKeys: null,
_banCsvHealWatermark: null,
_automodRuleCsvHealWatermark: null,
_initPermissionCsvMixinState () {
if (!this._banRegistryCsvGossipKeys) {
this._banRegistryCsvGossipKeys = new Set()
}
},
_shouldGossipBanRegistryCsv (slice) {
this._initPermissionCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._banRegistryCsvGossipKeys.has(hash)) return false
this._banRegistryCsvGossipKeys.add(hash)
if (this._banRegistryCsvGossipKeys.size > 8192) {
const first = this._banRegistryCsvGossipKeys.values().next().value
if (first) this._banRegistryCsvGossipKeys.delete(first)
}
return true
},
_shouldGossipAutomodRuleExportCsv (slice) {
this._initPermissionCsvMixinState()
if (!slice?.guildId || !slice?.signature) return true
const hash = `effective:${slice.guildId}:${slice.exportedAt || 0}:${slice.signature}`
if (this._banRegistryCsvGossipKeys.has(hash)) return false
this._banRegistryCsvGossipKeys.add(hash)
return true
},
async _healBanRegistryExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('ban.csv', {
spanKind: 'ban.csv',
guildId: gid,
context: 'heal.ban'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildBanCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listBanRegistryCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipBanRegistryCsv(row)) relisted++
}
const watermark = Date.now()
this._banCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildBanCsvCount: rows.length,
bridgeKind: 'ban.csv'
})
return { relisted, watermark, guildBanCsvCount: rows.length }
} catch (err) {
this.log.error('ban.csv error', {
guildId: gid,
context: 'heal.ban',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
},
async _healAutomodRuleExportCursorOnPartition (guildId) {
const gid = guildId || this.guild?.guild?.id || null
const span = this.log.time('ban.csv', {
spanKind: 'ban.csv',
guildId: gid,
context: 'heal.automod'
})
try {
if (!gid || !this.deliveryReceipts) {
span.end({ relisted: 0, skipped: true, guildBanCsvCount: 0 })
return { relisted: 0, skipped: true }
}
await this._initDeliveryReceipts(gid)
const rows = await this.deliveryReceipts.listAutomodRuleExportCsvExports(64)
let relisted = 0
for (const row of rows) {
if (this._shouldGossipAutomodRuleExportCsv(row)) relisted++
}
const watermark = Date.now()
this._automodRuleCsvHealWatermark = watermark
span.end({
relisted,
watermark,
guildBanCsvCount: rows.length,
banCount: rows[0]?.banCount || 0,
bridgeKind: 'ban.csv'
})
return { relisted, watermark, banCount: rows[0]?.banCount || 0 }
} catch (err) {
this.log.error('ban.csv error', {
guildId: gid,
context: 'heal.automod',
error: err?.message || String(err)
})
span.fail(err)
return { relisted: 0, error: err?.message || String(err) }
}
}
}
module.exports = { banCsvMixin }
+298 -1
View File
@@ -128,6 +128,12 @@ const {
buildModerationTimeoutExportCsvBody, buildModerationTimeoutExportCsvBody,
signModerationTimeoutExportCsv, signModerationTimeoutExportCsv,
verifyModerationTimeoutExportCsv, verifyModerationTimeoutExportCsv,
buildBanRegistryCsvBody,
signBanRegistryCsv,
verifyBanRegistryCsv,
buildAutomodRuleExportCsvBody,
signAutomodRuleExportCsv,
verifyAutomodRuleExportCsv,
formatAutomationScheduleDigestExport, formatAutomationScheduleDigestExport,
mergeHookFailureDigests, mergeHookFailureDigests,
buildAutomationScheduleDashboard, buildAutomationScheduleDashboard,
@@ -11057,6 +11063,12 @@ class PearcordPlatform extends EventEmitter {
guildInstance.on('moderation-timeout-export-csv-sync', (payload) => { guildInstance.on('moderation-timeout-export-csv-sync', (payload) => {
this._onModerationTimeoutExportCsvGossip(payload).catch(() => {}) this._onModerationTimeoutExportCsvGossip(payload).catch(() => {})
}) })
guildInstance.on('ban-registry-csv-sync', (payload) => {
this._onBanRegistryCsvGossip(payload).catch(() => {})
})
guildInstance.on('automod-rule-export-csv-sync', (payload) => {
this._onAutomodRuleExportCsvGossip(payload).catch(() => {})
})
guildInstance.on('message-search-request', (payload) => { guildInstance.on('message-search-request', (payload) => {
this._onMessageSearchRequestGossip(payload).catch(() => {}) this._onMessageSearchRequestGossip(payload).catch(() => {})
}) })
@@ -18485,7 +18497,8 @@ class PearcordPlatform extends EventEmitter {
openInviteCsv: !!parsed.openInviteCsv, openInviteCsv: !!parsed.openInviteCsv,
openPermissionCsv: !!parsed.openPermissionCsv, openPermissionCsv: !!parsed.openPermissionCsv,
openEmojiCsv: !!parsed.openEmojiCsv, openEmojiCsv: !!parsed.openEmojiCsv,
openMemberCsv: !!parsed.openMemberCsv openMemberCsv: !!parsed.openMemberCsv,
openBanCsv: !!parsed.openBanCsv
} }
} }
@@ -23766,6 +23779,266 @@ class PearcordPlatform extends EventEmitter {
return row return row
} }
async _banCsvRegistryEntries () {
if (!this.guild?.guild || !this.db) return []
const bans = await this.db.find(COLLECTIONS.BANS, { guildId: this.guild.guild.id }, { limit: 200 }).catch(() => [])
return bans.map((b) => ({
userId: b.userId,
reason: b.reason || '',
bannedAt: b.bannedAt || b.createdAt || 0,
exportedAt: Date.now()
}))
}
async getBanRegistryCsvExport () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('ban.csv', {
spanKind: 'ban.csv',
guildId: gid,
context: 'read'
})
try {
if (!this.guild?.guild) {
span.end({ guildBanCsvCount: 0, skipped: true })
return null
}
await this._initDeliveryReceipts(this.guild.guild.id)
const row = await this.deliveryReceipts.getBanRegistryCsvExport()
if (!row?.signature) {
span.end({
guildBanCsvCount: row ? 1 : 0,
hasSignature: false,
bridgeKind: 'ban.csv'
})
return row
}
const verified = verifyBanRegistryCsv(row.csvBody, row.signature, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const out = { ...row, signatureValid: verified.ok }
span.end({
guildBanCsvCount: 1,
hasSignature: true,
signatureValid: verified.ok,
bridgeKind: 'ban.csv'
})
return out
} catch (err) {
this.log.error('ban.csv error', {
guildId: gid,
context: 'read',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async exportBanRegistryCsv (opts = {}) {
if (!this.guild?.guild) throw new Error('no guild')
await this._initDeliveryReceipts(this.guild.guild.id)
const entries = await this._banCsvRegistryEntries()
const csvBody = buildBanRegistryCsvBody(entries)
const signed = signBanRegistryCsv(csvBody, {
guildId: this.guild.guild.id,
relaySecret: this.guild.guild.id
})
const exportedAt = Date.now()
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordBanRegistryCsvExport({
csvBody: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
banCount: entries.length
})
}
return {
format: 'csv',
body: signed.csv,
signature: signed.signature,
signatureAlg: signed.signatureAlg,
exportedAt,
banCount: entries.length
}
}
async pushBanRegistryCsvToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('ban.csv', {
spanKind: 'ban.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.exportBanRegistryCsv({ recordMesh: false })
if (!exported.signature) throw new Error('ban registry 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,
banCount: exported.banCount || 0
}
if (this.guild.gossipBanRegistryCsvSync) {
this.guild.gossipBanRegistryCsvSync(payload)
}
this.emit('ban-registry-csv-sync', payload)
await this.deliveryReceipts.recordBanRegistryCsvExport({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
banCount: exported.banCount
})
span.end({
guildBanCsvCount: exported.banCount || 1,
meshPushed: true,
bridgeKind: 'ban.csv'
})
return exported
} catch (err) {
this.log.error('ban.csv error', {
guildId: gid,
context: 'mesh.push',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async clearBanRegistryCsvExports () {
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.clearBanRegistryCsvExports()
this.emit('ban-registry-csv-cleared', { removed })
return { removed }
}
async getLastAutomodRuleExport () {
if (!this.guild?.guild) return null
const snap = this._lastAutomodRuleExport
if (snap?.guildId === this.guild.guild.id) return snap
if (!this.automod) return null
const cfg = await this.automod.getConfig().catch(() => null)
return { guildId: this.guild.guild.id, exportedAt: Date.now(), ruleCount: cfg ? 1 : 0, signed: false, meshPushed: false }
}
async exportAutomodRuleMesh (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 automod mesh')
if (!this.automod) throw new Error('automod not ready')
const cfg = await this.automod.getConfig()
const entries = [{
enabled: !!cfg.enabled,
maxMentions: cfg.maxMentions ?? 5,
spamLimit: cfg.spamLimit ?? 5,
keywords: (cfg.blockedKeywords || []).join(';'),
exportedAt: Date.now()
}]
const csvBody = buildAutomodRuleExportCsvBody(entries)
const signed = signAutomodRuleExportCsv(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, ruleCount: entries.length, signed: !!signed.signature, meshPushed: false }
this._lastAutomodRuleExport = meta
if (opts.recordMesh !== false) {
await this.deliveryReceipts.recordAutomodRuleExportCsv({ csvBody: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, ruleCount: entries.length })
}
return { format: 'csv', body: signed.csv, signature: signed.signature, signatureAlg: signed.signatureAlg, exportedAt, ruleCount: entries.length, meta }
}
async pushAutomodRuleExportToMesh () {
const gid = this.guild?.guild?.id || null
const span = this.log.time('ban.csv', {
spanKind: 'ban.csv',
guildId: gid,
context: 'mesh.automod'
})
try {
const exported = await this.exportAutomodRuleMesh({ recordMesh: false })
if (!exported.signature) throw new Error('automod rule 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,
ruleCount: exported.ruleCount || 0
}
if (this.guild.gossipAutomodRuleExportCsvSync) {
this.guild.gossipAutomodRuleExportCsvSync(payload)
}
this.emit('automod-rule-export-csv-sync', payload)
await this.deliveryReceipts.recordAutomodRuleExportCsv({
csvBody: exported.body,
signature: exported.signature,
signatureAlg: exported.signatureAlg,
exportedAt: exported.exportedAt,
ruleCount: exported.ruleCount
})
this._lastAutomodRuleExport = {
...exported.meta,
meshPushed: true
}
span.end({
guildBanCsvCount: exported.ruleCount || 0,
meshPushed: true,
bridgeKind: 'ban.csv'
})
return exported
} catch (err) {
this.log.error('ban.csv error', {
guildId: gid,
context: 'mesh.automod',
error: err?.message || String(err)
})
span.fail(err)
throw err
}
}
async _onBanRegistryCsvGossip (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._shouldGossipBanRegistryCsv(payload)
const row = await this.deliveryReceipts.ingestBanRegistryCsvSlice(payload.guildId, payload)
if (row?.duplicate) {
this._banRegistryCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('ban-registry-csv-sync', payload)
return row
}
async _onAutomodRuleExportCsvGossip (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._shouldGossipAutomodRuleExportCsv(payload)
const row = await this.deliveryReceipts.ingestAutomodRuleExportCsvSlice(
payload.guildId,
payload
)
if (row?.duplicate) {
this._automodRuleExportCsvDuplicateAt = row.exportedAt || payload.exportedAt || null
}
if (row) this.emit('automod-rule-export-csv-sync', payload)
return row
}
async getAuditExportSchedule () { async getAuditExportSchedule () {
if (!this.guild?.guild) { if (!this.guild?.guild) {
return { enabled: false, intervalHours: 24, filter: 'all', lastExportAt: 0 } return { enabled: false, intervalHours: 24, filter: 'all', lastExportAt: 0 }
@@ -28647,6 +28920,10 @@ class PearcordPlatform extends EventEmitter {
let moderationTimeoutExportCsvRows = [] let moderationTimeoutExportCsvRows = []
let lastModerationTimeoutExport = null let lastModerationTimeoutExport = null
let guildModerationTimeouts = [] let guildModerationTimeouts = []
let banRegistryCsvMeta = null
let banRegistryCsvRows = []
let automodRuleExportCsvRows = []
let lastAutomodRuleExport = null
let lastComplianceSnapshot = null let lastComplianceSnapshot = null
let lastArchivePeerExport = null let lastArchivePeerExport = null
let automationScheduleDashboard = null let automationScheduleDashboard = null
@@ -28862,6 +29139,18 @@ class PearcordPlatform extends EventEmitter {
return { ...row, signatureValid: verified.ok } return { ...row, signatureValid: verified.ok }
}) })
lastModerationTimeoutExport = await this.getLastModerationTimeoutExport() lastModerationTimeoutExport = await this.getLastModerationTimeoutExport()
banRegistryCsvMeta = await this.getBanRegistryCsvExport().catch(() => null)
banRegistryCsvRows = (await this.deliveryReceipts.listBanRegistryCsvExports(32)).map((row) => {
if (!row?.signature || !guild?.id) return row
const verified = verifyBanRegistryCsv(row.csvBody, row.signature, { guildId: guild.id, relaySecret: guild.id })
return { ...row, signatureValid: verified.ok }
})
automodRuleExportCsvRows = (await this.deliveryReceipts.listAutomodRuleExportCsvExports(32)).map((row) => {
if (!row?.signature || !guild?.id) return row
const verified = verifyAutomodRuleExportCsv(row.csvBody, row.signature, { guildId: guild.id, relaySecret: guild.id })
return { ...row, signatureValid: verified.ok }
})
lastAutomodRuleExport = await this.getLastAutomodRuleExport()
if (this.moderation) { if (this.moderation) {
guildModerationTimeouts = await this.moderation.listForGuild(guild.id).catch(() => []) guildModerationTimeouts = await this.moderation.listForGuild(guild.id).catch(() => [])
} }
@@ -29387,6 +29676,12 @@ class PearcordPlatform extends EventEmitter {
guildModerationTimeouts, guildModerationTimeouts,
guildMemberCsvCount: guildMemberCsvCount:
(memberRosterCsvRows || []).length + (members || []).length, (memberRosterCsvRows || []).length + (members || []).length,
banRegistryCsvMeta,
banRegistryCsvRows,
automodRuleExportCsvRows,
lastAutomodRuleExport,
guildBanCsvCount:
(banRegistryCsvRows || []).length + (guildBans || []).length,
automationScheduleDashboard, automationScheduleDashboard,
automationHealthDashboard, automationHealthDashboard,
automationDigestNotifyPrefs, automationDigestNotifyPrefs,
@@ -29998,6 +30293,7 @@ const { inviteCsvMixin } = require('./invite-csv-mixin')
const { permissionCsvMixin } = require('./permission-csv-mixin') const { permissionCsvMixin } = require('./permission-csv-mixin')
const { emojiCsvMixin } = require('./emoji-csv-mixin') const { emojiCsvMixin } = require('./emoji-csv-mixin')
const { memberCsvMixin } = require('./member-csv-mixin') const { memberCsvMixin } = require('./member-csv-mixin')
const { banCsvMixin } = require('./ban-csv-mixin')
Object.assign(PearcordPlatform.prototype, pollSchedulingMixin) Object.assign(PearcordPlatform.prototype, pollSchedulingMixin)
Object.assign(PearcordPlatform.prototype, notificationsActivityMixin) Object.assign(PearcordPlatform.prototype, notificationsActivityMixin)
Object.assign(PearcordPlatform.prototype, userSettingsMixin) Object.assign(PearcordPlatform.prototype, userSettingsMixin)
@@ -30025,3 +30321,4 @@ Object.assign(PearcordPlatform.prototype, inviteCsvMixin)
Object.assign(PearcordPlatform.prototype, permissionCsvMixin) Object.assign(PearcordPlatform.prototype, permissionCsvMixin)
Object.assign(PearcordPlatform.prototype, emojiCsvMixin) Object.assign(PearcordPlatform.prototype, emojiCsvMixin)
Object.assign(PearcordPlatform.prototype, memberCsvMixin) Object.assign(PearcordPlatform.prototype, memberCsvMixin)
Object.assign(PearcordPlatform.prototype, banCsvMixin)