@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,95 @@
1
+ // フック状態の規則(フラグ名・セッション名・作業ディレクトリ名)。ファイルの読み書きは infra/state-store.ts が行う。
2
+ import { InvalidValueError } from './errors.js';
3
+ import { parsePythonInteger, pythonRightStrip, pythonStrip, pythonStringRepr, truncateCodePoints } from './python-format.js';
4
+ import { createIssueReference, issueReferenceToString } from './reference-parser.js';
5
+ import { createRepositoryReference } from './repository-resolver.js';
6
+ // フラグファイル名
7
+ export const FLAG_PECOT_ACTIVE = '.pecot-active';
8
+ // セッション名(hooks の session-title.sh が Claude Code の sessionTitle に流す)。.pecot-active と同じタイミングで書く
9
+ export const FLAG_PECOT_SESSION_TITLE = '.pecot-session-title';
10
+ // 着手のときに選んだ base(ブランチ・位置・積んだ先の Issue)。session start が書き、session finish が消す
11
+ export const FLAG_PECOT_BASE = '.pecot-base';
12
+ export const FLAG_PECOT_QUICK_MODE = '.pecot-quick-mode';
13
+ export const FLAG_WIP_BRANCH_LINKED = '.wip-branch-linked';
14
+ // スラッシュコマンド起点の外部反映免除フラグ。
15
+ // 設置は hooks の create-slash-flag.sh が行う。
16
+ // 確認は mcp-handlers/pecot-post-ask.sh(merge は core/external-post-check.sh)が行う。
17
+ // MCP ツールが実投稿成功時に削除する。
18
+ export const FLAG_PR_CREATE_SLASH_PENDING = 'pr-create-slash-pending';
19
+ export const FLAG_ISSUE_CREATE_SLASH_PENDING = 'issue-create-slash-pending';
20
+ export const FLAG_MERGE_SLASH_PENDING = 'merge-slash-pending';
21
+ // 起票未完了のリマインド用フラグ。設置は hooks、確認は pecot-issue-pending-reminder.sh。MCP ツールが起票成功時に削除する
22
+ export const FLAG_ISSUE_PENDING = 'issue-pending';
23
+ export const SESSION_TITLE_MAX_CHARS = 40;
24
+ const ISSUE_TYPE_PREFIX_PATTERN = /^\[(?:Task|Bug|Epic)\]\s*/u;
25
+ /**
26
+ セッション名 `#<番号> <Issue タイトル>` を組み立てる。
27
+ 先頭の種別接頭辞(`[Task]` 等)を落とし、全体を SESSION_TITLE_MAX_CHARS 文字(コードポイント)で切る。
28
+ タイトルが空なら `#<番号>` だけにする
29
+ */
30
+ export function formatSessionTitle(issueNumber, title) {
31
+ const body = pythonStrip(title.replace(ISSUE_TYPE_PREFIX_PATTERN, ''));
32
+ const name = body === '' ? `#${String(issueNumber)}` : `#${String(issueNumber)} ${body}`;
33
+ return pythonRightStrip(truncateCodePoints(name, SESSION_TITLE_MAX_CHARS));
34
+ }
35
+ function lastSegment(issueReference) {
36
+ let end = issueReference.length;
37
+ while (end > 0 && issueReference.charAt(end - 1) === '/')
38
+ end -= 1;
39
+ const trimmed = issueReference.slice(0, end);
40
+ return trimmed.slice(trimmed.lastIndexOf('/') + 1);
41
+ }
42
+ /**
43
+ 作業ディレクトリ `.pecot/work/<Issue番号>/` の番号。参照(`owner/repo/N` または `N`)の末尾が ASCII の数字でなければ undefined。
44
+ `.pecot/work` の直下は Issue 番号の数字だけにする規約のため、全角数字などは通さない
45
+ */
46
+ export function workDirectoryName(issueReference) {
47
+ const number = lastSegment(issueReference);
48
+ return /^\d+$/u.test(number) ? number : undefined;
49
+ }
50
+ /**
51
+ 作業対象として書く内容(.pecot-active と .pecot-session-title)を決める。参照の末尾が整数でなければ InvalidValueError
52
+ */
53
+ export function planWorkTarget(issueReference, title) {
54
+ const text = lastSegment(issueReference);
55
+ const number = parsePythonInteger(text);
56
+ if (number === undefined)
57
+ throw new InvalidValueError(`invalid literal for int() with base 10: ${pythonStringRepr(text)}`);
58
+ return { active: issueReference, sessionTitle: formatSessionTitle(number, title) };
59
+ }
60
+ // ブランチ名に空白は入らないので、空白で区切る
61
+ const BASE_SHA_PATTERN = /^(?:[\da-f]{40}|[\da-f]{64})$/u;
62
+ const BASE_ISSUE_PATTERN = /^([^\s#/]+)\/([^\s#/]+)#(\d+)$/u;
63
+ /**
64
+ .pecot-base の 1 行。`<branch> <sha>` に、積んだときは ` <owner/repo#N>` を続ける
65
+ */
66
+ export function formatBaseRecord(record) {
67
+ const fields = [record.branch, record.sha];
68
+ if (record.stackedOn !== undefined)
69
+ fields.push(issueReferenceToString(record.stackedOn));
70
+ return fields.join(' ');
71
+ }
72
+ function parseStackedOn(text) {
73
+ const match = BASE_ISSUE_PATTERN.exec(text);
74
+ const [, owner, repository, digits] = match ?? [];
75
+ if (owner === undefined || repository === undefined || digits === undefined)
76
+ return undefined;
77
+ const number = Number(digits);
78
+ return number > 0 ? createIssueReference(createRepositoryReference(owner, repository), number) : undefined;
79
+ }
80
+ /**
81
+ .pecot-base の内容を読む。ファイルが無いのは、この機能の前に着手したものも含めて、開発ブランチから着手したものとして扱う。
82
+ 形が誤っていれば malformed
83
+ */
84
+ export function interpretBaseRecord(content) {
85
+ if (content === undefined)
86
+ return { kind: 'development', record: undefined };
87
+ const [branch, sha, issue, ...rest] = content.split(' ');
88
+ if (branch === undefined || branch === '' || sha === undefined || !BASE_SHA_PATTERN.test(sha) || rest.length > 0)
89
+ return { kind: 'malformed', content };
90
+ if (issue === undefined)
91
+ return { kind: 'development', record: { branch, sha, stackedOn: undefined } };
92
+ const stackedOn = parseStackedOn(issue);
93
+ return stackedOn === undefined ? { kind: 'malformed', content } : { kind: 'stacked', record: { branch, sha, stackedOn }, stackedOn };
94
+ }
95
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1,70 @@
1
+ import type { PecotError } from './errors.js';
2
+ import type { JsonValue } from './python-format.js';
3
+ /**
4
+ Python の正規表現の `\s`(str)と同じ範囲の文字クラスの中身。JS の `\s` から U+FEFF を除き、U+001C〜U+001F と U+0085 を足す
5
+ */
6
+ export declare const PYTHON_SPACE: string;
7
+ export declare const SPACE: string;
8
+ export declare const NON_SPACE: string;
9
+ /**
10
+ 固定の文字列から正規表現を作る。呼び出し側は利用者の入力を渡さない
11
+ */
12
+ export declare function compilePattern(source: string, flags: string): RegExp;
13
+ export interface MarkerPatterns {
14
+ /**
15
+ g フラグ付き
16
+ */
17
+ readonly begin: RegExp;
18
+ /**
19
+ g フラグ付き
20
+ */
21
+ readonly end: RegExp;
22
+ /**
23
+ g フラグなし
24
+ */
25
+ readonly tracker: RegExp;
26
+ }
27
+ /**
28
+ `<!-- <prefix>: list-begin -->` などの印の正規表現。空白は Python の `\s` と同じ範囲
29
+ */
30
+ export declare function markerPatterns(prefix: string): MarkerPatterns;
31
+ export declare const MARKER_PAIR_MESSAGE = "cannot rewrite the list: the Tracker body does not have exactly one pair of list-begin / list-end markers";
32
+ /**
33
+ 表のセルに入る文。`|` と改行と `<` を無害にする
34
+ */
35
+ export declare function cell(text: string): string;
36
+ export interface ListRegion {
37
+ /**
38
+ begin の印の直後
39
+ */
40
+ readonly begin: number;
41
+ /**
42
+ end の印の先頭
43
+ */
44
+ readonly end: number;
45
+ }
46
+ /**
47
+ 本文の一覧の範囲。印の組が 1 組でない(欠け・重なり・順序の逆転)なら、渡された型のエラーを投げる。
48
+ 正規表現は g フラグ付きで渡す
49
+ */
50
+ export declare function listRegion(body: string, beginPattern: Readonly<RegExp>, endPattern: Readonly<RegExp>, ErrorType: new (message: string) => PecotError): ListRegion;
51
+ export interface TrackerIssue {
52
+ readonly number: number;
53
+ readonly body: string;
54
+ }
55
+ export interface FoundTracker {
56
+ /**
57
+ 使う Tracker。open のものが無ければ undefined
58
+ */
59
+ readonly tracker: TrackerIssue | undefined;
60
+ /**
61
+ ほかの open の Tracker の番号(警告用。sync は閉じない)
62
+ */
63
+ readonly others: readonly number[];
64
+ }
65
+ /**
66
+ ラベルで引いた Issue から、open で本文に Tracker の印があるものを探す。複数あれば番号が最小のものを使う。
67
+ 正規表現は g フラグなしで渡す
68
+ */
69
+ export declare function findTracker(issues: readonly JsonValue[], trackerPattern: Readonly<RegExp>): FoundTracker;
70
+ //# sourceMappingURL=tracker-body.d.ts.map
@@ -0,0 +1,65 @@
1
+ // Tracker の本文の一覧の範囲と、open の Tracker の探し方(cli/core/tracker_body.py の移植)。2 つの Tracker が共有する。
2
+ // 印の正規表現とエラーの型は呼び出し側が渡す。改行の正規化は python-format.ts の normalizeNewlines を使う。
3
+ import { isJsonObject } from './json.js';
4
+ import { pythonStrip } from './python-format.js';
5
+ /**
6
+ Python の正規表現の `\s`(str)と同じ範囲の文字クラスの中身。JS の `\s` から U+FEFF を除き、U+001C〜U+001F と U+0085 を足す
7
+ */
8
+ export const PYTHON_SPACE = String.raw `\t\n\v\f\r \u001C-\u001F\u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000`;
9
+ export const SPACE = `[${PYTHON_SPACE}]`;
10
+ export const NON_SPACE = `[^${PYTHON_SPACE}]`;
11
+ /**
12
+ 固定の文字列から正規表現を作る。呼び出し側は利用者の入力を渡さない
13
+ */
14
+ export function compilePattern(source, flags) {
15
+ // eslint-disable-next-line security/detect-non-literal-regexp -- 固定の文字列から組み立てる
16
+ return new RegExp(source, flags);
17
+ }
18
+ /**
19
+ `<!-- <prefix>: list-begin -->` などの印の正規表現。空白は Python の `\s` と同じ範囲
20
+ */
21
+ export function markerPatterns(prefix) {
22
+ const marker = (name) => `<!--${SPACE}*${prefix}:${SPACE}*${name}${SPACE}*-->`;
23
+ return { begin: compilePattern(marker('list-begin'), 'gu'), end: compilePattern(marker('list-end'), 'gu'), tracker: compilePattern(marker('tracker'), 'u') };
24
+ }
25
+ const LINE_BREAK_RUN = compilePattern(`${SPACE}*[\r\n]${SPACE}*`, 'gu');
26
+ export const MARKER_PAIR_MESSAGE = 'cannot rewrite the list: the Tracker body does not have exactly one pair of list-begin / list-end markers';
27
+ /**
28
+ 表のセルに入る文。`|` と改行と `<` を無害にする
29
+ */
30
+ export function cell(text) {
31
+ return pythonStrip(text.replaceAll(LINE_BREAK_RUN, ' ')).replaceAll('<', '&lt;').replaceAll('|', String.raw `\|`);
32
+ }
33
+ function spanOf(match) {
34
+ return { start: match.index, end: match.index + match[0].length };
35
+ }
36
+ /**
37
+ 本文の一覧の範囲。印の組が 1 組でない(欠け・重なり・順序の逆転)なら、渡された型のエラーを投げる。
38
+ 正規表現は g フラグ付きで渡す
39
+ */
40
+ export function listRegion(body, beginPattern, endPattern, ErrorType) {
41
+ const begins = Array.from(body.matchAll(beginPattern), spanOf);
42
+ const ends = Array.from(body.matchAll(endPattern), spanOf);
43
+ const [begin] = begins;
44
+ const [end] = ends;
45
+ if (begin === undefined || end === undefined || begins.length !== 1 || ends.length !== 1 || begin.end > end.start) {
46
+ throw new ErrorType(MARKER_PAIR_MESSAGE);
47
+ }
48
+ return { begin: begin.end, end: end.start };
49
+ }
50
+ function trackerOf(issue, trackerPattern) {
51
+ if (!isJsonObject(issue) || issue['state'] !== 'open')
52
+ return undefined;
53
+ const { body, number } = issue;
54
+ return typeof body === 'string' && typeof number === 'number' && trackerPattern.test(body) ? { number, body } : undefined;
55
+ }
56
+ /**
57
+ ラベルで引いた Issue から、open で本文に Tracker の印があるものを探す。複数あれば番号が最小のものを使う。
58
+ 正規表現は g フラグなしで渡す
59
+ */
60
+ export function findTracker(issues, trackerPattern) {
61
+ const found = issues.map(issue => trackerOf(issue, trackerPattern)).filter(issue => issue !== undefined).toSorted((a, b) => a.number - b.number);
62
+ const [tracker, ...rest] = found;
63
+ return { tracker, others: rest.map(issue => issue.number) };
64
+ }
65
+ //# sourceMappingURL=tracker-body.js.map
@@ -0,0 +1,34 @@
1
+ import type { HintedText } from './command-hint.js';
2
+ import type { PullRequestReadout } from './issue-readout.js';
3
+ import type { Prerequisite, Readiness } from './readiness.js';
4
+ import type { IssueReference } from './reference-parser.js';
5
+ export type StartDecision = {
6
+ readonly kind: 'start';
7
+ } | {
8
+ readonly kind: 'stack';
9
+ readonly branch: string;
10
+ readonly issue: IssueReference;
11
+ } | {
12
+ readonly kind: 'blocked';
13
+ readonly message: HintedText;
14
+ };
15
+ /**
16
+ 判定から着手の仕方を決める。stackable は積む先のブランチから、blocked は止める。
17
+ startable と、判定を持たない Epic・Tracker(undefined)は、今までどおり
18
+ */
19
+ export declare function decideStart(readiness: Readiness | undefined, prerequisites: readonly Prerequisite[], target: IssueReference): StartDecision;
20
+ /**
21
+ --base が、判定で選んだ積む先と違うときの文。stackable のときだけ比べる
22
+ */
23
+ export declare function describeBaseMismatch(base: string | undefined, decision: Exclude<StartDecision, {
24
+ kind: 'blocked';
25
+ }>, target: IssueReference): HintedText | undefined;
26
+ /**
27
+ base のブランチを head に持つ PR のうち、表に出す 1 本。fork でない open のもの、無ければ fork でない最新のもの(新しい順に渡す)
28
+ */
29
+ export declare function pickBasePullRequest(pullRequests: readonly PullRequestReadout[]): PullRequestReadout | undefined;
30
+ /**
31
+ session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
32
+ */
33
+ export declare function describeStackBase(branch: string, issue: IssueReference, pullRequest: Readonly<PullRequestReadout> | undefined | 'unknown'): string;
34
+ //# sourceMappingURL=work-start.d.ts.map
@@ -0,0 +1,49 @@
1
+ // 着手の判定から、base の選び方・止める文・積んだ先の表示を決める。I/O を持たない。
2
+ import { commandHint, hinted, inputHint, joinHinted } from './command-hint.js';
3
+ import { describePrerequisiteState, describeReadiness, displayReference, isDone } from './readiness.js';
4
+ import { issueReferenceToCliReference } from './reference-parser.js';
5
+ function blockedMessage(target, readiness, prerequisites) {
6
+ const home = target.repository;
7
+ const unfinished = prerequisites.filter(({ issue }) => !isDone(issue));
8
+ const subject = issueReferenceToCliReference(target);
9
+ const waitsMerge = readiness.reason?.code === 'waits-merge' ? readiness.reason.issues : [];
10
+ return joinHinted([
11
+ `${displayReference(target, home)} is ${describeReadiness(readiness, prerequisites, home)}`,
12
+ ...unfinished.map(prerequisite => `- ${displayReference(prerequisite.issue.ref, home)}: ${describePrerequisiteState(prerequisite)}`),
13
+ ...unfinished.map(({ issue }) => hinted `to remove the prerequisite: ${commandHint(['issue', 'unblock'], { issue_ref: subject, by: issueReferenceToCliReference(issue.ref) })}`),
14
+ ...waitsMerge.map(({ issue }) => hinted `to stack on it instead of waiting for merge: ${commandHint(['issue', 'block'], { issue_ref: subject, by: issueReferenceToCliReference(issue), wait: 'stack' })}`),
15
+ ]);
16
+ }
17
+ /**
18
+ 判定から着手の仕方を決める。stackable は積む先のブランチから、blocked は止める。
19
+ startable と、判定を持たない Epic・Tracker(undefined)は、今までどおり
20
+ */
21
+ export function decideStart(readiness, prerequisites, target) {
22
+ if (readiness?.kind === 'blocked')
23
+ return { kind: 'blocked', message: blockedMessage(target, readiness, prerequisites) };
24
+ if (readiness?.kind === 'stackable' && readiness.stackOn !== undefined)
25
+ return { kind: 'stack', branch: readiness.stackOn.branch, issue: readiness.stackOn.issue };
26
+ return { kind: 'start' };
27
+ }
28
+ /**
29
+ --base が、判定で選んだ積む先と違うときの文。stackable のときだけ比べる
30
+ */
31
+ export function describeBaseMismatch(base, decision, target) {
32
+ const isDifferent = base !== undefined && base !== '' && decision.kind === 'stack' && base !== decision.branch;
33
+ return isDifferent ? hinted `${inputHint(['session', 'start'], 'base', base)} differs from the base chosen by readiness: ${decision.branch} (stacked on ${displayReference(decision.issue, target.repository)})` : undefined;
34
+ }
35
+ /**
36
+ base のブランチを head に持つ PR のうち、表に出す 1 本。fork でない open のもの、無ければ fork でない最新のもの(新しい順に渡す)
37
+ */
38
+ export function pickBasePullRequest(pullRequests) {
39
+ const own = pullRequests.filter(pullRequest => !pullRequest.isCrossRepository);
40
+ return own.find(pullRequest => pullRequest.state === 'OPEN') ?? own[0];
41
+ }
42
+ /**
43
+ session show の `- base:` の行。PR が無ければ `no PR`、読めなければ `PR unknown`
44
+ */
45
+ export function describeStackBase(branch, issue, pullRequest) {
46
+ const pr = pullRequest === 'unknown' ? 'PR unknown' : (pullRequest === undefined ? 'no PR' : `PR #${String(pullRequest.number)} ${pullRequest.state}`);
47
+ return `- base: ${branch} (#${String(issue.number)}, ${pr})`;
48
+ }
49
+ //# sourceMappingURL=work-start.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ YAML の文字列を読む。空の文書は null。構文が不正なら YAML ライブラリのエラーを投げる
3
+ */
4
+ export declare function parseYamlDocument(source: string): unknown;
5
+ //# sourceMappingURL=yaml-document.d.ts.map
@@ -0,0 +1,206 @@
1
+ // YAML の読み込み。Python の CLI が使っていた YAML ライブラリ(safe_load)と同じ値を返す。
2
+ //
3
+ // 揃える対象は、型の決め方(暗黙の型の正規表現)と、重複キーの扱い。
4
+ // - 真偽値は yes・no・true・false・on・off(大文字小文字は 3 通りだけ)。y と n は文字列のまま
5
+ // - 整数は 2 進・8 進(先頭が 0)・16 進・60 進、数字の間の `_` を受ける。`0o10` と `08` は文字列
6
+ // - 実数: 小数点が必要。`1e3` は文字列で、`1.0e+3` が実数。指数には符号が必要
7
+ // - 日付は `YYYY-MM-DD` か、`Y-M-D` + 時刻
8
+ // - 重複キーは後のものが勝つ。`=` と、キー以外の位置の `<<` は読めずにエラー
9
+ // - 明示タグ(`!!float 1` など)は値の形に依らず、タグの型で読む。読めない値と未知のタグはエラー
10
+ // - 配列や辞書をキーにすると、エラー
11
+ // 構文エラーの文は揃えない(YAML ライブラリの文のまま)。
12
+ // 文字列でないキー(`1:` `yes:` `null:`)は文字列にして読む。Python は整数・真偽値・None のキーで読む。
13
+ // フロントマターの項目名には当たらないため、検証後の結果は同じになる。
14
+ import { parseDocument, visit } from 'yaml';
15
+ import { JSON_NULL } from './json-null.js';
16
+ const REPLACED_TAGS = new Set([
17
+ 'tag:yaml.org,2002:bool',
18
+ 'tag:yaml.org,2002:int',
19
+ 'tag:yaml.org,2002:float',
20
+ 'tag:yaml.org,2002:timestamp',
21
+ ]);
22
+ const BOOL_PATTERN = /^(?:yes|Yes|YES|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$/u;
23
+ /* eslint-disable security/detect-unsafe-regex -- どの正規表現も全体を ^ と $ で囲み、量指定子の付いた群の中身は互いに重ならない。入力は YAML の 1 つのスカラー値で、破滅的な再試行は起きない */
24
+ // 実数と整数の正規表現は、Python の YAML ライブラリの 1 本を選択肢ごとに分けたもの(意味は同じ)
25
+ const FLOAT_PATTERNS = [
26
+ /^[+-]?\d[\d_]*\.[\d_]*(?:e[+-]\d+)?$/iu,
27
+ /^\.\d[\d_]*(?:e[+-]\d+)?$/iu,
28
+ /^[+-]?\d[\d_]*(?::[0-5]?\d)+\.[\d_]*$/u,
29
+ /^[+-]?\.(?:inf|Inf|INF)$/u,
30
+ /^\.(?:nan|NaN|NAN)$/u,
31
+ ];
32
+ const INT_PATTERNS = [
33
+ /^[+-]?0b[01_]+$/u,
34
+ /^[+-]?0[0-7_]+$/u,
35
+ /^[+-]?(?:0|[1-9][\d_]*)$/u,
36
+ /^[+-]?0x[\da-fA-F_]+$/u,
37
+ /^[+-]?[1-9][\d_]*(?::[0-5]?\d)+$/u,
38
+ ];
39
+ const TIMESTAMP_PATTERNS = [
40
+ /^(\d{4})-(\d{2})-(\d{2})$/u,
41
+ /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[Tt]|[\t ]+)(\d{1,2}):(\d{2}):(\d{2})(?:\.(\d*))?(?:[\t ]*(Z|[+-]\d{1,2}(?::\d{2})?))?$/u,
42
+ ];
43
+ // 実数の各部(60 進の各部も同じ形)
44
+ const DECIMAL_NUMBER = /^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/u;
45
+ /* eslint-enable security/detect-unsafe-regex */
46
+ function invalid(type, text) {
47
+ throw new Error(`invalid ${type} value: ${text}`);
48
+ }
49
+ // `1:30.5` のような 60 進。各部は数でなければならない
50
+ function sexagesimal(text, type) {
51
+ let total = 0;
52
+ for (const part of text.split(':'))
53
+ total = DECIMAL_NUMBER.test(part) ? total * 60 + Number(part) : invalid(type, text);
54
+ return total;
55
+ }
56
+ const BOOLEAN_VALUES = new Map([
57
+ ['yes', true], ['true', true], ['on', true], ['no', false], ['false', false], ['off', false],
58
+ ]);
59
+ function isTrueKeyword(text) {
60
+ return BOOLEAN_VALUES.get(text.toLowerCase()) ?? invalid('bool', text);
61
+ }
62
+ function resolveFloat(text) {
63
+ const value = text.replaceAll('_', '').toLowerCase();
64
+ const sign = value.startsWith('-') ? -1 : 1;
65
+ const unsigned = /^[+-]/u.test(value) ? value.slice(1) : value;
66
+ if (['.inf', 'inf', 'infinity'].includes(unsigned))
67
+ return sign * Infinity;
68
+ if (['.nan', 'nan'].includes(unsigned))
69
+ return NaN;
70
+ if (unsigned.includes(':'))
71
+ return sign * sexagesimal(unsigned, 'float');
72
+ return DECIMAL_NUMBER.test(unsigned) ? sign * Number(unsigned) : invalid('float', text);
73
+ }
74
+ // 符号を掛けると -0 になる(Python の整数に -0 は無い)ので、0 との差で負にする
75
+ function applySign(sign, magnitude) {
76
+ return sign < 0 ? 0 - magnitude : magnitude;
77
+ }
78
+ function parseDigits(digits, radix, pattern, text) {
79
+ return pattern.test(digits) ? Number.parseInt(digits, radix) : invalid('int', text);
80
+ }
81
+ function integerSexagesimal(unsigned, text) {
82
+ let total = 0;
83
+ for (const part of unsigned.split(':'))
84
+ total = total * 60 + parseDigits(part, 10, /^\d+$/u, text);
85
+ return total;
86
+ }
87
+ function resolveInteger(text) {
88
+ const value = text.replaceAll('_', '');
89
+ const sign = value.startsWith('-') ? -1 : 1;
90
+ const unsigned = /^[+-]/u.test(value) ? value.slice(1) : value;
91
+ if (unsigned === '0')
92
+ return 0;
93
+ if (unsigned.startsWith('0b'))
94
+ return applySign(sign, parseDigits(unsigned.slice(2), 2, /^[01]+$/u, text));
95
+ if (unsigned.startsWith('0x'))
96
+ return applySign(sign, parseDigits(unsigned.slice(2), 16, /^[\da-f]+$/iu, text));
97
+ if (unsigned.startsWith('0'))
98
+ return applySign(sign, parseDigits(unsigned, 8, /^[0-7]+$/u, text));
99
+ if (unsigned.includes(':'))
100
+ return applySign(sign, integerSexagesimal(unsigned, text));
101
+ return applySign(sign, parseDigits(unsigned, 10, /^\d+$/u, text));
102
+ }
103
+ const DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
104
+ function timeZoneMinutes(zone) {
105
+ if (zone === undefined || zone === 'Z')
106
+ return 0;
107
+ const sign = zone.startsWith('-') ? -1 : 1;
108
+ const [hours = '0', minutes = '0'] = zone.slice(1).split(':', 2);
109
+ return sign * (Number(hours) * 60 + Number(minutes));
110
+ }
111
+ function numberOrZero(text = '0') {
112
+ return Number(text);
113
+ }
114
+ // 小数部の最初の 3 桁がミリ秒
115
+ function milliseconds(fraction = '') {
116
+ return Number(`${fraction}000`.slice(0, 3));
117
+ }
118
+ function execFirst(patterns, text) {
119
+ for (const pattern of patterns) {
120
+ const match = pattern.exec(text);
121
+ if (match !== null)
122
+ return match;
123
+ }
124
+ return undefined;
125
+ }
126
+ function resolveTimestamp(text) {
127
+ const match = execFirst(TIMESTAMP_PATTERNS, text);
128
+ if (match === undefined)
129
+ throw new Error('not a timestamp');
130
+ const [, year, month, day, hour, minute, second, fraction, zone] = match;
131
+ const [y = 0, mo = 0, d = 0, h = 0, mi = 0, s = 0] = [year, month, day, hour, minute, second].map(part => numberOrZero(part));
132
+ const isValidDate = d >= 1 && d <= (DAYS_IN_MONTH[mo - 1] ?? 0) && new Date(Date.UTC(y, mo - 1, d)).getUTCDate() === d;
133
+ if (!isValidDate || h > 23 || mi > 59 || s > 59)
134
+ throw new Error(`date or time out of range: ${text}`);
135
+ return new Date(Date.UTC(y, mo - 1, d, h, mi, s, milliseconds(fraction)) - timeZoneMinutes(zone) * 60_000);
136
+ }
137
+ const TAG_BOOL = 'tag:yaml.org,2002:bool';
138
+ const TAG_FLOAT = 'tag:yaml.org,2002:float';
139
+ const TAG_INT = 'tag:yaml.org,2002:int';
140
+ const TAG_TIMESTAMP = 'tag:yaml.org,2002:timestamp';
141
+ const TAG_NULL = 'tag:yaml.org,2002:null';
142
+ // 暗黙の型(正規表現に合うとき)の読み方
143
+ const IMPLICIT_TAGS = [
144
+ { default: true, tag: TAG_BOOL, test: BOOL_PATTERN, resolve: isTrueKeyword },
145
+ ...FLOAT_PATTERNS.map((test) => ({ default: true, tag: TAG_FLOAT, test, resolve: resolveFloat })),
146
+ ...INT_PATTERNS.map((test) => ({ default: true, tag: TAG_INT, test, resolve: resolveInteger })),
147
+ ...TIMESTAMP_PATTERNS.map((test) => ({ default: true, tag: TAG_TIMESTAMP, test, resolve: resolveTimestamp })),
148
+ {
149
+ default: true,
150
+ tag: 'tag:yaml.org,2002:value',
151
+ test: /^=$/u,
152
+ resolve() {
153
+ throw new Error('could not determine a constructor for the tag \'tag:yaml.org,2002:value\'');
154
+ },
155
+ },
156
+ ];
157
+ // 明示タグ(`!!float 1`)の読み方。正規表現に合わない値も、タグの型で読む
158
+ const EXPLICIT_TAGS = [
159
+ { tag: TAG_BOOL, resolve: isTrueKeyword },
160
+ { tag: TAG_FLOAT, resolve: resolveFloat },
161
+ { tag: TAG_INT, resolve: resolveInteger },
162
+ { tag: TAG_TIMESTAMP, resolve: resolveTimestamp },
163
+ { tag: TAG_NULL, resolve: () => JSON_NULL },
164
+ ];
165
+ // mapAsMap で読んだ Map を、文字列キーの辞書にする。配列や辞書のキーは、Python ではハッシュできずエラー
166
+ function toPlainValue(value) {
167
+ if (Array.isArray(value))
168
+ return value.map((item) => toPlainValue(item));
169
+ if (!(value instanceof Map))
170
+ return value;
171
+ const entries = [];
172
+ for (const [key, item] of value) {
173
+ if (key instanceof Map || Array.isArray(key))
174
+ throw new TypeError('while constructing a mapping: found unhashable key');
175
+ entries.push([String(key), toPlainValue(item)]);
176
+ }
177
+ return Object.fromEntries(entries);
178
+ }
179
+ /**
180
+ YAML の文字列を読む。空の文書は null。構文が不正なら YAML ライブラリのエラーを投げる
181
+ */
182
+ export function parseYamlDocument(source) {
183
+ const document = parseDocument(source, {
184
+ version: '1.1',
185
+ uniqueKeys: false,
186
+ logLevel: 'error',
187
+ customTags: tags => [...tags.filter(tag => typeof tag === 'string' || !REPLACED_TAGS.has(tag.tag)), ...IMPLICIT_TAGS, ...EXPLICIT_TAGS],
188
+ });
189
+ const [error] = document.errors;
190
+ if (error !== undefined)
191
+ throw error;
192
+ // 未知のタグ(`!!foo`・`!foo`)は、YAML ライブラリでは警告になる。Python ではエラー
193
+ const unresolved = document.warnings.find(warning => warning.code === 'TAG_RESOLVE_FAILED');
194
+ if (unresolved !== undefined)
195
+ throw unresolved;
196
+ // `<<` は、キーの位置でだけ merge として読める。値や配列の要素にある引用符なしの `<<` は読めない
197
+ visit(document, {
198
+ Scalar(key, node) {
199
+ if (key !== 'key' && node.tag === undefined && node.type === 'PLAIN' && node.source === '<<') {
200
+ throw new Error('could not determine a constructor for the tag \'tag:yaml.org,2002:merge\'');
201
+ }
202
+ },
203
+ });
204
+ return toPlainValue(document.toJS({ mapAsMap: true }));
205
+ }
206
+ //# sourceMappingURL=yaml-document.js.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ 引数の組み合わせの決まり。同時に使えない組か、あるオプションが他のオプションを要る関係
3
+ */
4
+ export type Constraint = {
5
+ readonly conflicts: readonly string[];
6
+ } | {
7
+ readonly requires: Readonly<Record<string, readonly string[]>>;
8
+ };
9
+ export interface AuthoredNotes {
10
+ readonly details: readonly string[];
11
+ readonly constraints: readonly Constraint[];
12
+ readonly examples: readonly Readonly<{
13
+ run: string;
14
+ note: string;
15
+ }>[];
16
+ /**
17
+ 入力名 → 初期値の補足の文
18
+ */
19
+ readonly defaultNotes: ReadonlyMap<string, string>;
20
+ }
21
+ /**
22
+ 読めたか、読めなかったか。読めなかったときは、読もうとした絶対パスと理由(1 行)を持つ
23
+ */
24
+ export type NotesResult = {
25
+ readonly kind: 'read';
26
+ readonly notes: AuthoredNotes;
27
+ } | {
28
+ readonly kind: 'unreadable';
29
+ readonly file: string;
30
+ readonly reason: string;
31
+ };
32
+ /**
33
+ ID(`PW-SESSION-START`)の項目の details・constraints・examples・default_notes を読む。
34
+ ファイルが無い・YAML として読めない・項目が無い・欄の形が違うときは、場所と理由を持つ unreadable を返す
35
+ */
36
+ export declare function readAuthoredNotes(id: string, root?: string): NotesResult;
37
+ //# sourceMappingURL=authored-notes.d.ts.map
@@ -0,0 +1,72 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは pluginRoot() の下の固定の位置。引数 root はテストが一時ディレクトリを渡す */
2
+ // 定義書の手書きの側(interface/authored.yaml)から、コマンドの --help に出す 4 つの欄を読む。
3
+ // domain/yaml-document.ts は PyYAML 互換で `yes`・`no` を真偽値にするので、yaml の parse をそのまま使う。
4
+ import { readFileSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { parse } from 'yaml';
7
+ import { z } from 'zod';
8
+ import { pluginRoot } from '../version.js';
9
+ const NAMES_SCHEMA = z.array(z.string());
10
+ const CONFLICTS_SCHEMA = z.object({ conflicts: NAMES_SCHEMA });
11
+ const DEPENDENCY_SCHEMA = z.object({ requires: z.record(z.string(), NAMES_SCHEMA) });
12
+ const CONSTRAINT_SCHEMA = z.union([CONFLICTS_SCHEMA, DEPENDENCY_SCHEMA]);
13
+ const EXAMPLE_SCHEMA = z.object({ run: z.string(), note: z.string() });
14
+ const FILE_SCHEMA = z.object({ entries: z.record(z.string(), z.unknown()) });
15
+ const PROSE_SHAPE = {
16
+ details: NAMES_SCHEMA,
17
+ examples: z.array(EXAMPLE_SCHEMA),
18
+ default_notes: z.record(z.string(), z.string()),
19
+ };
20
+ // help は --help に出す英語の文。日本語で書いた定義書では、同じ名前の 3 つの欄の代わりに読む
21
+ const ENTRY_SCHEMA = z.object({
22
+ ...PROSE_SHAPE,
23
+ constraints: z.array(CONSTRAINT_SCHEMA),
24
+ help: z.object(PROSE_SHAPE).optional(),
25
+ });
26
+ /**
27
+ authored.yaml の置き場所。pluginRoot() の下の interface/
28
+ */
29
+ function authoredFile(root = pluginRoot()) {
30
+ return path.join(root, 'interface', 'authored.yaml');
31
+ }
32
+ function unreadable(file, reason) {
33
+ return { kind: 'unreadable', file, reason };
34
+ }
35
+ function isMissingFile(error) {
36
+ return error instanceof Error && 'code' in error && error.code === 'ENOENT';
37
+ }
38
+ /**
39
+ ID(`PW-SESSION-START`)の項目の details・constraints・examples・default_notes を読む。
40
+ ファイルが無い・YAML として読めない・項目が無い・欄の形が違うときは、場所と理由を持つ unreadable を返す
41
+ */
42
+ export function readAuthoredNotes(id, root = pluginRoot()) {
43
+ const file = authoredFile(root);
44
+ let text;
45
+ try {
46
+ text = readFileSync(file, 'utf8');
47
+ }
48
+ catch (error) {
49
+ return unreadable(file, isMissingFile(error) ? 'the file does not exist' : 'the file cannot be read');
50
+ }
51
+ let document;
52
+ try {
53
+ // 警告は process.emitWarning で出るので、誤りだけ拾う(help の出力に yaml の警告を混ぜない)
54
+ document = parse(text, { logLevel: 'error' });
55
+ }
56
+ catch {
57
+ return unreadable(file, 'it is not valid YAML');
58
+ }
59
+ const parsedFile = FILE_SCHEMA.safeParse(document);
60
+ if (!parsedFile.success)
61
+ return unreadable(file, 'it has no entries');
62
+ const entry = new Map(Object.entries(parsedFile.data.entries)).get(id);
63
+ if (entry === undefined)
64
+ return unreadable(file, `it has no entry ${id}`);
65
+ const parsed = ENTRY_SCHEMA.safeParse(entry);
66
+ if (!parsed.success)
67
+ return unreadable(file, `the fields of ${id} have the wrong shape`);
68
+ const { constraints } = parsed.data;
69
+ const { details, examples, default_notes: defaultNotes } = parsed.data.help ?? parsed.data;
70
+ return { kind: 'read', notes: { details, constraints, examples, defaultNotes: new Map(Object.entries(defaultNotes)) } };
71
+ }
72
+ //# sourceMappingURL=authored-notes.js.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ CHANGELOG ファイルのパスを解決する。存在しない場合もパスだけ返す。
3
+ 明示指定(空でない文字列)があればそれ、無ければ CHANGELOG.md → AIST-CHANGELOG.md の順に存在を確かめ、どちらも無ければ CHANGELOG.md。
4
+ 明示指定が絶対パスならそのまま返す(pathlib の / と同じ)
5
+ */
6
+ export declare function resolveChangelogPath(gitRoot: string, changelogFile?: string): string;
7
+ /**
8
+ ファイルがあれば内容、無ければ undefined
9
+ */
10
+ export declare function readChangelogIfExists(changelogPath: string): string | undefined;
11
+ /**
12
+ ファイルから最新バージョンを取る。ファイルが無ければ ChangelogFileNotFoundError
13
+ */
14
+ export declare function readLatestVersionFromFile(changelogPath: string): string;
15
+ /**
16
+ ファイルから指定バージョンのリリースノートを抽出する。ファイルが無ければ ChangelogFileNotFoundError
17
+ */
18
+ export declare function extractReleaseNotesFromFile(changelogPath: string, version: string): string;
19
+ //# sourceMappingURL=changelog-file.d.ts.map