Class ::nsmcp::CodexLogSummaryTool

::nsmcp::CodexLogSummaryTool[i] create ... \
           [ -adminExample (default "") ] \
           [ -adminSummary (default "") ] \
           [ -description (default "Summarize Codex app-server ERROR and WARN diagnostic records from its configured read-only SQLite pool. Defaults to the last ten minutes. Supply both from and to as Unix seconds for an exact half-open window of at most one day. Returned examples are newest first and bounded.") ] \
           [ -inputSchema (default " {"type":"object","properties":{ "from":{"type":"integer","minimum":0}, "to":{"type":"integer","minimum":1}, "lastMinutes":{"type":"integer","minimum":1,"maximum":1440}, "limit":{"type":"integer","minimum":1,"maximum":50} },"additionalProperties":false} ") ] \
           [ -name (default "codex_log_summary") ] \
           [ -outputSchema (default "") ] \
           [ -permission (default "diagnostics.logs.read") ] \
           [ -pool:required pool:required ] \
           [ -redactor:required redactor:required ]

Defined in /usr/local/ns/tcl/nsmcp/codex-logs.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nsmcp::Tool[i]
::nx::Class create ::nsmcp::CodexLogSummaryTool \
     -superclass ::nsmcp::Tool

Methods (to be applied on instances)

  • dependenciesPresent (scripted, public)

     <instance of nsmcp::CodexLogSummaryTool[i]> dependenciesPresent

    Testcases:
    No testcase defined.
    return [expr {[:cget -pool] in [ns_db pools]}]
  • execute (scripted, public)

     <instance of nsmcp::CodexLogSummaryTool[i]> execute context \
        arguments

    Read ERROR/WARN counts and bounded examples from the Codex log DB.

    Parameters:
    context (required)
    Authorized request context.
    arguments (required)
    Validated rooted JSON argument triples.
    Returns:
    Rooted JSON result with counts and bounded examples.

    Testcases:
    No testcase defined.
    lassign [:options $arguments] from to limit
    set samples {}
    set sampleCount 0
    ns_db withhandle -pool [:cget -pool] -timeout 1s db {
        if {[ns_db dbtype $db] ne "sqlite"} {
            error "Codex log pool must use nsdbsqlite"
        }
        set row [ns_db 1row $db "
            SELECT COUNT(*) AS total,
                   COALESCE(SUM(CASE WHEN level='ERROR' THEN 1 ELSE 0 END),0) AS errors,
                   COALESCE(SUM(CASE WHEN level='WARN' THEN 1 ELSE 0 END),0) AS warnings
              FROM logs
             WHERE ts >= $from AND ts < $to
               AND level IN ('ERROR','WARN')"]
        set total [ns_set get $row total]
        set errors [ns_set get $row errors]
        set warnings [ns_set get $row warnings]
        ns_set free $row
        set rows [ns_db select $db "
            SELECT ts, level, target, feedback_log_body
              FROM logs
             WHERE ts >= $from AND ts < $to
               AND level IN ('ERROR','WARN')
             ORDER BY ts DESC, ts_nanos DESC
             LIMIT $limit"]
        try {
            while {[ns_db getrow $db $rows]} {
                set body [[:cget -redactor] message [ns_set get $rows feedback_log_body]]
                set clipped [expr {[string length $body] > 1024}]
                lappend samples $sampleCount object [list  timestamp number [ns_set get $rows ts]  level string [ns_set get $rows level]  target string [ns_set get $rows target]  message string [string range $body 0 1023] truncated boolean $clipped]
                incr sampleCount
            }
        } finally {
            ns_set free $rows
        }
    }
    return [list {} object [list available boolean true source string codex-sqlite  from number $from to number $to total number $total  errors number $errors warnings number $warnings  returned number $sampleCount omitted number [expr {$total - $sampleCount}]  records array $samples]]
  • validate (scripted, public)

     <instance of nsmcp::CodexLogSummaryTool[i]> validate arguments

    Validate a bounded Codex diagnostic time window and result limit.

    Parameters:
    arguments (required)
    Rooted JSON argument triples.
    Returns:
    No meaningful value; invalid input raises RPC -32602.

    Testcases:
    No testcase defined.
    :options $arguments