@rigour-labs/cli 3.0.5 → 4.0.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.
@@ -0,0 +1,181 @@
1
+ import chalk from 'chalk';
2
+ import { pause, getMultiplier, sleep } from './demo-helpers.js';
3
+ // ── Simulated code writing ──────────────────────────────────────────
4
+ export async function simulateCodeWrite(filename, lines, options) {
5
+ const isCinematic = !!options.cinematic;
6
+ const lineDelay = isCinematic ? 40 * getMultiplier(options) : 0;
7
+ console.log(chalk.dim(`\n ${chalk.white('▸')} Writing ${chalk.cyan(filename)}...`));
8
+ if (isCinematic) {
9
+ await pause(200, options);
10
+ }
11
+ for (const line of lines) {
12
+ if (isCinematic) {
13
+ process.stdout.write(chalk.dim(` ${line}\n`));
14
+ await sleep(lineDelay);
15
+ }
16
+ }
17
+ if (!isCinematic) {
18
+ const preview = lines.slice(0, 3).join('\n ');
19
+ console.log(chalk.dim(` ${preview}`));
20
+ if (lines.length > 3) {
21
+ console.log(chalk.dim(` ... (${lines.length} lines)`));
22
+ }
23
+ }
24
+ }
25
+ // ── Hook simulation ─────────────────────────────────────────────────
26
+ export async function simulateHookCatch(gate, file, message, severity, options) {
27
+ if (options.cinematic) {
28
+ await pause(300, options);
29
+ }
30
+ const sevColor = severity === 'critical' ? chalk.red.bold
31
+ : severity === 'high' ? chalk.red
32
+ : chalk.yellow;
33
+ const hookPrefix = chalk.magenta.bold('[rigour/hook]');
34
+ const sevLabel = sevColor(severity.toUpperCase());
35
+ const gateLabel = chalk.red(`[${gate}]`);
36
+ console.log(` ${hookPrefix} ${sevLabel} ${gateLabel} ${chalk.white(file)}`);
37
+ console.log(` ${chalk.dim('→')} ${message}`);
38
+ if (options.cinematic) {
39
+ await pause(400, options);
40
+ }
41
+ }
42
+ // ── ASCII score bar ─────────────────────────────────────────────────
43
+ export function renderScoreBar(score, label, width = 30) {
44
+ const filled = Math.round((score / 100) * width);
45
+ const empty = width - filled;
46
+ const color = score >= 80 ? chalk.green : score >= 50 ? chalk.yellow : chalk.red;
47
+ const bar = color('█'.repeat(filled)) + chalk.dim('░'.repeat(empty));
48
+ return ` ${label.padEnd(14)} ${bar} ${color.bold(`${score}/100`)}`;
49
+ }
50
+ // ── ASCII trend chart ───────────────────────────────────────────────
51
+ export function renderTrendChart(scores) {
52
+ const height = 8;
53
+ const lines = [];
54
+ const maxScore = 100;
55
+ lines.push(chalk.dim(' Score Trend:'));
56
+ for (let row = height; row >= 0; row--) {
57
+ const threshold = (row / height) * maxScore;
58
+ let line = chalk.dim(String(Math.round(threshold)).padStart(3) + ' │');
59
+ for (const score of scores) {
60
+ if (score >= threshold) {
61
+ const color = score >= 80 ? chalk.green : score >= 50 ? chalk.yellow : chalk.red;
62
+ line += color(' ██');
63
+ }
64
+ else {
65
+ line += ' ';
66
+ }
67
+ }
68
+ lines.push(line);
69
+ }
70
+ lines.push(chalk.dim(' └' + '───'.repeat(scores.length)));
71
+ const labels = scores.map((_, i) => ` R${i + 1}`);
72
+ lines.push(chalk.dim(' ' + labels.join('')));
73
+ return lines.join('\n');
74
+ }
75
+ // ── Banner ───────────────────────────────────────────────────────────
76
+ export function printBanner(cinematic) {
77
+ const banner = chalk.bold.cyan(`
78
+ ____ _
79
+ / __ \\(_)____ ___ __ __ _____
80
+ / /_/ // // __ \`/ / / / / // ___/
81
+ / _, _// // /_/ // /_/ / / // /
82
+ /_/ |_|/_/ \\__, / \\__,_/_/ /_/
83
+ /____/
84
+ `);
85
+ console.log(banner);
86
+ }
87
+ // ── Planted issues (non-cinematic) ──────────────────────────────────
88
+ export function printPlantedIssues() {
89
+ console.log(chalk.bold.yellow('Planted issues:'));
90
+ console.log(chalk.dim(' 1. src/auth.ts — Hardcoded API key (security)'));
91
+ console.log(chalk.dim(' 2. src/api-handler.ts — Unhandled promise (AI drift)'));
92
+ console.log(chalk.dim(' 3. src/data-loader.ts — Hallucinated import (AI drift)'));
93
+ console.log(chalk.dim(' 4. src/utils.ts — TODO marker left by AI'));
94
+ console.log(chalk.dim(' 5. src/god-file.ts — 350+ lines (structural)'));
95
+ console.log('');
96
+ }
97
+ // ── Hooks demo: simulate AI agent → hook catches ────────────────────
98
+ // ── Closing section ─────────────────────────────────────────────────
99
+ export function displayGateResults(report, cinematic) {
100
+ const stats = report.stats;
101
+ if (report.status === 'FAIL') {
102
+ console.log(chalk.red.bold('✘ FAIL — Quality gate violations found.\n'));
103
+ // Score bars
104
+ if (stats.score !== undefined) {
105
+ console.log(renderScoreBar(stats.score, 'Overall'));
106
+ }
107
+ if (stats.ai_health_score !== undefined) {
108
+ console.log(renderScoreBar(stats.ai_health_score, 'AI Health'));
109
+ }
110
+ if (stats.structural_score !== undefined) {
111
+ console.log(renderScoreBar(stats.structural_score, 'Structural'));
112
+ }
113
+ console.log('');
114
+ // Severity breakdown
115
+ printSeverityBreakdown(stats);
116
+ // Violations list
117
+ for (const failure of report.failures) {
118
+ printFailure(failure);
119
+ }
120
+ console.log('');
121
+ }
122
+ else {
123
+ console.log(chalk.green.bold('✔ PASS — All quality gates satisfied.\n'));
124
+ }
125
+ console.log(chalk.dim(`Finished in ${stats.duration_ms}ms\n`));
126
+ }
127
+ export function printSeverityBreakdown(stats) {
128
+ if (!stats.severity_breakdown) {
129
+ return;
130
+ }
131
+ const parts = Object.entries(stats.severity_breakdown)
132
+ .filter(([, count]) => count > 0)
133
+ .map(([sev, count]) => {
134
+ const color = sev === 'critical' ? chalk.red.bold
135
+ : sev === 'high' ? chalk.red
136
+ : sev === 'medium' ? chalk.yellow
137
+ : chalk.dim;
138
+ return color(`${sev}: ${count}`);
139
+ });
140
+ if (parts.length > 0) {
141
+ console.log('Severity: ' + parts.join(', ') + '\n');
142
+ }
143
+ }
144
+ export function printFailure(failure) {
145
+ const sevLabel = failure.severity === 'critical' ? chalk.red.bold('CRIT')
146
+ : failure.severity === 'high' ? chalk.red('HIGH')
147
+ : failure.severity === 'medium' ? chalk.yellow('MED ')
148
+ : chalk.dim('LOW ');
149
+ const prov = failure.provenance ? chalk.dim(`[${failure.provenance}]`) : '';
150
+ console.log(` ${sevLabel} ${prov} ${chalk.red(`[${failure.id}]`)} ${failure.title}`);
151
+ if (failure.hint) {
152
+ console.log(chalk.cyan(` ${failure.hint}`));
153
+ }
154
+ }
155
+ export function printClosing(cinematic) {
156
+ const divider = chalk.bold.cyan('━'.repeat(50));
157
+ console.log(divider);
158
+ console.log(chalk.bold('What Rigour does:'));
159
+ console.log(chalk.dim(' Catches AI drift (hallucinated imports, unhandled promises)'));
160
+ console.log(chalk.dim(' Blocks security issues (hardcoded keys, injection patterns)'));
161
+ console.log(chalk.dim(' Enforces structure (file size, complexity, documentation)'));
162
+ console.log(chalk.dim(' Generates audit-ready evidence (scores, trends, reports)'));
163
+ console.log(chalk.dim(' Real-time hooks for Claude, Cursor, Cline, Windsurf'));
164
+ console.log(divider);
165
+ console.log('');
166
+ if (cinematic) {
167
+ console.log(chalk.bold('Peer-reviewed research:'));
168
+ console.log(chalk.white(' Deterministic Quality Gates for AI-Generated Code'));
169
+ console.log(chalk.dim(' https://zenodo.org/records/18673564'));
170
+ console.log('');
171
+ }
172
+ console.log(chalk.bold('Get started:'));
173
+ console.log(chalk.white(' $ npx @rigour-labs/cli init'));
174
+ console.log(chalk.white(' $ npx @rigour-labs/cli check'));
175
+ console.log(chalk.white(' $ npx @rigour-labs/cli hooks init'));
176
+ console.log('');
177
+ console.log(chalk.dim('GitHub: https://github.com/rigour-labs/rigour'));
178
+ console.log(chalk.dim('Docs: https://docs.rigour.run'));
179
+ console.log(chalk.dim('Paper: https://zenodo.org/records/18673564\n'));
180
+ console.log(chalk.dim.italic('If this saved you from a bad commit, star the repo ⭐'));
181
+ }
@@ -0,0 +1,9 @@
1
+ export interface DemoOptions {
2
+ cinematic?: boolean;
3
+ hooks?: boolean;
4
+ speed?: 'fast' | 'normal' | 'slow';
5
+ }
6
+ export declare function getMultiplier(options: DemoOptions): number;
7
+ export declare function sleep(ms: number): Promise<void>;
8
+ export declare function pause(ms: number, options: DemoOptions): Promise<void>;
9
+ export declare function typewrite(text: string, options: DemoOptions, charDelay?: number): Promise<void>;
@@ -0,0 +1,28 @@
1
+ const SPEED_MULTIPLIERS = {
2
+ fast: 0.3,
3
+ normal: 1.0,
4
+ slow: 1.8,
5
+ };
6
+ // ── Timing helpers ──────────────────────────────────────────────────
7
+ export function getMultiplier(options) {
8
+ return SPEED_MULTIPLIERS[options.speed || 'normal'] || 1.0;
9
+ }
10
+ export function sleep(ms) {
11
+ return new Promise(resolve => setTimeout(resolve, ms));
12
+ }
13
+ export async function pause(ms, options) {
14
+ await sleep(ms * getMultiplier(options));
15
+ }
16
+ // ── Typewriter effect ───────────────────────────────────────────────
17
+ export async function typewrite(text, options, charDelay = 18) {
18
+ if (!options.cinematic) {
19
+ process.stdout.write(text + '\n');
20
+ return;
21
+ }
22
+ const delay = charDelay * getMultiplier(options);
23
+ for (const char of text) {
24
+ process.stdout.write(char);
25
+ await sleep(delay);
26
+ }
27
+ process.stdout.write('\n');
28
+ }
@@ -0,0 +1,11 @@
1
+ import type { DemoOptions } from './demo-helpers.js';
2
+ export declare function runHooksDemo(demoDir: string, options: DemoOptions): Promise<void>;
3
+ export declare function simulateAgentWrite(filename: string, codeLines: string[], gate: string, file: string, message: string, severity: string, options: DemoOptions): Promise<void>;
4
+ export declare function runFullGates(demoDir: string, options: DemoOptions): Promise<void>;
5
+ export declare function runBeforeAfterDemo(demoDir: string, options: DemoOptions): Promise<void>;
6
+ export declare function scaffoldDemoProject(dir: string): Promise<void>;
7
+ export declare function buildDemoConfig(): Record<string, unknown>;
8
+ export declare function buildDemoPackageJson(): Record<string, unknown>;
9
+ export declare function writeIssueFiles(dir: string): Promise<void>;
10
+ export declare function writeGodFile(dir: string): Promise<void>;
11
+ export declare function generateDemoAudit(dir: string, report: any, outputPath: string): Promise<void>;
@@ -0,0 +1,356 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import chalk from 'chalk';
4
+ import yaml from 'yaml';
5
+ import { GateRunner, ConfigSchema } from '@rigour-labs/core';
6
+ import { recordScore } from '@rigour-labs/core';
7
+ import { pause, typewrite } from './demo-helpers.js';
8
+ import { simulateCodeWrite, simulateHookCatch, renderScoreBar, renderTrendChart, displayGateResults, } from './demo-display.js';
9
+ // ── Hooks demo: simulate AI agent → hook catches ────────────────────
10
+ export async function runHooksDemo(demoDir, options) {
11
+ const divider = chalk.cyan('━'.repeat(50));
12
+ console.log(divider);
13
+ console.log(chalk.bold.magenta(' Simulating AI agent writing code with hooks active...\n'));
14
+ if (options.cinematic) {
15
+ await pause(600, options);
16
+ }
17
+ // Step 1: AI writes auth.ts with hardcoded key
18
+ await simulateAgentWrite('src/auth.ts', [
19
+ 'import express from \'express\';',
20
+ '',
21
+ 'const API_KEY = "sk-live-4f3c2b1a0987654321abcdef";',
22
+ '',
23
+ 'export function authenticate(req: express.Request) {',
24
+ ' return req.headers.authorization === API_KEY;',
25
+ '}',
26
+ ], 'security-patterns', 'src/auth.ts:3', 'Possible hardcoded secret or API key', 'critical', options);
27
+ // Step 2: AI writes data-loader.ts with hallucinated import
28
+ await simulateAgentWrite('src/data-loader.ts', [
29
+ 'import { z } from \'zod\';',
30
+ 'import { magicParser } from \'ai-data-magic\';',
31
+ '',
32
+ 'export function loadData(raw: unknown) {',
33
+ ' return z.object({ name: z.string() }).parse(raw);',
34
+ '}',
35
+ ], 'hallucinated-imports', 'src/data-loader.ts:2', 'Import \'ai-data-magic\' does not resolve to an existing package', 'high', options);
36
+ // Step 3: AI writes api-handler.ts with unhandled promise
37
+ await simulateAgentWrite('src/api-handler.ts', [
38
+ 'export async function fetchUser(id: string) {',
39
+ ' const res = await fetch(`/api/users/${id}`);',
40
+ ' return res.json();',
41
+ '}',
42
+ '',
43
+ 'export function handleRequest(req: any, res: any) {',
44
+ ' fetchUser(req.params.id); // floating promise',
45
+ ' res.send(\'Processing...\');',
46
+ '}',
47
+ ], 'promise-safety', 'src/api-handler.ts:7', 'Unhandled promise — fetchUser() called without await or .catch()', 'medium', options);
48
+ console.log('');
49
+ console.log(chalk.magenta.bold(` Hooks caught 3 issues in real time — before the agent finished.`));
50
+ console.log(divider);
51
+ console.log('');
52
+ if (options.cinematic) {
53
+ await pause(1000, options);
54
+ }
55
+ }
56
+ export async function simulateAgentWrite(filename, codeLines, gate, file, message, severity, options) {
57
+ console.log(chalk.blue.bold(` Agent: Write → ${filename}`));
58
+ await simulateCodeWrite(filename, codeLines, options);
59
+ await simulateHookCatch(gate, file, message, severity, options);
60
+ console.log('');
61
+ }
62
+ // ── Full gate run ───────────────────────────────────────────────────
63
+ export async function runFullGates(demoDir, options) {
64
+ const isCinematic = !!options.cinematic;
65
+ console.log(chalk.bold.blue('Running full Rigour quality gates...\n'));
66
+ if (isCinematic) {
67
+ await pause(500, options);
68
+ }
69
+ try {
70
+ const configContent = await fs.readFile(path.join(demoDir, 'rigour.yml'), 'utf-8');
71
+ const rawConfig = yaml.parse(configContent);
72
+ const config = ConfigSchema.parse(rawConfig);
73
+ const runner = new GateRunner(config);
74
+ const report = await runner.run(demoDir);
75
+ recordScore(demoDir, report);
76
+ const reportPath = path.join(demoDir, config.output.report_path);
77
+ await fs.writeJson(reportPath, report, { spaces: 2 });
78
+ displayGateResults(report, isCinematic);
79
+ await generateArtifacts(demoDir, report, config);
80
+ }
81
+ catch (error) {
82
+ const msg = error instanceof Error ? error.message : String(error);
83
+ console.error(chalk.red(`Demo error: ${msg}`));
84
+ }
85
+ }
86
+ async function generateArtifacts(demoDir, report, config) {
87
+ if (report.status === 'FAIL') {
88
+ const { FixPacketService } = await import('@rigour-labs/core');
89
+ const fixPacketService = new FixPacketService();
90
+ const fixPacket = fixPacketService.generate(report, config);
91
+ const fixPacketPath = path.join(demoDir, 'rigour-fix-packet.json');
92
+ await fs.writeJson(fixPacketPath, fixPacket, { spaces: 2 });
93
+ console.log(chalk.green('✓ Fix packet generated: rigour-fix-packet.json'));
94
+ }
95
+ const auditPath = path.join(demoDir, 'rigour-audit-report.md');
96
+ await generateDemoAudit(demoDir, report, auditPath);
97
+ console.log(chalk.green('✓ Audit report exported: rigour-audit-report.md'));
98
+ console.log('');
99
+ }
100
+ // ── Before/After improvement demo ───────────────────────────────────
101
+ export async function runBeforeAfterDemo(demoDir, options) {
102
+ console.log(chalk.bold.green('Simulating agent fixing issues...\n'));
103
+ await pause(600, options);
104
+ // Fix the auth.ts — remove hardcoded key
105
+ await typewrite(chalk.dim(' Agent: Removing hardcoded API key from src/auth.ts...'), options);
106
+ await fs.writeFile(path.join(demoDir, 'src', 'auth.ts'), `
107
+ import express from 'express';
108
+
109
+ export function authenticate(req: express.Request) {
110
+ const token = req.headers.authorization;
111
+ if (!token) {
112
+ return { authenticated: false };
113
+ }
114
+ // Validate against secure key store
115
+ return { authenticated: validateToken(token) };
116
+ }
117
+
118
+ function validateToken(token: string): boolean {
119
+ return token.startsWith('Bearer ') && token.length > 20;
120
+ }
121
+ `.trim());
122
+ console.log(chalk.green(' ✓ Fixed: API key moved to environment variable'));
123
+ await pause(300, options);
124
+ // Fix data-loader.ts — remove hallucinated import
125
+ await typewrite(chalk.dim(' Agent: Removing hallucinated import from src/data-loader.ts...'), options);
126
+ await fs.writeFile(path.join(demoDir, 'src', 'data-loader.ts'), `
127
+ import { z } from 'zod';
128
+
129
+ const schema = z.object({
130
+ name: z.string(),
131
+ email: z.string().email(),
132
+ });
133
+
134
+ export function loadData(raw: unknown) {
135
+ return schema.parse(raw);
136
+ }
137
+ `.trim());
138
+ console.log(chalk.green(' ✓ Fixed: Removed non-existent package imports'));
139
+ await pause(300, options);
140
+ // Fix api-handler.ts — add error handling
141
+ await typewrite(chalk.dim(' Agent: Adding error handling to src/api-handler.ts...'), options);
142
+ await fs.writeFile(path.join(demoDir, 'src', 'api-handler.ts'), `
143
+ import express from 'express';
144
+
145
+ export async function fetchUserData(userId: string) {
146
+ const response = await fetch(\`https://api.example.com/users/\${userId}\`);
147
+ if (!response.ok) {
148
+ throw new Error(\`Failed to fetch user: \${response.status}\`);
149
+ }
150
+ return response.json();
151
+ }
152
+
153
+ export async function handleRequest(req: express.Request, res: express.Response) {
154
+ try {
155
+ const data = await fetchUserData(req.params.id);
156
+ res.json(data);
157
+ } catch (error) {
158
+ res.status(500).json({ error: 'Failed to fetch user data' });
159
+ }
160
+ }
161
+ `.trim());
162
+ console.log(chalk.green(' ✓ Fixed: Added proper await and error handling'));
163
+ console.log('');
164
+ await pause(500, options);
165
+ // Re-run gates to show improvement
166
+ console.log(chalk.bold.blue('Re-running quality gates after fixes...\n'));
167
+ await pause(400, options);
168
+ try {
169
+ const configContent = await fs.readFile(path.join(demoDir, 'rigour.yml'), 'utf-8');
170
+ const rawConfig = yaml.parse(configContent);
171
+ const config = ConfigSchema.parse(rawConfig);
172
+ const runner = new GateRunner(config);
173
+ const report2 = await runner.run(demoDir);
174
+ recordScore(demoDir, report2);
175
+ const score1 = 35; // approximate first-run score
176
+ const score2 = report2.stats.score ?? 75;
177
+ const remaining = report2.failures.length;
178
+ console.log(chalk.bold('Score improvement:\n'));
179
+ console.log(renderScoreBar(score1, 'Before'));
180
+ console.log(renderScoreBar(score2, 'After'));
181
+ console.log('');
182
+ // Trend chart
183
+ console.log(renderTrendChart([score1, score2]));
184
+ console.log('');
185
+ if (remaining > 0) {
186
+ console.log(chalk.yellow(` ${remaining} issue(s) remaining (structural, TODOs)`));
187
+ }
188
+ else {
189
+ console.log(chalk.green.bold(' All issues resolved!'));
190
+ }
191
+ console.log('');
192
+ }
193
+ catch (error) {
194
+ const msg = error instanceof Error ? error.message : String(error);
195
+ console.error(chalk.red(`Re-check error: ${msg}`));
196
+ }
197
+ }
198
+ // ── Scaffold demo project ───────────────────────────────────────────
199
+ export async function scaffoldDemoProject(dir) {
200
+ const config = buildDemoConfig();
201
+ await fs.writeFile(path.join(dir, 'rigour.yml'), yaml.stringify(config));
202
+ await fs.writeJson(path.join(dir, 'package.json'), buildDemoPackageJson(), { spaces: 2 });
203
+ await fs.ensureDir(path.join(dir, 'src'));
204
+ await fs.ensureDir(path.join(dir, 'docs'));
205
+ await writeIssueFiles(dir);
206
+ await writeGodFile(dir);
207
+ await fs.writeFile(path.join(dir, 'README.md'), '# Demo Project\n\nThis is a demo project for Rigour.\n');
208
+ }
209
+ export function buildDemoConfig() {
210
+ return {
211
+ version: 1,
212
+ preset: 'api',
213
+ gates: {
214
+ max_file_lines: 300,
215
+ forbid_todos: true,
216
+ forbid_fixme: true,
217
+ ast: { complexity: 10, max_params: 5 },
218
+ security: { enabled: true, block_on_severity: 'high' },
219
+ hallucinated_imports: { enabled: true, severity: 'critical' },
220
+ promise_safety: { enabled: true, severity: 'high' },
221
+ },
222
+ hooks: { enabled: true, tools: ['claude'] },
223
+ ignore: ['.git/**', 'node_modules/**'],
224
+ output: { report_path: 'rigour-report.json' },
225
+ };
226
+ }
227
+ export function buildDemoPackageJson() {
228
+ return {
229
+ name: 'rigour-demo',
230
+ version: '1.0.0',
231
+ dependencies: { express: '^4.18.0', zod: '^3.22.0' },
232
+ };
233
+ }
234
+ export async function writeIssueFiles(dir) {
235
+ // Issue 1: Hardcoded API key
236
+ await fs.writeFile(path.join(dir, 'src', 'auth.ts'), `
237
+ import express from 'express';
238
+
239
+ const API_KEY = "sk-live-4f3c2b1a0987654321abcdef";
240
+ const DB_PASSWORD = "super_secret_p@ssw0rd!";
241
+
242
+ export function authenticate(req: express.Request) {
243
+ const token = req.headers.authorization;
244
+ if (token === API_KEY) {
245
+ return { authenticated: true };
246
+ }
247
+ return { authenticated: false };
248
+ }
249
+
250
+ export function connectDatabase() {
251
+ return { host: 'prod-db.internal', password: DB_PASSWORD };
252
+ }
253
+ `.trim());
254
+ // Issue 2: Unhandled promise
255
+ await fs.writeFile(path.join(dir, 'src', 'api-handler.ts'), `
256
+ import express from 'express';
257
+
258
+ export async function fetchUserData(userId: string) {
259
+ const response = await fetch(\`https://api.example.com/users/\${userId}\`);
260
+ return response.json();
261
+ }
262
+
263
+ export function handleRequest(req: express.Request, res: express.Response) {
264
+ fetchUserData(req.params.id);
265
+ res.send('Processing...');
266
+ }
267
+
268
+ export function batchProcess(ids: string[]) {
269
+ ids.forEach(id => fetchUserData(id));
270
+ }
271
+ `.trim());
272
+ // Issue 3: Hallucinated import
273
+ await fs.writeFile(path.join(dir, 'src', 'data-loader.ts'), `
274
+ import { z } from 'zod';
275
+ import { magicParser } from 'ai-data-magic';
276
+ import { ultraCache } from 'quantum-cache-pro';
277
+
278
+ const schema = z.object({
279
+ name: z.string(),
280
+ email: z.string().email(),
281
+ });
282
+
283
+ export function loadData(raw: unknown) {
284
+ const parsed = schema.parse(raw);
285
+ return parsed;
286
+ }
287
+ `.trim());
288
+ // Issue 4: TODO markers
289
+ await fs.writeFile(path.join(dir, 'src', 'utils.ts'), `
290
+ // TODO: Claude suggested this but I need to review
291
+ // FIXME: This function has edge cases
292
+ export function formatDate(date: Date): string {
293
+ return date.toISOString().split('T')[0];
294
+ }
295
+
296
+ export function sanitizeInput(input: string): string {
297
+ // TODO: Add proper sanitization
298
+ return input.trim();
299
+ }
300
+ `.trim());
301
+ }
302
+ export async function writeGodFile(dir) {
303
+ const lines = [
304
+ '// Auto-generated data processing module',
305
+ 'export class DataProcessor {',
306
+ ];
307
+ for (let i = 0; i < 60; i++) {
308
+ lines.push(` process${i}(data: any) {`);
309
+ lines.push(` const result = data.map((x: any) => x * ${i + 1});`);
310
+ lines.push(` if (result.length > ${i * 10}) {`);
311
+ lines.push(` return result.slice(0, ${i * 10});`);
312
+ lines.push(` }`);
313
+ lines.push(` return result;`);
314
+ lines.push(` }`);
315
+ }
316
+ lines.push('}');
317
+ await fs.writeFile(path.join(dir, 'src', 'god-file.ts'), lines.join('\n'));
318
+ }
319
+ // ── Audit report generator ──────────────────────────────────────────
320
+ export async function generateDemoAudit(dir, report, outputPath) {
321
+ const stats = report.stats || {};
322
+ const failures = report.failures || [];
323
+ const lines = [];
324
+ lines.push('# Rigour Audit Report — Demo');
325
+ lines.push('');
326
+ lines.push(`**Generated:** ${new Date().toISOString()}`);
327
+ lines.push(`**Status:** ${report.status}`);
328
+ lines.push(`**Score:** ${stats.score ?? 100}/100`);
329
+ if (stats.ai_health_score !== undefined) {
330
+ lines.push(`**AI Health:** ${stats.ai_health_score}/100`);
331
+ }
332
+ if (stats.structural_score !== undefined) {
333
+ lines.push(`**Structural:** ${stats.structural_score}/100`);
334
+ }
335
+ lines.push('');
336
+ lines.push('## Violations');
337
+ lines.push('');
338
+ for (let i = 0; i < failures.length; i++) {
339
+ const f = failures[i];
340
+ lines.push(`### ${i + 1}. [${(f.severity || 'medium').toUpperCase()}] ${f.title}`);
341
+ lines.push(`- **ID:** \`${f.id}\``);
342
+ lines.push(`- **Provenance:** ${f.provenance || 'traditional'}`);
343
+ lines.push(`- **Details:** ${f.details}`);
344
+ if (f.files?.length) {
345
+ lines.push(`- **Files:** ${f.files.join(', ')}`);
346
+ }
347
+ if (f.hint) {
348
+ lines.push(`- **Hint:** ${f.hint}`);
349
+ }
350
+ lines.push('');
351
+ }
352
+ lines.push('---');
353
+ lines.push('*Generated by Rigour — https://rigour.run*');
354
+ lines.push('*Research: https://zenodo.org/records/18673564*');
355
+ await fs.writeFile(outputPath, lines.join('\n'));
356
+ }
@@ -3,21 +3,8 @@
3
3
  *
4
4
  * Creates a temp project with intentional AI-generated code issues,
5
5
  * runs Rigour against it, and shows the full experience.
6
- *
7
- * Modes:
8
- * Default: Fast demo — scaffold → check → results
9
- * --cinematic: Screen-recording optimized — typewriter effects, pauses,
10
- * simulated AI agent writing code, hooks catching issues
11
- * --hooks: Focus on the real-time hooks experience
12
- * --speed: Control pacing (fast / normal / slow)
13
- *
14
- * The "flagship demo" — one command to understand Rigour.
15
- *
16
6
  * @since v2.17.0 (extended v3.0.0)
17
7
  */
18
- export interface DemoOptions {
19
- cinematic?: boolean;
20
- hooks?: boolean;
21
- speed?: 'fast' | 'normal' | 'slow';
22
- }
8
+ import type { DemoOptions } from './demo-helpers.js';
9
+ export type { DemoOptions } from './demo-helpers.js';
23
10
  export declare function demoCommand(options?: DemoOptions): Promise<void>;