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

Function startAnnotateServer

packages/server/annotate.ts:131–661  ·  view source on GitHub ↗
(
  options: AnnotateServerOptions
)

Source from the content-addressed store, hash-verified

129 * - Port conflict retries
130 */
131export async function startAnnotateServer(
132 options: AnnotateServerOptions
133): Promise<AnnotateServerResult> {
134 // Side-channel pre-warm so /api/doc/exists POSTs land on warm cache.
135 void warmFileListCache(process.cwd(), "code");
136
137 const {
138 markdown,
139 filePath,
140 htmlContent,
141 origin,
142 mode = "annotate",
143 folderPath,
144 recentMessages,
145 sourceInfo,
146 sourceConverted,
147 sharingEnabled = true,
148 shareBaseUrl,
149 pasteApiUrl,
150 gate = false,
151 rawHtml,
152 renderHtml = false,
153 convertHtml = false,
154 agentCwd,
155 onReady,
156 } = options;
157
158 const isRemote = isRemoteSession();
159 const configuredPort = getServerPort();
160 const wslFlag = await isWSL();
161 const gitUser = detectGitUser();
162 const draftSource =
163 mode === "annotate-folder" && folderPath
164 ? `folder:${resolvePath(folderPath)}`
165 : renderHtml && rawHtml ? rawHtml : markdown;
166 const draftKey = contentHash(draftSource);
167 const externalAnnotations = createExternalAnnotationHandler("plan");
168 const aiRuntime = await createAIRuntime();
169 const htmlAssets = createHtmlAssetRegistry();
170 const agentTerminal = await createBunAgentTerminalBridge({
171 enabled: supportsAnnotateAgentTerminalMode(mode),
172 cwd: agentCwd ?? process.cwd(),
173 });
174
175 async function loadShareHtml(pathParam: string | null): Promise<Response> {
176 if (/^https?:\/\//i.test(filePath)) {
177 return Response.json({ error: "Raw HTML sharing is unavailable for URL annotations" }, { status: 400 });
178 }
179
180 const sourcePath = resolvePath(filePath);
181 const requestedPath = pathParam ? resolvePath(pathParam) : sourcePath;
182 if (!/\.html?$/i.test(requestedPath)) {
183 return Response.json({ error: "Share HTML is only available for HTML documents" }, { status: 400 });
184 }
185 if (!isAllowedHtmlSharePath(requestedPath)) {
186 return Response.json({ error: "Access denied" }, { status: 403 });
187 }
188

Callers 2

annotate.test.tsFile · 0.90
index.tsFile · 0.90

Calls 15

warmFileListCacheFunction · 0.90
isRemoteSessionFunction · 0.90
getServerPortFunction · 0.90
isWSLFunction · 0.90
detectGitUserFunction · 0.90
contentHashFunction · 0.90
createAIRuntimeFunction · 0.90
createHtmlAssetRegistryFunction · 0.90

Tested by

no test coverage detected