Skip to content

Commit 7445ed2

Browse files
author
SIN CI
committed
style: gofmt and goimports across cmd/sin-code
1 parent bc3f6ad commit 7445ed2

147 files changed

Lines changed: 1806 additions & 1266 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎cmd/sin-code/auto_cmd.go‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ type autoPilot interface {
3838
// autoHookVars holds injectable dependencies for the auto subcommand. Coverage
3939
// tests replace these fields to avoid real I/O or network calls.
4040
var autoHookVars = struct {
41-
osStat func(string) (os.FileInfo, error)
42-
osWriteFile func(string, []byte, os.FileMode) error
43-
osGetwd func() (string, error)
44-
loadProgram func(string) (*autopilot.Program, error)
41+
osStat func(string) (os.FileInfo, error)
42+
osWriteFile func(string, []byte, os.FileMode) error
43+
osGetwd func() (string, error)
44+
loadProgram func(string) (*autopilot.Program, error)
4545
defaultJournalPath func(string) string
46-
openJournal func(string) (*autopilot.Journal, error)
46+
openJournal func(string) (*autopilot.Journal, error)
4747
defaultSessionPath func() string
48-
openSession func(string) (*session.Store, error)
49-
openLessons func(string) (*lessons.Store, error)
50-
buildLoop func(ctx context.Context, cfg loopbuilder.Config, ls *lessons.Store) (autoLoop, func() error, error)
51-
newPilot func(cfg autopilot.Config) autoPilot
52-
newBudget func(minutes, maxExperiments int) *autopilot.Budget
53-
newSnapshotter func(string) *autopilot.Snapshotter
48+
openSession func(string) (*session.Store, error)
49+
openLessons func(string) (*lessons.Store, error)
50+
buildLoop func(ctx context.Context, cfg loopbuilder.Config, ls *lessons.Store) (autoLoop, func() error, error)
51+
newPilot func(cfg autopilot.Config) autoPilot
52+
newBudget func(minutes, maxExperiments int) *autopilot.Budget
53+
newSnapshotter func(string) *autopilot.Snapshotter
5454
}{
55-
osStat: os.Stat,
56-
osWriteFile: os.WriteFile,
57-
osGetwd: os.Getwd,
58-
loadProgram: autopilot.LoadProgram,
55+
osStat: os.Stat,
56+
osWriteFile: os.WriteFile,
57+
osGetwd: os.Getwd,
58+
loadProgram: autopilot.LoadProgram,
5959
defaultJournalPath: autopilot.DefaultJournalPath,
60-
openJournal: autopilot.OpenJournal,
60+
openJournal: autopilot.OpenJournal,
6161
defaultSessionPath: session.DefaultPath,
62-
openSession: session.Open,
63-
openLessons: lessons.Open,
62+
openSession: session.Open,
63+
openLessons: lessons.Open,
6464
buildLoop: func(ctx context.Context, cfg loopbuilder.Config, ls *lessons.Store) (autoLoop, func() error, error) {
6565
loop, cleanup, err := loopbuilder.Build(ctx, cfg, ls)
6666
if err != nil {
@@ -177,19 +177,19 @@ func newAutoRunCmd() *cobra.Command {
177177
if err != nil {
178178
return autopilot.LoopResult{}, "", err
179179
}
180-
loop, cleanup, err := autoHookVars.buildLoop(ctx, loopbuilder.Config{
181-
Workspace: workspace,
182-
SessionID: sess.ID,
183-
MaxTurns: maxTurns,
184-
VerifyMode: "poc",
185-
VerifyCmd: verifyCmd,
186-
Headless: true,
187-
Contract: autoContract,
188-
SessionStore: sessStore,
189-
ToolFactory: func(mgr *mcpclient.Manager) (agentloop.LocalToolFunc, []agentloop.ToolSpec) {
190-
return combinedTool(workspace, mgr), combinedSpecs(mgr)
191-
},
192-
}, lessonStore)
180+
loop, cleanup, err := autoHookVars.buildLoop(ctx, loopbuilder.Config{
181+
Workspace: workspace,
182+
SessionID: sess.ID,
183+
MaxTurns: maxTurns,
184+
VerifyMode: "poc",
185+
VerifyCmd: verifyCmd,
186+
Headless: true,
187+
Contract: autoContract,
188+
SessionStore: sessStore,
189+
ToolFactory: func(mgr *mcpclient.Manager) (agentloop.LocalToolFunc, []agentloop.ToolSpec) {
190+
return combinedTool(workspace, mgr), combinedSpecs(mgr)
191+
},
192+
}, lessonStore)
193193
if err != nil {
194194
return autopilot.LoopResult{}, "", err
195195
}

‎cmd/sin-code/autodev_daemon.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"fmt"
77
"os/exec"
88
"strings"
9-
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/autonomy"
9+
1010
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/agentloop"
11+
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/autonomy"
1112
)
1213

1314
func autoCreatePR(ctx context.Context, goal *autonomy.Goal, res *agentloop.Result) error {
@@ -57,6 +58,8 @@ func autoCreatePR(ctx context.Context, goal *autonomy.Goal, res *agentloop.Resul
5758
}
5859

5960
func autodevTruncate(s string, maxLen int) string {
60-
if len(s) <= maxLen { return s }
61+
if len(s) <= maxLen {
62+
return s
63+
}
6164
return s[:maxLen-3] + "..."
6265
}

‎cmd/sin-code/autodev_issue_cmd.go‎

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"fmt"
88
"os"
99
"strings"
10-
"github.com/spf13/cobra"
10+
1111
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/autonomy"
1212
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/ghbridge"
1313
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/goalcontract"
1414
"github.com/OpenSIN-Code/SIN-Code/cmd/sin-code/internal/orchestrator"
15+
"github.com/spf13/cobra"
1516
)
1617

1718
type issuePayload struct {
@@ -25,9 +26,13 @@ type issuePayload struct {
2526
func fetchIssue(ctx context.Context, repo string, number int) (*issuePayload, error) {
2627
b := ghbridge.New()
2728
out, _, err := b.Execute(ctx, []string{"issue", "view", fmt.Sprintf("%d", number), "--repo", repo, "--json", "number,title,body,state,url"})
28-
if err != nil { return nil, fmt.Errorf("gh issue view: %w", err) }
29+
if err != nil {
30+
return nil, fmt.Errorf("gh issue view: %w", err)
31+
}
2932
var issue issuePayload
30-
if err := json.Unmarshal([]byte(out), &issue); err != nil { return nil, fmt.Errorf("parse: %w", err) }
33+
if err := json.Unmarshal([]byte(out), &issue); err != nil {
34+
return nil, fmt.Errorf("parse: %w", err)
35+
}
3136
return &issue, nil
3237
}
3338

@@ -55,21 +60,36 @@ func newGoalAddFromIssueCmd() *cobra.Command {
5560
Use: "add-from-issue <number>", Short: "Read a GitHub issue and enqueue it as an autonomous goal (Autodev, issue #391)", Args: cobra.ExactArgs(1),
5661
RunE: func(cmd *cobra.Command, args []string) error {
5762
num, err := fmtAtoi(args[0])
58-
if err != nil { return fmt.Errorf("issue number must be positive: %w", err) }
59-
if repo == "" { repo = detectRepo(); if repo == "" { return fmt.Errorf("--repo not specified") } }
63+
if err != nil {
64+
return fmt.Errorf("issue number must be positive: %w", err)
65+
}
66+
if repo == "" {
67+
repo = detectRepo()
68+
if repo == "" {
69+
return fmt.Errorf("--repo not specified")
70+
}
71+
}
6072
ctx := cmd.Context()
6173
issue, err := fetchIssue(ctx, repo, num)
62-
if err != nil { return err }
63-
if issue.State != "open" { return fmt.Errorf("issue #%d is %s", num, issue.State) }
74+
if err != nil {
75+
return err
76+
}
77+
if issue.State != "open" {
78+
return fmt.Errorf("issue #%d is %s", num, issue.State)
79+
}
6480
contract := defaultIssueContract(issue)
6581
contract.SemanticCriteria = append(contract.SemanticCriteria, extraCriteria...)
6682
contractJSON, _ := contract.Marshal()
6783
q, err := autonomy.Open(autonomy.DefaultPath())
68-
if err != nil { return err }
84+
if err != nil {
85+
return err
86+
}
6987
defer q.Close()
7088
ws, _ := os.Getwd()
7189
id, err := q.AddWithContract(ctx, issueToPrompt(issue), ws, priority, retries, contractJSON)
72-
if err != nil { return err }
90+
if err != nil {
91+
return err
92+
}
7393
fmt.Printf("goal %d enqueued from issue #%d\n", id, num)
7494
return nil
7595
},
@@ -84,9 +104,15 @@ func newGoalAddFromIssueCmd() *cobra.Command {
84104
func detectRepo() string {
85105
b := ghbridge.New()
86106
out, _, err := b.Execute(context.Background(), []string{"repo", "view", "--json", "nameWithOwner"})
87-
if err != nil { return "" }
88-
var v struct{ NameWithOwner string `json:"nameWithOwner"` }
89-
if json.Unmarshal([]byte(out), &v) == nil { return v.NameWithOwner }
107+
if err != nil {
108+
return ""
109+
}
110+
var v struct {
111+
NameWithOwner string `json:"nameWithOwner"`
112+
}
113+
if json.Unmarshal([]byte(out), &v) == nil {
114+
return v.NameWithOwner
115+
}
90116
return ""
91117
}
92118

‎cmd/sin-code/browser_interaction.go‎

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,90 @@ import (
77
"fmt"
88
"strings"
99
"time"
10+
1011
"github.com/chromedp/chromedp"
1112
)
1213

1314
func toolBrowserScreenshot(ctx context.Context, selector, qualityStr string) (string, error) {
14-
if browserSession == nil { return "", fmt.Errorf("sin_browser_screenshot: no active browser session") }
15+
if browserSession == nil {
16+
return "", fmt.Errorf("sin_browser_screenshot: no active browser session")
17+
}
1518
quality := 80
16-
if qualityStr != "" { fmt.Sscanf(qualityStr, "%d", &quality) }
19+
if qualityStr != "" {
20+
fmt.Sscanf(qualityStr, "%d", &quality)
21+
}
1722
var buf []byte
1823
var err error
1924
if selector != "" {
2025
err = chromedp.Run(browserSession.cdpCtx, chromedp.WaitVisible(selector, chromedp.ByQuery), chromedp.Screenshot(selector, &buf, chromedp.ByQuery))
2126
} else {
2227
err = chromedp.Run(browserSession.cdpCtx, chromedp.CaptureScreenshot(&buf))
2328
}
24-
if err != nil { return "", fmt.Errorf("sin_browser_screenshot: %w", err) }
29+
if err != nil {
30+
return "", fmt.Errorf("sin_browser_screenshot: %w", err)
31+
}
2532
return "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf), nil
2633
}
2734

2835
func toolBrowserClick(ctx context.Context, selector string) (string, error) {
29-
if browserSession == nil { return "", fmt.Errorf("sin_browser_click: no active browser session") }
30-
if selector == "" { return "", fmt.Errorf("selector required") }
36+
if browserSession == nil {
37+
return "", fmt.Errorf("sin_browser_click: no active browser session")
38+
}
39+
if selector == "" {
40+
return "", fmt.Errorf("selector required")
41+
}
3142
err := chromedp.Run(browserSession.cdpCtx, chromedp.WaitVisible(selector, chromedp.ByQuery), chromedp.Click(selector, chromedp.ByQuery))
32-
if err != nil { return "", fmt.Errorf("sin_browser_click: %w", err) }
43+
if err != nil {
44+
return "", fmt.Errorf("sin_browser_click: %w", err)
45+
}
3346
return "clicked: " + selector, nil
3447
}
3548

3649
func toolBrowserType(ctx context.Context, selector, text, submitStr string) (string, error) {
37-
if browserSession == nil { return "", fmt.Errorf("no active browser session") }
38-
if selector == "" { return "", fmt.Errorf("selector required") }
50+
if browserSession == nil {
51+
return "", fmt.Errorf("no active browser session")
52+
}
53+
if selector == "" {
54+
return "", fmt.Errorf("selector required")
55+
}
3956
submit := strings.ToLower(submitStr) == "true"
4057
actions := []chromedp.Action{chromedp.WaitVisible(selector, chromedp.ByQuery), chromedp.Focus(selector, chromedp.ByQuery), chromedp.Clear(selector, chromedp.ByQuery), chromedp.SendKeys(selector, text, chromedp.ByQuery)}
41-
if submit { actions = append(actions, chromedp.SendKeys(selector, "\n", chromedp.ByQuery)) }
58+
if submit {
59+
actions = append(actions, chromedp.SendKeys(selector, "\n", chromedp.ByQuery))
60+
}
4261
err := chromedp.Run(browserSession.cdpCtx, actions...)
43-
if err != nil { return "", fmt.Errorf("sin_browser_type: %w", err) }
62+
if err != nil {
63+
return "", fmt.Errorf("sin_browser_type: %w", err)
64+
}
4465
r := "typed " + text + " into " + selector
45-
if submit { r += " and submitted" }
66+
if submit {
67+
r += " and submitted"
68+
}
4669
return r, nil
4770
}
4871

4972
func toolBrowserEval(ctx context.Context, expr string) (string, error) {
50-
if browserSession == nil { return "", fmt.Errorf("no active browser session") }
51-
if expr == "" { return "", fmt.Errorf("expression required") }
73+
if browserSession == nil {
74+
return "", fmt.Errorf("no active browser session")
75+
}
76+
if expr == "" {
77+
return "", fmt.Errorf("expression required")
78+
}
5279
var result any
5380
err := chromedp.Run(browserSession.cdpCtx, chromedp.Evaluate(expr, &result))
54-
if err != nil { return "", fmt.Errorf("sin_browser_eval: %w", err) }
81+
if err != nil {
82+
return "", fmt.Errorf("sin_browser_eval: %w", err)
83+
}
5584
return fmt.Sprintf("%v", result), nil
5685
}
5786

5887
func toolBrowserWait(ctx context.Context, selector, timeoutStr string) (string, error) {
59-
if browserSession == nil { return "", fmt.Errorf("no active browser session") }
60-
if selector == "" { return "", fmt.Errorf("selector required") }
88+
if browserSession == nil {
89+
return "", fmt.Errorf("no active browser session")
90+
}
91+
if selector == "" {
92+
return "", fmt.Errorf("selector required")
93+
}
6194
timeout := 10 * time.Second
6295
if timeoutStr != "" {
6396
var sec int
@@ -68,13 +101,17 @@ func toolBrowserWait(ctx context.Context, selector, timeoutStr string) (string,
68101
waitCtx, cancel := context.WithTimeout(ctx, timeout)
69102
defer cancel()
70103
err := chromedp.Run(waitCtx, chromedp.WaitVisible(selector, chromedp.ByQuery))
71-
if err != nil { return fmt.Sprintf("wait failed: %v", err), nil }
104+
if err != nil {
105+
return fmt.Sprintf("wait failed: %v", err), nil
106+
}
72107
return "element visible: " + selector, nil
73108
}
74109

75110
func registerBrowserInteractionSpecs() []agentloopToolSpecAlias {
76111
s := func(d string) map[string]any { return map[string]any{"type": "string", "description": d} }
77-
o := func(p map[string]any, r ...string) map[string]any { return map[string]any{"type": "object", "properties": p, "required": r} }
112+
o := func(p map[string]any, r ...string) map[string]any {
113+
return map[string]any{"type": "object", "properties": p, "required": r}
114+
}
78115
return []agentloopToolSpecAlias{
79116
{Name: "sin_browser_screenshot", Description: "Capture PNG screenshot as base64 data URI for visual understanding (issue #386)", InputSchema: o(map[string]any{"selector": s("CSS selector (optional)"), "quality": s("1-100 default 80")})},
80117
{Name: "sin_browser_click", Description: "Click element by CSS selector (issue #382)", InputSchema: o(map[string]any{"selector": s("CSS selector")}, "selector")},
@@ -86,11 +123,31 @@ func registerBrowserInteractionSpecs() []agentloopToolSpecAlias {
86123

87124
func dispatchBrowserInteraction(ctx context.Context, name string, args map[string]any) (string, bool, error) {
88125
switch name {
89-
case "sin_browser_screenshot": s,_ := args["selector"].(string); q,_ := args["quality"].(string); out,err := toolBrowserScreenshot(ctx,s,q); return out,true,err
90-
case "sin_browser_click": s,_ := args["selector"].(string); out,err := toolBrowserClick(ctx,s); return out,true,err
91-
case "sin_browser_type": s,_ := args["selector"].(string); t,_ := args["text"].(string); sub,_ := args["submit"].(string); out,err := toolBrowserType(ctx,s,t,sub); return out,true,err
92-
case "sin_browser_eval": e,_ := args["expr"].(string); out,err := toolBrowserEval(ctx,e); return out,true,err
93-
case "sin_browser_wait": s,_ := args["selector"].(string); t,_ := args["timeout"].(string); out,err := toolBrowserWait(ctx,s,t); return out,true,err
94-
default: return "",false,nil
126+
case "sin_browser_screenshot":
127+
s, _ := args["selector"].(string)
128+
q, _ := args["quality"].(string)
129+
out, err := toolBrowserScreenshot(ctx, s, q)
130+
return out, true, err
131+
case "sin_browser_click":
132+
s, _ := args["selector"].(string)
133+
out, err := toolBrowserClick(ctx, s)
134+
return out, true, err
135+
case "sin_browser_type":
136+
s, _ := args["selector"].(string)
137+
t, _ := args["text"].(string)
138+
sub, _ := args["submit"].(string)
139+
out, err := toolBrowserType(ctx, s, t, sub)
140+
return out, true, err
141+
case "sin_browser_eval":
142+
e, _ := args["expr"].(string)
143+
out, err := toolBrowserEval(ctx, e)
144+
return out, true, err
145+
case "sin_browser_wait":
146+
s, _ := args["selector"].(string)
147+
t, _ := args["timeout"].(string)
148+
out, err := toolBrowserWait(ctx, s, t)
149+
return out, true, err
150+
default:
151+
return "", false, nil
95152
}
96153
}

0 commit comments

Comments
 (0)