@spec-wave/cli 1.0.7 → 1.1.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 (68) hide show
  1. package/package.json +1 -1
  2. package/src/commands/audit.mjs +24 -18
  3. package/src/commands/code-review.mjs +91 -59
  4. package/src/commands/decompose.mjs +258 -221
  5. package/src/commands/doctor.mjs +16 -11
  6. package/src/commands/generate-bug.mjs +51 -44
  7. package/src/commands/generate-plan.mjs +83 -63
  8. package/src/commands/generate-qa-plan.mjs +145 -117
  9. package/src/commands/generate-spec.mjs +33 -28
  10. package/src/commands/implement.mjs +155 -79
  11. package/src/commands/info.mjs +4 -3
  12. package/src/commands/init.mjs +11 -5
  13. package/src/commands/install-skill.mjs +19 -0
  14. package/src/commands/issue.mjs +26 -39
  15. package/src/commands/merge.mjs +71 -20
  16. package/src/commands/mode.mjs +11 -6
  17. package/src/commands/move.mjs +16 -20
  18. package/src/commands/order.mjs +33 -22
  19. package/src/commands/preflight.mjs +24 -13
  20. package/src/commands/qa-lead.mjs +30 -17
  21. package/src/commands/qa-run.mjs +125 -103
  22. package/src/commands/qa.mjs +55 -44
  23. package/src/commands/refresh.mjs +24 -16
  24. package/src/commands/repair-stage.mjs +29 -16
  25. package/src/commands/repo.mjs +12 -4
  26. package/src/commands/run.mjs +23 -11
  27. package/src/commands/story.mjs +20 -25
  28. package/src/commands/task.mjs +21 -27
  29. package/src/commands/triage.mjs +33 -31
  30. package/src/commands/uninstall.mjs +7 -3
  31. package/src/commands/update.mjs +31 -22
  32. package/src/commands/validate.mjs +60 -52
  33. package/src/commands/workspace.mjs +7 -5
  34. package/src/config.mjs +7 -1
  35. package/src/lib/artifact-publish.mjs +20 -18
  36. package/src/lib/board-policy.mjs +144 -0
  37. package/src/lib/board.mjs +134 -233
  38. package/src/lib/cli-ref.mjs +75 -0
  39. package/src/lib/config-file.mjs +2 -1
  40. package/src/lib/doc-availability.mjs +10 -3
  41. package/src/lib/doc-source.mjs +9 -9
  42. package/src/lib/execution-mode.mjs +5 -3
  43. package/src/lib/implement-board.mjs +23 -26
  44. package/src/lib/issue-type.mjs +5 -1
  45. package/src/lib/plugin-skills.mjs +10 -0
  46. package/src/lib/pr-ready.mjs +48 -10
  47. package/src/lib/pr-step.mjs +3 -1
  48. package/src/lib/qa-exec.mjs +3 -1
  49. package/src/lib/qa-lead.mjs +11 -3
  50. package/src/lib/qa-plan-doc.mjs +10 -4
  51. package/src/lib/qa-report.mjs +2 -1
  52. package/src/lib/skill-compose.mjs +3 -0
  53. package/src/lib/spec-audit.mjs +1 -1
  54. package/src/lib/story-graph.mjs +62 -8
  55. package/src/lib/usage-report.mjs +8 -5
  56. package/src/lib/work-item-ref.mjs +176 -0
  57. package/src/plugin/.claude-plugin/plugin.json +1 -1
  58. package/src/plugins/scm-github/index.mjs +439 -0
  59. package/src/plugins/tracker-github-projects/fields.mjs +73 -0
  60. package/src/plugins/tracker-github-projects/index.mjs +625 -0
  61. package/src/ports/scm.mjs +197 -0
  62. package/src/ports/tracker.mjs +239 -0
  63. package/src/ports/types.mjs +254 -0
  64. package/src/setup/files.mjs +14 -12
  65. package/src/setup/labels.mjs +17 -12
  66. package/src/setup/project.mjs +40 -59
  67. package/src/templates/workflows/code/code-review.yml +1 -1
  68. package/src/templates/workflows/code/qa.yml +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spec-wave/cli",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
