@pecot/workflow-mcp 5.0.0 → 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 (176) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +80 -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 +59 -0
  6. package/cli/dist/commands/board-judgment.d.ts +60 -0
  7. package/cli/dist/commands/board-judgment.js +144 -0
  8. package/cli/dist/commands/board-move.d.ts +3 -0
  9. package/cli/dist/commands/board-move.js +57 -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 +72 -0
  14. package/cli/dist/commands/board-sync.d.ts +3 -0
  15. package/cli/dist/commands/board-sync.js +111 -0
  16. package/cli/dist/commands/{project-info.d.ts → board-view.d.ts} +21 -7
  17. package/cli/dist/commands/{project-info.js → board-view.js} +22 -12
  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 +100 -0
  22. package/cli/dist/commands/command-binding.js +4 -0
  23. package/cli/dist/commands/command-definition.d.ts +20 -6
  24. package/cli/dist/commands/command-definition.js +11 -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 +34 -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 +33 -0
  38. package/cli/dist/commands/issue-board.js +61 -1
  39. package/cli/dist/commands/issue-comment.js +47 -28
  40. package/cli/dist/commands/issue-create.js +548 -91
  41. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  42. package/cli/dist/commands/issue-dependency.js +282 -0
  43. package/cli/dist/commands/issue-readiness.d.ts +94 -0
  44. package/cli/dist/commands/issue-readiness.js +218 -0
  45. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  46. package/cli/dist/commands/issue-reopen.js +115 -0
  47. package/cli/dist/commands/issue-shared.d.ts +32 -19
  48. package/cli/dist/commands/issue-shared.js +82 -75
  49. package/cli/dist/commands/issue-show.d.ts +3 -0
  50. package/cli/dist/commands/issue-show.js +169 -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 +62 -0
  55. package/cli/dist/commands/output.d.ts +14 -2
  56. package/cli/dist/commands/output.js +14 -7
  57. package/cli/dist/commands/pr-waiting.d.ts +20 -0
  58. package/cli/dist/commands/pr-waiting.js +106 -0
  59. package/cli/dist/commands/pr.d.ts +19 -0
  60. package/cli/dist/commands/pr.js +242 -323
  61. package/cli/dist/commands/project-sync.d.ts +2 -1
  62. package/cli/dist/commands/project-sync.js +18 -9
  63. package/cli/dist/commands/project.d.ts +3 -2
  64. package/cli/dist/commands/project.js +212 -175
  65. package/cli/dist/commands/registry.js +13 -10
  66. package/cli/dist/commands/release.d.ts +2 -2
  67. package/cli/dist/commands/release.js +53 -114
  68. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  69. package/cli/dist/commands/renamed-commands.js +53 -0
  70. package/cli/dist/commands/repository-match.js +3 -2
  71. package/cli/dist/commands/session-finish.d.ts +3 -0
  72. package/cli/dist/commands/session-finish.js +267 -0
  73. package/cli/dist/commands/session-start.d.ts +3 -0
  74. package/cli/dist/commands/{repository.js → session-start.js} +99 -128
  75. package/cli/dist/commands/session.d.ts +3 -0
  76. package/cli/dist/commands/session.js +82 -29
  77. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  78. package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +57 -66
  79. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  80. package/cli/dist/commands/{security.js → tracker-sync-security.js} +50 -61
  81. package/cli/dist/commands/tracker-sync.d.ts +7 -0
  82. package/cli/dist/commands/tracker-sync.js +3 -6
  83. package/cli/dist/commands/tracker.d.ts +3 -0
  84. package/cli/dist/commands/tracker.js +18 -0
  85. package/cli/dist/commands/usage-error.d.ts +4 -0
  86. package/cli/dist/commands/usage-error.js +6 -0
  87. package/cli/dist/commands/work-target.d.ts +12 -3
  88. package/cli/dist/commands/work-target.js +46 -5
  89. package/cli/dist/commands/worktree.js +32 -28
  90. package/cli/dist/domain/batch-plan.d.ts +73 -0
  91. package/cli/dist/domain/batch-plan.js +114 -0
  92. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  93. package/cli/dist/domain/blocked-by-change.js +101 -0
  94. package/cli/dist/domain/board-move.d.ts +90 -0
  95. package/cli/dist/domain/board-move.js +92 -0
  96. package/cli/dist/domain/branch-name.js +1 -1
  97. package/cli/dist/domain/command-hint.d.ts +85 -0
  98. package/cli/dist/domain/command-hint.js +148 -0
  99. package/cli/dist/domain/config.d.ts +4 -0
  100. package/cli/dist/domain/config.js +11 -1
  101. package/cli/dist/domain/dependabot.js +1 -1
  102. package/cli/dist/domain/errors.d.ts +5 -0
  103. package/cli/dist/domain/errors.js +5 -0
  104. package/cli/dist/domain/format.d.ts +51 -4
  105. package/cli/dist/domain/format.js +72 -6
  106. package/cli/dist/domain/frontmatter.d.ts +18 -3
  107. package/cli/dist/domain/frontmatter.js +38 -12
  108. package/cli/dist/domain/issue-order.d.ts +55 -0
  109. package/cli/dist/domain/issue-order.js +65 -0
  110. package/cli/dist/domain/issue-readout.d.ts +36 -0
  111. package/cli/dist/domain/pull-request.d.ts +71 -4
  112. package/cli/dist/domain/pull-request.js +59 -10
  113. package/cli/dist/domain/readiness.d.ts +27 -0
  114. package/cli/dist/domain/readiness.js +114 -3
  115. package/cli/dist/domain/reference-parser.d.ts +3 -1
  116. package/cli/dist/domain/reference-parser.js +6 -2
  117. package/cli/dist/domain/release.d.ts +7 -3
  118. package/cli/dist/domain/release.js +5 -12
  119. package/cli/dist/domain/repository-policy.d.ts +9 -3
  120. package/cli/dist/domain/repository-policy.js +8 -7
  121. package/cli/dist/domain/repository-resolver.js +4 -1
  122. package/cli/dist/domain/security-alerts.js +1 -1
  123. package/cli/dist/domain/state.d.ts +30 -0
  124. package/cli/dist/domain/state.js +39 -0
  125. package/cli/dist/domain/work-start.d.ts +34 -0
  126. package/cli/dist/domain/work-start.js +49 -0
  127. package/cli/dist/infra/authored-notes.d.ts +1 -1
  128. package/cli/dist/infra/authored-notes.js +10 -4
  129. package/cli/dist/infra/config-store.d.ts +4 -0
  130. package/cli/dist/infra/config-store.js +13 -0
  131. package/cli/dist/infra/git.d.ts +12 -0
  132. package/cli/dist/infra/git.js +13 -1
  133. package/cli/dist/infra/github/client.d.ts +5 -0
  134. package/cli/dist/infra/github/client.js +10 -7
  135. package/cli/dist/infra/github/errors.d.ts +18 -0
  136. package/cli/dist/infra/github/errors.js +22 -0
  137. package/cli/dist/infra/github/issues.d.ts +39 -3
  138. package/cli/dist/infra/github/issues.js +178 -23
  139. package/cli/dist/infra/github/projects.d.ts +35 -0
  140. package/cli/dist/infra/github/projects.js +89 -8
  141. package/cli/dist/infra/github/pulls.d.ts +24 -0
  142. package/cli/dist/infra/github/pulls.js +56 -0
  143. package/cli/dist/infra/github/queries.d.ts +12 -4
  144. package/cli/dist/infra/github/queries.js +156 -8
  145. package/cli/dist/infra/github/readout.d.ts +5 -1
  146. package/cli/dist/infra/github/readout.js +11 -0
  147. package/cli/dist/infra/github/repos.d.ts +18 -0
  148. package/cli/dist/infra/github/repos.js +31 -0
  149. package/cli/dist/infra/nx-scope.d.ts +1 -1
  150. package/cli/dist/infra/nx-scope.js +1 -1
  151. package/cli/dist/infra/state-store.d.ts +10 -1
  152. package/cli/dist/infra/state-store.js +14 -2
  153. package/cli/dist/infra/worktree-links.d.ts +3 -0
  154. package/cli/dist/infra/worktree-links.js +8 -1
  155. package/cli/dist/infra/worktree.d.ts +12 -1
  156. package/cli/dist/infra/worktree.js +40 -23
  157. package/cli/dist/mcp/result.d.ts +34 -6
  158. package/cli/dist/mcp/result.js +62 -18
  159. package/cli/dist/mcp/server.d.ts +2 -2
  160. package/cli/dist/mcp/server.js +24 -10
  161. package/cli/templates/comment/plan.md +14 -0
  162. package/cli/templates/issue/bug.md +1 -1
  163. package/cli/templates/issue/task-implement.md +13 -6
  164. package/cli/templates/issue/task.md +1 -1
  165. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  166. package/npm-shrinkwrap.json +2 -2
  167. package/package.json +1 -1
  168. package/cli/dist/commands/dependabot.d.ts +0 -3
  169. package/cli/dist/commands/issue-project.d.ts +0 -3
  170. package/cli/dist/commands/issue-project.js +0 -176
  171. package/cli/dist/commands/issue-quick.d.ts +0 -3
  172. package/cli/dist/commands/issue-quick.js +0 -126
  173. package/cli/dist/commands/issue-read.d.ts +0 -3
  174. package/cli/dist/commands/issue-read.js +0 -80
  175. package/cli/dist/commands/repository.d.ts +0 -5
  176. package/cli/dist/commands/security.d.ts +0 -3
