MCPcopy Create free account
hub / github.com/github/copilot-sdk / startCLIServer

Method startCLIServer

go/client.go:1722–1930  ·  view source on GitHub ↗

startCLIServer starts the CLI server process. This spawns the CLI server as a subprocess using the configured transport mode (stdio or TCP).

(ctx context.Context)

Source from the content-addressed store, hash-verified

1720// This spawns the CLI server as a subprocess using the configured transport
1721// mode (stdio or TCP).
1722func (c *Client) startCLIServer(ctx context.Context) error {
1723 cliPath := c.cliPath
1724 if cliPath == "" {
1725 // If no CLI path is provided, attempt to use the embedded CLI if available
1726 cliPath = embeddedcli.Path()
1727 }
1728 if cliPath == "" {
1729 // Default to "copilot" in PATH if no embedded CLI is available and no custom path is set
1730 cliPath = "copilot"
1731 }
1732
1733 // Start with user-provided CLIArgs, then add SDK-managed args
1734 args := append([]string{}, c.cliArgs...)
1735 args = append(args, "--headless", "--no-auto-update")
1736 // Only pass --log-level when explicitly configured; otherwise let the
1737 // runtime use its own default.
1738 if c.options.LogLevel != "" {
1739 args = append(args, "--log-level", c.options.LogLevel)
1740 }
1741
1742 // Choose transport mode
1743 if c.useStdio {
1744 args = append(args, "--stdio")
1745 } else if c.port > 0 {
1746 args = append(args, "--port", strconv.Itoa(c.port))
1747 }
1748
1749 // Add auth-related flags
1750 if c.options.GitHubToken != "" {
1751 args = append(args, "--auth-token-env", "COPILOT_SDK_AUTH_TOKEN")
1752 }
1753 // Default useLoggedInUser to false when GitHubToken is provided
1754 useLoggedInUser := true
1755 if c.options.UseLoggedInUser != nil {
1756 useLoggedInUser = *c.options.UseLoggedInUser
1757 } else if c.options.GitHubToken != "" {
1758 useLoggedInUser = false
1759 }
1760 if !useLoggedInUser {
1761 args = append(args, "--no-auto-login")
1762 }
1763
1764 if c.options.SessionIdleTimeoutSeconds > 0 {
1765 args = append(args, "--session-idle-timeout", strconv.Itoa(c.options.SessionIdleTimeoutSeconds))
1766 }
1767
1768 if c.options.EnableRemoteSessions {
1769 args = append(args, "--remote")
1770 }
1771
1772 // If CLIPath is a .js file, run it with node
1773 // Note we can't rely on the shebang as Windows doesn't support it
1774 command := cliPath
1775 if strings.HasSuffix(cliPath, ".js") {
1776 command = "node"
1777 args = append([]string{cliPath}, args...)
1778 }
1779

Callers 1

StartMethod · 0.95

Calls 13

monitorProcessMethod · 0.95
killProcessMethod · 0.95
setEnvValueFunction · 0.85
NewClientMethod · 0.80
SetProcessDoneMethod · 0.80
SetOnCloseMethod · 0.80
StringMethod · 0.80
TextMethod · 0.80
configureProcAttrFunction · 0.70
DoneMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected