@pecot/workflow-mcp 5.0.0 → 7.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 (188) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +27 -22
  3. package/cli/dist/cli.js +6 -1
  4. package/cli/dist/commands/board-add.d.ts +3 -0
  5. package/cli/dist/commands/board-add.js +69 -0
  6. package/cli/dist/commands/board-judgment.d.ts +69 -0
  7. package/cli/dist/commands/board-judgment.js +150 -0
  8. package/cli/dist/commands/board-move.d.ts +3 -0
  9. package/cli/dist/commands/board-move.js +65 -0
  10. package/cli/dist/commands/board-readiness.d.ts +34 -0
  11. package/cli/dist/commands/board-readiness.js +108 -0
  12. package/cli/dist/commands/board-show.d.ts +3 -0
  13. package/cli/dist/commands/board-show.js +75 -0
  14. package/cli/dist/commands/board-sync.d.ts +3 -0
  15. package/cli/dist/commands/board-sync.js +120 -0
  16. package/cli/dist/commands/board-view.d.ts +151 -0
  17. package/cli/dist/commands/board-view.js +293 -0
  18. package/cli/dist/commands/board.d.ts +3 -0
  19. package/cli/dist/commands/board.js +12 -0
  20. package/cli/dist/commands/branch.d.ts +3 -0
  21. package/cli/dist/commands/branch.js +111 -0
  22. package/cli/dist/commands/command-binding.js +4 -0
  23. package/cli/dist/commands/command-definition.d.ts +39 -8
  24. package/cli/dist/commands/command-definition.js +20 -7
  25. package/cli/dist/commands/command-help.js +2 -2
  26. package/cli/dist/commands/command-hint.d.ts +5 -0
  27. package/cli/dist/commands/command-hint.js +13 -0
  28. package/cli/dist/commands/command-stop.d.ts +5 -3
  29. package/cli/dist/commands/command-stop.js +7 -6
  30. package/cli/dist/commands/failure-kind.d.ts +3 -0
  31. package/cli/dist/commands/failure-kind.js +35 -0
  32. package/cli/dist/commands/failure.d.ts +6 -0
  33. package/cli/dist/commands/failure.js +29 -3
  34. package/cli/dist/commands/github-client.d.ts +6 -2
  35. package/cli/dist/commands/github-client.js +13 -3
  36. package/cli/dist/commands/help.js +8 -13
  37. package/cli/dist/commands/issue-board.d.ts +61 -0
  38. package/cli/dist/commands/issue-board.js +85 -1
  39. package/cli/dist/commands/issue-comment.js +66 -30
  40. package/cli/dist/commands/issue-create.js +632 -92
  41. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  42. package/cli/dist/commands/issue-dependency.js +310 -0
  43. package/cli/dist/commands/issue-readiness.d.ts +122 -0
  44. package/cli/dist/commands/issue-readiness.js +253 -0
  45. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  46. package/cli/dist/commands/issue-reopen.js +130 -0
  47. package/cli/dist/commands/issue-shared.d.ts +33 -20
  48. package/cli/dist/commands/issue-shared.js +84 -76
  49. package/cli/dist/commands/issue-show.d.ts +3 -0
  50. package/cli/dist/commands/issue-show.js +239 -0
  51. package/cli/dist/commands/issue.d.ts +0 -1
  52. package/cli/dist/commands/issue.js +6 -8
  53. package/cli/dist/commands/names.d.ts +33 -0
  54. package/cli/dist/commands/names.js +63 -0
  55. package/cli/dist/commands/output.d.ts +32 -4
  56. package/cli/dist/commands/output.js +28 -8
  57. package/cli/dist/commands/pr-merge.d.ts +3 -0
  58. package/cli/dist/commands/pr-merge.js +230 -0
  59. package/cli/dist/commands/pr-reference.d.ts +8 -0
  60. package/cli/dist/commands/pr-reference.js +30 -0
  61. package/cli/dist/commands/pr-restack.d.ts +6 -0
  62. package/cli/dist/commands/pr-restack.js +233 -0
  63. package/cli/dist/commands/pr-waiting.d.ts +59 -0
  64. package/cli/dist/commands/pr-waiting.js +143 -0
  65. package/cli/dist/commands/pr.d.ts +23 -0
  66. package/cli/dist/commands/pr.js +378 -366
  67. package/cli/dist/commands/project-sync.d.ts +12 -3
  68. package/cli/dist/commands/project-sync.js +23 -13
  69. package/cli/dist/commands/project.d.ts +3 -2
  70. package/cli/dist/commands/project.js +371 -177
  71. package/cli/dist/commands/registry.js +15 -10
  72. package/cli/dist/commands/release.d.ts +2 -2
  73. package/cli/dist/commands/release.js +118 -130
  74. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  75. package/cli/dist/commands/renamed-commands.js +53 -0
  76. package/cli/dist/commands/repository-match.js +9 -3
  77. package/cli/dist/commands/session-finish.d.ts +3 -0
  78. package/cli/dist/commands/session-finish.js +383 -0
  79. package/cli/dist/commands/session-start.d.ts +3 -0
  80. package/cli/dist/commands/session-start.js +252 -0
  81. package/cli/dist/commands/session.d.ts +3 -0
  82. package/cli/dist/commands/session.js +186 -32
  83. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  84. package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
  85. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  86. package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
  87. package/cli/dist/commands/tracker-sync.d.ts +37 -0
  88. package/cli/dist/commands/tracker-sync.js +18 -6
  89. package/cli/dist/commands/tracker.d.ts +3 -0
  90. package/cli/dist/commands/tracker.js +20 -0
  91. package/cli/dist/commands/usage-error.d.ts +4 -0
  92. package/cli/dist/commands/usage-error.js +6 -0
  93. package/cli/dist/commands/work-target.d.ts +20 -3
  94. package/cli/dist/commands/work-target.js +49 -6
  95. package/cli/dist/commands/worktree.js +103 -33
  96. package/cli/dist/domain/batch-plan.d.ts +73 -0
  97. package/cli/dist/domain/batch-plan.js +114 -0
  98. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  99. package/cli/dist/domain/blocked-by-change.js +101 -0
  100. package/cli/dist/domain/board-move.d.ts +90 -0
  101. package/cli/dist/domain/board-move.js +92 -0
  102. package/cli/dist/domain/branch-name.js +1 -1
  103. package/cli/dist/domain/command-hint.d.ts +85 -0
  104. package/cli/dist/domain/command-hint.js +148 -0
  105. package/cli/dist/domain/config.d.ts +4 -0
  106. package/cli/dist/domain/config.js +11 -1
  107. package/cli/dist/domain/dependabot.js +1 -1
  108. package/cli/dist/domain/errors.d.ts +5 -0
  109. package/cli/dist/domain/errors.js +5 -0
  110. package/cli/dist/domain/format.d.ts +51 -4
  111. package/cli/dist/domain/format.js +72 -6
  112. package/cli/dist/domain/frontmatter.d.ts +18 -3
  113. package/cli/dist/domain/frontmatter.js +38 -12
  114. package/cli/dist/domain/issue-order.d.ts +55 -0
  115. package/cli/dist/domain/issue-order.js +65 -0
  116. package/cli/dist/domain/issue-readout.d.ts +36 -4
  117. package/cli/dist/domain/pull-request.d.ts +71 -4
  118. package/cli/dist/domain/pull-request.js +59 -10
  119. package/cli/dist/domain/readiness.d.ts +44 -0
  120. package/cli/dist/domain/readiness.js +153 -5
  121. package/cli/dist/domain/reference-parser.d.ts +3 -1
  122. package/cli/dist/domain/reference-parser.js +6 -2
  123. package/cli/dist/domain/release.d.ts +7 -3
  124. package/cli/dist/domain/release.js +5 -12
  125. package/cli/dist/domain/repository-policy.d.ts +9 -3
  126. package/cli/dist/domain/repository-policy.js +8 -7
  127. package/cli/dist/domain/repository-resolver.js +4 -1
  128. package/cli/dist/domain/restack.d.ts +62 -0
  129. package/cli/dist/domain/restack.js +53 -0
  130. package/cli/dist/domain/security-alerts.js +1 -1
  131. package/cli/dist/domain/state.d.ts +69 -0
  132. package/cli/dist/domain/state.js +67 -1
  133. package/cli/dist/domain/work-start.d.ts +30 -0
  134. package/cli/dist/domain/work-start.js +42 -0
  135. package/cli/dist/infra/authored-notes.d.ts +1 -1
  136. package/cli/dist/infra/authored-notes.js +10 -4
  137. package/cli/dist/infra/config-store.d.ts +4 -0
  138. package/cli/dist/infra/config-store.js +13 -0
  139. package/cli/dist/infra/git.d.ts +76 -0
  140. package/cli/dist/infra/git.js +123 -1
  141. package/cli/dist/infra/github/client.d.ts +5 -0
  142. package/cli/dist/infra/github/client.js +10 -7
  143. package/cli/dist/infra/github/errors.d.ts +18 -0
  144. package/cli/dist/infra/github/errors.js +22 -0
  145. package/cli/dist/infra/github/issues.d.ts +39 -3
  146. package/cli/dist/infra/github/issues.js +178 -23
  147. package/cli/dist/infra/github/projects.d.ts +35 -0
  148. package/cli/dist/infra/github/projects.js +89 -8
  149. package/cli/dist/infra/github/pulls.d.ts +105 -2
  150. package/cli/dist/infra/github/pulls.js +172 -5
  151. package/cli/dist/infra/github/queries.d.ts +15 -4
  152. package/cli/dist/infra/github/queries.js +203 -40
  153. package/cli/dist/infra/github/readout.d.ts +5 -1
  154. package/cli/dist/infra/github/readout.js +11 -33
  155. package/cli/dist/infra/github/repos.d.ts +18 -0
  156. package/cli/dist/infra/github/repos.js +31 -0
  157. package/cli/dist/infra/nx-scope.d.ts +1 -1
  158. package/cli/dist/infra/nx-scope.js +1 -1
  159. package/cli/dist/infra/state-store.d.ts +10 -1
  160. package/cli/dist/infra/state-store.js +14 -2
  161. package/cli/dist/infra/worktree-links.d.ts +3 -0
  162. package/cli/dist/infra/worktree-links.js +8 -1
  163. package/cli/dist/infra/worktree.d.ts +12 -1
  164. package/cli/dist/infra/worktree.js +40 -23
  165. package/cli/dist/mcp/result.d.ts +82 -7
  166. package/cli/dist/mcp/result.js +139 -19
  167. package/cli/dist/mcp/server.d.ts +2 -2
  168. package/cli/dist/mcp/server.js +57 -10
  169. package/cli/templates/comment/plan.md +14 -0
  170. package/cli/templates/comment/review-findings.md +3 -2
  171. package/cli/templates/issue/bug.md +13 -4
  172. package/cli/templates/issue/task-implement.md +13 -6
  173. package/cli/templates/issue/task.md +13 -4
  174. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  175. package/npm-shrinkwrap.json +2 -2
  176. package/package.json +1 -1
  177. package/cli/dist/commands/dependabot.d.ts +0 -3
  178. package/cli/dist/commands/issue-project.d.ts +0 -3
  179. package/cli/dist/commands/issue-project.js +0 -176
  180. package/cli/dist/commands/issue-quick.d.ts +0 -3
  181. package/cli/dist/commands/issue-quick.js +0 -126
  182. package/cli/dist/commands/issue-read.d.ts +0 -3
  183. package/cli/dist/commands/issue-read.js +0 -80
  184. package/cli/dist/commands/project-info.d.ts +0 -48
  185. package/cli/dist/commands/project-info.js +0 -181
  186. package/cli/dist/commands/repository.d.ts +0 -5
  187. package/cli/dist/commands/repository.js +0 -265
  188. package/cli/dist/commands/security.d.ts +0 -3
