All files / src graded-session.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 5/5
100% Lines 14/14

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                        1x 1x   1x   1x 9x     1x 7x     1x 14x 14x     1x 9x     1x 4x    
/**
 * graded-session.ts
 *
 * Module-level flag tracking whether the current Pi session is in graded mode.
 * Set to true by attempt-capture after dispatching an /attempt injection;
 * read by integrity-guard's before_agent_start hook to reinforce evaluation
 * constraints on every subsequent agent turn.
 *
 * Pi is single-process per session, so module-level state has session granularity
 * and resets automatically when Pi restarts.
 */
 
let _active = false;
let _jailbreakCount = 0;
 
export const JAILBREAK_ESCALATION_THRESHOLD = 3;
 
export function setGradedMode(active: boolean): void {
  _active = active;
}
 
export function isGradedModeActive(): boolean {
  return _active;
}
 
export function resetGradedMode(): void {
  _active = false;
  _jailbreakCount = 0;
}
 
export function incrementJailbreakCount(): number {
  return ++_jailbreakCount;
}
 
export function getJailbreakCount(): number {
  return _jailbreakCount;
}