workspace

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 19 Imported by: 0 modules, 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 workspace holds the node-workspace graph model, its storage, roles, the task-split prompt/parser and the scheduler.

Index

Constants

View Source
const FileName = "workspace.json"

FileName is the graph file inside .decsr.

Variables

This section is empty.

Functions

func BuildSplitPrompt

func BuildSplitPrompt(task string, roles []Role, projectContext string) string

BuildSplitPrompt assembles the lead's system prompt.

func MaxParallel

func MaxParallel(cfg config.Config) int

MaxParallel is the number of nodes that may run at once: the configured value, default 3, clamped to 1..8.

func Reconcile

func Reconcile(g *Graph, cfg config.Config)

Reconcile clears the assigned role of nodes whose role no longer exists.

func Save

func Save(path string, g *Graph) error

Save writes g to path atomically (temp file, then rename) with mode 0o600.

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 NewEngine

func NewEngine(g *Graph, ex Executor, maxParallel int, savePath string) *Engine

NewEngine creates an engine over g. savePath "" disables persistence.

func (*Engine) AcceptSuggestions

func (e *Engine) AcceptSuggestions(defined func(string) bool) int

AcceptSuggestions assigns the suggested role of every unassigned work node whose suggestion is defined. It returns how many nodes were assigned.

func (*Engine) AddFix

func (e *Engine) AddFix(checkID string) (string, error)

AddFix adds a fix node for a failed check node and returns its ID.

func (*Engine) Assign

func (e *Engine) Assign(id, role string) error

Assign sets the role of a todo or failed work node. "" unassigns.

func (*Engine) Auto

func (e *Engine) Auto() bool

Auto reports whether auto mode is on.

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) Events

func (e *Engine) Events() <-chan Event

Events returns the event stream. It is never closed.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, id string) error

Run starts one node now.

func (*Engine) RunAll

func (e *Engine) RunAll(ctx context.Context)

RunAll turns auto mode on and starts every runnable node, then keeps starting nodes as others finish.

func (*Engine) Running

func (e *Engine) Running() int

Running returns the number of nodes currently running.

func (*Engine) Snapshot

func (e *Engine) Snapshot() *Graph

Snapshot returns a deep copy of the graph.

func (*Engine) Stop

func (e *Engine) Stop(id string)

Stop cancels one running node; it ends failed with Error "stopped".

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

func (e *Engine) WillAutoRun(id string) bool

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 EventType

type EventType string

EventType classifies an Event.

const (
	EventStarted EventType = "started"
	EventOutput  EventType = "output"
	EventUsage   EventType = "usage"
	EventDone    EventType = "done"
	EventFailed  EventType = "failed"
)

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

func NewExecutor(root string, cfg config.Config, projectContext string) Executor

NewExecutor returns the real Executor: work nodes go through the generic worker, check nodes run their shell commands.

func NewExecutorWithChecks

func NewExecutorWithChecks(root string, cfg config.Config, projectContext string, checkCommands func() []string) Executor

NewExecutorWithChecks is NewExecutor with a lazy source of check commands: a check node without Commands calls checkCommands when it runs.

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

func Load(path string) (*Graph, error)

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

func ParseSplit(task, output string, roles []Role) (*Graph, error)

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

func (g *Graph) AddCheck(commands []string) *Node

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

func (g *Graph) AddCheckDeferred() *Node

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

func (g *Graph) AddFix(checkID, failure string) (*Node, error)

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

func (g *Graph) Assigned(n *Node) bool

Assigned reports whether a node may run: check nodes always, work nodes once a role is set.

func (*Graph) Blockers

func (g *Graph) Blockers(id string) []string

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) Clone

func (g *Graph) Clone() *Graph

Clone returns a deep copy.

func (*Graph) Counts

func (g *Graph) Counts() (todo, running, done, failed int)

Counts returns how many nodes are in each status.

func (*Graph) Layers

func (g *Graph) Layers() [][]*Node

Layers groups nodes by dependency depth (1 + the deepest dependency), keeping Nodes order inside a layer. The graph must be acyclic.

func (*Graph) Node

func (g *Graph) Node(id string) *Node

Node returns the node with the given ID, or nil.

func (*Graph) Runnable

func (g *Graph) Runnable() []*Node

Runnable returns the todo, assigned, unblocked nodes in Nodes order.

func (*Graph) Validate

func (g *Graph) Validate() error

Validate checks unique non-empty IDs, existing dependencies, no self dependency and no cycle.

type Kind

type Kind string

Kind distinguishes LLM work nodes from the build/test check node.

const (
	KindWork  Kind = "work"
	KindCheck Kind = "check"
)

type NewRole

type NewRole struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

NewRole is a role the lead proposed that is not defined yet.

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.

func (*Node) AllFiles

func (n *Node) AllFiles() []string

AllFiles is Files followed by the Observed paths not already in Files.

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.

type Role

type Role struct {
	Name        string
	Description string
	Builtin     bool
	ReadOnly    bool // reviews and reports only; never writes files
	Agent       config.AgentConfig
}

Role is a named agent persona: a description plus the runner settings.

func FindRole

func FindRole(cfg config.Config, name string) (Role, bool)

FindRole looks a role up by name.

func Roles

func Roles(cfg config.Config) []Role

Roles returns the built-in roles in config.BuiltinRoles order, then custom roles sorted by name. A custom role without runner/model inherits the pm role's runner, model and effort.

type Status

type Status string

Status is the lifecycle state of a node.

const (
	StatusTodo    Status = "todo"
	StatusRunning Status = "running"
	StatusDone    Status = "done"
	StatusFailed  Status = "failed"
)

Jump to

Keyboard shortcuts

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