@mokuyoaxis/agent-guard 0.2.8 → 0.2.9

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.
@@ -22,6 +22,7 @@ import _bootstrap # noqa: F401
22
22
 
23
23
  from core import classifier, recovery
24
24
  from core.cleanup import DEFAULT_MAX_DEPTH, DEFAULT_MAX_ENTRIES, plan_cleanup, select_entries
25
+ from core.cleanup_groups import discover_groups, measure_groups
25
26
  from core.messages import print_gc_guidance
26
27
 
27
28
 
@@ -29,6 +30,26 @@ LABELS = {"regenerable": "可再生 / regenerable", "discarded": "明确废弃 /
29
30
  "uncertain": "不确定 / uncertain", "protected": "受保护 / protected"}
30
31
 
31
32
 
33
+ def print_groups(result):
34
+ print("Read-only observation; no execution permission. Workspace: "
35
+ + json.dumps(result["workspace"], ensure_ascii=True))
36
+ if "overview" in result:
37
+ for row in result["overview"]:
38
+ print(row["kind"] + ": " + str(row.get("groups", row.get("branches")))
39
+ + " groups; size unknown")
40
+ coverage = result["coverage"]
41
+ print("Frontier complete: " + str(coverage["frontier_complete"])
42
+ + "; workspace scan complete: False; unexpanded: " + str(len(coverage["unexpanded"])))
43
+ print("Use --json for groups, scopes, issues and unexpanded paths; "
44
+ "continue discovery with explicit --scope PATH.")
45
+ else:
46
+ for row in result["scopes"]:
47
+ size = str(row["size_bytes"]) + " B" if row["size_complete"] else (
48
+ "whole size unknown; observed " + str(row["observed_bytes"]) + " B")
49
+ print(json.dumps(row["path"], ensure_ascii=True) + ": " + size)
50
+ print(result["notice"])
51
+
52
+
32
53
  def print_plan(plan, *, stream=None, selected=None):
33
54
  stream = stream or sys.stdout
34
55
  print("Plan: " + plan["plan_id"], file=stream)
@@ -106,8 +127,13 @@ def main(argv=None):
106
127
  help="explicitly declare a path/subtree discarded; repeatable")
107
128
  parser.add_argument("--protect", action="append", default=[], metavar="PATH",
108
129
  help="protect an additional path/subtree; repeatable")
109
- parser.add_argument("--max-entries", type=int, default=DEFAULT_MAX_ENTRIES)
110
- parser.add_argument("--max-depth", type=int, default=DEFAULT_MAX_DEPTH)
130
+ modes = parser.add_mutually_exclusive_group()
131
+ modes.add_argument("--discover", action="store_true", help="read-only directory overview; no executable plan")
132
+ modes.add_argument("--measure", action="store_true", help="read-only metadata sizes for explicit directory scopes")
133
+ parser.add_argument("--scope", action="append", default=[], metavar="PATH",
134
+ help="directory below the fixed root; repeatable, for --discover or --measure")
135
+ parser.add_argument("--max-entries", type=int, help="entry budget; defaults: plan/discover 10000, measure 20000")
136
+ parser.add_argument("--max-depth", type=int, help="depth budget; defaults: plan 32, discover 4, measure 32")
111
137
  parser.add_argument("--json", action="store_true")
112
138
  parser.add_argument("--execute", action="store_true")
113
139
  parser.add_argument("--plan-id", help="exact ID from the plan being reviewed")
@@ -115,13 +141,32 @@ def main(argv=None):
115
141
  help="select an exact selectable plan entry; repeatable")
116
142
  args = parser.parse_args(argv)
117
143
  try:
144
+ observing = args.discover or args.measure
145
+ if observing and (args.execute or args.plan_id or args.select or args.discard or args.protect):
146
+ raise ValueError("read-only discovery/measurement cannot accept plan declarations or execution arguments")
147
+ if args.scope and not observing:
148
+ raise ValueError("--scope requires --discover or --measure; it does not narrow an executable plan")
149
+ if observing:
150
+ root = args.root or classifier.discover_workspace(os.getcwd())
151
+ limits = {name: value for name, value in (("max_entries", args.max_entries), ("max_depth", args.max_depth))
152
+ if value is not None}
153
+ result = (discover_groups(root, args.scope, **limits) if args.discover
154
+ else measure_groups(root, args.scope, **limits))
155
+ if args.json:
156
+ print(json.dumps(result, ensure_ascii=True, indent=2))
157
+ else:
158
+ print_groups(result)
159
+ complete = (result["coverage"]["frontier_complete"] if args.discover
160
+ else all(row["observed_subset_complete"] for row in result["scopes"]))
161
+ return 0 if complete else 1
118
162
  if not args.execute and (args.select or args.plan_id):
119
163
  raise ValueError("--select and --plan-id require --execute")
120
164
  if args.execute and not args.plan_id:
121
165
  raise ValueError("--execute requires the reviewed --plan-id")
122
166
  root = args.root or classifier.discover_workspace(os.getcwd())
123
167
  options = dict(discard=args.discard, protect=args.protect,
124
- max_entries=args.max_entries, max_depth=args.max_depth)
168
+ max_entries=DEFAULT_MAX_ENTRIES if args.max_entries is None else args.max_entries,
169
+ max_depth=DEFAULT_MAX_DEPTH if args.max_depth is None else args.max_depth)
125
170
  plan = plan_cleanup(root, **options)
126
171
  if not args.execute:
127
172
  if args.json: