import { tool, ToolContext } from "@opencode-ai/plugin"; import path from "path"; function resolveWorklaneDir(context: ToolContext): string { return path.join(context.worktree || context.directory || "."); } /** * Run worklane and return its stdout, throwing with its stderr on failure. * * Both streams have to be piped. Bun defaults stderr to inherit, so it went to * this process and never reached the model, and Bun.$ throws a ShellError whose * message is only "Failed with exit code 1". Either way the CLI explained itself * and nothing relayed the explanation. * * stdout is the fallback, not the source: worklane writes errors to stderr. */ async function run(cmd: string[], context: ToolContext): Promise { const proc = Bun.spawn(["worklane", ...cmd], { cwd: resolveWorklaneDir(context), stdout: "pipe", stderr: "pipe", }); const [stdout, stderr, exitCode] = await Promise.all([ new Response(proc.stdout).text(), new Response(proc.stderr).text(), proc.exited, ]); if (exitCode !== 0) { // anyhow prefixes its own "Error: ", and every caller here adds a prefix of // its own, so drop it rather than relaying "Error adding comment: Error: ...". const reason = stderr.trim().replace(/^Error:\s*/, ""); throw new Error(reason || stdout.trim() || `worklane exited with code ${exitCode}`); } return stdout.trim(); } /** * Description lines as worklane wants them, one --description value per line, * blank ones included. * * cmd_add joins the values with a single newline, so an empty value is how a * paragraph break is spelled. Dropping the blanks here, which is what the old * filter(Boolean) did, collapsed every multi paragraph description into a single * paragraph, against this tool's own instruction to separate paragraphs with * newlines. * * Only the ends are trimmed, and only trailing whitespace within a line. Leading * whitespace is content: it is what makes a nested markdown list or an indented * block survive the trip. */ function descriptionLines(text: string): string[] { const lines = text.split("\n").map((line: string) => line.trimEnd()); let start = 0; let end = lines.length; while (start < end && lines[start] === "") start++; while (end > start && lines[end - 1] === "") end--; return lines.slice(start, end); } /** One value per non-empty line, for the arguments that hold a list of items. */ function itemLines(text: string): string[] { return text .split("\n") .map((line: string) => line.trim()) .filter(Boolean); } 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(_args: Record, context: ToolContext) { try { return await run(["init"], context); } catch (err: any) { return `Error initializing worklane: ${err.message}`; } }, }); export const add = tool({ description: "Add a new ticket to the worklane backlog. Requires a title. Description, acceptance criteria, and plan each support multiple lines (one item per line). Tags are comma-separated.", // Title is the only required field. Every other flag is left off entirely when // the field is omitted, so an unmarked schema only forced the model to invent a // value for fields it had nothing to say about. args: { title: tool.schema .string() .describe("Ticket title (required)"), description: tool.schema .string() .describe("Description text. Use newlines between paragraphs.") .optional(), acceptance: tool.schema .string() .describe("Acceptance criteria, one per line. Put each criterium on its own line.") .optional(), plan: tool.schema .string() .describe("Implementation plan steps, one per line. Put each step on its own line.") .optional(), tags: tool.schema .string() .describe("Comma-separated tags, e.g. 'bug,frontend,urgent'") .optional(), due: tool.schema .string() .describe("Due date in YYYY-MM-DD format") .optional(), owner: tool.schema .string() .describe("Ticket owner name. If omitted, defaults to the git user.") .optional(), priority: tool.schema .string() .describe("Priority level, 1 (most urgent) to 5 (least). Left unset if omitted.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.title) { return "Error adding ticket: title is required"; } const cmd: string[] = ["add", "--title", args.title]; if (args.description) { descriptionLines(args.description).forEach((line: string) => cmd.push("--description", line), ); } // Blanks are dropped from these two on purpose: each value is one criterium or // one step, so an empty line between them is spacing rather than content. if (args.acceptance) { itemLines(args.acceptance).forEach((line: string) => cmd.push("--acceptance", line), ); } if (args.plan) { itemLines(args.plan).forEach((line: string) => cmd.push("--plan", line)); } if (args.tags) cmd.push("--tags", args.tags); if (args.due) cmd.push("--due", args.due); if (args.owner) cmd.push("--owner", args.owner); if (args.priority) cmd.push("--priority", String(args.priority)); try { return await run(cmd, context); } catch (err: any) { return `Error adding ticket: ${err.message}`; } }, }); export const ls = tool({ description: "List all worklane tickets, sorted by priority then title. Optionally filter by status and by priority.", args: { status: tool.schema .enum(["backlog", "committed", "reviewing", "done"]) .describe("Filter by status") .optional(), priority: tool.schema .string() .describe("Only show tickets at this priority, 1 (most urgent) to 5 (least)") .optional(), }, async execute(args: Record, context: ToolContext) { const cmd = args.status ? ["ls", args.status] : ["ls"]; if (args.priority) cmd.push("--priority", String(args.priority)); try { return await run(cmd, context); } catch (err: any) { // The directory is worth naming here: the usual failure is that there is // no .worklane above it. return `Error listing tickets: ${err.message}, Dir: ${resolveWorklaneDir(context)}`; } }, }); export const show = tool({ description: "Show a complete ticket by UUID or title. Displays title, description, acceptance criteria, implementation plan, metadata, and the history: every comment on it and every change to its status, owner or tags.", args: { id: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), }, async execute(args: Record, context: ToolContext) { if (!args.id) { return "Error showing ticket: id is required"; } try { return await run(["show", args.id], context); } catch (err: any) { return `Error showing ticket: ${err.message}`; } }, }); export const mv = tool({ description: "Move a ticket to a different status in the workflow (backlog -> committed -> reviewing -> done).", args: { ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), status: tool.schema .enum(["backlog", "committed", "reviewing", "done"]) .describe("Target status (required)"), force: tool.schema .boolean() .describe("Force move (allows non-sequential moves like done -> backlog). Use with caution.") .optional(), actor: tool.schema .string() .describe("Who the entry is attributed to. If omitted, WORKLANE_ACTOR is used, then the git user, then \"unknown\". Set WORKLANE_ACTOR in the environment opencode is started with rather than passing this on every call.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.ticket) { return "Error moving ticket: ticket is required"; } if (!args.status) { return "Error moving ticket: status is required. Must be one of: backlog, committed, reviewing, done"; } const cmd: string[] = ["mv", args.ticket, "--status", args.status]; if (args.force) cmd.push("--force"); if (args.actor) cmd.push("--actor", args.actor); try { return await run(cmd, context); } catch (err: any) { return `Error moving ticket: ${err.message}`; } }, }); export const comment = tool({ description: "Add a comment to an existing ticket. The comment body supports markdown and newlines. Use it to add review feedback, notes, or status updates.", args: { ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), body: tool.schema .string() .describe("Comment body text (required). Supports markdown formatting and multiple paragraphs separated by newlines."), actor: tool.schema .string() .describe("Who the entry is attributed to. If omitted, WORKLANE_ACTOR is used, then the git user, then \"unknown\". Set WORKLANE_ACTOR in the environment opencode is started with rather than passing this on every call.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.ticket) { return "Error adding comment: ticket is required"; } if (!args.body) { return "Error adding comment: body is required"; } const cmd: string[] = ["comment", args.ticket, args.body]; if (args.actor) cmd.push("--actor", args.actor); try { return await run(cmd, context); } catch (err: any) { return `Error adding comment: ${err.message}`; } }, }); export const set = tool({ description: "Replace fields on an existing worklane ticket. Only the fields given are touched; everything else in the file, including ticked criteria and handwritten sections, is left alone. Owner is not settable here, use chown. Status is not settable here, use mv. To add to a section instead of replacing it, use append.", args: { ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), title: tool.schema .string() .describe("New title. The file is renamed to match, keeping the UUID.") .optional(), description: tool.schema .string() .describe("New description, replacing the whole section. Use newlines between paragraphs.") .optional(), acceptance: tool.schema .string() .describe("New acceptance criteria, one per line, replacing the whole list.") .optional(), plan: tool.schema .string() .describe("New implementation plan steps, one per line, replacing the whole list.") .optional(), tags: tool.schema .string() .describe("New comma-separated tags, replacing the existing ones.") .optional(), due: tool.schema .string() .describe("New due date in YYYY-MM-DD format") .optional(), priority: tool.schema .string() .describe("New priority level, 1 (most urgent) to 5 (least)") .optional(), actor: tool.schema .string() .describe("Who the entry is attributed to. Only reaches the entry tags writes, since that is the one field of this command's that is logged. If omitted, WORKLANE_ACTOR is used, then the git user.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.ticket) { return "Error setting fields: ticket is required"; } const cmd: string[] = ["set", args.ticket]; if (args.title) cmd.push("--title", args.title); if (args.description) { descriptionLines(args.description).forEach((line: string) => cmd.push("--description", line), ); } if (args.acceptance) { itemLines(args.acceptance).forEach((line: string) => cmd.push("--acceptance", line), ); } if (args.plan) { itemLines(args.plan).forEach((line: string) => cmd.push("--plan", line)); } if (args.tags) cmd.push("--tags", args.tags); if (args.due) cmd.push("--due", args.due); if (args.priority) cmd.push("--priority", String(args.priority)); // Last, and not counted as a field: the length check below is what refuses a call // that names nothing to change, and an actor alone changes nothing. const fields = cmd.length; if (args.actor) cmd.push("--actor", args.actor); if (fields === 2) { return "Error setting fields: give at least one field to change"; } try { return await run(cmd, context); } catch (err: any) { return `Error setting fields: ${err.message}`; } }, }); export const append = tool({ description: "Add to an existing worklane ticket without replacing what is there. The description gains a new paragraph; acceptance criteria and plan steps are added to the end of their lists, with steps numbered on from the last; tags are added to the ones the ticket already carries. Ticked criteria and handwritten content are left alone. To replace a section or the whole tag list outright, use set.", args: { ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), description: tool.schema .string() .describe("Text to add as a new paragraph at the end of the description.") .optional(), acceptance: tool.schema .string() .describe("Acceptance criteria to add, one per line.") .optional(), plan: tool.schema .string() .describe("Implementation plan steps to add, one per line.") .optional(), tags: tool.schema .string() .describe("Tags to add, comma separated, keeping the ones the ticket already carries. A tag it already has is reported as no change rather than added twice, so the ticket does not have to be read first.") .optional(), actor: tool.schema .string() .describe("Who the entry is attributed to. Only reaches the entry tags writes, since that is the one field of this command's that is logged. If omitted, WORKLANE_ACTOR is used, then the git user.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.ticket) { return "Error appending: ticket is required"; } const cmd: string[] = ["append", args.ticket]; if (args.description) { descriptionLines(args.description).forEach((line: string) => cmd.push("--description", line), ); } if (args.acceptance) { itemLines(args.acceptance).forEach((line: string) => cmd.push("--acceptance", line), ); } if (args.plan) { itemLines(args.plan).forEach((line: string) => cmd.push("--plan", line)); } if (args.tags) cmd.push("--tags", args.tags); // Last, and not counted as a field: the length check below is what refuses a call // that names nothing to add, and an actor alone adds nothing. Same shape as set. const fields = cmd.length; if (args.actor) cmd.push("--actor", args.actor); if (fields === 2) { return "Error appending: give at least one field to add to"; } try { return await run(cmd, context); } catch (err: any) { return `Error appending: ${err.message}`; } }, }); export const chown = tool({ description: "Change the owner of a worklane ticket. This is the only writer of the Owner field: set does not offer it. The user is free text and is checked against nothing. Note the argument order, user first and ticket second, after Unix chown.", args: { user: tool.schema .string() .describe("New owner (required). Free text, checked against nothing."), ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), actor: tool.schema .string() .describe("Who the entry is attributed to, which on this command is not the same as user: user becomes the ticket's owner, actor is who made the change. If omitted, WORKLANE_ACTOR is used, then the git user, then \"unknown\".") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.user) { return "Error changing owner: user is required"; } if (!args.ticket) { return "Error changing owner: ticket is required"; } const cmd: string[] = ["chown", args.user, args.ticket]; if (args.actor) cmd.push("--actor", args.actor); try { return await run(cmd, context); } catch (err: any) { return `Error changing owner: ${err.message}`; } }, }); /** * check and uncheck differ only in the verb, so the tool is built once. * * The criteria are required here even though the CLI makes them optional: without any * the CLI prompts, and there is no terminal on this side of the pipe. The CLI answers a * missing criterion with the numbered list on stderr, which run() relays, so the model * sees the options and can retry with a number. * * One value per line, like the other list arguments, and every value goes in one call. * The CLI resolves them all before it writes, so a bad term costs nothing, and finishing * a ticket is one tool call rather than one per box. */ function checkboxTool(verb: "check" | "uncheck") { const past = verb === "check" ? "Checked" : "Unchecked"; return tool({ description: `${past === "Checked" ? "Tick" : "Untick"} acceptance criteria on a worklane ticket. ` + "Every criterion not named keeps its state. Identify each one by its number as shown by show, " + "or by a substring of its text; a substring matching more than one is an error listing them. " + `Pass several, one per line, to ${verb} them in a single call, or the single word all for every ` + "criterion on the ticket. If any value cannot be resolved the whole call is refused and nothing " + "is written, so a partly wrong list never leaves the ticket half-marked.", args: { ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), criteria: tool.schema .string() .describe( "Criterion numbers as shown by show, or substrings of their text, one per line. " + "Or the single word all for every criterion (required)", ), }, async execute(args: Record, context: ToolContext) { if (!args.ticket) { return `Error running ${verb}: ticket is required`; } const terms = args.criteria ? itemLines(String(args.criteria)) : []; if (terms.length === 0) { return `Error running ${verb}: criteria is required, give the numbers, substrings, or all`; } try { return await run([verb, args.ticket, ...terms], context); } catch (err: any) { return `Error running ${verb}: ${err.message}`; } }, }); } export const check = checkboxTool("check"); export const uncheck = checkboxTool("uncheck"); /** * relate is the only writer of the Relations section, so the tool mirrors it rather * than folding relations into set. * * The clear half is one argument per kind rather than a free-text "kind target" line, * which is what the CLI's single --clear flag would force here. A kind inside a value * cannot be typed by the schema, a target is a search that may itself contain spaces, * and splitting the pair apart by hand re-parses what clap already refuses to guess at. * Per kind the target stays a plain line, the way every other list argument works. */ export const relate = tool({ description: "Record a relation from one ticket to another, or take one off. Kinds: blocked-by means this one waits on that one and its moves are refused while the target is open; regression-of means this one broke that one's fix; relates-to is a neighbour with no dependency. The edge is stored on the ticket you name alone, and show derives the other end for the target, so never record both directions.", args: { ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), blocked_by: tool.schema .string() .describe("Target tickets this one waits on, one per line.") .optional(), regression_of: tool.schema .string() .describe("Target tickets whose fix this one broke, one per line.") .optional(), relates_to: tool.schema .string() .describe("Target tickets this one merely relates to, one per line.") .optional(), clear_blocked_by: tool.schema .string() .describe("Targets whose blocked-by edge comes off this ticket, one per line.") .optional(), clear_regression_of: tool.schema .string() .describe("Targets whose regression-of edge comes off this ticket, one per line.") .optional(), clear_relates_to: tool.schema .string() .describe("Targets whose relates-to edge comes off this ticket, one per line.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.ticket) { return "Error relating tickets: ticket is required"; } const cmd: string[] = ["relate", args.ticket]; if (args.blocked_by) itemLines(args.blocked_by).forEach((line) => cmd.push("--blocked-by", line)); if (args.regression_of) { itemLines(args.regression_of).forEach((line) => cmd.push("--regression-of", line)); } if (args.relates_to) itemLines(args.relates_to).forEach((line) => cmd.push("--relates-to", line)); // The kind is spelled the way the flag records it, not the way show prints it: // the CLI takes either, and the flag spelling is the one with no space in it. if (args.clear_blocked_by) { itemLines(args.clear_blocked_by).forEach((line) => cmd.push("--clear", "blocked-by", line)); } if (args.clear_regression_of) { itemLines(args.clear_regression_of).forEach((line) => cmd.push("--clear", "regression-of", line)); } if (args.clear_relates_to) { itemLines(args.clear_relates_to).forEach((line) => cmd.push("--clear", "relates-to", line)); } if (cmd.length === 2) { return "Error relating tickets: name a relation to record or one to clear"; } try { return await run(cmd, context); } catch (err: any) { return `Error relating tickets: ${err.message}`; } }, }); /** * Five tools for the five campaign subcommands, one export each. * * One tool taking an action argument would mirror the CLI nesting, but the schema * could then no longer say which arguments belong to which action: campaign_set's * force only means something beside --codename, and campaign_append's description is * required where add's is not. Separate exports keep each schema true, and the ids * read as the CLI path anyway, since opencode builds them from this file name plus * the export: worklane_campaign_set. */ export const campaign_add = tool({ description: "File a new campaign: several separate tickets that have to be finished together for one goal. Its state is derived from its members, so there is nothing to move or close. Give a codename when you can: one word the board draws on every card in the campaign and the shortest thing that addresses it.", args: { title: tool.schema .string() .describe("Campaign title (required)"), description: tool.schema .string() .describe("What the campaign is for. Use newlines between paragraphs.") .optional(), codename: tool.schema .string() .describe("One word to call the campaign by, e.g. 'v1' or 'beaver'.") .optional(), owner: tool.schema .string() .describe("Campaign owner name. If omitted, defaults to the git user.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.title) { return "Error adding campaign: title is required"; } const cmd: string[] = ["campaign", "add", "--title", args.title]; if (args.description) { descriptionLines(args.description).forEach((line: string) => cmd.push("--description", line), ); } if (args.codename) cmd.push("--codename", String(args.codename)); if (args.owner) cmd.push("--owner", args.owner); try { return await run(cmd, context); } catch (err: any) { return `Error adding campaign: ${err.message}`; } }, }); export const campaign_set = tool({ description: "Replace fields on an existing campaign: its title, its description or its codename. Replacing a codename the campaign already has needs force, since everything refers to the campaign by that word once it exists; setting the codename it already carries is a no-op either way. Membership is not set here, use assign.", args: { campaign: tool.schema .string() .describe("Campaign UUID prefix, codename or title substring (required)"), title: tool.schema .string() .describe("New title. The file is renamed to match, keeping the UUID.") .optional(), description: tool.schema .string() .describe("New description, replacing the whole section. Use newlines between paragraphs.") .optional(), codename: tool.schema .string() .describe("New codename, one word. Replacing an existing one needs force.") .optional(), force: tool.schema .boolean() .describe("Allow replacing a codename the campaign already has.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.campaign) { return "Error setting campaign fields: campaign is required"; } const cmd: string[] = ["campaign", "set", args.campaign]; if (args.title) cmd.push("--title", args.title); if (args.description) { descriptionLines(args.description).forEach((line: string) => cmd.push("--description", line), ); } if (args.codename) cmd.push("--codename", String(args.codename)); if (args.force) cmd.push("--force"); if (cmd.length === 3) { return "Error setting campaign fields: give at least one field to change"; } try { return await run(cmd, context); } catch (err: any) { return `Error setting campaign fields: ${err.message}`; } }, }); export const campaign_append = tool({ description: "Add a paragraph to a campaign's description without replacing what is already written. To replace the whole description, use campaign_set.", args: { campaign: tool.schema .string() .describe("Campaign UUID prefix, codename or title substring (required)"), description: tool.schema .string() .describe("Text to add as a new paragraph at the end of the description (required)."), }, async execute(args: Record, context: ToolContext) { if (!args.campaign) { return "Error appending to campaign: campaign is required"; } if (!args.description) { return "Error appending to campaign: description is required"; } const cmd: string[] = ["campaign", "append", args.campaign]; descriptionLines(args.description).forEach((line: string) => cmd.push("--description", line), ); try { return await run(cmd, context); } catch (err: any) { return `Error appending to campaign: ${err.message}`; } }, }); export const campaign_ls = tool({ description: "List campaigns with how far each has got: id, codename or title, owner, and done members against total. Open until every member is done or discarded.", args: { ids: tool.schema .boolean() .describe("Print only id and title, tab separated, one per line, for parsing.") .optional(), }, async execute(args: Record, context: ToolContext) { const cmd = ["campaign", "ls"]; if (args.ids) cmd.push("--ids"); try { return await run(cmd, context); } catch (err: any) { return `Error listing campaigns: ${err.message}, Dir: ${resolveWorklaneDir(context)}`; } }, }); export const campaign_show = tool({ description: "Show a campaign's body and its members grouped by status, done included, so what is finished against what is left is one answer.", args: { campaign: tool.schema .string() .describe("Campaign UUID prefix, codename or title substring (required)"), }, async execute(args: Record, context: ToolContext) { if (!args.campaign) { return "Error showing campaign: campaign is required"; } try { return await run(["campaign", "show", args.campaign], context); } catch (err: any) { return `Error showing campaign: ${err.message}`; } }, }); export const assign = tool({ description: "Put a ticket in a campaign, moving it out of whichever campaign it was in: a ticket is in at most one. Note the order, campaign first and ticket second, after chown.", args: { campaign: tool.schema .string() .describe("Campaign UUID prefix, codename or title substring (required)"), ticket: tool.schema .string() .describe("Ticket UUID prefix (4+ chars) or title substring (required)"), actor: tool.schema .string() .describe("Who the entry is attributed to. If omitted, WORKLANE_ACTOR is used, then the git user, then \"unknown\". Set WORKLANE_ACTOR in the environment opencode is started with rather than passing this on every call.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.campaign) { return "Error assigning ticket: campaign is required"; } if (!args.ticket) { return "Error assigning ticket: ticket is required"; } const cmd: string[] = ["assign", args.campaign, args.ticket]; if (args.actor) cmd.push("--actor", args.actor); try { return await run(cmd, context); } catch (err: any) { return `Error assigning ticket: ${err.message}`; } }, }); /** * Three tools for tags, and none for `tags ls`: it prints exactly what the bare * `worklane tags` listing prints, which the tags tool runs. * * The annotation lines go through descriptionLines, not itemLines: an empty value is * a paragraph break in an annotation, exactly as it is in a description, because the * value_parser on the CLI side accepts one and the vocabulary file stores prose under * the tag heading. */ export const tags = tool({ description: "List the tags the board carries: the tag, how many tickets carry it, and the opening line of its declared meaning. Read this before inventing a tag. Case sensitive, so bug and Bug list separately and land next to each other, which is where a near-duplicate is spotted.", args: {}, async execute(_args: Record, context: ToolContext) { try { return await run(["tags"], context); } catch (err: any) { return `Error listing tags: ${err.message}, Dir: ${resolveWorklaneDir(context)}`; } }, }); export const tags_add = tool({ description: "Declare a tag and what it means: when the next ticket belongs in it. The tag is spelled exactly the way ls --tag matches it, one word with no comma in it.", args: { tag: tool.schema .string() .describe("The tag to declare (required), e.g. 'bug' or 'frontend'."), annotation: tool.schema .string() .describe("What the tag means and when it is appropriate. Use newlines between paragraphs.") .optional(), }, async execute(args: Record, context: ToolContext) { if (!args.tag) { return "Error declaring tag: tag is required"; } const cmd: string[] = ["tags", "add", args.tag]; if (args.annotation) { descriptionLines(args.annotation).forEach((line: string) => cmd.push("--annotation", line), ); } try { return await run(cmd, context); } catch (err: any) { return `Error declaring tag: ${err.message}`; } }, }); export const tags_set = tool({ description: "Replace what a declared tag means, keeping the tickets carrying it. There is no rename: changing the word itself means rewriting the Tags field of every ticket that carries it, which is a migration and not this call.", args: { tag: tool.schema .string() .describe("The tag to change, spelled the way it was declared (required)."), annotation: tool.schema .string() .describe("What the tag means, replacing whatever it said before. Use newlines between paragraphs (required)."), }, async execute(args: Record, context: ToolContext) { if (!args.tag) { return "Error setting tag meaning: tag is required"; } if (!args.annotation) { return "Error setting tag meaning: annotation is required"; } const cmd: string[] = ["tags", "set", args.tag]; descriptionLines(args.annotation).forEach((line: string) => cmd.push("--annotation", line), ); try { return await run(cmd, context); } catch (err: any) { return `Error setting tag meaning: ${err.message}`; } }, });