@vybestack/llxprt-code-core 0.11.0 → 0.12.0-nightly.260910.2aac6841e
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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt-config/defaults/default-prompts.json +3 -3
- package/dist/src/config/agentClientLifecycle.d.ts +4 -3
- package/dist/src/config/agentClientLifecycle.js +27 -14
- package/dist/src/config/agentClientLifecycle.js.map +1 -1
- package/dist/src/config/config.d.ts +2 -5
- package/dist/src/config/config.js +10 -23
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/configBase.d.ts +5 -1
- package/dist/src/config/configBase.js +27 -6
- package/dist/src/config/configBase.js.map +1 -1
- package/dist/src/config/configBaseCore.d.ts +26 -8
- package/dist/src/config/configBaseCore.js +30 -26
- package/dist/src/config/configBaseCore.js.map +1 -1
- package/dist/src/config/configMcpRuntime.d.ts +16 -0
- package/dist/src/config/configMcpRuntime.js +31 -0
- package/dist/src/config/configMcpRuntime.js.map +1 -0
- package/dist/src/config/configMediaDefaults.d.ts +10 -0
- package/dist/src/config/configMediaDefaults.js +17 -0
- package/dist/src/config/configMediaDefaults.js.map +1 -0
- package/dist/src/config/configTestHarness.d.ts +4 -0
- package/dist/src/config/configTypes.d.ts +4 -54
- package/dist/src/config/configTypes.js +6 -82
- package/dist/src/config/configTypes.js.map +1 -1
- package/dist/src/config/index.d.ts +1 -2
- package/dist/src/config/index.js +1 -2
- package/dist/src/config/index.js.map +1 -1
- package/dist/src/config/models.d.ts +0 -4
- package/dist/src/config/models.js +0 -4
- package/dist/src/config/models.js.map +1 -1
- package/dist/src/config/toolRegistryFactory.d.ts +2 -2
- package/dist/src/core/clientContract.d.ts +4 -6
- package/dist/src/core/compression/transcriptPathNotice.d.ts +22 -0
- package/dist/src/core/compression/transcriptPathNotice.js +29 -0
- package/dist/src/core/compression/transcriptPathNotice.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +2 -5
- package/dist/src/core/contentGenerator.js +10 -24
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/logger.d.ts +66 -0
- package/dist/src/core/logger.js +345 -30
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/prompts.d.ts +0 -1
- package/dist/src/core/prompts.js +5 -79
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/turn.d.ts +3 -3
- package/dist/src/hooks/hookTranslator.js +5 -4
- package/dist/src/hooks/hookTranslator.js.map +1 -1
- package/dist/src/index.d.ts +8 -6
- package/dist/src/index.js +8 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/llm-types/index.d.ts +1 -1
- package/dist/src/llm-types/modelEnvelope.d.ts +2 -1
- package/dist/src/llm-types/modelEnvelope.js +17 -1
- package/dist/src/llm-types/modelEnvelope.js.map +1 -1
- package/dist/src/models/schema.d.ts +40 -40
- package/dist/src/policy/policies/read-only.toml +0 -5
- package/dist/src/prompt-config/TemplateEngine.js +0 -3
- package/dist/src/prompt-config/TemplateEngine.js.map +1 -1
- package/dist/src/prompt-config/defaults/providers/gemini/core.md +0 -2
- package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
- package/dist/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
- package/dist/src/prompt-config/prompt-loader.d.ts +1 -1
- package/dist/src/prompt-config/prompt-loader.js +4 -4
- package/dist/src/prompt-config/prompt-loader.js.map +1 -1
- package/dist/src/prompt-config/types.d.ts +0 -1
- package/dist/src/recording/CheckpointService.d.ts +4 -0
- package/dist/src/recording/CheckpointService.js +67 -46
- package/dist/src/recording/CheckpointService.js.map +1 -1
- package/dist/src/recording/HistoryMutationService.d.ts +1 -1
- package/dist/src/recording/HistoryMutationService.js +27 -4
- package/dist/src/recording/HistoryMutationService.js.map +1 -1
- package/dist/src/recording/RecordingIntegration.d.ts +36 -2
- package/dist/src/recording/RecordingIntegration.js +224 -7
- package/dist/src/recording/RecordingIntegration.js.map +1 -1
- package/dist/src/recording/ReplayEngine.d.ts +8 -10
- package/dist/src/recording/ReplayEngine.js +161 -95
- package/dist/src/recording/ReplayEngine.js.map +1 -1
- package/dist/src/recording/SessionDiscovery.d.ts +4 -2
- package/dist/src/recording/SessionDiscovery.js +13 -5
- package/dist/src/recording/SessionDiscovery.js.map +1 -1
- package/dist/src/recording/SessionRecordingService.d.ts +23 -3
- package/dist/src/recording/SessionRecordingService.js +209 -51
- package/dist/src/recording/SessionRecordingService.js.map +1 -1
- package/dist/src/recording/SessionTransitionService.d.ts +7 -0
- package/dist/src/recording/SessionTransitionService.js +66 -13
- package/dist/src/recording/SessionTransitionService.js.map +1 -1
- package/dist/src/recording/index.d.ts +1 -0
- package/dist/src/recording/index.js +1 -0
- package/dist/src/recording/index.js.map +1 -1
- package/dist/src/recording/janitor/cleanupTypes.d.ts +3 -0
- package/dist/src/recording/janitor/cleanupTypes.js.map +1 -1
- package/dist/src/recording/janitor/mediaReclamation.d.ts +23 -0
- package/dist/src/recording/janitor/mediaReclamation.js +195 -0
- package/dist/src/recording/janitor/mediaReclamation.js.map +1 -0
- package/dist/src/recording/janitor/sessionJanitor.js +47 -1
- package/dist/src/recording/janitor/sessionJanitor.js.map +1 -1
- package/dist/src/recording/janitor/sessionScanner.d.ts +12 -9
- package/dist/src/recording/janitor/sessionScanner.js +248 -193
- package/dist/src/recording/janitor/sessionScanner.js.map +1 -1
- package/dist/src/recording/replay-test-helpers.d.ts +10 -1
- package/dist/src/recording/replay-test-helpers.js +24 -2
- package/dist/src/recording/replay-test-helpers.js.map +1 -1
- package/dist/src/recording/replayCheckpointMetadata.d.ts +28 -0
- package/dist/src/recording/replayCheckpointMetadata.js +96 -0
- package/dist/src/recording/replayCheckpointMetadata.js.map +1 -0
- package/dist/src/recording/replayErrorFormatting.d.ts +6 -0
- package/dist/src/recording/replayErrorFormatting.js +38 -0
- package/dist/src/recording/replayErrorFormatting.js.map +1 -0
- package/dist/src/recording/resumeSession.d.ts +3 -0
- package/dist/src/recording/resumeSession.js +7 -1
- package/dist/src/recording/resumeSession.js.map +1 -1
- package/dist/src/recording/semanticMediaPurgeReplayValidation.d.ts +14 -0
- package/dist/src/recording/semanticMediaPurgeReplayValidation.js +24 -0
- package/dist/src/recording/semanticMediaPurgeReplayValidation.js.map +1 -0
- package/dist/src/recording/session-media-package-blobs.d.ts +8 -0
- package/dist/src/recording/session-media-package-blobs.js +72 -0
- package/dist/src/recording/session-media-package-blobs.js.map +1 -0
- package/dist/src/recording/session-media-package-import.d.ts +26 -0
- package/dist/src/recording/session-media-package-import.js +124 -0
- package/dist/src/recording/session-media-package-import.js.map +1 -0
- package/dist/src/recording/session-media-package-state.d.ts +19 -0
- package/dist/src/recording/session-media-package-state.js +56 -0
- package/dist/src/recording/session-media-package-state.js.map +1 -0
- package/dist/src/recording/session-media-package-validation.d.ts +59 -0
- package/dist/src/recording/session-media-package-validation.js +286 -0
- package/dist/src/recording/session-media-package-validation.js.map +1 -0
- package/dist/src/recording/session-media-package-writer.d.ts +18 -0
- package/dist/src/recording/session-media-package-writer.js +70 -0
- package/dist/src/recording/session-media-package-writer.js.map +1 -0
- package/dist/src/recording/session-media-package.d.ts +27 -0
- package/dist/src/recording/session-media-package.js +366 -0
- package/dist/src/recording/session-media-package.js.map +1 -0
- package/dist/src/recording/types.d.ts +34 -2
- package/dist/src/recording/types.js.map +1 -1
- package/dist/src/runtime/AgentRuntimeContext.d.ts +22 -5
- package/dist/src/runtime/AgentRuntimeLoader.d.ts +6 -0
- package/dist/src/runtime/AgentRuntimeLoader.js +25 -6
- package/dist/src/runtime/AgentRuntimeLoader.js.map +1 -1
- package/dist/src/runtime/contracts/PromptEstimation.d.ts +1 -0
- package/dist/src/runtime/contracts/PromptEstimation.js.map +1 -1
- package/dist/src/runtime/contracts/RuntimeProvider.d.ts +3 -2
- package/dist/src/runtime/contracts/RuntimeProviderManager.d.ts +0 -2
- package/dist/src/runtime/createAgentRuntimeContext.js +28 -1
- package/dist/src/runtime/createAgentRuntimeContext.js.map +1 -1
- package/dist/src/runtime/providerRuntimeContext.d.ts +12 -0
- package/dist/src/runtime/providerRuntimeContext.js +3 -0
- package/dist/src/runtime/providerRuntimeContext.js.map +1 -1
- package/dist/src/runtime/runtimeAdapters.js +2 -2
- package/dist/src/runtime/runtimeAdapters.js.map +1 -1
- package/dist/src/services/history/ContentConverters.d.ts +11 -7
- package/dist/src/services/history/ContentConverters.js +11 -7
- package/dist/src/services/history/ContentConverters.js.map +1 -1
- package/dist/src/services/history/HistoryService.d.ts +18 -180
- package/dist/src/services/history/HistoryService.js +53 -523
- package/dist/src/services/history/HistoryService.js.map +1 -1
- package/dist/src/services/history/HistoryServiceCore.d.ts +278 -0
- package/dist/src/services/history/HistoryServiceCore.js +727 -0
- package/dist/src/services/history/HistoryServiceCore.js.map +1 -0
- package/dist/src/services/history/IContent.d.ts +118 -16
- package/dist/src/services/history/IContent.js +284 -4
- package/dist/src/services/history/IContent.js.map +1 -1
- package/dist/src/services/history/contentSize.js +22 -2
- package/dist/src/services/history/contentSize.js.map +1 -1
- package/dist/src/services/history/historyChronology.d.ts +7 -0
- package/dist/src/services/history/historyChronology.js +35 -3
- package/dist/src/services/history/historyChronology.js.map +1 -1
- package/dist/src/services/history/historyCloneUtils.d.ts +5 -4
- package/dist/src/services/history/historyCloneUtils.js +23 -16
- package/dist/src/services/history/historyCloneUtils.js.map +1 -1
- package/dist/src/services/history/historyCompressionQueue.d.ts +33 -0
- package/dist/src/services/history/historyCompressionQueue.js +81 -0
- package/dist/src/services/history/historyCompressionQueue.js.map +1 -0
- package/dist/src/services/history/historyEventTypes.d.ts +3 -0
- package/dist/src/services/history/historyMutationFailure.d.ts +15 -0
- package/dist/src/services/history/historyMutationFailure.js +22 -0
- package/dist/src/services/history/historyMutationFailure.js.map +1 -1
- package/dist/src/services/history/historyProviderPipeline.d.ts +1 -1
- package/dist/src/services/history/historyProviderPipeline.js +15 -5
- package/dist/src/services/history/historyProviderPipeline.js.map +1 -1
- package/dist/src/services/history/historyTokenEstimation.js +10 -6
- package/dist/src/services/history/historyTokenEstimation.js.map +1 -1
- package/dist/src/services/history/historyToolNormalization.d.ts +2 -0
- package/dist/src/services/history/historyToolNormalization.js +26 -9
- package/dist/src/services/history/historyToolNormalization.js.map +1 -1
- package/dist/src/services/history/provider-file-binding.d.ts +11 -0
- package/dist/src/services/history/provider-file-binding.js +70 -0
- package/dist/src/services/history/provider-file-binding.js.map +1 -0
- package/dist/src/services/history/semantic-media-purge.d.ts +66 -0
- package/dist/src/services/history/semantic-media-purge.js +404 -0
- package/dist/src/services/history/semantic-media-purge.js.map +1 -0
- package/dist/src/storage/SessionPersistenceService.d.ts +53 -2
- package/dist/src/storage/SessionPersistenceService.js +435 -23
- package/dist/src/storage/SessionPersistenceService.js.map +1 -1
- package/dist/src/storage/history-media-ownership.d.ts +38 -0
- package/dist/src/storage/history-media-ownership.js +136 -0
- package/dist/src/storage/history-media-ownership.js.map +1 -0
- package/dist/src/storage/local-media-store-child.d.ts +6 -0
- package/dist/src/storage/local-media-store-child.js +140 -0
- package/dist/src/storage/local-media-store-child.js.map +1 -0
- package/dist/src/storage/local-media-store-files.d.ts +44 -0
- package/dist/src/storage/local-media-store-files.js +460 -0
- package/dist/src/storage/local-media-store-files.js.map +1 -0
- package/dist/src/storage/local-media-store-lock-recovery.d.ts +15 -0
- package/dist/src/storage/local-media-store-lock-recovery.js +112 -0
- package/dist/src/storage/local-media-store-lock-recovery.js.map +1 -0
- package/dist/src/storage/local-media-store-persistence.d.ts +48 -0
- package/dist/src/storage/local-media-store-persistence.js +443 -0
- package/dist/src/storage/local-media-store-persistence.js.map +1 -0
- package/dist/src/storage/local-media-store-quota.d.ts +6 -0
- package/dist/src/storage/local-media-store-quota.js +66 -0
- package/dist/src/storage/local-media-store-quota.js.map +1 -0
- package/dist/src/storage/local-media-store-reservations.d.ts +55 -0
- package/dist/src/storage/local-media-store-reservations.js +377 -0
- package/dist/src/storage/local-media-store-reservations.js.map +1 -0
- package/dist/src/storage/local-media-store-types.d.ts +110 -0
- package/dist/src/storage/local-media-store-types.js +35 -0
- package/dist/src/storage/local-media-store-types.js.map +1 -0
- package/dist/src/storage/local-media-store-validation.d.ts +34 -0
- package/dist/src/storage/local-media-store-validation.js +449 -0
- package/dist/src/storage/local-media-store-validation.js.map +1 -0
- package/dist/src/storage/local-media-store.d.ts +47 -0
- package/dist/src/storage/local-media-store.js +353 -0
- package/dist/src/storage/local-media-store.js.map +1 -0
- package/dist/src/storage/media-admission-service.d.ts +49 -0
- package/dist/src/storage/media-admission-service.js +333 -0
- package/dist/src/storage/media-admission-service.js.map +1 -0
- package/dist/src/storage/media-lifecycle-metrics.d.ts +75 -0
- package/dist/src/storage/media-lifecycle-metrics.js +105 -0
- package/dist/src/storage/media-lifecycle-metrics.js.map +1 -0
- package/dist/src/storage/media-reference-lifecycle.d.ts +16 -0
- package/dist/src/storage/media-reference-lifecycle.js +84 -0
- package/dist/src/storage/media-reference-lifecycle.js.map +1 -0
- package/dist/src/storage/request-media-resolver.d.ts +67 -0
- package/dist/src/storage/request-media-resolver.js +325 -0
- package/dist/src/storage/request-media-resolver.js.map +1 -0
- package/dist/src/storage/session-media-service-factories.d.ts +19 -0
- package/dist/src/storage/session-media-service-factories.js +34 -0
- package/dist/src/storage/session-media-service-factories.js.map +1 -0
- package/dist/src/storage/session-persistence-helpers.d.ts +10 -0
- package/dist/src/storage/session-persistence-helpers.js +46 -0
- package/dist/src/storage/session-persistence-helpers.js.map +1 -0
- package/dist/src/test-utils/config.d.ts +2 -0
- package/dist/src/test-utils/config.js +5 -5
- package/dist/src/test-utils/config.js.map +1 -1
- package/dist/src/test-utils/runtime.d.ts +2 -0
- package/dist/src/test-utils/runtime.js +1 -2
- package/dist/src/test-utils/runtime.js.map +1 -1
- package/dist/src/tools-adapters/CoreShellToolHostAdapter.js +1 -9
- package/dist/src/tools-adapters/CoreShellToolHostAdapter.js.map +1 -1
- package/dist/src/tools-adapters/CoreSkillServiceAdapter.d.ts +0 -2
- package/dist/src/tools-adapters/CoreSkillServiceAdapter.js +0 -17
- package/dist/src/tools-adapters/CoreSkillServiceAdapter.js.map +1 -1
- package/dist/src/tools-adapters/CoreToolHostAdapter.d.ts +0 -21
- package/dist/src/tools-adapters/CoreToolHostAdapter.js +0 -8
- package/dist/src/tools-adapters/CoreToolHostAdapter.js.map +1 -1
- package/dist/src/utils/environmentContext.d.ts +8 -9
- package/dist/src/utils/environmentContext.js +11 -22
- package/dist/src/utils/environmentContext.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +1 -2
- package/dist/src/utils/errorParsing.js +22 -41
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/generateContentResponseUtilities.js +12 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
- package/dist/src/utils/summarizer.d.ts +1 -2
- package/dist/src/utils/summarizer.js +6 -5
- package/dist/src/utils/summarizer.js.map +1 -1
- package/dist/src/utils/tool-utils.js +7 -1
- package/dist/src/utils/tool-utils.js.map +1 -1
- package/index.ts +0 -4
- package/package.json +38 -30
- package/src/config/agentClientLifecycle.ts +53 -22
- package/src/config/config.ts +11 -26
- package/src/config/configBase.ts +46 -7
- package/src/config/configBaseCore.ts +38 -36
- package/src/config/configMcpRuntime.ts +46 -0
- package/src/config/configMediaDefaults.ts +19 -0
- package/src/config/configTypes.ts +13 -53
- package/src/config/index.ts +1 -4
- package/src/config/models.ts +0 -6
- package/src/config/toolRegistryFactory.ts +2 -2
- package/src/core/clientContract.ts +4 -6
- package/src/core/compression/transcriptPathNotice.ts +31 -0
- package/src/core/contentGenerator.ts +15 -39
- package/src/core/logger.ts +370 -39
- package/src/core/prompts.ts +4 -114
- package/src/core/turn.ts +3 -3
- package/src/hooks/hookTranslator.ts +6 -4
- package/src/index.ts +7 -7
- package/src/llm-types/index.ts +5 -0
- package/src/llm-types/modelEnvelope.ts +26 -2
- package/src/policy/policies/read-only.toml +0 -5
- package/src/prompt-config/TemplateEngine.ts +0 -3
- package/src/prompt-config/defaults/providers/gemini/core.md +0 -2
- package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/core.md +0 -2
- package/src/prompt-config/defaults/providers/gemini/models/gemini-2.5-flash/gemini-2-5-flash/core.md +0 -2
- package/src/prompt-config/prompt-loader.ts +7 -8
- package/src/prompt-config/types.ts +0 -1
- package/src/recording/CheckpointService.ts +110 -45
- package/src/recording/HistoryMutationService.ts +28 -3
- package/src/recording/RecordingIntegration.ts +258 -11
- package/src/recording/ReplayEngine.ts +220 -110
- package/src/recording/SessionDiscovery.ts +30 -4
- package/src/recording/SessionRecordingService.ts +253 -55
- package/src/recording/SessionTransitionService.ts +75 -12
- package/src/recording/index.ts +7 -0
- package/src/recording/janitor/cleanupTypes.ts +4 -0
- package/src/recording/janitor/mediaReclamation.ts +295 -0
- package/src/recording/janitor/sessionJanitor.ts +54 -1
- package/src/recording/janitor/sessionScanner.ts +319 -227
- package/src/recording/replay-test-helpers.ts +33 -2
- package/src/recording/replayCheckpointMetadata.ts +115 -0
- package/src/recording/replayErrorFormatting.ts +43 -0
- package/src/recording/resumeSession.ts +10 -0
- package/src/recording/semanticMediaPurgeReplayValidation.ts +35 -0
- package/src/recording/session-media-package-blobs.ts +116 -0
- package/src/recording/session-media-package-import.ts +189 -0
- package/src/recording/session-media-package-state.ts +120 -0
- package/src/recording/session-media-package-validation.ts +400 -0
- package/src/recording/session-media-package-writer.ts +117 -0
- package/src/recording/session-media-package.ts +692 -0
- package/src/recording/types.ts +37 -2
- package/src/runtime/AgentRuntimeContext.ts +28 -5
- package/src/runtime/AgentRuntimeLoader.ts +32 -7
- package/src/runtime/contracts/PromptEstimation.ts +1 -0
- package/src/runtime/contracts/RuntimeProvider.ts +3 -8
- package/src/runtime/contracts/RuntimeProviderManager.ts +0 -2
- package/src/runtime/createAgentRuntimeContext.ts +43 -1
- package/src/runtime/providerRuntimeContext.ts +22 -0
- package/src/runtime/runtimeAdapters.ts +2 -2
- package/src/services/history/ContentConverters.ts +11 -7
- package/src/services/history/HistoryService.ts +71 -696
- package/src/services/history/HistoryServiceCore.ts +1055 -0
- package/src/services/history/IContent.ts +460 -20
- package/src/services/history/contentSize.ts +22 -2
- package/src/services/history/historyChronology.ts +53 -3
- package/src/services/history/historyCloneUtils.ts +26 -22
- package/src/services/history/historyCompressionQueue.ts +102 -0
- package/src/services/history/historyEventTypes.ts +9 -0
- package/src/services/history/historyMutationFailure.ts +33 -0
- package/src/services/history/historyProviderPipeline.ts +19 -5
- package/src/services/history/historyTokenEstimation.ts +9 -5
- package/src/services/history/historyToolNormalization.ts +43 -11
- package/src/services/history/provider-file-binding.ts +115 -0
- package/src/services/history/semantic-media-purge.ts +593 -0
- package/src/storage/SessionPersistenceService.ts +667 -30
- package/src/storage/history-media-ownership.ts +185 -0
- package/src/storage/local-media-store-child.ts +163 -0
- package/src/storage/local-media-store-files.ts +643 -0
- package/src/storage/local-media-store-lock-recovery.ts +159 -0
- package/src/storage/local-media-store-persistence.ts +737 -0
- package/src/storage/local-media-store-quota.ts +111 -0
- package/src/storage/local-media-store-reservations.ts +485 -0
- package/src/storage/local-media-store-types.ts +161 -0
- package/src/storage/local-media-store-validation.ts +643 -0
- package/src/storage/local-media-store.ts +696 -0
- package/src/storage/media-admission-service.ts +512 -0
- package/src/storage/media-lifecycle-metrics.ts +228 -0
- package/src/storage/media-reference-lifecycle.ts +164 -0
- package/src/storage/request-media-resolver.ts +491 -0
- package/src/storage/session-media-service-factories.ts +48 -0
- package/src/storage/session-persistence-helpers.ts +85 -0
- package/src/test-utils/config.ts +7 -5
- package/src/test-utils/runtime.ts +3 -2
- package/src/tools-adapters/CoreShellToolHostAdapter.ts +1 -11
- package/src/tools-adapters/CoreSkillServiceAdapter.ts +0 -23
- package/src/tools-adapters/CoreToolHostAdapter.ts +0 -36
- package/src/utils/environmentContext.ts +11 -30
- package/src/utils/errorParsing.ts +19 -69
- package/src/utils/generateContentResponseUtilities.ts +28 -1
- package/src/utils/summarizer.ts +8 -10
- package/src/utils/tool-utils.ts +7 -1
- package/dist/src/code_assist/codeAssist.d.ts +0 -19
- package/dist/src/code_assist/codeAssist.js +0 -41
- package/dist/src/code_assist/codeAssist.js.map +0 -1
- package/dist/src/code_assist/contentGeneratorAdapters.d.ts +0 -49
- package/dist/src/code_assist/contentGeneratorAdapters.js +0 -197
- package/dist/src/code_assist/contentGeneratorAdapters.js.map +0 -1
- package/dist/src/code_assist/converter.d.ts +0 -74
- package/dist/src/code_assist/converter.js +0 -158
- package/dist/src/code_assist/converter.js.map +0 -1
- package/dist/src/code_assist/googleGenAIWrapper.d.ts +0 -27
- package/dist/src/code_assist/googleGenAIWrapper.js +0 -46
- package/dist/src/code_assist/googleGenAIWrapper.js.map +0 -1
- package/dist/src/code_assist/oauth-credential-storage.d.ts +0 -30
- package/dist/src/code_assist/oauth-credential-storage.js +0 -135
- package/dist/src/code_assist/oauth-credential-storage.js.map +0 -1
- package/dist/src/code_assist/server.d.ts +0 -44
- package/dist/src/code_assist/server.js +0 -154
- package/dist/src/code_assist/server.js.map +0 -1
- package/dist/src/code_assist/setup.d.ts +0 -20
- package/dist/src/code_assist/setup.js +0 -126
- package/dist/src/code_assist/setup.js.map +0 -1
- package/dist/src/code_assist/types.d.ts +0 -161
- package/dist/src/code_assist/types.js +0 -46
- package/dist/src/code_assist/types.js.map +0 -1
- package/dist/src/utils/getFolderStructure.d.ts +0 -31
- package/dist/src/utils/getFolderStructure.js +0 -240
- package/dist/src/utils/getFolderStructure.js.map +0 -1
- package/dist/src/utils/installationManager.d.ts +0 -16
- package/dist/src/utils/installationManager.js +0 -51
- package/dist/src/utils/installationManager.js.map +0 -1
- package/dist/src/utils/llm-edit-fixer.d.ts +0 -25
- package/dist/src/utils/llm-edit-fixer.js +0 -120
- package/dist/src/utils/llm-edit-fixer.js.map +0 -1
- package/src/code_assist/codeAssist.ts +0 -59
- package/src/code_assist/contentGeneratorAdapters.ts +0 -275
- package/src/code_assist/converter.ts +0 -288
- package/src/code_assist/googleGenAIWrapper.ts +0 -90
- package/src/code_assist/oauth-credential-storage.ts +0 -171
- package/src/code_assist/server.ts +0 -263
- package/src/code_assist/setup.ts +0 -189
- package/src/code_assist/types.ts +0 -201
- package/src/utils/getFolderStructure.ts +0 -382
- package/src/utils/installationManager.ts +0 -59
- package/src/utils/llm-edit-fixer.ts +0 -157
|
@@ -14,284 +14,376 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
* Global session scanner for the janitor.
|
|
19
|
-
*
|
|
20
|
-
* Scans every direct child of `Storage.getGlobalTempDir()` whose name is
|
|
21
|
-
* exactly a 64-character lowercase hexadecimal project hash. Within each
|
|
22
|
-
* project hash directory it discovers `chats/session-*.jsonl` (raw recordings)
|
|
23
|
-
* and `chats/archive/session-*.jsonl.gz` (cold archives). It uses bounded
|
|
24
|
-
* concurrency and the canonical header reader — never reading entire files
|
|
25
|
-
* into memory.
|
|
26
|
-
*
|
|
27
|
-
* Blast-radius safety (AC-10): symlinks are never followed; unknown files are
|
|
28
|
-
* ignored; non-hash directories are skipped.
|
|
29
|
-
*/
|
|
30
|
-
|
|
17
|
+
import type { Dirent, Stats } from 'node:fs';
|
|
31
18
|
import * as fs from 'node:fs/promises';
|
|
32
|
-
import type { Stats } from 'node:fs';
|
|
33
19
|
import * as path from 'node:path';
|
|
34
20
|
import type { SessionCandidate } from './cleanupTypes.js';
|
|
35
21
|
import { readSessionJsonlHeader } from './sessionHeaderReader.js';
|
|
36
22
|
|
|
37
|
-
/** Regex matching a 64-character lowercase hex project hash directory name. */
|
|
38
23
|
const PROJECT_HASH_RE = /^[0-9a-f]{64}$/;
|
|
39
|
-
|
|
40
|
-
/** Bounded concurrency for stat/header operations within a directory. */
|
|
41
|
-
const MAX_CONCURRENT_OPS = 8;
|
|
42
|
-
|
|
43
|
-
/** Archive sub-directory name inside a chats directory. */
|
|
44
24
|
export const ARCHIVE_DIR_NAME = 'archive';
|
|
45
|
-
|
|
46
|
-
/** Prefix and suffix for raw session recordings. */
|
|
47
25
|
const SESSION_PREFIX = 'session-';
|
|
48
26
|
const SESSION_JSONL_SUFFIX = '.jsonl';
|
|
49
27
|
const ARCHIVE_SUFFIX = '.jsonl.gz';
|
|
50
28
|
|
|
51
|
-
|
|
29
|
+
export interface SessionScanLimits {
|
|
30
|
+
readonly maxProjects: number;
|
|
31
|
+
readonly maxFiles: number;
|
|
32
|
+
readonly maxCandidateBytes: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const DEFAULT_SCAN_LIMITS: SessionScanLimits = {
|
|
36
|
+
maxProjects: 4096,
|
|
37
|
+
maxFiles: 100_000,
|
|
38
|
+
maxCandidateBytes: 16 * 1024 * 1024 * 1024,
|
|
39
|
+
};
|
|
40
|
+
|
|
52
41
|
export interface ScanResult {
|
|
53
42
|
readonly candidates: readonly SessionCandidate[];
|
|
54
43
|
readonly chatsDirs: readonly string[];
|
|
55
|
-
/** Number of non-benign (non-ENOENT) per-project scan failures (OCR 38/39). */
|
|
56
44
|
readonly scanErrorCount: number;
|
|
45
|
+
readonly scanSkippedCount: number;
|
|
57
46
|
}
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
interface ScanBudget {
|
|
49
|
+
readonly limits: SessionScanLimits;
|
|
50
|
+
files: number;
|
|
51
|
+
bytes: number;
|
|
52
|
+
skipped: number;
|
|
53
|
+
errors: number;
|
|
54
|
+
exhausted: boolean;
|
|
63
55
|
}
|
|
64
56
|
|
|
65
|
-
|
|
57
|
+
function hasErrnoCode(error: unknown, code: string): boolean {
|
|
58
|
+
return (
|
|
59
|
+
typeof error === 'object' &&
|
|
60
|
+
error !== null &&
|
|
61
|
+
Reflect.get(error, 'code') === code
|
|
62
|
+
);
|
|
63
|
+
}
|
|
66
64
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*/
|
|
73
|
-
function getFileSize(stat: Stats): number {
|
|
74
|
-
const allocated =
|
|
75
|
-
typeof stat.blocks === 'number' && stat.blksize > 0 ? stat.blocks * 512 : 0;
|
|
76
|
-
return allocated > 0 ? allocated : stat.size;
|
|
65
|
+
function positiveLimit(value: number, name: string): number {
|
|
66
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
67
|
+
throw new Error(`Invalid session scan limit ${name}`);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
): Promise<R[]> {
|
|
88
|
-
const results = new Array<R>(items.length);
|
|
89
|
-
let nextIndex = 0;
|
|
90
|
-
const worker = async (): Promise<void> => {
|
|
91
|
-
while (nextIndex < items.length) {
|
|
92
|
-
const i = nextIndex++;
|
|
93
|
-
results[i] = await mapper(items[i]);
|
|
94
|
-
}
|
|
72
|
+
function validatedLimits(limits: SessionScanLimits): SessionScanLimits {
|
|
73
|
+
return {
|
|
74
|
+
maxProjects: positiveLimit(limits.maxProjects, 'maxProjects'),
|
|
75
|
+
maxFiles: positiveLimit(limits.maxFiles, 'maxFiles'),
|
|
76
|
+
maxCandidateBytes: positiveLimit(
|
|
77
|
+
limits.maxCandidateBytes,
|
|
78
|
+
'maxCandidateBytes',
|
|
79
|
+
),
|
|
95
80
|
};
|
|
96
|
-
const workerCount = Math.min(limit, items.length);
|
|
97
|
-
await Promise.all(Array.from({ length: workerCount }, worker));
|
|
98
|
-
return results;
|
|
99
81
|
}
|
|
100
82
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*/
|
|
109
|
-
export async function scanGlobalSessions(
|
|
110
|
-
globalTempDir: string,
|
|
111
|
-
currentSessionId?: string,
|
|
112
|
-
): Promise<ScanResult> {
|
|
113
|
-
let topEntries: string[];
|
|
114
|
-
try {
|
|
115
|
-
topEntries = await fs.readdir(globalTempDir);
|
|
116
|
-
} catch (error: unknown) {
|
|
117
|
-
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
118
|
-
return { candidates: [], chatsDirs: [], scanErrorCount: 0 };
|
|
119
|
-
}
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const hashDirs = topEntries.filter((name) => PROJECT_HASH_RE.test(name));
|
|
124
|
-
const chatsDirs: string[] = [];
|
|
125
|
-
const allCandidates: SessionCandidate[] = [];
|
|
126
|
-
let scanErrorCount = 0;
|
|
127
|
-
|
|
128
|
-
// Process project-hash directories with bounded concurrency.
|
|
129
|
-
await boundedMap(hashDirs, MAX_CONCURRENT_OPS, async (hashDirName) => {
|
|
130
|
-
const hashDirPath = path.join(globalTempDir, hashDirName);
|
|
131
|
-
const chatsDir = path.join(hashDirPath, 'chats');
|
|
83
|
+
function getFileSize(fileStat: Stats): number {
|
|
84
|
+
const allocated =
|
|
85
|
+
typeof fileStat.blocks === 'number' && fileStat.blksize > 0
|
|
86
|
+
? fileStat.blocks * 512
|
|
87
|
+
: 0;
|
|
88
|
+
return allocated > 0 ? allocated : fileStat.size;
|
|
89
|
+
}
|
|
132
90
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// Never follow symlinks (AC-10).
|
|
140
|
-
if (lstat.isSymbolicLink()) return;
|
|
141
|
-
if (!lstat.isDirectory()) return;
|
|
91
|
+
function markBudgetExhausted(budget: ScanBudget): void {
|
|
92
|
+
if (!budget.exhausted) {
|
|
93
|
+
budget.exhausted = true;
|
|
94
|
+
budget.skipped += 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
142
97
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
chatsExists = false;
|
|
151
|
-
}
|
|
152
|
-
} catch {
|
|
153
|
-
chatsExists = false;
|
|
154
|
-
}
|
|
155
|
-
if (!chatsExists) return;
|
|
98
|
+
function candidateBudgetAtLimit(budget: ScanBudget): boolean {
|
|
99
|
+
return (
|
|
100
|
+
budget.exhausted ||
|
|
101
|
+
budget.files >= budget.limits.maxFiles ||
|
|
102
|
+
budget.bytes >= budget.limits.maxCandidateBytes
|
|
103
|
+
);
|
|
104
|
+
}
|
|
156
105
|
|
|
157
|
-
|
|
106
|
+
function reserveCandidateBudget(fileStat: Stats, budget: ScanBudget): boolean {
|
|
107
|
+
if (
|
|
108
|
+
candidateBudgetAtLimit(budget) ||
|
|
109
|
+
fileStat.size > budget.limits.maxCandidateBytes - budget.bytes
|
|
110
|
+
) {
|
|
111
|
+
markBudgetExhausted(budget);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
budget.files += 1;
|
|
115
|
+
budget.bytes += fileStat.size;
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
158
118
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
|
|
119
|
+
function rawFileName(name: string): boolean {
|
|
120
|
+
return (
|
|
121
|
+
name.startsWith(SESSION_PREFIX) &&
|
|
122
|
+
name.endsWith(SESSION_JSONL_SUFFIX) &&
|
|
123
|
+
!name.endsWith(ARCHIVE_SUFFIX)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
166
126
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
scanErrorCount += archiveBatch.errors;
|
|
171
|
-
});
|
|
127
|
+
function archiveFileName(name: string): boolean {
|
|
128
|
+
return name.startsWith(SESSION_PREFIX) && name.endsWith(ARCHIVE_SUFFIX);
|
|
129
|
+
}
|
|
172
130
|
|
|
173
|
-
|
|
131
|
+
async function scanRawSessionEntry(
|
|
132
|
+
entry: Dirent,
|
|
133
|
+
chatsDir: string,
|
|
134
|
+
projectHashDir: string,
|
|
135
|
+
currentSessionId: string | undefined,
|
|
136
|
+
budget: ScanBudget,
|
|
137
|
+
): Promise<SessionCandidate | undefined> {
|
|
138
|
+
if (!entry.isFile() || !rawFileName(entry.name)) return undefined;
|
|
139
|
+
const filePath = path.join(chatsDir, entry.name);
|
|
140
|
+
try {
|
|
141
|
+
const fileStat = await fs.lstat(filePath);
|
|
142
|
+
if (fileStat.isSymbolicLink() || !fileStat.isFile()) return undefined;
|
|
143
|
+
if (!reserveCandidateBudget(fileStat, budget)) return undefined;
|
|
144
|
+
const header = await readSessionJsonlHeader(filePath);
|
|
145
|
+
return {
|
|
146
|
+
kind: 'raw',
|
|
147
|
+
filePath,
|
|
148
|
+
fileName: entry.name,
|
|
149
|
+
containerDir: chatsDir,
|
|
150
|
+
projectHashDir,
|
|
151
|
+
sessionId: header?.sessionId ?? null,
|
|
152
|
+
isCurrentSession:
|
|
153
|
+
header?.sessionId !== undefined &&
|
|
154
|
+
currentSessionId !== undefined &&
|
|
155
|
+
header.sessionId === currentSessionId,
|
|
156
|
+
sizeBytes: getFileSize(fileStat),
|
|
157
|
+
mtime: fileStat.mtime,
|
|
158
|
+
dev: fileStat.dev,
|
|
159
|
+
ino: fileStat.ino,
|
|
160
|
+
};
|
|
161
|
+
} catch {
|
|
162
|
+
budget.errors += 1;
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
174
165
|
}
|
|
175
166
|
|
|
176
|
-
/** Scan `session-*.jsonl` files inside a chats directory. */
|
|
177
167
|
async function scanRawSessions(
|
|
178
168
|
chatsDir: string,
|
|
179
169
|
projectHashDir: string,
|
|
180
|
-
currentSessionId
|
|
181
|
-
|
|
182
|
-
|
|
170
|
+
currentSessionId: string | undefined,
|
|
171
|
+
budget: ScanBudget,
|
|
172
|
+
): Promise<SessionCandidate[]> {
|
|
173
|
+
const candidates: SessionCandidate[] = [];
|
|
174
|
+
let directory: Awaited<ReturnType<typeof fs.opendir>>;
|
|
183
175
|
try {
|
|
184
|
-
|
|
185
|
-
} catch (error
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// Non-ENOENT error (EACCES, EIO, …) — count as a scan failure (OCR 38/39).
|
|
189
|
-
return { candidates: [], errors: 1 };
|
|
176
|
+
directory = await fs.opendir(chatsDir);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (!hasErrnoCode(error, 'ENOENT')) budget.errors += 1;
|
|
179
|
+
return candidates;
|
|
190
180
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
!f.endsWith(ARCHIVE_SUFFIX),
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
let perFileErrors = 0;
|
|
200
|
-
const candidates = (
|
|
201
|
-
await boundedMap(sessionFiles, MAX_CONCURRENT_OPS, async (fileName) => {
|
|
202
|
-
const filePath = path.join(chatsDir, fileName);
|
|
203
|
-
try {
|
|
204
|
-
const lstat = await fs.lstat(filePath);
|
|
205
|
-
if (lstat.isSymbolicLink()) return null;
|
|
206
|
-
if (!lstat.isFile()) return null;
|
|
207
|
-
const header = await readSessionJsonlHeader(filePath);
|
|
208
|
-
const candidate: SessionCandidate = {
|
|
209
|
-
kind: 'raw',
|
|
210
|
-
filePath,
|
|
211
|
-
fileName,
|
|
212
|
-
containerDir: chatsDir,
|
|
213
|
-
projectHashDir,
|
|
214
|
-
sessionId: header?.sessionId ?? null,
|
|
215
|
-
isCurrentSession:
|
|
216
|
-
header?.sessionId != null &&
|
|
217
|
-
currentSessionId != null &&
|
|
218
|
-
header.sessionId === currentSessionId,
|
|
219
|
-
sizeBytes: getFileSize(lstat),
|
|
220
|
-
mtime: lstat.mtime,
|
|
221
|
-
dev: lstat.dev,
|
|
222
|
-
ino: lstat.ino,
|
|
223
|
-
};
|
|
224
|
-
return candidate;
|
|
225
|
-
} catch {
|
|
226
|
-
perFileErrors++;
|
|
227
|
-
return null;
|
|
181
|
+
try {
|
|
182
|
+
for await (const entry of directory) {
|
|
183
|
+
if (candidateBudgetAtLimit(budget)) {
|
|
184
|
+
markBudgetExhausted(budget);
|
|
185
|
+
break;
|
|
228
186
|
}
|
|
229
|
-
|
|
230
|
-
|
|
187
|
+
const candidate = await scanRawSessionEntry(
|
|
188
|
+
entry,
|
|
189
|
+
chatsDir,
|
|
190
|
+
projectHashDir,
|
|
191
|
+
currentSessionId,
|
|
192
|
+
budget,
|
|
193
|
+
);
|
|
194
|
+
if (candidate !== undefined) candidates.push(candidate);
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (!hasErrnoCode(error, 'ENOENT')) budget.errors += 1;
|
|
198
|
+
}
|
|
199
|
+
return candidates;
|
|
200
|
+
}
|
|
231
201
|
|
|
232
|
-
|
|
202
|
+
async function scanArchiveSessionEntry(
|
|
203
|
+
entry: Dirent,
|
|
204
|
+
archiveDir: string,
|
|
205
|
+
projectHashDir: string,
|
|
206
|
+
budget: ScanBudget,
|
|
207
|
+
): Promise<SessionCandidate | undefined> {
|
|
208
|
+
if (!entry.isFile() || !archiveFileName(entry.name)) return undefined;
|
|
209
|
+
const filePath = path.join(archiveDir, entry.name);
|
|
210
|
+
try {
|
|
211
|
+
const fileStat = await fs.lstat(filePath);
|
|
212
|
+
if (fileStat.isSymbolicLink() || !fileStat.isFile()) return undefined;
|
|
213
|
+
if (!reserveCandidateBudget(fileStat, budget)) return undefined;
|
|
214
|
+
return {
|
|
215
|
+
kind: 'archive',
|
|
216
|
+
filePath,
|
|
217
|
+
fileName: entry.name,
|
|
218
|
+
containerDir: archiveDir,
|
|
219
|
+
projectHashDir,
|
|
220
|
+
sessionId: null,
|
|
221
|
+
isCurrentSession: false,
|
|
222
|
+
sizeBytes: getFileSize(fileStat),
|
|
223
|
+
mtime: fileStat.mtime,
|
|
224
|
+
dev: fileStat.dev,
|
|
225
|
+
ino: fileStat.ino,
|
|
226
|
+
};
|
|
227
|
+
} catch {
|
|
228
|
+
budget.errors += 1;
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
233
231
|
}
|
|
234
232
|
|
|
235
|
-
/** Scan `session-*.jsonl.gz` archive files inside a chats/archive directory. */
|
|
236
233
|
async function scanArchiveSessions(
|
|
237
234
|
archiveDir: string,
|
|
238
235
|
projectHashDir: string,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
236
|
+
budget: ScanBudget,
|
|
237
|
+
): Promise<SessionCandidate[]> {
|
|
238
|
+
const candidates: SessionCandidate[] = [];
|
|
239
|
+
if (budget.exhausted || candidateBudgetAtLimit(budget)) return candidates;
|
|
242
240
|
try {
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
245
|
-
return
|
|
241
|
+
const archiveStat = await fs.lstat(archiveDir);
|
|
242
|
+
if (archiveStat.isSymbolicLink() || !archiveStat.isDirectory()) {
|
|
243
|
+
return candidates;
|
|
246
244
|
}
|
|
247
|
-
} catch (error
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// Non-ENOENT error (EACCES, EIO, …) — count as a scan failure (OCR 39).
|
|
251
|
-
return { candidates: [], errors: 1 };
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (!hasErrnoCode(error, 'ENOENT')) budget.errors += 1;
|
|
247
|
+
return candidates;
|
|
252
248
|
}
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
let directory: Awaited<ReturnType<typeof fs.opendir>>;
|
|
250
|
+
try {
|
|
251
|
+
directory = await fs.opendir(archiveDir);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
if (!hasErrnoCode(error, 'ENOENT')) budget.errors += 1;
|
|
254
|
+
return candidates;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
for await (const entry of directory) {
|
|
258
|
+
if (candidateBudgetAtLimit(budget)) {
|
|
259
|
+
markBudgetExhausted(budget);
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
const candidate = await scanArchiveSessionEntry(
|
|
263
|
+
entry,
|
|
264
|
+
archiveDir,
|
|
265
|
+
projectHashDir,
|
|
266
|
+
budget,
|
|
267
|
+
);
|
|
268
|
+
if (candidate !== undefined) candidates.push(candidate);
|
|
269
|
+
}
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (!hasErrnoCode(error, 'ENOENT')) budget.errors += 1;
|
|
272
|
+
}
|
|
273
|
+
return candidates;
|
|
274
|
+
}
|
|
275
|
+
async function validatedChatsDirectory(
|
|
276
|
+
globalTempDir: string,
|
|
277
|
+
projectName: string,
|
|
278
|
+
budget: ScanBudget,
|
|
279
|
+
): Promise<string | undefined> {
|
|
280
|
+
const projectPath = path.join(globalTempDir, projectName);
|
|
281
|
+
const chatsDir = path.join(projectPath, 'chats');
|
|
255
282
|
try {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
283
|
+
const projectStat = await fs.lstat(projectPath);
|
|
284
|
+
if (projectStat.isSymbolicLink() || !projectStat.isDirectory()) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
const chatsStat = await fs.lstat(chatsDir);
|
|
288
|
+
if (chatsStat.isSymbolicLink() || !chatsStat.isDirectory()) {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
return chatsDir;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (!hasErrnoCode(error, 'ENOENT')) budget.errors += 1;
|
|
294
|
+
return undefined;
|
|
261
295
|
}
|
|
296
|
+
}
|
|
262
297
|
|
|
263
|
-
|
|
264
|
-
|
|
298
|
+
async function appendProjectSessions(
|
|
299
|
+
globalTempDir: string,
|
|
300
|
+
projectName: string,
|
|
301
|
+
currentSessionId: string | undefined,
|
|
302
|
+
budget: ScanBudget,
|
|
303
|
+
candidates: SessionCandidate[],
|
|
304
|
+
chatsDirs: string[],
|
|
305
|
+
): Promise<void> {
|
|
306
|
+
const chatsDir = await validatedChatsDirectory(
|
|
307
|
+
globalTempDir,
|
|
308
|
+
projectName,
|
|
309
|
+
budget,
|
|
265
310
|
);
|
|
311
|
+
if (chatsDir === undefined) return;
|
|
312
|
+
chatsDirs.push(chatsDir);
|
|
313
|
+
candidates.push(
|
|
314
|
+
...(await scanRawSessions(chatsDir, projectName, currentSessionId, budget)),
|
|
315
|
+
);
|
|
316
|
+
if (budget.exhausted) return;
|
|
317
|
+
candidates.push(
|
|
318
|
+
...(await scanArchiveSessions(
|
|
319
|
+
path.join(chatsDir, ARCHIVE_DIR_NAME),
|
|
320
|
+
projectName,
|
|
321
|
+
budget,
|
|
322
|
+
)),
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
function projectBudgetAtLimit(projects: number, budget: ScanBudget): boolean {
|
|
326
|
+
if (projects < budget.limits.maxProjects && !budget.exhausted) return false;
|
|
327
|
+
if (!budget.exhausted) budget.skipped += 1;
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
266
330
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
331
|
+
/**
|
|
332
|
+
* Scan session recordings sequentially under explicit candidate and byte limits.
|
|
333
|
+
*
|
|
334
|
+
* @param globalTempDir - Global session temporary directory.
|
|
335
|
+
* @param currentSessionId - Session identifier that must be marked active.
|
|
336
|
+
* @param limits - Finite project, file, and aggregate-byte bounds.
|
|
337
|
+
* @returns Candidates, discovered chats directories, errors, and skipped entries.
|
|
338
|
+
*/
|
|
339
|
+
export async function scanGlobalSessions(
|
|
340
|
+
globalTempDir: string,
|
|
341
|
+
currentSessionId?: string,
|
|
342
|
+
limits: SessionScanLimits = DEFAULT_SCAN_LIMITS,
|
|
343
|
+
): Promise<ScanResult> {
|
|
344
|
+
const budget: ScanBudget = {
|
|
345
|
+
limits: validatedLimits(limits),
|
|
346
|
+
files: 0,
|
|
347
|
+
bytes: 0,
|
|
348
|
+
skipped: 0,
|
|
349
|
+
errors: 0,
|
|
350
|
+
exhausted: false,
|
|
351
|
+
};
|
|
352
|
+
const candidates: SessionCandidate[] = [];
|
|
353
|
+
const chatsDirs: string[] = [];
|
|
354
|
+
let projects = 0;
|
|
355
|
+
let directory: Awaited<ReturnType<typeof fs.opendir>>;
|
|
356
|
+
try {
|
|
357
|
+
directory = await fs.opendir(globalTempDir);
|
|
358
|
+
} catch (error) {
|
|
359
|
+
if (hasErrnoCode(error, 'ENOENT')) {
|
|
360
|
+
return {
|
|
361
|
+
candidates,
|
|
362
|
+
chatsDirs,
|
|
363
|
+
scanErrorCount: 0,
|
|
364
|
+
scanSkippedCount: 0,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
for await (const entry of directory) {
|
|
370
|
+
if (PROJECT_HASH_RE.test(entry.name)) {
|
|
371
|
+
if (projectBudgetAtLimit(projects, budget)) break;
|
|
372
|
+
projects += 1;
|
|
373
|
+
await appendProjectSessions(
|
|
374
|
+
globalTempDir,
|
|
375
|
+
entry.name,
|
|
376
|
+
currentSessionId,
|
|
377
|
+
budget,
|
|
378
|
+
candidates,
|
|
379
|
+
chatsDirs,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
candidates,
|
|
385
|
+
chatsDirs,
|
|
386
|
+
scanErrorCount: budget.errors,
|
|
387
|
+
scanSkippedCount: budget.skipped,
|
|
388
|
+
};
|
|
297
389
|
}
|
|
@@ -138,17 +138,48 @@ export function compressedLine(
|
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
140
|
* Build a valid JSONL line for a rewind event.
|
|
141
|
+
*
|
|
142
|
+
* `cutSeq` is the chronology `seq` of the first removed item (#2934). When it
|
|
143
|
+
* is omitted the payload carries no `cutSeq` key, matching legacy count-only
|
|
144
|
+
* rewind events.
|
|
141
145
|
*/
|
|
142
|
-
export function rewindLine(
|
|
146
|
+
export function rewindLine(
|
|
147
|
+
seq: number,
|
|
148
|
+
itemsRemoved: number,
|
|
149
|
+
cutSeq?: number,
|
|
150
|
+
): string {
|
|
143
151
|
return JSON.stringify({
|
|
144
152
|
v: 1,
|
|
145
153
|
seq,
|
|
146
154
|
ts: new Date().toISOString(),
|
|
147
155
|
type: 'rewind',
|
|
148
|
-
payload: { itemsRemoved },
|
|
156
|
+
payload: cutSeq === undefined ? { itemsRemoved } : { itemsRemoved, cutSeq },
|
|
149
157
|
});
|
|
150
158
|
}
|
|
151
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Build a text content entry carrying an explicit chronology marker, as
|
|
162
|
+
* HistoryService stamps them before the entry reaches the journal (#1721).
|
|
163
|
+
*/
|
|
164
|
+
export function makeMarkedContent(
|
|
165
|
+
text: string,
|
|
166
|
+
speaker: IContent['speaker'],
|
|
167
|
+
chronologySeq: number,
|
|
168
|
+
): IContent {
|
|
169
|
+
return {
|
|
170
|
+
speaker,
|
|
171
|
+
blocks: [{ type: 'text', text }],
|
|
172
|
+
metadata: {
|
|
173
|
+
chronology: {
|
|
174
|
+
seq: chronologySeq,
|
|
175
|
+
userTurn: 1,
|
|
176
|
+
step: chronologySeq,
|
|
177
|
+
recordedAt: 1787000000000,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
152
183
|
/**
|
|
153
184
|
* Build a valid JSONL line for a provider_switch event.
|
|
154
185
|
*/
|