feat(hooks): make start-work hook respect worktree config

This commit is contained in:
acamq
2026-03-11 18:33:38 -06:00
parent 66ac587dfa
commit 4405d25fc5
2 changed files with 10 additions and 7 deletions
+9 -6
View File
@@ -64,7 +64,7 @@ function resolveWorktreeContext(
}
}
export function createStartWorkHook(ctx: PluginInput) {
export function createStartWorkHook(ctx: PluginInput, options?: { worktreeEnabled?: boolean }) {
return {
"chat.message": async (input: StartWorkHookInput, output: StartWorkHookOutput): Promise<void> => {
const parts = output.parts
@@ -85,7 +85,10 @@ export function createStartWorkHook(ctx: PluginInput) {
const timestamp = new Date().toISOString()
const { planName: explicitPlanName, explicitWorktreePath } = parseUserRequest(promptText)
const { worktreePath, block: worktreeBlock } = resolveWorktreeContext(explicitWorktreePath)
const worktreeDisabled = options?.worktreeEnabled === false
const { worktreePath, block: worktreeBlock } = worktreeDisabled
? { worktreePath: undefined, block: "" }
: resolveWorktreeContext(explicitWorktreePath)
let contextInfo = ""
@@ -106,7 +109,7 @@ The requested plan "${getPlanName(matchedPlan)}" has been completed.
All ${progress.total} tasks are done. Create a new plan with: /plan "your task"`
} else {
if (existingState) clearBoulderState(ctx.directory)
const newState = createBoulderState(matchedPlan, sessionId, "atlas", worktreePath)
const newState = createBoulderState(matchedPlan, sessionId, "atlas", worktreeDisabled ? undefined : worktreePath)
writeBoulderState(ctx.directory, newState)
contextInfo = `
@@ -152,9 +155,9 @@ No incomplete plans available. Create a new plan with: /plan "your task"`
const progress = getPlanProgress(existingState.active_plan)
if (!progress.isComplete) {
const effectiveWorktree = worktreePath ?? existingState.worktree_path
const effectiveWorktree = worktreeDisabled ? undefined : (worktreePath ?? existingState.worktree_path)
if (worktreePath !== undefined) {
if (!worktreeDisabled && worktreePath !== undefined) {
const updatedSessions = existingState.session_ids.includes(sessionId)
? existingState.session_ids
: [...existingState.session_ids, sessionId]
@@ -213,7 +216,7 @@ All ${plans.length} plan(s) are complete. Create a new plan with: /plan "your ta
} else if (incompletePlans.length === 1) {
const planPath = incompletePlans[0]
const progress = getPlanProgress(planPath)
const newState = createBoulderState(planPath, sessionId, "atlas", worktreePath)
const newState = createBoulderState(planPath, sessionId, "atlas", worktreeDisabled ? undefined : worktreePath)
writeBoulderState(ctx.directory, newState)
contextInfo += `
+1 -1
View File
@@ -216,7 +216,7 @@ export function createSessionHooks(args: {
: null
const startWork = isHookEnabled("start-work")
? safeHook("start-work", () => createStartWorkHook(ctx))
? safeHook("start-work", () => createStartWorkHook(ctx, { worktreeEnabled: pluginConfig.start_work?.worktree }))
: null
const prometheusMdOnly = isHookEnabled("prometheus-md-only")