@spec-wave/cli 1.4.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.
- package/package.json +1 -1
- package/protocol/scm.v1.json +154 -0
- package/protocol/tracker.v1.json +175 -0
- package/src/api/github-rest.mjs +109 -0
- package/src/commands/audit.mjs +3 -5
- package/src/commands/code-review.mjs +10 -6
- package/src/commands/decompose.mjs +7 -6
- package/src/commands/doctor.mjs +389 -220
- package/src/commands/generate-bug.mjs +2 -2
- package/src/commands/generate-plan.mjs +5 -7
- package/src/commands/generate-qa-plan.mjs +3 -5
- package/src/commands/generate-spec.mjs +2 -2
- package/src/commands/implement.mjs +33 -21
- package/src/commands/init.mjs +36 -7
- package/src/commands/issue.mjs +6 -2
- package/src/commands/merge.mjs +20 -15
- package/src/commands/mode.mjs +18 -11
- package/src/commands/move.mjs +3 -3
- package/src/commands/order.mjs +3 -3
- package/src/commands/preflight.mjs +10 -6
- package/src/commands/qa-lead.mjs +6 -8
- package/src/commands/qa-run.mjs +39 -27
- package/src/commands/qa.mjs +10 -7
- package/src/commands/refresh.mjs +6 -3
- package/src/commands/repair-stage.mjs +1 -1
- package/src/commands/repo.mjs +6 -7
- package/src/commands/run.mjs +7 -5
- package/src/commands/story.mjs +3 -3
- package/src/commands/task.mjs +3 -3
- package/src/commands/triage.mjs +3 -3
- package/src/commands/uninstall.mjs +14 -6
- package/src/commands/update.mjs +47 -20
- package/src/commands/validate.mjs +3 -5
- package/src/commands/workspace.mjs +2 -2
- package/src/lib/artifact-publish.mjs +3 -3
- package/src/lib/board.mjs +22 -24
- package/src/lib/config-ports.mjs +114 -0
- package/src/lib/doc-source.mjs +16 -3
- package/src/lib/doctor-capabilities.mjs +168 -0
- package/src/lib/implement-board.mjs +1 -1
- package/src/lib/pr-ready.mjs +23 -11
- package/src/lib/story-graph.mjs +19 -6
- package/src/lib/tag-registry.mjs +58 -0
- package/src/lib/usage-report.mjs +15 -2
- package/src/plugin/.claude-plugin/plugin.json +1 -1
- package/src/plugins/load.mjs +427 -0
- package/src/plugins/scm-github/index.mjs +71 -2
- package/src/plugins/tracker-github-projects/index.mjs +52 -10
- package/src/ports/capabilities.mjs +47 -0
- package/src/ports/index.mjs +201 -46
- package/src/ports/scm.mjs +39 -2
- package/src/ports/tracker.mjs +43 -2
- package/src/ports/types.mjs +30 -6
- package/src/setup/files.mjs +2 -3
- package/src/setup/labels.mjs +2 -2
- package/src/setup/project.mjs +2 -2
- package/src/ui/wizard.mjs +76 -1
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
// RELATADOS — sem o relato, ela só avalia coerência interna.
|
|
10
10
|
// 3. Escreve em docs/bugs/<slug>/, fora de docs/features/.
|
|
11
11
|
import { resolveToken } from '../api/auth.mjs';
|
|
12
|
-
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
13
12
|
import { generateDocument } from '../lib/claude.mjs';
|
|
14
13
|
import { unwrapGeneratedDoc } from '../lib/unwrap-doc.mjs';
|
|
15
14
|
import { recordUsage } from '../lib/usage-report.mjs';
|
|
@@ -22,6 +21,7 @@ import { renderPrLine } from '../lib/artifact-pr.mjs';
|
|
|
22
21
|
import {
|
|
23
22
|
runCritique, resolveCritiqueAttempt, renderNeedsHumanComment,
|
|
24
23
|
} from '../lib/critique.mjs';
|
|
24
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
25
25
|
import {
|
|
26
26
|
LABEL_BUG, LABEL_CRITIQUE_FAILED, LABEL_NEEDS_HUMAN, REQUIRED_BUG_SECTIONS,
|
|
27
27
|
TARGET_LANGUAGE, DEFAULT_MAX_CRITIQUE_ATTEMPTS, labelNames,
|
|
@@ -63,7 +63,7 @@ export async function generateBug({ issueNumber, deps = {} }) {
|
|
|
63
63
|
// do runner mandando exportá-la — dentro de um repo que já sabe seu owner/repo.
|
|
64
64
|
const { owner, repo, root, config, mode } = resolveFlowContext({ command: 'generate-bug', requireRoot: true });
|
|
65
65
|
const n = parseInt(issueNumber, 10);
|
|
66
|
-
const tracker =
|
|
66
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
67
67
|
const ref = { key: String(n) };
|
|
68
68
|
|
|
69
69
|
console.log(`Buscando issue #${n}...`);
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { readFileSync, existsSync } from 'node:fs';
|
|
3
3
|
import { resolveToken } from '../api/auth.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
6
|
-
import { resolveScmLink } from '../ports/index.mjs';
|
|
4
|
+
import { requireScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
|
|
7
5
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
8
6
|
import {
|
|
9
7
|
allowsSpecPlan, SPEC_PLAN_EXCLUDED_TYPES, TARGET_LANGUAGE,
|
|
@@ -151,8 +149,8 @@ export async function generatePlan({ issueNumber, deps = {} }) {
|
|
|
151
149
|
console.log(`Modo de execução: ${mode}`);
|
|
152
150
|
|
|
153
151
|
console.log(`Buscando issue #${issueNumber}...`);
|
|
154
|
-
const tracker =
|
|
155
|
-
const scm =
|
|
152
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
153
|
+
const scm = await requireScm({ link: resolveScmLink({ owner, repo }), token, deps });
|
|
156
154
|
const ref = { key: String(parseInt(issueNumber, 10)) };
|
|
157
155
|
const issue = await tracker.getWorkItem({ ref });
|
|
158
156
|
|
|
@@ -413,8 +411,8 @@ export async function critique({ issueNumber, file, kind, failOnGrave = false })
|
|
|
413
411
|
console.log(`Modo de execução: ${mode}`);
|
|
414
412
|
|
|
415
413
|
const n = parseInt(issueNumber, 10);
|
|
416
|
-
const tracker =
|
|
417
|
-
const scm =
|
|
414
|
+
const tracker = await requireTracker({ token, owner, repo });
|
|
415
|
+
const scm = await requireScm({ link: resolveScmLink({ owner, repo }), token });
|
|
418
416
|
const ref = { key: String(n) };
|
|
419
417
|
const issue = await tracker.getWorkItem({ ref });
|
|
420
418
|
const type = detectIssueType(issue);
|
|
@@ -12,9 +12,7 @@
|
|
|
12
12
|
// Só um plano estruturalmente válido gasta uma chamada de crítica.
|
|
13
13
|
|
|
14
14
|
import { resolveToken } from '../api/auth.mjs';
|
|
15
|
-
import {
|
|
16
|
-
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
17
|
-
import { resolveScmLink } from '../ports/index.mjs';
|
|
15
|
+
import { requireScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
|
|
18
16
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
19
17
|
import { generateDocument } from '../lib/claude.mjs';
|
|
20
18
|
import { unwrapGeneratedDoc } from '../lib/unwrap-doc.mjs';
|
|
@@ -79,8 +77,8 @@ export async function generateQaPlan({ issueNumber, deps = {} }) {
|
|
|
79
77
|
console.log(`Modo de execução: ${runMode}`);
|
|
80
78
|
|
|
81
79
|
const number = parseInt(issueNumber, 10);
|
|
82
|
-
const tracker =
|
|
83
|
-
const scm =
|
|
80
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
81
|
+
const scm = await requireScm({ link: resolveScmLink({ owner, repo }), token, deps });
|
|
84
82
|
const ref = { key: String(number) };
|
|
85
83
|
const issue = await tracker.getWorkItem({ ref });
|
|
86
84
|
const type = detectIssueType(issue);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { resolveToken } from '../api/auth.mjs';
|
|
2
|
-
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
3
2
|
import { generateDocument } from '../lib/claude.mjs';
|
|
4
3
|
import { unwrapGeneratedDoc } from '../lib/unwrap-doc.mjs';
|
|
5
4
|
import { recordUsage } from '../lib/usage-report.mjs';
|
|
@@ -9,6 +8,7 @@ import { publishArtifact } from '../lib/artifact-publish.mjs';
|
|
|
9
8
|
import { renderPrLine } from '../lib/artifact-pr.mjs';
|
|
10
9
|
import { loadPrompt, systemPromptWithTools } from '../lib/prompt-loader.mjs';
|
|
11
10
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
11
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
12
12
|
import {
|
|
13
13
|
allowsSpecPlan, SPEC_PLAN_EXCLUDED_TYPES, TARGET_LANGUAGE, labelNames,
|
|
14
14
|
} from '../config.mjs';
|
|
@@ -46,7 +46,7 @@ export async function generateSpec({ issueNumber, deps = {} }) {
|
|
|
46
46
|
const gerar = deps.gerarDocumento ?? generateDocument;
|
|
47
47
|
|
|
48
48
|
console.log(`Buscando issue #${issueNumber}...`);
|
|
49
|
-
const tracker =
|
|
49
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
50
50
|
const ref = { key: String(issueNumber) };
|
|
51
51
|
const issue = await tracker.getWorkItem({ ref });
|
|
52
52
|
|
|
@@ -9,14 +9,11 @@ import {
|
|
|
9
9
|
PROGRESS_TODO, PROGRESS_IN_PROGRESS, PROGRESS_DONE, labelNames,
|
|
10
10
|
TRAILER_STORY, TRAILER_TASKS, TRAILER_AGENT,
|
|
11
11
|
} from '../config.mjs';
|
|
12
|
-
import {
|
|
13
|
-
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
14
|
-
import { resolveScmLink } from '../ports/index.mjs';
|
|
12
|
+
import { getScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
|
|
15
13
|
|
|
16
14
|
// Fábrica local: este arquivo é longo e os helpers recebem (token, owner, repo)
|
|
17
15
|
// separadamente. As operações abaixo são todas de LEITURA e não usam o memo do
|
|
18
16
|
// board, então construir por chamada não muda contagem nenhuma.
|
|
19
|
-
const trackerDe = (token, owner, repo) => createGithubTracker({ token, owner, repo });
|
|
20
17
|
|
|
21
18
|
/** WorkItem → a forma que este arquivo consome em dezenas de pontos. */
|
|
22
19
|
const comoSubIssue = w => ({
|
|
@@ -69,7 +66,9 @@ const MAX_COMMENT_CHARS = 2000;
|
|
|
69
66
|
// e para as instruções de fim de Story (mover a Feature para Code Review). Limita
|
|
70
67
|
// a profundidade para evitar loops em dados inconsistentes.
|
|
71
68
|
async function resolveFeature(token, owner, repo, startRef, trackerInjetado) {
|
|
72
|
-
|
|
69
|
+
// A porta chega SEMPRE: quem chama passa `deps.tracker`, já resolvido no
|
|
70
|
+
// bootstrap. O parâmetro fica por ser a assinatura que o teste usa.
|
|
71
|
+
const tracker = trackerInjetado;
|
|
73
72
|
let current = startRef;
|
|
74
73
|
for (let depth = 0; depth < 5 && current; depth++) {
|
|
75
74
|
const parent = await tracker.getParent({ ref: current });
|
|
@@ -104,9 +103,13 @@ async function probeMissingDoc({ token, owner, repo, root, pathRel, doc, issueNu
|
|
|
104
103
|
if (achado?.state === 'remote') return missingDocMessage({ pathRel, onRemote: true, fallback });
|
|
105
104
|
if (achado?.state === 'missing') return missingDocMessage({ pathRel, onRemote: false, fallback });
|
|
106
105
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
// `getScm` e não `requireScm`: esta sonda é best-effort — `existsOnRemote`
|
|
107
|
+
// recebe `null` e devolve "não sei", e a mensagem de documento ausente sai do
|
|
108
|
+
// mesmo jeito. Derrubar o `implement` porque a SONDA não pôde ser construída
|
|
109
|
+
// seria trocar um aviso por uma falha.
|
|
110
|
+
const { scm } = token && owner && repo
|
|
111
|
+
? await getScm({ link: resolveScmLink({ owner, repo }), token, deps })
|
|
112
|
+
: { scm: deps.scm ?? null };
|
|
110
113
|
const onRemote = await existsOnRemote({ scm, pathRel });
|
|
111
114
|
return missingDocMessage({ pathRel, onRemote, fallback });
|
|
112
115
|
}
|
|
@@ -651,7 +654,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot,
|
|
|
651
654
|
// de um Bug pode ser Feature OU Story — o tipo vem do prefixo do título.
|
|
652
655
|
let parent = null;
|
|
653
656
|
try {
|
|
654
|
-
const p0 = await
|
|
657
|
+
const p0 = await deps.tracker
|
|
655
658
|
.getParent({ ref: { key: String(bug.number), id: bug.node_id } });
|
|
656
659
|
if (p0?.ref?.key) {
|
|
657
660
|
parent = {
|
|
@@ -688,7 +691,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot,
|
|
|
688
691
|
});
|
|
689
692
|
|
|
690
693
|
const comments = [];
|
|
691
|
-
const all = await
|
|
694
|
+
const all = await deps.tracker.listComments({ ref: { key: String(issueNumber) } }).catch(() => []);
|
|
692
695
|
if (all.length > 0) {
|
|
693
696
|
const items = all.slice(-MAX_COMMENTS_PER_ISSUE).map(c => ({
|
|
694
697
|
...c,
|
|
@@ -708,7 +711,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot,
|
|
|
708
711
|
|
|
709
712
|
const blockedByWarnings = [];
|
|
710
713
|
try {
|
|
711
|
-
const blocked = await
|
|
714
|
+
const blocked = await deps.tracker.listBlockedBy({ ref: { key: String(issueNumber) } }).catch(() => []);
|
|
712
715
|
for (const b of blocked) {
|
|
713
716
|
// `listBlockedBy` devolve `{ ref, title, state }` — nunca `number`. Lido
|
|
714
717
|
// cru, o aviso que vai para o contexto do executor saía "#undefined".
|
|
@@ -892,7 +895,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
892
895
|
try {
|
|
893
896
|
const internal = new Set(stories.map(s => s.number));
|
|
894
897
|
const featureDeps = new Set(parseDependencies(feature.body));
|
|
895
|
-
const featureBlocked = await
|
|
898
|
+
const featureBlocked = await deps.tracker.listBlockedBy({ ref: { key: String(itemNumber(feature)) } }).catch(() => []);
|
|
896
899
|
for (const n of itemNumbers(featureBlocked)) featureDeps.add(n);
|
|
897
900
|
const check = [
|
|
898
901
|
{ kind: 'Feature', number: itemNumber(feature), deps: featureDeps },
|
|
@@ -901,7 +904,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
901
904
|
for (const c of check) {
|
|
902
905
|
for (const depNumber of [...c.deps].sort((a, b) => a - b)) {
|
|
903
906
|
if (internal.has(depNumber)) continue;
|
|
904
|
-
const dep = await
|
|
907
|
+
const dep = await deps.tracker
|
|
905
908
|
.getWorkItem({ ref: { key: String(depNumber) } })
|
|
906
909
|
.then(w => w && comoSubIssue(w))
|
|
907
910
|
.catch(() => null);
|
|
@@ -922,7 +925,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
922
925
|
...pending.map(s => ({ number: s.number, kind: 'Story' })),
|
|
923
926
|
];
|
|
924
927
|
for (const src of commentSources) {
|
|
925
|
-
const all = await
|
|
928
|
+
const all = await deps.tracker.listComments({ ref: { key: String(src.number) } }).catch(() => []);
|
|
926
929
|
if (all.length === 0) continue;
|
|
927
930
|
const items = all.slice(-MAX_COMMENTS_PER_ISSUE).map(c => ({
|
|
928
931
|
...c,
|
|
@@ -1064,12 +1067,21 @@ export async function implement({
|
|
|
1064
1067
|
return;
|
|
1065
1068
|
}
|
|
1066
1069
|
|
|
1070
|
+
// Bloco E, leva 4: a porta do hub é resolvida UMA vez, aqui, e viaja no
|
|
1071
|
+
// `deps` — que é por onde ela já chegava nas 13 chamadas espalhadas por cinco
|
|
1072
|
+
// funções. Resolver em cada site custaria 13 leituras de config (`loadConfig`
|
|
1073
|
+
// não cacheia) e manteria 13 construções duplicadas de uma porta única.
|
|
1074
|
+
//
|
|
1075
|
+
// Reatribuir o parâmetro é legal e é o menor diff possível: o objeto novo
|
|
1076
|
+
// alcança tudo que recebe `deps` daqui para baixo.
|
|
1077
|
+
deps = { ...deps, tracker: await requireTracker({ token, owner, repo, deps }) };
|
|
1078
|
+
|
|
1067
1079
|
p.intro(chalk.bold(`spec-wave implement #${issueNumber}`));
|
|
1068
1080
|
|
|
1069
1081
|
// 2. Lê a issue alvo.
|
|
1070
1082
|
let issue;
|
|
1071
1083
|
try {
|
|
1072
|
-
issue = await
|
|
1084
|
+
issue = await deps.tracker
|
|
1073
1085
|
.getWorkItem({ ref: { key: String(issueNumber) } })
|
|
1074
1086
|
.then(w => w && comoSubIssue(w));
|
|
1075
1087
|
} catch (err) {
|
|
@@ -1082,7 +1094,7 @@ export async function implement({
|
|
|
1082
1094
|
const type = detectIssueType(issue);
|
|
1083
1095
|
let tasks;
|
|
1084
1096
|
if (type === 'Story') {
|
|
1085
|
-
const subs = (await
|
|
1097
|
+
const subs = (await deps.tracker.listChildren({ ref: issue.ref })).map(comoSubIssue);
|
|
1086
1098
|
tasks = subs.filter(s => detectIssueType({ title: s.title, labels: s.labels }) === 'Task');
|
|
1087
1099
|
if (tasks.length === 0) {
|
|
1088
1100
|
p.log.error(`Story #${issueNumber} não tem Tasks (sub-issues) para implementar.`);
|
|
@@ -1153,7 +1165,7 @@ export async function implement({
|
|
|
1153
1165
|
// verificar antes de mover a Feature.
|
|
1154
1166
|
let siblingStories = [];
|
|
1155
1167
|
if (type === 'Story' && feature?.nodeId) {
|
|
1156
|
-
const featureSubs = (await
|
|
1168
|
+
const featureSubs = (await deps.tracker
|
|
1157
1169
|
.listChildren({ ref: { key: String(itemNumber(feature)), id: feature.nodeId } })
|
|
1158
1170
|
.catch(() => [])).map(comoSubIssue);
|
|
1159
1171
|
siblingStories = featureSubs
|
|
@@ -1172,7 +1184,7 @@ export async function implement({
|
|
|
1172
1184
|
}
|
|
1173
1185
|
commentSources.push({ number: itemNumber(issue), kind: type });
|
|
1174
1186
|
for (const src of commentSources) {
|
|
1175
|
-
const all = await
|
|
1187
|
+
const all = await deps.tracker.listComments({ ref: { key: String(src.number) } }).catch(() => []);
|
|
1176
1188
|
if (all.length === 0) continue;
|
|
1177
1189
|
const items = all.slice(-MAX_COMMENTS_PER_ISSUE).map(c => ({
|
|
1178
1190
|
...c,
|
|
@@ -1190,7 +1202,7 @@ export async function implement({
|
|
|
1190
1202
|
try {
|
|
1191
1203
|
let sinceIso = issue.createdAt || null;
|
|
1192
1204
|
if (feature?.number) {
|
|
1193
|
-
const featureIssue = await
|
|
1205
|
+
const featureIssue = await deps.tracker
|
|
1194
1206
|
.getWorkItem({ ref: { key: String(itemNumber(feature)) } })
|
|
1195
1207
|
.then(w => w && comoSubIssue(w))
|
|
1196
1208
|
.catch(() => null);
|
|
@@ -1208,10 +1220,10 @@ export async function implement({
|
|
|
1208
1220
|
const blockedByWarnings = [];
|
|
1209
1221
|
try {
|
|
1210
1222
|
const depNumbers = new Set(parseDependencies(issue.body));
|
|
1211
|
-
const blocked = await
|
|
1223
|
+
const blocked = await deps.tracker.listBlockedBy({ ref: { key: String(itemNumber(issue)) } }).catch(() => []);
|
|
1212
1224
|
for (const n of itemNumbers(blocked)) depNumbers.add(n);
|
|
1213
1225
|
for (const depNumber of [...depNumbers].sort((a, b) => a - b)) {
|
|
1214
|
-
const dep = await
|
|
1226
|
+
const dep = await deps.tracker
|
|
1215
1227
|
.getWorkItem({ ref: { key: String(depNumber) } })
|
|
1216
1228
|
.then(w => w && comoSubIssue(w))
|
|
1217
1229
|
.catch(() => null);
|
package/src/commands/init.mjs
CHANGED
|
@@ -7,9 +7,9 @@ import { runWizard } from '../ui/wizard.mjs';
|
|
|
7
7
|
import { setupProject } from '../setup/project.mjs';
|
|
8
8
|
import { setupLabels } from '../setup/labels.mjs';
|
|
9
9
|
import { setupFiles } from '../setup/files.mjs';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_SCM_KIND, DEFAULT_TRACKER_KIND, requireScm, requireTracker, resolveScmLink,
|
|
12
|
+
} from '../ports/index.mjs';
|
|
13
13
|
import {
|
|
14
14
|
CONFIG_FILE, AI_PROVIDERS, getProvider, DEFAULT_PROVIDER, PORTAL_URL, WORKFLOW_FILES, CODE_WORKFLOW_FILES,
|
|
15
15
|
ISSUE_TEMPLATE_FILES, STATUS_OPTIONS, ALL_LABELS, HUB_DISPATCH_SECRET,
|
|
@@ -93,6 +93,7 @@ export async function init(options) {
|
|
|
93
93
|
|
|
94
94
|
// --- Wizard ou flags ---
|
|
95
95
|
let owner, repo, projectTitle, provider, model;
|
|
96
|
+
let trackerKind, scmKind;
|
|
96
97
|
if (role === 'code') {
|
|
97
98
|
const self = parseRepoRef(options.repo);
|
|
98
99
|
if (!self) {
|
|
@@ -123,8 +124,15 @@ export async function init(options) {
|
|
|
123
124
|
p.log.info(`Projeto: ${projectTitle}`);
|
|
124
125
|
p.log.info(`IA: ${getProvider(provider).label} · modelo ${model}`);
|
|
125
126
|
} else {
|
|
126
|
-
({
|
|
127
|
+
({
|
|
128
|
+
owner, repo, projectTitle, provider, model, trackerKind, scmKind,
|
|
129
|
+
} = await runWizard());
|
|
127
130
|
}
|
|
131
|
+
// Modo não-interativo (`--repo`): sem wizard não há pergunta, e o fornecedor é o
|
|
132
|
+
// embutido. Uma flag para escolhê-lo entra quando houver um segundo — hoje ela
|
|
133
|
+
// só daria ao usuário uma forma de errar.
|
|
134
|
+
trackerKind ??= DEFAULT_TRACKER_KIND;
|
|
135
|
+
scmKind ??= DEFAULT_SCM_KIND;
|
|
128
136
|
|
|
129
137
|
const providerMeta = getProvider(provider);
|
|
130
138
|
|
|
@@ -140,7 +148,13 @@ export async function init(options) {
|
|
|
140
148
|
try {
|
|
141
149
|
// `verify()` é a sonda org-vs-user: o GitHub App só alcança Projects v2 de
|
|
142
150
|
// ORGANIZAÇÃO, e é aqui que o init recusa antes de criar qualquer coisa.
|
|
143
|
-
|
|
151
|
+
// `kind` EXPLÍCITO: o `init` roda antes de existir `.spec-wave.json`, então
|
|
152
|
+
// não há bloco `tracker` a normalizar. É esta a API que o bloco F vai usar
|
|
153
|
+
// para carregar o fornecedor que o usuário escolher nas duas perguntas.
|
|
154
|
+
const trackerSonda = await requireTracker({
|
|
155
|
+
token, owner, repo, kind: trackerKind,
|
|
156
|
+
});
|
|
157
|
+
const diag = await trackerSonda.verify();
|
|
144
158
|
ownerType = diag.facts.ownerType;
|
|
145
159
|
} catch (err) {
|
|
146
160
|
ownerSpinner.stop('');
|
|
@@ -189,8 +203,9 @@ export async function init(options) {
|
|
|
189
203
|
const localConfigPath = path.join(process.cwd(), CONFIG_FILE);
|
|
190
204
|
const raw = existsSync(localConfigPath)
|
|
191
205
|
? readFileSync(localConfigPath, 'utf-8')
|
|
192
|
-
: await
|
|
193
|
-
|
|
206
|
+
: await (await requireScm({
|
|
207
|
+
link: resolveScmLink({ owner, repo }), token,
|
|
208
|
+
})).readFile({ path: CONFIG_FILE });
|
|
194
209
|
if (raw) {
|
|
195
210
|
const existing = JSON.parse(raw);
|
|
196
211
|
if (existing.project) {
|
|
@@ -294,6 +309,20 @@ export async function init(options) {
|
|
|
294
309
|
role,
|
|
295
310
|
owner,
|
|
296
311
|
repo,
|
|
312
|
+
// Bloco F: o fornecedor fica EXPLÍCITO num repo novo. Sem `config` nem
|
|
313
|
+
// `capabilities` ao lado, de propósito:
|
|
314
|
+
//
|
|
315
|
+
// • `tracker.config` seria uma cópia do bloco `project` logo abaixo — o
|
|
316
|
+
// bloco D já o deriva na leitura, e duas fontes com o mesmo conteúdo
|
|
317
|
+
// divergem no dia em que uma das duas for editada. Um plugin que
|
|
318
|
+
// precise de configuração PRÓPRIA (o `site`/`projectKey` de um Jira) a
|
|
319
|
+
// recebe do `setup()` dele, não daqui;
|
|
320
|
+
// • `capabilities` espelhadas é o desvio declarado da §9.1 (§3.2 do
|
|
321
|
+
// plano): com um plugin que sobe junto com a CLI, a cópia nunca
|
|
322
|
+
// divergiria do runtime — envelheceria sem informar nada, e uma cópia
|
|
323
|
+
// que ninguém pode contradizer é a pior espécie.
|
|
324
|
+
tracker: { kind: trackerKind },
|
|
325
|
+
scm: { kind: scmKind },
|
|
297
326
|
project: {
|
|
298
327
|
title: projectTitle,
|
|
299
328
|
url: projectUrl ?? null,
|
package/src/commands/issue.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { readFileSync } from 'node:fs';
|
|
|
4
4
|
import { resolveToken } from '../api/auth.mjs';
|
|
5
5
|
import { CONFIG_FILE, PRIORITY_LABELS, WORK_ITEM_TYPES, initialStageForType } from '../config.mjs';
|
|
6
6
|
import { findConfigPath } from '../lib/project-root.mjs';
|
|
7
|
-
import {
|
|
7
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
8
8
|
|
|
9
9
|
const VALID_PRIORITIES = PRIORITY_LABELS.map(l => l.name);
|
|
10
10
|
|
|
@@ -77,7 +77,11 @@ export async function issue(options) {
|
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
// `project` vem do CHAMADOR e não do config: o `issue` o recebe já resolvido
|
|
81
|
+
// por quem o invocou. `getTracker` o normaliza a partir do bloco `tracker`, então
|
|
82
|
+
// passar `board: true` aqui exigiria um bloco que este caminho não usa — o que
|
|
83
|
+
// o `issue` faz com a porta é criar e etiquetar, não mexer no board.
|
|
84
|
+
const tracker = await requireTracker({ token, owner, repo, deps: options.deps || {} });
|
|
81
85
|
|
|
82
86
|
p.intro(chalk.bold(`spec-wave issue (${type})`));
|
|
83
87
|
|
package/src/commands/merge.mjs
CHANGED
|
@@ -20,9 +20,7 @@ import * as p from '@clack/prompts';
|
|
|
20
20
|
import chalk from 'chalk';
|
|
21
21
|
|
|
22
22
|
import { resolveToken } from '../api/auth.mjs';
|
|
23
|
-
import {
|
|
24
|
-
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
25
|
-
import { resolveScmLink } from '../ports/index.mjs';
|
|
23
|
+
import { requireScm, requireTracker, resolveScmLink } from '../ports/index.mjs';
|
|
26
24
|
import { missingTrailers } from '../lib/commit-trailers.mjs';
|
|
27
25
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
28
26
|
import { orderStories } from '../lib/dependencies.mjs';
|
|
@@ -243,12 +241,16 @@ function comoPrLegado(pr) {
|
|
|
243
241
|
|
|
244
242
|
function criarScmDe(token, hub) {
|
|
245
243
|
const cache = new Map();
|
|
246
|
-
|
|
244
|
+
// ASSÍNCRONA desde a leva 4 do bloco E. O memo continua guardando a PORTA e não
|
|
245
|
+
// a promessa, porque o `await` fica DENTRO dele: guardar a promessa faria cada
|
|
246
|
+
// chamada esperar de novo e perderia o ponto do cache, que é não reconstruir a
|
|
247
|
+
// porta por repositório num comando que percorre a pilha inteira.
|
|
248
|
+
return async (r) => {
|
|
247
249
|
const link = resolveScmLink({
|
|
248
250
|
owner: r.owner, repo: r.repo,
|
|
249
251
|
role: r.owner === hub.owner && r.repo === hub.repo ? 'hub' : 'code',
|
|
250
252
|
});
|
|
251
|
-
if (!cache.has(link.id)) cache.set(link.id,
|
|
253
|
+
if (!cache.has(link.id)) cache.set(link.id, await requireScm({ link, token }));
|
|
252
254
|
return cache.get(link.id);
|
|
253
255
|
};
|
|
254
256
|
}
|
|
@@ -303,14 +305,17 @@ export async function merge({
|
|
|
303
305
|
s.start('Montando o plano de merge...');
|
|
304
306
|
|
|
305
307
|
const scmDe = deps.scmDe ?? criarScmDe(token, { owner, repo });
|
|
306
|
-
|
|
308
|
+
// `await`: a fábrica virou assíncrona. Sem ele `hubScm` é Promise e todo
|
|
309
|
+
// método dela é `undefined` — o mesmo defeito que a leva 3 achou no
|
|
310
|
+
// `pr-ready`, onde o `.catch` do call site NÃO pega o TypeError sincrônico.
|
|
311
|
+
const hubScm = await scmDe({ owner, repo });
|
|
307
312
|
|
|
308
313
|
let featureIssue;
|
|
309
314
|
let defaultBranch;
|
|
310
315
|
try {
|
|
311
|
-
featureIssue = await (
|
|
316
|
+
featureIssue = await (await requireTracker({ token, owner, repo, deps }))
|
|
312
317
|
.getWorkItem({ ref: { key: String(featureNumber) } });
|
|
313
|
-
defaultBranch = await scmDe({ owner, repo }).defaultBranch();
|
|
318
|
+
defaultBranch = await (await scmDe({ owner, repo })).defaultBranch();
|
|
314
319
|
} catch (err) {
|
|
315
320
|
s.stop('');
|
|
316
321
|
p.log.error(`Não foi possível ler ${owner}/${repo}#${featureNumber}: ${err.message}`);
|
|
@@ -380,7 +385,7 @@ export async function merge({
|
|
|
380
385
|
const repos = [hub, ...codeRepos.map(r => ({ owner: r.owner, repo: r.repo, slug: r.slug }))];
|
|
381
386
|
const defaultBranches = new Map();
|
|
382
387
|
for (const r of codeRepos) {
|
|
383
|
-
const branch = await scmDe(r).defaultBranch().catch(() => null);
|
|
388
|
+
const branch = await (await scmDe(r)).defaultBranch().catch(() => null);
|
|
384
389
|
if (branch) defaultBranches.set(repoKey(r), branch);
|
|
385
390
|
else p.log.warn(`Não consegui ler a branch default de ${r.owner}/${r.repo} — assumindo "${defaultBranch}".`);
|
|
386
391
|
}
|
|
@@ -412,7 +417,7 @@ export async function merge({
|
|
|
412
417
|
if (codeRepos.length > 0 || sorted.some(story => (prsByStory.get(story) || []).length === 0)) {
|
|
413
418
|
const abertos = [];
|
|
414
419
|
for (const r of repos) {
|
|
415
|
-
const lista = (await scmDe(r).listOpenPullRequests().catch(() => [])).map(comoPrLegado);
|
|
420
|
+
const lista = (await (await scmDe(r)).listOpenPullRequests().catch(() => [])).map(comoPrLegado);
|
|
416
421
|
abertos.push(...lista.map(pr => ({ ...pr, repo: { owner: r.owner, repo: r.repo } })));
|
|
417
422
|
}
|
|
418
423
|
const linkMode = resolveLinkMode(fileConfig);
|
|
@@ -449,7 +454,7 @@ export async function merge({
|
|
|
449
454
|
// chamada extra por PR; falha de rede não afirma nada, só é pulada.
|
|
450
455
|
for (const { story, pr } of plano.fila) {
|
|
451
456
|
const r = prRepoOf(pr, hub);
|
|
452
|
-
const messages = await scmDe(r).listPullRequestCommitMessages({ number: String(pr.number) }).catch(() => null);
|
|
457
|
+
const messages = await (await scmDe(r)).listPullRequestCommitMessages({ number: String(pr.number) }).catch(() => null);
|
|
453
458
|
if (messages === null) continue;
|
|
454
459
|
const { missingStories } = missingTrailers(messages, { stories: [story] });
|
|
455
460
|
if (missingStories.length > 0) {
|
|
@@ -485,19 +490,19 @@ export async function merge({
|
|
|
485
490
|
const ref = prRef(pr, hub);
|
|
486
491
|
const prRepoOpt = sameRepo(r, hub) ? undefined : `${r.owner}/${r.repo}`;
|
|
487
492
|
// Estado fresco: a fila pode ter envelhecido entre o plano e este ponto.
|
|
488
|
-
const atual = await scmDe(r).getPullRequest({ number: String(pr.number) });
|
|
493
|
+
const atual = await (await scmDe(r)).getPullRequest({ number: String(pr.number) });
|
|
489
494
|
if (atual.state === 'merged') {
|
|
490
495
|
p.log.info(`PR ${ref} já estava mergeado — seguindo.`);
|
|
491
496
|
continue;
|
|
492
497
|
}
|
|
493
498
|
if (atual.baseRef !== def) {
|
|
494
499
|
p.log.step(`PR ${ref}: base ${atual.baseRef} → ${def}`);
|
|
495
|
-
await scmDe(r).setPullRequestBase({ number: String(pr.number), base: def });
|
|
500
|
+
await (await scmDe(r)).setPullRequestBase({ number: String(pr.number), base: def });
|
|
496
501
|
}
|
|
497
502
|
try {
|
|
498
503
|
// `merge` e não squash: squash reescreveria o merge-base dos
|
|
499
504
|
// dependentes e o retarget deixaria de ser limpo.
|
|
500
|
-
await scmDe(r).mergePullRequest({ number: String(pr.number), strategy: 'merge' });
|
|
505
|
+
await (await scmDe(r)).mergePullRequest({ number: String(pr.number), strategy: 'merge' });
|
|
501
506
|
} catch (err) {
|
|
502
507
|
// 405 = draft/check pendente/conflito. Parar AQUI preserva a ordem: os
|
|
503
508
|
// dependentes continuam com branch e PR intactos, e rodar de novo retoma.
|
|
@@ -528,7 +533,7 @@ export async function merge({
|
|
|
528
533
|
if (!keepBranches) {
|
|
529
534
|
for (const { repo: r, head } of mergedHeads) {
|
|
530
535
|
if (!head) continue;
|
|
531
|
-
await scmDe(r).deleteBranch({ branch: head }).catch(err =>
|
|
536
|
+
await (await scmDe(r)).deleteBranch({ branch: head }).catch(err =>
|
|
532
537
|
p.log.warn(`Branch ${head} (${r.owner}/${r.repo}) não apagada: ${err.message}`));
|
|
533
538
|
}
|
|
534
539
|
}
|
package/src/commands/mode.mjs
CHANGED
|
@@ -16,12 +16,14 @@ import * as p from '@clack/prompts';
|
|
|
16
16
|
import chalk from 'chalk';
|
|
17
17
|
|
|
18
18
|
import { resolveToken } from '../api/auth.mjs';
|
|
19
|
-
import {
|
|
20
|
-
import { resolveScmLink } from '../ports/index.mjs';
|
|
19
|
+
import { requireScm, resolveScmLink } from '../ports/index.mjs';
|
|
21
20
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Porta de SCM do repositório corrente — só a variável de execução sai daqui.
|
|
23
|
+
* ASSÍNCRONA desde a leva 5 do bloco E.
|
|
24
|
+
*/
|
|
25
|
+
const scmDe = (token, owner, repo, deps = {}) =>
|
|
26
|
+
requireScm({ link: resolveScmLink({ owner, repo }), token, deps });
|
|
25
27
|
import { CONFIG_FILE, WORKFLOW_FILES } from '../config.mjs';
|
|
26
28
|
import { updateConfig } from '../lib/config-file.mjs';
|
|
27
29
|
import {
|
|
@@ -48,16 +50,21 @@ export function unguardedWorkflows(root) {
|
|
|
48
50
|
|
|
49
51
|
// A variável só é legível por quem administra o repo. 403 não é falha: é "não
|
|
50
52
|
// verificável", e quem chama distingue isso de "não existe" (null).
|
|
51
|
-
async function readVariable(token, owner, repo) {
|
|
53
|
+
async function readVariable(token, owner, repo, deps = {}) {
|
|
52
54
|
try {
|
|
53
|
-
|
|
55
|
+
// `await` DUAS vezes, e o de dentro não é enfeite: sem ele a promessa de
|
|
56
|
+
// `getVariable` sai deste `try` sem ser esperada, e a rejeição escapa o
|
|
57
|
+
// `catch` que trata o 403 — o caso que o comentário acima descreve. Foi o que
|
|
58
|
+
// minha primeira conversão para porta assíncrona fez, e o que ninguém pegaria:
|
|
59
|
+
// `mode` não tinha teste de caminho.
|
|
60
|
+
return await (await scmDe(token, owner, repo, deps)).getVariable({ name: EXECUTION_VARIABLE });
|
|
54
61
|
} catch (err) {
|
|
55
62
|
if (err.status === 403 || err.status === 404) return undefined;
|
|
56
63
|
throw err;
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
export async function mode({ target, dryRun = false } = {}) {
|
|
67
|
+
export async function mode({ target, dryRun = false, deps = {} } = {}) {
|
|
61
68
|
p.intro(chalk.bold('spec-wave mode'));
|
|
62
69
|
|
|
63
70
|
const { config, root, configPath } = loadConfig();
|
|
@@ -81,7 +88,7 @@ export async function mode({ target, dryRun = false } = {}) {
|
|
|
81
88
|
if (owner && repo) {
|
|
82
89
|
try {
|
|
83
90
|
token = await resolveToken();
|
|
84
|
-
variavel = await readVariable(token, owner, repo);
|
|
91
|
+
variavel = await readVariable(token, owner, repo, deps);
|
|
85
92
|
} catch (err) {
|
|
86
93
|
p.log.warn(`Não foi possível consultar a variável do repositório: ${err.message}`);
|
|
87
94
|
variavel = undefined;
|
|
@@ -147,12 +154,12 @@ export async function mode({ target, dryRun = false } = {}) {
|
|
|
147
154
|
if (token && owner && repo) {
|
|
148
155
|
try {
|
|
149
156
|
if (esperado === null) {
|
|
150
|
-
const removida = await scmDe(token, owner, repo).deleteVariable({ name: EXECUTION_VARIABLE });
|
|
157
|
+
const removida = await (await scmDe(token, owner, repo, deps)).deleteVariable({ name: EXECUTION_VARIABLE });
|
|
151
158
|
p.log.success(removida
|
|
152
159
|
? `Variável ${EXECUTION_VARIABLE} removida — os workflows voltam a disparar.`
|
|
153
160
|
: `Variável ${EXECUTION_VARIABLE} já não existia.`);
|
|
154
161
|
} else {
|
|
155
|
-
await scmDe(token, owner, repo).setVariable({ name: EXECUTION_VARIABLE, value: esperado });
|
|
162
|
+
await (await scmDe(token, owner, repo, deps)).setVariable({ name: EXECUTION_VARIABLE, value: esperado });
|
|
156
163
|
p.log.success(`Variável ${EXECUTION_VARIABLE}=${esperado} — os jobs passam a ser pulados (0 minutos).`);
|
|
157
164
|
}
|
|
158
165
|
} catch (err) {
|
package/src/commands/move.mjs
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
import * as p from '@clack/prompts';
|
|
14
14
|
import chalk from 'chalk';
|
|
15
15
|
import { resolveToken } from '../api/auth.mjs';
|
|
16
|
-
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
17
16
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
18
17
|
import { openTracker, advanceToStage, resolveStageName } from '../lib/board.mjs';
|
|
19
18
|
import { resolveHubContext } from '../lib/project-root.mjs';
|
|
19
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
20
20
|
import {
|
|
21
21
|
CONFIG_FILE, PROGRESS_TODO, PROGRESS_IN_PROGRESS, PROGRESS_DONE,
|
|
22
22
|
isManualStageType, MANUAL_STAGE_TYPES, isStageInTrack, STAGE_TRACKS,
|
|
@@ -141,7 +141,7 @@ export async function move({ issue: issueArg, stage: stageArg, status: statusArg
|
|
|
141
141
|
|
|
142
142
|
let issue;
|
|
143
143
|
try {
|
|
144
|
-
issue = await (
|
|
144
|
+
issue = await (await requireTracker({ token, owner, repo, deps }))
|
|
145
145
|
.getWorkItem({ ref: { key: String(issueNumber) } });
|
|
146
146
|
} catch (err) {
|
|
147
147
|
p.log.error(`Não foi possível ler a issue #${issueNumber}: ${err.message}`);
|
|
@@ -178,7 +178,7 @@ export async function move({ issue: issueArg, stage: stageArg, status: statusArg
|
|
|
178
178
|
p.log.warn(`#${issueNumber} ${aviso}`);
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
const { tracker, error: projectError } = openTracker({ token, owner, repo, cwd: root || process.cwd(), tracker: deps.tracker });
|
|
181
|
+
const { tracker, error: projectError } = await openTracker({ token, owner, repo, cwd: root || process.cwd(), tracker: deps.tracker });
|
|
182
182
|
if (projectError) {
|
|
183
183
|
p.log.error(`${projectError} — board não atualizado. Rode \`spec-wave init\` (ou \`spec-wave refresh --config\`).`);
|
|
184
184
|
process.exitCode = 1;
|
package/src/commands/order.mjs
CHANGED
|
@@ -24,7 +24,6 @@ import path from 'node:path';
|
|
|
24
24
|
import * as p from '@clack/prompts';
|
|
25
25
|
import chalk from 'chalk';
|
|
26
26
|
import { resolveToken } from '../api/auth.mjs';
|
|
27
|
-
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
28
27
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
29
28
|
import { parseDependencies, orderStories } from '../lib/dependencies.mjs';
|
|
30
29
|
import { loadProjectConfig, selectOpenFeatures } from '../lib/board.mjs';
|
|
@@ -39,6 +38,7 @@ import { loadFeatureStories, loadBoardSnapshot, externalIssueInfo } from '../lib
|
|
|
39
38
|
import { resolveCacheTtl } from '../lib/net-cache.mjs';
|
|
40
39
|
import { pushWithRebase } from '../lib/git-retry.mjs';
|
|
41
40
|
import { CONFIG_FILE, STAGE_ORDER, STAGE_DEVELOPMENT, STAGE_DONE } from '../config.mjs';
|
|
41
|
+
import { requireTracker } from '../ports/index.mjs';
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Rótulo curto de uma Feature para a coluna do mapa (função PURA).
|
|
@@ -333,7 +333,7 @@ export async function order({
|
|
|
333
333
|
// 1. Lê a Feature e valida o tipo (1 chamada — a issue-alvo nunca vem de cache).
|
|
334
334
|
let featureIssue;
|
|
335
335
|
try {
|
|
336
|
-
featureIssue = await (
|
|
336
|
+
featureIssue = await (await requireTracker({ token, owner, repo, deps }))
|
|
337
337
|
.getWorkItem({ ref: { key: String(featureNumber) } });
|
|
338
338
|
} catch (err) {
|
|
339
339
|
emitError(opts, `Não foi possível ler a issue #${featureNumber}: ${err.message}`);
|
|
@@ -530,7 +530,7 @@ function commitSyncedFiles(root, filesRel, featureNumber, exec = execSync) {
|
|
|
530
530
|
}
|
|
531
531
|
|
|
532
532
|
async function syncDependencies({ token, owner, repo, root, opts, featureNumber, deps = {} }) {
|
|
533
|
-
const tracker =
|
|
533
|
+
const tracker = await requireTracker({ token, owner, repo, deps });
|
|
534
534
|
// Alvos: a Feature pedida, ou as Features abertas do board (--milestone filtra).
|
|
535
535
|
let targets = [];
|
|
536
536
|
if (featureNumber) {
|