@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.
Files changed (244) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +126 -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 +222 -0
  7. package/cli/dist/commands/cell-table.d.ts +3 -0
  8. package/cli/dist/commands/cell-table.js +495 -0
  9. package/cli/dist/commands/command-binding.d.ts +26 -0
  10. package/cli/dist/commands/command-binding.js +266 -0
  11. package/cli/dist/commands/command-definition.d.ts +136 -0
  12. package/cli/dist/commands/command-definition.js +101 -0
  13. package/cli/dist/commands/command-help.d.ts +8 -0
  14. package/cli/dist/commands/command-help.js +173 -0
  15. package/cli/dist/commands/command-stop.d.ts +19 -0
  16. package/cli/dist/commands/command-stop.js +30 -0
  17. package/cli/dist/commands/dependabot.d.ts +3 -0
  18. package/cli/dist/commands/dependabot.js +165 -0
  19. package/cli/dist/commands/directory-option.d.ts +7 -0
  20. package/cli/dist/commands/directory-option.js +48 -0
  21. package/cli/dist/commands/failure.d.ts +13 -0
  22. package/cli/dist/commands/failure.js +33 -0
  23. package/cli/dist/commands/fuzzy.d.ts +7 -0
  24. package/cli/dist/commands/fuzzy.js +79 -0
  25. package/cli/dist/commands/github-client.d.ts +12 -0
  26. package/cli/dist/commands/github-client.js +23 -0
  27. package/cli/dist/commands/global-options.d.ts +25 -0
  28. package/cli/dist/commands/global-options.js +83 -0
  29. package/cli/dist/commands/help-layout.d.ts +40 -0
  30. package/cli/dist/commands/help-layout.js +117 -0
  31. package/cli/dist/commands/help.d.ts +8 -0
  32. package/cli/dist/commands/help.js +55 -0
  33. package/cli/dist/commands/input-schema.d.ts +14 -0
  34. package/cli/dist/commands/input-schema.js +56 -0
  35. package/cli/dist/commands/issue-board.d.ts +38 -0
  36. package/cli/dist/commands/issue-board.js +62 -0
  37. package/cli/dist/commands/issue-comment.d.ts +3 -0
  38. package/cli/dist/commands/issue-comment.js +196 -0
  39. package/cli/dist/commands/issue-create.d.ts +3 -0
  40. package/cli/dist/commands/issue-create.js +329 -0
  41. package/cli/dist/commands/issue-project.d.ts +3 -0
  42. package/cli/dist/commands/issue-project.js +176 -0
  43. package/cli/dist/commands/issue-quick.d.ts +3 -0
  44. package/cli/dist/commands/issue-quick.js +126 -0
  45. package/cli/dist/commands/issue-read.d.ts +3 -0
  46. package/cli/dist/commands/issue-read.js +80 -0
  47. package/cli/dist/commands/issue-shared.d.ts +159 -0
  48. package/cli/dist/commands/issue-shared.js +419 -0
  49. package/cli/dist/commands/issue.d.ts +4 -0
  50. package/cli/dist/commands/issue.js +15 -0
  51. package/cli/dist/commands/names.d.ts +9 -0
  52. package/cli/dist/commands/names.js +16 -0
  53. package/cli/dist/commands/output.d.ts +78 -0
  54. package/cli/dist/commands/output.js +187 -0
  55. package/cli/dist/commands/pr.d.ts +3 -0
  56. package/cli/dist/commands/pr.js +933 -0
  57. package/cli/dist/commands/project-info.d.ts +48 -0
  58. package/cli/dist/commands/project-info.js +181 -0
  59. package/cli/dist/commands/project-sync.d.ts +91 -0
  60. package/cli/dist/commands/project-sync.js +273 -0
  61. package/cli/dist/commands/project.d.ts +5 -0
  62. package/cli/dist/commands/project.js +677 -0
  63. package/cli/dist/commands/registry.d.ts +6 -0
  64. package/cli/dist/commands/registry.js +27 -0
  65. package/cli/dist/commands/release.d.ts +10 -0
  66. package/cli/dist/commands/release.js +414 -0
  67. package/cli/dist/commands/repository-display.d.ts +3 -0
  68. package/cli/dist/commands/repository-display.js +7 -0
  69. package/cli/dist/commands/repository-match.d.ts +14 -0
  70. package/cli/dist/commands/repository-match.js +33 -0
  71. package/cli/dist/commands/repository.d.ts +5 -0
  72. package/cli/dist/commands/repository.js +265 -0
  73. package/cli/dist/commands/rich-panel.d.ts +22 -0
  74. package/cli/dist/commands/rich-panel.js +295 -0
  75. package/cli/dist/commands/security.d.ts +3 -0
  76. package/cli/dist/commands/security.js +164 -0
  77. package/cli/dist/commands/session.d.ts +3 -0
  78. package/cli/dist/commands/session.js +161 -0
  79. package/cli/dist/commands/tracker-sync.d.ts +58 -0
  80. package/cli/dist/commands/tracker-sync.js +53 -0
  81. package/cli/dist/commands/usage-error.d.ts +47 -0
  82. package/cli/dist/commands/usage-error.js +72 -0
  83. package/cli/dist/commands/value-types.d.ts +46 -0
  84. package/cli/dist/commands/value-types.js +94 -0
  85. package/cli/dist/commands/work-target.d.ts +13 -0
  86. package/cli/dist/commands/work-target.js +41 -0
  87. package/cli/dist/commands/worktree.d.ts +3 -0
  88. package/cli/dist/commands/worktree.js +335 -0
  89. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  90. package/cli/dist/domain/api-error-detail.js +25 -0
  91. package/cli/dist/domain/branch-name.d.ts +5 -0
  92. package/cli/dist/domain/branch-name.js +10 -0
  93. package/cli/dist/domain/changelog.d.ts +43 -0
  94. package/cli/dist/domain/changelog.js +107 -0
  95. package/cli/dist/domain/config.d.ts +215 -0
  96. package/cli/dist/domain/config.js +300 -0
  97. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  98. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  99. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  100. package/cli/dist/domain/dependabot-source.js +4 -0
  101. package/cli/dist/domain/dependabot.d.ts +47 -0
  102. package/cli/dist/domain/dependabot.js +88 -0
  103. package/cli/dist/domain/errors.d.ts +19 -0
  104. package/cli/dist/domain/errors.js +31 -0
  105. package/cli/dist/domain/field-options.d.ts +31 -0
  106. package/cli/dist/domain/field-options.js +44 -0
  107. package/cli/dist/domain/format.d.ts +47 -0
  108. package/cli/dist/domain/format.js +168 -0
  109. package/cli/dist/domain/frontmatter.d.ts +122 -0
  110. package/cli/dist/domain/frontmatter.js +264 -0
  111. package/cli/dist/domain/git-runner.d.ts +10 -0
  112. package/cli/dist/domain/git-runner.js +4 -0
  113. package/cli/dist/domain/git-url.d.ts +17 -0
  114. package/cli/dist/domain/git-url.js +30 -0
  115. package/cli/dist/domain/issue-kind.d.ts +16 -0
  116. package/cli/dist/domain/issue-kind.js +16 -0
  117. package/cli/dist/domain/issue-readout.d.ts +107 -0
  118. package/cli/dist/domain/issue-readout.js +4 -0
  119. package/cli/dist/domain/json-null.d.ts +2 -0
  120. package/cli/dist/domain/json-null.js +5 -0
  121. package/cli/dist/domain/json.d.ts +21 -0
  122. package/cli/dist/domain/json.js +47 -0
  123. package/cli/dist/domain/prerequisites.d.ts +32 -0
  124. package/cli/dist/domain/prerequisites.js +192 -0
  125. package/cli/dist/domain/pull-request.d.ts +134 -0
  126. package/cli/dist/domain/pull-request.js +232 -0
  127. package/cli/dist/domain/python-format.d.ts +105 -0
  128. package/cli/dist/domain/python-format.js +304 -0
  129. package/cli/dist/domain/readiness.d.ts +172 -0
  130. package/cli/dist/domain/readiness.js +280 -0
  131. package/cli/dist/domain/reference-parser.d.ts +49 -0
  132. package/cli/dist/domain/reference-parser.js +119 -0
  133. package/cli/dist/domain/release.d.ts +49 -0
  134. package/cli/dist/domain/release.js +72 -0
  135. package/cli/dist/domain/repository-policy.d.ts +32 -0
  136. package/cli/dist/domain/repository-policy.js +65 -0
  137. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  138. package/cli/dist/domain/repository-resolver.js +119 -0
  139. package/cli/dist/domain/sections.d.ts +69 -0
  140. package/cli/dist/domain/sections.js +514 -0
  141. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  142. package/cli/dist/domain/security-alerts-source.js +4 -0
  143. package/cli/dist/domain/security-alerts.d.ts +52 -0
  144. package/cli/dist/domain/security-alerts.js +107 -0
  145. package/cli/dist/domain/security-tracker.d.ts +115 -0
  146. package/cli/dist/domain/security-tracker.js +353 -0
  147. package/cli/dist/domain/state.d.ts +29 -0
  148. package/cli/dist/domain/state.js +56 -0
  149. package/cli/dist/domain/tracker-body.d.ts +70 -0
  150. package/cli/dist/domain/tracker-body.js +65 -0
  151. package/cli/dist/domain/yaml-document.d.ts +5 -0
  152. package/cli/dist/domain/yaml-document.js +206 -0
  153. package/cli/dist/infra/authored-notes.d.ts +37 -0
  154. package/cli/dist/infra/authored-notes.js +66 -0
  155. package/cli/dist/infra/changelog-file.d.ts +19 -0
  156. package/cli/dist/infra/changelog-file.js +43 -0
  157. package/cli/dist/infra/child-stdin.d.ts +4 -0
  158. package/cli/dist/infra/child-stdin.js +8 -0
  159. package/cli/dist/infra/config-store.d.ts +49 -0
  160. package/cli/dist/infra/config-store.js +121 -0
  161. package/cli/dist/infra/diagnostics.d.ts +9 -0
  162. package/cli/dist/infra/diagnostics.js +2 -0
  163. package/cli/dist/infra/file-kind.d.ts +9 -0
  164. package/cli/dist/infra/file-kind.js +26 -0
  165. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  166. package/cli/dist/infra/frontmatter-file.js +30 -0
  167. package/cli/dist/infra/git.d.ts +74 -0
  168. package/cli/dist/infra/git.js +133 -0
  169. package/cli/dist/infra/github/auth.d.ts +60 -0
  170. package/cli/dist/infra/github/auth.js +158 -0
  171. package/cli/dist/infra/github/client.d.ts +173 -0
  172. package/cli/dist/infra/github/client.js +576 -0
  173. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  174. package/cli/dist/infra/github/dependabot-source.js +33 -0
  175. package/cli/dist/infra/github/errors.d.ts +47 -0
  176. package/cli/dist/infra/github/errors.js +42 -0
  177. package/cli/dist/infra/github/index.d.ts +13 -0
  178. package/cli/dist/infra/github/index.js +19 -0
  179. package/cli/dist/infra/github/issues.d.ts +129 -0
  180. package/cli/dist/infra/github/issues.js +273 -0
  181. package/cli/dist/infra/github/payload.d.ts +44 -0
  182. package/cli/dist/infra/github/payload.js +80 -0
  183. package/cli/dist/infra/github/projects.d.ts +108 -0
  184. package/cli/dist/infra/github/projects.js +303 -0
  185. package/cli/dist/infra/github/pulls.d.ts +80 -0
  186. package/cli/dist/infra/github/pulls.js +161 -0
  187. package/cli/dist/infra/github/queries.d.ts +36 -0
  188. package/cli/dist/infra/github/queries.js +883 -0
  189. package/cli/dist/infra/github/readout.d.ts +18 -0
  190. package/cli/dist/infra/github/readout.js +156 -0
  191. package/cli/dist/infra/github/repos.d.ts +68 -0
  192. package/cli/dist/infra/github/repos.js +137 -0
  193. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  194. package/cli/dist/infra/github/rest-path.js +31 -0
  195. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  196. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  197. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  198. package/cli/dist/infra/gitignore-spec.js +235 -0
  199. package/cli/dist/infra/nx-scope.d.ts +51 -0
  200. package/cli/dist/infra/nx-scope.js +182 -0
  201. package/cli/dist/infra/os-error.d.ts +24 -0
  202. package/cli/dist/infra/os-error.js +38 -0
  203. package/cli/dist/infra/paths.d.ts +88 -0
  204. package/cli/dist/infra/paths.js +234 -0
  205. package/cli/dist/infra/state-store.d.ts +45 -0
  206. package/cli/dist/infra/state-store.js +118 -0
  207. package/cli/dist/infra/template-store.d.ts +15 -0
  208. package/cli/dist/infra/template-store.js +34 -0
  209. package/cli/dist/infra/text-file.d.ts +12 -0
  210. package/cli/dist/infra/text-file.js +33 -0
  211. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  212. package/cli/dist/infra/worktree-copy.js +95 -0
  213. package/cli/dist/infra/worktree-links.d.ts +139 -0
  214. package/cli/dist/infra/worktree-links.js +433 -0
  215. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  216. package/cli/dist/infra/worktree-setup.js +41 -0
  217. package/cli/dist/infra/worktree.d.ts +174 -0
  218. package/cli/dist/infra/worktree.js +567 -0
  219. package/cli/dist/mcp/result.d.ts +33 -0
  220. package/cli/dist/mcp/result.js +52 -0
  221. package/cli/dist/mcp/serve.d.ts +51 -0
  222. package/cli/dist/mcp/serve.js +183 -0
  223. package/cli/dist/mcp/server.d.ts +21 -0
  224. package/cli/dist/mcp/server.js +128 -0
  225. package/cli/dist/mcp/session-directory.d.ts +26 -0
  226. package/cli/dist/mcp/session-directory.js +84 -0
  227. package/cli/dist/package.json +1 -0
  228. package/cli/dist/version.d.ts +17 -0
  229. package/cli/dist/version.js +42 -0
  230. package/cli/templates/comment/merge-diff.md +34 -0
  231. package/cli/templates/comment/plan.md +181 -0
  232. package/cli/templates/comment/precede-notify.md +33 -0
  233. package/cli/templates/comment/review-findings.md +42 -0
  234. package/cli/templates/comment/review-resolution.md +48 -0
  235. package/cli/templates/issue/bug.md +63 -0
  236. package/cli/templates/issue/epic.md +54 -0
  237. package/cli/templates/issue/task-implement.md +67 -0
  238. package/cli/templates/issue/task.md +48 -0
  239. package/cli/templates/issue/tracker.md +48 -0
  240. package/cli/templates/pr/create.md +123 -0
  241. package/cli/templates/pr/release.md +56 -0
  242. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  243. package/npm-shrinkwrap.json +83 -0
  244. package/package.json +22 -4
