ark-trust 0.4.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.
Files changed (33) hide show
  1. ark_trust-0.4.1/LICENSE +3 -0
  2. ark_trust-0.4.1/PKG-INFO +147 -0
  3. ark_trust-0.4.1/README.md +119 -0
  4. ark_trust-0.4.1/pyproject.toml +30 -0
  5. ark_trust-0.4.1/setup.cfg +4 -0
  6. ark_trust-0.4.1/src/ark/__init__.py +49 -0
  7. ark_trust-0.4.1/src/ark/achievements.py +226 -0
  8. ark_trust-0.4.1/src/ark/auto.py +68 -0
  9. ark_trust-0.4.1/src/ark/benchmarks.py +233 -0
  10. ark_trust-0.4.1/src/ark/breaker.py +95 -0
  11. ark_trust-0.4.1/src/ark/crewai.py +108 -0
  12. ark_trust-0.4.1/src/ark/dashboard.py +237 -0
  13. ark_trust-0.4.1/src/ark/guard.py +125 -0
  14. ark_trust-0.4.1/src/ark/langchain.py +126 -0
  15. ark_trust-0.4.1/src/ark/module_kit.py +225 -0
  16. ark_trust-0.4.1/src/ark/multi_agent.py +234 -0
  17. ark_trust-0.4.1/src/ark/proactive.py +238 -0
  18. ark_trust-0.4.1/src/ark/schema_hub.py +465 -0
  19. ark_trust-0.4.1/src/ark/schema_registry.py +141 -0
  20. ark_trust-0.4.1/src/ark/score.py +121 -0
  21. ark_trust-0.4.1/src/ark/stateful_breaker.py +212 -0
  22. ark_trust-0.4.1/src/ark/trace.py +96 -0
  23. ark_trust-0.4.1/src/ark/validator.py +80 -0
  24. ark_trust-0.4.1/src/ark_trust.egg-info/PKG-INFO +147 -0
  25. ark_trust-0.4.1/src/ark_trust.egg-info/SOURCES.txt +31 -0
  26. ark_trust-0.4.1/src/ark_trust.egg-info/dependency_links.txt +1 -0
  27. ark_trust-0.4.1/src/ark_trust.egg-info/requires.txt +11 -0
  28. ark_trust-0.4.1/src/ark_trust.egg-info/top_level.txt +1 -0
  29. ark_trust-0.4.1/tests/test_ark.py +115 -0
  30. ark_trust-0.4.1/tests/test_schema_hub.py +295 -0
  31. ark_trust-0.4.1/tests/test_v0_3_0.py +234 -0
  32. ark_trust-0.4.1/tests/test_v0_4_0.py +89 -0
  33. ark_trust-0.4.1/tests/test_v0_4_0_stress.py +1434 -0
@@ -0,0 +1,3 @@
1
+ MIT License
2
+ Copyright (c) 2026 ARK Contributors
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy...
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: ark-trust
3
+ Version: 0.4.1
4
+ Summary: ARK - Agent Reliability Kit. Trust infrastructure for AI agents.
5
+ Author: ARK Contributors
6
+ License: MIT
7
+ Keywords: ai,agent,reliability,trust,guard,circuit-breaker,validation
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: pydantic>=2.0
19
+ Requires-Dist: httpx>=0.28
20
+ Requires-Dist: structlog>=23.0
21
+ Provides-Extra: langchain
22
+ Requires-Dist: langchain-core>=0.3; extra == "langchain"
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest; extra == "dev"
25
+ Requires-Dist: pytest-asyncio; extra == "dev"
26
+ Requires-Dist: ruff; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # ARK โ€” Agent Reliability Kit ๐Ÿ›ก
30
+
31
+ > **Trust infrastructure for AI agents.**
32
+ > Stripe-level idempotency ร— Sentinel circuit breakers ร— OpenTelemetry tracing ร— IDE-style validation.
33
+ > For AI agents.
34
+
35
+ [![Tests](https://img.shields.io/badge/tests-169/169-green)](https://github.com/wzg0911/ark)
36
+ [![Python](https://img.shields.io/badge/python-3.9+-blue)](https://pypi.org)
37
+ [![License](https://img.shields.io/badge/license-MIT-purple)](LICENSE)
38
+
39
+ ---
40
+
41
+ ## ๐Ÿค” Why ARK?
42
+
43
+ Your AI agent says it sent an email. **Did it really?**
44
+ Your AI agent says it charged $10. **Did it charge $10... or $100?**
45
+ Your AI agent retries on failure. **Did it just send 3 duplicate payments?**
46
+
47
+ > "Agent does not actually invoke tools, only simulates tool usage with fabricated output"
48
+ > โ€” *CrewAI Bug #?*, 63 comments
49
+
50
+ **ARK proves every agent action is real.**
51
+
52
+ ## โšก Quick Start
53
+
54
+ ```bash
55
+ pip install ark-trust
56
+ ```
57
+
58
+ ```python
59
+ from ark import IdempotencyGuard, CircuitBreaker, OutputValidator
60
+
61
+ # ๐Ÿ›ก 1. Never run duplicate payments
62
+ guard = IdempotencyGuard()
63
+
64
+ @guard.wrap
65
+ def charge(amount: float):
66
+ return stripe.charge(amount)
67
+
68
+ charge(99.99) # โœ… Charged
69
+ charge(99.99) # ๐Ÿ›ก Intercepted โ€” no duplicate!
70
+
71
+ # โšก 2. Auto-fallback when models fail
72
+ breaker = CircuitBreaker("gpt-4", failure_threshold=3)
73
+
74
+ result = breaker.call(
75
+ primary=lambda: gpt4.generate(prompt),
76
+ fallback=lambda: claude.generate(prompt) # Auto-switch!
77
+ )
78
+
79
+ # ๐Ÿ”ง 3. Validate agent output
80
+ from pydantic import BaseModel
81
+
82
+ class PaymentResult(BaseModel):
83
+ amount: float
84
+ txn_id: str
85
+
86
+ validator = OutputValidator()
87
+ result = validator.validate(PaymentResult, agent_output)
88
+ if not result.valid:
89
+ print(f"ARK blocked invalid output: {result.errors}")
90
+ ```
91
+
92
+ ## ๐Ÿ”ฑ The Four Pillars
93
+
94
+ | Pillar | Gene Source | What It Does |
95
+ |--------|------------|--------------|
96
+ | ๐Ÿ›ก **Idempotency Guard** | Stripe payments | Prevents duplicate tool execution |
97
+ | โšก **Circuit Breaker** | Sentinel microservices | Auto-meltdown โ†’ safe fallback |
98
+ | ๐Ÿ”ง **Output Validator** | IDE type checking | Validates agent output against schema |
99
+ | ๐Ÿ‘ **Trace** | OpenTelemetry | Full execution trace visibility |
100
+
101
+ ## ๐Ÿ“Š What ARK Catches
102
+
103
+ ```
104
+ CrewAI agents fake tool calls โ†’ ARK validates real execution
105
+ GPT-4 fails 6 times in a row โ†’ ARK auto-switches to Claude
106
+ Agent retries a payment 3 times โ†’ ARK blocks duplicates 2&3
107
+ Streaming response returns null โ†’ ARK detects + reloads
108
+ ```
109
+
110
+ ## ๐ŸŽฏ The Numbers
111
+
112
+ - **8847** error issues across top 3 agent frameworks
113
+ - **50+ comments** on a single "duplicate payment" bug
114
+ - **75%** of agent outputs need validation
115
+ - **0** existing products in this space (max competitor: 129โญ)
116
+
117
+ ## ๐Ÿ— Architecture
118
+
119
+ ```
120
+ Your Agent
121
+ โ†“
122
+ โ”Œโ”€โ”€โ”€ ARK Trust Layer โ”€โ”€โ”€โ”
123
+ โ”‚ ๐Ÿ›ก Guard โšก Breaker โ”‚
124
+ โ”‚ ๐Ÿ”ง Validator ๐Ÿ‘ Trace โ”‚
125
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
126
+ โ†“
127
+ Your Tools & APIs
128
+ ```
129
+
130
+ ## ๐Ÿš€ Roadmap
131
+
132
+ - [x] MVP โ€” 4 core pillars (v0.1.0)
133
+ - [x] LangChain integration โ€” `ARKCallbackHandler` (v0.1.0)
134
+ - [x] CrewAI integration โ€” `ARKCrewCallback` (v0.1.1)
135
+ - [x] Auto-detect frameworks (v0.2.0)
136
+ - [x] Reliability Score + Schema Registry โ€” 13 schemas (v0.2.0)
137
+ - [x] Dashboard UI โ€” real-time trust monitoring (v0.3.0)
138
+ - [x] Achievement system โ€” gamified reliability badges (v0.3.0)
139
+ - [x] PyPI publish automation (v0.3.0)
140
+
141
+ ## ๐Ÿ“œ License
142
+
143
+ MIT โ€” Free forever. ARK is open infrastructure.
144
+
145
+ ---
146
+
147
+ **Built with ๐Ÿงฌ gene recombination: Stripe ร— Sentinel ร— OpenTelemetry ร— IDE**
@@ -0,0 +1,119 @@
1
+ # ARK โ€” Agent Reliability Kit ๐Ÿ›ก
2
+
3
+ > **Trust infrastructure for AI agents.**
4
+ > Stripe-level idempotency ร— Sentinel circuit breakers ร— OpenTelemetry tracing ร— IDE-style validation.
5
+ > For AI agents.
6
+
7
+ [![Tests](https://img.shields.io/badge/tests-169/169-green)](https://github.com/wzg0911/ark)
8
+ [![Python](https://img.shields.io/badge/python-3.9+-blue)](https://pypi.org)
9
+ [![License](https://img.shields.io/badge/license-MIT-purple)](LICENSE)
10
+
11
+ ---
12
+
13
+ ## ๐Ÿค” Why ARK?
14
+
15
+ Your AI agent says it sent an email. **Did it really?**
16
+ Your AI agent says it charged $10. **Did it charge $10... or $100?**
17
+ Your AI agent retries on failure. **Did it just send 3 duplicate payments?**
18
+
19
+ > "Agent does not actually invoke tools, only simulates tool usage with fabricated output"
20
+ > โ€” *CrewAI Bug #?*, 63 comments
21
+
22
+ **ARK proves every agent action is real.**
23
+
24
+ ## โšก Quick Start
25
+
26
+ ```bash
27
+ pip install ark-trust
28
+ ```
29
+
30
+ ```python
31
+ from ark import IdempotencyGuard, CircuitBreaker, OutputValidator
32
+
33
+ # ๐Ÿ›ก 1. Never run duplicate payments
34
+ guard = IdempotencyGuard()
35
+
36
+ @guard.wrap
37
+ def charge(amount: float):
38
+ return stripe.charge(amount)
39
+
40
+ charge(99.99) # โœ… Charged
41
+ charge(99.99) # ๐Ÿ›ก Intercepted โ€” no duplicate!
42
+
43
+ # โšก 2. Auto-fallback when models fail
44
+ breaker = CircuitBreaker("gpt-4", failure_threshold=3)
45
+
46
+ result = breaker.call(
47
+ primary=lambda: gpt4.generate(prompt),
48
+ fallback=lambda: claude.generate(prompt) # Auto-switch!
49
+ )
50
+
51
+ # ๐Ÿ”ง 3. Validate agent output
52
+ from pydantic import BaseModel
53
+
54
+ class PaymentResult(BaseModel):
55
+ amount: float
56
+ txn_id: str
57
+
58
+ validator = OutputValidator()
59
+ result = validator.validate(PaymentResult, agent_output)
60
+ if not result.valid:
61
+ print(f"ARK blocked invalid output: {result.errors}")
62
+ ```
63
+
64
+ ## ๐Ÿ”ฑ The Four Pillars
65
+
66
+ | Pillar | Gene Source | What It Does |
67
+ |--------|------------|--------------|
68
+ | ๐Ÿ›ก **Idempotency Guard** | Stripe payments | Prevents duplicate tool execution |
69
+ | โšก **Circuit Breaker** | Sentinel microservices | Auto-meltdown โ†’ safe fallback |
70
+ | ๐Ÿ”ง **Output Validator** | IDE type checking | Validates agent output against schema |
71
+ | ๐Ÿ‘ **Trace** | OpenTelemetry | Full execution trace visibility |
72
+
73
+ ## ๐Ÿ“Š What ARK Catches
74
+
75
+ ```
76
+ CrewAI agents fake tool calls โ†’ ARK validates real execution
77
+ GPT-4 fails 6 times in a row โ†’ ARK auto-switches to Claude
78
+ Agent retries a payment 3 times โ†’ ARK blocks duplicates 2&3
79
+ Streaming response returns null โ†’ ARK detects + reloads
80
+ ```
81
+
82
+ ## ๐ŸŽฏ The Numbers
83
+
84
+ - **8847** error issues across top 3 agent frameworks
85
+ - **50+ comments** on a single "duplicate payment" bug
86
+ - **75%** of agent outputs need validation
87
+ - **0** existing products in this space (max competitor: 129โญ)
88
+
89
+ ## ๐Ÿ— Architecture
90
+
91
+ ```
92
+ Your Agent
93
+ โ†“
94
+ โ”Œโ”€โ”€โ”€ ARK Trust Layer โ”€โ”€โ”€โ”
95
+ โ”‚ ๐Ÿ›ก Guard โšก Breaker โ”‚
96
+ โ”‚ ๐Ÿ”ง Validator ๐Ÿ‘ Trace โ”‚
97
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
98
+ โ†“
99
+ Your Tools & APIs
100
+ ```
101
+
102
+ ## ๐Ÿš€ Roadmap
103
+
104
+ - [x] MVP โ€” 4 core pillars (v0.1.0)
105
+ - [x] LangChain integration โ€” `ARKCallbackHandler` (v0.1.0)
106
+ - [x] CrewAI integration โ€” `ARKCrewCallback` (v0.1.1)
107
+ - [x] Auto-detect frameworks (v0.2.0)
108
+ - [x] Reliability Score + Schema Registry โ€” 13 schemas (v0.2.0)
109
+ - [x] Dashboard UI โ€” real-time trust monitoring (v0.3.0)
110
+ - [x] Achievement system โ€” gamified reliability badges (v0.3.0)
111
+ - [x] PyPI publish automation (v0.3.0)
112
+
113
+ ## ๐Ÿ“œ License
114
+
115
+ MIT โ€” Free forever. ARK is open infrastructure.
116
+
117
+ ---
118
+
119
+ **Built with ๐Ÿงฌ gene recombination: Stripe ร— Sentinel ร— OpenTelemetry ร— IDE**
@@ -0,0 +1,30 @@
1
+ [project]
2
+ name = "ark-trust"
3
+ version = "0.4.1"
4
+ description = "ARK - Agent Reliability Kit. Trust infrastructure for AI agents."
5
+ readme = "README.md"
6
+ license = {text = "MIT"}
7
+ authors = [{name = "ARK Contributors"}]
8
+ keywords = ["ai", "agent", "reliability", "trust", "guard", "circuit-breaker", "validation"]
9
+ classifiers = [
10
+ "Development Status :: 4 - Beta",
11
+ "Intended Audience :: Developers",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Programming Language :: Python :: 3.9",
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ ]
18
+ requires-python = ">=3.9"
19
+ dependencies = [
20
+ "pydantic>=2.0",
21
+ "httpx>=0.28",
22
+ "structlog>=23.0",
23
+ ]
24
+ [project.optional-dependencies]
25
+ langchain = ["langchain-core>=0.3"]
26
+ dev = ["pytest", "pytest-asyncio", "ruff"]
27
+
28
+ [build-system]
29
+ requires = ["setuptools>=68"]
30
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,49 @@
1
+ """
2
+ ARK - Agent Reliability Kit
3
+ Trust infrastructure for AI agents.
4
+
5
+ ๅŸบๅ› ้‡็ป„:
6
+ ๐Ÿฆ Stripe โ†’ ๅน‚็ญ‰ๅฎˆๆŠค (Idempotency Guard)
7
+ โšก Sentinel โ†’ ็†”ๆ–ญๆŽงๅˆถๅ™จ (Circuit Breaker)
8
+ ๐Ÿ‘ OpenTelemetry โ†’ ้“พ่ทฏ่ฟฝ่ธช (Trace)
9
+ ๐Ÿ”ง IDE โ†’ ่พ“ๅ‡บ้ชŒ่ฏ (Output Validator)
10
+ ๐ŸŽฎ Gaming โ†’ ๅฏ้ ๆ€ง่ฏ„ๅˆ† (Reliability Score)
11
+ ๐Ÿ“ฆ Community โ†’ Schemaๆณจๅ†Œ่กจ (Schema Registry)
12
+ ๐Ÿ”ฎ memU โ†’ ้ข„ๆต‹ๆ€งๅฎˆๆŠค (ProactiveGuard)
13
+ ๐Ÿ’พ EverOS/MemBrain โ†’ ็Šถๆ€ๆŒไน…ๅŒ– (StatefulBreaker)
14
+ ๐Ÿงฉ GenericAgent โ†’ ๆจกๅ—ๅŒ–่ƒฝๅŠ› (ModuleKit)
15
+ ๐Ÿค PraisonAI โ†’ ๅคšAgentๅ่ฎฎ (MultiAgentProtocol)
16
+
17
+ v0.4.0.dev1 - ๅ››ๅคงๅขžๅผบๆจกๅ—
18
+ """
19
+
20
+ from .guard import IdempotencyGuard
21
+ from .breaker import CircuitBreaker
22
+ from .validator import OutputValidator
23
+ from .trace import Trace
24
+ from .score import ReliabilityScore
25
+ from .schema_registry import SchemaRegistry
26
+ from .schema_hub import SchemaHub, get_schema_hub
27
+ from .auto import auto_init, detect_frameworks
28
+ from .dashboard import Dashboard, get_dashboard, Event
29
+ from .achievements import Achievements, Achievement, Tier
30
+ from .benchmarks import Benchmarks, BenchmarkResult
31
+ from .proactive import ProactiveGuard, ProactiveBlockError
32
+ from .stateful_breaker import StatefulBreaker, CircuitOpenError
33
+ from .module_kit import ModulePipeline, Module, RateLimitModule, SchemaValidationModule, LoggingModule, ModuleBlockError
34
+ from .multi_agent import MultiAgentProtocol, AgentMessage, AgentHeartbeat, MessageStatus, AgentStatus
35
+
36
+ __version__ = "0.4.0.dev1"
37
+ __all__ = [
38
+ "IdempotencyGuard", "CircuitBreaker", "OutputValidator", "Trace",
39
+ "ReliabilityScore", "SchemaRegistry", "auto_init", "detect_frameworks",
40
+ "Dashboard", "get_dashboard", "Event", "Achievements", "Achievement", "Tier",
41
+ "Benchmarks", "BenchmarkResult",
42
+ "SchemaHub", "get_schema_hub",
43
+ "ProactiveGuard", "ProactiveBlockError",
44
+ "StatefulBreaker", "CircuitOpenError",
45
+ "ModulePipeline", "Module", "RateLimitModule",
46
+ "SchemaValidationModule", "LoggingModule", "ModuleBlockError",
47
+ "MultiAgentProtocol", "AgentMessage", "AgentHeartbeat",
48
+ "MessageStatus", "AgentStatus",
49
+ ]
@@ -0,0 +1,226 @@
1
+ """
2
+ ARK Achievements โ€” Gamification engine for agent trust
3
+ v0.3.0 โ€” Unlock badges as your agents become more reliable.
4
+
5
+ Usage:
6
+ from ark import Achievements
7
+ ach = Achievements()
8
+ ach.record("intercept", agent="checkout-bot")
9
+ ach.record("validate_pass", agent="checkout-bot")
10
+ print(ach.summary())
11
+ """
12
+
13
+ import time
14
+ from typing import Dict, List, Set
15
+ from dataclasses import dataclass, field
16
+ from enum import Enum
17
+
18
+
19
+ class Tier(Enum):
20
+ BRONZE = ("๐Ÿฅ‰", 1)
21
+ SILVER = ("๐Ÿฅˆ", 2)
22
+ GOLD = ("๐Ÿฅ‡", 3)
23
+ PLATINUM = ("๐Ÿ’Ž", 4)
24
+
25
+ def __init__(self, emoji: str, level: int):
26
+ self.emoji = emoji
27
+ self.level = level
28
+
29
+
30
+ @dataclass
31
+ class Achievement:
32
+ id: str
33
+ name: str
34
+ description: str
35
+ icon: str
36
+ progress: int = 0 # current count
37
+ target: int = 1 # count needed
38
+ tiers: List[Tier] = field(default_factory=lambda: [Tier.BRONZE, Tier.SILVER, Tier.GOLD, Tier.PLATINUM])
39
+ unlocked_at: List[float] = field(default_factory=list) # timestamps of unlocks
40
+ _previous_tier: int = 0
41
+
42
+ @property
43
+ def current_tier(self) -> Tier:
44
+ return self.tiers[min(len(self.unlocked_at), len(self.tiers) - 1)]
45
+
46
+ @property
47
+ def is_maxed(self) -> bool:
48
+ return len(self.unlocked_at) >= len(self.tiers)
49
+
50
+ @property
51
+ def next_tier_target(self) -> int:
52
+ """Target for the next tier, or -1 if maxed."""
53
+ if self.is_maxed:
54
+ return -1
55
+ idx = len(self.unlocked_at)
56
+ multiplier_map = {0: 1, 1: 10, 2: 100, 3: 1000}
57
+ return self.target * multiplier_map.get(idx, self.target)
58
+
59
+ def progress_pct(self) -> float:
60
+ if self.is_maxed:
61
+ return 100.0
62
+ return min(100.0, round(self.progress / self.next_tier_target * 100, 1))
63
+
64
+
65
+ # โ”€โ”€ Predefined Achievements โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
66
+
67
+ ACHIEVEMENTS = {
68
+ "guardian": Achievement(
69
+ id="guardian",
70
+ name="Guardian",
71
+ icon="๐Ÿ›ก",
72
+ description="Intercept duplicate calls",
73
+ target=10, # Bronze at 10, Silver at 100, Gold at 1000, Platinum at 10000
74
+ ),
75
+ "survivor": Achievement(
76
+ id="survivor",
77
+ name="Survivor",
78
+ icon="โšก",
79
+ description="Circuit breaker recovers",
80
+ target=1, # Bronze at 1, Silver at 10, Gold at 100, Platinum at 1000
81
+ ),
82
+ "inspector": Achievement(
83
+ id="inspector",
84
+ name="Inspector",
85
+ icon="๐Ÿ”ง",
86
+ description="Validations passed",
87
+ target=10, # Bronze at 10, Silver at 100, Gold at 1000, Platinum at 10000
88
+ ),
89
+ "watcher": Achievement(
90
+ id="watcher",
91
+ name="Watcher",
92
+ icon="๐Ÿ‘",
93
+ description="Spans traced",
94
+ target=10, # Bronze at 10, Silver at 100, Gold at 1000, Platinum at 10000
95
+ ),
96
+ "ark_master": Achievement(
97
+ id="ark_master",
98
+ name="ARK Master",
99
+ icon="๐ŸŽ–",
100
+ description="All four achievements at Gold+",
101
+ target=1,
102
+ tiers=[Tier.PLATINUM], # one-time ultimate unlock
103
+ ),
104
+ }
105
+
106
+
107
+ @dataclass
108
+ class Achievements:
109
+ """Tracks agent achievements and triggers unlocks."""
110
+
111
+ achievements: Dict[str, Achievement] = field(
112
+ default_factory=lambda: {k: Achievement(**v.__dict__) for k, v in ACHIEVEMENTS.items()}
113
+ )
114
+ recent_unlocks: List[Dict] = field(default_factory=list) # push notifications
115
+
116
+ # โ”€โ”€ recording โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
117
+
118
+ def record(self, kind: str, agent: str = "default", count: int = 1) -> List[str]:
119
+ """Record an event that may unlock achievements. Returns list of just-unlocked IDs."""
120
+ unlocked = []
121
+
122
+ mapping = {
123
+ "intercept": "guardian",
124
+ "recover": "survivor",
125
+ "validate_pass": "inspector",
126
+ "span": "watcher",
127
+ }
128
+
129
+ ach_id = mapping.get(kind)
130
+ if not ach_id:
131
+ return unlocked
132
+
133
+ ach = self.achievements[ach_id]
134
+ ach.progress += count
135
+
136
+ # Try to unlock next tier
137
+ while not ach.is_maxed:
138
+ target = ach.next_tier_target
139
+ if ach.progress >= target:
140
+ ach.unlocked_at.append(time.time())
141
+ tier_emoji = ach.current_tier.emoji
142
+ tier_name = ach.current_tier.name
143
+ self.recent_unlocks.append({
144
+ "achievement": ach.name,
145
+ "tier": tier_name,
146
+ "emoji": f"{ach.icon} {tier_emoji}",
147
+ "agent": agent,
148
+ "ts": ach.unlocked_at[-1],
149
+ })
150
+ unlocked.append(f"{ach.icon} {tier_emoji} {ach.name} ({tier_name}) โ€” {agent}")
151
+ else:
152
+ break
153
+
154
+ # Check ARK Master (all 4 at Gold+)
155
+ core = ["guardian", "survivor", "inspector", "watcher"]
156
+ master = self.achievements["ark_master"]
157
+ if not master.is_maxed:
158
+ all_gold = all(
159
+ len(self.achievements[a].unlocked_at) >= 3 for a in core
160
+ )
161
+ if all_gold:
162
+ master.progress = 1
163
+ master.unlocked_at.append(time.time())
164
+ self.recent_unlocks.append({
165
+ "achievement": "ARK Master",
166
+ "tier": "PLATINUM",
167
+ "emoji": "๐ŸŽ– ๐Ÿ’Ž",
168
+ "agent": agent,
169
+ "ts": master.unlocked_at[-1],
170
+ })
171
+ unlocked.append("๐ŸŽ– ๐Ÿ’Ž ARK Master โ€” ALL CORE ACHIEVEMENTS UNLOCKED!")
172
+
173
+ return unlocked
174
+
175
+ # โ”€โ”€ rendering โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
176
+
177
+ @property
178
+ def summary(self) -> List[Dict]:
179
+ return [
180
+ {
181
+ "id": ach.id,
182
+ "name": ach.name,
183
+ "icon": ach.icon,
184
+ "progress": ach.progress,
185
+ "next_target": ach.next_tier_target,
186
+ "progress_pct": ach.progress_pct(),
187
+ "tier": f"{ach.current_tier.emoji} {ach.current_tier.name}" if ach.unlocked_at else "๐Ÿ”’ Locked",
188
+ "unlocked_at": ach.unlocked_at.copy() if ach.unlocked_at else [],
189
+ "maxed": ach.is_maxed,
190
+ }
191
+ for ach in self.achievements.values()
192
+ ]
193
+
194
+ def render(self) -> str:
195
+ lines = [
196
+ "โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”",
197
+ "โ”‚ ๐Ÿ† ARK Achievements โ”‚",
198
+ "โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค",
199
+ "โ”‚ Achievement โ”‚ Progress โ”‚ Progress โ”‚ Tier โ”‚",
200
+ "โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค",
201
+ ]
202
+ for s in self.summary:
203
+ pct = f"{s['progress_pct']}%"
204
+ tier = s["tier"]
205
+ bar = _progress_bar(s["progress_pct"])
206
+ lines.append(
207
+ f"โ”‚ {s['icon']} {s['name']:<16} โ”‚ {s['progress']:>8} โ”‚ {bar:<9} โ”‚ {tier:<10} โ”‚"
208
+ )
209
+ lines.append("โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜")
210
+
211
+ if self.recent_unlocks:
212
+ lines.append("\n๐ŸŽ‰ Recent Unlocks:")
213
+ for u in self.recent_unlocks[-5:]:
214
+ lines.append(f" {u['emoji']} {u['achievement']} ({u['tier']})")
215
+
216
+ return "\n".join(lines)
217
+
218
+ def to_json(self) -> str:
219
+ import json
220
+ return json.dumps(self.summary, indent=2, default=str)
221
+
222
+
223
+ def _progress_bar(pct: float, width: int = 8) -> str:
224
+ filled = int(pct / 100 * width)
225
+ empty = width - filled
226
+ return "โ–ˆ" * filled + "โ–‘" * empty
@@ -0,0 +1,68 @@
1
+ """
2
+ ARK Auto-detection + Zero-config bootstrap
3
+ Auto-scans environment for agent frameworks and configures ARK accordingly.
4
+ """
5
+
6
+ import sys
7
+ import importlib
8
+ from typing import Dict, List, Optional
9
+
10
+
11
+ def detect_frameworks() -> List[str]:
12
+ """ๆ‰ซๆ็Žฏๅขƒไธญๅทฒๅฎ‰่ฃ…็š„Agentๆก†ๆžถ"""
13
+ frameworks = {
14
+ "langchain_core": "LangChain",
15
+ "crewai": "CrewAI",
16
+ "autogen": "AutoGen",
17
+ "agno": "Agno",
18
+ "openai": "OpenAI SDK",
19
+ "anthropic": "Anthropic SDK",
20
+ "google.generativeai": "Gemini SDK",
21
+ "llama_index": "LlamaIndex",
22
+ }
23
+ detected = []
24
+ for mod, name in frameworks.items():
25
+ try:
26
+ importlib.import_module(mod)
27
+ detected.append(name)
28
+ except ImportError:
29
+ pass
30
+ return detected
31
+
32
+
33
+ def auto_init() -> Dict:
34
+ """ไธ€้”ฎๅˆๅง‹ๅŒ–ARK โ€” ้›ถ้…็ฝฎ"""
35
+ from .guard import IdempotencyGuard
36
+ from .breaker import CircuitBreaker
37
+ from .validator import OutputValidator
38
+ from .score import ReliabilityScore
39
+ from .schema_registry import SchemaRegistry
40
+
41
+ frameworks = detect_frameworks()
42
+
43
+ config = {
44
+ "frameworks": frameworks,
45
+ "mode": "standalone" if not frameworks else "integrated",
46
+ "guard": IdempotencyGuard(),
47
+ "breaker": CircuitBreaker("auto-detect"),
48
+ "validator": OutputValidator(),
49
+ "score": ReliabilityScore(),
50
+ "registry": SchemaRegistry(),
51
+ }
52
+
53
+ # Auto-init framework hooks
54
+ if "CrewAI" in frameworks:
55
+ try:
56
+ from .crewai import ARKCrewCallback
57
+ config["crewai_callback"] = ARKCrewCallback
58
+ except Exception:
59
+ pass
60
+
61
+ if "LangChain" in frameworks:
62
+ try:
63
+ from .langchain import ARKCallbackHandler
64
+ config["langchain_handler"] = ARKCallbackHandler
65
+ except Exception:
66
+ pass
67
+
68
+ return config