@pecot/workflow-mcp 0.0.0-stage → 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 +8 -0
- package/LICENSE +21 -0
- package/README.md +184 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +227 -0
- 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/board-view.d.ts +62 -0
- package/cli/dist/commands/board-view.js +191 -0
- 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/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +270 -0
- package/cli/dist/commands/command-definition.d.ts +150 -0
- package/cli/dist/commands/command-definition.js +105 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- 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 +21 -0
- package/cli/dist/commands/command-stop.js +31 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- 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 +19 -0
- package/cli/dist/commands/failure.js +59 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +16 -0
- package/cli/dist/commands/github-client.js +33 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +50 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +71 -0
- package/cli/dist/commands/issue-board.js +122 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +215 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +786 -0
- 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 +172 -0
- package/cli/dist/commands/issue-shared.js +426 -0
- 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 +3 -0
- package/cli/dist/commands/issue.js +13 -0
- package/cli/dist/commands/names.d.ts +42 -0
- package/cli/dist/commands/names.js +78 -0
- package/cli/dist/commands/output.d.ts +90 -0
- package/cli/dist/commands/output.js +194 -0
- 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 +22 -0
- package/cli/dist/commands/pr.js +852 -0
- package/cli/dist/commands/project-sync.d.ts +92 -0
- package/cli/dist/commands/project-sync.js +282 -0
- package/cli/dist/commands/project.d.ts +6 -0
- package/cli/dist/commands/project.js +714 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +30 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +353 -0
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +34 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- 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/session-start.js +236 -0
- package/cli/dist/commands/session.d.ts +6 -0
- package/cli/dist/commands/session.js +214 -0
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-security.js +153 -0
- package/cli/dist/commands/tracker-sync.d.ts +65 -0
- package/cli/dist/commands/tracker-sync.js +50 -0
- 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 +51 -0
- package/cli/dist/commands/usage-error.js +78 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +22 -0
- package/cli/dist/commands/work-target.js +82 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +339 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- 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.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- 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 +219 -0
- package/cli/dist/domain/config.js +310 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +24 -0
- package/cli/dist/domain/errors.js +36 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +94 -0
- package/cli/dist/domain/format.js +234 -0
- package/cli/dist/domain/frontmatter.d.ts +137 -0
- package/cli/dist/domain/frontmatter.js +290 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- 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 +143 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +201 -0
- package/cli/dist/domain/pull-request.js +281 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +199 -0
- package/cli/dist/domain/readiness.js +391 -0
- package/cli/dist/domain/reference-parser.d.ts +51 -0
- package/cli/dist/domain/reference-parser.js +123 -0
- package/cli/dist/domain/release.d.ts +53 -0
- package/cli/dist/domain/release.js +65 -0
- package/cli/dist/domain/repository-policy.d.ts +38 -0
- package/cli/dist/domain/repository-policy.js +66 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +122 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +59 -0
- package/cli/dist/domain/state.js +95 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +72 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +53 -0
- package/cli/dist/infra/config-store.js +134 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +86 -0
- package/cli/dist/infra/git.js +145 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +178 -0
- package/cli/dist/infra/github/client.js +579 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +65 -0
- package/cli/dist/infra/github/errors.js +64 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +165 -0
- package/cli/dist/infra/github/issues.js +428 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +143 -0
- package/cli/dist/infra/github/projects.js +384 -0
- package/cli/dist/infra/github/pulls.d.ts +104 -0
- package/cli/dist/infra/github/pulls.js +217 -0
- package/cli/dist/infra/github/queries.d.ts +44 -0
- package/cli/dist/infra/github/queries.js +1031 -0
- package/cli/dist/infra/github/readout.d.ts +22 -0
- package/cli/dist/infra/github/readout.js +167 -0
- package/cli/dist/infra/github/repos.d.ts +86 -0
- package/cli/dist/infra/github/repos.js +168 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +54 -0
- package/cli/dist/infra/state-store.js +130 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +142 -0
- package/cli/dist/infra/worktree-links.js +440 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +185 -0
- package/cli/dist/infra/worktree.js +584 -0
- package/cli/dist/mcp/result.d.ts +61 -0
- package/cli/dist/mcp/result.js +96 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +142 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +195 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +74 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- zod の型は readonly にできない */
|
|
2
|
+
// コマンドごとの --help。引数とオプションは、定義書の書き出しと同じ normalizeInput を通して作る。
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { bulletSection, definitionSection, examplesSection, HELP_OPTION, helpWidth, paragraph, usageLines } from './help-layout.js';
|
|
5
|
+
import { isRecord, normalizeInput } from './input-schema.js';
|
|
6
|
+
import { flagOf } from './names.js';
|
|
7
|
+
import { describeRange } from './value-types.js';
|
|
8
|
+
const MAX_INLINE_CHOICES = 24;
|
|
9
|
+
function isList(property) {
|
|
10
|
+
return property['type'] === 'array';
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
複数回渡せる引数の要素。list でなければ引数そのもの
|
|
14
|
+
*/
|
|
15
|
+
function elementOf(property) {
|
|
16
|
+
const items = property['items'];
|
|
17
|
+
return isList(property) && isRecord(items) ? items : property;
|
|
18
|
+
}
|
|
19
|
+
function choicesOf(property) {
|
|
20
|
+
const choices = elementOf(property)['enum'];
|
|
21
|
+
return Array.isArray(choices) ? choices.map(String) : undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
選択肢を名前の列に並べると、列が広がって説明を置けなくなる長さか。長いときは型を `<str>` にして、説明の末尾に `[choices: a, b]` の形で出す
|
|
25
|
+
*/
|
|
26
|
+
function isLongChoices(choices) {
|
|
27
|
+
return choices.join('|').length > MAX_INLINE_CHOICES;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
値の型。`<str>`・`<int>`、選択肢は `<task|bug|epic|tracker>`
|
|
31
|
+
*/
|
|
32
|
+
function metavarOf(property) {
|
|
33
|
+
const choices = choicesOf(property);
|
|
34
|
+
if (choices !== undefined && !isLongChoices(choices))
|
|
35
|
+
return `<${choices.join('|')}>`;
|
|
36
|
+
return elementOf(property)['type'] === 'integer' ? '<int>' : '<str>';
|
|
37
|
+
}
|
|
38
|
+
function rangeOf(property) {
|
|
39
|
+
const element = elementOf(property);
|
|
40
|
+
const min = element['minimum'];
|
|
41
|
+
const max = element['maximum'];
|
|
42
|
+
if (typeof min !== 'number' && typeof max !== 'number')
|
|
43
|
+
return undefined;
|
|
44
|
+
return describeRange(typeof min === 'number' ? min : undefined, typeof max === 'number' ? max : undefined);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
初期値の表示。真偽値は、初期値が真で否定形を持つものだけ、正の形の名前を出す。初期値が偽のものは、付けないことが初期値なので出さない
|
|
48
|
+
*/
|
|
49
|
+
function defaultOf(name, property, hasNegation) {
|
|
50
|
+
const value = property['default'];
|
|
51
|
+
if (property['type'] === 'boolean')
|
|
52
|
+
return value === true && hasNegation ? name.replaceAll('_', '-') : undefined;
|
|
53
|
+
if (typeof value === 'string')
|
|
54
|
+
return value === '' ? undefined : value;
|
|
55
|
+
return typeof value === 'number' ? String(value) : undefined;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
説明、初期値の補足の文、末尾の `[repeatable]`・`[required]`・`[choices: …]`・`[default: …]`・`[0<=x<=20]`
|
|
59
|
+
*/
|
|
60
|
+
function describeProperty(described) {
|
|
61
|
+
const { name, property, isRequired, hasNegation, isOption, defaultNote = '' } = described;
|
|
62
|
+
const description = property['description'];
|
|
63
|
+
const fallback = defaultOf(name, property, hasNegation);
|
|
64
|
+
const allChoices = choicesOf(property);
|
|
65
|
+
const choices = isOption && allChoices !== undefined && !isLongChoices(allChoices) ? undefined : allChoices;
|
|
66
|
+
const range = rangeOf(property);
|
|
67
|
+
return [
|
|
68
|
+
typeof description === 'string' ? description : '',
|
|
69
|
+
defaultNote,
|
|
70
|
+
isOption && isList(property) ? '[repeatable]' : '',
|
|
71
|
+
isRequired && property['type'] !== 'boolean' ? '[required]' : '',
|
|
72
|
+
choices === undefined ? '' : `[choices: ${choices.join(', ')}]`,
|
|
73
|
+
fallback === undefined ? '' : `[default: ${fallback}]`,
|
|
74
|
+
range === undefined ? '' : `[${range}]`,
|
|
75
|
+
].filter(part => part !== '').join(' ');
|
|
76
|
+
}
|
|
77
|
+
function inputOf(definition) {
|
|
78
|
+
return normalizeInput(z.toJSONSchema(definition.input, { io: 'input' }), definition.path.join(' '), definition.hasOwnRepo);
|
|
79
|
+
}
|
|
80
|
+
function propertyOf(input, name) {
|
|
81
|
+
return Object.entries(input.properties).find(([key]) => key === name)?.[1] ?? {};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
グローバルの --repo でも満たせるので、自分の `--repo` を持つコマンドの repo は必須として出さない。位置引数の repo は必須と出す
|
|
85
|
+
*/
|
|
86
|
+
function isRequiredField(definition, input, name) {
|
|
87
|
+
return input.required.includes(name) && (name !== 'repo' || !definition.hasOwnRepo || definition.positional.includes('repo'));
|
|
88
|
+
}
|
|
89
|
+
function positionalName(name, input, isRequired) {
|
|
90
|
+
const shown = isRequired ? `<${name}>` : `[${name}]`;
|
|
91
|
+
return isList(propertyOf(input, name)) ? `${shown}...` : shown;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
Usage 行の `[OPTIONS]` と位置引数。必須は `<名前>`、任意は `[名前]`、複数は `...`。
|
|
95
|
+
使い方の誤りの `synopsisOf` は `{名前}` の書式で golden が固定しているので、別に持つ
|
|
96
|
+
*/
|
|
97
|
+
function synopsisFrom(definition, input) {
|
|
98
|
+
const names = definition.positional.map(name => positionalName(name, input, isRequiredField(definition, input, name)));
|
|
99
|
+
return ['[OPTIONS]', ...names].join(' ');
|
|
100
|
+
}
|
|
101
|
+
function argumentRows(definition, input, defaultNotes) {
|
|
102
|
+
return definition.positional.map((name) => {
|
|
103
|
+
const isRequired = isRequiredField(definition, input, name);
|
|
104
|
+
return {
|
|
105
|
+
name: positionalName(name, input, isRequired),
|
|
106
|
+
description: describeProperty({ name, property: propertyOf(input, name), isRequired, hasNegation: false, isOption: false, defaultNote: defaultNotes.get(name) }),
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
オプションの打つ形。短い形、長い形、別名、否定形の順に `, ` でつなぎ、値を取るなら型を付ける
|
|
112
|
+
*/
|
|
113
|
+
function optionName(definition, name, property) {
|
|
114
|
+
const forms = [definition.shortFlags.get(name), flagOf(name), definition.aliases.get(name), definition.negations.get(name)];
|
|
115
|
+
const joined = forms.filter(form => form !== undefined).join(', ');
|
|
116
|
+
return property['type'] === 'boolean' ? joined : `${joined} ${metavarOf(property)}`;
|
|
117
|
+
}
|
|
118
|
+
function optionRows(definition, input, defaultNotes) {
|
|
119
|
+
const rows = Object.keys(definition.input.shape)
|
|
120
|
+
.filter(name => !definition.positional.includes(name) && Object.hasOwn(input.properties, name))
|
|
121
|
+
.map((name) => {
|
|
122
|
+
const property = propertyOf(input, name);
|
|
123
|
+
const hasNegation = definition.negations.has(name);
|
|
124
|
+
return {
|
|
125
|
+
name: optionName(definition, name, property),
|
|
126
|
+
description: describeProperty({ name, property, isRequired: isRequiredField(definition, input, name), hasNegation, isOption: true, defaultNote: defaultNotes.get(name) }),
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
return [...rows, HELP_OPTION];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
入力名を打つ形にする。位置引数は `<file>`、オプションは `--screenshot`
|
|
133
|
+
*/
|
|
134
|
+
function referenceOf(definition, name) {
|
|
135
|
+
return definition.positional.includes(name) ? `<${name}>` : flagOf(name);
|
|
136
|
+
}
|
|
137
|
+
function joinNames(names) {
|
|
138
|
+
const last = names.at(-1) ?? '';
|
|
139
|
+
return names.length < 2 ? last : `${names.slice(0, -1).join(', ')} and ${last}`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
`requires: {message: [issue, template]}` は `--message requires --issue and --template`。
|
|
143
|
+
`conflicts: [file, screenshot]` は `<file> and --screenshot cannot be used together`
|
|
144
|
+
*/
|
|
145
|
+
function constraintSentences(definition, constraint) {
|
|
146
|
+
const reference = (name) => referenceOf(definition, name);
|
|
147
|
+
const referencesOf = (names) => joinNames(names.map(name => reference(name)));
|
|
148
|
+
return 'conflicts' in constraint
|
|
149
|
+
? [`${referencesOf(constraint.conflicts)} cannot be used together`]
|
|
150
|
+
: Object.entries(constraint.requires).map(([name, required]) => `${reference(name)} requires ${referencesOf(required)}`);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
コマンドの help。notes が undefined(定義書の手書きの側が読めない)なら Constraints・Details・Examples と初期値の補足を出さない。
|
|
154
|
+
Examples の打つ形の行は折り返さないので、幅を超えることがある。幅は 40 を下限にする
|
|
155
|
+
*/
|
|
156
|
+
export function commandHelpText(definition, notes, columns) {
|
|
157
|
+
const width = helpWidth(columns);
|
|
158
|
+
const input = inputOf(definition);
|
|
159
|
+
const defaultNotes = notes?.defaultNotes ?? new Map();
|
|
160
|
+
const positional = argumentRows(definition, input, defaultNotes);
|
|
161
|
+
const constraints = notes?.constraints.flatMap(constraint => constraintSentences(definition, constraint)) ?? [];
|
|
162
|
+
const sections = [
|
|
163
|
+
usageLines(`pecot ${definition.path.join(' ')} ${synopsisFrom(definition, input)}`, width),
|
|
164
|
+
paragraph(definition.description, width),
|
|
165
|
+
...positional.length === 0 ? [] : [definitionSection('Arguments', positional, width)],
|
|
166
|
+
definitionSection('Options', optionRows(definition, input, defaultNotes), width),
|
|
167
|
+
...constraints.length === 0 ? [] : [bulletSection('Constraints', constraints, width)],
|
|
168
|
+
...notes === undefined || notes.details.length === 0 ? [] : [bulletSection('Details', notes.details, width)],
|
|
169
|
+
...notes === undefined || notes.examples.length === 0 ? [] : [examplesSection(notes.examples, width)],
|
|
170
|
+
];
|
|
171
|
+
return `${sections.join('\n\n')}\n`;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=command-help.js.map
|
|
@@ -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
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// 案内(domain/command-hint.ts)の再 export と、定義の登録。出し先は CommandIo の surface で決まり、無ければ CLI の形。
|
|
2
|
+
import { registerHintCommands } from '../domain/command-hint.js';
|
|
3
|
+
export { commandHint, globalRepositoryHint, hinted, hintedTextOf, inputHint, inputNameHint, joinHinted, placeholder } from '../domain/command-hint.js';
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- zod の型
|
|
5
|
+
export function registerCommandHints(definitions) {
|
|
6
|
+
registerHintCommands(definitions.map(definition => ({
|
|
7
|
+
path: definition.path,
|
|
8
|
+
positional: definition.positional,
|
|
9
|
+
inputs: Object.keys(definition.input.shape),
|
|
10
|
+
hasOwnRepo: definition.hasOwnRepo,
|
|
11
|
+
})));
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=command-hint.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { HintedText } from './command-hint.js';
|
|
3
|
+
import type { FailureKind } from './failure-kind.js';
|
|
4
|
+
import type { Output } from './output.js';
|
|
5
|
+
/**
|
|
6
|
+
アクティブなプロジェクトが無いときの案内
|
|
7
|
+
*/
|
|
8
|
+
export declare const NO_ACTIVE_PROJECT: HintedText;
|
|
9
|
+
/**
|
|
10
|
+
error の行を出して、原因の名前と指定の終了コード(既定は 1)で止める
|
|
11
|
+
*/
|
|
12
|
+
export declare function stopWith(out: Readonly<Output>, message: string | HintedText, kind: FailureKind, code?: number): never;
|
|
13
|
+
/**
|
|
14
|
+
アクティブなプロジェクトの設定を読む。無ければ案内付きの NO_ACTIVE_PROJECT を error の行にして止める
|
|
15
|
+
*/
|
|
16
|
+
export declare function requireActiveConfig(out: Readonly<Output>): ProjectConfig;
|
|
17
|
+
/**
|
|
18
|
+
requireActiveConfig の、案内を添えない形。無ければ NO_ACTIVE_PROJECT_PLAIN を error の行にして止める
|
|
19
|
+
*/
|
|
20
|
+
export declare function requireActiveConfigPlain(out: Readonly<Output>): ProjectConfig;
|
|
21
|
+
//# sourceMappingURL=command-stop.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { loadActiveConfig } from '../infra/config-store.js';
|
|
2
|
+
import { CommandExit } from './command-definition.js';
|
|
3
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
4
|
+
/**
|
|
5
|
+
アクティブなプロジェクトが無いときの、案内を添えない文
|
|
6
|
+
*/
|
|
7
|
+
const NO_ACTIVE_PROJECT_PLAIN = 'no active project';
|
|
8
|
+
/**
|
|
9
|
+
アクティブなプロジェクトが無いときの案内
|
|
10
|
+
*/
|
|
11
|
+
export const NO_ACTIVE_PROJECT = hinted `no active project\nrun: ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`;
|
|
12
|
+
/**
|
|
13
|
+
error の行を出して、原因の名前と指定の終了コード(既定は 1)で止める
|
|
14
|
+
*/
|
|
15
|
+
export function stopWith(out, message, kind, code = 1) {
|
|
16
|
+
out.error(message);
|
|
17
|
+
throw new CommandExit(code, kind);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
アクティブなプロジェクトの設定を読む。無ければ案内付きの NO_ACTIVE_PROJECT を error の行にして止める
|
|
21
|
+
*/
|
|
22
|
+
export function requireActiveConfig(out) {
|
|
23
|
+
return loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT, 'no-active-project');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
requireActiveConfig の、案内を添えない形。無ければ NO_ACTIVE_PROJECT_PLAIN を error の行にして止める
|
|
27
|
+
*/
|
|
28
|
+
export function requireActiveConfigPlain(out) {
|
|
29
|
+
return loadActiveConfig() ?? stopWith(out, NO_ACTIVE_PROJECT_PLAIN, 'no-active-project');
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=command-stop.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const DIRECTORY_DESCRIPTION = "Target Git repository (absolute or relative path)";
|
|
3
|
+
/**
|
|
4
|
+
在るディレクトリの実体の絶対パスを返す。誤りの文は typer 0.28(click.Path)と同じで、値は直す前の入力を repr で出す
|
|
5
|
+
*/
|
|
6
|
+
export declare const directorySchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
7
|
+
//# sourceMappingURL=directory-option.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// -D / --directory の共有スキーマ。typer の exists=True・file_okay=False・dir_okay=True・resolve_path=True と同じ検証。
|
|
2
|
+
import { accessSync, constants, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { pythonStringRepr } from '../domain/python-format.js';
|
|
5
|
+
export const DIRECTORY_DESCRIPTION = 'Target Git repository (absolute or relative path)';
|
|
6
|
+
function statOf(resolved) {
|
|
7
|
+
try {
|
|
8
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- 利用者が渡した -D の値
|
|
9
|
+
return statSync(resolved);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function isReadable(resolved) {
|
|
16
|
+
try {
|
|
17
|
+
accessSync(resolved, constants.R_OK);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function resolvedOf(value) {
|
|
25
|
+
try {
|
|
26
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- 利用者が渡した -D の値
|
|
27
|
+
return realpathSync(value);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
在るディレクトリの実体の絶対パスを返す。誤りの文は typer 0.28(click.Path)と同じで、値は直す前の入力を repr で出す
|
|
35
|
+
*/
|
|
36
|
+
export const directorySchema = z.string().transform((value, context) => {
|
|
37
|
+
const resolved = resolvedOf(value);
|
|
38
|
+
const stats = statOf(resolved);
|
|
39
|
+
const where = pythonStringRepr(value);
|
|
40
|
+
if (stats === undefined)
|
|
41
|
+
context.addIssue(`Directory ${where} does not exist.`);
|
|
42
|
+
else if (stats.isFile())
|
|
43
|
+
context.addIssue(`Directory ${where} is a file.`);
|
|
44
|
+
else if (!isReadable(resolved))
|
|
45
|
+
context.addIssue(`Directory ${where} is not readable.`);
|
|
46
|
+
return resolved;
|
|
47
|
+
}).describe(DIRECTORY_DESCRIPTION);
|
|
48
|
+
//# sourceMappingURL=directory-option.js.map
|
|
@@ -0,0 +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'];
|
|
2
|
+
export type FailureKind = typeof FAILURE_KINDS[number];
|
|
3
|
+
//# sourceMappingURL=failure-kind.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// 失敗の原因の名前。MCP の結果の kind に入る。定義書の exit_status[].kind の集合と一致させる(tests/failure-kinds-definition.test.ts)。
|
|
2
|
+
// eslint-disable-next-line no-restricted-syntax -- 配列から型を作るための as const
|
|
3
|
+
export const FAILURE_KINDS = [
|
|
4
|
+
'invalid-input',
|
|
5
|
+
'aborted',
|
|
6
|
+
'github-auth',
|
|
7
|
+
'github-not-found',
|
|
8
|
+
'github-rate-limit',
|
|
9
|
+
'github-api',
|
|
10
|
+
'config-invalid',
|
|
11
|
+
'project-root-not-found',
|
|
12
|
+
'session-directory-unresolved',
|
|
13
|
+
'no-active-project',
|
|
14
|
+
'project-not-found',
|
|
15
|
+
'not-initialized',
|
|
16
|
+
'already-exists',
|
|
17
|
+
'repo-not-in-project',
|
|
18
|
+
'repo-setting-missing',
|
|
19
|
+
'repo-mismatch',
|
|
20
|
+
'git-unresolved',
|
|
21
|
+
'not-on-board',
|
|
22
|
+
'status-not-configured',
|
|
23
|
+
'guard-blocked',
|
|
24
|
+
'not-ready',
|
|
25
|
+
'dependency-rejected',
|
|
26
|
+
'dependency-unreadable',
|
|
27
|
+
'order-conflict',
|
|
28
|
+
'content-invalid',
|
|
29
|
+
'preflight-failed',
|
|
30
|
+
'pr-state',
|
|
31
|
+
'partial-failure',
|
|
32
|
+
'other',
|
|
33
|
+
];
|
|
34
|
+
//# sourceMappingURL=failure-kind.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FailureKind } from './failure-kind.js';
|
|
2
|
+
import type { CommandIo } from './registry.js';
|
|
3
|
+
export declare const FAILURE_EXIT_CODE = 1;
|
|
4
|
+
/**
|
|
5
|
+
最上位で error の行にできる例外か
|
|
6
|
+
*/
|
|
7
|
+
export declare function isReportableFailure(error: unknown): error is Error;
|
|
8
|
+
export declare function reportFailure(error: Readonly<Error>, io: CommandIo): void;
|
|
9
|
+
export declare const KIND_BY_CLASS: readonly (readonly [abstract new (...arguments_: never[]) => unknown, FailureKind])[];
|
|
10
|
+
/**
|
|
11
|
+
例外のクラスから失敗の原因の名前を決める。表に無いものは other
|
|
12
|
+
*/
|
|
13
|
+
export declare function kindOfFailure(error: unknown): FailureKind;
|
|
14
|
+
/**
|
|
15
|
+
コマンドの実行で捕まえた例外を、終了コードにする。CLI の runCli と MCP のツールの呼び出しが共有する。
|
|
16
|
+
使い方の誤りは枠付きで stderr に出して 2。確認の中止は Aborted. で 1。報告できる失敗は error の行で 1。それ以外は伝える
|
|
17
|
+
*/
|
|
18
|
+
export declare function exitCodeOfFailure(error: unknown, io: CommandIo, width: number): number;
|
|
19
|
+
//# sourceMappingURL=failure.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// コマンドが捕まえなかった例外を、最上位で `error: <message>` の行と終了コード 1 にする(Python の PecotError の網と同じ)。
|
|
2
|
+
// 値の誤り(InvalidValueError)と OS のエラーも同じ行にする。上のどれでもない例外はプログラムの誤りなので、伝える。
|
|
3
|
+
import { ConfigError } from '../domain/config.js';
|
|
4
|
+
import { PecotError, InvalidValueError, ProjectRootNotFoundError } from '../domain/errors.js';
|
|
5
|
+
import { DependenciesUnsupportedError, GitHubAPIError, GitHubAuthError, GitHubNotFoundError, GitHubRateLimitError } from '../infra/github/errors.js';
|
|
6
|
+
import { OsError } from '../infra/os-error.js';
|
|
7
|
+
import { hintedTextOf } from './command-hint.js';
|
|
8
|
+
import { AbortedError, createOutput, reportAborted } from './output.js';
|
|
9
|
+
import { formatUsageError, USAGE_EXIT_CODE, UsageError } from './usage-error.js';
|
|
10
|
+
export const FAILURE_EXIT_CODE = 1;
|
|
11
|
+
/**
|
|
12
|
+
最上位で error の行にできる例外か
|
|
13
|
+
*/
|
|
14
|
+
export function isReportableFailure(error) {
|
|
15
|
+
return error instanceof PecotError || error instanceof InvalidValueError || error instanceof OsError;
|
|
16
|
+
}
|
|
17
|
+
export function reportFailure(error, io) {
|
|
18
|
+
createOutput(false, io).error(hintedTextOf(error) ?? error.message);
|
|
19
|
+
}
|
|
20
|
+
// 子クラスを親より先に並べる
|
|
21
|
+
export const KIND_BY_CLASS = [
|
|
22
|
+
[UsageError, 'invalid-input'],
|
|
23
|
+
[InvalidValueError, 'invalid-input'],
|
|
24
|
+
[AbortedError, 'aborted'],
|
|
25
|
+
[GitHubAuthError, 'github-auth'],
|
|
26
|
+
[GitHubNotFoundError, 'github-not-found'],
|
|
27
|
+
[GitHubRateLimitError, 'github-rate-limit'],
|
|
28
|
+
[DependenciesUnsupportedError, 'dependency-rejected'],
|
|
29
|
+
[GitHubAPIError, 'github-api'],
|
|
30
|
+
[ConfigError, 'config-invalid'],
|
|
31
|
+
[ProjectRootNotFoundError, 'project-root-not-found'],
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
例外のクラスから失敗の原因の名前を決める。表に無いものは other
|
|
35
|
+
*/
|
|
36
|
+
export function kindOfFailure(error) {
|
|
37
|
+
return KIND_BY_CLASS.find(([type]) => error instanceof type)?.[1] ?? 'other';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
コマンドの実行で捕まえた例外を、終了コードにする。CLI の runCli と MCP のツールの呼び出しが共有する。
|
|
41
|
+
使い方の誤りは枠付きで stderr に出して 2。確認の中止は Aborted. で 1。報告できる失敗は error の行で 1。それ以外は伝える
|
|
42
|
+
*/
|
|
43
|
+
export function exitCodeOfFailure(error, io, width) {
|
|
44
|
+
if (error instanceof UsageError) {
|
|
45
|
+
io.failureKind?.(kindOfFailure(error));
|
|
46
|
+
io.stderr(formatUsageError(error, width));
|
|
47
|
+
return USAGE_EXIT_CODE;
|
|
48
|
+
}
|
|
49
|
+
if (error instanceof AbortedError) {
|
|
50
|
+
io.failureKind?.(kindOfFailure(error));
|
|
51
|
+
return reportAborted(io);
|
|
52
|
+
}
|
|
53
|
+
if (!isReportableFailure(error))
|
|
54
|
+
throw error;
|
|
55
|
+
io.failureKind?.(kindOfFailure(error));
|
|
56
|
+
reportFailure(error, io);
|
|
57
|
+
return FAILURE_EXIT_CODE;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=failure.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
word に近い候補を、近い順に最大 3 件返す。近さが同じなら、文字列の大きい方が先。
|
|
3
|
+
Python の heapq.nlargest が (近さ, 候補) の組で比べるため
|
|
4
|
+
*/
|
|
5
|
+
export declare function compareCodePoints(left: string, right: string): number;
|
|
6
|
+
export declare function closeMatches(word: string, possibilities: readonly string[]): readonly string[];
|
|
7
|
+
//# sourceMappingURL=fuzzy.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 近い語の候補。Python の difflib.get_close_matches(n=3、cutoff=0.6)を写す。
|
|
2
|
+
// click の `Possible options` と `Did you mean` の元になる。
|
|
3
|
+
import { splitCodePoints } from '../domain/python-format.js';
|
|
4
|
+
const MAX_MATCHES = 3;
|
|
5
|
+
const CUTOFF = 0.6;
|
|
6
|
+
/**
|
|
7
|
+
b の各文字が現れる位置
|
|
8
|
+
*/
|
|
9
|
+
function indexPositions(characters) {
|
|
10
|
+
const positions = new Map();
|
|
11
|
+
for (const [index, character] of characters.entries()) {
|
|
12
|
+
positions.set(character, [...positions.get(character) ?? [], index]);
|
|
13
|
+
}
|
|
14
|
+
return positions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
a の aStart 以上 aEnd 未満、b の bStart 以上 bEnd 未満で、最長の一致を探す。同じ長さなら a で最初、次に b で最初のもの
|
|
18
|
+
*/
|
|
19
|
+
function longestMatch(a, positions, range) {
|
|
20
|
+
let best = { aStart: range.aStart, bStart: range.bStart, size: 0 };
|
|
21
|
+
let previous = new Map();
|
|
22
|
+
for (let index = range.aStart; index < range.aEnd; index += 1) {
|
|
23
|
+
const current = new Map();
|
|
24
|
+
const candidates = (positions.get(a.at(index) ?? '') ?? []).filter(position => position >= range.bStart && position < range.bEnd);
|
|
25
|
+
for (const position of candidates) {
|
|
26
|
+
const size = (previous.get(position - 1) ?? 0) + 1;
|
|
27
|
+
current.set(position, size);
|
|
28
|
+
if (size > best.size)
|
|
29
|
+
best = { aStart: index - size + 1, bStart: position - size + 1, size };
|
|
30
|
+
}
|
|
31
|
+
previous = current;
|
|
32
|
+
}
|
|
33
|
+
return best;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
SequenceMatcher.ratio() と同じ。2 * 一致した文字数 / 全文字数
|
|
37
|
+
*/
|
|
38
|
+
function ratio(a, b) {
|
|
39
|
+
const total = a.length + b.length;
|
|
40
|
+
if (total === 0)
|
|
41
|
+
return 1;
|
|
42
|
+
const positions = indexPositions(b);
|
|
43
|
+
const queue = [{ aStart: 0, aEnd: a.length, bStart: 0, bEnd: b.length }];
|
|
44
|
+
let matched = 0;
|
|
45
|
+
for (let range = queue.pop(); range !== undefined; range = queue.pop()) {
|
|
46
|
+
const match = longestMatch(a, positions, range);
|
|
47
|
+
if (match.size === 0)
|
|
48
|
+
continue;
|
|
49
|
+
matched += match.size;
|
|
50
|
+
if (range.aStart < match.aStart && range.bStart < match.bStart) {
|
|
51
|
+
queue.push({ ...range, aEnd: match.aStart, bEnd: match.bStart });
|
|
52
|
+
}
|
|
53
|
+
const aAfter = match.aStart + match.size;
|
|
54
|
+
const bAfter = match.bStart + match.size;
|
|
55
|
+
if (aAfter < range.aEnd && bAfter < range.bEnd)
|
|
56
|
+
queue.push({ ...range, aStart: aAfter, bStart: bAfter });
|
|
57
|
+
}
|
|
58
|
+
return (2 * matched) / total;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
word に近い候補を、近い順に最大 3 件返す。近さが同じなら、文字列の大きい方が先。
|
|
62
|
+
Python の heapq.nlargest が (近さ, 候補) の組で比べるため
|
|
63
|
+
*/
|
|
64
|
+
export function compareCodePoints(left, right) {
|
|
65
|
+
if (left === right)
|
|
66
|
+
return 0;
|
|
67
|
+
return left < right ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
export function closeMatches(word, possibilities) {
|
|
70
|
+
const wordCharacters = splitCodePoints(word);
|
|
71
|
+
const scored = possibilities
|
|
72
|
+
.map(candidate => ({ candidate, score: ratio(splitCodePoints(candidate), wordCharacters) }))
|
|
73
|
+
.filter(entry => entry.score >= CUTOFF);
|
|
74
|
+
const ordered = scored.toSorted((left, right) => {
|
|
75
|
+
return left.score === right.score ? compareCodePoints(right.candidate, left.candidate) : right.score - left.score;
|
|
76
|
+
});
|
|
77
|
+
return ordered.slice(0, MAX_MATCHES).map(entry => entry.candidate);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=fuzzy.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import { GitHubClient } from '../infra/github/index.js';
|
|
3
|
+
import type { Output } from './output.js';
|
|
4
|
+
/**
|
|
5
|
+
host 向けのクライアントを作る。host が undefined なら既定のホスト。トークンが無いときは GitHubAuthError を投げる
|
|
6
|
+
*/
|
|
7
|
+
export declare function createGitHubClient(out: Readonly<Output>, host: string | undefined): GitHubClient;
|
|
8
|
+
/**
|
|
9
|
+
GitHub の失敗(GitHubAPIError と、接続の失敗の TransportFailure)なら、その文を返す。それ以外は投げ直す
|
|
10
|
+
*/
|
|
11
|
+
export declare function apiFailureMessage(error: unknown): string;
|
|
12
|
+
/**
|
|
13
|
+
クライアントを作る。認証などの失敗は error の行にして終了コード 1 で止める
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeClient(out: Readonly<Output>, config: Readonly<ProjectConfig>): GitHubClient;
|
|
16
|
+
//# sourceMappingURL=github-client.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TransportFailure } from '../infra/github/client.js';
|
|
2
|
+
import { GitHubClient } from '../infra/github/index.js';
|
|
3
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
4
|
+
import { stopWith } from './command-stop.js';
|
|
5
|
+
import { kindOfFailure } from './failure.js';
|
|
6
|
+
/**
|
|
7
|
+
host 向けのクライアントを作る。host が undefined なら既定のホスト。トークンが無いときは GitHubAuthError を投げる
|
|
8
|
+
*/
|
|
9
|
+
export function createGitHubClient(out, host) {
|
|
10
|
+
return new GitHubClient({ host, diagnostics: out });
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
GitHub の失敗(GitHubAPIError と、接続の失敗の TransportFailure)なら、その文を返す。それ以外は投げ直す
|
|
14
|
+
*/
|
|
15
|
+
export function apiFailureMessage(error) {
|
|
16
|
+
if (error instanceof GitHubAPIError || error instanceof TransportFailure)
|
|
17
|
+
return error.message;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
クライアントを作る。認証などの失敗は error の行にして終了コード 1 で止める
|
|
22
|
+
*/
|
|
23
|
+
export function makeClient(out, config) {
|
|
24
|
+
try {
|
|
25
|
+
return createGitHubClient(out, config.host);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (!(error instanceof GitHubAPIError))
|
|
29
|
+
throw error;
|
|
30
|
+
return stopWith(out, error.message, kindOfFailure(error));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=github-client.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UsageContext } from './usage-error.js';
|
|
2
|
+
/**
|
|
3
|
+
--repo の値が不正なときの文。detail は owner/repo の解析が投げた例外の文
|
|
4
|
+
*/
|
|
5
|
+
export declare function invalidRepositoryMessage(detail: string): string;
|
|
6
|
+
export declare const ROOT_USAGE: UsageContext;
|
|
7
|
+
/**
|
|
8
|
+
eager なオプション。click と同じく、先に指定された方だけを実行する
|
|
9
|
+
*/
|
|
10
|
+
export type EagerOption = 'help' | 'version';
|
|
11
|
+
export interface GlobalOptions {
|
|
12
|
+
readonly eager: EagerOption | undefined;
|
|
13
|
+
readonly repo: string | undefined;
|
|
14
|
+
readonly showRepo: boolean;
|
|
15
|
+
/**
|
|
16
|
+
コマンド名から後ろの引数
|
|
17
|
+
*/
|
|
18
|
+
readonly rest: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
root の引数を解析する。誤りは UsageError にする。
|
|
22
|
+
--repo の値が欠けた誤りと値を取らないオプションに値を付けた誤りは、click と同じく Usage 行を付けない
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseGlobalOptions(argv: readonly string[]): GlobalOptions;
|
|
25
|
+
//# sourceMappingURL=global-options.d.ts.map
|