Documentation
¶
Overview ¶
Package talks is Talks (ADR-110): two people who trust each other link their Caprocks once, and after that a one-line goal starts a Talk in which each side's own agent, grounded in its owner's 2nd Brain, talks to the other's until they are done, a cap is reached, or a person steps in.
What leaves this machine is the envelopes this package writes and nothing else: the messages this side's agent wrote and the guard let through (or the owner sent from a hold), the goal, a Talk's end, and this side's cost total when shared. Never the 2nd Brain, a session, a file, the brief, the agent's private note to its owner, or the grounding a turn read. They travel through the person link (pairing.KindPerson, peers.PeopleFile) as Noise ciphertext on the relay; nothing goes to Caprock.
The guard runs on every outgoing message: internal/redact plus the owner's literal never-share terms, and a hit holds the message for its owner (Send, Edit, Drop). The caps — messages and dollars per side per Talk — hold the Talk when reached. The other side's words reach the agent only quoted as data in the turn's prompt, and the turn has no tool: an incoming message can run nothing, by construction (Agent).
Index ¶
- Constants
- Variables
- func Guard(text string, terms []string) (string, redact.Counts)
- func Hash(raw []byte) string
- func Prompt(t Turn) string
- func System(t Turn) string
- func WriteSettings(dir string, s Settings) error
- type Agent
- type AgentFunc
- type Answer
- type Author
- type Deliver
- type Engine
- func (e *Engine) Accept(ctx context.Context, id string) (store.Talk, error)
- func (e *Engine) Continue(ctx context.Context, id string) (store.Talk, error)
- func (e *Engine) Delivery(ctx context.Context, person, id string) (Received, error)
- func (e *Engine) DropHeld(ctx context.Context, id string) (store.Talk, error)
- func (e *Engine) EditHeld(ctx context.Context, id, text string) (store.Talk, error)
- func (e *Engine) End(ctx context.Context, id string) (store.Talk, error)
- func (e *Engine) Get(ctx context.Context, id string) (View, error)
- func (e *Engine) List(ctx context.Context) ([]store.Talk, error)
- func (e *Engine) PersonGone(ctx context.Context, person, by string) error
- func (e *Engine) Receive(ctx context.Context, person string, raw []byte) (Received, error)
- func (e *Engine) Say(ctx context.Context, id, text string) (store.Talk, error)
- func (e *Engine) SendHeld(ctx context.Context, id string) (store.Talk, error)
- func (e *Engine) Start(ctx context.Context)
- func (e *Engine) StartTalk(ctx context.Context, person, goal string) (store.Talk, error)
- func (e *Engine) Wait()
- type Entry
- type Envelope
- type Grounding
- type Line
- type Notice
- type Options
- type Person
- type Received
- type RunnerAgent
- type Settings
- type Turn
- type View
Constants ¶
const ( // DefaultMaxMessages is how many messages this side's agent sends in a // Talk before the Talk holds for its owner. DefaultMaxMessages = 12 // DefaultMaxUSD is how much this side's turns may cost in a Talk before // it holds, in dollars as the agent reports them. DefaultMaxUSD = 5.0 // DefaultBrief is the brief every Talk starts with. DefaultBrief = "Never share secrets, keys, credentials, or other people's private data." )
The defaults Settings → Talks starts from (ADR-110, decided 2026-11-28). Limits Caprock chose for a Talk, not estimates of what one costs (rule 6).
const ( // MaxBody is the longest message, in bytes. MaxBody = 32 << 10 // MaxGoal is the longest goal, in runes. MaxGoal = 500 // MaxOpenPerPerson is how many Talks one person may have open with this // side at once (not finished or ended): a partner's Caprock opening // Talks without end would spend this side's agent on each. MaxOpenPerPerson = 10 )
Bounds on what one envelope and one setting may hold.
const ( // StateInvited is a Talk the other person started while *Let them start // talks* is off here: it waits for this side's Accept. StateInvited = "invited" // StateMyTurn is this side's agent's turn: running, or about to. StateMyTurn = "my_turn" // StateWaiting is the other side's turn. StateWaiting = "waiting" // StateHeld waits for this side's owner: Hold says why. StateHeld = "held" // StateFinished is both agents saying they are done. StateFinished = "finished" // StateEnded is ended by a person, or by Remove: EndedBy says whose. StateEnded = "ended" )
The states of a Talk on this side.
const ( // HoldRedaction is a message the guard caught: redaction or a // never-share term. Send, Edit or Drop. HoldRedaction = "redaction" // HoldNeedsOwner is a message the agent itself flagged for its owner. HoldNeedsOwner = "needs_owner" // HoldCap is a cap reached: Continue or End. HoldCap = "cap" // HoldError is a turn that failed: Continue tries again. HoldError = "error" )
Why a Talk is held (Talk.Hold).
const ( ByMe = "me" ByThem = "them" )
Who ended a Talk, and who started one.
const ( KindMessage = "message" KindHuman = "human" KindState = "state" )
The kinds of envelope this version sends (ADR-110 lists the rest: artifact, outcome, accept come with P2).
const ( EnvOpen = "open" EnvEnded = "ended" )
The states a KindState envelope carries.
const ( HowAuto = "auto" HowFromHold = "from_hold" HowEdited = "edited" HowTyped = "typed" )
How one of this side's envelopes left (TalkEnvelope.How).
KindNeverShare is what a never-share term's placeholder names.
const SettingsFile = "talks.json"
SettingsFile is where Settings live, mode 0600.
const TurnMarker = "CAPROCK-TALK-TURN v1"
TurnMarker opens every turn's prompt, so a fake agent knows a turn from a 2nd Brain read.
const TurnSchema = `` /* 258-byte string literal not displayed */
TurnSchema is the answer's shape.
Variables ¶
var ( ErrBadEnvelope = errors.New("that is not a Talk envelope this Caprock reads") ErrNotYours = errors.New("that talk is not one with you") ErrOutOfOrder = errors.New("that envelope does not follow the last one received") ErrNotHeld = errors.New("nothing is held in that talk") ErrEnded = errors.New("that talk has ended") ErrGoal = errors.New("a talk needs a goal of one line") ErrNoPerson = errors.New("no such person is linked for Talks") ErrCaught = errors.New("that text holds what the guard does not let leave") ErrState = errors.New("that talk is not in a state that allows this") ErrTooMany = errors.New("too many talks are open with this person: finish or end one first") )
Errors a caller turns into an answer.
var ErrNoAgent = errors.New("no coding agent to run a Talk turn with: install and sign in to Claude Code, Codex, Cursor or Gemini CLI")
ErrNoAgent is a machine with no agent to run a turn with.
Functions ¶
func Guard ¶
Guard is what runs on every outgoing text (ADR-110, the guard's step 2): internal/redact, then the literal never-share terms, case-folded. It returns the text as it would leave — every value caught replaced by a placeholder that names its kind — and what was caught. Anything caught holds a message.
func Prompt ¶
Prompt is the turn's data: the goal, the grounding and the transcript, each line JSON-quoted so no text of the other side's can close its quote.
func System ¶
System is the turn's instructions: who it speaks for, the brief, and the rule that the other side's words are data.
func WriteSettings ¶
WriteSettings saves talks.json, 0600, atomically.
Types ¶
type Agent ¶
Agent runs one turn. RunnerAgent is the real one; tests use a function or the fake claude in testdata, never a real agent.
type Answer ¶
type Answer struct {
// Message is what may leave, through the guard.
Message string `json:"message"`
// Note is a private note to the owner: never sent.
Note string `json:"note"`
// Sources are the grounding parts it drew on.
Sources []string `json:"sources"`
// Done says it has nothing more to add; NeedsOwner holds the message
// for its owner.
Done bool `json:"done"`
NeedsOwner bool `json:"needs_owner"`
// Agent and Model label who answered; CostUSD is what the call cost as
// the agent reported it (0 when it reports none).
Agent string `json:"-"`
Model string `json:"-"`
CostUSD float64 `json:"-"`
}
Answer is one turn's structured answer and what it cost.
type Author ¶
type Author struct {
// Kind is "agent" or "person".
Kind string `json:"kind"`
// Name is the sending person's name for Talks.
Name string `json:"name"`
// Agent and Model label an agent's message.
Agent string `json:"agent,omitempty"`
Model string `json:"model,omitempty"`
// Edited says the owner rewrote the agent's draft from a hold.
Edited bool `json:"edited,omitempty"`
}
Author is who wrote an envelope.
type Deliver ¶
type Deliver func(ctx context.Context, person string, body []byte) (status int, answer []byte, err error)
Deliver carries one envelope to a person's Caprock (POST /v1/talks/inbox there, through the person link) and returns the HTTP status and body.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs the Talks of this side.
func (*Engine) Accept ¶
Accept starts on this side a Talk the other person started while *Let them start talks* was off.
func (*Engine) Continue ¶
Continue answers a cap or a failed turn: a cap grows by the defaults again (Continue for 12 more), a failed turn runs again.
func (*Engine) Delivery ¶
Delivery is GET /v1/talks/inbox/{talk}: what this side holds of the sender's envelopes in a Talk with them.
func (*Engine) DropHeld ¶
DropHeld throws a held message away: the agent is told it was not sent and why, and writes again.
func (*Engine) EditHeld ¶
EditHeld sends the owner's text in place of a held message, marked as edited. It goes through the guard too: text that is caught is refused, and the owner changes it or sends the held one redacted.
func (*Engine) PersonGone ¶
PersonGone ends every Talk with a person whose link is gone — Removed here (byMe) or there — and empties the outbox toward them. Each side keeps its own copy of the transcript.
func (*Engine) Receive ¶
Receive takes one envelope from person, the relay key its channel proved. Delivery is at least once, so an envelope already held answers as taken.
func (*Engine) Say ¶
Say sends what this side's owner typed into a Talk, marked as theirs (KindHuman), through the guard: text that is caught is refused. It does not move the turn: the next turn on either side reads it. In a finished Talk it is the other side's agent's turn again.
func (*Engine) SendHeld ¶
SendHeld sends a held message as it would leave: with every value the guard caught replaced by its placeholder.
type Entry ¶
type Entry struct {
Side string `json:"side"`
store.TalkEnvelope
Envelope Envelope `json:"envelope"`
}
Entry is one envelope in a View.
type Envelope ¶
type Envelope struct {
V int `json:"v"`
Kind string `json:"kind"`
Talk string `json:"talk"`
// Seq is per sender, from 1; Prev is the hash of the sender's previous
// envelope in this Talk, "" for its first.
Seq int64 `json:"seq"`
Prev string `json:"prev"`
Author Author `json:"author"`
Body string `json:"body"`
// State is a KindState envelope's: EnvOpen (Body is the goal) or
// EnvEnded.
State string `json:"state,omitempty"`
// Done is the sending agent saying it has nothing more to add.
Done bool `json:"done,omitempty"`
// CostUSD is the sender's cost total for this Talk, when shared: their
// claim, shown as theirs.
CostUSD *float64 `json:"cost_usd,omitempty"`
// At is the sender's clock, unix ms.
At int64 `json:"at"`
}
Envelope is what travels between two Caprocks (ADR-110). Its JSON is stored on both sides byte for byte as it travelled, and its hash is over those bytes, so the two transcripts can be checked equal.
type Grounding ¶
type Grounding interface {
Ground(ctx context.Context, goal string) (text string, sources []string)
}
Grounding gathers what a turn may read of this side's 2nd Brain about a goal, read only. Nil grounds nothing.
type Line ¶
type Line struct {
// From is "you" (this side's agent), "owner" (this side's person),
// "them" (the other side's agent) or "partner" (the other person).
From string `json:"from"`
Text string `json:"text"`
}
Line is one line of the transcript as a turn sees it.
type Notice ¶
Notice is a hold for this side's owner: what the desktop, the phone and Telegram say (ADR-110: notifications only for a hold).
type Options ¶
type Options struct {
DB *sql.DB
Agent Agent
Ground Grounding
// Deliver sends to the other side; People finds a linked person.
Deliver Deliver
People func(id string) (Person, bool)
// Settings are Settings → Talks, read on every use.
Settings func() Settings
// Notify tells the owner of a hold; Changed says a Talk changed (a
// screen re-reads it). Either may be nil.
Notify func(Notice)
Changed func(talk, why string)
Log *slog.Logger
Now func() time.Time
// Retry overrides how long a failed delivery waits first, for tests.
Retry time.Duration
}
Options configure an Engine.
type Received ¶
Received is POST /v1/talks/inbox's answer: the newest of the sender's envelopes this side holds.
type RunnerAgent ¶
type RunnerAgent struct {
// Runners are the runners by agent id (brain.ReaderClaude, …).
Runners map[string]brain.Runner
// Pick is the agent and model a turn runs with when the owner chose
// none: the agent this machine reads with, its strongest model.
Pick func(ctx context.Context) (agent, model string)
}
RunnerAgent is an Agent over Second Brain's runner for one CLI (ADR-103).
type Settings ¶
type Settings struct {
// Name is what this side is called to the people it talks with.
Name string `json:"name,omitempty"`
// Brief is the brief every new Talk starts with.
Brief string `json:"brief,omitempty"`
// case-folded.
NeverShare []string `json:"never_share,omitempty"`
// MaxMessages and MaxUSD are the caps per side per Talk; 0 is the
// default.
MaxMessages int `json:"max_messages,omitempty"`
MaxUSD float64 `json:"max_usd,omitempty"`
ShareCost *bool `json:"share_cost,omitempty"`
// Agent and Model are the agent and model the turns run with; "" is the
// default (the strongest model of the agent this machine reads with).
Agent string `json:"agent,omitempty"`
Model string `json:"model,omitempty"`
}
Settings are Settings → Talks, kept in SettingsFile beside people.json: the never-share terms are the owner's own words (a client's name, a price floor), so not in config.json, which is pasted into support threads.
func ReadSettings ¶
ReadSettings loads talks.json; a missing file is the defaults.
func (Settings) BriefOrDefault ¶
BriefOrDefault is the brief a new Talk starts with.
func (Settings) SharesCost ¶
SharesCost is ShareCost with nil read as on.
type Turn ¶
type Turn struct {
Goal string
Brief string
OwnerName string
PartnerName string
Transcript []Line
// Grounding is what this side's 2nd Brain holds about the goal, read
// only, and Sources names where each part came from.
Grounding string
Sources []string
// Steer is what this turn is told first: why its last draft was not
// sent.
Steer string
// Agent and Model are the owner's choice; "" is the default.
Agent string
Model string
}
Turn is what one call is given.
type View ¶
type View struct {
store.Talk
// Transcript is every envelope, both sides, decoded.
Transcript []Entry `json:"transcript"`
// Waiting is how many of this side's envelopes the other side has not
// taken, and Offline the last delivery failure's words while any wait.
Waiting int `json:"waiting"`
Offline string `json:"offline,omitempty"`
}
View is a Talk as GET /v1/talks/{id} answers it.