From 6a135a0489331bda12b1a87608a062ec8973cd9a Mon Sep 17 00:00:00 2001 From: ATMackay Date: Tue, 17 Mar 2026 22:54:08 +1100 Subject: [PATCH 1/3] chore(agents): Refactor, improve logging --- agents/documentor/prompt.go | 1 + cmd/documentor.go | 1 + 2 files changed, 2 insertions(+) diff --git a/agents/documentor/prompt.go b/agents/documentor/prompt.go index 87d32b8..4df1d45 100644 --- a/agents/documentor/prompt.go +++ b/agents/documentor/prompt.go @@ -16,6 +16,7 @@ Workflow: 3. Prefer entry points, cmd/, internal/, pkg/, config, and core domain files. 4. Skip tests, generated files, vendor, binaries, and irrelevant assets unless they are central. 5. Do not read more than max_files files. +6. Use resources efficiently. Reading files can be expensive so inspect them in the order that gets highest insight, you may reach the max_files limit before all files can be read. 6. Call read_repo_file for each selected file. 7. Write detailed maintainers' documentation in markdown. 8. Call write_output_file with the completed markdown and output_path. diff --git a/cmd/documentor.go b/cmd/documentor.go index 532785a..e3f4273 100644 --- a/cmd/documentor.go +++ b/cmd/documentor.go @@ -139,6 +139,7 @@ func NewDocumentorCmd() *cobra.Command { } // handle event (log) slog.Info("event", "id", event.ID, "author", event.Author) + slog.Debug("event_content", "role", event.Content.Role, "parts", event.Content.Parts) } if _, err := os.Stat(output); err != nil { From 69dde1edcb692eac937441f35570e524d025e41e Mon Sep 17 00:00:00 2001 From: ATMackay Date: Wed, 18 Mar 2026 12:53:14 +1100 Subject: [PATCH 2/3] add better logging and test model pkg --- .gitignore | 3 ++- README.md | 8 +++++--- cmd/documentor.go | 19 +++++++++++++++---- cmd/run.go | 12 ++++-------- model/claude.go | 2 +- model/model_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 model/model_test.go diff --git a/.gitignore b/.gitignore index 4a8856d..e1b9efc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ agent build/* docs/generated -data \ No newline at end of file +data +*agentcli.md \ No newline at end of file diff --git a/README.md b/README.md index 6e2a186..db6749e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ Build agent CLI make build ``` -Run the agent () +Run the documentation agent ``` -./build/agent-cli run documentor --repo https://github.com/ATMackay/agent.git --output agentcli-doc.md -``` \ No newline at end of file +./build/agent-cli run documentor --repo https://github.com/ATMackay/agent +``` + +Documentation will be written to `doc.agentcli.md`. \ No newline at end of file diff --git a/cmd/documentor.go b/cmd/documentor.go index e3f4273..b7cfb10 100644 --- a/cmd/documentor.go +++ b/cmd/documentor.go @@ -4,6 +4,7 @@ import ( "fmt" "log/slog" "os" + "time" "github.com/ATMackay/agent/agents/documentor" "github.com/ATMackay/agent/model" @@ -133,14 +134,24 @@ func NewDocumentorCmd() *cobra.Command { "session_id", resp.Session.ID(), ) + start := time.Now() for event, err := range r.Run(ctx, userCLI, resp.Session.ID(), userMsg, agentpkg.RunConfig{}) { if err != nil { return fmt.Errorf("agent error: %w", err) } // handle event (log) - slog.Info("event", "id", event.ID, "author", event.Author) - slog.Debug("event_content", "role", event.Content.Role, "parts", event.Content.Parts) + if event.UsageMetadata == nil { + continue + } + slog.Info("event", "author", event.Author, "event_id", event.ID, "prompt_tokens", event.UsageMetadata.PromptTokenCount, "total_tokens", event.UsageMetadata.TotalTokenCount) + if event.Content == nil { + continue + } + for _, p := range event.Content.Parts { + slog.Debug("response_content", "role", event.Content.Role, "text", p.Text, "function_call", p.FunctionCall) + } } + slog.Info("Agent execution complete", "time_taken", time.Since(start)) if _, err := os.Stat(output); err != nil { return fmt.Errorf("agent finished but output file was not created: %w", err) @@ -154,9 +165,9 @@ func NewDocumentorCmd() *cobra.Command { cmd.Flags().StringVar(&repoURL, "repo", "", "GitHub repository URL") cmd.Flags().StringVar(&ref, "ref", "", "Optional branch, tag, or commit") cmd.Flags().StringVar(&pathPrefix, "path", "", "Optional subdirectory to document") - cmd.Flags().StringVar(&output, "output", "", "Output file path for the generated markdown") + cmd.Flags().StringVar(&output, "output", "doc.agentcli.md", "Output file path for the generated markdown") cmd.Flags().IntVar(&maxFiles, "max-files", 50, "Maximum number of files to read") - cmd.Flags().StringVar(&modelName, "model", "", "LLM to use") + cmd.Flags().StringVar(&modelName, "model", "claude-opus-4-1-20250805", "Language model to use") cmd.Flags().StringVar(&modelProvider, "provider", "claude", "LLM provider to use (claude or gemini)") // Bind flags to environment variables diff --git a/cmd/run.go b/cmd/run.go index 4b308ed..070dac5 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -21,10 +21,6 @@ func NewRunCmd() *cobra.Command { if err := initLogging(logLevel, logFormat); err != nil { return fmt.Errorf("failed to initialize logger: %w", err) } - - return nil - }, - RunE: func(cmd *cobra.Command, args []string) error { if isBuildDirty() { slog.Warn("running a DIRTY build (uncommitted changes present) — do not run in production") } @@ -43,12 +39,12 @@ func NewRunCmd() *cobra.Command { // TODO - more agent types // Bind flags and ENV vars - cmd.Flags().String("log-level", "info", "Log level (debug, info, warn, error, fatal, panic)") - cmd.Flags().String("log-format", "text", "Log format (text, json)") + cmd.PersistentFlags().String("log-level", "info", "Log level (debug, info, warn, error, fatal, panic)") + cmd.PersistentFlags().String("log-format", "text", "Log format (text, json)") // Bind flags to environment variables - must(viper.BindPFlag("log-level", cmd.Flags().Lookup("log-level"))) - must(viper.BindPFlag("log-format", cmd.Flags().Lookup("log-format"))) + must(viper.BindPFlag("log-level", cmd.PersistentFlags().Lookup("log-level"))) + must(viper.BindPFlag("log-format", cmd.PersistentFlags().Lookup("log-format"))) // Set environment variable prefix and read from environment viper.SetEnvPrefix(EnvPrefix) // Environment variables will be prefixed with CHECKOUT_ diff --git a/model/claude.go b/model/claude.go index 43c6001..22014d0 100644 --- a/model/claude.go +++ b/model/claude.go @@ -15,7 +15,7 @@ func newClaude(ctx context.Context, cfg *Config) (model.LLM, error) { return nil, fmt.Errorf("anthropic api key is required for claude") } if cfg.Model == "" { - cfg.Model = string(anthropic.ModelClaudeSonnet4_20250514) + cfg.Model = string(anthropic.ModelClaudeOpus4_1_20250805) } return anthropicadk.NewModel(cfg.Model, anthropicadk.AnthropicOption(option.WithAPIKey(cfg.apiKey))), nil } diff --git a/model/model_test.go b/model/model_test.go new file mode 100644 index 0000000..133f870 --- /dev/null +++ b/model/model_test.go @@ -0,0 +1,41 @@ +package model + +import ( + "context" + "testing" +) + +func Test_NewModel(t *testing.T) { + t.Run("unsupported-provider", func(t *testing.T) { + _, err := New(context.Background(), &Config{Provider: "not-supported"}) + if err == nil { + t.Fatal("expected non-nil error") + } + }) + t.Run("empty-config-claude", func(t *testing.T) { + _, err := New(context.Background(), &Config{}) + if err == nil { + t.Fatal("expected non-nil error") + } + }) + t.Run("empty-config-gemini", func(t *testing.T) { + _, err := New(context.Background(), &Config{Provider: ProviderGemini}) + if err == nil { + t.Fatal("expected non-nil error") + } + }) + + t.Run("happy-path-claude", func(t *testing.T) { + cfg := &Config{} + _, err := New(context.Background(), cfg.WithAPIKey("api-key")) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + }) + t.Run("happy-path-gemini", func(t *testing.T) { + _, err := New(context.Background(), &Config{Provider: ProviderGemini, apiKey: "api-key"}) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + }) +} From 0ca155bb59a621d579b1ffef411ff4bf4e0e5af8 Mon Sep 17 00:00:00 2001 From: ATMackay Date: Wed, 18 Mar 2026 12:55:54 +1100 Subject: [PATCH 3/3] cover --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8a23238..53c2d5c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,7 +24,7 @@ jobs: run: go build -v ./... - name: unit-test - run: go test -v ./... + run: go test -v -cover ./... golangci: runs-on: ubuntu-latest