-
Notifications
You must be signed in to change notification settings - Fork 0
Pattern Detection
Zeref OS extends itself only via review-first drafts. The loop:
session events → PATTERNS.jsonl → pattern-observer (background scan)
→ 48-80h rolling window, Jaccard ≥0.8, ≥3 occurrences
→ cluster + score → top-3 surfaced per scan
→ pattern-to-skill drafts SKILL.md to skills/drafts/
→ user reviews via /review-skill (approve/edit/reject/defer)
→ approved drafts promoted to skills/<name>/ via git mv (preserves history)
Never auto-activated. Per Core Principle 10 (Review-First Extension).
Do not codify a rule on the first occurrence of an error. Wait for the second.
| Occurrence | Action |
|---|---|
| First | Log to memory/MEMORY.md as a trap noticed |
| Second | Promote to a rule — codify in _shared/rules.md, agent prompt, or new skill |
Why: Premature codification creates brittle rules that don't generalize. Two occurrences = pattern; one = noise.
v2.6.1 example: C1 memory drift (ship cycles without wiki-maintenance) — first occurrence logged to memory/MEMORY.md. Second occurrence will trigger automation requirement (auto-fire wiki-maintenance on /stop).
See references/two-strikes-rule.md for full doctrine.
Per AGENTS.md + skill spec:
-
Window: rolling 48-80h scan of
memory/patterns/PATTERNS.jsonl - Task signature: verb + subject + 3-gram qualifiers (stop-words stripped)
- Similarity: Jaccard 3-gram ≥ 0.8 over qualifier sets
- Clustering: union-find; discard clusters < 3 members
-
Scoring:
frequency × (1 / recency_span_hours)(favors dense recent repetition) -
Output: top-3 by score per scan →
memory/sync/outbound/patterns/<cluster-id>.json -
Dedupe: by
cluster_id; update existing candidates with new members - Quiet hours: rest logged as suppressed (no overflow)
-
Activation:
/done,/stop,/status, manual - Background only: never blocks active work
User can disable via config/BUDGET.md pattern_detection: false.
When a candidate cluster surfaces:
-
DRAFT operation:
- Load candidate JSON
- Synthesize metadata:
name,description,trigger,model,max_turns - Synthesize body: mission, when-to-use, operations, safety
- Write
skills/drafts/<name>/SKILL.md - Write immutable
skills/drafts/<name>/PROVENANCE.md(cites every source event by hash) - v2.6.1 R6: PROVENANCE.md must preserve every entity that contributed to the pattern (tool names, file paths, repeated arguments)
-
REVIEW QUEUE (
/review-skill):- Lists pending drafts with score + event count + description
-
Per-draft prompt:
- Show frontmatter + body + provenance summary
- 4 actions:
-
approve →
git mv skills/drafts/<name>/ skills/<name>/; strip draft markers; log to DECISIONS.md - edit → open file in editor; re-prompt after save
-
reject → prompt reason;
rm -rfdraft dir; mark candidate JSONrejected_at - defer → leave in place; increment counter; auto-prompt again after 3 defers
-
approve →
PROVENANCE.md is immutable — never edited after creation. Approval doesn't touch it.
scripts/zeref-validate.py surfaces drafts as warnings:
Warnings:
! skills/drafts/ contains 1 pending draft(s) — run /review-skill
Validator does NOT block on drafts. Drafts are read-only artifacts until promoted.
Single draft currently in skills/drafts/grep-with-context/ (v2.5 L8 dogfood). Demonstrates the full pipeline:
- 4 events in
PATTERNS.jsonlwithevent: grep-with-context, action: "grep -r -B2 -A2 trigger"clustered together -
pattern-observersurfaced cluster (score > threshold) -
pattern-to-skilldrafted SKILL.md with PROVENANCE - Awaits user
/review-skilldecision
Examples of patterns the system would surface:
- Repeated
grep -r --includeoverskills/(3+ in 24h) → draftskill-searchskill - Repeated PII regex addition to
REDACT.md(4 distinct patterns added) → draftredact-helperskill - Repeated tier-override (5 instances of
CRITICAL on HAIKU) → suggest reclassifying CRITICAL or accepting Haiku for that workload (v2.6.1 L13 dual-key triggers this) - Repeated
wiki-maintenanceskip on ship cycles → trigger memory-drift remediation (C1)
- Never auto-activate: review-first per Core Principle 10
-
Never overwrite PROVENANCE: immutable per
pattern-to-skillspec -
Never delete rejected candidates: mark
rejected_atin JSON for future revisit (R2 non-deletion) - Never surface candidates that share signature with a user-rejected one within retention window
- R6 (v2.6.1): draft must preserve every entity from PATTERNS source events
- Memory-Model — PATTERNS.jsonl schema + 11 event types
-
Architecture —
pattern-observeragent +pattern-to-skillskill - Glossary — Two-Strikes Rule, pattern signature, cluster_id
references/two-strikes-rule.md
Getting Started
Architecture
- Architecture · 14 skills · 4 gates
- Memory-Model · flat + PATTERNS schema
- Privacy-Model · 3 modes + R6
- Team-Packs · 6 on-demand
- Pattern-Detection · Two-Strikes
Reference