@pecot/workflow-mcp 0.0.0-stage → 6.0.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.
Files changed (287) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +184 -2
  4. package/bin/pecot-workflow-mcp.mjs +10 -0
  5. package/cli/dist/cli.d.ts +26 -0
  6. package/cli/dist/cli.js +227 -0
  7. package/cli/dist/commands/board-add.d.ts +3 -0
  8. package/cli/dist/commands/board-add.js +59 -0
  9. package/cli/dist/commands/board-judgment.d.ts +60 -0
  10. package/cli/dist/commands/board-judgment.js +144 -0
  11. package/cli/dist/commands/board-move.d.ts +3 -0
  12. package/cli/dist/commands/board-move.js +57 -0
  13. package/cli/dist/commands/board-readiness.d.ts +34 -0
  14. package/cli/dist/commands/board-readiness.js +108 -0
  15. package/cli/dist/commands/board-show.d.ts +3 -0
  16. package/cli/dist/commands/board-show.js +72 -0
  17. package/cli/dist/commands/board-sync.d.ts +3 -0
  18. package/cli/dist/commands/board-sync.js +111 -0
  19. package/cli/dist/commands/board-view.d.ts +62 -0
  20. package/cli/dist/commands/board-view.js +191 -0
  21. package/cli/dist/commands/board.d.ts +3 -0
  22. package/cli/dist/commands/board.js +12 -0
  23. package/cli/dist/commands/branch.d.ts +3 -0
  24. package/cli/dist/commands/branch.js +100 -0
  25. package/cli/dist/commands/cell-table.d.ts +3 -0
  26. package/cli/dist/commands/cell-table.js +495 -0
  27. package/cli/dist/commands/command-binding.d.ts +26 -0
  28. package/cli/dist/commands/command-binding.js +270 -0
  29. package/cli/dist/commands/command-definition.d.ts +150 -0
  30. package/cli/dist/commands/command-definition.js +105 -0
  31. package/cli/dist/commands/command-help.d.ts +8 -0
  32. package/cli/dist/commands/command-help.js +173 -0
  33. package/cli/dist/commands/command-hint.d.ts +5 -0
  34. package/cli/dist/commands/command-hint.js +13 -0
  35. package/cli/dist/commands/command-stop.d.ts +21 -0
  36. package/cli/dist/commands/command-stop.js +31 -0
  37. package/cli/dist/commands/directory-option.d.ts +7 -0
  38. package/cli/dist/commands/directory-option.js +48 -0
  39. package/cli/dist/commands/failure-kind.d.ts +3 -0
  40. package/cli/dist/commands/failure-kind.js +34 -0
  41. package/cli/dist/commands/failure.d.ts +19 -0
  42. package/cli/dist/commands/failure.js +59 -0
  43. package/cli/dist/commands/fuzzy.d.ts +7 -0
  44. package/cli/dist/commands/fuzzy.js +79 -0
  45. package/cli/dist/commands/github-client.d.ts +16 -0
  46. package/cli/dist/commands/github-client.js +33 -0
  47. package/cli/dist/commands/global-options.d.ts +25 -0
  48. package/cli/dist/commands/global-options.js +83 -0
  49. package/cli/dist/commands/help-layout.d.ts +40 -0
  50. package/cli/dist/commands/help-layout.js +117 -0
  51. package/cli/dist/commands/help.d.ts +8 -0
  52. package/cli/dist/commands/help.js +50 -0
  53. package/cli/dist/commands/input-schema.d.ts +14 -0
  54. package/cli/dist/commands/input-schema.js +56 -0
  55. package/cli/dist/commands/issue-board.d.ts +71 -0
  56. package/cli/dist/commands/issue-board.js +122 -0
  57. package/cli/dist/commands/issue-comment.d.ts +3 -0
  58. package/cli/dist/commands/issue-comment.js +215 -0
  59. package/cli/dist/commands/issue-create.d.ts +3 -0
  60. package/cli/dist/commands/issue-create.js +786 -0
  61. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  62. package/cli/dist/commands/issue-dependency.js +282 -0
  63. package/cli/dist/commands/issue-readiness.d.ts +94 -0
  64. package/cli/dist/commands/issue-readiness.js +218 -0
  65. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  66. package/cli/dist/commands/issue-reopen.js +115 -0
  67. package/cli/dist/commands/issue-shared.d.ts +172 -0
  68. package/cli/dist/commands/issue-shared.js +426 -0
  69. package/cli/dist/commands/issue-show.d.ts +3 -0
  70. package/cli/dist/commands/issue-show.js +169 -0
  71. package/cli/dist/commands/issue.d.ts +3 -0
  72. package/cli/dist/commands/issue.js +13 -0
  73. package/cli/dist/commands/names.d.ts +42 -0
  74. package/cli/dist/commands/names.js +78 -0
  75. package/cli/dist/commands/output.d.ts +90 -0
  76. package/cli/dist/commands/output.js +194 -0
  77. package/cli/dist/commands/pr-waiting.d.ts +20 -0
  78. package/cli/dist/commands/pr-waiting.js +106 -0
  79. package/cli/dist/commands/pr.d.ts +22 -0
  80. package/cli/dist/commands/pr.js +852 -0
  81. package/cli/dist/commands/project-sync.d.ts +92 -0
  82. package/cli/dist/commands/project-sync.js +282 -0
  83. package/cli/dist/commands/project.d.ts +6 -0
  84. package/cli/dist/commands/project.js +714 -0
  85. package/cli/dist/commands/registry.d.ts +6 -0
  86. package/cli/dist/commands/registry.js +30 -0
  87. package/cli/dist/commands/release.d.ts +10 -0
  88. package/cli/dist/commands/release.js +353 -0
  89. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  90. package/cli/dist/commands/renamed-commands.js +53 -0
  91. package/cli/dist/commands/repository-display.d.ts +3 -0
  92. package/cli/dist/commands/repository-display.js +7 -0
  93. package/cli/dist/commands/repository-match.d.ts +14 -0
  94. package/cli/dist/commands/repository-match.js +34 -0
  95. package/cli/dist/commands/rich-panel.d.ts +22 -0
  96. package/cli/dist/commands/rich-panel.js +295 -0
  97. package/cli/dist/commands/session-finish.d.ts +3 -0
  98. package/cli/dist/commands/session-finish.js +267 -0
  99. package/cli/dist/commands/session-start.d.ts +3 -0
  100. package/cli/dist/commands/session-start.js +236 -0
  101. package/cli/dist/commands/session.d.ts +6 -0
  102. package/cli/dist/commands/session.js +214 -0
  103. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  104. package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
  105. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  106. package/cli/dist/commands/tracker-sync-security.js +153 -0
  107. package/cli/dist/commands/tracker-sync.d.ts +65 -0
  108. package/cli/dist/commands/tracker-sync.js +50 -0
  109. package/cli/dist/commands/tracker.d.ts +3 -0
  110. package/cli/dist/commands/tracker.js +18 -0
  111. package/cli/dist/commands/usage-error.d.ts +51 -0
  112. package/cli/dist/commands/usage-error.js +78 -0
  113. package/cli/dist/commands/value-types.d.ts +46 -0
  114. package/cli/dist/commands/value-types.js +94 -0
  115. package/cli/dist/commands/work-target.d.ts +22 -0
  116. package/cli/dist/commands/work-target.js +82 -0
  117. package/cli/dist/commands/worktree.d.ts +3 -0
  118. package/cli/dist/commands/worktree.js +339 -0
  119. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  120. package/cli/dist/domain/api-error-detail.js +25 -0
  121. package/cli/dist/domain/batch-plan.d.ts +73 -0
  122. package/cli/dist/domain/batch-plan.js +114 -0
  123. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  124. package/cli/dist/domain/blocked-by-change.js +101 -0
  125. package/cli/dist/domain/board-move.d.ts +90 -0
  126. package/cli/dist/domain/board-move.js +92 -0
  127. package/cli/dist/domain/branch-name.d.ts +5 -0
  128. package/cli/dist/domain/branch-name.js +10 -0
  129. package/cli/dist/domain/changelog.d.ts +43 -0
  130. package/cli/dist/domain/changelog.js +107 -0
  131. package/cli/dist/domain/command-hint.d.ts +85 -0
  132. package/cli/dist/domain/command-hint.js +148 -0
  133. package/cli/dist/domain/config.d.ts +219 -0
  134. package/cli/dist/domain/config.js +310 -0
  135. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  136. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  137. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  138. package/cli/dist/domain/dependabot-source.js +4 -0
  139. package/cli/dist/domain/dependabot.d.ts +47 -0
  140. package/cli/dist/domain/dependabot.js +88 -0
  141. package/cli/dist/domain/errors.d.ts +24 -0
  142. package/cli/dist/domain/errors.js +36 -0
  143. package/cli/dist/domain/field-options.d.ts +31 -0
  144. package/cli/dist/domain/field-options.js +44 -0
  145. package/cli/dist/domain/format.d.ts +94 -0
  146. package/cli/dist/domain/format.js +234 -0
  147. package/cli/dist/domain/frontmatter.d.ts +137 -0
  148. package/cli/dist/domain/frontmatter.js +290 -0
  149. package/cli/dist/domain/git-runner.d.ts +10 -0
  150. package/cli/dist/domain/git-runner.js +4 -0
  151. package/cli/dist/domain/git-url.d.ts +17 -0
  152. package/cli/dist/domain/git-url.js +30 -0
  153. package/cli/dist/domain/issue-kind.d.ts +16 -0
  154. package/cli/dist/domain/issue-kind.js +16 -0
  155. package/cli/dist/domain/issue-order.d.ts +55 -0
  156. package/cli/dist/domain/issue-order.js +65 -0
  157. package/cli/dist/domain/issue-readout.d.ts +143 -0
  158. package/cli/dist/domain/issue-readout.js +4 -0
  159. package/cli/dist/domain/json-null.d.ts +2 -0
  160. package/cli/dist/domain/json-null.js +5 -0
  161. package/cli/dist/domain/json.d.ts +21 -0
  162. package/cli/dist/domain/json.js +47 -0
  163. package/cli/dist/domain/prerequisites.d.ts +32 -0
  164. package/cli/dist/domain/prerequisites.js +192 -0
  165. package/cli/dist/domain/pull-request.d.ts +201 -0
  166. package/cli/dist/domain/pull-request.js +281 -0
  167. package/cli/dist/domain/python-format.d.ts +105 -0
  168. package/cli/dist/domain/python-format.js +304 -0
  169. package/cli/dist/domain/readiness.d.ts +199 -0
  170. package/cli/dist/domain/readiness.js +391 -0
  171. package/cli/dist/domain/reference-parser.d.ts +51 -0
  172. package/cli/dist/domain/reference-parser.js +123 -0
  173. package/cli/dist/domain/release.d.ts +53 -0
  174. package/cli/dist/domain/release.js +65 -0
  175. package/cli/dist/domain/repository-policy.d.ts +38 -0
  176. package/cli/dist/domain/repository-policy.js +66 -0
  177. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  178. package/cli/dist/domain/repository-resolver.js +122 -0
  179. package/cli/dist/domain/sections.d.ts +69 -0
  180. package/cli/dist/domain/sections.js +514 -0
  181. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  182. package/cli/dist/domain/security-alerts-source.js +4 -0
  183. package/cli/dist/domain/security-alerts.d.ts +52 -0
  184. package/cli/dist/domain/security-alerts.js +107 -0
  185. package/cli/dist/domain/security-tracker.d.ts +115 -0
  186. package/cli/dist/domain/security-tracker.js +353 -0
  187. package/cli/dist/domain/state.d.ts +59 -0
  188. package/cli/dist/domain/state.js +95 -0
  189. package/cli/dist/domain/tracker-body.d.ts +70 -0
  190. package/cli/dist/domain/tracker-body.js +65 -0
  191. package/cli/dist/domain/work-start.d.ts +34 -0
  192. package/cli/dist/domain/work-start.js +49 -0
  193. package/cli/dist/domain/yaml-document.d.ts +5 -0
  194. package/cli/dist/domain/yaml-document.js +206 -0
  195. package/cli/dist/infra/authored-notes.d.ts +37 -0
  196. package/cli/dist/infra/authored-notes.js +72 -0
  197. package/cli/dist/infra/changelog-file.d.ts +19 -0
  198. package/cli/dist/infra/changelog-file.js +43 -0
  199. package/cli/dist/infra/child-stdin.d.ts +4 -0
  200. package/cli/dist/infra/child-stdin.js +8 -0
  201. package/cli/dist/infra/config-store.d.ts +53 -0
  202. package/cli/dist/infra/config-store.js +134 -0
  203. package/cli/dist/infra/diagnostics.d.ts +9 -0
  204. package/cli/dist/infra/diagnostics.js +2 -0
  205. package/cli/dist/infra/file-kind.d.ts +9 -0
  206. package/cli/dist/infra/file-kind.js +26 -0
  207. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  208. package/cli/dist/infra/frontmatter-file.js +30 -0
  209. package/cli/dist/infra/git.d.ts +86 -0
  210. package/cli/dist/infra/git.js +145 -0
  211. package/cli/dist/infra/github/auth.d.ts +60 -0
  212. package/cli/dist/infra/github/auth.js +158 -0
  213. package/cli/dist/infra/github/client.d.ts +178 -0
  214. package/cli/dist/infra/github/client.js +579 -0
  215. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  216. package/cli/dist/infra/github/dependabot-source.js +33 -0
  217. package/cli/dist/infra/github/errors.d.ts +65 -0
  218. package/cli/dist/infra/github/errors.js +64 -0
  219. package/cli/dist/infra/github/index.d.ts +13 -0
  220. package/cli/dist/infra/github/index.js +19 -0
  221. package/cli/dist/infra/github/issues.d.ts +165 -0
  222. package/cli/dist/infra/github/issues.js +428 -0
  223. package/cli/dist/infra/github/payload.d.ts +44 -0
  224. package/cli/dist/infra/github/payload.js +80 -0
  225. package/cli/dist/infra/github/projects.d.ts +143 -0
  226. package/cli/dist/infra/github/projects.js +384 -0
  227. package/cli/dist/infra/github/pulls.d.ts +104 -0
  228. package/cli/dist/infra/github/pulls.js +217 -0
  229. package/cli/dist/infra/github/queries.d.ts +44 -0
  230. package/cli/dist/infra/github/queries.js +1031 -0
  231. package/cli/dist/infra/github/readout.d.ts +22 -0
  232. package/cli/dist/infra/github/readout.js +167 -0
  233. package/cli/dist/infra/github/repos.d.ts +86 -0
  234. package/cli/dist/infra/github/repos.js +168 -0
  235. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  236. package/cli/dist/infra/github/rest-path.js +31 -0
  237. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  238. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  239. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  240. package/cli/dist/infra/gitignore-spec.js +235 -0
  241. package/cli/dist/infra/nx-scope.d.ts +51 -0
  242. package/cli/dist/infra/nx-scope.js +182 -0
  243. package/cli/dist/infra/os-error.d.ts +24 -0
  244. package/cli/dist/infra/os-error.js +38 -0
  245. package/cli/dist/infra/paths.d.ts +88 -0
  246. package/cli/dist/infra/paths.js +234 -0
  247. package/cli/dist/infra/state-store.d.ts +54 -0
  248. package/cli/dist/infra/state-store.js +130 -0
  249. package/cli/dist/infra/template-store.d.ts +15 -0
  250. package/cli/dist/infra/template-store.js +34 -0
  251. package/cli/dist/infra/text-file.d.ts +12 -0
  252. package/cli/dist/infra/text-file.js +33 -0
  253. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  254. package/cli/dist/infra/worktree-copy.js +95 -0
  255. package/cli/dist/infra/worktree-links.d.ts +142 -0
  256. package/cli/dist/infra/worktree-links.js +440 -0
  257. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  258. package/cli/dist/infra/worktree-setup.js +41 -0
  259. package/cli/dist/infra/worktree.d.ts +185 -0
  260. package/cli/dist/infra/worktree.js +584 -0
  261. package/cli/dist/mcp/result.d.ts +61 -0
  262. package/cli/dist/mcp/result.js +96 -0
  263. package/cli/dist/mcp/serve.d.ts +51 -0
  264. package/cli/dist/mcp/serve.js +183 -0
  265. package/cli/dist/mcp/server.d.ts +21 -0
  266. package/cli/dist/mcp/server.js +142 -0
  267. package/cli/dist/mcp/session-directory.d.ts +26 -0
  268. package/cli/dist/mcp/session-directory.js +84 -0
  269. package/cli/dist/package.json +1 -0
  270. package/cli/dist/version.d.ts +17 -0
  271. package/cli/dist/version.js +42 -0
  272. package/cli/templates/comment/merge-diff.md +34 -0
  273. package/cli/templates/comment/plan.md +195 -0
  274. package/cli/templates/comment/precede-notify.md +33 -0
  275. package/cli/templates/comment/review-findings.md +42 -0
  276. package/cli/templates/comment/review-resolution.md +48 -0
  277. package/cli/templates/issue/bug.md +63 -0
  278. package/cli/templates/issue/epic.md +54 -0
  279. package/cli/templates/issue/task-implement.md +74 -0
  280. package/cli/templates/issue/task.md +48 -0
  281. package/cli/templates/issue/tracker.md +48 -0
  282. package/cli/templates/pr/create.md +123 -0
  283. package/cli/templates/pr/release.md +56 -0
  284. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  285. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  286. package/npm-shrinkwrap.json +83 -0
  287. package/package.json +22 -4
