@kud/jira-cli 0.2.1 → 0.3.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Jira on the command line. Reads issues, comments and **attachments** as plain text, so you can pipe them into anything.
4
4
 
5
- Black and white output, `--json` on every read, stable exit codes. No interactive prompts.
5
+ Black and white output, `--json` on every read, stable exit codes. Every subcommand is plain and pipeable — the interactive view lives behind the bare `jira` command and nowhere else.
6
6
 
7
7
  ## Install
8
8
 
@@ -41,6 +41,20 @@ Descriptions and comments render as Markdown, with embedded files named rather t
41
41
  jira issue view ABC-123 --comments
42
42
  ```
43
43
 
44
+ ## The interactive view
45
+
46
+ Run `jira` with no arguments:
47
+
48
+ ```sh
49
+ jira
50
+ ```
51
+
52
+ Your open issues, newest first. `↑↓` to move, `enter` to open, `a` to include closed ones, `r` to refresh, `q` to quit.
53
+
54
+ Inside an issue, `←→` switches between description, comments and attachments — descriptions and comments render as real Markdown, and attachments are listed with the comment or description each was embedded in. `t` transitions, `c` comments, `a` assigns to you, `o` opens the browser, `esc` goes back. Writes ask before they act.
55
+
56
+ Ink is loaded only for this view, via a dynamic import, so `jira issue list | grep` never pays for it. Piped or redirected, bare `jira` prints help instead of opening a UI.
57
+
44
58
  ## Using it alongside the Atlassian MCP
45
59
 
46
60
  The Atlassian MCP returns an issue's fields and comments, but **not** the content of its attachments — it can tell you a file is there and nothing more. When the answer to a ticket is inside a screenshot, a log or a CSV, that is the gap this fills:
@@ -0,0 +1,117 @@
1
+ // src/config.ts
2
+ import { readFileSync } from "fs";
3
+ import { homedir } from "os";
4
+ import { join } from "path";
5
+ import { normalizeBaseUrl } from "@kud/jira";
6
+ var configPath = () => process.env["JIRA_CONFIG_FILE"] || join(
7
+ process.env["XDG_CONFIG_HOME"] || join(homedir(), ".config"),
8
+ "jira",
9
+ "config.json"
10
+ );
11
+ var readFileConfig = (path = configPath()) => {
12
+ let raw;
13
+ try {
14
+ raw = readFileSync(path, "utf8");
15
+ } catch {
16
+ return {};
17
+ }
18
+ const parsed = JSON.parse(raw);
19
+ if (parsed.customFields && !Array.isArray(parsed.customFields))
20
+ throw new Error(`${path}: customFields must be an array of {id,label}`);
21
+ if ("token" in parsed || "apiToken" in parsed)
22
+ throw new Error(
23
+ `${path} contains a token. Tokens belong in ATLASSIAN_API_TOKEN, not in a file that gets shared and backed up \u2014 remove it.`
24
+ );
25
+ return parsed;
26
+ };
27
+ var loadConfig = (env = process.env, path = configPath()) => {
28
+ const file = readFileConfig(path);
29
+ const baseUrl = env["ATLASSIAN_BASE_URL"] || file.baseUrl;
30
+ const email = env["ATLASSIAN_USER_EMAIL"] || file.email;
31
+ const token = env["ATLASSIAN_API_TOKEN"];
32
+ const missing = [
33
+ ["ATLASSIAN_BASE_URL", baseUrl],
34
+ ["ATLASSIAN_USER_EMAIL", email],
35
+ ["ATLASSIAN_API_TOKEN", token]
36
+ ].filter(([, v]) => !v).map(([k]) => k);
37
+ if (missing.length > 0) return { missing };
38
+ return {
39
+ config: {
40
+ ...file,
41
+ baseUrl: normalizeBaseUrl(baseUrl),
42
+ email,
43
+ token
44
+ }
45
+ };
46
+ };
47
+
48
+ // src/commands/context.ts
49
+ import { createJiraClient } from "@kud/jira";
50
+
51
+ // src/output/format.ts
52
+ var identity = (s) => s;
53
+ var wrap = (open, close) => (s) => `\x1B[${open}m${s}\x1B[${close}m`;
54
+ var palette = (isTty, env = process.env) => {
55
+ const on = isTty && !env["NO_COLOR"] && env["TERM"] !== "dumb";
56
+ const c = (open, close) => on ? wrap(open, close) : identity;
57
+ return {
58
+ on,
59
+ dim: c("2", "22"),
60
+ bold: c("1", "22")
61
+ };
62
+ };
63
+ var ANSI = /\u001b\[[0-9;]*m/g;
64
+ var width = (s) => s.replace(ANSI, "").length;
65
+ var pad = (s, to) => s + " ".repeat(Math.max(0, to - width(s)));
66
+ var table = (rows, columns) => {
67
+ if (rows.length === 0) return "";
68
+ const cells = rows.map((r) => columns.map((c) => c.value(r)));
69
+ const widths = columns.map(
70
+ (c, i) => Math.max(width(c.header), ...cells.map((row) => width(row[i])))
71
+ );
72
+ const line = (values) => values.map((v, i) => {
73
+ const w = widths[i];
74
+ return columns[i]?.align === "right" ? " ".repeat(Math.max(0, w - width(v))) + v : pad(v, w);
75
+ }).join(" ").trimEnd();
76
+ return [line(columns.map((c) => c.header)), ...cells.map(line)].join("\n");
77
+ };
78
+ var truncate = (s, max) => s.length <= max ? s : `${s.slice(0, Math.max(0, max - 1))}\u2026`;
79
+
80
+ // src/commands/context.ts
81
+ var exitError = (code, message) => Object.assign(new Error(message), { name: "ExitError", code });
82
+ var isExitError = (e) => e instanceof Error && e.name === "ExitError";
83
+ var context = () => {
84
+ const loaded = loadConfig();
85
+ if ("missing" in loaded) {
86
+ throw exitError(
87
+ 2,
88
+ `missing environment variables: ${loaded.missing.join(", ")}
89
+
90
+ Set them, then retry:
91
+ export ATLASSIAN_BASE_URL=myorg.atlassian.net
92
+ export ATLASSIAN_USER_EMAIL=you@example.com
93
+ export ATLASSIAN_API_TOKEN=... # id.atlassian.com/manage-profile/security/api-tokens`
94
+ );
95
+ }
96
+ const { config } = loaded;
97
+ return {
98
+ config,
99
+ client: createJiraClient(config),
100
+ out: palette(process.stdout.isTTY === true)
101
+ };
102
+ };
103
+ var printJson = (value) => {
104
+ process.stdout.write(`${JSON.stringify(value, null, 2)}
105
+ `);
106
+ };
107
+
108
+ export {
109
+ table,
110
+ truncate,
111
+ configPath,
112
+ readFileConfig,
113
+ exitError,
114
+ isExitError,
115
+ context,
116
+ printJson
117
+ };
package/dist/index.js CHANGED
@@ -1,6 +1,18 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ configPath,
4
+ context,
5
+ exitError,
6
+ isExitError,
7
+ printJson,
8
+ readFileConfig,
9
+ table,
10
+ truncate
11
+ } from "./chunk-5MFNIQDW.js";
2
12
 
