- Extract follow-up submission resolution into `resolvePlanFollowUpSubmission` - Send implementation prompt in default mode when follow-up text is empty - Keep composer mode toggle synced when starting same-thread implementation turns - Add tests for follow-up submission behavior
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
export function proposedPlanTitle(planMarkdown: string): string | null {
|
|
const heading = planMarkdown.match(/^\s{0,3}#{1,6}\s+(.+)$/m)?.[1]?.trim();
|
|
return heading && heading.length > 0 ? heading : null;
|
|
}
|
|
|
|
function sanitizePlanFileSegment(input: string): string {
|
|
const sanitized = input
|
|
.toLowerCase()
|
|
.replace(/[`'".,!?()[\]{}]+/g, "")
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
.replace(/^-+|-+$/g, "");
|
|
return sanitized.length > 0 ? sanitized : "plan";
|
|
}
|
|
|
|
export function buildPlanImplementationPrompt(planMarkdown: string): string {
|
|
return `PLEASE IMPLEMENT THIS PLAN:\n${planMarkdown.trim()}`;
|
|
}
|
|
|
|
export function resolvePlanFollowUpSubmission(input: {
|
|
draftText: string;
|
|
planMarkdown: string;
|
|
}): {
|
|
text: string;
|
|
interactionMode: "default" | "plan";
|
|
} {
|
|
const trimmedDraftText = input.draftText.trim();
|
|
if (trimmedDraftText.length > 0) {
|
|
return {
|
|
text: trimmedDraftText,
|
|
interactionMode: "plan",
|
|
};
|
|
}
|
|
|
|
return {
|
|
text: buildPlanImplementationPrompt(input.planMarkdown),
|
|
interactionMode: "default",
|
|
};
|
|
}
|
|
|
|
export function buildPlanImplementationThreadTitle(planMarkdown: string): string {
|
|
const title = proposedPlanTitle(planMarkdown);
|
|
if (!title) {
|
|
return "Implement plan";
|
|
}
|
|
return `Implement ${title}`;
|
|
}
|
|
|
|
export function buildProposedPlanMarkdownFilename(planMarkdown: string): string {
|
|
const title = proposedPlanTitle(planMarkdown);
|
|
return `${sanitizePlanFileSegment(title ?? "plan")}.md`;
|
|
}
|