@pecot/workflow-mcp 5.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +27 -22
  3. package/cli/dist/cli.js +6 -1
  4. package/cli/dist/commands/board-add.d.ts +3 -0
  5. package/cli/dist/commands/board-add.js +69 -0
  6. package/cli/dist/commands/board-judgment.d.ts +69 -0
  7. package/cli/dist/commands/board-judgment.js +150 -0
  8. package/cli/dist/commands/board-move.d.ts +3 -0
  9. package/cli/dist/commands/board-move.js +65 -0
  10. package/cli/dist/commands/board-readiness.d.ts +34 -0
  11. package/cli/dist/commands/board-readiness.js +108 -0
  12. package/cli/dist/commands/board-show.d.ts +3 -0
  13. package/cli/dist/commands/board-show.js +75 -0
  14. package/cli/dist/commands/board-sync.d.ts +3 -0
  15. package/cli/dist/commands/board-sync.js +120 -0
  16. package/cli/dist/commands/board-view.d.ts +151 -0
  17. package/cli/dist/commands/board-view.js +293 -0
  18. package/cli/dist/commands/board.d.ts +3 -0
  19. package/cli/dist/commands/board.js +12 -0
  20. package/cli/dist/commands/branch.d.ts +3 -0
  21. package/cli/dist/commands/branch.js +111 -0
  22. package/cli/dist/commands/command-binding.js +4 -0
  23. package/cli/dist/commands/command-definition.d.ts +39 -8
  24. package/cli/dist/commands/command-definition.js +20 -7
  25. package/cli/dist/commands/command-help.js +2 -2
  26. package/cli/dist/commands/command-hint.d.ts +5 -0
  27. package/cli/dist/commands/command-hint.js +13 -0
  28. package/cli/dist/commands/command-stop.d.ts +5 -3
  29. package/cli/dist/commands/command-stop.js +7 -6
  30. package/cli/dist/commands/failure-kind.d.ts +3 -0
  31. package/cli/dist/commands/failure-kind.js +35 -0
  32. package/cli/dist/commands/failure.d.ts +6 -0
  33. package/cli/dist/commands/failure.js +29 -3
  34. package/cli/dist/commands/github-client.d.ts +6 -2
  35. package/cli/dist/commands/github-client.js +13 -3
  36. package/cli/dist/commands/help.js +8 -13
  37. package/cli/dist/commands/issue-board.d.ts +61 -0
  38. package/cli/dist/commands/issue-board.js +85 -1
  39. package/cli/dist/commands/issue-comment.js +66 -30
  40. package/cli/dist/commands/issue-create.js +632 -92
  41. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  42. package/cli/dist/commands/issue-dependency.js +310 -0
  43. package/cli/dist/commands/issue-readiness.d.ts +122 -0
  44. package/cli/dist/commands/issue-readiness.js +253 -0
  45. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  46. package/cli/dist/commands/issue-reopen.js +130 -0
  47. package/cli/dist/commands/issue-shared.d.ts +33 -20
  48. package/cli/dist/commands/issue-shared.js +84 -76
  49. package/cli/dist/commands/issue-show.d.ts +3 -0
  50. package/cli/dist/commands/issue-show.js +239 -0
  51. package/cli/dist/commands/issue.d.ts +0 -1
  52. package/cli/dist/commands/issue.js +6 -8
  53. package/cli/dist/commands/names.d.ts +33 -0
  54. package/cli/dist/commands/names.js +63 -0
  55. package/cli/dist/commands/output.d.ts +32 -4
  56. package/cli/dist/commands/output.js +28 -8
  57. package/cli/dist/commands/pr-merge.d.ts +3 -0
  58. package/cli/dist/commands/pr-merge.js +230 -0
  59. package/cli/dist/commands/pr-reference.d.ts +8 -0
  60. package/cli/dist/commands/pr-reference.js +30 -0
  61. package/cli/dist/commands/pr-restack.d.ts +6 -0
  62. package/cli/dist/commands/pr-restack.js +233 -0
  63. package/cli/dist/commands/pr-waiting.d.ts +59 -0
  64. package/cli/dist/commands/pr-waiting.js +143 -0
  65. package/cli/dist/commands/pr.d.ts +23 -0
  66. package/cli/dist/commands/pr.js +378 -366
  67. package/cli/dist/commands/project-sync.d.ts +12 -3
  68. package/cli/dist/commands/project-sync.js +23 -13
  69. package/cli/dist/commands/project.d.ts +3 -2
  70. package/cli/dist/commands/project.js +371 -177
  71. package/cli/dist/commands/registry.js +15 -10
  72. package/cli/dist/commands/release.d.ts +2 -2
  73. package/cli/dist/commands/release.js +118 -130
  74. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  75. package/cli/dist/commands/renamed-commands.js +53 -0
  76. package/cli/dist/commands/repository-match.js +9 -3
  77. package/cli/dist/commands/session-finish.d.ts +3 -0
  78. package/cli/dist/commands/session-finish.js +383 -0
  79. package/cli/dist/commands/session-start.d.ts +3 -0
  80. package/cli/dist/commands/session-start.js +252 -0
  81. package/cli/dist/commands/session.d.ts +3 -0
  82. package/cli/dist/commands/session.js +186 -32
  83. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  84. package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
  85. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  86. package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
  87. package/cli/dist/commands/tracker-sync.d.ts +37 -0
  88. package/cli/dist/commands/tracker-sync.js +18 -6
  89. package/cli/dist/commands/tracker.d.ts +3 -0
  90. package/cli/dist/commands/tracker.js +20 -0
  91. package/cli/dist/commands/usage-error.d.ts +4 -0
  92. package/cli/dist/commands/usage-error.js +6 -0
  93. package/cli/dist/commands/work-target.d.ts +20 -3
  94. package/cli/dist/commands/work-target.js +49 -6
  95. package/cli/dist/commands/worktree.js +103 -33
  96. package/cli/dist/domain/batch-plan.d.ts +73 -0
  97. package/cli/dist/domain/batch-plan.js +114 -0
  98. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  99. package/cli/dist/domain/blocked-by-change.js +101 -0
  100. package/cli/dist/domain/board-move.d.ts +90 -0
  101. package/cli/dist/domain/board-move.js +92 -0
  102. package/cli/dist/domain/branch-name.js +1 -1
  103. package/cli/dist/domain/command-hint.d.ts +85 -0
  104. package/cli/dist/domain/command-hint.js +148 -0
  105. package/cli/dist/domain/config.d.ts +4 -0
  106. package/cli/dist/domain/config.js +11 -1
  107. package/cli/dist/domain/dependabot.js +1 -1
  108. package/cli/dist/domain/errors.d.ts +5 -0
  109. package/cli/dist/domain/errors.js +5 -0
  110. package/cli/dist/domain/format.d.ts +51 -4
  111. package/cli/dist/domain/format.js +72 -6
  112. package/cli/dist/domain/frontmatter.d.ts +18 -3
  113. package/cli/dist/domain/frontmatter.js +38 -12
  114. package/cli/dist/domain/issue-order.d.ts +55 -0
  115. package/cli/dist/domain/issue-order.js +65 -0
  116. package/cli/dist/domain/issue-readout.d.ts +36 -4
  117. package/cli/dist/domain/pull-request.d.ts +71 -4
  118. package/cli/dist/domain/pull-request.js +59 -10
  119. package/cli/dist/domain/readiness.d.ts +44 -0
  120. package/cli/dist/domain/readiness.js +153 -5
  121. package/cli/dist/domain/reference-parser.d.ts +3 -1
  122. package/cli/dist/domain/reference-parser.js +6 -2
  123. package/cli/dist/domain/release.d.ts +7 -3
  124. package/cli/dist/domain/release.js +5 -12
  125. package/cli/dist/domain/repository-policy.d.ts +9 -3
  126. package/cli/dist/domain/repository-policy.js +8 -7
  127. package/cli/dist/domain/repository-resolver.js +4 -1
  128. package/cli/dist/domain/restack.d.ts +62 -0
  129. package/cli/dist/domain/restack.js +53 -0
  130. package/cli/dist/domain/security-alerts.js +1 -1
  131. package/cli/dist/domain/state.d.ts +69 -0
  132. package/cli/dist/domain/state.js +67 -1
  133. package/cli/dist/domain/work-start.d.ts +30 -0
  134. package/cli/dist/domain/work-start.js +42 -0
  135. package/cli/dist/infra/authored-notes.d.ts +1 -1
  136. package/cli/dist/infra/authored-notes.js +10 -4
  137. package/cli/dist/infra/config-store.d.ts +4 -0
  138. package/cli/dist/infra/config-store.js +13 -0
  139. package/cli/dist/infra/git.d.ts +76 -0
  140. package/cli/dist/infra/git.js +123 -1
  141. package/cli/dist/infra/github/client.d.ts +5 -0
  142. package/cli/dist/infra/github/client.js +10 -7
  143. package/cli/dist/infra/github/errors.d.ts +18 -0
  144. package/cli/dist/infra/github/errors.js +22 -0
  145. package/cli/dist/infra/github/issues.d.ts +39 -3
  146. package/cli/dist/infra/github/issues.js +178 -23
  147. package/cli/dist/infra/github/projects.d.ts +35 -0
  148. package/cli/dist/infra/github/projects.js +89 -8
  149. package/cli/dist/infra/github/pulls.d.ts +105 -2
  150. package/cli/dist/infra/github/pulls.js +172 -5
  151. package/cli/dist/infra/github/queries.d.ts +15 -4
  152. package/cli/dist/infra/github/queries.js +203 -40
  153. package/cli/dist/infra/github/readout.d.ts +5 -1
  154. package/cli/dist/infra/github/readout.js +11 -33
  155. package/cli/dist/infra/github/repos.d.ts +18 -0
  156. package/cli/dist/infra/github/repos.js +31 -0
  157. package/cli/dist/infra/nx-scope.d.ts +1 -1
  158. package/cli/dist/infra/nx-scope.js +1 -1
  159. package/cli/dist/infra/state-store.d.ts +10 -1
  160. package/cli/dist/infra/state-store.js +14 -2
  161. package/cli/dist/infra/worktree-links.d.ts +3 -0
  162. package/cli/dist/infra/worktree-links.js +8 -1
  163. package/cli/dist/infra/worktree.d.ts +12 -1
  164. package/cli/dist/infra/worktree.js +40 -23
  165. package/cli/dist/mcp/result.d.ts +82 -7
  166. package/cli/dist/mcp/result.js +139 -19
  167. package/cli/dist/mcp/server.d.ts +2 -2
  168. package/cli/dist/mcp/server.js +57 -10
  169. package/cli/templates/comment/plan.md +14 -0
  170. package/cli/templates/comment/review-findings.md +3 -2
  171. package/cli/templates/issue/bug.md +13 -4
  172. package/cli/templates/issue/task-implement.md +13 -6
  173. package/cli/templates/issue/task.md +13 -4
  174. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  175. package/npm-shrinkwrap.json +2 -2
  176. package/package.json +1 -1
  177. package/cli/dist/commands/dependabot.d.ts +0 -3
  178. package/cli/dist/commands/issue-project.d.ts +0 -3
  179. package/cli/dist/commands/issue-project.js +0 -176
  180. package/cli/dist/commands/issue-quick.d.ts +0 -3
  181. package/cli/dist/commands/issue-quick.js +0 -126
  182. package/cli/dist/commands/issue-read.d.ts +0 -3
  183. package/cli/dist/commands/issue-read.js +0 -80
  184. package/cli/dist/commands/project-info.d.ts +0 -48
  185. package/cli/dist/commands/project-info.js +0 -181
  186. package/cli/dist/commands/repository.d.ts +0 -5
  187. package/cli/dist/commands/repository.js +0 -265
  188. package/cli/dist/commands/security.d.ts +0 -3
