walk

package
v0.0.33 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 21 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 walk holds the skill for init's walk: one session reads an area's code, tests and docs and names its capabilities, each a promise with a footprint, and marks every other source file of the area shared with a reason. Footprints are init's own scaffolding, kept in init's record and never in the map.

Index

Constants

View Source
const (
	// Concurrency is the most sessions running at once.
	Concurrency = 3
	// MaxFixRounds is how often a session is sent back its answer's faults.
	MaxFixRounds = 2
)
View Source
const CapabilityDefinition = "" /* 322-byte string literal not displayed */

CapabilityDefinition is the definition of a capability the walk skill carries, word for word as architecture 15 section 4 quotes it.

Variables

View Source
var Split string

Split is the section a top-level area's session gets after Walk: it may split its area once, by promise, into parts that are walked on their own.

View Source
var Walk string

Walk is the walk session's system text: what the map is, what a capability is, how to walk an area, what each capability carries and the shape of the answer.

Functions

func Check

func Check(a Area, ans Answer, split sourceset.Division) (Footprints, Problems)

Check judges a capabilities answer for area a against the split of the repo's files, and returns the footprints it resolves to and what is wrong. A source or shared path is a file or a folder ending with a slash; the most specific claim wins and a tie claims the file twice.

func CheckSplit

func CheckSplit(a Area, ans Answer) ([]Area, Problems)

CheckSplit judges a split answer for area a: two or more parts with unique names, every source file in exactly one. It returns the parts as areas, each with a as its Parent.

func FixPrompt

func FixPrompt(p Problems) string

FixPrompt is the message that sends back everything a check found wrong, grouped, and asks for an answer holding only the changes.

func Message

func Message(a Area, split sourceset.Division, sizes map[string]int) string

Message is the walk session's message for area a: its name and promise (and the area it was split from), its source files one per line with line counts where sizes knows them, and the folders of the repo's test and doc files with counts (and its other files), so the session can Glob them. Everything of the repo's sits in a fence, as data.

func Text

func Text(w io.Writer, r Result) error

Text writes what the walk did in plain words: the totals, the names numbered, each area with its capabilities or its parts, and the model. It names no session and no file.

Types

type Answer

type Answer struct {
	Capabilities []Capability `json:"capabilities"`
	Shared       []Shared     `json:"shared"`
	Split        []Part       `json:"split"`
}

Answer is a walk session's answer: the capabilities and shared files of its area, or the parts it splits into.

func Apply

func Apply(ans Answer, fix Fix) Answer

Apply returns ans with fix applied: removals, drops and moves, then adds, shared files and new capabilities (in a split answer Add names parts).

func Parse

func Parse(text string) (Answer, error)

Parse reads the answer in the last fenced json block of text. An answer with neither capabilities nor a split is an error, worded to follow "the walk answer: ".

type Area

type Area struct {
	Name, Promise, Parent string
	Files                 []string
}

Area is what one walk session is given: an area's name and promise, the area it was split from when it is a part, and its source files.

type AreaResult

type AreaResult struct {
	Name         string   `json:"name"`
	Parent       string   `json:"parent,omitempty"`
	Capabilities []string `json:"capabilities"`
	Owned        int      `json:"owned"`
	Shared       int      `json:"shared"`
	Parts        []string `json:"parts"`
}

AreaResult is one area of a Result, or a part of the split area Parent.

type Capability

type Capability struct {
	Name    string   `json:"name"`
	Promise string   `json:"promise"`
	Sources []string `json:"sources"`
	Tests   []string `json:"tests"`
	Docs    []string `json:"docs"`
	Other   []string `json:"other,omitempty"`
}

Capability is one capability as the session names it: the source files it owns and the tests, docs and other files that bear on it.

type CapabilityRecord

type CapabilityRecord struct {
	Capability
	Area   string `json:"area"`
	Parent string `json:"parent"`
	// Entries are the test, doc and other paths as the session wrote them,
	// folders keeping their trailing slash; empty in an older stored walk.
	Entries Entries `json:"entries,omitempty"`
}

CapabilityRecord is a capability with its footprint, its area and, when that area is a part, the area it was split from.

type Entries

type Entries struct {
	Tests []string `json:"tests,omitempty"`
	Docs  []string `json:"docs,omitempty"`
	Other []string `json:"other,omitempty"`
}

Entries are the paths a footprint names for one kind of file, as written.

type Fix

type Fix struct {
	Add    map[string][]string `json:"add"`
	Shared []Shared            `json:"shared"`
	New    []Capability        `json:"new"`
	Drop   []string            `json:"drop"`
	Remove []string            `json:"remove"`
}

