Documentation
¶
Overview ¶
Package flowchart is the shape of a flow (ADR 0003), read from its Starlark script: the primitives it calls (agent, tool, ask, decide, parallel), in the order, branches and loops the script puts them. The terminal draws it (internal/tui); a run's records give its boxes their state. It reads the script only: nothing runs.
Index ¶
- Constants
- Variables
- func Check(name string, src []byte) []string
- func Delete(src []byte, n Node) ([]byte, error)
- func Diff(before, after *Chart)
- func Help(name string, src []byte, draft bool) (string, error)
- func Key(line, col int) string
- func Label(n Node) string
- func Move(src []byte, n Node, by int) ([]byte, error)
- func Removed(before, after *Chart) []string
- func SetText(src []byte, n Node, text string) ([]byte, error)
- func Tree(c *Chart, mark func(Node) string) string
- func ValidName(n string) bool
- type Arg
- type Change
- type Chart
- type Edit
- type Lines
- type Need
- type Node
- type OverviewInput
- type Reach
- type Span
- type View
Constants ¶
const ( Agent = "agent" Tool = "tool" Ask = "ask" Decide = "decide" Parallel = "parallel" // agents at once: Branches, or Body for each of Over If = "if" // Then, Else on Cond Loop = "loop" // Body, while or for Cond Return = "return" // the flow's end, with Text Phase = "phase" // the part the nodes after it belong to: Text Break = "break" // break or continue: Text )
Kinds of Node.
const Dir = ".kairocode/workflows"
Dir is where a project's flows are: <name>.star.
const DraftsDir = Dir + "/drafts"
DraftsDir is where flows are written before they are published (ADR 0030): drafts run only as tries.
Variables ¶
var ( ErrNotText = errors.New("its text is code, not words: ask for the change in words") ErrNotAlone = errors.New("the call is part of a larger statement: ask for the change in words") ErrNoSibling = errors.New("there is nothing to swap it with in its part of the flow") ErrNoEdit = errors.New("this box is not a call of the script") )
Why a change cannot be made on the chart: the user asks for it in words.
var Primitives = []string{"agent", "parallel", "tool", "ask", "decide", "phase"}
Primitives are the names a flow's script is given (internal/workflows' flowRun.builtins): what it can call besides Starlark's own.
Functions ¶
func Check ¶
Check looks at a flow's script without running it: does it parse, does it name only what exists (Starlark's own, the primitives, its own definitions), and does it have main(input). Each problem is "line:col: what", with how to put right the mistakes that Python habits make.
func Diff ¶
func Diff(before, after *Chart)
Diff marks the nodes of after that before does not have as they are: "~" where before has a node of that kind and title (changed), "+" where it has none (added).
func Help ¶
Help is what a flow is to be given and what it does (/flow <name> --help): its DESCRIPTION, its ARGS (how to call it), the lines of its script that read the words it is given (input["args"]), and its phases. draft: it is a draft (ADR 0030), tried with --draft.
func Key ¶
Key names a call of the script by where it is: what a run of the flow records before it makes the call (flow.at), and a box's state is looked up by.
func Move ¶
Move is src with n's statement swapped with the one before it (by -1) or after it (by 1) in its block.
func Removed ¶
Removed are the nodes of before that after does not have as they are, and whose kind and title it has no more of (taken away, not changed): as the tree labels them.
func SetText ¶
SetText is src with the text of n's box (its prompt, command or question) changed to text: only that string literal changes.
Types ¶
type Change ¶
type Change struct {
Mark string
Label string
Phase string
Before string
After string
// Src: its lines in the new script (none for "-").
Src Lines
}
Change is a step a new version of a flow adds ("+"), changes ("~") or takes away ("-"): as the tree labels it, in which phase, and its statement as the script before and after has it.
type Chart ¶
type Chart struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
// Args is what the flow is to be given (its ARGS): the words after
// /flow <name>, as their use says (ADR 0003, 追記).
Args string `json:"args,omitempty"`
Nodes []Node `json:"nodes"`
}
Chart is a flow's shape.
type Edit ¶
Edit is where a call's box is in its script, to change it there: its text's string literal (Lit, nil if the text is code), its statement and the statements of the block it is one of. Whole: the call is the whole statement, which can go without the rest of the script changing.
type Lines ¶
type Lines struct{ First, Last int }
Lines are a statement's lines, First to Last (from 1).
func Overview ¶
func Overview(c *Chart, in OverviewInput) (string, []Lines)
Overview is the first page of a flow's review: what it is for and how it runs, whether it is what the user asked for, what it reaches (what it sends out, what it changes, what asks the user first, how many times it runs a model), and what to watch out for. It is read from the script, but for what the user asked, which is the model's word, checked against the flow's phases. With it, for each of its lines, the script's lines of the step it is about.
type Need ¶
Need is one thing the user asked for, as the model that wrote the flow took it, and the phase of the flow that does it.
type Node ¶
type Node struct {
Kind string `json:"kind"`
// Title names what runs (the agent, the tool); Text is the prompt, the
// command, the question, the condition or the value, cut short.
Title string `json:"title,omitempty"`
Text string `json:"text,omitempty"`
// Code: Text is the script's code, not a string it gives.
Code bool `json:"code,omitempty"`
// Line and Col: where the call is (its opening parenthesis, where
// Starlark puts a call), to give the box a run's state (Key).
Line int `json:"line,omitempty"`
Col int `json:"col,omitempty"`
// Mark: how the node differs from the flow before a change: "+"
// added, "~" changed ("" the same). Set by Diff.
Mark string `json:"mark,omitempty"`
// Edit: where in the script the node is, to change it there (a call's).
Edit *Edit `json:"-"`
// Src: the script's lines the node is (its statement; an if's or a
// loop's head line), to show them.
Src Lines `json:"-"`
// Uses: where the values its text is made of come from, in words (a
// step's result, the user's words), when its text is code.
Uses []string `json:"-"`
// Args: for a tool, each named argument and what it is, in words (a
// step's result, the user's words) or as written.
Args []Arg `json:"args,omitempty"`
// Options: an ask's options, when the script gives them as a list.
Options []string `json:"options,omitempty"`
Cond string `json:"cond,omitempty"`
Then []Node `json:"then,omitempty"`
Else []Node `json:"else,omitempty"`
Body []Node `json:"body,omitempty"`
Branches [][]Node `json:"branches,omitempty"`
}
Node is a box of the chart, or a structure of boxes.
type OverviewInput ¶
type OverviewInput struct {
// Asked: what the user asked for, as the model took it (nil: it did
// not say).
Asked []Need
// Note says what a tool step reaches, in words, and how far.
Note func(Node) (string, Reach)
// Removed: steps the flow there now has and this one does not.
Removed []string
}
OverviewInput is what the overview is made of besides the chart.
type Reach ¶
type Reach int
Reach is what a tool step reaches, for the overview: Outside (an outside service, or what cannot be undone), Files (it changes files), or none.
type Span ¶
type Span struct{ Line, Col, EndLine, EndCol int }
Span is a piece of the script: from Line, Col to EndLine, EndCol (end not included; columns in runes, from 1).
type View ¶
type View struct {
Turn string `json:"turn"`
Chart *Chart `json:"chart"`
States map[string]string `json:"states"`
Rounds map[string]int `json:"rounds,omitempty"`
Done bool `json:"done,omitempty"`
}
View is a run of a flow as far as it has gone: its chart, from the script it recorded, and the state of each call (by Key): running, done, failed or waiting (for the user); a call not made yet has none. Rounds counts how often a call was made (in a loop).