@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
@@ -110,12 +110,46 @@ export function transformItems(rawItems, workflowFieldName) {
110
110
  }
111
111
  return transformed;
112
112
  }
113
+ function countMember(value, key) {
114
+ const found = member(member(value, key), 'totalCount');
115
+ return typeof found === 'number' ? found : undefined;
116
+ }
117
+ function parentOf(content) {
118
+ const parent = member(content, 'parent');
119
+ const repository = extractRepository(parent);
120
+ const number = member(parent, 'number');
121
+ return repository === '' || typeof number !== 'number' ? undefined : { repository, number };
122
+ }
123
+ /**
124
+ 一覧の応答から、Issue ごとの着手の判定の入力を取る。キーは boardItemKey と同じ。Issue 以外と、番号の無いものは含めない
125
+ */
126
+ export function readBoardProgress(rawItems, labelFieldName) {
127
+ const progress = new Map();
128
+ for (const item of rawItems) {
129
+ const content = member(item, 'content');
130
+ if (isEmptyValue(content) || member(content, 'blockedBy') === undefined)
131
+ continue;
132
+ const key = boardItemKey({ content: { number: member(content, 'number'), repository: extractRepository(content) } });
133
+ if (key === undefined)
134
+ continue;
135
+ const issueType = member(member(content, 'issueType'), 'name');
136
+ const blockedBy = member(member(content, 'blockedBy'), 'totalCount');
137
+ progress.set(key, {
138
+ issueType: typeof issueType === 'string' ? issueType : undefined,
139
+ subIssues: countMember(content, 'subIssues') ?? 0,
140
+ parent: parentOf(content),
141
+ blockedBy: typeof blockedBy === 'number' ? blockedBy : undefined,
142
+ label: extractWorkflowStatus(item, labelFieldName),
143
+ });
144
+ }
145
+ return progress;
146
+ }
113
147
  /**
114
- 1 アイテムを Markdown 表の行 `| Ref | Title |` にする。
148
+ 1 アイテムを Markdown 表の行 `| Ref | Title |` にする。extraCells は、Title の後ろに足すセル。
115
149
  Ref は GitHub 慣習に倣い `owner/repo#N` で合成する。
116
150
  リポジトリ情報または番号が欠落している場合は可能な範囲で埋め、両方欠落しているときは `-` を表示する
117
151
  */
