Class: Chocomint::Tools::Ls
Overview
許可ディレクトリ内のエントリを種別・サイズ付きで返す (Claude Code の LS 相当)。 list_dir が名前のみを返すのに対し、こちらは各エントリの詳細を JSON 配列で返す。
Instance Method Summary collapse
- #call(args) ⇒ Object
- #description ⇒ Object
-
#initialize(path_guard:) ⇒ Ls
constructor
A new instance of Ls.
- #name ⇒ Object
- #schema ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path_guard:) ⇒ Ls
Returns a new instance of Ls.
11 12 13 |
# File 'lib/chocomint/tools/ls.rb', line 11 def initialize(path_guard:) @path_guard = path_guard end |
Instance Method Details
#call(args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chocomint/tools/ls.rb', line 33 def call(args) measure do abs = @path_guard.resolve(args["path"]) next fail(stderr: "no such directory: #{args['path']}") unless File.directory?(abs) entries = Dir.children(abs).sort.map do |name| full = File.join(abs, name) { "name" => name, "type" => File.directory?(full) ? "directory" : "file", "size" => (File.size(full) if File.file?(full)) } end ok(stdout: JSON.generate(entries)) end end |
#description ⇒ Object
17 18 19 20 |
# File 'lib/chocomint/tools/ls.rb', line 17 def description "指定ディレクトリのエントリを name/type/size 付きの JSON 配列で返す。" \ "path は許可ディレクトリ内であること。" end |
#name ⇒ Object
15 |
# File 'lib/chocomint/tools/ls.rb', line 15 def name = "ls" |
#schema ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chocomint/tools/ls.rb', line 22 def schema { "type" => "object", "properties" => { "path" => { "type" => "string" } }, "required" => %w[path], "additionalProperties" => false } end |