# All files / lib/reflection index.ts

43.85% Statements 25/57
50% Branches 2/4
50% Functions 2/4
43.85% Lines 25/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    711x

    1x
    1x
    1x
    1x
    1x
    1x
    1x

    1x

    1x
    2x
    2x
    2x

    1x
    1x
    1x
    1x

    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
     // lib/reflection/index.ts

    import { isReflectionEnabled, isVerbose } from './flags';
    import { startIntrospection, stopIntrospection, _resetIntrospection } from './introspection';
    import { evaluateSignal } from './evaluator';
    import { applyDecisions, makeDecision, _resetFeedbackForTests as _resetFeedback } from './feedback';
    import { applyPolicyAdjustments, getPolicyState, _resetPolicyManager } from './policy';
    import { addToMemory, _resetMemory } from './memory';
    import {
      publishSignal,
      publishEvaluation,
      publishDecision,
      publishPolicyChange,
    } from './observe';

    let isRunning = false;

    function onSignal(signal: any) {
      // This will be updated to handle arrays of signals/evaluations later
      const evaluation = evaluateSignal(signal);
      publishEvaluation(evaluation);
      addToMemory({ evaluation });

      const decisions = makeDecision([evaluation]);
      if (decisions.length > 0) {
          decisions.forEach(decision => {
              publishDecision(decision);
              addToMemory({ decision });
          });
          applyDecisions(decisions);
      }
    }

    export function startSelfReflection(): void {
      if (isRunning || !isReflectionEnabled()) {
        return;
      }
      if (isVerbose()) {
        console.log('[Reflection] Starting Self-Reflection System...');
      }
      startIntrospection(onSignal);
      isRunning = true;
    }

    export function stopSelfReflection(): void {
      if (!isRunning) {
        return;
      }
      if (isVerbose()) {
        console.log('[Reflection] Stopping Self-Reflection System...');
      }
      stopIntrospection();
      isRunning = false;
    }

    export function _resetReflectionSystem(): void {
        stopSelfReflection();
        _resetIntrospection();
        _resetPolicyManager();
        _resetMemory();
        _resetFeedback();
    }

    // Export all types and public functions
    export * from './flags';
    export * from './types';
    export * from './policy';
    export * from './memory';
    export * from './evaluator';
    export * from './feedback';