Files
archie/internal/domain/messaging/chat_contract.go
T
sam 3902b7ecbc feat(identity): attribute a task action to the identity that acted
The transport could carry an actor and nothing filled it. It does now, so a
dashboard approval is recorded as the person whose credential verified, and an
agent's token is recorded as the agent's action -- for an agent, agent_approved;
for a person, human_approved; and for a caller whose identity archie could not
verify, task_approved, which claims nothing about who did it.

The actor travels the path the action takes: webui reads it from the request
context the middleware resolved, carries it in the gateway request, the daemon
passes it through the in-process adapter, and the NATS request body carries it to
the service that records it. Scope stays separate from actor at every hop, because
scope is which task a caller may touch and the actor is who touched it.

A chat channel's bound identity is an actor too: a bot acting on its own channel's
task is recorded as an agent's action rather than a person's, via ActorFromScope,
whose empty kind is what keeps it out of human_approved. The agent-facing
task_action tool passes that identity and never input["identity"].

The UI process's credential check is now filled by endpoint references rather than
by configuration: -oidc-issuer and -oidc-audience on archie-ui, two URLs the
process already understands the shape of, with the verifier built in Run because
cmd/ parses flags and nothing else. The UI package still never reads config, and a
configured provider that cannot be reached fails boot rather than falling back to
the gate that names nobody.

Evidence for this change, stated as measured: go build ./... and go vet ./... are
clean, and every package this touches passes -- webui, domain/taskactions,
infrastructure/taskactions, infrastructure/gatewayrpc, gateway, app/archieui,
app/archied, domain/messaging, channels/telegram, cmd/archie-ui. task check could
not be run to completion: it fails in cmd/archie-messaging on an untracked
internal/buildinfo package another lane has in flight, which is not this change and
was left untouched. The end-to-end flip is covered in
internal/webui/api_tasks_actor_test.go: a person's credential produces a record
naming that person with human_approved, an agent's produces agent_approved, an
unverified request produces task_approved with no actor, and a request carrying
forged actor fields cannot name one.
2026-09-22 14:52:10 +10:00

51 lines
2.4 KiB
Go

package messaging
import (
"context"
"github.com/samcharles93/archie-core/internal/domain/taskactions"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// ChatContract is the conversational boundary consumed by channel frontends.
// Results are snapshots: callers must not rely on shared object identity.
// It moved here from internal/gateway (archie-core-8cda.5.6) so the webui
// and archie-ui processes can hold the contract without linking the gateway
// runtime (and, transitively, its SQLite session store).
type ChatContract interface { //nolint:interfacebloat // wire contract intentionally covers the complete Gateway facade
Snapshot(context.Context) (ChatSnapshot, error)
GetSession(context.Context, string) (SessionContext, bool, error)
RecentMessages(context.Context, string, int) ([]Message, error)
RecentTurns(context.Context, string, int) ([]TurnRecord, error)
Route(context.Context, Inbound) (ChatReply, error)
// Stream emits started, delta/tool/media, then done or error, in order.
// Callers must drain the stream or cancel the context. Cancellation closes it.
Stream(context.Context, Inbound) (<-chan ChatEvent, error)
Cancel(context.Context, string) (ChatCancellation, error)
SetPersona(context.Context, string, string) (bool, error)
ChatTaskActionContract
}
// ChatTaskActionContract is the operator task mutation capability exposed by
// the Gateway. It is separate so read/turn consumers do not need to model it.
type ChatTaskActionContract interface {
// ApplyTaskAction applies an action on behalf of a chat identity, which
// may only act on its own tasks.
ApplyTaskAction(context.Context, string, int64, taskstate.Action) (TaskActionResult, error)
// ApplyOperatorTaskAction applies an action on behalf of an authenticated
// dashboard caller, who acts across identities. The actor is who the
// credential resolved to, or the zero Actor when the caller presented
// nothing archie could verify -- which is recorded unattributed rather than
// credited to a human. It is a separate method rather than an empty identity
// because "" is a real identity in a single-identity deployment (see
// chatTaskProfiles in the daemon).
ApplyOperatorTaskAction(context.Context, taskactions.Actor, int64, taskstate.Action) (TaskActionResult, error)
}
// TaskActionResult is what task_action returns.
type TaskActionResult struct {
TaskID int64 `json:"task_id"`
Action string `json:"action"`
Message string `json:"message"`
}