Class: Fp::Commands::Propose

Inherits:
Base
  • Object
show all
Defined in:
lib/fp/commands/propose.rb

Overview

fp propose --project --slug X --name "..." --why "..." --required a,b,c --acceptance "..." --parent Create a new requirement as draft

Constant Summary collapse

KNOWN_FLAGS =
{
  project: :string,
  slug: :string,
  name: :string,
  why: :string,
  required: :string,
  acceptance: :string,
  parent: :string
}.freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Fp::Commands::Base

Instance Method Details

#run(args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fp/commands/propose.rb', line 18

def run(args)
  opts, = parse_flags(args, KNOWN_FLAGS)

  require_flag(opts, :project)
  require_flag(opts, :slug, '--slug is required (immutable identifier for the requirement)')
  require_flag(opts, :name, '--name is required (human-readable title)')

  workspace_id = resolve_workspace_id(opts[:project])

  # Parse required surfaces (comma-separated)
  required_surfaces = if opts[:required]
                        opts[:required].split(',').map(&:strip)
                      else
                        []
                      end

  params = {
    slug: opts[:slug],
    title: opts[:name],
    workspace_id: workspace_id,
    required_surfaces: required_surfaces
  }
  params[:why] = opts[:why] if opts[:why]
  params[:acceptance] = opts[:acceptance] if opts[:acceptance]

  # Resolve parent slug to parent_id if provided
  if opts[:parent]
    parent_id = resolve_parent_id(workspace_id, opts[:parent])
    params[:parent_id] = parent_id
  end

  # Note: status is NOT sent - the API enforces draft for agents

  result = client.create_requirement(params)

  unless result[:ok]
    output.error(result[:error], status: result[:status])
    exit 1
  end

  requirement = result[:data]['requirement']

  output.success(result[:data]) do
    puts "Created requirement '#{requirement['slug']}' as DRAFT."
    puts
    puts "  Title:    #{requirement['title']}"
    puts "  Status:   #{requirement['status']}"
    puts "  Surfaces: #{(requirement['required_surfaces'] || []).join(', ')}"
    puts "  Parent:   #{opts[:parent] || '(none)'}" if opts[:parent]
    puts
    puts '⚠️  This requirement is a DRAFT.'
    puts '   A human must activate it in the web app before it appears in the parity matrix.'
    puts '   Agents cannot activate requirements.'
  end
end