@@ -0,0 +1,169 @@
1
+ // issue show。cli/commands/issue.py の issue_read の移植。
2
+ import { z } from 'zod';
3
+ import { JSON_NULL } from '../domain/json-null.js';
4
+ import { describePrerequisiteState, describeReadiness, describeUnknown, displayReference, TRACKER_TITLE_PREFIX } from '../domain/readiness.js';
5
+ import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
6
+ import { createRepositoryReference, repositoryFullName } from '../domain/repository-resolver.js';
7
+ import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
8
+ import { defineCommand } from './command-definition.js';
9
+ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
10
+ import { kindOfFailure } from './failure.js';
11
+ import { createGitHubClient } from './github-client.js';
12
+ import { ISSUE_REF_DESCRIPTION, issuePath, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
13
+ import { blockedByReadCount, createReadinessCache, judgeSnapshot, readIssueReadiness, readinessJson, snapshotWithoutPrerequisites } from './issue-readiness.js';
14
+ import { createOutput } from './output.js';
15
+ const MAX_COMMENT_LIMIT = 20;
16
+ const DEFAULT_COMMENT_LIMIT = 5;
17
+ function parentLine(issue, owner, repository) {
18
+ const { parent } = issue;
19
+ if (parent === null)
20
+ return undefined;
21
+ const isCrossRepository = parent.owner !== null && parent.repo !== null && (parent.owner !== owner || parent.repo !== repository);
22
+ const label = isCrossRepository ? `${parent.owner}/${parent.repo}#${String(parent.number)}` : `#${String(parent.number)}`;
23
+ return `**Parent:** ${label} ${parent.title} (${parent.state})`;
24
+ }
25
+ /**
26
+ Issue の情報を Markdown にする。owner・repo は、親が別のリポジトリかを調べる元
27
+ */
28
+ function formatIssueMarkdown(issue, owner, repository, readiness) {
29
+ const lines = [`## #${String(issue.number)} ${issue.title}`, ''];
30
+ const meta = [`**State:** ${issue.state}`];
31
+ if (issue.comments.total_count > 0)
32
+ meta.push(`**Comments:** ${String(issue.comments.total_count)}`);
33
+ lines.push(meta.join(' | '), '');
34
+ const parent = parentLine(issue, owner, repository);
35
+ const header = [...parent === undefined ? [] : [parent], ...readiness?.lines ?? []];
36
+ if (header.length > 0)
37
+ lines.push(...header, '');
38
+ if (issue.linked_branches.length > 0) {
39
+ lines.push('**Branches:**', ...issue.linked_branches.map(branch => ` - \`${branch}\``), '');
40
+ }
41
+ if (issue.linked_prs.length > 0) {
42
+ lines.push('**Linked PRs:**', ...issue.linked_prs.map(pr => ` - #${String(pr.number)} ${pr.title} (${pr.state})`), '');
43
+ }
44
+ if (issue.sub_issues.length > 0) {
45
+ lines.push('**Sub-issues:**', ...issue.sub_issues.map(sub => ` - #${String(sub.number)} ${sub.title} (${sub.state})`), '');
46
+ }
47
+ lines.push('---', '', issue.body);
48
+ const comments = issue.comments.nodes;
49
+ if (comments.length > 0) {
50
+ lines.push('', '', `### Comments (${String(comments.length)}/${String(issue.comments.total_count)})`, '');
51
+ for (const comment of comments) {
52
+ lines.push('---', '', `**@${comment.author}** - ${comment.created_at.slice(0, 10)}`, '', comment.body, '');
53
+ }
54
+ }
55
+ return lines.join('\n');
56
+ }
57
+ // 前提と判定を読めなかったとき
58
+ const UNREAD = { lines: [], blockedBy: JSON_NULL, readiness: JSON_NULL };
59
+ /**
60
+ 前提の行と JSON。Readiness の行は text が渡されたときだけ足す(Epic と Tracker は判定が無い)
61
+ */
62
+ function readinessView(source, readiness, text) {
63
+ const home = source.ref.repository;
64
+ const entries = source.prerequisites.map((prerequisite) => {
65
+ const { issue, wait, reason } = prerequisite;
66
+ return {
67
+ label: displayReference(issue.ref, home),
68
+ title: source.titles.get(issueReferenceKey(issue.ref)) ?? '',
69
+ state: issue.state === 'open' ? 'OPEN' : 'CLOSED',
70
+ status: describePrerequisiteState(prerequisite),
71
+ wait,
72
+ reason,
73
+ ref: issue.ref,
74
+ };
75
+ });
76
+ const lines = entries.length === 0
77
+ ? []
78
+ : [`**Blocked by:** ${entries.map(entry => `${entry.label} ${entry.title} (${entry.state}, ${entry.status})`).join(', ')}`, ...text === undefined ? [] : [`**Readiness:** ${text}`]];
79
+ return {
80
+ lines,
81
+ blockedBy: entries.map(entry => ({ number: entry.ref.number, repository: repositoryFullName(entry.ref.repository), state: entry.state, wait: entry.wait, reason: entry.reason ?? JSON_NULL })),
82
+ readiness: readiness === undefined || text === undefined ? JSON_NULL : readinessJson(readiness, text),
83
+ };
84
+ }
85
+ function judgedView(judged) {
86
+ const { readiness } = judged;
87
+ return readinessView(judged, readiness, readiness === undefined ? undefined : describeReadiness(readiness, judged.prerequisites, judged.ref.repository));
88
+ }
89
+ function warnAboutSections(out, source) {
90
+ const home = source.ref.repository;
91
+ const self = displayReference(source.ref, home);
92
+ for (const mismatch of source.mismatches) {
93
+ out.warning(`Waits for merge of ${self} lists ${displayReference(mismatch.ref, home)}, which is not a blocked-by of it`);
94
+ }
95
+ if (source.malformedReason !== undefined)
96
+ out.warning(`Waits for merge of ${self} is malformed: ${source.malformedReason}`);
97
+ }
98
+ // 前提が無いと分かっている Issue の判定。API は呼ばない。Epic と Tracker は判定を出さない
99
+ async function readWithoutPrerequisites(client, config, issue, reference) {
100
+ const isGrouping = issue.sub_issues.length > 0 || issue.title.startsWith(TRACKER_TITLE_PREFIX);
101
+ const target = { ref: reference, state: issue.state.toLowerCase() === 'open' ? 'open' : 'closed', column: undefined, label: undefined, kind: isGrouping ? 'epic' : 'task', branches: issue.linked_branches, pullRequests: [] };
102
+ const result = await judgeSnapshot(client, snapshotWithoutPrerequisites(config, { title: issue.title, target, parent: undefined }), createReadinessCache());
103
+ if (result.kind === 'unreadable')
104
+ throw new Error('unreachable: a snapshot without prerequisites is always judged');
105
+ return result;
106
+ }
107
+ // 判定が読めなくても、今までの出力は止めない
108
+ async function readView(out, client, config, issue, reference) {
109
+ const label = displayReference(reference, reference.repository);
110
+ try {
111
+ const result = issue.blockedByCount === 0
112
+ ? await readWithoutPrerequisites(client, config, issue, reference)
113
+ : await readIssueReadiness(client, config, reference, createReadinessCache(), undefined, blockedByReadCount(issue.blockedByCount));
114
+ if (result.kind === 'unreadable') {
115
+ const { snapshot } = result;
116
+ if (snapshot === undefined) {
117
+ out.warning(`could not read blocked-by of ${label}: ${result.reason}`);
118
+ return UNREAD;
119
+ }
120
+ out.warning(`could not judge readiness of ${label}: ${result.reason}`);
121
+ warnAboutSections(out, snapshot);
122
+ return readinessView(snapshot, undefined, describeUnknown(result.reason));
123
+ }
124
+ warnAboutSections(out, result);
125
+ return judgedView(result);
126
+ }
127
+ catch (error) {
128
+ if (!(error instanceof DependenciesUnsupportedError))
129
+ throw error;
130
+ out.warning(`could not read blocked-by of ${label}: ${error.message}`);
131
+ return UNREAD;
132
+ }
133
+ }
134
+ const ISSUE_SHOW = defineCommand({
135
+ path: ['issue', 'show'],
136
+ description: 'Fetch Issue details efficiently (GraphQL, only the needed fields)',
137
+ input: z.object({
138
+ issue_ref: z.string().describe(ISSUE_REF_DESCRIPTION),
139
+ json: z.boolean().default(false).describe('Output as JSON'),
140
+ comment_limit: z.int().min(0).max(MAX_COMMENT_LIMIT).default(DEFAULT_COMMENT_LIMIT).describe('Number of comments to show (0-20; 0 hides them)'),
141
+ }),
142
+ positional: ['issue_ref'],
143
+ shortFlags: { json: '-j', comment_limit: '-c' },
144
+ interactive: false,
145
+ run: async (input, io) => {
146
+ const output = createOutput(false, io);
147
+ return await runWithExit(async () => {
148
+ const config = requireActiveConfigPlain(output);
149
+ const { owner, repository, number } = parseIssueReferenceOrExit(output, input.repo, input.issue_ref);
150
+ let issue;
151
+ const client = createGitHubClient(output, config.host);
152
+ try {
153
+ issue = await client.getIssueSlim(owner, repository, number, input.comment_limit);
154
+ }
155
+ catch (error) {
156
+ if (!(error instanceof GitHubAPIError))
157
+ throw error;
158
+ return stopWith(output, `could not read Issue ${issuePath(owner, repository, number)}: ${error.message}`, kindOfFailure(error));
159
+ }
160
+ const jsonFields = { ...issue, blockedByCount: undefined };
161
+ const view = await readView(output, client, config, issue, createIssueReference(createRepositoryReference(owner, repository), number));
162
+ output.data(input.json
163
+ ? JSON.stringify({ ...jsonFields, owner, repo: repository, blockedBy: view.blockedBy, readiness: view.readiness }, undefined, 2)
164
+ : formatIssueMarkdown(issue, owner, repository, view));
165
+ });
166
+ },
167
+ });
168
+ export const ISSUE_SHOW_COMMANDS = [ISSUE_SHOW];
169
+ //# sourceMappingURL=issue-show.js.map
@@ -1,4 +1,3 @@
1
1
  import type { CommandDefinition } from './command-definition.js';
2
- export declare const ISSUE_BOARD_COMMANDS: readonly CommandDefinition[];
3
2
  export declare const ISSUE_COMMANDS: readonly CommandDefinition[];
4
3
  //# sourceMappingURL=issue.d.ts.map
@@ -1,15 +1,13 @@
1
1
  import { ISSUE_COMMENT_COMMANDS } from './issue-comment.js';
2
2
  import { ISSUE_CREATE_COMMANDS } from './issue-create.js';
3
- import { ISSUE_QUICK_COMMANDS } from './issue-quick.js';
4
- import { ISSUE_PROJECT_COMMANDS } from './issue-project.js';
5
- import { ISSUE_READ_COMMANDS } from './issue-read.js';
6
- // 並びは Python の登録順(help の一覧に出る順)にそろえる
7
- export const ISSUE_BOARD_COMMANDS = ISSUE_PROJECT_COMMANDS.filter(command => command.path.length === 1);
3
+ import { ISSUE_DEPENDENCY_COMMANDS } from './issue-dependency.js';
4
+ import { ISSUE_REOPEN_COMMANDS } from './issue-reopen.js';
5
+ import { ISSUE_SHOW_COMMANDS } from './issue-show.js';
8
6
  export const ISSUE_COMMANDS = [
9
7
  ...ISSUE_CREATE_COMMANDS,
10
- ...ISSUE_QUICK_COMMANDS,
11
- ...ISSUE_READ_COMMANDS,
8
+ ...ISSUE_SHOW_COMMANDS,
12
9
  ...ISSUE_COMMENT_COMMANDS,
13
- ...ISSUE_PROJECT_COMMANDS.filter(command => command.path.length !== 1),
10
+ ...ISSUE_DEPENDENCY_COMMANDS,
11
+ ...ISSUE_REOPEN_COMMANDS,
14
12
  ];
15
13
  //# sourceMappingURL=issue.js.map
@@ -6,4 +6,37 @@ export declare function flagOf(name: string): string;
6
6
  文字列を名前の順(コードユニットの順)に並べる比較関数
7
7
  */
8
8
  export declare function byName(left: string, right: string): number;
9
+ /**
10
+ コマンド名の語と、その意味
11
+ */
12
+ export interface CommandWord {
13
+ readonly name: string;
14
+ readonly meaning: string;
15
+ readonly readOnly?: true;
16
+ }
17
+ /**
18
+ グループの語。help は、グループの一覧と `pecot <グループ> --help` に help の文を出す
19
+ */
20
+ export interface CommandGroup extends CommandWord {
21
+ readonly help: string;
22
+ }
23
+ /**
24
+ コマンド名の 1 語目に使うグループ。利用者が操作する対象で、help の一覧はこの順に並ぶ
25
+ */
26
+ export declare const COMMAND_GROUPS: readonly CommandGroup[];
27
+ /**
28
+ コマンド名の 2 語目に使う動詞の語彙。1 語に 1 つの意味を決める
29
+ */
30
+ export declare const COMMAND_VERBS: readonly CommandWord[];
31
+ /**
32
+ コマンド名の決まりに合わない path と、その理由
33
+ */
34
+ export interface CommandNameViolation {
35
+ readonly path: string;
36
+ readonly reason: string;
37
+ }
38
+ /**
39
+ コマンド名の決まり(`<グループ> <動詞>` の 2 語で、1 語目が COMMAND_GROUPS、2 語目が COMMAND_VERBS にある)に合わない path を、渡された順で返す。全部が合えば空
40
+ */
41
+ export declare function commandNameViolations(paths: readonly (readonly string[])[]): readonly CommandNameViolation[];
9
42
  //# sourceMappingURL=names.d.ts.map
@@ -13,4 +13,66 @@ export function byName(left, right) {
13
13
  return -1;
14
14
  return left > right ? 1 : 0;
15
15
  }
16
+ /**
17
+ コマンド名の 1 語目に使うグループ。利用者が操作する対象で、help の一覧はこの順に並ぶ
18
+ */
19
+ export const COMMAND_GROUPS = [
20
+ { name: 'project', meaning: 'プロジェクトとの接続と設定ファイル。ボードの上の Issue には触らない', help: 'Connect to projects and manage the project config' },
21
+ { name: 'board', meaning: 'ボードの上の Issue の置き場所。設定ファイルは書かない', help: 'Show the project board and place Issues on it' },
22
+ { name: 'issue', meaning: 'Issue そのもの', help: 'Work with Issues' },
23
+ { name: 'session', meaning: '1 つの Issue の作業の始まりから終わりまで', help: 'Start, show, restore and finish the work on an Issue' },
24
+ { name: 'pr', meaning: 'PR そのもの', help: 'Work with PRs' },
25
+ { name: 'release', meaning: 'リリース', help: 'Work with releases' },
26
+ { name: 'tracker', meaning: 'Tracker の Issue の書き直し', help: 'Rewrite the list in a Tracker Issue' },
27
+ { name: 'worktree', meaning: 'worktree', help: 'Work with worktrees' },
28
+ { name: 'branch', meaning: 'リモートのブランチ', help: 'Work with remote branches' },
29
+ ];
30
+ /**
31
+ コマンド名の 2 語目に使う動詞の語彙。1 語に 1 つの意味を決める
32
+ */
33
+ export const COMMAND_VERBS = [
34
+ { name: 'list', meaning: '複数を並べる', readOnly: true },
35
+ { name: 'search', meaning: 'GitHub を探す', readOnly: true },
36
+ { name: 'show', meaning: '1 件を出す', readOnly: true },
37
+ { name: 'get', meaning: '設定の値を出す', readOnly: true },
38
+ { name: 'check', meaning: '次の操作の前に確かめる', readOnly: true },
39
+ { name: 'create', meaning: 'GitHub のものを作る' },
40
+ { name: 'delete', meaning: 'GitHub のものを消す' },
41
+ { name: 'add', meaning: '集まりに入れる' },
42
+ { name: 'remove', meaning: '集まりから出す' },
43
+ { name: 'init', meaning: '既にあるものを pecot で使える状態にする' },
44
+ { name: 'set', meaning: '設定のキーに値を入れる' },
45
+ { name: 'unset', meaning: '設定のキーの値を消す' },
46
+ { name: 'link', meaning: 'リポジトリをプロジェクトにつなぐ' },
47
+ { name: 'activate', meaning: '使うプロジェクトを切り替える' },
48
+ { name: 'start', meaning: '作業を始める' },
49
+ { name: 'restore', meaning: '作業の状態を戻す' },
50
+ { name: 'finish', meaning: '作業を終えて片付ける' },
51
+ { name: 'sync', meaning: '判定や一覧に合わせて書き直す' },
52
+ { name: 'move', meaning: 'ボードの列を移す' },
53
+ { name: 'merge', meaning: 'PR をマージする' },
54
+ { name: 'comment', meaning: 'コメントを書く' },
55
+ { name: 'reopen', meaning: '閉じたものを開き直す' },
56
+ { name: 'block', meaning: '前提を付ける' },
57
+ { name: 'unblock', meaning: '前提を外す' },
58
+ ];
59
+ const COMMAND_WORD_COUNT = 2;
60
+ function isListed(words, word) {
61
+ return word === undefined || words.some(listed => listed.name === word);
62
+ }
63
+ /**
64
+ コマンド名の決まり(`<グループ> <動詞>` の 2 語で、1 語目が COMMAND_GROUPS、2 語目が COMMAND_VERBS にある)に合わない path を、渡された順で返す。全部が合えば空
65
+ */
66
+ export function commandNameViolations(paths) {
67
+ return paths
68
+ .map(path => ({
69
+ path: path.join(' '),
70
+ reason: [
71
+ ...path.length === COMMAND_WORD_COUNT ? [] : [`has ${String(path.length)} word(s); a command name is '<group> <verb>' (2 words)`],
72
+ ...isListed(COMMAND_GROUPS, path.at(0)) ? [] : [`'${String(path.at(0))}' is not a group in COMMAND_GROUPS`],
73
+ ...isListed(COMMAND_VERBS, path.at(1)) ? [] : [`'${String(path.at(1))}' is not a verb in COMMAND_VERBS`],
74
+ ].join('; '),
75
+ }))
76
+ .filter(violation => violation.reason !== '');
77
+ }
16
78
  //# sourceMappingURL=names.js.map
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import type { HintedText } from '../domain/command-hint.js';
2
3
  import type { CommandIo } from './registry.js';
3
4
  /**
4
5
  操作の動詞。自由な文字列を受け取らない
@@ -19,11 +20,19 @@ export declare const VerbSchema: z.ZodEnum<{
19
20
  }>;
20
21
  export type Verb = z.infer<typeof VerbSchema>;
21
22
  /**
23
+ 動詞の過去分詞。done の前置きになる
24
+ */
25
+ export declare function pastOf(verb: Verb): string;
26
+ /**
22
27
  plan と result の元になる操作
23
28
  */
24
29
  export interface Operation {
25
30
  readonly verb: Verb;
26
31
  readonly target: string;
32
+ /**
33
+ 本題でない片付けの操作。行は同じに出し、MCP の結果の message には選ばない
34
+ */
35
+ readonly aside?: boolean;
27
36
  }
28
37
  export interface Output {
29
38
  /**
@@ -34,8 +43,11 @@ export interface Output {
34
43
  dry-run でないときだけ、実行した操作を stderr に出す
35
44
  */
36
45
  readonly done: (operation: Operation) => void;
37
- readonly warning: (message: string) => void;
38
- readonly error: (message: string) => void;
46
+ /**
47
+ 案内(HintedText)は io の出し先の形にする
48
+ */
49
+ readonly warning: (message: string | HintedText) => void;
50
+ readonly error: (message: string | HintedText) => void;
39
51
  /**
40
52
  value が未設定なら `unknown` と出す
41
53
  */
@@ -5,6 +5,7 @@
5
5
  // 期待の行は tests/output/cases.json に置き、Python の側と同じ値を共有する。
6
6
  import { readSync } from 'node:fs';
7
7
  import { z } from 'zod';
8
+ import { formatHinted } from '../domain/command-hint.js';
8
9
  import { hasErrorCode } from '../infra/os-error.js';
9
10
  /**
10
11
  操作の動詞。自由な文字列を受け取らない
@@ -13,7 +14,7 @@ export const VerbSchema = z.enum(['create', 'update', 'delete', 'add', 'remove',
13
14
  /**
14
15
  動詞の過去分詞。done の前置きになる
15
16
  */
16
- function pastOf(verb) {
17
+ export function pastOf(verb) {
17
18
  switch (verb) {
18
19
  case 'create': {
19
20
  return 'created';
@@ -61,23 +62,29 @@ function formatMessage(prefix, message) {
61
62
  return `${prefix}: ${lines.join('\n ')}\n`;
62
63
  }
63
64
  export function createOutput(isDryRun, io) {
65
+ const render = (message) => formatHinted(message, io.surface ?? 'cli');
66
+ const writeResult = (line, aside) => {
67
+ io.stderr(`${line}\n`);
68
+ if (aside !== true)
69
+ io.resultLine?.(line);
70
+ };
64
71
  return {
65
- planned: ({ verb, target }) => {
72
+ planned: ({ verb, target, aside }) => {
66
73
  if (!isDryRun)
67
74
  return;
68
75
  // unchanged に現在形は無いので、文を変える
69
- io.stderr(verb === 'unchanged' ? `dry-run: would leave ${target} unchanged\n` : `dry-run: would ${verb} ${target}\n`);
76
+ writeResult(verb === 'unchanged' ? `dry-run: would leave ${target} unchanged` : `dry-run: would ${verb} ${target}`, aside);
70
77
  },
71
- done: ({ verb, target }) => {
78
+ done: ({ verb, target, aside }) => {
72
79
  if (isDryRun)
73
80
  return;
74
- io.stderr(`${pastOf(verb)}: ${target}\n`);
81
+ writeResult(`${pastOf(verb)}: ${target}`, aside);
75
82
  },
76
83
  warning: (message) => {
77
- io.stderr(formatMessage('warning', message));
84
+ io.stderr(formatMessage('warning', render(message)));
78
85
  },
79
86
  error: (message) => {
80
- io.stderr(formatMessage('error', message));
87
+ io.stderr(formatMessage('error', render(message)));
81
88
  },
82
89
  count: (label, value) => {
83
90
  io.stderr(`count: ${label}: ${value === undefined ? 'unknown' : String(value)}\n`);
@@ -0,0 +1,20 @@
1
+ import type { ProjectConfig } from '../domain/config.js';
2
+ import type { RepositoryReference } from '../domain/repository-resolver.js';
3
+ import type { GitHubClient } from '../infra/github/index.js';
4
+ import type { Output } from './output.js';
5
+ export interface CreatedPullRequest {
6
+ readonly repository: RepositoryReference;
7
+ /**
8
+ head ブランチの末尾の番号の Issue
9
+ */
10
+ readonly issueNumber: number;
11
+ /**
12
+ 作った PR の番号。応答に無ければ undefined(読み直しの確かめを省く)
13
+ */
14
+ readonly pullRequest: number | undefined;
15
+ }
16
+ /**
17
+ head の Issue を待つ Issue を読み、判定に合わせてボードの列と札を動かす。読むのは、待つ Issue のボードの項目だけ
18
+ */
19
+ export declare function moveWaitingIssues(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, created: CreatedPullRequest): Promise<void>;
20
+ //# sourceMappingURL=pr-waiting.d.ts.map
@@ -0,0 +1,106 @@
1
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
2
+ // pr create の後に、head の Issue を待つ Issue(blocking)の列と札を、判定で動かす。
3
+ // どの失敗も warning にとどめ、終了コードを変えない。
4
+ import { setTimeout as delay } from 'node:timers/promises';
5
+ import { homeRepositoryOf, workflowFieldName } from '../domain/config.js';
6
+ import { boardItemKey } from '../domain/format.js';
7
+ import { displayReference } from '../domain/readiness.js';
8
+ import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
9
+ import { DependenciesUnsupportedError, GitHubNotFoundError } from '../infra/github/errors.js';
10
+ import { applyJudgedMoves, judgeBoard, SYNCED_COLUMNS } from './board-judgment.js';
11
+ import { mapWithLimit } from './board-view.js';
12
+ import { commandHint, hinted } from './command-hint.js';
13
+ import { apiFailureMessage } from './github-client.js';
14
+ // GitHub は書いた直後の読み取りの一致を保証しない。読み直す前に、反映を待つ時間
15
+ const RECHECK_DELAY_MILLISECONDS = 1500;
16
+ const READ_MAX_WORKERS = 8;
17
+ // 判定の前提の中の head の Issue に、作った PR が出ているか
18
+ function hasCreatedPullRequest(judged, waiting) {
19
+ const { created, head } = waiting;
20
+ if (created.pullRequest === undefined || judged.result.kind !== 'judged')
21
+ return true;
22
+ const headKey = issueReferenceKey(head);
23
+ const prerequisite = judged.result.prerequisites.find(({ issue }) => issueReferenceKey(issue.ref) === headKey);
24
+ return prerequisite?.issue.pullRequests.some(pullRequest => pullRequest.number === created.pullRequest) ?? false;
25
+ }
26
+ async function judgeKeys(waiting, items, keys) {
27
+ const { client, config } = waiting.context;
28
+ return await judgeBoard(client, config, items, new Map(), { columns: SYNCED_COLUMNS, withoutRead: target => (keys.has(target.key) ? undefined : 'skip') });
29
+ }
30
+ // 作った PR が判定に出ていない分を、少し待ってから 1 回だけ読み直す
31
+ async function judgeConfirmed(waiting, items) {
32
+ const first = await judgeKeys(waiting, items, new Set(items.flatMap(item => boardItemKey(item) ?? [])));
33
+ if (first === undefined)
34
+ return undefined;
35
+ const stale = new Set(first.filter(judged => !hasCreatedPullRequest(judged, waiting)).map(judged => judged.target.key));
36
+ if (stale.size > 0)
37
+ await delay(RECHECK_DELAY_MILLISECONDS);
38
+ const second = stale.size === 0 ? [] : await judgeKeys(waiting, items, stale);
39
+ if (second === undefined)
40
+ return undefined;
41
+ const latest = [...first.filter(judged => !stale.has(judged.target.key)), ...second];
42
+ return { confirmed: latest.filter(judged => hasCreatedPullRequest(judged, waiting)), unconfirmed: latest.filter(judged => !hasCreatedPullRequest(judged, waiting)) };
43
+ }
44
+ // head の Issue が PR のリポに無いとき(集約リポの運用・番号が Issue でないブランチ)と、依存関係に対応しない GHES では、何も出さない
45
+ async function readWaitingIssues(waiting) {
46
+ const { context: { out, client, home }, created, head } = waiting;
47
+ const name = displayReference(head, home);
48
+ const failed = `could not read the Issues waiting for ${name}`;
49
+ let read;
50
+ try {
51
+ read = await client.getIssueBlockingReferences(created.repository.owner, created.repository.repository, created.issueNumber);
52
+ }
53
+ catch (error) {
54
+ if (error instanceof DependenciesUnsupportedError || error instanceof GitHubNotFoundError)
55
+ return undefined;
56
+ out.warning(`${failed}: ${apiFailureMessage(error)}`);
57
+ return undefined;
58
+ }
59
+ if (read.kind === 'read-failed') {
60
+ out.warning(`${failed}: ${read.reason}`);
61
+ return undefined;
62
+ }
63
+ const partial = read.total > read.issues.length ? `read ${String(read.issues.length)} of ${String(read.total)} Issues waiting for ${name}; the rest were not moved` : undefined;
64
+ return { issues: read.issues, partial };
65
+ }
66
+ // 待つ Issue のうち、開いていてボードに載っているものの項目だけを読む
67
+ async function readBoardItems(waiting, issues) {
68
+ const { client, config } = waiting.context;
69
+ const field = workflowFieldName(config);
70
+ const open = issues.filter(issue => issue.state === 'OPEN');
71
+ const items = await mapWithLimit(open, READ_MAX_WORKERS, async ({ repository, number }) => await client.getIssueBoardItem(config.project.id, repository.owner, repository.repository, number, field));
72
+ return items.flatMap(item => item ?? []);
73
+ }
74
+ async function moveWaiting(waiting, issues) {
75
+ const { context, created } = waiting;
76
+ const items = await readBoardItems(waiting, issues);
77
+ if (items.length === 0)
78
+ return;
79
+ const judged = await judgeConfirmed(waiting, items);
80
+ if (judged === undefined)
81
+ return;
82
+ await applyJudgedMoves(context, judged.confirmed);
83
+ for (const { target } of judged.unconfirmed) {
84
+ context.out.warning(hinted `could not confirm that GitHub reflects PR #${String(created.pullRequest)} in the readiness of ${displayReference(target.ref, context.home)}; its column was not moved; run ${commandHint(['board', 'sync'])} later to move it`);
85
+ }
86
+ }
87
+ /**
88
+ head の Issue を待つ Issue を読み、判定に合わせてボードの列と札を動かす。読むのは、待つ Issue のボードの項目だけ
89
+ */
90
+ export async function moveWaitingIssues(out, client, config, created) {
91
+ const context = { out, client, config, home: homeRepositoryOf(config) };
92
+ const waiting = { context, created, head: createIssueReference(created.repository, created.issueNumber) };
93
+ const read = await readWaitingIssues(waiting);
94
+ if (read === undefined)
95
+ return;
96
+ try {
97
+ if (read.issues.length > 0)
98
+ await moveWaiting(waiting, read.issues);
99
+ }
100
+ catch (error) {
101
+ out.warning(`could not move the Issues waiting for ${displayReference(waiting.head, context.home)}: ${apiFailureMessage(error)}`);
102
+ }
103
+ if (read.partial !== undefined)
104
+ out.warning(read.partial);
105
+ }
106
+ //# sourceMappingURL=pr-waiting.js.map
@@ -1,3 +1,22 @@
1
+ import type { RemoteLocation } from '../domain/git-url.js';
2
+ import type { Output } from './output.js';
1
3
  import type { CommandDefinition } from './command-definition.js';
4
+ export declare const PR_REFERENCE_DESCRIPTION = "PR reference (`owner/repo/N`, or the short form `N` in the repository of `--repo`, or else of the git remote of the current directory)";
5
+ export declare function reasonOf(error: unknown): string;
6
+ export declare function isPositive(value: number | undefined): value is number;
7
+ export interface PrimaryRemote {
8
+ readonly name: string;
9
+ readonly url: string;
10
+ /**
11
+ URL が読めなければ undefined
12
+ */
13
+ readonly location: RemoteLocation | undefined;
14
+ }
15
+ export declare function primaryRemote(directory: string): PrimaryRemote | undefined;
16
+ export declare function parseReference(reference: string, globalRepository: string | undefined, out: Readonly<Output>): {
17
+ readonly owner: string;
18
+ readonly repository: string;
19
+ readonly number: number;
20
+ };
2
21
  export declare const PR_COMMANDS: readonly CommandDefinition[];
3
22
  //# sourceMappingURL=pr.d.ts.map