Loop Detector

pi-cyberneticsourcetypescript
Path: pi-cybernetic/src/monitors/loop-detector.tsRelative: src/monitors/loop-detector.tsSubproject: pi-cyberneticCategory: cybernetic-core
Lines: 100Bytes: 3,235Imports: 2Exports: 2

Content Preview

  1. /** P5 — action-sequence loop detection over a sliding window. */
  2. import type { Escalation } from "../types/index.ts";
  3. import { shannonEntropy, stableStringify } from "../util.ts";
  4. export interface RecordedAction {
  5. toolName: string;
  6. args: unknown;
  7. }
  8. export class LoopDetector {
  9. private window: string[] = [];
  10. private detections = 0;
  11. /** Repetition count at the moment of the last detection. */
  12. private lastDetectionLatency = 0;
  13. /** Signature already escalated — suppresses duplicate