@pecot/workflow-mcp 8.0.1-dev.61 → 8.0.1-dev.63

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pecot-w",
3
- "version": "8.0.1-dev.61",
3
+ "version": "8.0.1-dev.63",
4
4
  "description": "pecot-w (pecot-workflow) workflow automation plugin for Claude Code - skills, hooks, agents, and commands for AI-assisted development",
5
5
  "author": {
6
6
  "name": "pecot"
package/README.md CHANGED
@@ -121,6 +121,8 @@ Claude Code では、Claude Code がサーバを起動するディレクトリ
121
121
  | `worktree_init` | メイン worktree に worktree の設定ファイルを作る |
122
122
  | `worktree_link` | 既存の worktree にシンボリックリンクを適用・更新する |
123
123
  | `branch_delete` | リモートブランチを削除する(保護ブランチは消さない) |
124
+ | `workflow_install` | 同梱の GitHub Actions のワークフローの雛形をリポに書き出す(`check` で置いた雛形の版を確かめ、`force` で上書きする) |
125
+ | `workflow_doctor` | 雛形と、雛形が要る Actions の secret・変数の名前がそろっているかを確かめる(値は読まない) |
124
126
 
125
127
  ## 失敗したとき
126
128
 
@@ -27,6 +27,7 @@ export const COMMAND_GROUPS = [
27
27
  { name: 'tracker', meaning: 'Tracker の Issue の書き直し', help: 'Rewrite the list in a Tracker Issue' },
28
28
  { name: 'worktree', meaning: 'worktree', help: 'Work with worktrees' },
29
29
  { name: 'branch', meaning: 'リモートのブランチ', help: 'Work with remote branches' },
30
+ { name: 'workflow', meaning: '導入先のリポに置く GitHub Actions のワークフロー', help: 'Install and check the GitHub Actions workflows of pecot' },
30
31
  ];
31
32
  /**
32
33
  コマンド名の 2 語目に使う動詞の語彙。1 語に 1 つの意味を決める
@@ -37,11 +38,13 @@ export const COMMAND_VERBS = [
37
38
  { name: 'show', meaning: '1 件を出す', readOnly: true },
38
39
  { name: 'get', meaning: '設定の値を出す', readOnly: true },
39
40
  { name: 'check', meaning: '次の操作の前に確かめる', readOnly: true },
41
+ { name: 'doctor', meaning: '導入に要る設定がそろっているかを確かめる', readOnly: true },
40
42
  { name: 'create', meaning: 'GitHub のものを作る' },
41
43
  { name: 'delete', meaning: 'GitHub のものを消す' },
42
44
  { name: 'add', meaning: '集まりに入れる' },
43
45
  { name: 'remove', meaning: '集まりから出す' },
44
46
  { name: 'init', meaning: '既にあるものを pecot で使える状態にする' },
47
+ { name: 'install', meaning: '雛形をリポに書き出す' },
45
48
  { name: 'set', meaning: '設定のキーに値を入れる' },
46
49
  { name: 'unset', meaning: '設定のキーの値を消す' },
47
50
  { name: 'link', meaning: 'リポジトリをプロジェクトにつなぐ' },
@@ -12,6 +12,7 @@ import { RELEASE_COMMANDS } from './release.js';
12
12
  import { SESSION_COMMANDS } from './session.js';
13
13
  import { TRACKER_COMMANDS } from './tracker.js';
14
14
  import { WORKTREE_COMMANDS } from './worktree.js';
15
+ import { WORKFLOW_COMMANDS } from './workflow.js';
15
16
  export { defineCommand, toolNameOf } from './command-definition.js';
16
17
  // 並びは help の一覧の順で、names.ts の COMMAND_GROUPS の順に合わせる
17
18
  export const COMMANDS = [
@@ -26,6 +27,7 @@ export const COMMANDS = [
26
27
  ...TRACKER_COMMANDS,
27
28
  ...WORKTREE_COMMANDS,
28
29
  ...BRANCH_COMMANDS,
30
+ ...WORKFLOW_COMMANDS,
29
31
  ];
30
32
  registerCommandHints(COMMANDS);
31
33
  export function findCommand(path, commands = COMMANDS) {
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const WORKFLOW_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=workflow.d.ts.map
@@ -0,0 +1,176 @@
1
+ // workflow install・workflow doctor。導入先のリポに雛形を置き、版と要る設定を確かめる。
2
+ import { z } from 'zod';
3
+ import { formatHinted } from '../domain/command-hint.js';
4
+ import { evaluateRequirements, findWorkflowTemplate, isOutdated, readTemplateVersion, userLines, WORKFLOW_TEMPLATES } from '../domain/workflow-template.js';
5
+ import { gitToplevel, primaryRemoteRepository } from '../infra/git.js';
6
+ import { TransportFailure } from '../infra/github/client.js';
7
+ import { GitHubAPIError } from '../infra/github/errors.js';
8
+ import { readBundledWorkflow, readInstalledWorkflow, writeWorkflow } from '../infra/workflow-file.js';
9
+ import { defineCommand } from './command-definition.js';
10
+ import { commandHint, hinted, inputNameHint, joinHinted } from './command-hint.js';
11
+ import { stopWith } from './command-stop.js';
12
+ import { directorySchema } from './directory-option.js';
13
+ import { kindOfFailure } from './failure.js';
14
+ import { apiFailureMessage, createGitHubClient } from './github-client.js';
15
+ import { createOutput, DRY_RUN_FIELD } from './output.js';
16
+ import { USAGE_EXIT_CODE } from './usage-error.js';
17
+ const NAME_INPUT = z.string().describe(`Name of the workflow template (${WORKFLOW_TEMPLATES.map(template => template.name).join(', ')})`);
18
+ const DIRECTORY_INPUT = directorySchema.optional().describe('Root of the target Git repository (absolute or relative path; default: the current directory)');
19
+ function requireTemplate(out, name) {
20
+ return findWorkflowTemplate(name) ?? stopWith(out, `unknown workflow template: ${name}\navailable: ${WORKFLOW_TEMPLATES.map(item => item.name).join(', ')}`, 'invalid-input', USAGE_EXIT_CODE);
21
+ }
22
+ // 置き先はリポのルートから決めるので、サブディレクトリで打ってもルートに置く
23
+ function repositoryRoot(out, directory) {
24
+ const start = directory ?? process.cwd();
25
+ return gitToplevel({ cwd: start }) ?? stopWith(out, `${start} is not in a Git repository`, 'git-unresolved');
26
+ }
27
+ function versionOf(text) {
28
+ return text === undefined ? undefined : readTemplateVersion(text)?.version;
29
+ }
30
+ const INSTALL_OUTPUT = z.strictObject({
31
+ path: z.string().describe('Path of the workflow file from the repository root'),
32
+ version: z.number().describe('Version of the bundled template'),
33
+ installedVersion: z.number().optional().describe('Version of the file already in the repository; omitted when there is no file or no version marker'),
34
+ written: z.boolean().describe('Whether the file was written (false on check and dry_run)'),
35
+ upToDate: z.boolean().optional().describe('With check: whether the file in the repository has the version of the bundled template'),
36
+ removedLines: z.array(z.string()).optional().describe('With force: lines you added between the begin and end markers, which the bundled template replaces'),
37
+ dryRun: DRY_RUN_FIELD,
38
+ });
39
+ const INSTALL_PATH = ['workflow', 'install'];
40
+ function nextSteps(template) {
41
+ const settings = template.requirements.filter(requirement => requirement.type === 'anyOf').map(requirement => `set ${requirement.missing} in Settings > Secrets and variables > Actions`);
42
+ const steps = ['install the Claude GitHub App on the repository', ...settings];
43
+ return joinHinted([
44
+ 'next:',
45
+ ...steps.map((step, index) => ` ${String(index + 1)}. ${step}`),
46
+ hinted ` ${String(steps.length + 1)}. check the settings with: ${commandHint(['workflow', 'doctor'], { name: template.name })}`,
47
+ ]);
48
+ }
49
+ const workflowInstallCommand = defineCommand({
50
+ path: ['workflow', 'install'],
51
+ description: 'Write a GitHub Actions workflow template of pecot into the repository',
52
+ input: z.strictObject({
53
+ name: NAME_INPUT,
54
+ check: z.boolean().default(false).describe('Write nothing; check that the file in the repository has the version of the bundled template'),
55
+ force: z.boolean().default(false).describe('Overwrite the file when it already exists'),
56
+ dry_run: z.boolean().default(false).describe('Show what would be written without writing anything'),
57
+ directory: DIRECTORY_INPUT,
58
+ }),
59
+ output: INSTALL_OUTPUT,
60
+ positional: ['name'],
61
+ shortFlags: { dry_run: '-n', directory: '-D' },
62
+ interactive: false,
63
+ run: async (input, io) => {
64
+ await Promise.resolve();
65
+ const out = createOutput(input.dry_run, io);
66
+ if (input.check && (input.force || input.dry_run)) {
67
+ const message = hinted `${inputNameHint(INSTALL_PATH, 'check')} cannot be used with ${inputNameHint(INSTALL_PATH, 'force')} or ${inputNameHint(INSTALL_PATH, 'dry_run')}`;
68
+ return stopWith(out, message, 'invalid-input', USAGE_EXIT_CODE);
69
+ }
70
+ const template = requireTemplate(out, input.name);
71
+ const root = repositoryRoot(out, input.directory);
72
+ const bundled = readBundledWorkflow(template);
73
+ const version = versionOf(bundled) ?? 0;
74
+ const installed = readInstalledWorkflow(root, template);
75
+ const installedVersion = versionOf(installed);
76
+ const base = { path: template.destination, version, ...installedVersion !== undefined && { installedVersion } };
77
+ if (input.check) {
78
+ const isUpToDate = installed !== undefined && !isOutdated(installed, bundled);
79
+ out.result({ ...base, written: false, upToDate: isUpToDate });
80
+ if (isUpToDate) {
81
+ out.done({ verb: 'unchanged', target: `${template.destination} (workflow template ${template.name} ${String(version)})` });
82
+ return 0;
83
+ }
84
+ const state = installed === undefined ? `${template.destination} is missing` : `workflow template ${template.name} is outdated (installed ${installedVersion === undefined ? 'unknown' : String(installedVersion)}, bundled ${String(version)})`;
85
+ const run = commandHint(INSTALL_PATH, { name: template.name, ...installed !== undefined && { force: true } });
86
+ return stopWith(out, hinted `${state}\nupdate it with: ${run}`, 'not-ready');
87
+ }
88
+ if (installed !== undefined && !input.force) {
89
+ return stopWith(out, hinted `${template.destination} already exists\noverwrite it with: ${commandHint(INSTALL_PATH, { name: template.name, force: true })}`, 'already-exists', USAGE_EXIT_CODE);
90
+ }
91
+ const removed = installed === undefined ? [] : userLines(installed, bundled);
92
+ if (removed.length > 0)
93
+ out.warning(`these lines between the markers will be removed:\n${removed.join('\n')}`);
94
+ const operation = { verb: installed === undefined ? 'create' : 'update', target: template.destination };
95
+ const result = { ...base, ...installed !== undefined && { removedLines: [...removed] } };
96
+ if (input.dry_run) {
97
+ out.planned(operation);
98
+ out.result({ ...result, written: false });
99
+ return 0;
100
+ }
101
+ writeWorkflow(root, template, bundled);
102
+ out.done(operation);
103
+ out.data(formatHinted(nextSteps(template), io.surface ?? 'cli'));
104
+ out.result({ ...result, written: true });
105
+ return 0;
106
+ },
107
+ });
108
+ const DOCTOR_ITEM = z.strictObject({
109
+ name: z.string().describe('What was checked: the workflow file, the template version, a secret or variable, or the Claude GitHub App'),
110
+ state: z.enum(['ok', 'missing', 'outdated', 'skipped']).describe('ok, missing, outdated, or skipped (not readable with the token; not counted as missing)'),
111
+ });
112
+ const DOCTOR_OUTPUT = z.strictObject({
113
+ repository: z.string().describe('Repository of the git remote (owner/repo)'),
114
+ items: z.array(DOCTOR_ITEM).describe('Checked items in the order of the output lines'),
115
+ ready: z.boolean().describe('Whether nothing is missing or outdated'),
116
+ });
117
+ // Claude の App が入っているかは、リポのトークンでは読めない
118
+ const CLAUDE_APP_ITEM = { name: 'Claude GitHub App', state: 'skipped' };
119
+ // 読めた一覧の名前を合わせる。読めなかった一覧があれば complete を false にする
120
+ function mergeNames(lists) {
121
+ return { names: new Set(lists.flatMap(list => list ?? [])), complete: !lists.includes(undefined) };
122
+ }
123
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない
124
+ async function readSettingNames(client, owner, repository) {
125
+ const ownerType = await client.getRepositoryOwnerType(owner, repository);
126
+ const scopes = ownerType === 'Organization' ? ['repository', 'organization'] : ['repository'];
127
+ const [secrets, variables] = await Promise.all([
128
+ Promise.all(scopes.map(async (scope) => await client.listActionsSecretNames(owner, repository, scope))),
129
+ Promise.all(scopes.map(async (scope) => await client.listActionsVariableNames(owner, repository, scope))),
130
+ ]);
131
+ return { secrets: mergeNames(secrets), variables: mergeNames(variables) };
132
+ }
133
+ const workflowDoctorCommand = defineCommand({
134
+ path: ['workflow', 'doctor'],
135
+ description: 'Check that the repository has the workflow file and the settings it needs',
136
+ input: z.strictObject({
137
+ name: NAME_INPUT,
138
+ directory: DIRECTORY_INPUT,
139
+ }),
140
+ output: DOCTOR_OUTPUT,
141
+ positional: ['name'],
142
+ shortFlags: { directory: '-D' },
143
+ interactive: false,
144
+ run: async (input, io) => {
145
+ const out = createOutput(false, io);
146
+ const template = requireTemplate(out, input.name);
147
+ const root = repositoryRoot(out, input.directory);
148
+ const location = primaryRemoteRepository(root);
149
+ if (location === undefined)
150
+ return stopWith(out, 'cannot read the repository from the git remote\ncheck it with: git remote -v', 'git-unresolved');
151
+ const { owner, repository } = location;
152
+ const installed = readInstalledWorkflow(root, template);
153
+ const fileItems = installed === undefined
154
+ ? [{ name: template.destination, state: 'missing' }]
155
+ : [
156
+ { name: template.destination, state: 'ok' },
157
+ { name: `workflow template ${template.name}`, state: isOutdated(installed, readBundledWorkflow(template)) ? 'outdated' : 'ok' },
158
+ ];
159
+ let names;
160
+ try {
161
+ names = await readSettingNames(createGitHubClient(out, location.host), owner, repository);
162
+ }
163
+ catch (error) {
164
+ if (!(error instanceof GitHubAPIError || error instanceof TransportFailure))
165
+ throw error;
166
+ return stopWith(out, `could not read the settings of ${owner}/${repository}: ${apiFailureMessage(error)}`, kindOfFailure(error) === 'other' ? 'github-api' : kindOfFailure(error));
167
+ }
168
+ const items = [...fileItems, ...evaluateRequirements(template.requirements, names), CLAUDE_APP_ITEM];
169
+ out.data(items.map(item => `${item.state}: ${item.name}`).join('\n'));
170
+ const failing = items.filter(item => item.state === 'missing' || item.state === 'outdated');
171
+ out.result({ repository: `${owner}/${repository}`, items, ready: failing.length === 0 });
172
+ return failing.length > 0 ? stopWith(out, `${String(failing.length)} item(s) of workflow ${template.name} are missing or outdated`, 'repo-setting-missing') : 0;
173
+ },
174
+ });
175
+ export const WORKFLOW_COMMANDS = [workflowInstallCommand, workflowDoctorCommand];
176
+ //# sourceMappingURL=workflow.js.map
@@ -0,0 +1,78 @@
1
+ /**
2
+ secret か変数の名前 1 つ
3
+ */
4
+ export interface SettingName {
5
+ readonly kind: 'secret' | 'variable';
6
+ readonly name: string;
7
+ }
8
+ /**
9
+ 雛形が動くのに要る設定。
10
+ - when: 変数 `when` があるときだけ、`require` が要る
11
+ - anyOf: 候補のどれか 1 つの組が、全部そろっている
12
+ */
13
+ export type SettingRequirement = {
14
+ readonly type: 'when';
15
+ readonly when: SettingName;
16
+ readonly require: SettingName;
17
+ readonly missing: string;
18
+ } | {
19
+ readonly type: 'anyOf';
20
+ readonly options: readonly (readonly SettingName[])[];
21
+ readonly missing: string;
22
+ };
23
+ export interface WorkflowTemplate {
24
+ readonly name: string;
25
+ /**
26
+ `cli/templates/workflow/` の下のファイル名
27
+ */
28
+ readonly templateFile: string;
29
+ /**
30
+ リポのルートからの置き先
31
+ */
32
+ readonly destination: string;
33
+ readonly requirements: readonly SettingRequirement[];
34
+ }
35
+ /**
36
+ 雛形の一覧。雛形を足すときは行を足す
37
+ */
38
+ export declare const WORKFLOW_TEMPLATES: readonly WorkflowTemplate[];
39
+ export declare function findWorkflowTemplate(name: string): WorkflowTemplate | undefined;
40
+ export interface TemplateVersion {
41
+ readonly name: string;
42
+ readonly version: number;
43
+ }
44
+ /**
45
+ 1 行目の `# pecot-workflow-template: <名前> <版>` を読む。無ければ undefined
46
+ */
47
+ export declare function readTemplateVersion(text: string): TemplateVersion | undefined;
48
+ /**
49
+ 置いたファイルが同梱の雛形より古いか。目印の無いもの、名前の違うもの、版の小さいものを古いとする
50
+ */
51
+ export declare function isOutdated(installed: string, bundled: string): boolean;
52
+ /**
53
+ 置いたファイルの begin・end の囲みの中で、同梱の雛形の同じ囲みに無い行。
54
+ 同梱の雛形と比べるので、後の版で囲みの中の既定の行を変えると、古い既定の行もここに出る(警告に出るだけなので許す)
55
+ */
56
+ export declare function userLines(installed: string, bundled: string): readonly string[];
57
+ /**
58
+ 読めた一覧の名前と、読めなかった一覧が無いか(complete)
59
+ */
60
+ export interface SettingList {
61
+ readonly names: ReadonlySet<string>;
62
+ readonly complete: boolean;
63
+ }
64
+ export interface SettingNames {
65
+ readonly secrets: SettingList;
66
+ readonly variables: SettingList;
67
+ }
68
+ export type RequirementState = 'ok' | 'missing' | 'skipped';
69
+ export interface RequirementResult {
70
+ readonly name: string;
71
+ readonly state: RequirementState;
72
+ }
73
+ /**
74
+ 要件ごとに、そろっているか(ok)・足りないか(missing)・読めない一覧に頼るので決まらないか(skipped)を返す。
75
+ 条件の名前が無い要件は返さない
76
+ */
77
+ export declare function evaluateRequirements(requirements: readonly SettingRequirement[], names: Readonly<SettingNames>): readonly RequirementResult[];
78
+ //# sourceMappingURL=workflow-template.d.ts.map
@@ -0,0 +1,120 @@
1
+ // 導入先のリポに置くワークフローの雛形の一覧と、版・利用者の行・要る設定の判定。
2
+ const AGENT_ANTHROPIC_VARIABLES = ['FEDERATION_RULE_ID', 'ORGANIZATION_ID', 'SERVICE_ACCOUNT_ID', 'WORKSPACE_ID']
3
+ .map(suffix => ({ kind: 'variable', name: `PECOT_AGENT_ANTHROPIC_${suffix}` }));
4
+ /**
5
+ エージェント用の認証。自動処理が同じ名前で読む(spec 027 の data-model の「エージェント用の認証」)
6
+ */
7
+ const AGENT_REQUIREMENTS = [
8
+ {
9
+ type: 'when',
10
+ when: { kind: 'variable', name: 'PECOT_AGENT_APP_CLIENT_ID' },
11
+ require: { kind: 'secret', name: 'PECOT_AGENT_APP_PRIVATE_KEY' },
12
+ missing: 'secret PECOT_AGENT_APP_PRIVATE_KEY',
13
+ },
14
+ {
15
+ type: 'anyOf',
16
+ options: [[{ kind: 'secret', name: 'CLAUDE_CODE_OAUTH_TOKEN' }], AGENT_ANTHROPIC_VARIABLES],
17
+ missing: 'secret CLAUDE_CODE_OAUTH_TOKEN or variables PECOT_AGENT_ANTHROPIC_*',
18
+ },
19
+ ];
20
+ /**
21
+ 雛形の一覧。雛形を足すときは行を足す
22
+ */
23
+ export const WORKFLOW_TEMPLATES = [
24
+ { name: 'review', templateFile: 'pecot-review.yml', destination: '.github/workflows/pecot-review.yml', requirements: AGENT_REQUIREMENTS },
25
+ ];
26
+ export function findWorkflowTemplate(name) {
27
+ return WORKFLOW_TEMPLATES.find(template => template.name === name);
28
+ }
29
+ const VERSION_MARKER = /^# pecot-workflow-template: (\S+) (\d+)\s*$/u;
30
+ /**
31
+ 1 行目の `# pecot-workflow-template: <名前> <版>` を読む。無ければ undefined
32
+ */
33
+ export function readTemplateVersion(text) {
34
+ const match = VERSION_MARKER.exec(text.split('\n', 1)[0] ?? '');
35
+ return match === null ? undefined : { name: match[1] ?? '', version: Number(match[2]) };
36
+ }
37
+ /**
38
+ 置いたファイルが同梱の雛形より古いか。目印の無いもの、名前の違うもの、版の小さいものを古いとする
39
+ */
40
+ export function isOutdated(installed, bundled) {
41
+ const current = readTemplateVersion(installed);
42
+ const latest = readTemplateVersion(bundled);
43
+ if (latest === undefined)
44
+ throw new Error('the bundled template has no version marker');
45
+ return current?.name !== latest.name || current.version < latest.version;
46
+ }
47
+ const BLOCK_MARKER = /^\s*# pecot-[\w-]+:([\w-]+):(begin|end)\s*$/u;
48
+ function blocksOf(text) {
49
+ const blocks = new Map();
50
+ let current;
51
+ for (const line of text.split('\n')) {
52
+ const match = BLOCK_MARKER.exec(line);
53
+ if (match === null) {
54
+ current?.push(line);
55
+ continue;
56
+ }
57
+ if (match[2] === 'begin') {
58
+ current = [];
59
+ blocks.set(match[1] ?? '', current);
60
+ }
61
+ else {
62
+ current = undefined;
63
+ }
64
+ }
65
+ return blocks;
66
+ }
67
+ /**
68
+ 置いたファイルの begin・end の囲みの中で、同梱の雛形の同じ囲みに無い行。
69
+ 同梱の雛形と比べるので、後の版で囲みの中の既定の行を変えると、古い既定の行もここに出る(警告に出るだけなので許す)
70
+ */
71
+ export function userLines(installed, bundled) {
72
+ const bundledBlocks = blocksOf(bundled);
73
+ return [...blocksOf(installed)].flatMap(([block, lines]) => {
74
+ const known = new Set(bundledBlocks.get(block));
75
+ return lines.filter(line => line.trim() !== '' && !known.has(line));
76
+ });
77
+ }
78
+ // 名前の有無。見つからず、読めなかった一覧があるなら undefined
79
+ function has(names, setting) {
80
+ const list = setting.kind === 'secret' ? names.secrets : names.variables;
81
+ if (list.names.has(setting.name))
82
+ return true;
83
+ return list.complete ? false : undefined;
84
+ }
85
+ function allPresent(names, settings) {
86
+ const found = new Set(settings.map(setting => has(names, setting)));
87
+ if (found.has(false))
88
+ return false;
89
+ return found.has(undefined) ? undefined : true;
90
+ }
91
+ // 条件の付いた要件で、条件の名前が無いと undefined(項目にしない)
92
+ function stateOf(names, requirement) {
93
+ if (requirement.type === 'when') {
94
+ const condition = has(names, requirement.when);
95
+ if (condition === false)
96
+ return undefined;
97
+ const required = has(names, requirement.require);
98
+ if (required === true)
99
+ return 'ok';
100
+ return condition === undefined || required === undefined ? 'skipped' : 'missing';
101
+ }
102
+ const found = new Set(requirement.options.map(option => allPresent(names, option)));
103
+ if (found.has(true))
104
+ return 'ok';
105
+ return found.has(undefined) ? 'skipped' : 'missing';
106
+ }
107
+ /**
108
+ 要件ごとに、そろっているか(ok)・足りないか(missing)・読めない一覧に頼るので決まらないか(skipped)を返す。
109
+ 条件の名前が無い要件は返さない
110
+ */
111
+ export function evaluateRequirements(requirements, names) {
112
+ const results = [];
113
+ for (const requirement of requirements) {
114
+ const state = stateOf(names, requirement);
115
+ if (state !== undefined)
116
+ results.push({ name: requirement.missing, state });
117
+ }
118
+ return results;
119
+ }
120
+ //# sourceMappingURL=workflow-template.js.map
@@ -18,11 +18,16 @@ export interface GraphqlRateLimit {
18
18
  */
19
19
  readonly reset: number;
20
20
  }
21
+ /**
22
+ Actions の secret と変数を読む単位。organization は、organization の値のうち、そのリポに渡るもの
23
+ */
24
+ export type ActionsScope = 'repository' | 'organization';
21
25
  export declare class ReposApi extends GitHubClientBase {
26
+ private listNamesOrUndefined;
22
27
  /**
23
28
  Link ヘッダの next を最後まで辿る。2 ページ目以降は next の絶対 URL を使い、params を再送すると cursor と二重になる
24
29
  */
25
- protected listAll(path: string, firstParameters: Readonly<Record<string, number | string>>): Promise<readonly JsonValue[]>;
30
+ protected listAll(path: string, firstParameters: Readonly<Record<string, number | string>>, itemsKey?: string): Promise<readonly JsonValue[]>;
26
31
  /**
27
32
  GraphQL の点数の上限・使用量・残り・窓の切り替わり(REST の /rate_limit。点数を使わない)。読めない・形が違うときは undefined
28
33
  */
@@ -58,6 +63,18 @@ export declare class ReposApi extends GitHubClientBase {
58
63
  */
59
64
  createRelease(owner: string, repository: string, tagName: string, name: string, body: string, options?: Readonly<CreateReleaseOptions>): Promise<JsonObject>;
60
65
  /**
66
+ Actions の secret の名前の一覧。scope が organization なら、organization の secret のうち、このリポに渡るもの
67
+ */
68
+ listActionsSecretNames(owner: string, repository: string, scope: ActionsScope): Promise<readonly string[] | undefined>;
69
+ /**
70
+ Actions の変数の名前の一覧。scope が organization なら、organization の変数のうち、このリポに渡るもの
71
+ */
72
+ listActionsVariableNames(owner: string, repository: string, scope: ActionsScope): Promise<readonly string[] | undefined>;
73
+ /**
74
+ リポジトリの持ち主の種類(`User`・`Organization`)。読めない形なら undefined
75
+ */
76
+ getRepositoryOwnerType(owner: string, repository: string): Promise<string | undefined>;
77
+ /**
61
78
  リポジトリの既定ブランチ名
62
79
  */
63
80
  getRepositoryDefaultBranch(owner: string, repository: string): Promise<string>;
@@ -1,18 +1,35 @@
1
1
  // リポジトリ・ブランチ・リリース操作の API。cli/core/github/repos.py の移植。
2
2
  import { jsonField } from '../../domain/json.js';
3
3
  import { GitHubClientBase } from './client.js';
4
- import { GitHubAPIError, GitHubNotFoundError } from './errors.js';
4
+ import { GitHubAPIError, GitHubNotFoundError, GitHubRateLimitError } from './errors.js';
5
5
  import { asArray, isTruthy, requireString } from './payload.js';
6
6
  import { MUTATION_CREATE_LINKED_BRANCH, QUERY_GET_REPOSITORY_ID } from './queries.js';
7
7
  import { encodePath, encodePathSegment, repositoryPath } from './rest-path.js';
8
8
  const ALERTS_PER_PAGE = 100;
9
+ // 一覧の per_page の上限。secret は 100、変数は 30(REST の文書)
10
+ const SECRETS_PER_PAGE = 100;
11
+ const VARIABLES_PER_PAGE = 30;
9
12
  const NO_CONTENT = 204;
13
+ const FORBIDDEN = 403;
10
14
  const NOT_FOUND = 404;
11
15
  export class ReposApi extends GitHubClientBase {
16
+ // 名前だけを返し、変数の値は外へ渡さない。読めない(403・404)ときは undefined
17
+ async listNamesOrUndefined(path, perPage, itemsKey) {
18
+ let items;
19
+ try {
20
+ items = await this.listAll(path, { per_page: perPage }, itemsKey);
21
+ }
22
+ catch (error) {
23
+ if (error instanceof GitHubAPIError && (error.statusCode === FORBIDDEN || error.statusCode === NOT_FOUND) && !(error instanceof GitHubRateLimitError))
24
+ return undefined;
25
+ throw error;
26
+ }
27
+ return items.map(item => jsonField(item, 'name')).filter(name => typeof name === 'string');
28
+ }
12
29
  /**
13
30
  Link ヘッダの next を最後まで辿る。2 ページ目以降は next の絶対 URL を使い、params を再送すると cursor と二重になる
14
31
  */
15
- async listAll(path, firstParameters) {
32
+ async listAll(path, firstParameters, itemsKey) {
16
33
  const items = [];
17
34
  let target = path;
18
35
  let parameters = firstParameters;
@@ -20,7 +37,9 @@ export class ReposApi extends GitHubClientBase {
20
37
  const response = await this.restRequest('GET', target, { params: parameters });
21
38
  if (!response.isSuccess)
22
39
  this.handleHttpError(response);
23
- items.push(...asArray(response.json()));
40
+ // 応答が `{ total_count, <itemsKey>: [...] }` の形の一覧は、キーで配列を取り出す
41
+ const body = response.json();
42
+ items.push(...asArray(itemsKey === undefined ? body : jsonField(body, itemsKey)));
24
43
  const next = response.links.get('next');
25
44
  if (next === undefined)
26
45
  return items;
@@ -123,6 +142,28 @@ export class ReposApi extends GitHubClientBase {
123
142
  return this.restObject('POST', `${repositoryPath(owner, repository)}/releases`, { json: data });
124
143
  }
125
144
  /**
145
+ Actions の secret の名前の一覧。scope が organization なら、organization の secret のうち、このリポに渡るもの
146
+ */
147
+ async listActionsSecretNames(owner, repository, scope) {
148
+ const kind = scope === 'organization' ? 'organization-secrets' : 'secrets';
149
+ return await this.listNamesOrUndefined(`${repositoryPath(owner, repository)}/actions/${kind}`, SECRETS_PER_PAGE, 'secrets');
150
+ }
151
+ /**
152
+ Actions の変数の名前の一覧。scope が organization なら、organization の変数のうち、このリポに渡るもの
153
+ */
154
+ async listActionsVariableNames(owner, repository, scope) {
155
+ const kind = scope === 'organization' ? 'organization-variables' : 'variables';
156
+ return await this.listNamesOrUndefined(`${repositoryPath(owner, repository)}/actions/${kind}`, VARIABLES_PER_PAGE, 'variables');
157
+ }
158
+ /**
159
+ リポジトリの持ち主の種類(`User`・`Organization`)。読めない形なら undefined
160
+ */
161
+ async getRepositoryOwnerType(owner, repository) {
162
+ const repositoryInfo = await this.restJson('GET', repositoryPath(owner, repository));
163
+ const type = jsonField(jsonField(repositoryInfo, 'owner'), 'type');
164
+ return typeof type === 'string' ? type : undefined;
165
+ }
166
+ /**
126
167
  リポジトリの既定ブランチ名
127
168
  */
128
169
  async getRepositoryDefaultBranch(owner, repository) {
@@ -1,5 +1,5 @@
1
1
  import type { SectionHeading } from '../domain/sections.js';
2
- export type TemplateKind = 'issue' | 'comment' | 'pr';
2
+ export type TemplateKind = 'issue' | 'comment' | 'pr' | 'workflow';
3
3
  /**
4
4
  種別ごとのテンプレートのディレクトリ
5
5
  */
@@ -0,0 +1,14 @@
1
+ import type { WorkflowTemplate } from '../domain/workflow-template.js';
2
+ /**
3
+ 同梱の雛形の中身
4
+ */
5
+ export declare function readBundledWorkflow(template: Readonly<WorkflowTemplate>): string;
6
+ /**
7
+ リポに置いたファイルの中身。無ければ undefined
8
+ */
9
+ export declare function readInstalledWorkflow(root: string, template: Readonly<WorkflowTemplate>): string | undefined;
10
+ /**
11
+ 置き先に書き出す。ディレクトリが無ければ作る
12
+ */
13
+ export declare function writeWorkflow(root: string, template: Readonly<WorkflowTemplate>, content: string): void;
14
+ //# sourceMappingURL=workflow-file.d.ts.map
@@ -0,0 +1,28 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは雛形の一覧の置き先と、利用者が渡した -D から決まる */
2
+ // ワークフローの雛形を読み、導入先のリポに書き出す。
3
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { templatesDirectory } from './template-store.js';
6
+ import { readTextFile } from './text-file.js';
7
+ /**
8
+ 同梱の雛形の中身
9
+ */
10
+ export function readBundledWorkflow(template) {
11
+ return readTextFile(path.join(templatesDirectory('workflow'), template.templateFile));
12
+ }
13
+ /**
14
+ リポに置いたファイルの中身。無ければ undefined
15
+ */
16
+ export function readInstalledWorkflow(root, template) {
17
+ const file = path.join(root, template.destination);
18
+ return existsSync(file) ? readTextFile(file) : undefined;
19
+ }
20
+ /**
21
+ 置き先に書き出す。ディレクトリが無ければ作る
22
+ */
23
+ export function writeWorkflow(root, template, content) {
24
+ const file = path.join(root, template.destination);
25
+ mkdirSync(path.dirname(file), { recursive: true });
26
+ writeFileSync(file, content);
27
+ }
28
+ //# sourceMappingURL=workflow-file.js.map
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "8.0.1-dev.61",
3
+ "version": "8.0.1-dev.63",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@pecot/workflow-mcp",
9
- "version": "8.0.1-dev.61",
9
+ "version": "8.0.1-dev.63",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/server": "^2.4.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pecot/workflow-mcp",
3
- "version": "8.0.1-dev.61",
3
+ "version": "8.0.1-dev.63",
4
4
  "type": "module",
5
5
  "description": "pecot-workflow MCP server (standalone distribution)",
6
6
  "license": "MIT",