Fix #3629: resolve boulder progress from worktree plan

This commit is contained in:
lucasyounger
2026-04-25 16:34:34 +08:00
parent 48b0cfeaf5
commit 828c2634bd
13 changed files with 252 additions and 21 deletions
+34 -1
View File
@@ -5,7 +5,7 @@
*/
import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync } from "node:fs"
import { dirname, join, basename } from "node:path"
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path"
import type { BoulderState, PlanProgress, TaskSessionState } from "./types"
import { BOULDER_DIR, BOULDER_FILE, PROMETHEUS_PLANS_DIR } from "./constants"
@@ -15,6 +15,39 @@ export function getBoulderFilePath(directory: string): string {
return join(directory, BOULDER_DIR, BOULDER_FILE)
}
function resolveTrackedPath(baseDirectory: string, trackedPath: string): string {
return isAbsolute(trackedPath)
? resolve(trackedPath)
: resolve(baseDirectory, trackedPath)
}
export function resolveBoulderPlanPath(
directory: string,
state: Pick<BoulderState, "active_plan" | "worktree_path">,
): string {
const absolutePlanPath = resolveTrackedPath(directory, state.active_plan)
const worktreePath = state.worktree_path?.trim()
if (!worktreePath) {
return absolutePlanPath
}
const absoluteDirectory = resolve(directory)
const relativePlanPath = relative(absoluteDirectory, absolutePlanPath)
if (
relativePlanPath.length === 0
|| relativePlanPath.startsWith("..")
|| isAbsolute(relativePlanPath)
) {
return absolutePlanPath
}
const absoluteWorktreePath = resolveTrackedPath(directory, worktreePath)
const worktreePlanPath = resolve(absoluteWorktreePath, relativePlanPath)
return existsSync(worktreePlanPath)
? worktreePlanPath
: absolutePlanPath
}
export function readBoulderState(directory: string): BoulderState | null {
const filePath = getBoulderFilePath(directory)