Skip to main content

Module ttsr

Module ttsr 

Source
Expand description

Time-Traveling Stream Rules engine. TTSR (Time-Traveling Stream Rules) engine.

Monitors streaming model output against project rules. When a rule is violated, the stream is aborted and the rule is injected as a system reminder so the model can correct itself.

Ported from omp packages/coding-agent/src/export/ttsr.ts (TtsrManager).

Two matching modes are supported:

  • Regex: the original condition field, matched against streaming deltas.
  • AST: the optional ast_condition field, matched against file content after tool writes via the TtsrAstMatcher. AST matching shells out to the sg (ast-grep) CLI in the default build — same dependency surface as crate::tools::ast_grep.

Structs§

AstRule
One AST rule: the subset of a Rule that the TtsrAstMatcher cares about. Decoupled from Rule so AST evaluation is independent of regex compilation and so the matcher can be reused without a full rule registry.
Rule
A single TTSR rule.
TtsrAstMatcher
AST condition matcher: holds a list of AstRules, dedups by file digest, and delegates actual pattern matching to an injectable AstMatcherFn.
TtsrEngine
TTSR engine that buffers streaming deltas and checks them against registered rules.
TtsrMatchContext
Context passed to TtsrEngine::check_delta describing what is being generated right now.
TtsrSettings
Knobs for the TTSR engine.

Enums§

InterruptMode
Interrupt mode controlling which stream sources TTSR inspects.
MatchSource
Which stream source produced a delta.
RuleSource
Where a rule originated.
ScopeToken
Which source produced a TTSR match.

Traits§

RuleRegistry
Registry of TTSR rules (supplied by the host).

Type Aliases§

AstMatcherFn
Function signature for the underlying pattern matcher. Given an ast-grep pattern and the file content, return true if the pattern matches at least one node in the content.