refactor: deduplicate dispatchDoctorHeal — keep single copy in commands-handlers.ts (#1211)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
TÂCHES 2026-03-18 12:05:41 -06:00 committed by GitHub
parent 93edbc20d2
commit 3a0999c6db
3 changed files with 21 additions and 22 deletions

View file

@ -176,7 +176,7 @@ export async function postUnitPreVerification(pctx: PostUnitContext): Promise<"d
);
try {
const { formatDoctorIssuesForPrompt, formatDoctorReport } = await import("./doctor.js");
const { dispatchDoctorHeal } = await import("./commands.js");
const { dispatchDoctorHeal } = await import("./commands-handlers.js");
const actionable = report.issues.filter(i => i.severity === "error");
const reportText = formatDoctorReport(report, { scope: doctorScope, includeWarnings: true });
const structuredIssues = formatDoctorIssuesForPrompt(actionable);

View file

@ -19,7 +19,26 @@ import {
filterDoctorIssues,
} from "./doctor.js";
import { isAutoActive } from "./auto.js";
import { projectRoot, dispatchDoctorHeal } from "./commands.js";
import { projectRoot } from "./commands.js";
import { loadPrompt } from "./prompt-loader.js";
export function dispatchDoctorHeal(pi: ExtensionAPI, scope: string | undefined, reportText: string, structuredIssues: string): void {
const workflowPath = process.env.GSD_WORKFLOW_PATH ?? join(process.env.HOME ?? "~", ".pi", "GSD-WORKFLOW.md");
const workflow = readFileSync(workflowPath, "utf-8");
const prompt = loadPrompt("doctor-heal", {
doctorSummary: reportText,
structuredIssues,
scopeLabel: scope ?? "active milestone / blocking scope",
doctorCommandSuffix: scope ? ` ${scope}` : "",
});
const content = `Read the following GSD workflow protocol and execute exactly.\n\n${workflow}\n\n## Your Task\n\n${prompt}`;
pi.sendMessage(
{ customType: "gsd-doctor-heal", content, display: false },
{ triggerTurn: true },
);
}
export async function handleDoctor(args: string, ctx: ExtensionCommandContext, pi: ExtensionAPI): Promise<void> {
const trimmed = args.trim();

View file

@ -22,8 +22,6 @@ import {
getProjectGSDPreferencesPath,
loadEffectiveGSDPreferences,
} from "./preferences.js";
import { loadPrompt } from "./prompt-loader.js";
import { handleRemote } from "../remote-questions/mod.js";
import { handleQuick } from "./quick.js";
import { handleHistory } from "./history.js";
@ -47,24 +45,6 @@ import { handleDoctor, handleSteer, handleCapture, handleTriage, handleKnowledge
import { handleLogs } from "./commands-logs.js";
export function dispatchDoctorHeal(pi: ExtensionAPI, scope: string | undefined, reportText: string, structuredIssues: string): void {
const workflowPath = process.env.GSD_WORKFLOW_PATH ?? join(process.env.HOME ?? "~", ".pi", "GSD-WORKFLOW.md");
const workflow = readFileSync(workflowPath, "utf-8");
const prompt = loadPrompt("doctor-heal", {
doctorSummary: reportText,
structuredIssues,
scopeLabel: scope ?? "active milestone / blocking scope",
doctorCommandSuffix: scope ? ` ${scope}` : "",
});
const content = `Read the following GSD workflow protocol and execute exactly.\n\n${workflow}\n\n## Your Task\n\n${prompt}`;
pi.sendMessage(
{ customType: "gsd-doctor-heal", content, display: false },
{ triggerTurn: true },
);
}
/** Resolve the effective project root, accounting for worktree paths. */
export function projectRoot(): string {
const root = resolveProjectRoot(process.cwd());