@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,92 @@
|
|
|
1
|
+
import type { Repository } from '../domain/config.js';
|
|
2
|
+
import type { OptionPlacement } from '../domain/field-options.js';
|
|
3
|
+
import type { JsonObject } from '../domain/json.js';
|
|
4
|
+
import type { JsonValue } from '../domain/python-format.js';
|
|
5
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
6
|
+
import type { GitHubAPIError } from '../infra/github/errors.js';
|
|
7
|
+
import type { ProjectFieldOption } from '../infra/github/projects.js';
|
|
8
|
+
import type { Output } from './output.js';
|
|
9
|
+
/**
|
|
10
|
+
選択肢の定義。isOptional は無くても同期を止めない。placement は足すときの差し込み先の候補(先から使い、無ければ末尾)
|
|
11
|
+
*/
|
|
12
|
+
export interface OptionSpec {
|
|
13
|
+
readonly option: ProjectFieldOption;
|
|
14
|
+
readonly isOptional?: true;
|
|
15
|
+
readonly placement?: readonly OptionPlacement[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
前提を待つ Issue を pecot が置く列
|
|
19
|
+
*/
|
|
20
|
+
export declare const BLOCKED_SPEC: OptionSpec;
|
|
21
|
+
/**
|
|
22
|
+
人の判断を待つ Issue の札。既定の Status の末尾に足す
|
|
23
|
+
*/
|
|
24
|
+
export declare const NEEDS_ATTENTION_SPEC: OptionSpec;
|
|
25
|
+
/**
|
|
26
|
+
既定の Status のフィールド名
|
|
27
|
+
*/
|
|
28
|
+
export declare const STATUS_FIELD_NAME = "Status";
|
|
29
|
+
/**
|
|
30
|
+
workflow フィールドに作る選択肢
|
|
31
|
+
*/
|
|
32
|
+
export declare const WORKFLOW_FIELD_OPTIONS: readonly ProjectFieldOption[];
|
|
33
|
+
export declare const PRIORITY_FIELD_OPTIONS: readonly ProjectFieldOption[];
|
|
34
|
+
export declare const SIZE_FIELD_OPTIONS: readonly ProjectFieldOption[];
|
|
35
|
+
/**
|
|
36
|
+
`could not <action>` に API の失敗の文(と状態コード)を添えて、終了コード 1 で止める
|
|
37
|
+
*/
|
|
38
|
+
export declare function failApi(out: Readonly<Output>, action: string, error: Readonly<GitHubAPIError>): never;
|
|
39
|
+
/**
|
|
40
|
+
Python の str() に当たる文字列。値が無いときは None
|
|
41
|
+
*/
|
|
42
|
+
export declare function textOf(value: JsonValue | undefined): string;
|
|
43
|
+
export declare function isWorkflowField(name: JsonValue | undefined): boolean;
|
|
44
|
+
export declare function hasWorkflowField(fields: readonly JsonValue[]): boolean;
|
|
45
|
+
/**
|
|
46
|
+
プロジェクトの情報から fields.nodes を取る
|
|
47
|
+
*/
|
|
48
|
+
export declare function fieldNodesOf(projectInfo: JsonObject): readonly JsonValue[];
|
|
49
|
+
/**
|
|
50
|
+
タイトルが一致するプロジェクトを一覧から探す。無ければ、選べるタイトルを並べて止める
|
|
51
|
+
*/
|
|
52
|
+
export declare function findProjectByTitle(out: Readonly<Output>, client: Readonly<GitHubClient>, owner: string, name: string): Promise<JsonObject>;
|
|
53
|
+
/**
|
|
54
|
+
workflow フィールドに足りない必須の選択肢(要る順。optional は数えない。名前は大文字と小文字を区別しない)
|
|
55
|
+
*/
|
|
56
|
+
export declare function missingRequiredOptions(field: Readonly<JsonObject>): readonly string[];
|
|
57
|
+
/**
|
|
58
|
+
必須の選択肢が欠けたときの、終了コード 1 の止め方
|
|
59
|
+
*/
|
|
60
|
+
export declare function stopMissingOptions(out: Readonly<Output>, missing: readonly string[]): never;
|
|
61
|
+
/**
|
|
62
|
+
ファイル名に使う slug。小文字にして空白を `-` にし、`a-z0-9-` 以外を落とす
|
|
63
|
+
*/
|
|
64
|
+
export declare function slugify(text: string): string;
|
|
65
|
+
export declare function lastFieldNamed(fields: readonly JsonValue[], name: string): JsonObject | undefined;
|
|
66
|
+
export interface RepositoryParts {
|
|
67
|
+
readonly owner: string;
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly develop_branch?: string | undefined;
|
|
70
|
+
readonly release_branch?: string | undefined;
|
|
71
|
+
readonly changelog_file?: string | undefined;
|
|
72
|
+
readonly packages?: Repository['packages'];
|
|
73
|
+
readonly release_type?: Repository['release_type'];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
リポジトリを、モデルの定義順のキーで作る(保存の JSON のキーの順になる)
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildRepository(parts: Readonly<RepositoryParts>): Repository;
|
|
79
|
+
/**
|
|
80
|
+
GitHub Projects V2 の情報から設定ファイルを作るか更新し、アクティブにする。作った設定ファイルのパスを返す。
|
|
81
|
+
pecot-workflow に合うプロジェクトだけを扱う。suffix はその名前の workflow フィールドを使う。
|
|
82
|
+
skipIfUnchanged は、設定ファイルの内容が同じなら何も書かない。isDryRun は読むだけで、書く操作を planned で出す
|
|
83
|
+
*/
|
|
84
|
+
export declare function syncProjectConfig(out: Readonly<Output>, client: Readonly<GitHubClient>, target: Readonly<{
|
|
85
|
+
owner: string;
|
|
86
|
+
name: string;
|
|
87
|
+
host: string;
|
|
88
|
+
suffix?: string | undefined;
|
|
89
|
+
skipIfUnchanged?: boolean | undefined;
|
|
90
|
+
isDryRun?: boolean | undefined;
|
|
91
|
+
}>): Promise<string>;
|
|
92
|
+
//# sourceMappingURL=project-sync.d.ts.map
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// project の各コマンドが共有する部分。失敗の行、フィールドの検証、設定ファイルの同期(Python の project.py の _sync_project_config まわり)。
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { parseProjectConfig, serializeProjectConfig } from '../domain/config.js';
|
|
5
|
+
import { isJsonObject, jsonField, parseJsonText } from '../domain/json.js';
|
|
6
|
+
import { pythonRepr } from '../domain/python-format.js';
|
|
7
|
+
import { loadConfig, projectsDirectory, saveConfig, setActiveConfig } from '../infra/config-store.js';
|
|
8
|
+
import { asArray, isTruthy, requireNumber, requireString } from '../infra/github/payload.js';
|
|
9
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
10
|
+
import { stopWith } from './command-stop.js';
|
|
11
|
+
import { kindOfFailure } from './failure.js';
|
|
12
|
+
const WORKFLOW_FIELD_PREFIX = 'pecot-workflow-';
|
|
13
|
+
/**
|
|
14
|
+
前提を待つ Issue を pecot が置く列
|
|
15
|
+
*/
|
|
16
|
+
export const BLOCKED_SPEC = {
|
|
17
|
+
option: { name: 'Blocked', color: 'GRAY', description: 'Tasks waiting for prerequisite Issues. pecot moves them to Ready once they can start.' },
|
|
18
|
+
isOptional: true,
|
|
19
|
+
placement: [{ after: 'Backlog' }, { before: 'Ready' }],
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
人の判断を待つ Issue の札。既定の Status の末尾に足す
|
|
23
|
+
*/
|
|
24
|
+
export const NEEDS_ATTENTION_SPEC = {
|
|
25
|
+
option: { name: 'Needs Attention', color: 'RED', description: 'Waiting for a human decision or action.' },
|
|
26
|
+
isOptional: true,
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
既定の Status のフィールド名
|
|
30
|
+
*/
|
|
31
|
+
export const STATUS_FIELD_NAME = 'Status';
|
|
32
|
+
/**
|
|
33
|
+
workflow フィールドの選択肢の定義。作る順でもある
|
|
34
|
+
*/
|
|
35
|
+
const WORKFLOW_FIELD_SPECS = [
|
|
36
|
+
{ option: { name: 'Pending', color: 'GRAY', description: 'Items on hold (Epic or Task). Moved here from Ready or Backlog when deprioritized.' } },
|
|
37
|
+
{ option: { name: 'Backlog', color: 'RED', description: 'Items waiting to be planned. Not for direct work - break down into smaller tasks first.' } },
|
|
38
|
+
BLOCKED_SPEC,
|
|
39
|
+
{ option: { name: 'Ready', color: 'GREEN', description: 'Tasks ready for implementation. AI agent picks from here and moves to Active on start.' } },
|
|
40
|
+
{ option: { name: 'Active', color: 'BLUE', description: 'Currently being worked on. One active task per worktree - track progress and updates here.' } },
|
|
41
|
+
{ option: { name: 'In Review', color: 'YELLOW', description: 'Pull request created and waiting for review. Moves to Archived after merge is completed.' } },
|
|
42
|
+
{ option: { name: 'Archived', color: 'PURPLE', description: 'Completed or cancelled items. Moved here after the issue is closed or no longer needed.' } },
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
workflow フィールドに作る選択肢
|
|
46
|
+
*/
|
|
47
|
+
export const WORKFLOW_FIELD_OPTIONS = WORKFLOW_FIELD_SPECS.map(spec => spec.option);
|
|
48
|
+
export const PRIORITY_FIELD_OPTIONS = [
|
|
49
|
+
{ name: 'High', color: 'RED', description: 'Priority: high' },
|
|
50
|
+
{ name: 'Medium', color: 'YELLOW', description: 'Priority: medium' },
|
|
51
|
+
{ name: 'Low', color: 'GREEN', description: 'Priority: low' },
|
|
52
|
+
];
|
|
53
|
+
export const SIZE_FIELD_OPTIONS = [
|
|
54
|
+
{ name: 'XS', color: 'GREEN', description: 'Size: extra small' },
|
|
55
|
+
{ name: 'S', color: 'BLUE', description: 'Size: small' },
|
|
56
|
+
{ name: 'M', color: 'YELLOW', description: 'Size: medium' },
|
|
57
|
+
{ name: 'L', color: 'RED', description: 'Size: large' },
|
|
58
|
+
];
|
|
59
|
+
/**
|
|
60
|
+
`could not <action>` に API の失敗の文(と状態コード)を添えて、終了コード 1 で止める
|
|
61
|
+
*/
|
|
62
|
+
export function failApi(out, action, error) {
|
|
63
|
+
const detail = error.message;
|
|
64
|
+
const status = error.statusCode ?? 0;
|
|
65
|
+
return stopWith(out, status === 0 ? `could not ${action}: ${detail}` : `could not ${action} (status ${String(status)}): ${detail}`, kindOfFailure(error));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
Python の str() に当たる文字列。値が無いときは None
|
|
69
|
+
*/
|
|
70
|
+
export function textOf(value) {
|
|
71
|
+
if (value === undefined)
|
|
72
|
+
return 'None';
|
|
73
|
+
return typeof value === 'string' ? value : pythonRepr(value);
|
|
74
|
+
}
|
|
75
|
+
export function isWorkflowField(name) {
|
|
76
|
+
return typeof name === 'string' && name.startsWith(WORKFLOW_FIELD_PREFIX);
|
|
77
|
+
}
|
|
78
|
+
export function hasWorkflowField(fields) {
|
|
79
|
+
return fields.some(field => isWorkflowField(jsonField(field, 'name')));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
プロジェクトの情報から fields.nodes を取る
|
|
83
|
+
*/
|
|
84
|
+
export function fieldNodesOf(projectInfo) {
|
|
85
|
+
return asArray(jsonField(jsonField(projectInfo, 'fields'), 'nodes'));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
タイトルが一致するプロジェクトを一覧から探す。無ければ、選べるタイトルを並べて止める
|
|
89
|
+
*/
|
|
90
|
+
export async function findProjectByTitle(out, client, owner, name) {
|
|
91
|
+
const projects = await client.listProjects(owner);
|
|
92
|
+
const found = projects.find(project => jsonField(project, 'title') === name);
|
|
93
|
+
if (found !== undefined)
|
|
94
|
+
return found;
|
|
95
|
+
const titles = projects.map(project => `- ${textOf(jsonField(project, 'title'))}`).join('\n');
|
|
96
|
+
return stopWith(out, `project not found: ${name}\navailable projects:\n${titles}`, 'project-not-found');
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
workflow フィールドに足りない必須の選択肢(要る順。optional は数えない。名前は大文字と小文字を区別しない)
|
|
100
|
+
*/
|
|
101
|
+
export function missingRequiredOptions(field) {
|
|
102
|
+
const existing = new Set(asArray(field['options']).map(option => lowerName(option)));
|
|
103
|
+
return WORKFLOW_FIELD_SPECS.filter(spec => spec.isOptional !== true && !existing.has(spec.option.name.toLowerCase())).map(spec => spec.option.name);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
必須の選択肢が欠けたときの、終了コード 1 の止め方
|
|
107
|
+
*/
|
|
108
|
+
export function stopMissingOptions(out, missing) {
|
|
109
|
+
return stopWith(out, `pecot-workflow field is missing options: ${missing.join(', ')}\nrequired options: Backlog / Pending / Ready / Active / In Review / Archived`, 'not-initialized');
|
|
110
|
+
}
|
|
111
|
+
function lowerName(option) {
|
|
112
|
+
const name = jsonField(option, 'name');
|
|
113
|
+
return typeof name === 'string' ? name.toLowerCase() : '';
|
|
114
|
+
}
|
|
115
|
+
// 選択肢を持つ workflow フィールド。suffix があればその名前のもの、無ければ最初の pecot-workflow-*
|
|
116
|
+
function findWorkflowField(fields, suffix) {
|
|
117
|
+
return fields.find((field) => isJsonObject(field) && Object.hasOwn(field, 'options') && (suffix === undefined ? isWorkflowField(field['name']) : field['name'] === `${WORKFLOW_FIELD_PREFIX}${suffix}`));
|
|
118
|
+
}
|
|
119
|
+
async function fetchValidatedFields(out, client, target) {
|
|
120
|
+
const { owner, name, host, number, suffix } = target;
|
|
121
|
+
const projectInfo = await client.getProjectFields(owner, number);
|
|
122
|
+
if (projectInfo === undefined || !isTruthy(projectInfo))
|
|
123
|
+
return stopWith(out, `could not read project fields: ${name}`, 'not-initialized');
|
|
124
|
+
const fields = fieldNodesOf(projectInfo);
|
|
125
|
+
const workflowField = findWorkflowField(fields, suffix);
|
|
126
|
+
if (workflowField === undefined) {
|
|
127
|
+
return stopWith(out, hinted `project "${name}" has no pecot-workflow-* field
|
|
128
|
+
required field: pecot-workflow-<suffix> (Backlog/Pending/Ready/Active/In Review/Archived)
|
|
129
|
+
run: ${commandHint(['project', 'init'], { owner, name, host, suffix: placeholder('suffix') })}`, 'not-initialized');
|
|
130
|
+
}
|
|
131
|
+
const missing = missingRequiredOptions(workflowField);
|
|
132
|
+
if (missing.length > 0)
|
|
133
|
+
return stopMissingOptions(out, missing);
|
|
134
|
+
const views = asArray(jsonField(jsonField(projectInfo, 'views'), 'nodes'));
|
|
135
|
+
const viewNumber = jsonField(views.at(0), 'number');
|
|
136
|
+
return { workflowField, fields, viewNumber };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
ファイル名に使う slug。小文字にして空白を `-` にし、`a-z0-9-` 以外を落とす
|
|
140
|
+
*/
|
|
141
|
+
export function slugify(text) {
|
|
142
|
+
return text.toLowerCase().replaceAll(' ', '-').replaceAll(/[^a-z0-9-]/gu, '');
|
|
143
|
+
}
|
|
144
|
+
// urllib.parse.quote(text) と同じ。`/` と `_.-~` は残し、それ以外は %XX にする
|
|
145
|
+
function quote(text) {
|
|
146
|
+
return encodeURIComponent(text)
|
|
147
|
+
.replaceAll(/[!'()*]/gu, character => `%${character.codePointAt(0)?.toString(16).toUpperCase() ?? ''}`)
|
|
148
|
+
.replaceAll('%2F', '/');
|
|
149
|
+
}
|
|
150
|
+
function buildBoardUrl(projectUrl, workflowField, viewNumber) {
|
|
151
|
+
const databaseId = workflowField['databaseId'];
|
|
152
|
+
// 空白入りの値(In Review)を末尾に置く(URL の解析の誤りを避ける)
|
|
153
|
+
const present = new Set(asArray(workflowField['options']).map(option => lowerName(option)));
|
|
154
|
+
const names = WORKFLOW_FIELD_SPECS.filter(spec => spec.isOptional !== true || present.has(spec.option.name.toLowerCase())).map(spec => spec.option.name);
|
|
155
|
+
const plain = names.filter(name => !name.includes(' '));
|
|
156
|
+
const spaced = names.filter(name => name.includes(' '));
|
|
157
|
+
const values = [...plain, ...spaced];
|
|
158
|
+
const statusValues = values.map(value => value.includes(' ') ? `"${value}"` : value).join(',');
|
|
159
|
+
const filterQuery = quote(` ${textOf(workflowField['name'])}:${statusValues}`);
|
|
160
|
+
return isTruthy(databaseId) && isTruthy(viewNumber) ? `${projectUrl}/views/${textOf(viewNumber)}?layout=board&verticalGroupedBy%5BcolumnId%5D=${textOf(databaseId)}&filterQuery=${filterQuery}` : `${projectUrl}?filterQuery=${filterQuery}`;
|
|
161
|
+
}
|
|
162
|
+
function keyEntry(name, isOptional) {
|
|
163
|
+
return { key: name.toLowerCase().replaceAll(' ', '_'), label: name.toLowerCase(), isOptional };
|
|
164
|
+
}
|
|
165
|
+
// 設定ファイルのキーの順(保存の JSON のキーの順になる)。isOptional は選択肢の定義の値を使う
|
|
166
|
+
const WORKFLOW_KEY_ORDER = ['Backlog', 'Pending', 'Blocked', 'Ready', 'Active', 'In Review', 'Archived'];
|
|
167
|
+
const WORKFLOW_KEYS = WORKFLOW_KEY_ORDER.map(name => keyEntry(name, WORKFLOW_FIELD_SPECS.some(spec => spec.option.name === name && spec.isOptional === true)));
|
|
168
|
+
const STATUS_KEYS = [keyEntry('Todo', true), keyEntry(NEEDS_ATTENTION_SPEC.option.name, NEEDS_ATTENTION_SPEC.isOptional === true)];
|
|
169
|
+
const PRIORITY_KEYS = ['High', 'Medium', 'Low'].map(name => keyEntry(name, false));
|
|
170
|
+
const SIZE_KEYS = ['XS', 'S', 'M', 'L'].map(name => keyEntry(name, false));
|
|
171
|
+
// isOptional のキーは、ボードに選択肢が無ければ書かない。それ以外は無ければ空文字列で書く
|
|
172
|
+
function fieldOptionsConfig(field, keys) {
|
|
173
|
+
const idsByName = new Map();
|
|
174
|
+
const optionNodes = asArray(field['options']);
|
|
175
|
+
for (const option of optionNodes) {
|
|
176
|
+
const name = jsonField(option, 'name');
|
|
177
|
+
const id = jsonField(option, 'id');
|
|
178
|
+
if (typeof name === 'string' && typeof id === 'string')
|
|
179
|
+
idsByName.set(name.toLowerCase(), id);
|
|
180
|
+
}
|
|
181
|
+
const entries = keys
|
|
182
|
+
.filter(entry => idsByName.has(entry.label) || !entry.isOptional)
|
|
183
|
+
.map((entry) => [entry.key, idsByName.get(entry.label) ?? '']);
|
|
184
|
+
return { id: requireString(field['id'], 'field.id'), options: Object.fromEntries(entries) };
|
|
185
|
+
}
|
|
186
|
+
// 同じ名前のフィールドが複数あれば、後のものを使う
|
|
187
|
+
export function lastFieldNamed(fields, name) {
|
|
188
|
+
return fields.findLast((field) => isJsonObject(field) && field['name'] === name && Object.hasOwn(field, 'options'));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
リポジトリを、モデルの定義順のキーで作る(保存の JSON のキーの順になる)
|
|
192
|
+
*/
|
|
193
|
+
export function buildRepository(parts) {
|
|
194
|
+
return {
|
|
195
|
+
owner: parts.owner,
|
|
196
|
+
name: parts.name,
|
|
197
|
+
develop_branch: parts.develop_branch,
|
|
198
|
+
release_branch: parts.release_branch,
|
|
199
|
+
changelog_file: parts.changelog_file,
|
|
200
|
+
packages: parts.packages,
|
|
201
|
+
release_type: parts.release_type,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
// 既存の設定の順を先にし、リンクの外れたものを落として、新しいものをリンクの順に足す
|
|
205
|
+
function buildRepositories(linked, existing) {
|
|
206
|
+
const linkedKeys = new Map();
|
|
207
|
+
for (const entry of linked) {
|
|
208
|
+
const key = `${entry.owner}/${entry.name}`;
|
|
209
|
+
if (!linkedKeys.has(key))
|
|
210
|
+
linkedKeys.set(key, entry);
|
|
211
|
+
}
|
|
212
|
+
const previous = new Map(existing.map(repository => [`${repository.owner}/${repository.name}`, repository]));
|
|
213
|
+
const keys = [];
|
|
214
|
+
for (const key of previous.keys()) {
|
|
215
|
+
const entry = linkedKeys.get(key);
|
|
216
|
+
if (entry !== undefined)
|
|
217
|
+
keys.push([key, entry]);
|
|
218
|
+
}
|
|
219
|
+
for (const [key, entry] of linkedKeys) {
|
|
220
|
+
if (!previous.has(key))
|
|
221
|
+
keys.push([key, entry]);
|
|
222
|
+
}
|
|
223
|
+
return keys.map(([key, entry]) => buildRepository({ ...previous.get(key), owner: entry.owner, name: entry.name }));
|
|
224
|
+
}
|
|
225
|
+
function loadExistingConfig(configPath) {
|
|
226
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- 設定ディレクトリ配下のパス
|
|
227
|
+
return existsSync(configPath) ? loadConfig(configPath) : undefined;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
GitHub Projects V2 の情報から設定ファイルを作るか更新し、アクティブにする。作った設定ファイルのパスを返す。
|
|
231
|
+
pecot-workflow に合うプロジェクトだけを扱う。suffix はその名前の workflow フィールドを使う。
|
|
232
|
+
skipIfUnchanged は、設定ファイルの内容が同じなら何も書かない。isDryRun は読むだけで、書く操作を planned で出す
|
|
233
|
+
*/
|
|
234
|
+
export async function syncProjectConfig(out, client, target) {
|
|
235
|
+
const { owner, name, host, skipIfUnchanged = false } = target;
|
|
236
|
+
const project = await findProjectByTitle(out, client, owner, name);
|
|
237
|
+
const number = requireNumber(project['number'], 'project.number');
|
|
238
|
+
const { workflowField, fields, viewNumber } = await fetchValidatedFields(out, client, { owner, name, host, number, suffix: target.suffix });
|
|
239
|
+
const suffix = textOf(workflowField['name']).slice(WORKFLOW_FIELD_PREFIX.length);
|
|
240
|
+
const configPath = path.join(projectsDirectory(), `${host}_${owner}_${slugify(name)}_${suffix}.json`);
|
|
241
|
+
const existing = loadExistingConfig(configPath);
|
|
242
|
+
const linked = await client.getLinkedRepositories(owner, number);
|
|
243
|
+
const priorityField = lastFieldNamed(fields, 'pecot-priority');
|
|
244
|
+
const sizeField = lastFieldNamed(fields, 'pecot-size');
|
|
245
|
+
const statusField = lastFieldNamed(fields, STATUS_FIELD_NAME);
|
|
246
|
+
const config = {
|
|
247
|
+
host,
|
|
248
|
+
owner,
|
|
249
|
+
workflow_suffix: suffix,
|
|
250
|
+
project: {
|
|
251
|
+
number,
|
|
252
|
+
id: requireString(project['id'], 'project.id'),
|
|
253
|
+
board_url: buildBoardUrl(typeof project['url'] === 'string' ? project['url'] : '', workflowField, viewNumber),
|
|
254
|
+
fields: {
|
|
255
|
+
workflow: fieldOptionsConfig(workflowField, WORKFLOW_KEYS),
|
|
256
|
+
priority: priorityField === undefined ? undefined : fieldOptionsConfig(priorityField, PRIORITY_KEYS),
|
|
257
|
+
size: sizeField === undefined ? undefined : fieldOptionsConfig(sizeField, SIZE_KEYS),
|
|
258
|
+
status: statusField === undefined ? undefined : fieldOptionsConfig(statusField, STATUS_KEYS),
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
repositories: buildRepositories(linked, existing?.repositories ?? []),
|
|
262
|
+
aggregation_repo: existing?.aggregation_repo,
|
|
263
|
+
};
|
|
264
|
+
// 読み直して保存と同じ形にそろえてから比べる
|
|
265
|
+
const normalized = parseProjectConfig(parseJsonText(serializeProjectConfig(config)));
|
|
266
|
+
if (skipIfUnchanged && existing !== undefined && serializeProjectConfig(existing) === serializeProjectConfig(normalized)) {
|
|
267
|
+
out.planned({ verb: 'unchanged', target: `config file ${configPath}` });
|
|
268
|
+
return configPath;
|
|
269
|
+
}
|
|
270
|
+
const verb = existing === undefined ? 'create' : 'update';
|
|
271
|
+
if (target.isDryRun === true) {
|
|
272
|
+
out.planned({ verb, target: `config file ${configPath}` });
|
|
273
|
+
out.planned({ verb: 'set', target: `active project to ${path.parse(configPath).name}` });
|
|
274
|
+
return configPath;
|
|
275
|
+
}
|
|
276
|
+
saveConfig(config, configPath);
|
|
277
|
+
out.done({ verb, target: `config file ${configPath}` });
|
|
278
|
+
setActiveConfig(configPath);
|
|
279
|
+
out.done({ verb: 'set', target: `active project to ${path.parse(configPath).name}` });
|
|
280
|
+
return configPath;
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=project-sync.js.map
|