The previous commit incorrectly deleted all workflows. Only restart-gateway should be removed (replaced by direct shell trigger). Other workflows (solve-issue, extract-knowledge, develop-sense, develop-workflow) are CLI-triggered and independent of sense coupling.
74 lines
2.9 KiB
TypeScript
74 lines
2.9 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 preparePrompt({ threadId }: { threadId: string }): string {
|
|
return `You are the **prepare** agent. You ensure the target repository is ready for work.
|
|
|
|
Read prior messages / thread for issue markers: \`nerve thread show ${threadId}\`
|
|
|
|
## Goal
|
|
|
|
Find **owner**, **repo**, and **host** from \`---SOLVE_ISSUE_PARSE---\` in the thread (from read-issue).
|
|
|
|
Check the **initial user prompt** (the trigger message) for a local repo path. The user may specify it like:
|
|
- \`--repo /path/to/repo\`
|
|
- \`repo: /path/to/repo\`
|
|
- or just mention an absolute path to the local clone
|
|
|
|
## Steps
|
|
|
|
### If a local path is provided in the trigger prompt:
|
|
1. Verify \`<path>/.git\` exists — if not, fail with \`ready: false\`
|
|
2. \`cd "<path>" && git fetch --all\`
|
|
3. Ensure working tree clean: if \`git status --porcelain\` is non-empty, \`git stash push -u -m "solve-issue stash"\`
|
|
4. Detect default branch (\`main\` or \`master\`) and \`git checkout <default> && git pull --ff-only\`
|
|
5. Use this path as REPOPATH
|
|
|
|
### If no local path is provided:
|
|
1. Let \`REPOPATH=$HOME/Code/<owner>/<repo>\` (expand \`$HOME\`)
|
|
2. \`mkdir -p "$HOME/Code/<owner>"\`
|
|
3. If \`REPOPATH/.git\` is missing: \`git clone https://<host>/<owner>/<repo>.git "$REPOPATH"\`
|
|
Else: \`cd "$REPOPATH" && git fetch --all && git pull --ff-only\`
|
|
4. Ensure working tree clean: if \`git status --porcelain\` is non-empty, \`git stash push -u -m "solve-issue stash"\`
|
|
5. Detect default branch and \`git checkout <default>\`
|
|
|
|
### Then (both paths):
|
|
6. Detect package manager: \`pnpm-lock.yaml\` → pnpm, \`yarn.lock\` → yarn, \`package-lock.json\` → npm; run install (\`pnpm install --no-frozen-lockfile\` / \`npm ci\` or \`npm install\` / \`yarn\`).
|
|
7. If \`package.json\` has a \`build\` script, run the build (\`pnpm build\`, etc.) and fix nothing — only verify baseline passes.
|
|
|
|
## Required marker block
|
|
|
|
Emit **exactly**:
|
|
\`\`\`
|
|
---SOLVE_ISSUE_REPO---
|
|
path: <absolute path to REPOPATH>
|
|
defaultBranch: <main or master>
|
|
packageManager: <pnpm|npm|yarn>
|
|
---
|
|
\`\`\`
|
|
|
|
End with:
|
|
\`\`\`json
|
|
{ "ready": true }
|
|
\`\`\`
|
|
or \`{ "ready": false }\` if the repo is invalid, or install/build baseline failed.
|
|
|
|
**ready=true** only when the repo exists at \`path\`, is clean, dependencies installed, and baseline build succeeded (or no build script).`;
|
|
}
|
|
|
|
export const prepareMetaSchema = z.object({
|
|
ready: z.boolean().describe("true if repo is ready and baseline build ok"),
|
|
});
|
|
export type PrepareMeta = z.infer<typeof prepareMetaSchema>;
|
|
|
|
export function createPrepareRole(adapter: AgentFn, extract: LlmExtractorConfig): Role<PrepareMeta> {
|
|
return createRole(
|
|
adapter,
|
|
async (ctx: ThreadContext) => preparePrompt({ threadId: ctx.start.meta.threadId }),
|
|
prepareMetaSchema,
|
|
extract,
|
|
);
|
|
}
|