-
Notifications
You must be signed in to change notification settings - Fork 22
feat(daemon): remote kit sessions over iroh (kit daemon / kit --remote) #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c45e912
feat: daemon mode with iroh remote sessions (kit daemon / kit --remote)
ezynda3 64eeb52
fix: task dev builds the kit-tunnel sidecar
ezynda3 1abd872
feat: multi-session daemon over one endpoint, per-session teardown, e…
ezynda3 0a08113
fix: clean client terminal after remote session exit
ezynda3 77217b4
feat: daemon single-instance lock, 'kit daemon status', systemd user …
ezynda3 92d6b01
fix: check f.Close error in ReadStatus probe (errcheck)
ezynda3 fa14138
build: release pipeline ships the embedded kit-tunnel sidecar
ezynda3 5c2b47e
fix(daemon): address CodeRabbit review on remote sessions (#113)
ezynda3 f5db58d
fix(tunnel): expire pre-authentication slot reservations (#113)
ezynda3 71180d0
fix(ci): stop persisting checkout credentials in test jobs (#113)
ezynda3 1365789
fix(tunnel): time out accept_bi to release stalled session slots (#113)
ezynda3 039a57e
fix(tunnel): bound over-cap rejection tasks (#113)
ezynda3 bdb8eb6
fix(tunnel): bound concurrent over-cap rejection tasks (#113)
ezynda3 7ce77d4
docs: document remote sessions (kit daemon / kit --remote)
ezynda3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/signal" | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/mark3labs/kit/internal/daemon" | ||
| ) | ||
|
|
||
| var daemonCode string | ||
|
|
||
| var daemonCmd = &cobra.Command{ | ||
| Use: "daemon", | ||
| Short: "Run Kit as a remote daemon, waiting for a pairing connection", | ||
| Long: `Run Kit as a remote daemon. | ||
|
|
||
| Generates a pairing code and waits for remote peers to connect with | ||
| "kit --remote CODE". Each verified peer picks a working directory | ||
| (starting in this user's home directory) and gets its own session: | ||
| the session runs entirely on this machine, rendered inside the peer's | ||
| terminal. Multiple clients can hold sessions at the same time, and | ||
| exiting a session only disconnects that client. | ||
|
|
||
| The pairing code stays valid while the daemon runs; press Ctrl+C to | ||
| stop. Only one daemon may run per user; use "kit daemon status" to | ||
| inspect a running instance and "kit daemon service install" to manage | ||
| it via systemd (user service).`, | ||
| RunE: func(cmd *cobra.Command, _ []string) error { | ||
| ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) | ||
| defer stop() | ||
| return daemon.Serve(ctx, daemon.ServeOptions{Code: daemonCode}) | ||
| }, | ||
| } | ||
|
|
||
| var daemonStatusCmd = &cobra.Command{ | ||
| Use: "status", | ||
| Short: "Show the pairing code and state of a running daemon", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(_ *cobra.Command, _ []string) error { | ||
| st := daemon.ReadStatus() | ||
| if !st.Running { | ||
| fmt.Println("kit daemon is not running.") | ||
| fmt.Println("Start one with: kit daemon (or: kit daemon service install)") | ||
| if st.State != nil { | ||
| fmt.Printf("(stale state on disk from pid %d, started %s, code %s)\n", | ||
| st.State.PID, st.State.StartedAt.Format("2006-01-02 15:04"), st.State.Code) | ||
| } | ||
| return nil | ||
| } | ||
| s := st.State | ||
| if s == nil { | ||
| fmt.Printf("kit daemon is running (pid unknown — state file not written yet)\n") | ||
| return nil | ||
| } | ||
| uptime := time.Since(s.StartedAt).Round(time.Second) | ||
| fmt.Printf("kit daemon is running (pid %d, up %s)\n", s.PID, uptime) | ||
| fmt.Printf(" Pairing code: %s\n", s.Code) | ||
| fmt.Printf(" Connect with: kit --remote %s\n", normalizeForHint(s.Code)) | ||
| if s.Endpoint != "" { | ||
| fmt.Printf(" Endpoint: %s\n", s.Endpoint) | ||
| } | ||
| fmt.Printf(" Active sessions: %d\n", s.SessionsActive) | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| // normalizeForHint strips the display dash so the connect hint is | ||
| // copy-pasteable. | ||
| func normalizeForHint(displayCode string) string { | ||
| out := make([]byte, 0, len(displayCode)) | ||
| for i := 0; i < len(displayCode); i++ { | ||
| if displayCode[i] != '-' { | ||
| out = append(out, displayCode[i]) | ||
| } | ||
| } | ||
| return string(out) | ||
| } | ||
|
|
||
| var daemonServiceCmd = &cobra.Command{ | ||
| Use: "service", | ||
| Short: "Manage the kit daemon systemd user service", | ||
| Args: cobra.NoArgs, | ||
| } | ||
|
|
||
| var daemonServiceInstallCmd = &cobra.Command{ | ||
| Use: "install", | ||
| Short: "Install and start the systemd user service", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, _ []string) error { | ||
| return daemon.InstallSystemService(cmd.Context()) | ||
| }, | ||
| } | ||
|
|
||
| var daemonServiceRemoveCmd = &cobra.Command{ | ||
| Use: "remove", | ||
| Short: "Stop and uninstall the systemd user service", | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, _ []string) error { | ||
| return daemon.RemoveSystemService(cmd.Context()) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| daemonCmd.Flags().StringVar(&daemonCode, "code", "", "use a fixed pairing code instead of a random one (testing)") | ||
| _ = daemonCmd.Flags().MarkHidden("code") | ||
| daemonCmd.AddCommand(daemonStatusCmd) | ||
| daemonServiceCmd.AddCommand(daemonServiceInstallCmd) | ||
| daemonServiceCmd.AddCommand(daemonServiceRemoveCmd) | ||
| daemonCmd.AddCommand(daemonServiceCmd) | ||
| rootCmd.AddCommand(daemonCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /target |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.