779ca4872b
- Removed Prettier configuration files (.prettierignore and .prettierrc) and migrated formatting to Biome. - Updated Biome configuration from version 2.3.11 to 2.3.12 and changed arrowParentheses rule from 'always' to 'asNeeded'. - Pinned @biomejs/biome dependency to exact version 2.3.12 in package.json and bun.lock. - Applied consistent arrow function formatting across 489 files by removing unnecessary parentheses around single parameters. - Removed blank lines after comment blocks and reorganized imports for consistency across the codebase.
41 lines
998 B
TypeScript
41 lines
998 B
TypeScript
/**
|
|
* File Trigger Hook
|
|
*
|
|
* Watches a trigger file and injects its contents into the conversation.
|
|
* Useful for external systems to send messages to the agent.
|
|
*
|
|
* Usage:
|
|
* echo "Run the tests" > /tmp/agent-trigger.txt
|
|
*/
|
|
import * as fs from "node:fs";
|
|
import type { HookAPI } from "@oh-my-pi/pi-coding-agent";
|
|
|
|
export default function (pi: HookAPI) {
|
|
pi.on("session_start", async (_event, ctx) => {
|
|
const triggerFile = "/tmp/agent-trigger.txt";
|
|
|
|
fs.watch(triggerFile, async () => {
|
|
try {
|
|
const content = (await Bun.file(triggerFile).text()).trim();
|
|
if (content) {
|
|
pi.sendMessage(
|
|
{
|
|
customType: "file-trigger",
|
|
content: `External trigger: ${content}`,
|
|
display: true,
|
|
},
|
|
true, // triggerTurn - get LLM to respond
|
|
);
|
|
await Bun.write(triggerFile, ""); // Clear after reading
|
|
}
|
|
} catch {
|
|
// File might not exist yet
|
|
}
|
|
});
|
|
|
|
if (ctx.hasUI) {
|
|
ctx.ui.notify(`Watching ${triggerFile}`, "info");
|
|
}
|
|
});
|
|
}
|