@xenosystem/agent-interface-host 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +67 -0
- package/dist/acp/AcpAgentRegistryService.d.ts +77 -0
- package/dist/acp/AcpAgentRegistryService.d.ts.map +1 -0
- package/dist/acp/AcpAgentRegistryService.js +754 -0
- package/dist/acp/AcpAgentRegistryService.js.map +1 -0
- package/dist/acp/AcpAgentTurnExecutionAdapter.d.ts +56 -0
- package/dist/acp/AcpAgentTurnExecutionAdapter.d.ts.map +1 -0
- package/dist/acp/AcpAgentTurnExecutionAdapter.js +323 -0
- package/dist/acp/AcpAgentTurnExecutionAdapter.js.map +1 -0
- package/dist/acp/AcpApprovalPortAdapter.d.ts +41 -0
- package/dist/acp/AcpApprovalPortAdapter.d.ts.map +1 -0
- package/dist/acp/AcpApprovalPortAdapter.js +82 -0
- package/dist/acp/AcpApprovalPortAdapter.js.map +1 -0
- package/dist/acp/AcpCoordinationBridge.d.ts +13 -0
- package/dist/acp/AcpCoordinationBridge.d.ts.map +1 -0
- package/dist/acp/AcpCoordinationBridge.js +13 -0
- package/dist/acp/AcpCoordinationBridge.js.map +1 -0
- package/dist/acp/AcpDiagnosticsService.d.ts +61 -0
- package/dist/acp/AcpDiagnosticsService.d.ts.map +1 -0
- package/dist/acp/AcpDiagnosticsService.js +203 -0
- package/dist/acp/AcpDiagnosticsService.js.map +1 -0
- package/dist/acp/AcpExternalCertificationHarness.d.ts +47 -0
- package/dist/acp/AcpExternalCertificationHarness.d.ts.map +1 -0
- package/dist/acp/AcpExternalCertificationHarness.js +176 -0
- package/dist/acp/AcpExternalCertificationHarness.js.map +1 -0
- package/dist/acp/AcpHostBridge.d.ts +81 -0
- package/dist/acp/AcpHostBridge.d.ts.map +1 -0
- package/dist/acp/AcpHostBridge.js +101 -0
- package/dist/acp/AcpHostBridge.js.map +1 -0
- package/dist/acp/AcpInteractivePermissionBridge.d.ts +77 -0
- package/dist/acp/AcpInteractivePermissionBridge.d.ts.map +1 -0
- package/dist/acp/AcpInteractivePermissionBridge.js +127 -0
- package/dist/acp/AcpInteractivePermissionBridge.js.map +1 -0
- package/dist/acp/AcpPermissionBridge.d.ts +19 -0
- package/dist/acp/AcpPermissionBridge.d.ts.map +1 -0
- package/dist/acp/AcpPermissionBridge.js +110 -0
- package/dist/acp/AcpPermissionBridge.js.map +1 -0
- package/dist/acp/AcpPermissionPolicy.d.ts +111 -0
- package/dist/acp/AcpPermissionPolicy.d.ts.map +1 -0
- package/dist/acp/AcpPermissionPolicy.js +167 -0
- package/dist/acp/AcpPermissionPolicy.js.map +1 -0
- package/dist/acp/AcpProcessSupervisor.d.ts +134 -0
- package/dist/acp/AcpProcessSupervisor.d.ts.map +1 -0
- package/dist/acp/AcpProcessSupervisor.js +674 -0
- package/dist/acp/AcpProcessSupervisor.js.map +1 -0
- package/dist/acp/AcpProviderApprovalService.d.ts +27 -0
- package/dist/acp/AcpProviderApprovalService.d.ts.map +1 -0
- package/dist/acp/AcpProviderApprovalService.js +128 -0
- package/dist/acp/AcpProviderApprovalService.js.map +1 -0
- package/dist/acp/AcpProviderCatalogService.d.ts +69 -0
- package/dist/acp/AcpProviderCatalogService.d.ts.map +1 -0
- package/dist/acp/AcpProviderCatalogService.js +707 -0
- package/dist/acp/AcpProviderCatalogService.js.map +1 -0
- package/dist/acp/AcpProviderModelService.d.ts +6 -0
- package/dist/acp/AcpProviderModelService.d.ts.map +1 -0
- package/dist/acp/AcpProviderModelService.js +274 -0
- package/dist/acp/AcpProviderModelService.js.map +1 -0
- package/dist/acp/AcpProviderVersionReadiness.d.ts +6 -0
- package/dist/acp/AcpProviderVersionReadiness.d.ts.map +1 -0
- package/dist/acp/AcpProviderVersionReadiness.js +100 -0
- package/dist/acp/AcpProviderVersionReadiness.js.map +1 -0
- package/dist/acp/AcpRuntimeEventMapper.d.ts +16 -0
- package/dist/acp/AcpRuntimeEventMapper.d.ts.map +1 -0
- package/dist/acp/AcpRuntimeEventMapper.js +326 -0
- package/dist/acp/AcpRuntimeEventMapper.js.map +1 -0
- package/dist/acp/AcpSessionService.d.ts +65 -0
- package/dist/acp/AcpSessionService.d.ts.map +1 -0
- package/dist/acp/AcpSessionService.js +931 -0
- package/dist/acp/AcpSessionService.js.map +1 -0
- package/dist/acp/DurableAcpPermissionPolicyStore.d.ts +25 -0
- package/dist/acp/DurableAcpPermissionPolicyStore.d.ts.map +1 -0
- package/dist/acp/DurableAcpPermissionPolicyStore.js +100 -0
- package/dist/acp/DurableAcpPermissionPolicyStore.js.map +1 -0
- package/dist/acp/acpCommandSafety.d.ts +63 -0
- package/dist/acp/acpCommandSafety.d.ts.map +1 -0
- package/dist/acp/acpCommandSafety.js +90 -0
- package/dist/acp/acpCommandSafety.js.map +1 -0
- package/dist/acp/acpErrors.d.ts +47 -0
- package/dist/acp/acpErrors.d.ts.map +1 -0
- package/dist/acp/acpErrors.js +93 -0
- package/dist/acp/acpErrors.js.map +1 -0
- package/dist/acp/acpRedaction.d.ts +9 -0
- package/dist/acp/acpRedaction.d.ts.map +1 -0
- package/dist/acp/acpRedaction.js +69 -0
- package/dist/acp/acpRedaction.js.map +1 -0
- package/dist/acp/acpSessionResume.d.ts +8 -0
- package/dist/acp/acpSessionResume.d.ts.map +1 -0
- package/dist/acp/acpSessionResume.js +31 -0
- package/dist/acp/acpSessionResume.js.map +1 -0
- package/dist/acp/acpTypes.d.ts +467 -0
- package/dist/acp/acpTypes.d.ts.map +1 -0
- package/dist/acp/acpTypes.js +2 -0
- package/dist/acp/acpTypes.js.map +1 -0
- package/dist/agent/chooseDirectoryBridge.d.ts +29 -0
- package/dist/agent/chooseDirectoryBridge.d.ts.map +1 -0
- package/dist/agent/chooseDirectoryBridge.js +116 -0
- package/dist/agent/chooseDirectoryBridge.js.map +1 -0
- package/dist/agent/permissionProfiles.d.ts +29 -0
- package/dist/agent/permissionProfiles.d.ts.map +1 -0
- package/dist/agent/permissionProfiles.js +107 -0
- package/dist/agent/permissionProfiles.js.map +1 -0
- package/dist/agent/runtimeAuthorityPrompt.d.ts +13 -0
- package/dist/agent/runtimeAuthorityPrompt.d.ts.map +1 -0
- package/dist/agent/runtimeAuthorityPrompt.js +45 -0
- package/dist/agent/runtimeAuthorityPrompt.js.map +1 -0
- package/dist/agent/runtimeModeOutputGuard.d.ts +6 -0
- package/dist/agent/runtimeModeOutputGuard.d.ts.map +1 -0
- package/dist/agent/runtimeModeOutputGuard.js +40 -0
- package/dist/agent/runtimeModeOutputGuard.js.map +1 -0
- package/dist/agent/workspacePlacementBridge.d.ts +29 -0
- package/dist/agent/workspacePlacementBridge.d.ts.map +1 -0
- package/dist/agent/workspacePlacementBridge.js +143 -0
- package/dist/agent/workspacePlacementBridge.js.map +1 -0
- package/dist/agentSearch/AgentSearchService.d.ts +81 -0
- package/dist/agentSearch/AgentSearchService.d.ts.map +1 -0
- package/dist/agentSearch/AgentSearchService.js +1038 -0
- package/dist/agentSearch/AgentSearchService.js.map +1 -0
- package/dist/agentSearch/JsonInvertedIndexAdapter.d.ts +44 -0
- package/dist/agentSearch/JsonInvertedIndexAdapter.d.ts.map +1 -0
- package/dist/agentSearch/JsonInvertedIndexAdapter.js +307 -0
- package/dist/agentSearch/JsonInvertedIndexAdapter.js.map +1 -0
- package/dist/agentSearch/SearchIndexAdapter.d.ts +33 -0
- package/dist/agentSearch/SearchIndexAdapter.d.ts.map +1 -0
- package/dist/agentSearch/SearchIndexAdapter.js +2 -0
- package/dist/agentSearch/SearchIndexAdapter.js.map +1 -0
- package/dist/agentSearch/SearchSourceWatcher.d.ts +29 -0
- package/dist/agentSearch/SearchSourceWatcher.d.ts.map +1 -0
- package/dist/agentSearch/SearchSourceWatcher.js +150 -0
- package/dist/agentSearch/SearchSourceWatcher.js.map +1 -0
- package/dist/agentSearch/SqliteFtsIndexAdapter.d.ts +58 -0
- package/dist/agentSearch/SqliteFtsIndexAdapter.d.ts.map +1 -0
- package/dist/agentSearch/SqliteFtsIndexAdapter.js +420 -0
- package/dist/agentSearch/SqliteFtsIndexAdapter.js.map +1 -0
- package/dist/agentSearch/conversationIndexer.d.ts +69 -0
- package/dist/agentSearch/conversationIndexer.d.ts.map +1 -0
- package/dist/agentSearch/conversationIndexer.js +313 -0
- package/dist/agentSearch/conversationIndexer.js.map +1 -0
- package/dist/agentSearch/searchTypes.d.ts +264 -0
- package/dist/agentSearch/searchTypes.d.ts.map +1 -0
- package/dist/agentSearch/searchTypes.js +2 -0
- package/dist/agentSearch/searchTypes.js.map +1 -0
- package/dist/agentSearch/searchUtils.d.ts +12 -0
- package/dist/agentSearch/searchUtils.d.ts.map +1 -0
- package/dist/agentSearch/searchUtils.js +125 -0
- package/dist/agentSearch/searchUtils.js.map +1 -0
- package/dist/agentSearch/workspaceMetadataIndexer.d.ts +3 -0
- package/dist/agentSearch/workspaceMetadataIndexer.d.ts.map +1 -0
- package/dist/agentSearch/workspaceMetadataIndexer.js +125 -0
- package/dist/agentSearch/workspaceMetadataIndexer.js.map +1 -0
- package/dist/cli/CliControlPlaneService.d.ts +269 -0
- package/dist/cli/CliControlPlaneService.d.ts.map +1 -0
- package/dist/cli/CliControlPlaneService.js +1874 -0
- package/dist/cli/CliControlPlaneService.js.map +1 -0
- package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.d.ts +91 -0
- package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.d.ts.map +1 -0
- package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.js +379 -0
- package/dist/cloud/XenoCloudAgentTurnExecutionAdapter.js.map +1 -0
- package/dist/codebase/CodebaseIntelligenceService.d.ts +68 -0
- package/dist/codebase/CodebaseIntelligenceService.d.ts.map +1 -0
- package/dist/codebase/CodebaseIntelligenceService.js +1717 -0
- package/dist/codebase/CodebaseIntelligenceService.js.map +1 -0
- package/dist/codebase/LanguageServerProcessManager.d.ts +85 -0
- package/dist/codebase/LanguageServerProcessManager.d.ts.map +1 -0
- package/dist/codebase/LanguageServerProcessManager.js +607 -0
- package/dist/codebase/LanguageServerProcessManager.js.map +1 -0
- package/dist/codebase/codeTypes.d.ts +485 -0
- package/dist/codebase/codeTypes.d.ts.map +1 -0
- package/dist/codebase/codeTypes.js +2 -0
- package/dist/codebase/codeTypes.js.map +1 -0
- package/dist/codebase/codeUtils.d.ts +24 -0
- package/dist/codebase/codeUtils.d.ts.map +1 -0
- package/dist/codebase/codeUtils.js +177 -0
- package/dist/codebase/codeUtils.js.map +1 -0
- package/dist/codebase/contextPacks.d.ts +18 -0
- package/dist/codebase/contextPacks.d.ts.map +1 -0
- package/dist/codebase/contextPacks.js +180 -0
- package/dist/codebase/contextPacks.js.map +1 -0
- package/dist/codebase/dependencyGraph.d.ts +3 -0
- package/dist/codebase/dependencyGraph.d.ts.map +1 -0
- package/dist/codebase/dependencyGraph.js +209 -0
- package/dist/codebase/dependencyGraph.js.map +1 -0
- package/dist/codebase/fileIndexer.d.ts +27 -0
- package/dist/codebase/fileIndexer.d.ts.map +1 -0
- package/dist/codebase/fileIndexer.js +167 -0
- package/dist/codebase/fileIndexer.js.map +1 -0
- package/dist/codebase/symbolIndexer.d.ts +3 -0
- package/dist/codebase/symbolIndexer.d.ts.map +1 -0
- package/dist/codebase/symbolIndexer.js +184 -0
- package/dist/codebase/symbolIndexer.js.map +1 -0
- package/dist/codebase/whatChanged.d.ts +4 -0
- package/dist/codebase/whatChanged.d.ts.map +1 -0
- package/dist/codebase/whatChanged.js +138 -0
- package/dist/codebase/whatChanged.js.map +1 -0
- package/dist/coordination/CoordinationService.d.ts +166 -0
- package/dist/coordination/CoordinationService.d.ts.map +1 -0
- package/dist/coordination/CoordinationService.js +247 -0
- package/dist/coordination/CoordinationService.js.map +1 -0
- package/dist/coordination/claims.d.ts +122 -0
- package/dist/coordination/claims.d.ts.map +1 -0
- package/dist/coordination/claims.js +196 -0
- package/dist/coordination/claims.js.map +1 -0
- package/dist/coordination/coordinationTools.d.ts +40 -0
- package/dist/coordination/coordinationTools.d.ts.map +1 -0
- package/dist/coordination/coordinationTools.js +92 -0
- package/dist/coordination/coordinationTools.js.map +1 -0
- package/dist/coordination/laneBridge.d.ts +84 -0
- package/dist/coordination/laneBridge.d.ts.map +1 -0
- package/dist/coordination/laneBridge.js +86 -0
- package/dist/coordination/laneBridge.js.map +1 -0
- package/dist/coordination/messages.d.ts +225 -0
- package/dist/coordination/messages.d.ts.map +1 -0
- package/dist/coordination/messages.js +335 -0
- package/dist/coordination/messages.js.map +1 -0
- package/dist/coordination/permissionWaitRegistry.d.ts +32 -0
- package/dist/coordination/permissionWaitRegistry.d.ts.map +1 -0
- package/dist/coordination/permissionWaitRegistry.js +59 -0
- package/dist/coordination/permissionWaitRegistry.js.map +1 -0
- package/dist/coordination/query.d.ts +187 -0
- package/dist/coordination/query.d.ts.map +1 -0
- package/dist/coordination/query.js +138 -0
- package/dist/coordination/query.js.map +1 -0
- package/dist/coordination/renderInbox.d.ts +15 -0
- package/dist/coordination/renderInbox.d.ts.map +1 -0
- package/dist/coordination/renderInbox.js +19 -0
- package/dist/coordination/renderInbox.js.map +1 -0
- package/dist/coordination/runtimeEvents.d.ts +53 -0
- package/dist/coordination/runtimeEvents.d.ts.map +1 -0
- package/dist/coordination/runtimeEvents.js +112 -0
- package/dist/coordination/runtimeEvents.js.map +1 -0
- package/dist/detachedHostService.d.ts +77 -0
- package/dist/detachedHostService.d.ts.map +1 -0
- package/dist/detachedHostService.js +66 -0
- package/dist/detachedHostService.js.map +1 -0
- package/dist/detachedHostSupervisor.d.ts +102 -0
- package/dist/detachedHostSupervisor.d.ts.map +1 -0
- package/dist/detachedHostSupervisor.js +168 -0
- package/dist/detachedHostSupervisor.js.map +1 -0
- package/dist/durableRuntimeEventStore.d.ts +49 -0
- package/dist/durableRuntimeEventStore.d.ts.map +1 -0
- package/dist/durableRuntimeEventStore.js +364 -0
- package/dist/durableRuntimeEventStore.js.map +1 -0
- package/dist/engineering/EngineeringWorkbenchService.d.ts +142 -0
- package/dist/engineering/EngineeringWorkbenchService.d.ts.map +1 -0
- package/dist/engineering/EngineeringWorkbenchService.js +2301 -0
- package/dist/engineering/EngineeringWorkbenchService.js.map +1 -0
- package/dist/engineering/LandingService.d.ts +112 -0
- package/dist/engineering/LandingService.d.ts.map +1 -0
- package/dist/engineering/LandingService.js +239 -0
- package/dist/engineering/LandingService.js.map +1 -0
- package/dist/engineering/engineeringTypes.d.ts +2 -0
- package/dist/engineering/engineeringTypes.d.ts.map +1 -0
- package/dist/engineering/engineeringTypes.js +2 -0
- package/dist/engineering/engineeringTypes.js.map +1 -0
- package/dist/engineering/patchReview.d.ts +11 -0
- package/dist/engineering/patchReview.d.ts.map +1 -0
- package/dist/engineering/patchReview.js +174 -0
- package/dist/engineering/patchReview.js.map +1 -0
- package/dist/index.d.ts +834 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3242 -0
- package/dist/index.js.map +1 -0
- package/dist/intake/IntakeService.d.ts +84 -0
- package/dist/intake/IntakeService.d.ts.map +1 -0
- package/dist/intake/IntakeService.js +117 -0
- package/dist/intake/IntakeService.js.map +1 -0
- package/dist/intake/RepositoryTodoIntakeSource.d.ts +72 -0
- package/dist/intake/RepositoryTodoIntakeSource.d.ts.map +1 -0
- package/dist/intake/RepositoryTodoIntakeSource.js +168 -0
- package/dist/intake/RepositoryTodoIntakeSource.js.map +1 -0
- package/dist/intake/WorkspaceTodoIntakeSource.d.ts +53 -0
- package/dist/intake/WorkspaceTodoIntakeSource.d.ts.map +1 -0
- package/dist/intake/WorkspaceTodoIntakeSource.js +81 -0
- package/dist/intake/WorkspaceTodoIntakeSource.js.map +1 -0
- package/dist/isolation/CommandExecution.d.ts +132 -0
- package/dist/isolation/CommandExecution.d.ts.map +1 -0
- package/dist/isolation/CommandExecution.js +48 -0
- package/dist/isolation/CommandExecution.js.map +1 -0
- package/dist/isolation/LocalCommandExecutor.d.ts +27 -0
- package/dist/isolation/LocalCommandExecutor.d.ts.map +1 -0
- package/dist/isolation/LocalCommandExecutor.js +97 -0
- package/dist/isolation/LocalCommandExecutor.js.map +1 -0
- package/dist/isolation/RunExecutionEnvironment.d.ts +135 -0
- package/dist/isolation/RunExecutionEnvironment.d.ts.map +1 -0
- package/dist/isolation/RunExecutionEnvironment.js +206 -0
- package/dist/isolation/RunExecutionEnvironment.js.map +1 -0
- package/dist/isolation/RunIsolationService.d.ts +90 -0
- package/dist/isolation/RunIsolationService.d.ts.map +1 -0
- package/dist/isolation/RunIsolationService.js +86 -0
- package/dist/isolation/RunIsolationService.js.map +1 -0
- package/dist/isolation/SandboxCommandExecutor.d.ts +93 -0
- package/dist/isolation/SandboxCommandExecutor.d.ts.map +1 -0
- package/dist/isolation/SandboxCommandExecutor.js +189 -0
- package/dist/isolation/SandboxCommandExecutor.js.map +1 -0
- package/dist/knowledge/WorkspaceKnowledgeService.d.ts +71 -0
- package/dist/knowledge/WorkspaceKnowledgeService.d.ts.map +1 -0
- package/dist/knowledge/WorkspaceKnowledgeService.js +103 -0
- package/dist/knowledge/WorkspaceKnowledgeService.js.map +1 -0
- package/dist/localHostAuthority.d.ts +24 -0
- package/dist/localHostAuthority.d.ts.map +1 -0
- package/dist/localHostAuthority.js +87 -0
- package/dist/localHostAuthority.js.map +1 -0
- package/dist/localHostLease.d.ts +51 -0
- package/dist/localHostLease.d.ts.map +1 -0
- package/dist/localHostLease.js +167 -0
- package/dist/localHostLease.js.map +1 -0
- package/dist/localHostPaths.d.ts +30 -0
- package/dist/localHostPaths.d.ts.map +1 -0
- package/dist/localHostPaths.js +60 -0
- package/dist/localHostPaths.js.map +1 -0
- package/dist/localRpcTransport.d.ts +21 -0
- package/dist/localRpcTransport.d.ts.map +1 -0
- package/dist/localRpcTransport.js +423 -0
- package/dist/localRpcTransport.js.map +1 -0
- package/dist/node.d.ts +104 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +103 -0
- package/dist/node.js.map +1 -0
- package/dist/observation/DirectoryBaselineScanner.d.ts +44 -0
- package/dist/observation/DirectoryBaselineScanner.d.ts.map +1 -0
- package/dist/observation/DirectoryBaselineScanner.js +112 -0
- package/dist/observation/DirectoryBaselineScanner.js.map +1 -0
- package/dist/observation/MountContentReader.d.ts +63 -0
- package/dist/observation/MountContentReader.d.ts.map +1 -0
- package/dist/observation/MountContentReader.js +158 -0
- package/dist/observation/MountContentReader.js.map +1 -0
- package/dist/observation/RunObservationService.d.ts +229 -0
- package/dist/observation/RunObservationService.d.ts.map +1 -0
- package/dist/observation/RunObservationService.js +248 -0
- package/dist/observation/RunObservationService.js.map +1 -0
- package/dist/observation/XenoUseObservationSource.d.ts +42 -0
- package/dist/observation/XenoUseObservationSource.d.ts.map +1 -0
- package/dist/observation/XenoUseObservationSource.js +104 -0
- package/dist/observation/XenoUseObservationSource.js.map +1 -0
- package/dist/observation/XenoUseRunObserver.d.ts +140 -0
- package/dist/observation/XenoUseRunObserver.d.ts.map +1 -0
- package/dist/observation/XenoUseRunObserver.js +256 -0
- package/dist/observation/XenoUseRunObserver.js.map +1 -0
- package/dist/pluginMcp/PluginMcpManagerService.d.ts +141 -0
- package/dist/pluginMcp/PluginMcpManagerService.d.ts.map +1 -0
- package/dist/pluginMcp/PluginMcpManagerService.js +1821 -0
- package/dist/pluginMcp/PluginMcpManagerService.js.map +1 -0
- package/dist/pluginMcp/pluginMcpTypes.d.ts +349 -0
- package/dist/pluginMcp/pluginMcpTypes.d.ts.map +1 -0
- package/dist/pluginMcp/pluginMcpTypes.js +2 -0
- package/dist/pluginMcp/pluginMcpTypes.js.map +1 -0
- package/dist/policy/WorkspacePolicyService.d.ts +83 -0
- package/dist/policy/WorkspacePolicyService.d.ts.map +1 -0
- package/dist/policy/WorkspacePolicyService.js +809 -0
- package/dist/policy/WorkspacePolicyService.js.map +1 -0
- package/dist/policy/policyGuard.d.ts +27 -0
- package/dist/policy/policyGuard.d.ts.map +1 -0
- package/dist/policy/policyGuard.js +143 -0
- package/dist/policy/policyGuard.js.map +1 -0
- package/dist/policy/policyTypes.d.ts +190 -0
- package/dist/policy/policyTypes.d.ts.map +1 -0
- package/dist/policy/policyTypes.js +2 -0
- package/dist/policy/policyTypes.js.map +1 -0
- package/dist/runtime/RuntimeEventStore.d.ts +42 -0
- package/dist/runtime/RuntimeEventStore.d.ts.map +1 -0
- package/dist/runtime/RuntimeEventStore.js +412 -0
- package/dist/runtime/RuntimeEventStore.js.map +1 -0
- package/dist/runtime/RuntimeEventStoreRepositoryAdapter.d.ts +21 -0
- package/dist/runtime/RuntimeEventStoreRepositoryAdapter.d.ts.map +1 -0
- package/dist/runtime/RuntimeEventStoreRepositoryAdapter.js +41 -0
- package/dist/runtime/RuntimeEventStoreRepositoryAdapter.js.map +1 -0
- package/dist/runtime/RuntimeTimelineProjection.d.ts +5 -0
- package/dist/runtime/RuntimeTimelineProjection.d.ts.map +1 -0
- package/dist/runtime/RuntimeTimelineProjection.js +705 -0
- package/dist/runtime/RuntimeTimelineProjection.js.map +1 -0
- package/dist/runtime/runtimeEventTypes.d.ts +73 -0
- package/dist/runtime/runtimeEventTypes.d.ts.map +1 -0
- package/dist/runtime/runtimeEventTypes.js +2 -0
- package/dist/runtime/runtimeEventTypes.js.map +1 -0
- package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.d.ts +117 -0
- package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.d.ts.map +1 -0
- package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.js +214 -0
- package/dist/sdk/SdkNativeAgentTurnExecutionAdapter.js.map +1 -0
- package/dist/session/AgentSessionService.d.ts +285 -0
- package/dist/session/AgentSessionService.d.ts.map +1 -0
- package/dist/session/AgentSessionService.js +444 -0
- package/dist/session/AgentSessionService.js.map +1 -0
- package/dist/session/bufferedSessionPty.d.ts +27 -0
- package/dist/session/bufferedSessionPty.d.ts.map +1 -0
- package/dist/session/bufferedSessionPty.js +49 -0
- package/dist/session/bufferedSessionPty.js.map +1 -0
- package/dist/session/renderSupport.d.ts +53 -0
- package/dist/session/renderSupport.d.ts.map +1 -0
- package/dist/session/renderSupport.js +41 -0
- package/dist/session/renderSupport.js.map +1 -0
- package/dist/session/runtimeEventChannel.d.ts +56 -0
- package/dist/session/runtimeEventChannel.d.ts.map +1 -0
- package/dist/session/runtimeEventChannel.js +53 -0
- package/dist/session/runtimeEventChannel.js.map +1 -0
- package/dist/state/JsonAgentStateRepository.d.ts +29 -0
- package/dist/state/JsonAgentStateRepository.d.ts.map +1 -0
- package/dist/state/JsonAgentStateRepository.js +165 -0
- package/dist/state/JsonAgentStateRepository.js.map +1 -0
- package/dist/state/SqliteAgentStateRepository.d.ts +58 -0
- package/dist/state/SqliteAgentStateRepository.d.ts.map +1 -0
- package/dist/state/SqliteAgentStateRepository.js +777 -0
- package/dist/state/SqliteAgentStateRepository.js.map +1 -0
- package/dist/state/createAgentStateRepository.d.ts +4 -0
- package/dist/state/createAgentStateRepository.d.ts.map +1 -0
- package/dist/state/createAgentStateRepository.js +12 -0
- package/dist/state/createAgentStateRepository.js.map +1 -0
- package/dist/state/stateSanitizers.d.ts +7 -0
- package/dist/state/stateSanitizers.d.ts.map +1 -0
- package/dist/state/stateSanitizers.js +87 -0
- package/dist/state/stateSanitizers.js.map +1 -0
- package/dist/subagents/AcpSubagentExecutionAdapter.d.ts +12 -0
- package/dist/subagents/AcpSubagentExecutionAdapter.d.ts.map +1 -0
- package/dist/subagents/AcpSubagentExecutionAdapter.js +119 -0
- package/dist/subagents/AcpSubagentExecutionAdapter.js.map +1 -0
- package/dist/subagents/CliSubagentExecutionAdapter.d.ts +13 -0
- package/dist/subagents/CliSubagentExecutionAdapter.d.ts.map +1 -0
- package/dist/subagents/CliSubagentExecutionAdapter.js +217 -0
- package/dist/subagents/CliSubagentExecutionAdapter.js.map +1 -0
- package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts +78 -0
- package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts.map +1 -0
- package/dist/subagents/HostTurnSubagentExecutionAdapter.js +160 -0
- package/dist/subagents/HostTurnSubagentExecutionAdapter.js.map +1 -0
- package/dist/subagents/SubagentRunService.d.ts +103 -0
- package/dist/subagents/SubagentRunService.d.ts.map +1 -0
- package/dist/subagents/SubagentRunService.js +1183 -0
- package/dist/subagents/SubagentRunService.js.map +1 -0
- package/dist/subagents/SubagentScheduler.d.ts +167 -0
- package/dist/subagents/SubagentScheduler.d.ts.map +1 -0
- package/dist/subagents/SubagentScheduler.js +530 -0
- package/dist/subagents/SubagentScheduler.js.map +1 -0
- package/dist/subagents/TeamAgentRouter.d.ts +104 -0
- package/dist/subagents/TeamAgentRouter.d.ts.map +1 -0
- package/dist/subagents/TeamAgentRouter.js +435 -0
- package/dist/subagents/TeamAgentRouter.js.map +1 -0
- package/dist/subagents/capabilityMatcher.d.ts +3 -0
- package/dist/subagents/capabilityMatcher.d.ts.map +1 -0
- package/dist/subagents/capabilityMatcher.js +127 -0
- package/dist/subagents/capabilityMatcher.js.map +1 -0
- package/dist/subagents/subagentRunPort.d.ts +43 -0
- package/dist/subagents/subagentRunPort.d.ts.map +1 -0
- package/dist/subagents/subagentRunPort.js +24 -0
- package/dist/subagents/subagentRunPort.js.map +1 -0
- package/dist/subagents/subagentTypes.d.ts +330 -0
- package/dist/subagents/subagentTypes.d.ts.map +1 -0
- package/dist/subagents/subagentTypes.js +2 -0
- package/dist/subagents/subagentTypes.js.map +1 -0
- package/dist/subagents/subagentWorkspaceAuthority.d.ts +29 -0
- package/dist/subagents/subagentWorkspaceAuthority.d.ts.map +1 -0
- package/dist/subagents/subagentWorkspaceAuthority.js +173 -0
- package/dist/subagents/subagentWorkspaceAuthority.js.map +1 -0
- package/dist/support/SupportDiagnosticsService.d.ts +87 -0
- package/dist/support/SupportDiagnosticsService.d.ts.map +1 -0
- package/dist/support/SupportDiagnosticsService.js +1199 -0
- package/dist/support/SupportDiagnosticsService.js.map +1 -0
- package/dist/turns/DurableInterruptedTurnStore.d.ts +14 -0
- package/dist/turns/DurableInterruptedTurnStore.d.ts.map +1 -0
- package/dist/turns/DurableInterruptedTurnStore.js +63 -0
- package/dist/turns/DurableInterruptedTurnStore.js.map +1 -0
- package/dist/turns/interruptedTurns.d.ts +50 -0
- package/dist/turns/interruptedTurns.d.ts.map +1 -0
- package/dist/turns/interruptedTurns.js +54 -0
- package/dist/turns/interruptedTurns.js.map +1 -0
- package/dist/turns/turnAdmission.d.ts +113 -0
- package/dist/turns/turnAdmission.d.ts.map +1 -0
- package/dist/turns/turnAdmission.js +136 -0
- package/dist/turns/turnAdmission.js.map +1 -0
- package/dist/workspace/WorkspaceHostService.d.ts +126 -0
- package/dist/workspace/WorkspaceHostService.d.ts.map +1 -0
- package/dist/workspace/WorkspaceHostService.js +841 -0
- package/dist/workspace/WorkspaceHostService.js.map +1 -0
- package/dist/workspace/WorkspaceShellService.d.ts +71 -0
- package/dist/workspace/WorkspaceShellService.d.ts.map +1 -0
- package/dist/workspace/WorkspaceShellService.js +273 -0
- package/dist/workspace/WorkspaceShellService.js.map +1 -0
- package/dist/workspace/fileAssociations.d.ts +12 -0
- package/dist/workspace/fileAssociations.d.ts.map +1 -0
- package/dist/workspace/fileAssociations.js +202 -0
- package/dist/workspace/fileAssociations.js.map +1 -0
- package/dist/workspace/scrollbackBuffer.d.ts +48 -0
- package/dist/workspace/scrollbackBuffer.d.ts.map +1 -0
- package/dist/workspace/scrollbackBuffer.js +94 -0
- package/dist/workspace/scrollbackBuffer.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from 'fs';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { JsonInvertedIndexAdapter } from './JsonInvertedIndexAdapter.js';
|
|
6
|
+
import { createSqliteFtsIndexAdapter } from './SqliteFtsIndexAdapter.js';
|
|
7
|
+
import { indexConversation, indexRuntimeEventEnvelope } from './conversationIndexer.js';
|
|
8
|
+
import { indexWorkspaceMetadata } from './workspaceMetadataIndexer.js';
|
|
9
|
+
import { getWorkspacePolicyService } from '../policy/WorkspacePolicyService.js';
|
|
10
|
+
import { getPluginMcpManagerService } from '../pluginMcp/PluginMcpManagerService.js';
|
|
11
|
+
import { createScopeAcl, estimateTokens, normalizeSearchText, stableDocumentId } from './searchUtils.js';
|
|
12
|
+
const XENO_DIR = join(homedir(), '.xeno');
|
|
13
|
+
const AGENT_CHATS_DIR = join(XENO_DIR, 'agent-chats');
|
|
14
|
+
const RUNTIME_EVENTS_DIR = join(XENO_DIR, 'runtime-events');
|
|
15
|
+
const WORKSPACES_FILE = join(XENO_DIR, 'workspaces.json');
|
|
16
|
+
const SEARCH_DIR = join(XENO_DIR, 'indexes', 'hub-search');
|
|
17
|
+
const SEARCH_MANIFEST = join(SEARCH_DIR, 'manifest.json');
|
|
18
|
+
const SEARCH_SNAPSHOT = join(SEARCH_DIR, 'fallback-inverted.json');
|
|
19
|
+
const SEARCH_SQLITE_DB = join(SEARCH_DIR, 'hub-search.sqlite');
|
|
20
|
+
const ATTACHMENTS_FILE = join(SEARCH_DIR, 'attachments.json');
|
|
21
|
+
const QUERY_PROFILE_FILE = join(SEARCH_DIR, 'query-profile.json');
|
|
22
|
+
const INDEX_LIFECYCLE_FILE = join(SEARCH_DIR, 'index-lifecycle.json');
|
|
23
|
+
const MAX_PROFILE_ENTRIES = 250;
|
|
24
|
+
const MAX_DIRTY_SOURCES = 250;
|
|
25
|
+
const MAX_QUEUED_JOBS = 25;
|
|
26
|
+
const SLOW_QUERY_MS = 750;
|
|
27
|
+
const POLICY_SOURCE_DIRS = [
|
|
28
|
+
join(XENO_DIR, 'memory'),
|
|
29
|
+
join(XENO_DIR, 'artifacts'),
|
|
30
|
+
join(XENO_DIR, 'task-boards'),
|
|
31
|
+
join(XENO_DIR, 'plugins'),
|
|
32
|
+
join(XENO_DIR, 'mcp'),
|
|
33
|
+
];
|
|
34
|
+
class IndexJobCancelledError extends Error {
|
|
35
|
+
constructor(message = 'Search index job was cancelled.') {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = 'IndexJobCancelledError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function ensureSearchDir() {
|
|
41
|
+
if (!existsSync(SEARCH_DIR))
|
|
42
|
+
mkdirSync(SEARCH_DIR, { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
function safeReadJson(path, fallback) {
|
|
45
|
+
try {
|
|
46
|
+
if (!existsSync(path))
|
|
47
|
+
return fallback;
|
|
48
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return fallback;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function safeWriteJson(path, value) {
|
|
55
|
+
ensureSearchDir();
|
|
56
|
+
writeFileSync(path, JSON.stringify(value, null, 2), 'utf-8');
|
|
57
|
+
}
|
|
58
|
+
function fileFingerprint(path) {
|
|
59
|
+
try {
|
|
60
|
+
const stat = statSync(path);
|
|
61
|
+
return `${path}:${stat.size}:${Math.round(stat.mtimeMs)}`;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return `${path}:missing`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function directoryFingerprint(path) {
|
|
68
|
+
try {
|
|
69
|
+
if (!existsSync(path))
|
|
70
|
+
return `${path}:missing`;
|
|
71
|
+
const parts = [];
|
|
72
|
+
const visit = (dir) => {
|
|
73
|
+
for (const name of readdirSync(dir).sort()) {
|
|
74
|
+
const child = join(dir, name);
|
|
75
|
+
const stat = statSync(child);
|
|
76
|
+
if (stat.isDirectory()) {
|
|
77
|
+
visit(child);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
parts.push(`${child}:${stat.size}:${Math.round(stat.mtimeMs)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
visit(path);
|
|
85
|
+
return createHash('sha256').update(parts.join('\n')).digest('hex');
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return `${path}:error`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function computeSourceFingerprint() {
|
|
92
|
+
const parts = [fileFingerprint(WORKSPACES_FILE)];
|
|
93
|
+
try {
|
|
94
|
+
if (existsSync(AGENT_CHATS_DIR)) {
|
|
95
|
+
const files = readdirSync(AGENT_CHATS_DIR)
|
|
96
|
+
.filter((file) => file.endsWith('.json'))
|
|
97
|
+
.sort();
|
|
98
|
+
for (const file of files)
|
|
99
|
+
parts.push(fileFingerprint(join(AGENT_CHATS_DIR, file)));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
parts.push('agent-chats:error');
|
|
104
|
+
}
|
|
105
|
+
parts.push(directoryFingerprint(RUNTIME_EVENTS_DIR));
|
|
106
|
+
for (const dir of POLICY_SOURCE_DIRS)
|
|
107
|
+
parts.push(directoryFingerprint(dir));
|
|
108
|
+
return createHash('sha256').update(parts.join('\n')).digest('hex');
|
|
109
|
+
}
|
|
110
|
+
function getConversationId(value) {
|
|
111
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
112
|
+
return undefined;
|
|
113
|
+
const id = value.id;
|
|
114
|
+
return typeof id === 'string' && id.trim() ? id.trim() : undefined;
|
|
115
|
+
}
|
|
116
|
+
function getRuntimeEventConversationId(value) {
|
|
117
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
118
|
+
return undefined;
|
|
119
|
+
const record = value;
|
|
120
|
+
if (typeof record.conversationId === 'string' && record.conversationId.trim())
|
|
121
|
+
return record.conversationId.trim();
|
|
122
|
+
const event = record.event;
|
|
123
|
+
if (event && typeof event === 'object' && !Array.isArray(event)) {
|
|
124
|
+
const eventConversationId = event.conversationId;
|
|
125
|
+
if (typeof eventConversationId === 'string' && eventConversationId.trim())
|
|
126
|
+
return eventConversationId.trim();
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
function readConversationSummary(conversationId) {
|
|
131
|
+
const safeId = conversationId.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 200);
|
|
132
|
+
const conversationPath = join(AGENT_CHATS_DIR, `${safeId}.json`);
|
|
133
|
+
const conversation = safeReadJson(conversationPath, null);
|
|
134
|
+
if (!conversation) {
|
|
135
|
+
return { summary: '', tokenEstimate: 0, acl: { visibility: 'global' } };
|
|
136
|
+
}
|
|
137
|
+
const title = normalizeSearchText(conversation.title || 'Conversation');
|
|
138
|
+
const messages = Array.isArray(conversation.messages) ? conversation.messages : [];
|
|
139
|
+
const selected = messages.slice(-10)
|
|
140
|
+
.map((message) => {
|
|
141
|
+
const role = normalizeSearchText(message.role || 'message');
|
|
142
|
+
const content = normalizeSearchText(message.content || message.error || message.command || '');
|
|
143
|
+
return content ? `${role}: ${content}` : '';
|
|
144
|
+
})
|
|
145
|
+
.filter(Boolean);
|
|
146
|
+
const summary = [title, ...selected].join('\n').slice(0, 12_000);
|
|
147
|
+
const scope = {
|
|
148
|
+
workspaceId: typeof conversation.workspaceId === 'string' ? conversation.workspaceId : undefined,
|
|
149
|
+
teamId: typeof conversation.teamId === 'string' ? conversation.teamId : undefined,
|
|
150
|
+
agentId: typeof conversation.agentId === 'string' ? conversation.agentId : undefined,
|
|
151
|
+
conversationId,
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
summary,
|
|
155
|
+
tokenEstimate: estimateTokens(summary),
|
|
156
|
+
acl: createScopeAcl(scope, 'global'),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export class AgentSearchService {
|
|
160
|
+
index = new JsonInvertedIndexAdapter();
|
|
161
|
+
indexInit = null;
|
|
162
|
+
building = false;
|
|
163
|
+
ready = false;
|
|
164
|
+
error;
|
|
165
|
+
adapterFallbackReason;
|
|
166
|
+
sqliteAvailable = false;
|
|
167
|
+
lastQueryMs;
|
|
168
|
+
lastFreshCheckMs;
|
|
169
|
+
lastRebuildMs;
|
|
170
|
+
sourceFingerprint = null;
|
|
171
|
+
lastFreshCheckAt = 0;
|
|
172
|
+
queryProfileCache = null;
|
|
173
|
+
activeJob = null;
|
|
174
|
+
queuedJobs = [];
|
|
175
|
+
lastJob;
|
|
176
|
+
interruptedJob;
|
|
177
|
+
dirtySources = [];
|
|
178
|
+
crashResumeAvailable = false;
|
|
179
|
+
processingQueue = false;
|
|
180
|
+
cancelledJobIds = new Set();
|
|
181
|
+
constructor() {
|
|
182
|
+
this.restoreLifecycleState();
|
|
183
|
+
}
|
|
184
|
+
async query(request) {
|
|
185
|
+
const t0 = Date.now();
|
|
186
|
+
try {
|
|
187
|
+
await this.ensureFresh();
|
|
188
|
+
const result = this.index.search(request);
|
|
189
|
+
this.lastQueryMs = Date.now() - t0;
|
|
190
|
+
this.recordQueryProfile({
|
|
191
|
+
request,
|
|
192
|
+
durationMs: this.lastQueryMs,
|
|
193
|
+
resultCount: result.total,
|
|
194
|
+
success: true,
|
|
195
|
+
});
|
|
196
|
+
return { success: true, ...result, stats: this.buildStats() };
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
200
|
+
this.error = error;
|
|
201
|
+
this.lastQueryMs = Date.now() - t0;
|
|
202
|
+
this.recordQueryProfile({
|
|
203
|
+
request,
|
|
204
|
+
durationMs: this.lastQueryMs,
|
|
205
|
+
resultCount: 0,
|
|
206
|
+
success: false,
|
|
207
|
+
error,
|
|
208
|
+
});
|
|
209
|
+
return { success: false, results: [], total: 0, error, stats: this.buildStats() };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async hydrate(request) {
|
|
213
|
+
try {
|
|
214
|
+
await this.ensureFresh();
|
|
215
|
+
const document = this.index.getDocument(String(request.id || ''));
|
|
216
|
+
if (!document)
|
|
217
|
+
return { success: false, error: 'Search result not found.' };
|
|
218
|
+
return { success: true, document };
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async reindex(request = {}) {
|
|
225
|
+
if (request.cancelActive) {
|
|
226
|
+
this.cancelIndexing({ reason: request.reason || 'Superseded by a new reindex request.' });
|
|
227
|
+
}
|
|
228
|
+
await this.ensureIndexAdapter();
|
|
229
|
+
const job = this.createIndexJob(request.reason === 'crash-resume' ? 'crash-resume' : 'reindex', {
|
|
230
|
+
force: !!request.force,
|
|
231
|
+
reason: request.reason,
|
|
232
|
+
sourceFingerprint: computeSourceFingerprint(),
|
|
233
|
+
});
|
|
234
|
+
return this.enqueueIndexJob(job);
|
|
235
|
+
}
|
|
236
|
+
cancelIndexing(request = {}) {
|
|
237
|
+
const reason = normalizeSearchText(request.reason || 'Cancelled by user.') || 'Cancelled by user.';
|
|
238
|
+
let cancelledQueued = 0;
|
|
239
|
+
if (this.activeJob && (!request.jobId || request.jobId === this.activeJob.id)) {
|
|
240
|
+
this.cancelledJobIds.add(this.activeJob.id);
|
|
241
|
+
this.activeJob.error = reason;
|
|
242
|
+
this.activeJob.progress = {
|
|
243
|
+
...this.activeJob.progress,
|
|
244
|
+
phase: 'cancelled',
|
|
245
|
+
updatedAt: Date.now(),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const remaining = [];
|
|
249
|
+
for (const queued of this.queuedJobs) {
|
|
250
|
+
if (request.jobId && request.jobId !== queued.job.id) {
|
|
251
|
+
remaining.push(queued);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
queued.job.status = 'cancelled';
|
|
255
|
+
queued.job.error = reason;
|
|
256
|
+
queued.job.finishedAt = Date.now();
|
|
257
|
+
queued.job.progress = { ...queued.job.progress, phase: 'cancelled', updatedAt: Date.now() };
|
|
258
|
+
this.lastJob = queued.job;
|
|
259
|
+
cancelledQueued += 1;
|
|
260
|
+
queued.resolve(this.buildStatusSnapshot());
|
|
261
|
+
}
|
|
262
|
+
this.queuedJobs = remaining;
|
|
263
|
+
if (cancelledQueued > 0)
|
|
264
|
+
this.persistLifecycleState();
|
|
265
|
+
return this.buildStatusSnapshot();
|
|
266
|
+
}
|
|
267
|
+
async status() {
|
|
268
|
+
await this.ensureFresh(false);
|
|
269
|
+
return this.buildStatusSnapshot();
|
|
270
|
+
}
|
|
271
|
+
async health() {
|
|
272
|
+
await this.ensureIndexAdapter();
|
|
273
|
+
return this.buildHealth();
|
|
274
|
+
}
|
|
275
|
+
async profile(request = {}) {
|
|
276
|
+
await this.ensureIndexAdapter();
|
|
277
|
+
return this.buildQueryProfile(request);
|
|
278
|
+
}
|
|
279
|
+
lifecycleStatus() {
|
|
280
|
+
return this.buildLifecycleStatus();
|
|
281
|
+
}
|
|
282
|
+
async repair(request = {}) {
|
|
283
|
+
const startedAt = Date.now();
|
|
284
|
+
const repaired = [];
|
|
285
|
+
try {
|
|
286
|
+
ensureSearchDir();
|
|
287
|
+
if (request.cleanSnapshot) {
|
|
288
|
+
repaired.push(this.tryDeleteFile(SEARCH_MANIFEST, 'search-manifest'));
|
|
289
|
+
repaired.push(this.tryDeleteFile(SEARCH_SNAPSHOT, 'search-snapshot'));
|
|
290
|
+
}
|
|
291
|
+
if (request.cleanupOrphans !== false) {
|
|
292
|
+
repaired.push(this.cleanupOrphanedSearchArtifacts());
|
|
293
|
+
}
|
|
294
|
+
await this.reindex({
|
|
295
|
+
force: request.force !== false,
|
|
296
|
+
reason: this.crashResumeAvailable ? 'repair after interrupted search indexing' : 'search repair rebuild',
|
|
297
|
+
cancelActive: true,
|
|
298
|
+
});
|
|
299
|
+
if (request.compact !== false) {
|
|
300
|
+
repaired.push(this.compactIndex());
|
|
301
|
+
}
|
|
302
|
+
const status = await this.status();
|
|
303
|
+
const corruptCount = status.stats.corruptConversationCount || 0;
|
|
304
|
+
if (corruptCount > 0) {
|
|
305
|
+
repaired.push({
|
|
306
|
+
id: 'corrupt-conversation-files',
|
|
307
|
+
success: true,
|
|
308
|
+
detail: `${corruptCount} corrupt conversation file${corruptCount === 1 ? '' : 's'} skipped; index remains available.`,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
repaired.push({
|
|
312
|
+
id: 'search-index-rebuild',
|
|
313
|
+
success: !status.error && status.ready,
|
|
314
|
+
detail: `backend=${status.stats.backend} docs=${status.stats.documentCount}`,
|
|
315
|
+
error: status.error,
|
|
316
|
+
});
|
|
317
|
+
return {
|
|
318
|
+
success: repaired.every((entry) => entry.success),
|
|
319
|
+
status,
|
|
320
|
+
repaired,
|
|
321
|
+
durationMs: Date.now() - startedAt,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
const status = await this.status().catch(() => ({
|
|
326
|
+
ready: this.ready,
|
|
327
|
+
building: this.building,
|
|
328
|
+
error: err instanceof Error ? err.message : String(err),
|
|
329
|
+
stats: this.buildStats(),
|
|
330
|
+
health: this.buildHealth(),
|
|
331
|
+
}));
|
|
332
|
+
return {
|
|
333
|
+
success: false,
|
|
334
|
+
status,
|
|
335
|
+
repaired,
|
|
336
|
+
durationMs: Date.now() - startedAt,
|
|
337
|
+
error: err instanceof Error ? err.message : String(err),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
async attachConversation(request) {
|
|
342
|
+
const sourceConversationId = normalizeSearchText(request.sourceConversationId);
|
|
343
|
+
const targetConversationId = normalizeSearchText(request.targetConversationId);
|
|
344
|
+
if (!sourceConversationId || !targetConversationId) {
|
|
345
|
+
return { success: false, error: 'Missing source or target conversation ID.' };
|
|
346
|
+
}
|
|
347
|
+
if (sourceConversationId === targetConversationId) {
|
|
348
|
+
return { success: false, error: 'A conversation cannot attach itself.' };
|
|
349
|
+
}
|
|
350
|
+
const attachments = this.loadAttachments();
|
|
351
|
+
const existing = attachments.find((attachment) => (attachment.sourceConversationId === sourceConversationId
|
|
352
|
+
&& attachment.targetConversationId === targetConversationId));
|
|
353
|
+
if (existing)
|
|
354
|
+
return { success: true, attachment: existing };
|
|
355
|
+
const summary = readConversationSummary(sourceConversationId);
|
|
356
|
+
const attachment = {
|
|
357
|
+
id: stableDocumentId('attachment', targetConversationId, sourceConversationId, Date.now()),
|
|
358
|
+
sourceConversationId,
|
|
359
|
+
targetConversationId,
|
|
360
|
+
attachedByAgentId: normalizeSearchText(request.attachedByAgentId) || undefined,
|
|
361
|
+
attachedAt: Date.now(),
|
|
362
|
+
mode: request.mode || 'summary',
|
|
363
|
+
selectedMessageIds: request.selectedMessageIds,
|
|
364
|
+
selectedToolCallIds: request.selectedToolCallIds,
|
|
365
|
+
summary: summary.summary,
|
|
366
|
+
tokenEstimate: summary.tokenEstimate,
|
|
367
|
+
aclSnapshot: summary.acl,
|
|
368
|
+
};
|
|
369
|
+
attachments.push(attachment);
|
|
370
|
+
this.saveAttachments(attachments);
|
|
371
|
+
return { success: true, attachment };
|
|
372
|
+
}
|
|
373
|
+
listAttachments(conversationId) {
|
|
374
|
+
const id = normalizeSearchText(conversationId);
|
|
375
|
+
if (!id)
|
|
376
|
+
return { success: false, attachments: [], error: 'Missing conversation ID.' };
|
|
377
|
+
return {
|
|
378
|
+
success: true,
|
|
379
|
+
attachments: this.loadAttachments().filter((attachment) => attachment.targetConversationId === id),
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
detachConversation(attachmentId) {
|
|
383
|
+
const id = normalizeSearchText(attachmentId);
|
|
384
|
+
if (!id)
|
|
385
|
+
return { success: false, error: 'Missing attachment ID.' };
|
|
386
|
+
const before = this.loadAttachments();
|
|
387
|
+
const after = before.filter((attachment) => attachment.id !== id);
|
|
388
|
+
this.saveAttachments(after);
|
|
389
|
+
return { success: true };
|
|
390
|
+
}
|
|
391
|
+
notifySourcesChanged(sourcePath = 'unknown') {
|
|
392
|
+
this.lastFreshCheckAt = 0;
|
|
393
|
+
this.markDirtySource(sourcePath, 'dirty');
|
|
394
|
+
}
|
|
395
|
+
async ensureFresh(loadSnapshot = true) {
|
|
396
|
+
const t0 = Date.now();
|
|
397
|
+
await this.ensureIndexAdapter();
|
|
398
|
+
if (this.building || this.activeJob) {
|
|
399
|
+
this.lastFreshCheckMs = Date.now() - t0;
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const now = Date.now();
|
|
403
|
+
if (this.ready && now - this.lastFreshCheckAt < 750) {
|
|
404
|
+
this.lastFreshCheckMs = Date.now() - t0;
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
this.lastFreshCheckAt = now;
|
|
408
|
+
const fingerprint = computeSourceFingerprint();
|
|
409
|
+
if (this.crashResumeAvailable) {
|
|
410
|
+
await this.reindex({ force: true, reason: 'crash-resume' });
|
|
411
|
+
this.lastFreshCheckMs = Date.now() - t0;
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (this.ready && this.sourceFingerprint === fingerprint) {
|
|
415
|
+
this.lastFreshCheckMs = Date.now() - t0;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (loadSnapshot && this.tryLoadSnapshot(fingerprint)) {
|
|
419
|
+
this.lastFreshCheckMs = Date.now() - t0;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
await this.reindex({
|
|
423
|
+
force: true,
|
|
424
|
+
reason: this.crashResumeAvailable ? 'crash-resume' : 'source fingerprint changed',
|
|
425
|
+
});
|
|
426
|
+
this.lastFreshCheckMs = Date.now() - t0;
|
|
427
|
+
}
|
|
428
|
+
async ensureIndexAdapter() {
|
|
429
|
+
if (this.indexInit)
|
|
430
|
+
return this.indexInit;
|
|
431
|
+
this.indexInit = (async () => {
|
|
432
|
+
try {
|
|
433
|
+
this.index = await createSqliteFtsIndexAdapter(SEARCH_SQLITE_DB);
|
|
434
|
+
this.sqliteAvailable = true;
|
|
435
|
+
this.adapterFallbackReason = undefined;
|
|
436
|
+
}
|
|
437
|
+
catch {
|
|
438
|
+
this.sqliteAvailable = false;
|
|
439
|
+
this.adapterFallbackReason = 'node:sqlite is unavailable in this runtime; using JSON inverted index fallback.';
|
|
440
|
+
this.index = new JsonInvertedIndexAdapter();
|
|
441
|
+
}
|
|
442
|
+
})();
|
|
443
|
+
return this.indexInit;
|
|
444
|
+
}
|
|
445
|
+
async rebuild(_force, knownFingerprint, job) {
|
|
446
|
+
if (this.building)
|
|
447
|
+
return;
|
|
448
|
+
this.building = true;
|
|
449
|
+
this.error = undefined;
|
|
450
|
+
const t0 = Date.now();
|
|
451
|
+
try {
|
|
452
|
+
const fingerprint = knownFingerprint || computeSourceFingerprint();
|
|
453
|
+
const source = await this.loadSourceDocuments(job);
|
|
454
|
+
if (job && this.cancelledJobIds.has(job.id))
|
|
455
|
+
throw new IndexJobCancelledError();
|
|
456
|
+
this.updateJobProgress(job, 'indexing', source.documents.length, source.documents.length, 'search-index');
|
|
457
|
+
this.index.replaceAll(source.documents, {
|
|
458
|
+
sourceConversationCount: source.sourceConversationCount,
|
|
459
|
+
sourceWorkspaceCount: source.sourceWorkspaceCount,
|
|
460
|
+
corruptConversationCount: source.corruptConversationCount,
|
|
461
|
+
});
|
|
462
|
+
if (job && this.cancelledJobIds.has(job.id))
|
|
463
|
+
throw new IndexJobCancelledError();
|
|
464
|
+
this.updateJobProgress(job, 'persisting', source.documents.length, source.documents.length, SEARCH_SNAPSHOT);
|
|
465
|
+
this.sourceFingerprint = fingerprint;
|
|
466
|
+
this.ready = true;
|
|
467
|
+
this.saveSnapshot(fingerprint);
|
|
468
|
+
this.lastRebuildMs = Date.now() - t0;
|
|
469
|
+
}
|
|
470
|
+
catch (err) {
|
|
471
|
+
this.error = err instanceof Error ? err.message : String(err);
|
|
472
|
+
throw err;
|
|
473
|
+
}
|
|
474
|
+
finally {
|
|
475
|
+
this.building = false;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
buildStats() {
|
|
479
|
+
const profile = this.buildQueryProfile({ limit: MAX_PROFILE_ENTRIES });
|
|
480
|
+
return {
|
|
481
|
+
...this.index.getStats(),
|
|
482
|
+
sqliteAvailable: this.sqliteAvailable,
|
|
483
|
+
fallbackReason: this.adapterFallbackReason,
|
|
484
|
+
lastQueryMs: this.lastQueryMs,
|
|
485
|
+
lastFreshCheckMs: this.lastFreshCheckMs,
|
|
486
|
+
lastRebuildMs: this.lastRebuildMs,
|
|
487
|
+
slowQueryCount: profile.slowQueries.length,
|
|
488
|
+
averageQueryMs: profile.averageQueryMs ?? undefined,
|
|
489
|
+
p95QueryMs: profile.p95QueryMs ?? undefined,
|
|
490
|
+
failedQueryCount: profile.failedQueryCount,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
buildHealth() {
|
|
494
|
+
const manifest = safeReadJson(SEARCH_MANIFEST, null);
|
|
495
|
+
const snapshotPresent = existsSync(SEARCH_SNAPSHOT);
|
|
496
|
+
const currentFingerprint = computeSourceFingerprint();
|
|
497
|
+
const manifestFingerprint = manifest?.sourceFingerprint || null;
|
|
498
|
+
const stale = !!manifestFingerprint && manifestFingerprint !== currentFingerprint;
|
|
499
|
+
const stats = this.buildStats();
|
|
500
|
+
const issues = [];
|
|
501
|
+
if (!this.ready) {
|
|
502
|
+
issues.push({ id: 'index-not-ready', severity: 'warning', message: 'Search index is not ready yet.' });
|
|
503
|
+
}
|
|
504
|
+
if (this.error) {
|
|
505
|
+
issues.push({ id: 'index-error', severity: 'error', message: 'Search index reported an error.', detail: this.error });
|
|
506
|
+
}
|
|
507
|
+
if (!this.sqliteAvailable) {
|
|
508
|
+
issues.push({
|
|
509
|
+
id: 'sqlite-unavailable',
|
|
510
|
+
severity: 'info',
|
|
511
|
+
message: 'SQLite FTS is unavailable; JSON inverted index fallback is active.',
|
|
512
|
+
detail: this.adapterFallbackReason,
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
if (!manifest) {
|
|
516
|
+
issues.push({ id: 'manifest-missing', severity: 'warning', message: 'Search manifest is missing and will be recreated on rebuild.' });
|
|
517
|
+
}
|
|
518
|
+
if (!snapshotPresent) {
|
|
519
|
+
issues.push({ id: 'snapshot-missing', severity: 'warning', message: 'Search snapshot is missing and will be recreated on rebuild.' });
|
|
520
|
+
}
|
|
521
|
+
if (stale) {
|
|
522
|
+
issues.push({ id: 'source-changed', severity: 'info', message: 'Search sources changed since the last snapshot.', detail: 'A fresh query or repair will rebuild the index.' });
|
|
523
|
+
}
|
|
524
|
+
if (stats.corruptConversationCount > 0) {
|
|
525
|
+
issues.push({
|
|
526
|
+
id: 'corrupt-conversations',
|
|
527
|
+
severity: 'warning',
|
|
528
|
+
message: `${stats.corruptConversationCount} conversation file${stats.corruptConversationCount === 1 ? '' : 's'} could not be indexed.`,
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
if (typeof stats.lastQueryMs === 'number' && stats.lastQueryMs > 1000) {
|
|
532
|
+
issues.push({ id: 'slow-query', severity: 'warning', message: `Last search query took ${stats.lastQueryMs}ms.` });
|
|
533
|
+
}
|
|
534
|
+
if ((stats.slowQueryCount || 0) > 0) {
|
|
535
|
+
issues.push({ id: 'slow-query-history', severity: 'info', message: `${stats.slowQueryCount} recent slow search quer${stats.slowQueryCount === 1 ? 'y' : 'ies'} recorded.` });
|
|
536
|
+
}
|
|
537
|
+
if (typeof stats.p95QueryMs === 'number' && stats.p95QueryMs > SLOW_QUERY_MS) {
|
|
538
|
+
issues.push({ id: 'query-profile-degraded', severity: 'warning', message: `Search query p95 latency is ${stats.p95QueryMs}ms.` });
|
|
539
|
+
}
|
|
540
|
+
if ((stats.failedQueryCount || 0) > 0) {
|
|
541
|
+
issues.push({ id: 'query-profile-errors', severity: 'info', message: `${stats.failedQueryCount} recent search quer${stats.failedQueryCount === 1 ? 'y' : 'ies'} failed.` });
|
|
542
|
+
}
|
|
543
|
+
if (this.crashResumeAvailable) {
|
|
544
|
+
issues.push({ id: 'index-crash-resume-available', severity: 'warning', message: 'An interrupted search indexing job was detected and can be resumed or repaired.' });
|
|
545
|
+
}
|
|
546
|
+
if (this.activeJob) {
|
|
547
|
+
issues.push({ id: 'index-job-running', severity: 'info', message: `Search index job ${this.activeJob.id} is ${this.activeJob.progress.phase}.` });
|
|
548
|
+
}
|
|
549
|
+
const staleDirtySourceCount = this.dirtySources.filter((source) => source.status !== 'indexed').length;
|
|
550
|
+
if (staleDirtySourceCount > 0) {
|
|
551
|
+
issues.push({ id: 'dirty-source-queue', severity: 'info', message: `${staleDirtySourceCount} dirty search source${staleDirtySourceCount === 1 ? '' : 's'} queued for indexing.` });
|
|
552
|
+
}
|
|
553
|
+
return {
|
|
554
|
+
checkedAt: Date.now(),
|
|
555
|
+
healthy: issues.every((issue) => issue.severity !== 'error'),
|
|
556
|
+
stale: stale || staleDirtySourceCount > 0 || this.crashResumeAvailable,
|
|
557
|
+
sourceFingerprintKnown: !!this.sourceFingerprint || !!manifestFingerprint,
|
|
558
|
+
manifestPresent: !!manifest,
|
|
559
|
+
snapshotPresent,
|
|
560
|
+
issues,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
tryDeleteFile(path, id) {
|
|
564
|
+
try {
|
|
565
|
+
if (!existsSync(path))
|
|
566
|
+
return { id, success: true, detail: 'Already absent.' };
|
|
567
|
+
unlinkSync(path);
|
|
568
|
+
return { id, success: true, detail: 'Deleted stale cache file.' };
|
|
569
|
+
}
|
|
570
|
+
catch (err) {
|
|
571
|
+
return { id, success: false, error: err instanceof Error ? err.message : String(err) };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
cleanupOrphanedSearchArtifacts() {
|
|
575
|
+
try {
|
|
576
|
+
ensureSearchDir();
|
|
577
|
+
const removable = readdirSync(SEARCH_DIR)
|
|
578
|
+
.filter((file) => (/\.(tmp|bak|old|corrupt)$/i.test(file)
|
|
579
|
+
|| /^hub-search-orphan-/i.test(file)
|
|
580
|
+
|| /^repair-\d+-/i.test(file)));
|
|
581
|
+
for (const file of removable) {
|
|
582
|
+
unlinkSync(join(SEARCH_DIR, file));
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
id: 'search-orphan-artifacts',
|
|
586
|
+
success: true,
|
|
587
|
+
detail: removable.length ? `Removed ${removable.length} orphaned search cache artifact${removable.length === 1 ? '' : 's'}.` : 'No orphaned search cache artifacts found.',
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
catch (err) {
|
|
591
|
+
return { id: 'search-orphan-artifacts', success: false, error: err instanceof Error ? err.message : String(err) };
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
compactIndex() {
|
|
595
|
+
try {
|
|
596
|
+
const result = this.index.compact?.() || { success: true, detail: 'Index backend does not require compaction.' };
|
|
597
|
+
return {
|
|
598
|
+
id: 'search-index-compact',
|
|
599
|
+
success: result.success,
|
|
600
|
+
detail: result.detail,
|
|
601
|
+
error: result.error,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
catch (err) {
|
|
605
|
+
return { id: 'search-index-compact', success: false, error: err instanceof Error ? err.message : String(err) };
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
createIndexJob(kind, options) {
|
|
609
|
+
const now = Date.now();
|
|
610
|
+
return {
|
|
611
|
+
id: stableDocumentId('search-index-job', kind, now, Math.random().toString(36).slice(2, 8)),
|
|
612
|
+
kind,
|
|
613
|
+
status: 'queued',
|
|
614
|
+
force: options.force,
|
|
615
|
+
reason: options.reason,
|
|
616
|
+
sourceFingerprint: options.sourceFingerprint,
|
|
617
|
+
queuedAt: now,
|
|
618
|
+
attempt: 1,
|
|
619
|
+
progress: {
|
|
620
|
+
phase: 'queued',
|
|
621
|
+
completed: 0,
|
|
622
|
+
total: 1,
|
|
623
|
+
percent: 0,
|
|
624
|
+
updatedAt: now,
|
|
625
|
+
},
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
enqueueIndexJob(job) {
|
|
629
|
+
if (this.queuedJobs.length >= MAX_QUEUED_JOBS) {
|
|
630
|
+
const dropped = this.queuedJobs.shift();
|
|
631
|
+
if (dropped) {
|
|
632
|
+
dropped.job.status = 'cancelled';
|
|
633
|
+
dropped.job.error = 'Dropped because the search index queue was full.';
|
|
634
|
+
dropped.job.finishedAt = Date.now();
|
|
635
|
+
dropped.resolve(this.buildStatusSnapshot());
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
this.markDirtySourcesQueued();
|
|
639
|
+
const promise = new Promise((resolve) => {
|
|
640
|
+
this.queuedJobs.push({ job, resolve });
|
|
641
|
+
});
|
|
642
|
+
this.persistLifecycleState();
|
|
643
|
+
void this.processIndexQueue();
|
|
644
|
+
return promise;
|
|
645
|
+
}
|
|
646
|
+
async processIndexQueue() {
|
|
647
|
+
if (this.processingQueue)
|
|
648
|
+
return;
|
|
649
|
+
this.processingQueue = true;
|
|
650
|
+
try {
|
|
651
|
+
while (this.queuedJobs.length > 0) {
|
|
652
|
+
const item = this.queuedJobs.shift();
|
|
653
|
+
if (!item)
|
|
654
|
+
continue;
|
|
655
|
+
const job = item.job;
|
|
656
|
+
this.activeJob = job;
|
|
657
|
+
this.cancelledJobIds.delete(job.id);
|
|
658
|
+
job.status = 'running';
|
|
659
|
+
job.startedAt = Date.now();
|
|
660
|
+
this.updateJobProgress(job, 'loading-sources', 0, this.estimateSourceUnitCount(), job.sourceFingerprint);
|
|
661
|
+
this.persistLifecycleState();
|
|
662
|
+
try {
|
|
663
|
+
await this.rebuild(job.force, job.sourceFingerprint, job);
|
|
664
|
+
job.status = 'completed';
|
|
665
|
+
job.finishedAt = Date.now();
|
|
666
|
+
this.updateJobProgress(job, 'completed', job.progress.total, job.progress.total, SEARCH_MANIFEST);
|
|
667
|
+
this.crashResumeAvailable = false;
|
|
668
|
+
this.interruptedJob = undefined;
|
|
669
|
+
this.markQueuedDirtySourcesIndexed(job.finishedAt);
|
|
670
|
+
}
|
|
671
|
+
catch (err) {
|
|
672
|
+
const cancelled = err instanceof IndexJobCancelledError || this.cancelledJobIds.has(job.id);
|
|
673
|
+
job.status = cancelled ? 'cancelled' : 'failed';
|
|
674
|
+
job.finishedAt = Date.now();
|
|
675
|
+
job.error = err instanceof Error ? err.message : String(err);
|
|
676
|
+
if (cancelled)
|
|
677
|
+
this.error = undefined;
|
|
678
|
+
job.progress = {
|
|
679
|
+
...job.progress,
|
|
680
|
+
phase: cancelled ? 'cancelled' : 'failed',
|
|
681
|
+
updatedAt: Date.now(),
|
|
682
|
+
};
|
|
683
|
+
if (!cancelled) {
|
|
684
|
+
job.backoffMs = Math.min(5_000, Math.max(250, job.attempt * 500));
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
finally {
|
|
688
|
+
this.building = false;
|
|
689
|
+
this.cancelledJobIds.delete(job.id);
|
|
690
|
+
this.lastJob = job;
|
|
691
|
+
this.activeJob = null;
|
|
692
|
+
this.persistLifecycleState();
|
|
693
|
+
item.resolve(this.buildStatusSnapshot());
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
finally {
|
|
698
|
+
this.processingQueue = false;
|
|
699
|
+
this.persistLifecycleState();
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
updateJobProgress(job, phase, completed, total, currentSource) {
|
|
703
|
+
if (!job)
|
|
704
|
+
return;
|
|
705
|
+
const safeTotal = Math.max(1, total);
|
|
706
|
+
const safeCompleted = Math.max(0, Math.min(completed, safeTotal));
|
|
707
|
+
job.progress = {
|
|
708
|
+
phase,
|
|
709
|
+
completed: safeCompleted,
|
|
710
|
+
total: safeTotal,
|
|
711
|
+
percent: Math.max(0, Math.min(100, Math.round((safeCompleted / safeTotal) * 100))),
|
|
712
|
+
currentSource,
|
|
713
|
+
updatedAt: Date.now(),
|
|
714
|
+
};
|
|
715
|
+
this.persistLifecycleState();
|
|
716
|
+
}
|
|
717
|
+
buildStatusSnapshot() {
|
|
718
|
+
return {
|
|
719
|
+
ready: this.ready,
|
|
720
|
+
building: this.building || !!this.activeJob,
|
|
721
|
+
error: this.error,
|
|
722
|
+
stats: this.buildStats(),
|
|
723
|
+
health: this.buildHealth(),
|
|
724
|
+
lifecycle: this.buildLifecycleStatus(),
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
buildLifecycleStatus() {
|
|
728
|
+
const queuedJobs = this.queuedJobs.map((item) => item.job);
|
|
729
|
+
const dirtySources = this.dirtySources.slice().sort((a, b) => b.lastSeenAt - a.lastSeenAt);
|
|
730
|
+
return {
|
|
731
|
+
activeJob: this.activeJob || undefined,
|
|
732
|
+
queuedJobs,
|
|
733
|
+
lastJob: this.lastJob,
|
|
734
|
+
interruptedJob: this.interruptedJob,
|
|
735
|
+
dirtySources,
|
|
736
|
+
staleDirtySourceCount: dirtySources.filter((source) => source.status !== 'indexed').length,
|
|
737
|
+
crashResumeAvailable: this.crashResumeAvailable,
|
|
738
|
+
cancellable: !!this.activeJob || queuedJobs.length > 0,
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
restoreLifecycleState() {
|
|
742
|
+
const persisted = safeReadJson(INDEX_LIFECYCLE_FILE, null);
|
|
743
|
+
if (!persisted || persisted.version !== 1)
|
|
744
|
+
return;
|
|
745
|
+
this.dirtySources = Array.isArray(persisted.dirtySources) ? persisted.dirtySources.slice(-MAX_DIRTY_SOURCES) : [];
|
|
746
|
+
this.lastJob = persisted.lastJob;
|
|
747
|
+
this.interruptedJob = persisted.interruptedJob;
|
|
748
|
+
this.crashResumeAvailable = persisted.crashResumeAvailable === true;
|
|
749
|
+
const interrupted = [persisted.activeJob, ...(Array.isArray(persisted.queuedJobs) ? persisted.queuedJobs : [])]
|
|
750
|
+
.filter((job) => !!job && (job.status === 'running' || job.status === 'queued'))
|
|
751
|
+
.sort((a, b) => (b.startedAt || b.queuedAt) - (a.startedAt || a.queuedAt))[0];
|
|
752
|
+
if (interrupted) {
|
|
753
|
+
const now = Date.now();
|
|
754
|
+
this.interruptedJob = {
|
|
755
|
+
...interrupted,
|
|
756
|
+
status: 'interrupted',
|
|
757
|
+
finishedAt: now,
|
|
758
|
+
error: 'Process exited before the search index job completed.',
|
|
759
|
+
progress: {
|
|
760
|
+
...interrupted.progress,
|
|
761
|
+
phase: 'failed',
|
|
762
|
+
updatedAt: now,
|
|
763
|
+
},
|
|
764
|
+
};
|
|
765
|
+
this.lastJob = this.interruptedJob;
|
|
766
|
+
this.crashResumeAvailable = true;
|
|
767
|
+
this.markDirtySource('interrupted-index-job', 'dirty');
|
|
768
|
+
}
|
|
769
|
+
this.persistLifecycleState();
|
|
770
|
+
}
|
|
771
|
+
persistLifecycleState() {
|
|
772
|
+
try {
|
|
773
|
+
safeWriteJson(INDEX_LIFECYCLE_FILE, {
|
|
774
|
+
version: 1,
|
|
775
|
+
activeJob: this.activeJob || undefined,
|
|
776
|
+
queuedJobs: this.queuedJobs.map((item) => item.job),
|
|
777
|
+
lastJob: this.lastJob,
|
|
778
|
+
interruptedJob: this.interruptedJob,
|
|
779
|
+
dirtySources: this.dirtySources.slice(-MAX_DIRTY_SOURCES),
|
|
780
|
+
crashResumeAvailable: this.crashResumeAvailable,
|
|
781
|
+
savedAt: Date.now(),
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
catch {
|
|
785
|
+
// Lifecycle state improves recovery but search can still rebuild from source.
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
markDirtySource(path, status) {
|
|
789
|
+
const normalizedPath = normalizeSearchText(path).slice(0, 1000) || 'unknown';
|
|
790
|
+
const now = Date.now();
|
|
791
|
+
const existing = this.dirtySources.find((source) => source.path === normalizedPath);
|
|
792
|
+
if (existing) {
|
|
793
|
+
existing.lastSeenAt = now;
|
|
794
|
+
existing.eventCount += 1;
|
|
795
|
+
existing.status = status;
|
|
796
|
+
if (status !== 'indexed')
|
|
797
|
+
existing.indexedAt = undefined;
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
this.dirtySources.push({
|
|
801
|
+
path: normalizedPath,
|
|
802
|
+
firstSeenAt: now,
|
|
803
|
+
lastSeenAt: now,
|
|
804
|
+
eventCount: 1,
|
|
805
|
+
status,
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
this.dirtySources = this.dirtySources
|
|
809
|
+
.sort((a, b) => b.lastSeenAt - a.lastSeenAt)
|
|
810
|
+
.slice(0, MAX_DIRTY_SOURCES);
|
|
811
|
+
this.persistLifecycleState();
|
|
812
|
+
}
|
|
813
|
+
markDirtySourcesQueued() {
|
|
814
|
+
for (const source of this.dirtySources) {
|
|
815
|
+
if (source.status === 'dirty')
|
|
816
|
+
source.status = 'queued';
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
markQueuedDirtySourcesIndexed(indexedAt = Date.now()) {
|
|
820
|
+
for (const source of this.dirtySources) {
|
|
821
|
+
if (source.status === 'queued') {
|
|
822
|
+
source.status = 'indexed';
|
|
823
|
+
source.indexedAt = indexedAt;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
estimateSourceUnitCount() {
|
|
828
|
+
let count = 1;
|
|
829
|
+
try {
|
|
830
|
+
if (existsSync(AGENT_CHATS_DIR)) {
|
|
831
|
+
count += readdirSync(AGENT_CHATS_DIR).filter((file) => file.endsWith('.json')).length;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
catch {
|
|
835
|
+
count += 1;
|
|
836
|
+
}
|
|
837
|
+
try {
|
|
838
|
+
if (existsSync(RUNTIME_EVENTS_DIR)) {
|
|
839
|
+
count += readdirSync(RUNTIME_EVENTS_DIR).filter((file) => file.endsWith('.jsonl')).length;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
catch {
|
|
843
|
+
count += 1;
|
|
844
|
+
}
|
|
845
|
+
return Math.max(1, count);
|
|
846
|
+
}
|
|
847
|
+
async yieldToEventLoop() {
|
|
848
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
849
|
+
}
|
|
850
|
+
async loadSourceDocuments(job) {
|
|
851
|
+
const documents = [];
|
|
852
|
+
let sourceConversationCount = 0;
|
|
853
|
+
let sourceWorkspaceCount = 0;
|
|
854
|
+
let corruptConversationCount = 0;
|
|
855
|
+
const conversationsById = new Map();
|
|
856
|
+
const totalSourceCount = this.estimateSourceUnitCount();
|
|
857
|
+
let completedSourceCount = 0;
|
|
858
|
+
const checkpoint = async (currentSource) => {
|
|
859
|
+
if (job && this.cancelledJobIds.has(job.id))
|
|
860
|
+
throw new IndexJobCancelledError();
|
|
861
|
+
completedSourceCount += 1;
|
|
862
|
+
this.updateJobProgress(job, 'loading-sources', completedSourceCount, totalSourceCount, currentSource);
|
|
863
|
+
if (completedSourceCount % 25 === 0)
|
|
864
|
+
await this.yieldToEventLoop();
|
|
865
|
+
};
|
|
866
|
+
const workspaces = safeReadJson(WORKSPACES_FILE, []);
|
|
867
|
+
sourceWorkspaceCount = Array.isArray(workspaces) ? workspaces.length : 0;
|
|
868
|
+
documents.push(...indexWorkspaceMetadata(workspaces));
|
|
869
|
+
documents.push(...getWorkspacePolicyService().toSearchDocuments());
|
|
870
|
+
documents.push(...getPluginMcpManagerService().toSearchDocuments());
|
|
871
|
+
await checkpoint(WORKSPACES_FILE);
|
|
872
|
+
try {
|
|
873
|
+
if (existsSync(AGENT_CHATS_DIR)) {
|
|
874
|
+
const files = readdirSync(AGENT_CHATS_DIR).filter((file) => file.endsWith('.json')).sort();
|
|
875
|
+
for (const file of files) {
|
|
876
|
+
const path = join(AGENT_CHATS_DIR, file);
|
|
877
|
+
try {
|
|
878
|
+
const conversation = JSON.parse(readFileSync(path, 'utf-8'));
|
|
879
|
+
const conversationId = getConversationId(conversation);
|
|
880
|
+
if (conversationId)
|
|
881
|
+
conversationsById.set(conversationId, conversation);
|
|
882
|
+
const indexed = indexConversation(conversation, path);
|
|
883
|
+
if (indexed.length > 0)
|
|
884
|
+
sourceConversationCount += 1;
|
|
885
|
+
documents.push(...indexed);
|
|
886
|
+
}
|
|
887
|
+
catch {
|
|
888
|
+
corruptConversationCount += 1;
|
|
889
|
+
}
|
|
890
|
+
await checkpoint(path);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
catch {
|
|
895
|
+
// Keep workspace search available even when the conversation directory is temporarily unavailable.
|
|
896
|
+
}
|
|
897
|
+
try {
|
|
898
|
+
if (existsSync(RUNTIME_EVENTS_DIR)) {
|
|
899
|
+
const files = readdirSync(RUNTIME_EVENTS_DIR).filter((file) => file.endsWith('.jsonl')).sort();
|
|
900
|
+
for (const file of files) {
|
|
901
|
+
const path = join(RUNTIME_EVENTS_DIR, file);
|
|
902
|
+
const lines = readFileSync(path, 'utf-8').split(/\r?\n/);
|
|
903
|
+
for (const [lineIndex, line] of lines.entries()) {
|
|
904
|
+
const trimmed = line.trim();
|
|
905
|
+
if (!trimmed)
|
|
906
|
+
continue;
|
|
907
|
+
try {
|
|
908
|
+
const envelope = JSON.parse(trimmed);
|
|
909
|
+
const conversationId = getRuntimeEventConversationId(envelope);
|
|
910
|
+
documents.push(...indexRuntimeEventEnvelope(envelope, path, conversationId ? conversationsById.get(conversationId) : undefined, lineIndex + 1));
|
|
911
|
+
}
|
|
912
|
+
catch {
|
|
913
|
+
// Runtime JSONL traces are append-only; skip partial/corrupt lines without blocking search.
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
await checkpoint(path);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
catch {
|
|
921
|
+
// Runtime traces are supplementary search sources and must not block conversation/workspace search.
|
|
922
|
+
}
|
|
923
|
+
return { documents, sourceConversationCount, sourceWorkspaceCount, corruptConversationCount };
|
|
924
|
+
}
|
|
925
|
+
tryLoadSnapshot(sourceFingerprint) {
|
|
926
|
+
try {
|
|
927
|
+
const manifest = safeReadJson(SEARCH_MANIFEST, null);
|
|
928
|
+
if (!manifest || manifest.sourceFingerprint !== sourceFingerprint)
|
|
929
|
+
return false;
|
|
930
|
+
const snapshot = safeReadJson(SEARCH_SNAPSHOT, null);
|
|
931
|
+
if (!snapshot?.documents?.length)
|
|
932
|
+
return false;
|
|
933
|
+
this.index.importSnapshot(snapshot);
|
|
934
|
+
this.sourceFingerprint = sourceFingerprint;
|
|
935
|
+
this.ready = true;
|
|
936
|
+
this.error = undefined;
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
catch {
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
saveSnapshot(sourceFingerprint) {
|
|
944
|
+
try {
|
|
945
|
+
const snapshot = this.index.exportSnapshot();
|
|
946
|
+
safeWriteJson(SEARCH_SNAPSHOT, snapshot);
|
|
947
|
+
safeWriteJson(SEARCH_MANIFEST, {
|
|
948
|
+
version: 1,
|
|
949
|
+
sourceFingerprint,
|
|
950
|
+
builtAt: Date.now(),
|
|
951
|
+
stats: snapshot.stats,
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
catch {
|
|
955
|
+
// Search can always rebuild, so snapshot write failures should not break chat.
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
loadAttachments() {
|
|
959
|
+
const value = safeReadJson(ATTACHMENTS_FILE, []);
|
|
960
|
+
return Array.isArray(value) ? value : [];
|
|
961
|
+
}
|
|
962
|
+
saveAttachments(attachments) {
|
|
963
|
+
safeWriteJson(ATTACHMENTS_FILE, attachments.slice(-5000));
|
|
964
|
+
}
|
|
965
|
+
loadQueryProfile() {
|
|
966
|
+
if (this.queryProfileCache)
|
|
967
|
+
return this.queryProfileCache;
|
|
968
|
+
const value = safeReadJson(QUERY_PROFILE_FILE, []);
|
|
969
|
+
this.queryProfileCache = Array.isArray(value)
|
|
970
|
+
? value.filter((entry) => (!!entry
|
|
971
|
+
&& typeof entry.id === 'string'
|
|
972
|
+
&& typeof entry.timestamp === 'number'
|
|
973
|
+
&& typeof entry.durationMs === 'number'
|
|
974
|
+
&& typeof entry.query === 'string')).slice(-MAX_PROFILE_ENTRIES)
|
|
975
|
+
: [];
|
|
976
|
+
return this.queryProfileCache;
|
|
977
|
+
}
|
|
978
|
+
saveQueryProfile(entries) {
|
|
979
|
+
const limited = entries.slice(-MAX_PROFILE_ENTRIES);
|
|
980
|
+
this.queryProfileCache = limited;
|
|
981
|
+
safeWriteJson(QUERY_PROFILE_FILE, limited);
|
|
982
|
+
}
|
|
983
|
+
recordQueryProfile(params) {
|
|
984
|
+
try {
|
|
985
|
+
const query = normalizeSearchText(params.request.query).slice(0, 240);
|
|
986
|
+
const entries = this.loadQueryProfile();
|
|
987
|
+
entries.push({
|
|
988
|
+
id: stableDocumentId('search-query-profile', Date.now(), Math.random().toString(36).slice(2, 8)),
|
|
989
|
+
timestamp: Date.now(),
|
|
990
|
+
query,
|
|
991
|
+
mode: params.request.mode,
|
|
992
|
+
durationMs: Math.max(0, Math.round(params.durationMs)),
|
|
993
|
+
resultCount: Math.max(0, Math.floor(params.resultCount)),
|
|
994
|
+
success: params.success,
|
|
995
|
+
error: params.error ? normalizeSearchText(params.error).slice(0, 500) : undefined,
|
|
996
|
+
caller: params.request.caller,
|
|
997
|
+
});
|
|
998
|
+
this.saveQueryProfile(entries);
|
|
999
|
+
}
|
|
1000
|
+
catch {
|
|
1001
|
+
// Query profiling must never block search.
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
buildQueryProfile(request = {}) {
|
|
1005
|
+
const limit = Math.max(1, Math.min(Number(request.limit) || 50, MAX_PROFILE_ENTRIES));
|
|
1006
|
+
const all = this.loadQueryProfile()
|
|
1007
|
+
.slice()
|
|
1008
|
+
.sort((a, b) => b.timestamp - a.timestamp);
|
|
1009
|
+
const slowQueries = all.filter((entry) => entry.durationMs >= SLOW_QUERY_MS);
|
|
1010
|
+
const selected = (request.slowOnly ? slowQueries : all).slice(0, limit);
|
|
1011
|
+
const durations = all.map((entry) => entry.durationMs).filter((duration) => Number.isFinite(duration)).sort((a, b) => a - b);
|
|
1012
|
+
const failedQueryCount = all.filter((entry) => !entry.success).length;
|
|
1013
|
+
const averageQueryMs = durations.length
|
|
1014
|
+
? Math.round(durations.reduce((sum, duration) => sum + duration, 0) / durations.length)
|
|
1015
|
+
: null;
|
|
1016
|
+
const p95Index = durations.length ? Math.min(durations.length - 1, Math.ceil(durations.length * 0.95) - 1) : -1;
|
|
1017
|
+
const p95QueryMs = p95Index >= 0 ? durations[p95Index] : null;
|
|
1018
|
+
return {
|
|
1019
|
+
entries: selected,
|
|
1020
|
+
slowQueries: slowQueries.slice(0, limit),
|
|
1021
|
+
averageQueryMs,
|
|
1022
|
+
p95QueryMs,
|
|
1023
|
+
failedQueryCount,
|
|
1024
|
+
health: failedQueryCount > Math.max(3, all.length / 2)
|
|
1025
|
+
? 'failing'
|
|
1026
|
+
: p95QueryMs !== null && p95QueryMs > SLOW_QUERY_MS
|
|
1027
|
+
? 'degraded'
|
|
1028
|
+
: 'healthy',
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
let singleton = null;
|
|
1033
|
+
export function getAgentSearchService() {
|
|
1034
|
+
if (!singleton)
|
|
1035
|
+
singleton = new AgentSearchService();
|
|
1036
|
+
return singleton;
|
|
1037
|
+
}
|
|
1038
|
+
//# sourceMappingURL=AgentSearchService.js.map
|