←
TRCKR-282
Created: 2025-12-12
•
Updated: 2025-12-16
Relationships
Loading...
Attachments
Loading...
Comments (2)
qa-agent
·
2025-12-16
## QA PASSED
See QA report document: e9a5ed12-622d-4538-8a5c-0c324dd238a0
All hypotheses tested:
1. Module imports successfully
2. get_agent_info() returns complete, correctly-typed data
3. derive_agent_id() produces stable, correctly-formatted hashes
4. parse_issue_ids_from_branch() handles all edge cases
5. detect_cli_tool() correctly identifies Claude Code, Cursor, Aider
6. get_machine_address() falls back to local IP when Tailscale unavailable
29/29 unit tests pass. 90/90 issue regression tests pass. No issues found. Fix verified working.
agent
·
2025-12-12
Implemented complete agent auto-detection module as specified.
## Created Files
### trckr_agent.py (365 lines)
New module providing all required auto-detection functions:
**Main Functions:**
- `get_agent_info()` - Main entry point that gathers all auto-detectable fields
- `derive_agent_id(hostname, cli_tool, repo_path)` - Creates stable agent ID via SHA256 hash, truncated to 12 chars with 'agt_' prefix
- `get_machine_address()` - Network address detection with fallback chain: Tailscale FQDN → Tailscale IP → local IP
- `parse_issue_ids_from_branch(branch)` - Regex-based extraction of TRCKR-* patterns (case-insensitive, normalized to uppercase)
- `detect_cli_tool()` - Detects Claude Code (CLAUDECODE, CLAUDE_CODE_ENTRYPOINT), Cursor (CURSOR_USER), Aider (AIDER_MODEL)
- `detect_agent_model(model_override, transcript_path)` - Priority-based detection: CLI flag → TRCKR_AGENT_MODEL env → transcript → settings
**Auto-Detected Fields:**
- hostname: socket.gethostname()
- machine_address: Tailscale/local IP via get_machine_address()
- os_platform: sys.platform
- os_version: platform.release()
- repo_path: git rev-parse --show-toplevel
- git_remote: git remote get-url origin
- current_branch: git branch --show-current
- issue_ids: parse_issue_ids_from_branch()
- agent_model: detect_agent_model()
- agent_cli_tool: detect_cli_tool()
- agent_id: derive_agent_id()
**Helper Functions:**
- `_get_git_repo_path()`, `_get_git_remote()`, `_get_current_branch()` - Git operations
- `_get_tailscale_fqdn()`, `_get_tailscale_ip()`, `_get_local_ip()` - Network detection
- `_parse_model_from_transcript()`, `_parse_model_from_settings()` - Model detection
### tests/test_agent_detection.py (312 lines)
Comprehensive test suite with 29 tests across 6 test classes:
**Test Classes:**
- TestDeriveAgentId (5 tests): Hash stability, different inputs, None handling
- TestParseIssueIdsFromBranch (8 tests): Single/multiple issues, case normalization, edge cases
- TestDetectCliTool (5 tests): Claude Code, Cursor, Aider detection, no tool scenario
- TestDetectAgentModel (6 tests): Override priority, env vars, transcript parsing
- TestGetMachineAddress (3 tests): Tailscale FQDN, IP fallback, local IP fallback
- TestGetAgentInfo (2 tests): Complete info gathering, partial/None value handling
## Verification
Tested manually:
```bash
python3 -c "from trckr_agent import get_agent_info; info = get_agent_info(); print(f'Agent ID: {info[\"agent_id\"]}'); print(f'Hostname: {info[\"hostname\"]}')"
# Output:
# Agent ID: agt_6fc977e88224
# Hostname: Mac.localdomain
```
All 29 unit tests pass with full coverage of the new module.
## Implementation Notes
- All timeout values set to 5 seconds for subprocess calls
- Tailscale detection uses `tailscale status --json` to get FQDN and IPs
- Agent ID uses SHA256 for stability (same inputs always produce same ID)
- Issue ID parsing is case-insensitive but normalizes to uppercase
- Graceful degradation: functions return None when detection fails
- No external dependencies beyond stdlib (json, hashlib, socket, subprocess, re, platform, sys)