Merge pull request 'refactor: simplify workspace committer — infer from thread' (#18) from refactor/17-simplify-committer into master
This commit is contained in:
commit
59b8f033ba
@ -10,44 +10,16 @@ export const committerMetaSchema = z.object({
|
|||||||
});
|
});
|
||||||
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
|
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
|
||||||
|
|
||||||
export type BuildWorkspaceCommitterDeps = {
|
function workspaceCommitterPrompt(threadId: string): string {
|
||||||
extract: LlmExtractorConfig;
|
return `You are the committer agent. The coder finished with a passing build; your job is to branch, commit, and push.
|
||||||
nerveRoot: string;
|
|
||||||
workflowName: string;
|
|
||||||
conventionalCommitScopeHint: string;
|
|
||||||
branchCheckoutExample: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
function workspaceCommitterPrompt({
|
1. Read the workflow thread: \`nerve thread show ${threadId}\` — understand what was planned, coded, and reviewed.
|
||||||
threadId,
|
2. Run \`git status\`. If nothing to commit, set committed=false.
|
||||||
nerveRoot,
|
3. Create a feature branch: infer a good \`fix/<slug>\` or \`feat/<slug>\` name from the thread context.
|
||||||
workflowName,
|
4. \`git add -A\`
|
||||||
conventionalCommitScopeHint,
|
5. Write a conventional commit message based on the thread context.
|
||||||
branchCheckoutExample,
|
6. \`git commit -m "<message>"\` — do NOT pass \`--author\`, use repo git config.
|
||||||
}: {
|
7. \`git push -u origin <branch>\`
|
||||||
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>\`
|
|
||||||
|
|
||||||
**committed=true** only if branch was created, commit succeeded, and **push** succeeded.
|
**committed=true** only if branch was created, commit succeeded, and **push** succeeded.
|
||||||
|
|
||||||
@ -63,24 +35,11 @@ or
|
|||||||
|
|
||||||
export function createWorkspaceCommitterRole(
|
export function createWorkspaceCommitterRole(
|
||||||
adapter: AgentFn,
|
adapter: AgentFn,
|
||||||
{
|
extract: LlmExtractorConfig,
|
||||||
extract,
|
|
||||||
nerveRoot,
|
|
||||||
workflowName,
|
|
||||||
conventionalCommitScopeHint,
|
|
||||||
branchCheckoutExample,
|
|
||||||
}: BuildWorkspaceCommitterDeps,
|
|
||||||
): Role<CommitterMeta> {
|
): Role<CommitterMeta> {
|
||||||
const innerRole = createRole(
|
const innerRole = createRole(
|
||||||
adapter,
|
adapter,
|
||||||
async (start: StartStep) =>
|
async (start: StartStep) => workspaceCommitterPrompt(start.meta.threadId),
|
||||||
workspaceCommitterPrompt({
|
|
||||||
threadId: start.meta.threadId,
|
|
||||||
nerveRoot,
|
|
||||||
workflowName,
|
|
||||||
conventionalCommitScopeHint,
|
|
||||||
branchCheckoutExample,
|
|
||||||
}),
|
|
||||||
committerMetaSchema,
|
committerMetaSchema,
|
||||||
extract,
|
extract,
|
||||||
);
|
);
|
||||||
@ -93,13 +52,8 @@ export function createWorkspaceCommitterRole(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const innerStart = {
|
|
||||||
...start,
|
|
||||||
meta: { ...start.meta, workdir: nerveRoot },
|
|
||||||
} as StartStep;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await innerRole(innerStart, _messages);
|
return await innerRole(start, _messages);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = e instanceof Error ? e.message : String(e);
|
const msg = e instanceof Error ? e.message : String(e);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -28,13 +28,7 @@ export function createDevelopSenseWorkflow({
|
|||||||
coder: createCoderRole(a('coder'), extract),
|
coder: createCoderRole(a('coder'), extract),
|
||||||
reviewer: createReviewerRole(a('reviewer'), extract, cwd),
|
reviewer: createReviewerRole(a('reviewer'), extract, cwd),
|
||||||
tester: createTesterRole(a('tester'), extract, cwd),
|
tester: createTesterRole(a('tester'), extract, cwd),
|
||||||
committer: createWorkspaceCommitterRole(a('committer'), {
|
committer: createWorkspaceCommitterRole(a('committer'), extract),
|
||||||
extract,
|
|
||||||
nerveRoot: cwd,
|
|
||||||
workflowName: "develop-sense",
|
|
||||||
conventionalCommitScopeHint: "sense",
|
|
||||||
branchCheckoutExample: "git checkout -b fix/sense-export-path",
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
export {
|
export {
|
||||||
createWorkspaceCommitterRole,
|
createWorkspaceCommitterRole,
|
||||||
committerMetaSchema,
|
committerMetaSchema,
|
||||||
type BuildWorkspaceCommitterDeps,
|
|
||||||
type CommitterMeta,
|
type CommitterMeta,
|
||||||
} from "../../_shared/workspace-committer.js";
|
} from "../../_shared/workspace-committer.js";
|
||||||
|
|||||||
@ -28,13 +28,7 @@ export function createDevelopWorkflowWorkflow({
|
|||||||
coder: createCoderRole(a('coder'), extract),
|
coder: createCoderRole(a('coder'), extract),
|
||||||
reviewer: createReviewerRole(a('reviewer'), extract, nerveRoot),
|
reviewer: createReviewerRole(a('reviewer'), extract, nerveRoot),
|
||||||
tester: createTesterRole(a('tester'), extract, nerveRoot),
|
tester: createTesterRole(a('tester'), extract, nerveRoot),
|
||||||
committer: createWorkspaceCommitterRole(a('committer'), {
|
committer: createWorkspaceCommitterRole(a('committer'), extract),
|
||||||
extract,
|
|
||||||
nerveRoot,
|
|
||||||
workflowName: "develop-workflow",
|
|
||||||
conventionalCommitScopeHint: "workflow",
|
|
||||||
branchCheckoutExample: "git checkout -b feat/workflow-new-step",
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
export {
|
export {
|
||||||
createWorkspaceCommitterRole,
|
createWorkspaceCommitterRole,
|
||||||
committerMetaSchema,
|
committerMetaSchema,
|
||||||
type BuildWorkspaceCommitterDeps,
|
|
||||||
type CommitterMeta,
|
type CommitterMeta,
|
||||||
} from "../../_shared/workspace-committer.js";
|
} from "../../_shared/workspace-committer.js";
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export function createSolveIssueWorkflow({
|
|||||||
prepare: createPrepareRole(a("prepare"), extract),
|
prepare: createPrepareRole(a("prepare"), extract),
|
||||||
plan: createPlanRole(a("plan"), { extract, nerveRoot }),
|
plan: createPlanRole(a("plan"), { extract, nerveRoot }),
|
||||||
implement: createImplementRole(a("implement"), { 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),
|
review: createReviewRole(a("review"), extract, nerveRoot),
|
||||||
test: createTestRole(a("test"), extract),
|
test: createTestRole(a("test"), extract),
|
||||||
publish: createPublishRole(a("publish"), { extract, nerveRoot }),
|
publish: createPublishRole(a("publish"), { extract, nerveRoot }),
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import type { LlmExtractorConfig } from "@uncaged/nerve-workflow-utils";
|
|||||||
import { createRole, isDryRun } from "@uncaged/nerve-workflow-utils";
|
import { createRole, isDryRun } from "@uncaged/nerve-workflow-utils";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { resolveRepoCwd } from "../../lib/repo-context.js";
|
|
||||||
import { committerPrompt } from "./prompt.js";
|
import { committerPrompt } from "./prompt.js";
|
||||||
|
|
||||||
export const committerMetaSchema = z.object({
|
export const committerMetaSchema = z.object({
|
||||||
@ -13,35 +12,18 @@ export const committerMetaSchema = z.object({
|
|||||||
});
|
});
|
||||||
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
|
export type CommitterMeta = z.infer<typeof committerMetaSchema>;
|
||||||
|
|
||||||
export type CreateCommitterRoleDeps = {
|
|
||||||
extract: LlmExtractorConfig;
|
|
||||||
nerveRoot: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function createCommitterRole(
|
export function createCommitterRole(
|
||||||
adapter: AgentFn,
|
adapter: AgentFn,
|
||||||
{ extract, nerveRoot }: CreateCommitterRoleDeps,
|
extract: LlmExtractorConfig,
|
||||||
): Role<CommitterMeta> {
|
): Role<CommitterMeta> {
|
||||||
const innerRole = createRole(
|
const innerRole = createRole(
|
||||||
adapter,
|
adapter,
|
||||||
async (start: StartStep) =>
|
async (start: StartStep) => committerPrompt({ threadId: start.meta.threadId }),
|
||||||
committerPrompt({
|
|
||||||
threadId: start.meta.threadId,
|
|
||||||
nerveRoot,
|
|
||||||
}),
|
|
||||||
committerMetaSchema,
|
committerMetaSchema,
|
||||||
extract,
|
extract,
|
||||||
);
|
);
|
||||||
|
|
||||||
return async (start: StartStep, messages: WorkflowMessage[]): Promise<RoleResult<CommitterMeta>> => {
|
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)) {
|
if (isDryRun(start)) {
|
||||||
return {
|
return {
|
||||||
content: "[dry-run] committer skipped (no git branch/commit/push)",
|
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 {
|
try {
|
||||||
return await innerRole(innerStart, messages);
|
return await innerRole(start, messages);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = e instanceof Error ? e.message : String(e);
|
const msg = e instanceof Error ? e.message : String(e);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,40 +1,21 @@
|
|||||||
export function committerPrompt({
|
export function committerPrompt({ threadId }: { threadId: string }): string {
|
||||||
threadId,
|
return `You are the committer agent. The **implement** step finished with a passing build; your job is to branch, commit, and push.
|
||||||
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**.
|
|
||||||
|
|
||||||
## Context
|
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**.
|
||||||
- Read the full workflow thread: \`nerve thread show ${threadId}\`
|
3. \`cd\` to the repo **path** from the markers. Optionally read \`CONVENTIONS.md\` in that repo root if present.
|
||||||
- Optional workspace tone: \`cat ${nerveRoot}/CONVENTIONS.md\`
|
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.
|
||||||
## Find repo and issue markers
|
6. Create a feature branch (do not commit directly on the default branch if it would mix unrelated work):
|
||||||
|
|
||||||
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):
|
|
||||||
- Name: \`fix/<number>-<short-slug>\` for fixes, or \`feat/<number>-<short-slug>\` if the issue is clearly a feature.
|
- 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).
|
- **slug**: lowercase, hyphens only, short (from issue title words).
|
||||||
- Example: \`git checkout -b fix/42-auth-timeout\`
|
- Example: \`git checkout -b fix/42-auth-timeout\`
|
||||||
5. \`git add -A\`
|
7. \`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).
|
8. Write a **conventional commit** message describing what changed and why, using the thread 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.
|
9. \`git commit -m "<message>"\` — do NOT pass \`--author\`, use repo git config.
|
||||||
8. \`git push -u origin <branch-name>\`
|
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:
|
End your reply with a JSON line:
|
||||||
\`\`\`json
|
\`\`\`json
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user