@pecot/workflow-mcp 8.0.1-dev.59 → 8.0.1-dev.60
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 +1 -1
- package/cli/dist/commands/base-reading.d.ts +1 -1
- package/cli/dist/commands/base-reading.js +1 -1
- package/cli/dist/commands/board-sync.js +1 -1
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +12 -4
- package/cli/dist/commands/issue-comment.js +3 -2
- package/cli/dist/commands/issue-show.js +3 -2
- package/cli/dist/commands/output.d.ts +4 -0
- package/cli/dist/commands/output.js +1 -0
- package/cli/dist/commands/pr-merge.js +3 -2
- package/cli/dist/commands/pr-restack.js +16 -9
- package/cli/dist/commands/pr.js +18 -18
- package/cli/dist/commands/project.js +5 -3
- package/cli/dist/commands/release.js +8 -8
- package/cli/dist/commands/restack-reading.d.ts +4 -0
- package/cli/dist/commands/restack-reading.js +1 -1
- package/cli/dist/commands/session-finish.js +18 -8
- package/cli/dist/commands/session.js +1 -1
- package/cli/dist/commands/tracker-sync-dependabot.js +1 -1
- package/cli/dist/commands/tracker-sync-security.js +1 -1
- package/cli/dist/commands/worktree.js +4 -3
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/release.d.ts +10 -1
- package/cli/dist/domain/release.js +10 -6
- package/cli/dist/infra/git.d.ts +20 -16
- package/cli/dist/infra/git.js +40 -96
- package/cli/dist/infra/github/client.d.ts +12 -1
- package/cli/dist/infra/github/client.js +49 -16
- package/cli/dist/infra/nx-scope.d.ts +5 -1
- package/cli/dist/infra/nx-scope.js +20 -13
- package/cli/dist/infra/process-run.d.ts +57 -0
- package/cli/dist/infra/process-run.js +168 -0
- package/cli/dist/infra/worktree-setup.d.ts +3 -6
- package/cli/dist/infra/worktree-setup.js +8 -26
- package/cli/dist/infra/worktree.d.ts +5 -1
- package/cli/dist/infra/worktree.js +4 -4
- package/cli/dist/mcp/result.d.ts +3 -3
- package/cli/dist/mcp/result.js +4 -3
- package/cli/dist/mcp/serve.d.ts +12 -0
- package/cli/dist/mcp/serve.js +30 -2
- package/cli/dist/mcp/server.d.ts +4 -0
- package/cli/dist/mcp/server.js +14 -6
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -7,6 +7,11 @@ export declare class BaseError extends Error {
|
|
|
7
7
|
export declare class PecotError extends BaseError {
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
+
MCP の要求が取り消され、待っていた子プロセスや要求を止めた。message は取り消しの理由
|
|
11
|
+
*/
|
|
12
|
+
export declare class CancelledError extends BaseError {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
10
15
|
プロジェクトルートが見つからない
|
|
11
16
|
*/
|
|
12
17
|
export declare class ProjectRootNotFoundError extends PecotError {
|
|
@@ -19,6 +19,11 @@ export class BaseError extends Error {
|
|
|
19
19
|
export class PecotError extends BaseError {
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
+
MCP の要求が取り消され、待っていた子プロセスや要求を止めた。message は取り消しの理由
|
|
23
|
+
*/
|
|
24
|
+
export class CancelledError extends BaseError {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
22
27
|
プロジェクトルートが見つからない
|
|
23
28
|
*/
|
|
24
29
|
export class ProjectRootNotFoundError extends PecotError {
|
|
@@ -45,9 +45,18 @@ base より head が進んでいる commit の数。GitHub の compare で数え
|
|
|
45
45
|
*/
|
|
46
46
|
export type CountCommitsAhead = (base: string, head: string) => Promise<number>;
|
|
47
47
|
/**
|
|
48
|
+
remote のタグの有無。尋ねられなければ failure に git の stderr
|
|
49
|
+
*/
|
|
50
|
+
export type RemoteTagLookup = {
|
|
51
|
+
readonly isFound: boolean;
|
|
52
|
+
} | {
|
|
53
|
+
readonly failure: string;
|
|
54
|
+
};
|
|
55
|
+
export type LookUpRemoteTag = (remote: string, tagName: string) => Promise<RemoteTagLookup>;
|
|
56
|
+
/**
|
|
48
57
|
リリース前チェックを実行する。
|
|
49
58
|
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
50
59
|
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
51
60
|
*/
|
|
52
|
-
export declare function runPreflight(options: PreflightOptions, git: GitRunner, countAhead: CountCommitsAhead): Promise<PreflightResult>;
|
|
61
|
+
export declare function runPreflight(options: PreflightOptions, git: GitRunner, lookUpRemoteTag: LookUpRemoteTag, countAhead: CountCommitsAhead): Promise<PreflightResult>;
|
|
53
62
|
//# sourceMappingURL=release.d.ts.map
|
|
@@ -9,11 +9,13 @@ git を実行して標準出力を返す。非 0 終了は ReleaseError
|
|
|
9
9
|
*/
|
|
10
10
|
function runGit(git, arguments_) {
|
|
11
11
|
const result = git(arguments_);
|
|
12
|
-
if (result.exitCode !== 0)
|
|
13
|
-
throw
|
|
14
|
-
}
|
|
12
|
+
if (result.exitCode !== 0)
|
|
13
|
+
throw gitFailed(arguments_, result.stderr);
|
|
15
14
|
return pythonStrip(result.stdout);
|
|
16
15
|
}
|
|
16
|
+
function gitFailed(arguments_, stderr) {
|
|
17
|
+
return new ReleaseError(`git command failed: git ${arguments_.join(' ')}\n${pythonStrip(stderr)}`);
|
|
18
|
+
}
|
|
17
19
|
function determineVersion(options, changelogContent) {
|
|
18
20
|
if (options.version === undefined) {
|
|
19
21
|
try {
|
|
@@ -33,7 +35,7 @@ function determineVersion(options, changelogContent) {
|
|
|
33
35
|
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
34
36
|
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
35
37
|
*/
|
|
36
|
-
export async function runPreflight(options, git, countAhead) {
|
|
38
|
+
export async function runPreflight(options, git, lookUpRemoteTag, countAhead) {
|
|
37
39
|
const { changelogContent, developBranch, releaseBranch } = options;
|
|
38
40
|
if (changelogContent === undefined)
|
|
39
41
|
throw new ReleaseError(changelogNotFoundMessage(options.changelogPath));
|
|
@@ -43,8 +45,10 @@ export async function runPreflight(options, git, countAhead) {
|
|
|
43
45
|
const localTags = runGit(git, ['tag', '-l', tagName]);
|
|
44
46
|
if (localTags.split('\n').includes(tagName))
|
|
45
47
|
throw new ReleaseError(`tag already exists locally: ${tagName}`);
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
+
const remoteTag = await lookUpRemoteTag(remote, tagName);
|
|
49
|
+
if ('failure' in remoteTag)
|
|
50
|
+
throw gitFailed(['ls-remote', '--tags', remote, `refs/tags/${tagName}`], remoteTag.failure);
|
|
51
|
+
if (remoteTag.isFound)
|
|
48
52
|
throw new ReleaseError(`tag already exists on the remote: ${tagName}`);
|
|
49
53
|
const diffCount = await countAhead(releaseBranch, developBranch);
|
|
50
54
|
if (diffCount === 0) {
|
package/cli/dist/infra/git.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { GitResult, GitRunner } from '../domain/git-runner.js';
|
|
|
2
2
|
import type { RemoteLocation } from '../domain/git-url.js';
|
|
3
3
|
import { BaseError } from '../domain/errors.js';
|
|
4
4
|
import type { IssueReference } from '../domain/reference-parser.js';
|
|
5
|
+
import type { RemoteTagLookup } from '../domain/release.js';
|
|
5
6
|
export interface GitOptions {
|
|
6
7
|
/**
|
|
7
8
|
作業ディレクトリ。省略すると呼び出し元の作業ディレクトリ
|
|
@@ -38,23 +39,21 @@ export declare class GitCommandError extends BaseError {
|
|
|
38
39
|
readonly stderr: string;
|
|
39
40
|
constructor(arguments_: readonly string[], result: GitResult);
|
|
40
41
|
}
|
|
41
|
-
export declare const MAX_OUTPUT_BYTES: number;
|
|
42
|
-
/**
|
|
43
|
-
取り消しで止めたときの exitCode
|
|
44
|
-
*/
|
|
45
|
-
export declare const GIT_CANCELLED = -3;
|
|
46
|
-
/**
|
|
47
|
-
runGit の非同期版。待つ間もイベントループを止めない。
|
|
48
|
-
時間切れか signal の中断で、git を pre-push のフックごと止め、exitCode が GIT_TIMED_OUT か GIT_CANCELLED の結果を返す
|
|
49
|
-
*/
|
|
50
|
-
export declare function runGitAsync(arguments_: readonly string[], options?: Readonly<Omit<GitOptions, 'stripGitEnvironment' | 'check'>> & {
|
|
51
|
-
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
52
|
-
}): Promise<GitResult>;
|
|
53
42
|
/**
|
|
54
43
|
git を実行する。標準出力・標準エラーは改行を \n に揃えた文字列で返す。
|
|
55
44
|
git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
|
|
56
45
|
*/
|
|
57
46
|
export declare function runGit(arguments_: readonly string[], options?: Readonly<GitOptions>): GitResult;
|
|
47
|
+
export interface AsyncGitOptions extends GitOptions {
|
|
48
|
+
/**
|
|
49
|
+
MCP の要求の取り消し。取り消されたら git をプロセスグループごと止めて CancelledError を投げる
|
|
50
|
+
*/
|
|
51
|
+
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
runGit の非同期版。リモートを待つ git に使い、待つ間もイベントループを止めない
|
|
55
|
+
*/
|
|
56
|
+
export declare function runGitAsync(arguments_: readonly string[], options?: Readonly<AsyncGitOptions>): Promise<GitResult>;
|
|
58
57
|
/**
|
|
59
58
|
cwd を束ねた GitRunner。domain の関数に渡す。非 0 終了は例外にせず結果で返す
|
|
60
59
|
*/
|
|
@@ -100,6 +99,7 @@ export declare function activeIssueOf(directory?: string): IssueReference | unde
|
|
|
100
99
|
*/
|
|
101
100
|
export declare function remoteRepository(cwd: string | undefined, remote: string): RemoteLocation | undefined;
|
|
102
101
|
export declare const NON_INTERACTIVE_GIT: Readonly<Record<string, string>>;
|
|
102
|
+
export declare const REMOTE_TIMEOUT_MILLISECONDS = 60000;
|
|
103
103
|
/**
|
|
104
104
|
push の時間切れ。pre-push のフックの時間を含める
|
|
105
105
|
*/
|
|
@@ -112,14 +112,14 @@ export type PushResult = {
|
|
|
112
112
|
readonly pushed: true;
|
|
113
113
|
} | {
|
|
114
114
|
readonly pushed: false;
|
|
115
|
-
readonly reason: 'rejected' | 'timed-out'
|
|
115
|
+
readonly reason: 'rejected' | 'timed-out';
|
|
116
116
|
readonly stderr: string;
|
|
117
117
|
};
|
|
118
118
|
export type RebaseOutcome = 'done' | 'conflict';
|
|
119
119
|
/**
|
|
120
120
|
`git fetch <remote>`。失敗・時間切れは succeeded が false
|
|
121
121
|
*/
|
|
122
|
-
export declare function fetchRemote(cwd: string, remote: string): FetchResult
|
|
122
|
+
export declare function fetchRemote(cwd: string, remote: string, signal?: Readonly<AbortSignal>): Promise<FetchResult>;
|
|
123
123
|
/**
|
|
124
124
|
ref の指すコミットの SHA。無ければ undefined
|
|
125
125
|
*/
|
|
@@ -182,7 +182,7 @@ export interface PushOptions {
|
|
|
182
182
|
readonly timeoutMilliseconds?: number | undefined;
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
|
-
remote の branch が expectedSha のときだけ、手元の branch
|
|
185
|
+
remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか時間切れなら、その理由と stderr を返す。取り消されたら CancelledError を投げる
|
|
186
186
|
*/
|
|
187
187
|
export declare function pushWithLease(cwd: string, remote: string, branch: string, expectedSha: string, options?: Readonly<PushOptions>): Promise<PushResult>;
|
|
188
188
|
export type RemoteHead = {
|
|
@@ -194,5 +194,9 @@ export type RemoteHead = {
|
|
|
194
194
|
/**
|
|
195
195
|
remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
|
|
196
196
|
*/
|
|
197
|
-
export declare function remoteBranchHead(cwd: string, remote: string, branch: string): RemoteHead
|
|
197
|
+
export declare function remoteBranchHead(cwd: string, remote: string, branch: string, signal?: Readonly<AbortSignal>): Promise<RemoteHead>;
|
|
198
|
+
/**
|
|
199
|
+
remote にタグがあるか。届かないか時間切れなら failure に git の stderr を入れる
|
|
200
|
+
*/
|
|
201
|
+
export declare function remoteTagExists(cwd: string, remote: string, tagName: string, signal?: Readonly<AbortSignal>): Promise<RemoteTagLookup>;
|
|
198
202
|
//# sourceMappingURL=git.d.ts.map
|
package/cli/dist/infra/git.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// git コマンド実行の唯一の窓口。git の subprocess 呼び出しはすべて runGit か runGitAsync を経由する。
|
|
2
2
|
// 値を返す helper(gitToplevel 等)は、失敗時に undefined を返す。
|
|
3
|
-
import {
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { activeIssueFromBranch } from '../domain/branch-name.js';
|
|
@@ -9,6 +9,7 @@ import { BaseError, InvalidValueError } from '../domain/errors.js';
|
|
|
9
9
|
import { normalizeNewlines, pythonRepr, pythonStrip } from '../domain/python-format.js';
|
|
10
10
|
import { childStdin } from './child-stdin.js';
|
|
11
11
|
import { isFileNotFound, toOsError } from './os-error.js';
|
|
12
|
+
import { MAX_OUTPUT_BYTES, runProcess } from './process-run.js';
|
|
12
13
|
/**
|
|
13
14
|
時間切れで止めたときの exitCode
|
|
14
15
|
*/
|
|
@@ -30,96 +31,11 @@ export class GitCommandError extends BaseError {
|
|
|
30
31
|
this.stderr = result.stderr;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
// 出力が大きい git(log・diff 等)でも切れないようにする
|
|
34
|
-
export const MAX_OUTPUT_BYTES = 1024 * 1024 * 1024;
|
|
35
34
|
function withoutGitVariables() {
|
|
36
35
|
// interface-env: none
|
|
37
36
|
return Object.fromEntries(Object.entries(process.env).filter((entry) => entry[1] !== undefined && !entry[0].startsWith('GIT_')));
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
40
|
-
取り消しで止めたときの exitCode
|
|
41
|
-
*/
|
|
42
|
-
export const GIT_CANCELLED = -3;
|
|
43
|
-
// detached の git は端末の Ctrl-C を受けないので、受けたらグループごと止めてから既定の動きに戻す
|
|
44
|
-
const FORWARDED_SIGNALS = ['SIGINT', 'SIGTERM'];
|
|
45
|
-
function killGroup(pid) {
|
|
46
|
-
if (pid === undefined)
|
|
47
|
-
return;
|
|
48
|
-
try {
|
|
49
|
-
// detached の git はプロセスグループの頭なので、負の pid でフックの孫までまとめて止める
|
|
50
|
-
process.kill(-pid, 'SIGKILL');
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
// 既に終わっている
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
runGit の非同期版。待つ間もイベントループを止めない。
|
|
58
|
-
時間切れか signal の中断で、git を pre-push のフックごと止め、exitCode が GIT_TIMED_OUT か GIT_CANCELLED の結果を返す
|
|
59
|
-
*/
|
|
60
|
-
export async function runGitAsync(arguments_, options = {}) {
|
|
61
|
-
const timeout = options.timeoutMilliseconds === undefined ? undefined : AbortSignal.timeout(options.timeoutMilliseconds);
|
|
62
|
-
const stops = [options.signal, timeout].filter(signal => signal !== undefined);
|
|
63
|
-
const stop = stops.length === 0 ? undefined : AbortSignal.any(stops);
|
|
64
|
-
const child = spawn('git', [...arguments_], {
|
|
65
|
-
cwd: options.cwd,
|
|
66
|
-
// interface-env: none
|
|
67
|
-
env: options.env === undefined ? undefined : { ...process.env, ...options.env },
|
|
68
|
-
stdio: [childStdin(), 'pipe', 'pipe'],
|
|
69
|
-
detached: true,
|
|
70
|
-
});
|
|
71
|
-
const stdout = [];
|
|
72
|
-
const stderr = [];
|
|
73
|
-
child.stdout.setEncoding('utf8').on('data', (chunk) => {
|
|
74
|
-
stdout.push(chunk);
|
|
75
|
-
});
|
|
76
|
-
child.stderr.setEncoding('utf8').on('data', (chunk) => {
|
|
77
|
-
stderr.push(chunk);
|
|
78
|
-
});
|
|
79
|
-
const closed = new Promise((resolve) => {
|
|
80
|
-
child.on('close', () => {
|
|
81
|
-
resolve();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
const kill = () => {
|
|
85
|
-
killGroup(child.pid);
|
|
86
|
-
};
|
|
87
|
-
const forward = (signal) => {
|
|
88
|
-
killGroup(child.pid);
|
|
89
|
-
for (const name of FORWARDED_SIGNALS)
|
|
90
|
-
process.removeListener(name, forward);
|
|
91
|
-
process.kill(process.pid, signal);
|
|
92
|
-
};
|
|
93
|
-
stop?.addEventListener('abort', kill, { once: true });
|
|
94
|
-
for (const name of FORWARDED_SIGNALS)
|
|
95
|
-
process.on(name, forward);
|
|
96
|
-
const ended = await new Promise((resolve) => {
|
|
97
|
-
child.on('error', (error) => {
|
|
98
|
-
resolve({ kind: 'error', error });
|
|
99
|
-
});
|
|
100
|
-
// 'close' は stdio を持つ孫(フック)が終わるまで出ないので、git の終わりは 'exit' で受ける
|
|
101
|
-
child.on('exit', (code) => {
|
|
102
|
-
resolve({ kind: 'exit', code: code ?? undefined });
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
stop?.removeEventListener('abort', kill);
|
|
106
|
-
for (const name of FORWARDED_SIGNALS)
|
|
107
|
-
process.removeListener(name, forward);
|
|
108
|
-
if (ended.kind === 'error')
|
|
109
|
-
throw toOsError(ended.error);
|
|
110
|
-
// 止めずに終わったなら、出力を読み切る。止めたなら、残ったパイプを捨てる
|
|
111
|
-
if (ended.code === 0 || stop?.aborted !== true)
|
|
112
|
-
await closed;
|
|
113
|
-
else {
|
|
114
|
-
child.stdout.destroy();
|
|
115
|
-
child.stderr.destroy();
|
|
116
|
-
}
|
|
117
|
-
const output = { stdout: normalizeNewlines(stdout.join('')), stderr: normalizeNewlines(stderr.join('')) };
|
|
118
|
-
if (ended.code === 0 || stop?.aborted !== true)
|
|
119
|
-
return { exitCode: ended.code ?? -1, ...output };
|
|
120
|
-
return { exitCode: options.signal?.aborted === true ? GIT_CANCELLED : GIT_TIMED_OUT, ...output };
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
39
|
git を実行する。標準出力・標準エラーは改行を \n に揃えた文字列で返す。
|
|
124
40
|
git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
|
|
125
41
|
*/
|
|
@@ -146,6 +62,25 @@ export function runGit(arguments_, options = {}) {
|
|
|
146
62
|
return gitResult;
|
|
147
63
|
}
|
|
148
64
|
/**
|
|
65
|
+
runGit の非同期版。リモートを待つ git に使い、待つ間もイベントループを止めない
|
|
66
|
+
*/
|
|
67
|
+
export async function runGitAsync(arguments_, options = {}) {
|
|
68
|
+
// interface-env: none
|
|
69
|
+
const base = options.stripGitEnvironment === true ? withoutGitVariables() : (options.env === undefined ? undefined : process.env);
|
|
70
|
+
const result = await runProcess('git', arguments_, {
|
|
71
|
+
cwd: options.cwd,
|
|
72
|
+
env: base === undefined ? undefined : { ...base, ...options.env },
|
|
73
|
+
timeoutMilliseconds: options.timeoutMilliseconds,
|
|
74
|
+
signal: options.signal,
|
|
75
|
+
});
|
|
76
|
+
if (result.isTimedOut)
|
|
77
|
+
return { exitCode: GIT_TIMED_OUT, stdout: result.stdout, stderr: result.stderr };
|
|
78
|
+
const gitResult = { exitCode: result.exitCode ?? -1, stdout: result.stdout, stderr: result.stderr };
|
|
79
|
+
if (options.check === true && gitResult.exitCode !== 0)
|
|
80
|
+
throw new GitCommandError(arguments_, gitResult);
|
|
81
|
+
return gitResult;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
149
84
|
cwd を束ねた GitRunner。domain の関数に渡す。非 0 終了は例外にせず結果で返す
|
|
150
85
|
*/
|
|
151
86
|
export function gitRunnerFor(cwd, options = {}) {
|
|
@@ -236,8 +171,8 @@ export function remoteRepository(cwd, remote) {
|
|
|
236
171
|
}
|
|
237
172
|
// 端末で尋ねさせない。ssh は GIT_SSH_COMMAND で BatchMode にすると利用者の GIT_SSH と core.sshCommand を上書きするので、askpass を失敗させる
|
|
238
173
|
export const NON_INTERACTIVE_GIT = { GIT_TERMINAL_PROMPT: '0', SSH_ASKPASS: 'false', SSH_ASKPASS_REQUIRE: 'force' };
|
|
239
|
-
// fetch
|
|
240
|
-
const REMOTE_TIMEOUT_MILLISECONDS = 60_000;
|
|
174
|
+
// fetch は、認証の入力を待たずに、この時間で諦める
|
|
175
|
+
export const REMOTE_TIMEOUT_MILLISECONDS = 60_000;
|
|
241
176
|
/**
|
|
242
177
|
push の時間切れ。pre-push のフックの時間を含める
|
|
243
178
|
*/
|
|
@@ -246,8 +181,8 @@ const PEEL_TO_COMMIT = '^{commit}';
|
|
|
246
181
|
/**
|
|
247
182
|
`git fetch <remote>`。失敗・時間切れは succeeded が false
|
|
248
183
|
*/
|
|
249
|
-
export function fetchRemote(cwd, remote) {
|
|
250
|
-
const result =
|
|
184
|
+
export async function fetchRemote(cwd, remote, signal) {
|
|
185
|
+
const result = await runGitAsync(['fetch', remote], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS, signal });
|
|
251
186
|
return { succeeded: result.exitCode === 0, stderr: result.stderr };
|
|
252
187
|
}
|
|
253
188
|
/**
|
|
@@ -351,12 +286,10 @@ export function resetHardTo(cwd, reference) {
|
|
|
351
286
|
runGit(['reset', '--quiet', '--hard', reference], { cwd, check: true });
|
|
352
287
|
}
|
|
353
288
|
function pushFailure(exitCode) {
|
|
354
|
-
|
|
355
|
-
return 'timed-out';
|
|
356
|
-
return exitCode === GIT_CANCELLED ? 'cancelled' : 'rejected';
|
|
289
|
+
return exitCode === GIT_TIMED_OUT ? 'timed-out' : 'rejected';
|
|
357
290
|
}
|
|
358
291
|
/**
|
|
359
|
-
remote の branch が expectedSha のときだけ、手元の branch
|
|
292
|
+
remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか時間切れなら、その理由と stderr を返す。取り消されたら CancelledError を投げる
|
|
360
293
|
*/
|
|
361
294
|
export async function pushWithLease(cwd, remote, branch, expectedSha, options = {}) {
|
|
362
295
|
const result = await runGitAsync(['push', `--force-with-lease=${branch}:${expectedSha}`, remote, branch], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: options.timeoutMilliseconds ?? PUSH_TIMEOUT_MILLISECONDS, signal: options.signal });
|
|
@@ -368,11 +301,22 @@ const LS_REMOTE_TIMEOUT_MILLISECONDS = 10_000;
|
|
|
368
301
|
/**
|
|
369
302
|
remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
|
|
370
303
|
*/
|
|
371
|
-
export function remoteBranchHead(cwd, remote, branch) {
|
|
372
|
-
const listed =
|
|
304
|
+
export async function remoteBranchHead(cwd, remote, branch, signal) {
|
|
305
|
+
const listed = await runGitAsync(['ls-remote', '--exit-code', remote, `refs/heads/${branch}`], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: LS_REMOTE_TIMEOUT_MILLISECONDS, signal });
|
|
373
306
|
if (listed.exitCode === LS_REMOTE_NOT_FOUND)
|
|
374
307
|
return { isReachable: true, sha: undefined };
|
|
375
308
|
const [sha] = listed.exitCode === 0 ? listed.stdout.split(/\s/u, 1) : [];
|
|
376
309
|
return sha === undefined || sha === '' ? { isReachable: false } : { isReachable: true, sha };
|
|
377
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
remote にタグがあるか。届かないか時間切れなら failure に git の stderr を入れる
|
|
313
|
+
*/
|
|
314
|
+
export async function remoteTagExists(cwd, remote, tagName, signal) {
|
|
315
|
+
const listed = await runGitAsync(['ls-remote', '--tags', remote, `refs/tags/${tagName}`], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: LS_REMOTE_TIMEOUT_MILLISECONDS, signal });
|
|
316
|
+
if (listed.exitCode === GIT_TIMED_OUT)
|
|
317
|
+
return { failure: `${listed.stderr}timed out after ${String(LS_REMOTE_TIMEOUT_MILLISECONDS / 1000)} seconds` };
|
|
318
|
+
if (listed.exitCode !== 0)
|
|
319
|
+
return { failure: listed.stderr };
|
|
320
|
+
return { isFound: pythonStrip(listed.stdout) !== '' };
|
|
321
|
+
}
|
|
378
322
|
//# sourceMappingURL=git.js.map
|
|
@@ -89,6 +89,10 @@ export interface GitHubClientOptions {
|
|
|
89
89
|
*/
|
|
90
90
|
readonly token?: string | undefined;
|
|
91
91
|
/**
|
|
92
|
+
MCP の要求の取り消し。gh auth token と HTTP の要求を止める
|
|
93
|
+
*/
|
|
94
|
+
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
95
|
+
/**
|
|
92
96
|
1 回の要求の時間切れ(ミリ秒)。既定は 30000
|
|
93
97
|
*/
|
|
94
98
|
readonly timeoutMilliseconds?: number | undefined;
|
|
@@ -111,6 +115,8 @@ restJson・restObject・restRequest・handleHttpError・executeGraphql。
|
|
|
111
115
|
export declare class GitHubClientBase {
|
|
112
116
|
private readonly diagnostics;
|
|
113
117
|
private usedFallback;
|
|
118
|
+
private readonly signal;
|
|
119
|
+
private ghToken;
|
|
114
120
|
readonly host: string;
|
|
115
121
|
token: string;
|
|
116
122
|
readonly timeoutMilliseconds: number;
|
|
@@ -122,8 +128,8 @@ export declare class GitHubClientBase {
|
|
|
122
128
|
*/
|
|
123
129
|
readonly linkedRepositoriesCache: Map<string, readonly LinkedRepository[]>;
|
|
124
130
|
constructor(options: Readonly<GitHubClientOptions>);
|
|
125
|
-
private resolveToken;
|
|
126
131
|
private failAuthentication;
|
|
132
|
+
private loadGhToken;
|
|
127
133
|
private tokenFromEnvironment;
|
|
128
134
|
private tokenFromGh;
|
|
129
135
|
/**
|
|
@@ -137,12 +143,17 @@ export declare class GitHubClientBase {
|
|
|
137
143
|
*/
|
|
138
144
|
private retryWithFallbackToken;
|
|
139
145
|
private send;
|
|
146
|
+
private throwIfCancelled;
|
|
140
147
|
private sendRest;
|
|
141
148
|
private sendGraphql;
|
|
142
149
|
private classifyGraphqlFailure;
|
|
143
150
|
private runGraphql;
|
|
144
151
|
private assertSameOrigin;
|
|
145
152
|
/**
|
|
153
|
+
トークンが無ければ gh auth token を 1 回だけ読む。読めなければ GitHubAuthError、取り消されたら CancelledError
|
|
154
|
+
*/
|
|
155
|
+
ensureToken(): Promise<void>;
|
|
156
|
+
/**
|
|
146
157
|
REST の要求(401 のときは gh auth token に切り替えて 1 回だけ再試行する)。
|
|
147
158
|
target は `/user` のようなパス(base の後ろにつなぐ)か、`https://` で始まる絶対 URL(Link ヘッダの next など)。
|
|
148
159
|
失敗の状態コードは例外にせず、そのまま返す。呼び出し側が isSuccess を見て handleHttpError に渡す
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
// - redirect: 'manual' で呼ぶ。301 などは成功にせず、Python と同じ失敗にする。
|
|
6
6
|
// - URL は文字列の連結で作る。new URL は GHE の base(/api/v3)を落とす。
|
|
7
7
|
// - 失敗の文は httpx と gql の文言を写す。
|
|
8
|
-
import { spawnSync } from 'node:child_process';
|
|
9
8
|
import path from 'node:path';
|
|
10
9
|
import { isJsonObject, parseJsonText } from '../../domain/json.js';
|
|
11
|
-
import { BaseError, InvalidValueError } from '../../domain/errors.js';
|
|
10
|
+
import { BaseError, CancelledError, InvalidValueError } from '../../domain/errors.js';
|
|
12
11
|
import { formatHttpStatusError, isJsonArray, pythonRepr, pythonStrip, pythonTypeName, splitCodePoints, } from '../../domain/python-format.js';
|
|
13
12
|
import { configDirectory } from '../config-store.js';
|
|
14
13
|
import { projectRoot } from '../paths.js';
|
|
14
|
+
import { cancelledBy, runProcess } from '../process-run.js';
|
|
15
15
|
import { ensureEnvironmentFile, environmentValue, getEnvironmentVariableName, loadEnvironmentFile, pythonString, ROOT_ENV_VAR_MAP, scopesFor, tokenUrlFor, } from './auth.js';
|
|
16
16
|
import { GitHubAPIError, GitHubAuthError, GitHubNotFoundError, GitHubRateLimitError, } from './errors.js';
|
|
17
17
|
import { asObject, isTruthy } from './payload.js';
|
|
@@ -291,6 +291,8 @@ restJson・restObject・restRequest・handleHttpError・executeGraphql。
|
|
|
291
291
|
export class GitHubClientBase {
|
|
292
292
|
diagnostics;
|
|
293
293
|
usedFallback = false;
|
|
294
|
+
signal;
|
|
295
|
+
ghToken;
|
|
294
296
|
host;
|
|
295
297
|
token;
|
|
296
298
|
timeoutMilliseconds;
|
|
@@ -305,7 +307,9 @@ export class GitHubClientBase {
|
|
|
305
307
|
this.diagnostics = options.diagnostics;
|
|
306
308
|
this.host = options.host ?? 'github.com';
|
|
307
309
|
this.ghTimeoutMilliseconds = options.ghTimeoutMilliseconds ?? DEFAULT_GH_TIMEOUT_MILLISECONDS;
|
|
308
|
-
this.
|
|
310
|
+
this.signal = options.signal;
|
|
311
|
+
// gh auth token は子プロセスを待つので、構築では読まず ensureToken に回す。空はまだ読んでいない印
|
|
312
|
+
this.token = options.token === undefined || options.token === '' ? this.tokenFromEnvironment(this.host) ?? '' : options.token;
|
|
309
313
|
this.timeoutMilliseconds = options.timeoutMilliseconds ?? DEFAULT_TIMEOUT_MILLISECONDS;
|
|
310
314
|
const override = resolveApiUrlOverride();
|
|
311
315
|
if (override !== undefined) {
|
|
@@ -321,13 +325,12 @@ export class GitHubClientBase {
|
|
|
321
325
|
this.graphqlUrl = `https://${this.host}/api/graphql`;
|
|
322
326
|
}
|
|
323
327
|
}
|
|
324
|
-
// config/.env → ルート .env → gh auth token の順
|
|
325
|
-
resolveToken(host) {
|
|
326
|
-
return this.tokenFromEnvironment(host) ?? this.tokenFromGh(host) ?? this.failAuthentication(host);
|
|
327
|
-
}
|
|
328
328
|
failAuthentication(host) {
|
|
329
329
|
throw new GitHubAuthError(this.authErrorMessage(host));
|
|
330
330
|
}
|
|
331
|
+
async loadGhToken() {
|
|
332
|
+
this.token = await this.tokenFromGh(this.host) ?? this.failAuthentication(this.host);
|
|
333
|
+
}
|
|
331
334
|
tokenFromEnvironment(host) {
|
|
332
335
|
loadEnvironmentFile(path.join(configDirectory(), '.env'));
|
|
333
336
|
const token = environmentValue(getEnvironmentVariableName(host));
|
|
@@ -340,11 +343,18 @@ export class GitHubClientBase {
|
|
|
340
343
|
const rootToken = environmentValue(rootName);
|
|
341
344
|
return rootToken === undefined || rootToken === '' ? undefined : rootToken;
|
|
342
345
|
}
|
|
343
|
-
tokenFromGh(host) {
|
|
346
|
+
async tokenFromGh(host) {
|
|
344
347
|
const arguments_ = host === 'github.com' ? ['auth', 'token'] : ['auth', 'token', '-h', host];
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
+
let token = '';
|
|
349
|
+
try {
|
|
350
|
+
const result = await runProcess('gh', arguments_, { stdin: 'ignore', timeoutMilliseconds: this.ghTimeoutMilliseconds, signal: this.signal });
|
|
351
|
+
token = result.exitCode === 0 && !result.isTimedOut ? pythonStrip(result.stdout) : '';
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
// 取り消しは認証の失敗にしない(authErrorMessage が .env を作るため)。gh が無いときは読めなかった扱い
|
|
355
|
+
if (error instanceof CancelledError)
|
|
356
|
+
throw error;
|
|
357
|
+
}
|
|
348
358
|
return token.length === 0 ? undefined : token;
|
|
349
359
|
}
|
|
350
360
|
/**
|
|
@@ -391,11 +401,11 @@ or authenticate with the GitHub CLI:
|
|
|
391
401
|
/**
|
|
392
402
|
env のトークンが失効したとき、gh auth token に 1 回だけ切り替える。切り替えたら true
|
|
393
403
|
*/
|
|
394
|
-
retryWithFallbackToken() {
|
|
404
|
+
async retryWithFallbackToken() {
|
|
395
405
|
if (this.usedFallback)
|
|
396
406
|
return false;
|
|
397
407
|
this.usedFallback = true;
|
|
398
|
-
const newToken = this.tokenFromGh(this.host);
|
|
408
|
+
const newToken = await this.tokenFromGh(this.host);
|
|
399
409
|
if (newToken === undefined || newToken === this.token)
|
|
400
410
|
return false;
|
|
401
411
|
this.diagnostics.warning(TOKEN_FALLBACK_WARNING);
|
|
@@ -409,7 +419,9 @@ or authenticate with the GitHub CLI:
|
|
|
409
419
|
headers,
|
|
410
420
|
...(body !== undefined && { body }),
|
|
411
421
|
redirect: 'manual',
|
|
412
|
-
signal:
|
|
422
|
+
signal: this.signal === undefined
|
|
423
|
+
? AbortSignal.timeout(this.timeoutMilliseconds)
|
|
424
|
+
: AbortSignal.any([AbortSignal.timeout(this.timeoutMilliseconds), this.signal]),
|
|
413
425
|
});
|
|
414
426
|
const text = await response.text();
|
|
415
427
|
return new RestResponse({
|
|
@@ -421,10 +433,17 @@ or authenticate with the GitHub CLI:
|
|
|
421
433
|
});
|
|
422
434
|
}
|
|
423
435
|
catch (error) {
|
|
436
|
+
this.throwIfCancelled();
|
|
424
437
|
throw new TransportFailure(describeTransportFailure(error), { cause: error });
|
|
425
438
|
}
|
|
426
439
|
}
|
|
440
|
+
// 取り消しは時間切れ(AbortError)と名前で分けられないので、signal で見分ける
|
|
441
|
+
throwIfCancelled() {
|
|
442
|
+
if (this.signal?.aborted === true)
|
|
443
|
+
throw cancelledBy(this.signal);
|
|
444
|
+
}
|
|
427
445
|
async sendRest(method, url, options) {
|
|
446
|
+
await this.ensureToken();
|
|
428
447
|
const { json } = options;
|
|
429
448
|
const base = this.requestHeaders(options.apiVersion);
|
|
430
449
|
const headers = json === undefined ? base : { ...base, 'Content-Type': 'application/json' };
|
|
@@ -437,6 +456,7 @@ or authenticate with the GitHub CLI:
|
|
|
437
456
|
response = await this.send('POST', this.graphqlUrl, { ...this.requestHeaders(), 'Content-Type': 'application/json' }, JSON.stringify({ query, variables }));
|
|
438
457
|
}
|
|
439
458
|
catch (error) {
|
|
459
|
+
this.throwIfCancelled();
|
|
440
460
|
throw new GraphqlFailure(error instanceof Error ? error.message : String(error), { cause: error });
|
|
441
461
|
}
|
|
442
462
|
const { statusCode } = response;
|
|
@@ -488,19 +508,23 @@ or authenticate with the GitHub CLI:
|
|
|
488
508
|
return new GitHubAPIError(`GraphQL query error: ${message}`, detail);
|
|
489
509
|
}
|
|
490
510
|
async runGraphql(query, variables, isTolerated) {
|
|
511
|
+
// 認証の失敗と取り消しを、GraphQL の失敗に包まないよう try の外で待つ
|
|
512
|
+
await this.ensureToken();
|
|
491
513
|
try {
|
|
492
514
|
return await this.sendGraphql(query, variables, isTolerated);
|
|
493
515
|
}
|
|
494
516
|
catch (error) {
|
|
517
|
+
this.throwIfCancelled();
|
|
495
518
|
const failure = toGraphqlFailure(error);
|
|
496
519
|
if (!isUnauthorized(failure))
|
|
497
520
|
throw this.classifyGraphqlFailure(failure);
|
|
498
|
-
if (!this.retryWithFallbackToken())
|
|
521
|
+
if (!await this.retryWithFallbackToken())
|
|
499
522
|
throw new GitHubAuthError(`GraphQL authentication error: ${failure.message}`, { cause: failure });
|
|
500
523
|
try {
|
|
501
524
|
return await this.sendGraphql(query, variables, isTolerated);
|
|
502
525
|
}
|
|
503
526
|
catch (retryError) {
|
|
527
|
+
this.throwIfCancelled();
|
|
504
528
|
throw this.classifyGraphqlFailure(toGraphqlFailure(retryError));
|
|
505
529
|
}
|
|
506
530
|
}
|
|
@@ -515,6 +539,15 @@ or authenticate with the GitHub CLI:
|
|
|
515
539
|
throw new GitHubAPIError(`refusing to follow a URL on a different host than the API: ${target}`);
|
|
516
540
|
}
|
|
517
541
|
/**
|
|
542
|
+
トークンが無ければ gh auth token を 1 回だけ読む。読めなければ GitHubAuthError、取り消されたら CancelledError
|
|
543
|
+
*/
|
|
544
|
+
async ensureToken() {
|
|
545
|
+
if (this.token !== '')
|
|
546
|
+
return;
|
|
547
|
+
this.ghToken ??= this.loadGhToken();
|
|
548
|
+
await this.ghToken;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
518
551
|
REST の要求(401 のときは gh auth token に切り替えて 1 回だけ再試行する)。
|
|
519
552
|
target は `/user` のようなパス(base の後ろにつなぐ)か、`https://` で始まる絶対 URL(Link ヘッダの next など)。
|
|
520
553
|
失敗の状態コードは例外にせず、そのまま返す。呼び出し側が isSuccess を見て handleHttpError に渡す
|
|
@@ -523,7 +556,7 @@ or authenticate with the GitHub CLI:
|
|
|
523
556
|
this.assertSameOrigin(target);
|
|
524
557
|
const url = buildUrl(this.apiUrl, target, options.params);
|
|
525
558
|
const response = await this.sendRest(method, url, options);
|
|
526
|
-
return response.statusCode === 401 && this.retryWithFallbackToken() ? this.sendRest(method, url, options) : response;
|
|
559
|
+
return response.statusCode === 401 && await this.retryWithFallbackToken() ? this.sendRest(method, url, options) : response;
|
|
527
560
|
}
|
|
528
561
|
/**
|
|
529
562
|
REST の要求を送り、成功した応答の JSON を返す。失敗の応答は handleHttpError の例外にする。
|
|
@@ -26,12 +26,16 @@ export interface NxGraphOptions {
|
|
|
26
26
|
nx graph の実行上限(秒)。既定は NX_GRAPH_TIMEOUT_SECONDS
|
|
27
27
|
*/
|
|
28
28
|
readonly timeoutSeconds?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
MCP の要求の取り消し。取り消されたら nx を止めて CancelledError を投げる
|
|
31
|
+
*/
|
|
32
|
+
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
35
|
nx の project graph から `{プロジェクト名: NxProject}` を返す。stdout では大きな JSON が切れるため、一時ファイルに書かせて読む。
|
|
32
36
|
nx が無い・実行失敗・部分 graph・JSON の解析失敗なら undefined
|
|
33
37
|
*/
|
|
34
|
-
export declare function nxProjects(toplevel: string, options?: Readonly<NxGraphOptions>): ReadonlyMap<string, NxProject> | undefined
|
|
38
|
+
export declare function nxProjects(toplevel: string, options?: Readonly<NxGraphOptions>): Promise<ReadonlyMap<string, NxProject> | undefined>;
|
|
35
39
|
/**
|
|
36
40
|
`baseReference...head` の変更ファイル(リポジトリ root からの相対パス)を返す。baseReference は、ブランチのほか、コミットの SHA(base の記録の位置)も受ける。
|
|
37
41
|
rename 検出だと移動元のプロジェクトが漏れ、`core.quotePath` だと非 ASCII パスが一致しなくなるため、`--no-renames` と NUL 区切りで取る。
|