bacluc-opencode-completion-check-command 0.10.4 → 0.10.5
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.
- package/README.md +16 -0
- package/package.json +3 -3
- package/src/completion-check-command.ts +74 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -63,6 +63,22 @@ The `/completion-check-command` is automatically registered by the plugin's `con
|
|
|
63
63
|
}
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
### Default Command Sources
|
|
67
|
+
|
|
68
|
+
On `session.created` the plugin resolves the default command in precedence order:
|
|
69
|
+
|
|
70
|
+
1. `.agents/.completion-check-command` 2. `.opencode/.completion-check-command` 3. `AGENTS.md` code block after `/completion-check-command` 4. Claude hooks: `.claude/settings.local.json` → `.claude/settings.json` → `~/.claude/settings.json` (`hooks.Stop[].hooks[]` with `type == "command"` joined with `&&`)
|
|
71
|
+
|
|
72
|
+
Example `settings.json`:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"hooks": {
|
|
77
|
+
"Stop": [{ "hooks": [{ "type": "command", "command": "./scripts/completion-check" }] }]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
66
82
|
## Example
|
|
67
83
|
|
|
68
84
|
Create a check script:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bacluc-opencode-completion-check-command",
|
|
3
|
-
"version": "v0.10.
|
|
3
|
+
"version": "v0.10.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"format:check": "prettier --check ."
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@opencode-ai/plugin": "1.18.
|
|
39
|
+
"@opencode-ai/plugin": "1.18.30"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/bun": "1.4.
|
|
42
|
+
"@types/bun": "1.4.2",
|
|
43
43
|
"@types/node": "25.9.5",
|
|
44
44
|
"prettier": "3.9.6",
|
|
45
45
|
"typescript": "7.0.2",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Hooks, Plugin, PluginInput } from '@opencode-ai/plugin'
|
|
2
2
|
import type { Event } from '@opencode-ai/sdk'
|
|
3
3
|
import { promises as fs } from 'fs'
|
|
4
|
+
import { homedir } from 'os'
|
|
4
5
|
import { exec } from 'child_process'
|
|
5
6
|
|
|
6
7
|
export const DEFAULT_MAX_RETRIES = 10
|
|
@@ -212,6 +213,74 @@ async function readDefaultCommandFromDotfile(filePath: string): Promise<string |
|
|
|
212
213
|
return trimmed || null
|
|
213
214
|
}
|
|
214
215
|
|
|
216
|
+
function extractStopCommands(parsed: unknown): string | null {
|
|
217
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
218
|
+
return null
|
|
219
|
+
}
|
|
220
|
+
const hooks = (parsed as { hooks?: unknown }).hooks
|
|
221
|
+
if (!hooks || typeof hooks !== 'object') {
|
|
222
|
+
return null
|
|
223
|
+
}
|
|
224
|
+
const stop = (hooks as { Stop?: unknown }).Stop
|
|
225
|
+
if (!Array.isArray(stop)) {
|
|
226
|
+
return null
|
|
227
|
+
}
|
|
228
|
+
const commands: string[] = []
|
|
229
|
+
for (const entry of stop) {
|
|
230
|
+
if (!entry || typeof entry !== 'object') {
|
|
231
|
+
continue
|
|
232
|
+
}
|
|
233
|
+
const entryHooks = (entry as { hooks?: unknown }).hooks
|
|
234
|
+
if (!Array.isArray(entryHooks)) {
|
|
235
|
+
continue
|
|
236
|
+
}
|
|
237
|
+
for (const hook of entryHooks) {
|
|
238
|
+
if (!hook || typeof hook !== 'object') {
|
|
239
|
+
continue
|
|
240
|
+
}
|
|
241
|
+
const typed = hook as { type?: unknown; command?: unknown }
|
|
242
|
+
if (typed.type !== 'command' || typeof typed.command !== 'string' || !typed.command.trim()) {
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
commands.push(typed.command.trim())
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (commands.length === 0) {
|
|
249
|
+
return null
|
|
250
|
+
}
|
|
251
|
+
return commands.join(' && ')
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function readStopCommandsFile(filePath: string): Promise<string | null> {
|
|
255
|
+
const content = await readFileIfExists(filePath)
|
|
256
|
+
if (!content) {
|
|
257
|
+
return null
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
return extractStopCommands(JSON.parse(content))
|
|
261
|
+
} catch {
|
|
262
|
+
return null
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export async function readDefaultCommandFromClaudeHooks(
|
|
267
|
+
directory: string,
|
|
268
|
+
): Promise<{ command: string | null; source: string | null }> {
|
|
269
|
+
const home = process.env.HOME || homedir()
|
|
270
|
+
const candidates: Array<[string, string]> = [
|
|
271
|
+
[`${directory}/.claude/settings.local.json`, '.claude/settings.local.json'],
|
|
272
|
+
[`${directory}/.claude/settings.json`, '.claude/settings.json'],
|
|
273
|
+
[`${home}/.claude/settings.json`, '~/.claude/settings.json'],
|
|
274
|
+
]
|
|
275
|
+
for (const [filePath, source] of candidates) {
|
|
276
|
+
const command = await readStopCommandsFile(filePath)
|
|
277
|
+
if (command) {
|
|
278
|
+
return { command, source }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return { command: null, source: null }
|
|
282
|
+
}
|
|
283
|
+
|
|
215
284
|
export async function readDefaultCommand(
|
|
216
285
|
directory: string,
|
|
217
286
|
): Promise<{ command: string | null; source: string | null }> {
|
|
@@ -234,6 +303,11 @@ export async function readDefaultCommand(
|
|
|
234
303
|
return { command, source: 'AGENTS.md' }
|
|
235
304
|
}
|
|
236
305
|
|
|
306
|
+
const claudeHooks = await readDefaultCommandFromClaudeHooks(directory)
|
|
307
|
+
if (claudeHooks.command && claudeHooks.source) {
|
|
308
|
+
return claudeHooks
|
|
309
|
+
}
|
|
310
|
+
|
|
237
311
|
return { command: null, source: null }
|
|
238
312
|
}
|
|
239
313
|
|