@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,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_DEPENDENCY_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue-dependency.d.ts.map
@@ -0,0 +1,310 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ // issue block / unblock。既存の Issue の前提(blocked by)と種類(stack / merge)を後から直し、判定・列・札・本文の節をそろえる。
3
+ import { z } from 'zod';
4
+ import { hasExpectedPrerequisites, decideBlock, decideUnblock, searchCycle } from '../domain/blocked-by-change.js';
5
+ import { decideBoardMove } from '../domain/board-move.js';
6
+ import { getOptionId } from '../domain/config.js';
7
+ import { describeReadiness, displayReference, hasStarted } from '../domain/readiness.js';
8
+ import { createIssueReference, issueReferenceKey, issueReferenceToCliReference } from '../domain/reference-parser.js';
9
+ import { createRepositoryReference } from '../domain/repository-resolver.js';
10
+ import { MAX_BLOCKED_BY } from '../infra/github/issues.js';
11
+ import { defineCommand } from './command-definition.js';
12
+ import { commandHint, hinted, inputHint, inputNameHint, joinHinted } from './command-hint.js';
13
+ import { requireActiveConfigPlain, stopWith } from './command-stop.js';
14
+ import { kindOfFailure } from './failure.js';
15
+ import { apiFailureMessage, createGitHubClient } from './github-client.js';
16
+ import { applyBoardMove } from './issue-board.js';
17
+ import { createReadinessCache, readIssueReadiness } from './issue-readiness.js';
18
+ import { ensureRepositoryInProject, ISSUE_REF_DESCRIPTION, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
19
+ import { createOutput, DRY_RUN_FIELD } from './output.js';
20
+ import { USAGE_EXIT_CODE } from './usage-error.js';
21
+ const CONTENT_EXIT_CODE = 3;
22
+ // たどる Issue の数の上限。大きな連鎖で止まらないことより、確かめずに付けないことを優先する
23
+ const MAX_CYCLE_ISSUES = 200;
24
+ const BLOCK_PATH = ['issue', 'block'];
25
+ const ISSUE_FIELD = z.string().describe('The waiting Issue (owner/repo/N)');
26
+ const BY_FIELD = z.string().describe('The prerequisite Issue (owner/repo/N)');
27
+ const ISSUE_BLOCK_OUTPUT = z.strictObject({
28
+ issue: ISSUE_FIELD,
29
+ by: BY_FIELD,
30
+ wait: z.enum(['stack', 'merge']).describe('Wait kind of the blocked-by after the command'),
31
+ change: z.enum(['added', 'updated', 'unchanged']).describe('added (new blocked-by), updated (wait kind or reason changed), or unchanged'),
32
+ dryRun: DRY_RUN_FIELD,
33
+ });
34
+ const ISSUE_UNBLOCK_OUTPUT = z.strictObject({
35
+ issue: ISSUE_FIELD,
36
+ by: BY_FIELD,
37
+ change: z.enum(['removed', 'unchanged']).describe('removed, or unchanged when it was not a blocked-by'),
38
+ dryRun: DRY_RUN_FIELD,
39
+ });
40
+ function toReference(target) {
41
+ return createIssueReference(createRepositoryReference(target.owner, target.repository), target.number);
42
+ }
43
+ async function ensureLinked(out, config, client, { owner, repository }) {
44
+ await ensureRepositoryInProject(out, config, client, owner, repository, `repository ${owner}/${repository} is not in the project`);
45
+ }
46
+ async function wrapped(out, context, run) {
47
+ try {
48
+ return await run();
49
+ }
50
+ catch (error) {
51
+ return stopWith(out, `${context}: ${apiFailureMessage(error)}`, kindOfFailure(error));
52
+ }
53
+ }
54
+ function isOptionAvailable(config, field, key) {
55
+ const option = getOptionId(config, field, key);
56
+ return option !== undefined && option !== '';
57
+ }
58
+ function hintFor(value) {
59
+ return hinted `hint: run ${commandHint(['project', 'init'])} to add the ${value} option to the board`;
60
+ }
61
+ function boardMoveInput(judged, config, hasPrerequisites) {
62
+ const { target } = judged;
63
+ return {
64
+ eligible: target.state === 'open' && target.kind === 'task',
65
+ column: target.column,
66
+ label: target.label,
67
+ hasStarted: hasStarted(target),
68
+ hasPrerequisites,
69
+ readiness: judged.readiness,
70
+ // spec 023 が入るまで、札はこの機能が書いたものとして扱う
71
+ labelWrittenByAutomation: false,
72
+ available: {
73
+ blocked: isOptionAvailable(config, 'workflow', 'blocked'),
74
+ needsAttention: isOptionAvailable(config, 'status', 'needs_attention'),
75
+ todo: isOptionAvailable(config, 'status', 'todo'),
76
+ },
77
+ };
78
+ }
79
+ // 書いた内容が読み直しに出るまで 1 回だけ読み直す。GitHub は書いた直後の読み取りの一致を保証しない
80
+ async function readConfirmed(context, expected) {
81
+ const name = displayReference(context.target, context.home);
82
+ for (let attempt = 0; attempt < 2; attempt += 1) {
83
+ const result = await readIssueReadiness(context.client, context.config, context.target, createReadinessCache());
84
+ if (result.kind === 'unreadable')
85
+ return { failure: `could not judge readiness of ${name}: ${result.reason}` };
86
+ if (hasExpectedPrerequisites(result.prerequisites, expected))
87
+ return { judged: result };
88
+ }
89
+ return { failure: `could not confirm that GitHub reflects the blocked-by change of ${name}` };
90
+ }
91
+ // 書いた後の判定で、列と札を動かす。読めない・確かめられないときは動かさず warning にする(前提の変更は済んでいる)
92
+ async function moveBoard(context, expected, hasPrerequisites) {
93
+ const { out, client, config, home, target } = context;
94
+ const name = displayReference(target, home);
95
+ const read = await readConfirmed(context, expected);
96
+ if ('failure' in read) {
97
+ out.warning(`${read.failure}; the column and label of ${name} were not moved`);
98
+ return;
99
+ }
100
+ const { judged } = read;
101
+ if (judged.readiness === undefined)
102
+ return;
103
+ const move = decideBoardMove(boardMoveInput(judged, config, hasPrerequisites));
104
+ if (move === undefined)
105
+ return;
106
+ const hasWrite = move.column !== undefined || move.label !== undefined;
107
+ let itemId = '';
108
+ try {
109
+ if (hasWrite)
110
+ itemId = await client.getItemIdByIssue(config.project.id, target.repository.owner, target.repository.repository, target.number) ?? '';
111
+ }
112
+ catch (error) {
113
+ out.warning(`could not move ${name}: ${apiFailureMessage(error)}`);
114
+ return;
115
+ }
116
+ if (hasWrite && itemId === '')
117
+ return;
118
+ const { missing } = await applyBoardMove(out, client, config, itemId, { ref: target, home }, move, describeReadiness(judged.readiness, judged.prerequisites, home));
119
+ for (const value of missing) {
120
+ out.warning(joinHinted([`the ${value} option is not on the board, so ${name} was not moved`, hintFor(value)]));
121
+ }
122
+ }
123
+ function keysOf(issues) {
124
+ return new Set(issues.map(issue => issueReferenceKey({ repository: issue.repository, number: issue.number })));
125
+ }
126
+ function checkBlockUsage(out, input, target, by) {
127
+ const reason = input.reason?.trim();
128
+ const reasonFlag = inputNameHint(BLOCK_PATH, 'reason');
129
+ const waitMerge = inputHint(BLOCK_PATH, 'wait', 'merge');
130
+ if (input.wait === 'merge' && (reason === undefined || reason === ''))
131
+ stopWith(out, hinted `${reasonFlag} is required with ${waitMerge}`, 'invalid-input', USAGE_EXIT_CODE);
132
+ if (input.wait === 'stack' && input.reason !== undefined)
133
+ stopWith(out, hinted `${reasonFlag} is only valid with ${waitMerge}`, 'invalid-input', USAGE_EXIT_CODE);
134
+ if (reason !== undefined && /[\r\n]/u.test(reason))
135
+ stopWith(out, hinted `${reasonFlag} must be a single line`, 'invalid-input', USAGE_EXIT_CODE);
136
+ if (issueReferenceKey(target) === issueReferenceKey(by)) {
137
+ const name = displayReference(target, target.repository);
138
+ stopWith(out, `blocked-by would form a cycle: ${name} -> ${name}`, 'dependency-rejected', USAGE_EXIT_CODE);
139
+ }
140
+ return reason;
141
+ }
142
+ async function checkNoCycle(context, byId) {
143
+ const { out, client, target, home } = context;
144
+ const result = await wrapped(out, `could not check blocked-by cycle of ${displayReference(target, home)}`, async () => await searchCycle({
145
+ target,
146
+ by: context.by,
147
+ byId,
148
+ read: async (ids) => await client.getBlockedByOfNodes(ids),
149
+ limit: MAX_CYCLE_ISSUES,
150
+ }));
151
+ if (result.kind === 'cycle')
152
+ stopWith(out, `blocked-by would form a cycle: ${result.path.map(reference => displayReference(reference, home)).join(' -> ')}`, 'dependency-rejected', USAGE_EXIT_CODE);
153
+ else if (result.kind === 'unverifiable')
154
+ stopWith(out, `could not check blocked-by cycle of ${displayReference(target, home)}: ${result.reason}`, 'dependency-unreadable');
155
+ }
156
+ async function runBlock(out, input) {
157
+ const config = requireActiveConfigPlain(out);
158
+ const targetIssue = parseIssueReferenceOrExit(out, input.repo, input.issue_ref);
159
+ const byIssue = parseIssueReferenceOrExit(out, input.repo, input.by);
160
+ const target = toReference(targetIssue);
161
+ const by = toReference(byIssue);
162
+ const reason = checkBlockUsage(out, input, target, by);
163
+ const client = createGitHubClient(out, config.host);
164
+ await ensureLinked(out, config, client, targetIssue);
165
+ const home = target.repository;
166
+ const context = { out, client, config, home, target, by };
167
+ const name = displayReference(target, home);
168
+ const byName = displayReference(by, home);
169
+ const read = await wrapped(out, `could not read blocked-by of ${name}`, async () => await client.getIssueBlockedByReferences(targetIssue.owner, targetIssue.repository, targetIssue.number));
170
+ if (read.blockedBy.kind === 'read-failed')
171
+ stopWith(out, `could not read blocked-by of ${name}: ${read.blockedBy.reason}`, 'dependency-unreadable');
172
+ const { issues, total } = read.blockedBy;
173
+ const linked = issues.find(issue => issueReferenceKey({ repository: issue.repository, number: issue.number }) === issueReferenceKey(by));
174
+ if (linked === undefined && total >= MAX_BLOCKED_BY)
175
+ stopWith(out, `${name} already has ${String(MAX_BLOCKED_BY)} blocked-by issues`, 'dependency-rejected');
176
+ const decision = decideBlock({ body: read.body, home, by, wait: input.wait, reason, isLinked: linked !== undefined });
177
+ const result = { issue: issueReferenceToCliReference(target), by: issueReferenceToCliReference(by), wait: input.wait };
178
+ if (decision.kind === 'malformed') {
179
+ stopWith(out, `Waits for merge of ${name} is malformed: ${decision.reason}; fix the section in the Issue body and run the command again`, 'content-invalid', CONTENT_EXIT_CODE);
180
+ }
181
+ else if (decision.kind === 'unchanged') {
182
+ out.result({ ...result, change: 'unchanged' });
183
+ out.planned({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
184
+ out.done({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
185
+ return;
186
+ }
187
+ let byId = linked?.id;
188
+ if (decision.kind === 'add') {
189
+ byId = await wrapped(out, `could not read ${displayReference(by, home)}`, async () => await client.getIssueNodeId(byIssue.owner, byIssue.repository, byIssue.number));
190
+ await checkNoCycle(context, byId);
191
+ }
192
+ const operation = decision.kind === 'add'
193
+ ? { verb: 'add', target: `blocked-by ${byName} to ${name}` }
194
+ : { verb: 'update', target: `blocked-by ${byName} on ${name} (wait: ${input.wait})` };
195
+ out.planned(operation);
196
+ const change = decision.kind === 'add' ? 'added' : 'updated';
197
+ if (input.dry_run) {
198
+ out.result({ ...result, change });
199
+ return;
200
+ }
201
+ if (byId !== undefined && decision.kind === 'add') {
202
+ const blockingId = byId;
203
+ await wrapped(out, `could not add blocked-by ${byName} to ${name}`, async () => {
204
+ await client.addBlockedBy(read.id, blockingId);
205
+ });
206
+ out.done(operation);
207
+ }
208
+ if (decision.body !== read.body) {
209
+ const message = `could not update the body of ${name}${decision.kind === 'add' ? `; blocked-by ${byName} was added, run the command again to write the section` : ''}`;
210
+ await wrapped(out, message, async () => {
211
+ await client.updateIssueBody(targetIssue.owner, targetIssue.repository, targetIssue.number, decision.body);
212
+ });
213
+ }
214
+ if (decision.kind === 'update')
215
+ out.done(operation);
216
+ out.result({ ...result, change });
217
+ const keys = new Set([...keysOf(issues), issueReferenceKey(by)]);
218
+ await moveBoard(context, { keys, by, wait: { wait: input.wait, reason } }, true);
219
+ }
220
+ async function runUnblock(out, input) {
221
+ const config = requireActiveConfigPlain(out);
222
+ const targetIssue = parseIssueReferenceOrExit(out, input.repo, input.issue_ref);
223
+ const byIssue = parseIssueReferenceOrExit(out, input.repo, input.by);
224
+ const target = toReference(targetIssue);
225
+ const by = toReference(byIssue);
226
+ const client = createGitHubClient(out, config.host);
227
+ await ensureLinked(out, config, client, targetIssue);
228
+ const home = target.repository;
229
+ const context = { out, client, config, home, target, by };
230
+ const name = displayReference(target, home);
231
+ const byName = displayReference(by, home);
232
+ const read = await wrapped(out, `could not read blocked-by of ${name}`, async () => await client.getIssueBlockedByReferences(targetIssue.owner, targetIssue.repository, targetIssue.number));
233
+ if (read.blockedBy.kind === 'read-failed')
234
+ stopWith(out, `could not read blocked-by of ${name}: ${read.blockedBy.reason}`, 'dependency-unreadable');
235
+ const { issues, total } = read.blockedBy;
236
+ const linked = issues.find(issue => issueReferenceKey({ repository: issue.repository, number: issue.number }) === issueReferenceKey(by));
237
+ if (linked === undefined && total > issues.length)
238
+ stopWith(out, `could not read blocked-by of ${name}: ${String(issues.length)} of ${String(total)} issues were read`, 'dependency-unreadable');
239
+ const decision = decideUnblock({ body: read.body, home, by, isLinked: linked !== undefined });
240
+ const result = { issue: issueReferenceToCliReference(target), by: issueReferenceToCliReference(by) };
241
+ if (linked === undefined || decision.kind === 'unchanged') {
242
+ out.result({ ...result, change: 'unchanged' });
243
+ out.planned({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
244
+ out.done({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
245
+ return;
246
+ }
247
+ const operation = { verb: 'remove', target: `blocked-by ${byName} from ${name}` };
248
+ out.planned(operation);
249
+ if (input.dry_run) {
250
+ out.result({ ...result, change: 'removed' });
251
+ return;
252
+ }
253
+ await wrapped(out, `could not remove blocked-by ${byName} from ${name}`, async () => {
254
+ await client.removeBlockedBy(read.id, linked.id);
255
+ });
256
+ out.done(operation);
257
+ out.result({ ...result, change: 'removed' });
258
+ if (decision.malformedReason !== undefined) {
259
+ out.warning(`Waits for merge of ${name} is malformed: ${decision.malformedReason}; the section was not changed`);
260
+ }
261
+ else if (decision.body !== read.body) {
262
+ await wrapped(out, `could not update the body of ${name}; blocked-by ${byName} was removed`, async () => {
263
+ await client.updateIssueBody(targetIssue.owner, targetIssue.repository, targetIssue.number, decision.body);
264
+ });
265
+ }
266
+ const remaining = issues.filter(issue => issue.id !== linked.id);
267
+ // 人が別の理由で付けた札を、最後の前提を外しただけで戻さない
268
+ const hasPrerequisites = remaining.length > 0 || linked.state === 'CLOSED';
269
+ await moveBoard(context, { keys: keysOf(remaining), by, wait: undefined }, hasPrerequisites);
270
+ }
271
+ const ISSUE_BLOCK = defineCommand({
272
+ path: BLOCK_PATH,
273
+ description: 'Add a blocked-by (prerequisite) to an Issue, or change the wait kind and reason of an existing one',
274
+ input: z.object({
275
+ issue_ref: z.string().describe(`The waiting Issue. ${ISSUE_REF_DESCRIPTION}`),
276
+ by: z.string().describe('The Issue to wait for (`owner/repo/N`; another repository is allowed)'),
277
+ wait: z.enum(['stack', 'merge']).default('stack').describe('stack (build on its branch) or merge (wait until it is merged)'),
278
+ reason: z.string().optional().describe('Why it waits for the merge (required with --wait merge)'),
279
+ dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
280
+ }),
281
+ output: ISSUE_BLOCK_OUTPUT,
282
+ positional: ['issue_ref'],
283
+ interactive: false,
284
+ run: async (input, io) => {
285
+ const out = createOutput(input.dry_run, io);
286
+ return await runWithExit(async () => {
287
+ await runBlock(out, input);
288
+ });
289
+ },
290
+ });
291
+ const ISSUE_UNBLOCK = defineCommand({
292
+ path: ['issue', 'unblock'],
293
+ description: 'Remove a blocked-by (prerequisite) from an Issue',
294
+ input: z.object({
295
+ issue_ref: z.string().describe(`The waiting Issue. ${ISSUE_REF_DESCRIPTION}`),
296
+ by: z.string().describe('The prerequisite Issue to remove (`owner/repo/N`; another repository is allowed)'),
297
+ dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
298
+ }),
299
+ output: ISSUE_UNBLOCK_OUTPUT,
300
+ positional: ['issue_ref'],
301
+ interactive: false,
302
+ run: async (input, io) => {
303
+ const out = createOutput(input.dry_run, io);
304
+ return await runWithExit(async () => {
305
+ await runUnblock(out, input);
306
+ });
307
+ },
308
+ });
309
+ export const ISSUE_DEPENDENCY_COMMANDS = [ISSUE_BLOCK, ISSUE_UNBLOCK];
310
+ //# sourceMappingURL=issue-dependency.js.map
@@ -0,0 +1,122 @@
1
+ import { z } from 'zod';
2
+ import type { ProjectConfig } from '../domain/config.js';
3
+ import type { FactsMismatch, IssueFacts, IssuePullRequest, Prerequisite, Readiness } from '../domain/readiness.js';
4
+ import type { IssueReference } from '../domain/reference-parser.js';
5
+ import type { GitHubClient } from '../infra/github/index.js';
6
+ /**
7
+ 一覧の前提の件数から、個別に読む前提の件数を決める。件数が一覧に無ければ undefined(上限で読む)
8
+ */
9
+ export declare function blockedByReadCount(listed: number | undefined): number | undefined;
10
+ /**
11
+ head のブランチ名で引いた PR の取得結果を、1 回の実行の中で使い回す入れ物。キーは `owner/repo:head`
12
+ */
13
+ export type ReadinessCache = Map<string, Promise<IssuePullRequest | undefined>>;
14
+ export declare function createReadinessCache(): ReadinessCache;
15
+ /**
16
+ 前提まで読んだ Issue。判定の前の段階で、輪の検出に使う辺を取り出せる
17
+ */
18
+ export interface IssueSnapshot {
19
+ readonly kind: 'snapshot';
20
+ readonly ref: IssueReference;
21
+ readonly title: string;
22
+ readonly target: IssueFacts;
23
+ /**
24
+ 読めた前提。blockedBy の読み取りが失敗した Issue は、ここまで来ずに読めない理由で返る
25
+ */
26
+ readonly prerequisites: readonly Prerequisite[];
27
+ /**
28
+ 前提の title(issueReferenceKey → title)
29
+ */
30
+ readonly titles: ReadonlyMap<string, string>;
31
+ readonly mismatches: readonly FactsMismatch[];
32
+ /**
33
+ 本文の `## Waits for merge` の節が読めないときの理由
34
+ */
35
+ readonly malformedReason: string | undefined;
36
+ readonly parent: IssueReference | undefined;
37
+ /**
38
+ 対象のリポジトリの develop_branch。未設定なら undefined
39
+ */
40
+ readonly developmentBranch: string | undefined;
41
+ }
42
+ export interface UnreadableIssue {
43
+ readonly kind: 'unreadable';
44
+ readonly reason: string;
45
+ /**
46
+ 前提まで読めていたときの読み取り結果。判定だけが読めなかった(develop_branch が無い、PR の引き足しに失敗した)ときに付く
47
+ */
48
+ readonly snapshot?: IssueSnapshot;
49
+ }
50
+ export interface JudgedIssue extends Omit<IssueSnapshot, 'developmentBranch' | 'kind'> {
51
+ readonly kind: 'judged';
52
+ /**
53
+ Epic と Tracker は undefined
54
+ */
55
+ readonly readiness: Readiness | undefined;
56
+ }
57
+ export type IssueReadiness = JudgedIssue | UnreadableIssue;
58
+ /**
59
+ 対象の Issue と前提を読む。API の失敗と blockedBy の読み取りの失敗は、読めない理由で返す。
60
+ DependenciesUnsupportedError は GitHubAPIError だが、対応しない GHES を呼ぶ側で見分けるため、そのまま投げる
61
+ */
62
+ export declare function readIssueSnapshot(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, blockedByFirst?: number): Promise<IssueSnapshot | UnreadableIssue>;
63
+ /**
64
+ 前提の無い Issue の読み取り結果。一覧の値から作るので、API は呼ばない
65
+ */
66
+ export declare function snapshotWithoutPrerequisites(config: ProjectConfig, input: {
67
+ readonly title: string;
68
+ readonly target: IssueFacts;
69
+ readonly parent: IssueReference | undefined;
70
+ }): IssueSnapshot;
71
+ /**
72
+ Issue の前提の辺(対象のキー → 前提のキー)。輪の検出に使う
73
+ */
74
+ export declare function prerequisiteKeys(snapshot: Readonly<IssueSnapshot>): readonly string[];
75
+ /**
76
+ 前提を判定する。cycle は呼ぶ側が findCycle で求めた輪。
77
+ develop_branch が無いときと、PR の引き足しの API が失敗したときは、読み取り結果を添えた unreadable を返す。
78
+ DependenciesUnsupportedError はそのまま投げる。
79
+ 前提の PR が開発ブランチに届かないときだけ、base のブランチを head に持つ PR を引き足して、判定をやり直す
80
+ */
81
+ export declare function judgeSnapshot(client: Readonly<GitHubClient>, snapshot: Readonly<IssueSnapshot>, cache: ReadinessCache, cycle?: readonly string[]): Promise<IssueReadiness>;
82
+ /**
83
+ 判定済みの Issue の前提を assume で置き換え、同じ judgeSnapshot で判定し直す。API は、積んだ並びを引き足すときだけ呼ぶ
84
+ */
85
+ export declare function judgeAssuming(client: Readonly<GitHubClient>, config: ProjectConfig, judged: Readonly<JudgedIssue>, assume: (prerequisites: readonly Prerequisite[]) => readonly Prerequisite[], cache: ReadinessCache): Promise<IssueReadiness>;
86
+ /**
87
+ Issue 1 件の読み取りから判定までを通す。輪は呼ぶ側が渡す(issue show は輪を見ない)
88
+ */
89
+ export declare function readIssueReadiness(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, cache: ReadinessCache, cycle?: readonly string[], blockedByFirst?: number): Promise<IssueReadiness>;
90
+ /**
91
+ readinessJson の形。キーの並びは readinessJson と同じにする
92
+ */
93
+ export declare const READINESS_JSON: z.ZodObject<{
94
+ kind: z.ZodEnum<{
95
+ blocked: "blocked";
96
+ stackable: "stackable";
97
+ startable: "startable";
98
+ }>;
99
+ stackOn: z.ZodNullable<z.ZodObject<{
100
+ number: z.ZodInt;
101
+ repository: z.ZodString;
102
+ branch: z.ZodString;
103
+ }, z.core.$strict>>;
104
+ reason: z.ZodNullable<z.ZodString>;
105
+ text: z.ZodString;
106
+ }, z.core.$strict>;
107
+ export type ReadinessJson = z.input<typeof READINESS_JSON>;
108
+ /**
109
+ board show の判定。前提を読めなかった Issue の kind は unknown
110
+ */
111
+ export type BoardReadinessJson = Omit<ReadinessJson, 'kind'> & {
112
+ readonly kind: ReadinessJson['kind'] | 'unknown';
113
+ };
114
+ /**
115
+ JSON の出力に使う判定。reason は blocked のときだけの理由のコード、stackOn は積む先
116
+ */
117
+ export declare function readinessJson(readiness: Readonly<Readiness>, text: string): ReadinessJson;
118
+ /**
119
+ readIssueReadiness の、依存関係を持たない GHES を判定なしで通す形。GHES なら undefined を返し、onUnsupported に理由を渡す
120
+ */
121
+ export declare function readIssueReadinessIfSupported(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, cache: ReadinessCache, onUnsupported?: (reason: string) => void): Promise<IssueReadiness | undefined>;
122
+ //# sourceMappingURL=issue-readiness.d.ts.map