@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,153 @@
|
|
|
1
|
+
// `pecot tracker sync security` の本体。cli/commands/security.py の移植。open の Tracker の一覧を、open の security alert に書き直す。
|
|
2
|
+
// 途中で抜ける箇所は CommandExit を投げ、tracker sync の定義が終了コードにする。
|
|
3
|
+
import { ALERT_KINDS, kindLabel, listOpenAlerts, SecurityAlertError } from '../domain/security-alerts.js';
|
|
4
|
+
import { ALERT_LABEL, buildTrackerTitle, maxPriority, normalizeAlerts, parseTrackerEntries, planTracker, renderTrackerBody, TRACKER_PATTERN } from '../domain/security-tracker.js';
|
|
5
|
+
import { findTracker } from '../domain/tracker-body.js';
|
|
6
|
+
import { createDependabotSource } from '../infra/github/dependabot-source.js';
|
|
7
|
+
import { requireNumber } from '../infra/github/payload.js';
|
|
8
|
+
import { createScanAlertSource } from '../infra/github/security-alerts-source.js';
|
|
9
|
+
import { CommandExit } from './command-definition.js';
|
|
10
|
+
import { stopWith } from './command-stop.js';
|
|
11
|
+
import { kindOfFailure } from './failure.js';
|
|
12
|
+
import { makeClient } from './github-client.js';
|
|
13
|
+
import { createIssue, putOnBoard } from './issue-board.js';
|
|
14
|
+
import { createOutput } from './output.js';
|
|
15
|
+
import { apiErrorDetail, isBodyUnchanged, loadTarget, settle, todayUtc, warnExtraTrackers } from './tracker-sync.js';
|
|
16
|
+
// 一覧を取れなかった種類と無効の種類は行を触らず、足さない。終了コード 1 にするのは取れなかった種類だけ
|
|
17
|
+
async function fetchOpenAlerts(out, sources, host, owner, repository) {
|
|
18
|
+
const alerts = new Map();
|
|
19
|
+
const failed = new Set();
|
|
20
|
+
const disabled = new Set();
|
|
21
|
+
for (const kind of ALERT_KINDS) {
|
|
22
|
+
let raws;
|
|
23
|
+
try {
|
|
24
|
+
raws = await listOpenAlerts(sources, kind, owner, repository);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (!(error instanceof SecurityAlertError))
|
|
28
|
+
throw error;
|
|
29
|
+
failed.add(kind);
|
|
30
|
+
out.error(`could not list ${kindLabel(kind)} alerts (leaving its rows untouched): ${error.message}`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (raws === undefined) {
|
|
34
|
+
disabled.add(kind);
|
|
35
|
+
settle(out, { verb: 'skip', target: `${kindLabel(kind)} alerts (feature disabled)` });
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
alerts.set(kind, normalizeAlerts(kind, raws, host, owner, repository));
|
|
39
|
+
}
|
|
40
|
+
return { alerts, failed, disabled };
|
|
41
|
+
}
|
|
42
|
+
function operationsOf(plan, tracker, title, isUnchanged) {
|
|
43
|
+
if (tracker === undefined) {
|
|
44
|
+
if (!plan.create)
|
|
45
|
+
return { create: [{ verb: 'skip', target: 'Tracker creation' }], rewrite: [] };
|
|
46
|
+
const created = [{ verb: 'create', target: `Tracker "${title}" with priority ${String(maxPriority(plan.entries))}` }];
|
|
47
|
+
for (const entry of plan.entries)
|
|
48
|
+
created.push({ verb: 'add', target: `${entry.kind} #${String(entry.number)} to new Tracker` });
|
|
49
|
+
return { create: created, rewrite: [] };
|
|
50
|
+
}
|
|
51
|
+
const label = `#${String(tracker)}`;
|
|
52
|
+
if (isUnchanged)
|
|
53
|
+
return { create: [], rewrite: [{ verb: 'unchanged', target: `Tracker ${label}` }] };
|
|
54
|
+
const rewrite = [
|
|
55
|
+
...plan.added.map((entry) => ({ verb: 'add', target: `${entry.kind} #${String(entry.number)} to Tracker ${label}` })),
|
|
56
|
+
...plan.removed.map((entry) => ({ verb: 'remove', target: `${entry.kind} #${String(entry.number)} from Tracker ${label}` })),
|
|
57
|
+
];
|
|
58
|
+
return { create: [], rewrite: rewrite.length === 0 ? [{ verb: 'update', target: `Tracker ${label} body` }] : rewrite };
|
|
59
|
+
}
|
|
60
|
+
// Tracker を作る・書き直す・ボードに載せる。失敗の数を返す。
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は可変
|
|
62
|
+
async function applyChanges(out, input) {
|
|
63
|
+
const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged } = input;
|
|
64
|
+
const priority = maxPriority(plan.entries);
|
|
65
|
+
try {
|
|
66
|
+
if (number === undefined) {
|
|
67
|
+
if (!plan.create) {
|
|
68
|
+
for (const operation of stages.create)
|
|
69
|
+
out.done(operation);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
const issue = await createIssue(client, owner, repository, title, body, [ALERT_LABEL]);
|
|
73
|
+
for (const operation of stages.create)
|
|
74
|
+
out.done(operation);
|
|
75
|
+
await putOnBoard(client, config, owner, repository, requireNumber(issue['number'], 'number'), priority, { onlyIfEmpty: false });
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
let failures = 0;
|
|
79
|
+
let isUpdated = true;
|
|
80
|
+
if (!isUnchanged) {
|
|
81
|
+
try {
|
|
82
|
+
await client.updateIssueBody(owner, repository, number, body);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const text = apiErrorDetail(error);
|
|
86
|
+
if (text === undefined)
|
|
87
|
+
throw error;
|
|
88
|
+
// 422 を含む。本文は書き直されていないので、次の実行でやり直す
|
|
89
|
+
failures += 1;
|
|
90
|
+
isUpdated = false;
|
|
91
|
+
out.error(`could not update Tracker #${String(number)} body: ${text}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (isUpdated)
|
|
95
|
+
for (const operation of stages.rewrite)
|
|
96
|
+
out.done(operation);
|
|
97
|
+
// 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
|
|
98
|
+
await putOnBoard(client, config, owner, repository, number, priority, { onlyIfEmpty: true });
|
|
99
|
+
return failures;
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const text = apiErrorDetail(error);
|
|
103
|
+
if (text === undefined)
|
|
104
|
+
throw error;
|
|
105
|
+
out.error(`Tracker: ${text}`);
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
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
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { TrackerIssue } from '../domain/tracker-body.js';
|
|
3
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
4
|
+
import type { Operation, Output } from './output.js';
|
|
5
|
+
/**
|
|
6
|
+
API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
|
|
7
|
+
*/
|
|
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
|
+
}
|
|
16
|
+
export interface SyncTarget {
|
|
17
|
+
readonly config: ProjectConfig;
|
|
18
|
+
readonly owner: string;
|
|
19
|
+
readonly repository: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
|
|
23
|
+
設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
|
|
24
|
+
*/
|
|
25
|
+
export declare function loadTarget(out: Readonly<Output>, explicitRepository: string | undefined): SyncTarget;
|
|
26
|
+
/**
|
|
27
|
+
複数の Tracker が open のときに警告する(番号が最小のものを使い、ほかは閉じない)
|
|
28
|
+
*/
|
|
29
|
+
export declare function warnExtraTrackers(out: Readonly<Output>, tracker: Readonly<TrackerIssue> | undefined, others: readonly number[]): void;
|
|
30
|
+
/**
|
|
31
|
+
API エラーと通信エラーの文。ほかの例外なら undefined
|
|
32
|
+
*/
|
|
33
|
+
export declare function apiErrorDetail(error: unknown): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
書き直した本文が今の本文と同じか。比べるのは改行を `\n` に直したものどうし
|
|
36
|
+
*/
|
|
37
|
+
export declare function isBodyUnchanged(body: string, existingBody: string | undefined): boolean;
|
|
38
|
+
/**
|
|
39
|
+
Tracker の題に入れる、立てた日(UTC)の YYYY-MM-DD
|
|
40
|
+
*/
|
|
41
|
+
export declare function todayUtc(now: Readonly<Date>): string;
|
|
42
|
+
/**
|
|
43
|
+
操作を段ごとに分けたもの。作る段と書き直す段は 2 つの sync に共通
|
|
44
|
+
*/
|
|
45
|
+
export interface SyncStages {
|
|
46
|
+
readonly create: readonly Operation[];
|
|
47
|
+
readonly rewrite: readonly Operation[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
Tracker を反映する処理に渡す共通の入力
|
|
51
|
+
*/
|
|
52
|
+
export interface SyncApplyContext {
|
|
53
|
+
readonly client: GitHubClient;
|
|
54
|
+
readonly config: ProjectConfig;
|
|
55
|
+
readonly owner: string;
|
|
56
|
+
readonly repository: string;
|
|
57
|
+
readonly title: string;
|
|
58
|
+
readonly body: string;
|
|
59
|
+
/**
|
|
60
|
+
使う Tracker の番号。open の Tracker が無ければ undefined
|
|
61
|
+
*/
|
|
62
|
+
readonly number: number | undefined;
|
|
63
|
+
readonly isUnchanged: boolean;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=tracker-sync.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// tracker sync と session finish が共有する出力の補助。
|
|
2
|
+
import { TransportFailure } from '../infra/github/client.js';
|
|
3
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
4
|
+
import { requireActiveConfigPlain } from './command-stop.js';
|
|
5
|
+
import { requireReleaseTargetRepository } from './release.js';
|
|
6
|
+
/**
|
|
7
|
+
API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
|
|
8
|
+
*/
|
|
9
|
+
export function settle(out, operation) {
|
|
10
|
+
out.planned(operation);
|
|
11
|
+
out.done(operation);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
|
|
15
|
+
設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
|
|
16
|
+
*/
|
|
17
|
+
export function loadTarget(out, explicitRepository) {
|
|
18
|
+
const target = requireReleaseTargetRepository(undefined, explicitRepository, out);
|
|
19
|
+
const config = requireActiveConfigPlain(out);
|
|
20
|
+
return { config, owner: target.owner, repository: target.repository };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
複数の Tracker が open のときに警告する(番号が最小のものを使い、ほかは閉じない)
|
|
24
|
+
*/
|
|
25
|
+
export function warnExtraTrackers(out, tracker, others) {
|
|
26
|
+
if (others.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
const listed = others.map(number => `#${String(number)}`).join(', ');
|
|
29
|
+
const used = tracker === undefined ? 'none' : `#${String(tracker.number)}`;
|
|
30
|
+
out.warning(`multiple open Trackers; using ${used} (lowest number) and leaving ${listed} open`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
API エラーと通信エラーの文。ほかの例外なら undefined
|
|
34
|
+
*/
|
|
35
|
+
export function apiErrorDetail(error) {
|
|
36
|
+
return error instanceof GitHubAPIError || error instanceof TransportFailure ? error.message : undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
書き直した本文が今の本文と同じか。比べるのは改行を `\n` に直したものどうし
|
|
40
|
+
*/
|
|
41
|
+
export function isBodyUnchanged(body, existingBody) {
|
|
42
|
+
return existingBody?.replaceAll('\r\n', '\n') === body;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
Tracker の題に入れる、立てた日(UTC)の YYYY-MM-DD
|
|
46
|
+
*/
|
|
47
|
+
export function todayUtc(now) {
|
|
48
|
+
return now.toISOString().slice(0, 10);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=tracker-sync.js.map
|
|
@@ -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
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseError } from '../domain/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
誤りが起きたコマンド。
|
|
4
|
+
synopsis は Usage 行の `pecot <path>` の後ろに続く書式。
|
|
5
|
+
例は `[OPTIONS] {issue_ref}`。グループなら `[OPTIONS] COMMAND [ARGS]...` にする
|
|
6
|
+
*/
|
|
7
|
+
export interface UsageContext {
|
|
8
|
+
readonly commandPath: readonly string[];
|
|
9
|
+
readonly synopsis: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
使い方の誤り。終了コードは 2。context が無いときは枠だけを出す
|
|
13
|
+
*/
|
|
14
|
+
export declare class UsageError extends BaseError {
|
|
15
|
+
readonly context: UsageContext | undefined;
|
|
16
|
+
constructor(message: string, context?: Readonly<UsageContext>);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
コマンドとグループの Usage 行に出す書式
|
|
20
|
+
*/
|
|
21
|
+
export declare const COMMAND_SYNOPSIS = "[OPTIONS] COMMAND [ARGS]...";
|
|
22
|
+
export declare const USAGE_EXIT_CODE = 2;
|
|
23
|
+
export declare function missingArgumentMessage(name: string): string;
|
|
24
|
+
/**
|
|
25
|
+
names は長い形・短い形の順(例: `['--directory', '-D']`)
|
|
26
|
+
*/
|
|
27
|
+
export declare function missingOptionMessage(names: readonly string[]): string;
|
|
28
|
+
/**
|
|
29
|
+
possibilities は近い長いオプション。あれば、辞書順に並べて案内を付ける(1 件でも同じ形)
|
|
30
|
+
*/
|
|
31
|
+
export declare function noSuchOptionMessage(name: string, possibilities?: readonly string[]): string;
|
|
32
|
+
/**
|
|
33
|
+
possibilities は近いコマンド名。近い順のまま案内する
|
|
34
|
+
*/
|
|
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;
|
|
40
|
+
export declare function optionRequiresArgumentMessage(name: string): string;
|
|
41
|
+
export declare function optionTakesNoValueMessage(name: string): string;
|
|
42
|
+
/**
|
|
43
|
+
names はオプションなら長い形・短い形の順、位置引数なら入力の名前
|
|
44
|
+
*/
|
|
45
|
+
export declare function invalidValueMessage(names: string | readonly string[], detail: string): string;
|
|
46
|
+
export declare const MISSING_COMMAND_MESSAGE = "Missing command.";
|
|
47
|
+
/**
|
|
48
|
+
stderr に書く文字列を作る。Usage 行、Try 行、枠付きの Error の順。width は枠の幅(既定は 80)
|
|
49
|
+
*/
|
|
50
|
+
export declare function formatUsageError(error: Readonly<UsageError>, width?: number): string;
|
|
51
|
+
//# sourceMappingURL=usage-error.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// 使い方の誤りの表示。Python の CLI が出していた click の Usage 行・Try 行と、枠付きの Error を写す。
|
|
2
|
+
// 全コマンドの共通部。コマンドの path と引数の書式は、呼び出す側が渡す。
|
|
3
|
+
import { BaseError } from '../domain/errors.js';
|
|
4
|
+
import { compareCodePoints } from './fuzzy.js';
|
|
5
|
+
import { renderPanel, wrapText } from './rich-panel.js';
|
|
6
|
+
const PROGRAM = 'pecot';
|
|
7
|
+
const DEFAULT_OUTPUT_WIDTH = 80;
|
|
8
|
+
/**
|
|
9
|
+
使い方の誤り。終了コードは 2。context が無いときは枠だけを出す
|
|
10
|
+
*/
|
|
11
|
+
export class UsageError extends BaseError {
|
|
12
|
+
context;
|
|
13
|
+
constructor(message, context) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.context = context;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
コマンドとグループの Usage 行に出す書式
|
|
20
|
+
*/
|
|
21
|
+
export const COMMAND_SYNOPSIS = '[OPTIONS] COMMAND [ARGS]...';
|
|
22
|
+
export const USAGE_EXIT_CODE = 2;
|
|
23
|
+
export function missingArgumentMessage(name) {
|
|
24
|
+
return `Missing argument '${name}'.`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
names は長い形・短い形の順(例: `['--directory', '-D']`)
|
|
28
|
+
*/
|
|
29
|
+
export function missingOptionMessage(names) {
|
|
30
|
+
return `Missing option ${names.map(name => `'${name}'`).join(' / ')}.`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
possibilities は近い長いオプション。あれば、辞書順に並べて案内を付ける(1 件でも同じ形)
|
|
34
|
+
*/
|
|
35
|
+
export function noSuchOptionMessage(name, possibilities = []) {
|
|
36
|
+
const hint = possibilities.length === 0 ? '' : ` (Possible options: ${possibilities.toSorted(compareCodePoints).join(', ')})`;
|
|
37
|
+
return `No such option: ${name}${hint}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
possibilities は近いコマンド名。近い順のまま案内する
|
|
41
|
+
*/
|
|
42
|
+
export function noSuchCommandMessage(name, possibilities = []) {
|
|
43
|
+
const hint = possibilities.length === 0 ? '' : ` Did you mean ${possibilities.map(candidate => `'${candidate}'`).join(', ')}?`;
|
|
44
|
+
return `No such command '${name}'.${hint}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
古い名前のコマンドを打たれたときの案内。名前はどちらも空白でつないだ path
|
|
48
|
+
*/
|
|
49
|
+
export function renamedCommandMessage(oldName, newName) {
|
|
50
|
+
return `'${oldName}' was renamed to '${newName}'.`;
|
|
51
|
+
}
|
|
52
|
+
export function optionRequiresArgumentMessage(name) {
|
|
53
|
+
return `Option '${name}' requires an argument.`;
|
|
54
|
+
}
|
|
55
|
+
export function optionTakesNoValueMessage(name) {
|
|
56
|
+
return `Option '${name}' does not take a value.`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
names はオプションなら長い形・短い形の順、位置引数なら入力の名前
|
|
60
|
+
*/
|
|
61
|
+
export function invalidValueMessage(names, detail) {
|
|
62
|
+
const quoted = (typeof names === 'string' ? [names] : names).map(name => `'${name}'`).join(' / ');
|
|
63
|
+
return `Invalid value for ${quoted}: ${detail}`;
|
|
64
|
+
}
|
|
65
|
+
export const MISSING_COMMAND_MESSAGE = 'Missing command.';
|
|
66
|
+
function headerLines(context, width) {
|
|
67
|
+
const program = [PROGRAM, ...context.commandPath].join(' ');
|
|
68
|
+
const usage = wrapText(`Usage: ${program} ${context.synopsis}`, width).map(line => line.trimEnd());
|
|
69
|
+
return `${[...usage, `Try '${program} --help' for help.`].join('\n')}\n`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
stderr に書く文字列を作る。Usage 行、Try 行、枠付きの Error の順。width は枠の幅(既定は 80)
|
|
73
|
+
*/
|
|
74
|
+
export function formatUsageError(error, width = DEFAULT_OUTPUT_WIDTH) {
|
|
75
|
+
const header = error.context === undefined ? '' : headerLines(error.context, width);
|
|
76
|
+
return `${header}${renderPanel('Error', error.message, width)}`;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=usage-error.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
CLI の値の形。真偽値は値を取らない旗、list は繰り返して渡す
|
|
4
|
+
*/
|
|
5
|
+
export type FlagKind = 'boolean' | 'list' | 'value';
|
|
6
|
+
export interface IntegerType {
|
|
7
|
+
readonly type: 'integer';
|
|
8
|
+
readonly min: number | undefined;
|
|
9
|
+
readonly max: number | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface FloatType {
|
|
12
|
+
readonly type: 'float';
|
|
13
|
+
readonly min: number | undefined;
|
|
14
|
+
readonly max: number | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
選択肢の型(z.enum)。値は選択肢のどれかに一致しなければならない
|
|
18
|
+
*/
|
|
19
|
+
export interface ChoiceType {
|
|
20
|
+
readonly type: 'choice';
|
|
21
|
+
readonly choices: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
export type ValueType = ChoiceType | FloatType | IntegerType | {
|
|
24
|
+
readonly type: 'string';
|
|
25
|
+
};
|
|
26
|
+
export declare function flagKindOf(schema: z.core.$ZodType): FlagKind;
|
|
27
|
+
/**
|
|
28
|
+
値 1 つの型。list は要素の型
|
|
29
|
+
*/
|
|
30
|
+
export declare function valueTypeOf(schema: z.core.$ZodType): ValueType;
|
|
31
|
+
/**
|
|
32
|
+
範囲の文。両側なら `0<=x<=20`、片側なら `x>=1` か `x<=9`
|
|
33
|
+
*/
|
|
34
|
+
export declare function describeRange(min: number | undefined, max: number | undefined): string;
|
|
35
|
+
export type Conversion = {
|
|
36
|
+
readonly isValid: true;
|
|
37
|
+
readonly value: unknown;
|
|
38
|
+
} | {
|
|
39
|
+
readonly isValid: false;
|
|
40
|
+
readonly message: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
コマンドラインの文字列を、型に応じて変換する。誤りの文は typer 同梱の click と同じ
|
|
44
|
+
*/
|
|
45
|
+
export declare function convertValue(text: string, valueType: ValueType): Conversion;
|
|
46
|
+
//# sourceMappingURL=value-types.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- zod の型は readonly にできない */
|
|
2
|
+
// オプションと位置引数の型。zod のスキーマの形から、click と同じ型変換と誤りの文を決める。
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { parsePythonInteger, pythonFloatRepr, pythonStringRepr } from '../domain/python-format.js';
|
|
5
|
+
/**
|
|
6
|
+
包んでいる側のスキーマ。Optional・Default・Nullable・Readonly・Prefault・Catch・NonOptional は中を見る。
|
|
7
|
+
Pipe は、後段が transform なら前段を、そうでなければ後段を見る
|
|
8
|
+
*/
|
|
9
|
+
function innerSchemaOf(schema) {
|
|
10
|
+
if (schema instanceof z.ZodOptional || schema instanceof z.ZodDefault || schema instanceof z.ZodNullable
|
|
11
|
+
|| schema instanceof z.ZodReadonly || schema instanceof z.ZodPrefault || schema instanceof z.ZodCatch
|
|
12
|
+
|| schema instanceof z.ZodNonOptional)
|
|
13
|
+
return schema.unwrap();
|
|
14
|
+
if (schema instanceof z.ZodPipe)
|
|
15
|
+
return schema.out instanceof z.ZodTransform ? schema.in : schema.out;
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
function unwrapped(schema) {
|
|
19
|
+
let current = schema;
|
|
20
|
+
for (let inner = innerSchemaOf(current); inner !== undefined; inner = innerSchemaOf(current))
|
|
21
|
+
current = inner;
|
|
22
|
+
return current;
|
|
23
|
+
}
|
|
24
|
+
export function flagKindOf(schema) {
|
|
25
|
+
const current = unwrapped(schema);
|
|
26
|
+
if (current instanceof z.ZodBoolean)
|
|
27
|
+
return 'boolean';
|
|
28
|
+
return current instanceof z.ZodArray ? 'list' : 'value';
|
|
29
|
+
}
|
|
30
|
+
// z.int() は上下を安全な整数の端にする。範囲の指定とは見なさない
|
|
31
|
+
function boundOf(bound) {
|
|
32
|
+
return bound === null || Math.abs(bound) >= Number.MAX_SAFE_INTEGER ? undefined : bound;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
値 1 つの型。list は要素の型
|
|
36
|
+
*/
|
|
37
|
+
export function valueTypeOf(schema) {
|
|
38
|
+
const outer = unwrapped(schema);
|
|
39
|
+
const current = outer instanceof z.ZodArray ? unwrapped(outer.element) : outer;
|
|
40
|
+
if (current instanceof z.ZodNumber) {
|
|
41
|
+
const isInteger = (current.format ?? '').includes('int');
|
|
42
|
+
const range = { min: boundOf(current.minValue), max: boundOf(current.maxValue) };
|
|
43
|
+
return isInteger ? { type: 'integer', ...range } : { type: 'float', ...range };
|
|
44
|
+
}
|
|
45
|
+
return current instanceof z.ZodEnum ? { type: 'choice', choices: current.options.map(String) } : { type: 'string' };
|
|
46
|
+
}
|
|
47
|
+
const SPECIAL_FLOAT = /^[+-]?(?:inf|infinity|nan)$/iu;
|
|
48
|
+
const DECIMAL_CHARACTERS = /^[+-]?[\d.][\d.e+-]*$/iu;
|
|
49
|
+
/**
|
|
50
|
+
float(text) と同じ。前後の空白・数字の間の `_`・指数・inf・nan を受ける。不正なら undefined
|
|
51
|
+
*/
|
|
52
|
+
function parsePythonFloat(text) {
|
|
53
|
+
const lower = text.trim().toLowerCase().replaceAll(/(?<=\d)_(?=\d)/gu, '');
|
|
54
|
+
if (SPECIAL_FLOAT.test(lower)) {
|
|
55
|
+
if (lower.endsWith('nan'))
|
|
56
|
+
return NaN;
|
|
57
|
+
return lower.startsWith('-') ? -Infinity : Infinity;
|
|
58
|
+
}
|
|
59
|
+
if (!DECIMAL_CHARACTERS.test(lower))
|
|
60
|
+
return undefined;
|
|
61
|
+
const value = Number(lower);
|
|
62
|
+
return Number.isNaN(value) ? undefined : value;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
範囲の文。両側なら `0<=x<=20`、片側なら `x>=1` か `x<=9`
|
|
66
|
+
*/
|
|
67
|
+
export function describeRange(min, max) {
|
|
68
|
+
if (min !== undefined && max !== undefined)
|
|
69
|
+
return `${String(min)}<=x<=${String(max)}`;
|
|
70
|
+
return min === undefined ? `x<=${String(max)}` : `x>=${String(min)}`;
|
|
71
|
+
}
|
|
72
|
+
function isOutside(value, min, max) {
|
|
73
|
+
return (min !== undefined && value < min) || (max !== undefined && value > max);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
コマンドラインの文字列を、型に応じて変換する。誤りの文は typer 同梱の click と同じ
|
|
77
|
+
*/
|
|
78
|
+
export function convertValue(text, valueType) {
|
|
79
|
+
if (valueType.type === 'string')
|
|
80
|
+
return { isValid: true, value: text };
|
|
81
|
+
if (valueType.type === 'choice') {
|
|
82
|
+
return valueType.choices.includes(text) ? { isValid: true, value: text } : { isValid: false, message: `${pythonStringRepr(text)} is not one of ${valueType.choices.map(choice => pythonStringRepr(choice)).join(', ')}.` };
|
|
83
|
+
}
|
|
84
|
+
const { min, max } = valueType;
|
|
85
|
+
const name = `${valueType.type === 'float' ? 'float' : 'int'}${min === undefined && max === undefined ? '' : ' range'}`;
|
|
86
|
+
const value = valueType.type === 'float' ? parsePythonFloat(text) : parsePythonInteger(text);
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
return { isValid: false, message: `${pythonStringRepr(text)} is not a valid ${name}.` };
|
|
89
|
+
if (!isOutside(value, min, max))
|
|
90
|
+
return { isValid: true, value };
|
|
91
|
+
const shown = valueType.type === 'float' ? pythonFloatRepr(value) : String(value);
|
|
92
|
+
return { isValid: false, message: `${shown} is not in the range ${describeRange(min, max)}.` };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=value-types.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BaseRecord } from '../domain/state.js';
|
|
2
|
+
import type { Output } from './output.js';
|
|
3
|
+
export interface RecordWorkTargetOptions {
|
|
4
|
+
/**
|
|
5
|
+
真なら、記録の失敗を warning ではなく error の行で出し、終了コード 1 で止める
|
|
6
|
+
*/
|
|
7
|
+
readonly failWithExit?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
着手で選んだ base。作業対象を記録できたときに .pecot-base へ書く。省くと .pecot-base は消えたままになる
|
|
10
|
+
*/
|
|
11
|
+
readonly base?: Readonly<BaseRecord>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
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)を書かずに出す
|
|
20
|
+
*/
|
|
21
|
+
export declare function planWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number): void;
|
|
22
|
+
//# sourceMappingURL=work-target.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// 作業対象(.pecot-active と .pecot-session-title、作業ディレクトリ)を記録して、結果の行を出す。
|
|
2
|
+
import { InvalidValueError, ProjectRootNotFoundError } from '../domain/errors.js';
|
|
3
|
+
import { FLAG_PECOT_BASE } from '../domain/state.js';
|
|
4
|
+
import { OsError, hasErrorCode, toOsError } from '../infra/os-error.js';
|
|
5
|
+
import { WORK_DIR } from '../infra/paths.js';
|
|
6
|
+
import { ensureWorkDirectory, removeFlag, writeBaseRecord, writeWorkTarget } from '../infra/state-store.js';
|
|
7
|
+
import { stopWith } from './command-stop.js';
|
|
8
|
+
/**
|
|
9
|
+
記録の失敗として扱う例外か。OS の失敗・値の誤り・プロジェクトルート不明。プログラムの誤りは伝える
|
|
10
|
+
*/
|
|
11
|
+
function isRecordingFailure(error) {
|
|
12
|
+
return error instanceof OsError || error instanceof InvalidValueError || error instanceof ProjectRootNotFoundError || hasErrorCode(error);
|
|
13
|
+
}
|
|
14
|
+
function describeFailure(error) {
|
|
15
|
+
const converted = toOsError(error);
|
|
16
|
+
return converted instanceof Error ? converted.message : error.message;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
.pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
|
|
20
|
+
失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかを返す
|
|
21
|
+
*/
|
|
22
|
+
export function recordWorkTarget(out, owner, repository, issueNumber, title, options = {}) {
|
|
23
|
+
const issueReference = `${owner}/${repository}/${String(issueNumber)}`;
|
|
24
|
+
clearBase(out);
|
|
25
|
+
let target;
|
|
26
|
+
try {
|
|
27
|
+
writeWorkTarget(issueReference, title);
|
|
28
|
+
target = `work target ${issueReference}`;
|
|
29
|
+
if (ensureWorkDirectory(issueReference) !== undefined)
|
|
30
|
+
target += ` (work directory ${WORK_DIR}/${String(issueNumber)}/)`;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!isRecordingFailure(error))
|
|
34
|
+
throw error;
|
|
35
|
+
if (options.failWithExit === true) {
|
|
36
|
+
stopWith(out, `could not record the work target: ${describeFailure(error)}`, 'other');
|
|
37
|
+
}
|
|
38
|
+
out.warning(`could not record the work target: ${describeFailure(error)}`);
|
|
39
|
+
return 'failed';
|
|
40
|
+
}
|
|
41
|
+
out.done({ verb: 'set', target });
|
|
42
|
+
if (options.base !== undefined)
|
|
43
|
+
recordBase(options.base, out);
|
|
44
|
+
return 'recorded';
|
|
45
|
+
}
|
|
46
|
+
function warnBase(out, error) {
|
|
47
|
+
if (!isRecordingFailure(error))
|
|
48
|
+
throw error;
|
|
49
|
+
out.warning(`could not record the base: ${describeFailure(error)}`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
前の作業対象の .pecot-base を消す。消せなければ warning の行を出して続ける
|
|
53
|
+
*/
|
|
54
|
+
function clearBase(out) {
|
|
55
|
+
try {
|
|
56
|
+
removeFlag(FLAG_PECOT_BASE);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// 状態ディレクトリが無い(ENOTDIR)なら消すものが無い。書くほうの失敗が別に出る
|
|
60
|
+
if (hasErrorCode(error) && error.code === 'ENOTDIR')
|
|
61
|
+
return;
|
|
62
|
+
warnBase(out, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
.pecot-base を書く。書けなければ warning の行を出して続ける
|
|
67
|
+
*/
|
|
68
|
+
function recordBase(record, out) {
|
|
69
|
+
try {
|
|
70
|
+
writeBaseRecord(record);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
warnBase(out, error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
予行の行。recordWorkTarget が書く作業対象(.pecot-active・.pecot-session-title・.pecot-base)を書かずに出す
|
|
78
|
+
*/
|
|
79
|
+
export function planWorkTarget(out, owner, repository, issueNumber) {
|
|
80
|
+
out.planned({ verb: 'set', target: `work target ${owner}/${repository}/${String(issueNumber)}` });
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=work-target.js.map
|