Files
archie/modules/chat/parameters.go
T
samandCopilot cbfcd43018 feat(chat): add the chat module to the archie binary (#2018)
Conversations are the chat module's own tables. A turn is stored before it
is acknowledged, runs after the turns before it in its session, and records
everything it streams, so a reader replays it from a cursor. The agent uses
the configured agent model, the same connector tools as a run and the
dashboard's own reads; every action is judged, and one judgement holds is
put to people through approvals and run once when approved. A restart fails
the turns it interrupted visibly and never restarts a started action.

Conversation memory is a set of notes in the memory module. The chat
prompts are copied from internal/prompts (chat-system.tmpl, soul.md,
session-title.md) into internal/platform/prompts while the gateway still
reads them; the tool parameter redaction is copied from
internal/domain/messaging/tool_parameters.go.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-19 19:40:44 +11:00

73 lines
1.6 KiB
Go

package chat
import (
"encoding/json"
"strings"
"github.com/samcharles93/archie-core/internal/webhookguard"
)
const (
parametersMaxRunes = 2000
outputMaxRunes = 16000
redactedParameterValue = "[redacted]"
)
// summarizeParameters returns a bounded JSON shape of a tool's input with the
// values of credential-like keys redacted, for the transcript.
func summarizeParameters(input string) string {
if strings.TrimSpace(input) == "" {
return ""
}
decoder := json.NewDecoder(strings.NewReader(input))
decoder.UseNumber()
var value any
if err := decoder.Decode(&value); err != nil {
return "[unavailable]"
}
value = redactParameters(value, false)
encoded, err := json.Marshal(value)
if err != nil {
return "[unavailable]"
}
return truncateRunes(string(encoded), parametersMaxRunes)
}
func redactParameters(value any, sensitive bool) any {
if sensitive {
return redactedParameterValue
}
switch typed := value.(type) {
case map[string]any:
for key, child := range typed {
typed[key] = redactParameters(child, sensitiveKey(key))
}
return typed
case []any:
for i, child := range typed {
typed[i] = redactParameters(child, sensitive)
}
return typed
default:
return value
}
}
func sensitiveKey(key string) bool {
normalized := strings.NewReplacer("-", "_", " ", "_").Replace(strings.ToLower(key))
for _, marker := range webhookguard.SensitiveKeyMarkers {
if strings.Contains(normalized, marker) {
return true
}
}
return false
}
func truncateRunes(s string, limit int) string {
runes := []rune(s)
if len(runes) <= limit {
return s
}
return string(runes[:limit-1]) + "…"
}