agentpack-cli 0.1.15__tar.gz → 0.1.16__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.
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/PKG-INFO +11 -7
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/README.md +10 -6
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/pyproject.toml +1 -1
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/__init__.py +1 -1
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/application/pack_service.py +7 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/doctor.py +29 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/install.py +9 -2
- agentpack_cli-0.1.16/src/agentpack/installers/claude.py +229 -0
- agentpack_cli-0.1.16/src/agentpack/mcp_server.py +415 -0
- agentpack_cli-0.1.15/src/agentpack/installers/claude.py +0 -172
- agentpack_cli-0.1.15/src/agentpack/mcp_server.py +0 -195
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/.gitignore +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/LICENSE +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/antigravity.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/base.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/claude.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/codex.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/cursor.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/detect.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/generic.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/adapters/windsurf.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/dependency_graph.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/go_imports.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/java_imports.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/js_ts_imports.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/python_imports.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/ranking.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/rust_imports.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/symbols.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/analysis/tests.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/application/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/cli.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/_shared.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/benchmark.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/claude_cmd.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/diff.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/explain.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/init.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/mcp_cmd.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/monitor.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/pack.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/scan.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/stats.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/status.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/summarize.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/commands/watch.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/bootstrap.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/cache.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/config.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/context_pack.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/diff.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/git.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/git_hooks.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/global_install.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/ignore.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/merkle.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/models.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/redactor.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/scanner.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/snapshot.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/token_estimator.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/core/vscode_tasks.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/data/agentpack.md +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/installers/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/installers/antigravity.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/installers/codex.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/installers/cursor.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/installers/windsurf.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/integrations/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/integrations/git_hooks.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/integrations/global_install.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/integrations/vscode_tasks.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/renderers/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/renderers/compact.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/renderers/markdown.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/renderers/receipts.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/session/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/session/state.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/summaries/__init__.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/summaries/base.py +0 -0
- {agentpack_cli-0.1.15 → agentpack_cli-0.1.16}/src/agentpack/summaries/offline.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: agentpack-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.16
|
|
4
4
|
Summary: Token-aware context packing for AI coding agents — Claude, Cursor, Windsurf, and Codex
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -44,7 +44,7 @@ Description-Content-Type: text/markdown
|
|
|
44
44
|
[](https://opensource.org/licenses/MIT)
|
|
45
45
|
[](https://github.com/vishal2612200/agentpack/actions/workflows/ci.yml)
|
|
46
46
|
|
|
47
|
-
> **Status: alpha (v0.1.
|
|
47
|
+
> **Status: alpha (v0.1.17).** Works, tested, used in real sessions. Python and JavaScript/TypeScript are the best-supported languages. Not yet validated across a wide range of repos. API may change before 1.0.
|
|
48
48
|
>
|
|
49
49
|
> **Platform note:** macOS and Linux are fully supported. Windows support is not yet implemented (git hooks use POSIX shell; the Claude Code session hooks use `python3`/`rm -f`). Contributions welcome.
|
|
50
50
|
|
|
@@ -297,7 +297,7 @@ Configures:
|
|
|
297
297
|
- `CLAUDE.md` — tells Claude to read the context pack before each task
|
|
298
298
|
- `.claude/settings.json` — two hooks:
|
|
299
299
|
- `SessionStart`: clears injection sentinel so first prompt gets context
|
|
300
|
-
- `UserPromptSubmit`:
|
|
300
|
+
- `UserPromptSubmit`: detects repo changes via content hash (not file mtime), triggers background repack using your prompt as the task description so keyword scoring matches the current conversation
|
|
301
301
|
|
|
302
302
|
After this, context is injected automatically into every Claude Code session. No `/agentpack` command needed — it just happens.
|
|
303
303
|
|
|
@@ -354,7 +354,7 @@ The Skill descriptor activates AgentPack automatically — no `--task` flag requ
|
|
|
354
354
|
|---|---|---|---|---|---|
|
|
355
355
|
| Config file patched | `CLAUDE.md` + `.claude/settings.json` | `.cursorrules` + `.cursor/rules/*.mdc` | `.windsurfrules` | `AGENTS.md` | `.agent/skills/agentpack/SKILL.md` + `GEMINI.md` |
|
|
356
356
|
| Auto-inject on startup | ✅ `UserPromptSubmit` hook | ✅ `alwaysApply` | ✅ rules file | ✅ `AGENTS.md` | ✅ Skill auto-activation |
|
|
357
|
-
| Auto-repack when stale | ✅ hook (
|
|
357
|
+
| Auto-repack when stale | ✅ hook (content hash via `root_hash`, ~1ms when fresh) | ✅ git hooks | ✅ git hooks | ✅ git hooks | ✅ git hooks |
|
|
358
358
|
| Manual repack shortcut | ✅ `/agentpack` slash cmd | ✅ VS Code task | ✅ VS Code task | `agentpack pack` | ✅ VS Code task |
|
|
359
359
|
|
|
360
360
|
---
|
|
@@ -640,7 +640,7 @@ Options:
|
|
|
640
640
|
|
|
641
641
|
### `agentpack session` _(removed)_
|
|
642
642
|
|
|
643
|
-
Session management was removed in v0.1.
|
|
643
|
+
Session management was removed in v0.1.12. `agentpack init` bootstraps the session automatically. Use `agentpack watch` to keep context current. To change the task, edit `.agentpack/task.md`.
|
|
644
644
|
|
|
645
645
|
---
|
|
646
646
|
|
|
@@ -826,13 +826,13 @@ Tokens after ignore: 210,000
|
|
|
826
826
|
|
|
827
827
|
### `agentpack stats`
|
|
828
828
|
|
|
829
|
-
Show session state
|
|
829
|
+
Show session state, token statistics, and selection accuracy for the last pack.
|
|
830
830
|
|
|
831
831
|
```bash
|
|
832
832
|
agentpack stats
|
|
833
833
|
```
|
|
834
834
|
|
|
835
|
-
When a session is active, shows session panel (agent, mode, started, refresh count) above token stats. Also lists top included files by score.
|
|
835
|
+
When a session is active, shows session panel (agent, mode, started, refresh count) above token stats. Also lists top included files by score and avg recall/precision/F1 over the last 10 runs.
|
|
836
836
|
|
|
837
837
|
---
|
|
838
838
|
|
|
@@ -910,8 +910,10 @@ agentpack monitor --clear
|
|
|
910
910
|
| Direct dependency of changed file | +50 |
|
|
911
911
|
| Reverse dependency | +40 |
|
|
912
912
|
| Has related tests | +35 |
|
|
913
|
+
| Knowledge/architecture doc (DECISIONS.md, ADR-*.md, ARCHITECTURE.md, docs/adr/, docs/decisions/, docs/rfcs/) | +30 |
|
|
913
914
|
| Config file | +25 |
|
|
914
915
|
| Recently modified | +20 |
|
|
916
|
+
| High churn (top 10% by commit frequency) | +15 |
|
|
915
917
|
| Large unrelated file | −50 |
|
|
916
918
|
| Ignored/binary | −100 |
|
|
917
919
|
|
|
@@ -960,8 +962,10 @@ content_keyword_max = 60
|
|
|
960
962
|
direct_dep = 50
|
|
961
963
|
reverse_dep = 40
|
|
962
964
|
related_test = 35
|
|
965
|
+
knowledge_file = 30 # DECISIONS.md, ADR-*.md, ARCHITECTURE.md, docs/adr/ etc.
|
|
963
966
|
config_file = 25
|
|
964
967
|
recently_modified = 20
|
|
968
|
+
churn_high = 15 # top 10% by commit frequency
|
|
965
969
|
large_unrelated_penalty = -50
|
|
966
970
|
ignored_penalty = -100
|
|
967
971
|
```
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://github.com/vishal2612200/agentpack/actions/workflows/ci.yml)
|
|
7
7
|
|
|
8
|
-
> **Status: alpha (v0.1.
|
|
8
|
+
> **Status: alpha (v0.1.17).** Works, tested, used in real sessions. Python and JavaScript/TypeScript are the best-supported languages. Not yet validated across a wide range of repos. API may change before 1.0.
|
|
9
9
|
>
|
|
10
10
|
> **Platform note:** macOS and Linux are fully supported. Windows support is not yet implemented (git hooks use POSIX shell; the Claude Code session hooks use `python3`/`rm -f`). Contributions welcome.
|
|
11
11
|
|
|
@@ -258,7 +258,7 @@ Configures:
|
|
|
258
258
|
- `CLAUDE.md` — tells Claude to read the context pack before each task
|
|
259
259
|
- `.claude/settings.json` — two hooks:
|
|
260
260
|
- `SessionStart`: clears injection sentinel so first prompt gets context
|
|
261
|
-
- `UserPromptSubmit`:
|
|
261
|
+
- `UserPromptSubmit`: detects repo changes via content hash (not file mtime), triggers background repack using your prompt as the task description so keyword scoring matches the current conversation
|
|
262
262
|
|
|
263
263
|
After this, context is injected automatically into every Claude Code session. No `/agentpack` command needed — it just happens.
|
|
264
264
|
|
|
@@ -315,7 +315,7 @@ The Skill descriptor activates AgentPack automatically — no `--task` flag requ
|
|
|
315
315
|
|---|---|---|---|---|---|
|
|
316
316
|
| Config file patched | `CLAUDE.md` + `.claude/settings.json` | `.cursorrules` + `.cursor/rules/*.mdc` | `.windsurfrules` | `AGENTS.md` | `.agent/skills/agentpack/SKILL.md` + `GEMINI.md` |
|
|
317
317
|
| Auto-inject on startup | ✅ `UserPromptSubmit` hook | ✅ `alwaysApply` | ✅ rules file | ✅ `AGENTS.md` | ✅ Skill auto-activation |
|
|
318
|
-
| Auto-repack when stale | ✅ hook (
|
|
318
|
+
| Auto-repack when stale | ✅ hook (content hash via `root_hash`, ~1ms when fresh) | ✅ git hooks | ✅ git hooks | ✅ git hooks | ✅ git hooks |
|
|
319
319
|
| Manual repack shortcut | ✅ `/agentpack` slash cmd | ✅ VS Code task | ✅ VS Code task | `agentpack pack` | ✅ VS Code task |
|
|
320
320
|
|
|
321
321
|
---
|
|
@@ -601,7 +601,7 @@ Options:
|
|
|
601
601
|
|
|
602
602
|
### `agentpack session` _(removed)_
|
|
603
603
|
|
|
604
|
-
Session management was removed in v0.1.
|
|
604
|
+
Session management was removed in v0.1.12. `agentpack init` bootstraps the session automatically. Use `agentpack watch` to keep context current. To change the task, edit `.agentpack/task.md`.
|
|
605
605
|
|
|
606
606
|
---
|
|
607
607
|
|
|
@@ -787,13 +787,13 @@ Tokens after ignore: 210,000
|
|
|
787
787
|
|
|
788
788
|
### `agentpack stats`
|
|
789
789
|
|
|
790
|
-
Show session state
|
|
790
|
+
Show session state, token statistics, and selection accuracy for the last pack.
|
|
791
791
|
|
|
792
792
|
```bash
|
|
793
793
|
agentpack stats
|
|
794
794
|
```
|
|
795
795
|
|
|
796
|
-
When a session is active, shows session panel (agent, mode, started, refresh count) above token stats. Also lists top included files by score.
|
|
796
|
+
When a session is active, shows session panel (agent, mode, started, refresh count) above token stats. Also lists top included files by score and avg recall/precision/F1 over the last 10 runs.
|
|
797
797
|
|
|
798
798
|
---
|
|
799
799
|
|
|
@@ -871,8 +871,10 @@ agentpack monitor --clear
|
|
|
871
871
|
| Direct dependency of changed file | +50 |
|
|
872
872
|
| Reverse dependency | +40 |
|
|
873
873
|
| Has related tests | +35 |
|
|
874
|
+
| Knowledge/architecture doc (DECISIONS.md, ADR-*.md, ARCHITECTURE.md, docs/adr/, docs/decisions/, docs/rfcs/) | +30 |
|
|
874
875
|
| Config file | +25 |
|
|
875
876
|
| Recently modified | +20 |
|
|
877
|
+
| High churn (top 10% by commit frequency) | +15 |
|
|
876
878
|
| Large unrelated file | −50 |
|
|
877
879
|
| Ignored/binary | −100 |
|
|
878
880
|
|
|
@@ -921,8 +923,10 @@ content_keyword_max = 60
|
|
|
921
923
|
direct_dep = 50
|
|
922
924
|
reverse_dep = 40
|
|
923
925
|
related_test = 35
|
|
926
|
+
knowledge_file = 30 # DECISIONS.md, ADR-*.md, ARCHITECTURE.md, docs/adr/ etc.
|
|
924
927
|
config_file = 25
|
|
925
928
|
recently_modified = 20
|
|
929
|
+
churn_high = 15 # top 10% by commit frequency
|
|
926
930
|
large_unrelated_penalty = -50
|
|
927
931
|
ignored_penalty = -100
|
|
928
932
|
```
|
|
@@ -303,6 +303,7 @@ class PackService:
|
|
|
303
303
|
budget=plan.budget,
|
|
304
304
|
token_estimate=packed_tokens,
|
|
305
305
|
)
|
|
306
|
+
excluded_receipts = [r for r in plan.receipts if r.action == "excluded"]
|
|
306
307
|
_record_metrics(
|
|
307
308
|
root,
|
|
308
309
|
task=request.task,
|
|
@@ -315,6 +316,8 @@ class PackService:
|
|
|
315
316
|
changed_count=len(plan.all_changed),
|
|
316
317
|
selected_paths=[sf.path for sf in plan.selected],
|
|
317
318
|
current_changed=plan.all_changed,
|
|
319
|
+
excluded_count=len(excluded_receipts),
|
|
320
|
+
excluded_paths=[r.path for r in excluded_receipts if r.reason == "score too low"][:10],
|
|
318
321
|
)
|
|
319
322
|
|
|
320
323
|
return PackResult(
|
|
@@ -404,6 +407,8 @@ def _record_metrics(
|
|
|
404
407
|
changed_count: int,
|
|
405
408
|
selected_paths: list[str],
|
|
406
409
|
current_changed: set[str],
|
|
410
|
+
excluded_count: int = 0,
|
|
411
|
+
excluded_paths: list[str] | None = None,
|
|
407
412
|
) -> None:
|
|
408
413
|
metrics_path = root / ".agentpack" / "metrics.jsonl"
|
|
409
414
|
accuracy = _compute_selection_accuracy(root, metrics_path, selected_paths, current_changed)
|
|
@@ -416,6 +421,8 @@ def _record_metrics(
|
|
|
416
421
|
"saving_pct": round(saving_pct, 1),
|
|
417
422
|
"selected_files": selected_count,
|
|
418
423
|
"changed_files": changed_count,
|
|
424
|
+
"excluded_files": excluded_count,
|
|
425
|
+
"excluded_paths": excluded_paths or [],
|
|
419
426
|
"selected_paths": selected_paths,
|
|
420
427
|
"phases": {k: round(v, 3) for k, v in phase_times.items()},
|
|
421
428
|
"total_s": round(sum(phase_times.values()), 3),
|
|
@@ -149,6 +149,35 @@ def register(app: typer.Typer) -> None:
|
|
|
149
149
|
if _local_has_hooks and not _global_has_hooks:
|
|
150
150
|
console.print(" [yellow]![/] Hooks local-only — context won't auto-inject in other repos. Run: agentpack install --agent claude --global")
|
|
151
151
|
|
|
152
|
+
# --- MCP server ---
|
|
153
|
+
console.print("\n[bold]MCP server[/]")
|
|
154
|
+
mcp_json = root / ".mcp.json"
|
|
155
|
+
global_claude_settings_for_mcp = Path.home() / ".claude" / "settings.json"
|
|
156
|
+
_local_has_mcp = False
|
|
157
|
+
_global_has_mcp = False
|
|
158
|
+
if mcp_json.exists():
|
|
159
|
+
try:
|
|
160
|
+
mcp_data = _json.loads(mcp_json.read_text())
|
|
161
|
+
if "agentpack" in mcp_data.get("mcpServers", {}):
|
|
162
|
+
console.print(f" [green]✓[/] MCP server registered (local): {mcp_json}")
|
|
163
|
+
_local_has_mcp = True
|
|
164
|
+
else:
|
|
165
|
+
console.print(" [yellow]![/] .mcp.json exists but agentpack missing — run: agentpack install --agent claude")
|
|
166
|
+
except Exception:
|
|
167
|
+
console.print(f" [yellow]![/] Could not parse {mcp_json}")
|
|
168
|
+
else:
|
|
169
|
+
console.print(" [dim]-[/] .mcp.json not present (run: agentpack install --agent claude)")
|
|
170
|
+
if global_claude_settings_for_mcp.exists():
|
|
171
|
+
try:
|
|
172
|
+
global_data = _json.loads(global_claude_settings_for_mcp.read_text())
|
|
173
|
+
if "agentpack" in global_data.get("mcpServers", {}):
|
|
174
|
+
console.print(f" [green]✓[/] MCP server registered (global): {global_claude_settings_for_mcp}")
|
|
175
|
+
_global_has_mcp = True
|
|
176
|
+
except Exception:
|
|
177
|
+
pass
|
|
178
|
+
if not _local_has_mcp and not _global_has_mcp:
|
|
179
|
+
console.print(" [yellow]![/] MCP server not registered — mcp__agentpack__* tools unavailable")
|
|
180
|
+
|
|
152
181
|
# --- Slash command ---
|
|
153
182
|
console.print("\n[bold]Slash command (/agentpack)[/]")
|
|
154
183
|
local_cmd = root / ".claude" / "commands" / "agentpack.md"
|
|
@@ -51,6 +51,10 @@ def register(app: typer.Typer) -> None:
|
|
|
51
51
|
scope = "~/.claude/settings.json" if global_install else ".claude/settings.json"
|
|
52
52
|
console.print(f"[green]{scope} {hook_action}.[/]")
|
|
53
53
|
|
|
54
|
+
mcp_action = installer.patch_mcp_server(root, global_install)
|
|
55
|
+
mcp_scope = "~/.claude/settings.json" if global_install else ".mcp.json"
|
|
56
|
+
console.print(f"[green]{mcp_scope} mcpServers.agentpack {mcp_action}.[/]")
|
|
57
|
+
|
|
54
58
|
if slash_command:
|
|
55
59
|
_install_slash_command(root, global_install)
|
|
56
60
|
|
|
@@ -164,11 +168,14 @@ def register(app: typer.Typer) -> None:
|
|
|
164
168
|
# --- Agent-specific config ---
|
|
165
169
|
if agent == "claude":
|
|
166
170
|
if not dry_run:
|
|
167
|
-
|
|
171
|
+
inst = ClaudeInstaller()
|
|
172
|
+
hook_action = inst.patch_claude_settings(root, global_install=True)
|
|
168
173
|
console.print(f"\n[green]~/.claude/settings.json {hook_action}.[/]")
|
|
174
|
+
mcp_action = inst.patch_mcp_server(root, global_install=True)
|
|
175
|
+
console.print(f"[green]~/.claude/settings.json mcpServers.agentpack {mcp_action}.[/]")
|
|
169
176
|
_install_slash_command(root, global_install=True)
|
|
170
177
|
else:
|
|
171
|
-
console.print("\n[dim]Would patch: ~/.claude/settings.json (hooks)[/]")
|
|
178
|
+
console.print("\n[dim]Would patch: ~/.claude/settings.json (hooks + mcpServers for global)[/]")
|
|
172
179
|
console.print("[dim]Would install: ~/.claude/commands/agentpack.md (slash command)[/]")
|
|
173
180
|
|
|
174
181
|
elif agent == "cursor":
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
_AGENTPACK_BLOCK = """\
|
|
8
|
+
<!-- agentpack:start -->
|
|
9
|
+
## AgentPack
|
|
10
|
+
|
|
11
|
+
AgentPack MCP server is available. For coding tasks in this repository, call the MCP tool
|
|
12
|
+
before editing files to get task-relevant context without loading the entire codebase.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
mcp__agentpack__pack_context(task="<what you're working on>", budget=4000)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Other tools:
|
|
19
|
+
- `mcp__agentpack__explain_file(path)` — score breakdown + symbols for a file
|
|
20
|
+
- `mcp__agentpack__get_related_files(path)` — import-graph neighbours
|
|
21
|
+
- `mcp__agentpack__get_stats()` — token/saving stats for the latest pack
|
|
22
|
+
- `mcp__agentpack__get_context()` — read the pre-built pack (no repack)
|
|
23
|
+
- `mcp__agentpack__refresh()` — refresh using current task.md
|
|
24
|
+
|
|
25
|
+
If MCP is not available, fall back to the CLI:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
agentpack pack --agent claude --task "<task>"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then read `.agentpack/context.claude.md`.
|
|
32
|
+
<!-- agentpack:end -->"""
|
|
33
|
+
|
|
34
|
+
_BLOCK_RE = re.compile(
|
|
35
|
+
r"<!-- agentpack:start -->.*?<!-- agentpack:end -->",
|
|
36
|
+
re.DOTALL,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ClaudeInstaller:
|
|
41
|
+
"""Configures Claude-specific repo and global files."""
|
|
42
|
+
|
|
43
|
+
def patch_claude_md(self, root: Path) -> str:
|
|
44
|
+
"""Insert/update AgentPack block in CLAUDE.md. Returns action taken."""
|
|
45
|
+
claude_md = root / "CLAUDE.md"
|
|
46
|
+
|
|
47
|
+
if not claude_md.exists():
|
|
48
|
+
claude_md.write_text(f"{_AGENTPACK_BLOCK}\n")
|
|
49
|
+
return "created"
|
|
50
|
+
|
|
51
|
+
content = claude_md.read_text()
|
|
52
|
+
if _BLOCK_RE.search(content):
|
|
53
|
+
new_content = _BLOCK_RE.sub(_AGENTPACK_BLOCK, content)
|
|
54
|
+
if new_content != content:
|
|
55
|
+
claude_md.write_text(new_content)
|
|
56
|
+
return "updated"
|
|
57
|
+
return "unchanged"
|
|
58
|
+
|
|
59
|
+
claude_md.write_text(content.rstrip() + "\n\n" + _AGENTPACK_BLOCK + "\n")
|
|
60
|
+
return "appended"
|
|
61
|
+
|
|
62
|
+
def patch_claude_settings(self, root: Path, global_install: bool = False) -> str:
|
|
63
|
+
"""Merge agentpack hooks into .claude/settings.json. Returns action taken."""
|
|
64
|
+
if global_install:
|
|
65
|
+
settings_path = Path.home() / ".claude" / "settings.json"
|
|
66
|
+
else:
|
|
67
|
+
settings_path = root / ".claude" / "settings.json"
|
|
68
|
+
|
|
69
|
+
settings_path.parent.mkdir(parents=True, exist_ok=True)
|
|
70
|
+
|
|
71
|
+
existing: dict = {}
|
|
72
|
+
if settings_path.exists():
|
|
73
|
+
try:
|
|
74
|
+
existing = json.loads(settings_path.read_text())
|
|
75
|
+
except json.JSONDecodeError:
|
|
76
|
+
existing = {}
|
|
77
|
+
|
|
78
|
+
hooks = existing.setdefault("hooks", {})
|
|
79
|
+
|
|
80
|
+
# SessionStart: delete sentinel + kick off background repack so first prompt
|
|
81
|
+
# gets fresh context without blocking the session.
|
|
82
|
+
# Use session refresh if session exists (respects task.md), else fall back to pack.
|
|
83
|
+
sentinel_cmd = (
|
|
84
|
+
"rm -f .agentpack/.context_injected .agentpack/.mcp_reminded"
|
|
85
|
+
" && ([ -f .agentpack/session.json ]"
|
|
86
|
+
" && agentpack session refresh >/dev/null 2>&1"
|
|
87
|
+
" || agentpack pack --task auto --mode balanced >/dev/null 2>&1) &"
|
|
88
|
+
)
|
|
89
|
+
session_start = hooks.setdefault("SessionStart", [])
|
|
90
|
+
# Replace any stale agentpack session hooks (old cmd only deleted sentinel).
|
|
91
|
+
for entry in session_start:
|
|
92
|
+
entry["hooks"] = [
|
|
93
|
+
h for h in entry.get("hooks", [])
|
|
94
|
+
if not (".context_injected" in h.get("command", "") and "rm -f" in h.get("command", ""))
|
|
95
|
+
]
|
|
96
|
+
session_start[:] = [e for e in session_start if e.get("hooks")]
|
|
97
|
+
already_has_session_hook = any(
|
|
98
|
+
any(h.get("command", "") == sentinel_cmd for h in entry.get("hooks", []))
|
|
99
|
+
for entry in session_start
|
|
100
|
+
)
|
|
101
|
+
if not already_has_session_hook:
|
|
102
|
+
session_start.append({"hooks": [{"type": "command", "command": sentinel_cmd}]})
|
|
103
|
+
|
|
104
|
+
# UserPromptSubmit: tiny MCP reminder — no context injection, no file reads.
|
|
105
|
+
# MCP server handles actual context retrieval on demand (pull-based).
|
|
106
|
+
# Background repack keeps the index fresh for MCP queries, using the
|
|
107
|
+
# user's prompt as the task so keyword scoring matches current work.
|
|
108
|
+
# root_hash (not md5 of whole file) avoids false "changed" on created_at churn.
|
|
109
|
+
mcp_reminder_cmd = (
|
|
110
|
+
"python3 -c \"\n"
|
|
111
|
+
"import json, pathlib, subprocess, sys\n"
|
|
112
|
+
"snap = pathlib.Path('.agentpack/snapshots/latest.json')\n"
|
|
113
|
+
"sentinel = pathlib.Path('.agentpack/.mcp_reminded')\n"
|
|
114
|
+
"try:\n"
|
|
115
|
+
" current_hash = json.loads(snap.read_text()).get('root_hash') if snap.exists() else None\n"
|
|
116
|
+
"except Exception:\n"
|
|
117
|
+
" current_hash = None\n"
|
|
118
|
+
"reminded_hash = sentinel.read_text().strip() if sentinel.exists() else None\n"
|
|
119
|
+
"try:\n"
|
|
120
|
+
" hook_data = json.loads(sys.stdin.read())\n"
|
|
121
|
+
" prompt = hook_data.get('prompt', '')\n"
|
|
122
|
+
"except Exception:\n"
|
|
123
|
+
" prompt = ''\n"
|
|
124
|
+
"task = (prompt[:200].strip() or 'auto') if prompt else 'auto'\n"
|
|
125
|
+
# Background repack when repo changed since last pack.
|
|
126
|
+
"if current_hash != reminded_hash:\n"
|
|
127
|
+
" subprocess.Popen(['agentpack', 'pack', '--task', task, '--mode', 'balanced'],\n"
|
|
128
|
+
" stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n"
|
|
129
|
+
" sentinel.write_text(current_hash or '1')\n"
|
|
130
|
+
" msg = 'AgentPack: repo changed — repacking index. Call agentpack_pack_context(task=\\\"...\\\") for fresh context.'\n"
|
|
131
|
+
"else:\n"
|
|
132
|
+
" msg = 'AgentPack MCP ready. Call agentpack_pack_context(task=\\\"...\\\") before editing files.'\n"
|
|
133
|
+
"print(json.dumps({'hookSpecificOutput': {'hookEventName': 'UserPromptSubmit',\n"
|
|
134
|
+
" 'additionalContext': msg}}))\n"
|
|
135
|
+
"\""
|
|
136
|
+
)
|
|
137
|
+
user_prompt = hooks.setdefault("UserPromptSubmit", [])
|
|
138
|
+
# Remove stale agentpack hooks (old injection hooks and old MCP reminder versions).
|
|
139
|
+
def _is_stale_agentpack_hook(cmd: str) -> bool:
|
|
140
|
+
return (
|
|
141
|
+
"context.claude.md" in cmd
|
|
142
|
+
or ".context_injected" in cmd
|
|
143
|
+
or (".mcp_reminded" in cmd and "hashlib" in cmd) # old md5-based reminder
|
|
144
|
+
)
|
|
145
|
+
for entry in user_prompt:
|
|
146
|
+
entry["hooks"] = [
|
|
147
|
+
h for h in entry.get("hooks", [])
|
|
148
|
+
if not _is_stale_agentpack_hook(h.get("command", ""))
|
|
149
|
+
]
|
|
150
|
+
user_prompt[:] = [e for e in user_prompt if e.get("hooks")]
|
|
151
|
+
already_has_prompt_hook = any(
|
|
152
|
+
any(h.get("command", "") == mcp_reminder_cmd for h in entry.get("hooks", []))
|
|
153
|
+
for entry in user_prompt
|
|
154
|
+
)
|
|
155
|
+
if not already_has_prompt_hook:
|
|
156
|
+
user_prompt.append({
|
|
157
|
+
"hooks": [{
|
|
158
|
+
"type": "command",
|
|
159
|
+
"command": mcp_reminder_cmd,
|
|
160
|
+
"timeout": 5,
|
|
161
|
+
"statusMessage": "Checking agentpack index...",
|
|
162
|
+
}]
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
new_content = json.dumps(existing, indent=2) + "\n"
|
|
166
|
+
if settings_path.exists() and settings_path.read_text() == new_content:
|
|
167
|
+
return "unchanged"
|
|
168
|
+
settings_path.write_text(new_content)
|
|
169
|
+
return "updated"
|
|
170
|
+
|
|
171
|
+
def patch_mcp_server(self, root: Path, global_install: bool = False) -> str:
|
|
172
|
+
"""Register agentpack MCP server. Returns action taken.
|
|
173
|
+
|
|
174
|
+
Local install writes to .mcp.json (Claude Code's standard per-project
|
|
175
|
+
MCP config). Global install writes to ~/.claude/settings.json.
|
|
176
|
+
"""
|
|
177
|
+
agentpack_entry = {"command": "agentpack", "args": ["mcp"]}
|
|
178
|
+
|
|
179
|
+
if global_install:
|
|
180
|
+
settings_path = Path.home() / ".claude" / "settings.json"
|
|
181
|
+
settings_path.parent.mkdir(parents=True, exist_ok=True)
|
|
182
|
+
|
|
183
|
+
existing: dict = {}
|
|
184
|
+
if settings_path.exists():
|
|
185
|
+
try:
|
|
186
|
+
existing = json.loads(settings_path.read_text())
|
|
187
|
+
except json.JSONDecodeError:
|
|
188
|
+
existing = {}
|
|
189
|
+
|
|
190
|
+
mcp_servers = existing.setdefault("mcpServers", {})
|
|
191
|
+
if mcp_servers.get("agentpack") == agentpack_entry:
|
|
192
|
+
return "unchanged"
|
|
193
|
+
mcp_servers["agentpack"] = agentpack_entry
|
|
194
|
+
settings_path.write_text(json.dumps(existing, indent=2) + "\n")
|
|
195
|
+
return "updated"
|
|
196
|
+
|
|
197
|
+
# Local install: use .mcp.json (read by Claude Code for project MCP servers)
|
|
198
|
+
mcp_json_path = root / ".mcp.json"
|
|
199
|
+
|
|
200
|
+
existing_mcp: dict = {}
|
|
201
|
+
if mcp_json_path.exists():
|
|
202
|
+
try:
|
|
203
|
+
existing_mcp = json.loads(mcp_json_path.read_text())
|
|
204
|
+
except json.JSONDecodeError:
|
|
205
|
+
existing_mcp = {}
|
|
206
|
+
|
|
207
|
+
mcp_servers = existing_mcp.setdefault("mcpServers", {})
|
|
208
|
+
if mcp_servers.get("agentpack") == agentpack_entry:
|
|
209
|
+
self._migrate_mcp_from_claude_settings(root)
|
|
210
|
+
return "unchanged"
|
|
211
|
+
|
|
212
|
+
mcp_servers["agentpack"] = agentpack_entry
|
|
213
|
+
mcp_json_path.write_text(json.dumps(existing_mcp, indent=2) + "\n")
|
|
214
|
+
self._migrate_mcp_from_claude_settings(root)
|
|
215
|
+
return "updated"
|
|
216
|
+
|
|
217
|
+
def _migrate_mcp_from_claude_settings(self, root: Path) -> None:
|
|
218
|
+
"""Remove stale mcpServers key from .claude/settings.json if present."""
|
|
219
|
+
settings_path = root / ".claude" / "settings.json"
|
|
220
|
+
if not settings_path.exists():
|
|
221
|
+
return
|
|
222
|
+
try:
|
|
223
|
+
existing = json.loads(settings_path.read_text())
|
|
224
|
+
except json.JSONDecodeError:
|
|
225
|
+
return
|
|
226
|
+
if "mcpServers" not in existing:
|
|
227
|
+
return
|
|
228
|
+
del existing["mcpServers"]
|
|
229
|
+
settings_path.write_text(json.dumps(existing, indent=2) + "\n")
|