@spec-wave/cli 1.3.0 → 1.5.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 (59) hide show
  1. package/package.json +1 -1
  2. package/protocol/scm.v1.json +154 -0
  3. package/protocol/tracker.v1.json +175 -0
  4. package/src/api/github-rest.mjs +109 -0
  5. package/src/commands/audit.mjs +3 -4
  6. package/src/commands/code-review.mjs +11 -6
  7. package/src/commands/decompose.mjs +29 -9
  8. package/src/commands/doctor.mjs +389 -220
  9. package/src/commands/generate-bug.mjs +17 -7
  10. package/src/commands/generate-plan.mjs +21 -13
  11. package/src/commands/generate-qa-plan.mjs +19 -11
  12. package/src/commands/generate-spec.mjs +19 -6
  13. package/src/commands/implement.mjs +105 -49
  14. package/src/commands/init.mjs +36 -6
  15. package/src/commands/issue.mjs +6 -2
  16. package/src/commands/merge.mjs +31 -18
  17. package/src/commands/mode.mjs +18 -10
  18. package/src/commands/move.mjs +3 -3
  19. package/src/commands/order.mjs +30 -20
  20. package/src/commands/preflight.mjs +10 -5
  21. package/src/commands/qa-lead.mjs +41 -31
  22. package/src/commands/qa-run.mjs +83 -55
  23. package/src/commands/qa.mjs +10 -6
  24. package/src/commands/refresh.mjs +6 -3
  25. package/src/commands/repair-stage.mjs +1 -1
  26. package/src/commands/repo.mjs +7 -7
  27. package/src/commands/run.mjs +7 -4
  28. package/src/commands/story.mjs +3 -3
  29. package/src/commands/task.mjs +3 -3
  30. package/src/commands/triage.mjs +3 -3
  31. package/src/commands/uninstall.mjs +14 -5
  32. package/src/commands/update.mjs +47 -19
  33. package/src/commands/validate.mjs +3 -4
  34. package/src/commands/workspace.mjs +2 -2
  35. package/src/lib/artifact-publish.mjs +4 -3
  36. package/src/lib/board.mjs +22 -24
  37. package/src/lib/config-ports.mjs +114 -0
  38. package/src/lib/critique.mjs +11 -1
  39. package/src/lib/doc-source.mjs +16 -2
  40. package/src/lib/doctor-capabilities.mjs +168 -0
  41. package/src/lib/implement-board.mjs +6 -1
  42. package/src/lib/implement-stream.mjs +87 -0
  43. package/src/lib/pr-ready.mjs +24 -11
  44. package/src/lib/story-graph.mjs +26 -6
  45. package/src/lib/tag-registry.mjs +58 -0
  46. package/src/lib/usage-report.mjs +15 -2
  47. package/src/plugin/.claude-plugin/plugin.json +1 -1
  48. package/src/plugins/load.mjs +427 -0
  49. package/src/plugins/scm-github/index.mjs +71 -2
  50. package/src/plugins/tracker-github-projects/index.mjs +52 -10
  51. package/src/ports/capabilities.mjs +47 -0
  52. package/src/ports/index.mjs +347 -0
  53. package/src/ports/scm.mjs +39 -2
  54. package/src/ports/tracker.mjs +94 -3
  55. package/src/ports/types.mjs +59 -6
  56. package/src/setup/files.mjs +2 -2
  57. package/src/setup/labels.mjs +2 -2
  58. package/src/setup/project.mjs +2 -2
  59. package/src/ui/wizard.mjs +76 -1
@@ -18,8 +18,7 @@
18
18
 
19
19
  import { execSync } from 'node:child_process';
20
20
  import { resolveToken } from '../api/auth.mjs';