@@ -0,0 +1,253 @@
1
+ // Issue の着手の可否の読み取り。前提を読み、判定する。board show と issue show が使う。
2
+ // 流れは getIssuePrerequisites → readWaitsForMerge → toIssueFacts → judgeReadiness。
3
+ import { z } from 'zod';
4
+ import { findRepository, workflowFieldName } from '../domain/config.js';
5
+ import { JSON_NULL } from '../domain/json-null.js';
6
+ import { readWaitsForMerge } from '../domain/prerequisites.js';
7
+ import { judgeReadiness, toIssueFacts } from '../domain/readiness.js';
8
+ import { issueReferenceKey } from '../domain/reference-parser.js';
9
+ import { repositoryFullName } from '../domain/repository-resolver.js';
10
+ import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
11
+ import { MAX_BLOCKED_BY } from '../infra/github/issues.js';
12
+ import { STATUS_FIELD_NAME } from './project-sync.js';
13
+ /**
14
+ 順 8 で base をたどる段数の上限
15
+ */
16
+ const MAX_STACK_TRACE_STEPS = 10;
17
+ /**
18
+ 前提を読む件数の下限。一覧を読んでから足された前提も取りこぼさない
19
+ */
20
+ const MIN_BLOCKED_BY_READ = 8;
21
+ /**
22
+ 一覧の前提の件数から、個別に読む前提の件数を決める。件数が一覧に無ければ undefined(上限で読む)
23
+ */
24
+ export function blockedByReadCount(listed) {
25
+ return listed === undefined ? undefined : Math.min(Math.max(listed, MIN_BLOCKED_BY_READ), MAX_BLOCKED_BY);
26
+ }
27
+ export function createReadinessCache() {
28
+ return new Map();
29
+ }
30
+ function unreadable(reason, snapshot) {
31
+ return snapshot === undefined ? { kind: 'unreadable', reason } : { kind: 'unreadable', reason, snapshot };
32
+ }
33
+ function titlesOf(readout) {
34
+ return readout.blockedBy.kind === 'ok' ? new Map(readout.blockedBy.issues.map(issue => [issueReferenceKey({ repository: issue.repository, number: issue.number }), issue.title])) : new Map();
35
+ }
36
+ /**
37
+ 対象の Issue と前提を読む。API の失敗と blockedBy の読み取りの失敗は、読めない理由で返す。
38
+ DependenciesUnsupportedError は GitHubAPIError だが、対応しない GHES を呼ぶ側で見分けるため、そのまま投げる
39
+ */
40
+ export async function readIssueSnapshot(client, config, reference, blockedByFirst) {
41
+ const { owner, repository } = reference.repository;
42
+ let readout;
43
+ try {
44
+ readout = await client.getIssuePrerequisites(owner, repository, reference.number, config.project.id, {
45
+ columnFieldName: workflowFieldName(config),
46
+ labelFieldName: STATUS_FIELD_NAME,
47
+ }, blockedByFirst);
48
+ }
49
+ catch (error) {
50
+ if (error instanceof GitHubAPIError && !(error instanceof DependenciesUnsupportedError))
51
+ return unreadable(error.message);
52
+ throw error;
53
+ }
54
+ const section = readWaitsForMerge(readout.issue.body, reference.repository);
55
+ const result = toIssueFacts(readout, section, { columnFieldName: workflowFieldName(config), labelFieldName: STATUS_FIELD_NAME });
56
+ if (result.prerequisites === 'read-failed') {
57
+ return unreadable(readout.blockedBy.kind === 'read-failed' ? readout.blockedBy.reason : 'could not read blocked-by');
58
+ }
59
+ const { parent } = readout.issue;
60
+ return {
61
+ kind: 'snapshot',
62
+ ref: reference,
63
+ title: readout.issue.title,
64
+ target: result.target,
65
+ prerequisites: result.prerequisites,
66
+ titles: titlesOf(readout),
67
+ mismatches: result.mismatches,
68
+ malformedReason: section.kind === 'malformed' ? section.reason : undefined,
69
+ parent: parent === null ? undefined : { repository: parent.repository, number: parent.number },
70
+ developmentBranch: findRepository(config, owner, repository)?.develop_branch,
71
+ };
72
+ }
73
+ /**
74
+ 前提の無い Issue の読み取り結果。一覧の値から作るので、API は呼ばない
75
+ */
76
+ export function snapshotWithoutPrerequisites(config, input) {
77
+ const { repository } = input.target.ref;
78
+ return {
79
+ kind: 'snapshot',
80
+ ref: input.target.ref,
81
+ title: input.title,
82
+ target: input.target,
83
+ prerequisites: [],
84
+ titles: new Map(),
85
+ mismatches: [],
86
+ malformedReason: undefined,
87
+ parent: input.parent,
88
+ developmentBranch: findRepository(config, repository.owner, repository.repository)?.develop_branch,
89
+ };
90
+ }
91
+ /**
92
+ Issue の前提の辺(対象のキー → 前提のキー)。輪の検出に使う
93
+ */
94
+ export function prerequisiteKeys(snapshot) {
95
+ return snapshot.prerequisites.map(({ issue }) => issueReferenceKey(issue.ref));
96
+ }
97
+ function toIssuePullRequest(readout) {
98
+ return {
99
+ repository: readout.repository,
100
+ number: readout.number,
101
+ state: readout.state === 'OPEN' ? 'open' : (readout.state === 'MERGED' ? 'merged' : 'closed'),
102
+ headRefName: readout.headRefName,
103
+ baseRefName: readout.baseRefName,
104
+ isDraft: readout.isDraft,
105
+ isCrossRepository: readout.isCrossRepository,
106
+ };
107
+ }
108
+ // head のブランチを持つ PR が、open で fork からでないものちょうど 1 本なら返す。2 本以上か続きがあれば足さない
109
+ async function lookUpByHead(client, repository, head) {
110
+ const found = await client.listPullRequestsByHead(repository.owner, repository.repository, head);
111
+ if (found.hasNextPage)
112
+ return undefined;
113
+ const candidates = found.pullRequests.map(pullRequest => toIssuePullRequest(pullRequest)).filter(pullRequest => pullRequest.state === 'open' && !pullRequest.isCrossRepository);
114
+ return candidates.length === 1 ? candidates[0] : undefined;
115
+ }
116
+ function cachedLookUp(client, cache, repository, head) {
117
+ const key = `${repositoryFullName(repository)}:${head}`.toLowerCase();
118
+ const cached = cache.get(key);
119
+ if (cached !== undefined)
120
+ return cached;
121
+ const pending = lookUpByHead(client, repository, head);
122
+ cache.set(key, pending);
123
+ return pending;
124
+ }
125
+ // 前提の open で fork からでない PR
126
+ function prerequisitePullRequests(prerequisites) {
127
+ return prerequisites.flatMap(({ issue }) => issue.pullRequests).filter(pullRequest => pullRequest.state === 'open' && !pullRequest.isCrossRepository);
128
+ }
129
+ // diverged の間、base のブランチを head に持つ PR を引き足して判定をやり直す
130
+ async function traceStacks(client, snapshot, cache, byHead, first, judge, branch) {
131
+ const { prerequisites } = snapshot;
132
+ let readiness = first;
133
+ const traced = new Set();
134
+ for (let step = 0; step < MAX_STACK_TRACE_STEPS && readiness?.reason?.code === 'diverged'; step += 1) {
135
+ const known = new Set([...prerequisitePullRequests(prerequisites), ...byHead.values()].map(pullRequest => pullRequest.headRefName));
136
+ const missing = [...prerequisitePullRequests(prerequisites), ...byHead.values()].filter(pullRequest => pullRequest.baseRefName !== branch && !known.has(pullRequest.baseRefName) && !traced.has(`${repositoryFullName(pullRequest.repository)}:${pullRequest.baseRefName}`.toLowerCase()));
137
+ if (missing.length === 0)
138
+ break;
139
+ for (const pullRequest of missing) {
140
+ traced.add(`${repositoryFullName(pullRequest.repository)}:${pullRequest.baseRefName}`.toLowerCase());
141
+ const base = await cachedLookUp(client, cache, pullRequest.repository, pullRequest.baseRefName);
142
+ if (base !== undefined)
143
+ byHead.set(base.headRefName, base);
144
+ }
145
+ readiness = judge();
146
+ }
147
+ return readiness;
148
+ }
149
+ /**
150
+ 前提を判定する。cycle は呼ぶ側が findCycle で求めた輪。
151
+ develop_branch が無いときと、PR の引き足しの API が失敗したときは、読み取り結果を添えた unreadable を返す。
152
+ DependenciesUnsupportedError はそのまま投げる。
153
+ 前提の PR が開発ブランチに届かないときだけ、base のブランチを head に持つ PR を引き足して、判定をやり直す
154
+ */
155
+ export async function judgeSnapshot(client, snapshot, cache, cycle) {
156
+ const { developmentBranch, prerequisites, target } = snapshot;
157
+ const hasUnfinished = prerequisites.some(({ issue }) => !(issue.state === 'closed' && issue.pullRequests.some(pullRequest => pullRequest.state === 'merged')));
158
+ if (hasUnfinished && (developmentBranch === undefined || developmentBranch === '')) {
159
+ return unreadable(`develop_branch is not set for ${repositoryFullName(snapshot.ref.repository)}`, snapshot);
160
+ }
161
+ const branch = developmentBranch ?? '';
162
+ const byHead = new Map();
163
+ const judge = () => judgeReadiness({ target, prerequisites, cycle, pullRequestsByHead: byHead, developmentBranch: branch });
164
+ let readiness = judge();
165
+ try {
166
+ readiness = await traceStacks(client, snapshot, cache, byHead, readiness, judge, branch);
167
+ }
168
+ catch (error) {
169
+ if (error instanceof GitHubAPIError && !(error instanceof DependenciesUnsupportedError))
170
+ return unreadable(error.message, snapshot);
171
+ throw error;
172
+ }
173
+ return {
174
+ kind: 'judged',
175
+ ref: snapshot.ref,
176
+ title: snapshot.title,
177
+ target,
178
+ prerequisites,
179
+ titles: snapshot.titles,
180
+ mismatches: snapshot.mismatches,
181
+ malformedReason: snapshot.malformedReason,
182
+ parent: snapshot.parent,
183
+ readiness,
184
+ };
185
+ }
186
+ /**
187
+ 判定済みの Issue の前提を assume で置き換え、同じ judgeSnapshot で判定し直す。API は、積んだ並びを引き足すときだけ呼ぶ
188
+ */
189
+ export async function judgeAssuming(client, config, judged, assume, cache) {
190
+ const { repository } = judged.ref;
191
+ const snapshot = {
192
+ kind: 'snapshot',
193
+ ref: judged.ref,
194
+ title: judged.title,
195
+ target: judged.target,
196
+ prerequisites: assume(judged.prerequisites),
197
+ titles: judged.titles,
198
+ mismatches: judged.mismatches,
199
+ malformedReason: judged.malformedReason,
200
+ parent: judged.parent,
201
+ developmentBranch: findRepository(config, repository.owner, repository.repository)?.develop_branch,
202
+ };
203
+ // 輪は前提の辺だけで決まり、状態の置き換えで変わらない
204
+ const reason = judged.readiness?.reason;
205
+ return await judgeSnapshot(client, snapshot, cache, reason?.code === 'cycle' ? reason.cycle : undefined);
206
+ }
207
+ /**
208
+ Issue 1 件の読み取りから判定までを通す。輪は呼ぶ側が渡す(issue show は輪を見ない)
209
+ */
210
+ export async function readIssueReadiness(client, config, reference, cache, cycle, blockedByFirst) {
211
+ const snapshot = await readIssueSnapshot(client, config, reference, blockedByFirst);
212
+ return snapshot.kind === 'unreadable' ? snapshot : await judgeSnapshot(client, snapshot, cache, cycle);
213
+ }
214
+ /**
215
+ readinessJson の形。キーの並びは readinessJson と同じにする
216
+ */
217
+ export const READINESS_JSON = z.strictObject({
218
+ kind: z.enum(['startable', 'stackable', 'blocked']).describe('Readiness judgment'),
219
+ stackOn: z.strictObject({
220
+ number: z.int().describe('Issue number to stack on'),
221
+ repository: z.string().describe('Repository of that Issue (owner/repo)'),
222
+ branch: z.string().describe('Branch to stack on'),
223
+ }).nullable().describe('Prerequisite to stack on (null unless stackable)'),
224
+ reason: z.string().nullable().describe('Code of the reason for blocked (null unless blocked)'),
225
+ text: z.string().describe('Readiness as shown in the Readiness line'),
226
+ });
227
+ /**
228
+ JSON の出力に使う判定。reason は blocked のときだけの理由のコード、stackOn は積む先
229
+ */
230
+ export function readinessJson(readiness, text) {
231
+ const { stackOn } = readiness;
232
+ return {
233
+ kind: readiness.kind,
234
+ stackOn: stackOn === undefined ? JSON_NULL : { number: stackOn.issue.number, repository: repositoryFullName(stackOn.issue.repository), branch: stackOn.branch },
235
+ reason: readiness.reason?.code ?? JSON_NULL,
236
+ text,
237
+ };
238
+ }
239
+ /**
240
+ readIssueReadiness の、依存関係を持たない GHES を判定なしで通す形。GHES なら undefined を返し、onUnsupported に理由を渡す
241
+ */
242
+ export async function readIssueReadinessIfSupported(client, config, reference, cache, onUnsupported) {
243
+ try {
244
+ return await readIssueReadiness(client, config, reference, cache);
245
+ }
246
+ catch (error) {
247
+ if (!(error instanceof DependenciesUnsupportedError))
248
+ throw error;
249
+ onUnsupported?.(error.message);
250
+ return undefined;
251
+ }
252
+ }
253
+ //# sourceMappingURL=issue-readiness.js.map
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_REOPEN_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue-reopen.d.ts.map
@@ -0,0 +1,130 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ // issue reopen。cli/commands/issue.py の移植。
3
+ import { setTimeout as delay } from 'node:timers/promises';
4
+ import { z } from 'zod';
5
+ import { GitHubAPIError } from '../infra/github/errors.js';
6
+ import { defineCommand } from './command-definition.js';
7
+ import { isStatusConfigured, setIssueField } from './issue-board.js';
8
+ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
9
+ import { kindOfFailure } from './failure.js';
10
+ import { connectToProject, exitInvalidStatus, ISSUE_REF_DESCRIPTION, issuePath, notConfiguredMessage, parseIssueReferenceOrExit, runWithExit, VALID_STATUSES, } from './issue-shared.js';
11
+ import { createOutput, DRY_RUN_FIELD } from './output.js';
12
+ // Projects V2 の自動化が Issue をもう一度閉じることがあるため、status を設定した後に待つ
13
+ const AUTOMATION_WAIT_MILLISECONDS = 3000;
14
+ const ISSUE_REOPEN_OUTPUT = z.strictObject({
15
+ issue: z.string().describe('Issue reopened (owner/repo/N)'),
16
+ status: z.string().optional().describe('Workflow status set on the board (omitted when the Issue is not on the board or the status is not configured)'),
17
+ unarchived: z.boolean().describe('Whether the item was unarchived on the board'),
18
+ commented: z.boolean().describe('Whether the reason was posted as a comment'),
19
+ dryRun: DRY_RUN_FIELD,
20
+ });
21
+ // アーカイブの解除、1 回目の reopen、ボードの status の更新。設定できたら自動化を待つ
22
+ async function reopenAndSetStatus(output, client, config, issue, status) {
23
+ const { owner, repository, number } = issue;
24
+ const target = `Issue ${issuePath(owner, repository, number)}`;
25
+ const item = await client.getIssueProjectItem(config.project.id, owner, repository, number);
26
+ output.result({ issue: issuePath(issue.owner, issue.repository, issue.number), unarchived: false, commented: false });
27
+ // アーカイブ済みの項目はボードの列に出ないので戻す。失敗したら Issue を開かずに止める
28
+ if (item?.isArchived === true) {
29
+ try {
30
+ await client.unarchiveProjectItem(config.project.id, item.id);
31
+ }
32
+ catch (error) {
33
+ if (!(error instanceof GitHubAPIError))
34
+ throw error;
35
+ stopWith(output, `could not unarchive ${target} on the board: ${error.message}`, kindOfFailure(error));
36
+ }
37
+ output.done({ verb: 'update', target: `${target} unarchived on the board` });
38
+ output.result({ unarchived: true });
39
+ }
40
+ await client.reopenIssue(owner, repository, number);
41
+ const itemId = item?.id;
42
+ if (itemId === undefined) {
43
+ output.warning(`${target} is not on the project board`);
44
+ }
45
+ else if (await setIssueField(client, config, itemId, 'workflow', status)) {
46
+ output.done({ verb: 'set', target: `${target} status ${status}` });
47
+ output.result({ status });
48
+ await delay(AUTOMATION_WAIT_MILLISECONDS);
49
+ }
50
+ else {
51
+ output.warning(notConfiguredMessage(status));
52
+ }
53
+ }
54
+ // 2 回目の reopen(自動化による close への対策)で open を確かめ、--comment があれば理由を投稿する
55
+ async function confirmReopened(output, client, issue, comment) {
56
+ const { owner, repository, number } = issue;
57
+ const target = `Issue ${issuePath(owner, repository, number)}`;
58
+ const result = await client.reopenIssue(owner, repository, number);
59
+ const state = result['state'];
60
+ if (state !== 'open') {
61
+ stopWith(output, `${target} did not become open (state: ${typeof state === 'string' ? state : 'None'})`, 'other');
62
+ }
63
+ output.done({ verb: 'reopen', target });
64
+ if (comment === undefined || comment === '')
65
+ return;
66
+ await client.addIssueComment(owner, repository, number, comment);
67
+ output.done({ verb: 'create', target: `comment on ${issuePath(owner, repository, number)}` });
68
+ output.result({ commented: true });
69
+ }
70
+ // 予行。ボードの項目を読み、書く操作を並べる
71
+ async function planReopen(output, client, config, issue, status, comment) {
72
+ const { owner, repository, number } = issue;
73
+ const target = `Issue ${issuePath(owner, repository, number)}`;
74
+ const item = await client.getIssueProjectItem(config.project.id, owner, repository, number);
75
+ const hasComment = comment !== undefined && comment !== '';
76
+ const willSetStatus = item !== undefined && isStatusConfigured(config, status);
77
+ output.result({ issue: issuePath(issue.owner, issue.repository, issue.number), ...willSetStatus && { status }, unarchived: item?.isArchived === true, commented: hasComment });
78
+ output.planned({ verb: 'reopen', target });
79
+ if (item?.isArchived === true)
80
+ output.planned({ verb: 'update', target: `${target} unarchived on the board` });
81
+ if (item === undefined)
82
+ output.warning(`${target} is not on the project board`);
83
+ else if (willSetStatus)
84
+ output.planned({ verb: 'set', target: `${target} status ${status}` });
85
+ else
86
+ output.warning(notConfiguredMessage(status));
87
+ if (hasComment)
88
+ output.planned({ verb: 'create', target: `comment on ${issuePath(owner, repository, number)}` });
89
+ }
90
+ async function reopenIssue(output, client, config, issue, status, comment) {
91
+ await reopenAndSetStatus(output, client, config, issue, status);
92
+ await confirmReopened(output, client, issue, comment);
93
+ }
94
+ const ISSUE_REOPEN = defineCommand({
95
+ path: ['issue', 'reopen'],
96
+ description: 'Reopen a closed Issue (also sets the status on the board)',
97
+ input: z.object({
98
+ issue_ref: z.string().describe(ISSUE_REF_DESCRIPTION),
99
+ status: z.string().default('ready').describe('Status after reopening (backlog/pending/blocked/ready/active/in_review/archived)'),
100
+ comment: z.string().optional().describe('Reason for reopening (posted as a comment)'),
101
+ dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
102
+ }),
103
+ output: ISSUE_REOPEN_OUTPUT,
104
+ positional: ['issue_ref'],
105
+ shortFlags: { status: '-s', comment: '-c', dry_run: '-n' },
106
+ interactive: false,
107
+ run: async (input, io) => {
108
+ const output = createOutput(input.dry_run, io);
109
+ return await runWithExit(async () => {
110
+ const { status, comment } = input;
111
+ if (!VALID_STATUSES.has(status))
112
+ exitInvalidStatus(output, status);
113
+ const config = requireActiveConfigPlain(output);
114
+ const { owner, repository, number } = parseIssueReferenceOrExit(output, input.repo, input.issue_ref);
115
+ const target = `Issue ${issuePath(owner, repository, number)}`;
116
+ try {
117
+ const client = await connectToProject(output, config, owner, repository);
118
+ const run = input.dry_run ? planReopen : reopenIssue;
119
+ await run(output, client, config, { owner, repository, number }, status, comment);
120
+ }
121
+ catch (error) {
122
+ if (!(error instanceof GitHubAPIError))
123
+ throw error;
124
+ stopWith(output, `could not reopen ${target}: ${error.message}`, kindOfFailure(error));
125
+ }
126
+ });
127
+ },
128
+ });
129
+ export const ISSUE_REOPEN_COMMANDS = [ISSUE_REOPEN];
130
+ //# sourceMappingURL=issue-reopen.js.map
@@ -1,9 +1,11 @@
1
1
  import { z } from 'zod';
