coderoast 0.1.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/Agents.md ADDED
@@ -0,0 +1,391 @@
1
+ # Agents Architecture - CodeRoast
2
+
3
+ This document describes the **agent-based architecture** used in CodeRoast.
4
+
5
+ The goal of agents in this system is **separation of responsibility**, **hallucination control**, and **clear reasoning boundaries** between deterministic analysis and generative narration.
6
+
7
+ ---
8
+
9
+ ## Design Principles
10
+
11
+ 1. **Deterministic before Generative**
12
+ Agents that compute facts must run before agents that explain them.
13
+
14
+ 2. **Single Responsibility per Agent**
15
+ Each agent has one clear job and produces structured output.
16
+
17
+ 3. **Evidence-Bound Communication**
18
+ Agents communicate using schemas, not free text.
19
+
20
+ 4. **Graceful Degradation**
21
+ If an AI agent fails, deterministic agents still produce usable output.
22
+
23
+ ---
24
+
25
+ ## Agent Overview
26
+
27
+ ```
28
+ CLI Agent
29
+ -> Repo Scanner Agent
30
+ -> Code Analysis Agent
31
+ -> Insight Aggregator Agent
32
+ -> Evidence Guard Agent
33
+ -> Fix-It Agent (optional --fix)
34
+ -> Fix-Apply Agent (optional --apply-fixes)
35
+ -> Roast Narrator Agent (Gemini API)
36
+ -> Output Formatter Agent
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 1. CLI Agent
42
+
43
+ **Type:** Deterministic
44
+ **Role:** Entry point and command orchestration
45
+
46
+ ### Responsibilities
47
+
48
+ * Parse CLI commands and flags
49
+ * Validate inputs
50
+ * Select analysis mode (severity, focus, output format)
51
+ * Trigger downstream agents in order
52
+
53
+ ### Inputs
54
+
55
+ * Command arguments
56
+ * Flags (e.g. `--severity`, `--focus`)
57
+
58
+ ### Outputs
59
+
60
+ ```json
61
+ {
62
+ "path": ".",
63
+ "severity": "savage",
64
+ "focus": "architecture"
65
+ }
66
+ ```
67
+
68
+ ---
69
+
70
+ ## 2. Repo Scanner Agent
71
+
72
+ **Type:** Deterministic
73
+ **Role:** Repository discovery and metadata extraction
74
+
75
+ ### Responsibilities
76
+
77
+ * Traverse filesystem
78
+ * Respect `.gitignore`
79
+ * Detect languages and file types
80
+ * Identify entry points
81
+
82
+ ### Outputs
83
+
84
+ ```json
85
+ {
86
+ "languages": ["ts", "js"],
87
+ "fileCount": 128,
88
+ "folders": 19,
89
+ "entryPoints": ["src/index.ts"]
90
+ }
91
+ ```
92
+
93
+ ### Notes
94
+
95
+ * No code semantics here
96
+ * Pure structure and counts
97
+
98
+ ---
99
+
100
+ ## 3. Code Analysis Agent
101
+
102
+ **Type:** Deterministic
103
+ **Role:** Static code analysis and signal extraction
104
+
105
+ ### Responsibilities
106
+
107
+ * Parse ASTs
108
+ * Compute metrics
109
+ * Detect architectural and code smells
110
+ * Capture line ranges to support evidence
111
+
112
+ ### Signals Produced
113
+
114
+ * Long functions
115
+ * Duplicate blocks
116
+ * Direct circular dependencies
117
+ * Test presence
118
+
119
+ Planned: god files, layer violations, dependency direction.
120
+
121
+ ### Outputs
122
+
123
+ ```json
124
+ {
125
+ "metrics": {
126
+ "maxFunctionLength": 311,
127
+ "avgFunctionLength": 42,
128
+ "duplicateBlocks": 7,
129
+ "totalFunctions": 128
130
+ },
131
+ "signals": {
132
+ "longFunctions": [
133
+ {
134
+ "file": "src/handlers/user.ts",
135
+ "name": "saveUser",
136
+ "length": 72,
137
+ "startLine": 10,
138
+ "endLine": 81
139
+ }
140
+ ],
141
+ "duplicateBlocks": [
142
+ {
143
+ "hash": "a1b2c3",
144
+ "length": 12,
145
+ "occurrences": [
146
+ { "file": "src/a.ts", "startLine": 20, "endLine": 31 }
147
+ ]
148
+ }
149
+ ],
150
+ "circularDependencies": [
151
+ {
152
+ "from": "src/a.ts",
153
+ "to": "src/b.ts",
154
+ "fromStartLine": 1,
155
+ "fromEndLine": 1,
156
+ "toStartLine": 1,
157
+ "toEndLine": 1
158
+ }
159
+ ],
160
+ "testPresence": {
161
+ "hasTests": true,
162
+ "testFiles": ["src/__tests__/smoke.test.ts"]
163
+ }
164
+ }
165
+ }
166
+ ```
167
+
168
+ ### Notes
169
+
170
+ * This agent does **not** interpret or judge
171
+ * It only reports facts
172
+
173
+ ---
174
+
175
+ ## 4. Insight Aggregator Agent
176
+
177
+ **Type:** Deterministic
178
+ **Role:** Prepare LLM-safe context
179
+
180
+ ### Responsibilities
181
+
182
+ * Merge scanner and analysis outputs
183
+ * Filter noise
184
+ * Attach confidence levels
185
+ * Build structured evidence entries
186
+
187
+ ### Outputs
188
+
189
+ ```json
190
+ {
191
+ "issues": [
192
+ {
193
+ "type": "maintainability",
194
+ "signal": "longFunctions",
195
+ "confidence": "medium",
196
+ "evidence": [
197
+ {
198
+ "file": "src/handlers/user.ts",
199
+ "startLine": 10,
200
+ "endLine": 81,
201
+ "metrics": [{ "type": "loc", "value": 72 }]
202
+ }
203
+ ]
204
+ }
205
+ ]
206
+ }
207
+ ```
208
+
209
+ ### Notes
210
+
211
+ * This agent defines what the narrator is *allowed* to talk about
212
+ * Evidence entries must include file path, line range, and metrics
213
+
214
+ ---
215
+
216
+ ## 5. Evidence Guard Agent
217
+
218
+ **Type:** Deterministic
219
+ **Role:** Validate evidence completeness and enforce narration boundaries
220
+
221
+ ### Responsibilities
222
+
223
+ * Validate each issue has evidence entries with file path, line range, and metrics
224
+ * Mark issues as incomplete with a reason
225
+ * Gate what the narrator is allowed to say
226
+
227
+ ### Outputs
228
+
229
+ ```json
230
+ {
231
+ "issues": [
232
+ {
233
+ "type": "testing",
234
+ "signal": "testPresence",
235
+ "confidence": "medium",
236
+ "evidence": [],
237
+ "evidenceComplete": false,
238
+ "missingEvidenceReason": "No evidence items provided."
239
+ }
240
+ ]
241
+ }
242
+ ```
243
+
244
+ ### Notes
245
+
246
+ * If evidence is incomplete, the narrator must respond with "not enough data"
247
+
248
+ ---
249
+
250
+ ## 6. Fix-It Agent (optional --fix)
251
+
252
+ **Type:** Generative + Deterministic guard
253
+ **Role:** Evidence-locked patch preview and verification
254
+
255
+ ### Responsibilities
256
+
257
+ * Generate patch suggestions with Gemini using evidence-only prompts
258
+ * Reject any edit outside evidence line ranges
259
+ * Re-run analysis on patched content to verify improvement
260
+ * Emit unified diff previews only (no file writes)
261
+
262
+ ### Configuration
263
+
264
+ * `GEMINI_API_KEY` or `GOOGLE_API_KEY` (required to enable fixes)
265
+ * `--fix` (enable fix-it previews)
266
+
267
+ ### Hard Constraints
268
+
269
+ * Only touch files and line ranges present in evidence
270
+ * If verification fails, mark the suggestion as rejected
271
+
272
+ ---
273
+
274
+ ## 7. Fix-Apply Agent (optional --apply-fixes)
275
+
276
+ **Type:** Deterministic
277
+ **Role:** Proof-locked application of fixes on a new git branch
278
+
279
+ ### Responsibilities
280
+
281
+ * Apply verified Fix-It patches on a new git branch
282
+ * Run tests and only mark the apply as successful if tests pass
283
+ * Report branch name, test command, and pass/fail status
284
+
285
+ ### Configuration
286
+
287
+ * `--apply-fixes` (enable apply)
288
+ * `--fix-branch <name>` (optional branch name)
289
+ * `--fix-test-cmd "<cmd>"` (optional test command override)
290
+
291
+ ### Hard Constraints
292
+
293
+ * Must refuse to run on a dirty working tree
294
+ * Must not modify files if patch application fails
295
+
296
+ ---
297
+
298
+ ## 8. Roast Narrator Agent (Gemini API)
299
+
300
+ **Type:** Generative (Constrained)
301
+ **Role:** Human-readable explanation and humor
302
+
303
+ ### Responsibilities
304
+
305
+ * Generate roast-style feedback
306
+ * Explain issues using provided evidence
307
+ * Match selected tone (gentle, savage, investor-demo)
308
+ * Call Gemini API via the Google Gen AI SDK (`@google/genai`) with evidence-only prompts
309
+
310
+ ### Configuration
311
+
312
+ * `GEMINI_API_KEY` or `GOOGLE_API_KEY` (required to enable Gemini)
313
+
314
+ ### Hard Constraints
315
+
316
+ * Cannot introduce new issues
317
+ * Cannot infer unseen code
318
+ * Must reference provided evidence only
319
+ * If evidence is incomplete, respond with "not enough data"
320
+
321
+ ### Prompt Guarantees
322
+
323
+ * Evidence-bound
324
+ * Structured sections
325
+ * Tone without factual drift
326
+
327
+ ---
328
+
329
+ ## 9. Output Formatter Agent
330
+
331
+ **Type:** Deterministic
332
+ **Role:** UX presentation
333
+
334
+ ### Responsibilities
335
+
336
+ * Format output for terminal
337
+ * Apply colors, emojis, scores
338
+ * Render sections consistently
339
+
340
+ ### Output Example
341
+
342
+ ```
343
+ Architecture Roast
344
+ Repo Status: Recovering
345
+ Score: 6.8 / 10
346
+ ```
347
+
348
+ ---
349
+
350
+ ## Hallucination Safeguards (Agent-Level)
351
+
352
+ | Safeguard | Enforced By |
353
+ | --------------------------------- | ------------------------- |
354
+ | No raw code to LLM | Insight Aggregator |
355
+ | Evidence completeness validation | Evidence Guard |
356
+ | Evidence-locked patch scope | Fix-It Agent |
357
+ | Evidence-only narration | Evidence Guard + Narrator |
358
+ | Confidence labeling | Aggregator |
359
+ | Deterministic fallback | Output Formatter |
360
+
361
+ Worst case behavior:
362
+
363
+ > Output becomes factual and boring - never incorrect. If evidence is missing, the narrator says "not enough data".
364
+
365
+ ---
366
+
367
+ ## Implementation Plan (Gemini Integration)
368
+
369
+ 1. Add a Gemini client module and strict evidence-only prompt builder.
370
+ 2. Use `GEMINI_API_KEY` or `GOOGLE_API_KEY` to enable the narrator, with deterministic fallback when missing or on API error.
371
+ 3. Wire Gemini into the pipeline using Evidence Guard output only.
372
+ 4. Add tests with mocked Gemini responses and failure-mode fallback.
373
+
374
+ ---
375
+
376
+ ## Judge-Ready Summary
377
+
378
+ > CodeRoast uses a multi-agent pipeline where deterministic agents extract verifiable signals and a constrained generative agent narrates them. The Evidence Guard enforces evidence completeness, and the Fix-It Agent offers evidence-locked patch previews with verification.
379
+
380
+ ---
381
+
382
+ ## Future Agents (Post-Hackathon)
383
+
384
+ * CI Agent (GitHub Actions)
385
+ * Diff Agent (PR analysis)
386
+ * Trend Agent (historical repo health)
387
+ * Security Agent (OWASP-focused)
388
+
389
+ ---
390
+
391
+ **End of Agents.md**
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CodeRoast
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 ADDED
@@ -0,0 +1,153 @@
1
+ # CodeRoast
2
+
3
+ CodeRoast is an agent-based architecture for generating evidence-bound code reviews and "roasts" with strong separation between deterministic analysis and constrained narration.
4
+
5
+ ## Overview
6
+
7
+ This repository currently contains the architecture specification in `AGENTS.md`. The design focuses on deterministic data extraction first, followed by a tightly constrained generative step for human-readable output.
8
+
9
+ ## Architecture
10
+
11
+ Pipeline:
12
+
13
+ ```
14
+ CLI Agent
15
+ -> Repo Scanner Agent
16
+ -> Code Analysis Agent
17
+ -> Insight Aggregator Agent
18
+ -> Evidence Guard Agent
19
+ -> Roast Narrator Agent
20
+ -> Output Formatter Agent
21
+ ```
22
+
23
+ ## Agents at a Glance
24
+
25
+ - CLI Agent: parses commands and orchestrates the pipeline
26
+ - Repo Scanner Agent: discovers files, languages, and entry points
27
+ - Code Analysis Agent: extracts structural signals and metrics
28
+ - Insight Aggregator Agent: merges findings and ranks issues with confidence
29
+ - Evidence Guard Agent: validates evidence completeness and gates narration
30
+ - Roast Narrator Agent: generates explanation constrained to evidence
31
+ - Output Formatter Agent: renders final output for the terminal
32
+
33
+ ## Design Principles
34
+
35
+ - Deterministic before generative
36
+ - Single responsibility per agent
37
+ - Evidence-bound communication
38
+ - Graceful degradation when generative steps fail
39
+
40
+ ## Hallucination Safeguards
41
+
42
+ - No raw code is sent to the narrator
43
+ - Narration is limited to known signals and evidence
44
+ - Evidence completeness is validated before narration
45
+ - Confidence is attached to every issue
46
+
47
+ ## Getting Started
48
+
49
+ Prerequisite: Node.js 20+ (required by `@google/genai`).
50
+
51
+ ## Install (npm)
52
+
53
+ ```
54
+ npm install -g coderoast
55
+ ```
56
+
57
+ Run:
58
+
59
+ ```
60
+ coderoast --path . --severity savage --focus architecture
61
+ ```
62
+
63
+ 1. Install dependencies:
64
+
65
+ ```
66
+ npm install
67
+ ```
68
+
69
+ 2. Build the project:
70
+
71
+ ```
72
+ npm run build
73
+ ```
74
+
75
+ 3. (Optional) Enable Gemini narration (Google Gen AI SDK):
76
+
77
+ ```
78
+ set GEMINI_API_KEY=your_api_key
79
+ ```
80
+
81
+ You can also add it to a `.env` file at the project root (see `.env.example`):
82
+
83
+ ```
84
+ GEMINI_API_KEY=your_api_key
85
+ ```
86
+
87
+ The Google Gen AI SDK also supports `GOOGLE_API_KEY` if you prefer that name.
88
+
89
+ Optional overrides:
90
+
91
+ ```
92
+ GEMINI_MODEL=gemini-2.5-flash
93
+ GEMINI_API_VERSION=v1
94
+ ```
95
+
96
+ If you see a model not found error, set `GEMINI_MODEL` to an available model (for example, `gemini-3-flash-preview` if your API access includes it) or specify `GEMINI_API_VERSION`. The SDK defaults to beta endpoints unless you set an API version.
97
+
98
+ 4. Run the CLI:
99
+
100
+ ```
101
+ npm start -- --path . --severity savage --focus architecture
102
+ ```
103
+
104
+ To include raw evidence and patch diffs in the output, add `--details`:
105
+
106
+ ```
107
+ npm start -- --path . --severity savage --focus architecture --details
108
+ ```
109
+
110
+ You can cap the evidence list with `--details-limit` (default is 3 when details are shown). Use `--details-limit=0` to show all evidence lines.
111
+
112
+ 5. (Optional) Preview evidence-locked fixes:
113
+
114
+ ```
115
+ npm start -- --path . --fix
116
+ ```
117
+
118
+ Fix-It only outputs patch previews and does not edit files.
119
+
120
+ 6. (Optional) Proof-locked apply (new branch + tests):
121
+
122
+ ```
123
+ npm start -- --path . --fix --apply-fixes
124
+ ```
125
+
126
+ Optional flags:
127
+
128
+ - `--fix-branch <name>`: name the branch to create (default is `coderoast-fix-<timestamp>`).
129
+ - `--fix-test-cmd "<cmd>"`: override the test command (default is `npm test`).
130
+ - `--fix-debug`: save raw Gemini patch output to a temp file for debugging.
131
+ - `--fix-limit <n>`: limit how many Fix-It attempts to run.
132
+
133
+ ## Scripts
134
+
135
+ - `npm run lint` - run ESLint
136
+ - `npm run lint:fix` - auto-fix lint issues
137
+ - `npm run demo:fix` - create a demo repo and run Fix-It (requires `GEMINI_API_KEY` for suggestions)
138
+ - `npm run demo:judge` - run a judge-style report on the current repo (`--details` + `--fix`)
139
+ - `npm run typecheck` - run TypeScript in no-emit mode
140
+ - `npm run build` - compile to `dist/`
141
+ - `npm start` - run the compiled CLI
142
+ - `npm test` - build and run the test suite
143
+
144
+ ## Project Structure
145
+
146
+ - `src/index.ts` - CLI entry point
147
+ - `src/pipeline.ts` - agent pipeline orchestrator
148
+ - `src/agents/` - agent implementations
149
+ - `src/types.ts` - shared types and schemas
150
+
151
+ ## Learn More
152
+
153
+ See `AGENTS.md` for the full specification and detailed agent responsibilities.
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCliAgent = runCliAgent;
4
+ const DEFAULT_CONFIG = {
5
+ path: ".",
6
+ severity: "gentle",
7
+ focus: "general",
8
+ showDetails: false,
9
+ };
10
+ const SEVERITIES = ["gentle", "savage", "investor-demo"];
11
+ const FOCUS_AREAS = [
12
+ "architecture",
13
+ "performance",
14
+ "style",
15
+ "security",
16
+ "general",
17
+ ];
18
+ function getArgValue(args, name) {
19
+ const flag = `--${name}`;
20
+ const prefix = `${flag}=`;
21
+ for (let i = 0; i < args.length; i += 1) {
22
+ const arg = args[i];
23
+ if (arg === flag) {
24
+ return args[i + 1];
25
+ }
26
+ if (arg.startsWith(prefix)) {
27
+ return arg.slice(prefix.length);
28
+ }
29
+ }
30
+ return undefined;
31
+ }
32
+ function coerceSeverity(value) {
33
+ if (value && SEVERITIES.includes(value)) {
34
+ return value;
35
+ }
36
+ return DEFAULT_CONFIG.severity;
37
+ }
38
+ function coerceFocus(value) {
39
+ if (value && FOCUS_AREAS.includes(value)) {
40
+ return value;
41
+ }
42
+ return DEFAULT_CONFIG.focus;
43
+ }
44
+ function parseNumber(value) {
45
+ if (!value) {
46
+ return undefined;
47
+ }
48
+ const parsed = Number(value);
49
+ if (!Number.isFinite(parsed)) {
50
+ return undefined;
51
+ }
52
+ return parsed;
53
+ }
54
+ function parseBooleanFlag(args, name) {
55
+ const flag = `--${name}`;
56
+ const prefix = `${flag}=`;
57
+ for (const arg of args) {
58
+ if (arg === flag) {
59
+ return true;
60
+ }
61
+ if (arg.startsWith(prefix)) {
62
+ const value = arg.slice(prefix.length).toLowerCase();
63
+ if (value === "" || value === "true" || value === "1") {
64
+ return true;
65
+ }
66
+ if (value === "false" || value === "0") {
67
+ return false;
68
+ }
69
+ return true;
70
+ }
71
+ }
72
+ return false;
73
+ }
74
+ function parseBooleanFlagWithAliases(args, names) {
75
+ return names.some((name) => parseBooleanFlag(args, name));
76
+ }
77
+ function runCliAgent(argv) {
78
+ return {
79
+ path: getArgValue(argv, "path") ?? DEFAULT_CONFIG.path,
80
+ severity: coerceSeverity(getArgValue(argv, "severity")),
81
+ focus: coerceFocus(getArgValue(argv, "focus")),
82
+ maxFileSizeMB: parseNumber(getArgValue(argv, "max-file-size-mb")),
83
+ scanTimeoutMs: parseNumber(getArgValue(argv, "scan-timeout-ms")),
84
+ enableFixes: parseBooleanFlag(argv, "fix"),
85
+ showDetails: parseBooleanFlag(argv, "details"),
86
+ detailsLimit: parseNumber(getArgValue(argv, "details-limit")),
87
+ applyFixes: parseBooleanFlagWithAliases(argv, ["apply-fixes", "apply"]),
88
+ fixDebug: parseBooleanFlag(argv, "fix-debug"),
89
+ fixBranch: getArgValue(argv, "fix-branch"),
90
+ fixTestCmd: getArgValue(argv, "fix-test-cmd"),
91
+ fixLimit: parseNumber(getArgValue(argv, "fix-limit")),
92
+ };
93
+ }