@pecot/workflow-mcp 5.0.0 → 7.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 (188) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +27 -22
  3. package/cli/dist/cli.js +6 -1
  4. package/cli/dist/commands/board-add.d.ts +3 -0
  5. package/cli/dist/commands/board-add.js +69 -0
  6. package/cli/dist/commands/board-judgment.d.ts +69 -0
  7. package/cli/dist/commands/board-judgment.js +150 -0
  8. package/cli/dist/commands/board-move.d.ts +3 -0
  9. package/cli/dist/commands/board-move.js +65 -0
  10. package/cli/dist/commands/board-readiness.d.ts +34 -0
  11. package/cli/dist/commands/board-readiness.js +108 -0
  12. package/cli/dist/commands/board-show.d.ts +3 -0
  13. package/cli/dist/commands/board-show.js +75 -0
  14. package/cli/dist/commands/board-sync.d.ts +3 -0
  15. package/cli/dist/commands/board-sync.js +120 -0
  16. package/cli/dist/commands/board-view.d.ts +151 -0
  17. package/cli/dist/commands/board-view.js +293 -0
  18. package/cli/dist/commands/board.d.ts +3 -0
  19. package/cli/dist/commands/board.js +12 -0
  20. package/cli/dist/commands/branch.d.ts +3 -0
  21. package/cli/dist/commands/branch.js +111 -0
  22. package/cli/dist/commands/command-binding.js +4 -0
  23. package/cli/dist/commands/command-definition.d.ts +39 -8
  24. package/cli/dist/commands/command-definition.js +20 -7
  25. package/cli/dist/commands/command-help.js +2 -2
  26. package/cli/dist/commands/command-hint.d.ts +5 -0
  27. package/cli/dist/commands/command-hint.js +13 -0
  28. package/cli/dist/commands/command-stop.d.ts +5 -3
  29. package/cli/dist/commands/command-stop.js +7 -6
  30. package/cli/dist/commands/failure-kind.d.ts +3 -0
  31. package/cli/dist/commands/failure-kind.js +35 -0
  32. package/cli/dist/commands/failure.d.ts +6 -0
  33. package/cli/dist/commands/failure.js +29 -3
  34. package/cli/dist/commands/github-client.d.ts +6 -2
  35. package/cli/dist/commands/github-client.js +13 -3
  36. package/cli/dist/commands/help.js +8 -13
  37. package/cli/dist/commands/issue-board.d.ts +61 -0
  38. package/cli/dist/commands/issue-board.js +85 -1
  39. package/cli/dist/commands/issue-comment.js +66 -30
  40. package/cli/dist/commands/issue-create.js +632 -92
  41. package/cli/dist/commands/issue-dependency.d.ts +3 -0
  42. package/cli/dist/commands/issue-dependency.js +310 -0
  43. package/cli/dist/commands/issue-readiness.d.ts +122 -0
  44. package/cli/dist/commands/issue-readiness.js +253 -0
  45. package/cli/dist/commands/issue-reopen.d.ts +3 -0
  46. package/cli/dist/commands/issue-reopen.js +130 -0
  47. package/cli/dist/commands/issue-shared.d.ts +33 -20
  48. package/cli/dist/commands/issue-shared.js +84 -76
  49. package/cli/dist/commands/issue-show.d.ts +3 -0
  50. package/cli/dist/commands/issue-show.js +239 -0
  51. package/cli/dist/commands/issue.d.ts +0 -1
  52. package/cli/dist/commands/issue.js +6 -8
  53. package/cli/dist/commands/names.d.ts +33 -0
  54. package/cli/dist/commands/names.js +63 -0
  55. package/cli/dist/commands/output.d.ts +32 -4
  56. package/cli/dist/commands/output.js +28 -8
  57. package/cli/dist/commands/pr-merge.d.ts +3 -0
  58. package/cli/dist/commands/pr-merge.js +230 -0
  59. package/cli/dist/commands/pr-reference.d.ts +8 -0
  60. package/cli/dist/commands/pr-reference.js +30 -0
  61. package/cli/dist/commands/pr-restack.d.ts +6 -0
  62. package/cli/dist/commands/pr-restack.js +233 -0
  63. package/cli/dist/commands/pr-waiting.d.ts +59 -0
  64. package/cli/dist/commands/pr-waiting.js +143 -0
  65. package/cli/dist/commands/pr.d.ts +23 -0
  66. package/cli/dist/commands/pr.js +378 -366
  67. package/cli/dist/commands/project-sync.d.ts +12 -3
  68. package/cli/dist/commands/project-sync.js +23 -13
  69. package/cli/dist/commands/project.d.ts +3 -2
  70. package/cli/dist/commands/project.js +371 -177
  71. package/cli/dist/commands/registry.js +15 -10
  72. package/cli/dist/commands/release.d.ts +2 -2
  73. package/cli/dist/commands/release.js +118 -130
  74. package/cli/dist/commands/renamed-commands.d.ts +26 -0
  75. package/cli/dist/commands/renamed-commands.js +53 -0
  76. package/cli/dist/commands/repository-match.js +9 -3
  77. package/cli/dist/commands/session-finish.d.ts +3 -0
  78. package/cli/dist/commands/session-finish.js +383 -0
  79. package/cli/dist/commands/session-start.d.ts +3 -0
  80. package/cli/dist/commands/session-start.js +252 -0
  81. package/cli/dist/commands/session.d.ts +3 -0
  82. package/cli/dist/commands/session.js +186 -32
  83. package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
  84. package/cli/dist/commands/{dependabot.js → tracker-sync-dependabot.js} +76 -68
  85. package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
  86. package/cli/dist/commands/{security.js → tracker-sync-security.js} +71 -64
  87. package/cli/dist/commands/tracker-sync.d.ts +37 -0
  88. package/cli/dist/commands/tracker-sync.js +18 -6
  89. package/cli/dist/commands/tracker.d.ts +3 -0
  90. package/cli/dist/commands/tracker.js +20 -0
  91. package/cli/dist/commands/usage-error.d.ts +4 -0
  92. package/cli/dist/commands/usage-error.js +6 -0
  93. package/cli/dist/commands/work-target.d.ts +20 -3
  94. package/cli/dist/commands/work-target.js +49 -6
  95. package/cli/dist/commands/worktree.js +103 -33
  96. package/cli/dist/domain/batch-plan.d.ts +73 -0
  97. package/cli/dist/domain/batch-plan.js +114 -0
  98. package/cli/dist/domain/blocked-by-change.d.ts +99 -0
  99. package/cli/dist/domain/blocked-by-change.js +101 -0
  100. package/cli/dist/domain/board-move.d.ts +90 -0
  101. package/cli/dist/domain/board-move.js +92 -0
  102. package/cli/dist/domain/branch-name.js +1 -1
  103. package/cli/dist/domain/command-hint.d.ts +85 -0
  104. package/cli/dist/domain/command-hint.js +148 -0
  105. package/cli/dist/domain/config.d.ts +4 -0
  106. package/cli/dist/domain/config.js +11 -1
  107. package/cli/dist/domain/dependabot.js +1 -1
  108. package/cli/dist/domain/errors.d.ts +5 -0
  109. package/cli/dist/domain/errors.js +5 -0
  110. package/cli/dist/domain/format.d.ts +51 -4
  111. package/cli/dist/domain/format.js +72 -6
  112. package/cli/dist/domain/frontmatter.d.ts +18 -3
  113. package/cli/dist/domain/frontmatter.js +38 -12
  114. package/cli/dist/domain/issue-order.d.ts +55 -0
  115. package/cli/dist/domain/issue-order.js +65 -0
  116. package/cli/dist/domain/issue-readout.d.ts +36 -4
  117. package/cli/dist/domain/pull-request.d.ts +71 -4
  118. package/cli/dist/domain/pull-request.js +59 -10
  119. package/cli/dist/domain/readiness.d.ts +44 -0
  120. package/cli/dist/domain/readiness.js +153 -5
  121. package/cli/dist/domain/reference-parser.d.ts +3 -1
  122. package/cli/dist/domain/reference-parser.js +6 -2
  123. package/cli/dist/domain/release.d.ts +7 -3
  124. package/cli/dist/domain/release.js +5 -12
  125. package/cli/dist/domain/repository-policy.d.ts +9 -3
  126. package/cli/dist/domain/repository-policy.js +8 -7
  127. package/cli/dist/domain/repository-resolver.js +4 -1
  128. package/cli/dist/domain/restack.d.ts +62 -0
  129. package/cli/dist/domain/restack.js +53 -0
  130. package/cli/dist/domain/security-alerts.js +1 -1
  131. package/cli/dist/domain/state.d.ts +69 -0
  132. package/cli/dist/domain/state.js +67 -1
  133. package/cli/dist/domain/work-start.d.ts +30 -0
  134. package/cli/dist/domain/work-start.js +42 -0
  135. package/cli/dist/infra/authored-notes.d.ts +1 -1
  136. package/cli/dist/infra/authored-notes.js +10 -4
  137. package/cli/dist/infra/config-store.d.ts +4 -0
  138. package/cli/dist/infra/config-store.js +13 -0
  139. package/cli/dist/infra/git.d.ts +76 -0
  140. package/cli/dist/infra/git.js +123 -1
  141. package/cli/dist/infra/github/client.d.ts +5 -0
  142. package/cli/dist/infra/github/client.js +10 -7
  143. package/cli/dist/infra/github/errors.d.ts +18 -0
  144. package/cli/dist/infra/github/errors.js +22 -0
  145. package/cli/dist/infra/github/issues.d.ts +39 -3
  146. package/cli/dist/infra/github/issues.js +178 -23
  147. package/cli/dist/infra/github/projects.d.ts +35 -0
  148. package/cli/dist/infra/github/projects.js +89 -8
  149. package/cli/dist/infra/github/pulls.d.ts +105 -2
  150. package/cli/dist/infra/github/pulls.js +172 -5
  151. package/cli/dist/infra/github/queries.d.ts +15 -4
  152. package/cli/dist/infra/github/queries.js +203 -40
  153. package/cli/dist/infra/github/readout.d.ts +5 -1
  154. package/cli/dist/infra/github/readout.js +11 -33
  155. package/cli/dist/infra/github/repos.d.ts +18 -0
  156. package/cli/dist/infra/github/repos.js +31 -0
  157. package/cli/dist/infra/nx-scope.d.ts +1 -1
  158. package/cli/dist/infra/nx-scope.js +1 -1
  159. package/cli/dist/infra/state-store.d.ts +10 -1
  160. package/cli/dist/infra/state-store.js +14 -2
  161. package/cli/dist/infra/worktree-links.d.ts +3 -0
  162. package/cli/dist/infra/worktree-links.js +8 -1
  163. package/cli/dist/infra/worktree.d.ts +12 -1
  164. package/cli/dist/infra/worktree.js +40 -23
  165. package/cli/dist/mcp/result.d.ts +82 -7
  166. package/cli/dist/mcp/result.js +139 -19
  167. package/cli/dist/mcp/server.d.ts +2 -2
  168. package/cli/dist/mcp/server.js +57 -10
  169. package/cli/templates/comment/plan.md +14 -0
  170. package/cli/templates/comment/review-findings.md +3 -2
  171. package/cli/templates/issue/bug.md +13 -4
  172. package/cli/templates/issue/task-implement.md +13 -6
  173. package/cli/templates/issue/task.md +13 -4
  174. package/cli/templates/workflow/pecot-board-sync.yml +84 -0
  175. package/npm-shrinkwrap.json +2 -2
  176. package/package.json +1 -1
  177. package/cli/dist/commands/dependabot.d.ts +0 -3
  178. package/cli/dist/commands/issue-project.d.ts +0 -3
  179. package/cli/dist/commands/issue-project.js +0 -176
  180. package/cli/dist/commands/issue-quick.d.ts +0 -3
  181. package/cli/dist/commands/issue-quick.js +0 -126
  182. package/cli/dist/commands/issue-read.d.ts +0 -3
  183. package/cli/dist/commands/issue-read.js +0 -80
  184. package/cli/dist/commands/project-info.d.ts +0 -48
  185. package/cli/dist/commands/project-info.js +0 -181
  186. package/cli/dist/commands/repository.d.ts +0 -5
  187. package/cli/dist/commands/repository.js +0 -265
  188. package/cli/dist/commands/security.d.ts +0 -3
