(ctx, rawOptions?: PlannotatorOpenCodeOptions)
| 278 | } |
| 279 | |
| 280 | const PlannotatorPlugin: Plugin = async (ctx, rawOptions?: PlannotatorOpenCodeOptions) => { |
| 281 | const workflowOptions = normalizeWorkflowOptions(rawOptions); |
| 282 | |
| 283 | // Preload HTML in background — populates the sync cache before first use |
| 284 | readFile(resolveBundledHtmlPath("plannotator.html"), "utf-8").then(h => { _planHtml = h; }).catch(() => {}); |
| 285 | readFile(resolveBundledHtmlPath("review-editor.html"), "utf-8").then(h => { _reviewHtml = h; }).catch(() => {}); |
| 286 | |
| 287 | let cachedAgents: any[] | null = null; |
| 288 | |
| 289 | async function getSharingEnabled(): Promise<boolean> { |
| 290 | try { |
| 291 | const response = await ctx.client.config.get({ query: { directory: ctx.directory } }); |
| 292 | // @ts-ignore - share config may exist |
| 293 | const share = response?.data?.share; |
| 294 | if (share !== undefined) { |
| 295 | return share !== "disabled"; |
| 296 | } |
| 297 | } catch { |
| 298 | // Config read failed, fall through to env var / plannotator config |
| 299 | } |
| 300 | return resolveSharingEnabled(loadConfig()); |
| 301 | } |
| 302 | |
| 303 | function getShareBaseUrl(): string | undefined { |
| 304 | return process.env.PLANNOTATOR_SHARE_URL || undefined; |
| 305 | } |
| 306 | |
| 307 | function getPasteApiUrl(): string | undefined { |
| 308 | return process.env.PLANNOTATOR_PASTE_URL || undefined; |
| 309 | } |
| 310 | |
| 311 | async function getOpenCodeAgents(): Promise<any[] | undefined> { |
| 312 | try { |
| 313 | if (!cachedAgents) { |
| 314 | const response = await ctx.client.app.agents({ |
| 315 | query: { directory: ctx.directory }, |
| 316 | }); |
| 317 | cachedAgents = response.data ?? []; |
| 318 | } |
| 319 | return cachedAgents; |
| 320 | } catch { |
| 321 | return undefined; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | async function getBridgeContext(): Promise<OpenCodeBridgeContext> { |
| 326 | return { |
| 327 | sharingEnabled: await getSharingEnabled(), |
| 328 | shareBaseUrl: getShareBaseUrl(), |
| 329 | pasteApiUrl: getPasteApiUrl(), |
| 330 | agents: await getOpenCodeAgents(), |
| 331 | }; |
| 332 | } |
| 333 | |
| 334 | function getPlanTimeoutSeconds(): number | null { |
| 335 | const raw = process.env.PLANNOTATOR_PLAN_TIMEOUT_SECONDS?.trim(); |
| 336 | if (!raw) return DEFAULT_PLAN_TIMEOUT_SECONDS; |
| 337 |
nothing calls this directly
no test coverage detected