chore: auto-commit (799 archivos)
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+49
-5
@@ -1,11 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
"fn-registry/registry"
|
||||
)
|
||||
@@ -58,13 +62,53 @@ func cmdRun(args []string) {
|
||||
|
||||
fmt.Fprintf(os.Stderr, "[fn run] %s (%s/%s) %s\n", fn.ID, fn.Lang, fn.Kind, strings.Join(passArgs, " "))
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
os.Exit(exitErr.ExitCode())
|
||||
t0 := time.Now()
|
||||
runErr := cmd.Run()
|
||||
durationMs := time.Since(t0).Milliseconds()
|
||||
|
||||
exitCode := 0
|
||||
errClass := ""
|
||||
if runErr != nil {
|
||||
if exitErr, ok := runErr.(*exec.ExitError); ok {
|
||||
exitCode = exitErr.ExitCode()
|
||||
errClass = fmt.Sprintf("exit_%d", exitCode)
|
||||
} else {
|
||||
exitCode = 1
|
||||
errClass = "spawn_error"
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logFnRunTelemetry(registryRoot, fn.ID, durationMs, exitCode == 0, errClass)
|
||||
|
||||
if runErr != nil {
|
||||
if errClass == "spawn_error" {
|
||||
fmt.Fprintf(os.Stderr, "error: %v\n", runErr)
|
||||
}
|
||||
os.Exit(exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
// logFnRunTelemetry inserts a row into call_monitor.operations.db.calls if
|
||||
// the database is present. No-op silently otherwise — never blocks the run.
|
||||
func logFnRunTelemetry(registryRoot, functionID string, durationMs int64, success bool, errClass string) {
|
||||
callDB := filepath.Join(registryRoot, "projects", "fn_monitoring", "apps", "call_monitor", "operations.db")
|
||||
if _, err := os.Stat(callDB); err != nil {
|
||||
return
|
||||
}
|
||||
conn, err := sql.Open("sqlite3", callDB+"?_journal_mode=WAL&_busy_timeout=100")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
sessionID := os.Getenv("CLAUDE_SESSION_ID")
|
||||
successInt := 0
|
||||
if success {
|
||||
successInt = 1
|
||||
}
|
||||
_, _ = conn.Exec(
|
||||
`INSERT INTO calls (session_id, function_id, tool_used, args_hash, duration_ms, success, error_class, error_snippet, ts)
|
||||
VALUES (?, ?, 'fn_run_cli', '', ?, ?, ?, '', CAST(strftime('%s','now') AS INTEGER))`,
|
||||
sessionID, functionID, durationMs, successInt, errClass,
|
||||
)
|
||||
}
|
||||
|
||||
func resolveFunction(db *registry.DB, idOrName string) (*registry.Function, error) {
|
||||
|
||||
Reference in New Issue
Block a user