@@ -1,16 +1,16 @@
1
- // dependabot sync。移す元は cli/commands/dependabot.py。
1
+ // `pecot tracker sync dependabot` の本体。移す元は cli/commands/dependabot.py。
2
2
  // 判断を待つ dependabot の PR を、open の Tracker の一覧に反映する。載せる PR が無くなったら、一覧を none にして Tracker を閉じる。
3
- import { z } from 'zod';
4
3
  import { buildTrackerTitle, checksLabel, DependabotPrError, parseTrackerPullRequestNumbers, planTracker, PR_LABEL, PRIORITY, renderTrackerBody, rollupState, TRACKER_PATTERN, waitingReasons, } from '../domain/dependabot-pull-requests.js';
5
4
  import { jsonField } from '../domain/json.js';
6
5
  import { findTracker } from '../domain/tracker-body.js';
7
6
  import { requireNumber } from '../infra/github/payload.js';
8
- import { defineCommand } from './command-definition.js';
7
+ import { CommandExit } from './command-definition.js';
8
+ import { stopWith } from './command-stop.js';
9
+ import { kindOfFailure } from './failure.js';
9
10
  import { makeClient } from './github-client.js';
10
11
  import { createIssue, putOnBoard } from './issue-board.js';
11
12
  import { createOutput } from './output.js';