@@ -0,0 +1,426 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ // issue 系のコマンドが共有する関数と定数。cli/commands/issue.py の移植。
3
+ // typer.Exit(n) に当たるのは、error の行を出して止める stopWith(output, 文, n)。
4
+ // 行を別の関数が先に出した後は、throw new CommandExit(n) で止める。
5
+ // BadParameter は、run の本体を包む runWithExit が受ける。
6
+ import path from 'node:path';
7
+ import { z } from 'zod';
8
+ import { aggregationRepositoryReference, isRepositoryInProject } from '../domain/config.js';
9
+ import { formatHinted } from '../domain/command-hint.js';
10
+ import { BaseError } from '../domain/errors.js';
11
+ import { CommandExit } from './command-definition.js';
12
+ import { planOrders, usedOrdersOf } from '../domain/issue-order.js';
13
+ import { pythonStrip } from '../domain/python-format.js';
14
+ import { issueReferenceToCliReference, parseIssueReference, ReferenceParseError } from '../domain/reference-parser.js';
15
+ import { AmbiguousRepositoryError, createRepositoryReference, resolveRepository } from '../domain/repository-resolver.js';
16
+ import { CLOSED_HEADINGS_BY_TEMPLATE, FOLD_SUMMARY_BY_TEMPLATE, validateBodyStyle, validateClosedHeadings, validateFoldBalance, validateFoldSummaries, validateHeadingSummaries, validateSections, } from '../domain/sections.js';
17
+ import { gitRunnerFor } from '../infra/git.js';
18
+ import { GitHubAPIError } from '../infra/github/errors.js';
19
+ import { requireNumber, requireString } from '../infra/github/payload.js';
20
+ import { readTemplateSections, templateFile } from '../infra/template-store.js';
21
+ import { commandHint, hinted, inputHint, inputNameHint } from './command-hint.js';
22
+ import { stopWith } from './command-stop.js';
23
+ import { kindOfFailure } from './failure.js';
24
+ import { createGitHubClient } from './github-client.js';
25
+ import { addIssueToBoard, createIssue, setIssueField } from './issue-board.js';
26
+ import { USAGE_EXIT_CODE, UsageError } from './usage-error.js';
27
+ // Epic を作るコマンド。作成先の案内に使う
28
+ const EPIC_CREATE_PATH = ['issue', 'create'];
29
+ /**
30
+ issue comment のテンプレ検証失敗の終了コード。通信失敗・設定なし・引数不足の 1 と区別し、hooks がこの値で分岐する
31
+ */
32
+ export const COMMENT_VALIDATION_EXIT_CODE = 3;
33
+ /**
34
+ Issue 種別の入力。issue create が使う
35
+ */
36
+ export const ISSUE_TYPE_SCHEMA = z.enum(['task', 'bug', 'epic', 'tracker']).default('task').describe('Issue type (task/bug/epic/tracker)');
37
+ export const PARENT_EPIC_DESCRIPTION = 'Parent Epic reference: an integer (relative to aggregation_repo) or the primary form \'owner/repo/N\'';
38
+ export const ISSUE_REF_DESCRIPTION = 'Issue reference (`owner/repo/N`, or the short form `N` in the repository of `--repo`, or else of the git remote of the current directory)';
39
+ export const VALID_STATUSES = new Set(['backlog', 'pending', 'blocked', 'ready', 'active', 'in_review', 'archived']);
40
+ /**
41
+ Issue 種別 → タイトルの接頭辞
42
+ */
43
+ const TYPE_PREFIX_MAP = new Map([
44
+ ['task', '[Task]'],
45
+ ['bug', '[Bug]'],
46
+ ['epic', '[Epic]'],
47
+ ['tracker', '[Tracker]'],
48
+ ]);
49
+ /**
50
+ 起票時の status は、型対応テンプレートの既定値だけを受ける。pending / archived への配置はボード上の手動操作
51
+ */
52
+ export const TYPE_DEFAULT_STATUS = { epic: 'backlog', tracker: 'backlog', task: 'ready', bug: 'ready' };
53
+ /**
54
+ Backlog に置く型(freeform の size と quick-mode フラグの扱いが Epic と同じ)
55
+ */
56
+ export const BACKLOG_TYPES = new Set(['epic', 'tracker']);
57
+ // --- 終了の表し方 ---
58
+ /**
59
+ 引数の値が不正。Python の typer.BadParameter。呼ぶ側が受けない場合は、runWithExit が使い方の誤り(終了コード 2)にする
60
+ */
61
+ class BadParameterError extends BaseError {
62
+ text;
63
+ // message は CLI の形。text は出し先の形で描き直すために持つ
64
+ constructor(text) {
65
+ super(formatHinted(text, 'cli'));
66
+ this.text = text;
67
+ }
68
+ }
69
+ /**
70
+ run の本体を包む。終わったら 0 を返す。BadParameterError は使い方の誤りにして伝える。
71
+ それ以外の例外はそのまま伝える。CommandExit は defineCommand が受けて終了コードにする
72
+ */
73
+ export async function runWithExit(body) {
74
+ try {
75
+ await body();
76
+ return 0;
77
+ }
78
+ catch (error) {
79
+ if (error instanceof BadParameterError)
80
+ throw new UsageError(`Invalid value: ${error.message}`);
81
+ throw error;
82
+ }
83
+ }
84
+ // --- Issue 参照 ---
85
+ /**
86
+ `owner/repo/N` の表記。エラー文と done の行の対象に使う
87
+ */
88
+ export function issuePath(owner, repository, number) {
89
+ return `${owner}/${repository}/${String(number)}`;
90
+ }
91
+ /**
92
+ グローバルの --repo(run の入力の repo)か、カレントの git から base のリポジトリを決める。
93
+ 曖昧なら undefined(`owner/repo/N` の主軸形を使う利用者のため)。--repo の形式が不正なら InvalidValueError を伝える
94
+ */
95
+ function resolveBaseRepository(repository) {
96
+ try {
97
+ return resolveRepository(repository, gitRunnerFor()).repository;
98
+ }
99
+ catch (error) {
100
+ if (error instanceof AmbiguousRepositoryError)
101
+ return undefined;
102
+ throw error;
103
+ }
104
+ }
105
+ /**
106
+ Issue 参照(`owner/repo/N` または短縮形 `N`)を分ける。不正、または base が決まらない短縮形なら BadParameterError
107
+ */
108
+ function parseIssueReferenceFromContext(repository, raw) {
109
+ const base = resolveBaseRepository(repository);
110
+ try {
111
+ const reference = parseIssueReference(raw, base, { repositoryFlag: true });
112
+ return { owner: reference.repository.owner, repository: reference.repository.repository, number: reference.number };
113
+ }
114
+ catch (error) {
115
+ if (error instanceof ReferenceParseError)
116
+ throw new BadParameterError(error.hintedText ?? error.message);
117
+ throw error;
118
+ }
119
+ }
120
+ /**
121
+ parseIssueReferenceFromContext の失敗を、error の行と終了コード 2 にしたもの
122
+ */
123
+ export function parseIssueReferenceOrExit(output, repository, raw) {
124
+ try {
125
+ return parseIssueReferenceFromContext(repository, raw);
126
+ }
127
+ catch (error) {
128
+ if (!(error instanceof BadParameterError))
129
+ throw error;
130
+ return stopWith(output, error.text, 'invalid-input', USAGE_EXIT_CODE);
131
+ }
132
+ }
133
+ // --- status ---
134
+ /**
135
+ 不正な status と、有効な値を出して終了コード 1
136
+ */
137
+ export function exitInvalidStatus(output, status) {
138
+ return stopWith(output, `invalid status: ${status}\nvalid values: backlog/pending/blocked/ready/active/in_review/archived`, 'invalid-input');
139
+ }
140
+ /**
141
+ 起票時の status が、許す値のどれかと一致するか確かめる。違えば終了コード 1。許す値の既定は、型対応テンプレートの既定値だけ。
142
+ enum 外の値(`--status foo`)と、許さない値(`--type bug --status backlog`)は文を分ける
143
+ */
144
+ export function validateStatusForType(output, issueType, status, allowed) {
145
+ if (!VALID_STATUSES.has(status))
146
+ exitInvalidStatus(output, status);
147
+ // eslint-disable-next-line security/detect-object-injection -- issueType は列挙型
148
+ const accepted = allowed ?? [TYPE_DEFAULT_STATUS[issueType]];
149
+ if (accepted.includes(status))
150
+ return;
151
+ stopWith(output, `the status at creation for type '${issueType}' is only ${accepted.map(value => `'${value}'`).join(' or ')} (given: ${status})\nhint: move it to pending or another status on the board after creation`, 'invalid-input');
152
+ }
153
+ // --- parent_epic・タイトル・order ---
154
+ /**
155
+ CLI のオプションで来た parent_epic。空・空白だけなら undefined、数字だけなら整数(安全な整数を超えるなら数字の文字列)、それ以外は文字列
156
+ */
157
+ export function normalizeParentEpicCli(raw) {
158
+ if (raw === undefined)
159
+ return undefined;
160
+ const stripped = pythonStrip(raw);
161
+ if (stripped === '')
162
+ return undefined;
163
+ if (!/^\d+$/u.test(stripped))
164
+ return stripped;
165
+ const value = Number(stripped);
166
+ // 安全な整数に収まらない数字は、丸めずに文字列のまま返す(先頭の 0 は Python の int() と同じく落とす)
167
+ return Number.isSafeInteger(value) ? value : stripped.replace(/^0+(?=\d)/u, '');
168
+ }
169
+ /**
170
+ parent_epic を Issue 参照にする。整数は aggregation_repo の Issue(未設定なら task のリポジトリ)、`owner/repo/N` はそのまま。
171
+ 解決できなければ BadParameterError。番号が安全な整数を超える参照は、丸めずに解決できない参照として扱う
172
+ */
173
+ export function resolveParentEpicReference(raw, config, taskOwner, taskRepository) {
174
+ const base = aggregationRepositoryReference(config) ?? createRepositoryReference(taskOwner, taskRepository);
175
+ try {
176
+ if (typeof raw === 'string' && /^\d+$/u.test(raw) && !Number.isSafeInteger(Number(raw))) {
177
+ throw new ReferenceParseError(`the number is too large: ${raw}`, raw);
178
+ }
179
+ return parseIssueReference(String(raw), base);
180
+ }
181
+ catch (error) {
182
+ if (!(error instanceof ReferenceParseError))
183
+ throw error;
184
+ throw new BadParameterError(`could not resolve parent_epic: ${error.message}\naccepted forms: an integer (Issue number in aggregation_repo) or the primary form 'owner/repo/N'`);
185
+ }
186
+ }
187
+ /**
188
+ Epic を作るリポジトリを、aggregation_repo の方針で決める。
189
+ repository が空で aggregation_repo も未設定なら、決められないので終了コード 2
190
+ */
191
+ export function resolveEpicTargetRepository(output, repository, config) {
192
+ const stripped = repository === undefined ? '' : pythonStrip(repository);
193
+ const explicit = stripped === '' ? undefined : stripped;
194
+ const aggregation = config.aggregation_repo;
195
+ if (explicit === undefined) {
196
+ if (aggregation === undefined) {
197
+ stopWith(output, hinted `cannot decide where to create the Epic\ndeclare aggregation_repo in the project config, or pass ${inputNameHint(EPIC_CREATE_PATH, 'repo')}`, 'repo-setting-missing', USAGE_EXIT_CODE);
198
+ }
199
+ return { repository: aggregation, needsWarning: false };
200
+ }
201
+ return { repository: explicit, needsWarning: aggregation !== undefined && explicit !== aggregation };
202
+ }
203
+ /**
204
+ Epic の作成先が aggregation_repo と違うときの警告
205
+ */
206
+ export function warnEpicRepositoryException(output, resolvedRepository, config) {
207
+ output.warning(hinted `${inputHint(EPIC_CREATE_PATH, 'repo', resolvedRepository)} differs from aggregation_repo (${String(config.aggregation_repo)})\ncontinuing as an exception for an Epic in an implementation repo`);
208
+ }
209
+ /**
210
+ タイトルに接頭辞と、Epic 番号・order を付ける。例は `[Task] #353-04: タイトル`
211
+ */
212
+ export function buildIssueTitle(issueType, title, options = {}) {
213
+ const prefix = TYPE_PREFIX_MAP.get(issueType) ?? '';
214
+ const hasPrefix = prefix !== '' && title.startsWith(prefix);
215
+ const baseTitle = hasPrefix ? pythonStrip(title.slice(prefix.length)) : title;
216
+ if (options.parentEpic !== undefined && options.order !== undefined) {
217
+ const number = `#${String(options.parentEpic)}-${orderLabel(options.order)}`;
218
+ return prefix === '' ? `${number}: ${baseTitle}` : `${prefix} ${number}: ${baseTitle}`;
219
+ }
220
+ return prefix === '' || hasPrefix ? title : `${prefix} ${title}`;
221
+ }
222
+ /**
223
+ タイトルの番号。2 桁にそろえる
224
+ */
225
+ function orderLabel(order) {
226
+ return String(order).padStart(2, '0');
227
+ }
228
+ /**
229
+ 親 Epic のサブ Issue から、使われた番号を読む。全件を読む。Epic を取れなければ warning を出して undefined
230
+ */
231
+ export async function readUsedOrders(output, client, owner, repository, parentEpic) {
232
+ try {
233
+ return usedOrdersOf(await client.getAllSubIssues(owner, repository, parentEpic), parentEpic);
234
+ }
235
+ catch (error) {
236
+ if (!(error instanceof GitHubAPIError))
237
+ throw error;
238
+ output.warning(`could not fetch the parent Epic #${String(parentEpic)}: ${error.message}`);
239
+ return undefined;
240
+ }
241
+ }
242
+ /**
243
+ 明示の order が既存の Issue と重なったときの error を出して終了コード 1。一度使った番号は、OPEN でも CLOSED でも再利用できない
244
+ */
245
+ export function stopForDuplicateOrder(output, parentEpic, order, existing, nextAvailable) {
246
+ const stateLabel = existing.state === 'OPEN' ? 'OPEN' : 'CLOSED';
247
+ return stopWith(output, `Epic #${String(parentEpic)} already has an Issue with order=${String(order)} (${stateLabel})\n#${String(existing.number)} ${existing.title}\nnext available order: ${String(nextAvailable)}`, 'order-conflict');
248
+ }
249
+ /**
250
+ 同じ Epic に、同じ order の Issue が無いことを確かめる。最初の一致を error にして終了コード 1。Epic を取れなければ warning だけで続ける
251
+ */
252
+ export async function checkDuplicateOrder(output, client, owner, repository, parentEpic, order) {
253
+ const used = await readUsedOrders(output, client, owner, repository, parentEpic);
254
+ if (used === undefined)
255
+ return;
256
+ const plan = planOrders(used, [{ file: '', order }]);
257
+ if (plan.kind === 'duplicate-existing')
258
+ stopForDuplicateOrder(output, parentEpic, order, plan.existing, plan.nextAvailable);
259
+ }
260
+ // --- Issue の作成・ボード・親 Epic ---
261
+ /**
262
+ Issue を作り、`created:` の行を出して API の応答を返す。失敗は error の行と終了コード 1。
263
+ source は作成元のファイル名(`from <source>` として行の末尾に付く)
264
+ */
265
+ export async function createIssueOrExit(output, client, owner, repository, title, body, labels, source) {
266
+ let issue;
267
+ try {
268
+ issue = await createIssue(client, owner, repository, title, body, labels);
269
+ }
270
+ catch (error) {
271
+ if (!(error instanceof GitHubAPIError))
272
+ throw error;
273
+ return stopWith(output, `could not create an Issue in ${owner}/${repository}: ${error.message}`, kindOfFailure(error));
274
+ }
275
+ const target = `Issue ${issuePath(owner, repository, requireNumber(issue['number'], 'number'))}`;
276
+ output.done({ verb: 'create', target: source === undefined || source === '' ? target : `${target} from ${source}` });
277
+ return issue;
278
+ }
279
+ /**
280
+ Issue の作成の応答から、番号・URL・node id を取る
281
+ */
282
+ export function summarizeCreatedIssue(issue) {
283
+ const nodeId = issue['node_id'];
284
+ return {
285
+ number: requireNumber(issue['number'], 'number'),
286
+ url: requireString(issue['html_url'], 'html_url'),
287
+ nodeId: typeof nodeId === 'string' ? nodeId : undefined,
288
+ };
289
+ }
290
+ /**
291
+ Issue をボードへ追加する。失敗は warning と Issue の URL を出して undefined
292
+ */
293
+ export async function addToBoardOrWarn(output, client, config, owner, repository, issueNumber, issueNodeId, issueUrl) {
294
+ let added;
295
+ try {
296
+ added = await addIssueToBoard(client, config, owner, repository, issueNumber, issueNodeId);
297
+ }
298
+ catch (error) {
299
+ if (!(error instanceof GitHubAPIError))
300
+ throw error;
301
+ output.warning(`could not add Issue ${issuePath(owner, repository, issueNumber)} to project: ${error.message}`);
302
+ output.data(issueUrl);
303
+ return undefined;
304
+ }
305
+ output.done({ verb: 'add', target: `Issue ${issuePath(owner, repository, issueNumber)} to project` });
306
+ return added;
307
+ }
308
+ /**
309
+ カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。失敗したフィールドは、何も出さずに飛ばす。設定できたフィールドの名前を返す
310
+ */
311
+ export async function setIssueFields(output, client, config, itemId, target, fields) {
312
+ const labels = [];
313
+ const written = [];
314
+ for (const { fieldName, optionName, label } of fields) {
315
+ try {
316
+ if (await setIssueField(client, config, itemId, fieldName, optionName)) {
317
+ labels.push(label);
318
+ written.push(fieldName);
319
+ }
320
+ }
321
+ catch (error) {
322
+ if (!(error instanceof GitHubAPIError))
323
+ throw error;
324
+ }
325
+ }
326
+ if (labels.length > 0)
327
+ output.done({ verb: 'set', target: `${target} ${labels.join(', ')}` });
328
+ return written;
329
+ }
330
+ /**
331
+ 親 Epic のサブ Issue にする。失敗は Issue の URL(issueUrl が undefined なら出し済みとして省く)、error の行の順に出して終了コード 1。issueNodeId は、無ければ取り直す関数
332
+ */
333
+ export async function linkToParentEpic(output, client, target, parentReference, issueNodeId, issueUrl) {
334
+ const parent = issueReferenceToCliReference(parentReference);
335
+ try {
336
+ const parentNodeId = await client.getIssueNodeId(parentReference.repository.owner, parentReference.repository.repository, parentReference.number);
337
+ await client.addSubIssue(parentNodeId, typeof issueNodeId === 'string' ? issueNodeId : await issueNodeId());
338
+ }
339
+ catch (error) {
340
+ if (!(error instanceof GitHubAPIError))
341
+ throw error;
342
+ if (issueUrl !== undefined)
343
+ output.data(issueUrl);
344
+ stopWith(output, `could not add ${target} as sub-issue of ${parent}: ${error.message}\nthe order in its title is not counted for the next numbering until it is linked to the parent; link it by hand`, kindOfFailure(error));
345
+ }
346
+ output.done({ verb: 'add', target: `${target} as sub-issue of ${parent}` });
347
+ }
348
+ /**
349
+ リポジトリがプロジェクトにリンクされていなければ、message を error に出して終了コード 1
350
+ */
351
+ export async function ensureRepositoryInProject(output, config, client, owner, repository, message) {
352
+ if (await isRepositoryInProject(config, owner, repository, client))
353
+ return;
354
+ stopWith(output, message, 'repo-not-in-project');
355
+ }
356
+ /**
357
+ クライアントを作り、リポジトリがプロジェクトにあることを確かめる。無ければ error と終了コード 1。board add・board move・issue reopen が使う
358
+ */
359
+ export async function connectToProject(output, config, owner, repository) {
360
+ const client = createGitHubClient(output, config.host);
361
+ await ensureRepositoryInProject(output, config, client, owner, repository, `repository ${owner}/${repository} is not in the project`);
362
+ return client;
363
+ }
364
+ /**
365
+ ボードに無い status の error の文。blocked は後から足せる option なので、足し方の hint を添える
366
+ */
367
+ export function notConfiguredMessage(status) {
368
+ const base = `status '${status}' is not configured in the project`;
369
+ return status === 'blocked' ? hinted `${base}\nhint: run ${commandHint(['project', 'init'])} to add the Blocked option to the board` : base;
370
+ }
371
+ /**
372
+ 起票用のクライアントを作り、リポジトリのリンクと、親 Epic のリポジトリでの order の重複を確かめる
373
+ */
374
+ export async function clientForIssueCreate(output, config, owner, repository, display, parentReference, order) {
375
+ const client = createGitHubClient(output, config.host);
376
+ await ensureRepositoryInProject(output, config, client, owner, repository, `${display} is not linked to the project`);
377
+ if (parentReference !== undefined && order !== undefined) {
378
+ await checkDuplicateOrder(output, client, parentReference.repository.owner, parentReference.repository.repository, parentReference.number, order);
379
+ }
380
+ return client;
381
+ }
382
+ // --- テンプレートの検証 ---
383
+ /**
384
+ 本文をテンプレートと比べ、違反を 1 つの error にして出す。違反があれば true。
385
+ 1 行目はテンプレートのパス。続く行に、違反のある種類だけを並べる
386
+ */
387
+ export function hasReportedTemplateViolations(output, body, templatePath, options = {}) {
388
+ const required = readTemplateSections(templatePath);
389
+ const missing = required.length > 0 ? validateSections(body, required) : [];
390
+ const summaryErrors = required.length > 0 ? validateHeadingSummaries(body, required) : [];
391
+ const styleErrors = validateBodyStyle(body);
392
+ const stem = path.basename(templatePath, path.extname(templatePath));
393
+ const closedGuidance = CLOSED_HEADINGS_BY_TEMPLATE.get(stem);
394
+ const foldErrors = closedGuidance === undefined ? [] : [...validateFoldBalance(body)];
395
+ const extraHeadings = closedGuidance !== undefined && required.length > 0 ? validateClosedHeadings(body, required) : [];
396
+ const foldSummary = FOLD_SUMMARY_BY_TEMPLATE.get(stem);
397
+ if (foldSummary !== undefined)
398
+ foldErrors.push(...validateFoldSummaries(body, foldSummary));
399
+ if (missing.length === 0 && summaryErrors.length === 0 && styleErrors.length === 0 && foldErrors.length === 0 && extraHeadings.length === 0)
400
+ return false;
401
+ const lines = [`the body does not follow the template ${templatePath}`];
402
+ if (missing.length > 0) {
403
+ lines.push(`missing sections: ${missing.join(', ')}`);
404
+ if (options.emDashHint === true && missing.some(section => section.includes(' — <'))) {
405
+ lines.push('hint: the em dash must be U+2014; hyphen-minus (-) and EN DASH (U+2013) are not allowed');
406
+ }
407
+ }
408
+ if (summaryErrors.length > 0)
409
+ lines.push(`heading summary rule violations: ${summaryErrors.join(', ')}`);
410
+ if (styleErrors.length > 0)
411
+ lines.push(`unusable notation: ${styleErrors.join(', ')}`);
412
+ if (foldErrors.length > 0)
413
+ lines.push(`collapse rule violations: ${foldErrors.join(', ')}`);
414
+ if (extraHeadings.length > 0)
415
+ lines.push(`headings not in the template: ${extraHeadings.join(', ')} (${String(closedGuidance)})`);
416
+ output.error(lines.join('\n'));
417
+ return true;
418
+ }
419
+ /**
420
+ Issue 本文を種別のテンプレートと比べる。違反があれば error を出して終了コード 1
421
+ */
422
+ export function validateIssueTemplate(output, templateType, body) {
423
+ if (hasReportedTemplateViolations(output, body, templateFile('issue', templateType), { emDashHint: true }))
424
+ throw new CommandExit(1, 'content-invalid');
425
+ }
426
+ //# sourceMappingURL=issue-shared.js.map
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_SHOW_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue-show.d.ts.map
@@ -0,0 +1,169 @@
1
+ // issue show。cli/commands/issue.py の issue_read の移植。
2
+ import { z } from 'zod';
3
+ import { JSON_NULL } from '../domain/json-null.js';
4
+ import { describePrerequisiteState, describeReadiness, describeUnknown, displayReference, TRACKER_TITLE_PREFIX } from '../domain/readiness.js';
5
+ import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
6
+ import { createRepositoryReference, repositoryFullName } from '../domain/repository-resolver.js';
7
+ import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
8
+ import { defineCommand } from './command-definition.js';
9
+ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
10
+ import { kindOfFailure } from './failure.js';
11
+ import { createGitHubClient } from './github-client.js';
12
+ import { ISSUE_REF_DESCRIPTION, issuePath, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
13
+ import { blockedByReadCount, createReadinessCache, judgeSnapshot, readIssueReadiness, readinessJson, snapshotWithoutPrerequisites } from './issue-readiness.js';
14
+ import { createOutput } from './output.js';
15
+ const MAX_COMMENT_LIMIT = 20;
16
+ const DEFAULT_COMMENT_LIMIT = 5;
17
+ function parentLine(issue, owner, repository) {
18
+ const { parent } = issue;
19
+ if (parent === null)
20
+ return undefined;
21
+ const isCrossRepository = parent.owner !== null && parent.repo !== null && (parent.owner !== owner || parent.repo !== repository);
22
+ const label = isCrossRepository ? `${parent.owner}/${parent.repo}#${String(parent.number)}` : `#${String(parent.number)}`;
23
+ return `**Parent:** ${label} ${parent.title} (${parent.state})`;
24
+ }
25
+ /**
26
+ Issue の情報を Markdown にする。owner・repo は、親が別のリポジトリかを調べる元
27
+ */
28
+ function formatIssueMarkdown(issue, owner, repository, readiness) {
29
+ const lines = [`## #${String(issue.number)} ${issue.title}`, ''];
30
+ const meta = [`**State:** ${issue.state}`];
31
+ if (issue.comments.total_count > 0)
32
+ meta.push(`**Comments:** ${String(issue.comments.total_count)}`);
33
+ lines.push(meta.join(' | '), '');
34
+ const parent = parentLine(issue, owner, repository);
35
+ const header = [...parent === undefined ? [] : [parent], ...readiness?.lines ?? []];
36
+ if (header.length > 0)
37
+ lines.push(...header, '');
38
+ if (issue.linked_branches.length > 0) {
39
+ lines.push('**Branches:**', ...issue.linked_branches.map(branch => ` - \`${branch}\``), '');
40
+ }
41
+ if (issue.linked_prs.length > 0) {
42
+ lines.push('**Linked PRs:**', ...issue.linked_prs.map(pr => ` - #${String(pr.number)} ${pr.title} (${pr.state})`), '');
43
+ }
44
+ if (issue.sub_issues.length > 0) {
45
+ lines.push('**Sub-issues:**', ...issue.sub_issues.map(sub => ` - #${String(sub.number)} ${sub.title} (${sub.state})`), '');
46
+ }
47
+ lines.push('---', '', issue.body);
48
+ const comments = issue.comments.nodes;
49
+ if (comments.length > 0) {
50
+ lines.push('', '', `### Comments (${String(comments.length)}/${String(issue.comments.total_count)})`, '');
51
+ for (const comment of comments) {
52
+ lines.push('---', '', `**@${comment.author}** - ${comment.created_at.slice(0, 10)}`, '', comment.body, '');
53
+ }
54
+ }
55
+ return lines.join('\n');
56
+ }
57
+ // 前提と判定を読めなかったとき
58
+ const UNREAD = { lines: [], blockedBy: JSON_NULL, readiness: JSON_NULL };
59
+ /**
60
+ 前提の行と JSON。Readiness の行は text が渡されたときだけ足す(Epic と Tracker は判定が無い)
61
+ */
62
+ function readinessView(source, readiness, text) {
63
+ const home = source.ref.repository;
64
+ const entries = source.prerequisites.map((prerequisite) => {
65
+ const { issue, wait, reason } = prerequisite;
66
+ return {
67
+ label: displayReference(issue.ref, home),
68
+ title: source.titles.get(issueReferenceKey(issue.ref)) ?? '',
69
+ state: issue.state === 'open' ? 'OPEN' : 'CLOSED',
70
+ status: describePrerequisiteState(prerequisite),
71
+ wait,
72
+ reason,
73
+ ref: issue.ref,
74
+ };
75
+ });
76
+ const lines = entries.length === 0
77
+ ? []
78
+ : [`**Blocked by:** ${entries.map(entry => `${entry.label} ${entry.title} (${entry.state}, ${entry.status})`).join(', ')}`, ...text === undefined ? [] : [`**Readiness:** ${text}`]];
79
+ return {
80
+ lines,
81
+ blockedBy: entries.map(entry => ({ number: entry.ref.number, repository: repositoryFullName(entry.ref.repository), state: entry.state, wait: entry.wait, reason: entry.reason ?? JSON_NULL })),
82
+ readiness: readiness === undefined || text === undefined ? JSON_NULL : readinessJson(readiness, text),
83
+ };
84
+ }
85
+ function judgedView(judged) {
86
+ const { readiness } = judged;
87
+ return readinessView(judged, readiness, readiness === undefined ? undefined : describeReadiness(readiness, judged.prerequisites, judged.ref.repository));
88
+ }
89
+ function warnAboutSections(out, source) {
90
+ const home = source.ref.repository;
91
+ const self = displayReference(source.ref, home);
92
+ for (const mismatch of source.mismatches) {
93
+ out.warning(`Waits for merge of ${self} lists ${displayReference(mismatch.ref, home)}, which is not a blocked-by of it`);
94
+ }
95
+ if (source.malformedReason !== undefined)
96
+ out.warning(`Waits for merge of ${self} is malformed: ${source.malformedReason}`);
97
+ }
98
+ // 前提が無いと分かっている Issue の判定。API は呼ばない。Epic と Tracker は判定を出さない
99
+ async function readWithoutPrerequisites(client, config, issue, reference) {
100
+ const isGrouping = issue.sub_issues.length > 0 || issue.title.startsWith(TRACKER_TITLE_PREFIX);
101
+ const target = { ref: reference, state: issue.state.toLowerCase() === 'open' ? 'open' : 'closed', column: undefined, label: undefined, kind: isGrouping ? 'epic' : 'task', branches: issue.linked_branches, pullRequests: [] };
102
+ const result = await judgeSnapshot(client, snapshotWithoutPrerequisites(config, { title: issue.title, target, parent: undefined }), createReadinessCache());
103
+ if (result.kind === 'unreadable')
104
+ throw new Error('unreachable: a snapshot without prerequisites is always judged');
105
+ return result;
106
+ }
107
+ // 判定が読めなくても、今までの出力は止めない
108
+ async function readView(out, client, config, issue, reference) {
109
+ const label = displayReference(reference, reference.repository);
110
+ try {
111
+ const result = issue.blockedByCount === 0
112
+ ? await readWithoutPrerequisites(client, config, issue, reference)
113
+ : await readIssueReadiness(client, config, reference, createReadinessCache(), undefined, blockedByReadCount(issue.blockedByCount));
114
+ if (result.kind === 'unreadable') {
115
+ const { snapshot } = result;
116
+ if (snapshot === undefined) {
117
+ out.warning(`could not read blocked-by of ${label}: ${result.reason}`);
118
+ return UNREAD;
119
+ }
120
+ out.warning(`could not judge readiness of ${label}: ${result.reason}`);
121
+ warnAboutSections(out, snapshot);
122
+ return readinessView(snapshot, undefined, describeUnknown(result.reason));
123
+ }
124
+ warnAboutSections(out, result);
125
+ return judgedView(result);
126
+ }
127
+ catch (error) {
128
+ if (!(error instanceof DependenciesUnsupportedError))
129
+ throw error;
130
+ out.warning(`could not read blocked-by of ${label}: ${error.message}`);
131
+ return UNREAD;
132
+ }
133
+ }
134
+ const ISSUE_SHOW = defineCommand({
135
+ path: ['issue', 'show'],
136
+ description: 'Fetch Issue details efficiently (GraphQL, only the needed fields)',
137
+ input: z.object({
138
+ issue_ref: z.string().describe(ISSUE_REF_DESCRIPTION),
139
+ json: z.boolean().default(false).describe('Output as JSON'),
140
+ comment_limit: z.int().min(0).max(MAX_COMMENT_LIMIT).default(DEFAULT_COMMENT_LIMIT).describe('Number of comments to show (0-20; 0 hides them)'),
141
+ }),
142
+ positional: ['issue_ref'],
143
+ shortFlags: { json: '-j', comment_limit: '-c' },
144
+ interactive: false,
145
+ run: async (input, io) => {
146
+ const output = createOutput(false, io);
147
+ return await runWithExit(async () => {
148
+ const config = requireActiveConfigPlain(output);
149
+ const { owner, repository, number } = parseIssueReferenceOrExit(output, input.repo, input.issue_ref);
150
+ let issue;
151
+ const client = createGitHubClient(output, config.host);
152
+ try {
153
+ issue = await client.getIssueSlim(owner, repository, number, input.comment_limit);
154
+ }
155
+ catch (error) {
156
+ if (!(error instanceof GitHubAPIError))
157
+ throw error;
158
+ return stopWith(output, `could not read Issue ${issuePath(owner, repository, number)}: ${error.message}`, kindOfFailure(error));
159
+ }
160
+ const jsonFields = { ...issue, blockedByCount: undefined };
161
+ const view = await readView(output, client, config, issue, createIssueReference(createRepositoryReference(owner, repository), number));
162
+ output.data(input.json
163
+ ? JSON.stringify({ ...jsonFields, owner, repo: repository, blockedBy: view.blockedBy, readiness: view.readiness }, undefined, 2)
164
+ : formatIssueMarkdown(issue, owner, repository, view));
165
+ });
166
+ },
167
+ });
168
+ export const ISSUE_SHOW_COMMANDS = [ISSUE_SHOW];
169
+ //# sourceMappingURL=issue-show.js.map
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { ISSUE_COMMENT_COMMANDS } from './issue-comment.js';
2
+ import { ISSUE_CREATE_COMMANDS } from './issue-create.js';
3
+ import { ISSUE_DEPENDENCY_COMMANDS } from './issue-dependency.js';
4
+ import { ISSUE_REOPEN_COMMANDS } from './issue-reopen.js';
5
+ import { ISSUE_SHOW_COMMANDS } from './issue-show.js';
6
+ export const ISSUE_COMMANDS = [
7
+ ...ISSUE_CREATE_COMMANDS,
8
+ ...ISSUE_SHOW_COMMANDS,
9
+ ...ISSUE_COMMENT_COMMANDS,
10
+ ...ISSUE_DEPENDENCY_COMMANDS,
11
+ ...ISSUE_REOPEN_COMMANDS,
12
+ ];
13
+ //# sourceMappingURL=issue.js.map
@@ -0,0 +1,42 @@
1
+ /**
2
+ 入力名を長いオプションの形にする。`force_overwrite_active` は `--force-overwrite-active`
3
+ */
4
+ export declare function flagOf(name: string): string;
5
+ /**
6
+ 文字列を名前の順(コードユニットの順)に並べる比較関数
7
+ */
8
+ export declare function byName(left: string, right: string): number;
9
+ /**
10
+ コマンド名の語と、その意味
11
+ */
12
+ export interface CommandWord {
13
+ readonly name: string;
14
+ readonly meaning: string;
15
+ readonly readOnly?: true;
16
+ }
17
+ /**
18
+ グループの語。help は、グループの一覧と `pecot <グループ> --help` に help の文を出す
19
+ */
20
+ export interface CommandGroup extends CommandWord {
21
+ readonly help: string;
22
+ }
23
+ /**
24
+ コマンド名の 1 語目に使うグループ。利用者が操作する対象で、help の一覧はこの順に並ぶ
25
+ */
26
+ export declare const COMMAND_GROUPS: readonly CommandGroup[];
27
+ /**
28
+ コマンド名の 2 語目に使う動詞の語彙。1 語に 1 つの意味を決める
29
+ */
30
+ export declare const COMMAND_VERBS: readonly CommandWord[];
31
+ /**
32
+ コマンド名の決まりに合わない path と、その理由
33
+ */
34
+ export interface CommandNameViolation {
35
+ readonly path: string;
36
+ readonly reason: string;
37
+ }
38
+ /**
39
+ コマンド名の決まり(`<グループ> <動詞>` の 2 語で、1 語目が COMMAND_GROUPS、2 語目が COMMAND_VERBS にある)に合わない path を、渡された順で返す。全部が合えば空
40
+ */
41
+ export declare function commandNameViolations(paths: readonly (readonly string[])[]): readonly CommandNameViolation[];
42
+ //# sourceMappingURL=names.d.ts.map