The PRD's deletion gate for the Messaging Service could not pass: go list -deps ./cmd/archie-messaging linked modernc.org/sqlite, internal/store, internal/domain/workflow and internal/agentexec -- all through one import, archiemessaging/run.go -> internal/app/controlplane, from which the service used three symbols. The decision was to sever rather than amend the gate, because a boundary you whitelist around is no longer a boundary (archie-core-1ng1, recorded in docs/architecture/migration-decisions.md). Measured before touching anything: internal/app/controlplane was the ONLY direct import of the service that dragged those runtimes -- every other one was clean -- so severing this one dependency is sufficient for the gate. Moved into the new internal/infrastructure/controlplanerpc: the generic resource client (NewRPCClient, Query), the RuntimeChatConfig projection, the reader interface (now the exported ResourceReader), the wire sentinels, the status mapping (now ClientError), and the channel-settings document with its decode -- ChannelSettings, TelegramSettings, WebhookChannelSettings, EmailSettings, RateLimitSettings, ChannelDuration, DecodeRenamingLegacyKeys. internal/app/controlplane keeps the store-backed server, the Definition registry, every kind's seed/validator/Normalize, the schema derivation, and its resource-specific reads and watches. Its Client embeds the new one, so the read path has one implementation while the workflow, persona and cronstore reads stay with the processes that already link those engines. The documents are type-aliased back into this package so the store-backed side reads them by the names it has always used: one definition, not a copy on each side of the boundary. The gate is now enforced by cmd/archie-messaging/architecture_test.go, measuring the linked binary against the PRD's banned list, with one exception checked in both directions: internal/domain/workflow/task, the Task status and view vocabulary whose own dependency set holds none of the banned runtimes. The UI gate carries the same entry for the same reason, and the fleet skill names it as the precedent. Verified: task check exit 0. The gate was red-proofed twice -- banning internal/channels fails it, and removing the workflow/task exception fails it -- so neither the loop nor the exception is decorative.
67 lines
3.2 KiB
Go
67 lines
3.2 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
|
|
)
|
|
|
|
// The channel-settings DOCUMENT lives in internal/infrastructure/controlplanerpc,
|
|
// beside the client that projects it, so a process that only reads stored
|
|
// settings does not link this package's store-backed server and workflow engine
|
|
// (archie-core-1ng1). These aliases keep the store-backed side reading the same
|
|
// types by the same names it always used, so there is one definition of the
|
|
// document rather than a copy on each side of the boundary.
|
|
type (
|
|
channelSettings = controlplanerpc.ChannelSettings
|
|
telegramSettings = controlplanerpc.TelegramSettings
|
|
webhookChannelSettings = controlplanerpc.WebhookChannelSettings
|
|
emailSettings = controlplanerpc.EmailSettings
|
|
rateLimitSettings = controlplanerpc.RateLimitSettings
|
|
channelDuration = controlplanerpc.ChannelDuration
|
|
)
|
|
|
|
// ChannelSettingsKind is re-exported so the store-backed side and its callers
|
|
// keep naming one kind by one name.
|
|
const ChannelSettingsKind = controlplanerpc.ChannelSettingsKind
|
|
|
|
func seedChannels(cfg config.Config) any {
|
|
chat := cfg.Chat
|
|
return channelSettings{
|
|
Operator: chat.Operator, Workspace: chat.Workspace, UnrestrictedFilesystem: chat.UnrestrictedFilesystem, ShowToolCalls: chat.ShowToolCalls, MaxSteps: chat.MaxSteps, Models: chat.Models,
|
|
Email: emailSettings{ListenAddr: chat.Email.ListenAddr, RelayAddr: chat.Email.RelayAddr},
|
|
WebhookAddr: chat.WebhookAddr,
|
|
Telegram: telegramSettings{AllowedUserIDs: chat.Telegram.AllowedUserIDs, Token: chat.Telegram.Token, TokenEnv: chat.Telegram.TokenEnv, CredentialConfigured: chat.Telegram.TokenEnv != "" || chat.Telegram.Token != (config.SecretRef{})},
|
|
Webhook: webhookChannelSettings{Path: chat.Webhook.Path, Secret: chat.Webhook.Secret, CredentialConfigured: chat.Webhook.Secret != (config.SecretRef{}), Template: chat.Webhook.Template, DeliverTo: chat.Webhook.DeliverTo},
|
|
RateLimit: rateLimitSettings{Window: channelDuration(chat.RateLimit.Window), MaxRequests: chat.RateLimit.MaxRequests},
|
|
}
|
|
}
|
|
|
|
func validateChannels(input []byte) error {
|
|
return validateAs(input, func(settings channelSettings) error {
|
|
if settings.MaxSteps < 0 || settings.RateLimit.MaxRequests < 0 || settings.RateLimit.Window < 0 {
|
|
return fmt.Errorf("channel limits must not be negative")
|
|
}
|
|
if settings.Webhook.DeliverTo != "" && settings.Webhook.DeliverTo != "origin" {
|
|
return fmt.Errorf("webhook deliver_to must be empty or origin")
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// normalizeChannels canonicalizes the stored document: decoding into the shape
|
|
// above and re-encoding writes the snake_case keys and the string duration,
|
|
// dropping the Go-cased keys an earlier revision stored. A document that still
|
|
// carries them converges the next time it is written; reads tolerate them
|
|
// meanwhile (emailSettings, rateLimitSettings), so nothing has to be re-saved
|
|
// before it can be read again.
|
|
func normalizeChannels(input []byte) ([]byte, error) {
|
|
var settings channelSettings
|
|
if err := json.Unmarshal(input, &settings); err != nil {
|
|
return nil, err
|
|
}
|
|
return json.Marshal(settings)
|
|
}
|