faure 0.2.0 → 0.2.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 +4 -4
- data/lib/faure/agent.rb +13 -6
- data/lib/faure/codeur.rb +23 -8
- data/lib/faure/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fedb51ca95dcbf138d793cdff8baa004c83e387c36227614cfbb153c428c71e7
|
|
4
|
+
data.tar.gz: 0dd90f77c0ff1beaec7b769f2801de8cd8c1813abbdd87530db7124c8df36837
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 382459631e6b8c9656f10458144102833aae453e67e4421540d72c6a00f87b5b18aa390d591ca263ffe3f695eaf1af22acce4dc9bca948ae56f9c30504ea7be1
|
|
7
|
+
data.tar.gz: 48b1e12767c69deb1a44d7f83f0f1610269359f82930c3cc27c921fcca016207d7eebe35b07a4e704280c6ad7ce4fd9bdea9a47bc28c775204e620ca7de0ec21
|
data/lib/faure/agent.rb
CHANGED
|
@@ -11,14 +11,21 @@ module Faure
|
|
|
11
11
|
class Agent
|
|
12
12
|
|
|
13
13
|
def initialize
|
|
14
|
-
|
|
14
|
+
raw = ENV.fetch('TRIGGER_PAYLOAD', '{}')
|
|
15
|
+
raw = File.read(raw) if File.exist?(raw)
|
|
16
|
+
payload = begin
|
|
17
|
+
JSON.parse(raw)
|
|
18
|
+
rescue JSON::ParserError => e
|
|
19
|
+
abort "[faure] TRIGGER_PAYLOAD invalide : #{e.message}"
|
|
20
|
+
end
|
|
15
21
|
@issue_iid = payload.dig('issue', 'iid').to_s
|
|
16
22
|
end
|
|
17
23
|
|
|
18
24
|
def run
|
|
19
25
|
branch_name = "feature/issue-#{@issue_iid}"
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
system("git fetch origin #{branch_name} #{Config::TARGET_BRANCH}")
|
|
27
|
+
diff = `git diff origin/#{Config::TARGET_BRANCH}...origin/#{branch_name} --stat`
|
|
28
|
+
diff_full = `git diff origin/#{Config::TARGET_BRANCH}...origin/#{branch_name}`
|
|
22
29
|
|
|
23
30
|
if diff.strip.empty?
|
|
24
31
|
puts '[faure:agent] Aucun diff détecté, abandon.'
|
|
@@ -61,9 +68,9 @@ module Faure
|
|
|
61
68
|
|
|
62
69
|
def mr_system_prompt
|
|
63
70
|
if Config::LANG == 'fr'
|
|
64
|
-
'Tu es un assistant qui rédige des descriptions de Merge Request claires et concises en français. Réponds uniquement avec le texte de la description, sans balises.'
|
|
71
|
+
'/nothink Tu es un assistant qui rédige des descriptions de Merge Request claires et concises en français. Réponds uniquement avec le texte de la description, sans balises.'
|
|
65
72
|
else
|
|
66
|
-
'You are an assistant that writes clear and concise Merge Request descriptions in English. Reply only with the description text, no markup.'
|
|
73
|
+
'/nothink You are an assistant that writes clear and concise Merge Request descriptions in English. Reply only with the description text, no markup.'
|
|
67
74
|
end
|
|
68
75
|
end
|
|
69
76
|
|
|
@@ -72,7 +79,7 @@ module Faure
|
|
|
72
79
|
req = Net::HTTP::Post.new(uri)
|
|
73
80
|
req['Content-Type'] = 'application/json'
|
|
74
81
|
req.body = { model: Config::AGENT_MODEL, messages: messages, max_tokens: max_tokens }.to_json
|
|
75
|
-
res = Net::HTTP.start(uri.host, uri.port) { |h| h.request(req) }
|
|
82
|
+
res = Net::HTTP.start(uri.host, uri.port, read_timeout: 300) { |h| h.request(req) }
|
|
76
83
|
JSON.parse(res.body).dig('choices', 0, 'message', 'content')
|
|
77
84
|
end
|
|
78
85
|
|
data/lib/faure/codeur.rb
CHANGED
|
@@ -12,7 +12,13 @@ module Faure
|
|
|
12
12
|
class Codeur
|
|
13
13
|
|
|
14
14
|
def initialize
|
|
15
|
-
|
|
15
|
+
raw = ENV.fetch('TRIGGER_PAYLOAD', '{}')
|
|
16
|
+
raw = File.read(raw) if File.exist?(raw)
|
|
17
|
+
payload = begin
|
|
18
|
+
JSON.parse(raw)
|
|
19
|
+
rescue JSON::ParserError => e
|
|
20
|
+
abort "[faure] TRIGGER_PAYLOAD invalide : #{e.message}"
|
|
21
|
+
end
|
|
16
22
|
@note = payload.dig('object_attributes', 'note') || ''
|
|
17
23
|
@noteable_type = payload.dig('object_attributes', 'noteable_type')
|
|
18
24
|
@author_id = payload.dig('user', 'id').to_i
|
|
@@ -84,6 +90,7 @@ module Faure
|
|
|
84
90
|
lang_instruction = Config::LANG == 'fr' ? 'Réponds en français.' : 'Reply in English.'
|
|
85
91
|
agents_section = @agents_md ? "\n## Project conventions\n\n#{@agents_md}\n" : ''
|
|
86
92
|
<<~SYSTEM
|
|
93
|
+
/nothink
|
|
87
94
|
Tu es un agent codeur expert. Tu reçois une tâche de développement et tu dois produire les modifications de fichiers nécessaires.
|
|
88
95
|
#{lang_instruction}
|
|
89
96
|
#{agents_section}
|
|
@@ -160,12 +167,20 @@ module Faure
|
|
|
160
167
|
puts " → #{f[:path]}"
|
|
161
168
|
end
|
|
162
169
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
system("git
|
|
168
|
-
|
|
170
|
+
gitlab_host = URI(Config::GITLAB_URL).host
|
|
171
|
+
project_path = ENV.fetch('CI_PROJECT_PATH')
|
|
172
|
+
push_url = "https://oauth2:#{Config::API_TOKEN}@#{gitlab_host}/#{project_path}.git"
|
|
173
|
+
|
|
174
|
+
abort '[faure] git config email failed' unless system("git config user.email 'faure@liant.dev'")
|
|
175
|
+
abort '[faure] git config name failed' unless system("git config user.name 'Faure Codeur'")
|
|
176
|
+
abort '[faure] git remote set-url failed' unless system("git remote set-url origin #{push_url}")
|
|
177
|
+
abort '[faure] git checkout failed' unless system("git checkout -B #{branch_name}")
|
|
178
|
+
abort '[faure] git add failed' unless system('git add -A')
|
|
179
|
+
abort '[faure] git commit failed' unless system("git commit -m 'faure(issue-#{@issue_iid}): modifications automatiques'")
|
|
180
|
+
unless system("git push origin #{branch_name} --force-with-lease") ||
|
|
181
|
+
system("git push origin #{branch_name} --force")
|
|
182
|
+
abort '[faure] git push failed'
|
|
183
|
+
end
|
|
169
184
|
puts "[faure] Push sur #{branch_name} effectué"
|
|
170
185
|
end
|
|
171
186
|
|
|
@@ -206,7 +221,7 @@ module Faure
|
|
|
206
221
|
req = Net::HTTP::Post.new(uri)
|
|
207
222
|
req['Content-Type'] = 'application/json'
|
|
208
223
|
req.body = { model: model, messages: messages, max_tokens: max_tokens }.to_json
|
|
209
|
-
res = Net::HTTP.start(uri.host, uri.port) { |h| h.request(req) }
|
|
224
|
+
res = Net::HTTP.start(uri.host, uri.port, read_timeout: 600) { |h| h.request(req) }
|
|
210
225
|
data = JSON.parse(res.body)
|
|
211
226
|
data.dig('choices', 0, 'message', 'content') or raise "Réponse inattendue : #{res.body}"
|
|
212
227
|
end
|
data/lib/faure/version.rb
CHANGED