Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cmd

import (
"strings"
"time"

"github.com/onkernel/cli/pkg/util"
"github.com/onkernel/kernel-go-sdk"
"github.com/pterm/pterm"
"github.com/samber/lo"
Expand Down Expand Up @@ -133,7 +133,7 @@ func runAppHistory(cmd *cobra.Command, args []string) error {
}

for _, dep := range *deployments {
created := dep.CreatedAt.Format(time.RFC3339)
created := util.FormatLocal(dep.CreatedAt)
status := string(dep.Status)

tableData = append(tableData, []string{
Expand Down
74 changes: 58 additions & 16 deletions cmd/browsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"github.com/onkernel/cli/pkg/util"
"github.com/onkernel/kernel-go-sdk"
"github.com/onkernel/kernel-go-sdk/option"
"github.com/onkernel/kernel-go-sdk/packages/ssestream"

Check failure on line 17 in cmd/browsers.go

View workflow job for this annotation

GitHub Actions / test

github.com/stainless-sdks/kernel-go@v0.0.0-20250828180419-4c2c25792fa0: invalid version: git ls-remote -q https://github.com/stainless-sdks/kernel-go in /home/runner/go/pkg/mod/cache/vcs/3563256f7b3335aeb62510446cbd6f99af044800b0672efa9e83fb3f98fc0986: exit status 128:
"github.com/onkernel/kernel-go-sdk/shared"

Check failure on line 18 in cmd/browsers.go

View workflow job for this annotation

GitHub Actions / test

github.com/stainless-sdks/kernel-go@v0.0.0-20250828180419-4c2c25792fa0: invalid version: git ls-remote -q https://github.com/stainless-sdks/kernel-go in /home/runner/go/pkg/mod/cache/vcs/3563256f7b3335aeb62510446cbd6f99af044800b0672efa9e83fb3f98fc0986: exit status 128:
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -76,10 +76,13 @@

// Inputs for each command
type BrowsersCreateInput struct {
PersistenceID string
TimeoutSeconds int
Stealth BoolFlag
Headless BoolFlag
PersistenceID string
TimeoutSeconds int
Stealth BoolFlag
Headless BoolFlag
ProfileID string
ProfileName string
ProfileSaveChanges BoolFlag
}

type BrowsersDeleteInput struct {
Expand Down Expand Up @@ -115,7 +118,7 @@

// Prepare table data
tableData := pterm.TableData{
{"Browser ID", "Created At", "Persistent ID", "CDP WS URL", "Live View URL"},
{"Browser ID", "Created At", "Persistent ID", "Profile", "CDP WS URL", "Live View URL"},
}

for _, browser := range *browsers {
Expand All @@ -124,10 +127,18 @@
persistentID = browser.Persistence.ID
}

profile := "-"
if browser.Profile.Name != "" {
profile = browser.Profile.Name
} else if browser.Profile.ID != "" {
profile = browser.Profile.ID
}

tableData = append(tableData, []string{
browser.SessionID,
browser.CreatedAt.Format("2006-01-02 15:04:05"),
util.FormatLocal(browser.CreatedAt),
persistentID,
profile,
truncateURL(browser.CdpWsURL, 50),
truncateURL(browser.BrowserLiveViewURL, 50),
})
Expand All @@ -153,6 +164,21 @@
params.Headless = kernel.Opt(in.Headless.Value)
}

// Validate profile selection: at most one of profile-id or profile-name must be provided
if in.ProfileID != "" && in.ProfileName != "" {
pterm.Error.Println("must specify at most one of --profile-id or --profile-name")
return nil
} else if in.ProfileID != "" || in.ProfileName != "" {
params.Profile = kernel.BrowserNewParamsProfile{
SaveChanges: kernel.Opt(in.ProfileSaveChanges.Value),
}
if in.ProfileID != "" {
params.Profile.ID = kernel.Opt(in.ProfileID)
} else if in.ProfileName != "" {
params.Profile.Name = kernel.Opt(in.ProfileName)
}
}

browser, err := b.browsers.New(ctx, params)
if err != nil {
return util.CleanedUpSdkError{Err: err}
Expand All @@ -169,6 +195,13 @@
if browser.Persistence.ID != "" {
tableData = append(tableData, []string{"Persistent ID", browser.Persistence.ID})
}
if browser.Profile.ID != "" || browser.Profile.Name != "" {
profVal := browser.Profile.Name
if profVal == "" {
profVal = browser.Profile.ID
}
tableData = append(tableData, []string{"Profile", profVal})
}

printTableNoPad(tableData, true)
return nil
Expand Down Expand Up @@ -337,7 +370,7 @@
defer stream.Close()
for stream.Next() {
ev := stream.Current()
pterm.Println(fmt.Sprintf("[%s] %s", ev.Timestamp.Format("2006-01-02 15:04:05"), ev.Message))
pterm.Println(fmt.Sprintf("[%s] %s", util.FormatLocal(ev.Timestamp), ev.Message))
}
if err := stream.Err(); err != nil {
return util.CleanedUpSdkError{Err: err}
Expand Down Expand Up @@ -386,7 +419,7 @@
}
rows := pterm.TableData{{"Replay ID", "Started At", "Finished At", "View URL"}}
for _, r := range *items {
rows = append(rows, []string{r.ReplayID, r.StartedAt.Format("2006-01-02 15:04:05"), r.FinishedAt.Format("2006-01-02 15:04:05"), truncateURL(r.ReplayViewURL, 60)})
rows = append(rows, []string{r.ReplayID, util.FormatLocal(r.StartedAt), util.FormatLocal(r.FinishedAt), truncateURL(r.ReplayViewURL, 60)})
}
printTableNoPad(rows, true)
return nil
Expand All @@ -412,7 +445,7 @@
if err != nil {
return util.CleanedUpSdkError{Err: err}
}
rows := pterm.TableData{{"Property", "Value"}, {"Replay ID", res.ReplayID}, {"View URL", res.ReplayViewURL}, {"Started At", res.StartedAt.Format("2006-01-02 15:04:05")}}
rows := pterm.TableData{{"Property", "Value"}, {"Replay ID", res.ReplayID}, {"View URL", res.ReplayViewURL}, {"Started At", util.FormatLocal(res.StartedAt)}}
printTableNoPad(rows, true)
return nil
}
Expand Down Expand Up @@ -597,7 +630,7 @@
if err != nil {
return util.CleanedUpSdkError{Err: err}
}
rows := pterm.TableData{{"Property", "Value"}, {"Process ID", res.ProcessID}, {"PID", fmt.Sprintf("%d", res.Pid)}, {"Started At", res.StartedAt.Format("2006-01-02 15:04:05")}}
rows := pterm.TableData{{"Property", "Value"}, {"Process ID", res.ProcessID}, {"PID", fmt.Sprintf("%d", res.Pid)}, {"Started At", util.FormatLocal(res.StartedAt)}}
printTableNoPad(rows, true)
return nil
}
Expand Down Expand Up @@ -900,7 +933,7 @@
if err != nil {
return util.CleanedUpSdkError{Err: err}
}
rows := pterm.TableData{{"Property", "Value"}, {"Path", res.Path}, {"Name", res.Name}, {"Mode", res.Mode}, {"IsDir", fmt.Sprintf("%t", res.IsDir)}, {"SizeBytes", fmt.Sprintf("%d", res.SizeBytes)}, {"ModTime", res.ModTime.Format("2006-01-02 15:04:05")}}
rows := pterm.TableData{{"Property", "Value"}, {"Path", res.Path}, {"Name", res.Name}, {"Mode", res.Mode}, {"IsDir", fmt.Sprintf("%t", res.IsDir)}, {"SizeBytes", fmt.Sprintf("%d", res.SizeBytes)}, {"ModTime", util.FormatLocal(res.ModTime)}}
printTableNoPad(rows, true)
return nil
}
Expand Down Expand Up @@ -928,7 +961,7 @@
}
rows := pterm.TableData{{"Mode", "Size", "ModTime", "Name", "Path"}}
for _, f := range *res {
rows = append(rows, []string{f.Mode, fmt.Sprintf("%d", f.SizeBytes), f.ModTime.Format("2006-01-02 15:04:05"), f.Name, f.Path})
rows = append(rows, []string{f.Mode, fmt.Sprintf("%d", f.SizeBytes), util.FormatLocal(f.ModTime), f.Name, f.Path})
}
printTableNoPad(rows, true)
return nil
Expand Down Expand Up @@ -1297,6 +1330,9 @@
browsersCreateCmd.Flags().BoolP("stealth", "s", false, "Launch browser in stealth mode to avoid detection")
browsersCreateCmd.Flags().BoolP("headless", "H", false, "Launch browser without GUI access")
browsersCreateCmd.Flags().IntP("timeout", "t", 60, "Timeout in seconds for the browser session")
browsersCreateCmd.Flags().String("profile-id", "", "Profile ID to load into the browser session (mutually exclusive with --profile-name)")
browsersCreateCmd.Flags().String("profile-name", "", "Profile name to load into the browser session (mutually exclusive with --profile-id)")
browsersCreateCmd.Flags().Bool("save-changes", false, "If set, save changes back to the profile when the session ends")

// Add flags for delete command
browsersDeleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt")
Expand All @@ -1319,12 +1355,18 @@
stealthVal, _ := cmd.Flags().GetBool("stealth")
headlessVal, _ := cmd.Flags().GetBool("headless")
timeout, _ := cmd.Flags().GetInt("timeout")
profileID, _ := cmd.Flags().GetString("profile-id")
profileName, _ := cmd.Flags().GetString("profile-name")
saveChanges, _ := cmd.Flags().GetBool("save-changes")

in := BrowsersCreateInput{
PersistenceID: persistenceID,
TimeoutSeconds: timeout,
Stealth: BoolFlag{Set: cmd.Flags().Changed("stealth"), Value: stealthVal},
Headless: BoolFlag{Set: cmd.Flags().Changed("headless"), Value: headlessVal},
PersistenceID: persistenceID,
TimeoutSeconds: timeout,
Stealth: BoolFlag{Set: cmd.Flags().Changed("stealth"), Value: stealthVal},
Headless: BoolFlag{Set: cmd.Flags().Changed("headless"), Value: headlessVal},
ProfileID: profileID,
ProfileName: profileName,
ProfileSaveChanges: BoolFlag{Set: cmd.Flags().Changed("save-changes"), Value: saveChanges},
}

svc := client.Browsers
Expand Down
5 changes: 3 additions & 2 deletions cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"time"

"github.com/onkernel/cli/pkg/util"
"github.com/onkernel/kernel-go-sdk"
"github.com/onkernel/kernel-go-sdk/option"
"github.com/pterm/pterm"
Expand Down Expand Up @@ -83,7 +84,7 @@ func runLogs(cmd *cobra.Command, args []string) error {
case "log":
logEntry := data.AsLog()
if timestamps {
fmt.Printf("%s %s\n", logEntry.Timestamp.Format(time.RFC3339Nano), logEntry.Message)
fmt.Printf("%s %s\n", util.FormatLocal(logEntry.Timestamp), logEntry.Message)
} else {
fmt.Println(logEntry.Message)
}
Expand Down Expand Up @@ -117,7 +118,7 @@ func runLogs(cmd *cobra.Command, args []string) error {
case "log":
logEntry := data.AsLog()
if timestamps {
fmt.Printf("%s %s\n", logEntry.Timestamp.Format(time.RFC3339Nano), logEntry.Message)
fmt.Printf("%s %s\n", util.FormatLocal(logEntry.Timestamp), logEntry.Message)
} else {
fmt.Println(logEntry.Message)
}
Expand Down
Loading
Loading