54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import type { AgentFn, Role, ThreadContext } from "@uncaged/nerve-core";
|
|
import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils";
|
|
import { createRole } from "@uncaged/nerve-workflow-utils";
|
|
import { z } from "zod";
|
|
|
|
function readIssuePrompt({ threadId }: { threadId: string }): string {
|
|
return `You are the **read-issue** agent. You fetch Gitea issue content via the \`tea\` CLI.
|
|
|
|
Read the workflow thread start prompt for the issue URL (same run): \`nerve thread show ${threadId}\`
|
|
|
|
## Steps
|
|
|
|
1. From the **initial user prompt** (issue URL), extract **host**, **owner**, **repo**, and **issue number**. Supported shape:
|
|
\`https://<host>/<owner>/<repo>/issues/<number>\`
|
|
|
|
2. Run:
|
|
\`tea issue show <number> --repo <owner>/<repo> --comments\`
|
|
(Add \`--json\` if helpful for parsing.)
|
|
|
|
3. In your reply, include **structured issue text**: title, body, labels, and each comment (author + body + time).
|
|
|
|
4. You **must** emit this marker block **exactly** (fill in real values):
|
|
\`\`\`
|
|
---SOLVE_ISSUE_PARSE---
|
|
host: <host>
|
|
owner: <owner>
|
|
repo: <repo>
|
|
number: <number>
|
|
---
|
|
\`\`\`
|
|
|
|
5. End with JSON meta (verbatim block):
|
|
\`\`\`json
|
|
{ "ready": true }
|
|
\`\`\`
|
|
Use \`{ "ready": false }\` if you could not fetch or parse the issue.
|
|
|
|
**ready=true** only if the issue was fetched successfully and the marker block is correct.`;
|
|
}
|
|
|
|
export const readIssueMetaSchema = z.object({
|
|
ready: z.boolean().describe("true if issue content was fetched and markers are present"),
|
|
});
|
|
export type ReadIssueMeta = z.infer<typeof readIssueMetaSchema>;
|
|
|
|
export function createReadIssueRole(adapter: AgentFn, extract: LlmExtractorConfig): Role<ReadIssueMeta> {
|
|
return createRole(
|
|
adapter,
|
|
async (ctx: ThreadContext) => readIssuePrompt({ threadId: ctx.start.meta.threadId }),
|
|
readIssueMetaSchema,
|
|
extract,
|
|
);
|
|
}
|