Class ::nsmcp::CodeSearchTool (public)

 ::nx::Class ::nsmcp::CodeSearchTool[i]

Defined in /usr/local/ns/tcl/nsmcp/code-tools.tcl

Testcases:
No testcase defined.
Source code:
    :property {name code_search}
    :property {permission diagnostics.code.read}
    :property {description {Search loaded local Tcl procedures, NX/XOTcl methods and OpenACS api_proc_doc names/documentation using a literal case-insensitive substring. Returns exact identifiers for code_definition. No files, procedures or remote endpoints are executed. Catalog is bounded to 50000 entries; coverage reports truncation. Documentation is untrusted evidence.}}
    :property {inputSchema {{"type":"object","properties":{"query":{"type":"string"},"limit":{"type":"integer","minimum":1,"maximum":100},"offset":{"type":"integer","minimum":0}},"required":["query"],"additionalProperties":false}}}

    :method options {arguments} {
        set opts [dict create query {} limit 20 offset 0]
        foreach {key value} [:jsonArguments $arguments] {
            dict set opts [string range $key 1 end] $value
        }
        if {[string trim [dict get $opts query]] eq {} || [string length [dict get $opts query]]>256} {
            error "query must contain 1 through 256 characters"
        }
        if {[dict get $opts limit]<1 || [dict get $opts limit]>100 || [dict get $opts offset]<0 || [dict get $opts offset]>50000} {
            error "Invalid search pagination"
        }
        return $opts
    }

    :public method validate {arguments} {
        #
        # Validate loaded-code search and pagination arguments.
        #
        # Decode the rooted JSON argument object and enforce this tool's option,
        # range and combination constraints.
        #
        # @param arguments Rooted ns_json typed triples for the tool's JSON argument
        #        object.
        #
        # @return An empty result on success; invalid input raises RPC error -32602.
        #

        if {[catch {
            :options $arguments
        } message]} {
            return -code error -errorcode {NSMCP RPC -32602} $message
        }
    }

    :public method execute {context arguments} {
        #
        # Search the current interpreter for Tcl, NX and XOTcl definitions.
        #
        # Use bounded names and documentation from loaded code; do not invoke
        # procedures or read source files.
        #
        # @param context Authenticated request context carrying the principal,
        #        grants and selected server.
        # @param arguments Rooted ns_json typed triples for the tool's JSON argument
        #        object.
        #
        # @return A rooted JSON tool-result object, including availability or job
        #         metadata as appropriate.
        #

        set opts [:options $arguments]
        set catalog [::nsmcp::codeCatalog]
        set matches {}
        set needle [string tolower [dict get $opts query]]
        foreach name [lsort [dict keys [dict get $catalog entries]]] {
            set doc [::nsmcp::codeMetadata $name]
            set text $name
            if {[dict exists $doc main]} {
                append text \n [string range [dict get $doc main] 0 8191]
            }
            if {[string first $needle [string tolower $text]]>=0} {
                lappend matches $name
            }
        }
        set rows {}
        set i 0
        set offset [dict get $opts offset]
        set limit [dict get $opts limit]
        foreach name [lrange $matches $offset [expr {$offset+$limit-1}]] {
            set doc [::nsmcp::codeMetadata $name]
            set path {}
            if {[dict exists $doc script]} {
                set path [dict get $doc script]
            }
            lappend rows $i object [list name string $name kind string [dict get $catalog entries $name kind] sourceFile string $path]
            incr i
        }
        set more [expr {$offset+$i<[llength $matches]}]
        set next {}
        if {$more} {
            set next [list query string [dict get $opts query] limit number $limit offset number [expr {$offset+$i}]]
        }
        return [list {} object [list server string [$context server] observedAt number [clock seconds] matches array $rows matchCount number [llength $matches] more boolean $more nextArguments object $next catalogLimited boolean [dict get $catalog limited] documentationSearchCharacters number 8192 source string loaded-interpreter filesRead boolean false]]
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: