vibe-code-explainer 0.2.1 → 0.3.1

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.
Files changed (31) hide show
  1. package/README.md +105 -44
  2. package/dist/{chunk-5NCRRHU7.js → chunk-RK7ZFN4W.js} +10 -2
  3. package/dist/chunk-RK7ZFN4W.js.map +1 -0
  4. package/dist/chunk-Y45OIJ6Q.js +429 -0
  5. package/dist/chunk-Y45OIJ6Q.js.map +1 -0
  6. package/dist/chunk-Y55I7ZS5.js +604 -0
  7. package/dist/chunk-Y55I7ZS5.js.map +1 -0
  8. package/dist/cli/index.js +6 -6
  9. package/dist/{config-5PDPXG7Z.js → config-AHHWBME7.js} +19 -2
  10. package/dist/config-AHHWBME7.js.map +1 -0
  11. package/dist/hooks/post-tool.js +62 -26
  12. package/dist/hooks/post-tool.js.map +1 -1
  13. package/dist/{init-KUVD2YGA.js → init-ZR6C4F7Q.js} +19 -3
  14. package/dist/init-ZR6C4F7Q.js.map +1 -0
  15. package/dist/ollama-LAUI7N5U.js +14 -0
  16. package/dist/{schema-TBXFNCIG.js → schema-YEJIXFMK.js} +4 -2
  17. package/dist/{tracker-HCWPUZIO.js → tracker-4ORSFJQB.js} +4 -2
  18. package/dist/{uninstall-CNGJWJYQ.js → uninstall-AIH4HVPZ.js} +2 -2
  19. package/package.json +1 -1
  20. package/dist/chunk-5NCRRHU7.js.map +0 -1
  21. package/dist/chunk-W67RX53R.js +0 -347
  22. package/dist/chunk-W67RX53R.js.map +0 -1
  23. package/dist/chunk-YS2XIZIA.js +0 -544
  24. package/dist/chunk-YS2XIZIA.js.map +0 -1
  25. package/dist/config-5PDPXG7Z.js.map +0 -1
  26. package/dist/init-KUVD2YGA.js.map +0 -1
  27. package/dist/ollama-34TOVCUY.js +0 -12
  28. /package/dist/{ollama-34TOVCUY.js.map → ollama-LAUI7N5U.js.map} +0 -0
  29. /package/dist/{schema-TBXFNCIG.js.map → schema-YEJIXFMK.js.map} +0 -0
  30. /package/dist/{tracker-HCWPUZIO.js.map → tracker-4ORSFJQB.js.map} +0 -0
  31. /package/dist/{uninstall-CNGJWJYQ.js.map → uninstall-AIH4HVPZ.js.map} +0 -0
package/README.md CHANGED
@@ -16,30 +16,57 @@ No more accepting code blindly.
16
16
  **Safe change (low/no risk):**
17
17
 
18
18
  ```
19
- ┌─ code-explainer ─────────────────────────────
20
- src/app/page.tsx
21
-
22
- Changed the page background from a solid dark color to a
23
- gradient that blends two shades of blue. Visual-only change,
24
- no logic or data affected.
25
-
26
- Risk: ✅ None
27
- └──────────────────────────────────────────────
19
+ ╭─ vibe-code-explainer ─────────────────────────╮
20
+
21
+ 📄 src/app/page.tsx │
22
+
23
+ Impact │
24
+ Changed page background from solid dark │
25
+ blue to a gradient. │
26
+
27
+ │ ▸ How it works │
28
+ │ `bg-gradient-to-br` + `from-`/`to-` Tailwind │
29
+ │ utilities generate a CSS linear-gradient. │
30
+ │ │
31
+ │ ▸ Why │
32
+ │ Tailwind: utility classes for gradients │
33
+ │ instead of writing custom CSS. │
34
+ │ │
35
+ │ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ │
36
+ │ │
37
+ │ ✓ Risk: None │
38
+ │ │
39
+ ╰─────────────────────────────────────────────────╯
28
40
  ```
29
41
 
30
42
  **Risky change (medium/high risk):**
31
43
 