@@ -1,26 +1,31 @@
1
- import { DEPENDABOT_COMMANDS } from './dependabot.js';
2
- import { ISSUE_BOARD_COMMANDS, ISSUE_COMMANDS } from './issue.js';
1
+ // コマンド定義の一覧。CLI と MCP の両方がこの一覧から作られる。
2
+ // 各コマンドは defineCommand() で定義して、グループのファイルの一覧に足す。定義の型と defineCommand は command-definition.ts にあり、ここから再公開する。
3
+ import { BOARD_COMMANDS } from './board.js';
4
+ import { BRANCH_COMMANDS } from './branch.js';
5
+ import { registerCommandHints } from './command-hint.js';
6
+ import { ISSUE_COMMANDS } from './issue.js';
7
+ import { PR_RESTACK_COMMANDS } from './pr-restack.js';
3
8
  import { PR_COMMANDS } from './pr.js';
4
9
  import { PROJECT_COMMANDS } from './project.js';
5
10
  import { RELEASE_COMMANDS } from './release.js';
6
- import { REPOSITORY_COMMANDS } from './repository.js';
7
- import { SECURITY_COMMANDS } from './security.js';
8
11
  import { SESSION_COMMANDS } from './session.js';
12
+ import { TRACKER_COMMANDS } from './tracker.js';
9
13
  import { WORKTREE_COMMANDS } from './worktree.js';
