MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / stableStringify

Function stableStringify

server/src/training-agent/state.ts:142–155  ·  view source on GitHub ↗

* Stable stringify for dirty-detection. * * Sort keys so object equality is positional-independent. Drop * `lastAccessedAt` — we update it on every read, so including it * would make every getSession() look dirty and defeat the * "only flush real mutations" invariant.

(value: unknown)

Source from the content-addressed store, hash-verified

140 * "only flush real mutations" invariant.
141 */
142function stableStringify(value: unknown): string {
143 return JSON.stringify(value, (k, v) => {
144 if (k === 'lastAccessedAt') return undefined;
145 if (v && typeof v === 'object' && !Array.isArray(v)) {
146 const sorted: Record<string, unknown> = {};
147 for (const key of Object.keys(v as Record<string, unknown>).sort()) {
148 if (key === 'lastAccessedAt') continue;
149 sorted[key] = (v as Record<string, unknown>)[key];
150 }
151 return sorted;
152 }
153 return v;
154 });
155}
156
157// ── Session shape helpers ────────────────────────────────────────
158

Callers 3

flushDirtySessionsFunction · 0.70
getSessionFunction · 0.70
findSessionMatchingFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected