agentsam-sdk 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.
- agentsam_sdk-0.1.0/LICENSE +21 -0
- agentsam_sdk-0.1.0/PKG-INFO +107 -0
- agentsam_sdk-0.1.0/README.md +78 -0
- agentsam_sdk-0.1.0/agentsam_sdk/__init__.py +13 -0
- agentsam_sdk-0.1.0/agentsam_sdk/cli.py +263 -0
- agentsam_sdk-0.1.0/agentsam_sdk/client.py +220 -0
- agentsam_sdk-0.1.0/agentsam_sdk/data/__init__.py +0 -0
- agentsam_sdk-0.1.0/agentsam_sdk/data/agentsam_walk.py +158 -0
- agentsam_sdk-0.1.0/agentsam_sdk/data/d1_adapter.py +124 -0
- agentsam_sdk-0.1.0/agentsam_sdk/data/d1_bloat.py +445 -0
- agentsam_sdk-0.1.0/agentsam_sdk/errors/__init__.py +4 -0
- agentsam_sdk-0.1.0/agentsam_sdk/errors/vocabulary.py +2740 -0
- agentsam_sdk-0.1.0/agentsam_sdk/hooks/__init__.py +32 -0
- agentsam_sdk-0.1.0/agentsam_sdk/hooks/adapters.py +132 -0
- agentsam_sdk-0.1.0/agentsam_sdk/hooks/contracts.py +121 -0
- agentsam_sdk-0.1.0/agentsam_sdk/hooks/runtime.py +253 -0
- agentsam_sdk-0.1.0/agentsam_sdk/knowledge/__init__.py +3 -0
- agentsam_sdk-0.1.0/agentsam_sdk/knowledge/client.py +33 -0
- agentsam_sdk-0.1.0/agentsam_sdk/knowledge/models.py +126 -0
- agentsam_sdk-0.1.0/agentsam_sdk/py.typed +0 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/__init__.py +12 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/__main__.py +3 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/inspect.py +496 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/__init__.py +5 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/__main__.py +3 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/cli.py +84 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/discovery.py +153 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/git.py +84 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/metrics.py +92 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/intelligence/snapshot.py +108 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/inventory.py +352 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/recon/__init__.py +28 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/recon/__main__.py +3 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/recon/cli.py +178 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/recon/packet.py +294 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/recon/validate.py +76 -0
- agentsam_sdk-0.1.0/agentsam_sdk/repository/scan_bloat.py +173 -0
- agentsam_sdk-0.1.0/agentsam_sdk/runtime/__init__.py +0 -0
- agentsam_sdk-0.1.0/agentsam_sdk/runtime/contract.py +119 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/__init__.py +52 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/__main__.py +4 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/bootstrap.py +15 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/demo.py +306 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/frames.py +147 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/onboarding.py +208 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/status.py +87 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/theme.py +57 -0
- agentsam_sdk-0.1.0/agentsam_sdk/tui/widgets.py +218 -0
- agentsam_sdk-0.1.0/agentsam_sdk.egg-info/PKG-INFO +107 -0
- agentsam_sdk-0.1.0/agentsam_sdk.egg-info/SOURCES.txt +67 -0
- agentsam_sdk-0.1.0/agentsam_sdk.egg-info/dependency_links.txt +1 -0
- agentsam_sdk-0.1.0/agentsam_sdk.egg-info/entry_points.txt +2 -0
- agentsam_sdk-0.1.0/agentsam_sdk.egg-info/requires.txt +3 -0
- agentsam_sdk-0.1.0/agentsam_sdk.egg-info/top_level.txt +1 -0
- agentsam_sdk-0.1.0/pyproject.toml +49 -0
- agentsam_sdk-0.1.0/setup.cfg +4 -0
- agentsam_sdk-0.1.0/tests/test_agentsam_walk.py +31 -0
- agentsam_sdk-0.1.0/tests/test_contract.py +43 -0
- agentsam_sdk-0.1.0/tests/test_d1_bloat.py +93 -0
- agentsam_sdk-0.1.0/tests/test_hooks.py +115 -0
- agentsam_sdk-0.1.0/tests/test_knowledge_models.py +26 -0
- agentsam_sdk-0.1.0/tests/test_packaging.py +42 -0
- agentsam_sdk-0.1.0/tests/test_public_client.py +82 -0
- agentsam_sdk-0.1.0/tests/test_recon.py +257 -0
- agentsam_sdk-0.1.0/tests/test_repository_inspect.py +84 -0
- agentsam_sdk-0.1.0/tests/test_repository_intelligence.py +99 -0
- agentsam_sdk-0.1.0/tests/test_repository_inventory.py +53 -0
- agentsam_sdk-0.1.0/tests/test_scan_bloat.py +31 -0
- agentsam_sdk-0.1.0/tests/test_tui_cli.py +26 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Inner Animal Media
|
|
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.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentsam-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Stdlib-first Agent Sam repository/data CLI and local SAM client, with an optional Rich terminal UI.
|
|
5
|
+
Author-email: Sam Primeaux <sam@inneranimalmedia.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/SamPrimeaux/agentsam-sdk
|
|
8
|
+
Project-URL: Repository, https://github.com/SamPrimeaux/agentsam-sdk
|
|
9
|
+
Project-URL: Issues, https://github.com/SamPrimeaux/agentsam-sdk/issues
|
|
10
|
+
Project-URL: npm, https://www.npmjs.com/package/@inneranimalmedia/agentsam-sdk
|
|
11
|
+
Keywords: agentsam,sam,agents,sdk,repository,cli
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: tui
|
|
27
|
+
Requires-Dist: rich>=13.7.0; extra == "tui"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# agentsam-sdk (Python)
|
|
31
|
+
|
|
32
|
+
Core repository/data commands remain **stdlib-only** (`dependencies = []`).
|
|
33
|
+
Rich is an optional renderer dependency used by the SDK's internal terminal preview lab;
|
|
34
|
+
it is not exposed as an installed-user renderer command.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install agentsam-sdk # stdlib-only core
|
|
38
|
+
pip install "agentsam-sdk[tui]" # optional Rich terminal renderer
|
|
39
|
+
agentsam repository inventory --repo-root /path/to/repo --format json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Requires Python 3.10+. For development from a checkout: `cd python && pip install -e .`
|
|
43
|
+
then `python -m unittest discover -s tests -v`.
|
|
44
|
+
|
|
45
|
+
### `AgentSamClient.invoke()`
|
|
46
|
+
|
|
47
|
+
The repository, data, hooks and `agentsam` CLI tools run entirely in Python. The local
|
|
48
|
+
SAM client (`AgentSamClient`) delegates to the Node SAM kernel, so it needs Node 20+ and
|
|
49
|
+
the npm package in the project or a parent directory:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install @inneranimalmedia/agentsam-sdk
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The bridge is found automatically from the working directory. It is read-only by design:
|
|
56
|
+
write, D1, CMS and terminal operations are refused (`sam_bridge_operation_not_allowed`).
|
|
57
|
+
Without the npm package, `invoke()` raises `sam_bridge_not_installed`.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Protocol: [`../protocol/README.md`](https://github.com/SamPrimeaux/agentsam-sdk/blob/main/protocol/README.md).
|
|
61
|
+
|
|
62
|
+
## Portable lifecycle hooks
|
|
63
|
+
|
|
64
|
+
`agentsam_sdk.hooks` implements the same `agentsam.hook.v1` envelope as the
|
|
65
|
+
JavaScript/TypeScript, Go, Rust, command, and HTTP adapters. It is stdlib-only:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from agentsam_sdk.hooks import HookRuntime
|
|
69
|
+
|
|
70
|
+
hooks = HookRuntime()
|
|
71
|
+
hooks.register("pre_tool_use", lambda envelope: {
|
|
72
|
+
"permission_decision": "allow"
|
|
73
|
+
})
|
|
74
|
+
result = await hooks.dispatch("pre_tool_use", {
|
|
75
|
+
"tool_name": "repository.snapshot", "tool_args": {}
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
See [`../packages/agentsam-hooks/README.md`](https://github.com/SamPrimeaux/agentsam-sdk/blob/main/packages/agentsam-hooks/README.md)
|
|
80
|
+
for composition, permission, and subprocess transport rules.
|
|
81
|
+
|
|
82
|
+
## Optional sibling packages (not part of stdlib core)
|
|
83
|
+
|
|
84
|
+
| Package | Path | Notes |
|
|
85
|
+
|---------|------|-------|
|
|
86
|
+
| `agentsam-site-scrape` | [`../packages/agentsam-site-scrape/`](https://github.com/SamPrimeaux/agentsam-sdk/blob/main/packages/agentsam-site-scrape/) | Optional/network (`requests`); crawl→R2. Dual-homed with IAM `tools/agentsam-site-scrape/`. Does **not** fold into `agentsam_sdk`. |
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Internal Rich renderer preview
|
|
90
|
+
|
|
91
|
+
The npm SDK owns the public interactive experience. For renderer development only:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
cd ..
|
|
95
|
+
npm run ui:preview -- tour
|
|
96
|
+
npm run ui:preview -- thinking
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The Python module can also be invoked directly after installing the optional extra:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
cd python
|
|
103
|
+
pip install -e '.[tui]'
|
|
104
|
+
PYTHONPATH=. python -m agentsam_sdk.tui --scene dashboard --check
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`agentsam_sdk.tui` is presentation-only. It does not define tools, execution policy, or public CLI vocabulary.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# agentsam-sdk (Python)
|
|
2
|
+
|
|
3
|
+
Core repository/data commands remain **stdlib-only** (`dependencies = []`).
|
|
4
|
+
Rich is an optional renderer dependency used by the SDK's internal terminal preview lab;
|
|
5
|
+
it is not exposed as an installed-user renderer command.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install agentsam-sdk # stdlib-only core
|
|
9
|
+
pip install "agentsam-sdk[tui]" # optional Rich terminal renderer
|
|
10
|
+
agentsam repository inventory --repo-root /path/to/repo --format json
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Python 3.10+. For development from a checkout: `cd python && pip install -e .`
|
|
14
|
+
then `python -m unittest discover -s tests -v`.
|
|
15
|
+
|
|
16
|
+
### `AgentSamClient.invoke()`
|
|
17
|
+
|
|
18
|
+
The repository, data, hooks and `agentsam` CLI tools run entirely in Python. The local
|
|
19
|
+
SAM client (`AgentSamClient`) delegates to the Node SAM kernel, so it needs Node 20+ and
|
|
20
|
+
the npm package in the project or a parent directory:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @inneranimalmedia/agentsam-sdk
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The bridge is found automatically from the working directory. It is read-only by design:
|
|
27
|
+
write, D1, CMS and terminal operations are refused (`sam_bridge_operation_not_allowed`).
|
|
28
|
+
Without the npm package, `invoke()` raises `sam_bridge_not_installed`.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Protocol: [`../protocol/README.md`](https://github.com/SamPrimeaux/agentsam-sdk/blob/main/protocol/README.md).
|
|
32
|
+
|
|
33
|
+
## Portable lifecycle hooks
|
|
34
|
+
|
|
35
|
+
`agentsam_sdk.hooks` implements the same `agentsam.hook.v1` envelope as the
|
|
36
|
+
JavaScript/TypeScript, Go, Rust, command, and HTTP adapters. It is stdlib-only:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from agentsam_sdk.hooks import HookRuntime
|
|
40
|
+
|
|
41
|
+
hooks = HookRuntime()
|
|
42
|
+
hooks.register("pre_tool_use", lambda envelope: {
|
|
43
|
+
"permission_decision": "allow"
|
|
44
|
+
})
|
|
45
|
+
result = await hooks.dispatch("pre_tool_use", {
|
|
46
|
+
"tool_name": "repository.snapshot", "tool_args": {}
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
See [`../packages/agentsam-hooks/README.md`](https://github.com/SamPrimeaux/agentsam-sdk/blob/main/packages/agentsam-hooks/README.md)
|
|
51
|
+
for composition, permission, and subprocess transport rules.
|
|
52
|
+
|
|
53
|
+
## Optional sibling packages (not part of stdlib core)
|
|
54
|
+
|
|
55
|
+
| Package | Path | Notes |
|
|
56
|
+
|---------|------|-------|
|
|
57
|
+
| `agentsam-site-scrape` | [`../packages/agentsam-site-scrape/`](https://github.com/SamPrimeaux/agentsam-sdk/blob/main/packages/agentsam-site-scrape/) | Optional/network (`requests`); crawl→R2. Dual-homed with IAM `tools/agentsam-site-scrape/`. Does **not** fold into `agentsam_sdk`. |
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Internal Rich renderer preview
|
|
61
|
+
|
|
62
|
+
The npm SDK owns the public interactive experience. For renderer development only:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
cd ..
|
|
66
|
+
npm run ui:preview -- tour
|
|
67
|
+
npm run ui:preview -- thinking
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The Python module can also be invoked directly after installing the optional extra:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
cd python
|
|
74
|
+
pip install -e '.[tui]'
|
|
75
|
+
PYTHONPATH=. python -m agentsam_sdk.tui --scene dashboard --check
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`agentsam_sdk.tui` is presentation-only. It does not define tools, execution policy, or public CLI vocabulary.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""agentsam_sdk — stdlib-only toolkit for inneranimalmedia D1/repo audits.
|
|
2
|
+
|
|
3
|
+
Every tool follows the runtime.contract pattern: ToolInput in, ToolResult out,
|
|
4
|
+
plus a receipt written to output_dir for audit trail. No hardcoded
|
|
5
|
+
identity/repo/workspace/tenant values anywhere in this package — see
|
|
6
|
+
runtime.contract.HARD_LAW_NOTE.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
|
|
11
|
+
# Public local SAM client. Remote ACP, MCP and app-specific authorities remain
|
|
12
|
+
# separately scoped; their mere existence does not grant this client access.
|
|
13
|
+
from .client import AgentSamClient, AsyncAgentSamClient, Choose, Check, Score, SamClientError
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"""agentsam CLI -- stdlib argparse only (no click/typer dep, per project
|
|
2
|
+
convention: Python tooling here is stdlib-only).
|
|
3
|
+
|
|
4
|
+
agentsam data d1-bloat --quick --format markdown --output-dir /tmp/d1-bloat
|
|
5
|
+
agentsam data agentsam-walk --prefix agentsam_ --output-dir /tmp/walk
|
|
6
|
+
agentsam repository inventory --repo-root .. --output-dir /tmp/scan --format json
|
|
7
|
+
agentsam repository inventory --repo-root .. --format json | jq '.data.totals'
|
|
8
|
+
agentsam repository scan-bloat --root src --min-kb 10 --top 30 --format json
|
|
9
|
+
agentsam repository inspect --repo-root . --json --dupes | jq '.duplicates'
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import sys
|
|
16
|
+
|
|
17
|
+
from agentsam_sdk.runtime.contract import ToolInput, ToolResult
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _print_result(result: ToolResult, fmt: str) -> None:
|
|
21
|
+
if fmt == "json":
|
|
22
|
+
print(json.dumps(result.to_dict(), indent=2, default=str))
|
|
23
|
+
else:
|
|
24
|
+
status = "OK" if result.ok else "FAIL"
|
|
25
|
+
print(f"[{status}] {result.tool} ({result.mode}) — {result.summary}", file=sys.stderr)
|
|
26
|
+
if result.error:
|
|
27
|
+
print(f" error: {result.error}", file=sys.stderr)
|
|
28
|
+
for a in result.artifacts:
|
|
29
|
+
print(f" wrote: {a}", file=sys.stderr)
|
|
30
|
+
# When markdown artifacts were written, surface path; else dump summary data keys
|
|
31
|
+
if fmt == "markdown" and result.ok and result.data.get("categories"):
|
|
32
|
+
# stdout stays quiet when artifacts exist; callers use the .md file
|
|
33
|
+
if not result.artifacts:
|
|
34
|
+
from agentsam_sdk.repository.inventory import _markdown
|
|
35
|
+
|
|
36
|
+
sys.stdout.write(_markdown(result.data))
|
|
37
|
+
if fmt == "markdown" and result.ok and result.data.get("files") is not None:
|
|
38
|
+
from agentsam_sdk.repository.scan_bloat import human_table
|
|
39
|
+
|
|
40
|
+
sys.stdout.write(
|
|
41
|
+
human_table(
|
|
42
|
+
result.data.get("files") or [],
|
|
43
|
+
scanned=int(result.data.get("file_count") or 0),
|
|
44
|
+
total_kb=float(result.data.get("total_kb") or 0),
|
|
45
|
+
total_tokens=int(result.data.get("total_est_tokens") or 0),
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _cmd_data_d1_bloat(args: argparse.Namespace) -> int:
|
|
51
|
+
from agentsam_sdk.data import d1_bloat
|
|
52
|
+
|
|
53
|
+
mode = "full" if args.full else "quick"
|
|
54
|
+
ti = ToolInput(
|
|
55
|
+
mode=mode,
|
|
56
|
+
params={
|
|
57
|
+
"db": args.db, "config": args.config, "repo_root": args.repo_root,
|
|
58
|
+
"prefix": args.prefix, "workers": args.workers, "top": args.top,
|
|
59
|
+
},
|
|
60
|
+
output_dir=args.output_dir,
|
|
61
|
+
)
|
|
62
|
+
result = d1_bloat.run(ti)
|
|
63
|
+
_print_result(result, args.format)
|
|
64
|
+
return 0 if result.ok else 1
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _cmd_data_agentsam_walk(args: argparse.Namespace) -> int:
|
|
68
|
+
from agentsam_sdk.data import agentsam_walk
|
|
69
|
+
|
|
70
|
+
ti = ToolInput(
|
|
71
|
+
mode="default",
|
|
72
|
+
params={"db": args.db, "config": args.config, "repo_root": args.repo_root, "prefix": args.prefix},
|
|
73
|
+
output_dir=args.output_dir,
|
|
74
|
+
)
|
|
75
|
+
result = agentsam_walk.run(ti)
|
|
76
|
+
_print_result(result, args.format)
|
|
77
|
+
return 0 if result.ok else 1
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _cmd_repository_inventory(args: argparse.Namespace) -> int:
|
|
81
|
+
from agentsam_sdk.repository import inventory
|
|
82
|
+
|
|
83
|
+
ti = ToolInput(
|
|
84
|
+
mode="read-only",
|
|
85
|
+
params={
|
|
86
|
+
"repo_root": args.repo_root,
|
|
87
|
+
"top": args.top,
|
|
88
|
+
"min_bytes": args.min_bytes,
|
|
89
|
+
"by_ext": args.by_ext,
|
|
90
|
+
"include_node_modules": args.include_node_modules,
|
|
91
|
+
"include_venvs": args.include_venvs,
|
|
92
|
+
"include_git": args.include_git,
|
|
93
|
+
"include_dist": args.include_dist,
|
|
94
|
+
"follow_symlinks": args.follow_symlinks,
|
|
95
|
+
},
|
|
96
|
+
output_dir=args.output_dir,
|
|
97
|
+
)
|
|
98
|
+
result = inventory.run(ti)
|
|
99
|
+
_print_result(result, args.format)
|
|
100
|
+
return 0 if result.ok else 1
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _cmd_repository_scan_bloat(args: argparse.Namespace) -> int:
|
|
104
|
+
from agentsam_sdk.repository import scan_bloat
|
|
105
|
+
|
|
106
|
+
ti = ToolInput(
|
|
107
|
+
mode="read-only",
|
|
108
|
+
params={
|
|
109
|
+
"root": args.root,
|
|
110
|
+
"top": args.top,
|
|
111
|
+
"min_kb": args.min_kb,
|
|
112
|
+
"ext": args.ext,
|
|
113
|
+
"exclude": args.exclude,
|
|
114
|
+
},
|
|
115
|
+
output_dir=args.output_dir,
|
|
116
|
+
)
|
|
117
|
+
result = scan_bloat.run(ti)
|
|
118
|
+
# Agent capture: --json-envelope prints data payload only (legacy tools/scan_bloat.py)
|
|
119
|
+
if args.json_envelope:
|
|
120
|
+
print(json.dumps(result.data if result.ok else {"ok": False, "error": result.error}, indent=2))
|
|
121
|
+
return 0 if result.ok else 1
|
|
122
|
+
_print_result(result, args.format)
|
|
123
|
+
return 0 if result.ok else 1
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _cmd_repository_inspect(args: argparse.Namespace) -> int:
|
|
127
|
+
from agentsam_sdk.repository import inspect as repo_inspect
|
|
128
|
+
|
|
129
|
+
argv: list[str] = []
|
|
130
|
+
if args.repo_root:
|
|
131
|
+
argv.extend(["--repo-root", args.repo_root])
|
|
132
|
+
want_text = bool(args.text) or args.format in ("text", "markdown")
|
|
133
|
+
want_json = bool(args.json) or args.format == "json" or not want_text
|
|
134
|
+
if want_json and not want_text:
|
|
135
|
+
argv.append("--json")
|
|
136
|
+
if want_text and not want_json:
|
|
137
|
+
argv.append("--text")
|
|
138
|
+
if want_text and want_json:
|
|
139
|
+
# Explicit both → JSON wins (machine default) unless only --text
|
|
140
|
+
argv.append("--json")
|
|
141
|
+
if args.dupes:
|
|
142
|
+
argv.append("--dupes")
|
|
143
|
+
if args.all:
|
|
144
|
+
argv.append("--all")
|
|
145
|
+
if args.since:
|
|
146
|
+
argv.extend(["--since", args.since])
|
|
147
|
+
if args.recent is not None:
|
|
148
|
+
argv.extend(["--recent", str(args.recent)])
|
|
149
|
+
if args.largest is not None:
|
|
150
|
+
argv.extend(["--largest", str(args.largest)])
|
|
151
|
+
if args.out:
|
|
152
|
+
argv.extend(["--out", args.out])
|
|
153
|
+
return repo_inspect.main_cli(argv)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
157
|
+
ap = argparse.ArgumentParser(prog="agentsam", description="agentsam_sdk CLI")
|
|
158
|
+
sub = ap.add_subparsers(dest="group", required=True)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
data = sub.add_parser("data", help="D1 data audits")
|
|
162
|
+
data_sub = data.add_subparsers(dest="cmd", required=True)
|
|
163
|
+
|
|
164
|
+
bloat = data_sub.add_parser(
|
|
165
|
+
"d1-bloat",
|
|
166
|
+
help="database-scoped D1 audit (--quick=counts, --full=text sizes)",
|
|
167
|
+
)
|
|
168
|
+
bloat.add_argument("--db", help="D1 database name (else AGENTSAM_D1_DB_NAME)")
|
|
169
|
+
bloat.add_argument("--config", help="wrangler config path (else AGENTSAM_WRANGLER_CONFIG)")
|
|
170
|
+
bloat.add_argument("--repo-root", help="repo root wrangler runs from")
|
|
171
|
+
bloat.add_argument("--quick", action="store_true", default=True,
|
|
172
|
+
help="All tables: COUNT(*) only (default)")
|
|
173
|
+
bloat.add_argument("--full", action="store_true",
|
|
174
|
+
help="All tables: row counts + text/JSON LENGTH estimates")
|
|
175
|
+
bloat.add_argument("--prefix", help="Only tables whose name starts with this prefix")
|
|
176
|
+
bloat.add_argument("--workers", type=int, default=6)
|
|
177
|
+
bloat.add_argument("--top", type=int, default=40)
|
|
178
|
+
bloat.add_argument("--output-dir")
|
|
179
|
+
bloat.add_argument("--format", choices=["json", "markdown"], default="markdown")
|
|
180
|
+
bloat.set_defaults(func=_cmd_data_d1_bloat)
|
|
181
|
+
|
|
182
|
+
walk = data_sub.add_parser("agentsam-walk", help="walk agentsam_* tables")
|
|
183
|
+
walk.add_argument("--db")
|
|
184
|
+
walk.add_argument("--config")
|
|
185
|
+
walk.add_argument("--repo-root")
|
|
186
|
+
walk.add_argument("--prefix", default="agentsam_")
|
|
187
|
+
walk.add_argument("--output-dir")
|
|
188
|
+
walk.add_argument("--format", choices=["json", "markdown"], default="markdown")
|
|
189
|
+
walk.set_defaults(func=_cmd_data_agentsam_walk)
|
|
190
|
+
|
|
191
|
+
repo = sub.add_parser("repository", help="repository-level audits")
|
|
192
|
+
repo_sub = repo.add_subparsers(dest="cmd", required=True)
|
|
193
|
+
inv = repo_sub.add_parser(
|
|
194
|
+
"inventory",
|
|
195
|
+
help="file counts + sizes by logical category (jq-friendly JSON)",
|
|
196
|
+
)
|
|
197
|
+
inv.add_argument("--repo-root", default=".")
|
|
198
|
+
inv.add_argument("--output-dir")
|
|
199
|
+
inv.add_argument("--format", choices=["json", "markdown"], default="json")
|
|
200
|
+
inv.add_argument("--top", type=int, default=20, help="N largest files (0 to omit)")
|
|
201
|
+
inv.add_argument("--min-bytes", type=int, default=0)
|
|
202
|
+
inv.add_argument(
|
|
203
|
+
"--by-ext",
|
|
204
|
+
action=argparse.BooleanOptionalAction,
|
|
205
|
+
default=True,
|
|
206
|
+
help="Include by_extension_detail with byte rollups (default: on)",
|
|
207
|
+
)
|
|
208
|
+
inv.add_argument("--include-node-modules", action="store_true")
|
|
209
|
+
inv.add_argument("--include-venvs", action="store_true")
|
|
210
|
+
inv.add_argument("--include-git", action="store_true")
|
|
211
|
+
inv.add_argument("--include-dist", action="store_true")
|
|
212
|
+
inv.add_argument("--follow-symlinks", action="store_true")
|
|
213
|
+
inv.set_defaults(func=_cmd_repository_inventory)
|
|
214
|
+
|
|
215
|
+
sb = repo_sub.add_parser(
|
|
216
|
+
"scan-bloat",
|
|
217
|
+
help="largest runtime source files (KB/lines/est. tokens)",
|
|
218
|
+
)
|
|
219
|
+
sb.add_argument("--root", default=".", help="directory to scan (default: cwd)")
|
|
220
|
+
sb.add_argument("--top", type=int, default=30)
|
|
221
|
+
sb.add_argument("--min-kb", type=float, default=0)
|
|
222
|
+
sb.add_argument(
|
|
223
|
+
"--ext",
|
|
224
|
+
default=".js,.ts,.jsx,.tsx,.mjs,.cjs",
|
|
225
|
+
help="comma-separated extensions",
|
|
226
|
+
)
|
|
227
|
+
sb.add_argument("--exclude", default="", help="extra dir names to exclude")
|
|
228
|
+
sb.add_argument("--output-dir")
|
|
229
|
+
sb.add_argument("--format", choices=["json", "markdown"], default="markdown")
|
|
230
|
+
sb.add_argument(
|
|
231
|
+
"--json-envelope",
|
|
232
|
+
action="store_true",
|
|
233
|
+
help="print ToolResult.data JSON only (agent/terminal capture)",
|
|
234
|
+
)
|
|
235
|
+
sb.set_defaults(func=_cmd_repository_scan_bloat)
|
|
236
|
+
|
|
237
|
+
insp = repo_sub.add_parser(
|
|
238
|
+
"inspect",
|
|
239
|
+
help="file walk: sizes + dates (+ optional --dupes SHA-256 groups)",
|
|
240
|
+
)
|
|
241
|
+
insp.add_argument("--repo-root", default=None)
|
|
242
|
+
insp.add_argument("--format", choices=["json", "markdown", "text"], default="json")
|
|
243
|
+
insp.add_argument("--json", action="store_true")
|
|
244
|
+
insp.add_argument("--text", action="store_true")
|
|
245
|
+
insp.add_argument("--dupes", action="store_true")
|
|
246
|
+
insp.add_argument("--all", action="store_true")
|
|
247
|
+
insp.add_argument("--since", default=None)
|
|
248
|
+
insp.add_argument("--recent", type=int, default=50)
|
|
249
|
+
insp.add_argument("--largest", type=int, default=30)
|
|
250
|
+
insp.add_argument("--out", default=None)
|
|
251
|
+
insp.set_defaults(func=_cmd_repository_inspect)
|
|
252
|
+
|
|
253
|
+
return ap
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def main(argv: list[str] | None = None) -> int:
|
|
257
|
+
parser = build_parser()
|
|
258
|
+
args = parser.parse_args(argv)
|
|
259
|
+
return args.func(args)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
if __name__ == "__main__":
|
|
263
|
+
sys.exit(main())
|