@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,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
@@ -0,0 +1,178 @@
1
+ import type { JsonObject } from '../../domain/json.js';
2
+ import type { LinkedRepository } from '../../domain/config.js';
3
+ import { BaseError } from '../../domain/errors.js';
4
+ import type { JsonValue } from '../../domain/python-format.js';
5
+ import type { Diagnostics } from '../diagnostics.js';
6
+ /**
7
+ PECOT_GITHUB_API_URL を検証して返す。未設定・空文字なら undefined。
8
+ 前後比較のテストが GitHub の代わりに偽サーバへ向けるための差し替え口。
9
+ ループバックの http URL だけを受け付け、それ以外は InvalidValueError。末尾の `/` は落とす
10
+ */
11
+ export declare function resolveApiUrlOverride(): string | undefined;
12
+ export type HttpMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
13
+ /**
14
+ クエリの値。undefined は Python の None に当たり、`key=` と書く
15
+ */
16
+ export type QueryValue = boolean | number | string | undefined;
17
+ export interface RestRequestOptions {
18
+ readonly params?: Readonly<Record<string, QueryValue>> | undefined;
19
+ /**
20
+ JSON の本文
21
+ */
22
+ readonly json?: JsonValue | undefined;
23
+ /**
24
+ X-GitHub-Api-Version の値。省略すると DEFAULT_API_VERSION
25
+ */
26
+ readonly apiVersion?: string | undefined;
27
+ }
28
+ export declare const DEFAULT_API_VERSION = "2022-11-28";
29
+ /**
30
+ 送信の失敗(接続できない・時間切れ)。Python の httpx の例外に当たり、PecotError ではない
31
+ */
32
+ export declare class TransportFailure extends BaseError {
33
+ }
34
+ export interface HeaderLink {
35
+ readonly url: string;
36
+ readonly rel?: string | undefined;
37
+ }
38
+ /**
39
+ REST の応答。Python の httpx.Response のうち、呼び出し側が使う部分
40
+ */
41
+ export declare class RestResponse {
42
+ private readonly headers;
43
+ readonly statusCode: number;
44
+ readonly statusText: string;
45
+ readonly url: string;
46
+ readonly text: string;
47
+ constructor(init: Readonly<{
48
+ statusCode: number;
49
+ statusText: string;
50
+ url: string;
51
+ text: string;
52
+ headers: ReadonlyMap<string, string>;
53
+ }>);
54
+ /**
55
+ 状態コードが 2xx
56
+ */
57
+ get isSuccess(): boolean;
58
+ /**
59
+ ヘッダの値。名前は大文字小文字を区別しない
60
+ */
61
+ header(name: string): string | undefined;
62
+ /**
63
+ Link ヘッダ。キーは rel(無ければ url)
64
+ */
65
+ get links(): ReadonlyMap<string, HeaderLink>;
66
+ /**
67
+ 本文を JSON として読む。不正なら InvalidValueError
68
+ */
69
+ json(): JsonValue;
70
+ }
71
+ /**
72
+ errors[].path(フィールドの道筋)を受けて、許す errors かを答える
73
+ */
74
+ export type PathPredicate = (path: readonly JsonValue[]) => boolean;
75
+ /**
76
+ executeGraphqlTolerating の結果。data と、許した errors
77
+ */
78
+ export interface GraphqlOutcome {
79
+ readonly data: JsonObject;
80
+ readonly errors: readonly JsonObject[];
81
+ }
82
+ export interface GitHubClientOptions {
83
+ /**
84
+ GitHub のホスト。既定は github.com
85
+ */
86
+ readonly host?: string | undefined;
87
+ /**
88
+ 認証トークン。省略または空なら、config/.env・ルート .env・gh auth token の順で取る
89
+ */
90
+ readonly token?: string | undefined;
91
+ /**
92
+ 1 回の要求の時間切れ(ミリ秒)。既定は 30000
93
+ */
94
+ readonly timeoutMilliseconds?: number | undefined;
95
+ /**
96
+ gh auth token の時間切れ(ミリ秒)。既定は 10000
97
+ */
98
+ readonly ghTimeoutMilliseconds?: number | undefined;
99
+ /**
100
+ 警告の受け口。トークンを切り替えたときの案内を渡す。省略できない(省くと警告が出ない)
101
+ */
102
+ readonly diagnostics: Diagnostics;
103
+ }
104
+ /**
105
+ GitHub API クライアント(REST と GraphQL)。github.com と GHES に対応する。
106
+
107
+ トークンの優先順位は、token の指定、config/.env、ルート .env、gh auth token の順。
108
+ issues・pulls・projects・repos の操作は、次のメソッドを使って作る。
109
+ restJson・restObject・restRequest・handleHttpError・executeGraphql。
110
+ */
111
+ export declare class GitHubClientBase {
112
+ private readonly diagnostics;
113
+ private usedFallback;
114
+ readonly host: string;
115
+ token: string;
116
+ readonly timeoutMilliseconds: number;
117
+ readonly ghTimeoutMilliseconds: number;
118
+ readonly apiUrl: string;
119
+ readonly graphqlUrl: string;
120
+ /**
121
+ プロジェクトにリンクされたリポジトリの一覧のキャッシュ(`owner/projectNumber` がキー)
122
+ */
123
+ readonly linkedRepositoriesCache: Map<string, readonly LinkedRepository[]>;
124
+ constructor(options: Readonly<GitHubClientOptions>);
125
+ private resolveToken;
126
+ private tokenFromEnvironment;
127
+ private tokenFromGh;
128
+ /**
129
+ 認証エラーの文を作る。.env が無ければ生成し、あるときはホストの変数が無ければ追記する
130
+ */
131
+ private authErrorMessage;
132
+ private requestHeaders;
133
+ /**
134
+ env のトークンが失効したとき、gh auth token に 1 回だけ切り替える。切り替えたら true
135
+ */
136
+ private retryWithFallbackToken;
137
+ private send;
138
+ private sendRest;
139
+ private sendGraphql;
140
+ private classifyGraphqlFailure;
141
+ private runGraphql;
142
+ private assertSameOrigin;
143
+ /**
144
+ REST の要求(401 のときは gh auth token に切り替えて 1 回だけ再試行する)。
145
+ target は `/user` のようなパス(base の後ろにつなぐ)か、`https://` で始まる絶対 URL(Link ヘッダの next など)。
146
+ 失敗の状態コードは例外にせず、そのまま返す。呼び出し側が isSuccess を見て handleHttpError に渡す
147
+ */
148
+ restRequest(method: HttpMethod, target: string, options?: Readonly<RestRequestOptions>): Promise<RestResponse>;
149
+ /**
150
+ REST の要求を送り、成功した応答の JSON を返す。失敗の応答は handleHttpError の例外にする。
151
+ 本文が無い応答(204 など)には使わない
152
+ */
153
+ restJson(method: HttpMethod, target: string, options?: Readonly<RestRequestOptions>): Promise<JsonValue>;
154
+ /**
155
+ restJson の結果をオブジェクトとして返す(オブジェクトでなければ空のオブジェクト。Python の as_dict と同じ)
156
+ */
157
+ restObject(method: HttpMethod, target: string, options?: Readonly<RestRequestOptions>): Promise<JsonObject>;
158
+ /**
159
+ HTTP エラーの応答を、状態コード別の例外にして投げる
160
+ */
161
+ handleHttpError(response: RestResponse): never;
162
+ /**
163
+ GraphQL を実行する。失敗は応答の状態コードと errors の type で分類する。
164
+ 状態が 401(または type が UNAUTHORIZED)は GitHubAuthError。gh auth token に 1 回切り替えて再試行する。
165
+ レート制限は GitHubRateLimitError、それ以外は GitHubAPIError
166
+ */
167
+ executeGraphql(query: string, variables?: Readonly<Record<string, JsonValue>>): Promise<JsonObject>;
168
+ /**
169
+ executeGraphql の、部分エラーを許す版。data があり、errors のすべてが isTolerated を満たすとき、例外にせず data と errors を返す。
170
+ それ以外の errors は executeGraphql と同じ例外になる
171
+ */
172
+ executeGraphqlTolerating(query: string, variables: Readonly<Record<string, JsonValue>>, isTolerated: PathPredicate): Promise<GraphqlOutcome>;
173
+ /**
174
+ 認証ユーザーの情報(login・id・name・email など)
175
+ */
176
+ getAuthenticatedUser(): Promise<JsonValue>;
177
+ }
178
+ //# sourceMappingURL=client.d.ts.map