From bf22f8aa3b8d91e0ce44bff0b01fac50d85d2269 Mon Sep 17 00:00:00 2001 From: Jack Chakany Date: Sun, 15 Nov 2026 23:17:10 +0100 Subject: [PATCH 1/2] Accept decimal text for integer tool arguments A transport can send a schema-declared integer as decimal text, and the tool call then fails with 'must be an integer'. Coerce exact decimal text for integer-declared arguments in the shared argument correction pass, and stop the vector branch from swallowing strings, which are vectors. Cover both spellings in the argument correction test. #AUTO-ff2ac79cab --- src/tools/registry.lisp | 43 +++++++++++++++++++++++++++++++++++++---- tests/tool-tests.lisp | 21 +++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/tools/registry.lisp b/src/tools/registry.lisp index b082e12d1..237a88a94 100644 --- a/src/tools/registry.lisp +++ b/src/tools/registry.lisp @@ -1347,19 +1347,54 @@ Each element is a cons of the declared name and its subschema." (collect schema))) (nreverse properties))) -(-> tool--corrected-value (json-object t) t) +(-> tool--integer-schema-p (t) boolean) +(defun tool--integer-schema-p (schema) + "Return true when SCHEMA declares the JSON integer type alone." + (and (json-object-p schema) + (equal (json-get schema "type") "integer") + t)) + +(-> tool--decimal-integer-text-p (string) boolean) +(defun tool--decimal-integer-text-p (text) + "Return true when TEXT is one plain decimal integer and nothing else." + (let ((start (if (and (plusp (length text)) + (member (char text 0) '(#\+ #\-) :test #'char=)) + 1 + 0))) + (and (< start (length text)) + (loop for index from start below (length text) + always (digit-char-p (char text index))) + t))) + +(-> tool--declared-scalar (t t) t) +(defun tool--declared-scalar (schema value) + "Return VALUE in the JSON type SCHEMA declares when its text form is exact. + +A transport can carry a declared integer as decimal text. Accept that spelling +so the call executes, and leave every other value unchanged so a malformed +number still reaches the argument diagnostic." + (if (and (stringp value) + (tool--integer-schema-p schema) + (tool--decimal-integer-text-p value)) + (parse-integer value) + value)) + +(-> tool--corrected-value (t t) t) (defun tool--corrected-value (schema value) - "Return VALUE with underscore-spelled names corrected against SCHEMA." + "Return VALUE corrected against SCHEMA. + +A declared name accepts its underscore spelling, and a declared integer accepts +its own decimal text." (cond ((and (json-object-p schema) (json-object-p value)) (tool--corrected-object (tool--schema-properties schema) value)) - ((and (json-object-p schema) (vectorp value)) + ((and (json-object-p schema) (vectorp value) (not (stringp value))) (let ((items (json-get schema "items"))) (if (json-object-p items) (map 'simple-vector (lambda (element) (tool--corrected-value items element)) value) value))) (t - value))) + (tool--declared-scalar schema value)))) (-> tool--corrected-object (list json-object) json-object) (defun tool--corrected-object (properties object) diff --git a/tests/tool-tests.lisp b/tests/tool-tests.lisp index 6e79eb9f9..864bfb510 100644 --- a/tests/tool-tests.lisp +++ b/tests/tool-tests.lisp @@ -735,7 +735,8 @@ (received nil) (schema (tool-object-schema (json-object - "path" (tool-string-property "Path") + "path" (tool-string-property "Path") + "count" (tool-integer-property "Count") "options" (tool-object-schema (json-object "deep-name" (tool-string-property "Deep name")) '("deep-name")) @@ -771,6 +772,24 @@ "nested object names are corrected") (test-assert (equal (json-get (aref (json-get received "rows") 0) "row-id") "1") "array item names are corrected")) + (let ((result (tool-registry-execute-call + registry + (json-object "namespace" "probe" "name" "contract" + "arguments" "{\"path\":\"workspace:probe\",\"count\":\"7\"}") + context))) + (test-assert (tool-result-success-p result) + "a declared integer accepts its decimal text") + (test-assert (eql (json-get received "count") 7) + "the decimal text becomes an integer argument")) + (let ((result (tool-registry-execute-call + registry + (json-object "namespace" "probe" "name" "contract" + "arguments" "{\"path\":\"workspace:probe\",\"count\":\"7.5\"}") + context))) + (test-assert (tool-result-success-p result) + "a non-integer spelling still reaches dispatch") + (test-assert (equal (json-get received "count") "7.5") + "only exact decimal text becomes an integer")) (let ((result (tool-registry-execute-call registry (json-object "namespace" "probe" "name" "contract" From ef8a8cfcb83177bb715ecbb5866a3431e2dea653 Mon Sep 17 00:00:00 2001 From: Jack Chakany Date: Sun, 15 Nov 2026 23:47:45 +0100 Subject: [PATCH 2/2] Accept JSON boolean text for boolean tool arguments The same transport that carries a declared integer as decimal text can carry a declared boolean as the text true or false. Coerce those two exact spellings in the shared argument correction pass so the call executes, and leave every other spelling unchanged. Cover both spellings in the argument correction test. #AUTO-ff2ac79cab --- src/tools/registry.lisp | 43 +++++++++++++++++++++++++++++++---------- tests/tool-tests.lisp | 19 ++++++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/tools/registry.lisp b/src/tools/registry.lisp index 237a88a94..43e27c50d 100644 --- a/src/tools/registry.lisp +++ b/src/tools/registry.lisp @@ -1366,25 +1366,48 @@ Each element is a cons of the declared name and its subschema." always (digit-char-p (char text index))) t))) +(-> tool--boolean-schema-p (t) boolean) +(defun tool--boolean-schema-p (schema) + "Return true when SCHEMA declares the JSON boolean type alone." + (and (json-object-p schema) + (equal (json-get schema "type") "boolean") + t)) + +(-> tool--declared-boolean (string) t) +(defun tool--declared-boolean (text) + "Return TEXT as a JSON boolean when it spells one, else TEXT unchanged." + (cond + ((string= text "true") + t) + ((string= text "false") + (json-false)) + (t + text))) + (-> tool--declared-scalar (t t) t) (defun tool--declared-scalar (schema value) "Return VALUE in the JSON type SCHEMA declares when its text form is exact. -A transport can carry a declared integer as decimal text. Accept that spelling -so the call executes, and leave every other value unchanged so a malformed -number still reaches the argument diagnostic." - (if (and (stringp value) - (tool--integer-schema-p schema) - (tool--decimal-integer-text-p value)) - (parse-integer value) - value)) +A transport can carry a declared integer as decimal text or a declared boolean +as its JSON spelling. Accept those spellings so the call executes, and leave +every other value unchanged so a malformed value still reaches the argument +diagnostic." + (cond + ((and (stringp value) + (tool--integer-schema-p schema) + (tool--decimal-integer-text-p value)) + (parse-integer value)) + ((and (stringp value) (tool--boolean-schema-p schema)) + (tool--declared-boolean value)) + (t + value))) (-> tool--corrected-value (t t) t) (defun tool--corrected-value (schema value) "Return VALUE corrected against SCHEMA. -A declared name accepts its underscore spelling, and a declared integer accepts -its own decimal text." +A declared name accepts its underscore spelling, a declared integer accepts its +own decimal text, and a declared boolean accepts its JSON spelling." (cond ((and (json-object-p schema) (json-object-p value)) (tool--corrected-object (tool--schema-properties schema) value)) diff --git a/tests/tool-tests.lisp b/tests/tool-tests.lisp index 864bfb510..e5feb7c1f 100644 --- a/tests/tool-tests.lisp +++ b/tests/tool-tests.lisp @@ -737,6 +737,7 @@ (json-object "path" (tool-string-property "Path") "count" (tool-integer-property "Count") + "flag" (tool-boolean-property "Flag") "options" (tool-object-schema (json-object "deep-name" (tool-string-property "Deep name")) '("deep-name")) @@ -790,6 +791,24 @@ "a non-integer spelling still reaches dispatch") (test-assert (equal (json-get received "count") "7.5") "only exact decimal text becomes an integer")) + (let ((result (tool-registry-execute-call + registry + (json-object "namespace" "probe" "name" "contract" + "arguments" "{\"path\":\"workspace:probe\",\"flag\":\"true\"}") + context))) + (test-assert (tool-result-success-p result) + "a declared boolean accepts its JSON spelling") + (test-assert (json-true-p (json-get received "flag")) + "the true spelling becomes a JSON boolean")) + (let ((result (tool-registry-execute-call + registry + (json-object "namespace" "probe" "name" "contract" + "arguments" "{\"path\":\"workspace:probe\",\"flag\":\"maybe\"}") + context))) + (test-assert (tool-result-success-p result) + "a non-boolean spelling still reaches dispatch") + (test-assert (equal (json-get received "flag") "maybe") + "only exact JSON spellings become booleans")) (let ((result (tool-registry-execute-call registry (json-object "namespace" "probe" "name" "contract"