@pecot/workflow-mcp 0.0.0-stage → 6.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.
Files changed (287) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +184 -2
  4. package/bin/pecot-workflow-mcp.mjs +10 -0
  5. package/cli/dist/cli.d.ts +26 -0
  6. package/cli/dist/cli.js +227 -0
  7. package/cli/dist/commands/board-add.d.ts +3 -0
  8. package/cli/dist/commands/board-add.js +59 -0
  9. package/cli/dist/commands/board-judgment.d.ts +60 -0
  10. package/cli/dist/commands/board-judgment.js +144 -0
  11. package/cli/dist/commands/board-move.d.ts +3 -0
  12. package/cli/dist/commands/board-move.js +57 -0
  13. package/cli/dist/commands/board-readiness.d.ts +34 -0
  14. package/cli/dist/commands/board-readiness.js +108 -0
  15. package/cli/dist/commands/board-show.d.ts +3 -0
  16. package/cli/dist/commands/board-show.js +72 -0
  17. package/cli/dist/commands/board-sync.d.ts +3 -0
  18. package/cli/dist/commands/board-sync.js +111 -0
  19. package/cli/dist/commands/board-view.d.ts +62 -0
  20. package/cli/dist/commands/board-view.js +191 -0
  21. package/cli/dist/commands/board.d.ts +3 -0
  22. package/cli/dist/commands/board.js +12 -0
  23. package/cli/dist/commands/branch.d.ts +3 -0
  24. package/cli/dist/commands/branch.js +100 -0
  25. package/cli/dist/commands/cell-table.d.ts +3 -0
  26. package/cli/dist/commands/cell-table.js +495 -0
  27. package/cli/dist/commands/command-binding.d.ts +26 -0
  28. package/cli/dist/commands/command-binding.js +270 -0
  29. package/cli/dist/commands/command-definition.d.ts +150 -0
  30. package/cli/dist/commands/command-definition.js +105 -0
  31. package/cli/dist/commands/command-help.d.ts +8 -0
  32. package/cli/dist/commands/command-help.js +173 -0
  33. package/cli/dist/commands/command-hint.d.ts +5 -0
  34. package/cli/dist/commands/command-hint.js +13 -0
  35. package/cli/dist/commands/command-stop.d.ts +21 -0
  36. package/cli/dist/commands/command-stop.js +31 -0
  37. package/cli/dist/commands/directory-option.d.ts +7 -0
  38. package/cli/dist/commands/directory-option.js +48 -0
  39. package/cli/dist/commands/failure-kind.d.ts +3 -0
  40. package/cli/dist/commands/failure-kind.js +34 -0
  41. package/cli/dist/commands/failure.d.ts +19 -0
  42. package/cli/dist/commands/failure.js +59 -0
  43. package/cli/dist/commands/fuzzy.d.ts +7 -0
  44. package/cli/dist/commands/fuzzy.js +79 -0
  45. package/cli/dist/commands/github-client.d.ts +16 -0
  46. package/cli/dist/commands/github-client.js +33 -0
  47. package/cli/dist/commands/global-options.d.ts +25 -0
  48. package/cli/dist/commands/global-options.js +83 -0
  49. package/cli/dist/commands/help-layout.d.ts +40 -0
  50. package/cli/dist/commands/help-layout.js +117 -0
  51. package/cli/dist/commands/help.d.ts +8 -0
  52. package/cli/dist/commands/help.js +50 -0
  53. package/cli/dist/commands/input-schema.d.ts +14 -0
  54. package/cli/dist/commands/input-schema.js +56 -0
  55. package/cli/dist/commands/issue-board.d.ts +71 -0
  56. package/cli/dist/commands/issue-board.js +122 -0
  57. package/cli/dist/commands/issue-comment.d.ts +3 -0
  58. package/cli/dist/commands/issue-comment.js +215 -0
  59. package/cli/dist/commands/issue-create.d.ts +3 -0
  60. package/cli/dist/commands/issue-create.js +786 -0
  61. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  62. package/cli/dist/commands/issue-dependency.js +282 -0
  63. package/cli/dist/commands/issue-readiness.d.ts +94 -0
  64. package/cli/dist/commands/issue-readiness.js +218 -0
  65. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  66. package/cli/dist/commands/issue-reopen.js +115 -0
  67. package/cli/dist/commands/issue-shared.d.ts +172 -0
  68. package/cli/dist/commands/issue-shared.js +426 -0
  69. package/cli/dist/commands/issue-show.d.ts +3 -0
  70. package/cli/dist/commands/issue-show.js +169 -0
  71. package/cli/dist/commands/issue.d.ts +3 -0
  72. package/cli/dist/commands/issue.js +13 -0
  73. package/cli/dist/commands/names.d.ts +42 -0
  74. package/cli/dist/commands/names.js +78 -0
  75. package/cli/dist/commands/output.d.ts +90 -0
  76. package/cli/dist/commands/output.js +194 -0
  77. package/cli/dist/commands/pr-waiting.d.ts +20 -0
  78. package/cli/dist/commands/pr-waiting.js +106 -0
  79. package/cli/dist/commands/pr.d.ts +22 -0
  80. package/cli/dist/commands/pr.js +852 -0
  81. package/cli/dist/commands/project-sync.d.ts +92 -0
  82. package/cli/dist/commands/project-sync.js +282 -0
  83. package/cli/dist/commands/project.d.ts +6 -0
  84. package/cli/dist/commands/project.js +714 -0
  85. package/cli/dist/commands/registry.d.ts +6 -0
  86. package/cli/dist/commands/registry.js +30 -0
  87. package/cli/dist/commands/release.d.ts +10 -0
  88. package/cli/dist/commands/release.js +353 -0
  89. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  90. package/cli/dist/commands/renamed-commands.js +53 -0
  91. package/cli/dist/commands/repository-display.d.ts +3 -0
  92. package/cli/dist/commands/repository-display.js +7 -0
  93. package/cli/dist/commands/repository-match.d.ts +14 -0
  94. package/cli/dist/commands/repository-match.js +34 -0
  95. package/cli/dist/commands/rich-panel.d.ts +22 -0
  96. package/cli/dist/commands/rich-panel.js +295 -0
  97. package/cli/dist/commands/session-finish.d.ts +3 -0
  98. package/cli/dist/commands/session-finish.js +267 -0
  99. package/cli/dist/commands/session-start.d.ts +3 -0
  100. package/cli/dist/commands/session-start.js +236 -0
  101. package/cli/dist/commands/session.d.ts +6 -0
  102. package/cli/dist/commands/session.js +214 -0
  103. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  104. package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
  105. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  106. package/cli/dist/commands/tracker-sync-security.js +153 -0
  107. package/cli/dist/commands/tracker-sync.d.ts +65 -0
  108. package/cli/dist/commands/tracker-sync.js +50 -0
  109. package/cli/dist/commands/tracker.d.ts +3 -0
  110. package/cli/dist/commands/tracker.js +18 -0
  111. package/cli/dist/commands/usage-error.d.ts +51 -0
  112. package/cli/dist/commands/usage-error.js +78 -0
  113. package/cli/dist/commands/value-types.d.ts +46 -0
  114. package/cli/dist/commands/value-types.js +94 -0
  115. package/cli/dist/commands/work-target.d.ts +22 -0
  116. package/cli/dist/commands/work-target.js +82 -0
  117. package/cli/dist/commands/worktree.d.ts +3 -0
  118. package/cli/dist/commands/worktree.js +339 -0
  119. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  120. package/cli/dist/domain/api-error-detail.js +25 -0
  121. package/cli/dist/domain/batch-plan.d.ts +73 -0
  122. package/cli/dist/domain/batch-plan.js +114 -0
  123. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  124. package/cli/dist/domain/blocked-by-change.js +101 -0
  125. package/cli/dist/domain/board-move.d.ts +90 -0
  126. package/cli/dist/domain/board-move.js +92 -0
  127. package/cli/dist/domain/branch-name.d.ts +5 -0
  128. package/cli/dist/domain/branch-name.js +10 -0
  129. package/cli/dist/domain/changelog.d.ts +43 -0
  130. package/cli/dist/domain/changelog.js +107 -0
  131. package/cli/dist/domain/command-hint.d.ts +85 -0
  132. package/cli/dist/domain/command-hint.js +148 -0
  133. package/cli/dist/domain/config.d.ts +219 -0
  134. package/cli/dist/domain/config.js +310 -0
  135. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  136. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  137. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  138. package/cli/dist/domain/dependabot-source.js +4 -0
  139. package/cli/dist/domain/dependabot.d.ts +47 -0
  140. package/cli/dist/domain/dependabot.js +88 -0
  141. package/cli/dist/domain/errors.d.ts +24 -0
  142. package/cli/dist/domain/errors.js +36 -0
  143. package/cli/dist/domain/field-options.d.ts +31 -0
  144. package/cli/dist/domain/field-options.js +44 -0
  145. package/cli/dist/domain/format.d.ts +94 -0
  146. package/cli/dist/domain/format.js +234 -0
  147. package/cli/dist/domain/frontmatter.d.ts +137 -0
  148. package/cli/dist/domain/frontmatter.js +290 -0
  149. package/cli/dist/domain/git-runner.d.ts +10 -0
  150. package/cli/dist/domain/git-runner.js +4 -0
  151. package/cli/dist/domain/git-url.d.ts +17 -0
  152. package/cli/dist/domain/git-url.js +30 -0
  153. package/cli/dist/domain/issue-kind.d.ts +16 -0
  154. package/cli/dist/domain/issue-kind.js +16 -0
  155. package/cli/dist/domain/issue-order.d.ts +55 -0
  156. package/cli/dist/domain/issue-order.js +65 -0
  157. package/cli/dist/domain/issue-readout.d.ts +143 -0
  158. package/cli/dist/domain/issue-readout.js +4 -0
  159. package/cli/dist/domain/json-null.d.ts +2 -0
  160. package/cli/dist/domain/json-null.js +5 -0
  161. package/cli/dist/domain/json.d.ts +21 -0
  162. package/cli/dist/domain/json.js +47 -0
  163. package/cli/dist/domain/prerequisites.d.ts +32 -0
  164. package/cli/dist/domain/prerequisites.js +192 -0
  165. package/cli/dist/domain/pull-request.d.ts +201 -0
  166. package/cli/dist/domain/pull-request.js +281 -0
  167. package/cli/dist/domain/python-format.d.ts +105 -0
  168. package/cli/dist/domain/python-format.js +304 -0
  169. package/cli/dist/domain/readiness.d.ts +199 -0
  170. package/cli/dist/domain/readiness.js +391 -0
  171. package/cli/dist/domain/reference-parser.d.ts +51 -0
  172. package/cli/dist/domain/reference-parser.js +123 -0
  173. package/cli/dist/domain/release.d.ts +53 -0
  174. package/cli/dist/domain/release.js +65 -0
  175. package/cli/dist/domain/repository-policy.d.ts +38 -0
  176. package/cli/dist/domain/repository-policy.js +66 -0
  177. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  178. package/cli/dist/domain/repository-resolver.js +122 -0
  179. package/cli/dist/domain/sections.d.ts +69 -0
  180. package/cli/dist/domain/sections.js +514 -0
  181. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  182. package/cli/dist/domain/security-alerts-source.js +4 -0
  183. package/cli/dist/domain/security-alerts.d.ts +52 -0
  184. package/cli/dist/domain/security-alerts.js +107 -0
  185. package/cli/dist/domain/security-tracker.d.ts +115 -0
  186. package/cli/dist/domain/security-tracker.js +353 -0
  187. package/cli/dist/domain/state.d.ts +59 -0
  188. package/cli/dist/domain/state.js +95 -0
  189. package/cli/dist/domain/tracker-body.d.ts +70 -0
  190. package/cli/dist/domain/tracker-body.js +65 -0
  191. package/cli/dist/domain/work-start.d.ts +34 -0
  192. package/cli/dist/domain/work-start.js +49 -0
  193. package/cli/dist/domain/yaml-document.d.ts +5 -0
  194. package/cli/dist/domain/yaml-document.js +206 -0
  195. package/cli/dist/infra/authored-notes.d.ts +37 -0
  196. package/cli/dist/infra/authored-notes.js +72 -0
  197. package/cli/dist/infra/changelog-file.d.ts +19 -0
  198. package/cli/dist/infra/changelog-file.js +43 -0
  199. package/cli/dist/infra/child-stdin.d.ts +4 -0
  200. package/cli/dist/infra/child-stdin.js +8 -0
  201. package/cli/dist/infra/config-store.d.ts +53 -0
  202. package/cli/dist/infra/config-store.js +134 -0
  203. package/cli/dist/infra/diagnostics.d.ts +9 -0
  204. package/cli/dist/infra/diagnostics.js +2 -0
  205. package/cli/dist/infra/file-kind.d.ts +9 -0
  206. package/cli/dist/infra/file-kind.js +26 -0
  207. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  208. package/cli/dist/infra/frontmatter-file.js +30 -0
  209. package/cli/dist/infra/git.d.ts +86 -0
  210. package/cli/dist/infra/git.js +145 -0
  211. package/cli/dist/infra/github/auth.d.ts +60 -0
  212. package/cli/dist/infra/github/auth.js +158 -0
  213. package/cli/dist/infra/github/client.d.ts +178 -0
  214. package/cli/dist/infra/github/client.js +579 -0
  215. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  216. package/cli/dist/infra/github/dependabot-source.js +33 -0
  217. package/cli/dist/infra/github/errors.d.ts +65 -0
  218. package/cli/dist/infra/github/errors.js +64 -0
  219. package/cli/dist/infra/github/index.d.ts +13 -0
  220. package/cli/dist/infra/github/index.js +19 -0
  221. package/cli/dist/infra/github/issues.d.ts +165 -0
  222. package/cli/dist/infra/github/issues.js +428 -0
  223. package/cli/dist/infra/github/payload.d.ts +44 -0
  224. package/cli/dist/infra/github/payload.js +80 -0
  225. package/cli/dist/infra/github/projects.d.ts +143 -0
  226. package/cli/dist/infra/github/projects.js +384 -0
  227. package/cli/dist/infra/github/pulls.d.ts +104 -0
  228. package/cli/dist/infra/github/pulls.js +217 -0
  229. package/cli/dist/infra/github/queries.d.ts +44 -0
  230. package/cli/dist/infra/github/queries.js +1031 -0
  231. package/cli/dist/infra/github/readout.d.ts +22 -0
  232. package/cli/dist/infra/github/readout.js +167 -0
  233. package/cli/dist/infra/github/repos.d.ts +86 -0
  234. package/cli/dist/infra/github/repos.js +168 -0
  235. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  236. package/cli/dist/infra/github/rest-path.js +31 -0
  237. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  238. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  239. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  240. package/cli/dist/infra/gitignore-spec.js +235 -0
  241. package/cli/dist/infra/nx-scope.d.ts +51 -0
  242. package/cli/dist/infra/nx-scope.js +182 -0
  243. package/cli/dist/infra/os-error.d.ts +24 -0
  244. package/cli/dist/infra/os-error.js +38 -0
  245. package/cli/dist/infra/paths.d.ts +88 -0
  246. package/cli/dist/infra/paths.js +234 -0
  247. package/cli/dist/infra/state-store.d.ts +54 -0
  248. package/cli/dist/infra/state-store.js +130 -0
  249. package/cli/dist/infra/template-store.d.ts +15 -0
  250. package/cli/dist/infra/template-store.js +34 -0
  251. package/cli/dist/infra/text-file.d.ts +12 -0
  252. package/cli/dist/infra/text-file.js +33 -0
  253. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  254. package/cli/dist/infra/worktree-copy.js +95 -0
  255. package/cli/dist/infra/worktree-links.d.ts +142 -0
  256. package/cli/dist/infra/worktree-links.js +440 -0
  257. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  258. package/cli/dist/infra/worktree-setup.js +41 -0
  259. package/cli/dist/infra/worktree.d.ts +185 -0
  260. package/cli/dist/infra/worktree.js +584 -0
  261. package/cli/dist/mcp/result.d.ts +61 -0
  262. package/cli/dist/mcp/result.js +96 -0
  263. package/cli/dist/mcp/serve.d.ts +51 -0
  264. package/cli/dist/mcp/serve.js +183 -0
  265. package/cli/dist/mcp/server.d.ts +21 -0
  266. package/cli/dist/mcp/server.js +142 -0
  267. package/cli/dist/mcp/session-directory.d.ts +26 -0
  268. package/cli/dist/mcp/session-directory.js +84 -0
  269. package/cli/dist/package.json +1 -0
  270. package/cli/dist/version.d.ts +17 -0
  271. package/cli/dist/version.js +42 -0
  272. package/cli/templates/comment/merge-diff.md +34 -0
  273. package/cli/templates/comment/plan.md +195 -0
  274. package/cli/templates/comment/precede-notify.md +33 -0
  275. package/cli/templates/comment/review-findings.md +42 -0
  276. package/cli/templates/comment/review-resolution.md +48 -0
  277. package/cli/templates/issue/bug.md +63 -0
  278. package/cli/templates/issue/epic.md +54 -0
  279. package/cli/templates/issue/task-implement.md +74 -0
  280. package/cli/templates/issue/task.md +48 -0
  281. package/cli/templates/issue/tracker.md +48 -0
  282. package/cli/templates/pr/create.md +123 -0
  283. package/cli/templates/pr/release.md +56 -0
  284. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  285. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  286. package/npm-shrinkwrap.json +83 -0
  287. package/package.json +22 -4
