binocs 0.1.0

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README.md +528 -0
  4. data/Rakefile +7 -0
  5. data/app/assets/javascripts/binocs/application.js +105 -0
  6. data/app/assets/stylesheets/binocs/application.css +67 -0
  7. data/app/channels/binocs/application_cable/channel.rb +8 -0
  8. data/app/channels/binocs/application_cable/connection.rb +8 -0
  9. data/app/channels/binocs/requests_channel.rb +13 -0
  10. data/app/controllers/binocs/application_controller.rb +62 -0
  11. data/app/controllers/binocs/requests_controller.rb +69 -0
  12. data/app/helpers/binocs/application_helper.rb +61 -0
  13. data/app/models/binocs/application_record.rb +7 -0
  14. data/app/models/binocs/request.rb +198 -0
  15. data/app/views/binocs/requests/_empty_list.html.erb +9 -0
  16. data/app/views/binocs/requests/_request.html.erb +61 -0
  17. data/app/views/binocs/requests/index.html.erb +115 -0
  18. data/app/views/binocs/requests/show.html.erb +227 -0
  19. data/app/views/layouts/binocs/application.html.erb +109 -0
  20. data/config/importmap.rb +6 -0
  21. data/config/routes.rb +11 -0
  22. data/db/migrate/20240101000000_create_binocs_requests.rb +36 -0
  23. data/exe/binocs +86 -0
  24. data/lib/binocs/agent.rb +153 -0
  25. data/lib/binocs/agent_context.rb +165 -0
  26. data/lib/binocs/agent_manager.rb +302 -0
  27. data/lib/binocs/configuration.rb +65 -0
  28. data/lib/binocs/engine.rb +61 -0
  29. data/lib/binocs/log_subscriber.rb +56 -0
  30. data/lib/binocs/middleware/request_recorder.rb +264 -0
  31. data/lib/binocs/swagger/client.rb +100 -0
  32. data/lib/binocs/swagger/path_matcher.rb +118 -0
  33. data/lib/binocs/tui/agent_output.rb +163 -0
  34. data/lib/binocs/tui/agents_list.rb +195 -0
  35. data/lib/binocs/tui/app.rb +726 -0
  36. data/lib/binocs/tui/colors.rb +115 -0
  37. data/lib/binocs/tui/filter_menu.rb +162 -0
  38. data/lib/binocs/tui/help_screen.rb +93 -0
  39. data/lib/binocs/tui/request_detail.rb +899 -0
  40. data/lib/binocs/tui/request_list.rb +268 -0
  41. data/lib/binocs/tui/spirit_animal.rb +235 -0
  42. data/lib/binocs/tui/window.rb +98 -0
  43. data/lib/binocs/tui.rb +24 -0
  44. data/lib/binocs/version.rb +5 -0
  45. data/lib/binocs.rb +27 -0
  46. data/lib/generators/binocs/install/install_generator.rb +61 -0
  47. data/lib/generators/binocs/install/templates/create_binocs_requests.rb +36 -0
  48. data/lib/generators/binocs/install/templates/initializer.rb +25 -0
  49. data/lib/tasks/binocs_tasks.rake +38 -0
  50. metadata +149 -0
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+ require "rails/generators/active_record"
5
+
6
+ module Binocs
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+
11
+ source_root File.expand_path("templates", __dir__)
12
+
13
+ def self.next_migration_number(dirname)
14
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
15
+ end
16
+
17
+ def copy_migrations
18
+ migration_template "create_binocs_requests.rb", "db/migrate/create_binocs_requests.rb"
19
+ end
20
+
21
+ def create_initializer
22
+ template "initializer.rb", "config/initializers/binocs.rb"
23
+ end
24
+
25
+ def add_route
26
+ route "mount Binocs::Engine => '/binocs' unless Rails.env.production?"
27
+ end
28
+
29
+ def update_gitignore
30
+ gitignore_path = Rails.root.join(".gitignore")
31
+ return unless File.exist?(gitignore_path)
32
+
33
+ gitignore_entries = <<~GITIGNORE
34
+
35
+ # Binocs AI Agent files
36
+ .binocs-context.md
37
+ .binocs-prompt.md
38
+ GITIGNORE
39
+
40
+ gitignore_content = File.read(gitignore_path)
41
+
42
+ # Check if already added
43
+ return if gitignore_content.include?(".binocs-context.md")
44
+
45
+ append_to_file ".gitignore", gitignore_entries
46
+ say "Updated .gitignore with Binocs entries", :green
47
+ end
48
+
49
+ def show_readme
50
+ say ""
51
+ say "Binocs installed successfully!", :green
52
+ say ""
53
+ say "Next steps:"
54
+ say " 1. Run migrations: bin/rails db:migrate"
55
+ say " 2. Start your server: bin/rails server"
56
+ say " 3. Visit: http://localhost:3000/binocs"
57
+ say ""
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateBinocsRequests < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
4
+ def change
5
+ create_table :binocs_requests do |t|
6
+ t.string :uuid, null: false, index: { unique: true }
7
+ t.string :method, null: false
8
+ t.string :path, null: false
9
+ t.text :full_url
10
+ t.string :controller_name
11
+ t.string :action_name
12
+ t.string :route_name
13
+ t.text :params
14
+ t.text :request_headers
15
+ t.text :response_headers
16
+ t.text :request_body
17
+ t.text :response_body
18
+ t.integer :status_code
19
+ t.float :duration_ms
20
+ t.string :ip_address
21
+ t.string :session_id
22
+ t.text :logs
23
+ t.text :exception
24
+ t.integer :memory_delta
25
+ t.string :content_type
26
+
27
+ t.timestamps
28
+ end
29
+
30
+ add_index :binocs_requests, :method
31
+ add_index :binocs_requests, :status_code
32
+ add_index :binocs_requests, :controller_name
33
+ add_index :binocs_requests, :created_at
34
+ add_index :binocs_requests, :duration_ms
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Binocs Configuration
4
+ # For more options, see: https://github.com/zincan/binocs
5
+
6
+ Binocs.configure do |config|
7
+ # Enable/disable Binocs (automatically disabled in production)
8
+ config.enabled = true
9
+
10
+ # How long to keep request records
11
+ config.retention_period = 24.hours
12
+
13
+ # Maximum request/response body size to store
14
+ config.max_body_size = 64.kilobytes
15
+
16
+ # Paths to ignore
17
+ config.ignored_paths = %w[/assets /packs /binocs /cable]
18
+
19
+ # Maximum number of requests to store
20
+ config.max_requests = 1000
21
+
22
+ # Optional: Protect dashboard with basic auth
23
+ # config.basic_auth_username = ENV['BINOCS_USERNAME']
24
+ # config.basic_auth_password = ENV['BINOCS_PASSWORD']
25
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :binocs do
4
+ desc "Clear all Binocs request records"
5
+ task clear: :environment do
6
+ count = Binocs::Request.count
7
+ Binocs::Request.delete_all
8
+ puts "Cleared #{count} Binocs request records."
9
+ end
10
+
11
+ desc "Prune old Binocs request records"
12
+ task prune: :environment do
13
+ retention = Binocs.configuration.retention_period
14
+ count = Binocs::Request.where("created_at < ?", retention.ago).delete_all
15
+ puts "Pruned #{count} Binocs request records older than #{retention.inspect}."
16
+ end
17
+
18
+ desc "Show Binocs statistics"
19
+ task stats: :environment do
20
+ puts "Binocs Statistics"
21
+ puts "-" * 40
22
+ puts "Total requests: #{Binocs::Request.count}"
23
+ puts "Requests today: #{Binocs::Request.today.count}"
24
+ puts "Requests last hour: #{Binocs::Request.last_hour.count}"
25
+ puts "Average duration: #{Binocs::Request.average_duration || 0}ms"
26
+ puts "Error rate: #{Binocs::Request.error_rate}%"
27
+ puts ""
28
+ puts "Methods breakdown:"
29
+ Binocs::Request.methods_breakdown.each do |method, count|
30
+ puts " #{method}: #{count}"
31
+ end
32
+ puts ""
33
+ puts "Status breakdown:"
34
+ Binocs::Request.status_breakdown.sort.each do |status, count|
35
+ puts " #{status}: #{count}"
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binocs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nate Collins
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: curses
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.4'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rails
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '7.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: stimulus-rails
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: turbo-rails
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ description: A Rails engine that provides a beautiful dashboard to monitor and debug
69
+ HTTP requests, similar to Laravel Telescope. Includes a terminal UI with vim keybindings.
70
+ email:
71
+ - n@zincan.com
72
+ executables:
73
+ - binocs
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - MIT-LICENSE
78
+ - README.md
79
+ - Rakefile
80
+ - app/assets/javascripts/binocs/application.js
81
+ - app/assets/stylesheets/binocs/application.css
82
+ - app/channels/binocs/application_cable/channel.rb
83
+ - app/channels/binocs/application_cable/connection.rb
84
+ - app/channels/binocs/requests_channel.rb
85
+ - app/controllers/binocs/application_controller.rb
86
+ - app/controllers/binocs/requests_controller.rb
87
+ - app/helpers/binocs/application_helper.rb
88
+ - app/models/binocs/application_record.rb
89
+ - app/models/binocs/request.rb
90
+ - app/views/binocs/requests/_empty_list.html.erb
91
+ - app/views/binocs/requests/_request.html.erb
92
+ - app/views/binocs/requests/index.html.erb
93
+ - app/views/binocs/requests/show.html.erb
94
+ - app/views/layouts/binocs/application.html.erb
95
+ - config/importmap.rb
96
+ - config/routes.rb
97
+ - db/migrate/20240101000000_create_binocs_requests.rb
98
+ - exe/binocs
99
+ - lib/binocs.rb
100
+ - lib/binocs/agent.rb
101
+ - lib/binocs/agent_context.rb
102
+ - lib/binocs/agent_manager.rb
103
+ - lib/binocs/configuration.rb
104
+ - lib/binocs/engine.rb
105
+ - lib/binocs/log_subscriber.rb
106
+ - lib/binocs/middleware/request_recorder.rb
107
+ - lib/binocs/swagger/client.rb
108
+ - lib/binocs/swagger/path_matcher.rb
109
+ - lib/binocs/tui.rb
110
+ - lib/binocs/tui/agent_output.rb
111
+ - lib/binocs/tui/agents_list.rb
112
+ - lib/binocs/tui/app.rb
113
+ - lib/binocs/tui/colors.rb
114
+ - lib/binocs/tui/filter_menu.rb
115
+ - lib/binocs/tui/help_screen.rb
116
+ - lib/binocs/tui/request_detail.rb
117
+ - lib/binocs/tui/request_list.rb
118
+ - lib/binocs/tui/spirit_animal.rb
119
+ - lib/binocs/tui/window.rb
120
+ - lib/binocs/version.rb
121
+ - lib/generators/binocs/install/install_generator.rb
122
+ - lib/generators/binocs/install/templates/create_binocs_requests.rb
123
+ - lib/generators/binocs/install/templates/initializer.rb
124
+ - lib/tasks/binocs_tasks.rake
125
+ homepage: https://github.com/zincan/binocs
126
+ licenses:
127
+ - MIT
128
+ metadata:
129
+ homepage_uri: https://github.com/zincan/binocs
130
+ source_code_uri: https://github.com/zincan/binocs
131
+ changelog_uri: https://github.com/zincan/binocs/blob/main/CHANGELOG.md
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 3.0.0
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.6.7
147
+ specification_version: 4
148
+ summary: Web and TUI request monitoring for development in Rails
149
+ test_files: []