@@ -184,6 +184,12 @@ import { OAUTH_CALLBACK_SERVER } from "@posthog/workspace-server/services/oauth-
184184import { oauthCallbackModule } from "@posthog/workspace-server/services/oauth-callback/oauth-callback.module" ;
185185import { onboardingImportModule } from "@posthog/workspace-server/services/onboarding-import/onboarding-import.module" ;
186186import { osModule } from "@posthog/workspace-server/services/os/os.module" ;
187+ import {
188+ PI_RPC_CLIENT_FACTORY ,
189+ PI_SESSION_SERVICE ,
190+ } from "@posthog/workspace-server/services/pi-session/identifiers" ;
191+ import type { PiSessionService } from "@posthog/workspace-server/services/pi-session/pi-session" ;
192+ import { piSessionModule } from "@posthog/workspace-server/services/pi-session/pi-session.module" ;
187193import { POSTHOG_PLUGIN_SERVICE } from "@posthog/workspace-server/services/posthog-plugin/identifiers" ;
188194import { posthogPluginModule } from "@posthog/workspace-server/services/posthog-plugin/posthog-plugin.module" ;
189195import { PROCESS_TRACKING_SERVICE } from "@posthog/workspace-server/services/process-tracking/identifiers" ;
@@ -220,6 +226,7 @@ import { workspaceModule } from "@posthog/workspace-server/services/workspace/wo
220226import { workspaceMetadataModule } from "@posthog/workspace-server/services/workspace-metadata/workspace-metadata.module" ;
221227import ExternalAppsStoreImpl from "electron-store" ;
222228import type { FileWatcherBridge } from "../index" ;
229+ import { DesktopPiRpcClientFactory } from "../platform-adapters/desktop-pi-rpc-client-factory" ;
223230import { ElectronAppLifecycle } from "../platform-adapters/electron-app-lifecycle" ;
224231import { ElectronAppMeta } from "../platform-adapters/electron-app-meta" ;
225232import { ElectronAppMetrics } from "../platform-adapters/electron-app-metrics" ;
@@ -356,10 +363,15 @@ container
356363 . bind ( MAIN_DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY )
357364 . toService ( DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY ) ;
358365container . load ( agentModule ) ;
366+ container . load ( piSessionModule ) ;
359367container . bind ( AGENT_SLEEP_COORDINATOR ) . toService ( MAIN_SLEEP_SERVICE ) ;
360368container . bind ( AGENT_MCP_APPS ) . toService ( MCP_APPS_SERVICE ) ;
361369container . bind ( AGENT_REPO_FILES ) . toService ( MAIN_FS_SERVICE ) ;
362370container . bind ( AGENT_AUTH ) . toService ( MAIN_AUTH_SERVICE ) ;
371+ container
372+ . bind ( PI_RPC_CLIENT_FACTORY )
373+ . to ( DesktopPiRpcClientFactory )
374+ . inSingletonScope ( ) ;
363375container . bind ( AGENT_LOGGER ) . toConstantValue ( logger ) ;
364376container . load ( osModule ) ;
365377container . bind < RootLogger > ( ROOT_LOGGER ) . toConstantValue ( logger ) ;
@@ -391,8 +403,12 @@ container.bind(MCP_PROXY_AUTH).toDynamicValue((ctx) => {
391403} ) ;
392404container . load ( archiveModule ) ;
393405container . bind ( ARCHIVE_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
394- cancelSessionsByTaskId : ( taskId : string ) =>
395- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
406+ cancelSessionsByTaskId : async ( taskId : string ) => {
407+ await Promise . all ( [
408+ ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
409+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
410+ ] ) ;
411+ } ,
396412} ) ) ;
397413container . bind ( ARCHIVE_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
398414 stopWatching : async ( worktreePath : string ) => {
@@ -403,8 +419,12 @@ container.bind(ARCHIVE_FILE_WATCHER).toDynamicValue((ctx) => ({
403419} ) ) ;
404420container . load ( suspensionModule ) ;
405421container . bind ( SUSPENSION_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
406- cancelSessionsByTaskId : ( taskId : string ) =>
407- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
422+ cancelSessionsByTaskId : async ( taskId : string ) => {
423+ await Promise . all ( [
424+ ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
425+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
426+ ] ) ;
427+ } ,
408428} ) ) ;
409429container . bind ( SUSPENSION_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
410430 stopWatching : async ( worktreePath : string ) => {
@@ -675,7 +695,12 @@ container.load(workspaceModule);
675695container . bind ( WORKSPACE_AGENT ) . toDynamicValue ( ( ctx ) : WorkspaceAgent => {
676696 const agent = ctx . get < AgentService > ( AGENT_SERVICE ) ;
677697 return {
678- cancelSessionsByTaskId : ( taskId ) => agent . cancelSessionsByTaskId ( taskId ) ,
698+ cancelSessionsByTaskId : async ( taskId ) => {
699+ await Promise . all ( [
700+ agent . cancelSessionsByTaskId ( taskId ) ,
701+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
702+ ] ) ;
703+ } ,
679704 onAgentFileActivity : ( handler ) =>
680705 agent . on ( AgentServiceEvent . AgentFileActivity , handler ) ,
681706 } ;
0 commit comments