-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfl.ts
More file actions
36 lines (31 loc) · 1.05 KB
/
Copy pathfl.ts
File metadata and controls
36 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { Plugin } from "@opencode-ai/plugin"
// ForceLoop `fl gate` auto-driver for OpenCode.
//
// Behavior:
// - On `session.idle`, run `fl gate` with a 60-second timeout.
// - Exit 0: silent pass, no AI intervention.
// - Exit != 0: re-inject stdout+stderr as a prompt into the session
// with `noReply: false` to trigger the AI's auto-reply / fix loop.
//
// Source of truth for OpenCode plugin API:
// https://opencode.ai/docs/plugins/
export const FlGateHook: Plugin = async ({ client, $ }) => {
return {
event: async ({ event }) => {
if (event.type !== "session.idle") return;
const sessionID = event.properties?.sessionID;
if (!sessionID) return;
const result = await $`fl gate`.nothrow();
if (result.exitCode !== 0) {
const text = (result.stdout?.toString() ?? "") + (result.stderr?.toString() ?? "");
await client.session.prompt({
path: { id: sessionID },
body: {
noReply: false,
parts: [{ type: "text", text }],
},
});
}
},
};
};