Agents
dotagents._agents
Agent registry: base Agent type + per-agent adapters (Plan 00).
Agent
Base class for dotagents adapters.
Identity (plan 08): each adapter declares its harness_id (the stable
ecosystem name, e.g. claude-code -- NOT the short registry name),
vendor (provider family), and model_source_vars (the vendor-native
env vars to read a running model id from, in precedence order). These feed
stamp_identity which emits the standardized AGENTS_*/AGENT vars.
context_files = []
class-attribute
instance-attribute
detect_env_vars = []
class-attribute
instance-attribute
harness_id = ''
class-attribute
instance-attribute
harness_loads = []
class-attribute
instance-attribute
model_source_vars = []
class-attribute
instance-attribute
name = ''
class-attribute
instance-attribute
vendor = ''
class-attribute
instance-attribute
detect(root)
Return True if this agent's config is present in the given root.
Source code in src/dotagents/_agents.py
67 68 69 | |
detect_env(environ)
Return True if this agent's harness is running based on env vars.
Default: True if any declared marker var is present. Adapters whose
markers are prefixes (e.g. Codex's CODEX_SANDBOX_*) override this.
Source code in src/dotagents/_agents.py
29 30 31 32 33 34 35 | |
resolve_model(environ)
Return the running model id from the first populated source var, or None.
Source code in src/dotagents/_agents.py
37 38 39 40 41 42 43 | |
wire_hooks(dest, *, dry_run, logger, config_root=None)
Wire up hooks in the agent's settings, if this adapter supports it.
A no-op on the base class: the hook schema is harness-specific, so only
adapters with a verified schema override this. config_root overrides
the agent's own config dir (e.g. ~/.claude) and exists so tests can
redirect writes away from the real one.
Source code in src/dotagents/_agents.py
55 56 57 58 59 60 61 62 63 64 65 | |
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Write the base configuration files for this agent (used by init/install).
Source code in src/dotagents/_agents.py
45 46 47 48 49 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Write the assembled context file for this agent (used by context generator).
Source code in src/dotagents/_agents.py
51 52 53 | |
AntigravityAgent
Bases: Agent
PRETOOLUSE_HOOK_SCRIPT = 'preinvocation_antigravity_context.py'
class-attribute
instance-attribute
context_files = ['.agents/rules/dotagents.md']
class-attribute
instance-attribute
detect_env_vars = []
class-attribute
instance-attribute
harness_id = 'antigravity'
class-attribute
instance-attribute
harness_loads = ['~/.gemini/GEMINI.md', '.agents/rules/dotagents.md']
class-attribute
instance-attribute
model_source_vars = []
class-attribute
instance-attribute
name = 'antigravity'
class-attribute
instance-attribute
vendor = 'google'
class-attribute
instance-attribute
wire_hooks(dest, *, dry_run, logger, config_root=None)
Deploys the context-injection script and wires it as a
PreInvocation handler in <config_root|~/.gemini/config>/hooks.json.
Global scope only (~/.gemini/config/hooks.json), like the plugin
directory it mirrors (~/.gemini/config/plugins/) -- Antigravity's
docs describe this as making a plugin/hook "active across all
workspaces", and PreInvocation carries no per-project matcher to
scope it more narrowly (confirmed: PreInvocation's matcher is
documented as ignored).
Source code in src/dotagents/_agents.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
449 450 451 452 453 454 455 456 457 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
459 460 461 462 463 464 | |
ClaudeAgent
Bases: Agent
CWD_CHANGED_COMMAND = '[ -f AGENTS.md ] && cat AGENTS.md || true'
class-attribute
instance-attribute
CWD_CHANGED_COMMAND_POWERSHELL = 'if (Test-Path AGENTS.md) { Get-Content AGENTS.md -Raw }'
class-attribute
instance-attribute
PRETOOLUSE_POWERSHELL_COMMAND = '$h = [Console]::In.ReadToEnd() | ConvertFrom-Json; if ($h.tool_name -eq "PowerShell" -and -not $env:AGENTS_RUNTIME_SET -and $h.tool_input.command) { $p = \'if (-not $env:AGENTS_RUNTIME_SET) { $env:AGENTS_RUNTIME_SET = "1"; & "$HOME\\.agents\\bin\\dotagents.cmd" env --format powershell 2>$null | Invoke-Expression }; \'; $u = $h.tool_input.PSObject.Copy(); $u.command = $p + $h.tool_input.command; @{hookSpecificOutput=@{hookEventName="PreToolUse";permissionDecision="allow";updatedInput=$u}} | ConvertTo-Json -Depth 10 -Compress }'
class-attribute
instance-attribute
SESSION_START_COMMAND = 'if [ -n "$CLAUDE_ENV_FILE" ]; then %(path)s dotagents env --diff --format export >> "$CLAUDE_ENV_FILE"; fi; %(path)s dotagents context' % {'path': _HOOK_PATH}
class-attribute
instance-attribute
SESSION_START_COMMAND_POWERSHELL = '& "$env:USERPROFILE\\.agents\\bin\\dotagents.cmd" context'
class-attribute
instance-attribute
context_files = ['CLAUDE.md']
class-attribute
instance-attribute
detect_env_vars = ['CLAUDECODE', 'CLAUDE_CODE_ENTRYPOINT']
class-attribute
instance-attribute
harness_id = 'claude-code'
class-attribute
instance-attribute
harness_loads = ['~/.agents/AGENTS.md', 'AGENTS.md']
class-attribute
instance-attribute
model_source_vars = ['ANTHROPIC_MODEL']
class-attribute
instance-attribute
name = 'claude'
class-attribute
instance-attribute
vendor = 'anthropic'
class-attribute
instance-attribute
wire_hooks(dest, *, dry_run, logger, config_root=None)
Link the shared skills dir into ~/.claude and merge our two hooks.
Additive and idempotent: unrelated settings keys and foreign hooks survive, and a second run writes nothing.
Source code in src/dotagents/_agents.py
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 | |
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
382 383 384 385 386 387 | |
CodexAgent
Bases: Agent
ENV_BLOCK_BEGIN = '# dotagents:begin'
class-attribute
instance-attribute
ENV_BLOCK_END = '# dotagents:end'
class-attribute
instance-attribute
ENV_BLOCK_SKIP = frozenset({'PATH'})
class-attribute
instance-attribute
PRETOOLUSE_HOOK_SCRIPT = 'pretooluse_codex_env.py'
class-attribute
instance-attribute
SESSION_START_COMMAND = 'PATH=".agents/bin:$HOME/.agents/bin:$PATH" dotagents context'
class-attribute
instance-attribute
context_files = ['AGENTS.md']
class-attribute
instance-attribute
detect_env_vars = ['CODEX_HOME', 'CODEX_SANDBOX']
class-attribute
instance-attribute
harness_id = 'codex'
class-attribute
instance-attribute
harness_loads = ['AGENTS.md']
class-attribute
instance-attribute
model_source_vars = ['OPENAI_MODEL']
class-attribute
instance-attribute
name = 'codex'
class-attribute
instance-attribute
vendor = 'openai'
class-attribute
instance-attribute
detect_env(environ)
Source code in src/dotagents/_agents.py
582 583 584 585 586 | |
wire_hooks(dest, *, dry_run, logger, config_root=None)
Merge SessionStart + PreToolUse into <codex-home>/hooks.json, and
deploy the PreToolUse env-loader script alongside it.
Source code in src/dotagents/_agents.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 | |
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
588 589 590 591 592 593 594 595 596 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
818 819 820 821 822 823 | |
write_env_block(env, *, dry_run, logger, config_root=None)
Write env into a managed [shell_environment_policy] block in
config.toml, so Codex injects those vars into every subprocess.
Source code in src/dotagents/_agents.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
CopilotAgent
Bases: Agent
context_files = ['.github/copilot-instructions.md']
class-attribute
instance-attribute
detect_env_vars = []
class-attribute
instance-attribute
harness_id = 'copilot'
class-attribute
instance-attribute
harness_loads = ['.github/copilot-instructions.md']
class-attribute
instance-attribute
model_source_vars = ['COPILOT_MODEL']
class-attribute
instance-attribute
name = 'copilot'
class-attribute
instance-attribute
vendor = 'github'
class-attribute
instance-attribute
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
871 872 873 874 875 876 877 878 879 880 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
882 883 884 885 886 887 | |
CursorAgent
Bases: Agent
context_files = ['.cursorrules', '.cursor/rules/']
class-attribute
instance-attribute
detect_env_vars = ['CURSOR_AGENT']
class-attribute
instance-attribute
harness_id = 'cursor'
class-attribute
instance-attribute
harness_loads = ['.cursorrules', '.cursor/rules/']
class-attribute
instance-attribute
model_source_vars = ['CURSOR_DEFAULT_MODEL']
class-attribute
instance-attribute
name = 'cursor'
class-attribute
instance-attribute
vendor = 'cursor'
class-attribute
instance-attribute
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
839 840 841 842 843 844 845 846 847 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
849 850 851 852 853 854 | |
GeminiAgent
Bases: Agent
context_files = ['GEMINI.md']
class-attribute
instance-attribute
detect_env_vars = ['GEMINI_CLI']
class-attribute
instance-attribute
harness_id = 'gemini-cli'
class-attribute
instance-attribute
harness_loads = ['GEMINI.md']
class-attribute
instance-attribute
model_source_vars = ['GEMINI_MODEL']
class-attribute
instance-attribute
name = 'gemini'
class-attribute
instance-attribute
vendor = 'google'
class-attribute
instance-attribute
write_base_config(dest, src, base_agents_text, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
402 403 404 405 406 407 408 409 410 | |
write_context(dest, effective_context, *, force, dry_run, logger)
Source code in src/dotagents/_agents.py
412 413 414 415 416 417 | |
get_agent(name)
Source code in src/dotagents/_agents.py
900 901 902 | |
get_all_agents()
Source code in src/dotagents/_agents.py
904 905 | |
resolve_active_agent(environ, explicit=None, root=None)
Resolve the active agent by precedence (plan 00).
Precedence: explicit (--agents) > $AGENTS_HARNESS (registry name or harness_id) > env-var detection (detect_env) > config-file detection (detect(root)) > default (claude).
root is where config-file detect() looks (default: cwd).
Source code in src/dotagents/_agents.py
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | |
stamp_identity(environ, explicit=None, root=None)
Return the standardized AGENTS_* / AGENT identity vars (plan 08).
Emits AGENTS_HARNESS (the harness_id, e.g. claude-code -- NOT the
short name), AGENTS_VENDOR, AGENT (= AGENTS_HARNESS, aligning with
the emerging ecosystem marker used by Goose/Amp; agentsmd/agents.md#136),
and, when derivable, AGENTS_MODEL (from the adapter's vendor model var)
and AGENTS_AGENT (a named persona, from $AGENTS_AGENT if already set).
Never emits a var it cannot source (no empty AGENTS_MODEL=). Does NOT
clobber a value already set in environ -- an explicit user/harness value
wins. The deliberate curated mapping replaces the precursor's blanket
CLAUDE_*->AGENTS_* rewrite (no AGENTS_CODE_SESSION_ID junk).
Source code in src/dotagents/_agents.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |