@mokuyoaxis/agent-guard 0.2.6 → 0.2.8

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.
Files changed (39) hide show
  1. package/README.md +45 -20
  2. package/README.zh-CN.md +39 -19
  3. package/adapters/INTEGRATION.md +6 -0
  4. package/adapters/mcp/__init__.py +1 -0
  5. package/adapters/mcp/doctor.py +325 -0
  6. package/adapters/mcp/operations.py +174 -0
  7. package/adapters/mcp/requirements.txt +3 -0
  8. package/adapters/mcp/server.py +126 -0
  9. package/core/admission.py +388 -0
  10. package/core/audit.py +1 -1
  11. package/core/classifier.py +2 -1
  12. package/core/cleanup.py +297 -0
  13. package/core/delete_config.py +153 -0
  14. package/core/policy.py +35 -7
  15. package/core/recovery.py +10 -0
  16. package/docs/README.md +35 -14
  17. package/docs/design/architecture.md +42 -16
  18. package/docs/design/compatibility.md +246 -7
  19. package/docs/design/threat-model.md +53 -1
  20. package/docs/guides/cleanup-plan.md +227 -0
  21. package/docs/guides/deletion-limits.md +150 -0
  22. package/docs/guides/getting-started.md +26 -12
  23. package/docs/guides/harness-capabilities.md +29 -4
  24. package/docs/guides/mcp.md +420 -0
  25. package/docs/history/friction.md +99 -1
  26. package/docs/releases/release-notes-0.2.7.md +217 -0
  27. package/docs/releases/release-notes-0.2.8.md +172 -0
  28. package/docs/releases/unreleased.md +182 -5
  29. package/docs/reports/test-report-dsh-paired-lab.md +1 -1
  30. package/docs/reports/test-report-kimi-code-block.md +1 -1
  31. package/doctor.py +25 -1
  32. package/live_sentinel.py +1 -1
  33. package/package.json +3 -1
  34. package/skills/delete-guard/SKILL.md +69 -1
  35. package/skills/delete-guard/references/policy.md +66 -3
  36. package/skills/delete-guard/scripts/check.py +39 -9
  37. package/skills/delete-guard/scripts/cleanup.py +164 -0
  38. package/skills/delete-guard/scripts/safe_delete.py +22 -4
  39. package/skills/delete-guard/scripts/status.py +77 -1
@@ -3,6 +3,7 @@
3
3
 
4
4
  status.py [--json] [--tail N]
5
5
  status.py --trash-index [--root PATH ...] [--trash PATH ...] [--json]
