@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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// board show。表示と alert の収集は board-view.ts、着手の判定は board-readiness.ts が持つ。何も書き換えない。
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
5
|
+
import { formatBoardOutput, formatStackableChains } from '../domain/format.js';
|
|
6
|
+
import { parseOwnerRepository } from '../domain/repository-resolver.js';
|
|
7
|
+
import { getActiveConfigPath } from '../infra/config-store.js';
|
|
8
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
9
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
10
|
+
import { commandHint, hinted, inputHint } from './command-hint.js';
|
|
11
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
12
|
+
import { createGitHubClient } from './github-client.js';
|
|
13
|
+
import { createOutput } from './output.js';
|
|
14
|
+
import { readBoardReadiness, readinessOf, skipBoardReadiness } from './board-readiness.js';
|
|
15
|
+
import { boardShowJson, boardShowMarkdown, collectAlertStatuses, readBoard } from './board-view.js';
|
|
16
|
+
import { failApi } from './project-sync.js';
|
|
17
|
+
const SYNC_PATH = ['board', 'sync'];
|
|
18
|
+
function mismatchNote(count) {
|
|
19
|
+
const subject = count === 1 ? '1 Ready or Blocked Issue may be' : `${String(count)} Ready or Blocked Issues may be`;
|
|
20
|
+
return hinted `${subject} in a column or Status that does not match its judgment; run ${commandHint(SYNC_PATH)} (${inputHint(SYNC_PATH, 'dry_run')} to preview) to fix`;
|
|
21
|
+
}
|
|
22
|
+
const boardShowCommand = defineCommand({
|
|
23
|
+
path: ['board', 'show'],
|
|
24
|
+
description: 'Show the dashboard of the project board',
|
|
25
|
+
input: z.strictObject({
|
|
26
|
+
json: z.boolean().default(false).describe('Output as JSON'),
|
|
27
|
+
repo: z.string().superRefine((value, context) => {
|
|
28
|
+
try {
|
|
29
|
+
parseOwnerRepository(value);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!(error instanceof InvalidValueError))
|
|
33
|
+
throw error;
|
|
34
|
+
context.addIssue({ code: 'custom', message: `must be in 'owner/repo' form: ${error.message}` });
|
|
35
|
+
}
|
|
36
|
+
}).optional().describe('Target repository, given explicitly as \'owner/repo\''),
|
|
37
|
+
}),
|
|
38
|
+
hasOwnRepo: true,
|
|
39
|
+
positional: [],
|
|
40
|
+
shortFlags: { json: '-j' },
|
|
41
|
+
interactive: false,
|
|
42
|
+
run: async (input, io) => {
|
|
43
|
+
const out = createOutput(false, io);
|
|
44
|
+
const config = requireActiveConfig(out);
|
|
45
|
+
const configPath = getActiveConfigPath();
|
|
46
|
+
const projectName = configPath === undefined ? `${config.host}_${config.owner}_${String(config.project.number)}` : path.parse(configPath).name;
|
|
47
|
+
try {
|
|
48
|
+
const client = createGitHubClient(out, config.host);
|
|
49
|
+
const { items, progress, isLegacy } = await readBoard(client, config, input.repo);
|
|
50
|
+
const statuses = await collectAlertStatuses(client, config);
|
|
51
|
+
const view = { config, projectName, statuses };
|
|
52
|
+
const readiness = isLegacy ? skipBoardReadiness(out) : await readBoardReadiness(out, client, config, items, input.repo, progress);
|
|
53
|
+
if (readiness.mismatches > 0)
|
|
54
|
+
out.warning(mismatchNote(readiness.mismatches));
|
|
55
|
+
const json = readiness.json === undefined ? undefined : (item) => readinessOf(readiness, item);
|
|
56
|
+
out.data(input.json
|
|
57
|
+
? boardShowJson(view, items, json)
|
|
58
|
+
: boardShowMarkdown(view, input.repo, formatBoardOutput(items, readiness.texts), formatStackableChains(readiness.chains)));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof GitHubAPIError)
|
|
62
|
+
return failApi(out, 'read project board', error);
|
|
63
|
+
// Python の `except Exception` と同じ範囲(あらゆる Error)で捕まえる
|
|
64
|
+
if (error instanceof Error && !(error instanceof CommandExit))
|
|
65
|
+
return stopWith(out, `unexpected error: ${error.message}`, 'other');
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
export const BOARD_SHOW_COMMANDS = [boardShowCommand];
|
|
72
|
+
//# sourceMappingURL=board-show.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
|
+
// board sync。ボードの Ready・Blocked・Active・In Review の Issue を判定に合わせて、列と札を直す。
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { homeRepositoryOf } from '../domain/config.js';
|
|
6
|
+
import { loadActiveConfig, listProjectConfigNames, loadConfig, projectsDirectory } from '../infra/config-store.js';
|
|
7
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
8
|
+
import { applyJudgedMoves, judgeBoard, SYNCED_COLUMNS } from './board-judgment.js';
|
|
9
|
+
import { CommandExit, defineCommand } from './command-definition.js';
|
|
10
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
11
|
+
import { NO_ACTIVE_PROJECT, stopWith } from './command-stop.js';
|
|
12
|
+
import { makeClient } from './github-client.js';
|
|
13
|
+
import { createOutput } from './output.js';
|
|
14
|
+
import { pruneArchivedItems, readBoard } from './board-view.js';
|
|
15
|
+
import { failApi } from './project-sync.js';
|
|
16
|
+
function unsupportedWarning(out) {
|
|
17
|
+
out.warning('this GitHub Enterprise Server does not support issue dependencies (blockedBy); no column is moved');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
対象の Issue の前提と着手の跡を読み、判定に合わせて列と札を直す。dryRun は同じ文を予定の行で出し、書かない。
|
|
21
|
+
書き込みの失敗は warning にして続け、失敗した Issue の数を返す
|
|
22
|
+
*/
|
|
23
|
+
async function syncBoard(context, read, isDryRun) {
|
|
24
|
+
const { out, client, config } = context;
|
|
25
|
+
// 着手の跡は一覧に無いので、info と違い、一覧の値だけでは判定しない。Ready で前提 0 件なら動かさないと決まるので読まない
|
|
26
|
+
const judged = await judgeBoard(client, config, read.items, read.progress, {
|
|
27
|
+
columns: SYNCED_COLUMNS,
|
|
28
|
+
withoutRead: (target, known) => (target.item.workflow === 'Ready' && known?.blockedBy === 0 ? 'skip' : undefined),
|
|
29
|
+
});
|
|
30
|
+
if (judged === undefined) {
|
|
31
|
+
unsupportedWarning(out);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
return await applyJudgedMoves(context, judged, isDryRun);
|
|
35
|
+
}
|
|
36
|
+
function availableNames() {
|
|
37
|
+
return listProjectConfigNames().join(', ');
|
|
38
|
+
}
|
|
39
|
+
// --project、次にアクティブ設定。どちらも無く設定が 1 つだけなら、それを使う
|
|
40
|
+
function resolveConfig(out, project) {
|
|
41
|
+
if (project !== undefined) {
|
|
42
|
+
// 一覧は projects/ の *.json の名前なので、一致すれば ../ などの外のパスにならない
|
|
43
|
+
const name = project.endsWith('.json') ? project.slice(0, -'.json'.length) : project;
|
|
44
|
+
return listProjectConfigNames().includes(name) ? loadConfig(path.join(projectsDirectory(), `${name}.json`)) : stopWith(out, `project config not found: ${project}\navailable: ${availableNames()}`, 'project-not-found');
|
|
45
|
+
}
|
|
46
|
+
const active = loadActiveConfig();
|
|
47
|
+
if (active !== undefined)
|
|
48
|
+
return active;
|
|
49
|
+
const names = listProjectConfigNames();
|
|
50
|
+
const [only] = names;
|
|
51
|
+
if (only === undefined)
|
|
52
|
+
return stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
|
|
53
|
+
if (names.length === 1)
|
|
54
|
+
return loadConfig(path.join(projectsDirectory(), `${only}.json`));
|
|
55
|
+
return stopWith(out, hinted `no active project, and ${String(names.length)} project configs exist\nrun: ${commandHint(['board', 'sync'], { project: placeholder('NAME') })}\navailable: ${names.join(', ')}`, 'no-active-project');
|
|
56
|
+
}
|
|
57
|
+
// 窓が途中で切り替わると前後の used を比べられないので、使用量の行を省く
|
|
58
|
+
function reportPoints(out, before, after) {
|
|
59
|
+
if (before === undefined || after === undefined)
|
|
60
|
+
return;
|
|
61
|
+
const used = after.used - before.used;
|
|
62
|
+
if (before.reset === after.reset && used >= 0)
|
|
63
|
+
out.count('GraphQL points used', used);
|
|
64
|
+
out.count('GraphQL points remaining', after.remaining);
|
|
65
|
+
}
|
|
66
|
+
function failureMessage(failures) {
|
|
67
|
+
return failures === 1 ? 'could not write 1 Issue to the board' : `could not write ${String(failures)} Issues to the board`;
|
|
68
|
+
}
|
|
69
|
+
function deleteFailureMessage(failures) {
|
|
70
|
+
return failures === 1 ? 'could not delete 1 archived item from the board' : `could not delete ${String(failures)} archived items from the board`;
|
|
71
|
+
}
|
|
72
|
+
const boardSyncCommand = defineCommand({
|
|
73
|
+
path: ['board', 'sync'],
|
|
74
|
+
description: 'Move the Issues in Ready, Blocked, Active and In Review to the columns and Status values their judgment calls for, and delete the Archived items beyond the latest 20 from the board',
|
|
75
|
+
input: z.strictObject({
|
|
76
|
+
dry_run: z.boolean().default(false).describe('Show the planned moves without writing to the board'),
|
|
77
|
+
project: z.string().optional().describe('Name of the project config under .pecot/config/projects (without .json). Without it, the active project; when none is active and only one config exists, that one'),
|
|
78
|
+
}),
|
|
79
|
+
positional: [],
|
|
80
|
+
interactive: false,
|
|
81
|
+
run: async (input, io) => {
|
|
82
|
+
const out = createOutput(input.dry_run, io);
|
|
83
|
+
const config = resolveConfig(out, input.project);
|
|
84
|
+
const client = makeClient(out, config);
|
|
85
|
+
const before = await client.getGraphqlRateLimit();
|
|
86
|
+
let read;
|
|
87
|
+
try {
|
|
88
|
+
read = await readBoard(client, config, undefined);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (!(error instanceof GitHubAPIError))
|
|
92
|
+
throw error;
|
|
93
|
+
reportPoints(out, before, await client.getGraphqlRateLimit());
|
|
94
|
+
return failApi(out, 'read project board', error);
|
|
95
|
+
}
|
|
96
|
+
if (read.isLegacy)
|
|
97
|
+
unsupportedWarning(out);
|
|
98
|
+
const failures = read.isLegacy ? 0 : await syncBoard({ out, client, config, home: homeRepositoryOf(config) }, read, input.dry_run);
|
|
99
|
+
const pruneFailures = await pruneArchivedItems(out, client, config, read.allItems, input.dry_run);
|
|
100
|
+
reportPoints(out, before, await client.getGraphqlRateLimit());
|
|
101
|
+
if (failures === 0 && pruneFailures === 0)
|
|
102
|
+
return 0;
|
|
103
|
+
if (failures > 0)
|
|
104
|
+
out.error(failureMessage(failures));
|
|
105
|
+
if (pruneFailures > 0)
|
|
106
|
+
out.error(deleteFailureMessage(pruneFailures));
|
|
107
|
+
throw new CommandExit(1, 'partial-failure');
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
export const BOARD_SYNC_COMMANDS = [boardSyncCommand];
|
|
111
|
+
//# sourceMappingURL=board-sync.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ProjectConfig } from '../domain/config.js';
|
|
2
2
|
import type { DependabotAlertStatus } from '../domain/dependabot.js';
|
|
3
|
-
import type { BoardItem } from '../domain/format.js';
|
|
3
|
+
import type { BoardItem, BoardProgress } from '../domain/format.js';
|
|
4
|
+
import type { JsonObject } from '../domain/json.js';
|
|
5
|
+
import { JSON_NULL } from '../domain/json-null.js';
|
|
4
6
|
import type { GitHubClient } from '../infra/github/index.js';
|
|
5
7
|
import type { Output } from './output.js';
|
|
6
8
|
/**
|
|
@@ -9,9 +11,9 @@ import type { Output } from './output.js';
|
|
|
9
11
|
export type AlertStatus = DependabotAlertStatus | string;
|
|
10
12
|
/**
|
|
11
13
|
Archived のアイテムを updatedAt の新しい順に並べ、最新の 20 件を残して、残りをボードから消す。
|
|
12
|
-
|
|
14
|
+
消せなかった件数を warning の行に出し、その数を返す
|
|
13
15
|
*/
|
|
14
|
-
export declare function pruneArchivedItems(out: Readonly<Output>, client: Readonly<Pick<GitHubClient, 'deleteProjectItem'>>, config: ProjectConfig, allItems: readonly BoardItem[]): Promise<
|
|
16
|
+
export declare function pruneArchivedItems(out: Readonly<Output>, client: Readonly<Pick<GitHubClient, 'deleteProjectItem'>>, config: ProjectConfig, allItems: readonly BoardItem[], isDryRun: boolean): Promise<number>;
|
|
15
17
|
/**
|
|
16
18
|
登録リポジトリごとの Dependabot alert の状態(登録の順)。
|
|
17
19
|
1 つの取得の失敗でボードの表示を止めないよう、DependabotAlertError はここで理由の文字列にする
|
|
@@ -21,28 +23,40 @@ export declare function collectAlertStatuses(client: Readonly<GitHubClient>, con
|
|
|
21
23
|
items を最大 limit 件ずつ並列に処理し、結果を items の順で返す。1 件でも投げたら、その例外で止まる
|
|
22
24
|
*/
|
|
23
25
|
export declare function mapWithLimit<Item, Result>(items: readonly Item[], limit: number, task: (item: Item) => Promise<Result>): Promise<readonly Result[]>;
|
|
24
|
-
export interface
|
|
26
|
+
export interface BoardShowView {
|
|
25
27
|
readonly config: ProjectConfig;
|
|
26
28
|
readonly projectName: string;
|
|
27
29
|
readonly statuses: readonly AlertStatus[];
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
32
|
+
アイテムの JSON の readiness を引く。判定の無いアイテムは null
|
|
33
|
+
*/
|
|
34
|
+
export type ReadinessSource = (item: BoardItem) => JsonObject | typeof JSON_NULL;
|
|
35
|
+
/**
|
|
30
36
|
info --json の出力
|
|
31
37
|
*/
|
|
32
|
-
export declare function
|
|
38
|
+
export declare function boardShowJson(view: Readonly<BoardShowView>, items: readonly BoardItem[], readiness?: ReadinessSource): string;
|
|
33
39
|
/**
|
|
34
40
|
info の Markdown の出力
|
|
35
41
|
*/
|
|
36
|
-
export declare function
|
|
42
|
+
export declare function boardShowMarkdown(view: Readonly<BoardShowView>, effectiveRepository: string | undefined, boardOutput: string, chainsSection?: string): string;
|
|
37
43
|
export interface BoardRead {
|
|
38
44
|
readonly allItems: readonly BoardItem[];
|
|
39
45
|
/**
|
|
40
46
|
表示するアイテム(OPEN の Backlog・Pending・Blocked・Ready・Active・In Review。リポジトリの指定があれば絞る)
|
|
41
47
|
*/
|
|
42
48
|
readonly items: readonly BoardItem[];
|
|
49
|
+
/**
|
|
50
|
+
boardItemKey → 着手の判定の軽い入力。前提の無い Issue の個別の読み取りを省く
|
|
51
|
+
*/
|
|
52
|
+
readonly progress: ReadonlyMap<string, BoardProgress>;
|
|
53
|
+
/**
|
|
54
|
+
一覧を足す前のクエリで読み直した(Issue の依存関係に対応しない GHES)
|
|
55
|
+
*/
|
|
56
|
+
readonly isLegacy: boolean;
|
|
43
57
|
}
|
|
44
58
|
/**
|
|
45
59
|
ボードのアイテムを全部読み、表示するものに絞る
|
|
46
60
|
*/
|
|
47
61
|
export declare function readBoard(client: Readonly<GitHubClient>, config: ProjectConfig, effectiveRepository: string | undefined): Promise<BoardRead>;
|
|
48
|
-
//# sourceMappingURL=
|
|
62
|
+
//# sourceMappingURL=board-view.d.ts.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
//
|
|
1
|
+
// board show の表示と、Archived の整理、Dependabot alert の収集。
|
|
2
2
|
import { effectiveReleaseType, workflowFieldName } from '../domain/config.js';
|
|
3
3
|
import { DependabotAlertError, fetchDependabotAlertStatus } from '../domain/dependabot.js';
|
|
4
|
-
import { formatItemsJson, transformItems } from '../domain/format.js';
|
|
4
|
+
import { formatItemsJson, readBoardProgress, transformItems } from '../domain/format.js';
|
|
5
5
|
import { JSON_NULL } from '../domain/json-null.js';
|
|
6
6
|
import { compareStrings } from '../domain/python-format.js';
|
|
7
7
|
import { createDependabotSource } from '../infra/github/dependabot-source.js';
|
|
8
8
|
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
9
|
+
import { STATUS_FIELD_NAME } from './project-sync.js';
|
|
9
10
|
/**
|
|
10
11
|
Archived のうち、ボードに残す件数
|
|
11
12
|
*/
|
|
@@ -20,13 +21,17 @@ function updatedAtOf(item) {
|
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
Archived のアイテムを updatedAt の新しい順に並べ、最新の 20 件を残して、残りをボードから消す。
|
|
23
|
-
|
|
24
|
+
消せなかった件数を warning の行に出し、その数を返す
|
|
24
25
|
*/
|
|
25
|
-
export async function pruneArchivedItems(out, client, config, allItems) {
|
|
26
|
+
export async function pruneArchivedItems(out, client, config, allItems, isDryRun) {
|
|
26
27
|
const archived = allItems.filter(item => item.workflow === 'Archived').toSorted((first, second) => compareStrings(updatedAtOf(second), updatedAtOf(first)));
|
|
27
28
|
if (archived.length <= ARCHIVED_KEEP)
|
|
28
|
-
return;
|
|
29
|
+
return 0;
|
|
29
30
|
const targets = archived.slice(ARCHIVED_KEEP);
|
|
31
|
+
if (isDryRun) {
|
|
32
|
+
out.planned({ verb: 'delete', target: `${String(targets.length)} archived items` });
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
30
35
|
let deleted = 0;
|
|
31
36
|
for (const item of targets) {
|
|
32
37
|
// ID が文字列でないアイテムは、API を呼ばず、失敗として数える
|
|
@@ -43,10 +48,11 @@ export async function pruneArchivedItems(out, client, config, allItems) {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
if (deleted > 0)
|
|
46
|
-
out.done({ verb: 'delete', target: `${String(deleted)} archived items
|
|
51
|
+
out.done({ verb: 'delete', target: `${String(deleted)} archived items`, aside: true });
|
|
47
52
|
const failed = targets.length - deleted;
|
|
48
53
|
if (failed > 0)
|
|
49
54
|
out.warning(`failed to delete ${String(failed)} archived items`);
|
|
55
|
+
return failed;
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
58
|
登録リポジトリごとの Dependabot alert の状態(登録の順)。
|
|
@@ -102,7 +108,7 @@ function alertsLine(status) {
|
|
|
102
108
|
/**
|
|
103
109
|
info --json の出力
|
|
104
110
|
*/
|
|
105
|
-
export function
|
|
111
|
+
export function boardShowJson(view, items, readiness) {
|
|
106
112
|
const { config, projectName, statuses } = view;
|
|
107
113
|
const output = {
|
|
108
114
|
project: {
|
|
@@ -120,7 +126,7 @@ export function infoJson(view, items) {
|
|
|
120
126
|
release_branch: entry.release_branch ?? JSON_NULL,
|
|
121
127
|
dependabot_alerts: alertsJson(statusAt(statuses, index)),
|
|
122
128
|
})),
|
|
123
|
-
board: formatItemsJson(items),
|
|
129
|
+
board: readiness === undefined ? formatItemsJson(items) : { items: items.map(item => ({ ...item, readiness: readiness(item) })) },
|
|
124
130
|
};
|
|
125
131
|
return JSON.stringify(output, undefined, 2);
|
|
126
132
|
}
|
|
@@ -148,7 +154,7 @@ function repositoryLines(view) {
|
|
|
148
154
|
/**
|
|
149
155
|
info の Markdown の出力
|
|
150
156
|
*/
|
|
151
|
-
export function
|
|
157
|
+
export function boardShowMarkdown(view, effectiveRepository, boardOutput, chainsSection) {
|
|
152
158
|
const { config, projectName } = view;
|
|
153
159
|
const aggregation = config.aggregation_repo === undefined || config.aggregation_repo === '' ? 'none' : `\`${config.aggregation_repo}\``;
|
|
154
160
|
return [
|
|
@@ -165,6 +171,7 @@ export function infoMarkdown(view, effectiveRepository, boardOutput) {
|
|
|
165
171
|
effectiveRepository === undefined || effectiveRepository === '' ? '## Board status' : `## Board status (filter: ${effectiveRepository})`,
|
|
166
172
|
'',
|
|
167
173
|
boardOutput,
|
|
174
|
+
...(chainsSection === undefined ? [] : ['', chainsSection]),
|
|
168
175
|
].join('\n');
|
|
169
176
|
}
|
|
170
177
|
/**
|
|
@@ -172,10 +179,13 @@ export function infoMarkdown(view, effectiveRepository, boardOutput) {
|
|
|
172
179
|
*/
|
|
173
180
|
export async function readBoard(client, config, effectiveRepository) {
|
|
174
181
|
const fieldName = workflowFieldName(config);
|
|
175
|
-
const
|
|
182
|
+
const state = { isLegacy: false };
|
|
183
|
+
const rawItems = await client.listProjectItems(config.project.id, { workflowFieldName: fieldName, onLegacy: () => {
|
|
184
|
+
state.isLegacy = true;
|
|
185
|
+
} });
|
|
176
186
|
const allItems = transformItems(rawItems, fieldName);
|
|
177
187
|
const open = allItems.filter(item => item.content.state === 'OPEN' && typeof item.workflow === 'string' && DISPLAY_STATUSES.has(item.workflow));
|
|
178
188
|
const items = effectiveRepository === undefined || effectiveRepository === '' ? open : open.filter(item => item.content.repository === effectiveRepository);
|
|
179
|
-
return { allItems, items };
|
|
189
|
+
return { allItems, items, progress: readBoardProgress(rawItems, STATUS_FIELD_NAME), isLegacy: state.isLegacy };
|
|
180
190
|
}
|
|
181
|
-
//# sourceMappingURL=
|
|
191
|
+
//# sourceMappingURL=board-view.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// board のグループのコマンド。並びは help の一覧に出る順
|
|
2
|
+
import { BOARD_ADD_COMMANDS } from './board-add.js';
|
|
3
|
+
import { BOARD_MOVE_COMMANDS } from './board-move.js';
|
|
4
|
+
import { BOARD_SHOW_COMMANDS } from './board-show.js';
|
|
5
|
+
import { BOARD_SYNC_COMMANDS } from './board-sync.js';
|
|
6
|
+
export const BOARD_COMMANDS = [
|
|
7
|
+
...BOARD_SHOW_COMMANDS,
|
|
8
|
+
...BOARD_ADD_COMMANDS,
|
|
9
|
+
...BOARD_MOVE_COMMANDS,
|
|
10
|
+
...BOARD_SYNC_COMMANDS,
|
|
11
|
+
];
|
|
12
|
+
//# sourceMappingURL=board.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// branch delete。Python の cli/commands/repo.py の delete_branch の移植。
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { describeApiError } from '../domain/api-error-detail.js';
|
|
4
|
+
import { findRepository } from '../domain/config.js';
|
|
5
|
+
import { compareStrings } from '../domain/python-format.js';
|
|
6
|
+
import { ReferenceParseError, parseRepositoryReference } from '../domain/reference-parser.js';
|
|
7
|
+
import { GitHubAPIError, isMissingReferenceError } from '../infra/github/errors.js';
|
|
8
|
+
import { defineCommand } from './command-definition.js';
|
|
9
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
10
|
+
import { kindOfFailure } from './failure.js';
|
|
11
|
+
import { createGitHubClient } from './github-client.js';
|
|
12
|
+
import { createOutput } from './output.js';
|
|
13
|
+
import { requireRepositoryMatch } from './repository-match.js';
|
|
14
|
+
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
15
|
+
const branchDeleteCommand = defineCommand({
|
|
16
|
+
path: ['branch', 'delete'],
|
|
17
|
+
hasOwnRepo: true,
|
|
18
|
+
ignoresGlobalRepo: true,
|
|
19
|
+
description: 'Delete a remote branch (a protected branch is never deleted)',
|
|
20
|
+
input: z.strictObject({
|
|
21
|
+
repo: z.string().describe('Repository reference (owner/repo)'),
|
|
22
|
+
branch: z.string().describe('Name of the branch to delete'),
|
|
23
|
+
dry_run: z.boolean().default(false).describe('Show what would be deleted without deleting anything'),
|
|
24
|
+
}),
|
|
25
|
+
positional: ['repo', 'branch'],
|
|
26
|
+
shortFlags: { dry_run: '-n' },
|
|
27
|
+
interactive: false,
|
|
28
|
+
run: async (input, io) => {
|
|
29
|
+
// 位置引数の repo は対象のリポで、cwd と比べる明示値ではない
|
|
30
|
+
requireRepositoryMatch('reject', undefined, io, process.cwd());
|
|
31
|
+
const out = createOutput(input.dry_run, io);
|
|
32
|
+
// 1. repo をパース
|
|
33
|
+
let target;
|
|
34
|
+
try {
|
|
35
|
+
target = parseRepositoryReference(input.repo);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!(error instanceof ReferenceParseError))
|
|
39
|
+
throw error;
|
|
40
|
+
return stopWith(out, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
41
|
+
}
|
|
42
|
+
const { owner, repository } = target;
|
|
43
|
+
// 2. 設定取得
|
|
44
|
+
const config = requireActiveConfig(out);
|
|
45
|
+
// 3. 保護ブランチ収集(設定の develop_branch・release_branch と、API の既定ブランチ)
|
|
46
|
+
const protectedBranches = new Set();
|
|
47
|
+
const repositoryConfig = findRepository(config, owner, repository);
|
|
48
|
+
for (const branch of [repositoryConfig?.develop_branch, repositoryConfig?.release_branch]) {
|
|
49
|
+
if (branch !== undefined && branch !== '')
|
|
50
|
+
protectedBranches.add(branch);
|
|
51
|
+
}
|
|
52
|
+
let client;
|
|
53
|
+
try {
|
|
54
|
+
client = createGitHubClient(out, config.host);
|
|
55
|
+
protectedBranches.add(await client.getRepositoryDefaultBranch(owner, repository));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (!(error instanceof GitHubAPIError))
|
|
59
|
+
throw error;
|
|
60
|
+
return stopWith(out, `could not read the default branch of ${owner}/${repository}: ${error.message}`, kindOfFailure(error));
|
|
61
|
+
}
|
|
62
|
+
// 4. 保護ブランチチェック
|
|
63
|
+
if (protectedBranches.has(input.branch)) {
|
|
64
|
+
return stopWith(out, `${input.branch} is a protected branch\nprotected: ${[...protectedBranches].toSorted(compareStrings).join(', ')}`, 'guard-blocked');
|
|
65
|
+
}
|
|
66
|
+
// 5. dry-run
|
|
67
|
+
const operation = { verb: 'delete', target: `remote branch ${input.branch} in ${owner}/${repository}` };
|
|
68
|
+
if (input.dry_run) {
|
|
69
|
+
out.planned(operation);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
// 6. 削除実行
|
|
73
|
+
try {
|
|
74
|
+
await client.deleteBranch(owner, repository, input.branch);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (!(error instanceof GitHubAPIError))
|
|
78
|
+
throw error;
|
|
79
|
+
return stopWith(out, `could not delete remote branch ${input.branch} in ${owner}/${repository}: ${error.message}`, kindOfFailure(error));
|
|
80
|
+
}
|
|
81
|
+
out.done(operation);
|
|
82
|
+
// wip ブランチも連動削除
|
|
83
|
+
const wipBranch = `wip/${input.branch}`;
|
|
84
|
+
try {
|
|
85
|
+
await client.deleteBranch(owner, repository, wipBranch);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (!(error instanceof GitHubAPIError))
|
|
89
|
+
throw error;
|
|
90
|
+
// wip ブランチの削除の失敗だけは、API の応答の本文の詳細も見せる(Python の describe_api_error と同じ)。存在しない場合は何も出さない
|
|
91
|
+
if (!isMissingReferenceError(error))
|
|
92
|
+
out.warning(`could not delete remote branch ${wipBranch} in ${owner}/${repository}: ${describeApiError(error)}`);
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
out.done({ verb: 'delete', target: `remote branch ${wipBranch} in ${owner}/${repository}` });
|
|
96
|
+
return 0;
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
export const BRANCH_COMMANDS = [branchDeleteCommand];
|
|
100
|
+
//# sourceMappingURL=branch.js.map
|
|
@@ -5,6 +5,7 @@ import { Command, CommanderError, Option } from 'commander';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { closeMatches } from './fuzzy.js';
|
|
7
7
|
import { flagOf } from './names.js';
|
|
8
|
+
import { findRenamedInput, renamedInputNote } from './renamed-commands.js';
|
|
8
9
|
import { invalidValueMessage, missingArgumentMessage, missingOptionMessage, noSuchOptionMessage, optionRequiresArgumentMessage, optionTakesNoValueMessage, UsageError, } from './usage-error.js';
|
|
9
10
|
import { convertValue, flagKindOf, valueTypeOf } from './value-types.js';
|
|
10
11
|
function fieldSchemaOf(definition, name) {
|
|
@@ -113,6 +114,9 @@ function toUsageError(error, argv, bound, usage) {
|
|
|
113
114
|
const booleanNames = ['--help', ...bound.flatMap(entry => entry.kind === 'boolean' ? [entry.names[0], entry.negation] : [])];
|
|
114
115
|
if (typedName !== quoted && booleanNames.includes(typedName))
|
|
115
116
|
return new UsageError(optionTakesNoValueMessage(typedName));
|
|
117
|
+
const renamed = typedName.startsWith('--') ? findRenamedInput(usage.commandPath, typedName.slice(2).replaceAll('-', '_')) : undefined;
|
|
118
|
+
if (renamed !== undefined)
|
|
119
|
+
return new UsageError(`${noSuchOptionMessage(typedName)}${renamedInputNote(typedName, flagOf(renamed))}`, usage);
|
|
116
120
|
const longNames = ['--help', ...bound.flatMap(entry => [...entry.names.filter(name => name.startsWith('--')), ...entry.negation === undefined ? [] : [entry.negation]])];
|
|
117
121
|
const possibilities = typedName.startsWith('--') ? closeMatches(typedName, longNames) : [];
|
|
118
122
|
return new UsageError(noSuchOptionMessage(typedName, possibilities), usage);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { BaseError } from '../domain/errors.js';
|
|
3
|
+
import type { FailureKind } from './failure-kind.js';
|
|
3
4
|
/**
|
|
4
5
|
コマンドが出力を書く先。CLI は process の stdout・stderr、MCP は結果の文字列に集める
|
|
5
6
|
*/
|
|
@@ -10,6 +11,18 @@ export interface CommandIo {
|
|
|
10
11
|
標準入力から 1 行読む(末尾の改行は含めない)。終端は undefined。渡されない io(MCP)は、入力の終端と同じ扱い
|
|
11
12
|
*/
|
|
12
13
|
readonly readLine?: () => string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
案内の出し先。MCP の io(collectIo)だけが mcp を入れる。無ければ CLI の形
|
|
16
|
+
*/
|
|
17
|
+
readonly surface?: 'cli' | 'mcp';
|
|
18
|
+
/**
|
|
19
|
+
失敗の原因の名前を受け取る。MCP だけが渡す
|
|
20
|
+
*/
|
|
21
|
+
readonly failureKind?: (kind: FailureKind) => void;
|
|
22
|
+
/**
|
|
23
|
+
結果の行(created: など。改行を含まない)を受け取る。片付けの行は渡さない。MCP だけが渡す
|
|
24
|
+
*/
|
|
25
|
+
readonly resultLine?: (line: string) => void;
|
|
13
26
|
}
|
|
14
27
|
/**
|
|
15
28
|
コマンドの途中で、決めた終了コードで止めるための例外。defineCommand が包む run の 1 か所で捕まえて、戻り値の終了コードにする。
|
|
@@ -17,7 +30,8 @@ Python の `typer.Exit(n)` に当たる。`error:` の行や使い方の枠は
|
|
|
17
30
|
*/
|
|
18
31
|
export declare class CommandExit extends BaseError {
|
|
19
32
|
readonly exitCode: number;
|
|
20
|
-
|
|
33
|
+
readonly kind: FailureKind;
|
|
34
|
+
constructor(exitCode: number, kind: FailureKind);
|
|
21
35
|
}
|
|
22
36
|
declare const GLOBAL_SCHEMA: z.ZodObject<{
|
|
23
37
|
repo: z.ZodOptional<z.ZodString>;
|
|
@@ -25,7 +39,7 @@ declare const GLOBAL_SCHEMA: z.ZodObject<{
|
|
|
25
39
|
export type GlobalInput = z.output<typeof GLOBAL_SCHEMA>;
|
|
26
40
|
export interface CommandSpec<Input extends z.ZodObject> {
|
|
27
41
|
/**
|
|
28
|
-
`['issue', 'create']`、`['add
|
|
42
|
+
`['issue', 'create']`、`['board', 'add']`。決まりは `<対象> <動詞>` の 2 語で、どちらも英小文字だけ(names.ts の commandNameViolations)
|
|
29
43
|
*/
|
|
30
44
|
readonly path: readonly string[];
|
|
31
45
|
/**
|
|
@@ -64,9 +78,9 @@ export interface CommandSpec<Input extends z.ZodObject> {
|
|
|
64
78
|
*/
|
|
65
79
|
readonly negations?: Readonly<Partial<Record<keyof Input['shape'] & string, string>>>;
|
|
66
80
|
/**
|
|
67
|
-
|
|
81
|
+
実行して 0 を返す。出力は io に書く。失敗は CommandExit で止め、原因の名前を運ぶ
|
|
68
82
|
*/
|
|
69
|
-
readonly run: (input: z.output<Input> & GlobalInput, io: CommandIo) => Promise<
|
|
83
|
+
readonly run: (input: z.output<Input> & GlobalInput, io: CommandIo) => Promise<0>;
|
|
70
84
|
/**
|
|
71
85
|
CLI でだけ利用者に問うか
|
|
72
86
|
*/
|
|
@@ -121,11 +135,11 @@ export interface CommandDefinition {
|
|
|
121
135
|
readonly run: (input: Readonly<Record<string, unknown>>, io: CommandIo) => Promise<number>;
|
|
122
136
|
}
|
|
123
137
|
/**
|
|
124
|
-
path から MCP のツール名を作る。`['issue', 'create']` は issue_create、`['add
|
|
138
|
+
path から MCP のツール名を作る。`['issue', 'create']` は issue_create、`['board', 'add']` は board_add
|
|
125
139
|
*/
|
|
126
140
|
export declare function toolNameOf(path: readonly string[]): string;
|
|
127
141
|
/**
|
|
128
|
-
path から定義書(interface/)の項目の ID を作る。`['
|
|
142
|
+
path から定義書(interface/)の項目の ID を作る。`['session', 'start']` は PW-SESSION-START、`['issue', 'create']` は PW-ISSUE-CREATE
|
|
129
143
|
*/
|
|
130
144
|
export declare function interfaceIdOf(path: readonly string[]): string;
|
|
131
145
|
/**
|
|
@@ -10,9 +10,11 @@ Python の `typer.Exit(n)` に当たる。`error:` の行や使い方の枠は
|
|
|
10
10
|
*/
|
|
11
11
|
export class CommandExit extends BaseError {
|
|
12
12
|
exitCode;
|
|
13
|
-
|
|
13
|
+
kind;
|
|
14
|
+
constructor(exitCode, kind) {
|
|
14
15
|
super(`exit ${String(exitCode)}`);
|
|
15
16
|
this.exitCode = exitCode;
|
|
17
|
+
this.kind = kind;
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
@@ -21,13 +23,13 @@ export class CommandExit extends BaseError {
|
|
|
21
23
|
const GLOBAL_SHAPE = { repo: z.string().optional() };
|
|
22
24
|
const GLOBAL_SCHEMA = z.object(GLOBAL_SHAPE);
|
|
23
25
|
/**
|
|
24
|
-
path から MCP のツール名を作る。`['issue', 'create']` は issue_create、`['add
|
|
26
|
+
path から MCP のツール名を作る。`['issue', 'create']` は issue_create、`['board', 'add']` は board_add
|
|
25
27
|
*/
|
|
26
28
|
export function toolNameOf(path) {
|
|
27
|
-
return path.join('_')
|
|
29
|
+
return path.join('_');
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
|
-
path から定義書(interface/)の項目の ID を作る。`['
|
|
32
|
+
path から定義書(interface/)の項目の ID を作る。`['session', 'start']` は PW-SESSION-START、`['issue', 'create']` は PW-ISSUE-CREATE
|
|
31
33
|
*/
|
|
32
34
|
export function interfaceIdOf(path) {
|
|
33
35
|
return `PW-${path.join(' ').toUpperCase().replaceAll(/[ _]/g, '-')}`;
|
|
@@ -50,9 +52,10 @@ async function runToExitCode(run, input, io) {
|
|
|
50
52
|
return await run(input, io);
|
|
51
53
|
}
|
|
52
54
|
catch (error) {
|
|
53
|
-
if (error instanceof CommandExit)
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (!(error instanceof CommandExit))
|
|
56
|
+
throw error;
|
|
57
|
+
io.failureKind?.(error.kind);
|
|
58
|
+
return error.exitCode;
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
@@ -63,6 +66,7 @@ export function defineCommand(spec) {
|
|
|
63
66
|
throw new TypeError('コマンドの path が空です');
|
|
64
67
|
const hasOwnRepository = spec.hasOwnRepo === true;
|
|
65
68
|
const hasRepositoryField = Object.hasOwn(spec.input.shape, 'repo');
|
|
69
|
+
// eslint-disable-next-line no-restricted-syntax -- コマンドの定義の誤りで、利用者には出ない
|
|
66
70
|
if (hasRepositoryField && !hasOwnRepository)
|
|
67
71
|
throw new TypeError('input の repo はグローバルの --repo 用の予約名です');
|
|
68
72
|
if (hasOwnRepository && !hasRepositoryField)
|
|
@@ -81,10 +81,10 @@ function propertyOf(input, name) {
|
|
|
81
81
|
return Object.entries(input.properties).find(([key]) => key === name)?.[1] ?? {};
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
グローバルの --repo でも満たせるので、自分の `--repo` を持つコマンドの repo
|
|
84
|
+
グローバルの --repo でも満たせるので、自分の `--repo` を持つコマンドの repo は必須として出さない。位置引数の repo は必須と出す
|
|
85
85
|
*/
|
|
86
86
|
function isRequiredField(definition, input, name) {
|
|
87
|
-
return input.required.includes(name) &&
|
|
87
|
+
return input.required.includes(name) && (name !== 'repo' || !definition.hasOwnRepo || definition.positional.includes('repo'));
|
|
88
88
|
}
|
|
89
89
|
function positionalName(name, input, isRequired) {
|
|
90
90
|
const shown = isRequired ? `<${name}>` : `[${name}]`;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CommandDefinition } from './command-definition.js';
|
|
2
|
+
export { commandHint, globalRepositoryHint, hinted, hintedTextOf, inputHint, inputNameHint, joinHinted, placeholder } from '../domain/command-hint.js';
|
|
3
|
+
export type { CommandHint, HintedText } from '../domain/command-hint.js';
|
|
4
|
+
export declare function registerCommandHints(definitions: readonly CommandDefinition[]): void;
|
|
5
|
+
//# sourceMappingURL=command-hint.d.ts.map
|