Documentation
¶
Overview ¶
Package workspace holds the node-workspace graph model, its storage, roles, the task-split prompt/parser and the scheduler.
Index ¶
- Constants
- func BuildSplitPrompt(task string, roles []Role, projectContext string) string
- func MaxParallel(cfg config.Config) int
- func Reconcile(g *Graph, cfg config.Config)
- func Save(path string, g *Graph) error
- type Engine
- func (e *Engine) AcceptSuggestions(defined func(string) bool) int
- func (e *Engine) AddFix(checkID string) (string, error)
- func (e *Engine) Assign(id, role string) error
- func (e *Engine) Auto() bool
- func (e *Engine) Close()
- func (e *Engine) Done() <-chan struct{}
- func (e *Engine) Events() <-chan Event
- func (e *Engine) Run(ctx context.Context, id string) error
- func (e *Engine) RunAll(ctx context.Context)
- func (e *Engine) Running() int
- func (e *Engine) Snapshot() *Graph
- func (e *Engine) Stop(id string)
- func (e *Engine) StopAll()
- func (e *Engine) WillAutoRun(id string) bool
- type Event
- type EventType
- type Executor
- type Graph
- func (g *Graph) AddCheck(commands []string) *Node
- func (g *Graph) AddCheckDeferred() *Node
- func (g *Graph) AddFix(checkID, failure string) (*Node, error)
- func (g *Graph) Assigned(n *Node) bool
- func (g *Graph) Blockers(id string) []string
- func (g *Graph) Clone() *Graph
- func (g *Graph) Counts() (todo, running, done, failed int)
- func (g *Graph) Layers() [][]*Node
- func (g *Graph) Node(id string) *Node
- func (g *Graph) Runnable() []*Node
- func (g *Graph) Validate() error
- type Kind
- type NewRole
- type Node
- type Result
- type Role
- type Status
Constants ¶
const FileName = "workspace.json"
FileName is the graph file inside .decsr.
Variables ¶
This section is empty.
Functions ¶
func BuildSplitPrompt ¶
BuildSplitPrompt assembles the lead's system prompt.
func MaxParallel ¶
MaxParallel is the number of nodes that may run at once: the configured value, default 3, clamped to 1..8.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine schedules graph nodes onto an Executor, up to maxParallel at once. All graph mutation happens under its mutex; callers read snapshots.
func (*Engine) AcceptSuggestions ¶
AcceptSuggestions assigns the suggested role of every unassigned work node whose suggestion is defined. It returns how many nodes were assigned.
func (*Engine) Close ¶
func (e *Engine) Close()
Close stops every node (see StopAll) and then closes Done. It is safe to call more than once.
func (*Engine) Done ¶
func (e *Engine) Done() <-chan struct{}
Done is closed by Close; an event pump can stop reading when it fires.
func (*Engine) RunAll ¶
RunAll turns auto mode on and starts every runnable node, then keeps starting nodes as others finish.
func (*Engine) StopAll ¶
func (e *Engine) StopAll()
StopAll turns auto mode off, cancels every running node and waits for the node goroutines to return, for at most 5 seconds: a node that ignores its cancelled context is abandoned and StopAll returns anyway. From the moment it begins, event sends never block (events are dropped when the buffer is full), so it does not depend on anyone reading Events().
func (*Engine) WillAutoRun ¶
WillAutoRun reports whether auto mode is on and the node is todo and assigned, so it will start by itself as soon as its dependencies are done.
type Event ¶
type Event struct {
NodeID string
Type EventType
Text string // output chunk, or the error text for EventFailed
// EventUsage: cumulative for the node.
In, Out int
Estimated bool
}
Event is a progress notification for one node. NodeID "" is used for engine-level messages (for example a failed save).
type Executor ¶
type Executor interface {
Run(ctx context.Context, g *Graph, n *Node, emit func(Event)) (Result, error)
}
Executor runs one node. It must return promptly when ctx is cancelled.
func NewExecutor ¶
NewExecutor returns the real Executor: work nodes go through the generic worker, check nodes run their shell commands.
type Graph ¶
type Graph struct {
Task string `json:"task"`
Title string `json:"title"`
Nodes []*Node `json:"nodes"`
NewRoles []NewRole `json:"new_roles,omitempty"`
}
Graph is the whole workspace: the task and its nodes.
func Load ¶
Load reads a graph from path. Nodes saved as running (an interrupted run) come back as todo. A missing file returns os.ErrNotExist unchanged.
func ParseSplit ¶
ParseSplit turns the lead's output into a validated graph. Roles named by the lead become suggestions only; nothing is assigned.
func Split ¶
func Split(ctx context.Context, r runner.LLMRunner, model string, task string, roles []Role, projectContext string, onToken func(string)) (*Graph, runner.TokenUsage, error)
Split asks the lead to split task and parses the answer. When the graph has several nodes and the lead suggested no role at all, it asks once more.
func (*Graph) AddCheck ¶
AddCheck appends the CHECK node depending on every other node. It returns nil without change when commands is empty or CHECK already exists.
func (*Graph) AddCheckDeferred ¶
AddCheckDeferred appends the CHECK node without commands; the executor asks for the commands when the node runs. It returns nil when CHECK exists.
func (*Graph) AddFix ¶
AddFix appends a work node "F<n>" that fixes a failed check, resets the check to todo and makes it depend on the new node.
func (*Graph) Assigned ¶
Assigned reports whether a node may run: check nodes always, work nodes once a role is set.
func (*Graph) Blockers ¶
Blockers returns the dependency IDs of id that are not done, in DependsOn order. A dependency that does not exist counts as a blocker.
func (*Graph) Layers ¶
Layers groups nodes by dependency depth (1 + the deepest dependency), keeping Nodes order inside a layer. The graph must be acyclic.
type Node ¶
type Node struct {
ID string `json:"id"` // "T1", "T2", …, "CHECK", "F1"
Title string `json:"title"`
Description string `json:"description"`
Kind Kind `json:"kind"`
Role string `json:"role,omitempty"` // assigned role; "" = unassigned
SuggestedRole string `json:"suggested_role,omitempty"`
DependsOn []string `json:"depends_on,omitempty"`
Status Status `json:"status"`
Commands []string `json:"commands,omitempty"` // check nodes
Summary string `json:"summary,omitempty"`
Files []string `json:"files,omitempty"`
Observed []string `json:"observed,omitempty"` // changed on disk by the agent's own tools
Warnings []string `json:"warnings,omitempty"`
Error string `json:"error,omitempty"`
InputTokens int `json:"input_tokens,omitempty"`
OutputTokens int `json:"output_tokens,omitempty"`
Estimated bool `json:"estimated,omitempty"`
StartedAt time.Time `json:"started_at,omitempty"`
EndedAt time.Time `json:"ended_at,omitempty"`
}
Node is one sub-task in the graph.
type Result ¶
type Result struct {
Summary string
Files []string // written from the worker's explicit file blocks
Observed []string // new or changed on disk during the run, by the agent's own tools
Warnings []string
}
Result is the outcome of a successful node run.