refactor: extract createGitService() factory, remove debug logs (#1278)

This commit is contained in:
TÂCHES 2026-03-18 17:23:26 -06:00 committed by GitHub
parent a647a2fcb6
commit 1e4ea36f1f
5 changed files with 29 additions and 26 deletions

View file

@ -38,7 +38,7 @@ import {
import { selfHealRuntimeRecords } from "./auto-recovery.js";
import { ensureGitignore, untrackRuntimeFiles } from "./gitignore.js";
import { nativeIsRepo, nativeInit } from "./native-git-bridge.js";
import { GitServiceImpl } from "./git-service.js";
import { createGitService } from "./git-service.js";
import {
captureIntegrationBranch,
detectWorktreeName,
@ -129,7 +129,7 @@ export async function bootstrapAutoSession(
}
// Initialize GitServiceImpl
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
// Check for crash from previous session (use both old and new lock data)
const crashLock = readCrashLock(base);
@ -330,12 +330,12 @@ export async function bootstrapAutoSession(
if (existingWtPath) {
const wtPath = enterAutoWorktree(base, s.currentMilestoneId);
s.basePath = wtPath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(`Entered auto-worktree at ${wtPath}`, "info");
} else {
const wtPath = createAutoWorktree(base, s.currentMilestoneId);
s.basePath = wtPath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(`Created auto-worktree at ${wtPath}`, "info");
}
registerSigtermHandler(s.originalBasePath);

View file

@ -118,7 +118,7 @@ import {
parseSliceBranch,
setActiveMilestoneId,
} from "./worktree.js";
import { GitServiceImpl, type TaskCommitContext } from "./git-service.js";
import { createGitService, type TaskCommitContext } from "./git-service.js";
import { getPriorSliceCompletionBlocker } from "./dispatch-guard.js";
import { formatGitError } from "./git-self-heal.js";
import {
@ -462,7 +462,7 @@ export async function stopAuto(ctx?: ExtensionContext, pi?: ExtensionAPI, reason
try { autoCommitCurrentBranch(s.basePath, "stop", s.currentMilestoneId); } catch (e) { debugLog("stop-auto-commit-failed", { error: e instanceof Error ? e.message : String(e) }); }
teardownAutoWorktree(s.originalBasePath, s.currentMilestoneId, { preserveBranch: true });
s.basePath = s.originalBasePath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx?.ui.notify("Exited auto-worktree (branch preserved for resume).", "info");
} catch (err) {
ctx?.ui.notify(
@ -626,12 +626,12 @@ export async function startAuto(
if (existingWtPath) {
const wtPath = enterAutoWorktree(s.originalBasePath, s.currentMilestoneId);
s.basePath = wtPath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(`Re-entered auto-worktree at ${wtPath}`, "info");
} else {
const wtPath = createAutoWorktree(s.originalBasePath, s.currentMilestoneId);
s.basePath = wtPath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(`Recreated auto-worktree at ${wtPath}`, "info");
}
} catch (err) {
@ -1124,7 +1124,7 @@ async function dispatchNextUnit(
}
s.basePath = s.originalBasePath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
invalidateAllCaches();
state = await deriveState(s.basePath);
@ -1136,7 +1136,7 @@ async function dispatchNextUnit(
try {
const wtPath = createAutoWorktree(s.basePath, mid);
s.basePath = wtPath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(`Created auto-worktree for ${mid} at ${wtPath}`, "info");
} catch (err) {
ctx.ui.notify(
@ -1176,7 +1176,7 @@ async function dispatchNextUnit(
const roadmapContent = readFileSync(roadmapPath, "utf-8");
const mergeResult = mergeMilestoneToMain(s.originalBasePath, s.currentMilestoneId, roadmapContent);
s.basePath = s.originalBasePath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(
`Milestone ${ s.currentMilestoneId } merged to main.${mergeResult.pushed ? " Pushed to remote." : ""}`,
"info",
@ -1201,7 +1201,7 @@ async function dispatchNextUnit(
if (roadmapPath) {
const roadmapContent = readFileSync(roadmapPath, "utf-8");
const mergeResult = mergeMilestoneToMain(s.basePath, s.currentMilestoneId, roadmapContent);
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(
`Milestone ${ s.currentMilestoneId } merged (branch mode).${mergeResult.pushed ? " Pushed to remote." : ""}`,
"info",
@ -1279,7 +1279,7 @@ async function dispatchNextUnit(
const roadmapContent = readFileSync(roadmapPath, "utf-8");
const mergeResult = mergeMilestoneToMain(s.originalBasePath, s.currentMilestoneId, roadmapContent);
s.basePath = s.originalBasePath;
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(
`Milestone ${ s.currentMilestoneId } merged to main.${mergeResult.pushed ? " Pushed to remote." : ""}`,
"info",
@ -1303,7 +1303,7 @@ async function dispatchNextUnit(
if (roadmapPath) {
const roadmapContent = readFileSync(roadmapPath, "utf-8");
const mergeResult = mergeMilestoneToMain(s.basePath, s.currentMilestoneId, roadmapContent);
s.gitService = new GitServiceImpl(s.basePath, loadEffectiveGSDPreferences()?.preferences?.git ?? {});
s.gitService = createGitService(s.basePath);
ctx.ui.notify(
`Milestone ${ s.currentMilestoneId } merged (branch mode).${mergeResult.pushed ? " Pushed to remote." : ""}`,
"info",
@ -1866,8 +1866,6 @@ export async function dispatchHookUnit(
ctx.ui.setStatus("gsd-auto", s.stepMode ? "next" : "auto");
ctx.ui.notify(`Running post-unit hook: ${hookName}`, "info");
console.log(`[dispatchHookUnit] Sending prompt of length ${hookPrompt.length}`);
console.log(`[dispatchHookUnit] Prompt preview: ${hookPrompt.substring(0, 200)}...`);
pi.sendMessage(
{ customType: "gsd-auto", content: hookPrompt, display: true },
{ triggerTurn: true },

View file

@ -19,8 +19,7 @@ import {
} from "./workflow-templates.js";
import { loadPrompt } from "./prompt-loader.js";
import { gsdRoot } from "./paths.js";
import { GitServiceImpl, runGit } from "./git-service.js";
import { loadEffectiveGSDPreferences } from "./preferences.js";
import { createGitService, runGit } from "./git-service.js";
import { isAutoActive, isAutoPaused } from "./auto.js";
// ─── Helpers ─────────────────────────────────────────────────────────────────
@ -423,9 +422,8 @@ export async function handleStart(
// ─── Create git branch (unless isolation: none) ─────────────────────────
const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git ?? {};
const git = new GitServiceImpl(basePath, gitPrefs);
const skipBranch = gitPrefs.isolation === "none";
const git = createGitService(basePath);
const skipBranch = git.prefs.isolation === "none";
const slug = slugify(description || templateId);
const branchName = `gsd/${templateId}/${slug}`;
let branchCreated = false;

View file

@ -13,6 +13,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { gsdRoot } from "./paths.js";
import { GIT_NO_PROMPT_ENV } from "./git-constants.js";
import { loadEffectiveGSDPreferences } from "./preferences.js";
import {
detectWorktreeName,
@ -541,6 +542,14 @@ export class GitServiceImpl {
}
// ─── Factory ───────────────────────────────────────────────────────────────
/** Create a GitServiceImpl with the current effective git preferences. */
export function createGitService(basePath: string): GitServiceImpl {
const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git ?? {};
return new GitServiceImpl(basePath, gitPrefs);
}
// ─── Commit Type Inference ─────────────────────────────────────────────────
/**

View file

@ -14,8 +14,7 @@ import { existsSync, mkdirSync, readdirSync } from "node:fs";
import { join } from "node:path";
import { loadPrompt } from "./prompt-loader.js";
import { gsdRoot } from "./paths.js";
import { GitServiceImpl, runGit } from "./git-service.js";
import { loadEffectiveGSDPreferences } from "./preferences.js";
import { createGitService, runGit } from "./git-service.js";
// ─── Quick Task Helpers ───────────────────────────────────────────────────────
@ -103,10 +102,9 @@ export async function handleQuick(
const date = new Date().toISOString().split("T")[0];
// Create git branch for the quick task (unless isolation: none)
const gitPrefs = loadEffectiveGSDPreferences()?.preferences?.git ?? {};
const git = new GitServiceImpl(basePath, gitPrefs);
const git = createGitService(basePath);
const branchName = `gsd/quick/${taskNum}-${slug}`;
const skipBranch = gitPrefs.isolation === "none";
const skipBranch = git.prefs.isolation === "none";
let branchCreated = false;
if (!skipBranch) {