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:
@@ -10,6 +10,13 @@ function emptyDraft(): ProjectConfigDraft {
|
||||
teardownText: "",
|
||||
teardownOriginalKind: "missing",
|
||||
scripts: [],
|
||||
metadataPrompts: {
|
||||
agentTitle: "",
|
||||
branchName: "",
|
||||
commitMessage: "",
|
||||
pullRequest: "",
|
||||
},
|
||||
metadataGenerationBase: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -210,6 +217,100 @@ describe("applyDraftToConfig", () => {
|
||||
expect(tunnel.port).toBe("auto");
|
||||
});
|
||||
|
||||
it("reads metadata prompt instructions for all four keys", () => {
|
||||
const draft = configToDraft({
|
||||
metadataGeneration: {
|
||||
agentTitle: { instructions: "Use mb/." },
|
||||
branchName: { instructions: "feat/<slug>" },
|
||||
commitMessage: { instructions: "Conventional commits." },
|
||||
pullRequest: { instructions: "Include risk notes." },
|
||||
},
|
||||
});
|
||||
expect(draft.metadataPrompts).toEqual({
|
||||
agentTitle: "Use mb/.",
|
||||
branchName: "feat/<slug>",
|
||||
commitMessage: "Conventional commits.",
|
||||
pullRequest: "Include risk notes.",
|
||||
});
|
||||
});
|
||||
|
||||
it("defaults metadata prompts to empty strings when not present", () => {
|
||||
const draft = configToDraft({
|
||||
metadataGeneration: { agentTitle: { instructions: "Use mb/." } },
|
||||
});
|
||||
expect(draft.metadataPrompts).toEqual({
|
||||
agentTitle: "Use mb/.",
|
||||
branchName: "",
|
||||
commitMessage: "",
|
||||
pullRequest: "",
|
||||
});
|
||||
});
|
||||
|
||||
it("writes only metadata prompt entries with non-empty text", () => {
|
||||
const base: PaseoConfigRaw = {};
|
||||
const draft = configToDraft(base);
|
||||
draft.metadataPrompts.agentTitle = "Use mb/.";
|
||||
draft.metadataPrompts.commitMessage = "Conventional commits.";
|
||||
const next = applyDraftToConfig({ draft, base });
|
||||
expect(next.metadataGeneration).toEqual({
|
||||
agentTitle: { instructions: "Use mb/." },
|
||||
commitMessage: { instructions: "Conventional commits." },
|
||||
});
|
||||
});
|
||||
|
||||
it("drops the metadataGeneration field when all prompts are empty", () => {
|
||||
const base = PaseoConfigRawSchema.parse({
|
||||
metadataGeneration: {
|
||||
agentTitle: { instructions: "Use mb/." },
|
||||
},
|
||||
});
|
||||
const draft = configToDraft(base);
|
||||
draft.metadataPrompts.agentTitle = "";
|
||||
const next = applyDraftToConfig({ draft, base });
|
||||
expect(next.metadataGeneration).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves unknown sibling fields inside metadataGeneration on round-trip", () => {
|
||||
const base = PaseoConfigRawSchema.parse({
|
||||
metadataGeneration: {
|
||||
agentTitle: { instructions: "Use mb/." },
|
||||
futureField: 42,
|
||||
},
|
||||
});
|
||||
const draft = configToDraft(base);
|
||||
draft.metadataPrompts.agentTitle = "Use prefix mb/ on titles.";
|
||||
const next = applyDraftToConfig({ draft, base });
|
||||
const metadata = next.metadataGeneration as Record<string, unknown>;
|
||||
expect(metadata.agentTitle).toEqual({ instructions: "Use prefix mb/ on titles." });
|
||||
expect(metadata.futureField).toBe(42);
|
||||
});
|
||||
|
||||
it("preserves unknown fields inside a metadata prompt entry on round-trip", () => {
|
||||
const base = PaseoConfigRawSchema.parse({
|
||||
metadataGeneration: {
|
||||
agentTitle: { instructions: "Use mb/.", model: "haiku" },
|
||||
},
|
||||
});
|
||||
const draft = configToDraft(base);
|
||||
draft.metadataPrompts.agentTitle = "Updated.";
|
||||
const next = applyDraftToConfig({ draft, base });
|
||||
const metadata = next.metadataGeneration as Record<string, unknown>;
|
||||
expect(metadata.agentTitle).toEqual({ instructions: "Updated.", model: "haiku" });
|
||||
});
|
||||
|
||||
it("clears instructions but preserves unknown sibling fields when text becomes empty", () => {
|
||||
const base = PaseoConfigRawSchema.parse({
|
||||
metadataGeneration: {
|
||||
agentTitle: { instructions: "Use mb/.", model: "haiku" },
|
||||
},
|
||||
});
|
||||
const draft = configToDraft(base);
|
||||
draft.metadataPrompts.agentTitle = "";
|
||||
const next = applyDraftToConfig({ draft, base });
|
||||
const metadata = next.metadataGeneration as Record<string, unknown>;
|
||||
expect(metadata.agentTitle).toEqual({ model: "haiku" });
|
||||
});
|
||||
|
||||
it("drops scripts with an empty name and removes scripts no longer present in the draft", () => {
|
||||
const base = PaseoConfigRawSchema.parse({
|
||||
scripts: {
|
||||
|
||||
Reference in New Issue
Block a user