Index
axm_echo
axm-echo.
Similarity & echo detection over code corpora (numpy/scikit-learn).
EchoCodeTool
Bases: AXMTool
Detect cross-package code echoes (intent-equivalent duplicates).
Registered as echo_code via the axm.tools entry point.
Source code in packages/axm-echo/src/axm_echo/tools.py
| Python | |
|---|---|
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
name
property
Return the tool name for registry lookup.
execute(*, backend='st', threshold=PAIR_THRESHOLD, top_n=_DEFAULT_TOP_N, max_cluster_size=MAX_CLUSTER_SIZE, **kwargs)
Cluster cross-package echoes over the configured corpus.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Backend
|
Embedding backend -- |
'st'
|
threshold
|
float
|
Minimum cosine for a candidate pair. |
PAIR_THRESHOLD
|
top_n
|
int
|
Show at most this many of the nearest non-acknowledged clusters; the total count stays visible in the metadata. |
_DEFAULT_TOP_N
|
max_cluster_size
|
int
|
Reject components larger than this as union-find over-merges (structural conformity, not a duplicate echo). |
MAX_CLUSTER_SIZE
|
Returns:
| Type | Description |
|---|---|
ToolResult
|
ToolResult with the bounded |
ToolResult
|
|
ToolResult
|
pairs), the live/shown/actionable counts, and |
Source code in packages/axm-echo/src/axm_echo/tools.py
Symbol
dataclass
A single public symbol projected into the corpus.
Source code in packages/axm-echo/src/axm_echo/corpus.py
embed_text
property
Unified embed text: docstring if present, else code/signature.
has_doc
property
Whether the symbol carries a non-empty docstring.
as_dict()
Flat dict view (qualname, package, signature, embed_text, ...).
Source code in packages/axm-echo/src/axm_echo/corpus.py
code_tokens(src)
Tokenize code text for the TF-IDF backend.
Lowercases identifiers, splits camelCase and snake_case into
sub-tokens, and appends structural keyword hints weighted by frequency
so control-flow shape contributes to the vector.
Source code in packages/axm-echo/src/axm_echo/embedding.py
config_path()
Return the path to the echo config (~/axm/echo.toml).
Does not check existence; callers degrade gracefully when absent.
discover_package_roots()
Discover every package directory across the configured scope.
Walks each workspace root from :func:axm_echo.scope.load_scope,
covering both the <ws>/packages/<pkg> convention and the flat
other/<pkg> layout. The set of roots is data-driven (no frozen
package list), so newly added packages are picked up automatically
(AC4).
Returns:
| Type | Description |
|---|---|
list[Path]
|
Sorted, de-duplicated package directories. |
Source code in packages/axm-echo/src/axm_echo/corpus.py
embed(texts, *, backend='tfidf')
Embed texts into a dense matrix via the chosen backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
Sequence[str]
|
Texts to embed (one row per text). |
required |
backend
|
Backend
|
|
'tfidf'
|
Returns:
| Type | Description |
|---|---|
NDArray[float64]
|
A |
NDArray[float64]
|
normalized; |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in packages/axm-echo/src/axm_echo/embedding.py
extract_monorepo()
Extract public symbols across every discovered package (corpus).
Returns:
| Type | Description |
|---|---|
list[SymbolDict]
|
The concatenated symbol corpus for the configured scope. |
Source code in packages/axm-echo/src/axm_echo/corpus.py
| Python | |
|---|---|
extract_package(pkg_root)
Extract every public function/class of a package via axm-ast.
"Public" follows the axm-ast convention: a symbol exported in the
module's __all__ when present, else any module-level name without
a leading underscore. Test files and empty __init__ files are
skipped; unparseable files are silently ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg_root
|
Path
|
Package directory (containing |
required |
Returns:
| Type | Description |
|---|---|
list[SymbolDict]
|
One |
list[SymbolDict]
|
|
list[SymbolDict]
|
|
Source code in packages/axm-echo/src/axm_echo/corpus.py
flatten_body(body)
Flatten compound statements (with/if/for/while/try) into their inner body.
Source code in packages/axm-echo/src/axm_echo/structural.py
jaccard_similarity(a, b)
Jaccard similarity between two sets (1.0 when both are empty).
Source code in packages/axm-echo/src/axm_echo/structural.py
load_scope()
Return the workspace roots to scan, with graceful degradation.
Reads workspace_roots from ~/axm/echo.toml when present and
well-formed. On any failure (file absent, unreadable, invalid TOML,
missing or empty workspace_roots) returns [Path.cwd()] so the
caller still has the current workspace to scan -- never an exception.
Returns:
| Type | Description |
|---|---|
list[Path]
|
Resolved, de-duplicated workspace root paths. Always non-empty. |
Source code in packages/axm-echo/src/axm_echo/scope.py
neighbors(query, matrix, *, k=10, threshold=None)
Cosine top-k nearest rows to query (exact brute-force matmul).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
NDArray[float64]
|
A single query vector of shape |
required |
matrix
|
NDArray[float64]
|
Corpus matrix of shape |
required |
k
|
int
|
Maximum number of neighbors to return. |
10
|
threshold
|
float | None
|
If set, drop neighbors with cosine below this value. |
None
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, float]]
|
A list of |
list[tuple[int, float]]
|
descending, length |
list[tuple[int, float]]
|
corpus; if |
Source code in packages/axm-echo/src/axm_echo/embedding.py
normalize_dump(stmt)
Normalized single-statement dump (constants + name ids replaced).
Source code in packages/axm-echo/src/axm_echo/structural.py
statement_set(node)
Normalized stmt shapes (constants + name ids replaced) as a set.