bacluc-opencode-completion-check-command 0.8.4 → 0.9.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 +1 -1
- package/src/completion-check-command.ts +61 -3
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -190,6 +190,48 @@ export async function readDefaultCommandFromAgentsMd(directory: string): Promise
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
async function readFileIfExists(filePath: string): Promise<string | null> {
|
|
194
|
+
try {
|
|
195
|
+
return await fs.readFile(filePath, 'utf-8')
|
|
196
|
+
} catch {
|
|
197
|
+
return null
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function readDefaultCommandFromDotfile(filePath: string): Promise<string | null> {
|
|
202
|
+
const content = await readFileIfExists(filePath)
|
|
203
|
+
if (!content) {
|
|
204
|
+
return null
|
|
205
|
+
}
|
|
206
|
+
const trimmed = content.trim()
|
|
207
|
+
return trimmed || null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export async function readDefaultCommand(
|
|
211
|
+
directory: string,
|
|
212
|
+
): Promise<{ command: string | null; source: string | null }> {
|
|
213
|
+
const agentsDotfile = `${directory}/.agents/.completion-check-command`
|
|
214
|
+
const opencodeDotfile = `${directory}/.opencode/.completion-check-command`
|
|
215
|
+
const agentsMd = `${directory}/AGENTS.md`
|
|
216
|
+
|
|
217
|
+
let command = await readDefaultCommandFromDotfile(agentsDotfile)
|
|
218
|
+
if (command) {
|
|
219
|
+
return { command, source: '.agents/.completion-check-command' }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
command = await readDefaultCommandFromDotfile(opencodeDotfile)
|
|
223
|
+
if (command) {
|
|
224
|
+
return { command, source: '.opencode/.completion-check-command' }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
command = await readDefaultCommandFromAgentsMd(directory)
|
|
228
|
+
if (command) {
|
|
229
|
+
return { command, source: 'AGENTS.md' }
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return { command: null, source: null }
|
|
233
|
+
}
|
|
234
|
+
|
|
193
235
|
export const CompletionCheckCommandPlugin: Plugin = async (input, options) => {
|
|
194
236
|
const { client } = input
|
|
195
237
|
const maxRetries = typeof options?.maxRetries === 'number' ? options.maxRetries : DEFAULT_MAX_RETRIES
|
|
@@ -255,16 +297,16 @@ export const CompletionCheckCommandPlugin: Plugin = async (input, options) => {
|
|
|
255
297
|
if (event.type === 'session.created') {
|
|
256
298
|
const sessionID = (event as Extract<Event, { type: 'session.created' }>).properties.info.id
|
|
257
299
|
const directory = (event as Extract<Event, { type: 'session.created' }>).properties.info.directory
|
|
258
|
-
const defaultCommand = await
|
|
300
|
+
const { command: defaultCommand, source } = await readDefaultCommand(directory)
|
|
259
301
|
|
|
260
|
-
if (defaultCommand) {
|
|
302
|
+
if (defaultCommand && source) {
|
|
261
303
|
store.set(sessionID, defaultCommand)
|
|
262
304
|
|
|
263
305
|
try {
|
|
264
306
|
await client.tui.showToast({
|
|
265
307
|
body: {
|
|
266
308
|
title: 'Completion Check',
|
|
267
|
-
message: `Found default completion check command in
|
|
309
|
+
message: `Found default completion check command in ${source}. It will be run automatically when the agent finishes:\n\n\`\`\`bash\n${defaultCommand}\n\`\`\``,
|
|
268
310
|
variant: 'info',
|
|
269
311
|
duration: 10000,
|
|
270
312
|
},
|
|
@@ -317,6 +359,22 @@ export const CompletionCheckCommandPlugin: Plugin = async (input, options) => {
|
|
|
317
359
|
|
|
318
360
|
if (result.exitCode === 0) {
|
|
319
361
|
store.delete(sessionID)
|
|
362
|
+
|
|
363
|
+
console.log(`[Completion Check] Command succeeded. Task is complete.\nCommand: ${command}`)
|
|
364
|
+
|
|
365
|
+
try {
|
|
366
|
+
await client.tui.showToast({
|
|
367
|
+
body: {
|
|
368
|
+
title: 'Completion Check',
|
|
369
|
+
message: `Command succeeded! Task is complete.\n\n\`\`\`bash\n${command}\n\`\`\``,
|
|
370
|
+
variant: 'success',
|
|
371
|
+
duration: 10000,
|
|
372
|
+
},
|
|
373
|
+
})
|
|
374
|
+
} catch {
|
|
375
|
+
// Ignore feedback errors
|
|
376
|
+
}
|
|
377
|
+
|
|
320
378
|
return
|
|
321
379
|
}
|
|
322
380
|
|