MCPcopy Create free account
hub / github.com/backnotprop/plannotator / startPlannotatorServer

Function startPlannotatorServer

packages/server/index.ts:128–633  ·  view source on GitHub ↗
(
  options: ServerOptions
)

Source from the content-addressed store, hash-verified

126 * - Port conflict retries
127 */
128export async function startPlannotatorServer(
129 options: ServerOptions
130): Promise<ServerResult> {
131 const { plan, origin, htmlContent, permissionMode, sharingEnabled = true, shareBaseUrl, pasteApiUrl, onReady, mode, customPlanPath } = options;
132
133 const isRemote = isRemoteSession();
134 const configuredPort = getServerPort();
135 const wslFlag = await isWSL();
136 const gitUser = detectGitUser();
137
138 // Side-channel pre-warm: kick off the code-file walk now so the
139 // renderer's POST /api/doc/exists lands on warm cache.
140 void warmFileListCache(process.cwd(), "code");
141
142 // --- Archive mode setup ---
143 let archivePlans: ArchivedPlan[] = [];
144 let initialArchivePlan = "";
145 let resolveDone: (() => void) | undefined;
146 let donePromise: Promise<void> | undefined;
147
148 if (mode === "archive") {
149 archivePlans = listArchivedPlans(customPlanPath ?? undefined);
150 initialArchivePlan = archivePlans.length > 0
151 ? readArchivedPlan(archivePlans[0].filename, customPlanPath ?? undefined) ?? ""
152 : "";
153 donePromise = new Promise<void>((resolve) => { resolveDone = resolve; });
154 }
155
156 // --- Plan review mode setup (skip in archive mode) ---
157 const draftKey = mode !== "archive" ? contentHash(plan) : "";
158 const editorAnnotations = mode !== "archive" ? createEditorAnnotationHandler() : null;
159 const externalAnnotations = mode !== "archive" ? createExternalAnnotationHandler("plan") : null;
160 const aiRuntime = mode !== "archive" ? await createAIRuntime() : null;
161 const slug = mode !== "archive" ? generateSlug(plan) : "";
162
163 // Lazy cache for in-session archive browsing (plan review sidebar tab)
164 let cachedArchivePlans: ReturnType<typeof listArchivedPlans> | null = null;
165
166 // Plan-specific: repo info, version history, decision promise
167 let repoInfo: Awaited<ReturnType<typeof getRepoInfo>> | null = null;
168 let project = "";
169 let currentPlanPath = "";
170 let previousPlan: string | null = null;
171 let versionInfo = { version: 0, totalVersions: 0, project: "" };
172
173 let resolveDecision: (result: {
174 approved: boolean;
175 feedback?: string;
176 savedPath?: string;
177 agentSwitch?: string;
178 permissionMode?: string;
179 }) => void;
180 let decisionPromise: Promise<{
181 approved: boolean;
182 feedback?: string;
183 savedPath?: string;
184 agentSwitch?: string;
185 permissionMode?: string;

Callers 3

index.tsFile · 0.90
test-server.tsFile · 0.90
runEmbeddedPlanReviewFunction · 0.85

Calls 15

isRemoteSessionFunction · 0.90
getServerPortFunction · 0.90
isWSLFunction · 0.90
detectGitUserFunction · 0.90
warmFileListCacheFunction · 0.90
listArchivedPlansFunction · 0.90
readArchivedPlanFunction · 0.90
contentHashFunction · 0.90
createAIRuntimeFunction · 0.90
generateSlugFunction · 0.90

Tested by

no test coverage detected