@konductro/cursor-plugin 1.1.0 → 1.2.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/README.md +64 -0
- package/package.json +1 -1
- package/servers/konductro-api.js +305 -5
package/README.md
CHANGED
|
@@ -59,6 +59,9 @@ Tools are called automatically by Cursor's agent based on your requests:
|
|
|
59
59
|
| `get_ticket_context` | Load full context for a ticket |
|
|
60
60
|
| `start_work` | Create branch and start a ticket |
|
|
61
61
|
| `create_pr` | Create a pull request for a ticket |
|
|
62
|
+
| `create_work_item` | Create a story, task or bug in the project this repo belongs to |
|
|
63
|
+
| `update_work_item` | Change the title, description or acceptance criteria of a work item you own |
|
|
64
|
+
| `delete_work_item` | Delete a task or bug that has not been started |
|
|
62
65
|
| `list_tech_analysis_tasks` | List tech analysis assignments |
|
|
63
66
|
| `get_task_context` | Load tech analysis context |
|
|
64
67
|
| `submit_tech_analysis` | Submit analysis document |
|
|
@@ -74,6 +77,67 @@ Tools are called automatically by Cursor's agent based on your requests:
|
|
|
74
77
|
| `profile_repository` | Submit repository profile |
|
|
75
78
|
| `find_project_prototypes` | Find UX prototypes for a project |
|
|
76
79
|
|
|
80
|
+
### Work items
|
|
81
|
+
|
|
82
|
+
The project is resolved from the repository's git remote, so you are never asked for a
|
|
83
|
+
project identifier.
|
|
84
|
+
|
|
85
|
+
**Everything created lands in Draft** and still needs an SDM's approval before it can be
|
|
86
|
+
worked on.
|
|
87
|
+
|
|
88
|
+
**`update_work_item` can change three fields and no others.** Status, sprint, assignee and
|
|
89
|
+
everything else are deliberately not on the schema — change those in Konductro. Sending
|
|
90
|
+
`acceptanceCriteria` replaces the whole list rather than appending to it. The `changed`
|
|
91
|
+
list it reports back is the fields that were written, not the ones that turned out to
|
|
92
|
+
differ, so re-sending a value unchanged still shows up in it.
|
|
93
|
+
|
|
94
|
+
**A task is created in the repository you are standing in.** Its parent story is the only
|
|
95
|
+
thing you need to name. Set `repositoryId` yourself only for a task that will be built in a
|
|
96
|
+
different repository on the same project.
|
|
97
|
+
|
|
98
|
+
**Only a task may have a parent.** A story or a bug sent with a `parentKey` is refused and
|
|
99
|
+
nothing is created, rather than being filed top-level as though it had worked. A bug is
|
|
100
|
+
always standalone here — Konductro parents one to a story only when QA files it against a
|
|
101
|
+
failed test criterion — so name the story in the description instead. A story is top-level
|
|
102
|
+
by definition: the hierarchy is story → task, and work that belongs under a story is a task.
|
|
103
|
+
|
|
104
|
+
**`create_work_item` returns the new item's id.** Use it for the follow-up call. Ticket
|
|
105
|
+
keys are prefix plus number and the prefix is not returned, so a guessed key resolves to a
|
|
106
|
+
different project's item of the same number instead of failing.
|
|
107
|
+
|
|
108
|
+
#### Who can create and change stories
|
|
109
|
+
|
|
110
|
+
Each project has a story access setting, which an SDM controls under Settings → General:
|
|
111
|
+
|
|
112
|
+
| Setting | What a developer can do |
|
|
113
|
+
|---|---|
|
|
114
|
+
| **Planning roles only** | Cannot create or change stories. Filing bugs and editing tasks are unaffected. |
|
|
115
|
+
| **Developers can, with review** | Changes apply straight away, then wait for an SDM to approve or reject. |
|
|
116
|
+
| **Developers can, no review** | Creates and changes apply with nothing held for approval. |
|
|
117
|
+
|
|
118
|
+
A new project starts on **planning roles only**.
|
|
119
|
+
|
|
120
|
+
Under *with review*, a change to a story is applied and then held: the story will not move
|
|
121
|
+
to Ready for QA until an SDM resolves it, even once every task is done. If it is rejected,
|
|
122
|
+
the previous values are restored and you are notified.
|
|
123
|
+
|
|
124
|
+
#### What a refusal means
|
|
125
|
+
|
|
126
|
+
These are answers, not errors — none of them is worth retrying as-is.
|
|
127
|
+
|
|
128
|
+
| You will see | What to do |
|
|
129
|
+
|---|---|
|
|
130
|
+
| The project's story access is set to planning roles only | A project setting. Ask an SDM to make the change, or to open story access for developers. |
|
|
131
|
+
| You can only change work items assigned to you, that you are the developer on, or that you created | Ask whoever owns it, or ask an SDM. |
|
|
132
|
+
| Stories cannot be deleted from the CLI | Deleting a story removes its tasks with it. Archive it in Konductro instead. |
|
|
133
|
+
| QA filed this bug against a failed test criterion | It is QA's record of a failure, not yours to remove. |
|
|
134
|
+
| Only a task can be created under a parent | Nothing was created. For a bug, re-run without `parentKey` and name the story in the description. For a story, you probably wanted `kind: "task"`. |
|
|
135
|
+
| Work has already started on this item | It has a branch, or has moved past sprint planning. Only items still in draft, approved or in_sprint can be deleted. |
|
|
136
|
+
| Your seat is a viewer seat | Read-only across the whole platform, not a project setting. Ask an admin for a contributor seat. |
|
|
137
|
+
| Your role on this project is read-only | Ask an SDM for a writing role on the project. |
|
|
138
|
+
| You are not a member of this project | Ask an SDM to add you to the project team. |
|
|
139
|
+
| Konductro is not configured | A setup problem rather than a permissions one — re-run `konductro-cursor-setup` with your URL and token. |
|
|
140
|
+
|
|
77
141
|
## Updating Your Token
|
|
78
142
|
|
|
79
143
|
Run the setup command again with the new token:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@konductro/cursor-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Cursor IDE plugin for the Konductro platform: technical analysis, delivery tasks, repository profiling, and prototype workflows.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
package/servers/konductro-api.js
CHANGED
|
@@ -52,13 +52,148 @@ async function konductroFetch(path, options = {}) {
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
if (!response.ok) {
|
|
55
|
-
const
|
|
56
|
-
|
|
55
|
+
const raw = await response.text().catch(() => '');
|
|
56
|
+
// KON-520: keep the machine-readable code and status on the error. The backend
|
|
57
|
+
// answers { error, code, details? }, and every tool should branch on CODE rather than
|
|
58
|
+
// on message text so a wording change server-side cannot break the plugin.
|
|
59
|
+
//
|
|
60
|
+
// NOTE this CHANGED err.message. It used to be the whole envelope —
|
|
61
|
+
// `Konductro API error (404): {"error":"Bug not found","code":"BUG_NOT_FOUND"}` — and
|
|
62
|
+
// is now just the `error` sentence. Anything that used to sniff the message for a
|
|
63
|
+
// status or a code no longer matches, so those call sites were moved onto err.code /
|
|
64
|
+
// err.status (get_bug_for_enrichment and submit_bug_enrichment). If you add a tool,
|
|
65
|
+
// read the code; do not go back to matching text.
|
|
66
|
+
let parsed = null;
|
|
67
|
+
try { parsed = JSON.parse(raw); } catch { /* not JSON — fall through to the raw body */ }
|
|
68
|
+
const err = new Error(
|
|
69
|
+
parsed?.error ? parsed.error : `Konductro API error (${response.status}): ${raw}`,
|
|
70
|
+
);
|
|
71
|
+
err.status = response.status;
|
|
72
|
+
err.code = parsed?.code ?? null;
|
|
73
|
+
// Zod's flatten() on a validation failure. Kept so a refusal can name the offending
|
|
74
|
+
// field instead of saying "Validation failed" and leaving the agent to guess.
|
|
75
|
+
err.details = parsed?.details ?? null;
|
|
76
|
+
throw err;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
79
|
return response.json();
|
|
60
80
|
}
|
|
61
81
|
|
|
82
|
+
// ─── KON-520: work-item tools ────────────────────────────────────────────────
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Turn a backend refusal into a sentence a developer can act on.
|
|
86
|
+
*
|
|
87
|
+
* A bare 403 makes an agent retry or guess. Each of these says what to do instead, and
|
|
88
|
+
* the setting-related one NAMES the setting, because the developer's next move is to ask
|
|
89
|
+
* their SDM rather than to try again.
|
|
90
|
+
*
|
|
91
|
+
* Keyed on code, never on message text.
|
|
92
|
+
*/
|
|
93
|
+
function refusalText(err) {
|
|
94
|
+
switch (err.code) {
|
|
95
|
+
case 'STORY_ACCESS_DENIED':
|
|
96
|
+
return "Refused: this project's story access is set to planning roles only, so stories here can only be created or edited by an SDM, architect or UX lead. This is a project setting, not something to retry — ask an SDM to make the change, or to open story access for developers. Filing bugs and editing tasks are unaffected.";
|
|
97
|
+
case 'NOT_YOUR_WORK_ITEM':
|
|
98
|
+
return 'Refused: you can only change work items assigned to you, that you are the developer on, or that you created. Ask whoever owns it, or ask an SDM to make the change.';
|
|
99
|
+
case 'STORIES_NOT_DELETABLE':
|
|
100
|
+
return 'Refused: stories cannot be deleted from the CLI — deleting one removes its tasks with it and cannot be undone. Archive it in Konductro instead.';
|
|
101
|
+
case 'QA_FILED_BUG':
|
|
102
|
+
return "Refused: QA filed this bug against a failed test criterion, so it is their record of what went wrong and is not yours to remove. Fix it, or ask QA if it was raised in error.";
|
|
103
|
+
case 'WORK_ALREADY_STARTED':
|
|
104
|
+
// Mirrors DELETABLE_STATUSES in work-item-access.service.ts: draft, approved and
|
|
105
|
+
// in_sprint are all still deletable. Anything past those, or anything with a
|
|
106
|
+
// branch, is not.
|
|
107
|
+
return 'Refused: work has already started on this item — it has a branch, or has moved past sprint planning (only items still in draft, approved or in_sprint can be deleted). Deleting it would orphan the branch. Close it out in Konductro instead.';
|
|
108
|
+
case 'INSUFFICIENT_ROLE':
|
|
109
|
+
return 'Refused: your Konductro seat is a viewer seat, which is read-only across the whole platform. This is not a project setting — ask an admin to move you to a contributor seat.';
|
|
110
|
+
case 'READ_ONLY_ROLE':
|
|
111
|
+
return 'Refused: your role on this project is read-only (viewer or stakeholder), so you cannot create or change work items here. Ask an SDM to give you a writing role on the project.';
|
|
112
|
+
case 'NOT_PROJECT_MEMBER':
|
|
113
|
+
return 'Refused: you are not a member of this project, so you cannot create or change work items in it. Ask an SDM to add you to the project team.';
|
|
114
|
+
default:
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A missing token is a setup problem, not a permission problem — say so differently.
|
|
121
|
+
*
|
|
122
|
+
* Uses this plugin's own NOT_CONFIGURED_MESSAGE, which names the `konductro-cursor-setup`
|
|
123
|
+
* command, rather than telling a Cursor user to go and set environment variables by hand.
|
|
124
|
+
* The `setup` flag is what workItemCall reads: the message is this repo's, so matching on
|
|
125
|
+
* its opening words the way the reference plugin does would not survive here.
|
|
126
|
+
*/
|
|
127
|
+
function assertAuthConfigured() {
|
|
128
|
+
if (!KONDUCTRO_URL || !CLI_TOKEN) {
|
|
129
|
+
const err = new Error(NOT_CONFIGURED_MESSAGE);
|
|
130
|
+
err.setup = true;
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Name the field a validation failure is actually about.
|
|
137
|
+
*
|
|
138
|
+
* The backend answers INVALID_BODY with Zod's flatten() attached. Dropping it leaves the
|
|
139
|
+
* agent holding "Validation failed" with nothing to correct, which it can only respond to
|
|
140
|
+
* by guessing — so the whole point of validating is lost on the way back.
|
|
141
|
+
*/
|
|
142
|
+
function validationText(err) {
|
|
143
|
+
const f = err.details?.fieldErrors ?? {};
|
|
144
|
+
const fields = Object.entries(f)
|
|
145
|
+
.map(([name, msgs]) => `${name} (${(msgs ?? []).join('; ')})`)
|
|
146
|
+
.join(', ');
|
|
147
|
+
const form = (err.details?.formErrors ?? []).join('; ');
|
|
148
|
+
const parts = [fields, form].filter(Boolean).join(' — ');
|
|
149
|
+
if (!parts) return err.message;
|
|
150
|
+
// The backend's sentence for this code is sometimes unpunctuated ('Validation failed'),
|
|
151
|
+
// so close it before appending rather than running the two together.
|
|
152
|
+
const lead = /[.!?]$/.test(err.message) ? err.message : `${err.message}.`;
|
|
153
|
+
return `${lead} Problem with: ${parts}.`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Every work-item tool answers refusals the same way, so the cases read alike.
|
|
158
|
+
*
|
|
159
|
+
* ON isError. A REFUSAL is not an error — it is a correct, final answer to a question the
|
|
160
|
+
* developer was entitled to ask, and flagging it as an error is what makes an agent retry
|
|
161
|
+
* it or escalate around it. A genuine FAILURE (bad token, unreachable server, a 500, a
|
|
162
|
+
* shape the backend rejected) is an error, and is flagged, because the agent should stop
|
|
163
|
+
* and surface it rather than carry on as if the write landed.
|
|
164
|
+
*
|
|
165
|
+
* This is deliberately NOT "whatever the rest of the file does": most tools here flag
|
|
166
|
+
* nothing at all and report failures as ordinary prose, which is the weaker half of the
|
|
167
|
+
* convention. The two bug-enrichment tools already make the distinction this follows.
|
|
168
|
+
*/
|
|
169
|
+
async function workItemCall(fn) {
|
|
170
|
+
try {
|
|
171
|
+
assertAuthConfigured();
|
|
172
|
+
return { content: [{ type: 'text', text: await fn() }] };
|
|
173
|
+
} catch (err) {
|
|
174
|
+
if (err.status === 401) {
|
|
175
|
+
return {
|
|
176
|
+
content: [{ type: 'text', text: `Not authenticated: Konductro rejected the CLI token. It may be expired or revoked — create a new one in Konductro under your profile, then re-run \`konductro-cursor-setup --url <URL> --token <TOKEN>\`. This is a setup problem, not a permissions one.` }],
|
|
177
|
+
isError: true,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const refusal = refusalText(err);
|
|
181
|
+
if (refusal) return { content: [{ type: 'text', text: refusal }] };
|
|
182
|
+
|
|
183
|
+
// Setup errors already read as full sentences; only wrap the ones that do not.
|
|
184
|
+
const text = err.setup
|
|
185
|
+
? err.message
|
|
186
|
+
: `Failed: ${err.code === 'INVALID_BODY' ? validationText(err) : err.message}`;
|
|
187
|
+
return { content: [{ type: 'text', text }], isError: true };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Resolve the project from the repo's git remote, so no project id is ever asked for. */
|
|
192
|
+
async function projectFromRepo(repoUrl) {
|
|
193
|
+
const repo = await konductroFetch(`/api/cli/repo-by-url?url=${encodeURIComponent(repoUrl)}`);
|
|
194
|
+
return repo;
|
|
195
|
+
}
|
|
196
|
+
|
|
62
197
|
const server = new McpServer({
|
|
63
198
|
name: 'konductro',
|
|
64
199
|
version: '1.0.0',
|
|
@@ -505,6 +640,12 @@ server.tool(
|
|
|
505
640
|
text += `### Context Pack\n\n${ctx.ticket.contextPack}\n\n`;
|
|
506
641
|
}
|
|
507
642
|
|
|
643
|
+
// Developer Notes — present when context is fetched on a story itself. For a
|
|
644
|
+
// task, the notes that matter are the parent story's, rendered below.
|
|
645
|
+
if (ctx.ticket.developerNotes) {
|
|
646
|
+
text += `### Developer Notes\n\n${ctx.ticket.developerNotes}\n\n`;
|
|
647
|
+
}
|
|
648
|
+
|
|
508
649
|
// Parent Story
|
|
509
650
|
if (ctx.parent) {
|
|
510
651
|
text += `### Parent Story: ${ctx.parent.ticketKey} — ${ctx.parent.title}\n\n`;
|
|
@@ -517,6 +658,10 @@ server.tool(
|
|
|
517
658
|
if (ctx.parent.contextPack) {
|
|
518
659
|
text += `**Story Context Pack:**\n${ctx.parent.contextPack}\n\n`;
|
|
519
660
|
}
|
|
661
|
+
// Story-level context accumulated by whoever worked the story's other tasks.
|
|
662
|
+
if (ctx.parent.developerNotes) {
|
|
663
|
+
text += `**Parent Story, Developer Notes:**\n${ctx.parent.developerNotes}\n\n`;
|
|
664
|
+
}
|
|
520
665
|
}
|
|
521
666
|
|
|
522
667
|
// Children tasks
|
|
@@ -562,6 +707,153 @@ server.tool(
|
|
|
562
707
|
}
|
|
563
708
|
);
|
|
564
709
|
|
|
710
|
+
// Tool: Append a developer note to a story (KON-314)
|
|
711
|
+
server.tool(
|
|
712
|
+
'append_story_developer_note',
|
|
713
|
+
"Append a note to a story's developer notes in Konductro, so context you worked out on one task is there for whoever picks up the next task on the same story. Notes live on the STORY, not the task: pass the parent story's key, which get_ticket_context prints in its Parent Story heading. Pass the current task's key as taskKey so the entry is attributable. Send only your new note — the endpoint appends it, and Konductro stamps the author, timestamp and task itself, so do not include a heading, a timestamp, a separator, or any notes you read earlier.",
|
|
714
|
+
{
|
|
715
|
+
storyId: z.string().describe('The story to append to — key (e.g. KON-283) or UUID. Not a task.'),
|
|
716
|
+
note: z.string().describe('The new note only, as markdown. No heading, timestamp or separator.'),
|
|
717
|
+
taskKey: z.string().optional().describe("The key of the task this note came from (e.g. KON-314), when there is one"),
|
|
718
|
+
},
|
|
719
|
+
async ({ storyId, note, taskKey }) => {
|
|
720
|
+
const result = await konductroFetch(`/api/cli/tickets/${storyId}/developer-notes`, {
|
|
721
|
+
method: 'POST',
|
|
722
|
+
body: JSON.stringify({ note, taskKey }),
|
|
723
|
+
});
|
|
724
|
+
|
|
725
|
+
// Not echoing result.developerNotes: it is the whole accumulated blob, and
|
|
726
|
+
// repeating it here invites a later call to send it back as a "new" note.
|
|
727
|
+
return {
|
|
728
|
+
content: [{
|
|
729
|
+
type: 'text',
|
|
730
|
+
text: `Note appended to ${result.ticketKey}'s developer notes.`,
|
|
731
|
+
}],
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
);
|
|
735
|
+
|
|
736
|
+
// Tool: Create a work item
|
|
737
|
+
server.tool(
|
|
738
|
+
'create_work_item',
|
|
739
|
+
"Create a story, task or bug in the Konductro project this repository belongs to. Anything created this way lands in DRAFT and still needs an SDM's approval before it can be worked — say so when you report back, so nobody thinks it is ready to start. A task needs a parent story, and is created in the repository repoUrl resolves to; a bug needs no parent and is filed standalone. Creating STORIES is governed by the project's story access setting and may be refused; filing bugs and creating tasks are not affected by it. Pass the repository's git remote (git remote get-url origin) — the project is resolved from it, never asked for.",
|
|
740
|
+
{
|
|
741
|
+
repoUrl: z.string().describe('The git remote URL of this repository (run: git remote get-url origin)'),
|
|
742
|
+
kind: z.enum(['story', 'task', 'bug']).describe('What to create'),
|
|
743
|
+
title: z.string().describe('A short title, as a person would write it'),
|
|
744
|
+
description: z.string().describe('What this is and why, in markdown'),
|
|
745
|
+
acceptanceCriteria: z.array(z.string()).optional().describe('Observable behaviour, one per item. Omit for a bug unless you have them.'),
|
|
746
|
+
parentKey: z.string().optional().describe('For a TASK, the parent story key (e.g. KON-451). ONLY a task may have a parent. A story or a bug sent with a parentKey is REFUSED and nothing is created, rather than being filed top-level as though it had worked.'),
|
|
747
|
+
repositoryId: z.string().optional().describe('For a TASK, the repository UUID it will be built in. Leave this out — it defaults to the repository repoUrl resolves to, which is the one you are standing in. Only set it for a task that will be built in a DIFFERENT repository on the same project, and then you need that repo\'s UUID from Konductro.'),
|
|
748
|
+
},
|
|
749
|
+
async ({ repoUrl, kind, title, description, acceptanceCriteria, parentKey, repositoryId }) => workItemCall(async () => {
|
|
750
|
+
// The backend's body schema DECLARES parentKey, so .strict() does not reject it — it
|
|
751
|
+
// is accepted and then dropped for anything that is not a task, because the route
|
|
752
|
+
// reads it only inside the task branch and calls createBug / createStory without it
|
|
753
|
+
// (routes/cli.ts). The item lands top-level and the 201 reports success, so asking
|
|
754
|
+
// for it under a story and being told it worked is exactly what happens. Refuse
|
|
755
|
+
// instead: a refusal is recoverable in the next turn, a misfiled item is found later
|
|
756
|
+
// by someone else, if at all.
|
|
757
|
+
//
|
|
758
|
+
// The two cases are dropped by the same code path but for different reasons, so the
|
|
759
|
+
// remedy differs and the message branches. A bug COULD have a parent — QA files bugs
|
|
760
|
+
// against the tested story that way — this endpoint just does not wire it through. A
|
|
761
|
+
// story could not: the hierarchy is story → task, so nothing sits above a story ever,
|
|
762
|
+
// and an agent sending one almost certainly meant to create a task.
|
|
763
|
+
if (kind !== 'task' && parentKey) {
|
|
764
|
+
const why = kind === 'bug'
|
|
765
|
+
? `Konductro only parents a bug to a story when QA files it against a failed test criterion; a bug created from the CLI is always standalone in the project's Bugs phase. Re-run without parentKey, and name ${parentKey} in the description so the link to it is not lost.`
|
|
766
|
+
: `A story is top-level by definition — the hierarchy is story → task, so nothing sits above a story. If you meant to add work under ${parentKey}, re-run with kind "task". If you meant a new story, re-run without parentKey.`;
|
|
767
|
+
return `Refused: only a task can be created under a parent, and NOTHING WAS CREATED. ${why}`;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const repo = await projectFromRepo(repoUrl);
|
|
771
|
+
|
|
772
|
+
// Creating a task was a dead end without this. The backend requires repositoryId as a
|
|
773
|
+
// UUID, and nothing a developer can reach hands one out — get_decomposition_context
|
|
774
|
+
// is the only tool that returns one, and that needs an assigned decomposition task
|
|
775
|
+
// you do not have. So the agent was asked for a value it could not obtain, and a
|
|
776
|
+
// guess came back as a bare "Validation failed".
|
|
777
|
+
//
|
|
778
|
+
// It was in hand the whole time: repo-by-url returns the repository row (id, name,
|
|
779
|
+
// repoUrl, repoType, stacks, projectId, project) and the id was being discarded.
|
|
780
|
+
// Defaulting to it is also the right answer rather than merely an available one — the
|
|
781
|
+
// task is being written from inside the repo it will be built in.
|
|
782
|
+
//
|
|
783
|
+
// Tasks only. createStory ignores it, and defaulting it on a bug would silently start
|
|
784
|
+
// attributing bugs to a repository they were not attributed to before.
|
|
785
|
+
const resolvedRepositoryId = kind === 'task' ? (repositoryId ?? repo.id) : repositoryId;
|
|
786
|
+
|
|
787
|
+
const created = await konductroFetch(`/api/cli/projects/${repo.projectId}/work-items`, {
|
|
788
|
+
method: 'POST',
|
|
789
|
+
body: JSON.stringify({ kind, title, description, acceptanceCriteria, parentKey, repositoryId: resolvedRepositoryId }),
|
|
790
|
+
});
|
|
791
|
+
// Returning the id rather than the number alone. A key is PREFIX-NUMBER, the prefix is
|
|
792
|
+
// nowhere in this tool's reach (repo-by-url does not return ticketPrefix), so printing
|
|
793
|
+
// the number and pointing at "its key" invited the agent to guess one. resolveTicketId
|
|
794
|
+
// matches prefix+number across the whole TENANT, not within the project, so a guessed
|
|
795
|
+
// prefix does not 404 — it resolves to another project's ticket of the same number,
|
|
796
|
+
// and the next update_work_item edits that one instead. The id closes it off: the UUID
|
|
797
|
+
// branch of resolveTicketId short-circuits with no lookup at all.
|
|
798
|
+
return `Created #${created.ticketNumber} — "${created.title}" (${created.kind}) in ${repo.project?.name ?? 'the project'}.\n\nid: ${created.id}\n\nIt is in ${created.status.toUpperCase()} and needs an SDM to approve it before it can be worked on. Use THAT id with get_ticket_context, update_work_item or delete_work_item. Do not build a key from #${created.ticketNumber} — the project's ticket prefix is not returned here, and a guessed prefix silently resolves to a different project's item of the same number rather than failing.`;
|
|
799
|
+
})
|
|
800
|
+
);
|
|
801
|
+
|
|
802
|
+
// Tool: Update a work item
|
|
803
|
+
server.tool(
|
|
804
|
+
'update_work_item',
|
|
805
|
+
"Change the title, description or acceptance criteria of a work item you own in Konductro — one assigned to you, that you are the developer on, or that you created. THESE THREE FIELDS ARE ALL YOU CAN CHANGE: status, sprint, assignee and everything else are deliberately not available here and must be changed in Konductro. Editing a STORY is governed by the project's story access setting and may be refused, or may be applied and then held for an SDM to review; editing a task is not affected by it. Send only the fields you are actually changing.",
|
|
806
|
+
{
|
|
807
|
+
key: z.string().describe('The work item key (e.g. KON-451) or UUID'),
|
|
808
|
+
title: z.string().optional().describe('The new title'),
|
|
809
|
+
description: z.string().optional().describe('The new description, in markdown'),
|
|
810
|
+
acceptanceCriteria: z.array(z.string()).optional().describe('The FULL new list, not just the additions — it replaces what is there'),
|
|
811
|
+
},
|
|
812
|
+
async ({ key, title, description, acceptanceCriteria }) => workItemCall(async () => {
|
|
813
|
+
const body = {};
|
|
814
|
+
if (title !== undefined) body.title = title;
|
|
815
|
+
if (description !== undefined) body.description = description;
|
|
816
|
+
if (acceptanceCriteria !== undefined) body.acceptanceCriteria = acceptanceCriteria;
|
|
817
|
+
if (Object.keys(body).length === 0) {
|
|
818
|
+
return 'Nothing to change — pass at least one of title, description or acceptanceCriteria.';
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
const result = await konductroFetch(`/api/cli/tickets/${encodeURIComponent(key)}/work-item`, {
|
|
822
|
+
method: 'PATCH',
|
|
823
|
+
body: JSON.stringify(body),
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
// Deliberately NOT echoing the updated values back. Returning the item invites the
|
|
827
|
+
// next call to send them again as "new" values, re-submitting fields nobody changed
|
|
828
|
+
// and raising a review for a no-op. Same reason append_story_developer_note does not
|
|
829
|
+
// return the notes blob.
|
|
830
|
+
// `changed` echoes the fields that were WRITTEN, not the ones that turned out to
|
|
831
|
+
// differ — the server returns Object.keys of what it applied (routes/cli.ts). So
|
|
832
|
+
// re-sending a title with its existing value still reports "changed: title". Do not
|
|
833
|
+
// read it as a diff.
|
|
834
|
+
const changed = (result.changed ?? Object.keys(body)).join(', ');
|
|
835
|
+
let text = `Updated ${key} (#${result.ticketNumber}) — changed: ${changed}.`;
|
|
836
|
+
if (result.awaitingReview) {
|
|
837
|
+
text += '\n\nThis change is APPLIED but now waiting for an SDM to approve or reject it, because this project reviews story changes. Until it is resolved the story will not move to Ready for QA, even if every task is done. If it is rejected the previous values come back and you will be notified.';
|
|
838
|
+
}
|
|
839
|
+
return text;
|
|
840
|
+
})
|
|
841
|
+
);
|
|
842
|
+
|
|
843
|
+
// Tool: Delete a work item
|
|
844
|
+
server.tool(
|
|
845
|
+
'delete_work_item',
|
|
846
|
+
"Delete a task or a bug from Konductro that has not been started. Bugs count: Konductro stores a bug as a task, so a developer's own unstarted bug can be deleted here. Stories cannot — deleting one takes its tasks with it and there is no restore, so archive a story in Konductro instead. Neither can a bug QA filed against a failed test criterion, which is part of that test record rather than yours. Nothing that has started can be deleted by anyone: that means anything carrying a branch, or anything past sprint planning, since only draft, approved and in_sprint items still qualify. Close those out in Konductro instead. Beyond that you may delete an item you are assigned to, are the developer on, or created; an SDM, architect or UX lead on the project may delete any item that qualifies. This is permanent and there is no undo, so be sure the developer asked for it.",
|
|
847
|
+
{
|
|
848
|
+
key: z.string().describe('The task or bug key (e.g. KON-452) or UUID'),
|
|
849
|
+
},
|
|
850
|
+
async ({ key }) => workItemCall(async () => {
|
|
851
|
+
const result = await konductroFetch(`/api/cli/tickets/${encodeURIComponent(key)}/work-item`, { method: 'DELETE' });
|
|
852
|
+
const extra = result.deleted > 1 ? ` (${result.deleted} rows, including its linked records)` : '';
|
|
853
|
+
return `Deleted ${key}${extra}. This cannot be undone.`;
|
|
854
|
+
})
|
|
855
|
+
);
|
|
856
|
+
|
|
565
857
|
// Tool: Start work on a ticket
|
|
566
858
|
server.tool(
|
|
567
859
|
'start_work',
|
|
@@ -958,7 +1250,13 @@ server.tool(
|
|
|
958
1250
|
|
|
959
1251
|
return { content: [{ type: 'text', text }] };
|
|
960
1252
|
} catch (err) {
|
|
961
|
-
|
|
1253
|
+
// KON-520: this used to sniff err.message for 'BUG_NOT_FOUND' / '404', which worked
|
|
1254
|
+
// only because the message was the whole raw envelope. konductroFetch now sets
|
|
1255
|
+
// message to the backend's `error` sentence, so that match silently stopped firing
|
|
1256
|
+
// and a missing bug reported as a generic failure. Read the code and the status
|
|
1257
|
+
// instead — both are on the error and neither depends on wording.
|
|
1258
|
+
const notABug = err.code === 'BUG_NOT_FOUND' || err.status === 404;
|
|
1259
|
+
const msg = notABug
|
|
962
1260
|
? `Ticket ${ticketId} not found or is not a bug.`
|
|
963
1261
|
: `Failed to load bug context: ${err.message}`;
|
|
964
1262
|
return { content: [{ type: 'text', text: msg }], isError: true };
|
|
@@ -994,9 +1292,11 @@ server.tool(
|
|
|
994
1292
|
: 'No new enrichment applied (fields may already exist on the ticket).';
|
|
995
1293
|
return { content: [{ type: 'text', text: applied }] };
|
|
996
1294
|
} catch (err) {
|
|
997
|
-
|
|
1295
|
+
// Same fix as get_bug_for_enrichment above — match on err.code / err.status, not
|
|
1296
|
+
// on message text, which konductroFetch no longer formats the way this expected.
|
|
1297
|
+
const msg = (err.code === 'BUG_NOT_FOUND' || err.status === 404)
|
|
998
1298
|
? `Ticket ${ticketId} not found or is not a bug.`
|
|
999
|
-
: err.
|
|
1299
|
+
: err.code === 'INVALID_ENRICHMENT'
|
|
1000
1300
|
? 'At least one enrichment field must be provided.'
|
|
1001
1301
|
: `Failed to submit enrichment: ${err.message}`;
|
|
1002
1302
|
return { content: [{ type: 'text', text: msg }], isError: true };
|