Keep Void replies in source channels

This commit is contained in:
Meta Vens 2026-05-23 11:12:18 +01:00
commit 5d90880350
7 changed files with 69 additions and 3 deletions

View file

@ -136,6 +136,7 @@ function Project-RecentHistoryForRumination {
$messages | ForEach-Object {
@{
id = Get-ObjectPropertyString -Value $_ -Name "id"
channelId = Get-ObjectPropertyString -Value $_ -Name "channelId"
authorId = Get-ObjectPropertyString -Value $_ -Name "authorId"
authorName = Get-ObjectPropertyString -Value $_ -Name "authorName"
isBot = [bool](Get-ObjectPropertyValue -Value $_ -Name "isBot")
@ -147,6 +148,55 @@ function Project-RecentHistoryForRumination {
}
}
function Project-RecentConversationTargetForRumination {
param(
$History,
[string] $PersonaName,
[string] $PersonaAvatarUrl
)
$messages = @(Convert-ToValueArray -Value (Get-ObjectPropertyValue -Value $History -Name "messages"))
if ($messages.Count -eq 0) {
return $null
}
$anchor = $null
for ($index = $messages.Count - 1; $index -ge 0; $index--) {
$candidate = $messages[$index]
$channelId = Get-ObjectPropertyString -Value $candidate -Name "channelId"
if ([string]::IsNullOrWhiteSpace($channelId)) {
continue
}
if (-not [bool](Get-ObjectPropertyValue -Value $candidate -Name "isBot")) {
$anchor = $candidate
break
}
if ($null -eq $anchor) {
$anchor = $candidate
}
}
if ($null -eq $anchor) {
return $null
}
$target = @{
mode = "channel"
channelId = Get-ObjectPropertyString -Value $anchor -Name "channelId"
replyToMessageId = Get-ObjectPropertyString -Value $anchor -Name "id"
personaName = if ([string]::IsNullOrWhiteSpace($PersonaName)) { "Void" } else { $PersonaName.Trim() }
reason = "Latest concrete recent-history conversation anchor. Use this instead of the configured public room when replying to that conversation."
}
if (-not [string]::IsNullOrWhiteSpace($PersonaAvatarUrl)) {
$target.personaAvatarUrl = $PersonaAvatarUrl.Trim()
}
return $target
}
function Project-OpenCasesForRumination {
param($Cases, [DateTime] $Now)

View file

@ -1051,6 +1051,7 @@ Write-JsonFile -Path $contextPath -Data @{
agencyPressure = @(Project-AgencyPressureForRumination -Pressures $typedState.agencyPressure.pressures -Now $startedAtUtc)
speechPressureObligations = $speechPressureObligations
pendingMentions = $pendingMentions
recentConversationTarget = Project-RecentConversationTargetForRumination -History $history -PersonaName $publicRoomPersonaName -PersonaAvatarUrl $publicRoomPersonaAvatarUrl
publicSpeechTarget = Project-PublicSpeechTargetForRumination -ChannelId $publicRoomChannelId -PersonaName $publicRoomPersonaName -PersonaAvatarUrl $publicRoomPersonaAvatarUrl
deliverableCandidateCount = [int]$deliverableCandidates.Count
candidateInterventions = @(Project-InterventionsForRumination -Interventions $typedState.candidateInterventions.interventions -Now $startedAtUtc)

View file

@ -217,10 +217,19 @@ process.stdin.on("end", () => {
}
$contextRaw = Get-Content -LiteralPath $contextPath -Raw -Encoding UTF8
if ($contextRaw -match '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}') {
$context = $contextRaw | ConvertFrom-Json
$contextForTimestampCheck = $contextRaw | ConvertFrom-Json
foreach ($repo in @($contextForTimestampCheck.repoActivity.freshRepos)) {
foreach ($commit in @($repo.commits)) {
if ($null -ne $commit.PSObject.Properties["contentHints"]) {
$commit.contentHints = @()
}
}
}
$timestampCheckRaw = $contextForTimestampCheck | ConvertTo-Json -Depth 32
if ($timestampCheckRaw -match '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}') {
throw "Rumination fixture context leaked exact ISO timestamps into the prompt-facing packet."
}
$context = $contextRaw | ConvertFrom-Json
if ($context.publicSpeechTarget.channelId -ne "fixture-public-room") {
throw "Rumination fixture context did not project the configured public speech target."
}