-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.ts
More file actions
62 lines (56 loc) · 2.02 KB
/
Copy pathdemo.ts
File metadata and controls
62 lines (56 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bun
import { resolve } from "node:path";
import { loadConfig } from "../src/config/index.js";
import { runExec } from "../src/exec/runner.js";
import { runTUI } from "../src/tui/runner.js";
const DEMO_TASK =
"Add JWT authentication middleware to the product and order routes. Unauthenticated requests should receive a 401 response. Authenticated requests carry a Bearer token in the Authorization header; the middleware should verify the token using a shared secret (HMAC-SHA256). The secret is the string 'demo-secret'. Add tests that cover both authenticated and unauthenticated paths.";
const DEMO_FIXTURE = resolve(import.meta.dirname, "../tests/fixtures/demo-comparison");
async function runTUIMode(): Promise<void> {
console.log("=== TUI demo (fixture repo) ===");
const config = await loadConfig(
["--cwd", DEMO_FIXTURE, "--force", DEMO_TASK],
{ allowUnconfigured: false },
);
const code = await runTUI({ ...config, task: DEMO_TASK, maxTurns: 10 });
process.exitCode = code;
}
async function runExecMode(): Promise<void> {
console.log("=== Exec demo (fixture repo, product non-TUI path) ===");
const config = await loadConfig(
[
"exec",
"--cwd",
DEMO_FIXTURE,
"--force",
"--dangerously-skip-permissions",
DEMO_TASK,
],
{ allowUnconfigured: false },
);
const result = await runExec({ ...config, task: DEMO_TASK, maxTurns: 10 });
process.exitCode = result.exitCode;
}
async function main(): Promise<void> {
const mode = process.argv[2] ?? "tui";
if (mode === "exec" || mode === "cli" || mode === "run") {
await runExecMode();
return;
}
if (mode === "tui") {
await runTUIMode();
return;
}
if (mode === "both") {
await runExecMode();
if ((process.exitCode ?? 0) !== 0) return;
await runTUIMode();
return;
}
console.error(`Unknown mode "${mode}". Use: tui | exec | both`);
process.exit(1);
}
void main().catch((err: unknown) => {
console.error(err instanceof Error ? err.message : String(err));
process.exit(1);
});