← back to jmgilman__sow

Function bodies 590 total

All specs Real LLM only Function bodies
refs.runRefsInit function · go · L28-L44 (17 LOC)
cli/cmd/refs/init.go
func runRefsInit(cmd *cobra.Command) error {
	ctx := cmd.Context()

	// Get context
	sowCtx := cmdutil.GetContext(ctx)

	// Create refs manager
	mgr := refs.NewManager(sowCtx)

	// Initialize all refs
	if err := mgr.InitRefs(ctx); err != nil {
		return err
	}

	cmd.Println("✓ Refs initialized successfully")
	return nil
}
refs.newListCmd function · go · L12-L51 (40 LOC)
cli/cmd/refs/list.go
func newListCmd() *cobra.Command {
	var (
		typeFilter     string
		semanticFilter string
		tagsFilter     []string
		showLocal      bool
		showCommitted  bool
		format         string
	)

	cmd := &cobra.Command{
		Use:   "list",
		Short: "List configured references",
		Long: `List all configured references across all types.

Supports filtering by:
  --type      Structural type (git, file)
  --semantic  Semantic type (knowledge, code)
  --tags      Topic tags (comma-separated)
  --local     Show only local refs
  --committed Show only committed refs (default: show both)

Output formats:
  table  Table format (default)
  json   JSON output
  yaml   YAML output`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runRefsList(cmd, typeFilter, semanticFilter, tagsFilter, showLocal, showCommitted, format)
		},
	}

	cmd.Flags().StringVar(&typeFilter, "type", "", "Filter by structural type (git, file)")
	cmd.Flags().StringVar(&semanticFilter, "semantic", "", "Filter by semantic typ
refs.runRefsList function · go · L53-L137 (85 LOC)
cli/cmd/refs/list.go
func runRefsList(
	cmd *cobra.Command,
	typeFilter string,
	semanticFilter string,
	tagsFilter []string,
	showLocal bool,
	showCommitted bool,
	format string,
) error {
	ctx := cmd.Context()

	// Get context
	sowCtx := cmdutil.GetContext(ctx)

	// Create refs manager
	mgr := refs.NewManager(sowCtx)

	// Build filter options
	var opts []refs.RefListOption

	if typeFilter != "" {
		opts = append(opts, refs.WithRefTypeFilter(typeFilter))
	}
	if semanticFilter != "" {
		opts = append(opts, refs.WithRefSemanticFilter(semanticFilter))
	}
	if len(tagsFilter) > 0 {
		opts = append(opts, refs.WithRefTagsFilter(tagsFilter...))
	}

	// Handle local/committed filters
	if showLocal && !showCommitted {
		opts = append(opts, refs.WithRefLocalOnly())
	} else if showCommitted && !showLocal {
		opts = append(opts, refs.WithRefCommittedOnly())
	}
	// If both true or both false, show both (default behavior)

	// List refs
	refsList, err := mgr.List(opts...)
	if err != nil {
		return fmt.Errorf("failed to 
refs.NewRefsCmd function · go · L16-L50 (35 LOC)
cli/cmd/refs/refs.go
func NewRefsCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "refs",
		Short: "Manage external knowledge and code references",
		Long: `Manage external references to knowledge and code repositories.

Refs provide access to external documentation, style guides, and code
examples. They are cached locally and symlinked into .sow/refs/ for
easy access by AI agents.

The type of reference is automatically inferred from the URL scheme:
  git+https://github.com/org/repo → git type
  git+ssh://[email protected]/org/repo → git type
  [email protected]:org/repo           → git type (SSH shorthand)
  file:///absolute/path             → file type

Commands:
  add     - Add a new reference
  update  - Update existing references
  remove  - Remove a reference
  list    - List configured references
  status  - Check reference staleness
  init    - Initialize refs after cloning`,
	}

	// Unified subcommands
	cmd.AddCommand(newAddCmd())
	cmd.AddCommand(newUpdateCmd())
	cmd.AddCommand(newRemoveCmd())
	
refs.printRefsJSON function · go · L102-L109 (8 LOC)
cli/cmd/refs/refs.go
func printRefsJSON(cmd *cobra.Command, refsList []refWithSource) error {
	data, err := json.MarshalIndent(refsList, "", "  ")
	if err != nil {
		return fmt.Errorf("failed to marshal JSON: %w", err)
	}
	cmd.Println(string(data))
	return nil
}
refs.printRefsYAML function · go · L112-L119 (8 LOC)
cli/cmd/refs/refs.go
func printRefsYAML(cmd *cobra.Command, refsList []refWithSource) error {
	data, err := yaml.Marshal(refsList)
	if err != nil {
		return fmt.Errorf("failed to marshal YAML: %w", err)
	}
	cmd.Print(string(data))
	return nil
}
refs.newRemoveCmd function · go · L12-L35 (24 LOC)
cli/cmd/refs/remove.go
func newRemoveCmd() *cobra.Command {
	var (
		force      bool
		pruneCache bool
	)

	cmd := &cobra.Command{
		Use:   "remove <id>",
		Short: "Remove a reference",
		Long: `Remove a reference from the repository.

Removes the workspace symlink and the index entry. Optionally prunes
the cache if no other repositories use it (--prune-cache flag).`,
		Args: cobra.ExactArgs(1),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runRefsRemove(cmd, args[0], force, pruneCache)
		},
	}

	cmd.Flags().BoolVar(&force, "force", false, "Skip confirmation prompt")
	cmd.Flags().BoolVar(&pruneCache, "prune-cache", false, "Remove from cache if no other repos use it")

	return cmd
}
Powered by Repobility — scan your code at https://repobility.com
refs.newStatusCmd function · go · L11-L29 (19 LOC)
cli/cmd/refs/status.go
func newStatusCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "status [id]",
		Short: "Check reference staleness",
		Long: `Check if references are up to date with their sources.

If ID specified, checks that specific ref.
If no ID specified, checks all refs that support staleness checking (e.g., git refs).`,
		RunE: func(cmd *cobra.Command, args []string) error {
			refID := ""
			if len(args) > 0 {
				refID = args[0]
			}
			return runRefsStatus(cmd, refID)
		},
	}

	return cmd
}
refs.runRefsStatus function · go · L31-L114 (84 LOC)
cli/cmd/refs/status.go
func runRefsStatus(cmd *cobra.Command, refID string) error {
	ctx := cmd.Context()

	// Get context
	sowCtx := cmdutil.GetContext(ctx)

	// Create refs manager
	mgr := refs.NewManager(sowCtx)

	// Check specific ref or all refs
	if refID != "" {
		// Get specific ref
		ref, err := mgr.Get(refID)
		if err != nil {
			return fmt.Errorf("ref not found: %w", err)
		}

		// Check status
		isStale, err := ref.Status(ctx)
		if err != nil {
			return fmt.Errorf("failed to check status: %w", err)
		}

		if isStale {
			cmd.Printf("⚠ %s is STALE (updates available)\n", refID)
			cmd.Println("\nRun 'sow refs update " + refID + "' to update")
		} else {
			cmd.Printf("✓ %s is current\n", refID)
		}

		return nil
	}

	// Check all refs
	refsList, err := mgr.List()
	if err != nil {
		return fmt.Errorf("failed to list refs: %w", err)
	}

	if len(refsList) == 0 {
		cmd.Println("No refs to check")
		return nil
	}

	current := 0
	stale := 0
	skipped := 0

	for _, ref := range refsList {
		id := ref.ID()
refs.newUpdateCmd function · go · L11-L29 (19 LOC)
cli/cmd/refs/update.go
func newUpdateCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "update [id]",
		Short: "Update reference(s)",
		Long: `Update references by pulling latest changes.

If ID specified, updates that specific ref.
If no ID specified, updates all refs that support updates (e.g., git refs).`,
		RunE: func(cmd *cobra.Command, args []string) error {
			refID := ""
			if len(args) > 0 {
				refID = args[0]
			}
			return runRefsUpdate(cmd, refID)
		},
	}

	return cmd
}
refs.runRefsUpdate function · go · L31-L93 (63 LOC)
cli/cmd/refs/update.go
func runRefsUpdate(cmd *cobra.Command, refID string) error {
	ctx := cmd.Context()

	// Get context
	sowCtx := cmdutil.GetContext(ctx)

	// Create refs manager
	mgr := refs.NewManager(sowCtx)

	// Update specific ref or all refs
	if refID != "" {
		// Get specific ref
		ref, err := mgr.Get(refID)
		if err != nil {
			return fmt.Errorf("ref not found: %w", err)
		}

		// Update the ref
		if err := ref.Update(ctx); err != nil {
			return fmt.Errorf("failed to update ref: %w", err)
		}

		cmd.Printf("✓ Updated %s\n", refID)
		return nil
	}

	// Update all refs
	refsList, err := mgr.List()
	if err != nil {
		return fmt.Errorf("failed to list refs: %w", err)
	}

	if len(refsList) == 0 {
		cmd.Println("No refs to update")
		return nil
	}

	updated := 0
	skipped := 0

	for _, ref := range refsList {
		id := ref.ID()

		// Attempt update
		if err := ref.Update(ctx); err != nil {
			cmd.Printf("⚠ Skipped %s: %v\n", id, err)
			skipped++
			continue
		}

		cmd.Printf("✓ Updated %s\n", id)
		upda
cmd.NewRootCmd function · go · L31-L92 (62 LOC)
cli/cmd/root.go
func NewRootCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "sow",
		Short: "AI-powered system of work",
		Long: `sow - Structured software development with AI agents

sow is a CLI tool and framework for managing AI-assisted software projects.
It provides structure, state management, and context compilation for
orchestrating multiple AI agents across a 5-phase development workflow.`,
		Version:       Version,
		SilenceUsage:  true,
		SilenceErrors: true,
		PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
			// Get current working directory
			cwd, err := os.Getwd()
			if err != nil {
				return fmt.Errorf("failed to get current directory: %w", err)
			}

			// Find repository root (walk up to find .git)
			repoRoot := findRepoRoot(cwd)
			if repoRoot == "" {
				repoRoot = cwd // Fallback to cwd if not in a git repo
			}

			// Create sow context
			// If .sow doesn't exist, context.FS() will be nil
			// Commands can check context.IsInitialized() if they need .s
cmd.Execute function · go · L95-L101 (7 LOC)
cli/cmd/root.go
func Execute() {
	rootCmd := NewRootCmd()
	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
		os.Exit(1)
	}
}
cmd.findRepoRoot function · go · L105-L140 (36 LOC)
cli/cmd/root.go
func findRepoRoot(start string) string {
	dir := start
	for {
		// Check if .git exists in this directory
		gitPath := dir + string(os.PathSeparator) + ".git"
		if _, err := os.Stat(gitPath); err == nil {
			return dir
		}

		// Move up one directory
		parent := dir + string(os.PathSeparator) + ".."
		absParent, err := os.Stat(parent)
		if err != nil {
			return "" // Can't stat parent, give up
		}

		// Get absolute path of parent
		absPath, err := filepath.Abs(parent)
		if err != nil {
			return ""
		}

		// Check if we've reached the root
		if absPath == dir {
			return "" // Reached filesystem root without finding .git
		}

		// Check if parent is the same as current (another way to detect root)
		currentStat, _ := os.Stat(dir)
		if os.SameFile(currentStat, absParent) {
			return ""
		}

		dir = absPath
	}
}
cmd.NewTaskCmd function · go · L19-L37 (19 LOC)
cli/cmd/task.go
func NewTaskCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "task",
		Short: "Manage project tasks",
		Long: `Manage project tasks.

Task commands allow you to create, modify, and list tasks within project phases.
Tasks are the atomic units of work, each with inputs, outputs, and status tracking.`,
	}

	cmd.AddCommand(newTaskAddCmd())
	cmd.AddCommand(newTaskSetCmd())
	cmd.AddCommand(newTaskAbandonCmd())
	cmd.AddCommand(newTaskStatusCmd())
	cmd.AddCommand(newTaskInputCmd())
	cmd.AddCommand(newTaskOutputCmd())

	return cmd
}
Methodology: Repobility · https://repobility.com/research/state-of-ai-code-2026/
cmd.newTaskAddCmd function · go · L40-L83 (44 LOC)
cli/cmd/task.go
func newTaskAddCmd() *cobra.Command {
	var agent, description, taskID, phase string

	cmd := &cobra.Command{
		Use:   "add <name>",
		Short: "Add a new task",
		Long: `Add a new task to the specified phase.

Creates a new task with a gap-numbered ID (010, 020, 030...) and initializes
the task directory structure:
  - description.md (from --description or placeholder)
  - log.md (empty template)
  - feedback/ (empty directory)

The task ID is auto-generated by default, but can be specified with --id.

Phase Support:
  Not all phases support tasks. Use --phase to specify which phase, or let
  the command choose a smart default based on current project state.

Examples:
  # Add task with agent and description (auto-generated ID, default phase)
  sow task add "Implement JWT signing" --agent implementer --description "Create RS256 signing"

  # Add task to specific phase
  sow task add "Implement JWT signing" --agent implementer --phase implementation

  # Add task with specific ID
  sow ta
cmd.newTaskSetCmd function · go · L86-L121 (36 LOC)
cli/cmd/task.go
func newTaskSetCmd() *cobra.Command {
	var taskID, phase string

	cmd := &cobra.Command{
		Use:   "set <field-path> <value>",
		Short: "Set task field value",
		Long: `Set a task field value using dot notation.

Supports:
  - Direct fields: status, iteration, assigned_agent, name
  - Metadata fields: metadata.* (any custom field)

Examples:
  # Set status
  sow task set --id 010 status completed

  # Set iteration
  sow task set --id 010 iteration 2

  # Set metadata field
  sow task set --id 010 metadata.complexity high

  # Set field in specific phase
  sow task set --id 010 --phase implementation status in_progress`,
		Args: cobra.ExactArgs(2),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runTaskSet(cmd, args, taskID, phase)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (defaults to current phase)")
	_ = cmd.MarkFlagRequired("id")

	return cmd
}
cmd.newTaskAbandonCmd function · go · L124-L150 (27 LOC)
cli/cmd/task.go
func newTaskAbandonCmd() *cobra.Command {
	var taskID, phase string

	cmd := &cobra.Command{
		Use:   "abandon",
		Short: "Abandon a task",
		Long: `Mark a task as abandoned.

Sets the task status to "abandoned" and sets the completed_at timestamp.

Examples:
  # Abandon task (default phase)
  sow task abandon --id 010

  # Abandon task in specific phase
  sow task abandon --id 010 --phase implementation`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskAbandon(cmd, taskID, phase)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (defaults to current phase)")
	_ = cmd.MarkFlagRequired("id")

	return cmd
}
cmd.newTaskStatusCmd function · go · L153-L185 (33 LOC)
cli/cmd/task.go
func newTaskStatusCmd() *cobra.Command {
	var taskID, phase string

	cmd := &cobra.Command{
		Use:   "status",
		Short: "Show task status",
		Long: `Show task status - either overview of all tasks or detailed info about a specific task.

Without --id flag: Shows overview of all tasks in the specified phase (or default phase)
With --id flag: Shows detailed information about a specific task including inputs, outputs, and metadata

Examples:
  # Show overview of all tasks (default phase)
  sow task status

  # Show overview of tasks in specific phase
  sow task status --phase implementation

  # Show detailed information about task 010
  sow task status --id 010

  # Show task in specific phase
  sow task status --id 010 --phase implementation`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskStatus(cmd, taskID, phase)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID for detailed view (optional)")
	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (
cmd.runTaskAdd function · go · L188-L270 (83 LOC)
cli/cmd/task.go
func runTaskAdd(cmd *cobra.Command, name, agent, description, taskID, explicitPhase string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Generate or validate task ID
	if taskID == "" {
		// Auto-generate next task ID (gap-numbered)
		taskID = generateNextTaskID(phaseState.Tasks)
	} else {
		// Validate specified task ID format (must be 3 digits)
		if len
cmd.runTaskSet function · go · L273-L342 (70 LOC)
cli/cmd/task.go
func runTaskSet(cmd *cobra.Command, args []string, taskID, explicitPhase string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Wrap in Task type for f
cmd.runTaskAbandon function · go · L345-L402 (58 LOC)
cli/cmd/task.go
func runTaskAbandon(cmd *cobra.Command, taskID, explicitPhase string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Update task status
	now := time.No
cmd.runTaskStatus function · go · L405-L448 (44 LOC)
cli/cmd/task.go
func runTaskStatus(cmd *cobra.Command, taskID, explicitPhase string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Check if overview or detailed mode
	if taskID == "" {
		// Overview mode - show all tasks
		return displayTaskOverview(phaseName, phaseState.Tasks)
	}

	// Detailed mode - find and display specific task
	for _, task := range phaseState.Tasks 
Repobility — the code-quality scanner for AI-generated software · https://repobility.com
cmd.displayTaskOverview function · go · L451-L480 (30 LOC)
cli/cmd/task.go
func displayTaskOverview(phaseName string, tasks []project.TaskState) error {
	if len(tasks) == 0 {
		fmt.Printf("No tasks found in phase %s.\n", phaseName)
		return nil
	}

	fmt.Printf("Tasks in %s phase:\n", phaseName)

	// Count statuses
	statusCounts := make(map[string]int)
	for _, task := range tasks {
		statusCounts[task.Status]++

		// Display task line
		iterationInfo := ""
		if task.Iteration > 1 {
			iterationInfo = fmt.Sprintf(" - iteration %d", task.Iteration)
		}
		fmt.Printf("  [%s] %s (%s)%s\n", task.Id, task.Name, task.Status, iterationInfo)
	}

	// Summary line
	fmt.Printf("\n%d total tasks", len(tasks))
	for status, count := range statusCounts {
		fmt.Printf(": %d %s", count, status)
	}
	fmt.Println()

	return nil
}
cmd.displayTaskDetail function · go · L483-L550 (68 LOC)
cli/cmd/task.go
func displayTaskDetail(task project.TaskState) error {
	fmt.Printf("Task: %s - %s\n", task.Id, task.Name)
	fmt.Printf("Phase: %s\n", task.Phase)
	fmt.Printf("Status: %s\n", task.Status)
	fmt.Printf("Iteration: %d\n", task.Iteration)
	fmt.Printf("Assigned Agent: %s\n", task.Assigned_agent)
	fmt.Println()

	// Timestamps
	fmt.Println("Timestamps:")
	fmt.Printf("  Created:   %s\n", task.Created_at.Format("2006-01-02 15:04:05"))
	if !task.Started_at.IsZero() {
		fmt.Printf("  Started:   %s\n", task.Started_at.Format("2006-01-02 15:04:05"))
	}
	fmt.Printf("  Updated:   %s\n", task.Updated_at.Format("2006-01-02 15:04:05"))
	if !task.Completed_at.IsZero() {
		fmt.Printf("  Completed: %s\n", task.Completed_at.Format("2006-01-02 15:04:05"))
	}
	fmt.Println()

	// Inputs
	if len(task.Inputs) > 0 {
		fmt.Printf("Inputs (%d):\n", len(task.Inputs))
		for i, input := range task.Inputs {
			fmt.Printf("  [%d] %s: %s\n", i, input.Type, input.Path)
			// Show metadata if present
			if len(input.Metadat
cmd.generateNextTaskID function · go · L554-L571 (18 LOC)
cli/cmd/task.go
func generateNextTaskID(tasks []project.TaskState) string {
	if len(tasks) == 0 {
		return "010"
	}

	// Find highest ID
	maxID := 0
	for _, task := range tasks {
		id, err := strconv.Atoi(task.Id)
		if err == nil && id > maxID {
			maxID = id
		}
	}

	// Return next gap-numbered ID
	nextID := maxID + 10
	return fmt.Sprintf("%03d", nextID)
}
cmd.createTaskDirectory function · go · L574-L602 (29 LOC)
cli/cmd/task.go
func createTaskDirectory(ctx *sow.Context, phaseName, taskID, description string) error {
	taskDir := filepath.Join(ctx.RepoRoot(), ".sow/project/phases", phaseName, "tasks", taskID)

	// Create directories
	if err := os.MkdirAll(filepath.Join(taskDir, "feedback"), 0755); err != nil {
		return err
	}

	// Create description.md
	descPath := filepath.Join(taskDir, "description.md")
	descContent := description
	if descContent == "" {
		descContent = "# Task Description\n\nTODO: Add task description\n"
	} else {
		descContent = descContent + "\n"
	}
	if err := os.WriteFile(descPath, []byte(descContent), 0644); err != nil {
		return err
	}

	// Create empty log.md
	logPath := filepath.Join(taskDir, "log.md")
	logContent := "# Task Log\n\nWorker actions will be logged here.\n"
	if err := os.WriteFile(logPath, []byte(logContent), 0644); err != nil {
		return err
	}

	return nil
}
cmd.newTaskInputCmd function · go · L15-L31 (17 LOC)
cli/cmd/task_input.go
func newTaskInputCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "input",
		Short: "Manage task input artifacts",
		Long: `Manage task input artifacts.

Task input commands allow you to add, modify, remove, and list input artifacts
for tasks. Artifacts are managed using zero-based indices.`,
	}

	cmd.AddCommand(newTaskInputAddCmd())
	cmd.AddCommand(newTaskInputSetCmd())
	cmd.AddCommand(newTaskInputRemoveCmd())
	cmd.AddCommand(newTaskInputListCmd())

	return cmd
}
cmd.newTaskInputAddCmd function · go · L34-L76 (43 LOC)
cli/cmd/task_input.go
func newTaskInputAddCmd() *cobra.Command {
	var taskID, artifactType, path, phase string
	var approved bool

	cmd := &cobra.Command{
		Use:   "add",
		Short: "Add input artifact to task",
		Long: `Add an input artifact to a task.

Creates a new input artifact with the specified type and path.
The artifact is appended to the task's input list.

To set metadata fields, use 'task input set' after adding the artifact.

Examples:
  # Add reference artifact
  sow task input add --id 010 --type reference --path sinks/style-guide.md

  # Add feedback artifact
  sow task input add --id 010 --type feedback --path phases/implementation/tasks/010/feedback/1.md

  # Then set metadata (e.g., assessment)
  sow task input set --id 010 --index 0 metadata.assessment fail

  # Add with approval flag
  sow task input add --id 010 --type reference --path docs/arch.md --approved`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskInputAdd(cmd, taskID, artifactType, path, phase, approved)
cmd.newTaskInputSetCmd function · go · L79-L115 (37 LOC)
cli/cmd/task_input.go
func newTaskInputSetCmd() *cobra.Command {
	var taskID, phase string
	var index int

	cmd := &cobra.Command{
		Use:   "set <field-path> <value>",
		Short: "Set field on task input artifact by index",
		Long: `Set a field on a task input artifact using its index.

Supports both direct fields and metadata fields using dot notation:
  - Direct fields: type, path, approved
  - Metadata fields: metadata.* (any custom field)

Examples:
  # Set approved field
  sow task input set --id 010 --index 0 approved true

  # Set metadata field (e.g., feedback status)
  sow task input set --id 010 --index 2 metadata.status addressed

  # Set nested metadata
  sow task input set --id 010 --index 0 metadata.reviewer.name orchestrator`,
		Args: cobra.ExactArgs(2),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runTaskInputSet(cmd, args, taskID, phase, index)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().IntVar(&index, "index", -1, "Artifact index
cmd.newTaskInputRemoveCmd function · go · L118-L149 (32 LOC)
cli/cmd/task_input.go
func newTaskInputRemoveCmd() *cobra.Command {
	var taskID, phase string
	var index int

	cmd := &cobra.Command{
		Use:   "remove",
		Short: "Remove task input artifact by index",
		Long: `Remove an input artifact from a task by its index.

The artifact at the specified index is removed from the task's input list.
Indices of subsequent artifacts are shifted down.

Examples:
  # Remove first input
  sow task input remove --id 010 --index 0

  # Remove specific feedback item
  sow task input remove --id 010 --index 2`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskInputRemove(cmd, taskID, phase, index)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().IntVar(&index, "index", -1, "Artifact index (required)")
	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (defaults to current phase)")

	_ = cmd.MarkFlagRequired("id")
	_ = cmd.MarkFlagRequired("index")

	return cmd
}
Repobility · code-quality intelligence · https://repobility.com
cmd.newTaskInputListCmd function · go · L152-L175 (24 LOC)
cli/cmd/task_input.go
func newTaskInputListCmd() *cobra.Command {
	var taskID, phase string

	cmd := &cobra.Command{
		Use:   "list",
		Short: "List input artifacts for task",
		Long: `List all input artifacts for a task.

Displays artifacts with their indices and details including type, path,
approval status, and metadata.

Example:
  sow task input list --id 010`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskInputList(cmd, taskID, phase)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (defaults to current phase)")
	_ = cmd.MarkFlagRequired("id")

	return cmd
}
cmd.runTaskInputAdd function · go · L178-L242 (65 LOC)
cli/cmd/task_input.go
func runTaskInputAdd(cmd *cobra.Command, taskID, artifactType, path, explicitPhase string, approved bool) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	/
cmd.runTaskInputSet function · go · L245-L318 (74 LOC)
cli/cmd/task_input.go
func runTaskInputSet(cmd *cobra.Command, args []string, taskID, explicitPhase string, index int) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Get fie
cmd.runTaskInputRemove function · go · L321-L384 (64 LOC)
cli/cmd/task_input.go
func runTaskInputRemove(cmd *cobra.Command, taskID, explicitPhase string, index int) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Validate index
	if 
cmd.runTaskInputList function · go · L387-L440 (54 LOC)
cli/cmd/task_input.go
func runTaskInputList(cmd *cobra.Command, taskID, explicitPhase string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Convert to state.Artifact for fo
cmd.newTaskOutputCmd function · go · L15-L31 (17 LOC)
cli/cmd/task_output.go
func newTaskOutputCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "output",
		Short: "Manage task output artifacts",
		Long: `Manage task output artifacts.

Task output commands allow you to add, modify, remove, and list output artifacts
for tasks. Artifacts are managed using zero-based indices.`,
	}

	cmd.AddCommand(newTaskOutputAddCmd())
	cmd.AddCommand(newTaskOutputSetCmd())
	cmd.AddCommand(newTaskOutputRemoveCmd())
	cmd.AddCommand(newTaskOutputListCmd())

	return cmd
}
cmd.newTaskOutputAddCmd function · go · L34-L68 (35 LOC)
cli/cmd/task_output.go
func newTaskOutputAddCmd() *cobra.Command {
	var taskID, artifactType, path, phase string
	var approved bool

	cmd := &cobra.Command{
		Use:   "add",
		Short: "Add output artifact to task",
		Long: `Add an output artifact to a task.

Creates a new output artifact with the specified type and path.
The artifact is appended to the task's output list.

Examples:
  # Add modified file
  sow task output add --id 010 --type modified --path src/auth/jwt.ts

  # Add with approval flag
  sow task output add --id 010 --type modified --path src/auth/verify.ts --approved`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskOutputAdd(cmd, taskID, artifactType, path, phase, approved)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().StringVar(&artifactType, "type", "", "Artifact type (required)")
	cmd.Flags().StringVar(&path, "path", "", "Artifact path (required)")
	cmd.Flags().BoolVar(&approved, "approved", false, "Mark artifact as approved")

	
cmd.newTaskOutputSetCmd function · go · L71-L107 (37 LOC)
cli/cmd/task_output.go
func newTaskOutputSetCmd() *cobra.Command {
	var taskID, phase string
	var index int

	cmd := &cobra.Command{
		Use:   "set <field-path> <value>",
		Short: "Set field on task output artifact by index",
		Long: `Set a field on a task output artifact using its index.

Supports both direct fields and metadata fields using dot notation:
  - Direct fields: type, path, approved
  - Metadata fields: metadata.* (any custom field)

Examples:
  # Set approved field
  sow task output set --id 010 --index 0 approved true

  # Set metadata field
  sow task output set --id 010 --index 0 metadata.reviewed true

  # Set nested metadata
  sow task output set --id 010 --index 0 metadata.reviewer.name orchestrator`,
		Args: cobra.ExactArgs(2),
		RunE: func(cmd *cobra.Command, args []string) error {
			return runTaskOutputSet(cmd, args, taskID, phase, index)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().IntVar(&index, "index", -1, "Artifact index (required)")

	cmd.
Powered by Repobility — scan your code at https://repobility.com
cmd.newTaskOutputRemoveCmd function · go · L110-L141 (32 LOC)
cli/cmd/task_output.go
func newTaskOutputRemoveCmd() *cobra.Command {
	var taskID, phase string
	var index int

	cmd := &cobra.Command{
		Use:   "remove",
		Short: "Remove task output artifact by index",
		Long: `Remove an output artifact from a task by its index.

The artifact at the specified index is removed from the task's output list.
Indices of subsequent artifacts are shifted down.

Examples:
  # Remove first output
  sow task output remove --id 010 --index 0

  # Remove specific file
  sow task output remove --id 010 --index 2`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskOutputRemove(cmd, taskID, phase, index)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().IntVar(&index, "index", -1, "Artifact index (required)")

	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (defaults to current phase)")
	_ = cmd.MarkFlagRequired("id")
	_ = cmd.MarkFlagRequired("index")

	return cmd
}
cmd.newTaskOutputListCmd function · go · L144-L167 (24 LOC)
cli/cmd/task_output.go
func newTaskOutputListCmd() *cobra.Command {
	var taskID, phase string

	cmd := &cobra.Command{
		Use:   "list",
		Short: "List output artifacts for task",
		Long: `List all output artifacts for a task.

Displays artifacts with their indices and details including type, path,
approval status, and metadata.

Example:
  sow task output list --id 010`,
		RunE: func(cmd *cobra.Command, _ []string) error {
			return runTaskOutputList(cmd, taskID, phase)
		},
	}

	cmd.Flags().StringVar(&taskID, "id", "", "Task ID (required)")
	cmd.Flags().StringVar(&phase, "phase", "", "Target phase (defaults to current phase)")
	_ = cmd.MarkFlagRequired("id")

	return cmd
}
cmd.runTaskOutputAdd function · go · L170-L234 (65 LOC)
cli/cmd/task_output.go
func runTaskOutputAdd(cmd *cobra.Command, taskID, artifactType, path, explicitPhase string, approved bool) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	
cmd.runTaskOutputSet function · go · L237-L310 (74 LOC)
cli/cmd/task_output.go
func runTaskOutputSet(cmd *cobra.Command, args []string, taskID, explicitPhase string, index int) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Get fi
cmd.runTaskOutputRemove function · go · L313-L376 (64 LOC)
cli/cmd/task_output.go
func runTaskOutputRemove(cmd *cobra.Command, taskID, explicitPhase string, index int) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Validate index
	if
cmd.runTaskOutputList function · go · L379-L432 (54 LOC)
cli/cmd/task_output.go
func runTaskOutputList(cmd *cobra.Command, taskID, explicitPhase string) error {
	ctx := cmdutil.GetContext(cmd.Context())

	// Check if sow is initialized
	if !ctx.IsInitialized() {
		return fmt.Errorf("sow not initialized. Run 'sow init' first")
	}

	// Load project
	proj, err := cmdutil.LoadProject(cmd.Context(), ctx)
	if err != nil {
		if strings.Contains(err.Error(), "no such file") {
			return fmt.Errorf("no active project found")
		}
		return fmt.Errorf("failed to load project: %w", err)
	}

	// Resolve which phase to use
	phaseName, err := resolveTaskPhase(proj, explicitPhase)
	if err != nil {
		return err
	}

	// Get phase
	phaseState, exists := proj.Phases[phaseName]
	if !exists {
		return fmt.Errorf("phase not found: %s", phaseName)
	}

	// Find task by ID
	taskIndex := -1
	for i, t := range phaseState.Tasks {
		if t.Id == taskID {
			taskIndex = i
			break
		}
	}

	if taskIndex == -1 {
		return fmt.Errorf("task not found: %s", taskID)
	}

	// Convert to state.Artifact for f
cmd.NewWorktreeCmd function · go · L16-L36 (21 LOC)
cli/cmd/worktree.go
func NewWorktreeCmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "worktree",
		Short: "Manage git worktrees",
		Long: `Manage git worktrees used for concurrent sow sessions.

Worktrees enable running multiple sow sessions simultaneously:
  - Exploration sessions on different topics
  - Project work on separate branches
  - Design sessions for different features

Each worktree has isolated state while sharing committed knowledge.`,
	}

	// Add subcommands
	cmd.AddCommand(newWorktreeListCmd())
	cmd.AddCommand(newWorktreeRemoveCmd())
	cmd.AddCommand(newWorktreePruneCmd())

	return cmd
}
cmd.newWorktreeListCmd function · go · L39-L46 (8 LOC)
cli/cmd/worktree.go
func newWorktreeListCmd() *cobra.Command {
	return &cobra.Command{
		Use:   "list",
		Short: "List all worktrees with session information",
		Long:  `Display all active worktrees showing path, branch, session type, and status.`,
		RunE:  runWorktreeList,
	}
}
Methodology: Repobility · https://repobility.com/research/state-of-ai-code-2026/
cmd.runWorktreeList function · go · L48-L100 (53 LOC)
cli/cmd/worktree.go
func runWorktreeList(cmd *cobra.Command, _ []string) error {
	ctx := cmdutil.GetContext(cmd.Context())

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

	// Filter to only .sow/worktrees/ (exclude main repo)
	sowWorktrees := []WorktreeInfo{}
	for _, wt := range worktrees {
		// Check if this is a .sow/worktrees/* worktree
		if !isSowWorktree(wt.Path(), ctx.RepoRoot()) {
			continue
		}

		// Detect session type
		sessionType := detectSessionType(wt.Path())

		// Get branch name
		branchName := extractBranchName(wt.Path(), ctx.RepoRoot())

		sowWorktrees = append(sowWorktrees, WorktreeInfo{
			Path:        wt.Path(),
			Branch:      branchName,
			SessionType: sessionType,
			Status:      "active", // Could check for locked, etc.
		})
	}

	// Display in table format
	if len(sowWorktrees) == 0 {
		fmt.Println("No sow worktrees found")
		return nil
	}

	w := tabwr
cmd.isSowWorktree function · go · L111-L120 (10 LOC)
cli/cmd/worktree.go
func isSowWorktree(path, repoRoot string) bool {
	worktreesDir := filepath.Join(repoRoot, ".sow", "worktrees")
	rel, err := filepath.Rel(worktreesDir, path)
	if err != nil {
		return false
	}
	// Check that path is under .sow/worktrees/ and not "." or starts with ".."
	// If rel starts with "..", it's outside the worktreesDir
	return !filepath.IsAbs(rel) && rel != "." && !strings.HasPrefix(rel, "..")
}
cmd.detectSessionType function · go · L123-L138 (16 LOC)
cli/cmd/worktree.go
func detectSessionType(worktreePath string) string {
	// Check for session state directories
	if _, err := os.Stat(filepath.Join(worktreePath, ".sow", "project")); err == nil {
		return "project"
	}
	if _, err := os.Stat(filepath.Join(worktreePath, ".sow", "exploration")); err == nil {
		return "exploration"
	}
	if _, err := os.Stat(filepath.Join(worktreePath, ".sow", "design")); err == nil {
		return "design"
	}
	if _, err := os.Stat(filepath.Join(worktreePath, ".sow", "breakdown")); err == nil {
		return "breakdown"
	}
	return "unknown"
}
‹ prevpage 4 / 12next ›