primitive: correlation -- relate two patterns within a file #78

Closed
opened 2026-05-26 05:16:12 +02:00 by michael · 2 comments
Owner

Goal

Add a correlation primitive that can relate two patterns within
the same file -- enabling rules like "if pattern A is present,
pattern B must also be present (or must not be present)".

Motivation

Current primitives check one thing at a time. Some findings require
relating two observations:

  • "sha256sum in io.popen AND no require(daw.common.crypto)" -> finding
  • "io.open for writing AND no require(daw.common.fs)" -> finding
  • "os.execute present AND out:run_rc also present" -> inconsistency

These cannot be expressed with the existing pattern primitive alone.

Concept

primitive: correlation
if_match: "io.popen.*sha256"
must_not_match: "require.*daw.common.crypto"
message: "raw sha256 detected without daw.common.crypto"

Notes

Long-term vision: fragjan learns to detect common function signatures
automatically across a codebase. This primitive is the foundation.
Automatic detection is a separate, later effort.

Related: no-reimplement rules (DAW/fragjan#76)

Acceptance Criteria

  • correlation primitive spec defined (fragjan_primitive/v1)
  • Prototype implementation
  • At least one rule uses it
  • Tested against known cases
## Goal Add a `correlation` primitive that can relate two patterns within the same file -- enabling rules like "if pattern A is present, pattern B must also be present (or must not be present)". ## Motivation Current primitives check one thing at a time. Some findings require relating two observations: - "sha256sum in io.popen AND no require(daw.common.crypto)" -> finding - "io.open for writing AND no require(daw.common.fs)" -> finding - "os.execute present AND out:run_rc also present" -> inconsistency These cannot be expressed with the existing `pattern` primitive alone. ## Concept ```yaml primitive: correlation if_match: "io.popen.*sha256" must_not_match: "require.*daw.common.crypto" message: "raw sha256 detected without daw.common.crypto" ``` ## Notes Long-term vision: fragjan learns to detect common function signatures automatically across a codebase. This primitive is the foundation. Automatic detection is a separate, later effort. Related: no-reimplement rules (DAW/fragjan#76) ## Acceptance Criteria - [ ] correlation primitive spec defined (fragjan_primitive/v1) - [ ] Prototype implementation - [ ] At least one rule uses it - [ ] Tested against known cases
michael added this to the Basic Version milestone 2026-05-30 16:08:42 +02:00
Author
Owner

Spec: filecorrelation primitive

Primitive ID: daw.fragjan.check.filecorrelation
Module: daw-modul-fragjan-check-filecorrelation
Lua require: daw.fragjan.check.filecorrelation

Parameters

if_match: "pattern"        # trigger: is file relevant at all?
must_match: "pattern"      # optional: must also be present in file
must_not_match: "pattern"  # optional: must not be present in file
skip_comments: true         # consistent with other primitives

At least one of must_match / must_not_match is required.

Semantics (file-level, not line-level)

  • if_match no match -> skip (file not affected)
  • if_match matches + must_match missing -> finding
  • if_match matches + must_not_match present -> finding
  • Both patterns match anywhere in the file, independent of line

Example

primitive: daw.fragjan.check.filecorrelation
if_match: "io.popen.*sha256"
must_not_match: "require.*daw.common.crypto"
skip_comments: true

Related: DAW/fragjan#104 (next session priorities)

## Spec: filecorrelation primitive Primitive ID: `daw.fragjan.check.filecorrelation` Module: `daw-modul-fragjan-check-filecorrelation` Lua require: `daw.fragjan.check.filecorrelation` ### Parameters ```yaml if_match: "pattern" # trigger: is file relevant at all? must_match: "pattern" # optional: must also be present in file must_not_match: "pattern" # optional: must not be present in file skip_comments: true # consistent with other primitives ``` At least one of `must_match` / `must_not_match` is required. ### Semantics (file-level, not line-level) - `if_match` no match -> `skip` (file not affected) - `if_match` matches + `must_match` missing -> finding - `if_match` matches + `must_not_match` present -> finding - Both patterns match anywhere in the file, independent of line ### Example ```yaml primitive: daw.fragjan.check.filecorrelation if_match: "io.popen.*sha256" must_not_match: "require.*daw.common.crypto" skip_comments: true ``` Related: DAW/fragjan#104 (next session priorities)
Author
Owner

Implementation

Implemented as DAW/fragjan#105 (fragjan-check-filecorrelation 0.1.0).

The filecorrelation primitive covers file-level correlation between
two patterns. First rule using it: no-raw-sha256-popen (DAW/fragjan#77).

Note: more complex cases (reimpl alongside legitimate require) require
project-level analysis -- foundation for anagild integration.

## Implementation Implemented as DAW/fragjan#105 (fragjan-check-filecorrelation 0.1.0). The filecorrelation primitive covers file-level correlation between two patterns. First rule using it: no-raw-sha256-popen (DAW/fragjan#77). Note: more complex cases (reimpl alongside legitimate require) require project-level analysis -- foundation for anagild integration.
michael 2026-05-31 19:40:08 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/fragjan#78
No description provided.