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 ¶
- type Adapter
- type Config
- type Effects
- type Environment
- type NeedsSandbox
- type O
- func (o *O) Clone() *O
- func (o *O) Del(k string) *O
- func (o *O) Get(k string) any
- func (o *O) Has(k string) bool
- func (o *O) Int(k string) (int, bool)
- func (o *O) Keys() []string
- func (o *O) List(k string) []any
- func (o *O) MarshalJSON() ([]byte, error)
- func (o *O) Obj(k string) *O
- func (o *O) Set(k string, v any) *O
- func (o *O) Str(k string) string
- func (o *O) UnmarshalJSON(b []byte) error
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 (*Adapter) Close ¶
Close cancels the turns that are running, waits for them, and closes the loops.
func (*Adapter) Handle ¶
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.
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 ¶
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) MarshalJSON ¶
MarshalJSON writes the members in order.
func (*O) Set ¶
Set writes a member, appending it when it is new and replacing it in place when it is not.
func (*O) UnmarshalJSON ¶
UnmarshalJSON reads an object, keeping the order of its members.
Source Files
¶
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. |