refactor: simplify workspace committer — infer from thread #18

Merged
xiaoju merged 1 commits from refactor/17-simplify-committer into master 2026-04-29 12:53:35 +00:00
8 changed files with 31 additions and 133 deletions
Showing only changes of commit 0a9da468f7 - Show all commits

View File

@ -10,44 +10,16 @@ export const committerMetaSchema = z.object({
});
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
export type BuildWorkspaceCommitterDeps = {
extract: LlmExtractorConfig;
nerveRoot: string;
workflowName: string;
conventionalCommitScopeHint: string;
branchCheckoutExample: string;
};
function workspaceCommitterPrompt(threadId: string): string {
return `You are the committer agent. The coder finished with a passing build; your job is to branch, commit, and push.
function workspaceCommitterPrompt({
threadId,
nerveRoot,
workflowName,
conventionalCommitScopeHint,
branchCheckoutExample,
}: {
threadId: string;
nerveRoot: string;
workflowName: string;
conventionalCommitScopeHint: string;
branchCheckoutExample: string;
}): string {
return `You are the **committer** agent (Hermes) for the **${workflowName}** workflow. The coder finished with a passing build; you branch, commit, and push workspace changes.
## Context
1. Read the workflow thread: \`nerve thread show ${threadId}\`
2. Your git repository root is: \`${nerveRoot}\`\`cd\` there for all git commands.
## Steps (in order)
1. Run \`git status\`. There should be uncommitted changes from the coder. If there is nothing to commit, set **committed** to false and explain.
2. Create a short-lived branch (do not commit directly on the default branch if it would mix unrelated work):
- Prefer \`fix/<short-slug>\` or \`feat/<short-slug>\` with a lowercase hyphenated slug from the thread (planner/coder context).
- Example: \`${branchCheckoutExample}\`
3. \`git add -A\`
4. Write a **conventional commit** message summarizing what changed and why (scope may be \`${conventionalCommitScopeHint}\` or similar).
5. \`git commit -m "<message>"\` (use multiple \`-m\` if you need a body). Do **not** pass \`--author\` — always use the repo's local git config identity.
6. \`git push -u origin <branch-name>\`
1. Read the workflow thread: \`nerve thread show ${threadId}\` — understand what was planned, coded, and reviewed.
2. Run \`git status\`. If nothing to commit, set committed=false.
3. Create a feature branch: infer a good \`fix/<slug>\` or \`feat/<slug>\` name from the thread context.
4. \`git add -A\`
5. Write a conventional commit message based on the thread context.
6. \`git commit -m "<message>"\` — do NOT pass \`--author\`, use repo git config.
7. \`git push -u origin <branch>\`
**committed=true** only if branch was created, commit succeeded, and **push** succeeded.
@ -63,24 +35,11 @@ or
export function createWorkspaceCommitterRole(
adapter: AgentFn,
{
extract,
nerveRoot,
workflowName,
conventionalCommitScopeHint,
branchCheckoutExample,
}: BuildWorkspaceCommitterDeps,
extract: LlmExtractorConfig,
): Role<CommitterMeta> {
const innerRole = createRole(
adapter,
async (start: StartStep) =>
workspaceCommitterPrompt({
threadId: start.meta.threadId,
nerveRoot,
workflowName,
conventionalCommitScopeHint,
branchCheckoutExample,
}),
async (start: StartStep) => workspaceCommitterPrompt(start.meta.threadId),
committerMetaSchema,
extract,
);
@ -93,13 +52,8 @@ export function createWorkspaceCommitterRole(
};
}
const innerStart = {
...start,
meta: { ...start.meta, workdir: nerveRoot },
} as StartStep;
try {
return await innerRole(innerStart, _messages);
return await innerRole(start, _messages);
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
return {

View File

@ -28,13 +28,7 @@ export function createDevelopSenseWorkflow({
coder: createCoderRole(a('coder'), extract),
reviewer: createReviewerRole(a('reviewer'), extract, cwd),
tester: createTesterRole(a('tester'), extract, cwd),
committer: createWorkspaceCommitterRole(a('committer'), {
extract,
nerveRoot: cwd,
workflowName: "develop-sense",
conventionalCommitScopeHint: "sense",
branchCheckoutExample: "git checkout -b fix/sense-export-path",
}),
committer: createWorkspaceCommitterRole(a('committer'), extract),
};
return {

View File

@ -1,6 +1,5 @@
export {
createWorkspaceCommitterRole,
committerMetaSchema,
type BuildWorkspaceCommitterDeps,
type CommitterMeta,
} from "../../_shared/workspace-committer.js";

View File

@ -28,13 +28,7 @@ export function createDevelopWorkflowWorkflow({
coder: createCoderRole(a('coder'), extract),
reviewer: createReviewerRole(a('reviewer'), extract, nerveRoot),
tester: createTesterRole(a('tester'), extract, nerveRoot),
committer: createWorkspaceCommitterRole(a('committer'), {
extract,
nerveRoot,
workflowName: "develop-workflow",
conventionalCommitScopeHint: "workflow",
branchCheckoutExample: "git checkout -b feat/workflow-new-step",
}),
committer: createWorkspaceCommitterRole(a('committer'), extract),
};
return {

View File

@ -1,6 +1,5 @@
export {
createWorkspaceCommitterRole,
committerMetaSchema,
type BuildWorkspaceCommitterDeps,
type CommitterMeta,
} from "../../_shared/workspace-committer.js";

View File

@ -33,7 +33,7 @@ export function createSolveIssueWorkflow({
prepare: createPrepareRole(a("prepare"), extract),
plan: createPlanRole(a("plan"), { extract, nerveRoot }),
implement: createImplementRole(a("implement"), { extract, nerveRoot }),
committer: createCommitterRole(a("committer"), { extract, nerveRoot }),
committer: createCommitterRole(a("committer"), extract),
review: createReviewRole(a("review"), extract, nerveRoot),
test: createTestRole(a("test"), extract),
publish: createPublishRole(a("publish"), { extract, nerveRoot }),

View File

@ -3,7 +3,6 @@ import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils";
import { createRole, isDryRun } from "@uncaged/nerve-workflow-utils";
import { z } from "zod";
import { resolveRepoCwd } from "../../lib/repo-context.js";
import { committerPrompt } from "./prompt.js";
export const committerMetaSchema = z.object({
@ -13,35 +12,18 @@ export const committerMetaSchema = z.object({
});
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
export type CreateCommitterRoleDeps = {
extract: LlmExtractorConfig;
nerveRoot: string;
};
export function createCommitterRole(
adapter: AgentFn,
{ extract, nerveRoot }: CreateCommitterRoleDeps,
extract: LlmExtractorConfig,
): Role<CommitterMeta> {
const innerRole = createRole(
adapter,
async (start: StartStep) =>
committerPrompt({
threadId: start.meta.threadId,
nerveRoot,
}),
async (start: StartStep) => committerPrompt({ threadId: start.meta.threadId }),
committerMetaSchema,
extract,
);
return async (start: StartStep, messages: WorkflowMessage[]): Promise<RoleResult<CommitterMeta>> => {
const cwd = resolveRepoCwd(messages);
if (cwd === null) {
return {
content: "committer cannot run: missing repo path in thread markers",
meta: { committed: false },
};
}
if (isDryRun(start)) {
return {
content: "[dry-run] committer skipped (no git branch/commit/push)",
@ -49,13 +31,8 @@ export function createCommitterRole(
};
}
const innerStart = {
...start,
meta: { ...start.meta, workdir: cwd },
} as StartStep;
try {
return await innerRole(innerStart, messages);
return await innerRole(start, messages);
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
return {

View File

@ -1,40 +1,21 @@
export function committerPrompt({
threadId,
nerveRoot,
}: {
threadId: string;
nerveRoot: string;
}): string {
return `You are the **committer** agent (Hermes). The **implement** step finished with a passing build; your job is to put those changes on a feature branch and push to **origin**.
export 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.
## Context
- Read the full workflow thread: \`nerve thread show ${threadId}\`
- Optional workspace tone: \`cat ${nerveRoot}/CONVENTIONS.md\`
## Find repo and issue markers
In the thread, locate \`---SOLVE_ISSUE_PARSE---\` and \`---SOLVE_ISSUE_REPO---\`. From them you need:
- Issue **number** and **title** (from PARSE; title for the branch slug)
- Repo checkout **path** (from REPO \`path\`) — this is your working copy; your shell cwd should be this directory.
## Steps (in order)
1. \`cd\` to the repo **path** from SOLVE_ISSUE_REPO.
2. Run \`git rev-parse --abbrev-ref HEAD\` and compare with **defaultBranch** from SOLVE_ISSUE_REPO. 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 with nothing to commit when you expected changes, set **committed** to false and explain (avoids empty PRs from wrong state).
3. Run \`git status\`. There should be **uncommitted** changes from implement. If the tree is clean with nothing to commit, set **committed** to false and explain.
4. Create a feature branch (do not work on the default branch directly):
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.
- **number** from SOLVE_ISSUE_PARSE.
- **slug**: lowercase, hyphens only, short (from issue title words).
- Example: \`git checkout -b fix/42-auth-timeout\`
5. \`git add -A\`
6. Write a **conventional commit** message (e.g. \`fix(scope): summary\` or \`feat(scope): summary\`) describing **what** changed and **why**, using the thread (plan + implement context).
7. \`git commit -m "<message>"\` — use a single \`-m\` for a one-line message, or multiple \`-m\` for body paragraphs if needed. Do **not** pass \`--author\` — always use the repo's local git config identity.
8. \`git push -u origin <branch-name>\`
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 you created the branch, committed successfully, and **push** succeeded.
**committed=true** only if branch was created, commit succeeded, and **push** succeeded.
End your reply with a JSON line:
\`\`\`json