@gitkraken/core-gitlens 0.1.0 → 0.3.0
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/CHANGELOG.md +25 -1
- package/dist/git/cache.d.ts +49 -9
- package/dist/git/cache.d.ts.map +1 -1
- package/dist/git/cache.js +174 -14
- package/dist/git/cache.js.map +1 -1
- package/dist/git/context.d.ts +11 -2
- package/dist/git/context.d.ts.map +1 -1
- package/dist/git/context.js.map +1 -1
- package/dist/git/models/branch.d.ts +1 -0
- package/dist/git/models/branch.d.ts.map +1 -1
- package/dist/git/models/branch.js.map +1 -1
- package/dist/git/models/commit.d.ts +1 -9
- package/dist/git/models/commit.d.ts.map +1 -1
- package/dist/git/models/commit.js +4 -9
- package/dist/git/models/commit.js.map +1 -1
- package/dist/git/models/graph.d.ts +2 -4
- package/dist/git/models/graph.d.ts.map +1 -1
- package/dist/git/models/reference.d.ts +31 -0
- package/dist/git/models/reference.d.ts.map +1 -1
- package/dist/git/models/remote.d.ts.map +1 -1
- package/dist/git/models/remote.js.map +1 -1
- package/dist/git/models/repository.d.ts +20 -3
- package/dist/git/models/repository.d.ts.map +1 -1
- package/dist/git/models/repository.js +42 -5
- package/dist/git/models/repository.js.map +1 -1
- package/dist/git/models/search.d.ts +2 -2
- package/dist/git/models/search.d.ts.map +1 -1
- package/dist/git/models/worktree.d.ts +4 -1
- package/dist/git/models/worktree.d.ts.map +1 -1
- package/dist/git/models/worktree.js +2 -2
- package/dist/git/models/worktree.js.map +1 -1
- package/dist/git/parsers/diffParser.d.ts +0 -1
- package/dist/git/parsers/diffParser.d.ts.map +1 -1
- package/dist/git/parsers/diffParser.js +22 -61
- package/dist/git/parsers/diffParser.js.map +1 -1
- package/dist/git/providers/branches.d.ts +18 -4
- package/dist/git/providers/branches.d.ts.map +1 -1
- package/dist/git/providers/commits.d.ts +6 -0
- package/dist/git/providers/commits.d.ts.map +1 -1
- package/dist/git/providers/config.d.ts +6 -1
- package/dist/git/providers/config.d.ts.map +1 -1
- package/dist/git/providers/diff.d.ts +2 -0
- package/dist/git/providers/diff.d.ts.map +1 -1
- package/dist/git/providers/operations.d.ts +39 -10
- package/dist/git/providers/operations.d.ts.map +1 -1
- package/dist/git/providers/pausedOperations.d.ts +3 -1
- package/dist/git/providers/pausedOperations.d.ts.map +1 -1
- package/dist/git/providers/refs.d.ts +23 -2
- package/dist/git/providers/refs.d.ts.map +1 -1
- package/dist/git/providers/revision.d.ts +1 -1
- package/dist/git/providers/revision.d.ts.map +1 -1
- package/dist/git/providers/staging.d.ts +18 -0
- package/dist/git/providers/staging.d.ts.map +1 -1
- package/dist/git/providers/status.d.ts +4 -1
- package/dist/git/providers/status.d.ts.map +1 -1
- package/dist/git/remotes/azure-devops.d.ts.map +1 -1
- package/dist/git/remotes/azure-devops.js.map +1 -1
- package/dist/git/{exec.types.d.ts → run.types.d.ts} +22 -3
- package/dist/git/run.types.d.ts.map +1 -0
- package/dist/git/run.types.js +2 -0
- package/dist/git/run.types.js.map +1 -0
- package/dist/git/service.d.ts.map +1 -1
- package/dist/git/service.js.map +1 -1
- package/dist/git/utils/autolink.utils.d.ts.map +1 -1
- package/dist/git/utils/autolink.utils.js.map +1 -1
- package/dist/git/utils/blame.utils.d.ts.map +1 -1
- package/dist/git/utils/blame.utils.js.map +1 -1
- package/dist/git/utils/conflictResolution.utils.d.ts +6 -0
- package/dist/git/utils/conflictResolution.utils.d.ts.map +1 -0
- package/dist/git/utils/conflictResolution.utils.js +25 -0
- package/dist/git/utils/conflictResolution.utils.js.map +1 -0
- package/dist/git/utils/fileStatus.utils.d.ts +2 -1
- package/dist/git/utils/fileStatus.utils.d.ts.map +1 -1
- package/dist/git/utils/fileStatus.utils.js +4 -0
- package/dist/git/utils/fileStatus.utils.js.map +1 -1
- package/dist/git/utils/search.utils.d.ts.map +1 -1
- package/dist/git/utils/search.utils.js +3 -0
- package/dist/git/utils/search.utils.js.map +1 -1
- package/dist/git/utils/sorting.d.ts +14 -0
- package/dist/git/utils/sorting.d.ts.map +1 -1
- package/dist/git/utils/sorting.js +34 -0
- package/dist/git/utils/sorting.js.map +1 -1
- package/dist/git/utils/status.utils.d.ts.map +1 -1
- package/dist/git/utils/status.utils.js.map +1 -1
- package/dist/git/watching/classifyChange.d.ts.map +1 -1
- package/dist/git/watching/classifyChange.js +8 -0
- package/dist/git/watching/classifyChange.js.map +1 -1
- package/dist/git/watching/gitIgnoreFilter.js +1 -1
- package/dist/git/watching/gitIgnoreFilter.js.map +1 -1
- package/dist/git/watching/initWatcher.d.ts.map +1 -1
- package/dist/git/watching/initWatcher.js.map +1 -1
- package/dist/git/watching/watchGroup.d.ts.map +1 -1
- package/dist/git/watching/watchGroup.js.map +1 -1
- package/dist/git/watching/watchService.d.ts.map +1 -1
- package/dist/git/watching/watchService.js +24 -4
- package/dist/git/watching/watchService.js.map +1 -1
- package/dist/git/watching/watchSession.d.ts.map +1 -1
- package/dist/git/watching/watchSession.js.map +1 -1
- package/dist/git-cli/cliGitProvider.js +1 -1
- package/dist/git-cli/cliGitProvider.js.map +1 -1
- package/dist/git-cli/exec/exec.types.d.ts +1 -1
- package/dist/git-cli/exec/exec.types.d.ts.map +1 -1
- package/dist/git-cli/exec/git.d.ts +31 -6
- package/dist/git-cli/exec/git.d.ts.map +1 -1
- package/dist/git-cli/exec/git.js +70 -9
- package/dist/git-cli/exec/git.js.map +1 -1
- package/dist/git-cli/exec/gitQueue.d.ts +22 -6
- package/dist/git-cli/exec/gitQueue.d.ts.map +1 -1
- package/dist/git-cli/exec/gitQueue.js +88 -24
- package/dist/git-cli/exec/gitQueue.js.map +1 -1
- package/dist/git-cli/parsers/blameParser.d.ts.map +1 -1
- package/dist/git-cli/parsers/blameParser.js.map +1 -1
- package/dist/git-cli/parsers/logParser.d.ts +1 -0
- package/dist/git-cli/parsers/logParser.d.ts.map +1 -1
- package/dist/git-cli/parsers/logParser.js +4 -0
- package/dist/git-cli/parsers/logParser.js.map +1 -1
- package/dist/git-cli/parsers/refParser.d.ts +3 -30
- package/dist/git-cli/parsers/refParser.d.ts.map +1 -1
- package/dist/git-cli/parsers/refParser.js +30 -30
- package/dist/git-cli/parsers/refParser.js.map +1 -1
- package/dist/git-cli/providers/blame.d.ts.map +1 -1
- package/dist/git-cli/providers/blame.js +1 -1
- package/dist/git-cli/providers/blame.js.map +1 -1
- package/dist/git-cli/providers/branches.d.ts +17 -5
- package/dist/git-cli/providers/branches.d.ts.map +1 -1
- package/dist/git-cli/providers/branches.js +245 -162
- package/dist/git-cli/providers/branches.js.map +1 -1
- package/dist/git-cli/providers/commits.d.ts +4 -0
- package/dist/git-cli/providers/commits.d.ts.map +1 -1
- package/dist/git-cli/providers/commits.js +120 -35
- package/dist/git-cli/providers/commits.js.map +1 -1
- package/dist/git-cli/providers/config.d.ts +11 -2
- package/dist/git-cli/providers/config.d.ts.map +1 -1
- package/dist/git-cli/providers/config.js +36 -11
- package/dist/git-cli/providers/config.js.map +1 -1
- package/dist/git-cli/providers/contributors.d.ts.map +1 -1
- package/dist/git-cli/providers/contributors.js +7 -4
- package/dist/git-cli/providers/contributors.js.map +1 -1
- package/dist/git-cli/providers/diff.d.ts +2 -0
- package/dist/git-cli/providers/diff.d.ts.map +1 -1
- package/dist/git-cli/providers/diff.js +92 -20
- package/dist/git-cli/providers/diff.js.map +1 -1
- package/dist/git-cli/providers/graph.d.ts.map +1 -1
- package/dist/git-cli/providers/graph.js +49 -28
- package/dist/git-cli/providers/graph.js.map +1 -1
- package/dist/git-cli/providers/operations.d.ts +30 -11
- package/dist/git-cli/providers/operations.d.ts.map +1 -1
- package/dist/git-cli/providers/operations.js +146 -43
- package/dist/git-cli/providers/operations.js.map +1 -1
- package/dist/git-cli/providers/patch.d.ts.map +1 -1
- package/dist/git-cli/providers/patch.js +15 -30
- package/dist/git-cli/providers/patch.js.map +1 -1
- package/dist/git-cli/providers/pausedOperations.d.ts +3 -1
- package/dist/git-cli/providers/pausedOperations.d.ts.map +1 -1
- package/dist/git-cli/providers/pausedOperations.js +13 -7
- package/dist/git-cli/providers/pausedOperations.js.map +1 -1
- package/dist/git-cli/providers/refs.d.ts +19 -2
- package/dist/git-cli/providers/refs.d.ts.map +1 -1
- package/dist/git-cli/providers/refs.js +312 -9
- package/dist/git-cli/providers/refs.js.map +1 -1
- package/dist/git-cli/providers/remotes.js +4 -4
- package/dist/git-cli/providers/remotes.js.map +1 -1
- package/dist/git-cli/providers/revision.d.ts +1 -1
- package/dist/git-cli/providers/revision.d.ts.map +1 -1
- package/dist/git-cli/providers/revision.js +15 -11
- package/dist/git-cli/providers/revision.js.map +1 -1
- package/dist/git-cli/providers/staging.d.ts +8 -0
- package/dist/git-cli/providers/staging.d.ts.map +1 -1
- package/dist/git-cli/providers/staging.js +52 -8
- package/dist/git-cli/providers/staging.js.map +1 -1
- package/dist/git-cli/providers/stash.d.ts +0 -8
- package/dist/git-cli/providers/stash.d.ts.map +1 -1
- package/dist/git-cli/providers/stash.js +63 -119
- package/dist/git-cli/providers/stash.js.map +1 -1
- package/dist/git-cli/providers/status.d.ts +4 -1
- package/dist/git-cli/providers/status.d.ts.map +1 -1
- package/dist/git-cli/providers/status.js +10 -9
- package/dist/git-cli/providers/status.js.map +1 -1
- package/dist/git-cli/providers/tags.d.ts.map +1 -1
- package/dist/git-cli/providers/tags.js +13 -9
- package/dist/git-cli/providers/tags.js.map +1 -1
- package/dist/git-cli/providers/worktrees.js +3 -3
- package/dist/git-cli/providers/worktrees.js.map +1 -1
- package/dist/ipc/discovery.d.ts +27 -0
- package/dist/ipc/discovery.d.ts.map +1 -0
- package/dist/ipc/discovery.js +38 -0
- package/dist/ipc/discovery.js.map +1 -0
- package/dist/ipc/ipcServer.d.ts +20 -0
- package/dist/ipc/ipcServer.d.ts.map +1 -0
- package/dist/ipc/ipcServer.js +162 -0
- package/dist/ipc/ipcServer.js.map +1 -0
- package/dist/plus/agents/providers/claudeCodeProvider.d.ts +114 -0
- package/dist/plus/agents/providers/claudeCodeProvider.d.ts.map +1 -0
- package/dist/plus/agents/providers/claudeCodeProvider.js +1480 -0
- package/dist/plus/agents/providers/claudeCodeProvider.js.map +1 -0
- package/dist/plus/agents/providers/claudeCodeTranscript.d.ts +36 -0
- package/dist/plus/agents/providers/claudeCodeTranscript.d.ts.map +1 -0
- package/dist/plus/agents/providers/claudeCodeTranscript.js +171 -0
- package/dist/plus/agents/providers/claudeCodeTranscript.js.map +1 -0
- package/dist/plus/agents/sanitizePrompt.d.ts +15 -0
- package/dist/plus/agents/sanitizePrompt.d.ts.map +1 -0
- package/dist/plus/agents/sanitizePrompt.js +103 -0
- package/dist/plus/agents/sanitizePrompt.js.map +1 -0
- package/dist/plus/agents/stateMachine.d.ts +32 -0
- package/dist/plus/agents/stateMachine.d.ts.map +1 -0
- package/dist/plus/agents/stateMachine.js +180 -0
- package/dist/plus/agents/stateMachine.js.map +1 -0
- package/dist/plus/agents/types.d.ts +203 -0
- package/dist/plus/agents/types.d.ts.map +1 -0
- package/dist/plus/agents/types.js +49 -0
- package/dist/plus/agents/types.js.map +1 -0
- package/dist/plus/ai/constants.d.ts +2 -1
- package/dist/plus/ai/constants.d.ts.map +1 -1
- package/dist/plus/ai/constants.js +7 -0
- package/dist/plus/ai/constants.js.map +1 -1
- package/dist/plus/ai/errors.d.ts +4 -1
- package/dist/plus/ai/errors.d.ts.map +1 -1
- package/dist/plus/ai/errors.js +38 -0
- package/dist/plus/ai/errors.js.map +1 -1
- package/dist/plus/ai/models/model.d.ts +1 -1
- package/dist/plus/ai/models/model.d.ts.map +1 -1
- package/dist/plus/ai/models/model.js.map +1 -1
- package/dist/plus/ai/models/promptTemplates.d.ts +28 -2
- package/dist/plus/ai/models/promptTemplates.d.ts.map +1 -1
- package/dist/plus/ai/models/results.d.ts +28 -0
- package/dist/plus/ai/models/results.d.ts.map +1 -1
- package/dist/plus/ai/prompts.d.ts +4 -0
- package/dist/plus/ai/prompts.d.ts.map +1 -1
- package/dist/plus/ai/prompts.js +167 -1
- package/dist/plus/ai/prompts.js.map +1 -1
- package/dist/plus/ai/utils/ai.utils.d.ts.map +1 -1
- package/dist/plus/ai/utils/ai.utils.js +2 -0
- package/dist/plus/ai/utils/ai.utils.js.map +1 -1
- package/dist/plus/ai/utils/results.utils.d.ts +3 -0
- package/dist/plus/ai/utils/results.utils.d.ts.map +1 -1
- package/dist/plus/ai/utils/results.utils.js +75 -0
- package/dist/plus/ai/utils/results.utils.js.map +1 -1
- package/dist/plus/ai/utils/truncation.utils.d.ts +1 -1
- package/dist/plus/ai/utils/truncation.utils.d.ts.map +1 -1
- package/dist/plus/ai/utils/truncation.utils.js.map +1 -1
- package/dist/plus/git-github/api/github.d.ts +10 -1
- package/dist/plus/git-github/api/github.d.ts.map +1 -1
- package/dist/plus/git-github/api/github.js +156 -49
- package/dist/plus/git-github/api/github.js.map +1 -1
- package/dist/plus/git-github/api/types.d.ts +8 -0
- package/dist/plus/git-github/api/types.d.ts.map +1 -1
- package/dist/plus/git-github/models.d.ts +1 -1
- package/dist/plus/git-github/models.d.ts.map +1 -1
- package/dist/plus/git-github/models.js.map +1 -1
- package/dist/plus/git-github/providers/github/blame.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/blame.js.map +1 -1
- package/dist/plus/git-github/providers/github/branches.d.ts +5 -1
- package/dist/plus/git-github/providers/github/branches.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/branches.js +60 -22
- package/dist/plus/git-github/providers/github/branches.js.map +1 -1
- package/dist/plus/git-github/providers/github/commits.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/commits.js +144 -92
- package/dist/plus/git-github/providers/github/commits.js.map +1 -1
- package/dist/plus/git-github/providers/github/diff.d.ts +3 -1
- package/dist/plus/git-github/providers/github/diff.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/diff.js +23 -9
- package/dist/plus/git-github/providers/github/diff.js.map +1 -1
- package/dist/plus/git-github/providers/github/refs.d.ts +9 -1
- package/dist/plus/git-github/providers/github/refs.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/refs.js +38 -13
- package/dist/plus/git-github/providers/github/refs.js.map +1 -1
- package/dist/plus/git-github/providers/github/revision.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/revision.js +1 -2
- package/dist/plus/git-github/providers/github/revision.js.map +1 -1
- package/dist/plus/git-github/providers/github/status.d.ts +4 -1
- package/dist/plus/git-github/providers/github/status.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/status.js +1 -1
- package/dist/plus/git-github/providers/github/status.js.map +1 -1
- package/dist/plus/git-github/providers/github/tags.d.ts.map +1 -1
- package/dist/plus/git-github/providers/github/tags.js +35 -36
- package/dist/plus/git-github/providers/github/tags.js.map +1 -1
- package/dist/plus/git-github/providers/githubGitProvider.d.ts.map +1 -1
- package/dist/plus/git-github/providers/githubGitProvider.js.map +1 -1
- package/dist/utils/color.d.ts.map +1 -1
- package/dist/utils/color.js.map +1 -1
- package/dist/utils/decorators/log.js +1 -1
- package/dist/utils/decorators/log.js.map +1 -1
- package/dist/utils/decorators/sequentialize.d.ts.map +1 -1
- package/dist/utils/decorators/sequentialize.js +4 -2
- package/dist/utils/decorators/sequentialize.js.map +1 -1
- package/dist/utils/decorators/serializable.d.ts.map +1 -1
- package/dist/utils/decorators/serializable.js.map +1 -1
- package/dist/utils/dedupedAsyncCache.d.ts +37 -0
- package/dist/utils/dedupedAsyncCache.d.ts.map +1 -0
- package/dist/utils/dedupedAsyncCache.js +68 -0
- package/dist/utils/dedupedAsyncCache.js.map +1 -0
- package/dist/utils/diff.d.ts +2 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +53 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/disposable.d.ts.map +1 -1
- package/dist/utils/disposable.js.map +1 -1
- package/dist/utils/env/node/base64.js.map +1 -1
- package/dist/utils/env/node/exec.d.ts.map +1 -1
- package/dist/utils/env/node/exec.js.map +1 -1
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/formatter.d.ts.map +1 -1
- package/dist/utils/formatter.js +4 -10
- package/dist/utils/formatter.js.map +1 -1
- package/dist/utils/iterable.d.ts.map +1 -1
- package/dist/utils/iterable.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/lruMap.d.ts +49 -0
- package/dist/utils/lruMap.d.ts.map +1 -0
- package/dist/utils/lruMap.js +103 -0
- package/dist/utils/lruMap.js.map +1 -0
- package/dist/utils/markdown.d.ts.map +1 -1
- package/dist/utils/markdown.js.map +1 -1
- package/dist/utils/mru.d.ts.map +1 -1
- package/dist/utils/mru.js.map +1 -1
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/promise.d.ts +1 -0
- package/dist/utils/promise.d.ts.map +1 -1
- package/dist/utils/promise.js +17 -0
- package/dist/utils/promise.js.map +1 -1
- package/dist/utils/promiseCache.d.ts +10 -0
- package/dist/utils/promiseCache.d.ts.map +1 -1
- package/dist/utils/promiseCache.js +22 -0
- package/dist/utils/promiseCache.js.map +1 -1
- package/dist/utils/string.d.ts.map +1 -1
- package/dist/utils/string.js.map +1 -1
- package/dist/utils/uri.d.ts.map +1 -1
- package/dist/utils/uri.js.map +1 -1
- package/dist/utils/version.d.ts +14 -0
- package/dist/utils/version.d.ts.map +1 -1
- package/dist/utils/version.js +48 -0
- package/dist/utils/version.js.map +1 -1
- package/package.json +13 -1
- package/src/git/cache.ts +309 -29
- package/src/git/context.ts +11 -2
- package/src/git/models/branch.ts +1 -0
- package/src/git/models/commit.ts +2 -17
- package/src/git/models/graph.ts +2 -4
- package/src/git/models/reference.ts +33 -0
- package/src/git/models/remote.ts +1 -0
- package/src/git/models/repository.ts +44 -6
- package/src/git/models/search.ts +2 -2
- package/src/git/models/worktree.ts +10 -2
- package/src/git/parsers/diffParser.ts +9 -44
- package/src/git/providers/branches.ts +25 -4
- package/src/git/providers/commits.ts +7 -0
- package/src/git/providers/config.ts +4 -0
- package/src/git/providers/diff.ts +8 -2
- package/src/git/providers/operations.ts +54 -3
- package/src/git/providers/pausedOperations.ts +1 -0
- package/src/git/providers/refs.ts +32 -3
- package/src/git/providers/revision.ts +5 -1
- package/src/git/providers/staging.ts +14 -0
- package/src/git/providers/status.ts +6 -1
- package/src/git/remotes/azure-devops.ts +2 -0
- package/src/git/{exec.types.ts → run.types.ts} +22 -2
- package/src/git/service.ts +1 -0
- package/src/git/utils/autolink.utils.ts +1 -0
- package/src/git/utils/blame.utils.ts +2 -0
- package/src/git/utils/conflictResolution.utils.ts +31 -0
- package/src/git/utils/fileStatus.utils.ts +7 -1
- package/src/git/utils/search.utils.ts +2 -0
- package/src/git/utils/sorting.ts +38 -0
- package/src/git/utils/status.utils.ts +1 -0
- package/src/git/watching/classifyChange.ts +9 -0
- package/src/git/watching/gitIgnoreFilter.ts +2 -2
- package/src/git/watching/initWatcher.ts +2 -0
- package/src/git/watching/watchGroup.ts +3 -0
- package/src/git/watching/watchService.ts +38 -5
- package/src/git/watching/watchSession.ts +10 -0
- package/src/git-cli/cliGitProvider.ts +1 -1
- package/src/git-cli/exec/exec.types.ts +2 -2
- package/src/git-cli/exec/git.ts +76 -23
- package/src/git-cli/exec/gitQueue.ts +98 -25
- package/src/git-cli/parsers/blameParser.ts +1 -0
- package/src/git-cli/parsers/logParser.ts +6 -1
- package/src/git-cli/parsers/refParser.ts +33 -34
- package/src/git-cli/providers/blame.ts +2 -1
- package/src/git-cli/providers/branches.ts +341 -196
- package/src/git-cli/providers/commits.ts +145 -46
- package/src/git-cli/providers/config.ts +50 -16
- package/src/git-cli/providers/contributors.ts +7 -12
- package/src/git-cli/providers/diff.ts +107 -20
- package/src/git-cli/providers/graph.ts +58 -29
- package/src/git-cli/providers/operations.ts +253 -57
- package/src/git-cli/providers/patch.ts +16 -37
- package/src/git-cli/providers/pausedOperations.ts +14 -6
- package/src/git-cli/providers/refs.ts +274 -11
- package/src/git-cli/providers/remotes.ts +4 -4
- package/src/git-cli/providers/revision.ts +22 -15
- package/src/git-cli/providers/staging.ts +51 -8
- package/src/git-cli/providers/stash.ts +67 -134
- package/src/git-cli/providers/status.ts +21 -10
- package/src/git-cli/providers/tags.ts +18 -19
- package/src/git-cli/providers/worktrees.ts +3 -3
- package/src/ipc/discovery.ts +56 -0
- package/src/ipc/ipcServer.ts +171 -0
- package/src/plus/agents/providers/claudeCodeProvider.ts +1782 -0
- package/src/plus/agents/providers/claudeCodeTranscript.ts +214 -0
- package/src/plus/agents/sanitizePrompt.ts +109 -0
- package/src/plus/agents/stateMachine.ts +197 -0
- package/src/plus/agents/types.ts +277 -0
- package/src/plus/ai/constants.ts +8 -0
- package/src/plus/ai/errors.ts +40 -0
- package/src/plus/ai/models/model.ts +1 -0
- package/src/plus/ai/models/promptTemplates.ts +42 -0
- package/src/plus/ai/models/results.ts +30 -0
- package/src/plus/ai/prompts.ts +171 -1
- package/src/plus/ai/utils/ai.utils.ts +2 -0
- package/src/plus/ai/utils/results.utils.ts +101 -0
- package/src/plus/ai/utils/truncation.utils.ts +3 -1
- package/src/plus/git-github/api/github.ts +199 -53
- package/src/plus/git-github/api/types.ts +15 -0
- package/src/plus/git-github/models.ts +1 -1
- package/src/plus/git-github/providers/github/blame.ts +2 -0
- package/src/plus/git-github/providers/github/branches.ts +75 -33
- package/src/plus/git-github/providers/github/commits.ts +231 -160
- package/src/plus/git-github/providers/github/diff.ts +35 -21
- package/src/plus/git-github/providers/github/refs.ts +57 -22
- package/src/plus/git-github/providers/github/revision.ts +1 -2
- package/src/plus/git-github/providers/github/status.ts +6 -1
- package/src/plus/git-github/providers/github/tags.ts +61 -62
- package/src/plus/git-github/providers/githubGitProvider.ts +1 -0
- package/src/utils/color.ts +2 -0
- package/src/utils/decorators/log.ts +1 -1
- package/src/utils/decorators/sequentialize.ts +8 -6
- package/src/utils/decorators/serializable.ts +1 -0
- package/src/utils/dedupedAsyncCache.ts +74 -0
- package/src/utils/diff.ts +61 -0
- package/src/utils/disposable.ts +2 -0
- package/src/utils/env/node/base64.ts +1 -1
- package/src/utils/env/node/exec.ts +4 -2
- package/src/utils/error.ts +1 -0
- package/src/utils/formatter.ts +4 -11
- package/src/utils/iterable.ts +4 -1
- package/src/utils/logger.ts +1 -0
- package/src/utils/lruMap.ts +112 -0
- package/src/utils/markdown.ts +1 -0
- package/src/utils/mru.ts +2 -0
- package/src/utils/path.ts +1 -0
- package/src/utils/promise.ts +22 -0
- package/src/utils/promiseCache.ts +24 -0
- package/src/utils/string.ts +2 -0
- package/src/utils/uri.ts +1 -0
- package/src/utils/version.ts +49 -0
- package/dist/git/exec.types.d.ts.map +0 -1
- package/dist/git/exec.types.js +0 -2
- package/dist/git/exec.types.js.map +0 -1
|
@@ -6,6 +6,7 @@ import type { GitConflictFile } from '../../git/models/staging.js';
|
|
|
6
6
|
import { GitStatus } from '../../git/models/status.js';
|
|
7
7
|
import type { GitStatusFile } from '../../git/models/statusFile.js';
|
|
8
8
|
import type { GitStatusSubProvider, GitWorkingChangesState } from '../../git/providers/status.js';
|
|
9
|
+
import type { GitCommandPriority } from '../../git/run.types.js';
|
|
9
10
|
import { isCancellationError } from '../../utils/cancellation.js';
|
|
10
11
|
import { gate } from '../../utils/decorators/gate.js';
|
|
11
12
|
import { debug } from '../../utils/decorators/log.js';
|
|
@@ -33,19 +34,27 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
33
34
|
|
|
34
35
|
@gate(rp => rp ?? '')
|
|
35
36
|
@debug()
|
|
36
|
-
async getStatus(
|
|
37
|
+
async getStatus(
|
|
38
|
+
repoPath: string | undefined,
|
|
39
|
+
options?: { priority?: GitCommandPriority },
|
|
40
|
+
cancellation?: AbortSignal,
|
|
41
|
+
): Promise<GitStatus | undefined> {
|
|
37
42
|
if (repoPath == null) return undefined;
|
|
38
43
|
|
|
39
44
|
const porcelainVersion = (await this.git.supports('git:status:porcelain-v2')) ? 2 : 1;
|
|
40
45
|
|
|
41
|
-
const result = await this.statusCore(repoPath, porcelainVersion, {}, cancellation);
|
|
46
|
+
const result = await this.statusCore(repoPath, porcelainVersion, { priority: options?.priority }, cancellation);
|
|
42
47
|
const repoUri = fileUri(normalizePath(repoPath));
|
|
43
48
|
const status = parseGitStatus(result.stdout, repoPath, porcelainVersion, p =>
|
|
44
49
|
joinUriPath(repoUri, normalizePath(p)),
|
|
45
50
|
);
|
|
46
51
|
|
|
47
52
|
if (status?.detached) {
|
|
48
|
-
const pausedOpStatus = await this.provider.pausedOps?.getPausedOperationStatus?.(
|
|
53
|
+
const pausedOpStatus = await this.provider.pausedOps?.getPausedOperationStatus?.(
|
|
54
|
+
repoPath,
|
|
55
|
+
undefined,
|
|
56
|
+
cancellation,
|
|
57
|
+
);
|
|
49
58
|
if (pausedOpStatus?.type === 'rebase') {
|
|
50
59
|
return new GitStatus(
|
|
51
60
|
repoPath,
|
|
@@ -126,7 +135,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
126
135
|
private async statusCore(
|
|
127
136
|
repoPath: string,
|
|
128
137
|
porcelainVersion: number = 1,
|
|
129
|
-
options?: { similarityThreshold?: number },
|
|
138
|
+
options?: { similarityThreshold?: number; priority?: GitCommandPriority },
|
|
130
139
|
cancellation?: AbortSignal,
|
|
131
140
|
...pathspecs: string[]
|
|
132
141
|
): Promise<GitResult> {
|
|
@@ -142,12 +151,13 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
142
151
|
);
|
|
143
152
|
}
|
|
144
153
|
|
|
145
|
-
return this.git.
|
|
154
|
+
return this.git.run(
|
|
146
155
|
{
|
|
147
156
|
cwd: repoPath,
|
|
148
157
|
cancellation: cancellation,
|
|
149
158
|
configs: gitConfigsStatus,
|
|
150
159
|
env: { GIT_OPTIONAL_LOCKS: '0' },
|
|
160
|
+
...(options?.priority != null ? { priority: options.priority } : undefined),
|
|
151
161
|
},
|
|
152
162
|
...params,
|
|
153
163
|
'--',
|
|
@@ -168,7 +178,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
168
178
|
const staged = options?.staged ?? true;
|
|
169
179
|
const unstaged = options?.unstaged ?? true;
|
|
170
180
|
if (staged || unstaged) {
|
|
171
|
-
const result = await this.git.
|
|
181
|
+
const result = await this.git.run(
|
|
172
182
|
{ cwd: repoPath, cancellation: cancellation, errors: 'ignore' },
|
|
173
183
|
'diff',
|
|
174
184
|
'--quiet',
|
|
@@ -218,14 +228,14 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
218
228
|
try {
|
|
219
229
|
const [stagedResult, unstagedResult, untrackedResult] = await Promise.allSettled([
|
|
220
230
|
// Check for staged changes
|
|
221
|
-
this.git.
|
|
231
|
+
this.git.run(
|
|
222
232
|
{ cwd: repoPath, cancellation: cancellation, errors: 'ignore' },
|
|
223
233
|
'diff',
|
|
224
234
|
'--quiet',
|
|
225
235
|
'--staged',
|
|
226
236
|
),
|
|
227
237
|
// Check for unstaged changes
|
|
228
|
-
this.git.
|
|
238
|
+
this.git.run({ cwd: repoPath, cancellation: cancellation, errors: 'ignore' }, 'diff', '--quiet'),
|
|
229
239
|
// Check for untracked files
|
|
230
240
|
this.hasUntrackedFiles(repoPath, cancellation),
|
|
231
241
|
]);
|
|
@@ -247,6 +257,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
247
257
|
return result;
|
|
248
258
|
} catch (ex) {
|
|
249
259
|
if (isCancellationError(ex)) throw ex;
|
|
260
|
+
|
|
250
261
|
scope?.error(ex);
|
|
251
262
|
scope?.addExitInfo('error checking for changes');
|
|
252
263
|
// Return all false on error for graceful degradation
|
|
@@ -279,7 +290,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
279
290
|
const scope = getScopedLogger();
|
|
280
291
|
|
|
281
292
|
try {
|
|
282
|
-
const result = await this.git.
|
|
293
|
+
const result = await this.git.run(
|
|
283
294
|
{ cwd: repoPath, cancellation: cancellation, errors: 'ignore' },
|
|
284
295
|
'ls-files',
|
|
285
296
|
'-z',
|
|
@@ -337,7 +348,7 @@ export class StatusGitSubProvider implements GitStatusSubProvider {
|
|
|
337
348
|
const scope = getScopedLogger();
|
|
338
349
|
|
|
339
350
|
try {
|
|
340
|
-
const result = await this.git.
|
|
351
|
+
const result = await this.git.run(
|
|
341
352
|
{ cwd: repoPath, cancellation: cancellation, errors: 'ignore' },
|
|
342
353
|
'ls-files',
|
|
343
354
|
'-z',
|
|
@@ -16,7 +16,6 @@ import type { CliGitProviderInternal } from '../cliGitProvider.js';
|
|
|
16
16
|
import type { GitResult } from '../exec/exec.types.js';
|
|
17
17
|
import type { Git, GitError } from '../exec/git.js';
|
|
18
18
|
import { getGitCommandError, gitConfigsBranch } from '../exec/git.js';
|
|
19
|
-
import { getTagParser } from '../parsers/refParser.js';
|
|
20
19
|
|
|
21
20
|
export class TagsGitSubProvider implements GitTagsSubProvider {
|
|
22
21
|
constructor(
|
|
@@ -54,29 +53,29 @@ export class TagsGitSubProvider implements GitTagsSubProvider {
|
|
|
54
53
|
// Prefer the aggregate signal from the cache; fall back to the caller's cancellation.
|
|
55
54
|
signal ??= cancellation;
|
|
56
55
|
try {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const result = await this.git.exec(
|
|
60
|
-
{ cwd: repoPath, cancellation: signal },
|
|
61
|
-
'for-each-ref',
|
|
62
|
-
...parser.arguments,
|
|
63
|
-
'refs/tags/',
|
|
64
|
-
);
|
|
65
|
-
if (!result.stdout) return emptyPagedResult;
|
|
56
|
+
const records = await this.provider.refs.getRefs(commonPath, signal);
|
|
57
|
+
if (!records.length) return emptyPagedResult;
|
|
66
58
|
|
|
67
59
|
using sw = maybeStopWatch(scope, { log: { onlyExit: true, level: 'debug' } });
|
|
68
60
|
|
|
69
61
|
const tags: GitTag[] = [];
|
|
70
62
|
|
|
71
|
-
for (const
|
|
63
|
+
for (const record of records) {
|
|
64
|
+
const fullName = record.name;
|
|
65
|
+
if (!fullName.startsWith('refs/tags/')) continue;
|
|
66
|
+
|
|
67
|
+
// Annotated tags: peeledObjectname is the commit SHA; objectname is the tag-object SHA.
|
|
68
|
+
// Lightweight tags: peeledObjectname is empty; objectname is already the commit SHA.
|
|
69
|
+
const sha = record.peeledObjectname || record.objectname;
|
|
70
|
+
|
|
72
71
|
tags.push(
|
|
73
72
|
new GitTag(
|
|
74
73
|
commonPath,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
fullName,
|
|
75
|
+
sha,
|
|
76
|
+
record.subject,
|
|
77
|
+
record.creatorDate ? new Date(record.creatorDate) : undefined,
|
|
78
|
+
record.authorDate ? new Date(record.authorDate) : undefined,
|
|
80
79
|
),
|
|
81
80
|
);
|
|
82
81
|
}
|
|
@@ -130,7 +129,7 @@ export class TagsGitSubProvider implements GitTagsSubProvider {
|
|
|
130
129
|
const params: string[] = ['tag', '--format=%(refname:short)'];
|
|
131
130
|
params.push(options?.mode === 'pointsAt' ? `--points-at=${sha}` : `--contains=${sha}`);
|
|
132
131
|
|
|
133
|
-
return this.git.
|
|
132
|
+
return this.git.run(
|
|
134
133
|
{
|
|
135
134
|
cwd: repoPath,
|
|
136
135
|
cancellation: cancellation,
|
|
@@ -149,7 +148,7 @@ export class TagsGitSubProvider implements GitTagsSubProvider {
|
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
try {
|
|
152
|
-
await this.git.
|
|
151
|
+
await this.git.run({ cwd: repoPath }, ...args);
|
|
153
152
|
this.context.hooks?.cache?.onReset?.(repoPath, 'tags');
|
|
154
153
|
this.context.hooks?.repository?.onChanged?.(repoPath, ['tags']);
|
|
155
154
|
} catch (ex) {
|
|
@@ -170,7 +169,7 @@ export class TagsGitSubProvider implements GitTagsSubProvider {
|
|
|
170
169
|
const args = ['tag', '-d', name];
|
|
171
170
|
|
|
172
171
|
try {
|
|
173
|
-
await this.git.
|
|
172
|
+
await this.git.run({ cwd: repoPath }, ...args);
|
|
174
173
|
this.context.hooks?.cache?.onReset?.(repoPath, 'tags');
|
|
175
174
|
this.context.hooks?.repository?.onChanged?.(repoPath, ['tags']);
|
|
176
175
|
} catch (ex) {
|
|
@@ -49,7 +49,7 @@ export class WorktreesGitSubProvider implements GitWorktreesSubProvider {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
try {
|
|
52
|
-
await this.git.
|
|
52
|
+
await this.git.run({ cwd: repoPath }, ...args);
|
|
53
53
|
|
|
54
54
|
this.context.hooks?.cache?.onReset?.(
|
|
55
55
|
repoPath,
|
|
@@ -106,7 +106,7 @@ export class WorktreesGitSubProvider implements GitWorktreesSubProvider {
|
|
|
106
106
|
// Prefer the aggregate signal from the cache; fall back to the caller's cancellation.
|
|
107
107
|
signal ??= cancellation;
|
|
108
108
|
const [dataResult, branchesResult] = await Promise.allSettled([
|
|
109
|
-
this.git.
|
|
109
|
+
this.git.run({ cwd: commonPath, cancellation: signal }, 'worktree', 'list', '--porcelain'),
|
|
110
110
|
this.provider.branches.getBranches(commonPath, undefined, signal),
|
|
111
111
|
]);
|
|
112
112
|
|
|
@@ -154,7 +154,7 @@ export class WorktreesGitSubProvider implements GitWorktreesSubProvider {
|
|
|
154
154
|
|
|
155
155
|
let deleted = false;
|
|
156
156
|
try {
|
|
157
|
-
await this.git.
|
|
157
|
+
await this.git.run({ cwd: repoPath, errors: 'throw' }, ...args);
|
|
158
158
|
deleted = true;
|
|
159
159
|
} catch (ex) {
|
|
160
160
|
scope?.error(ex);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { mkdir, unlink, writeFile } from 'fs/promises';
|
|
2
|
+
import { tmpdir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { ppid } from 'process';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Directory scanned by `gk` binaries (and `@gitkraken/core-gitlens` consumers) for the
|
|
8
|
+
* extension's CLI-capable IPC server discovery file. Anything written here is assumed
|
|
9
|
+
* by older `gk` versions to be a CLI server — do NOT write agent-only files here.
|
|
10
|
+
*/
|
|
11
|
+
export const cliDiscoveryDir = join(tmpdir(), 'gitkraken', 'gitlens');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Directory scanned by peer GitLens windows for agent-session-capable IPC servers.
|
|
15
|
+
* Stable across GitLens versions; older windows still scan it, so don't move it.
|
|
16
|
+
*/
|
|
17
|
+
export const agentDiscoveryDir = join(tmpdir(), 'gitkraken', 'gitlens', 'agents');
|
|
18
|
+
|
|
19
|
+
export interface IpcDiscoveryData {
|
|
20
|
+
token: string;
|
|
21
|
+
address: string;
|
|
22
|
+
port: number;
|
|
23
|
+
workspacePaths: string[];
|
|
24
|
+
// Optional fields — present when the writing capability needs them.
|
|
25
|
+
// Old gk binaries ignore unknown fields, so this stays back-compat.
|
|
26
|
+
ideName?: string;
|
|
27
|
+
ideDisplayName?: string;
|
|
28
|
+
scheme?: string;
|
|
29
|
+
pid?: number;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getDiscoveryFileName(port: number): string {
|
|
34
|
+
return `gitlens-ipc-server-${ppid}-${port}.json`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getDiscoveryFilePath(dir: string, port: number): string {
|
|
38
|
+
return join(dir, getDiscoveryFileName(port));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function writeDiscoveryFile(dir: string, data: IpcDiscoveryData): Promise<string> {
|
|
42
|
+
const filePath = getDiscoveryFilePath(dir, data.port);
|
|
43
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
44
|
+
await writeFile(filePath, JSON.stringify(data, null, 2), { mode: 0o600 });
|
|
45
|
+
return filePath;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function cleanupDiscoveryFile(filePath: string | undefined): Promise<void> {
|
|
49
|
+
if (filePath == null) return;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await unlink(filePath);
|
|
53
|
+
} catch {
|
|
54
|
+
// Ignore cleanup errors
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { IncomingMessage, Server, ServerResponse } from 'http';
|
|
2
|
+
import { createServer } from 'http';
|
|
3
|
+
import { uuid } from '../utils/crypto.js';
|
|
4
|
+
import { debug } from '../utils/decorators/log.js';
|
|
5
|
+
import type { UnifiedDisposable } from '../utils/disposable.js';
|
|
6
|
+
import { createDisposable } from '../utils/disposable.js';
|
|
7
|
+
import { Logger } from '../utils/logger.js';
|
|
8
|
+
import { getScopedLogger } from '../utils/logger.scoped.js';
|
|
9
|
+
|
|
10
|
+
export interface IpcHandler<Request = unknown, Response = void> {
|
|
11
|
+
(request: Request | undefined, searchParams: URLSearchParams): Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function createIpcServer<Request = unknown, Response = void>(): Promise<IpcServer<Request, Response>> {
|
|
15
|
+
const server = createServer();
|
|
16
|
+
const token = uuid();
|
|
17
|
+
|
|
18
|
+
return new Promise<IpcServer<Request, Response>>((resolve, reject) => {
|
|
19
|
+
try {
|
|
20
|
+
server.on('error', ex => {
|
|
21
|
+
Logger.error(ex, 'IPC server error');
|
|
22
|
+
reject(ex);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Let the OS assign an available port by listening on port 0
|
|
26
|
+
server.listen(0, '127.0.0.1', () => {
|
|
27
|
+
const address = server.address();
|
|
28
|
+
if (address == null || typeof address === 'string') {
|
|
29
|
+
reject(new Error('Failed to get server address'));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const port = address.port;
|
|
34
|
+
const serverUrl = `http://127.0.0.1:${port}`;
|
|
35
|
+
resolve(new IpcServer(serverUrl, port, token, server));
|
|
36
|
+
});
|
|
37
|
+
} catch (ex) {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
39
|
+
reject(ex);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class IpcServer<Request = unknown, Response = void> implements UnifiedDisposable {
|
|
45
|
+
private readonly handlers = new Map<string | undefined, IpcHandler<Request, Response>>();
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
readonly ipcAddress: string,
|
|
49
|
+
readonly ipcPort: number,
|
|
50
|
+
readonly ipcToken: string,
|
|
51
|
+
private server: Server,
|
|
52
|
+
) {
|
|
53
|
+
server
|
|
54
|
+
.on('listening', () => {
|
|
55
|
+
Logger.trace(`IPC server listening on ${this.ipcAddress}`);
|
|
56
|
+
})
|
|
57
|
+
.on('request', this.onRequest.bind(this));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
dispose(): void {
|
|
61
|
+
this.handlers.clear();
|
|
62
|
+
this.server.close();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
[Symbol.dispose](): void {
|
|
66
|
+
this.dispose();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Awaits server close; use only when deterministic teardown is required (e.g., tests).
|
|
70
|
+
// Production callers should use dispose() — UnifiedDisposable contract is sync.
|
|
71
|
+
shutdown(): Promise<void> {
|
|
72
|
+
this.handlers.clear();
|
|
73
|
+
return new Promise<void>(resolve => {
|
|
74
|
+
this.server.close(() => resolve());
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
registerHandler(name: string, handler: IpcHandler<Request, Response>): UnifiedDisposable {
|
|
79
|
+
const path = `/${name}`;
|
|
80
|
+
if (this.handlers.has(path)) {
|
|
81
|
+
throw new Error(`IPC handler '${name}' is already registered`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.handlers.set(path, handler);
|
|
85
|
+
return createDisposable(() => this.handlers.delete(path));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@debug({ args: false })
|
|
89
|
+
private onRequest(req: IncomingMessage, res: ServerResponse): void {
|
|
90
|
+
const scope = getScopedLogger();
|
|
91
|
+
|
|
92
|
+
// Parse URL to extract pathname for routing and query parameters
|
|
93
|
+
let pathname: string | undefined;
|
|
94
|
+
let searchParams = new URLSearchParams();
|
|
95
|
+
try {
|
|
96
|
+
const url = new URL(req.url ?? '', this.ipcAddress);
|
|
97
|
+
pathname = url.pathname;
|
|
98
|
+
searchParams = url.searchParams;
|
|
99
|
+
} catch {
|
|
100
|
+
pathname = req.url;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const handler = this.handlers.get(pathname);
|
|
104
|
+
if (handler == null) {
|
|
105
|
+
scope?.warn(`IPC handler for ${pathname} not found`);
|
|
106
|
+
res.writeHead(404);
|
|
107
|
+
res.end();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Add bearer token authorization
|
|
112
|
+
const authHeader = req.headers['authorization'];
|
|
113
|
+
if (authHeader !== `Bearer ${this.ipcToken}`) {
|
|
114
|
+
Logger.warn(scope, `IPC handler for ${req.url} unauthorized`);
|
|
115
|
+
res.writeHead(401);
|
|
116
|
+
res.end();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const maxBodySize = 10_485_760; // 10 MB
|
|
121
|
+
let bodySize = 0;
|
|
122
|
+
const chunks: Uint8Array[] = [];
|
|
123
|
+
req.on('data', (d: Uint8Array) => {
|
|
124
|
+
bodySize += d.length;
|
|
125
|
+
if (bodySize > maxBodySize) {
|
|
126
|
+
res.writeHead(413);
|
|
127
|
+
res.end();
|
|
128
|
+
req.destroy();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
chunks.push(d);
|
|
133
|
+
});
|
|
134
|
+
req.on('end', async () => {
|
|
135
|
+
if (bodySize > maxBodySize) return;
|
|
136
|
+
|
|
137
|
+
const body = Buffer.concat(chunks).toString('utf8');
|
|
138
|
+
|
|
139
|
+
let data: Request | undefined;
|
|
140
|
+
try {
|
|
141
|
+
data = body ? (JSON.parse(body) as Request) : undefined;
|
|
142
|
+
} catch (ex) {
|
|
143
|
+
scope?.error(ex, 'Invalid JSON in IPC request body', { body: body });
|
|
144
|
+
res.writeHead(400);
|
|
145
|
+
res.end('Invalid JSON');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const result = await handler(data, searchParams);
|
|
151
|
+
if (result == null) {
|
|
152
|
+
res.writeHead(200);
|
|
153
|
+
res.end();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (typeof result === 'string') {
|
|
158
|
+
res.writeHead(200);
|
|
159
|
+
res.end(result);
|
|
160
|
+
} else {
|
|
161
|
+
res.writeHead(200);
|
|
162
|
+
res.end(JSON.stringify(result));
|
|
163
|
+
}
|
|
164
|
+
} catch (ex) {
|
|
165
|
+
scope?.error(ex, 'IPC handler error', data);
|
|
166
|
+
res.writeHead(500);
|
|
167
|
+
res.end();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|