@@ -61,7 +61,7 @@ import {
6161import {
6262 handleAnnotateServerReady ,
6363} from "@plannotator/server/annotate" ;
64- import { loadConfig } from "@plannotator/shared/config" ;
64+ import { loadConfig , resolveUseJina } from "@plannotator/shared/config" ;
6565import { parseReviewArgs } from "@plannotator/shared/review-args" ;
6666import { statSync , existsSync } from "fs" ;
6767import {
@@ -72,7 +72,7 @@ import {
7272 buildPlanFileRule ,
7373} from "@plannotator/shared/prompts" ;
7474import { openBrowser } from "@plannotator/server/browser" ;
75- import { cleanupDaemonState , discoverDaemon } from "@plannotator/server/daemon/client" ;
75+ import { cleanupDaemonState , discoverDaemon , waitForDaemonShutdown } from "@plannotator/server/daemon/client" ;
7676import { startDaemonRuntime } from "@plannotator/server/daemon/runtime" ;
7777import { createDaemonSessionFactory } from "@plannotator/server/daemon/session-factory" ;
7878import { getDaemonStartCommand } from "@plannotator/server/daemon/start-command" ;
@@ -127,6 +127,7 @@ const reviewHtmlContent = reviewHtml as unknown as string;
127127
128128// Check for subcommand
129129const args = process . argv . slice ( 2 ) ;
130+ const launcherCwd = process . cwd ( ) ;
130131
131132// Global flag: --browser <name>
132133const browserIdx = args . indexOf ( "--browser" ) ;
@@ -282,6 +283,13 @@ async function runDaemonCommand(): Promise<void> {
282283 process . exit ( 1 ) ;
283284 }
284285 const result = await daemon . client . shutdown ( ) ;
286+ if ( "ok" in result && result . ok ) {
287+ const stopped = await waitForDaemonShutdown ( daemon . state ) ;
288+ if ( ! stopped ) {
289+ console . log ( JSON . stringify ( { ok : false , code : "daemon-stop-timeout" , message : "Timed out waiting for the Plannotator daemon to stop." } ) ) ;
290+ process . exit ( 1 ) ;
291+ }
292+ }
285293 console . log ( JSON . stringify ( result ) ) ;
286294 process . exit ( "ok" in result && result . ok ? 0 : 1 ) ;
287295 }
@@ -300,7 +308,7 @@ async function runDaemonCommand(): Promise<void> {
300308 }
301309
302310 if ( ! foreground ) {
303- const child = Bun . spawn ( getDaemonStartCommand ( ) , {
311+ const child = Bun . spawn ( getDaemonStartCommand ( process . argv , process . execPath , launcherCwd ) , {
304312 cwd : getInvocationCwd ( ) ,
305313 stdin : "ignore" ,
306314 stdout : "ignore" ,
@@ -449,7 +457,7 @@ async function ensureDaemonClient(options: { pluginError?: boolean } = {}) {
449457 fail ( `daemon-${ existing . code } ` , existing . message ) ;
450458 }
451459
452- const command = getDaemonStartCommand ( ) ;
460+ const command = getDaemonStartCommand ( process . argv , process . execPath , launcherCwd ) ;
453461 const child = Bun . spawn ( command , {
454462 cwd : getInvocationCwd ( ) ,
455463 stdin : "ignore" ,
@@ -523,6 +531,8 @@ async function runDaemonSessionRequest(request: PluginRequest, options: { plugin
523531 } ;
524532 if ( created . session . remoteShare ) {
525533 process . stderr . write ( formatRemoteShareNotice ( created . session . remoteShare ) ) ;
534+ } else if ( daemon . state . isRemote ) {
535+ process . stderr . write ( `\n Open this forwarded Plannotator session URL:\n ${ created . session . url } \n\n` ) ;
526536 }
527537 if ( options . pluginError ) {
528538 emitPluginSessionReady ( session ) ;
@@ -597,11 +607,14 @@ async function runPluginArchiveCommand(): Promise<void> {
597607async function runPluginAnnotateCommand ( defaultMode : "annotate" | "annotate-last" = "annotate" ) : Promise < void > {
598608 const request = await readPluginRequest < PluginAnnotateRequest > ( ) ;
599609 const origin = getPluginOrigin ( request ) ;
610+ const useJina = resolveUseJina ( request . noJina === true , loadConfig ( ) ) ;
600611 await runDaemonBackedPluginRequest ( {
601612 ...request ,
602613 action : defaultMode ,
603614 origin,
604615 cwd : resolvePluginCwd ( request ) ,
616+ useJina,
617+ jinaApiKey : process . env . JINA_API_KEY ,
605618 } ) ;
606619}
607620
@@ -754,6 +767,8 @@ if (args[0] === "sessions") {
754767 cwd : getInvocationCwd ( ) ,
755768 args : rawFilePath ,
756769 noJina : cliNoJina ,
770+ useJina : resolveUseJina ( cliNoJina , loadConfig ( ) ) ,
771+ jinaApiKey : process . env . JINA_API_KEY ,
757772 gate : gateFlag ,
758773 renderHtml : renderHtmlFlag ,
759774 sharingEnabled,
0 commit comments