Skip to content

Commit ade028c

Browse files
committed
test: Add test plugin and config for prompt.before hook verification
1 parent 38e35ce commit ade028c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

.opencode/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugin": ["file:///home/user/opencode-auto/my-test-plugin.ts"]
3+
}

my-test-plugin.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { Plugin } from "@opencode-ai/plugin"
2+
3+
export const TestPlugin: Plugin = async () => {
4+
console.log("🎯 Test Plugin Loaded!")
5+
6+
return {
7+
"prompt.before": async (input, output) => {
8+
console.log("\n" + "=".repeat(60))
9+
console.log("🔥 PROMPT.BEFORE HOOK FIRED!")
10+
console.log("=".repeat(60))
11+
console.log("Session:", input.sessionID)
12+
console.log("Agent:", input.agent)
13+
console.log("Prompt:", input.prompt.substring(0, 100))
14+
console.log("Prompt length:", input.prompt.length)
15+
console.log("Current model:", input.model || "default")
16+
console.log("=".repeat(60) + "\n")
17+
18+
// Test: switch to Haiku for "simple" prompts
19+
if (input.prompt.toLowerCase().includes("simple")) {
20+
output.model = {
21+
providerID: "anthropic",
22+
modelID: "claude-haiku-3-5"
23+
}
24+
console.log("✅ SWITCHED TO HAIKU FOR SIMPLE TASK\n")
25+
}
26+
27+
// Test: switch to Sonnet for "complex" prompts
28+
if (input.prompt.toLowerCase().includes("complex") || input.prompt.toLowerCase().includes("refactor")) {
29+
output.model = {
30+
providerID: "anthropic",
31+
modelID: "claude-sonnet-4-5"
32+
}
33+
console.log("✅ SWITCHED TO SONNET 4.5 FOR COMPLEX TASK\n")
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)