aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
35 lines • 1.29 kB
JavaScript
/**
* Deterministic cache key composition.
*
* The hash includes content hashes (not just artifact IDs) so file edits
* invalidate the cache cleanly. Inputs are sorted by artifactId so caller
* order does not affect the resulting hash.
*
* @implements #1203
* @see .aiwg/architecture/adr-rlm-index-features-impl-plan.md
*/
import { createHash } from 'node:crypto';
/** Compute a stable sha256 hex hash for a cache key. */
export function computeHash(key) {
const sortedInputs = [...key.inputs].sort((a, b) => a.artifactId.localeCompare(b.artifactId));
const canonical = JSON.stringify({
inputs: sortedInputs,
query: key.query,
subPrompt: key.subPrompt,
model: key.model,
aggregateStrategy: key.aggregateStrategy,
});
return createHash('sha256').update(canonical).digest('hex');
}
/** Validate a cache key has the minimum required fields. */
export function isCacheKey(value) {
if (!value || typeof value !== 'object')
return false;
const k = value;
return (Array.isArray(k['inputs']) &&
typeof k['query'] === 'string' &&
typeof k['subPrompt'] === 'string' &&
typeof k['model'] === 'string' &&
typeof k['aggregateStrategy'] === 'string');
}
//# sourceMappingURL=hash.js.map