Repository navigation
Expand file tree
/
Copy pathindex.ts
More file actions
79 lines (72 loc) · 2.5 KB
/
Copy pathindex.ts
File metadata and controls
79 lines (72 loc) · 2.5 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
import {
accessTokenFromEnv,
query,
type AgentDefinition,
type SDKMessage,
} from "@qoder-ai/qoder-agent-sdk";
export const agents: Record<string, AgentDefinition> = {
"architecture-explorer": {
description: "Maps the repository architecture and important boundaries.",
prompt:
"Inspect the repository with read-only tools. Report the main modules, their responsibilities, dependencies, and architectural risks. Do not modify files.",
tools: ["Read", "Glob", "Grep"],
maxTurns: 5,
},
"test-strategist": {
description: "Evaluates the test strategy for a proposed migration.",
prompt:
"Inspect tests and production code with read-only tools. Identify critical behaviors, coverage gaps, and a practical migration verification plan. Do not modify files.",
tools: ["Read", "Glob", "Grep"],
maxTurns: 5,
},
};
function assistantText(message: SDKMessage): string[] {
if (message.type !== "assistant") return [];
const content = message.message.content;
if (!Array.isArray(content)) return [];
return content.flatMap((block) =>
block.type === "text" ? [block.text] : [],
);
}
export async function run(workspace: string): Promise<void> {
const stream = query({
prompt:
"Ask architecture-explorer to map the repository, then ask test-strategist to design verification for a major dependency upgrade. Synthesize their findings into a concise migration plan with ordered steps and risks.",
options: {
auth: accessTokenFromEnv(),
cwd: workspace,
model: "auto",
agents,
tools: ["Agent"],
allowedTools: ["Agent"],
maxTurns: 8,
},
});
let completed = false;
try {
for await (const message of stream) {
for (const text of assistantText(message)) process.stdout.write(text);
if (message.type === "result") {
if (message.subtype !== "success") {
throw new Error(message.errors?.join("\n") || message.subtype);
}
completed = true;
}
}
} finally {
await stream.close();
}
if (!completed) throw new Error("The query ended without a success result.");
process.stdout.write("\n");
}
async function main(): Promise<void> {
await run(resolve(process.argv[2] ?? process.cwd()));
}
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
main().catch((error: unknown) => {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
});
}