Merge remote-tracking branch 'upstream/main' into feat/agent-sandbox
This commit is contained in:
commit
851dfa267a
5 changed files with 71 additions and 59 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 366 KiB After Width: | Height: | Size: 140 KiB |
|
|
@ -6,6 +6,13 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Common patterns in Go HTTP error messages
|
||||||
|
var httpStatusPatterns = []*regexp.Regexp{
|
||||||
|
regexp.MustCompile(`status[:\s]+(\d{3})`),
|
||||||
|
regexp.MustCompile(`http[/\s]+\d*\.?\d*\s+(\d{3})`),
|
||||||
|
regexp.MustCompile(`\b([3-5]\d{2})\b`),
|
||||||
|
}
|
||||||
|
|
||||||
// errorPattern defines a single pattern (string or regex) for error classification.
|
// errorPattern defines a single pattern (string or regex) for error classification.
|
||||||
type errorPattern struct {
|
type errorPattern struct {
|
||||||
substring string
|
substring string
|
||||||
|
|
@ -198,20 +205,13 @@ func classifyByMessage(msg string) FailoverReason {
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractHTTPStatus extracts an HTTP status code from an error message.
|
// extractHTTPStatus extracts an HTTP status code from an error message.
|
||||||
// Looks for patterns like "status: 429", "status 429", "HTTP 429", or standalone "429".
|
// Looks for patterns like "status: 429", "status 429", "http/1.1 429", "http 429", or standalone "429".
|
||||||
func extractHTTPStatus(msg string) int {
|
func extractHTTPStatus(msg string) int {
|
||||||
// Common patterns in Go HTTP error messages
|
for _, p := range httpStatusPatterns {
|
||||||
patterns := []*regexp.Regexp{
|
|
||||||
regexp.MustCompile(`status[:\s]+(\d{3})`),
|
|
||||||
regexp.MustCompile(`HTTP[/\s]+\d*\.?\d*\s+(\d{3})`),
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range patterns {
|
|
||||||
if m := p.FindStringSubmatch(msg); len(m) > 1 {
|
if m := p.FindStringSubmatch(msg); len(m) > 1 {
|
||||||
return parseDigits(m[1])
|
return parseDigits(m[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,8 @@ func TestExtractHTTPStatus(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{"status: 429 rate limited", 429},
|
{"status: 429 rate limited", 429},
|
||||||
{"status 401 unauthorized", 401},
|
{"status 401 unauthorized", 401},
|
||||||
{"HTTP/1.1 502 Bad Gateway", 502},
|
{"http/1.1 502 bad gateway", 502},
|
||||||
|
{"error 429", 429},
|
||||||
{"no status code here", 0},
|
{"no status code here", 0},
|
||||||
{"random number 12345", 0},
|
{"random number 12345", 0},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@ func NewGitHubCopilotProvider(uri string, connectMode string, model string) (*Gi
|
||||||
|
|
||||||
switch connectMode {
|
switch connectMode {
|
||||||
case "stdio":
|
case "stdio":
|
||||||
// TODO:
|
// TODO: Implement stdio mode for GitHub Copilot provider
|
||||||
return nil, fmt.Errorf("stdio mode not implemented")
|
// See https://github.com/github/copilot-sdk/blob/main/docs/getting-started.md for details
|
||||||
|
return nil, fmt.Errorf("stdio mode not implemented for GitHub Copilot provider; please use 'grpc' mode instead")
|
||||||
case "grpc":
|
case "grpc":
|
||||||
client := copilot.NewClient(&copilot.ClientOptions{
|
client := copilot.NewClient(&copilot.ClientOptions{
|
||||||
CLIUrl: uri,
|
CLIUrl: uri,
|
||||||
|
|
@ -100,9 +101,12 @@ func (p *GitHubCopilotProvider) Chat(
|
||||||
return nil, fmt.Errorf("provider closed")
|
return nil, fmt.Errorf("provider closed")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, _ := session.SendAndWait(ctx, copilot.MessageOptions{
|
resp, err := session.SendAndWait(ctx, copilot.MessageOptions{
|
||||||
Prompt: string(fullcontent),
|
Prompt: string(fullcontent),
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to send message to copilot: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
return nil, fmt.Errorf("empty response from copilot")
|
return nil, fmt.Errorf("empty response from copilot")
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,15 @@ type ExecTool struct {
|
||||||
restrictToWorkspace bool
|
restrictToWorkspace bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultDenyPatterns = []*regexp.Regexp{
|
var (
|
||||||
|
defaultDenyPatterns = []*regexp.Regexp{
|
||||||
regexp.MustCompile(`\brm\s+-[rf]{1,2}\b`),
|
regexp.MustCompile(`\brm\s+-[rf]{1,2}\b`),
|
||||||
regexp.MustCompile(`\bdel\s+/[fq]\b`),
|
regexp.MustCompile(`\bdel\s+/[fq]\b`),
|
||||||
regexp.MustCompile(`\brmdir\s+/s\b`),
|
regexp.MustCompile(`\brmdir\s+/s\b`),
|
||||||
regexp.MustCompile(`\b(format|mkfs|diskpart)\b\s`), // Match disk wiping commands (must be followed by space/args)
|
// Match disk wiping commands (must be followed by space/args)
|
||||||
|
regexp.MustCompile(
|
||||||
|
`\b(format|mkfs|diskpart)\b\s`,
|
||||||
|
),
|
||||||
regexp.MustCompile(`\bdd\s+if=`),
|
regexp.MustCompile(`\bdd\s+if=`),
|
||||||
regexp.MustCompile(`>\s*/dev/sd[a-z]\b`), // Block writes to disk devices (but allow /dev/null)
|
regexp.MustCompile(`>\s*/dev/sd[a-z]\b`), // Block writes to disk devices (but allow /dev/null)
|
||||||
regexp.MustCompile(`\b(shutdown|reboot|poweroff)\b`),
|
regexp.MustCompile(`\b(shutdown|reboot|poweroff)\b`),
|
||||||
|
|
@ -66,7 +70,11 @@ var defaultDenyPatterns = []*regexp.Regexp{
|
||||||
regexp.MustCompile(`\bssh\b.*@`),
|
regexp.MustCompile(`\bssh\b.*@`),
|
||||||
regexp.MustCompile(`\beval\b`),
|
regexp.MustCompile(`\beval\b`),
|
||||||
regexp.MustCompile(`\bsource\s+.*\.sh\b`),
|
regexp.MustCompile(`\bsource\s+.*\.sh\b`),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// absolutePathPattern matches absolute file paths in commands (Unix and Windows).
|
||||||
|
absolutePathPattern = regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`)
|
||||||
|
)
|
||||||
|
|
||||||
func NewExecTool(workingDir string, restrict bool) (*ExecTool, error) {
|
func NewExecTool(workingDir string, restrict bool) (*ExecTool, error) {
|
||||||
return NewExecToolWithConfig(workingDir, restrict, nil)
|
return NewExecToolWithConfig(workingDir, restrict, nil)
|
||||||
|
|
@ -280,8 +288,7 @@ func guardCommandWithPolicy(
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`)
|
matches := absolutePathPattern.FindAllString(cmd, -1)
|
||||||
matches := pathPattern.FindAllString(cmd, -1)
|
|
||||||
|
|
||||||
for _, raw := range matches {
|
for _, raw := range matches {
|
||||||
p, err := filepath.Abs(raw)
|
p, err := filepath.Abs(raw)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue