@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
41 lines • 1.26 kB
JavaScript
import { TRACK_WINDOW } from "./policy.js";
export function canonicalizeArgs(args) {
return stableStringify(args ?? {});
}
function stableStringify(value) {
if (value === null || typeof value !== "object")
return JSON.stringify(value) ?? "null";
if (Array.isArray(value))
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
const record = value;
const keys = Object.keys(record).sort();
const parts = [];
for (const key of keys) {
const entry = record[key];
if (entry === undefined)
continue;
parts.push(`${JSON.stringify(key)}:${stableStringify(entry)}`);
}
return `{${parts.join(",")}}`;
}
export class ToolCallTracker {
constructor() {
this.calls = [];
}
record(toolName, args) {
const argsJson = canonicalizeArgs(args);
const record = { toolName, argsJson, signature: `${toolName}\u0000${argsJson}` };
this.calls.push(record);
if (this.calls.length > TRACK_WINDOW) {
this.calls = this.calls.slice(-TRACK_WINDOW);
}
return record;
}
get records() {
return this.calls;
}
reset() {
this.calls = [];
}
}
//# sourceMappingURL=tracker.js.map