Rules
agent_gate.rules
¶
Layer 1: deterministic rules.
These checks are lookups and pattern matches. No wording of a command can talk them out of a verdict, which is why they run first and why the model gate may only make their verdicts stricter.
The shell checks are heuristics, not a shell parser. They catch the common shapes of network access, outward actions, identity changes and writes outside the mandate. A command they cannot read is sent to a person.
ask(law, reason)
¶
An ask from the rules layer.
Source code in src/agent_gate/rules.py
184 185 186 | |
check(action, mandate)
¶
Layer 1: judge one action against the mandate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
the action. |
required |
mandate
|
Mandate
|
the governing mandate. |
required |
Source code in src/agent_gate/rules.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
check_bash(action, mandate)
¶
Judge a Bash command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
a Bash action. |
required |
mandate
|
Mandate
|
the governing mandate. |
required |
Source code in src/agent_gate/rules.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
check_delegation(action, mandate)
¶
Judge the prompt of a subagent call (Agent, or Task in older Claude Code).
A subagent's own tool calls reach the gate too, but its prompt is where an agent hands off what it may not do itself. The prompt is prose, so what it names outside the mandate goes to a person; it is not denied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
an |
required |
mandate
|
Mandate
|
the governing mandate. |
required |
Source code in src/agent_gate/rules.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
check_history(action, mandate, entries, digest)
¶
Layer 1, history: actions that resemble blocked ones, and repeated denials.
A close resemblance to a denied action asks a person rather than
denying: the rules still deny a true repeat on their own, and a
rewording that slips past them goes to a person. Repeated denials count
only within the last :data:DENIAL_WINDOW consequential actions, so a burst of
blocked attempts stops the agent but a long session recovers once the
agent works inside the mandate again. Only denials made under the
current mandate count, so a person also clears them by changing the
mandate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
the action. |
required |
mandate
|
Mandate
|
the governing mandate. |
required |
entries
|
list[dict[str, Any]]
|
the session's ledger entries. |
required |
digest
|
str
|
the current mandate's digest. |
required |
Source code in src/agent_gate/rules.py
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 | |
deny(law, reason)
¶
A deny from the rules layer.
Source code in src/agent_gate/rules.py
179 180 181 | |
drop_heredoc_text(command)
¶
Remove the bodies of heredocs that feed a program other than a shell.
A heredoc fed to cat or python is text, not commands; reading its
lines as commands gives false alarms. A heredoc fed to a shell keeps its
body, since those lines are commands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
the command line. |
required |
Source code in src/agent_gate/rules.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
normalize_remote(url)
¶
Reduce a git URL to host/owner/repo, lowercased.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
an https, ssh, git or scp-style ( |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
the normalized remote, or |
Source code in src/agent_gate/rules.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
split_commands(command)
¶
Split a shell command at ;, |, &&, || and newlines outside quotes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
the command line. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
the stripped, non-empty pieces. |
Source code in src/agent_gate/rules.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |