Class: Chocomint::Validator::MachineValidator
- Inherits:
-
Object
- Object
- Chocomint::Validator::MachineValidator
- Defined in:
- lib/chocomint/validator/machine_validator.rb
Overview
ツール実行結果の機械的検証 (DESIGN §3)。 LLM を呼ばずに Ruby だけで判定する。true=合格 / false=RETRY。
Instance Method Summary collapse
-
#initialize(path_guard:, max_output_bytes:) ⇒ MachineValidator
constructor
A new instance of MachineValidator.
-
#valid?(proposal, result) ⇒ Boolean
proposal: { "tool" => name, "arguments" => ... } result: { exit_code:, stdout:, stderr:, duration_ms: }.
Constructor Details
#initialize(path_guard:, max_output_bytes:) ⇒ MachineValidator
Returns a new instance of MachineValidator.
8 9 10 11 |
# File 'lib/chocomint/validator/machine_validator.rb', line 8 def initialize(path_guard:, max_output_bytes:) @path_guard = path_guard @max_output_bytes = max_output_bytes end |
Instance Method Details
#valid?(proposal, result) ⇒ Boolean
proposal: { "tool" => name, "arguments" => ... } result: { exit_code:, stdout:, stderr:, duration_ms: }
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/chocomint/validator/machine_validator.rb', line 15 def valid?(proposal, result) return false unless common_checks(result) args = proposal["arguments"] case proposal["tool"] when "write_file" then write_file_checks(args) when "read_file" then result[:stdout].to_s.bytesize >= 0 when "list_dir" then true when "append_file" then File.exist?(@path_guard.resolve(args["path"])) when "delete_file" then !File.exist?(@path_guard.resolve(args["path"])) when "make_dir" then File.directory?(@path_guard.resolve(args["path"])) when "file_info" then json?(result[:stdout]) when "run_command" then true # exit_code は common_checks で 0 を確認済み when "edit" then File.exist?(@path_guard.resolve(args["path"])) when "ls" then json?(result[:stdout]) when "grep", "glob" then true when "bash", "powershell" then true # exit_code は common_checks で確認済み else true end rescue StandardError false end |