@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
30 lines • 1.34 kB
JavaScript
import { createHash } from "node:crypto";
import { keyedIdentity } from "./config-identity-key.js";
export function hashConfig(config, agentDir) {
return keyedIdentity(agentDir, hashableConfig(config));
}
/** The unkeyed identity earlier builds persisted; read only to adopt a matching cache entry. */
export function legacyHashConfig(config) {
return createHash("sha256").update(hashableConfig(config)).digest("hex");
}
function hashableConfig(config) {
// startupTimeoutMs is a client-side startup-race policy, not a connection or
// catalog-shape input. Excluding it from the identity hash keeps the catalog
// cache valid across upgrades (configs written before the field existed hash
// identically) and avoids a needless reconnect when only the window changes.
const hashable = { ...config };
delete hashable.startupTimeoutMs;
return stableStringify(hashable);
}
function stableStringify(value) {
if (Array.isArray(value))
return `[${value.map(stableStringify).join(",")}]`;
if (typeof value === "object" && value !== null) {
return `{${Object.keys(value)
.sort()
.map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`)
.join(",")}}`;
}
return JSON.stringify(value);
}
//# sourceMappingURL=config-identity.js.map