local-agent
Version:
A CLI agentic system for orchestrating tools and memory with per-folder scoping
66 lines • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSessionFile = createSessionFile;
exports.logUserPrompt = logUserPrompt;
exports.logToolUsed = logToolUsed;
exports.logAgentResponse = logAgentResponse;
exports.logAgentError = logAgentError;
/**
* @fileoverview
* Provides utilities for session memory logging.
* Handles creation of session files and appending user prompts, tool usage, agent responses, and errors.
*/
const fs_1 = require("fs");
/**
* Creates a new session memory file and writes the session header.
* The file is named with the current timestamp and stored in the memory directory.
*
* @param {Date} now - The current date and time.
* @param {string} toolRow - A summary row listing all tools and their status.
* @param {string} toolStatusMd - Markdown-formatted details of tool load status.
* @param {string} agentName - The display name of the agent.
* @returns {string} The path to the created session file.
*/
function createSessionFile(now, toolRow, toolStatusMd, agentName) {
const sessionFile = `memory/session-${now.toISOString().replace(/[:.]/g, "-")}.md`;
let header = `# ${agentName} Session – ${now.toLocaleString()}\n\n${toolRow}\n\n## Tools Loaded\n\n${toolStatusMd}\n`;
(0, fs_1.writeFileSync)(sessionFile, header, "utf8");
return sessionFile;
}
/**
* Appends a user prompt to the session memory file.
*
* @param {string} sessionFile - Path to the session file.
* @param {string} prompt - The user's input prompt.
*/
function logUserPrompt(sessionFile, prompt) {
(0, fs_1.appendFileSync)(sessionFile, `## User\n\n${prompt}\n\n`, "utf8");
}
/**
* Appends a tool usage entry to the session memory file.
*
* @param {string} sessionFile - Path to the session file.
* @param {string} toolName - The name of the tool used.
*/
function logToolUsed(sessionFile, toolName) {
(0, fs_1.appendFileSync)(sessionFile, `## Tool Used\n\n${toolName}\n\n`, "utf8");
}
/**
* Appends an agent response to the session memory file.
*
* @param {string} sessionFile - Path to the session file.
* @param {string} response - The agent's response text.
*/
function logAgentResponse(sessionFile, response) {
(0, fs_1.appendFileSync)(sessionFile, `## Agent\n\n${response}\n\n`, "utf8");
}
/**
* Appends an error message to the session memory file.
*
* @param {string} sessionFile - Path to the session file.
* @param {string} errMsg - The error message to log.
*/
function logAgentError(sessionFile, errMsg) {
(0, fs_1.appendFileSync)(sessionFile, `## Agent (error)\n\n${errMsg}\n\n`, "utf8");
}
//# sourceMappingURL=memory.js.map