@@ -0,0 +1,121 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスはプロジェクトルート配下の設定ディレクトリと、呼び出し側が渡す設定ファイル */
2
+ // プロジェクト設定(`.pecot/config/projects/*.json`)の読み書き。モデルと判定は domain/config.ts にある。
3
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { ConfigError, findRepositoryByName, MultipleConfigsError, parseProjectConfig, serializeProjectConfig, } from '../domain/config.js';
6
+ import { InvalidValueError } from '../domain/errors.js';
7
+ import { parseJsonText } from '../domain/json.js';
8
+ import { compareStrings, pythonStrip, ValidationFailure } from '../domain/python-format.js';
9
+ import { isFileNotFound } from './os-error.js';
10
+ import { CONFIG_DIR, projectRoot, resolveRealPath } from './paths.js';
11
+ import { readTextFile } from './text-file.js';
12
+ /**
13
+ 設定ディレクトリ(`{プロジェクトルート}/.pecot/config`)
14
+ */
15
+ export function configDirectory() {
16
+ return path.join(projectRoot(), CONFIG_DIR);
17
+ }
18
+ /**
19
+ プロジェクト設定ディレクトリ(`.pecot/config/projects`)
20
+ */
21
+ export function projectsDirectory() {
22
+ return path.join(configDirectory(), 'projects');
23
+ }
24
+ /**
25
+ JSON ファイルから設定を読む。無ければ ConfigError、JSON の構文や形が不正なら `invalid config file: {パス}: {詳細}` の ConfigError。
26
+ 詳細は、形の不正なら `場所: 本文` を `; ` でつないだもの(Python と同じ)、構文の不正なら JSON パーサーの文(Python の JSONDecodeError の文とは違う)
27
+ */
28
+ export function loadConfig(file) {
29
+ if (!existsSync(file))
30
+ throw new ConfigError(`config file not found: ${file}`);
31
+ try {
32
+ return parseProjectConfig(parseJsonText(readTextFile(file)));
33
+ }
34
+ catch (error) {
35
+ if (error instanceof ValidationFailure) {
36
+ const detail = error.issues.map(issue => `${issue.location.map(String).join('.')}: ${issue.message}`).join('; ');
37
+ throw new ConfigError(`invalid config file: ${file}: ${detail}`, { cause: error });
38
+ }
39
+ if (error instanceof InvalidValueError)
40
+ throw new ConfigError(`invalid config file: ${file}: ${error.message}`, { cause: error });
41
+ throw error;
42
+ }
43
+ }
44
+ /**
45
+ 設定を JSON ファイルに保存する。親ディレクトリが無ければ作る
46
+ */
47
+ export function saveConfig(config, file) {
48
+ mkdirSync(path.dirname(file), { recursive: true });
49
+ writeFileSync(file, serializeProjectConfig(config));
50
+ }
51
+ /**
52
+ .active ファイルが指すアクティブ設定のパス。中身は .active のあるディレクトリ基準の相対パス(絶対パスも可)。
53
+ 設定されていない・指す先が無いときは undefined
54
+ */
55
+ export function getActiveConfigPath() {
56
+ const activeFile = path.join(projectsDirectory(), '.active');
57
+ if (!existsSync(activeFile))
58
+ return undefined;
59
+ const raw = pythonStrip(readTextFile(activeFile));
60
+ if (raw === '')
61
+ return undefined;
62
+ const configPath = resolveRealPath(path.resolve(path.dirname(activeFile), raw));
63
+ return existsSync(configPath) ? configPath : undefined;
64
+ }
65
+ export function loadActiveConfig() {
66
+ const configPath = getActiveConfigPath();
67
+ return configPath === undefined ? undefined : loadConfig(configPath);
68
+ }
69
+ /**
70
+ アクティブ設定を設定する。.active には .active のあるディレクトリ基準の相対パスを書く。ファイルが無ければ ConfigError
71
+ */
72
+ export function setActiveConfig(file) {
73
+ if (!existsSync(file))
74
+ throw new ConfigError(`config file not found: ${file}`);
75
+ const activeFile = path.join(projectsDirectory(), '.active');
76
+ mkdirSync(path.dirname(activeFile), { recursive: true });
77
+ const relative = path.relative(path.resolve(path.dirname(activeFile)), path.resolve(file));
78
+ writeFileSync(activeFile, `${relative}\n`);
79
+ }
80
+ /**
81
+ `{host}_{owner}_*.json` の設定ファイルを探す(プロジェクト名ベース)。host と owner の両方が要る。
82
+ 複数見つかったら MultipleConfigsError(名前順)
83
+ */
84
+ export function findConfigFile(options) {
85
+ const { host, owner } = options;
86
+ if (host === undefined || host === '' || owner === undefined || owner === '')
87
+ return undefined;
88
+ const directory = projectsDirectory();
89
+ const prefix = `${host}_${owner}_`;
90
+ let names;
91
+ try {
92
+ names = readdirSync(directory);
93
+ }
94
+ catch (error) {
95
+ if (isFileNotFound(error))
96
+ return undefined;
97
+ throw error;
98
+ }
99
+ const matches = names.filter(name => name.startsWith(prefix) && name.endsWith('.json') && name.length >= prefix.length + '.json'.length).toSorted(compareStrings);
100
+ const [only] = matches;
101
+ if (matches.length > 1)
102
+ throw new MultipleConfigsError(matches.map(name => path.join(directory, name)));
103
+ return only === undefined ? undefined : path.join(directory, only);
104
+ }
105
+ /**
106
+ プロジェクト設定を取得する。引数なしはアクティブ設定。
107
+ repository だけなら、アクティブ設定の repositories にあればそれを返し、無ければ検索する。見つからなければ undefined
108
+ */
109
+ export function getProjectConfig(query = {}) {
110
+ const { host, owner, repository } = query;
111
+ if (host === undefined && owner === undefined && repository === undefined)
112
+ return loadActiveConfig();
113
+ if (host === undefined && owner === undefined && repository !== undefined) {
114
+ const active = loadActiveConfig();
115
+ if (active !== undefined && findRepositoryByName(active, repository) !== undefined)
116
+ return active;
117
+ }
118
+ const configPath = findConfigFile({ host, owner });
119
+ return configPath === undefined ? undefined : loadConfig(configPath);
120
+ }
121
+ //# sourceMappingURL=config-store.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ infra が警告・エラーを伝える受け口。呼ぶ側(commands)が渡す。
3
+ `src/commands/output.ts` の `Output` がそのまま満たす。前置き(`warning:`・`error:`)と字下げは受け口の側が付ける
4
+ */
5
+ export interface Diagnostics {
6
+ readonly warning: (message: string) => void;
7
+ readonly error: (message: string) => void;
8
+ }
9
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ ディレクトリか。無い・読めないときは false
3
+ */
4
+ export declare function isDirectory(target: string): boolean;
5
+ /**
6
+ 通常のファイルか。無い・読めないときは false
7
+ */
8
+ export declare function isFile(target: string): boolean;
9
+ //# sourceMappingURL=file-kind.d.ts.map
@@ -0,0 +1,26 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側が決める。ここは種類を調べるだけ */
2
+ // パスの種類の判定。Python の Path.is_dir() / is_file() と同じく、シンボリックリンクを辿り、読めないパスは偽にする。
3
+ import { statSync } from 'node:fs';
4
+ /**
5
+ ディレクトリか。無い・読めないときは false
6
+ */
7
+ export function isDirectory(target) {
8
+ try {
9
+ return statSync(target).isDirectory();
10
+ }
11
+ catch {
12
+ return false;
13
+ }
14
+ }
15
+ /**
16
+ 通常のファイルか。無い・読めないときは false
17
+ */
18
+ export function isFile(target) {
19
+ try {
20
+ return statSync(target).isFile();
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ //# sourceMappingURL=file-kind.js.map
@@ -0,0 +1,14 @@
1
+ import type { ParsedComment, ParsedIssue, ParsedPullRequest } from '../domain/frontmatter.js';
2
+ /**
3
+ Issue 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
4
+ */
5
+ export declare function parseIssueFile(file: string): ParsedIssue;
6
+ /**
7
+ コメント用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
8
+ */
9
+ export declare function parseCommentFile(file: string): ParsedComment;
10
+ /**
11
+ PR 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
12
+ */
13
+ export declare function parsePullRequestFile(file: string): ParsedPullRequest;
14
+ //# sourceMappingURL=frontmatter-file.d.ts.map
@@ -0,0 +1,30 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側(コマンドの引数)が決める。この層は読むだけ */
2
+ // フロントマター付き Markdown ファイルの読み込み。パースそのものは domain/frontmatter.ts が行う。
3
+ import { existsSync } from 'node:fs';
4
+ import { FrontmatterError, parseCommentContent, parseFrontmatter, parsePullRequestContent } from '../domain/frontmatter.js';
5
+ import { normalizePath } from './paths.js';
6
+ import { readTextFile } from './text-file.js';
7
+ function readFrontmatterFile(file) {
8
+ if (!existsSync(file))
9
+ throw new FrontmatterError(`file not found: ${normalizePath(file)}`);
10
+ return readTextFile(file);
11
+ }
12
+ /**
13
+ Issue 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
14
+ */
15
+ export function parseIssueFile(file) {
16
+ return parseFrontmatter(readFrontmatterFile(file));
17
+ }
18
+ /**
19
+ コメント用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
20
+ */
21
+ export function parseCommentFile(file) {
22
+ return parseCommentContent(readFrontmatterFile(file));
23
+ }
24
+ /**
25
+ PR 用のファイルをパースする。ファイルが無い・パースできないときは FrontmatterError
26
+ */
27
+ export function parsePullRequestFile(file) {
28
+ return parsePullRequestContent(readFrontmatterFile(file));
29
+ }
30
+ //# sourceMappingURL=frontmatter-file.js.map
@@ -0,0 +1,74 @@
1
+ import type { GitResult, GitRunner } from '../domain/git-runner.js';
2
+ import type { RemoteLocation } from '../domain/git-url.js';
3
+ import { BaseError } from '../domain/errors.js';
4
+ export interface GitOptions {
5
+ /**
6
+ 作業ディレクトリ。省略すると呼び出し元の作業ディレクトリ
7
+ */
8
+ readonly cwd?: string | undefined;
9
+ /**
10
+ true なら GIT_* の env を除いて実行する。git のフック内では GIT_DIR 等が設定され、作業ディレクトリの代わりに参照される。
11
+ 作業ディレクトリ基準で解決したいときに使う
12
+ */
13
+ readonly stripGitEnvironment?: boolean | undefined;
14
+ /**
15
+ true なら非 0 終了で GitCommandError を投げる
16
+ */
17
+ readonly check?: boolean | undefined;
18
+ }
19
+ /**
20
+ check 付きの実行が非 0 で終わった(Python の CalledProcessError に当たる)
21
+ */
22
+ export declare class GitCommandError extends BaseError {
23
+ readonly exitCode: number;
24
+ readonly stdout: string;
25
+ readonly stderr: string;
26
+ constructor(arguments_: readonly string[], result: GitResult);
27
+ }
28
+ export declare const MAX_OUTPUT_BYTES: number;
29
+ /**
30
+ git を実行する。標準出力・標準エラーは改行を \n に揃えた文字列で返す。
31
+ git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
32
+ */
33
+ export declare function runGit(arguments_: readonly string[], options?: Readonly<GitOptions>): GitResult;
34
+ /**
35
+ cwd を束ねた GitRunner。domain の関数に渡す。非 0 終了は例外にせず結果で返す
36
+ */
37
+ export declare function gitRunnerFor(cwd?: string, options?: Readonly<Pick<GitOptions, 'stripGitEnvironment'>>): GitRunner;
38
+ /**
39
+ 標準出力を削らずに返す。非 0 終了・git が無いときは undefined
40
+ */
41
+ export declare function gitStdout(arguments_: readonly string[], options?: Readonly<Omit<GitOptions, 'check'>>): string | undefined;
42
+ /**
43
+ git リポジトリ(ワークツリー)のルート。git の外・git が無いときは undefined
44
+ */
45
+ export declare function gitToplevel(options?: Readonly<Pick<GitOptions, 'cwd' | 'stripGitEnvironment'>>): string | undefined;
46
+ /**
47
+ remote の URL。remote が無い・git の外なら undefined
48
+ */
49
+ export declare function gitRemoteUrl(cwd?: string, remote?: string): string | undefined;
50
+ /**
51
+ remote 名の一覧。git の外・git が無いときは undefined
52
+ */
53
+ export declare function listRemotes(cwd?: string): readonly string[] | undefined;
54
+ /**
55
+ 優先順の remote 候補。origin があれば origin だけ、無ければ一覧の順にすべて
56
+ */
57
+ export declare function preferredRemotes(remotes: readonly string[]): readonly string[];
58
+ /**
59
+ 主の remote 名。origin、無ければ最初の remote。remote が無い・git の外なら undefined
60
+ */
61
+ export declare function primaryRemoteName(cwd?: string): string | undefined;
62
+ /**
63
+ 主の remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
64
+ */
65
+ export declare function primaryRemoteRepository(cwd?: string): RemoteLocation | undefined;
66
+ /**
67
+ 現在のブランチ名(detached HEAD では `HEAD`)。git の外なら undefined
68
+ */
69
+ export declare function gitCurrentBranch(cwd?: string): string | undefined;
70
+ /**
71
+ 指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
72
+ */
73
+ export declare function remoteRepository(cwd: string | undefined, remote: string): RemoteLocation | undefined;
74
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1,133 @@
1
+ // git コマンド実行の唯一の窓口。git の subprocess 呼び出しはすべて runGit を経由する。
2
+ // 値を返す helper(gitToplevel 等)は、失敗時に undefined を返す。
3
+ import { spawnSync } from 'node:child_process';
4
+ import { parseRemoteUrl } from '../domain/git-url.js';
5
+ import { BaseError, InvalidValueError } from '../domain/errors.js';
6
+ import { normalizeNewlines, pythonRepr, pythonStrip } from '../domain/python-format.js';
7
+ import { childStdin } from './child-stdin.js';
8
+ import { isFileNotFound, toOsError } from './os-error.js';
9
+ /**
10
+ check 付きの実行が非 0 で終わった(Python の CalledProcessError に当たる)
11
+ */
12
+ export class GitCommandError extends BaseError {
13
+ exitCode;
14
+ stdout;
15
+ stderr;
16
+ constructor(arguments_, result) {
17
+ super(`Command ${pythonRepr(['git', ...arguments_])} returned non-zero exit status ${String(result.exitCode)}.`);
18
+ this.exitCode = result.exitCode;
19
+ this.stdout = result.stdout;
20
+ this.stderr = result.stderr;
21
+ }
22
+ }
23
+ // 出力が大きい git(log・diff 等)でも切れないようにする
24
+ export const MAX_OUTPUT_BYTES = 1024 * 1024 * 1024;
25
+ function withoutGitVariables() {
26
+ // interface-env: none
27
+ return Object.fromEntries(Object.entries(process.env).filter((entry) => entry[1] !== undefined && !entry[0].startsWith('GIT_')));
28
+ }
29
+ /**
30
+ git を実行する。標準出力・標準エラーは改行を \n に揃えた文字列で返す。
31
+ git や作業ディレクトリが見つからなければ OsError(code ENOENT)を投げる
32
+ */
33
+ export function runGit(arguments_, options = {}) {
34
+ const result = spawnSync('git', [...arguments_], {
35
+ cwd: options.cwd,
36
+ env: options.stripGitEnvironment === true ? withoutGitVariables() : undefined,
37
+ encoding: 'utf8',
38
+ maxBuffer: MAX_OUTPUT_BYTES,
39
+ stdio: [childStdin(), 'pipe', 'pipe'],
40
+ });
41
+ if (result.error !== undefined) {
42
+ // spawnSync の ENOENT は path が `git` で入る。cwd が無いときも同じ ENOENT になる
43
+ throw toOsError(result.error);
44
+ }
45
+ const gitResult = { exitCode: result.status ?? -1, stdout: normalizeNewlines(result.stdout), stderr: normalizeNewlines(result.stderr) };
46
+ if (options.check === true && gitResult.exitCode !== 0)
47
+ throw new GitCommandError(arguments_, gitResult);
48
+ return gitResult;
49
+ }
50
+ /**
51
+ cwd を束ねた GitRunner。domain の関数に渡す。非 0 終了は例外にせず結果で返す
52
+ */
53
+ export function gitRunnerFor(cwd, options = {}) {
54
+ return arguments_ => runGit(arguments_, { cwd, stripGitEnvironment: options.stripGitEnvironment });
55
+ }
56
+ /**
57
+ 標準出力を削らずに返す。非 0 終了・git が無いときは undefined
58
+ */
59
+ export function gitStdout(arguments_, options = {}) {
60
+ try {
61
+ return runGit(arguments_, { ...options, check: true }).stdout;
62
+ }
63
+ catch (error) {
64
+ if (error instanceof GitCommandError || isFileNotFound(error))
65
+ return undefined;
66
+ throw error;
67
+ }
68
+ }
69
+ function runForValue(arguments_, options) {
70
+ const stdout = gitStdout(arguments_, options);
71
+ return stdout === undefined ? undefined : pythonStrip(stdout);
72
+ }
73
+ /**
74
+ git リポジトリ(ワークツリー)のルート。git の外・git が無いときは undefined
75
+ */
76
+ export function gitToplevel(options = {}) {
77
+ return runForValue(['rev-parse', '--show-toplevel'], options);
78
+ }
79
+ /**
80
+ remote の URL。remote が無い・git の外なら undefined
81
+ */
82
+ export function gitRemoteUrl(cwd, remote = 'origin') {
83
+ return runForValue(['remote', 'get-url', remote], { cwd });
84
+ }
85
+ /**
86
+ remote 名の一覧。git の外・git が無いときは undefined
87
+ */
88
+ export function listRemotes(cwd) {
89
+ const output = runForValue(['remote'], { cwd });
90
+ return output === undefined ? undefined : output.split('\n').map(line => pythonStrip(line)).filter(line => line !== '');
91
+ }
92
+ /**
93
+ 優先順の remote 候補。origin があれば origin だけ、無ければ一覧の順にすべて
94
+ */
95
+ export function preferredRemotes(remotes) {
96
+ return remotes.includes('origin') ? ['origin'] : remotes;
97
+ }
98
+ /**
99
+ 主の remote 名。origin、無ければ最初の remote。remote が無い・git の外なら undefined
100
+ */
101
+ export function primaryRemoteName(cwd) {
102
+ return preferredRemotes(listRemotes(cwd) ?? [])[0];
103
+ }
104
+ /**
105
+ 主の remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
106
+ */
107
+ export function primaryRemoteRepository(cwd) {
108
+ const name = primaryRemoteName(cwd);
109
+ return name === undefined ? undefined : remoteRepository(cwd, name);
110
+ }
111
+ /**
112
+ 現在のブランチ名(detached HEAD では `HEAD`)。git の外なら undefined
113
+ */
114
+ export function gitCurrentBranch(cwd) {
115
+ return runForValue(['rev-parse', '--abbrev-ref', 'HEAD'], { cwd });
116
+ }
117
+ /**
118
+ 指定した remote の URL から host・owner・repository を返す。remote 不在・git の外・URL 形式の不一致は undefined
119
+ */
120
+ export function remoteRepository(cwd, remote) {
121
+ const url = gitRemoteUrl(cwd, remote);
122
+ if (url === undefined)
123
+ return undefined;
124
+ try {
125
+ return parseRemoteUrl(url);
126
+ }
127
+ catch (error) {
128
+ if (error instanceof InvalidValueError)
129
+ return undefined;
130
+ throw error;
131
+ }
132
+ }
133
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1,60 @@
1
+ import type { JsonObject } from '../../domain/json.js';
2
+ import type { JsonValue } from '../../domain/python-format.js';
3
+ /**
4
+ str(value) と同じ。文字列はそのまま、それ以外は repr
5
+ */
6
+ export declare function pythonString(value: JsonValue): string;
7
+ /**
8
+ 環境変数の値。無ければ undefined。
9
+
10
+ 名前が実行時に決まるので、環境変数の名前を添字で直接書く形では読めない。
11
+ 名前の元は、hosts.json の env_var、ホストから作る `PECOT_GITHUB_<HOST>_TOKEN`、ROOT_ENV_VAR_MAP。
12
+ 環境変数の宣言の確認(.githooks/tests/test_nx_env_inputs.py)は、この読み方を検出できない。
13
+ 宣言できない代わりに、テストが結果をトークンの値に依存させない。
14
+ テストは token を明示して渡すか、トークンの変数を自分で設定する。
15
+ トークンの変数を外す隔離は tests/_helpers/environment.ts の useIsolatedEnvironment が行う。
16
+ */
17
+ export declare function environmentValue(name: string): string | undefined;
18
+ /**
19
+ ホスト設定をロードする(キャッシュ付き)。
20
+ 設定ディレクトリの hosts.json を読む。ファイルが無ければ空の設定。
21
+ 最上位が JSON のオブジェクトでないときは、空の設定として扱う
22
+ */
23
+ export declare function loadHostsConfig(): JsonObject;
24
+ /**
25
+ ホスト設定のキャッシュを捨てる(テスト用)
26
+ */
27
+ export declare function clearHostsConfigCache(): void;
28
+ /**
29
+ ホストの設定(env_var・token_url・description・scopes)。無い、または空のオブジェクトなら undefined
30
+ */
31
+ export declare function getHostConfig(host: string): JsonObject | undefined;
32
+ /**
33
+ hosts.json に定義が無いときの既定の環境変数名。hosts.json.sample・.env.sample と同じ名前。
34
+ hosts.json はリポに含まれないため、Actions などの新しい checkout ではこの名前を使う
35
+ */
36
+ export declare const DEFAULT_ENV_VAR_MAP: ReadonlyMap<string, string>;
37
+ /**
38
+ ホストに対応する環境変数名。hosts.json の定義、既定の対応、`PECOT_GITHUB_<HOST>_TOKEN`(ドットはアンダースコア)の順に使う
39
+ */
40
+ export declare function getEnvironmentVariableName(host: string): string;
41
+ export declare const ROOT_ENV_VAR_MAP: ReadonlyMap<string, string>;
42
+ /**
43
+ 環境変数ファイルを読み、実行中の環境に設定する。Python の load_env_file と同じく環境を書き換える。
44
+ KEY=VALUE 形式で、空行と # で始まる行は飛ばす。既にある環境変数は上書きしない
45
+ */
46
+ export declare function loadEnvironmentFile(file: string): void;
47
+ /**
48
+ トークンの取得先 URL(hosts.json の token_url、無ければ設定画面の URL)
49
+ */
50
+ export declare function tokenUrlFor(host: string): string;
51
+ /**
52
+ hosts.json の scopes。無い、または配列でないときは空
53
+ */
54
+ export declare function scopesFor(host: string): readonly string[];
55
+ /**
56
+ 認証用の .env を生成または更新して、そのパスを返す。
57
+ 無ければ新規作成する。あるときは、ホストの環境変数名が書かれていない場合だけ追記する
58
+ */
59
+ export declare function ensureEnvironmentFile(host: string): string;
60
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1,158 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは設定ディレクトリ配下のファイルと、呼び出し側が渡す .env */
2
+ // GitHub トークン解決に使うホスト設定と .env の読み書き。cli/core/github/auth.py の移植。
3
+ import { appendFileSync, existsSync, writeFileSync } from 'node:fs';
4
+ import path from 'node:path';
5
+ import { InvalidValueError } from '../../domain/errors.js';
6
+ import { isJsonObject, jsonField, parseJsonText } from '../../domain/json.js';
7
+ import { isJsonArray, pythonRepr, pythonStrip, pythonStringRepr } from '../../domain/python-format.js';
8
+ import { configDirectory } from '../config-store.js';
9
+ import { toOsError } from '../os-error.js';
10
+ import { readTextFile } from '../text-file.js';
11
+ /**
12
+ str(value) と同じ。文字列はそのまま、それ以外は repr
13
+ */
14
+ export function pythonString(value) {
15
+ return typeof value === 'string' ? value : pythonRepr(value);
16
+ }
17
+ // ホスト設定のキャッシュ(モジュールレベル)
18
+ const hostsCache = { value: undefined };
19
+ /**
20
+ 環境変数の値。無ければ undefined。
21
+
22
+ 名前が実行時に決まるので、環境変数の名前を添字で直接書く形では読めない。
23
+ 名前の元は、hosts.json の env_var、ホストから作る `PECOT_GITHUB_<HOST>_TOKEN`、ROOT_ENV_VAR_MAP。
24
+ 環境変数の宣言の確認(.githooks/tests/test_nx_env_inputs.py)は、この読み方を検出できない。
25
+ 宣言できない代わりに、テストが結果をトークンの値に依存させない。
26
+ テストは token を明示して渡すか、トークンの変数を自分で設定する。
27
+ トークンの変数を外す隔離は tests/_helpers/environment.ts の useIsolatedEnvironment が行う。
28
+ */
29
+ export function environmentValue(name) {
30
+ // interface-env: PECOT_GITHUB_*_TOKEN GITHUB_COM_TOKEN
31
+ return new Map(Object.entries(process.env)).get(name);
32
+ }
33
+ /**
34
+ ホスト設定をロードする(キャッシュ付き)。
35
+ 設定ディレクトリの hosts.json を読む。ファイルが無ければ空の設定。
36
+ 最上位が JSON のオブジェクトでないときは、空の設定として扱う
37
+ */
38
+ export function loadHostsConfig() {
39
+ if (hostsCache.value !== undefined)
40
+ return hostsCache.value;
41
+ const hostsFile = path.join(configDirectory(), 'hosts.json');
42
+ let loaded = { hosts: {} };
43
+ if (existsSync(hostsFile)) {
44
+ const parsed = parseJsonText(readTextFile(hostsFile));
45
+ loaded = isJsonObject(parsed) ? parsed : {};
46
+ }
47
+ hostsCache.value = loaded;
48
+ return loaded;
49
+ }
50
+ /**
51
+ ホスト設定のキャッシュを捨てる(テスト用)
52
+ */
53
+ export function clearHostsConfigCache() {
54
+ hostsCache.value = undefined;
55
+ }
56
+ /**
57
+ ホストの設定(env_var・token_url・description・scopes)。無い、または空のオブジェクトなら undefined
58
+ */
59
+ export function getHostConfig(host) {
60
+ const hosts = jsonField(loadHostsConfig(), 'hosts');
61
+ const entry = isJsonObject(hosts) ? jsonField(hosts, host) : undefined;
62
+ return isJsonObject(entry) && Object.keys(entry).length > 0 ? entry : undefined;
63
+ }
64
+ // Python の dict の添字参照が KeyError になる所。str(KeyError) と同じ文にする
65
+ function requiredField(config, key) {
66
+ const value = jsonField(config, key);
67
+ if (value === undefined)
68
+ throw new InvalidValueError(pythonStringRepr(key));
69
+ return value;
70
+ }
71
+ /**
72
+ hosts.json に定義が無いときの既定の環境変数名。hosts.json.sample・.env.sample と同じ名前。
73
+ hosts.json はリポに含まれないため、Actions などの新しい checkout ではこの名前を使う
74
+ */
75
+ export const DEFAULT_ENV_VAR_MAP = new Map([
76
+ ['github.com', 'PECOT_GITHUB_COM_TOKEN'],
77
+ ]);
78
+ /**
79
+ ホストに対応する環境変数名。hosts.json の定義、既定の対応、`PECOT_GITHUB_<HOST>_TOKEN`(ドットはアンダースコア)の順に使う
80
+ */
81
+ export function getEnvironmentVariableName(host) {
82
+ const hostConfig = getHostConfig(host);
83
+ return hostConfig === undefined
84
+ ? DEFAULT_ENV_VAR_MAP.get(host) ?? `PECOT_GITHUB_${host.toUpperCase().replaceAll('.', '_')}_TOKEN`
85
+ : pythonString(requiredField(hostConfig, 'env_var'));
86
+ }
87
+ // ルート .env の変数名マッピング(ホスト → ルート .env の変数名)。MCP ラッパーと同じトークンソースを参照するための定義
88
+ export const ROOT_ENV_VAR_MAP = new Map([
89
+ ['github.com', 'GITHUB_COM_TOKEN'],
90
+ ]);
91
+ /**
92
+ 環境変数ファイルを読み、実行中の環境に設定する。Python の load_env_file と同じく環境を書き換える。
93
+ KEY=VALUE 形式で、空行と # で始まる行は飛ばす。既にある環境変数は上書きしない
94
+ */
95
+ export function loadEnvironmentFile(file) {
96
+ if (!existsSync(file))
97
+ return;
98
+ for (const rawLine of readTextFile(file).split('\n')) {
99
+ const line = pythonStrip(rawLine);
100
+ if (line === '' || line.startsWith('#'))
101
+ continue;
102
+ const separator = line.indexOf('=');
103
+ if (separator === -1)
104
+ continue;
105
+ const key = pythonStrip(line.slice(0, separator));
106
+ const value = pythonStrip(line.slice(separator + 1));
107
+ // interface-env: none
108
+ if (key !== '' && !Object.hasOwn(process.env, key))
109
+ Reflect.set(process.env, key, value);
110
+ }
111
+ }
112
+ /**
113
+ トークンの取得先 URL(hosts.json の token_url、無ければ設定画面の URL)
114
+ */
115
+ export function tokenUrlFor(host) {
116
+ const hostConfig = getHostConfig(host);
117
+ return hostConfig === undefined ? `https://${host}/settings/tokens` : pythonString(requiredField(hostConfig, 'token_url'));
118
+ }
119
+ /**
120
+ hosts.json の scopes。無い、または配列でないときは空
121
+ */
122
+ export function scopesFor(host) {
123
+ const hostConfig = getHostConfig(host);
124
+ const scopes = hostConfig === undefined ? undefined : jsonField(hostConfig, 'scopes');
125
+ return isJsonArray(scopes) ? scopes.map(scope => pythonString(scope)) : [];
126
+ }
127
+ function environmentEntry(host) {
128
+ const hostConfig = getHostConfig(host);
129
+ const description = hostConfig === undefined ? host : pythonString(requiredField(hostConfig, 'description'));
130
+ const scopes = scopesFor(host);
131
+ const scopesComment = scopes.length > 0 ? `# 必要なスコープ: ${scopes.join(', ')}` : '';
132
+ return `\n# ${description}\n# 取得先: ${tokenUrlFor(host)}\n${scopesComment}\n${getEnvironmentVariableName(host)}=\n`;
133
+ }
134
+ const ENVIRONMENT_FILE_HEADER = `# pecot-cli 認証設定
135
+ # 各トークンの値を設定してください
136
+ #
137
+ # トークン作成時は必要なスコープを付与してください
138
+ `;
139
+ /**
140
+ 認証用の .env を生成または更新して、そのパスを返す。
141
+ 無ければ新規作成する。あるときは、ホストの環境変数名が書かれていない場合だけ追記する
142
+ */
143
+ export function ensureEnvironmentFile(host) {
144
+ const file = path.join(configDirectory(), '.env');
145
+ const name = getEnvironmentVariableName(host);
146
+ const entry = environmentEntry(host);
147
+ try {
148
+ if (!existsSync(file))
149
+ writeFileSync(file, ENVIRONMENT_FILE_HEADER + entry, 'utf8');
150
+ else if (!readTextFile(file).includes(name))
151
+ appendFileSync(file, entry, 'utf8');
152
+ }
153
+ catch (error) {
154
+ throw toOsError(error);
155
+ }
156
+ return file;
157
+ }
158
+ //# sourceMappingURL=auth.js.map