32
44
  ```
33
- ┌─ code-explainer ⚠️ ──────────────────────────
34
- 🚨 .env
35
-
36
- Adds a Stripe payment secret key directly in the environment
37
- file. This key gives access to your payment system.
38
-
39
- Risk: 🚨 High
40
- A live payment API key is hardcoded in the file and should
41
- not be committed to version control.
42
- └──────────────────────────────────────────────
45
+ ╭─ vibe-code-explainer ─────────────────────────╮ ← red border
46
+
47
+ 📄 .env │
48
+
49
+ Impact │
50
+ Added a Stripe payment secret key directly │
51
+ in the environment file. │
52
+
53
+ How it works │
54
+ │ `.env` files store environment variables, │
55
+ │ read by your code at runtime. `sk_live_` │
56
+ │ is Stripe's prefix for production keys. │
57
+ │ │
58
+ │ ▸ Why │
59
+ │ Convention: secrets live in .env files that │
60
+ │ are kept out of git via .gitignore. │
61
+ │ │
62
+ │ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ ─ ┄ │
63
+ │ │
64
+ │ 🚨 Risk: High │
65
+ │ A live Stripe production key is hardcoded. │
66
+ │ Make sure .env is in .gitignore before │
67
+ │ committing. │
68
+ │ │
69
+ ╰─────────────────────────────────────────────────╯
43
70
  ```
44
71
 
45
72
  ---
@@ -112,9 +139,15 @@ exist, so you can set a global default and override per-project.
112
139
 
113
140
  #### 3. Detail level
114
141
 
115
- - **Standard** 1–2 sentence explanation per change (recommended)
116
- - **Minimal** — one short sentence per change
117
- - **Verbose** — detailed bullet-point breakdown of every change
142
+ This is also the **teacher mode** switch:
143
+
144
+ - **Minimal** — single sentence describing the impact. **No teaching.** Use
145
+ this if you just want to know what changed without any educational content.
146
+ - **Standard** — three sections per change: **Impact** (what changes for the
147
+ user), **How it works** (mechanical explanation of the syntax/concept),
148
+ **Why** (why this approach was used). Recommended.
149
+ - **Verbose** — same three sections, each more in-depth (2–4 sentences).
150
+ Plus a fourth **Deeper dive** section with related terms to look up.
118
151
 
119
152
  #### 4. Language
120
153
 
@@ -123,10 +156,25 @@ Pick the language the explanations are written in. Supported:
123
156
  English, Portuguese, Spanish, French, German, Italian, Chinese, Japanese,
124
157
  Korean.
125
158
 
126
- Only the `summary` and `riskReason` fields are translated. JSON keys and the
127
- risk labels (`none` / `low` / `medium` / `high`) stay in English.
159
+ Only the natural-language fields (impact, howItWorks, why, deepDive items,
160
+ riskReason) are translated. JSON keys and risk labels (`none` / `low` /
161
+ `medium` / `high`) stay in English so parsing stays stable.
162
+
163
+ #### 5. Programming knowledge level (only when teaching is on)
164
+
165
+ If you picked Standard or Verbose, the installer asks how much you already
166
+ know about programming. This calibrates the depth of the teaching:
128
167
 
129
- #### 5. Model (Ollama only)
168
+ - **Never programmed** explanations start from "what is a variable" when
169
+ needed. Uses everyday-life analogies.
170
+ - **Just starting out** — explains new technical terms, doesn't re-teach
171
+ basics like variables and functions.
172
+ - **Read code with difficulty** — assumes core concepts, focuses on idiomatic
173
+ patterns and what specific syntax accomplishes.
174
+ - **Code regularly** — concise. Mentions modern features, gotchas, and
175
+ alternatives rather than syntax basics.
176
+
177
+ #### 6. Model (Ollama only)
130
178
 
131
179
  - If you have an NVIDIA GPU, the installer auto-detects your VRAM and picks
132
180
  the right model.
@@ -249,14 +297,15 @@ offers to download it on the spot if not.
249
297
  code-explainer config (project)
250
298
 
251
299
  Current settings:
