@pecot/workflow-mcp 0.0.0-stage → 5.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 (244) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +126 -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 +222 -0
  7. package/cli/dist/commands/cell-table.d.ts +3 -0
  8. package/cli/dist/commands/cell-table.js +495 -0
  9. package/cli/dist/commands/command-binding.d.ts +26 -0
  10. package/cli/dist/commands/command-binding.js +266 -0
  11. package/cli/dist/commands/command-definition.d.ts +136 -0
  12. package/cli/dist/commands/command-definition.js +101 -0
  13. package/cli/dist/commands/command-help.d.ts +8 -0
  14. package/cli/dist/commands/command-help.js +173 -0
  15. package/cli/dist/commands/command-stop.d.ts +19 -0
  16. package/cli/dist/commands/command-stop.js +30 -0
  17. package/cli/dist/commands/dependabot.d.ts +3 -0
  18. package/cli/dist/commands/dependabot.js +165 -0
  19. package/cli/dist/commands/directory-option.d.ts +7 -0
  20. package/cli/dist/commands/directory-option.js +48 -0
  21. package/cli/dist/commands/failure.d.ts +13 -0
  22. package/cli/dist/commands/failure.js +33 -0
  23. package/cli/dist/commands/fuzzy.d.ts +7 -0
  24. package/cli/dist/commands/fuzzy.js +79 -0
  25. package/cli/dist/commands/github-client.d.ts +12 -0
  26. package/cli/dist/commands/github-client.js +23 -0
  27. package/cli/dist/commands/global-options.d.ts +25 -0
  28. package/cli/dist/commands/global-options.js +83 -0
  29. package/cli/dist/commands/help-layout.d.ts +40 -0
  30. package/cli/dist/commands/help-layout.js +117 -0
  31. package/cli/dist/commands/help.d.ts +8 -0
  32. package/cli/dist/commands/help.js +55 -0
  33. package/cli/dist/commands/input-schema.d.ts +14 -0
  34. package/cli/dist/commands/input-schema.js +56 -0
  35. package/cli/dist/commands/issue-board.d.ts +38 -0
  36. package/cli/dist/commands/issue-board.js +62 -0
  37. package/cli/dist/commands/issue-comment.d.ts +3 -0
  38. package/cli/dist/commands/issue-comment.js +196 -0
  39. package/cli/dist/commands/issue-create.d.ts +3 -0
  40. package/cli/dist/commands/issue-create.js +329 -0
  41. package/cli/dist/commands/issue-project.d.ts +3 -0
  42. package/cli/dist/commands/issue-project.js +176 -0
  43. package/cli/dist/commands/issue-quick.d.ts +3 -0
  44. package/cli/dist/commands/issue-quick.js +126 -0
  45. package/cli/dist/commands/issue-read.d.ts +3 -0
  46. package/cli/dist/commands/issue-read.js +80 -0
  47. package/cli/dist/commands/issue-shared.d.ts +159 -0
  48. package/cli/dist/commands/issue-shared.js +419 -0
  49. package/cli/dist/commands/issue.d.ts +4 -0
  50. package/cli/dist/commands/issue.js +15 -0
  51. package/cli/dist/commands/names.d.ts +9 -0
  52. package/cli/dist/commands/names.js +16 -0
  53. package/cli/dist/commands/output.d.ts +78 -0
  54. package/cli/dist/commands/output.js +187 -0
  55. package/cli/dist/commands/pr.d.ts +3 -0
  56. package/cli/dist/commands/pr.js +933 -0
  57. package/cli/dist/commands/project-info.d.ts +48 -0
  58. package/cli/dist/commands/project-info.js +181 -0
  59. package/cli/dist/commands/project-sync.d.ts +91 -0
  60. package/cli/dist/commands/project-sync.js +273 -0
  61. package/cli/dist/commands/project.d.ts +5 -0
  62. package/cli/dist/commands/project.js +677 -0
  63. package/cli/dist/commands/registry.d.ts +6 -0
  64. package/cli/dist/commands/registry.js +27 -0
  65. package/cli/dist/commands/release.d.ts +10 -0
  66. package/cli/dist/commands/release.js +414 -0
  67. package/cli/dist/commands/repository-display.d.ts +3 -0
  68. package/cli/dist/commands/repository-display.js +7 -0
  69. package/cli/dist/commands/repository-match.d.ts +14 -0
  70. package/cli/dist/commands/repository-match.js +33 -0
  71. package/cli/dist/commands/repository.d.ts +5 -0
  72. package/cli/dist/commands/repository.js +265 -0
  73. package/cli/dist/commands/rich-panel.d.ts +22 -0
  74. package/cli/dist/commands/rich-panel.js +295 -0
  75. package/cli/dist/commands/security.d.ts +3 -0
  76. package/cli/dist/commands/security.js +164 -0
  77. package/cli/dist/commands/session.d.ts +3 -0
  78. package/cli/dist/commands/session.js +161 -0
  79. package/cli/dist/commands/tracker-sync.d.ts +58 -0
  80. package/cli/dist/commands/tracker-sync.js +53 -0
  81. package/cli/dist/commands/usage-error.d.ts +47 -0
  82. package/cli/dist/commands/usage-error.js +72 -0
  83. package/cli/dist/commands/value-types.d.ts +46 -0
  84. package/cli/dist/commands/value-types.js +94 -0
  85. package/cli/dist/commands/work-target.d.ts +13 -0
  86. package/cli/dist/commands/work-target.js +41 -0
  87. package/cli/dist/commands/worktree.d.ts +3 -0
  88. package/cli/dist/commands/worktree.js +335 -0
  89. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  90. package/cli/dist/domain/api-error-detail.js +25 -0
  91. package/cli/dist/domain/branch-name.d.ts +5 -0
  92. package/cli/dist/domain/branch-name.js +10 -0
  93. package/cli/dist/domain/changelog.d.ts +43 -0
  94. package/cli/dist/domain/changelog.js +107 -0
  95. package/cli/dist/domain/config.d.ts +215 -0
  96. package/cli/dist/domain/config.js +300 -0
  97. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  98. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  99. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  100. package/cli/dist/domain/dependabot-source.js +4 -0
  101. package/cli/dist/domain/dependabot.d.ts +47 -0
  102. package/cli/dist/domain/dependabot.js +88 -0
  103. package/cli/dist/domain/errors.d.ts +19 -0
  104. package/cli/dist/domain/errors.js +31 -0
  105. package/cli/dist/domain/field-options.d.ts +31 -0
  106. package/cli/dist/domain/field-options.js +44 -0
  107. package/cli/dist/domain/format.d.ts +47 -0
  108. package/cli/dist/domain/format.js +168 -0
  109. package/cli/dist/domain/frontmatter.d.ts +122 -0
  110. package/cli/dist/domain/frontmatter.js +264 -0
  111. package/cli/dist/domain/git-runner.d.ts +10 -0
  112. package/cli/dist/domain/git-runner.js +4 -0
  113. package/cli/dist/domain/git-url.d.ts +17 -0
  114. package/cli/dist/domain/git-url.js +30 -0
  115. package/cli/dist/domain/issue-kind.d.ts +16 -0
  116. package/cli/dist/domain/issue-kind.js +16 -0
  117. package/cli/dist/domain/issue-readout.d.ts +107 -0
  118. package/cli/dist/domain/issue-readout.js +4 -0
  119. package/cli/dist/domain/json-null.d.ts +2 -0
  120. package/cli/dist/domain/json-null.js +5 -0
  121. package/cli/dist/domain/json.d.ts +21 -0
  122. package/cli/dist/domain/json.js +47 -0
  123. package/cli/dist/domain/prerequisites.d.ts +32 -0
  124. package/cli/dist/domain/prerequisites.js +192 -0
  125. package/cli/dist/domain/pull-request.d.ts +134 -0
  126. package/cli/dist/domain/pull-request.js +232 -0
  127. package/cli/dist/domain/python-format.d.ts +105 -0
  128. package/cli/dist/domain/python-format.js +304 -0
  129. package/cli/dist/domain/readiness.d.ts +172 -0
  130. package/cli/dist/domain/readiness.js +280 -0
  131. package/cli/dist/domain/reference-parser.d.ts +49 -0
  132. package/cli/dist/domain/reference-parser.js +119 -0
  133. package/cli/dist/domain/release.d.ts +49 -0
  134. package/cli/dist/domain/release.js +72 -0
  135. package/cli/dist/domain/repository-policy.d.ts +32 -0
  136. package/cli/dist/domain/repository-policy.js +65 -0
  137. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  138. package/cli/dist/domain/repository-resolver.js +119 -0
  139. package/cli/dist/domain/sections.d.ts +69 -0
  140. package/cli/dist/domain/sections.js +514 -0
  141. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  142. package/cli/dist/domain/security-alerts-source.js +4 -0
  143. package/cli/dist/domain/security-alerts.d.ts +52 -0
  144. package/cli/dist/domain/security-alerts.js +107 -0
  145. package/cli/dist/domain/security-tracker.d.ts +115 -0
  146. package/cli/dist/domain/security-tracker.js +353 -0
  147. package/cli/dist/domain/state.d.ts +29 -0
  148. package/cli/dist/domain/state.js +56 -0
  149. package/cli/dist/domain/tracker-body.d.ts +70 -0
  150. package/cli/dist/domain/tracker-body.js +65 -0
  151. package/cli/dist/domain/yaml-document.d.ts +5 -0
  152. package/cli/dist/domain/yaml-document.js +206 -0
  153. package/cli/dist/infra/authored-notes.d.ts +37 -0
  154. package/cli/dist/infra/authored-notes.js +66 -0
  155. package/cli/dist/infra/changelog-file.d.ts +19 -0
  156. package/cli/dist/infra/changelog-file.js +43 -0
  157. package/cli/dist/infra/child-stdin.d.ts +4 -0
  158. package/cli/dist/infra/child-stdin.js +8 -0
  159. package/cli/dist/infra/config-store.d.ts +49 -0
  160. package/cli/dist/infra/config-store.js +121 -0
  161. package/cli/dist/infra/diagnostics.d.ts +9 -0
  162. package/cli/dist/infra/diagnostics.js +2 -0
  163. package/cli/dist/infra/file-kind.d.ts +9 -0
  164. package/cli/dist/infra/file-kind.js +26 -0
  165. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  166. package/cli/dist/infra/frontmatter-file.js +30 -0
  167. package/cli/dist/infra/git.d.ts +74 -0
  168. package/cli/dist/infra/git.js +133 -0
  169. package/cli/dist/infra/github/auth.d.ts +60 -0
  170. package/cli/dist/infra/github/auth.js +158 -0
  171. package/cli/dist/infra/github/client.d.ts +173 -0
  172. package/cli/dist/infra/github/client.js +576 -0
  173. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  174. package/cli/dist/infra/github/dependabot-source.js +33 -0
  175. package/cli/dist/infra/github/errors.d.ts +47 -0
  176. package/cli/dist/infra/github/errors.js +42 -0
  177. package/cli/dist/infra/github/index.d.ts +13 -0
  178. package/cli/dist/infra/github/index.js +19 -0
  179. package/cli/dist/infra/github/issues.d.ts +129 -0
  180. package/cli/dist/infra/github/issues.js +273 -0
  181. package/cli/dist/infra/github/payload.d.ts +44 -0
  182. package/cli/dist/infra/github/payload.js +80 -0
  183. package/cli/dist/infra/github/projects.d.ts +108 -0
  184. package/cli/dist/infra/github/projects.js +303 -0
  185. package/cli/dist/infra/github/pulls.d.ts +80 -0
  186. package/cli/dist/infra/github/pulls.js +161 -0
  187. package/cli/dist/infra/github/queries.d.ts +36 -0
  188. package/cli/dist/infra/github/queries.js +883 -0
  189. package/cli/dist/infra/github/readout.d.ts +18 -0
  190. package/cli/dist/infra/github/readout.js +156 -0
  191. package/cli/dist/infra/github/repos.d.ts +68 -0
  192. package/cli/dist/infra/github/repos.js +137 -0
  193. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  194. package/cli/dist/infra/github/rest-path.js +31 -0
  195. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  196. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  197. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  198. package/cli/dist/infra/gitignore-spec.js +235 -0
  199. package/cli/dist/infra/nx-scope.d.ts +51 -0
  200. package/cli/dist/infra/nx-scope.js +182 -0
  201. package/cli/dist/infra/os-error.d.ts +24 -0
  202. package/cli/dist/infra/os-error.js +38 -0
  203. package/cli/dist/infra/paths.d.ts +88 -0
  204. package/cli/dist/infra/paths.js +234 -0
  205. package/cli/dist/infra/state-store.d.ts +45 -0
  206. package/cli/dist/infra/state-store.js +118 -0
  207. package/cli/dist/infra/template-store.d.ts +15 -0
  208. package/cli/dist/infra/template-store.js +34 -0
  209. package/cli/dist/infra/text-file.d.ts +12 -0
  210. package/cli/dist/infra/text-file.js +33 -0
  211. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  212. package/cli/dist/infra/worktree-copy.js +95 -0
  213. package/cli/dist/infra/worktree-links.d.ts +139 -0
  214. package/cli/dist/infra/worktree-links.js +433 -0
  215. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  216. package/cli/dist/infra/worktree-setup.js +41 -0
  217. package/cli/dist/infra/worktree.d.ts +174 -0
  218. package/cli/dist/infra/worktree.js +567 -0
  219. package/cli/dist/mcp/result.d.ts +33 -0
  220. package/cli/dist/mcp/result.js +52 -0
  221. package/cli/dist/mcp/serve.d.ts +51 -0
  222. package/cli/dist/mcp/serve.js +183 -0
  223. package/cli/dist/mcp/server.d.ts +21 -0
  224. package/cli/dist/mcp/server.js +128 -0
  225. package/cli/dist/mcp/session-directory.d.ts +26 -0
  226. package/cli/dist/mcp/session-directory.js +84 -0
  227. package/cli/dist/package.json +1 -0
  228. package/cli/dist/version.d.ts +17 -0
  229. package/cli/dist/version.js +42 -0
  230. package/cli/templates/comment/merge-diff.md +34 -0
  231. package/cli/templates/comment/plan.md +181 -0
  232. package/cli/templates/comment/precede-notify.md +33 -0
  233. package/cli/templates/comment/review-findings.md +42 -0
  234. package/cli/templates/comment/review-resolution.md +48 -0
  235. package/cli/templates/issue/bug.md +63 -0
  236. package/cli/templates/issue/epic.md +54 -0
  237. package/cli/templates/issue/task-implement.md +67 -0
  238. package/cli/templates/issue/task.md +48 -0
  239. package/cli/templates/issue/tracker.md +48 -0
  240. package/cli/templates/pr/create.md +123 -0
  241. package/cli/templates/pr/release.md +56 -0
  242. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  243. package/npm-shrinkwrap.json +83 -0
  244. package/package.json +22 -4