6
+ status.py --reset-delete-budget [--json]
6
7
  """
7
8
  from __future__ import annotations
8
9
 
@@ -15,7 +16,7 @@ import sys
15
16
  import _bootstrap # noqa: F401
16
17
 
17
18
  from core import AUDIT_NAME, TRASH_DIRNAME
18
- from core import audit, classifier, policy, recovery
19
+ from core import admission, audit, classifier, policy, recovery
19
20
  from core.messages import (
20
21
  HOST_STATUS_NOTICE, QUARANTINE_NOTICE, gc_guidance, print_gc_guidance)
21
22
 
@@ -24,6 +25,8 @@ def main() -> int:
24
25
  ap = argparse.ArgumentParser(description=__doc__)
25
26
  ap.add_argument("--json", action="store_true", dest="as_json")
26
27
  ap.add_argument("--tail", type=int, default=10)
28
+ ap.add_argument("--reset-delete-budget", action="store_true",
29
+ help="interactively reset this session's deletion budget; preserves recovery copies")
27
30
  ap.add_argument("--trash-index", action="store_true",
28
31
  help="read-only quarantine locations for agents and future UI")
29
32
  ap.add_argument("--root", action="append", default=[],
@@ -36,6 +39,13 @@ def main() -> int:
36
39
  help="index directory-entry budget (default 10000)")
37
40
  args = ap.parse_args()
38
41
 
42
+ if args.reset_delete_budget and args.trash_index:
43
+ ap.error("--reset-delete-budget cannot be combined with --trash-index")
44
+ if args.reset_delete_budget and not (sys.stdin.isatty() and sys.stderr.isatty()):
45
+ print("Deletion-budget reset requires interactive stdin and stderr; no state changed.",
46
+ file=sys.stderr)
47
+ return 2
48
+
39
49
  base = os.getcwd()
40
50
  if args.trash_index:
41
51
  from core.trash_index import (
@@ -82,6 +92,8 @@ def main() -> int:
82
92
  trash_root = os.environ.get(
83
93
  "AGENT_GUARD_TRASH", os.path.join(workspace, TRASH_DIRNAME))
84
94
  engine = recovery.RecoveryEngine(workspace, trash_root)
95
+ if args.reset_delete_budget and not reset_delete_budget(workspace, trash_root, engine):
96
+ return 2
85
97
  state = policy.load_mode(trash_root)
86
98
  # Project display-only identity/time metadata, never authorization state.
87
99
  mode_metadata = audit.project({"ts": state["since"], "session": state["set_by"]})
@@ -104,6 +116,7 @@ def main() -> int:
104
116
  "mode_set_by": mode_metadata.get("session"),
105
117
  "trash_root": trash_root,
106
118
  "usage": usage,
119
+ "delete_admission": deletion_admission(workspace, trash_root),
107
120
  "retention": {
108
121
  "soft_days": plan["retention_days"],
109
122
  "soft_limit_bytes": plan["size_limit_bytes"],
@@ -133,6 +146,19 @@ def main() -> int:
133
146
  f"{usage['transactions']} transactions "
134
147
  f"({usage['restorable_transactions']} restorable)")
135
148
  print(f"snapshots : {stash_count} agent-guard stashes")
149
+ deletion = info["delete_admission"]
150
+ if deletion.get("status") == "BLOCKED":
151
+ print(f"deletion : BLOCKED [{deletion['code']}] {deletion['reason']}")
152
+ else:
153
+ limits = deletion["limits"]
154
+ print(f"deletion : admitted {deletion['used_bytes']}/{limits['session_max_bytes']} bytes, "
155
+ f"{deletion['used_entries']}/{limits['session_max_entries']} entries")
156
+ print(f"window : {deletion['window_operations']}/{limits['rate_max_operations']} operations "
157
+ f"in {limits['rate_window_seconds']}s; "
158
+ f"same-target limit {limits['repeat_max_operations']}")
159
+ print(f"capacity : admission limits {limits['quarantine_max_bytes']} bytes / "
160
+ f"{limits['quarantine_max_entries']} entries")
161
+ print(deletion["accounting"])
136
162
  ret = info["retention"]
137
163
  print(f"retention : soft {ret['soft_days']}d / "
138
164
  f"{ret['soft_limit_bytes'] // (1024**3)}GiB; "
@@ -151,6 +177,56 @@ def main() -> int:
151
177
  return 0
152
178
 
153
179
 
180
+ def deletion_admission(workspace, trash_root):
181
+ """Expose unusable admission state without hiding recovery/GC guidance."""
182
+ try:
183
+ return admission.describe(workspace, trash_root)
184
+ except admission.AdmissionDenied as exc:
185
+ return {"status": "BLOCKED", "code": exc.code, "reason": exc.reason}
186
+
187
+
188
+ def reset_delete_budget(workspace, trash_root, engine):
189
+ """Explicit operator reset; durable intent precedes the state mutation."""
190
+ if not (sys.stdin.isatty() and sys.stderr.isatty()):
191
+ print("Deletion-budget reset requires interactive stdin and stderr; no state changed.",
192
+ file=sys.stderr)
193
+ return False
194
+ current = deletion_admission(workspace, trash_root)
195
+ if current.get("status") == "BLOCKED":
196
+ print(f"[{current['code']}] {current['reason']}; no budget reset.", file=sys.stderr)
197
+ return False
198
+ print("Reset this session's admitted deletion bytes, entries and rate window.\n"
199
+ "Quarantine capacity, recovery files and recovery records are retained.\n"
200
+ f"Current admitted work: {current['used_bytes']} bytes / {current['used_entries']} entries.\n"
201
+ "Type RESET to continue: ", end="", file=sys.stderr, flush=True)
202
+ if sys.stdin.readline().rstrip("\r\n") != "RESET":
203
+ print("Cancelled; no state changed.", file=sys.stderr)
204
+ return False
205
+ audit_path = os.path.join(trash_root, AUDIT_NAME)
206
+ check_id = audit.new_txid()
207
+ try:
208
+ engine.ensure_layout()
209
+ audit.append({"event": "delete-budget-reset", "phase": "intent", "check_id": check_id},
210
+ audit_path)
211
+ except OSError:
212
+ print("Budget reset blocked: its audit intent could not be persisted.", file=sys.stderr)
213
+ return False
214
+ try:
215
+ admission.reset_session(workspace, trash_root)
216
+ except admission.AdmissionDenied as exc:
217
+ print(f"[{exc.code}] {exc.reason}; budget reset did not complete.", file=sys.stderr)
218
+ return False
219
+ try:
220
+ audit.append({"event": "delete-budget-reset", "phase": "complete", "check_id": check_id},
221
+ audit_path)
222
+ except OSError:
223
+ print("Session budget was reset, but its completion audit could not be persisted; inspect the intent.",
224
+ file=sys.stderr)
225
+ return False
226
+ print("Session deletion budget reset; recovery data retained.", file=sys.stderr)
227
+ return True
228
+
229
+
154
230
  def audit_tail(trash_root, n):
155
231
  # core.audit projects both historical field names and values. Status
156
232
  # exposes a smaller summary, with no session or compensation details.