pi / packages /coding-agent /src /core /settings-diagnostics.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
f500658 verified
Raw History Blame Contribute Delete
986 Bytes
import type { AgentSessionRuntimeDiagnostic } from "./agent-session-services.ts";
import type { SettingsManager } from "./settings-manager.ts";
export function collectSettingsDiagnostics(settingsManager: SettingsManager): AgentSessionRuntimeDiagnostic[] {
return settingsManager.drainErrors().map(({ scope, path, error }) => ({
type: "warning",
message: path ? `Invalid settings file ${path}: ${error.message}` : `Invalid ${scope} settings: ${error.message}`,
}));
}
/**
* Remove duplicate type/message diagnostics while preserving their first occurrence.
* Startup and runtime settings managers can report the same file error.
*/
export function deduplicateDiagnostics(
diagnostics: readonly AgentSessionRuntimeDiagnostic[],
): AgentSessionRuntimeDiagnostic[] {
const seen = new Set<string>();
return diagnostics.filter((diagnostic) => {
const key = `${diagnostic.type}\0${diagnostic.message}`;
if (seen.has(key)) return false;
seen.add(key);
return true;
});
}