From 3a0999c6dbc6a4b1fe9564c950aa652c68939ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=82CHES?= Date: Wed, 18 Mar 2026 12:05:41 -0600 Subject: [PATCH] =?UTF-8?q?refactor:=20deduplicate=20dispatchDoctorHeal=20?= =?UTF-8?q?=E2=80=94=20keep=20single=20copy=20in=20commands-handlers.ts=20?= =?UTF-8?q?(#1211)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Claude Opus 4.6 (1M context) --- .../extensions/gsd/auto-post-unit.ts | 2 +- .../extensions/gsd/commands-handlers.ts | 21 ++++++++++++++++++- src/resources/extensions/gsd/commands.ts | 20 ------------------ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/resources/extensions/gsd/auto-post-unit.ts b/src/resources/extensions/gsd/auto-post-unit.ts index ab6e5e9a6..f3ee32961 100644 --- a/src/resources/extensions/gsd/auto-post-unit.ts +++ b/src/resources/extensions/gsd/auto-post-unit.ts @@ -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); diff --git a/src/resources/extensions/gsd/commands-handlers.ts b/src/resources/extensions/gsd/commands-handlers.ts index a1c1ae9f9..addd2730a 100644 --- a/src/resources/extensions/gsd/commands-handlers.ts +++ b/src/resources/extensions/gsd/commands-handlers.ts @@ -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 { const trimmed = args.trim(); diff --git a/src/resources/extensions/gsd/commands.ts b/src/resources/extensions/gsd/commands.ts index a50b4d1b4..08c6515b4 100644 --- a/src/resources/extensions/gsd/commands.ts +++ b/src/resources/extensions/gsd/commands.ts @@ -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());