Fix #3629: resolve boulder progress from worktree plan
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user