agent-detector 1.0.0__py3-none-any.whl
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from agent_detector._detector import (
|
|
2
|
+
KNOWN_AGENTS,
|
|
3
|
+
AgentConfidence,
|
|
4
|
+
AgentName,
|
|
5
|
+
DetectionResult,
|
|
6
|
+
DetectionSource,
|
|
7
|
+
detect_agent,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"KNOWN_AGENTS",
|
|
12
|
+
"AgentConfidence",
|
|
13
|
+
"AgentName",
|
|
14
|
+
"DetectionResult",
|
|
15
|
+
"DetectionSource",
|
|
16
|
+
"detect_agent",
|
|
17
|
+
]
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Literal, Optional, cast
|
|
6
|
+
|
|
7
|
+
AgentConfidence = Literal["high", "medium", "low"]
|
|
8
|
+
DetectionSource = Literal["environment", "path"]
|
|
9
|
+
AgentName = Literal[
|
|
10
|
+
"amp",
|
|
11
|
+
"antigravity",
|
|
12
|
+
"augment-cli",
|
|
13
|
+
"claude-code",
|
|
14
|
+
"codex",
|
|
15
|
+
"copilot-cli",
|
|
16
|
+
"cowork",
|
|
17
|
+
"cursor",
|
|
18
|
+
"cursor-cli",
|
|
19
|
+
"gemini-cli",
|
|
20
|
+
"goose",
|
|
21
|
+
"kiro",
|
|
22
|
+
"opencode",
|
|
23
|
+
"pi",
|
|
24
|
+
"replit",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
KNOWN_AGENTS: frozenset[AgentName] = frozenset(
|
|
28
|
+
{
|
|
29
|
+
"amp",
|
|
30
|
+
"antigravity",
|
|
31
|
+
"augment-cli",
|
|
32
|
+
"claude-code",
|
|
33
|
+
"codex",
|
|
34
|
+
"copilot-cli",
|
|
35
|
+
"cowork",
|
|
36
|
+
"cursor",
|
|
37
|
+
"cursor-cli",
|
|
38
|
+
"gemini-cli",
|
|
39
|
+
"goose",
|
|
40
|
+
"kiro",
|
|
41
|
+
"opencode",
|
|
42
|
+
"pi",
|
|
43
|
+
"replit",
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
_PI_AGENT_PATH = re.compile(r"(?:^|[\\/])\.pi[\\/]agent(?:[\\/]|$)")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class DetectionResult:
|
|
52
|
+
"""Evidence that an AI coding agent is driving the current process."""
|
|
53
|
+
|
|
54
|
+
agent: AgentName
|
|
55
|
+
confidence: AgentConfidence
|
|
56
|
+
source: DetectionSource
|
|
57
|
+
signal: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def detect_agent(
|
|
61
|
+
environ: Optional[Mapping[str, str]] = None,
|
|
62
|
+
*,
|
|
63
|
+
minimum_confidence: AgentConfidence = "low",
|
|
64
|
+
) -> Optional[DetectionResult]:
|
|
65
|
+
"""Detect the AI coding agent driving the current process, if any.
|
|
66
|
+
|
|
67
|
+
Detection is best-effort. A ``None`` result means "unattributed", not "human".
|
|
68
|
+
|
|
69
|
+
Values from the environment are inspected locally but are never included in
|
|
70
|
+
the returned result.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
values = os.environ if environ is None else environ
|
|
74
|
+
|
|
75
|
+
if minimum_confidence not in ("high", "medium", "low"):
|
|
76
|
+
raise ValueError("minimum_confidence must be 'high', 'medium', or 'low'")
|
|
77
|
+
|
|
78
|
+
confidence_order: tuple[AgentConfidence, ...] = ("high", "medium", "low")
|
|
79
|
+
minimum_confidence_index = confidence_order.index(minimum_confidence)
|
|
80
|
+
candidates: list[DetectionResult] = []
|
|
81
|
+
|
|
82
|
+
# An explicit known identity is checked before inferred signals.
|
|
83
|
+
explicit_agent = values.get("AI_AGENT", "")
|
|
84
|
+
if explicit_agent in KNOWN_AGENTS:
|
|
85
|
+
candidates.append(
|
|
86
|
+
DetectionResult(cast(AgentName, explicit_agent), "high", "environment", "AI_AGENT")
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Amp sets CLAUDECODE too, so its more specific signals must win.
|
|
90
|
+
if values.get("AGENT") == "amp":
|
|
91
|
+
candidates.append(DetectionResult("amp", "high", "environment", "AGENT"))
|
|
92
|
+
if values.get("AMP_CURRENT_THREAD_ID"):
|
|
93
|
+
candidates.append(DetectionResult("amp", "medium", "environment", "AMP_CURRENT_THREAD_ID"))
|
|
94
|
+
|
|
95
|
+
# OpenAI Codex CLI.
|
|
96
|
+
for signal in ("CODEX_THREAD_ID", "CODEX_CI", "CODEX_SANDBOX"):
|
|
97
|
+
if values.get(signal):
|
|
98
|
+
candidates.append(DetectionResult("codex", "high", "environment", signal))
|
|
99
|
+
|
|
100
|
+
# Google Gemini CLI.
|
|
101
|
+
if values.get("GEMINI_CLI"):
|
|
102
|
+
candidates.append(DetectionResult("gemini-cli", "high", "environment", "GEMINI_CLI"))
|
|
103
|
+
|
|
104
|
+
# GitHub Copilot CLI. This signal is observed but not publicly documented.
|
|
105
|
+
if values.get("COPILOT_CLI"):
|
|
106
|
+
candidates.append(DetectionResult("copilot-cli", "medium", "environment", "COPILOT_CLI"))
|
|
107
|
+
|
|
108
|
+
# OpenCode sets OPENCODE for the running agent. OPENCODE_CLIENT and
|
|
109
|
+
# OPENCODE_CALLER identify its launcher, so they are intentionally ignored.
|
|
110
|
+
if values.get("OPENCODE"):
|
|
111
|
+
candidates.append(DetectionResult("opencode", "high", "environment", "OPENCODE"))
|
|
112
|
+
|
|
113
|
+
if values.get("ANTIGRAVITY_AGENT"):
|
|
114
|
+
candidates.append(
|
|
115
|
+
DetectionResult("antigravity", "medium", "environment", "ANTIGRAVITY_AGENT")
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
if values.get("AUGMENT_AGENT"):
|
|
119
|
+
candidates.append(DetectionResult("augment-cli", "medium", "environment", "AUGMENT_AGENT"))
|
|
120
|
+
|
|
121
|
+
# Cowork and Claude Code share ambient Claude markers. Check Cowork first.
|
|
122
|
+
if values.get("CLAUDE_CODE_IS_COWORK"):
|
|
123
|
+
candidates.append(DetectionResult("cowork", "high", "environment", "CLAUDE_CODE_IS_COWORK"))
|
|
124
|
+
|
|
125
|
+
# This specifically marks commands spawned by Claude Code.
|
|
126
|
+
if values.get("CLAUDE_CODE_CHILD_SESSION"):
|
|
127
|
+
candidates.append(
|
|
128
|
+
DetectionResult("claude-code", "high", "environment", "CLAUDE_CODE_CHILD_SESSION")
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# These can also exist in Claude's integrated terminal, so they carry less
|
|
132
|
+
# confidence than the child-session signal.
|
|
133
|
+
for signal in ("CLAUDECODE", "CLAUDE_CODE"):
|
|
134
|
+
if values.get(signal):
|
|
135
|
+
candidates.append(DetectionResult("claude-code", "medium", "environment", signal))
|
|
136
|
+
|
|
137
|
+
# Cursor IDE and Cursor CLI are distinguishable when both signals exist.
|
|
138
|
+
if values.get("CURSOR_TRACE_ID"):
|
|
139
|
+
candidates.append(DetectionResult("cursor", "medium", "environment", "CURSOR_TRACE_ID"))
|
|
140
|
+
|
|
141
|
+
if values.get("CURSOR_AGENT"):
|
|
142
|
+
candidates.append(DetectionResult("cursor-cli", "high", "environment", "CURSOR_AGENT"))
|
|
143
|
+
|
|
144
|
+
if values.get("CURSOR_EXTENSION_HOST_ROLE") == "agent-exec":
|
|
145
|
+
candidates.append(
|
|
146
|
+
DetectionResult("cursor-cli", "medium", "environment", "CURSOR_EXTENSION_HOST_ROLE")
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# The following signals are broader or have less first-party evidence, so
|
|
150
|
+
# they are checked only after the more specific agent signals above.
|
|
151
|
+
if values.get("TERM_PROGRAM") == "kiro":
|
|
152
|
+
candidates.append(DetectionResult("kiro", "low", "environment", "TERM_PROGRAM"))
|
|
153
|
+
|
|
154
|
+
path = values.get("PATH", "")
|
|
155
|
+
if _PI_AGENT_PATH.search(path):
|
|
156
|
+
candidates.append(DetectionResult("pi", "medium", "path", "PATH"))
|
|
157
|
+
|
|
158
|
+
if values.get("REPL_ID"):
|
|
159
|
+
candidates.append(DetectionResult("replit", "low", "environment", "REPL_ID"))
|
|
160
|
+
|
|
161
|
+
if values.get("GOOSE_PROVIDER"):
|
|
162
|
+
candidates.append(DetectionResult("goose", "low", "environment", "GOOSE_PROVIDER"))
|
|
163
|
+
|
|
164
|
+
return next(
|
|
165
|
+
(
|
|
166
|
+
candidate
|
|
167
|
+
for candidate in candidates
|
|
168
|
+
if confidence_order.index(candidate.confidence) <= minimum_confidence_index
|
|
169
|
+
),
|
|
170
|
+
None,
|
|
171
|
+
)
|
agent_detector/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-detector
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Detect AI coding agents from their execution environment
|
|
5
|
+
Project-URL: Homepage, https://github.com/patrick91/agent-detector
|
|
6
|
+
Project-URL: Repository, https://github.com/patrick91/agent-detector
|
|
7
|
+
Project-URL: Issues, https://github.com/patrick91/agent-detector/issues
|
|
8
|
+
Author: Patrick Arminio
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: agent,ai,claude,cli,codex,telemetry
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Agent Detector
|
|
28
|
+
|
|
29
|
+
`agent-detector` is a small, dependency-free Python package for detecting which
|
|
30
|
+
AI coding agent is driving the current process.
|
|
31
|
+
|
|
32
|
+
It returns evidence rather than only a boolean, so callers can distinguish an
|
|
33
|
+
explicit identity from a broad environmental hint.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install agent-detector
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from agent_detector import detect_agent
|
|
45
|
+
|
|
46
|
+
detection = detect_agent()
|
|
47
|
+
|
|
48
|
+
if detection:
|
|
49
|
+
print(detection.agent) # "codex"
|
|
50
|
+
print(detection.confidence) # "high"
|
|
51
|
+
print(detection.signal) # "CODEX_THREAD_ID"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The returned `DetectionResult` contains:
|
|
55
|
+
|
|
56
|
+
- `agent`: an `AgentName` literal containing a supported agent name
|
|
57
|
+
- `confidence`: `high`, `medium`, or `low`
|
|
58
|
+
- `source`: `environment` or `path`
|
|
59
|
+
- `signal`: the name of the matched signal, never its value
|
|
60
|
+
|
|
61
|
+
Pass a mapping to make detection deterministic in tests:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
assert detect_agent({"OPENCODE": "1"}).agent == "opencode"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Require a minimum confidence when broad environmental hints are not useful:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
detection = detect_agent(minimum_confidence="high")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`minimum_confidence` is typed as `Literal["high", "medium", "low"]` and
|
|
74
|
+
defaults to `"low"`.
|
|
75
|
+
|
|
76
|
+
## Supported agents
|
|
77
|
+
|
|
78
|
+
| Agent | Signals | Confidence |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| Explicit override | `AI_AGENT` containing a supported agent name | high |
|
|
81
|
+
| Amp | `AGENT=amp`, `AMP_CURRENT_THREAD_ID` | high / medium |
|
|
82
|
+
| Codex | `CODEX_THREAD_ID`, `CODEX_CI`, `CODEX_SANDBOX` | high |
|
|
83
|
+
| Gemini CLI | `GEMINI_CLI` | high |
|
|
84
|
+
| Copilot CLI | `COPILOT_CLI` | medium |
|
|
85
|
+
| OpenCode | `OPENCODE` | high |
|
|
86
|
+
| Antigravity | `ANTIGRAVITY_AGENT` | medium |
|
|
87
|
+
| Augment CLI | `AUGMENT_AGENT` | medium |
|
|
88
|
+
| Cowork | `CLAUDE_CODE_IS_COWORK` | high |
|
|
89
|
+
| Claude Code | `CLAUDE_CODE_CHILD_SESSION`, `CLAUDECODE`, `CLAUDE_CODE` | high / medium |
|
|
90
|
+
| Cursor | `CURSOR_TRACE_ID` | medium |
|
|
91
|
+
| Cursor CLI | `CURSOR_AGENT`, `CURSOR_EXTENSION_HOST_ROLE=agent-exec` | high / medium |
|
|
92
|
+
| Kiro | `TERM_PROGRAM=kiro` | low |
|
|
93
|
+
| Pi | `.pi/agent` entry in `PATH` | medium |
|
|
94
|
+
| Replit | `REPL_ID` | low |
|
|
95
|
+
| Goose | `GOOSE_PROVIDER` | low |
|
|
96
|
+
|
|
97
|
+
`AI_AGENT` takes precedence over inferred signals when its value is one of the
|
|
98
|
+
supported agent names. Unknown values are ignored.
|
|
99
|
+
|
|
100
|
+
The detector is deliberately ordered. For example, Amp is checked before
|
|
101
|
+
Claude Code because Amp also sets `CLAUDECODE`.
|
|
102
|
+
|
|
103
|
+
## Important limitations
|
|
104
|
+
|
|
105
|
+
Detection is best-effort. `None` means **unattributed**, not "human". Some
|
|
106
|
+
signals can also be present in an integrated terminal where a person typed the
|
|
107
|
+
command manually.
|
|
108
|
+
|
|
109
|
+
This package detects the execution harness. It cannot determine whether a
|
|
110
|
+
particular skill, plugin, prompt, or model caused the command. Use a separate
|
|
111
|
+
explicit marker when that attribution matters.
|
|
112
|
+
|
|
113
|
+
## Privacy
|
|
114
|
+
|
|
115
|
+
Environment values such as thread IDs are never returned. A result contains
|
|
116
|
+
only a normalized agent name and the name and category of the matched signal.
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
uv sync --all-groups
|
|
122
|
+
uv run ruff check .
|
|
123
|
+
uv run ruff format --check .
|
|
124
|
+
uv run mypy
|
|
125
|
+
uv run pytest
|
|
126
|
+
uv build
|
|
127
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
agent_detector/__init__.py,sha256=kU9nRrHT7TWT-GCpzQUkca2pSPlOVmNSinKe6HZi4Ec,296
|
|
2
|
+
agent_detector/_detector.py,sha256=QSu8HNVQJX3In8DuS-8isPE_ppc-GzJ_a6lvsWnOKIY,5935
|
|
3
|
+
agent_detector/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
4
|
+
agent_detector-1.0.0.dist-info/METADATA,sha256=jMTgQBHAz770f8FMC5Dv9zpX2jVZ2yydVm1kiPpmTLk,4177
|
|
5
|
+
agent_detector-1.0.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
6
|
+
agent_detector-1.0.0.dist-info/licenses/LICENSE,sha256=pFgSIuwDZh_CA1OuRDQ1k2oD1IdkWDwoLw4xQZ06Q-4,1072
|
|
7
|
+
agent_detector-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Patrick Arminio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|