@pecot/workflow-mcp 0.0.0-stage → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +12 -0
- package/cli/dist/commands/github-client.js +23 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +55 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +19 -0
- package/cli/dist/domain/errors.js +31 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-readout.d.ts +107 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +134 -0
- package/cli/dist/domain/pull-request.js +232 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +66 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +49 -0
- package/cli/dist/infra/config-store.js +121 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +74 -0
- package/cli/dist/infra/git.js +133 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +173 -0
- package/cli/dist/infra/github/client.js +576 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +47 -0
- package/cli/dist/infra/github/errors.js +42 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +129 -0
- package/cli/dist/infra/github/issues.js +273 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +45 -0
- package/cli/dist/infra/state-store.js +118 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +139 -0
- package/cli/dist/infra/worktree-links.js +433 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +128 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +181 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +67 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Writable } from 'node:stream';
|
|
2
|
+
import type { Readable } from 'node:stream';
|
|
3
|
+
import type { McpServer, Transport } from '@modelcontextprotocol/server';
|
|
4
|
+
import type { StdioServerHandle } from '@modelcontextprotocol/server/stdio';
|
|
5
|
+
import type { McpServerOptions } from './server.js';
|
|
6
|
+
/**
|
|
7
|
+
process.stdout / process.stderr のうち、ガードが使う面
|
|
8
|
+
*/
|
|
9
|
+
export interface WritableTarget {
|
|
10
|
+
write(chunk: string | Uint8Array, callback?: (error?: Error | null) => void): boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
stdout を JSON-RPC 専用にする。返した Writable だけが本物の stdout へ届き、ほかの書き込みは stderr へ逃がす。同じ stdout に対しては冪等
|
|
14
|
+
*/
|
|
15
|
+
export declare function installStdoutGuard(stdout: WritableTarget, stderr: WritableTarget): Writable;
|
|
16
|
+
export interface McpServeDependencies {
|
|
17
|
+
/**
|
|
18
|
+
options.unavailableReason があるとき、サーバはどのツールの呼び出しにもその理由を返す(対象のリポを決められなかったとき)
|
|
19
|
+
*/
|
|
20
|
+
readonly createServer: (options: Readonly<McpServerOptions>) => McpServer;
|
|
21
|
+
readonly createTransport: (stdin: Readable, stdout: Writable) => Transport;
|
|
22
|
+
/**
|
|
23
|
+
stdout のガードを張り、JSON-RPC 専用の Writable を返す
|
|
24
|
+
*/
|
|
25
|
+
readonly installStdoutGuard: () => Writable;
|
|
26
|
+
readonly stdin: Readable;
|
|
27
|
+
readonly stderr: WritableTarget;
|
|
28
|
+
/**
|
|
29
|
+
セッションのディレクトリの判定に使う環境変数。読む名前は session-directory.ts にある
|
|
30
|
+
*/
|
|
31
|
+
readonly environment: Readonly<Record<string, string | undefined>>;
|
|
32
|
+
/**
|
|
33
|
+
起動したときの作業ディレクトリを読む。読めない(消えている)ときは投げる
|
|
34
|
+
*/
|
|
35
|
+
readonly cwd: () => string;
|
|
36
|
+
/**
|
|
37
|
+
作業ディレクトリを移す。失敗したら投げる
|
|
38
|
+
*/
|
|
39
|
+
readonly changeDirectory: (directory: string) => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
MCP サーバを stdio で待ち受ける。factory は 1 接続で複数回呼ばれうるので、createServer と onerror の設定以外の副作用を持たせない。
|
|
43
|
+
stdin が閉じたら接続を閉じる
|
|
44
|
+
*/
|
|
45
|
+
export declare function runMcpServe(dependencies: Readonly<McpServeDependencies>): StdioServerHandle;
|
|
46
|
+
export declare function defaultDependencies(): McpServeDependencies;
|
|
47
|
+
/**
|
|
48
|
+
`pecot mcp` の本体。子プロセスの stdin を切り離してから待ち受ける。起動できたら 0、同期の起動の失敗は stderr に出して 1 を返す
|
|
49
|
+
*/
|
|
50
|
+
export declare function executeMcpServe(buildDependencies?: () => McpServeDependencies): number;
|
|
51
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// `pecot mcp` の実装。cli.ts が dynamic import で読む。stdout は JSON-RPC 専用にし、stdin が閉じたら接続を閉じる。
|
|
2
|
+
// pecot-tools の serve.ts と骨格が同じ。SIGTERM・SIGINT の配線と子の kill は、子が短命で git が同期なので持たない(共有は別途)。
|
|
3
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数は Node の stream。mutable な型でしか公開されていない */
|
|
4
|
+
import { Writable } from 'node:stream';
|
|
5
|
+
import { StdioServerTransport, serveStdio } from '@modelcontextprotocol/server/stdio';
|
|
6
|
+
import { setChildStdin } from '../infra/child-stdin.js';
|
|
7
|
+
import { createOutput } from '../commands/output.js';
|
|
8
|
+
import { UNDETERMINED_PREFIX, resolveSessionDirectory, unusableReason } from './session-directory.js';
|
|
9
|
+
import { createMcpServer } from './server.js';
|
|
10
|
+
// 二重に張ると、2 回目が転送用の write を元の write として束縛し、JSON-RPC が stderr へ回る。張り済みなら初回の Writable を返す
|
|
11
|
+
const installedGuards = new WeakMap();
|
|
12
|
+
// stdout の書き込み失敗は、ガードと SDK の onerror に同じ Error で届く。1 回だけ報告する
|
|
13
|
+
const reportedErrors = new WeakSet();
|
|
14
|
+
function discard() {
|
|
15
|
+
// stdout には何も出さない
|
|
16
|
+
}
|
|
17
|
+
function reportTo(target) {
|
|
18
|
+
const output = createOutput(false, {
|
|
19
|
+
stdout: discard,
|
|
20
|
+
stderr: (text) => {
|
|
21
|
+
target.write(text);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return (message) => {
|
|
25
|
+
output.error(message);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async function closeQuietly(handle) {
|
|
29
|
+
try {
|
|
30
|
+
await handle.close();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// 終了処理中の失敗は、報告先が無い
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
stdout を JSON-RPC 専用にする。返した Writable だけが本物の stdout へ届き、ほかの書き込みは stderr へ逃がす。同じ stdout に対しては冪等
|
|
38
|
+
*/
|
|
39
|
+
export function installStdoutGuard(stdout, stderr) {
|
|
40
|
+
const installed = installedGuards.get(stdout);
|
|
41
|
+
if (installed !== undefined)
|
|
42
|
+
return installed;
|
|
43
|
+
const isOriginalWrite = stdout.write.bind(stdout);
|
|
44
|
+
const isForwardToStderr = (chunk, encodingOrCallback, callback) => {
|
|
45
|
+
const done = typeof encodingOrCallback === 'function' ? encodingOrCallback : callback;
|
|
46
|
+
// eslint-disable-next-line no-restricted-syntax -- stdout へ書かれた生の chunk を、行に整えず stderr へ逃がす
|
|
47
|
+
const isWritten = stderr.write(chunk);
|
|
48
|
+
done?.();
|
|
49
|
+
return isWritten;
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(stdout, 'write', { value: isForwardToStderr, writable: true, configurable: true });
|
|
52
|
+
const protocolStdout = new Writable({
|
|
53
|
+
write(chunk, _encoding, callback) {
|
|
54
|
+
isOriginalWrite(chunk, callback);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
// EPIPE は error イベントで上がる。拾わないと uncaught 例外で落ちる
|
|
58
|
+
protocolStdout.on('error', (error) => {
|
|
59
|
+
reportedErrors.add(error);
|
|
60
|
+
reportTo(stderr)(`failed to write to stdout: ${error.message}`);
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
});
|
|
63
|
+
installedGuards.set(stdout, protocolStdout);
|
|
64
|
+
return protocolStdout;
|
|
65
|
+
}
|
|
66
|
+
function messageOf(error) {
|
|
67
|
+
return error instanceof Error ? error.message : String(error);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
MCP サーバを stdio で待ち受ける。factory は 1 接続で複数回呼ばれうるので、createServer と onerror の設定以外の副作用を持たせない。
|
|
71
|
+
stdin が閉じたら接続を閉じる
|
|
72
|
+
*/
|
|
73
|
+
export function runMcpServe(dependencies) {
|
|
74
|
+
const protocolStdout = dependencies.installStdoutGuard();
|
|
75
|
+
const transport = dependencies.createTransport(dependencies.stdin, protocolStdout);
|
|
76
|
+
const reportError = reportTo(dependencies.stderr);
|
|
77
|
+
// 接続とインスタンスの onerror に同じ Error が流れるので、1 回だけ報告する
|
|
78
|
+
const report = (error) => {
|
|
79
|
+
if (reportedErrors.has(error))
|
|
80
|
+
return;
|
|
81
|
+
reportedErrors.add(error);
|
|
82
|
+
reportError(error.message);
|
|
83
|
+
};
|
|
84
|
+
const reportUnexpected = (error, collected) => {
|
|
85
|
+
reportError(error instanceof Error ? (error.stack ?? error.message) : String(error));
|
|
86
|
+
if (collected.stdout !== '')
|
|
87
|
+
reportError(`stdout so far: ${collected.stdout}`);
|
|
88
|
+
if (collected.stderr !== '')
|
|
89
|
+
reportError(`stderr so far: ${collected.stderr}`);
|
|
90
|
+
};
|
|
91
|
+
const handle = serveStdio(() => {
|
|
92
|
+
try {
|
|
93
|
+
const server = dependencies.createServer({ reportUnexpected });
|
|
94
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener -- SDK の Protocol は onerror 経由で通知する
|
|
95
|
+
server.server.onerror = report;
|
|
96
|
+
return server;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
// 起動に失敗したプロセスは待ち受けても役に立たない
|
|
100
|
+
process.exitCode = 1;
|
|
101
|
+
void closeQuietly(handle);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}, { transport, onerror: report });
|
|
105
|
+
return handle;
|
|
106
|
+
}
|
|
107
|
+
// セッションのディレクトリの判定が読む環境変数
|
|
108
|
+
function hostEnvironment() {
|
|
109
|
+
return {
|
|
110
|
+
CLAUDE_PLUGIN_ROOT: process.env['CLAUDE_PLUGIN_ROOT'],
|
|
111
|
+
PLUGIN_ROOT: process.env['PLUGIN_ROOT'],
|
|
112
|
+
COPILOT_PLUGIN_ROOT: process.env['COPILOT_PLUGIN_ROOT'],
|
|
113
|
+
COPILOT_SESSION_CWD: process.env['COPILOT_SESSION_CWD'],
|
|
114
|
+
CLAUDE_PROJECT_DIR: process.env['CLAUDE_PROJECT_DIR'],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export function defaultDependencies() {
|
|
118
|
+
return {
|
|
119
|
+
createServer: options => createMcpServer(undefined, options),
|
|
120
|
+
createTransport: (stdin, stdout) => new StdioServerTransport(stdin, stdout),
|
|
121
|
+
/* v8 ignore next -- 実 process.stdout を差し替えるので、単体テストからは起動しない(ガード本体は偽の stream で確かめる) */
|
|
122
|
+
installStdoutGuard: () => installStdoutGuard(process.stdout, process.stderr),
|
|
123
|
+
stdin: process.stdin,
|
|
124
|
+
stderr: process.stderr,
|
|
125
|
+
environment: hostEnvironment(),
|
|
126
|
+
cwd: () => process.cwd(),
|
|
127
|
+
changeDirectory: (directory) => {
|
|
128
|
+
process.chdir(directory);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
対象のリポを見るディレクトリを決めて移る。決められない(cwd を読めない、判定の結果、移るのに失敗)ときは理由を返す
|
|
134
|
+
*/
|
|
135
|
+
function moveToSessionDirectory(dependencies) {
|
|
136
|
+
let cwd;
|
|
137
|
+
try {
|
|
138
|
+
cwd = dependencies.cwd();
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return `${UNDETERMINED_PREFIX}: cannot read the current directory: ${messageOf(error)}`;
|
|
142
|
+
}
|
|
143
|
+
const decision = resolveSessionDirectory(dependencies.environment, cwd);
|
|
144
|
+
if (decision.kind === 'stay')
|
|
145
|
+
return undefined;
|
|
146
|
+
if (decision.kind === 'undetermined')
|
|
147
|
+
return decision.reason;
|
|
148
|
+
try {
|
|
149
|
+
dependencies.changeDirectory(decision.directory);
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return unusableReason(decision.variable, decision.value, decision.directory, messageOf(error));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
`pecot mcp` の本体。子プロセスの stdin を切り離してから待ち受ける。起動できたら 0、同期の起動の失敗は stderr に出して 1 を返す
|
|
158
|
+
*/
|
|
159
|
+
export function executeMcpServe(buildDependencies = defaultDependencies) {
|
|
160
|
+
let dependencies;
|
|
161
|
+
try {
|
|
162
|
+
dependencies = buildDependencies();
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
reportTo(process.stderr)(messageOf(error));
|
|
166
|
+
return 1;
|
|
167
|
+
}
|
|
168
|
+
// 子が JSON-RPC のパイプ(fd 0)を読むと、メッセージを食う
|
|
169
|
+
setChildStdin('ignore');
|
|
170
|
+
try {
|
|
171
|
+
// 移るのは起動の 1 回だけ。決められなくても起動し、ツールの呼び出しで理由を返す(起動に失敗したサーバは、ホストにはツールが無いように見える)
|
|
172
|
+
const unavailableReason = moveToSessionDirectory(dependencies);
|
|
173
|
+
if (unavailableReason !== undefined)
|
|
174
|
+
reportTo(dependencies.stderr)(unavailableReason);
|
|
175
|
+
runMcpServe({ ...dependencies, createServer: options => dependencies.createServer({ ...options, unavailableReason }) });
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
reportTo(dependencies.stderr)(messageOf(error));
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import type { CommandDefinition } from '../commands/registry.js';
|
|
3
|
+
export declare const MCP_SERVER_NAME = "pecot-workflow";
|
|
4
|
+
export interface McpServerOptions {
|
|
5
|
+
/**
|
|
6
|
+
対象のリポを決められなかった理由。あるとき、どのツールの呼び出しもコマンドを呼ばず、この理由を失敗(exit code 1)で返す。tools/list は変わらない
|
|
7
|
+
*/
|
|
8
|
+
readonly unavailableReason?: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
プログラムの誤り(報告できる失敗でも使い方の誤りでもない例外)と、それまでに集めた出力を、切り分けのために伝える先。SDK は message だけの結果にする
|
|
11
|
+
*/
|
|
12
|
+
readonly reportUnexpected?: (error: unknown, collected: {
|
|
13
|
+
readonly stdout: string;
|
|
14
|
+
readonly stderr: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
MCP サーバを作り、commands のそれぞれをツールとして登録する。名前は toolName、説明は description、並びは commands の順
|
|
19
|
+
*/
|
|
20
|
+
export declare function createMcpServer(commands?: readonly CommandDefinition[], options?: Readonly<McpServerOptions>): McpServer;
|
|
21
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// COMMANDS の 34 個を MCP のツールとして登録するサーバ。CLI と同じ定義の run を呼び、結果の形だけが違う。
|
|
2
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- zod と SDK の型は readonly にできない */
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { InvalidValueError } from '../domain/errors.js';
|
|
6
|
+
import { parseOwnerRepository } from '../domain/repository-resolver.js';
|
|
7
|
+
import { resolveApiUrlOverride } from '../infra/github/client.js';
|
|
8
|
+
import { usageOf, withUsage } from '../commands/command-binding.js';
|
|
9
|
+
import { createOutput } from '../commands/output.js';
|
|
10
|
+
import { exitCodeOfFailure } from '../commands/failure.js';
|
|
11
|
+
import { isRecord } from '../commands/input-schema.js';
|
|
12
|
+
import { COMMANDS } from '../commands/registry.js';
|
|
13
|
+
import { outputWidth } from '../commands/rich-panel.js';
|
|
14
|
+
import { readVersion } from '../version.js';
|
|
15
|
+
import { collectIo, toRejectedResult, toToolResult } from './result.js';
|
|
16
|
+
export const MCP_SERVER_NAME = 'pecot-workflow';
|
|
17
|
+
function rejected(message) {
|
|
18
|
+
return { kind: 'rejected', message: `invalid input: ${message}` };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
SDK に渡す入力のスキーマ。tools/list の形は定義書と同じ z.toJSONSchema の形に additionalProperties: false を足し、検証は素通しにする。
|
|
22
|
+
SDK に zod を渡すと、検証の後に未知のキーを捨てた値が届き、未知のキーを誤りにできない
|
|
23
|
+
*/
|
|
24
|
+
function passthroughSchema(definition) {
|
|
25
|
+
const jsonSchema = () => ({ ...z.toJSONSchema(definition.input, { io: 'input' }), additionalProperties: false });
|
|
26
|
+
return {
|
|
27
|
+
'~standard': {
|
|
28
|
+
version: 1,
|
|
29
|
+
vendor: MCP_SERVER_NAME,
|
|
30
|
+
jsonSchema: { input: jsonSchema, output: jsonSchema },
|
|
31
|
+
validate: value => ({ value }),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function issuesMessage(error) {
|
|
36
|
+
return error.issues.map(issue => issue.path.length === 0 ? issue.message : `${issue.path.join('.')}: ${issue.message}`).join('; ');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
入力を検証する。順は CLI と同じ(未知のキー → repo の形 → definition.parse)。誤りならコマンドを呼ばない
|
|
40
|
+
*/
|
|
41
|
+
function prepare(definition, raw) {
|
|
42
|
+
// arguments が配列や null なら SDK が先に -32602 で断るので、ここに来る非 object は省略(undefined)だけ
|
|
43
|
+
const input = isRecord(raw) ? raw : {};
|
|
44
|
+
const unknown = Object.keys(input).filter(key => !Object.hasOwn(definition.input.shape, key));
|
|
45
|
+
if (unknown.length > 0)
|
|
46
|
+
return rejected(`unknown ${unknown.length === 1 ? 'key' : 'keys'} ${unknown.map(key => `'${key}'`).join(', ')}`);
|
|
47
|
+
const repository = input['repo'];
|
|
48
|
+
if (typeof repository === 'string' && !definition.hasOwnRepo) {
|
|
49
|
+
try {
|
|
50
|
+
parseOwnerRepository(repository);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (!(error instanceof InvalidValueError))
|
|
54
|
+
throw error;
|
|
55
|
+
return rejected(`repo: ${error.message}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return { kind: 'prepared', command: definition.parse(input) };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (!(error instanceof z.ZodError))
|
|
63
|
+
throw error;
|
|
64
|
+
return rejected(issuesMessage(error));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// 対象のリポを決められなかったとき、コマンドを呼ばずに理由を失敗で返す
|
|
68
|
+
function unavailableResult(reason) {
|
|
69
|
+
const collected = collectIo();
|
|
70
|
+
createOutput(false, collected.io).error(reason);
|
|
71
|
+
return toToolResult({ exitCode: 1, stdout: collected.stdout(), stderr: collected.stderr() });
|
|
72
|
+
}
|
|
73
|
+
async function invoke(definition, raw, options) {
|
|
74
|
+
if (options.unavailableReason !== undefined)
|
|
75
|
+
return unavailableResult(options.unavailableReason);
|
|
76
|
+
const collected = collectIo();
|
|
77
|
+
// interface-env: TERMINAL_WIDTH COLUMNS
|
|
78
|
+
const width = outputWidth(process.env, undefined);
|
|
79
|
+
let exitCode;
|
|
80
|
+
try {
|
|
81
|
+
resolveApiUrlOverride();
|
|
82
|
+
const preparation = prepare(definition, raw);
|
|
83
|
+
if (preparation.kind === 'rejected')
|
|
84
|
+
return toRejectedResult(preparation.message);
|
|
85
|
+
try {
|
|
86
|
+
exitCode = await preparation.command.run(collected.io);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw withUsage(error, usageOf(definition));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
try {
|
|
94
|
+
exitCode = exitCodeOfFailure(error, collected.io, width);
|
|
95
|
+
}
|
|
96
|
+
catch (error_) {
|
|
97
|
+
options.reportUnexpected?.(error_, { stdout: collected.stdout(), stderr: collected.stderr() });
|
|
98
|
+
throw error_;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return toToolResult({ exitCode, stdout: collected.stdout(), stderr: collected.stderr() });
|
|
102
|
+
}
|
|
103
|
+
// コマンドは process.cwd()(起動のときに serve.ts が決めたセッションのディレクトリ)と .pecot/ の状態ファイルを読み書きするので、呼び出しは 1 件ずつ実行する。接続が複数あっても共有する
|
|
104
|
+
const sequence = { tail: Promise.resolve(true) };
|
|
105
|
+
async function inSequence(signal, task) {
|
|
106
|
+
const previous = sequence.tail;
|
|
107
|
+
const turn = Promise.withResolvers();
|
|
108
|
+
sequence.tail = turn.promise;
|
|
109
|
+
await previous;
|
|
110
|
+
try {
|
|
111
|
+
// 待っている間に中断(notifications/cancelled)か接続の切断があれば、本体を呼ばない。応答は届かないので中身は何でもよい
|
|
112
|
+
return signal.aborted ? toRejectedResult('cancelled') : await task();
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
turn.resolve(true);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
MCP サーバを作り、commands のそれぞれをツールとして登録する。名前は toolName、説明は description、並びは commands の順
|
|
120
|
+
*/
|
|
121
|
+
export function createMcpServer(commands = COMMANDS, options = {}) {
|
|
122
|
+
const server = new McpServer({ name: MCP_SERVER_NAME, version: readVersion() });
|
|
123
|
+
for (const definition of commands) {
|
|
124
|
+
server.registerTool(definition.toolName, { description: definition.description, inputSchema: passthroughSchema(definition) }, async (arguments_, serverContext) => await inSequence(serverContext.mcpReq.signal, async () => await invoke(definition, arguments_, options)));
|
|
125
|
+
}
|
|
126
|
+
return server;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
判定の結果。move は directory へ移る。variable と value は元の環境変数で、移れなかったときの理由に使う。
|
|
3
|
+
stay は cwd のまま。undetermined は決められない(reason は stderr にそのまま出せる 1 行)
|
|
4
|
+
*/
|
|
5
|
+
export type SessionDirectory = {
|
|
6
|
+
readonly kind: 'move';
|
|
7
|
+
readonly directory: string;
|
|
8
|
+
readonly variable: string;
|
|
9
|
+
readonly value: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'stay';
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'undetermined';
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const UNDETERMINED_PREFIX = "cannot determine the target repository";
|
|
17
|
+
/**
|
|
18
|
+
環境変数の指すディレクトリが使えないときの理由の文。directory は相対パスを cwd で絶対にした値、cause は移るのに失敗した元の文
|
|
19
|
+
*/
|
|
20
|
+
export declare function unusableReason(name: string, value: string, directory: string, cause?: string): string;
|
|
21
|
+
/**
|
|
22
|
+
サーバが対象のリポを見るディレクトリを決める。条件の表は specs/020-workflow-ts-mcp/contracts/mcp-tools.md の「対象のリポ」。
|
|
23
|
+
相対パスの変数は、移る前の cwd を起点にして絶対パスへ直す
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveSessionDirectory(environment: Readonly<Record<string, string | undefined>>, cwd: string): SessionDirectory;
|
|
26
|
+
//# sourceMappingURL=session-directory.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// `pecot mcp` が起動のときに移る、セッションのディレクトリの判定。
|
|
2
|
+
// GitHub Copilot CLI は、プラグインのサーバをプラグインの root を cwd にして起動する。
|
|
3
|
+
import { statSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { normalizePath, resolveRealPath } from '../infra/paths.js';
|
|
6
|
+
export const UNDETERMINED_PREFIX = 'cannot determine the target repository';
|
|
7
|
+
// 空文字は無いものとして扱う
|
|
8
|
+
function valueOf(environment, name) {
|
|
9
|
+
const value = Object.hasOwn(environment, name) ? Reflect.get(environment, name) : undefined;
|
|
10
|
+
return typeof value !== 'string' || value === '' ? undefined : value;
|
|
11
|
+
}
|
|
12
|
+
function isDirectory(target) {
|
|
13
|
+
try {
|
|
14
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- ホストが渡したセッションのディレクトリの有無を見る
|
|
15
|
+
return statSync(target).isDirectory();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function messageOf(error) {
|
|
22
|
+
return error instanceof Error ? error.message : String(error);
|
|
23
|
+
}
|
|
24
|
+
// directory の実体パスが root と同じ、または root の配下。無いパスは字句どおりに解くので投げない。
|
|
25
|
+
// 投げるのは権限などの失敗で、解決できなかったパスを理由に入れる
|
|
26
|
+
function containment(directory, root) {
|
|
27
|
+
let failed = directory;
|
|
28
|
+
try {
|
|
29
|
+
const real = resolveRealPath(directory);
|
|
30
|
+
failed = root;
|
|
31
|
+
const rootReal = resolveRealPath(root);
|
|
32
|
+
const isInside = real === rootReal || real.startsWith(rootReal.endsWith('/') ? rootReal : `${rootReal}/`);
|
|
33
|
+
return { kind: isInside ? 'inside' : 'outside' };
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return { kind: 'unresolved', reason: `${UNDETERMINED_PREFIX}: cannot resolve the real path of ${failed}: ${messageOf(error)}` };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
環境変数の指すディレクトリが使えないときの理由の文。directory は相対パスを cwd で絶対にした値、cause は移るのに失敗した元の文
|
|
41
|
+
*/
|
|
42
|
+
export function unusableReason(name, value, directory, cause) {
|
|
43
|
+
const resolved = path.isAbsolute(value) ? '' : ` (resolved to ${directory})`;
|
|
44
|
+
return `${UNDETERMINED_PREFIX}: ${name} is not a usable directory: ${value}${resolved}${cause === undefined ? '' : `: ${cause}`}`;
|
|
45
|
+
}
|
|
46
|
+
function moveOrUnusable(name, value, cwd) {
|
|
47
|
+
const directory = path.resolve(cwd, value);
|
|
48
|
+
return isDirectory(directory)
|
|
49
|
+
? { kind: 'move', directory: normalizePath(directory), variable: name, value }
|
|
50
|
+
: { kind: 'undetermined', reason: unusableReason(name, value, directory) };
|
|
51
|
+
}
|
|
52
|
+
// Agent Plugins 1.0 が約束する PLUGIN_ROOT と、Claude Code・Copilot CLI が渡す CLAUDE_PLUGIN_ROOT
|
|
53
|
+
const PLUGIN_ROOT_VARIABLES = ['CLAUDE_PLUGIN_ROOT', 'PLUGIN_ROOT'];
|
|
54
|
+
/**
|
|
55
|
+
サーバが対象のリポを見るディレクトリを決める。条件の表は specs/020-workflow-ts-mcp/contracts/mcp-tools.md の「対象のリポ」。
|
|
56
|
+
相対パスの変数は、移る前の cwd を起点にして絶対パスへ直す
|
|
57
|
+
*/
|
|
58
|
+
export function resolveSessionDirectory(environment, cwd) {
|
|
59
|
+
// cwd がプラグインの root の中でなければ、ホストがセッションのディレクトリを cwd にして起動している
|
|
60
|
+
let isInsidePlugin = false;
|
|
61
|
+
for (const name of PLUGIN_ROOT_VARIABLES) {
|
|
62
|
+
const value = valueOf(environment, name);
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
continue;
|
|
65
|
+
const result = containment(cwd, path.resolve(cwd, value));
|
|
66
|
+
if (result.kind === 'unresolved')
|
|
67
|
+
return { kind: 'undetermined', reason: result.reason };
|
|
68
|
+
isInsidePlugin ||= result.kind === 'inside';
|
|
69
|
+
}
|
|
70
|
+
if (!isInsidePlugin)
|
|
71
|
+
return { kind: 'stay' };
|
|
72
|
+
const session = valueOf(environment, 'COPILOT_SESSION_CWD');
|
|
73
|
+
if (session !== undefined)
|
|
74
|
+
return moveOrUnusable('COPILOT_SESSION_CWD', session, cwd);
|
|
75
|
+
// COPILOT_PLUGIN_ROOT があれば Copilot CLI の起動で、CLAUDE_PROJECT_DIR は起動したシェルから継いだ値
|
|
76
|
+
const project = valueOf(environment, 'CLAUDE_PROJECT_DIR');
|
|
77
|
+
if (project !== undefined && valueOf(environment, 'COPILOT_PLUGIN_ROOT') === undefined)
|
|
78
|
+
return moveOrUnusable('CLAUDE_PROJECT_DIR', project, cwd);
|
|
79
|
+
return {
|
|
80
|
+
kind: 'undetermined',
|
|
81
|
+
reason: `${UNDETERMINED_PREFIX}: the server was started in the plugin directory (${cwd}) and the host passed no session directory (COPILOT_SESSION_CWD); upgrade GitHub Copilot CLI to 1.0.106 or later, or start the server in the target repository`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=session-directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
plugin ルート(`plugins/pecot-workflow/`)を返す。
|
|
3
|
+
|
|
4
|
+
`CLAUDE_PLUGIN_ROOT` が最優先。Claude Code・Copilot CLI が、hook・MCP の起動時に渡す。
|
|
5
|
+
|
|
6
|
+
env が無いとき(`node dist/cli.js` の直叩き・単体配布・テスト)は source 相対。本ファイルは
|
|
7
|
+
src 直下 / dist 直下(tsconfig.build.json の rootDir: src で平坦化)/ 配布ツリーのいずれでも
|
|
8
|
+
plugin ルートから 2 階層下に置かれる。
|
|
9
|
+
src 直下から動かすとこの相対解決が成り立たなくなるため、階層は version.test.ts で固定する。
|
|
10
|
+
*/
|
|
11
|
+
export declare function pluginRoot(): string;
|
|
12
|
+
/**
|
|
13
|
+
plugin.json の version を返す。読めなければ開発用の既定値。
|
|
14
|
+
*/
|
|
15
|
+
export declare function readVersion(): string;
|
|
16
|
+
export declare function loadVersionFromPluginJson(manifestPath: string): string | undefined;
|
|
17
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// プラグイン版数の解決。cli.ts と今後の mcp の双方から参照するため、cli.ts から独立させている
|
|
2
|
+
// (mcp → cli.ts の import は循環になる)。
|
|
3
|
+
// 層構成は domain ← infra ← commands / mcp。本ファイルはどの層にも属さない共通モジュールとして src 直下に置く。
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
const DEFAULT_VERSION = '0.0.0+dev';
|
|
8
|
+
/**
|
|
9
|
+
plugin ルート(`plugins/pecot-workflow/`)を返す。
|
|
10
|
+
|
|
11
|
+
`CLAUDE_PLUGIN_ROOT` が最優先。Claude Code・Copilot CLI が、hook・MCP の起動時に渡す。
|
|
12
|
+
|
|
13
|
+
env が無いとき(`node dist/cli.js` の直叩き・単体配布・テスト)は source 相対。本ファイルは
|
|
14
|
+
src 直下 / dist 直下(tsconfig.build.json の rootDir: src で平坦化)/ 配布ツリーのいずれでも
|
|
15
|
+
plugin ルートから 2 階層下に置かれる。
|
|
16
|
+
src 直下から動かすとこの相対解決が成り立たなくなるため、階層は version.test.ts で固定する。
|
|
17
|
+
*/
|
|
18
|
+
export function pluginRoot() {
|
|
19
|
+
const fromEnvironment = process.env['CLAUDE_PLUGIN_ROOT']?.trim();
|
|
20
|
+
return fromEnvironment === undefined || fromEnvironment === '' ? path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..') : fromEnvironment;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
plugin.json の version を返す。読めなければ開発用の既定値。
|
|
24
|
+
*/
|
|
25
|
+
export function readVersion() {
|
|
26
|
+
/* v8 ignore next -- 同梱 plugin.json は常在。読めない場合は loadVersionFromPluginJson の単体テストで担保 */
|
|
27
|
+
return loadVersionFromPluginJson(path.join(pluginRoot(), '.claude-plugin/plugin.json')) ?? DEFAULT_VERSION;
|
|
28
|
+
}
|
|
29
|
+
export function loadVersionFromPluginJson(manifestPath) {
|
|
30
|
+
let parsed;
|
|
31
|
+
try {
|
|
32
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- 環境変数か import.meta.url 由来のパス
|
|
33
|
+
parsed = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line no-restricted-syntax -- 直後の typeof で narrowing する
|
|
39
|
+
const version = parsed?.version;
|
|
40
|
+
return typeof version === 'string' && version !== '' ? version : undefined;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
issue_ref: ""
|
|
3
|
+
template: merge-diff
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<!--
|
|
7
|
+
読者: この Issue が属する Epic を追う人(後のタスクを計画する人・Epic の完了を判定する人)。末尾の「例:」の形で書く。
|
|
8
|
+
|
|
9
|
+
書き方:
|
|
10
|
+
- 見出しの `—` の後は、何がどうなったか(どうなるか)を、主語と述語のある 1 文で書く
|
|
11
|
+
- 計画との差が無ければ Variance を `- 計画通り完了` に、後への影響が無ければ Impact を `- 後続タスクへの影響なし` にする
|
|
12
|
+
|
|
13
|
+
例:
|
|
14
|
+
|
|
15
|
+
## Merge — CSV の書き出しが入り、計画と違う点が 1 つある
|
|
16
|
+
|
|
17
|
+
### Variance — 列の順の決め方が計画と違う
|
|
18
|
+
|
|
19
|
+
- 列の順 — 計画では設定ファイルで決める予定だった。実績は `mytool list` の表示と同じ順にした(利用者が 2 つの順を覚えずに済むため)
|
|
20
|
+
|
|
21
|
+
### Impact — 並べ替えのタスクは CSV の列の順を前提にできる
|
|
22
|
+
|
|
23
|
+
- 並べ替えのタスク — CSV の列の順が `mytool list` と同じなので、並べ替えの結果を CSV でそのまま確かめられる
|
|
24
|
+
-->
|
|
25
|
+
|
|
26
|
+
## Merge — <完了サマリを1行で>
|
|
27
|
+
|
|
28
|
+
### Variance — <計画との差分を1行で>
|
|
29
|
+
|
|
30
|
+
- <変わった点> — <計画では A、実績は B(理由)>
|
|
31
|
+
|
|
32
|
+
### Impact — <後続への影響を1行で>
|
|
33
|
+
|
|
34
|
+
- <影響を受ける後のタスク> — <何を合わせるか>
|