a11y_agent 0.0.5.pre.alpha.1 → 0.0.5.pre.alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/LICENSE +661 -0
- data/lib/a11y_agent/version.rb +1 -1
- data/lib/agents/a11y_agent.rb +160 -0
- data/lib/bin/axe.ts +19 -0
- data/lib/generators/fix_a11y_generator.rb +35 -0
- data/lib/generators/hydrate_document_generator.rb +27 -0
- data/lib/tasks/release.rake +6 -2
- data/package.json +8 -3
- data/yarn.lock +845 -187
- metadata +14 -11
- data/eslint.config.mjs +0 -23
- data/lib/a11y_agent.rb +0 -119
- data/lib/fix_a11y_generator.rb +0 -32
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a11y_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.5.pre.alpha.
|
4
|
+
version: 0.0.5.pre.alpha.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Cundiff
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: tty-prompt
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,13 +88,16 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".env.sample"
|
91
|
+
- ".ruby-version"
|
92
|
+
- LICENSE
|
91
93
|
- README.md
|
92
94
|
- Rakefile
|
93
|
-
- eslint.config.mjs
|
94
95
|
- fixtures/sample.tsx
|
95
|
-
- lib/a11y_agent.rb
|
96
96
|
- lib/a11y_agent/version.rb
|
97
|
-
- lib/
|
97
|
+
- lib/agents/a11y_agent.rb
|
98
|
+
- lib/bin/axe.ts
|
99
|
+
- lib/generators/fix_a11y_generator.rb
|
100
|
+
- lib/generators/hydrate_document_generator.rb
|
98
101
|
- lib/tasks/release.rake
|
99
102
|
- package.json
|
100
103
|
- trigger.txt
|
@@ -117,11 +120,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
120
|
version: 3.3.0
|
118
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
122
|
requirements:
|
120
|
-
- - "
|
123
|
+
- - ">="
|
121
124
|
- !ruby/object:Gem::Version
|
122
|
-
version:
|
125
|
+
version: '0'
|
123
126
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.5.11
|
125
128
|
signing_key:
|
126
129
|
specification_version: 4
|
127
130
|
summary: AI agent that fixes accessibility issues
|
data/eslint.config.mjs
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
import globals from "globals";
|
2
|
-
import pluginJs from "@eslint/js";
|
3
|
-
import tseslint from "typescript-eslint";
|
4
|
-
import pluginReact from "eslint-plugin-react";
|
5
|
-
import jsxA11y from "eslint-plugin-jsx-a11y";
|
6
|
-
|
7
|
-
export default [
|
8
|
-
{
|
9
|
-
files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"],
|
10
|
-
languageOptions: {
|
11
|
-
parserOptions: {
|
12
|
-
ecmaFeatures: {
|
13
|
-
jsx: true,
|
14
|
-
},
|
15
|
-
},
|
16
|
-
},
|
17
|
-
},
|
18
|
-
{ languageOptions: { globals: globals.browser } },
|
19
|
-
jsxA11y.flatConfigs.strict,
|
20
|
-
pluginJs.configs.recommended,
|
21
|
-
...tseslint.configs.recommended,
|
22
|
-
pluginReact.configs.flat.recommended,
|
23
|
-
];
|
data/lib/a11y_agent.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'diffy'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'json'
|
6
|
-
require 'open3'
|
7
|
-
require 'rainbow/refinement'
|
8
|
-
require 'sublayer'
|
9
|
-
require 'tty-prompt'
|
10
|
-
require_relative './fix_a11y_generator'
|
11
|
-
|
12
|
-
Diffy::Diff.default_format = :color
|
13
|
-
|
14
|
-
# Sublayer.configuration.ai_provider = Sublayer::Providers::OpenAi
|
15
|
-
# Sublayer.configuration.ai_model = "gpt-4o-mini"
|
16
|
-
|
17
|
-
# Sublayer.configuration.ai_provider = Sublayer::Providers::Gemini
|
18
|
-
# Sublayer.configuration.ai_model = "gemini-1.5-flash-latest"
|
19
|
-
|
20
|
-
Sublayer.configuration.ai_provider = Sublayer::Providers::Claude
|
21
|
-
Sublayer.configuration.ai_model = 'claude-3-haiku-20240307'
|
22
|
-
|
23
|
-
module Sublayer
|
24
|
-
module Agents
|
25
|
-
class A11yAgent < Base
|
26
|
-
using Rainbow
|
27
|
-
|
28
|
-
def initialize(file:)
|
29
|
-
@accessibility_issues = []
|
30
|
-
@issue_types = []
|
31
|
-
@file = file
|
32
|
-
@file_contents = File.read(@file)
|
33
|
-
end
|
34
|
-
|
35
|
-
trigger_on_files_changed do
|
36
|
-
['./trigger.txt']
|
37
|
-
end
|
38
|
-
|
39
|
-
check_status do
|
40
|
-
puts "🔍 Checking accessibility issues in #{@file}..."
|
41
|
-
stdout, _stderr, _status = Open3.capture3("eslint #{@file} --format stylish")
|
42
|
-
|
43
|
-
@accessibility_issues = stdout.split("\n")[2..]
|
44
|
-
@accessibility_issues = @accessibility_issues.map { |issue| issue.gsub(/\s+/, ' ').strip }
|
45
|
-
|
46
|
-
puts "🚨 Found #{@accessibility_issues.length} accessibility issues" unless @accessibility_issues.empty?
|
47
|
-
end
|
48
|
-
|
49
|
-
goal_condition do
|
50
|
-
puts '🎉 All accessibility issues have been fixed!' if @accessibility_issues.empty?
|
51
|
-
@accessibility_issues.empty?
|
52
|
-
end
|
53
|
-
|
54
|
-
step do
|
55
|
-
prompt = TTY::Prompt.new
|
56
|
-
|
57
|
-
@accessibility_issues.each do |issue|
|
58
|
-
contents = File.read(@file)
|
59
|
-
|
60
|
-
user_input = nil
|
61
|
-
fixed = nil
|
62
|
-
additional_prompt = nil
|
63
|
-
|
64
|
-
until %i[yes no].include?(user_input)
|
65
|
-
puts "🔧 Attempting a fix: #{issue}"
|
66
|
-
result = FixA11yGenerator.new(contents:, issue:,
|
67
|
-
additional_prompt:).generate
|
68
|
-
result << "\n" unless result.end_with?("\n")
|
69
|
-
|
70
|
-
Diffy::Diff.new(contents, result).each_chunk do |chunk|
|
71
|
-
case chunk
|
72
|
-
when /^\+/
|
73
|
-
print chunk.to_s.green
|
74
|
-
when /^-/
|
75
|
-
print chunk.to_s.red
|
76
|
-
else
|
77
|
-
lines = chunk.to_s.split("\n")
|
78
|
-
puts lines[0..2].join("\n")
|
79
|
-
puts '...'
|
80
|
-
puts lines[-3..].join("\n")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
choices = [
|
85
|
-
{ key: 'y', name: 'approve and continue', value: :yes },
|
86
|
-
{ key: 'n', name: 'skip this change', value: :no },
|
87
|
-
{ key: 'r', name: 'retry with optional instructions', value: :retry },
|
88
|
-
{ key: 'q', name: 'quit; stop making changes', value: :quit }
|
89
|
-
]
|
90
|
-
|
91
|
-
user_input = prompt.expand('Approve changes?', choices)
|
92
|
-
|
93
|
-
case user_input
|
94
|
-
when :yes
|
95
|
-
fixed = result
|
96
|
-
when :no
|
97
|
-
fixed = contents
|
98
|
-
when :retry
|
99
|
-
additional_prompt = prompt.ask('Additional instructions:')
|
100
|
-
fixed = nil
|
101
|
-
when :quit
|
102
|
-
puts 'Quitting...'
|
103
|
-
exit
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
contents = fixed
|
108
|
-
|
109
|
-
puts 'Writing to file...'
|
110
|
-
File.write(@file, contents)
|
111
|
-
end
|
112
|
-
|
113
|
-
puts '🎉 Done!'
|
114
|
-
puts '✅ Complete diff:'
|
115
|
-
puts Diffy::Diff.new(@file_contents, File.read(@file))
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
data/lib/fix_a11y_generator.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class FixA11yGenerator < Sublayer::Generators::Base
|
2
|
-
llm_output_adapter type: :single_string,
|
3
|
-
name: "fix_accessibility_issue_based_on_a11y_issue",
|
4
|
-
description: "Given a JSX file and an accessibility issue, generate a new JSX file with the issue fixed."
|
5
|
-
|
6
|
-
def initialize(contents:, issue:, additional_prompt: nil)
|
7
|
-
@contents = contents
|
8
|
-
@issue = issue
|
9
|
-
@additional_prompt = additional_prompt
|
10
|
-
end
|
11
|
-
|
12
|
-
def generate
|
13
|
-
super
|
14
|
-
end
|
15
|
-
|
16
|
-
def prompt
|
17
|
-
<<~PROMPT
|
18
|
-
Given the following JSX contents and an individual accessibility issue, generate a new JSX file with the individual issue fixed, leaving the rest of the contents unchanged.:
|
19
|
-
|
20
|
-
Code:
|
21
|
-
#{@contents}
|
22
|
-
|
23
|
-
Accessibility issue:
|
24
|
-
#{@issue}
|
25
|
-
|
26
|
-
Additional user instructions (if any):
|
27
|
-
#{@additional_prompt || "None"}
|
28
|
-
|
29
|
-
Return the JSX contents with the issue fixed.
|
30
|
-
PROMPT
|
31
|
-
end
|
32
|
-
end
|