@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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +80 -22
- package/cli/dist/cli.js +6 -1
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +59 -0
- package/cli/dist/commands/board-judgment.d.ts +60 -0
- package/cli/dist/commands/board-judgment.js +144 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +57 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +72 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +111 -0
- package/cli/dist/commands/{project-info.d.ts → board-view.d.ts} +21 -7
- package/cli/dist/commands/{project-info.js → board-view.js} +22 -12
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +100 -0
- package/cli/dist/commands/command-binding.js +4 -0
- package/cli/dist/commands/command-definition.d.ts +20 -6
- package/cli/dist/commands/command-definition.js +11 -7
- package/cli/dist/commands/command-help.js +2 -2
- package/cli/dist/commands/command-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +5 -3
- package/cli/dist/commands/command-stop.js +7 -6
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +34 -0
- package/cli/dist/commands/failure.d.ts +6 -0
- package/cli/dist/commands/failure.js +29 -3
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +13 -3
- package/cli/dist/commands/help.js +8 -13
- package/cli/dist/commands/issue-board.d.ts +33 -0
- package/cli/dist/commands/issue-board.js +61 -1
- package/cli/dist/commands/issue-comment.js +47 -28
- package/cli/dist/commands/issue-create.js +548 -91
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +282 -0
- package/cli/dist/commands/issue-readiness.d.ts +94 -0
- package/cli/dist/commands/issue-readiness.js +218 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +115 -0
- package/cli/dist/commands/issue-shared.d.ts +32 -19
- package/cli/dist/commands/issue-shared.js +82 -75
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +169 -0
- package/cli/dist/commands/issue.d.ts +0 -1
- package/cli/dist/commands/issue.js +6 -8
- package/cli/dist/commands/names.d.ts +33 -0
- package/cli/dist/commands/names.js +62 -0
- package/cli/dist/commands/output.d.ts +14 -2
- package/cli/dist/commands/output.js +14 -7
- package/cli/dist/commands/pr-waiting.d.ts +20 -0
- package/cli/dist/commands/pr-waiting.js +106 -0
- package/cli/dist/commands/pr.d.ts +19 -0
- package/cli/dist/commands/pr.js +242 -323
- package/cli/dist/commands/project-sync.d.ts +2 -1
- package/cli/dist/commands/project-sync.js +18 -9
- package/cli/dist/commands/project.d.ts +3 -2
- package/cli/dist/commands/project.js +212 -175
- package/cli/dist/commands/registry.js +13 -10
- package/cli/dist/commands/release.d.ts +2 -2
- package/cli/dist/commands/release.js +53 -114
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-match.js +3 -2
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +267 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/{repository.js → session-start.js} +99 -128
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +82 -29
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +57 -66
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/{security.js → tracker-sync-security.js} +50 -61
- package/cli/dist/commands/tracker-sync.d.ts +7 -0
- package/cli/dist/commands/tracker-sync.js +3 -6
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +18 -0
- package/cli/dist/commands/usage-error.d.ts +4 -0
- package/cli/dist/commands/usage-error.js +6 -0
- package/cli/dist/commands/work-target.d.ts +12 -3
- package/cli/dist/commands/work-target.js +46 -5
- package/cli/dist/commands/worktree.js +32 -28
- package/cli/dist/domain/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -0
- package/cli/dist/domain/branch-name.js +1 -1
- package/cli/dist/domain/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +4 -0
- package/cli/dist/domain/config.js +11 -1
- package/cli/dist/domain/dependabot.js +1 -1
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/format.d.ts +51 -4
- package/cli/dist/domain/format.js +72 -6
- package/cli/dist/domain/frontmatter.d.ts +18 -3
- package/cli/dist/domain/frontmatter.js +38 -12
- package/cli/dist/domain/issue-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +36 -0
- package/cli/dist/domain/pull-request.d.ts +71 -4
- package/cli/dist/domain/pull-request.js +59 -10
- package/cli/dist/domain/readiness.d.ts +27 -0
- package/cli/dist/domain/readiness.js +114 -3
- package/cli/dist/domain/reference-parser.d.ts +3 -1
- package/cli/dist/domain/reference-parser.js +6 -2
- package/cli/dist/domain/release.d.ts +7 -3
- package/cli/dist/domain/release.js +5 -12
- package/cli/dist/domain/repository-policy.d.ts +9 -3
- package/cli/dist/domain/repository-policy.js +8 -7
- package/cli/dist/domain/repository-resolver.js +4 -1
- package/cli/dist/domain/security-alerts.js +1 -1
- package/cli/dist/domain/state.d.ts +30 -0
- package/cli/dist/domain/state.js +39 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -0
- package/cli/dist/infra/authored-notes.d.ts +1 -1
- package/cli/dist/infra/authored-notes.js +10 -4
- package/cli/dist/infra/config-store.d.ts +4 -0
- package/cli/dist/infra/config-store.js +13 -0
- package/cli/dist/infra/git.d.ts +12 -0
- package/cli/dist/infra/git.js +13 -1
- package/cli/dist/infra/github/client.d.ts +5 -0
- package/cli/dist/infra/github/client.js +10 -7
- package/cli/dist/infra/github/errors.d.ts +18 -0
- package/cli/dist/infra/github/errors.js +22 -0
- package/cli/dist/infra/github/issues.d.ts +39 -3
- package/cli/dist/infra/github/issues.js +178 -23
- package/cli/dist/infra/github/projects.d.ts +35 -0
- package/cli/dist/infra/github/projects.js +89 -8
- package/cli/dist/infra/github/pulls.d.ts +24 -0
- package/cli/dist/infra/github/pulls.js +56 -0
- package/cli/dist/infra/github/queries.d.ts +12 -4
- package/cli/dist/infra/github/queries.js +156 -8
- package/cli/dist/infra/github/readout.d.ts +5 -1
- package/cli/dist/infra/github/readout.js +11 -0
- package/cli/dist/infra/github/repos.d.ts +18 -0
- package/cli/dist/infra/github/repos.js +31 -0
- package/cli/dist/infra/nx-scope.d.ts +1 -1
- package/cli/dist/infra/nx-scope.js +1 -1
- package/cli/dist/infra/state-store.d.ts +10 -1
- package/cli/dist/infra/state-store.js +14 -2
- package/cli/dist/infra/worktree-links.d.ts +3 -0
- package/cli/dist/infra/worktree-links.js +8 -1
- package/cli/dist/infra/worktree.d.ts +12 -1
- package/cli/dist/infra/worktree.js +40 -23
- package/cli/dist/mcp/result.d.ts +34 -6
- package/cli/dist/mcp/result.js +62 -18
- package/cli/dist/mcp/server.d.ts +2 -2
- package/cli/dist/mcp/server.js +24 -10
- package/cli/templates/comment/plan.md +14 -0
- package/cli/templates/issue/bug.md +1 -1
- package/cli/templates/issue/task-implement.md +13 -6
- package/cli/templates/issue/task.md +1 -1
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/cli/dist/commands/dependabot.d.ts +0 -3
- package/cli/dist/commands/issue-project.d.ts +0 -3
- package/cli/dist/commands/issue-project.js +0 -176
- package/cli/dist/commands/issue-quick.d.ts +0 -3
- package/cli/dist/commands/issue-quick.js +0 -126
- package/cli/dist/commands/issue-read.d.ts +0 -3
- package/cli/dist/commands/issue-read.js +0 -80
- package/cli/dist/commands/repository.d.ts +0 -5
- package/cli/dist/commands/security.d.ts +0 -3
|
@@ -1,22 +1,28 @@
|
|
|
1
|
-
// session
|
|
1
|
+
// session show・session restore。cli/commands/session.py の移植。
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
4
4
|
import { ConfigError } from '../domain/config.js';
|
|
5
5
|
import { PecotError } from '../domain/errors.js';
|
|
6
|
+
import { describeReadiness } from '../domain/readiness.js';
|
|
6
7
|
import { parseIssueReference, ReferenceParseError } from '../domain/reference-parser.js';
|
|
7
8
|
import { FLAG_PECOT_ACTIVE } from '../domain/state.js';
|
|
9
|
+
import { describeStackBase, pickBasePullRequest } from '../domain/work-start.js';
|
|
8
10
|
import { loadActiveConfig } from '../infra/config-store.js';
|
|
9
11
|
import { gitCurrentBranch, primaryRemoteRepository } from '../infra/git.js';
|
|
10
12
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
11
|
-
import { hasFlag, readFlag } from '../infra/state-store.js';
|
|
13
|
+
import { hasFlag, readBaseRecord, readFlag } from '../infra/state-store.js';
|
|
12
14
|
import { defineCommand } from './command-definition.js';
|
|
13
15
|
import { FAILURE_EXIT_CODE } from './failure.js';
|
|
16
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
14
17
|
import { stopWith } from './command-stop.js';
|
|
15
18
|
import { directorySchema } from './directory-option.js';
|
|
16
19
|
import { createGitHubClient } from './github-client.js';
|
|
20
|
+
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
17
21
|
import { createOutput } from './output.js';
|
|
22
|
+
import { SESSION_FINISH_COMMANDS } from './session-finish.js';
|
|
23
|
+
import { SESSION_START_COMMANDS } from './session-start.js';
|
|
18
24
|
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
19
|
-
import { recordWorkTarget } from './work-target.js';
|
|
25
|
+
import { planWorkTarget, recordWorkTarget } from './work-target.js';
|
|
20
26
|
const ALL_FLAGS = [FLAG_PECOT_ACTIVE];
|
|
21
27
|
function collectFlagStatuses() {
|
|
22
28
|
return ALL_FLAGS.map((name) => {
|
|
@@ -24,43 +30,81 @@ function collectFlagStatuses() {
|
|
|
24
30
|
return { name, isSet, content: isSet ? readFlag(name) ?? '' : '' };
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
|
-
// .pecot-active の Issue を GitHub から読んで、Markdown の行にする。読めなければ warning
|
|
28
|
-
async function
|
|
33
|
+
// .pecot-active の Issue を GitHub から読んで、Markdown の行にする。読めなければ warning だけ出して undefined にする
|
|
34
|
+
async function readActiveIssue(statuses, output) {
|
|
29
35
|
const active = statuses.find(status => status.name === FLAG_PECOT_ACTIVE && status.isSet && status.content !== '');
|
|
30
36
|
if (active === undefined)
|
|
31
|
-
return
|
|
37
|
+
return undefined;
|
|
32
38
|
let reference;
|
|
33
39
|
try {
|
|
34
40
|
reference = parseIssueReference(active.content);
|
|
35
41
|
}
|
|
36
42
|
catch (error) {
|
|
37
43
|
if (error instanceof ReferenceParseError)
|
|
38
|
-
return
|
|
44
|
+
return undefined;
|
|
39
45
|
throw error;
|
|
40
46
|
}
|
|
41
47
|
let issue;
|
|
48
|
+
let config;
|
|
49
|
+
let client;
|
|
42
50
|
try {
|
|
43
|
-
|
|
51
|
+
config = loadActiveConfig();
|
|
44
52
|
if (config === undefined) {
|
|
45
53
|
output.warning('cannot read the active Issue: no active project');
|
|
46
|
-
return
|
|
54
|
+
return undefined;
|
|
47
55
|
}
|
|
48
|
-
|
|
56
|
+
client = createGitHubClient(output, config.host);
|
|
57
|
+
issue = await client.getIssueSlim(reference.repository.owner, reference.repository.repository, reference.number, 0);
|
|
49
58
|
}
|
|
50
59
|
catch (error) {
|
|
51
60
|
if (error instanceof ConfigError || error instanceof GitHubAPIError) {
|
|
52
61
|
output.warning(`cannot read the active Issue: ${error.message}`);
|
|
53
|
-
return
|
|
62
|
+
return undefined;
|
|
54
63
|
}
|
|
55
64
|
throw error;
|
|
56
65
|
}
|
|
57
66
|
const lines = ['', '## Active Issue', '', `#${String(issue.number)} ${issue.title} (${issue.state})`];
|
|
58
67
|
if (issue.body !== '')
|
|
59
68
|
lines.push('', issue.body);
|
|
60
|
-
return lines;
|
|
69
|
+
return { reference, config, client, lines };
|
|
70
|
+
}
|
|
71
|
+
// 積んで着手した作業ディレクトリの `## Stack` の節。積んでいなければ空
|
|
72
|
+
async function stackLines(active, output) {
|
|
73
|
+
const reading = readBaseRecord();
|
|
74
|
+
if (reading.kind === 'malformed')
|
|
75
|
+
output.warning(`.pecot-base is malformed: ${reading.content}`);
|
|
76
|
+
if (reading.kind !== 'stacked')
|
|
77
|
+
return [];
|
|
78
|
+
const { record, stackedOn } = reading;
|
|
79
|
+
const { owner, repository } = stackedOn.repository;
|
|
80
|
+
let pullRequest;
|
|
81
|
+
try {
|
|
82
|
+
const found = await active.client.listPullRequestsByHead(owner, repository, record.branch);
|
|
83
|
+
pullRequest = pickBasePullRequest(found.pullRequests);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (!(error instanceof GitHubAPIError))
|
|
87
|
+
throw error;
|
|
88
|
+
output.warning(`cannot read the PR of the base branch: ${error.message}`);
|
|
89
|
+
pullRequest = 'unknown';
|
|
90
|
+
}
|
|
91
|
+
const readiness = await readinessLines(active, output);
|
|
92
|
+
return ['', '## Stack', describeStackBase(record.branch, stackedOn, pullRequest), ...readiness];
|
|
61
93
|
}
|
|
62
|
-
|
|
63
|
-
|
|
94
|
+
// 着手中の Issue の判定が blocked のときだけ出す
|
|
95
|
+
async function readinessLines(active, output) {
|
|
96
|
+
const result = await readIssueReadinessIfSupported(active.client, active.config, active.reference, createReadinessCache());
|
|
97
|
+
if (result === undefined)
|
|
98
|
+
return [];
|
|
99
|
+
if (result.kind === 'unreadable') {
|
|
100
|
+
output.warning(`cannot judge readiness of the active Issue: ${result.reason}`);
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const { readiness } = result;
|
|
104
|
+
return readiness?.kind === 'blocked' ? [`- readiness: ${describeReadiness(readiness, result.prerequisites, active.reference.repository)}`] : [];
|
|
105
|
+
}
|
|
106
|
+
const SESSION_SHOW = defineCommand({
|
|
107
|
+
path: ['session', 'show'],
|
|
64
108
|
description: 'Show the session flag state, branch information, and inferred Issue',
|
|
65
109
|
input: z.object({ directory: directorySchema }),
|
|
66
110
|
positional: [],
|
|
@@ -72,6 +116,7 @@ const STATUS = defineCommand({
|
|
|
72
116
|
const origin = primaryRemoteRepository(input.directory);
|
|
73
117
|
const issueNumber = branch === undefined ? undefined : extractIssueNumberFromBranch(branch);
|
|
74
118
|
const statuses = collectFlagStatuses();
|
|
119
|
+
const active = await readActiveIssue(statuses, output);
|
|
75
120
|
const lines = [
|
|
76
121
|
'# Session status',
|
|
77
122
|
'',
|
|
@@ -82,7 +127,8 @@ const STATUS = defineCommand({
|
|
|
82
127
|
'| Flag | State | Content |',
|
|
83
128
|
'|------|-------|---------|',
|
|
84
129
|
...statuses.map(status => `| ${status.name} | ${status.isSet ? 'set' : 'unset'} | ${status.content} |`),
|
|
85
|
-
...
|
|
130
|
+
...active?.lines ?? [],
|
|
131
|
+
...active === undefined ? [] : await stackLines(active, output),
|
|
86
132
|
];
|
|
87
133
|
output.data(lines.join('\n'));
|
|
88
134
|
return 0;
|
|
@@ -105,21 +151,21 @@ async function fetchIssueTitle(owner, repository, number, output) {
|
|
|
105
151
|
throw error;
|
|
106
152
|
}
|
|
107
153
|
}
|
|
108
|
-
//
|
|
154
|
+
// issue_ref が無いときの、ブランチ名と remote からの推定。決められなければ error を出して終了コード 1
|
|
109
155
|
function inferTarget(directory, output) {
|
|
110
156
|
const branch = gitCurrentBranch(directory);
|
|
111
157
|
if (branch === undefined) {
|
|
112
|
-
return stopWith(output, 'cannot read the branch name', FAILURE_EXIT_CODE);
|
|
158
|
+
return stopWith(output, 'cannot read the branch name', 'git-unresolved', FAILURE_EXIT_CODE);
|
|
113
159
|
}
|
|
114
160
|
const number = extractIssueNumberFromBranch(branch);
|
|
115
161
|
if (number === undefined) {
|
|
116
|
-
return stopWith(output, `cannot infer the Issue number from the branch name: ${branch}\nrun:
|
|
162
|
+
return stopWith(output, hinted `cannot infer the Issue number from the branch name: ${branch}\nrun: ${commandHint(['session', 'restore'], { issue_ref: placeholder('owner/repo/N') })}`, 'git-unresolved', FAILURE_EXIT_CODE);
|
|
117
163
|
}
|
|
118
164
|
const origin = primaryRemoteRepository(directory);
|
|
119
165
|
const message = 'cannot read the repository information';
|
|
120
|
-
return origin === undefined ? stopWith(output, message, FAILURE_EXIT_CODE) : { owner: origin.owner, repository: origin.repository, number };
|
|
166
|
+
return origin === undefined ? stopWith(output, message, 'git-unresolved', FAILURE_EXIT_CODE) : { owner: origin.owner, repository: origin.repository, number };
|
|
121
167
|
}
|
|
122
|
-
//
|
|
168
|
+
// issue_ref の参照を分ける。形が誤っていれば error を出して終了コード 2
|
|
123
169
|
function parseTarget(issue, output) {
|
|
124
170
|
try {
|
|
125
171
|
const reference = parseIssueReference(issue);
|
|
@@ -128,22 +174,23 @@ function parseTarget(issue, output) {
|
|
|
128
174
|
catch (error) {
|
|
129
175
|
if (!(error instanceof ReferenceParseError))
|
|
130
176
|
throw error;
|
|
131
|
-
return stopWith(output, error.message, USAGE_EXIT_CODE);
|
|
177
|
+
return stopWith(output, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
132
178
|
}
|
|
133
179
|
}
|
|
134
|
-
const
|
|
180
|
+
const SESSION_RESTORE = defineCommand({
|
|
135
181
|
path: ['session', 'restore'],
|
|
136
182
|
description: 'Restore lost session flags (such as .pecot-active) from the branch information',
|
|
137
183
|
input: z.object({
|
|
138
|
-
|
|
184
|
+
issue_ref: z.string().optional().describe('Issue reference (owner/repo/number)'),
|
|
139
185
|
directory: directorySchema,
|
|
186
|
+
dry_run: z.boolean().default(false).describe('Show what would be recorded without writing anything'),
|
|
140
187
|
}),
|
|
141
188
|
positional: [],
|
|
142
|
-
shortFlags: {
|
|
189
|
+
shortFlags: { issue_ref: '-i', directory: '-D', dry_run: '-n' },
|
|
143
190
|
interactive: false,
|
|
144
191
|
run: async (input, io) => {
|
|
145
|
-
const output = createOutput(
|
|
146
|
-
const target = input.
|
|
192
|
+
const output = createOutput(input.dry_run, io);
|
|
193
|
+
const target = input.issue_ref === undefined ? inferTarget(input.directory, output) : parseTarget(input.issue_ref, output);
|
|
147
194
|
let title;
|
|
148
195
|
try {
|
|
149
196
|
title = await fetchIssueTitle(target.owner, target.repository, target.number, output);
|
|
@@ -151,11 +198,17 @@ const RESTORE = defineCommand({
|
|
|
151
198
|
catch (error) {
|
|
152
199
|
if (!(error instanceof ConfigError))
|
|
153
200
|
throw error;
|
|
154
|
-
return stopWith(output, error.message, FAILURE_EXIT_CODE);
|
|
201
|
+
return stopWith(output, error.message, 'config-invalid', FAILURE_EXIT_CODE);
|
|
155
202
|
}
|
|
156
|
-
|
|
203
|
+
if (input.dry_run)
|
|
204
|
+
planWorkTarget(output, target.owner, target.repository, target.number);
|
|
205
|
+
else
|
|
206
|
+
recordWorkTarget(output, target.owner, target.repository, target.number, title, { failWithExit: true });
|
|
157
207
|
return 0;
|
|
158
208
|
},
|
|
159
209
|
});
|
|
160
|
-
|
|
210
|
+
/**
|
|
211
|
+
session のグループのコマンド。start は session-start.ts、finish は session-finish.ts にある。並びは help の一覧に出る順
|
|
212
|
+
*/
|
|
213
|
+
export const SESSION_COMMANDS = [...SESSION_START_COMMANDS, SESSION_SHOW, SESSION_RESTORE, ...SESSION_FINISH_COMMANDS];
|
|
161
214
|
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandIo } from './command-definition.js';
|
|
2
|
+
import type { TrackerSyncInput } from './tracker-sync.js';
|
|
3
|
+
/**
|
|
4
|
+
tracker sync の source dependabot の本体。Tracker の Dependabot PRs waiting for a human decision の一覧を書き直す
|
|
5
|
+
*/
|
|
6
|
+
export declare function runDependabotSync(input: Readonly<TrackerSyncInput>, io: CommandIo): Promise<0>;
|
|
7
|
+
//# sourceMappingURL=tracker-sync-dependabot.d.ts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
//
|
|
1
|
+
// `pecot tracker sync dependabot` の本体。移す元は cli/commands/dependabot.py。
|
|
2
2
|
// 判断を待つ dependabot の PR を、open の Tracker の一覧に反映する。載せる PR が無くなったら、一覧を none にして Tracker を閉じる。
|
|
3
|
-
import { z } from 'zod';
|
|
4
3
|
import { buildTrackerTitle, checksLabel, DependabotPrError, parseTrackerPullRequestNumbers, planTracker, PR_LABEL, PRIORITY, renderTrackerBody, rollupState, TRACKER_PATTERN, waitingReasons, } from '../domain/dependabot-pull-requests.js';
|
|
5
4
|
import { jsonField } from '../domain/json.js';
|
|
6
5
|
import { findTracker } from '../domain/tracker-body.js';
|
|
7
6
|
import { requireNumber } from '../infra/github/payload.js';
|
|
8
|
-
import {
|
|
7
|
+
import { CommandExit } from './command-definition.js';
|
|
8
|
+
import { stopWith } from './command-stop.js';
|
|
9
|
+
import { kindOfFailure } from './failure.js';
|
|
9
10
|
import { makeClient } from './github-client.js';
|
|
10
11
|
import { createIssue, putOnBoard } from './issue-board.js';
|
|
11
12
|
import { createOutput } from './output.js';
|
|
12
13
|
import { apiErrorDetail, isBodyUnchanged, loadTarget, todayUtc, warnExtraTrackers } from './tracker-sync.js';
|
|
13
|
-
const FAILURE = 1;
|
|
14
14
|
function textOrEmpty(value) {
|
|
15
15
|
return typeof value === 'string' ? value : '';
|
|
16
16
|
}
|
|
@@ -101,65 +101,56 @@ async function applyChanges(out, input) {
|
|
|
101
101
|
return 1;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
out.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
out.planned(operation);
|
|
158
|
-
if (input.dry_run)
|
|
159
|
-
return 0;
|
|
160
|
-
const failures = await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
|
|
161
|
-
return failures > 0 ? FAILURE : 0;
|
|
162
|
-
},
|
|
163
|
-
});
|
|
164
|
-
export const DEPENDABOT_COMMANDS = [sync];
|
|
165
|
-
//# sourceMappingURL=dependabot.js.map
|
|
104
|
+
/**
|
|
105
|
+
tracker sync の source dependabot の本体。Tracker の Dependabot PRs waiting for a human decision の一覧を書き直す
|
|
106
|
+
*/
|
|
107
|
+
export async function runDependabotSync(input, io) {
|
|
108
|
+
const out = createOutput(input.dry_run, io);
|
|
109
|
+
const { config, owner, repository } = loadTarget(out, input.repo);
|
|
110
|
+
const client = makeClient(out, config);
|
|
111
|
+
let pullRequests;
|
|
112
|
+
let issues;
|
|
113
|
+
try {
|
|
114
|
+
pullRequests = await client.listOpenDependabotPullRequests(owner, repository);
|
|
115
|
+
issues = await client.listIssuesByLabel(owner, repository, PR_LABEL);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const detail = apiErrorDetail(error);
|
|
119
|
+
if (detail === undefined)
|
|
120
|
+
throw error;
|
|
121
|
+
return stopWith(out, `could not list pull requests or issues: ${detail}`, kindOfFailure(error));
|
|
122
|
+
}
|
|
123
|
+
const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
|
|
124
|
+
warnExtraTrackers(out, tracker, others);
|
|
125
|
+
const existingBody = tracker?.body;
|
|
126
|
+
let oldNumbers;
|
|
127
|
+
try {
|
|
128
|
+
oldNumbers = tracker === undefined ? undefined : parseTrackerPullRequestNumbers(existingBody);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (tracker === undefined || !(error instanceof DependabotPrError))
|
|
132
|
+
throw error;
|
|
133
|
+
return stopWith(out, `Tracker #${String(tracker.number)}: ${error.message}`, 'content-invalid');
|
|
134
|
+
}
|
|
135
|
+
const now = new Date();
|
|
136
|
+
const nodes = pullRequests;
|
|
137
|
+
const waiting = nodes.map(node => ({ node, reasons: waitingReasons(node, now) })).filter(item => item.reasons.length > 0);
|
|
138
|
+
out.count('open dependabot PRs', nodes.length);
|
|
139
|
+
out.count('PRs awaiting a decision', waiting.length);
|
|
140
|
+
out.count('PRs awaiting a decision without check results', waiting.filter(item => rollupState(item.node) === undefined).length);
|
|
141
|
+
const plan = planTracker(waiting.map(item => ({ ...entryOf(item.node), reasons: item.reasons })), oldNumbers);
|
|
142
|
+
const title = buildTrackerTitle(todayUtc(now));
|
|
143
|
+
const body = renderTrackerBody(plan.entries, existingBody);
|
|
144
|
+
const number = tracker?.number;
|
|
145
|
+
const isUnchanged = isBodyUnchanged(body, existingBody);
|
|
146
|
+
const stages = operationsFor(plan, number, title, isUnchanged);
|
|
147
|
+
for (const operation of [...stages.create, ...stages.rewrite, ...stages.close])
|
|
148
|
+
out.planned(operation);
|
|
149
|
+
if (input.dry_run)
|
|
150
|
+
return 0;
|
|
151
|
+
const failures = await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
|
|
152
|
+
if (failures > 0)
|
|
153
|
+
throw new CommandExit(1, 'partial-failure');
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=tracker-sync-dependabot.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandIo } from './command-definition.js';
|
|
2
|
+
import type { TrackerSyncInput } from './tracker-sync.js';
|
|
3
|
+
/**
|
|
4
|
+
tracker sync の source security の本体。Tracker の open security alerts の一覧を書き直す
|
|
5
|
+
*/
|
|
6
|
+
export declare function runSecuritySync(input: Readonly<TrackerSyncInput>, io: CommandIo): Promise<0>;
|
|
7
|
+
//# sourceMappingURL=tracker-sync-security.d.ts.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
// `pecot security
|
|
2
|
-
// 途中で抜ける箇所は CommandExit を投げ、
|
|
3
|
-
import { z } from 'zod';
|
|
1
|
+
// `pecot tracker sync security` の本体。cli/commands/security.py の移植。open の Tracker の一覧を、open の security alert に書き直す。
|
|
2
|
+
// 途中で抜ける箇所は CommandExit を投げ、tracker sync の定義が終了コードにする。
|
|
4
3
|
import { ALERT_KINDS, kindLabel, listOpenAlerts, SecurityAlertError } from '../domain/security-alerts.js';
|
|
5
4
|
import { ALERT_LABEL, buildTrackerTitle, maxPriority, normalizeAlerts, parseTrackerEntries, planTracker, renderTrackerBody, TRACKER_PATTERN } from '../domain/security-tracker.js';
|
|
6
5
|
import { findTracker } from '../domain/tracker-body.js';
|
|
7
6
|
import { createDependabotSource } from '../infra/github/dependabot-source.js';
|
|
8
7
|
import { requireNumber } from '../infra/github/payload.js';
|
|
9
8
|
import { createScanAlertSource } from '../infra/github/security-alerts-source.js';
|
|
10
|
-
import { CommandExit
|
|
9
|
+
import { CommandExit } from './command-definition.js';
|
|
10
|
+
import { stopWith } from './command-stop.js';
|
|
11
|
+
import { kindOfFailure } from './failure.js';
|
|
11
12
|
import { makeClient } from './github-client.js';
|
|
12
13
|
import { createIssue, putOnBoard } from './issue-board.js';
|
|
13
14
|
import { createOutput } from './output.js';
|
|
14
15
|
import { apiErrorDetail, isBodyUnchanged, loadTarget, settle, todayUtc, warnExtraTrackers } from './tracker-sync.js';
|
|
15
|
-
const FAILURE = 1;
|
|
16
16
|
// 一覧を取れなかった種類と無効の種類は行を触らず、足さない。終了コード 1 にするのは取れなかった種類だけ
|
|
17
17
|
async function fetchOpenAlerts(out, sources, host, owner, repository) {
|
|
18
18
|
const alerts = new Map();
|
|
@@ -106,59 +106,48 @@ async function applyChanges(out, input) {
|
|
|
106
106
|
return 1;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const stages = operationsOf(plan, number, title, isUnchanged);
|
|
155
|
-
for (const operation of [...stages.create, ...stages.rewrite])
|
|
156
|
-
out.planned(operation);
|
|
157
|
-
const failures = input.dry_run ? 0 : await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
|
|
158
|
-
if (failed.size > 0 || failures > 0)
|
|
159
|
-
throw new CommandExit(FAILURE);
|
|
160
|
-
return 0;
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
export const SECURITY_COMMANDS = [sync];
|
|
164
|
-
//# sourceMappingURL=security.js.map
|
|
109
|
+
/**
|
|
110
|
+
tracker sync の source security の本体。Tracker の open security alerts の一覧を書き直す
|
|
111
|
+
*/
|
|
112
|
+
export async function runSecuritySync(input, io) {
|
|
113
|
+
const out = createOutput(input.dry_run, io);
|
|
114
|
+
const { config, owner, repository } = loadTarget(out, input.repo);
|
|
115
|
+
const client = makeClient(out, config);
|
|
116
|
+
const sources = { scan: createScanAlertSource(client), dependabot: createDependabotSource(client) };
|
|
117
|
+
const { alerts, failed, disabled } = await fetchOpenAlerts(out, sources, config.host, owner, repository);
|
|
118
|
+
let issues;
|
|
119
|
+
try {
|
|
120
|
+
issues = await client.listIssuesByLabel(owner, repository, ALERT_LABEL);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
const text = apiErrorDetail(error);
|
|
124
|
+
if (text === undefined)
|
|
125
|
+
throw error;
|
|
126
|
+
return stopWith(out, `could not list issues: ${text}`, kindOfFailure(error));
|
|
127
|
+
}
|
|
128
|
+
const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
|
|
129
|
+
warnExtraTrackers(out, tracker, others);
|
|
130
|
+
const existingBody = tracker?.body;
|
|
131
|
+
let entries;
|
|
132
|
+
try {
|
|
133
|
+
entries = tracker === undefined ? undefined : parseTrackerEntries(existingBody);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (!(error instanceof SecurityAlertError))
|
|
137
|
+
throw error;
|
|
138
|
+
return stopWith(out, `${tracker === undefined ? 'Tracker' : `Tracker #${String(tracker.number)}`}: ${error.message}`, 'content-invalid');
|
|
139
|
+
}
|
|
140
|
+
const plan = planTracker(alerts, entries, failed, disabled);
|
|
141
|
+
const title = buildTrackerTitle(todayUtc(new Date()));
|
|
142
|
+
const body = renderTrackerBody(plan.entries, config.host, owner, repository, { existingBody, disabledKinds: disabled, failedKinds: failed });
|
|
143
|
+
const number = tracker?.number;
|
|
144
|
+
const isUnchanged = isBodyUnchanged(body, existingBody);
|
|
145
|
+
const stages = operationsOf(plan, number, title, isUnchanged);
|
|
146
|
+
for (const operation of [...stages.create, ...stages.rewrite])
|
|
147
|
+
out.planned(operation);
|
|
148
|
+
const failures = input.dry_run ? 0 : await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
|
|
149
|
+
if (failed.size > 0 || failures > 0)
|
|
150
|
+
throw new CommandExit(1, 'partial-failure');
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=tracker-sync-security.js.map
|
|
@@ -6,6 +6,13 @@ import type { Operation, Output } from './output.js';
|
|
|
6
6
|
API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
|
|
7
7
|
*/
|
|
8
8
|
export declare function settle(out: Output, operation: Operation): void;
|
|
9
|
+
/**
|
|
10
|
+
tracker sync の各 source の本体が受ける入力
|
|
11
|
+
*/
|
|
12
|
+
export interface TrackerSyncInput {
|
|
13
|
+
readonly dry_run: boolean;
|
|
14
|
+
readonly repo?: string | undefined;
|
|
15
|
+
}
|
|
9
16
|
export interface SyncTarget {
|
|
10
17
|
readonly config: ProjectConfig;
|
|
11
18
|
readonly owner: string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
//
|
|
1
|
+
// tracker sync と session finish が共有する出力の補助。
|
|
2
2
|
import { TransportFailure } from '../infra/github/client.js';
|
|
3
3
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
4
|
-
import { CommandExit } from './command-definition.js';
|
|
5
4
|
import { requireActiveConfigPlain } from './command-stop.js';
|
|
6
|
-
import {
|
|
5
|
+
import { requireReleaseTargetRepository } from './release.js';
|
|
7
6
|
/**
|
|
8
7
|
API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
|
|
9
8
|
*/
|
|
@@ -16,9 +15,7 @@ export function settle(out, operation) {
|
|
|
16
15
|
設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
|
|
17
16
|
*/
|
|
18
17
|
export function loadTarget(out, explicitRepository) {
|
|
19
|
-
const target =
|
|
20
|
-
if (target === undefined)
|
|
21
|
-
throw new CommandExit(1);
|
|
18
|
+
const target = requireReleaseTargetRepository(undefined, explicitRepository, out);
|
|
22
19
|
const config = requireActiveConfigPlain(out);
|
|
23
20
|
return { config, owner: target.owner, repository: target.repository };
|
|
24
21
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// `pecot tracker sync <source>`。source ごとの本体(dependabot.ts・security.ts)を呼び分ける。
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { defineCommand } from './command-definition.js';
|
|
4
|
+
import { runDependabotSync } from './tracker-sync-dependabot.js';
|
|
5
|
+
import { runSecuritySync } from './tracker-sync-security.js';
|
|
6
|
+
const syncCommand = defineCommand({
|
|
7
|
+
path: ['tracker', 'sync'],
|
|
8
|
+
description: 'Rewrite the open Tracker\'s list for a source: Dependabot PRs waiting for a human decision, or open security alerts',
|
|
9
|
+
input: z.strictObject({
|
|
10
|
+
source: z.enum(['dependabot', 'security']).describe('What to put into the Tracker: dependabot (Dependabot PRs waiting for a human decision) or security (open security alerts)'),
|
|
11
|
+
dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
|
|
12
|
+
}),
|
|
13
|
+
positional: ['source'],
|
|
14
|
+
interactive: false,
|
|
15
|
+
run: async (input, io) => await (input.source === 'dependabot' ? runDependabotSync(input, io) : runSecuritySync(input, io)),
|
|
16
|
+
});
|
|
17
|
+
export const TRACKER_COMMANDS = [syncCommand];
|
|
18
|
+
//# sourceMappingURL=tracker.js.map
|
|
@@ -33,6 +33,10 @@ export declare function noSuchOptionMessage(name: string, possibilities?: readon
|
|
|
33
33
|
possibilities は近いコマンド名。近い順のまま案内する
|
|
34
34
|
*/
|
|
35
35
|
export declare function noSuchCommandMessage(name: string, possibilities?: readonly string[]): string;
|
|
36
|
+
/**
|
|
37
|
+
古い名前のコマンドを打たれたときの案内。名前はどちらも空白でつないだ path
|
|
38
|
+
*/
|
|
39
|
+
export declare function renamedCommandMessage(oldName: string, newName: string): string;
|
|
36
40
|
export declare function optionRequiresArgumentMessage(name: string): string;
|
|
37
41
|
export declare function optionTakesNoValueMessage(name: string): string;
|
|
38
42
|
/**
|
|
@@ -43,6 +43,12 @@ export function noSuchCommandMessage(name, possibilities = []) {
|
|
|
43
43
|
const hint = possibilities.length === 0 ? '' : ` Did you mean ${possibilities.map(candidate => `'${candidate}'`).join(', ')}?`;
|
|
44
44
|
return `No such command '${name}'.${hint}`;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
古い名前のコマンドを打たれたときの案内。名前はどちらも空白でつないだ path
|
|
48
|
+
*/
|
|
49
|
+
export function renamedCommandMessage(oldName, newName) {
|
|
50
|
+
return `'${oldName}' was renamed to '${newName}'.`;
|
|
51
|
+
}
|
|
46
52
|
export function optionRequiresArgumentMessage(name) {
|
|
47
53
|
return `Option '${name}' requires an argument.`;
|
|
48
54
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
import type { BaseRecord } from '../domain/state.js';
|
|
1
2
|
import type { Output } from './output.js';
|
|
2
3
|
export interface RecordWorkTargetOptions {
|
|
3
4
|
/**
|
|
4
5
|
真なら、記録の失敗を warning ではなく error の行で出し、終了コード 1 で止める
|
|
5
6
|
*/
|
|
6
7
|
readonly failWithExit?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
着手で選んだ base。作業対象を記録できたときに .pecot-base へ書く。省くと .pecot-base は消えたままになる
|
|
10
|
+
*/
|
|
11
|
+
readonly base?: Readonly<BaseRecord>;
|
|
7
12
|
}
|
|
8
13
|
/**
|
|
9
|
-
.pecot-
|
|
10
|
-
失敗は warning
|
|
14
|
+
.pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
|
|
15
|
+
失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかを返す
|
|
16
|
+
*/
|
|
17
|
+
export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>): 'recorded' | 'failed';
|
|
18
|
+
/**
|
|
19
|
+
予行の行。recordWorkTarget が書く作業対象(.pecot-active・.pecot-session-title・.pecot-base)を書かずに出す
|
|
11
20
|
*/
|
|
12
|
-
export declare function
|
|
21
|
+
export declare function planWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number): void;
|
|
13
22
|
//# sourceMappingURL=work-target.d.ts.map
|