MCPcopy
hub / github.com/openai/codex-plugin-cc / saveState

Function saveState

plugins/codex/scripts/lib/state.mjs:92–116  ·  view source on GitHub ↗
(cwd, state)

Source from the content-addressed store, hash-verified

90}
91
92export function saveState(cwd, state) {
93 const previousJobs = loadState(cwd).jobs;
94 ensureStateDir(cwd);
95 const nextJobs = pruneJobs(state.jobs ?? []);
96 const nextState = {
97 version: STATE_VERSION,
98 config: {
99 ...defaultState().config,
100 ...(state.config ?? {})
101 },
102 jobs: nextJobs
103 };
104
105 const retainedIds = new Set(nextJobs.map((job) => job.id));
106 for (const job of previousJobs) {
107 if (retainedIds.has(job.id)) {
108 continue;
109 }
110 removeJobFile(resolveJobFile(cwd, job.id));
111 removeFileIfExists(job.logFile);
112 }
113
114 fs.writeFileSync(resolveStateFile(cwd), `${JSON.stringify(nextState, null, 2)}\n`, "utf8");
115 return nextState;
116}
117
118export function updateState(cwd, mutate) {
119 const state = loadState(cwd);

Callers 3

state.test.mjsFile · 0.90
cleanupSessionJobsFunction · 0.90
updateStateFunction · 0.85

Calls 8

loadStateFunction · 0.85
ensureStateDirFunction · 0.85
pruneJobsFunction · 0.85
defaultStateFunction · 0.85
removeJobFileFunction · 0.85
resolveJobFileFunction · 0.85
removeFileIfExistsFunction · 0.85
resolveStateFileFunction · 0.85

Tested by

no test coverage detected