@pecot/workflow-mcp 0.0.0-stage → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +184 -2
  4. package/bin/pecot-workflow-mcp.mjs +10 -0
  5. package/cli/dist/cli.d.ts +26 -0
  6. package/cli/dist/cli.js +227 -0
  7. package/cli/dist/commands/board-add.d.ts +3 -0
  8. package/cli/dist/commands/board-add.js +59 -0
  9. package/cli/dist/commands/board-judgment.d.ts +60 -0
  10. package/cli/dist/commands/board-judgment.js +144 -0
  11. package/cli/dist/commands/board-move.d.ts +3 -0
  12. package/cli/dist/commands/board-move.js +57 -0
  13. package/cli/dist/commands/board-readiness.d.ts +34 -0
  14. package/cli/dist/commands/board-readiness.js +108 -0
  15. package/cli/dist/commands/board-show.d.ts +3 -0
  16. package/cli/dist/commands/board-show.js +72 -0
  17. package/cli/dist/commands/board-sync.d.ts +3 -0
  18. package/cli/dist/commands/board-sync.js +111 -0
  19. package/cli/dist/commands/board-view.d.ts +62 -0
  20. package/cli/dist/commands/board-view.js +191 -0
  21. package/cli/dist/commands/board.d.ts +3 -0
  22. package/cli/dist/commands/board.js +12 -0
  23. package/cli/dist/commands/branch.d.ts +3 -0
  24. package/cli/dist/commands/branch.js +100 -0
  25. package/cli/dist/commands/cell-table.d.ts +3 -0
  26. package/cli/dist/commands/cell-table.js +495 -0
  27. package/cli/dist/commands/command-binding.d.ts +26 -0
  28. package/cli/dist/commands/command-binding.js +270 -0
  29. package/cli/dist/commands/command-definition.d.ts +150 -0
  30. package/cli/dist/commands/command-definition.js +105 -0
  31. package/cli/dist/commands/command-help.d.ts +8 -0
  32. package/cli/dist/commands/command-help.js +173 -0
  33. package/cli/dist/commands/command-hint.d.ts +5 -0
  34. package/cli/dist/commands/command-hint.js +13 -0
  35. package/cli/dist/commands/command-stop.d.ts +21 -0
  36. package/cli/dist/commands/command-stop.js +31 -0
  37. package/cli/dist/commands/directory-option.d.ts +7 -0
  38. package/cli/dist/commands/directory-option.js +48 -0
  39. package/cli/dist/commands/failure-kind.d.ts +3 -0
  40. package/cli/dist/commands/failure-kind.js +34 -0
  41. package/cli/dist/commands/failure.d.ts +19 -0
  42. package/cli/dist/commands/failure.js +59 -0
  43. package/cli/dist/commands/fuzzy.d.ts +7 -0
  44. package/cli/dist/commands/fuzzy.js +79 -0
  45. package/cli/dist/commands/github-client.d.ts +16 -0
  46. package/cli/dist/commands/github-client.js +33 -0
  47. package/cli/dist/commands/global-options.d.ts +25 -0
  48. package/cli/dist/commands/global-options.js +83 -0
  49. package/cli/dist/commands/help-layout.d.ts +40 -0
  50. package/cli/dist/commands/help-layout.js +117 -0
  51. package/cli/dist/commands/help.d.ts +8 -0
  52. package/cli/dist/commands/help.js +50 -0
  53. package/cli/dist/commands/input-schema.d.ts +14 -0
  54. package/cli/dist/commands/input-schema.js +56 -0
  55. package/cli/dist/commands/issue-board.d.ts +71 -0
  56. package/cli/dist/commands/issue-board.js +122 -0
  57. package/cli/dist/commands/issue-comment.d.ts +3 -0
  58. package/cli/dist/commands/issue-comment.js +215 -0
  59. package/cli/dist/commands/issue-create.d.ts +3 -0
  60. package/cli/dist/commands/issue-create.js +786 -0
  61. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  62. package/cli/dist/commands/issue-dependency.js +282 -0
  63. package/cli/dist/commands/issue-readiness.d.ts +94 -0
  64. package/cli/dist/commands/issue-readiness.js +218 -0
  65. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  66. package/cli/dist/commands/issue-reopen.js +115 -0
  67. package/cli/dist/commands/issue-shared.d.ts +172 -0
  68. package/cli/dist/commands/issue-shared.js +426 -0
  69. package/cli/dist/commands/issue-show.d.ts +3 -0
  70. package/cli/dist/commands/issue-show.js +169 -0
  71. package/cli/dist/commands/issue.d.ts +3 -0
  72. package/cli/dist/commands/issue.js +13 -0
  73. package/cli/dist/commands/names.d.ts +42 -0
  74. package/cli/dist/commands/names.js +78 -0
  75. package/cli/dist/commands/output.d.ts +90 -0
  76. package/cli/dist/commands/output.js +194 -0
  77. package/cli/dist/commands/pr-waiting.d.ts +20 -0
  78. package/cli/dist/commands/pr-waiting.js +106 -0
  79. package/cli/dist/commands/pr.d.ts +22 -0
  80. package/cli/dist/commands/pr.js +852 -0
  81. package/cli/dist/commands/project-sync.d.ts +92 -0
  82. package/cli/dist/commands/project-sync.js +282 -0
  83. package/cli/dist/commands/project.d.ts +6 -0
  84. package/cli/dist/commands/project.js +714 -0
  85. package/cli/dist/commands/registry.d.ts +6 -0
  86. package/cli/dist/commands/registry.js +30 -0
  87. package/cli/dist/commands/release.d.ts +10 -0
  88. package/cli/dist/commands/release.js +353 -0
  89. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  90. package/cli/dist/commands/renamed-commands.js +53 -0
  91. package/cli/dist/commands/repository-display.d.ts +3 -0
  92. package/cli/dist/commands/repository-display.js +7 -0
  93. package/cli/dist/commands/repository-match.d.ts +14 -0
  94. package/cli/dist/commands/repository-match.js +34 -0
  95. package/cli/dist/commands/rich-panel.d.ts +22 -0
  96. package/cli/dist/commands/rich-panel.js +295 -0
  97. package/cli/dist/commands/session-finish.d.ts +3 -0
  98. package/cli/dist/commands/session-finish.js +267 -0
  99. package/cli/dist/commands/session-start.d.ts +3 -0
  100. package/cli/dist/commands/session-start.js +236 -0
  101. package/cli/dist/commands/session.d.ts +6 -0
  102. package/cli/dist/commands/session.js +214 -0
  103. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  104. package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
  105. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  106. package/cli/dist/commands/tracker-sync-security.js +153 -0
  107. package/cli/dist/commands/tracker-sync.d.ts +65 -0
  108. package/cli/dist/commands/tracker-sync.js +50 -0
  109. package/cli/dist/commands/tracker.d.ts +3 -0
  110. package/cli/dist/commands/tracker.js +18 -0
  111. package/cli/dist/commands/usage-error.d.ts +51 -0
  112. package/cli/dist/commands/usage-error.js +78 -0
  113. package/cli/dist/commands/value-types.d.ts +46 -0
  114. package/cli/dist/commands/value-types.js +94 -0
  115. package/cli/dist/commands/work-target.d.ts +22 -0
  116. package/cli/dist/commands/work-target.js +82 -0
  117. package/cli/dist/commands/worktree.d.ts +3 -0
  118. package/cli/dist/commands/worktree.js +339 -0
  119. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  120. package/cli/dist/domain/api-error-detail.js +25 -0
  121. package/cli/dist/domain/batch-plan.d.ts +73 -0
  122. package/cli/dist/domain/batch-plan.js +114 -0
  123. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  124. package/cli/dist/domain/blocked-by-change.js +101 -0
  125. package/cli/dist/domain/board-move.d.ts +90 -0
  126. package/cli/dist/domain/board-move.js +92 -0
  127. package/cli/dist/domain/branch-name.d.ts +5 -0
  128. package/cli/dist/domain/branch-name.js +10 -0
  129. package/cli/dist/domain/changelog.d.ts +43 -0
  130. package/cli/dist/domain/changelog.js +107 -0
  131. package/cli/dist/domain/command-hint.d.ts +85 -0
  132. package/cli/dist/domain/command-hint.js +148 -0
  133. package/cli/dist/domain/config.d.ts +219 -0
  134. package/cli/dist/domain/config.js +310 -0
  135. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  136. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  137. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  138. package/cli/dist/domain/dependabot-source.js +4 -0
  139. package/cli/dist/domain/dependabot.d.ts +47 -0
  140. package/cli/dist/domain/dependabot.js +88 -0
  141. package/cli/dist/domain/errors.d.ts +24 -0
  142. package/cli/dist/domain/errors.js +36 -0
  143. package/cli/dist/domain/field-options.d.ts +31 -0
  144. package/cli/dist/domain/field-options.js +44 -0
  145. package/cli/dist/domain/format.d.ts +94 -0
  146. package/cli/dist/domain/format.js +234 -0
  147. package/cli/dist/domain/frontmatter.d.ts +137 -0
  148. package/cli/dist/domain/frontmatter.js +290 -0
  149. package/cli/dist/domain/git-runner.d.ts +10 -0
  150. package/cli/dist/domain/git-runner.js +4 -0
  151. package/cli/dist/domain/git-url.d.ts +17 -0
  152. package/cli/dist/domain/git-url.js +30 -0
  153. package/cli/dist/domain/issue-kind.d.ts +16 -0
  154. package/cli/dist/domain/issue-kind.js +16 -0
  155. package/cli/dist/domain/issue-order.d.ts +55 -0
  156. package/cli/dist/domain/issue-order.js +65 -0
  157. package/cli/dist/domain/issue-readout.d.ts +143 -0
  158. package/cli/dist/domain/issue-readout.js +4 -0
  159. package/cli/dist/domain/json-null.d.ts +2 -0
  160. package/cli/dist/domain/json-null.js +5 -0
  161. package/cli/dist/domain/json.d.ts +21 -0
  162. package/cli/dist/domain/json.js +47 -0
  163. package/cli/dist/domain/prerequisites.d.ts +32 -0
  164. package/cli/dist/domain/prerequisites.js +192 -0
  165. package/cli/dist/domain/pull-request.d.ts +201 -0
  166. package/cli/dist/domain/pull-request.js +281 -0
  167. package/cli/dist/domain/python-format.d.ts +105 -0
  168. package/cli/dist/domain/python-format.js +304 -0
  169. package/cli/dist/domain/readiness.d.ts +199 -0
  170. package/cli/dist/domain/readiness.js +391 -0
  171. package/cli/dist/domain/reference-parser.d.ts +51 -0
  172. package/cli/dist/domain/reference-parser.js +123 -0
  173. package/cli/dist/domain/release.d.ts +53 -0
  174. package/cli/dist/domain/release.js +65 -0
  175. package/cli/dist/domain/repository-policy.d.ts +38 -0
  176. package/cli/dist/domain/repository-policy.js +66 -0
  177. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  178. package/cli/dist/domain/repository-resolver.js +122 -0
  179. package/cli/dist/domain/sections.d.ts +69 -0
  180. package/cli/dist/domain/sections.js +514 -0
  181. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  182. package/cli/dist/domain/security-alerts-source.js +4 -0
  183. package/cli/dist/domain/security-alerts.d.ts +52 -0
  184. package/cli/dist/domain/security-alerts.js +107 -0
  185. package/cli/dist/domain/security-tracker.d.ts +115 -0
  186. package/cli/dist/domain/security-tracker.js +353 -0
  187. package/cli/dist/domain/state.d.ts +59 -0
  188. package/cli/dist/domain/state.js +95 -0
  189. package/cli/dist/domain/tracker-body.d.ts +70 -0
  190. package/cli/dist/domain/tracker-body.js +65 -0
  191. package/cli/dist/domain/work-start.d.ts +34 -0
  192. package/cli/dist/domain/work-start.js +49 -0
  193. package/cli/dist/domain/yaml-document.d.ts +5 -0
  194. package/cli/dist/domain/yaml-document.js +206 -0
  195. package/cli/dist/infra/authored-notes.d.ts +37 -0
  196. package/cli/dist/infra/authored-notes.js +72 -0
  197. package/cli/dist/infra/changelog-file.d.ts +19 -0
  198. package/cli/dist/infra/changelog-file.js +43 -0
  199. package/cli/dist/infra/child-stdin.d.ts +4 -0
  200. package/cli/dist/infra/child-stdin.js +8 -0
  201. package/cli/dist/infra/config-store.d.ts +53 -0
  202. package/cli/dist/infra/config-store.js +134 -0
  203. package/cli/dist/infra/diagnostics.d.ts +9 -0
  204. package/cli/dist/infra/diagnostics.js +2 -0
  205. package/cli/dist/infra/file-kind.d.ts +9 -0
  206. package/cli/dist/infra/file-kind.js +26 -0
  207. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  208. package/cli/dist/infra/frontmatter-file.js +30 -0
  209. package/cli/dist/infra/git.d.ts +86 -0
  210. package/cli/dist/infra/git.js +145 -0
  211. package/cli/dist/infra/github/auth.d.ts +60 -0
  212. package/cli/dist/infra/github/auth.js +158 -0
  213. package/cli/dist/infra/github/client.d.ts +178 -0
  214. package/cli/dist/infra/github/client.js +579 -0
  215. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  216. package/cli/dist/infra/github/dependabot-source.js +33 -0
  217. package/cli/dist/infra/github/errors.d.ts +65 -0
  218. package/cli/dist/infra/github/errors.js +64 -0
  219. package/cli/dist/infra/github/index.d.ts +13 -0
  220. package/cli/dist/infra/github/index.js +19 -0
  221. package/cli/dist/infra/github/issues.d.ts +165 -0
  222. package/cli/dist/infra/github/issues.js +428 -0
  223. package/cli/dist/infra/github/payload.d.ts +44 -0
  224. package/cli/dist/infra/github/payload.js +80 -0
  225. package/cli/dist/infra/github/projects.d.ts +143 -0
  226. package/cli/dist/infra/github/projects.js +384 -0
  227. package/cli/dist/infra/github/pulls.d.ts +104 -0
  228. package/cli/dist/infra/github/pulls.js +217 -0
  229. package/cli/dist/infra/github/queries.d.ts +44 -0
  230. package/cli/dist/infra/github/queries.js +1031 -0
  231. package/cli/dist/infra/github/readout.d.ts +22 -0
  232. package/cli/dist/infra/github/readout.js +167 -0
  233. package/cli/dist/infra/github/repos.d.ts +86 -0
  234. package/cli/dist/infra/github/repos.js +168 -0
  235. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  236. package/cli/dist/infra/github/rest-path.js +31 -0
  237. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  238. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  239. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  240. package/cli/dist/infra/gitignore-spec.js +235 -0
  241. package/cli/dist/infra/nx-scope.d.ts +51 -0
  242. package/cli/dist/infra/nx-scope.js +182 -0
  243. package/cli/dist/infra/os-error.d.ts +24 -0
  244. package/cli/dist/infra/os-error.js +38 -0
  245. package/cli/dist/infra/paths.d.ts +88 -0
  246. package/cli/dist/infra/paths.js +234 -0
  247. package/cli/dist/infra/state-store.d.ts +54 -0
  248. package/cli/dist/infra/state-store.js +130 -0
  249. package/cli/dist/infra/template-store.d.ts +15 -0
  250. package/cli/dist/infra/template-store.js +34 -0
  251. package/cli/dist/infra/text-file.d.ts +12 -0
  252. package/cli/dist/infra/text-file.js +33 -0
  253. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  254. package/cli/dist/infra/worktree-copy.js +95 -0
  255. package/cli/dist/infra/worktree-links.d.ts +142 -0
  256. package/cli/dist/infra/worktree-links.js +440 -0
  257. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  258. package/cli/dist/infra/worktree-setup.js +41 -0
  259. package/cli/dist/infra/worktree.d.ts +185 -0
  260. package/cli/dist/infra/worktree.js +584 -0
  261. package/cli/dist/mcp/result.d.ts +61 -0
  262. package/cli/dist/mcp/result.js +96 -0
  263. package/cli/dist/mcp/serve.d.ts +51 -0
  264. package/cli/dist/mcp/serve.js +183 -0
  265. package/cli/dist/mcp/server.d.ts +21 -0
  266. package/cli/dist/mcp/server.js +142 -0
  267. package/cli/dist/mcp/session-directory.d.ts +26 -0
  268. package/cli/dist/mcp/session-directory.js +84 -0
  269. package/cli/dist/package.json +1 -0
  270. package/cli/dist/version.d.ts +17 -0
  271. package/cli/dist/version.js +42 -0
  272. package/cli/templates/comment/merge-diff.md +34 -0
  273. package/cli/templates/comment/plan.md +195 -0
  274. package/cli/templates/comment/precede-notify.md +33 -0
  275. package/cli/templates/comment/review-findings.md +42 -0
  276. package/cli/templates/comment/review-resolution.md +48 -0
  277. package/cli/templates/issue/bug.md +63 -0
  278. package/cli/templates/issue/epic.md +54 -0
  279. package/cli/templates/issue/task-implement.md +74 -0
  280. package/cli/templates/issue/task.md +48 -0
  281. package/cli/templates/issue/tracker.md +48 -0
  282. package/cli/templates/pr/create.md +123 -0
  283. package/cli/templates/pr/release.md +56 -0
  284. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  285. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  286. package/npm-shrinkwrap.json +83 -0
  287. package/package.json +22 -4
