@payconductor/houndsman 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +156 -3
- package/assets/houndsman.png +0 -0
- package/assets/logo-legacy.png +0 -0
- package/assets/logo.png +0 -0
- package/package.json +64 -5
- package/src/cli/index.ts +290 -0
- package/src/core/assets.ts +28 -0
- package/src/core/brief.ts +185 -0
- package/src/core/commands/context.ts +39 -0
- package/src/core/commands/findings.ts +390 -0
- package/src/core/commands/review.ts +50 -0
- package/src/core/commands/scaffold.ts +393 -0
- package/src/core/commands/setup.ts +75 -0
- package/src/core/commands/test.ts +20 -0
- package/src/core/commands/update.ts +30 -0
- package/src/core/commands/watchdog.ts +105 -0
- package/src/core/config-loader.ts +87 -0
- package/src/core/config.ts +101 -0
- package/src/core/diff-source.ts +140 -0
- package/src/core/doc-discoverer.ts +33 -0
- package/src/core/file-classifier.ts +295 -0
- package/src/core/finding-anchor.ts +147 -0
- package/src/core/findings-state.ts +538 -0
- package/src/core/jev/index.ts +12 -0
- package/src/core/jev/jev-candidates.ts +105 -0
- package/src/core/jev/jev-client.ts +160 -0
- package/src/core/jev/jev-detector.ts +205 -0
- package/src/core/jev/jev-questions.ts +92 -0
- package/src/core/jev/jev-types.ts +91 -0
- package/src/core/orchestrator.ts +596 -0
- package/src/core/paths.ts +33 -0
- package/src/core/pr-context.ts +271 -0
- package/src/core/registry-check.ts +160 -0
- package/src/core/report-builder.ts +461 -0
- package/src/core/types.ts +147 -0
- package/src/core/watchdog-registry.ts +43 -0
- package/src/index.ts +132 -0
- package/src/server/artifacts.ts +66 -0
- package/src/server/client/App.tsx +158 -0
- package/src/server/client/ArtifactsPanel.tsx +48 -0
- package/src/server/client/Filters.tsx +83 -0
- package/src/server/client/FindingCard.tsx +122 -0
- package/src/server/client/FindingsList.tsx +54 -0
- package/src/server/client/RunList.tsx +43 -0
- package/src/server/client/SummaryBar.tsx +21 -0
- package/src/server/client/api.ts +37 -0
- package/src/server/client/constants.ts +63 -0
- package/src/server/client/index.tsx +12 -0
- package/src/server/client/types.ts +48 -0
- package/src/server/client-build.ts +47 -0
- package/src/server/index.ts +365 -0
- package/src/skill/AUDIT-PROTOCOL.md +96 -0
- package/src/skill/OUTPUT-FORMAT.md +70 -0
- package/src/skill/README.md +124 -0
- package/src/skill/SETUP.md +101 -0
- package/src/skill/example-review.md +58 -0
- package/src/skill/houndsman-update.md +251 -0
- package/src/skill/houndsman.md +316 -0
- package/src/tests/findings-anchor.test.ts +120 -0
- package/src/tests/findings-commands.test.ts +226 -0
- package/src/tests/findings-state.test.ts +274 -0
- package/src/tests/fixtures/fake-project.ts +64 -0
- package/src/tests/review-scripts.test.ts +1150 -0
- package/src/tests/server.test.ts +212 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Houndsman contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,156 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# houndsman
|
|
2
|
+
|
|
3
|
+
Orquestrador de revisão de Pull Requests. Classifica o diff, despacha **watchdogs**
|
|
4
|
+
especializados por domínio (um subagente por watchdog) e consolida os achados em um
|
|
5
|
+
relatório único.
|
|
6
|
+
|
|
7
|
+
> Review de PR no piloto automático: alguém aprova no "LGTM" sem ler, um `catch {}` engole
|
|
8
|
+
> o erro e ninguém nota. Sexta às 18h a produção cobra a conta — e aí todo mundo lembra
|
|
9
|
+
> daquela linha.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
**Terminologia:** **houndsman** = orquestrador/treinador (CLI + motor) · **watchdog** = cada
|
|
14
|
+
agente especialista por domínio que audita o diff · **review/revisão** = o processo ·
|
|
15
|
+
**Jev** = pré-análise opcional. O vocabulário completo (brief, findings, manifest, budget,
|
|
16
|
+
overflow, churn, candidato…) está em [`docs/GLOSSARY.md`](docs/GLOSSARY.md).
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Como iniciar
|
|
21
|
+
|
|
22
|
+
Você monta o **seu time de cães de caça** (os watchdogs), cada um farejando um domínio
|
|
23
|
+
diferente das PRs. O motor só coordena a caçada — as regras são problema seu.
|
|
24
|
+
|
|
25
|
+
### 1. Pré-requisitos
|
|
26
|
+
|
|
27
|
+
- **Bun** — runtime obrigatório.
|
|
28
|
+
- **git** — o diff usa `git diff <base>...<head>`.
|
|
29
|
+
- Opcionais: **`gh`** (contexto da PR) e **`TYPESAFE_API_KEY`** (pré-análise Jev). A revisão
|
|
30
|
+
funciona normalmente sem eles; o `houndsman doctor` valida a credencial Jev quando presente.
|
|
31
|
+
|
|
32
|
+
### 2. Instale o CLI (global)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bun add -g @payconductor/houndsman
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 3. Configure o projeto (uma vez)
|
|
39
|
+
|
|
40
|
+
Na raiz do projeto:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bun run houndsman setup
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Cria a camada `.houndsman/`, que é **autocontida** (não instala nada no seu projeto):
|
|
47
|
+
|
|
48
|
+
| Caminho | Dono | O que é |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `houndsman.config.ts` | você | Configuração do projeto (um objeto de dados) |
|
|
51
|
+
| `.houndsman/watchdogs/` | você | Suas regras — começa com **1 watchdog de exemplo** |
|
|
52
|
+
| `.houndsman/exclusions.ts` | você | Arquivos que nunca entram na revisão |
|
|
53
|
+
| `.houndsman/doc-mappings.ts` | você | path → documentação de contexto |
|
|
54
|
+
| `.houndsman/core/**` | auto | Tipos + docs do skill (sincronizados por `houndsman update`) |
|
|
55
|
+
|
|
56
|
+
> **Não existe "modo completo".** O `setup` já cria a camada inicial com um watchdog de
|
|
57
|
+
> exemplo — troque o exemplo pelas regras reais do seu projeto (ou use `/houndsman-update`).
|
|
58
|
+
|
|
59
|
+
### 4. Escreva suas regras
|
|
60
|
+
|
|
61
|
+
Edite `.houndsman/watchdogs/` — veja [Escrevendo boas regras](docs/AVANCADO.md#escrevendo-boas-regras).
|
|
62
|
+
|
|
63
|
+
### 5. Valide
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
bun run houndsman doctor
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 6. Rode a primeira revisão
|
|
70
|
+
|
|
71
|
+
No seu harness (Claude Code / agents), invoque o skill:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
/houndsman
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
O skill orquestra tudo e grava o relatório em `.houndsman/.runs/<branch-slug>/review.md`.
|
|
78
|
+
Não precisa rodar nenhum script à mão.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## O fluxo de trabalho
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
/houndsman
|
|
86
|
+
├─ Passo 0 contexto da PR (gh, opcional)
|
|
87
|
+
├─ Passo 1 classifica o diff → briefs por watchdog
|
|
88
|
+
├─ Passo 2 N subagentes revisam em paralelo
|
|
89
|
+
├─ Passo 3 consolida em review.md + state.json
|
|
90
|
+
└─ Passo 4 triagem (UI local ou agente)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- Revisão normal: só `/houndsman` (a branch é detectada; base default `main`).
|
|
94
|
+
- Revisar outra branch: `/houndsman feature/minha-branch`.
|
|
95
|
+
- Manual (sem skill): `houndsman context` → `houndsman --base main` → *(subagentes)* →
|
|
96
|
+
`houndsman --finalize`.
|
|
97
|
+
- CI: `houndsman --finalize --fail-on-blocking` (exit 1 se houver bloqueantes).
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Triando os findings (opcional)
|
|
102
|
+
|
|
103
|
+
Depois do `--finalize`, cada finding tem um `id` curto e um `fingerprint` de **conteúdo**
|
|
104
|
+
no `.houndsman/.runs/<branch-slug>/state.json`. Você decide o que fazer com cada um — pela
|
|
105
|
+
**UI local** ou pelo **agente** (auto-fix) — sem abrir o JSON à mão:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
bun run houndsman server --open # UI: triar, comentar, marcar feito, ler artefatos
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- **decision:** `pending` · `execute` · `ignore` (+ comentário).
|
|
112
|
+
- **execState:** `pending` · `in_progress` · `done` · `stale`.
|
|
113
|
+
|
|
114
|
+
**Auto-fix pelo agente** — as linhas mudam depois do fix, e o motor reancora por conteúdo:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
bun run houndsman findings list --decision execute --json
|
|
118
|
+
bun run houndsman findings sync
|
|
119
|
+
bun run houndsman findings done <id>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
> A identidade do finding é o **conteúdo** (fingerprint), não a linha: itens deslocados
|
|
123
|
+
> pelo fix não se perdem. O estado é local e mora em `.runs/<slug>/state.json` (gitignored).
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Mantendo a configuração
|
|
128
|
+
|
|
129
|
+
- **Alterar regras** → use o skill **`/houndsman-update`**. Ele prova no código que o padrão
|
|
130
|
+
existe (evidência) antes de editar e roda as validações.
|
|
131
|
+
- **Atualizou a lib?** Sincronize os arquivos auto-gerados sem tocar nas suas regras:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
bun run houndsman update
|
|
135
|
+
bun run houndsman doctor
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
O `update` reescreve **só** `.houndsman/core/**` e `.houndsman/.gitignore`. Seus arquivos
|
|
139
|
+
(`watchdogs/`, `exclusions.ts`, `doc-mappings.ts`, `houndsman.config.ts`) nunca são tocados.
|
|
140
|
+
- **Recomeçar a camada do zero** → `houndsman setup --force` (sobrescreve só os arquivos do
|
|
141
|
+
usuário; sem `--force` o `setup` é idempotente).
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Documentação
|
|
146
|
+
|
|
147
|
+
- `docs/AVANCADO.md` — como funciona por dentro (diagrama do fluxo e onde o Jev entra),
|
|
148
|
+
referência de comandos e boas práticas para escrever regras.
|
|
149
|
+
- `docs/GLOSSARY.md` — glossário do vocabulário de domínio (brief, findings, manifest,
|
|
150
|
+
budget, overflow, churn, candidato, Jev…): o que cada termo significa **neste** projeto.
|
|
151
|
+
- `docs/CONTRIBUTING.md` — arquitetura, fluxos internos, princípios e desenvolvimento da
|
|
152
|
+
lib (para quem vai contribuir).
|
|
153
|
+
|
|
154
|
+
- `src/skill/SETUP.md` — referência de configuração passo a passo.
|
|
155
|
+
- `src/skill/houndsman.md` — orquestração do skill `/houndsman`.
|
|
156
|
+
- `src/skill/houndsman-update.md` — manutenção das regras dos watchdogs.
|
|
Binary file
|
|
Binary file
|
package/assets/logo.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@payconductor/houndsman",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Orquestrador de revisão de Pull Requests: classifica o diff, despacha watchdogs especializados por domínio e consolida o relatório.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"bin": {
|
|
8
|
+
"houndsman": "./src/cli/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"assets",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/payconductor-ai/houndsman.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/payconductor-ai/houndsman/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/payconductor-ai/houndsman#readme",
|
|
27
|
+
"author": "PayConductor",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"pull-request",
|
|
30
|
+
"code-review",
|
|
31
|
+
"cli",
|
|
32
|
+
"bun",
|
|
33
|
+
"ai-agents",
|
|
34
|
+
"orchestrator"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"bun": ">=1.1.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"houndsman": "bun run ./src/cli/index.ts",
|
|
44
|
+
"build": "bun build ./src/cli/index.ts --target bun --outdir dist",
|
|
45
|
+
"test": "bun test ./src/tests",
|
|
46
|
+
"typecheck": "tsc -b",
|
|
47
|
+
"lint": "biome check .",
|
|
48
|
+
"format": "biome format --write .",
|
|
49
|
+
"ci": "biome ci . && tsc -b",
|
|
50
|
+
"ci:check": "biome check",
|
|
51
|
+
"ci:check:fix": "biome check --fix",
|
|
52
|
+
"ci:fix": "bun run ci:check:fix && bun run ci:format:fix",
|
|
53
|
+
"ci:format": "biome format",
|
|
54
|
+
"ci:format:fix": "biome format --fix"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"axios": "^1.12.2",
|
|
58
|
+
"preact": "^11.0.1"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@biomejs/biome": "2.2.4",
|
|
62
|
+
"bun-types": "^1.3.14",
|
|
63
|
+
"typescript": "^7.0.2"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Entrypoint único do `houndsman` — `houndsman [comando]`.
|
|
5
|
+
*
|
|
6
|
+
* Carrega a configuração do projeto (`HoundsmanConfig`) em runtime (a partir do
|
|
7
|
+
* cwd) e orquestra funções/classes de `core/`. Não importa nenhum caminho do
|
|
8
|
+
* projeto consumidor estaticamente.
|
|
9
|
+
*
|
|
10
|
+
* Comandos:
|
|
11
|
+
* (default) Passo 1 — preparar (classificação + briefs + manifesto)
|
|
12
|
+
* --finalize Passo 3 — consolidar os findings em review.md
|
|
13
|
+
* context Passo 0 — coletar o contexto da PR via `gh`
|
|
14
|
+
* findings <sub> Triagem dos findings (list/set/done/sync/...)
|
|
15
|
+
* server Sobe a UI local de triagem (Bun.serve)
|
|
16
|
+
* setup Cria a configuração inicial do projeto (config + skills)
|
|
17
|
+
* update Sincroniza os arquivos auto-gerados (.houndsman/core)
|
|
18
|
+
* doctor Valida a configuração, o ambiente e a credencial Jev (anti-drift)
|
|
19
|
+
* test Roda a suíte de testes da lib
|
|
20
|
+
* watchdog <id> Contexto de um watchdog (`--rules`, `--json`)
|
|
21
|
+
*
|
|
22
|
+
* Flags: `--base <b>` · `--head <ref>` · `--branch <b>` · `--dir <d>` ·
|
|
23
|
+
* `--config <path>` · `--clean` · `--no-jev` · `--fail-on-blocking`.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { runContextCommand } from "../core/commands/context";
|
|
27
|
+
import { runFindingsCommand } from "../core/commands/findings";
|
|
28
|
+
import { parseReviewArgs } from "../core/commands/review";
|
|
29
|
+
import { runSetupCommand } from "../core/commands/setup";
|
|
30
|
+
import { runLibTests } from "../core/commands/test";
|
|
31
|
+
import { runUpdateCommand } from "../core/commands/update";
|
|
32
|
+
import { renderWatchdogContext } from "../core/commands/watchdog";
|
|
33
|
+
import { type HoundsmanConfig, resolveArtifactDir } from "../core/config";
|
|
34
|
+
import { loadConfig } from "../core/config-loader";
|
|
35
|
+
import { JevClient } from "../core/jev";
|
|
36
|
+
import { finalize, prepare, resolveBranch } from "../core/orchestrator";
|
|
37
|
+
import { relFromRoot } from "../core/paths";
|
|
38
|
+
import { checkRegistry } from "../core/registry-check";
|
|
39
|
+
import { startServer } from "../server";
|
|
40
|
+
|
|
41
|
+
const HELP = `Uso: houndsman [comando] [flags]
|
|
42
|
+
|
|
43
|
+
Comandos:
|
|
44
|
+
(nenhum) Prepara a revisão (classification + briefs + manifesto)
|
|
45
|
+
--finalize Consolida os findings em review.md
|
|
46
|
+
context Coleta o contexto da PR via gh (Passo 0)
|
|
47
|
+
findings <sub> Triagem dos findings (list · show · set · done · reset · sync · summary · path)
|
|
48
|
+
server Sobe a UI local de triagem (--port, --host, --open)
|
|
49
|
+
setup Cria a configuração inicial do projeto (config + skills)
|
|
50
|
+
update Sincroniza os arquivos auto-gerados (.houndsman/core)
|
|
51
|
+
doctor Valida a configuração, o ambiente e a credencial Jev
|
|
52
|
+
test Roda a suíte de testes da lib
|
|
53
|
+
watchdog <id> Contexto de um watchdog (--rules, --json)
|
|
54
|
+
|
|
55
|
+
Flags:
|
|
56
|
+
--config <path> Caminho do houndsman.config.* (default: detecta no cwd)
|
|
57
|
+
--base <branch> Base do diff (default: main)
|
|
58
|
+
--head <ref> Head do diff (default: HEAD)
|
|
59
|
+
--branch <nome> Branch alvo (default: detecta do git)
|
|
60
|
+
--dir <dir> Diretório dos artefatos
|
|
61
|
+
--clean Descarta findings anteriores
|
|
62
|
+
--no-jev Desativa a pré-análise Jev
|
|
63
|
+
--fail-on-blocking Exit 1 se houver bloqueantes (com --finalize)
|
|
64
|
+
|
|
65
|
+
Flags de findings:
|
|
66
|
+
--decision <d> pending | execute | ignore
|
|
67
|
+
--exec <e> pending | in_progress | done | stale
|
|
68
|
+
--comment <text> Comentário/instrução adicional
|
|
69
|
+
--watchdog <id> Filtra por watchdog (list)
|
|
70
|
+
--severity <s> Filtra por severidade (list)
|
|
71
|
+
--file <text> Filtra por trecho do caminho (list)
|
|
72
|
+
--all Inclui findings ausentes do último relatório
|
|
73
|
+
--json Saída JSON
|
|
74
|
+
--limit <n> Limita o nº de itens (list)`;
|
|
75
|
+
|
|
76
|
+
function readFlag(args: string[], flag: string): string | undefined {
|
|
77
|
+
const index = args.indexOf(flag);
|
|
78
|
+
return index >= 0 ? args[index + 1] : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Passo 0 — contexto da PR via `gh`. */
|
|
82
|
+
function runContext(config: HoundsmanConfig, args: string[]): void {
|
|
83
|
+
const { paths, context } = runContextCommand(config, {
|
|
84
|
+
branch: readFlag(args, "--branch"),
|
|
85
|
+
dir: readFlag(args, "--dir"),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (context.available) {
|
|
89
|
+
const src = context.source;
|
|
90
|
+
const label = [src?.number ? `#${src.number}` : "", src?.title ?? ""]
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.join(" ");
|
|
93
|
+
console.log(
|
|
94
|
+
`[houndsman] PR ${label} (${src?.head} → ${src?.base}), ${context.stats?.files ?? 0} arquivo(s).`,
|
|
95
|
+
);
|
|
96
|
+
console.log(`[houndsman] contexto: ${relFromRoot(paths.context)}`);
|
|
97
|
+
console.log(`[houndsman] brief: ${relFromRoot(paths.brief)}`);
|
|
98
|
+
console.log(
|
|
99
|
+
`[houndsman] próximo passo: subagente resume em ${relFromRoot(paths.summary)}`,
|
|
100
|
+
);
|
|
101
|
+
} else {
|
|
102
|
+
console.log(
|
|
103
|
+
`[houndsman] contexto indisponível (${context.reason}): ${context.detail}`,
|
|
104
|
+
);
|
|
105
|
+
console.log(`[houndsman] marcador: ${relFromRoot(paths.context)}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Valida a configuração do projeto e o ambiente. */
|
|
110
|
+
async function runDoctor(config: HoundsmanConfig): Promise<void> {
|
|
111
|
+
console.log("→ Validando configuração do projeto...");
|
|
112
|
+
const { problems, warnings, jevQuestions } = checkRegistry(config);
|
|
113
|
+
|
|
114
|
+
if (problems.length > 0) {
|
|
115
|
+
console.error("\n❌ Problemas na configuração de revisão:\n");
|
|
116
|
+
for (const problem of problems) console.error(` - ${problem}`);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
console.log(
|
|
120
|
+
` ✅ ${config.watchdogIds.length} watchdogs, ${jevQuestions} pergunta(s) Jev.`,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (warnings.length > 0) {
|
|
124
|
+
console.log(`\n⚠️ ${warnings.length} aviso(s) (não bloqueantes):`);
|
|
125
|
+
for (const warning of warnings) console.log(` - ${warning}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
console.log("\n→ Ambiente:");
|
|
129
|
+
console.log(` ${Bun.which("git") ? "✅" : "❌"} git`);
|
|
130
|
+
console.log(` ${Bun.which("gh") ? "✅" : "⚠️ "} gh (opcional — contexto da PR)`);
|
|
131
|
+
await reportJevCredential();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Reporta o estado da credencial Jev: presença e validade (chamada mínima).
|
|
136
|
+
* Fail-open — nunca altera o exit code (`doctor` é diagnóstico).
|
|
137
|
+
*/
|
|
138
|
+
async function reportJevCredential(): Promise<void> {
|
|
139
|
+
const client = new JevClient();
|
|
140
|
+
if (!client.isConfigured()) {
|
|
141
|
+
console.log(" ⚠️ TYPESAFE_API_KEY (opcional — pré-análise Jev)");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const check = await client.validateCredential();
|
|
145
|
+
if (check.ok) {
|
|
146
|
+
console.log(` ✅ Jev: credencial válida (modelo ${check.model}).`);
|
|
147
|
+
} else if (check.kind === "invalid") {
|
|
148
|
+
console.log(` ❌ Jev: credencial inválida — ${check.detail}`);
|
|
149
|
+
} else {
|
|
150
|
+
console.log(` ⚠️ Jev: não foi possível validar — ${check.detail}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Contexto de um watchdog. */
|
|
155
|
+
function runWatchdog(config: HoundsmanConfig, args: string[]): void {
|
|
156
|
+
const id = args.find((arg) => !arg.startsWith("-"));
|
|
157
|
+
|
|
158
|
+
if (!id || renderWatchdogContext(config, id) === null) {
|
|
159
|
+
console.error(
|
|
160
|
+
id
|
|
161
|
+
? `Watchdog '${id}' não existe.`
|
|
162
|
+
: "Informe o id do watchdog: houndsman watchdog <id>",
|
|
163
|
+
);
|
|
164
|
+
console.error(`Ids válidos: ${config.watchdogIds.join(", ")}`);
|
|
165
|
+
process.exit(1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
console.log(
|
|
169
|
+
renderWatchdogContext(config, id, {
|
|
170
|
+
withRules: args.includes("--rules"),
|
|
171
|
+
json: args.includes("--json"),
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Subcomando `findings` — triagem dos findings (list/show/set/done/reset/
|
|
178
|
+
* sync/summary/path). Deixa o agente interagir com o estado sem abrir o JSON.
|
|
179
|
+
*/
|
|
180
|
+
function runFindings(config: HoundsmanConfig, args: string[]): void {
|
|
181
|
+
const result = runFindingsCommand(config, args);
|
|
182
|
+
if (result.exitCode !== 0) {
|
|
183
|
+
console.error(result.output);
|
|
184
|
+
process.exit(result.exitCode);
|
|
185
|
+
}
|
|
186
|
+
console.log(result.output);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Abre a URL no navegador padrão (best-effort, por plataforma). */
|
|
190
|
+
function openBrowser(url: string): void {
|
|
191
|
+
try {
|
|
192
|
+
const command =
|
|
193
|
+
process.platform === "win32"
|
|
194
|
+
? ["cmd", "/c", "start", "", url]
|
|
195
|
+
: process.platform === "darwin"
|
|
196
|
+
? ["open", url]
|
|
197
|
+
: ["xdg-open", url];
|
|
198
|
+
Bun.spawn(command, { stdout: "ignore", stderr: "ignore" });
|
|
199
|
+
} catch {
|
|
200
|
+
// best-effort — se não abrir, o usuário copia a URL.
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Subcomando `server` — sobe a UI local de triagem. */
|
|
205
|
+
function runServer(config: HoundsmanConfig, args: string[]): void {
|
|
206
|
+
const port = Number(readFlag(args, "--port")) || 7331;
|
|
207
|
+
const host = readFlag(args, "--host") ?? "127.0.0.1";
|
|
208
|
+
const { url } = startServer({ config, port, host });
|
|
209
|
+
console.log(`[houndsman] servidor em ${url}`);
|
|
210
|
+
console.log("[houndsman] Ctrl+C para encerrar.");
|
|
211
|
+
if (args.includes("--open")) openBrowser(url);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Passo 1/3 — preparar ou finalizar. */
|
|
215
|
+
async function runReview(config: HoundsmanConfig, args: string[]): Promise<void> {
|
|
216
|
+
const opts = parseReviewArgs(args, resolveArtifactDir(config));
|
|
217
|
+
const branch = resolveBranch(opts);
|
|
218
|
+
|
|
219
|
+
if (opts.finalize) {
|
|
220
|
+
const result = finalize(opts, branch, config);
|
|
221
|
+
if (opts.failOnBlocking && result.blockers > 0) process.exit(1);
|
|
222
|
+
} else {
|
|
223
|
+
await prepare(opts, branch, config);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Executa um subcomando. `--config` sobrepõe a descoberta automática.
|
|
229
|
+
* Comandos que não precisam de projeto (`test`, `setup`) são tratados antes do load.
|
|
230
|
+
*/
|
|
231
|
+
export async function main(): Promise<void> {
|
|
232
|
+
const argv = process.argv.slice(2);
|
|
233
|
+
const first = argv[0];
|
|
234
|
+
const command = first && !first.startsWith("-") ? first : undefined;
|
|
235
|
+
const rest = command ? argv.slice(1) : argv;
|
|
236
|
+
|
|
237
|
+
if (command === "test") {
|
|
238
|
+
process.exit(runLibTests());
|
|
239
|
+
}
|
|
240
|
+
if (command === "setup") {
|
|
241
|
+
await runSetupCommand({ cwd: process.cwd(), args: rest });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (command === "update") {
|
|
245
|
+
await runUpdateCommand({ cwd: process.cwd(), args: rest });
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (command === "help") {
|
|
250
|
+
console.info(HELP);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const { config } = await loadConfig({
|
|
255
|
+
configPath: readFlag(argv, "--config"),
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
switch (command) {
|
|
259
|
+
case "context":
|
|
260
|
+
runContext(config, rest);
|
|
261
|
+
return;
|
|
262
|
+
case "doctor":
|
|
263
|
+
case "check":
|
|
264
|
+
await runDoctor(config);
|
|
265
|
+
return;
|
|
266
|
+
case "watchdog":
|
|
267
|
+
runWatchdog(config, rest);
|
|
268
|
+
return;
|
|
269
|
+
case "findings":
|
|
270
|
+
runFindings(config, rest);
|
|
271
|
+
return;
|
|
272
|
+
case "server":
|
|
273
|
+
runServer(config, rest);
|
|
274
|
+
return;
|
|
275
|
+
case undefined:
|
|
276
|
+
await runReview(config, rest);
|
|
277
|
+
return;
|
|
278
|
+
default:
|
|
279
|
+
console.error(`Subcomando desconhecido: '${command}'.\n`);
|
|
280
|
+
console.error(HELP);
|
|
281
|
+
process.exit(1);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (import.meta.main) {
|
|
286
|
+
await main().catch((error) => {
|
|
287
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
288
|
+
process.exit(1);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolução dos assets embarcados no pacote (`src/skill/`) — biblioteca.
|
|
3
|
+
*
|
|
4
|
+
* Usados para **gerar** a camada de projeto (`houndsman setup`/`update`), não
|
|
5
|
+
* para resolver caminhos em runtime. Derivados da localização do módulo — não
|
|
6
|
+
* do cwd.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
|
|
11
|
+
/** Diretório de assets markdown embarcados no pacote. */
|
|
12
|
+
export const SKILL_DIR = join(import.meta.dir, "..", "skill");
|
|
13
|
+
|
|
14
|
+
/** Diretório de assets de mídia do pacote (root `assets/` — logo etc.). */
|
|
15
|
+
export const MEDIA_DIR = join(import.meta.dir, "..", "..", "assets");
|
|
16
|
+
|
|
17
|
+
/** Nome do arquivo de schema de output dos watchdogs. */
|
|
18
|
+
export const OUTPUT_FORMAT_FILE = "OUTPUT-FORMAT.md";
|
|
19
|
+
|
|
20
|
+
/** Caminho absoluto de um asset embarcado em `src/skill/`. */
|
|
21
|
+
export function assetPath(fileName: string): string {
|
|
22
|
+
return join(SKILL_DIR, fileName);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Caminho absoluto de um asset de mídia em `assets/` (ex.: a logo). */
|
|
26
|
+
export function mediaPath(fileName: string): string {
|
|
27
|
+
return join(MEDIA_DIR, fileName);
|
|
28
|
+
}
|