MCPcopy Create free account
hub / github.com/cursor/plugins / loadState

Function loadState

continual-learning/hooks/continual-learning-stop.ts:65–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

63}
64
65function loadState(): ContinuousLearningState {
66 const fallback: ContinuousLearningState = {
67 version: 1,
68 lastRunAtMs: 0,
69 turnsSinceLastRun: 0,
70 lastTranscriptMtimeMs: null,
71 lastProcessedGenerationId: null,
72 trialStartedAtMs: null,
73 };
74
75 if (!existsSync(STATE_PATH)) {
76 return fallback;
77 }
78
79 try {
80 const raw = readFileSync(STATE_PATH, "utf-8");
81 const parsed = JSON.parse(raw) as Partial<ContinuousLearningState>;
82 if (parsed.version !== 1) {
83 return fallback;
84 }
85 return {
86 version: 1,
87 lastRunAtMs:
88 typeof parsed.lastRunAtMs === "number" && Number.isFinite(parsed.lastRunAtMs)
89 ? parsed.lastRunAtMs
90 : 0,
91 turnsSinceLastRun:
92 typeof parsed.turnsSinceLastRun === "number" &&
93 Number.isFinite(parsed.turnsSinceLastRun) &&
94 parsed.turnsSinceLastRun >= 0
95 ? parsed.turnsSinceLastRun
96 : 0,
97 lastTranscriptMtimeMs:
98 typeof parsed.lastTranscriptMtimeMs === "number" &&
99 Number.isFinite(parsed.lastTranscriptMtimeMs)
100 ? parsed.lastTranscriptMtimeMs
101 : null,
102 lastProcessedGenerationId:
103 typeof parsed.lastProcessedGenerationId === "string"
104 ? parsed.lastProcessedGenerationId
105 : null,
106 trialStartedAtMs:
107 typeof parsed.trialStartedAtMs === "number" &&
108 Number.isFinite(parsed.trialStartedAtMs)
109 ? parsed.trialStartedAtMs
110 : null,
111 };
112 } catch {
113 return fallback;
114 }
115}
116
117function saveState(state: ContinuousLearningState): void {
118 const directory = dirname(STATE_PATH);

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected