pattern-dev
Skill4 starsChanged 4 months agoMITView on GitHub
Pattern detection internals — detection order, adding new patterns, normalization pipeline, timestamp architecture. Use when editing src/patterns/ or src/normalize.rs, adding a pattern, fixing detection, changing normalization order.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 1 is distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 73
Add the token variant to Token enum in patterns/mod.rs, plus its KindFacts row in Token::facts() and its arm in Token::value_string() — the …
- Very specific: line 74
Add pub mod your_pattern; to patterns/mod.rs
- Very specific: line 75
Add a DetectorEntry to DETECTOR_ORDER in normalize.rs at the correct position (set enabled, a prefilter if a cheap byte check exists, and …
- Very specific: line 76
Add to --disable-patterns handling in main.rs (the disable_patterns → config.normalize_* mapping)
- Very specific: line 77
Add stats counter to FoldingStats in folder.rs
- Distinctive: line 78
Write unit tests with realistic log samples
- Very specific: line 79
Test ReDoS resistance with malicious inputs (see testing skill)
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pattern Development
Detection Order
Order matters — earlier patterns consume text first, preventing later patterns
from matching the same content. Timestamps before Network preserves URLs.
Quoted strings last to avoid consuming tokens detected by earlier patterns.
The order is declared in one place: the DETECTOR_ORDER table in
normalize.rs (one DetectorEntry per detector with enabled config gate,
prefilter cheap byte check, optional defers_to_kubernetes predicate, and
the run hook). normalize_line just walks the table:
- Timestamps — 30+ formats via unified registry (
patterns/timestamp/) - Email — RFC 5322 (
patterns/email.rs) - Paths — before Network to preserve URLs (
patterns/path.rs) - JSON — structure detection (
patterns/json.rs) - UUIDs — standard format (
patterns/uuid.rs) - Network — IPs, ports, FQDNs (
patterns/network.rs) - Hashes — MD5, SHA1, SHA256, SHA512 (
patterns/hash.rs) - Process IDs — PIDs, thread IDs (
patterns/process.rs) - Kubernetes — namespaces, pods, volumes (
patterns/kubernetes.rs) - HTTP Status — status codes (
patterns/http_status.rs) - Bracket Context —
[error]-style tags (patterns/bracket_context.rs) - Key-Value —
key=valuepairs (patterns/key_value.rs) - Log Module — level + module patterns (
patterns/log_module.rs) - Structured Messages — component + level token for stats only; the line text is preserved verbatim so distinct messages fold into distinct groups (
patterns/structured.rs) - Durations — time and size values (
patterns/duration.rs) - Names — variable names (
patterns/names.rs) — always enabled - Quoted Strings — last to avoid consuming other tokens (
patterns/quoted.rs)
Normalization Pipeline
Normalizer struct in normalize.rs orchestrates detection:
Normalizer::normalize_line(original) -> Result<LogLine>is the entry point- Each detector has
DetectorName::detect_and_replace(&normalized) -> (String, Vec<Token>) normalize_linewalksDETECTOR_ORDER, each entry replacing matched content with tokens (<IP>,<TIMESTAMP>,<UUID>, etc.)- The kubernetes deference rule is expressed per-entry in the table: the bracket, log-module, and structured entries carry a
defers_to_kubernetespredicate (patterns::has_kubernetes_indicators/has_kubernetes_structured_indicators) that skips them on kubernetes-shaped lines — the detectors themselves no longer check this - The normalized line + tokens are returned as a
LogLine - A hash of the normalized text is computed for fast similarity comparison
Token variants are defined in patterns/mod.rs as the Token enum.
Timestamp Architecture
The timestamp system uses a unified registry (patterns/timestamp/registry.rs):
- 30+ patterns covering ISO 8601, RFC 3339, syslog, K8s, Apache, PostgreSQL, etc.
- Longest-match-first — overlap resolution by length, then priority
- Unix timestamps demoted to lowest priority to avoid false positives on plain numbers
- LazyLock for thread-safe static initialization
Key files:
patterns/timestamp/mod.rs— public API re-exports (theTimestampDetectorlegacy shim was removed; callUnifiedTimestampDetectordirectly)patterns/timestamp/registry.rs— pattern definitions and mergingpatterns/timestamp/detector.rs—UnifiedTimestampDetector(the engine)patterns/timestamp/formats.rs— format enum and metadatapatterns/timestamp/priority.rs—PatternPriority+FormatFamily(implements the overlap-resolution logic)
Adding a New Pattern
- Create
src/patterns/your_pattern.rs - Implement
pub fn detect_and_replace(line: &str) -> (String, Vec<Token>) - Add the token variant to
Tokenenum inpatterns/mod.rs, plus itsKindFactsrow inToken::facts()and its arm inToken::value_string()— the taxonomy owns machine name, display label, stats bucket, sample-worthiness, and value stringification; the folder/renderer consumers are projections of it - Add
pub mod your_pattern;topatterns/mod.rs - Add a
DetectorEntrytoDETECTOR_ORDERinnormalize.rsat the correct position (setenabled, aprefilterif a cheap byte check exists, anddefers_to_kubernetesif the pattern must yield to KubernetesDetector) - Add to
--disable-patternshandling inmain.rs(thedisable_patterns→config.normalize_*mapping) - Add stats counter to
FoldingStatsinfolder.rs - Write unit tests with realistic log samples
- Test ReDoS resistance with malicious inputs (see
testingskill)
Essence Mode
--essence is a flag on Config (config.rs:24 essence_mode: bool), not a
separate module. The standalone essence/ module was deleted as dead code.
Timestamps are already tokenized to <TIMESTAMP> by the normal TimestampDetector
in every mode — that's not essence-specific. What --essence actually does is
suppress timestamp variations during variation-type aggregation
(normalize.rs:355-358): when comparing the first and last line in a group,
timestamp token differences are ignored, so groups that differ only by timestamp
don't get flagged as "varying: timestamp" in the rollup.
Net effect: structural comparison between log periods works, because the same template with a different time now counts as the same pattern.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

