promptPreprocessor.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.promptPreprocessor = promptPreprocessor;
const ical_1 = require("./ical");
const macos_1 = require("./macos");
// PromptPreprocessorController has no getPluginConfig — use defaults.
// injectTodayIntoPrompt config only affects tool calls; preprocessor always injects.
// To disable injection, users can toggle it off by removing the preprocessor (not supported without config access).
async function promptPreprocessor(ctl, userMessage) {
// Only inject on first message of a session to avoid repetition
const history = await ctl.pullHistory();
if (history.length !== 0)
return userMessage;
try {
const today = new Date();
today.setHours(0, 0, 0, 0);
const endOfDay = new Date(today);
endOfDay.setHours(23, 59, 59, 999);
// Default to macOS; ICS path unknown without config access
const events = (0, macos_1.fetchMacOSEvents)(today, endOfDay);
const summary = events.length === 0
? "No events scheduled today."
: `Today's events (${today.toDateString()}):\n${events.map(e => " • " + (0, ical_1.formatEvent)(e)).join("\n")}`;
const injection = `[Calendar context: ${summary}]`;
return `${injection}\n\n${userMessage.getText()}`;
}
catch {
// Silently skip if Calendar.app unavailable or on non-macOS
return userMessage;
}
}