bacluc-opencode-completion-check-command 0.2.0 → 0.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bacluc-opencode-completion-check-command",
3
- "version": "v0.2.0",
3
+ "version": "v0.3.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "opencode",
@@ -40,6 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/bun": "1.3.14",
43
+ "@types/node": "25.9.2",
43
44
  "prettier": "3.8.3",
44
45
  "typescript": "6.0.3",
45
46
  "vitest": "4.1.7"
@@ -1,5 +1,6 @@
1
1
  import type { Hooks, Plugin, PluginInput } from '@opencode-ai/plugin'
2
2
  import type { Event } from '@opencode-ai/sdk'
3
+ import { promises as fs } from 'fs'
3
4
 
4
5
  export const DEFAULT_MAX_RETRIES = 10
5
6
 
@@ -108,6 +109,19 @@ export function buildFailureMessage(result: CommandResult): string {
108
109
  return message
109
110
  }
110
111
 
112
+ export async function readDefaultCommandFromAgentsMd(directory: string): Promise<string | null> {
113
+ try {
114
+ const content = await fs.readFile(`${directory}/AGENTS.md`, 'utf-8')
115
+ const commandIndex = content.indexOf('/completion-check-command')
116
+ if (commandIndex === -1) {
117
+ return null
118
+ }
119
+ return parseCodeBlock(content.slice(commandIndex))
120
+ } catch {
121
+ return null
122
+ }
123
+ }
124
+
111
125
  export const CompletionCheckCommandPlugin: Plugin = async (input, options) => {
112
126
  const { client, $ } = input
113
127
  const maxRetries = typeof options?.maxRetries === 'number' ? options.maxRetries : DEFAULT_MAX_RETRIES
@@ -170,6 +184,31 @@ export const CompletionCheckCommandPlugin: Plugin = async (input, options) => {
170
184
  },
171
185
 
172
186
  event: async ({ event }) => {
187
+ if (event.type === 'session.created') {
188
+ const sessionID = (event as Extract<Event, { type: 'session.created' }>).properties.info.id
189
+ const directory = (event as Extract<Event, { type: 'session.created' }>).properties.info.directory
190
+ const defaultCommand = await readDefaultCommandFromAgentsMd(directory)
191
+
192
+ if (defaultCommand) {
193
+ store.set(sessionID, defaultCommand)
194
+
195
+ try {
196
+ await client.tui.showToast({
197
+ body: {
198
+ title: 'Completion Check',
199
+ message: `Found default completion check command in AGENTS.md. It will be run automatically when the agent finishes:\n\n\`\`\`bash\n${defaultCommand}\n\`\`\``,
200
+ variant: 'info',
201
+ duration: 10000,
202
+ },
203
+ })
204
+ } catch {
205
+ // Ignore feedback errors
206
+ }
207
+ }
208
+
209
+ return
210
+ }
211
+
173
212
  if (event.type !== 'session.idle') {
174
213
  return
175
214
  }