Skip to content

Commit bb63719

Browse files
Merge pull request #35 from priyanshujain/cleanup-excessive-comments
Remove redundant comments across codebase
2 parents 0541aa4 + 5e912cf commit bb63719

File tree

14 files changed

+8
-69
lines changed

14 files changed

+8
-69
lines changed

CLAUDE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Coding Guidelines
2+
3+
- Keep code simple and easy to read.
4+
- Avoid excessive comments — only comment when absolutely necessary.
5+
16
## Git Branch Rules
27

38
- No slashes in branch names (e.g., use `fix-something` not `fix/something`).

agent/compact.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88

99
const defaultMaxHistory = 40
1010

11-
// compactHistory trims history to half of maxHistory when it exceeds maxHistory,
12-
// prepending a summary placeholder for the removed messages.
1311
func (a *Agent) compactHistory() {
1412
if len(a.history) <= a.maxHistory {
1513
return

agent/scrub.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ var credentialPattern = regexp.MustCompile(
66
`(?i)(token|api[_-]?key|password|secret|authorization)(\s*[:=]\s*)(\S+)`,
77
)
88

9-
// bearerPattern matches "Bearer <token>" to scrub the actual token value.
109
var bearerPattern = regexp.MustCompile(
1110
`(?i)(Bearer\s+)(\S+)`,
1211
)
1312

14-
// ScrubCredentials redacts credential values in strings like "TOKEN=abcdef"
15-
// or "api_key: sk-proj-abc". The label and separator are preserved; only the
16-
// value is replaced with a redacted form that keeps the first 4 characters.
1713
func ScrubCredentials(s string) string {
18-
// Scrub Bearer tokens first (e.g. "Bearer eyJhbG...") before the
19-
// credential pattern replaces the keyword that precedes them.
14+
// Scrub Bearer tokens before the credential pattern replaces the keyword.
2015
s = bearerPattern.ReplaceAllStringFunc(s, func(match string) string {
2116
parts := bearerPattern.FindStringSubmatch(match)
2217
if len(parts) < 3 {

daemon/lock_unix.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"syscall"
99
)
1010

11-
// acquireLock takes an exclusive file lock to prevent multiple daemon instances.
12-
// Returns the lock file which must be kept open for the lifetime of the daemon.
1311
func acquireLock() (*os.File, error) {
1412
f, err := os.OpenFile(lockPath(), os.O_CREATE|os.O_RDWR, 0600)
1513
if err != nil {
@@ -24,7 +22,6 @@ func acquireLock() (*os.File, error) {
2422
return f, nil
2523
}
2624

27-
// releaseLock releases the file lock and removes the lock file.
2825
func releaseLock(f *os.File) {
2926
syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
3027
f.Close()

daemon/lock_windows.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ const (
2020
lockfileFailImmediately = 0x00000001
2121
)
2222

23-
// lockHandle stores the Windows file handle obtained during acquireLock
24-
// so that releaseLock can unlock the same handle. On Windows, os.File.Fd()
25-
// returns a new duplicated handle on each call, so we must capture it once.
23+
// On Windows, os.File.Fd() returns a new duplicated handle on each call,
24+
// so we capture it once during acquireLock for use in releaseLock.
2625
var lockHandle uintptr
2726

28-
// acquireLock takes an exclusive file lock to prevent multiple daemon instances.
29-
// Returns the lock file which must be kept open for the lifetime of the daemon.
3027
func acquireLock() (*os.File, error) {
3128
f, err := os.OpenFile(lockPath(), os.O_CREATE|os.O_RDWR, 0600)
3229
if err != nil {
@@ -51,7 +48,6 @@ func acquireLock() (*os.File, error) {
5148
return f, nil
5249
}
5350

54-
// releaseLock releases the file lock and removes the lock file.
5551
func releaseLock(f *os.File) {
5652
ol := new(syscall.Overlapped)
5753
procUnlockFileEx.Call(

internal/cli/setup.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
// gwsServices lists the Google Workspace services available via gws.
2423
var gwsServices = []string{"calendar", "drive", "docs", "sheets", "tasks", "people"}
2524

2625
var setupCmd = &cobra.Command{
@@ -33,7 +32,6 @@ var setupCmd = &cobra.Command{
3332

3433
fmt.Print("\n Welcome to OpenBotKit setup!\n\n")
3534

36-
// Step 1: Source selection.
3735
var sources []string
3836
sourceOptions := []huh.Option[string]{
3937
huh.NewOption("LLM Models (for obk chat)", "models"),
@@ -113,7 +111,6 @@ var setupCmd = &cobra.Command{
113111
return fmt.Errorf("save config: %w", err)
114112
}
115113

116-
// Install skills based on current auth state.
117114
fmt.Println("\n -- Installing skills --")
118115
result, err := skills.Install(cfg)
119116
if err != nil {
@@ -151,7 +148,6 @@ func setupGoogle(cfg *config.Config) error {
151148
return fmt.Errorf("create provider dir: %w", err)
152149
}
153150

154-
// Credentials path.
155151
defaultCredPath := cfg.GoogleCredentialsFile()
156152
var credPath string
157153

@@ -177,7 +173,6 @@ func setupGoogle(cfg *config.Config) error {
177173
return fmt.Errorf("credentials file not found: %s", credPath)
178174
}
179175

180-
// Save to config.
181176
if cfg.Providers == nil {
182177
cfg.Providers = &config.ProvidersConfig{}
183178
}
@@ -186,7 +181,6 @@ func setupGoogle(cfg *config.Config) error {
186181
}
187182
cfg.Providers.Google.CredentialsFile = credPath
188183

189-
// Scope selection.
190184
var scopes []string
191185
err = huh.NewForm(
192186
huh.NewGroup(
@@ -207,7 +201,6 @@ func setupGoogle(cfg *config.Config) error {
207201
scopes = []string{"https://www.googleapis.com/auth/gmail.readonly"}
208202
}
209203

210-
// OAuth flow.
211204
gp := google.New(google.Config{
212205
CredentialsFile: credPath,
213206
TokenDBPath: cfg.GoogleTokenDBPath(),
@@ -221,7 +214,6 @@ func setupGoogle(cfg *config.Config) error {
221214

222215
fmt.Printf("\n Authenticated as %s\n", email)
223216

224-
// Sync window.
225217
var syncDays string
226218
err = huh.NewForm(
227219
huh.NewGroup(
@@ -247,7 +239,6 @@ func setupGWS(cfg *config.Config, services []string) error {
247239
fmt.Printf("\n -- Google Workspace Setup (%s) --\n", strings.Join(services, ", "))
248240
fmt.Println(" These services are powered by gws (Google Workspace CLI).")
249241

250-
// Check for gws binary.
251242
gwsPath, err := exec.LookPath("gws")
252243
if err != nil {
253244
fmt.Println("\n Checking for gws... not found.")
@@ -273,7 +264,6 @@ func setupGWS(cfg *config.Config, services []string) error {
273264
fmt.Printf(" gws found at %s\n", gwsPath)
274265
}
275266

276-
// Share credentials with gws.
277267
credPath := cfg.GoogleCredentialsFile()
278268
home, err := os.UserHomeDir()
279269
if err != nil {
@@ -295,7 +285,6 @@ func setupGWS(cfg *config.Config, services []string) error {
295285
}
296286
fmt.Printf(" Shared credentials with gws (%s)\n", gwsCredPath)
297287

298-
// Run gws auth login.
299288
scopeArg := strings.Join(services, ",")
300289
fmt.Println("\n Opening browser for Google Workspace access...")
301290
authCmd := exec.Command(gwsPath, "auth", "login", "--scopes", scopeArg)
@@ -307,7 +296,6 @@ func setupGWS(cfg *config.Config, services []string) error {
307296
}
308297
fmt.Println(" Google Workspace authenticated.")
309298

310-
// Save to config.
311299
if cfg.Integrations == nil {
312300
cfg.Integrations = &config.IntegrationsConfig{}
313301
}
@@ -316,7 +304,6 @@ func setupGWS(cfg *config.Config, services []string) error {
316304
}
317305
cfg.Integrations.GWS.Enabled = true
318306

319-
// Merge with existing services.
320307
existing := make(map[string]bool)
321308
for _, s := range cfg.Integrations.GWS.Services {
322309
existing[s] = true
@@ -369,7 +356,6 @@ func isGWSService(s string) bool {
369356
return false
370357
}
371358

372-
// cleanPath handles drag-and-drop paths that may have quotes and whitespace.
373359
func cleanPath(s string) string {
374360
s = strings.TrimSpace(s)
375361
s = strings.Trim(s, "'\"")

oauth/google/tokensource.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"golang.org/x/oauth2"
88
)
99

10-
// dbTokenSource wraps an oauth2.TokenSource and persists refreshed tokens
11-
// back to the database on every refresh.
1210
type dbTokenSource struct {
1311
email string
1412
store *TokenStore

oauth/google/tokenstore.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"golang.org/x/oauth2"
1111
)
1212

13-
// TokenStore persists Google OAuth tokens in a local SQLite database.
14-
// Uses a single unified table instead of the legacy 2-table design.
1513
type TokenStore struct {
1614
db *sql.DB
1715
}

provider/anthropic/anthropic.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,17 @@ const (
2424
vertexAPIVersion = "vertex-2023-10-16"
2525
)
2626

27-
// Anthropic implements the provider.Provider interface using the Anthropic Messages API.
28-
// It supports both the direct Anthropic API and Google Vertex AI.
2927
type Anthropic struct {
3028
apiKey string
3129
baseURL string
3230
client *http.Client
3331

34-
// Vertex AI fields.
3532
vertexProject string
3633
vertexRegion string
3734
tokenOnce sync.Once
3835
tokenSource oauth2.TokenSource
3936
}
4037

41-
// Ensure Anthropic implements Provider at compile time.
4238
var _ provider.Provider = (*Anthropic)(nil)
4339

4440
func init() {
@@ -55,29 +51,23 @@ func init() {
5551
})
5652
}
5753

58-
// Option configures the Anthropic provider.
5954
type Option func(*Anthropic)
6055

61-
// WithBaseURL sets a custom API base URL (useful for testing).
6256
func WithBaseURL(url string) Option {
6357
return func(a *Anthropic) { a.baseURL = url }
6458
}
6559

66-
// WithHTTPClient sets a custom HTTP client.
6760
func WithHTTPClient(c *http.Client) Option {
6861
return func(a *Anthropic) { a.client = c }
6962
}
7063

71-
// WithVertexAI configures the provider to use Google Vertex AI instead of the direct Anthropic API.
72-
// Uses Google Application Default Credentials unless a custom TokenSource is provided via WithTokenSource.
7364
func WithVertexAI(project, region string) Option {
7465
return func(a *Anthropic) {
7566
a.vertexProject = project
7667
a.vertexRegion = region
7768
}
7869
}
7970

80-
// WithTokenSource sets a custom OAuth2 token source for Vertex AI authentication.
8171
func WithTokenSource(ts oauth2.TokenSource) Option {
8272
return func(a *Anthropic) { a.tokenSource = ts }
8373
}
@@ -103,7 +93,6 @@ func (a *Anthropic) vertexToken(ctx context.Context) (string, error) {
10393
return token.AccessToken, nil
10494
}
10595

106-
// New creates a new Anthropic provider.
10796
func New(apiKey string, opts ...Option) *Anthropic {
10897
a := &Anthropic{
10998
apiKey: apiKey,
@@ -116,7 +105,6 @@ func New(apiKey string, opts ...Option) *Anthropic {
116105
return a
117106
}
118107

119-
// Chat sends a non-streaming chat request.
120108
func (a *Anthropic) Chat(ctx context.Context, req provider.ChatRequest) (*provider.ChatResponse, error) {
121109
body := a.buildRequest(req, false)
122110

@@ -138,7 +126,6 @@ func (a *Anthropic) Chat(ctx context.Context, req provider.ChatRequest) (*provid
138126
return a.parseResponse(&apiResp), nil
139127
}
140128

141-
// StreamChat sends a streaming chat request and returns a channel of events.
142129
func (a *Anthropic) StreamChat(ctx context.Context, req provider.ChatRequest) (<-chan provider.StreamEvent, error) {
143130
body := a.buildRequest(req, true)
144131

@@ -167,14 +154,12 @@ func (a *Anthropic) buildRequest(req provider.ChatRequest, stream bool) map[stri
167154
body["stream"] = true
168155
}
169156

170-
// Convert messages.
171157
var msgs []map[string]any
172158
for _, m := range req.Messages {
173159
msgs = append(msgs, convertMessage(m))
174160
}
175161
body["messages"] = msgs
176162

177-
// Convert tools.
178163
if len(req.Tools) > 0 {
179164
var tools []map[string]any
180165
for _, t := range req.Tools {
@@ -417,8 +402,6 @@ func (a *Anthropic) parseSSE(body io.ReadCloser, ch chan<- provider.StreamEvent)
417402
}
418403
}
419404

420-
// API types for JSON marshaling.
421-
422405
type apiResponse struct {
423406
Type string `json:"type"`
424407
Content []apiContent `json:"content"`

provider/credential.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/zalando/go-keyring"
99
)
1010

11-
// LoadCredential retrieves an API key from the OS keyring.
12-
// The ref format is "keychain:<service>/<account>", e.g. "keychain:obk/anthropic".
1311
func LoadCredential(ref string) (string, error) {
1412
service, account, err := parseCredentialRef(ref)
1513
if err != nil {
@@ -22,7 +20,6 @@ func LoadCredential(ref string) (string, error) {
2220
return val, nil
2321
}
2422

25-
// StoreCredential saves an API key to the OS keyring.
2623
func StoreCredential(ref, value string) error {
2724
service, account, err := parseCredentialRef(ref)
2825
if err != nil {
@@ -34,9 +31,6 @@ func StoreCredential(ref, value string) error {
3431
return nil
3532
}
3633

37-
// ResolveAPIKey resolves an API key from a keyring reference or
38-
// an environment variable. For headless/CI environments where no
39-
// keyring is available, set the environment variable directly.
4034
func ResolveAPIKey(ref, envVar string) (string, error) {
4135
if ref != "" && strings.HasPrefix(ref, "keychain:") {
4236
key, err := LoadCredential(ref)

0 commit comments

Comments
 (0)