10
14
  export { defineCommand, toolNameOf } from './command-definition.js';
11
- // 並びは Python の登録順。help の一覧と「近いコマンド」の案内が、この順で出る
15
+ // 並びは help の一覧の順で、names.ts の COMMAND_GROUPS の順に合わせる
12
16
  export const COMMANDS = [
13
- ...ISSUE_BOARD_COMMANDS,
14
- ...REPOSITORY_COMMANDS,
15
17
  ...PROJECT_COMMANDS,
18
+ ...BOARD_COMMANDS,
16
19
  ...ISSUE_COMMANDS,
17
- ...PR_COMMANDS,
18
20
  ...SESSION_COMMANDS,
21
+ ...PR_COMMANDS,
22
+ ...PR_RESTACK_COMMANDS,
19
23
  ...RELEASE_COMMANDS,
20
- ...SECURITY_COMMANDS,
21
- ...DEPENDABOT_COMMANDS,
24
+ ...TRACKER_COMMANDS,
22
25
  ...WORKTREE_COMMANDS,
26
+ ...BRANCH_COMMANDS,
23
27
  ];
28
+ registerCommandHints(COMMANDS);
24
29
  export function findCommand(path, commands = COMMANDS) {
25
30
  return commands.find(command => command.path.join(' ') === path.join(' '));
26
31
  }
@@ -2,9 +2,9 @@ import type { RepositoryReference } from '../domain/repository-resolver.js';
2
2
  import type { Output } from './output.js';
3
3
  import type { CommandDefinition } from './command-definition.js';
4
4
  /**
5
- 順は採用済みの --repo、グローバルの --repo、主の remote。決められないと error の行を出して undefined を返す。
5
+ 順は採用済みの --repo、グローバルの --repo、主の remote。決められないと error の行を出して終了コード 1 で止める。
6
6
  remote は process.cwd() から読む
7
7
  */
8
- export declare function resolveReleaseTargetRepository(adopted: RepositoryReference | undefined, explicit: string | undefined, out: Readonly<Output>): RepositoryReference | undefined;
8
+ export declare function requireReleaseTargetRepository(adopted: RepositoryReference | undefined, explicit: string | undefined, out: Readonly<Output>): RepositoryReference;
9
9
  export declare const RELEASE_COMMANDS: readonly CommandDefinition[];
10
10
  //# sourceMappingURL=release.d.ts.map
@@ -1,4 +1,4 @@
1
- // release preflight・create・merge。移す元は cli/commands/release.py。
1
+ // release check・create・merge。移す元は cli/commands/release.py。
2
2
  import path from 'node:path';
3
3
  import { z } from 'zod';
4
4
  import { describeApiError } from '../domain/api-error-detail.js';
@@ -18,90 +18,59 @@ import { TransportFailure } from '../infra/github/client.js';
18
18
  import { createDependabotSource } from '../infra/github/dependabot-source.js';
19
19
  import { GitHubAPIError, GitHubNotFoundError } from '../infra/github/errors.js';
20
20
  import { createScanAlertSource } from '../infra/github/security-alerts-source.js';
21
- import { NO_ACTIVE_PROJECT } from './command-stop.js';
21
+ import { commandHint, hinted, inputHint, inputNameHint, placeholder } from './command-hint.js';
22
+ import { NO_ACTIVE_PROJECT, stopWith } from './command-stop.js';
23
+ import { kindOfFailure } from './failure.js';
22
24
  import { createGitHubClient, makeClient } from './github-client.js';
23
- import { createOutput } from './output.js';
24
- import { defineCommand } from './command-definition.js';
25
+ import { issuePath } from './issue-shared.js';
26
+ import { createOutput, DRY_RUN_FIELD } from './output.js';
27
+ import { CommandExit, defineCommand } from './command-definition.js';
25
28
  import { requireRepositoryMatch } from './repository-match.js';
26
29
  import { USAGE_EXIT_CODE } from './usage-error.js';
27
- const FAILURE = 1;
30
+ const CHECK_PATH = ['release', 'check'];
28
31
  /**
29
- 順は採用済みの --repo、グローバルの --repo、主の remote。決められないと error の行を出して undefined を返す。
32
+ 順は採用済みの --repo、グローバルの --repo、主の remote。決められないと error の行を出して終了コード 1 で止める。
30
33
  remote は process.cwd() から読む
31
34
  */
