ticketlens 0.22.1 → 0.24.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 +29 -4
- package/bin/ticketlens.mjs +35 -0
- package/package.json +1 -1
- package/scripts/postinstall.mjs +1 -0
- package/skills/jtb/SKILL.md +24 -1
- package/skills/jtb/scripts/lib/adapters/github-adapter.mjs +79 -0
- package/skills/jtb/scripts/lib/adapters/jira-adapter.mjs +33 -5
- package/skills/jtb/scripts/lib/adapters/linear-adapter.mjs +101 -0
- package/skills/jtb/scripts/lib/adf-converter.mjs +19 -0
- package/skills/jtb/scripts/lib/cli.mjs +8 -0
- package/skills/jtb/scripts/lib/help.mjs +67 -5
- package/skills/jtb/scripts/lib/jira-client.mjs +87 -1
- package/skills/jtb/scripts/lib/mcp-install.mjs +92 -0
- package/skills/jtb/scripts/lib/mcp-server.mjs +86 -9
- package/skills/jtb/scripts/lib/resolve-adapter.mjs +1 -1
- package/skills/jtb/scripts/lib/ticket-action-cooldown.mjs +72 -0
- package/skills/jtb/scripts/lib/ticket-action-log.mjs +72 -0
- package/skills/jtb/scripts/lib/ticket-command.mjs +236 -0
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
> Your AI assistant shouldn't need to read your tickets.
|
|
16
16
|
|
|
17
|
-
>
|
|
17
|
+
> Reads your tickets, tells you which ones need you right now — and now writes back too: post comments and transition status directly from your terminal or AI session.
|
|
18
18
|
|
|
19
19
|
<div align="center"><img src="docs/demos/fetch.gif" alt="ticketlens CNV1-2 demo" width="700" /></div>
|
|
20
20
|
|
|
@@ -411,7 +411,7 @@ Every note is scanned before saving — anything shaped like a real secret (API
|
|
|
411
411
|
|
|
412
412
|
**Removing a note:** `ticketlens note delete --id="..." [--ticket=KEY]` removes a note from your local vault. Local only — if it was already pushed to a team, teammates who pulled it keep their copy; deleting it there too is a manager action from the Console (Admin > Recall).
|
|
413
413
|
|
|
414
|
-
**Any MCP-capable AI harness:** `ticketlens mcp` starts a stdio [MCP](https://modelcontextprotocol.io) server exposing `recall_add` and `
|
|
414
|
+
**Any MCP-capable AI harness:** `ticketlens mcp` starts a stdio [MCP](https://modelcontextprotocol.io) server exposing `recall_add`, `recall_search`, `ticket_comment`, and `ticket_transition` as native tools — any MCP-compatible AI assistant, not just Claude Code, can call them directly instead of constructing a shell command. It's a thin adapter over the exact same code as the CLI commands above — same Pro gate, same secret scan/local vault/tracker writes, same team sync — nothing is reimplemented. Point your harness's MCP config at it: `{ "command": "ticketlens", "args": ["mcp"] }` — or run `ticketlens mcp install` in a project to write that entry into its `.mcp.json` for you (creates the file if it doesn't exist, merges in if it does — never touches any other entry already there; `--dry-run` to preview first).
|
|
415
415
|
|
|
416
416
|
`note add`'s save confirmation and `recall`'s search results are styled by default in a terminal; add `--plain` to either for bare, pipe-safe output. `recall` always shows each note's file ID (e.g. `[1784135399545-fe01c4.md]`) so you can open it directly (`cat ~/.ticketlens/recall/<PREFIX>/<id>`), or pass `--full` to print the full body content inline instead.
|
|
417
417
|
|
|
@@ -419,6 +419,22 @@ Every note is scanned before saving — anything shaped like a real secret (API
|
|
|
419
419
|
|
|
420
420
|
---
|
|
421
421
|
|
|
422
|
+
### Comment & Transition
|
|
423
|
+
|
|
424
|
+
```bash
|
|
425
|
+
ticketlens comment PROJ-123 --body="Looks good, merging." # Post a comment to the tracker
|
|
426
|
+
ticketlens transition PROJ-123 # List valid transitions (read-only)
|
|
427
|
+
ticketlens transition PROJ-123 --target="Done" --confirm # Execute the transition
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Write directly to the ticket in its real tracker — Jira, GitHub, or Linear — from your terminal or an AI session via `ticket_comment`/`ticket_transition` MCP tools. Requires a Pro license.
|
|
431
|
+
|
|
432
|
+
`ticketlens transition` with just a ticket key lists the tracker's current valid options without changing anything (Jira: real workflow transitions for that issue; GitHub: open/closed; Linear: team-scoped workflow states). Add both `--target` and `--confirm` to execute — `--confirm` is a deliberate two-step gate: a behavioral nudge and forensic trail, not a hard security guarantee. Every write, once resolved, is re-validated against the tracker's current state immediately before executing — never a blind write against a stale option.
|
|
433
|
+
|
|
434
|
+
Both actions have a short local debounce (10s) against an accidental double-fire (a flaky retry, hitting enter twice), and every successful write is appended to a local, append-only audit log (`~/.ticketlens/ticket-action-log.jsonl`). A write that times out is never retried automatically — unlike Recall notes, ticket comments/transitions aren't naturally idempotent, so a timed-out attempt is surfaced to you instead of silently repeated.
|
|
435
|
+
|
|
436
|
+
---
|
|
437
|
+
|
|
422
438
|
### Response-Time Stats
|
|
423
439
|
|
|
424
440
|
```bash
|
|
@@ -692,7 +708,14 @@ ticketlens recall CNV1-2 # Search saved notes by ticket key
|
|
|
692
708
|
ticketlens recall "retry backoff" # Free-text search across all notes [Pro]
|
|
693
709
|
ticketlens recall sync # Retry any notes stuck in the local queue [Team+]
|
|
694
710
|
ticketlens recall settings # Show effective retry-queue settings, fetched live [Team+]
|
|
695
|
-
ticketlens mcp # Start the MCP stdio server (
|
|
711
|
+
ticketlens mcp # Start the MCP stdio server (recall/ticket write tools) [Pro]
|
|
712
|
+
ticketlens mcp install # Register it into the current project's .mcp.json
|
|
713
|
+
ticketlens mcp install --dry-run # Preview the registration without writing
|
|
714
|
+
|
|
715
|
+
# ── Comment & Transition ─────────────────────────────────────────────────────
|
|
716
|
+
ticketlens comment CNV1-2 --body="Looks good, merging." # Post a comment to the tracker [Pro]
|
|
717
|
+
ticketlens transition CNV1-2 # List valid transitions (read-only) [Pro]
|
|
718
|
+
ticketlens transition CNV1-2 --target="Done" --confirm # Execute the transition [Pro]
|
|
696
719
|
|
|
697
720
|
# ── Stats ──────────────────────────────────────────────────────────────────────
|
|
698
721
|
ticketlens stats # Response-time metrics from local history
|
|
@@ -774,7 +797,9 @@ ticketlens note delete --id="..." # Remove a note from your local vault
|
|
|
774
797
|
ticketlens recall <query|TICKET-KEY> # Search your saved Recall notes
|
|
775
798
|
ticketlens recall sync # Retry any notes stuck in the local queue
|
|
776
799
|
ticketlens recall settings # Show effective retry-queue settings, fetched live
|
|
777
|
-
ticketlens mcp # Start the MCP stdio server (
|
|
800
|
+
ticketlens mcp # Start the MCP stdio server (recall/ticket write tools)
|
|
801
|
+
ticketlens comment CNV1-2 --body="..." # Post a comment to the tracker
|
|
802
|
+
ticketlens transition CNV1-2 --target="Done" --confirm # Transition ticket status
|
|
778
803
|
ticketlens activate YOUR-LICENSE-KEY # Activate Pro license
|
|
779
804
|
```
|
|
780
805
|
|
package/bin/ticketlens.mjs
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
printCollisionsHelp, printStatsHelp,
|
|
29
29
|
printCloudKeysHelp,
|
|
30
30
|
printNoteHelp, printRecallHelp, printMcpHelp,
|
|
31
|
+
printCommentHelp, printTransitionHelp,
|
|
31
32
|
} from '../skills/jtb/scripts/lib/help.mjs';
|
|
32
33
|
import { runStats } from '../skills/jtb/scripts/lib/run-stats.mjs';
|
|
33
34
|
import { createStyler } from '../skills/jtb/scripts/lib/ansi.mjs';
|
|
@@ -724,6 +725,12 @@ switch (command) {
|
|
|
724
725
|
|
|
725
726
|
case 'mcp': {
|
|
726
727
|
if (cmdArgs.includes('--help') || cmdArgs.includes('-h')) { printMcpHelp(); break; }
|
|
728
|
+
if (cmdArgs[0] === 'install') {
|
|
729
|
+
const { mcpInstall } = await import('../skills/jtb/scripts/lib/mcp-install.mjs');
|
|
730
|
+
const { written, dryRun, reason } = mcpInstall({ dryRun: cmdArgs.includes('--dry-run') });
|
|
731
|
+
if (!dryRun && !written && reason) process.exitCode = 1;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
727
734
|
// Long-lived stdio server, not a one-shot command — no .then()-exit-code
|
|
728
735
|
// pattern; it exits when the client closes stdin (spec's stdio lifecycle).
|
|
729
736
|
const { runMcpServer } = await import('../skills/jtb/scripts/lib/mcp-server.mjs');
|
|
@@ -731,6 +738,34 @@ switch (command) {
|
|
|
731
738
|
break;
|
|
732
739
|
}
|
|
733
740
|
|
|
741
|
+
case 'comment': {
|
|
742
|
+
if (cmdArgs.includes('--help') || cmdArgs.includes('-h')) { printCommentHelp(); break; }
|
|
743
|
+
const { runTicketComment } = await import('../skills/jtb/scripts/lib/ticket-command.mjs');
|
|
744
|
+
runTicketComment(cmdArgs).then(({ ok }) => {
|
|
745
|
+
if (!ok) process.exitCode = 1;
|
|
746
|
+
}).catch(err => {
|
|
747
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
748
|
+
process.exitCode = 1;
|
|
749
|
+
});
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
case 'transition': {
|
|
754
|
+
if (cmdArgs.includes('--help') || cmdArgs.includes('-h')) { printTransitionHelp(); break; }
|
|
755
|
+
const { runTicketTransitionList, runTicketTransition } = await import('../skills/jtb/scripts/lib/ticket-command.mjs');
|
|
756
|
+
// No --target → discovery only, never mutates. --target present → execute
|
|
757
|
+
// (runTicketTransition itself still refuses without --confirm).
|
|
758
|
+
const hasTarget = cmdArgs.some(a => a.startsWith('--target='));
|
|
759
|
+
const runFn = hasTarget ? runTicketTransition : runTicketTransitionList;
|
|
760
|
+
runFn(cmdArgs).then(({ ok }) => {
|
|
761
|
+
if (!ok) process.exitCode = 1;
|
|
762
|
+
}).catch(err => {
|
|
763
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
764
|
+
process.exitCode = 1;
|
|
765
|
+
});
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
768
|
+
|
|
734
769
|
case 'help':
|
|
735
770
|
default: {
|
|
736
771
|
const isInteractive = args.length === 0 && process.stdin.isTTY && process.stdout.isTTY && !process.env.CI;
|
package/package.json
CHANGED
package/scripts/postinstall.mjs
CHANGED
|
@@ -102,6 +102,7 @@ try {
|
|
|
102
102
|
} else {
|
|
103
103
|
console.log(' → New here? Run tl to launch the guided setup.');
|
|
104
104
|
}
|
|
105
|
+
console.log(' → Using an MCP-capable AI harness? Run tl mcp install in a project to register Recall as native tools.');
|
|
105
106
|
console.log('');
|
|
106
107
|
} catch {
|
|
107
108
|
// Silent on failure — never breaks the install.
|
package/skills/jtb/SKILL.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- jtb-skill-version: 0.
|
|
1
|
+
<!-- jtb-skill-version: 0.24.0 -->
|
|
2
2
|
---
|
|
3
3
|
name: jtb
|
|
4
4
|
description: Fetch a Jira ticket's full context (description, comments, linked issues, code references) and assemble a structured TicketBrief for implementation planning. Use when user types /jtb, mentions a Jira ticket key, or wants to plan work from a Jira ticket.
|
|
@@ -60,6 +60,9 @@ Fetches a Jira ticket and produces a structured brief with code references, then
|
|
|
60
60
|
/jtb recall PROD-1234 # search saved Recall notes (Pro)
|
|
61
61
|
/jtb recall sync # retry any notes stuck in the local queue (Team+)
|
|
62
62
|
/jtb recall settings # show effective retry-queue settings, fetched live (Team+)
|
|
63
|
+
/jtb comment PROD-1234 --body="..." # post a comment to the tracker (Pro)
|
|
64
|
+
/jtb transition PROD-1234 # list the tracker's current valid transitions (Pro)
|
|
65
|
+
/jtb transition PROD-1234 --target="Done" --confirm # execute the transition (Pro)
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
## Prerequisites
|
|
@@ -260,6 +263,26 @@ Recall notes are stored locally at `~/.ticketlens/recall/`. On a Pro account wit
|
|
|
260
263
|
|
|
261
264
|
---
|
|
262
265
|
|
|
266
|
+
## Comment & Transition — write back to the tracker (Pro)
|
|
267
|
+
|
|
268
|
+
Unlike Recall (a local note about a ticket), these write directly to the ticket's real tracker — Jira, GitHub, or Linear. Only dispatch when the user has actually asked for the ticket to be commented on or moved — never as a routine end-of-session action the way Recall capture is.
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
ticketlens comment PROD-1234 --body="Fixed in a2f9c1, deployed to staging."
|
|
272
|
+
ticketlens transition PROD-1234 # list valid transitions — read-only
|
|
273
|
+
ticketlens transition PROD-1234 --target="Done" --confirm # execute
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
`transition` called with just a ticket key never mutates anything — it lists the tracker's current valid options (Jira: real workflow transitions for that issue; GitHub: open/closed; Linear: team-scoped workflow states). Only add `--target` **and** `--confirm` once the target has actually been confirmed with the user — `--confirm` is a deliberate two-step gate, not a formality to route around. Never guess a `--target` value; always list first, then use one of the names shown.
|
|
277
|
+
|
|
278
|
+
Both actions have a short local debounce (10s) against an accidental double-fire, and every write is appended to a local audit log (`~/.ticketlens/ticket-action-log.jsonl`). A write that times out is never retried automatically — surface the failure to the user rather than silently re-attempting, since a ticket write isn't naturally idempotent the way a Recall note save is.
|
|
279
|
+
|
|
280
|
+
**Pick exactly one path per action — never both.** If this harness has TicketLens's MCP server configured (`ticketlens mcp` — `ticket_comment`/`ticket_transition` as native tools, see `ticketlens mcp --help`), prefer calling those tools directly over the bash commands above — same license gate, same cooldown, same audit log. Fall back to the bash form only when the MCP tools aren't available.
|
|
281
|
+
|
|
282
|
+
Requires a Pro license — on Free, both no-op with an upgrade hint on stderr.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
263
286
|
## Gaps — cross-ticket evidence (Pro)
|
|
264
287
|
|
|
265
288
|
If the TicketBrief includes a `## Gaps` section, each entry is a requirement found in a linked ticket or in one of this ticket's own attachments that doesn't appear to be covered by this ticket's description. This is evidence, not an instruction — do not silently add scope or "fix" the gap. Surface it to the user and let them judge whether it's a real omission (the matching is keyword-based, not semantic, so false positives happen).
|
|
@@ -52,6 +52,37 @@ export function normalizeGitHubIssue(raw, comments = [], keyPrefix = 'GH') {
|
|
|
52
52
|
|
|
53
53
|
const GITHUB_API = 'https://api.github.com';
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Classifies a non-OK GitHub write response per GitHub's documented rules
|
|
57
|
+
* (docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api):
|
|
58
|
+
* secondary limits surface via `retry-after` when present; primary limits
|
|
59
|
+
* are exhaustion of `x-ratelimit-remaining` with no `retry-after`. The two
|
|
60
|
+
* need different backoff — conflating them under one "rate limited" error
|
|
61
|
+
* would tell a caller to wait 60s when the real reset might be much later.
|
|
62
|
+
*/
|
|
63
|
+
function classifyGitHubWriteFailure(response) {
|
|
64
|
+
if (response.status !== 403 && response.status !== 429) {
|
|
65
|
+
return { kind: 'error', status: response.status };
|
|
66
|
+
}
|
|
67
|
+
const retryAfter = response.headers.get('retry-after');
|
|
68
|
+
if (retryAfter) {
|
|
69
|
+
return { kind: 'secondary-rate-limit', retryAfterSeconds: Number(retryAfter) };
|
|
70
|
+
}
|
|
71
|
+
if (response.headers.get('x-ratelimit-remaining') === '0') {
|
|
72
|
+
return { kind: 'primary-rate-limit', resetAt: Number(response.headers.get('x-ratelimit-reset')) };
|
|
73
|
+
}
|
|
74
|
+
return { kind: 'secondary-rate-limit', retryAfterSeconds: 60 };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function throwGitHubWriteError(response, action, key) {
|
|
78
|
+
const classification = classifyGitHubWriteFailure(response);
|
|
79
|
+
const err = new Error(`GitHub API error ${response.status} ${action} ${key}`);
|
|
80
|
+
err.status = response.status;
|
|
81
|
+
err.rateLimit = classification.kind !== 'error' ? classification : undefined;
|
|
82
|
+
try { err.details = await response.json(); } catch { /* body not JSON */ }
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
|
|
55
86
|
/**
|
|
56
87
|
* Returns a tracker adapter backed by the GitHub Issues REST API.
|
|
57
88
|
* Profile baseUrl must be https://github.com/OWNER/REPO.
|
|
@@ -108,5 +139,53 @@ export function createGitHubAdapter(conn, { fetcher = globalThis.fetch } = {}) {
|
|
|
108
139
|
async fetchStatuses() {
|
|
109
140
|
return ['open', 'closed'];
|
|
110
141
|
},
|
|
142
|
+
|
|
143
|
+
async addComment(key, body, opts = {}) {
|
|
144
|
+
const number = parseInt(key.split('-').pop(), 10);
|
|
145
|
+
const res = await fetcher(`${GITHUB_API}/repos/${owner}/${repo}/issues/${number}/comments`, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: { ...headers, 'Content-Type': 'application/json' },
|
|
148
|
+
body: JSON.stringify({ body }),
|
|
149
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 10_000),
|
|
150
|
+
});
|
|
151
|
+
if (!res.ok) await throwGitHubWriteError(res, 'commenting on', key);
|
|
152
|
+
const raw = await res.json();
|
|
153
|
+
return { id: String(raw.id), url: raw.html_url ?? null };
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* GitHub issues have exactly one valid opposite state — not a
|
|
158
|
+
* discoverable workflow like Jira. Reports it in the same
|
|
159
|
+
* {id, name, to} shape as Jira's getTransitions for a uniform
|
|
160
|
+
* cross-tracker adapter contract.
|
|
161
|
+
*/
|
|
162
|
+
async getTransitions(key, opts = {}) {
|
|
163
|
+
const ticket = await this.fetchTicket(key, opts);
|
|
164
|
+
return ticket.status === 'open'
|
|
165
|
+
? [{ id: 'closed', name: 'Close issue', to: 'closed' }]
|
|
166
|
+
: [{ id: 'open', name: 'Reopen issue', to: 'open' }];
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
async transition(key, target, opts = {}) {
|
|
170
|
+
const ticket = await this.fetchTicket(key, opts);
|
|
171
|
+
const t = String(target).toLowerCase();
|
|
172
|
+
if (t === ticket.status) {
|
|
173
|
+
return { executed: false, reason: 'already-in-target-state', options: await this.getTransitions(key, opts) };
|
|
174
|
+
}
|
|
175
|
+
const options = await this.getTransitions(key, opts);
|
|
176
|
+
const match = options.find(o => o.id === t || o.name.toLowerCase() === t || o.to === t);
|
|
177
|
+
if (!match) {
|
|
178
|
+
return { executed: false, reason: 'not-found', options };
|
|
179
|
+
}
|
|
180
|
+
const number = parseInt(key.split('-').pop(), 10);
|
|
181
|
+
const res = await fetcher(`${GITHUB_API}/repos/${owner}/${repo}/issues/${number}`, {
|
|
182
|
+
method: 'PATCH',
|
|
183
|
+
headers: { ...headers, 'Content-Type': 'application/json' },
|
|
184
|
+
body: JSON.stringify({ state: match.to }),
|
|
185
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 10_000),
|
|
186
|
+
});
|
|
187
|
+
if (!res.ok) await throwGitHubWriteError(res, 'transitioning', key);
|
|
188
|
+
return { executed: true, to: match.to };
|
|
189
|
+
},
|
|
111
190
|
};
|
|
112
191
|
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { fetchTicket, fetchCurrentUser, searchTickets, fetchStatuses } from '../jira-client.mjs';
|
|
1
|
+
import { fetchTicket, fetchCurrentUser, searchTickets, fetchStatuses, postComment, getTransitions, postTransition } from '../jira-client.mjs';
|
|
2
2
|
import { buildJiraEnv } from '../config.mjs';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Finds the option in a fresh transitions list matching a caller-given
|
|
6
|
+
* target — by id (exact) or by name/to-name (case-insensitive). Never
|
|
7
|
+
* trusts a caller-supplied id without confirming it's still a real,
|
|
8
|
+
* currently-valid option for this exact issue right now.
|
|
9
|
+
*/
|
|
10
|
+
function resolveTransitionTarget(options, target) {
|
|
11
|
+
const t = String(target).toLowerCase();
|
|
12
|
+
return options.find(o => o.id === String(target) || o.name.toLowerCase() === t || (o.to ?? '').toLowerCase() === t);
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
/**
|
|
5
16
|
* Returns a tracker adapter backed by the Jira REST API.
|
|
6
17
|
* Binds connection credentials so callers never touch jira-client directly.
|
|
@@ -8,12 +19,29 @@ import { buildJiraEnv } from '../config.mjs';
|
|
|
8
19
|
export function createJiraAdapter(conn, { fetcher = globalThis.fetch } = {}) {
|
|
9
20
|
const env = buildJiraEnv(conn);
|
|
10
21
|
const apiVersion = conn.auth === 'cloud' ? 3 : 2;
|
|
22
|
+
const base = { env, fetcher, apiVersion, allowPrivateIp: conn.allowPrivateIp };
|
|
11
23
|
|
|
12
24
|
return {
|
|
13
25
|
type: 'jira',
|
|
14
|
-
fetchTicket: (key, opts = {}) => fetchTicket(key, {
|
|
15
|
-
fetchCurrentUser: (opts = {}) => fetchCurrentUser({
|
|
16
|
-
searchTickets: (query, opts = {}) => searchTickets(query, {
|
|
17
|
-
fetchStatuses: (opts = {}) => fetchStatuses({
|
|
26
|
+
fetchTicket: (key, opts = {}) => fetchTicket(key, { ...base, ...opts }),
|
|
27
|
+
fetchCurrentUser: (opts = {}) => fetchCurrentUser({ ...base, ...opts }),
|
|
28
|
+
searchTickets: (query, opts = {}) => searchTickets(query, { ...base, ...opts }),
|
|
29
|
+
fetchStatuses: (opts = {}) => fetchStatuses({ ...base, ...opts }),
|
|
30
|
+
addComment: (key, body, opts = {}) => postComment(key, body, { ...base, ...opts }),
|
|
31
|
+
getTransitions: (key, opts = {}) => getTransitions(key, { ...base, ...opts }),
|
|
32
|
+
/**
|
|
33
|
+
* Always re-fetches transitions fresh and resolves `target` against
|
|
34
|
+
* them before executing — a caller can never blind-POST a stale or
|
|
35
|
+
* guessed transition id, even if they try.
|
|
36
|
+
*/
|
|
37
|
+
async transition(key, target, opts = {}) {
|
|
38
|
+
const options = await getTransitions(key, { ...base, ...opts });
|
|
39
|
+
const match = resolveTransitionTarget(options, target);
|
|
40
|
+
if (!match) {
|
|
41
|
+
return { executed: false, reason: 'not-found', options };
|
|
42
|
+
}
|
|
43
|
+
await postTransition(key, match.id, { ...base, ...opts });
|
|
44
|
+
return { executed: true, to: match.to ?? match.name };
|
|
45
|
+
},
|
|
18
46
|
};
|
|
19
47
|
}
|
|
@@ -65,6 +65,39 @@ async function gql(query, variables, { token, fetcher, signal }) {
|
|
|
65
65
|
return data;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Resolves a human identifier (e.g. "ENG-123") to the issue's internal id
|
|
70
|
+
* plus its current state and team — mutations require the UUID id, never
|
|
71
|
+
* the identifier string (confirmed against Linear's own SDK docs).
|
|
72
|
+
*/
|
|
73
|
+
async function fetchIssueStateInfo(key, { token, fetcher, signal }) {
|
|
74
|
+
const data = await gql(
|
|
75
|
+
`query ($id: String!) {
|
|
76
|
+
issues(filter: { identifier: { eq: $id } }, first: 1) {
|
|
77
|
+
nodes { id state { id name } team { id } }
|
|
78
|
+
}
|
|
79
|
+
}`,
|
|
80
|
+
{ id: key },
|
|
81
|
+
{ token, fetcher, signal },
|
|
82
|
+
);
|
|
83
|
+
const node = data.issues?.nodes?.[0];
|
|
84
|
+
if (!node) throw new Error(`Linear issue not found: ${key}`);
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function fetchTeamWorkflowStates(teamId, { token, fetcher, signal }) {
|
|
89
|
+
const data = await gql(
|
|
90
|
+
`query ($teamId: ID!) {
|
|
91
|
+
workflowStates(filter: { team: { id: { eq: $teamId } } }, first: 50) {
|
|
92
|
+
nodes { id name }
|
|
93
|
+
}
|
|
94
|
+
}`,
|
|
95
|
+
{ teamId },
|
|
96
|
+
{ token, fetcher, signal },
|
|
97
|
+
);
|
|
98
|
+
return data.workflowStates?.nodes ?? [];
|
|
99
|
+
}
|
|
100
|
+
|
|
68
101
|
/**
|
|
69
102
|
* Returns a tracker adapter backed by the Linear GraphQL API.
|
|
70
103
|
* Profile baseUrl must contain linear.app. Auth token stored as apiToken in credentials.json.
|
|
@@ -130,5 +163,73 @@ export function createLinearAdapter(conn, { fetcher = globalThis.fetch } = {}) {
|
|
|
130
163
|
);
|
|
131
164
|
return (data.workflowStates?.nodes ?? []).map(s => s.name);
|
|
132
165
|
},
|
|
166
|
+
|
|
167
|
+
async addComment(key, body, opts = {}) {
|
|
168
|
+
const signal = AbortSignal.timeout(opts.timeoutMs ?? 10_000);
|
|
169
|
+
const { id: issueId } = await fetchIssueStateInfo(key, { token, fetcher, signal });
|
|
170
|
+
const data = await gql(
|
|
171
|
+
`mutation ($issueId: String!, $body: String!) {
|
|
172
|
+
commentCreate(input: { issueId: $issueId, body: $body }) {
|
|
173
|
+
success
|
|
174
|
+
comment { id url }
|
|
175
|
+
}
|
|
176
|
+
}`,
|
|
177
|
+
{ issueId, body },
|
|
178
|
+
{ token, fetcher, signal },
|
|
179
|
+
);
|
|
180
|
+
if (!data.commentCreate?.success) {
|
|
181
|
+
throw new Error(`Linear commentCreate reported success:false for ${key}`);
|
|
182
|
+
}
|
|
183
|
+
return { id: data.commentCreate.comment.id, url: data.commentCreate.comment.url ?? null };
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Scoped to the issue's own team — Linear's workflow states are
|
|
188
|
+
* per-team, so an unscoped list would offer states from teams this
|
|
189
|
+
* issue can never actually move into.
|
|
190
|
+
*/
|
|
191
|
+
async getTransitions(key, opts = {}) {
|
|
192
|
+
const signal = AbortSignal.timeout(opts.timeoutMs ?? 10_000);
|
|
193
|
+
const info = await fetchIssueStateInfo(key, { token, fetcher, signal });
|
|
194
|
+
const states = await fetchTeamWorkflowStates(info.team.id, { token, fetcher, signal });
|
|
195
|
+
return states
|
|
196
|
+
.filter(s => s.id !== info.state?.id)
|
|
197
|
+
.map(s => ({ id: s.id, name: s.name, to: s.name }));
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Always re-resolves the issue's current state and team-scoped
|
|
202
|
+
* options fresh before executing — a caller can never blind-mutate
|
|
203
|
+
* with a stale stateId. Explicitly checks `success` on the mutation
|
|
204
|
+
* payload: Linear can return HTTP 200 with no top-level GraphQL
|
|
205
|
+
* `errors` and still report success:false (e.g. permission denial),
|
|
206
|
+
* so absence of `errors` alone does not mean the mutation applied.
|
|
207
|
+
*/
|
|
208
|
+
async transition(key, target, opts = {}) {
|
|
209
|
+
const signal = AbortSignal.timeout(opts.timeoutMs ?? 10_000);
|
|
210
|
+
const info = await fetchIssueStateInfo(key, { token, fetcher, signal });
|
|
211
|
+
const states = await fetchTeamWorkflowStates(info.team.id, { token, fetcher, signal });
|
|
212
|
+
const t = String(target).toLowerCase();
|
|
213
|
+
const options = states
|
|
214
|
+
.filter(s => s.id !== info.state?.id)
|
|
215
|
+
.map(s => ({ id: s.id, name: s.name, to: s.name }));
|
|
216
|
+
const match = options.find(o => o.id === String(target) || o.name.toLowerCase() === t);
|
|
217
|
+
if (!match) {
|
|
218
|
+
return { executed: false, reason: 'not-found', options };
|
|
219
|
+
}
|
|
220
|
+
const data = await gql(
|
|
221
|
+
`mutation ($id: String!, $stateId: String!) {
|
|
222
|
+
issueUpdate(id: $id, input: { stateId: $stateId }) {
|
|
223
|
+
success
|
|
224
|
+
}
|
|
225
|
+
}`,
|
|
226
|
+
{ id: info.id, stateId: match.id },
|
|
227
|
+
{ token, fetcher, signal },
|
|
228
|
+
);
|
|
229
|
+
if (!data.issueUpdate?.success) {
|
|
230
|
+
return { executed: false, reason: 'mutation-rejected', options };
|
|
231
|
+
}
|
|
232
|
+
return { executed: true, to: match.to };
|
|
233
|
+
},
|
|
133
234
|
};
|
|
134
235
|
}
|
|
@@ -4,6 +4,25 @@
|
|
|
4
4
|
* comment bodies are ADF objects instead of plain text strings.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Converts plain text to a minimal ADF document — one paragraph node per
|
|
9
|
+
* blank-line-separated block, one text node per paragraph. Jira Cloud (API
|
|
10
|
+
* v3) rejects a plain string comment body outright; Server/DC (v2) accepts
|
|
11
|
+
* one directly. No rich-text/markdown conversion — deliberately minimal,
|
|
12
|
+
* matching the narrow-schema scope of ticket_comment (no formatting inputs
|
|
13
|
+
* accepted, so none need representing here).
|
|
14
|
+
*/
|
|
15
|
+
export function textToAdf(text) {
|
|
16
|
+
const paragraphs = (text || '').split('\n\n').filter(Boolean);
|
|
17
|
+
return {
|
|
18
|
+
version: 1,
|
|
19
|
+
type: 'doc',
|
|
20
|
+
content: paragraphs.length > 0
|
|
21
|
+
? paragraphs.map(p => ({ type: 'paragraph', content: [{ type: 'text', text: p }] }))
|
|
22
|
+
: [{ type: 'paragraph', content: [] }],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
7
26
|
export function adfToText(value) {
|
|
8
27
|
if (value == null) return '';
|
|
9
28
|
if (typeof value === 'string') return value;
|
|
@@ -130,6 +130,14 @@ export function parseCommand(args) {
|
|
|
130
130
|
return { command: 'mcp', args: args.slice(1) };
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
if (first === 'comment') {
|
|
134
|
+
return { command: 'comment', args: args.slice(1) };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (first === 'transition') {
|
|
138
|
+
return { command: 'transition', args: args.slice(1) };
|
|
139
|
+
}
|
|
140
|
+
|
|
133
141
|
// Anything that looks like a ticket key or any non-flag arg → fetch
|
|
134
142
|
return { command: 'fetch', args };
|
|
135
143
|
}
|
|
@@ -54,6 +54,8 @@ export function printHelp({ stream = process.stdout } = {}) {
|
|
|
54
54
|
` ${s.brand('ticketlens')} recall sync Retry any notes stuck in the local queue ${s.dim('[Team+]')}`,
|
|
55
55
|
` ${s.brand('ticketlens')} recall settings Show effective retry-queue settings, fetched live ${s.dim('[Team+]')}`,
|
|
56
56
|
` ${s.brand('ticketlens')} mcp Start the MCP stdio server for Recall ${s.dim('[Pro]')}`,
|
|
57
|
+
` ${s.brand('ticketlens')} comment ${s.dim('<TICKET-KEY> --body=...')} Post a comment to the tracker ${s.dim('[Pro]')}`,
|
|
58
|
+
` ${s.brand('ticketlens')} transition ${s.dim('<TICKET-KEY> [--target=... --confirm]')} Move ticket status ${s.dim('[Pro]')}`,
|
|
57
59
|
'',
|
|
58
60
|
` ${s.brand('ticketlens')} delete ${s.dim('<PROFILE-NAME>')} Remove a profile`,
|
|
59
61
|
` ${s.brand('ticketlens')} activate ${s.dim('<KEY>')} Activate a license key`,
|
|
@@ -592,16 +594,25 @@ export function printMcpHelp({ stream = process.stdout } = {}) {
|
|
|
592
594
|
'',
|
|
593
595
|
` ${s.bold(s.brand('ticketlens'))} ${s.bold('mcp')} ${s.dim('[Pro]')}`,
|
|
594
596
|
'',
|
|
595
|
-
` Start an MCP (Model Context Protocol) stdio server exposing Recall
|
|
596
|
-
` native tools — ${s.cyan('recall_add')}
|
|
597
|
-
` harness, not just Claude Code
|
|
598
|
-
` ${s.cyan('note add')}/${s.cyan('recall')}
|
|
599
|
-
`
|
|
597
|
+
` Start an MCP (Model Context Protocol) stdio server exposing Recall and`,
|
|
598
|
+
` ticket writes as native tools — ${s.cyan('recall_add')}, ${s.cyan('recall_search')}, ${s.cyan('ticket_comment')},`,
|
|
599
|
+
` ${s.cyan('ticket_transition')} — for any MCP-compatible AI harness, not just Claude Code.`,
|
|
600
|
+
` Thin adapter over the same code as ${s.cyan('note add')}/${s.cyan('recall')}/${s.cyan('comment')}/${s.cyan('transition')}`,
|
|
601
|
+
` above: same Pro gate, same local vault/tracker writes, same team sync.`,
|
|
602
|
+
` ${s.cyan('ticket_transition')} is destructive when called with \`target\`+\`confirm: true\`.`,
|
|
603
|
+
` Long-running — exits when the client closes stdin.`,
|
|
600
604
|
'',
|
|
601
605
|
` ${s.bold('OPTIONS')}`,
|
|
602
606
|
'',
|
|
603
607
|
` ${s.brand('-h')}, ${s.brand('--help')} Show this help`,
|
|
604
608
|
'',
|
|
609
|
+
` ${s.bold('COMMANDS')}`,
|
|
610
|
+
'',
|
|
611
|
+
` ${s.brand('install')} Register "ticketlens mcp" into the current project's .mcp.json`,
|
|
612
|
+
'',
|
|
613
|
+
` ${s.dim('install is ungated — writes the registration for anyone; the tools it')}`,
|
|
614
|
+
` ${s.dim('points at still require Pro at call time, same as note add/recall.')}`,
|
|
615
|
+
'',
|
|
605
616
|
` ${s.bold('HARNESS CONFIG')}`,
|
|
606
617
|
'',
|
|
607
618
|
` ${s.dim('{ "command": "ticketlens", "args": ["mcp"] }')}`,
|
|
@@ -609,6 +620,57 @@ export function printMcpHelp({ stream = process.stdout } = {}) {
|
|
|
609
620
|
` ${s.bold('EXAMPLES')}`,
|
|
610
621
|
'',
|
|
611
622
|
` ${s.dim('$')} ticketlens mcp`,
|
|
623
|
+
` ${s.dim('$')} ticketlens mcp install`,
|
|
624
|
+
` ${s.dim('$')} ticketlens mcp install --dry-run`,
|
|
625
|
+
'',
|
|
626
|
+
];
|
|
627
|
+
stream.write(lines.join('\n') + '\n');
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export function printCommentHelp({ stream = process.stdout } = {}) {
|
|
631
|
+
const s = createStyler({ isTTY: stream.isTTY });
|
|
632
|
+
const lines = [
|
|
633
|
+
'',
|
|
634
|
+
` ${s.bold(s.brand('ticketlens'))} ${s.bold('comment')} ${s.dim('TICKET-KEY --body="..."')} ${s.dim('[Pro]')}`,
|
|
635
|
+
'',
|
|
636
|
+
` Post a comment directly to the ticket in its tracker (Jira/GitHub/Linear). ${s.dim('[Pro]')}`,
|
|
637
|
+
` Writes to the real tracker — this is not a local Recall note.`,
|
|
638
|
+
'',
|
|
639
|
+
` ${s.bold('OPTIONS')}`,
|
|
640
|
+
'',
|
|
641
|
+
` ${s.brand('--body')}=${s.dim('TEXT')} Comment body ${s.dim('(required)')}`,
|
|
642
|
+
` ${s.brand('--profile')}=${s.dim('NAME')} Connection profile to use ${s.dim('(optional)')}`,
|
|
643
|
+
` ${s.brand('-h')}, ${s.brand('--help')} Show this help`,
|
|
644
|
+
'',
|
|
645
|
+
` ${s.bold('EXAMPLES')}`,
|
|
646
|
+
'',
|
|
647
|
+
` ${s.dim('$')} ticketlens comment PROD-123 --body="Looks good, merging."`,
|
|
648
|
+
'',
|
|
649
|
+
];
|
|
650
|
+
stream.write(lines.join('\n') + '\n');
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export function printTransitionHelp({ stream = process.stdout } = {}) {
|
|
654
|
+
const s = createStyler({ isTTY: stream.isTTY });
|
|
655
|
+
const lines = [
|
|
656
|
+
'',
|
|
657
|
+
` ${s.bold(s.brand('ticketlens'))} ${s.bold('transition')} ${s.dim('TICKET-KEY [--target="..." --confirm]')} ${s.dim('[Pro]')}`,
|
|
658
|
+
'',
|
|
659
|
+
` Move a ticket to a new status in its tracker (Jira/GitHub/Linear). ${s.dim('[Pro]')}`,
|
|
660
|
+
` Called with just a ticket key, lists the tracker's current valid options`,
|
|
661
|
+
` without changing anything. Add ${s.brand('--target')} and ${s.brand('--confirm')} together to execute.`,
|
|
662
|
+
'',
|
|
663
|
+
` ${s.bold('OPTIONS')}`,
|
|
664
|
+
'',
|
|
665
|
+
` ${s.brand('--target')}=${s.dim('NAME')} Target status/transition name ${s.dim('(from the list, case-insensitive)')}`,
|
|
666
|
+
` ${s.brand('--confirm')} Required alongside --target to actually execute`,
|
|
667
|
+
` ${s.brand('--profile')}=${s.dim('NAME')} Connection profile to use ${s.dim('(optional)')}`,
|
|
668
|
+
` ${s.brand('-h')}, ${s.brand('--help')} Show this help`,
|
|
669
|
+
'',
|
|
670
|
+
` ${s.bold('EXAMPLES')}`,
|
|
671
|
+
'',
|
|
672
|
+
` ${s.dim('$')} ticketlens transition PROD-123`,
|
|
673
|
+
` ${s.dim('$')} ticketlens transition PROD-123 --target="Done" --confirm`,
|
|
612
674
|
'',
|
|
613
675
|
];
|
|
614
676
|
stream.write(lines.join('\n') + '\n');
|