118
- export function formatTableRow(item) {
152
+ export function formatTableRow(item, extraCells = []) {
119
153
  const { number } = item.content;
120
154
  const repository = item.content.repository ?? '';
121
155
  const numberText = number === undefined || number === null ? '' : displayText(number);
@@ -128,7 +162,7 @@ export function formatTableRow(item) {
128
162
  reference = `#${numberText}`;
129
163
  const { title } = item;
130
164
  const titleText = title === undefined || isEmptyValue(title) ? '-' : displayText(title);
131
- return `| ${reference} | ${titleText} |`;
165
+ return `| ${[reference, titleText, ...extraCells].join(' | ')} |`;
132
166
  }
133
167
  function updatedAtOf(item) {
134
168
  return typeof item.updatedAt === 'string' ? item.updatedAt : '';
@@ -141,10 +175,27 @@ function newestFirst(first, second) {
141
175
  return a < b ? 1 : -1;
142
176
  }
143
177
  /**
178
+ 判定の文の表(readiness 引数)を引くキー。`owner/repo#N` の小文字で、issueReferenceKey と同じ形になる。
179
+ リポジトリか番号が欠けたアイテムは undefined
180
+ */
181
+ export function boardItemKey(item) {
182
+ const { number } = item.content;
183
+ const repository = item.content.repository ?? '';
184
+ return repository === '' || number === undefined || number === null ? undefined : `${repository}#${displayText(number)}`.toLowerCase();
185
+ }
186
+ // 判定の列を足す節(Ready・Blocked)
187
+ const READINESS_STATUSES = new Set(['Ready', 'Blocked']);
188
+ function readinessCell(item, readiness) {
189
+ const key = boardItemKey(item);
190
+ return (key === undefined ? undefined : readiness.get(key)) ?? '-';
191
+ }
192
+ /**
144
193
  プロジェクトボードを Markdown 形式で出力する。件数が 0 のステータスは出さない。
145
- Archived は 6 件以上あるとき、更新が新しい直近 5 件だけを出す
194
+ Archived は 6 件以上あるとき、更新が新しい直近 5 件だけを出す。
195
+ readiness(boardItemKey → 判定の文)を渡したときだけ、Ready と Blocked の節に Readiness の列を足す。
196
+ 表に無いアイテムのセルは `-`
146
197
  */
147
- export function formatBoardOutput(items) {
198
+ export function formatBoardOutput(items, readiness) {
148
199
  const sections = [];
149
200
  for (const status of STATUS_ORDER) {
150
201
  const patterns = STATUS_PATTERNS.get(status) ?? [];
@@ -155,11 +206,26 @@ export function formatBoardOutput(items) {
155
206
  const isTruncated = status === 'Archived' && totalCount > ARCHIVED_DISPLAY_LIMIT;
156
207
  const displayItems = isTruncated ? statusItems.toSorted(newestFirst).slice(0, ARCHIVED_DISPLAY_LIMIT) : statusItems;
157
208
  const heading = isTruncated ? `### ${status} (latest ${String(ARCHIVED_DISPLAY_LIMIT)} of ${String(totalCount)})` : `### ${status} (${String(totalCount)})`;
158
- sections.push([heading, '| Ref | Title |', '|-----|----------|', ...displayItems.map(item => formatTableRow(item))]);
209
+ if (readiness !== undefined && READINESS_STATUSES.has(status)) {
210
+ const rows = displayItems.map(item => formatTableRow(item, [readinessCell(item, readiness)]));
211
+ sections.push([heading, '| Ref | Title | Readiness |', '|-----|----------|-----------|', ...rows]);
212
+ }
213
+ else {
214
+ sections.push([heading, '| Ref | Title |', '|-----|----------|', ...displayItems.map(item => formatTableRow(item))]);
215
+ }
159
216
  }
160
217
  return sections.length === 0 ? '_No items_' : sections.map(section => section.join('\n')).join('\n\n');
161
218
  }
162
219
  /**
220
+ `## Stackable chains` の節を作る。1 行が 1 つの並びで、並びが無ければ undefined
221
+ */
222
+ export function formatStackableChains(chains) {
223
+ if (chains.length === 0)
224
+ return undefined;
225
+ const lines = chains.map(({ epic = '(no epic)', chain }) => `- ${epic}: ${chain.join(' -> ')}`);
226
+ return ['## Stackable chains', '', ...lines].join('\n');
227
+ }
228
+ /**
163
229
  アイテムリストを JSON 出力用の辞書にする
164
230
  */
165
231
  export function formatItemsJson(items) {
@@ -1,6 +1,14 @@
1
1
  import { z } from 'zod';
2
2
  import { PecotError } from './errors.js';
3
+ /**
4
+ コマンドが契約の文を作る誤り。`parallel` は使えなくなった項目、`merge-without-reason` は理由の無い `wait: merge`
5
+ */
6
+ export type FrontmatterErrorKind = 'parallel' | 'merge-without-reason';
3
7
  export declare class FrontmatterError extends PecotError {
8
+ readonly kind: FrontmatterErrorKind | undefined;
9
+ constructor(message: string, options?: Readonly<ErrorOptions & {
10
+ kind?: FrontmatterErrorKind;
11
+ }>);
4
12
  }
5
13
  declare const IssueFrontmatterSchema: z.ZodReadonly<z.ZodObject<{
6
14
  title: z.ZodString;
@@ -18,7 +26,7 @@ declare const IssueFrontmatterSchema: z.ZodReadonly<z.ZodObject<{
18
26
  tracker: "tracker";
19
27
  }>>>, z.ZodTransform<"bug" | "epic" | "task" | "task-implement" | "tracker" | undefined, "bug" | "epic" | "task" | "task-implement" | "tracker" | null | undefined>>, unknown>;
20
28
  repository: z.ZodString;
21
- status: z.ZodEnum<{
29
+ status: z.ZodOptional<z.ZodEnum<{
22
30
  active: "active";
23
31
  archived: "archived";
24
32
  backlog: "backlog";
@@ -26,7 +34,15 @@ declare const IssueFrontmatterSchema: z.ZodReadonly<z.ZodObject<{
26
34
  in_review: "in_review";
27
35
  pending: "pending";
28
36
  ready: "ready";
29
- }>;
37
+ }>>;
38
+ blocked_by: z.ZodPreprocess<z.ZodPrefault<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
39
+ issue: z.ZodPreprocess<z.ZodString, unknown>;
40
+ wait: z.ZodPrefault<z.ZodEnum<{
41
+ merge: "merge";
42
+ stack: "stack";
43
+ }>>;
44
+ reason: z.ZodPreprocess<z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>, unknown>;
45
+ }, z.core.$strip>>>>>, unknown>;
30
46
  priority: z.ZodPreprocess<z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
31
47
  high: "high";
32
48
  low: "low";
@@ -41,7 +57,6 @@ declare const IssueFrontmatterSchema: z.ZodReadonly<z.ZodObject<{
41
57
  labels: z.ZodPrefault<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
42
58
  parent_epic: z.ZodPreprocess<z.ZodPipe<z.ZodUnknown, z.ZodTransform<string | number | undefined, unknown>>, unknown>;
43
59
  order: z.ZodPreprocess<z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodNumber>>, z.ZodTransform<number | undefined, number | null | undefined>>, unknown>;
44
- parallel: z.ZodPreprocess<z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>, unknown>;
45
60
  }, z.core.$strip>>;
46
61
  declare const CommentFrontmatterSchema: z.ZodReadonly<z.ZodObject<{
47
62
  issue_ref: z.ZodString;
@@ -10,12 +10,18 @@ import { PecotError } from './errors.js';
10
10
  import { normalizeNewlines, parsePythonInteger, pythonStrip, pythonStringRepr } from './python-format.js';
11
11
  import { parseYamlDocument } from './yaml-document.js';
12
12
  export class FrontmatterError extends PecotError {
13
+ kind;
14
+ constructor(message, options) {
15
+ super(message, options);
16
+ this.kind = options?.kind;
17
+ }
13
18
  }
14
19
  // 検証のエラー文
15
20
  const REQUIRED_MESSAGE = 'Field required';
16
21
  const STRING_MESSAGE = 'Input should be a valid string';
17
22
  const LIST_MESSAGE = 'Input should be a valid list';
18
- const PARALLEL_MESSAGE = 'String should match pattern \'^[a-z]$\'';
23
+ const SINGLE_LINE_MESSAGE = 'Value error, reason must be a single line';
24
+ const NOT_EMPTY_MESSAGE = 'String should have at least 1 character';
19
25
  function quotedChoices(values) {
20
26
  const quoted = values.map(value => pythonStringRepr(String(value)));
21
27
  const last = quoted.at(-1);
@@ -86,12 +92,21 @@ function normalizeParentEpic(value) {
86
92
  const IntegerSchema = z.number({ error: issue => integerMessage(issue.input) }).refine(Number.isSafeInteger, { error: issue => integerMessage(issue.input) });
87
93
  const IssueTypeSchema = z.enum(['task', 'bug', 'epic', 'tracker'], { error: choiceMessage });
88
94
  const WorkflowStatusSchema = z.enum(WORKFLOW_STATUSES, { error: choiceMessage });
95
+ function stripString(value) {
96
+ return typeof value === 'string' ? pythonStrip(value) : value;
97
+ }
98
+ const BlockedByEntrySchema = z.object({
99
+ issue: z.preprocess(stripString, z.string({ error: stringMessage }).min(1, { error: NOT_EMPTY_MESSAGE })),
100
+ wait: z.enum(['stack', 'merge'], { error: choiceMessage }).prefault('stack'),
101
+ reason: z.preprocess(normalizeOptionalText, z.string({ error: stringMessage }).refine(value => !/[\r\n]/u.test(value), { error: SINGLE_LINE_MESSAGE }).nullish().transform(value => value ?? undefined)),
102
+ }).readonly();
89
103
  const IssueFrontmatterSchema = z.object({
90
104
  title: z.string({ error: stringMessage }),
91
105
  type: IssueTypeSchema,
92
106
  template: z.preprocess(emptyStringToUndefined, z.enum(['task', 'bug', 'epic', 'tracker', 'task-implement'], { error: choiceMessage }).nullish().transform(value => value ?? undefined)),
93
107
  repository: z.string({ error: stringMessage }),
94
- status: WorkflowStatusSchema,
108
+ status: WorkflowStatusSchema.optional(),
109
+ blocked_by: z.preprocess(value => value === null ? undefined : value, z.array(BlockedByEntrySchema, { error: listMessage }).readonly().prefault([])),
95
110
  priority: z.preprocess(emptyStringToUndefined, z.enum(PRIORITIES, { error: choiceMessage }).nullish().transform(value => value ?? undefined)),
96
111
  size: z.preprocess(emptyStringToUndefined, z.enum(SIZES, { error: choiceMessage }).nullish().transform(value => value ?? undefined)),
97
112
  labels: z.array(z.string({ error: STRING_MESSAGE }), { error: listMessage }).readonly().prefault([]),
@@ -103,7 +118,6 @@ const IssueFrontmatterSchema = z.object({
103
118
  return z.NEVER;
104
119
  })),
105
120
  order: z.preprocess(value => convertToInteger(emptyStringToUndefined(value)), IntegerSchema.nullish().transform(value => value ?? undefined)),
106
- parallel: z.preprocess(emptyStringToUndefined, z.string({ error: STRING_MESSAGE }).regex(/^[a-z]$/u, { error: PARALLEL_MESSAGE }).nullish().transform(value => value ?? undefined)),
107
121
  }).readonly();
108
122
  const CommentFrontmatterSchema = z.object({
109
123
  issue_ref: z.string({ error: stringMessage }),
@@ -127,29 +141,41 @@ function validationError(lines) {
127
141
  function fieldErrors(issues) {
128
142
  return validationError(issues.map(issue => issueLine(issue)));
129
143
  }
130
- // parent_epic と order の相互検証。項目の誤りが無いときだけ行う
131
- function checkOrderWithParentEpic(frontmatter) {
132
- const { parent_epic: parentEpic, order, parallel } = frontmatter;
144
+ // parent_epic・order・blocked_by・status の相互検証。項目の誤りが無いときだけ行う
145
+ function checkCrossFields(frontmatter) {
146
+ const { parent_epic: parentEpic, order, blocked_by: blockedBy, status, type } = frontmatter;
147
+ if (blockedBy.some(entry => entry.wait === 'merge' && entry.reason === undefined)) {
148
+ throw new FrontmatterError('blocked_by needs reason for wait: merge', { kind: 'merge-without-reason' });
149
+ }
133
150
  let message;
134
- if (parentEpic !== undefined && order === undefined)
135
- message = 'order is required when parent_epic is set';
136
- else if (parentEpic === undefined && order !== undefined)
151
+ if (parentEpic === undefined && order !== undefined)
137
152
  message = 'parent_epic is required when order is set';
138
153
  else if (order !== undefined && order <= 0)
139
154
  message = `order must be an integer of 1 or more: ${String(order)}`;
140
- else if (parallel !== undefined && order === undefined)
141
- message = 'order is required when parallel is set';
155
+ else if (blockedBy.length > 0 && (type === 'epic' || type === 'tracker'))
156
+ message = `blocked_by cannot be set for type ${type}`;
157
+ else if (status === 'ready' && blockedBy.length > 0)
158
+ message = 'status: ready cannot be set together with blocked_by';
159
+ else if (status === 'blocked' && blockedBy.length === 0)
160
+ message = 'status: blocked requires blocked_by';
142
161
  if (message !== undefined)
143
162
  throw validationError([` - : Value error, ${message}`]);
144
163
  }
164
+ function hasParallel(data) {
165
+ const value = typeof data === 'object' && data !== null && 'parallel' in data ? data.parallel : undefined;
166
+ return typeof value === 'string' ? value !== '' : value !== undefined && value !== null;
167
+ }
145
168
  /**
146
169
  値から Issue のフロントマターを作る。不正なら FrontmatterError
147
170
  */
148
171
  export function validateIssueFrontmatter(data) {
172
+ // 使えなくなった項目の案内は、ほかの誤りと重なっても先に出す
173
+ if (hasParallel(data))
174
+ throw new FrontmatterError('parallel is no longer supported', { kind: 'parallel' });
149
175
  const result = IssueFrontmatterSchema.safeParse(data);
150
176
  if (!result.success)
151
177
  throw fieldErrors(result.error.issues);
152
- checkOrderWithParentEpic(result.data);
178
+ checkCrossFields(result.data);
153
179
  return result.data;
154
180
  }
155
181
  /**
@@ -0,0 +1,55 @@
1
+ export interface SubIssueTitle {
2
+ readonly number: number;
3
+ readonly state: string;
4
+ readonly title: string;
5
+ }
6
+ export interface UsedOrder {
7
+ readonly number: number;
8
+ readonly state: string;
9
+ readonly title: string;
10
+ /**
11
+ タイトルの番号。枝の文字は数えない
12
+ */
13
+ readonly order: number;
14
+ }
15
+ /**
16
+ サブタスクのうち、タイトルが親 Epic の番号付きのものを、使われた番号にする
17
+ */
18
+ export declare function usedOrdersOf(subIssues: readonly SubIssueTitle[], parentEpic: number): readonly UsedOrder[];
19
+ export interface OrderRequest {
20
+ readonly file: string;
21
+ /**
22
+ 明示の番号。省いたら undefined
23
+ */
24
+ readonly order: number | undefined;
25
+ }
26
+ export type OrderPlan = {
27
+ readonly kind: 'planned';
28
+ readonly orders: readonly number[];
29
+ } | {
30
+ readonly kind: 'duplicate-in-batch';
31
+ readonly order: number;
32
+ readonly files: readonly string[];
33
+ } | {
34
+ readonly kind: 'duplicate-existing';
35
+ readonly order: number;
36
+ readonly existing: UsedOrder;
37
+ readonly nextAvailable: number;
38
+ } | {
39
+ readonly kind: 'unreadable-parent';
40
+ };
41
+ /**
42
+ 一括の中で明示の番号が重なるものを返す。ネットワークを使わずに確かめられる
43
+ */
44
+ export declare function findBatchDuplicate(requests: readonly OrderRequest[]): {
45
+ readonly order: number;
46
+ readonly files: readonly string[];
47
+ } | undefined;
48
+ /**
49
+ 同じ親 Epic のファイルに番号を振る。requests はファイルの順。
50
+ 使われた番号は、親のサブタスクのタイトルから読んだもの(読めなければ undefined)。
51
+ 明示の番号は、既存の番号とも、ほかのファイルの明示の番号とも重ねない。
52
+ 省いたファイルには、既存の番号と明示の番号の最大の次から、ファイルの順に振る。省いたファイルがあって使われた番号を読めなければ、決められない
53
+ */
54
+ export declare function planOrders(used: readonly UsedOrder[] | undefined, requests: readonly OrderRequest[]): OrderPlan;
55
+ //# sourceMappingURL=issue-order.d.ts.map
@@ -0,0 +1,65 @@
1
+ // タイトルの通し番号(specs/024 の R13)。サブタスクのタイトルと明示の番号から、使われた番号・重複・次の番号を決める。I/O を持たない。
2
+ // タイトルの先頭の `#123-01:` と `#123-01a:` から、Epic 番号・番号・枝の文字を取る。`[Task] ` のような接頭辞は許す
3
+ const ORDER_PATTERN = /^#(\d+)-(\d+)([a-z])?:/u;
4
+ const TITLE_PREFIX_PATTERN = /^\[[^\]]*\] ?/u;
5
+ /**
6
+ サブタスクのうち、タイトルが親 Epic の番号付きのものを、使われた番号にする
7
+ */
8
+ export function usedOrdersOf(subIssues, parentEpic) {
9
+ const used = [];
10
+ for (const sub of subIssues) {
11
+ const [, epic, order] = ORDER_PATTERN.exec(sub.title.replace(TITLE_PREFIX_PATTERN, '')) ?? [];
12
+ if (epic === undefined || order === undefined || Number(epic) !== parentEpic)
13
+ continue;
14
+ used.push({ number: sub.number, state: sub.state, title: sub.title, order: Number(order) });
15
+ }
16
+ return used;
17
+ }
18
+ function explicitOrders(requests) {
19
+ const explicit = new Map();
20
+ for (const { file, order } of requests) {
21
+ if (order !== undefined)
22
+ explicit.set(order, [...explicit.get(order) ?? [], file]);
23
+ }
24
+ return explicit;
25
+ }
26
+ /**
27
+ 一括の中で明示の番号が重なるものを返す。ネットワークを使わずに確かめられる
28
+ */
29
+ export function findBatchDuplicate(requests) {
30
+ for (const [order, files] of explicitOrders(requests)) {
31
+ if (files.length > 1)
32
+ return { order, files };
33
+ }
34
+ return undefined;
35
+ }
36
+ /**
37
+ 同じ親 Epic のファイルに番号を振る。requests はファイルの順。
38
+ 使われた番号は、親のサブタスクのタイトルから読んだもの(読めなければ undefined)。
39
+ 明示の番号は、既存の番号とも、ほかのファイルの明示の番号とも重ねない。
40
+ 省いたファイルには、既存の番号と明示の番号の最大の次から、ファイルの順に振る。省いたファイルがあって使われた番号を読めなければ、決められない
41
+ */
42
+ export function planOrders(used, requests) {
43
+ const explicit = explicitOrders(requests);
44
+ // 省いたファイルへの番号と、重複のときの案内は、同じ「既存と明示の最大の次」
45
+ const first = Math.max(0, ...(used ?? []).map(entry => entry.order), ...explicit.keys()) + 1;
46
+ for (const [order, files] of explicit) {
47
+ if (files.length > 1)
48
+ return { kind: 'duplicate-in-batch', order, files };
49
+ const existing = used?.find(entry => entry.order === order);
50
+ if (existing !== undefined)
51
+ return { kind: 'duplicate-existing', order, existing, nextAvailable: first };
52
+ }
53
+ if (used === undefined && requests.some(({ order }) => order === undefined))
54
+ return { kind: 'unreadable-parent' };
55
+ let next = first;
56
+ const orders = requests.map(({ order }) => {
57
+ if (order !== undefined)
58
+ return order;
59
+ const assigned = next;
60
+ next += 1;
61
+ return assigned;
62
+ });
63
+ return { kind: 'planned', orders };
64
+ }
65
+ //# sourceMappingURL=issue-order.js.map
@@ -58,13 +58,16 @@ export interface IssueReadout {
58
58
  closedByPullRequestsReferences(includeClosedPrs: true) の PR
59
59
  */
60
60
  readonly closingPullRequests: readonly PullRequestReadout[];
61
- /**
62
- timelineItems の PR。ConnectedEvent のうち後で外されていないものと、CrossReferencedEvent のうち閉じる参照か、head が `/<Issue 番号>` で終わるもの
63
- */
64
- readonly timelinePullRequests: readonly PullRequestReadout[];
65
61
  }
66
62
  export interface TargetIssueReadout extends IssueReadout {
67
63
  readonly body: string;
64
+ /**
65
+ 親の Issue(sub-issue の親)。親が無い、または応答に無ければ null
66
+ */
67
+ readonly parent: {
68
+ readonly repository: RepositoryReference;
69
+ readonly number: number;
70
+ } | null;
68
71
  }
69
72
  /**
70
73
  blockedBy の読み取り結果。読めない部分があるときは read-failed。
@@ -104,4 +107,33 @@ export interface PullRequestsByHeadReadout {
104
107
  */
105
108
  readonly hasNextPage: boolean;
106
109
  }
110
+ /**
111
+ 前提 1 件の参照。block / unblock が、付ける前の確認と輪の探索に使う
112
+ */
113
+ export interface BlockedByReference {
114
+ /**
115
+ GraphQL の node ID
116
+ */
117
+ readonly id: string;
118
+ readonly repository: RepositoryReference;
119
+ readonly number: number;
120
+ readonly state: IssueStateReadout;
121
+ }
122
+ /**
123
+ 前提の参照の読み取り結果。total は件数で、issues は読めた分(total に足りないことがある)。
124
+ null の node と部分エラーは read-failed
125
+ */
126
+ export type BlockedByReferences = {
127
+ readonly kind: 'ok';
128
+ readonly total: number;
129
+ readonly issues: readonly BlockedByReference[];
130
+ } | {
131
+ readonly kind: 'read-failed';
132
+ readonly reason: string;
133
+ };
134
+ export interface IssueBlockedByReferences {
135
+ readonly id: string;
136
+ readonly body: string;
137
+ readonly blockedBy: BlockedByReferences;
138
+ }
107
139
  //# sourceMappingURL=issue-readout.d.ts.map
@@ -1,5 +1,8 @@
1
+ import type { HintedText } from './command-hint.js';
2
+ import type { PullRequestReadout } from './issue-readout.js';
1
3
  import type { SectionHeading } from './sections.js';
2
- export declare const SCREENSHOT_MISSING_ERROR: string;
4
+ import type { BaseReading } from './state.js';
5
+ export declare const SCREENSHOT_MISSING_ERROR: HintedText;
3
6
  /**
4
7
  本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
5
8
  */
@@ -32,11 +35,75 @@ export interface PullRequestContentOptions {
32
35
  テンプレートから取り出した必須の節。空なら節の検証をしない
33
36
  */
34
37
  readonly requiredSections: readonly SectionHeading[];
38
+ /**
39
+ 積んで着手した記録の base(下の段のブランチ)。開発ブランチのほか、この base も通す
40
+ */
41
+ readonly stackedBase?: string | undefined;
35
42
  }
36
43
  /**
37
44
  PR の内容を検証し、エラーの文を返す(無ければ空)。ブランチ設定の欠けは、呼び出し側が先に止める
38
45
  */
39
- export declare function validatePullRequestContent(options: Readonly<PullRequestContentOptions>): readonly string[];
46
+ export declare function validatePullRequestContent(options: Readonly<PullRequestContentOptions>): readonly (string | HintedText)[];
47
+ export interface PullRequestBaseInput {
48
+ readonly reading: BaseReading;
49
+ /**
50
+ 渡された base(テンプレートの base か --base)
51
+ */
52
+ readonly base: string;
53
+ readonly developBranch: string;
54
+ /**
55
+ 下の段のブランチを head に持つ PR(pickLowerPullRequest で選んだもの)。積んだ記録のときだけ見る
56
+ */
57
+ readonly lowerPullRequest?: Readonly<PullRequestReadout> | undefined;
58
+ }
59
+ export type PullRequestBaseStop = {
60
+ readonly kind: 'stop';
61
+ readonly reason: 'malformed';
62
+ readonly content: string;
63
+ } | {
64
+ readonly kind: 'stop';
65
+ readonly reason: 'no-open-pr';
66
+ readonly branch: string;
67
+ } | {
68
+ readonly kind: 'stop';
69
+ readonly reason: 'lower-open';
70
+ readonly branch: string;
71
+ readonly pullRequest: number;
72
+ readonly base: string;
73
+ };
74
+ export interface PullRequestBaseUse {
75
+ readonly kind: 'use';
76
+ /**
77
+ PR を作る base
78
+ */
79
+ readonly base: string;
80
+ /**
81
+ 新しい PR と一緒にスタックへ登録する、下の段の PR の番号。登録しなければ undefined
82
+ */
83
+ readonly stackOn: number | undefined;
84
+ /**
85
+ 内容の検証(validatePullRequestContent)に渡す記録の base
86
+ */
87
+ readonly stackedBase: string | undefined;
88
+ /**
89
+ 下の段の PR がマージ済みか。題の scope を記録のコミットから比べるのは、マージ済みのときだけ
90
+ */
91
+ readonly isLowerMerged: boolean;
92
+ }
93
+ export type PullRequestBaseDecision = PullRequestBaseStop | PullRequestBaseUse;
94
+ /**
95
+ base の記録と下の段の PR の状態から、PR を作る base とスタックへの登録を決める。
96
+ 記録の base でも開発ブランチでもない base は、そのまま返して内容の検証で落とす
97
+ */
98
+ export declare function decidePullRequestBase(input: Readonly<PullRequestBaseInput>): PullRequestBaseDecision;
99
+ /**
100
+ 下の段のブランチを head に持つ PR から、base を決める 1 本を選ぶ。fork でないもののうち、開いている・マージ済み・閉じた の順(同じ状態なら渡した順の先頭)
101
+ */
102
+ export declare function pickLowerPullRequest(pullRequests: readonly PullRequestReadout[]): PullRequestReadout | undefined;
103
+ /**
104
+ 止めた理由の文(`error: ` の前置きを含まない)。下の段の PR が無いときは、直し方の行を続ける
105
+ */
106
+ export declare function describeBaseStop(stop: Readonly<PullRequestBaseStop>): readonly string[];
40
107
  export interface IssueSummary {
41
108
  readonly number: number;
42
109
  readonly title: string;
@@ -81,7 +148,7 @@ export interface PullRequestWithReviewsView extends PullRequestView {
81
148
  readonly review_threads: readonly ReviewThreadView[];
82
149
  }
83
150
  /**
84
- `pr read` の既定の Markdown
151
+ `pr show` の既定の Markdown
85
152
  */
86
153
  export declare function formatPullRequestMarkdown(pr: PullRequestSlimView): string;
87
154
  /**
@@ -93,7 +160,7 @@ export declare function formatReviewsMarkdown(reviews: readonly ReviewView[]): s
93
160
  */
94
161
  export declare function formatReviewThreadsMarkdown(threads: readonly ReviewThreadView[]): string;
95
162
  /**
96
- `pr read --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
163
+ `pr show --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
97
164
  */
98
165
  export declare function formatPullRequestWithReviewsMarkdown(pr: PullRequestWithReviewsView, owner: string, repository: string): string;
99
166
  export interface PreflightWarning {