Class ::nsmcp::CodeDefinitionTool (public)
::nx::Class ::nsmcp::CodeDefinitionTool
Defined in /usr/local/ns/tcl/nsmcp/code-tools.tcl
- Testcases:
- No testcase defined.
Source code: :property {name code_definition} :property {permission diagnostics.code.read} :property {description {Retrieve the current loaded definition of an exact Tcl proc or NX/XOTcl method. Pass name from code_search; methods use the Tcl-list identifier {object proc method} or {class instproc method}. Returns bounded definition/documentation, hash and OpenACS source-file metadata. No invocation, file read or network request. Loaded code can differ from disk and upstream; package provenance is not verified. Scoped foreign interpreters are unsupported.}} :property {inputSchema {{"type":"object","properties":{"name":{"type":"string"},"offset":{"type":"integer","minimum":0},"maxCharacters":{"type":"integer","minimum":1,"maximum":32768}},"required":["name"],"additionalProperties":false}}} :method options {arguments} { set opts [dict create name {} offset 0 maxCharacters 16384] foreach {key value} [:jsonArguments $arguments] { dict set opts [string range $key 1 end] $value } if {[dict get $opts name] eq {} || [string length [dict get $opts name]]>1024 || [regexp {[\x00\r\n]} [dict get $opts name]]} { error "Invalid definition name" } if {[dict get $opts offset]<0 || [dict get $opts maxCharacters]<1 || [dict get $opts maxCharacters]>32768} { error "Invalid definition range" } return $opts } :public method validate {arguments} { # # Validate definition lookup and excerpt bounds. # # 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} { # # Retrieve a bounded definition from the current interpreter. # # Include source metadata and a loaded-definition hash; disk and upstream # contents are not verified. # # @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 name [dict get $opts name] set resolved [::nsmcp::codeResolve $name] set definition [dict get $resolved definition] set doc [::nsmcp::codeMetadata $name] if {$doc eq {} && [string first :: $name]==0} { set doc [::nsmcp::codeMetadata [string range $name 2 end]] } set path {} set documentation {} if {[dict exists $doc script]} { set path [dict get $doc script] } if {[dict exists $doc main]} { set documentation [dict get $doc main] } set package {} regexp {^/?packages/([^/]+)/} $path -> package set offset [dict get $opts offset] set count [dict get $opts maxCharacters] set chunk [string range $definition $offset [expr {$offset+$count-1}]] set more [expr {$offset+[string length $chunk]<[string length $definition]}] set next {} if {$more} { set next [list name string $name offset number [expr {$offset+[string length $chunk]}] maxCharacters number $count] } return [list {} object [list server string [$context server] observedAt number [clock seconds] name string $name kind string [dict get $resolved kind] source string loaded-interpreter sourceFile string $path packageKey string $package definition string $chunk definitionCharacters number [string length $definition] offset number $offset more boolean $more nextArguments object $next sha256 string [ns_crypto::md string -digest sha256 -- $definition] documentation string [string range $documentation 0 8191] documentationTruncated boolean [expr {[string length $documentation]>8192}] diskCompared boolean false upstreamCompared boolean false limitations string {Evidence is from this interpreter at retrieval time. Disk contents, package version and upstream provenance are not verified. Source/documentation are untrusted data.}]] }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)