252
- Engine: Local LLM (Ollama)
253
- Model: qwen3.5:4b
254
- Ollama URL: http://localhost:11434
255
- Detail level: standard
256
- Language: English
257
- Hooks: Edit ✓ Write ✓ Bash
258
- Excluded: *.lock, dist/**, node_modules/**
259
- Skip if slow: 8s
300
+ Engine: Local LLM (Ollama)
301
+ Model: qwen3.5:4b
302
+ Ollama URL: http://localhost:11434
303
+ Detail level: standard
304
+ Language: English
305
+ Learner level: Read code with difficulty
306
+ Hooks: Edit ✓ Write ✓ Bash ✓
307
+ Excluded: *.lock, dist/**, node_modules/**
308
+ Skip if slow: Never skip
260
309
 
261
310
  ? What would you like to change?
262
311
  ❯ Engine
@@ -264,6 +313,7 @@ Current settings:
264
313
  Ollama URL
265
314
  Detail level
266
315
  Language
316
+ Learner level
267
317
  Enable/disable hooks
268
318
  File exclusions
269
319
  Latency timeout
@@ -288,16 +338,20 @@ If both exist, the project config takes precedence at runtime.
288
338
  - **Detail level** — minimal / standard / verbose. See
289
339
  [Install → Detail level](#3-detail-level) for what each produces.
290
340
  - **Language** — English, Portuguese, Spanish, French, German, Italian,
291
- Chinese, Japanese, Korean. Applies to the `summary` and `riskReason`
292
- fields; JSON keys and risk labels stay in English.
341
+ Chinese, Japanese, Korean. Applies to the natural-language fields (impact,
342
+ howItWorks, why, deepDive, riskReason); JSON keys and risk labels stay in
343
+ English.
344
+ - **Learner level** — calibrates teaching depth. Options: never programmed /
345
+ just starting / read code with difficulty / code regularly. See
346
+ [Install → step 5](#5-programming-knowledge-level-only-when-teaching-is-on).
293
347
  - **Hooks** — turn on or off individually. If Bash explanations feel noisy,
294
348
  disable just that hook and keep Edit + Write.
295
349
  - **File exclusions** — glob patterns for files you never want explained.
296
350
  Defaults cover lockfiles, build output, and dependencies. Add patterns like
297
351
  `*.generated.*` if your project has codegen.
298
352
  - **Latency timeout** — maximum time to wait for an explanation before
299
- skipping it. Options: 5s (aggressive), 8s (balanced, recommended), 15s
300
- (patient), or never skip.
353
+ skipping it. Options: 5s (aggressive), 8s (balanced), 15s (patient), or
354
+ never skip (default explanations always wait until the engine responds).
301
355
 
302
356
  ### Editing the config file directly
303
357
 
@@ -316,13 +370,14 @@ Full config schema:
316
370
  "ollamaUrl": "http://localhost:11434",
317
371
  "detailLevel": "standard",
318
372
  "language": "en",
373
+ "learnerLevel": "intermediate",
319
374
  "hooks": {
320
375
  "edit": true,
321
376
  "write": true,
322
377
  "bash": true
323
378
  },
324
379
  "exclude": ["*.lock", "dist/**", "node_modules/**"],
325
- "skipIfSlowMs": 8000,
380
+ "skipIfSlowMs": 0,
326
381
  "bashFilter": {
327
382
  "capturePatterns": [
328
383
  "rm", "mv", "cp", "mkdir",
@@ -344,6 +399,7 @@ Field types:
344
399
  | `ollamaUrl` | Any valid URL (warns on non-loopback) |
345
400
  | `detailLevel` | `"minimal"` / `"standard"` / `"verbose"` |
346
401
  | `language` | `"en"` / `"pt"` / `"es"` / `"fr"` / `"de"` / `"it"` / `"zh"` / `"ja"` / `"ko"` |
402
+ | `learnerLevel` | `"none"` / `"beginner"` / `"intermediate"` / `"regular"` |
347
403
  | `hooks.edit` / `hooks.write` / `hooks.bash` | `true` or `false` |
348
404
  | `exclude` | Array of glob patterns |
349
405
  | `skipIfSlowMs` | Number in milliseconds; `0` means never skip |
@@ -441,14 +497,19 @@ Most common causes, in order:
441
497
  the issue.
442
498
  4. **The file is excluded.** Check your `exclude` patterns in the config.
443
499
 
444
- ### The explanation took too long and got skipped
500
+ ### Claude Code feels slow because it's waiting for explanations
501
+
502
+ By default, code-explainer never skips — every explanation waits for the
503
+ engine to finish so you don't lose context. With Ollama, that can be 10–15s
504
+ on cold start, then 2–5s for normal explanations.
445
505
 
446
- Default timeout is 8 seconds. Cold starts with Ollama (first explanation
447
- after starting the service) can be 10–15 seconds. Two fixes:
506
+ If the wait is bothering you:
448
507
 
449
- - Run `vibe-code-explainer warmup` right after starting Ollama.
450
- - Raise the timeout to 15 seconds via `vibe-code-explainer config →
451
- Latency timeout`.
508
+ - Run `vibe-code-explainer warmup` after starting Ollama, so the first
509
+ explanation is fast.
510
+ - Set a timeout via `vibe-code-explainer config → Latency timeout`. Options:
511
+ 5s (aggressive), 8s (balanced), 15s (patient). Anything that takes longer
512
+ is skipped with a notice instead of blocking Claude Code.
452
513
 
453
514
  ### Explanations are low-quality
454
515
 
@@ -15,6 +15,12 @@ var LANGUAGE_NAMES = {
15
15
  ja: "Japanese",
16
16
  ko: "Korean"
17
17
  };
18
+ var LEARNER_LEVEL_NAMES = {
19
+ none: "Never programmed",
20
+ beginner: "Just starting out",
21
+ intermediate: "Read code with difficulty",
22
+ regular: "Code regularly"
23
+ };
18
24
  var CONFIG_FILENAME = "code-explainer.config.json";
19
25
  function getGlobalConfigPath() {
20
26
  return join(homedir(), ".code-explainer.config.json");
@@ -25,13 +31,14 @@ var DEFAULT_CONFIG = {
25
31
  ollamaUrl: "http://localhost:11434",
26
32
  detailLevel: "standard",
27
33
  language: "en",
34
+ learnerLevel: "intermediate",
28
35
  hooks: {
29
36
  edit: true,
30
37
  write: true,
31
38
  bash: true
32
39
  },
33
40
  exclude: ["*.lock", "dist/**", "node_modules/**"],
34
- skipIfSlowMs: 8e3,
41
+ skipIfSlowMs: 0,
35
42
  bashFilter: {
36
43
  capturePatterns: [
37
44
  "rm",
@@ -81,9 +88,10 @@ function loadConfig(configPath) {
81
88
 
82
89
  export {
83
90
  LANGUAGE_NAMES,
91
+ LEARNER_LEVEL_NAMES,
84
92
  CONFIG_FILENAME,
85
93
  getGlobalConfigPath,
86
94
  DEFAULT_CONFIG,
87
95
  loadConfig
88
96
  };
89
- //# sourceMappingURL=chunk-5NCRRHU7.js.map
97
+ //# sourceMappingURL=chunk-RK7ZFN4W.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config/schema.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\nexport type Engine = \"ollama\" | \"claude\";\nexport type DetailLevel = \"minimal\" | \"standard\" | \"verbose\";\nexport type RiskLevel = \"none\" | \"low\" | \"medium\" | \"high\";\n\nexport type Language =\n | \"en\"\n | \"pt\"\n | \"es\"\n | \"fr\"\n | \"de\"\n | \"it\"\n | \"zh\"\n | \"ja\"\n | \"ko\";\n\nexport const LANGUAGE_NAMES: Record<Language, string> = {\n en: \"English\",\n pt: \"Portuguese\",\n es: \"Spanish\",\n fr: \"French\",\n de: \"German\",\n it: \"Italian\",\n zh: \"Chinese\",\n ja: \"Japanese\",\n ko: \"Korean\",\n};\n\nexport type LearnerLevel = \"none\" | \"beginner\" | \"intermediate\" | \"regular\";\n\nexport const LEARNER_LEVEL_NAMES: Record<LearnerLevel, string> = {\n none: \"Never programmed\",\n beginner: \"Just starting out\",\n intermediate: \"Read code with difficulty\",\n regular: \"Code regularly\",\n};\n\nexport interface HooksConfig {\n edit: boolean;\n write: boolean;\n bash: boolean;\n}\n\nexport interface BashFilterConfig {\n capturePatterns: string[];\n}\n\nexport interface Config {\n engine: Engine;\n ollamaModel: string;\n ollamaUrl: string;\n detailLevel: DetailLevel;\n language: Language;\n learnerLevel: LearnerLevel;\n hooks: HooksConfig;\n exclude: string[];\n skipIfSlowMs: number;\n bashFilter: BashFilterConfig;\n}\n\nexport interface DeepDiveItem {\n term: string;\n explanation: string;\n}\n\nexport interface ExplanationResult {\n impact: string;\n howItWorks: string;\n why: string;\n deepDive: DeepDiveItem[];\n isSamePattern: boolean;\n samePatternNote: string;\n risk: RiskLevel;\n riskReason: string;\n}\n\nexport interface HookPayload {\n session_id: string;\n transcript_path: string;\n cwd: string;\n permission_mode: string;\n hook_event_name: string;\n tool_name: string;\n tool_input: Record<string, unknown>;\n tool_response: string;\n}\n\nexport const CONFIG_FILENAME = \"code-explainer.config.json\";\n\nexport function getGlobalConfigPath(): string {\n return join(homedir(), \".code-explainer.config.json\");\n}\n\nexport const DEFAULT_CONFIG: Config = {\n engine: \"ollama\",\n ollamaModel: \"qwen3.5:4b\",\n ollamaUrl: \"http://localhost:11434\",\n detailLevel: \"standard\",\n language: \"en\",\n learnerLevel: \"intermediate\",\n hooks: {\n edit: true,\n write: true,\n bash: true,\n },\n exclude: [\"*.lock\", \"dist/**\", \"node_modules/**\"],\n skipIfSlowMs: 0,\n bashFilter: {\n capturePatterns: [\n \"rm\",\n \"mv\",\n \"cp\",\n \"mkdir\",\n \"npm install\",\n \"pip install\",\n \"yarn add\",\n \"pnpm add\",\n \"chmod\",\n \"chown\",\n \"git checkout\",\n \"git reset\",\n \"git revert\",\n \"sed -i\",\n ],\n },\n};\n\nfunction mergeConfig(base: Config, overlay: Partial<Config>): Config {\n return {\n ...base,\n ...overlay,\n hooks: { ...base.hooks, ...(overlay.hooks ?? {}) },\n bashFilter: {\n ...base.bashFilter,\n ...(overlay.bashFilter ?? {}),\n },\n };\n}\n\nfunction tryReadJson(path: string): Partial<Config> | null {\n if (!existsSync(path)) return null;\n try {\n return JSON.parse(readFileSync(path, \"utf-8\")) as Partial<Config>;\n } catch {\n return null;\n }\n}\n\n/**\n * Load config with three-level resolution, most specific first:\n * 1. Project config (passed as configPath) — overrides everything\n * 2. Global user config (~/.code-explainer.config.json)\n * 3. Built-in defaults\n *\n * A project config that lacks a field falls through to the global; a global\n * that lacks a field falls through to defaults. This lets a global install\n * set everyone's defaults while still allowing per-project overrides.\n */\nexport function loadConfig(configPath: string): Config {\n const globalConfig = tryReadJson(getGlobalConfigPath());\n const projectConfig = tryReadJson(configPath);\n\n let result = DEFAULT_CONFIG;\n if (globalConfig) result = mergeConfig(result, globalConfig);\n if (projectConfig) result = mergeConfig(result, projectConfig);\n return result;\n}\n"],"mappings":";;;AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,eAAe;AACxB,SAAS,YAAY;AAiBd,IAAM,iBAA2C;AAAA,EACtD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAIO,IAAM,sBAAoD;AAAA,EAC/D,MAAM;AAAA,EACN,UAAU;AAAA,EACV,cAAc;AAAA,EACd,SAAS;AACX;AAoDO,IAAM,kBAAkB;AAExB,SAAS,sBAA8B;AAC5C,SAAO,KAAK,QAAQ,GAAG,6BAA6B;AACtD;AAEO,IAAM,iBAAyB;AAAA,EACpC,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,WAAW;AAAA,EACX,aAAa;AAAA,EACb,UAAU;AAAA,EACV,cAAc;AAAA,EACd,OAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,SAAS,CAAC,UAAU,WAAW,iBAAiB;AAAA,EAChD,cAAc;AAAA,EACd,YAAY;AAAA,IACV,iBAAiB;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,YAAY,MAAc,SAAkC;AACnE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,GAAG;AAAA,IACH,OAAO,EAAE,GAAG,KAAK,OAAO,GAAI,QAAQ,SAAS,CAAC,EAAG;AAAA,IACjD,YAAY;AAAA,MACV,GAAG,KAAK;AAAA,MACR,GAAI,QAAQ,cAAc,CAAC;AAAA,IAC7B;AAAA,EACF;AACF;AAEA,SAAS,YAAY,MAAsC;AACzD,MAAI,CAAC,WAAW,IAAI,EAAG,QAAO;AAC9B,MAAI;AACF,WAAO,KAAK,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,EAC/C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAYO,SAAS,WAAW,YAA4B;AACrD,QAAM,eAAe,YAAY,oBAAoB,CAAC;AACtD,QAAM,gBAAgB,YAAY,UAAU;AAE5C,MAAI,SAAS;AACb,MAAI,aAAc,UAAS,YAAY,QAAQ,YAAY;AAC3D,MAAI,cAAe,UAAS,YAAY,QAAQ,aAAa;AAC7D,SAAO;AACT;","names":[]}