compose

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 9 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 compose is the composer (spec_045_composer): a guided conversation that makes a workspace's component. It asks what it needs, writes the component in its file format, and checks it with the kind's own rules, sending the problems back to be fixed, before handing it on as a draft. A kind is a Recipe; the conversation is the same for all.

Index

Constants

View Source
const Instruction = `You are the composer of an AI agent workspace: you make one component for the user (described below) through a short conversation.
Ask only what you must to make a good component, one question at a time, in plain words, with up to six short suggested answers when there are natural choices. When the request already says enough, draft at once.
When you draft, write the component's whole file in its format, using only names the workspace has (listed below) unless the user asked for something new, and nothing that isn't needed.
Answer in one of two ways.
A question: JSON only, {"question": "…", "options": ["…"]}
A draft: a JSON line, {"draft": {"name": "lowercase-name-with-hyphens", "summary": "one sentence: what it does"}}, then the file's whole text in one fenced block:
` + "```" + `file
…
` + "```"

Instruction tells the model its job.

View Source
const Keep = time.Hour

Keep is how long a session lasts after its last turn.

View Source
const MaxQuestions = 5

MaxQuestions is how many questions the composer may ask before it must draft.

Variables

View Source
var ErrNoReply = errors.New("the composer's answer is neither a question nor a draft")

ErrNoReply means the model's answer is neither a question nor a draft.

View Source
var ErrNoSession = errors.New("no such composer session")

ErrNoSession means there's no such session (it ended, or it's another workspace's).

Functions

func Answer

func Answer(s *Session, text string)

Answer records the user's answer to s's question (or a change asked of its draft, which starts a new draft).

func Prompt

func Prompt(r Recipe, context string, s *Session, problems []string) string

Prompt is what the model gets for s's next turn: the recipe's brief, the workspace's context, the component being changed, the conversation, and what's asked of this turn.

func Step

func Step(ctx context.Context, r Recipe, context string, s *Session, ask Asker) error

Step runs the composer's turn on s: a question, or a draft checked with the recipe (and sent back with its problems, up to twice, to be fixed). context describes the workspace for the model.

Types

type Asker

type Asker func(ctx context.Context, instruction, prompt string) (reply string, costUSD float64, err error)

Asker has a model answer prompt under instruction, and says what it cost.

type Draft

type Draft struct {
	Name    string `json:"name"`
	Summary string `json:"summary"`
	// File is the component in its file format.
	File     string   `json:"file"`
	Problems []string `json:"problems,omitempty"`
}

Draft is the component as the composer wrote it.

type Recipe

type Recipe struct {
	Kind string
	// Brief says what the kind is and its file format, for the model.
	Brief string
	// Check returns what doesn't hold in a draft (nothing: it loads).
	Check func(name, file string) []string
}

Recipe is one kind of component: what the model is told about it, and how a draft of it is checked.

type Session

type Session struct {
	ID        string
	Kind      string
	Workspace string
	// Current is the component being changed, as its file ("" for a new one).
	Current string
	Turns   []Turn
	// Draft is the latest draft (nil until there's one).
	Draft   *Draft
	CostUSD float64
	Updated time.Time
	// contains filtered or unexported fields
}

Session is one conversation.

func (*Session) Asking

func (s *Session) Asking() bool

Asking reports whether the composer's last turn is a question waiting for an answer.

func (*Session) Lock

func (s *Session) Lock()

Lock holds s for a turn.

func (*Session) Snapshot

func (s *Session) Snapshot() *Session

Snapshot is a copy of s, to hand out (its own, unheld lock).

func (*Session) Unlock

func (s *Session) Unlock()

Unlock lets s go after a turn.

type Store

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

Store keeps the sessions going, in memory.

func (*Store) Drop

func (st *Store) Drop(workspace, id string)

Drop forgets workspace's session id.

func (*Store) Get

func (st *Store) Get(workspace, id string) (*Session, error)

Get is workspace's session id.

func (*Store) New

func (st *Store) New(kind, workspace, current, request string) *Session

New starts a session of kind in workspace, with the user's request.

type Turn

type Turn struct {
	// Role is "user" or "composer".
	Role string `json:"role"`
	Text string `json:"text"`
	// Options are a question's suggested answers.
	Options []string `json:"options,omitempty"`
	// Drafted marks the composer's turn that handed on a draft (its
	// summary): not a question.
	Drafted bool `json:"drafted,omitempty"`
}

Turn is one message of the conversation.

Jump to

Keyboard shortcuts

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