12
13
  import { apiErrorDetail, isBodyUnchanged, loadTarget, todayUtc, warnExtraTrackers } from './tracker-sync.js';
13
- const FAILURE = 1;
14
14
  function textOrEmpty(value) {
15
15
  return typeof value === 'string' ? value : '';
16
16
  }
@@ -42,10 +42,18 @@ function operationsFor(plan, tracker, title, isUnchanged) {
42
42
  rewrite.push({ verb: 'update', target: `Tracker #${String(tracker)} body` });
43
43
  return { create: [], rewrite, close: plan.close ? [{ verb: 'close', target: `Tracker #${String(tracker)}` }] : [] };
44
44
  }
45
+ // 足す行と外す行。open の Tracker が無ければ、立てる Tracker に載せる行を足す行にする
46
+ function rowsOf(plan, tracker) {
47
+ const added = tracker === undefined ? (plan.create ? plan.entries : []) : plan.added;
48
+ return {
49
+ added: added.map(entry => ({ kind: 'pull-request', number: entry.number })),
50
+ removed: plan.removed.map(number => ({ kind: 'pull-request', number })),
51
+ };
52
+ }
45
53
  // Tracker を作る・書き直す・閉じる・ボードに載せる。失敗の数を返す。
46
54
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は可変
47
55
  async function applyChanges(out, input) {
48
- const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged } = input;
56
+ const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows } = input;
49
57
  try {
50
58
  if (number === undefined) {
51
59
  if (!plan.create) {
@@ -56,7 +64,9 @@ async function applyChanges(out, input) {
56
64
  const issue = await createIssue(client, owner, repository, title, body, [PR_LABEL]);
57
65
  for (const operation of stages.create)
58
66
  out.done(operation);
59
- await putOnBoard(client, config, owner, repository, requireNumber(issue['number'], 'number'), PRIORITY, { onlyIfEmpty: false });
67
+ const created = requireNumber(issue['number'], 'number');
68
+ out.result({ tracker: created, created: true, added: rows.added });
69
+ await putOnBoard(client, config, owner, repository, created, PRIORITY, { onlyIfEmpty: false });
60
70
  return 0;
61
71
  }
62
72
  if (!isUnchanged) {
@@ -74,6 +84,7 @@ async function applyChanges(out, input) {
74
84
  }
75
85
  for (const operation of stages.rewrite)
76
86
  out.done(operation);
87
+ out.result(rows);
77
88
  const [closing] = stages.close;
78
89
  if (closing !== undefined) {
79
90
  try {
@@ -87,6 +98,7 @@ async function applyChanges(out, input) {
87
98
  return 1;
88
99
  }
89
100
  out.done(closing);
101
+ out.result({ closed: true });
90
102
  return 0;
91
103
  }
92
104
  // 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
@@ -101,65 +113,61 @@ async function applyChanges(out, input) {
101
113
  return 1;
102
114
  }
103
115
  }
104
- const sync = defineCommand({
105
- path: ['dependabot', 'sync'],
106
- description: 'Rewrite the open Tracker\'s list of Dependabot PRs waiting for a human decision',
107
- input: z.object({
108
- dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
109
- }),
110
- positional: [],
111
- interactive: false,
112
- run: async (input, io) => {
113
- const out = createOutput(input.dry_run, io);
114
- const { config, owner, repository } = loadTarget(out, input.repo);
115
- const client = makeClient(out, config);
116
- if (client === undefined)
117
- return FAILURE;
118
- let pullRequests;
119
- let issues;
120
- try {
121
- pullRequests = await client.listOpenDependabotPullRequests(owner, repository);
122
- issues = await client.listIssuesByLabel(owner, repository, PR_LABEL);
123
- }
124
- catch (error) {
125
- const detail = apiErrorDetail(error);
126
- if (detail === undefined)
127
- throw error;
128
- out.error(`could not list pull requests or issues: ${detail}`);
129
- return FAILURE;
130
- }
131
- const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
132
- warnExtraTrackers(out, tracker, others);
133
- const existingBody = tracker?.body;
134
- let oldNumbers;
135
- try {
136
- oldNumbers = tracker === undefined ? undefined : parseTrackerPullRequestNumbers(existingBody);
137
- }
138
- catch (error) {
139
- if (tracker === undefined || !(error instanceof DependabotPrError))
140
- throw error;
141
- out.error(`Tracker #${String(tracker.number)}: ${error.message}`);
142
- return FAILURE;
143
- }
144
- const now = new Date();
145
- const nodes = pullRequests;
146
- const waiting = nodes.map(node => ({ node, reasons: waitingReasons(node, now) })).filter(item => item.reasons.length > 0);
147
- out.count('open dependabot PRs', nodes.length);
148
- out.count('PRs awaiting a decision', waiting.length);
149
- out.count('PRs awaiting a decision without check results', waiting.filter(item => rollupState(item.node) === undefined).length);
150
- const plan = planTracker(waiting.map(item => ({ ...entryOf(item.node), reasons: item.reasons })), oldNumbers);
151
- const title = buildTrackerTitle(todayUtc(now));
152
- const body = renderTrackerBody(plan.entries, existingBody);
153
- const number = tracker?.number;
154
- const isUnchanged = isBodyUnchanged(body, existingBody);
155
- const stages = operationsFor(plan, number, title, isUnchanged);
156
- for (const operation of [...stages.create, ...stages.rewrite, ...stages.close])
157
- out.planned(operation);
158
- if (input.dry_run)
159
- return 0;
160
- const failures = await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
161
- return failures > 0 ? FAILURE : 0;
162
- },
163
- });
164
- export const DEPENDABOT_COMMANDS = [sync];
165
- //# sourceMappingURL=dependabot.js.map
116
+ /**
117
+ tracker sync の source dependabot の本体。Tracker の Dependabot PRs waiting for a human decision の一覧を書き直す
118
+ */
119
+ export async function runDependabotSync(input, io) {
120
+ const out = createOutput(input.dry_run, io);
121
+ const { config, owner, repository } = loadTarget(out, input.repo);
122
+ const client = makeClient(out, config);
123
+ let pullRequests;
124
+ let issues;
125
+ try {
126
+ pullRequests = await client.listOpenDependabotPullRequests(owner, repository);
127
+ issues = await client.listIssuesByLabel(owner, repository, PR_LABEL);
128
+ }
129
+ catch (error) {
130
+ const detail = apiErrorDetail(error);
131
+ if (detail === undefined)
132
+ throw error;
133
+ return stopWith(out, `could not list pull requests or issues: ${detail}`, kindOfFailure(error));
134
+ }
135
+ const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
136
+ warnExtraTrackers(out, tracker, others);
137
+ const existingBody = tracker?.body;
138
+ let oldNumbers;
139
+ try {
140
+ oldNumbers = tracker === undefined ? undefined : parseTrackerPullRequestNumbers(existingBody);
141
+ }
142
+ catch (error) {
143
+ if (tracker === undefined || !(error instanceof DependabotPrError))
144
+ throw error;
145
+ return stopWith(out, `Tracker #${String(tracker.number)}: ${error.message}`, 'content-invalid');
146
+ }
147
+ const now = new Date();
148
+ const nodes = pullRequests;
149
+ const waiting = nodes.map(node => ({ node, reasons: waitingReasons(node, now) })).filter(item => item.reasons.length > 0);
150
+ out.count('open dependabot PRs', nodes.length);
151
+ out.count('PRs awaiting a decision', waiting.length);
152
+ out.count('PRs awaiting a decision without check results', waiting.filter(item => rollupState(item.node) === undefined).length);
153
+ const plan = planTracker(waiting.map(item => ({ ...entryOf(item.node), reasons: item.reasons })), oldNumbers);
154
+ const title = buildTrackerTitle(todayUtc(now));
155
+ const body = renderTrackerBody(plan.entries, existingBody);
156
+ const number = tracker?.number;
157
+ const isUnchanged = isBodyUnchanged(body, existingBody);
158
+ const stages = operationsFor(plan, number, title, isUnchanged);
159
+ for (const operation of [...stages.create, ...stages.rewrite, ...stages.close])
160
+ out.planned(operation);
161
+ const rows = rowsOf(plan, number);
162
+ const synced = { source: 'dependabot', ...number !== undefined && { tracker: number } };
163
+ if (input.dry_run) {
164
+ out.result({ ...synced, created: number === undefined && plan.create, ...rows, closed: plan.close });
165
+ return 0;
166
+ }
167
+ out.result({ ...synced, created: false, added: [], removed: [], closed: false });
168
+ const failures = await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows });
169
+ if (failures > 0)
170
+ throw new CommandExit(1, 'partial-failure');
171
+ return 0;
172
+ }
173
+ //# sourceMappingURL=tracker-sync-dependabot.js.map
@@ -0,0 +1,7 @@
1
+ import type { CommandIo } from './command-definition.js';
2
+ import type { TrackerSyncInput } from './tracker-sync.js';
3
+ /**
4
+ tracker sync の source security の本体。Tracker の open security alerts の一覧を書き直す
5
+ */
6
+ export declare function runSecuritySync(input: Readonly<TrackerSyncInput>, io: CommandIo): Promise<0>;
7
+ //# sourceMappingURL=tracker-sync-security.d.ts.map
@@ -1,18 +1,18 @@
1
- // `pecot security sync`。cli/commands/security.py の移植。open の Tracker の一覧を、open の security alert に書き直す。
2
- // 途中で抜ける箇所は CommandExit を投げ、defineCommand が終了コードにする。
3
- import { z } from 'zod';
1
+ // `pecot tracker sync security` の本体。cli/commands/security.py の移植。open の Tracker の一覧を、open の security alert に書き直す。
2
+ // 途中で抜ける箇所は CommandExit を投げ、tracker sync の定義が終了コードにする。
4
3
  import { ALERT_KINDS, kindLabel, listOpenAlerts, SecurityAlertError } from '../domain/security-alerts.js';
5
4
  import { ALERT_LABEL, buildTrackerTitle, maxPriority, normalizeAlerts, parseTrackerEntries, planTracker, renderTrackerBody, TRACKER_PATTERN } from '../domain/security-tracker.js';
6
5
  import { findTracker } from '../domain/tracker-body.js';
7
6
  import { createDependabotSource } from '../infra/github/dependabot-source.js';
8
7
  import { requireNumber } from '../infra/github/payload.js';
9
8
  import { createScanAlertSource } from '../infra/github/security-alerts-source.js';
10
- import { CommandExit, defineCommand } from './command-definition.js';
9
+ import { CommandExit } from './command-definition.js';
10
+ import { stopWith } from './command-stop.js';
11
+ import { kindOfFailure } from './failure.js';
11
12
  import { makeClient } from './github-client.js';
12
13
  import { createIssue, putOnBoard } from './issue-board.js';
13
14
  import { createOutput } from './output.js';
14
15
  import { apiErrorDetail, isBodyUnchanged, loadTarget, settle, todayUtc, warnExtraTrackers } from './tracker-sync.js';
15
- const FAILURE = 1;
16
16
  // 一覧を取れなかった種類と無効の種類は行を触らず、足さない。終了コード 1 にするのは取れなかった種類だけ
17
17
  async function fetchOpenAlerts(out, sources, host, owner, repository) {
18
18
  const alerts = new Map();
@@ -57,10 +57,21 @@ function operationsOf(plan, tracker, title, isUnchanged) {
57
57
  ];
58
58
  return { create: [], rewrite: rewrite.length === 0 ? [{ verb: 'update', target: `Tracker ${label} body` }] : rewrite };
59
59
  }
60
+ // 足す行と外す行。open の Tracker が無ければ、立てる Tracker に載せる行を足す行にする。本文が変わらなければどちらも空
61
+ function rowsOf(plan, tracker, isUnchanged) {
62
+ if (tracker !== undefined && isUnchanged)
63
+ return { added: [], removed: [] };
64
+ const added = tracker === undefined ? (plan.create ? plan.entries : []) : plan.added;
65
+ const removed = tracker === undefined ? [] : plan.removed;
66
+ return {
67
+ added: added.map(entry => ({ kind: entry.kind, number: entry.number })),
68
+ removed: removed.map(entry => ({ kind: entry.kind, number: entry.number })),
69
+ };
70
+ }
60
71
  // Tracker を作る・書き直す・ボードに載せる。失敗の数を返す。
61
72
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は可変
62
73
  async function applyChanges(out, input) {
63
- const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged } = input;
74
+ const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows } = input;
64
75
  const priority = maxPriority(plan.entries);
65
76
  try {
66
77
  if (number === undefined) {
@@ -72,7 +83,9 @@ async function applyChanges(out, input) {
72
83
  const issue = await createIssue(client, owner, repository, title, body, [ALERT_LABEL]);
73
84
  for (const operation of stages.create)
74
85
  out.done(operation);
75
- await putOnBoard(client, config, owner, repository, requireNumber(issue['number'], 'number'), priority, { onlyIfEmpty: false });
86
+ const created = requireNumber(issue['number'], 'number');
87
+ out.result({ tracker: created, created: true, added: rows.added });
88
+ await putOnBoard(client, config, owner, repository, created, priority, { onlyIfEmpty: false });
76
89
  return 0;
77
90
  }
78
91
  let failures = 0;
@@ -91,9 +104,11 @@ async function applyChanges(out, input) {
91
104
  out.error(`could not update Tracker #${String(number)} body: ${text}`);
92
105
  }
93
106
  }
94
- if (isUpdated)
107
+ if (isUpdated) {
95
108
  for (const operation of stages.rewrite)
96
109
  out.done(operation);
110
+ out.result(rows);
111
+ }
97
112
  // 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
98
113
  await putOnBoard(client, config, owner, repository, number, priority, { onlyIfEmpty: true });
99
114
  return failures;
@@ -106,59 +121,51 @@ async function applyChanges(out, input) {
106
121
  return 1;
107
122
  }
108
123
  }
109
- const sync = defineCommand({
110
- path: ['security', 'sync'],
111
- description: 'Rewrite the open Tracker\'s list of open security alerts',
112
- input: z.object({
113
- dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
114
- }),
115
- positional: [],
116
- interactive: false,
117
- run: async (input, io) => {
118
- const out = createOutput(input.dry_run, io);
119
- const { config, owner, repository } = loadTarget(out, input.repo);
120
- const client = makeClient(out, config);
121
- if (client === undefined)
122
- return FAILURE;
123
- const sources = { scan: createScanAlertSource(client), dependabot: createDependabotSource(client) };
124
- const { alerts, failed, disabled } = await fetchOpenAlerts(out, sources, config.host, owner, repository);
125
- let issues;
126
- try {
127
- issues = await client.listIssuesByLabel(owner, repository, ALERT_LABEL);
128
- }
129
- catch (error) {
130
- const text = apiErrorDetail(error);
131
- if (text === undefined)
132
- throw error;
133
- out.error(`could not list issues: ${text}`);
134
- return FAILURE;
135
- }
136
- const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
137
- warnExtraTrackers(out, tracker, others);
138
- const existingBody = tracker?.body;
139
- let entries;
140
- try {
141
- entries = tracker === undefined ? undefined : parseTrackerEntries(existingBody);
142
- }
143
- catch (error) {
144
- if (!(error instanceof SecurityAlertError))
145
- throw error;
146
- out.error(`${tracker === undefined ? 'Tracker' : `Tracker #${String(tracker.number)}`}: ${error.message}`);
147
- return FAILURE;
148
- }
149
- const plan = planTracker(alerts, entries, failed, disabled);
150
- const title = buildTrackerTitle(todayUtc(new Date()));
151
- const body = renderTrackerBody(plan.entries, config.host, owner, repository, { existingBody, disabledKinds: disabled, failedKinds: failed });
152
- const number = tracker?.number;
153
- const isUnchanged = isBodyUnchanged(body, existingBody);
154
- const stages = operationsOf(plan, number, title, isUnchanged);
155
- for (const operation of [...stages.create, ...stages.rewrite])
156
- out.planned(operation);
157
- const failures = input.dry_run ? 0 : await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
158
- if (failed.size > 0 || failures > 0)
159
- throw new CommandExit(FAILURE);
160
- return 0;
161
- },
162
- });
163
- export const SECURITY_COMMANDS = [sync];
164
- //# sourceMappingURL=security.js.map
124
+ /**
125
+ tracker sync の source security の本体。Tracker の open security alerts の一覧を書き直す
126
+ */
127
+ export async function runSecuritySync(input, io) {
128
+ const out = createOutput(input.dry_run, io);
129
+ const { config, owner, repository } = loadTarget(out, input.repo);
130
+ const client = makeClient(out, config);
131
+ const sources = { scan: createScanAlertSource(client), dependabot: createDependabotSource(client) };
132
+ const { alerts, failed, disabled } = await fetchOpenAlerts(out, sources, config.host, owner, repository);
133
+ let issues;
134
+ try {
135
+ issues = await client.listIssuesByLabel(owner, repository, ALERT_LABEL);
136
+ }
137
+ catch (error) {
138
+ const text = apiErrorDetail(error);
139
+ if (text === undefined)
140
+ throw error;
141
+ return stopWith(out, `could not list issues: ${text}`, kindOfFailure(error));
142
+ }
143
+ const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
144
+ warnExtraTrackers(out, tracker, others);
145
+ const existingBody = tracker?.body;
146
+ let entries;
147
+ try {
148
+ entries = tracker === undefined ? undefined : parseTrackerEntries(existingBody);
149
+ }
150
+ catch (error) {
151
+ if (!(error instanceof SecurityAlertError))
152
+ throw error;
153
+ return stopWith(out, `${tracker === undefined ? 'Tracker' : `Tracker #${String(tracker.number)}`}: ${error.message}`, 'content-invalid');
154
+ }
155
+ const plan = planTracker(alerts, entries, failed, disabled);
156
+ const title = buildTrackerTitle(todayUtc(new Date()));
157
+ const body = renderTrackerBody(plan.entries, config.host, owner, repository, { existingBody, disabledKinds: disabled, failedKinds: failed });
158
+ const number = tracker?.number;
159
+ const isUnchanged = isBodyUnchanged(body, existingBody);
160
+ const stages = operationsOf(plan, number, title, isUnchanged);
161
+ for (const operation of [...stages.create, ...stages.rewrite])
162
+ out.planned(operation);
163
+ const rows = rowsOf(plan, number, isUnchanged);
164
+ const synced = { source: 'security', ...number !== undefined && { tracker: number }, closed: false };
165
+ out.result(input.dry_run ? { ...synced, created: number === undefined && plan.create, ...rows } : { ...synced, created: false, added: [], removed: [] });
166
+ const failures = input.dry_run ? 0 : await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged, rows });
167
+ if (failed.size > 0 || failures > 0)
168
+ throw new CommandExit(1, 'partial-failure');
169
+ return 0;
170
+ }
171
+ //# sourceMappingURL=tracker-sync-security.js.map
@@ -1,3 +1,4 @@
1
+ import { z } from 'zod';
1
2
  import type { ProjectConfig } from '../domain/config.js';
2
3
  import type { TrackerIssue } from '../domain/tracker-body.js';
3
4
  import type { GitHubClient } from '../infra/github/index.js';
@@ -6,6 +7,42 @@ import type { Operation, Output } from './output.js';
6
7
  API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
7
8
  */
8
9
  export declare function settle(out: Output, operation: Operation): void;
10
+ export declare const TRACKER_SYNC_OUTPUT: z.ZodObject<{
11
+ source: z.ZodEnum<{
12
+ dependabot: "dependabot";
13
+ security: "security";
14
+ }>;
15
+ tracker: z.ZodOptional<z.ZodInt>;
16
+ created: z.ZodBoolean;
17
+ added: z.ZodArray<z.ZodObject<{
18
+ kind: z.ZodEnum<{
19
+ "code-scanning": "code-scanning";
20
+ dependabot: "dependabot";
21
+ "pull-request": "pull-request";
22
+ "secret-scanning": "secret-scanning";
23
+ }>;
24
+ number: z.ZodInt;
25
+ }, z.core.$strict>>;
26
+ removed: z.ZodArray<z.ZodObject<{
27
+ kind: z.ZodEnum<{
28
+ "code-scanning": "code-scanning";
29
+ dependabot: "dependabot";
30
+ "pull-request": "pull-request";
31
+ "secret-scanning": "secret-scanning";
32
+ }>;
33
+ number: z.ZodInt;
34
+ }, z.core.$strict>>;
35
+ closed: z.ZodBoolean;
36
+ dryRun: z.ZodOptional<z.ZodLiteral<true>>;
37
+ }, z.core.$strict>;
38
+ export type TrackerSyncData = z.input<typeof TRACKER_SYNC_OUTPUT>;
39
+ /**
40
+ tracker sync の各 source の本体が受ける入力
41
+ */
42
+ export interface TrackerSyncInput {
43
+ readonly dry_run: boolean;
44
+ readonly repo?: string | undefined;
45
+ }
9
46
  export interface SyncTarget {
10
47
  readonly config: ProjectConfig;
11
48
  readonly owner: string;
@@ -1,9 +1,10 @@
1
- // Tracker に反映するコマンドと、PR の後片付けが共有する出力の補助。
1
+ // tracker sync と session finish が共有する出力の補助。
2
+ import { z } from 'zod';
2
3
  import { TransportFailure } from '../infra/github/client.js';
3
4
  import { GitHubAPIError } from '../infra/github/errors.js';
4
- import { CommandExit } from './command-definition.js';
5
5
  import { requireActiveConfigPlain } from './command-stop.js';
6
- import { resolveReleaseTargetRepository } from './release.js';
6
+ import { DRY_RUN_FIELD } from './output.js';
7
+ import { requireReleaseTargetRepository } from './release.js';
7
8
  /**
8
9
  API を呼ばない操作の行を出す。dry-run では計画、実行では結果になる
9
10
  */
@@ -11,14 +12,25 @@ export function settle(out, operation) {
11
12
  out.planned(operation);
12
13
  out.done(operation);
13
14
  }
15
+ const TRACKER_ENTRY_JSON = z.strictObject({
16
+ kind: z.enum(['pull-request', 'dependabot', 'code-scanning', 'secret-scanning']).describe('Kind of the row: a Dependabot PR, or the kind of security alert'),
17
+ number: z.int().describe('PR or alert number'),
18
+ });
19
+ export const TRACKER_SYNC_OUTPUT = z.strictObject({
20
+ source: z.enum(['dependabot', 'security']).describe('Source synced'),
21
+ tracker: z.int().optional().describe('Number of the Tracker used or created (omitted when there is none, or on dry_run before creation)'),
22
+ created: z.boolean().describe('Whether a new Tracker was created (on dry_run, would be created)'),
23
+ added: z.array(TRACKER_ENTRY_JSON).describe('Rows added to the Tracker list (on dry_run, to be added)'),
24
+ removed: z.array(TRACKER_ENTRY_JSON).describe('Rows removed from the Tracker list (on dry_run, to be removed)'),
25
+ closed: z.boolean().describe('Whether the Tracker was closed because its list became none (on dry_run, would be closed)'),
26
+ dryRun: DRY_RUN_FIELD,
27
+ });
14
28
  /**
15
29
  対象のリポ(--repo、主の remote の順)とアクティブな設定を決める。決められなければ error の行を出して終了コード 1 で止める。
16
30
  設定が無いときの文は Python の sync と同じ 1 行で、案内の行を付けない
17
31
  */
18
32
  export function loadTarget(out, explicitRepository) {
19
- const target = resolveReleaseTargetRepository(undefined, explicitRepository, out);
20
- if (target === undefined)
21
- throw new CommandExit(1);
33
+ const target = requireReleaseTargetRepository(undefined, explicitRepository, out);
22
34
  const config = requireActiveConfigPlain(out);
23
35
  return { config, owner: target.owner, repository: target.repository };
24
36
  }
@@ -0,0 +1,3 @@
1
+ import type { CommandDefinition } from './command-definition.js';
2
+ export declare const TRACKER_COMMANDS: readonly CommandDefinition[];
3
+ //# sourceMappingURL=tracker.d.ts.map
@@ -0,0 +1,20 @@
1
+ // `pecot tracker sync <source>`。source ごとの本体(dependabot.ts・security.ts)を呼び分ける。
2
+ import { z } from 'zod';
3
+ import { defineCommand } from './command-definition.js';
4
+ import { runDependabotSync } from './tracker-sync-dependabot.js';
5
+ import { runSecuritySync } from './tracker-sync-security.js';
6
+ import { TRACKER_SYNC_OUTPUT } from './tracker-sync.js';
7
+ const syncCommand = defineCommand({
8
+ path: ['tracker', 'sync'],
9
+ description: 'Rewrite the open Tracker\'s list for a source: Dependabot PRs waiting for a human decision, or open security alerts',
10
+ input: z.strictObject({
11
+ source: z.enum(['dependabot', 'security']).describe('What to put into the Tracker: dependabot (Dependabot PRs waiting for a human decision) or security (open security alerts)'),
12
+ dry_run: z.boolean().default(false).describe('Show the planned Tracker changes without changing anything'),
13
+ }),
14
+ output: TRACKER_SYNC_OUTPUT,
15
+ positional: ['source'],
16
+ interactive: false,
17
+ run: async (input, io) => await (input.source === 'dependabot' ? runDependabotSync(input, io) : runSecuritySync(input, io)),
18
+ });
19
+ export const TRACKER_COMMANDS = [syncCommand];
20
+ //# sourceMappingURL=tracker.js.map
@@ -33,6 +33,10 @@ export declare function noSuchOptionMessage(name: string, possibilities?: readon
33
33
  possibilities は近いコマンド名。近い順のまま案内する
34
34
  */
35
35
  export declare function noSuchCommandMessage(name: string, possibilities?: readonly string[]): string;
36
+ /**
37
+ 古い名前のコマンドを打たれたときの案内。名前はどちらも空白でつないだ path
38
+ */
39
+ export declare function renamedCommandMessage(oldName: string, newName: string): string;
36
40
  export declare function optionRequiresArgumentMessage(name: string): string;
37
41
  export declare function optionTakesNoValueMessage(name: string): string;
38
42
  /**
@@ -43,6 +43,12 @@ export function noSuchCommandMessage(name, possibilities = []) {
43
43
  const hint = possibilities.length === 0 ? '' : ` Did you mean ${possibilities.map(candidate => `'${candidate}'`).join(', ')}?`;
44
44
  return `No such command '${name}'.${hint}`;
45
45
  }
46
+ /**
47
+ 古い名前のコマンドを打たれたときの案内。名前はどちらも空白でつないだ path
48
+ */
49
+ export function renamedCommandMessage(oldName, newName) {
50
+ return `'${oldName}' was renamed to '${newName}'.`;
51
+ }
46
52
  export function optionRequiresArgumentMessage(name) {
47
53
  return `Option '${name}' requires an argument.`;
48
54
  }
@@ -1,13 +1,30 @@
1
+ import type { BaseRecord } from '../domain/state.js';
1
2
  import type { Output } from './output.js';
2
3
  export interface RecordWorkTargetOptions {
3
4
  /**
4
5
  真なら、記録の失敗を warning ではなく error の行で出し、終了コード 1 で止める
5
6
  */
6
7
  readonly failWithExit?: boolean;
8
+ /**
9
+ 着手で選んだ base。作業対象を記録できたときに .pecot-base へ書く。省くと .pecot-base は消えたままになる
10
+ */
11
+ readonly base?: Readonly<BaseRecord>;
7
12
  }
8
13
  /**
9
- .pecot-active と .pecot-session-title を書き、`set: work target ...` の行を出す。
10
- 失敗は warning の行にする。failWithExit なら error の行を出して CommandExit(1) を投げる
14
+ recordWorkTarget の結果。workDirectory は作れた作業ディレクトリの絶対パス
15
+ */
16
+ export interface RecordedWorkTarget {
17
+ readonly status: 'recorded' | 'failed';
18
+ readonly issue: string;
19
+ readonly workDirectory?: string | undefined;
20
+ }
21
+ /**
22
+ .pecot-base を消してから作業対象を書き、`set: work target ...` の行を出す。options.base があれば記録後に .pecot-base も書く。
23
+ 失敗は warning の行。failWithExit なら error の行と CommandExit(1)。記録できたかと、行に出した参照・作業ディレクトリを返す
24
+ */
25
+ export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>): RecordedWorkTarget;
26
+ /**
27
+ 予行の行。recordWorkTarget が書く作業対象(.pecot-active・.pecot-session-title・.pecot-base)を書かずに出す
11
28
  */
12
- export declare function recordWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number, title: string, options?: Readonly<RecordWorkTargetOptions>): void;
29
+ export declare function planWorkTarget(out: Readonly<Output>, owner: string, repository: string, issueNumber: number): void;
13
30
  //# sourceMappingURL=work-target.d.ts.map