21
- import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
22
- import { createGithubScm, githubLink } from '../plugins/scm-github/index.mjs';
21
+ import { requireScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
23
22
  import { codeRepositories, repoLabel, repoLabelSpec } from '../lib/repo-role.mjs';
24
23
 
25
24
  import { openTracker, advanceToStage } from '../lib/board.mjs';
@@ -267,8 +266,10 @@ function formatItemsLintWarning(texts) {
267
266
  * catch: o aviso some e vira unhandled rejection.
268
267
  */
269
268
  async function publishFile(ctx, { doc, pathRel, content, nextLabel = null, extraFiles = [] }) {
269
+ const { deps = {} } = ctx;
270
270
  const { token, owner, repo, issue, issueNumber, base } = ctx;
271
271
  const published = await publishArtifact({
272
+ scm: deps.scm ?? null,
272
273
  token, owner, repo, doc,
273
274
  issueNumber: parseInt(issueNumber, 10),
274
275
  issueTitle: issue?.title || '',
@@ -309,6 +310,7 @@ export function codeReposPromptSection(config) {
309
310
  }
310
311
 
311
312
  async function draftDecomposition(ctx) {
313
+ const { deps = {} } = ctx;
312
314
  const {
313
315
  token, owner, repo, tracker, issue, issueNumber, type, labels, usage, root, runMode,
314
316
  docRel, dirRel, base,
@@ -317,6 +319,7 @@ async function draftDecomposition(ctx) {
317
319
  const kind = DECOMPOSE_TARGETS[type]; // Feature → 'stories'; RFC → 'tasks'
318
320
 
319
321
  const ler = (doc, pathRel) => loadArtifact({
322
+ scm: deps.scm ?? null,
320
323
  token, owner, repo, root, pathRel, doc, issueNumber: number, base,
321
324
  });
322
325
 
@@ -392,7 +395,7 @@ async function draftDecomposition(ctx) {
392
395
  type === 'RFC' ? 'decompose/rfc' : 'decompose/feature',
393
396
  { cwd: root },
394
397
  );
395
- const generated = parseModelJson(await generateDocument(
398
+ const generated = parseModelJson(await (deps.gerarDocumento ?? generateDocument)(
396
399
  systemPromptWithTools(decomposePrompt),
397
400
  userContent,
398
401
  { action: 'decompose', labels, usage, maxTurns: decomposePrompt.maxTurns, issueNumber, cwd: root }
@@ -482,6 +485,7 @@ async function draftDecomposition(ctx) {
482
485
  try {
483
486
  critique = await runCritique({
484
487
  kind: 'stories',
488
+ gerarEstruturado: deps.gerarEstruturado,
485
489
  decisions,
486
490
  spec: specContent,
487
491
  plan: planContent,
@@ -578,10 +582,12 @@ async function finishDraft(
578
582
  // ---------------------------------------------------------------------------
579
583
 
580
584
  async function applyDecomposition(ctx) {
585
+ const { deps = {} } = ctx;
581
586
  const { token, owner, repo, tracker, issueNumber, docRel, root, base } = ctx;
582
587
  const number = parseInt(issueNumber, 10);
583
588
 
584
589
  const rascunho = await loadArtifact({
590
+ scm: deps.scm ?? null,
585
591
  token, owner, repo, root, pathRel: docRel,
586
592
  doc: 'decomposition', issueNumber: number, base,
587
593
  });
@@ -1088,8 +1094,8 @@ async function createTasksFromDoc(ctx, doc) {
1088
1094
  }
1089
1095
 
1090
1096
  // Projeto + campos Etapa/Status do board (reutilizados em todos os itens).
1091
- async function resolveBoard({ token, projectToken, owner, repo, root }, { strict = false } = {}) {
1092
- const { tracker, error: projectError } = openTracker({
1097
+ async function resolveBoard({ token, projectToken, owner, repo, root, deps = {} }, { strict = false } = {}) {
1098
+ const { tracker, error: projectError } = await openTracker({
1093
1099
  token, projectToken, owner, repo, cwd: root || process.cwd(),
1094
1100
  });
1095
1101
  if (projectError) {
@@ -1170,7 +1176,17 @@ export function renderApplyFailureComment({ trigger, message, createdItems = [],
1170
1176
  // `apply` SEM default: `undefined` significa "ninguém decidiu" e é o que faz o
1171
1177
  // fallback por label valer no workflow. Um default `false` aqui reintroduziria
1172
1178
  // o bug, porque a CLI passa `undefined` quando a flag não é usada.
1173
- export async function decompose({ issueNumber, apply }) {
1179
+ /**
1180
+ * @param {object} params
1181
+ * @param {string|number} params.issueNumber
1182
+ * @param {boolean} [params.apply]
1183
+ * @param {object} [params.deps] seam de teste — `tracker`, `scm`,
1184
+ * `gerarDocumento` e `gerarEstruturado`. Viaja dentro do `ctx`, que já é o
1185
+ * objeto que atravessa as funções internas (`draftDecomposition`,
1186
+ * `applyDecomposition`, `publishFile`, `resolveBoard`): pendurá-lo ali é um
1187
+ * ponto de costura em vez de quatro.
1188
+ */
1189
+ export async function decompose({ issueNumber, apply, deps = {} }) {
1174
1190
  const token = await resolveToken();
1175
1191
  // PROJECT_TOKEN deve ter scope "project" para atualizar GitHub Projects v2.
1176
1192
  // Fallback para GITHUB_TOKEN (só funciona em repos pessoais sem org restrictions).
@@ -1180,7 +1196,10 @@ export async function decompose({ issueNumber, apply }) {
1180
1196
  console.log(`Modo de execução: ${runMode}`);
1181
1197
 
1182
1198
  const number = parseInt(issueNumber, 10);
1183
- const tracker = createGithubTracker({ token, projectToken, owner, repo });
1199
+ // `projectToken` viaja: este é o comando que cria dezenas de issues E mexe no
1200
+ // board, e a assimetria das duas credenciais é requisito (`PROJECT_TOKEN` só
1201
+ // para Projects v2). `getTracker` a repassa à fábrica sem promovê-la.
1202
+ const tracker = await requireTracker({ token, projectToken, owner, repo, deps });
1184
1203
  const issue = await tracker.getWorkItem({ ref: { key: String(number) } });
1185
1204
  const type = detectIssueType(issue);
1186
1205
  const labels = labelNames(issue);
@@ -1244,7 +1263,7 @@ export async function decompose({ issueNumber, apply }) {
1244
1263
  // Branch base: é dela que os documentos são lidos quando não estão no clone, e
1245
1264
  // é contra ela que o PR do rascunho é aberto. Best-effort — sem ela a leitura
1246
1265
  // cai para o default da API, que é o mesmo lugar.
1247
- const base = await createGithubScm({ link: githubLink({ owner, repo }), token })
1266
+ const base = await (await requireScm({ link: resolveScmLink({ owner, repo }), token, deps }))
1248
1267
  .defaultBranch().catch(() => null);
1249
1268
 
1250
1269
  // Comentários só são necessários no rascunho (contador de tentativas).
@@ -1262,6 +1281,7 @@ export async function decompose({ issueNumber, apply }) {
1262
1281
  const usageEntries = [];
1263
1282
  const ctx = {
1264
1283
  token, projectToken, owner, repo, tracker, issue, issueNumber, type, labels, comments,
1284
+ deps,
1265
1285
  root, runMode, docRel: `${docRel}/${DECOMPOSITION_FILE}`,
1266
1286
  dirRel: docRel,
1267
1287
  base,
@@ -1301,6 +1321,6 @@ export async function decompose({ issueNumber, apply }) {
1301
1321
  throw err;
1302
1322
  } finally {
1303
1323
  // Best-effort: nunca propaga erro (ver recordUsage).
1304
- await recordUsage({ token, owner, repo, issueNumber: number, entries: usageEntries });
1324
+ await recordUsage({ token, owner, repo, tracker, issueNumber: number, entries: usageEntries });
1305
1325
  }
1306
1326
  }