@@ -187,6 +187,12 @@ import { OAUTH_CALLBACK_SERVER } from "@posthog/workspace-server/services/oauth-
187187import { oauthCallbackModule } from "@posthog/workspace-server/services/oauth-callback/oauth-callback.module" ;
188188import { onboardingImportModule } from "@posthog/workspace-server/services/onboarding-import/onboarding-import.module" ;
189189import { osModule } from "@posthog/workspace-server/services/os/os.module" ;
190+ import {
191+ PI_RPC_CLIENT_FACTORY ,
192+ PI_SESSION_SERVICE ,
193+ } from "@posthog/workspace-server/services/pi-session/identifiers" ;
194+ import type { PiSessionService } from "@posthog/workspace-server/services/pi-session/pi-session" ;
195+ import { piSessionModule } from "@posthog/workspace-server/services/pi-session/pi-session.module" ;
190196import { POSTHOG_PLUGIN_SERVICE } from "@posthog/workspace-server/services/posthog-plugin/identifiers" ;
191197import { posthogPluginModule } from "@posthog/workspace-server/services/posthog-plugin/posthog-plugin.module" ;
192198import { PROCESS_TRACKING_SERVICE } from "@posthog/workspace-server/services/process-tracking/identifiers" ;
@@ -223,6 +229,7 @@ import { workspaceModule } from "@posthog/workspace-server/services/workspace/wo
223229import { workspaceMetadataModule } from "@posthog/workspace-server/services/workspace-metadata/workspace-metadata.module" ;
224230import ExternalAppsStoreImpl from "electron-store" ;
225231import type { FileWatcherBridge } from "../index" ;
232+ import { DesktopPiRpcClientFactory } from "../platform-adapters/desktop-pi-rpc-client-factory" ;
226233import { ElectronAppLifecycle } from "../platform-adapters/electron-app-lifecycle" ;
227234import { ElectronAppMeta } from "../platform-adapters/electron-app-meta" ;
228235import { ElectronAppMetrics } from "../platform-adapters/electron-app-metrics" ;
@@ -359,10 +366,15 @@ container
359366 . bind ( MAIN_DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY )
360367 . toService ( DEFAULT_ADDITIONAL_DIRECTORY_REPOSITORY ) ;
361368container . load ( agentModule ) ;
369+ container . load ( piSessionModule ) ;
362370container . bind ( AGENT_SLEEP_COORDINATOR ) . toService ( MAIN_SLEEP_SERVICE ) ;
363371container . bind ( AGENT_MCP_APPS ) . toService ( MCP_APPS_SERVICE ) ;
364372container . bind ( AGENT_REPO_FILES ) . toService ( MAIN_FS_SERVICE ) ;
365373container . bind ( AGENT_AUTH ) . toService ( MAIN_AUTH_SERVICE ) ;
374+ container
375+ . bind ( PI_RPC_CLIENT_FACTORY )
376+ . to ( DesktopPiRpcClientFactory )
377+ . inSingletonScope ( ) ;
366378container . bind ( AGENT_LOGGER ) . toConstantValue ( logger ) ;
367379container . load ( osModule ) ;
368380container . bind < RootLogger > ( ROOT_LOGGER ) . toConstantValue ( logger ) ;
@@ -394,8 +406,12 @@ container.bind(MCP_PROXY_AUTH).toDynamicValue((ctx) => {
394406} ) ;
395407container . load ( archiveModule ) ;
396408container . bind ( ARCHIVE_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
397- cancelSessionsByTaskId : ( taskId : string ) =>
398- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
409+ cancelSessionsByTaskId : async ( taskId : string ) => {
410+ await Promise . all ( [
411+ ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
412+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
413+ ] ) ;
414+ } ,
399415} ) ) ;
400416container . bind ( ARCHIVE_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
401417 stopWatching : async ( worktreePath : string ) => {
@@ -406,8 +422,12 @@ container.bind(ARCHIVE_FILE_WATCHER).toDynamicValue((ctx) => ({
406422} ) ) ;
407423container . load ( suspensionModule ) ;
408424container . bind ( SUSPENSION_SESSION_CANCELLER ) . toDynamicValue ( ( ctx ) => ( {
409- cancelSessionsByTaskId : ( taskId : string ) =>
410- ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
425+ cancelSessionsByTaskId : async ( taskId : string ) => {
426+ await Promise . all ( [
427+ ctx . get < AgentService > ( AGENT_SERVICE ) . cancelSessionsByTaskId ( taskId ) ,
428+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
429+ ] ) ;
430+ } ,
411431} ) ) ;
412432container . bind ( SUSPENSION_FILE_WATCHER ) . toDynamicValue ( ( ctx ) => ( {
413433 stopWatching : async ( worktreePath : string ) => {
@@ -685,7 +705,12 @@ container.load(workspaceModule);
685705container . bind ( WORKSPACE_AGENT ) . toDynamicValue ( ( ctx ) : WorkspaceAgent => {
686706 const agent = ctx . get < AgentService > ( AGENT_SERVICE ) ;
687707 return {
688- cancelSessionsByTaskId : ( taskId ) => agent . cancelSessionsByTaskId ( taskId ) ,
708+ cancelSessionsByTaskId : async ( taskId ) => {
709+ await Promise . all ( [
710+ agent . cancelSessionsByTaskId ( taskId ) ,
711+ ctx . get < PiSessionService > ( PI_SESSION_SERVICE ) . stop ( taskId ) ,
712+ ] ) ;
713+ } ,
689714 onAgentFileActivity : ( handler ) =>
690715 agent . on ( AgentServiceEvent . AgentFileActivity , handler ) ,
691716 } ;
0 commit comments