wat

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2018 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const AsciiEnter = 13
View Source
const AsciiEsc = 27
View Source
const AsciiLineFeed = 10
View Source
const Divider = "--------------------\n"

Variables

View Source
var CmdTimeout time.Duration
View Source
var ErrNoWatRoot = errors.New("No wat root found")

Functions

func CmdLogGroupsToFile

func CmdLogGroupsToFile(ws WatWorkspace, gs []CommandLogGroup) error

func Execute

func Execute() (outerErr error)

func Init

func Init(a analytics.Analytics, dir string) error

Init makes the given directory into a wat project root (i.e. creates a .wat/ directory)

func MakeWatIgnore

func MakeWatIgnore(root string) error

func MustJson

func MustJson(obj interface{}) string

func RecentFileInfos

func RecentFileInfos(ws WatWorkspace) ([]fileInfo, error)

func RecentFileNames

func RecentFileNames(ws WatWorkspace) ([]string, error)

func RunCommands

func RunCommands(ctx context.Context, ws WatWorkspace, cmds []WatCommand, timeout time.Duration,
	outStream, errStream io.Writer, logContext LogContext) error

Runs the given commands and logs their results to file for use in making our ML model

func TermBold

func TermBold(s string) string

Types

type CommandList

type CommandList struct {
	Timestamp time.Time
	Commands  []WatCommand
}

func List

Get the list of commands.

If there are already commands on disk fresher than the ttl, return those commands. Otherwise, generates a list of available WatCommands (i.e. command + associated files) and writes them to disk (.wat/list).

Set the ttl to 0 to always regenerate.

type CommandLog

type CommandLog struct {
	// The Command field of WatCommand
	Command string

	Success  bool
	Duration time.Duration
}

type CommandLogGroup

type CommandLogGroup struct {
	Logs    []CommandLog
	Context LogContext
}

All the commands that ran at a particular state of the workspace, grouped together.

func ReadCmdLogGroups

func ReadCmdLogGroups(ws WatWorkspace) ([]CommandLogGroup, error)

func Train

func Train(ctx context.Context, ws WatWorkspace, cmds []WatCommand, ttl time.Duration) ([]CommandLogGroup, error)

Gets training data.

If sufficiently fresh training data lives on disk, return that data. Otherwise, generate new training data and write it to disk.

func (*CommandLogGroup) Add

func (g *CommandLogGroup) Add(l CommandLog)

type CommandWithCondition

type CommandWithCondition struct {
	Condition Condition
	Command   string
}

type Condition

type Condition struct {
	// A known recently-edited file.
	EditedFile string

	// A known successful command.
	SuccessCommand string
}

The environment that a test is run in.

Must be a value struct so that we can use it as a key in a map.

func (Condition) Ancestors

func (c Condition) Ancestors() []Condition

Get all the conditions that are "ancestors" of this condition, from most narrow to most broad.

func (Condition) WithEditedFile

func (c Condition) WithEditedFile(f string) Condition

func (Condition) WithSuccess

func (c Condition) WithSuccess(cmd string) Condition

type CostEstimate

type CostEstimate struct {
	Duration time.Duration
	Count    int

	// If false, we've only seen bootstrapped durations
	Real bool
}

func (CostEstimate) Add

Creates a new cost estimate after working in the old cost estimate.

type DecisionStore

type DecisionStore struct {
	// contains filtered or unexported fields
}

func (DecisionStore) AddCommandLogGroup

func (s DecisionStore) AddCommandLogGroup(g CommandLogGroup)

func (DecisionStore) AddCommandLogGroups

func (s DecisionStore) AddCommandLogGroups(logGroups []CommandLogGroup)

func (DecisionStore) Cost

func (s DecisionStore) Cost(cmd WatCommand) time.Duration

func (DecisionStore) CostSensitiveGain

func (s DecisionStore) CostSensitiveGain(cmd WatCommand, cond Condition) float64

A gain metric. Currently expressed as a unit of gain / cost Gain is directly proportional to failure probability, as explained in the design doc. Cost is expressed in seconds We weight gain higher than cost as gain ^ 2 / cost

func (DecisionStore) FailureProbability

