agent-efficiency 1.4.2__py3-none-any.whl
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.
- agent_efficiency/__init__.py +15 -0
- agent_efficiency/_bundle/mcp/server.py +519 -0
- agent_efficiency/_bundle/rules/AGENT_RULES.md +9 -0
- agent_efficiency/_bundle/scripts/ae_cli.py +327 -0
- agent_efficiency/_bundle/scripts/ae_init.py +267 -0
- agent_efficiency/_bundle/scripts/ae_manage.py +578 -0
- agent_efficiency/_bundle/scripts/install.py +308 -0
- agent_efficiency/_bundle/scripts/pretool_hook.py +350 -0
- agent_efficiency/_bundle/scripts/render_demo_svg.py +180 -0
- agent_efficiency/_bundle/scripts/setup_hooks.py +330 -0
- agent_efficiency/_bundle/scripts/sync_shared.py +85 -0
- agent_efficiency/_bundle/scripts/validate_skills.py +150 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/SKILL.md +80 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/config/models.json +237 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/examples/workflow.md +77 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/references/routing-and-escalation.md +63 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/references/state-and-handoff.md +84 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/_ae_core/__init__.py +90 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/_ae_core/io_lock.py +199 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/_ae_core/savings.py +249 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/_ae_core/security.py +235 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/_ae_core/usage.py +195 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/agent_state.py +266 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/context_doctor.py +780 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/llm_adapter.py +306 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/route_task.py +496 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/state_ops.py +580 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/state_render.py +428 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/state_store.py +440 -0
- agent_efficiency/_bundle/skills/adaptive-orchestration-handoff/scripts/transcript_audit.py +854 -0
- agent_efficiency/_bundle/skills/local-context-index/SKILL.md +71 -0
- agent_efficiency/_bundle/skills/local-context-index/references/cli-reference.md +112 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/_ae_core/__init__.py +90 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/_ae_core/io_lock.py +199 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/_ae_core/savings.py +249 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/_ae_core/security.py +235 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/_ae_core/usage.py +195 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/compact_run.py +395 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/context_index.py +341 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_db.py +393 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_ignore.py +184 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_indexer.py +330 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_lsp.py +213 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_parsers.py +769 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_search.py +498 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_slice.py +610 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_trace.py +553 -0
- agent_efficiency/_bundle/skills/local-context-index/scripts/idx_workspace.py +219 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/SKILL.md +52 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/references/provider-caching.md +52 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/_ae_core/__init__.py +90 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/_ae_core/io_lock.py +199 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/_ae_core/savings.py +249 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/_ae_core/security.py +235 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/_ae_core/usage.py +195 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/cache_payload.py +278 -0
- agent_efficiency/_bundle/skills/prompt-cache-manager/scripts/prompt_cache.py +488 -0
- agent_efficiency/cli.py +23 -0
- agent_efficiency/mcp_entry.py +25 -0
- agent_efficiency-1.4.2.dist-info/METADATA +267 -0
- agent_efficiency-1.4.2.dist-info/RECORD +64 -0
- agent_efficiency-1.4.2.dist-info/WHEEL +4 -0
- agent_efficiency-1.4.2.dist-info/entry_points.txt +4 -0
- agent_efficiency-1.4.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""AgentEfficiency — Local Context Index CLI entrypoint & public API facade."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Optional, Sequence
|
|
10
|
+
|
|
11
|
+
_SCRIPT_DIR = str(Path(__file__).resolve().parent)
|
|
12
|
+
if _SCRIPT_DIR not in sys.path:
|
|
13
|
+
sys.path.insert(0, _SCRIPT_DIR)
|
|
14
|
+
|
|
15
|
+
from _ae_core import configure_utf8_stdio, estimate_tokens, normalize_rel_path, redact_secrets # noqa: E402, F401
|
|
16
|
+
from compact_run import compress_command_output, run_compact # noqa: E402, F401
|
|
17
|
+
from idx_db import SCHEMA_VERSION, assert_not_symlink_artifact, build_project_map, db_open, status # noqa: E402, F401
|
|
18
|
+
from idx_ignore import DEFAULT_MAP_BUDGET_TOKENS, is_ignored, load_gitignore_rules, load_repo_config # noqa: E402, F401
|
|
19
|
+
from idx_indexer import index, run_watch # noqa: E402, F401
|
|
20
|
+
from idx_search import ( # noqa: E402, F401
|
|
21
|
+
call_graph,
|
|
22
|
+
file_deps,
|
|
23
|
+
find_refs,
|
|
24
|
+
format_compact_callgraph as _format_compact_callgraph,
|
|
25
|
+
format_compact_deps as _format_compact_deps,
|
|
26
|
+
format_compact_search as _format_compact_search,
|
|
27
|
+
git_changed,
|
|
28
|
+
list_symbols,
|
|
29
|
+
search,
|
|
30
|
+
)
|
|
31
|
+
from idx_slice import ( # noqa: E402, F401
|
|
32
|
+
context_pack,
|
|
33
|
+
diff_pack,
|
|
34
|
+
file_outline,
|
|
35
|
+
format_compact_diff_pack as _format_compact_diff_pack,
|
|
36
|
+
format_compact_multi_slice as _format_compact_multi_slice,
|
|
37
|
+
format_compact_pack as _format_compact_pack,
|
|
38
|
+
slice_file,
|
|
39
|
+
slice_many,
|
|
40
|
+
)
|
|
41
|
+
from idx_trace import ( # noqa: E402, F401
|
|
42
|
+
find_affected_tests,
|
|
43
|
+
format_compact_tests_for as _format_compact_tests_for,
|
|
44
|
+
format_compact_trace_pack as _format_compact_trace_pack,
|
|
45
|
+
parse_stacktrace_frames,
|
|
46
|
+
trace_pack,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
51
|
+
ap = argparse.ArgumentParser(description="AgentEfficiency incremental repository indexer, call-graph & token-budgeted retriever.")
|
|
52
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
53
|
+
|
|
54
|
+
p = sub.add_parser("index", help="Build or incrementally update the local index and PROJECT_MAP.md")
|
|
55
|
+
p.add_argument("repo", type=Path)
|
|
56
|
+
p.add_argument("--force", action="store_true")
|
|
57
|
+
p.add_argument("--map-budget-tokens", type=int, default=None)
|
|
58
|
+
p.add_argument("--no-gitignore", action="store_true")
|
|
59
|
+
p.add_argument("--no-git-exclude", action="store_true", help="Do not auto-add .agent-index/ to .git/info/exclude")
|
|
60
|
+
p.add_argument("--quiet", action="store_true", help="Suppress stdout summary")
|
|
61
|
+
p.add_argument("--hook-format", choices=["none", "gemini", "claude"], default="none", help="Emit hook-compatible JSON on stdout")
|
|
62
|
+
|
|
63
|
+
p = sub.add_parser("status", help="Show index stats and optional staleness check")
|
|
64
|
+
p.add_argument("repo", type=Path)
|
|
65
|
+
p.add_argument("--check-stale", action="store_true")
|
|
66
|
+
|
|
67
|
+
p = sub.add_parser("map", help="Print compact PROJECT_MAP.md (indexes first if missing)")
|
|
68
|
+
p.add_argument("repo", type=Path)
|
|
69
|
+
p.add_argument("--max-tokens", type=int, default=None)
|
|
70
|
+
|
|
71
|
+
p = sub.add_parser("search", help="Hybrid FTS5 BM25 + symbol + path search")
|
|
72
|
+
p.add_argument("repo", type=Path)
|
|
73
|
+
p.add_argument("query")
|
|
74
|
+
p.add_argument("--limit", type=int, default=8)
|
|
75
|
+
p.add_argument("--lang", default=None)
|
|
76
|
+
p.add_argument("--path-prefix", default=None)
|
|
77
|
+
p.add_argument("--max-tokens", type=int, default=None)
|
|
78
|
+
p.add_argument("--format", choices=["json", "compact"], default="json")
|
|
79
|
+
|
|
80
|
+
p = sub.add_parser("symbols", help="Search extracted symbols across languages")
|
|
81
|
+
p.add_argument("repo", type=Path)
|
|
82
|
+
p.add_argument("pattern", nargs="?", default="")
|
|
83
|
+
p.add_argument("--path", default=None)
|
|
84
|
+
p.add_argument("--kind", default=None)
|
|
85
|
+
p.add_argument("--limit", type=int, default=30)
|
|
86
|
+
p.add_argument("--format", choices=["json", "compact"], default="json")
|
|
87
|
+
|
|
88
|
+
p = sub.add_parser("outline", help="Show structural file outline without implementation body")
|
|
89
|
+
p.add_argument("repo", type=Path)
|
|
90
|
+
p.add_argument("path")
|
|
91
|
+
p.add_argument("--format", choices=["json", "compact"], default="json")
|
|
92
|
+
|
|
93
|
+
p = sub.add_parser("slice", help="Read 1 or more symbol bodies or line ranges from disk (`a.py:foo b.py:10-40`)")
|
|
94
|
+
p.add_argument("repo", type=Path)
|
|
95
|
+
p.add_argument("paths", nargs="+", help="One or more targets: `path`, `path:start-end`, `path:Symbol`, `path:Class.method`")
|
|
96
|
+
p.add_argument("--start", type=int, default=None)
|
|
97
|
+
p.add_argument("--end", type=int, default=None)
|
|
98
|
+
p.add_argument("--symbol", default=None)
|
|
99
|
+
p.add_argument("--context", type=int, default=2)
|
|
100
|
+
p.add_argument("--max-tokens", type=int, default=None)
|
|
101
|
+
p.add_argument("--with-header", action="store_true", help="Prepend compact file imports, module constants & enclosing class signature")
|
|
102
|
+
p.add_argument("--format", choices=["json", "compact"], default="compact")
|
|
103
|
+
|
|
104
|
+
p = sub.add_parser("refs", help="Find importers and code references to a symbol or path")
|
|
105
|
+
p.add_argument("repo", type=Path)
|
|
106
|
+
p.add_argument("target")
|
|
107
|
+
p.add_argument("--limit", type=int, default=25)
|
|
108
|
+
p.add_argument("--format", choices=["json", "compact"], default="json")
|
|
109
|
+
|
|
110
|
+
p = sub.add_parser("deps", help="Show outgoing imports and incoming blast-radius dependents")
|
|
111
|
+
p.add_argument("repo", type=Path)
|
|
112
|
+
p.add_argument("path")
|
|
113
|
+
p.add_argument("--depth", type=int, default=1)
|
|
114
|
+
p.add_argument("--format", choices=["json", "compact"], default="json")
|
|
115
|
+
|
|
116
|
+
p = sub.add_parser("callgraph", help="Show symbol-level callers and callees across the repository")
|
|
117
|
+
p.add_argument("repo", type=Path)
|
|
118
|
+
p.add_argument("symbol")
|
|
119
|
+
p.add_argument("--direction", choices=["both", "callers", "callees"], default="both")
|
|
120
|
+
p.add_argument("--depth", type=int, default=2)
|
|
121
|
+
p.add_argument("--limit", type=int, default=40)
|
|
122
|
+
p.add_argument("--lsp", action="store_true", help="Use installed local LSP server (tsserver/pyright/rust-analyzer/gopls) for type-checked callers when available")
|
|
123
|
+
p.add_argument("--format", choices=["compact", "json"], default="compact")
|
|
124
|
+
|
|
125
|
+
p = sub.add_parser("changed", help="Show git-changed files and their indexed symbols")
|
|
126
|
+
p.add_argument("repo", type=Path)
|
|
127
|
+
p.add_argument("--base", default="HEAD")
|
|
128
|
+
|
|
129
|
+
p = sub.add_parser("pack", help="Build a strictly token-budgeted context bundle for a task")
|
|
130
|
+
p.add_argument("repo", type=Path)
|
|
131
|
+
p.add_argument("query")
|
|
132
|
+
p.add_argument("--budget-tokens", type=int, default=2500)
|
|
133
|
+
p.add_argument("--include-map", action="store_true")
|
|
134
|
+
p.add_argument("--files", default="")
|
|
135
|
+
p.add_argument("--format", choices=["md", "json"], default="md")
|
|
136
|
+
|
|
137
|
+
p = sub.add_parser("diff-pack", help="Build a strictly token-budgeted diff + affected symbols + callers bundle")
|
|
138
|
+
p.add_argument("repo", type=Path)
|
|
139
|
+
p.add_argument("--base", default="HEAD")
|
|
140
|
+
p.add_argument("--budget-tokens", type=int, default=2500)
|
|
141
|
+
p.add_argument("--format", choices=["md", "json"], default="md")
|
|
142
|
+
|
|
143
|
+
p = sub.add_parser("trace-pack", help="Parse stacktrace text/file/stdin and pack in-repo failing function slices")
|
|
144
|
+
p.add_argument("repo", type=Path)
|
|
145
|
+
p.add_argument("--file", dest="trace_file", type=Path, default=None, help="Read stacktrace from file (default: stdin)")
|
|
146
|
+
p.add_argument("--text", dest="trace_text", default=None, help="Inline stacktrace text")
|
|
147
|
+
p.add_argument("--budget-tokens", type=int, default=1800)
|
|
148
|
+
p.add_argument("--max-frames", type=int, default=6)
|
|
149
|
+
p.add_argument("--context", type=int, default=3)
|
|
150
|
+
p.add_argument("--format", choices=["md", "json"], default="md")
|
|
151
|
+
|
|
152
|
+
p = sub.add_parser("tests-for", help="Find minimal affected test files for changed or explicit source paths")
|
|
153
|
+
p.add_argument("repo", type=Path)
|
|
154
|
+
p.add_argument("paths", nargs="*", help="Optional explicit file paths (defaults to git changed files)")
|
|
155
|
+
p.add_argument("--base", default="HEAD")
|
|
156
|
+
p.add_argument("--depth", type=int, default=2)
|
|
157
|
+
p.add_argument("--max-tests", type=int, default=15)
|
|
158
|
+
p.add_argument("--format", choices=["compact", "json", "cmd"], default="compact")
|
|
159
|
+
|
|
160
|
+
p = sub.add_parser("run", help="Execute a test/build command, compress output, and auto-attach failing trace code slices")
|
|
161
|
+
p.add_argument("repo", type=Path)
|
|
162
|
+
p.add_argument("--budget-tokens", type=int, default=800)
|
|
163
|
+
p.add_argument("--timeout", type=int, default=120)
|
|
164
|
+
p.add_argument("--shell", dest="shell_cmd", default=None)
|
|
165
|
+
p.add_argument("--no-trace-slices", action="store_true", help="Disable auto-attaching in-repo stacktrace slices on failure")
|
|
166
|
+
p.add_argument("--trace-budget-tokens", type=int, default=None, help="Token budget for failure trace slices")
|
|
167
|
+
p.add_argument("--verbose", action="store_true", help="Wider pre-error context, higher warning retention & larger default budget")
|
|
168
|
+
p.add_argument("--format", choices=["compact", "json"], default="compact")
|
|
169
|
+
p.add_argument("command", nargs=argparse.REMAINDER)
|
|
170
|
+
|
|
171
|
+
p = sub.add_parser("show", help="Show indexed file content (prefer `outline` or `slice`)")
|
|
172
|
+
p.add_argument("repo", type=Path)
|
|
173
|
+
p.add_argument("path")
|
|
174
|
+
p.add_argument("--start", type=int, default=None)
|
|
175
|
+
p.add_argument("--end", type=int, default=None)
|
|
176
|
+
|
|
177
|
+
p = sub.add_parser("watch", help="Watch repository with debounce and incremental re-indexing")
|
|
178
|
+
p.add_argument("repo", type=Path)
|
|
179
|
+
p.add_argument("--debounce", type=float, default=0.5)
|
|
180
|
+
return ap
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
184
|
+
configure_utf8_stdio()
|
|
185
|
+
args = _build_parser().parse_args(argv)
|
|
186
|
+
repo = args.repo.resolve()
|
|
187
|
+
|
|
188
|
+
if args.cmd == "index":
|
|
189
|
+
res = index(
|
|
190
|
+
repo,
|
|
191
|
+
force=args.force,
|
|
192
|
+
map_budget_tokens=args.map_budget_tokens,
|
|
193
|
+
use_gitignore=(False if args.no_gitignore else None),
|
|
194
|
+
auto_git_exclude=(False if args.no_git_exclude else None),
|
|
195
|
+
)
|
|
196
|
+
if args.hook_format in ("gemini", "claude"):
|
|
197
|
+
print("{}")
|
|
198
|
+
elif not args.quiet:
|
|
199
|
+
print(json.dumps(res, indent=2))
|
|
200
|
+
elif args.cmd == "status":
|
|
201
|
+
print(json.dumps(status(repo, check_stale=args.check_stale), indent=2))
|
|
202
|
+
elif args.cmd == "map":
|
|
203
|
+
mp = repo / ".agent-index" / "PROJECT_MAP.md"
|
|
204
|
+
assert_not_symlink_artifact(mp, repo)
|
|
205
|
+
if not mp.exists():
|
|
206
|
+
index(repo, map_budget_tokens=args.max_tokens)
|
|
207
|
+
print(mp.read_text(encoding="utf-8"), end="")
|
|
208
|
+
elif args.max_tokens is not None:
|
|
209
|
+
db, _ = db_open(repo, read_only=True)
|
|
210
|
+
print(build_project_map(repo, db, budget_tokens=args.max_tokens), end="")
|
|
211
|
+
db.close()
|
|
212
|
+
else:
|
|
213
|
+
print(mp.read_text(encoding="utf-8"), end="")
|
|
214
|
+
elif args.cmd == "search":
|
|
215
|
+
hits = search(repo, args.query, limit=args.limit, lang=args.lang, path_prefix=args.path_prefix, max_tokens=args.max_tokens)
|
|
216
|
+
print(_format_compact_search(hits) if args.format == "compact" else json.dumps(hits, indent=2, ensure_ascii=False))
|
|
217
|
+
elif args.cmd == "symbols":
|
|
218
|
+
syms = list_symbols(repo, args.pattern, path_filter=args.path, kind_filter=args.kind, limit=args.limit)
|
|
219
|
+
if args.format == "compact":
|
|
220
|
+
for s in syms:
|
|
221
|
+
print(f"{s['path']}:L{s['line']}-{s['end_line']} [{s['kind']}] {s['signature']}")
|
|
222
|
+
else:
|
|
223
|
+
print(json.dumps(syms, indent=2, ensure_ascii=False))
|
|
224
|
+
elif args.cmd == "outline":
|
|
225
|
+
ol = file_outline(repo, args.path)
|
|
226
|
+
if args.format == "compact":
|
|
227
|
+
print(f"{ol['path']} ({ol['lines']}L, ~{ol['full_file_tokens_est']} tok → outline ~{ol['outline_tokens_est']} tok, -{ol['token_savings_pct']}%)")
|
|
228
|
+
print(f"Summary: {ol['summary']}")
|
|
229
|
+
if ol["imports"]:
|
|
230
|
+
print(f"Imports: {', '.join(ol['imports'][:15])}")
|
|
231
|
+
for s in ol["symbols"]:
|
|
232
|
+
doc = f" — {s['doc']}" if s["doc"] else ""
|
|
233
|
+
print(f" L{s['lines']} [{s['kind']}] {s['signature']}{doc}")
|
|
234
|
+
else:
|
|
235
|
+
print(json.dumps(ol, indent=2, ensure_ascii=False))
|
|
236
|
+
elif args.cmd == "slice":
|
|
237
|
+
if len(args.paths) == 1:
|
|
238
|
+
sl = slice_file(
|
|
239
|
+
repo,
|
|
240
|
+
args.paths[0],
|
|
241
|
+
start=args.start,
|
|
242
|
+
end=args.end,
|
|
243
|
+
symbol=args.symbol,
|
|
244
|
+
context=args.context,
|
|
245
|
+
max_tokens=args.max_tokens,
|
|
246
|
+
with_header=args.with_header,
|
|
247
|
+
)
|
|
248
|
+
if args.format == "compact":
|
|
249
|
+
stale = " [INDEX STALE — live disk read]" if sl["index_stale"] else ""
|
|
250
|
+
print(f"# {sl['path']} L{sl['start_line']}-{sl['end_line']}/{sl['total_lines']} (~{sl['slice_tokens_est']} tok, -{sl['token_savings_pct']}% vs full){stale}\n{sl['text']}")
|
|
251
|
+
else:
|
|
252
|
+
print(json.dumps(sl, indent=2, ensure_ascii=False))
|
|
253
|
+
else:
|
|
254
|
+
ms = slice_many(repo, args.paths, context=args.context, max_tokens=args.max_tokens, with_header=args.with_header)
|
|
255
|
+
print(_format_compact_multi_slice(ms) if args.format == "compact" else json.dumps(ms, indent=2, ensure_ascii=False))
|
|
256
|
+
elif args.cmd == "refs":
|
|
257
|
+
res = find_refs(repo, args.target, limit=args.limit)
|
|
258
|
+
if args.format == "compact":
|
|
259
|
+
print(f"Target: {res['target']} ({res['reference_files_count']} files)")
|
|
260
|
+
for imp in res["importers"]:
|
|
261
|
+
print(f" [import] {imp['src_path']} -> {imp['dst_raw']}")
|
|
262
|
+
for occ in res["occurrences"]:
|
|
263
|
+
print(f" {occ['path']}:{occ['line']} {occ['text']}")
|
|
264
|
+
else:
|
|
265
|
+
print(json.dumps(res, indent=2, ensure_ascii=False))
|
|
266
|
+
elif args.cmd == "deps":
|
|
267
|
+
res = file_deps(repo, args.path, depth=args.depth)
|
|
268
|
+
print(_format_compact_deps(res) if args.format == "compact" else json.dumps(res, indent=2, ensure_ascii=False))
|
|
269
|
+
elif args.cmd == "callgraph":
|
|
270
|
+
cg = call_graph(repo, args.symbol, direction=args.direction, depth=args.depth, limit=args.limit, use_lsp=args.lsp)
|
|
271
|
+
print(_format_compact_callgraph(cg) if args.format == "compact" else json.dumps(cg, indent=2, ensure_ascii=False))
|
|
272
|
+
elif args.cmd == "changed":
|
|
273
|
+
print(json.dumps(git_changed(repo, base=args.base), indent=2, ensure_ascii=False))
|
|
274
|
+
elif args.cmd == "pack":
|
|
275
|
+
pk = context_pack(repo, args.query, budget_tokens=args.budget_tokens, include_map=args.include_map, explicit_files=[x.strip() for x in args.files.split(",") if x.strip()])
|
|
276
|
+
print(_format_compact_pack(pk) if args.format == "md" else json.dumps(pk, indent=2, ensure_ascii=False))
|
|
277
|
+
elif args.cmd == "diff-pack":
|
|
278
|
+
dp = diff_pack(repo, base=args.base, budget_tokens=args.budget_tokens)
|
|
279
|
+
print(_format_compact_diff_pack(dp) if args.format == "md" else json.dumps(dp, indent=2, ensure_ascii=False))
|
|
280
|
+
elif args.cmd == "trace-pack":
|
|
281
|
+
if args.trace_text is not None:
|
|
282
|
+
raw_trace = args.trace_text
|
|
283
|
+
elif args.trace_file is not None:
|
|
284
|
+
raw_trace = args.trace_file.read_text(encoding="utf-8", errors="replace")
|
|
285
|
+
elif not sys.stdin.isatty():
|
|
286
|
+
raw_trace = sys.stdin.read()
|
|
287
|
+
else:
|
|
288
|
+
raise SystemExit("Provide `--text '...'`, `--file <log>`, or pipe stacktrace via stdin.")
|
|
289
|
+
tp = trace_pack(repo, raw_trace, budget_tokens=args.budget_tokens, max_frames=args.max_frames, context=args.context)
|
|
290
|
+
print(_format_compact_trace_pack(tp) if args.format == "md" else json.dumps(tp, indent=2, ensure_ascii=False))
|
|
291
|
+
elif args.cmd == "tests-for":
|
|
292
|
+
tf = find_affected_tests(repo, args.paths, base=args.base, depth=args.depth, max_tests=args.max_tests)
|
|
293
|
+
if args.format == "json":
|
|
294
|
+
print(json.dumps(tf, indent=2, ensure_ascii=False))
|
|
295
|
+
elif args.format == "cmd":
|
|
296
|
+
print(tf.get("suggested_command") or " ".join(a["path"] for a in tf.get("affected_tests", [])))
|
|
297
|
+
else:
|
|
298
|
+
print(_format_compact_tests_for(tf))
|
|
299
|
+
elif args.cmd == "run":
|
|
300
|
+
cmd_argv = list(args.command)
|
|
301
|
+
if cmd_argv and cmd_argv[0] == "--":
|
|
302
|
+
cmd_argv = cmd_argv[1:]
|
|
303
|
+
run_kw = dict(
|
|
304
|
+
budget_tokens=args.budget_tokens,
|
|
305
|
+
timeout=args.timeout,
|
|
306
|
+
include_trace_slices=not args.no_trace_slices,
|
|
307
|
+
trace_budget_tokens=args.trace_budget_tokens,
|
|
308
|
+
verbose=args.verbose,
|
|
309
|
+
)
|
|
310
|
+
if args.shell_cmd:
|
|
311
|
+
res = run_compact(repo, args.shell_cmd, shell=True, **run_kw)
|
|
312
|
+
elif cmd_argv:
|
|
313
|
+
res = run_compact(repo, cmd_argv, shell=False, **run_kw)
|
|
314
|
+
else:
|
|
315
|
+
raise SystemExit("Provide either `--shell '<cmd>'` or `-- <cmd> [args...]`.")
|
|
316
|
+
if args.format == "json":
|
|
317
|
+
print(json.dumps(res, indent=2, ensure_ascii=False))
|
|
318
|
+
else:
|
|
319
|
+
log_note = f" | full_log={res['full_log']}" if res.get("full_log") else ""
|
|
320
|
+
print(f"$ {res['cmd']} -> exit {res['exit_code']} ({res['duration_ms']}ms, ~{res['raw_tokens_est']} -> ~{res['compact_tokens_est']} tok, -{res['token_savings_pct']}%){log_note}\n{res['output']}")
|
|
321
|
+
if res.get("trace_slices_md"):
|
|
322
|
+
print(f"\n{res['trace_slices_md']}")
|
|
323
|
+
return int(res["exit_code"])
|
|
324
|
+
elif args.cmd == "show":
|
|
325
|
+
rel = normalize_rel_path(args.path)
|
|
326
|
+
if args.start is not None or args.end is not None:
|
|
327
|
+
print(slice_file(repo, rel, start=args.start, end=args.end)["text"])
|
|
328
|
+
else:
|
|
329
|
+
db, _ = db_open(repo, read_only=True)
|
|
330
|
+
row = db.execute("SELECT content FROM files WHERE path=?", (rel,)).fetchone()
|
|
331
|
+
db.close()
|
|
332
|
+
if not row:
|
|
333
|
+
raise SystemExit("File not indexed; reindex or check path.")
|
|
334
|
+
print(redact_secrets(row[0]))
|
|
335
|
+
elif args.cmd == "watch":
|
|
336
|
+
run_watch(repo, debounce=args.debounce)
|
|
337
|
+
return 0
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
if __name__ == "__main__":
|
|
341
|
+
raise SystemExit(main())
|