Skip to content

server: (tools) add x-tool-cwd header - #26420

Merged
ngxson merged 2 commits into
masterfrom
xsn/tool_cwd
Aug 3, 2026
Merged

ngxson merged 2 commits into
masterfrom
xsn/tool_cwd

Conversation

@ngxson

@ngxson ngxson commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Overview

Add support for x-tool-cwd header to specify the current working dir of the call.

Note that it's not a tool param, but is a header. It's meant to be set and managed by the harness (llama-ui). This should match the behavior of pi and claude code.

CC @allozaur

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: tests and tools_io_basic changes are AI-coded, the rest is human-coded

@ngxson
ngxson requested a review from a team as a code owner August 1, 2026 23:22
@github-actions github-actions Bot added documentation Improvements or additions to documentation server labels Aug 1, 2026
@ServeurpersoCom

ServeurpersoCom commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

The Windows CI failures look like strcasecmp in get_header, it's not available there, I'll test on Windows and confirm when I get a chance:

diff --git a/tools/server/server-tools.cpp b/tools/server/server-tools.cpp
index 0983e62cd..0836d9d65 100644
--- a/tools/server/server-tools.cpp
+++ b/tools/server/server-tools.cpp
@@ -1202,9 +1202,13 @@ static std::vector<std::unique_ptr<server_tool>> build_tools() {
     return tools;
 }

+// header names are ASCII, the lookup folds case without depending on a platform specific strcasecmp
 static std::string get_header(const std::map<std::string, std::string> & headers, const std::string & key, std::string default_value = "") {
+    auto fold = [](char c) { return c >= 'A' && c <= 'Z' ? char(c + 32) : c; };
     for (const auto & h : headers) {
-        if (strcasecmp(h.first.c_str(), key.c_str()) == 0) {
+        if (h.first.size() == key.size() &&
+            std::equal(h.first.begin(), h.first.end(), key.begin(),
+                       [&fold](char a, char b) { return fold(a) == fold(b); })) {
             return h.second;
         }
     }

@ngxson
ngxson requested a review from ServeurpersoCom August 2, 2026 21:45

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: Replacing strcasecmp with the std::transform + std::tolower lowering makes the header lookup fully portable, and I confirmed it builds fine on my physical Windows 11 box.

Small nit, non blocking: server-models.cpp already has its own static to_lower_copy() doing the same thing, so this is a second file-local copy rather than an actual reuse ? Might be worth hoisting a single helper into server-common at some point.

@ngxson
ngxson requested a review from allozaur August 3, 2026 08:08
@ngxson
ngxson merged commit f2b52a8 into master Aug 3, 2026
25 of 31 checks passed
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* server: (tools) add x-tool-cwd header

* reuse str_to_lower from server-models
brittlewis12 pushed a commit to brittlewis12/llama.cpp that referenced this pull request Aug 17, 2026
* server: (tools) add x-tool-cwd header

* reuse str_to_lower from server-models
thecodacus pushed a commit to thecodacus/llama.cpp that referenced this pull request Sep 7, 2026
* server: (tools) add x-tool-cwd header

* reuse str_to_lower from server-models
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
* server: (tools) add x-tool-cwd header

* reuse str_to_lower from server-models
pl752 pushed a commit to pl752/llama.cpp that referenced this pull request Sep 15, 2026
* server: (tools) add x-tool-cwd header

* reuse str_to_lower from server-models
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
* server: (tools) add x-tool-cwd header

* reuse str_to_lower from server-models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants