frame

package
v0.7.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package frame is the Dev environment protocol on top of the dev loop.

Hanzo Dev's client speaks Effect RPC: JSON frames, one request per call and a stream of chunks per subscription, with the orchestration-v2 schemas in the Dev app's packages/contracts. The loop in this repository speaks its own alphabet, eight events in and ten actions out. An Adapter is where the two meet (HIP-1330): it takes each frame a client sends, drives the loop with the events it means, and writes back the frames the real Dev server would have written for the same thing. The loop, the client and the server are unchanged.

An Adapter serves chat mode: a thread with no workspace. The methods it answers are the chat-mode subset (HIP-1330): connecting, listing threads, launching one, sending a message, receiving the reply, renaming and settling. A method that needs a workspace (a shell, files, a checkout, a browser, a preview) is not answered; Handle returns a *NeedsSandbox naming it, and whoever owns the session decides: lease a cell and carry the request there, or Refuse it with the typed error the client already understands.

The Adapter does no I/O of its own. The model, the persistence of its state and any effect a loop asks for are an Effects, supplied by the session layer that owns the lease, the ledger and the sandbox.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter is one client's environment protocol, over one session.

func New

func New(cfg Config) (*Adapter, error)

New starts an Adapter.

func (*Adapter) Close

func (a *Adapter) Close(ctx context.Context) error

Close cancels the turns that are running, waits for them, and closes the loops.

func (*Adapter) Handle

func (a *Adapter) Handle(ctx context.Context, frame []byte) error

Handle takes one frame from the client. It returns once the frames the request asks for immediately are sent; a reply that takes the model's time arrives later, through Send.

A method that needs a workspace answers *NeedsSandbox and sends nothing.

func (*Adapter) Refuse

func (a *Adapter) Refuse(n *NeedsSandbox) error

Refuse answers a request with the typed error the client already understands for a method its session may not use: an EnvironmentAuthorizationError that names the scope and asks for the "sandbox" permission.

func (*Adapter) State

func (a *Adapter) State() ([]byte, error)

State is everything the Adapter keeps between frames: the threads, their projections, and each loop's snapshot. Restore it with Config.State.

func (*Adapter) Wait

func (a *Adapter) Wait()

Wait returns when every turn that is running has finished.

type Config

type Config struct {
	// Core runs the loop. One Core serves every Adapter in the process.
	Core    *dev.Core
	Effects Effects
	// Send writes one logical frame to the client. The Adapter calls it in
	// order, one call at a time, and splits a large frame into parts first when
	// the client asked.
	Send        func([]byte) error
	Environment Environment
	// Project is the id of the one project a chat session has, the scratch
	// space its threads live in. It is derived from the environment when empty.
	Project string
	// Sequence is where a new session's sequence of events starts: the
	// sequence of the snapshot the client already holds.
	Sequence int
	// Query is the query string the client opened its socket with.
	Query url.Values
	// State restores what a previous Adapter's State returned.
	State []byte
	// Now and NewID are the clock and the source of ids; tests replace them.
	Now   func() time.Time
	NewID func() string
}

Config is what an Adapter is born with.

type Effects

type Effects interface {
	// Model answers one ask, routed through Hanzo. Each increment of the reply
	// as it arrives goes to delta, so a client sees the text stream; the Reply
	// is the whole of it.
	Model(ctx context.Context, ask dev.Ask, delta func(string)) (dev.Reply, error)
	// Perform runs an Op the loop asked for that touches a workspace: Read,
	// Write, Patch, Exec, Git or Browse. A chat-mode session answers
	// *NeedsSandbox, and the session layer leases a cell and runs it there.
	Perform(ctx context.Context, op dev.Op) (dev.Output, error)
	// Save keeps the Adapter's State, which holds each thread's loop snapshot,
	// at the place in the sequence the loop asked for it.
	Save(ctx context.Context, state []byte) error
}

Effects is what the Adapter asks of the session layer.

type Environment

type Environment struct {
	ID    string
	Label string
}

Environment names the server the client believes it is talking to.

type NeedsSandbox

type NeedsSandbox struct {
	// ID is the request's id, and Method its name.
	ID     int
	Method string
	// Scope is the environment scope the method asks for, which is how the
	// client names the same thing.
	Scope string
}

NeedsSandbox is Handle's answer to a request that needs a workspace. The Adapter has sent nothing for it: the session layer either leases a cell and carries the request there, or calls Refuse.

func (*NeedsSandbox) Error

func (n *NeedsSandbox) Error() string

type O

type O struct {
	// contains filtered or unexported fields
}

O is a JSON object that keeps its members in the order they were written. Dev's frames are built from recorded frames, and the order the recording wrote is the order the server writes, so an O reads and writes members as they came. A nested object is an *O, an array a []any, a number its literal as a jsontext.Value.

func (*O) Clone

func (o *O) Clone() *O

Clone is a deep copy.

func (*O) Del

func (o *O) Del(k string) *O

Del removes a member.

func (*O) Get

func (o *O) Get(k string) any

Get is a member, or nil when there is none.

func (*O) Has

func (o *O) Has(k string) bool

Has reports whether the member exists, null included.

func (*O) Int

func (o *O) Int(k string) (int, bool)

Int is a whole-number member.

func (*O) Keys

func (o *O) Keys() []string

Keys are the member names in order.

func (*O) List

func (o *O) List(k string) []any

List is an array member.

func (*O) MarshalJSON

func (o *O) MarshalJSON() ([]byte, error)

MarshalJSON writes the members in order.

func (*O) Obj

func (o *O) Obj(k string) *O

Obj is an object member, nil when it is anything else.

func (*O) Set

func (o *O) Set(k string, v any) *O

Set writes a member, appending it when it is new and replacing it in place when it is not.

func (*O) Str

func (o *O) Str(k string) string

Str is a string member, empty when it is anything else.

func (*O) UnmarshalJSON

func (o *O) UnmarshalJSON(b []byte) error

UnmarshalJSON reads an object, keeping the order of its members.

Directories

Path Synopsis
cmd
framed command
Command framed serves one Dev environment-protocol session over stdio, for a client that cannot speak ZAP: frames in and out are a u32 little-endian length and then one frame, as a ZAP session carries them.
Command framed serves one Dev environment-protocol session over stdio, for a client that cannot speak ZAP: frames in and out are a u32 little-endian length and then one frame, as a ZAP session carries them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL