@pecot/workflow-mcp 0.0.0-stage → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/.claude-plugin/plugin.json +8 -0
  2. package/LICENSE +21 -0
  3. package/README.md +126 -2
  4. package/bin/pecot-workflow-mcp.mjs +10 -0
  5. package/cli/dist/cli.d.ts +26 -0
  6. package/cli/dist/cli.js +222 -0
  7. package/cli/dist/commands/cell-table.d.ts +3 -0
  8. package/cli/dist/commands/cell-table.js +495 -0
  9. package/cli/dist/commands/command-binding.d.ts +26 -0
  10. package/cli/dist/commands/command-binding.js +266 -0
  11. package/cli/dist/commands/command-definition.d.ts +136 -0
  12. package/cli/dist/commands/command-definition.js +101 -0
  13. package/cli/dist/commands/command-help.d.ts +8 -0
  14. package/cli/dist/commands/command-help.js +173 -0
  15. package/cli/dist/commands/command-stop.d.ts +19 -0
  16. package/cli/dist/commands/command-stop.js +30 -0
  17. package/cli/dist/commands/dependabot.d.ts +3 -0
  18. package/cli/dist/commands/dependabot.js +165 -0
  19. package/cli/dist/commands/directory-option.d.ts +7 -0
  20. package/cli/dist/commands/directory-option.js +48 -0
  21. package/cli/dist/commands/failure.d.ts +13 -0
  22. package/cli/dist/commands/failure.js +33 -0
  23. package/cli/dist/commands/fuzzy.d.ts +7 -0
  24. package/cli/dist/commands/fuzzy.js +79 -0
  25. package/cli/dist/commands/github-client.d.ts +12 -0
  26. package/cli/dist/commands/github-client.js +23 -0
  27. package/cli/dist/commands/global-options.d.ts +25 -0
  28. package/cli/dist/commands/global-options.js +83 -0
  29. package/cli/dist/commands/help-layout.d.ts +40 -0
  30. package/cli/dist/commands/help-layout.js +117 -0
  31. package/cli/dist/commands/help.d.ts +8 -0
  32. package/cli/dist/commands/help.js +55 -0
  33. package/cli/dist/commands/input-schema.d.ts +14 -0
  34. package/cli/dist/commands/input-schema.js +56 -0
  35. package/cli/dist/commands/issue-board.d.ts +38 -0
  36. package/cli/dist/commands/issue-board.js +62 -0
  37. package/cli/dist/commands/issue-comment.d.ts +3 -0
  38. package/cli/dist/commands/issue-comment.js +196 -0
  39. package/cli/dist/commands/issue-create.d.ts +3 -0
  40. package/cli/dist/commands/issue-create.js +329 -0
  41. package/cli/dist/commands/issue-project.d.ts +3 -0
  42. package/cli/dist/commands/issue-project.js +176 -0
  43. package/cli/dist/commands/issue-quick.d.ts +3 -0
  44. package/cli/dist/commands/issue-quick.js +126 -0
  45. package/cli/dist/commands/issue-read.d.ts +3 -0
  46. package/cli/dist/commands/issue-read.js +80 -0
  47. package/cli/dist/commands/issue-shared.d.ts +159 -0
  48. package/cli/dist/commands/issue-shared.js +419 -0
  49. package/cli/dist/commands/issue.d.ts +4 -0
  50. package/cli/dist/commands/issue.js +15 -0
  51. package/cli/dist/commands/names.d.ts +9 -0
  52. package/cli/dist/commands/names.js +16 -0
  53. package/cli/dist/commands/output.d.ts +78 -0
  54. package/cli/dist/commands/output.js +187 -0
  55. package/cli/dist/commands/pr.d.ts +3 -0
  56. package/cli/dist/commands/pr.js +933 -0
  57. package/cli/dist/commands/project-info.d.ts +48 -0
  58. package/cli/dist/commands/project-info.js +181 -0
  59. package/cli/dist/commands/project-sync.d.ts +91 -0
  60. package/cli/dist/commands/project-sync.js +273 -0
  61. package/cli/dist/commands/project.d.ts +5 -0
  62. package/cli/dist/commands/project.js +677 -0
  63. package/cli/dist/commands/registry.d.ts +6 -0
  64. package/cli/dist/commands/registry.js +27 -0
  65. package/cli/dist/commands/release.d.ts +10 -0
  66. package/cli/dist/commands/release.js +414 -0
  67. package/cli/dist/commands/repository-display.d.ts +3 -0
  68. package/cli/dist/commands/repository-display.js +7 -0
  69. package/cli/dist/commands/repository-match.d.ts +14 -0
  70. package/cli/dist/commands/repository-match.js +33 -0
  71. package/cli/dist/commands/repository.d.ts +5 -0
  72. package/cli/dist/commands/repository.js +265 -0
  73. package/cli/dist/commands/rich-panel.d.ts +22 -0
  74. package/cli/dist/commands/rich-panel.js +295 -0
  75. package/cli/dist/commands/security.d.ts +3 -0
  76. package/cli/dist/commands/security.js +164 -0
  77. package/cli/dist/commands/session.d.ts +3 -0
  78. package/cli/dist/commands/session.js +161 -0
  79. package/cli/dist/commands/tracker-sync.d.ts +58 -0
  80. package/cli/dist/commands/tracker-sync.js +53 -0
  81. package/cli/dist/commands/usage-error.d.ts +47 -0
  82. package/cli/dist/commands/usage-error.js +72 -0
  83. package/cli/dist/commands/value-types.d.ts +46 -0
  84. package/cli/dist/commands/value-types.js +94 -0
  85. package/cli/dist/commands/work-target.d.ts +13 -0
  86. package/cli/dist/commands/work-target.js +41 -0
  87. package/cli/dist/commands/worktree.d.ts +3 -0
  88. package/cli/dist/commands/worktree.js +335 -0
  89. package/cli/dist/domain/api-error-detail.d.ts +10 -0
  90. package/cli/dist/domain/api-error-detail.js +25 -0
  91. package/cli/dist/domain/branch-name.d.ts +5 -0
  92. package/cli/dist/domain/branch-name.js +10 -0
  93. package/cli/dist/domain/changelog.d.ts +43 -0
  94. package/cli/dist/domain/changelog.js +107 -0
  95. package/cli/dist/domain/config.d.ts +215 -0
  96. package/cli/dist/domain/config.js +300 -0
  97. package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
  98. package/cli/dist/domain/dependabot-pull-requests.js +338 -0
  99. package/cli/dist/domain/dependabot-source.d.ts +51 -0
  100. package/cli/dist/domain/dependabot-source.js +4 -0
  101. package/cli/dist/domain/dependabot.d.ts +47 -0
  102. package/cli/dist/domain/dependabot.js +88 -0
  103. package/cli/dist/domain/errors.d.ts +19 -0
  104. package/cli/dist/domain/errors.js +31 -0
  105. package/cli/dist/domain/field-options.d.ts +31 -0
  106. package/cli/dist/domain/field-options.js +44 -0
  107. package/cli/dist/domain/format.d.ts +47 -0
  108. package/cli/dist/domain/format.js +168 -0
  109. package/cli/dist/domain/frontmatter.d.ts +122 -0
  110. package/cli/dist/domain/frontmatter.js +264 -0
  111. package/cli/dist/domain/git-runner.d.ts +10 -0
  112. package/cli/dist/domain/git-runner.js +4 -0
  113. package/cli/dist/domain/git-url.d.ts +17 -0
  114. package/cli/dist/domain/git-url.js +30 -0
  115. package/cli/dist/domain/issue-kind.d.ts +16 -0
  116. package/cli/dist/domain/issue-kind.js +16 -0
  117. package/cli/dist/domain/issue-readout.d.ts +107 -0
  118. package/cli/dist/domain/issue-readout.js +4 -0
  119. package/cli/dist/domain/json-null.d.ts +2 -0
  120. package/cli/dist/domain/json-null.js +5 -0
  121. package/cli/dist/domain/json.d.ts +21 -0
  122. package/cli/dist/domain/json.js +47 -0
  123. package/cli/dist/domain/prerequisites.d.ts +32 -0
  124. package/cli/dist/domain/prerequisites.js +192 -0
  125. package/cli/dist/domain/pull-request.d.ts +134 -0
  126. package/cli/dist/domain/pull-request.js +232 -0
  127. package/cli/dist/domain/python-format.d.ts +105 -0
  128. package/cli/dist/domain/python-format.js +304 -0
  129. package/cli/dist/domain/readiness.d.ts +172 -0
  130. package/cli/dist/domain/readiness.js +280 -0
  131. package/cli/dist/domain/reference-parser.d.ts +49 -0
  132. package/cli/dist/domain/reference-parser.js +119 -0
  133. package/cli/dist/domain/release.d.ts +49 -0
  134. package/cli/dist/domain/release.js +72 -0
  135. package/cli/dist/domain/repository-policy.d.ts +32 -0
  136. package/cli/dist/domain/repository-policy.js +65 -0
  137. package/cli/dist/domain/repository-resolver.d.ts +57 -0
  138. package/cli/dist/domain/repository-resolver.js +119 -0
  139. package/cli/dist/domain/sections.d.ts +69 -0
  140. package/cli/dist/domain/sections.js +514 -0
  141. package/cli/dist/domain/security-alerts-source.d.ts +29 -0
  142. package/cli/dist/domain/security-alerts-source.js +4 -0
  143. package/cli/dist/domain/security-alerts.d.ts +52 -0
  144. package/cli/dist/domain/security-alerts.js +107 -0
  145. package/cli/dist/domain/security-tracker.d.ts +115 -0
  146. package/cli/dist/domain/security-tracker.js +353 -0
  147. package/cli/dist/domain/state.d.ts +29 -0
  148. package/cli/dist/domain/state.js +56 -0
  149. package/cli/dist/domain/tracker-body.d.ts +70 -0
  150. package/cli/dist/domain/tracker-body.js +65 -0
  151. package/cli/dist/domain/yaml-document.d.ts +5 -0
  152. package/cli/dist/domain/yaml-document.js +206 -0
  153. package/cli/dist/infra/authored-notes.d.ts +37 -0
  154. package/cli/dist/infra/authored-notes.js +66 -0
  155. package/cli/dist/infra/changelog-file.d.ts +19 -0
  156. package/cli/dist/infra/changelog-file.js +43 -0
  157. package/cli/dist/infra/child-stdin.d.ts +4 -0
  158. package/cli/dist/infra/child-stdin.js +8 -0
  159. package/cli/dist/infra/config-store.d.ts +49 -0
  160. package/cli/dist/infra/config-store.js +121 -0
  161. package/cli/dist/infra/diagnostics.d.ts +9 -0
  162. package/cli/dist/infra/diagnostics.js +2 -0
  163. package/cli/dist/infra/file-kind.d.ts +9 -0
  164. package/cli/dist/infra/file-kind.js +26 -0
  165. package/cli/dist/infra/frontmatter-file.d.ts +14 -0
  166. package/cli/dist/infra/frontmatter-file.js +30 -0
  167. package/cli/dist/infra/git.d.ts +74 -0
  168. package/cli/dist/infra/git.js +133 -0
  169. package/cli/dist/infra/github/auth.d.ts +60 -0
  170. package/cli/dist/infra/github/auth.js +158 -0
  171. package/cli/dist/infra/github/client.d.ts +173 -0
  172. package/cli/dist/infra/github/client.js +576 -0
  173. package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
  174. package/cli/dist/infra/github/dependabot-source.js +33 -0
  175. package/cli/dist/infra/github/errors.d.ts +47 -0
  176. package/cli/dist/infra/github/errors.js +42 -0
  177. package/cli/dist/infra/github/index.d.ts +13 -0
  178. package/cli/dist/infra/github/index.js +19 -0
  179. package/cli/dist/infra/github/issues.d.ts +129 -0
  180. package/cli/dist/infra/github/issues.js +273 -0
  181. package/cli/dist/infra/github/payload.d.ts +44 -0
  182. package/cli/dist/infra/github/payload.js +80 -0
  183. package/cli/dist/infra/github/projects.d.ts +108 -0
  184. package/cli/dist/infra/github/projects.js +303 -0
  185. package/cli/dist/infra/github/pulls.d.ts +80 -0
  186. package/cli/dist/infra/github/pulls.js +161 -0
  187. package/cli/dist/infra/github/queries.d.ts +36 -0
  188. package/cli/dist/infra/github/queries.js +883 -0
  189. package/cli/dist/infra/github/readout.d.ts +18 -0
  190. package/cli/dist/infra/github/readout.js +156 -0
  191. package/cli/dist/infra/github/repos.d.ts +68 -0
  192. package/cli/dist/infra/github/repos.js +137 -0
  193. package/cli/dist/infra/github/rest-path.d.ts +14 -0
  194. package/cli/dist/infra/github/rest-path.js +31 -0
  195. package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
  196. package/cli/dist/infra/github/security-alerts-source.js +73 -0
  197. package/cli/dist/infra/gitignore-spec.d.ts +36 -0
  198. package/cli/dist/infra/gitignore-spec.js +235 -0
  199. package/cli/dist/infra/nx-scope.d.ts +51 -0
  200. package/cli/dist/infra/nx-scope.js +182 -0
  201. package/cli/dist/infra/os-error.d.ts +24 -0
  202. package/cli/dist/infra/os-error.js +38 -0
  203. package/cli/dist/infra/paths.d.ts +88 -0
  204. package/cli/dist/infra/paths.js +234 -0
  205. package/cli/dist/infra/state-store.d.ts +45 -0
  206. package/cli/dist/infra/state-store.js +118 -0
  207. package/cli/dist/infra/template-store.d.ts +15 -0
  208. package/cli/dist/infra/template-store.js +34 -0
  209. package/cli/dist/infra/text-file.d.ts +12 -0
  210. package/cli/dist/infra/text-file.js +33 -0
  211. package/cli/dist/infra/worktree-copy.d.ts +24 -0
  212. package/cli/dist/infra/worktree-copy.js +95 -0
  213. package/cli/dist/infra/worktree-links.d.ts +139 -0
  214. package/cli/dist/infra/worktree-links.js +433 -0
  215. package/cli/dist/infra/worktree-setup.d.ts +21 -0
  216. package/cli/dist/infra/worktree-setup.js +41 -0
  217. package/cli/dist/infra/worktree.d.ts +174 -0
  218. package/cli/dist/infra/worktree.js +567 -0
  219. package/cli/dist/mcp/result.d.ts +33 -0
  220. package/cli/dist/mcp/result.js +52 -0
  221. package/cli/dist/mcp/serve.d.ts +51 -0
  222. package/cli/dist/mcp/serve.js +183 -0
  223. package/cli/dist/mcp/server.d.ts +21 -0
  224. package/cli/dist/mcp/server.js +128 -0
  225. package/cli/dist/mcp/session-directory.d.ts +26 -0
  226. package/cli/dist/mcp/session-directory.js +84 -0
  227. package/cli/dist/package.json +1 -0
  228. package/cli/dist/version.d.ts +17 -0
  229. package/cli/dist/version.js +42 -0
  230. package/cli/templates/comment/merge-diff.md +34 -0
  231. package/cli/templates/comment/plan.md +181 -0
  232. package/cli/templates/comment/precede-notify.md +33 -0
  233. package/cli/templates/comment/review-findings.md +42 -0
  234. package/cli/templates/comment/review-resolution.md +48 -0
  235. package/cli/templates/issue/bug.md +63 -0
  236. package/cli/templates/issue/epic.md +54 -0
  237. package/cli/templates/issue/task-implement.md +67 -0
  238. package/cli/templates/issue/task.md +48 -0
  239. package/cli/templates/issue/tracker.md +48 -0
  240. package/cli/templates/pr/create.md +123 -0
  241. package/cli/templates/pr/release.md +56 -0
  242. package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
  243. package/npm-shrinkwrap.json +83 -0
  244. package/package.json +22 -4
@@ -0,0 +1,235 @@
1
+ // gitignore 形式のパターンでパスを判定する。Python の pathspec の GitIgnoreSpec(1.1.1)を写したもの。
2
+ //
3
+ // 写したものは次の 2 つ。
4
+ // - GitIgnoreSpecPattern.pattern_to_regex(パターンから正規表現への変換)。
5
+ // - 簡易 backend の match_file(dir の印の優先規則)。
6
+ // `ignore` パッケージは使わない。
7
+ // 否定パターンを組んだ `.nx/` などで、pathspec と判定が分かれるため。
8
+ //
9
+ // 正規表現の差は次のように吸収する。
10
+ // - 名前付きグループは、Python の書式から JS の書式に直す。
11
+ // - Python の `.` は \n 以外すべてに当たるので、`[^\n]` と書く。
12
+ // - 文字クラスの先頭の `]` は `\]` にする。そのままだと JS では空の文字クラスになる。
13
+ // - 正規表現は `u` フラグで作る。
14
+ //
15
+ // 範囲が逆(`[z-a]` など)のパターンは、Python では re.error、ここでは SyntaxError を投げる。
16
+ import { InvalidValueError } from '../domain/errors.js';
17
+ import { pythonRightStrip, pythonStringRepr, splitCodePoints } from '../domain/python-format.js';
18
+ const DIRECTORY_MARK = 'ps_d';
19
+ const DIRECTORY_MARK_GROUP = `(?<${DIRECTORY_MARK}>/)`;
20
+ const DIRECTORY_MARK_OPTIONAL = `(?:${DIRECTORY_MARK_GROUP}|$)`;
21
+ const ANY_CHARACTER = '[^\\n]';
22
+ /**
23
+ パターンが不正(Python の GitIgnorePatternError に当たる)
24
+ */
25
+ export class GitIgnorePatternError extends InvalidValueError {
26
+ }
27
+ // 範囲の記法が不正なパターンは、git が捨てるので、パターンごと無効にする
28
+ class RangeNotationError extends GitIgnorePatternError {
29
+ }
30
+ // glob のワイルドカードに当たる式(アスタリスクは `/` 以外の 0 文字以上、疑問符は `/` 以外の 1 文字)
31
+ const GLOB_WILDCARDS = new Map([['*', '[^/]*'], ['?', '[^/]']]);
32
+ const REGEX_SYNTAX_CHARACTERS = new Set('\\^$.*+?()[]{}|');
33
+ function escapeCharacter(character) {
34
+ return REGEX_SYNTAX_CHARACTERS.has(character) ? `\\${character}` : character;
35
+ }
36
+ // 括弧式の中身は正規表現にそのまま入れる。先頭の `]` は文字なので、JS で空の文字クラスにならないよう escape する
37
+ function bracketBody(body) {
38
+ return body.startsWith(']') ? `\\${body}` : body;
39
+ }
40
+ // `[` の次の位置から括弧式を読む。感嘆符かキャレットで始まれば否定。
41
+ // 閉じる `]` が無ければ RangeNotationError
42
+ function translateBracketExpression(characters, start, pattern) {
43
+ const end = characters.length;
44
+ let close = start;
45
+ if (close < end && ['!', '^'].includes(characters.at(close) ?? ''))
46
+ close += 1;
47
+ if (close < end && characters.at(close) === ']')
48
+ close += 1;
49
+ while (close < end && characters.at(close) !== ']')
50
+ close += 1;
51
+ if (close >= end) {
52
+ throw new RangeNotationError(`Invalid range notation=${pythonStringRepr(characters.slice(start, close).join(''))} found in pattern=${pythonStringRepr(pattern)}.`);
53
+ }
54
+ // キャレットによる否定は POSIX では未定義だが、git に合わせて感嘆符と同じく否定にする
55
+ const isNegated = ['!', '^'].includes(characters.at(start) ?? '');
56
+ const bodyStart = isNegated ? start + 1 : start;
57
+ const body = characters.slice(bodyStart, close + 1).join('').replaceAll('\\', '\\\\');
58
+ return { expression: `[${isNegated ? '^' : ''}${bracketBody(body)}`, next: close + 1 };
59
+ }
60
+ // fnmatch.translate を元にした、1 セグメントの glob → 正規表現(FNM_PATHNAME 相当)
61
+ function translateSegmentGlob(pattern) {
62
+ const characters = splitCodePoints(pattern);
63
+ let regex = '';
64
+ let index = 0;
65
+ while (index < characters.length) {
66
+ const character = characters.at(index) ?? '';
67
+ if (character === '\\') {
68
+ const escaped = characters.at(index + 1);
69
+ if (escaped === undefined)
70
+ throw new InvalidValueError(`Escape character found with no next character to escape: ${pythonStringRepr(pattern)}`);
71
+ regex += escapeCharacter(escaped);
72
+ index += 2;
73
+ }
74
+ else if (character === '[') {
75
+ const bracket = translateBracketExpression(characters, index + 1, pattern);
76
+ regex += bracket.expression;
77
+ index = bracket.next;
78
+ }
79
+ else {
80
+ regex += GLOB_WILDCARDS.get(character) ?? escapeCharacter(character);
81
+ index += 1;
82
+ }
83
+ }
84
+ return regex;
85
+ }
86
+ // `**` や `*` など、特別扱いして式を直接返すパターンがある
87
+ function normalizeSegments(isDirectoryPattern, original) {
88
+ const segments = [...original];
89
+ if (segments.at(0) === '') {
90
+ // 先頭が `/` のパターンは root 基準。空の先頭を除く
91
+ segments.shift();
92
+ }
93
+ else if ((segments.length === 1 || (segments.length === 2 && segments.at(1) === '')) && segments.at(0) !== '**') {
94
+ // セグメントが 1 つのパターンは、`**/` を前に足したものと同じ
95
+ segments.unshift('**');
96
+ }
97
+ if (segments.length === 0)
98
+ throw new InvalidValueError('Pattern normalized to nothing.');
99
+ // 末尾が `/` のパターンは、配下のすべてに当たる(`{pattern}/**`)
100
+ if (segments.at(-1) === '')
101
+ segments[segments.length - 1] = '**';
102
+ // `**/**` を 1 つにする
103
+ for (let index = segments.length - 1; index > 0; index -= 1) {
104
+ if (segments.at(index - 1) === '**' && segments.at(index) === '**')
105
+ segments.splice(index, 1);
106
+ }
107
+ const [first, second, third] = segments;
108
+ if (first === '**' && segments.length === 1)
109
+ return { kind: 'override', source: isDirectoryPattern ? DIRECTORY_MARK_GROUP : '.' };
110
+ if (first === '**' && second === '*' && segments.length === 2)
111
+ return { kind: 'override', source: '.' };
112
+ if (first === '**' && second === '*' && third === '**' && segments.length === 3)
113
+ return { kind: 'override', source: isDirectoryPattern ? DIRECTORY_MARK_GROUP : '/' };
114
+ return { kind: 'segments', segments };
115
+ }
116
+ function translateSegments(isDirectoryPattern, segments) {
117
+ const parts = [];
118
+ let isNeedsSlash = false;
119
+ const last = segments.length - 1;
120
+ for (const [index, segment] of segments.entries()) {
121
+ if (segment === '**') {
122
+ if (index === 0) {
123
+ parts.push(`^(?:${ANY_CHARACTER}+/)?`);
124
+ }
125
+ else if (index < last) {
126
+ parts.push(`(?:/${ANY_CHARACTER}+)?`);
127
+ isNeedsSlash = true;
128
+ }
129
+ else {
130
+ parts.push(isDirectoryPattern ? DIRECTORY_MARK_GROUP : '/');
131
+ }
132
+ }
133
+ else {
134
+ if (index === 0)
135
+ parts.push('^');
136
+ if (isNeedsSlash)
137
+ parts.push('/');
138
+ parts.push(segment === '*' ? '[^/]+' : translateSegmentGlob(segment));
139
+ if (index === last)
140
+ parts.push(DIRECTORY_MARK_OPTIONAL);
141
+ isNeedsSlash = true;
142
+ }
143
+ }
144
+ return parts.join('');
145
+ }
146
+ /**
147
+ パターン 1 行を正規表現にする。何にも当たらないパターン(空行・コメント・`/` 単体・範囲の記法が不正)は undefined。
148
+ 感嘆符だけのパターンと、末尾が `\` のパターンは GitIgnorePatternError
149
+ */
150
+ export function patternToRegex(line) {
151
+ // 末尾の `\ ` は、空白を escape したもの。それ以外は末尾の空白を落とす(先頭の空白は残す)
152
+ const pattern = line.endsWith('\\ ') ? line : pythonRightStrip(line);
153
+ if (pattern === '' || pattern === '/' || pattern.startsWith('#'))
154
+ return undefined;
155
+ const isInclude = !pattern.startsWith('!');
156
+ const body = isInclude ? pattern : pattern.slice(1);
157
+ const originalSegments = body.split('/');
158
+ const isDirectoryPattern = originalSegments.at(-1) === '';
159
+ const invalid = (cause) => new GitIgnorePatternError(`Invalid git pattern: ${pythonStringRepr(line)}`, { cause });
160
+ let normalized;
161
+ try {
162
+ normalized = normalizeSegments(isDirectoryPattern, originalSegments);
163
+ }
164
+ catch (error) {
165
+ if (error instanceof InvalidValueError)
166
+ throw invalid(error);
167
+ throw error;
168
+ }
169
+ if (normalized.kind === 'override')
170
+ return { source: normalized.source, include: isInclude };
171
+ try {
172
+ return { source: translateSegments(isDirectoryPattern, normalized.segments), include: isInclude };
173
+ }
174
+ catch (error) {
175
+ // 範囲の記法が不正なパターンは、git が捨てるので無効にする
176
+ if (error instanceof RangeNotationError)
177
+ return undefined;
178
+ if (error instanceof InvalidValueError)
179
+ throw invalid(error);
180
+ throw error;
181
+ }
182
+ }
183
+ function normalizeFile(file) {
184
+ if (file.startsWith('/'))
185
+ return file.slice(1);
186
+ return file.startsWith('./') ? file.slice(2) : file;
187
+ }
188
+ function buildPattern(compiled) {
189
+ // eslint-disable-next-line security/detect-non-literal-regexp -- gitignore のパターンを正規表現にするのがこのモジュールの目的。source は patternToRegex が組む
190
+ const regex = new RegExp(compiled.source, 'u');
191
+ return {
192
+ include: compiled.include,
193
+ match: (file) => {
194
+ const found = regex.exec(file);
195
+ if (found === null)
196
+ return 'none';
197
+ return found.groups?.['ps_d'] ? 'directory' : 'file';
198
+ },
199
+ };
200
+ }
201
+ // 後ろのパターンから見る。dir の印で当たったもの(優先度 1)より、ファイルとして当たったもの(優先度 2)が勝つ。
202
+ // 優先度 2 の最初の一致で止める
203
+ function isExcluded(reversedPatterns, file) {
204
+ let isIncluded = false;
205
+ let bestPriority = 0;
206
+ for (const pattern of reversedPatterns) {
207
+ const kind = pattern.match(file);
208
+ if (kind === 'none')
209
+ continue;
210
+ const priority = kind === 'directory' ? 1 : 2;
211
+ if (priority > bestPriority) {
212
+ isIncluded = pattern.include;
213
+ bestPriority = priority;
214
+ }
215
+ if (priority === 2)
216
+ return isIncluded;
217
+ }
218
+ return isIncluded;
219
+ }
220
+ function compilePattern(line) {
221
+ const compiled = patternToRegex(line);
222
+ return compiled === undefined ? undefined : buildPattern(compiled);
223
+ }
224
+ /**
225
+ パターンの行からコンパイルする。空の行は読み飛ばす(空白だけの行は、何にも当たらないパターンとして数える)
226
+ */
227
+ export function compileGitIgnoreSpec(lines) {
228
+ const matchable = lines.filter(line => line !== '').map(line => compilePattern(line)).filter(pattern => pattern !== undefined);
229
+ const reversed = matchable.toReversed();
230
+ return {
231
+ matchablePatternCount: matchable.length,
232
+ matchFile: file => isExcluded(reversed, normalizeFile(file)),
233
+ };
234
+ }
235
+ //# sourceMappingURL=gitignore-spec.js.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ nx graph の実行上限(秒)
3
+ */
4
+ export declare const NX_GRAPH_TIMEOUT_SECONDS = 120;
5
+ /**
6
+ どの nx プロジェクトにも属さないファイルを表す scope
7
+ */
8
+ export declare const REPOSITORY_SCOPE = "repo";
9
+ /**
10
+ nx 実行ファイルを返す(`<toplevel>/node_modules/.bin/nx` → PATH 上の `nx`)。
11
+ `npx --no-install` は未導入時に registry へ問い合わせ、symlink 経由では別 worktree の nx を拾うため使わない
12
+ */
13
+ export declare function resolveNx(toplevel: string): string | undefined;
14
+ export interface NxProject {
15
+ /**
16
+ リポジトリ直下からの root(`.` はリポジトリ直下)
17
+ */
18
+ readonly root: string;
19
+ /**
20
+ PR タイトルの scope。tag `scope:<名前>` の値、無ければプロジェクト名
21
+ */
22
+ readonly scope: string;
23
+ }
24
+ export interface NxGraphOptions {
25
+ /**
26
+ nx graph の実行上限(秒)。既定は NX_GRAPH_TIMEOUT_SECONDS
27
+ */
28
+ readonly timeoutSeconds?: number | undefined;
29
+ }
30
+ /**
31
+ nx の project graph から `{プロジェクト名: NxProject}` を返す。stdout では大きな JSON が切れるため、一時ファイルに書かせて読む。
32
+ nx が無い・実行失敗・部分 graph・JSON の解析失敗なら undefined
33
+ */
34
+ export declare function nxProjects(toplevel: string, options?: Readonly<NxGraphOptions>): ReadonlyMap<string, NxProject> | undefined;
35
+ /**
36
+ `baseReference...head` の変更ファイル(リポジトリ root からの相対パス)を返す。
37
+ rename 検出だと移動元のプロジェクトが漏れ、`core.quotePath` だと非 ASCII パスが一致しなくなるため、`--no-renames` と NUL 区切りで取る。
38
+ baseReference / head が解決できない・git 失敗・git が無いなら undefined
39
+ */
40
+ export declare function changedFiles(toplevel: string, baseReference: string, head: string): readonly string[] | undefined;
41
+ /**
42
+ 変更ファイルから期待する scope を、昇順で返す。持ち主は project root との最長一致で決め、どれにも属さないファイルがあれば末尾に `repo` を足す。
43
+ `.nx/version-plans/` 配下は数えない。
44
+ */
45
+ export declare function expectedScope(files: readonly string[], projects: ReadonlyMap<string, NxProject>): readonly string[];
46
+ /**
47
+ PR タイトルの `type(scope):` から scope を `,` で分けて返す。空白は削らない(規則は空白なしの `,` 区切り)。
48
+ scope が無い・空なら undefined
49
+ */
50
+ export declare function parseTitleScope(title: string): readonly string[] | undefined;
51
+ //# sourceMappingURL=nx-scope.d.ts.map
@@ -0,0 +1,182 @@
1
+ /* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側が渡すリポジトリルート配下 */
2
+ // 変更した nx プロジェクトから PR タイトルの scope を算出する。
3
+ //
4
+ // 割り当ては `.githooks/pre-push/check-version-plan-required.sh` と同じ規則。
5
+ // nx の project graph → git diff → project root との最長一致、の順で求める。
6
+ // 判定できない場合は例外ではなく undefined を返し、呼び出し側が警告して割り当てを飛ばす(フェイルオープン)。
7
+ import { spawnSync } from 'node:child_process';
8
+ import { accessSync, constants, mkdirSync, mkdtempSync, rmSync, statSync } from 'node:fs';
9
+ import path from 'node:path';
10
+ import { isJsonObject, jsonField, tryParseJsonText } from '../domain/json.js';
11
+ import { compareStrings, isJsonArray, pythonRepr } from '../domain/python-format.js';
12
+ import { GitCommandError, runGit } from './git.js';
13
+ import { isFileNotFound } from './os-error.js';
14
+ import { TMP_DIR } from './paths.js';
15
+ import { readTextFile } from './text-file.js';
16
+ /**
17
+ nx graph の実行上限(秒)
18
+ */
19
+ export const NX_GRAPH_TIMEOUT_SECONDS = 120;
20
+ /**
21
+ どの nx プロジェクトにも属さないファイルを表す scope
22
+ */
23
+ export const REPOSITORY_SCOPE = 'repo';
24
+ // PR タイトルの scope を宣言する nx の tag の接頭辞
25
+ const SCOPE_TAG_PREFIX = 'scope:';
26
+ // nx 固定のリリース用メタデータ。scope の算出から除外する
27
+ const VERSION_PLANS_PREFIX = '.nx/version-plans/';
28
+ // `type(scope): ...` の scope 部分。破壊的変更の印が付く形も受ける
29
+ const TITLE_SCOPE_PATTERN = /^[A-Za-z]+\(([^()]*)\)!?:/u;
30
+ function isExecutableFile(target) {
31
+ try {
32
+ if (statSync(target).isDirectory())
33
+ return false;
34
+ accessSync(target, constants.X_OK);
35
+ return true;
36
+ }
37
+ catch {
38
+ // stat・access が投げるのはシステムエラーだけ。Python の os.access と同じく、使えないものは偽にする
39
+ return false;
40
+ }
41
+ }
42
+ // PATH 上の実行ファイル(shutil.which と同じ。PATH の空の要素は、カレントディレクトリとして探す)
43
+ function whichExecutable(name) {
44
+ const searchPath = process.env['PATH'] ?? '/bin:/usr/bin';
45
+ return searchPath.split(path.delimiter).map(directory => path.join(directory, name)).find(candidate => isExecutableFile(candidate));
46
+ }
47
+ /**
48
+ nx 実行ファイルを返す(`<toplevel>/node_modules/.bin/nx` → PATH 上の `nx`)。
49
+ `npx --no-install` は未導入時に registry へ問い合わせ、symlink 経由では別 worktree の nx を拾うため使わない
50
+ */
51
+ export function resolveNx(toplevel) {
52
+ const local = path.join(toplevel, 'node_modules', '.bin', 'nx');
53
+ return isExecutableFile(local) ? local : whichExecutable('nx');
54
+ }
55
+ // tag `scope:<名前>` の値。無い・空ならプロジェクト名
56
+ function scopeOf(name, tags) {
57
+ if (!isJsonArray(tags))
58
+ return name;
59
+ for (const tag of tags) {
60
+ if (typeof tag === 'string' && tag.startsWith(SCOPE_TAG_PREFIX) && tag.length > SCOPE_TAG_PREFIX.length)
61
+ return tag.slice(SCOPE_TAG_PREFIX.length);
62
+ }
63
+ return name;
64
+ }
65
+ function projectsFromGraph(text) {
66
+ const graph = tryParseJsonText(text);
67
+ const projects = new Map();
68
+ const nodes = jsonField(jsonField(graph, 'graph'), 'nodes');
69
+ if (!isJsonObject(nodes))
70
+ return undefined;
71
+ for (const [name, node] of Object.entries(nodes)) {
72
+ const data = jsonField(node, 'data');
73
+ const root = jsonField(data, 'root');
74
+ // root は文字列のはず。他の型も Python の str() と同じ文字列にする
75
+ if (root === undefined)
76
+ return undefined;
77
+ projects.set(name, {
78
+ root: (typeof root === 'string' ? root : pythonRepr(root)).replace(/\/+$/u, '') || '.',
79
+ scope: scopeOf(name, jsonField(data, 'tags')),
80
+ });
81
+ }
82
+ return projects;
83
+ }
84
+ /**
85
+ nx の project graph から `{プロジェクト名: NxProject}` を返す。stdout では大きな JSON が切れるため、一時ファイルに書かせて読む。
86
+ nx が無い・実行失敗・部分 graph・JSON の解析失敗なら undefined
87
+ */
88
+ export function nxProjects(toplevel, options = {}) {
89
+ const nx = resolveNx(toplevel);
90
+ if (nx === undefined)
91
+ return undefined;
92
+ const temporaryBase = path.join(toplevel, TMP_DIR);
93
+ let work;
94
+ try {
95
+ mkdirSync(temporaryBase, { recursive: true });
96
+ work = mkdtempSync(path.join(temporaryBase, 'nx-scope.'));
97
+ }
98
+ catch {
99
+ return undefined;
100
+ }
101
+ try {
102
+ const graphFile = path.join(work, 'graph.json');
103
+ const result = spawnSync(nx, ['graph', `--file=${graphFile}`], {
104
+ cwd: toplevel,
105
+ encoding: 'utf8',
106
+ stdio: ['ignore', 'pipe', 'pipe'],
107
+ timeout: (options.timeoutSeconds ?? NX_GRAPH_TIMEOUT_SECONDS) * 1000,
108
+ killSignal: 'SIGKILL',
109
+ // interface-env: none
110
+ env: { ...process.env, NX_DAEMON: 'false' },
111
+ });
112
+ if (result.error !== undefined || result.status !== 0 || result.stderr.includes('Showing partial graph'))
113
+ return undefined;
114
+ let text;
115
+ try {
116
+ text = readTextFile(graphFile);
117
+ }
118
+ catch {
119
+ return undefined;
120
+ }
121
+ const projects = projectsFromGraph(text);
122
+ return projects === undefined || projects.size === 0 ? undefined : projects;
123
+ }
124
+ finally {
125
+ try {
126
+ rmSync(work, { recursive: true, force: true });
127
+ }
128
+ catch {
129
+ // 後始末の失敗で、本文の結果や例外を上書きしない(Python の ignore_errors=True と同じ)
130
+ }
131
+ }
132
+ }
133
+ /**
134
+ `baseReference...head` の変更ファイル(リポジトリ root からの相対パス)を返す。
135
+ rename 検出だと移動元のプロジェクトが漏れ、`core.quotePath` だと非 ASCII パスが一致しなくなるため、`--no-renames` と NUL 区切りで取る。
136
+ baseReference / head が解決できない・git 失敗・git が無いなら undefined
137
+ */
138
+ export function changedFiles(toplevel, baseReference, head) {
139
+ try {
140
+ for (const reference of [baseReference, head]) {
141
+ runGit(['rev-parse', '--verify', '--quiet', [reference, '^{commit}'].join('')], { cwd: toplevel, check: true });
142
+ }
143
+ const result = runGit(['diff', '-z', '--name-only', '--no-renames', `${baseReference}...${head}`], { cwd: toplevel, check: true });
144
+ return result.stdout.split('\0').filter(file => file !== '');
145
+ }
146
+ catch (error) {
147
+ if (error instanceof GitCommandError || isFileNotFound(error))
148
+ return undefined;
149
+ throw error;
150
+ }
151
+ }
152
+ function isUnder(file, root) {
153
+ return root === '.' || file === root || file.startsWith(`${root}/`);
154
+ }
155
+ /**
156
+ 変更ファイルから期待する scope を、昇順で返す。持ち主は project root との最長一致で決め、どれにも属さないファイルがあれば末尾に `repo` を足す。
157
+ `.nx/version-plans/` 配下は数えない。
158
+ */
159
+ export function expectedScope(files, projects) {
160
+ const ordered = [...projects].map(([, project]) => project).toSorted((a, b) => b.root.length - a.root.length);
161
+ const scopes = new Set();
162
+ let hasOutside = false;
163
+ const counted = files.filter(item => !item.startsWith(VERSION_PLANS_PREFIX));
164
+ for (const file of counted) {
165
+ const owner = ordered.find(project => isUnder(file, project.root));
166
+ if (owner === undefined)
167
+ hasOutside = true;
168
+ else
169
+ scopes.add(owner.scope);
170
+ }
171
+ const scope = [...scopes].filter(item => item !== REPOSITORY_SCOPE).toSorted(compareStrings);
172
+ return hasOutside || scopes.has(REPOSITORY_SCOPE) ? [...scope, REPOSITORY_SCOPE] : scope;
173
+ }
174
+ /**
175
+ PR タイトルの `type(scope):` から scope を `,` で分けて返す。空白は削らない(規則は空白なしの `,` 区切り)。
176
+ scope が無い・空なら undefined
177
+ */
178
+ export function parseTitleScope(title) {
179
+ const scope = TITLE_SCOPE_PATTERN.exec(title)?.[1];
180
+ return scope === undefined || scope === '' ? undefined : scope.split(',');
181
+ }
182
+ //# sourceMappingURL=nx-scope.js.map
@@ -0,0 +1,24 @@
1
+ import { BaseError } from '../domain/errors.js';
2
+ export declare class OsError extends BaseError {
3
+ readonly code: string;
4
+ readonly path: string | undefined;
5
+ constructor(message: string, code: string, path: string | undefined, options?: Readonly<ErrorOptions>);
6
+ }
7
+ /**
8
+ Node のシステムエラー(code が `E` で始まる文字列)か
9
+ */
10
+ export declare function hasErrorCode(error: unknown): error is Error & {
11
+ readonly code: string;
12
+ readonly path?: string;
13
+ readonly dest?: string;
14
+ };
15
+ /**
16
+ システムコールの失敗(Node の fs 等が投げる、syscall を持つエラー)か
17
+ */
18
+ export declare function isSystemCallError(error: unknown): boolean;
19
+ export declare function isFileNotFound(error: unknown): boolean;
20
+ /**
21
+ Node のシステムエラーを OsError にする。errno の表に無い code は元の message を使う。EISDIR のように path を持たないエラーには fallbackPath を付ける。システムエラーでなければそのまま返す
22
+ */
23
+ export declare function toOsError(error: unknown, fallbackPath?: string): unknown;
24
+ //# sourceMappingURL=os-error.d.ts.map
@@ -0,0 +1,38 @@
1
+ // OS のエラー(Python の OSError に当たる)。文言は Python の `[Errno 2] No such file or directory: 'x'` に揃える。
2
+ import { BaseError } from '../domain/errors.js';
3
+ import { formatOsError } from '../domain/python-format.js';
4
+ export class OsError extends BaseError {
5
+ code;
6
+ path;
7
+ constructor(message, code, path, options) {
8
+ super(message, options);
9
+ this.code = code;
10
+ this.path = path;
11
+ }
12
+ }
13
+ /**
14
+ Node のシステムエラー(code が `E` で始まる文字列)か
15
+ */
16
+ export function hasErrorCode(error) {
17
+ return error instanceof Error && 'code' in error && typeof error.code === 'string' && error.code.startsWith('E');
18
+ }
19
+ /**
20
+ システムコールの失敗(Node の fs 等が投げる、syscall を持つエラー)か
21
+ */
22
+ export function isSystemCallError(error) {
23
+ return hasErrorCode(error) && 'syscall' in error;
24
+ }
25
+ export function isFileNotFound(error) {
26
+ return hasErrorCode(error) && error.code === 'ENOENT';
27
+ }
28
+ /**
29
+ Node のシステムエラーを OsError にする。errno の表に無い code は元の message を使う。EISDIR のように path を持たないエラーには fallbackPath を付ける。システムエラーでなければそのまま返す
30
+ */
31
+ export function toOsError(error, fallbackPath) {
32
+ if (!hasErrorCode(error))
33
+ return error;
34
+ const errorPath = error.path ?? fallbackPath;
35
+ const message = formatOsError({ code: error.code, path: errorPath, dest: error.dest }) ?? error.message;
36
+ return new OsError(message, error.code, errorPath, { cause: error });
37
+ }
38
+ //# sourceMappingURL=os-error.js.map
@@ -0,0 +1,88 @@
1
+ import { PecotError } from '../domain/errors.js';
2
+ export declare const PECOT_DIR = ".pecot";
3
+ export declare const STATE_DIR = ".pecot/state";
4
+ export declare const WORK_DIR = ".pecot/work";
5
+ export declare const CONFIG_DIR = ".pecot/config";
6
+ export declare const TMP_DIR = ".pecot/tmp";
7
+ export declare const OUTPUT_DIR = ".pecot/tmp/output";
8
+ export declare const PECOT_GITIGNORE_FILENAME = ".pecot/.gitignore";
9
+ export declare const WORKTREE_CONFIG_FILENAME = ".pecot/config/worktree-config.json";
10
+ export declare const WORKTREE_IGNORE_FILENAME = ".pecot/config/.worktreeignore";
11
+ export declare const HOOKS_CONFIG_FILENAME = ".pecot/config/hooks-config.json";
12
+ export declare const ACTIVE_PROJECT_FILENAME = ".pecot/config/projects/.active";
13
+ /**
14
+ 候補名を使い切っても出力パスを予約できなかった
15
+ */
16
+ export declare class OutputPathReservationError extends PecotError {
17
+ }
18
+ /**
19
+ パス文字列を Python の Path と同じ形にする(空のセグメントと `.` を落とし、末尾のスラッシュを落とす)
20
+ */
21
+ export declare function normalizePath(text: string): string;
22
+ /**
23
+ シンボリックリンクを解決した絶対パス。存在しない部分は、存在する最も深い親を解決して字句どおりにつなぐ(Python の Path.resolve())
24
+ */
25
+ export declare function resolveRealPath(target: string): string;
26
+ export interface ProjectRootOptions {
27
+ /**
28
+ 起点のディレクトリ。省略すると呼び出し元の作業ディレクトリ
29
+ */
30
+ readonly cwd?: string | undefined;
31
+ }
32
+ /**
33
+ プロジェクトルートを取得する。
34
+ 1. CLAUDE_PROJECT_DIR があれば使う(テスト上書き用)。
35
+ 2. cwd が PECOT_SESSION_PROJECT_DIR の .pecot/work 配下(入れ子の git リポを除く)なら、その実体パス。
36
+ worktree の .pecot/work は base への symlink で、そこでは git toplevel が base になる。
37
+ 3. なければ git rev-parse --show-toplevel で解決する(GIT_* を除いて実行する)。
38
+
39
+ どれも得られなければ ProjectRootNotFoundError
40
+ */
41
+ export declare function projectRoot(options?: Readonly<ProjectRootOptions>): string;
42
+ /**
43
+ 出力ディレクトリ(`{プロジェクトルート}/.pecot/tmp/output`)
44
+ */
45
+ export declare function outputDirectory(options?: Readonly<ProjectRootOptions>): string;
46
+ export interface ReserveOptions {
47
+ /**
48
+ 試行する候補名の数。既定は 60
49
+ */
50
+ readonly maxAttempts?: number | undefined;
51
+ /**
52
+ 現在時刻。省略すると new Date()(テストで固定するために差し替える)
53
+ */
54
+ readonly now?: (() => Date) | undefined;
55
+ }
56
+ /**
57
+ `YYYYMMDD-HHMMSS`(ローカル時刻)。reserveOutputPath の nameFor に渡す形
58
+ */
59
+ export declare function formatTimestamp(milliseconds: number): string;
60
+ /**
61
+ outputDirectory 配下に空ファイルを排他作成して返す。
62
+ nameFor には `YYYYMMDD-HHMMSS` 形式の文字列を渡し、返ってきた名前で作る。既に同名があれば 1 秒進めた候補で再試行する。
63
+ 時刻は生成物の一意性と生成順の目安であり、実時刻の記録ではない。衝突した分だけ実時刻より先に進む。
64
+ 候補をすべて使い切ったら OutputPathReservationError
65
+ */
66
+ export declare function reserveOutputPath(output: string, nameFor: (timestamp: string) => string, options?: Readonly<ReserveOptions>): string;
67
+ /**
68
+ reserveOutputPath で予約したパスを本文に渡し、本文が例外を投げたら予約を撤去する。
69
+ 予約から書き込みまでの間で異常終了しても、0 バイトのファイルを出力先へ残さない。正常に終われば何もしない
70
+ */
71
+ export declare function withReservedOutputPath<T>(output: string, nameFor: (timestamp: string) => string, body: (reserved: string) => T, options?: Readonly<ReserveOptions>): T;
72
+ /**
73
+ withReservedOutputPath の、本文が非同期のもの
74
+ */
75
+ export declare function withReservedOutputPathAsync<T>(output: string, nameFor: (timestamp: string) => string, body: (reserved: string) => Promise<T>, options?: Readonly<ReserveOptions>): Promise<T>;
76
+ /**
77
+ データ置き場。作らずに値を返す。有効な HOME と有効な XDG_DATA_HOME がどちらも無いときは undefined。
78
+
79
+ bin/_lib.sh の plugin_data_dir_resolve と同じ解決順で、同じ入力なら同じ結果になる。
80
+ この対応は infra/tests/paths.test.ts が固定する。
81
+ 順序は CLAUDE_PLUGIN_DATA、PLUGIN_DATA、XDG_DATA_HOME、HOME。
82
+ 有効な値は、空でない絶対パスだけ。
83
+ 先頭が変数展開の書式(ドル記号と開き波括弧)の値は無効とする。
84
+ 末尾の改行と CR は落とす。
85
+ XDG_DATA_HOME の下は `pecot/pecot-workflow`、HOME の下は `.local/share/pecot/pecot-workflow`
86
+ */
87
+ export declare function dataDirectory(): string | undefined;
88
+ //# sourceMappingURL=paths.d.ts.map