@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,148 @@
1
+ // 出力の文に添える、次に打つコマンドの案内。案内はコマンドの path と入力のデータで持ち、CLI の行か MCP のツールの呼び方にする。
2
+ // コマンドの形(位置引数・入力名)は commands/registry.ts が registerHintCommands で登録する。
3
+ const catalog = new Map();
4
+ export function registerHintCommands(shapes) {
5
+ for (const shape of shapes)
6
+ catalog.set(shape.path.join(' '), shape);
7
+ }
8
+ export function commandHint(path, input = {}) {
9
+ return { kind: 'command', path, input };
10
+ }
11
+ export function inputHint(path, name, value = true) {
12
+ return { kind: 'input', path, name, value };
13
+ }
14
+ /**
15
+ 入力の名前だけの案内。`--host is required` の `--host`
16
+ */
17
+ export function inputNameHint(path, name) {
18
+ return { kind: 'input', path, name, value: undefined };
19
+ }
20
+ /**
21
+ グローバルの repo の案内。value が無ければ名前だけ(CLI は `--repo`、MCP は `repo`)
22
+ */
23
+ export function globalRepositoryHint(value) {
24
+ return { kind: 'global-repo', value };
25
+ }
26
+ export function placeholder(name) {
27
+ return { placeholder: name };
28
+ }
29
+ function isHint(value) {
30
+ return typeof value === 'object' && value !== null && 'kind' in value;
31
+ }
32
+ /**
33
+ タグ付きテンプレートで HintedText を作る。`hinted\`run: ${commandHint(['project', 'init'])}\``
34
+ */
35
+ export function hinted(strings, ...values) {
36
+ return strings.flatMap((text, index) => {
37
+ const value = values.at(index);
38
+ if (index >= values.length)
39
+ return [text];
40
+ return [text, isHint(value) ? value : String(value)];
41
+ });
42
+ }
43
+ /**
44
+ HintedText を連結する。区切りは separator
45
+ */
46
+ export function joinHinted(parts, separator = '\n') {
47
+ return parts.flatMap((part, index) => [...index === 0 ? [] : [separator], ...typeof part === 'string' ? [part] : part]);
48
+ }
49
+ function shapeOf(path) {
50
+ const shape = catalog.get(path.join(' '));
51
+ if (shape === undefined)
52
+ throw new TypeError(`案内のコマンド '${path.join(' ')}' が定義に無い`);
53
+ return shape;
54
+ }
55
+ function assertInput(shape, name) {
56
+ // 自分の --repo を持たないコマンドの repo は、グローバルの --repo
57
+ if (name === 'repo' && !shape.hasOwnRepo)
58
+ return;
59
+ if (!shape.inputs.includes(name))
60
+ throw new TypeError(`案内の入力 '${name}' が '${shape.path.join(' ')}' の定義に無い`);
61
+ }
62
+ function isList(value) {
63
+ return Array.isArray(value);
64
+ }
65
+ function isPlaceholder(value) {
66
+ return typeof value === 'object' && !isList(value);
67
+ }
68
+ // シェルにそのまま渡せない値は、単一引用符で包む
69
+ function cliValue(value) {
70
+ if (typeof value === 'number')
71
+ return String(value);
72
+ if (typeof value === 'object')
73
+ return `<${value.placeholder}>`;
74
+ return /^[\w./:@=+,-]+$/u.test(value) ? value : `'${value.replaceAll('\'', String.raw `'\''`)}'`;
75
+ }
76
+ function mcpValue(value) {
77
+ if (isPlaceholder(value))
78
+ return `<${value.placeholder}>`;
79
+ return typeof value === 'string' || isList(value) ? JSON.stringify(value) : String(value);
80
+ }
81
+ function flagOf(name) {
82
+ return `--${name.replaceAll('_', '-')}`;
83
+ }
84
+ function cliOption(name, value) {
85
+ const flag = flagOf(name);
86
+ if (typeof value === 'boolean') {
87
+ if (!value)
88
+ throw new TypeError(`案内の入力 '${name}' に false は出せない`);
89
+ return [flag];
90
+ }
91
+ return isList(value) ? value.flatMap((item) => [flag, cliValue(item)]) : [flag, cliValue(value)];
92
+ }
93
+ function cliPositional(value) {
94
+ if (typeof value === 'boolean')
95
+ throw new TypeError('位置引数に真偽値は出せない');
96
+ return isList(value) ? value.map((item) => cliValue(item)) : [cliValue(value)];
97
+ }
98
+ function formatCommand(hint, surface) {
99
+ const shape = shapeOf(hint.path);
100
+ const values = new Map(Object.entries(hint.input));
101
+ const names = Object.keys(hint.input);
102
+ for (const name of names)
103
+ assertInput(shape, name);
104
+ const ordered = [...shape.positional.filter(name => names.includes(name)), ...names.filter(name => !shape.positional.includes(name))];
105
+ const valueOf = (name) => values.get(name) ?? '';
106
+ if (surface === 'mcp') {
107
+ const tool = hint.path.join('_');
108
+ return ordered.length === 0 ? tool : `${tool} with ${ordered.map(name => `${name}: ${mcpValue(valueOf(name))}`).join(', ')}`;
109
+ }
110
+ const globalRepository = !shape.hasOwnRepo && names.includes('repo') ? cliOption('repo', valueOf('repo')) : [];
111
+ const words = ordered.filter(name => globalRepository.length === 0 || name !== 'repo').flatMap(name => shape.positional.includes(name) ? cliPositional(valueOf(name)) : cliOption(name, valueOf(name)));
112
+ return ['pecot', ...globalRepository, ...hint.path, ...words].join(' ');
113
+ }
114
+ /**
115
+ 案内 1 つを出し先の形にする。定義に無い path・入力名は TypeError
116
+ */
117
+ export function formatHint(hint, surface) {
118
+ if (hint.kind === 'command')
119
+ return formatCommand(hint, surface);
120
+ if (hint.kind === 'input')
121
+ assertInput(shapeOf(hint.path), hint.name);
122
+ const name = hint.kind === 'input' ? hint.name : 'repo';
123
+ const { value } = hint;
124
+ switch (surface) {
125
+ case 'mcp': {
126
+ return value === undefined ? name : `${name}: ${mcpValue(value)}`;
127
+ }
128
+ case 'cli': {
129
+ return value === undefined ? flagOf(name) : cliOption(name, value).join(' ');
130
+ }
131
+ }
132
+ }
133
+ export function formatHinted(text, surface) {
134
+ return typeof text === 'string' ? text : text.map(part => typeof part === 'string' ? part : formatHint(part, surface)).join('');
135
+ }
136
+ function isHintedText(value) {
137
+ return Array.isArray(value) && value.every((part) => typeof part === 'string' || isHint(part));
138
+ }
139
+ /**
140
+ 例外が持つ案内(hintedText)。最上位はこれを出し先の形で描き直す。無ければ undefined
141
+ */
142
+ export function hintedTextOf(error) {
143
+ if (typeof error !== 'object' || error === null || !('hintedText' in error))
144
+ return undefined;
145
+ const { hintedText } = error;
146
+ return isHintedText(hintedText) ? hintedText : undefined;
147
+ }
148
+ //# sourceMappingURL=command-hint.js.map
@@ -0,0 +1,219 @@
1
+ import { z } from 'zod';
2
+ import { PecotError } from './errors.js';
3
+ import type { JsonValue } from './python-format.js';
4
+ import type { RepositoryReference } from './repository-resolver.js';
5
+ declare const WorkflowStatusSchema: z.ZodEnum<{
6
+ active: "active";
7
+ archived: "archived";
8
+ backlog: "backlog";
9
+ blocked: "blocked";
10
+ in_review: "in_review";
11
+ pending: "pending";
12
+ ready: "ready";
13
+ }>;
14
+ export type WorkflowStatus = z.infer<typeof WorkflowStatusSchema>;
15
+ export declare const WORKFLOW_STATUSES: readonly WorkflowStatus[];
16
+ declare const PrioritySchema: z.ZodEnum<{
17
+ high: "high";
18
+ low: "low";
19
+ medium: "medium";
20
+ }>;
21
+ export type Priority = z.infer<typeof PrioritySchema>;
22
+ export declare const PRIORITIES: readonly Priority[];
23
+ declare const SizeSchema: z.ZodEnum<{
24
+ l: "l";
25
+ m: "m";
26
+ s: "s";
27
+ xs: "xs";
28
+ }>;
29
+ export type Size = z.infer<typeof SizeSchema>;
30
+ export declare const SIZES: readonly Size[];
31
+ export declare function convertToInteger(value: unknown): unknown;
32
+ declare const FieldOptionsSchema: z.ZodReadonly<z.ZodObject<{
33
+ id: z.ZodString;
34
+ options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
35
+ }, z.core.$strip>>;
36
+ declare const PackageSchema: z.ZodReadonly<z.ZodObject<{
37
+ name: z.ZodString;
38
+ changelog: z.ZodString;
39
+ }, z.core.$strip>>;
40
+ declare const ReleaseTypeSchema: z.ZodEnum<{
41
+ multi: "multi";
42
+ nx: "nx";
43
+ single: "single";
44
+ }>;
45
+ export type ReleaseType = z.infer<typeof ReleaseTypeSchema>;
46
+ /**
47
+ release_type の取れる値(single・multi・nx)
48
+ */
49
+ export declare const RELEASE_TYPES: readonly ReleaseType[];
50
+ declare const RepositorySchema: z.ZodReadonly<z.ZodObject<{
51
+ owner: z.ZodString;
52
+ name: z.ZodString;
53
+ develop_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
54
+ release_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
55
+ changelog_file: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
56
+ packages: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
57
+ name: z.ZodString;
58
+ changelog: z.ZodString;
59
+ }, z.core.$strip>>>>>>, z.ZodTransform<readonly Readonly<{
60
+ name: string;
61
+ changelog: string;
62
+ }>[] | undefined, readonly Readonly<{
63
+ name: string;
64
+ changelog: string;
65
+ }>[] | null | undefined>>;
66
+ release_type: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
67
+ multi: "multi";
68
+ nx: "nx";
69
+ single: "single";
70
+ }>>>, z.ZodTransform<"multi" | "nx" | "single" | undefined, "multi" | "nx" | "single" | null | undefined>>;
71
+ }, z.core.$strip>>;
72
+ declare const ProjectConfigSchema: z.ZodReadonly<z.ZodObject<{
73
+ host: z.ZodString;
74
+ owner: z.ZodString;
75
+ workflow_suffix: z.ZodString;
76
+ project: z.ZodReadonly<z.ZodObject<{
77
+ number: z.ZodPreprocess<z.ZodInt, unknown>;
78
+ id: z.ZodString;
79
+ board_url: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
80
+ fields: z.ZodReadonly<z.ZodObject<{
81
+ workflow: z.ZodReadonly<z.ZodObject<{
82
+ id: z.ZodString;
83
+ options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
84
+ }, z.core.$strip>>;
85
+ priority: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
86
+ id: z.ZodString;
87
+ options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
88
+ }, z.core.$strip>>>>, z.ZodTransform<Readonly<{
89
+ id: string;
90
+ options: Readonly<Record<string, string>>;
91
+ }> | undefined, Readonly<{
92
+ id: string;
93
+ options: Readonly<Record<string, string>>;
94
+ }> | null | undefined>>;
95
+ size: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
96
+ id: z.ZodString;
97
+ options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
98
+ }, z.core.$strip>>>>, z.ZodTransform<Readonly<{
99
+ id: string;
100
+ options: Readonly<Record<string, string>>;
101
+ }> | undefined, Readonly<{
102
+ id: string;
103
+ options: Readonly<Record<string, string>>;
104
+ }> | null | undefined>>;
105
+ status: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodObject<{
106
+ id: z.ZodString;
107
+ options: z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>;
108
+ }, z.core.$strip>>>>, z.ZodTransform<Readonly<{
109
+ id: string;
110
+ options: Readonly<Record<string, string>>;
111
+ }> | undefined, Readonly<{
112
+ id: string;
113
+ options: Readonly<Record<string, string>>;
114
+ }> | null | undefined>>;
115
+ }, z.core.$strip>>;
116
+ }, z.core.$strip>>;
117
+ repositories: z.ZodDefault<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
118
+ owner: z.ZodString;
119
+ name: z.ZodString;
120
+ develop_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
121
+ release_branch: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
122
+ changelog_file: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
123
+ packages: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
124
+ name: z.ZodString;
125
+ changelog: z.ZodString;
126
+ }, z.core.$strip>>>>>>, z.ZodTransform<readonly Readonly<{
127
+ name: string;
128
+ changelog: string;
129
+ }>[] | undefined, readonly Readonly<{
130
+ name: string;
131
+ changelog: string;
132
+ }>[] | null | undefined>>;
133
+ release_type: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
134
+ multi: "multi";
135
+ nx: "nx";
136
+ single: "single";
137
+ }>>>, z.ZodTransform<"multi" | "nx" | "single" | undefined, "multi" | "nx" | "single" | null | undefined>>;
138
+ }, z.core.$strip>>>>>;
139
+ aggregation_repo: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | undefined, string | null | undefined>>;
140
+ }, z.core.$strip>>;
141
+ export type FieldOptions = z.infer<typeof FieldOptionsSchema>;
142
+ export type Package = z.infer<typeof PackageSchema>;
143
+ export type Repository = z.infer<typeof RepositorySchema>;
144
+ export type ProjectConfig = z.infer<typeof ProjectConfigSchema>;
145
+ /**
146
+ プロジェクトにリンクされたリポジトリ。判定の問い合わせ先(GitHub)の実体は infra が持つ
147
+ */
148
+ export interface LinkedRepository {
149
+ readonly owner: string;
150
+ readonly name: string;
151
+ }
152
+ export interface RepositoryMembership {
153
+ readonly linkedRepositories: (owner: string, projectNumber: number) => Promise<readonly LinkedRepository[]>;
154
+ }
155
+ export declare class ConfigError extends PecotError {
156
+ }
157
+ export declare class MultipleConfigsError extends ConfigError {
158
+ readonly files: readonly string[];
159
+ constructor(files: readonly string[]);
160
+ }
161
+ /**
162
+ JSON の値からプロジェクト設定を作る。形が不正なら ValidationFailure(表題は ProjectConfig)
163
+ */
164
+ export declare function parseProjectConfig(data: JsonValue): ProjectConfig;
165
+ /**
166
+ パッケージ 1 件を作る。NAME の形が不正なら ValidationFailure(表題は Package)。保存より前の検証で使う
167
+ */
168
+ export declare function parsePackage(data: JsonValue): Package;
169
+ /**
170
+ 設定ファイルの中身。2 スペースのインデントで、末尾に改行を置く。
171
+ 値の無い項目は出さず、非 ASCII の文字はそのまま出す。
172
+ キーの順はモデルの定義順
173
+ */
174
+ export declare function serializeProjectConfig(config: ProjectConfig): string;
175
+ export declare function workflowFieldName(config: ProjectConfig): string;
176
+ export declare function getFieldId(config: ProjectConfig, fieldName: string): string | undefined;
177
+ export declare function getOptionId(config: ProjectConfig, fieldName: string, optionName: string): string | undefined;
178
+ export declare function findRepository(config: ProjectConfig, owner: string, name: string): Repository | undefined;
179
+ /**
180
+ owner を指定せずに名前だけで探す(アクティブ設定内の検索用)
181
+ */
182
+ export declare function findRepositoryByName(config: ProjectConfig, name: string): Repository | undefined;
183
+ /**
184
+ 設定の repositories の 1 件の `owner/name`
185
+ */
186
+ export declare function configuredRepositoryFullName(repository: Repository): string;
187
+ export declare function findPackage(repository: Repository, name: string): Package | undefined;
188
+ /**
189
+ release_type が未指定なら、packages の有無から決める(あれば multi、無ければ single)
190
+ */
191
+ export declare function effectiveReleaseType(repository: Repository): ReleaseType;
192
+ export declare function getDevelopBranch(config: ProjectConfig, owner: string, name: string): string | undefined;
193
+ export declare function getReleaseBranch(config: ProjectConfig, owner: string, name: string): string | undefined;
194
+ /**
195
+ aggregation_repo を RepositoryReference にする(未設定なら undefined)
196
+ */
197
+ export declare function aggregationRepositoryReference(config: ProjectConfig): RepositoryReference | undefined;
198
+ /**
199
+ Issue の表記で `#N` だけにするリポジトリ。repository(owner/repo)があればそれ、無ければ設定の最初のリポジトリ
200
+ */
201
+ export declare function homeRepositoryOf(config: ProjectConfig, repository?: string): RepositoryReference | undefined;
202
+ /**
203
+ リポジトリがプロジェクトにリンクされているか。リンクの一覧は membership に問い合わせる
204
+ */
205
+ export declare function isRepositoryInProject(config: ProjectConfig, owner: string, name: string, membership: RepositoryMembership): Promise<boolean>;
206
+ /**
207
+ aggregation_repo を差し替えたコピー。undefined なら外す。値の形式は検証しない(呼び出し側が先に検証する)
208
+ */
209
+ export declare function withAggregationRepository(config: ProjectConfig, value: string | undefined): ProjectConfig;
210
+ /**
211
+ リポジトリを末尾に足したコピー
212
+ */
213
+ export declare function withRepositoryAppended(config: ProjectConfig, repository: Repository): ProjectConfig;
214
+ /**
215
+ 同じ owner と name のリポジトリのうち、最初の 1 件を差し替えたコピー(find_repository と同じ)。無ければ元のまま
216
+ */
217
+ export declare function withRepositoryReplaced(config: ProjectConfig, repository: Repository): ProjectConfig;
218
+ export {};
219
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1,310 @@
1
+ // プロジェクト設定(.pecot/config/projects/*.json)のモデルと判定。ファイルの読み書きは infra/config-store.ts が行う。
2
+ //
3
+ // モデルは zod の schema で表す。読んだ値は読み取り専用(凍結)で、更新はコピーを作る。
4
+ // 検証エラーは、Python の CLI が出していた書式(表題は元のクラス名)の ValidationFailure にして投げる。
5
+ // 値が無いこと(null・未指定)は、読んだ後はどちらも undefined になり、保存では出さない。
6
+ import { z } from 'zod';
7
+ import { PecotError } from './errors.js';
8
+ import { isJsonObject, jsonField } from './json.js';
9
+ import { isJsonArray, pythonRepr, pythonStrip, pythonStringRepr, ValidationFailure } from './python-format.js';
10
+ import { parseOwnerRepository, splitOwnerRepository } from './repository-resolver.js';
11
+ const WorkflowStatusSchema = z.enum(['backlog', 'pending', 'blocked', 'ready', 'active', 'in_review', 'archived']);
12
+ export const WORKFLOW_STATUSES = WorkflowStatusSchema.options;
13
+ const PrioritySchema = z.enum(['high', 'medium', 'low']);
14
+ export const PRIORITIES = PrioritySchema.options;
15
+ const SizeSchema = z.enum(['xs', 's', 'm', 'l']);
16
+ export const SIZES = SizeSchema.options;
17
+ const NAME_PATTERN = /^[\w.-]+$/u;
18
+ // zod が issue に入れる pattern(`/source/flags`)→ Python の文に出す正規表現の文字列
19
+ const PYTHON_PATTERN_TEXTS = new Map([[String(NAME_PATTERN), '^[A-Za-z0-9_.-]+$']]);
20
+ const AGGREGATION_REPOSITORY_PATTERN = /^[\w.-]+\/[\w.-]+$/u;
21
+ /**
22
+ オブジェクトの schema。型が違うときの issue の message に、元のクラス名を入れる
23
+ */
24
+ function model(name, shape) {
25
+ return z.object(shape, { error: () => name });
26
+ }
27
+ /**
28
+ `X | None = None` に当たる文字列。null と未指定は、どちらも undefined にする
29
+ */
30
+ const optionalString = z.string().nullish().transform(value => value ?? undefined);
31
+ // int の lax な変換。bool は 0・1、前後の空白・符号・数字の間の `_`・小数部が 0 だけの文字列は整数にする。
32
+ // 変換できない値はそのまま渡し、z.int() が型の誤りにする。
33
+ export function convertToInteger(value) {
34
+ if (typeof value === 'boolean')
35
+ return value ? 1 : 0;
36
+ if (typeof value !== 'string')
37
+ return value;
38
+ const text = pythonStrip(value);
39
+ const isUnderscoreSeparatedDigits = text.replace(/^[+-]/u, '').split('_').every(group => /^\d+$/u.test(group));
40
+ if (isUnderscoreSeparatedDigits)
41
+ return Number(text.replaceAll('_', ''));
42
+ if (/^[+-]?\d+\.0+$/u.test(text))
43
+ return Number(text.slice(0, text.indexOf('.'))) + 0; // -0 を 0 にする
44
+ return value;
45
+ }
46
+ const laxInteger = z.preprocess(convertToInteger, z.int());
47
+ const FieldOptionsSchema = model('FieldOptions', {
48
+ id: z.string(),
49
+ options: z.record(z.string(), z.string()).readonly(),
50
+ }).readonly();
51
+ const ProjectFieldsSchema = model('ProjectFields', {
52
+ workflow: FieldOptionsSchema,
53
+ priority: FieldOptionsSchema.nullish().transform(value => value ?? undefined),
54
+ size: FieldOptionsSchema.nullish().transform(value => value ?? undefined),
55
+ status: FieldOptionsSchema.nullish().transform(value => value ?? undefined),
56
+ }).readonly();
57
+ const ProjectSchema = model('Project', {
58
+ number: laxInteger,
59
+ id: z.string(),
60
+ board_url: optionalString,
61
+ fields: ProjectFieldsSchema,
62
+ }).readonly();
63
+ const PackageSchema = model('Package', {
64
+ name: z.string().min(1, { abort: true }).regex(NAME_PATTERN),
65
+ changelog: z.string().min(1),
66
+ }).readonly();
67
+ const ReleaseTypeSchema = z.enum(['single', 'multi', 'nx']);
68
+ /**
69
+ release_type の取れる値(single・multi・nx)
70
+ */
71
+ export const RELEASE_TYPES = ReleaseTypeSchema.options;
72
+ const RepositorySchema = model('Repository', {
73
+ owner: z.string(),
74
+ name: z.string(),
75
+ develop_branch: optionalString,
76
+ release_branch: optionalString,
77
+ changelog_file: optionalString,
78
+ packages: z.array(PackageSchema).readonly().nullish().transform(value => value ?? undefined),
79
+ release_type: ReleaseTypeSchema.nullish().transform(value => value ?? undefined),
80
+ }).superRefine((repository, context) => {
81
+ // monorepo 構成(packages あり)では CHANGELOG は package ごとに管理するので、リポ全体の changelog_file は意味を持たない
82
+ const hasPackages = repository.packages !== undefined && repository.packages.length > 0;
83
+ if (hasPackages && repository.changelog_file !== undefined && repository.changelog_file !== '') {
84
+ context.addIssue({
85
+ code: 'custom',
86
+ message: 'Value error, changelog_file and packages cannot be set together; in a monorepo, use packages[].changelog instead',
87
+ params: { type: 'value_error' },
88
+ });
89
+ }
90
+ }).readonly();
91
+ const ProjectConfigSchema = model('ProjectConfig', {
92
+ host: z.string(),
93
+ owner: z.string(),
94
+ workflow_suffix: z.string(),
95
+ project: ProjectSchema,
96
+ repositories: z.array(RepositorySchema).readonly().default([]),
97
+ aggregation_repo: z.string().superRefine((value, context) => {
98
+ if (!AGGREGATION_REPOSITORY_PATTERN.test(value)) {
99
+ context.addIssue({
100
+ code: 'custom',
101
+ message: `Value error, aggregation_repo must be in 'owner/repo' form: ${pythonStringRepr(value)}`,
102
+ params: { type: 'value_error' },
103
+ });
104
+ }
105
+ }).nullish().transform(value => value ?? undefined),
106
+ }).readonly();
107
+ export class ConfigError extends PecotError {
108
+ }
109
+ export class MultipleConfigsError extends ConfigError {
110
+ files;
111
+ constructor(files) {
112
+ const names = files.map(file => file.slice(file.lastIndexOf('/') + 1));
113
+ super(`multiple config files found: ${pythonRepr(names)}`);
114
+ this.files = files;
115
+ }
116
+ }
117
+ // 検証エラーの変換
118
+ function valueAt(root, location) {
119
+ let current = root;
120
+ for (const key of location) {
121
+ if (isJsonArray(current))
122
+ current = current[Number(key)];
123
+ else if (isJsonObject(current))
124
+ current = jsonField(current, String(key));
125
+ else
126
+ return undefined;
127
+ }
128
+ return current;
129
+ }
130
+ function quotedChoices(values) {
131
+ const quoted = values.map(value => pythonStringRepr(String(value)));
132
+ const last = quoted.at(-1);
133
+ return last === undefined || quoted.length <= 1 ? quoted.join('') : `${quoted.slice(0, -1).join(', ')} or ${last}`;
134
+ }
135
+ function integerIssue(input) {
136
+ if (typeof input === 'string')
137
+ return { type: 'int_parsing', message: 'Input should be a valid integer, unable to parse string as an integer' };
138
+ if (typeof input !== 'number')
139
+ return { type: 'int_type', message: 'Input should be a valid integer' };
140
+ if (!Number.isFinite(input))
141
+ return { type: 'finite_number', message: 'Input should be a finite number' };
142
+ return { type: 'int_from_float', message: 'Input should be a valid integer, got a number with a fractional part' };
143
+ }
144
+ function invalidTypeIssue(expected, modelName, location, input) {
145
+ if (input === undefined)
146
+ return { type: 'missing', location, message: 'Field required', input: undefined };
147
+ if (expected === 'string')
148
+ return { type: 'string_type', location, message: 'Input should be a valid string', input };
149
+ if (expected === 'int' || expected === 'number')
150
+ return { ...integerIssue(input), location, input };
151
+ if (expected === 'array')
152
+ return { type: 'list_type', location, message: 'Input should be a valid list', input };
153
+ if (expected === 'record')
154
+ return { type: 'dict_type', location, message: 'Input should be a valid dictionary', input };
155
+ return { type: 'model_type', location, message: `Input should be a valid dictionary or instance of ${modelName}`, input };
156
+ }
157
+ function toValidationIssue(issue, root) {
158
+ const location = issue.path.map(key => typeof key === 'symbol' ? String(key) : key);
159
+ const input = valueAt(root, location);
160
+ if (issue.code === 'invalid_type') {
161
+ // 値が無いときの input は、その項目を持つはずの親(Python の入力辞書)
162
+ const base = invalidTypeIssue(issue.expected, issue.message, location, input);
163
+ return base.type === 'missing' ? { ...base, input: valueAt(root, location.slice(0, -1)) } : base;
164
+ }
165
+ if (issue.code === 'invalid_value')
166
+ return { type: 'literal_error', location, message: `Input should be ${quotedChoices(issue.values ?? [])}`, input };
167
+ if (issue.code === 'too_small') {
168
+ const minimum = Number(issue.minimum);
169
+ return { type: 'string_too_short', location, message: `String should have at least ${String(minimum)} character${minimum === 1 ? '' : 's'}`, input };
170
+ }
171
+ if (issue.code === 'invalid_format') {
172
+ // Python の文には、Python 側の正規表現の書き方(lint が書き換える前の形)がそのまま入る
173
+ const pattern = PYTHON_PATTERN_TEXTS.get(String(issue.pattern)) ?? String(issue.pattern);
174
+ return { type: 'string_pattern_mismatch', location, message: `String should match pattern ${pythonStringRepr(pattern)}`, input };
175
+ }
176
+ return { type: 'value_error', location, message: issue.message, input };
177
+ }
178
+ /**
179
+ JSON の値からプロジェクト設定を作る。形が不正なら ValidationFailure(表題は ProjectConfig)
180
+ */
181
+ export function parseProjectConfig(data) {
182
+ const result = ProjectConfigSchema.safeParse(data);
183
+ if (!result.success)
184
+ throw new ValidationFailure('ProjectConfig', result.error.issues.map(issue => toValidationIssue(issue, data)));
185
+ return result.data;
186
+ }
187
+ /**
188
+ パッケージ 1 件を作る。NAME の形が不正なら ValidationFailure(表題は Package)。保存より前の検証で使う
189
+ */
190
+ export function parsePackage(data) {
191
+ const result = PackageSchema.safeParse(data);
192
+ if (!result.success)
193
+ throw new ValidationFailure('Package', result.error.issues.map(issue => toValidationIssue(issue, data)));
194
+ return result.data;
195
+ }
196
+ /**
197
+ 設定ファイルの中身。2 スペースのインデントで、末尾に改行を置く。
198
+ 値の無い項目は出さず、非 ASCII の文字はそのまま出す。
199
+ キーの順はモデルの定義順
200
+ */
201
+ export function serializeProjectConfig(config) {
202
+ return `${JSON.stringify(config, undefined, 2)}\n`;
203
+ }
204
+ // 検索
205
+ export function workflowFieldName(config) {
206
+ return `pecot-workflow-${config.workflow_suffix}`;
207
+ }
208
+ function fieldOf(config, fieldName) {
209
+ switch (fieldName) {
210
+ case 'workflow': {
211
+ return config.project.fields.workflow;
212
+ }
213
+ case 'priority': {
214
+ return config.project.fields.priority;
215
+ }
216
+ case 'size': {
217
+ return config.project.fields.size;
218
+ }
219
+ case 'status': {
220
+ return config.project.fields.status;
221
+ }
222
+ default: {
223
+ return undefined;
224
+ }
225
+ }
226
+ }
227
+ export function getFieldId(config, fieldName) {
228
+ return fieldOf(config, fieldName)?.id;
229
+ }
230
+ export function getOptionId(config, fieldName, optionName) {
231
+ const options = fieldOf(config, fieldName)?.options;
232
+ return options === undefined ? undefined : new Map(Object.entries(options)).get(optionName);
233
+ }
234
+ export function findRepository(config, owner, name) {
235
+ return config.repositories.find(repository => repository.owner === owner && repository.name === name);
236
+ }
237
+ /**
238
+ owner を指定せずに名前だけで探す(アクティブ設定内の検索用)
239
+ */
240
+ export function findRepositoryByName(config, name) {
241
+ return config.repositories.find(repository => repository.name === name);
242
+ }
243
+ /**
244
+ 設定の repositories の 1 件の `owner/name`
245
+ */
246
+ export function configuredRepositoryFullName(repository) {
247
+ return `${repository.owner}/${repository.name}`;
248
+ }
249
+ export function findPackage(repository, name) {
250
+ return repository.packages?.find(item => item.name === name);
251
+ }
252
+ /**
253
+ release_type が未指定なら、packages の有無から決める(あれば multi、無ければ single)
254
+ */
255
+ export function effectiveReleaseType(repository) {
256
+ if (repository.release_type !== undefined)
257
+ return repository.release_type;
258
+ return repository.packages !== undefined && repository.packages.length > 0 ? 'multi' : 'single';
259
+ }
260
+ export function getDevelopBranch(config, owner, name) {
261
+ return findRepository(config, owner, name)?.develop_branch;
262
+ }
263
+ export function getReleaseBranch(config, owner, name) {
264
+ return findRepository(config, owner, name)?.release_branch;
265
+ }
266
+ /**
267
+ aggregation_repo を RepositoryReference にする(未設定なら undefined)
268
+ */
269
+ export function aggregationRepositoryReference(config) {
270
+ return config.aggregation_repo === undefined || config.aggregation_repo === '' ? undefined : parseOwnerRepository(config.aggregation_repo);
271
+ }
272
+ /**
273
+ Issue の表記で `#N` だけにするリポジトリ。repository(owner/repo)があればそれ、無ければ設定の最初のリポジトリ
274
+ */
275
+ export function homeRepositoryOf(config, repository = '') {
276
+ const split = splitOwnerRepository(repository);
277
+ if (split !== undefined)
278
+ return split;
279
+ const [first] = config.repositories;
280
+ return first === undefined ? undefined : { owner: first.owner, repository: first.name };
281
+ }
282
+ /**
283
+ リポジトリがプロジェクトにリンクされているか。リンクの一覧は membership に問い合わせる
284
+ */
285
+ export async function isRepositoryInProject(config, owner, name, membership) {
286
+ const linked = await membership.linkedRepositories(config.owner, config.project.number);
287
+ return linked.some(repository => repository.owner === owner && repository.name === name);
288
+ }
289
+ // 更新(コピーを作る)
290
+ /**
291
+ aggregation_repo を差し替えたコピー。undefined なら外す。値の形式は検証しない(呼び出し側が先に検証する)
292
+ */
293
+ export function withAggregationRepository(config, value) {
294
+ return Object.freeze({ ...config, aggregation_repo: value });
295
+ }
296
+ /**
297
+ リポジトリを末尾に足したコピー
298
+ */
299
+ export function withRepositoryAppended(config, repository) {
300
+ return Object.freeze({ ...config, repositories: Object.freeze([...config.repositories, repository]) });
301
+ }
302
+ /**
303
+ 同じ owner と name のリポジトリのうち、最初の 1 件を差し替えたコピー(find_repository と同じ)。無ければ元のまま
304
+ */
305
+ export function withRepositoryReplaced(config, repository) {
306
+ const index = config.repositories.findIndex(item => item.owner === repository.owner && item.name === repository.name);
307
+ const replaced = config.repositories.map((item, position) => position === index ? repository : item);
308
+ return Object.freeze({ ...config, repositories: Object.freeze(replaced) });
309
+ }
310
+ //# sourceMappingURL=config.js.map