32
- export function resolveReleaseTargetRepository(adopted, explicit, out) {
35
+ export function requireReleaseTargetRepository(adopted, explicit, out) {
33
36
  if (adopted !== undefined)
34
37
  return adopted;
35
38
  if (explicit !== undefined) {
36
- const parts = splitOwnerRepository(explicit);
37
- if (parts === undefined) {
38
- out.error(`invalid --repo format: ${pythonStringRepr(explicit)}\nspecify it as owner/repo`);
39
- return undefined;
40
- }
41
- return parts;
42
- }
43
- const remote = primaryRemoteRepository(process.cwd());
44
- if (remote === undefined) {
45
- out.error('could not read the repository from the git remote');
46
- return undefined;
39
+ return splitOwnerRepository(explicit) ?? stopWith(out, hinted `invalid ${inputNameHint(CHECK_PATH, 'repo')} format: ${pythonStringRepr(explicit)}\nspecify it as owner/repo`, 'invalid-input');
47
40
  }
41
+ const remote = primaryRemoteRepository(process.cwd()) ?? stopWith(out, 'could not read the repository from the git remote', 'git-unresolved');
48
42
  return { owner: remote.owner, repository: remote.repository };
49
43
  }
50
- // 4 つの場合(packages の有無と --package の有無)を分ける。矛盾があれば error の行を出して undefined を返す
44
+ // 4 つの場合(packages の有無と --package の有無)を分ける。矛盾があれば error の行を出して止める
51
45
  function resolvePackageContext(out, repositoryConfig, packageName, gitRoot, owner, repository) {
52
46
  const packages = repositoryConfig?.packages ?? [];
53
47
  if (repositoryConfig !== undefined && packages.length > 0) {
54
48
  const names = packages.map(item => item.name).join(', ');
55
- if (packageName === undefined) {
56
- out.error(`${owner}/${repository} is a monorepo\nspecify --package (available: ${names})`);
57
- return undefined;
58
- }
59
- const found = findPackage(repositoryConfig, packageName);
60
- if (found === undefined) {
61
- out.error(`package '${packageName}' is not registered in ${owner}/${repository}\navailable: ${names}`);
62
- return undefined;
63
- }
49
+ if (packageName === undefined)
50
+ stopWith(out, hinted `${owner}/${repository} is a monorepo\nspecify ${inputNameHint(['release', 'check'], 'package')} (available: ${names})`, 'invalid-input');
51
+ const found = findPackage(repositoryConfig, packageName) ?? stopWith(out, `package '${packageName}' is not registered in ${owner}/${repository}\navailable: ${names}`, 'invalid-input');
64
52
  return { changelogPath: path.isAbsolute(found.changelog) ? found.changelog : path.join(gitRoot, found.changelog), tagPrefix: found.name };
65
53
  }
66
- if (packageName !== undefined) {
67
- out.error(`${owner}/${repository} has no packages configured\n--package can only be used in a monorepo`);
68
- return undefined;
69
- }
54
+ if (packageName !== undefined)
55
+ stopWith(out, `${owner}/${repository} has no packages configured\n--package can only be used in a monorepo`, 'invalid-input');
70
56
  return { changelogPath: resolveChangelogPath(gitRoot, repositoryConfig?.changelog_file), tagPrefix: undefined };
71
57
  }
72
58
  function requireBranchSetting(out, branch, kind, owner, repository) {
73
- if (branch === undefined || branch === '') {
74
- out.error(`${kind}_branch is not set for ${owner}/${repository}\nset it with: pecot project set-repo ${owner}/${repository} --${kind}-branch <branch>`);
75
- return undefined;
76
- }
77
- return branch;
59
+ return branch === undefined || branch === '' ? stopWith(out, hinted `${kind}_branch is not set for ${owner}/${repository}\nset it with: ${commandHint(['project', 'link'], { repo: `${owner}/${repository}`, [`${kind}_branch`]: placeholder('branch') })}`, 'repo-setting-missing') : branch;
78
60
  }
79
61
  function loadReleaseContext(out, adopted, explicit, packageName, options = {}) {
80
62
  const cwd = process.cwd();
81
- const gitRoot = gitToplevel({ cwd });
82
- if (gitRoot === undefined) {
83
- out.error('could not find the root directory of the git repository');
84
- return undefined;
85
- }
86
- const target = resolveReleaseTargetRepository(adopted, explicit, out);
87
- if (target === undefined)
88
- return undefined;
89
- const { owner, repository } = target;
90
- const config = loadActiveConfig();
91
- if (config === undefined) {
92
- out.error(NO_ACTIVE_PROJECT);
93
- return undefined;
94
- }
63
+ const gitRoot = gitToplevel({ cwd }) ?? stopWith(out, 'could not find the root directory of the git repository', 'git-unresolved');
64
+ const { owner, repository } = requireReleaseTargetRepository(adopted, explicit, out);
65
+ const config = loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
95
66
  const repositoryConfig = findRepository(config, owner, repository);
96
67
  if (repositoryConfig !== undefined && options.nxAlertsOnly === true && effectiveReleaseType(repositoryConfig) === 'nx') {
97
68
  if (packageName !== undefined || options.version !== undefined) {
98
- out.error('the version argument and --package cannot be used when release_type is nx\nrun it without arguments (Nx Release decides the version)');
99
- return undefined;
69
+ stopWith(out, hinted `the version argument and ${inputNameHint(CHECK_PATH, 'package')} cannot be used when release_type is nx\nrun it without arguments (Nx Release decides the version)`, 'invalid-input');
100
70
  }
101
71
  return { config, owner, repository, repositoryConfig, changelogPath: resolveChangelogPath(gitRoot, repositoryConfig.changelog_file), tagPrefix: undefined };
102
72
  }
103
- const resolved = resolvePackageContext(out, repositoryConfig, packageName, gitRoot, owner, repository);
104
- return resolved === undefined ? undefined : { config, owner, repository, repositoryConfig, ...resolved };
73
+ return { config, owner, repository, repositoryConfig, ...resolvePackageContext(out, repositoryConfig, packageName, gitRoot, owner, repository) };
105
74
  }
106
75
  function alertLabel(number, packageName, severity) {
107
76
  const detail = [packageName, severity].filter(value => value !== undefined && value !== '').join(', ');
@@ -112,8 +81,8 @@ function warnAlertsUnavailable(out, reason) {
112
81
  const [first = ''] = reason.trim().split(/\r\n|[\n\r]/u, 1);
113
82
  out.warning(`could not check Dependabot alerts. The release is not blocked.\nreason: ${first.trim().replace(/\.+$/u, '').trimEnd()}`);
114
83
  }
115
- // open の Dependabot alert は警告だけで、リリースを止めない
116
- async function checkDependabotAlerts(out, config, owner, repository) {
84
+ // open の Dependabot alert は警告だけで、リリースを止めない。読めた状態を返し、読めなければ undefined
85
+ async function checkDependabotAlerts(out, config, owner, repository, skip) {
117
86
  let status;
118
87
  try {
119
88
  const client = createGitHubClient(out, config.host);
@@ -122,31 +91,32 @@ async function checkDependabotAlerts(out, config, owner, repository) {
122
91
  catch (error) {
123
92
  if (error instanceof DependabotAlertError) {
124
93
  warnAlertsUnavailable(out, error.message);
125
- return;
94
+ return undefined;
126
95
  }
127
96
  if (error instanceof GitHubAPIError) {
128
97
  warnAlertsUnavailable(out, error.message);
129
- return;
98
+ return undefined;
130
99
  }
131
100
  throw error;
132
101
  }
133
102
  if (!status.enabled) {
134
- out.done({ verb: 'skip', target: 'Dependabot alerts (feature disabled)' });
135
- return;
103
+ skip('Dependabot alerts (feature disabled)');
104
+ return status;
136
105
  }
137
106
  if (status.openCount === 0) {
138
107
  out.count('open Dependabot alerts', 0);
139
- return;
108
+ return status;
140
109
  }
141
110
  const severity = status.maxSeverity === undefined ? '' : ` (highest severity: ${status.maxSeverity})`;
142
111
  const listing = status.openAlerts.map(alert => `\n${alertLabel(alert.number, alert.package, alert.severity)}`).join('');
143
112
  const noun = status.openCount === 1 ? 'alert' : 'alerts';
144
113
  out.warning(`${String(status.openCount)} open Dependabot ${noun}${severity}. The release is not blocked.${listing}\n→ ${status.alertsUrl}`);
114
+ return status;
145
115
  }
146
116
  /**
147
117
  code scanning・secret scanning の open の alert があれば、false を返す。機能が無効のリポジトリは通る
148
118
  */
149
- async function isScanningPassed(out, name, fetchStatus) {
119
+ async function isScanningPassed(out, name, fetchStatus, skip) {
150
120
  let status;
151
121
  try {
152
122
  status = await fetchStatus();
@@ -158,7 +128,7 @@ async function isScanningPassed(out, name, fetchStatus) {
158
128
  return false;
159
129
  }
160
130
  if (!status.enabled) {
161
- out.done({ verb: 'skip', target: `${name} (feature disabled)` });
131
+ skip(`${name} (feature disabled)`);
162
132
  return true;
163
133
  }
164
134
  if (status.openCount === 0) {
@@ -172,14 +142,20 @@ async function isScanningPassed(out, name, fetchStatus) {
172
142
  /**
173
143
  3 種を確かめる。1 つが失敗しても残りを続け、最後に成否を返す
174
144
  */
175
- async function areAlertsPassed(out, config, owner, repository) {
145
+ async function checkAlerts(out, config, owner, repository) {
146
+ const skipped = [];
147
+ const skip = (target) => {
148
+ out.done({ verb: 'skip', target, aside: true });
149
+ skipped.push(target);
150
+ };
151
+ let dependabot;
176
152
  const checks = [
177
153
  async () => {
178
- await checkDependabotAlerts(out, config, owner, repository);
154
+ dependabot = await checkDependabotAlerts(out, config, owner, repository, skip);
179
155
  return true;
180
156
  },
181
- async () => await isScanningPassed(out, 'code scanning', async () => await fetchCodeScanningStatus(createScanAlertSource(createGitHubClient(out, config.host)), config.host, owner, repository)),
182
- async () => await isScanningPassed(out, 'secret scanning', async () => await fetchSecretScanningStatus(createScanAlertSource(createGitHubClient(out, config.host)), config.host, owner, repository)),
157
+ async () => await isScanningPassed(out, 'code scanning', async () => await fetchCodeScanningStatus(createScanAlertSource(createGitHubClient(out, config.host)), config.host, owner, repository), skip),
158
+ async () => await isScanningPassed(out, 'secret scanning', async () => await fetchSecretScanningStatus(createScanAlertSource(createGitHubClient(out, config.host)), config.host, owner, repository), skip),
183
159
  ];
184
160
  let isPassed = true;
185
161
  for (const check of checks) {
@@ -194,15 +170,29 @@ async function areAlertsPassed(out, config, owner, repository) {
194
170
  isPassed = false;
195
171
  }
196
172
  }
197
- return isPassed;
173
+ return { isPassed, skipped, dependabot };
198
174
  }
199
- const preflight = defineCommand({
200
- path: ['release', 'preflight'],
201
- description: 'Run the pre-release checks (preflight); for an nx repository only the alerts are checked',
175
+ const RELEASE_CHECK_OUTPUT = z.strictObject({
176
+ version: z.string().optional().describe('Version to release (omitted when release_type is nx, where only the alerts are checked)'),
177
+ tag: z.string().optional().describe('Tag to create (omitted when release_type is nx)'),
178
+ releaseNotes: z.string().optional().describe('Release notes from the CHANGELOG (omitted when release_type is nx)'),
179
+ commitCount: z.int().optional().describe('Number of commits from the release branch to the develop branch (omitted when release_type is nx)'),
180
+ skipped: z.array(z.string()).describe('Checks skipped because the feature is disabled, as in the skipped lines (e.g. "Dependabot alerts (feature disabled)")'),
181
+ dependabotAlerts: z.strictObject({
182
+ enabled: z.boolean().describe('Whether Dependabot alerts are enabled'),
183
+ openCount: z.int().describe('Number of open alerts (0 when disabled)'),
184
+ maxSeverity: z.string().optional().describe('Highest severity of the open alerts (omitted when there is none)'),
185
+ alertsUrl: z.string().describe('URL of the alert list'),
186
+ }).optional().describe('Dependabot alert status (omitted when it could not be read; the release is not blocked)'),
187
+ });
188
+ const releaseCheckCommand = defineCommand({
189
+ path: CHECK_PATH,
190
+ description: 'Run the pre-release checks; for an nx repository only the alerts are checked',
202
191
  input: z.object({
203
192
  version: z.string().optional().describe('Release version (detected from the CHANGELOG when omitted)'),
204
193
  package: z.string().optional().describe('Package name in a monorepo (required for repositories with packages configured)'),
205
194
  }),
195
+ output: RELEASE_CHECK_OUTPUT,
206
196
  positional: ['version'],
207
197
  interactive: false,
208
198
  run: async (input, io) => {
@@ -210,23 +200,23 @@ const preflight = defineCommand({
210
200
  const out = createOutput(false, io);
211
201
  const cwd = process.cwd();
212
202
  const context = loadReleaseContext(out, adopted, input.repo, input.package, { version: input.version, nxAlertsOnly: true });
213
- if (context === undefined)
214
- return FAILURE;
215
203
  const { config, owner, repository } = context;
216
- const isAlertsPassed = await areAlertsPassed(out, config, owner, repository);
217
- if (!isAlertsPassed)
218
- return FAILURE;
204
+ const alerts = await checkAlerts(out, config, owner, repository);
205
+ const { dependabot } = alerts;
206
+ out.result({
207
+ skipped: [...alerts.skipped],
208
+ ...dependabot !== undefined && { dependabotAlerts: { enabled: dependabot.enabled, openCount: dependabot.openCount, ...dependabot.maxSeverity !== undefined && { maxSeverity: dependabot.maxSeverity }, alertsUrl: dependabot.alertsUrl } },
209
+ });
210
+ if (!alerts.isPassed)
211
+ throw new CommandExit(1, 'preflight-failed');
219
212
  if (context.repositoryConfig !== undefined && effectiveReleaseType(context.repositoryConfig) === 'nx')
220
213
  return 0;
221
214
  const developBranch = requireBranchSetting(out, getDevelopBranch(config, owner, repository), 'develop', owner, repository);
222
- if (developBranch === undefined)
223
- return FAILURE;
224
215
  const releaseBranch = requireBranchSetting(out, getReleaseBranch(config, owner, repository), 'release', owner, repository);
225
- if (releaseBranch === undefined)
226
- return FAILURE;
227
216
  const remote = primaryRemoteName(cwd) ?? 'origin';
228
217
  try {
229
- const result = runPreflight({
218
+ const client = createGitHubClient(out, config.host);
219
+ const result = await runPreflight({
230
220
  changelogPath: context.changelogPath,
231
221
  changelogContent: readChangelogIfExists(context.changelogPath),
232
222
  developBranch,
@@ -234,20 +224,29 @@ const preflight = defineCommand({
234
224
  version: input.version,
235
225
  tagPrefix: context.tagPrefix,
236
226
  remote,
237
- }, gitRunnerFor(cwd));
227
+ }, gitRunnerFor(cwd), async (base, head) => await client.countCommitsAhead(owner, repository, base, head));
238
228
  out.count(`commits to release (${remote}/${result.developBranch} -> ${remote}/${result.releaseBranch})`, result.diffCount);
229
+ out.result({ version: result.version, tag: result.tagName, releaseNotes: result.releaseNotes, commitCount: result.diffCount });
239
230
  out.data(`version: ${result.version}\ntag: ${result.tagName}\n\n${result.releaseNotes}`);
240
231
  return 0;
241
232
  }
242
233
  catch (error) {
234
+ if (error instanceof GitHubAPIError || error instanceof TransportFailure) {
235
+ return stopWith(out, `could not count the commits from ${releaseBranch} to ${developBranch}: ${error.message}`, kindOfFailure(error));
236
+ }
243
237
  if (!(error instanceof ReleaseError))
244
238
  throw error;
245
- out.error(error.message);
246
- return FAILURE;
239
+ return stopWith(out, error.message, 'preflight-failed');
247
240
  }
248
241
  },
249
242
  });
250
- const create = defineCommand({
243
+ const RELEASE_CREATE_OUTPUT = z.strictObject({
244
+ tag: z.string().describe('Tag of the release'),
245
+ url: z.string().optional().describe('URL of the created release (omitted on dry_run)'),
246
+ releaseNotes: z.string().describe('Release notes from the CHANGELOG'),
247
+ dryRun: DRY_RUN_FIELD,
248
+ });
249
+ const releaseCreateCommand = defineCommand({
251
250
  path: ['release', 'create'],
252
251
  description: 'Create a GitHub release and its tag (the release notes come from the CHANGELOG)',
253
252
  input: z.object({
@@ -255,6 +254,7 @@ const create = defineCommand({
255
254
  dry_run: z.boolean().default(false).describe('Show what would happen without changing anything'),
256
255
  package: z.string().optional().describe('Package name in a monorepo (required for repositories with packages configured)'),
257
256
  }),
257
+ output: RELEASE_CREATE_OUTPUT,
258
258
  positional: ['version'],
259
259
  interactive: false,
260
260
  run: async (input, io) => {
@@ -266,12 +266,9 @@ const create = defineCommand({
266
266
  catch (error) {
267
267
  if (!(error instanceof InvalidVersionError))
268
268
  throw error;
269
- out.error(error.message);
270
- return FAILURE;
269
+ return stopWith(out, error.message, 'invalid-input');
271
270
  }
272
271
  const context = loadReleaseContext(out, adopted, input.repo, input.package);
273
- if (context === undefined)
274
- return FAILURE;
275
272
  const { config, owner, repository, tagPrefix } = context;
276
273
  let releaseNotes;
277
274
  try {
@@ -280,39 +277,42 @@ const create = defineCommand({
280
277
  catch (error) {
281
278
  if (!(error instanceof PecotError) && !(error instanceof ChangelogFileNotFoundError))
282
279
  throw error;
283
- out.error(error.message);
284
- return FAILURE;
280
+ return stopWith(out, error.message, 'preflight-failed');
285
281
  }
286
282
  const releaseBranch = requireBranchSetting(out, getReleaseBranch(config, owner, repository), 'release', owner, repository);
287
- if (releaseBranch === undefined)
288
- return FAILURE;
289
283
  const tagName = tagPrefix === undefined ? `v${input.version}` : `${tagPrefix}-v${input.version}`;
290
284
  const releaseName = tagPrefix === undefined ? tagName : `${tagPrefix} v${input.version}`;
291
285
  const operation = { verb: 'create', target: `release ${tagName} on ${releaseBranch}` };
292
286
  if (input.dry_run) {
293
287
  out.planned(operation);
288
+ out.result({ tag: tagName, releaseNotes });
294
289
  out.data(releaseNotes);
295
290
  return 0;
296
291
  }
297
292
  const client = makeClient(out, config);
298
- if (client === undefined)
299
- return FAILURE;
300
293
  try {
301
294
  const result = await client.createRelease(owner, repository, tagName, releaseName, releaseNotes, { targetCommitish: releaseBranch });
302
295
  out.done(operation);
303
296
  const url = result['html_url'];
297
+ out.result({ tag: tagName, releaseNotes, ...typeof url === 'string' && { url } });
304
298
  out.data(typeof url === 'string' ? url : '');
305
299
  return 0;
306
300
  }
307
301
  catch (error) {
308
302
  if (!(error instanceof GitHubAPIError))
309
303
  throw error;
310
- out.error(`could not create release ${tagName} in ${owner}/${repository}: ${describeApiError(error)}`);
311
- return FAILURE;
304
+ return stopWith(out, `could not create release ${tagName} in ${owner}/${repository}: ${describeApiError(error)}`, kindOfFailure(error));
312
305
  }
313
306
  },
314
307
  });
315
- const merge = defineCommand({
308
+ const RELEASE_MERGE_OUTPUT = z.strictObject({
309
+ pullRequest: z.string().describe('Release PR (owner/repo/N)'),
310
+ head: z.string().describe('Head branch of the PR'),
311
+ base: z.string().describe('Base branch of the PR (the release branch)'),
312
+ deletedBranch: z.boolean().describe('Whether the remote head branch was deleted (false without delete_branch, on dry_run, or when the deletion failed)'),
313
+ dryRun: DRY_RUN_FIELD,
314
+ });
315
+ const releaseMergeCommand = defineCommand({
316
316
  path: ['release', 'merge'],
317
317
  description: 'Merge a release PR with a regular merge',
318
318
  input: z.object({
@@ -321,17 +321,14 @@ const merge = defineCommand({
321
321
  delete_branch: z.boolean().default(false).describe('Delete the branch after merging'),
322
322
  admin: z.boolean().default(false).describe('Merge with admin rights (skip the mergeability check)'),
323
323
  }),
324
+ output: RELEASE_MERGE_OUTPUT,
324
325
  positional: ['pr_ref'],
325
326
  shortFlags: { dry_run: '-n', delete_branch: '-d' },
326
327
  interactive: false,
327
328
  run: async (input, io) => {
328
329
  requireRepositoryMatch('reject', input.repo, io, process.cwd());
329
330
  const out = createOutput(input.dry_run, io);
330
- const config = loadActiveConfig();
331
- if (config === undefined) {
332
- out.error(NO_ACTIVE_PROJECT);
333
- return FAILURE;
334
- }
331
+ const config = loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
335
332
  let reference;
336
333
  try {
337
334
  reference = parsePullRequestReference(input.pr_ref);
@@ -339,12 +336,11 @@ const merge = defineCommand({
339
336
  catch (error) {
340
337
  if (!(error instanceof ReferenceParseError))
341
338
  throw error;
342
- out.error(error.message);
343
- return USAGE_EXIT_CODE;
339
+ return stopWith(out, error.message, 'invalid-input', USAGE_EXIT_CODE);
344
340
  }
345
341
  const { owner, repository } = reference.repository;
346
342
  const number = reference.number;
347
- const pullRequestName = `${owner}/${repository}/${String(number)}`;
343
+ const pullRequestName = issuePath(owner, repository, number);
348
344
  let client;
349
345
  let pullRequest;
350
346
  try {
@@ -352,38 +348,29 @@ const merge = defineCommand({
352
348
  pullRequest = await client.getPullRequestSlim(owner, repository, number);
353
349
  }
354
350
  catch (error) {
355
- if (error instanceof GitHubNotFoundError) {
356
- out.error(`PR ${pullRequestName} not found`);
357
- return FAILURE;
358
- }
351
+ if (error instanceof GitHubNotFoundError)
352
+ return stopWith(out, `PR ${pullRequestName} not found`, 'github-not-found');
359
353
  if (!(error instanceof GitHubAPIError))
360
354
  throw error;
361
- out.error(`could not read PR ${pullRequestName}: ${describeApiError(error)}`);
362
- return FAILURE;
363
- }
364
- if (pullRequest.state === 'MERGED') {
365
- out.error(`PR #${String(number)} is already merged`);
366
- return FAILURE;
367
- }
368
- if (pullRequest.state === 'CLOSED') {
369
- out.error(`PR #${String(number)} is closed`);
370
- return FAILURE;
355
+ return stopWith(out, `could not read PR ${pullRequestName}: ${describeApiError(error)}`, kindOfFailure(error));
371
356
  }
357
+ if (pullRequest.state === 'MERGED')
358
+ stopWith(out, `PR #${String(number)} is already merged`, 'pr-state');
359
+ else if (pullRequest.state === 'CLOSED')
360
+ stopWith(out, `PR #${String(number)} is closed`, 'pr-state');
372
361
  if (pullRequest.mergeable === 'CONFLICTING' && !input.admin) {
373
- out.error(`PR #${String(number)} has conflicts that must be resolved\nto try a forced merge, add --admin`);
374
- return FAILURE;
362
+ stopWith(out, hinted `PR #${String(number)} has conflicts that must be resolved\nto try a forced merge, add ${inputHint(['release', 'merge'], 'admin')}`, 'pr-state');
375
363
  }
376
364
  const releaseBranch = requireBranchSetting(out, getReleaseBranch(config, owner, repository), 'release', owner, repository);
377
- if (releaseBranch === undefined)
378
- return FAILURE;
379
365
  if (pullRequest.base_ref !== releaseBranch) {
380
- out.error(`the base branch of PR #${String(number)} does not match release_branch\nbase: ${pullRequest.base_ref}\nrelease_branch: ${releaseBranch}`);
381
- return FAILURE;
366
+ stopWith(out, `the base branch of PR #${String(number)} does not match release_branch\nbase: ${pullRequest.base_ref}\nrelease_branch: ${releaseBranch}`, 'pr-state');
382
367
  }
383
368
  const headBranch = pullRequest.head_ref;
384
369
  const operation = { verb: 'merge', target: `PR ${pullRequestName} (${headBranch} -> ${pullRequest.base_ref}, merge commit)` };
370
+ const merged = { pullRequest: pullRequestName, head: headBranch, base: pullRequest.base_ref, deletedBranch: false };
385
371
  if (input.dry_run) {
386
372
  out.planned(operation);
373
+ out.result(merged);
387
374
  return 0;
388
375
  }
389
376
  try {
@@ -392,14 +379,15 @@ const merge = defineCommand({
392
379
  catch (error) {
393
380
  if (!(error instanceof GitHubAPIError))
394
381
  throw error;
395
- out.error(`could not merge PR ${pullRequestName}: ${describeApiError(error)}`);
396
- return FAILURE;
382
+ return stopWith(out, `could not merge PR ${pullRequestName}: ${describeApiError(error)}`, kindOfFailure(error));
397
383
  }
398
384
  out.done(operation);
385
+ out.result(merged);
399
386
  if (input.delete_branch) {
400
387
  try {
401
388
  await client.deleteBranch(owner, repository, headBranch);
402
389
  out.done({ verb: 'delete', target: `remote branch ${headBranch} in ${owner}/${repository}` });
390
+ out.result({ deletedBranch: true });
403
391
  }
404
392
  catch (error) {
405
393
  if (!(error instanceof GitHubAPIError))
@@ -410,5 +398,5 @@ const merge = defineCommand({
410
398
  return 0;
411
399
  },
412
400
  });
413
- export const RELEASE_COMMANDS = [preflight, create, merge];
401
+ export const RELEASE_COMMANDS = [releaseCheckCommand, releaseCreateCommand, releaseMergeCommand];
414
402
  //# sourceMappingURL=release.js.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ 古い名前から新しい名前への表。キーは main のコマンド名で、値は今の名前
3
+ */
4
+ export declare const RENAMED_COMMANDS: ReadonlyMap<string, string>;
5
+ /**
6
+ 解決が止まった path の古い名前と新しい名前。`dependabot` のように 1 語目で止まったときは、その語で始まる古い名前を返す。無ければ undefined
7
+ */
8
+ export declare function findRenamedCommand(path: readonly string[]): readonly [string, string] | undefined;
9
+ /**
10
+ 古い入力名。command はコマンド名、oldName は古い入力名、newName は今の入力名
11
+ */
12
+ export interface RenamedInput {
13
+ readonly command: string;
14
+ readonly oldName: string;
15
+ readonly newName: string;
16
+ }
17
+ export declare const RENAMED_INPUTS: readonly RenamedInput[];
18
+ /**
19
+ path のコマンドの古い入力名 name の、今の入力名。無ければ undefined
20
+ */
21
+ export declare function findRenamedInput(path: readonly string[], name: string): string | undefined;
22
+ /**
23
+ 誤りの文に添える、古い名前から今の名前への案内
24
+ */
25
+ export declare function renamedInputNote(oldName: string, newName: string): string;
26
+ //# sourceMappingURL=renamed-commands.d.ts.map
@@ -0,0 +1,53 @@
1
+ // #412・#428 で変えた main の古いコマンド名と入力名。CLI と MCP が案内に使い、skills のテストが古い名前を拾うのに使う。次の major で消す
2
+ /**
3
+ 古い名前から新しい名前への表。キーは main のコマンド名で、値は今の名前
4
+ */
5
+ export const RENAMED_COMMANDS = new Map([
6
+ ['add-to-project', 'board add'],
7
+ ['update-issue-status', 'board move'],
8
+ ['create-branch', 'session start'],
9
+ ['delete-branch', 'branch delete'],
10
+ ['dependabot sync', 'tracker sync dependabot'],
11
+ ['security sync', 'tracker sync security'],
12
+ ['project info', 'board show'],
13
+ ['project set-repo', 'project link'],
14
+ ['project set-aggregation-repo', 'project set aggregation_repo'],
15
+ ['project unset-aggregation-repo', 'project unset aggregation_repo'],
16
+ ['project show-aggregation-repo', 'project get aggregation_repo'],
17
+ ['issue read', 'issue show'],
18
+ ['pr read', 'pr show'],
19
+ ['pr preflight', 'pr check'],
20
+ ['pr cleanup', 'session finish'],
21
+ ['release preflight', 'release check'],
22
+ ['session status', 'session show'],
23
+ ['issue quick', 'issue create --freeform'],
24
+ ]);
25
+ /**
26
+ 解決が止まった path の古い名前と新しい名前。`dependabot` のように 1 語目で止まったときは、その語で始まる古い名前を返す。無ければ undefined
27
+ */
28
+ export function findRenamedCommand(path) {
29
+ const prefix = path.join(' ');
30
+ return [...RENAMED_COMMANDS].find(([oldName]) => oldName === prefix || oldName.startsWith(`${prefix} `));
31
+ }
32
+ export const RENAMED_INPUTS = [
33
+ { command: 'issue comment', oldName: 'issue', newName: 'issue_ref' },
34
+ { command: 'session restore', oldName: 'issue', newName: 'issue_ref' },
35
+ { command: 'branch delete', oldName: 'repo_ref', newName: 'repo' },
36
+ { command: 'project link', oldName: 'owner_repo', newName: 'repo' },
37
+ { command: 'session start', oldName: 'branch_name', newName: 'branch' },
38
+ { command: 'issue create', oldName: 'plan', newName: 'dry_run' },
39
+ ];
40
+ /**
41
+ path のコマンドの古い入力名 name の、今の入力名。無ければ undefined
42
+ */
43
+ export function findRenamedInput(path, name) {
44
+ const command = path.join(' ');
45
+ return RENAMED_INPUTS.find(entry => entry.command === command && entry.oldName === name)?.newName;
46
+ }
47
+ /**
48
+ 誤りの文に添える、古い名前から今の名前への案内
49
+ */
50
+ export function renamedInputNote(oldName, newName) {
51
+ return ` ('${oldName}' was renamed to '${newName}')`;
52
+ }
53
+ //# sourceMappingURL=renamed-commands.js.map