@pecot/workflow-mcp 5.0.0 → 7.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 +1 -1
- package/README.md +27 -22
- package/cli/dist/cli.js +6 -1
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +69 -0
- package/cli/dist/commands/board-judgment.d.ts +69 -0
- package/cli/dist/commands/board-judgment.js +150 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +65 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +75 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +120 -0
- package/cli/dist/commands/board-view.d.ts +151 -0
- package/cli/dist/commands/board-view.js +293 -0
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +111 -0
- package/cli/dist/commands/command-binding.js +4 -0
- package/cli/dist/commands/command-definition.d.ts +39 -8
- package/cli/dist/commands/command-definition.js +20 -7
- package/cli/dist/commands/command-help.js +2 -2
- package/cli/dist/commands/command-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +5 -3
- package/cli/dist/commands/command-stop.js +7 -6
- package/cli/dist/commands/failure-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +35 -0
- package/cli/dist/commands/failure.d.ts +6 -0
- package/cli/dist/commands/failure.js +29 -3
- package/cli/dist/commands/github-client.d.ts +6 -2
- package/cli/dist/commands/github-client.js +13 -3
- package/cli/dist/commands/help.js +8 -13
- package/cli/dist/commands/issue-board.d.ts +61 -0
- package/cli/dist/commands/issue-board.js +85 -1
- package/cli/dist/commands/issue-comment.js +66 -30
- package/cli/dist/commands/issue-create.js +632 -92
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +310 -0
- package/cli/dist/commands/issue-readiness.d.ts +122 -0
- package/cli/dist/commands/issue-readiness.js +253 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +130 -0
- package/cli/dist/commands/issue-shared.d.ts +33 -20
- package/cli/dist/commands/issue-shared.js +84 -76
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +239 -0
- package/cli/dist/commands/issue.d.ts +0 -1
- package/cli/dist/commands/issue.js +6 -8
- package/cli/dist/commands/names.d.ts +33 -0
- package/cli/dist/commands/names.js +63 -0
- package/cli/dist/commands/output.d.ts +32 -4
- package/cli/dist/commands/output.js +28 -8
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +230 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +233 -0
- package/cli/dist/commands/pr-waiting.d.ts +59 -0
- package/cli/dist/commands/pr-waiting.js +143 -0
- package/cli/dist/commands/pr.d.ts +23 -0
- package/cli/dist/commands/pr.js +378 -366
- package/cli/dist/commands/project-sync.d.ts +12 -3
- package/cli/dist/commands/project-sync.js +23 -13
- package/cli/dist/commands/project.d.ts +3 -2
- package/cli/dist/commands/project.js +371 -177
- package/cli/dist/commands/registry.js +15 -10
- package/cli/dist/commands/release.d.ts +2 -2
- package/cli/dist/commands/release.js +118 -130
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -0
- package/cli/dist/commands/repository-match.js +9 -3
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +383 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +252 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +186 -32
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
- package/cli/dist/commands/tracker-sync.d.ts +37 -0
- package/cli/dist/commands/tracker-sync.js +18 -6
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +20 -0
- package/cli/dist/commands/usage-error.d.ts +4 -0
- package/cli/dist/commands/usage-error.js +6 -0
- package/cli/dist/commands/work-target.d.ts +20 -3
- package/cli/dist/commands/work-target.js +49 -6
- package/cli/dist/commands/worktree.js +103 -33
- package/cli/dist/domain/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -0
- package/cli/dist/domain/branch-name.js +1 -1
- package/cli/dist/domain/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +4 -0
- package/cli/dist/domain/config.js +11 -1
- package/cli/dist/domain/dependabot.js +1 -1
- package/cli/dist/domain/errors.d.ts +5 -0
- package/cli/dist/domain/errors.js +5 -0
- package/cli/dist/domain/format.d.ts +51 -4
- package/cli/dist/domain/format.js +72 -6
- package/cli/dist/domain/frontmatter.d.ts +18 -3
- package/cli/dist/domain/frontmatter.js +38 -12
- package/cli/dist/domain/issue-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +36 -4
- package/cli/dist/domain/pull-request.d.ts +71 -4
- package/cli/dist/domain/pull-request.js +59 -10
- package/cli/dist/domain/readiness.d.ts +44 -0
- package/cli/dist/domain/readiness.js +153 -5
- package/cli/dist/domain/reference-parser.d.ts +3 -1
- package/cli/dist/domain/reference-parser.js +6 -2
- package/cli/dist/domain/release.d.ts +7 -3
- package/cli/dist/domain/release.js +5 -12
- package/cli/dist/domain/repository-policy.d.ts +9 -3
- package/cli/dist/domain/repository-policy.js +8 -7
- package/cli/dist/domain/repository-resolver.js +4 -1
- package/cli/dist/domain/restack.d.ts +62 -0
- package/cli/dist/domain/restack.js +53 -0
- package/cli/dist/domain/security-alerts.js +1 -1
- package/cli/dist/domain/state.d.ts +69 -0
- package/cli/dist/domain/state.js +67 -1
- package/cli/dist/domain/work-start.d.ts +30 -0
- package/cli/dist/domain/work-start.js +42 -0
- package/cli/dist/infra/authored-notes.d.ts +1 -1
- package/cli/dist/infra/authored-notes.js +10 -4
- package/cli/dist/infra/config-store.d.ts +4 -0
- package/cli/dist/infra/config-store.js +13 -0
- package/cli/dist/infra/git.d.ts +76 -0
- package/cli/dist/infra/git.js +123 -1
- package/cli/dist/infra/github/client.d.ts +5 -0
- package/cli/dist/infra/github/client.js +10 -7
- package/cli/dist/infra/github/errors.d.ts +18 -0
- package/cli/dist/infra/github/errors.js +22 -0
- package/cli/dist/infra/github/issues.d.ts +39 -3
- package/cli/dist/infra/github/issues.js +178 -23
- package/cli/dist/infra/github/projects.d.ts +35 -0
- package/cli/dist/infra/github/projects.js +89 -8
- package/cli/dist/infra/github/pulls.d.ts +105 -2
- package/cli/dist/infra/github/pulls.js +172 -5
- package/cli/dist/infra/github/queries.d.ts +15 -4
- package/cli/dist/infra/github/queries.js +203 -40
- package/cli/dist/infra/github/readout.d.ts +5 -1
- package/cli/dist/infra/github/readout.js +11 -33
- package/cli/dist/infra/github/repos.d.ts +18 -0
- package/cli/dist/infra/github/repos.js +31 -0
- package/cli/dist/infra/nx-scope.d.ts +1 -1
- package/cli/dist/infra/nx-scope.js +1 -1
- package/cli/dist/infra/state-store.d.ts +10 -1
- package/cli/dist/infra/state-store.js +14 -2
- package/cli/dist/infra/worktree-links.d.ts +3 -0
- package/cli/dist/infra/worktree-links.js +8 -1
- package/cli/dist/infra/worktree.d.ts +12 -1
- package/cli/dist/infra/worktree.js +40 -23
- package/cli/dist/mcp/result.d.ts +82 -7
- package/cli/dist/mcp/result.js +139 -19
- package/cli/dist/mcp/server.d.ts +2 -2
- package/cli/dist/mcp/server.js +57 -10
- package/cli/templates/comment/plan.md +14 -0
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task-implement.md +13 -6
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +84 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/cli/dist/commands/dependabot.d.ts +0 -3
- package/cli/dist/commands/issue-project.d.ts +0 -3
- package/cli/dist/commands/issue-project.js +0 -176
- package/cli/dist/commands/issue-quick.d.ts +0 -3
- package/cli/dist/commands/issue-quick.js +0 -126
- package/cli/dist/commands/issue-read.d.ts +0 -3
- package/cli/dist/commands/issue-read.js +0 -80
- package/cli/dist/commands/project-info.d.ts +0 -48
- package/cli/dist/commands/project-info.js +0 -181
- package/cli/dist/commands/repository.d.ts +0 -5
- package/cli/dist/commands/repository.js +0 -265
- package/cli/dist/commands/security.d.ts +0 -3
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { BaseError } from '../domain/errors.js';
|
|
12
12
|
import { existsSync, readdirSync, readFileSync, rmdirSync, writeFileSync } from 'node:fs';
|
|
13
13
|
import path from 'node:path';
|
|
14
|
+
import { commandHint, formatHinted, hinted, inputHint, inputNameHint, placeholder } from '../domain/command-hint.js';
|
|
14
15
|
import { findRepository, getDevelopBranch } from '../domain/config.js';
|
|
15
16
|
import { pythonStrip, ValidationFailure } from '../domain/python-format.js';
|
|
16
17
|
import { createRepositoryReference } from '../domain/repository-resolver.js';
|
|
@@ -22,10 +23,19 @@ import { normalizePath, resolveRealPath, WORKTREE_CONFIG_FILENAME } from './path
|
|
|
22
23
|
import { createSymlinks, loadConfig, loadCopyExcludeSpec, WorktreeConfigError, } from './worktree-links.js';
|
|
23
24
|
import { copyFiles } from './worktree-copy.js';
|
|
24
25
|
import { runSetupCommand } from './worktree-setup.js';
|
|
26
|
+
const WORKTREE_ADD_PATH = ['worktree', 'add'];
|
|
25
27
|
/**
|
|
26
28
|
ワークツリー操作に失敗した(Python の RuntimeError に当たる)。メッセージは利用者に見せる文
|
|
27
29
|
*/
|
|
28
30
|
export class WorktreeRuntimeError extends BaseError {
|
|
31
|
+
hintedText;
|
|
32
|
+
failure;
|
|
33
|
+
// message は CLI の形。MCP では最上位が hintedText から描き直す
|
|
34
|
+
constructor(message, options = {}) {
|
|
35
|
+
super(formatHinted(message, 'cli'), options.cause === undefined ? undefined : { cause: options.cause });
|
|
36
|
+
this.hintedText = typeof message === 'string' ? undefined : message;
|
|
37
|
+
this.failure = options.failure ?? 'other';
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
// 環境ガード
|
|
31
41
|
function isSet(value = '') {
|
|
@@ -312,14 +322,15 @@ function readRemoteCandidates(cwd) {
|
|
|
312
322
|
function loadCopyExcludeSpecOrRaise(mainWorktree, diagnostics) {
|
|
313
323
|
const configPath = path.join(mainWorktree, WORKTREE_CONFIG_FILENAME);
|
|
314
324
|
if (!existsSync(configPath)) {
|
|
315
|
-
throw new WorktreeRuntimeError(`worktree config not found: ${WORKTREE_CONFIG_FILENAME}\n run
|
|
325
|
+
throw new WorktreeRuntimeError(hinted `worktree config not found: ${WORKTREE_CONFIG_FILENAME}\n run ${commandHint(['worktree', 'init'])} to generate the template`, { failure: 'not-initialized' });
|
|
316
326
|
}
|
|
317
327
|
try {
|
|
318
328
|
return { configPath, spec: loadCopyExcludeSpec(mainWorktree, diagnostics) };
|
|
319
329
|
}
|
|
320
330
|
catch (error) {
|
|
331
|
+
// loadCopyExcludeSpec の WorktreeConfigError は、.worktreeignore が無いときだけ
|
|
321
332
|
if (error instanceof WorktreeConfigError)
|
|
322
|
-
throw new WorktreeRuntimeError(error.message, { cause: error });
|
|
333
|
+
throw new WorktreeRuntimeError(error.hintedText ?? error.message, { cause: error, failure: 'not-initialized' });
|
|
323
334
|
throw error;
|
|
324
335
|
}
|
|
325
336
|
}
|
|
@@ -330,7 +341,7 @@ function requireRegisteredRepository(cwd) {
|
|
|
330
341
|
throw new WorktreeRuntimeError(NO_REMOTE_MESSAGE);
|
|
331
342
|
const config = loadActiveConfig();
|
|
332
343
|
if (config === undefined) {
|
|
333
|
-
throw new WorktreeRuntimeError(
|
|
344
|
+
throw new WorktreeRuntimeError(hinted `project config not found\n hint: run ${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })} to set the project`, { failure: 'no-active-project' });
|
|
334
345
|
}
|
|
335
346
|
for (const candidate of candidates) {
|
|
336
347
|
if (candidate.repository !== undefined && findRepository(config, candidate.repository.owner, candidate.repository.repository) !== undefined) {
|
|
@@ -343,25 +354,24 @@ function requireRegisteredRepository(cwd) {
|
|
|
343
354
|
const registered = config.repositories.length > 0
|
|
344
355
|
? config.repositories.map(item => ` - ${item.owner}/${item.name}`).join('\n')
|
|
345
356
|
: ' (none registered)';
|
|
346
|
-
throw new WorktreeRuntimeError(`repository ${repository.owner}/${repository.repository} is not registered in the
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
+ ' pecot project activate <PROJECT>');
|
|
357
|
+
throw new WorktreeRuntimeError(hinted `repository ${repository.owner}/${repository.repository} is not registered in the active pecot project
|
|
358
|
+
|
|
359
|
+
registered repositories:
|
|
360
|
+
${registered}
|
|
361
|
+
|
|
362
|
+
to add this repository to the pecot project:
|
|
363
|
+
${commandHint(['project', 'link'], { repo: `${repository.owner}/${repository.repository}` })}
|
|
364
|
+
|
|
365
|
+
to switch to another project:
|
|
366
|
+
${commandHint(['project', 'activate'], { project: placeholder('PROJECT') })}`, { failure: 'repo-not-in-project' });
|
|
357
367
|
}
|
|
358
368
|
// ベースブランチ決定(プロジェクト設定の develop_branch を使用)
|
|
359
369
|
function defaultBaseBranch(config, repository) {
|
|
360
370
|
const developBranch = getDevelopBranch(config, repository.owner, repository.repository);
|
|
361
371
|
if (developBranch === undefined || developBranch === '') {
|
|
362
|
-
throw new WorktreeRuntimeError(`develop_branch is not set for repository ${repository.owner}/${repository.repository}
|
|
363
|
-
|
|
364
|
-
|
|
372
|
+
throw new WorktreeRuntimeError(hinted `develop_branch is not set for repository ${repository.owner}/${repository.repository}
|
|
373
|
+
add develop_branch to repositories in the project config file
|
|
374
|
+
or pass ${inputNameHint(WORKTREE_ADD_PATH, 'base')} explicitly`, { failure: 'repo-setting-missing' });
|
|
365
375
|
}
|
|
366
376
|
return developBranch;
|
|
367
377
|
}
|
|
@@ -372,7 +382,7 @@ function loadWorktreeConfigOrRaise(configPath) {
|
|
|
372
382
|
}
|
|
373
383
|
catch (error) {
|
|
374
384
|
if (error instanceof WorktreeConfigError) {
|
|
375
|
-
throw new WorktreeRuntimeError(`failed to load the worktree config: ${normalizePath(configPath)}: ${error.message}\n fix the config file and run it again`, { cause: error });
|
|
385
|
+
throw new WorktreeRuntimeError(`failed to load the worktree config: ${normalizePath(configPath)}: ${error.message}\n fix the config file and run it again`, { cause: error, failure: 'config-invalid' });
|
|
376
386
|
}
|
|
377
387
|
throw error;
|
|
378
388
|
}
|
|
@@ -466,9 +476,8 @@ function addGitWorktree(cwd, worktreePath, name, base, isExistingBranchAllowed)
|
|
|
466
476
|
const currentUpstream = pythonStrip(runGit(['for-each-ref', '--format=%(upstream:short)', `refs/heads/${name}`], { cwd }).stdout);
|
|
467
477
|
const expectedUpstream = baseBranch === '' ? undefined : `${remote}/${baseBranch}`;
|
|
468
478
|
if ((currentUpstream === '' ? undefined : currentUpstream) !== expectedUpstream) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
+ 'pass --allow-existing-branch to reuse it');
|
|
479
|
+
const current = currentUpstream === '' ? '(unset)' : currentUpstream;
|
|
480
|
+
throw new WorktreeRuntimeError(hinted `branch '${name}' already exists and its upstream differs from the expected one (current: ${current}, expected: ${expectedUpstream ?? 'None'}): pass ${inputHint(WORKTREE_ADD_PATH, 'allow_existing_branch')} to reuse it`);
|
|
472
481
|
}
|
|
473
482
|
// upstream 一致かつ bind なし → prune に取り残された孤児ブランチとみなし除去
|
|
474
483
|
const worktreeOfBranch = runGit(['for-each-ref', '--format=%(worktreepath)', `refs/heads/${name}`], { cwd });
|
|
@@ -518,20 +527,28 @@ function findWorktreePathByName(cwd, name) {
|
|
|
518
527
|
/**
|
|
519
528
|
ワークツリーを削除する。name は worktree add が付けた名前(wtN)か、checkout しているブランチ名。
|
|
520
529
|
WT が見つからない・削除に失敗した場合は WorktreeRuntimeError。
|
|
521
|
-
ローカルブランチを消せなかったときは、その理由を返す。成功時と shouldKeepBranch は undefined
|
|
530
|
+
ローカルブランチを消せなかったときは、その理由を返す。成功時と shouldKeepBranch は undefined。isDryRun は WT を探すだけで何も消さない
|
|
522
531
|
*/
|
|
523
532
|
export function removeWorktree(cwd, name, diagnostics, options = {}) {
|
|
524
533
|
// 1. WTパスを特定
|
|
525
534
|
const worktreePath = findWorktreePathByName(cwd, name);
|
|
526
535
|
if (worktreePath === undefined)
|
|
527
536
|
throw new WorktreeRuntimeError(`worktree not found: ${name}`);
|
|
537
|
+
if (options.isDryRun === true)
|
|
538
|
+
return undefined;
|
|
528
539
|
// 2. git worktree remove
|
|
529
540
|
const gitArguments = ['worktree', 'remove', worktreePath];
|
|
530
541
|
if (options.isForced === true)
|
|
531
542
|
gitArguments.push('--force');
|
|
532
543
|
const removed = runGit(gitArguments, { cwd });
|
|
533
|
-
if (removed.exitCode !== 0)
|
|
544
|
+
if (removed.exitCode !== 0) {
|
|
545
|
+
const reason = pythonStrip(removed.stderr);
|
|
546
|
+
// git の文は CLI の `--force` を案内するので、MCP でも打てる形の案内を添える
|
|
547
|
+
if (options.isForced !== true && reason.includes('contains modified or untracked files')) {
|
|
548
|
+
throw new WorktreeRuntimeError(hinted `failed to remove the worktree: ${reason}\nhint: to remove it with its changes, pass ${inputHint(['worktree', 'remove'], 'force')}`);
|
|
549
|
+
}
|
|
534
550
|
throw new WorktreeRuntimeError(`failed to remove the worktree: ${removed.stderr}`);
|
|
551
|
+
}
|
|
535
552
|
// 3. ブランチ削除(ローカルブランチ)
|
|
536
553
|
let branchError;
|
|
537
554
|
if (options.shouldKeepBranch !== true) {
|
package/cli/dist/mcp/result.d.ts
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
|
-
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
1
|
+
import type { CallToolResult, StandardSchemaWithJSON } from '@modelcontextprotocol/server';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { FailureKind } from '../commands/failure-kind.js';
|
|
2
4
|
import type { CommandIo } from '../commands/registry.js';
|
|
3
5
|
export interface CommandOutcome {
|
|
6
|
+
/**
|
|
7
|
+
成否を決めるためだけに使う。結果には載せない
|
|
8
|
+
*/
|
|
4
9
|
readonly exitCode: number;
|
|
10
|
+
/**
|
|
11
|
+
成功の文を決めるためだけに使う。結果には載せない
|
|
12
|
+
*/
|
|
5
13
|
readonly stdout: string;
|
|
14
|
+
/**
|
|
15
|
+
失敗の detail を決めるためだけに使う。結果には載せない
|
|
16
|
+
*/
|
|
6
17
|
readonly stderr: string;
|
|
18
|
+
/**
|
|
19
|
+
失敗の原因の名前。終了コードが 0 でないのに無ければ other
|
|
20
|
+
*/
|
|
21
|
+
readonly kind?: FailureKind | undefined;
|
|
22
|
+
/**
|
|
23
|
+
失敗の detail の代わりの文。warning を除いた stderr が空のときに使う
|
|
24
|
+
*/
|
|
25
|
+
readonly message?: string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
成功の文に使う結果の行(片付けの行を除いた最初のもの)。無ければ stdout の最初の空でない行
|
|
28
|
+
*/
|
|
29
|
+
readonly resultLine?: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
コマンドの output で検証した後の項目。失敗では途中まで進んだ結果
|
|
32
|
+
*/
|
|
33
|
+
readonly data?: Readonly<Record<string, unknown>> | undefined;
|
|
34
|
+
readonly warnings?: readonly string[] | undefined;
|
|
7
35
|
}
|
|
8
36
|
export interface CollectedIo {
|
|
9
37
|
/**
|
|
@@ -12,22 +40,69 @@ export interface CollectedIo {
|
|
|
12
40
|
readonly io: CommandIo;
|
|
13
41
|
readonly stdout: () => string;
|
|
14
42
|
readonly stderr: () => string;
|
|
43
|
+
readonly kind: () => FailureKind | undefined;
|
|
44
|
+
readonly resultLine: () => string | undefined;
|
|
45
|
+
readonly data: () => Readonly<Record<string, unknown>>;
|
|
46
|
+
readonly warnings: () => readonly string[];
|
|
15
47
|
}
|
|
16
48
|
/**
|
|
17
|
-
stdout・stderr
|
|
49
|
+
stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行、項目、warning の文を集める io
|
|
18
50
|
*/
|
|
19
51
|
export declare function collectIo(): CollectedIo;
|
|
20
52
|
/**
|
|
21
|
-
|
|
53
|
+
ツールの項目と並べて structuredContent の最上位に置く、全ツールに共通の 4 項目
|
|
54
|
+
*/
|
|
55
|
+
export declare const COMMON_OUTPUT_PROPERTIES: {
|
|
56
|
+
kind: {
|
|
57
|
+
type: string;
|
|
58
|
+
description: string;
|
|
59
|
+
};
|
|
60
|
+
detail: {
|
|
61
|
+
type: string;
|
|
62
|
+
description: string;
|
|
63
|
+
};
|
|
64
|
+
log: {
|
|
65
|
+
type: string;
|
|
66
|
+
description: string;
|
|
67
|
+
};
|
|
68
|
+
warnings: {
|
|
69
|
+
type: string;
|
|
70
|
+
items: {
|
|
71
|
+
type: string;
|
|
72
|
+
};
|
|
73
|
+
description: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
ツールの outputSchema(JSON Schema)。最上位の properties にコマンドの output の項目と共通の 4 項目を並べ、
|
|
78
|
+
anyOf の枝で「成功の必須項目」か「kind と detail」を求める。成功の必須項目が無ければ anyOf を置かない
|
|
79
|
+
*/
|
|
80
|
+
export declare function toolOutputSchema(output: z.ZodObject): Record<string, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
手組みの JSON Schema を、SDK が受ける形にする。検証は SDK の ajv(2020-12)で、値を変えない
|
|
22
83
|
*/
|
|
23
|
-
export declare
|
|
84
|
+
export declare function standardOutputSchema(schema: Readonly<Record<string, unknown>>): StandardSchemaWithJSON;
|
|
24
85
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
86
|
+
stderr を、warning の文(前置きと続きの行の字下げを除く)と、それ以外の行に分ける。続きの行は、warning の行の後の空白 2 つで始まる行
|
|
87
|
+
*/
|
|
88
|
+
export declare function splitWarnings(stderr: string): {
|
|
89
|
+
readonly warnings: readonly string[];
|
|
90
|
+
readonly rest: readonly string[];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
失敗の全文。warning を除いた stderr の、最初の error の行から後(前置きを除く)。error の行が無ければ warning を除いた stderr の全部、それも空なら message
|
|
94
|
+
*/
|
|
95
|
+
export declare function detailOf(stderr: string, message: string): string;
|
|
96
|
+
/**
|
|
97
|
+
content は、文の text(空なら省く)と、structuredContent と 1 字も違わない JSON の text。ホストがどちらを渡しても同じ中身が届く
|
|
27
98
|
*/
|
|
28
99
|
export declare function toToolResult(outcome: Readonly<CommandOutcome>): CallToolResult;
|
|
29
100
|
/**
|
|
30
|
-
|
|
101
|
+
コマンドを呼ぶ前に入力を断った結果。終了コードは使い方の誤りと同じ 2
|
|
31
102
|
*/
|
|
32
103
|
export declare function toRejectedResult(message: string): CallToolResult;
|
|
104
|
+
/**
|
|
105
|
+
中断(notifications/cancelled か接続の切断)で本体を呼ばなかった結果。応答はクライアントに届かない
|
|
106
|
+
*/
|
|
107
|
+
export declare function toAbortedResult(): CallToolResult;
|
|
33
108
|
//# sourceMappingURL=result.d.ts.map
|
package/cli/dist/mcp/result.js
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
// MCP のツールの結果。コマンドの出力と、MCP の io だけが受ける項目・warning を集め、仕様の content・structuredContent・isError の形にする。
|
|
2
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- zod の型は readonly にできない */
|
|
3
|
+
import { fromJsonSchema } from '@modelcontextprotocol/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { WARNING_PREFIX } from '../commands/output.js';
|
|
6
|
+
import { USAGE_EXIT_CODE } from '../commands/usage-error.js';
|
|
1
7
|
/**
|
|
2
|
-
stdout・stderr
|
|
8
|
+
stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行、項目、warning の文を集める io
|
|
3
9
|
*/
|
|
4
10
|
export function collectIo() {
|
|
5
11
|
const out = [];
|
|
6
12
|
const error = [];
|
|
13
|
+
let failureKind;
|
|
14
|
+
let firstResult;
|
|
15
|
+
// createOutput を何度も呼ぶコマンドがあるので、項目はここで重ねる
|
|
16
|
+
let fields = {};
|
|
17
|
+
const warnings = [];
|
|
7
18
|
return {
|
|
8
19
|
io: {
|
|
9
20
|
stdout: (text) => {
|
|
@@ -12,41 +23,150 @@ export function collectIo() {
|
|
|
12
23
|
stderr: (text) => {
|
|
13
24
|
error.push(text);
|
|
14
25
|
},
|
|
26
|
+
surface: 'mcp',
|
|
27
|
+
failureKind: (kind) => {
|
|
28
|
+
failureKind ??= kind;
|
|
29
|
+
},
|
|
30
|
+
resultLine: (line) => {
|
|
31
|
+
firstResult ??= line;
|
|
32
|
+
},
|
|
33
|
+
data: (added) => {
|
|
34
|
+
fields = { ...fields, ...added };
|
|
35
|
+
},
|
|
36
|
+
warning: (text) => {
|
|
37
|
+
warnings.push(text);
|
|
38
|
+
},
|
|
15
39
|
},
|
|
16
40
|
stdout: () => out.join(''),
|
|
17
41
|
stderr: () => error.join(''),
|
|
42
|
+
kind: () => failureKind,
|
|
43
|
+
resultLine: () => firstResult,
|
|
44
|
+
data: () => fields,
|
|
45
|
+
warnings: () => [...warnings],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
ツールの項目と並べて structuredContent の最上位に置く、全ツールに共通の 4 項目
|
|
50
|
+
*/
|
|
51
|
+
export const COMMON_OUTPUT_PROPERTIES = {
|
|
52
|
+
kind: { type: 'string', description: 'Failure kind (failure only)' },
|
|
53
|
+
detail: { type: 'string', description: 'Full failure text: the error message and the guidance lines that follow it (failure only)' },
|
|
54
|
+
log: { type: 'string', description: 'Raw output of a child process (failure only; omitted when not captured)' },
|
|
55
|
+
warnings: { type: 'array', items: { type: 'string' }, description: 'Warning messages, without the "warning: " prefix (omitted when there is none)' },
|
|
56
|
+
};
|
|
57
|
+
const FAILURE_REQUIRED = ['kind', 'detail'];
|
|
58
|
+
const JsonObjectSchema = z.looseObject({
|
|
59
|
+
properties: z.record(z.string(), z.unknown()).optional(),
|
|
60
|
+
required: z.array(z.string()).optional(),
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
ツールの outputSchema(JSON Schema)。最上位の properties にコマンドの output の項目と共通の 4 項目を並べ、
|
|
64
|
+
anyOf の枝で「成功の必須項目」か「kind と detail」を求める。成功の必須項目が無ければ anyOf を置かない
|
|
65
|
+
*/
|
|
66
|
+
export function toolOutputSchema(output) {
|
|
67
|
+
const generated = Object.entries(z.toJSONSchema(output, { io: 'output' })).filter(([key]) => key !== '$schema');
|
|
68
|
+
const { required = [], properties = {}, ...rest } = JsonObjectSchema.parse(Object.fromEntries(generated));
|
|
69
|
+
return {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: { ...properties, ...COMMON_OUTPUT_PROPERTIES },
|
|
72
|
+
// 定義書に書き出す順(type・properties・additionalProperties)に合わせる
|
|
73
|
+
...rest,
|
|
74
|
+
...required.length > 0 && { anyOf: [{ required }, { required: [...FAILURE_REQUIRED] }] },
|
|
18
75
|
};
|
|
19
76
|
}
|
|
20
77
|
/**
|
|
21
|
-
|
|
78
|
+
手組みの JSON Schema を、SDK が受ける形にする。検証は SDK の ajv(2020-12)で、値を変えない
|
|
79
|
+
*/
|
|
80
|
+
export function standardOutputSchema(schema) {
|
|
81
|
+
// eslint-disable-next-line no-restricted-syntax -- JsonSchemaType は全キーワードの型で、組み立てた object を当てられない
|
|
82
|
+
return fromJsonSchema(schema);
|
|
83
|
+
}
|
|
84
|
+
const ERROR_PREFIX = 'error: ';
|
|
85
|
+
const CONTINUATION = ' ';
|
|
86
|
+
function linesOf(text) {
|
|
87
|
+
return text.split('\n').filter(line => line.trim() !== '');
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
stderr を、warning の文(前置きと続きの行の字下げを除く)と、それ以外の行に分ける。続きの行は、warning の行の後の空白 2 つで始まる行
|
|
91
|
+
*/
|
|
92
|
+
export function splitWarnings(stderr) {
|
|
93
|
+
const warnings = [];
|
|
94
|
+
const rest = [];
|
|
95
|
+
let current;
|
|
96
|
+
for (const line of stderr.split('\n')) {
|
|
97
|
+
if (line.startsWith(WARNING_PREFIX)) {
|
|
98
|
+
current = [line.slice(WARNING_PREFIX.length)];
|
|
99
|
+
warnings.push('');
|
|
100
|
+
}
|
|
101
|
+
else if (current !== undefined && line.startsWith(CONTINUATION)) {
|
|
102
|
+
current.push(line.slice(CONTINUATION.length));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
current = undefined;
|
|
106
|
+
rest.push(line);
|
|
107
|
+
}
|
|
108
|
+
if (current !== undefined)
|
|
109
|
+
warnings[warnings.length - 1] = current.join('\n');
|
|
110
|
+
}
|
|
111
|
+
return { warnings, rest };
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
失敗の全文。warning を除いた stderr の、最初の error の行から後(前置きを除く)。error の行が無ければ warning を除いた stderr の全部、それも空なら message
|
|
22
115
|
*/
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
116
|
+
export function detailOf(stderr, message) {
|
|
117
|
+
const { rest } = splitWarnings(stderr);
|
|
118
|
+
const start = rest.findIndex(line => line.startsWith(ERROR_PREFIX));
|
|
119
|
+
const kept = start === -1 ? rest : rest.slice(start).with(0, rest.at(start)?.slice(ERROR_PREFIX.length) ?? '');
|
|
120
|
+
const text = kept.join('\n').replaceAll(/^\n+|\n+$/g, '');
|
|
121
|
+
return text === '' ? message : text;
|
|
26
122
|
}
|
|
27
|
-
//
|
|
28
|
-
function
|
|
29
|
-
if (outcome.
|
|
30
|
-
return outcome.
|
|
31
|
-
const
|
|
32
|
-
|
|
123
|
+
// 失敗の detail の代わりの文。渡された message、無ければ最初の error の行の文、それも無ければ stderr の最初の行
|
|
124
|
+
function failureMessageOf(outcome) {
|
|
125
|
+
if (outcome.message !== undefined)
|
|
126
|
+
return outcome.message;
|
|
127
|
+
const lines = linesOf(outcome.stderr);
|
|
128
|
+
const errorLine = lines.find(line => line.startsWith(ERROR_PREFIX));
|
|
129
|
+
return errorLine === undefined ? (lines.at(0)?.trim() ?? '') : errorLine.slice(ERROR_PREFIX.length);
|
|
130
|
+
}
|
|
131
|
+
function toOutput(outcome) {
|
|
132
|
+
const warnings = outcome.warnings ?? [];
|
|
133
|
+
const warned = warnings.length > 0 ? { warnings } : {};
|
|
134
|
+
if (outcome.exitCode === 0) {
|
|
135
|
+
return {
|
|
136
|
+
isOk: true,
|
|
137
|
+
text: outcome.resultLine ?? linesOf(outcome.stdout).at(0)?.trim() ?? '',
|
|
138
|
+
structured: { ...outcome.data, ...warned },
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const detail = detailOf(outcome.stderr, failureMessageOf(outcome));
|
|
142
|
+
return {
|
|
143
|
+
isOk: false,
|
|
144
|
+
text: detail,
|
|
145
|
+
structured: { kind: outcome.kind ?? 'other', detail, ...outcome.data, ...warned },
|
|
146
|
+
};
|
|
33
147
|
}
|
|
34
148
|
/**
|
|
35
|
-
content
|
|
36
|
-
structuredContent は付けない(Claude Code が content を落とし、Copilot CLI は二重に渡すため)。終了コードと 2 つの出力は _meta に入れる
|
|
149
|
+
content は、文の text(空なら省く)と、structuredContent と 1 字も違わない JSON の text。ホストがどちらを渡しても同じ中身が届く
|
|
37
150
|
*/
|
|
38
151
|
export function toToolResult(outcome) {
|
|
39
|
-
const
|
|
152
|
+
const { isOk, text, structured } = toOutput(outcome);
|
|
153
|
+
const json = { type: 'text', text: JSON.stringify(structured) };
|
|
40
154
|
return {
|
|
41
|
-
content:
|
|
42
|
-
|
|
43
|
-
|
|
155
|
+
content: text === '' ? [json] : [{ type: 'text', text }, json],
|
|
156
|
+
structuredContent: { ...structured },
|
|
157
|
+
...!isOk && { isError: true },
|
|
44
158
|
};
|
|
45
159
|
}
|
|
46
160
|
/**
|
|
47
|
-
|
|
161
|
+
コマンドを呼ぶ前に入力を断った結果。終了コードは使い方の誤りと同じ 2
|
|
48
162
|
*/
|
|
49
163
|
export function toRejectedResult(message) {
|
|
50
|
-
return {
|
|
164
|
+
return toToolResult({ exitCode: USAGE_EXIT_CODE, stdout: '', stderr: '', kind: 'invalid-input', message });
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
中断(notifications/cancelled か接続の切断)で本体を呼ばなかった結果。応答はクライアントに届かない
|
|
168
|
+
*/
|
|
169
|
+
export function toAbortedResult() {
|
|
170
|
+
return toToolResult({ exitCode: 1, stdout: '', stderr: '', kind: 'aborted', message: 'cancelled' });
|
|
51
171
|
}
|
|
52
172
|
//# sourceMappingURL=result.js.map
|
package/cli/dist/mcp/server.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import type { CommandDefinition } from '../commands/registry.js';
|
|
|
3
3
|
export declare const MCP_SERVER_NAME = "pecot-workflow";
|
|
4
4
|
export interface McpServerOptions {
|
|
5
5
|
/**
|
|
6
|
-
|
|
6
|
+
対象のリポを決められなかった理由。あるとき、どのツールの呼び出しもコマンドを呼ばず、この理由を失敗(終了コード 1、kind は session-directory-unresolved)で返す。tools/list は変わらない
|
|
7
7
|
*/
|
|
8
8
|
readonly unavailableReason?: string | undefined;
|
|
9
9
|
/**
|
|
10
|
-
|
|
10
|
+
プログラムの誤り(報告できる失敗でも使い方の誤りでもない例外)と、それまでに集めた出力を、切り分けのために伝える先。結果は kind が other の失敗にする
|
|
11
11
|
*/
|
|
12
12
|
readonly reportUnexpected?: (error: unknown, collected: {
|
|
13
13
|
readonly stdout: string;
|
package/cli/dist/mcp/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// COMMANDS
|
|
1
|
+
// COMMANDS の全コマンドを MCP のツールとして登録するサーバ。CLI と同じ定義の run を呼び、結果の形だけが違う。
|
|
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';
|
|
@@ -10,9 +10,11 @@ import { createOutput } from '../commands/output.js';
|
|
|
10
10
|
import { exitCodeOfFailure } from '../commands/failure.js';
|
|
11
11
|
import { isRecord } from '../commands/input-schema.js';
|
|
12
12
|
import { COMMANDS } from '../commands/registry.js';
|
|
13
|
+
import { findRenamedInput, renamedInputNote } from '../commands/renamed-commands.js';
|
|
13
14
|
import { outputWidth } from '../commands/rich-panel.js';
|
|
15
|
+
import { UsageError } from '../commands/usage-error.js';
|
|
14
16
|
import { readVersion } from '../version.js';
|
|
15
|
-
import { collectIo, toRejectedResult, toToolResult } from './result.js';
|
|
17
|
+
import { collectIo, standardOutputSchema, toAbortedResult, toolOutputSchema, toRejectedResult, toToolResult } from './result.js';
|
|
16
18
|
export const MCP_SERVER_NAME = 'pecot-workflow';
|
|
17
19
|
function rejected(message) {
|
|
18
20
|
return { kind: 'rejected', message: `invalid input: ${message}` };
|
|
@@ -42,8 +44,13 @@ function prepare(definition, raw) {
|
|
|
42
44
|
// arguments が配列や null なら SDK が先に -32602 で断るので、ここに来る非 object は省略(undefined)だけ
|
|
43
45
|
const input = isRecord(raw) ? raw : {};
|
|
44
46
|
const unknown = Object.keys(input).filter(key => !Object.hasOwn(definition.input.shape, key));
|
|
45
|
-
if (unknown.length > 0)
|
|
46
|
-
|
|
47
|
+
if (unknown.length > 0) {
|
|
48
|
+
const notes = unknown.map((key) => {
|
|
49
|
+
const renamed = findRenamedInput(definition.path, key);
|
|
50
|
+
return renamed === undefined ? '' : renamedInputNote(key, renamed);
|
|
51
|
+
});
|
|
52
|
+
return rejected(`unknown ${unknown.length === 1 ? 'key' : 'keys'} ${unknown.map(key => `'${key}'`).join(', ')}${notes.join('')}`);
|
|
53
|
+
}
|
|
47
54
|
const repository = input['repo'];
|
|
48
55
|
if (typeof repository === 'string' && !definition.hasOwnRepo) {
|
|
49
56
|
try {
|
|
@@ -68,7 +75,10 @@ function prepare(definition, raw) {
|
|
|
68
75
|
function unavailableResult(reason) {
|
|
69
76
|
const collected = collectIo();
|
|
70
77
|
createOutput(false, collected.io).error(reason);
|
|
71
|
-
return toToolResult({ exitCode: 1, stdout: collected.stdout(), stderr: collected.stderr() });
|
|
78
|
+
return toToolResult({ exitCode: 1, stdout: collected.stdout(), stderr: collected.stderr(), kind: 'session-directory-unresolved' });
|
|
79
|
+
}
|
|
80
|
+
function unexpectedMessage(error) {
|
|
81
|
+
return error instanceof Error ? error.message : String(error);
|
|
72
82
|
}
|
|
73
83
|
async function invoke(definition, raw, options) {
|
|
74
84
|
if (options.unavailableReason !== undefined)
|
|
@@ -77,6 +87,7 @@ async function invoke(definition, raw, options) {
|
|
|
77
87
|
// interface-env: TERMINAL_WIDTH COLUMNS
|
|
78
88
|
const width = outputWidth(process.env, undefined);
|
|
79
89
|
let exitCode;
|
|
90
|
+
let message;
|
|
80
91
|
try {
|
|
81
92
|
resolveApiUrlOverride();
|
|
82
93
|
const preparation = prepare(definition, raw);
|
|
@@ -90,15 +101,51 @@ async function invoke(definition, raw, options) {
|
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
catch (error) {
|
|
104
|
+
// 使い方の誤りは枠で出すので、error の行の代わりに例外の文の 1 行目を message にする
|
|
105
|
+
if (error instanceof UsageError)
|
|
106
|
+
message = error.message.split('\n', 1)[0];
|
|
93
107
|
try {
|
|
94
108
|
exitCode = exitCodeOfFailure(error, collected.io, width);
|
|
95
109
|
}
|
|
96
110
|
catch (error_) {
|
|
97
111
|
options.reportUnexpected?.(error_, { stdout: collected.stdout(), stderr: collected.stderr() });
|
|
98
|
-
|
|
112
|
+
return finish(definition, collected, { exitCode: 1, message: unexpectedMessage(error_), kind: 'other' }, options);
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
|
-
return
|
|
115
|
+
return finish(definition, collected, { exitCode, message }, options);
|
|
116
|
+
}
|
|
117
|
+
// SDK の検証に任せると、合わない結果は structuredContent の無い文字列だけになるので、ここで検証する
|
|
118
|
+
function finish(definition, collected, ended, options) {
|
|
119
|
+
const stdout = collected.stdout();
|
|
120
|
+
const stderr = collected.stderr();
|
|
121
|
+
const outcome = {
|
|
122
|
+
exitCode: ended.exitCode,
|
|
123
|
+
stdout,
|
|
124
|
+
stderr,
|
|
125
|
+
kind: ended.kind ?? collected.kind(),
|
|
126
|
+
message: ended.message,
|
|
127
|
+
resultLine: collected.resultLine(),
|
|
128
|
+
warnings: collected.warnings(),
|
|
129
|
+
};
|
|
130
|
+
const raw = collected.data();
|
|
131
|
+
if (ended.exitCode === 0) {
|
|
132
|
+
const parsed = definition.output.safeParse(raw);
|
|
133
|
+
if (parsed.success)
|
|
134
|
+
return toToolResult({ ...outcome, data: parsed.data });
|
|
135
|
+
options.reportUnexpected?.(parsed.error, { stdout, stderr });
|
|
136
|
+
// 書き込みが済んだ後の食い違いもありうるので、呼び直さないよう伝える。項目は失敗と同じく省略可の形で検証して残す
|
|
137
|
+
const message = `the command finished, but its data does not match the output schema: ${issuesMessage(parsed.error)}; the operation may already be done, so do not call it again`;
|
|
138
|
+
return toToolResult({ ...outcome, exitCode: 1, stderr: '', kind: 'other', message, data: partialData(definition, raw, stdout, stderr, options) });
|
|
139
|
+
}
|
|
140
|
+
return toToolResult({ ...outcome, data: partialData(definition, raw, stdout, stderr, options) });
|
|
141
|
+
}
|
|
142
|
+
// 失敗の結果は SDK とクライアントが検証しない。省略可の形に合わなければ、kind などを保ち、ツールの項目だけを捨てる
|
|
143
|
+
function partialData(definition, raw, stdout, stderr, options) {
|
|
144
|
+
const parsed = definition.output.partial().safeParse(raw);
|
|
145
|
+
if (parsed.success)
|
|
146
|
+
return parsed.data;
|
|
147
|
+
options.reportUnexpected?.(parsed.error, { stdout, stderr });
|
|
148
|
+
return undefined;
|
|
102
149
|
}
|
|
103
150
|
// コマンドは process.cwd()(起動のときに serve.ts が決めたセッションのディレクトリ)と .pecot/ の状態ファイルを読み書きするので、呼び出しは 1 件ずつ実行する。接続が複数あっても共有する
|
|
104
151
|
const sequence = { tail: Promise.resolve(true) };
|
|
@@ -108,8 +155,8 @@ async function inSequence(signal, task) {
|
|
|
108
155
|
sequence.tail = turn.promise;
|
|
109
156
|
await previous;
|
|
110
157
|
try {
|
|
111
|
-
// 待っている間に中断(notifications/cancelled
|
|
112
|
-
return signal.aborted ?
|
|
158
|
+
// 待っている間に中断(notifications/cancelled)か接続の切断があれば、本体を呼ばない。応答は届かない
|
|
159
|
+
return signal.aborted ? toAbortedResult() : await task();
|
|
113
160
|
}
|
|
114
161
|
finally {
|
|
115
162
|
turn.resolve(true);
|
|
@@ -121,7 +168,7 @@ MCP サーバを作り、commands のそれぞれをツールとして登録す
|
|
|
121
168
|
export function createMcpServer(commands = COMMANDS, options = {}) {
|
|
122
169
|
const server = new McpServer({ name: MCP_SERVER_NAME, version: readVersion() });
|
|
123
170
|
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)));
|
|
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)));
|
|
125
172
|
}
|
|
126
173
|
return server;
|
|
127
174
|
}
|
|
@@ -8,6 +8,8 @@ template: plan
|
|
|
8
8
|
|
|
9
9
|
書き方:
|
|
10
10
|
- Files は、外に触る代表ファイルを並べ、`<details>` の中にファイルごとのどう触るかを詳しく書く
|
|
11
|
+
- Files の `<details>` の先頭に作業単位の表(実装者・モデル・担当)を書く。実装者は `w-implementer-1` から順に名付け、main が自分で直すなら `main` と書き、その行のモデルは `—` にする。モデルの基準は w-help スキルの参照「エージェントのモデル」(pecot-w の `skills/w-help/references/agent-models.md`)
|
|
12
|
+
- 作業単位を委譲するかは、w-help スキルの参照「サブエージェントの使い方」(pecot-w の `skills/w-help/references/subagent-usage.md`)の「実装と修正を委譲する条件」で決める。当たらない単位の実装者は `main` にする
|
|
11
13
|
- Claude Code の plan mode の標準 5 項目は、Context・Approach(推奨方針)・Files(主要ファイルと再利用する既存関数)・E2E(検証)に書く
|
|
12
14
|
|
|
13
15
|
CUJ = 利用者(人またはエージェント)が製品の起点から始め、利用者が観測する結果で終わる操作フロー。
|
|
@@ -52,6 +54,12 @@ CUJ ごとに「誰が・起点・観測結果」の 3 要素を必須とし、
|
|
|
52
54
|
<details>
|
|
53
55
|
<summary align="right">詳細はこちら</summary>
|
|
54
56
|
|
|
57
|
+
作業単位
|
|
58
|
+
|
|
59
|
+
| 実装者 | モデル | 担当 |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| main | — | 4 ファイルの全部(独立した作業が 3 つに届かず、読むファイルも少ないので、委譲しない) |
|
|
62
|
+
|
|
55
63
|
- `src/export.py`
|
|
56
64
|
- `--format` の引数を足す。値は `json`(既定)と `csv`
|
|
57
65
|
- それ以外の値は「csv か json を指定してください」で止める
|
|
@@ -143,6 +151,12 @@ CUJ 3
|
|
|
143
151
|
<details>
|
|
144
152
|
<summary align="right">詳細はこちら</summary>
|
|
145
153
|
|
|
154
|
+
作業単位
|
|
155
|
+
|
|
156
|
+
| 実装者 | モデル | 担当 |
|
|
157
|
+
|---|---|---|
|
|
158
|
+
| <w-implementer-1 / main> | <sonnet / opus / —> | <担当ファイルと、そのモデルを選んだ理由> |
|
|
159
|
+
|
|
146
160
|
<ファイルごとに、どう触るか。再利用する既存の関数があれば、その名前>
|
|
147
161
|
|
|
148
162
|
</details>
|