@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
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
// 割り当ては `.githooks/pre-push/check-version-plan-required.sh` と同じ規則。
|
|
5
5
|
// nx の project graph → git diff → project root との最長一致、の順で求める。
|
|
6
6
|
// 判定できない場合は例外ではなく undefined を返し、呼び出し側が警告して割り当てを飛ばす(フェイルオープン)。
|
|
7
|
-
import { spawnSync } from 'node:child_process';
|
|
8
7
|
import { accessSync, constants, mkdirSync, mkdtempSync, rmSync, statSync } from 'node:fs';
|
|
9
8
|
import path from 'node:path';
|
|
10
9
|
import { isJsonObject, jsonField, tryParseJsonText } from '../domain/json.js';
|
|
11
10
|
import { compareStrings, isJsonArray, pythonRepr } from '../domain/python-format.js';
|
|
12
11
|
import { GitCommandError, runGit } from './git.js';
|
|
13
|
-
import { isFileNotFound } from './os-error.js';
|
|
12
|
+
import { isFileNotFound, OsError } from './os-error.js';
|
|
14
13
|
import { TMP_DIR } from './paths.js';
|
|
14
|
+
import { runProcess } from './process-run.js';
|
|
15
15
|
import { readTextFile } from './text-file.js';
|
|
16
16
|
/**
|
|
17
17
|
nx graph の実行上限(秒)
|
|
@@ -85,7 +85,7 @@ function projectsFromGraph(text) {
|
|
|
85
85
|
nx の project graph から `{プロジェクト名: NxProject}` を返す。stdout では大きな JSON が切れるため、一時ファイルに書かせて読む。
|
|
86
86
|
nx が無い・実行失敗・部分 graph・JSON の解析失敗なら undefined
|
|
87
87
|
*/
|
|
88
|
-
export function nxProjects(toplevel, options = {}) {
|
|
88
|
+
export async function nxProjects(toplevel, options = {}) {
|
|
89
89
|
const nx = resolveNx(toplevel);
|
|
90
90
|
if (nx === undefined)
|
|
91
91
|
return undefined;
|
|
@@ -100,16 +100,23 @@ export function nxProjects(toplevel, options = {}) {
|
|
|
100
100
|
}
|
|
101
101
|
try {
|
|
102
102
|
const graphFile = path.join(work, 'graph.json');
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
let result;
|
|
104
|
+
try {
|
|
105
|
+
result = await runProcess(nx, ['graph', `--file=${graphFile}`], {
|
|
106
|
+
cwd: toplevel,
|
|
107
|
+
stdin: 'ignore',
|
|
108
|
+
timeoutMilliseconds: (options.timeoutSeconds ?? NX_GRAPH_TIMEOUT_SECONDS) * 1000,
|
|
109
|
+
// interface-env: none
|
|
110
|
+
env: { ...process.env, NX_DAEMON: 'false' },
|
|
111
|
+
signal: options.signal,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error instanceof OsError)
|
|
116
|
+
return undefined;
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
if (result.isTimedOut || result.exitCode !== 0 || result.stderr.includes('Showing partial graph'))
|
|
113
120
|
return undefined;
|
|
114
121
|
let text;
|
|
115
122
|
try {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CancelledError } from '../domain/errors.js';
|
|
2
|
+
import type { ChildStdin } from './child-stdin.js';
|
|
3
|
+
/**
|
|
4
|
+
子の標準出力・標準エラーを溜める上限。出力が大きい git(log・diff 等)でも切れない大きさにし、超えた分は捨てる
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_OUTPUT_BYTES: number;
|
|
7
|
+
/**
|
|
8
|
+
止めるときに SIGTERM を送ってから SIGKILL を送るまでの猶予。git が lock ファイルを片付ける時間
|
|
9
|
+
*/
|
|
10
|
+
export declare const KILL_GRACE_MILLISECONDS = 1000;
|
|
11
|
+
export interface ProcessOptions {
|
|
12
|
+
readonly cwd?: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
子の環境変数の全体。省略すると今の環境を継承する
|
|
15
|
+
*/
|
|
16
|
+
readonly env?: Readonly<Record<string, string | undefined>> | undefined;
|
|
17
|
+
/**
|
|
18
|
+
true なら command をシェルで解釈する
|
|
19
|
+
*/
|
|
20
|
+
readonly shell?: boolean | undefined;
|
|
21
|
+
/**
|
|
22
|
+
省略すると childStdin() に従う
|
|
23
|
+
*/
|
|
24
|
+
readonly stdin?: ChildStdin | undefined;
|
|
25
|
+
/**
|
|
26
|
+
過ぎたら止めて、isTimedOut が true の結果を返す
|
|
27
|
+
*/
|
|
28
|
+
readonly timeoutMilliseconds?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
MCP の要求の取り消し。取り消されたら子を止めて CancelledError を投げる
|
|
31
|
+
*/
|
|
32
|
+
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface ProcessResult {
|
|
35
|
+
/**
|
|
36
|
+
シグナルで終わったときは null
|
|
37
|
+
*/
|
|
38
|
+
readonly exitCode: number | null;
|
|
39
|
+
readonly signal: NodeJS.Signals | null;
|
|
40
|
+
readonly stdout: string;
|
|
41
|
+
readonly stderr: string;
|
|
42
|
+
readonly isTimedOut: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
signal の取り消しの理由を持つ CancelledError
|
|
46
|
+
*/
|
|
47
|
+
export declare function cancelledBy(signal: Readonly<AbortSignal>): CancelledError;
|
|
48
|
+
/**
|
|
49
|
+
生きている子のグループに SIGTERM を送る。サーバの終了のときに呼ぶ
|
|
50
|
+
*/
|
|
51
|
+
export declare function killRunningProcesses(): void;
|
|
52
|
+
/**
|
|
53
|
+
子プロセスを動かし、終わるのを待つ。起動に失敗(ENOENT など)したら OsError を投げる。
|
|
54
|
+
子が 0 で終わっていれば、取り消しと重なっても成功の結果を返す
|
|
55
|
+
*/
|
|
56
|
+
export declare function runProcess(command: string, arguments_: readonly string[], options?: Readonly<ProcessOptions>): Promise<ProcessResult>;
|
|
57
|
+
//# sourceMappingURL=process-run.d.ts.map
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// 待つ時間の長い子プロセスを、イベントループを止めずに動かす。時間切れと MCP の要求の取り消しで、子をプロセスグループごと止める。
|
|
2
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- Node の型が mutable */
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { CancelledError } from '../domain/errors.js';
|
|
5
|
+
import { normalizeNewlines } from '../domain/python-format.js';
|
|
6
|
+
import { childStdin } from './child-stdin.js';
|
|
7
|
+
import { toOsError } from './os-error.js';
|
|
8
|
+
/**
|
|
9
|
+
子の標準出力・標準エラーを溜める上限。出力が大きい git(log・diff 等)でも切れない大きさにし、超えた分は捨てる
|
|
10
|
+
*/
|
|
11
|
+
export const MAX_OUTPUT_BYTES = 1024 * 1024 * 1024;
|
|
12
|
+
/**
|
|
13
|
+
止めるときに SIGTERM を送ってから SIGKILL を送るまでの猶予。git が lock ファイルを片付ける時間
|
|
14
|
+
*/
|
|
15
|
+
export const KILL_GRACE_MILLISECONDS = 1000;
|
|
16
|
+
const running = new Set();
|
|
17
|
+
// 別のセッションの子には端末のシグナルが届かないので、受けたらグループへ送ってから既定の動きに戻す
|
|
18
|
+
const FORWARDED_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT'];
|
|
19
|
+
function createCapture() {
|
|
20
|
+
const chunks = [];
|
|
21
|
+
let captured = 0;
|
|
22
|
+
return {
|
|
23
|
+
push: (chunk) => {
|
|
24
|
+
const room = MAX_OUTPUT_BYTES - captured;
|
|
25
|
+
if (room <= 0)
|
|
26
|
+
return;
|
|
27
|
+
const kept = chunk.subarray(0, Math.min(room, chunk.length));
|
|
28
|
+
captured += kept.length;
|
|
29
|
+
chunks.push(kept);
|
|
30
|
+
},
|
|
31
|
+
text: () => normalizeNewlines(Buffer.concat(chunks).toString('utf8')),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function reasonText(reason) {
|
|
35
|
+
if (typeof reason === 'string')
|
|
36
|
+
return reason;
|
|
37
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
signal の取り消しの理由を持つ CancelledError
|
|
41
|
+
*/
|
|
42
|
+
export function cancelledBy(signal) {
|
|
43
|
+
return new CancelledError(reasonText(signal.reason));
|
|
44
|
+
}
|
|
45
|
+
// 子はグループの頭なので、負の pid で孫(git-remote-https・フック・シェルの下のコマンド)にも送る
|
|
46
|
+
function signalGroup(child, signal) {
|
|
47
|
+
if (child.pid === undefined)
|
|
48
|
+
return;
|
|
49
|
+
try {
|
|
50
|
+
process.kill(-child.pid, signal);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// 既に終わっている
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// SIGTERM で片付けの機会を渡し、猶予の後も残っていれば SIGKILL で止める
|
|
57
|
+
function terminateGroup(child) {
|
|
58
|
+
signalGroup(child, 'SIGTERM');
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
signalGroup(child, 'SIGKILL');
|
|
61
|
+
}, KILL_GRACE_MILLISECONDS).unref();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
生きている子のグループに SIGTERM を送る。サーバの終了のときに呼ぶ
|
|
65
|
+
*/
|
|
66
|
+
export function killRunningProcesses() {
|
|
67
|
+
for (const child of running)
|
|
68
|
+
signalGroup(child, 'SIGTERM');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
子プロセスを動かし、終わるのを待つ。起動に失敗(ENOENT など)したら OsError を投げる。
|
|
72
|
+
子が 0 で終わっていれば、取り消しと重なっても成功の結果を返す
|
|
73
|
+
*/
|
|
74
|
+
export async function runProcess(command, arguments_, options = {}) {
|
|
75
|
+
const { signal } = options;
|
|
76
|
+
if (signal?.aborted === true)
|
|
77
|
+
throw cancelledBy(signal);
|
|
78
|
+
const timeout = options.timeoutMilliseconds === undefined ? undefined : AbortSignal.timeout(options.timeoutMilliseconds);
|
|
79
|
+
// 時間切れのとき、フックなどの孫までまとめて止めるため、子を自分のグループの頭にする
|
|
80
|
+
const child = spawn(command, [...arguments_], {
|
|
81
|
+
cwd: options.cwd,
|
|
82
|
+
env: options.env,
|
|
83
|
+
shell: options.shell,
|
|
84
|
+
stdio: [options.stdin ?? childStdin(), 'pipe', 'pipe'],
|
|
85
|
+
detached: true,
|
|
86
|
+
});
|
|
87
|
+
running.add(child);
|
|
88
|
+
const stdout = createCapture();
|
|
89
|
+
const stderr = createCapture();
|
|
90
|
+
child.stdout.on('data', stdout.push);
|
|
91
|
+
child.stderr.on('data', stderr.push);
|
|
92
|
+
return await new Promise((resolve, reject) => {
|
|
93
|
+
let stopped;
|
|
94
|
+
let isSettled = false;
|
|
95
|
+
const hasExited = () => child.exitCode !== null || child.signalCode !== null;
|
|
96
|
+
const onTimeout = () => {
|
|
97
|
+
stop('timed-out');
|
|
98
|
+
};
|
|
99
|
+
const onAbort = () => {
|
|
100
|
+
stop('cancelled');
|
|
101
|
+
};
|
|
102
|
+
const forward = (received) => {
|
|
103
|
+
signalGroup(child, received);
|
|
104
|
+
finish();
|
|
105
|
+
process.kill(process.pid, received);
|
|
106
|
+
};
|
|
107
|
+
const finish = () => {
|
|
108
|
+
isSettled = true;
|
|
109
|
+
running.delete(child);
|
|
110
|
+
timeout?.removeEventListener('abort', onTimeout);
|
|
111
|
+
signal?.removeEventListener('abort', onAbort);
|
|
112
|
+
for (const name of FORWARDED_SIGNALS)
|
|
113
|
+
process.removeListener(name, forward);
|
|
114
|
+
};
|
|
115
|
+
const settle = (exitCode, exitSignal) => {
|
|
116
|
+
if (isSettled)
|
|
117
|
+
return;
|
|
118
|
+
finish();
|
|
119
|
+
if (stopped === 'cancelled' && signal !== undefined) {
|
|
120
|
+
reject(cancelledBy(signal));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
resolve({ exitCode, signal: exitSignal, stdout: stdout.text(), stderr: stderr.text(), isTimedOut: stopped === 'timed-out' });
|
|
124
|
+
};
|
|
125
|
+
// 止めた後は close を待たない。パイプを握った孫が残ると、close は孫が終わるまで来ない
|
|
126
|
+
const settleOnExit = () => {
|
|
127
|
+
child.stdout.destroy();
|
|
128
|
+
child.stderr.destroy();
|
|
129
|
+
settle(child.exitCode, child.signalCode);
|
|
130
|
+
};
|
|
131
|
+
const stop = (reason) => {
|
|
132
|
+
if (isSettled || stopped !== undefined)
|
|
133
|
+
return;
|
|
134
|
+
terminateGroup(child);
|
|
135
|
+
// 子が先に終わっていれば、その結果を返す。0 で終わっていない取り消しだけは、続きを動かさないために投げる
|
|
136
|
+
if (hasExited()) {
|
|
137
|
+
if (reason === 'cancelled' && child.exitCode !== 0)
|
|
138
|
+
stopped = reason;
|
|
139
|
+
settleOnExit();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
stopped = reason;
|
|
143
|
+
};
|
|
144
|
+
timeout?.addEventListener('abort', onTimeout, { once: true });
|
|
145
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
146
|
+
for (const name of FORWARDED_SIGNALS)
|
|
147
|
+
process.on(name, forward);
|
|
148
|
+
child.once('error', (error) => {
|
|
149
|
+
if (isSettled)
|
|
150
|
+
return;
|
|
151
|
+
finish();
|
|
152
|
+
const converted = toOsError(error);
|
|
153
|
+
reject(converted instanceof Error ? converted : error);
|
|
154
|
+
});
|
|
155
|
+
child.once('exit', (exitCode) => {
|
|
156
|
+
if (stopped === undefined)
|
|
157
|
+
return;
|
|
158
|
+
// 止める前に 0 で終わっていた(止めるのと終わるのが重なった)なら成功とする
|
|
159
|
+
if (exitCode === 0)
|
|
160
|
+
stopped = undefined;
|
|
161
|
+
settleOnExit();
|
|
162
|
+
});
|
|
163
|
+
child.once('close', (exitCode, exitSignal) => {
|
|
164
|
+
settle(exitCode, exitSignal);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=process-run.js.map
|
|
@@ -11,11 +11,8 @@ export interface SetupResult {
|
|
|
11
11
|
readonly stderr: string;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
setup_command を shell 経由で実行して、結果を構造化して返す。
|
|
15
|
-
|
|
16
|
-
stdin は常に閉じて、対話プロンプトで stall しないようにする。
|
|
17
|
-
timeoutSeconds を超えた場合は子プロセスを kill し、exitCode -1 の SetupResult を返す(例外は投げない)。-1 は timeout 起因の目印。
|
|
18
|
-
timeoutSeconds が 0 なら、Python と同じくすぐ時間切れになる
|
|
14
|
+
setup_command を shell 経由で実行して、結果を構造化して返す。stdin は閉じて、対話プロンプトで止まらないようにする。
|
|
15
|
+
timeoutSeconds を超えたら止めて exitCode -1 を返す(0 ならすぐ時間切れ)。signal で取り消されたら、シェルの下のコマンドごと止めて CancelledError を投げる
|
|
19
16
|
*/
|
|
20
|
-
export declare function runSetupCommand(command: string, cwd: string, timeoutSeconds?: number): SetupResult
|
|
17
|
+
export declare function runSetupCommand(command: string, cwd: string, timeoutSeconds?: number, signal?: Readonly<AbortSignal>): Promise<SetupResult>;
|
|
21
18
|
//# sourceMappingURL=worktree-setup.d.ts.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// ワークツリー作成後の setup_command の実行。Python の subprocess.run(shell=True)と同じ結果にする。
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
2
|
import os from 'node:os';
|
|
4
|
-
import {
|
|
5
|
-
import { MAX_OUTPUT_BYTES } from './git.js';
|
|
6
|
-
import { hasErrorCode, toOsError } from './os-error.js';
|
|
3
|
+
import { runProcess } from './process-run.js';
|
|
7
4
|
const SIGNAL_NUMBERS = new Map(Object.entries(os.constants.signals));
|
|
8
5
|
function signalNumber(signal) {
|
|
9
6
|
return signal === null ? -1 : -(SIGNAL_NUMBERS.get(signal) ?? 1);
|
|
@@ -13,29 +10,14 @@ function timeoutMilliseconds(timeoutSeconds) {
|
|
|
13
10
|
return timeoutSeconds === undefined ? undefined : Math.max(1, timeoutSeconds * 1000);
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
|
-
setup_command を shell 経由で実行して、結果を構造化して返す。
|
|
17
|
-
|
|
18
|
-
stdin は常に閉じて、対話プロンプトで stall しないようにする。
|
|
19
|
-
timeoutSeconds を超えた場合は子プロセスを kill し、exitCode -1 の SetupResult を返す(例外は投げない)。-1 は timeout 起因の目印。
|
|
20
|
-
timeoutSeconds が 0 なら、Python と同じくすぐ時間切れになる
|
|
13
|
+
setup_command を shell 経由で実行して、結果を構造化して返す。stdin は閉じて、対話プロンプトで止まらないようにする。
|
|
14
|
+
timeoutSeconds を超えたら止めて exitCode -1 を返す(0 ならすぐ時間切れ)。signal で取り消されたら、シェルの下のコマンドごと止めて CancelledError を投げる
|
|
21
15
|
*/
|
|
22
|
-
export function runSetupCommand(command, cwd, timeoutSeconds) {
|
|
23
|
-
const result =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
encoding: 'utf8',
|
|
27
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
28
|
-
timeout: timeoutMilliseconds(timeoutSeconds),
|
|
29
|
-
killSignal: 'SIGKILL',
|
|
30
|
-
maxBuffer: MAX_OUTPUT_BYTES,
|
|
31
|
-
});
|
|
32
|
-
const isTimedOut = hasErrorCode(result.error) && result.error.code === 'ETIMEDOUT';
|
|
33
|
-
if (!isTimedOut && result.error !== undefined)
|
|
34
|
-
throw toOsError(result.error);
|
|
35
|
-
const stdout = normalizeNewlines(result.stdout);
|
|
36
|
-
const stderr = normalizeNewlines(result.stderr);
|
|
37
|
-
return isTimedOut
|
|
16
|
+
export async function runSetupCommand(command, cwd, timeoutSeconds, signal) {
|
|
17
|
+
const result = await runProcess(command, [], { cwd, shell: true, stdin: 'ignore', timeoutMilliseconds: timeoutMilliseconds(timeoutSeconds), signal });
|
|
18
|
+
const { stdout, stderr } = result;
|
|
19
|
+
return result.isTimedOut
|
|
38
20
|
? { command, exitCode: -1, stdout, stderr: `${stderr}timeout after ${String(timeoutSeconds)} seconds`.trimStart() }
|
|
39
|
-
: { command, exitCode: result.
|
|
21
|
+
: { command, exitCode: result.exitCode ?? signalNumber(result.signal), stdout, stderr };
|
|
40
22
|
}
|
|
41
23
|
//# sourceMappingURL=worktree-setup.js.map
|
|
@@ -164,12 +164,16 @@ export interface CreateWorktreeOptions {
|
|
|
164
164
|
使うプロジェクトの設定の名前。省略時は remote のリポを含む設定
|
|
165
165
|
*/
|
|
166
166
|
readonly project?: string | undefined;
|
|
167
|
+
/**
|
|
168
|
+
MCP の要求の取り消し。setup_command を止める
|
|
169
|
+
*/
|
|
170
|
+
readonly signal?: Readonly<AbortSignal> | undefined;
|
|
167
171
|
}
|
|
168
172
|
/**
|
|
169
173
|
ワークツリーを作成する。cwd は対象 Git リポジトリのパス。
|
|
170
174
|
作成に失敗した場合、プロジェクトルート・既存ブランチ衝突・設定の不備は WorktreeRuntimeError
|
|
171
175
|
*/
|
|
172
|
-
export declare function createWorktree(cwd: string, diagnostics: Diagnostics, options?: Readonly<CreateWorktreeOptions>): WorktreeCreateResult
|
|
176
|
+
export declare function createWorktree(cwd: string, diagnostics: Diagnostics, options?: Readonly<CreateWorktreeOptions>): Promise<WorktreeCreateResult>;
|
|
173
177
|
/**
|
|
174
178
|
ワークツリーを削除する。name は worktree add が付けた名前(wtN)か、checkout しているブランチ名。
|
|
175
179
|
WT が見つからない・削除に失敗した場合は WorktreeRuntimeError。
|
|
@@ -362,11 +362,11 @@ function copyUntrackedToWorktree(mainWorktree, worktreePath, spec, symlinkedPath
|
|
|
362
362
|
return copyable.length > 0 ? copyFiles(mainWorktree, worktreePath, copyable) : [];
|
|
363
363
|
}
|
|
364
364
|
// セットアップコマンド実行。優先順位: CLI --setup 明示 > config.setup_command > skip
|
|
365
|
-
function runEffectiveSetup(setupCommand, config, worktreePath, diagnostics) {
|
|
365
|
+
async function runEffectiveSetup(setupCommand, config, worktreePath, diagnostics, signal) {
|
|
366
366
|
const effective = setupCommand ?? config.setup_command;
|
|
367
367
|
if (effective === undefined || effective === '')
|
|
368
368
|
return undefined;
|
|
369
|
-
const result = runSetupCommand(effective, worktreePath, config.setup_command_timeout);
|
|
369
|
+
const result = await runSetupCommand(effective, worktreePath, config.setup_command_timeout, signal);
|
|
370
370
|
if (result.exitCode !== 0) {
|
|
371
371
|
// Python の core と同じ 1 メッセージ。字下げは受け口側が付ける
|
|
372
372
|
const head = result.exitCode === -1 ? `setup command timed out: ${effective}` : `setup command failed (exit ${String(result.exitCode)}): ${effective}`;
|
|
@@ -385,7 +385,7 @@ function runEffectiveSetup(setupCommand, config, worktreePath, diagnostics) {
|
|
|
385
385
|
ワークツリーを作成する。cwd は対象 Git リポジトリのパス。
|
|
386
386
|
作成に失敗した場合、プロジェクトルート・既存ブランチ衝突・設定の不備は WorktreeRuntimeError
|
|
387
387
|
*/
|
|
388
|
-
export function createWorktree(cwd, diagnostics, options = {}) {
|
|
388
|
+
export async function createWorktree(cwd, diagnostics, options = {}) {
|
|
389
389
|
// 1. メインWT検出 & プロジェクトルート
|
|
390
390
|
const mainWorktree = findMainWorktree(cwd);
|
|
391
391
|
const projectRoot = detectProjectRoot(cwd);
|
|
@@ -416,7 +416,7 @@ export function createWorktree(cwd, diagnostics, options = {}) {
|
|
|
416
416
|
? { linkedFiles: [], symlinkedPaths: [] }
|
|
417
417
|
: createWorktreeSymlinks(worktreeConfig, projectRoot, worktreePath, diagnostics);
|
|
418
418
|
const copiedFiles = options.shouldCopy === false ? [] : copyUntrackedToWorktree(mainWorktree, worktreePath, spec, linking.symlinkedPaths);
|
|
419
|
-
const setupResult = runEffectiveSetup(options.setupCommand, worktreeConfig, worktreePath, diagnostics);
|
|
419
|
+
const setupResult = await runEffectiveSetup(options.setupCommand, worktreeConfig, worktreePath, diagnostics, options.signal);
|
|
420
420
|
return { name, path: worktreePath, branch: name, baseBranch, copiedFiles, linkedFiles: linking.linkedFiles, setupResult };
|
|
421
421
|
}
|
|
422
422
|
/**
|
package/cli/dist/mcp/result.d.ts
CHANGED
|
@@ -46,9 +46,9 @@ export interface CollectedIo {
|
|
|
46
46
|
readonly warnings: () => readonly string[];
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行、項目、warning の文を集める io
|
|
49
|
+
stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行、項目、warning の文を集める io。signal は io にそのまま渡す
|
|
50
50
|
*/
|
|
51
|
-
export declare function collectIo(): CollectedIo;
|
|
51
|
+
export declare function collectIo(signal?: Readonly<AbortSignal>): CollectedIo;
|
|
52
52
|
/**
|
|
53
53
|
ツールの項目と並べて structuredContent の最上位に置く、全ツールに共通の 4 項目
|
|
54
54
|
*/
|
|
@@ -102,7 +102,7 @@ export declare function toToolResult(outcome: Readonly<CommandOutcome>): CallToo
|
|
|
102
102
|
*/
|
|
103
103
|
export declare function toRejectedResult(message: string): CallToolResult;
|
|
104
104
|
/**
|
|
105
|
-
中断(notifications/cancelled
|
|
105
|
+
中断(notifications/cancelled か接続の切断)で、本体を呼ばなかったか途中で止めた結果。応答はクライアントに届かない
|
|
106
106
|
*/
|
|
107
107
|
export declare function toAbortedResult(): CallToolResult;
|
|
108
108
|
//# sourceMappingURL=result.d.ts.map
|
package/cli/dist/mcp/result.js
CHANGED
|
@@ -5,9 +5,9 @@ import { z } from 'zod';
|
|
|
5
5
|
import { WARNING_PREFIX } from '../commands/output.js';
|
|
6
6
|
import { USAGE_EXIT_CODE } from '../commands/usage-error.js';
|
|
7
7
|
/**
|
|
8
|
-
stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行、項目、warning の文を集める io
|
|
8
|
+
stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行、項目、warning の文を集める io。signal は io にそのまま渡す
|
|
9
9
|
*/
|
|
10
|
-
export function collectIo() {
|
|
10
|
+
export function collectIo(signal) {
|
|
11
11
|
const out = [];
|
|
12
12
|
const error = [];
|
|
13
13
|
let failureKind;
|
|
@@ -24,6 +24,7 @@ export function collectIo() {
|
|
|
24
24
|
error.push(text);
|
|
25
25
|
},
|
|
26
26
|
surface: 'mcp',
|
|
27
|
+
...(signal !== undefined && { signal }),
|
|
27
28
|
failureKind: (kind) => {
|
|
28
29
|
failureKind ??= kind;
|
|
29
30
|
},
|
|
@@ -164,7 +165,7 @@ export function toRejectedResult(message) {
|
|
|
164
165
|
return toToolResult({ exitCode: USAGE_EXIT_CODE, stdout: '', stderr: '', kind: 'invalid-input', message });
|
|
165
166
|
}
|
|
166
167
|
/**
|
|
167
|
-
中断(notifications/cancelled
|
|
168
|
+
中断(notifications/cancelled か接続の切断)で、本体を呼ばなかったか途中で止めた結果。応答はクライアントに届かない
|
|
168
169
|
*/
|
|
169
170
|
export function toAbortedResult() {
|
|
170
171
|
return toToolResult({ exitCode: 1, stdout: '', stderr: '', kind: 'aborted', message: 'cancelled' });
|
package/cli/dist/mcp/serve.d.ts
CHANGED
|
@@ -13,7 +13,19 @@ export interface WritableTarget {
|
|
|
13
13
|
stdout を JSON-RPC 専用にする。返した Writable だけが本物の stdout へ届き、ほかの書き込みは stderr へ逃がす。同じ stdout に対しては冪等
|
|
14
14
|
*/
|
|
15
15
|
export declare function installStdoutGuard(stdout: WritableTarget, stderr: WritableTarget): Writable;
|
|
16
|
+
/**
|
|
17
|
+
SIGTERM / SIGINT / 'exit' の配線先。既定は process 本体で、テストはフェイクを渡す
|
|
18
|
+
*/
|
|
19
|
+
export interface ProcessSignals {
|
|
20
|
+
on(event: 'SIGTERM' | 'SIGINT' | 'exit', listener: () => void): void;
|
|
21
|
+
exit(code: number): void;
|
|
22
|
+
}
|
|
16
23
|
export interface McpServeDependencies {
|
|
24
|
+
/**
|
|
25
|
+
終了時の後始末。別のプロセスグループで待っている子は、サーバが終わっても残るので止める
|
|
26
|
+
*/
|
|
27
|
+
readonly onShutdown: readonly (() => void)[];
|
|
28
|
+
readonly signals: ProcessSignals;
|
|
17
29
|
/**
|
|
18
30
|
options.unavailableReason があるとき、サーバはどのツールの呼び出しにもその理由を返す(対象のリポを決められなかったとき)
|
|
19
31
|
*/
|
package/cli/dist/mcp/serve.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// `pecot mcp` の実装。cli.ts が dynamic import で読む。stdout は JSON-RPC 専用にし、stdin が閉じたら接続を閉じる。
|
|
2
|
-
// pecot-tools の serve.ts
|
|
2
|
+
// pecot-tools の serve.ts と骨格が同じ。終了のときは、待っている子プロセス(runProcess)を止める。
|
|
3
3
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数は Node の stream。mutable な型でしか公開されていない */
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
import { StdioServerTransport, serveStdio } from '@modelcontextprotocol/server/stdio';
|
|
6
6
|
import { setChildStdin } from '../infra/child-stdin.js';
|
|
7
|
+
import { killRunningProcesses } from '../infra/process-run.js';
|
|
7
8
|
import { createOutput } from '../commands/output.js';
|
|
8
9
|
import { UNDETERMINED_PREFIX, resolveSessionDirectory, unusableReason } from './session-directory.js';
|
|
9
10
|
import { createMcpServer } from './server.js';
|
|
@@ -63,6 +64,26 @@ export function installStdoutGuard(stdout, stderr) {
|
|
|
63
64
|
installedGuards.set(stdout, protocolStdout);
|
|
64
65
|
return protocolStdout;
|
|
65
66
|
}
|
|
67
|
+
const SIGTERM_EXIT_CODE = 143;
|
|
68
|
+
const SIGINT_EXIT_CODE = 130;
|
|
69
|
+
function runShutdown(dependencies) {
|
|
70
|
+
for (const hook of dependencies.onShutdown)
|
|
71
|
+
hook();
|
|
72
|
+
}
|
|
73
|
+
// SIGTERM / SIGINT は既定の即終了が無効になるので、明示的に exit する
|
|
74
|
+
function installShutdownHandlers(dependencies) {
|
|
75
|
+
dependencies.signals.on('SIGTERM', () => {
|
|
76
|
+
runShutdown(dependencies);
|
|
77
|
+
dependencies.signals.exit(SIGTERM_EXIT_CODE);
|
|
78
|
+
});
|
|
79
|
+
dependencies.signals.on('SIGINT', () => {
|
|
80
|
+
runShutdown(dependencies);
|
|
81
|
+
dependencies.signals.exit(SIGINT_EXIT_CODE);
|
|
82
|
+
});
|
|
83
|
+
dependencies.signals.on('exit', () => {
|
|
84
|
+
runShutdown(dependencies);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
66
87
|
function messageOf(error) {
|
|
67
88
|
return error instanceof Error ? error.message : String(error);
|
|
68
89
|
}
|
|
@@ -74,6 +95,7 @@ export function runMcpServe(dependencies) {
|
|
|
74
95
|
const protocolStdout = dependencies.installStdoutGuard();
|
|
75
96
|
const transport = dependencies.createTransport(dependencies.stdin, protocolStdout);
|
|
76
97
|
const reportError = reportTo(dependencies.stderr);
|
|
98
|
+
installShutdownHandlers(dependencies);
|
|
77
99
|
// 接続とインスタンスの onerror に同じ Error が流れるので、1 回だけ報告する
|
|
78
100
|
const report = (error) => {
|
|
79
101
|
if (reportedErrors.has(error))
|
|
@@ -88,9 +110,13 @@ export function runMcpServe(dependencies) {
|
|
|
88
110
|
if (collected.stderr !== '')
|
|
89
111
|
reportError(`stderr so far: ${collected.stderr}`);
|
|
90
112
|
};
|
|
113
|
+
const reportCancelled = (reason) => {
|
|
114
|
+
// eslint-disable-next-line no-restricted-syntax -- 取り消しの理由の記録。失敗ではないので error の行にしない
|
|
115
|
+
dependencies.stderr.write(`cancelled: ${reason}\n`);
|
|
116
|
+
};
|
|
91
117
|
const handle = serveStdio(() => {
|
|
92
118
|
try {
|
|
93
|
-
const server = dependencies.createServer({ reportUnexpected });
|
|
119
|
+
const server = dependencies.createServer({ reportUnexpected, reportCancelled });
|
|
94
120
|
// eslint-disable-next-line unicorn/prefer-add-event-listener -- SDK の Protocol は onerror 経由で通知する
|
|
95
121
|
server.server.onerror = report;
|
|
96
122
|
return server;
|
|
@@ -118,6 +144,8 @@ export function defaultDependencies() {
|
|
|
118
144
|
return {
|
|
119
145
|
createServer: options => createMcpServer(undefined, options),
|
|
120
146
|
createTransport: (stdin, stdout) => new StdioServerTransport(stdin, stdout),
|
|
147
|
+
onShutdown: [killRunningProcesses],
|
|
148
|
+
signals: process,
|
|
121
149
|
/* v8 ignore next -- 実 process.stdout を差し替えるので、単体テストからは起動しない(ガード本体は偽の stream で確かめる) */
|
|
122
150
|
installStdoutGuard: () => installStdoutGuard(process.stdout, process.stderr),
|
|
123
151
|
stdin: process.stdin,
|
package/cli/dist/mcp/server.d.ts
CHANGED
|
@@ -13,6 +13,10 @@ export interface McpServerOptions {
|
|
|
13
13
|
readonly stdout: string;
|
|
14
14
|
readonly stderr: string;
|
|
15
15
|
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
要求の取り消しでコマンドを止めたとき、その理由を伝える先(仕様が理由の記録を求める)
|
|
18
|
+
*/
|
|
19
|
+
readonly reportCancelled?: (reason: string) => void;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
MCP サーバを作り、commands のそれぞれをツールとして登録する。名前は toolName、説明は description、並びは commands の順
|
package/cli/dist/mcp/server.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- zod と SDK の型は readonly にできない */
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import { InvalidValueError } from '../domain/errors.js';
|
|
5
|
+
import { CancelledError, InvalidValueError } from '../domain/errors.js';
|
|
6
6
|
import { parseOwnerRepository } from '../domain/repository-resolver.js';
|
|
7
7
|
import { resolveApiUrlOverride } from '../infra/github/client.js';
|
|
8
|
+
import { cancelledBy } from '../infra/process-run.js';
|
|
8
9
|
import { usageOf, withUsage } from '../commands/command-binding.js';
|
|
9
10
|
import { createOutput } from '../commands/output.js';
|
|
10
11
|
import { exitCodeOfFailure } from '../commands/failure.js';
|
|
@@ -83,7 +84,7 @@ function unexpectedMessage(error) {
|
|
|
83
84
|
async function invoke(definition, raw, options, signal) {
|
|
84
85
|
if (options.unavailableReason !== undefined)
|
|
85
86
|
return unavailableResult(options.unavailableReason);
|
|
86
|
-
const collected = collectIo();
|
|
87
|
+
const collected = collectIo(signal);
|
|
87
88
|
// interface-env: TERMINAL_WIDTH COLUMNS
|
|
88
89
|
const width = outputWidth(process.env, undefined);
|
|
89
90
|
let exitCode;
|
|
@@ -94,13 +95,17 @@ async function invoke(definition, raw, options, signal) {
|
|
|
94
95
|
if (preparation.kind === 'rejected')
|
|
95
96
|
return toRejectedResult(preparation.message);
|
|
96
97
|
try {
|
|
97
|
-
exitCode = await preparation.command.run(
|
|
98
|
+
exitCode = await preparation.command.run(collected.io);
|
|
98
99
|
}
|
|
99
100
|
catch (error) {
|
|
100
101
|
throw withUsage(error, usageOf(definition));
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
catch (error) {
|
|
105
|
+
if (error instanceof CancelledError) {
|
|
106
|
+
options.reportCancelled?.(error.message);
|
|
107
|
+
return toAbortedResult();
|
|
108
|
+
}
|
|
104
109
|
// 使い方の誤りは枠で出すので、error の行の代わりに例外の文の 1 行目を message にする
|
|
105
110
|
if (error instanceof UsageError)
|
|
106
111
|
message = error.message.split('\n', 1)[0];
|
|
@@ -149,14 +154,17 @@ function partialData(definition, raw, stdout, stderr, options) {
|
|
|
149
154
|
}
|
|
150
155
|
// コマンドは process.cwd()(起動のときに serve.ts が決めたセッションのディレクトリ)と .pecot/ の状態ファイルを読み書きするので、呼び出しは 1 件ずつ実行する。接続が複数あっても共有する
|
|
151
156
|
const sequence = { tail: Promise.resolve(true) };
|
|
152
|
-
async function inSequence(signal, task) {
|
|
157
|
+
async function inSequence(signal, options, task) {
|
|
153
158
|
const previous = sequence.tail;
|
|
154
159
|
const turn = Promise.withResolvers();
|
|
155
160
|
sequence.tail = turn.promise;
|
|
156
161
|
await previous;
|
|
157
162
|
try {
|
|
158
163
|
// 待っている間に中断(notifications/cancelled)か接続の切断があれば、本体を呼ばない。応答は届かない
|
|
159
|
-
|
|
164
|
+
if (!signal.aborted)
|
|
165
|
+
return await task();
|
|
166
|
+
options.reportCancelled?.(cancelledBy(signal).message);
|
|
167
|
+
return toAbortedResult();
|
|
160
168
|
}
|
|
161
169
|
finally {
|
|
162
170
|
turn.resolve(true);
|
|
@@ -168,7 +176,7 @@ MCP サーバを作り、commands のそれぞれをツールとして登録す
|
|
|
168
176
|
export function createMcpServer(commands = COMMANDS, options = {}) {
|
|
169
177
|
const server = new McpServer({ name: MCP_SERVER_NAME, version: readVersion() });
|
|
170
178
|
for (const definition of commands) {
|
|
171
|
-
server.registerTool(definition.toolName, { description: definition.description, inputSchema: passthroughSchema(definition), outputSchema: standardOutputSchema(toolOutputSchema(definition.output)) }, async (arguments_, serverContext) => await inSequence(serverContext.mcpReq.signal, async () => await invoke(definition, arguments_, options, serverContext.mcpReq.signal)));
|
|
179
|
+
server.registerTool(definition.toolName, { description: definition.description, inputSchema: passthroughSchema(definition), outputSchema: standardOutputSchema(toolOutputSchema(definition.output)) }, async (arguments_, serverContext) => await inSequence(serverContext.mcpReq.signal, options, async () => await invoke(definition, arguments_, options, serverContext.mcpReq.signal)));
|
|
172
180
|
}
|
|
173
181
|
return server;
|
|
174
182
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pecot/workflow-mcp",
|
|
3
|
-
"version": "8.0.1-dev.
|
|
3
|
+
"version": "8.0.1-dev.60",
|
|
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.
|
|
9
|
+
"version": "8.0.1-dev.60",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/server": "^2.4.0",
|