@@ -0,0 +1,196 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは利用者の引数とテンプレートの置き場で決まる */
3
+ // issue comment。cli/commands/issue.py の issue_comment とその内部関数の移植。
4
+ import { existsSync, writeFileSync } from 'node:fs';
5
+ import { z } from 'zod';
6
+ import { isRepositoryInProject } from '../domain/config.js';
7
+ import { FrontmatterError, setFrontmatterValue } from '../domain/frontmatter.js';
8
+ import { jsonField } from '../domain/json.js';
9
+ import { pythonStrip } from '../domain/python-format.js';
10
+ import { OsError, toOsError } from '../infra/os-error.js';
11
+ import { parseCommentFile } from '../infra/frontmatter-file.js';
12
+ import { GitHubAPIError } from '../infra/github/errors.js';
13
+ import { OutputPathReservationError, outputDirectory, withReservedOutputPath } from '../infra/paths.js';
14
+ import { readTextFile } from '../infra/text-file.js';
15
+ import { templateFile } from '../infra/template-store.js';
16
+ import { defineCommand, CommandExit } from './command-definition.js';
17
+ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
18
+ import { createGitHubClient } from './github-client.js';
19
+ import { COMMENT_VALIDATION_EXIT_CODE, hasReportedTemplateViolations, issuePath, parseIssueReferenceOrExit, runWithExit, } from './issue-shared.js';
20
+ import { createOutput } from './output.js';
21
+ const TEMPLATE_SCHEMA = z.enum(['plan', 'merge-diff', 'review-findings', 'review-resolution', 'precede-notify']);
22
+ const TEMPLATE_CHOICES = TEMPLATE_SCHEMA.options.join(' / ');
23
+ // PR へのコメントは GitHub が /pull/ の形で html_url を返すので、両方受ける
24
+ const COMMENT_URL_PATTERN = /^https?:\/\/(?<host>[^/]+)\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/(?:issues|pull)\/(?<number>\d+)#issuecomment-(?<id>\d+)$/u;
25
+ function htmlUrlOf(comment, fallback) {
26
+ const url = jsonField(comment, 'html_url');
27
+ return typeof url === 'string' ? url : fallback;
28
+ }
29
+ // テンプレートをコピーして、そのパスを標準出力に出す。issue_ref が渡されていれば、コピーの issue_ref に入れる
30
+ function prepareTemplate(output, template, issueReference) {
31
+ const templatePath = templateFile('comment', template);
32
+ if (!existsSync(templatePath)) {
33
+ stopWith(output, `template not found: ${templatePath}`);
34
+ }
35
+ let content = readTextFile(templatePath);
36
+ if (issueReference !== undefined && issueReference !== '') {
37
+ content = content.replaceAll('issue_ref: ""', () => `issue_ref: "${issueReference}"`);
38
+ }
39
+ try {
40
+ withReservedOutputPath(outputDirectory(), timestamp => `comment-${template}-${timestamp}.md`, (reserved) => {
41
+ writeFileSync(reserved, content, 'utf8');
42
+ output.data(reserved);
43
+ });
44
+ }
45
+ catch (error) {
46
+ if (!(error instanceof OutputPathReservationError))
47
+ throw error;
48
+ stopWith(output, error.message);
49
+ }
50
+ }
51
+ // comment_url からコメントの id を取る。issue_ref と別の Issue を指していたら終了コード 1
52
+ function commentIdFor(output, commentUrl, host, target) {
53
+ const groups = COMMENT_URL_PATTERN.exec(pythonStrip(commentUrl))?.groups;
54
+ if (groups === undefined) {
55
+ return stopWith(output, `comment_url has the wrong form: ${commentUrl}\nexpected: https://<host>/<owner>/<repo>/{issues|pull}/<number>#issuecomment-<id>`);
56
+ }
57
+ const { host: urlHost = '', owner = '', repo: urlRepository = '', number = '', id = '' } = groups;
58
+ if (urlHost.toLowerCase() !== host.toLowerCase()) {
59
+ return stopWith(output, `the host of comment_url (${urlHost}) differs from the configured host (${host})`);
60
+ }
61
+ const isSameIssue = owner.toLowerCase() === target.owner.toLowerCase()
62
+ && urlRepository.toLowerCase() === target.repository.toLowerCase()
63
+ && Number(number) === target.number;
64
+ const message = `comment_url (${owner}/${urlRepository}/${number}) points to a different Issue than issue_ref (${target.owner}/${target.repository}/${String(target.number)})`;
65
+ return isSameIssue ? Number(id) : stopWith(output, message);
66
+ }
67
+ // 次に同じファイルを渡したとき更新になるよう、URL を書き戻す。できなければ warning だけ出す
68
+ function writeBackCommentUrl(output, file, commentUrl) {
69
+ try {
70
+ const content = readTextFile(file);
71
+ writeFileSync(file, setFrontmatterValue(content, 'comment_url', commentUrl), 'utf8');
72
+ }
73
+ catch (error) {
74
+ const converted = toOsError(error, file);
75
+ if (converted instanceof OsError || converted instanceof FrontmatterError) {
76
+ output.warning(`could not write comment_url back to the file: ${converted.message}`);
77
+ return;
78
+ }
79
+ throw converted;
80
+ }
81
+ }
82
+ // コメントを作って created の行と URL を出す。失敗は error の行と終了コード 1。作ったコメントの URL を返す
83
+ async function createComment(output, client, target, body) {
84
+ const display = issuePath(target.owner, target.repository, target.number);
85
+ let comment;
86
+ try {
87
+ comment = await client.addIssueComment(target.owner, target.repository, target.number, body);
88
+ }
89
+ catch (error) {
90
+ if (!(error instanceof GitHubAPIError))
91
+ throw error;
92
+ return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}`);
93
+ }
94
+ const createdUrl = htmlUrlOf(comment, '');
95
+ output.done({ verb: 'create', target: `comment on ${display}` });
96
+ output.data(createdUrl);
97
+ return createdUrl;
98
+ }
99
+ // comment_url のコメントを書き換える。失敗は error の行と終了コード 1
100
+ async function updateComment(output, client, target, commentId, commentUrl, body) {
101
+ const display = issuePath(target.owner, target.repository, target.number);
102
+ let comment;
103
+ try {
104
+ comment = await client.updateIssueComment(target.owner, target.repository, commentId, body);
105
+ }
106
+ catch (error) {
107
+ if (!(error instanceof GitHubAPIError))
108
+ throw error;
109
+ return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}`);
110
+ }
111
+ output.done({ verb: 'update', target: `comment on ${display}` });
112
+ output.data(htmlUrlOf(comment, commentUrl));
113
+ }
114
+ async function postFromFile(output, config, repository, file) {
115
+ let parsed;
116
+ try {
117
+ parsed = parseCommentFile(file);
118
+ }
119
+ catch (error) {
120
+ if (!(error instanceof FrontmatterError))
121
+ throw error;
122
+ return stopWith(output, error.message);
123
+ }
124
+ const { frontmatter, body } = parsed;
125
+ const target = parseIssueReferenceOrExit(output, repository, frontmatter.issue_ref);
126
+ if (frontmatter.template === undefined) {
127
+ return stopWith(output, `specify template in the frontmatter (${TEMPLATE_CHOICES})`);
128
+ }
129
+ if (hasReportedTemplateViolations(output, body, templateFile('comment', frontmatter.template)))
130
+ throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE);
131
+ // comment_url は、issue_ref と同じ Issue のコメントに限る
132
+ const commentUrl = frontmatter.comment_url;
133
+ const hasCommentUrl = commentUrl !== undefined && commentUrl !== '';
134
+ const commentId = hasCommentUrl ? commentIdFor(output, commentUrl, config.host, target) : 0;
135
+ const client = createGitHubClient(output, config.host);
136
+ if (!await isRepositoryInProject(config, target.owner, target.repository, client)) {
137
+ output.warning(`${target.owner}/${target.repository} is not in the project`);
138
+ }
139
+ if (hasCommentUrl) {
140
+ await updateComment(output, client, target, commentId, commentUrl, body);
141
+ return;
142
+ }
143
+ const createdUrl = await createComment(output, client, target, body);
144
+ if (createdUrl !== '')
145
+ writeBackCommentUrl(output, file, createdUrl);
146
+ }
147
+ async function postDirect(output, config, repository, issueReference, message, template) {
148
+ const target = parseIssueReferenceOrExit(output, repository, issueReference);
149
+ if (hasReportedTemplateViolations(output, message, templateFile('comment', template)))
150
+ throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE);
151
+ await createComment(output, createGitHubClient(output, config.host), target, message);
152
+ }
153
+ const ISSUE_COMMENT = defineCommand({
154
+ path: ['issue', 'comment'],
155
+ description: 'Post a comment on an Issue',
156
+ input: z.object({
157
+ file: z.string().optional().describe('Path of a Markdown file with frontmatter'),
158
+ message: z.string().optional().describe('Comment body'),
159
+ issue: z.string().optional().describe('Issue reference (owner/repo/123 form, required with -m)'),
160
+ prepare: z.boolean().default(false).describe('Copy a template to the work directory'),
161
+ template: TEMPLATE_SCHEMA.optional().describe('Template type (required with --prepare and -m; plan/merge-diff/review-findings/review-resolution/precede-notify)'),
162
+ }),
163
+ positional: ['file'],
164
+ shortFlags: { message: '-m', issue: '-i', prepare: '-p', template: '-t' },
165
+ interactive: false,
166
+ run: async (input, io) => {
167
+ const output = createOutput(false, io);
168
+ return await runWithExit(async () => {
169
+ const { file, message, issue, prepare, template } = input;
170
+ if (template === undefined && (prepare || (message !== undefined && file === undefined))) {
171
+ stopWith(output, `specify a template with -t (${TEMPLATE_CHOICES})`);
172
+ }
173
+ if (prepare && template !== undefined) {
174
+ prepareTemplate(output, template, issue);
175
+ return;
176
+ }
177
+ if (file !== undefined) {
178
+ await postFromFile(output, requireActiveConfigPlain(output), input.repo, file);
179
+ return;
180
+ }
181
+ if (message !== undefined && template !== undefined) {
182
+ if (issue === undefined || issue === '') {
183
+ stopWith(output, '--issue (Issue reference) is required with -m');
184
+ }
185
+ await postDirect(output, requireActiveConfigPlain(output), input.repo, issue, message, template);
186
+ return;
187
+ }
188
+ stopWith(output, 'missing arguments\n'
189
+ + 'direct posting: pecot issue comment -m "MESSAGE" -t <template> --issue owner/repo/123\n'
190
+ + 'prepare a template: pecot issue comment --prepare -t <template>\n'
191
+ + 'from a file: pecot issue comment <path>');
192
+ });
193
+ },
194
+ });
195
+ export const ISSUE_COMMENT_COMMANDS = [ISSUE_COMMENT];
196
+ //# sourceMappingURL=issue-comment.js.map
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_CREATE_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue-create.d.ts.map
@@ -0,0 +1,329 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは利用者の引数で決まる */
3
+ // issue create。cli/commands/issue.py の issue_create の移植。--prepare・ファイル・-m の 3 つの形がある。
4
+ import { existsSync, statSync, writeFileSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { z } from 'zod';
7
+ import { splitOwnerRepository } from '../domain/repository-resolver.js';
8
+ import { FrontmatterError, stripFrontmatter, stripLeadingHtmlComment } from '../domain/frontmatter.js';
9
+ import { FLAG_ISSUE_CREATE_SLASH_PENDING, FLAG_ISSUE_PENDING } from '../domain/state.js';
10
+ import { compareStrings, pythonStrip, pythonStringRepr } from '../domain/python-format.js';
11
+ import { parseIssueFile } from '../infra/frontmatter-file.js';
12
+ import { OutputPathReservationError, normalizePath, outputDirectory, resolveRealPath, withReservedOutputPath } from '../infra/paths.js';
13
+ import { consumeFlag } from '../infra/state-store.js';
14
+ import { templateFile } from '../infra/template-store.js';
15
+ import { readTextFile } from '../infra/text-file.js';
16
+ import { defineCommand } from './command-definition.js';
17
+ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
18
+ import { addToBoardOrWarn, buildIssueTitle, clientForIssueCreate, createIssueOrExit, ISSUE_TYPE_SCHEMA, issuePath, linkToParentEpic, normalizeParentEpicCli, PARENT_EPIC_DESCRIPTION, resolveEpicTargetRepository, resolveParentEpicReference, runWithExit, setIssueFields, summarizeCreatedIssue, TYPE_DEFAULT_STATUS, validateIssueTemplate, validateStatusForType, warnEpicRepositoryException, } from './issue-shared.js';
19
+ import { createOutput } from './output.js';
20
+ import { USAGE_EXIT_CODE } from './usage-error.js';
21
+ const FILES_SCHEMA = z.array(z.string()).optional().describe('Path of a Markdown file with frontmatter (several for a batch post)');
22
+ const LABEL_SCHEMA = z.array(z.string()).optional().describe('Label (can be given several times)');
23
+ const TEMPLATE_SCHEMA = z.enum(['task', 'bug', 'epic', 'tracker', 'task-implement']).default('task').describe('Template type (with --prepare: task/bug/epic/tracker/task-implement)');
24
+ // 一括投稿の先行 Issue 番号の置き場所。key は先行ファイルの --suffix 由来か、ファイルの stem
25
+ const PLACEHOLDER_PATTERN = /\{\{issue:([^{}\s]+)\}\}/gu;
26
+ // --prepare --suffix が作るファイル名 `issue-<template>-<YYYYMMDD>-<HHMMSS>-<suffix>`
27
+ const PREPARED_FILENAME_PATTERN = /^issue-.+-\d{8}-\d{6}-(?<suffix>.+)$/u;
28
+ // Python の `$` は末尾の改行の前にも当たる
29
+ const REPOSITORY_SEGMENT_PATTERN = /^[\w.-]+\n?$/u;
30
+ // --- 共通 ---
31
+ // owner/repo の形が不正なら error と終了コード 2。正しければ owner と name を返す
32
+ function validateRepositoryShape(output, repository) {
33
+ const parts = splitOwnerRepository(repository);
34
+ const isValid = parts !== undefined && REPOSITORY_SEGMENT_PATTERN.test(parts.owner) && REPOSITORY_SEGMENT_PATTERN.test(parts.repository);
35
+ const message = `invalid repository format: ${repository}\nexpected: owner/repo`;
36
+ return isValid ? [parts.owner, parts.repository] : stopWith(output, message, USAGE_EXIT_CODE);
37
+ }
38
+ /**
39
+ Issue を作ってボードへ足し、欄の設定・親 Epic への接続・URL の出力まで行う。
40
+ ボードへの追加に失敗したら、そこで止める。作った Issue の番号を返す
41
+ */
42
+ async function postIssue(output, client, config, posting) {
43
+ const { owner, repository } = posting;
44
+ const issue = await createIssueOrExit(output, client, owner, repository, posting.title, posting.body, posting.labels, posting.source);
45
+ const { number, url, nodeId } = summarizeCreatedIssue(issue);
46
+ const target = `Issue ${issuePath(owner, repository, number)}`;
47
+ consumeFlag(FLAG_ISSUE_PENDING);
48
+ const added = await addToBoardOrWarn(output, client, config, owner, repository, number, posting.useResponseNodeId ? nodeId : undefined, url);
49
+ if (added === undefined)
50
+ return number;
51
+ await setIssueFields(output, client, config, added.itemId, target, posting.fields);
52
+ if (posting.parentReference !== undefined)
53
+ await linkToParentEpic(output, client, target, posting.parentReference, added.issueNodeId, url);
54
+ output.data(url);
55
+ return number;
56
+ }
57
+ function parentReferenceOf(raw, config, owner, repository) {
58
+ return raw === undefined ? undefined : resolveParentEpicReference(raw, config, owner, repository);
59
+ }
60
+ // --- --prepare ---
61
+ function prepareTemplate(output, template, repository, suffix) {
62
+ if (template !== 'epic' && repository === undefined) {
63
+ stopWith(output, '--repo owner/repo is required with --template task|bug|tracker|task-implement', USAGE_EXIT_CODE);
64
+ }
65
+ if (repository !== undefined)
66
+ validateRepositoryShape(output, repository);
67
+ const source = templateFile('issue', template);
68
+ if (!existsSync(source)) {
69
+ stopWith(output, `template not found: ${source}`);
70
+ }
71
+ let content = readTextFile(source);
72
+ // 置き換えの文字列に `$` があっても、そのまま入れる
73
+ if (repository !== undefined)
74
+ content = content.replace('repository: ""', () => `repository: ${repository}`);
75
+ const nameSuffix = suffix === undefined || suffix === '' ? '' : `-${suffix}`;
76
+ try {
77
+ withReservedOutputPath(outputDirectory(), timestamp => `issue-${template}-${timestamp}${nameSuffix}.md`, (reserved) => {
78
+ writeFileSync(reserved, content, 'utf8');
79
+ output.data(reserved);
80
+ });
81
+ }
82
+ catch (error) {
83
+ if (!(error instanceof OutputPathReservationError))
84
+ throw error;
85
+ stopWith(output, error.message);
86
+ }
87
+ }
88
+ // --- ファイルからの一括投稿 ---
89
+ function fileKeys(file) {
90
+ const stem = path.parse(path.basename(file)).name;
91
+ const keys = new Set([stem]);
92
+ const suffix = PREPARED_FILENAME_PATTERN.exec(stem)?.groups?.['suffix'];
93
+ if (suffix !== undefined)
94
+ keys.add(suffix);
95
+ return keys;
96
+ }
97
+ function isFile(file) {
98
+ try {
99
+ return statSync(file).isFile();
100
+ }
101
+ catch {
102
+ return false;
103
+ }
104
+ }
105
+ // 1 件も投稿しないうちに、ファイルの重複・不在と、先行を指さないプレースホルダを止める
106
+ function validatePlaceholders(output, files) {
107
+ const seen = new Set();
108
+ const available = new Set();
109
+ for (const file of files) {
110
+ const resolved = resolveRealPath(file);
111
+ if (seen.has(resolved)) {
112
+ stopWith(output, `file specified more than once: ${normalizePath(file)}`);
113
+ }
114
+ seen.add(resolved);
115
+ if (!isFile(file)) {
116
+ stopWith(output, `file not found: ${normalizePath(file)}`);
117
+ }
118
+ // フロントマターと冒頭のガイドコメントは投稿本文に出ないので、走査から外す
119
+ const body = stripLeadingHtmlComment(stripFrontmatter(readTextFile(file)));
120
+ for (const [, reference] of body.matchAll(PLACEHOLDER_PATTERN)) {
121
+ if (reference === undefined || available.has(reference))
122
+ continue;
123
+ stopWith(output, `{{issue:${reference}}} in ${path.basename(file)} does not point to an earlier file (forward reference or unknown key)\nput the file it depends on earlier in the arguments`);
124
+ }
125
+ const keys = fileKeys(file);
126
+ const collided = [...keys].filter(key => available.has(key)).toSorted(compareStrings);
127
+ if (collided.length > 0) {
128
+ stopWith(output, `placeholder keys collide: ${collided.join(', ')} (${path.basename(file)})`);
129
+ }
130
+ for (const key of keys)
131
+ available.add(key);
132
+ }
133
+ }
134
+ // ファイル入力の作成先。Epic は aggregation_repo の方針で決める
135
+ function fileTargetRepository(output, frontmatter, config) {
136
+ let resolved;
137
+ if (frontmatter.type === 'epic') {
138
+ const explicit = frontmatter.repository === '' ? undefined : pythonStrip(frontmatter.repository);
139
+ const target = resolveEpicTargetRepository(output, explicit, config);
140
+ if (target.needsWarning)
141
+ warnEpicRepositoryException(output, target.repository, config);
142
+ resolved = target.repository;
143
+ }
144
+ else {
145
+ resolved = frontmatter.repository;
146
+ }
147
+ const parts = splitOwnerRepository(resolved);
148
+ if (parts === undefined) {
149
+ stopWith(output, `invalid repository format in the frontmatter: ${pythonStringRepr(frontmatter.repository)}`);
150
+ }
151
+ return [parts.owner, parts.repository];
152
+ }
153
+ function expandPlaceholders(body, created, owner, repository) {
154
+ return body.replaceAll(PLACEHOLDER_PATTERN, (whole, key) => {
155
+ const issue = created.get(key);
156
+ if (issue === undefined)
157
+ return whole;
158
+ return issue.repository === `${owner}/${repository}` ? `#${String(issue.number)}` : `${issue.repository}#${String(issue.number)}`;
159
+ });
160
+ }
161
+ function frontmatterFields(frontmatter) {
162
+ const fields = [{ fieldName: 'workflow', optionName: frontmatter.status, label: `status ${frontmatter.status}` }];
163
+ if (frontmatter.priority !== undefined)
164
+ fields.push({ fieldName: 'priority', optionName: frontmatter.priority, label: `priority ${frontmatter.priority}` });
165
+ if (frontmatter.size !== undefined)
166
+ fields.push({ fieldName: 'size', optionName: frontmatter.size, label: `size ${frontmatter.size}` });
167
+ return fields;
168
+ }
169
+ async function createFromFile(output, file, created) {
170
+ const config = requireActiveConfigPlain(output);
171
+ let parsed;
172
+ try {
173
+ parsed = parseIssueFile(file);
174
+ }
175
+ catch (error) {
176
+ if (!(error instanceof FrontmatterError))
177
+ throw error;
178
+ return stopWith(output, error.message);
179
+ }
180
+ const { frontmatter } = parsed;
181
+ const [owner, repository] = fileTargetRepository(output, frontmatter, config);
182
+ const body = created.size > 0 ? expandPlaceholders(parsed.body, created, owner, repository) : parsed.body;
183
+ validateIssueTemplate(output, frontmatter.template ?? frontmatter.type, body);
184
+ // 作成より前に、純粋な判定で止める
185
+ validateStatusForType(output, frontmatter.type, frontmatter.status);
186
+ const parentReference = parentReferenceOf(frontmatter.parent_epic, config, owner, repository);
187
+ const title = buildIssueTitle(frontmatter.type, frontmatter.title, { parentEpic: parentReference?.number, order: frontmatter.order, parallel: frontmatter.parallel });
188
+ const client = await clientForIssueCreate(output, config, owner, repository, frontmatter.repository, parentReference, frontmatter.order, frontmatter.parallel);
189
+ const number = await postIssue(output, client, config, {
190
+ owner,
191
+ repository,
192
+ title,
193
+ body,
194
+ labels: frontmatter.labels.length > 0 ? frontmatter.labels : undefined,
195
+ source: path.basename(file),
196
+ useResponseNodeId: false,
197
+ fields: frontmatterFields(frontmatter),
198
+ parentReference,
199
+ });
200
+ return { repository: `${owner}/${repository}`, number };
201
+ }
202
+ async function createFromFiles(output, files) {
203
+ validatePlaceholders(output, files);
204
+ const created = new Map();
205
+ for (const file of files) {
206
+ const issue = await createFromFile(output, file, created);
207
+ for (const key of fileKeys(file))
208
+ created.set(key, issue);
209
+ }
210
+ consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
211
+ }
212
+ // config は epic の作成先を決めるときに読み済みなら渡す。無ければ、status の確認の後に読む
213
+ async function createDirect(output, options, loadedConfig) {
214
+ const { issueType } = options;
215
+ // status は設定の取得や作成より前に確かめる
216
+ let status;
217
+ if (options.status === undefined) {
218
+ // eslint-disable-next-line security/detect-object-injection -- issueType は列挙型
219
+ status = TYPE_DEFAULT_STATUS[issueType];
220
+ }
221
+ else {
222
+ validateStatusForType(output, issueType, options.status);
223
+ status = options.status;
224
+ }
225
+ const config = loadedConfig ?? requireActiveConfigPlain(output);
226
+ const [owner, repository] = validateRepositoryShape(output, options.repository);
227
+ const parentReference = parentReferenceOf(normalizeParentEpicCli(options.parentEpic), config, owner, repository);
228
+ const title = buildIssueTitle(issueType, options.title, { parentEpic: parentReference?.number, order: options.order });
229
+ validateIssueTemplate(output, issueType, options.message);
230
+ const client = await clientForIssueCreate(output, config, owner, repository, options.repository, parentReference, options.order);
231
+ const fields = [{ fieldName: 'workflow', optionName: status, label: `status ${status}` }];
232
+ if (options.priority !== undefined && options.priority !== '')
233
+ fields.push({ fieldName: 'priority', optionName: options.priority, label: `priority ${options.priority}` });
234
+ if (options.size !== undefined && options.size !== '')
235
+ fields.push({ fieldName: 'size', optionName: options.size, label: `size ${options.size}` });
236
+ await postIssue(output, client, config, {
237
+ owner,
238
+ repository,
239
+ title,
240
+ body: options.message,
241
+ labels: options.labels !== undefined && options.labels.length > 0 ? options.labels : undefined,
242
+ source: undefined,
243
+ useResponseNodeId: true,
244
+ fields,
245
+ parentReference,
246
+ });
247
+ }
248
+ // -m の作成先。epic 以外は --repo が要る。epic は aggregation_repo の方針で決める
249
+ function messageModeTarget(output, issueType, repository) {
250
+ if (issueType !== 'epic') {
251
+ if (repository === undefined || repository === '') {
252
+ stopWith(output, '-r (repository) is required with -m');
253
+ }
254
+ return { repository, config: undefined };
255
+ }
256
+ const config = requireActiveConfigPlain(output);
257
+ const target = resolveEpicTargetRepository(output, repository, config);
258
+ if (target.needsWarning)
259
+ warnEpicRepositoryException(output, target.repository, config);
260
+ return { repository: target.repository, config };
261
+ }
262
+ const USAGE_TEXT = 'missing arguments\n'
263
+ + 'direct posting: pecot issue create -t "TITLE" -r owner/repo -m "BODY"\n'
264
+ + 'prepare a template: pecot issue create --prepare --template task --repo owner/repo\n'
265
+ + 'from a file: pecot issue create <path>';
266
+ // -m の直接投稿。入力の確認から作成まで
267
+ async function createFromMessage(output, input, message) {
268
+ if (input.title === undefined || input.title === '') {
269
+ stopWith(output, '-t (title) is required with -m');
270
+ }
271
+ const target = messageModeTarget(output, input.type, input.repo);
272
+ await createDirect(output, {
273
+ message,
274
+ title: input.title,
275
+ repository: target.repository,
276
+ issueType: input.type,
277
+ status: input.status,
278
+ priority: input.priority,
279
+ size: input.size,
280
+ parentEpic: input.parent_epic,
281
+ labels: input.label,
282
+ order: input.order,
283
+ }, target.config);
284
+ consumeFlag(FLAG_ISSUE_CREATE_SLASH_PENDING);
285
+ }
286
+ const ISSUE_CREATE = defineCommand({
287
+ path: ['issue', 'create'],
288
+ hasOwnRepo: true,
289
+ ignoresGlobalRepo: true,
290
+ description: 'Create Issues from Markdown files with frontmatter',
291
+ input: z.object({
292
+ files: FILES_SCHEMA,
293
+ message: z.string().optional().describe('Issue body (direct posting mode)'),
294
+ title: z.string().optional().describe('Issue title (direct posting mode, required with -m)'),
295
+ repo: z.string().optional().describe('Repository (owner/repo form; required with -m / --prepare unless epic)'),
296
+ type: ISSUE_TYPE_SCHEMA,
297
+ status: z.string().optional().describe('Status (backlog/pending/ready/active/in_review/archived)'),
298
+ priority: z.string().optional().describe('Priority (high/medium/low)'),
299
+ size: z.string().optional().describe('Size (xs/s/m/l)'),
300
+ parent_epic: z.string().optional().describe(PARENT_EPIC_DESCRIPTION),
301
+ order: z.int().optional().describe('Order number of the subtask (used with parent_epic)'),
302
+ label: LABEL_SCHEMA,
303
+ prepare: z.boolean().default(false).describe('Copy a template to the work directory'),
304
+ template: TEMPLATE_SCHEMA,
305
+ suffix: z.string().optional().describe('Suffix of the output file name (only with --prepare)'),
306
+ }),
307
+ positional: ['files'],
308
+ shortFlags: { message: '-m', title: '-t', repo: '-r', label: '-l', prepare: '-p', suffix: '-s' },
309
+ interactive: false,
310
+ run: async (input, io) => {
311
+ const output = createOutput(false, io);
312
+ return await runWithExit(async () => {
313
+ if (input.prepare) {
314
+ prepareTemplate(output, input.template, input.repo, input.suffix);
315
+ }
316
+ else if (input.files !== undefined && input.files.length > 0) {
317
+ await createFromFiles(output, input.files);
318
+ }
319
+ else if (input.message === undefined) {
320
+ stopWith(output, USAGE_TEXT);
321
+ }
322
+ else {
323
+ await createFromMessage(output, input, input.message);
324
+ }
325
+ });
326
+ },
327
+ });
328
+ export const ISSUE_CREATE_COMMANDS = [ISSUE_CREATE];
329
+ //# sourceMappingURL=issue-create.js.map
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const ISSUE_PROJECT_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=issue-project.d.ts.map