feat: project-level prompts for metadata generation (#836)
* feat(server): project-level prompts for metadata generation Add `metadataGeneration` config to `paseo.json` so projects can customize the four LLM-generated metadata strings — agent title, worktree branch name, commit message, and pull request title+body. Each entry takes an `instructions` string that gets injected as a `<user-instructions>` block between the default rules and the load-bearing JSON format contract, with wrapper text saying user instructions override defaults. Missing/empty/invalid config keeps every prompt byte-identical to today. * refactor(server): centralize project metadata prompt building Three near-identical readers and four gate-then-wrap blocks collapsed into one buildMetadataPrompt helper. wrapWithUserInstructions tightened to require a non-empty string; its misleading empty fallback is gone. * feat(app): edit metadata generation prompts in project settings Adds four textareas (agent title, branch name, commit message, pull request) under project settings, modeled on the existing setup/teardown pattern. Round-trips through paseo.json preserving unknown sibling fields at both the metadataGeneration and entry level.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { readPaseoConfigJson } from "./paseo-config-file.js";
|
||||
import { PaseoConfigSchema } from "./paseo-config-schema.js";
|
||||
import { wrapWithUserInstructions } from "./wrap-user-instructions.js";
|
||||
|
||||
export type MetadataConfigKey = "agentTitle" | "branchName" | "commitMessage" | "pullRequest";
|
||||
|
||||
export interface RepoRootResolver {
|
||||
resolveRepoRoot: (cwd: string) => Promise<string>;
|
||||
}
|
||||
|
||||
export interface BuildMetadataPromptOptions {
|
||||
cwd: string;
|
||||
configKey: MetadataConfigKey;
|
||||
before: string;
|
||||
after: string;
|
||||
trailing?: string;
|
||||
workspaceGitService?: RepoRootResolver;
|
||||
}
|
||||
|
||||
export async function buildMetadataPrompt(options: BuildMetadataPromptOptions): Promise<string> {
|
||||
const instructions = await readProjectMetadataInstructions(options);
|
||||
const head = isNonEmptyString(instructions)
|
||||
? wrapWithUserInstructions(options.before, instructions, options.after)
|
||||
: `${options.before}\n${options.after}`;
|
||||
return options.trailing ? `${head}\n\n${options.trailing}` : head;
|
||||
}
|
||||
|
||||
async function readProjectMetadataInstructions(
|
||||
options: Pick<BuildMetadataPromptOptions, "cwd" | "configKey" | "workspaceGitService">,
|
||||
): Promise<string | undefined> {
|
||||
if (!options.workspaceGitService) {
|
||||
return undefined;
|
||||
}
|
||||
try {
|
||||
const repoRoot = await options.workspaceGitService.resolveRepoRoot(options.cwd);
|
||||
const json = readPaseoConfigJson(repoRoot);
|
||||
const config = PaseoConfigSchema.parse(json);
|
||||
return config.metadataGeneration?.[options.configKey]?.instructions;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function isNonEmptyString(value: unknown): value is string {
|
||||
return typeof value === "string" && value.trim() !== "";
|
||||
}
|
||||
Reference in New Issue
Block a user