@pecot/workflow-mcp 0.0.0-stage → 5.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 +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -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 +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -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-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -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.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -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 +12 -0
- package/cli/dist/commands/github-client.js +23 -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 +55 -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 +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -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 +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -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 +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -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/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/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -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 +19 -0
- package/cli/dist/domain/errors.js +31 -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 +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -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-readout.d.ts +107 -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 +134 -0
- package/cli/dist/domain/pull-request.js +232 -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 +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -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 +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -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 +66 -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 +49 -0
- package/cli/dist/infra/config-store.js +121 -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 +74 -0
- package/cli/dist/infra/git.js +133 -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 +173 -0
- package/cli/dist/infra/github/client.js +576 -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 +47 -0
- package/cli/dist/infra/github/errors.js +42 -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 +129 -0
- package/cli/dist/infra/github/issues.js +273 -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 +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -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 +45 -0
- package/cli/dist/infra/state-store.js +118 -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 +139 -0
- package/cli/dist/infra/worktree-links.js +433 -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 +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -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 +128 -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 +181 -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 +67 -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/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// security alert の種類と、種類ごとの open の alert の取得、code scanning・secret scanning の状態判定。`release preflight` と `security sync` が使う。
|
|
2
|
+
// 取得は ScanAlertSource と DependabotSource に任せる。
|
|
3
|
+
import { describeApiError } from './api-error-detail.js';
|
|
4
|
+
import { PecotError } from './errors.js';
|
|
5
|
+
import { jsonField } from './json.js';
|
|
6
|
+
/**
|
|
7
|
+
種類の並び。Tracker の見出しと行の並びはこの順
|
|
8
|
+
*/
|
|
9
|
+
export const ALERT_KINDS = ['dependabot', 'code-scanning', 'secret-scanning'];
|
|
10
|
+
/**
|
|
11
|
+
Tracker の見出しとエラー文に出す種類の表示名
|
|
12
|
+
*/
|
|
13
|
+
export function kindLabel(kind) {
|
|
14
|
+
switch (kind) {
|
|
15
|
+
case 'dependabot': {
|
|
16
|
+
return 'Dependabot';
|
|
17
|
+
}
|
|
18
|
+
case 'code-scanning': {
|
|
19
|
+
return 'code scanning';
|
|
20
|
+
}
|
|
21
|
+
case 'secret-scanning': {
|
|
22
|
+
return 'secret scanning';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
security alert の状態を判定できない
|
|
28
|
+
*/
|
|
29
|
+
export class SecurityAlertError extends PecotError {
|
|
30
|
+
}
|
|
31
|
+
const UNCONFIRMED_MESSAGE = 'cannot fetch the secret scanning list (permission may be missing; it cannot be confirmed as disabled)';
|
|
32
|
+
function unwrap(result, kind, owner, repository) {
|
|
33
|
+
switch (result.kind) {
|
|
34
|
+
case 'ok':
|
|
35
|
+
case 'disabled': {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
case 'unconfirmed': {
|
|
39
|
+
throw new SecurityAlertError(`${owner}/${repository}: ${UNCONFIRMED_MESSAGE}`);
|
|
40
|
+
}
|
|
41
|
+
case 'failure': {
|
|
42
|
+
throw new SecurityAlertError(`${owner}/${repository}: ${kindLabel(kind)}: ${result.message}`);
|
|
43
|
+
}
|
|
44
|
+
case 'network': {
|
|
45
|
+
throw new SecurityAlertError(`${owner}/${repository}: request failed: ${result.message}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// forbidden は呼び出し側が分けて扱う。ここに来る forbidden は、有効 / 無効の判定の応答(レート制限以外の 403 は ok にならない)
|
|
50
|
+
function unwrapDependabot(result, owner, repository) {
|
|
51
|
+
switch (result.kind) {
|
|
52
|
+
case 'ok': {
|
|
53
|
+
return result.value;
|
|
54
|
+
}
|
|
55
|
+
case 'network': {
|
|
56
|
+
throw new SecurityAlertError(`${owner}/${repository}: request failed: ${result.message}`);
|
|
57
|
+
}
|
|
58
|
+
case 'forbidden':
|
|
59
|
+
case 'rateLimited':
|
|
60
|
+
case 'failure': {
|
|
61
|
+
throw new SecurityAlertError(`${owner}/${repository}: ${kindLabel('dependabot')}: ${describeApiError(result.failure)}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function listDependabot(source, owner, repository) {
|
|
66
|
+
const listed = await source.listOpenAlerts(owner, repository);
|
|
67
|
+
if (listed.kind !== 'forbidden')
|
|
68
|
+
return unwrapDependabot(listed, owner, repository);
|
|
69
|
+
// 403 は無効と権限不足の両方で起きる。有効なら権限不足としてエラーにする
|
|
70
|
+
if (unwrapDependabot(await source.isAlertsEnabled(owner, repository), owner, repository)) {
|
|
71
|
+
throw new SecurityAlertError(`${owner}/${repository}: Dependabot alerts are enabled but the list cannot be fetched (permission may be missing)`);
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
async function listScan(source, kind, owner, repository) {
|
|
76
|
+
const listed = unwrap(await source.listOpenAlerts(kind, owner, repository), kind, owner, repository);
|
|
77
|
+
return listed.kind === 'disabled' ? undefined : listed.alerts;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
種類ごとの open の alert(API の応答そのもの)を取る。機能が無効のリポは undefined。
|
|
81
|
+
一覧を取得できず無効とも言えないとき(API エラー・通信エラー・権限不足)は SecurityAlertError
|
|
82
|
+
*/
|
|
83
|
+
export async function listOpenAlerts(sources, kind, owner, repository) {
|
|
84
|
+
return kind === 'dependabot' ? listDependabot(sources.dependabot, owner, repository) : listScan(sources.scan, kind, owner, repository);
|
|
85
|
+
}
|
|
86
|
+
async function scanStatus(source, kind, host, owner, repository) {
|
|
87
|
+
const alertsUrl = `https://${host}/${owner}/${repository}/security/${kind}`;
|
|
88
|
+
const alerts = await listScan(source, kind, owner, repository);
|
|
89
|
+
if (alerts === undefined)
|
|
90
|
+
return { enabled: false, openCount: 0, alertsUrl, openNumbers: [] };
|
|
91
|
+
const numbers = alerts.map(alert => jsonField(alert, 'number')).filter((number) => Number.isSafeInteger(number));
|
|
92
|
+
return { enabled: true, openCount: alerts.length, alertsUrl, openNumbers: numbers.toSorted((a, b) => a - b) };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
code scanning の open の alert 数を取る(既定ブランチが対象)。状態を判定できなければ SecurityAlertError
|
|
96
|
+
*/
|
|
97
|
+
export async function fetchCodeScanningStatus(source, host, owner, repository) {
|
|
98
|
+
return scanStatus(source, 'code-scanning', host, owner, repository);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
secret scanning の open の alert 数を取る(値は取得しない)。
|
|
102
|
+
権限不足などで無効と確かめられないときも SecurityAlertError
|
|
103
|
+
*/
|
|
104
|
+
export async function fetchSecretScanningStatus(source, host, owner, repository) {
|
|
105
|
+
return scanStatus(source, 'secret-scanning', host, owner, repository);
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=security-alerts.js.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { JsonValue } from './python-format.js';
|
|
2
|
+
import type { AlertKind } from './security-alerts.js';
|
|
3
|
+
export declare const ALERT_LABEL = "security-alert";
|
|
4
|
+
export declare const LIST_END = "<!-- pecot-alert: list-end -->";
|
|
5
|
+
export declare const TRACKER_PATTERN: RegExp;
|
|
6
|
+
/**
|
|
7
|
+
Tracker の表の 1 行(open の alert)。表に出してよい情報だけ
|
|
8
|
+
*/
|
|
9
|
+
export interface TrackerEntry {
|
|
10
|
+
readonly kind: AlertKind;
|
|
11
|
+
readonly number: number;
|
|
12
|
+
/**
|
|
13
|
+
high / medium / low
|
|
14
|
+
*/
|
|
15
|
+
readonly priority: string;
|
|
16
|
+
/**
|
|
17
|
+
Dependabot のパッケージ名(ほかの種類は undefined)
|
|
18
|
+
*/
|
|
19
|
+
readonly package: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
Dependabot の GHSA ID(ほかの種類は undefined)
|
|
22
|
+
*/
|
|
23
|
+
readonly ghsa: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
Dependabot の advisory の題(公開の情報。ほかの種類は undefined)
|
|
26
|
+
*/
|
|
27
|
+
readonly summary: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
open の alert 1 件の要点(行に URL を足したもの)
|
|
31
|
+
*/
|
|
32
|
+
export interface Alert extends TrackerEntry {
|
|
33
|
+
readonly url: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
行の識別子(種類と番号)
|
|
37
|
+
*/
|
|
38
|
+
export declare function entryKey(entry: Readonly<Pick<TrackerEntry, 'kind' | 'number'>>): string;
|
|
39
|
+
/**
|
|
40
|
+
API の alert の並びを共通の形にする(番号の無いものは除く)
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeAlerts(kind: AlertKind, raws: readonly JsonValue[], host: string, owner: string, repository: string): readonly Alert[];
|
|
43
|
+
/**
|
|
44
|
+
urllib.parse.quote(text, safe="") と同じ。英数字と `_.-~` 以外を UTF-8 の `%XX`(大文字)にする
|
|
45
|
+
*/
|
|
46
|
+
export declare function quoteComponent(text: string): string;
|
|
47
|
+
/**
|
|
48
|
+
urllib.parse.unquote(text) と同じ。不正な `%` の列はそのまま残し、不正な UTF-8 は U+FFFD にする
|
|
49
|
+
*/
|
|
50
|
+
export declare function unquoteComponent(text: string): string;
|
|
51
|
+
/**
|
|
52
|
+
全行の Priority の最大。行が無ければ undefined。同順位は先の行の値
|
|
53
|
+
*/
|
|
54
|
+
export declare function maxPriority(entries: readonly TrackerEntry[]): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
行の並びを、種類の順・番号の順に固定する
|
|
57
|
+
*/
|
|
58
|
+
export declare function sortedEntries(entries: readonly TrackerEntry[]): readonly TrackerEntry[];
|
|
59
|
+
export interface RenderOptions {
|
|
60
|
+
/**
|
|
61
|
+
既存の本文。あれば list-begin から list-end の間だけを書き直し、外の文は残す。無ければ Tracker の印と一覧だけの本文を作る
|
|
62
|
+
*/
|
|
63
|
+
readonly existingBody?: string | undefined;
|
|
64
|
+
/**
|
|
65
|
+
無効の種類。見出しの下に disabled だけを置く
|
|
66
|
+
*/
|
|
67
|
+
readonly disabledKinds?: ReadonlySet<AlertKind>;
|
|
68
|
+
/**
|
|
69
|
+
一覧を取れなかった種類。行が無ければ見出しの下に unavailable を置く
|
|
70
|
+
*/
|
|
71
|
+
readonly failedKinds?: ReadonlySet<AlertKind>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
Tracker の本文を作る。一覧は種類ごとの見出しと表にする。
|
|
75
|
+
existingBody の印が 1 組でなければ SecurityAlertError
|
|
76
|
+
*/
|
|
77
|
+
export declare function renderTrackerBody(entries: readonly TrackerEntry[], host: string, owner: string, repository: string, options?: Readonly<RenderOptions>): string;
|
|
78
|
+
/**
|
|
79
|
+
Tracker の本文から、一覧の行を読む。
|
|
80
|
+
1 行に印が複数あってよい。`sum=` は束の先頭の印にだけあるので、同じ GHSA の残りに引き継ぐ。
|
|
81
|
+
`state=` の無い行と `state=open` の行だけを読み、ほかの state・旧い `folded count=`・印の無い行は読み捨てる。
|
|
82
|
+
list-begin / list-end の印が 1 組でなければ SecurityAlertError
|
|
83
|
+
*/
|
|
84
|
+
export declare function parseTrackerEntries(body?: string): readonly TrackerEntry[];
|
|
85
|
+
/**
|
|
86
|
+
Tracker の題。today は立てた日(UTC)の YYYY-MM-DD
|
|
87
|
+
*/
|
|
88
|
+
export declare function buildTrackerTitle(today: string): string;
|
|
89
|
+
/**
|
|
90
|
+
alert と Tracker の一覧の突き合わせの結果
|
|
91
|
+
*/
|
|
92
|
+
export interface TrackerPlan {
|
|
93
|
+
/**
|
|
94
|
+
新しい Tracker を立てるか(open の Tracker が無く、表に載せる行があるとき)
|
|
95
|
+
*/
|
|
96
|
+
readonly create: boolean;
|
|
97
|
+
/**
|
|
98
|
+
書き直した後の行(並びは固定)
|
|
99
|
+
*/
|
|
100
|
+
readonly entries: readonly TrackerEntry[];
|
|
101
|
+
/**
|
|
102
|
+
一覧に足した行
|
|
103
|
+
*/
|
|
104
|
+
readonly added: readonly TrackerEntry[];
|
|
105
|
+
/**
|
|
106
|
+
一覧から外した行
|
|
107
|
+
*/
|
|
108
|
+
readonly removed: readonly TrackerEntry[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
open の alert と Tracker の今の行から、書き直した行を出す。entries が undefined なら open の Tracker が無い。
|
|
112
|
+
failedKinds の種類は前の行をそのまま使い、disabledKinds の種類は行を持たない
|
|
113
|
+
*/
|
|
114
|
+
export declare function planTracker(openAlerts: ReadonlyMap<AlertKind, readonly Alert[]>, entries: readonly TrackerEntry[] | undefined, failedKinds?: ReadonlySet<AlertKind>, disabledKinds?: ReadonlySet<AlertKind>): TrackerPlan;
|
|
115
|
+
//# sourceMappingURL=security-tracker.d.ts.map
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// security alert の Tracker の本文の読み書きと、行の足し外しを決める純粋な処理(cli/core/security_alerts.py の移植)。
|
|
2
|
+
// 公開のリポとボードに載るので、本文に出すのは種類・番号・Priority・URL まで。Dependabot はパッケージ名と GHSA の ID も出す。
|
|
3
|
+
import { jsonField } from './json.js';
|
|
4
|
+
import { normalizeNewlines, parsePythonInteger, pythonStrip } from './python-format.js';
|
|
5
|
+
import { ALERT_KINDS, kindLabel, SecurityAlertError } from './security-alerts.js';
|
|
6
|
+
import { cell, compilePattern, listRegion, markerPatterns, NON_SPACE, SPACE } from './tracker-body.js';
|
|
7
|
+
export const ALERT_LABEL = 'security-alert';
|
|
8
|
+
const TRACKER_MARKER = '<!-- pecot-alert: tracker -->';
|
|
9
|
+
const LIST_BEGIN = '<!-- pecot-alert: list-begin -->';
|
|
10
|
+
export const LIST_END = '<!-- pecot-alert: list-end -->';
|
|
11
|
+
const SEVERITY_PRIORITY = new Map([['critical', 'high'], ['high', 'high'], ['medium', 'medium'], ['low', 'low']]);
|
|
12
|
+
const RULE_SEVERITY_PRIORITY = new Map([['error', 'high'], ['warning', 'medium'], ['note', 'low']]);
|
|
13
|
+
const PRIORITY_RANK = new Map([['low', 0], ['medium', 1], ['high', 2]]);
|
|
14
|
+
const DEFAULT_PRIORITY = 'medium';
|
|
15
|
+
const MARKER_SOURCE = String.raw `<!--${SPACE}*pecot-alert:${SPACE}*(dependabot|code-scanning|secret-scanning)/(\p{Nd}+)((?:${SPACE}+[a-z]+=${NON_SPACE}+)*)${SPACE}*-->`;
|
|
16
|
+
const MARKER_PATTERN = compilePattern(MARKER_SOURCE, 'gu');
|
|
17
|
+
const ATTRIBUTE_PATTERN = compilePattern(`([a-z]+)=(${NON_SPACE}+)`, 'gu');
|
|
18
|
+
// 行の 1 列目の先頭に並ぶ印(1 行に複数あってよい)
|
|
19
|
+
const ROW_MARKERS_PATTERN = compilePattern(String.raw `^\|${SPACE}*((?:<!--[^>]*?-->${SPACE}*)+)`, 'u');
|
|
20
|
+
const MARKERS = markerPatterns('pecot-alert');
|
|
21
|
+
export const TRACKER_PATTERN = MARKERS.tracker;
|
|
22
|
+
// Python の `$` は末尾の改行 1 つの手前にも合う
|
|
23
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- 繰り返しは固定の 3 回
|
|
24
|
+
const GHSA_PATTERN = /^GHSA(?:-[a-z0-9]{4}){3}\n?$/u;
|
|
25
|
+
/**
|
|
26
|
+
行の識別子(種類と番号)
|
|
27
|
+
*/
|
|
28
|
+
export function entryKey(entry) {
|
|
29
|
+
return `${entry.kind}/${String(entry.number)}`;
|
|
30
|
+
}
|
|
31
|
+
function valuesOf(map) {
|
|
32
|
+
const values = [];
|
|
33
|
+
for (const value of map.values())
|
|
34
|
+
values.push(value);
|
|
35
|
+
return values;
|
|
36
|
+
}
|
|
37
|
+
function isGhsa(value) {
|
|
38
|
+
return value !== undefined && GHSA_PATTERN.test(value);
|
|
39
|
+
}
|
|
40
|
+
// Python の `a or b`(空文字も無いものとして扱う)
|
|
41
|
+
function orElse(first, second) {
|
|
42
|
+
return first === undefined || first === '' ? second : first;
|
|
43
|
+
}
|
|
44
|
+
function textField(value) {
|
|
45
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
46
|
+
}
|
|
47
|
+
function alertNumber(raw) {
|
|
48
|
+
const number = jsonField(raw, 'number');
|
|
49
|
+
return typeof number === 'number' && Number.isSafeInteger(number) ? number : undefined;
|
|
50
|
+
}
|
|
51
|
+
function alertUrl(raw, host, owner, repository, kind, number) {
|
|
52
|
+
return textField(jsonField(raw, 'html_url')) ?? `https://${host}/${owner}/${repository}/security/${kind}/${String(number)}`;
|
|
53
|
+
}
|
|
54
|
+
// Priority は security_vulnerability.severity、無ければ security_advisory.severity で決める
|
|
55
|
+
function normalizeDependabot(raw, host, owner, repository) {
|
|
56
|
+
const number = alertNumber(raw);
|
|
57
|
+
if (number === undefined)
|
|
58
|
+
return undefined;
|
|
59
|
+
const advisory = jsonField(raw, 'security_advisory');
|
|
60
|
+
const dependency = jsonField(jsonField(raw, 'dependency'), 'package');
|
|
61
|
+
const severity = textField(jsonField(jsonField(raw, 'security_vulnerability'), 'severity')) ?? textField(jsonField(advisory, 'severity'));
|
|
62
|
+
const ghsa = textField(jsonField(advisory, 'ghsa_id'));
|
|
63
|
+
return {
|
|
64
|
+
kind: 'dependabot',
|
|
65
|
+
number,
|
|
66
|
+
priority: SEVERITY_PRIORITY.get(severity ?? '') ?? DEFAULT_PRIORITY,
|
|
67
|
+
url: alertUrl(raw, host, owner, repository, 'dependabot', number),
|
|
68
|
+
package: textField(jsonField(dependency, 'name')),
|
|
69
|
+
ghsa: isGhsa(ghsa) ? ghsa : undefined,
|
|
70
|
+
summary: textField(jsonField(advisory, 'summary')),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Priority は rule.security_severity_level、無ければ rule.severity で決める
|
|
74
|
+
function normalizeCodeScanning(raw, host, owner, repository) {
|
|
75
|
+
const number = alertNumber(raw);
|
|
76
|
+
if (number === undefined)
|
|
77
|
+
return undefined;
|
|
78
|
+
const rule = jsonField(raw, 'rule');
|
|
79
|
+
const level = textField(jsonField(rule, 'security_severity_level'));
|
|
80
|
+
const severity = textField(jsonField(rule, 'severity'));
|
|
81
|
+
return {
|
|
82
|
+
kind: 'code-scanning',
|
|
83
|
+
number,
|
|
84
|
+
priority: SEVERITY_PRIORITY.get(level ?? '') ?? RULE_SEVERITY_PRIORITY.get(severity ?? '') ?? DEFAULT_PRIORITY,
|
|
85
|
+
url: alertUrl(raw, host, owner, repository, 'code-scanning', number),
|
|
86
|
+
package: undefined,
|
|
87
|
+
ghsa: undefined,
|
|
88
|
+
summary: undefined,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// secret scanning の Priority は常に high
|
|
92
|
+
function normalizeSecretScanning(raw, host, owner, repository) {
|
|
93
|
+
const number = alertNumber(raw);
|
|
94
|
+
if (number === undefined)
|
|
95
|
+
return undefined;
|
|
96
|
+
return {
|
|
97
|
+
kind: 'secret-scanning',
|
|
98
|
+
number,
|
|
99
|
+
priority: 'high',
|
|
100
|
+
url: alertUrl(raw, host, owner, repository, 'secret-scanning', number),
|
|
101
|
+
package: undefined,
|
|
102
|
+
ghsa: undefined,
|
|
103
|
+
summary: undefined,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
API の alert の並びを共通の形にする(番号の無いものは除く)
|
|
108
|
+
*/
|
|
109
|
+
export function normalizeAlerts(kind, raws, host, owner, repository) {
|
|
110
|
+
const normalize = kind === 'dependabot' ? normalizeDependabot : (kind === 'code-scanning' ? normalizeCodeScanning : normalizeSecretScanning);
|
|
111
|
+
return raws.map(raw => normalize(raw, host, owner, repository)).filter(alert => alert !== undefined);
|
|
112
|
+
}
|
|
113
|
+
const UNRESERVED = /^[\w.~-]$/u;
|
|
114
|
+
/**
|
|
115
|
+
urllib.parse.quote(text, safe="") と同じ。英数字と `_.-~` 以外を UTF-8 の `%XX`(大文字)にする
|
|
116
|
+
*/
|
|
117
|
+
export function quoteComponent(text) {
|
|
118
|
+
return Array.from(new TextEncoder().encode(text), (byte) => {
|
|
119
|
+
const character = String.fromCodePoint(byte);
|
|
120
|
+
return byte < 0x80 && UNRESERVED.test(character) ? character : `%${byte.toString(16).toUpperCase().padStart(2, '0')}`;
|
|
121
|
+
}).join('');
|
|
122
|
+
}
|
|
123
|
+
// eslint-disable-next-line security/detect-unsafe-regex -- 1 つの繰り返しは固定の 3 文字で、バックトラックは増えない
|
|
124
|
+
const PERCENT_RUN = /(?:%[\dA-F]{2})+/giu;
|
|
125
|
+
const UTF8_DECODER = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
126
|
+
/**
|
|
127
|
+
urllib.parse.unquote(text) と同じ。不正な `%` の列はそのまま残し、不正な UTF-8 は U+FFFD にする
|
|
128
|
+
*/
|
|
129
|
+
export function unquoteComponent(text) {
|
|
130
|
+
return text.replaceAll(PERCENT_RUN, run => UTF8_DECODER.decode(Uint8Array.from(run.slice(1).split('%'), hex => Number.parseInt(hex, 16))));
|
|
131
|
+
}
|
|
132
|
+
function entryMarker(entry) {
|
|
133
|
+
const parts = [entryKey(entry), `priority=${entry.priority}`];
|
|
134
|
+
// `--` を含めないため、`-` も符号化する
|
|
135
|
+
if (entry.package !== undefined && entry.package !== '')
|
|
136
|
+
parts.push(`pkg=${quoteComponent(entry.package).replaceAll('-', '%2D')}`);
|
|
137
|
+
if (isGhsa(entry.ghsa))
|
|
138
|
+
parts.push(`ghsa=${entry.ghsa}`);
|
|
139
|
+
if (entry.summary !== undefined && entry.summary !== '')
|
|
140
|
+
parts.push(`sum=${quoteComponent(entry.summary).replaceAll('-', '%2D')}`);
|
|
141
|
+
return `<!-- pecot-alert: ${parts.join(' ')} -->`;
|
|
142
|
+
}
|
|
143
|
+
// リンクの題に入れても表を壊さないよう `\` `[` `]` `|` `<` を無害にする
|
|
144
|
+
function titleText(text) {
|
|
145
|
+
return cell(text.replaceAll('\\', '\\\\').replaceAll('[', String.raw `\[`).replaceAll(']', String.raw `\]`));
|
|
146
|
+
}
|
|
147
|
+
function alertLink(entry, host, owner, repository) {
|
|
148
|
+
return `[#${String(entry.number)}](https://${host}/${owner}/${repository}/security/${entry.kind}/${String(entry.number)})`;
|
|
149
|
+
}
|
|
150
|
+
// code scanning・secret scanning の行。title は固定の masked
|
|
151
|
+
function entryRow(entry, host, owner, repository) {
|
|
152
|
+
return `| ${entryMarker(entry)} masked | ${alertLink(entry, host, owner, repository)} | ${entry.priority} |`;
|
|
153
|
+
}
|
|
154
|
+
function rankOf(priority) {
|
|
155
|
+
return PRIORITY_RANK.get(priority) ?? 1;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
全行の Priority の最大。行が無ければ undefined。同順位は先の行の値
|
|
159
|
+
*/
|
|
160
|
+
export function maxPriority(entries) {
|
|
161
|
+
let best;
|
|
162
|
+
for (const { priority } of entries) {
|
|
163
|
+
if (best === undefined || rankOf(priority) > rankOf(best))
|
|
164
|
+
best = priority;
|
|
165
|
+
}
|
|
166
|
+
return best;
|
|
167
|
+
}
|
|
168
|
+
function hasGhsa(entry) {
|
|
169
|
+
return entry.ghsa !== undefined && entry.ghsa !== '';
|
|
170
|
+
}
|
|
171
|
+
function membersOf(group) {
|
|
172
|
+
return [group.first, ...group.rest];
|
|
173
|
+
}
|
|
174
|
+
function groupRank(group) {
|
|
175
|
+
let best = -Infinity;
|
|
176
|
+
for (const entry of membersOf(group))
|
|
177
|
+
best = Math.max(best, rankOf(entry.priority));
|
|
178
|
+
return best;
|
|
179
|
+
}
|
|
180
|
+
// GHSA ごとに束ねる(GHSA の無い alert は 1 件ずつ)。並びは Priority の高い順、同じなら先頭の番号順
|
|
181
|
+
function advisoryGroups(entries) {
|
|
182
|
+
const restByGhsa = new Map();
|
|
183
|
+
const groups = [];
|
|
184
|
+
const ordered = entries.toSorted((a, b) => a.number - b.number);
|
|
185
|
+
for (const entry of ordered) {
|
|
186
|
+
const existing = hasGhsa(entry) ? restByGhsa.get(entry.ghsa) : undefined;
|
|
187
|
+
if (existing !== undefined) {
|
|
188
|
+
existing.push(entry);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const rest = [];
|
|
192
|
+
groups.push({ first: entry, rest });
|
|
193
|
+
if (hasGhsa(entry))
|
|
194
|
+
restByGhsa.set(entry.ghsa, rest);
|
|
195
|
+
}
|
|
196
|
+
return groups.toSorted((a, b) => groupRank(b) - groupRank(a) || a.first.number - b.first.number);
|
|
197
|
+
}
|
|
198
|
+
function firstNonEmpty(values) {
|
|
199
|
+
return values.find(value => value !== undefined && value !== '');
|
|
200
|
+
}
|
|
201
|
+
// Dependabot の advisory 1 件の行(内容・alert・Priority)
|
|
202
|
+
function advisoryRow(group, host, owner, repository) {
|
|
203
|
+
const { first } = group;
|
|
204
|
+
const members = membersOf(group);
|
|
205
|
+
// summary は束の先頭の alert の印にだけ付ける。読み戻しで束の残りに引き継ぐ
|
|
206
|
+
const summary = firstNonEmpty(members.map(entry => entry.summary));
|
|
207
|
+
const package_ = firstNonEmpty(members.map(entry => entry.package));
|
|
208
|
+
const label = titleText(orElse(orElse(summary, first.ghsa), orElse(package_, '不明')) ?? '不明');
|
|
209
|
+
const content = hasGhsa(first) ? `[${label}](https://${host}/advisories/${first.ghsa})` : label;
|
|
210
|
+
const markers = members.map((entry, index) => entryMarker({ ...entry, summary: index === 0 ? summary : undefined })).join(' ');
|
|
211
|
+
const links = members.map(entry => alertLink(entry, host, owner, repository)).join(' ');
|
|
212
|
+
return `| ${markers} ${content} | ${links} | ${maxPriority(members) ?? DEFAULT_PRIORITY} |`;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
行の並びを、種類の順・番号の順に固定する
|
|
216
|
+
*/
|
|
217
|
+
export function sortedEntries(entries) {
|
|
218
|
+
return entries.toSorted((a, b) => ALERT_KINDS.indexOf(a.kind) - ALERT_KINDS.indexOf(b.kind) || a.number - b.number);
|
|
219
|
+
}
|
|
220
|
+
// 行が無いときの語は、無効が disabled、取れず前の行も無いが unavailable、0 件が none
|
|
221
|
+
function section(kind, entries, status, host, owner, repository) {
|
|
222
|
+
const head = `## ${kindLabel(kind)}\n\n`;
|
|
223
|
+
if (status === 'disabled')
|
|
224
|
+
return `${head}disabled`;
|
|
225
|
+
const rows = entries.filter(entry => entry.kind === kind);
|
|
226
|
+
if (rows.length === 0)
|
|
227
|
+
return head + (status === 'failed' ? 'unavailable' : 'none');
|
|
228
|
+
const bodyRows = kind === 'dependabot'
|
|
229
|
+
? advisoryGroups(rows).map(group => advisoryRow(group, host, owner, repository))
|
|
230
|
+
// Priority の高い順、同じなら番号順
|
|
231
|
+
: rows.toSorted((a, b) => rankOf(b.priority) - rankOf(a.priority) || a.number - b.number).map(entry => entryRow(entry, host, owner, repository));
|
|
232
|
+
return head + ['| title | alert | Priority |', '|---|---|---|', ...bodyRows].join('\n');
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
Tracker の本文を作る。一覧は種類ごとの見出しと表にする。
|
|
236
|
+
existingBody の印が 1 組でなければ SecurityAlertError
|
|
237
|
+
*/
|
|
238
|
+
export function renderTrackerBody(entries, host, owner, repository, options = {}) {
|
|
239
|
+
const { existingBody, disabledKinds = new Set(), failedKinds = new Set() } = options;
|
|
240
|
+
const statusOf = (kind) => (disabledKinds.has(kind) ? 'disabled' : (failedKinds.has(kind) ? 'failed' : 'ok'));
|
|
241
|
+
const sections = ALERT_KINDS.map(kind => section(kind, entries, statusOf(kind), host, owner, repository)).join('\n\n');
|
|
242
|
+
if (existingBody === undefined)
|
|
243
|
+
return `${TRACKER_MARKER}\n\n${LIST_BEGIN}\n${sections}\n${LIST_END}\n`;
|
|
244
|
+
const text = normalizeNewlines(existingBody);
|
|
245
|
+
const region = listRegion(text, MARKERS.begin, MARKERS.end, SecurityAlertError);
|
|
246
|
+
return `${text.slice(0, region.begin)}\n${sections}\n${text.slice(region.end)}`;
|
|
247
|
+
}
|
|
248
|
+
function attributesOf(text) {
|
|
249
|
+
const attributes = new Map();
|
|
250
|
+
for (const [, name = '', value = ''] of text.matchAll(ATTRIBUTE_PATTERN))
|
|
251
|
+
attributes.set(name, value);
|
|
252
|
+
return attributes;
|
|
253
|
+
}
|
|
254
|
+
function kindOf(name) {
|
|
255
|
+
return ALERT_KINDS.find(kind => kind === name) ?? 'dependabot';
|
|
256
|
+
}
|
|
257
|
+
function entriesOfMarkers(markers) {
|
|
258
|
+
const found = [];
|
|
259
|
+
for (const [, kind, digits = '', rest = ''] of markers.matchAll(MARKER_PATTERN)) {
|
|
260
|
+
const attributes = attributesOf(rest);
|
|
261
|
+
const number = parsePythonInteger(digits);
|
|
262
|
+
if (number === undefined || (attributes.get('state') ?? 'open') !== 'open')
|
|
263
|
+
continue;
|
|
264
|
+
const priority = attributes.get('priority') ?? DEFAULT_PRIORITY;
|
|
265
|
+
const ghsa = attributes.get('ghsa');
|
|
266
|
+
const package_ = attributes.get('pkg');
|
|
267
|
+
const summary = attributes.get('sum');
|
|
268
|
+
found.push({
|
|
269
|
+
kind: kindOf(kind),
|
|
270
|
+
number,
|
|
271
|
+
priority: PRIORITY_RANK.has(priority) ? priority : DEFAULT_PRIORITY,
|
|
272
|
+
package: package_ === undefined ? undefined : unquoteComponent(package_),
|
|
273
|
+
ghsa: isGhsa(ghsa) ? ghsa : undefined,
|
|
274
|
+
summary: summary === undefined ? undefined : unquoteComponent(summary),
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
return found;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
Tracker の本文から、一覧の行を読む。
|
|
281
|
+
1 行に印が複数あってよい。`sum=` は束の先頭の印にだけあるので、同じ GHSA の残りに引き継ぐ。
|
|
282
|
+
`state=` の無い行と `state=open` の行だけを読み、ほかの state・旧い `folded count=`・印の無い行は読み捨てる。
|
|
283
|
+
list-begin / list-end の印が 1 組でなければ SecurityAlertError
|
|
284
|
+
*/
|
|
285
|
+
export function parseTrackerEntries(body = '') {
|
|
286
|
+
const text = normalizeNewlines(body);
|
|
287
|
+
const region = listRegion(text, MARKERS.begin, MARKERS.end, SecurityAlertError);
|
|
288
|
+
const entries = new Map();
|
|
289
|
+
for (const line of text.slice(region.begin, region.end).split('\n')) {
|
|
290
|
+
const markers = ROW_MARKERS_PATTERN.exec(pythonStrip(line))?.[1];
|
|
291
|
+
if (markers === undefined)
|
|
292
|
+
continue;
|
|
293
|
+
for (const entry of entriesOfMarkers(markers)) {
|
|
294
|
+
if (!entries.has(entryKey(entry)))
|
|
295
|
+
entries.set(entryKey(entry), entry);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const summaries = new Map();
|
|
299
|
+
for (const entry of valuesOf(entries)) {
|
|
300
|
+
if (entry.summary !== undefined && entry.summary !== '' && hasGhsa(entry))
|
|
301
|
+
summaries.set(entry.ghsa, entry.summary);
|
|
302
|
+
}
|
|
303
|
+
const filled = valuesOf(entries).map((entry) => {
|
|
304
|
+
const inherited = hasGhsa(entry) ? summaries.get(entry.ghsa) : undefined;
|
|
305
|
+
return { ...entry, summary: orElse(entry.summary, inherited) };
|
|
306
|
+
});
|
|
307
|
+
return sortedEntries(filled);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
Tracker の題。today は立てた日(UTC)の YYYY-MM-DD
|
|
311
|
+
*/
|
|
312
|
+
export function buildTrackerTitle(today) {
|
|
313
|
+
return `[Tracker] security alert — ${today}`;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
open の alert と Tracker の今の行から、書き直した行を出す。entries が undefined なら open の Tracker が無い。
|
|
317
|
+
failedKinds の種類は前の行をそのまま使い、disabledKinds の種類は行を持たない
|
|
318
|
+
*/
|
|
319
|
+
export function planTracker(openAlerts, entries, failedKinds = new Set(), disabledKinds = new Set()) {
|
|
320
|
+
const oldByKey = new Map();
|
|
321
|
+
const rows = new Map();
|
|
322
|
+
const previous = entries ?? [];
|
|
323
|
+
for (const old of previous) {
|
|
324
|
+
oldByKey.set(entryKey(old), old);
|
|
325
|
+
if (failedKinds.has(old.kind))
|
|
326
|
+
rows.set(entryKey(old), old);
|
|
327
|
+
}
|
|
328
|
+
for (const kind of ALERT_KINDS) {
|
|
329
|
+
if (failedKinds.has(kind) || disabledKinds.has(kind))
|
|
330
|
+
continue;
|
|
331
|
+
const alerts = openAlerts.get(kind) ?? [];
|
|
332
|
+
for (const alert of alerts) {
|
|
333
|
+
const key = entryKey({ kind, number: alert.number });
|
|
334
|
+
const old = oldByKey.get(key);
|
|
335
|
+
rows.set(key, {
|
|
336
|
+
kind,
|
|
337
|
+
number: alert.number,
|
|
338
|
+
priority: alert.priority,
|
|
339
|
+
package: orElse(alert.package, old?.package),
|
|
340
|
+
ghsa: orElse(alert.ghsa, old?.ghsa),
|
|
341
|
+
summary: orElse(alert.summary, old?.summary),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const planned = sortedEntries(valuesOf(rows));
|
|
346
|
+
return {
|
|
347
|
+
create: entries === undefined && planned.length > 0,
|
|
348
|
+
entries: planned,
|
|
349
|
+
added: sortedEntries(planned.filter(entry => !oldByKey.has(entryKey(entry)))),
|
|
350
|
+
removed: sortedEntries(valuesOf(oldByKey).filter(old => !rows.has(entryKey(old)))),
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=security-tracker.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const FLAG_PECOT_ACTIVE = ".pecot-active";
|
|
2
|
+
export declare const FLAG_PECOT_SESSION_TITLE = ".pecot-session-title";
|
|
3
|
+
export declare const FLAG_PECOT_QUICK_MODE = ".pecot-quick-mode";
|
|
4
|
+
export declare const FLAG_WIP_BRANCH_LINKED = ".wip-branch-linked";
|
|
5
|
+
export declare const FLAG_PR_CREATE_SLASH_PENDING = "pr-create-slash-pending";
|
|
6
|
+
export declare const FLAG_ISSUE_CREATE_SLASH_PENDING = "issue-create-slash-pending";
|
|
7
|
+
export declare const FLAG_MERGE_SLASH_PENDING = "merge-slash-pending";
|
|
8
|
+
export declare const FLAG_ISSUE_PENDING = "issue-pending";
|
|
9
|
+
export declare const SESSION_TITLE_MAX_CHARS = 40;
|
|
10
|
+
/**
|
|
11
|
+
セッション名 `#<番号> <Issue タイトル>` を組み立てる。
|
|
12
|
+
先頭の種別接頭辞(`[Task]` 等)を落とし、全体を SESSION_TITLE_MAX_CHARS 文字(コードポイント)で切る。
|
|
13
|
+
タイトルが空なら `#<番号>` だけにする
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatSessionTitle(issueNumber: number, title: string): string;
|
|
16
|
+
/**
|
|
17
|
+
作業ディレクトリ `.pecot/work/<Issue番号>/` の番号。参照(`owner/repo/N` または `N`)の末尾が ASCII の数字でなければ undefined。
|
|
18
|
+
`.pecot/work` の直下は Issue 番号の数字だけにする規約のため、全角数字などは通さない
|
|
19
|
+
*/
|
|
20
|
+
export declare function workDirectoryName(issueReference: string): string | undefined;
|
|
21
|
+
export interface WorkTarget {
|
|
22
|
+
readonly active: string;
|
|
23
|
+
readonly sessionTitle: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
作業対象として書く内容(.pecot-active と .pecot-session-title)を決める。参照の末尾が整数でなければ InvalidValueError
|
|
27
|
+
*/
|
|
28
|
+
export declare function planWorkTarget(issueReference: string, title: string): WorkTarget;
|
|
29
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// フック状態の規則(フラグ名・セッション名・作業ディレクトリ名)。ファイルの読み書きは infra/state-store.ts が行う。
|
|
2
|
+
import { InvalidValueError } from './errors.js';
|
|
3
|
+
import { parsePythonInteger, pythonRightStrip, pythonStrip, pythonStringRepr, truncateCodePoints } from './python-format.js';
|
|
4
|
+
// フラグファイル名
|
|
5
|
+
export const FLAG_PECOT_ACTIVE = '.pecot-active';
|
|
6
|
+
// セッション名(hooks の session-title.sh が Claude Code の sessionTitle に流す)。.pecot-active と同じタイミングで書く
|
|
7
|
+
export const FLAG_PECOT_SESSION_TITLE = '.pecot-session-title';
|
|
8
|
+
export const FLAG_PECOT_QUICK_MODE = '.pecot-quick-mode';
|
|
9
|
+
export const FLAG_WIP_BRANCH_LINKED = '.wip-branch-linked';
|
|
10
|
+
// スラッシュコマンド起点の外部反映免除フラグ。
|
|
11
|
+
// 設置は hooks の create-slash-flag.sh が行う。
|
|
12
|
+
// 確認は mcp-handlers/pecot-post-ask.sh(merge は core/external-post-check.sh)が行う。
|
|
13
|
+
// MCP ツールが実投稿成功時に削除する。
|
|
14
|
+
export const FLAG_PR_CREATE_SLASH_PENDING = 'pr-create-slash-pending';
|
|
15
|
+
export const FLAG_ISSUE_CREATE_SLASH_PENDING = 'issue-create-slash-pending';
|
|
16
|
+
export const FLAG_MERGE_SLASH_PENDING = 'merge-slash-pending';
|
|
17
|
+
// 起票未完了のリマインド用フラグ。設置は hooks、確認は pecot-issue-pending-reminder.sh。MCP ツールが起票成功時に削除する
|
|
18
|
+
export const FLAG_ISSUE_PENDING = 'issue-pending';
|
|
19
|
+
export const SESSION_TITLE_MAX_CHARS = 40;
|
|
20
|
+
const ISSUE_TYPE_PREFIX_PATTERN = /^\[(?:Task|Bug|Epic)\]\s*/u;
|
|
21
|
+
/**
|
|
22
|
+
セッション名 `#<番号> <Issue タイトル>` を組み立てる。
|
|
23
|
+
先頭の種別接頭辞(`[Task]` 等)を落とし、全体を SESSION_TITLE_MAX_CHARS 文字(コードポイント)で切る。
|
|
24
|
+
タイトルが空なら `#<番号>` だけにする
|
|
25
|
+
*/
|
|
26
|
+
export function formatSessionTitle(issueNumber, title) {
|
|
27
|
+
const body = pythonStrip(title.replace(ISSUE_TYPE_PREFIX_PATTERN, ''));
|
|
28
|
+
const name = body === '' ? `#${String(issueNumber)}` : `#${String(issueNumber)} ${body}`;
|
|
29
|
+
return pythonRightStrip(truncateCodePoints(name, SESSION_TITLE_MAX_CHARS));
|
|
30
|
+
}
|
|
31
|
+
function lastSegment(issueReference) {
|
|
32
|
+
let end = issueReference.length;
|
|
33
|
+
while (end > 0 && issueReference.charAt(end - 1) === '/')
|
|
34
|
+
end -= 1;
|
|
35
|
+
const trimmed = issueReference.slice(0, end);
|
|
36
|
+
return trimmed.slice(trimmed.lastIndexOf('/') + 1);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
作業ディレクトリ `.pecot/work/<Issue番号>/` の番号。参照(`owner/repo/N` または `N`)の末尾が ASCII の数字でなければ undefined。
|
|
40
|
+
`.pecot/work` の直下は Issue 番号の数字だけにする規約のため、全角数字などは通さない
|
|
41
|
+
*/
|
|
42
|
+
export function workDirectoryName(issueReference) {
|
|
43
|
+
const number = lastSegment(issueReference);
|
|
44
|
+
return /^\d+$/u.test(number) ? number : undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
作業対象として書く内容(.pecot-active と .pecot-session-title)を決める。参照の末尾が整数でなければ InvalidValueError
|
|
48
|
+
*/
|
|
49
|
+
export function planWorkTarget(issueReference, title) {
|
|
50
|
+
const text = lastSegment(issueReference);
|
|
51
|
+
const number = parsePythonInteger(text);
|
|
52
|
+
if (number === undefined)
|
|
53
|
+
throw new InvalidValueError(`invalid literal for int() with base 10: ${pythonStringRepr(text)}`);
|
|
54
|
+
return { active: issueReference, sessionTitle: formatSessionTitle(number, title) };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=state.js.map
|