schwarm-cli 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 485f701799de73d084bf43fff3cc0ebf1244a41397775baea03de793b860b4b9
4
- data.tar.gz: 6125bc6e805189c3faa9ec3d33ff6545fd77c4c93ab966ccae142a2fc50102a5
3
+ metadata.gz: 407d8cf7c33a697ed71a0bd8b3345d278fa34705ec04fdc2ee358d55c7c549c2
4
+ data.tar.gz: 2949bbaf855be804caec35e0a25df038850c2bd4e7885421651f3cc48c4cbbe3
5
5
  SHA512:
6
- metadata.gz: 1ef6550c32124fe3a2125dc2e79d10c05ec918bbabafd17918d1c13274954b33fae413cd679f58e5484c4b02b97bda64c6d495a62fb02d38e1afba389de7ac69
7
- data.tar.gz: 2057d8334094ab913ebc115ed3818a54887cafa922688bcc66f54be4035322d51466ccd7610a1aad0b68f59ccb643604551a7b7e791168ba49f3be4a9e83dbf7
6
+ metadata.gz: d3841fa2204bac7b1ee9debab270e7509925388563d49a72dcfbbfb61d8c7ab593ccc14a6c6ec978925c43c0a83f46603e0607a28a4e5d4696f50b87f1f7e8c4
7
+ data.tar.gz: cffebca5659d080e7b05ddd386e254acc3870b40678a59ee3e76acf5e5ee82119643ecd7390df00b7102768b5f8e11703900927a4ba035e211b0314e33a3fb5b
@@ -3,8 +3,9 @@
3
3
  module SchwarmCli
4
4
  class Client
5
5
  class AgentSessions < Resource
6
- def list(source: nil, status: nil, page: nil, per_page: nil)
6
+ def list(source: nil, status: nil, page: nil, per_page: nil, active: nil)
7
7
  params = { source:, status:, page:, per_page: }.compact
8
+ params[:active] = active unless active.nil?
8
9
  get("/api/v2/agent_sessions", params).body
9
10
  end
10
11
 
@@ -3,8 +3,9 @@
3
3
  module SchwarmCli
4
4
  class Client
5
5
  class Tasks < Resource
6
- def list(status: nil, repository_id: nil, page: nil, per_page: nil, query: nil)
7
- params = { status:, repository_id:, page:, per_page:, q: query }.compact
6
+ def list(query: nil, **filters)
7
+ params = filters.compact
8
+ params[:q] = query if query
8
9
  get("/api/v2/tasks", params).body
9
10
  end
10
11
 
@@ -6,10 +6,13 @@ module SchwarmCli
6
6
  desc "list", "List repository agents"
7
7
  option :repo, type: :string, desc: "Filter by repository ID"
8
8
  option :query, type: :string, desc: "Search by name"
9
+ pagination_options
9
10
  def list
10
11
  handle_errors do
11
- data = client.agents.list(repository_id: options[:repo], query: options[:query])
12
- output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_id],
12
+ data = fetch_paged do |page_params|
13
+ client.agents.list(repository_id: options[:repo], query: options[:query], **page_params)
14
+ end
15
+ output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_name],
13
16
  %w[ENABLED enabled], %w[SCHEDULE schedule]])
14
17
  end
15
18
  end
@@ -9,6 +9,16 @@ module SchwarmCli
9
9
  class_option :url, type: :string, desc: "Schwarm server URL (overrides config)"
10
10
  class_option :token, type: :string, desc: "API key (overrides config)"
11
11
 
12
+ DEFAULT_LIST_LIMIT = 20
13
+
14
+ # Declares --limit, --page, --all options for the next method.
15
+ def self.pagination_options
16
+ method_option :limit, type: :numeric,
17
+ desc: "Max results per page (default: #{DEFAULT_LIST_LIMIT})"
18
+ method_option :page, type: :numeric, desc: "Page number (1-indexed)"
19
+ method_option :all, type: :boolean, default: false, desc: "Fetch all pages (no cap)"
20
+ end
21
+
12
22
  private
13
23
 
14
24
  def client
@@ -19,8 +29,36 @@ module SchwarmCli
19
29
  if options[:json]
20
30
  Formatters::Json.format(data)
21
31
  else
22
- Formatters::Table.format_list(data["data"], columns:)
32
+ Formatters::Table.format_list(data["data"], columns:, meta: data["meta"])
33
+ end
34
+ end
35
+
36
+ # Yields pagination params to the block (once per page). With --all, pages
37
+ # through all results; otherwise a single call using --limit/--page (or the
38
+ # CLI default limit). Returns the merged payload.
39
+ def fetch_paged(&block)
40
+ if options[:all]
41
+ fetch_all_pages(&block)
42
+ else
43
+ per_page = options[:limit] || DEFAULT_LIST_LIMIT
44
+ block.call({ page: options[:page], per_page: }.compact)
45
+ end
46
+ end
47
+
48
+ def fetch_all_pages
49
+ merged_data = []
50
+ page = 1
51
+ per_page = options[:limit] || 200
52
+ meta = nil
53
+ loop do
54
+ response = yield({ page:, per_page: })
55
+ merged_data.concat(response["data"] || [])
56
+ meta = response["meta"]
57
+ break unless meta && page < meta["total_pages"].to_i
58
+
59
+ page += 1
23
60
  end
61
+ { "data" => merged_data, "meta" => meta&.merge("page" => 1, "per_page" => merged_data.size) }
24
62
  end
25
63
 
26
64
  def output_record(data, fields:)
@@ -6,10 +6,13 @@ module SchwarmCli
6
6
  desc "list", "List recurring tasks"
7
7
  option :repo, type: :string, desc: "Filter by repository ID"
8
8
  option :query, type: :string, desc: "Search by name"
9
+ pagination_options
9
10
  def list
10
11
  handle_errors do
11
- data = client.recurring.list(repository_id: options[:repo], query: options[:query])
12
- output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_id],
12
+ data = fetch_paged do |page_params|
13
+ client.recurring.list(repository_id: options[:repo], query: options[:query], **page_params)
14
+ end
15
+ output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_name],
13
16
  %w[ENABLED enabled], %w[SCHEDULE schedule]])
14
17
  end
15
18
  end
@@ -6,11 +6,14 @@ module SchwarmCli
6
6
  desc "list", "List repository-skill associations"
7
7
  option :repo, type: :string, desc: "Filter by repository ID"
8
8
  option :skill, type: :string, desc: "Filter by skill ID"
9
+ pagination_options
9
10
  def list
10
11
  handle_errors do
11
- data = client.repo_skills.list(repository_id: options[:repo], skill_id: options[:skill])
12
- output_list(data, columns: [%w[ID id], %w[REPO github_repository_id],
13
- %w[SKILL skill_id]])
12
+ data = fetch_paged do |page_params|
13
+ client.repo_skills.list(repository_id: options[:repo], skill_id: options[:skill], **page_params)
14
+ end
15
+ output_list(data, columns: [%w[ID id], %w[REPO github_repository_name],
16
+ %w[SKILL skill_name]])
14
17
  end
15
18
  end
16
19
 
@@ -6,9 +6,12 @@ module SchwarmCli
6
6
  desc "list", "List repositories"
7
7
  option :status, type: :string, desc: "Filter by status"
8
8
  option :query, type: :string, desc: "Search by name"
9
+ pagination_options
9
10
  def list
10
11
  handle_errors do
11
- data = client.repositories.list(status: options[:status], query: options[:query])
12
+ data = fetch_paged do |page_params|
13
+ client.repositories.list(status: options[:status], query: options[:query], **page_params)
14
+ end
12
15
  output_list(data, columns: [%w[ID id], %w[NAME name], %w[STATUS status]])
13
16
  end
14
17
  end
@@ -5,10 +5,13 @@ module SchwarmCli
5
5
  class Secrets < Base
6
6
  desc "list", "List secret files"
7
7
  option :repo, type: :string, desc: "Filter by repository ID"
8
+ pagination_options
8
9
  def list
9
10
  handle_errors do
10
- data = client.secrets.list(repository_id: options[:repo])
11
- output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_id],
11
+ data = fetch_paged do |page_params|
12
+ client.secrets.list(repository_id: options[:repo], **page_params)
13
+ end
14
+ output_list(data, columns: [%w[ID id], %w[NAME name], %w[REPO github_repository_name],
12
15
  %w[PATH path]])
13
16
  end
14
17
  end
@@ -3,12 +3,19 @@
3
3
  module SchwarmCli
4
4
  module Commands
5
5
  class Sessions < Base
6
- desc "list", "List agent sessions"
6
+ desc "list", "List agent sessions (shows active ones by default)"
7
7
  option :source, type: :string, desc: "Filter by source"
8
8
  option :status, type: :string, desc: "Filter by status"
9
+ pagination_options
9
10
  def list
10
11
  handle_errors do
11
- data = client.sessions.list(source: options[:source], status: options[:status])
12
+ active_only = options[:status].nil? && !options[:all]
13
+ data = fetch_paged do |page_params|
14
+ client.sessions.list(
15
+ source: options[:source], status: options[:status],
16
+ active: active_only ? true : nil, **page_params
17
+ )
18
+ end
12
19
  output_list(data, columns: [%w[ID id], %w[SOURCE source], %w[STATUS status],
13
20
  %w[CREATED created_at]])
14
21
  end
@@ -5,9 +5,12 @@ module SchwarmCli
5
5
  class SharedAgentsCmd < Base
6
6
  desc "list", "List shared agents"
7
7
  option :query, type: :string, desc: "Search by name"
8
+ pagination_options
8
9
  def list
9
10
  handle_errors do
10
- data = client.shared_agents.list(query: options[:query])
11
+ data = fetch_paged do |page_params|
12
+ client.shared_agents.list(query: options[:query], **page_params)
13
+ end
11
14
  output_list(data, columns: [%w[ID id], %w[NAME name], %w[ENABLED enabled],
12
15
  %w[SCHEDULE schedule]])