3
13
  // src/index.ts
14
+ import { realpathSync } from "fs";
15
+ import { fileURLToPath } from "url";
4
16
  import { Command } from "commander";
5
17
  import { isJiraApiError } from "@kud/jira";
6
18
 
@@ -12,115 +24,6 @@ import {
12
24
  isTextual,
13
25
  locateAttachments
14
26
  } from "@kud/jira";
15
-
16
- // src/output/format.ts
17
- var identity = (s) => s;
18
- var wrap = (open, close) => (s) => `\x1B[${open}m${s}\x1B[${close}m`;
19
- var palette = (isTty, env = process.env) => {
20
- const on = isTty && !env["NO_COLOR"] && env["TERM"] !== "dumb";
21
- const c = (open, close) => on ? wrap(open, close) : identity;
22
- return {
23
- on,
24
- dim: c("2", "22"),
25
- bold: c("1", "22")
26
- };
27
- };
28
- var ANSI = /\u001b\[[0-9;]*m/g;
29
- var width = (s) => s.replace(ANSI, "").length;
30
- var pad = (s, to) => s + " ".repeat(Math.max(0, to - width(s)));
31
- var table = (rows, columns) => {
32
- if (rows.length === 0) return "";
33
- const cells = rows.map((r) => columns.map((c) => c.value(r)));
34
- const widths = columns.map(
35
- (c, i) => Math.max(width(c.header), ...cells.map((row) => width(row[i])))
36
- );
37
- const line = (values) => values.map((v, i) => {
38
- const w = widths[i];
39
- return columns[i]?.align === "right" ? " ".repeat(Math.max(0, w - width(v))) + v : pad(v, w);
40
- }).join(" ").trimEnd();
41
- return [line(columns.map((c) => c.header)), ...cells.map(line)].join("\n");
42
- };
43
- var truncate = (s, max) => s.length <= max ? s : `${s.slice(0, Math.max(0, max - 1))}\u2026`;
44
-
45
- // src/commands/context.ts
46
- import { createJiraClient } from "@kud/jira";
47
-
48
- // src/config.ts
49
- import { readFileSync } from "fs";
50
- import { homedir } from "os";
51
- import { join } from "path";
52
- import { normalizeBaseUrl } from "@kud/jira";
53
- var configPath = () => process.env["JIRA_CONFIG_FILE"] || join(
54
- process.env["XDG_CONFIG_HOME"] || join(homedir(), ".config"),
55
- "jira",
56
- "config.json"
57
- );
58
- var readFileConfig = (path = configPath()) => {
59
- let raw;
60
- try {
61
- raw = readFileSync(path, "utf8");
62
- } catch {
63
- return {};
64
- }
65
- const parsed = JSON.parse(raw);
66
- if (parsed.customFields && !Array.isArray(parsed.customFields))
67
- throw new Error(`${path}: customFields must be an array of {id,label}`);
68
- if ("token" in parsed || "apiToken" in parsed)
69
- throw new Error(
70
- `${path} contains a token. Tokens belong in ATLASSIAN_API_TOKEN, not in a file that gets shared and backed up \u2014 remove it.`
71
- );
72
- return parsed;
73
- };
74
- var loadConfig = (env = process.env, path = configPath()) => {
75
- const file = readFileConfig(path);
76
- const baseUrl = env["ATLASSIAN_BASE_URL"] || file.baseUrl;
77
- const email = env["ATLASSIAN_USER_EMAIL"] || file.email;
78
- const token = env["ATLASSIAN_API_TOKEN"];
79
- const missing = [
80
- ["ATLASSIAN_BASE_URL", baseUrl],
81
- ["ATLASSIAN_USER_EMAIL", email],
82
- ["ATLASSIAN_API_TOKEN", token]
83
- ].filter(([, v]) => !v).map(([k]) => k);
84
- if (missing.length > 0) return { missing };
85
- return {
86
- config: {
87
- ...file,
88
- baseUrl: normalizeBaseUrl(baseUrl),
89
- email,
90
- token
91
- }
92
- };
93
- };
94
-
95
- // src/commands/context.ts
96
- var exitError = (code, message) => Object.assign(new Error(message), { name: "ExitError", code });
97
- var isExitError = (e) => e instanceof Error && e.name === "ExitError";
98
- var context = () => {
99
- const loaded = loadConfig();
100
- if ("missing" in loaded) {
101
- throw exitError(
102
- 2,
103
- `missing environment variables: ${loaded.missing.join(", ")}
104
-
105
- Set them, then retry:
106
- export ATLASSIAN_BASE_URL=myorg.atlassian.net
107
- export ATLASSIAN_USER_EMAIL=you@example.com
108
- export ATLASSIAN_API_TOKEN=... # id.atlassian.com/manage-profile/security/api-tokens`
109
- );
110
- }
111
- const { config } = loaded;
112
- return {
113
- config,
114
- client: createJiraClient(config),
115
- out: palette(process.stdout.isTTY === true)
116
- };
117
- };
118
- var printJson = (value) => {
119
- process.stdout.write(`${JSON.stringify(value, null, 2)}
120
- `);
121
- };
122
-
123
- // src/commands/attachment.ts
124
27
  var humanSize = (bytes) => {
125
28
  const units = ["B", "KB", "MB", "GB"];
126
29
  const exponent = Math.min(
@@ -332,9 +235,9 @@ import {
332
235
  } from "@kud/jira";
333
236
 
334
237
  // src/commands/issue-write.ts
335
- import { readFileSync as readFileSync2 } from "fs";
238
+ import { readFileSync } from "fs";
336
239
  import { adfToMarkdown, markdownToAdf } from "@kud/jira";
337
- var readBody = (value) => value === "-" ? readFileSync2(0, "utf8") : value;
240
+ var readBody = (value) => value === "-" ? readFileSync(0, "utf8") : value;
338
241
  var resolveAccountId = async (who, projectKey) => {
339
242
  if (who === "none" || who === "unassigned") return null;
340
243
  if (who === "me") return (await context().client.getMe()).accountId;
@@ -477,8 +380,8 @@ var registerIssueWriteCommands = (issue) => {
477
380
  if (options.json) return printJson(values);
478
381
  process.stdout.write(
479
382
  `${values.flatMap(
480
- (entry) => (entry.items ?? []).map(
481
- (item) => `${ctx.out.dim(entry.created?.slice(0, 10) ?? "\u2014")} ${entry.author?.displayName ?? "unknown"} ${item.field}: ${item.fromString ?? "\u2014"} \u2192 ${item.toString ?? "\u2014"}`
383
+ (entry2) => (entry2.items ?? []).map(
384
+ (item) => `${ctx.out.dim(entry2.created?.slice(0, 10) ?? "\u2014")} ${entry2.author?.displayName ?? "unknown"} ${item.field}: ${item.fromString ?? "\u2014"} \u2192 ${item.toString ?? "\u2014"}`
482
385
  )
483
386
  ).join("\n")}
484
387
  `
@@ -589,7 +492,7 @@ var registerIssueCommands = (program2) => {
589
492
  `);
590
493
  }
591
494
  );
592
- issue.command("transition <key> [status]").alias("move").description("move an issue, or list available transitions").option("--json", "emit JSON").action(
495
+ issue.command("transition <key> [status]").alias("move").description("move an issue, or list available transitions").option("--resolution <name>", "resolution to set as part of the move").option("--json", "emit JSON").action(
593
496
  async (key, status, options) => {
594
497
  const ctx = context();
595
498
  const { transitions } = await ctx.client.getTransitions(key);
@@ -615,7 +518,11 @@ var registerIssueCommands = (program2) => {
615
518
  `no transition '${status}' on ${key}. Available: ${transitions.map((t) => t.name).join(", ")}`
616
519
  );
617
520
  }
618
- await ctx.client.transitionIssue(key, match.id);
521
+ await ctx.client.transitionIssue(
522
+ key,
523
+ match.id,
524
+ options.resolution ? { resolution: { name: options.resolution } } : void 0
525
+ );
619
526
  if (options.json) return printJson({ key, transition: match });
620
527
  process.stdout.write(`${key} \u2192 ${match.to?.name ?? match.name}
621
528
  `);
@@ -968,10 +875,54 @@ var exitCodeFor = (error) => {
968
875
  return error.status === 401 || error.status === 403 ? 4 : 1;
969
876
  return 1;
970
877
  };
971
- program.parseAsync(process.argv).catch((error) => {
878
+ var fail = (error) => {
972
879
  process.stderr.write(
973
880
  `jira: ${error instanceof Error ? error.message : String(error)}
974
881
  `
975
882
  );
976
883
  process.exit(exitCodeFor(error));
977
- });
884
+ };
885
+ var interactiveArgs = (argv) => {
886
+ const rest = argv.slice(2);
887
+ const screenAt = rest.indexOf("--screen");
888
+ const screen = screenAt === -1 ? void 0 : rest[screenAt + 1];
889
+ const consumed = new Set(
890
+ screenAt === -1 ? ["--mock"] : ["--mock", "--screen", screen ?? ""]
891
+ );
892
+ return {
893
+ screen,
894
+ mock: rest.includes("--mock"),
895
+ isBare: rest.every((a) => consumed.has(a))
896
+ };
897
+ };
898
+ var main = async () => {
899
+ const { screen, mock, isBare } = interactiveArgs(process.argv);
900
+ if (screen === "list" && isBare) {
901
+ const { SCREENS } = await import("./tui-4JIAFCJF.js");
902
+ process.stdout.write(`${SCREENS.join("\n")}
903
+ `);
904
+ return;
905
+ }
906
+ if (isBare) {
907
+ if (!process.stdout.isTTY) {
908
+ program.outputHelp();
909
+ return;
910
+ }
911
+ const { runTui } = await import("./tui-4JIAFCJF.js");
912
+ const [, key] = (screen ?? "").split(":");
913
+ await runTui({
914
+ screen: screen?.startsWith("detail") ? "detail" : "issues",
915
+ mock,
916
+ ...key ? { issueKey: key } : {}
917
+ });
918
+ return;
919
+ }
920
+ await program.parseAsync(process.argv);
921
+ };
922
+ var entry = process.argv[1];
923
+ if (entry && fileURLToPath(import.meta.url) === realpathSync(entry)) {
924
+ main().catch(fail);
925
+ }
926
+ export {
927
+ interactiveArgs
928
+ };
@@ -0,0 +1,593 @@
1
+ import {
2
+ context
3
+ } from "./chunk-5MFNIQDW.js";
4
+
5
+ // src/tui/index.tsx
6
+ import { render } from "ink";
7
+
8
+ // src/tui/app.tsx
9
+ import { execFile } from "child_process";
10
+ import { Alert, ConfirmInput, Select, Spinner, TextInput } from "@kud/ink-ui";
11
+ import { Box as Box3, Text as Text3, useApp, useInput as useInput3, useStdout } from "ink";
12
+ import { useCallback, useEffect, useState as useState2 } from "react";
13
+
14
+ // src/tui/detail.tsx
15
+ import { MarkdownViewport } from "@kud/ink-markdown";
16
+ import {
17
+ Badge,
18
+ FooterHints,
19
+ KeyValue,
20
+ Tabs,
21
+ useTabs
22
+ } from "@kud/ink-ui";
23
+ import { Box, Text, useInput } from "ink";
24
+ import { useState } from "react";
25
+ import { jsx, jsxs } from "react/jsx-runtime";
26
+ var originOf = (a) => a.origins.map(
27
+ (o) => o.kind === "comment" ? `comment by ${o.author ?? "unknown"}` : o.kind === "description" ? "description" : "issue"
28
+ ).join(", ");
29
+ var humanSize = (bytes) => {
30
+ const units = ["B", "KB", "MB", "GB"];
31
+ const e = Math.min(
32
+ units.length - 1,
33
+ Math.floor(Math.log(Math.max(bytes, 1)) / Math.log(1024))
34
+ );
35
+ const value = bytes / 1024 ** e;
36
+ return `${e === 0 ? value : value.toFixed(1)}${units[e]}`;
37
+ };
38
+ var commentsAsMarkdown = (issue) => issue.comments.length === 0 ? "_No comments._" : issue.comments.map((c) => `**${c.author}** \xB7 ${c.created}
39
+
40
+ ${c.body}`).join("\n\n---\n\n");
41
+ var attachmentsAsMarkdown = (issue) => issue.attachments.length === 0 ? "_No attachments._" : issue.attachments.map(
42
+ (a) => `- \`${a.filename}\` \u2014 ${a.mimeType}, ${humanSize(a.size)}
43
+ from ${originOf(a)}
44
+ \`jira attachment read ${issue.key} ${a.filename}\``
45
+ ).join("\n");
46
+ var IssueDetailView = ({
47
+ issue,
48
+ height,
49
+ width,
50
+ onBack,
51
+ onTransition,
52
+ onComment,
53
+ onAssign,
54
+ onOpenBrowser
55
+ }) => {
56
+ const tabs = [
57
+ { value: "description", label: "Description" },
58
+ { value: "comments", label: "Comments", count: issue.comments.length },
59
+ {
60
+ value: "attachments",
61
+ label: "Attachments",
62
+ count: issue.attachments.length
63
+ }
64
+ ];
65
+ const { active } = useTabs(tabs, { initial: "description" });
66
+ const [scroll, setScroll] = useState(0);
67
+ useInput((input, key) => {
68
+ if (key.escape || key.leftArrow) return onBack();
69
+ if (input === "t") return onTransition();
70
+ if (input === "c") return onComment();
71
+ if (input === "a") return onAssign();
72
+ if (input === "o") return onOpenBrowser();
73
+ if (key.downArrow || input === "j") setScroll((s) => s + 1);
74
+ if (key.upArrow || input === "k") setScroll((s) => Math.max(0, s - 1));
75
+ });
76
+ const source = active === "comments" ? commentsAsMarkdown(issue) : active === "attachments" ? attachmentsAsMarkdown(issue) : issue.description || "_No description._";
77
+ const bodyHeight = Math.max(3, height - 12);
78
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
79
+ /* @__PURE__ */ jsxs(Text, { bold: true, children: [
80
+ issue.key,
81
+ " ",
82
+ issue.summary
83
+ ] }),
84
+ /* @__PURE__ */ jsxs(Box, { marginTop: 1, flexDirection: "column", children: [
85
+ /* @__PURE__ */ jsx(KeyValue, { label: "status", value: /* @__PURE__ */ jsx(Badge, { children: issue.status }) }),
86
+ /* @__PURE__ */ jsx(KeyValue, { label: "type", value: issue.type }),
87
+ /* @__PURE__ */ jsx(KeyValue, { label: "assignee", value: issue.assignee }),
88
+ /* @__PURE__ */ jsx(KeyValue, { label: "reporter", value: issue.reporter }),
89
+ issue.labels.length > 0 && /* @__PURE__ */ jsx(KeyValue, { label: "labels", value: issue.labels.join(", ") })
90
+ ] }),
91
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Tabs, { items: tabs, active: active ?? "description" }) }),
92
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(
93
+ MarkdownViewport,
94
+ {
95
+ source,
96
+ width: Math.max(20, width - 2),
97
+ height: bodyHeight,
98
+ scrollOffset: scroll
99
+ }
100
+ ) }),
101
+ /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(
102
+ FooterHints,
103
+ {
104
+ hints: [
105
+ ["\u2190\u2192", "section"],
106
+ ["\u2191\u2193", "scroll"],
107
+ ["t", "transition"],
108
+ ["c", "comment"],
109
+ ["a", "assign to me"],
110
+ ["o", "browser"],
111
+ ["esc", "back"]
112
+ ]
113
+ }
114
+ ) })
115
+ ] });
116
+ };
117
+
118
+ // src/tui/list.tsx
119
+ import { FooterHints as FooterHints2, SelectableRow, useListCursor } from "@kud/ink-ui";
120
+ import { Box as Box2, Text as Text2, useInput as useInput2 } from "ink";
121
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
122
+ var pad = (s, width) => s.length > width ? `${s.slice(0, width - 1)}\u2026` : s.padEnd(width);
123
+ var windowFor = (cursor, total, size) => {
124
+ const start = Math.max(
125
+ 0,
126
+ Math.min(cursor - Math.floor(size / 2), total - size)
127
+ );
128
+ return { start: Math.max(0, start), end: Math.max(0, start) + size };
129
+ };
130
+ var IssueList = ({
131
+ rows,
132
+ showingAll,
133
+ onOpen,
134
+ onToggleAll,
135
+ onRefresh,
136
+ height
137
+ }) => {
138
+ const { cursor } = useListCursor(rows.length, { vimKeys: true });
139
+ useInput2((input, key) => {
140
+ if (key.return && rows[cursor]) onOpen(rows[cursor].key);
141
+ if (input === "a") onToggleAll();
142
+ if (input === "r") onRefresh();
143
+ });
144
+ const hints = [
145
+ ["\u2191\u2193", "move"],
146
+ ["enter", "open"],
147
+ ["a", showingAll ? "open only" : "show all"],
148
+ ["r", "refresh"],
149
+ ["q", "quit"]
150
+ ];
151
+ if (rows.length === 0) {
152
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", gap: 1, children: [
153
+ /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: showingAll ? "Nothing is assigned to you." : "No open issues assigned to you \u2014 press a to include closed ones." }),
154
+ /* @__PURE__ */ jsx2(FooterHints2, { hints })
155
+ ] });
156
+ }
157
+ const size = Math.max(3, height - 5);
158
+ const { start, end } = windowFor(cursor, rows.length, size);
159
+ const visible = rows.slice(start, end);
160
+ return /* @__PURE__ */ jsxs2(Box2, { flexDirection: "column", children: [
161
+ /* @__PURE__ */ jsx2(Box2, { paddingLeft: 2, children: /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
162
+ pad("KEY", 11),
163
+ pad("STATUS", 17),
164
+ pad("SUMMARY", 60),
165
+ "ASSIGNEE"
166
+ ] }) }),
167
+ visible.map((row, i) => /* @__PURE__ */ jsx2(SelectableRow, { active: start + i === cursor, children: /* @__PURE__ */ jsxs2(Text2, { children: [
168
+ pad(row.key, 11),
169
+ pad(row.status, 17),
170
+ pad(row.summary, 60),
171
+ /* @__PURE__ */ jsx2(Text2, { dimColor: true, children: row.assignee })
172
+ ] }) }, row.key)),
173
+ /* @__PURE__ */ jsxs2(Box2, { marginTop: 1, flexDirection: "column", children: [
174
+ /* @__PURE__ */ jsxs2(Text2, { dimColor: true, children: [
175
+ cursor + 1,
176
+ "/",
177
+ rows.length,
178
+ showingAll ? " \xB7 all" : " \xB7 open only"
179
+ ] }),
180
+ /* @__PURE__ */ jsx2(FooterHints2, { hints })
181
+ ] })
182
+ ] });
183
+ };
184
+
185
+ // src/tui/app.tsx
186
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
187
+ var MIN_WIDTH = 60;
188
+ var MIN_HEIGHT = 12;
189
+ var App = ({ data, initialScreen, initialKey }) => {
190
+ const { exit } = useApp();
191
+ const { stdout } = useStdout();
192
+ const width = stdout?.columns ?? 80;
193
+ const height = stdout?.rows ?? 24;
194
+ const [screen, setScreen] = useState2(initialScreen);
195
+ const [rows, setRows] = useState2(null);
196
+ const [issue, setIssue] = useState2(null);
197
+ const [overlay, setOverlay] = useState2({ kind: "none" });
198
+ const [showingAll, setShowingAll] = useState2(false);
199
+ const [error, setError] = useState2(null);
200
+ const [busy, setBusy] = useState2(null);
201
+ const loadList = useCallback(
202
+ async (all) => {
203
+ setError(null);
204
+ setRows(null);
205
+ try {
206
+ setRows(await data.listIssues(all));
207
+ } catch (e) {
208
+ setError(e instanceof Error ? e.message : String(e));
209
+ }
210
+ },
211
+ [data]
212
+ );
213
+ const loadIssue = useCallback(
214
+ async (key) => {
215
+ setError(null);
216
+ setIssue(null);
217
+ setScreen("detail");
218
+ try {
219
+ setIssue(await data.getIssue(key));
220
+ } catch (e) {
221
+ setError(e instanceof Error ? e.message : String(e));
222
+ }
223
+ },
224
+ [data]
225
+ );
226
+ useEffect(() => {
227
+ if (initialScreen === "detail" && initialKey) void loadIssue(initialKey);
228
+ else void loadList(false);
229
+ }, [initialScreen, initialKey, loadIssue, loadList]);
230
+ useInput3((input, key) => {
231
+ if (overlay.kind !== "none") return;
232
+ if (input === "q" || key.ctrl && input === "c") exit();
233
+ if (error && input === "r") {
234
+ if (screen === "issues") void loadList(showingAll);
235
+ else if (issue) void loadIssue(issue.key);
236
+ }
237
+ });
238
+ if (width < MIN_WIDTH || height < MIN_HEIGHT) {
239
+ return /* @__PURE__ */ jsxs3(Text3, { children: [
240
+ "Terminal too small \u2014 needs at least ",
241
+ MIN_WIDTH,
242
+ "\xD7",
243
+ MIN_HEIGHT,
244
+ ", this is",
245
+ " ",
246
+ width,
247
+ "\xD7",
248
+ height,
249
+ "."
250
+ ] });
251
+ }
252
+ if (error) {
253
+ return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", gap: 1, children: [
254
+ /* @__PURE__ */ jsx3(Alert, { variant: "error", children: error }),
255
+ /* @__PURE__ */ jsx3(Text3, { dimColor: true, children: "r retry \xB7 q quit" })
256
+ ] });
257
+ }
258
+ if (busy) return /* @__PURE__ */ jsx3(Spinner, { label: busy });
259
+ if (overlay.kind === "transition") {
260
+ return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", gap: 1, children: [
261
+ /* @__PURE__ */ jsxs3(Text3, { bold: true, children: [
262
+ "Move ",
263
+ issue?.key,
264
+ " to\u2026"
265
+ ] }),
266
+ /* @__PURE__ */ jsx3(
267
+ Select,
268
+ {
269
+ options: overlay.options.map((t) => ({
270
+ label: `${t.name} \u2192 ${t.to}`,
271
+ value: t.id
272
+ })),
273
+ onSubmit: (id) => {
274
+ setOverlay({ kind: "none" });
275
+ void (async () => {
276
+ setBusy("Transitioning\u2026");
277
+ try {
278
+ await data.transition(issue.key, id);
279
+ await loadIssue(issue.key);
280
+ } catch (e) {
281
+ setError(e instanceof Error ? e.message : String(e));
282
+ } finally {
283
+ setBusy(null);
284
+ }
285
+ })();
286
+ }
287
+ }
288
+ ),
289
+ /* @__PURE__ */ jsx3(Text3, { dimColor: true, children: "esc cancel" })
290
+ ] });
291
+ }
292
+ if (overlay.kind === "comment") {
293
+ return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", gap: 1, children: [
294
+ /* @__PURE__ */ jsxs3(Text3, { bold: true, children: [
295
+ "Comment on ",
296
+ issue?.key
297
+ ] }),
298
+ /* @__PURE__ */ jsx3(
299
+ TextInput,
300
+ {
301
+ placeholder: "Markdown is supported\u2026",
302
+ onSubmit: (body) => {
303
+ setOverlay({ kind: "none" });
304
+ if (!body.trim()) return;
305
+ void (async () => {
306
+ setBusy("Posting\u2026");
307
+ try {
308
+ await data.comment(issue.key, body);
309
+ await loadIssue(issue.key);
310
+ } catch (e) {
311
+ setError(e instanceof Error ? e.message : String(e));
312
+ } finally {
313
+ setBusy(null);
314
+ }
315
+ })();
316
+ }
317
+ }
318
+ )
319
+ ] });
320
+ }
321
+ if (overlay.kind === "assign") {
322
+ return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", gap: 1, children: [
323
+ /* @__PURE__ */ jsxs3(Text3, { children: [
324
+ "Assign ",
325
+ issue?.key,
326
+ " to yourself?"
327
+ ] }),
328
+ /* @__PURE__ */ jsx3(
329
+ ConfirmInput,
330
+ {
331
+ onCancel: () => setOverlay({ kind: "none" }),
332
+ onConfirm: () => {
333
+ setOverlay({ kind: "none" });
334
+ void (async () => {
335
+ setBusy("Assigning\u2026");
336
+ try {
337
+ await data.assignToMe(issue.key);
338
+ await loadIssue(issue.key);
339
+ } catch (e) {
340
+ setError(e instanceof Error ? e.message : String(e));
341
+ } finally {
342
+ setBusy(null);
343
+ }
344
+ })();
345
+ }
346
+ }
347
+ )
348
+ ] });
349
+ }
350
+ if (screen === "detail") {
351
+ if (!issue) return /* @__PURE__ */ jsx3(Spinner, { label: "Loading issue\u2026" });
352
+ return /* @__PURE__ */ jsx3(
353
+ IssueDetailView,
354
+ {
355
+ issue,
356
+ width,
357
+ height,
358
+ onBack: () => setScreen("issues"),
359
+ onOpenBrowser: () => execFile(opener(), [issue.url]),
360
+ onAssign: () => setOverlay({ kind: "assign" }),
361
+ onComment: () => setOverlay({ kind: "comment" }),
362
+ onTransition: () => {
363
+ void (async () => {
364
+ setBusy("Loading transitions\u2026");
365
+ try {
366
+ const options = await data.getTransitions(issue.key);
367
+ setOverlay({ kind: "transition", options });
368
+ } catch (e) {
369
+ setError(e instanceof Error ? e.message : String(e));
370
+ } finally {
371
+ setBusy(null);
372
+ }
373
+ })();
374
+ }
375
+ }
376
+ );
377
+ }
378
+ if (!rows) return /* @__PURE__ */ jsx3(Spinner, { label: "Loading issues\u2026" });
379
+ return /* @__PURE__ */ jsx3(
380
+ IssueList,
381
+ {
382
+ rows,
383
+ height,
384
+ showingAll,
385
+ onOpen: (key) => void loadIssue(key),
386
+ onRefresh: () => void loadList(showingAll),
387
+ onToggleAll: () => {
388
+ const next = !showingAll;
389
+ setShowingAll(next);
390
+ void loadList(next);
391
+ }
392
+ }
393
+ );
394
+ };
395
+ var opener = () => process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
396
+
397
+ // src/tui/data.ts
398
+ import { adfToMarkdown, locateAttachments } from "@kud/jira";
399
+ var OPEN_ONLY = "statusCategory != Done";
400
+ var toRow = (issue) => ({
401
+ key: issue.key,
402
+ status: issue.fields.status?.name ?? "\u2014",
403
+ summary: issue.fields.summary ?? "",
404
+ assignee: issue.fields.assignee?.displayName ?? "unassigned",
405
+ updated: issue.fields.updated?.slice(0, 10) ?? ""
406
+ });
407
+ var liveData = (ctx = context()) => ({
408
+ baseUrl: ctx.config.baseUrl,
409
+ listIssues: async (all) => {
410
+ const jql = `assignee = currentUser()${all ? "" : ` AND ${OPEN_ONLY}`} ORDER BY updated DESC`;
411
+ return (await ctx.client.searchIssues(jql, { limit: 200 })).map(toRow);
412
+ },
413
+ getIssue: async (key) => {
414
+ const issue = await ctx.client.getIssue(key);
415
+ const attachments = locateAttachments(issue);
416
+ const filenameOf = (id) => attachments.find((a) => a.id === id)?.filename;
417
+ const f = issue.fields;
418
+ return {
419
+ key: issue.key,
420
+ summary: f.summary ?? "",
421
+ status: f.status?.name ?? "\u2014",
422
+ type: f.issuetype?.name ?? "\u2014",
423
+ assignee: f.assignee?.displayName ?? "unassigned",
424
+ reporter: f.reporter?.displayName ?? "\u2014",
425
+ labels: f.labels ?? [],
426
+ url: `${ctx.config.baseUrl}/browse/${issue.key}`,
427
+ description: adfToMarkdown(f.description, filenameOf),
428
+ comments: (f.comment?.comments ?? []).map((c) => ({
429
+ id: c.id,
430
+ author: c.author?.displayName ?? "unknown",
431
+ created: c.created?.slice(0, 10) ?? "",
432
+ body: adfToMarkdown(c.body, filenameOf)
433
+ })),
434
+ attachments
435
+ };
436
+ },
437
+ getTransitions: async (key) => (await ctx.client.getTransitions(key)).transitions.map((t) => ({
438
+ id: t.id,
439
+ name: t.name,
440
+ to: t.to?.name ?? t.name
441
+ })),
442
+ transition: (key, transitionId) => ctx.client.transitionIssue(key, transitionId),
443
+ comment: async (key, body) => {
444
+ const { markdownToAdf } = await import("@kud/jira");
445
+ await ctx.client.addComment(key, markdownToAdf(body));
446
+ },
447
+ assignToMe: async (key) => {
448
+ const me = await ctx.client.getMe();
449
+ await ctx.client.assignIssue(key, me.accountId);
450
+ }
451
+ });
452
+
453
+ // src/tui/mock.ts
454
+ var ROWS = [
455
+ {
456
+ key: "SHOP-412",
457
+ status: "In Progress",
458
+ summary: "Checkout total ignores the discount on the last item",
459
+ assignee: "Ada Okafor",
460
+ updated: "2026-08-14"
461
+ },
462
+ {
463
+ key: "SHOP-408",
464
+ status: "In Review",
465
+ summary: "Add a dark theme to the storefront",
466
+ assignee: "Ada Okafor",
467
+ updated: "2026-08-13"
468
+ },
469
+ {
470
+ key: "SHOP-397",
471
+ status: "To Do",
472
+ summary: "Search returns stale results after a filter change",
473
+ assignee: "Ada Okafor",
474
+ updated: "2026-08-11"
475
+ },
476
+ {
477
+ key: "PLAT-88",
478
+ status: "Blocked",
479
+ summary: "Rotate the staging database credentials",
480
+ assignee: "Ada Okafor",
481
+ updated: "2026-08-09"
482
+ }
483
+ ];
484
+ var DETAIL = {
485
+ "SHOP-412": {
486
+ key: "SHOP-412",
487
+ summary: "Checkout total ignores the discount on the last item",
488
+ status: "In Progress",
489
+ type: "Bug",
490
+ assignee: "Ada Okafor",
491
+ reporter: "Bram Nilsen",
492
+ labels: ["checkout", "regression"],
493
+ url: "https://example.atlassian.net/browse/SHOP-412",
494
+ description: [
495
+ "## What happens",
496
+ "",
497
+ "The basket total is correct until the **last** line item, whose discount is",
498
+ "dropped from the sum.",
499
+ "",
500
+ "```js",
501
+ "const total = items.slice(0, -1).reduce(withDiscount, 0)",
502
+ "```",
503
+ "",
504
+ "1. Add three items",
505
+ "2. Apply `SUMMER20`",
506
+ "3. Compare the total against the line items",
507
+ "",
508
+ "[attachment: basket.png]"
509
+ ].join("\n"),
510
+ comments: [
511
+ {
512
+ id: "c1",
513
+ author: "Bram Nilsen",
514
+ created: "2026-08-13",
515
+ body: "Reproduced on staging. Screenshot attached.\n\n[attachment: basket.png]"
516
+ },
517
+ {
518
+ id: "c2",
519
+ author: "Ada Okafor",
520
+ created: "2026-08-14",
521
+ body: "Off-by-one in `slice(0, -1)`. Fix and a regression test on the way."
522
+ }
523
+ ],
524
+ attachments: [
525
+ {
526
+ id: "9001",
527
+ filename: "basket.png",
528
+ mimeType: "image/png",
529
+ size: 48213,
530
+ origins: [{ kind: "comment", commentId: "c1", author: "Bram Nilsen" }]
531
+ },
532
+ {
533
+ id: "9002",
534
+ filename: "checkout.log",
535
+ mimeType: "text/plain",
536
+ size: 2044,
537
+ origins: [{ kind: "issue" }]
538
+ }
539
+ ]
540
+ }
541
+ };
542
+ var fallbackDetail = (key) => {
543
+ const row = ROWS.find((r) => r.key === key) ?? ROWS[0];
544
+ return {
545
+ key: row.key,
546
+ summary: row.summary,
547
+ status: row.status,
548
+ type: "Task",
549
+ assignee: row.assignee,
550
+ reporter: "Bram Nilsen",
551
+ labels: [],
552
+ url: `https://example.atlassian.net/browse/${row.key}`,
553
+ description: "_No description._",
554
+ comments: [],
555
+ attachments: []
556
+ };
557
+ };
558
+ var mockData = () => ({
559
+ baseUrl: "https://example.atlassian.net",
560
+ listIssues: async (all) => all ? ROWS : ROWS.filter((r) => r.status !== "Done"),
561
+ getIssue: async (key) => DETAIL[key] ?? fallbackDetail(key),
562
+ getTransitions: async () => [
563
+ { id: "11", name: "Start progress", to: "In Progress" },
564
+ { id: "21", name: "Ready for review", to: "In Review" },
565
+ { id: "31", name: "Done", to: "Done" }
566
+ ],
567
+ transition: async () => {
568
+ },
569
+ comment: async () => {
570
+ },
571
+ assignToMe: async () => {
572
+ }
573
+ });
574
+
575
+ // src/tui/index.tsx
576
+ import { jsx as jsx4 } from "react/jsx-runtime";
577
+ var SCREENS = ["issues", "detail"];
578
+ var runTui = async ({
579
+ screen,
580
+ mock,
581
+ issueKey
582
+ }) => {
583
+ const data = mock ? mockData() : liveData();
584
+ const key = issueKey ?? (mock ? "SHOP-412" : void 0);
585
+ const { waitUntilExit } = render(
586
+ /* @__PURE__ */ jsx4(App, { data, initialScreen: screen, initialKey: key })
587
+ );
588
+ await waitUntilExit();
589
+ };
590
+ export {
591
+ SCREENS,
592
+ runTui
593
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/jira-cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Jira on the command line — read issues, comments and attachments as plain text",
6
6
  "keywords": [
@@ -37,11 +37,18 @@
37
37
  "prepublishOnly": "npm run build"
38
38
  },
39
39
  "dependencies": {
40
- "@kud/jira": "0.1.0",
41
- "commander": "14.0.1"
40
+ "@kud/ink-markdown": "0.1.1",
41
+ "@kud/ink-ui": "0.14.1",
42
+ "@kud/jira": "0.2.0",
43
+ "commander": "14.0.1",
44
+ "ink": "7.0.1",
45
+ "react": "19.2.5"
42
46
  },
43
47
  "devDependencies": {
48
+ "@kud/cli-testing": "0.1.0",
44
49
  "@types/node": "24.10.1",
50
+ "@types/react": "19.2.7",
51
+ "ink-testing-library": "4.0.0",
45
52
  "tsup": "8.5.0",
46
53
  "tsx": "4.20.6",
47
54
  "typescript": "5.9.3",