Kavi
Patterns

Patterns

Automatic pattern extraction from landing reports for cross-session knowledge reuse.

Patterns

Patterns are a beta feature. The API surface and behavior may change in future releases.

Patterns are extracted automatically from landing reports after a successful kavi land. They capture what was done, what files were touched, what commands were used, and relevant metadata -- then persist across sessions so that future missions benefit from prior experience.

How Patterns Work

When a mission lands successfully, Kavi analyzes the landing report and extracts a pattern record. This pattern encodes the shape of the work: the title and summary, the file paths that were changed, the commands that were run, and tags derived from the codebase context.

When a new mission starts, Kavi searches the pattern library for the top 3 matching patterns and promotes them into the mission's brain as "Pattern: ..." entries. This gives agents context about how similar work was done before, including which files to look at and which commands to run.

Pattern Storage

Patterns are stored in a JSON file at the repository root:

.kavi-patterns.json

This file persists across sessions and is meant to be committed to version control so the entire team benefits from accumulated patterns.

PatternEntry Interface

The following fields make up a pattern entry:

FieldTypeDescription
idstringUnique pattern identifier
sourceRepoRootstringAbsolute path to the repository root where the pattern was extracted
missionIdstring | nullID of the mission that produced this pattern
reportIdstring | nullID of the landing report that produced this pattern
titlestringShort title summarizing the pattern
summarystringDetailed description of the work that was done
promptstring | nullThe original mission prompt, if available
tagsstring[]Tags for categorization and matching
examplePathsstring[]File paths that were changed as part of this pattern
commandsstring[]Commands that were used (test runners, build scripts, etc.)
createdAtstringISO timestamp of creation
updatedAtstringISO timestamp of last update

Deduplication

Pattern deduplication uses a fingerprint computed from:

  • Normalized title (lowercased, trimmed)
  • Sorted tags
  • Repository root path

If a pattern with the same fingerprint already exists, Kavi merges the new data into the existing record:

  • summary, prompt, reportId, and missionId are updated to the latest values
  • tags, examplePaths, and commands are unioned (no duplicates)
  • updatedAt is refreshed

This keeps the pattern library compact while accumulating knowledge over time.

Tag Extraction

Tags are automatically extracted from multiple sources:

  • File extensions -- e.g., .ts, .tsx, .go, .rs become tags like typescript, react, go, rust
  • Path segments -- directory names from changed file paths (e.g., src/api/ produces api)
  • Mission context -- tokens from the mission title and prompt that match known categories

Tag extraction is capped at 20 tags per pattern to keep entries focused.

Command Detection

Kavi detects commands from two sources:

  • package.json scripts -- test, build, lint, and other scripts defined in the project's package.json
  • Common test/build commands -- npm test, go test, cargo test, pytest, npm run build, and other standard commands detected from the repository structure

Detected commands are stored in the pattern so that future missions working on similar code know which validation commands to run.

CLI Commands

# List all patterns, or search with a query
kavi patterns
kavi patterns "api endpoint"

kavi patterns displays the stored pattern library with titles, tags, and example paths. With a query argument, it filters patterns by relevance.

On this page