Execute tool calls in worktree root
This commit is contained in:
+13
-18
@@ -2,15 +2,15 @@ import { tool } from "@opencode-ai/plugin"
|
||||
import path from "path"
|
||||
|
||||
function resolveWorklaneDir(context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
return path.join(context.worktree || context.directory || ".", ".worklane")
|
||||
return path.join(context.worktree || context.directory || ".")
|
||||
}
|
||||
|
||||
export const init = tool({
|
||||
description: "Initialize worklane in the current project. Creates the .worklane/ directory with backlog, committed, reviewing, and done subdirectories.",
|
||||
args: {},
|
||||
async execute() {
|
||||
async execute(_args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
try {
|
||||
const result = await Bun.$`worklane init`.text()
|
||||
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`worklane init`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error initializing worklane: ${err.message}`
|
||||
@@ -29,7 +29,7 @@ export const add = tool({
|
||||
due: tool.schema.string().describe("Due date in YYYY-MM-DD format"),
|
||||
owner: tool.schema.string().describe("Owner name"),
|
||||
},
|
||||
async execute(args) {
|
||||
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
const cmd: string[] = ["add", "--title", args.title]
|
||||
if (args.description) {
|
||||
args.description
|
||||
@@ -60,7 +60,7 @@ export const add = tool({
|
||||
if (args.owner) cmd.push("--owner", args.owner)
|
||||
|
||||
try {
|
||||
const result = await Bun.$`worklane ${cmd}`.text()
|
||||
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`worklane ${cmd}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error adding ticket: ${err.message}`
|
||||
@@ -73,10 +73,9 @@ export const ls = tool({
|
||||
args: {
|
||||
status: tool.schema.enum(["backlog", "committed", "reviewing", "done"]).describe("Filter by status").optional(),
|
||||
},
|
||||
async execute(args) {
|
||||
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
try {
|
||||
const cmd = args.status ? `worklane ls --status ${args.status}` : "worklane ls"
|
||||
const result = await Bun.$`${cmd}`.text()
|
||||
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`${args.status ? "worklane ls --status " + args.status : "worklane ls"}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error listing tickets: ${err.message}`
|
||||
@@ -89,9 +88,9 @@ export const show = tool({
|
||||
args: {
|
||||
id: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"),
|
||||
},
|
||||
async execute(args) {
|
||||
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
try {
|
||||
const result = await Bun.$`worklane show ${args.id}`.text()
|
||||
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`worklane show ${args.id}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error showing ticket: ${err.message}`
|
||||
@@ -106,10 +105,9 @@ export const mv = tool({
|
||||
status: tool.schema.enum(["backlog", "committed", "reviewing", "done"]).describe("Target status"),
|
||||
force: tool.schema.boolean().describe("Force move (allows non-sequential moves like done -> backlog)").optional(),
|
||||
},
|
||||
async execute(args) {
|
||||
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
try {
|
||||
const cmd = args.force ? `worklane mv ${args.ticket} --status ${args.status} --force` : `worklane mv ${args.ticket} --status ${args.status}`
|
||||
const result = await Bun.$`${cmd}`.text()
|
||||
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`${args.force ? "worklane mv " + args.ticket + " --status " + args.status + " --force" : "worklane mv " + args.ticket + " --status " + args.status}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error moving ticket: ${err.message}`
|
||||
@@ -124,12 +122,9 @@ export const comment = tool({
|
||||
body: tool.schema.string().describe("Comment body (required)"),
|
||||
owner: tool.schema.string().describe("Comment author").optional(),
|
||||
},
|
||||
async execute(args) {
|
||||
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) {
|
||||
try {
|
||||
const cmd = args.owner
|
||||
? `worklane comment ${args.ticket} --owner ${args.owner} "${args.body}"`
|
||||
: `worklane comment ${args.ticket} "${args.body}"`
|
||||
const result = await Bun.$`${cmd}`.text()
|
||||
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`${args.owner ? "worklane comment " + args.ticket + " --owner " + args.owner + " \"" + args.body + "\"" : "worklane comment " + args.ticket + " \"" + args.body + "\""}`.text()
|
||||
return result.trim()
|
||||
} catch (err: any) {
|
||||
return `Error adding comment: ${err.message}`
|
||||
|
||||
Reference in New Issue
Block a user