Repository navigation
Expand file tree
/
Copy pathanalyze.ts
More file actions
50 lines (45 loc) · 1.54 KB
/
Copy pathanalyze.ts
File metadata and controls
50 lines (45 loc) · 1.54 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
import { openDb, resolveProjectDir, runAnalysis } from "@procni/core";
import { join } from "node:path";
import { resolveProject } from "../lib/resolveProject.js";
import { resolveProviderOrThrow } from "../lib/resolveProvider.js";
export interface AnalyzeOpportunity {
id: number;
title: string;
summary: string;
score: number;
}
export interface AnalyzeResult {
analysisRunId: number;
opportunities: AnalyzeOpportunity[];
}
/**
* `procni analyze` — a synchronous, one-shot terminal command distinct from
* the job-queue path `procni dev`'s web UI uses (see
* `packages/core/src/pipeline/README.md` for why `runAnalysis` has two
* callers rather than one). Blocking here is fine: a CLI command is expected
* to run to completion, unlike an HTTP request.
*/
export async function runAnalyzeCommand(
cwd: string,
onStageStart?: (stage: string) => void,
): Promise<AnalyzeResult> {
const { repoRoot, config } = await resolveProject(cwd);
const { provider, model } = await resolveProviderOrThrow();
const db = openDb(join(resolveProjectDir(repoRoot), "procni.db"));
try {
const result = await runAnalysis(db, {
repoRoot,
projectName: config.name,
ai: provider,
model,
triggeredBy: "cli",
...(onStageStart ? { onStageStart: (stage: string) => onStageStart(stage) } : {}),
});
return {
analysisRunId: result.analysisRunId,
opportunities: result.opportunities.map((o) => ({ id: o.id, title: o.title, summary: o.summary, score: o.score })),
};
} finally {
await db.destroy();
}
}