@@ -0,0 +1,5 @@
1
+ // JSON の null を表す定数。GraphQL の変数や JSON の出力に null が要る箇所は、これを使う。
2
+ // `unicorn/no-null` を外すのはここ 1 か所だけにする。
3
+ // eslint-disable-next-line unicorn/no-null -- JSON の null を表す唯一の定数
4
+ export const JSON_NULL = null;
5
+ //# sourceMappingURL=json-null.js.map
@@ -0,0 +1,21 @@
1
+ import type { JsonValue } from './python-format.js';
2
+ export type JsonObject = Readonly<Record<string, JsonValue>>;
3
+ /**
4
+ 配列でも null でもないオブジェクトか
5
+ */
6
+ export declare function isJsonObject(value: JsonValue | undefined): value is JsonObject;
7
+ /**
8
+ オブジェクトの自身のキーの値。オブジェクトでない、またはキーが無ければ undefined。
9
+ キーに prototype の名前が来ても、継承した値は返さない
10
+ */
11
+ export declare function jsonField(value: JsonValue | undefined, key: string): JsonValue | undefined;
12
+ /**
13
+ JSON 文字列を読む。構文が不正なら undefined
14
+ */
15
+ export declare function tryParseJsonText(text: string): JsonValue | undefined;
16
+ /**
17
+ JSON 文字列を読む。不正なら InvalidValueError。
18
+ 文言は JSON パーサーのもので、Python の JSONDecodeError の文とは違う
19
+ */
20
+ export declare function parseJsonText(text: string): JsonValue;
21
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1,47 @@
1
+ // JSON の値を読む補助。型の絞り込み、フィールドの読み取り、JSON 文字列の読み込みの置き場。
2
+ // 同じ補助を各所に書かないよう、domain と infra はここから import する。
3
+ import { InvalidValueError } from './errors.js';
4
+ import { isJsonArray } from './python-format.js';
5
+ /**
6
+ 配列でも null でもないオブジェクトか
7
+ */
8
+ export function isJsonObject(value) {
9
+ return typeof value === 'object' && value !== null && !isJsonArray(value);
10
+ }
11
+ /**
12
+ オブジェクトの自身のキーの値。オブジェクトでない、またはキーが無ければ undefined。
13
+ キーに prototype の名前が来ても、継承した値は返さない
14
+ */
15
+ export function jsonField(value, key) {
16
+ return isJsonObject(value) ? new Map(Object.entries(value)).get(key) : undefined;
17
+ }
18
+ /**
19
+ JSON 文字列を読む。構文が不正なら undefined
20
+ */
21
+ export function tryParseJsonText(text) {
22
+ try {
23
+ // eslint-disable-next-line no-restricted-syntax -- JSON.parse の結果は定義上 JsonValue
24
+ return JSON.parse(text);
25
+ }
26
+ catch (error) {
27
+ if (error instanceof SyntaxError)
28
+ return undefined;
29
+ throw error;
30
+ }
31
+ }
32
+ /**
33
+ JSON 文字列を読む。不正なら InvalidValueError。
34
+ 文言は JSON パーサーのもので、Python の JSONDecodeError の文とは違う
35
+ */
36
+ export function parseJsonText(text) {
37
+ try {
38
+ // eslint-disable-next-line no-restricted-syntax -- JSON.parse の結果は定義上 JsonValue
39
+ return JSON.parse(text);
40
+ }
41
+ catch (error) {
42
+ if (error instanceof SyntaxError)
43
+ throw new InvalidValueError(error.message, { cause: error });
44
+ throw error;
45
+ }
46
+ }
47
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1,32 @@
1
+ import type { IssueReference } from './reference-parser.js';
2
+ import type { RepositoryReference } from './repository-resolver.js';
3
+ export declare const WAITS_FOR_MERGE_HEADING = "## Waits for merge";
4
+ export interface WaitsForMergeLine {
5
+ readonly ref: IssueReference;
6
+ readonly reason: string;
7
+ }
8
+ /**
9
+ absent は節が無いこと。malformed は節が読めないこと(呼ぶ側は前提をすべて merge として扱う)
10
+ */
11
+ export type WaitsForMergeReadout = {
12
+ readonly kind: 'absent';
13
+ } | {
14
+ readonly kind: 'ok';
15
+ readonly lines: readonly WaitsForMergeLine[];
16
+ } | {
17
+ readonly kind: 'malformed';
18
+ readonly reason: string;
19
+ };
20
+ /**
21
+ 本文から `## Waits for merge` の節を読む。repository は `#N` の参照が指すリポ(本文のある Issue のリポ)
22
+ */
23
+ export declare function readWaitsForMerge(body: string, repository: RepositoryReference): WaitsForMergeReadout;
24
+ /**
25
+ 前提の行を足す。同じ参照の行があれば理由を書き換える。節の外は変えない。節が読めないときは InvalidValueError
26
+ */
27
+ export declare function upsertWaitsForMerge(body: string, repository: RepositoryReference, reference: IssueReference, reason: string): string;
28
+ /**
29
+ 前提の行を外す。参照が無ければ本文をそのまま返す。行が無くなれば節ごと消す。節が読めないときは InvalidValueError
30
+ */
31
+ export declare function removeWaitsForMerge(body: string, repository: RepositoryReference, reference: IssueReference): string;
32
+ //# sourceMappingURL=prerequisites.d.ts.map
@@ -0,0 +1,192 @@
1
+ // Issue の本文の `## Waits for merge` の節の読み書き(contracts/prerequisite-table.md の 3)。純関数だけを置く。
2
+ import { InvalidValueError } from './errors.js';
3
+ import { createIssueReference, issueReferenceKey, issueReferenceToString } from './reference-parser.js';
4
+ import { ValidationFailure } from './python-format.js';
5
+ import { createRepositoryReference, isSameRepository } from './repository-resolver.js';
6
+ export const WAITS_FOR_MERGE_HEADING = '## Waits for merge';
7
+ const LINE_PATTERN = /([^\n]*)(\n|$)/gu;
8
+ const SAME_REPOSITORY_REFERENCE = /^#(\d+)$/u;
9
+ const QUALIFIED_REFERENCE = /^([\w.-]+)\/([\w.-]+)#(\d+)$/u;
10
+ function splitLines(body) {
11
+ const lines = [];
12
+ for (const match of body.matchAll(LINE_PATTERN)) {
13
+ const [whole, content = '', newline = ''] = match;
14
+ if (whole === '')
15
+ break;
16
+ const hasCarriageReturn = newline !== '' && content.endsWith('\r');
17
+ lines.push({
18
+ text: hasCarriageReturn ? content.slice(0, -1) : content,
19
+ eol: hasCarriageReturn ? '\r\n' : newline,
20
+ });
21
+ }
22
+ return lines;
23
+ }
24
+ function joinLines(lines) {
25
+ return lines.map(line => line.text + line.eol).join('');
26
+ }
27
+ function lineEnding(body) {
28
+ return body.includes('\r\n') ? '\r\n' : '\n';
29
+ }
30
+ function locateSections(lines) {
31
+ const sections = [];
32
+ for (const [index, line] of lines.entries()) {
33
+ if (line.text !== WAITS_FOR_MERGE_HEADING)
34
+ continue;
35
+ const next = lines.findIndex((candidate, position) => position > index && candidate.text.startsWith('## '));
36
+ sections.push({ start: index, end: next === -1 ? lines.length : next });
37
+ }
38
+ return sections;
39
+ }
40
+ function formatReference(repository, reference) {
41
+ return isSameRepository(repository, reference.repository) ? `#${String(reference.number)}` : issueReferenceToString(reference);
42
+ }
43
+ function createReference(repository, digits) {
44
+ const number = Number(digits);
45
+ if (!Number.isSafeInteger(number))
46
+ return undefined;
47
+ try {
48
+ return createIssueReference(repository(), number);
49
+ }
50
+ catch (error) {
51
+ if (error instanceof ValidationFailure)
52
+ return undefined;
53
+ throw error;
54
+ }
55
+ }
56
+ function parseReference(raw, repository) {
57
+ const sameRepositoryNumber = SAME_REPOSITORY_REFERENCE.exec(raw)?.[1];
58
+ if (sameRepositoryNumber !== undefined)
59
+ return createReference(() => repository, sameRepositoryNumber);
60
+ const [, owner, name, qualifiedNumber] = QUALIFIED_REFERENCE.exec(raw) ?? [];
61
+ return owner === undefined || name === undefined || qualifiedNumber === undefined
62
+ ? undefined
63
+ : createReference(() => createRepositoryReference(owner, name), qualifiedNumber);
64
+ }
65
+ function parseLine(text, repository) {
66
+ if (text.trim() === '')
67
+ return { kind: 'blank' };
68
+ if (!text.startsWith('- '))
69
+ return { kind: 'invalid', reason: `not a list item: ${text}` };
70
+ const rest = text.slice(2);
71
+ const separator = rest.indexOf(': ');
72
+ if (separator === -1)
73
+ return { kind: 'invalid', reason: `no ': ' separator: ${text}` };
74
+ const reference = parseReference(rest.slice(0, separator), repository);
75
+ if (reference === undefined)
76
+ return { kind: 'invalid', reason: `invalid issue reference: ${text}` };
77
+ const reason = rest.slice(separator + 2).trim();
78
+ return reason === '' ? { kind: 'invalid', reason: `empty reason: ${text}` } : { kind: 'entry', entry: { ref: reference, reason } };
79
+ }
80
+ function readSection(lines, section, repository) {
81
+ const entries = [];
82
+ const seen = new Set();
83
+ const sectionLines = lines.slice(section.start + 1, section.end);
84
+ for (const line of sectionLines) {
85
+ const parsed = parseLine(line.text, repository);
86
+ if (parsed.kind === 'blank')
87
+ continue;
88
+ if (parsed.kind === 'invalid')
89
+ return { kind: 'malformed', reason: parsed.reason };
90
+ const key = issueReferenceKey(parsed.entry.ref);
91
+ if (seen.has(key))
92
+ return { kind: 'malformed', reason: `duplicate reference: ${key}` };
93
+ seen.add(key);
94
+ entries.push(parsed.entry);
95
+ }
96
+ return { kind: 'ok', lines: entries };
97
+ }
98
+ function readBody(lines, repository) {
99
+ const sections = locateSections(lines);
100
+ const [section] = sections;
101
+ if (section === undefined)
102
+ return { readout: { kind: 'absent' }, section: undefined };
103
+ if (sections.length > 1)
104
+ return { readout: { kind: 'malformed', reason: `${WAITS_FOR_MERGE_HEADING} appears ${String(sections.length)} times` }, section };
105
+ return { readout: readSection(lines, section, repository), section };
106
+ }
107
+ /**
108
+ 本文から `## Waits for merge` の節を読む。repository は `#N` の参照が指すリポ(本文のある Issue のリポ)
109
+ */
110
+ export function readWaitsForMerge(body, repository) {
111
+ return readBody(splitLines(body), repository).readout;
112
+ }
113
+ function requireWritable(body, repository) {
114
+ const lines = splitLines(body);
115
+ const { readout, section } = readBody(lines, repository);
116
+ if (readout.kind === 'malformed')
117
+ throw new InvalidValueError(`${WAITS_FOR_MERGE_HEADING} section is malformed: ${readout.reason}`);
118
+ return { lines, section, entries: readout.kind === 'ok' ? readout.lines : [] };
119
+ }
120
+ function sectionIndexes(section) {
121
+ return Array.from({ length: section.end - section.start - 1 }, (_, offset) => section.start + 1 + offset);
122
+ }
123
+ function entryIndex(lines, section, repository, reference) {
124
+ const key = issueReferenceKey(reference);
125
+ return sectionIndexes(section).find((index) => {
126
+ const parsed = parseLine(lines.at(index)?.text ?? '', repository);
127
+ return parsed.kind === 'entry' && issueReferenceKey(parsed.entry.ref) === key;
128
+ });
129
+ }
130
+ // 足す位置の行(無ければその手前の行)の改行に合わせる。末尾に改行の無い本文は、足した行も改行なしで終える
131
+ function insertAfter(lines, index, text, fallbackEol) {
132
+ const previous = lines.at(index);
133
+ const isAtEnd = previous?.eol === '';
134
+ const eol = lines.slice(0, index + 1).findLast(line => line.eol !== '')?.eol ?? fallbackEol;
135
+ const kept = lines.with(index, { text: previous?.text ?? '', eol });
136
+ return kept.toSpliced(index + 1, 0, { text, eol: isAtEnd ? '' : eol });
137
+ }
138
+ // 末尾の改行が無い本文へ足した節は、改行なしで終える。removeWaitsForMerge で外すと元の本文と同じになる
139
+ function appendSection(lines, text, eol) {
140
+ const last = lines.at(-1);
141
+ const isUnterminated = last?.eol === '';
142
+ const terminated = isUnterminated ? lines.with(lines.length - 1, { text: last.text, eol }) : lines;
143
+ const separator = terminated.length === 0 || terminated.at(-1)?.text === '' ? [] : [{ text: '', eol }];
144
+ return [...terminated, ...separator, { text: WAITS_FOR_MERGE_HEADING, eol }, { text: '', eol }, { text, eol: isUnterminated ? '' : eol }];
145
+ }
146
+ /**
147
+ 前提の行を足す。同じ参照の行があれば理由を書き換える。節の外は変えない。節が読めないときは InvalidValueError
148
+ */
149
+ export function upsertWaitsForMerge(body, repository, reference, reason) {
150
+ const trimmed = reason.trim();
151
+ if (trimmed === '' || /[\r\n]/u.test(trimmed))
152
+ throw new InvalidValueError('reason must be a single non-empty line');
153
+ const text = `- ${formatReference(repository, reference)}: ${trimmed}`;
154
+ const eol = lineEnding(body);
155
+ const { lines, section } = requireWritable(body, repository);
156
+ if (section === undefined)
157
+ return joinLines(appendSection(lines, text, eol));
158
+ const existing = entryIndex(lines, section, repository, reference);
159
+ if (existing !== undefined)
160
+ return joinLines(lines.with(existing, { text, eol: lines.at(existing)?.eol ?? eol }));
161
+ const contentIndexes = sectionIndexes(section).filter(index => lines.at(index)?.text.trim() !== '');
162
+ return joinLines(insertAfter(lines, contentIndexes.at(-1) ?? section.start, text, eol));
163
+ }
164
+ // 最後の行を消すときは、前の行の改行も落として末尾の形を保つ
165
+ function removeEntryLine(lines, index) {
166
+ const isLast = lines.at(index)?.eol === '';
167
+ const previous = lines.at(index - 1);
168
+ const kept = isLast && previous !== undefined ? lines.with(index - 1, { text: previous.text, eol: '' }) : lines;
169
+ return kept.toSpliced(index, 1);
170
+ }
171
+ /**
172
+ 前提の行を外す。参照が無ければ本文をそのまま返す。行が無くなれば節ごと消す。節が読めないときは InvalidValueError
173
+ */
174
+ export function removeWaitsForMerge(body, repository, reference) {
175
+ const { lines, section, entries } = requireWritable(body, repository);
176
+ if (section === undefined)
177
+ return body;
178
+ const index = entryIndex(lines, section, repository, reference);
179
+ if (index === undefined)
180
+ return body;
181
+ if (entries.length > 1)
182
+ return joinLines(removeEntryLine(lines, index));
183
+ // 節が本文の末尾なら、手前の空行(節との区切り)も一緒に消し、節が改行なしで終わっていれば手前の行も改行なしにする
184
+ const lastContent = lines.slice(0, section.start).findLastIndex(line => line.text.trim() !== '');
185
+ if (section.end !== lines.length)
186
+ return joinLines(lines.toSpliced(section.start, section.end - section.start));
187
+ const before = lines.slice(0, lastContent + 1);
188
+ const previous = before.at(-1);
189
+ const isUnterminated = lines.at(-1)?.eol === '';
190
+ return joinLines(previous !== undefined && isUnterminated ? [...before.slice(0, -1), { text: previous.text, eol: '' }] : before);
191
+ }
192
+ //# sourceMappingURL=prerequisites.js.map
@@ -0,0 +1,201 @@
1
+ import type { HintedText } from './command-hint.js';
2
+ import type { PullRequestReadout } from './issue-readout.js';
3
+ import type { SectionHeading } from './sections.js';
4
+ import type { BaseReading } from './state.js';
5
+ export declare const SCREENSHOT_MISSING_ERROR: HintedText;
6
+ /**
7
+ 本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
8
+ */
9
+ export declare function extractClosingIssueNumbers(body: string): readonly number[];
10
+ /**
11
+ 本文にその Issue 番号の参照が無ければ、末尾に `Closes #N` を足す。あればそのまま返す
12
+ */
13
+ export declare function appendIssueCloseIfNeeded(body: string, issueNumber: number): string;
14
+ /**
15
+ 本文に Issue 参照(`#N` か `owner/repo#N`)があるか
16
+ */
17
+ export declare function hasIssueReference(body: string): boolean;
18
+ /**
19
+ リリース PR か。release テンプレート、または develop から release への PR
20
+ */
21
+ export declare function isReleasePullRequest(template: string, base: string, head: string | undefined, developBranch: string | undefined, releaseBranch: string | undefined): boolean;
22
+ export interface PullRequestContentOptions {
23
+ readonly body: string;
24
+ readonly base: string;
25
+ readonly developBranch: string | undefined;
26
+ readonly releaseBranch: string | undefined;
27
+ readonly head: string | undefined;
28
+ readonly template: string;
29
+ readonly skipIssueReferenceCheck: boolean;
30
+ /**
31
+ Summary に画像が無い理由。正規化済みで、無ければ undefined
32
+ */
33
+ readonly screenshot: string | undefined;
34
+ /**
35
+ テンプレートから取り出した必須の節。空なら節の検証をしない
36
+ */
37
+ readonly requiredSections: readonly SectionHeading[];
38
+ /**
39
+ 積んで着手した記録の base(下の段のブランチ)。開発ブランチのほか、この base も通す
40
+ */
41
+ readonly stackedBase?: string | undefined;
42
+ }
43
+ /**
44
+ PR の内容を検証し、エラーの文を返す(無ければ空)。ブランチ設定の欠けは、呼び出し側が先に止める
45
+ */
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(pickBasePullRequest で選んだもの)。積んだ記録のときだけ見る
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[];
107
+ export interface IssueSummary {
108
+ readonly number: number;
109
+ readonly title: string;
110
+ }
111
+ export interface PullRequestView {
112
+ readonly number: number;
113
+ readonly state: string;
114
+ readonly title: string;
115
+ readonly body: string;
116
+ readonly head_ref: string;
117
+ readonly base_ref: string;
118
+ readonly is_draft: boolean;
119
+ readonly mergeable: string;
120
+ readonly comments: number;
121
+ readonly closing_issues: readonly IssueSummary[];
122
+ readonly referenced_issues: readonly IssueSummary[];
123
+ }
124
+ export interface PullRequestSlimView extends PullRequestView {
125
+ readonly reviews: readonly {
126
+ readonly state: string;
127
+ readonly author: string | null;
128
+ }[];
129
+ }
130
+ export interface ReviewView {
131
+ readonly state: string;
132
+ readonly author: string | null;
133
+ readonly body: string;
134
+ readonly submitted_at: string | null;
135
+ }
136
+ export interface ReviewThreadView {
137
+ readonly is_resolved: boolean;
138
+ readonly path: string | null;
139
+ readonly line: number | null;
140
+ readonly comments: readonly {
141
+ readonly author: string | null;
142
+ readonly body: string;
143
+ readonly created_at: string | null;
144
+ }[];
145
+ }
146
+ export interface PullRequestWithReviewsView extends PullRequestView {
147
+ readonly reviews: readonly ReviewView[];
148
+ readonly review_threads: readonly ReviewThreadView[];
149
+ }
150
+ /**
151
+ `pr show` の既定の Markdown
152
+ */
153
+ export declare function formatPullRequestMarkdown(pr: PullRequestSlimView): string;
154
+ /**
155
+ レビュー本文の節。レビューが無ければ空文字
156
+ */
157
+ export declare function formatReviewsMarkdown(reviews: readonly ReviewView[]): string;
158
+ /**
159
+ 行コメント(reviewThreads)の節。無ければ空文字
160
+ */
161
+ export declare function formatReviewThreadsMarkdown(threads: readonly ReviewThreadView[]): string;
162
+ /**
163
+ `pr show --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
164
+ */
165
+ export declare function formatPullRequestWithReviewsMarkdown(pr: PullRequestWithReviewsView, owner: string, repository: string): string;
166
+ export interface PreflightWarning {
167
+ readonly label: string;
168
+ readonly message: string;
169
+ readonly fixHint: string;
170
+ }
171
+ /**
172
+ `git status` の出力に変更があるか。空・取得失敗の印・「nothing to commit」かつ「working tree clean」は無し
173
+ */
174
+ export declare function hasStatusChanges(gitStatus: string): boolean;
175
+ /**
176
+ stash の一覧の文字列に、stash の項目があるか(「(no stash)」と取得失敗の印は無し)
177
+ */
178
+ export declare function hasStashEntries(stashList: string): boolean;
179
+ export interface PushStatus {
180
+ readonly isPushed: boolean;
181
+ readonly message: string;
182
+ }
183
+ /**
184
+ ahead と behind のコミット数から、push の状態の文を作る
185
+ */
186
+ export declare function describePushStatus(remote: string, branch: string, ahead: number, behind: number): PushStatus;
187
+ export interface PreflightFacts {
188
+ readonly gitStatus: string;
189
+ readonly stashList: string;
190
+ readonly isPushed: boolean;
191
+ readonly pushMessage: string;
192
+ }
193
+ /**
194
+ 警告を、未 push・変更あり・stash ありの順で返す
195
+ */
196
+ export declare function collectPreflightWarnings(facts: Readonly<PreflightFacts>): readonly PreflightWarning[];
197
+ /**
198
+ 警告 1 行の文
199
+ */
200
+ export declare function formatPreflightWarning(warning: PreflightWarning): string;
201
+ //# sourceMappingURL=pull-request.d.ts.map