58 lines
2.8 KiB
TypeScript
58 lines
2.8 KiB
TypeScript
import type { AgentFn, Role, ThreadContext } from "@uncaged/nerve-core";
|
|
import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils";
|
|
import { createRole, decorateRole, withDryRun, onFail } from "@uncaged/nerve-workflow-utils";
|
|
import { z } from "zod";
|
|
|
|
function committerPrompt({ threadId }: { threadId: string }): string {
|
|
return `You are the committer agent. The **implement** step finished with a passing build; your job is to branch, commit, and push.
|
|
|
|
1. Read the workflow thread: \`nerve thread show ${threadId}\` — understand what was planned, implemented, and reviewed.
|
|
2. In the thread, locate \`---SOLVE_ISSUE_PARSE---\` and \`---SOLVE_ISSUE_REPO---\`. From them you need issue **number**, **title** (for the branch slug), repo **path**, and **defaultBranch**.
|
|
3. \`cd\` to the repo **path** from the markers. Optionally read \`CONVENTIONS.md\` in that repo root if present.
|
|
4. Run \`git rev-parse --abbrev-ref HEAD\` and compare with **defaultBranch** from the markers. Implement leaves changes uncommitted on the default branch — you should be on that branch with a dirty working tree. If you are not on the default branch, or the tree is clean when you expected changes, set **committed** to false and explain.
|
|
5. Run \`git status\`. If there is nothing to commit, set **committed** to false and explain.
|
|
6. Create a feature branch (do not commit directly on the default branch if it would mix unrelated work):
|
|
- Name: \`fix/<number>-<short-slug>\` for fixes, or \`feat/<number>-<short-slug>\` if the issue is clearly a feature.
|
|
- **slug**: lowercase, hyphens only, short (from issue title words).
|
|
- Example: \`git checkout -b fix/42-auth-timeout\`
|
|
7. \`git add -A\`
|
|
8. Write a **conventional commit** message describing what changed and why, using the thread context.
|
|
9. \`git commit -m "<message>"\` — do NOT pass \`--author\`, use repo git config.
|
|
10. \`git push -u origin <branch-name>\`
|
|
|
|
**committed=true** only if branch was created, commit succeeded, and **push** succeeded.
|
|
|
|
End your reply with a JSON line:
|
|
\`\`\`json
|
|
{ "committed": true }
|
|
\`\`\`
|
|
or
|
|
\`\`\`json
|
|
{ "committed": false }
|
|
\`\`\``;
|
|
}
|
|
|
|
export const committerMetaSchema = z.object({
|
|
committed: z
|
|
.boolean()
|
|
.describe("true if branch created, changes committed, and pushed successfully"),
|
|
});
|
|
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
|
|
|
|
export function createCommitterRole(
|
|
adapter: AgentFn,
|
|
extract: LlmExtractorConfig,
|
|
): Role<CommitterMeta> {
|
|
const inner = createRole(
|
|
adapter,
|
|
async (ctx: ThreadContext) => committerPrompt({ threadId: ctx.start.meta.threadId }),
|
|
committerMetaSchema,
|
|
extract,
|
|
);
|
|
|
|
return decorateRole(inner, [
|
|
withDryRun({ label: "committer", meta: { committed: true } as CommitterMeta }),
|
|
onFail({ label: "committer", meta: { committed: false } as CommitterMeta }),
|
|
]) as Role<CommitterMeta>;
|
|
}
|