diff --git a/apps/opencode-plugin/index.ts b/apps/opencode-plugin/index.ts index adc557b0..dae038b6 100644 --- a/apps/opencode-plugin/index.ts +++ b/apps/opencode-plugin/index.ts @@ -26,6 +26,7 @@ import { handleAnnotateServerReady, } from "@plannotator/server/annotate"; import { getGitContext, runGitDiff } from "@plannotator/server/git"; +import { writeRemoteShareLink } from "@plannotator/server/share-url"; // @ts-ignore - Bun import attribute for text import indexHtml from "./plannotator.html" with { type: "text" }; @@ -311,12 +312,25 @@ Do NOT proceed with implementation until your plan is approved. shareBaseUrl: getShareBaseUrl(), htmlContent, opencodeClient: ctx.client, - onReady: (url, isRemote, port) => { + onReady: async (url, isRemote, port) => { handleServerReady(url, isRemote, port); + if (isRemote && await getSharingEnabled()) { + await writeRemoteShareLink(args.plan, getShareBaseUrl(), "review the plan", "plan only").catch(() => {}); + } }, }); - const result = await server.waitForDecision(); + const PLANNOTATOR_TIMEOUT_MS = 10 * 60 * 1000; // 10min timeout + let timeoutId: ReturnType; + const result = await Promise.race([ + server.waitForDecision().then((r) => { clearTimeout(timeoutId); return r; }), + new Promise<{ approved: boolean; feedback?: string }>((resolve) => { + timeoutId = setTimeout( + () => resolve({ approved: false, feedback: "[Plannotator] No response within 10 minutes. Port released automatically. Please call submit_plan again." }), + PLANNOTATOR_TIMEOUT_MS + ); + }), + ]); await Bun.sleep(1500); server.stop();