Pure context-extraction functions for AI features.
FC/IS rule: file I/O happens in the caller (shell layer). These functions receive already-read content as strings/maps and transform it into context strings for prompt building.
Pure context-extraction functions for AI features. FC/IS rule: file I/O happens in the caller (shell layer). These functions receive already-read content as strings/maps and transform it into context strings for prompt building.
(derive-test-ns source-path)Derive the test namespace string from a source file path.
Example: 'libs/user/src/wagoe/user/core/validation.clj' => 'wagoe.user.core.validation-test'
Args: source-path - file path string
Returns: Test namespace string.
Derive the test namespace string from a source file path. Example: 'libs/user/src/wagoe/user/core/validation.clj' => 'wagoe.user.core.validation-test' Args: source-path - file path string Returns: Test namespace string.
(derive-test-path source-path)Derive the file path a generated test namespace belongs at.
Example: 'libs/user/src/wagoe/user/core/validation.clj' => 'libs/user/test/wagoe/user/core/validation_test.clj'
Both monorepo layouts (libs/<lib>/src/...) and generated-project layouts
(src/...) work: the first src path segment becomes test. Matching a
segment rather than a substring keeps a directory such as srcgen/ or a
namespace containing src from being rewritten.
Args: source-path - file path string
Returns:
Test file path string, or nil when source-path has no src segment —
there is no convention to apply, and guessing one would put the file
somewhere Kaocha does not look.
Derive the file path a generated test namespace belongs at. Example: 'libs/user/src/wagoe/user/core/validation.clj' => 'libs/user/test/wagoe/user/core/validation_test.clj' Both monorepo layouts (`libs/<lib>/src/...`) and generated-project layouts (`src/...`) work: the first `src` path *segment* becomes `test`. Matching a segment rather than a substring keeps a directory such as `srcgen/` or a namespace containing `src` from being rewritten. Args: source-path - file path string Returns: Test file path string, or nil when `source-path` has no src segment — there is no convention to apply, and guessing one would put the file somewhere Kaocha does not look.
(determine-test-type file-path)Determine the Kaocha test type for a source file path.
Args: file-path - string like 'libs/user/src/wagoe/user/core/validation.clj'
Returns: :unit, :integration, or :contract keyword.
Determine the Kaocha test type for a source file path. Args: file-path - string like 'libs/user/src/wagoe/user/core/validation.clj' Returns: :unit, :integration, or :contract keyword.
(extract-file-references stacktrace)Extract file:line references from a stack trace string.
Finds patterns like (file.clj:42) or file.clj:42 in the trace.
Args: stacktrace - stack trace string
Returns: Sorted distinct seq of 'filename:line' strings.
Extract file:line references from a stack trace string. Finds patterns like (file.clj:42) or file.clj:42 in the trace. Args: stacktrace - stack trace string Returns: Sorted distinct seq of 'filename:line' strings.
(extract-module-names lib-dirs)Extract existing module names from a list of directory paths.
Args: lib-dirs - seq of path strings like ["libs/user" "libs/core" ...]
Returns: Sorted seq of module name strings (basename of each path).
Extract existing module names from a list of directory paths. Args: lib-dirs - seq of path strings like ["libs/user" "libs/core" ...] Returns: Sorted seq of module name strings (basename of each path).
(extract-public-function-names source)Extract public defn names from a Clojure source string.
Args: source - Clojure source code string
Returns: Seq of function name strings.
Extract public defn names from a Clojure source string. Args: source - Clojure source code string Returns: Seq of function name strings.
(extract-schema-context schema-files)Build a schema context string from a map of schema file contents.
Args: schema-files - map of {relative-path source-str} for schema.clj files
Returns: A human-readable summary string of table names and fields found.
Build a schema context string from a map of schema file contents.
Args:
schema-files - map of {relative-path source-str} for schema.clj files
Returns:
A human-readable summary string of table names and fields found.(filter-clj-sources all-files)From a map of {path content}, keep only .clj source files under src/.
Args: all-files - map of {path content-str}
Returns: Filtered map.
From a map of {path content}, keep only .clj source files under src/.
Args:
all-files - map of {path content-str}
Returns:
Filtered map.(ns-form-aliases ns-form){ns-sym alias-sym} for the requires that name an alias.
{ns-sym alias-sym} for the requires that name an alias.
(ns-form-requires ns-form)The namespaces an ns form requires, in order.
The namespaces an ns form requires, in order.
(render-namespace-apis aliases apis)The public API of each required namespace, named the way the source refers to it, for the test generator's prompt. The model invented protocol names when it only saw the source (BOU-572).
apis is [{:ns :protocols [{:name :methods [{:name :arglists}]}]
:vars [{:name :arglists}] :error}].
The public API of each required namespace, named the way the source refers
to it, for the test generator's prompt. The model invented protocol names
when it only saw the source (BOU-572).
`apis` is [{:ns :protocols [{:name :methods [{:name :arglists}]}]
:vars [{:name :arglists}] :error}].(summarise-stacktrace stacktrace)(summarise-stacktrace stacktrace n)Return the first N lines of a stack trace (to fit context window).
Args: stacktrace - full stack trace string n - max number of lines (default 60)
Returns: Truncated string.
Return the first N lines of a stack trace (to fit context window). Args: stacktrace - full stack trace string n - max number of lines (default 60) Returns: Truncated string.
(truncate-source source)(truncate-source source max-lines)Truncate a source file string to max-lines lines to fit context.
Args: source - source code string max-lines - maximum number of lines to keep (default 150)
Returns: Possibly truncated string with a note if truncated.
Truncate a source file string to max-lines lines to fit context. Args: source - source code string max-lines - maximum number of lines to keep (default 150) Returns: Possibly truncated string with a note if truncated.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |