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 Action
- type Agent
- type AgentFunc
- type Answer
- type Author
- type Card
- type Deliver
- type Engine
- func (e *Engine) Accept(ctx context.Context, id string) (store.Talk, error)
- func (e *Engine) AcceptOutcome(ctx context.Context, id, hash string) (Card, 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) OutcomeCard(ctx context.Context, id, hash string) (Card, store.Talk, error)
- func (e *Engine) PersonGone(ctx context.Context, person, by string) error
- func (e *Engine) ProposeOutcome(ctx context.Context, id string, o Outcome) (Card, 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 Outcome
- type Person
- type Received
- type RunnerAgent
- type Settings
- type Turn
- type View
Constants ¶
const ( KindOutcome = "outcome" KindAccept = "accept" )
The envelope kinds of P2's outcome card.
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 // MaxEnvelope is the longest envelope a Caprock takes, in bytes as it // travels (JSON); a longer one is refused there (400) and would wait in // the outbox with the rest of its Talk behind it, so none is queued. MaxEnvelope = MaxBody + 8<<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 besides the outcome card's (outcome.go: KindOutcome, KindAccept); ADR-110's artifact comes later.
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).
const CapOutcome = "outcome"
CapOutcome is the capability to read outcome and accept envelopes. Each side tells the other what it reads on every envelope (Envelope.Caps) and in every answer to one (Received.Caps); a Caprock from before the card tells nothing, and is sent no card: an envelope it refuses would wait in the outbox and every later one of the Talk behind it.
const HoldOutcome = "outcome"
HoldOutcome is not a hold: it is a Notice's kind for a new card (ADR-110: notifications for a hold and for an outcome card).
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 = `` /* 623-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 ErrAccepted = errors.New("you already accepted this version")
ErrAccepted is a second Accept of the same version from this side.
var ErrCard = errors.New("an outcome card needs a decision")
ErrCard is a card with no decision.
var ErrCardTooBig = errors.New("that outcome card is too long to send: shorten it")
ErrCardTooBig is a card whose envelope would be longer than the other side takes (MaxEnvelope).
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.
var ErrOldPeer = errors.New("their Caprock does not read outcome cards yet: it must be updated first")
ErrOldPeer is a card or an Accept toward a Caprock that reads none.
var ErrPeerUnknown = errors.New("their Caprock has not said yet whether it reads outcome cards: try again once it has answered")
ErrPeerUnknown is a card before the other side's Caprock said what it reads.
var ErrStale = errors.New("that is not the card's current version: read it again")
ErrStale is an Accept of a version that is not the current one.
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 Action ¶ added in v0.208.0
type Action struct {
Who string `json:"who"`
What string `json:"what"`
By string `json:"by,omitempty"`
}
Action is one line of who does what.
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"`
// Outcome is an outcome card the agent proposes with its message: it
// leaves through the guard like the message, and only people accept it.
Outcome *Outcome `json:"outcome,omitempty"`
// 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 Card ¶ added in v0.208.0
type Card struct {
// Side is whose envelope proposed it, Seq and Hash that envelope's.
Side string `json:"side"`
Seq int64 `json:"seq"`
Hash string `json:"hash"`
Version int `json:"version"`
Author Author `json:"author"`
Outcome Outcome `json:"outcome"`
At int64 `json:"at"`
// Current is the version people accept now: the highest, ties broken
// by hash so both sides pick the same.
Current bool `json:"current"`
// AcceptedByMe and AcceptedByThem are each side's person accepting
// this very version; Agreed is both.
AcceptedByMe bool `json:"accepted_by_me"`
AcceptedByThem bool `json:"accepted_by_them"`
Agreed bool `json:"agreed"`
// Text is the card as Copy for Slack copies it.
Text string `json:"text"`
}
Card is one version of a Talk's outcome card as GET /v1/talks/{id} answers it.
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) AcceptOutcome ¶ added in v0.208.0
AcceptOutcome is this side's person accepting the current version, named by its hash: an Accept envelope for this side only. An older version, or one this side already accepted, is refused.
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) OutcomeCard ¶ added in v0.208.0
OutcomeCard is one version of a Talk's card by its hash, and the Talk.
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) ProposeOutcome ¶ added in v0.208.0
ProposeOutcome sends this side's person's version of the card — a new card or an edit of the current one — through the guard: a card the guard catches is refused and nothing is sent. Every Accept so far was of an older version, so the new one needs both again.
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. Every answer says what this side reads.
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"`
// Outcome is a KindOutcome envelope's card version (outcome.go).
Outcome *Outcome `json:"outcome,omitempty"`
// Accepts is a KindAccept envelope's: the hash of the outcome envelope
// whose version the sender's person accepted.
Accepts string `json:"accepts,omitempty"`
// Caps are what the sender reads beyond P1's envelopes (CapOutcome);
// a Caprock from before the outcome card sends none.
Caps []string `json:"caps,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
// Caps are what this side reads beyond P1's envelopes, told to the
// other side on every envelope and every answer (outcome.go); nil is
// every capability this version has, an empty slice none (a Caprock
// from before the outcome card, for tests).
Caps []string
}
Options configure an Engine.
type Outcome ¶ added in v0.208.0
type Outcome struct {
// Version counts the card's versions in a Talk, both sides together,
// from 1; the proposer sets it one past the highest it holds.
Version int `json:"version"`
Decision string `json:"decision"`
Open []string `json:"open,omitempty"`
Actions []Action `json:"actions,omitempty"`
Sources []string `json:"sources,omitempty"`
}
Outcome is one version of the card, as it travels.
func GuardOutcome ¶ added in v0.208.0
GuardOutcome runs the guard on every text of a card: the card as it would leave and everything caught, counted together.
type Received ¶
type Received struct {
Have int64 `json:"have"`
State string `json:"state,omitempty"`
// Caps are what this side reads (Options.Caps); a Caprock from before
// the outcome card answers none.
Caps []string `json:"caps,omitempty"`
}
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
// NoCards says the other side's Caprock reads no outcome card: the
// turn is told not to propose one.
NoCards bool
}
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"`
// Cards are every version of the outcome card, oldest first; DraftCard
// is the card held with a held message, as it would leave.
Cards []Card `json:"cards"`
DraftCard *Outcome `json:"draft_outcome,omitempty"`
}
View is a Talk as GET /v1/talks/{id} answers it.