1313 */
1414
1515import type { Origin } from "@plannotator/shared/agents" ;
16- import { resolve } from "path" ;
1716import { isRemoteSession , getServerHostname , getServerPort } from "./remote" ;
1817import { openEditorDiff } from "./ide" ;
1918import {
@@ -47,7 +46,7 @@ import { composeImproveContext } from "@plannotator/shared/pfm-reminder";
4746import { handleImage , handleUpload , handleAgents , handleServerReady , handleDraftSave , handleDraftLoad , handleDraftDelete , handleFavicon , type OpencodeClient } from "./shared-handlers" ;
4847import { contentHash , deleteDraft } from "./draft" ;
4948import { handleDoc , handleDocExists , handleObsidianVaults , handleObsidianFiles , handleObsidianDoc , handleFileBrowserFiles } from "./reference-handlers" ;
50- import { warmFileListCache } from "@plannotator/shared/resolve-file" ;
49+ import { resolveUserPath , warmFileListCache } from "@plannotator/shared/resolve-file" ;
5150import { createEditorAnnotationHandler } from "./editor-annotations" ;
5251import { createExternalAnnotationHandler } from "./external-annotations" ;
5352import { isWSL } from "./browser" ;
@@ -137,6 +136,11 @@ export async function createPlannotatorSession(
137136 options : ServerOptions
138137) : Promise < PlannotatorSession > {
139138 const { cwd = process . cwd ( ) , plan, origin, htmlContent, permissionMode, sharingEnabled = true , shareBaseUrl, pasteApiUrl, mode, customPlanPath } = options ;
139+ const resolvePlanStoragePath = ( customPath ?: string | null ) : string | undefined => {
140+ if ( ! customPath ?. trim ( ) ) return undefined ;
141+ return resolveUserPath ( customPath , cwd ) ;
142+ } ;
143+ const archiveCustomPath = resolvePlanStoragePath ( customPlanPath ) ;
140144
141145 const wslFlag = await isWSL ( ) ;
142146 const gitUser = detectGitUser ( ) ;
@@ -152,9 +156,9 @@ export async function createPlannotatorSession(
152156 let donePromise : Promise < void > | undefined ;
153157
154158 if ( mode === "archive" ) {
155- archivePlans = listArchivedPlans ( customPlanPath ?? undefined ) ;
159+ archivePlans = listArchivedPlans ( archiveCustomPath ) ;
156160 initialArchivePlan = archivePlans . length > 0
157- ? readArchivedPlan ( archivePlans [ 0 ] . filename , customPlanPath ?? undefined ) ?? ""
161+ ? readArchivedPlan ( archivePlans [ 0 ] . filename , archiveCustomPath ) ?? ""
158162 : "" ;
159163 donePromise = new Promise < void > ( ( resolve ) => { resolveDone = resolve ; } ) ;
160164 }
@@ -244,7 +248,7 @@ export async function createPlannotatorSession(
244248 // API: List archived plans (from ~/.plannotator/plans/)
245249 // Cached for session lifetime — new plans won't appear during a single review
246250 if ( url . pathname === "/api/archive/plans" && req . method === "GET" ) {
247- const customPath = url . searchParams . get ( "customPath" ) || undefined ;
251+ const customPath = resolvePlanStoragePath ( url . searchParams . get ( "customPath" ) ) ;
248252 if ( ! cachedArchivePlans ) cachedArchivePlans = listArchivedPlans ( customPath ) ;
249253 return Response . json ( { plans : cachedArchivePlans } ) ;
250254 }
@@ -255,7 +259,7 @@ export async function createPlannotatorSession(
255259 if ( ! filename ) {
256260 return Response . json ( { error : "Missing filename parameter" } , { status : 400 } ) ;
257261 }
258- const customPath = url . searchParams . get ( "customPath" ) || undefined ;
262+ const customPath = resolvePlanStoragePath ( url . searchParams . get ( "customPath" ) ) ;
259263 const content = readArchivedPlan ( filename , customPath ) ;
260264 if ( content === null ) {
261265 return Response . json ( { error : "Plan not found" } , { status : 404 } ) ;
@@ -485,7 +489,7 @@ export async function createPlannotatorSession(
485489 // Capture plan save settings
486490 if ( body . planSave !== undefined ) {
487491 planSaveEnabled = body . planSave . enabled ;
488- planSaveCustomPath = body . planSave . customPath ;
492+ planSaveCustomPath = resolvePlanStoragePath ( body . planSave . customPath ) ;
489493 }
490494
491495 // Run integrations in parallel — they're independent
@@ -546,7 +550,7 @@ export async function createPlannotatorSession(
546550 // Capture plan save settings
547551 if ( body . planSave !== undefined ) {
548552 planSaveEnabled = body . planSave . enabled ;
549- planSaveCustomPath = body . planSave . customPath ;
553+ planSaveCustomPath = resolvePlanStoragePath ( body . planSave . customPath ) ;
550554 }
551555 } catch {
552556 // Use default feedback
0 commit comments