@pecot/workflow-mcp 6.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +4 -57
- package/cli/dist/commands/board-add.js +11 -1
- package/cli/dist/commands/board-judgment.d.ts +12 -3
- package/cli/dist/commands/board-judgment.js +12 -6
- package/cli/dist/commands/board-move.js +9 -1
- package/cli/dist/commands/board-readiness.d.ts +3 -3
- package/cli/dist/commands/board-show.js +5 -2
- package/cli/dist/commands/board-sync.js +14 -5
- package/cli/dist/commands/board-view.d.ts +94 -5
- package/cli/dist/commands/board-view.js +119 -17
- package/cli/dist/commands/branch.js +12 -1
- package/cli/dist/commands/command-definition.d.ts +19 -2
- package/cli/dist/commands/command-definition.js +9 -0
- package/cli/dist/commands/failure-kind.d.ts +1 -1
- package/cli/dist/commands/failure-kind.js +1 -0
- package/cli/dist/commands/issue-board.d.ts +31 -3
- package/cli/dist/commands/issue-board.js +28 -4
- package/cli/dist/commands/issue-comment.js +19 -2
- package/cli/dist/commands/issue-create.js +90 -7
- package/cli/dist/commands/issue-dependency.js +32 -4
- package/cli/dist/commands/issue-readiness.d.ts +30 -2
- package/cli/dist/commands/issue-readiness.js +35 -0
- package/cli/dist/commands/issue-reopen.js +18 -3
- package/cli/dist/commands/issue-shared.d.ts +3 -3
- package/cli/dist/commands/issue-shared.js +3 -2
- package/cli/dist/commands/issue-show.js +78 -8
- package/cli/dist/commands/names.js +1 -0
- package/cli/dist/commands/output.d.ts +18 -2
- package/cli/dist/commands/output.js +16 -3
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +230 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +233 -0
- package/cli/dist/commands/pr-waiting.d.ts +41 -2
- package/cli/dist/commands/pr-waiting.js +74 -37
- package/cli/dist/commands/pr.d.ts +10 -6
- package/cli/dist/commands/pr.js +160 -67
- package/cli/dist/commands/project-sync.d.ts +10 -2
- package/cli/dist/commands/project-sync.js +7 -6
- package/cli/dist/commands/project.js +173 -16
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +67 -18
- package/cli/dist/commands/repository-match.js +7 -2
- package/cli/dist/commands/session-finish.js +128 -12
- package/cli/dist/commands/session-start.js +22 -6
- package/cli/dist/commands/session.js +121 -20
- package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
- package/cli/dist/commands/tracker-sync-security.js +22 -4
- package/cli/dist/commands/tracker-sync.d.ts +30 -0
- package/cli/dist/commands/tracker-sync.js +15 -0
- package/cli/dist/commands/tracker.js +2 -0
- package/cli/dist/commands/work-target.d.ts +10 -2
- package/cli/dist/commands/work-target.js +6 -4
- package/cli/dist/commands/worktree.js +71 -5
- package/cli/dist/domain/issue-readout.d.ts +0 -4
- package/cli/dist/domain/pull-request.d.ts +1 -1
- package/cli/dist/domain/readiness.d.ts +17 -0
- package/cli/dist/domain/readiness.js +39 -2
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/state.d.ts +39 -0
- package/cli/dist/domain/state.js +28 -1
- package/cli/dist/domain/work-start.d.ts +0 -4
- package/cli/dist/domain/work-start.js +0 -7
- package/cli/dist/infra/git.d.ts +64 -0
- package/cli/dist/infra/git.js +110 -0
- package/cli/dist/infra/github/pulls.d.ts +81 -2
- package/cli/dist/infra/github/pulls.js +116 -5
- package/cli/dist/infra/github/queries.d.ts +4 -1
- package/cli/dist/infra/github/queries.js +47 -32
- package/cli/dist/infra/github/readout.js +0 -33
- package/cli/dist/mcp/result.d.ts +63 -16
- package/cli/dist/mcp/result.js +106 -30
- package/cli/dist/mcp/server.js +37 -4
- package/cli/templates/comment/plan.md +2 -2
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// board show の表示と、Archived の整理、Dependabot alert の収集。
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { effectiveReleaseType, workflowFieldName } from '../domain/config.js';
|
|
3
4
|
import { DependabotAlertError, fetchDependabotAlertStatus } from '../domain/dependabot.js';
|
|
4
5
|
import { formatItemsJson, readBoardProgress, transformItems } from '../domain/format.js';
|
|
@@ -6,6 +7,7 @@ import { JSON_NULL } from '../domain/json-null.js';
|
|
|
6
7
|
import { compareStrings } from '../domain/python-format.js';
|
|
7
8
|
import { createDependabotSource } from '../infra/github/dependabot-source.js';
|
|
8
9
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
10
|
+
import { READINESS_JSON } from './issue-readiness.js';
|
|
9
11
|
import { STATUS_FIELD_NAME } from './project-sync.js';
|
|
10
12
|
/**
|
|
11
13
|
Archived のうち、ボードに残す件数
|
|
@@ -21,16 +23,16 @@ function updatedAtOf(item) {
|
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
Archived のアイテムを updatedAt の新しい順に並べ、最新の 20 件を残して、残りをボードから消す。
|
|
24
|
-
消せなかった件数を warning
|
|
26
|
+
消せなかった件数を warning の行に出す。消した件数(dry-run は消す予定の件数)と、消せなかった件数を返す
|
|
25
27
|
*/
|
|
26
28
|
export async function pruneArchivedItems(out, client, config, allItems, isDryRun) {
|
|
27
29
|
const archived = allItems.filter(item => item.workflow === 'Archived').toSorted((first, second) => compareStrings(updatedAtOf(second), updatedAtOf(first)));
|
|
28
30
|
if (archived.length <= ARCHIVED_KEEP)
|
|
29
|
-
return 0;
|
|
31
|
+
return { deleted: 0, failed: 0 };
|
|
30
32
|
const targets = archived.slice(ARCHIVED_KEEP);
|
|
31
33
|
if (isDryRun) {
|
|
32
34
|
out.planned({ verb: 'delete', target: `${String(targets.length)} archived items` });
|
|
33
|
-
return 0;
|
|
35
|
+
return { deleted: targets.length, failed: 0 };
|
|
34
36
|
}
|
|
35
37
|
let deleted = 0;
|
|
36
38
|
for (const item of targets) {
|
|
@@ -52,7 +54,7 @@ export async function pruneArchivedItems(out, client, config, allItems, isDryRun
|
|
|
52
54
|
const failed = targets.length - deleted;
|
|
53
55
|
if (failed > 0)
|
|
54
56
|
out.warning(`failed to delete ${String(failed)} archived items`);
|
|
55
|
-
return failed;
|
|
57
|
+
return { deleted, failed };
|
|
56
58
|
}
|
|
57
59
|
/**
|
|
58
60
|
登録リポジトリごとの Dependabot alert の状態(登録の順)。
|
|
@@ -95,6 +97,69 @@ function statusAt(statuses, index) {
|
|
|
95
97
|
throw new RangeError(`no Dependabot alert status for repository #${String(index)}`);
|
|
96
98
|
return status;
|
|
97
99
|
}
|
|
100
|
+
const ALERTS_JSON = z.union([
|
|
101
|
+
z.strictObject({
|
|
102
|
+
error: z.string().describe('Reason the Dependabot alerts could not be fetched'),
|
|
103
|
+
}),
|
|
104
|
+
z.strictObject({
|
|
105
|
+
enabled: z.boolean().describe('Whether Dependabot alerts are enabled'),
|
|
106
|
+
open_count: z.int().describe('Number of open alerts (0 when disabled)'),
|
|
107
|
+
max_severity: z.string().nullable().describe('Highest severity of the open alerts (null when there is none)'),
|
|
108
|
+
alerts_url: z.string().describe('URL of the alert list'),
|
|
109
|
+
}),
|
|
110
|
+
]);
|
|
111
|
+
// extend は同じ名前のキーを元の位置のまま置き換えるので、キーの並びは readinessJson と同じに保たれる
|
|
112
|
+
const BOARD_READINESS_JSON = READINESS_JSON.extend({
|
|
113
|
+
kind: z.enum(['startable', 'stackable', 'blocked', 'unknown']).describe('Readiness judgment (unknown when the prerequisites could not be read)'),
|
|
114
|
+
text: z.string().describe('Readiness as shown in the Readiness column'),
|
|
115
|
+
});
|
|
116
|
+
const BOARD_CONTENT_JSON = z.strictObject({
|
|
117
|
+
number: z.unknown().optional().describe('Issue or PR number'),
|
|
118
|
+
state: z.unknown().optional().describe('State of the Issue or PR (OPEN etc.)'),
|
|
119
|
+
url: z.unknown().optional().describe('URL of the Issue or PR'),
|
|
120
|
+
labels: z.array(z.string()).optional().describe('Label names'),
|
|
121
|
+
repository: z.string().optional().describe('Repository (owner/repo)'),
|
|
122
|
+
});
|
|
123
|
+
const BOARD_ITEM_JSON = z.strictObject({
|
|
124
|
+
id: z.unknown().optional().describe('Project item ID'),
|
|
125
|
+
workflow: z.string().nullable().optional().describe('Column (workflow field value) of the item'),
|
|
126
|
+
title: z.unknown().optional().describe('Title of the Issue or PR'),
|
|
127
|
+
updatedAt: z.unknown().optional().describe('Last update time of the item'),
|
|
128
|
+
content: BOARD_CONTENT_JSON.describe('Issue or PR on the card'),
|
|
129
|
+
readiness: BOARD_READINESS_JSON.nullable().optional().describe('Readiness of a Ready or Blocked Issue (null for other items; omitted when the server does not support issue dependencies)'),
|
|
130
|
+
});
|
|
131
|
+
const PACKAGE_JSON = z.strictObject({
|
|
132
|
+
name: z.string().describe('Package name'),
|
|
133
|
+
changelog: z.string().describe('Path of the CHANGELOG of the package'),
|
|
134
|
+
});
|
|
135
|
+
const REPOSITORY_JSON = z.strictObject({
|
|
136
|
+
full_name: z.string().describe('Repository (owner/repo)'),
|
|
137
|
+
owner: z.string().describe('Owner of the repository'),
|
|
138
|
+
name: z.string().describe('Name of the repository'),
|
|
139
|
+
develop_branch: z.string().nullable().describe('Develop branch (null when not set)'),
|
|
140
|
+
release_branch: z.string().nullable().describe('Release branch (null when not set)'),
|
|
141
|
+
dependabot_alerts: ALERTS_JSON.describe('Dependabot alert status, or the reason it could not be fetched'),
|
|
142
|
+
release_type: z.enum(['single', 'multi', 'nx']).describe('Release type in effect (data only; not in --json)'),
|
|
143
|
+
packages: z.array(PACKAGE_JSON).describe('Packages of a monorepo (data only; empty when none)'),
|
|
144
|
+
changelog_file: z.string().optional().describe('CHANGELOG path set for a repository without packages (data only; omitted when not set)'),
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
board show の MCP の data。project・repositories・board は --json と同じ。repositories の release_type・packages・changelog_file と mismatches は data にだけ足す
|
|
148
|
+
*/
|
|
149
|
+
export const BOARD_SHOW_OUTPUT = z.strictObject({
|
|
150
|
+
project: z.strictObject({
|
|
151
|
+
name: z.string().describe('Name of the project config'),
|
|
152
|
+
host: z.string().describe('GitHub host'),
|
|
153
|
+
owner: z.string().describe('Owner of the project'),
|
|
154
|
+
number: z.int().describe('Project number'),
|
|
155
|
+
aggregation_repo: z.string().nullable().describe('Roadmap (aggregation) repository (null when not set)'),
|
|
156
|
+
}).describe('Overview of the project'),
|
|
157
|
+
repositories: z.array(REPOSITORY_JSON).describe('Registered repositories, in registration order'),
|
|
158
|
+
board: z.strictObject({
|
|
159
|
+
items: z.array(BOARD_ITEM_JSON).describe('Open items in Backlog, Pending, Blocked, Ready, Active and In Review'),
|
|
160
|
+
}).describe('Board status'),
|
|
161
|
+
mismatches: z.int().describe('Number of Ready or Blocked Issues whose column or Status may not match the judgment (data only)'),
|
|
162
|
+
});
|
|
98
163
|
function alertsJson(status) {
|
|
99
164
|
return typeof status === 'string' ? { error: status } : { enabled: status.enabled, open_count: status.openCount, max_severity: status.maxSeverity ?? JSON_NULL, alerts_url: status.alertsUrl };
|
|
100
165
|
}
|
|
@@ -105,12 +170,26 @@ function alertsLine(status) {
|
|
|
105
170
|
return ' dependabot_alerts: disabled';
|
|
106
171
|
return ` dependabot_alerts: open ${String(status.openCount)}`;
|
|
107
172
|
}
|
|
173
|
+
function repositoryJson(entry, status) {
|
|
174
|
+
return {
|
|
175
|
+
full_name: `${entry.owner}/${entry.name}`,
|
|
176
|
+
owner: entry.owner,
|
|
177
|
+
name: entry.name,
|
|
178
|
+
develop_branch: entry.develop_branch ?? JSON_NULL,
|
|
179
|
+
release_branch: entry.release_branch ?? JSON_NULL,
|
|
180
|
+
dependabot_alerts: alertsJson(status),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function itemJson(item) {
|
|
184
|
+
const { labels } = item.content;
|
|
185
|
+
return { ...item, content: { ...item.content, labels: labels === undefined ? undefined : [...labels] } };
|
|
186
|
+
}
|
|
108
187
|
/**
|
|
109
|
-
|
|
188
|
+
--json の標準出力と MCP の data の中身。キーを並べた順が --json の出力の順になる
|
|
110
189
|
*/
|
|
111
|
-
export function
|
|
190
|
+
export function boardShowData(view, items, readiness) {
|
|
112
191
|
const { config, projectName, statuses } = view;
|
|
113
|
-
|
|
192
|
+
return {
|
|
114
193
|
project: {
|
|
115
194
|
name: projectName,
|
|
116
195
|
host: config.host,
|
|
@@ -118,17 +197,40 @@ export function boardShowJson(view, items, readiness) {
|
|
|
118
197
|
number: config.project.number,
|
|
119
198
|
aggregation_repo: config.aggregation_repo ?? JSON_NULL,
|
|
120
199
|
},
|
|
121
|
-
repositories: config.repositories.map((entry, index) => (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
200
|
+
repositories: config.repositories.map((entry, index) => repositoryJson(entry, statusAt(statuses, index))),
|
|
201
|
+
board: readiness === undefined
|
|
202
|
+
? { items: formatItemsJson(items).items.map(item => itemJson(item)) }
|
|
203
|
+
: { items: items.map((item) => {
|
|
204
|
+
const found = readiness(item);
|
|
205
|
+
return { ...itemJson(item), readiness: found };
|
|
206
|
+
}) },
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
info --json の出力
|
|
211
|
+
*/
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- zod の input の型は配列が可変
|
|
213
|
+
export function boardShowJson(data) {
|
|
214
|
+
return JSON.stringify(data, undefined, 2);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
MCP の data。--json の中身に、リポジトリごとの release_type・packages・changelog_file と、食い違いの件数を足す
|
|
218
|
+
*/
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- zod の input の型は配列が可変
|
|
220
|
+
export function boardShowResult(view, core, mismatches) {
|
|
221
|
+
const { config, statuses } = view;
|
|
222
|
+
return {
|
|
223
|
+
...core,
|
|
224
|
+
repositories: config.repositories.map((entry, index) => ({ ...repositoryJson(entry, statusAt(statuses, index)), ...repositoryExtras(entry) })),
|
|
225
|
+
mismatches,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function repositoryExtras(entry) {
|
|
229
|
+
return {
|
|
230
|
+
release_type: effectiveReleaseType(entry),
|
|
231
|
+
packages: (entry.packages ?? []).map(item => ({ name: item.name, changelog: item.changelog })),
|
|
232
|
+
...entry.changelog_file !== undefined && entry.changelog_file !== '' && { changelog_file: entry.changelog_file },
|
|
130
233
|
};
|
|
131
|
-
return JSON.stringify(output, undefined, 2);
|
|
132
234
|
}
|
|
133
235
|
function repositoryLines(view) {
|
|
134
236
|
const { config, statuses } = view;
|
|
@@ -9,9 +9,16 @@ import { defineCommand } from './command-definition.js';
|
|
|
9
9
|
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
10
10
|
import { kindOfFailure } from './failure.js';
|
|
11
11
|
import { createGitHubClient } from './github-client.js';
|
|
12
|
-
import { createOutput } from './output.js';
|
|
12
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
13
13
|
import { requireRepositoryMatch } from './repository-match.js';
|
|
14
14
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
15
|
+
const BRANCH_DELETE_OUTPUT = z.strictObject({
|
|
16
|
+
branch: z.string().describe('Name of the remote branch'),
|
|
17
|
+
repository: z.string().describe('Repository of the branch (owner/repo)'),
|
|
18
|
+
deleted: z.boolean().describe('Whether the remote branch was deleted (false on dry_run)'),
|
|
19
|
+
wipBranch: z.string().optional().describe('Name of the wip branch that was deleted along with it (omitted when there was none or it could not be deleted)'),
|
|
20
|
+
dryRun: DRY_RUN_FIELD,
|
|
21
|
+
});
|
|
15
22
|
const branchDeleteCommand = defineCommand({
|
|
16
23
|
path: ['branch', 'delete'],
|
|
17
24
|
hasOwnRepo: true,
|
|
@@ -22,6 +29,7 @@ const branchDeleteCommand = defineCommand({
|
|
|
22
29
|
branch: z.string().describe('Name of the branch to delete'),
|
|
23
30
|
dry_run: z.boolean().default(false).describe('Show what would be deleted without deleting anything'),
|
|
24
31
|
}),
|
|
32
|
+
output: BRANCH_DELETE_OUTPUT,
|
|
25
33
|
positional: ['repo', 'branch'],
|
|
26
34
|
shortFlags: { dry_run: '-n' },
|
|
27
35
|
interactive: false,
|
|
@@ -67,6 +75,7 @@ const branchDeleteCommand = defineCommand({
|
|
|
67
75
|
const operation = { verb: 'delete', target: `remote branch ${input.branch} in ${owner}/${repository}` };
|
|
68
76
|
if (input.dry_run) {
|
|
69
77
|
out.planned(operation);
|
|
78
|
+
out.result({ branch: input.branch, repository: `${owner}/${repository}`, deleted: false });
|
|
70
79
|
return 0;
|
|
71
80
|
}
|
|
72
81
|
// 6. 削除実行
|
|
@@ -79,6 +88,7 @@ const branchDeleteCommand = defineCommand({
|
|
|
79
88
|
return stopWith(out, `could not delete remote branch ${input.branch} in ${owner}/${repository}: ${error.message}`, kindOfFailure(error));
|
|
80
89
|
}
|
|
81
90
|
out.done(operation);
|
|
91
|
+
out.result({ branch: input.branch, repository: `${owner}/${repository}`, deleted: true });
|
|
82
92
|
// wip ブランチも連動削除
|
|
83
93
|
const wipBranch = `wip/${input.branch}`;
|
|
84
94
|
try {
|
|
@@ -93,6 +103,7 @@ const branchDeleteCommand = defineCommand({
|
|
|
93
103
|
return 0;
|
|
94
104
|
}
|
|
95
105
|
out.done({ verb: 'delete', target: `remote branch ${wipBranch} in ${owner}/${repository}` });
|
|
106
|
+
out.result({ wipBranch });
|
|
96
107
|
return 0;
|
|
97
108
|
},
|
|
98
109
|
});
|
|
@@ -23,6 +23,14 @@ export interface CommandIo {
|
|
|
23
23
|
結果の行(created: など。改行を含まない)を受け取る。片付けの行は渡さない。MCP だけが渡す
|
|
24
24
|
*/
|
|
25
25
|
readonly resultLine?: (line: string) => void;
|
|
26
|
+
/**
|
|
27
|
+
成功の data の項目を受け取る。何度も渡されたら浅く重ねる(後の値が勝つ)。MCP だけが渡す
|
|
28
|
+
*/
|
|
29
|
+
readonly data?: (fields: Readonly<Record<string, unknown>>) => void;
|
|
30
|
+
/**
|
|
31
|
+
warning の文(`warning: ` の前置きと字下げを除いたもの)を受け取る。MCP だけが渡す
|
|
32
|
+
*/
|
|
33
|
+
readonly warning?: (text: string) => void;
|
|
26
34
|
}
|
|
27
35
|
/**
|
|
28
36
|
コマンドの途中で、決めた終了コードで止めるための例外。defineCommand が包む run の 1 か所で捕まえて、戻り値の終了コードにする。
|
|
@@ -37,7 +45,7 @@ declare const GLOBAL_SCHEMA: z.ZodObject<{
|
|
|
37
45
|
repo: z.ZodOptional<z.ZodString>;
|
|
38
46
|
}, z.core.$strip>;
|
|
39
47
|
export type GlobalInput = z.output<typeof GLOBAL_SCHEMA>;
|
|
40
|
-
export interface CommandSpec<Input extends z.ZodObject> {
|
|
48
|
+
export interface CommandSpec<Input extends z.ZodObject, Output extends z.ZodObject> {
|
|
41
49
|
/**
|
|
42
50
|
`['issue', 'create']`、`['board', 'add']`。決まりは `<対象> <動詞>` の 2 語で、どちらも英小文字だけ(names.ts の commandNameViolations)
|
|
43
51
|
*/
|
|
@@ -52,6 +60,11 @@ export interface CommandSpec<Input extends z.ZodObject> {
|
|
|
52
60
|
*/
|
|
53
61
|
readonly input: Input;
|
|
54
62
|
/**
|
|
63
|
+
MCP の成功の data の型(z.strictObject)。run は createOutput<z.input<typeof output>>() の result で項目を渡す。
|
|
64
|
+
`.default()`・transform・z.date() は使わない(定義書への書き出しで形が変わるか、例外になる)
|
|
65
|
+
*/
|
|
66
|
+
readonly output: Output;
|
|
67
|
+
/**
|
|
55
68
|
自分の `--repo` を持つ印。真なら input に `repo` を書ける(説明は `.describe()`、形の検証は input の refine)。
|
|
56
69
|
実行時の `repo` は、サブコマンドの値を先に使い、無ければグローバルの値になる
|
|
57
70
|
*/
|
|
@@ -103,6 +116,10 @@ export interface CommandDefinition {
|
|
|
103
116
|
グローバルの repo を足した入力
|
|
104
117
|
*/
|
|
105
118
|
readonly input: z.ZodObject;
|
|
119
|
+
/**
|
|
120
|
+
MCP の成功の data の型
|
|
121
|
+
*/
|
|
122
|
+
readonly output: z.ZodObject;
|
|
106
123
|
readonly positional: readonly string[];
|
|
107
124
|
/**
|
|
108
125
|
自分の `--repo` を持つか。真のとき、input の repo はコマンド自身の引数
|
|
@@ -145,6 +162,6 @@ export declare function interfaceIdOf(path: readonly string[]): string;
|
|
|
145
162
|
/**
|
|
146
163
|
型付きの仕様から、型を消した定義を作る。parse が input で検証してから本体を呼ぶので、型を消しても安全に呼べる
|
|
147
164
|
*/
|
|
148
|
-
export declare function defineCommand<Input extends z.ZodObject>(spec: Readonly<CommandSpec<Input>>): CommandDefinition;
|
|
165
|
+
export declare function defineCommand<Input extends z.ZodObject, Output extends z.ZodObject>(spec: Readonly<CommandSpec<Input, Output>>): CommandDefinition;
|
|
149
166
|
export {};
|
|
150
167
|
//# sourceMappingURL=command-definition.d.ts.map
|
|
@@ -21,6 +21,7 @@ export class CommandExit extends BaseError {
|
|
|
21
21
|
グローバルの --repo を入力にしたもの。全コマンドの入力に足される
|
|
22
22
|
*/
|
|
23
23
|
const GLOBAL_SHAPE = { repo: z.string().optional() };
|
|
24
|
+
const RESERVED_OUTPUT_KEYS = ['reason', 'detail', 'warnings', 'log'];
|
|
24
25
|
const GLOBAL_SCHEMA = z.object(GLOBAL_SHAPE);
|
|
25
26
|
/**
|
|
26
27
|
path から MCP のツール名を作る。`['issue', 'create']` は issue_create、`['board', 'add']` は board_add
|
|
@@ -71,6 +72,13 @@ export function defineCommand(spec) {
|
|
|
71
72
|
throw new TypeError('input の repo はグローバルの --repo 用の予約名です');
|
|
72
73
|
if (hasOwnRepository && !hasRepositoryField)
|
|
73
74
|
throw new TypeError('hasOwnRepo のコマンドは input に repo が要ります');
|
|
75
|
+
// 定義書の data の成功の側を閉じた型(additionalProperties: false)にするため
|
|
76
|
+
if (!(spec.output.def.catchall instanceof z.ZodNever))
|
|
77
|
+
throw new TypeError('output は z.strictObject で書きます');
|
|
78
|
+
// MCP の結果の data は共通の項目を extend で重ねるので、同じ名前は知らせなしに上書きされる
|
|
79
|
+
const reserved = RESERVED_OUTPUT_KEYS.filter(key => Object.hasOwn(spec.output.shape, key));
|
|
80
|
+
if (reserved.length > 0)
|
|
81
|
+
throw new TypeError(`output の ${reserved.join('・')} は MCP の結果の共通の項目の予約名です`);
|
|
74
82
|
assertDistinctFlags(Object.keys(spec.input.shape), spec.positional, flagMap(spec.negations));
|
|
75
83
|
const aliased = Object.keys(spec.aliases ?? {});
|
|
76
84
|
for (const name of aliased) {
|
|
@@ -91,6 +99,7 @@ export function defineCommand(spec) {
|
|
|
91
99
|
toolName: toolNameOf(spec.path),
|
|
92
100
|
description: spec.description,
|
|
93
101
|
input,
|
|
102
|
+
output: spec.output,
|
|
94
103
|
positional: spec.positional,
|
|
95
104
|
hasOwnRepo: hasOwnRepository,
|
|
96
105
|
ignoresGlobalRepo: spec.ignoresGlobalRepo === true,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const FAILURE_KINDS: readonly ['invalid-input', 'aborted', 'github-auth', 'github-not-found', 'github-rate-limit', 'github-api', 'config-invalid', 'project-root-not-found', 'session-directory-unresolved', 'no-active-project', 'project-not-found', 'not-initialized', 'already-exists', 'repo-not-in-project', 'repo-setting-missing', 'repo-mismatch', 'git-unresolved', 'not-on-board', 'status-not-configured', 'guard-blocked', 'not-ready', 'dependency-rejected', 'dependency-unreadable', 'order-conflict', 'content-invalid', 'preflight-failed', 'pr-state', 'partial-failure', 'other'];
|
|
1
|
+
export declare const FAILURE_KINDS: readonly ['invalid-input', 'aborted', 'github-auth', 'github-not-found', 'github-rate-limit', 'github-api', 'config-invalid', 'project-root-not-found', 'session-directory-unresolved', 'no-active-project', 'project-not-found', 'not-initialized', 'already-exists', 'repo-not-in-project', 'repo-setting-missing', 'repo-mismatch', 'git-unresolved', 'not-on-board', 'status-not-configured', 'guard-blocked', 'not-ready', 'dependency-rejected', 'dependency-unreadable', 'order-conflict', 'content-invalid', 'preflight-failed', 'pr-state', 'git-conflict', 'partial-failure', 'other'];
|
|
2
2
|
export type FailureKind = typeof FAILURE_KINDS[number];
|
|
3
3
|
//# sourceMappingURL=failure-kind.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { BoardMove, LabelValue, MissingValue, MovableColumn } from '../domain/board-move.js';
|
|
2
3
|
import type { ProjectConfig } from '../domain/config.js';
|
|
3
4
|
import type { IssueReference } from '../domain/reference-parser.js';
|
|
4
5
|
import type { RepositoryReference } from '../domain/repository-resolver.js';
|
|
@@ -43,6 +44,29 @@ export interface PutOnBoardOptions {
|
|
|
43
44
|
途中で失敗して空のままの項目は、次の onlyIfEmpty の実行で直る。失敗したら GitHubAPIError
|
|
44
45
|
*/
|
|
45
46
|
export declare function putOnBoard(client: GitHubClient, config: ProjectConfig, owner: string, repository: string, issueNumber: number, priority: string | undefined, options: Readonly<PutOnBoardOptions>): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
列と札の行(moved: と set: Status of)に出した値。issue は行の表示の参照、reason は列を動かす理由の文。書いていない側は undefined
|
|
49
|
+
*/
|
|
50
|
+
export interface BoardMoveLine {
|
|
51
|
+
readonly issue: string;
|
|
52
|
+
readonly column: {
|
|
53
|
+
readonly from: string;
|
|
54
|
+
readonly to: MovableColumn;
|
|
55
|
+
} | undefined;
|
|
56
|
+
readonly label: LabelValue | undefined;
|
|
57
|
+
readonly reason: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync と pr create の data が使う
|
|
61
|
+
*/
|
|
62
|
+
export declare const BOARD_MOVE_JSON: z.ZodObject<{
|
|
63
|
+
issue: z.ZodString;
|
|
64
|
+
from: z.ZodOptional<z.ZodString>;
|
|
65
|
+
to: z.ZodOptional<z.ZodString>;
|
|
66
|
+
label: z.ZodOptional<z.ZodString>;
|
|
67
|
+
reason: z.ZodString;
|
|
68
|
+
}, z.core.$strict>;
|
|
69
|
+
export declare function moveJson({ issue, column, label, reason }: Readonly<BoardMoveLine>): z.input<typeof BOARD_MOVE_JSON>;
|
|
46
70
|
export interface AppliedMove {
|
|
47
71
|
/**
|
|
48
72
|
実際に動いた先の列。動かなかったら undefined
|
|
@@ -53,6 +77,10 @@ export interface AppliedMove {
|
|
|
53
77
|
書き込みに失敗した。列だけ書けて札で失敗したときも真
|
|
54
78
|
*/
|
|
55
79
|
readonly hasFailed: boolean;
|
|
80
|
+
/**
|
|
81
|
+
書けた列と札。どちらも書かなかったら undefined
|
|
82
|
+
*/
|
|
83
|
+
readonly written: BoardMoveLine | undefined;
|
|
56
84
|
}
|
|
57
85
|
interface MoveTarget {
|
|
58
86
|
readonly ref: IssueReference;
|
|
@@ -64,8 +92,8 @@ text は列を動かす理由の判定の文。board sync と issue block / unbl
|
|
|
64
92
|
*/
|
|
65
93
|
export declare function applyBoardMove(out: Readonly<Output>, client: GitHubClient, config: ProjectConfig, itemId: string, target: MoveTarget, move: Readonly<BoardMove>, text: string): Promise<AppliedMove>;
|
|
66
94
|
/**
|
|
67
|
-
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run
|
|
95
|
+
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)。予定の列と札を返し、どちらも無ければ undefined
|
|
68
96
|
*/
|
|
69
|
-
export declare function planBoardMove(out: Readonly<Output>, target: MoveTarget, move: Readonly<BoardMove>, text: string):
|
|
97
|
+
export declare function planBoardMove(out: Readonly<Output>, target: MoveTarget, move: Readonly<BoardMove>, text: string): BoardMoveLine | undefined;
|
|
70
98
|
export {};
|
|
71
99
|
//# sourceMappingURL=issue-board.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
2
|
// Issue の作成・ボードへの追加・フィールドの設定と、判定に応じた列と札の書き込み(applyBoardMove)。cli/core/issue_board.py の移植に applyBoardMove を足した。
|
|
3
3
|
// 失敗は GitHubAPIError で呼び出し側に返す。表示と終了コードは呼び出し側が決める。
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
import { COLUMN_CONFIG_KEYS, LABEL_CONFIG_KEYS } from '../domain/board-move.js';
|
|
5
6
|
import { getFieldId, getOptionId } from '../domain/config.js';
|
|
6
7
|
import { displayReference } from '../domain/readiness.js';
|
|
@@ -70,6 +71,24 @@ export async function putOnBoard(client, config, owner, repository, issueNumber,
|
|
|
70
71
|
await setIssueField(client, config, itemId, fieldName, option);
|
|
71
72
|
}
|
|
72
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
列と札を動かした(dry-run は動かす予定の)Issue 1 件。board sync と pr create の data が使う
|
|
76
|
+
*/
|
|
77
|
+
export const BOARD_MOVE_JSON = z.strictObject({
|
|
78
|
+
issue: z.string().describe('Issue as shown in the moved line (#N, or owner/repo#N outside the home repository)'),
|
|
79
|
+
from: z.string().optional().describe('Column before the move (omitted when only the Status changed)'),
|
|
80
|
+
to: z.string().optional().describe('Column after the move (omitted when only the Status changed)'),
|
|
81
|
+
label: z.string().optional().describe('Status value set (omitted when the Status did not change)'),
|
|
82
|
+
reason: z.string().describe('Readiness that decided the move'),
|
|
83
|
+
});
|
|
84
|
+
export function moveJson({ issue, column, label, reason }) {
|
|
85
|
+
return {
|
|
86
|
+
issue,
|
|
87
|
+
...column !== undefined && { from: column.from, to: column.to },
|
|
88
|
+
...label !== undefined && { label },
|
|
89
|
+
reason,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
73
92
|
function moveOperation(name, column, text) {
|
|
74
93
|
return { verb: 'move', target: `${name} ${column.from} -> ${column.to} (${text})` };
|
|
75
94
|
}
|
|
@@ -88,14 +107,16 @@ export async function applyBoardMove(out, client, config, itemId, target, move,
|
|
|
88
107
|
const name = displayReference(target.ref, target.home);
|
|
89
108
|
if (move.conflict !== undefined)
|
|
90
109
|
warnConflict(out, name, target, move.conflict);
|
|
91
|
-
let
|
|
110
|
+
let column;
|
|
111
|
+
let label;
|
|
92
112
|
let hasFailed = false;
|
|
93
113
|
try {
|
|
94
114
|
if (move.column !== undefined && await setIssueField(client, config, itemId, 'workflow', COLUMN_CONFIG_KEYS[move.column.to])) {
|
|
95
|
-
|
|
115
|
+
column = { from: move.column.from, to: move.column.to };
|
|
96
116
|
out.done(moveOperation(name, move.column, text));
|
|
97
117
|
}
|
|
98
118
|
if (move.label !== undefined && await setIssueField(client, config, itemId, 'status', LABEL_CONFIG_KEYS[move.label])) {
|
|
119
|
+
label = move.label;
|
|
99
120
|
out.done(labelOperation(name, move.label));
|
|
100
121
|
}
|
|
101
122
|
}
|
|
@@ -105,10 +126,11 @@ export async function applyBoardMove(out, client, config, itemId, target, move,
|
|
|
105
126
|
out.warning(`could not move ${name}: ${error.message}`);
|
|
106
127
|
hasFailed = true;
|
|
107
128
|
}
|
|
108
|
-
|
|
129
|
+
const written = column === undefined && label === undefined ? undefined : { issue: name, column, label, reason: text };
|
|
130
|
+
return { column: column?.to, missing: move.missing, hasFailed, written };
|
|
109
131
|
}
|
|
110
132
|
/**
|
|
111
|
-
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run
|
|
133
|
+
applyBoardMove と同じ文を、書かずに予定の行として出す(--dry-run)。予定の列と札を返し、どちらも無ければ undefined
|
|
112
134
|
*/
|
|
113
135
|
export function planBoardMove(out, target, move, text) {
|
|
114
136
|
const name = displayReference(target.ref, target.home);
|
|
@@ -118,5 +140,7 @@ export function planBoardMove(out, target, move, text) {
|
|
|
118
140
|
out.planned(moveOperation(name, move.column, text));
|
|
119
141
|
if (move.label !== undefined)
|
|
120
142
|
out.planned(labelOperation(name, move.label));
|
|
143
|
+
const column = move.column === undefined ? undefined : { from: move.column.from, to: move.column.to };
|
|
144
|
+
return column === undefined && move.label === undefined ? undefined : { issue: name, column, label: move.label, reason: text };
|
|
121
145
|
}
|
|
122
146
|
//# sourceMappingURL=issue-board.js.map
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable security/detect-non-literal-fs-filename -- パスは利用者の引数とテンプレートの置き場で決まる */
|
|
3
3
|
// issue comment。cli/commands/issue.py の issue_comment とその内部関数の移植。
|
|
4
4
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
import { isRepositoryInProject } from '../domain/config.js';
|
|
7
8
|
import { FrontmatterError, setFrontmatterValue } from '../domain/frontmatter.js';
|
|
@@ -19,11 +20,18 @@ import { stopWith, requireActiveConfigPlain } from './command-stop.js';
|
|
|
19
20
|
import { kindOfFailure } from './failure.js';
|
|
20
21
|
import { createGitHubClient } from './github-client.js';
|
|
21
22
|
import { COMMENT_VALIDATION_EXIT_CODE, hasReportedTemplateViolations, issuePath, parseIssueReferenceOrExit, runWithExit, } from './issue-shared.js';
|
|
22
|
-
import { createOutput } from './output.js';
|
|
23
|
+
import { createOutput, DRY_RUN_FIELD } from './output.js';
|
|
23
24
|
const TEMPLATE_SCHEMA = z.enum(['plan', 'merge-diff', 'review-findings', 'review-resolution', 'precede-notify']);
|
|
24
25
|
const TEMPLATE_CHOICES = TEMPLATE_SCHEMA.options.join(' / ');
|
|
25
26
|
// PR へのコメントは GitHub が /pull/ の形で html_url を返すので、両方受ける
|
|
26
27
|
const COMMENT_URL_PATTERN = /^https?:\/\/(?<host>[^/]+)\/(?<owner>[^/]+)\/(?<repo>[^/]+)\/(?:issues|pull)\/(?<number>\d+)#issuecomment-(?<id>\d+)$/u;
|
|
28
|
+
const ISSUE_COMMENT_OUTPUT = z.strictObject({
|
|
29
|
+
issue: z.string().optional().describe('Issue commented on (owner/repo/N; omitted with prepare)'),
|
|
30
|
+
commentUrl: z.string().optional().describe('URL of the comment created or updated (omitted on dry_run, with prepare, or when GitHub returned no URL)'),
|
|
31
|
+
change: z.enum(['created', 'updated']).optional().describe('Whether the comment was created or updated (omitted with prepare)'),
|
|
32
|
+
file: z.string().optional().describe('Absolute path of the file written: the template copied with prepare, or the file whose comment_url was written back after posting from it (omitted otherwise)'),
|
|
33
|
+
dryRun: DRY_RUN_FIELD,
|
|
34
|
+
});
|
|
27
35
|
function htmlUrlOf(comment, fallback) {
|
|
28
36
|
const url = jsonField(comment, 'html_url');
|
|
29
37
|
return typeof url === 'string' ? url : fallback;
|
|
@@ -35,6 +43,7 @@ function prepareTemplate(output, template, issueReference, isDryRun) {
|
|
|
35
43
|
stopWith(output, `template not found: ${templatePath}`, 'other');
|
|
36
44
|
}
|
|
37
45
|
if (isDryRun) {
|
|
46
|
+
output.result({});
|
|
38
47
|
output.planned({ verb: 'create', target: `comment template ${template} in ${outputDirectory()}` });
|
|
39
48
|
return;
|
|
40
49
|
}
|
|
@@ -45,6 +54,7 @@ function prepareTemplate(output, template, issueReference, isDryRun) {
|
|
|
45
54
|
try {
|
|
46
55
|
withReservedOutputPath(outputDirectory(), timestamp => `comment-${template}-${timestamp}.md`, (reserved) => {
|
|
47
56
|
writeFileSync(reserved, content, 'utf8');
|
|
57
|
+
output.result({ file: path.resolve(reserved) });
|
|
48
58
|
output.data(reserved);
|
|
49
59
|
});
|
|
50
60
|
}
|
|
@@ -75,6 +85,7 @@ function writeBackCommentUrl(output, file, commentUrl) {
|
|
|
75
85
|
try {
|
|
76
86
|
const content = readTextFile(file);
|
|
77
87
|
writeFileSync(file, setFrontmatterValue(content, 'comment_url', commentUrl), 'utf8');
|
|
88
|
+
output.result({ file: path.resolve(file) });
|
|
78
89
|
}
|
|
79
90
|
catch (error) {
|
|
80
91
|
const converted = toOsError(error, file);
|
|
@@ -98,6 +109,7 @@ async function createComment(output, client, target, body) {
|
|
|
98
109
|
return stopWith(output, `could not create a comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
|
|
99
110
|
}
|
|
100
111
|
const createdUrl = htmlUrlOf(comment, '');
|
|
112
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: 'created', ...createdUrl !== '' && { commentUrl: createdUrl } });
|
|
101
113
|
output.done({ verb: 'create', target: `comment on ${display}` });
|
|
102
114
|
output.data(createdUrl);
|
|
103
115
|
return createdUrl;
|
|
@@ -114,8 +126,10 @@ async function updateComment(output, client, target, commentId, commentUrl, body
|
|
|
114
126
|
throw error;
|
|
115
127
|
return stopWith(output, `could not update the comment on Issue ${display}: ${error.message}`, kindOfFailure(error));
|
|
116
128
|
}
|
|
129
|
+
const updatedUrl = htmlUrlOf(comment, commentUrl);
|
|
130
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: 'updated', commentUrl: updatedUrl });
|
|
117
131
|
output.done({ verb: 'update', target: `comment on ${display}` });
|
|
118
|
-
output.data(
|
|
132
|
+
output.data(updatedUrl);
|
|
119
133
|
}
|
|
120
134
|
async function postFromFile(output, config, repository, file, isDryRun) {
|
|
121
135
|
let parsed;
|
|
@@ -144,6 +158,7 @@ async function postFromFile(output, config, repository, file, isDryRun) {
|
|
|
144
158
|
}
|
|
145
159
|
if (isDryRun) {
|
|
146
160
|
const display = issuePath(target.owner, target.repository, target.number);
|
|
161
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: hasCommentUrl ? 'updated' : 'created' });
|
|
147
162
|
output.planned({ verb: hasCommentUrl ? 'update' : 'create', target: `comment on ${display}` });
|
|
148
163
|
if (!hasCommentUrl)
|
|
149
164
|
output.planned({ verb: 'set', target: `comment_url in ${file}` });
|
|
@@ -162,6 +177,7 @@ async function postDirect(output, config, repository, issueReference, message, t
|
|
|
162
177
|
if (hasReportedTemplateViolations(output, message, templateFile('comment', template)))
|
|
163
178
|
throw new CommandExit(COMMENT_VALIDATION_EXIT_CODE, 'content-invalid');
|
|
164
179
|
if (isDryRun) {
|
|
180
|
+
output.result({ issue: issuePath(target.owner, target.repository, target.number), change: 'created' });
|
|
165
181
|
output.planned({ verb: 'create', target: `comment on ${issuePath(target.owner, target.repository, target.number)}` });
|
|
166
182
|
return;
|
|
167
183
|
}
|
|
@@ -179,6 +195,7 @@ const ISSUE_COMMENT = defineCommand({
|
|
|
179
195
|
template: TEMPLATE_SCHEMA.optional().describe('Template type (required with --prepare and -m; plan/merge-diff/review-findings/review-resolution/precede-notify)'),
|
|
180
196
|
dry_run: z.boolean().default(false).describe('Show what would be posted or written without changing anything'),
|
|
181
197
|
}),
|
|
198
|
+
output: ISSUE_COMMENT_OUTPUT,
|
|
182
199
|
positional: ['file'],
|
|
183
200
|
shortFlags: { message: '-m', issue_ref: '-i', prepare: '-p', template: '-t', dry_run: '-n' },
|
|
184
201
|
interactive: false,
|