2
2
  import type { ProjectConfig } from '../domain/config.js';
3
3
  import type { IssueFrontmatter } from '../domain/frontmatter.js';
4
+ import type { UsedOrder } from '../domain/issue-order.js';
4
5
  import type { IssueReference } from '../domain/reference-parser.js';
5
6
  import type { JsonObject } from '../domain/json.js';
6
7
  import type { GitHubClient } from '../infra/github/index.js';
8
+ import type { HintedText } from './command-hint.js';
7
9
  import type { BoardItem } from './issue-board.js';
8
10
  import type { Output } from './output.js';
9
11
  export type IssueType = IssueFrontmatter['type'];
@@ -12,7 +14,7 @@ issue comment のテンプレ検証失敗の終了コード。通信失敗・設
12
14
  */
13
15
  export declare const COMMENT_VALIDATION_EXIT_CODE = 3;
14
16
  /**
15
- Issue 種別の入力。issue create と issue quick が共有する
17
+ Issue 種別の入力。issue create が使う
16
18
  */
17
19
  export declare const ISSUE_TYPE_SCHEMA: z.ZodDefault<z.ZodEnum<{
18
20
  bug: "bug";
@@ -28,16 +30,16 @@ export declare const VALID_STATUSES: ReadonlySet<string>;
28
30
  */
29
31
  export declare const TYPE_DEFAULT_STATUS: Readonly<Record<IssueType, string>>;
30
32
  /**
31
- Backlog に置く型(quick の status / size / quick フラグの扱いが Epic と同じ)
33
+ Backlog に置く型(freeform の size と quick-mode フラグの扱いが Epic と同じ)
32
34
  */
33
35
  export declare const BACKLOG_TYPES: ReadonlySet<string>;
34
36
  /**
35
37
  run の本体を包む。終わったら 0 を返す。BadParameterError は使い方の誤りにして伝える。
36
38
  それ以外の例外はそのまま伝える。CommandExit は defineCommand が受けて終了コードにする
37
39
  */
38
- export declare function runWithExit(body: () => Promise<void>): Promise<number>;
40
+ export declare function runWithExit(body: () => Promise<void>): Promise<0>;
39
41
  /**
40
- `owner/repo/N` の表記。エラー文と done の行の対象に使う
42
+ `owner/repo/N` の表記。エラー文と done の行の対象、MCP の data の参照に使う
41
43
  */
42
44
  export declare function issuePath(owner: string, repository: string, number: number): string;
43
45
  export interface IssueTarget {
@@ -54,10 +56,10 @@ export declare function parseIssueReferenceOrExit(output: Output, repository: st
54
56
  */
55
57
  export declare function exitInvalidStatus(output: Output, status: string): never;
56
58
  /**
57
- 起票時の status が、型対応テンプレートの既定値と一致するか確かめる。違えば終了コード 1。
58
- enum 外の値(`--status foo`)と、型に合わない別テンプレートの既定値(`--type bug --status backlog`)は文を分ける
59
+ 起票時の status が、許す値のどれかと一致するか確かめる。違えば終了コード 1。許す値の既定は、型対応テンプレートの既定値だけ。
60
+ enum 外の値(`--status foo`)と、許さない値(`--type bug --status backlog`)は文を分ける
59
61
  */
60
- export declare function validateStatusForType(output: Output, issueType: IssueType, status: string): void;
62
+ export declare function validateStatusForType(output: Output, issueType: IssueType, status: string, allowed?: readonly string[]): void;
61
63
  /**
62
64
  CLI のオプションで来た parent_epic。空・空白だけなら undefined、数字だけなら整数(安全な整数を超えるなら数字の文字列)、それ以外は文字列
63
65
  */
@@ -86,20 +88,23 @@ export declare function warnEpicRepositoryException(output: Output, resolvedRepo
86
88
  export interface IssueTitleOptions {
87
89
  readonly parentEpic?: number | undefined;
88
90
  readonly order?: number | undefined;
89
- /**
90
- 同じ段の中の枝の文字(a-z)。order が無ければ使わない
91
- */
92
- readonly parallel?: string | undefined;
93
91
  }
94
92
  /**
95
- タイトルに接頭辞と、Epic 番号・order(・枝の文字)を付ける。例は `[Task] #353-04a: タイトル`
93
+ タイトルに接頭辞と、Epic 番号・order を付ける。例は `[Task] #353-04: タイトル`
96
94
  */
97
95
  export declare function buildIssueTitle(issueType: string, title: string, options?: Readonly<IssueTitleOptions>): string;
98
96
  /**
99
- 同じ Epic に、同じ(段, 枝の文字)の Issue が無いことを確かめる。OPEN でも CLOSED でも、一度使った番号は再利用できない。
100
- 同じ段では、枝ありと枝なしも重複。最初の一致を error にして終了コード 1。Epic を取れなければ warning だけで続ける
97
+ 親 Epic のサブ Issue から、使われた番号を読む。全件を読む。Epic を取れなければ warning を出して undefined
98
+ */
99
+ export declare function readUsedOrders(output: Output, client: GitHubClient, owner: string, repository: string, parentEpic: number): Promise<readonly UsedOrder[] | undefined>;
100
+ /**
101
+ 明示の order が既存の Issue と重なったときの error を出して終了コード 1。一度使った番号は、OPEN でも CLOSED でも再利用できない
102
+ */
103
+ export declare function stopForDuplicateOrder(output: Output, parentEpic: number, order: number, existing: UsedOrder, nextAvailable: number): never;
104
+ /**
105
+ 同じ Epic に、同じ order の Issue が無いことを確かめる。最初の一致を error にして終了コード 1。Epic を取れなければ warning だけで続ける
101
106
  */
102
- export declare function checkDuplicateOrder(output: Output, client: GitHubClient, owner: string, repository: string, parentEpic: number, order: number, parallel?: string): Promise<void>;
107
+ export declare function checkDuplicateOrder(output: Output, client: GitHubClient, owner: string, repository: string, parentEpic: number, order: number): Promise<void>;
103
108
  /**
104
109
  Issue を作り、`created:` の行を出して API の応答を返す。失敗は error の行と終了コード 1。
105
110
  source は作成元のファイル名(`from <source>` として行の末尾に付く)
@@ -130,21 +135,29 @@ export interface IssueField {
130
135
  readonly label: string;
131
136
  }
132
137
  /**
133
- カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。失敗したフィールドは、何も出さずに飛ばす
138
+ カスタムフィールドを順に設定し、設定できた分を 1 行の set にする。失敗したフィールドは、何も出さずに飛ばす。設定できたフィールドの名前を返す
134
139
  */
135
- export declare function setIssueFields(output: Output, client: GitHubClient, config: ProjectConfig, itemId: string, target: string, fields: readonly IssueField[]): Promise<void>;
140
+ export declare function setIssueFields(output: Output, client: GitHubClient, config: ProjectConfig, itemId: string, target: string, fields: readonly IssueField[]): Promise<readonly string[]>;
136
141
  /**
137
- 親 Epic のサブ Issue にする。失敗は Issue の URL、error の行の順に出して終了コード 1
142
+ 親 Epic のサブ Issue にする。失敗は Issue の URL(issueUrl が undefined なら出し済みとして省く)、error の行の順に出して終了コード 1。issueNodeId は、無ければ取り直す関数。行に出した親の参照(owner/repo/N)を返す
138
143
  */
139
- export declare function linkToParentEpic(output: Output, client: GitHubClient, target: string, parentReference: IssueReference, issueNodeId: string, issueUrl: string): Promise<void>;
144
+ export declare function linkToParentEpic(output: Output, client: GitHubClient, target: string, parentReference: IssueReference, issueNodeId: string | (() => Promise<string>), issueUrl: string | undefined): Promise<string>;
140
145
  /**
141
146
  リポジトリがプロジェクトにリンクされていなければ、message を error に出して終了コード 1
142
147
  */
143
148
  export declare function ensureRepositoryInProject(output: Output, config: ProjectConfig, client: GitHubClient, owner: string, repository: string, message: string): Promise<void>;
144
149
  /**
150
+ クライアントを作り、リポジトリがプロジェクトにあることを確かめる。無ければ error と終了コード 1。board add・board move・issue reopen が使う
151
+ */
152
+ export declare function connectToProject(output: Output, config: ProjectConfig, owner: string, repository: string): Promise<GitHubClient>;
153
+ /**
154
+ ボードに無い status の error の文。blocked は後から足せる option なので、足し方の hint を添える
155
+ */
156
+ export declare function notConfiguredMessage(status: string): string | HintedText;
157
+ /**
145
158
  起票用のクライアントを作り、リポジトリのリンクと、親 Epic のリポジトリでの order の重複を確かめる
146
159
  */
147
- export declare function clientForIssueCreate(output: Output, config: ProjectConfig, owner: string, repository: string, display: string, parentReference: IssueReference | undefined, order: number | undefined, parallel?: string): Promise<GitHubClient>;
160
+ export declare function clientForIssueCreate(output: Output, config: ProjectConfig, owner: string, repository: string, display: string, parentReference: IssueReference | undefined, order: number | undefined): Promise<GitHubClient>;
148
161
  /**
149
162
  本文をテンプレートと比べ、違反を 1 つの error にして出す。違反があれば true。
150
163
  1 行目はテンプレートのパス。続く行に、違反のある種類だけを並べる