MCPcopy
hub / github.com/OpenCoworkAI/open-codesign / recordDiagnosticEvent

Function recordDiagnosticEvent

apps/desktop/src/main/snapshots-db.ts:531–578  ·  view source on GitHub ↗
(
  db: Database,
  input: DiagnosticEventInput,
  now: () => number = Date.now,
)

Source from the content-addressed store, hash-verified

529}
530
531export function recordDiagnosticEvent(
532 db: Database,
533 input: DiagnosticEventInput,
534 now: () => number = Date.now,
535): number {
536 return mutateStore(db, (data) => {
537 const ts = now();
538 const recent = data.diagnosticEvents
539 .filter(
540 (event) =>
541 event.fingerprint === input.fingerprint && event.ts > ts - DIAGNOSTIC_DEDUP_WINDOW_MS,
542 )
543 .sort((a, b) => b.ts - a.ts || b.id - a.id)[0];
544 if (recent !== undefined) {
545 const idx = data.diagnosticEvents.findIndex((event) => event.id === recent.id);
546 if (idx >= 0) {
547 const current = data.diagnosticEvents[idx];
548 if (current === undefined) return recent.id;
549 data.diagnosticEvents[idx] = {
550 ...current,
551 ts,
552 transient: current.transient || input.transient,
553 count: current.count + 1,
554 };
555 }
556 return recent.id;
557 }
558
559 const id =
560 data.diagnosticEvents.reduce((max, event) => (event.id > max ? event.id : max), 0) + 1;
561 data.diagnosticEvents.push({
562 id,
563 schemaVersion: 1,
564 ts,
565 level: input.level,
566 code: input.code,
567 scope: input.scope,
568 runId: input.runId,
569 fingerprint: input.fingerprint,
570 message: input.message,
571 stack: input.stack,
572 transient: input.transient,
573 count: 1,
574 context: input.context,
575 });
576 return id;
577 });
578}
579
580export function getDiagnosticEventById(db: Database, id: number): DiagnosticEventRow | undefined {
581 const row = readStore(db).diagnosticEvents.find((event) => event.id === id);

Callers 6

registerDiagnosticsIpcFunction · 0.90
recordFinalErrorFunction · 0.90
coreLoggerForFunction · 0.90

Calls 1

mutateStoreFunction · 0.85

Tested by

no test coverage detected