File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4848(defn ^:private read-file [arguments db]
4949 (or (invalid-arguments arguments (concat (path-validations db)
5050 [[" path" fs/readable? " File $path is not readable" ]]))
51- (single-text-content (slurp (fs/file (fs/canonicalize (get arguments " path" )))))))
51+ (let [head (get arguments " head" )
52+ tail (get arguments " tail" )
53+ content (cond-> (slurp (fs/file (fs/canonicalize (get arguments " path" ))))
54+ head (->> (string/split-lines )
55+ (take head)
56+ (string/join " \n " ))
57+ tail (->> (string/split-lines )
58+ (take-last tail)
59+ (string/join " \n " )))]
60+ (single-text-content content))))
5261
5362(def definitions
5463 {" list_allowed_directories"
Original file line number Diff line number Diff line change 7070 " tool_call_output"
7171 {:role " user"
7272 :content [{:type " tool_result"
73- :tool-use-id (:id content)
73+ :tool_use_id (:id content)
7474 :content (llm-util/stringfy-tool-result content)}]}
7575 msg))
7676 past-messages)
Original file line number Diff line number Diff line change 7979 f.tools.filesystem/allowed-path? (constantly true )]
8080 ((get-in f.tools.filesystem/definitions [" read_file" :handler ])
8181 {" path" (h/file-path " /foo/qux" )}
82+ {:workspace-folders [{:uri (h/file-uri " file:///foo/bar/baz" ) :name " baz" }]})))))
83+ (testing " heading a file"
84+ (is (match?
85+ {:contents [{:type :text
86+ :error false
87+ :content " fooo\n bar" }]}
88+ (with-redefs [slurp (constantly " fooo\n bar\n baz" )
89+ fs/exists? (constantly true )
90+ fs/readable? (constantly true )
91+ f.tools.filesystem/allowed-path? (constantly true )]
92+ ((get-in f.tools.filesystem/definitions [" read_file" :handler ])
93+ {" path" (h/file-path " /foo/qux" )
94+ " head" 2 }
95+ {:workspace-folders [{:uri (h/file-uri " file:///foo/bar/baz" ) :name " baz" }]})))))
96+ (testing " tailling a file"
97+ (is (match?
98+ {:contents [{:type :text
99+ :error false
100+ :content " bar\n baz" }]}
101+ (with-redefs [slurp (constantly " fooo\n bar\n baz" )
102+ fs/exists? (constantly true )
103+ fs/readable? (constantly true )
104+ f.tools.filesystem/allowed-path? (constantly true )]
105+ ((get-in f.tools.filesystem/definitions [" read_file" :handler ])
106+ {" path" (h/file-path " /foo/qux" )
107+ " tail" 2 }
82108 {:workspace-folders [{:uri (h/file-uri " file:///foo/bar/baz" ) :name " baz" }]}))))))
Original file line number Diff line number Diff line change 2727 :name " list_allowed_directories"
2828 :input {}}]}
2929 {:role " user" :content [{:type " tool_result"
30- :tool-use-id " call-1"
30+ :tool_use_id " call-1"
3131 :content " Allowed directories: /foo/bar\n " }]}
3232 {:role " assistant" :content " I see /foo/bar" }
3333 {:role " user" :content [{:type :text :text " Thanks" :cache_control {:type " ephemeral" }}]}]
You can’t perform that action at this time.
0 commit comments