pattern

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package pattern turns a stream of recorded commands into reusable-recipe suggestions, deterministically and without any machine learning.

The approach is structural template mining (the Drain/IPLoM family applied to shell commands): commands are tokenized and grouped by a structural signature, then the slots that vary across a group's occurrences become fill-in-the-blank parameters. Crucially, what counts as a "value" is learned from observed variation — yore never has to understand a token's meaning — so the whole thing is a pure function of the input, reproducible and offline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyOf

func KeyOf(command string) string

KeyOf returns the structural key for a single command — the same identity Detect assigns to its group — so callers can match a command against existing recipes or dismissed suggestions.

Types

type Candidate

type Candidate struct {
	Name     string    // proposed recipe name
	Template string    // command with {blanks}, ready to display/save
	Params   []Param   // the blanks, in template order
	Count    int       // occurrences (within the recency window)
	Dirs     []string  // distinct directories it ran in (capped)
	LastUsed time.Time // most recent occurrence
	Key      string    // stable structural id, for dedup and dismissal
}

Candidate is a suggested recipe mined from repeated usage.

func Detect

func Detect(obs []Observation, opts Options) []Candidate

Detect mines suggestions from observations. It is deterministic: the same input always yields the same candidates.

type Observation

type Observation struct {
	Command string
	Dir     string
	Time    time.Time
}

Observation is one recorded command run, the only input the engine needs.

type Options

type Options struct {
	MinCount     int           // minimum occurrences to suggest (default 5)
	RecentWithin time.Duration // ignore commands older than this (default 30d; 0 = no limit)
	Now          time.Time     // reference time (default time.Now)
	MaxValues    int           // cap on evidence values shown per param (default 5)
	Limit        int           // cap on candidates returned (0 = all)
}

Options tunes detection.

type Param

type Param struct {
	Name   string
	Values []string
}

Param is an inferred fill-in-the-blank, with the distinct values observed for it (the evidence that makes the inference legible).

Jump to

Keyboard shortcuts

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