@denvermullets/jait 1.4.0 → 1.6.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/dist/api-client.d.ts +5 -1
- package/dist/api-client.js +60 -34
- package/dist/attachments.d.ts +9 -2
- package/dist/attachments.js +93 -29
- package/dist/description-sections.d.ts +44 -0
- package/dist/description-sections.js +156 -0
- package/dist/index.js +8 -0
- package/dist/tools/comments.d.ts +20 -0
- package/dist/tools/comments.js +85 -25
- package/dist/tools/decisions.d.ts +2 -0
- package/dist/tools/decisions.js +64 -0
- package/dist/tools/description-section-tools.d.ts +18 -0
- package/dist/tools/description-section-tools.js +77 -0
- package/dist/tools/issues.d.ts +46 -6
- package/dist/tools/issues.js +180 -30
- package/dist/tools/labels.js +39 -0
- package/dist/tools/notifications.d.ts +2 -0
- package/dist/tools/notifications.js +62 -0
- package/dist/tools/projects.js +81 -13
- package/dist/tools/recurring-issues.d.ts +2 -0
- package/dist/tools/recurring-issues.js +132 -0
- package/dist/tools/sub-issues.d.ts +32 -0
- package/dist/tools/sub-issues.js +90 -0
- package/package.json +4 -4
package/dist/api-client.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
interface RequestOptions {
|
|
2
2
|
method?: string;
|
|
3
3
|
body?: Record<string, unknown>;
|
|
4
|
-
form?: FormData;
|
|
5
4
|
params?: Record<string, string | number | undefined>;
|
|
6
5
|
}
|
|
6
|
+
export declare function apiBaseUrl(): string;
|
|
7
7
|
export declare function apiRequest<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
8
|
+
export declare function apiRequestWithHeaders<T>(path: string, options?: RequestOptions): Promise<{
|
|
9
|
+
data: T;
|
|
10
|
+
headers: Headers;
|
|
11
|
+
}>;
|
|
8
12
|
export {};
|
package/dist/api-client.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { readToken } from "./config-store.js";
|
|
2
2
|
const DEFAULT_API_URL = "https://justanotherissuetracker.com";
|
|
3
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
3
4
|
function getConfig() {
|
|
4
|
-
const apiUrl = process.env.MTASKS_API_URL || DEFAULT_API_URL;
|
|
5
5
|
const apiToken = process.env.MTASKS_API_TOKEN || readToken();
|
|
6
6
|
if (!apiToken) {
|
|
7
7
|
throw new Error("No token found. Run 'npx @denvermullets/jait login <token>' or set MTASKS_API_TOKEN.");
|
|
8
8
|
}
|
|
9
9
|
return {
|
|
10
|
-
baseUrl:
|
|
10
|
+
baseUrl: apiBaseUrl(),
|
|
11
11
|
token: apiToken,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
export function apiBaseUrl() {
|
|
15
|
+
return (process.env.MTASKS_API_URL || DEFAULT_API_URL).replace(/\/$/, "");
|
|
16
|
+
}
|
|
17
|
+
function apiTimeoutMs() {
|
|
18
|
+
const parsed = Number(process.env.MTASKS_API_TIMEOUT_MS);
|
|
19
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_TIMEOUT_MS;
|
|
20
|
+
}
|
|
14
21
|
export async function apiRequest(path, options = {}) {
|
|
22
|
+
return (await apiRequestWithHeaders(path, options)).data;
|
|
23
|
+
}
|
|
24
|
+
// Same as apiRequest, plus the response headers (for cursors such as
|
|
25
|
+
// X-Next-Before-Id on the activity feeds).
|
|
26
|
+
export async function apiRequestWithHeaders(path, options = {}) {
|
|
15
27
|
const { baseUrl, token } = getConfig();
|
|
16
|
-
const { method = "GET", body,
|
|
28
|
+
const { method = "GET", body, params } = options;
|
|
17
29
|
const url = new URL(`${baseUrl}${path}`);
|
|
18
30
|
if (params) {
|
|
19
31
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -22,39 +34,53 @@ export async function apiRequest(path, options = {}) {
|
|
|
22
34
|
}
|
|
23
35
|
}
|
|
24
36
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
const timeoutMs = apiTimeoutMs();
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
40
|
+
// The timer stays armed through the body read (a server can send headers
|
|
41
|
+
// and then stall) and is cleared only once the body is consumed.
|
|
42
|
+
try {
|
|
43
|
+
const response = await fetch(url.toString(), {
|
|
44
|
+
method,
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `Bearer ${token}`,
|
|
47
|
+
Accept: "application/json",
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
},
|
|
50
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const errorBody = await response.text();
|
|
55
|
+
let message;
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(errorBody);
|
|
58
|
+
message =
|
|
59
|
+
parsed.message ||
|
|
60
|
+
parsed.errors?.join(", ") ||
|
|
61
|
+
parsed.error ||
|
|
62
|
+
errorBody;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
message = errorBody;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`API error ${response.status}: ${message}`);
|
|
47
68
|
}
|
|
48
|
-
|
|
69
|
+
// Some endpoints (e.g. a 204 No Content on DELETE) return an empty body.
|
|
70
|
+
// Guard against JSON.parse throwing "Unexpected end of JSON input".
|
|
71
|
+
const text = response.status === 204 ? "" : await response.text();
|
|
72
|
+
return {
|
|
73
|
+
data: (text ? JSON.parse(text) : undefined),
|
|
74
|
+
headers: response.headers,
|
|
75
|
+
};
|
|
49
76
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
79
|
+
throw new Error(`Request to ${path} timed out after ${timeoutMs}ms`);
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
54
82
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return undefined;
|
|
83
|
+
finally {
|
|
84
|
+
clearTimeout(timer);
|
|
58
85
|
}
|
|
59
|
-
return JSON.parse(text);
|
|
60
86
|
}
|
package/dist/attachments.d.ts
CHANGED
|
@@ -2,15 +2,22 @@ import { z } from "zod";
|
|
|
2
2
|
export declare const filePathsSchema: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
3
3
|
export interface LocalFile {
|
|
4
4
|
filename: string;
|
|
5
|
+
contentType: string;
|
|
5
6
|
data: Uint8Array<ArrayBuffer>;
|
|
6
7
|
}
|
|
8
|
+
export interface UploadedFile {
|
|
9
|
+
filename: string;
|
|
10
|
+
signedId: string;
|
|
11
|
+
}
|
|
7
12
|
export interface Attachment {
|
|
8
13
|
id: number;
|
|
9
14
|
filename: string;
|
|
10
15
|
content_type: string;
|
|
11
16
|
byte_size: number;
|
|
12
|
-
|
|
17
|
+
download_url: string;
|
|
13
18
|
}
|
|
19
|
+
export declare function contentTypeFor(filename: string): string | undefined;
|
|
14
20
|
export declare function readLocalFiles(paths: string[]): Promise<LocalFile[]>;
|
|
15
|
-
export declare function
|
|
21
|
+
export declare function uploadLocalFiles(paths: string[] | undefined): Promise<UploadedFile[]>;
|
|
22
|
+
export declare function attachUploads(path: string, uploads: UploadedFile[]): Promise<Attachment[]>;
|
|
16
23
|
export declare function formatAttachments(attachments: Attachment[]): string;
|
package/dist/attachments.js
CHANGED
|
@@ -1,19 +1,53 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { readFile, stat } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
|
-
import { basename, resolve } from "node:path";
|
|
4
|
+
import { basename, extname, resolve } from "node:path";
|
|
4
5
|
import { z } from "zod";
|
|
6
|
+
import { apiBaseUrl, apiRequest } from "./api-client.js";
|
|
5
7
|
export const filePathsSchema = z
|
|
6
8
|
.array(z.string())
|
|
7
9
|
.optional()
|
|
8
|
-
.describe("Local file paths to attach (absolute, or ~/...).
|
|
10
|
+
.describe("Local file paths to attach (absolute, or ~/...). Max 25 MB each; images, PDFs, video, text/markdown/csv/json, zip and Office files. Existing attachments are kept.");
|
|
11
|
+
// Mirrors ALLOWED_CONTENT_TYPES in the Rails app's
|
|
12
|
+
// app/controllers/api/v1/direct_uploads_controller.rb (SVG/HTML are refused there).
|
|
13
|
+
const CONTENT_TYPES = {
|
|
14
|
+
".png": "image/png",
|
|
15
|
+
".jpg": "image/jpeg",
|
|
16
|
+
".jpeg": "image/jpeg",
|
|
17
|
+
".gif": "image/gif",
|
|
18
|
+
".webp": "image/webp",
|
|
19
|
+
".heic": "image/heic",
|
|
20
|
+
".avif": "image/avif",
|
|
21
|
+
".pdf": "application/pdf",
|
|
22
|
+
".txt": "text/plain",
|
|
23
|
+
".log": "text/plain",
|
|
24
|
+
".md": "text/markdown",
|
|
25
|
+
".markdown": "text/markdown",
|
|
26
|
+
".csv": "text/csv",
|
|
27
|
+
".json": "application/json",
|
|
28
|
+
".zip": "application/zip",
|
|
29
|
+
".doc": "application/msword",
|
|
30
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
31
|
+
".xls": "application/vnd.ms-excel",
|
|
32
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
33
|
+
".ppt": "application/vnd.ms-powerpoint",
|
|
34
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
35
|
+
".mp4": "video/mp4",
|
|
36
|
+
".mov": "video/quicktime",
|
|
37
|
+
".webm": "video/webm",
|
|
38
|
+
};
|
|
39
|
+
const MAX_BYTES = 25 * 1024 * 1024;
|
|
9
40
|
function expandPath(path) {
|
|
10
41
|
if (path === "~" || path.startsWith("~/")) {
|
|
11
42
|
return resolve(homedir(), path.slice(2));
|
|
12
43
|
}
|
|
13
44
|
return resolve(path);
|
|
14
45
|
}
|
|
15
|
-
|
|
16
|
-
|
|
46
|
+
export function contentTypeFor(filename) {
|
|
47
|
+
return CONTENT_TYPES[extname(filename).toLowerCase()];
|
|
48
|
+
}
|
|
49
|
+
// Reads and validates every file up front so a bad path or type fails the
|
|
50
|
+
// call before anything is written, rather than leaving a half-done change.
|
|
17
51
|
export async function readLocalFiles(paths) {
|
|
18
52
|
return Promise.all(paths.map(async (path) => {
|
|
19
53
|
const fullPath = expandPath(path);
|
|
@@ -21,34 +55,64 @@ export async function readLocalFiles(paths) {
|
|
|
21
55
|
if (!info?.isFile()) {
|
|
22
56
|
throw new Error(`Attachment not found or not a file: ${path}`);
|
|
23
57
|
}
|
|
58
|
+
const filename = basename(fullPath);
|
|
59
|
+
const contentType = contentTypeFor(filename);
|
|
60
|
+
if (!contentType) {
|
|
61
|
+
throw new Error(`Unsupported attachment type: ${filename}. Allowed: ${Object.keys(CONTENT_TYPES).join(" ")}`);
|
|
62
|
+
}
|
|
63
|
+
if (info.size === 0 || info.size > MAX_BYTES) {
|
|
64
|
+
throw new Error(`Attachment must be between 1 byte and 25 MB: ${path}`);
|
|
65
|
+
}
|
|
24
66
|
const buffer = await readFile(fullPath);
|
|
25
|
-
return { filename
|
|
67
|
+
return { filename, contentType, data: new Uint8Array(buffer) };
|
|
26
68
|
}));
|
|
27
69
|
}
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
70
|
+
// ActiveStorage direct upload: register the blob with the API, PUT the bytes
|
|
71
|
+
// to the storage URL it hands back, and return the signed id that the attach
|
|
72
|
+
// endpoints take. The storage URL is pre-signed, so no Authorization header.
|
|
73
|
+
async function uploadFile(file) {
|
|
74
|
+
const checksum = createHash("md5").update(file.data).digest("base64");
|
|
75
|
+
const blob = await apiRequest("/api/v1/direct_uploads", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
body: {
|
|
78
|
+
blob: {
|
|
79
|
+
filename: file.filename,
|
|
80
|
+
byte_size: file.data.byteLength,
|
|
81
|
+
checksum,
|
|
82
|
+
content_type: file.contentType,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const target = new URL(blob.direct_upload.url, apiBaseUrl());
|
|
87
|
+
const response = await fetch(target, {
|
|
88
|
+
method: "PUT",
|
|
89
|
+
headers: blob.direct_upload.headers,
|
|
90
|
+
body: file.data,
|
|
91
|
+
});
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw new Error(`Upload of ${file.filename} failed: ${response.status} ${await response.text()}`);
|
|
50
94
|
}
|
|
51
|
-
return
|
|
95
|
+
return { filename: file.filename, signedId: blob.signed_id };
|
|
96
|
+
}
|
|
97
|
+
// Validates every path, then uploads. Uploaded-but-unattached blobs are
|
|
98
|
+
// harmless (ActiveStorage purges orphans), so a later failure leaves no mess.
|
|
99
|
+
export async function uploadLocalFiles(paths) {
|
|
100
|
+
if (!paths || paths.length === 0)
|
|
101
|
+
return [];
|
|
102
|
+
const files = await readLocalFiles(paths);
|
|
103
|
+
const uploaded = [];
|
|
104
|
+
for (const file of files)
|
|
105
|
+
uploaded.push(await uploadFile(file));
|
|
106
|
+
return uploaded;
|
|
107
|
+
}
|
|
108
|
+
// POST {signed_ids} to an issue's or project's attachments endpoint.
|
|
109
|
+
export async function attachUploads(path, uploads) {
|
|
110
|
+
if (uploads.length === 0)
|
|
111
|
+
return [];
|
|
112
|
+
return apiRequest(path, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
body: { signed_ids: uploads.map((u) => u.signedId) },
|
|
115
|
+
});
|
|
52
116
|
}
|
|
53
117
|
function formatBytes(bytes) {
|
|
54
118
|
if (bytes < 1024)
|
|
@@ -59,6 +123,6 @@ function formatBytes(bytes) {
|
|
|
59
123
|
}
|
|
60
124
|
export function formatAttachments(attachments) {
|
|
61
125
|
return attachments
|
|
62
|
-
.map((a) => `${a.filename} (${a.content_type}, ${formatBytes(a.byte_size)})`)
|
|
126
|
+
.map((a) => `${a.filename} (${a.content_type}, ${formatBytes(a.byte_size)}, attachment ID: ${a.id})`)
|
|
63
127
|
.join(", ");
|
|
64
128
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface SectionInfo {
|
|
2
|
+
heading: string;
|
|
3
|
+
level: number;
|
|
4
|
+
}
|
|
5
|
+
/** Base class for every expected splicing failure (bad heading, bad match). */
|
|
6
|
+
export declare class SectionError extends Error {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class SectionNotFound extends SectionError {
|
|
10
|
+
constructor(heading: string, available: string[]);
|
|
11
|
+
}
|
|
12
|
+
export declare class DuplicateHeading extends SectionError {
|
|
13
|
+
constructor(heading: string, count: number);
|
|
14
|
+
}
|
|
15
|
+
export declare class TextNotFound extends SectionError {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
export declare class AmbiguousMatch extends SectionError {
|
|
19
|
+
constructor(count: number);
|
|
20
|
+
}
|
|
21
|
+
export declare class EmptyOldString extends SectionError {
|
|
22
|
+
constructor();
|
|
23
|
+
}
|
|
24
|
+
export declare function listSections(description: string): SectionInfo[];
|
|
25
|
+
/** Body of a section (heading line excluded), subsections included, verbatim. */
|
|
26
|
+
export declare function getSection(description: string, { heading }: {
|
|
27
|
+
heading: string;
|
|
28
|
+
}): string;
|
|
29
|
+
/** Replace a section's body (subsections included). Heading line is kept. */
|
|
30
|
+
export declare function replaceSection(description: string, { heading, body }: {
|
|
31
|
+
heading: string;
|
|
32
|
+
body: string;
|
|
33
|
+
}): string;
|
|
34
|
+
/** Append text at the end of a section (after its last subsection). */
|
|
35
|
+
export declare function appendToSection(description: string, { heading, text }: {
|
|
36
|
+
heading: string;
|
|
37
|
+
text: string;
|
|
38
|
+
}): string;
|
|
39
|
+
/** Literal find-and-replace over the whole description. */
|
|
40
|
+
export declare function replaceText(description: string, { oldString, newString, replaceAll, }: {
|
|
41
|
+
oldString: string;
|
|
42
|
+
newString: string;
|
|
43
|
+
replaceAll?: boolean;
|
|
44
|
+
}): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Pure string-in, string-out helpers for reading and editing a markdown
|
|
2
|
+
// description by section. No API or MCP SDK imports on purpose.
|
|
3
|
+
/** Base class for every expected splicing failure (bad heading, bad match). */
|
|
4
|
+
export class SectionError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "SectionError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class SectionNotFound extends SectionError {
|
|
11
|
+
constructor(heading, available) {
|
|
12
|
+
super(`Section "${heading}" not found. Available headings: ${available.length ? available.map((h) => `"${h}"`).join(", ") : "(none)"}`);
|
|
13
|
+
this.name = "SectionNotFound";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class DuplicateHeading extends SectionError {
|
|
17
|
+
constructor(heading, count) {
|
|
18
|
+
super(`Heading "${heading}" is ambiguous: it appears ${count} times in the description`);
|
|
19
|
+
this.name = "DuplicateHeading";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class TextNotFound extends SectionError {
|
|
23
|
+
constructor() {
|
|
24
|
+
super("Text not found: found 0 matches for oldString");
|
|
25
|
+
this.name = "TextNotFound";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class AmbiguousMatch extends SectionError {
|
|
29
|
+
constructor(count) {
|
|
30
|
+
super(`Ambiguous match: found ${count} matches for oldString; add surrounding context to make it unique or pass replaceAll`);
|
|
31
|
+
this.name = "AmbiguousMatch";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class EmptyOldString extends SectionError {
|
|
35
|
+
constructor() {
|
|
36
|
+
super("oldString must not be empty");
|
|
37
|
+
this.name = "EmptyOldString";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const HEADING_RE = /^(#{2,6})\s+(.+)$/;
|
|
41
|
+
const FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
|
|
42
|
+
function parse(description) {
|
|
43
|
+
const lines = [];
|
|
44
|
+
const re = /([^\r\n]*)(\r\n|\n|$)/g;
|
|
45
|
+
let m;
|
|
46
|
+
while ((m = re.exec(description)) !== null) {
|
|
47
|
+
if (m[0] === "")
|
|
48
|
+
break;
|
|
49
|
+
lines.push({ text: m[1], eol: m[2] });
|
|
50
|
+
}
|
|
51
|
+
const headings = [];
|
|
52
|
+
let fence = null;
|
|
53
|
+
lines.forEach((line, index) => {
|
|
54
|
+
const f = FENCE_RE.exec(line.text);
|
|
55
|
+
if (fence) {
|
|
56
|
+
if (f &&
|
|
57
|
+
f[1][0] === fence[0] &&
|
|
58
|
+
f[1].length >= fence.length &&
|
|
59
|
+
line.text.trim() === f[1]) {
|
|
60
|
+
fence = null;
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (f) {
|
|
65
|
+
fence = f[1];
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const h = HEADING_RE.exec(line.text);
|
|
69
|
+
if (!h)
|
|
70
|
+
return;
|
|
71
|
+
// CommonMark: an optional closing sequence of #s (preceded by whitespace)
|
|
72
|
+
// is not part of the heading text.
|
|
73
|
+
const heading = h[2]
|
|
74
|
+
.replace(/(?:^|\s+)#+\s*$/, "")
|
|
75
|
+
.trim();
|
|
76
|
+
if (heading)
|
|
77
|
+
headings.push({ index, heading, level: h[1].length });
|
|
78
|
+
});
|
|
79
|
+
return { lines, headings };
|
|
80
|
+
}
|
|
81
|
+
function locate(description, heading) {
|
|
82
|
+
const { lines, headings } = parse(description);
|
|
83
|
+
const matches = headings.filter((h) => h.heading === heading);
|
|
84
|
+
if (matches.length === 0) {
|
|
85
|
+
throw new SectionNotFound(heading, headings.map((h) => h.heading));
|
|
86
|
+
}
|
|
87
|
+
if (matches.length > 1)
|
|
88
|
+
throw new DuplicateHeading(heading, matches.length);
|
|
89
|
+
const target = matches[0];
|
|
90
|
+
const next = headings.find((h) => h.index > target.index && h.level <= target.level);
|
|
91
|
+
const end = next ? next.index : lines.length;
|
|
92
|
+
const join = (from, to) => lines
|
|
93
|
+
.slice(from, to)
|
|
94
|
+
.map((l) => l.text + l.eol)
|
|
95
|
+
.join("");
|
|
96
|
+
const eol = lines.find((l) => l.eol)?.eol || "\n";
|
|
97
|
+
return {
|
|
98
|
+
head: lines[target.index],
|
|
99
|
+
body: join(target.index + 1, end),
|
|
100
|
+
before: join(0, target.index + 1),
|
|
101
|
+
after: join(end, lines.length),
|
|
102
|
+
hasAfter: end < lines.length,
|
|
103
|
+
eol,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function splitTrailingBreaks(s) {
|
|
107
|
+
const m = /(?:\r?\n)*$/.exec(s);
|
|
108
|
+
return { content: s.slice(0, m.index), trailing: m[0] };
|
|
109
|
+
}
|
|
110
|
+
function assemble(loc, content, trailing) {
|
|
111
|
+
let before = loc.before;
|
|
112
|
+
if (content && !loc.head.eol)
|
|
113
|
+
before += loc.eol; // heading was the last, unterminated line
|
|
114
|
+
let body = content + trailing;
|
|
115
|
+
if (loc.hasAfter && body && !/\n$/.test(body))
|
|
116
|
+
body += loc.eol;
|
|
117
|
+
if (loc.hasAfter && !body && !loc.head.eol)
|
|
118
|
+
before += loc.eol;
|
|
119
|
+
return before + body + loc.after;
|
|
120
|
+
}
|
|
121
|
+
export function listSections(description) {
|
|
122
|
+
return parse(description).headings.map(({ heading, level }) => ({
|
|
123
|
+
heading,
|
|
124
|
+
level,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/** Body of a section (heading line excluded), subsections included, verbatim. */
|
|
128
|
+
export function getSection(description, { heading }) {
|
|
129
|
+
return locate(description, heading).body;
|
|
130
|
+
}
|
|
131
|
+
/** Replace a section's body (subsections included). Heading line is kept. */
|
|
132
|
+
export function replaceSection(description, { heading, body }) {
|
|
133
|
+
const loc = locate(description, heading);
|
|
134
|
+
const { trailing } = splitTrailingBreaks(loc.body);
|
|
135
|
+
return assemble(loc, splitTrailingBreaks(body).content, trailing);
|
|
136
|
+
}
|
|
137
|
+
/** Append text at the end of a section (after its last subsection). */
|
|
138
|
+
export function appendToSection(description, { heading, text }) {
|
|
139
|
+
const loc = locate(description, heading);
|
|
140
|
+
const { content, trailing } = splitTrailingBreaks(loc.body);
|
|
141
|
+
const add = splitTrailingBreaks(text).content;
|
|
142
|
+
const joined = content ? content + loc.eol + add : add;
|
|
143
|
+
return assemble(loc, joined, trailing);
|
|
144
|
+
}
|
|
145
|
+
/** Literal find-and-replace over the whole description. */
|
|
146
|
+
export function replaceText(description, { oldString, newString, replaceAll = false, }) {
|
|
147
|
+
if (oldString === "")
|
|
148
|
+
throw new EmptyOldString();
|
|
149
|
+
const parts = description.split(oldString);
|
|
150
|
+
const count = parts.length - 1;
|
|
151
|
+
if (count === 0)
|
|
152
|
+
throw new TextNotFound();
|
|
153
|
+
if (count > 1 && !replaceAll)
|
|
154
|
+
throw new AmbiguousMatch(count);
|
|
155
|
+
return parts.join(newString);
|
|
156
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,11 @@ import { registerMemberTools } from "./tools/members.js";
|
|
|
8
8
|
import { registerLabelTools } from "./tools/labels.js";
|
|
9
9
|
import { registerProjectTools } from "./tools/projects.js";
|
|
10
10
|
import { registerIssueDependencyTools } from "./tools/issue-dependencies.js";
|
|
11
|
+
import { registerSubIssueTools } from "./tools/sub-issues.js";
|
|
11
12
|
import { registerCommentTools } from "./tools/comments.js";
|
|
13
|
+
import { registerDecisionTools } from "./tools/decisions.js";
|
|
14
|
+
import { registerNotificationTools } from "./tools/notifications.js";
|
|
15
|
+
import { registerRecurringIssueTools } from "./tools/recurring-issues.js";
|
|
12
16
|
import { writeToken, clearToken } from "./config-store.js";
|
|
13
17
|
const [, , cmd, arg] = process.argv;
|
|
14
18
|
if (cmd === "login") {
|
|
@@ -32,10 +36,14 @@ const server = new McpServer({
|
|
|
32
36
|
registerTeamTools(server);
|
|
33
37
|
registerIssueTools(server);
|
|
34
38
|
registerIssueDependencyTools(server);
|
|
39
|
+
registerSubIssueTools(server);
|
|
35
40
|
registerCommentTools(server);
|
|
36
41
|
registerLaneTools(server);
|
|
37
42
|
registerMemberTools(server);
|
|
38
43
|
registerLabelTools(server);
|
|
39
44
|
registerProjectTools(server);
|
|
45
|
+
registerDecisionTools(server);
|
|
46
|
+
registerNotificationTools(server);
|
|
47
|
+
registerRecurringIssueTools(server);
|
|
40
48
|
const transport = new StdioServerTransport();
|
|
41
49
|
await server.connect(transport);
|
package/dist/tools/comments.d.ts
CHANGED
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type Attachment } from "../attachments.js";
|
|
3
|
+
interface CommentUser {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Comment {
|
|
9
|
+
id: number;
|
|
10
|
+
body: string | null;
|
|
11
|
+
parent_id: number | null;
|
|
12
|
+
user: CommentUser | null;
|
|
13
|
+
files?: Attachment[];
|
|
14
|
+
created_at: string;
|
|
15
|
+
updated_at: string;
|
|
16
|
+
replies?: Comment[];
|
|
17
|
+
owner_type?: "Issue" | "Project";
|
|
18
|
+
owner_id?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function formatComment(comment: Comment, indent?: number): string;
|
|
2
21
|
export declare function registerCommentTools(server: McpServer): void;
|
|
22
|
+
export {};
|