@payconductor/houndsman 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +14 -13
  2. package/package.json +1 -1
  3. package/src/cli/commands/doctor-command.ts +22 -0
  4. package/src/cli/commands/hunt-command.ts +440 -29
  5. package/src/cli/commands/review-command.ts +20 -2
  6. package/src/cli/help.ts +16 -8
  7. package/src/cli/index.ts +15 -2
  8. package/src/cli/progress.ts +45 -0
  9. package/src/core/ai/ai-client.ts +3 -7
  10. package/src/core/ai/ai-sdk-model-provider.ts +43 -24
  11. package/src/core/ai/features/brief-enricher.ts +0 -1
  12. package/src/core/ai/features/classifier.ts +0 -1
  13. package/src/core/ai/features/context-summarizer.ts +0 -1
  14. package/src/core/ai/features/pre-analyzer.ts +0 -1
  15. package/src/core/ai/features/technical-summarizer.ts +0 -1
  16. package/src/core/ai/features/verifier.ts +0 -1
  17. package/src/core/ai/index.ts +6 -4
  18. package/src/core/ai/prompts/pre-analysis.ts +3 -2
  19. package/src/core/ai/schemas.ts +1 -23
  20. package/src/core/ai/types.ts +4 -15
  21. package/src/core/ai/usage-budget.ts +1 -1
  22. package/src/core/ast/diff.ts +37 -2
  23. package/src/core/ast/service.ts +1 -1
  24. package/src/core/brief.ts +54 -5
  25. package/src/core/changed-scope.ts +207 -0
  26. package/src/core/commands/scaffold.ts +12 -18
  27. package/src/core/config.ts +30 -15
  28. package/src/core/defaults.ts +14 -5
  29. package/src/core/engine/review-scope.ts +131 -17
  30. package/src/core/engine/review-session.ts +7 -3
  31. package/src/core/engine/review-workspace.ts +14 -0
  32. package/src/core/env.ts +14 -0
  33. package/src/core/hunt/hunt-runner.ts +328 -0
  34. package/src/core/hunt/index.ts +59 -0
  35. package/src/core/hunt/maki-install.ts +331 -0
  36. package/src/core/hunt/maki-model.ts +101 -0
  37. package/src/core/hunt/maki-prompt.ts +71 -0
  38. package/src/core/hunt/maki-release.ts +104 -0
  39. package/src/core/hunt/maki-runner.ts +276 -0
  40. package/src/core/hunt/pool.ts +30 -0
  41. package/src/core/jev/jev-detector.ts +7 -2
  42. package/src/core/logging/index.ts +3 -1
  43. package/src/core/logging/logger.ts +22 -3
  44. package/src/core/logging/progress.ts +282 -0
  45. package/src/core/orchestrator.ts +173 -59
  46. package/src/core/project-config.ts +34 -24
  47. package/src/core/registry-check.ts +2 -12
  48. package/src/core/rule-text.ts +3 -55
  49. package/src/core/services/git-repository.ts +8 -0
  50. package/src/core/storage/types.ts +1 -1
  51. package/src/core/types.ts +3 -14
  52. package/src/index.ts +74 -3
  53. package/src/server/client/utils/constants.ts +3 -6
  54. package/src/server/client/utils/types.ts +0 -1
  55. package/src/skill/OUTPUT-FORMAT.md +5 -0
  56. package/src/skill/README.md +14 -1
  57. package/src/skill/SETUP.md +22 -2
  58. package/src/skill/SKILL.md +4 -0
  59. package/src/skill/fix.md +1 -1
  60. package/src/skill/hunt.md +38 -6
  61. package/src/tests/__snapshots__/baseline.test.ts.snap +69 -32
  62. package/src/tests/ai-core.test.ts +38 -1
  63. package/src/tests/changed-scope.test.ts +197 -0
  64. package/src/tests/cli.test.ts +1 -0
  65. package/src/tests/fallback.test.ts +1 -96
  66. package/src/tests/fixtures/fake-model-provider.ts +0 -1
  67. package/src/tests/hunt-cli.test.ts +185 -0
  68. package/src/tests/hunt-install.test.ts +153 -0
  69. package/src/tests/hunt-maki.test.ts +467 -0
  70. package/src/tests/progress.test.ts +117 -0
  71. package/src/tests/review-scope.test.ts +95 -0
  72. package/src/tests/worktree.test.ts +1 -3
  73. package/src/harness/README.md +0 -15
  74. package/src/harness/agent/agent-context.ts +0 -33
  75. package/src/harness/agent/agent-errors.ts +0 -30
  76. package/src/harness/agent/agent-factory.ts +0 -46
  77. package/src/harness/agent/agent-reporter.ts +0 -34
  78. package/src/harness/agent/agent-result.ts +0 -16
  79. package/src/harness/agent/agent-runner.ts +0 -32
  80. package/src/harness/agent/agent-scheduler.ts +0 -37
  81. package/src/harness/agent/review-agent.ts +0 -401
  82. package/src/harness/config/harness-config.ts +0 -89
  83. package/src/harness/hunt/hunt-harness.ts +0 -83
  84. package/src/harness/hunt/hunt-options.ts +0 -92
  85. package/src/harness/hunt/hunt-result.ts +0 -17
  86. package/src/harness/hunt/hunt-session.ts +0 -359
  87. package/src/harness/hunt/review-planner.ts +0 -98
  88. package/src/harness/index.ts +0 -36
  89. package/src/harness/investigation/agent-state.ts +0 -134
  90. package/src/harness/investigation/evidence-verifier.ts +0 -129
  91. package/src/harness/investigation/evidence.ts +0 -110
  92. package/src/harness/investigation/finding-critic.ts +0 -96
  93. package/src/harness/investigation/investigation-planner.ts +0 -118
  94. package/src/harness/investigation/investigation-task.ts +0 -10
  95. package/src/harness/investigation/review-journal.ts +0 -87
  96. package/src/harness/investigation/rule-analyzer.ts +0 -178
  97. package/src/harness/investigation/rule-signals.ts +0 -110
  98. package/src/harness/prompts/agent-schemas.ts +0 -57
  99. package/src/harness/prompts/reviewer-prompt-builder.ts +0 -101
  100. package/src/harness/prompts/states/conclude-prompt.ts +0 -16
  101. package/src/harness/prompts/states/investigate-prompt.ts +0 -37
  102. package/src/harness/prompts/states/orient-prompt.ts +0 -15
  103. package/src/harness/prompts/states/verify-prompt.ts +0 -22
  104. package/src/harness/tools/agent-tool.ts +0 -102
  105. package/src/harness/tools/builtin/changed-symbols-tool.ts +0 -48
  106. package/src/harness/tools/builtin/doc-context-tool.ts +0 -74
  107. package/src/harness/tools/builtin/file-outline-tool.ts +0 -66
  108. package/src/harness/tools/builtin/find-references-tool.ts +0 -66
  109. package/src/harness/tools/builtin/find-symbol-tool.ts +0 -91
  110. package/src/harness/tools/builtin/helpers.ts +0 -115
  111. package/src/harness/tools/builtin/impact-tool.ts +0 -48
  112. package/src/harness/tools/builtin/imports-exports-tool.ts +0 -53
  113. package/src/harness/tools/builtin/index.ts +0 -59
  114. package/src/harness/tools/builtin/list-files-tool.ts +0 -85
  115. package/src/harness/tools/builtin/pr-context-tool.ts +0 -41
  116. package/src/harness/tools/builtin/read-file-range-tool.ts +0 -73
  117. package/src/harness/tools/builtin/rule-signals-tool.ts +0 -36
  118. package/src/harness/tools/builtin/search-code-tool.ts +0 -65
  119. package/src/harness/tools/builtin/symbol-context-tool.ts +0 -106
  120. package/src/harness/tools/builtin/tests-for-symbol-tool.ts +0 -61
  121. package/src/harness/tools/path-guard.ts +0 -90
  122. package/src/harness/tools/result-limiter.ts +0 -49
  123. package/src/harness/tools/secret-redactor.ts +0 -54
  124. package/src/harness/tools/tool-cache.ts +0 -50
  125. package/src/harness/tools/tool-call-budget.ts +0 -60
  126. package/src/harness/tools/tool-context.ts +0 -5
  127. package/src/harness/tools/tool-middleware.ts +0 -105
  128. package/src/harness/tools/tool-policy.ts +0 -51
  129. package/src/harness/tools/tool-registry.ts +0 -112
  130. package/src/harness/tools/tool-result.ts +0 -15
  131. package/src/harness/tools/toolbox.ts +0 -36
  132. package/src/harness/validation/finding-validator.ts +0 -119
  133. package/src/tests/fixtures/fake-agent-tools.ts +0 -69
  134. package/src/tests/fixtures/fake-investigation.ts +0 -64
  135. package/src/tests/harness-agent.test.ts +0 -141
  136. package/src/tests/harness-investigation.test.ts +0 -206
  137. package/src/tests/harness-tools.test.ts +0 -148
  138. package/src/tests/hunt-command.test.ts +0 -212
  139. package/src/tests/rule-analyzer.test.ts +0 -61
  140. package/src/tests/tool-contracts.test.ts +0 -82
