@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,101 @@
1
+ // issue block / unblock の判断(付ける・変える・何もしない・外す)と、輪の探索。I/O は引数の関数で受ける。
2
+ import { InvalidValueError } from './errors.js';
3
+ import { readWaitsForMerge, removeWaitsForMerge, upsertWaitsForMerge } from './prerequisites.js';
4
+ import { displayReference } from './readiness.js';
5
+ import { issueReferenceKey } from './reference-parser.js';
6
+ function nextBody(input, hasLine, currentReason) {
7
+ const { body, home, by, wait, reason = '' } = input;
8
+ if (wait === 'stack')
9
+ return hasLine ? removeWaitsForMerge(body, home, by) : body;
10
+ const trimmed = reason.trim();
11
+ if (trimmed === '')
12
+ throw new InvalidValueError('reason is required with wait: merge');
13
+ return hasLine && currentReason === trimmed ? body : upsertWaitsForMerge(body, home, by, trimmed);
14
+ }
15
+ /**
16
+ 付ける・種類を変える・何もしないのどれにするかと、書く本文を決める。
17
+ 節が読めないときは本文を書き換えられないので malformed を返す
18
+ */
19
+ export function decideBlock(input) {
20
+ const section = readWaitsForMerge(input.body, input.home);
21
+ if (section.kind === 'malformed')
22
+ return { kind: 'malformed', reason: section.reason };
23
+ const key = issueReferenceKey(input.by);
24
+ const line = section.kind === 'ok' ? section.lines.find(candidate => issueReferenceKey(candidate.ref) === key) : undefined;
25
+ const body = nextBody(input, line !== undefined, line?.reason);
26
+ if (!input.isLinked)
27
+ return { kind: 'add', body };
28
+ return body === input.body ? { kind: 'unchanged' } : { kind: 'update', body };
29
+ }
30
+ /**
31
+ 外すか何もしないかを決める。付いていなければ、節に古い行が残っていても本文は書き換えない
32
+ */
33
+ export function decideUnblock(input) {
34
+ if (!input.isLinked)
35
+ return { kind: 'unchanged' };
36
+ const section = readWaitsForMerge(input.body, input.home);
37
+ return section.kind === 'malformed'
38
+ ? { kind: 'remove', body: input.body, malformedReason: section.reason }
39
+ : { kind: 'remove', body: removeWaitsForMerge(input.body, input.home, input.by), malformedReason: undefined };
40
+ }
41
+ function pathTo(visited, key) {
42
+ const chain = [];
43
+ for (let current = visited.get(key); current !== undefined; current = current.parentKey === undefined ? undefined : visited.get(current.parentKey)) {
44
+ chain.unshift(current.ref);
45
+ }
46
+ return chain;
47
+ }
48
+ /**
49
+ by から blocked by を 1 段ずつたどり、target に戻れば輪として道(target → by → … → target)を返す。
50
+ 読めない Issue・件数の不足・上限は unverifiable。GitHub は 3 つ以上の輪を通すので、確かめずに付けない
51
+ */
52
+ export async function searchCycle(input) {
53
+ const { target, by, read, limit } = input;
54
+ const targetKey = issueReferenceKey(target);
55
+ const byKey = issueReferenceKey(by);
56
+ const visited = new Map([[byKey, { ref: by, parentKey: undefined }]]);
57
+ let frontier = [{ id: input.byId, ref: by }];
58
+ while (frontier.length > 0) {
59
+ const results = await read(frontier.map(({ id }) => id));
60
+ const next = [];
61
+ for (const node of frontier) {
62
+ const result = results.get(node.id);
63
+ const label = displayReference(node.ref, target.repository);
64
+ if (result === undefined || result.kind === 'read-failed') {
65
+ return { kind: 'unverifiable', reason: `could not read blocked-by of ${label}: ${result?.reason ?? 'no result'}` };
66
+ }
67
+ if (result.total > result.issues.length) {
68
+ return { kind: 'unverifiable', reason: `blocked-by of ${label} has ${String(result.total)} issues, more than can be read` };
69
+ }
70
+ const nodeKey = issueReferenceKey(node.ref);
71
+ for (const issue of result.issues) {
72
+ const reference = { repository: issue.repository, number: issue.number };
73
+ const key = issueReferenceKey(reference);
74
+ if (key === targetKey)
75
+ return { kind: 'cycle', path: [target, ...pathTo(visited, nodeKey), target] };
76
+ if (visited.has(key))
77
+ continue;
78
+ if (visited.size >= limit)
79
+ return { kind: 'unverifiable', reason: `more than ${String(limit)} issues in the blocked-by chain` };
80
+ visited.set(key, { ref: reference, parentKey: nodeKey });
81
+ next.push({ id: issue.id, ref: reference });
82
+ }
83
+ }
84
+ frontier = next;
85
+ }
86
+ return { kind: 'none' };
87
+ }
88
+ /**
89
+ 書いた後の読み直しが、書いた内容と一致するか。GitHub は書いた直後の読み取りの一致を保証しない
90
+ */
91
+ export function hasExpectedPrerequisites(prerequisites, expected) {
92
+ const keys = new Set(prerequisites.map(({ issue }) => issueReferenceKey(issue.ref)));
93
+ if (keys.size !== expected.keys.size || [...keys].some(key => !expected.keys.has(key)))
94
+ return false;
95
+ if (expected.wait === undefined)
96
+ return true;
97
+ const byKey = issueReferenceKey(expected.by);
98
+ const found = prerequisites.find(({ issue }) => issueReferenceKey(issue.ref) === byKey);
99
+ return found?.wait === expected.wait.wait && (found.wait === 'stack' || found.reason === expected.wait.reason);
100
+ }
101
+ //# sourceMappingURL=blocked-by-change.js.map
@@ -0,0 +1,90 @@
1
+ import type { Readiness } from './readiness.js';
2
+ import type { IssueReference } from './reference-parser.js';
3
+ export type MovableColumn = 'Ready' | 'Blocked';
4
+ export type LabelValue = 'Needs Attention' | 'Todo';
5
+ export type MissingValue = 'Blocked' | 'Needs Attention' | 'Todo';
6
+ /**
7
+ 進行の欄(列)の表示名と設定のキー(`workflow.options.<key>`)の対応
8
+ */
9
+ export declare const COLUMN_CONFIG_KEYS: {
10
+ Blocked: string;
11
+ 'In Review': string;
12
+ Ready: string;
13
+ };
14
+ /**
15
+ 札(Status)の表示名と設定のキー(`status.options.<key>`)の対応
16
+ */
17
+ export declare const LABEL_CONFIG_KEYS: {
18
+ 'Needs Attention': string;
19
+ Todo: string;
20
+ };
21
+ export interface BoardMoveInput {
22
+ /**
23
+ open で、着手の対象(kind が task)か。偽なら何も返さない
24
+ */
25
+ readonly eligible: boolean;
26
+ /**
27
+ 今の列の表示名。ボードに無ければ undefined
28
+ */
29
+ readonly column: string | undefined;
30
+ /**
31
+ 今の札(Status の表示名)。無ければ undefined
32
+ */
33
+ readonly label: string | undefined;
34
+ /**
35
+ 着手の跡(ブランチか PR)がある
36
+ */
37
+ readonly hasStarted: boolean;
38
+ /**
39
+ 前提を 1 つ以上持つ
40
+ */
41
+ readonly hasPrerequisites: boolean;
42
+ /**
43
+ 着手の可否の判定。読めないときは undefined(何も返さない)
44
+ */
45
+ readonly readiness: Readiness | undefined;
46
+ /**
47
+ 今の札を自動処理(spec 023)が書いた
48
+ */
49
+ readonly labelWrittenByAutomation: boolean;
50
+ /**
51
+ ボードにある値
52
+ */
53
+ readonly available: {
54
+ readonly blocked: boolean;
55
+ readonly needsAttention: boolean;
56
+ readonly todo: boolean;
57
+ };
58
+ }
59
+ export interface BoardMove {
60
+ readonly column?: {
61
+ readonly from: string;
62
+ readonly to: MovableColumn;
63
+ /**
64
+ 動かす理由の判定。文は describeReadiness で作る
65
+ */
66
+ readonly reason: Readiness;
67
+ };
68
+ readonly label?: LabelValue;
69
+ /**
70
+ 着手の跡があるのに判定が blocked の食い違い
71
+ */
72
+ readonly conflict?: {
73
+ readonly column: string;
74
+ /**
75
+ blocked の理由に当たった Issue
76
+ */
77
+ readonly issues: readonly IssueReference[];
78
+ };
79
+ /**
80
+ 動かす先の値がボードに無く、動かせなかったもの
81
+ */
82
+ readonly missing: readonly MissingValue[];
83
+ }
84
+ /**
85
+ data-model.md の 6 の 2 つの表を当てはめる。
86
+ 対象でない・ボードに無い・判定が読めないときは undefined を返す。
87
+ 動かす先の値がボードに無いときは動かさず、missing に入れる
88
+ */
89
+ export declare function decideBoardMove(input: BoardMoveInput): BoardMove | undefined;
90
+ //# sourceMappingURL=board-move.d.ts.map
@@ -0,0 +1,92 @@
1
+ // 列と札を直す判断(specs/024 の data-model.md の 6)。I/O を持たない純関数だけを置く。
2
+ import { NEEDS_ATTENTION_LABEL } from './readiness.js';
3
+ /**
4
+ 進行の欄(列)の表示名と設定のキー(`workflow.options.<key>`)の対応
5
+ */
6
+ export const COLUMN_CONFIG_KEYS = {
7
+ 'Blocked': 'blocked',
8
+ 'In Review': 'in_review',
9
+ 'Ready': 'ready',
10
+ };
11
+ /**
12
+ 札(Status)の表示名と設定のキー(`status.options.<key>`)の対応
13
+ */
14
+ export const LABEL_CONFIG_KEYS = {
15
+ 'Needs Attention': 'needs_attention',
16
+ 'Todo': 'todo',
17
+ };
18
+ // Backlog・Pending・Archived は人が置いた列なので、動かさず札も書かない
19
+ const RESETTABLE_COLUMNS = new Set(['Ready', 'Active', 'In Review']);
20
+ const WORKING_COLUMNS = new Set(['Ready', 'Blocked', 'Active', 'In Review']);
21
+ function blockingIssues(readiness) {
22
+ const { reason } = readiness;
23
+ if (reason === undefined)
24
+ return [];
25
+ switch (reason.code) {
26
+ case 'unreadable':
27
+ case 'cycle': {
28
+ return [];
29
+ }
30
+ case 'closed-unmerged':
31
+ case 'other-repository':
32
+ case 'diverged': {
33
+ return reason.issues;
34
+ }
35
+ case 'waits-merge':
36
+ case 'not-in-review': {
37
+ return reason.issues.map(({ issue }) => issue);
38
+ }
39
+ }
40
+ }
41
+ const BACK_TO_READY_COLUMNS = new Set(['Blocked', 'Active', 'In Review']);
42
+ // 着手の跡が無い Issue の列の行き先。動かさないときは undefined
43
+ function targetColumn(column, kind) {
44
+ if (kind === 'blocked')
45
+ return RESETTABLE_COLUMNS.has(column) ? 'Blocked' : undefined;
46
+ return BACK_TO_READY_COLUMNS.has(column) ? 'Ready' : undefined;
47
+ }
48
+ function targetLabel(input, readiness) {
49
+ if (readiness.needsReview)
50
+ return input.label === NEEDS_ATTENTION_LABEL ? undefined : 'Needs Attention';
51
+ const isOwnLabel = input.label === NEEDS_ATTENTION_LABEL && !input.labelWrittenByAutomation;
52
+ return isOwnLabel && input.hasPrerequisites ? 'Todo' : undefined;
53
+ }
54
+ // 人が置いた列でも、判定が読めないときでもない
55
+ function isDecidable(column, readiness) {
56
+ return WORKING_COLUMNS.has(column) && readiness.reason?.code !== 'unreadable';
57
+ }
58
+ /**
59
+ data-model.md の 6 の 2 つの表を当てはめる。
60
+ 対象でない・ボードに無い・判定が読めないときは undefined を返す。
61
+ 動かす先の値がボードに無いときは動かさず、missing に入れる
62
+ */
63
+ export function decideBoardMove(input) {
64
+ const { column, readiness, eligible } = input;
65
+ if (!eligible || column === undefined || readiness === undefined || !isDecidable(column, readiness))
66
+ return undefined;
67
+ const missing = [];
68
+ let move = { missing };
69
+ if (input.hasStarted) {
70
+ // 着手の跡がある Issue は進めているセッションのものなので、列と札を変えない(FR-084)
71
+ if (readiness.kind === 'blocked' && RESETTABLE_COLUMNS.has(column)) {
72
+ move = { ...move, conflict: { column, issues: blockingIssues(readiness) } };
73
+ }
74
+ return move.conflict === undefined ? undefined : move;
75
+ }
76
+ const to = targetColumn(column, readiness.kind);
77
+ if (to !== undefined) {
78
+ if (to === 'Blocked' && !input.available.blocked)
79
+ missing.push('Blocked');
80
+ else
81
+ move = { ...move, column: { from: column, to, reason: readiness } };
82
+ }
83
+ const label = targetLabel(input, readiness);
84
+ if (label === 'Needs Attention' && !input.available.needsAttention)
85
+ missing.push('Needs Attention');
86
+ else if (label === 'Todo' && !input.available.todo)
87
+ missing.push('Todo');
88
+ else if (label !== undefined)
89
+ move = { ...move, label };
90
+ return move.column === undefined && move.label === undefined && missing.length === 0 ? undefined : move;
91
+ }
92
+ //# sourceMappingURL=board-move.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ ブランチ名の末尾の Issue 番号。末尾が数字だけの区切りでなければ undefined
3
+ */
4
+ export declare function extractIssueNumberFromBranch(branch: string): number | undefined;
5
+ //# sourceMappingURL=branch-name.d.ts.map
@@ -0,0 +1,10 @@
1
+ // ブランチ名の読み取り。pecot session start が作る名前は、末尾が `/Issue番号` になる。
2
+ import { parsePythonInteger } from './python-format.js';
3
+ /**
4
+ ブランチ名の末尾の Issue 番号。末尾が数字だけの区切りでなければ undefined
5
+ */
6
+ export function extractIssueNumberFromBranch(branch) {
7
+ const last = branch.split('/').at(-1) ?? '';
8
+ return /^\p{Nd}+$/u.test(last) ? parsePythonInteger(last) : undefined;
9
+ }
10
+ //# sourceMappingURL=branch-name.js.map
@@ -0,0 +1,43 @@
1
+ import { PecotError, BaseError } from './errors.js';
2
+ export declare class ChangelogError extends PecotError {
3
+ }
4
+ /**
5
+ セマンティックバージョニング形式(X.Y.Z)に準拠していない
6
+ */
7
+ export declare class InvalidVersionError extends ChangelogError {
8
+ }
9
+ /**
10
+ CHANGELOG.md にバージョン情報が存在しない
11
+ */
12
+ export declare class VersionNotFoundError extends ChangelogError {
13
+ }
14
+ /**
15
+ CHANGELOG.md が存在しない。Python の FileNotFoundError に当たるので、PecotError ではない
16
+ */
17
+ export declare class ChangelogFileNotFoundError extends BaseError {
18
+ }
19
+ export declare const DEFAULT_CHANGELOG_FILE = "CHANGELOG.md";
20
+ export declare const CHANGELOG_FALLBACK_FILES: readonly string[];
21
+ /**
22
+ パス末尾のファイル名。エラー文に、実際に探したファイルの名前を出すために使う
23
+ */
24
+ export declare function changelogFileName(changelogPath: string): string;
25
+ /**
26
+ CHANGELOG が無いときの文
27
+ */
28
+ export declare function changelogNotFoundMessage(changelogPath: string): string;
29
+ /**
30
+ セマンティックバージョニング形式を検証する。形式違反は InvalidVersionError
31
+ */
32
+ export declare function validateSemver(version: string): void;
33
+ /**
34
+ ## [X.Y.Z] 形式の最初のバージョンを返す。Unreleased は飛ばす。無ければ VersionNotFoundError。
35
+ fileName は、エラー文に出す CHANGELOG のファイル名
36
+ */
37
+ export declare function getLatestVersion(content: string, fileName?: string): string;
38
+ /**
39
+ ## [X.Y.Z] の次の行から次の `## ` セクションまでの内容を返す。無ければ VersionNotFoundError。
40
+ fileName は、エラー文に出す CHANGELOG のファイル名
41
+ */
42
+ export declare function extractVersionReleaseNotes(content: string, version: string, fileName?: string): string;
43
+ //# sourceMappingURL=changelog.d.ts.map
@@ -0,0 +1,107 @@
1
+ // CHANGELOG.md の検証ロジック。Keep a Changelog 形式とセマンティックバージョニングに準拠する。
2
+ // ファイルは読まない。内容(文字列)を受けて値を返す。ファイルを読む側は infra/changelog-file.ts にある。
3
+ // Python の re と同じ判定にする(\d は Unicode の 10 進数字、\s は str.isspace、$ は末尾の改行 1 つの前でも合う)。
4
+ import { PecotError, BaseError } from './errors.js';
5
+ import { pythonStrip, splitCodePoints } from './python-format.js';
6
+ export class ChangelogError extends PecotError {
7
+ }
8
+ /**
9
+ セマンティックバージョニング形式(X.Y.Z)に準拠していない
10
+ */
11
+ export class InvalidVersionError extends ChangelogError {
12
+ }
13
+ /**
14
+ CHANGELOG.md にバージョン情報が存在しない
15
+ */
16
+ export class VersionNotFoundError extends ChangelogError {
17
+ }
18
+ /**
19
+ CHANGELOG.md が存在しない。Python の FileNotFoundError に当たるので、PecotError ではない
20
+ */
21
+ export class ChangelogFileNotFoundError extends BaseError {
22
+ }
23
+ export const DEFAULT_CHANGELOG_FILE = 'CHANGELOG.md';
24
+ export const CHANGELOG_FALLBACK_FILES = ['CHANGELOG.md', 'AIST-CHANGELOG.md'];
25
+ // X.Y.Z 形式。先頭に `v` は付けない
26
+ const SEMVER_PATTERN = /^\p{Nd}+\.\p{Nd}+\.\p{Nd}+\n?$/u;
27
+ // バージョン行の見出し記号と空白より後ろを見る。行の形は `## [X.Y.Z] - YYYY-MM-DD`。
28
+ const VERSION_PATTERN = /^\[(\p{Nd}+\.\p{Nd}+\.\p{Nd}+)\]/u;
29
+ // str.splitlines() の区切り。U+001C〜U+001E も含む。量指定子は無く、unsafe-regex は誤検知。
30
+ // eslint-disable-next-line no-control-regex, security/detect-unsafe-regex -- 区切りの制御文字と誤検知
31
+ const LINE_BREAK = /[\n\r\v\f\u{1C}-\u{1E}\u{85}\u{2028}\u{2029}]/u;
32
+ function splitLines(content) {
33
+ // 改行コードの \r\n は区切り 1 つと数えるため、先に \n へ揃える
34
+ const lines = content.replaceAll('\r\n', '\n').split(LINE_BREAK);
35
+ if (lines.at(-1) === '')
36
+ lines.pop();
37
+ return lines;
38
+ }
39
+ /**
40
+ `##` + 空白 1 つ以上で始まる行の、空白の後ろを返す。そうでなければ undefined。
41
+ 空白は Python の `\s`(str.isspace)と同じ。pythonStrip で先頭の空白を落として確かめる
42
+ */
43
+ function headingRest(line) {
44
+ if (!line.startsWith('##'))
45
+ return undefined;
46
+ const body = line.slice(2);
47
+ return body === '' || pythonStrip(splitCodePoints(body)[0] ?? '') !== '' ? undefined : pythonStrip(body);
48
+ }
49
+ /**
50
+ パス末尾のファイル名。エラー文に、実際に探したファイルの名前を出すために使う
51
+ */
52
+ export function changelogFileName(changelogPath) {
53
+ return changelogPath.slice(changelogPath.lastIndexOf('/') + 1);
54
+ }
55
+ /**
56
+ CHANGELOG が無いときの文
57
+ */
58
+ export function changelogNotFoundMessage(changelogPath) {
59
+ return `${changelogFileName(changelogPath)} not found: ${changelogPath}`;
60
+ }
61
+ /**
62
+ セマンティックバージョニング形式を検証する。形式違反は InvalidVersionError
63
+ */
64
+ export function validateSemver(version) {
65
+ if (!SEMVER_PATTERN.test(version)) {
66
+ throw new InvalidVersionError(`invalid version format: ${version}\n`
67
+ + 'use semantic versioning (X.Y.Z)');
68
+ }
69
+ }
70
+ /**
71
+ ## [X.Y.Z] 形式の最初のバージョンを返す。Unreleased は飛ばす。無ければ VersionNotFoundError。
72
+ fileName は、エラー文に出す CHANGELOG のファイル名
73
+ */
74
+ export function getLatestVersion(content, fileName = DEFAULT_CHANGELOG_FILE) {
75
+ for (const line of splitLines(content)) {
76
+ const version = VERSION_PATTERN.exec(headingRest(line) ?? '')?.[1];
77
+ if (version !== undefined)
78
+ return version;
79
+ }
80
+ throw new VersionNotFoundError(`no version found in ${fileName}\n`
81
+ + 'for a first release, specify the version manually');
82
+ }
83
+ /**
84
+ ## [X.Y.Z] の次の行から次の `## ` セクションまでの内容を返す。無ければ VersionNotFoundError。
85
+ fileName は、エラー文に出す CHANGELOG のファイル名
86
+ */
87
+ export function extractVersionReleaseNotes(content, version, fileName = DEFAULT_CHANGELOG_FILE) {
88
+ const heading = `[${version}]`;
89
+ let isInVersion = false;
90
+ const versionLines = [];
91
+ for (const line of splitLines(content)) {
92
+ if (headingRest(line)?.startsWith(heading) === true) {
93
+ isInVersion = true;
94
+ continue;
95
+ }
96
+ if (!isInVersion)
97
+ continue;
98
+ // 次の ## セクションが来たら終了
99
+ if (line.startsWith('## '))
100
+ break;
101
+ versionLines.push(line);
102
+ }
103
+ if (!isInVersion)
104
+ throw new VersionNotFoundError(`version not found in ${fileName}: ${version}`);
105
+ return pythonStrip(versionLines.join('\n'));
106
+ }
107
+ //# sourceMappingURL=changelog.js.map
@@ -0,0 +1,85 @@
1
+ /**
2
+ 案内の出し先。cli は `pecot ...` の行、mcp はツール名と入力
3
+ */
4
+ export type HintSurface = 'cli' | 'mcp';
5
+ /**
6
+ 利用者が埋める値。CLI でも MCP でも `<NAME>` と出す
7
+ */
8
+ export interface HintPlaceholder {
9
+ readonly placeholder: string;
10
+ }
11
+ export type HintValue = string | number | boolean | HintPlaceholder | readonly string[];
12
+ /**
13
+ コマンド 1 つの案内。input の並びは、位置引数の後ろのオプションの並びになる
14
+ */
15
+ export interface CommandHint {
16
+ readonly kind: 'command';
17
+ readonly path: readonly string[];
18
+ readonly input: Readonly<Record<string, HintValue>>;
19
+ }
20
+ /**
21
+ 入力 1 つだけの案内(`--allow-cross-repo` の形)
22
+ */
23
+ export interface InputHint {
24
+ readonly kind: 'input';
25
+ readonly path: readonly string[];
26
+ readonly name: string;
27
+ /**
28
+ undefined なら名前だけ(CLI は `--host`、MCP は `host`)
29
+ */
30
+ readonly value: HintValue | undefined;
31
+ }
32
+ /**
33
+ グローバルの repo の案内。どのコマンドでも同じ形なので path を持たない
34
+ */
35
+ export interface GlobalRepositoryHint {
36
+ readonly kind: 'global-repo';
37
+ readonly value: HintValue | undefined;
38
+ }
39
+ export type Hint = CommandHint | InputHint | GlobalRepositoryHint;
40
+ /**
41
+ 文字列と案内を並べた文。描くときに案内を出し先の形にする
42
+ */
43
+ export type HintedText = readonly (string | Hint)[];
44
+ /**
45
+ コマンドの形。案内の検証と、CLI の位置引数の並びに使う
46
+ */
47
+ export interface HintCommandShape {
48
+ readonly path: readonly string[];
49
+ readonly positional: readonly string[];
50
+ readonly inputs: readonly string[];
51
+ /**
52
+ 偽なら、入力 repo はグローバルの `--repo` で、CLI ではコマンド名の前に出す
53
+ */
54
+ readonly hasOwnRepo: boolean;
55
+ }
56
+ export declare function registerHintCommands(shapes: readonly HintCommandShape[]): void;
57
+ export declare function commandHint(path: readonly string[], input?: Readonly<Record<string, HintValue>>): CommandHint;
58
+ export declare function inputHint(path: readonly string[], name: string, value?: HintValue): InputHint;
59
+ /**
60
+ 入力の名前だけの案内。`--host is required` の `--host`
61
+ */
62
+ export declare function inputNameHint(path: readonly string[], name: string): InputHint;
63
+ /**
64
+ グローバルの repo の案内。value が無ければ名前だけ(CLI は `--repo`、MCP は `repo`)
65
+ */
66
+ export declare function globalRepositoryHint(value?: HintValue): GlobalRepositoryHint;
67
+ export declare function placeholder(name: string): HintPlaceholder;
68
+ /**
69
+ タグ付きテンプレートで HintedText を作る。`hinted\`run: ${commandHint(['project', 'init'])}\``
70
+ */
71
+ export declare function hinted(strings: TemplateStringsArray, ...values: readonly (string | number | Hint)[]): HintedText;
72
+ /**
73
+ HintedText を連結する。区切りは separator
74
+ */
75
+ export declare function joinHinted(parts: readonly (string | HintedText)[], separator?: string): HintedText;
76
+ /**
77
+ 案内 1 つを出し先の形にする。定義に無い path・入力名は TypeError
78
+ */
79
+ export declare function formatHint(hint: Hint, surface: HintSurface): string;
80
+ export declare function formatHinted(text: string | HintedText, surface: HintSurface): string;
81
+ /**
82
+ 例外が持つ案内(hintedText)。最上位はこれを出し先の形で描き直す。無ければ undefined
83
+ */
84
+ export declare function hintedTextOf(error: unknown): HintedText | undefined;
85
+ //# sourceMappingURL=command-hint.d.ts.map