4
4
  "description": "Setup spec-driven GitHub workflow with Projects v2, labels, issue templates, and AI-powered Actions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,9 +22,8 @@ import { readdirSync } from 'node:fs';
22
22
  import path from 'node:path';
23
23
 
24
24
  import { resolveToken } from '../api/auth.mjs';
25
- import {
26
- getIssue, getRepoDefaultBranch, listMilestones, listIssuesByMilestone,
27
- } from '../api/github-rest.mjs';
25
+ import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
26
+ import { createGithubScm, githubLink } from '../plugins/scm-github/index.mjs';
28
27
  import { CONFIG_FILE } from '../config.mjs';
29
28
  import { detectIssueType } from '../lib/issue-type.mjs';
30
29
  import { featureDocPaths } from '../lib/doc-paths.mjs';
@@ -74,7 +73,7 @@ export function listRepoFiles(root, { maxFiles = MAX_FILES, maxDepth = 8 } = {})
74
73
  return out;
75
74
  }
76
75
 
77
- export async function audit({ milestone: milestoneArg, critique = false, json = false } = {}) {
76
+ export async function audit({ milestone: milestoneArg, critique = false, json = false, deps = {} } = {}) {
78
77
  const falhar = (msg) => {
79
78
  if (json) console.log(JSON.stringify({ erro: msg }, null, 2));
80
79
  else p.log.error(msg);
@@ -96,14 +95,17 @@ export async function audit({ milestone: milestoneArg, critique = false, json =
96
95
  return falhar(`Sem token utilizável para ${owner}/${repo}: ${err.message}`);
97
96
  }
98
97
 
98
+ const tracker = deps.tracker ?? createGithubTracker({ token, owner, repo });
99
+ const scm = deps.scm ?? createGithubScm({ link: githubLink({ owner, repo }), token });
100
+
99
101
  const s = json ? null : p.spinner();
100
102
  s?.start('Montando o catálogo de Features...');
101
103
 
102
104
  let base;
103
105
  let milestones;
104
106
  try {
105
- base = await getRepoDefaultBranch(token, owner, repo);
106
- milestones = await listMilestones(token, owner, repo);
107
+ base = await scm.defaultBranch();
108
+ milestones = await tracker.listMilestones();
107
109
  } catch (err) {
108
110
  s?.stop('');
109
111
  return falhar(`Não foi possível ler o repositório ${owner}/${repo}: ${err.message}`);
@@ -120,16 +122,16 @@ export async function audit({ milestone: milestoneArg, critique = false, json =
120
122
  let targetIssues = [];
121
123
  try {
122
124
  for (const m of milestones) {
123
- const issues = await listIssuesByMilestone(token, owner, repo, m.number);
124
- if (m.number === milestone.number) targetIssues = issues;
125
+ const issues = await tracker.listWorkItemsByMilestone({ milestone: m });
126
+ if (m.key === milestone.key) targetIssues = issues;
125
127
  for (const i of issues) {
126
128
  if (detectIssueType(i) !== 'Feature') continue;
127
129
  catalog.push({
128
- number: i.number,
130
+ number: Number(i.ref.key),
129
131
  title: i.title,
130
132
  slug: slugify(i.title),
131
133
  closed: i.state === 'closed',
132
- milestone: { number: m.number, title: m.title, due_on: m.due_on ?? null },
134
+ milestone: { number: Number(m.key), title: m.title, due_on: m.dueOn ?? null },
133
135
  });
134
136
  }
135
137
  }
@@ -149,14 +151,14 @@ export async function audit({ milestone: milestoneArg, critique = false, json =
149
151
  // agentes-2026-08.md: descartar isso é a mesma lacuna que o preflight já
150
152
  // corrigiu (PRs #65/#66) e que este comando herdou sem herdar a distinção.
151
153
  const { content, state } = await loadArtifact({
152
- token, owner, repo, root, base,
153
- pathRel: docs.spec.rel, doc: 'spec', issueNumber: issue.number,
154
+ token, owner, repo, root, base, scm,
155
+ pathRel: docs.spec.rel, doc: 'spec', issueNumber: issue.ref.key,
154
156
  });
155
157
  features.push({
156
- number: issue.number,
158
+ number: Number(issue.ref.key),
157
159
  title: issue.title,
158
160
  slug: slugify(issue.title),
159
- milestone: { number: milestone.number, title: milestone.title, due_on: milestone.due_on ?? null },
161
+ milestone: { number: Number(milestone.key), title: milestone.title, due_on: milestone.dueOn ?? null },
160
162
  spec: content,
161
163
  specState: state,
162
164
  });
@@ -179,15 +181,19 @@ export async function audit({ milestone: milestoneArg, critique = false, json =
179
181
  }
180
182
  const missingRefs = [];
181
183
  for (const n of desconhecidas) {
182
- const issue = await getIssue(token, owner, repo, n).catch(() => null);
184
+ const issue = await tracker.getWorkItem({ ref: { key: String(n) } }).catch(() => null);
183
185
  if (!issue) { missingRefs.push(n); continue; }
184
186
  catalog.push({
185
- number: issue.number,
187
+ number: Number(issue.ref.key),
186
188
  title: issue.title,
187
189
  slug: slugify(issue.title),
188
190
  closed: issue.state === 'closed',
189
191
  milestone: issue.milestone
190
- ? { number: issue.milestone.number, title: issue.milestone.title, due_on: issue.milestone.due_on ?? null }
192
+ ? {
193
+ number: Number(issue.milestone.key),
194
+ title: issue.milestone.title,
195
+ due_on: issue.milestone.dueOn ?? null,
196
+ }
191
197
  : null,
192
198
  });
193
199
  }
@@ -245,7 +251,7 @@ export async function audit({ milestone: milestoneArg, critique = false, json =
245
251
  }
246
252
 
247
253
  const saida = {
248
- milestone: { title: milestone.title, number: milestone.number },
254
+ milestone: { title: milestone.title, number: Number(milestone.key) },
249
255
  features: features.map(f => ({ number: f.number, title: f.title, temSpec: !!f.spec })),
250
256
  auditoria: resultado,
251
257
  // `markdown` é o comentário pronto para a issue — quem posta (nas DUAS
@@ -1,15 +1,28 @@
1
1
  import { appendFileSync } from 'node:fs';
2
2
  import { resolveToken } from '../api/auth.mjs';
3
- import { getIssue, getPR, commentOnIssue } from '../api/github-rest.mjs';
4
- import {
5
- addProjectItem, getIssueParent, listSubIssues, getItemSingleSelectValue, getPRClosingIssues,
6
- } from '../api/github-graphql.mjs';
3
+ import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
4
+ import { createGithubScm, githubLink } from '../plugins/scm-github/index.mjs';
5
+
6
+ // WorkItem → a forma `{number, nodeId, title, labels}` que este arquivo usa nos
7
+ // mapas de Stories/Tasks. Um lugar só, no ponto de leitura.
8
+ const comoItem = w => w && ({
9
+ number: Number(w.ref.key),
10
+ nodeId: w.ref.id,
11
+ node_id: w.ref.id,
12
+ title: w.title,
13
+ body: w.body || '',
14
+ labels: w.tags || [],
15
+ state: w.state || null,
16
+ createdAt: w.createdAt || null,
17
+ ref: w.ref,
18
+ });
7
19
  import { detectIssueType } from '../lib/issue-type.mjs';
8
- import { loadProjectConfig, resolveField, advanceToStage } from '../lib/board.mjs';
20
+ import { openTracker, advanceToStage } from '../lib/board.mjs';
9
21
  import { resolveHubContext, resolvePrRepo } from '../lib/project-root.mjs';
10
22
  import { markFeaturePrsReady } from '../lib/pr-ready.mjs';
11
23
  import { codeReposForItems } from '../lib/workspace.mjs';
12
24
  import { extractIssueRefs, hubIssueNumbers, resolveLinkMode, sameRepo } from '../lib/pr-link.mjs';
25
+ import { cliRef } from '../lib/cli-ref.mjs';
13
26
  import {
14
27
  STATUS_OPTIONS, STAGE_ORDER, STAGE_DONE, PROGRESS_TODO, PROGRESS_DONE, isManualStageType,
15
28
  LABEL_DECOMPOSE, LABEL_DECOMPOSE_APPLY, labelNames,
@@ -54,24 +67,25 @@ export function partitionByCreation(subs = [], notAfter = null) {
54
67
  }
55
68
 
56
69
  // A partir de qualquer issue (Feature/Story/Task), sobe a hierarquia e retorna a Feature.
57
- async function resolveFeatureIssue(token, owner, repo, issueNumber) {
70
+ async function resolveFeatureIssue(tracker, issueNumber) {
58
71
  let issue;
59
72
  try {
60
- issue = await getIssue(token, owner, repo, issueNumber);
73
+ issue = comoItem(await tracker.getWorkItem({ ref: { key: String(issueNumber) } }));
61
74
  } catch {
62
75
  return null;
63
76
  }
77
+ if (!issue) return null;
64
78
  const type = detectIssueType(issue);
65
79
  if (type === 'Feature') return issue;
66
80
  if (type !== 'Story' && type !== 'Task') return null;
67
- let currentNodeId = issue.node_id;
81
+ let atual = issue.ref;
68
82
  for (let depth = 0; depth < 5; depth++) {
69
- const parent = await getIssueParent(token, currentNodeId);
83
+ const parent = await tracker.getParent({ ref: atual });
70
84
  if (!parent) return null;
71
85
  if (detectIssueType({ title: parent.title }) === 'Feature') {
72
- return await getIssue(token, owner, repo, parent.number).catch(() => null);
86
+ return comoItem(await tracker.getWorkItem({ ref: parent.ref }).catch(() => null));
73
87
  }
74
- currentNodeId = parent.nodeId;
88
+ atual = parent.ref;
75
89
  }
76
90
  return null;
77
91
  }
@@ -107,7 +121,7 @@ function isDecomposing(issue) {
107
121
  return labelNames(issue?.labels || []).some(n => DECOMPOSING_LABELS.includes(n));
108
122
  }
109
123
 
110
- async function collectReviewUnit(token, owner, repo, issueNumber, { notAfter = null } = {}) {
124
+ async function collectReviewUnit(tracker, issueNumber, { notAfter = null } = {}) {
111
125
  const stories = new Map();
112
126
  const tasks = new Map();
113
127
  const bugs = new Map();
@@ -117,7 +131,8 @@ async function collectReviewUnit(token, owner, repo, issueNumber, { notAfter = n
117
131
  const empty = (extra = {}) => ({ feature: null, stories, tasks, bugs, skipped, deferred: null, ...extra });
118
132
 
119
133
  let issue;
120
- try { issue = await getIssue(token, owner, repo, issueNumber); } catch { return empty(); }
134
+ try { issue = comoItem(await tracker.getWorkItem({ ref: { key: String(issueNumber) } })); } catch { return empty(); }
135
+ if (!issue) return empty();
121
136
  const type = detectIssueType(issue);
122
137
  const kind = classifyReviewTarget(type);
123
138
  if (kind === 'ignore') return empty();
@@ -126,7 +141,7 @@ async function collectReviewUnit(token, owner, repo, issueNumber, { notAfter = n
126
141
  return empty({ bugs });
127
142
  }
128
143
 
129
- const featureIssue = await resolveFeatureIssue(token, owner, repo, issueNumber);
144
+ const featureIssue = await resolveFeatureIssue(tracker, issueNumber);
130
145
  const feature = featureIssue
131
146
  ? { number: featureIssue.number, nodeId: featureIssue.node_id, title: featureIssue.title }
132
147
  : null;
@@ -141,8 +156,8 @@ async function collectReviewUnit(token, owner, repo, issueNumber, { notAfter = n
141
156
  const isManual = (sub) => isManualStageType(detectIssueType({ title: sub.title, labels: sub.labels }));
142
157
 
143
158
  // Desce um nível aplicando o recorte temporal, registrando o que ficou de fora.
144
- const children = async (nodeId) => {
145
- const all = await listSubIssues(token, nodeId).catch(() => []);
159
+ const children = async (ref) => {
160
+ const all = (await tracker.listChildren({ ref }).catch(() => [])).map(comoItem);
146
161
  const { kept, skipped: out } = partitionByCreation(all, notAfter);
147
162
  skipped.push(...out);
148
163
  return kept;
@@ -150,48 +165,49 @@ async function collectReviewUnit(token, owner, repo, issueNumber, { notAfter = n
150
165
 
151
166
  if (type === 'Feature') {
152
167
  // Referência direta à Feature: toda a subárvore (Stories + Tasks).
153
- for (const st of await children(issue.node_id)) {
168
+ for (const st of await children(issue.ref)) {
154
169
  if (isManual(st)) continue;
155
170
  addStory(st.number, st.nodeId, st.title);
156
- for (const t of await children(st.nodeId)) { if (isManual(t)) continue; addTask(t.number, t.nodeId, t.title); }
171
+ for (const t of await children(st.ref)) { if (isManual(t)) continue; addTask(t.number, t.nodeId, t.title); }
157
172
  }
158
173
  } else if (type === 'Story') {
159
174
  addStory(issue.number, issue.node_id, issue.title);
160
- for (const t of await children(issue.node_id)) { if (isManual(t)) continue; addTask(t.number, t.nodeId, t.title); }
175
+ for (const t of await children(issue.ref)) { if (isManual(t)) continue; addTask(t.number, t.nodeId, t.title); }
161
176
  } else { // Task → inclui a Story pai e as Tasks irmãs.
162
177
  addTask(issue.number, issue.node_id, issue.title);
163
- const parent = await getIssueParent(token, issue.node_id).catch(() => null);
178
+ const parent = await tracker.getParent({ ref: issue.ref }).catch(() => null);
164
179
  if (parent && detectIssueType({ title: parent.title }) === 'Story') {
165
- addStory(parent.number, parent.nodeId, parent.title);
166
- for (const t of await children(parent.nodeId)) { if (isManual(t)) continue; addTask(t.number, t.nodeId, t.title); }
180
+ addStory(Number(parent.ref.key), parent.ref.id, parent.title);
181
+ for (const t of await children(parent.ref)) { if (isManual(t)) continue; addTask(t.number, t.nodeId, t.title); }
167
182
  }
168
183
  }
169
184
  return { feature, stories, tasks, bugs, skipped, deferred: null };
170
185
  }
171
186
 
172
187
  // A Feature só avança quando TODAS as suas Stories já estiverem em Code Review
173
- // (ou etapa posterior). readToken lê as issues; projToken opera no Project.
188
+ // (ou etapa posterior). Uma porta só: `listChildren` usa o token simples e
189
+ // `getStage` o de board — a assimetria vive dentro da instância, não aqui.
174
190
  //
175
191
  // Devolve também as Stories: quem chama usa a mesma lista para tirar os PRs da
176
- // Feature do rascunho, sem repetir o listSubIssues.
177
- async function allStoriesReadyForReview(readToken, projToken, project, etapaField, featureNodeId) {
178
- const subs = await listSubIssues(readToken, featureNodeId).catch(() => []);
192
+ // Feature do rascunho, sem repetir a leitura dos filhos.
193
+ async function allStoriesReadyForReview(tracker, featureRef) {
194
+ const subs = (await tracker.listChildren({ ref: featureRef }).catch(() => [])).map(comoItem);
179
195
  const stories = subs
180
196
  .filter(s => detectIssueType({ title: s.title }) === 'Story')
181
- .map(s => ({ number: s.number, nodeId: s.nodeId }));
182
- if (!etapaField?.id) return { ready: true, stories }; // sem campo Etapa não há como checar — assume ok
197
+ .map(s => ({ number: s.number, nodeId: s.nodeId, ref: s.ref }));
183
198
  if (stories.length === 0) return { ready: true, stories };
184
199
  const tgtIdx = STAGE_ORDER.indexOf(CODE_REVIEW_STAGE);
185
200
  for (const st of stories) {
186
- const itemId = await addProjectItem(projToken, project.id, st.nodeId);
187
- const current = await getItemSingleSelectValue(projToken, itemId, etapaField.id).catch(() => null);
201
+ // Etapa ilegível conta como pendente, igual a antes: sem saber onde a Story
202
+ // está, avançar a Feature seria adivinhar que o trabalho acabou.
203
+ const current = await tracker.getStage({ ref: st.ref }).catch(() => null);
188
204
  const idx = current ? STAGE_ORDER.indexOf(current) : -1;
189
205
  if (idx === -1 || idx < tgtIdx) return { ready: false, stories }; // há Story pendente
190
206
  }
191
207
  return { ready: true, stories };
192
208
  }
193
209
 
194
- export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = false }) {
210
+ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = false, deps = {} }) {
195
211
  const token = await resolveToken();
196
212
  const projectToken = process.env.PROJECT_TOKEN || token;
197
213
  // Dois repositórios, que só coincidem no mono-repo: o hub (dono das issues e
@@ -211,7 +227,16 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
211
227
  const prRepo = resolvePrRepo(prRepoOpt, ctx);
212
228
  const prNum = parseInt(prNumber, 10);
213
229
 
214
- const pr = await getPR(token, prRepo.owner, prRepo.repo, prNum);
230
+ // Porta do repositório DO PR — `--pr-repo` pode apontar para um repo de
231
+ // código, e o número de PR colide entre repositórios.
232
+ const prScm = deps.scm ?? createGithubScm({
233
+ link: githubLink({
234
+ owner: prRepo.owner, repo: prRepo.repo, role: sameRepo(prRepo, hub) ? 'hub' : 'code',
235
+ }),
236
+ token,
237
+ });
238
+ const pr = await prScm.getPullRequest({ number: String(prNum) });
239
+ const prCriadoEm = pr?.createdAt ?? null;
215
240
  const linkMode = resolveLinkMode(cfg);
216
241
 
217
242
  // Duas fontes de vínculo, nesta ordem: o que o GitHub reconhece nativamente
@@ -220,10 +245,10 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
220
245
  // O vínculo nativo é sempre do repositório do PR — cross-repo o GitHub não
221
246
  // popula (RFC-005 §4) — então só conta quando o PR está no próprio hub.
222
247
  const linked = sameRepo(prRepo, hub)
223
- ? await getPRClosingIssues(token, prRepo.owner, prRepo.repo, prNum).catch(err => {
248
+ ? (await prScm.getPullRequestClosingWorkItems({ number: String(prNum) }).catch(err => {
224
249
  console.warn(`Não foi possível ler os vínculos nativos do PR: ${err.message}`);
225
250
  return [];
226
- })
251
+ })).map(Number)
227
252
  : [];
228
253
  const refs = extractIssueRefs(pr.body || '', { prRepo, linkMode });
229
254
  const issueNums = [...new Set([...linked, ...hubIssueNumbers(refs, hub)])];
@@ -258,20 +283,15 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
258
283
  return;
259
284
  }
260
285
 
261
- // Carrega projeto do .spec-wave.json
262
- const { project, error: projectError } = loadProjectConfig();
286
+ // Uma instância para todo o comando: o memo de item do board é dela, e é o
287
+ // que mantém a contagem de chamadas igual à de antes.
288
+ // PROJECT_TOKEN é a credencial do board; `token` segue fazendo as issues.
289
+ const { tracker, error: projectError } = openTracker({ token, projectToken, owner, repo, tracker: deps.tracker });
263
290
  if (projectError) {
264
291
  console.warn(`${projectError} — board não atualizado.`);
265
292
  return;
266
293
  }
267
294
 
268
- // Resolve campos uma vez, reutiliza em todas as Features.
269
- const etapaField = await resolveField(projectToken, project, 'Etapa').catch(() => null);
270
- const statusField = await resolveField(projectToken, project, 'Status').catch(() => null);
271
- // Repara o Work Item Type vazio de passagem (o apply nunca o escreveu).
272
- // Só preenche o vazio e nunca derruba o movimento — ver ensureWorkItemType.
273
- const typeField = await resolveField(projectToken, project, 'Work Item Type').catch(() => null);
274
-
275
295
  const seen = new Set();
276
296
  const updated = [];
277
297
  const featuresChecked = new Set();
@@ -283,7 +303,7 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
283
303
  // Stories → 👀 Code Review; Feature → Code Review só quando TODAS as suas
284
304
  // Stories já estiverem em Code Review.
285
305
  for (const num of issueNums) {
286
- const unit = await collectReviewUnit(token, owner, repo, num, { notAfter: pr.created_at });
306
+ const unit = await collectReviewUnit(tracker, num, { notAfter: prCriadoEm });
287
307
  const { feature, stories, tasks, bugs } = unit;
288
308
  if (unit.deferred) {
289
309
  deferred.add(unit.deferred);
@@ -302,9 +322,11 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
302
322
  if (seen.has(n)) continue;
303
323
  seen.add(n);
304
324
  try {
305
- const moved = await advanceToStage(
306
- projectToken, project, etapaField, statusField, info.nodeId, DONE_STAGE, DONE_STATUS,
307
- { typeField, itemType: 'Task' });
325
+ const moved = await advanceToStage({
326
+ tracker,
327
+ ref: { key: String(n), id: info.nodeId },
328
+ stage: DONE_STAGE, progress: DONE_STATUS, itemType: 'Task',
329
+ });
308
330
  if (moved) {
309
331
  updated.push(`#${n} ${info.title} → ${DONE_STAGE}`);
310
332
  console.log(`#${n} → "${DONE_STAGE}" / Status "${DONE_STATUS}".`);
@@ -321,9 +343,11 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
321
343
  if (seen.has(n)) continue;
322
344
  seen.add(n);
323
345
  try {
324
- const moved = await advanceToStage(
325
- projectToken, project, etapaField, statusField, info.nodeId, CODE_REVIEW_STAGE, TODO_STATUS,
326
- { typeField, itemType: 'Story' });
346
+ const moved = await advanceToStage({
347
+ tracker,
348
+ ref: { key: String(n), id: info.nodeId },
349
+ stage: CODE_REVIEW_STAGE, progress: TODO_STATUS, itemType: 'Story',
350
+ });
327
351
  if (moved) {
328
352
  updated.push(`#${n} ${info.title} → ${CODE_REVIEW_STAGE}`);
329
353
  console.log(`#${n} → "${CODE_REVIEW_STAGE}" / Status "${TODO_STATUS}".`);
@@ -340,9 +364,11 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
340
364
  if (seen.has(n)) continue;
341
365
  seen.add(n);
342
366
  try {
343
- const moved = await advanceToStage(
344
- projectToken, project, etapaField, statusField, info.nodeId, CODE_REVIEW_STAGE, TODO_STATUS,
345
- { typeField, itemType: 'Bug' });
367
+ const moved = await advanceToStage({
368
+ tracker,
369
+ ref: { key: String(n), id: info.nodeId },
370
+ stage: CODE_REVIEW_STAGE, progress: TODO_STATUS, itemType: 'Bug',
371
+ });
346
372
  if (moved) {
347
373
  updated.push(`#${n} ${info.title} → ${CODE_REVIEW_STAGE}`);
348
374
  console.log(`Bug #${n} → "${CODE_REVIEW_STAGE}" / Status "${TODO_STATUS}".`);
@@ -359,14 +385,16 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
359
385
  featuresChecked.add(feature.number);
360
386
  try {
361
387
  const { ready, stories: featureStories } = await allStoriesReadyForReview(
362
- token, projectToken, project, etapaField, feature.nodeId);
388
+ tracker, { key: String(feature.number), id: feature.nodeId });
363
389
  if (!ready) {
364
390
  console.log(`Feature #${feature.number} mantida em desenvolvimento — ainda há Stories pendentes (fora de "${CODE_REVIEW_STAGE}").`);
365
391
  } else if (!seen.has(feature.number)) {
366
392
  seen.add(feature.number);
367
- const moved = await advanceToStage(
368
- projectToken, project, etapaField, statusField, feature.nodeId, CODE_REVIEW_STAGE, TODO_STATUS,
369
- { typeField, itemType: 'Feature' });
393
+ const moved = await advanceToStage({
394
+ tracker,
395
+ ref: { key: String(feature.number), id: feature.nodeId },
396
+ stage: CODE_REVIEW_STAGE, progress: TODO_STATUS, itemType: 'Feature',
397
+ });
370
398
  if (moved) {
371
399
  updated.push(`#${feature.number} ${feature.title} (Feature) → ${CODE_REVIEW_STAGE}`);
372
400
  console.log(`Feature #${feature.number} → "${CODE_REVIEW_STAGE}" (todas as Stories concluídas).`);
@@ -380,6 +408,7 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
380
408
  // impossível de mergear no GitHub. Best-effort, como o resto.
381
409
  const marcados = await markFeaturePrsReady({
382
410
  token, owner, repo, feature, stories: featureStories, linkMode,
411
+ scmDe: deps.scmDe,
383
412
  codeRepos: codeReposForItems(cfg, { labels: feature.labels || [], children: featureStories }).repos,
384
413
  // `updated` vira a lista "Board atualizado" no comentário do PR;
385
414
  // desrascunhar não é movimento de board e ganha parágrafo próprio.
@@ -425,10 +454,13 @@ export async function codeReview({ prNumber, prRepo: prRepoOpt, resolveOnly = fa
425
454
  partes.push(
426
455
  `⏳ **Board não atualizado** para ${[...deferred].map(n => `#${n}`).join(', ')}: ` +
427
456
  'há decomposição em andamento. Depois que ela terminar, rode ' +
428
- `\`npx @spec-wave/cli@latest code-review --pr-number ${prNumber}\`.`
457
+ `\`npx ${cliRef()} code-review --pr-number ${prNumber}\`.`
429
458
  );
430
459
  }
431
- await commentOnIssue(token, prRepo.owner, prRepo.repo, prNum, partes.join('\n\n')).catch(() => {});
460
+ // O comentário vai no PR, no repositório do PR.
461
+ await (deps.prTracker ?? createGithubTracker({ token, owner: prRepo.owner, repo: prRepo.repo }))
462
+ .addComment({ ref: { key: String(prNum) }, body: partes.join('\n\n') })
463
+ .catch(() => {});
432
464
  }
433
465
 
434
466
  console.log(`code-review: ${updated.length} item(ns) atualizado(s) no board.`);