Attempt to fix the tool

This commit is contained in:
2026-05-16 02:19:54 +02:00
parent 31421ff103
commit bcb24f1fa6
+121 -58
View File
@@ -1,133 +1,196 @@
import { tool } from "@opencode-ai/plugin" import { tool, ToolContext } from "@opencode-ai/plugin";
import path from "path" import path from "path";
function resolveWorklaneDir(context: Parameters<(typeof tool)['prototype'].execute>[1]) { function resolveWorklaneDir(context: ToolContext): string {
return path.join(context.worktree || context.directory || ".") return path.join(context.worktree || context.directory || ".");
} }
export const init = tool({ export const init = tool({
description: "Initialize worklane in the current project. Creates the .worklane/ directory with backlog, committed, reviewing, and done subdirectories.", description:
"Initialize worklane in the current project. Creates the .worklane/ directory with backlog, committed, reviewing, and done subdirectories.",
args: {}, args: {},
async execute(_args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) { async execute(_args: Record<string, any>, context: ToolContext) {
try { try {
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`worklane init`.text() const result = await Bun.$`worklane init`
return result.trim() .cwd(resolveWorklaneDir(context))
.text();
return result.trim();
} catch (err: any) { } catch (err: any) {
return `Error initializing worklane: ${err.message}` return `Error initializing worklane: ${err.message}`;
} }
}, },
}) });
export const add = tool({ export const add = tool({
description: "Add a new ticket to the worklane backlog. Supports title, description, acceptance criteria, implementation plan, tags, due date, and owner.", description:
"Add a new ticket to the worklane backlog. Supports title, description, acceptance criteria, implementation plan, tags, due date, and owner.",
args: { args: {
title: tool.schema.string().describe("Ticket title (required)"), title: tool.schema.string().describe("Ticket title (required)"),
description: tool.schema.string().describe("Ticket description"), description: tool.schema.string().describe("Multiline ticket description"),
acceptance: tool.schema.string().describe("Acceptance criteria as comma-separated list"), acceptance: tool.schema
plan: tool.schema.string().describe("Implementation plan as comma-separated steps"), .string()
.describe("Acceptance criteria one per line"),
plan: tool.schema
.string()
.describe("Implementation plan with one step per line"),
tags: tool.schema.string().describe("Tags as comma-separated list"), tags: tool.schema.string().describe("Tags as comma-separated list"),
due: tool.schema.string().describe("Due date in YYYY-MM-DD format"), due: tool.schema.string().describe("Due date in YYYY-MM-DD format"),
owner: tool.schema.string().describe("Owner name"), owner: tool.schema.string().describe("Owner name"),
}, },
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) { async execute(args: Record<string, any>, context: ToolContext) {
const cmd: string[] = ["add", "--title", args.title] const cmd: (string | number)[] = ["add", "--title", args.title];
if (args.description) { if (args.description) {
args.description args.description
.split("\n") .split("\n")
.map((l) => l.trim()) .map((l: string) => l.trim())
.filter(Boolean) .filter(Boolean)
.forEach((line) => cmd.push("--description", line)) .forEach((line: string) => cmd.push("--description", line));
} }
if (args.acceptance) { if (args.acceptance) {
args.acceptance args.acceptance
.split("\n") .split("\n")
.map((l) => l.trim()) .map((l: string) => l.trim())
.filter(Boolean) .filter(Boolean)
.forEach((line) => cmd.push("--acceptance", line)) .forEach((line: string) => cmd.push("--acceptance", line));
} }
if (args.plan) { if (args.plan) {
args.plan args.plan
.split("\n") .split("\n")
.map((l) => l.trim()) .map((l: string) => l.trim())
.filter(Boolean) .filter(Boolean)
.forEach((line) => cmd.push("--plan", line)) .forEach((line: string) => cmd.push("--plan", line));
} }
if (args.tags) cmd.push("--tags", args.tags) if (args.tags) cmd.push("--tags", args.tags);
if (args.due) cmd.push("--due", args.due) if (args.due) cmd.push("--due", args.due);
if (args.owner) cmd.push("--owner", args.owner) if (args.owner) cmd.push("--owner", args.owner);
const workdir = resolveWorklaneDir(context);
try { try {
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`worklane ${cmd}`.text() const proc = Bun.spawn(["worklane", ...cmd], { cwd: workdir });
return result.trim() const { exitCode, stdout, stderr } = await proc.exited;
if (exitCode !== 0) {
const stderrStr = new TextDecoder().decode(stderr);
throw new Error(stderrStr.trim() || `Exit code ${exitCode}`);
}
return new TextDecoder().decode(stdout).trim();
} catch (err: any) { } catch (err: any) {
return `Error adding ticket: ${err.message}` return `Error adding ticket: ${err.message}`;
} }
}, },
}) });
export const ls = tool({ export const ls = tool({
description: "List all worklane tickets. Optionally filter by status (backlog, committed, reviewing, done).", description:
"List all worklane tickets. Optionally filter by status (backlog, committed, reviewing, done).",
args: { args: {
status: tool.schema.enum(["backlog", "committed", "reviewing", "done"]).describe("Filter by status").optional(), status: tool.schema
.enum(["backlog", "committed", "reviewing", "done"])
.describe("Filter by status")
.optional(),
}, },
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) { async execute(args: Record<string, any>, context: ToolContext) {
const workdir = resolveWorklaneDir(context);
try { try {
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`${args.status ? "worklane ls --status " + args.status : "worklane ls"}`.text() if (args.status) {
return result.trim() const result = await Bun.$`worklane ls ${args.status}`
.cwd(workdir)
.text();
return result.trim();
} else {
const result = await Bun.$`worklane ls`.cwd(workdir).text();
return result.trim();
}
} catch (err: any) { } catch (err: any) {
return `Error listing tickets: ${err.message}` return `Error listing tickets: ${err.message}, Dir: ${workdir}`;
} }
}, },
}) });
export const show = tool({ export const show = tool({
description: "Show a complete ticket by UUID or title. Displays title, description, acceptance criteria, implementation plan, metadata, and comments.", description:
"Show a complete ticket by UUID or title. Displays title, description, acceptance criteria, implementation plan, metadata, and comments.",
args: { args: {
id: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"), id: tool.schema
.string()
.describe("Ticket UUID (8+ chars) or title substring"),
}, },
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) { async execute(args: Record<string, any>, context: ToolContext) {
const workdir = resolveWorklaneDir(context);
try { try {
const result = await Bun.$({ cwd: resolveWorklaneDir(context) })`worklane show ${args.id}`.text() const result = await Bun.$`worklane show ${args.id}`.cwd(workdir).text();
return result.trim() return result.trim();
} catch (err: any) { } catch (err: any) {
return `Error showing ticket: ${err.message}` return `Error showing ticket: ${err.message}`;
} }
}, },
}) });
export const mv = tool({ export const mv = tool({
description: "Move a ticket to a different status in the workflow (backlog -> committed -> reviewing -> done).", description:
"Move a ticket to a different status in the workflow (backlog -> committed -> reviewing -> done).",
args: { args: {
ticket: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"), ticket: tool.schema
status: tool.schema.enum(["backlog", "committed", "reviewing", "done"]).describe("Target status"), .string()
force: tool.schema.boolean().describe("Force move (allows non-sequential moves like done -> backlog)").optional(), .describe("Ticket UUID (8+ chars) or title substring"),
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: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) { async execute(args: Record<string, any>, context: ToolContext) {
const cmd: (string | number)[] = [
"mv",
args.ticket,
"--status",
args.status,
];
if (args.force) cmd.push("--force");
const workdir = resolveWorklaneDir(context);
try { try {
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() const proc = Bun.spawn(["worklane", ...cmd], { cwd: workdir });
return result.trim() const { exitCode, stdout, stderr } = await proc.exited;
if (exitCode !== 0) {
const stderrStr = new TextDecoder().decode(stderr);
throw new Error(stderrStr.trim() || `Exit code ${exitCode}`);
}
return new TextDecoder().decode(stdout).trim();
} catch (err: any) { } catch (err: any) {
return `Error moving ticket: ${err.message}` return `Error moving ticket: ${err.message}`;
} }
}, },
}) });
export const comment = tool({ export const comment = tool({
description: "Add a comment to an existing ticket.", description: "Add a comment to an existing ticket.",
args: { args: {
ticket: tool.schema.string().describe("Ticket UUID (8+ chars) or title substring"), ticket: tool.schema
.string()
.describe("Ticket UUID (8+ chars) or title substring"),
body: tool.schema.string().describe("Comment body (required)"), body: tool.schema.string().describe("Comment body (required)"),
owner: tool.schema.string().describe("Comment author").optional(), owner: tool.schema.string().describe("Comment author").optional(),
}, },
async execute(args: Record<string, never>, context: Parameters<(typeof tool)['prototype'].execute>[1]) { async execute(args: Record<string, any>, context: ToolContext) {
const cmd: (string | number)[] = ["comment", args.ticket, args.body];
if (args.owner) cmd.push("--owner", args.owner);
const workdir = resolveWorklaneDir(context);
try { try {
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() const proc = Bun.spawn(["worklane", ...cmd], { cwd: workdir });
return result.trim() const { exitCode, stdout, stderr } = await proc.exited;
if (exitCode !== 0) {
const stderrStr = new TextDecoder().decode(stderr);
throw new Error(stderrStr.trim() || `Exit code ${exitCode}`);
}
return new TextDecoder().decode(stdout).trim();
} catch (err: any) { } catch (err: any) {
return `Error adding comment: ${err.message}` return `Error adding comment: ${err.message}`;
} }
}, },
}) });