@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,65 @@
1
+ // リリース前チェック(preflight)。git は GitRunner を受けて呼ぶ。CHANGELOG は内容(文字列)を受ける。
2
+ import { changelogFileName, changelogNotFoundMessage, extractVersionReleaseNotes, getLatestVersion, validateSemver, VersionNotFoundError } from './changelog.js';
3
+ import { PecotError } from './errors.js';
4
+ import { pythonStrip } from './python-format.js';
5
+ export class ReleaseError extends PecotError {
6
+ }
7
+ /**
8
+ git を実行して標準出力を返す。非 0 終了は ReleaseError
9
+ */
10
+ function runGit(git, arguments_) {
11
+ const result = git(arguments_);
12
+ if (result.exitCode !== 0) {
13
+ throw new ReleaseError(`git command failed: git ${arguments_.join(' ')}\n${pythonStrip(result.stderr)}`);
14
+ }
15
+ return pythonStrip(result.stdout);
16
+ }
17
+ function determineVersion(options, changelogContent) {
18
+ if (options.version === undefined) {
19
+ try {
20
+ return getLatestVersion(changelogContent, changelogFileName(options.changelogPath));
21
+ }
22
+ catch (error) {
23
+ if (error instanceof VersionNotFoundError)
24
+ throw new ReleaseError(error.message, { cause: error });
25
+ throw error;
26
+ }
27
+ }
28
+ validateSemver(options.version);
29
+ return options.version;
30
+ }
31
+ /**
32
+ リリース前チェックを実行する。
33
+ 1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
34
+ 4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
35
+ */
36
+ export async function runPreflight(options, git, countAhead) {
37
+ const { changelogContent, developBranch, releaseBranch } = options;
38
+ if (changelogContent === undefined)
39
+ throw new ReleaseError(changelogNotFoundMessage(options.changelogPath));
40
+ const remote = options.remote ?? 'origin';
41
+ const version = determineVersion(options, changelogContent);
42
+ const tagName = options.tagPrefix === undefined || options.tagPrefix === '' ? `v${version}` : `${options.tagPrefix}-v${version}`;
43
+ const localTags = runGit(git, ['tag', '-l', tagName]);
44
+ if (localTags.split('\n').includes(tagName))
45
+ throw new ReleaseError(`tag already exists locally: ${tagName}`);
46
+ const remoteTags = runGit(git, ['ls-remote', '--tags', remote, `refs/tags/${tagName}`]);
47
+ if (remoteTags !== '')
48
+ throw new ReleaseError(`tag already exists on the remote: ${tagName}`);
49
+ const diffCount = await countAhead(releaseBranch, developBranch);
50
+ if (diffCount === 0) {
51
+ throw new ReleaseError(`no difference between ${remote}/${releaseBranch} and ${remote}/${developBranch}: `
52
+ + 'there is nothing to release');
53
+ }
54
+ let releaseNotes;
55
+ try {
56
+ releaseNotes = extractVersionReleaseNotes(changelogContent, version, changelogFileName(options.changelogPath));
57
+ }
58
+ catch (error) {
59
+ if (error instanceof VersionNotFoundError)
60
+ throw new ReleaseError(error.message, { cause: error });
61
+ throw error;
62
+ }
63
+ return { version, releaseNotes, developBranch, releaseBranch, diffCount, tagName };
64
+ }
65
+ //# sourceMappingURL=release.js.map
@@ -0,0 +1,38 @@
1
+ import type { HintedText } from './command-hint.js';
2
+ import type { RepositoryReference, ResolvedRepository } from './repository-resolver.js';
3
+ export type PolicyMode = 'reject' | 'warn';
4
+ export interface PolicyInput {
5
+ /**
6
+ グローバル `--repo` の値。無ければ undefined
7
+ */
8
+ readonly explicit: string | undefined;
9
+ /**
10
+ カレント Git remote からの解決結果。解決できなければ undefined
11
+ */
12
+ readonly resolved: ResolvedRepository | undefined;
13
+ readonly mode: PolicyMode;
14
+ }
15
+ /**
16
+ 結果の種類は kind で判別する。stderr は改行を含まない行の並びで、呼ぶ側が出し先の形にして 1 行ずつ出す。
17
+ - proceed は、続行する。adopted は明示値から採用したリポジトリ(--repo が無ければ undefined)。
18
+ - exit は、stderr を出して指定の終了コードで終わる。
19
+ */
20
+ export type PolicyOutcome = {
21
+ readonly kind: 'proceed';
22
+ readonly adopted: RepositoryReference | undefined;
23
+ readonly stderr: readonly (string | HintedText)[];
24
+ } | {
25
+ readonly kind: 'exit';
26
+ readonly exitCode: 1;
27
+ readonly failure: PolicyFailure;
28
+ readonly stderr: readonly (string | HintedText)[];
29
+ };
30
+ /**
31
+ 止める原因の名前。commands の FailureKind の一部
32
+ */
33
+ export type PolicyFailure = 'git-unresolved' | 'invalid-input' | 'repo-mismatch';
34
+ /**
35
+ `--repo` とカレント Git remote の不一致時の方針を判定する
36
+ */
37
+ export declare function applyRepositoryPolicy(input: PolicyInput): PolicyOutcome;
38
+ //# sourceMappingURL=repository-policy.d.ts.map
@@ -0,0 +1,66 @@
1
+ // `--repo` 不一致方針(FR-009a / FR-009b)の判定。
2
+ //
3
+ // ローカル Git を破壊する操作系(worktree・session start・branch delete など)は reject にする。
4
+ // GitHub API 側への操作が中心のもの(release など)は warn にする。
5
+ // 判定だけを純粋な関数にする。stderr への出力と終了は、呼ぶ側(commands 層)が行う。
6
+ //
7
+ // 決定木:
8
+ // 1. --repo を指定しない場合
9
+ // - カレント Git remote を解決できたら続行する(採用値なし)。
10
+ // - 解決できなければ「リポジトリが曖昧です」で終了コード 1。
11
+ // 2. --repo を指定した場合
12
+ // - 形式が不正なら終了コード 1。
13
+ // - カレント Git remote が無い場合(Git 外・remote 無し)は、比較できないので明示値を採用して続行する。
14
+ // - 一致なら明示値を採用して続行する。
15
+ // - 不一致で reject は終了コード 1、warn は警告を出して明示値を採用して続行する。
16
+ //
17
+ // 文言は contracts/cli-commands.md の固定文言と一致させる(stderr を e2e で確かめるため)。
18
+ import { globalRepositoryHint, hinted, placeholder } from './command-hint.js';
19
+ import { InvalidValueError } from './errors.js';
20
+ import { pythonStringRepr } from './python-format.js';
21
+ import { parseOwnerRepository, repositoryFullName } from './repository-resolver.js';
22
+ function exitWith(failure, ...stderr) {
23
+ return { kind: 'exit', exitCode: 1, failure, stderr };
24
+ }
25
+ function parseExplicit(explicit) {
26
+ try {
27
+ return parseOwnerRepository(explicit);
28
+ }
29
+ catch (error) {
30
+ if (error instanceof InvalidValueError)
31
+ return undefined;
32
+ throw error;
33
+ }
34
+ }
35
+ /**
36
+ `--repo` とカレント Git remote の不一致時の方針を判定する
37
+ */
38
+ export function applyRepositoryPolicy(input) {
39
+ const { explicit, resolved, mode } = input;
40
+ if (explicit === undefined) {
41
+ return resolved === undefined
42
+ ? exitWith('git-unresolved', 'error: the repository is ambiguous', hinted ` give ${globalRepositoryHint(placeholder('owner/repo'))}`)
43
+ : { kind: 'proceed', adopted: undefined, stderr: [] };
44
+ }
45
+ const explicitReference = parseExplicit(explicit);
46
+ if (explicitReference === undefined)
47
+ return exitWith('invalid-input', hinted `error: ${globalRepositoryHint()} has an invalid form: ${pythonStringRepr(explicit)}`);
48
+ // Git 外 / remote 不在は比較対象が無いので、明示値を採用する
49
+ if (resolved?.source !== 'current-git')
50
+ return { kind: 'proceed', adopted: explicitReference, stderr: [] };
51
+ const current = resolved.repository;
52
+ if (current.owner === explicitReference.owner && current.repository === explicitReference.repository) {
53
+ return { kind: 'proceed', adopted: explicitReference, stderr: [] };
54
+ }
55
+ const explicitName = repositoryFullName(explicitReference);
56
+ const currentName = repositoryFullName(current);
57
+ if (mode === 'reject') {
58
+ return exitWith('repo-mismatch', hinted `error: ${globalRepositoryHint()} ${explicitName} differs from the current Git remote (${currentName})`, ' this command works only on the repository of the current Git remote');
59
+ }
60
+ return {
61
+ kind: 'proceed',
62
+ adopted: explicitReference,
63
+ stderr: [hinted `warning: using ${globalRepositoryHint()} ${explicitName} (current Git remote: ${currentName})`],
64
+ };
65
+ }
66
+ //# sourceMappingURL=repository-policy.js.map
@@ -0,0 +1,57 @@
1
+ import { PecotError } from './errors.js';
2
+ import type { GitRunner } from './git-runner.js';
3
+ export interface RepositoryReference {
4
+ readonly owner: string;
5
+ readonly repository: string;
6
+ }
7
+ export type ResolveSource = 'explicit' | 'current-git';
8
+ /**
9
+ 解決の結果。source が explicit のとき remoteName は undefined、current-git のとき remoteName は空でない文字列
10
+ */
11
+ export interface ResolvedRepository {
12
+ readonly repository: RepositoryReference;
13
+ readonly source: ResolveSource;
14
+ readonly remoteName: string | undefined;
15
+ }
16
+ export declare class AmbiguousRepositoryError extends PecotError {
17
+ }
18
+ /**
19
+ owner と repository の各セグメントを検証して作る。両方が不正なら 2 件を 1 つの例外にまとめる
20
+ */
21
+ export declare function createRepositoryReference(owner: string, repository: string): RepositoryReference;
22
+ export declare function repositoryFullName(reference: RepositoryReference): string;
23
+ export declare function isSameRepository(left: RepositoryReference, right: RepositoryReference): boolean;
24
+ /**
25
+ `/` で分けてちょうど 2 つなら owner と repository を返し、違えば undefined。
26
+ 中身は検証しない(`a/` や `/b` も通る)。検証は parseOwnerRepository の側
27
+ */
28
+ export declare function splitOwnerRepository(raw: string): {
29
+ readonly owner: string;
30
+ readonly repository: string;
31
+ } | undefined;
32
+ /**
33
+ `owner/repo` 形式の文字列を分ける。形式が違えば InvalidValueError
34
+ */
35
+ export declare function parseOwnerRepository(raw: string): RepositoryReference;
36
+ /**
37
+ source と remoteName の整合を検証して作る
38
+ */
39
+ export declare function createResolvedRepository(resolved: ResolvedRepository): ResolvedRepository;
40
+ /**
41
+ remote 名の一覧から主の remote を選ぶ(origin、無ければ最初)。一覧が空なら undefined
42
+ */
43
+ export declare function pickPrimaryRemote(remotes: readonly string[]): string | undefined;
44
+ /**
45
+ 現在の git の remote からリポジトリを取り出す。git の外・remote 無しは undefined。
46
+ URL の形式が不正なときは、InvalidValueError をそのまま伝える(バグ扱い)。
47
+ Python の `_detect_current_git_repo` と同じで、不正なら undefined を返す infra/git.ts の remoteRepository とは契約が違う
48
+ */
49
+ export declare function detectCurrentGitRepository(git: GitRunner): {
50
+ readonly repository: RepositoryReference;
51
+ readonly remoteName: string;
52
+ } | undefined;
53
+ /**
54
+ リポジトリを解決する。明示値があれば git を呼ばずにそれを使う
55
+ */
56
+ export declare function resolveRepository(explicit: string | undefined, git: GitRunner): ResolvedRepository;
57
+ //# sourceMappingURL=repository-resolver.d.ts.map
@@ -0,0 +1,122 @@
1
+ // マルチリポ対応のリポジトリ解決。
2
+ //
3
+ // 決定木:
4
+ // 1. 明示値(--repo)があれば、それを owner/repo として使う(source=explicit)。
5
+ // 2. git のワークツリー内なら、origin の URL から取る(source=current-git)。
6
+ // origin が無ければ、先頭の remote を使う。
7
+ // 3. どちらも成り立たなければ、AmbiguousRepositoryError を投げる。
8
+ //
9
+ // 検証エラーの文は、Python の CLI の書式に揃える。
10
+ // 表題は元のクラス名(RepoRef・ResolvedRepo)を使う。
11
+ import { formatHinted, globalRepositoryHint, hinted, placeholder } from './command-hint.js';
12
+ import { PecotError, InvalidValueError } from './errors.js';
13
+ import { parseRemoteUrl } from './git-url.js';
14
+ import { pythonStringRepr, ValidationFailure } from './python-format.js';
15
+ const SEGMENT_PATTERN = /^[\w.-]+$/u;
16
+ export class AmbiguousRepositoryError extends PecotError {
17
+ }
18
+ // `.` と `..` は、REST の URL に文字列で連結すると別のパスを指すので拒否する(Python は通していた)
19
+ function segmentIssue(field, value) {
20
+ if (value !== '.' && value !== '..' && SEGMENT_PATTERN.test(value))
21
+ return [];
22
+ return [{
23
+ type: 'value_error',
24
+ location: [field],
25
+ message: `Value error, invalid owner/repo segment: ${pythonStringRepr(value)} (allowed: [A-Za-z0-9_.-]+)`,
26
+ input: value,
27
+ }];
28
+ }
29
+ /**
30
+ owner と repository の各セグメントを検証して作る。両方が不正なら 2 件を 1 つの例外にまとめる
31
+ */
32
+ export function createRepositoryReference(owner, repository) {
33
+ const issues = [...segmentIssue('owner', owner), ...segmentIssue('repo', repository)];
34
+ if (issues.length > 0)
35
+ throw new ValidationFailure('RepoRef', issues);
36
+ return Object.freeze({ owner, repository });
37
+ }
38
+ export function repositoryFullName(reference) {
39
+ return `${reference.owner}/${reference.repository}`;
40
+ }
41
+ export function isSameRepository(left, right) {
42
+ return repositoryFullName(left).toLowerCase() === repositoryFullName(right).toLowerCase();
43
+ }
44
+ /**
45
+ `/` で分けてちょうど 2 つなら owner と repository を返し、違えば undefined。
46
+ 中身は検証しない(`a/` や `/b` も通る)。検証は parseOwnerRepository の側
47
+ */
48
+ export function splitOwnerRepository(raw) {
49
+ const [owner, repository, ...rest] = raw.split('/');
50
+ return owner === undefined || repository === undefined || rest.length > 0 ? undefined : { owner, repository };
51
+ }
52
+ /**
53
+ `owner/repo` 形式の文字列を分ける。形式が違えば InvalidValueError
54
+ */
55
+ export function parseOwnerRepository(raw) {
56
+ const parts = splitOwnerRepository(raw);
57
+ if (parts === undefined) {
58
+ throw new InvalidValueError(`invalid owner/repo form: ${pythonStringRepr(raw)} (expected: 'owner/repo')`);
59
+ }
60
+ return createRepositoryReference(parts.owner, parts.repository);
61
+ }
62
+ /**
63
+ source と remoteName の整合を検証して作る
64
+ */
65
+ export function createResolvedRepository(resolved) {
66
+ const input = {
67
+ repo: { owner: resolved.repository.owner, repo: resolved.repository.repository },
68
+ source: resolved.source,
69
+ remote_name: resolved.remoteName ?? 'None',
70
+ };
71
+ if (resolved.source === 'current-git' && (resolved.remoteName === undefined || resolved.remoteName === '')) {
72
+ throw new ValidationFailure('ResolvedRepo', [{ type: 'value_error', location: [], message: 'Value error, remote_name is required when source=CURRENT_GIT', input }]);
73
+ }
74
+ if (resolved.source === 'explicit' && resolved.remoteName !== undefined) {
75
+ throw new ValidationFailure('ResolvedRepo', [{ type: 'value_error', location: [], message: 'Value error, remote_name must be None when source=EXPLICIT', input }]);
76
+ }
77
+ return Object.freeze({ ...resolved });
78
+ }
79
+ /**
80
+ remote 名の一覧から主の remote を選ぶ(origin、無ければ最初)。一覧が空なら undefined
81
+ */
82
+ export function pickPrimaryRemote(remotes) {
83
+ return remotes.includes('origin') ? 'origin' : remotes[0];
84
+ }
85
+ /**
86
+ 現在の git の remote からリポジトリを取り出す。git の外・remote 無しは undefined。
87
+ URL の形式が不正なときは、InvalidValueError をそのまま伝える(バグ扱い)。
88
+ Python の `_detect_current_git_repo` と同じで、不正なら undefined を返す infra/git.ts の remoteRepository とは契約が違う
89
+ */
90
+ export function detectCurrentGitRepository(git) {
91
+ const inside = git(['rev-parse', '--is-inside-work-tree']);
92
+ if (inside.exitCode !== 0 || inside.stdout.trim() !== 'true')
93
+ return undefined;
94
+ const remotesResult = git(['remote']);
95
+ if (remotesResult.exitCode !== 0)
96
+ return undefined;
97
+ const remotes = remotesResult.stdout.split('\n').map(line => line.trim()).filter(line => line !== '');
98
+ const remoteName = pickPrimaryRemote(remotes);
99
+ if (remoteName === undefined)
100
+ return undefined;
101
+ const url = git(['remote', 'get-url', remoteName]);
102
+ if (url.exitCode !== 0)
103
+ return undefined;
104
+ const { owner, repository } = parseRemoteUrl(url.stdout.trim());
105
+ return { repository: createRepositoryReference(owner, repository), remoteName };
106
+ }
107
+ /**
108
+ リポジトリを解決する。明示値があれば git を呼ばずにそれを使う
109
+ */
110
+ export function resolveRepository(explicit, git) {
111
+ if (explicit !== undefined) {
112
+ return createResolvedRepository({ repository: parseOwnerRepository(explicit), source: 'explicit', remoteName: undefined });
113
+ }
114
+ const detected = detectCurrentGitRepository(git);
115
+ if (detected !== undefined) {
116
+ return createResolvedRepository({ repository: detected.repository, source: 'current-git', remoteName: detected.remoteName });
117
+ }
118
+ // 文を出すのは CLI の最上位(src/cli.ts)だけ。ほかの呼び手は捕まえて undefined にする
119
+ const repositoryHint = globalRepositoryHint(placeholder('owner/repo'));
120
+ throw new AmbiguousRepositoryError(formatHinted(hinted `repository is ambiguous: pass ${repositoryHint}`, 'cli'));
121
+ }
122
+ //# sourceMappingURL=repository-resolver.js.map
@@ -0,0 +1,69 @@
1
+ export interface SectionHeading {
2
+ readonly level: number;
3
+ /**
4
+ 見出しの文字列。em-dash サマリ込み(例: `Progress — <現在地を1行で>`)
5
+ */
6
+ readonly name: string;
7
+ }
8
+ export declare const SUMMARY_MAX_CHARS = 50;
9
+ export declare const PLAN_FOLD_SUMMARY = "<summary align=\"right\">\u8A73\u7D30\u306F\u3053\u3061\u3089</summary>";
10
+ export declare const FOLD_SUMMARY_BY_TEMPLATE: ReadonlyMap<string, string>;
11
+ /**
12
+ テンプレに無い `##` / `###` 見出しを拒否するテンプレ名と、拒否したときに添える案内文。
13
+ テンプレごとに閉じた見出しの集合を持たせる。
14
+ Python の `issue.py` の `_report_template_violations` は、この Map にテンプレ名があるときだけ 2 つの検証を掛ける。
15
+ 掛ける検証は validateFoldBalance と validateClosedHeadings。コマンドを移すときは同じ条件にする
16
+ */
17
+ export declare const CLOSED_HEADINGS_BY_TEMPLATE: ReadonlyMap<string, string>;
18
+ export declare const CHECKBOX_ERROR = "checkbox syntax (- [ ] / 1. [ ]) is not allowed";
19
+ export declare const HORIZONTAL_RULE_ERROR = "horizontal rules are not allowed";
20
+ export declare const EMOJI_ERROR = "emoji are not allowed";
21
+ export declare const SOFT_BREAK_ERROR = "a paragraph is broken across lines: GitHub shows line breaks as written, so write each paragraph on one line and separate paragraphs with a blank line";
22
+ export declare const SUMMARY_NOT_JAPANESE_ERROR = "the summary must be written in Japanese";
23
+ export declare const SUMMARY_MULTI_SENTENCE_ERROR = "the summary must be one sentence";
24
+ /**
25
+ テンプレートの内容から見出しセクションを抽出する(レベル情報付き)。
26
+ フロントマター(先頭の `---` と次の `---` の間)と、その後ろの先頭の HTML コメント(書き方ガイド)は読み飛ばし、`##`〜`######` で始まる行を拾う
27
+ */
28
+ export declare function extractSectionsFromTemplate(template: string): readonly SectionHeading[];
29
+ /**
30
+ 必須セクションの存在を確認する(見出しレベルも検証)。不足している見出しの表記を返す(例: `### Done — <summary>`)。
31
+ em-dash 付きの見出しは「ベース名 + em-dash + サマリ」の形があるかだけを見る。
32
+ サマリの規則(文字数・日本語・1 文)は validateHeadingSummaries が、未編集の `<...>` の残存は validateBodyStyle が見る(#962)。
33
+ それ以外の見出しはセクション名の前方一致をチェックする
34
+ */
35
+ export declare function validateSections(body: string, requiredSections: readonly SectionHeading[]): readonly string[];
36
+ /**
37
+ em-dash 見出しのサマリが規則を満たすか確認し、違反の表記を返す。
38
+ 規則は文字数・日本語・1 文である
39
+ (例: `## Verified — the summary must be written in Japanese`)。
40
+ 見出し自体が無いものは validateSections が不足として返すため、ここでは扱わない
41
+ */
42
+ export declare function validateHeadingSummaries(body: string, requiredSections: readonly SectionHeading[]): readonly string[];
43
+ export declare function validateBodyStyle(body: string): readonly string[];
44
+ /**
45
+ 折りたたみ(`<details>`)の開閉が対応しているかを判定する。
46
+ コードフェンス・インラインコード・HTML コメントの中の `<details>` は折りたたみとして扱わない。
47
+ 閉じられていない開きタグ、開きの無い閉じタグをエラーにする。折りたたみの外の文字数は見ない。
48
+ 未閉じのコードフェンスは空リストを返す(validateBodyStyle が別に出す)
49
+ */
50
+ export declare function validateFoldBalance(body: string): readonly string[];
51
+ /**
52
+ テンプレに無い `##` / `###` 見出しが本文に無いかを判定する。
53
+ `(level, 名前)` の組で比べる。名前は em-dash の前の部分で、サマリは見ない。
54
+ コードフェンス・インラインコード・HTML コメントの中の見出しは対象外で、`<details>` の中の見出しは対象にする。
55
+ h1 と h4 以下は縛らない。テンプレに無い見出しの表記を返す(例: `## Context`)。同じ見出しは 1 回だけ返す
56
+ */
57
+ export declare function validateClosedHeadings(body: string, requiredSections: readonly SectionHeading[]): readonly string[];
58
+ /**
59
+ 折りたたみの開閉部分(`<summary>`)が全て expected の形かを判定する。
60
+ コードフェンス・インラインコード・HTML コメントの中の `<summary>` は対象外。
61
+ 開きタグの位置から expected と一字一句一致するかを見るため、属性・文言・閉じタグのどれが違っても違反になる
62
+ */
63
+ export declare function validateFoldSummaries(body: string, expected: string): readonly string[];
64
+ /**
65
+ Summary 節に画像の参照(Markdown 記法か `<img`)があるか。フェンス・インラインコード・HTML コメントの中は数えない。
66
+ 記法は網羅しない。取りこぼしは screenshot の理由で避けられる
67
+ */
68
+ export declare function hasSummaryImage(body: string): boolean;
69
+ //# sourceMappingURL=sections.d.ts.map