MCPcopy Index your code
hub / github.com/WithSecureLabs/tau-engine

github.com/WithSecureLabs/tau-engine @v1.15.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.15.0 ↗ · + Follow
182 symbols 476 edges 17 files 15 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Tau Engine

crates.io Documentation

This crate provides a library that tags documents by running and matching rules over them.

Overview

The engine makes use of a Pratt parser and a tree solver in order to evaluate the detection logic of a rule against a document, if the outcome is true the document is considered tagged by that rule.

Rules

A rule is used to tag a document and is made up of three parts: - detection: the logic used to evaluate a document. - true positives: example documents that must evaluate to true for the given detection. - true negatives: example documents that must evaluate to false for the given detection.

The detection block is made up of a condition, and identifiers. This allows for simple but expressive rules, below is a brief summary:

Identifiers

Identifiers are used to help keep the condition concise and generally contain the core of the matching logic. They consist of Key/Value pairs which allow for the extraction of data from the document and the evaluate of its value. It should be noted that mappings are treated as conjunctions, while sequences are treated as disjunctions.

Identifiers make use of the following matching logic: - foobar: an exact match of foobar - foobar*: starts with foobar - *foobar: ends with foobar - *foobar*: contains foobar - ?foobar: regex foobar

Any of the above can be made case insensitive with the i prefix, for example: - ifoobar - ifoobar*

Escaping can be achieved with a combination of ' and ".

Condition

The condition is just a boolean expression and supports the following: - and: logical conjunction - or: logical disjunction - ==: equality comparison - >, >=, <, <=: numeric comparisons - not: negate - all(i): make sequences behave as conjunctions - of(i, x): ensure a sequence has a minimum number of matches

Examples

This is an example of how the engine can tag a document against a provided rule:

tau-engine = "1.0"
use std::borrow::Cow;

use tau_engine::{Document, Rule, Value};

// Define a document.
struct Foo {
    foo: String,
}
impl Document for Foo {
    fn find(&self, key: &str) -> Option<Value<'_>> {
        match key {
            "foo" => Some(Value::String(Cow::Borrowed(&self.foo))),
            _ => None,
        }
    }
}

// Write a rule.
let rule = r#"
detection:
  A:
    foo: foobar
  condition: A
true_positives:
- foo: foobar
true_negatives:
- foo: foo
"#;

// Load and validate a rule.
let rule = Rule::load(rule).unwrap();
assert_eq!(rule.validate().unwrap(), true);

// Create a document.
let foo = Foo {
    foo: "foobar".to_owned(),
};

// Evalute the document with the rule.
assert_eq!(rule.matches(&foo), true);

This is an example of how the engine can be used to tag on JSON.

tau-engine = { version = "1.0", features = ["json"] }
use serde_json::json;
use tau_engine::{Document, Rule};

// Write a rule.
let rule = r#"
detection:
  A:
    foo: foobar
  condition: A
true_positives:
- foo: foobar
true_negatives:
- foo: foo
"#;

// Load and validate a rule.
let rule = Rule::load(rule).unwrap();
assert_eq!(rule.validate().unwrap(), true);

// Create a document.
let foo = json!({
    "foo": "foobar",
});

// Evalute the document with the rule.
assert_eq!(rule.matches(&foo), true);

Extension points exported contracts — how you extend this code

AsValue (Interface)
(no doc) [10 implementers]
src/value.rs
Document (Interface)
(no doc) [6 implementers]
src/document.rs
Tokeniser (Interface)
Tokenise data into a collection of Tokens to then be used by the parser. This trait converts a tau engine condition into [1 …
src/tokeniser.rs
IdentifierParser (Interface)
Parse data into an Identifier. This trait parses a Tau Engine identifier into an `Identifier`. [1 implementers]
src/identifier.rs
Object (Interface)
(no doc) [4 implementers]
src/value.rs
Array (Interface)
(no doc) [2 implementers]
src/value.rs

Core symbols most depended-on inside this repo

to_string
called by 73
src/value.rs
len
called by 59
src/yaml.rs
parse_invalid_token
called by 47
src/error.rs
as_str
called by 41
src/value.rs
iter
called by 38
src/value.rs
parse_invalid_ident
called by 25
src/error.rs
find
called by 20
src/solver.rs
tokenise
called by 19
src/tokeniser.rs

Shape

Function 90
Method 60
Enum 16
Class 10
Interface 6

Languages

Rust100%

Modules by API surface

src/tokeniser.rs29 symbols
src/value.rs28 symbols
src/parser.rs26 symbols
src/optimiser.rs21 symbols
src/error.rs18 symbols
src/rule.rs14 symbols
src/identifier.rs14 symbols
src/solver.rs11 symbols
src/json.rs5 symbols
src/yaml.rs4 symbols
src/document.rs4 symbols
tests/common.rs2 symbols

For agents

$ claude mcp add tau-engine \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact