Add support for package executors and support for PTY handling (#100)

* define contract for package executors

* introduce npx executor

* add npx and pnpx cmd support

* fix typo

* rm PackageExecutor and depend on PackageManager interface

* add support for PTY to handle parent-child process interaction

* refactor PTY handling in proxy flow

* enforce interactiveSession interface check

* close reader explicitly and clean npm version for pkg executors

* rm interaction from interceptors

* add docs and wait for outputRouter before exit

* add support for non interactive TTY for proxy mode

* add support for CI env var check for non interactive tty proxy mode

* update readme to include npx, pnpx support

* Update internal/flows/proxy_flow.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>

* update ptyx lib

* fix docs typo

---------

Signed-off-by: Sahil Bansal <bansalsahil315@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Sahil Bansal
2026-01-09 22:03:42 +05:30
committed by GitHub
co-authored by Copilot
parent a373b5b243
commit 31f23fd065
21 changed files with 1009 additions and 96 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ type ConfirmationHook struct {
//
// The function will exit when the confirmation channel is closed.
func HandleConfirmationRequests(confirmationChan chan *ConfirmationRequest,
interaction guard.PackageManagerGuardInteraction, hooks *ConfirmationHook) {
interaction *guard.PackageManagerGuardInteraction, hooks *ConfirmationHook) {
if hooks == nil {
hooks = &ConfirmationHook{}
}
+2 -2
View File
@@ -118,7 +118,7 @@ func TestHandleConfirmationRequests(t *testing.T) {
}
confirmationChan := make(chan *ConfirmationRequest, 1)
go HandleConfirmationRequests(confirmationChan, interaction, hooks)
go HandleConfirmationRequests(confirmationChan, &interaction, hooks)
pkgVersion := mockPackageVersion("test-package", "1.0.0")
analysisResult := mockAnalysisResult()
@@ -159,7 +159,7 @@ func TestHandleConfirmationRequests_MultipleSequential(t *testing.T) {
}
confirmationChan := make(chan *ConfirmationRequest, 3)
go HandleConfirmationRequests(confirmationChan, interaction, nil)
go HandleConfirmationRequests(confirmationChan, &interaction, nil)
pkgVersion1 := mockPackageVersion("package-1", "1.0.0")
analysisResult1 := mockAnalysisResult()
-5
View File
@@ -5,7 +5,6 @@ import (
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
"github.com/safedep/pmg/analyzer"
"github.com/safedep/pmg/guard"
"github.com/safedep/pmg/proxy"
)
@@ -14,7 +13,6 @@ type InterceptorFactory struct {
analyzer analyzer.PackageVersionAnalyzer
cache AnalysisCache
confirmationChan chan *ConfirmationRequest
interaction guard.PackageManagerGuardInteraction
}
// NewInterceptorFactory creates a new interceptor factory with shared dependencies
@@ -22,13 +20,11 @@ func NewInterceptorFactory(
analyzer analyzer.PackageVersionAnalyzer,
cache AnalysisCache,
confirmationChan chan *ConfirmationRequest,
interaction guard.PackageManagerGuardInteraction,
) *InterceptorFactory {
return &InterceptorFactory{
analyzer: analyzer,
cache: cache,
confirmationChan: confirmationChan,
interaction: interaction,
}
}
@@ -41,7 +37,6 @@ func (f *InterceptorFactory) CreateInterceptor(ecosystem packagev1.Ecosystem) (p
f.analyzer,
f.cache,
f.confirmationChan,
f.interaction,
), nil
default:
-3
View File
@@ -6,7 +6,6 @@ import (
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
"github.com/safedep/dry/log"
"github.com/safedep/pmg/analyzer"
"github.com/safedep/pmg/guard"
"github.com/safedep/pmg/proxy"
)
@@ -30,14 +29,12 @@ func NewNpmRegistryInterceptor(
analyzer analyzer.PackageVersionAnalyzer,
cache AnalysisCache,
confirmationChan chan *ConfirmationRequest,
interaction guard.PackageManagerGuardInteraction,
) *NpmRegistryInterceptor {
return &NpmRegistryInterceptor{
baseRegistryInterceptor: baseRegistryInterceptor{
analyzer: analyzer,
cache: cache,
confirmationChan: confirmationChan,
interaction: interaction,
},
}
}