opencode-goal-plugin 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ // Installation verification for opencode-goal-plugin.
3
+ // Checks the plugin can be loaded and wired up correctly without ever
4
+ // invoking a model — every check below uses the same mock-client approach
5
+ // as scripts/smoke-command-hook.mjs.
6
+
7
+ import assert from "node:assert/strict"
8
+
9
+ const REQUIRED_HOOKS = [
10
+ "command.execute.before",
11
+ "event",
12
+ "experimental.chat.system.transform",
13
+ "experimental.compaction.autocontinue",
14
+ ]
15
+
16
+ const results = []
17
+
18
+ function check(name, fn) {
19
+ return Promise.resolve()
20
+ .then(fn)
21
+ .then(() => {
22
+ results.push({ name, ok: true })
23
+ console.log(` ✅ ${name}`)
24
+ })
25
+ .catch((error) => {
26
+ results.push({ name, ok: false, error })
27
+ console.log(` ❌ ${name}`)
28
+ console.log(` ${error.message}`)
29
+ })
30
+ }
31
+
32
+ console.log("opencode-goal-plugin installation verification\n")
33
+
34
+ await check("Node.js >= 18", () => {
35
+ const major = Number(process.versions.node.split(".")[0])
36
+ assert.ok(major >= 18, `Node ${process.versions.node} is below the required >=18`)
37
+ })
38
+
39
+ let pluginModule
40
+ let GoalPlugin
41
+
42
+ await check("plugin module resolves and exposes expected shape", async () => {
43
+ pluginModule = await import("opencode-goal-plugin")
44
+ GoalPlugin = pluginModule.GoalPlugin
45
+ assert.equal(pluginModule.default.id, "opencode-goal-plugin")
46
+ assert.equal(typeof pluginModule.default.server, "function")
47
+ assert.equal(typeof GoalPlugin, "function")
48
+ })
49
+
50
+ const sessionID = `verify-${process.pid}`
51
+ const promptCalls = []
52
+ const logCalls = []
53
+
54
+ const client = {
55
+ app: {
56
+ log: async (input) => {
57
+ logCalls.push(input)
58
+ },
59
+ },
60
+ session: {
61
+ messages: async () => ({ data: [] }),
62
+ promptAsync: async (input) => {
63
+ promptCalls.push(input)
64
+ return {}
65
+ },
66
+ },
67
+ }
68
+
69
+ let hooks
70
+
71
+ await check("plugin initializes and registers all 4 required hooks", async () => {
72
+ // registerTools defaults to true but silently no-ops without the optional
73
+ // @opencode-ai/plugin peer dependency, so it is not asserted here — the
74
+ // 4 hooks below are always present regardless of that peer dependency.
75
+ hooks = await GoalPlugin({ client }, { minDelayMs: 1, persistState: false })
76
+ for (const hookName of REQUIRED_HOOKS) {
77
+ assert.equal(
78
+ typeof hooks[hookName],
79
+ "function",
80
+ `missing or non-function hook: ${hookName}`,
81
+ )
82
+ }
83
+ })
84
+
85
+ async function runGoalCommand(args) {
86
+ const output = { parts: [] }
87
+ await hooks["command.execute.before"](
88
+ { command: "goal", sessionID, arguments: args },
89
+ output,
90
+ )
91
+ assert.equal(output.parts.length, 1)
92
+ assert.equal(output.parts[0].type, "text")
93
+ return output.parts[0].text
94
+ }
95
+
96
+ await check("/goal status works", async () => {
97
+ const text = await runGoalCommand("status")
98
+ assert.match(text, /No active goal/)
99
+ })
100
+
101
+ await check("/goal set works", async () => {
102
+ const text = await runGoalCommand("verify the installation --max-turns 1")
103
+ assert.match(text, /New active goal: verify the installation/)
104
+ const statusText = await runGoalCommand("status")
105
+ assert.match(statusText, /Active goal: verify the installation/)
106
+ })
107
+
108
+ await check("no model calls were made during verification", () => {
109
+ assert.equal(promptCalls.length, 0, "expected zero promptAsync calls")
110
+ })
111
+
112
+ // Clean up the goal created above so this script has no side effects.
113
+ await runGoalCommand("clear")
114
+
115
+ console.log()
116
+
117
+ const failed = results.filter((r) => !r.ok)
118
+ if (failed.length > 0) {
119
+ console.log(`${failed.length}/${results.length} checks failed.`)
120
+ process.exit(1)
121
+ }
122
+
123
+ console.log(`All ${results.length} checks passed. opencode-goal-plugin is installed correctly.`)