@@ -1,212 +0,0 @@
1
- /**
2
- * `hunt` — parser de flags, dry-run e fluxo completo com provider fake.
3
- */
4
-
5
- import { afterAll, describe, expect, test } from "bun:test";
6
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
7
- import { tmpdir } from "node:os";
8
- import { join } from "node:path";
9
- import { defineHoundsmanConfig } from "../core/config";
10
- import { HoundsmanEngine } from "../core/engine/houndsman-engine";
11
- import { SilentLogger } from "../core/logging";
12
- import { defineWatchdog } from "../core/types";
13
- import { HuntHarness } from "../harness/hunt/hunt-harness";
14
- import { parseHuntArgs } from "../harness/hunt/hunt-options";
15
- import { FakeModelProvider } from "./fixtures/fake-model-provider";
16
-
17
- const RULE = "Nunca usar `any`.";
18
-
19
- const configBase = defineHoundsmanConfig({
20
- projectName: "Hunt",
21
- watchdogs: {
22
- alpha: defineWatchdog({
23
- id: "alpha",
24
- name: "Alpha",
25
- description: "Watchdog do hunt.",
26
- scope: "src/alpha/**",
27
- classify: [{ value: "^src/alpha/" }],
28
- rules: [{ severity: "blocking", text: RULE }],
29
- contextFiles: [],
30
- }),
31
- },
32
- exclusions: [],
33
- docMappings: [],
34
- });
35
-
36
- describe("parseHuntArgs", () => {
37
- test("flags e defaults", () => {
38
- const options = parseHuntArgs([
39
- "--base",
40
- "origin/main",
41
- "--head",
42
- "abc",
43
- "--watchdog",
44
- "alpha",
45
- "--full",
46
- "--no-ast",
47
- "--resume",
48
- "--allow-partial",
49
- "--dry-run",
50
- "--fail-on-blocking",
51
- "--max-calls",
52
- "7",
53
- "--concurrency",
54
- "3",
55
- "--model",
56
- "m",
57
- ]);
58
- expect(options.base).toBe("origin/main");
59
- expect(options.head).toBe("abc");
60
- expect(options.watchdog).toBe("alpha");
61
- expect(options.full).toBe(true);
62
- expect(options.noAst).toBe(true);
63
- expect(options.noJev).toBe(true);
64
- expect(options.resume).toBe(true);
65
- expect(options.allowPartial).toBe(true);
66
- expect(options.dryRun).toBe(true);
67
- expect(options.failOnBlocking).toBe(true);
68
- expect(options.maxCalls).toBe(7);
69
- expect(options.concurrency).toBe(3);
70
- expect(options.model).toBe("m");
71
- });
72
- });
73
-
74
- // ---------------------------------------------------------------------------
75
- // Repo git temporário
76
- // ---------------------------------------------------------------------------
77
-
78
- const cwd = mkdtempSync(join(tmpdir(), "houndsman-hunt-"));
79
- const originalCwd = process.cwd();
80
- const originalHome = process.env.HOUNDSMAN_HOME;
81
- const originalKey = process.env.HOUNDSMAN_DEEP_SEEK_API_KEY;
82
- let base = "";
83
-
84
- function git(args: string[]): string {
85
- const result = Bun.spawnSync(["git", ...args], {
86
- cwd,
87
- stdout: "pipe",
88
- stderr: "pipe",
89
- });
90
- if (result.exitCode !== 0) {
91
- throw new Error(`git ${args.join(" ")}: ${result.stderr.toString()}`);
92
- }
93
- return result.stdout.toString();
94
- }
95
-
96
- function setupRepo(): void {
97
- git(["init", "-b", "main"]);
98
- git(["config", "user.email", "hunt@example.test"]);
99
- git(["config", "user.name", "Hunt"]);
100
- git(["config", "commit.gpgsign", "false"]);
101
- mkdirSync(join(cwd, "src", "alpha"), { recursive: true });
102
- writeFileSync(join(cwd, "src/alpha/a.ts"), "export const a = 1;\n");
103
- git(["add", "."]);
104
- git(["commit", "-m", "initial"]);
105
- base = git(["rev-parse", "HEAD"]).trim();
106
- writeFileSync(join(cwd, "src/alpha/a.ts"), "export const a: any = 1;\n");
107
- git(["add", "-A"]);
108
- git(["commit", "-m", "change"]);
109
- process.env.HOUNDSMAN_HOME = join(cwd, ".home");
110
- process.chdir(cwd);
111
- }
112
-
113
- function engine(): HoundsmanEngine {
114
- return new HoundsmanEngine({
115
- ...configBase,
116
- storage: { provider: "sqlite", path: join(cwd, "houndsman.db") },
117
- });
118
- }
119
-
120
- setupRepo();
121
- afterAll(() => {
122
- process.chdir(originalCwd);
123
- if (originalHome === undefined) delete process.env.HOUNDSMAN_HOME;
124
- else process.env.HOUNDSMAN_HOME = originalHome;
125
- if (originalKey === undefined) delete process.env.HOUNDSMAN_DEEP_SEEK_API_KEY;
126
- else process.env.HOUNDSMAN_DEEP_SEEK_API_KEY = originalKey;
127
- rmSync(cwd, { recursive: true, force: true });
128
- });
129
-
130
- describe("hunt", () => {
131
- test("dry-run lista watchdogs sem chamar IA", async () => {
132
- const instance = engine();
133
- try {
134
- const harness = await HuntHarness.from(
135
- instance,
136
- parseHuntArgs(["--base", base, "--head", "HEAD", "--dry-run"]),
137
- new SilentLogger(),
138
- );
139
- const result = await harness.run();
140
- expect(result.status).toBe("dry-run");
141
- expect(result.messages.join("\n")).toContain("alpha");
142
- } finally {
143
- instance.close();
144
- }
145
- });
146
-
147
- test("sem chave e sem --dry-run falha com mensagem clara", async () => {
148
- delete process.env.HOUNDSMAN_DEEP_SEEK_API_KEY;
149
- const instance = engine();
150
- try {
151
- await expect(
152
- HuntHarness.from(
153
- instance,
154
- parseHuntArgs(["--base", base, "--head", "HEAD"]),
155
- new SilentLogger(),
156
- ),
157
- ).rejects.toThrow(/hunt exige IA configurada/);
158
- } finally {
159
- instance.close();
160
- }
161
- });
162
-
163
- test("provider fake investiga, grava findings e finaliza", async () => {
164
- const provider = new FakeModelProvider(async (request, index) => {
165
- if (index === 0) return { hypotheses: ["any"] };
166
- if (index === 1) return { taskIds: ["rule-0"] };
167
- const tool = request.tools?.read_file_range;
168
- if (!tool) throw new Error("read_file_range ausente");
169
- const parsed = JSON.parse(
170
- await tool.execute({ path: "src/alpha/a.ts", startLine: 1, endLine: 1 }),
171
- ) as { evidence?: { id: string }[] };
172
- return {
173
- findingDrafts: [
174
- {
175
- rule: RULE,
176
- severity: "blocking",
177
- file: "src/alpha/a.ts",
178
- line: 1,
179
- message: "any detectado",
180
- action: "tipar",
181
- evidenceIds: [parsed.evidence?.[0]?.id].filter(Boolean),
182
- confidence: 0.9,
183
- },
184
- ],
185
- coverage: [{ rule: RULE, status: "checked" }],
186
- };
187
- });
188
- const instance = engine();
189
- try {
190
- const harness = await HuntHarness.from(
191
- instance,
192
- parseHuntArgs(["--base", base, "--head", "HEAD"]),
193
- new SilentLogger(),
194
- provider,
195
- );
196
- const result = await harness.run();
197
- expect(result.status).toBe("completed");
198
- expect(result.blockers).toBe(1);
199
- const review = instance.storage.readArtifact(result.reviewId, "review.md");
200
- expect(review?.content).toContain("any detectado");
201
- const transcript = instance.storage.readArtifact(
202
- result.reviewId,
203
- "harness-transcript.json",
204
- );
205
- expect(transcript?.content).toContain("VERIFY");
206
- const usage = instance.storage.readArtifact(result.reviewId, "ai-usage.json");
207
- expect(usage?.content).toContain('"calls"');
208
- } finally {
209
- instance.close();
210
- }
211
- });
212
- });
@@ -1,61 +0,0 @@
1
- /**
2
- * RuleAnalyzer — polaridade, categoria, sinais e hints.
3
- */
4
-
5
- import { describe, expect, test } from "bun:test";
6
- import { RuleAnalyzer } from "../harness/investigation/rule-analyzer";
7
-
8
- const analyzer = new RuleAnalyzer();
9
-
10
- describe("RuleAnalyzer", () => {
11
- test("detecta polaridade explícita", () => {
12
- const [avoid, promote] = analyzer.analyze([
13
- { severity: "blocking", text: "Evitar: chamar banco diretamente em rotas." },
14
- { severity: "attention", text: "Promover: usar `logger` estruturado." },
15
- ]);
16
- expect(avoid?.intent).toBe("avoid");
17
- expect(promote?.intent).toBe("promote");
18
- });
19
-
20
- test("classifica categoria por keywords", () => {
21
- const [data, tests] = analyzer.analyze([
22
- {
23
- severity: "attention",
24
- text: "Evitar: query direta no banco sem migration.",
25
- },
26
- { severity: "nit", text: "Promover: cobertura de teste no handler." },
27
- ]);
28
- expect(data?.category).toBe("data");
29
- expect(tests?.category).toBe("tests");
30
- });
31
-
32
- test("extrai sinais de backticks e hints (confiança alta)", () => {
33
- const [analysis] = analyzer.analyze([
34
- {
35
- severity: "blocking",
36
- text: "Evitar: usar `db.query` fora do service.",
37
- hints: {
38
- symbols: ["OrderService"],
39
- imports: ["db"],
40
- checks: ["symbol_context"],
41
- },
42
- },
43
- ]);
44
- expect(analysis?.confidence).toBe("high");
45
- expect(analysis?.signals.some((signal) => signal.value === "OrderService")).toBe(
46
- true,
47
- );
48
- expect(analysis?.signals.some((signal) => signal.value === "db")).toBe(true);
49
- expect(analysis?.checks.some((check) => check.tool === "symbol_context")).toBe(
50
- true,
51
- );
52
- });
53
-
54
- test("keywords ignoram stopwords", () => {
55
- const [analysis] = analyzer.analyze([
56
- { severity: "nit", text: "Nunca usar any em produção" },
57
- ]);
58
- expect(analysis?.keywords).not.toContain("nunca");
59
- expect(analysis?.keywords).toContain("produção");
60
- });
61
- });
@@ -1,82 +0,0 @@
1
- /**
2
- * Contract test das tools built-in: metadata, schema e erros estruturados.
3
- */
4
-
5
- import { describe, expect, test } from "bun:test";
6
- import { AstService } from "../core/ast/service";
7
- import { Watchdog } from "../core/domain/watchdog";
8
- import { SilentReporter } from "../harness/agent/agent-reporter";
9
- import { AgentState } from "../harness/investigation/agent-state";
10
- import type { ToolContext } from "../harness/tools/agent-tool";
11
- import { BuiltinToolsModule } from "../harness/tools/builtin";
12
- import { ToolCache } from "../harness/tools/tool-cache";
13
- import { ToolCallBudget } from "../harness/tools/tool-call-budget";
14
- import { ToolMiddleware } from "../harness/tools/tool-middleware";
15
- import { ToolRegistry } from "../harness/tools/tool-registry";
16
- import { fakeAgentContext } from "./fixtures/fake-investigation";
17
- import { fakeHoundsmanConfig } from "./fixtures/fake-project";
18
-
19
- function registry(): ToolRegistry {
20
- const value = new ToolRegistry();
21
- value.registerModule(new BuiltinToolsModule());
22
- return value;
23
- }
24
-
25
- function context(): ToolContext {
26
- return {
27
- repoRoot: process.cwd(),
28
- watchdog: new Watchdog(fakeHoundsmanConfig.watchdogs.alpha),
29
- diff: { byFile: new Map(), churn: new Map() },
30
- ast: new AstService(fakeHoundsmanConfig),
31
- state: new AgentState(),
32
- budget: new ToolCallBudget(20, 10),
33
- cache: new ToolCache(),
34
- logger: new SilentReporter(),
35
- agent: fakeAgentContext({ repoRoot: process.cwd() }),
36
- rules: new Map(),
37
- };
38
- }
39
-
40
- describe("contratos das tools", () => {
41
- test("todas declaram metadata read-only e capabilities", () => {
42
- for (const tool of registry().list()) {
43
- expect(tool.metadata.name.length).toBeGreaterThan(0);
44
- expect(tool.metadata.description.length).toBeGreaterThan(0);
45
- expect(tool.metadata.readOnly).toBe(true);
46
- expect(tool.metadata.capabilities.length).toBeGreaterThan(0);
47
- expect(tool.metadata.cost).toBeGreaterThanOrEqual(1);
48
- }
49
- });
50
-
51
- test("nenhuma tool devolve arquivo inteiro por padrão", () => {
52
- // `read_file_range` exige faixa explícita.
53
- const range = registry().get("read_file_range");
54
- expect(range?.inputSchema.safeParse({ path: "a.ts" }).success).toBe(false);
55
- // `file_outline` só devolve metadados (não tem parâmetro de corpo).
56
- const outline = registry().get("file_outline");
57
- expect(outline?.inputSchema.safeParse({ path: "a.ts" }).success).toBe(true);
58
- });
59
-
60
- test("tools de arquivo devolvem erro estruturado (não lançam)", async () => {
61
- const middleware = new ToolMiddleware();
62
- for (const [name, input] of [
63
- ["read_file_range", { path: "../x", startLine: 1, endLine: 2 }],
64
- ["file_outline", { path: "../x" }],
65
- ["imports_exports", { file: "../x" }],
66
- ] as const) {
67
- const result = await registry().execute(name, input, context(), middleware);
68
- expect(result.ok).toBe(false);
69
- expect(typeof result.error).toBe("string");
70
- }
71
- });
72
-
73
- test("rule_signals devolve erro quando a regra não existe", async () => {
74
- const result = await registry().execute(
75
- "rule_signals",
76
- { rule: "regra inexistente" },
77
- context(),
78
- new ToolMiddleware(),
79
- );
80
- expect(result.ok).toBe(false);
81
- });
82
- });