Fix is the answer to FixPrompt: only the changes. Add moves paths to a capability (or a part) from every other claim, Shared marks files shared, New adds capabilities, Drop takes paths back from every claim, and Remove takes capabilities out by name.

func ParseFix

func ParseFix(text string) (Fix, error)

ParseFix reads the answer to FixPrompt from the last fenced json block.

type Footprint

type Footprint struct {
	Name, Promise               string
	Sources, Tests, Docs, Other []string
	Entries                     Entries
}

Footprint is a capability with the source files it owns and the tests, docs and other files that bear on it, every folder expanded to files and sorted. Entries are the test, doc and other paths as the session gave them.

type Footprints

type Footprints struct {
	Capabilities []Footprint
	Shared       []Shared
}

Footprints are an area's capabilities, and its shared files with reasons.

type Part

type Part struct {
	Name    string   `json:"name"`
	Promise string   `json:"promise"`
	Sources []string `json:"sources"`
}

Part is one part of a split area.

type Problems

type Problems struct {
	// Split is set when the answer checked was a split.
	Split bool
	// Unclaimed are source files owned by none and not shared.
	Unclaimed []string
	// Twice maps a source file to the owners that both claim it.
	Twice map[string][]string
	// Outside are "owner: path" for source or shared paths matching no file
	// of the area.
	Outside []string
	// NotTest, NotDoc and NotOther are "capability: path" for tests, docs and
	// other paths matching no file the split named a test, a doc or other.
	NotTest, NotDoc, NotOther []string
	// NoSource are the capabilities (or parts) owning no source file.
	NoSource []string
	// Names are the other faults: a repeated, malformed or empty name, an
	// empty promise, too few parts.
	Names []string
}

Problems are what a check found wrong with an answer. Each list is empty when it found nothing of that kind.

func (Problems) Empty

func (p Problems) Empty() bool

Empty reports whether nothing was found.

type Record

type Record struct {
	Capabilities []CapabilityRecord `json:"capabilities"`
	Shared       []SharedRecord     `json:"shared"`
	Splits       []SplitRecord      `json:"splits"`
	Renamed      []Rename           `json:"renamed"`
	Sessions     []string           `json:"sessions"`
}

Record is the body init's record keeps for the walk, read back with Load. Its file paths are init's own and never reach the map.

func Load

func Load(st *initrecord.Store) (Record, bool, error)

Load reads the stored walk and decodes its body, false when none exists.

type Rename

type Rename struct {
	Area string `json:"area"`
	From string `json:"from"`
	To   string `json:"to"`
}

Rename is a name an earlier area took: Area's From is kept as To.

type Result

type Result struct {
	Areas        []AreaResult   `json:"areas"`
	Capabilities int            `json:"capabilities"`
	Owned        int            `json:"owned"`
	Shared       int            `json:"shared"`
	Unclaimed    int            `json:"unclaimed"`
	FixRounds    int            `json:"fix_rounds"`
	Renamed      []Rename       `json:"renamed"`
	Model        string         `json:"model"`
	Tokens       adapter.Tokens `json:"tokens"`
}

Result is what the walk ended with: each area in stored order, its parts after it, and the totals. Unclaimed is 0 when the walk was stored.

func Run

func Run(ctx context.Context, st Store, s Session) (Result, error)

Run is init's walk: one read-only session per stored area, at most Concurrency at once, names the area's capabilities with their footprints and its shared files, or splits it once into parts walked the same way. The walk is stored in init's record only when every area ended whole; otherwise the error names each that failed. Nothing reaches the repo or map.

type Session

type Session struct {
	Agent    func() (adapter.Adapter, error)
	Root     string
	Progress io.Writer
	Now      func() time.Time
}

Session is the agent, the root its sessions read, progress and the clock.

type Shared

type Shared struct {
	Path   string `json:"path"`
	Reason string `json:"reason"`
}

Shared is a source file, or a folder ending with a slash, kept by many capabilities or by none, with the reason.

type SharedRecord

type SharedRecord struct {
	Shared
	Area string `json:"area"`
}

SharedRecord is a source file no capability owns, with its area.

type SplitRecord

type SplitRecord struct {
	Area  string             `json:"area"`
	Parts []areas.AreaRecord `json:"parts"`
}

SplitRecord is an area a session split, with the parts walked in its place.

type Store

type Store interface {
	Areas(ctx context.Context) (initrecord.Areas, bool, error)
	PutWalk(context.Context, initrecord.Walk) error
}

Store is init's record as the walk uses it.

Jump to

Keyboard shortcuts

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