dinoguard 0.1.0__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.
- dinoguard-0.1.0/LICENSE +21 -0
- dinoguard-0.1.0/PKG-INFO +135 -0
- dinoguard-0.1.0/README.md +116 -0
- dinoguard-0.1.0/dinoguard/__init__.py +23 -0
- dinoguard-0.1.0/dinoguard/__main__.py +5 -0
- dinoguard-0.1.0/dinoguard/adapters/__init__.py +53 -0
- dinoguard-0.1.0/dinoguard/adapters/antigravity.py +104 -0
- dinoguard-0.1.0/dinoguard/adapters/base.py +66 -0
- dinoguard-0.1.0/dinoguard/adapters/claude_code.py +146 -0
- dinoguard-0.1.0/dinoguard/adapters/claude_like.py +109 -0
- dinoguard-0.1.0/dinoguard/adapters/codex.py +51 -0
- dinoguard-0.1.0/dinoguard/adapters/common.py +92 -0
- dinoguard-0.1.0/dinoguard/adapters/copilot.py +52 -0
- dinoguard-0.1.0/dinoguard/adapters/cursor.py +91 -0
- dinoguard-0.1.0/dinoguard/adapters/gemini.py +57 -0
- dinoguard-0.1.0/dinoguard/adapters/goose.py +75 -0
- dinoguard-0.1.0/dinoguard/adapters/hermes.py +98 -0
- dinoguard-0.1.0/dinoguard/adapters/install.py +169 -0
- dinoguard-0.1.0/dinoguard/adapters/more_install.py +201 -0
- dinoguard-0.1.0/dinoguard/adapters/opencode.py +68 -0
- dinoguard-0.1.0/dinoguard/adapters/other_install.py +204 -0
- dinoguard-0.1.0/dinoguard/adapters/plugin_bridge.py +140 -0
- dinoguard-0.1.0/dinoguard/adapters/sdk.py +71 -0
- dinoguard-0.1.0/dinoguard/alerts/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/alerts/channels.py +144 -0
- dinoguard-0.1.0/dinoguard/alerts/engine.py +200 -0
- dinoguard-0.1.0/dinoguard/alerts/nl.py +94 -0
- dinoguard-0.1.0/dinoguard/analytics/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/analytics/compare.py +74 -0
- dinoguard-0.1.0/dinoguard/analytics/errors.py +48 -0
- dinoguard-0.1.0/dinoguard/analytics/export.py +28 -0
- dinoguard-0.1.0/dinoguard/analytics/stats.py +58 -0
- dinoguard-0.1.0/dinoguard/approvals/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/approvals/flow.py +108 -0
- dinoguard-0.1.0/dinoguard/approvals/setup.py +55 -0
- dinoguard-0.1.0/dinoguard/assistant/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/assistant/chats.py +19 -0
- dinoguard-0.1.0/dinoguard/assistant/mcp_http.py +95 -0
- dinoguard-0.1.0/dinoguard/assistant/mcp_server.py +125 -0
- dinoguard-0.1.0/dinoguard/assistant/mcp_write.py +134 -0
- dinoguard-0.1.0/dinoguard/assistant/nl2sql.py +128 -0
- dinoguard-0.1.0/dinoguard/audit/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/audit/contract.py +112 -0
- dinoguard-0.1.0/dinoguard/audit/findings.py +79 -0
- dinoguard-0.1.0/dinoguard/audit/replay.py +229 -0
- dinoguard-0.1.0/dinoguard/audit/runs.py +72 -0
- dinoguard-0.1.0/dinoguard/audit/schedule.py +71 -0
- dinoguard-0.1.0/dinoguard/authoring/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/authoring/backtest.py +71 -0
- dinoguard-0.1.0/dinoguard/authoring/draft.py +123 -0
- dinoguard-0.1.0/dinoguard/authoring/templates.py +54 -0
- dinoguard-0.1.0/dinoguard/cli/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/cli/__main__.py +5 -0
- dinoguard-0.1.0/dinoguard/cli/core.py +263 -0
- dinoguard-0.1.0/dinoguard/cli/data.py +142 -0
- dinoguard-0.1.0/dinoguard/cli/main.py +178 -0
- dinoguard-0.1.0/dinoguard/cli/ops.py +274 -0
- dinoguard-0.1.0/dinoguard/cli/pol.py +154 -0
- dinoguard-0.1.0/dinoguard/config.py +111 -0
- dinoguard-0.1.0/dinoguard/daemon/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/daemon/__main__.py +5 -0
- dinoguard-0.1.0/dinoguard/daemon/client.py +59 -0
- dinoguard-0.1.0/dinoguard/daemon/server.py +207 -0
- dinoguard-0.1.0/dinoguard/daemon/transport.py +54 -0
- dinoguard-0.1.0/dinoguard/dashboard/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/dashboard/api_core.py +226 -0
- dinoguard-0.1.0/dinoguard/dashboard/api_ops.py +247 -0
- dinoguard-0.1.0/dinoguard/dashboard/app.py +86 -0
- dinoguard-0.1.0/dinoguard/dashboard/metrics.py +72 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/app.css +71 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/app.js +83 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/charts.js +91 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/index.html +44 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/pages_analytics.js +46 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/pages_main.js +128 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/pages_ops.js +96 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/pages_policy.js +75 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/runner.html +20 -0
- dinoguard-0.1.0/dinoguard/dashboard/static/runner.js +81 -0
- dinoguard-0.1.0/dinoguard/dashboard/trace.py +82 -0
- dinoguard-0.1.0/dinoguard/deploy/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/deploy/versions.py +91 -0
- dinoguard-0.1.0/dinoguard/engine/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/engine/authority.py +15 -0
- dinoguard-0.1.0/dinoguard/engine/context.py +136 -0
- dinoguard-0.1.0/dinoguard/engine/decisions.py +76 -0
- dinoguard-0.1.0/dinoguard/engine/events.py +94 -0
- dinoguard-0.1.0/dinoguard/engine/modes.py +27 -0
- dinoguard-0.1.0/dinoguard/engine/registry.py +256 -0
- dinoguard-0.1.0/dinoguard/engine/runner.py +203 -0
- dinoguard-0.1.0/dinoguard/evals/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/evals/draft.py +79 -0
- dinoguard-0.1.0/dinoguard/evals/manage.py +155 -0
- dinoguard-0.1.0/dinoguard/evals/runner.py +106 -0
- dinoguard-0.1.0/dinoguard/evals/safe_eval.py +81 -0
- dinoguard-0.1.0/dinoguard/evals/sentiment.py +34 -0
- dinoguard-0.1.0/dinoguard/frameworks.py +227 -0
- dinoguard-0.1.0/dinoguard/hook/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/hook/__main__.py +5 -0
- dinoguard-0.1.0/dinoguard/hook/client.py +140 -0
- dinoguard-0.1.0/dinoguard/integrations.py +86 -0
- dinoguard-0.1.0/dinoguard/llm.py +68 -0
- dinoguard-0.1.0/dinoguard/otel/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/otel/ingest.py +72 -0
- dinoguard-0.1.0/dinoguard/packs/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/packs/build.py +36 -0
- dinoguard-0.1.0/dinoguard/packs/install.py +135 -0
- dinoguard-0.1.0/dinoguard/packs/loader.py +93 -0
- dinoguard-0.1.0/dinoguard/packs/manifest.py +101 -0
- dinoguard-0.1.0/dinoguard/packs/source.py +96 -0
- dinoguard-0.1.0/dinoguard/paths.py +85 -0
- dinoguard-0.1.0/dinoguard/policies/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/_common.py +82 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/_probe.py +52 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/_shell.py +222 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/ai_behaviour.py +161 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/approval.py +42 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/contract.py +22 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/dangerous.py +127 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/database.py +69 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/env.py +126 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/git.py +110 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/infra.py +100 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/packages.py +116 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/secrets.py +84 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/self_protect.py +138 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/tokens.py +84 -0
- dinoguard-0.1.0/dinoguard/policies/builtin/workflow.py +106 -0
- dinoguard-0.1.0/dinoguard/reviewer/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/reviewer/checks.py +111 -0
- dinoguard-0.1.0/dinoguard/reviewer/review.py +170 -0
- dinoguard-0.1.0/dinoguard/runner_ui/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/runner_ui/app.py +86 -0
- dinoguard-0.1.0/dinoguard/runner_ui/art.py +62 -0
- dinoguard-0.1.0/dinoguard/runner_ui/demo.py +76 -0
- dinoguard-0.1.0/dinoguard/runner_ui/notch.py +342 -0
- dinoguard-0.1.0/dinoguard/runner_ui/notch_model.py +208 -0
- dinoguard-0.1.0/dinoguard/runner_ui/notch_os.py +130 -0
- dinoguard-0.1.0/dinoguard/runner_ui/scene.py +130 -0
- dinoguard-0.1.0/dinoguard/runner_ui/state.py +83 -0
- dinoguard-0.1.0/dinoguard/secrets/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/secrets/scanner.py +149 -0
- dinoguard-0.1.0/dinoguard/service.py +96 -0
- dinoguard-0.1.0/dinoguard/store/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/store/db.py +58 -0
- dinoguard-0.1.0/dinoguard/store/drift.py +52 -0
- dinoguard-0.1.0/dinoguard/store/migrations/001_init.sql +75 -0
- dinoguard-0.1.0/dinoguard/store/migrations/002_inventory.sql +17 -0
- dinoguard-0.1.0/dinoguard/store/migrations/003_mcp.sql +6 -0
- dinoguard-0.1.0/dinoguard/store/queries.py +70 -0
- dinoguard-0.1.0/dinoguard/store/retention.py +100 -0
- dinoguard-0.1.0/dinoguard/store/writer.py +161 -0
- dinoguard-0.1.0/dinoguard/tokens/__init__.py +1 -0
- dinoguard-0.1.0/dinoguard/tokens/prices.py +110 -0
- dinoguard-0.1.0/dinoguard/tokens/prices.yaml +129 -0
- dinoguard-0.1.0/dinoguard/tokens/transcript.py +103 -0
- dinoguard-0.1.0/dinoguard/tracer.py +146 -0
- dinoguard-0.1.0/dinoguard/undo.py +105 -0
- dinoguard-0.1.0/dinoguard/util.py +59 -0
- dinoguard-0.1.0/dinoguard/version.py +5 -0
- dinoguard-0.1.0/dinoguard.egg-info/PKG-INFO +135 -0
- dinoguard-0.1.0/dinoguard.egg-info/SOURCES.txt +186 -0
- dinoguard-0.1.0/dinoguard.egg-info/dependency_links.txt +1 -0
- dinoguard-0.1.0/dinoguard.egg-info/entry_points.txt +4 -0
- dinoguard-0.1.0/dinoguard.egg-info/requires.txt +10 -0
- dinoguard-0.1.0/dinoguard.egg-info/top_level.txt +1 -0
- dinoguard-0.1.0/pyproject.toml +41 -0
- dinoguard-0.1.0/setup.cfg +4 -0
- dinoguard-0.1.0/tests/test_alerts_approvals.py +158 -0
- dinoguard-0.1.0/tests/test_audit_authoring.py +113 -0
- dinoguard-0.1.0/tests/test_daemon.py +118 -0
- dinoguard-0.1.0/tests/test_dashboard.py +106 -0
- dinoguard-0.1.0/tests/test_engine.py +177 -0
- dinoguard-0.1.0/tests/test_evals_assistant.py +127 -0
- dinoguard-0.1.0/tests/test_hook_encoding.py +47 -0
- dinoguard-0.1.0/tests/test_install.py +69 -0
- dinoguard-0.1.0/tests/test_inventory_audit.py +227 -0
- dinoguard-0.1.0/tests/test_inventory_data.py +207 -0
- dinoguard-0.1.0/tests/test_mcp_undo.py +185 -0
- dinoguard-0.1.0/tests/test_more_harnesses.py +275 -0
- dinoguard-0.1.0/tests/test_notch.py +240 -0
- dinoguard-0.1.0/tests/test_packs_adapters.py +221 -0
- dinoguard-0.1.0/tests/test_phase2_claude.py +97 -0
- dinoguard-0.1.0/tests/test_prices_upgrade.py +82 -0
- dinoguard-0.1.0/tests/test_reviewer.py +136 -0
- dinoguard-0.1.0/tests/test_runner_tokens.py +122 -0
- dinoguard-0.1.0/tests/test_sdk_tracer.py +156 -0
dinoguard-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jureddi Hanish Naidu
|
|
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.
|
dinoguard-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dinoguard
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local guardrails + observability for AI coding agents, with a dotted dino runner.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: fastapi
|
|
10
|
+
Requires-Dist: uvicorn
|
|
11
|
+
Requires-Dist: pydantic
|
|
12
|
+
Requires-Dist: rich
|
|
13
|
+
Requires-Dist: httpx
|
|
14
|
+
Requires-Dist: pyyaml
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest; extra == "dev"
|
|
17
|
+
Requires-Dist: watchfiles; extra == "dev"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# DinoGuard 🦕
|
|
21
|
+
|
|
22
|
+
Local guardrails and observability for AI coding agents (Claude Code, Cursor, Codex, Copilot, Gemini CLI, and your
|
|
23
|
+
own agents). DinoGuard sits between the agent's harness and the real action. **Before** every tool call it answers
|
|
24
|
+
**allow / instruct / deny**. It records everything locally, shows a live dotted dino runner, and gives you a
|
|
25
|
+
dashboard, audits, evals, alerts and phone approvals.
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
Architecture inspired by FailproofAI. No code reused.
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pipx install git+https://github.com/hanish-8880/dino-guard # PyPI release coming soon
|
|
35
|
+
dinoguard install # Claude Code hooks (user scope) + start the fail-closed daemon
|
|
36
|
+
dinoguard notch # floating always-on-top dino pill beside your apps (--autostart: open on login)
|
|
37
|
+
dinoguard runner # dotted dino strip for a split pane
|
|
38
|
+
dinoguard dashboard # http://127.0.0.1:8030
|
|
39
|
+
dinoguard demo # 60 s scripted risky session that shows every runner state
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`dinoguard install` works non-interactively (set `DG_NO_FIRST_RUN=1` to skip the first-run wizard). Other harnesses:
|
|
43
|
+
`dinoguard install --harness cursor|gemini|copilot|codex|opencode [--scope user|project|local]`. Undo with
|
|
44
|
+
`dinoguard uninstall`, which restores your settings file byte-for-byte.
|
|
45
|
+
|
|
46
|
+
## How it works
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
harness hook JSON → adapter → canonical event → policy engine (daemon) → decision → adapter → native response
|
|
50
|
+
│
|
|
51
|
+
SQLite store · stream.jsonl · runner · dashboard · alerts · reviewer
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- **Adapters** turn each harness's events and tool names into one canonical shape. Policies never see
|
|
55
|
+
harness-specific formats. See `docs/adapters/`.
|
|
56
|
+
- **Fail-closed daemon:** once configured, if `dinoguardd` is down, times out or speaks another protocol version,
|
|
57
|
+
every guarded action is denied with a hint to run `dinoguard doctor`. (Windows uses a localhost TCP socket with an
|
|
58
|
+
auth token, because CPython has no `AF_UNIX` there.)
|
|
59
|
+
- **Engine:** built-ins run first, first deny wins, instructs are merged, each policy has a 10 s deadline,
|
|
60
|
+
observe/enforce per policy, hard/reviewable authority. `guard-self-protect` is always on.
|
|
61
|
+
|
|
62
|
+
## Policies
|
|
63
|
+
|
|
64
|
+
50 built-ins across self-protection, secrets, environment, dangerous commands, infrastructure, git, database,
|
|
65
|
+
packages, AI failure modes (loops, hallucinated paths, goal drift, finished tasks, destructive shapes), turn-end
|
|
66
|
+
workflow gates, token coaching and phone approval.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
dinoguard policies # list with enabled/mode/authority
|
|
70
|
+
dinoguard policies enforce no-git-add-all
|
|
71
|
+
dinoguard policies set token-budget budget_usd=5
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Write your own in `.dinoguard/policies/*policies.py` (project) or `~/.dinoguard/policies/` (user):
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from dinoguard import policy, allow, deny
|
|
78
|
+
|
|
79
|
+
@policy(name="no-generated-edits", events=["PreToolUse"], params={"dirs": ["dist", "generated"]})
|
|
80
|
+
def no_generated_edits(ctx):
|
|
81
|
+
if ctx.tool_name in ("Write", "Edit"):
|
|
82
|
+
path = str(ctx.tool_input.get("file_path", ""))
|
|
83
|
+
if any(f"/{d}/" in f"/{path}" for d in ctx.params["dirs"]):
|
|
84
|
+
return deny("Edit the source and run the generator instead.")
|
|
85
|
+
return allow()
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
New custom policies start in **observe** mode. Or let DinoGuard draft one:
|
|
89
|
+
`dinoguard policy new "never touch the payments folder"` → `test` → `backtest` → `publish` →
|
|
90
|
+
`deploy --mode observe` → `policies enforce`, and `rollback` if needed.
|
|
91
|
+
|
|
92
|
+
## Everything else
|
|
93
|
+
|
|
94
|
+
| Feature | Command / place |
|
|
95
|
+
|---|---|
|
|
96
|
+
| Dotted dino runner (terminal / web) | `dinoguard runner`, `dinoguard runner --web` |
|
|
97
|
+
| Dashboard: home, sessions, traces + sub-agent graph, live, policies, audit, insights, evals, alerts, metrics (p50/p95/p99), SQL queries + tiles, settings, Ctrl+J assistant | `dinoguard dashboard` |
|
|
98
|
+
| Local audit of past Claude Code sessions | `dinoguard audit [--goal "..."] [--project P] [--session ID] [--env E] [--context FILE] [--schedule 7] [--email you@x]` |
|
|
99
|
+
| Agent contract (`should` / `should_not` in `.dinoguard/contract.yaml`), checked by audits and the `contract-should-not` policy | `dinoguard audit`, `dinoguard policies enable contract-should-not` |
|
|
100
|
+
| Audit history + coverage, recurrence check (a fixed failure that comes back reopens its insight and alerts) | `dinoguard audit --history` |
|
|
101
|
+
| Finding → suggested policy, installed in observe mode | `dinoguard audit suggest <finding-id> --install` |
|
|
102
|
+
| Compare two sessions, or groups by model / harness / environment / outcome | `dinoguard compare A B`, `dinoguard compare --by model` |
|
|
103
|
+
| Error groups (fingerprinted), tool + policy analytics | `dinoguard errors`, dashboard Metrics page |
|
|
104
|
+
| Trace export (redacted JSON / JSONL) | `dinoguard export <session> --format jsonl` |
|
|
105
|
+
| Retention + configurable redaction (`retention_days`, `redaction.extra_patterns`, `redaction.store_outputs`) | `dinoguard prune [--days N] [--dry-run]` |
|
|
106
|
+
| Environment labels on sessions | `DG_ENV=staging` |
|
|
107
|
+
| Hook drift warnings + per-harness capability table | `dinoguard doctor`, `dinoguard status` |
|
|
108
|
+
| LLM reviewer for reviewable policies (any OpenAI-compatible endpoint) | `dinoguard reviewer setup --url ... --key-stdin --mode observe` |
|
|
109
|
+
| Phone approval (Telegram / WhatsApp via Twilio or Meta) | `dinoguard approve setup --telegram`, `dinoguard policies enforce phone-approval` |
|
|
110
|
+
| Alerts ("tell me when denies > 5 in 10 minutes") → insights + Slack/email/webhook/Telegram/WhatsApp | `dinoguard alerts new "..." --channel ops` |
|
|
111
|
+
| Evals (safe code expressions, LLM judge, classifier, external worker) + built-in sentiment | `dinoguard eval new|test|deploy|backfill|results|rollback` |
|
|
112
|
+
| Eval from plain words; compare scores by group | `dinoguard eval new cheap --from "cost under $1"`, `dinoguard eval results cheap --by model` |
|
|
113
|
+
| Ask your data (read-only SQL) + MCP server | `dinoguard ask "..."`, `dinoguard mcp` |
|
|
114
|
+
| Policy packs from GitHub releases or a folder (SHA256SUMS-pinned; integrity, not a signature). `DG_NO_DOWNLOAD=1` = offline, `DG_PACK_BASE_URL` = mirror | `dinoguard policies add owner/repo@tag`, `github:o/r@tag`, a release URL, or `./folder`; `--only pack:policy` |
|
|
115
|
+
| SDK for custom agents + OpenTelemetry ingest | `from dinoguard import check`, `docs/adapters/sdk.md` |
|
|
116
|
+
| Lifecycle tracer (model calls, tools, humans, errors, pause/resume) + framework helpers (LangChain, LlamaIndex, CrewAI, Pydantic AI, Deep Agents) | `with dinoguard.trace_session(...) as t:`, `dinoguard.frameworks` |
|
|
117
|
+
| Any language over HTTP; JS/TS client with no dependencies | `POST /api/v1/events`, `sdk/ts/dinoguard.mjs` |
|
|
118
|
+
| More harnesses: Devin, Factory Droid, Deep Agents Code, Antigravity, Pi, OpenClaw, Hermes | `dinoguard install --harness devin|droid|deepagents|antigravity|pi|openclaw|hermes`, `docs/adapters/` |
|
|
119
|
+
| MCP write tools that need your yes first; MCP over local HTTP | `dinoguard mcp --http`, approve with `dinoguard approve answer <code> yes` |
|
|
120
|
+
| Undo hint: git checkpoint before allowed risky actions | `dinoguard undo [<event-id>]` |
|
|
121
|
+
|
|
122
|
+
All data stays in `~/.dinoguard/` (SQLite in WAL mode plus `stream.jsonl`). Secrets are redacted before storage.
|
|
123
|
+
Stored data older than `retention_days` (default 90) is pruned once a day by the daemon; set it to `0` to keep
|
|
124
|
+
everything. There is no cap on runs, evals or audits: it is your laptop.
|
|
125
|
+
Network calls happen only for the optional reviewer/LLM features, alerts, approvals, and pack downloads.
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install -e ".[dev]"
|
|
131
|
+
pytest -q
|
|
132
|
+
python demo/make_gif.py # regenerate docs/runner.gif (needs Pillow)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
See `PROGRESS.md` for build status and `CLAUDE.md` for the design.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# DinoGuard 🦕
|
|
2
|
+
|
|
3
|
+
Local guardrails and observability for AI coding agents (Claude Code, Cursor, Codex, Copilot, Gemini CLI, and your
|
|
4
|
+
own agents). DinoGuard sits between the agent's harness and the real action. **Before** every tool call it answers
|
|
5
|
+
**allow / instruct / deny**. It records everything locally, shows a live dotted dino runner, and gives you a
|
|
6
|
+
dashboard, audits, evals, alerts and phone approvals.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
Architecture inspired by FailproofAI. No code reused.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pipx install git+https://github.com/hanish-8880/dino-guard # PyPI release coming soon
|
|
16
|
+
dinoguard install # Claude Code hooks (user scope) + start the fail-closed daemon
|
|
17
|
+
dinoguard notch # floating always-on-top dino pill beside your apps (--autostart: open on login)
|
|
18
|
+
dinoguard runner # dotted dino strip for a split pane
|
|
19
|
+
dinoguard dashboard # http://127.0.0.1:8030
|
|
20
|
+
dinoguard demo # 60 s scripted risky session that shows every runner state
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`dinoguard install` works non-interactively (set `DG_NO_FIRST_RUN=1` to skip the first-run wizard). Other harnesses:
|
|
24
|
+
`dinoguard install --harness cursor|gemini|copilot|codex|opencode [--scope user|project|local]`. Undo with
|
|
25
|
+
`dinoguard uninstall`, which restores your settings file byte-for-byte.
|
|
26
|
+
|
|
27
|
+
## How it works
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
harness hook JSON → adapter → canonical event → policy engine (daemon) → decision → adapter → native response
|
|
31
|
+
│
|
|
32
|
+
SQLite store · stream.jsonl · runner · dashboard · alerts · reviewer
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- **Adapters** turn each harness's events and tool names into one canonical shape. Policies never see
|
|
36
|
+
harness-specific formats. See `docs/adapters/`.
|
|
37
|
+
- **Fail-closed daemon:** once configured, if `dinoguardd` is down, times out or speaks another protocol version,
|
|
38
|
+
every guarded action is denied with a hint to run `dinoguard doctor`. (Windows uses a localhost TCP socket with an
|
|
39
|
+
auth token, because CPython has no `AF_UNIX` there.)
|
|
40
|
+
- **Engine:** built-ins run first, first deny wins, instructs are merged, each policy has a 10 s deadline,
|
|
41
|
+
observe/enforce per policy, hard/reviewable authority. `guard-self-protect` is always on.
|
|
42
|
+
|
|
43
|
+
## Policies
|
|
44
|
+
|
|
45
|
+
50 built-ins across self-protection, secrets, environment, dangerous commands, infrastructure, git, database,
|
|
46
|
+
packages, AI failure modes (loops, hallucinated paths, goal drift, finished tasks, destructive shapes), turn-end
|
|
47
|
+
workflow gates, token coaching and phone approval.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
dinoguard policies # list with enabled/mode/authority
|
|
51
|
+
dinoguard policies enforce no-git-add-all
|
|
52
|
+
dinoguard policies set token-budget budget_usd=5
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Write your own in `.dinoguard/policies/*policies.py` (project) or `~/.dinoguard/policies/` (user):
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from dinoguard import policy, allow, deny
|
|
59
|
+
|
|
60
|
+
@policy(name="no-generated-edits", events=["PreToolUse"], params={"dirs": ["dist", "generated"]})
|
|
61
|
+
def no_generated_edits(ctx):
|
|
62
|
+
if ctx.tool_name in ("Write", "Edit"):
|
|
63
|
+
path = str(ctx.tool_input.get("file_path", ""))
|
|
64
|
+
if any(f"/{d}/" in f"/{path}" for d in ctx.params["dirs"]):
|
|
65
|
+
return deny("Edit the source and run the generator instead.")
|
|
66
|
+
return allow()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
New custom policies start in **observe** mode. Or let DinoGuard draft one:
|
|
70
|
+
`dinoguard policy new "never touch the payments folder"` → `test` → `backtest` → `publish` →
|
|
71
|
+
`deploy --mode observe` → `policies enforce`, and `rollback` if needed.
|
|
72
|
+
|
|
73
|
+
## Everything else
|
|
74
|
+
|
|
75
|
+
| Feature | Command / place |
|
|
76
|
+
|---|---|
|
|
77
|
+
| Dotted dino runner (terminal / web) | `dinoguard runner`, `dinoguard runner --web` |
|
|
78
|
+
| Dashboard: home, sessions, traces + sub-agent graph, live, policies, audit, insights, evals, alerts, metrics (p50/p95/p99), SQL queries + tiles, settings, Ctrl+J assistant | `dinoguard dashboard` |
|
|
79
|
+
| Local audit of past Claude Code sessions | `dinoguard audit [--goal "..."] [--project P] [--session ID] [--env E] [--context FILE] [--schedule 7] [--email you@x]` |
|
|
80
|
+
| Agent contract (`should` / `should_not` in `.dinoguard/contract.yaml`), checked by audits and the `contract-should-not` policy | `dinoguard audit`, `dinoguard policies enable contract-should-not` |
|
|
81
|
+
| Audit history + coverage, recurrence check (a fixed failure that comes back reopens its insight and alerts) | `dinoguard audit --history` |
|
|
82
|
+
| Finding → suggested policy, installed in observe mode | `dinoguard audit suggest <finding-id> --install` |
|
|
83
|
+
| Compare two sessions, or groups by model / harness / environment / outcome | `dinoguard compare A B`, `dinoguard compare --by model` |
|
|
84
|
+
| Error groups (fingerprinted), tool + policy analytics | `dinoguard errors`, dashboard Metrics page |
|
|
85
|
+
| Trace export (redacted JSON / JSONL) | `dinoguard export <session> --format jsonl` |
|
|
86
|
+
| Retention + configurable redaction (`retention_days`, `redaction.extra_patterns`, `redaction.store_outputs`) | `dinoguard prune [--days N] [--dry-run]` |
|
|
87
|
+
| Environment labels on sessions | `DG_ENV=staging` |
|
|
88
|
+
| Hook drift warnings + per-harness capability table | `dinoguard doctor`, `dinoguard status` |
|
|
89
|
+
| LLM reviewer for reviewable policies (any OpenAI-compatible endpoint) | `dinoguard reviewer setup --url ... --key-stdin --mode observe` |
|
|
90
|
+
| Phone approval (Telegram / WhatsApp via Twilio or Meta) | `dinoguard approve setup --telegram`, `dinoguard policies enforce phone-approval` |
|
|
91
|
+
| Alerts ("tell me when denies > 5 in 10 minutes") → insights + Slack/email/webhook/Telegram/WhatsApp | `dinoguard alerts new "..." --channel ops` |
|
|
92
|
+
| Evals (safe code expressions, LLM judge, classifier, external worker) + built-in sentiment | `dinoguard eval new|test|deploy|backfill|results|rollback` |
|
|
93
|
+
| Eval from plain words; compare scores by group | `dinoguard eval new cheap --from "cost under $1"`, `dinoguard eval results cheap --by model` |
|
|
94
|
+
| Ask your data (read-only SQL) + MCP server | `dinoguard ask "..."`, `dinoguard mcp` |
|
|
95
|
+
| Policy packs from GitHub releases or a folder (SHA256SUMS-pinned; integrity, not a signature). `DG_NO_DOWNLOAD=1` = offline, `DG_PACK_BASE_URL` = mirror | `dinoguard policies add owner/repo@tag`, `github:o/r@tag`, a release URL, or `./folder`; `--only pack:policy` |
|
|
96
|
+
| SDK for custom agents + OpenTelemetry ingest | `from dinoguard import check`, `docs/adapters/sdk.md` |
|
|
97
|
+
| Lifecycle tracer (model calls, tools, humans, errors, pause/resume) + framework helpers (LangChain, LlamaIndex, CrewAI, Pydantic AI, Deep Agents) | `with dinoguard.trace_session(...) as t:`, `dinoguard.frameworks` |
|
|
98
|
+
| Any language over HTTP; JS/TS client with no dependencies | `POST /api/v1/events`, `sdk/ts/dinoguard.mjs` |
|
|
99
|
+
| More harnesses: Devin, Factory Droid, Deep Agents Code, Antigravity, Pi, OpenClaw, Hermes | `dinoguard install --harness devin|droid|deepagents|antigravity|pi|openclaw|hermes`, `docs/adapters/` |
|
|
100
|
+
| MCP write tools that need your yes first; MCP over local HTTP | `dinoguard mcp --http`, approve with `dinoguard approve answer <code> yes` |
|
|
101
|
+
| Undo hint: git checkpoint before allowed risky actions | `dinoguard undo [<event-id>]` |
|
|
102
|
+
|
|
103
|
+
All data stays in `~/.dinoguard/` (SQLite in WAL mode plus `stream.jsonl`). Secrets are redacted before storage.
|
|
104
|
+
Stored data older than `retention_days` (default 90) is pruned once a day by the daemon; set it to `0` to keep
|
|
105
|
+
everything. There is no cap on runs, evals or audits: it is your laptop.
|
|
106
|
+
Network calls happen only for the optional reviewer/LLM features, alerts, approvals, and pack downloads.
|
|
107
|
+
|
|
108
|
+
## Development
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install -e ".[dev]"
|
|
112
|
+
pytest -q
|
|
113
|
+
python demo/make_gif.py # regenerate docs/runner.gif (needs Pillow)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
See `PROGRESS.md` for build status and `CLAUDE.md` for the design.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""DinoGuard public SDK.
|
|
2
|
+
|
|
3
|
+
from dinoguard import policy, allow, instruct, deny, check
|
|
4
|
+
"""
|
|
5
|
+
from .engine.decisions import Decision, allow, ask_human, deny, instruct
|
|
6
|
+
from .engine.registry import policy
|
|
7
|
+
from .version import PROTOCOL_VERSION, __version__
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def check(tool: str, input: dict | None = None, session_id: str | None = None, **kw) -> Decision: # noqa: A002
|
|
11
|
+
"""Evaluate a tool call from a custom agent. See dinoguard.adapters.sdk.check."""
|
|
12
|
+
from .adapters.sdk import check as _check
|
|
13
|
+
return _check(tool, input or {}, session_id=session_id, **kw)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def trace_session(**kw):
|
|
17
|
+
"""Lifecycle tracer for custom agents (model calls, tools, humans, errors). See dinoguard.tracer."""
|
|
18
|
+
from .tracer import trace_session as _t
|
|
19
|
+
return _t(**kw)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
__all__ = ["policy", "allow", "instruct", "deny", "ask_human", "check", "trace_session", "Decision", "__version__",
|
|
23
|
+
"PROTOCOL_VERSION"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Adapter lookup by harness name."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import importlib
|
|
5
|
+
|
|
6
|
+
from .base import Adapter
|
|
7
|
+
|
|
8
|
+
_ADAPTERS = {
|
|
9
|
+
"claude": ("claude_code", "ClaudeCodeAdapter"),
|
|
10
|
+
"claude-code": ("claude_code", "ClaudeCodeAdapter"),
|
|
11
|
+
"cursor": ("cursor", "CursorAdapter"),
|
|
12
|
+
"codex": ("codex", "CodexAdapter"),
|
|
13
|
+
"copilot": ("copilot", "CopilotAdapter"),
|
|
14
|
+
"gemini": ("gemini", "GeminiAdapter"),
|
|
15
|
+
"opencode": ("opencode", "OpenCodeAdapter"),
|
|
16
|
+
"goose": ("goose", "GooseAdapter"),
|
|
17
|
+
"sdk": ("sdk", "SDKAdapter"),
|
|
18
|
+
"devin": ("claude_like", "DevinAdapter"),
|
|
19
|
+
"droid": ("claude_like", "DroidAdapter"),
|
|
20
|
+
"deepagents": ("claude_like", "DeepAgentsCodeAdapter"),
|
|
21
|
+
"dcode": ("claude_like", "DeepAgentsCodeAdapter"),
|
|
22
|
+
"hermes": ("hermes", "HermesAdapter"),
|
|
23
|
+
"antigravity": ("antigravity", "AntigravityAdapter"),
|
|
24
|
+
"agy": ("antigravity", "AntigravityAdapter"),
|
|
25
|
+
"pi": ("plugin_bridge", "PiAdapter"),
|
|
26
|
+
"openclaw": ("plugin_bridge", "OpenClawAdapter"),
|
|
27
|
+
}
|
|
28
|
+
_ALIASES_HIDDEN = {"claude-code", "dcode", "agy"}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def names() -> list[str]:
|
|
32
|
+
return sorted(k for k in _ADAPTERS if k not in _ALIASES_HIDDEN)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def sniff(harness: str) -> str:
|
|
36
|
+
"""Harnesses that also read Claude Code's settings run our `claude` hook; tell them apart by the
|
|
37
|
+
environment they set for hooks (Devin: DEVIN_PROJECT_DIR, Factory Droid: FACTORY_PROJECT_DIR)."""
|
|
38
|
+
import os
|
|
39
|
+
if harness.lower() in ("claude", "claude-code"):
|
|
40
|
+
if os.environ.get("DEVIN_PROJECT_DIR"):
|
|
41
|
+
return "devin"
|
|
42
|
+
if os.environ.get("FACTORY_PROJECT_DIR") or os.environ.get("DROID_PROJECT_DIR"):
|
|
43
|
+
return "droid"
|
|
44
|
+
return harness
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_adapter(name: str) -> Adapter:
|
|
48
|
+
try:
|
|
49
|
+
mod_name, cls_name = _ADAPTERS[name.lower()]
|
|
50
|
+
except KeyError:
|
|
51
|
+
raise ValueError(f"unknown harness {name!r}; known: {', '.join(names())}") from None
|
|
52
|
+
mod = importlib.import_module(f"{__name__}.{mod_name}")
|
|
53
|
+
return getattr(mod, cls_name)()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Google Antigravity CLI (`agy`) hooks. Verified 2026-11-26 against antigravity.google/docs/hooks.md.
|
|
2
|
+
See docs/adapters/antigravity.md.
|
|
3
|
+
|
|
4
|
+
The payload has no event-name field, so the installed command passes it: `dinoguard-hook antigravity PreToolUse`.
|
|
5
|
+
stdin (camelCase): conversationId, workspacePaths, transcriptPath, modelName, lastUserInput, toolCall{name,args},
|
|
6
|
+
stepIdx, error, terminationReason ... Decisions go back as JSON on stdout (exit codes are not documented), so
|
|
7
|
+
DinoGuard always prints JSON and exits 0, including when it fails closed.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
|
|
13
|
+
from ..engine.decisions import DENY, INSTRUCT, Decision
|
|
14
|
+
from ..engine.events import CanonicalEvent, make_tool
|
|
15
|
+
from .base import Adapter, NativeResponse, response_text
|
|
16
|
+
from .common import canonical_input
|
|
17
|
+
|
|
18
|
+
EVENT_MAP = {"PreToolUse": "PreToolUse", "PostToolUse": "PostToolUse", "PreInvocation": "ModelRequest",
|
|
19
|
+
"PostInvocation": "ModelResponse", "Stop": "Stop", "SessionStart": "SessionStart"}
|
|
20
|
+
HOOK_EVENTS = ["PreToolUse", "PostToolUse", "PreInvocation", "PostInvocation", "Stop", "SessionStart"]
|
|
21
|
+
|
|
22
|
+
# native tool -> (canonical, {native arg -> canonical arg})
|
|
23
|
+
TOOLS = {
|
|
24
|
+
"run_command": ("Bash", {"CommandLine": "command", "Cwd": "cwd"}),
|
|
25
|
+
"view_file": ("Read", {"AbsolutePath": "file_path"}),
|
|
26
|
+
"write_to_file": ("Write", {"TargetFile": "file_path", "CodeContent": "content"}),
|
|
27
|
+
"replace_file_content": ("Edit", {"TargetFile": "file_path", "TargetContent": "old_string",
|
|
28
|
+
"ReplacementContent": "new_string"}),
|
|
29
|
+
"multi_replace_file_content": ("Edit", {"TargetFile": "file_path"}),
|
|
30
|
+
"grep_search": ("Grep", {"Query": "pattern", "SearchPath": "path"}),
|
|
31
|
+
"find_by_name": ("Glob", {"Pattern": "pattern", "SearchDirectory": "path"}),
|
|
32
|
+
"list_dir": ("Glob", {"DirectoryPath": "path"}),
|
|
33
|
+
"read_url_content": ("WebFetch", {"Url": "url"}),
|
|
34
|
+
"search_web": ("WebSearch", {"query": "query", "Query": "query"}),
|
|
35
|
+
"invoke_subagent": ("Task", {}),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def map_tool(name: str | None, args) -> tuple[str, dict]:
|
|
40
|
+
args = dict(args) if isinstance(args, dict) else {}
|
|
41
|
+
spec = TOOLS.get(str(name or ""))
|
|
42
|
+
if not spec:
|
|
43
|
+
if str(name or "").startswith("mcp"):
|
|
44
|
+
return f"MCP:{name}", args
|
|
45
|
+
return "Other", {"_tool": name, **args}
|
|
46
|
+
canon, fields = spec
|
|
47
|
+
out = dict(args)
|
|
48
|
+
for src, dst in fields.items():
|
|
49
|
+
if src in args:
|
|
50
|
+
out[dst] = args[src]
|
|
51
|
+
if name == "multi_replace_file_content":
|
|
52
|
+
chunks = args.get("ReplacementChunks") or []
|
|
53
|
+
out["old_string"] = "\n".join(str(c.get("TargetContent", "")) for c in chunks if isinstance(c, dict))
|
|
54
|
+
out["new_string"] = "\n".join(str(c.get("ReplacementContent", "")) for c in chunks if isinstance(c, dict))
|
|
55
|
+
return canon, canonical_input(canon, out) if canon in ("Bash", "Read", "Write", "Edit") else out
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class AntigravityAdapter(Adapter):
|
|
59
|
+
name = "antigravity"
|
|
60
|
+
VERIFIED_VERSION = "docs read 2026-11-26 (hooks page undated; App v2.35.2)"
|
|
61
|
+
blocking_events = frozenset({"PreToolUse", "Stop"})
|
|
62
|
+
known_native_tools = frozenset({"manage_task", "schedule", "list_permissions", "ask_permission",
|
|
63
|
+
"define_subagent", "send_message", "manage_subagents", "ask_question",
|
|
64
|
+
"generate_image"})
|
|
65
|
+
|
|
66
|
+
def to_canonical(self, raw: dict) -> CanonicalEvent:
|
|
67
|
+
native = str(raw.get("_event") or raw.get("hookEventName") or "")
|
|
68
|
+
call = raw.get("toolCall") if isinstance(raw.get("toolCall"), dict) else {}
|
|
69
|
+
tool = None
|
|
70
|
+
if call.get("name"):
|
|
71
|
+
cname, cinp = map_tool(call.get("name"), call.get("args"))
|
|
72
|
+
tool = make_tool(cname, cinp)
|
|
73
|
+
tool["native_name"] = call.get("name")
|
|
74
|
+
ws = raw.get("workspacePaths") or []
|
|
75
|
+
cwd = (tool or {}).get("input", {}).get("cwd") or (ws[0] if isinstance(ws, list) and ws else None)
|
|
76
|
+
output, n = response_text(raw.get("toolResult") or raw.get("result")) if native == "PostToolUse" else (None, 0)
|
|
77
|
+
return CanonicalEvent(event=EVENT_MAP.get(native, native or "Notification"), harness=self.name,
|
|
78
|
+
session={"id": raw.get("conversationId") or "antigravity", "cwd": cwd,
|
|
79
|
+
"transcript_path": raw.get("transcriptPath")},
|
|
80
|
+
tool=tool, prompt=raw.get("lastUserInput") if native == "SessionStart" else None,
|
|
81
|
+
output=output, output_chars=n,
|
|
82
|
+
error=str(raw["error"])[:1000] if raw.get("error") else None,
|
|
83
|
+
extra={"native_event": native, "model": raw.get("modelName"),
|
|
84
|
+
"step": raw.get("stepIdx")}, raw=raw)
|
|
85
|
+
|
|
86
|
+
def to_native(self, event: CanonicalEvent, decision: Decision) -> NativeResponse:
|
|
87
|
+
ev, kind = event.event, decision.kind
|
|
88
|
+
reason = decision.reason or ""
|
|
89
|
+
if ev == "PreToolUse":
|
|
90
|
+
if kind == DENY:
|
|
91
|
+
return NativeResponse(0, json.dumps({"decision": "deny",
|
|
92
|
+
"reason": f"[DinoGuard:{decision.policy}] {reason}"}), "")
|
|
93
|
+
return NativeResponse(0, json.dumps({"decision": "allow"}), "") # allow = defer to normal policy
|
|
94
|
+
if ev == "Stop" and kind == DENY: # a workflow gate: keep going, the reason becomes a system message
|
|
95
|
+
return NativeResponse(0, json.dumps({"decision": "continue", "reason": f"[DinoGuard] {reason}"}), "")
|
|
96
|
+
if kind == INSTRUCT and event.extra.get("native_event") in ("SessionStart", "PreInvocation", "PostInvocation"):
|
|
97
|
+
return NativeResponse(0, json.dumps({"injectSteps": [
|
|
98
|
+
{"systemMessage": {"systemMessage": f"[DinoGuard] {reason}"}}]}), "")
|
|
99
|
+
return NativeResponse(0, "{}", "")
|
|
100
|
+
|
|
101
|
+
def fail_closed(self, event_name, reason):
|
|
102
|
+
if event_name in ("PreToolUse", None):
|
|
103
|
+
return NativeResponse(0, json.dumps({"decision": "deny", "reason": f"[DinoGuard] {reason}"}), "")
|
|
104
|
+
return NativeResponse(0, "{}", "")
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Adapter interface: native hook payload <-> canonical event / native response."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ..engine.decisions import Decision
|
|
10
|
+
from ..engine.events import CanonicalEvent
|
|
11
|
+
|
|
12
|
+
OUTPUT_LIMIT = 4000
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class NativeResponse:
|
|
17
|
+
exit_code: int = 0
|
|
18
|
+
stdout: str = ""
|
|
19
|
+
stderr: str = ""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Adapter(ABC):
|
|
23
|
+
name: str = "base"
|
|
24
|
+
#: canonical events this harness can block on (documented in docs/adapters/<name>.md)
|
|
25
|
+
blocking_events: frozenset[str] = frozenset()
|
|
26
|
+
#: harness version / docs date the adapter was checked against (see docs/adapters/<name>.md)
|
|
27
|
+
VERIFIED_VERSION: str | None = None
|
|
28
|
+
#: native tool names that deliberately map to canonical "Other"; None = don't track tool drift
|
|
29
|
+
known_native_tools: frozenset[str] | None = None
|
|
30
|
+
#: plain-words capability notes shown by `dinoguard status`
|
|
31
|
+
observe_only_note: str = "every other event is observe-only"
|
|
32
|
+
|
|
33
|
+
@abstractmethod
|
|
34
|
+
def to_canonical(self, raw: dict[str, Any]) -> CanonicalEvent: ...
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
def to_native(self, event: CanonicalEvent, decision: Decision) -> NativeResponse: ...
|
|
38
|
+
|
|
39
|
+
def fail_closed(self, event_name: str | None, reason: str) -> NativeResponse:
|
|
40
|
+
"""Response used when DinoGuard itself cannot evaluate. Default: block via exit 2."""
|
|
41
|
+
return NativeResponse(2, "", reason)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def response_text(resp: Any) -> tuple[str, int]:
|
|
45
|
+
"""Flatten a tool response into text (truncated) + original length."""
|
|
46
|
+
if resp is None:
|
|
47
|
+
return "", 0
|
|
48
|
+
if isinstance(resp, str):
|
|
49
|
+
text = resp
|
|
50
|
+
elif isinstance(resp, dict):
|
|
51
|
+
parts = []
|
|
52
|
+
for k in ("stdout", "stderr", "output", "content", "result", "text", "error", "file"):
|
|
53
|
+
v = resp.get(k)
|
|
54
|
+
if isinstance(v, str) and v:
|
|
55
|
+
parts.append(v)
|
|
56
|
+
elif isinstance(v, dict) and isinstance(v.get("content"), str):
|
|
57
|
+
parts.append(v["content"])
|
|
58
|
+
elif isinstance(v, list):
|
|
59
|
+
parts.extend(str(x.get("text", x)) if isinstance(x, dict) else str(x) for x in v)
|
|
60
|
+
text = "\n".join(parts) if parts else json.dumps(resp, default=str)
|
|
61
|
+
elif isinstance(resp, list):
|
|
62
|
+
text = "\n".join(str(x.get("text", x)) if isinstance(x, dict) else str(x) for x in resp)
|
|
63
|
+
else:
|
|
64
|
+
text = str(resp)
|
|
65
|
+
n = len(text)
|
|
66
|
+
return (text if n <= OUTPUT_LIMIT * 4 else text[: OUTPUT_LIMIT * 4]), n
|