agentleFS
air-gappedair-gapped/lessence/.claude/skills/pattern-dev/SKILL.md

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
  1. Very specific:

    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 …

    line 73
  2. Very specific:

    Add pub mod your_pattern; to patterns/mod.rs

    line 74
  3. Very specific:

    Add a DetectorEntry to DETECTOR_ORDER in normalize.rs at the correct position (set enabled, a prefilter if a cheap byte check exists, and …

    line 75
  4. Very specific:

    Add to --disable-patterns handling in main.rs (the disable_patterns → config.normalize_* mapping)

    line 76
  5. Very specific:

    Add stats counter to FoldingStats in folder.rs

    line 77
  6. Distinctive:

    Write unit tests with realistic log samples

    line 78
  7. Very specific:

    Test ReDoS resistance with malicious inputs (see testing skill)

    line 79

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. Timestamps — 30+ formats via unified registry (patterns/timestamp/)
  2. Email — RFC 5322 (patterns/email.rs)
  3. Paths — before Network to preserve URLs (patterns/path.rs)
  4. JSON — structure detection (patterns/json.rs)
  5. UUIDs — standard format (patterns/uuid.rs)
  6. Network — IPs, ports, FQDNs (patterns/network.rs)
  7. Hashes — MD5, SHA1, SHA256, SHA512 (patterns/hash.rs)
  8. Process IDs — PIDs, thread IDs (patterns/process.rs)
  9. Kubernetes — namespaces, pods, volumes (patterns/kubernetes.rs)
  10. HTTP Status — status codes (patterns/http_status.rs)
  11. Bracket Context — [error]-style tags (patterns/bracket_context.rs)
  12. Key-Value — key=value pairs (patterns/key_value.rs)
  13. Log Module — level + module patterns (patterns/log_module.rs)
  14. Structured Messages — component + level token for stats only; the line text is preserved verbatim so distinct messages fold into distinct groups (patterns/structured.rs)
  15. Durations — time and size values (patterns/duration.rs)
  16. Names — variable names (patterns/names.rs) — always enabled
  17. Quoted Strings — last to avoid consuming other tokens (patterns/quoted.rs)

Normalization Pipeline

Normalizer struct in normalize.rs orchestrates detection:

  1. Normalizer::normalize_line(original) -> Result<LogLine> is the entry point
  2. Each detector has DetectorName::detect_and_replace(&normalized) -> (String, Vec<Token>)
  3. normalize_line walks DETECTOR_ORDER, each entry replacing matched content with tokens (<IP>, <TIMESTAMP>, <UUID>, etc.)
  4. The kubernetes deference rule is expressed per-entry in the table: the bracket, log-module, and structured entries carry a defers_to_kubernetes predicate (patterns::has_kubernetes_indicators / has_kubernetes_structured_indicators) that skips them on kubernetes-shaped lines — the detectors themselves no longer check this
  5. The normalized line + tokens are returned as a LogLine
  6. 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 (the TimestampDetector legacy shim was removed; call UnifiedTimestampDetector directly)
  • patterns/timestamp/registry.rs — pattern definitions and merging
  • patterns/timestamp/detector.rs — UnifiedTimestampDetector (the engine)
  • patterns/timestamp/formats.rs — format enum and metadata
  • patterns/timestamp/priority.rs — PatternPriority + FormatFamily (implements the overlap-resolution logic)

Adding a New Pattern

  1. Create src/patterns/your_pattern.rs
  2. Implement pub fn detect_and_replace(line: &str) -> (String, Vec<Token>)
  3. 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 taxonomy owns machine name, display label, stats bucket, sample-worthiness, and value stringification; the folder/renderer consumers are projections of it
  4. Add pub mod your_pattern; to patterns/mod.rs
  5. Add a DetectorEntry to DETECTOR_ORDER in normalize.rs at the correct position (set enabled, a prefilter if a cheap byte check exists, and defers_to_kubernetes if the pattern must yield to KubernetesDetector)
  6. Add to --disable-patterns handling in main.rs (the disable_patterns → config.normalize_* mapping)
  7. Add stats counter to FoldingStats in folder.rs
  8. Write unit tests with realistic log samples
  9. Test ReDoS resistance with malicious inputs (see testing skill)

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.