@ictechgy/context-guard 0.4.1 → 0.4.3
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.
- package/CHANGELOG.md +9 -0
- package/README.ko.md +61 -32
- package/README.md +90 -22
- package/context-guard-kit/README.md +39 -26
- package/context-guard-kit/benchmark_runner.py +273 -8
- package/context-guard-kit/claude_transcript_cost_audit.py +325 -12
- package/context-guard-kit/context_compress.py +153 -1
- package/context-guard-kit/context_filter.py +446 -0
- package/context-guard-kit/context_guard_cli.py +3 -0
- package/context-guard-kit/context_guard_diet.py +677 -2
- package/context-guard-kit/context_pack.py +1694 -2
- package/context-guard-kit/cost_guard.py +1870 -0
- package/context-guard-kit/setup_wizard.py +820 -29
- package/context-guard-kit/trim_command_output.py +396 -45
- package/docs/benchmark-fixtures/learned-compression.tasks.example.json +24 -0
- package/docs/benchmark-fixtures/learned-compression.variants.example.json +10 -0
- package/docs/benchmark-fixtures/visual-ocr.tasks.example.json +24 -0
- package/docs/benchmark-fixtures/visual-ocr.variants.example.json +10 -0
- package/docs/benchmark-workflow-examples.md +40 -0
- package/docs/benchmark-workflows/context-pack-byte-proxy.example.json +169 -0
- package/docs/benchmark-workflows/measured-token-workflow.example.json +170 -0
- package/docs/benchmark-workflows/provider-cache-telemetry.example.json +170 -0
- package/docs/cache-diagnostics-schema.md +75 -0
- package/docs/cache-diagnostics.example.json +116 -0
- package/docs/cache-diagnostics.schema.json +460 -0
- package/docs/distribution.md +4 -2
- package/docs/experimental-benchmark-fixtures.md +36 -0
- package/package.json +11 -2
- package/packaging/homebrew/context-guard.rb.template +3 -2
- package/plugins/context-guard/.claude-plugin/plugin.json +1 -1
- package/plugins/context-guard/README.ko.md +21 -13
- package/plugins/context-guard/README.md +24 -10
- package/plugins/context-guard/bin/context-guard +3 -0
- package/plugins/context-guard/bin/context-guard-audit +325 -12
- package/plugins/context-guard/bin/context-guard-bench +273 -8
- package/plugins/context-guard/bin/context-guard-compress +153 -1
- package/plugins/context-guard/bin/context-guard-cost +1870 -0
- package/plugins/context-guard/bin/context-guard-diet +677 -2
- package/plugins/context-guard/bin/context-guard-filter +446 -0
- package/plugins/context-guard/bin/context-guard-pack +1694 -2
- package/plugins/context-guard/bin/context-guard-setup +820 -29
- package/plugins/context-guard/bin/context-guard-trim-output +396 -45
- package/plugins/context-guard/brief/README.md +10 -3
- package/plugins/context-guard/skills/optimize/SKILL.md +5 -2
- package/plugins/context-guard/skills/setup/SKILL.md +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes for the ContextGuard plugin are documented here.
|
|
4
4
|
|
|
5
|
+
## [0.4.3] - 2026-06-08
|
|
6
|
+
|
|
7
|
+
- Fixed the Homebrew formula template so packaged helper paths are handled as Pathname objects during install.
|
|
8
|
+
- Supersedes the unpublished `0.4.2` npm candidate after Brew install validation caught the formula issue.
|
|
9
|
+
|
|
10
|
+
## [0.4.2] - 2026-06-08
|
|
11
|
+
|
|
12
|
+
- Polished Korean README, plugin README, kit README, and GitHub Pages copy with Claude-assisted proofreading while preserving conservative token/cost claim boundaries.
|
|
13
|
+
|
|
5
14
|
## [0.4.1] - 2026-06-05
|
|
6
15
|
|
|
7
16
|
- Publish the cross-agent distribution release under a fresh npm version because `0.4.0` is unavailable on the registry while still returning a public 404.
|
package/README.ko.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ContextGuard
|
|
2
2
|
|
|
3
|
-
ContextGuard는 AI 코딩·도구 에이전트를 위한 로컬 우선 컨텍스트 관리 도구 모음입니다. Claude Code 플러그인으로
|
|
3
|
+
ContextGuard는 AI 코딩·도구 에이전트를 위한 로컬 우선 컨텍스트 관리 도구 모음입니다. Claude Code 플러그인으로 먼저 사용할 수 있으며, 설치 후 프로젝트별로 명시적으로 적용하고 필요하면 되돌릴 수 있습니다. 출력 축약, 심볼 단위 읽기, 반복 실패 알림, 민감정보 패턴 가림, 사용량 측정 가드레일은 로컬 헬퍼 명령과 brief 모드 안내 규칙 스니펫을 통해 다른 에이전트에도 확장됩니다.
|
|
4
4
|
|
|
5
5
|
- 영문 문서: [`README.md`](README.md)
|
|
6
6
|
- HTML 랜딩 페이지: [GitHub Pages](https://ictechgy.github.io/context-guard/) ([소스](docs/index.html))
|
|
@@ -14,18 +14,20 @@ ContextGuard는 AI 코딩·도구 에이전트를 위한 로컬 우선 컨텍스
|
|
|
14
14
|
| Claude Code | `/plugin marketplace add ictechgy/context-guard` 후 `/plugin install context-guard@context-guard` | 프로젝트에서 `/context-guard:setup` 실행 |
|
|
15
15
|
| Codex CLI 또는 터미널 기반 에이전트 | `npm install -g @ictechgy/context-guard` 또는 일회성 `npx @ictechgy/context-guard ...` | `context-guard setup --agent codex --scope project --with-init --with-skill --plan` 확인 후 `--yes`로 적용 |
|
|
16
16
|
| Gemini/Cursor/Windsurf/Cline/Copilot | npm/npx 설치 | 원하는 에이전트만 `context-guard setup --agent ... --scope project --with-init --plan`으로 확인 후 적용 |
|
|
17
|
-
| macOS/Homebrew 사용자 |
|
|
17
|
+
| macOS/Homebrew 사용자 | 배포 경로: `brew install ictechgy/tap/context-guard` | 설치 후 같은 `context-guard setup ...` 명령 사용 |
|
|
18
18
|
|
|
19
19
|
자주 쓰는 명령은 다음과 같습니다.
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
npm install -g @ictechgy/context-guard
|
|
23
23
|
npx @ictechgy/context-guard --version
|
|
24
|
+
context-guard doctor --root . --json # 읽기 전용 상태 점검; 변경 없음
|
|
24
25
|
context-guard setup --agent codex --scope project --with-init --with-skill --plan
|
|
26
|
+
context-guard setup --agent claude --scope user --verify --json # 읽기 전용 사용자 범위 점검
|
|
25
27
|
context-guard setup --agent claude --scope user --plan
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
기본값은 프로젝트 단위 설정입니다. 사용자 단위 설정은 명시적으로 선택해야 하며,
|
|
30
|
+
기본값은 프로젝트 단위 설정입니다. 사용자 단위 설정은 명시적으로 선택해야 하며, 실제로 변경을 적용하려면 `--yes`와 명시적인 `--agent`가 필요합니다. 지원되는 사용자 단위 변경은 백업과 되돌리기 기록을 남기며, 패키지 설치 중에는 실행되지 않습니다.
|
|
29
31
|
|
|
30
32
|
ContextGuard는 절감 수치를 과장하지 않습니다. 흔히 컨텍스트를 불필요하게 키우는 원인을 줄이고, 실제 전후 비교 결과는 각자의 작업에서 측정할 수 있도록 벤치마크 도구를 제공합니다. 저장소마다 효과는 달라질 수 있으며, 고정된 토큰·비용 절감률을 보장하지 않습니다.
|
|
31
33
|
|
|
@@ -35,7 +37,7 @@ ContextGuard는 Claude Code 플러그인으로 시작하는 것이 가장 빠릅
|
|
|
35
37
|
|
|
36
38
|
- **로컬 헬퍼 명령**(`context-guard-*`)은 특정 에이전트에 묶이지 않은 일반 셸 명령으로 실행됩니다.
|
|
37
39
|
- **brief 모드 스니펫**은 에이전트의 지시 파일(`AGENTS.md`, `GEMINI.md`, `.cursorrules`, Copilot 지시 파일 등)에 마커 블록으로 설치하고, 블록을 지우면 제거됩니다.
|
|
38
|
-
-
|
|
40
|
+
- **여러 에이전트 설정**은 먼저 dry-run으로 계획을 보여주고, 로컬 파일만 대상으로 하며, 변경 전 백업을 남긴 뒤 명시적으로 승인한 경우에만 적용합니다.
|
|
39
41
|
|
|
40
42
|
현재 지원하는 연동 방식은 다음과 같습니다.
|
|
41
43
|
|
|
@@ -61,7 +63,8 @@ ContextGuard는 모델 가격 자체를 낮추는 도구가 아닙니다. AI 코
|
|
|
61
63
|
| 같은 실패 명령을 반복하는 경우 | Bash 실패가 반복되면 불필요한 실패 로그가 더 쌓이기 전에 전략을 바꾸도록 알립니다. |
|
|
62
64
|
| 민감하거나 과도한 터미널 출력 | 자격 증명처럼 보이는 값과 민감해 보이는 경로를 패턴 기반으로 최대한 가립니다. |
|
|
63
65
|
| 어디서 토큰과 비용이 커지는지 모르는 경우 | 상태표시줄, 대화 기록 감사, 기준 실행과 변형 실행을 쌍으로 맞춰 비교한 벤치마크 리포트로 전후 비교 근거를 남깁니다. |
|
|
64
|
-
|
|
|
66
|
+
| Anthropic API 요청이 provider prompt cache hit를 놓칠 수 있는 경우 | `context-guard cost preflight`가 호출 전 입력 크기, cache breakpoint별 위험, 낮음/중간/높음 비용 범위를 추정합니다. 기본값은 경고만 합니다. |
|
|
67
|
+
| 안정적인 프롬프트 앞부분보다 자주 바뀌는 컨텍스트가 먼저 오는 경우 | 제한된 범위의 가림 처리된 segment hash로 프롬프트 배치를 감사하여, 원문 프롬프트를 노출하지 않고 캐시에 불리한 배치 가능성을 알립니다. |
|
|
65
68
|
| 좁은 작업에 비해 큰 tool/MCP catalog가 들어가는 경우 | 로컬 tool catalog를 제한된 top-k schema report로 순위화하고, 전체 가림 처리된 schema는 로컬 요약 기록으로 다시 조회할 수 있게 합니다. |
|
|
66
69
|
|
|
67
70
|
## 캐시·압축 도구와의 차이
|
|
@@ -70,10 +73,10 @@ ContextGuard는 provider 캐시, semantic cache, 프롬프트 압축 도구를
|
|
|
70
73
|
|
|
71
74
|
| 도구 유형 | 줄이는 방식 | ContextGuard와의 관계 |
|
|
72
75
|
| --- | --- | --- |
|
|
73
|
-
| Provider prompt/context caching | 안정적인 프롬프트 앞부분을 재사용합니다. | 보완 관계입니다. ContextGuard는 자주 바뀌는 컨텍스트 뒷부분을 더 작고 깨끗하게 유지하도록 돕고, `context-guard-audit`로
|
|
76
|
+
| Provider prompt/context caching | 안정적인 프롬프트 앞부분을 재사용합니다. | 보완 관계입니다. ContextGuard는 자주 바뀌는 컨텍스트 뒷부분을 더 작고 깨끗하게 유지하도록 돕고, `context-guard-audit`로 배치를 감지하며, `context-guard cost`로 Anthropic 요청이 cache read 대신 cache write가 될 가능성을 미리 알릴 수 있습니다. |
|
|
74
77
|
| Semantic response cache | 같거나 비슷한 요청의 이전 답변을 재사용합니다. | 보완 관계입니다. ContextGuard는 AI 답변 캐시를 제공하지 않습니다. |
|
|
75
78
|
| 프롬프트/컨텍스트 압축 | 이미 선택된 텍스트를 더 짧게 만듭니다. | 인접한 역할입니다. ContextGuard는 로컬 출력 축약과 요약을 제공하지만, 무손실 의미 압축을 보장하지 않습니다. |
|
|
76
|
-
| 실험적 learned/multimodal/self-hosted 기법 | 프롬프트를 압축하거나, 시각 자료를 줄이거나, self-hosted 추론 내부를 최적화합니다. |
|
|
79
|
+
| 실험적 learned/multimodal/self-hosted 기법 | 프롬프트를 압축하거나, 시각 자료를 줄이거나, self-hosted 추론 내부를 최적화합니다. | 품질 보존을 확인하는 matched benchmark가 통과하기 전까지는 experimental radar에만 기록하며, hosted API 절감 주장으로 보지 않습니다. |
|
|
77
80
|
| ContextGuard | 불필요한 파일, 로그, 반복 실패, 과도한 출력이 에이전트 컨텍스트에 들어가기 전에 줄어들도록 돕습니다. | 로컬 가드레일, 되돌릴 수 있는 로컬 보관본, 측정 도구입니다. |
|
|
78
81
|
|
|
79
82
|
설계에 참고한 관련 패턴은 다음과 같습니다.
|
|
@@ -86,9 +89,9 @@ ContextGuard는 provider 캐시, semantic cache, 프롬프트 압축 도구를
|
|
|
86
89
|
|
|
87
90
|
## brief 모드 (권고)
|
|
88
91
|
|
|
89
|
-
brief 모드는 코딩 에이전트가 군더더기를
|
|
92
|
+
brief 모드는 코딩 에이전트가 군더더기를 줄이도록 요청하되, 리뷰에 필요한 증거(파일 경로, 명령, 명령 출력과 오류, 코드 블록, 검증 상태, 변경 파일, 남은 과제, 주의사항)는 유지하게 돕는 에이전트 중립·안내용 규칙 스니펫 모음입니다. 강제가 아니라 최선 노력 안내이며, 토큰·비용 절감을 **보장하지 않습니다.**
|
|
90
93
|
|
|
91
|
-
사전 정의된 세 레벨이 [`plugins/context-guard/brief/`](plugins/context-guard/brief/)에 포함됩니다: `lite`, `standard`, `ultra`. 각 레벨은
|
|
94
|
+
사전 정의된 세 레벨이 [`plugins/context-guard/brief/`](plugins/context-guard/brief/)에 포함됩니다: `lite`, `standard`, `ultra`. 각 레벨은 에이전트 규칙·지시 파일(`AGENTS.md`, `CLAUDE.md`, Cursor 규칙 파일, Copilot 지시 등)에 들어가는 마커 구분 블록입니다. `context-guard setup --agent codex --scope project --brief-mode standard --plan`으로 미리 보고, 적용은 `--yes`로 다시 실행하며, 제거는 `--brief-mode off`를 사용하세요. 자세한 내용은 [`plugins/context-guard/brief/README.md`](plugins/context-guard/brief/README.md)를 참고하세요.
|
|
92
95
|
|
|
93
96
|
## 직접 측정하는 방법
|
|
94
97
|
|
|
@@ -98,9 +101,10 @@ brief 모드는 코딩 에이전트가 군더더기를 줄이되 리뷰에 필
|
|
|
98
101
|
- 원본 로그와 요약 출력 또는 로컬 보관 요약 기록의 차이
|
|
99
102
|
- `context-guard-audit`가 보고한 대화 기록 사용량 집중 지점과 `cache_friendliness` 프롬프트 배치 신호
|
|
100
103
|
- 상태표시줄의 `cache` / `reuse` 값: ContextGuard가 직접 만든 절감 효과가 아니라 관찰된 대화 기록·provider cache 신호입니다.
|
|
104
|
+
- `context-guard cost preflight`로 Anthropic 요청 JSON의 추정 비용을 보고, 호출 뒤 `context-guard cost observe`로 provider usage 필드(`cache_creation_input_tokens`, `cache_read_input_tokens`)를 대조합니다.
|
|
101
105
|
- `context-guard-bench`로 성공한 기준/변형 실행을 쌍으로 맞춰 비교한 결과
|
|
102
106
|
- 큰 tool/MCP catalog와 `context-guard-tool-prune` top-k 리포트 및 요약 기록 재조회 방식의 차이
|
|
103
|
-
- [`research/experimental-token-reduction-radar.md`](research/experimental-token-reduction-radar.md)의 선택적 실험 lane
|
|
107
|
+
- [`research/experimental-token-reduction-radar.md`](research/experimental-token-reduction-radar.md)의 선택적 실험 lane과 마찬가지로, [`docs/experimental-benchmark-fixtures.md`](docs/experimental-benchmark-fixtures.md)의 fixture-only 시작 예시도 절감 주장을 하려면 같은 matched-task benchmark gate를 먼저 통과해야 합니다.
|
|
104
108
|
|
|
105
109
|
## ContextGuard가 하지 않는 일
|
|
106
110
|
|
|
@@ -108,10 +112,11 @@ brief 모드는 코딩 에이전트가 군더더기를 줄이되 리뷰에 필
|
|
|
108
112
|
- 모델 토큰을 줄이기 위해 작업을 외부 AI 서비스로 전송하지 않습니다.
|
|
109
113
|
- 설치만으로 전역 Claude 설정을 변경하지 않습니다.
|
|
110
114
|
- 절감 수치가 필요할 때 직접 전후 비교 측정을 대신하지 않습니다.
|
|
111
|
-
-
|
|
115
|
+
- 로컬 RAM/디스크 보관본은 다음에 보낼 컨텍스트를 줄이는 데 도움될 수 있지만 Anthropic provider prompt cache를 대체하거나 cache hit를 보장하지 않습니다. 배포나 청구 설명 전에는 Anthropic prompt caching/pricing 문서를 다시 확인하세요: https://docs.anthropic.com/en/build-with-claude/prompt-caching 및 https://platform.claude.com/docs/en/about-claude/pricing.
|
|
116
|
+
- learned compression, multimodal OCR/crop pruning, self-hosted KV/latent inference optimization은 runtime 기능으로 제공하지 않습니다. 이 항목들은 research radar에만 기록된, 검증 게이트를 통과하지 않은 실험 항목입니다.
|
|
112
117
|
- 예전 `/claude-token-optimizer:*` Claude Code 슬래시 명령을 별칭으로 제공하지 않습니다. 설치 후에는 `/context-guard:*`를 사용하세요.
|
|
113
118
|
|
|
114
|
-
기존 자동화가 바로 깨지지 않도록 로컬 CLI 호환 래퍼(`claude-token-*`, `claude-read-symbol`, `claude-trim-output`, `claude-sanitize-output`)는 `bin
|
|
119
|
+
기존 자동화가 바로 깨지지 않도록 로컬 CLI 호환 래퍼(`claude-token-*`, `claude-read-symbol`, `claude-trim-output`, `claude-sanitize-output`)는 `bin/`에서 계속 제공합니다.
|
|
115
120
|
|
|
116
121
|
## 제공 기능
|
|
117
122
|
|
|
@@ -123,12 +128,17 @@ brief 모드는 코딩 에이전트가 군더더기를 줄이되 리뷰에 필
|
|
|
123
128
|
| 대용량 읽기 가드와 심볼 리더 | 파일 전체 읽기 대신 `rg`, 심볼 단위 읽기, 작은 줄 범위 읽기를 사용하도록 안내합니다. |
|
|
124
129
|
| 출력 축약과 민감정보 가림 | 테스트·빌드·검색·diff 출력을 작게 만들고, 에이전트 컨텍스트에 들어가기 전에 민감해 보이는 값을 가립니다. |
|
|
125
130
|
| 로컬 로그 보관소 | 큰 로그를 대화 밖 로컬 저장소에 보관하고, 요약 정보나 요청한 줄 범위만 다시 가져옵니다. |
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
131
|
+
| Anthropic 비용 가드 | `context-guard cost preflight/observe/ledger/compile`이 cache 위험과 비용 범위를 추정하고, 원문 대신 keyed HMAC fingerprint만 저장하며, `--enforce`를 명시하지 않으면 경고만 합니다. |
|
|
132
|
+
| 예산 기반 컨텍스트 패커 | 우선순위가 있는 로컬 파일 근거를 바이트 예산 안의 Markdown 팩으로 조립하고, 로컬 신호에서 `build`용 manifest를 추천하며, `--explain`으로 짧은 로컬 선택 이유를 덧붙일 수 있습니다. |
|
|
133
|
+
| Tool/MCP schema pruner | 로컬 catalog에서 bounded top-k tool/schema 자문 리포트를 만들고, compact 요약 기록과 전체 가림 처리된 payload 재조회 경로를 남깁니다. |
|
|
134
|
+
| 보수적 stdin 압축기 | 선택한 JSON, diff, 로그, 검색 출력, 코드, 산문을 줄이고, 관측 바이트 근거와 추정 토큰 proxy를 함께 표시합니다. |
|
|
129
135
|
| 반복 실패 알림 | Bash 실패가 반복되면 실패 로그가 컨텍스트를 채우기 전에 전략을 바꾸도록 안내합니다. |
|
|
130
136
|
| 상태표시줄, 감사, 벤치마크 | 컨텍스트·캐시·비용 신호를 보여주고, 사용량과 캐시 친화성 집중 지점을 찾고, 보수적인 전후 비교 증거를 남깁니다. |
|
|
131
137
|
|
|
138
|
+
### 비용 가드 키 준비
|
|
139
|
+
|
|
140
|
+
비용 가드의 로컬 HMAC 키는 기본적으로 `.context-guard/cost-ledger/hmac.key`에 자동 생성됩니다. 관리자가 직접 주입하는 경우 파일에는 필수 padding을 포함한 canonical URL-safe base64 32바이트 키만 정확히 들어 있어야 하며, trailing newline이나 공백은 허용하지 않습니다. 리포트는 키와 원문 프롬프트를 출력하지 않으며, 로컬 ledger는 Anthropic/provider prompt cache를 대체하지 않습니다.
|
|
141
|
+
|
|
132
142
|
## Claude Code에서 설치
|
|
133
143
|
|
|
134
144
|
마켓플레이스를 추가하고 플러그인을 설치합니다.
|
|
@@ -161,34 +171,45 @@ npm 패키지는 단일 `context-guard` 명령과 기존 `context-guard-*` 헬
|
|
|
161
171
|
```bash
|
|
162
172
|
npm install -g @ictechgy/context-guard
|
|
163
173
|
context-guard --version
|
|
174
|
+
context-guard doctor --root . --json
|
|
164
175
|
context-guard setup --agent codex --scope project --with-init --with-skill --plan
|
|
176
|
+
context-guard setup --agent codex --scope project --brief-mode standard --plan
|
|
165
177
|
```
|
|
166
178
|
|
|
167
179
|
전역 설치 없이 한 번만 실행하려면 다음처럼 사용할 수 있습니다.
|
|
168
180
|
|
|
169
181
|
```bash
|
|
170
182
|
npx @ictechgy/context-guard setup --agent codex --scope project --with-init --with-skill --plan
|
|
183
|
+
npx @ictechgy/context-guard setup --agent codex --scope project --brief-mode standard --plan
|
|
171
184
|
npm exec @ictechgy/context-guard -- --version
|
|
172
185
|
```
|
|
173
186
|
|
|
174
|
-
`--scope project`는 `AGENTS.md`, `.agents/skills/...`처럼 저장소 안 파일에 적용합니다. `--scope user`는
|
|
187
|
+
`--scope project`는 `AGENTS.md`, `.agents/skills/...`처럼 저장소 안 파일에 적용합니다. `--scope user`는 전체 사용자 환경에 적용하려는 경우에만 의도적으로 사용하세요. 실제 적용에는 `--yes`와 명시적인 `--agent`가 필요하며, 지원되는 쓰기는 되돌리기 기록을 남깁니다.
|
|
175
188
|
|
|
176
189
|
## Homebrew 배포 경로
|
|
177
190
|
|
|
178
|
-
Homebrew는
|
|
191
|
+
Homebrew는 공유 `ictechgy/tap` tap을 통해 macOS 배포 경로로 사용할 수 있습니다.
|
|
179
192
|
|
|
180
193
|
```bash
|
|
181
|
-
brew
|
|
182
|
-
brew install context-guard
|
|
194
|
+
brew install ictechgy/tap/context-guard
|
|
183
195
|
context-guard --version
|
|
184
196
|
```
|
|
185
197
|
|
|
186
|
-
tap
|
|
198
|
+
이미 `ictechgy/tap`을 tap했다면 `brew install context-guard`도 사용할 수 있습니다.
|
|
187
199
|
|
|
188
200
|
## 자주 쓰는 헬퍼 명령
|
|
189
201
|
|
|
190
202
|
대부분의 사용자는 `/context-guard:setup`부터 시작하면 됩니다. 아래 명령은 로컬 테스트, 자동화, 특정 문제 진단에 유용합니다. 기본 명령 접두사는 `context-guard-*`입니다.
|
|
191
203
|
|
|
204
|
+
### 설치 전 상태 점검
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
context-guard doctor --root . --json
|
|
208
|
+
context-guard setup --agent claude --scope user --verify --json
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
두 명령은 모두 설정을 변경하지 않는 읽기 전용 점검입니다. `doctor`는 권장 다음 명령을 보고하고, `setup --verify`는 설정을 적용하지 않은 채 완료 여부만 확인합니다. `--json` 모드는 결과를 stdout으로 출력합니다.
|
|
212
|
+
|
|
192
213
|
### 컨텍스트 관리 검사
|
|
193
214
|
|
|
194
215
|
```bash
|
|
@@ -217,15 +238,23 @@ long-command 2>&1 | ./plugins/context-guard/bin/context-guard-artifact store --c
|
|
|
217
238
|
### 예산 기반 컨텍스트 팩 만들기
|
|
218
239
|
|
|
219
240
|
```bash
|
|
220
|
-
./plugins/context-guard/bin/context-guard-pack
|
|
241
|
+
./plugins/context-guard/bin/context-guard-pack auto \
|
|
221
242
|
--root . \
|
|
222
|
-
--
|
|
223
|
-
--
|
|
224
|
-
--
|
|
243
|
+
--query "failing tests review" \
|
|
244
|
+
--diff HEAD \
|
|
245
|
+
--manifest-out suggested-pack.json \
|
|
246
|
+
--pack-out context-pack.md \
|
|
247
|
+
--budget-bytes 12000 --json --explain
|
|
248
|
+
# 또는 명시적인 두 단계로 실행:
|
|
249
|
+
./plugins/context-guard/bin/context-guard-pack suggest \
|
|
250
|
+
--root . --query "failing tests review" --diff HEAD \
|
|
251
|
+
--manifest-out suggested-pack.json --budget-bytes 12000 --json
|
|
252
|
+
./plugins/context-guard/bin/context-guard-pack build \
|
|
253
|
+
--root . --manifest suggested-pack.json --budget-bytes 12000 --json
|
|
225
254
|
./plugins/context-guard/bin/context-guard-pack slice --root . --path README.md --lines 1:40 --json
|
|
226
255
|
```
|
|
227
256
|
|
|
228
|
-
`context-guard-pack`은 우선순위가 있는 로컬 파일 근거를 렌더링된 UTF-8 바이트 기준 `--budget-bytes` 안의 Markdown 팩으로 조립합니다. JSON 출력은 포함·부분 포함·중복·unsafe·missing·예산 초과로 누락된 source를 기록하고, `.context-guard/packs`에 제한된 로컬 요약 기록을 쓰며, `path`와 `root`를 안전하게 표시할 수 있을 때만 정확한 가림 처리 slice 명령을 제공합니다. 안전하지 않으면 팩 본문과 JSON 메타데이터에 `retrieval_omitted_reason`을 남깁니다. 바이트 수는 관측값이고, 토큰 수는 provider가 실제 측정한 토큰 절감값이 아니라 추정 `chars_div_4` proxy입니다.
|
|
257
|
+
`context-guard-pack auto`는 같은 추천 단계를 실행한 뒤 예산 기반 Markdown 팩까지 바로 만드는 한-command 로컬 전용 경로입니다. `--explain`을 추가하면 JSON 또는 텍스트 출력에 결정적 로컬 선택/build 이유를 짧게 포함합니다. JSON explain에는 bounded `repo_map`도 들어가며 sampled byte/token-proxy tree, category-only secret risk count, signature-first hint, explain-only graph rank, 기존 `slice`/symbol 재조회 힌트를 제공합니다. 이 repo-map은 manifest, pack 본문, receipt, byte budget을 바꾸지 않고 네트워크·모델 호출·임베딩을 쓰지 않으며 provider token 또는 savings claim이 아닙니다. `--manifest-out`은 여전히 `build`가 읽을 수 있는 manifest만 저장하고, `--pack-out`은 렌더링된 팩 본문을 저장합니다. `context-guard-pack suggest`는 더 낮은 수준의 추가 로컬 전용 준비 단계입니다. `--query`, `--diff`, 반복 `--files`, 그리고 `--root` 아래의 선택적 `--output` / `--test-output` 텍스트 파일을 가림 처리한 신호에서 후보 파일과 줄 범위를 순위화한 뒤 `build --manifest`가 바로 읽을 수 있는 manifest를 씁니다. 표준 라이브러리 기반의 결정적 휴리스틱만 사용하며, 네트워크·모델 호출·임베딩·provider 비용 추정은 하지 않습니다. `context-guard-pack build`는 우선순위가 있는 로컬 파일 근거를 렌더링된 UTF-8 바이트 기준 `--budget-bytes` 안의 Markdown 팩으로 조립합니다. JSON 출력은 포함·부분 포함·중복·unsafe·missing·예산 초과로 누락된 source를 기록하고, `.context-guard/packs`에 제한된 로컬 요약 기록을 쓰며, `path`와 `root`를 안전하게 표시할 수 있을 때만 정확한 가림 처리 slice 명령을 제공합니다. 안전하지 않으면 팩 본문과 JSON 메타데이터에 `retrieval_omitted_reason`을 남깁니다. 바이트 수는 관측값이고, 토큰 수는 provider가 실제 측정한 토큰 절감값이 아니라 추정 `chars_div_4` proxy입니다.
|
|
229
258
|
|
|
230
259
|
### 작업에 맞게 tool/MCP catalog 줄이기
|
|
231
260
|
|
|
@@ -237,7 +266,7 @@ long-command 2>&1 | ./plugins/context-guard/bin/context-guard-artifact store --c
|
|
|
237
266
|
./plugins/context-guard/bin/context-guard-tool-prune get <receipt_id> --tool read_file --json
|
|
238
267
|
```
|
|
239
268
|
|
|
240
|
-
`context-guard-tool-prune`은 로컬 tool 또는 MCP catalog를 결정적 lexical heuristic(어휘 기반 휴리스틱)으로 순위화해 제한된 top-k 자문 리포트를 만듭니다. inline schema는 관측된 UTF-8 바이트 예산을 지키고, 누락되거나 예산 때문에 생략된 schema는 `.context-guard/tool-prune`의 compact 요약 기록과 별도 가림 처리 payload로 다시 조회할 수 있습니다. 이 기능은
|
|
269
|
+
`context-guard-tool-prune`은 로컬 tool 또는 MCP catalog를 결정적 lexical heuristic(어휘 기반 휴리스틱)으로 순위화해 제한된 top-k 자문 리포트를 만듭니다. inline schema는 관측된 UTF-8 바이트 예산을 지키고, 누락되거나 예산 때문에 생략된 schema는 `.context-guard/tool-prune`의 compact 요약 기록과 별도 가림 처리 payload로 다시 조회할 수 있습니다. 이 기능은 안내용이며 MCP 설정을 변경하지 않습니다. 토큰 값은 provider가 측정한 절감 수치가 아니라 추정 proxy입니다.
|
|
241
270
|
|
|
242
271
|
### 선택한 로컬 텍스트를 보수적으로 압축하기
|
|
243
272
|
|
|
@@ -271,7 +300,7 @@ head/tail 로그 대신 의미 요약이 필요하면 `--digest markdown` 또는
|
|
|
271
300
|
./plugins/context-guard/bin/context-guard-audit ~/.claude/projects --top 20 --recommend
|
|
272
301
|
```
|
|
273
302
|
|
|
274
|
-
감사 명령은 기본적으로 너무 큰 대화 기록 파일과 JSONL 기록을 건너뛰고(`--max-file-bytes`, `--max-line-bytes`), 건너뛴 개수를 함께 보고합니다. 손상된 추적 기록이 메모리를 독점하거나 스캔 공백을 숨기지 않도록 하기 위한 방어입니다. JSON 출력에는 `cache_friendliness
|
|
303
|
+
감사 명령은 기본적으로 너무 큰 대화 기록 파일과 JSONL 기록을 건너뛰고(`--max-file-bytes`, `--max-line-bytes`), 건너뛴 개수를 함께 보고합니다. 손상된 추적 기록이 메모리를 독점하거나 스캔 공백을 숨기지 않도록 하기 위한 방어입니다. JSON 출력에는 `cache_friendliness`와 [`cache_diagnostics`](docs/cache-diagnostics-schema.md)도 포함됩니다. 이는 제한된 사용량 필드, timestamped cache telemetry records, 가림 처리된 segment hash로 만든 휴리스틱 프롬프트 배치/cache-read 진단이며, 자주 바뀌는 내용이 프롬프트 앞부분에 있는지, 안정 prefix 후보가 있는지, cache miss 가설과 TTL/headroom 증거 공백이 무엇인지 알릴 수 있습니다. 원문 프롬프트는 출력하지 않고 provider cache hit를 증명하지 않으며, 대화 기록 스키마가 충분한 증거를 드러내지 않으면 `missing`, `partial`, `hypothesis`, `unavailable`일 수 있습니다.
|
|
275
304
|
|
|
276
305
|
### 상태표시줄에서 컨텍스트와 캐시 상태 확인
|
|
277
306
|
|
|
@@ -289,14 +318,13 @@ head/tail 로그 대신 의미 요약이 필요하면 `--digest markdown` 또는
|
|
|
289
318
|
--ledger-jsonl bench/cost-shift.jsonl --report-json bench/report.json
|
|
290
319
|
```
|
|
291
320
|
|
|
292
|
-
보고서는 성공한 기준/변형 실행을 실제 토큰과 `cost_usd + external_cost_usd` 기준으로 비교합니다. 바이트 감소는 간접 증거로만 기록하며, 그 자체를 절감 증명으로 보지 않습니다. 토큰 절감 주장은 대응 태스크 양쪽 모두에 `primary_tokens_measured`가 있을 때만 계산합니다. `wall_time_seconds`, `provider_cached_tokens`, `provider_cached_tokens_measured`는 진단용 텔레메트리이며, ContextGuard가 직접 만든 토큰·비용 절감 증거로 보지 않습니다. 비용 필드가 0이거나 없으면 토큰 절감만 표시하고 실제 비용 절감은 주장하지 않습니다. 절감 주장은 양쪽 모두 성공한 태스크 대응 기준이며, 실패율 가드레일이 악화되면 경고 수준으로 조정합니다. CSV 스키마는 엄격하게 검사합니다. 벤치마크 헬퍼를 업그레이드한 뒤에는 새 `--csv` 파일을 시작하거나 mismatch 오류가 알려주는 헤더로 마이그레이션하세요. 최소 보고서 형태 예시는 [`docs/benchmark-report.example.json`](docs/benchmark-report.example.json)을 참고하세요.
|
|
321
|
+
보고서는 성공한 기준/변형 실행을 실제 토큰과 `cost_usd + external_cost_usd` 기준으로 비교합니다. 바이트 감소는 간접 증거로만 기록하며, 그 자체를 절감 증명으로 보지 않습니다. 토큰 절감 주장은 대응 태스크 양쪽 모두에 `primary_tokens_measured`가 있을 때만 계산합니다. `matched_pair_evidence`는 성공한 기준/변형 task bucket을 transform, 측정 가능 여부, quality gate, claim boundary와 연결하므로 절감 문구를 쓰기 전에 이 항목을 먼저 확인해야 합니다. `wall_time_seconds`, `provider_cached_tokens`, `provider_cached_tokens_measured`는 진단용 텔레메트리이며, ContextGuard가 직접 만든 토큰·비용 절감 증거로 보지 않습니다. 비용 필드가 0이거나 없으면 토큰 절감만 표시하고 실제 비용 절감은 주장하지 않습니다. 절감 주장은 양쪽 모두 성공한 태스크 대응 기준이며, 실패율 가드레일이 악화되면 경고 수준으로 조정합니다. CSV 스키마는 엄격하게 검사합니다. 벤치마크 헬퍼를 업그레이드한 뒤에는 새 `--csv` 파일을 시작하거나 mismatch 오류가 알려주는 헤더로 마이그레이션하세요. 최소 보고서 형태 예시는 [`docs/benchmark-report.example.json`](docs/benchmark-report.example.json)을, 작업 유형별 합성 예시와 안전한 해석 경계는 [`docs/benchmark-workflow-examples.md`](docs/benchmark-workflow-examples.md)을, fixture-only 실험 시작 예시는 [`docs/experimental-benchmark-fixtures.md`](docs/experimental-benchmark-fixtures.md)을 참고하세요.
|
|
293
322
|
|
|
294
323
|
## 아직 제공하지 않는 기능
|
|
295
324
|
|
|
296
|
-
|
|
325
|
+
아래 항목은 프로젝트가 기록해 둔 방향일 뿐, 약속된 기능이 아닙니다. 저장소의 다른 문서에 명시되지 않는 한 아직 제공 기능이 아닙니다.
|
|
297
326
|
|
|
298
|
-
-
|
|
299
|
-
- learned prompt/context compression, multimodal crop/OCR 또는 visual-token pruning, self-hosted KV/latent inference optimization. [experimental token-reduction radar](research/experimental-token-reduction-radar.md)를 참고하세요. 이 lane들은 matched successful task, failure-rate guardrail, human-correction tracking, shifted-cost accounting, provider-measured token/cost evidence가 있어야 hosted API 절감 주장을 할 수 있습니다.
|
|
327
|
+
- learned prompt/context compression, multimodal crop/OCR 또는 visual-token pruning, self-hosted KV/latent inference optimization. 자세한 내용은 [experimental token-reduction radar](research/experimental-token-reduction-radar.md)와 [fixture-only experimental benchmark starters](docs/experimental-benchmark-fixtures.md)를 참고하세요. 이 lane들은 matched successful task, failure-rate guardrail, human-correction tracking, shifted-cost accounting, provider-measured token/cost evidence가 있어야 hosted API 절감 주장을 할 수 있습니다. Radar의 later-roadmap gate는 neural/semantic compression, trust-tiered injection-aware compression, context-diff compaction, local proxy constraint도 별도 미래 PR이 gate를 통과하기 전까지 experimental/non-shipped로 묶습니다.
|
|
300
328
|
|
|
301
329
|
## 저장소 구조
|
|
302
330
|
|
|
@@ -325,6 +353,7 @@ claude --plugin-dir ./plugins/context-guard
|
|
|
325
353
|
|
|
326
354
|
```bash
|
|
327
355
|
./plugins/context-guard/bin/context-guard-setup --plan
|
|
356
|
+
./plugins/context-guard/bin/context-guard-setup --agent codex --brief-mode standard --plan
|
|
328
357
|
./plugins/context-guard/bin/context-guard-setup --yes
|
|
329
358
|
```
|
|
330
359
|
|
|
@@ -344,7 +373,7 @@ python3 scripts/prepublish_check.py
|
|
|
344
373
|
python3 scripts/release_smoke.py
|
|
345
374
|
```
|
|
346
375
|
|
|
347
|
-
`prepublish_check.py`는 패키지 불변식, 동기화된 플러그인 바이너리, 매니페스트, 진단 메시지 가림 처리, 회귀 테스트를 확인합니다. `release_smoke.py`는 임시 프로젝트에서 `plugins/context-guard/bin`의 대표 패키징 엔트리포인트를
|
|
376
|
+
`prepublish_check.py`는 패키지 불변식, 동기화된 플러그인 바이너리, 매니페스트, 진단 메시지 가림 처리, 회귀 테스트를 확인합니다. `release_smoke.py`는 임시 프로젝트에서 `plugins/context-guard/bin`의 대표 패키징 엔트리포인트를 실제로 실행해, 배포 전 깨진 CLI 연결을 잡습니다. 전체 릴리스 절차, 증거 체크리스트, quad-review 요구사항, 롤백 체크리스트는 [docs/release-runbook.md](docs/release-runbook.md)를 참고하세요.
|
|
348
377
|
|
|
349
378
|
버전별 릴리스 노트는 [CHANGELOG.md](CHANGELOG.md)에 기록하며, 사전 배포 게이트는 플러그인 매니페스트 버전과 일치하는 항목이 있는지 확인합니다.
|
|
350
379
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ContextGuard
|
|
2
2
|
|
|
3
|
-
ContextGuard is a local-first context
|
|
3
|
+
ContextGuard is a local-first context management toolkit for AI coding and tool agents. It ships as a Claude Code plugin first — install once, apply per project, reverse if needed. Guardrails cover trimmed output, symbol-level reads, repeated-failure nudges, secret-pattern redaction, and usage measurement, then extend to other agents through local helper commands and advisory brief-mode rule snippets.
|
|
4
4
|
|
|
5
5
|
- Korean documentation: [`README.ko.md`](README.ko.md)
|
|
6
6
|
- Static landing page: [GitHub Pages](https://ictechgy.github.io/context-guard/) ([source](docs/index.html))
|
|
@@ -14,18 +14,20 @@ Install and activation are separate. Installing ContextGuard only puts local hel
|
|
|
14
14
|
| Claude Code | `/plugin marketplace add ictechgy/context-guard` then `/plugin install context-guard@context-guard` | Run `/context-guard:setup` inside the project. |
|
|
15
15
|
| Codex CLI or any terminal-first agent | `npm install -g @ictechgy/context-guard` or one-shot `npx @ictechgy/context-guard ...` | `context-guard setup --agent codex --scope project --with-init --with-skill --plan`, then rerun with `--yes`. |
|
|
16
16
|
| Other rule-file agents | npm/npx install above | `context-guard setup --agent gemini,cursor,windsurf,cline,copilot --scope project --with-init --plan`, then apply only the agents you want. |
|
|
17
|
-
| macOS/Homebrew users |
|
|
17
|
+
| macOS/Homebrew users | release path: `brew install ictechgy/tap/context-guard` | Same `context-guard setup ...` commands after install. |
|
|
18
18
|
|
|
19
19
|
Common commands:
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
22
|
npm install -g @ictechgy/context-guard
|
|
23
23
|
npx @ictechgy/context-guard --version
|
|
24
|
+
context-guard doctor --root . --json # read-only health check; no changes made
|
|
24
25
|
context-guard setup --agent codex --scope project --with-init --with-skill --plan
|
|
26
|
+
context-guard setup --agent claude --scope user --verify --json # read-only user-scope check
|
|
25
27
|
context-guard setup --agent claude --scope user --plan
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
Project scope is the default. User-level setup is opt-in, requires an explicit agent for writes, records backups/rollback metadata, and never runs during package installation.
|
|
30
|
+
Project scope is the default. User-level setup is opt-in, requires an explicit agent for writes, records backups/rollback metadata, and never runs during package installation. Use `context-guard doctor` or `context-guard setup --verify` for a read-only health check before applying setup; doctor only reports next commands and makes no changes.
|
|
29
31
|
|
|
30
32
|
ContextGuard is intentionally conservative about savings claims. It reduces common sources of context bloat and provides benchmark tooling so you can measure real before/after results on your own tasks. It does **not** promise a fixed token or cost reduction for every repository.
|
|
31
33
|
|
|
@@ -61,6 +63,7 @@ ContextGuard does not make the model cheaper by itself. It reduces avoidable con
|
|
|
61
63
|
| Repeated failing commands | Warn after repeated Bash failures so the agent changes strategy before more stale logs enter context. |
|
|
62
64
|
| Secret-like or noisy terminal output | Apply best-effort, pattern-based redaction for common credential patterns and sensitive-looking paths before output is copied into context. |
|
|
63
65
|
| Unknown token/cost hotspots | Surface statusline signals, transcript audits, and matched benchmark reports for before/after evidence. |
|
|
66
|
+
| Anthropic API requests that may miss prompt cache | `context-guard cost preflight` estimates input size, breakpoint-level cache risk, and low/mid/high cost ranges before a call; default mode warns only. |
|
|
64
67
|
| Volatile context before stable prompt prefixes | Audit bounded redacted prompt-segment hashes and flag likely cache-unfriendly prompt layouts without exposing raw prompt text. |
|
|
65
68
|
| Large tool/MCP catalogs for one narrow task | Rank a local tool catalog into a bounded top-k schema report while keeping full sanitized schemas retrievable from local receipts. |
|
|
66
69
|
|
|
@@ -70,7 +73,7 @@ ContextGuard is complementary to provider and semantic caches, and adjacent to p
|
|
|
70
73
|
|
|
71
74
|
| Tool category | Saves by | ContextGuard relationship |
|
|
72
75
|
| --- | --- | --- |
|
|
73
|
-
| Provider prompt/context caching | Reusing stable prompt prefixes. | Complementary; ContextGuard helps keep the changing tail of context smaller and cleaner,
|
|
76
|
+
| Provider prompt/context caching | Reusing stable prompt prefixes. | Complementary; ContextGuard helps keep the changing tail of context smaller and cleaner, `context-guard-audit` can flag likely volatile prefix layouts, and `context-guard cost` can warn when an Anthropic request is likely to create/cache-write instead of read. |
|
|
74
77
|
| Semantic response cache | Reusing answers to identical or similar requests. | Complementary; ContextGuard does not serve cached AI answers. |
|
|
75
78
|
| Prompt/context compression | Shortening text that is already selected for the model. | Adjacent; ContextGuard trims and summarizes local output, but does not promise lossless semantic compression. |
|
|
76
79
|
| Experimental learned/multimodal/self-hosted techniques | Compressing prompts, reducing visual evidence, or optimizing self-hosted inference internals. | Tracked only in the experimental radar until matched benchmarks prove quality-preserving value; not a hosted API savings claim. |
|
|
@@ -88,7 +91,7 @@ Related patterns that informed the design:
|
|
|
88
91
|
|
|
89
92
|
Brief mode is a set of agent-neutral, advisory rule snippets that ask a coding agent to cut filler while preserving the evidence a reviewer needs: file paths, commands, command output and errors, code blocks, verification status, changed files, known gaps, and caveats. It is best-effort guidance, not enforcement, and does **not** guarantee any token or cost savings.
|
|
90
93
|
|
|
91
|
-
Three deterministic levels ship under [`plugins/context-guard/brief/`](plugins/context-guard/brief/): `lite`, `standard`, and `ultra`. Each level is a single marker-delimited block
|
|
94
|
+
Three deterministic levels ship under [`plugins/context-guard/brief/`](plugins/context-guard/brief/): `lite`, `standard`, and `ultra`. Each level is a single marker-delimited block for an agent's rule/instruction file (for example `AGENTS.md`, `CLAUDE.md`, a Cursor rules file, or Copilot instructions). Manage it through setup with `context-guard setup --agent codex --scope project --brief-mode standard --plan`, rerun with `--yes` to apply, and use `--brief-mode off` to remove the managed block. See [`plugins/context-guard/brief/README.md`](plugins/context-guard/brief/README.md).
|
|
92
95
|
|
|
93
96
|
## What to measure
|
|
94
97
|
|
|
@@ -98,9 +101,10 @@ When you need a savings claim, measure it on your own tasks:
|
|
|
98
101
|
- raw logs versus digest output or artifact receipts
|
|
99
102
|
- transcript hotspots reported by `context-guard-audit`, including `cache_friendliness` prompt-layout signals
|
|
100
103
|
- statusline `cache` / `reuse` as observed transcript/provider-cache signals, not savings caused by ContextGuard
|
|
104
|
+
- `context-guard cost preflight` estimates for Anthropic request JSON, followed by `context-guard cost observe` using provider usage fields (`cache_creation_input_tokens`, `cache_read_input_tokens`) after the call
|
|
101
105
|
- matched successful baseline/variant runs from `context-guard-bench`
|
|
102
106
|
- large tool/MCP catalogs versus `context-guard-tool-prune` top-k reports plus receipt retrieval
|
|
103
|
-
- optional experimental lanes in [`research/experimental-token-reduction-radar.md`](research/experimental-token-reduction-radar.md)
|
|
107
|
+
- optional experimental lanes in [`research/experimental-token-reduction-radar.md`](research/experimental-token-reduction-radar.md); fixture-only starters in [`docs/experimental-benchmark-fixtures.md`](docs/experimental-benchmark-fixtures.md) use the same matched-task benchmark gates before any savings claim
|
|
104
108
|
|
|
105
109
|
## What ContextGuard does not do
|
|
106
110
|
|
|
@@ -108,6 +112,7 @@ When you need a savings claim, measure it on your own tasks:
|
|
|
108
112
|
- It does not send work to external AI providers to save model tokens.
|
|
109
113
|
- It does not mutate global Claude settings during install.
|
|
110
114
|
- It does not replace real before/after measurement when you need a savings claim.
|
|
115
|
+
- Local RAM/disk receipts can reduce what you send next, but they do **not** replace Anthropic's provider prompt cache or guarantee cache hits. Recheck Anthropic prompt-caching and pricing docs before release or billing claims: https://docs.anthropic.com/en/build-with-claude/prompt-caching and https://platform.claude.com/docs/en/about-claude/pricing.
|
|
111
116
|
- It does not ship learned compression, multimodal OCR/crop pruning, or self-hosted KV/latent inference optimization as runtime features; those remain gated experiments in the research radar.
|
|
112
117
|
- It does not alias the old `/claude-token-optimizer:*` Claude Code slash-command namespace. Use `/context-guard:*` after installing this plugin.
|
|
113
118
|
|
|
@@ -120,15 +125,23 @@ Legacy local CLI wrappers (`claude-token-*`, `claude-read-symbol`, `claude-trim-
|
|
|
120
125
|
| Claude Code plugin skills | Guided setup, optimization, and transcript usage audits. |
|
|
121
126
|
| Project-local setup wizard | Applies recommended `.claude/settings.json` options without touching global settings. |
|
|
122
127
|
| Context hygiene scanner | Finds missing guardrails, noisy hooks, broad reads, large context files, secret-like files, excessive MCP servers, and expensive defaults. |
|
|
128
|
+
| Structural-waste doctor | Opt-in local diagnostics for duplicate rules, stale imports, unused skill candidates, oversized tool schemas, and repeated read/tool-call loops. |
|
|
123
129
|
| Large-read guard and symbol reader | Nudges the agent toward `rg`, symbol reads, and small line ranges instead of full-file reads. |
|
|
124
130
|
| Output trimming and sanitizing | Keeps test, build, search, and diff output compact while redacting likely secrets before they enter agent context. |
|
|
131
|
+
| Declarative output filter | Opt-in JSON DSL for user-owned command filters with protected failure passthrough and validation before use. |
|
|
125
132
|
| Local artifact store | Saves large sanitized logs outside the conversation and returns compact receipts or exact requested slices. |
|
|
126
|
-
|
|
|
133
|
+
| Anthropic cost guard | `context-guard cost preflight/observe/ledger/compile` estimates cache-risk and cost ranges, stores only keyed HMAC fingerprints, and stays passive unless `--enforce` is explicit. |
|
|
134
|
+
| Budgeted context packer | Assembles prioritized local file evidence into a byte-budgeted Markdown pack, can suggest a build-compatible manifest from local signals, and adds `--explain` for compact local selection reasons plus bounded repo-map metadata. |
|
|
127
135
|
| Tool/MCP schema pruner | Emits bounded top-k tool/schema advisory reports from local catalogs with compact receipts and full sanitized payload retrieval. |
|
|
128
136
|
| Conservative stdin compressor | Shrinks selected JSON, diffs, logs, search output, code, and prose with observed byte evidence and estimated token proxies. |
|
|
137
|
+
| Protected-zone policy receipts | Opt-in `context-guard-compress --protected-policy` and `context-guard cost compile` metadata mark code/diff/path/hash/JSON/literal zones as structural-only with exact retrieval guidance. |
|
|
129
138
|
| Repeated-failure nudge | Warns after repeated Bash failures so the agent changes strategy before stale logs fill the context. |
|
|
130
139
|
| Statusline, audit, and benchmarks | Shows context/cache/cost signals, finds usage and cache-friendliness hotspots, and records conservative before/after evidence. |
|
|
131
140
|
|
|
141
|
+
### Cost guard key provisioning
|
|
142
|
+
|
|
143
|
+
Cost guard creates its local HMAC key automatically at `.context-guard/cost-ledger/hmac.key`. If you provision that file yourself, it must contain exactly one canonical URL-safe base64 32-byte key with required padding and no trailing newline or whitespace. Reports never emit the key or raw prompt text, and the local ledger does not replace Anthropic/provider prompt caching.
|
|
144
|
+
|
|
132
145
|
## Install in Claude Code
|
|
133
146
|
|
|
134
147
|
Add the marketplace and install the plugin:
|
|
@@ -161,13 +174,16 @@ The npm package exposes a canonical `context-guard` command plus the backwards-c
|
|
|
161
174
|
```bash
|
|
162
175
|
npm install -g @ictechgy/context-guard
|
|
163
176
|
context-guard --version
|
|
177
|
+
context-guard doctor --root . --json
|
|
164
178
|
context-guard setup --agent codex --scope project --with-init --with-skill --plan
|
|
179
|
+
context-guard setup --agent codex --scope project --brief-mode standard --plan
|
|
165
180
|
```
|
|
166
181
|
|
|
167
182
|
For a one-off run without global installation:
|
|
168
183
|
|
|
169
184
|
```bash
|
|
170
185
|
npx @ictechgy/context-guard setup --agent codex --scope project --with-init --with-skill --plan
|
|
186
|
+
npx @ictechgy/context-guard setup --agent codex --scope project --brief-mode standard --plan
|
|
171
187
|
npm exec @ictechgy/context-guard -- --version
|
|
172
188
|
```
|
|
173
189
|
|
|
@@ -175,20 +191,28 @@ Use `--scope project` for repository files such as `AGENTS.md` and `.agents/skil
|
|
|
175
191
|
|
|
176
192
|
## Homebrew release path
|
|
177
193
|
|
|
178
|
-
Homebrew is
|
|
194
|
+
Homebrew is available through the shared `ictechgy/tap` tap:
|
|
179
195
|
|
|
180
196
|
```bash
|
|
181
|
-
brew
|
|
182
|
-
brew install context-guard
|
|
197
|
+
brew install ictechgy/tap/context-guard
|
|
183
198
|
context-guard --version
|
|
184
199
|
```
|
|
185
200
|
|
|
186
|
-
|
|
201
|
+
If you already tapped `ictechgy/tap`, `brew install context-guard` also works.
|
|
187
202
|
|
|
188
203
|
## Helper commands
|
|
189
204
|
|
|
190
205
|
Most users should start with `/context-guard:setup`. The helper commands below are useful for local testing, automation, or targeted debugging. The canonical command prefix is `context-guard-*`.
|
|
191
206
|
|
|
207
|
+
### Health check before setup
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
context-guard doctor --root . --json
|
|
211
|
+
context-guard setup --agent claude --scope user --verify --json
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Both modes are read-only configuration checks. `doctor` reports recommended next commands, and `setup --verify` checks whether setup is complete without applying changes. With `--json`, the report is written to stdout.
|
|
215
|
+
|
|
192
216
|
### Scan context hygiene
|
|
193
217
|
|
|
194
218
|
```bash
|
|
@@ -197,6 +221,17 @@ Most users should start with `/context-guard:setup`. The helper commands below a
|
|
|
197
221
|
|
|
198
222
|
The scanner reports missing guardrails, noisy hooks, broad context paths, large or secret-like instruction/rule files across common AI-agent surfaces, and local context-exclusion recommendations for bulky or sensitive paths. `--top` caps both the reported context-like files and context-exclusion recommendations. Recommendations are heuristic/advisory unless they are emitted as Claude `permissions.deny` entries.
|
|
199
223
|
|
|
224
|
+
### Diagnose structural context waste
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
./plugins/context-guard/bin/context-guard-diet structural-waste . \
|
|
228
|
+
--tool-catalog tools.json \
|
|
229
|
+
--log-path .claude \
|
|
230
|
+
--json
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The structural-waste doctor is opt-in and read-only. It reuses the diet scanner's local safety model, then adds advisory findings for duplicate rule units, stale Python imports, unused skill candidates, excessive MCP/tool schema catalogs, and repeated file reads or duplicate tool calls from local JSON/JSONL logs. It does not edit files, disable tools, call the network, or print raw prompt/tool-input text; default output uses relative paths, hashed labels, and redacted secret-shaped path components. Treat low-confidence import/skill findings as review prompts, not deletion instructions.
|
|
234
|
+
|
|
200
235
|
### Read symbols instead of whole large files
|
|
201
236
|
|
|
202
237
|
```bash
|
|
@@ -212,20 +247,28 @@ long-command 2>&1 | ./plugins/context-guard/bin/context-guard-artifact store --c
|
|
|
212
247
|
./plugins/context-guard/bin/context-guard-artifact get <artifact_id> --lines 1:80
|
|
213
248
|
```
|
|
214
249
|
|
|
215
|
-
Artifact mode is for capture and retrieval. It stores sanitized output under `.context-guard/artifacts` by default and can still read legacy `.claude-token-optimizer/artifacts` receipts from before the rebrand. JSON receipts include line-numbered top-error receipts, duplicate-line groups, and sanitized bounded `suggested_queries` so an agent can fetch the smallest useful exact slice instead of replaying the full log. When a
|
|
250
|
+
Artifact mode is for capture and retrieval. It stores sanitized output under `.context-guard/artifacts` by default and can still read legacy `.claude-token-optimizer/artifacts` receipts from before the rebrand. JSON receipts include line-numbered top-error receipts, duplicate-line groups, and sanitized bounded `suggested_queries` so an agent can fetch the smallest useful exact slice instead of replaying the full log. When `--max-lines` accompanies a `--lines START:END` selector, it caps lines returned within that range; it does not expand the selector. Preserve the producer command's exit code yourself when using shell pipelines in release checks, or use `context-guard-trim-output -- ...` when exit-code preservation is the primary requirement.
|
|
216
251
|
|
|
217
252
|
### Build a budgeted context pack
|
|
218
253
|
|
|
219
254
|
```bash
|
|
220
|
-
./plugins/context-guard/bin/context-guard-pack
|
|
255
|
+
./plugins/context-guard/bin/context-guard-pack auto \
|
|
221
256
|
--root . \
|
|
222
|
-
--
|
|
223
|
-
--
|
|
224
|
-
--
|
|
257
|
+
--query "review failing tests" \
|
|
258
|
+
--diff HEAD \
|
|
259
|
+
--manifest-out suggested-pack.json \
|
|
260
|
+
--pack-out context-pack.md \
|
|
261
|
+
--budget-bytes 12000 --json --explain
|
|
262
|
+
# Or run the two explicit steps:
|
|
263
|
+
./plugins/context-guard/bin/context-guard-pack suggest \
|
|
264
|
+
--root . --query "review failing tests" --diff HEAD \
|
|
265
|
+
--manifest-out suggested-pack.json --budget-bytes 12000 --json
|
|
266
|
+
./plugins/context-guard/bin/context-guard-pack build \
|
|
267
|
+
--root . --manifest suggested-pack.json --budget-bytes 12000 --json
|
|
225
268
|
./plugins/context-guard/bin/context-guard-pack slice --root . --path README.md --lines 1:40 --json
|
|
226
269
|
```
|
|
227
270
|
|
|
228
|
-
`context-guard-pack` assembles prioritized local file evidence into a Markdown body whose rendered UTF-8 bytes stay within `--budget-bytes`. JSON output records included, partial, duplicate, unsafe, missing, and budget-omitted sources, writes a bounded local receipt under `.context-guard/packs`, and includes copy-pasteable `slice` commands for exact sanitized retrieval when the path/root are safe to display. If retrieval is unsafe, the pack and JSON metadata include `retrieval_omitted_reason` instead of a command. Byte counts are observed; token counts remain estimated `chars_div_4` proxies, not measured provider-token savings.
|
|
271
|
+
`context-guard-pack auto` is the one-command local-only path that runs the same suggestion step and immediately builds the budgeted Markdown pack; add `--explain` when you want compact deterministic local selection/build reasons in JSON or text output. `--explain` also includes bounded `repo_map` metadata: sampled byte/token-proxy tree entries, category-only secret-risk counts, signature-first file hints, explain-only graph ranks, and exact `slice`/symbol retrieval hints. This metadata does not change the manifest, pack body, receipt, or byte budget, does not use network/model/embedding calls, and treats token values as local `chars_div_4` proxies rather than provider-token or savings claims. `--manifest-out` remains a build-compatible manifest, while `--pack-out` can save the rendered pack. `context-guard-pack suggest` is the lower-level additive local-only planning step. It ranks candidate files and line ranges from `--query`, `--diff`, repeated `--files`, and optional `--output` / `--test-output` text files under `--root` after sanitizing those output signals, then writes a manifest that `build --manifest` can consume. It uses deterministic standard-library heuristics only: no network, model calls, embeddings, or provider-cost estimate. `context-guard-pack build` assembles prioritized local file evidence into a Markdown body whose rendered UTF-8 bytes stay within `--budget-bytes`. JSON output records included, partial, duplicate, unsafe, missing, and budget-omitted sources, writes a bounded local receipt under `.context-guard/packs`, and includes copy-pasteable `slice` commands for exact sanitized retrieval when the path/root are safe to display. If retrieval is unsafe, the pack and JSON metadata include `retrieval_omitted_reason` instead of a command. Byte counts are observed; token counts remain estimated `chars_div_4` proxies, not measured provider-token savings.
|
|
229
272
|
|
|
230
273
|
### Prune a tool/MCP catalog for a task
|
|
231
274
|
|
|
@@ -244,17 +287,20 @@ Artifact mode is for capture and retrieval. It stores sanitized output under `.c
|
|
|
244
287
|
```bash
|
|
245
288
|
git diff | ./plugins/context-guard/bin/context-guard-compress --json
|
|
246
289
|
pytest -q 2>&1 | ./plugins/context-guard/bin/context-guard-compress --type log
|
|
290
|
+
cat evidence.txt | ./plugins/context-guard/bin/context-guard-compress --json --protected-policy
|
|
247
291
|
```
|
|
248
292
|
|
|
249
293
|
`context-guard-compress` classifies sanitized stdin as JSON, diff, log, search output, code, or prose, then applies deterministic reductions such as JSON compaction, diff context folding, duplicate log/search line collapse, and whitespace normalization. It never claims observed model-token savings; byte counts are observed, token counts are labeled as estimates, and lossy receipts point you back to `context-guard-artifact store` for exact retrieval.
|
|
250
294
|
|
|
295
|
+
Add `--protected-policy` when the input may contain semantic-sensitive zones such as code fences, diffs, identifiers, numeric constants, hashes, paths, stack frames, quoted strings, or JSON keys. The flag does not change default compressor behavior; it adds `protected_zone_policy` and `transform_policy` metadata that denies semantic/paraphrase rewrites, allows only structural transforms plus artifact retrieval, and stores only class/count policy metadata rather than raw protected spans.
|
|
296
|
+
|
|
251
297
|
### Trim or summarize command output
|
|
252
298
|
|
|
253
299
|
```bash
|
|
254
300
|
./plugins/context-guard/bin/context-guard-trim-output --max-lines 120 -- npm test
|
|
255
301
|
```
|
|
256
302
|
|
|
257
|
-
Use `--digest markdown` or `--digest json` for a compact semantic digest instead of head/tail logs. Digest mode keeps status, exit code, truncation counts, runner failure facts, a sanitized failure signature, duplicate-line groups, representative lines, redaction counts, and suggested next queries while preserving the wrapped command exit code. Wrapped commands time out after 600 seconds by default; tune this with `--timeout-seconds`.
|
|
303
|
+
Use `--digest markdown` or `--digest json` for a compact semantic digest instead of head/tail logs. Digest mode keeps status, exit code, truncation counts, runner failure facts, a sanitized failure signature, duplicate-line groups, representative lines, redaction counts, and suggested next queries while preserving the wrapped command exit code. Add `--artifact-receipt` with digest mode when you want the exact sanitized full output stored locally as a `context-guard-artifact` receipt; re-expand with the emitted `context-guard-artifact get ...` command before relying on omitted details. Wrapped commands time out after 600 seconds by default; tune this with `--timeout-seconds`.
|
|
258
304
|
|
|
259
305
|
### Sanitize search and diff output
|
|
260
306
|
|
|
@@ -265,13 +311,35 @@ Use `--digest markdown` or `--digest json` for a compact semantic digest instead
|
|
|
265
311
|
|
|
266
312
|
The sanitizer reduces the chance that token-like, key-like, password-like, or sensitive path values are copied into agent context.
|
|
267
313
|
|
|
314
|
+
### Apply an opt-in declarative output filter
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
cat > .context-guard/filter-dsl.json <<'JSON'
|
|
318
|
+
{
|
|
319
|
+
"schema_version": "contextguard.filter-dsl.v1",
|
|
320
|
+
"filters": [
|
|
321
|
+
{
|
|
322
|
+
"id": "git-status-short",
|
|
323
|
+
"match": {"argv_prefix": ["git", "status", "--short"]},
|
|
324
|
+
"include_regex": ["^[ MADRCU?!]"],
|
|
325
|
+
"max_lines": 80
|
|
326
|
+
}
|
|
327
|
+
]
|
|
328
|
+
}
|
|
329
|
+
JSON
|
|
330
|
+
./plugins/context-guard/bin/context-guard-filter validate --config .context-guard/filter-dsl.json
|
|
331
|
+
./plugins/context-guard/bin/context-guard-filter run --config .context-guard/filter-dsl.json -- git status --short
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
`context-guard-filter` is an opt-in local helper for user-owned JSON filter files; it does not install default filters or change hooks. Invalid configs, no-match commands, filtering errors, empty filtered output, and protected `git`/test/lint/`gh` command failures pass the original command stdout/stderr and exit code through. In filtered mode, line rules apply to combined stdout+stderr and write the filtered result to stdout; passthrough mode preserves stdout/stderr streams. `run --json-report` writes filter diagnostics to stderr so stdout remains command/filter output; protected nonzero passthrough suppresses that report to keep stderr raw. Treat filtered byte reductions as local presentation changes, not hosted token/cost savings claims.
|
|
335
|
+
|
|
268
336
|
### Audit local transcript usage
|
|
269
337
|
|
|
270
338
|
```bash
|
|
271
339
|
./plugins/context-guard/bin/context-guard-audit ~/.claude/projects --top 20 --recommend
|
|
272
340
|
```
|
|
273
341
|
|
|
274
|
-
The audit command skips oversized transcript files and JSONL records by default (`--max-file-bytes`, `--max-line-bytes`) and reports skipped counts, so a corrupt trace cannot dominate memory or hide scan gaps. JSON output also includes `cache_friendliness
|
|
342
|
+
The audit command skips oversized transcript files and JSONL records by default (`--max-file-bytes`, `--max-line-bytes`) and reports skipped counts, so a corrupt trace cannot dominate memory or hide scan gaps. JSON output also includes `cache_friendliness` and [`cache_diagnostics`](docs/cache-diagnostics-schema.md): heuristic prompt-layout/cache-read diagnostics built from bounded usage fields, timestamped cache telemetry records, and redacted segment hashes. They can flag likely volatile content near the prompt prefix, stable-prefix candidates, cache-miss hypotheses, and TTL/headroom evidence gaps, but they do not print raw prompt text, do not prove provider cache hits, and may be `missing`, `partial`, `hypothesis`, or `unavailable` when transcript schemas do not expose enough evidence.
|
|
275
343
|
|
|
276
344
|
### Watch context and cache health in the statusline
|
|
277
345
|
|
|
@@ -289,14 +357,13 @@ The audit command skips oversized transcript files and JSONL records by default
|
|
|
289
357
|
--ledger-jsonl bench/cost-shift.jsonl --report-json bench/report.json
|
|
290
358
|
```
|
|
291
359
|
|
|
292
|
-
The report compares successful baseline/variant runs by real tokens and `cost_usd + external_cost_usd`. Byte reductions are recorded as proxy evidence, not treated as proof of savings. Token-savings claims require `primary_tokens_measured` on both sides of a matched task. `wall_time_seconds`, `provider_cached_tokens`, and `provider_cached_tokens_measured` are diagnostic telemetry, not proof of ContextGuard-caused token or cost savings. If cost fields are zero or unavailable, the report can still mark token savings but will not claim shifted-cost savings. Claims are paired by matched successful tasks and downgraded when failure-rate guardrails regress. CSV schemas are strict; after upgrading the benchmark helper, start a new `--csv` file or migrate the header named in the mismatch error. See [`docs/benchmark-report.example.json`](docs/benchmark-report.example.json) for a minimal report-shape example.
|
|
360
|
+
The report compares successful baseline/variant runs by real tokens and `cost_usd + external_cost_usd`. Byte reductions are recorded as proxy evidence, not treated as proof of savings. Token-savings claims require `primary_tokens_measured` on both sides of a matched task. `matched_pair_evidence` links each successful baseline/variant task bucket to the transform, measurement availability, quality gate, and claim boundary; inspect it before making any savings statement. `wall_time_seconds`, `provider_cached_tokens`, and `provider_cached_tokens_measured` are diagnostic telemetry, not proof of ContextGuard-caused token or cost savings. If cost fields are zero or unavailable, the report can still mark token savings but will not claim shifted-cost savings. Claims are paired by matched successful tasks and downgraded when failure-rate guardrails regress. CSV schemas are strict; after upgrading the benchmark helper, start a new `--csv` file or migrate the header named in the mismatch error. See [`docs/benchmark-report.example.json`](docs/benchmark-report.example.json) for a minimal report-shape example, [`docs/benchmark-workflow-examples.md`](docs/benchmark-workflow-examples.md) for workflow-specific synthetic examples, and [`docs/experimental-benchmark-fixtures.md`](docs/experimental-benchmark-fixtures.md) for fixture-only experimental task/variant starters.
|
|
293
361
|
|
|
294
362
|
## What is not yet shipped
|
|
295
363
|
|
|
296
364
|
These are directions the project has noted, not committed features. Nothing here ships unless documented elsewhere in the repository.
|
|
297
365
|
|
|
298
|
-
-
|
|
299
|
-
- learned prompt/context compression, multimodal crop/OCR or visual-token pruning, and self-hosted KV/latent inference optimizations. See the [experimental token-reduction radar](research/experimental-token-reduction-radar.md); these lanes require matched successful tasks, failure-rate guardrails, human-correction tracking, shifted-cost accounting, and provider-measured token/cost evidence before any hosted API savings claim.
|
|
366
|
+
- learned prompt/context compression, multimodal crop/OCR or visual-token pruning, and self-hosted KV/latent inference optimizations. See the [experimental token-reduction radar](research/experimental-token-reduction-radar.md) and [fixture-only experimental benchmark starters](docs/experimental-benchmark-fixtures.md); these lanes require matched successful tasks, failure-rate guardrails, human-correction tracking, shifted-cost accounting, and provider-measured token/cost evidence before any hosted API savings claim. The radar's later-roadmap gates also keep neural/semantic compression, trust-tiered injection-aware compression, context-diff compaction, and local proxy constraints experimental/non-shipped until a separate future PR satisfies those gates.
|
|
300
367
|
|
|
301
368
|
## Repository layout
|
|
302
369
|
|
|
@@ -325,6 +392,7 @@ Plugin helper binaries are not added to `PATH` by default. For local testing, in
|
|
|
325
392
|
|
|
326
393
|
```bash
|
|
327
394
|
./plugins/context-guard/bin/context-guard-setup --plan
|
|
395
|
+
./plugins/context-guard/bin/context-guard-setup --agent codex --brief-mode standard --plan
|
|
328
396
|
./plugins/context-guard/bin/context-guard-setup --yes
|
|
329
397
|
```
|
|
330
398
|
|