13
16
  end
@@ -6,9 +6,12 @@ module SchwarmCli
6
6
  class_option :skill, type: :string, required: true, desc: "Skill ID"
7
7
 
8
8
  desc "list", "List skill files"
9
+ pagination_options
9
10
  def list
10
11
  handle_errors do
11
- data = client.skill_files.list(skill_id: options[:skill])
12
+ data = fetch_paged do |page_params|
13
+ client.skill_files.list(skill_id: options[:skill], **page_params)
14
+ end
12
15
  output_list(data, columns: [%w[ID id], %w[PATH path], %w[CREATED created_at]])
13
16
  end
14
17
  end
@@ -5,9 +5,12 @@ module SchwarmCli
5
5
  class SkillsCmd < Base
6
6
  desc "list", "List skills"
7
7
  option :query, type: :string, desc: "Search by name"
8
+ pagination_options
8
9
  def list
9
10
  handle_errors do
10
- data = client.skills.list(query: options[:query])
11
+ data = fetch_paged do |page_params|
12
+ client.skills.list(query: options[:query], **page_params)
13
+ end
11
14
  output_list(data, columns: [%w[ID id], %w[NAME name], %w[GLOBAL global]])
12
15
  end
13
16
  end
@@ -3,15 +3,16 @@
3
3
  module SchwarmCli
4
4
  module Commands
5
5
  class Tasks < Base
6
- desc "list", "List tasks"
6
+ desc "list", "List tasks (excludes archived by default)"
7
7
  option :status, type: :string, desc: "Filter by status"
8
8
  option :repo, type: :string, desc: "Filter by repository ID"
9
9
  option :query, type: :string, desc: "Search by name"
10
+ pagination_options
10
11
  def list
11
12
  handle_errors do
12
- data = client.tasks.list(status: options[:status], repository_id: options[:repo], query: options[:query])
13
+ data = fetch_paged { |page_params| client.tasks.list(**list_attrs, **page_params) }
13
14
  output_list(data, columns: [%w[ID id], %w[NAME name], %w[STATUS status],
14
- %w[REPO github_repository_id], %w[CREATED created_at]])
15
+ %w[REPO github_repository_name], %w[CREATED created_at]])
15
16
  end
16
17
  end
17
18
 
@@ -115,6 +116,14 @@ module SchwarmCli
115
116
 
116
117
  private
117
118
 
119
+ def list_attrs
120
+ exclude_archived = options[:status].nil? && !options[:all]
121
+ {
122
+ status: options[:status], repository_id: options[:repo], query: options[:query],
123
+ archived: exclude_archived ? false : nil
124
+ }
125
+ end
126
+
118
127
  def create_attrs
119
128
  {
120
129
  name: options[:name], prompt: read_prompt,
@@ -5,9 +5,12 @@ module SchwarmCli
5
5
  class Templates < Base
6
6
  desc "list", "List task templates"
7
7
  option :query, type: :string, desc: "Search by name"
8
+ pagination_options
8
9
  def list
9
10
  handle_errors do
10
- data = client.templates.list(query: options[:query])
11
+ data = fetch_paged do |page_params|
12
+ client.templates.list(query: options[:query], **page_params)
13
+ end
11
14
  output_list(data, columns: [%w[ID id], %w[NAME name], %w[CREATED created_at]])
12
15
  end
13
16
  end
@@ -3,7 +3,7 @@
3
3
  module SchwarmCli
4
4
  module Formatters
5
5
  module Table
6
- def self.format_list(records, columns:)
6
+ def self.format_list(records, columns:, meta: nil)
7
7
  if records.empty?
8
8
  puts "No results found."
9
9
  return
@@ -14,6 +14,18 @@ module SchwarmCli
14
14
  records.each do |record|
15
15
  puts format_row(columns.map { |_, key| record[key].to_s }, columns, widths)
16
16
  end
17
+ footer = pagination_footer(records, meta)
18
+ puts "\n#{footer}" if footer
19
+ end
20
+
21
+ def self.pagination_footer(records, meta)
22
+ meta = meta&.transform_keys(&:to_s)
23
+ total = meta && meta["total_count"]
24
+ return nil if total.nil? || total <= records.size
25
+
26
+ parts = ["showing #{records.size} of #{total}"]
27
+ parts << "page #{meta['page']} of #{meta['total_pages']}" if meta["total_pages"].to_i > 1
28
+ "#{parts.join(' · ')} — use --all or --page/--limit to see more"
17
29
  end
18
30
 
19
31
  def self.format_record(record, fields:)
@@ -33,7 +45,7 @@ module SchwarmCli
33
45
  values.zip(columns).map { |val, (_, key)| val.ljust(widths[key]) }.join(" ")
34
46
  end
35
47
 
36
- private_class_method :column_widths, :format_row
48
+ private_class_method :column_widths, :format_row, :pagination_footer
37
49
  end
38
50
  end
39
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SchwarmCli
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schwarm-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Garrigues