@@ -0,0 +1,96 @@
1
+ import { z } from 'zod';
2
+ import { USAGE_EXIT_CODE } from '../commands/usage-error.js';
3
+ /**
4
+ stdout・stderr に書かれた文字列と、失敗の原因の名前、最初の結果の行を集める io
5
+ */
6
+ export function collectIo() {
7
+ const out = [];
8
+ const error = [];
9
+ let failureKind;
10
+ let firstResult;
11
+ return {
12
+ io: {
13
+ stdout: (text) => {
14
+ out.push(text);
15
+ },
16
+ stderr: (text) => {
17
+ error.push(text);
18
+ },
19
+ surface: 'mcp',
20
+ failureKind: (kind) => {
21
+ failureKind ??= kind;
22
+ },
23
+ resultLine: (line) => {
24
+ firstResult ??= line;
25
+ },
26
+ },
27
+ stdout: () => out.join(''),
28
+ stderr: () => error.join(''),
29
+ kind: () => failureKind,
30
+ resultLine: () => firstResult,
31
+ };
32
+ }
33
+ /**
34
+ 全ツールが共有する outputSchema。pecot-tools・pecot-visual と項目の名前をそろえる
35
+ */
36
+ export const TOOL_OUTPUT_SCHEMA = z.object({
37
+ ok: z.boolean().describe('Whether the tool completed its intended run'),
38
+ exitCode: z.number().describe('Exit code (0 = success)'),
39
+ kind: z.string().optional().describe('Failure kind (omitted on success)'),
40
+ artifacts: z.array(z.string()).describe('Absolute paths of files and directories created or updated'),
41
+ data: z.record(z.string(), z.unknown()).describe('Object with the details of the run'),
42
+ message: z.string().describe('One-line summary for the calling agent. On success, the first result line or else the first stdout line; empty when there is neither'),
43
+ stdout: z.string().optional().describe('Captured stdout (omitted when empty)'),
44
+ stderr: z.string().optional().describe('Captured stderr (omitted when empty)'),
45
+ });
46
+ const ERROR_PREFIX = 'error: ';
47
+ function linesOf(text) {
48
+ return text.split('\n').filter(line => line.trim() !== '');
49
+ }
50
+ // 失敗は最初の error の行の文、無ければ stderr の最初の行。成功は結果の行、無ければ stdout の最初の行
51
+ function messageOf(outcome) {
52
+ if (outcome.exitCode === 0)
53
+ return outcome.resultLine ?? linesOf(outcome.stdout).at(0)?.trim() ?? '';
54
+ const lines = linesOf(outcome.stderr);
55
+ if (outcome.message !== undefined)
56
+ return outcome.message;
57
+ const errorLine = lines.find(line => line.startsWith(ERROR_PREFIX));
58
+ return errorLine === undefined ? (lines.at(0)?.trim() ?? '') : errorLine.slice(ERROR_PREFIX.length);
59
+ }
60
+ function toOutput(outcome) {
61
+ const isOk = outcome.exitCode === 0;
62
+ return {
63
+ ok: isOk,
64
+ exitCode: outcome.exitCode,
65
+ ...!isOk && { kind: outcome.kind ?? 'other' },
66
+ artifacts: [],
67
+ data: {},
68
+ message: messageOf(outcome),
69
+ ...outcome.stdout !== '' && { stdout: outcome.stdout },
70
+ ...outcome.stderr !== '' && { stderr: outcome.stderr },
71
+ };
72
+ }
73
+ /**
74
+ structuredContent と、同じ JSON を本文にした content の両方で返す。ホストがどちらを渡しても同じ中身が届く
75
+ */
76
+ export function toToolResult(outcome) {
77
+ const output = toOutput(outcome);
78
+ return {
79
+ content: [{ type: 'text', text: JSON.stringify(output) }],
80
+ structuredContent: { ...output },
81
+ ...!output.ok && { isError: true },
82
+ };
83
+ }
84
+ /**
85
+ コマンドを呼ぶ前に入力を断った結果。終了コードは使い方の誤りと同じ 2
86
+ */
87
+ export function toRejectedResult(message) {
88
+ return toToolResult({ exitCode: USAGE_EXIT_CODE, stdout: '', stderr: '', kind: 'invalid-input', message });
89
+ }
90
+ /**
91
+ 中断(notifications/cancelled か接続の切断)で本体を呼ばなかった結果。応答はクライアントに届かない
92
+ */
93
+ export function toAbortedResult() {
94
+ return toToolResult({ exitCode: 1, stdout: '', stderr: '', kind: 'aborted', message: 'cancelled' });
95
+ }
96
+ //# sourceMappingURL=result.js.map
@@ -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
+ 対象のリポを決められなかった理由。あるとき、どのツールの呼び出しもコマンドを呼ばず、この理由を失敗(終了コード 1、kind は session-directory-unresolved)で返す。tools/list は変わらない
7
+ */
8
+ readonly unavailableReason?: string | undefined;
9
+ /**
10
+ プログラムの誤り(報告できる失敗でも使い方の誤りでもない例外)と、それまでに集めた出力を、切り分けのために伝える先。結果は kind が other の失敗にする
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,142 @@
1
+ // COMMANDS の全コマンドを 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 { findRenamedInput, renamedInputNote } from '../commands/renamed-commands.js';
14
+ import { outputWidth } from '../commands/rich-panel.js';
15
+ import { UsageError } from '../commands/usage-error.js';
16
+ import { readVersion } from '../version.js';
17
+ import { collectIo, TOOL_OUTPUT_SCHEMA, toAbortedResult, toRejectedResult, toToolResult } from './result.js';
18
+ export const MCP_SERVER_NAME = 'pecot-workflow';
19
+ function rejected(message) {
20
+ return { kind: 'rejected', message: `invalid input: ${message}` };
21
+ }
22
+ /**
23
+ SDK に渡す入力のスキーマ。tools/list の形は定義書と同じ z.toJSONSchema の形に additionalProperties: false を足し、検証は素通しにする。
24
+ SDK に zod を渡すと、検証の後に未知のキーを捨てた値が届き、未知のキーを誤りにできない
25
+ */
26
+ function passthroughSchema(definition) {
27
+ const jsonSchema = () => ({ ...z.toJSONSchema(definition.input, { io: 'input' }), additionalProperties: false });
28
+ return {
29
+ '~standard': {
30
+ version: 1,
31
+ vendor: MCP_SERVER_NAME,
32
+ jsonSchema: { input: jsonSchema, output: jsonSchema },
33
+ validate: value => ({ value }),
34
+ },
35
+ };
36
+ }
37
+ function issuesMessage(error) {
38
+ return error.issues.map(issue => issue.path.length === 0 ? issue.message : `${issue.path.join('.')}: ${issue.message}`).join('; ');
39
+ }
40
+ /**
41
+ 入力を検証する。順は CLI と同じ(未知のキー → repo の形 → definition.parse)。誤りならコマンドを呼ばない
42
+ */
43
+ function prepare(definition, raw) {
44
+ // arguments が配列や null なら SDK が先に -32602 で断るので、ここに来る非 object は省略(undefined)だけ
45
+ const input = isRecord(raw) ? raw : {};
46
+ const unknown = Object.keys(input).filter(key => !Object.hasOwn(definition.input.shape, key));
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
+ }
54
+ const repository = input['repo'];
55
+ if (typeof repository === 'string' && !definition.hasOwnRepo) {
56
+ try {
57
+ parseOwnerRepository(repository);
58
+ }
59
+ catch (error) {
60
+ if (!(error instanceof InvalidValueError))
61
+ throw error;
62
+ return rejected(`repo: ${error.message}`);
63
+ }
64
+ }
65
+ try {
66
+ return { kind: 'prepared', command: definition.parse(input) };
67
+ }
68
+ catch (error) {
69
+ if (!(error instanceof z.ZodError))
70
+ throw error;
71
+ return rejected(issuesMessage(error));
72
+ }
73
+ }
74
+ // 対象のリポを決められなかったとき、コマンドを呼ばずに理由を失敗で返す
75
+ function unavailableResult(reason) {
76
+ const collected = collectIo();
77
+ createOutput(false, collected.io).error(reason);
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);
82
+ }
83
+ async function invoke(definition, raw, options) {
84
+ if (options.unavailableReason !== undefined)
85
+ return unavailableResult(options.unavailableReason);
86
+ const collected = collectIo();
87
+ // interface-env: TERMINAL_WIDTH COLUMNS
88
+ const width = outputWidth(process.env, undefined);
89
+ let exitCode;
90
+ let message;
91
+ try {
92
+ resolveApiUrlOverride();
93
+ const preparation = prepare(definition, raw);
94
+ if (preparation.kind === 'rejected')
95
+ return toRejectedResult(preparation.message);
96
+ try {
97
+ exitCode = await preparation.command.run(collected.io);
98
+ }
99
+ catch (error) {
100
+ throw withUsage(error, usageOf(definition));
101
+ }
102
+ }
103
+ catch (error) {
104
+ // 使い方の誤りは枠で出すので、error の行の代わりに例外の文の 1 行目を message にする
105
+ if (error instanceof UsageError)
106
+ message = error.message.split('\n', 1)[0];
107
+ try {
108
+ exitCode = exitCodeOfFailure(error, collected.io, width);
109
+ }
110
+ catch (error_) {
111
+ options.reportUnexpected?.(error_, { stdout: collected.stdout(), stderr: collected.stderr() });
112
+ return toToolResult({ exitCode: 1, stdout: collected.stdout(), stderr: collected.stderr(), kind: 'other', message: unexpectedMessage(error_) });
113
+ }
114
+ }
115
+ return toToolResult({ exitCode, stdout: collected.stdout(), stderr: collected.stderr(), kind: collected.kind(), message, resultLine: collected.resultLine() });
116
+ }
117
+ // コマンドは process.cwd()(起動のときに serve.ts が決めたセッションのディレクトリ)と .pecot/ の状態ファイルを読み書きするので、呼び出しは 1 件ずつ実行する。接続が複数あっても共有する
118
+ const sequence = { tail: Promise.resolve(true) };
119
+ async function inSequence(signal, task) {
120
+ const previous = sequence.tail;
121
+ const turn = Promise.withResolvers();
122
+ sequence.tail = turn.promise;
123
+ await previous;
124
+ try {
125
+ // 待っている間に中断(notifications/cancelled)か接続の切断があれば、本体を呼ばない。応答は届かない
126
+ return signal.aborted ? toAbortedResult() : await task();
127
+ }
128
+ finally {
129
+ turn.resolve(true);
130
+ }
131
+ }
132
+ /**
133
+ MCP サーバを作り、commands のそれぞれをツールとして登録する。名前は toolName、説明は description、並びは commands の順
134
+ */
135
+ export function createMcpServer(commands = COMMANDS, options = {}) {
136
+ const server = new McpServer({ name: MCP_SERVER_NAME, version: readVersion() });
137
+ for (const definition of commands) {
138
+ server.registerTool(definition.toolName, { description: definition.description, inputSchema: passthroughSchema(definition), outputSchema: TOOL_OUTPUT_SCHEMA }, async (arguments_, serverContext) => await inSequence(serverContext.mcpReq.signal, async () => await invoke(definition, arguments_, options)));
139
+ }
140
+ return server;
141
+ }
142
+ //# 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