@pecot/workflow-mcp 8.0.1-dev.59 → 8.0.1-dev.61
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 +85 -15
- 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/github/pulls.d.ts +4 -0
- package/cli/dist/infra/github/pulls.js +6 -0
- 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
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.61",
|
|
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.61",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/server": "^2.4.0",
|