Documentation
¶
Index ¶
- Variables
- func CreateConversation(reg ConversationCreator, creator SessionCreator, ...) dispatch.Handler
- func ListConversations(reg ConversationLister) dispatch.Handler
- func RegisterPushToken(reg *devices.Registry, registryPath string, logger *slog.Logger) dispatch.Handler
- func SendMessage(router SessionRouter, queue Enqueuer, logger *slog.Logger) dispatch.Handler
- type ConversationCreator
- type ConversationLister
- type Enqueuer
- type SessionCreator
- type SessionRouter
- type TurnWriter
Constants ¶
This section is empty.
Variables ¶
var ErrSpawnDirRejected = errors.New("conversation spawn directory rejected")
ErrSpawnDirRejected marks a deterministic rejection of a conversation's requested spawn workdir (it escapes $HOME after symlink resolution, or is unresolvable). SessionCreator implementations wrap it; the handler maps it to a non-retryable protocol.malformed reply rather than a retryable server.binary_offline, because re-issuing the same Cwd fails identically. The sentinel lives in this consumer/mapper package (cmd/pyry wraps it, no import cycle); mirrors the errors.Is mapping convention pinned in PROJECT-MEMORY.
Functions ¶
func CreateConversation ¶ added in v0.15.0
func CreateConversation(reg ConversationCreator, creator SessionCreator, registryPath, defaultCwd string, logger *slog.Logger) dispatch.Handler
CreateConversation returns a dispatch.Handler that processes a create_conversation frame from the phone: it mints a fresh conversation id, mints and binds a dedicated claude session for it via the sessions pool, records a registry row carrying the bound session id plus the effective cwd / promoted flag / name (server defaults applied when a field is null), eagerly persists the registry, and replies with a conversation_created envelope correlated via in_reply_to.
reg is the conversations registry; creator mints the per-conversation session; registryPath is the canonical on-disk path passed to the eager Save; defaultCwd is the absolute cwd recorded when the payload's cwd is null; logger is the daemon's slog logger.
SECURITY: this handler is a spawn-consumer — it mints a per-conversation claude session via creator.Create, which now spawns in the conversation's own (phone-influenced) Cwd rather than the daemon's shared workdir (#685, reversing the prior deferral). The phone's raw requested Cwd is forwarded verbatim as creator.Create's spawnDir; this handler does NO path handling and stays free of internal/sessions / cmd-layer imports. The cmd-layer adapter (sessionMinter → resolveSpawnDir) is the sole validator: it canonicalises + confines the Cwd to $HOME (rejecting any path that escapes after symlink resolution) and trust-marks the realpath before claude spawns, identical to the daemon's own bootstrap-workdir posture. A rejected Cwd surfaces as a non-retryable protocol.malformed reply (errors.Is ErrSpawnDirRejected) with no half-bound row; a null Cwd yields an empty spawnDir → the shared trusted workdir (unchanged). The session id reaching claude's argv (--session-id) is server-minted (sessions.NewID, crypto/rand); the created conversation id is server-minted (conversations.NewID), never phone-supplied, so a phone cannot choose, collide, or overwrite a row (Create appends).
func ListConversations ¶
func ListConversations(reg ConversationLister) dispatch.Handler
ListConversations returns a dispatch.Handler that answers a list_conversations request with a conversations envelope. The handler reads the registry, projects each row to a protocol.ConversationSummary, sorts by LastUsedAt asc / ID asc (mirroring Registry.Save), and replies via Conn.Reply (which stamps id, ts, and in_reply_to).
func RegisterPushToken ¶
func RegisterPushToken(reg *devices.Registry, registryPath string, logger *slog.Logger) dispatch.Handler
RegisterPushToken returns a dispatch.Handler that processes a register_push_token frame from the phone. reg is the devices registry; registryPath is the canonical on-disk path passed to Save; logger is the daemon's slog logger used for every branch's structured event.
SECURITY:
- The push token (p.Token, dev.PushToken) is opaque infrastructure data (FCM/APNs registration id); not a secret on par with the device auth token. It is logged at INFO when a write happens (as a side-effect of the write event) and never as a field value at any level.
- The Device.Name is logged on every authenticated branch. The unauth branch has no name to log; that is the only path without it.
Concurrency: the handler is stateless beyond the closure capture. reg's mutex serialises UpdatePushRegistration and Save independently; two concurrent calls for the same TokenHash interleave at the mutex boundary with documented last-writer-wins semantics.
func SendMessage ¶
SendMessage returns a dispatch.Handler that processes a send_message frame from the phone. router validates the frame's ConversationID against its bound claude session (#678) and stamps the active-conversation cursor (#687); queue is the daemon's inbound backlog the message is appended to; logger is the daemon's slog logger used for every branch's structured event.
Since #721 the handler acks on ENQUEUE (accepted into the backlog), not on delivery-confirm. It validates the binding synchronously, enqueues non-blocking, and returns an ack; the daemon's msgqueue drain delivers the backlog one message at a time through the reliable WriteUserTurn path, paced by claude reaching idle (#704). This is the ADR 025 line 123 contract — send_message is unchanged at the wire level, queued by the daemon when claude is busy.
The ack contract (which failures still produce an error reply vs are absorbed by the drain) is asymmetric by design:
- At enqueue we have a live phone to tell "retry", so a malformed payload, an unknown conversation, and an unbound conversation are all rejected synchronously, before any enqueue.
- Once enqueued, the ack promised delivery, so a transient resolve/activate/ write failure is held and retried by the drain rather than surfaced (a conversation that becomes unbound post-ack is retried, not dropped).
SECURITY:
- payload.Text is treated as opaque transit content: it is stored in the in-memory FIFO and reaches the supervised claude child's stdin verbatim only at the drain's WriteUserTurn call. No transformation, no length cap beyond the transport's WS read ceiling (1 MiB; see internal/transport).
- payload.Text is NEVER logged at any level. conversation_id and message_id (phone-supplied opaque ids) plus the assigned queued_msg_id are logged on the enqueue path; conversation_id only on the reject paths.
- The phone supplies only the ConversationID lookup key and the Text; the routing target (the bound session) is read from the server-stored registry row, never phone-writable. An unbound conversation is rejected before enqueue, so a turn is never silently routed to the shared bootstrap session (#678 AC#4).
Types ¶
type ConversationCreator ¶ added in v0.15.0
type ConversationCreator interface {
Create(c conversations.Conversation)
Save(path string) error
}
ConversationCreator is the minimal write surface this handler consumes from the conversations registry. *conversations.Registry satisfies it structurally; no adapter required.
type ConversationLister ¶
type ConversationLister interface {
List(filter ...conversations.ListFilter) []conversations.Conversation
}
ConversationLister is the minimal surface this handler consumes from the conversations registry. *conversations.Registry satisfies it structurally; no adapter required. The variadic shape mirrors conversations.Registry.List exactly so structural matching holds.
type Enqueuer ¶ added in v0.15.0
Enqueuer is the inbound backlog the send_message handler appends to instead of delivering synchronously. *msgqueue.Queue satisfies it. The interface is defined here, consumer-side, so handlers/ stays free of an internal/msgqueue import (mirrors SessionRouter and TurnWriter). Enqueue is non-blocking and returns the stable per-conversation id assigned to the message.
type SessionCreator ¶ added in v0.15.0
type SessionCreator interface {
Create(ctx context.Context, label, spawnDir string) (string, error)
}
SessionCreator is the minimal session-mint surface this handler consumes from the sessions pool: mint, supervise, and activate one dedicated claude session whose claude spawns in spawnDir, returning the session id. It is adapted at the cmd/pyry boundary (sessionMinter) rather than satisfying *sessions.Pool directly — keeping handlers/ free of internal/sessions imports, mirroring TurnWriter.
spawnDir == "" → the daemon's shared trusted workdir (default, unchanged). A non-empty spawnDir is the phone's *requested* working directory (the raw, untrusted conversation Cwd); the implementation validates it (confine to $HOME, symlink-resolve both sides) and trust-marks it before spawning. A requested dir that escapes $HOME is rejected with an error wrapping ErrSpawnDirRejected; the handler maps that to a non-retryable reply.
type SessionRouter ¶ added in v0.15.0
type SessionRouter interface {
Route(conversationID string) (TurnWriter, error)
}
SessionRouter resolves a send_message frame's conversation id to the write surface for that conversation's bound claude session (#678). Resolution is a pure in-memory lookup (no I/O, non-blocking) — the blocking activation happens in the returned TurnWriter's Activate, under the handler's existing budget. The interface lives in this package, returning a TurnWriter rather than any internal/sessions type, so handlers/ stays free of an internal/sessions import (mirrors SessionCreator in create_conversation.go).
Failure mapping the handler relies on:
- unknown conversation → conversations.ErrConversationNotFound (maps to conversation.not_found, not retryable)
- conversation has no bound session, or the bound session id is not in the pool → any other non-nil error (maps to retryable server.binary_offline)
type TurnWriter ¶
type TurnWriter interface {
Activate(ctx context.Context) error
WriteUserTurn(ctx context.Context, conversationID string, payload []byte) error
}
TurnWriter is the minimal per-conversation write-surface that the inbound delivery seam drives. *sessions.Session satisfies it via one-line passthroughs to Session.Activate and Supervisor.WriteUserTurn. The interface lives in this package so handlers/ stays free of internal/sessions and internal/supervisor imports.
Since #721 the send_message handler no longer drives a TurnWriter directly — it enqueues, and the daemon's msgqueue drain (cmd/pyry.newInboundDeliver) resolves and writes one message at a time. SessionRouter.Route still returns a TurnWriter so the handler can validate the binding before enqueue.
Activate is called before WriteUserTurn so an idle-evicted bootstrap session lazily respawns claude on the next delivery rather than dropping it silently (#396). On an already-active session Activate is a near-no-op (two non-blocking channel receives).