← back to jmgilman__sow

Function bodies 590 total

All specs Real LLM only Function bodies
cmd.extractBranchName function · go · L141-L148 (8 LOC)
cli/cmd/worktree.go
func extractBranchName(worktreePath, repoRoot string) string {
	worktreesDir := filepath.Join(repoRoot, ".sow", "worktrees")
	rel, err := filepath.Rel(worktreesDir, worktreePath)
	if err != nil {
		return "unknown"
	}
	return rel
}
cmd.newWorktreeRemoveCmd function · go · L151-L162 (12 LOC)
cli/cmd/worktree.go
func newWorktreeRemoveCmd() *cobra.Command {
	return &cobra.Command{
		Use:   "remove <path>",
		Short: "Remove a worktree",
		Long: `Remove a worktree at the specified path.

The worktree must be clean (no uncommitted changes) to be removed.
Use 'sow worktree list' to see available worktrees.`,
		Args: cobra.ExactArgs(1),
		RunE: runWorktreeRemove,
	}
}
cmd.runWorktreeRemove function · go · L164-L205 (42 LOC)
cli/cmd/worktree.go
func runWorktreeRemove(cmd *cobra.Command, args []string) error {
	ctx := cmdutil.GetContext(cmd.Context())
	path := args[0]

	// Normalize path to absolute for consistent comparison
	absPath, err := filepath.Abs(path)
	if err != nil {
		return fmt.Errorf("failed to resolve path: %w", err)
	}

	// Validate path exists
	if _, err := os.Stat(absPath); os.IsNotExist(err) {
		return fmt.Errorf("worktree does not exist: %s", absPath)
	}

	// Get all worktrees to find the matching one
	worktrees, err := ctx.Git().Repository().ListWorktrees()
	if err != nil {
		return fmt.Errorf("failed to list worktrees: %w", err)
	}

	// Find the worktree to remove
	var targetWorktree *git.Worktree
	for _, wt := range worktrees {
		if wt.Path() == absPath {
			targetWorktree = wt
			break
		}
	}

	if targetWorktree == nil {
		return fmt.Errorf("path is not a worktree: %s", absPath)
	}

	// Remove using git wrapper (includes safety checks)
	if err := targetWorktree.Remove(); err != nil {
		return fmt.Errorf(
cmd.newWorktreePruneCmd function · go · L208-L218 (11 LOC)
cli/cmd/worktree.go
func newWorktreePruneCmd() *cobra.Command {
	return &cobra.Command{
		Use:   "prune",
		Short: "Remove orphaned worktree metadata",
		Long: `Clean up worktree administrative files that no longer have a corresponding worktree directory.

This is useful after manually deleting worktree directories or after system crashes.
It's safe to run periodically as it only removes metadata for non-existent worktrees.`,
		RunE: runWorktreePrune,
	}
}
cmd.runWorktreePrune function · go · L220-L230 (11 LOC)
cli/cmd/worktree.go
func runWorktreePrune(cmd *cobra.Command, _ []string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Prune using git wrapper
	if err := ctx.Git().Repository().PruneWorktrees(); err != nil {
		return fmt.Errorf("failed to prune worktrees: %w", err)
	}

	fmt.Println("Pruned orphaned worktree metadata")
	return nil
}
agents.StandardAgents function · go · L110-L119 (10 LOC)
cli/internal/agents/agents.go
func StandardAgents() []*Agent {
	return []*Agent{
		Implementer,
		Architect,
		Reviewer,
		Planner,
		Researcher,
		Decomposer,
	}
}
agents.NewClaudeExecutor function · go · L41-L49 (9 LOC)
cli/internal/agents/executor_claude.go
func NewClaudeExecutor(yoloMode bool, model string, outputDir string, customArgs []string) *ClaudeExecutor {
	return &ClaudeExecutor{
		yoloMode:   yoloMode,
		model:      model,
		outputDir:  outputDir,
		customArgs: customArgs,
		runner:     &DefaultCommandRunner{},
	}
}
Want this analysis on your repo? https://repobility.com/scan/
agents.NewClaudeExecutorWithRunner function · go · L60-L68 (9 LOC)
cli/internal/agents/executor_claude.go
func NewClaudeExecutorWithRunner(yoloMode bool, model string, outputDir string, customArgs []string, runner CommandRunner) *ClaudeExecutor {
	return &ClaudeExecutor{
		yoloMode:   yoloMode,
		model:      model,
		outputDir:  outputDir,
		customArgs: customArgs,
		runner:     runner,
	}
}
agents.ClaudeExecutor.outputPath method · go · L78-L83 (6 LOC)
cli/internal/agents/executor_claude.go
func (e *ClaudeExecutor) outputPath(sessionID string) string {
	if e.outputDir == "" || sessionID == "" {
		return ""
	}
	return filepath.Join(e.outputDir, sessionID+".log")
}
agents.ClaudeExecutor.Spawn method · go · L102-L136 (35 LOC)
cli/internal/agents/executor_claude.go
func (e *ClaudeExecutor) Spawn(ctx context.Context, agent *Agent, prompt string, sessionID string) error {
	// Load agent prompt template
	agentPrompt, err := LoadPrompt(agent.PromptPath)
	if err != nil {
		return fmt.Errorf("failed to load agent prompt: %w", err)
	}

	// Combine prompts
	fullPrompt := agentPrompt + "\n\n" + prompt

	// Build args - always use --print for non-interactive mode
	// Use stream-json for real-time output to log files (requires --verbose)
	// Use acceptEdits permission mode to allow file writes without full bypass
	args := []string{"--print", "--verbose", "--output-format", "stream-json", "--permission-mode", "acceptEdits"}
	if e.yoloMode {
		args = append(args, "--dangerously-skip-permissions")
	}
	if e.model != "" {
		args = append(args, "--model", e.model)
	}
	if sessionID != "" {
		args = append(args, "--session-id", sessionID)
	}

	// Append custom arguments from user config
	if len(e.customArgs) > 0 {
		args = append(args, e.customArgs...)
	}

	// Exec
agents.ClaudeExecutor.Resume method · go · L153-L172 (20 LOC)
cli/internal/agents/executor_claude.go
func (e *ClaudeExecutor) Resume(ctx context.Context, sessionID string, prompt string) error {
	// Build args - always use --print for non-interactive mode
	// Use stream-json for real-time output to log files (requires --verbose)
	// Use acceptEdits permission mode to allow file writes without full bypass
	args := []string{"--print", "--verbose", "--output-format", "stream-json", "--permission-mode", "acceptEdits", "--resume", sessionID}
	if e.yoloMode {
		args = append(args, "--dangerously-skip-permissions")
	}

	// Append custom arguments from user config
	if len(e.customArgs) > 0 {
		args = append(args, e.customArgs...)
	}

	// Execute with output capture (appends to same session log)
	if err := e.runner.Run(ctx, "claude", args, strings.NewReader(prompt), e.outputPath(sessionID)); err != nil {
		return fmt.Errorf("claude resume failed: %w", err)
	}
	return nil
}
agents.ClaudeExecutor.ValidateAvailability method · go · L182-L188 (7 LOC)
cli/internal/agents/executor_claude.go
func (e *ClaudeExecutor) ValidateAvailability() error {
	_, err := exec.LookPath("claude")
	if err != nil {
		return fmt.Errorf("claude CLI not found on PATH: %w\n\nInstall: npm install -g @anthropic-ai/claude-code", err)
	}
	return nil
}
agents.NewCursorExecutor function · go · L39-L46 (8 LOC)
cli/internal/agents/executor_cursor.go
func NewCursorExecutor(yoloMode bool, outputDir string, customArgs []string) *CursorExecutor {
	return &CursorExecutor{
		yoloMode:   yoloMode,
		outputDir:  outputDir,
		customArgs: customArgs,
		runner:     &DefaultCommandRunner{},
	}
}
agents.NewCursorExecutorWithRunner function · go · L56-L63 (8 LOC)
cli/internal/agents/executor_cursor.go
func NewCursorExecutorWithRunner(yoloMode bool, outputDir string, customArgs []string, runner CommandRunner) *CursorExecutor {
	return &CursorExecutor{
		yoloMode:   yoloMode,
		outputDir:  outputDir,
		customArgs: customArgs,
		runner:     runner,
	}
}
agents.CursorExecutor.outputPath method · go · L73-L78 (6 LOC)
cli/internal/agents/executor_cursor.go
func (e *CursorExecutor) outputPath(sessionID string) string {
	if e.outputDir == "" || sessionID == "" {
		return ""
	}
	return filepath.Join(e.outputDir, sessionID+".log")
}
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
agents.CursorExecutor.Spawn method · go · L91-L124 (34 LOC)
cli/internal/agents/executor_cursor.go
func (e *CursorExecutor) Spawn(ctx context.Context, agent *Agent, prompt string, sessionID string) error {
	// Load agent prompt template
	agentPrompt, err := LoadPrompt(agent.PromptPath)
	if err != nil {
		return fmt.Errorf("failed to load agent prompt: %w", err)
	}

	// Combine prompts
	fullPrompt := agentPrompt + "\n\n" + prompt

	// Build args - cursor-agent uses subcommand "agent"
	// Use stream-json for real-time output to log files
	args := []string{"agent", "--print", "--output-format", "stream-json"}

	// Add --force when yoloMode enabled (Cursor's equivalent of skip-permissions)
	if e.yoloMode {
		args = append(args, "--force")
	}

	if sessionID != "" {
		args = append(args, "--chat-id", sessionID)
	}

	// Append custom arguments from user config
	if len(e.customArgs) > 0 {
		args = append(args, e.customArgs...)
	}

	// Execute with output capture
	if err = e.runner.Run(ctx, "cursor-agent", args, strings.NewReader(fullPrompt), e.outputPath(sessionID)); err != nil {
		return f
agents.CursorExecutor.Resume method · go · L134-L153 (20 LOC)
cli/internal/agents/executor_cursor.go
func (e *CursorExecutor) Resume(ctx context.Context, sessionID string, prompt string) error {
	// Use stream-json for real-time output to log files
	args := []string{"agent", "--print", "--output-format", "stream-json", "--resume", sessionID}

	// Add --force when yoloMode enabled (Cursor's equivalent of skip-permissions)
	if e.yoloMode {
		args = append(args, "--force")
	}

	// Append custom arguments from user config
	if len(e.customArgs) > 0 {
		args = append(args, e.customArgs...)
	}

	// Execute with output capture (appends to same session log)
	if err := e.runner.Run(ctx, "cursor-agent", args, strings.NewReader(prompt), e.outputPath(sessionID)); err != nil {
		return fmt.Errorf("cursor-agent resume failed: %w", err)
	}
	return nil
}
agents.DefaultCommandRunner.Run method · go · L96-L156 (61 LOC)
cli/internal/agents/executor.go
func (r *DefaultCommandRunner) Run(ctx context.Context, name string, args []string, stdin io.Reader, outputPath string) error {
	cmd := exec.CommandContext(ctx, name, args...)
	cmd.Stdin = stdin

	// Always capture stderr for error messages
	var stderrBuf bytes.Buffer

	// Track dualWriter for flushing after command completes
	var dualWriter *logformat.DualWriter

	if outputPath != "" {
		// Ensure output directory exists
		outputDir := filepath.Dir(outputPath)
		if err := os.MkdirAll(outputDir, 0755); err != nil {
			return fmt.Errorf("failed to create output directory: %w", err)
		}

		// Determine file paths for raw JSON and formatted output
		rawPath, formattedPath := splitOutputPaths(outputPath)

		// Open raw JSON file for appending
		rawFile, err := os.OpenFile(rawPath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
		if err != nil {
			return fmt.Errorf("failed to open raw output file: %w", err)
		}
		defer func() { _ = rawFile.Close() }()

		// Open formatted output file for appen
agents.splitOutputPaths function · go · L161-L175 (15 LOC)
cli/internal/agents/executor.go
func splitOutputPaths(outputPath string) (rawPath, formattedPath string) {
	ext := filepath.Ext(outputPath)
	base := strings.TrimSuffix(outputPath, ext)

	if ext == ".log" {
		// Replace .log with .json for raw output
		rawPath = base + ".json"
		formattedPath = outputPath
	} else {
		// Add extensions to the base path
		rawPath = outputPath + ".json"
		formattedPath = outputPath + ".log"
	}
	return
}
agents.MockExecutor.Name method · go · L37-L42 (6 LOC)
cli/internal/agents/executor_mock.go
func (m *MockExecutor) Name() string {
	if m.NameFunc != nil {
		return m.NameFunc()
	}
	return ""
}
agents.MockExecutor.Spawn method · go · L45-L50 (6 LOC)
cli/internal/agents/executor_mock.go
func (m *MockExecutor) Spawn(ctx context.Context, agent *Agent, prompt string, sessionID string) error {
	if m.SpawnFunc != nil {
		return m.SpawnFunc(ctx, agent, prompt, sessionID)
	}
	return nil
}
agents.MockExecutor.Resume method · go · L53-L58 (6 LOC)
cli/internal/agents/executor_mock.go
func (m *MockExecutor) Resume(ctx context.Context, sessionID string, prompt string) error {
	if m.ResumeFunc != nil {
		return m.ResumeFunc(ctx, sessionID, prompt)
	}
	return nil
}
agents.MockExecutor.SupportsResumption method · go · L61-L66 (6 LOC)
cli/internal/agents/executor_mock.go
func (m *MockExecutor) SupportsResumption() bool {
	if m.SupportsResumptionFunc != nil {
		return m.SupportsResumptionFunc()
	}
	return false
}
About: code-quality intelligence by Repobility · https://repobility.com
agents.MockExecutor.ValidateAvailability method · go · L69-L74 (6 LOC)
cli/internal/agents/executor_mock.go
func (m *MockExecutor) ValidateAvailability() error {
	if m.ValidateAvailabilityFunc != nil {
		return m.ValidateAvailabilityFunc()
	}
	return nil
}
agents.MockCommandRunner.Run method · go · L116-L132 (17 LOC)
cli/internal/agents/executor_mock.go
func (m *MockCommandRunner) Run(ctx context.Context, name string, args []string, stdin io.Reader, outputPath string) error {
	// Capture call parameters.
	m.LastName = name
	m.LastArgs = args
	m.LastOutputPath = outputPath
	if stdin != nil {
		data, _ := io.ReadAll(stdin)
		m.LastStdin = string(data)
	} else {
		m.LastStdin = ""
	}

	if m.RunFunc != nil {
		return m.RunFunc(ctx, name, args, stdin, outputPath)
	}
	return nil
}
agents.ExecutorRegistry.Register method · go · L50-L57 (8 LOC)
cli/internal/agents/executor_registry.go
func (r *ExecutorRegistry) Register(executor Executor) {
	name := executor.Name()
	if _, exists := r.executors[name]; exists {
		panic(fmt.Sprintf("executor already registered: %s", name))
	}

	r.executors[name] = executor
}
agents.ExecutorRegistry.Get method · go · L68-L75 (8 LOC)
cli/internal/agents/executor_registry.go
func (r *ExecutorRegistry) Get(name string) (Executor, error) {
	executor, ok := r.executors[name]
	if !ok {
		return nil, fmt.Errorf("unknown executor: %s", name)
	}

	return executor, nil
}
agents.ExecutorRegistry.List method · go · L84-L91 (8 LOC)
cli/internal/agents/executor_registry.go
func (r *ExecutorRegistry) List() []string {
	names := make([]string, 0, len(r.executors))
	for name := range r.executors {
		names = append(names, name)
	}

	return names
}
agents.ExecutorRegistry.RegisterNamed method · go · L102-L108 (7 LOC)
cli/internal/agents/executor_registry.go
func (r *ExecutorRegistry) RegisterNamed(name string, executor Executor) {
	if _, exists := r.executors[name]; exists {
		panic(fmt.Sprintf("executor already registered: %s", name))
	}

	r.executors[name] = executor
}
agents.LoadExecutorRegistry function · go · L131-L171 (41 LOC)
cli/internal/agents/executor_registry.go
func LoadExecutorRegistry(userConfig *schemas.UserConfig, outputDir string) (*ExecutorRegistry, error) {
	registry := NewExecutorRegistry()

	// If no config or no executors defined, create default
	if userConfig == nil || userConfig.Agents == nil || len(userConfig.Agents.Executors) == 0 {
		// Register default claude-code executor
		registry.RegisterNamed(DefaultExecutorName, NewClaudeExecutor(false, "", outputDir, nil))
		return registry, nil
	}

	// Create executors from config
	for name, execConfig := range userConfig.Agents.Executors {
		var yoloMode bool
		var model string
		var customArgs []string

		if execConfig.Settings != nil {
			if execConfig.Settings.Yolo_mode != nil {
				yoloMode = *execConfig.Settings.Yolo_mode
			}
			if execConfig.Settings.Model != nil {
				model = *execConfig.Settings.Model
			}
		}
		customArgs = execConfig.Custom_args

		var executor Executor
		switch execConfig.Type {
		case "claude":
			executor = NewClaudeExecutor(yoloMode, model, outputDir, c
agents.ExecutorRegistry.GetAgentExecutor method · go · L181-L192 (12 LOC)
cli/internal/agents/executor_registry.go
func (r *ExecutorRegistry) GetAgentExecutor(agentName string, bindings *struct {
	Orchestrator *string `json:"orchestrator,omitempty"`
	Implementer  *string `json:"implementer,omitempty"`
	Architect    *string `json:"architect,omitempty"`
	Reviewer     *string `json:"reviewer,omitempty"`
	Planner      *string `json:"planner,omitempty"`
	Researcher   *string `json:"researcher,omitempty"`
	Decomposer   *string `json:"decomposer,omitempty"`
}) (Executor, error) {
	executorName := resolveExecutorName(agentName, bindings)
	return r.Get(executorName)
}
Methodology: Repobility · https://repobility.com/research/state-of-ai-code-2026/
agents.resolveExecutorName function · go · L195-L230 (36 LOC)
cli/internal/agents/executor_registry.go
func resolveExecutorName(agentName string, bindings *struct {
	Orchestrator *string `json:"orchestrator,omitempty"`
	Implementer  *string `json:"implementer,omitempty"`
	Architect    *string `json:"architect,omitempty"`
	Reviewer     *string `json:"reviewer,omitempty"`
	Planner      *string `json:"planner,omitempty"`
	Researcher   *string `json:"researcher,omitempty"`
	Decomposer   *string `json:"decomposer,omitempty"`
}) string {
	if bindings == nil {
		return DefaultExecutorName
	}

	var bound *string
	switch agentName {
	case "orchestrator":
		bound = bindings.Orchestrator
	case "implementer":
		bound = bindings.Implementer
	case "architect":
		bound = bindings.Architect
	case "reviewer":
		bound = bindings.Reviewer
	case "planner":
		bound = bindings.Planner
	case "researcher":
		bound = bindings.Researcher
	case "decomposer":
		bound = bindings.Decomposer
	}

	if bound != nil {
		return *bound
	}
	return DefaultExecutorName
}
logformat.NewFormatter function · go · L31-L36 (6 LOC)
cli/internal/agents/logformat/formatter.go
func NewFormatter() *Formatter {
	return &Formatter{
		MaxContentLen:  MaxContentLength,
		MaxThinkingLen: MaxThinkingLength,
	}
}
logformat.Formatter.Format method · go · L40-L56 (17 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) Format(event *Event) string {
	switch event.Type {
	case EventTypeSystem:
		if event.Subtype == "init" {
			return f.formatInit(event)
		}
		return ""
	case EventTypeAssistant:
		return f.formatAssistant(event)
	case EventTypeUser:
		return f.formatToolResult(event)
	case EventTypeResult:
		return f.formatResult(event)
	default:
		return ""
	}
}
logformat.Formatter.formatInit method · go · L59-L79 (21 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) formatInit(event *Event) string {
	var b strings.Builder

	b.WriteString(doubleLine())
	b.WriteString("SESSION STARTED\n")
	b.WriteString(doubleLine())
	b.WriteString(fmt.Sprintf("  Session ID: %s\n", event.SessionID))
	b.WriteString(fmt.Sprintf("  Model: %s\n", event.Model))
	if event.CWD != "" {
		b.WriteString(fmt.Sprintf("  Working Dir: %s\n", event.CWD))
	}
	if event.ClaudeCodeVersion != "" {
		b.WriteString(fmt.Sprintf("  Claude Code: v%s\n", event.ClaudeCodeVersion))
	}
	if event.PermissionMode != "" && event.PermissionMode != "default" {
		b.WriteString(fmt.Sprintf("  Permission Mode: %s\n", event.PermissionMode))
	}
	b.WriteString("\n")

	return b.String()
}
logformat.Formatter.formatAssistant method · go · L82-L110 (29 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) formatAssistant(event *Event) string {
	if event.Message == nil {
		return ""
	}

	blocks, err := event.Message.ParseContentBlocks()
	if err != nil || len(blocks) == 0 {
		return ""
	}

	var b strings.Builder

	for _, block := range blocks {
		switch block.Type {
		case "text":
			if text := strings.TrimSpace(block.Text); text != "" {
				b.WriteString(singleLine())
				b.WriteString("THINKING\n")
				b.WriteString(singleLine())
				b.WriteString(f.indent(f.truncate(text, f.maxThinking()), "  "))
				b.WriteString("\n\n")
			}
		case "tool_use":
			b.WriteString(f.formatToolCall(&block))
		}
	}

	return b.String()
}
logformat.Formatter.formatToolCall method · go · L113-L127 (15 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) formatToolCall(block *ContentBlock) string {
	var b strings.Builder

	b.WriteString(singleLine())
	b.WriteString(fmt.Sprintf("TOOL: %s\n", block.Name))
	b.WriteString(singleLine())

	input, _ := block.ParseToolInput()
	if input != nil {
		f.writeToolInput(&b, block.Name, input, block.Input)
	}
	b.WriteString("\n")

	return b.String()
}
logformat.Formatter.writeToolInput method · go · L130-L147 (18 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) writeToolInput(b *strings.Builder, toolName string, input *ToolInput, rawInput []byte) {
	switch toolName {
	case "Bash":
		f.writeBashInput(b, input)
	case "Read":
		fmt.Fprintf(b, "  File: %s\n", input.FilePath)
	case "Write":
		f.writeWriteInput(b, input)
	case "Edit":
		f.writeEditInput(b, input)
	case "Glob", "Grep":
		f.writeSearchInput(b, input)
	case "TodoWrite":
		f.writeTodoInput(b, input)
	default:
		fmt.Fprintf(b, "  Input: %s\n", f.truncateLine(string(rawInput), 200))
	}
}
logformat.Formatter.writeBashInput method · go · L149-L156 (8 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) writeBashInput(b *strings.Builder, input *ToolInput) {
	if input.Description != "" {
		fmt.Fprintf(b, "  Description: %s\n", input.Description)
	}
	if input.Command != "" {
		fmt.Fprintf(b, "  Command: %s\n", f.truncateLine(input.Command, 200))
	}
}
Want this analysis on your repo? https://repobility.com/scan/
logformat.Formatter.writeWriteInput method · go · L158-L164 (7 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) writeWriteInput(b *strings.Builder, input *ToolInput) {
	fmt.Fprintf(b, "  File: %s\n", input.FilePath)
	if input.Content != "" {
		lines := strings.Count(input.Content, "\n") + 1
		fmt.Fprintf(b, "  Content: %d lines\n", lines)
	}
}
logformat.Formatter.writeEditInput method · go · L166-L171 (6 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) writeEditInput(b *strings.Builder, input *ToolInput) {
	fmt.Fprintf(b, "  File: %s\n", input.FilePath)
	if input.OldString != "" {
		fmt.Fprintf(b, "  Replacing: %s\n", f.truncateLine(input.OldString, 100))
	}
}
logformat.Formatter.writeSearchInput method · go · L173-L178 (6 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) writeSearchInput(b *strings.Builder, input *ToolInput) {
	fmt.Fprintf(b, "  Pattern: %s\n", input.Pattern)
	if input.Path != "" {
		fmt.Fprintf(b, "  Path: %s\n", input.Path)
	}
}
logformat.Formatter.writeTodoInput method · go · L180-L189 (10 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) writeTodoInput(b *strings.Builder, input *ToolInput) {
	if len(input.Todos) == 0 {
		return
	}
	b.WriteString("  Todos:\n")
	for _, todo := range input.Todos {
		status := statusIcon(todo.Status)
		fmt.Fprintf(b, "    %s %s\n", status, todo.Content)
	}
}
logformat.Formatter.formatToolResult method · go · L192-L242 (51 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) formatToolResult(event *Event) string {
	if event.Message == nil {
		return ""
	}

	blocks, err := event.Message.ParseContentBlocks()
	if err != nil || len(blocks) == 0 {
		return ""
	}

	var b strings.Builder

	for _, block := range blocks {
		if block.Type != "tool_result" {
			continue
		}

		status := "OK"
		if block.IsError {
			status = "ERROR"
		}

		b.WriteString(singleLine())
		b.WriteString(fmt.Sprintf("RESULT [%s]\n", status))
		b.WriteString(singleLine())

		// Prefer tool_use_result if available (has structured stdout/stderr)
		if event.ToolUseResult != nil {
			if event.ToolUseResult.Stderr != "" {
				b.WriteString("  STDERR:\n")
				b.WriteString(f.indent(f.truncate(event.ToolUseResult.Stderr, f.maxContent()), "    "))
				b.WriteString("\n")
			}
			if event.ToolUseResult.Stdout != "" {
				output := f.truncate(event.ToolUseResult.Stdout, f.maxContent())
				b.WriteString(f.indent(output, "  "))
				b.WriteString("\n")
			}
			if event.ToolUseResult
logformat.Formatter.formatResult method · go · L245-L279 (35 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) formatResult(event *Event) string {
	var b strings.Builder

	b.WriteString(doubleLine())
	if event.IsError {
		b.WriteString("SESSION FAILED\n")
	} else {
		b.WriteString("SESSION COMPLETE\n")
	}
	b.WriteString(doubleLine())

	// Duration
	duration := formatDuration(event.DurationMS)
	apiDuration := formatDuration(event.DurationAPIMS)
	b.WriteString(fmt.Sprintf("  Duration: %s (API: %s)\n", duration, apiDuration))

	// Turns
	b.WriteString(fmt.Sprintf("  Turns: %d\n", event.NumTurns))

	// Cost
	if event.TotalCostUSD > 0 {
		b.WriteString(fmt.Sprintf("  Cost: $%.2f\n", event.TotalCostUSD))
	}

	b.WriteString("\n")

	// Final result
	if event.Result != "" {
		b.WriteString("  FINAL RESULT:\n")
		b.WriteString(f.indent(event.Result, "  "))
		b.WriteString("\n")
	}

	return b.String()
}
logformat.Formatter.maxContent method · go · L283-L288 (6 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) maxContent() int {
	if f.MaxContentLen > 0 {
		return f.MaxContentLen
	}
	return MaxContentLength
}
logformat.Formatter.maxThinking method · go · L290-L295 (6 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) maxThinking() int {
	if f.MaxThinkingLen > 0 {
		return f.MaxThinkingLen
	}
	return MaxThinkingLength
}
Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
logformat.Formatter.truncate method · go · L297-L302 (6 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) truncate(s string, maxLen int) string {
	if len(s) <= maxLen {
		return s
	}
	return s[:maxLen] + fmt.Sprintf("\n  ... [truncated, %d total chars]", len(s))
}
logformat.Formatter.truncateLine method · go · L304-L312 (9 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) truncateLine(s string, maxLen int) string {
	// Replace newlines with spaces for single-line display
	s = strings.ReplaceAll(s, "\n", " ")
	s = strings.ReplaceAll(s, "\r", "")
	if len(s) <= maxLen {
		return s
	}
	return s[:maxLen] + "..."
}
logformat.Formatter.indent method · go · L314-L322 (9 LOC)
cli/internal/agents/logformat/formatter.go
func (f *Formatter) indent(s string, prefix string) string {
	lines := strings.Split(s, "\n")
	for i, line := range lines {
		if line != "" {
			lines[i] = prefix + line
		}
	}
	return strings.Join(lines, "\n")
}
‹ prevpage 5 / 12next ›