flowchart

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 10 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 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

View Source
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.

View Source
const Dir = ".kairocode/workflows"

Dir is where a project's flows are: <name>.star.

View Source
const DraftsDir = Dir + "/drafts"

DraftsDir is where flows are written before they are published (ADR 0030): drafts run only as tries.

Variables

View Source
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.

View Source
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

func Check(name string, src []byte) []string

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 Delete

func Delete(src []byte, n Node) ([]byte, error)

Delete is src without n's statement.

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

func Help(name string, src []byte, draft bool) (string, error)

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

func Key(line, col int) string

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 Label

func Label(n Node) string

Label is a box's line: what kind of step it is and what it runs.

func Move

func Move(src []byte, n Node, by int) ([]byte, error)

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

func Removed(before, after *Chart) []string

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

func SetText(src []byte, n Node, text string) ([]byte, error)

SetText is src with the text of n's box (its prompt, command or question) changed to text: only that string literal changes.

func Tree

func Tree(c *Chart, mark func(Node) string) string

Tree is the chart as a tree of lines: what a terminal too narrow for the boxes shows. mark gives each box its state's mark (nil: none).

func ValidName

func ValidName(n string) bool

ValidName reports whether n can be a flow's name. "new", "graph" and "runs" are taken by /flow new, /flow graph and /flow runs (ADR 0029).

Types

type Arg

type Arg struct {
	Name string `json:"name"`
	Text string `json:"text"`
}

Arg is a tool's argument: its name, and what it is.

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.

func Changes

func Changes(before, after *Chart, beforeSrc, afterSrc string) ([]Change, int)

Changes are what after changes of before, in after's order (what it takes away last, in before's), and how many steps stay as they were. A step of the same kind and title as one taken away is that one changed.

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.

func Build

func Build(name string, src []byte) (*Chart, error)

Build reads the flow name's script src.

type Edit

type Edit struct {
	Lit   *Span
	Stmt  Lines
	Block []Lines
	Index int
	Whole bool
}

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.

func TreeLines

func TreeLines(c *Chart, mark func(Node) string) (string, []Lines)

TreeLines is Tree, and for each of its lines the script's lines the box is (zero for a line that is no box).

type Need

type Need struct {
	Need  string `json:"need"`
	Phase string `json:"phase"`
}

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.

func (Node) Key

func (n Node) Key() string

Key is the node's call's key ("" for a node that is not a call).

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.

const (
	ReachNone Reach = iota
	ReachFiles
	ReachOutside
)

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

Jump to

Keyboard shortcuts

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