Files
Maven/vendor/modernc.org/libc/probes.go
T
kami 6c92f85d10 feat(ecosystem): compliant Praxis/Hexis integration + vendored build
Bring the Nexus/Praxis/Hexis integration in line with
MAVEN_ECOSYSTEM_ARCHITECTURE.md:

- Praxis over HTTP: drop the in-process praxis.db open (praxisstore/
  praxistools) and call praxisd's /api/v1/tools/* API via a new praxisClient.
  Honors the "no component reads another's DB" invariant (AC#12).
  PraxisConfig.DBPath -> URL.
- Hexis confirmation gate: mutating capabilities (ReadOnly=false) now park a
  bound pendingHexis confirmation and require a spoken "да" before executing;
  read-only run immediately (AC#7, no auto attention->action).
- Capability safety: >1 verb match is ambiguous -> ask instead of firing the
  first; ambiguous Nexus resolution asks for clarification (AC#2).
- Correlation IDs on Hexis execute, recorded in the cross-service trace.
- Bug: importance arrives as JSON float64 over HTTP, not int.
- Tests: confirm-gate, decline, read-only, and ambiguity paths.

Build: vendor/ bakes in the hexis client (replace-directed at a sibling repo
outside the Docker context); Dockerfile builds from vendor and no longer
`go mod download`s the unreachable replace paths.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 20:24:33 +04:00

170 lines
2.7 KiB
Go

// Copyright 2022 The Libc Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libc // import "modernc.org/libc"
import (
"bytes"
"fmt"
"math"
"runtime/debug"
"sort"
"strings"
"sync"
"sync/atomic"
"github.com/dustin/go-humanize"
)
type PerfCounter struct {
a []int32
labels []string
enabled bool
}
func NewPerfCounter(labels []string) *PerfCounter {
return &PerfCounter{
a: make([]int32, len(labels)),
labels: labels,
enabled: true,
}
}
func (c *PerfCounter) Disable() { c.enabled = false }
func (c *PerfCounter) Enable() { c.enabled = true }
func (c *PerfCounter) Clear() {
for i := range c.a {
c.a[i] = 0
}
}
func (c *PerfCounter) Inc(n int) {
if c.enabled {
atomic.AddInt32(&c.a[n], 1)
}
}
func (c *PerfCounter) IncN(n, m int) {
if c.enabled {
atomic.AddInt32(&c.a[n], int32(m))
}
}
func (c *PerfCounter) String() string {
sv := c.enabled
defer func() { c.enabled = sv }()
c.enabled = false
var a []string
for i, v := range c.a {
if v != 0 {
a = append(a, fmt.Sprintf("%q: %s", c.labels[i], h(v)))
}
}
return fmt.Sprint(a)
}
func h(v interface{}) string {
switch x := v.(type) {
case int:
return humanize.Comma(int64(x))
case int32:
return humanize.Comma(int64(x))
case int64:
return humanize.Comma(x)
case uint32:
return humanize.Comma(int64(x))
case uint64:
if x <= math.MaxInt64 {
return humanize.Comma(int64(x))
}
return "-" + humanize.Comma(-int64(x))
}
return fmt.Sprint(v)
}
type StackCapture struct {
sync.Mutex
m map[string]int
depth int
enabled bool
}
func NewStackCapture(depth int) *StackCapture {
return &StackCapture{
m: map[string]int{},
depth: depth,
enabled: true,
}
}
func (c *StackCapture) Disable() { c.enabled = false }
func (c *StackCapture) Enable() { c.enabled = true }
func (c *StackCapture) Clear() {
c.Lock()
defer c.Unlock()
c.m = map[string]int{}
}
var (
stackCapturePrefix = []byte("\n\t")
)
func (c *StackCapture) Record() {
if !c.enabled {
return
}
b := debug.Stack()
var s strings.Builder
out:
for i := 0; len(b) > 0 && i < c.depth+2; i++ {
l := bytes.Index(b, stackCapturePrefix)
if l < 0 {
break out
}
b = b[l+len(stackCapturePrefix):]
h := bytes.IndexByte(b, '\n')
if h < 0 {
h = len(b)
}
if i > 1 {
fmt.Fprintf(&s, "\n\t%s", b[:h])
}
b = b[h:]
}
c.Lock()
defer c.Unlock()
c.m[s.String()]++
}
func (c *StackCapture) String() string {
c.Lock()
defer c.Unlock()
var b strings.Builder
var a []string
for k := range c.m {
a = append(a, k)
}
sort.Slice(a, func(i, j int) bool { return c.m[a[i]] < c.m[a[j]] })
for _, k := range a {
fmt.Fprintf(&b, "%d%s\n", c.m[k], k)
}
return b.String()
}