traceiq 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- traceiq-0.3.1/.github/workflows/ci.yml +73 -0
- traceiq-0.3.1/.github/workflows/publish-testpypi.yml +64 -0
- traceiq-0.3.1/.github/workflows/publish.yml +63 -0
- traceiq-0.3.1/.gitignore +98 -0
- traceiq-0.3.1/.pre-commit-config.yaml +13 -0
- traceiq-0.3.1/CHANGELOG.md +49 -0
- traceiq-0.3.1/CLAUDE.md +239 -0
- traceiq-0.3.1/CONTRIBUTING.md +122 -0
- traceiq-0.3.1/LICENSE +21 -0
- traceiq-0.3.1/MATH.md +289 -0
- traceiq-0.3.1/PKG-INFO +667 -0
- traceiq-0.3.1/README.md +618 -0
- traceiq-0.3.1/SECURITY.md +54 -0
- traceiq-0.3.1/docs/api/index.md +349 -0
- traceiq-0.3.1/docs/cli.md +219 -0
- traceiq-0.3.1/docs/examples.md +277 -0
- traceiq-0.3.1/docs/index.md +63 -0
- traceiq-0.3.1/docs/installation.md +110 -0
- traceiq-0.3.1/docs/metrics.md +329 -0
- traceiq-0.3.1/docs/quickstart.md +163 -0
- traceiq-0.3.1/examples/output/.gitkeep +0 -0
- traceiq-0.3.1/examples/simulate_infection.py +246 -0
- traceiq-0.3.1/examples/smoke.py +112 -0
- traceiq-0.3.1/examples/test_real_agents.py +364 -0
- traceiq-0.3.1/mkdocs.yml +62 -0
- traceiq-0.3.1/notebooks/demo.ipynb +190 -0
- traceiq-0.3.1/pyproject.toml +88 -0
- traceiq-0.3.1/research/__init__.py +7 -0
- traceiq-0.3.1/research/ablation_study.py +222 -0
- traceiq-0.3.1/research/sensitivity_analysis.py +460 -0
- traceiq-0.3.1/research/synthetic_simulation.py +303 -0
- traceiq-0.3.1/ruff.toml +20 -0
- traceiq-0.3.1/src/traceiq/__init__.py +48 -0
- traceiq-0.3.1/src/traceiq/capabilities.py +215 -0
- traceiq-0.3.1/src/traceiq/cli.py +796 -0
- traceiq-0.3.1/src/traceiq/embeddings.py +230 -0
- traceiq-0.3.1/src/traceiq/export.py +207 -0
- traceiq-0.3.1/src/traceiq/graph.py +364 -0
- traceiq-0.3.1/src/traceiq/metrics.py +239 -0
- traceiq-0.3.1/src/traceiq/models.py +128 -0
- traceiq-0.3.1/src/traceiq/plotting.py +711 -0
- traceiq-0.3.1/src/traceiq/scoring.py +322 -0
- traceiq-0.3.1/src/traceiq/storage/__init__.py +7 -0
- traceiq-0.3.1/src/traceiq/storage/base.py +56 -0
- traceiq-0.3.1/src/traceiq/storage/memory.py +65 -0
- traceiq-0.3.1/src/traceiq/storage/sqlite.py +438 -0
- traceiq-0.3.1/src/traceiq/tracker.py +428 -0
- traceiq-0.3.1/tests/conftest.py +136 -0
- traceiq-0.3.1/tests/test_canonical_metrics.py +460 -0
- traceiq-0.3.1/tests/test_capabilities.py +227 -0
- traceiq-0.3.1/tests/test_export.py +190 -0
- traceiq-0.3.1/tests/test_metrics.py +276 -0
- traceiq-0.3.1/tests/test_plotting.py +143 -0
- traceiq-0.3.1/tests/test_pypi_safety.py +367 -0
- traceiq-0.3.1/tests/test_scoring.py +224 -0
- traceiq-0.3.1/tests/test_storage_sqlite.py +221 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[plot,dev]"
|
|
28
|
+
|
|
29
|
+
- name: Run ruff check
|
|
30
|
+
run: |
|
|
31
|
+
ruff check src/ tests/
|
|
32
|
+
|
|
33
|
+
- name: Run ruff format check
|
|
34
|
+
run: |
|
|
35
|
+
ruff format --check src/ tests/
|
|
36
|
+
|
|
37
|
+
- name: Run pytest
|
|
38
|
+
run: |
|
|
39
|
+
pytest -v
|
|
40
|
+
|
|
41
|
+
- name: Run smoke test
|
|
42
|
+
run: |
|
|
43
|
+
python examples/smoke.py
|
|
44
|
+
|
|
45
|
+
build:
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
needs: test
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v4
|
|
51
|
+
|
|
52
|
+
- name: Set up Python
|
|
53
|
+
uses: actions/setup-python@v5
|
|
54
|
+
with:
|
|
55
|
+
python-version: "3.11"
|
|
56
|
+
|
|
57
|
+
- name: Install build tools
|
|
58
|
+
run: |
|
|
59
|
+
python -m pip install --upgrade pip build
|
|
60
|
+
|
|
61
|
+
- name: Build package
|
|
62
|
+
run: |
|
|
63
|
+
python -m build
|
|
64
|
+
|
|
65
|
+
- name: Validate with twine
|
|
66
|
+
run: |
|
|
67
|
+
pip install twine
|
|
68
|
+
python -m twine check dist/*
|
|
69
|
+
|
|
70
|
+
- name: Verify wheel
|
|
71
|
+
run: |
|
|
72
|
+
pip install dist/*.whl
|
|
73
|
+
python -c "import traceiq; print(f'TraceIQ v{traceiq.__version__} import successful!')"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
name: Publish to TestPyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*rc*" # Only release candidates: v0.3.1rc1, v1.0.0rc2, etc.
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write # Required for OIDC trusted publishing
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout repository
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python 3.10
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.10"
|
|
23
|
+
|
|
24
|
+
- name: Install build tools
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install build twine
|
|
28
|
+
|
|
29
|
+
- name: Build package
|
|
30
|
+
run: python -m build
|
|
31
|
+
|
|
32
|
+
- name: Validate with twine
|
|
33
|
+
run: python -m twine check dist/*
|
|
34
|
+
|
|
35
|
+
- name: Verify wheel installation
|
|
36
|
+
run: |
|
|
37
|
+
pip install dist/*.whl
|
|
38
|
+
python -c "import traceiq; print(f'traceiq {traceiq.__version__}')"
|
|
39
|
+
traceiq --version
|
|
40
|
+
|
|
41
|
+
- name: Upload build artifacts
|
|
42
|
+
uses: actions/upload-artifact@v4
|
|
43
|
+
with:
|
|
44
|
+
name: dist
|
|
45
|
+
path: dist/
|
|
46
|
+
retention-days: 5
|
|
47
|
+
|
|
48
|
+
publish:
|
|
49
|
+
needs: build
|
|
50
|
+
runs-on: ubuntu-latest
|
|
51
|
+
environment:
|
|
52
|
+
name: testpypi
|
|
53
|
+
url: https://test.pypi.org/project/traceiq/
|
|
54
|
+
steps:
|
|
55
|
+
- name: Download build artifacts
|
|
56
|
+
uses: actions/download-artifact@v4
|
|
57
|
+
with:
|
|
58
|
+
name: dist
|
|
59
|
+
path: dist/
|
|
60
|
+
|
|
61
|
+
- name: Publish to TestPyPI
|
|
62
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
63
|
+
with:
|
|
64
|
+
repository-url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
- "!v*rc*" # Exclude release candidates (handled by testpypi workflow)
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
id-token: write # Required for OIDC trusted publishing
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
build:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout repository
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Set up Python 3.10
|
|
21
|
+
uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.10"
|
|
24
|
+
|
|
25
|
+
- name: Install build tools
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
pip install build twine
|
|
29
|
+
|
|
30
|
+
- name: Build package
|
|
31
|
+
run: python -m build
|
|
32
|
+
|
|
33
|
+
- name: Validate with twine
|
|
34
|
+
run: python -m twine check dist/*
|
|
35
|
+
|
|
36
|
+
- name: Verify wheel installation
|
|
37
|
+
run: |
|
|
38
|
+
pip install dist/*.whl
|
|
39
|
+
python -c "import traceiq; print(f'traceiq {traceiq.__version__}')"
|
|
40
|
+
traceiq --version
|
|
41
|
+
|
|
42
|
+
- name: Upload build artifacts
|
|
43
|
+
uses: actions/upload-artifact@v4
|
|
44
|
+
with:
|
|
45
|
+
name: dist
|
|
46
|
+
path: dist/
|
|
47
|
+
retention-days: 5
|
|
48
|
+
|
|
49
|
+
publish:
|
|
50
|
+
needs: build
|
|
51
|
+
runs-on: ubuntu-latest
|
|
52
|
+
environment:
|
|
53
|
+
name: pypi
|
|
54
|
+
url: https://pypi.org/project/traceiq/
|
|
55
|
+
steps:
|
|
56
|
+
- name: Download build artifacts
|
|
57
|
+
uses: actions/download-artifact@v4
|
|
58
|
+
with:
|
|
59
|
+
name: dist
|
|
60
|
+
path: dist/
|
|
61
|
+
|
|
62
|
+
- name: Publish to PyPI
|
|
63
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
traceiq-0.3.1/.gitignore
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage reports
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.nox/
|
|
39
|
+
.coverage
|
|
40
|
+
.coverage.*
|
|
41
|
+
.cache
|
|
42
|
+
nosetests.xml
|
|
43
|
+
coverage.xml
|
|
44
|
+
*.cover
|
|
45
|
+
*.py,cover
|
|
46
|
+
.hypothesis/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
|
|
49
|
+
# Translations
|
|
50
|
+
*.mo
|
|
51
|
+
*.pot
|
|
52
|
+
|
|
53
|
+
# Environments
|
|
54
|
+
.env
|
|
55
|
+
.venv
|
|
56
|
+
env/
|
|
57
|
+
venv/
|
|
58
|
+
ENV/
|
|
59
|
+
env.bak/
|
|
60
|
+
venv.bak/
|
|
61
|
+
|
|
62
|
+
# IDE
|
|
63
|
+
.idea/
|
|
64
|
+
.vscode/
|
|
65
|
+
*.swp
|
|
66
|
+
*.swo
|
|
67
|
+
*~
|
|
68
|
+
|
|
69
|
+
# Jupyter Notebook
|
|
70
|
+
.ipynb_checkpoints
|
|
71
|
+
|
|
72
|
+
# pytype static type analyzer
|
|
73
|
+
.pytype/
|
|
74
|
+
|
|
75
|
+
# mypy
|
|
76
|
+
.mypy_cache/
|
|
77
|
+
.dmypy.json
|
|
78
|
+
dmypy.json
|
|
79
|
+
|
|
80
|
+
# Ruff
|
|
81
|
+
.ruff_cache/
|
|
82
|
+
|
|
83
|
+
# Project specific
|
|
84
|
+
*.db
|
|
85
|
+
*.sqlite
|
|
86
|
+
examples/output/*.png
|
|
87
|
+
examples/output/*.csv
|
|
88
|
+
examples/output/*.jsonl
|
|
89
|
+
|
|
90
|
+
# macOS
|
|
91
|
+
.DS_Store
|
|
92
|
+
|
|
93
|
+
# MkDocs build output
|
|
94
|
+
site/
|
|
95
|
+
|
|
96
|
+
# Build artifacts
|
|
97
|
+
dist/
|
|
98
|
+
build/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
3
|
+
rev: v0.1.9
|
|
4
|
+
hooks:
|
|
5
|
+
- id: ruff-format
|
|
6
|
+
- id: ruff
|
|
7
|
+
args: [--fix]
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
10
|
+
rev: v4.5.0
|
|
11
|
+
hooks:
|
|
12
|
+
- id: end-of-file-fixer
|
|
13
|
+
- id: trailing-whitespace
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to TraceIQ will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-02-16
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **Truncation flags**: `sender_truncated` and `receiver_truncated` flags are added to score results when content exceeds `max_content_length`
|
|
13
|
+
- **Real batch embeddings**: `embed_batch()` now uses true batch encoding via `model.encode(list)` for better performance
|
|
14
|
+
- **Deterministic ordering**: All ranking outputs (`top_influencers`, `top_susceptible`, `top_influenced`) are now sorted by score descending, then agent_id ascending for consistent results
|
|
15
|
+
- **CLI validation**: The `ingest` command now validates that both `sender_content` and `receiver_content` are present in each JSONL record, with line number reporting on errors
|
|
16
|
+
- **Pre-commit hooks**: Added `.pre-commit-config.yaml` with ruff format and lint hooks
|
|
17
|
+
- **New tests**: Added comprehensive PyPI safety tests for imports, schema compatibility, caching, and deterministic behavior
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- **max_content_length default**: Increased from 512 to 5000 characters
|
|
22
|
+
- **Embedding cache key**: Cache key is now based on the hash of truncated content only, not full content
|
|
23
|
+
- **Schema migration**: Old databases with single `content` column now raise `RuntimeError` instead of auto-migrating
|
|
24
|
+
- **Version sourcing**: Version is now read from package metadata (single source of truth in `pyproject.toml`)
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- **Susceptibility plot label**: Changed X-axis label from "Total Incoming Influence" to "Total Incoming Drift" to accurately reflect the metric
|
|
29
|
+
|
|
30
|
+
### Documentation
|
|
31
|
+
|
|
32
|
+
- Added detailed docstring in `scoring.py` explaining baseline definition and influence scoring algorithms
|
|
33
|
+
|
|
34
|
+
## [0.1.0] - 2026-02-01
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- Initial release
|
|
39
|
+
- Core `InfluenceTracker` class for tracking AI-to-AI interactions
|
|
40
|
+
- Support for memory and SQLite storage backends
|
|
41
|
+
- SentenceTransformer-based embeddings with LRU caching
|
|
42
|
+
- Mock embedder for testing without heavy dependencies
|
|
43
|
+
- Drift and influence scoring with configurable thresholds
|
|
44
|
+
- NetworkX-based influence graph analytics
|
|
45
|
+
- Matplotlib plotting functions (drift over time, heatmaps, bar charts, network graphs)
|
|
46
|
+
- CLI with init, ingest, summary, export, and plot commands
|
|
47
|
+
- CSV and JSONL export functions
|
|
48
|
+
- Comprehensive test suite
|
|
49
|
+
- MkDocs documentation
|
traceiq-0.3.1/CLAUDE.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# CLAUDE.md - TraceIQ Project Context
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
**TraceIQ** is a Python library for measuring AI-to-AI influence in multi-agent systems. It tracks how one agent's outputs influence another agent's behavior using semantic embeddings and provides tools for analysis, visualization, and security monitoring.
|
|
6
|
+
|
|
7
|
+
## Repository
|
|
8
|
+
|
|
9
|
+
- **GitHub**: https://github.com/Anarv2104/TraceIQ
|
|
10
|
+
- **PyPI**: traceiq (pending publication)
|
|
11
|
+
- **Version**: 0.3.0
|
|
12
|
+
|
|
13
|
+
## Project Status: COMPLETE
|
|
14
|
+
|
|
15
|
+
### v0.3.0 - IEEE Research Framework
|
|
16
|
+
|
|
17
|
+
| Phase | Status | Description |
|
|
18
|
+
|-------|--------|-------------|
|
|
19
|
+
| Core Implementation | ✅ Done | All source modules implemented |
|
|
20
|
+
| Storage Backends | ✅ Done | Memory and SQLite backends |
|
|
21
|
+
| Embeddings | ✅ Done | SentenceTransformer + Mock embedder |
|
|
22
|
+
| Scoring Engine | ✅ Done | Drift, influence, IQx, RWI, Z-score |
|
|
23
|
+
| Graph Analytics | ✅ Done | NetworkX + spectral radius |
|
|
24
|
+
| Plotting | ✅ Done | 10 plot types including IEEE metrics |
|
|
25
|
+
| CLI | ✅ Done | Extended with IEEE metric commands |
|
|
26
|
+
| Export | ✅ Done | CSV and JSONL export functions |
|
|
27
|
+
| IEEE Metrics | ✅ Done | 7 new metrics (IQx, RWI, PR, etc.) |
|
|
28
|
+
| Capability Registry | ✅ Done | Attack surface computation |
|
|
29
|
+
| Research Scripts | ✅ Done | Simulation, ablation, sensitivity |
|
|
30
|
+
| Tests | ✅ Done | 116 tests passing |
|
|
31
|
+
| Documentation | ✅ Done | MATH.md + updated docs |
|
|
32
|
+
|
|
33
|
+
## Architecture
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
TraceIQ/
|
|
37
|
+
├── src/traceiq/
|
|
38
|
+
│ ├── __init__.py # Public API exports
|
|
39
|
+
│ ├── models.py # Pydantic models (extended with IEEE fields)
|
|
40
|
+
│ ├── tracker.py # Main InfluenceTracker class
|
|
41
|
+
│ ├── embeddings.py # SentenceTransformerEmbedder, MockEmbedder
|
|
42
|
+
│ ├── scoring.py # ScoringEngine (drift, IQx, RWI, Z-score)
|
|
43
|
+
│ ├── metrics.py # NEW: Core IEEE metric computations
|
|
44
|
+
│ ├── capabilities.py # NEW: CapabilityRegistry for attack surface
|
|
45
|
+
│ ├── graph.py # InfluenceGraph (spectral radius, adjacency)
|
|
46
|
+
│ ├── plotting.py # Extended plotting (IQx heatmap, PR over time)
|
|
47
|
+
│ ├── cli.py # Click CLI (propagation-risk, alerts, etc.)
|
|
48
|
+
│ ├── export.py # CSV/JSONL export functions
|
|
49
|
+
│ └── storage/
|
|
50
|
+
│ ├── base.py # Abstract StorageBackend
|
|
51
|
+
│ ├── memory.py # MemoryStorage (dict-based)
|
|
52
|
+
│ └── sqlite.py # SQLiteStorage (extended schema)
|
|
53
|
+
├── research/ # NEW: Research experiment scripts
|
|
54
|
+
│ ├── synthetic_simulation.py
|
|
55
|
+
│ ├── ablation_study.py
|
|
56
|
+
│ └── sensitivity_analysis.py
|
|
57
|
+
├── tests/ # Pytest test suite
|
|
58
|
+
├── docs/ # MkDocs documentation
|
|
59
|
+
├── examples/ # Runnable examples
|
|
60
|
+
├── MATH.md # NEW: Mathematical framework documentation
|
|
61
|
+
└── pyproject.toml # Package configuration (v0.3.0)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## IEEE Metrics Summary
|
|
65
|
+
|
|
66
|
+
| Metric | Formula | Purpose |
|
|
67
|
+
|--------|---------|---------|
|
|
68
|
+
| **Drift (L2)** | `D = \|\|s(t+) - s(t-)\|\|_2` | L2 norm state change |
|
|
69
|
+
| **IQx** | `IQx = D / (B + ε)` | Normalized influence quotient |
|
|
70
|
+
| **Accumulated Influence** | `AI = Σ IQx` | Sum over window |
|
|
71
|
+
| **Propagation Risk** | `PR = spectral_radius(W)` | Network instability |
|
|
72
|
+
| **Attack Surface** | `AS = Σ p(c)` | Capability-weighted risk |
|
|
73
|
+
| **RWI** | `RWI = IQx × AS` | Security-adjusted influence |
|
|
74
|
+
| **Z-score** | `Z = (IQx - μ) / (σ + ε)` | Anomaly detection |
|
|
75
|
+
|
|
76
|
+
## Key Algorithms
|
|
77
|
+
|
|
78
|
+
### Legacy Drift Detection
|
|
79
|
+
```python
|
|
80
|
+
drift_delta = 1 - cosine_similarity(current_embedding, baseline_embedding)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### IEEE Drift (L2)
|
|
84
|
+
```python
|
|
85
|
+
drift_l2 = np.linalg.norm(emb_after - emb_before)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Influence Quotient (IQx)
|
|
89
|
+
```python
|
|
90
|
+
IQx = drift_l2 / (baseline_median + epsilon)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Propagation Risk
|
|
94
|
+
```python
|
|
95
|
+
spectral_radius = max(abs(eigenvalues(adjacency_matrix)))
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Risk-Weighted Influence
|
|
99
|
+
```python
|
|
100
|
+
RWI = IQx * attack_surface
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Dependencies
|
|
104
|
+
|
|
105
|
+
**Core:**
|
|
106
|
+
- pydantic >= 2.0
|
|
107
|
+
- numpy >= 1.24
|
|
108
|
+
- networkx >= 3.0
|
|
109
|
+
- click >= 8.0
|
|
110
|
+
- rich >= 13.0
|
|
111
|
+
|
|
112
|
+
**Optional:**
|
|
113
|
+
- sentence-transformers >= 2.2 (`[embedding]`)
|
|
114
|
+
- matplotlib >= 3.7 (`[plot]`)
|
|
115
|
+
- pandas >= 2.0, scipy >= 1.10 (`[research]`)
|
|
116
|
+
|
|
117
|
+
## Commands
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Install
|
|
121
|
+
pip install -e ".[all,dev]"
|
|
122
|
+
|
|
123
|
+
# Run tests
|
|
124
|
+
pytest -v
|
|
125
|
+
|
|
126
|
+
# Lint
|
|
127
|
+
ruff check src/ tests/
|
|
128
|
+
|
|
129
|
+
# Format
|
|
130
|
+
ruff format src/ tests/
|
|
131
|
+
|
|
132
|
+
# Build package
|
|
133
|
+
python -m build
|
|
134
|
+
|
|
135
|
+
# Run research simulation
|
|
136
|
+
python research/synthetic_simulation.py
|
|
137
|
+
|
|
138
|
+
# CLI commands (v0.3.0)
|
|
139
|
+
traceiq --help
|
|
140
|
+
traceiq propagation-risk --db traceiq.db
|
|
141
|
+
traceiq alerts --db traceiq.db --threshold 2.0
|
|
142
|
+
traceiq risky-agents --db traceiq.db
|
|
143
|
+
traceiq capabilities show
|
|
144
|
+
traceiq plot iqx-heatmap --db traceiq.db -o heatmap.png
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Example Usage (v0.3.0)
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from traceiq import InfluenceTracker, TrackerConfig
|
|
151
|
+
|
|
152
|
+
# Configure with IEEE metrics
|
|
153
|
+
config = TrackerConfig(
|
|
154
|
+
storage_backend="sqlite",
|
|
155
|
+
storage_path="research.db",
|
|
156
|
+
baseline_window=10,
|
|
157
|
+
epsilon=1e-6,
|
|
158
|
+
anomaly_threshold=2.0,
|
|
159
|
+
capability_weights={
|
|
160
|
+
"execute_code": 1.0,
|
|
161
|
+
"admin": 1.5,
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
tracker = InfluenceTracker(config=config)
|
|
166
|
+
|
|
167
|
+
# Register agent capabilities
|
|
168
|
+
tracker.capabilities.register_agent("agent_0", ["execute_code", "admin"])
|
|
169
|
+
tracker.capabilities.register_agent("agent_1", ["file_read"])
|
|
170
|
+
|
|
171
|
+
# Track with full metrics
|
|
172
|
+
result = tracker.track_event(
|
|
173
|
+
sender_id="agent_0",
|
|
174
|
+
receiver_id="agent_1",
|
|
175
|
+
sender_content="Execute this command...",
|
|
176
|
+
receiver_content="Executing command...",
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
print(f"IQx: {result['IQx']}")
|
|
180
|
+
print(f"RWI: {result['RWI']}")
|
|
181
|
+
print(f"Z-score: {result['Z_score']}")
|
|
182
|
+
print(f"Alert: {result['alert']}")
|
|
183
|
+
|
|
184
|
+
# Get propagation risk
|
|
185
|
+
pr = tracker.get_propagation_risk()
|
|
186
|
+
print(f"Propagation Risk: {pr}")
|
|
187
|
+
|
|
188
|
+
# Get anomaly alerts
|
|
189
|
+
alerts = tracker.get_alerts()
|
|
190
|
+
print(f"Alerts: {len(alerts)}")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Test Results
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
116 tests passing (110 passed, 6 skipped)
|
|
197
|
+
- test_metrics.py: 25 tests (L2 drift, IQx, PR, AS, RWI, Z-score)
|
|
198
|
+
- test_capabilities.py: 21 tests (registry, persistence, attack surface)
|
|
199
|
+
- test_scoring.py: 12 tests (cosine similarity, cold start, thresholds)
|
|
200
|
+
- test_storage_sqlite.py: 11 tests (CRUD, persistence, schema migration)
|
|
201
|
+
- test_export.py: 10 tests (CSV, JSONL output)
|
|
202
|
+
- test_plotting.py: 7 tests (visualization generation - skipped without matplotlib)
|
|
203
|
+
- test_pypi_safety.py: 16 tests (import safety, schema compat, determinism)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Research Experiments
|
|
207
|
+
|
|
208
|
+
### Synthetic Simulation
|
|
209
|
+
```bash
|
|
210
|
+
python research/synthetic_simulation.py
|
|
211
|
+
```
|
|
212
|
+
- 5-agent simulation with biased injector
|
|
213
|
+
- Measures influence propagation
|
|
214
|
+
- Generates plots to `research/outputs/`
|
|
215
|
+
|
|
216
|
+
### Ablation Study
|
|
217
|
+
```bash
|
|
218
|
+
python research/ablation_study.py
|
|
219
|
+
```
|
|
220
|
+
- Tests baseline_window [3, 5, 10, 15, 20, 30]
|
|
221
|
+
- Measures detection rate vs window size
|
|
222
|
+
|
|
223
|
+
### Sensitivity Analysis
|
|
224
|
+
```bash
|
|
225
|
+
python research/sensitivity_analysis.py
|
|
226
|
+
```
|
|
227
|
+
- Epsilon sensitivity
|
|
228
|
+
- Anomaly threshold precision/recall
|
|
229
|
+
- Capability weight schemes
|
|
230
|
+
|
|
231
|
+
## Backward Compatibility
|
|
232
|
+
|
|
233
|
+
- v0.2.0 databases automatically migrated to v0.3.0 schema
|
|
234
|
+
- All v0.2.0 API remains functional
|
|
235
|
+
- New IEEE metric fields default to None for old records
|
|
236
|
+
|
|
237
|
+
## Contact
|
|
238
|
+
|
|
239
|
+
Repository: https://github.com/Anarv2104/TraceIQ
|