@spec-wave/cli 1.3.0 → 1.4.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/src/commands/audit.mjs +3 -2
- package/src/commands/code-review.mjs +3 -2
- package/src/commands/decompose.mjs +26 -7
- package/src/commands/generate-bug.mjs +16 -6
- package/src/commands/generate-plan.mjs +21 -11
- package/src/commands/generate-qa-plan.mjs +20 -10
- package/src/commands/generate-spec.mjs +18 -5
- package/src/commands/implement.mjs +91 -47
- package/src/commands/init.mjs +3 -2
- package/src/commands/merge.mjs +14 -6
- package/src/commands/mode.mjs +3 -2
- package/src/commands/order.mjs +29 -19
- package/src/commands/preflight.mjs +3 -2
- package/src/commands/qa-lead.mjs +40 -28
- package/src/commands/qa-run.mjs +68 -52
- package/src/commands/qa.mjs +3 -2
- package/src/commands/repo.mjs +3 -2
- package/src/commands/run.mjs +3 -2
- package/src/commands/uninstall.mjs +3 -2
- package/src/commands/update.mjs +3 -2
- package/src/commands/validate.mjs +3 -2
- package/src/lib/artifact-publish.mjs +3 -2
- package/src/lib/critique.mjs +11 -1
- package/src/lib/doc-source.mjs +3 -2
- package/src/lib/implement-board.mjs +5 -0
- package/src/lib/implement-stream.mjs +87 -0
- package/src/lib/pr-ready.mjs +4 -3
- package/src/lib/story-graph.mjs +9 -2
- package/src/plugin/.claude-plugin/plugin.json +1 -1
- package/src/ports/index.mjs +192 -0
- package/src/ports/tracker.mjs +51 -1
- package/src/ports/types.mjs +29 -0
- package/src/setup/files.mjs +3 -2
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
TRAILER_STORY, TRAILER_TASKS, TRAILER_AGENT,
|
|
11
11
|
} from '../config.mjs';
|
|
12
12
|
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
13
|
-
import { createGithubScm
|
|
13
|
+
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
14
|
+
import { resolveScmLink } from '../ports/index.mjs';
|
|
14
15
|
|
|
15
16
|
// Fábrica local: este arquivo é longo e os helpers recebem (token, owner, repo)
|
|
16
17
|
// separadamente. As operações abaixo são todas de LEITURA e não usam o memo do
|
|
@@ -37,6 +38,7 @@ import { loadArtifact } from '../lib/doc-source.mjs';
|
|
|
37
38
|
import { buildBugContext } from '../lib/bug-context.mjs';
|
|
38
39
|
import { slugify } from '../lib/slugify.mjs';
|
|
39
40
|
import { parseDependencies, orderStories, formatDependencyLine } from '../lib/dependencies.mjs';
|
|
41
|
+
import { STREAM_DIR_ENV, runStreamed, streamFileFor, withStreamJson } from '../lib/implement-stream.mjs';
|
|
40
42
|
import { loadProjectConfig } from '../lib/board.mjs';
|
|
41
43
|
import { planBoardMoves, applyBoardMoves } from '../lib/implement-board.mjs';
|
|
42
44
|
import { markFeaturePrsReady } from '../lib/pr-ready.mjs';
|
|
@@ -66,8 +68,8 @@ const MAX_COMMENT_CHARS = 2000;
|
|
|
66
68
|
// "Feature" e devolve { number, title } — usado para resolver docs/features/<slug>
|
|
67
69
|
// e para as instruções de fim de Story (mover a Feature para Code Review). Limita
|
|
68
70
|
// a profundidade para evitar loops em dados inconsistentes.
|
|
69
|
-
async function resolveFeature(token, owner, repo, startRef) {
|
|
70
|
-
const tracker = trackerDe(token, owner, repo);
|
|
71
|
+
async function resolveFeature(token, owner, repo, startRef, trackerInjetado) {
|
|
72
|
+
const tracker = trackerInjetado ?? trackerDe(token, owner, repo);
|
|
71
73
|
let current = startRef;
|
|
72
74
|
for (let depth = 0; depth < 5 && current; depth++) {
|
|
73
75
|
const parent = await tracker.getParent({ ref: current });
|
|
@@ -90,9 +92,9 @@ async function resolveFeature(token, owner, repo, startRef) {
|
|
|
90
92
|
*
|
|
91
93
|
* Best-effort como a sonda que substitui: nunca lança, nunca bloqueia.
|
|
92
94
|
*/
|
|
93
|
-
async function probeMissingDoc({ token, owner, repo, root, pathRel, doc, issueNumber, fallback }) {
|
|
95
|
+
async function probeMissingDoc({ token, owner, repo, root, pathRel, doc, issueNumber, fallback, deps = {} }) {
|
|
94
96
|
if (issueNumber) {
|
|
95
|
-
const achado = await loadArtifact({ token, owner, repo, root, pathRel, doc, issueNumber })
|
|
97
|
+
const achado = await loadArtifact({ token, owner, repo, root, pathRel, doc, issueNumber, scm: deps.scm ?? null })
|
|
96
98
|
.catch(() => null);
|
|
97
99
|
if (achado?.state === 'pending-pr' || achado?.state === 'branch-only') {
|
|
98
100
|
return missingDocMessage({
|
|
@@ -102,9 +104,9 @@ async function probeMissingDoc({ token, owner, repo, root, pathRel, doc, issueNu
|
|
|
102
104
|
if (achado?.state === 'remote') return missingDocMessage({ pathRel, onRemote: true, fallback });
|
|
103
105
|
if (achado?.state === 'missing') return missingDocMessage({ pathRel, onRemote: false, fallback });
|
|
104
106
|
}
|
|
105
|
-
const scm = token && owner && repo
|
|
106
|
-
? createGithubScm({ link:
|
|
107
|
-
: null;
|
|
107
|
+
const scm = deps.scm ?? (token && owner && repo
|
|
108
|
+
? createGithubScm({ link: resolveScmLink({ owner, repo }), token })
|
|
109
|
+
: null);
|
|
108
110
|
const onRemote = await existsOnRemote({ scm, pathRel });
|
|
109
111
|
return missingDocMessage({ pathRel, onRemote, fallback });
|
|
110
112
|
}
|
|
@@ -377,7 +379,7 @@ export function buildContext({
|
|
|
377
379
|
* @param {{warnOnSkip?:boolean}} [opts]
|
|
378
380
|
* @returns {Promise<Map<number, string|null>>}
|
|
379
381
|
*/
|
|
380
|
-
async function fetchStagesOf(token, owner, repo, items, { warnOnSkip = false } = {}) {
|
|
382
|
+
async function fetchStagesOf(token, owner, repo, items, { warnOnSkip = false, deps = {} } = {}) {
|
|
381
383
|
const stageOf = new Map();
|
|
382
384
|
if (items.length === 0) return stageOf;
|
|
383
385
|
const { project, error: projectError } = loadProjectConfig();
|
|
@@ -389,7 +391,9 @@ async function fetchStagesOf(token, owner, repo, items, { warnOnSkip = false } =
|
|
|
389
391
|
}
|
|
390
392
|
try {
|
|
391
393
|
const { root } = loadConfig();
|
|
392
|
-
const snapshot = await loadBoardSnapshot({
|
|
394
|
+
const snapshot = await loadBoardSnapshot({
|
|
395
|
+
token, owner, repo, project, root, fresh: true, tracker: deps.tracker,
|
|
396
|
+
});
|
|
393
397
|
for (const s of items) {
|
|
394
398
|
stageOf.set(s.number, snapshot.index.get(s.number)?.fields?.Etapa ?? null);
|
|
395
399
|
}
|
|
@@ -639,7 +643,7 @@ function renderCommand(template, vars) {
|
|
|
639
643
|
* existe (o caso do P0, que dispensa o documento), o contexto assume a
|
|
640
644
|
* investigação inteira.
|
|
641
645
|
*/
|
|
642
|
-
async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot }) {
|
|
646
|
+
async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot, deps = {} }) {
|
|
643
647
|
const issueNumber = bug.number;
|
|
644
648
|
const severity = (labelNames(bug).find(n => /^P[0-3]$/.test(n))) || null;
|
|
645
649
|
|
|
@@ -647,7 +651,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
647
651
|
// de um Bug pode ser Feature OU Story — o tipo vem do prefixo do título.
|
|
648
652
|
let parent = null;
|
|
649
653
|
try {
|
|
650
|
-
const p0 = await trackerDe(token, owner, repo)
|
|
654
|
+
const p0 = await (deps.tracker ?? trackerDe(token, owner, repo))
|
|
651
655
|
.getParent({ ref: { key: String(bug.number), id: bug.node_id } });
|
|
652
656
|
if (p0?.ref?.key) {
|
|
653
657
|
parent = {
|
|
@@ -668,6 +672,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
668
672
|
p.log.info(`bug.md encontrado em ${chalk.cyan(fileRel)}.`);
|
|
669
673
|
} else {
|
|
670
674
|
p.log.warn(await probeMissingDoc({
|
|
675
|
+
deps,
|
|
671
676
|
token, owner, repo, root: repoRoot,
|
|
672
677
|
pathRel: fileRel, doc: 'bug', issueNumber: bug.number,
|
|
673
678
|
fallback: 'o contexto assume a investigação inteira.',
|
|
@@ -676,14 +681,14 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
676
681
|
|
|
677
682
|
// Board: Bug → Desenvolvimento (In Progress). Não move a Feature-pai.
|
|
678
683
|
await applyBoardMoves({
|
|
679
|
-
token,
|
|
684
|
+
token, tracker: deps.tracker,
|
|
680
685
|
moves: planBoardMoves('start', { bug: { nodeId: bug.node_id, number: issueNumber } }),
|
|
681
686
|
cwd: repoRoot || process.cwd(),
|
|
682
687
|
dryRun,
|
|
683
688
|
});
|
|
684
689
|
|
|
685
690
|
const comments = [];
|
|
686
|
-
const all = await trackerDe(token, owner, repo).listComments({ ref: { key: String(issueNumber) } }).catch(() => []);
|
|
691
|
+
const all = await (deps.tracker ?? trackerDe(token, owner, repo)).listComments({ ref: { key: String(issueNumber) } }).catch(() => []);
|
|
687
692
|
if (all.length > 0) {
|
|
688
693
|
const items = all.slice(-MAX_COMMENTS_PER_ISSUE).map(c => ({
|
|
689
694
|
...c,
|
|
@@ -703,7 +708,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
703
708
|
|
|
704
709
|
const blockedByWarnings = [];
|
|
705
710
|
try {
|
|
706
|
-
const blocked = await trackerDe(token, owner, repo).listBlockedBy({ ref: { key: String(issueNumber) } }).catch(() => []);
|
|
711
|
+
const blocked = await (deps.tracker ?? trackerDe(token, owner, repo)).listBlockedBy({ ref: { key: String(issueNumber) } }).catch(() => []);
|
|
707
712
|
for (const b of blocked) {
|
|
708
713
|
// `listBlockedBy` devolve `{ ref, title, state }` — nunca `number`. Lido
|
|
709
714
|
// cru, o aviso que vai para o contexto do executor saía "#undefined".
|
|
@@ -724,6 +729,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
724
729
|
});
|
|
725
730
|
|
|
726
731
|
await writeContextAndRunSpecKit({
|
|
732
|
+
deps,
|
|
727
733
|
config,
|
|
728
734
|
issueNumber,
|
|
729
735
|
type: 'Bug',
|
|
@@ -739,7 +745,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
739
745
|
: `Bug #${issueNumber} corrigido — abra o PR com \`Fixes #${issueNumber}\`.`,
|
|
740
746
|
onSuccess: async () => {
|
|
741
747
|
await applyBoardMoves({
|
|
742
|
-
token,
|
|
748
|
+
token, tracker: deps.tracker,
|
|
743
749
|
moves: planBoardMoves('success', { bug: { nodeId: bug.node_id, number: issueNumber } }),
|
|
744
750
|
cwd: repoRoot || process.cwd(),
|
|
745
751
|
dryRun,
|
|
@@ -748,7 +754,7 @@ async function implementBug({ token, owner, repo, config, bug, dryRun, repoRoot
|
|
|
748
754
|
});
|
|
749
755
|
}
|
|
750
756
|
|
|
751
|
-
async function implementFeature({ token, owner, repo, config, feature, featureDirOpt, dryRun, repoRoot, refresh = false }) {
|
|
757
|
+
async function implementFeature({ token, owner, repo, config, feature, featureDirOpt, dryRun, repoRoot, refresh = false, deps = {} }) {
|
|
752
758
|
const ttlSec = resolveCacheTtl(config);
|
|
753
759
|
const currentBranch = currentGitBranch(repoRoot);
|
|
754
760
|
const mode = deliveryMode({ branch: currentBranch });
|
|
@@ -762,6 +768,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
762
768
|
let carga;
|
|
763
769
|
try {
|
|
764
770
|
carga = await loadFeatureStories({
|
|
771
|
+
tracker: deps.tracker,
|
|
765
772
|
token, owner, repo, root: repoRoot,
|
|
766
773
|
feature: { number: itemNumber(feature), nodeId: feature.node_id, title: feature.title },
|
|
767
774
|
refresh, ttlSec,
|
|
@@ -784,7 +791,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
784
791
|
for (const w of carga.warnings) p.log.warn(w);
|
|
785
792
|
|
|
786
793
|
// F1-board. Feature → Desenvolvimento (In Progress) já no início.
|
|
787
|
-
await applyBoardMoves({ token, dryRun, moves: planBoardMoves('start', {
|
|
794
|
+
await applyBoardMoves({ token, dryRun, tracker: deps.tracker, moves: planBoardMoves('start', {
|
|
788
795
|
feature: { nodeId: feature.node_id, number: itemNumber(feature) },
|
|
789
796
|
}) });
|
|
790
797
|
|
|
@@ -797,7 +804,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
797
804
|
const codeRepos = codeReposForItems(config, { labels: feature.labels || [], children: enriched }).repos;
|
|
798
805
|
|
|
799
806
|
// F3. Etapa de cada Story no board (best-effort — sem board, nada é pulado).
|
|
800
|
-
const stageOf = await fetchStagesOf(token, owner, repo, enriched, { warnOnSkip: true });
|
|
807
|
+
const stageOf = await fetchStagesOf(token, owner, repo, enriched, { warnOnSkip: true, deps });
|
|
801
808
|
|
|
802
809
|
// F4. Planejamento: pendentes em ordem topológica, puladas, ciclos.
|
|
803
810
|
const { pending, skipped, cycle } = planFeatureImplementation(
|
|
@@ -824,7 +831,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
824
831
|
// Feature. Sem isso, uma Feature que ficou para trás (executor que concluiu
|
|
825
832
|
// sem mover o card, run interrompido) não tinha como ser destravada —
|
|
826
833
|
// reexecutar o implement caía aqui e retornava.
|
|
827
|
-
await applyBoardMoves({ token, dryRun, moves: planBoardMoves('success', {
|
|
834
|
+
await applyBoardMoves({ token, dryRun, tracker: deps.tracker, moves: planBoardMoves('success', {
|
|
828
835
|
feature: { nodeId: feature.node_id, number: itemNumber(feature) },
|
|
829
836
|
}) });
|
|
830
837
|
// Mesmo destravamento do lado dos PRs: a Feature está pronta para review,
|
|
@@ -834,6 +841,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
834
841
|
feature: { nodeId: feature.node_id, number: itemNumber(feature) },
|
|
835
842
|
stories: enriched,
|
|
836
843
|
linkMode: resolveLinkMode(config),
|
|
844
|
+
scmDe: deps.scmDe,
|
|
837
845
|
});
|
|
838
846
|
p.outro(`Todas as ${stories.length} story(ies) da Feature #${itemNumber(feature)} já estão implementadas — nada a fazer.`);
|
|
839
847
|
return;
|
|
@@ -845,6 +853,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
845
853
|
const noTasks = [];
|
|
846
854
|
for (const s of pending) {
|
|
847
855
|
const { subs: storySubs } = await cachedSubIssues({
|
|
856
|
+
tracker: deps.tracker,
|
|
848
857
|
token, owner, repo, root: repoRoot, parent: { number: s.number, nodeId: s.nodeId }, refresh, ttlSec,
|
|
849
858
|
}).catch(() => ({ subs: [] }));
|
|
850
859
|
s.tasks = storySubs
|
|
@@ -870,6 +879,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
870
879
|
} else {
|
|
871
880
|
const specRel = `docs/features/${slugify(feature.title)}/spec.md`;
|
|
872
881
|
p.log.warn(await probeMissingDoc({
|
|
882
|
+
deps,
|
|
873
883
|
token, owner, repo, root: repoRoot,
|
|
874
884
|
pathRel: specRel, doc: 'spec', issueNumber: itemNumber(feature),
|
|
875
885
|
fallback: 'seguindo só com as Stories.',
|
|
@@ -882,7 +892,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
882
892
|
try {
|
|
883
893
|
const internal = new Set(stories.map(s => s.number));
|
|
884
894
|
const featureDeps = new Set(parseDependencies(feature.body));
|
|
885
|
-
const featureBlocked = await trackerDe(token, owner, repo).listBlockedBy({ ref: { key: String(itemNumber(feature)) } }).catch(() => []);
|
|
895
|
+
const featureBlocked = await (deps.tracker ?? trackerDe(token, owner, repo)).listBlockedBy({ ref: { key: String(itemNumber(feature)) } }).catch(() => []);
|
|
886
896
|
for (const n of itemNumbers(featureBlocked)) featureDeps.add(n);
|
|
887
897
|
const check = [
|
|
888
898
|
{ kind: 'Feature', number: itemNumber(feature), deps: featureDeps },
|
|
@@ -891,7 +901,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
891
901
|
for (const c of check) {
|
|
892
902
|
for (const depNumber of [...c.deps].sort((a, b) => a - b)) {
|
|
893
903
|
if (internal.has(depNumber)) continue;
|
|
894
|
-
const dep = await trackerDe(token, owner, repo)
|
|
904
|
+
const dep = await (deps.tracker ?? trackerDe(token, owner, repo))
|
|
895
905
|
.getWorkItem({ ref: { key: String(depNumber) } })
|
|
896
906
|
.then(w => w && comoSubIssue(w))
|
|
897
907
|
.catch(() => null);
|
|
@@ -912,7 +922,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
912
922
|
...pending.map(s => ({ number: s.number, kind: 'Story' })),
|
|
913
923
|
];
|
|
914
924
|
for (const src of commentSources) {
|
|
915
|
-
const all = await trackerDe(token, owner, repo).listComments({ ref: { key: String(src.number) } }).catch(() => []);
|
|
925
|
+
const all = await (deps.tracker ?? trackerDe(token, owner, repo)).listComments({ ref: { key: String(src.number) } }).catch(() => []);
|
|
916
926
|
if (all.length === 0) continue;
|
|
917
927
|
const items = all.slice(-MAX_COMMENTS_PER_ISSUE).map(c => ({
|
|
918
928
|
...c,
|
|
@@ -945,6 +955,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
945
955
|
hub: { owner, repo },
|
|
946
956
|
});
|
|
947
957
|
await writeContextAndRunSpecKit({
|
|
958
|
+
deps,
|
|
948
959
|
config,
|
|
949
960
|
repoSlugs: slugsForItem({ labels: feature.labels || [], children: pending }),
|
|
950
961
|
issueNumber: itemNumber(feature),
|
|
@@ -967,7 +978,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
967
978
|
// Execução única para todas as pendentes: no sucesso, Tasks → Done e
|
|
968
979
|
// Stories → Code Review.
|
|
969
980
|
for (const s of pending) {
|
|
970
|
-
await applyBoardMoves({ token, moves: planBoardMoves('success', {
|
|
981
|
+
await applyBoardMoves({ token, tracker: deps.tracker, moves: planBoardMoves('success', {
|
|
971
982
|
story: { nodeId: s.nodeId, number: s.number },
|
|
972
983
|
tasks: s.tasks || [],
|
|
973
984
|
}) });
|
|
@@ -982,7 +993,7 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
982
993
|
// do PR como plano B. Sob o dev-agent, que trabalha num branch único e
|
|
983
994
|
// não abre PR, nenhum dos dois acontecia: as 6 Stories da feature #18
|
|
984
995
|
// foram para Code Review e a Feature ficou em Desenvolvimento.
|
|
985
|
-
await applyBoardMoves({ token, moves: planBoardMoves('success', {
|
|
996
|
+
await applyBoardMoves({ token, tracker: deps.tracker, moves: planBoardMoves('success', {
|
|
986
997
|
feature: { nodeId: feature.node_id, number: itemNumber(feature) },
|
|
987
998
|
}) });
|
|
988
999
|
// A Feature avançou de Etapa; os PRs precisam contar a mesma história.
|
|
@@ -999,8 +1010,18 @@ async function implementFeature({ token, owner, repo, config, feature, featureDi
|
|
|
999
1010
|
});
|
|
1000
1011
|
}
|
|
1001
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* @param {object} [params]
|
|
1015
|
+
* @param {object} [params.deps] seam de teste — `tracker`, `scm` e `exec`.
|
|
1016
|
+
*
|
|
1017
|
+
* `trackerDe` é const de TOPO DE MÓDULO, chamada de cinco funções. Em vez de
|
|
1018
|
+
* levar `deps` às cinco, a PORTA viaja nos mesmos objetos que já carregam
|
|
1019
|
+
* token/owner/repo — mesma técnica do `qa-lead`, onde o `bootstrap` passou a
|
|
1020
|
+
* devolvê-la.
|
|
1021
|
+
*/
|
|
1002
1022
|
export async function implement({
|
|
1003
1023
|
issue: issueArg, featureDir: featureDirOpt, dryRun, refresh = false, verifyCommits = false,
|
|
1024
|
+
deps = {},
|
|
1004
1025
|
}) {
|
|
1005
1026
|
const issueNumber = parseInt(String(issueArg).replace('#', ''), 10);
|
|
1006
1027
|
if (!Number.isInteger(issueNumber)) {
|
|
@@ -1048,7 +1069,7 @@ export async function implement({
|
|
|
1048
1069
|
// 2. Lê a issue alvo.
|
|
1049
1070
|
let issue;
|
|
1050
1071
|
try {
|
|
1051
|
-
issue = await trackerDe(token, owner, repo)
|
|
1072
|
+
issue = await (deps.tracker ?? trackerDe(token, owner, repo))
|
|
1052
1073
|
.getWorkItem({ ref: { key: String(issueNumber) } })
|
|
1053
1074
|
.then(w => w && comoSubIssue(w));
|
|
1054
1075
|
} catch (err) {
|
|
@@ -1061,7 +1082,7 @@ export async function implement({
|
|
|
1061
1082
|
const type = detectIssueType(issue);
|
|
1062
1083
|
let tasks;
|
|
1063
1084
|
if (type === 'Story') {
|
|
1064
|
-
const subs = (await trackerDe(token, owner, repo).listChildren({ ref: issue.ref })).map(comoSubIssue);
|
|
1085
|
+
const subs = (await (deps.tracker ?? trackerDe(token, owner, repo)).listChildren({ ref: issue.ref })).map(comoSubIssue);
|
|
1065
1086
|
tasks = subs.filter(s => detectIssueType({ title: s.title, labels: s.labels }) === 'Task');
|
|
1066
1087
|
if (tasks.length === 0) {
|
|
1067
1088
|
p.log.error(`Story #${issueNumber} não tem Tasks (sub-issues) para implementar.`);
|
|
@@ -1074,12 +1095,12 @@ export async function implement({
|
|
|
1074
1095
|
p.log.info(`Task única #${issueNumber}.`);
|
|
1075
1096
|
} else if (type === 'Feature') {
|
|
1076
1097
|
// Modo Feature: Stories pendentes em ordem de dependência, contexto único.
|
|
1077
|
-
await implementFeature({ token, owner, repo, config, feature: issue, featureDirOpt, dryRun, repoRoot, refresh });
|
|
1098
|
+
await implementFeature({ token, owner, repo, config, feature: issue, featureDirOpt, dryRun, repoRoot, refresh, deps });
|
|
1078
1099
|
return;
|
|
1079
1100
|
} else if (type === 'Bug') {
|
|
1080
1101
|
// Modo Bug: sem tasks e sem spec/plan — o trabalho é investigar antes de
|
|
1081
1102
|
// corrigir, e o contexto impõe essa ordem.
|
|
1082
|
-
await implementBug({ token, owner, repo, config, bug: issue, dryRun, repoRoot });
|
|
1103
|
+
await implementBug({ token, owner, repo, config, bug: issue, dryRun, repoRoot, deps });
|
|
1083
1104
|
return;
|
|
1084
1105
|
} else {
|
|
1085
1106
|
p.log.error(
|
|
@@ -1091,7 +1112,7 @@ export async function implement({
|
|
|
1091
1112
|
|
|
1092
1113
|
// 4. Resolve a Feature (pai na cadeia) — para spec.md/plan.md e para as
|
|
1093
1114
|
// instruções de fim de Story (avançar a Etapa para Code Review).
|
|
1094
|
-
const feature = await resolveFeature(token, owner, repo, issue.ref);
|
|
1115
|
+
const feature = await resolveFeature(token, owner, repo, issue.ref, deps.tracker);
|
|
1095
1116
|
let featureDir = featureDirOpt;
|
|
1096
1117
|
if (!featureDir && feature?.title) {
|
|
1097
1118
|
// Ancorado na RAIZ do repo: o config é encontrado subindo na árvore, e os
|
|
@@ -1107,6 +1128,7 @@ export async function implement({
|
|
|
1107
1128
|
: featureDir;
|
|
1108
1129
|
p.log.warn(feature?.title
|
|
1109
1130
|
? await probeMissingDoc({
|
|
1131
|
+
deps,
|
|
1110
1132
|
token, owner, repo, root: repoRoot,
|
|
1111
1133
|
pathRel: specRel, doc: 'spec', issueNumber: feature?.number,
|
|
1112
1134
|
fallback: 'seguindo só com as tasks.',
|
|
@@ -1119,7 +1141,7 @@ export async function implement({
|
|
|
1119
1141
|
// 4a-board. Board determinístico: Feature/Story → Desenvolvimento (In
|
|
1120
1142
|
// Progress) já no início — a UI mostra o desenvolvimento em andamento sem
|
|
1121
1143
|
// depender de o LLM mover cards. Best-effort: falha vira warn.
|
|
1122
|
-
await applyBoardMoves({ token, dryRun, moves: planBoardMoves('start', {
|
|
1144
|
+
await applyBoardMoves({ token, dryRun, tracker: deps.tracker, moves: planBoardMoves('start', {
|
|
1123
1145
|
feature: feature ? { nodeId: feature.nodeId, number: itemNumber(feature) } : null,
|
|
1124
1146
|
story: type === 'Story' ? { nodeId: issue.node_id, number: itemNumber(issue) } : null,
|
|
1125
1147
|
tasks: tasks.map(t => ({ nodeId: t.nodeId, number: t.number })),
|
|
@@ -1131,7 +1153,7 @@ export async function implement({
|
|
|
1131
1153
|
// verificar antes de mover a Feature.
|
|
1132
1154
|
let siblingStories = [];
|
|
1133
1155
|
if (type === 'Story' && feature?.nodeId) {
|
|
1134
|
-
const featureSubs = (await trackerDe(token, owner, repo)
|
|
1156
|
+
const featureSubs = (await (deps.tracker ?? trackerDe(token, owner, repo))
|
|
1135
1157
|
.listChildren({ ref: { key: String(itemNumber(feature)), id: feature.nodeId } })
|
|
1136
1158
|
.catch(() => [])).map(comoSubIssue);
|
|
1137
1159
|
siblingStories = featureSubs
|
|
@@ -1150,7 +1172,7 @@ export async function implement({
|
|
|
1150
1172
|
}
|
|
1151
1173
|
commentSources.push({ number: itemNumber(issue), kind: type });
|
|
1152
1174
|
for (const src of commentSources) {
|
|
1153
|
-
const all = await trackerDe(token, owner, repo).listComments({ ref: { key: String(src.number) } }).catch(() => []);
|
|
1175
|
+
const all = await (deps.tracker ?? trackerDe(token, owner, repo)).listComments({ ref: { key: String(src.number) } }).catch(() => []);
|
|
1154
1176
|
if (all.length === 0) continue;
|
|
1155
1177
|
const items = all.slice(-MAX_COMMENTS_PER_ISSUE).map(c => ({
|
|
1156
1178
|
...c,
|
|
@@ -1168,7 +1190,7 @@ export async function implement({
|
|
|
1168
1190
|
try {
|
|
1169
1191
|
let sinceIso = issue.createdAt || null;
|
|
1170
1192
|
if (feature?.number) {
|
|
1171
|
-
const featureIssue = await trackerDe(token, owner, repo)
|
|
1193
|
+
const featureIssue = await (deps.tracker ?? trackerDe(token, owner, repo))
|
|
1172
1194
|
.getWorkItem({ ref: { key: String(itemNumber(feature)) } })
|
|
1173
1195
|
.then(w => w && comoSubIssue(w))
|
|
1174
1196
|
.catch(() => null);
|
|
@@ -1186,10 +1208,10 @@ export async function implement({
|
|
|
1186
1208
|
const blockedByWarnings = [];
|
|
1187
1209
|
try {
|
|
1188
1210
|
const depNumbers = new Set(parseDependencies(issue.body));
|
|
1189
|
-
const blocked = await trackerDe(token, owner, repo).listBlockedBy({ ref: { key: String(itemNumber(issue)) } }).catch(() => []);
|
|
1211
|
+
const blocked = await (deps.tracker ?? trackerDe(token, owner, repo)).listBlockedBy({ ref: { key: String(itemNumber(issue)) } }).catch(() => []);
|
|
1190
1212
|
for (const n of itemNumbers(blocked)) depNumbers.add(n);
|
|
1191
1213
|
for (const depNumber of [...depNumbers].sort((a, b) => a - b)) {
|
|
1192
|
-
const dep = await trackerDe(token, owner, repo)
|
|
1214
|
+
const dep = await (deps.tracker ?? trackerDe(token, owner, repo))
|
|
1193
1215
|
.getWorkItem({ ref: { key: String(depNumber) } })
|
|
1194
1216
|
.then(w => w && comoSubIssue(w))
|
|
1195
1217
|
.catch(() => null);
|
|
@@ -1214,6 +1236,7 @@ export async function implement({
|
|
|
1214
1236
|
hub: { owner, repo },
|
|
1215
1237
|
});
|
|
1216
1238
|
await writeContextAndRunSpecKit({
|
|
1239
|
+
deps,
|
|
1217
1240
|
config, issueNumber, type, title: issue.title, specPlan, context, dryRun,
|
|
1218
1241
|
mode, repoRoot, expectedBranch: currentBranch,
|
|
1219
1242
|
verifyCommits,
|
|
@@ -1228,7 +1251,7 @@ export async function implement({
|
|
|
1228
1251
|
: `${chalk.green('✓')} Implementação acionada para ${type} #${issueNumber}.\n` +
|
|
1229
1252
|
' Próximo: revise as mudanças e abra o PR — o board já foi atualizado.',
|
|
1230
1253
|
onSuccess: async () => {
|
|
1231
|
-
await applyBoardMoves({ token, moves: planBoardMoves('success', {
|
|
1254
|
+
await applyBoardMoves({ token, tracker: deps.tracker, moves: planBoardMoves('success', {
|
|
1232
1255
|
story: type === 'Story' ? { nodeId: issue.node_id, number: itemNumber(issue) } : null,
|
|
1233
1256
|
tasks: tasks.map(t => ({ nodeId: t.nodeId, number: t.number })),
|
|
1234
1257
|
}) });
|
|
@@ -1247,10 +1270,10 @@ export async function implement({
|
|
|
1247
1270
|
// Sem irmãs, esta era a única Story: a Feature avança direto (nada a
|
|
1248
1271
|
// consultar). Com irmãs, todas precisam já estar em Code Review+.
|
|
1249
1272
|
if (siblingStories.length > 0) {
|
|
1250
|
-
const stageOf = await fetchStagesOf(token, owner, repo, siblingStories, {});
|
|
1273
|
+
const stageOf = await fetchStagesOf(token, owner, repo, siblingStories, { deps });
|
|
1251
1274
|
if (!featureCanAdvance(siblingStories, stageOf)) return;
|
|
1252
1275
|
}
|
|
1253
|
-
await applyBoardMoves({ token, dryRun, moves: planBoardMoves('success', {
|
|
1276
|
+
await applyBoardMoves({ token, dryRun, tracker: deps.tracker, moves: planBoardMoves('success', {
|
|
1254
1277
|
feature: { nodeId: feature.nodeId, number: itemNumber(feature) },
|
|
1255
1278
|
}) });
|
|
1256
1279
|
// Chegou aqui = era a última Story pendente. É ESTE o momento que o
|
|
@@ -1275,7 +1298,7 @@ export async function implement({
|
|
|
1275
1298
|
async function writeContextAndRunSpecKit({
|
|
1276
1299
|
config, issueNumber, type, title, specPlan, context, dryRun, outroSuccess, onSuccess,
|
|
1277
1300
|
mode = 'pr-stack', repoRoot = null, expectedBranch = null,
|
|
1278
|
-
verifyCommits = false, expectedTrailers = null, repoSlugs = [],
|
|
1301
|
+
verifyCommits = false, expectedTrailers = null, repoSlugs = [], deps = {},
|
|
1279
1302
|
}) {
|
|
1280
1303
|
mkdirSync(WORK_DIR, { recursive: true });
|
|
1281
1304
|
const tasksFile = path.join(WORK_DIR, `implement-${issueNumber}.md`);
|
|
@@ -1339,15 +1362,36 @@ async function writeContextAndRunSpecKit({
|
|
|
1339
1362
|
return;
|
|
1340
1363
|
}
|
|
1341
1364
|
|
|
1342
|
-
|
|
1365
|
+
// Sob o spec-wave-agent com a tela ao vivo (SPEC_WAVE_STREAM_DIR), a saída
|
|
1366
|
+
// do agente interno vai para um arquivo por story e o stdout recebe só o
|
|
1367
|
+
// resumo (lib/implement-stream.mjs). Sem a env, stdio herdado como sempre.
|
|
1368
|
+
const streamDir = process.env[STREAM_DIR_ENV];
|
|
1369
|
+
const command = streamDir
|
|
1370
|
+
? withStreamJson(renderCommand(template, vars))
|
|
1371
|
+
: renderCommand(template, vars);
|
|
1343
1372
|
|
|
1344
1373
|
p.log.step(`Executando: ${chalk.dim(command)}`);
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1374
|
+
if (streamDir) {
|
|
1375
|
+
let code;
|
|
1376
|
+
try {
|
|
1377
|
+
code = await runStreamed(command, { streamFile: streamFileFor(streamDir, issueNumber) });
|
|
1378
|
+
} catch (err) {
|
|
1379
|
+
code = 1;
|
|
1380
|
+
p.log.error(`spec-kit implement falhou ao iniciar: ${err.message}`);
|
|
1381
|
+
}
|
|
1382
|
+
if (code !== 0) {
|
|
1383
|
+
p.log.error(`spec-kit implement falhou (exit ${code}).`);
|
|
1384
|
+
process.exitCode = 1;
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
} else {
|
|
1388
|
+
try {
|
|
1389
|
+
(deps.exec ?? execSync)(command, { stdio: 'inherit' });
|
|
1390
|
+
} catch (err) {
|
|
1391
|
+
p.log.error(`spec-kit implement falhou: ${err.message}`);
|
|
1392
|
+
process.exitCode = 1;
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1351
1395
|
}
|
|
1352
1396
|
|
|
1353
1397
|
// Guarda barata contra o sintoma do item 1 do rfc/plano-hardening-agentes-
|
package/src/commands/init.mjs
CHANGED
|
@@ -8,7 +8,8 @@ import { setupProject } from '../setup/project.mjs';
|
|
|
8
8
|
import { setupLabels } from '../setup/labels.mjs';
|
|
9
9
|
import { setupFiles } from '../setup/files.mjs';
|
|
10
10
|
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
11
|
-
import { createGithubScm
|
|
11
|
+
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
12
|
+
import { resolveScmLink } from '../ports/index.mjs';
|
|
12
13
|
import {
|
|
13
14
|
CONFIG_FILE, AI_PROVIDERS, getProvider, DEFAULT_PROVIDER, PORTAL_URL, WORKFLOW_FILES, CODE_WORKFLOW_FILES,
|
|
14
15
|
ISSUE_TEMPLATE_FILES, STATUS_OPTIONS, ALL_LABELS, HUB_DISPATCH_SECRET,
|
|
@@ -188,7 +189,7 @@ export async function init(options) {
|
|
|
188
189
|
const localConfigPath = path.join(process.cwd(), CONFIG_FILE);
|
|
189
190
|
const raw = existsSync(localConfigPath)
|
|
190
191
|
? readFileSync(localConfigPath, 'utf-8')
|
|
191
|
-
: await createGithubScm({ link:
|
|
192
|
+
: await createGithubScm({ link: resolveScmLink({ owner, repo }), token })
|
|
192
193
|
.readFile({ path: CONFIG_FILE });
|
|
193
194
|
if (raw) {
|
|
194
195
|
const existing = JSON.parse(raw);
|
package/src/commands/merge.mjs
CHANGED
|
@@ -21,7 +21,8 @@ import chalk from 'chalk';
|
|
|
21
21
|
|
|
22
22
|
import { resolveToken } from '../api/auth.mjs';
|
|
23
23
|
import { createGithubTracker } from '../plugins/tracker-github-projects/index.mjs';
|
|
24
|
-
import { createGithubScm
|
|
24
|
+
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
25
|
+
import { resolveScmLink } from '../ports/index.mjs';
|
|
25
26
|
import { missingTrailers } from '../lib/commit-trailers.mjs';
|
|
26
27
|
import { detectIssueType } from '../lib/issue-type.mjs';
|
|
27
28
|
import { orderStories } from '../lib/dependencies.mjs';
|
|
@@ -243,7 +244,7 @@ function comoPrLegado(pr) {
|
|
|
243
244
|
function criarScmDe(token, hub) {
|
|
244
245
|
const cache = new Map();
|
|
245
246
|
return (r) => {
|
|
246
|
-
const link =
|
|
247
|
+
const link = resolveScmLink({
|
|
247
248
|
owner: r.owner, repo: r.repo,
|
|
248
249
|
role: r.owner === hub.owner && r.repo === hub.repo ? 'hub' : 'code',
|
|
249
250
|
});
|
|
@@ -252,9 +253,16 @@ function criarScmDe(token, hub) {
|
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
255
|
|
|
256
|
+
/**
|
|
257
|
+
* @param {object} [params]
|
|
258
|
+
* @param {object} [params.deps] seam de teste — `tracker` e `scmDe`. Em
|
|
259
|
+
* multi-repo o `scmDe` é uma FÁBRICA por repositório, não uma porta só: o
|
|
260
|
+
* comando fala com N repos de código mais o hub, e uma porta única esconderia
|
|
261
|
+
* exatamente o defeito que importa aqui — PR aberto no repositório errado.
|
|
262
|
+
*/
|
|
255
263
|
export async function merge({
|
|
256
264
|
feature: featureArg, yes = false, dryRun = false, keepBranches = false,
|
|
257
|
-
remote = false, refresh = false,
|
|
265
|
+
remote = false, refresh = false, deps = {},
|
|
258
266
|
} = {}) {
|
|
259
267
|
const { config: fileConfig, root: repoRoot } = loadConfig();
|
|
260
268
|
const ttlSec = resolveCacheTtl(fileConfig);
|
|
@@ -294,13 +302,13 @@ export async function merge({
|
|
|
294
302
|
const s = p.spinner();
|
|
295
303
|
s.start('Montando o plano de merge...');
|
|
296
304
|
|
|
297
|
-
const scmDe = criarScmDe(token, { owner, repo });
|
|
305
|
+
const scmDe = deps.scmDe ?? criarScmDe(token, { owner, repo });
|
|
298
306
|
const hubScm = scmDe({ owner, repo });
|
|
299
307
|
|
|
300
308
|
let featureIssue;
|
|
301
309
|
let defaultBranch;
|
|
302
310
|
try {
|
|
303
|
-
featureIssue = await createGithubTracker({ token, owner, repo })
|
|
311
|
+
featureIssue = await (deps.tracker ?? createGithubTracker({ token, owner, repo }))
|
|
304
312
|
.getWorkItem({ ref: { key: String(featureNumber) } });
|
|
305
313
|
defaultBranch = await scmDe({ owner, repo }).defaultBranch();
|
|
306
314
|
} catch (err) {
|
|
@@ -327,7 +335,7 @@ export async function merge({
|
|
|
327
335
|
let carga;
|
|
328
336
|
try {
|
|
329
337
|
carga = await loadFeatureStories({
|
|
330
|
-
token, owner, repo, root: repoRoot,
|
|
338
|
+
token, owner, repo, root: repoRoot, tracker: deps.tracker,
|
|
331
339
|
// `ref.id`: sem ele, `loadFeatureStories` chama listChildren sem node id
|
|
332
340
|
// e o plugin paga um getIssue a mais para reidratar o que já estava aqui.
|
|
333
341
|
feature: { number: featureNumber, nodeId: featureIssue.ref?.id, title: featureIssue.title },
|
package/src/commands/mode.mjs
CHANGED
|
@@ -16,11 +16,12 @@ import * as p from '@clack/prompts';
|
|
|
16
16
|
import chalk from 'chalk';
|
|
17
17
|
|
|
18
18
|
import { resolveToken } from '../api/auth.mjs';
|
|
19
|
-
import { createGithubScm
|
|
19
|
+
import { createGithubScm } from '../plugins/scm-github/index.mjs';
|
|
20
|
+
import { resolveScmLink } from '../ports/index.mjs';
|
|
20
21
|
|
|
21
22
|
/** Porta de SCM do repositório corrente — só a variável de execução sai daqui. */
|
|
22
23
|
const scmDe = (token, owner, repo) =>
|
|
23
|
-
createGithubScm({ link:
|
|
24
|
+
createGithubScm({ link: resolveScmLink({ owner, repo }), token });
|
|
24
25
|
import { CONFIG_FILE, WORKFLOW_FILES } from '../config.mjs';
|
|
25
26
|
import { updateConfig } from '../lib/config-file.mjs';
|
|
26
27
|
import {
|