func (s DecisionStore) FailureProbability(cmd WatCommand, cond Condition) float64

func (DecisionStore) HasCost

func (s DecisionStore) HasCost(cmd WatCommand) bool

type LogContext

type LogContext struct {
	// watRoot-relative paths of files that have been recently edited.
	// The definition of "recent" is deliberately fuzzy and might change.
	RecentEdits []string

	StartTime time.Time
	Source    LogSource
}

type LogSource

type LogSource int
const (

	// An edit made by the user
	LogSourceUser LogSource = iota

	// An made-up command-log used to bootstrap training,
	// so that we have interesting data to work with before the
	// user runs any commands.
	LogSourceBootstrap

	// An edit automatically generated by a fuzzer
	LogSourceFuzz

	// Logs generated when the trainer runs the commands
	// in the workspace for the first time.
	LogSourceTrainInit
)

type PackageJSON

type PackageJSON struct {
	Scripts map[string]string `json:"scripts"`
}

type PluginGo

type PluginGo struct{}

type PluginNodeJS

type PluginNodeJS struct {
}

type PluginPytest

type PluginPytest struct{}

type ResultHistory

type ResultHistory struct {
	SuccessCount uint32
	FailCount    uint32
}

func (ResultHistory) Add

func (h ResultHistory) Add(success bool) ResultHistory

type WatCommand

type WatCommand struct {
	Command     string
	FilePattern string
}

func Decide

func Decide(ctx context.Context, ws WatWorkspace, n int) ([]WatCommand, error)

func RunBuiltinPlugins

func RunBuiltinPlugins(ctx context.Context, ws WatWorkspace) (result []WatCommand)

func RunUserPlugins

func RunUserPlugins(ctx context.Context, ws WatWorkspace) (result []WatCommand, err error)

func (WatCommand) Empty

func (c WatCommand) Empty() bool

func (WatCommand) PrettyCmd

func (c WatCommand) PrettyCmd() string

PrettyCmd returns a string suitable for prettily printing this cmd to terminal

type WatCommandCostSort

type WatCommandCostSort struct {
	Commands []WatCommand
	DS       DecisionStore
}

func (WatCommandCostSort) Len

func (s WatCommandCostSort) Len() int

func (WatCommandCostSort) Less

func (s WatCommandCostSort) Less(i, j int) bool

func (WatCommandCostSort) Swap

func (s WatCommandCostSort) Swap(i, j int)

type WatWorkspace

type WatWorkspace struct {
	// contains filtered or unexported fields
}

func GetOrInitWatWorkspace

func GetOrInitWatWorkspace() (WatWorkspace, error)

func GetOrInitWatWorkspaceAt

func GetOrInitWatWorkspaceAt(wd string, a analytics.Analytics) (WatWorkspace, error)

func (WatWorkspace) Append

func (w WatWorkspace) Append(name, contents string) error

Append appends the given contents to the specified file in the .wat dir (<wat_root>/.wat/<name>)

func (WatWorkspace) AppendLine

func (w WatWorkspace) AppendLine(name, contents string) error

AppendLine appends the given contents as a newline

func (WatWorkspace) Exists

func (w WatWorkspace) Exists(name string) (bool, error)

func (WatWorkspace) Fatal

func (ws WatWorkspace) Fatal(msg string, err error)

func (WatWorkspace) Read

func (w WatWorkspace) Read(name string) ([]byte, error)

Read reads the specified file from the .wat dir (<wat_root>/.wat/<name>)

func (WatWorkspace) Root

func (w WatWorkspace) Root() string

func (WatWorkspace) Stat

func (w WatWorkspace) Stat(name string) (os.FileInfo, error)

func (WatWorkspace) WalkDir

func (w WatWorkspace) WalkDir(dir string) ([]fileInfo, error)

func (WatWorkspace) WalkRoot

func (w WatWorkspace) WalkRoot() ([]fileInfo, error)

func (WatWorkspace) Write

func (w WatWorkspace) Write(name, contents string) error

Write (over)writes the specified file in the .wat dir (<wat_root>/.wat/<name>) with the given contents

Jump to

Keyboard shortcuts

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